mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-22 18:32:00 +00:00
Refactor DocumentClientUtilityBase to not be a class (#115)
This commit is contained in:
@@ -33,6 +33,15 @@ import Trigger from "./Trigger";
|
||||
import UserDefinedFunction from "./UserDefinedFunction";
|
||||
import { config } from "../../Config";
|
||||
import Explorer from "../Explorer";
|
||||
import {
|
||||
createDocument,
|
||||
readTriggers,
|
||||
readUserDefinedFunctions,
|
||||
readStoredProcedures,
|
||||
readCollectionQuotaInfo,
|
||||
readOffer,
|
||||
readOffers
|
||||
} from "../../Common/DocumentClientUtilityBase";
|
||||
|
||||
export default class Collection implements ViewModels.Collection {
|
||||
public nodeKind: string;
|
||||
@@ -306,7 +315,6 @@ export default class Collection implements ViewModels.Collection {
|
||||
documentIds: ko.observableArray<DocumentId>([]),
|
||||
tabKind: ViewModels.CollectionTabKind.Documents,
|
||||
title: "Items",
|
||||
documentClientUtility: this.container.documentClientUtility,
|
||||
|
||||
selfLink: this.self,
|
||||
isActive: ko.observable<boolean>(false),
|
||||
@@ -358,7 +366,6 @@ export default class Collection implements ViewModels.Collection {
|
||||
conflictIds: ko.observableArray<ConflictId>([]),
|
||||
tabKind: ViewModels.CollectionTabKind.Conflicts,
|
||||
title: "Conflicts",
|
||||
documentClientUtility: this.container.documentClientUtility,
|
||||
|
||||
selfLink: this.self,
|
||||
isActive: ko.observable<boolean>(false),
|
||||
@@ -419,7 +426,7 @@ export default class Collection implements ViewModels.Collection {
|
||||
tabKind: ViewModels.CollectionTabKind.QueryTables,
|
||||
title: title,
|
||||
tabPath: "",
|
||||
documentClientUtility: this.container.documentClientUtility,
|
||||
|
||||
collection: this,
|
||||
|
||||
node: this,
|
||||
@@ -472,7 +479,7 @@ export default class Collection implements ViewModels.Collection {
|
||||
node: this,
|
||||
title: title,
|
||||
tabPath: "",
|
||||
documentClientUtility: this.container.documentClientUtility,
|
||||
|
||||
collection: this,
|
||||
selfLink: this.self,
|
||||
masterKey: CosmosClient.masterKey() || "",
|
||||
@@ -527,7 +534,7 @@ export default class Collection implements ViewModels.Collection {
|
||||
tabKind: ViewModels.CollectionTabKind.Documents,
|
||||
title: "Documents",
|
||||
tabPath: "",
|
||||
documentClientUtility: this.container.documentClientUtility,
|
||||
|
||||
collection: this,
|
||||
|
||||
node: this,
|
||||
@@ -580,7 +587,7 @@ export default class Collection implements ViewModels.Collection {
|
||||
tabKind: ViewModels.CollectionTabKind.Settings,
|
||||
title: !this.offer() ? "Settings" : "Scale & Settings",
|
||||
tabPath: "",
|
||||
documentClientUtility: this.container.documentClientUtility,
|
||||
|
||||
collection: this,
|
||||
node: this,
|
||||
selfLink: this.self,
|
||||
@@ -645,10 +652,8 @@ export default class Collection implements ViewModels.Collection {
|
||||
defaultExperience: this.container.defaultExperience()
|
||||
});
|
||||
// TODO: Use the collection entity cache to get quota info
|
||||
const quotaInfoPromise: Q.Promise<DataModels.CollectionQuotaInfo> = this.container.documentClientUtility.readCollectionQuotaInfo(
|
||||
this
|
||||
);
|
||||
const offerInfoPromise: Q.Promise<DataModels.Offer[]> = this.container.documentClientUtility.readOffers();
|
||||
const quotaInfoPromise: Q.Promise<DataModels.CollectionQuotaInfo> = readCollectionQuotaInfo(this);
|
||||
const offerInfoPromise: Q.Promise<DataModels.Offer[]> = readOffers();
|
||||
Q.all([quotaInfoPromise, offerInfoPromise]).then(
|
||||
() => {
|
||||
this.container.isRefreshingExplorer(false);
|
||||
@@ -675,41 +680,39 @@ export default class Collection implements ViewModels.Collection {
|
||||
return;
|
||||
}
|
||||
|
||||
this.container.documentClientUtility
|
||||
.readOffer(collectionOffer)
|
||||
.then((offerDetail: DataModels.OfferWithHeaders) => {
|
||||
if (OfferUtils.isNotOfferV1(collectionOffer)) {
|
||||
const offerThroughputInfo: DataModels.OfferThroughputInfo = {
|
||||
minimumRUForCollection:
|
||||
offerDetail.content &&
|
||||
offerDetail.content.collectionThroughputInfo &&
|
||||
offerDetail.content.collectionThroughputInfo.minimumRUForCollection,
|
||||
numPhysicalPartitions:
|
||||
offerDetail.content &&
|
||||
offerDetail.content.collectionThroughputInfo &&
|
||||
offerDetail.content.collectionThroughputInfo.numPhysicalPartitions
|
||||
};
|
||||
readOffer(collectionOffer).then((offerDetail: DataModels.OfferWithHeaders) => {
|
||||
if (OfferUtils.isNotOfferV1(collectionOffer)) {
|
||||
const offerThroughputInfo: DataModels.OfferThroughputInfo = {
|
||||
minimumRUForCollection:
|
||||
offerDetail.content &&
|
||||
offerDetail.content.collectionThroughputInfo &&
|
||||
offerDetail.content.collectionThroughputInfo.minimumRUForCollection,
|
||||
numPhysicalPartitions:
|
||||
offerDetail.content &&
|
||||
offerDetail.content.collectionThroughputInfo &&
|
||||
offerDetail.content.collectionThroughputInfo.numPhysicalPartitions
|
||||
};
|
||||
|
||||
collectionOffer.content.collectionThroughputInfo = offerThroughputInfo;
|
||||
}
|
||||
collectionOffer.content.collectionThroughputInfo = offerThroughputInfo;
|
||||
}
|
||||
|
||||
(collectionOffer as DataModels.OfferWithHeaders).headers = offerDetail.headers;
|
||||
this.offer(collectionOffer);
|
||||
this.offer.valueHasMutated();
|
||||
this.quotaInfo(quotaInfo);
|
||||
TelemetryProcessor.traceSuccess(
|
||||
Action.LoadOffers,
|
||||
{
|
||||
databaseAccountName: this.container.databaseAccount().name,
|
||||
databaseName: this.databaseId,
|
||||
collectionName: this.id(),
|
||||
defaultExperience: this.container.defaultExperience(),
|
||||
offerVersion: collectionOffer && collectionOffer.offerVersion
|
||||
},
|
||||
startKey
|
||||
);
|
||||
deferred.resolve();
|
||||
});
|
||||
(collectionOffer as DataModels.OfferWithHeaders).headers = offerDetail.headers;
|
||||
this.offer(collectionOffer);
|
||||
this.offer.valueHasMutated();
|
||||
this.quotaInfo(quotaInfo);
|
||||
TelemetryProcessor.traceSuccess(
|
||||
Action.LoadOffers,
|
||||
{
|
||||
databaseAccountName: this.container.databaseAccount().name,
|
||||
databaseName: this.databaseId,
|
||||
collectionName: this.id(),
|
||||
defaultExperience: this.container.defaultExperience(),
|
||||
offerVersion: collectionOffer && collectionOffer.offerVersion
|
||||
},
|
||||
startKey
|
||||
);
|
||||
deferred.resolve();
|
||||
});
|
||||
},
|
||||
(error: any) => {
|
||||
this.container.isRefreshingExplorer(false);
|
||||
@@ -747,7 +750,6 @@ export default class Collection implements ViewModels.Collection {
|
||||
tabKind: ViewModels.CollectionTabKind.Query,
|
||||
title: title,
|
||||
tabPath: "",
|
||||
documentClientUtility: this.container.documentClientUtility,
|
||||
collection: this,
|
||||
node: this,
|
||||
selfLink: this.self,
|
||||
@@ -780,7 +782,6 @@ export default class Collection implements ViewModels.Collection {
|
||||
tabKind: ViewModels.CollectionTabKind.Query,
|
||||
title: title,
|
||||
tabPath: "",
|
||||
documentClientUtility: this.container.documentClientUtility,
|
||||
collection: this,
|
||||
node: this,
|
||||
selfLink: this.self,
|
||||
@@ -813,7 +814,6 @@ export default class Collection implements ViewModels.Collection {
|
||||
node: this,
|
||||
title: title,
|
||||
tabPath: "",
|
||||
documentClientUtility: this.container.documentClientUtility,
|
||||
collection: this,
|
||||
selfLink: this.self,
|
||||
masterKey: CosmosClient.masterKey() || "",
|
||||
@@ -836,7 +836,6 @@ export default class Collection implements ViewModels.Collection {
|
||||
tabKind: ViewModels.CollectionTabKind.MongoShell,
|
||||
title: "Shell " + id,
|
||||
tabPath: "",
|
||||
documentClientUtility: this.container.documentClientUtility,
|
||||
collection: this,
|
||||
node: this,
|
||||
hashLocation: `${Constants.HashRoutePrefixes.collectionsWithIds(this.databaseId, this.id())}/mongoShell`,
|
||||
@@ -1075,40 +1074,34 @@ export default class Collection implements ViewModels.Collection {
|
||||
}
|
||||
|
||||
public loadStoredProcedures(): Q.Promise<any> {
|
||||
return this.container.documentClientUtility
|
||||
.readStoredProcedures(this)
|
||||
.then((storedProcedures: DataModels.StoredProcedure[]) => {
|
||||
const storedProceduresNodes: ViewModels.TreeNode[] = storedProcedures.map(
|
||||
storedProcedure => new StoredProcedure(this.container, this, storedProcedure)
|
||||
);
|
||||
const otherNodes = this.children().filter(node => node.nodeKind !== "StoredProcedure");
|
||||
const allNodes = otherNodes.concat(storedProceduresNodes);
|
||||
this.children(allNodes);
|
||||
});
|
||||
return readStoredProcedures(this).then((storedProcedures: DataModels.StoredProcedure[]) => {
|
||||
const storedProceduresNodes: ViewModels.TreeNode[] = storedProcedures.map(
|
||||
storedProcedure => new StoredProcedure(this.container, this, storedProcedure)
|
||||
);
|
||||
const otherNodes = this.children().filter(node => node.nodeKind !== "StoredProcedure");
|
||||
const allNodes = otherNodes.concat(storedProceduresNodes);
|
||||
this.children(allNodes);
|
||||
});
|
||||
}
|
||||
|
||||
public loadUserDefinedFunctions(): Q.Promise<any> {
|
||||
return this.container.documentClientUtility
|
||||
.readUserDefinedFunctions(this)
|
||||
.then((userDefinedFunctions: DataModels.UserDefinedFunction[]) => {
|
||||
const userDefinedFunctionsNodes: ViewModels.TreeNode[] = userDefinedFunctions.map(
|
||||
udf => new UserDefinedFunction(this.container, this, udf)
|
||||
);
|
||||
const otherNodes = this.children().filter(node => node.nodeKind !== "UserDefinedFunction");
|
||||
const allNodes = otherNodes.concat(userDefinedFunctionsNodes);
|
||||
this.children(allNodes);
|
||||
});
|
||||
return readUserDefinedFunctions(this).then((userDefinedFunctions: DataModels.UserDefinedFunction[]) => {
|
||||
const userDefinedFunctionsNodes: ViewModels.TreeNode[] = userDefinedFunctions.map(
|
||||
udf => new UserDefinedFunction(this.container, this, udf)
|
||||
);
|
||||
const otherNodes = this.children().filter(node => node.nodeKind !== "UserDefinedFunction");
|
||||
const allNodes = otherNodes.concat(userDefinedFunctionsNodes);
|
||||
this.children(allNodes);
|
||||
});
|
||||
}
|
||||
|
||||
public loadTriggers(): Q.Promise<any> {
|
||||
return this.container.documentClientUtility
|
||||
.readTriggers(this, null /*options*/)
|
||||
.then((triggers: DataModels.Trigger[]) => {
|
||||
const triggerNodes: ViewModels.TreeNode[] = triggers.map(trigger => new Trigger(this.container, this, trigger));
|
||||
const otherNodes = this.children().filter(node => node.nodeKind !== "Trigger");
|
||||
const allNodes = otherNodes.concat(triggerNodes);
|
||||
this.children(allNodes);
|
||||
});
|
||||
return readTriggers(this, null /*options*/).then((triggers: DataModels.Trigger[]) => {
|
||||
const triggerNodes: ViewModels.TreeNode[] = triggers.map(trigger => new Trigger(this.container, this, trigger));
|
||||
const otherNodes = this.children().filter(node => node.nodeKind !== "Trigger");
|
||||
const allNodes = otherNodes.concat(triggerNodes);
|
||||
this.children(allNodes);
|
||||
});
|
||||
}
|
||||
|
||||
public onDragOver(source: Collection, event: { originalEvent: DragEvent }) {
|
||||
@@ -1269,7 +1262,7 @@ export default class Collection implements ViewModels.Collection {
|
||||
const promises: Array<Q.Promise<any>> = [];
|
||||
|
||||
const triggerCreateDocument: (documentContent: any) => Q.Promise<any> = (documentContent: any) => {
|
||||
return this.container.documentClientUtility.createDocument(this, documentContent).then(
|
||||
return createDocument(this, documentContent).then(
|
||||
doc => {
|
||||
record.numSucceeded++;
|
||||
return Q.resolve();
|
||||
|
||||
Reference in New Issue
Block a user