Refactor Data Access Utility (#112)

This commit is contained in:
Steve Faulkner 2020-07-24 16:45:48 -05:00 committed by GitHub
parent 6dcdacc8c4
commit 6d142f16f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 825 additions and 1014 deletions

File diff suppressed because it is too large Load Diff

View File

@ -5,9 +5,9 @@ import * as ViewModels from "../Contracts/ViewModels";
import Q from "q"; import Q from "q";
import { ConflictDefinition, ItemDefinition, QueryIterator, Resource } from "@azure/cosmos"; import { ConflictDefinition, ItemDefinition, QueryIterator, Resource } from "@azure/cosmos";
import { ConsoleDataType } from "../Explorer/Menus/NotificationConsole/NotificationConsoleComponent"; import { ConsoleDataType } from "../Explorer/Menus/NotificationConsole/NotificationConsoleComponent";
import { DataAccessUtilityBase } from "./DataAccessUtilityBase"; import * as DataAccessUtilityBase from "./DataAccessUtilityBase";
import * as Logger from "./Logger"; import * as Logger from "./Logger";
import { MessageHandler } from "./MessageHandler"; import { sendMessage } from "./MessageHandler";
import { MessageTypes } from "../Contracts/ExplorerContracts"; import { MessageTypes } from "../Contracts/ExplorerContracts";
import { MinimalQueryIterator, nextPage } from "./IteratorUtilities"; import { MinimalQueryIterator, nextPage } from "./IteratorUtilities";
import { NotificationConsoleUtils } from "../Utils/NotificationConsoleUtils"; import { NotificationConsoleUtils } from "../Utils/NotificationConsoleUtils";
@ -16,15 +16,13 @@ import StoredProcedure from "../Explorer/Tree/StoredProcedure";
// TODO: Log all promise resolutions and errors with verbosity levels // TODO: Log all promise resolutions and errors with verbosity levels
export default class DocumentClientUtilityBase { export default class DocumentClientUtilityBase {
constructor(private _dataAccessUtility: DataAccessUtilityBase) {}
public queryDocuments( public queryDocuments(
databaseId: string, databaseId: string,
containerId: string, containerId: string,
query: string, query: string,
options: any options: any
): Q.Promise<QueryIterator<ItemDefinition & Resource>> { ): Q.Promise<QueryIterator<ItemDefinition & Resource>> {
return this._dataAccessUtility.queryDocuments(databaseId, containerId, query, options); return DataAccessUtilityBase.queryDocuments(databaseId, containerId, query, options);
} }
public queryConflicts( public queryConflicts(
@ -33,7 +31,7 @@ export default class DocumentClientUtilityBase {
query: string, query: string,
options: any options: any
): Q.Promise<QueryIterator<ConflictDefinition & Resource>> { ): Q.Promise<QueryIterator<ConflictDefinition & Resource>> {
return this._dataAccessUtility.queryConflicts(databaseId, containerId, query, options); return DataAccessUtilityBase.queryConflicts(databaseId, containerId, query, options);
} }
public getEntityName() { public getEntityName() {
@ -54,8 +52,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Querying stored procedures for container ${collection.id()}` `Querying stored procedures for container ${collection.id()}`
); );
this._dataAccessUtility DataAccessUtilityBase.readStoredProcedures(collection, options)
.readStoredProcedures(collection, options)
.then( .then(
(storedProcedures: DataModels.StoredProcedure[]) => { (storedProcedures: DataModels.StoredProcedure[]) => {
deferred.resolve(storedProcedures); deferred.resolve(storedProcedures);
@ -82,7 +79,7 @@ export default class DocumentClientUtilityBase {
requestedResource: DataModels.Resource, requestedResource: DataModels.Resource,
options?: any options?: any
): Q.Promise<DataModels.StoredProcedure> { ): Q.Promise<DataModels.StoredProcedure> {
return this._dataAccessUtility.readStoredProcedure(collection, requestedResource, options); return DataAccessUtilityBase.readStoredProcedure(collection, requestedResource, options);
} }
public readUserDefinedFunctions( public readUserDefinedFunctions(
@ -94,8 +91,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Querying user defined functions for collection ${collection.id()}` `Querying user defined functions for collection ${collection.id()}`
); );
this._dataAccessUtility DataAccessUtilityBase.readUserDefinedFunctions(collection, options)
.readUserDefinedFunctions(collection, options)
.then( .then(
(userDefinedFunctions: DataModels.UserDefinedFunction[]) => { (userDefinedFunctions: DataModels.UserDefinedFunction[]) => {
deferred.resolve(userDefinedFunctions); deferred.resolve(userDefinedFunctions);
@ -122,7 +118,7 @@ export default class DocumentClientUtilityBase {
requestedResource: DataModels.Resource, requestedResource: DataModels.Resource,
options: any options: any
): Q.Promise<DataModels.UserDefinedFunction> { ): Q.Promise<DataModels.UserDefinedFunction> {
return this._dataAccessUtility.readUserDefinedFunction(collection, requestedResource, options); return DataAccessUtilityBase.readUserDefinedFunction(collection, requestedResource, options);
} }
public readTriggers(collection: ViewModels.Collection, options: any): Q.Promise<DataModels.Trigger[]> { public readTriggers(collection: ViewModels.Collection, options: any): Q.Promise<DataModels.Trigger[]> {
@ -132,8 +128,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Querying triggers for container ${collection.id()}` `Querying triggers for container ${collection.id()}`
); );
this._dataAccessUtility DataAccessUtilityBase.readTriggers(collection, options)
.readTriggers(collection, options)
.then( .then(
(triggers: DataModels.Trigger[]) => { (triggers: DataModels.Trigger[]) => {
deferred.resolve(triggers); deferred.resolve(triggers);
@ -160,7 +155,7 @@ export default class DocumentClientUtilityBase {
requestedResource: DataModels.Resource, requestedResource: DataModels.Resource,
options?: any options?: any
): Q.Promise<DataModels.Trigger> { ): Q.Promise<DataModels.Trigger> {
return this._dataAccessUtility.readTrigger(collection, requestedResource, options); return DataAccessUtilityBase.readTrigger(collection, requestedResource, options);
} }
public executeStoredProcedure( public executeStoredProcedure(
@ -175,8 +170,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Executing stored procedure ${storedProcedure.id()}` `Executing stored procedure ${storedProcedure.id()}`
); );
this._dataAccessUtility DataAccessUtilityBase.executeStoredProcedure(collection, storedProcedure, partitionKeyValue, params)
.executeStoredProcedure(collection, storedProcedure, partitionKeyValue, params)
.then( .then(
(response: any) => { (response: any) => {
deferred.resolve(response); deferred.resolve(response);
@ -250,8 +244,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Reading ${entityName} ${documentId.id()}` `Reading ${entityName} ${documentId.id()}`
); );
this._dataAccessUtility DataAccessUtilityBase.readDocument(collection, documentId)
.readDocument(collection, documentId)
.then( .then(
(document: any) => { (document: any) => {
deferred.resolve(document); deferred.resolve(document);
@ -283,8 +276,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Updating container ${collection.id()}` `Updating container ${collection.id()}`
); );
this._dataAccessUtility DataAccessUtilityBase.updateCollection(databaseId, collection.id(), newCollection)
.updateCollection(databaseId, collection.id(), newCollection)
.then( .then(
(replacedCollection: DataModels.Collection) => { (replacedCollection: DataModels.Collection) => {
NotificationConsoleUtils.logConsoleMessage( NotificationConsoleUtils.logConsoleMessage(
@ -321,8 +313,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Updating ${entityName} ${documentId.id()}` `Updating ${entityName} ${documentId.id()}`
); );
this._dataAccessUtility DataAccessUtilityBase.updateDocument(collection, documentId, newDocument)
.updateDocument(collection, documentId, newDocument)
.then( .then(
(updatedDocument: any) => { (updatedDocument: any) => {
NotificationConsoleUtils.logConsoleMessage( NotificationConsoleUtils.logConsoleMessage(
@ -358,8 +349,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Updating offer for resource ${offer.resource}` `Updating offer for resource ${offer.resource}`
); );
this._dataAccessUtility DataAccessUtilityBase.updateOffer(offer, newOffer, options)
.updateOffer(offer, newOffer, options)
.then( .then(
(replacedOffer: DataModels.Offer) => { (replacedOffer: DataModels.Offer) => {
NotificationConsoleUtils.logConsoleMessage( NotificationConsoleUtils.logConsoleMessage(
@ -393,10 +383,7 @@ export default class DocumentClientUtilityBase {
return deferred.promise; return deferred.promise;
} }
public updateOfferThroughputBeyondLimit( public updateOfferThroughputBeyondLimit(requestPayload: DataModels.UpdateOfferThroughputRequest): Q.Promise<void> {
requestPayload: DataModels.UpdateOfferThroughputRequest,
options: any = {}
): Q.Promise<void> {
const deferred: Q.Deferred<void> = Q.defer<void>(); const deferred: Q.Deferred<void> = Q.defer<void>();
const resourceDescriptionInfo: string = requestPayload.collectionName const resourceDescriptionInfo: string = requestPayload.collectionName
? `database ${requestPayload.databaseName} and container ${requestPayload.collectionName}` ? `database ${requestPayload.databaseName} and container ${requestPayload.collectionName}`
@ -405,8 +392,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Requesting increase in throughput to ${requestPayload.throughput} for ${resourceDescriptionInfo}` `Requesting increase in throughput to ${requestPayload.throughput} for ${resourceDescriptionInfo}`
); );
this._dataAccessUtility DataAccessUtilityBase.updateOfferThroughputBeyondLimit(requestPayload)
.updateOfferThroughputBeyondLimit(requestPayload, options)
.then( .then(
() => { () => {
NotificationConsoleUtils.logConsoleMessage( NotificationConsoleUtils.logConsoleMessage(
@ -439,8 +425,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Updating stored procedure ${storedProcedure.id}` `Updating stored procedure ${storedProcedure.id}`
); );
this._dataAccessUtility DataAccessUtilityBase.updateStoredProcedure(collection, storedProcedure, options)
.updateStoredProcedure(collection, storedProcedure, options)
.then( .then(
(updatedStoredProcedure: DataModels.StoredProcedure) => { (updatedStoredProcedure: DataModels.StoredProcedure) => {
NotificationConsoleUtils.logConsoleMessage( NotificationConsoleUtils.logConsoleMessage(
@ -476,8 +461,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Updating user defined function ${userDefinedFunction.id}` `Updating user defined function ${userDefinedFunction.id}`
); );
this._dataAccessUtility DataAccessUtilityBase.updateUserDefinedFunction(collection, userDefinedFunction, options)
.updateUserDefinedFunction(collection, userDefinedFunction, options)
.then( .then(
(updatedUserDefinedFunction: DataModels.UserDefinedFunction) => { (updatedUserDefinedFunction: DataModels.UserDefinedFunction) => {
NotificationConsoleUtils.logConsoleMessage( NotificationConsoleUtils.logConsoleMessage(
@ -506,8 +490,7 @@ export default class DocumentClientUtilityBase {
public updateTrigger(collection: ViewModels.Collection, trigger: DataModels.Trigger): Q.Promise<DataModels.Trigger> { public updateTrigger(collection: ViewModels.Collection, trigger: DataModels.Trigger): Q.Promise<DataModels.Trigger> {
var deferred = Q.defer<any>(); var deferred = Q.defer<any>();
const id = NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.InProgress, `Updating trigger ${trigger.id}`); const id = NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.InProgress, `Updating trigger ${trigger.id}`);
this._dataAccessUtility DataAccessUtilityBase.updateTrigger(collection, trigger)
.updateTrigger(collection, trigger)
.then( .then(
(updatedTrigger: DataModels.Trigger) => { (updatedTrigger: DataModels.Trigger) => {
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Info, `Updated trigger ${trigger.id}`); NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Info, `Updated trigger ${trigger.id}`);
@ -537,8 +520,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Creating new ${entityName} for container ${collection.id()}` `Creating new ${entityName} for container ${collection.id()}`
); );
this._dataAccessUtility DataAccessUtilityBase.createDocument(collection, newDocument)
.createDocument(collection, newDocument)
.then( .then(
(savedDocument: any) => { (savedDocument: any) => {
NotificationConsoleUtils.logConsoleMessage( NotificationConsoleUtils.logConsoleMessage(
@ -574,8 +556,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Creating stored procedure for container ${collection.id()}` `Creating stored procedure for container ${collection.id()}`
); );
this._dataAccessUtility DataAccessUtilityBase.createStoredProcedure(collection, newStoredProcedure, options)
.createStoredProcedure(collection, newStoredProcedure, options)
.then( .then(
(createdStoredProcedure: DataModels.StoredProcedure) => { (createdStoredProcedure: DataModels.StoredProcedure) => {
NotificationConsoleUtils.logConsoleMessage( NotificationConsoleUtils.logConsoleMessage(
@ -611,8 +592,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Creating user defined function for container ${collection.id()}` `Creating user defined function for container ${collection.id()}`
); );
this._dataAccessUtility DataAccessUtilityBase.createUserDefinedFunction(collection, newUserDefinedFunction, options)
.createUserDefinedFunction(collection, newUserDefinedFunction, options)
.then( .then(
(createdUserDefinedFunction: DataModels.UserDefinedFunction) => { (createdUserDefinedFunction: DataModels.UserDefinedFunction) => {
NotificationConsoleUtils.logConsoleMessage( NotificationConsoleUtils.logConsoleMessage(
@ -648,8 +628,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Creating trigger for container ${collection.id()}` `Creating trigger for container ${collection.id()}`
); );
this._dataAccessUtility DataAccessUtilityBase.createTrigger(collection, newTrigger, options)
.createTrigger(collection, newTrigger, options)
.then( .then(
(createdTrigger: DataModels.Trigger) => { (createdTrigger: DataModels.Trigger) => {
NotificationConsoleUtils.logConsoleMessage( NotificationConsoleUtils.logConsoleMessage(
@ -682,8 +661,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Deleting ${entityName} ${documentId.id()}` `Deleting ${entityName} ${documentId.id()}`
); );
this._dataAccessUtility DataAccessUtilityBase.deleteDocument(collection, documentId)
.deleteDocument(collection, documentId)
.then( .then(
(response: any) => { (response: any) => {
NotificationConsoleUtils.logConsoleMessage( NotificationConsoleUtils.logConsoleMessage(
@ -720,8 +698,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Deleting conflict ${conflictId.id()}` `Deleting conflict ${conflictId.id()}`
); );
this._dataAccessUtility DataAccessUtilityBase.deleteConflict(collection, conflictId, options)
.deleteConflict(collection, conflictId, options)
.then( .then(
(response: any) => { (response: any) => {
NotificationConsoleUtils.logConsoleMessage( NotificationConsoleUtils.logConsoleMessage(
@ -754,8 +731,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Deleting container ${collection.id()}` `Deleting container ${collection.id()}`
); );
this._dataAccessUtility DataAccessUtilityBase.deleteCollection(collection, options)
.deleteCollection(collection, options)
.then( .then(
(response: any) => { (response: any) => {
NotificationConsoleUtils.logConsoleMessage( NotificationConsoleUtils.logConsoleMessage(
@ -788,8 +764,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Deleting database ${database.id()}` `Deleting database ${database.id()}`
); );
this._dataAccessUtility DataAccessUtilityBase.deleteDatabase(database, options)
.deleteDatabase(database, options)
.then( .then(
(response: any) => { (response: any) => {
NotificationConsoleUtils.logConsoleMessage( NotificationConsoleUtils.logConsoleMessage(
@ -826,8 +801,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Deleting stored procedure ${storedProcedure.id}` `Deleting stored procedure ${storedProcedure.id}`
); );
this._dataAccessUtility DataAccessUtilityBase.deleteStoredProcedure(collection, storedProcedure, options)
.deleteStoredProcedure(collection, storedProcedure, options)
.then( .then(
(response: any) => { (response: any) => {
NotificationConsoleUtils.logConsoleMessage( NotificationConsoleUtils.logConsoleMessage(
@ -863,8 +837,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Deleting user defined function ${userDefinedFunction.id}` `Deleting user defined function ${userDefinedFunction.id}`
); );
this._dataAccessUtility DataAccessUtilityBase.deleteUserDefinedFunction(collection, userDefinedFunction, options)
.deleteUserDefinedFunction(collection, userDefinedFunction, options)
.then( .then(
(response: any) => { (response: any) => {
NotificationConsoleUtils.logConsoleMessage( NotificationConsoleUtils.logConsoleMessage(
@ -897,8 +870,7 @@ export default class DocumentClientUtilityBase {
): Q.Promise<DataModels.Trigger> { ): Q.Promise<DataModels.Trigger> {
var deferred = Q.defer<any>(); var deferred = Q.defer<any>();
const id = NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.InProgress, `Deleting trigger ${trigger.id}`); const id = NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.InProgress, `Deleting trigger ${trigger.id}`);
this._dataAccessUtility DataAccessUtilityBase.deleteTrigger(collection, trigger, options)
.deleteTrigger(collection, trigger, options)
.then( .then(
(response: any) => { (response: any) => {
NotificationConsoleUtils.logConsoleMessage( NotificationConsoleUtils.logConsoleMessage(
@ -925,11 +897,11 @@ export default class DocumentClientUtilityBase {
} }
public refreshCachedResources(options: any = {}): Q.Promise<void> { public refreshCachedResources(options: any = {}): Q.Promise<void> {
return this._dataAccessUtility.refreshCachedResources(options); return DataAccessUtilityBase.refreshCachedResources(options);
} }
public refreshCachedOffers(): Q.Promise<void> { public refreshCachedOffers(): Q.Promise<void> {
return this._dataAccessUtility.refreshCachedOffers(); return DataAccessUtilityBase.refreshCachedOffers();
} }
public readCollections(database: ViewModels.Database, options: any = {}): Q.Promise<DataModels.Collection[]> { public readCollections(database: ViewModels.Database, options: any = {}): Q.Promise<DataModels.Collection[]> {
@ -938,8 +910,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Querying containers for database ${database.id()}` `Querying containers for database ${database.id()}`
); );
this._dataAccessUtility DataAccessUtilityBase.readCollections(database, options)
.readCollections(database, options)
.then( .then(
(collections: DataModels.Collection[]) => { (collections: DataModels.Collection[]) => {
deferred.resolve(collections); deferred.resolve(collections);
@ -968,8 +939,7 @@ export default class DocumentClientUtilityBase {
`Querying container ${collectionId}` `Querying container ${collectionId}`
); );
this._dataAccessUtility DataAccessUtilityBase.readCollection(databaseId, collectionId)
.readCollection(databaseId, collectionId)
.then( .then(
(collection: DataModels.Collection) => { (collection: DataModels.Collection) => {
deferred.resolve(collection); deferred.resolve(collection);
@ -1001,8 +971,7 @@ export default class DocumentClientUtilityBase {
ConsoleDataType.InProgress, ConsoleDataType.InProgress,
`Querying quota info for container ${collection.id}` `Querying quota info for container ${collection.id}`
); );
this._dataAccessUtility DataAccessUtilityBase.readCollectionQuotaInfo(collection, options)
.readCollectionQuotaInfo(collection, options)
.then( .then(
(quota: DataModels.CollectionQuotaInfo) => { (quota: DataModels.CollectionQuotaInfo) => {
deferred.resolve(quota); deferred.resolve(quota);
@ -1028,8 +997,7 @@ export default class DocumentClientUtilityBase {
var deferred = Q.defer<DataModels.Offer[]>(); var deferred = Q.defer<DataModels.Offer[]>();
const id = NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.InProgress, "Querying offers"); const id = NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.InProgress, "Querying offers");
this._dataAccessUtility DataAccessUtilityBase.readOffers(options)
.readOffers(options)
.then( .then(
(offers: DataModels.Offer[]) => { (offers: DataModels.Offer[]) => {
deferred.resolve(offers); deferred.resolve(offers);
@ -1055,8 +1023,7 @@ export default class DocumentClientUtilityBase {
var deferred = Q.defer<DataModels.OfferWithHeaders>(); var deferred = Q.defer<DataModels.OfferWithHeaders>();
const id = NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.InProgress, "Querying offer"); const id = NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.InProgress, "Querying offer");
this._dataAccessUtility DataAccessUtilityBase.readOffer(requestedResource, options)
.readOffer(requestedResource, options)
.then( .then(
(offer: DataModels.OfferWithHeaders) => { (offer: DataModels.OfferWithHeaders) => {
deferred.resolve(offer); deferred.resolve(offer);
@ -1081,8 +1048,7 @@ export default class DocumentClientUtilityBase {
public readDatabases(options: any): Q.Promise<DataModels.Database[]> { public readDatabases(options: any): Q.Promise<DataModels.Database[]> {
var deferred = Q.defer<any>(); var deferred = Q.defer<any>();
const id = NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.InProgress, "Querying databases"); const id = NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.InProgress, "Querying databases");
this._dataAccessUtility DataAccessUtilityBase.readDatabases(options)
.readDatabases(options)
.then( .then(
(databases: DataModels.Database[]) => { (databases: DataModels.Database[]) => {
deferred.resolve(databases); deferred.resolve(databases);
@ -1114,8 +1080,7 @@ export default class DocumentClientUtilityBase {
`Creating a new container ${request.collectionId} for database ${request.databaseId}` `Creating a new container ${request.collectionId} for database ${request.databaseId}`
); );
this._dataAccessUtility DataAccessUtilityBase.getOrCreateDatabaseAndCollection(request, options)
.getOrCreateDatabaseAndCollection(request, options)
.then( .then(
(collection: DataModels.Collection) => { (collection: DataModels.Collection) => {
NotificationConsoleUtils.logConsoleMessage( NotificationConsoleUtils.logConsoleMessage(
@ -1146,8 +1111,7 @@ export default class DocumentClientUtilityBase {
`Creating a new database ${request.databaseId}` `Creating a new database ${request.databaseId}`
); );
this._dataAccessUtility DataAccessUtilityBase.createDatabase(request, options)
.createDatabase(request, options)
.then( .then(
(database: DataModels.Database) => { (database: DataModels.Database) => {
NotificationConsoleUtils.logConsoleMessage( NotificationConsoleUtils.logConsoleMessage(
@ -1175,7 +1139,7 @@ export default class DocumentClientUtilityBase {
if (error.message && error.message.toLowerCase().indexOf("sharedoffer is disabled for your account") > 0) { if (error.message && error.message.toLowerCase().indexOf("sharedoffer is disabled for your account") > 0) {
return; return;
} }
MessageHandler.sendMessage({ sendMessage({
type: MessageTypes.ForbiddenError, type: MessageTypes.ForbiddenError,
reason: error && error.message ? error.message : error reason: error && error.message ? error.message : error
}); });

View File

@ -1,46 +1,26 @@
jest.mock("./MessageHandler");
import { LogEntryLevel } from "../Contracts/Diagnostics"; import { LogEntryLevel } from "../Contracts/Diagnostics";
import * as Logger from "./Logger"; import * as Logger from "./Logger";
import { MessageHandler } from "./MessageHandler";
import { MessageTypes } from "../Contracts/ExplorerContracts"; import { MessageTypes } from "../Contracts/ExplorerContracts";
import { sendMessage } from "./MessageHandler";
describe("Logger", () => { describe("Logger", () => {
let sendMessageSpy: jasmine.Spy;
beforeEach(() => { beforeEach(() => {
sendMessageSpy = spyOn(MessageHandler, "sendMessage"); jest.resetAllMocks();
});
afterEach(() => {
sendMessageSpy = null;
}); });
it("should log info messages", () => { it("should log info messages", () => {
Logger.logInfo("Test info", "DocDB"); Logger.logInfo("Test info", "DocDB");
const spyArgs = sendMessageSpy.calls.mostRecent().args[0]; expect(sendMessage).toBeCalled();
expect(spyArgs.type).toBe(MessageTypes.LogInfo);
expect(spyArgs.data).toContain(LogEntryLevel.Verbose);
expect(spyArgs.data).toContain("DocDB");
expect(spyArgs.data).toContain("Test info");
}); });
it("should log error messages", () => { it("should log error messages", () => {
Logger.logError("Test error", "DocDB"); Logger.logError("Test error", "DocDB");
const spyArgs = sendMessageSpy.calls.mostRecent().args[0]; expect(sendMessage).toBeCalled();
expect(spyArgs.type).toBe(MessageTypes.LogInfo);
expect(spyArgs.data).toContain(LogEntryLevel.Error);
expect(spyArgs.data).toContain("DocDB");
expect(spyArgs.data).toContain("Test error");
}); });
it("should log warnings", () => { it("should log warnings", () => {
Logger.logWarning("Test warning", "DocDB"); Logger.logWarning("Test warning", "DocDB");
const spyArgs = sendMessageSpy.calls.mostRecent().args[0]; expect(sendMessage).toBeCalled();
expect(spyArgs.type).toBe(MessageTypes.LogInfo);
expect(spyArgs.data).toContain(LogEntryLevel.Warning);
expect(spyArgs.data).toContain("DocDB");
expect(spyArgs.data).toContain("Test warning");
}); });
}); });

View File

@ -1,4 +1,4 @@
import { MessageHandler } from "./MessageHandler"; import { sendMessage } from "./MessageHandler";
import { Diagnostics, MessageTypes } from "../Contracts/ExplorerContracts"; import { Diagnostics, MessageTypes } from "../Contracts/ExplorerContracts";
import { appInsights } from "../Shared/appInsights"; import { appInsights } from "../Shared/appInsights";
import { SeverityLevel } from "@microsoft/applicationinsights-web"; import { SeverityLevel } from "@microsoft/applicationinsights-web";
@ -33,7 +33,7 @@ export function logError(message: string | Error, area: string, code?: number):
} }
function _logEntry(entry: Diagnostics.LogEntry): void { function _logEntry(entry: Diagnostics.LogEntry): void {
MessageHandler.sendMessage({ sendMessage({
type: MessageTypes.LogInfo, type: MessageTypes.LogInfo,
data: JSON.stringify(entry) data: JSON.stringify(entry)
}); });

View File

@ -1,65 +1,29 @@
import Q from "q"; import Q from "q";
import { CachedDataPromise, MessageHandler } from "./MessageHandler"; import * as MessageHandler from "./MessageHandler";
import { MessageTypes } from "../Contracts/ExplorerContracts"; import { MessageTypes } from "../Contracts/ExplorerContracts";
class MockMessageHandler extends MessageHandler {
public static addToMap(key: string, value: CachedDataPromise<any>): void {
MessageHandler.RequestMap[key] = value;
}
public static mapContainsKey(key: string): boolean {
return MessageHandler.RequestMap[key] != null;
}
public static clearAllEntries(): void {
MessageHandler.RequestMap = {};
}
public static runGarbageCollector(): void {
MessageHandler.runGarbageCollector();
}
}
describe("Message Handler", () => { describe("Message Handler", () => {
beforeEach(() => { it("should handle cached message", async () => {
MockMessageHandler.clearAllEntries(); let mockPromise = {
});
xit("should send cached data message", (done: any) => {
const testValidationCallback = (e: MessageEvent) => {
expect(e.data.data).toEqual(
jasmine.objectContaining({ type: MessageTypes.AllDatabases, params: ["some param"] })
);
e.currentTarget.removeEventListener(e.type, testValidationCallback);
done();
};
window.parent.addEventListener("message", testValidationCallback);
MockMessageHandler.sendCachedDataMessage(MessageTypes.AllDatabases, ["some param"]);
});
it("should handle cached message", () => {
let mockPromise: CachedDataPromise<any> = {
id: "123", id: "123",
startTime: new Date(), startTime: new Date(),
deferred: Q.defer<any>() deferred: Q.defer<any>()
}; };
let mockMessage = { message: { id: "123", data: "{}" } }; let mockMessage = { message: { id: "123", data: "{}" } };
MessageHandler.RequestMap[mockPromise.id] = mockPromise;
MockMessageHandler.addToMap(mockPromise.id, mockPromise); MessageHandler.handleCachedDataMessage(mockMessage);
MockMessageHandler.handleCachedDataMessage(mockMessage);
expect(mockPromise.deferred.promise.isFulfilled()).toBe(true); expect(mockPromise.deferred.promise.isFulfilled()).toBe(true);
}); });
it("should delete fulfilled promises on running the garbage collector", () => { it("should delete fulfilled promises on running the garbage collector", async () => {
let mockPromise: CachedDataPromise<any> = { let message = {
id: "123", id: "123",
startTime: new Date(), startTime: new Date(),
deferred: Q.defer<any>() deferred: Q.defer<any>()
}; };
MockMessageHandler.addToMap(mockPromise.id, mockPromise); MessageHandler.handleCachedDataMessage(message);
mockPromise.deferred.reject("some error"); MessageHandler.runGarbageCollector();
MockMessageHandler.runGarbageCollector(); expect(MessageHandler.RequestMap["123"]).toBeUndefined();
expect(MockMessageHandler.mapContainsKey(mockPromise.id)).toBe(false);
}); });
}); });

View File

@ -9,77 +9,65 @@ export interface CachedDataPromise<T> {
id: string; id: string;
} }
/** export const RequestMap: Record<string, CachedDataPromise<any>> = {};
* For some reason, typescript emits a Map() in the compiled js output(despite the target being set to ES5) forcing us to define our own polyfill,
* so we define our own custom implementation of the ES6 Map to work around it.
*/
type Map = { [key: string]: CachedDataPromise<any> };
export class MessageHandler { export function handleCachedDataMessage(message: any): void {
protected static RequestMap: Map = {}; const messageContent = message && message.message;
if (message == null || messageContent == null || messageContent.id == null || !RequestMap[messageContent.id]) {
public static handleCachedDataMessage(message: any): void { return;
const messageContent = message && message.message;
if (
message == null ||
messageContent == null ||
messageContent.id == null ||
!MessageHandler.RequestMap[messageContent.id]
) {
return;
}
const cachedDataPromise = MessageHandler.RequestMap[messageContent.id];
if (messageContent.error != null) {
cachedDataPromise.deferred.reject(messageContent.error);
} else {
cachedDataPromise.deferred.resolve(JSON.parse(messageContent.data));
}
MessageHandler.runGarbageCollector();
} }
public static sendCachedDataMessage<TResponseDataModel>( const cachedDataPromise = RequestMap[messageContent.id];
messageType: MessageTypes, if (messageContent.error != null) {
params: Object[], cachedDataPromise.deferred.reject(messageContent.error);
timeoutInMs?: number } else {
): Q.Promise<TResponseDataModel> { cachedDataPromise.deferred.resolve(JSON.parse(messageContent.data));
let cachedDataPromise: CachedDataPromise<TResponseDataModel> = { }
deferred: Q.defer<TResponseDataModel>(), runGarbageCollector();
startTime: new Date(), }
id: _.uniqueId()
};
MessageHandler.RequestMap[cachedDataPromise.id] = cachedDataPromise;
MessageHandler.sendMessage({ type: messageType, params: params, id: cachedDataPromise.id });
//TODO: Use telemetry to measure optimal time to resolve/reject promises export function sendCachedDataMessage<TResponseDataModel>(
return cachedDataPromise.deferred.promise.timeout( messageType: MessageTypes,
timeoutInMs || Constants.ClientDefaults.requestTimeoutMs, params: Object[],
"Timed out while waiting for response from portal" timeoutInMs?: number
): Q.Promise<TResponseDataModel> {
let cachedDataPromise: CachedDataPromise<TResponseDataModel> = {
deferred: Q.defer<TResponseDataModel>(),
startTime: new Date(),
id: _.uniqueId()
};
RequestMap[cachedDataPromise.id] = cachedDataPromise;
sendMessage({ type: messageType, params: params, id: cachedDataPromise.id });
//TODO: Use telemetry to measure optimal time to resolve/reject promises
return cachedDataPromise.deferred.promise.timeout(
timeoutInMs || Constants.ClientDefaults.requestTimeoutMs,
"Timed out while waiting for response from portal"
);
}
export function sendMessage(data: any): void {
if (canSendMessage()) {
window.parent.postMessage(
{
signature: "pcIframe",
data: data
},
window.document.referrer
); );
} }
}
public static sendMessage(data: any): void {
if (MessageHandler.canSendMessage()) { export function canSendMessage(): boolean {
window.parent.postMessage( return window.parent !== window;
{ }
signature: "pcIframe",
data: data // TODO: This is exported just for testing. It should not be.
}, export function runGarbageCollector() {
window.document.referrer Object.keys(RequestMap).forEach((key: string) => {
); const promise: Q.Promise<any> = RequestMap[key].deferred.promise;
} if (promise.isFulfilled() || promise.isRejected()) {
} delete RequestMap[key];
}
public static canSendMessage(): boolean { });
return window.parent !== window;
}
protected static runGarbageCollector() {
Object.keys(MessageHandler.RequestMap).forEach((key: string) => {
const promise: Q.Promise<any> = MessageHandler.RequestMap[key].deferred.promise;
if (promise.isFulfilled() || promise.isRejected()) {
delete MessageHandler.RequestMap[key];
}
});
}
} }

View File

@ -12,7 +12,7 @@ import { config } from "../Config";
import { ConsoleDataType } from "../Explorer/Menus/NotificationConsole/NotificationConsoleComponent"; import { ConsoleDataType } from "../Explorer/Menus/NotificationConsole/NotificationConsoleComponent";
import { Constants as CosmosSDKConstants } from "@azure/cosmos"; import { Constants as CosmosSDKConstants } from "@azure/cosmos";
import { CosmosClient } from "./CosmosClient"; import { CosmosClient } from "./CosmosClient";
import { MessageHandler } from "./MessageHandler"; import { sendMessage } from "./MessageHandler";
import { MessageTypes } from "../Contracts/ExplorerContracts"; import { MessageTypes } from "../Contracts/ExplorerContracts";
import { NotificationConsoleUtils } from "../Utils/NotificationConsoleUtils"; import { NotificationConsoleUtils } from "../Utils/NotificationConsoleUtils";
import { ResourceProviderClient } from "../ResourceProvider/ResourceProviderClient"; import { ResourceProviderClient } from "../ResourceProvider/ResourceProviderClient";
@ -408,7 +408,7 @@ async function errorHandling(response: Response, action: string, params: unknown
`Error ${action}: ${errorMessage}, Payload: ${JSON.stringify(params)}` `Error ${action}: ${errorMessage}, Payload: ${JSON.stringify(params)}`
); );
if (response.status === HttpStatusCodes.Forbidden) { if (response.status === HttpStatusCodes.Forbidden) {
MessageHandler.sendMessage({ type: MessageTypes.ForbiddenError, reason: errorMessage }); sendMessage({ type: MessageTypes.ForbiddenError, reason: errorMessage });
return; return;
} }
throw new Error(errorMessage); throw new Error(errorMessage);

View File

@ -12,7 +12,7 @@ import {
PortalTheme PortalTheme
} from "./HeatmapDatatypes"; } from "./HeatmapDatatypes";
import { isInvalidParentFrameOrigin } from "../../Utils/MessageValidation"; import { isInvalidParentFrameOrigin } from "../../Utils/MessageValidation";
import { MessageHandler } from "../../Common/MessageHandler"; import { sendCachedDataMessage, sendMessage } from "../../Common/MessageHandler";
import { MessageTypes } from "../../Contracts/ExplorerContracts"; import { MessageTypes } from "../../Contracts/ExplorerContracts";
import { StyleConstants } from "../../Common/Constants"; import { StyleConstants } from "../../Common/Constants";
import "./Heatmap.less"; import "./Heatmap.less";
@ -209,7 +209,7 @@ export class Heatmap {
for (let i = 0; i < this._chartData.dataPoints.length; i++) { for (let i = 0; i < this._chartData.dataPoints.length; i++) {
output.push(this._chartData.dataPoints[i][xAxisIndex]); output.push(this._chartData.dataPoints[i][xAxisIndex]);
} }
MessageHandler.sendCachedDataMessage(MessageTypes.LogInfo, output); sendCachedDataMessage(MessageTypes.LogInfo, output);
}); });
} }
} }
@ -266,4 +266,4 @@ export function handleMessage(event: MessageEvent) {
} }
window.addEventListener("message", handleMessage, false); window.addEventListener("message", handleMessage, false);
MessageHandler.sendMessage("ready"); sendMessage("ready");

View File

@ -52,7 +52,7 @@ import { isInvalidParentFrameOrigin } from "../Utils/MessageValidation";
import { IGalleryItem } from "../Juno/JunoClient"; import { IGalleryItem } from "../Juno/JunoClient";
import { LoadQueryPane } from "./Panes/LoadQueryPane"; import { LoadQueryPane } from "./Panes/LoadQueryPane";
import * as Logger from "../Common/Logger"; import * as Logger from "../Common/Logger";
import { MessageHandler } from "../Common/MessageHandler"; import { sendMessage, sendCachedDataMessage, handleCachedDataMessage } from "../Common/MessageHandler";
import { NotebookContentItem, NotebookContentItemType } from "./Notebook/NotebookContentItem"; import { NotebookContentItem, NotebookContentItemType } from "./Notebook/NotebookContentItem";
import { NotebookUtil } from "./Notebook/NotebookUtil"; import { NotebookUtil } from "./Notebook/NotebookUtil";
import { NotebookWorkspaceManager } from "../NotebookWorkspaceManager/NotebookWorkspaceManager"; import { NotebookWorkspaceManager } from "../NotebookWorkspaceManager/NotebookWorkspaceManager";
@ -1607,7 +1607,7 @@ export default class Explorer {
public async getArcadiaToken(): Promise<string> { public async getArcadiaToken(): Promise<string> {
return new Promise<string>((resolve: (token: string) => void, reject: (error: any) => void) => { return new Promise<string>((resolve: (token: string) => void, reject: (error: any) => void) => {
MessageHandler.sendCachedDataMessage<string>(MessageTypes.GetArcadiaToken, undefined /** params **/).then( sendCachedDataMessage<string>(MessageTypes.GetArcadiaToken, undefined /** params **/).then(
(token: string) => { (token: string) => {
resolve(token); resolve(token);
}, },
@ -1645,11 +1645,11 @@ export default class Explorer {
} }
public async createWorkspace(): Promise<string> { public async createWorkspace(): Promise<string> {
return MessageHandler.sendCachedDataMessage(MessageTypes.CreateWorkspace, undefined /** params **/); return sendCachedDataMessage(MessageTypes.CreateWorkspace, undefined /** params **/);
} }
public async createSparkPool(workspaceId: string): Promise<string> { public async createSparkPool(workspaceId: string): Promise<string> {
return MessageHandler.sendCachedDataMessage(MessageTypes.CreateSparkPool, [workspaceId]); return sendCachedDataMessage(MessageTypes.CreateSparkPool, [workspaceId]);
} }
public async initNotebooks(databaseAccount: DataModels.DatabaseAccount): Promise<void> { public async initNotebooks(databaseAccount: DataModels.DatabaseAccount): Promise<void> {
@ -1845,7 +1845,7 @@ export default class Explorer {
} }
} }
if (message.actionType === ActionContracts.ActionType.TransmitCachedData) { if (message.actionType === ActionContracts.ActionType.TransmitCachedData) {
MessageHandler.handleCachedDataMessage(message); handleCachedDataMessage(message);
return; return;
} }
if (message.type) { if (message.type) {
@ -2041,7 +2041,7 @@ export default class Explorer {
public signInAad = () => { public signInAad = () => {
TelemetryProcessor.trace(Action.SignInAad, undefined, { area: "Explorer" }); TelemetryProcessor.trace(Action.SignInAad, undefined, { area: "Explorer" });
MessageHandler.sendMessage({ sendMessage({
type: MessageTypes.AadSignIn type: MessageTypes.AadSignIn
}); });
}; };
@ -2052,21 +2052,21 @@ export default class Explorer {
}; };
public clickHostedAccountSwitch = () => { public clickHostedAccountSwitch = () => {
MessageHandler.sendMessage({ sendMessage({
type: MessageTypes.UpdateAccountSwitch, type: MessageTypes.UpdateAccountSwitch,
click: true click: true
}); });
}; };
public clickHostedDirectorySwitch = () => { public clickHostedDirectorySwitch = () => {
MessageHandler.sendMessage({ sendMessage({
type: MessageTypes.UpdateDirectoryControl, type: MessageTypes.UpdateDirectoryControl,
click: true click: true
}); });
}; };
public refreshDatabaseAccount = () => { public refreshDatabaseAccount = () => {
MessageHandler.sendMessage({ sendMessage({
type: MessageTypes.RefreshDatabaseAccount type: MessageTypes.RefreshDatabaseAccount
}); });
}; };

View File

@ -14,7 +14,7 @@ import * as TableConstants from "./Constants";
import * as TableEntityProcessor from "./TableEntityProcessor"; import * as TableEntityProcessor from "./TableEntityProcessor";
import * as ViewModels from "../../Contracts/ViewModels"; import * as ViewModels from "../../Contracts/ViewModels";
import { MessageTypes } from "../../Contracts/ExplorerContracts"; import { MessageTypes } from "../../Contracts/ExplorerContracts";
import { MessageHandler } from "../../Common/MessageHandler"; import { sendMessage } from "../../Common/MessageHandler";
import DocumentClientUtilityBase from "../../Common/DocumentClientUtilityBase"; import DocumentClientUtilityBase from "../../Common/DocumentClientUtilityBase";
import Explorer from "../Explorer"; import Explorer from "../Explorer";
@ -738,7 +738,7 @@ export class CassandraAPIDataClient extends TableDataClient {
private _checkForbiddenError(reason: any) { private _checkForbiddenError(reason: any) {
if (reason && reason.code === Constants.HttpStatusCodes.Forbidden) { if (reason && reason.code === Constants.HttpStatusCodes.Forbidden) {
MessageHandler.sendMessage({ sendMessage({
type: MessageTypes.ForbiddenError, type: MessageTypes.ForbiddenError,
reason: typeof reason === "string" ? "reason" : JSON.stringify(reason) reason: typeof reason === "string" ? "reason" : JSON.stringify(reason)
}); });

View File

@ -2,7 +2,6 @@ import * as ko from "knockout";
import * as ViewModels from "../../Contracts/ViewModels"; import * as ViewModels from "../../Contracts/ViewModels";
import * as Constants from "../../Common/Constants"; import * as Constants from "../../Common/Constants";
import DocumentsTab from "./DocumentsTab"; import DocumentsTab from "./DocumentsTab";
import { DataAccessUtility } from "../../Platform/Portal/DataAccessUtility";
import Explorer from "../Explorer"; import Explorer from "../Explorer";
import DocumentClientUtilityBase from "../../Common/DocumentClientUtilityBase"; import DocumentClientUtilityBase from "../../Common/DocumentClientUtilityBase";
@ -15,7 +14,7 @@ describe("Documents tab", () => {
tabKind: ViewModels.CollectionTabKind.Documents, tabKind: ViewModels.CollectionTabKind.Documents,
title: "", title: "",
tabPath: "", tabPath: "",
documentClientUtility: new DocumentClientUtilityBase(new DataAccessUtility()), documentClientUtility: new DocumentClientUtilityBase(),
selfLink: "", selfLink: "",
hashLocation: "", hashLocation: "",
isActive: ko.observable<boolean>(false), isActive: ko.observable<boolean>(false),
@ -98,7 +97,7 @@ describe("Documents tab", () => {
tabKind: ViewModels.CollectionTabKind.Documents, tabKind: ViewModels.CollectionTabKind.Documents,
title: "", title: "",
tabPath: "", tabPath: "",
documentClientUtility: new DocumentClientUtilityBase(new DataAccessUtility()), documentClientUtility: new DocumentClientUtilityBase(),
selfLink: "", selfLink: "",
hashLocation: "", hashLocation: "",
isActive: ko.observable<boolean>(false), isActive: ko.observable<boolean>(false),
@ -117,7 +116,7 @@ describe("Documents tab", () => {
tabKind: ViewModels.CollectionTabKind.Documents, tabKind: ViewModels.CollectionTabKind.Documents,
title: "", title: "",
tabPath: "", tabPath: "",
documentClientUtility: new DocumentClientUtilityBase(new DataAccessUtility()), documentClientUtility: new DocumentClientUtilityBase(),
selfLink: "", selfLink: "",
hashLocation: "", hashLocation: "",
isActive: ko.observable<boolean>(false), isActive: ko.observable<boolean>(false),
@ -136,7 +135,7 @@ describe("Documents tab", () => {
tabKind: ViewModels.CollectionTabKind.Documents, tabKind: ViewModels.CollectionTabKind.Documents,
title: "", title: "",
tabPath: "", tabPath: "",
documentClientUtility: new DocumentClientUtilityBase(new DataAccessUtility()), documentClientUtility: new DocumentClientUtilityBase(),
selfLink: "", selfLink: "",
hashLocation: "", hashLocation: "",
isActive: ko.observable<boolean>(false), isActive: ko.observable<boolean>(false),
@ -155,7 +154,7 @@ describe("Documents tab", () => {
tabKind: ViewModels.CollectionTabKind.Documents, tabKind: ViewModels.CollectionTabKind.Documents,
title: "", title: "",
tabPath: "", tabPath: "",
documentClientUtility: new DocumentClientUtilityBase(new DataAccessUtility()), documentClientUtility: new DocumentClientUtilityBase(),
selfLink: "", selfLink: "",
hashLocation: "", hashLocation: "",
isActive: ko.observable<boolean>(false), isActive: ko.observable<boolean>(false),
@ -174,7 +173,7 @@ describe("Documents tab", () => {
tabKind: ViewModels.CollectionTabKind.Documents, tabKind: ViewModels.CollectionTabKind.Documents,
title: "", title: "",
tabPath: "", tabPath: "",
documentClientUtility: new DocumentClientUtilityBase(new DataAccessUtility()), documentClientUtility: new DocumentClientUtilityBase(),
selfLink: "", selfLink: "",
hashLocation: "", hashLocation: "",
isActive: ko.observable<boolean>(false), isActive: ko.observable<boolean>(false),

View File

@ -7,7 +7,6 @@ import Database from "../Tree/Database";
import DocumentClientUtilityBase from "../../Common/DocumentClientUtilityBase"; import DocumentClientUtilityBase from "../../Common/DocumentClientUtilityBase";
import Explorer from "../Explorer"; import Explorer from "../Explorer";
import SettingsTab from "../Tabs/SettingsTab"; import SettingsTab from "../Tabs/SettingsTab";
import { DataAccessUtility } from "../../Platform/Portal/DataAccessUtility";
describe("Settings tab", () => { describe("Settings tab", () => {
const baseCollection: DataModels.Collection = { const baseCollection: DataModels.Collection = {
@ -189,7 +188,7 @@ describe("Settings tab", () => {
tabKind: ViewModels.CollectionTabKind.Settings, tabKind: ViewModels.CollectionTabKind.Settings,
title: "Scale & Settings", title: "Scale & Settings",
tabPath: "", tabPath: "",
documentClientUtility: new DocumentClientUtilityBase(new DataAccessUtility()), documentClientUtility: new DocumentClientUtilityBase(),
selfLink: "", selfLink: "",
hashLocation: "", hashLocation: "",
@ -213,7 +212,7 @@ describe("Settings tab", () => {
tabKind: ViewModels.CollectionTabKind.Settings, tabKind: ViewModels.CollectionTabKind.Settings,
title: "Scale & Settings", title: "Scale & Settings",
tabPath: "", tabPath: "",
documentClientUtility: new DocumentClientUtilityBase(new DataAccessUtility()), documentClientUtility: new DocumentClientUtilityBase(),
selfLink: "", selfLink: "",
hashLocation: "", hashLocation: "",
@ -232,7 +231,7 @@ describe("Settings tab", () => {
tabKind: ViewModels.CollectionTabKind.Settings, tabKind: ViewModels.CollectionTabKind.Settings,
title: "Scale & Settings", title: "Scale & Settings",
tabPath: "", tabPath: "",
documentClientUtility: new DocumentClientUtilityBase(new DataAccessUtility()), documentClientUtility: new DocumentClientUtilityBase(),
selfLink: "", selfLink: "",
hashLocation: "", hashLocation: "",
@ -271,7 +270,7 @@ describe("Settings tab", () => {
tabKind: ViewModels.CollectionTabKind.Settings, tabKind: ViewModels.CollectionTabKind.Settings,
title: "Scale & Settings", title: "Scale & Settings",
tabPath: "", tabPath: "",
documentClientUtility: new DocumentClientUtilityBase(new DataAccessUtility()), documentClientUtility: new DocumentClientUtilityBase(),
selfLink: "", selfLink: "",
hashLocation: "", hashLocation: "",
@ -288,7 +287,7 @@ describe("Settings tab", () => {
tabKind: ViewModels.CollectionTabKind.Settings, tabKind: ViewModels.CollectionTabKind.Settings,
title: "Scale & Settings", title: "Scale & Settings",
tabPath: "", tabPath: "",
documentClientUtility: new DocumentClientUtilityBase(new DataAccessUtility()), documentClientUtility: new DocumentClientUtilityBase(),
selfLink: "", selfLink: "",
hashLocation: "", hashLocation: "",
@ -314,7 +313,7 @@ describe("Settings tab", () => {
tabKind: ViewModels.CollectionTabKind.Settings, tabKind: ViewModels.CollectionTabKind.Settings,
title: "Scale & Settings", title: "Scale & Settings",
tabPath: "", tabPath: "",
documentClientUtility: new DocumentClientUtilityBase(new DataAccessUtility()), documentClientUtility: new DocumentClientUtilityBase(),
selfLink: "", selfLink: "",
hashLocation: "", hashLocation: "",
@ -395,7 +394,7 @@ describe("Settings tab", () => {
tabKind: ViewModels.CollectionTabKind.Settings, tabKind: ViewModels.CollectionTabKind.Settings,
title: "Scale & Settings", title: "Scale & Settings",
tabPath: "", tabPath: "",
documentClientUtility: new DocumentClientUtilityBase(new DataAccessUtility()), documentClientUtility: new DocumentClientUtilityBase(),
selfLink: "", selfLink: "",
hashLocation: "", hashLocation: "",
@ -541,7 +540,7 @@ describe("Settings tab", () => {
tabKind: ViewModels.CollectionTabKind.Settings, tabKind: ViewModels.CollectionTabKind.Settings,
title: "Scale & Settings", title: "Scale & Settings",
tabPath: "", tabPath: "",
documentClientUtility: new DocumentClientUtilityBase(new DataAccessUtility()), documentClientUtility: new DocumentClientUtilityBase(),
selfLink: "", selfLink: "",
hashLocation: "", hashLocation: "",

View File

@ -1,6 +1,5 @@
import * as ko from "knockout"; import * as ko from "knockout";
import * as ViewModels from "../../Contracts/ViewModels"; import * as ViewModels from "../../Contracts/ViewModels";
import { DataAccessUtility } from "../../Platform/Portal/DataAccessUtility";
import { TabsManager } from "./TabsManager"; import { TabsManager } from "./TabsManager";
import DocumentClientUtilityBase from "../../Common/DocumentClientUtilityBase"; import DocumentClientUtilityBase from "../../Common/DocumentClientUtilityBase";
import DocumentsTab from "./DocumentsTab"; import DocumentsTab from "./DocumentsTab";
@ -64,7 +63,7 @@ describe("Tabs manager tests", () => {
collection, collection,
title: "", title: "",
tabPath: "", tabPath: "",
documentClientUtility: new DocumentClientUtilityBase(new DataAccessUtility()), documentClientUtility: new DocumentClientUtilityBase(),
selfLink: "", selfLink: "",
hashLocation: "", hashLocation: "",
isActive: ko.observable<boolean>(false), isActive: ko.observable<boolean>(false),

View File

@ -1,12 +0,0 @@
import Q from "q";
import { DataAccessUtilityBase } from "../../Common/DataAccessUtilityBase";
export class DataAccessUtility extends DataAccessUtilityBase {
public refreshCachedOffers(): Q.Promise<void> {
return Q();
}
public refreshCachedResources(options: any): Q.Promise<void> {
return Q();
}
}

View File

@ -4,12 +4,11 @@ import Explorer from "../../Explorer/Explorer";
import { NotificationsClient } from "./NotificationsClient"; import { NotificationsClient } from "./NotificationsClient";
import DocumentClientUtilityBase from "../../Common/DocumentClientUtilityBase"; import DocumentClientUtilityBase from "../../Common/DocumentClientUtilityBase";
import { DataAccessUtility } from "./DataAccessUtility";
export default class EmulatorExplorerFactory { export default class EmulatorExplorerFactory {
public static createExplorer(): Explorer { public static createExplorer(): Explorer {
DocumentClientUtilityBase; DocumentClientUtilityBase;
const documentClientUtility: DocumentClientUtilityBase = new DocumentClientUtilityBase(new DataAccessUtility()); const documentClientUtility: DocumentClientUtilityBase = new DocumentClientUtilityBase();
const explorer: Explorer = new Explorer({ const explorer: Explorer = new Explorer({
documentClientUtility: documentClientUtility, documentClientUtility: documentClientUtility,

View File

@ -1,12 +0,0 @@
import Q from "q";
import { DataAccessUtilityBase } from "../../Common/DataAccessUtilityBase";
export class DataAccessUtility extends DataAccessUtilityBase {
public refreshCachedOffers(): Q.Promise<void> {
return Q();
}
public refreshCachedResources(): Q.Promise<void> {
return Q();
}
}

View File

@ -1,12 +1,10 @@
import * as ViewModels from "../../Contracts/ViewModels";
import Explorer from "../../Explorer/Explorer"; import Explorer from "../../Explorer/Explorer";
import { NotificationsClient } from "./NotificationsClient"; import { NotificationsClient } from "./NotificationsClient";
import DocumentClientUtilityBase from "../../Common/DocumentClientUtilityBase"; import DocumentClientUtilityBase from "../../Common/DocumentClientUtilityBase";
import { DataAccessUtility } from "./DataAccessUtility";
export default class HostedExplorerFactory { export default class HostedExplorerFactory {
public createExplorer(): Explorer { public createExplorer(): Explorer {
var documentClientUtility = new DocumentClientUtilityBase(new DataAccessUtility()); var documentClientUtility = new DocumentClientUtilityBase();
const explorer = new Explorer({ const explorer = new Explorer({
documentClientUtility: documentClientUtility, documentClientUtility: documentClientUtility,
@ -19,7 +17,7 @@ export default class HostedExplorerFactory {
public static reInitializeDocumentClientUtilityForExplorer(explorer: Explorer): void { public static reInitializeDocumentClientUtilityForExplorer(explorer: Explorer): void {
if (!!explorer) { if (!!explorer) {
const documentClientUtility = new DocumentClientUtilityBase(new DataAccessUtility()); const documentClientUtility = new DocumentClientUtilityBase();
explorer.rebindDocumentClientUtility(documentClientUtility); explorer.rebindDocumentClientUtility(documentClientUtility);
explorer.notificationConsoleData([]); explorer.notificationConsoleData([]);
} }

View File

@ -18,7 +18,7 @@ import { CosmosClient } from "../../Common/CosmosClient";
import { DataExplorerInputsFrame } from "../../Contracts/ViewModels"; import { DataExplorerInputsFrame } from "../../Contracts/ViewModels";
import { DefaultExperienceUtility } from "../../Shared/DefaultExperienceUtility"; import { DefaultExperienceUtility } from "../../Shared/DefaultExperienceUtility";
import { HostedUtils } from "./HostedUtils"; import { HostedUtils } from "./HostedUtils";
import { MessageHandler } from "../../Common/MessageHandler"; import { sendMessage } from "../../Common/MessageHandler";
import { MessageTypes } from "../../Contracts/ExplorerContracts"; import { MessageTypes } from "../../Contracts/ExplorerContracts";
import { SessionStorageUtility, StorageKey } from "../../Shared/StorageUtility"; import { SessionStorageUtility, StorageKey } from "../../Shared/StorageUtility";
import { SubscriptionUtilMappings } from "../../Shared/Constants"; import { SubscriptionUtilMappings } from "../../Shared/Constants";
@ -77,7 +77,7 @@ export default class Main {
const explorer: Explorer = this._instantiateExplorer(); const explorer: Explorer = this._instantiateExplorer();
if (authType === AuthType.EncryptedToken) { if (authType === AuthType.EncryptedToken) {
MessageHandler.sendMessage({ sendMessage({
type: MessageTypes.UpdateAccountSwitch, type: MessageTypes.UpdateAccountSwitch,
props: { props: {
authType: AuthType.EncryptedToken, authType: AuthType.EncryptedToken,
@ -102,7 +102,7 @@ export default class Main {
} }
); );
} else if (authType === AuthType.AAD) { } else if (authType === AuthType.AAD) {
MessageHandler.sendMessage({ sendMessage({
type: MessageTypes.GetAccessAadRequest type: MessageTypes.GetAccessAadRequest
}); });
if (this._getAadAccessDeferred != null) { if (this._getAadAccessDeferred != null) {
@ -287,7 +287,7 @@ export default class Main {
const apiExperience: string = DefaultExperienceUtility.getDefaultExperienceFromApiKind( const apiExperience: string = DefaultExperienceUtility.getDefaultExperienceFromApiKind(
Main._accessInputMetadata.apiKind Main._accessInputMetadata.apiKind
); );
MessageHandler.sendMessage({ sendMessage({
type: MessageTypes.UpdateAccountSwitch, type: MessageTypes.UpdateAccountSwitch,
props: { props: {
authType: AuthType.EncryptedToken, authType: AuthType.EncryptedToken,
@ -385,7 +385,7 @@ export default class Main {
window.addEventListener( window.addEventListener(
"click", "click",
() => { () => {
MessageHandler.sendMessage({ sendMessage({
type: MessageTypes.ExplorerClickEvent type: MessageTypes.ExplorerClickEvent
}); });
}, },
@ -514,7 +514,7 @@ export default class Main {
) { ) {
Main._initDataExplorerFrameInputs(explorer, masterKey, account, authorizationToken); Main._initDataExplorerFrameInputs(explorer, masterKey, account, authorizationToken);
explorer.isAccountReady.valueHasMutated(); explorer.isAccountReady.valueHasMutated();
MessageHandler.sendMessage("ready"); sendMessage("ready");
} }
private static _shouldProcessMessage(event: MessageEvent): boolean { private static _shouldProcessMessage(event: MessageEvent): boolean {

View File

@ -1,96 +0,0 @@
import "jquery";
import * as _ from "underscore";
import Q from "q";
import { getAuthorizationHeader } from "../../Utils/AuthorizationUtils";
import * as DataModels from "../../Contracts/DataModels";
import * as ViewModels from "../../Contracts/ViewModels";
import * as Constants from "../../Common/Constants";
import { DataAccessUtilityBase } from "../../Common/DataAccessUtilityBase";
import { MessageHandler } from "../../Common/MessageHandler";
import { MessageTypes } from "../../Contracts/ExplorerContracts";
export class DataAccessUtility extends DataAccessUtilityBase {
public readDatabases(options: any): Q.Promise<DataModels.Database[]> {
return MessageHandler.sendCachedDataMessage<DataModels.Database[]>(MessageTypes.AllDatabases, [
(<any>window).dataExplorer.databaseAccount().id,
Constants.ClientDefaults.portalCacheTimeoutMs
]).catch(error => {
return super.readDatabases(options);
});
}
// public readCollections(database: ViewModels.Database, options: any): Q.Promise<DataModels.Collection[]> {
// return MessageHandler.sendCachedDataMessage<DataModels.Collection[]>(MessageTypes.CollectionsForDatabase, [
// (<any>window).dataExplorer.databaseAccount().id,
// database.id()
// ]);
// }
public readOffers(options: any): Q.Promise<DataModels.Offer[]> {
return MessageHandler.sendCachedDataMessage<DataModels.Offer[]>(MessageTypes.AllOffers, [
(<any>window).dataExplorer.databaseAccount().id,
Constants.ClientDefaults.portalCacheTimeoutMs
]).catch(error => {
return super.readOffers(options);
});
}
public readOffer(requestedResource: DataModels.Offer, options: any): Q.Promise<DataModels.OfferWithHeaders> {
const deferred: Q.Deferred<DataModels.OfferWithHeaders> = Q.defer<DataModels.OfferWithHeaders>();
super.readOffer(requestedResource, options).then(
(offer: DataModels.OfferWithHeaders) => deferred.resolve(offer),
(reason: any) => {
const isThrottled: boolean =
!!reason &&
!!reason.error &&
!!reason.error.code &&
reason.error.code == Constants.HttpStatusCodes.TooManyRequests;
if (isThrottled && MessageHandler.canSendMessage()) {
MessageHandler.sendCachedDataMessage<DataModels.OfferWithHeaders>(MessageTypes.SingleOffer, [
(<any>window).dataExplorer.databaseAccount().id,
requestedResource._self,
requestedResource.offerVersion
]).then(
(offer: DataModels.OfferWithHeaders) => deferred.resolve(offer),
(reason: any) => deferred.reject(reason)
);
return;
}
deferred.reject(reason);
}
);
return deferred.promise;
}
public updateOfferThroughputBeyondLimit(
updateThroughputRequestPayload: DataModels.UpdateOfferThroughputRequest,
options: any
): Q.Promise<void> {
const deferred: Q.Deferred<void> = Q.defer<void>();
const explorer = window.dataExplorer;
const url: string = `${explorer.extensionEndpoint()}/api/offerthroughputrequest/updatebeyondspecifiedlimit`;
const authorizationHeader: ViewModels.AuthorizationTokenHeaderMetadata = getAuthorizationHeader();
const requestOptions: any = _.extend({}, options, {});
requestOptions[authorizationHeader.header] = authorizationHeader.token;
const requestSettings: JQueryAjaxSettings<any> = {
type: "POST",
contentType: "application/json",
headers: requestOptions,
data: JSON.stringify(updateThroughputRequestPayload)
};
$.ajax(url, requestSettings).then(
(data: any, textStatus: string, xhr: JQueryXHR<any>) => {
deferred.resolve();
},
(xhr: JQueryXHR<any>, textStatus: string, error: any) => {
deferred.reject(xhr.responseText);
}
);
return deferred.promise;
}
}

View File

@ -1,13 +1,11 @@
import * as ViewModels from "../../Contracts/ViewModels";
import Explorer from "../../Explorer/Explorer"; import Explorer from "../../Explorer/Explorer";
import { NotificationsClient } from "./NotificationsClient"; import { NotificationsClient } from "./NotificationsClient";
import DocumentClientUtilityBase from "../../Common/DocumentClientUtilityBase"; import DocumentClientUtilityBase from "../../Common/DocumentClientUtilityBase";
import { DataAccessUtility } from "./DataAccessUtility";
export default class PortalExplorerFactory { export default class PortalExplorerFactory {
public createExplorer(): Explorer { public createExplorer(): Explorer {
var documentClientUtility = new DocumentClientUtilityBase(new DataAccessUtility()); var documentClientUtility = new DocumentClientUtilityBase();
var explorer = new Explorer({ var explorer = new Explorer({
documentClientUtility: documentClientUtility, documentClientUtility: documentClientUtility,

View File

@ -1,5 +1,5 @@
import { MessageTypes } from "../Contracts/ExplorerContracts"; import { MessageTypes } from "../Contracts/ExplorerContracts";
import { MessageHandler } from "../Common/MessageHandler"; import { sendMessage } from "../Common/MessageHandler";
import { TabRouteHandler } from "./TabRouteHandler"; import { TabRouteHandler } from "./TabRouteHandler";
export class RouteHandler { export class RouteHandler {
@ -27,7 +27,7 @@ export class RouteHandler {
} }
public updateRouteHashLocation(hash: string): void { public updateRouteHashLocation(hash: string): void {
MessageHandler.sendMessage({ sendMessage({
type: MessageTypes.UpdateLocationHash, type: MessageTypes.UpdateLocationHash,
locationHash: hash locationHash: hash
}); });

View File

@ -7,7 +7,7 @@ import { AddDbUtilities } from "../Shared/AddDatabaseUtility";
import { ConsoleDataType } from "../Explorer/Menus/NotificationConsole/NotificationConsoleComponent"; import { ConsoleDataType } from "../Explorer/Menus/NotificationConsole/NotificationConsoleComponent";
import { CosmosClient } from "../Common/CosmosClient"; import { CosmosClient } from "../Common/CosmosClient";
import { HttpStatusCodes } from "../Common/Constants"; import { HttpStatusCodes } from "../Common/Constants";
import { MessageHandler } from "../Common/MessageHandler"; import { sendMessage } from "../Common/MessageHandler";
import { MessageTypes } from "../Contracts/ExplorerContracts"; import { MessageTypes } from "../Contracts/ExplorerContracts";
import { NotificationConsoleUtils } from "../Utils/NotificationConsoleUtils"; import { NotificationConsoleUtils } from "../Utils/NotificationConsoleUtils";
import { ResourceProviderClient } from "../ResourceProvider/ResourceProviderClient"; import { ResourceProviderClient } from "../ResourceProvider/ResourceProviderClient";
@ -108,7 +108,7 @@ export class CreateSqlCollectionUtilities {
`Error creating collection: ${JSON.stringify(response)}` `Error creating collection: ${JSON.stringify(response)}`
); );
if (response.status === HttpStatusCodes.Forbidden) { if (response.status === HttpStatusCodes.Forbidden) {
MessageHandler.sendMessage({ type: MessageTypes.ForbiddenError }); sendMessage({ type: MessageTypes.ForbiddenError });
} }
throw new Error(`Error creating collection`); throw new Error(`Error creating collection`);
} }
@ -202,7 +202,7 @@ export class CreateCollectionUtilities {
`Error creating graph: ${JSON.stringify(response)}` `Error creating graph: ${JSON.stringify(response)}`
); );
if (response.status === HttpStatusCodes.Forbidden) { if (response.status === HttpStatusCodes.Forbidden) {
MessageHandler.sendMessage({ type: MessageTypes.ForbiddenError }); sendMessage({ type: MessageTypes.ForbiddenError });
} }
throw new Error(`Error creating graph`); throw new Error(`Error creating graph`);
} }
@ -248,7 +248,7 @@ export class Utilities {
`Error creating table: ${JSON.stringify(reason)}, Payload: ${params}` `Error creating table: ${JSON.stringify(reason)}, Payload: ${params}`
); );
if (reason.status === HttpStatusCodes.Forbidden) { if (reason.status === HttpStatusCodes.Forbidden) {
MessageHandler.sendMessage({ type: MessageTypes.ForbiddenError }); sendMessage({ type: MessageTypes.ForbiddenError });
return; return;
} }
throw new Error(`Error creating table`); throw new Error(`Error creating table`);

View File

@ -4,7 +4,7 @@ import { config } from "../Config";
import { ConsoleDataType } from "../Explorer/Menus/NotificationConsole/NotificationConsoleComponent"; import { ConsoleDataType } from "../Explorer/Menus/NotificationConsole/NotificationConsoleComponent";
import { CosmosClient } from "../Common/CosmosClient"; import { CosmosClient } from "../Common/CosmosClient";
import { HttpStatusCodes } from "../Common/Constants"; import { HttpStatusCodes } from "../Common/Constants";
import { MessageHandler } from "../Common/MessageHandler"; import { sendMessage } from "../Common/MessageHandler";
import { MessageTypes } from "../Contracts/ExplorerContracts"; import { MessageTypes } from "../Contracts/ExplorerContracts";
import { NotificationConsoleUtils } from "../Utils/NotificationConsoleUtils"; import { NotificationConsoleUtils } from "../Utils/NotificationConsoleUtils";
import { ResourceProviderClient } from "../ResourceProvider/ResourceProviderClient"; import { ResourceProviderClient } from "../ResourceProvider/ResourceProviderClient";
@ -164,7 +164,7 @@ export class AddDbUtilities {
`Error creating ${dbType}: ${JSON.stringify(reason)}, Payload: ${params}` `Error creating ${dbType}: ${JSON.stringify(reason)}, Payload: ${params}`
); );
if (reason.status === HttpStatusCodes.Forbidden) { if (reason.status === HttpStatusCodes.Forbidden) {
MessageHandler.sendMessage({ type: MessageTypes.ForbiddenError }); sendMessage({ type: MessageTypes.ForbiddenError });
return; return;
} }
throw new Error(`Error creating ${dbType}`); throw new Error(`Error creating ${dbType}`);

View File

@ -1,5 +1,5 @@
import { Action, ActionModifiers } from "./TelemetryConstants"; import { Action, ActionModifiers } from "./TelemetryConstants";
import { MessageHandler } from "../../Common/MessageHandler"; import { sendMessage } from "../../Common/MessageHandler";
import { MessageTypes } from "../../Contracts/ExplorerContracts"; import { MessageTypes } from "../../Contracts/ExplorerContracts";
import { appInsights } from "../appInsights"; import { appInsights } from "../appInsights";
import { config } from "../../Config"; import { config } from "../../Config";
@ -11,7 +11,7 @@ import { config } from "../../Config";
// TODO: Log telemetry for StorageExplorer case/other clients as well // TODO: Log telemetry for StorageExplorer case/other clients as well
export default class TelemetryProcessor { export default class TelemetryProcessor {
public static trace(action: Action, actionModifier: string = ActionModifiers.Mark, data?: any): void { public static trace(action: Action, actionModifier: string = ActionModifiers.Mark, data?: any): void {
MessageHandler.sendMessage({ sendMessage({
type: MessageTypes.TelemetryInfo, type: MessageTypes.TelemetryInfo,
data: { data: {
action: Action[action], action: Action[action],
@ -25,7 +25,7 @@ export default class TelemetryProcessor {
public static traceStart(action: Action, data?: any): number { public static traceStart(action: Action, data?: any): number {
const timestamp: number = Date.now(); const timestamp: number = Date.now();
MessageHandler.sendMessage({ sendMessage({
type: MessageTypes.TelemetryInfo, type: MessageTypes.TelemetryInfo,
data: { data: {
action: Action[action], action: Action[action],
@ -40,7 +40,7 @@ export default class TelemetryProcessor {
} }
public static traceSuccess(action: Action, data?: any, timestamp?: number): void { public static traceSuccess(action: Action, data?: any, timestamp?: number): void {
MessageHandler.sendMessage({ sendMessage({
type: MessageTypes.TelemetryInfo, type: MessageTypes.TelemetryInfo,
data: { data: {
action: Action[action], action: Action[action],
@ -54,7 +54,7 @@ export default class TelemetryProcessor {
} }
public static traceFailure(action: Action, data?: any, timestamp?: number): void { public static traceFailure(action: Action, data?: any, timestamp?: number): void {
MessageHandler.sendMessage({ sendMessage({
type: MessageTypes.TelemetryInfo, type: MessageTypes.TelemetryInfo,
data: { data: {
action: Action[action], action: Action[action],
@ -68,7 +68,7 @@ export default class TelemetryProcessor {
} }
public static traceCancel(action: Action, data?: any, timestamp?: number): void { public static traceCancel(action: Action, data?: any, timestamp?: number): void {
MessageHandler.sendMessage({ sendMessage({
type: MessageTypes.TelemetryInfo, type: MessageTypes.TelemetryInfo,
data: { data: {
action: Action[action], action: Action[action],
@ -83,7 +83,7 @@ export default class TelemetryProcessor {
public static traceOpen(action: Action, data?: any, timestamp?: number): number { public static traceOpen(action: Action, data?: any, timestamp?: number): number {
const validTimestamp = timestamp || Date.now(); const validTimestamp = timestamp || Date.now();
MessageHandler.sendMessage({ sendMessage({
type: MessageTypes.TelemetryInfo, type: MessageTypes.TelemetryInfo,
data: { data: {
action: Action[action], action: Action[action],
@ -99,7 +99,7 @@ export default class TelemetryProcessor {
public static traceMark(action: Action, data?: any, timestamp?: number): number { public static traceMark(action: Action, data?: any, timestamp?: number): number {
const validTimestamp = timestamp || Date.now(); const validTimestamp = timestamp || Date.now();
MessageHandler.sendMessage({ sendMessage({
type: MessageTypes.TelemetryInfo, type: MessageTypes.TelemetryInfo,
data: { data: {
action: Action[action], action: Action[action],

View File

@ -1,5 +1,5 @@
import { BindingHandlersRegisterer } from "./Bindings/BindingHandlersRegisterer"; import { BindingHandlersRegisterer } from "./Bindings/BindingHandlersRegisterer";
import { MessageHandler } from "./Common/MessageHandler"; import { sendMessage } from "./Common/MessageHandler";
import * as ko from "knockout"; import * as ko from "knockout";
import Explorer from "./Explorer/Explorer"; import Explorer from "./Explorer/Explorer";
@ -8,7 +8,7 @@ export const applyExplorerBindings = (explorer: Explorer) => {
ko.applyBindings(explorer); ko.applyBindings(explorer);
// This message should ideally be sent immediately after explorer has been initialized for optimal data explorer load times. // This message should ideally be sent immediately after explorer has been initialized for optimal data explorer load times.
// TODO: Send another message to describe that the bindings have been applied, and handle message transfers accordingly in the portal // TODO: Send another message to describe that the bindings have been applied, and handle message transfers accordingly in the portal
MessageHandler.sendMessage("ready"); sendMessage("ready");
window.dataExplorer = explorer; window.dataExplorer = explorer;
BindingHandlersRegisterer.registerBindingHandlers(); BindingHandlersRegisterer.registerBindingHandlers();
$("#divExplorer").show(); $("#divExplorer").show();