@fluidframework/container-loader 2.0.0-dev-rc.1.0.0.225277 → 2.0.0-dev-rc.1.0.0.232845
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/CHANGELOG.md +34 -0
- package/README.md +3 -9
- package/api-report/container-loader.api.md +1 -1
- package/dist/attachment.d.ts +116 -0
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +82 -0
- package/dist/attachment.js.map +1 -0
- package/dist/{audience.cjs → audience.js} +1 -1
- package/dist/audience.js.map +1 -0
- package/dist/{catchUpMonitor.cjs → catchUpMonitor.js} +1 -1
- package/dist/catchUpMonitor.js.map +1 -0
- package/dist/connectionManager.d.ts.map +1 -1
- package/dist/{connectionManager.cjs → connectionManager.js} +6 -7
- package/dist/connectionManager.js.map +1 -0
- package/dist/connectionState.d.ts +1 -1
- package/dist/{connectionState.cjs → connectionState.js} +2 -2
- package/dist/{connectionState.cjs.map → connectionState.js.map} +1 -1
- package/dist/{connectionStateHandler.cjs → connectionStateHandler.js} +3 -3
- package/dist/connectionStateHandler.js.map +1 -0
- package/dist/container-loader-alpha.d.ts +2 -2
- package/dist/container-loader-beta.d.ts +24 -1
- package/dist/container-loader-public.d.ts +24 -1
- package/dist/container-loader-untrimmed.d.ts +2 -2
- package/dist/container.d.ts +21 -8
- package/dist/container.d.ts.map +1 -1
- package/dist/{container.cjs → container.js} +192 -164
- package/dist/container.js.map +1 -0
- package/dist/containerContext.d.ts +3 -2
- package/dist/containerContext.d.ts.map +1 -1
- package/dist/{containerContext.cjs → containerContext.js} +3 -2
- package/dist/containerContext.js.map +1 -0
- package/dist/containerStorageAdapter.d.ts +3 -3
- package/dist/containerStorageAdapter.d.ts.map +1 -1
- package/dist/{containerStorageAdapter.cjs → containerStorageAdapter.js} +13 -14
- package/dist/containerStorageAdapter.js.map +1 -0
- package/dist/{contracts.cjs → contracts.js} +1 -1
- package/dist/contracts.js.map +1 -0
- package/dist/{debugLogger.cjs → debugLogger.js} +1 -1
- package/dist/debugLogger.js.map +1 -0
- package/dist/{deltaManager.cjs → deltaManager.js} +3 -3
- package/dist/deltaManager.js.map +1 -0
- package/dist/{deltaQueue.cjs → deltaQueue.js} +1 -1
- package/dist/deltaQueue.js.map +1 -0
- package/dist/{disposal.cjs → disposal.js} +1 -1
- package/dist/disposal.js.map +1 -0
- package/dist/{error.cjs → error.js} +1 -1
- package/dist/error.js.map +1 -0
- package/dist/{index.cjs → index.js} +6 -6
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +1 -1
- package/dist/{loader.cjs → loader.js} +5 -5
- package/dist/{loader.cjs.map → loader.js.map} +1 -1
- package/dist/location-redirection-utilities/{index.cjs → index.js} +2 -2
- package/dist/location-redirection-utilities/index.js.map +1 -0
- package/dist/location-redirection-utilities/{resolveWithLocationRedirection.cjs → resolveWithLocationRedirection.js} +1 -1
- package/dist/location-redirection-utilities/resolveWithLocationRedirection.js.map +1 -0
- package/dist/{noopHeuristic.cjs → noopHeuristic.js} +1 -1
- package/dist/noopHeuristic.js.map +1 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/{packageVersion.cjs → packageVersion.js} +2 -2
- package/dist/packageVersion.js.map +1 -0
- package/dist/{protocol.cjs → protocol.js} +1 -1
- package/dist/protocol.js.map +1 -0
- package/dist/protocolTreeDocumentStorageService.d.ts +1 -0
- package/dist/protocolTreeDocumentStorageService.d.ts.map +1 -1
- package/dist/{protocolTreeDocumentStorageService.cjs → protocolTreeDocumentStorageService.js} +2 -1
- package/dist/protocolTreeDocumentStorageService.js.map +1 -0
- package/dist/{quorum.cjs → quorum.js} +1 -1
- package/dist/quorum.js.map +1 -0
- package/dist/retriableDocumentStorageService.d.ts +2 -1
- package/dist/retriableDocumentStorageService.d.ts.map +1 -1
- package/dist/{retriableDocumentStorageService.cjs → retriableDocumentStorageService.js} +9 -1
- package/dist/retriableDocumentStorageService.js.map +1 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/utils.d.ts +13 -7
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +211 -0
- package/dist/utils.js.map +1 -0
- package/lib/attachment.d.mts +112 -0
- package/lib/attachment.d.mts.map +1 -0
- package/lib/attachment.mjs +74 -0
- package/lib/attachment.mjs.map +1 -0
- package/lib/connectionManager.d.mts.map +1 -1
- package/lib/connectionManager.mjs +2 -5
- package/lib/connectionManager.mjs.map +1 -1
- package/lib/connectionState.d.mts +1 -1
- package/lib/connectionState.mjs +1 -1
- package/lib/connectionState.mjs.map +1 -1
- package/lib/container-loader-alpha.d.mts +2 -2
- package/lib/container-loader-beta.d.mts +24 -1
- package/lib/container-loader-public.d.mts +24 -1
- package/lib/container-loader-untrimmed.d.mts +2 -2
- package/lib/container.d.mts +21 -8
- package/lib/container.d.mts.map +1 -1
- package/lib/container.mjs +176 -151
- package/lib/container.mjs.map +1 -1
- package/lib/containerContext.d.mts +3 -2
- package/lib/containerContext.d.mts.map +1 -1
- package/lib/containerContext.mjs +2 -1
- package/lib/containerContext.mjs.map +1 -1
- package/lib/containerStorageAdapter.d.mts +3 -3
- package/lib/containerStorageAdapter.d.mts.map +1 -1
- package/lib/containerStorageAdapter.mjs +10 -11
- package/lib/containerStorageAdapter.mjs.map +1 -1
- package/lib/loader.d.mts +1 -1
- package/lib/loader.mjs.map +1 -1
- package/lib/packageVersion.d.mts +1 -1
- package/lib/packageVersion.mjs +1 -1
- package/lib/packageVersion.mjs.map +1 -1
- package/lib/protocolTreeDocumentStorageService.d.mts +1 -0
- package/lib/protocolTreeDocumentStorageService.d.mts.map +1 -1
- package/lib/protocolTreeDocumentStorageService.mjs +1 -0
- package/lib/protocolTreeDocumentStorageService.mjs.map +1 -1
- package/lib/retriableDocumentStorageService.d.mts +2 -1
- package/lib/retriableDocumentStorageService.d.mts.map +1 -1
- package/lib/retriableDocumentStorageService.mjs +9 -1
- package/lib/retriableDocumentStorageService.mjs.map +1 -1
- package/lib/utils.d.mts +13 -7
- package/lib/utils.d.mts.map +1 -1
- package/lib/utils.mjs +96 -29
- package/lib/utils.mjs.map +1 -1
- package/package.json +36 -30
- package/src/attachment.ts +219 -0
- package/src/connectionManager.ts +2 -4
- package/src/connectionState.ts +1 -1
- package/src/container.ts +260 -191
- package/src/containerContext.ts +2 -1
- package/src/containerStorageAdapter.ts +15 -12
- package/src/loader.ts +1 -1
- package/src/packageVersion.ts +1 -1
- package/src/protocolTreeDocumentStorageService.ts +1 -0
- package/src/retriableDocumentStorageService.ts +18 -1
- package/src/utils.ts +128 -36
- package/dist/audience.cjs.map +0 -1
- package/dist/catchUpMonitor.cjs.map +0 -1
- package/dist/connectionManager.cjs.map +0 -1
- package/dist/connectionStateHandler.cjs.map +0 -1
- package/dist/container.cjs.map +0 -1
- package/dist/containerContext.cjs.map +0 -1
- package/dist/containerStorageAdapter.cjs.map +0 -1
- package/dist/contracts.cjs.map +0 -1
- package/dist/debugLogger.cjs.map +0 -1
- package/dist/deltaManager.cjs.map +0 -1
- package/dist/deltaQueue.cjs.map +0 -1
- package/dist/disposal.cjs.map +0 -1
- package/dist/error.cjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/location-redirection-utilities/index.cjs.map +0 -1
- package/dist/location-redirection-utilities/resolveWithLocationRedirection.cjs.map +0 -1
- package/dist/noopHeuristic.cjs.map +0 -1
- package/dist/packageVersion.cjs.map +0 -1
- package/dist/protocol.cjs.map +0 -1
- package/dist/protocolTreeDocumentStorageService.cjs.map +0 -1
- package/dist/quorum.cjs.map +0 -1
- package/dist/retriableDocumentStorageService.cjs.map +0 -1
- package/dist/utils.cjs +0 -142
- package/dist/utils.cjs.map +0 -1
- package/tsc-multi.test.json +0 -4
- /package/{.eslintrc.js → .eslintrc.cjs} +0 -0
package/dist/{protocolTreeDocumentStorageService.cjs → protocolTreeDocumentStorageService.js}
RENAMED
|
@@ -14,6 +14,7 @@ class ProtocolTreeStorageService {
|
|
|
14
14
|
this.internalStorageService = internalStorageService;
|
|
15
15
|
this.addProtocolSummaryIfMissing = addProtocolSummaryIfMissing;
|
|
16
16
|
this.getSnapshotTree = this.internalStorageService.getSnapshotTree.bind(this.internalStorageService);
|
|
17
|
+
this.getSnapshot = this.internalStorageService.getSnapshot?.bind(this.internalStorageService);
|
|
17
18
|
this.getVersions = this.internalStorageService.getVersions.bind(this.internalStorageService);
|
|
18
19
|
this.createBlob = this.internalStorageService.createBlob.bind(this.internalStorageService);
|
|
19
20
|
this.readBlob = this.internalStorageService.readBlob.bind(this.internalStorageService);
|
|
@@ -34,4 +35,4 @@ class ProtocolTreeStorageService {
|
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
exports.ProtocolTreeStorageService = ProtocolTreeStorageService;
|
|
37
|
-
//# sourceMappingURL=protocolTreeDocumentStorageService.
|
|
38
|
+
//# sourceMappingURL=protocolTreeDocumentStorageService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocolTreeDocumentStorageService.js","sourceRoot":"","sources":["../src/protocolTreeDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAMH;;;GAGG;AACH,MAAa,0BAA0B;IACtC,YACkB,sBAA6D,EAC7D,2BAAwE;QADxE,2BAAsB,GAAtB,sBAAsB,CAAuC;QAC7D,gCAA2B,GAA3B,2BAA2B,CAA6C;QAY1F,oBAAe,GAAG,IAAI,CAAC,sBAAsB,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QAChG,gBAAW,GAAG,IAAI,CAAC,sBAAsB,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACzF,gBAAW,GAAG,IAAI,CAAC,sBAAsB,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACxF,eAAU,GAAG,IAAI,CAAC,sBAAsB,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACtF,aAAQ,GAAG,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QAClF,oBAAe,GAAG,IAAI,CAAC,sBAAsB,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QAChG,YAAO,GAAG,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IAjB7E,CAAC;IACJ,IAAW,QAAQ;QAClB,OAAO,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC;IAC7C,CAAC;IACD,IAAW,aAAa;QACvB,OAAO,IAAI,CAAC,sBAAsB,CAAC,aAAa,CAAC;IAClD,CAAC;IACD,IAAW,QAAQ;QAClB,OAAO,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC;IAC7C,CAAC;IAUD,KAAK,CAAC,wBAAwB,CAC7B,OAAqB,EACrB,OAAwB;QAExB,OAAO,IAAI,CAAC,sBAAsB,CAAC,wBAAwB,CAC1D,IAAI,CAAC,2BAA2B,CAAC,OAAO,CAAC,EACzC,OAAO,CACP,CAAC;IACH,CAAC;CACD;AAhCD,gEAgCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDisposable } from \"@fluidframework/core-interfaces\";\nimport { IDocumentStorageService, ISummaryContext } from \"@fluidframework/driver-definitions\";\nimport { ISummaryTree } from \"@fluidframework/protocol-definitions\";\n\n/**\n * A storage service wrapper whose sole job is to intercept calls to uploadSummaryWithContext and ensure they include\n * the protocol summary, using the provided callback to add it if necessary.\n */\nexport class ProtocolTreeStorageService implements IDocumentStorageService, IDisposable {\n\tconstructor(\n\t\tprivate readonly internalStorageService: IDocumentStorageService & IDisposable,\n\t\tprivate readonly addProtocolSummaryIfMissing: (summaryTree: ISummaryTree) => ISummaryTree,\n\t) {}\n\tpublic get policies() {\n\t\treturn this.internalStorageService.policies;\n\t}\n\tpublic get repositoryUrl() {\n\t\treturn this.internalStorageService.repositoryUrl;\n\t}\n\tpublic get disposed() {\n\t\treturn this.internalStorageService.disposed;\n\t}\n\n\tgetSnapshotTree = this.internalStorageService.getSnapshotTree.bind(this.internalStorageService);\n\tgetSnapshot = this.internalStorageService.getSnapshot?.bind(this.internalStorageService);\n\tgetVersions = this.internalStorageService.getVersions.bind(this.internalStorageService);\n\tcreateBlob = this.internalStorageService.createBlob.bind(this.internalStorageService);\n\treadBlob = this.internalStorageService.readBlob.bind(this.internalStorageService);\n\tdownloadSummary = this.internalStorageService.downloadSummary.bind(this.internalStorageService);\n\tdispose = this.internalStorageService.dispose.bind(this.internalStorageService);\n\n\tasync uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\treturn this.internalStorageService.uploadSummaryWithContext(\n\t\t\tthis.addProtocolSummaryIfMissing(summary),\n\t\t\tcontext,\n\t\t);\n\t}\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quorum.js","sourceRoot":"","sources":["../src/quorum.ts"],"names":[],"mappings":";;;AAOA,SAAgB,+BAA+B,CAC9C,MAAyB;IAEzB,kEAAkE;IAClE,MAAM,qBAAqB,GAAuB;QACjD,GAAG,EAAE,MAAM;QACX,KAAK,EAAE,MAAM;QACb,sBAAsB,EAAE,CAAC;QACzB,oBAAoB,EAAE,CAAC;QACvB,cAAc,EAAE,CAAC;KACjB,CAAC;IACF,OAAO,CAAC,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC;AAC1C,CAAC;AAZD,0EAYC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { IFluidCodeDetails } from \"@fluidframework/core-interfaces\";\nimport { ICommittedProposal } from \"@fluidframework/protocol-definitions\";\n\nexport function initQuorumValuesFromCodeDetails(\n\tsource: IFluidCodeDetails,\n): [string, ICommittedProposal][] {\n\t// Seed the base quorum to be an empty list with a code quorum set\n\tconst committedCodeProposal: ICommittedProposal = {\n\t\tkey: \"code\",\n\t\tvalue: source,\n\t\tapprovalSequenceNumber: 0,\n\t\tcommitSequenceNumber: 0,\n\t\tsequenceNumber: 0,\n\t};\n\treturn [[\"code\", committedCodeProposal]];\n}\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { FetchSource, IDocumentStorageService, IDocumentStorageServicePolicies, ISummaryContext } from "@fluidframework/driver-definitions";
|
|
5
|
+
import { FetchSource, IDocumentStorageService, IDocumentStorageServicePolicies, ISnapshot, ISnapshotFetchOptions, ISummaryContext } from "@fluidframework/driver-definitions";
|
|
6
6
|
import { ICreateBlobResponse, ISnapshotTree, ISummaryHandle, ISummaryTree, IVersion } from "@fluidframework/protocol-definitions";
|
|
7
7
|
import { IDisposable } from "@fluidframework/core-interfaces";
|
|
8
8
|
import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils";
|
|
@@ -17,6 +17,7 @@ export declare class RetriableDocumentStorageService implements IDocumentStorage
|
|
|
17
17
|
dispose(): void;
|
|
18
18
|
get repositoryUrl(): string;
|
|
19
19
|
getSnapshotTree(version?: IVersion, scenarioName?: string): Promise<ISnapshotTree | null>;
|
|
20
|
+
getSnapshot(snapshotFetchOptions?: ISnapshotFetchOptions): Promise<ISnapshot>;
|
|
20
21
|
readBlob(id: string): Promise<ArrayBufferLike>;
|
|
21
22
|
getVersions(versionId: string | null, count: number, scenarioName?: string, fetchSource?: FetchSource): Promise<IVersion[]>;
|
|
22
23
|
uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retriableDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/retriableDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,WAAW,EACX,uBAAuB,EACvB,+BAA+B,EAC/B,eAAe,EACf,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACN,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAgB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"retriableDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/retriableDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,WAAW,EACX,uBAAuB,EACvB,+BAA+B,EAC/B,SAAS,EACT,qBAAqB,EACrB,eAAe,EACf,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACN,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAgB,mBAAmB,EAAc,MAAM,iCAAiC,CAAC;AAGhG,qBAAa,+BAAgC,YAAW,uBAAuB,EAAE,WAAW;IAI1F,OAAO,CAAC,QAAQ,CAAC,uBAAuB;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJxB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,sBAAsB,CAAsC;gBAElD,uBAAuB,EAAE,OAAO,CAAC,uBAAuB,CAAC,EACzD,MAAM,EAAE,mBAAmB;IAK7C,IAAW,QAAQ,IAAI,+BAA+B,GAAG,SAAS,CAKjE;IACD,IAAW,QAAQ,YAElB;IACM,OAAO;IAId,IAAW,aAAa,IAAI,MAAM,CAKjC;IAEY,eAAe,CAC3B,OAAO,CAAC,EAAE,QAAQ,EAClB,YAAY,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAUnB,WAAW,CAAC,oBAAoB,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,SAAS,CAAC;IAe7E,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAO9C,WAAW,CACvB,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,KAAK,EAAE,MAAM,EACb,YAAY,CAAC,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,WAAW,GACvB,OAAO,CAAC,QAAQ,EAAE,CAAC;IAUT,wBAAwB,CACpC,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,eAAe,GACtB,OAAO,CAAC,MAAM,CAAC;IA8BL,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;IAO9D,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAO5E,OAAO,CAAC,oBAAoB;YAiBd,YAAY;CAM1B"}
|
|
@@ -36,6 +36,14 @@ class RetriableDocumentStorageService {
|
|
|
36
36
|
async getSnapshotTree(version, scenarioName) {
|
|
37
37
|
return this.runWithRetry(async () => this.internalStorageServiceP.then(async (s) => s.getSnapshotTree(version, scenarioName)), "storage_getSnapshotTree");
|
|
38
38
|
}
|
|
39
|
+
async getSnapshot(snapshotFetchOptions) {
|
|
40
|
+
return this.runWithRetry(async () => this.internalStorageServiceP.then(async (s) => {
|
|
41
|
+
if (s.getSnapshot !== undefined) {
|
|
42
|
+
return s.getSnapshot(snapshotFetchOptions);
|
|
43
|
+
}
|
|
44
|
+
throw new telemetry_utils_1.UsageError("getSnapshot api should exist on internal storage in RetriableDocStorageService class");
|
|
45
|
+
}), "storage_getSnapshot");
|
|
46
|
+
}
|
|
39
47
|
async readBlob(id) {
|
|
40
48
|
return this.runWithRetry(async () => this.internalStorageServiceP.then(async (s) => s.readBlob(id)), "storage_readBlob");
|
|
41
49
|
}
|
|
@@ -85,4 +93,4 @@ class RetriableDocumentStorageService {
|
|
|
85
93
|
}
|
|
86
94
|
}
|
|
87
95
|
exports.RetriableDocumentStorageService = RetriableDocumentStorageService;
|
|
88
|
-
//# sourceMappingURL=retriableDocumentStorageService.
|
|
96
|
+
//# sourceMappingURL=retriableDocumentStorageService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retriableDocumentStorageService.js","sourceRoot":"","sources":["../src/retriableDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2DAAoD;AAiBpD,qEAAgG;AAChG,+DAA4D;AAE5D,MAAa,+BAA+B;IAG3C,YACkB,uBAAyD,EACzD,MAA2B;QAD3B,4BAAuB,GAAvB,uBAAuB,CAAkC;QACzD,WAAM,GAAN,MAAM,CAAqB;QAJrC,cAAS,GAAG,KAAK,CAAC;QAMzB,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,sBAAsB,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC7F,CAAC;IAED,IAAW,QAAQ;QAClB,IAAI,IAAI,CAAC,sBAAsB,EAAE;YAChC,OAAO,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC;SAC5C;QACD,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACzD,CAAC;IACD,IAAW,QAAQ;QAClB,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IACM,OAAO;QACb,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,IAAW,aAAa;QACvB,IAAI,IAAI,CAAC,sBAAsB,EAAE;YAChC,OAAO,IAAI,CAAC,sBAAsB,CAAC,aAAa,CAAC;SACjD;QACD,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACzD,CAAC;IAEM,KAAK,CAAC,eAAe,CAC3B,OAAkB,EAClB,YAAq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AoB,CACpB,CAAC;IACH,CAAC;IAEO,oBAAoB,CAAC,QAAgB,EAAE,KAAc;QAC5D,IAAI,IAAI,CAAC,SAAS,EAAE;YACnB,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAC7B;gBACC,SAAS,EAAE,GAAG,QAAQ,yBAAyB;gBAC/C,aAAa,EAAE,QAAQ,EAAE,gDAAgD;aACzE,EACD,KAAK,CACL,CAAC;YACF,4DAA4D;YAC5D,MAAM,IAAI,8BAAY,CAAC,2CAA2C,EAAE;gBACnE,QAAQ,EAAE,KAAK;aACf,CAAC,CAAC;SACH;QACD,OAAO;IACR,CAAC;IAEO,KAAK,CAAC,YAAY,CAAI,GAAqB,EAAE,QAAgB;QACpE,OAAO,IAAA,2BAAY,EAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE;YAC/C,OAAO,EAAE,CAAC,UAAkB,EAAE,KAAc,EAAE,EAAE,CAC/C,IAAI,CAAC,oBAAoB,CAAC,QAAQ,EAAE,KAAK,CAAC;SAC3C,CAAC,CAAC;IACJ,CAAC;CACD;AAtJD,0EAsJC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport {\n\tFetchSource,\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n\tISnapshot,\n\tISnapshotFetchOptions,\n\tISummaryContext,\n} from \"@fluidframework/driver-definitions\";\nimport {\n\tICreateBlobResponse,\n\tISnapshotTree,\n\tISummaryHandle,\n\tISummaryTree,\n\tIVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport { IDisposable } from \"@fluidframework/core-interfaces\";\nimport { GenericError, ITelemetryLoggerExt, UsageError } from \"@fluidframework/telemetry-utils\";\nimport { runWithRetry } from \"@fluidframework/driver-utils\";\n\nexport class RetriableDocumentStorageService implements IDocumentStorageService, IDisposable {\n\tprivate _disposed = false;\n\tprivate internalStorageService: IDocumentStorageService | undefined;\n\tconstructor(\n\t\tprivate readonly internalStorageServiceP: Promise<IDocumentStorageService>,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t) {\n\t\tthis.internalStorageServiceP.then((s) => (this.internalStorageService = s)).catch(() => {});\n\t}\n\n\tpublic get policies(): IDocumentStorageServicePolicies | undefined {\n\t\tif (this.internalStorageService) {\n\t\t\treturn this.internalStorageService.policies;\n\t\t}\n\t\tthrow new Error(\"storage service not yet instantiated\");\n\t}\n\tpublic get disposed() {\n\t\treturn this._disposed;\n\t}\n\tpublic dispose() {\n\t\tthis._disposed = true;\n\t}\n\n\tpublic get repositoryUrl(): string {\n\t\tif (this.internalStorageService) {\n\t\t\treturn this.internalStorageService.repositoryUrl;\n\t\t}\n\t\tthrow new Error(\"storage service not yet instantiated\");\n\t}\n\n\tpublic async getSnapshotTree(\n\t\tversion?: IVersion,\n\t\tscenarioName?: string,\n\t): Promise<ISnapshotTree | null> {\n\t\treturn this.runWithRetry(\n\t\t\tasync () =>\n\t\t\t\tthis.internalStorageServiceP.then(async (s) =>\n\t\t\t\t\ts.getSnapshotTree(version, scenarioName),\n\t\t\t\t),\n\t\t\t\"storage_getSnapshotTree\",\n\t\t);\n\t}\n\n\tpublic async getSnapshot(snapshotFetchOptions?: ISnapshotFetchOptions): Promise<ISnapshot> {\n\t\treturn this.runWithRetry(\n\t\t\tasync () =>\n\t\t\t\tthis.internalStorageServiceP.then(async (s) => {\n\t\t\t\t\tif (s.getSnapshot !== undefined) {\n\t\t\t\t\t\treturn s.getSnapshot(snapshotFetchOptions);\n\t\t\t\t\t}\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\"getSnapshot api should exist on internal storage in RetriableDocStorageService class\",\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t\"storage_getSnapshot\",\n\t\t);\n\t}\n\n\tpublic async readBlob(id: string): Promise<ArrayBufferLike> {\n\t\treturn this.runWithRetry(\n\t\t\tasync () => this.internalStorageServiceP.then(async (s) => s.readBlob(id)),\n\t\t\t\"storage_readBlob\",\n\t\t);\n\t}\n\n\tpublic async getVersions(\n\t\tversionId: string | null,\n\t\tcount: number,\n\t\tscenarioName?: string,\n\t\tfetchSource?: FetchSource,\n\t): Promise<IVersion[]> {\n\t\treturn this.runWithRetry(\n\t\t\tasync () =>\n\t\t\t\tthis.internalStorageServiceP.then(async (s) =>\n\t\t\t\t\ts.getVersions(versionId, count, scenarioName, fetchSource),\n\t\t\t\t),\n\t\t\t\"storage_getVersions\",\n\t\t);\n\t}\n\n\tpublic async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\t// Not using retry loop here. Couple reasons:\n\t\t// 1. If client lost connectivity, then retry loop will result in uploading stale summary\n\t\t// by stale summarizer after connectivity comes back. It will cause failures for this client and for\n\t\t// real (new) summarizer. This problem in particular should be solved in future by supplying abort handle\n\t\t// on all APIs and caller (ContainerRuntime.submitSummary) aborting call on loss of connectivity\n\t\t// 2. Similar, if we get 429 with retryAfter = 10 minutes, it's likely not the right call to retry summary\n\t\t// upload in 10 minutes - it's better to keep processing ops and retry later. Though caller needs to take\n\t\t// retryAfter into account!\n\t\t// But retry loop is required for creation flow (Container.attach)\n\t\tassert(\n\t\t\t(context.referenceSequenceNumber === 0) === (context.ackHandle === undefined),\n\t\t\t0x251 /* \"creation summary has to have seq=0 && handle === undefined\" */,\n\t\t);\n\t\tif (context.referenceSequenceNumber !== 0) {\n\t\t\treturn this.internalStorageServiceP.then(async (s) =>\n\t\t\t\ts.uploadSummaryWithContext(summary, context),\n\t\t\t);\n\t\t}\n\n\t\t// Creation flow with attachment blobs - need to do retries!\n\t\treturn this.runWithRetry(\n\t\t\tasync () =>\n\t\t\t\tthis.internalStorageServiceP.then(async (s) =>\n\t\t\t\t\ts.uploadSummaryWithContext(summary, context),\n\t\t\t\t),\n\t\t\t\"storage_uploadSummaryWithContext\",\n\t\t);\n\t}\n\n\tpublic async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n\t\treturn this.runWithRetry(\n\t\t\tasync () => this.internalStorageServiceP.then(async (s) => s.downloadSummary(handle)),\n\t\t\t\"storage_downloadSummary\",\n\t\t);\n\t}\n\n\tpublic async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\treturn this.runWithRetry(\n\t\t\tasync () => this.internalStorageServiceP.then(async (s) => s.createBlob(file)),\n\t\t\t\"storage_createBlob\",\n\t\t);\n\t}\n\n\tprivate checkStorageDisposed(callName: string, error: unknown) {\n\t\tif (this._disposed) {\n\t\t\tthis.logger.sendTelemetryEvent(\n\t\t\t\t{\n\t\t\t\t\teventName: `${callName}_abortedStorageDisposed`,\n\t\t\t\t\tfetchCallName: callName, // fetchCallName matches logs in runWithRetry.ts\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t);\n\t\t\t// pre-0.58 error message: storageServiceDisposedCannotRetry\n\t\t\tthrow new GenericError(\"Storage Service is disposed. Cannot retry\", {\n\t\t\t\tcanRetry: false,\n\t\t\t});\n\t\t}\n\t\treturn;\n\t}\n\n\tprivate async runWithRetry<T>(api: () => Promise<T>, callName: string): Promise<T> {\n\t\treturn runWithRetry(api, callName, this.logger, {\n\t\t\tonRetry: (_delayInMs: number, error: unknown) =>\n\t\t\t\tthis.checkStorageDisposed(callName, error),\n\t\t});\n\t}\n}\n"]}
|
package/dist/tsdoc-metadata.json
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { ISummaryTree, ISnapshotTree } from "@fluidframework/protocol-definitions";
|
|
6
6
|
import { CombinedAppAndProtocolSummary, DeltaStreamConnectionForbiddenError } from "@fluidframework/driver-utils";
|
|
7
|
+
import { ISerializableBlobContents } from "./containerStorageAdapter";
|
|
8
|
+
import { IPendingDetachedContainerState } from "./container";
|
|
7
9
|
export interface ISnapshotTreeWithBlobContents extends ISnapshotTree {
|
|
8
10
|
blobsContents: {
|
|
9
11
|
[path: string]: ArrayBufferLike;
|
|
@@ -55,13 +57,17 @@ export declare function tryParseCompatibleResolvedUrl(url: string): IParsedUrl |
|
|
|
55
57
|
* @internal
|
|
56
58
|
*/
|
|
57
59
|
export declare function combineAppAndProtocolSummary(appSummary: ISummaryTree, protocolSummary: ISummaryTree): CombinedAppAndProtocolSummary;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*/
|
|
63
|
-
export declare function convertProtocolAndAppSummaryToSnapshotTree(protocolSummaryTree: ISummaryTree, appSummaryTree: ISummaryTree): ISnapshotTreeWithBlobContents;
|
|
64
|
-
export declare const getSnapshotTreeFromSerializedContainer: (detachedContainerSnapshot: ISummaryTree) => ISnapshotTreeWithBlobContents;
|
|
60
|
+
export declare const getSnapshotTreeAndBlobsFromSerializedContainer: (detachedContainerSnapshot: ISummaryTree) => {
|
|
61
|
+
tree: ISnapshotTree;
|
|
62
|
+
blobs: ISerializableBlobContents;
|
|
63
|
+
};
|
|
65
64
|
export declare function getProtocolSnapshotTree(snapshot: ISnapshotTree): ISnapshotTree;
|
|
65
|
+
export declare const combineSnapshotTreeAndSnapshotBlobs: (baseSnapshot: ISnapshotTree, snapshotBlobs: ISerializableBlobContents) => ISnapshotTreeWithBlobContents;
|
|
66
66
|
export declare function isDeltaStreamConnectionForbiddenError(error: any): error is DeltaStreamConnectionForbiddenError;
|
|
67
|
+
export declare function getDetachedContainerStateFromSerializedContainer(serializedContainer: string): IPendingDetachedContainerState;
|
|
68
|
+
/**
|
|
69
|
+
* Ensures only a single instance of the provided async function is running.
|
|
70
|
+
* If there are multiple calls they will all get the same promise to wait on.
|
|
71
|
+
*/
|
|
72
|
+
export declare const runSingle: <A extends any[], R>(func: (...args: A) => Promise<R>) => (...args: A) => Promise<R>;
|
|
67
73
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAe,MAAM,sCAAsC,CAAC;AAEhG,OAAO,EACN,6BAA6B,EAC7B,mCAAmC,EAEnC,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAe,MAAM,sCAAsC,CAAC;AAEhG,OAAO,EACN,6BAA6B,EAC7B,mCAAmC,EAEnC,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAI7D,MAAM,WAAW,6BAA8B,SAAQ,aAAa;IACnE,aAAa,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;KAAE,CAAC;IACnD,KAAK,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,6BAA6B,CAAA;KAAE,CAAC;CACzD;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IAC1B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACnC;AAED;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAWjF;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC3C,UAAU,EAAE,YAAY,EACxB,eAAe,EAAE,YAAY,GAC3B,6BAA6B,CAiB/B;AA0ED,eAAO,MAAM,8CAA8C,8BAC/B,YAAY,KACrC;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,yBAAyB,CAAA;CAYzD,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,aAAa,GAAG,aAAa,CAE9E;AAED,eAAO,MAAM,mCAAmC,iBACjC,aAAa,iBACZ,yBAAyB,KACtC,6BAwBF,CAAC;AAEF,wBAAgB,qCAAqC,CACpD,KAAK,EAAE,GAAG,GACR,KAAK,IAAI,mCAAmC,CAM9C;AAoBD,wBAAgB,gDAAgD,CAC/D,mBAAmB,EAAE,MAAM,GACzB,8BAA8B,CAkBhC;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,sFAsBrB,CAAC"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.runSingle = exports.getDetachedContainerStateFromSerializedContainer = exports.isDeltaStreamConnectionForbiddenError = exports.combineSnapshotTreeAndSnapshotBlobs = exports.getProtocolSnapshotTree = exports.getSnapshotTreeAndBlobsFromSerializedContainer = exports.combineAppAndProtocolSummary = exports.tryParseCompatibleResolvedUrl = void 0;
|
|
8
|
+
const url_1 = require("url");
|
|
9
|
+
const uuid_1 = require("uuid");
|
|
10
|
+
const client_utils_1 = require("@fluid-internal/client-utils");
|
|
11
|
+
const core_utils_1 = require("@fluidframework/core-utils");
|
|
12
|
+
const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
|
|
13
|
+
const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
|
|
14
|
+
const driver_utils_1 = require("@fluidframework/driver-utils");
|
|
15
|
+
const driver_definitions_1 = require("@fluidframework/driver-definitions");
|
|
16
|
+
/**
|
|
17
|
+
* Utility api to parse the IResolvedUrl.url into specific parts like querystring, path to get
|
|
18
|
+
* deep link info etc.
|
|
19
|
+
* Warning - This function may not be compatible with any Url Resolver's resolved url. It works
|
|
20
|
+
* with urls of type: protocol://<string>/.../..?<querystring>
|
|
21
|
+
* @param url - This is the IResolvedUrl.url part of the resolved url.
|
|
22
|
+
* @returns The IParsedUrl representing the input URL, or undefined if the format was not supported
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
function tryParseCompatibleResolvedUrl(url) {
|
|
26
|
+
const parsed = (0, url_1.parse)(url, true);
|
|
27
|
+
if (typeof parsed.pathname !== "string") {
|
|
28
|
+
throw new telemetry_utils_1.LoggingError("Failed to parse pathname");
|
|
29
|
+
}
|
|
30
|
+
const query = parsed.search ?? "";
|
|
31
|
+
const regex = /^\/([^/]*\/[^/]*)(\/?.*)$/;
|
|
32
|
+
const match = regex.exec(parsed.pathname);
|
|
33
|
+
return match?.length === 3
|
|
34
|
+
? { id: match[1], path: match[2], query, version: parsed.query.version }
|
|
35
|
+
: undefined;
|
|
36
|
+
}
|
|
37
|
+
exports.tryParseCompatibleResolvedUrl = tryParseCompatibleResolvedUrl;
|
|
38
|
+
/**
|
|
39
|
+
* Combine the app summary and protocol summary in 1 tree.
|
|
40
|
+
* @param appSummary - Summary of the app.
|
|
41
|
+
* @param protocolSummary - Summary of the protocol.
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
function combineAppAndProtocolSummary(appSummary, protocolSummary) {
|
|
45
|
+
(0, core_utils_1.assert)(!(0, driver_utils_1.isCombinedAppAndProtocolSummary)(appSummary), 0x5a8 /* app summary is already a combined tree! */);
|
|
46
|
+
(0, core_utils_1.assert)(!(0, driver_utils_1.isCombinedAppAndProtocolSummary)(protocolSummary), 0x5a9 /* protocol summary is already a combined tree! */);
|
|
47
|
+
const createNewSummary = {
|
|
48
|
+
type: protocol_definitions_1.SummaryType.Tree,
|
|
49
|
+
tree: {
|
|
50
|
+
".protocol": protocolSummary,
|
|
51
|
+
".app": appSummary,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
return createNewSummary;
|
|
55
|
+
}
|
|
56
|
+
exports.combineAppAndProtocolSummary = combineAppAndProtocolSummary;
|
|
57
|
+
/**
|
|
58
|
+
* Converts a summary to snapshot tree and separate its blob contents
|
|
59
|
+
* to align detached container format with IPendingContainerState
|
|
60
|
+
* @param summary - ISummaryTree
|
|
61
|
+
*/
|
|
62
|
+
function convertSummaryToSnapshotAndBlobs(summary) {
|
|
63
|
+
let blobContents = {};
|
|
64
|
+
const treeNode = {
|
|
65
|
+
blobs: {},
|
|
66
|
+
trees: {},
|
|
67
|
+
id: (0, uuid_1.v4)(),
|
|
68
|
+
unreferenced: summary.unreferenced,
|
|
69
|
+
};
|
|
70
|
+
const keys = Object.keys(summary.tree);
|
|
71
|
+
for (const key of keys) {
|
|
72
|
+
const summaryObject = summary.tree[key];
|
|
73
|
+
switch (summaryObject.type) {
|
|
74
|
+
case protocol_definitions_1.SummaryType.Tree: {
|
|
75
|
+
const { tree, blobs } = convertSummaryToSnapshotAndBlobs(summaryObject);
|
|
76
|
+
treeNode.trees[key] = tree;
|
|
77
|
+
blobContents = { ...blobContents, ...blobs };
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case protocol_definitions_1.SummaryType.Attachment:
|
|
81
|
+
treeNode.blobs[key] = summaryObject.id;
|
|
82
|
+
break;
|
|
83
|
+
case protocol_definitions_1.SummaryType.Blob: {
|
|
84
|
+
const blobId = (0, uuid_1.v4)();
|
|
85
|
+
treeNode.blobs[key] = blobId;
|
|
86
|
+
const contentString = summaryObject.content instanceof Uint8Array
|
|
87
|
+
? (0, client_utils_1.Uint8ArrayToString)(summaryObject.content)
|
|
88
|
+
: summaryObject.content;
|
|
89
|
+
blobContents[blobId] = contentString;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case protocol_definitions_1.SummaryType.Handle:
|
|
93
|
+
throw new telemetry_utils_1.LoggingError("No handles should be there in summary in detached container!!");
|
|
94
|
+
break;
|
|
95
|
+
default: {
|
|
96
|
+
(0, core_utils_1.unreachableCase)(summaryObject, `Unknown tree type ${summaryObject.type}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return { tree: treeNode, blobs: blobContents };
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Converts summary parts into a SnapshotTree and its blob contents.
|
|
104
|
+
* @param protocolSummaryTree - Protocol Summary Tree
|
|
105
|
+
* @param appSummaryTree - App Summary Tree
|
|
106
|
+
*/
|
|
107
|
+
function convertProtocolAndAppSummaryToSnapshotAndBlobs(protocolSummaryTree, appSummaryTree) {
|
|
108
|
+
const combinedSummary = {
|
|
109
|
+
type: protocol_definitions_1.SummaryType.Tree,
|
|
110
|
+
tree: { ...appSummaryTree.tree },
|
|
111
|
+
};
|
|
112
|
+
combinedSummary.tree[".protocol"] = protocolSummaryTree;
|
|
113
|
+
const snapshotTreeWithBlobContents = convertSummaryToSnapshotAndBlobs(combinedSummary);
|
|
114
|
+
return snapshotTreeWithBlobContents;
|
|
115
|
+
}
|
|
116
|
+
const getSnapshotTreeAndBlobsFromSerializedContainer = (detachedContainerSnapshot) => {
|
|
117
|
+
(0, core_utils_1.assert)((0, driver_utils_1.isCombinedAppAndProtocolSummary)(detachedContainerSnapshot), "Protocol and App summary trees should be present");
|
|
118
|
+
const protocolSummaryTree = detachedContainerSnapshot.tree[".protocol"];
|
|
119
|
+
const appSummaryTree = detachedContainerSnapshot.tree[".app"];
|
|
120
|
+
const snapshotTreeWithBlobContents = convertProtocolAndAppSummaryToSnapshotAndBlobs(protocolSummaryTree, appSummaryTree);
|
|
121
|
+
return snapshotTreeWithBlobContents;
|
|
122
|
+
};
|
|
123
|
+
exports.getSnapshotTreeAndBlobsFromSerializedContainer = getSnapshotTreeAndBlobsFromSerializedContainer;
|
|
124
|
+
function getProtocolSnapshotTree(snapshot) {
|
|
125
|
+
return ".protocol" in snapshot.trees ? snapshot.trees[".protocol"] : snapshot;
|
|
126
|
+
}
|
|
127
|
+
exports.getProtocolSnapshotTree = getProtocolSnapshotTree;
|
|
128
|
+
const combineSnapshotTreeAndSnapshotBlobs = (baseSnapshot, snapshotBlobs) => {
|
|
129
|
+
const blobsContents = {};
|
|
130
|
+
// Process blobs in the current level
|
|
131
|
+
for (const [, id] of Object.entries(baseSnapshot.blobs)) {
|
|
132
|
+
if (snapshotBlobs[id]) {
|
|
133
|
+
blobsContents[id] = (0, client_utils_1.stringToBuffer)(snapshotBlobs[id], "utf8");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Recursively process trees in the current level
|
|
137
|
+
const trees = {};
|
|
138
|
+
for (const [path, tree] of Object.entries(baseSnapshot.trees)) {
|
|
139
|
+
trees[path] = (0, exports.combineSnapshotTreeAndSnapshotBlobs)(tree, snapshotBlobs);
|
|
140
|
+
}
|
|
141
|
+
// Create a new snapshot tree with blob contents and processed trees
|
|
142
|
+
const snapshotTreeWithBlobContents = {
|
|
143
|
+
...baseSnapshot,
|
|
144
|
+
blobsContents,
|
|
145
|
+
trees,
|
|
146
|
+
};
|
|
147
|
+
return snapshotTreeWithBlobContents;
|
|
148
|
+
};
|
|
149
|
+
exports.combineSnapshotTreeAndSnapshotBlobs = combineSnapshotTreeAndSnapshotBlobs;
|
|
150
|
+
function isDeltaStreamConnectionForbiddenError(error) {
|
|
151
|
+
return (typeof error === "object" &&
|
|
152
|
+
error !== null &&
|
|
153
|
+
error?.errorType === driver_definitions_1.DriverErrorTypes.deltaStreamConnectionForbidden);
|
|
154
|
+
}
|
|
155
|
+
exports.isDeltaStreamConnectionForbiddenError = isDeltaStreamConnectionForbiddenError;
|
|
156
|
+
/**
|
|
157
|
+
* Validates format in parsed string get from detached container
|
|
158
|
+
* serialization using IPendingDetachedContainerState format.
|
|
159
|
+
*/
|
|
160
|
+
function isPendingDetachedContainerState(detachedContainerState) {
|
|
161
|
+
if (detachedContainerState?.attached === undefined ||
|
|
162
|
+
detachedContainerState?.baseSnapshot === undefined ||
|
|
163
|
+
detachedContainerState?.snapshotBlobs === undefined ||
|
|
164
|
+
detachedContainerState?.hasAttachmentBlobs === undefined) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
function getDetachedContainerStateFromSerializedContainer(serializedContainer) {
|
|
170
|
+
const hasBlobsSummaryTree = ".hasAttachmentBlobs";
|
|
171
|
+
const parsedContainerState = JSON.parse(serializedContainer);
|
|
172
|
+
if (isPendingDetachedContainerState(parsedContainerState)) {
|
|
173
|
+
return parsedContainerState;
|
|
174
|
+
}
|
|
175
|
+
else if ((0, driver_utils_1.isCombinedAppAndProtocolSummary)(parsedContainerState)) {
|
|
176
|
+
const { tree, blobs } = (0, exports.getSnapshotTreeAndBlobsFromSerializedContainer)(parsedContainerState);
|
|
177
|
+
const detachedContainerState = {
|
|
178
|
+
attached: false,
|
|
179
|
+
baseSnapshot: tree,
|
|
180
|
+
snapshotBlobs: blobs,
|
|
181
|
+
hasAttachmentBlobs: parsedContainerState.tree[hasBlobsSummaryTree] !== undefined,
|
|
182
|
+
};
|
|
183
|
+
return detachedContainerState;
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
throw new telemetry_utils_1.UsageError("Cannot rehydrate detached container. Incorrect format");
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
exports.getDetachedContainerStateFromSerializedContainer = getDetachedContainerStateFromSerializedContainer;
|
|
190
|
+
/**
|
|
191
|
+
* Ensures only a single instance of the provided async function is running.
|
|
192
|
+
* If there are multiple calls they will all get the same promise to wait on.
|
|
193
|
+
*/
|
|
194
|
+
const runSingle = (func) => {
|
|
195
|
+
let running;
|
|
196
|
+
// don't mark this function async, so we return the same promise,
|
|
197
|
+
// rather than one that is wrapped due to async
|
|
198
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
199
|
+
return (...args) => {
|
|
200
|
+
if (running !== undefined) {
|
|
201
|
+
if (!(0, core_utils_1.compareArrays)(running.args, args)) {
|
|
202
|
+
return Promise.reject(new telemetry_utils_1.UsageError("Subsequent calls cannot use different arguments."));
|
|
203
|
+
}
|
|
204
|
+
return running.result;
|
|
205
|
+
}
|
|
206
|
+
running = { args, result: func(...args).finally(() => (running = undefined)) };
|
|
207
|
+
return running.result;
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
exports.runSingle = runSingle;
|
|
211
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6BAA4B;AAC5B,+BAAkC;AAClC,+DAAkF;AAClF,2DAAoF;AACpF,+EAAgG;AAChG,qEAA2E;AAC3E,+DAIsC;AACtC,2EAAsE;AAsCtE;;;;;;;;GAQG;AACH,SAAgB,6BAA6B,CAAC,GAAW;IACxD,MAAM,MAAM,GAAG,IAAA,WAAK,EAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAChC,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE;QACxC,MAAM,IAAI,8BAAY,CAAC,0BAA0B,CAAC,CAAC;KACnD;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;IAClC,MAAM,KAAK,GAAG,2BAA2B,CAAC;IAC1C,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1C,OAAO,KAAK,EAAE,MAAM,KAAK,CAAC;QACzB,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,OAAiB,EAAE;QAClF,CAAC,CAAC,SAAS,CAAC;AACd,CAAC;AAXD,sEAWC;AAED;;;;;GAKG;AACH,SAAgB,4BAA4B,CAC3C,U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,IAAgC,EAAE,EAAE;IACjF,IAAI,OAKQ,CAAC;IACb,iEAAiE;IACjE,+CAA+C;IAC/C,qEAAqE;IACrE,OAAO,CAAC,GAAG,IAAO,EAAE,EAAE;QACrB,IAAI,OAAO,KAAK,SAAS,EAAE;YAC1B,IAAI,CAAC,IAAA,0BAAa,EAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;gBACvC,OAAO,OAAO,CAAC,MAAM,CACpB,IAAI,4BAAU,CAAC,kDAAkD,CAAC,CAClE,CAAC;aACF;YACD,OAAO,OAAO,CAAC,MAAM,CAAC;SACtB;QACD,OAAO,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC;QAC/E,OAAO,OAAO,CAAC,MAAM,CAAC;IACvB,CAAC,CAAC;AACH,CAAC,CAAC;AAtBW,QAAA,SAAS,aAsBpB","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { parse } from \"url\";\nimport { v4 as uuid } from \"uuid\";\nimport { Uint8ArrayToString, stringToBuffer } from \"@fluid-internal/client-utils\";\nimport { assert, compareArrays, unreachableCase } from \"@fluidframework/core-utils\";\nimport { ISummaryTree, ISnapshotTree, SummaryType } from \"@fluidframework/protocol-definitions\";\nimport { LoggingError, UsageError } from \"@fluidframework/telemetry-utils\";\nimport {\n\tCombinedAppAndProtocolSummary,\n\tDeltaStreamConnectionForbiddenError,\n\tisCombinedAppAndProtocolSummary,\n} from \"@fluidframework/driver-utils\";\nimport { DriverErrorTypes } from \"@fluidframework/driver-definitions\";\nimport { ISerializableBlobContents } from \"./containerStorageAdapter\";\nimport { IPendingDetachedContainerState } from \"./container\";\n\n// This is used when we rehydrate a container from the snapshot. Here we put the blob contents\n// in separate property: blobContents.\nexport interface ISnapshotTreeWithBlobContents extends ISnapshotTree {\n\tblobsContents: { [path: string]: ArrayBufferLike };\n\ttrees: { [path: string]: ISnapshotTreeWithBlobContents };\n}\n\n/**\n * Interface to represent the parsed parts of IResolvedUrl.url to help\n * in getting info about different parts of the url.\n * May not be compatible or relevant for any Url Resolver\n * @internal\n */\nexport interface IParsedUrl {\n\t/**\n\t * It is combination of tenantid/docId part of the url.\n\t */\n\tid: string;\n\t/**\n\t * It is the deep link path in the url.\n\t */\n\tpath: string;\n\t/**\n\t * Query string part of the url.\n\t */\n\tquery: string;\n\t/**\n\t * Null means do not use snapshots, undefined means load latest snapshot\n\t * otherwise it's version ID passed to IDocumentStorageService.getVersions() to figure out what snapshot to use.\n\t * If needed, can add undefined which is treated by Container.load() as load latest snapshot.\n\t */\n\tversion: string | null | undefined;\n}\n\n/**\n * Utility api to parse the IResolvedUrl.url into specific parts like querystring, path to get\n * deep link info etc.\n * Warning - This function may not be compatible with any Url Resolver's resolved url. It works\n * with urls of type: protocol://<string>/.../..?<querystring>\n * @param url - This is the IResolvedUrl.url part of the resolved url.\n * @returns The IParsedUrl representing the input URL, or undefined if the format was not supported\n * @internal\n */\nexport function tryParseCompatibleResolvedUrl(url: string): IParsedUrl | undefined {\n\tconst parsed = parse(url, true);\n\tif (typeof parsed.pathname !== \"string\") {\n\t\tthrow new LoggingError(\"Failed to parse pathname\");\n\t}\n\tconst query = parsed.search ?? \"\";\n\tconst regex = /^\\/([^/]*\\/[^/]*)(\\/?.*)$/;\n\tconst match = regex.exec(parsed.pathname);\n\treturn match?.length === 3\n\t\t? { id: match[1], path: match[2], query, version: parsed.query.version as string }\n\t\t: undefined;\n}\n\n/**\n * Combine the app summary and protocol summary in 1 tree.\n * @param appSummary - Summary of the app.\n * @param protocolSummary - Summary of the protocol.\n * @internal\n */\nexport function combineAppAndProtocolSummary(\n\tappSummary: ISummaryTree,\n\tprotocolSummary: ISummaryTree,\n): CombinedAppAndProtocolSummary {\n\tassert(\n\t\t!isCombinedAppAndProtocolSummary(appSummary),\n\t\t0x5a8 /* app summary is already a combined tree! */,\n\t);\n\tassert(\n\t\t!isCombinedAppAndProtocolSummary(protocolSummary),\n\t\t0x5a9 /* protocol summary is already a combined tree! */,\n\t);\n\tconst createNewSummary: CombinedAppAndProtocolSummary = {\n\t\ttype: SummaryType.Tree,\n\t\ttree: {\n\t\t\t\".protocol\": protocolSummary,\n\t\t\t\".app\": appSummary,\n\t\t},\n\t};\n\treturn createNewSummary;\n}\n\n/**\n * Converts a summary to snapshot tree and separate its blob contents\n * to align detached container format with IPendingContainerState\n * @param summary - ISummaryTree\n */\nfunction convertSummaryToSnapshotAndBlobs(summary: ISummaryTree): {\n\ttree: ISnapshotTree;\n\tblobs: ISerializableBlobContents;\n} {\n\tlet blobContents: ISerializableBlobContents = {};\n\tconst treeNode: ISnapshotTree = {\n\t\tblobs: {},\n\t\ttrees: {},\n\t\tid: uuid(),\n\t\tunreferenced: summary.unreferenced,\n\t};\n\tconst keys = Object.keys(summary.tree);\n\tfor (const key of keys) {\n\t\tconst summaryObject = summary.tree[key];\n\n\t\tswitch (summaryObject.type) {\n\t\t\tcase SummaryType.Tree: {\n\t\t\t\tconst { tree, blobs } = convertSummaryToSnapshotAndBlobs(summaryObject);\n\t\t\t\ttreeNode.trees[key] = tree;\n\t\t\t\tblobContents = { ...blobContents, ...blobs };\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SummaryType.Attachment:\n\t\t\t\ttreeNode.blobs[key] = summaryObject.id;\n\t\t\t\tbreak;\n\t\t\tcase SummaryType.Blob: {\n\t\t\t\tconst blobId = uuid();\n\t\t\t\ttreeNode.blobs[key] = blobId;\n\t\t\t\tconst contentString: string =\n\t\t\t\t\tsummaryObject.content instanceof Uint8Array\n\t\t\t\t\t\t? Uint8ArrayToString(summaryObject.content)\n\t\t\t\t\t\t: summaryObject.content;\n\t\t\t\tblobContents[blobId] = contentString;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SummaryType.Handle:\n\t\t\t\tthrow new LoggingError(\n\t\t\t\t\t\"No handles should be there in summary in detached container!!\",\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tunreachableCase(summaryObject, `Unknown tree type ${(summaryObject as any).type}`);\n\t\t\t}\n\t\t}\n\t}\n\treturn { tree: treeNode, blobs: blobContents };\n}\n\n/**\n * Converts summary parts into a SnapshotTree and its blob contents.\n * @param protocolSummaryTree - Protocol Summary Tree\n * @param appSummaryTree - App Summary Tree\n */\nfunction convertProtocolAndAppSummaryToSnapshotAndBlobs(\n\tprotocolSummaryTree: ISummaryTree,\n\tappSummaryTree: ISummaryTree,\n): { tree: ISnapshotTree; blobs: ISerializableBlobContents } {\n\tconst combinedSummary: ISummaryTree = {\n\t\ttype: SummaryType.Tree,\n\t\ttree: { ...appSummaryTree.tree },\n\t};\n\n\tcombinedSummary.tree[\".protocol\"] = protocolSummaryTree;\n\tconst snapshotTreeWithBlobContents = convertSummaryToSnapshotAndBlobs(combinedSummary);\n\treturn snapshotTreeWithBlobContents;\n}\n\nexport const getSnapshotTreeAndBlobsFromSerializedContainer = (\n\tdetachedContainerSnapshot: ISummaryTree,\n): { tree: ISnapshotTree; blobs: ISerializableBlobContents } => {\n\tassert(\n\t\tisCombinedAppAndProtocolSummary(detachedContainerSnapshot),\n\t\t\"Protocol and App summary trees should be present\",\n\t);\n\tconst protocolSummaryTree = detachedContainerSnapshot.tree[\".protocol\"];\n\tconst appSummaryTree = detachedContainerSnapshot.tree[\".app\"];\n\tconst snapshotTreeWithBlobContents = convertProtocolAndAppSummaryToSnapshotAndBlobs(\n\t\tprotocolSummaryTree,\n\t\tappSummaryTree,\n\t);\n\treturn snapshotTreeWithBlobContents;\n};\n\nexport function getProtocolSnapshotTree(snapshot: ISnapshotTree): ISnapshotTree {\n\treturn \".protocol\" in snapshot.trees ? snapshot.trees[\".protocol\"] : snapshot;\n}\n\nexport const combineSnapshotTreeAndSnapshotBlobs = (\n\tbaseSnapshot: ISnapshotTree,\n\tsnapshotBlobs: ISerializableBlobContents,\n): ISnapshotTreeWithBlobContents => {\n\tconst blobsContents: { [path: string]: ArrayBufferLike } = {};\n\n\t// Process blobs in the current level\n\tfor (const [, id] of Object.entries(baseSnapshot.blobs)) {\n\t\tif (snapshotBlobs[id]) {\n\t\t\tblobsContents[id] = stringToBuffer(snapshotBlobs[id], \"utf8\");\n\t\t}\n\t}\n\n\t// Recursively process trees in the current level\n\tconst trees: { [path: string]: ISnapshotTreeWithBlobContents } = {};\n\tfor (const [path, tree] of Object.entries(baseSnapshot.trees)) {\n\t\ttrees[path] = combineSnapshotTreeAndSnapshotBlobs(tree, snapshotBlobs);\n\t}\n\n\t// Create a new snapshot tree with blob contents and processed trees\n\tconst snapshotTreeWithBlobContents: ISnapshotTreeWithBlobContents = {\n\t\t...baseSnapshot,\n\t\tblobsContents,\n\t\ttrees,\n\t};\n\n\treturn snapshotTreeWithBlobContents;\n};\n\nexport function isDeltaStreamConnectionForbiddenError(\n\terror: any,\n): error is DeltaStreamConnectionForbiddenError {\n\treturn (\n\t\ttypeof error === \"object\" &&\n\t\terror !== null &&\n\t\terror?.errorType === DriverErrorTypes.deltaStreamConnectionForbidden\n\t);\n}\n\n/**\n * Validates format in parsed string get from detached container\n * serialization using IPendingDetachedContainerState format.\n */\nfunction isPendingDetachedContainerState(\n\tdetachedContainerState: IPendingDetachedContainerState,\n): detachedContainerState is IPendingDetachedContainerState {\n\tif (\n\t\tdetachedContainerState?.attached === undefined ||\n\t\tdetachedContainerState?.baseSnapshot === undefined ||\n\t\tdetachedContainerState?.snapshotBlobs === undefined ||\n\t\tdetachedContainerState?.hasAttachmentBlobs === undefined\n\t) {\n\t\treturn false;\n\t}\n\treturn true;\n}\n\nexport function getDetachedContainerStateFromSerializedContainer(\n\tserializedContainer: string,\n): IPendingDetachedContainerState {\n\tconst hasBlobsSummaryTree = \".hasAttachmentBlobs\";\n\tconst parsedContainerState = JSON.parse(serializedContainer);\n\tif (isPendingDetachedContainerState(parsedContainerState)) {\n\t\treturn parsedContainerState;\n\t} else if (isCombinedAppAndProtocolSummary(parsedContainerState)) {\n\t\tconst { tree, blobs } =\n\t\t\tgetSnapshotTreeAndBlobsFromSerializedContainer(parsedContainerState);\n\t\tconst detachedContainerState: IPendingDetachedContainerState = {\n\t\t\tattached: false,\n\t\t\tbaseSnapshot: tree,\n\t\t\tsnapshotBlobs: blobs,\n\t\t\thasAttachmentBlobs: parsedContainerState.tree[hasBlobsSummaryTree] !== undefined,\n\t\t};\n\t\treturn detachedContainerState;\n\t} else {\n\t\tthrow new UsageError(\"Cannot rehydrate detached container. Incorrect format\");\n\t}\n}\n\n/**\n * Ensures only a single instance of the provided async function is running.\n * If there are multiple calls they will all get the same promise to wait on.\n */\nexport const runSingle = <A extends any[], R>(func: (...args: A) => Promise<R>) => {\n\tlet running:\n\t\t| {\n\t\t\t\targs: A;\n\t\t\t\tresult: Promise<R>;\n\t\t }\n\t\t| undefined;\n\t// don't mark this function async, so we return the same promise,\n\t// rather than one that is wrapped due to async\n\t// eslint-disable-next-line @typescript-eslint/promise-function-async\n\treturn (...args: A) => {\n\t\tif (running !== undefined) {\n\t\t\tif (!compareArrays(running.args, args)) {\n\t\t\t\treturn Promise.reject(\n\t\t\t\t\tnew UsageError(\"Subsequent calls cannot use different arguments.\"),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn running.result;\n\t\t}\n\t\trunning = { args, result: func(...args).finally(() => (running = undefined)) };\n\t\treturn running.result;\n\t};\n};\n"]}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { AttachState } from "@fluidframework/container-definitions";
|
|
2
|
+
import { CombinedAppAndProtocolSummary } from "@fluidframework/driver-utils";
|
|
3
|
+
import { ISnapshotTree, ISummaryTree } from "@fluidframework/protocol-definitions";
|
|
4
|
+
import { IDocumentStorageService } from "@fluidframework/driver-definitions";
|
|
5
|
+
import { ISerializableBlobContents } from "./containerStorageAdapter.mjs";
|
|
6
|
+
import { IDetachedBlobStorage } from ".";
|
|
7
|
+
/**
|
|
8
|
+
* The default state a newly created detached container will have.
|
|
9
|
+
* All but the state are optional and undefined, they just exist
|
|
10
|
+
* to make the union easy to deal with for both Detached types
|
|
11
|
+
*/
|
|
12
|
+
export interface DetachedDefaultData {
|
|
13
|
+
readonly state: AttachState.Detached;
|
|
14
|
+
readonly blobs?: undefined;
|
|
15
|
+
readonly summary?: undefined;
|
|
16
|
+
readonly redirectTable?: undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* This always follows DetachedDefaultData when there are
|
|
20
|
+
* outstanding blobs in the detached blob storage.
|
|
21
|
+
* The redirect table will get filled up to include data
|
|
22
|
+
* about the blobs as they are uploaded.
|
|
23
|
+
*/
|
|
24
|
+
export interface DetachedDataWithOutstandingBlobs {
|
|
25
|
+
readonly state: AttachState.Detached;
|
|
26
|
+
readonly blobs: "outstanding";
|
|
27
|
+
readonly summary?: undefined;
|
|
28
|
+
readonly redirectTable: Map<string, string>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* This state always follows DetachedDataWithOutstandingBlobs.
|
|
32
|
+
* It signals that all outstanding blobs are done being uploaded,
|
|
33
|
+
* so the container can move to the attaching state.
|
|
34
|
+
*/
|
|
35
|
+
export interface AttachingDataWithBlobs {
|
|
36
|
+
readonly state: AttachState.Attaching;
|
|
37
|
+
readonly blobs: "done";
|
|
38
|
+
readonly summary: CombinedAppAndProtocolSummary;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* This always follows DefaultDetachedState when there are
|
|
42
|
+
* no blobs in the detached blob storage. Because there are
|
|
43
|
+
* no blobs we can immediately get the summary and transition
|
|
44
|
+
* to the attaching state.
|
|
45
|
+
*/
|
|
46
|
+
export interface AttachingDataWithoutBlobs {
|
|
47
|
+
readonly state: AttachState.Attaching;
|
|
48
|
+
readonly summary: CombinedAppAndProtocolSummary;
|
|
49
|
+
readonly blobs: "none";
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The final attachment state which signals the container is fully attached.
|
|
53
|
+
* The baseSnapshotAndBlobs will only be enabled when offline load is enabled.
|
|
54
|
+
*/
|
|
55
|
+
export interface AttachedData {
|
|
56
|
+
readonly state: AttachState.Attached;
|
|
57
|
+
readonly snapshot?: {
|
|
58
|
+
tree: ISnapshotTree;
|
|
59
|
+
blobs: ISerializableBlobContents;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A union of all the attachment data types for
|
|
64
|
+
* tracking across all container attachment states
|
|
65
|
+
*/
|
|
66
|
+
export type AttachmentData = DetachedDefaultData | DetachedDataWithOutstandingBlobs | AttachingDataWithoutBlobs | AttachingDataWithBlobs | AttachedData;
|
|
67
|
+
/**
|
|
68
|
+
* The data and services necessary for runRetriableAttachProcess.
|
|
69
|
+
*/
|
|
70
|
+
export interface AttachProcessProps {
|
|
71
|
+
/**
|
|
72
|
+
* The initial attachment data this call should start with
|
|
73
|
+
*/
|
|
74
|
+
readonly initialAttachmentData: Exclude<AttachmentData, AttachedData>;
|
|
75
|
+
/**
|
|
76
|
+
* The caller should use this callback to keep track of the current
|
|
77
|
+
* attachment data, and perform any other operations necessary
|
|
78
|
+
* for dealing with attachment state changes, like emitting events
|
|
79
|
+
*
|
|
80
|
+
* @param attachmentData - the updated attachment data */
|
|
81
|
+
readonly setAttachmentData: (attachmentData: AttachmentData) => void;
|
|
82
|
+
/**
|
|
83
|
+
* The caller should create and or get services based on the data, and its own information.
|
|
84
|
+
* @param data - the data to create services from,
|
|
85
|
+
* the summary property being the most relevant part of the data.
|
|
86
|
+
* @returns A compatible storage service
|
|
87
|
+
*/
|
|
88
|
+
readonly createOrGetStorageService: (data: ISummaryTree | undefined) => Promise<Pick<IDocumentStorageService, "createBlob" | "uploadSummaryWithContext">>;
|
|
89
|
+
/**
|
|
90
|
+
* The detached blob storage if it exists.
|
|
91
|
+
*/
|
|
92
|
+
readonly detachedBlobStorage?: Pick<IDetachedBlobStorage, "getBlobIds" | "readBlob" | "size">;
|
|
93
|
+
/**
|
|
94
|
+
* The caller should create the attachment summary for the container.
|
|
95
|
+
* @param redirectTable - Maps local blob ids to remote blobs ids.
|
|
96
|
+
* @returns The attachment summary for the container.
|
|
97
|
+
*/
|
|
98
|
+
readonly createAttachmentSummary: (redirectTable?: Map<string, string>) => CombinedAppAndProtocolSummary;
|
|
99
|
+
/**
|
|
100
|
+
* Whether offline load is enabled or not.
|
|
101
|
+
*/
|
|
102
|
+
readonly offlineLoadEnabled: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Executes the attach process state machine based on the provided data and services.
|
|
106
|
+
* This method is retriable on failure. Based on the provided initialAttachmentData
|
|
107
|
+
* this method will resume the attachment process and attempt to complete it.
|
|
108
|
+
*
|
|
109
|
+
* @param props - The data and services necessary to run the attachment process
|
|
110
|
+
*/
|
|
111
|
+
export declare const runRetriableAttachProcess: (props: AttachProcessProps) => Promise<void>;
|
|
112
|
+
//# sourceMappingURL=attachment.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment.d.mts","sourceRoot":"","sources":["../src/attachment.ts"],"names":[],"mappings":"OAIO,EAAE,WAAW,EAAE,MAAM,uCAAuC;OAC5D,EAAE,6BAA6B,EAAE,MAAM,8BAA8B;OACrE,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sCAAsC;OAE3E,EAAE,uBAAuB,EAAE,MAAM,oCAAoC;OAErE,EAAE,yBAAyB,EAAE;OAC7B,EAAE,oBAAoB,EAAE,MAAM,GAAG;AAExC;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,QAAQ,CAAC;IACrC,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC;IAC7B,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,CAAC;CACnC;AAED;;;;;GA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B,EAAE,CACnC,IAAI,EAAE,YAAY,GAAG,SAAS,KAC1B,OAAO,CAAC,IAAI,CAAC,uBAAuB,EAAE,YAAY,GAAG,0BAA0B,CAAC,CAAC,CAAC;IAEvF;;OAEG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,YAAY,GAAG,UAAU,GAAG,MAAM,CAAC,CAAC;IAE9F;;;;OAIG;IACH,QAAQ,CAAC,uBAAuB,EAAE,CACjC,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,KAC/B,6BAA6B,CAAC;IAEnC;;OAEG;IACH,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAC;CACrC;AAED;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,UAAiB,kBAAkB,KAAG,QAAQ,IAAI,CAgFvF,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { AttachState } from "@fluidframework/container-definitions";
|
|
2
|
+
import { assert } from "@fluidframework/core-utils";
|
|
3
|
+
import { getSnapshotTreeAndBlobsFromSerializedContainer } from "./utils.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* Executes the attach process state machine based on the provided data and services.
|
|
6
|
+
* This method is retriable on failure. Based on the provided initialAttachmentData
|
|
7
|
+
* this method will resume the attachment process and attempt to complete it.
|
|
8
|
+
*
|
|
9
|
+
* @param props - The data and services necessary to run the attachment process
|
|
10
|
+
*/
|
|
11
|
+
export const runRetriableAttachProcess = async (props) => {
|
|
12
|
+
const { detachedBlobStorage, createOrGetStorageService, setAttachmentData, createAttachmentSummary, offlineLoadEnabled, } = props;
|
|
13
|
+
let currentData = props.initialAttachmentData;
|
|
14
|
+
if (currentData.blobs === undefined) {
|
|
15
|
+
// If attachment blobs were uploaded in detached state we will go through a different attach flow
|
|
16
|
+
const outstandingAttachmentBlobs = detachedBlobStorage !== undefined && detachedBlobStorage.size > 0;
|
|
17
|
+
// Determine the next phase of attaching which depends on if there are attachment blobs
|
|
18
|
+
// if there are, we will stay detached, so an empty file can be created, and the blobs
|
|
19
|
+
// uploaded, otherwise we will get the summary to create the file with and move to attaching
|
|
20
|
+
currentData = outstandingAttachmentBlobs
|
|
21
|
+
? {
|
|
22
|
+
state: AttachState.Detached,
|
|
23
|
+
blobs: "outstanding",
|
|
24
|
+
redirectTable: new Map(),
|
|
25
|
+
}
|
|
26
|
+
: {
|
|
27
|
+
state: AttachState.Attaching,
|
|
28
|
+
summary: props.createAttachmentSummary(),
|
|
29
|
+
blobs: "none",
|
|
30
|
+
};
|
|
31
|
+
setAttachmentData(currentData);
|
|
32
|
+
}
|
|
33
|
+
// this has to run here, as it is what creates the file
|
|
34
|
+
// and we need to file for all possible cases after this point
|
|
35
|
+
const storage = await createOrGetStorageService(currentData.summary);
|
|
36
|
+
if (currentData.blobs === "outstanding") {
|
|
37
|
+
const { redirectTable } = currentData;
|
|
38
|
+
// upload blobs to storage
|
|
39
|
+
assert(!!detachedBlobStorage, 0x24e /* "assertion for type narrowing" */);
|
|
40
|
+
// build a table mapping IDs assigned locally to IDs assigned by storage and pass it to runtime to
|
|
41
|
+
// support blob handles that only know about the local IDs
|
|
42
|
+
while (redirectTable.size < detachedBlobStorage.size) {
|
|
43
|
+
const newIds = detachedBlobStorage.getBlobIds().filter((id) => !redirectTable.has(id));
|
|
44
|
+
for (const id of newIds) {
|
|
45
|
+
const blob = await detachedBlobStorage.readBlob(id);
|
|
46
|
+
const response = await storage.createBlob(blob);
|
|
47
|
+
redirectTable.set(id, response.id);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
setAttachmentData((currentData = {
|
|
51
|
+
state: AttachState.Attaching,
|
|
52
|
+
summary: createAttachmentSummary(redirectTable),
|
|
53
|
+
blobs: "done",
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
assert(currentData.state === AttachState.Attaching, "must be attaching by this point");
|
|
57
|
+
if (currentData.blobs === "done") {
|
|
58
|
+
// done means outstanding blobs were uploaded.
|
|
59
|
+
// in that case an empty file was created, the blobs were uploaded
|
|
60
|
+
// and now this finally uploads the summary
|
|
61
|
+
await storage.uploadSummaryWithContext(currentData.summary, {
|
|
62
|
+
referenceSequenceNumber: 0,
|
|
63
|
+
ackHandle: undefined,
|
|
64
|
+
proposalHandle: undefined,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
setAttachmentData((currentData = {
|
|
68
|
+
state: AttachState.Attached,
|
|
69
|
+
snapshot: offlineLoadEnabled
|
|
70
|
+
? getSnapshotTreeAndBlobsFromSerializedContainer(currentData.summary)
|
|
71
|
+
: undefined,
|
|
72
|
+
}));
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=attachment.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment.mjs","sourceRoot":"","sources":["../src/attachment.ts"],"names":[],"mappings":"OAIO,EAAE,WAAW,EAAE,MAAM,uCAAuC;OAG5D,EAAE,MAAM,EAAE,MAAM,4BAA4B;OAE5C,EAAE,8CAA8C,EAAE;AA0HzD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,EAAE,KAAyB,EAAiB,EAAE;IAC3F,MAAM,EACL,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,GAClB,GAAG,KAAK,CAAC;IACV,IAAI,WAAW,GAAmB,KAAK,CAAC,qBAAqB,CAAC;IAE9D,IAAI,WAAW,CAAC,KAAK,KAAK,SAAS,EAAE;QACpC,iGAAiG;QACjG,MAAM,0BAA0B,GAC/B,mBAAmB,KAAK,SAAS,IAAI,mBAAmB,CAAC,IAAI,GAAG,CAAC,CAAC;QACnE,uFAAuF;QACvF,sFAAsF;QACtF,4FAA4F;QAC5F,WAAW,GAAG,0BAA0B;YACvC,CAAC,CAAC;gBACA,KAAK,EAAE,WAAW,CAAC,QAAQ;gBAC3B,KAAK,EAAE,aAAa;gBACpB,aAAa,EAAE,IAAI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AAW,CAAC,SAAS,EAAE,iCAAiC,CAAC,CAAC;IAEvF,IAAI,WAAW,CAAC,KAAK,KAAK,MAAM,EAAE;QACjC,8CAA8C;QAC9C,kEAAkE;QAClE,2CAA2C;QAC3C,MAAM,OAAO,CAAC,wBAAwB,CAAC,WAAW,CAAC,OAAO,EAAE;YAC3D,uBAAuB,EAAE,CAAC;YAC1B,SAAS,EAAE,SAAS;YACpB,cAAc,EAAE,SAAS;SACzB,CAAC,CAAC;KACH;IAED,iBAAiB,CAChB,CAAC,WAAW,GAAG;QACd,KAAK,EAAE,WAAW,CAAC,QAAQ;QAC3B,QAAQ,EAAE,kBAAkB;YAC3B,CAAC,CAAC,8CAA8C,CAAC,WAAW,CAAC,OAAO,CAAC;YACrE,CAAC,CAAC,SAAS;KACZ,CAAC,CACF,CAAC;AACH,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { CombinedAppAndProtocolSummary } from \"@fluidframework/driver-utils\";\nimport { ISnapshotTree, ISummaryTree } from \"@fluidframework/protocol-definitions\";\nimport { assert } from \"@fluidframework/core-utils\";\nimport { IDocumentStorageService } from \"@fluidframework/driver-definitions\";\nimport { getSnapshotTreeAndBlobsFromSerializedContainer } from \"./utils\";\nimport { ISerializableBlobContents } from \"./containerStorageAdapter\";\nimport { IDetachedBlobStorage } from \".\";\n\n/**\n * The default state a newly created detached container will have.\n * All but the state are optional and undefined, they just exist\n * to make the union easy to deal with for both Detached types\n */\nexport interface DetachedDefaultData {\n\treadonly state: AttachState.Detached;\n\treadonly blobs?: undefined;\n\treadonly summary?: undefined;\n\treadonly redirectTable?: undefined;\n}\n\n/**\n * This always follows DetachedDefaultData when there are\n * outstanding blobs in the detached blob storage.\n * The redirect table will get filled up to include data\n * about the blobs as they are uploaded.\n */\nexport interface DetachedDataWithOutstandingBlobs {\n\treadonly state: AttachState.Detached;\n\treadonly blobs: \"outstanding\";\n\treadonly summary?: undefined;\n\treadonly redirectTable: Map<string, string>;\n}\n\n/**\n * This state always follows DetachedDataWithOutstandingBlobs.\n * It signals that all outstanding blobs are done being uploaded,\n * so the container can move to the attaching state.\n */\nexport interface AttachingDataWithBlobs {\n\treadonly state: AttachState.Attaching;\n\treadonly blobs: \"done\";\n\treadonly summary: CombinedAppAndProtocolSummary;\n}\n\n/**\n * This always follows DefaultDetachedState when there are\n * no blobs in the detached blob storage. Because there are\n * no blobs we can immediately get the summary and transition\n * to the attaching state.\n */\nexport interface AttachingDataWithoutBlobs {\n\treadonly state: AttachState.Attaching;\n\treadonly summary: CombinedAppAndProtocolSummary;\n\treadonly blobs: \"none\";\n}\n\n/**\n * The final attachment state which signals the container is fully attached.\n * The baseSnapshotAndBlobs will only be enabled when offline load is enabled.\n */\nexport interface AttachedData {\n\treadonly state: AttachState.Attached;\n\treadonly snapshot?: {\n\t\ttree: ISnapshotTree;\n\t\tblobs: ISerializableBlobContents;\n\t};\n}\n\n/**\n * A union of all the attachment data types for\n * tracking across all container attachment states\n */\nexport type AttachmentData =\n\t| DetachedDefaultData\n\t| DetachedDataWithOutstandingBlobs\n\t| AttachingDataWithoutBlobs\n\t| AttachingDataWithBlobs\n\t| AttachedData;\n\n/**\n * The data and services necessary for runRetriableAttachProcess.\n */\nexport interface AttachProcessProps {\n\t/**\n\t * The initial attachment data this call should start with\n\t */\n\treadonly initialAttachmentData: Exclude<AttachmentData, AttachedData>;\n\n\t/**\n\t * The caller should use this callback to keep track of the current\n\t * attachment data, and perform any other operations necessary\n\t * for dealing with attachment state changes, like emitting events\n\t *\n\t * @param attachmentData - the updated attachment data\t */\n\treadonly setAttachmentData: (attachmentData: AttachmentData) => void;\n\n\t/**\n\t * The caller should create and or get services based on the data, and its own information.\n\t * @param data - the data to create services from,\n\t * the summary property being the most relevant part of the data.\n\t * @returns A compatible storage service\n\t */\n\treadonly createOrGetStorageService: (\n\t\tdata: ISummaryTree | undefined,\n\t) => Promise<Pick<IDocumentStorageService, \"createBlob\" | \"uploadSummaryWithContext\">>;\n\n\t/**\n\t * The detached blob storage if it exists.\n\t */\n\treadonly detachedBlobStorage?: Pick<IDetachedBlobStorage, \"getBlobIds\" | \"readBlob\" | \"size\">;\n\n\t/**\n\t * The caller should create the attachment summary for the container.\n\t * @param redirectTable - Maps local blob ids to remote blobs ids.\n\t * @returns The attachment summary for the container.\n\t */\n\treadonly createAttachmentSummary: (\n\t\tredirectTable?: Map<string, string>,\n\t) => CombinedAppAndProtocolSummary;\n\n\t/**\n\t * Whether offline load is enabled or not.\n\t */\n\treadonly offlineLoadEnabled: boolean;\n}\n\n/**\n * Executes the attach process state machine based on the provided data and services.\n * This method is retriable on failure. Based on the provided initialAttachmentData\n * this method will resume the attachment process and attempt to complete it.\n *\n * @param props - The data and services necessary to run the attachment process\n */\nexport const runRetriableAttachProcess = async (props: AttachProcessProps): Promise<void> => {\n\tconst {\n\t\tdetachedBlobStorage,\n\t\tcreateOrGetStorageService,\n\t\tsetAttachmentData,\n\t\tcreateAttachmentSummary,\n\t\tofflineLoadEnabled,\n\t} = props;\n\tlet currentData: AttachmentData = props.initialAttachmentData;\n\n\tif (currentData.blobs === undefined) {\n\t\t// If attachment blobs were uploaded in detached state we will go through a different attach flow\n\t\tconst outstandingAttachmentBlobs =\n\t\t\tdetachedBlobStorage !== undefined && detachedBlobStorage.size > 0;\n\t\t// Determine the next phase of attaching which depends on if there are attachment blobs\n\t\t// if there are, we will stay detached, so an empty file can be created, and the blobs\n\t\t// uploaded, otherwise we will get the summary to create the file with and move to attaching\n\t\tcurrentData = outstandingAttachmentBlobs\n\t\t\t? {\n\t\t\t\t\tstate: AttachState.Detached,\n\t\t\t\t\tblobs: \"outstanding\",\n\t\t\t\t\tredirectTable: new Map<string, string>(),\n\t\t\t }\n\t\t\t: {\n\t\t\t\t\tstate: AttachState.Attaching,\n\t\t\t\t\tsummary: props.createAttachmentSummary(),\n\t\t\t\t\tblobs: \"none\",\n\t\t\t };\n\t\tsetAttachmentData(currentData);\n\t}\n\n\t// this has to run here, as it is what creates the file\n\t// and we need to file for all possible cases after this point\n\tconst storage = await createOrGetStorageService(currentData.summary);\n\n\tif (currentData.blobs === \"outstanding\") {\n\t\tconst { redirectTable } = currentData;\n\t\t// upload blobs to storage\n\t\tassert(!!detachedBlobStorage, 0x24e /* \"assertion for type narrowing\" */);\n\n\t\t// build a table mapping IDs assigned locally to IDs assigned by storage and pass it to runtime to\n\t\t// support blob handles that only know about the local IDs\n\t\twhile (redirectTable.size < detachedBlobStorage.size) {\n\t\t\tconst newIds = detachedBlobStorage.getBlobIds().filter((id) => !redirectTable.has(id));\n\t\t\tfor (const id of newIds) {\n\t\t\t\tconst blob = await detachedBlobStorage.readBlob(id);\n\t\t\t\tconst response = await storage.createBlob(blob);\n\t\t\t\tredirectTable.set(id, response.id);\n\t\t\t}\n\t\t}\n\t\tsetAttachmentData(\n\t\t\t(currentData = {\n\t\t\t\tstate: AttachState.Attaching,\n\t\t\t\tsummary: createAttachmentSummary(redirectTable),\n\t\t\t\tblobs: \"done\",\n\t\t\t}),\n\t\t);\n\t}\n\n\tassert(currentData.state === AttachState.Attaching, \"must be attaching by this point\");\n\n\tif (currentData.blobs === \"done\") {\n\t\t// done means outstanding blobs were uploaded.\n\t\t// in that case an empty file was created, the blobs were uploaded\n\t\t// and now this finally uploads the summary\n\t\tawait storage.uploadSummaryWithContext(currentData.summary, {\n\t\t\treferenceSequenceNumber: 0,\n\t\t\tackHandle: undefined,\n\t\t\tproposalHandle: undefined,\n\t\t});\n\t}\n\n\tsetAttachmentData(\n\t\t(currentData = {\n\t\t\tstate: AttachState.Attached,\n\t\t\tsnapshot: offlineLoadEnabled\n\t\t\t\t? getSnapshotTreeAndBlobsFromSerializedContainer(currentData.summary)\n\t\t\t\t: undefined,\n\t\t}),\n\t);\n};\n"]}
|