mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-21 09:51:11 +00:00
Refactor Data Access Utility (#112)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,11 @@ import Explorer from "../../Explorer/Explorer";
|
||||
|
||||
import { NotificationsClient } from "./NotificationsClient";
|
||||
import DocumentClientUtilityBase from "../../Common/DocumentClientUtilityBase";
|
||||
import { DataAccessUtility } from "./DataAccessUtility";
|
||||
|
||||
export default class EmulatorExplorerFactory {
|
||||
public static createExplorer(): Explorer {
|
||||
DocumentClientUtilityBase;
|
||||
const documentClientUtility: DocumentClientUtilityBase = new DocumentClientUtilityBase(new DataAccessUtility());
|
||||
const documentClientUtility: DocumentClientUtilityBase = new DocumentClientUtilityBase();
|
||||
|
||||
const explorer: Explorer = new Explorer({
|
||||
documentClientUtility: documentClientUtility,
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import Explorer from "../../Explorer/Explorer";
|
||||
import { NotificationsClient } from "./NotificationsClient";
|
||||
import DocumentClientUtilityBase from "../../Common/DocumentClientUtilityBase";
|
||||
import { DataAccessUtility } from "./DataAccessUtility";
|
||||
|
||||
export default class HostedExplorerFactory {
|
||||
public createExplorer(): Explorer {
|
||||
var documentClientUtility = new DocumentClientUtilityBase(new DataAccessUtility());
|
||||
var documentClientUtility = new DocumentClientUtilityBase();
|
||||
|
||||
const explorer = new Explorer({
|
||||
documentClientUtility: documentClientUtility,
|
||||
@@ -19,7 +17,7 @@ export default class HostedExplorerFactory {
|
||||
|
||||
public static reInitializeDocumentClientUtilityForExplorer(explorer: Explorer): void {
|
||||
if (!!explorer) {
|
||||
const documentClientUtility = new DocumentClientUtilityBase(new DataAccessUtility());
|
||||
const documentClientUtility = new DocumentClientUtilityBase();
|
||||
explorer.rebindDocumentClientUtility(documentClientUtility);
|
||||
explorer.notificationConsoleData([]);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import { CosmosClient } from "../../Common/CosmosClient";
|
||||
import { DataExplorerInputsFrame } from "../../Contracts/ViewModels";
|
||||
import { DefaultExperienceUtility } from "../../Shared/DefaultExperienceUtility";
|
||||
import { HostedUtils } from "./HostedUtils";
|
||||
import { MessageHandler } from "../../Common/MessageHandler";
|
||||
import { sendMessage } from "../../Common/MessageHandler";
|
||||
import { MessageTypes } from "../../Contracts/ExplorerContracts";
|
||||
import { SessionStorageUtility, StorageKey } from "../../Shared/StorageUtility";
|
||||
import { SubscriptionUtilMappings } from "../../Shared/Constants";
|
||||
@@ -77,7 +77,7 @@ export default class Main {
|
||||
|
||||
const explorer: Explorer = this._instantiateExplorer();
|
||||
if (authType === AuthType.EncryptedToken) {
|
||||
MessageHandler.sendMessage({
|
||||
sendMessage({
|
||||
type: MessageTypes.UpdateAccountSwitch,
|
||||
props: {
|
||||
authType: AuthType.EncryptedToken,
|
||||
@@ -102,7 +102,7 @@ export default class Main {
|
||||
}
|
||||
);
|
||||
} else if (authType === AuthType.AAD) {
|
||||
MessageHandler.sendMessage({
|
||||
sendMessage({
|
||||
type: MessageTypes.GetAccessAadRequest
|
||||
});
|
||||
if (this._getAadAccessDeferred != null) {
|
||||
@@ -287,7 +287,7 @@ export default class Main {
|
||||
const apiExperience: string = DefaultExperienceUtility.getDefaultExperienceFromApiKind(
|
||||
Main._accessInputMetadata.apiKind
|
||||
);
|
||||
MessageHandler.sendMessage({
|
||||
sendMessage({
|
||||
type: MessageTypes.UpdateAccountSwitch,
|
||||
props: {
|
||||
authType: AuthType.EncryptedToken,
|
||||
@@ -385,7 +385,7 @@ export default class Main {
|
||||
window.addEventListener(
|
||||
"click",
|
||||
() => {
|
||||
MessageHandler.sendMessage({
|
||||
sendMessage({
|
||||
type: MessageTypes.ExplorerClickEvent
|
||||
});
|
||||
},
|
||||
@@ -514,7 +514,7 @@ export default class Main {
|
||||
) {
|
||||
Main._initDataExplorerFrameInputs(explorer, masterKey, account, authorizationToken);
|
||||
explorer.isAccountReady.valueHasMutated();
|
||||
MessageHandler.sendMessage("ready");
|
||||
sendMessage("ready");
|
||||
}
|
||||
|
||||
private static _shouldProcessMessage(event: MessageEvent): boolean {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import Explorer from "../../Explorer/Explorer";
|
||||
|
||||
import { NotificationsClient } from "./NotificationsClient";
|
||||
import DocumentClientUtilityBase from "../../Common/DocumentClientUtilityBase";
|
||||
import { DataAccessUtility } from "./DataAccessUtility";
|
||||
|
||||
export default class PortalExplorerFactory {
|
||||
public createExplorer(): Explorer {
|
||||
var documentClientUtility = new DocumentClientUtilityBase(new DataAccessUtility());
|
||||
var documentClientUtility = new DocumentClientUtilityBase();
|
||||
|
||||
var explorer = new Explorer({
|
||||
documentClientUtility: documentClientUtility,
|
||||
|
||||
Reference in New Issue
Block a user