@fluidframework/local-driver 0.59.2000-63294 → 0.59.3000-66610
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth.js +2 -2
- package/dist/auth.js.map +1 -1
- package/dist/localDeltaStorageService.js +1 -1
- package/dist/localDeltaStorageService.js.map +1 -1
- package/dist/localDocumentServiceFactory.d.ts.map +1 -1
- package/dist/localDocumentServiceFactory.js +10 -9
- package/dist/localDocumentServiceFactory.js.map +1 -1
- package/dist/localResolver.js +3 -3
- package/dist/localResolver.js.map +1 -1
- package/dist/localSessionStorageDb.d.ts.map +1 -1
- package/dist/localSessionStorageDb.js +16 -9
- package/dist/localSessionStorageDb.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/package.json +13 -13
- package/src/auth.ts +1 -1
- package/src/localDocumentServiceFactory.ts +4 -2
- package/src/localSessionStorageDb.ts +16 -9
- package/src/packageVersion.ts +1 -1
package/dist/auth.js
CHANGED
|
@@ -34,8 +34,8 @@ function generateToken(tenantId, documentId, key, scopes, user, lifetime = 60 *
|
|
|
34
34
|
exports.generateToken = generateToken;
|
|
35
35
|
function generateUser() {
|
|
36
36
|
const randomUser = {
|
|
37
|
-
id: uuid_1.v4(),
|
|
38
|
-
name: server_services_client_1.getRandomName(" ", true),
|
|
37
|
+
id: (0, uuid_1.v4)(),
|
|
38
|
+
name: (0, server_services_client_1.getRandomName)(" ", true),
|
|
39
39
|
};
|
|
40
40
|
return randomUser;
|
|
41
41
|
}
|
package/dist/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,yCAA8C;AAC9C,+BAAkC;AAClC,mFAAuE;AAEvE;;;GAGG;AACH,SAAgB,aAAa,CACzB,QAAgB,EAChB,UAAkB,EA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AAE,KAAK,SAAS,EAAE;QACnD,SAAS,GAAG,YAAY,EAAE,CAAC;KAC9B;IAED,0BAA0B;IAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IAEtD,MAAM,MAAM,GAAiB;QACzB,UAAU;QACV,MAAM;QACN,QAAQ;QACR,IAAI,EAAE,SAAS;QACf,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG,GAAG,QAAQ;QACnB,GAAG;KACN,CAAC;IAEF,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAC9B,OAAO,gBAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACvG,CAAC;AA5BD,sCA4BC;AAED,SAAgB,YAAY;IACxB,MAAM,UAAU,GAAG;QACf,EAAE,EAAE,IAAA,SAAI,GAAE;QACV,IAAI,EAAE,IAAA,sCAAa,EAAC,GAAG,EAAE,IAAI,CAAC;KACjC,CAAC;IAEF,OAAO,UAAU,CAAC;AACtB,CAAC;AAPD,oCAOC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITokenClaims, IUser, ScopeType } from \"@fluidframework/protocol-definitions\";\nimport { KJUR as jsrsasign } from \"jsrsasign\";\nimport { v4 as uuid } from \"uuid\";\nimport { getRandomName } from \"@fluidframework/server-services-client\";\n\n/**\n * Generates a JWT token to authorize against. We do not use the implementation in\n * services-client since it cannot run in the browser without polyfills.\n */\nexport function generateToken(\n tenantId: string,\n documentId: string,\n key: string,\n scopes: ScopeType[],\n user?: IUser,\n lifetime: number = 60 * 60,\n ver: string = \"1.0\"): string {\n let userClaim = (user) ? user : generateUser();\n if (userClaim.id === \"\" || userClaim.id === undefined) {\n userClaim = generateUser();\n }\n\n // Current time in seconds\n const now = Math.round((new Date()).getTime() / 1000);\n\n const claims: ITokenClaims = {\n documentId,\n scopes,\n tenantId,\n user: userClaim,\n iat: now,\n exp: now + lifetime,\n ver,\n };\n\n const utf8Key = { utf8: key };\n return jsrsasign.jws.JWS.sign(null, JSON.stringify({ alg: \"HS256\", typ: \"JWT\" }), claims, utf8Key);\n}\n\nexport function generateUser(): IUser {\n const randomUser = {\n id: uuid(),\n name: getRandomName(\" \", true),\n };\n\n return randomUser;\n}\n"]}
|
|
@@ -16,7 +16,7 @@ class LocalDeltaStorageService {
|
|
|
16
16
|
this.databaseManager = databaseManager;
|
|
17
17
|
}
|
|
18
18
|
fetchMessages(from, to, abortSignal, cachedOnly) {
|
|
19
|
-
return driver_utils_1.streamFromMessages(this.getCore(from, to));
|
|
19
|
+
return (0, driver_utils_1.streamFromMessages)(this.getCore(from, to));
|
|
20
20
|
}
|
|
21
21
|
async getCore(from, to) {
|
|
22
22
|
const query = { documentId: this.id, tenantId: this.tenantId };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localDeltaStorageService.js","sourceRoot":"","sources":["../src/localDeltaStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH,+DAAkE;AAElE;;GAEG;AACH,MAAa,wBAAwB;IACjC,YACqB,QAAgB,EAChB,EAAU,EACV,eAAiC;QAFjC,aAAQ,GAAR,QAAQ,CAAQ;QAChB,OAAE,GAAF,EAAE,CAAQ;QACV,oBAAe,GAAf,eAAe,CAAkB;IACtD,CAAC;IAEM,aAAa,CAChB,IAAY,EACZ,EAAsB,EACtB,WAAyB,EACzB,UAAoB;QAEhB,OAAO,iCAAkB,
|
|
1
|
+
{"version":3,"file":"localDeltaStorageService.js","sourceRoot":"","sources":["../src/localDeltaStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH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n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport * as api from \"@fluidframework/driver-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { IDatabaseManager } from \"@fluidframework/server-services-core\";\nimport { streamFromMessages } from \"@fluidframework/driver-utils\";\n\n/**\n * Provides access to the underlying delta storage on the server for local driver.\n */\nexport class LocalDeltaStorageService implements api.IDocumentDeltaStorageService {\n constructor(\n private readonly tenantId: string,\n private readonly id: string,\n private readonly databaseManager: IDatabaseManager) {\n }\n\n public fetchMessages(\n from: number,\n to: number | undefined,\n abortSignal?: AbortSignal,\n cachedOnly?: boolean,\n ): api.IStream<ISequencedDocumentMessage[]> {\n return streamFromMessages(this.getCore(from, to));\n }\n\n private async getCore(from: number, to?: number) {\n const query = { documentId: this.id, tenantId: this.tenantId };\n query[\"operation.sequenceNumber\"] = {};\n query[\"operation.sequenceNumber\"].$gt = from - 1; // from is inclusive\n\n // This looks like a bug. It used to work without setting $lt key. Now it does not\n // Need follow up\n query[\"operation.sequenceNumber\"].$lt = to ?? Number.MAX_SAFE_INTEGER;\n\n const allDeltas = await this.databaseManager.getDeltaCollection(this.tenantId, this.id);\n const dbDeltas = await allDeltas.find(query, { \"operation.sequenceNumber\": 1 });\n const messages = dbDeltas.map((delta) => delta.operation);\n return messages;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localDocumentServiceFactory.d.ts","sourceRoot":"","sources":["../src/localDocumentServiceFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"localDocumentServiceFactory.d.ts","sourceRoot":"","sources":["../src/localDocumentServiceFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACH,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACxB,YAAY,EACf,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE1E,OAAO,EAAE,2BAA2B,EAA8B,MAAM,qCAAqC,CAAC;AAM9G,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAKnF;;GAEG;AACH,qBAAa,2BAA4B,YAAW,uBAAuB;IAUnE,OAAO,CAAC,QAAQ,CAAC,0BAA0B;IAC3C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAC1B,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC;IAX1C,SAAgB,YAAY,iBAAiB;IAG7C,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAAwD;IAEpG;;OAEG;gBAEkB,0BAA0B,EAAE,2BAA2B,EACvD,QAAQ,CAAC,sCAA0B,EACnC,oBAAoB,CAAC,8BAAkB;IAE/C,eAAe,CACxB,gBAAgB,EAAE,YAAY,GAAG,SAAS,EAC1C,WAAW,EAAE,YAAY,EACzB,MAAM,CAAC,EAAE,oBAAoB,EAC7B,kBAAkB,CAAC,EAAE,OAAO,GAC7B,OAAO,CAAC,gBAAgB,CAAC;IAqC5B;;;;OAIG;IACU,qBAAqB,CAC9B,WAAW,EAAE,YAAY,EACzB,MAAM,CAAC,EAAE,oBAAoB,EAC7B,kBAAkB,CAAC,EAAE,OAAO,GAC7B,OAAO,CAAC,gBAAgB,CAAC;IA4B5B;;;;OAIG;IACI,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM;IAQlE;;;;;;OAMG;IACI,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,GAAG;CAOzF"}
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.LocalDocumentServiceFactory = void 0;
|
|
8
8
|
const url_1 = require("url");
|
|
9
|
-
const common_utils_1 = require("@fluidframework/common-utils");
|
|
10
9
|
const routerlicious_driver_1 = require("@fluidframework/routerlicious-driver");
|
|
11
10
|
const driver_utils_1 = require("@fluidframework/driver-utils");
|
|
12
11
|
const server_services_client_1 = require("@fluidframework/server-services-client");
|
|
@@ -28,8 +27,10 @@ class LocalDocumentServiceFactory {
|
|
|
28
27
|
}
|
|
29
28
|
async createContainer(createNewSummary, resolvedUrl, logger, clientIsSummarizer) {
|
|
30
29
|
var _a, _b, _c;
|
|
31
|
-
driver_utils_1.ensureFluidResolvedUrl(resolvedUrl);
|
|
32
|
-
|
|
30
|
+
(0, driver_utils_1.ensureFluidResolvedUrl)(resolvedUrl);
|
|
31
|
+
if (createNewSummary === undefined) {
|
|
32
|
+
throw new Error("Empty file summary creation isn't supported in this driver.");
|
|
33
|
+
}
|
|
33
34
|
const pathName = new URL(resolvedUrl.url).pathname;
|
|
34
35
|
const pathArr = pathName.split("/");
|
|
35
36
|
const tenantId = pathArr[pathArr.length - 2];
|
|
@@ -43,10 +44,10 @@ class LocalDocumentServiceFactory {
|
|
|
43
44
|
if (!(protocolSummary && appSummary)) {
|
|
44
45
|
throw new Error("Protocol and App Summary required in the full summary");
|
|
45
46
|
}
|
|
46
|
-
const documentAttributes = driver_utils_1.getDocAttributesFromProtocolSummary(protocolSummary);
|
|
47
|
-
const quorumValues = driver_utils_1.getQuorumValuesFromProtocolSummary(protocolSummary);
|
|
47
|
+
const documentAttributes = (0, driver_utils_1.getDocAttributesFromProtocolSummary)(protocolSummary);
|
|
48
|
+
const quorumValues = (0, driver_utils_1.getQuorumValuesFromProtocolSummary)(protocolSummary);
|
|
48
49
|
const sequenceNumber = documentAttributes.sequenceNumber;
|
|
49
|
-
await documentStorage.createDocument(tenantId, id, appSummary, sequenceNumber, (_a = documentAttributes.term) !== null && _a !== void 0 ? _a : 1, server_services_client_1.defaultHash, (_b = resolvedUrl.endpoints.ordererUrl) !== null && _b !== void 0 ? _b : "", (_c = resolvedUrl.endpoints.storageUrl) !== null && _c !== void 0 ? _c : "", quorumValues);
|
|
50
|
+
await documentStorage.createDocument(tenantId, id, appSummary, sequenceNumber, (_a = documentAttributes.term) !== null && _a !== void 0 ? _a : 1, server_services_client_1.defaultHash, (_b = resolvedUrl.endpoints.ordererUrl) !== null && _b !== void 0 ? _b : "", (_c = resolvedUrl.endpoints.storageUrl) !== null && _c !== void 0 ? _c : "", quorumValues, false);
|
|
50
51
|
return this.createDocumentService(resolvedUrl, logger, clientIsSummarizer);
|
|
51
52
|
}
|
|
52
53
|
/**
|
|
@@ -55,8 +56,8 @@ class LocalDocumentServiceFactory {
|
|
|
55
56
|
* @param resolvedUrl - resolved URL of document
|
|
56
57
|
*/
|
|
57
58
|
async createDocumentService(resolvedUrl, logger, clientIsSummarizer) {
|
|
58
|
-
driver_utils_1.ensureFluidResolvedUrl(resolvedUrl);
|
|
59
|
-
const parsedUrl = url_1.parse(resolvedUrl.url);
|
|
59
|
+
(0, driver_utils_1.ensureFluidResolvedUrl)(resolvedUrl);
|
|
60
|
+
const parsedUrl = (0, url_1.parse)(resolvedUrl.url);
|
|
60
61
|
const [, tenantId, documentId] = parsedUrl.path ? parsedUrl.path.split("/") : [];
|
|
61
62
|
if (!documentId || !tenantId) {
|
|
62
63
|
throw new Error(`Couldn't parse resolved url. [documentId:${documentId}][tenantId:${tenantId}]`);
|
|
@@ -67,7 +68,7 @@ class LocalDocumentServiceFactory {
|
|
|
67
68
|
throw new Error(`Token was not provided.`);
|
|
68
69
|
}
|
|
69
70
|
const tokenProvider = new routerlicious_driver_1.DefaultTokenProvider(jwtToken);
|
|
70
|
-
return localDocumentService_1.createLocalDocumentService(resolvedUrl, this.localDeltaConnectionServer, tokenProvider, tenantId, documentId, this.documentDeltaConnectionsMap, this.policies, this.innerDocumentService);
|
|
71
|
+
return (0, localDocumentService_1.createLocalDocumentService)(resolvedUrl, this.localDeltaConnectionServer, tokenProvider, tenantId, documentId, this.documentDeltaConnectionsMap, this.policies, this.innerDocumentService);
|
|
71
72
|
}
|
|
72
73
|
/**
|
|
73
74
|
* Gets the document delta connection for the clientId and asks it to disconnect the client.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localDocumentServiceFactory.js","sourceRoot":"","sources":["../src/localDocumentServiceFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6BAA4B;
|
|
1
|
+
{"version":3,"file":"localDocumentServiceFactory.js","sourceRoot":"","sources":["../src/localDocumentServiceFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6BAA4B;AAQ5B,+EAA4E;AAE5E,+DAIsC;AAEtC,mFAAqE;AAErE,iEAAoE;AAEpE;;GAEG;AACH,MAAa,2BAA2B;IAMpC;;OAEG;IACH,YACqB,0BAAuD,EACvD,QAAmC,EACnC,oBAAuC;QAFvC,+BAA0B,GAA1B,0BAA0B,CAA6B;QACvD,aAAQ,GAAR,QAAQ,CAA2B;QACnC,yBAAoB,GAApB,oBAAoB,CAAmB;QAX5C,iBAAY,GAAG,aAAa,CAAC;QAE7C,6CAA6C;QAC5B,gCAA2B,GAA8C,IAAI,GAAG,EAAE,CAAC;IAQpC,CAAC;IAE1D,KAAK,CAAC,eAAe,CACxB,gBAA0C,EAC1C,WAAyB,EACzB,MAA6B,EAC7B,kBAA4B;;QAE5B,IAAA,qCAAsB,EAAC,WAAW,CAAC,CAAC;QACpC,IAAI,gBAAgB,KAAK,SAAS,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;SAClF;QACD,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;QACnD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACpC,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC7C,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;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CAAC;SACzD;QACD,oEAAoE;QACpE,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACpF,CAAC;CACJ;AAxHD,kEAwHC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { parse } from \"url\";\nimport {\n IDocumentService,\n IDocumentServiceFactory,\n IDocumentServicePolicies,\n IResolvedUrl,\n} from \"@fluidframework/driver-definitions\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/common-definitions\";\nimport { DefaultTokenProvider } from \"@fluidframework/routerlicious-driver\";\nimport { ILocalDeltaConnectionServer, LocalDeltaConnectionServer } from \"@fluidframework/server-local-server\";\nimport {\n ensureFluidResolvedUrl,\n getDocAttributesFromProtocolSummary,\n getQuorumValuesFromProtocolSummary,\n} from \"@fluidframework/driver-utils\";\nimport { ISummaryTree, NackErrorType } from \"@fluidframework/protocol-definitions\";\nimport { defaultHash } from \"@fluidframework/server-services-client\";\nimport { LocalDocumentDeltaConnection } from \"./localDocumentDeltaConnection\";\nimport { createLocalDocumentService } from \"./localDocumentService\";\n\n/**\n * Implementation of document service factory for local use.\n */\nexport class LocalDocumentServiceFactory implements IDocumentServiceFactory {\n public readonly protocolName = \"fluid-test:\";\n\n // A map of clientId to LocalDocumentService.\n private readonly documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection> = new Map();\n\n /**\n * @param localDeltaConnectionServer - delta connection server for ops\n */\n constructor(\n private readonly localDeltaConnectionServer: ILocalDeltaConnectionServer,\n private readonly policies?: IDocumentServicePolicies,\n private readonly innerDocumentService?: IDocumentService) { }\n\n public async createContainer(\n createNewSummary: ISummaryTree | undefined,\n resolvedUrl: IResolvedUrl,\n logger?: ITelemetryBaseLogger,\n clientIsSummarizer?: boolean,\n ): Promise<IDocumentService> {\n ensureFluidResolvedUrl(resolvedUrl);\n if (createNewSummary === undefined) {\n throw new Error(\"Empty file summary creation isn't supported in this driver.\");\n }\n const pathName = new URL(resolvedUrl.url).pathname;\n const pathArr = pathName.split(\"/\");\n const tenantId = pathArr[pathArr.length - 2];\n const id = pathArr[pathArr.length - 1];\n if (!this.localDeltaConnectionServer) {\n throw new Error(\"Provide the localDeltaConnectionServer!!\");\n }\n const documentStorage = (this.localDeltaConnectionServer as LocalDeltaConnectionServer).documentStorage;\n\n const protocolSummary = createNewSummary.tree[\".protocol\"] as ISummaryTree;\n const appSummary = createNewSummary.tree[\".app\"] as ISummaryTree;\n if (!(protocolSummary && appSummary)) {\n throw new Error(\"Protocol and App Summary required in the full summary\");\n }\n const documentAttributes = getDocAttributesFromProtocolSummary(protocolSummary);\n const quorumValues = getQuorumValuesFromProtocolSummary(protocolSummary);\n const sequenceNumber = documentAttributes.sequenceNumber;\n await documentStorage.createDocument(\n tenantId,\n id,\n appSummary,\n sequenceNumber,\n documentAttributes.term ?? 1,\n defaultHash,\n resolvedUrl.endpoints.ordererUrl ?? \"\",\n resolvedUrl.endpoints.storageUrl ?? \"\",\n quorumValues,\n false,\n );\n return this.createDocumentService(resolvedUrl, logger, clientIsSummarizer);\n }\n\n /**\n * Creates and returns a document service for testing using the given resolved\n * URL for the tenant ID, document ID, and token.\n * @param resolvedUrl - resolved URL of document\n */\n public async createDocumentService(\n resolvedUrl: IResolvedUrl,\n logger?: ITelemetryBaseLogger,\n clientIsSummarizer?: boolean,\n ): Promise<IDocumentService> {\n ensureFluidResolvedUrl(resolvedUrl);\n\n const parsedUrl = parse(resolvedUrl.url);\n const [, tenantId, documentId] = parsedUrl.path ? parsedUrl.path.split(\"/\") : [];\n if (!documentId || !tenantId) {\n throw new Error(`Couldn't parse resolved url. [documentId:${documentId}][tenantId:${tenantId}]`);\n }\n\n const fluidResolvedUrl = resolvedUrl;\n const jwtToken = fluidResolvedUrl.tokens.jwt;\n if (!jwtToken) {\n throw new Error(`Token was not provided.`);\n }\n\n const tokenProvider = new DefaultTokenProvider(jwtToken);\n\n return createLocalDocumentService(\n resolvedUrl,\n this.localDeltaConnectionServer,\n tokenProvider,\n tenantId,\n documentId,\n this.documentDeltaConnectionsMap,\n this.policies,\n this.innerDocumentService);\n }\n\n /**\n * Gets the document delta connection for the clientId and asks it to disconnect the client.\n * @param clientId - The ID of the client to be disconnected.\n * @param disconnectReason - The reason of the disconnection.\n */\n public disconnectClient(clientId: string, disconnectReason: string) {\n if (!this.documentDeltaConnectionsMap.has(clientId)) {\n throw new Error(`No client with the id: ${clientId}`);\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.documentDeltaConnectionsMap.get(clientId)!.disconnectClient(disconnectReason);\n }\n\n /**\n * Gets the document delta connection for the clientId and asks it to nack the client.\n * @param clientId - The ID of the client to be Nack'd.\n * @param code - An error code number that represents the error. It will be a valid HTTP error code.\n * @param type - Type of the Nack.\n * @param message - A message about the nack for debugging/logging/telemetry purposes.\n */\n public nackClient(clientId: string, code?: number, type?: NackErrorType, message?: any) {\n if (!this.documentDeltaConnectionsMap.has(clientId)) {\n throw new Error(`No client with the id: ${clientId}`);\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.documentDeltaConnectionsMap.get(clientId)!.nackClient(code, type, message);\n }\n}\n"]}
|
package/dist/localResolver.js
CHANGED
|
@@ -47,7 +47,7 @@ class LocalResolver {
|
|
|
47
47
|
storageUrl: `http://localhost:3000/repos/${this.tenantId}`,
|
|
48
48
|
},
|
|
49
49
|
id: documentId,
|
|
50
|
-
tokens: { jwt: auth_1.generateToken(this.tenantId, documentId, this.tokenKey, scopes) },
|
|
50
|
+
tokens: { jwt: (0, auth_1.generateToken)(this.tenantId, documentId, this.tokenKey, scopes) },
|
|
51
51
|
type: "fluid",
|
|
52
52
|
url: `fluid-test://localhost:3000/${this.tenantId}/${fullPath}`,
|
|
53
53
|
};
|
|
@@ -59,12 +59,12 @@ class LocalResolver {
|
|
|
59
59
|
url = url.substr(1);
|
|
60
60
|
}
|
|
61
61
|
const fluidResolvedUrl = resolvedUrl;
|
|
62
|
-
const parsedUrl = url_1.parse(fluidResolvedUrl.url);
|
|
62
|
+
const parsedUrl = (0, url_1.parse)(fluidResolvedUrl.url);
|
|
63
63
|
if (parsedUrl.pathname === null) {
|
|
64
64
|
throw new Error("Url should contain tenant and docId!!");
|
|
65
65
|
}
|
|
66
66
|
const [, , documentId] = parsedUrl.pathname.split("/");
|
|
67
|
-
common_utils_1.assert(!!documentId, 0x09a /* "'documentId' must be a defined, non-zero length string." */);
|
|
67
|
+
(0, common_utils_1.assert)(!!documentId, 0x09a /* "'documentId' must be a defined, non-zero length string." */);
|
|
68
68
|
return `http://localhost:3000/${documentId}/${url}`;
|
|
69
69
|
}
|
|
70
70
|
createCreateNewRequest(documentId) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localResolver.js","sourceRoot":"","sources":["../src/localResolver.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6BAA4B;AAC5B,+DAAsD;AAEtD,2EAK4C;AAC5C,+EAAiE;AACjE,iCAAuC;AAEvC,SAAgB,mCAAmC,CAAC,UAAkB;IAClE,MAAM,gBAAgB,GAAa;QAC/B,GAAG,EAAE,yBAAyB,UAAU,EAAE;QAC1C,OAAO,EAAE;YACL,CAAC,iCAAY,CAAC,SAAS,CAAC,EAAE,IAAI;SACjC;KACJ,CAAC;IACF,OAAO,gBAAgB,CAAC;AAC5B,CAAC;AARD,kFAQC;AAED;;;GAGG;AACH,MAAa,aAAa;IAItB;QAHiB,aAAQ,GAAG,UAAU,CAAC;QACtB,aAAQ,GAAG,UAAU,CAAC;IAEvB,CAAC;IAEjB;;;;;OAKG;IACI,KAAK,CAAC,OAAO,CAAC,OAAiB;QAClC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACvC,MAAM,QAAQ,GAAG,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,C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CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvD,IAAA,qBAAM,EAAC,CAAC,CAAC,UAAU,EAAE,KAAK,CAAC,+DAA+D,CAAC,CAAC;QAE5F,OAAO,yBAAyB,UAAU,IAAI,GAAG,EAAE,CAAC;IACxD,CAAC;IAEM,sBAAsB,CAAC,UAAkB;QAC5C,OAAO,mCAAmC,CAAC,UAAU,CAAC,CAAC;IAC3D,CAAC;CACJ;AApDD,sCAoDC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { parse } from \"url\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport { IRequest } from \"@fluidframework/core-interfaces\";\nimport {\n IFluidResolvedUrl,\n IResolvedUrl,\n IUrlResolver,\n DriverHeader,\n} from \"@fluidframework/driver-definitions\";\nimport { ScopeType } from \"@fluidframework/protocol-definitions\";\nimport { generateToken } from \"./auth\";\n\nexport function createLocalResolverCreateNewRequest(documentId: string): IRequest {\n const createNewRequest: IRequest = {\n url: `http://localhost:3000/${documentId}`,\n headers: {\n [DriverHeader.createNew]: true,\n },\n };\n return createNewRequest;\n}\n\n/**\n * Resolves URLs by providing fake URLs which succeed with the other\n * related local classes.\n */\nexport class LocalResolver implements IUrlResolver {\n private readonly tenantId = \"tenantId\";\n private readonly tokenKey = \"tokenKey\";\n\n constructor() { }\n\n /**\n * Resolves URL requests by providing fake URLs with an actually generated\n * token from constant test strings. The root of the URL is fake, but the\n * remaining relative URL can still be parsed.\n * @param request - request to handle\n */\n public async resolve(request: IRequest): Promise<IResolvedUrl> {\n const parsedUrl = new URL(request.url);\n const fullPath = `${parsedUrl.pathname.substr(1)}${parsedUrl.search}`;\n const documentId = fullPath.split(\"/\")[0];\n const scopes = [ScopeType.DocRead, ScopeType.DocWrite, ScopeType.SummaryWrite];\n const resolved: IFluidResolvedUrl = {\n endpoints: {\n deltaStorageUrl: `http://localhost:3000/deltas/${this.tenantId}/${documentId}`,\n ordererUrl: \"http://localhost:3000\",\n storageUrl: `http://localhost:3000/repos/${this.tenantId}`,\n },\n id: documentId,\n tokens: { jwt: generateToken(this.tenantId, documentId, this.tokenKey, scopes) },\n type: \"fluid\",\n url: `fluid-test://localhost:3000/${this.tenantId}/${fullPath}`,\n };\n\n return resolved;\n }\n\n public async getAbsoluteUrl(resolvedUrl: IResolvedUrl, relativeUrl: string): Promise<string> {\n let url = relativeUrl;\n if (url.startsWith(\"/\")) {\n url = url.substr(1);\n }\n const fluidResolvedUrl = resolvedUrl as IFluidResolvedUrl;\n\n const parsedUrl = parse(fluidResolvedUrl.url);\n if (parsedUrl.pathname === null) {\n throw new Error(\"Url should contain tenant and docId!!\");\n }\n const [, , documentId] = parsedUrl.pathname.split(\"/\");\n assert(!!documentId, 0x09a /* \"'documentId' must be a defined, non-zero length string.\" */);\n\n return `http://localhost:3000/${documentId}/${url}`;\n }\n\n public createCreateNewRequest(documentId: string): IRequest {\n return createLocalResolverCreateNewRequest(documentId);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localSessionStorageDb.d.ts","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":"AAKA,OAAO,EAAe,GAAG,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"localSessionStorageDb.d.ts","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":"AAKA,OAAO,EAAe,GAAG,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAmSnE;;GAEG;AACH,qBAAa,4BAA6B,YAAW,cAAc;IAC/D,SAAgB,YAAY,EAAE,GAAG,CAAC;gBACtB,SAAS,EAAE,MAAM;IAGhB,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;CAGvC"}
|
|
@@ -15,7 +15,7 @@ class LocalSessionStorageCollection {
|
|
|
15
15
|
constructor(namespace, name) {
|
|
16
16
|
this.collectionName = `${namespace}-${name}`;
|
|
17
17
|
}
|
|
18
|
-
aggregate(
|
|
18
|
+
aggregate(pipeline, options) {
|
|
19
19
|
throw new Error("Method Not Implemented");
|
|
20
20
|
}
|
|
21
21
|
async updateMany(filter, set, addToSet) {
|
|
@@ -26,7 +26,8 @@ class LocalSessionStorageCollection {
|
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.find}
|
|
29
|
-
|
|
29
|
+
*/
|
|
30
|
+
/*
|
|
30
31
|
* Each query key consists of several keys separated by '.' e.g: "operation.sequenceNumber".
|
|
31
32
|
* The hierarchical syntax allows finding nested key patterns.
|
|
32
33
|
*/
|
|
@@ -86,7 +87,8 @@ class LocalSessionStorageCollection {
|
|
|
86
87
|
}
|
|
87
88
|
/**
|
|
88
89
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}
|
|
89
|
-
|
|
90
|
+
*/
|
|
91
|
+
/*
|
|
90
92
|
* Query is expected to have a member "_id" which is a string used to find value in the database.
|
|
91
93
|
*/
|
|
92
94
|
async findOne(query) {
|
|
@@ -94,7 +96,8 @@ class LocalSessionStorageCollection {
|
|
|
94
96
|
}
|
|
95
97
|
/**
|
|
96
98
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.update}
|
|
97
|
-
|
|
99
|
+
*/
|
|
100
|
+
/*
|
|
98
101
|
* Query is expected to have a member "_id" which is a string used to find value in the database.
|
|
99
102
|
*/
|
|
100
103
|
async update(query, set, addToSet) {
|
|
@@ -111,7 +114,8 @@ class LocalSessionStorageCollection {
|
|
|
111
114
|
}
|
|
112
115
|
/**
|
|
113
116
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}
|
|
114
|
-
|
|
117
|
+
*/
|
|
118
|
+
/*
|
|
115
119
|
* Query is expected to have a member "_id" which is a string used to find value in the database.
|
|
116
120
|
*/
|
|
117
121
|
async upsert(query, set, addToSet) {
|
|
@@ -128,7 +132,8 @@ class LocalSessionStorageCollection {
|
|
|
128
132
|
}
|
|
129
133
|
/**
|
|
130
134
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}
|
|
131
|
-
|
|
135
|
+
*/
|
|
136
|
+
/*
|
|
132
137
|
* Value is expected to have a member "_id" which is a string used to search in the database.
|
|
133
138
|
*/
|
|
134
139
|
async insertOne(value) {
|
|
@@ -144,7 +149,8 @@ class LocalSessionStorageCollection {
|
|
|
144
149
|
}
|
|
145
150
|
/**
|
|
146
151
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}
|
|
147
|
-
|
|
152
|
+
*/
|
|
153
|
+
/*
|
|
148
154
|
* Value and query are expected to have a member "_id" which is a string used to search or insert in the database.
|
|
149
155
|
*/
|
|
150
156
|
async findOrCreate(query, value) {
|
|
@@ -157,7 +163,8 @@ class LocalSessionStorageCollection {
|
|
|
157
163
|
}
|
|
158
164
|
/**
|
|
159
165
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}
|
|
160
|
-
|
|
166
|
+
*/
|
|
167
|
+
/*
|
|
161
168
|
* Each element in values is expected to have a member "_id" which is a string used to insert in the database.
|
|
162
169
|
*/
|
|
163
170
|
async insertMany(values, ordered) {
|
|
@@ -206,7 +213,7 @@ class LocalSessionStorageCollection {
|
|
|
206
213
|
for (const value of values) {
|
|
207
214
|
if (value) {
|
|
208
215
|
if (!value._id) {
|
|
209
|
-
value._id = uuid_1.v4();
|
|
216
|
+
value._id = (0, uuid_1.v4)();
|
|
210
217
|
}
|
|
211
218
|
sessionStorage.setItem(`${this.collectionName}-${value._id}`, JSON.stringify(value));
|
|
212
219
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localSessionStorageDb.js","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,mCAAsC;AAGtC,+BAAkC;AAElC;;;GA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AC1E,CAAC;CACJ;AAED;;GAEG;AACH,MAAa,4BAA4B;IAErC,YAAY,SAAiB;QACzB,IAAI,CAAC,YAAY,GAAG,IAAI,qBAAqB,CAAC,SAAS,CAAC,CAAC;IAC7D,CAAC;IACM,KAAK,CAAC,OAAO;QAChB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;CACJ;AARD,oEAQC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { EventEmitter } from \"events\";\nimport { ICollection, IDb } from \"@fluidframework/server-services-core\";\nimport { ITestDbFactory } from \"@fluidframework/server-test-utils\";\nimport { v4 as uuid } from \"uuid\";\n\n/**\n * A collection for local session storage, where data is stored in the browser\n * Functions include database operations such as queries, insertion and update.\n */\nclass LocalSessionStorageCollection<T> implements ICollection<T> {\n private readonly collectionName: string;\n constructor(namespace, name) {\n this.collectionName = `${namespace}-${name}`;\n }\n\n public aggregate(group: any, options?: any): any {\n throw new Error(\"Method Not Implemented\");\n }\n\n public async updateMany(filter: any, set: any, addToSet: any): Promise<void> {\n throw new Error(\"Method Not Implemented\");\n }\n public async distinct(key: any, query: any): Promise<any> {\n throw new Error(\"Method Not Implemented\");\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.find}\n *\n * Each query key consists of several keys separated by '.' e.g: \"operation.sequenceNumber\".\n * The hierarchical syntax allows finding nested key patterns.\n */\n public async find(query: any, sort: any): Promise<any[]> {\n // split the keys and get the corresponding value\n function getValueByKey(propertyBag, key: string) {\n const keys = key.split(\".\");\n let value = propertyBag;\n keys.forEach((splitKey) => {\n value = value[splitKey];\n });\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value;\n }\n\n // getting keys of the query we are trying to find\n const queryKeys = Object.keys(query);\n let filteredCollection = this.getAllInternal();\n queryKeys.forEach((key) => {\n if (!query[key]) {\n return;\n }\n if (query[key].$gt > 0 || query[key].$lt > 0) {\n if (query[key].$gt > 0) {\n filteredCollection = filteredCollection.filter(\n (value) => getValueByKey(value, key) > query[key].$gt);\n }\n if (query[key].$lt > 0) {\n filteredCollection = filteredCollection.filter(\n (value) => getValueByKey(value, key) < query[key].$lt);\n }\n } else {\n filteredCollection = filteredCollection.filter(\n (value) => getValueByKey(value, key) === query[key]);\n }\n });\n\n if (sort && Object.keys(sort).length === 1) {\n // eslint-disable-next-line no-inner-declarations\n function compare(a, b) {\n const sortKey = Object.keys(sort)[0];\n if (sort[sortKey] === 1) {\n // A goes before b, sorting in ascending order\n return getValueByKey(a, sortKey) - getValueByKey(b, sortKey);\n } else {\n // B goes before a, sorting in descending order\n return getValueByKey(b, sortKey) - getValueByKey(a, sortKey);\n }\n }\n\n filteredCollection = filteredCollection.sort(compare);\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return filteredCollection;\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}\n */\n public async findAll(): Promise<any[]> {\n return Promise.resolve(this.getAllInternal());\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}\n *\n * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n */\n public async findOne(query: any): Promise<any> {\n return Promise.resolve(this.findOneInternal(query));\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.update}\n *\n * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n */\n public async update(query: any, set: any, addToSet: any): Promise<void> {\n const value = this.findOneInternal(query);\n if (!value) {\n throw new Error(\"Not found\");\n } else {\n for (const key of Object.keys(set)) {\n value[key] = set[key];\n }\n this.insertInternal(value);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}\n *\n * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n */\n public async upsert(query: any, set: any, addToSet: any): Promise<void> {\n const value = this.findOneInternal(query);\n if (!value) {\n this.insertInternal(set);\n } else {\n for (const key of Object.keys(set)) {\n value[key] = set[key];\n }\n this.insertInternal(value);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}\n *\n * Value is expected to have a member \"_id\" which is a string used to search in the database.\n */\n public async insertOne(value: any): Promise<any> {\n const presentVal = this.findOneInternal(value);\n // Only raise error when the object is present and the value is not equal.\n if (presentVal) {\n if (JSON.stringify(presentVal) === JSON.stringify(value)) {\n return;\n }\n throw new Error(\"Existing Object!!\");\n }\n\n return this.insertInternal(value);\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}\n *\n * Value and query are expected to have a member \"_id\" which is a string used to search or insert in the database.\n */\n public async findOrCreate(query: any, value: any): Promise<{ value: any, existing: boolean }> {\n const existing = this.findOneInternal(query);\n if (existing) {\n return { value: existing, existing: true };\n }\n this.insertInternal(value);\n return { value, existing: false };\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}\n *\n * Each element in values is expected to have a member \"_id\" which is a string used to insert in the database.\n */\n public async insertMany(values: any[], ordered: boolean): Promise<void> {\n this.insertInternal(...values);\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteOne}\n */\n public async deleteOne(query: any): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteMany}\n */\n public async deleteMany(query: any): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.createIndex}\n */\n public async createIndex(index: any, unique: boolean): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * Return all values in the database\n */\n private getAllInternal(): any[] {\n const values: string[] = [];\n for (let i = 0; i < sessionStorage.length; i++) {\n const key = sessionStorage.key(i);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n if (key!.startsWith(this.collectionName)) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n values.push(JSON.parse(sessionStorage.getItem(key!)!));\n }\n }\n return values;\n }\n\n /**\n * Inserts values into the session storge.\n * Values are expected to have a member \"_id\" which is a unique id, otherwise will be assigned one\n *\n * @param values - data to insert to the database\n */\n private insertInternal(...values: any[]) {\n for (const value of values) {\n if (value) {\n if (!value._id) {\n value._id = uuid();\n }\n sessionStorage.setItem(`${this.collectionName}-${value._id}`, JSON.stringify(value));\n }\n }\n }\n\n /**\n * Finds the query in session storage and returns its value.\n * Returns null if query is not found.\n * Query is expected to have a member \"_id\" which is a unique id.\n *\n * @param query - what to find in the database\n */\n private findOneInternal(query: any): any {\n if (query._id) {\n const json = sessionStorage.getItem(`${this.collectionName}-${query._id}`);\n if (json) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return JSON.parse(json);\n }\n } else {\n const queryKeys = Object.keys(query);\n for (let i = 0; i < sessionStorage.length; i++) {\n const ssKey = sessionStorage.key(i);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n if (!ssKey!.startsWith(this.collectionName)) {\n continue;\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const value = JSON.parse(sessionStorage.getItem(ssKey!)!);\n for (const qk of queryKeys) {\n if (value[qk] !== query[qk]) {\n continue;\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value;\n }\n }\n return null;\n }\n}\n\n/**\n * A database for testing that stores data in the browsers session storage\n */\nclass LocalSessionStorageDb extends EventEmitter implements IDb {\n private readonly collections = new Map<string, LocalSessionStorageCollection<any>>();\n constructor(private readonly namespace) {\n super();\n }\n public async close(): Promise<void> {\n return Promise.resolve();\n }\n public collection<T>(name: string): ICollection<T> {\n if (!this.collections.has(name)) {\n this.collections.set(name, new LocalSessionStorageCollection<T>(`${this.namespace}-db`, name));\n }\n return this.collections.get(name) as LocalSessionStorageCollection<T>;\n }\n}\n\n/**\n * A database factory for testing that stores data in the browsers session storage\n */\nexport class LocalSessionStorageDbFactory implements ITestDbFactory {\n public readonly testDatabase: IDb;\n constructor(namespace: string) {\n this.testDatabase = new LocalSessionStorageDb(namespace);\n }\n public async connect(): Promise<IDb> {\n return this.testDatabase;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"localSessionStorageDb.js","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,mCAAsC;AAGtC,+BAAkC;AAElC;;;GAGG;AACH,MAAM,6BAA6B;IAE/B,YAAY,SAAS,EAAE,IAAI;QACvB,IAAI,CAAC,cAAc,GAAG,GAAG,SAAS,IAAI,IAAI,EAAE,CAAC;IACjD,CAAC;IAEM,SAAS,CAAC,QAAa,EAAE,OAAa;QACzC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC9C,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,MAAW,EAAE,GAAQ,EAAE,QAAa;QACxD,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC9C,CAAC;IACM,KAAK,CAAC,QAAQ,CAAC,GAAQ,EAAE,KAAU;QACtC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH;;;OAGG;IACI,KAAK,CAAC,IAAI,CAAC,KAAU,EAAE,IAAS;QACnC,iDAAiD;QACjD,SAAS,aAAa,CAAC,WAAW,EAAE,GAAW;YAC3C,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAI,KAAK,GAAG,WAAW,CAAC;YACxB,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACtB,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;YAC5B,CAAC,CAAC,CAAC;YACH,+DAA+D;YAC/D,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,kDAAkD;QAClD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,kBAAkB,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QAC/C,SAA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AI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAC7B,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,6BAA6B,CAAI,GAAG,IAAI,CAAC,SAAS,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;SAClG;QACD,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAqC,CAAC;IAC1E,CAAC;CACJ;AAED;;GAEG;AACH,MAAa,4BAA4B;IAErC,YAAY,SAAiB;QACzB,IAAI,CAAC,YAAY,GAAG,IAAI,qBAAqB,CAAC,SAAS,CAAC,CAAC;IAC7D,CAAC;IACM,KAAK,CAAC,OAAO;QAChB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;CACJ;AARD,oEAQC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { EventEmitter } from \"events\";\nimport { ICollection, IDb } from \"@fluidframework/server-services-core\";\nimport { ITestDbFactory } from \"@fluidframework/server-test-utils\";\nimport { v4 as uuid } from \"uuid\";\n\n/**\n * A collection for local session storage, where data is stored in the browser\n * Functions include database operations such as queries, insertion and update.\n */\nclass LocalSessionStorageCollection<T> implements ICollection<T> {\n private readonly collectionName: string;\n constructor(namespace, name) {\n this.collectionName = `${namespace}-${name}`;\n }\n\n public aggregate(pipeline: any, options?: any): any {\n throw new Error(\"Method Not Implemented\");\n }\n\n public async updateMany(filter: any, set: any, addToSet: any): Promise<void> {\n throw new Error(\"Method Not Implemented\");\n }\n public async distinct(key: any, query: any): Promise<any> {\n throw new Error(\"Method Not Implemented\");\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.find}\n */\n /*\n * Each query key consists of several keys separated by '.' e.g: \"operation.sequenceNumber\".\n * The hierarchical syntax allows finding nested key patterns.\n */\n public async find(query: any, sort: any): Promise<any[]> {\n // split the keys and get the corresponding value\n function getValueByKey(propertyBag, key: string) {\n const keys = key.split(\".\");\n let value = propertyBag;\n keys.forEach((splitKey) => {\n value = value[splitKey];\n });\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value;\n }\n\n // getting keys of the query we are trying to find\n const queryKeys = Object.keys(query);\n let filteredCollection = this.getAllInternal();\n queryKeys.forEach((key) => {\n if (!query[key]) {\n return;\n }\n if (query[key].$gt > 0 || query[key].$lt > 0) {\n if (query[key].$gt > 0) {\n filteredCollection = filteredCollection.filter(\n (value) => getValueByKey(value, key) > query[key].$gt);\n }\n if (query[key].$lt > 0) {\n filteredCollection = filteredCollection.filter(\n (value) => getValueByKey(value, key) < query[key].$lt);\n }\n } else {\n filteredCollection = filteredCollection.filter(\n (value) => getValueByKey(value, key) === query[key]);\n }\n });\n\n if (sort && Object.keys(sort).length === 1) {\n // eslint-disable-next-line no-inner-declarations\n function compare(a, b) {\n const sortKey = Object.keys(sort)[0];\n if (sort[sortKey] === 1) {\n // A goes before b, sorting in ascending order\n return getValueByKey(a, sortKey) - getValueByKey(b, sortKey);\n } else {\n // B goes before a, sorting in descending order\n return getValueByKey(b, sortKey) - getValueByKey(a, sortKey);\n }\n }\n\n filteredCollection = filteredCollection.sort(compare);\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return filteredCollection;\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}\n */\n public async findAll(): Promise<any[]> {\n return Promise.resolve(this.getAllInternal());\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}\n */\n /*\n * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n */\n public async findOne(query: any): Promise<any> {\n return Promise.resolve(this.findOneInternal(query));\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.update}\n */\n /*\n * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n */\n public async update(query: any, set: any, addToSet: any): Promise<void> {\n const value = this.findOneInternal(query);\n if (!value) {\n throw new Error(\"Not found\");\n } else {\n for (const key of Object.keys(set)) {\n value[key] = set[key];\n }\n this.insertInternal(value);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}\n */\n /*\n * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n */\n public async upsert(query: any, set: any, addToSet: any): Promise<void> {\n const value = this.findOneInternal(query);\n if (!value) {\n this.insertInternal(set);\n } else {\n for (const key of Object.keys(set)) {\n value[key] = set[key];\n }\n this.insertInternal(value);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}\n */\n /*\n * Value is expected to have a member \"_id\" which is a string used to search in the database.\n */\n public async insertOne(value: any): Promise<any> {\n const presentVal = this.findOneInternal(value);\n // Only raise error when the object is present and the value is not equal.\n if (presentVal) {\n if (JSON.stringify(presentVal) === JSON.stringify(value)) {\n return;\n }\n throw new Error(\"Existing Object!!\");\n }\n\n return this.insertInternal(value);\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}\n */\n /*\n * Value and query are expected to have a member \"_id\" which is a string used to search or insert in the database.\n */\n public async findOrCreate(query: any, value: any): Promise<{ value: any; existing: boolean; }> {\n const existing = this.findOneInternal(query);\n if (existing) {\n return { value: existing, existing: true };\n }\n this.insertInternal(value);\n return { value, existing: false };\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}\n */\n /*\n * Each element in values is expected to have a member \"_id\" which is a string used to insert in the database.\n */\n public async insertMany(values: any[], ordered: boolean): Promise<void> {\n this.insertInternal(...values);\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteOne}\n */\n public async deleteOne(query: any): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteMany}\n */\n public async deleteMany(query: any): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.createIndex}\n */\n public async createIndex(index: any, unique: boolean): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * Return all values in the database\n */\n private getAllInternal(): any[] {\n const values: string[] = [];\n for (let i = 0; i < sessionStorage.length; i++) {\n const key = sessionStorage.key(i);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n if (key!.startsWith(this.collectionName)) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n values.push(JSON.parse(sessionStorage.getItem(key!)!));\n }\n }\n return values;\n }\n\n /**\n * Inserts values into the session storge.\n * Values are expected to have a member \"_id\" which is a unique id, otherwise will be assigned one\n *\n * @param values - data to insert to the database\n */\n private insertInternal(...values: any[]) {\n for (const value of values) {\n if (value) {\n if (!value._id) {\n value._id = uuid();\n }\n sessionStorage.setItem(`${this.collectionName}-${value._id}`, JSON.stringify(value));\n }\n }\n }\n\n /**\n * Finds the query in session storage and returns its value.\n * Returns null if query is not found.\n * Query is expected to have a member \"_id\" which is a unique id.\n *\n * @param query - what to find in the database\n */\n private findOneInternal(query: any): any {\n if (query._id) {\n const json = sessionStorage.getItem(`${this.collectionName}-${query._id}`);\n if (json) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return JSON.parse(json);\n }\n } else {\n const queryKeys = Object.keys(query);\n for (let i = 0; i < sessionStorage.length; i++) {\n const ssKey = sessionStorage.key(i);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n if (!ssKey!.startsWith(this.collectionName)) {\n continue;\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const value = JSON.parse(sessionStorage.getItem(ssKey!)!);\n for (const qk of queryKeys) {\n if (value[qk] !== query[qk]) {\n continue;\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value;\n }\n }\n return null;\n }\n}\n\n/**\n * A database for testing that stores data in the browsers session storage\n */\nclass LocalSessionStorageDb extends EventEmitter implements IDb {\n private readonly collections = new Map<string, LocalSessionStorageCollection<any>>();\n constructor(private readonly namespace) {\n super();\n }\n public async close(): Promise<void> {\n return Promise.resolve();\n }\n public collection<T>(name: string): ICollection<T> {\n if (!this.collections.has(name)) {\n this.collections.set(name, new LocalSessionStorageCollection<T>(`${this.namespace}-db`, name));\n }\n return this.collections.get(name) as LocalSessionStorageCollection<T>;\n }\n}\n\n/**\n * A database factory for testing that stores data in the browsers session storage\n */\nexport class LocalSessionStorageDbFactory implements ITestDbFactory {\n public readonly testDatabase: IDb;\n constructor(namespace: string) {\n this.testDatabase = new LocalSessionStorageDb(namespace);\n }\n public async connect(): Promise<IDb> {\n return this.testDatabase;\n }\n}\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/local-driver";
|
|
8
|
-
export declare const pkgVersion = "0.59.
|
|
8
|
+
export declare const pkgVersion = "0.59.3000-66610";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/local-driver";
|
|
11
|
-
exports.pkgVersion = "0.59.
|
|
11
|
+
exports.pkgVersion = "0.59.3000-66610";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,8BAA8B,CAAC;AACzC,QAAA,UAAU,GAAG,iBAAiB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/local-driver\";\nexport const pkgVersion = \"0.59.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,8BAA8B,CAAC;AACzC,QAAA,UAAU,GAAG,iBAAiB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/local-driver\";\nexport const pkgVersion = \"0.59.3000-66610\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/local-driver",
|
|
3
|
-
"version": "0.59.
|
|
3
|
+
"version": "0.59.3000-66610",
|
|
4
4
|
"description": "Fluid local driver",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -59,23 +59,23 @@
|
|
|
59
59
|
"@fluidframework/common-definitions": "^0.20.1",
|
|
60
60
|
"@fluidframework/common-utils": "^0.32.1",
|
|
61
61
|
"@fluidframework/core-interfaces": "^0.43.1000",
|
|
62
|
-
"@fluidframework/driver-base": "0.59.
|
|
62
|
+
"@fluidframework/driver-base": "0.59.3000-66610",
|
|
63
63
|
"@fluidframework/driver-definitions": "^0.46.1000",
|
|
64
|
-
"@fluidframework/driver-utils": "0.59.
|
|
64
|
+
"@fluidframework/driver-utils": "0.59.3000-66610",
|
|
65
65
|
"@fluidframework/protocol-definitions": "^0.1028.1000",
|
|
66
|
-
"@fluidframework/routerlicious-driver": "0.59.
|
|
67
|
-
"@fluidframework/server-local-server": "^0.1036.
|
|
68
|
-
"@fluidframework/server-services-client": "^0.1036.
|
|
69
|
-
"@fluidframework/server-services-core": "^0.1036.
|
|
70
|
-
"@fluidframework/server-test-utils": "^0.1036.
|
|
66
|
+
"@fluidframework/routerlicious-driver": "0.59.3000-66610",
|
|
67
|
+
"@fluidframework/server-local-server": "^0.1036.3000-0",
|
|
68
|
+
"@fluidframework/server-services-client": "^0.1036.3000-0",
|
|
69
|
+
"@fluidframework/server-services-core": "^0.1036.3000-0",
|
|
70
|
+
"@fluidframework/server-test-utils": "^0.1036.3000-0",
|
|
71
71
|
"jsrsasign": "^10.2.0",
|
|
72
72
|
"uuid": "^8.3.1"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@fluidframework/build-common": "^0.23.0",
|
|
76
|
-
"@fluidframework/eslint-config-fluid": "^0.28.
|
|
77
|
-
"@fluidframework/local-driver-previous": "npm:@fluidframework/local-driver@0.59.
|
|
78
|
-
"@fluidframework/mocha-test-setup": "0.59.
|
|
76
|
+
"@fluidframework/eslint-config-fluid": "^0.28.2000-0",
|
|
77
|
+
"@fluidframework/local-driver-previous": "npm:@fluidframework/local-driver@0.59.2000",
|
|
78
|
+
"@fluidframework/mocha-test-setup": "0.59.3000-66610",
|
|
79
79
|
"@rushstack/eslint-config": "^2.5.1",
|
|
80
80
|
"@types/jsrsasign": "^8.0.8",
|
|
81
81
|
"@types/mocha": "^8.2.2",
|
|
@@ -98,11 +98,11 @@
|
|
|
98
98
|
"nyc": "^15.0.0",
|
|
99
99
|
"rimraf": "^2.6.2",
|
|
100
100
|
"socket.io-client": "^4.4.1",
|
|
101
|
-
"typescript": "~4.
|
|
101
|
+
"typescript": "~4.5.5",
|
|
102
102
|
"typescript-formatter": "7.1.0"
|
|
103
103
|
},
|
|
104
104
|
"typeValidation": {
|
|
105
|
-
"version": "0.59.
|
|
105
|
+
"version": "0.59.3000",
|
|
106
106
|
"broken": {}
|
|
107
107
|
}
|
|
108
108
|
}
|
package/src/auth.ts
CHANGED
|
@@ -39,7 +39,7 @@ export function generateToken(
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
const utf8Key = { utf8: key };
|
|
42
|
-
return jsrsasign.jws.JWS.sign(null, JSON.stringify({ alg:"HS256", typ: "JWT" }), claims, utf8Key);
|
|
42
|
+
return jsrsasign.jws.JWS.sign(null, JSON.stringify({ alg: "HS256", typ: "JWT" }), claims, utf8Key);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export function generateUser(): IUser {
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { parse } from "url";
|
|
7
|
-
import { assert } from "@fluidframework/common-utils";
|
|
8
7
|
import {
|
|
9
8
|
IDocumentService,
|
|
10
9
|
IDocumentServiceFactory,
|
|
@@ -48,7 +47,9 @@ export class LocalDocumentServiceFactory implements IDocumentServiceFactory {
|
|
|
48
47
|
clientIsSummarizer?: boolean,
|
|
49
48
|
): Promise<IDocumentService> {
|
|
50
49
|
ensureFluidResolvedUrl(resolvedUrl);
|
|
51
|
-
|
|
50
|
+
if (createNewSummary === undefined) {
|
|
51
|
+
throw new Error("Empty file summary creation isn't supported in this driver.");
|
|
52
|
+
}
|
|
52
53
|
const pathName = new URL(resolvedUrl.url).pathname;
|
|
53
54
|
const pathArr = pathName.split("/");
|
|
54
55
|
const tenantId = pathArr[pathArr.length - 2];
|
|
@@ -76,6 +77,7 @@ export class LocalDocumentServiceFactory implements IDocumentServiceFactory {
|
|
|
76
77
|
resolvedUrl.endpoints.ordererUrl ?? "",
|
|
77
78
|
resolvedUrl.endpoints.storageUrl ?? "",
|
|
78
79
|
quorumValues,
|
|
80
|
+
false,
|
|
79
81
|
);
|
|
80
82
|
return this.createDocumentService(resolvedUrl, logger, clientIsSummarizer);
|
|
81
83
|
}
|
|
@@ -17,7 +17,7 @@ class LocalSessionStorageCollection<T> implements ICollection<T> {
|
|
|
17
17
|
this.collectionName = `${namespace}-${name}`;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
public aggregate(
|
|
20
|
+
public aggregate(pipeline: any, options?: any): any {
|
|
21
21
|
throw new Error("Method Not Implemented");
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -30,7 +30,8 @@ class LocalSessionStorageCollection<T> implements ICollection<T> {
|
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.find}
|
|
33
|
-
|
|
33
|
+
*/
|
|
34
|
+
/*
|
|
34
35
|
* Each query key consists of several keys separated by '.' e.g: "operation.sequenceNumber".
|
|
35
36
|
* The hierarchical syntax allows finding nested key patterns.
|
|
36
37
|
*/
|
|
@@ -96,7 +97,8 @@ class LocalSessionStorageCollection<T> implements ICollection<T> {
|
|
|
96
97
|
|
|
97
98
|
/**
|
|
98
99
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}
|
|
99
|
-
|
|
100
|
+
*/
|
|
101
|
+
/*
|
|
100
102
|
* Query is expected to have a member "_id" which is a string used to find value in the database.
|
|
101
103
|
*/
|
|
102
104
|
public async findOne(query: any): Promise<any> {
|
|
@@ -105,7 +107,8 @@ class LocalSessionStorageCollection<T> implements ICollection<T> {
|
|
|
105
107
|
|
|
106
108
|
/**
|
|
107
109
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.update}
|
|
108
|
-
|
|
110
|
+
*/
|
|
111
|
+
/*
|
|
109
112
|
* Query is expected to have a member "_id" which is a string used to find value in the database.
|
|
110
113
|
*/
|
|
111
114
|
public async update(query: any, set: any, addToSet: any): Promise<void> {
|
|
@@ -122,7 +125,8 @@ class LocalSessionStorageCollection<T> implements ICollection<T> {
|
|
|
122
125
|
|
|
123
126
|
/**
|
|
124
127
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}
|
|
125
|
-
|
|
128
|
+
*/
|
|
129
|
+
/*
|
|
126
130
|
* Query is expected to have a member "_id" which is a string used to find value in the database.
|
|
127
131
|
*/
|
|
128
132
|
public async upsert(query: any, set: any, addToSet: any): Promise<void> {
|
|
@@ -139,7 +143,8 @@ class LocalSessionStorageCollection<T> implements ICollection<T> {
|
|
|
139
143
|
|
|
140
144
|
/**
|
|
141
145
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}
|
|
142
|
-
|
|
146
|
+
*/
|
|
147
|
+
/*
|
|
143
148
|
* Value is expected to have a member "_id" which is a string used to search in the database.
|
|
144
149
|
*/
|
|
145
150
|
public async insertOne(value: any): Promise<any> {
|
|
@@ -157,10 +162,11 @@ class LocalSessionStorageCollection<T> implements ICollection<T> {
|
|
|
157
162
|
|
|
158
163
|
/**
|
|
159
164
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}
|
|
160
|
-
|
|
165
|
+
*/
|
|
166
|
+
/*
|
|
161
167
|
* Value and query are expected to have a member "_id" which is a string used to search or insert in the database.
|
|
162
168
|
*/
|
|
163
|
-
public async findOrCreate(query: any, value: any): Promise<{ value: any
|
|
169
|
+
public async findOrCreate(query: any, value: any): Promise<{ value: any; existing: boolean; }> {
|
|
164
170
|
const existing = this.findOneInternal(query);
|
|
165
171
|
if (existing) {
|
|
166
172
|
return { value: existing, existing: true };
|
|
@@ -171,7 +177,8 @@ class LocalSessionStorageCollection<T> implements ICollection<T> {
|
|
|
171
177
|
|
|
172
178
|
/**
|
|
173
179
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}
|
|
174
|
-
|
|
180
|
+
*/
|
|
181
|
+
/*
|
|
175
182
|
* Each element in values is expected to have a member "_id" which is a string used to insert in the database.
|
|
176
183
|
*/
|
|
177
184
|
public async insertMany(values: any[], ordered: boolean): Promise<void> {
|
package/src/packageVersion.ts
CHANGED