@fluidframework/local-driver 2.80.0 → 2.81.0-374083
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.d.ts.map +1 -1
- package/dist/auth.js +1 -0
- package/dist/auth.js.map +1 -1
- package/dist/localDocumentStorageService.d.ts.map +1 -1
- package/dist/localDocumentStorageService.js +1 -0
- package/dist/localDocumentStorageService.js.map +1 -1
- package/dist/localSessionStorageDb.d.ts.map +1 -1
- package/dist/localSessionStorageDb.js +1 -0
- package/dist/localSessionStorageDb.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/eslint.config.mts +4 -4
- package/lib/auth.d.ts.map +1 -1
- package/lib/auth.js +1 -0
- package/lib/auth.js.map +1 -1
- package/lib/localDocumentStorageService.d.ts.map +1 -1
- package/lib/localDocumentStorageService.js +1 -0
- package/lib/localDocumentStorageService.js.map +1 -1
- package/lib/localSessionStorageDb.d.ts.map +1 -1
- package/lib/localSessionStorageDb.js +1 -0
- package/lib/localSessionStorageDb.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/package.json +14 -14
- package/src/auth.ts +1 -0
- package/src/localDocumentStorageService.ts +1 -0
- package/src/localSessionStorageDb.ts +1 -0
- package/src/packageVersion.ts +1 -1
- package/.eslintrc.cjs +0 -27
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAC3D,OAAO,EAAgB,SAAS,EAAE,MAAM,6CAA6C,CAAC;AAItF;;;GAGG;AACH,wBAAgB,aAAa,CAC5B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,SAAS,EAAE,EACnB,IAAI,CAAC,EAAE,KAAK,EACZ,QAAQ,GAAE,MAAgB,EAC1B,GAAG,GAAE,MAAc,GACjB,MAAM,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAC3D,OAAO,EAAgB,SAAS,EAAE,MAAM,6CAA6C,CAAC;AAItF;;;GAGG;AACH,wBAAgB,aAAa,CAC5B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,SAAS,EAAE,EACnB,IAAI,CAAC,EAAE,KAAK,EACZ,QAAQ,GAAE,MAAgB,EAC1B,GAAG,GAAE,MAAc,GACjB,MAAM,CA2BR;AAED,wBAAgB,YAAY,IAAI,KAAK,CAWpC"}
|
package/dist/auth.js
CHANGED
|
@@ -12,6 +12,7 @@ const uuid_1 = require("uuid");
|
|
|
12
12
|
* services-client since it cannot run in the browser without polyfills.
|
|
13
13
|
*/
|
|
14
14
|
function generateToken(tenantId, documentId, key, scopes, user, lifetime = 60 * 60, ver = "1.0") {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ?? could change behavior for falsy values
|
|
15
16
|
let userClaim = user ? user : generateUser();
|
|
16
17
|
if (userClaim.id === "" || userClaim.id === undefined) {
|
|
17
18
|
userClaim = generateUser();
|
package/dist/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,yCAA8C;AAC9C,+BAAkC;AAElC;;;GAGG;AACH,SAAgB,aAA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nimport { IUser } from \"@fluidframework/driver-definitions\";\nimport { ITokenClaims, ScopeType } from \"@fluidframework/driver-definitions/internal\";\nimport { KJUR as jsrsasign } from \"jsrsasign\";\nimport { v4 as uuid } from \"uuid\";\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\ttenantId: string,\n\tdocumentId: string,\n\tkey: string,\n\tscopes: ScopeType[],\n\tuser?: IUser,\n\tlifetime: number = 60 * 60,\n\tver: string = \"1.0\",\n): string {\n\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ?? could change behavior for falsy values\n\tlet userClaim = user ? user : generateUser();\n\tif (userClaim.id === \"\" || userClaim.id === undefined) {\n\t\tuserClaim = generateUser();\n\t}\n\n\t// Current time in seconds\n\tconst now = Math.round(new Date().getTime() / 1000);\n\n\tconst claims: ITokenClaims = {\n\t\tdocumentId,\n\t\tscopes,\n\t\ttenantId,\n\t\tuser: userClaim,\n\t\tiat: now,\n\t\texp: now + lifetime,\n\t\tver,\n\t};\n\n\tconst utf8Key = { utf8: key };\n\treturn jsrsasign.jws.JWS.sign(\n\t\tnull,\n\t\tJSON.stringify({ alg: \"HS256\", typ: \"JWT\" }),\n\t\tclaims,\n\t\tutf8Key,\n\t);\n}\n\nexport function generateUser(): IUser {\n\tconst userId = uuid();\n\tconst match = /^([\\da-f]{8})-([\\da-f]{4})/.exec(userId);\n\tconst userName = match !== null ? match[0] : userId; // Just use the first two segments of the (fake) userId as a fake name.\n\n\tconst randomUser = {\n\t\tid: userId,\n\t\tname: userName,\n\t};\n\n\treturn randomUser;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/localDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClF,OAAO,EACN,uBAAu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CAWrC"}
|
|
@@ -27,6 +27,7 @@ class LocalDocumentStorageService {
|
|
|
27
27
|
this.summaryTreeUploadManager = new server_services_client_1.SummaryTreeUploadManager(manager, this.blobsShaCache, this.getPreviousFullSnapshot.bind(this));
|
|
28
28
|
}
|
|
29
29
|
async getVersions(versionId, count) {
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ?? could change behavior for falsy values
|
|
30
31
|
const id = versionId ? versionId : this.id;
|
|
31
32
|
const commits = await this.manager.getCommits(id, count);
|
|
32
33
|
return commits.map((commit) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localDocumentStorageService.js","sourceRoot":"","sources":["../src/localDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAKsC;AACtC,kEAA6D;AAa7D,iEAAsE;AAEtE,mFAIgD;AAEhD,qEAA0D;AAE1D,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,mBAAmB;AACzD;;GAEG;AACH,MAAa,2BAA2B;IAMvC,YACkB,EAAU,EACV,OAAmB,EACpB,QAAyC,EACxC,0BAAwD,EACxD,WAA0B;QAJ1B,OAAE,GAAF,EAAE,CAAQ;QACV,YAAO,GAAP,OAAO,CAAY;QACpB,aAAQ,GAAR,QAAQ,CAAiC;QACxC,+BAA0B,GAA1B,0BAA0B,CAA8B;QACxD,gBAAW,GAAX,WAAW,CAAe;QAV5C,uFAAuF;QACvF,2BAA2B;QACR,kBAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;QAU5D,IAAI,CAAC,wBAAwB,GAAG,IAAI,iDAAwB,CAC3D,OAAO,EACP,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,CACvC,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,SAAwB,EAAE,KAAa;QAC/D,MAAM,EAAE,GAAG,SAAS,CAAC,C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E;gBAC1D,mEAAmE;gBACnE,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;gBAC3B,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1C,CAAC,CAAC;YACH,CAAC,CAAC,SAAS,CAAC;IACd,CAAC;CACD;AA3SD,kEA2SC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIsoBuffer,\n\tUint8ArrayToString,\n\tbufferToString,\n\tstringToBuffer,\n} from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { ISummaryHandle, ISummaryTree } from \"@fluidframework/driver-definitions\";\nimport {\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n\tIResolvedUrl,\n\ttype ISnapshot,\n\ttype ISnapshotFetchOptions,\n\tISummaryContext,\n\tICreateBlobResponse,\n\tISnapshotTreeEx,\n\tIVersion,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { buildGitTreeHierarchy } from \"@fluidframework/protocol-base\";\nimport { ILocalDeltaConnectionServer } from \"@fluidframework/server-local-server\";\nimport {\n\tGitManager,\n\tISummaryUploadManager,\n\tSummaryTreeUploadManager,\n} from \"@fluidframework/server-services-client\";\n\nimport { createDocument } from \"./localCreateDocument.js\";\n\nconst minTTLInSeconds = 24 * 60 * 60; // Same TTL as ODSP\n/**\n * @internal\n */\nexport class LocalDocumentStorageService implements IDocumentStorageService {\n\t// The values of this cache is useless. We only need the keys. So we are always putting\n\t// empty strings as values.\n\tprotected readonly blobsShaCache = new Map<string, string>();\n\tprivate readonly summaryTreeUploadManager: ISummaryUploadManager;\n\n\tconstructor(\n\t\tprivate readonly id: string,\n\t\tprivate readonly manager: GitManager,\n\t\tpublic readonly policies: IDocumentStorageServicePolicies,\n\t\tprivate readonly localDeltaConnectionServer?: ILocalDeltaConnectionServer,\n\t\tprivate readonly resolvedUrl?: IResolvedUrl,\n\t) {\n\t\tthis.summaryTreeUploadManager = new SummaryTreeUploadManager(\n\t\t\tmanager,\n\t\t\tthis.blobsShaCache,\n\t\t\tthis.getPreviousFullSnapshot.bind(this),\n\t\t);\n\t}\n\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\tconst id = versionId ? versionId : this.id;\n\t\tconst commits = await this.manager.getCommits(id, count);\n\t\treturn commits.map((commit) => ({\n\t\t\tdate: commit.commit.author.date,\n\t\t\tid: commit.sha,\n\t\t\ttreeId: commit.commit.tree.sha,\n\t\t}));\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null> {\n\t\tlet requestVersion = version;\n\t\tif (!requestVersion) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\t// Non null asserting here because of the length check above\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\trequestVersion = versions[0]!;\n\t\t}\n\n\t\tconst rawTree = await this.manager.getTree(requestVersion.treeId);\n\t\tconst tree = buildGitTreeHierarchy(rawTree, this.blobsShaCache, true);\n\t\tawait this.populateGroupId(tree);\n\t\treturn tree;\n\t}\n\n\tpublic async getSnapshot(snapshotFetchOptions?: ISnapshotFetchOptions): Promise<ISnapshot> {\n\t\tlet versionId = snapshotFetchOptions?.versionId;\n\t\tif (!versionId) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\tthrow new Error(\"No versions for the document!\");\n\t\t\t}\n\n\t\t\t// Non null asserting here because of the length check above\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tversionId = versions[0]!.treeId;\n\t\t}\n\t\tconst rawTree = await this.manager.getTree(versionId);\n\t\tconst snapshotTree = buildGitTreeHierarchy(rawTree, this.blobsShaCache, true);\n\t\tconst groupIds = new Set<string>(snapshotFetchOptions?.loadingGroupIds ?? []);\n\t\t// TODO Why are we non null asserting here\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst attributesBlobId = snapshotTree.trees[\".protocol\"]!.blobs.attributes!;\n\t\t// Only populate contents for the blobs which are supposed to be returned.\n\t\tconst blobContents = new Map<string, ArrayBuffer>();\n\t\tconst attributesBlobData = await this.readBlob(attributesBlobId);\n\t\tif (groupIds.has(\"\") || groupIds.size === 0) {\n\t\t\t// If the root is in the groupIds, we don't need to filter the tree.\n\t\t\t// We can just strip the of all groupIds as in collect the blobIds so that we can\n\t\t\t// return blob contents only for those ids.\n\t\t\tawait this.collectBlobContentsForUngroupedSnapshot(snapshotTree, groupIds, blobContents);\n\t\t} else {\n\t\t\tconst hasFoundTree = await this.filterTreeByLoadingGroupIds(\n\t\t\t\tsnapshotTree,\n\t\t\t\tgroupIds,\n\t\t\t\tfalse,\n\t\t\t\tblobContents,\n\t\t\t);\n\t\t\tassert(hasFoundTree, 0x8dd /* No tree found for the given groupIds */);\n\t\t}\n\n\t\tconst attributesString = IsoBuffer.from(attributesBlobData).toString(\"utf-8\");\n\t\tconst attributes = JSON.parse(attributesString);\n\t\tconst sequenceNumber: number = attributes.sequenceNumber ?? 0;\n\t\treturn {\n\t\t\tsnapshotTree,\n\t\t\tblobContents,\n\t\t\tops: [],\n\t\t\tsnapshotFormatV: 1,\n\t\t\tsequenceNumber,\n\t\t\tlatestSequenceNumber: undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Collect the blobIds to keep in the snapshot for ungrouped snapshot plus\n\t * any other loading groupId along with it.\n\t *\n\t * @param tree - The tree to evaluate for loading groupIds\n\t * @returns a tree that has trees with groupIds that are empty\n\t */\n\tprivate async collectBlobContentsForUngroupedSnapshot(\n\t\ttree: ISnapshotTreeEx,\n\t\tloadingGroupIds: Set<string>,\n\t\tblobContents: Map<string, ArrayBuffer>,\n\t): Promise<void> {\n\t\tconst groupId = await this.readGroupId(tree);\n\t\tif (groupId === undefined || loadingGroupIds.has(groupId)) {\n\t\t\tfor (const id of Object.values(tree.blobs)) {\n\t\t\t\tblobContents.set(id, await this.readBlob(id));\n\t\t\t}\n\t\t\tawait Promise.all(\n\t\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\t\tawait this.collectBlobContentsForUngroupedSnapshot(\n\t\t\t\t\t\tchildTree,\n\t\t\t\t\t\tloadingGroupIds,\n\t\t\t\t\t\tblobContents,\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Named differently as the algorithm is a little more involved.\n\t *\n\t * We want to strip the tree if it has a groupId that is not in the loadingGroupIds or if it doesn't have a descendent or ancestor\n\t * that has a groupId that is in the loadingGroupIds.\n\t *\n\t * We keep the tree in the opposite case.\n\t *\n\t * @param tree - the tree to strip of any data that is not in the loadingGroupIds\n\t * @param loadingGroupIds - the set of groupIds that are being loaded\n\t * @param ancestorGroupIdInLoadingGroup - whether the ancestor of the tree has a groupId that is in the loadingGroupIds\n\t * @returns whether or not it or descendant has a groupId that is in the loadingGroupIds\n\t */\n\tprivate async filterTreeByLoadingGroupIds(\n\t\ttree: ISnapshotTreeEx,\n\t\tloadingGroupIds: Set<string>,\n\t\tancestorGroupIdInLoadingGroup: boolean,\n\t\tblobContents: Map<string, ArrayBuffer>,\n\t): Promise<boolean> {\n\t\tassert(loadingGroupIds.size > 0, 0x8de /* loadingGroupIds should not be empty */);\n\t\tconst groupId = await this.readGroupId(tree);\n\n\t\t// Strip the tree if it has a groupId and it is not in the loadingGroupIds\n\t\t// This is an optimization here as we have other reasons to keep the tree.\n\t\tconst noGroupIdInLoadingGroupIds = groupId !== undefined && !loadingGroupIds.has(groupId);\n\t\tif (noGroupIdInLoadingGroupIds) {\n\t\t\tthis.stripTree(tree, groupId);\n\t\t\treturn false;\n\t\t}\n\n\t\t// Keep tree if it has a groupId and it is in the loadingGroupIds\n\t\tconst groupIdInLoadingGroupIds = groupId !== undefined && loadingGroupIds.has(groupId);\n\n\t\t// Keep tree if it has an ancestor that has a groupId that is in loadingGroupIds and it doesn't have groupId\n\t\tconst isChildOfAncestorWithGroupId =\n\t\t\tancestorGroupIdInLoadingGroup && groupId === undefined;\n\n\t\t// Collect blobsIds so that we can return blob contents only for these blobs.\n\t\tif (groupIdInLoadingGroupIds || isChildOfAncestorWithGroupId) {\n\t\t\tfor (const id of Object.values(tree.blobs)) {\n\t\t\t\tblobContents.set(id, await this.readBlob(id));\n\t\t\t}\n\t\t}\n\t\t// Keep tree if it has a child that has a groupId that is in loadingGroupIds\n\t\tconst descendants = await Promise.all<boolean>(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\treturn this.filterTreeByLoadingGroupIds(\n\t\t\t\t\tchildTree,\n\t\t\t\t\tloadingGroupIds,\n\t\t\t\t\tancestorGroupIdInLoadingGroup || groupIdInLoadingGroupIds,\n\t\t\t\t\tblobContents,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tconst isAncestorOfDescendantsWithGroupId = descendants.some((keep) => keep);\n\n\t\t// We don't want to return prematurely as we still may have children that we want to keep.\n\t\tif (\n\t\t\tgroupIdInLoadingGroupIds ||\n\t\t\tisChildOfAncestorWithGroupId ||\n\t\t\tisAncestorOfDescendantsWithGroupId\n\t\t) {\n\t\t\t// Keep this tree node\n\t\t\treturn true;\n\t\t}\n\n\t\t// This means we have no groupId and none of our ancestors or descendants have a groupId in the loadingGroupIds\n\t\tthis.stripTree(tree, groupId);\n\t\treturn false;\n\t}\n\n\t// Takes all the blobs of a tree and puts it into the blobContents\n\tprivate async populateBlobContents(\n\t\ttree: ISnapshotTreeEx,\n\t\tblobContents: Map<string, ArrayBufferLike>,\n\t\tblobIdsToKeep: Set<string>,\n\t): Promise<void> {\n\t\tawait Promise.all(\n\t\t\tObject.entries(tree.blobs).map(async ([path, blobId]) => {\n\t\t\t\tif (blobIdsToKeep.has(blobId)) {\n\t\t\t\t\tconst content = await this.readBlob(blobId);\n\t\t\t\t\tblobContents.set(blobId, content);\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t\tawait Promise.all(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\tawait this.populateBlobContents(childTree, blobContents, blobIdsToKeep);\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate async populateGroupId(tree: ISnapshotTreeEx): Promise<void> {\n\t\tawait this.readGroupId(tree);\n\t\tawait Promise.all(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\tawait this.populateGroupId(childTree);\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate stripTree(tree: ISnapshotTreeEx, groupId: string | undefined): void {\n\t\ttree.blobs = {};\n\t\ttree.groupId = groupId;\n\t\ttree.trees = {};\n\t}\n\n\tprivate async readGroupId(tree: ISnapshotTreeEx): Promise<string | undefined> {\n\t\tconst groupIdBlobId = tree.blobs[\".groupId\"];\n\t\tif (groupIdBlobId !== undefined) {\n\t\t\tconst groupIdBuffer = await this.readBlob(groupIdBlobId);\n\t\t\tconst groupId = bufferToString(groupIdBuffer, \"utf8\");\n\t\t\ttree.groupId = groupId;\n\t\t\tdelete tree.blobs[\".groupId\"];\n\t\t\treturn groupId;\n\t\t}\n\n\t\treturn tree.groupId;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\tconst blob = await this.manager.getBlob(blobId);\n\t\tthis.blobsShaCache.set(blob.sha, \"\");\n\t\tconst bufferContent = stringToBuffer(blob.content, blob.encoding);\n\t\treturn bufferContent;\n\t}\n\n\tpublic async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\tif (context.referenceSequenceNumber === 0) {\n\t\t\tif (this.localDeltaConnectionServer === undefined || this.resolvedUrl === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Insufficient constructor parameters. An ILocalDeltaConnectionServer and IResolvedUrl required\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait createDocument(this.localDeltaConnectionServer, this.resolvedUrl, summary);\n\t\t\tconst version = await this.getVersions(this.id, 1);\n\t\t\t// TODO Why are we non null asserting here\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\treturn version[0]!.id;\n\t\t}\n\t\treturn this.summaryTreeUploadManager.writeSummaryTree(\n\t\t\tsummary,\n\t\t\tcontext.ackHandle ?? \"\",\n\t\t\t\"channel\",\n\t\t);\n\t}\n\n\tpublic async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\tconst uint8ArrayFile = new Uint8Array(file);\n\t\treturn this.manager\n\t\t\t.createBlob(Uint8ArrayToString(uint8ArrayFile, \"base64\"), \"base64\")\n\t\t\t.then((r) => ({ id: r.sha, url: r.url, minTTLInSeconds }));\n\t}\n\n\tpublic async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n\t\tthrow new Error(\"NOT IMPLEMENTED!\");\n\t}\n\n\tprivate async getPreviousFullSnapshot(\n\t\tparentHandle: string,\n\t): Promise<ISnapshotTreeEx | null | undefined> {\n\t\treturn parentHandle\n\t\t\t? this.getVersions(parentHandle, 1).then(async (versions) => {\n\t\t\t\t\t// Clear the cache as the getSnapshotTree call will fill the cache.\n\t\t\t\t\tthis.blobsShaCache.clear();\n\t\t\t\t\treturn this.getSnapshotTree(versions[0]);\n\t\t\t\t})\n\t\t\t: undefined;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"localDocumentStorageService.js","sourceRoot":"","sources":["../src/localDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAKsC;AACtC,kEAA6D;AAa7D,iEAAsE;AAEtE,mFAIgD;AAEhD,qEAA0D;AAE1D,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,mBAAmB;AACzD;;GAEG;AACH,MAAa,2BAA2B;IAMvC,YACkB,EAAU,EACV,OAAmB,EACpB,QAAyC,EACxC,0BA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AAU,CAAC,IAAA,iCAAkB,EAAC,cAAc,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC;aAClE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,MAAsB;QAClD,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACrC,CAAC;IAEO,KAAK,CAAC,uBAAuB,CACpC,YAAoB;QAEpB,OAAO,YAAY;YAClB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;gBAC1D,mEAAmE;gBACnE,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;gBAC3B,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1C,CAAC,CAAC;YACH,CAAC,CAAC,SAAS,CAAC;IACd,CAAC;CACD;AA5SD,kEA4SC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIsoBuffer,\n\tUint8ArrayToString,\n\tbufferToString,\n\tstringToBuffer,\n} from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { ISummaryHandle, ISummaryTree } from \"@fluidframework/driver-definitions\";\nimport {\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n\tIResolvedUrl,\n\ttype ISnapshot,\n\ttype ISnapshotFetchOptions,\n\tISummaryContext,\n\tICreateBlobResponse,\n\tISnapshotTreeEx,\n\tIVersion,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { buildGitTreeHierarchy } from \"@fluidframework/protocol-base\";\nimport { ILocalDeltaConnectionServer } from \"@fluidframework/server-local-server\";\nimport {\n\tGitManager,\n\tISummaryUploadManager,\n\tSummaryTreeUploadManager,\n} from \"@fluidframework/server-services-client\";\n\nimport { createDocument } from \"./localCreateDocument.js\";\n\nconst minTTLInSeconds = 24 * 60 * 60; // Same TTL as ODSP\n/**\n * @internal\n */\nexport class LocalDocumentStorageService implements IDocumentStorageService {\n\t// The values of this cache is useless. We only need the keys. So we are always putting\n\t// empty strings as values.\n\tprotected readonly blobsShaCache = new Map<string, string>();\n\tprivate readonly summaryTreeUploadManager: ISummaryUploadManager;\n\n\tconstructor(\n\t\tprivate readonly id: string,\n\t\tprivate readonly manager: GitManager,\n\t\tpublic readonly policies: IDocumentStorageServicePolicies,\n\t\tprivate readonly localDeltaConnectionServer?: ILocalDeltaConnectionServer,\n\t\tprivate readonly resolvedUrl?: IResolvedUrl,\n\t) {\n\t\tthis.summaryTreeUploadManager = new SummaryTreeUploadManager(\n\t\t\tmanager,\n\t\t\tthis.blobsShaCache,\n\t\t\tthis.getPreviousFullSnapshot.bind(this),\n\t\t);\n\t}\n\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ?? could change behavior for falsy values\n\t\tconst id = versionId ? versionId : this.id;\n\t\tconst commits = await this.manager.getCommits(id, count);\n\t\treturn commits.map((commit) => ({\n\t\t\tdate: commit.commit.author.date,\n\t\t\tid: commit.sha,\n\t\t\ttreeId: commit.commit.tree.sha,\n\t\t}));\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null> {\n\t\tlet requestVersion = version;\n\t\tif (!requestVersion) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\t// Non null asserting here because of the length check above\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\trequestVersion = versions[0]!;\n\t\t}\n\n\t\tconst rawTree = await this.manager.getTree(requestVersion.treeId);\n\t\tconst tree = buildGitTreeHierarchy(rawTree, this.blobsShaCache, true);\n\t\tawait this.populateGroupId(tree);\n\t\treturn tree;\n\t}\n\n\tpublic async getSnapshot(snapshotFetchOptions?: ISnapshotFetchOptions): Promise<ISnapshot> {\n\t\tlet versionId = snapshotFetchOptions?.versionId;\n\t\tif (!versionId) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\tthrow new Error(\"No versions for the document!\");\n\t\t\t}\n\n\t\t\t// Non null asserting here because of the length check above\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tversionId = versions[0]!.treeId;\n\t\t}\n\t\tconst rawTree = await this.manager.getTree(versionId);\n\t\tconst snapshotTree = buildGitTreeHierarchy(rawTree, this.blobsShaCache, true);\n\t\tconst groupIds = new Set<string>(snapshotFetchOptions?.loadingGroupIds ?? []);\n\t\t// TODO Why are we non null asserting here\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst attributesBlobId = snapshotTree.trees[\".protocol\"]!.blobs.attributes!;\n\t\t// Only populate contents for the blobs which are supposed to be returned.\n\t\tconst blobContents = new Map<string, ArrayBuffer>();\n\t\tconst attributesBlobData = await this.readBlob(attributesBlobId);\n\t\tif (groupIds.has(\"\") || groupIds.size === 0) {\n\t\t\t// If the root is in the groupIds, we don't need to filter the tree.\n\t\t\t// We can just strip the of all groupIds as in collect the blobIds so that we can\n\t\t\t// return blob contents only for those ids.\n\t\t\tawait this.collectBlobContentsForUngroupedSnapshot(snapshotTree, groupIds, blobContents);\n\t\t} else {\n\t\t\tconst hasFoundTree = await this.filterTreeByLoadingGroupIds(\n\t\t\t\tsnapshotTree,\n\t\t\t\tgroupIds,\n\t\t\t\tfalse,\n\t\t\t\tblobContents,\n\t\t\t);\n\t\t\tassert(hasFoundTree, 0x8dd /* No tree found for the given groupIds */);\n\t\t}\n\n\t\tconst attributesString = IsoBuffer.from(attributesBlobData).toString(\"utf-8\");\n\t\tconst attributes = JSON.parse(attributesString);\n\t\tconst sequenceNumber: number = attributes.sequenceNumber ?? 0;\n\t\treturn {\n\t\t\tsnapshotTree,\n\t\t\tblobContents,\n\t\t\tops: [],\n\t\t\tsnapshotFormatV: 1,\n\t\t\tsequenceNumber,\n\t\t\tlatestSequenceNumber: undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Collect the blobIds to keep in the snapshot for ungrouped snapshot plus\n\t * any other loading groupId along with it.\n\t *\n\t * @param tree - The tree to evaluate for loading groupIds\n\t * @returns a tree that has trees with groupIds that are empty\n\t */\n\tprivate async collectBlobContentsForUngroupedSnapshot(\n\t\ttree: ISnapshotTreeEx,\n\t\tloadingGroupIds: Set<string>,\n\t\tblobContents: Map<string, ArrayBuffer>,\n\t): Promise<void> {\n\t\tconst groupId = await this.readGroupId(tree);\n\t\tif (groupId === undefined || loadingGroupIds.has(groupId)) {\n\t\t\tfor (const id of Object.values(tree.blobs)) {\n\t\t\t\tblobContents.set(id, await this.readBlob(id));\n\t\t\t}\n\t\t\tawait Promise.all(\n\t\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\t\tawait this.collectBlobContentsForUngroupedSnapshot(\n\t\t\t\t\t\tchildTree,\n\t\t\t\t\t\tloadingGroupIds,\n\t\t\t\t\t\tblobContents,\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Named differently as the algorithm is a little more involved.\n\t *\n\t * We want to strip the tree if it has a groupId that is not in the loadingGroupIds or if it doesn't have a descendent or ancestor\n\t * that has a groupId that is in the loadingGroupIds.\n\t *\n\t * We keep the tree in the opposite case.\n\t *\n\t * @param tree - the tree to strip of any data that is not in the loadingGroupIds\n\t * @param loadingGroupIds - the set of groupIds that are being loaded\n\t * @param ancestorGroupIdInLoadingGroup - whether the ancestor of the tree has a groupId that is in the loadingGroupIds\n\t * @returns whether or not it or descendant has a groupId that is in the loadingGroupIds\n\t */\n\tprivate async filterTreeByLoadingGroupIds(\n\t\ttree: ISnapshotTreeEx,\n\t\tloadingGroupIds: Set<string>,\n\t\tancestorGroupIdInLoadingGroup: boolean,\n\t\tblobContents: Map<string, ArrayBuffer>,\n\t): Promise<boolean> {\n\t\tassert(loadingGroupIds.size > 0, 0x8de /* loadingGroupIds should not be empty */);\n\t\tconst groupId = await this.readGroupId(tree);\n\n\t\t// Strip the tree if it has a groupId and it is not in the loadingGroupIds\n\t\t// This is an optimization here as we have other reasons to keep the tree.\n\t\tconst noGroupIdInLoadingGroupIds = groupId !== undefined && !loadingGroupIds.has(groupId);\n\t\tif (noGroupIdInLoadingGroupIds) {\n\t\t\tthis.stripTree(tree, groupId);\n\t\t\treturn false;\n\t\t}\n\n\t\t// Keep tree if it has a groupId and it is in the loadingGroupIds\n\t\tconst groupIdInLoadingGroupIds = groupId !== undefined && loadingGroupIds.has(groupId);\n\n\t\t// Keep tree if it has an ancestor that has a groupId that is in loadingGroupIds and it doesn't have groupId\n\t\tconst isChildOfAncestorWithGroupId =\n\t\t\tancestorGroupIdInLoadingGroup && groupId === undefined;\n\n\t\t// Collect blobsIds so that we can return blob contents only for these blobs.\n\t\tif (groupIdInLoadingGroupIds || isChildOfAncestorWithGroupId) {\n\t\t\tfor (const id of Object.values(tree.blobs)) {\n\t\t\t\tblobContents.set(id, await this.readBlob(id));\n\t\t\t}\n\t\t}\n\t\t// Keep tree if it has a child that has a groupId that is in loadingGroupIds\n\t\tconst descendants = await Promise.all<boolean>(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\treturn this.filterTreeByLoadingGroupIds(\n\t\t\t\t\tchildTree,\n\t\t\t\t\tloadingGroupIds,\n\t\t\t\t\tancestorGroupIdInLoadingGroup || groupIdInLoadingGroupIds,\n\t\t\t\t\tblobContents,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tconst isAncestorOfDescendantsWithGroupId = descendants.some((keep) => keep);\n\n\t\t// We don't want to return prematurely as we still may have children that we want to keep.\n\t\tif (\n\t\t\tgroupIdInLoadingGroupIds ||\n\t\t\tisChildOfAncestorWithGroupId ||\n\t\t\tisAncestorOfDescendantsWithGroupId\n\t\t) {\n\t\t\t// Keep this tree node\n\t\t\treturn true;\n\t\t}\n\n\t\t// This means we have no groupId and none of our ancestors or descendants have a groupId in the loadingGroupIds\n\t\tthis.stripTree(tree, groupId);\n\t\treturn false;\n\t}\n\n\t// Takes all the blobs of a tree and puts it into the blobContents\n\tprivate async populateBlobContents(\n\t\ttree: ISnapshotTreeEx,\n\t\tblobContents: Map<string, ArrayBufferLike>,\n\t\tblobIdsToKeep: Set<string>,\n\t): Promise<void> {\n\t\tawait Promise.all(\n\t\t\tObject.entries(tree.blobs).map(async ([path, blobId]) => {\n\t\t\t\tif (blobIdsToKeep.has(blobId)) {\n\t\t\t\t\tconst content = await this.readBlob(blobId);\n\t\t\t\t\tblobContents.set(blobId, content);\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t\tawait Promise.all(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\tawait this.populateBlobContents(childTree, blobContents, blobIdsToKeep);\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate async populateGroupId(tree: ISnapshotTreeEx): Promise<void> {\n\t\tawait this.readGroupId(tree);\n\t\tawait Promise.all(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\tawait this.populateGroupId(childTree);\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate stripTree(tree: ISnapshotTreeEx, groupId: string | undefined): void {\n\t\ttree.blobs = {};\n\t\ttree.groupId = groupId;\n\t\ttree.trees = {};\n\t}\n\n\tprivate async readGroupId(tree: ISnapshotTreeEx): Promise<string | undefined> {\n\t\tconst groupIdBlobId = tree.blobs[\".groupId\"];\n\t\tif (groupIdBlobId !== undefined) {\n\t\t\tconst groupIdBuffer = await this.readBlob(groupIdBlobId);\n\t\t\tconst groupId = bufferToString(groupIdBuffer, \"utf8\");\n\t\t\ttree.groupId = groupId;\n\t\t\tdelete tree.blobs[\".groupId\"];\n\t\t\treturn groupId;\n\t\t}\n\n\t\treturn tree.groupId;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\tconst blob = await this.manager.getBlob(blobId);\n\t\tthis.blobsShaCache.set(blob.sha, \"\");\n\t\tconst bufferContent = stringToBuffer(blob.content, blob.encoding);\n\t\treturn bufferContent;\n\t}\n\n\tpublic async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\tif (context.referenceSequenceNumber === 0) {\n\t\t\tif (this.localDeltaConnectionServer === undefined || this.resolvedUrl === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Insufficient constructor parameters. An ILocalDeltaConnectionServer and IResolvedUrl required\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait createDocument(this.localDeltaConnectionServer, this.resolvedUrl, summary);\n\t\t\tconst version = await this.getVersions(this.id, 1);\n\t\t\t// TODO Why are we non null asserting here\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\treturn version[0]!.id;\n\t\t}\n\t\treturn this.summaryTreeUploadManager.writeSummaryTree(\n\t\t\tsummary,\n\t\t\tcontext.ackHandle ?? \"\",\n\t\t\t\"channel\",\n\t\t);\n\t}\n\n\tpublic async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\tconst uint8ArrayFile = new Uint8Array(file);\n\t\treturn this.manager\n\t\t\t.createBlob(Uint8ArrayToString(uint8ArrayFile, \"base64\"), \"base64\")\n\t\t\t.then((r) => ({ id: r.sha, url: r.url, minTTLInSeconds }));\n\t}\n\n\tpublic async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n\t\tthrow new Error(\"NOT IMPLEMENTED!\");\n\t}\n\n\tprivate async getPreviousFullSnapshot(\n\t\tparentHandle: string,\n\t): Promise<ISnapshotTreeEx | null | undefined> {\n\t\treturn parentHandle\n\t\t\t? this.getVersions(parentHandle, 1).then(async (versions) => {\n\t\t\t\t\t// Clear the cache as the getSnapshotTree call will fill the cache.\n\t\t\t\t\tthis.blobsShaCache.clear();\n\t\t\t\t\treturn this.getSnapshotTree(versions[0]);\n\t\t\t\t})\n\t\t\t: undefined;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localSessionStorageDb.d.ts","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,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":"AAAA;;;GAGG;AAGH,OAAO,EAAe,GAAG,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAmTnE;;;GAGG;AACH,qBAAa,4BAA6B,YAAW,cAAc;IAClE,SAAgB,YAAY,EAAE,GAAG,CAA+B;IACnD,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;CAGpC"}
|
|
@@ -217,6 +217,7 @@ class LocalSessionStorageCollection {
|
|
|
217
217
|
insertInternal(...values) {
|
|
218
218
|
for (const value of values) {
|
|
219
219
|
if (value) {
|
|
220
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy
|
|
220
221
|
if (!value._id) {
|
|
221
222
|
value._id = (0, uuid_1.v4)();
|
|
222
223
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localSessionStorageDb.js","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA4D;AAG5D,+BAAkC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hD;;QACkB,gBAAW,GAAG,IAAI,GAAG,EAA8C,CAAC;IAgBtF,CAAC;IAfO,KAAK,CAAC,KAAK,KAAmB,CAAC;IAC/B,UAAU,CAAI,IAAY;QAChC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,6BAA6B,CAAI,IAAI,CAAC,CAAC,CAAC;QACxE,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAqC,CAAC;IACvE,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,IAAY;QACvC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC;QACb,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAED;;;GAGG;AACH,MAAa,4BAA4B;IAAzC;QACiB,iBAAY,GAAQ,IAAI,qBAAqB,EAAE,CAAC;IAIjE,CAAC;IAHO,KAAK,CAAC,OAAO;QACnB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;CACD;AALD,oEAKC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"@fluid-internal/client-utils\";\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\t/**\n\t * @param collectionName - data type of the collection, e.g. blobs, deltas, trees, etc.\n\t */\n\tconstructor(private readonly collectionName: string) {}\n\n\tpublic aggregate(pipeline: any, options?: any): any {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\n\tpublic async updateMany(filter: any, set: any, addToSet: any): Promise<void> {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\tpublic async distinct(key: any, query: any): Promise<any> {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\tpublic async findAndUpdate(query: any, value: T): Promise<{ value: T; existing: boolean }> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.find}\n\t */\n\t/*\n\t * Each query key consists of several keys separated by '.' e.g: \"operation.sequenceNumber\".\n\t * The hierarchical syntax allows finding nested key patterns.\n\t */\n\tpublic async find(query: any, sort: any): Promise<any[]> {\n\t\t// split the keys and get the corresponding value\n\t\tfunction getValueByKey(propertyBag, key: string): any {\n\t\t\tconst keys = key.split(\".\");\n\t\t\tlet value = propertyBag;\n\t\t\tkeys.forEach((splitKey) => {\n\t\t\t\tvalue = value[splitKey];\n\t\t\t});\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\t\treturn value;\n\t\t}\n\n\t\t// getting keys of the query we are trying to find\n\t\tconst queryKeys = Object.keys(query);\n\t\tlet filteredCollection = this.getAllInternal();\n\t\tqueryKeys.forEach((key) => {\n\t\t\tif (!query[key]) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (query[key].$gt > 0 || query[key].$lt > 0) {\n\t\t\t\tif (query[key].$gt > 0) {\n\t\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t\t(value) => getValueByKey(value, key) > query[key].$gt,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (query[key].$lt > 0) {\n\t\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t\t(value) => getValueByKey(value, key) < query[key].$lt,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t(value) => getValueByKey(value, key) === query[key],\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\n\t\tif (sort && Object.keys(sort).length === 1) {\n\t\t\t// eslint-disable-next-line no-inner-declarations\n\t\t\tfunction compare(a, b): number {\n\t\t\t\t// Non null asserting here because of the length check above\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst sortKey = Object.keys(sort)[0]!;\n\t\t\t\treturn sort[sortKey] === 1\n\t\t\t\t\t? getValueByKey(a, sortKey) - getValueByKey(b, sortKey)\n\t\t\t\t\t: getValueByKey(b, sortKey) - getValueByKey(a, sortKey);\n\t\t\t}\n\n\t\t\tfilteredCollection = filteredCollection.sort(compare);\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn filteredCollection;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}\n\t */\n\tpublic async findAll(): Promise<any[]> {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn this.getAllInternal();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async findOne(query: any): Promise<any> {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn this.findOneInternal(query);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.update}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async update(query: any, set: any, addToSet: any): Promise<void> {\n\t\tconst value = this.findOneInternal(query);\n\t\tif (!value) {\n\t\t\tthrow new Error(\"Not found\");\n\t\t} else {\n\t\t\tfor (const key of Object.keys(set)) {\n\t\t\t\tvalue[key] = set[key];\n\t\t\t}\n\t\t\tthis.insertInternal(value);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async upsert(query: any, set: any, addToSet: any): Promise<void> {\n\t\tconst value = this.findOneInternal(query);\n\t\tif (!value) {\n\t\t\tthis.insertInternal(set);\n\t\t} else {\n\t\t\tfor (const key of Object.keys(set)) {\n\t\t\t\tvalue[key] = set[key];\n\t\t\t}\n\t\t\tthis.insertInternal(value);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}\n\t */\n\t/*\n\t * Value is expected to have a member \"_id\" which is a string used to search in the database.\n\t */\n\tpublic async insertOne(value: any): Promise<any> {\n\t\tconst presentVal = this.findOneInternal(value);\n\t\t// Only raise error when the object is present and the value is not equal.\n\t\tif (presentVal) {\n\t\t\tif (JSON.stringify(presentVal) === JSON.stringify(value)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow new Error(\"Existing Object!!\");\n\t\t}\n\n\t\treturn this.insertInternal(value);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}\n\t */\n\t/*\n\t * Value and query are expected to have a member \"_id\" which is a string used to search or insert in the database.\n\t */\n\tpublic async findOrCreate(\n\t\tquery: any,\n\t\tvalue: any,\n\t): Promise<{ value: any; existing: boolean }> {\n\t\tconst existing = this.findOneInternal(query);\n\t\tif (existing) {\n\t\t\treturn { value: existing, existing: true };\n\t\t}\n\t\tthis.insertInternal(value);\n\t\treturn { value, existing: false };\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}\n\t */\n\t/*\n\t * Each element in values is expected to have a member \"_id\" which is a string used to insert in the database.\n\t */\n\tpublic async insertMany(values: any[], ordered: boolean): Promise<void> {\n\t\tthis.insertInternal(...values);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteOne}\n\t */\n\tpublic async deleteOne(query: any): Promise<any> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteMany}\n\t */\n\tpublic async deleteMany(query: any): Promise<any> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.createIndex}\n\t */\n\tpublic async createIndex(index: any, unique: boolean): Promise<void> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * Return all values in the database\n\t */\n\tprivate getAllInternal(): any[] {\n\t\tconst values: string[] = [];\n\t\tfor (let i = 0; i < sessionStorage.length; i++) {\n\t\t\tconst key = sessionStorage.key(i);\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (key!.startsWith(this.collectionName)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tvalues.push(JSON.parse(sessionStorage.getItem(key!)!));\n\t\t\t}\n\t\t}\n\t\treturn values;\n\t}\n\n\t/**\n\t * Inserts values into the session storge.\n\t * Values are expected to have a member \"_id\" which is a unique id, otherwise will be assigned one\n\t *\n\t * @param values - data to insert to the database\n\t */\n\tprivate insertInternal(...values: any[]): void {\n\t\tfor (const value of values) {\n\t\t\tif (value) {\n\t\t\t\tif (!value._id) {\n\t\t\t\t\tvalue._id = uuid();\n\t\t\t\t}\n\t\t\t\tsessionStorage.setItem(`${this.collectionName}-${value._id}`, JSON.stringify(value));\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Finds the query in session storage and returns its value.\n\t * Returns null if query is not found.\n\t * Query is expected to have a member \"_id\" which is a unique id.\n\t *\n\t * @param query - what to find in the database\n\t */\n\tprivate findOneInternal(query: any): any {\n\t\tif (query._id) {\n\t\t\tconst json = sessionStorage.getItem(`${this.collectionName}-${query._id}`);\n\t\t\tif (json) {\n\t\t\t\treturn JSON.parse(json);\n\t\t\t}\n\t\t} else {\n\t\t\tconst queryKeys = Object.keys(query);\n\t\t\tfor (let i = 0; i < sessionStorage.length; i++) {\n\t\t\t\tconst ssKey = sessionStorage.key(i);\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tif (!ssKey!.startsWith(this.collectionName)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst value = JSON.parse(sessionStorage.getItem(ssKey!)!);\n\t\t\t\tlet foundMismatch = false;\n\t\t\t\tfor (const qk of queryKeys) {\n\t\t\t\t\tif (value[qk] !== query[qk]) {\n\t\t\t\t\t\tfoundMismatch = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!foundMismatch) {\n\t\t\t\t\treturn value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n}\n\n/**\n * A database for testing that stores data in the browsers session storage\n */\nclass LocalSessionStorageDb extends EventEmitter implements IDb {\n\tprivate readonly collections = new Map<string, LocalSessionStorageCollection<any>>();\n\tpublic async close(): Promise<void> {}\n\tpublic collection<T>(name: string): ICollection<T> {\n\t\tif (!this.collections.has(name)) {\n\t\t\tthis.collections.set(name, new LocalSessionStorageCollection<T>(name));\n\t\t}\n\t\treturn this.collections.get(name) as LocalSessionStorageCollection<T>;\n\t}\n\n\tpublic async dropCollection(name: string): Promise<boolean> {\n\t\tif (!this.collections.has(name)) {\n\t\t\treturn true;\n\t\t}\n\t\tthis.collections.delete(name);\n\t\treturn true;\n\t}\n}\n\n/**\n * A database factory for testing that stores data in the browsers session storage\n * @internal\n */\nexport class LocalSessionStorageDbFactory implements ITestDbFactory {\n\tpublic readonly testDatabase: IDb = new LocalSessionStorageDb();\n\tpublic async connect(): Promise<IDb> {\n\t\treturn this.testDatabase;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"localSessionStorageDb.js","sourceRoot":"","sources":["../src/localSessionStorageD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OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAED;;GAEG;AACH,MAAM,qBAAsB,SAAQ,2BAAY;IAAhD;;QACkB,gBAAW,GAAG,IAAI,GAAG,EAA8C,CAAC;IAgBtF,CAAC;IAfO,KAAK,CAAC,KAAK,KAAmB,CAAC;IAC/B,UAAU,CAAI,IAAY;QAChC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,6BAA6B,CAAI,IAAI,CAAC,CAAC,CAAC;QACxE,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAqC,CAAC;IACvE,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,IAAY;QACvC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC;QACb,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAED;;;GAGG;AACH,MAAa,4BAA4B;IAAzC;QACiB,iBAAY,GAAQ,IAAI,qBAAqB,EAAE,CAAC;IAIjE,CAAC;IAHO,KAAK,CAAC,OAAO;QACnB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;CACD;AALD,oEAKC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"@fluid-internal/client-utils\";\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\t/**\n\t * @param collectionName - data type of the collection, e.g. blobs, deltas, trees, etc.\n\t */\n\tconstructor(private readonly collectionName: string) {}\n\n\tpublic aggregate(pipeline: any, options?: any): any {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\n\tpublic async updateMany(filter: any, set: any, addToSet: any): Promise<void> {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\tpublic async distinct(key: any, query: any): Promise<any> {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\tpublic async findAndUpdate(query: any, value: T): Promise<{ value: T; existing: boolean }> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.find}\n\t */\n\t/*\n\t * Each query key consists of several keys separated by '.' e.g: \"operation.sequenceNumber\".\n\t * The hierarchical syntax allows finding nested key patterns.\n\t */\n\tpublic async find(query: any, sort: any): Promise<any[]> {\n\t\t// split the keys and get the corresponding value\n\t\tfunction getValueByKey(propertyBag, key: string): any {\n\t\t\tconst keys = key.split(\".\");\n\t\t\tlet value = propertyBag;\n\t\t\tkeys.forEach((splitKey) => {\n\t\t\t\tvalue = value[splitKey];\n\t\t\t});\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\t\treturn value;\n\t\t}\n\n\t\t// getting keys of the query we are trying to find\n\t\tconst queryKeys = Object.keys(query);\n\t\tlet filteredCollection = this.getAllInternal();\n\t\tqueryKeys.forEach((key) => {\n\t\t\tif (!query[key]) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (query[key].$gt > 0 || query[key].$lt > 0) {\n\t\t\t\tif (query[key].$gt > 0) {\n\t\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t\t(value) => getValueByKey(value, key) > query[key].$gt,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (query[key].$lt > 0) {\n\t\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t\t(value) => getValueByKey(value, key) < query[key].$lt,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t(value) => getValueByKey(value, key) === query[key],\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\n\t\tif (sort && Object.keys(sort).length === 1) {\n\t\t\t// eslint-disable-next-line no-inner-declarations\n\t\t\tfunction compare(a, b): number {\n\t\t\t\t// Non null asserting here because of the length check above\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst sortKey = Object.keys(sort)[0]!;\n\t\t\t\treturn sort[sortKey] === 1\n\t\t\t\t\t? getValueByKey(a, sortKey) - getValueByKey(b, sortKey)\n\t\t\t\t\t: getValueByKey(b, sortKey) - getValueByKey(a, sortKey);\n\t\t\t}\n\n\t\t\tfilteredCollection = filteredCollection.sort(compare);\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn filteredCollection;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}\n\t */\n\tpublic async findAll(): Promise<any[]> {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn this.getAllInternal();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async findOne(query: any): Promise<any> {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn this.findOneInternal(query);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.update}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async update(query: any, set: any, addToSet: any): Promise<void> {\n\t\tconst value = this.findOneInternal(query);\n\t\tif (!value) {\n\t\t\tthrow new Error(\"Not found\");\n\t\t} else {\n\t\t\tfor (const key of Object.keys(set)) {\n\t\t\t\tvalue[key] = set[key];\n\t\t\t}\n\t\t\tthis.insertInternal(value);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async upsert(query: any, set: any, addToSet: any): Promise<void> {\n\t\tconst value = this.findOneInternal(query);\n\t\tif (!value) {\n\t\t\tthis.insertInternal(set);\n\t\t} else {\n\t\t\tfor (const key of Object.keys(set)) {\n\t\t\t\tvalue[key] = set[key];\n\t\t\t}\n\t\t\tthis.insertInternal(value);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}\n\t */\n\t/*\n\t * Value is expected to have a member \"_id\" which is a string used to search in the database.\n\t */\n\tpublic async insertOne(value: any): Promise<any> {\n\t\tconst presentVal = this.findOneInternal(value);\n\t\t// Only raise error when the object is present and the value is not equal.\n\t\tif (presentVal) {\n\t\t\tif (JSON.stringify(presentVal) === JSON.stringify(value)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow new Error(\"Existing Object!!\");\n\t\t}\n\n\t\treturn this.insertInternal(value);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}\n\t */\n\t/*\n\t * Value and query are expected to have a member \"_id\" which is a string used to search or insert in the database.\n\t */\n\tpublic async findOrCreate(\n\t\tquery: any,\n\t\tvalue: any,\n\t): Promise<{ value: any; existing: boolean }> {\n\t\tconst existing = this.findOneInternal(query);\n\t\tif (existing) {\n\t\t\treturn { value: existing, existing: true };\n\t\t}\n\t\tthis.insertInternal(value);\n\t\treturn { value, existing: false };\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}\n\t */\n\t/*\n\t * Each element in values is expected to have a member \"_id\" which is a string used to insert in the database.\n\t */\n\tpublic async insertMany(values: any[], ordered: boolean): Promise<void> {\n\t\tthis.insertInternal(...values);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteOne}\n\t */\n\tpublic async deleteOne(query: any): Promise<any> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteMany}\n\t */\n\tpublic async deleteMany(query: any): Promise<any> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.createIndex}\n\t */\n\tpublic async createIndex(index: any, unique: boolean): Promise<void> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * Return all values in the database\n\t */\n\tprivate getAllInternal(): any[] {\n\t\tconst values: string[] = [];\n\t\tfor (let i = 0; i < sessionStorage.length; i++) {\n\t\t\tconst key = sessionStorage.key(i);\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (key!.startsWith(this.collectionName)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tvalues.push(JSON.parse(sessionStorage.getItem(key!)!));\n\t\t\t}\n\t\t}\n\t\treturn values;\n\t}\n\n\t/**\n\t * Inserts values into the session storge.\n\t * Values are expected to have a member \"_id\" which is a unique id, otherwise will be assigned one\n\t *\n\t * @param values - data to insert to the database\n\t */\n\tprivate insertInternal(...values: any[]): void {\n\t\tfor (const value of values) {\n\t\t\tif (value) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy\n\t\t\t\tif (!value._id) {\n\t\t\t\t\tvalue._id = uuid();\n\t\t\t\t}\n\t\t\t\tsessionStorage.setItem(`${this.collectionName}-${value._id}`, JSON.stringify(value));\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Finds the query in session storage and returns its value.\n\t * Returns null if query is not found.\n\t * Query is expected to have a member \"_id\" which is a unique id.\n\t *\n\t * @param query - what to find in the database\n\t */\n\tprivate findOneInternal(query: any): any {\n\t\tif (query._id) {\n\t\t\tconst json = sessionStorage.getItem(`${this.collectionName}-${query._id}`);\n\t\t\tif (json) {\n\t\t\t\treturn JSON.parse(json);\n\t\t\t}\n\t\t} else {\n\t\t\tconst queryKeys = Object.keys(query);\n\t\t\tfor (let i = 0; i < sessionStorage.length; i++) {\n\t\t\t\tconst ssKey = sessionStorage.key(i);\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tif (!ssKey!.startsWith(this.collectionName)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst value = JSON.parse(sessionStorage.getItem(ssKey!)!);\n\t\t\t\tlet foundMismatch = false;\n\t\t\t\tfor (const qk of queryKeys) {\n\t\t\t\t\tif (value[qk] !== query[qk]) {\n\t\t\t\t\t\tfoundMismatch = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!foundMismatch) {\n\t\t\t\t\treturn value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n}\n\n/**\n * A database for testing that stores data in the browsers session storage\n */\nclass LocalSessionStorageDb extends EventEmitter implements IDb {\n\tprivate readonly collections = new Map<string, LocalSessionStorageCollection<any>>();\n\tpublic async close(): Promise<void> {}\n\tpublic collection<T>(name: string): ICollection<T> {\n\t\tif (!this.collections.has(name)) {\n\t\t\tthis.collections.set(name, new LocalSessionStorageCollection<T>(name));\n\t\t}\n\t\treturn this.collections.get(name) as LocalSessionStorageCollection<T>;\n\t}\n\n\tpublic async dropCollection(name: string): Promise<boolean> {\n\t\tif (!this.collections.has(name)) {\n\t\t\treturn true;\n\t\t}\n\t\tthis.collections.delete(name);\n\t\treturn true;\n\t}\n}\n\n/**\n * A database factory for testing that stores data in the browsers session storage\n * @internal\n */\nexport class LocalSessionStorageDbFactory implements ITestDbFactory {\n\tpublic readonly testDatabase: IDb = new LocalSessionStorageDb();\n\tpublic async connect(): Promise<IDb> {\n\t\treturn this.testDatabase;\n\t}\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 = "2.
|
|
8
|
+
export declare const pkgVersion = "2.81.0-374083";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,iCAAiC,CAAC;AACtD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,iCAAiC,CAAC;AACtD,eAAO,MAAM,UAAU,kBAAkB,CAAC"}
|
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 = "2.
|
|
11
|
+
exports.pkgVersion = "2.81.0-374083";
|
|
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,
|
|
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,eAAe,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 = \"2.81.0-374083\";\n"]}
|
package/eslint.config.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* To regenerate: pnpm tsx scripts/generate-flat-eslint-configs.ts --typescript
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
5
4
|
*/
|
|
5
|
+
|
|
6
6
|
import type { Linter } from "eslint";
|
|
7
7
|
import { minimalDeprecated } from "../../../common/build/eslint-config-fluid/flat.mts";
|
|
8
8
|
|
package/lib/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAC3D,OAAO,EAAgB,SAAS,EAAE,MAAM,6CAA6C,CAAC;AAItF;;;GAGG;AACH,wBAAgB,aAAa,CAC5B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,SAAS,EAAE,EACnB,IAAI,CAAC,EAAE,KAAK,EACZ,QAAQ,GAAE,MAAgB,EAC1B,GAAG,GAAE,MAAc,GACjB,MAAM,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAC3D,OAAO,EAAgB,SAAS,EAAE,MAAM,6CAA6C,CAAC;AAItF;;;GAGG;AACH,wBAAgB,aAAa,CAC5B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,SAAS,EAAE,EACnB,IAAI,CAAC,EAAE,KAAK,EACZ,QAAQ,GAAE,MAAgB,EAC1B,GAAG,GAAE,MAAc,GACjB,MAAM,CA2BR;AAED,wBAAgB,YAAY,IAAI,KAAK,CAWpC"}
|
package/lib/auth.js
CHANGED
|
@@ -9,6 +9,7 @@ import { v4 as uuid } from "uuid";
|
|
|
9
9
|
* services-client since it cannot run in the browser without polyfills.
|
|
10
10
|
*/
|
|
11
11
|
export function generateToken(tenantId, documentId, key, scopes, user, lifetime = 60 * 60, ver = "1.0") {
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ?? could change behavior for falsy values
|
|
12
13
|
let userClaim = user ? user : generateUser();
|
|
13
14
|
if (userClaim.id === "" || userClaim.id === undefined) {
|
|
14
15
|
userClaim = generateUser();
|
package/lib/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC;;;GAGG;AACH,MAAM,UAAU,aAAa,CAC5B,QAAgB,EAChB,UAAkB,EAClB,GAAW,EACX,MAAmB,EACnB,IAAY,EACZ,WAAmB,EAAE,GAAG,EAAE,EAC1B,MAAc,KAAK;IAEnB,IAAI,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC;IAC7C,IAAI,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,SAAS,CAAC,EAAE,KAAK,SAAS,EAAE,CAAC;QACvD,SAAS,GAAG,YAAY,EAAE,CAAC;IAC5B,CAAC;IAED,0BAA0B;IAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IAEpD,MAAM,MAAM,GAAiB;QAC5B,UAAU;QACV,MAAM;QACN,QAAQ;QACR,IAAI,EAAE,SAAS;QACf,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG,GAAG,QAAQ;QACnB,GAAG;KACH,CAAC;IAEF,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAC9B,OAAO,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAC5B,IAAI,EACJ,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAC5C,MAAM,EACN,OAAO,CACP,CAAC;AACH,CAAC;AAED,MAAM,UAAU,YAAY;IAC3B,MAAM,MAAM,GAAG,IAAI,EAAE,CAAC;IACtB,MAAM,KAAK,GAAG,4BAA4B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACxD,MAAM,QAAQ,GAAG,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,uEAAuE;IAE5H,MAAM,UAAU,GAAG;QAClB,EAAE,EAAE,MAAM;QACV,IAAI,EAAE,QAAQ;KACd,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IUser } from \"@fluidframework/driver-definitions\";\nimport { ITokenClaims, ScopeType } from \"@fluidframework/driver-definitions/internal\";\nimport { KJUR as jsrsasign } from \"jsrsasign\";\nimport { v4 as uuid } from \"uuid\";\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\ttenantId: string,\n\tdocumentId: string,\n\tkey: string,\n\tscopes: ScopeType[],\n\tuser?: IUser,\n\tlifetime: number = 60 * 60,\n\tver: string = \"1.0\",\n): string {\n\tlet userClaim = user ? user : generateUser();\n\tif (userClaim.id === \"\" || userClaim.id === undefined) {\n\t\tuserClaim = generateUser();\n\t}\n\n\t// Current time in seconds\n\tconst now = Math.round(new Date().getTime() / 1000);\n\n\tconst claims: ITokenClaims = {\n\t\tdocumentId,\n\t\tscopes,\n\t\ttenantId,\n\t\tuser: userClaim,\n\t\tiat: now,\n\t\texp: now + lifetime,\n\t\tver,\n\t};\n\n\tconst utf8Key = { utf8: key };\n\treturn jsrsasign.jws.JWS.sign(\n\t\tnull,\n\t\tJSON.stringify({ alg: \"HS256\", typ: \"JWT\" }),\n\t\tclaims,\n\t\tutf8Key,\n\t);\n}\n\nexport function generateUser(): IUser {\n\tconst userId = uuid();\n\tconst match = /^([\\da-f]{8})-([\\da-f]{4})/.exec(userId);\n\tconst userName = match !== null ? match[0] : userId; // Just use the first two segments of the (fake) userId as a fake name.\n\n\tconst randomUser = {\n\t\tid: userId,\n\t\tname: userName,\n\t};\n\n\treturn randomUser;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC;;;GAGG;AACH,MAAM,UAAU,aAAa,CAC5B,QAAgB,EAChB,UAAkB,EAClB,GAAW,EACX,MAAmB,EACnB,IAAY,EACZ,WAAmB,EAAE,GAAG,EAA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c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IUser } from \"@fluidframework/driver-definitions\";\nimport { ITokenClaims, ScopeType } from \"@fluidframework/driver-definitions/internal\";\nimport { KJUR as jsrsasign } from \"jsrsasign\";\nimport { v4 as uuid } from \"uuid\";\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\ttenantId: string,\n\tdocumentId: string,\n\tkey: string,\n\tscopes: ScopeType[],\n\tuser?: IUser,\n\tlifetime: number = 60 * 60,\n\tver: string = \"1.0\",\n): string {\n\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ?? could change behavior for falsy values\n\tlet userClaim = user ? user : generateUser();\n\tif (userClaim.id === \"\" || userClaim.id === undefined) {\n\t\tuserClaim = generateUser();\n\t}\n\n\t// Current time in seconds\n\tconst now = Math.round(new Date().getTime() / 1000);\n\n\tconst claims: ITokenClaims = {\n\t\tdocumentId,\n\t\tscopes,\n\t\ttenantId,\n\t\tuser: userClaim,\n\t\tiat: now,\n\t\texp: now + lifetime,\n\t\tver,\n\t};\n\n\tconst utf8Key = { utf8: key };\n\treturn jsrsasign.jws.JWS.sign(\n\t\tnull,\n\t\tJSON.stringify({ alg: \"HS256\", typ: \"JWT\" }),\n\t\tclaims,\n\t\tutf8Key,\n\t);\n}\n\nexport function generateUser(): IUser {\n\tconst userId = uuid();\n\tconst match = /^([\\da-f]{8})-([\\da-f]{4})/.exec(userId);\n\tconst userName = match !== null ? match[0] : userId; // Just use the first two segments of the (fake) userId as a fake name.\n\n\tconst randomUser = {\n\t\tid: userId,\n\t\tname: userName,\n\t};\n\n\treturn randomUser;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/localDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,EAAE,cAAc,EAAE,YAA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cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;YAI7D,uBAAuB;CAWrC"}
|
|
@@ -24,6 +24,7 @@ export class LocalDocumentStorageService {
|
|
|
24
24
|
this.summaryTreeUploadManager = new SummaryTreeUploadManager(manager, this.blobsShaCache, this.getPreviousFullSnapshot.bind(this));
|
|
25
25
|
}
|
|
26
26
|
async getVersions(versionId, count) {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ?? could change behavior for falsy values
|
|
27
28
|
const id = versionId ? versionId : this.id;
|
|
28
29
|
const commits = await this.manager.getCommits(id, count);
|
|
29
30
|
return commits.map((commit) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localDocumentStorageService.js","sourceRoot":"","sources":["../src/localDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,SAAS,EACT,kBAAkB,EAClB,cAAc,EACd,cAAc,GACd,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAa7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,EAGN,wBAAwB,GACxB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,mBAAmB;AACzD;;GAEG;AACH,MAAM,OAAO,2BAA2B;IAMvC,YACkB,EAAU,EACV,OAAmB,EACpB,QAAyC,EACxC,0BAAwD,EACxD,WAA0B;QAJ1B,OAAE,GAAF,EAAE,CAAQ;QACV,YAAO,GAAP,OAAO,CAAY;QACpB,aAAQ,GAAR,QAAQ,CAAiC;QACxC,+BAA0B,GAA1B,0BAA0B,CAA8B;QACxD,gBAAW,GAAX,WAAW,CAAe;QAV5C,uFAAuF;QACvF,2BAA2B;QACR,kBAAa,GAAG,IAAI,GAAG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CAAC,kBAAkB,CAAC,CAAC;IACrC,CAAC;IAEO,KAAK,CAAC,uBAAuB,CACpC,YAAoB;QAEpB,OAAO,YAAY;YAClB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;gBAC1D,mEAAmE;gBACnE,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;gBAC3B,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1C,CAAC,CAAC;YACH,CAAC,CAAC,SAAS,CAAC;IACd,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIsoBuffer,\n\tUint8ArrayToString,\n\tbufferToString,\n\tstringToBuffer,\n} from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { ISummaryHandle, ISummaryTree } from \"@fluidframework/driver-definitions\";\nimport {\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n\tIResolvedUrl,\n\ttype ISnapshot,\n\ttype ISnapshotFetchOptions,\n\tISummaryContext,\n\tICreateBlobResponse,\n\tISnapshotTreeEx,\n\tIVersion,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { buildGitTreeHierarchy } from \"@fluidframework/protocol-base\";\nimport { ILocalDeltaConnectionServer } from \"@fluidframework/server-local-server\";\nimport {\n\tGitManager,\n\tISummaryUploadManager,\n\tSummaryTreeUploadManager,\n} from \"@fluidframework/server-services-client\";\n\nimport { createDocument } from \"./localCreateDocument.js\";\n\nconst minTTLInSeconds = 24 * 60 * 60; // Same TTL as ODSP\n/**\n * @internal\n */\nexport class LocalDocumentStorageService implements IDocumentStorageService {\n\t// The values of this cache is useless. We only need the keys. So we are always putting\n\t// empty strings as values.\n\tprotected readonly blobsShaCache = new Map<string, string>();\n\tprivate readonly summaryTreeUploadManager: ISummaryUploadManager;\n\n\tconstructor(\n\t\tprivate readonly id: string,\n\t\tprivate readonly manager: GitManager,\n\t\tpublic readonly policies: IDocumentStorageServicePolicies,\n\t\tprivate readonly localDeltaConnectionServer?: ILocalDeltaConnectionServer,\n\t\tprivate readonly resolvedUrl?: IResolvedUrl,\n\t) {\n\t\tthis.summaryTreeUploadManager = new SummaryTreeUploadManager(\n\t\t\tmanager,\n\t\t\tthis.blobsShaCache,\n\t\t\tthis.getPreviousFullSnapshot.bind(this),\n\t\t);\n\t}\n\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\tconst id = versionId ? versionId : this.id;\n\t\tconst commits = await this.manager.getCommits(id, count);\n\t\treturn commits.map((commit) => ({\n\t\t\tdate: commit.commit.author.date,\n\t\t\tid: commit.sha,\n\t\t\ttreeId: commit.commit.tree.sha,\n\t\t}));\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null> {\n\t\tlet requestVersion = version;\n\t\tif (!requestVersion) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\t// Non null asserting here because of the length check above\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\trequestVersion = versions[0]!;\n\t\t}\n\n\t\tconst rawTree = await this.manager.getTree(requestVersion.treeId);\n\t\tconst tree = buildGitTreeHierarchy(rawTree, this.blobsShaCache, true);\n\t\tawait this.populateGroupId(tree);\n\t\treturn tree;\n\t}\n\n\tpublic async getSnapshot(snapshotFetchOptions?: ISnapshotFetchOptions): Promise<ISnapshot> {\n\t\tlet versionId = snapshotFetchOptions?.versionId;\n\t\tif (!versionId) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\tthrow new Error(\"No versions for the document!\");\n\t\t\t}\n\n\t\t\t// Non null asserting here because of the length check above\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tversionId = versions[0]!.treeId;\n\t\t}\n\t\tconst rawTree = await this.manager.getTree(versionId);\n\t\tconst snapshotTree = buildGitTreeHierarchy(rawTree, this.blobsShaCache, true);\n\t\tconst groupIds = new Set<string>(snapshotFetchOptions?.loadingGroupIds ?? []);\n\t\t// TODO Why are we non null asserting here\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst attributesBlobId = snapshotTree.trees[\".protocol\"]!.blobs.attributes!;\n\t\t// Only populate contents for the blobs which are supposed to be returned.\n\t\tconst blobContents = new Map<string, ArrayBuffer>();\n\t\tconst attributesBlobData = await this.readBlob(attributesBlobId);\n\t\tif (groupIds.has(\"\") || groupIds.size === 0) {\n\t\t\t// If the root is in the groupIds, we don't need to filter the tree.\n\t\t\t// We can just strip the of all groupIds as in collect the blobIds so that we can\n\t\t\t// return blob contents only for those ids.\n\t\t\tawait this.collectBlobContentsForUngroupedSnapshot(snapshotTree, groupIds, blobContents);\n\t\t} else {\n\t\t\tconst hasFoundTree = await this.filterTreeByLoadingGroupIds(\n\t\t\t\tsnapshotTree,\n\t\t\t\tgroupIds,\n\t\t\t\tfalse,\n\t\t\t\tblobContents,\n\t\t\t);\n\t\t\tassert(hasFoundTree, 0x8dd /* No tree found for the given groupIds */);\n\t\t}\n\n\t\tconst attributesString = IsoBuffer.from(attributesBlobData).toString(\"utf-8\");\n\t\tconst attributes = JSON.parse(attributesString);\n\t\tconst sequenceNumber: number = attributes.sequenceNumber ?? 0;\n\t\treturn {\n\t\t\tsnapshotTree,\n\t\t\tblobContents,\n\t\t\tops: [],\n\t\t\tsnapshotFormatV: 1,\n\t\t\tsequenceNumber,\n\t\t\tlatestSequenceNumber: undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Collect the blobIds to keep in the snapshot for ungrouped snapshot plus\n\t * any other loading groupId along with it.\n\t *\n\t * @param tree - The tree to evaluate for loading groupIds\n\t * @returns a tree that has trees with groupIds that are empty\n\t */\n\tprivate async collectBlobContentsForUngroupedSnapshot(\n\t\ttree: ISnapshotTreeEx,\n\t\tloadingGroupIds: Set<string>,\n\t\tblobContents: Map<string, ArrayBuffer>,\n\t): Promise<void> {\n\t\tconst groupId = await this.readGroupId(tree);\n\t\tif (groupId === undefined || loadingGroupIds.has(groupId)) {\n\t\t\tfor (const id of Object.values(tree.blobs)) {\n\t\t\t\tblobContents.set(id, await this.readBlob(id));\n\t\t\t}\n\t\t\tawait Promise.all(\n\t\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\t\tawait this.collectBlobContentsForUngroupedSnapshot(\n\t\t\t\t\t\tchildTree,\n\t\t\t\t\t\tloadingGroupIds,\n\t\t\t\t\t\tblobContents,\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Named differently as the algorithm is a little more involved.\n\t *\n\t * We want to strip the tree if it has a groupId that is not in the loadingGroupIds or if it doesn't have a descendent or ancestor\n\t * that has a groupId that is in the loadingGroupIds.\n\t *\n\t * We keep the tree in the opposite case.\n\t *\n\t * @param tree - the tree to strip of any data that is not in the loadingGroupIds\n\t * @param loadingGroupIds - the set of groupIds that are being loaded\n\t * @param ancestorGroupIdInLoadingGroup - whether the ancestor of the tree has a groupId that is in the loadingGroupIds\n\t * @returns whether or not it or descendant has a groupId that is in the loadingGroupIds\n\t */\n\tprivate async filterTreeByLoadingGroupIds(\n\t\ttree: ISnapshotTreeEx,\n\t\tloadingGroupIds: Set<string>,\n\t\tancestorGroupIdInLoadingGroup: boolean,\n\t\tblobContents: Map<string, ArrayBuffer>,\n\t): Promise<boolean> {\n\t\tassert(loadingGroupIds.size > 0, 0x8de /* loadingGroupIds should not be empty */);\n\t\tconst groupId = await this.readGroupId(tree);\n\n\t\t// Strip the tree if it has a groupId and it is not in the loadingGroupIds\n\t\t// This is an optimization here as we have other reasons to keep the tree.\n\t\tconst noGroupIdInLoadingGroupIds = groupId !== undefined && !loadingGroupIds.has(groupId);\n\t\tif (noGroupIdInLoadingGroupIds) {\n\t\t\tthis.stripTree(tree, groupId);\n\t\t\treturn false;\n\t\t}\n\n\t\t// Keep tree if it has a groupId and it is in the loadingGroupIds\n\t\tconst groupIdInLoadingGroupIds = groupId !== undefined && loadingGroupIds.has(groupId);\n\n\t\t// Keep tree if it has an ancestor that has a groupId that is in loadingGroupIds and it doesn't have groupId\n\t\tconst isChildOfAncestorWithGroupId =\n\t\t\tancestorGroupIdInLoadingGroup && groupId === undefined;\n\n\t\t// Collect blobsIds so that we can return blob contents only for these blobs.\n\t\tif (groupIdInLoadingGroupIds || isChildOfAncestorWithGroupId) {\n\t\t\tfor (const id of Object.values(tree.blobs)) {\n\t\t\t\tblobContents.set(id, await this.readBlob(id));\n\t\t\t}\n\t\t}\n\t\t// Keep tree if it has a child that has a groupId that is in loadingGroupIds\n\t\tconst descendants = await Promise.all<boolean>(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\treturn this.filterTreeByLoadingGroupIds(\n\t\t\t\t\tchildTree,\n\t\t\t\t\tloadingGroupIds,\n\t\t\t\t\tancestorGroupIdInLoadingGroup || groupIdInLoadingGroupIds,\n\t\t\t\t\tblobContents,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tconst isAncestorOfDescendantsWithGroupId = descendants.some((keep) => keep);\n\n\t\t// We don't want to return prematurely as we still may have children that we want to keep.\n\t\tif (\n\t\t\tgroupIdInLoadingGroupIds ||\n\t\t\tisChildOfAncestorWithGroupId ||\n\t\t\tisAncestorOfDescendantsWithGroupId\n\t\t) {\n\t\t\t// Keep this tree node\n\t\t\treturn true;\n\t\t}\n\n\t\t// This means we have no groupId and none of our ancestors or descendants have a groupId in the loadingGroupIds\n\t\tthis.stripTree(tree, groupId);\n\t\treturn false;\n\t}\n\n\t// Takes all the blobs of a tree and puts it into the blobContents\n\tprivate async populateBlobContents(\n\t\ttree: ISnapshotTreeEx,\n\t\tblobContents: Map<string, ArrayBufferLike>,\n\t\tblobIdsToKeep: Set<string>,\n\t): Promise<void> {\n\t\tawait Promise.all(\n\t\t\tObject.entries(tree.blobs).map(async ([path, blobId]) => {\n\t\t\t\tif (blobIdsToKeep.has(blobId)) {\n\t\t\t\t\tconst content = await this.readBlob(blobId);\n\t\t\t\t\tblobContents.set(blobId, content);\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t\tawait Promise.all(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\tawait this.populateBlobContents(childTree, blobContents, blobIdsToKeep);\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate async populateGroupId(tree: ISnapshotTreeEx): Promise<void> {\n\t\tawait this.readGroupId(tree);\n\t\tawait Promise.all(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\tawait this.populateGroupId(childTree);\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate stripTree(tree: ISnapshotTreeEx, groupId: string | undefined): void {\n\t\ttree.blobs = {};\n\t\ttree.groupId = groupId;\n\t\ttree.trees = {};\n\t}\n\n\tprivate async readGroupId(tree: ISnapshotTreeEx): Promise<string | undefined> {\n\t\tconst groupIdBlobId = tree.blobs[\".groupId\"];\n\t\tif (groupIdBlobId !== undefined) {\n\t\t\tconst groupIdBuffer = await this.readBlob(groupIdBlobId);\n\t\t\tconst groupId = bufferToString(groupIdBuffer, \"utf8\");\n\t\t\ttree.groupId = groupId;\n\t\t\tdelete tree.blobs[\".groupId\"];\n\t\t\treturn groupId;\n\t\t}\n\n\t\treturn tree.groupId;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\tconst blob = await this.manager.getBlob(blobId);\n\t\tthis.blobsShaCache.set(blob.sha, \"\");\n\t\tconst bufferContent = stringToBuffer(blob.content, blob.encoding);\n\t\treturn bufferContent;\n\t}\n\n\tpublic async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\tif (context.referenceSequenceNumber === 0) {\n\t\t\tif (this.localDeltaConnectionServer === undefined || this.resolvedUrl === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Insufficient constructor parameters. An ILocalDeltaConnectionServer and IResolvedUrl required\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait createDocument(this.localDeltaConnectionServer, this.resolvedUrl, summary);\n\t\t\tconst version = await this.getVersions(this.id, 1);\n\t\t\t// TODO Why are we non null asserting here\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\treturn version[0]!.id;\n\t\t}\n\t\treturn this.summaryTreeUploadManager.writeSummaryTree(\n\t\t\tsummary,\n\t\t\tcontext.ackHandle ?? \"\",\n\t\t\t\"channel\",\n\t\t);\n\t}\n\n\tpublic async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\tconst uint8ArrayFile = new Uint8Array(file);\n\t\treturn this.manager\n\t\t\t.createBlob(Uint8ArrayToString(uint8ArrayFile, \"base64\"), \"base64\")\n\t\t\t.then((r) => ({ id: r.sha, url: r.url, minTTLInSeconds }));\n\t}\n\n\tpublic async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n\t\tthrow new Error(\"NOT IMPLEMENTED!\");\n\t}\n\n\tprivate async getPreviousFullSnapshot(\n\t\tparentHandle: string,\n\t): Promise<ISnapshotTreeEx | null | undefined> {\n\t\treturn parentHandle\n\t\t\t? this.getVersions(parentHandle, 1).then(async (versions) => {\n\t\t\t\t\t// Clear the cache as the getSnapshotTree call will fill the cache.\n\t\t\t\t\tthis.blobsShaCache.clear();\n\t\t\t\t\treturn this.getSnapshotTree(versions[0]);\n\t\t\t\t})\n\t\t\t: undefined;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"localDocumentStorageService.js","sourceRoot":"","sources":["../src/localDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,SAAS,EACT,kBAAkB,EAClB,cAA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C,CAAC;YACnD,0CAA0C;YAC1C,oEAAoE;YACpE,OAAO,OAAO,CAAC,CAAC,CAAE,CAAC,EAAE,CAAC;QACvB,CAAC;QACD,OAAO,IAAI,CAAC,wBAAwB,CAAC,gBAAgB,CACpD,OAAO,EACP,OAAO,CAAC,SAAS,IAAI,EAAE,EACvB,SAAS,CACT,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,IAAqB;QAC5C,MAAM,cAAc,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC,OAAO;aACjB,UAAU,CAAC,kBAAkB,CAAC,cAAc,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC;aAClE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,MAAsB;QAClD,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACrC,CAAC;IAEO,KAAK,CAAC,uBAAuB,CACpC,YAAoB;QAEpB,OAAO,YAAY;YAClB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;gBAC1D,mEAAmE;gBACnE,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;gBAC3B,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1C,CAAC,CAAC;YACH,CAAC,CAAC,SAAS,CAAC;IACd,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIsoBuffer,\n\tUint8ArrayToString,\n\tbufferToString,\n\tstringToBuffer,\n} from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { ISummaryHandle, ISummaryTree } from \"@fluidframework/driver-definitions\";\nimport {\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n\tIResolvedUrl,\n\ttype ISnapshot,\n\ttype ISnapshotFetchOptions,\n\tISummaryContext,\n\tICreateBlobResponse,\n\tISnapshotTreeEx,\n\tIVersion,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { buildGitTreeHierarchy } from \"@fluidframework/protocol-base\";\nimport { ILocalDeltaConnectionServer } from \"@fluidframework/server-local-server\";\nimport {\n\tGitManager,\n\tISummaryUploadManager,\n\tSummaryTreeUploadManager,\n} from \"@fluidframework/server-services-client\";\n\nimport { createDocument } from \"./localCreateDocument.js\";\n\nconst minTTLInSeconds = 24 * 60 * 60; // Same TTL as ODSP\n/**\n * @internal\n */\nexport class LocalDocumentStorageService implements IDocumentStorageService {\n\t// The values of this cache is useless. We only need the keys. So we are always putting\n\t// empty strings as values.\n\tprotected readonly blobsShaCache = new Map<string, string>();\n\tprivate readonly summaryTreeUploadManager: ISummaryUploadManager;\n\n\tconstructor(\n\t\tprivate readonly id: string,\n\t\tprivate readonly manager: GitManager,\n\t\tpublic readonly policies: IDocumentStorageServicePolicies,\n\t\tprivate readonly localDeltaConnectionServer?: ILocalDeltaConnectionServer,\n\t\tprivate readonly resolvedUrl?: IResolvedUrl,\n\t) {\n\t\tthis.summaryTreeUploadManager = new SummaryTreeUploadManager(\n\t\t\tmanager,\n\t\t\tthis.blobsShaCache,\n\t\t\tthis.getPreviousFullSnapshot.bind(this),\n\t\t);\n\t}\n\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ?? could change behavior for falsy values\n\t\tconst id = versionId ? versionId : this.id;\n\t\tconst commits = await this.manager.getCommits(id, count);\n\t\treturn commits.map((commit) => ({\n\t\t\tdate: commit.commit.author.date,\n\t\t\tid: commit.sha,\n\t\t\ttreeId: commit.commit.tree.sha,\n\t\t}));\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null> {\n\t\tlet requestVersion = version;\n\t\tif (!requestVersion) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\t// Non null asserting here because of the length check above\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\trequestVersion = versions[0]!;\n\t\t}\n\n\t\tconst rawTree = await this.manager.getTree(requestVersion.treeId);\n\t\tconst tree = buildGitTreeHierarchy(rawTree, this.blobsShaCache, true);\n\t\tawait this.populateGroupId(tree);\n\t\treturn tree;\n\t}\n\n\tpublic async getSnapshot(snapshotFetchOptions?: ISnapshotFetchOptions): Promise<ISnapshot> {\n\t\tlet versionId = snapshotFetchOptions?.versionId;\n\t\tif (!versionId) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\tthrow new Error(\"No versions for the document!\");\n\t\t\t}\n\n\t\t\t// Non null asserting here because of the length check above\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tversionId = versions[0]!.treeId;\n\t\t}\n\t\tconst rawTree = await this.manager.getTree(versionId);\n\t\tconst snapshotTree = buildGitTreeHierarchy(rawTree, this.blobsShaCache, true);\n\t\tconst groupIds = new Set<string>(snapshotFetchOptions?.loadingGroupIds ?? []);\n\t\t// TODO Why are we non null asserting here\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst attributesBlobId = snapshotTree.trees[\".protocol\"]!.blobs.attributes!;\n\t\t// Only populate contents for the blobs which are supposed to be returned.\n\t\tconst blobContents = new Map<string, ArrayBuffer>();\n\t\tconst attributesBlobData = await this.readBlob(attributesBlobId);\n\t\tif (groupIds.has(\"\") || groupIds.size === 0) {\n\t\t\t// If the root is in the groupIds, we don't need to filter the tree.\n\t\t\t// We can just strip the of all groupIds as in collect the blobIds so that we can\n\t\t\t// return blob contents only for those ids.\n\t\t\tawait this.collectBlobContentsForUngroupedSnapshot(snapshotTree, groupIds, blobContents);\n\t\t} else {\n\t\t\tconst hasFoundTree = await this.filterTreeByLoadingGroupIds(\n\t\t\t\tsnapshotTree,\n\t\t\t\tgroupIds,\n\t\t\t\tfalse,\n\t\t\t\tblobContents,\n\t\t\t);\n\t\t\tassert(hasFoundTree, 0x8dd /* No tree found for the given groupIds */);\n\t\t}\n\n\t\tconst attributesString = IsoBuffer.from(attributesBlobData).toString(\"utf-8\");\n\t\tconst attributes = JSON.parse(attributesString);\n\t\tconst sequenceNumber: number = attributes.sequenceNumber ?? 0;\n\t\treturn {\n\t\t\tsnapshotTree,\n\t\t\tblobContents,\n\t\t\tops: [],\n\t\t\tsnapshotFormatV: 1,\n\t\t\tsequenceNumber,\n\t\t\tlatestSequenceNumber: undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Collect the blobIds to keep in the snapshot for ungrouped snapshot plus\n\t * any other loading groupId along with it.\n\t *\n\t * @param tree - The tree to evaluate for loading groupIds\n\t * @returns a tree that has trees with groupIds that are empty\n\t */\n\tprivate async collectBlobContentsForUngroupedSnapshot(\n\t\ttree: ISnapshotTreeEx,\n\t\tloadingGroupIds: Set<string>,\n\t\tblobContents: Map<string, ArrayBuffer>,\n\t): Promise<void> {\n\t\tconst groupId = await this.readGroupId(tree);\n\t\tif (groupId === undefined || loadingGroupIds.has(groupId)) {\n\t\t\tfor (const id of Object.values(tree.blobs)) {\n\t\t\t\tblobContents.set(id, await this.readBlob(id));\n\t\t\t}\n\t\t\tawait Promise.all(\n\t\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\t\tawait this.collectBlobContentsForUngroupedSnapshot(\n\t\t\t\t\t\tchildTree,\n\t\t\t\t\t\tloadingGroupIds,\n\t\t\t\t\t\tblobContents,\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Named differently as the algorithm is a little more involved.\n\t *\n\t * We want to strip the tree if it has a groupId that is not in the loadingGroupIds or if it doesn't have a descendent or ancestor\n\t * that has a groupId that is in the loadingGroupIds.\n\t *\n\t * We keep the tree in the opposite case.\n\t *\n\t * @param tree - the tree to strip of any data that is not in the loadingGroupIds\n\t * @param loadingGroupIds - the set of groupIds that are being loaded\n\t * @param ancestorGroupIdInLoadingGroup - whether the ancestor of the tree has a groupId that is in the loadingGroupIds\n\t * @returns whether or not it or descendant has a groupId that is in the loadingGroupIds\n\t */\n\tprivate async filterTreeByLoadingGroupIds(\n\t\ttree: ISnapshotTreeEx,\n\t\tloadingGroupIds: Set<string>,\n\t\tancestorGroupIdInLoadingGroup: boolean,\n\t\tblobContents: Map<string, ArrayBuffer>,\n\t): Promise<boolean> {\n\t\tassert(loadingGroupIds.size > 0, 0x8de /* loadingGroupIds should not be empty */);\n\t\tconst groupId = await this.readGroupId(tree);\n\n\t\t// Strip the tree if it has a groupId and it is not in the loadingGroupIds\n\t\t// This is an optimization here as we have other reasons to keep the tree.\n\t\tconst noGroupIdInLoadingGroupIds = groupId !== undefined && !loadingGroupIds.has(groupId);\n\t\tif (noGroupIdInLoadingGroupIds) {\n\t\t\tthis.stripTree(tree, groupId);\n\t\t\treturn false;\n\t\t}\n\n\t\t// Keep tree if it has a groupId and it is in the loadingGroupIds\n\t\tconst groupIdInLoadingGroupIds = groupId !== undefined && loadingGroupIds.has(groupId);\n\n\t\t// Keep tree if it has an ancestor that has a groupId that is in loadingGroupIds and it doesn't have groupId\n\t\tconst isChildOfAncestorWithGroupId =\n\t\t\tancestorGroupIdInLoadingGroup && groupId === undefined;\n\n\t\t// Collect blobsIds so that we can return blob contents only for these blobs.\n\t\tif (groupIdInLoadingGroupIds || isChildOfAncestorWithGroupId) {\n\t\t\tfor (const id of Object.values(tree.blobs)) {\n\t\t\t\tblobContents.set(id, await this.readBlob(id));\n\t\t\t}\n\t\t}\n\t\t// Keep tree if it has a child that has a groupId that is in loadingGroupIds\n\t\tconst descendants = await Promise.all<boolean>(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\treturn this.filterTreeByLoadingGroupIds(\n\t\t\t\t\tchildTree,\n\t\t\t\t\tloadingGroupIds,\n\t\t\t\t\tancestorGroupIdInLoadingGroup || groupIdInLoadingGroupIds,\n\t\t\t\t\tblobContents,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tconst isAncestorOfDescendantsWithGroupId = descendants.some((keep) => keep);\n\n\t\t// We don't want to return prematurely as we still may have children that we want to keep.\n\t\tif (\n\t\t\tgroupIdInLoadingGroupIds ||\n\t\t\tisChildOfAncestorWithGroupId ||\n\t\t\tisAncestorOfDescendantsWithGroupId\n\t\t) {\n\t\t\t// Keep this tree node\n\t\t\treturn true;\n\t\t}\n\n\t\t// This means we have no groupId and none of our ancestors or descendants have a groupId in the loadingGroupIds\n\t\tthis.stripTree(tree, groupId);\n\t\treturn false;\n\t}\n\n\t// Takes all the blobs of a tree and puts it into the blobContents\n\tprivate async populateBlobContents(\n\t\ttree: ISnapshotTreeEx,\n\t\tblobContents: Map<string, ArrayBufferLike>,\n\t\tblobIdsToKeep: Set<string>,\n\t): Promise<void> {\n\t\tawait Promise.all(\n\t\t\tObject.entries(tree.blobs).map(async ([path, blobId]) => {\n\t\t\t\tif (blobIdsToKeep.has(blobId)) {\n\t\t\t\t\tconst content = await this.readBlob(blobId);\n\t\t\t\t\tblobContents.set(blobId, content);\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t\tawait Promise.all(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\tawait this.populateBlobContents(childTree, blobContents, blobIdsToKeep);\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate async populateGroupId(tree: ISnapshotTreeEx): Promise<void> {\n\t\tawait this.readGroupId(tree);\n\t\tawait Promise.all(\n\t\t\tObject.values(tree.trees).map(async (childTree) => {\n\t\t\t\tawait this.populateGroupId(childTree);\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate stripTree(tree: ISnapshotTreeEx, groupId: string | undefined): void {\n\t\ttree.blobs = {};\n\t\ttree.groupId = groupId;\n\t\ttree.trees = {};\n\t}\n\n\tprivate async readGroupId(tree: ISnapshotTreeEx): Promise<string | undefined> {\n\t\tconst groupIdBlobId = tree.blobs[\".groupId\"];\n\t\tif (groupIdBlobId !== undefined) {\n\t\t\tconst groupIdBuffer = await this.readBlob(groupIdBlobId);\n\t\t\tconst groupId = bufferToString(groupIdBuffer, \"utf8\");\n\t\t\ttree.groupId = groupId;\n\t\t\tdelete tree.blobs[\".groupId\"];\n\t\t\treturn groupId;\n\t\t}\n\n\t\treturn tree.groupId;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\tconst blob = await this.manager.getBlob(blobId);\n\t\tthis.blobsShaCache.set(blob.sha, \"\");\n\t\tconst bufferContent = stringToBuffer(blob.content, blob.encoding);\n\t\treturn bufferContent;\n\t}\n\n\tpublic async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\tif (context.referenceSequenceNumber === 0) {\n\t\t\tif (this.localDeltaConnectionServer === undefined || this.resolvedUrl === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Insufficient constructor parameters. An ILocalDeltaConnectionServer and IResolvedUrl required\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait createDocument(this.localDeltaConnectionServer, this.resolvedUrl, summary);\n\t\t\tconst version = await this.getVersions(this.id, 1);\n\t\t\t// TODO Why are we non null asserting here\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\treturn version[0]!.id;\n\t\t}\n\t\treturn this.summaryTreeUploadManager.writeSummaryTree(\n\t\t\tsummary,\n\t\t\tcontext.ackHandle ?? \"\",\n\t\t\t\"channel\",\n\t\t);\n\t}\n\n\tpublic async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\tconst uint8ArrayFile = new Uint8Array(file);\n\t\treturn this.manager\n\t\t\t.createBlob(Uint8ArrayToString(uint8ArrayFile, \"base64\"), \"base64\")\n\t\t\t.then((r) => ({ id: r.sha, url: r.url, minTTLInSeconds }));\n\t}\n\n\tpublic async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n\t\tthrow new Error(\"NOT IMPLEMENTED!\");\n\t}\n\n\tprivate async getPreviousFullSnapshot(\n\t\tparentHandle: string,\n\t): Promise<ISnapshotTreeEx | null | undefined> {\n\t\treturn parentHandle\n\t\t\t? this.getVersions(parentHandle, 1).then(async (versions) => {\n\t\t\t\t\t// Clear the cache as the getSnapshotTree call will fill the cache.\n\t\t\t\t\tthis.blobsShaCache.clear();\n\t\t\t\t\treturn this.getSnapshotTree(versions[0]);\n\t\t\t\t})\n\t\t\t: undefined;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localSessionStorageDb.d.ts","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,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":"AAAA;;;GAGG;AAGH,OAAO,EAAe,GAAG,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAmTnE;;;GAGG;AACH,qBAAa,4BAA6B,YAAW,cAAc;IAClE,SAAgB,YAAY,EAAE,GAAG,CAA+B;IACnD,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;CAGpC"}
|
|
@@ -214,6 +214,7 @@ class LocalSessionStorageCollection {
|
|
|
214
214
|
insertInternal(...values) {
|
|
215
215
|
for (const value of values) {
|
|
216
216
|
if (value) {
|
|
217
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy
|
|
217
218
|
if (!value._id) {
|
|
218
219
|
value._id = uuid();
|
|
219
220
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localSessionStorageDb.js","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAG5D,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC;;;GAGG;AACH,MAAM,6BAA6B;IAClC;;OAEG;IACH,YAA6B,cAAsB;QAAtB,mBAAc,GAAd,cAAc,CAAQ;IAAG,CAAC;IAEhD,SAAS,CAAC,QAAa,EAAE,OAAa;QAC5C,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC3C,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,MAAW,EAAE,GAAQ,EAAE,QAAa;QAC3D,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC3C,CAAC;IACM,KAAK,CAAC,QAAQ,CAAC,GAAQ,EAAE,KAAU;QACzC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC3C,CAAC;IACM,KAAK,CAAC,aAAa,CAAC,KAAU,EAAE,KAAQ;QAC9C,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IAED;;OAEG;IACH;;;OAGG;IACI,KAAK,CAAC,IAAI,CAAC,KAAU,EAAE,IAAS;QACtC,iDAAiD;QACjD,SAAS,aAAa,CAAC,WAAW,EAAE,GAAW;YAC9C,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAI,KAAK,GAAG,WAAW,CAAC;YACxB,IAAI,CAA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D","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"@fluid-internal/client-utils\";\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\t/**\n\t * @param collectionName - data type of the collection, e.g. blobs, deltas, trees, etc.\n\t */\n\tconstructor(private readonly collectionName: string) {}\n\n\tpublic aggregate(pipeline: any, options?: any): any {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\n\tpublic async updateMany(filter: any, set: any, addToSet: any): Promise<void> {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\tpublic async distinct(key: any, query: any): Promise<any> {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\tpublic async findAndUpdate(query: any, value: T): Promise<{ value: T; existing: boolean }> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.find}\n\t */\n\t/*\n\t * Each query key consists of several keys separated by '.' e.g: \"operation.sequenceNumber\".\n\t * The hierarchical syntax allows finding nested key patterns.\n\t */\n\tpublic async find(query: any, sort: any): Promise<any[]> {\n\t\t// split the keys and get the corresponding value\n\t\tfunction getValueByKey(propertyBag, key: string): any {\n\t\t\tconst keys = key.split(\".\");\n\t\t\tlet value = propertyBag;\n\t\t\tkeys.forEach((splitKey) => {\n\t\t\t\tvalue = value[splitKey];\n\t\t\t});\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\t\treturn value;\n\t\t}\n\n\t\t// getting keys of the query we are trying to find\n\t\tconst queryKeys = Object.keys(query);\n\t\tlet filteredCollection = this.getAllInternal();\n\t\tqueryKeys.forEach((key) => {\n\t\t\tif (!query[key]) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (query[key].$gt > 0 || query[key].$lt > 0) {\n\t\t\t\tif (query[key].$gt > 0) {\n\t\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t\t(value) => getValueByKey(value, key) > query[key].$gt,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (query[key].$lt > 0) {\n\t\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t\t(value) => getValueByKey(value, key) < query[key].$lt,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t(value) => getValueByKey(value, key) === query[key],\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\n\t\tif (sort && Object.keys(sort).length === 1) {\n\t\t\t// eslint-disable-next-line no-inner-declarations\n\t\t\tfunction compare(a, b): number {\n\t\t\t\t// Non null asserting here because of the length check above\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst sortKey = Object.keys(sort)[0]!;\n\t\t\t\treturn sort[sortKey] === 1\n\t\t\t\t\t? getValueByKey(a, sortKey) - getValueByKey(b, sortKey)\n\t\t\t\t\t: getValueByKey(b, sortKey) - getValueByKey(a, sortKey);\n\t\t\t}\n\n\t\t\tfilteredCollection = filteredCollection.sort(compare);\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn filteredCollection;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}\n\t */\n\tpublic async findAll(): Promise<any[]> {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn this.getAllInternal();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async findOne(query: any): Promise<any> {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn this.findOneInternal(query);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.update}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async update(query: any, set: any, addToSet: any): Promise<void> {\n\t\tconst value = this.findOneInternal(query);\n\t\tif (!value) {\n\t\t\tthrow new Error(\"Not found\");\n\t\t} else {\n\t\t\tfor (const key of Object.keys(set)) {\n\t\t\t\tvalue[key] = set[key];\n\t\t\t}\n\t\t\tthis.insertInternal(value);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async upsert(query: any, set: any, addToSet: any): Promise<void> {\n\t\tconst value = this.findOneInternal(query);\n\t\tif (!value) {\n\t\t\tthis.insertInternal(set);\n\t\t} else {\n\t\t\tfor (const key of Object.keys(set)) {\n\t\t\t\tvalue[key] = set[key];\n\t\t\t}\n\t\t\tthis.insertInternal(value);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}\n\t */\n\t/*\n\t * Value is expected to have a member \"_id\" which is a string used to search in the database.\n\t */\n\tpublic async insertOne(value: any): Promise<any> {\n\t\tconst presentVal = this.findOneInternal(value);\n\t\t// Only raise error when the object is present and the value is not equal.\n\t\tif (presentVal) {\n\t\t\tif (JSON.stringify(presentVal) === JSON.stringify(value)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow new Error(\"Existing Object!!\");\n\t\t}\n\n\t\treturn this.insertInternal(value);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}\n\t */\n\t/*\n\t * Value and query are expected to have a member \"_id\" which is a string used to search or insert in the database.\n\t */\n\tpublic async findOrCreate(\n\t\tquery: any,\n\t\tvalue: any,\n\t): Promise<{ value: any; existing: boolean }> {\n\t\tconst existing = this.findOneInternal(query);\n\t\tif (existing) {\n\t\t\treturn { value: existing, existing: true };\n\t\t}\n\t\tthis.insertInternal(value);\n\t\treturn { value, existing: false };\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}\n\t */\n\t/*\n\t * Each element in values is expected to have a member \"_id\" which is a string used to insert in the database.\n\t */\n\tpublic async insertMany(values: any[], ordered: boolean): Promise<void> {\n\t\tthis.insertInternal(...values);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteOne}\n\t */\n\tpublic async deleteOne(query: any): Promise<any> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteMany}\n\t */\n\tpublic async deleteMany(query: any): Promise<any> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.createIndex}\n\t */\n\tpublic async createIndex(index: any, unique: boolean): Promise<void> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * Return all values in the database\n\t */\n\tprivate getAllInternal(): any[] {\n\t\tconst values: string[] = [];\n\t\tfor (let i = 0; i < sessionStorage.length; i++) {\n\t\t\tconst key = sessionStorage.key(i);\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (key!.startsWith(this.collectionName)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tvalues.push(JSON.parse(sessionStorage.getItem(key!)!));\n\t\t\t}\n\t\t}\n\t\treturn values;\n\t}\n\n\t/**\n\t * Inserts values into the session storge.\n\t * Values are expected to have a member \"_id\" which is a unique id, otherwise will be assigned one\n\t *\n\t * @param values - data to insert to the database\n\t */\n\tprivate insertInternal(...values: any[]): void {\n\t\tfor (const value of values) {\n\t\t\tif (value) {\n\t\t\t\tif (!value._id) {\n\t\t\t\t\tvalue._id = uuid();\n\t\t\t\t}\n\t\t\t\tsessionStorage.setItem(`${this.collectionName}-${value._id}`, JSON.stringify(value));\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Finds the query in session storage and returns its value.\n\t * Returns null if query is not found.\n\t * Query is expected to have a member \"_id\" which is a unique id.\n\t *\n\t * @param query - what to find in the database\n\t */\n\tprivate findOneInternal(query: any): any {\n\t\tif (query._id) {\n\t\t\tconst json = sessionStorage.getItem(`${this.collectionName}-${query._id}`);\n\t\t\tif (json) {\n\t\t\t\treturn JSON.parse(json);\n\t\t\t}\n\t\t} else {\n\t\t\tconst queryKeys = Object.keys(query);\n\t\t\tfor (let i = 0; i < sessionStorage.length; i++) {\n\t\t\t\tconst ssKey = sessionStorage.key(i);\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tif (!ssKey!.startsWith(this.collectionName)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst value = JSON.parse(sessionStorage.getItem(ssKey!)!);\n\t\t\t\tlet foundMismatch = false;\n\t\t\t\tfor (const qk of queryKeys) {\n\t\t\t\t\tif (value[qk] !== query[qk]) {\n\t\t\t\t\t\tfoundMismatch = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!foundMismatch) {\n\t\t\t\t\treturn value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n}\n\n/**\n * A database for testing that stores data in the browsers session storage\n */\nclass LocalSessionStorageDb extends EventEmitter implements IDb {\n\tprivate readonly collections = new Map<string, LocalSessionStorageCollection<any>>();\n\tpublic async close(): Promise<void> {}\n\tpublic collection<T>(name: string): ICollection<T> {\n\t\tif (!this.collections.has(name)) {\n\t\t\tthis.collections.set(name, new LocalSessionStorageCollection<T>(name));\n\t\t}\n\t\treturn this.collections.get(name) as LocalSessionStorageCollection<T>;\n\t}\n\n\tpublic async dropCollection(name: string): Promise<boolean> {\n\t\tif (!this.collections.has(name)) {\n\t\t\treturn true;\n\t\t}\n\t\tthis.collections.delete(name);\n\t\treturn true;\n\t}\n}\n\n/**\n * A database factory for testing that stores data in the browsers session storage\n * @internal\n */\nexport class LocalSessionStorageDbFactory implements ITestDbFactory {\n\tpublic readonly testDatabase: IDb = new LocalSessionStorageDb();\n\tpublic async connect(): Promise<IDb> {\n\t\treturn this.testDatabase;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"localSessionStorageDb.js","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAG5D,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC;;;GAGG;AACH,MAAM,6BAA6B;IAClC;;OAEG;IACH,YAA6B,cAAsB;QAAtB,mBAAc,GAAd,cAAc,CAAQ;IAAG,CAAC;IAEhD,SAAS,CAAC,QAAa,EAAE,OAAa;QAC5C,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC3C,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,MAAW,EAAE,GAAQ,EAAE,QAAa;QAC3D,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC3C,CAAC;IACM,KAAK,CAAC,QAAQ,CAAC,GAAQ,EAAE,KAAU;QACzC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC3C,CAAC;IACM,KAAK,CAAC,aAAa,CAAC,KAAU,EAAE,KAAQ;QAC9C,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IAED;;OAEG;IACH;;;OAGG;IACI,KAAK,CAAC,IAAI,CAAC,KAAU,EAAE,IAAS;QACtC,iDAAiD;QACjD,SAAS,aAAa,CAAC,WAAW,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AA4B;IAAzC;QACiB,iBAAY,GAAQ,IAAI,qBAAqB,EAAE,CAAC;IAIjE,CAAC;IAHO,KAAK,CAAC,OAAO;QACnB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"@fluid-internal/client-utils\";\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\t/**\n\t * @param collectionName - data type of the collection, e.g. blobs, deltas, trees, etc.\n\t */\n\tconstructor(private readonly collectionName: string) {}\n\n\tpublic aggregate(pipeline: any, options?: any): any {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\n\tpublic async updateMany(filter: any, set: any, addToSet: any): Promise<void> {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\tpublic async distinct(key: any, query: any): Promise<any> {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\tpublic async findAndUpdate(query: any, value: T): Promise<{ value: T; existing: boolean }> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.find}\n\t */\n\t/*\n\t * Each query key consists of several keys separated by '.' e.g: \"operation.sequenceNumber\".\n\t * The hierarchical syntax allows finding nested key patterns.\n\t */\n\tpublic async find(query: any, sort: any): Promise<any[]> {\n\t\t// split the keys and get the corresponding value\n\t\tfunction getValueByKey(propertyBag, key: string): any {\n\t\t\tconst keys = key.split(\".\");\n\t\t\tlet value = propertyBag;\n\t\t\tkeys.forEach((splitKey) => {\n\t\t\t\tvalue = value[splitKey];\n\t\t\t});\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\t\treturn value;\n\t\t}\n\n\t\t// getting keys of the query we are trying to find\n\t\tconst queryKeys = Object.keys(query);\n\t\tlet filteredCollection = this.getAllInternal();\n\t\tqueryKeys.forEach((key) => {\n\t\t\tif (!query[key]) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (query[key].$gt > 0 || query[key].$lt > 0) {\n\t\t\t\tif (query[key].$gt > 0) {\n\t\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t\t(value) => getValueByKey(value, key) > query[key].$gt,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (query[key].$lt > 0) {\n\t\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t\t(value) => getValueByKey(value, key) < query[key].$lt,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t(value) => getValueByKey(value, key) === query[key],\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\n\t\tif (sort && Object.keys(sort).length === 1) {\n\t\t\t// eslint-disable-next-line no-inner-declarations\n\t\t\tfunction compare(a, b): number {\n\t\t\t\t// Non null asserting here because of the length check above\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst sortKey = Object.keys(sort)[0]!;\n\t\t\t\treturn sort[sortKey] === 1\n\t\t\t\t\t? getValueByKey(a, sortKey) - getValueByKey(b, sortKey)\n\t\t\t\t\t: getValueByKey(b, sortKey) - getValueByKey(a, sortKey);\n\t\t\t}\n\n\t\t\tfilteredCollection = filteredCollection.sort(compare);\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn filteredCollection;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}\n\t */\n\tpublic async findAll(): Promise<any[]> {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn this.getAllInternal();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async findOne(query: any): Promise<any> {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn this.findOneInternal(query);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.update}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async update(query: any, set: any, addToSet: any): Promise<void> {\n\t\tconst value = this.findOneInternal(query);\n\t\tif (!value) {\n\t\t\tthrow new Error(\"Not found\");\n\t\t} else {\n\t\t\tfor (const key of Object.keys(set)) {\n\t\t\t\tvalue[key] = set[key];\n\t\t\t}\n\t\t\tthis.insertInternal(value);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async upsert(query: any, set: any, addToSet: any): Promise<void> {\n\t\tconst value = this.findOneInternal(query);\n\t\tif (!value) {\n\t\t\tthis.insertInternal(set);\n\t\t} else {\n\t\t\tfor (const key of Object.keys(set)) {\n\t\t\t\tvalue[key] = set[key];\n\t\t\t}\n\t\t\tthis.insertInternal(value);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}\n\t */\n\t/*\n\t * Value is expected to have a member \"_id\" which is a string used to search in the database.\n\t */\n\tpublic async insertOne(value: any): Promise<any> {\n\t\tconst presentVal = this.findOneInternal(value);\n\t\t// Only raise error when the object is present and the value is not equal.\n\t\tif (presentVal) {\n\t\t\tif (JSON.stringify(presentVal) === JSON.stringify(value)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow new Error(\"Existing Object!!\");\n\t\t}\n\n\t\treturn this.insertInternal(value);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}\n\t */\n\t/*\n\t * Value and query are expected to have a member \"_id\" which is a string used to search or insert in the database.\n\t */\n\tpublic async findOrCreate(\n\t\tquery: any,\n\t\tvalue: any,\n\t): Promise<{ value: any; existing: boolean }> {\n\t\tconst existing = this.findOneInternal(query);\n\t\tif (existing) {\n\t\t\treturn { value: existing, existing: true };\n\t\t}\n\t\tthis.insertInternal(value);\n\t\treturn { value, existing: false };\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}\n\t */\n\t/*\n\t * Each element in values is expected to have a member \"_id\" which is a string used to insert in the database.\n\t */\n\tpublic async insertMany(values: any[], ordered: boolean): Promise<void> {\n\t\tthis.insertInternal(...values);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteOne}\n\t */\n\tpublic async deleteOne(query: any): Promise<any> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteMany}\n\t */\n\tpublic async deleteMany(query: any): Promise<any> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.createIndex}\n\t */\n\tpublic async createIndex(index: any, unique: boolean): Promise<void> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * Return all values in the database\n\t */\n\tprivate getAllInternal(): any[] {\n\t\tconst values: string[] = [];\n\t\tfor (let i = 0; i < sessionStorage.length; i++) {\n\t\t\tconst key = sessionStorage.key(i);\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (key!.startsWith(this.collectionName)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tvalues.push(JSON.parse(sessionStorage.getItem(key!)!));\n\t\t\t}\n\t\t}\n\t\treturn values;\n\t}\n\n\t/**\n\t * Inserts values into the session storge.\n\t * Values are expected to have a member \"_id\" which is a unique id, otherwise will be assigned one\n\t *\n\t * @param values - data to insert to the database\n\t */\n\tprivate insertInternal(...values: any[]): void {\n\t\tfor (const value of values) {\n\t\t\tif (value) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy\n\t\t\t\tif (!value._id) {\n\t\t\t\t\tvalue._id = uuid();\n\t\t\t\t}\n\t\t\t\tsessionStorage.setItem(`${this.collectionName}-${value._id}`, JSON.stringify(value));\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Finds the query in session storage and returns its value.\n\t * Returns null if query is not found.\n\t * Query is expected to have a member \"_id\" which is a unique id.\n\t *\n\t * @param query - what to find in the database\n\t */\n\tprivate findOneInternal(query: any): any {\n\t\tif (query._id) {\n\t\t\tconst json = sessionStorage.getItem(`${this.collectionName}-${query._id}`);\n\t\t\tif (json) {\n\t\t\t\treturn JSON.parse(json);\n\t\t\t}\n\t\t} else {\n\t\t\tconst queryKeys = Object.keys(query);\n\t\t\tfor (let i = 0; i < sessionStorage.length; i++) {\n\t\t\t\tconst ssKey = sessionStorage.key(i);\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tif (!ssKey!.startsWith(this.collectionName)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst value = JSON.parse(sessionStorage.getItem(ssKey!)!);\n\t\t\t\tlet foundMismatch = false;\n\t\t\t\tfor (const qk of queryKeys) {\n\t\t\t\t\tif (value[qk] !== query[qk]) {\n\t\t\t\t\t\tfoundMismatch = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!foundMismatch) {\n\t\t\t\t\treturn value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n}\n\n/**\n * A database for testing that stores data in the browsers session storage\n */\nclass LocalSessionStorageDb extends EventEmitter implements IDb {\n\tprivate readonly collections = new Map<string, LocalSessionStorageCollection<any>>();\n\tpublic async close(): Promise<void> {}\n\tpublic collection<T>(name: string): ICollection<T> {\n\t\tif (!this.collections.has(name)) {\n\t\t\tthis.collections.set(name, new LocalSessionStorageCollection<T>(name));\n\t\t}\n\t\treturn this.collections.get(name) as LocalSessionStorageCollection<T>;\n\t}\n\n\tpublic async dropCollection(name: string): Promise<boolean> {\n\t\tif (!this.collections.has(name)) {\n\t\t\treturn true;\n\t\t}\n\t\tthis.collections.delete(name);\n\t\treturn true;\n\t}\n}\n\n/**\n * A database factory for testing that stores data in the browsers session storage\n * @internal\n */\nexport class LocalSessionStorageDbFactory implements ITestDbFactory {\n\tpublic readonly testDatabase: IDb = new LocalSessionStorageDb();\n\tpublic async connect(): Promise<IDb> {\n\t\treturn this.testDatabase;\n\t}\n}\n"]}
|
package/lib/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 = "2.
|
|
8
|
+
export declare const pkgVersion = "2.81.0-374083";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,iCAAiC,CAAC;AACtD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,iCAAiC,CAAC;AACtD,eAAO,MAAM,UAAU,kBAAkB,CAAC"}
|
package/lib/packageVersion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,8BAA8B,CAAC;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,8BAA8B,CAAC;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,eAAe,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 = \"2.81.0-374083\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/local-driver",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.81.0-374083",
|
|
4
4
|
"description": "Fluid local driver",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -71,31 +71,31 @@
|
|
|
71
71
|
"temp-directory": "nyc/.nyc_output"
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@fluid-internal/client-utils": "
|
|
75
|
-
"@fluidframework/core-interfaces": "
|
|
76
|
-
"@fluidframework/core-utils": "
|
|
77
|
-
"@fluidframework/driver-base": "
|
|
78
|
-
"@fluidframework/driver-definitions": "
|
|
79
|
-
"@fluidframework/driver-utils": "
|
|
74
|
+
"@fluid-internal/client-utils": "2.81.0-374083",
|
|
75
|
+
"@fluidframework/core-interfaces": "2.81.0-374083",
|
|
76
|
+
"@fluidframework/core-utils": "2.81.0-374083",
|
|
77
|
+
"@fluidframework/driver-base": "2.81.0-374083",
|
|
78
|
+
"@fluidframework/driver-definitions": "2.81.0-374083",
|
|
79
|
+
"@fluidframework/driver-utils": "2.81.0-374083",
|
|
80
80
|
"@fluidframework/protocol-base": "^7.0.0",
|
|
81
|
-
"@fluidframework/routerlicious-driver": "
|
|
81
|
+
"@fluidframework/routerlicious-driver": "2.81.0-374083",
|
|
82
82
|
"@fluidframework/server-local-server": "^7.0.0",
|
|
83
83
|
"@fluidframework/server-services-client": "^7.0.0",
|
|
84
84
|
"@fluidframework/server-services-core": "^7.0.0",
|
|
85
85
|
"@fluidframework/server-test-utils": "^7.0.0",
|
|
86
|
-
"@fluidframework/telemetry-utils": "
|
|
86
|
+
"@fluidframework/telemetry-utils": "2.81.0-374083",
|
|
87
87
|
"jsrsasign": "^11.0.0",
|
|
88
88
|
"uuid": "^11.1.0"
|
|
89
89
|
},
|
|
90
90
|
"devDependencies": {
|
|
91
91
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
92
92
|
"@biomejs/biome": "~1.9.3",
|
|
93
|
-
"@fluid-internal/mocha-test-setup": "
|
|
94
|
-
"@fluid-tools/build-cli": "^0.
|
|
93
|
+
"@fluid-internal/mocha-test-setup": "2.81.0-374083",
|
|
94
|
+
"@fluid-tools/build-cli": "^0.63.0",
|
|
95
95
|
"@fluidframework/build-common": "^2.0.3",
|
|
96
|
-
"@fluidframework/build-tools": "^0.
|
|
97
|
-
"@fluidframework/eslint-config-fluid": "
|
|
98
|
-
"@fluidframework/local-driver-previous": "npm:@fluidframework/local-driver@2.
|
|
96
|
+
"@fluidframework/build-tools": "^0.63.0",
|
|
97
|
+
"@fluidframework/eslint-config-fluid": "2.81.0-374083",
|
|
98
|
+
"@fluidframework/local-driver-previous": "npm:@fluidframework/local-driver@2.80.0",
|
|
99
99
|
"@microsoft/api-extractor": "7.52.11",
|
|
100
100
|
"@types/jsrsasign": "^10.5.12",
|
|
101
101
|
"@types/mocha": "^10.0.10",
|
package/src/auth.ts
CHANGED
|
@@ -21,6 +21,7 @@ export function generateToken(
|
|
|
21
21
|
lifetime: number = 60 * 60,
|
|
22
22
|
ver: string = "1.0",
|
|
23
23
|
): string {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ?? could change behavior for falsy values
|
|
24
25
|
let userClaim = user ? user : generateUser();
|
|
25
26
|
if (userClaim.id === "" || userClaim.id === undefined) {
|
|
26
27
|
userClaim = generateUser();
|
|
@@ -57,6 +57,7 @@ export class LocalDocumentStorageService implements IDocumentStorageService {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
public async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ?? could change behavior for falsy values
|
|
60
61
|
const id = versionId ? versionId : this.id;
|
|
61
62
|
const commits = await this.manager.getCommits(id, count);
|
|
62
63
|
return commits.map((commit) => ({
|
|
@@ -241,6 +241,7 @@ class LocalSessionStorageCollection<T> implements ICollection<T> {
|
|
|
241
241
|
private insertInternal(...values: any[]): void {
|
|
242
242
|
for (const value of values) {
|
|
243
243
|
if (value) {
|
|
244
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy
|
|
244
245
|
if (!value._id) {
|
|
245
246
|
value._id = uuid();
|
|
246
247
|
}
|
package/src/packageVersion.ts
CHANGED
package/.eslintrc.cjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
module.exports = {
|
|
7
|
-
extends: [
|
|
8
|
-
require.resolve("@fluidframework/eslint-config-fluid/minimal-deprecated"),
|
|
9
|
-
"prettier",
|
|
10
|
-
],
|
|
11
|
-
parserOptions: {
|
|
12
|
-
project: ["./tsconfig.json", "./src/test/tsconfig.json"],
|
|
13
|
-
},
|
|
14
|
-
rules: {
|
|
15
|
-
"@typescript-eslint/strict-boolean-expressions": "off",
|
|
16
|
-
},
|
|
17
|
-
overrides: [
|
|
18
|
-
{
|
|
19
|
-
// Rules only for test files
|
|
20
|
-
files: ["*.spec.ts", "src/test/**"],
|
|
21
|
-
rules: {
|
|
22
|
-
// Test files are run in node only so additional node libraries can be used.
|
|
23
|
-
"import-x/no-nodejs-modules": ["error", { allow: ["assert"] }],
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
};
|