@fluidframework/container-loader 2.63.0-359461 → 2.63.0-359962
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/api-report/container-loader.legacy.alpha.api.md +3 -0
- package/dist/attachment.d.ts +2 -7
- package/dist/attachment.d.ts.map +1 -1
- package/dist/attachment.js +2 -4
- package/dist/attachment.js.map +1 -1
- package/dist/container.d.ts.map +1 -1
- package/dist/container.js +7 -7
- package/dist/container.js.map +1 -1
- package/dist/containerStorageAdapter.d.ts +2 -2
- package/dist/containerStorageAdapter.d.ts.map +1 -1
- package/dist/containerStorageAdapter.js +1 -1
- package/dist/containerStorageAdapter.js.map +1 -1
- package/dist/createAndLoadContainerUtils.js +1 -1
- package/dist/createAndLoadContainerUtils.js.map +1 -1
- package/dist/frozenServices.d.ts +10 -1
- package/dist/frozenServices.d.ts.map +1 -1
- package/dist/frozenServices.js +24 -4
- package/dist/frozenServices.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/legacyAlpha.d.ts +1 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/serializedStateManager.d.ts +19 -12
- package/dist/serializedStateManager.d.ts.map +1 -1
- package/dist/serializedStateManager.js +112 -98
- package/dist/serializedStateManager.js.map +1 -1
- package/dist/utils.d.ts +10 -4
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +43 -25
- package/dist/utils.js.map +1 -1
- package/lib/attachment.d.ts +2 -7
- package/lib/attachment.d.ts.map +1 -1
- package/lib/attachment.js +3 -5
- package/lib/attachment.js.map +1 -1
- package/lib/container.d.ts.map +1 -1
- package/lib/container.js +8 -8
- package/lib/container.js.map +1 -1
- package/lib/containerStorageAdapter.d.ts +2 -2
- package/lib/containerStorageAdapter.d.ts.map +1 -1
- package/lib/containerStorageAdapter.js +1 -1
- package/lib/containerStorageAdapter.js.map +1 -1
- package/lib/createAndLoadContainerUtils.js +2 -2
- package/lib/createAndLoadContainerUtils.js.map +1 -1
- package/lib/frozenServices.d.ts +10 -1
- package/lib/frozenServices.d.ts.map +1 -1
- package/lib/frozenServices.js +20 -1
- package/lib/frozenServices.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/legacyAlpha.d.ts +1 -0
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/serializedStateManager.d.ts +19 -12
- package/lib/serializedStateManager.d.ts.map +1 -1
- package/lib/serializedStateManager.js +114 -100
- package/lib/serializedStateManager.js.map +1 -1
- package/lib/utils.d.ts +10 -4
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +41 -24
- package/lib/utils.js.map +1 -1
- package/package.json +11 -11
- package/src/attachment.ts +7 -13
- package/src/container.ts +12 -10
- package/src/containerStorageAdapter.ts +5 -6
- package/src/createAndLoadContainerUtils.ts +2 -2
- package/src/frozenServices.ts +28 -2
- package/src/index.ts +1 -0
- package/src/packageVersion.ts +1 -1
- package/src/serializedStateManager.ts +166 -132
- package/src/utils.ts +53 -31
package/lib/utils.js
CHANGED
|
@@ -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 {
|
|
5
|
+
import { bufferToString, stringToBuffer, Uint8ArrayToArrayBuffer, } from "@fluid-internal/client-utils";
|
|
6
6
|
import { assert, compareArrays, unreachableCase } from "@fluidframework/core-utils/internal";
|
|
7
7
|
import { SummaryType } from "@fluidframework/driver-definitions";
|
|
8
8
|
import { DriverErrorTypes, } from "@fluidframework/driver-definitions/internal";
|
|
@@ -59,9 +59,8 @@ export function combineAppAndProtocolSummary(appSummary, protocolSummary) {
|
|
|
59
59
|
* to align detached container format with IPendingContainerState
|
|
60
60
|
* @param summary - ISummaryTree
|
|
61
61
|
*/
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
const treeNode = {
|
|
62
|
+
function convertSummaryToISnapshot(summary, blobContents = new Map()) {
|
|
63
|
+
const snapshotTree = {
|
|
65
64
|
blobs: {},
|
|
66
65
|
trees: {},
|
|
67
66
|
id: uuid(),
|
|
@@ -71,22 +70,20 @@ function convertSummaryToSnapshotAndBlobs(summary) {
|
|
|
71
70
|
for (const [key, summaryObject] of Object.entries(summary.tree)) {
|
|
72
71
|
switch (summaryObject.type) {
|
|
73
72
|
case SummaryType.Tree: {
|
|
74
|
-
const innerSnapshot =
|
|
75
|
-
|
|
76
|
-
blobContents = { ...blobContents, ...innerSnapshot.snapshotBlobs };
|
|
73
|
+
const innerSnapshot = convertSummaryToISnapshot(summaryObject, blobContents);
|
|
74
|
+
snapshotTree.trees[key] = innerSnapshot.snapshotTree;
|
|
77
75
|
break;
|
|
78
76
|
}
|
|
79
77
|
case SummaryType.Attachment: {
|
|
80
|
-
|
|
78
|
+
snapshotTree.blobs[key] = summaryObject.id;
|
|
81
79
|
break;
|
|
82
80
|
}
|
|
83
81
|
case SummaryType.Blob: {
|
|
84
82
|
const blobId = uuid();
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
?
|
|
88
|
-
: summaryObject.content;
|
|
89
|
-
blobContents[blobId] = contentString;
|
|
83
|
+
snapshotTree.blobs[key] = blobId;
|
|
84
|
+
blobContents.set(blobId, summaryObject.content instanceof Uint8Array
|
|
85
|
+
? Uint8ArrayToArrayBuffer(summaryObject.content)
|
|
86
|
+
: stringToBuffer(summaryObject.content, "utf8"));
|
|
90
87
|
break;
|
|
91
88
|
}
|
|
92
89
|
case SummaryType.Handle: {
|
|
@@ -98,8 +95,14 @@ function convertSummaryToSnapshotAndBlobs(summary) {
|
|
|
98
95
|
}
|
|
99
96
|
}
|
|
100
97
|
}
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
return {
|
|
99
|
+
blobContents,
|
|
100
|
+
latestSequenceNumber: undefined,
|
|
101
|
+
ops: [],
|
|
102
|
+
sequenceNumber: 0,
|
|
103
|
+
snapshotFormatV: 1,
|
|
104
|
+
snapshotTree,
|
|
105
|
+
};
|
|
103
106
|
}
|
|
104
107
|
/**
|
|
105
108
|
* Converts a snapshot to snapshotInfo with its blob contents
|
|
@@ -127,7 +130,7 @@ export function convertSnapshotToSnapshotInfo(snapshot) {
|
|
|
127
130
|
* Note, this assumes the ISnapshot sequence number is defined. Otherwise an assert will be thrown
|
|
128
131
|
* @param snapshot - ISnapshot
|
|
129
132
|
*/
|
|
130
|
-
export function convertSnapshotInfoToSnapshot(snapshotInfo
|
|
133
|
+
export function convertSnapshotInfoToSnapshot(snapshotInfo) {
|
|
131
134
|
const blobContents = new Map();
|
|
132
135
|
for (const [blobId, serializedContent] of Object.entries(snapshotInfo.snapshotBlobs)) {
|
|
133
136
|
blobContents.set(blobId, stringToBuffer(serializedContent, "utf8"));
|
|
@@ -136,7 +139,7 @@ export function convertSnapshotInfoToSnapshot(snapshotInfo, snapshotSequenceNumb
|
|
|
136
139
|
snapshotTree: snapshotInfo.baseSnapshot,
|
|
137
140
|
blobContents,
|
|
138
141
|
ops: [],
|
|
139
|
-
sequenceNumber: snapshotSequenceNumber,
|
|
142
|
+
sequenceNumber: snapshotInfo.snapshotSequenceNumber,
|
|
140
143
|
latestSequenceNumber: undefined,
|
|
141
144
|
snapshotFormatV: 1,
|
|
142
145
|
};
|
|
@@ -146,20 +149,20 @@ export function convertSnapshotInfoToSnapshot(snapshotInfo, snapshotSequenceNumb
|
|
|
146
149
|
* @param protocolSummaryTree - Protocol Summary Tree
|
|
147
150
|
* @param appSummaryTree - App Summary Tree
|
|
148
151
|
*/
|
|
149
|
-
function
|
|
152
|
+
function convertProtocolAndAppSummaryToISnapshot(protocolSummaryTree, appSummaryTree) {
|
|
150
153
|
const combinedSummary = {
|
|
151
154
|
type: SummaryType.Tree,
|
|
152
155
|
tree: { ...appSummaryTree.tree },
|
|
153
156
|
};
|
|
154
157
|
combinedSummary.tree[".protocol"] = protocolSummaryTree;
|
|
155
|
-
const snapshotTreeWithBlobContents =
|
|
158
|
+
const snapshotTreeWithBlobContents = convertSummaryToISnapshot(combinedSummary);
|
|
156
159
|
return snapshotTreeWithBlobContents;
|
|
157
160
|
}
|
|
158
|
-
export const
|
|
161
|
+
export const getISnapshotFromSerializedContainer = (detachedContainerSnapshot) => {
|
|
159
162
|
assert(isCombinedAppAndProtocolSummary(detachedContainerSnapshot), 0x8e6 /* Protocol and App summary trees should be present */);
|
|
160
163
|
const protocolSummaryTree = detachedContainerSnapshot.tree[".protocol"];
|
|
161
164
|
const appSummaryTree = detachedContainerSnapshot.tree[".app"];
|
|
162
|
-
const snapshotTreeWithBlobContents =
|
|
165
|
+
const snapshotTreeWithBlobContents = convertProtocolAndAppSummaryToISnapshot(protocolSummaryTree, appSummaryTree);
|
|
163
166
|
return snapshotTreeWithBlobContents;
|
|
164
167
|
};
|
|
165
168
|
export function getProtocolSnapshotTree(snapshot) {
|
|
@@ -205,6 +208,21 @@ function isPendingDetachedContainerState(detachedContainerState) {
|
|
|
205
208
|
}
|
|
206
209
|
return true;
|
|
207
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Converts an ISnapshot to a SnapshotWithBlobs, extracting and serializing its blob contents.
|
|
213
|
+
* @param snapshot - The ISnapshot to convert.
|
|
214
|
+
* @returns A SnapshotWithBlobs containing the base snapshot and serialized blob contents.
|
|
215
|
+
*/
|
|
216
|
+
export function convertISnapshotToSnapshotWithBlobs(snapshot) {
|
|
217
|
+
const snapshotBlobs = {};
|
|
218
|
+
for (const [id, blob] of snapshot.blobContents.entries()) {
|
|
219
|
+
snapshotBlobs[id] = bufferToString(blob, "utf8");
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
baseSnapshot: snapshot.snapshotTree,
|
|
223
|
+
snapshotBlobs,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
208
226
|
/**
|
|
209
227
|
* Parses the given string into {@link IPendingDetachedContainerState} format,
|
|
210
228
|
* with validation (if invalid, throws a UsageError).
|
|
@@ -220,11 +238,10 @@ export function getDetachedContainerStateFromSerializedContainer(serializedConta
|
|
|
220
238
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
221
239
|
}
|
|
222
240
|
else if (isCombinedAppAndProtocolSummary(parsedContainerState)) {
|
|
223
|
-
const
|
|
241
|
+
const snapshot = getISnapshotFromSerializedContainer(parsedContainerState);
|
|
224
242
|
const detachedContainerState = {
|
|
225
243
|
attached: false,
|
|
226
|
-
|
|
227
|
-
snapshotBlobs,
|
|
244
|
+
...convertISnapshotToSnapshotWithBlobs(snapshot),
|
|
228
245
|
hasAttachmentBlobs: parsedContainerState.tree[hasBlobsSummaryTree] !== undefined,
|
|
229
246
|
};
|
|
230
247
|
return detachedContainerState;
|
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,kBAAkB,EAClB,cAAc,EACd,cAAc,GACd,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC7F,OAAO,EAAqB,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EACN,gBAAgB,GAKhB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAGN,+BAA+B,EAC/B,YAAY,GACZ,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACN,YAAY,EACZ,UAAU,GAEV,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AA2ClC;;;;;;;;GAQG;AACH,MAAM,UAAU,6BAA6B,CAAC,GAAW;IACxD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C,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;AAEF,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAC1C,OAAkD,EAClD,IAA+B;IAE/B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO;YACN,qBAAqB,EAAE,CAAC;YACxB,cAAc,EAAE,CAAC;SACjB,CAAC;IACH,CAAC;IAED,oFAAoF;IACpF,MAAM,cAAc,GACnB,WAAW,IAAI,IAAI,CAAC,KAAK;QACxB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,UAAU;QAC1C,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAE9B,MAAM,UAAU,GAAG,MAAM,YAAY,CAAsB,OAAO,EAAE,cAAc,CAAC,CAAC;IAEpF,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 {\n\tUint8ArrayToString,\n\tbufferToString,\n\tstringToBuffer,\n} from \"@fluid-internal/client-utils\";\nimport { assert, compareArrays, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { type ISummaryTree, SummaryType } from \"@fluidframework/driver-definitions\";\nimport {\n\tDriverErrorTypes,\n\ttype IDocumentAttributes,\n\ttype ISnapshotTree,\n\ttype IDocumentStorageService,\n\ttype ISnapshot,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\ttype CombinedAppAndProtocolSummary,\n\ttype DeltaStreamConnectionForbiddenError,\n\tisCombinedAppAndProtocolSummary,\n\treadAndParse,\n} from \"@fluidframework/driver-utils/internal\";\nimport {\n\tLoggingError,\n\tUsageError,\n\ttype IFluidErrorBase,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport { v4 as uuid } from \"uuid\";\n\nimport type { ISerializableBlobContents } from \"./containerStorageAdapter.js\";\nimport type {\n\tIPendingContainerState,\n\tIPendingDetachedContainerState,\n\tISnapshotInfo,\n\tSnapshotWithBlobs,\n} from \"./serializedStateManager.js\";\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 * @legacy @beta\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 * Undefined means load latest snapshot, otherwise it's version ID passed to IDocumentStorageService.getVersions()\n\t * to figure out what snapshot to use.\n\t */\n\tversion: string | 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 * @legacy @beta\n */\nexport function tryParseCompatibleResolvedUrl(url: string): IParsedUrl | undefined {\n\tconst parsed = new URL(url);\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? {\n\t\t\t\tid: match[1],\n\t\t\t\tpath: match[2],\n\t\t\t\tquery,\n\t\t\t\t// URLSearchParams returns null if the param is not provided.\n\t\t\t\tversion: parsed.searchParams.get(\"version\") ?? undefined,\n\t\t\t}\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): SnapshotWithBlobs {\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\tgroupId: summary.groupId,\n\t};\n\tfor (const [key, summaryObject] of Object.entries(summary.tree)) {\n\t\tswitch (summaryObject.type) {\n\t\t\tcase SummaryType.Tree: {\n\t\t\t\tconst innerSnapshot = convertSummaryToSnapshotAndBlobs(summaryObject);\n\t\t\t\ttreeNode.trees[key] = innerSnapshot.baseSnapshot;\n\t\t\t\tblobContents = { ...blobContents, ...innerSnapshot.snapshotBlobs };\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\t}\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}\n\t\t\tdefault: {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n\t\t\t\tunreachableCase(summaryObject, `Unknown tree type ${(summaryObject as any).type}`);\n\t\t\t}\n\t\t}\n\t}\n\tconst pendingSnapshot = { baseSnapshot: treeNode, snapshotBlobs: blobContents };\n\treturn pendingSnapshot;\n}\n\n/**\n * Converts a snapshot to snapshotInfo with its blob contents\n * to align detached container format with IPendingContainerState\n *\n * Note, this assumes the ISnapshot sequence number is defined. Otherwise an assert will be thrown\n * @param snapshot - ISnapshot\n */\nexport function convertSnapshotToSnapshotInfo(snapshot: ISnapshot): ISnapshotInfo {\n\tassert(\n\t\tsnapshot.sequenceNumber !== undefined,\n\t\t0x93a /* Snapshot sequence number is missing */,\n\t);\n\tconst snapshotBlobs: ISerializableBlobContents = {};\n\tfor (const [blobId, arrayBufferLike] of snapshot.blobContents.entries()) {\n\t\tsnapshotBlobs[blobId] = bufferToString(arrayBufferLike, \"utf8\");\n\t}\n\treturn {\n\t\tbaseSnapshot: snapshot.snapshotTree,\n\t\tsnapshotBlobs,\n\t\tsnapshotSequenceNumber: snapshot.sequenceNumber,\n\t};\n}\n\n/**\n * Converts a snapshot to snapshotInfo with its blob contents\n * to align detached container format with IPendingContainerState\n *\n * Note, this assumes the ISnapshot sequence number is defined. Otherwise an assert will be thrown\n * @param snapshot - ISnapshot\n */\nexport function convertSnapshotInfoToSnapshot(\n\tsnapshotInfo: ISnapshotInfo,\n\tsnapshotSequenceNumber: number,\n): ISnapshot {\n\tconst blobContents = new Map<string, ArrayBufferLike>();\n\tfor (const [blobId, serializedContent] of Object.entries(snapshotInfo.snapshotBlobs)) {\n\t\tblobContents.set(blobId, stringToBuffer(serializedContent, \"utf8\"));\n\t}\n\treturn {\n\t\tsnapshotTree: snapshotInfo.baseSnapshot,\n\t\tblobContents,\n\t\tops: [],\n\t\tsequenceNumber: snapshotSequenceNumber,\n\t\tlatestSequenceNumber: undefined,\n\t\tsnapshotFormatV: 1,\n\t};\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): SnapshotWithBlobs {\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): SnapshotWithBlobs => {\n\tassert(\n\t\tisCombinedAppAndProtocolSummary(detachedContainerSnapshot),\n\t\t0x8e6 /* 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] !== undefined) {\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: unknown,\n): error is DeltaStreamConnectionForbiddenError {\n\treturn (\n\t\ttypeof error === \"object\" &&\n\t\terror !== null &&\n\t\t(error as Partial<IFluidErrorBase>)?.errorType ===\n\t\t\tDriverErrorTypes.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\n/**\n * Parses the given string into {@link IPendingDetachedContainerState} format,\n * with validation (if invalid, throws a UsageError).\n * This is the inverse of the JSON.stringify call in {@link Container.serialize}\n */\nexport function getDetachedContainerStateFromSerializedContainer(\n\tserializedContainer: string,\n): IPendingDetachedContainerState {\n\tconst hasBlobsSummaryTree = \".hasAttachmentBlobs\";\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\tconst parsedContainerState = JSON.parse(serializedContainer);\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\tif (isPendingDetachedContainerState(parsedContainerState)) {\n\t\treturn parsedContainerState;\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t} else if (isCombinedAppAndProtocolSummary(parsedContainerState)) {\n\t\tconst { baseSnapshot, snapshotBlobs } =\n\t\t\tgetSnapshotTreeAndBlobsFromSerializedContainer(parsedContainerState);\n\t\tconst detachedContainerState: IPendingDetachedContainerState = {\n\t\t\tattached: false,\n\t\t\tbaseSnapshot,\n\t\t\tsnapshotBlobs,\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 * Blindly parses the given string into {@link IPendingContainerState} format.\n * This is the inverse of the JSON.stringify call in {@link SerializedStateManager.getPendingLocalState}\n */\nexport function getAttachedContainerStateFromSerializedContainer(\n\tserializedContainer: string | undefined,\n): IPendingContainerState | undefined {\n\treturn serializedContainer === undefined\n\t\t? undefined\n\t\t: (JSON.parse(serializedContainer) as IPendingContainerState);\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 */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const runSingle = <A extends any[], R>(\n\tfunc: (...args: A) => Promise<R>,\n): ((...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): Promise<R> => {\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\nexport async function getDocumentAttributes(\n\tstorage: Pick<IDocumentStorageService, \"readBlob\">,\n\ttree: ISnapshotTree | undefined,\n): Promise<IDocumentAttributes> {\n\tif (tree === undefined) {\n\t\treturn {\n\t\t\tminimumSequenceNumber: 0,\n\t\t\tsequenceNumber: 0,\n\t\t};\n\t}\n\n\t// Backward compatibility: old docs would have \".attributes\" instead of \"attributes\"\n\tconst attributesHash =\n\t\t\".protocol\" in tree.trees\n\t\t\t? tree.trees[\".protocol\"].blobs.attributes\n\t\t\t: tree.blobs[\".attributes\"];\n\n\tconst attributes = await readAndParse<IDocumentAttributes>(storage, attributesHash);\n\n\treturn attributes;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,cAAc,EACd,cAAc,EACd,uBAAuB,GACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC7F,OAAO,EAAqB,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EACN,gBAAgB,GAKhB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EA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;AACnB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tbufferToString,\n\tstringToBuffer,\n\tUint8ArrayToArrayBuffer,\n} from \"@fluid-internal/client-utils\";\nimport { assert, compareArrays, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { type ISummaryTree, SummaryType } from \"@fluidframework/driver-definitions\";\nimport {\n\tDriverErrorTypes,\n\ttype IDocumentAttributes,\n\ttype ISnapshotTree,\n\ttype IDocumentStorageService,\n\ttype ISnapshot,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\ttype CombinedAppAndProtocolSummary,\n\ttype DeltaStreamConnectionForbiddenError,\n\tisCombinedAppAndProtocolSummary,\n\treadAndParse,\n} from \"@fluidframework/driver-utils/internal\";\nimport {\n\tLoggingError,\n\tUsageError,\n\ttype IFluidErrorBase,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport { v4 as uuid } from \"uuid\";\n\nimport type { ISerializableBlobContents } from \"./containerStorageAdapter.js\";\nimport type {\n\tIPendingContainerState,\n\tIPendingDetachedContainerState,\n\tSerializedSnapshotInfo,\n\tSnapshotWithBlobs,\n} from \"./serializedStateManager.js\";\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 * @legacy @beta\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 * Undefined means load latest snapshot, otherwise it's version ID passed to IDocumentStorageService.getVersions()\n\t * to figure out what snapshot to use.\n\t */\n\tversion: string | 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 * @legacy @beta\n */\nexport function tryParseCompatibleResolvedUrl(url: string): IParsedUrl | undefined {\n\tconst parsed = new URL(url);\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? {\n\t\t\t\tid: match[1],\n\t\t\t\tpath: match[2],\n\t\t\t\tquery,\n\t\t\t\t// URLSearchParams returns null if the param is not provided.\n\t\t\t\tversion: parsed.searchParams.get(\"version\") ?? undefined,\n\t\t\t}\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 convertSummaryToISnapshot(\n\tsummary: ISummaryTree,\n\tblobContents = new Map<string, ArrayBuffer>(),\n): ISnapshot {\n\tconst snapshotTree: ISnapshotTree = {\n\t\tblobs: {},\n\t\ttrees: {},\n\t\tid: uuid(),\n\t\tunreferenced: summary.unreferenced,\n\t\tgroupId: summary.groupId,\n\t};\n\n\tfor (const [key, summaryObject] of Object.entries(summary.tree)) {\n\t\tswitch (summaryObject.type) {\n\t\t\tcase SummaryType.Tree: {\n\t\t\t\tconst innerSnapshot = convertSummaryToISnapshot(summaryObject, blobContents);\n\t\t\t\tsnapshotTree.trees[key] = innerSnapshot.snapshotTree;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SummaryType.Attachment: {\n\t\t\t\tsnapshotTree.blobs[key] = summaryObject.id;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SummaryType.Blob: {\n\t\t\t\tconst blobId = uuid();\n\t\t\t\tsnapshotTree.blobs[key] = blobId;\n\t\t\t\tblobContents.set(\n\t\t\t\t\tblobId,\n\t\t\t\t\tsummaryObject.content instanceof Uint8Array\n\t\t\t\t\t\t? Uint8ArrayToArrayBuffer(summaryObject.content)\n\t\t\t\t\t\t: stringToBuffer(summaryObject.content, \"utf8\"),\n\t\t\t\t);\n\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}\n\t\t\tdefault: {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n\t\t\t\tunreachableCase(summaryObject, `Unknown tree type ${(summaryObject as any).type}`);\n\t\t\t}\n\t\t}\n\t}\n\treturn {\n\t\tblobContents,\n\t\tlatestSequenceNumber: undefined,\n\t\tops: [],\n\t\tsequenceNumber: 0,\n\t\tsnapshotFormatV: 1,\n\t\tsnapshotTree,\n\t};\n}\n\n/**\n * Converts a snapshot to snapshotInfo with its blob contents\n * to align detached container format with IPendingContainerState\n *\n * Note, this assumes the ISnapshot sequence number is defined. Otherwise an assert will be thrown\n * @param snapshot - ISnapshot\n */\nexport function convertSnapshotToSnapshotInfo(snapshot: ISnapshot): SerializedSnapshotInfo {\n\tassert(\n\t\tsnapshot.sequenceNumber !== undefined,\n\t\t0x93a /* Snapshot sequence number is missing */,\n\t);\n\tconst snapshotBlobs: ISerializableBlobContents = {};\n\tfor (const [blobId, arrayBufferLike] of snapshot.blobContents.entries()) {\n\t\tsnapshotBlobs[blobId] = bufferToString(arrayBufferLike, \"utf8\");\n\t}\n\treturn {\n\t\tbaseSnapshot: snapshot.snapshotTree,\n\t\tsnapshotBlobs,\n\t\tsnapshotSequenceNumber: snapshot.sequenceNumber,\n\t};\n}\n\n/**\n * Converts a snapshot to snapshotInfo with its blob contents\n * to align detached container format with IPendingContainerState\n *\n * Note, this assumes the ISnapshot sequence number is defined. Otherwise an assert will be thrown\n * @param snapshot - ISnapshot\n */\nexport function convertSnapshotInfoToSnapshot(\n\tsnapshotInfo: SerializedSnapshotInfo,\n): ISnapshot {\n\tconst blobContents = new Map<string, ArrayBuffer>();\n\tfor (const [blobId, serializedContent] of Object.entries(snapshotInfo.snapshotBlobs)) {\n\t\tblobContents.set(blobId, stringToBuffer(serializedContent, \"utf8\"));\n\t}\n\treturn {\n\t\tsnapshotTree: snapshotInfo.baseSnapshot,\n\t\tblobContents,\n\t\tops: [],\n\t\tsequenceNumber: snapshotInfo.snapshotSequenceNumber,\n\t\tlatestSequenceNumber: undefined,\n\t\tsnapshotFormatV: 1,\n\t};\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 convertProtocolAndAppSummaryToISnapshot(\n\tprotocolSummaryTree: ISummaryTree,\n\tappSummaryTree: ISummaryTree,\n): ISnapshot {\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 = convertSummaryToISnapshot(combinedSummary);\n\treturn snapshotTreeWithBlobContents;\n}\n\nexport const getISnapshotFromSerializedContainer = (\n\tdetachedContainerSnapshot: ISummaryTree,\n): ISnapshot => {\n\tassert(\n\t\tisCombinedAppAndProtocolSummary(detachedContainerSnapshot),\n\t\t0x8e6 /* 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 = convertProtocolAndAppSummaryToISnapshot(\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] !== undefined) {\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: unknown,\n): error is DeltaStreamConnectionForbiddenError {\n\treturn (\n\t\ttypeof error === \"object\" &&\n\t\terror !== null &&\n\t\t(error as Partial<IFluidErrorBase>)?.errorType ===\n\t\t\tDriverErrorTypes.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/**\n * Converts an ISnapshot to a SnapshotWithBlobs, extracting and serializing its blob contents.\n * @param snapshot - The ISnapshot to convert.\n * @returns A SnapshotWithBlobs containing the base snapshot and serialized blob contents.\n */\nexport function convertISnapshotToSnapshotWithBlobs(snapshot: ISnapshot): SnapshotWithBlobs {\n\tconst snapshotBlobs: ISerializableBlobContents = {};\n\tfor (const [id, blob] of snapshot.blobContents.entries()) {\n\t\tsnapshotBlobs[id] = bufferToString(blob, \"utf8\");\n\t}\n\treturn {\n\t\tbaseSnapshot: snapshot.snapshotTree,\n\t\tsnapshotBlobs,\n\t};\n}\n\n/**\n * Parses the given string into {@link IPendingDetachedContainerState} format,\n * with validation (if invalid, throws a UsageError).\n * This is the inverse of the JSON.stringify call in {@link Container.serialize}\n */\nexport function getDetachedContainerStateFromSerializedContainer(\n\tserializedContainer: string,\n): IPendingDetachedContainerState {\n\tconst hasBlobsSummaryTree = \".hasAttachmentBlobs\";\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\tconst parsedContainerState = JSON.parse(serializedContainer);\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\tif (isPendingDetachedContainerState(parsedContainerState)) {\n\t\treturn parsedContainerState;\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t} else if (isCombinedAppAndProtocolSummary(parsedContainerState)) {\n\t\tconst snapshot = getISnapshotFromSerializedContainer(parsedContainerState);\n\t\tconst detachedContainerState: IPendingDetachedContainerState = {\n\t\t\tattached: false,\n\t\t\t...convertISnapshotToSnapshotWithBlobs(snapshot),\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 * Blindly parses the given string into {@link IPendingContainerState} format.\n * This is the inverse of the JSON.stringify call in {@link SerializedStateManager.getPendingLocalState}\n */\nexport function getAttachedContainerStateFromSerializedContainer(\n\tserializedContainer: string | undefined,\n): IPendingContainerState | undefined {\n\treturn serializedContainer === undefined\n\t\t? undefined\n\t\t: (JSON.parse(serializedContainer) as IPendingContainerState);\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 */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const runSingle = <A extends any[], R>(\n\tfunc: (...args: A) => Promise<R>,\n): ((...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): Promise<R> => {\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\nexport async function getDocumentAttributes(\n\tstorage: Pick<IDocumentStorageService, \"readBlob\">,\n\ttree: ISnapshotTree | undefined,\n): Promise<IDocumentAttributes> {\n\tif (tree === undefined) {\n\t\treturn {\n\t\t\tminimumSequenceNumber: 0,\n\t\t\tsequenceNumber: 0,\n\t\t};\n\t}\n\n\t// Backward compatibility: old docs would have \".attributes\" instead of \"attributes\"\n\tconst attributesHash =\n\t\t\".protocol\" in tree.trees\n\t\t\t? tree.trees[\".protocol\"].blobs.attributes\n\t\t\t: tree.blobs[\".attributes\"];\n\n\tconst attributes = await readAndParse<IDocumentAttributes>(storage, attributesHash);\n\n\treturn attributes;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/container-loader",
|
|
3
|
-
"version": "2.63.0-
|
|
3
|
+
"version": "2.63.0-359962",
|
|
4
4
|
"description": "Fluid container loader",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -129,13 +129,13 @@
|
|
|
129
129
|
"temp-directory": "nyc/.nyc_output"
|
|
130
130
|
},
|
|
131
131
|
"dependencies": {
|
|
132
|
-
"@fluid-internal/client-utils": "2.63.0-
|
|
133
|
-
"@fluidframework/container-definitions": "2.63.0-
|
|
134
|
-
"@fluidframework/core-interfaces": "2.63.0-
|
|
135
|
-
"@fluidframework/core-utils": "2.63.0-
|
|
136
|
-
"@fluidframework/driver-definitions": "2.63.0-
|
|
137
|
-
"@fluidframework/driver-utils": "2.63.0-
|
|
138
|
-
"@fluidframework/telemetry-utils": "2.63.0-
|
|
132
|
+
"@fluid-internal/client-utils": "2.63.0-359962",
|
|
133
|
+
"@fluidframework/container-definitions": "2.63.0-359962",
|
|
134
|
+
"@fluidframework/core-interfaces": "2.63.0-359962",
|
|
135
|
+
"@fluidframework/core-utils": "2.63.0-359962",
|
|
136
|
+
"@fluidframework/driver-definitions": "2.63.0-359962",
|
|
137
|
+
"@fluidframework/driver-utils": "2.63.0-359962",
|
|
138
|
+
"@fluidframework/telemetry-utils": "2.63.0-359962",
|
|
139
139
|
"@types/events_pkg": "npm:@types/events@^3.0.0",
|
|
140
140
|
"@ungap/structured-clone": "^1.2.0",
|
|
141
141
|
"debug": "^4.3.4",
|
|
@@ -146,9 +146,9 @@
|
|
|
146
146
|
"devDependencies": {
|
|
147
147
|
"@arethetypeswrong/cli": "^0.17.1",
|
|
148
148
|
"@biomejs/biome": "~1.9.3",
|
|
149
|
-
"@fluid-internal/client-utils": "2.63.0-
|
|
150
|
-
"@fluid-internal/mocha-test-setup": "2.63.0-
|
|
151
|
-
"@fluid-private/test-loader-utils": "2.63.0-
|
|
149
|
+
"@fluid-internal/client-utils": "2.63.0-359962",
|
|
150
|
+
"@fluid-internal/mocha-test-setup": "2.63.0-359962",
|
|
151
|
+
"@fluid-private/test-loader-utils": "2.63.0-359962",
|
|
152
152
|
"@fluid-tools/build-cli": "^0.58.3",
|
|
153
153
|
"@fluidframework/build-common": "^2.0.3",
|
|
154
154
|
"@fluidframework/build-tools": "^0.58.3",
|
package/src/attachment.ts
CHANGED
|
@@ -6,12 +6,14 @@
|
|
|
6
6
|
import { AttachState } from "@fluidframework/container-definitions";
|
|
7
7
|
import { assert } from "@fluidframework/core-utils/internal";
|
|
8
8
|
import type { ISummaryTree } from "@fluidframework/driver-definitions";
|
|
9
|
-
import type {
|
|
9
|
+
import type {
|
|
10
|
+
IDocumentStorageService,
|
|
11
|
+
ISnapshot,
|
|
12
|
+
} from "@fluidframework/driver-definitions/internal";
|
|
10
13
|
import type { CombinedAppAndProtocolSummary } from "@fluidframework/driver-utils/internal";
|
|
11
14
|
|
|
12
15
|
import type { MemoryDetachedBlobStorage } from "./memoryBlobStorage.js";
|
|
13
|
-
import
|
|
14
|
-
import { getSnapshotTreeAndBlobsFromSerializedContainer } from "./utils.js";
|
|
16
|
+
import { getISnapshotFromSerializedContainer } from "./utils.js";
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* The default state a newly created detached container will have.
|
|
@@ -124,11 +126,6 @@ export interface AttachProcessProps {
|
|
|
124
126
|
readonly createAttachmentSummary: (
|
|
125
127
|
redirectTable?: Map<string, string>,
|
|
126
128
|
) => CombinedAppAndProtocolSummary;
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Whether offline load is enabled or not.
|
|
130
|
-
*/
|
|
131
|
-
readonly offlineLoadEnabled: boolean;
|
|
132
129
|
}
|
|
133
130
|
|
|
134
131
|
/**
|
|
@@ -144,9 +141,8 @@ export const runRetriableAttachProcess = async ({
|
|
|
144
141
|
createOrGetStorageService,
|
|
145
142
|
setAttachmentData,
|
|
146
143
|
createAttachmentSummary,
|
|
147
|
-
offlineLoadEnabled,
|
|
148
144
|
initialAttachmentData,
|
|
149
|
-
}: AttachProcessProps): Promise<
|
|
145
|
+
}: AttachProcessProps): Promise<ISnapshot> => {
|
|
150
146
|
let currentData: AttachmentData = initialAttachmentData;
|
|
151
147
|
|
|
152
148
|
if (currentData.blobs === undefined) {
|
|
@@ -214,9 +210,7 @@ export const runRetriableAttachProcess = async ({
|
|
|
214
210
|
});
|
|
215
211
|
}
|
|
216
212
|
|
|
217
|
-
const snapshot
|
|
218
|
-
? getSnapshotTreeAndBlobsFromSerializedContainer(currentData.summary)
|
|
219
|
-
: undefined;
|
|
213
|
+
const snapshot = getISnapshotFromSerializedContainer(currentData.summary);
|
|
220
214
|
|
|
221
215
|
setAttachmentData(
|
|
222
216
|
(currentData = {
|
package/src/container.ts
CHANGED
|
@@ -159,8 +159,9 @@ import {
|
|
|
159
159
|
getDetachedContainerStateFromSerializedContainer,
|
|
160
160
|
getDocumentAttributes,
|
|
161
161
|
getProtocolSnapshotTree,
|
|
162
|
-
|
|
162
|
+
getISnapshotFromSerializedContainer,
|
|
163
163
|
runSingle,
|
|
164
|
+
convertISnapshotToSnapshotWithBlobs,
|
|
164
165
|
} from "./utils.js";
|
|
165
166
|
|
|
166
167
|
const detachedContainerRefSeqNumber = 0;
|
|
@@ -1022,9 +1023,8 @@ export class Container
|
|
|
1022
1023
|
this.isInteractiveClient &&
|
|
1023
1024
|
(this.mc.config.getBoolean("Fluid.Container.enableOfflineLoad") ??
|
|
1024
1025
|
this.mc.config.getBoolean("Fluid.Container.enableOfflineFull") ??
|
|
1025
|
-
options.enableOfflineLoad
|
|
1026
|
+
options.enableOfflineLoad !== false);
|
|
1026
1027
|
this.serializedStateManager = new SerializedStateManager(
|
|
1027
|
-
pendingLocalState,
|
|
1028
1028
|
this.subLogger,
|
|
1029
1029
|
this.storageAdapter,
|
|
1030
1030
|
offlineLoadEnabled,
|
|
@@ -1127,6 +1127,7 @@ export class Container
|
|
|
1127
1127
|
this._protocolHandler?.close();
|
|
1128
1128
|
|
|
1129
1129
|
this.connectionStateHandler.dispose();
|
|
1130
|
+
this.serializedStateManager.dispose();
|
|
1130
1131
|
} catch (newError) {
|
|
1131
1132
|
this.mc.logger.sendErrorEvent({ eventName: "ContainerCloseException" }, newError);
|
|
1132
1133
|
}
|
|
@@ -1173,6 +1174,7 @@ export class Container
|
|
|
1173
1174
|
this._protocolHandler?.close();
|
|
1174
1175
|
|
|
1175
1176
|
this.connectionStateHandler.dispose();
|
|
1177
|
+
this.serializedStateManager.dispose();
|
|
1176
1178
|
|
|
1177
1179
|
const maybeError = error === undefined ? undefined : new Error(error.message);
|
|
1178
1180
|
this._runtime?.dispose(maybeError);
|
|
@@ -1251,16 +1253,14 @@ export class Container
|
|
|
1251
1253
|
this.captureProtocolSummary(),
|
|
1252
1254
|
);
|
|
1253
1255
|
|
|
1254
|
-
const
|
|
1255
|
-
getSnapshotTreeAndBlobsFromSerializedContainer(combinedSummary);
|
|
1256
|
+
const snapshot = getISnapshotFromSerializedContainer(combinedSummary);
|
|
1256
1257
|
const pendingRuntimeState =
|
|
1257
1258
|
attachingData === undefined ? undefined : this.runtime.getPendingLocalState();
|
|
1258
1259
|
assert(!isPromiseLike(pendingRuntimeState), 0x8e3 /* should not be a promise */);
|
|
1259
1260
|
|
|
1260
1261
|
const detachedContainerState: IPendingDetachedContainerState = {
|
|
1261
1262
|
attached: false,
|
|
1262
|
-
|
|
1263
|
-
snapshotBlobs,
|
|
1263
|
+
...convertISnapshotToSnapshotWithBlobs(snapshot),
|
|
1264
1264
|
pendingRuntimeState,
|
|
1265
1265
|
hasAttachmentBlobs:
|
|
1266
1266
|
this.detachedBlobStorage !== undefined && this.detachedBlobStorage.size > 0,
|
|
@@ -1352,7 +1352,6 @@ export class Container
|
|
|
1352
1352
|
|
|
1353
1353
|
let attachP = runRetriableAttachProcess({
|
|
1354
1354
|
initialAttachmentData: this.attachmentData,
|
|
1355
|
-
offlineLoadEnabled: this.serializedStateManager.offlineLoadEnabled,
|
|
1356
1355
|
detachedBlobStorage: this.detachedBlobStorage,
|
|
1357
1356
|
setAttachmentData,
|
|
1358
1357
|
createAttachmentSummary,
|
|
@@ -1669,8 +1668,11 @@ export class Container
|
|
|
1669
1668
|
timings.phase2 = performanceNow();
|
|
1670
1669
|
|
|
1671
1670
|
// Fetch specified snapshot.
|
|
1672
|
-
const {
|
|
1673
|
-
|
|
1671
|
+
const {
|
|
1672
|
+
snapshot: baseSnapshot,
|
|
1673
|
+
version,
|
|
1674
|
+
attributes,
|
|
1675
|
+
} = await this.serializedStateManager.fetchSnapshot(specifiedVersion, pendingLocalState);
|
|
1674
1676
|
const baseSnapshotTree: ISnapshotTree | undefined = getSnapshotTree(baseSnapshot);
|
|
1675
1677
|
this._loadedFromVersion = version;
|
|
1676
1678
|
|
|
@@ -31,7 +31,7 @@ import { ProtocolTreeStorageService } from "./protocolTreeDocumentStorageService
|
|
|
31
31
|
import { RetriableDocumentStorageService } from "./retriableDocumentStorageService.js";
|
|
32
32
|
import type {
|
|
33
33
|
ISerializedStateManagerDocumentStorageService,
|
|
34
|
-
|
|
34
|
+
SerializedSnapshotInfo,
|
|
35
35
|
} from "./serializedStateManager.js";
|
|
36
36
|
import { convertSnapshotInfoToSnapshot } from "./utils.js";
|
|
37
37
|
|
|
@@ -88,7 +88,9 @@ export class ContainerStorageAdapter
|
|
|
88
88
|
* ArrayBufferLikes or utf8 encoded strings, containing blobs from a snapshot
|
|
89
89
|
*/
|
|
90
90
|
private readonly blobContents: { [id: string]: ArrayBufferLike | string } = {},
|
|
91
|
-
private loadingGroupIdSnapshotsFromPendingState:
|
|
91
|
+
private loadingGroupIdSnapshotsFromPendingState:
|
|
92
|
+
| Record<string, SerializedSnapshotInfo>
|
|
93
|
+
| undefined,
|
|
92
94
|
private readonly addProtocolSummaryIfMissing: (summaryTree: ISummaryTree) => ISummaryTree,
|
|
93
95
|
private readonly enableSummarizeProtocolTree: boolean | undefined,
|
|
94
96
|
) {
|
|
@@ -184,10 +186,7 @@ export class ContainerStorageAdapter
|
|
|
184
186
|
const localSnapshot =
|
|
185
187
|
this.loadingGroupIdSnapshotsFromPendingState[snapshotFetchOptions.loadingGroupIds[0]];
|
|
186
188
|
assert(localSnapshot !== undefined, 0x970 /* Local snapshot must be present */);
|
|
187
|
-
snapshot = convertSnapshotInfoToSnapshot(
|
|
188
|
-
localSnapshot,
|
|
189
|
-
localSnapshot.snapshotSequenceNumber,
|
|
190
|
-
);
|
|
189
|
+
snapshot = convertSnapshotInfoToSnapshot(localSnapshot);
|
|
191
190
|
} else {
|
|
192
191
|
if (this._storageService.getSnapshot === undefined) {
|
|
193
192
|
throw new UsageError(
|
|
@@ -21,7 +21,7 @@ import type {
|
|
|
21
21
|
IUrlResolver,
|
|
22
22
|
} from "@fluidframework/driver-definitions/internal";
|
|
23
23
|
|
|
24
|
-
import {
|
|
24
|
+
import { createFrozenDocumentServiceFactory } from "./frozenServices.js";
|
|
25
25
|
import { Loader } from "./loader.js";
|
|
26
26
|
import type { ProtocolHandlerBuilder } from "./protocol.js";
|
|
27
27
|
|
|
@@ -197,6 +197,6 @@ export async function loadFrozenContainerFromPendingState(
|
|
|
197
197
|
): Promise<IContainer> {
|
|
198
198
|
return loadExistingContainer({
|
|
199
199
|
...props,
|
|
200
|
-
documentServiceFactory:
|
|
200
|
+
documentServiceFactory: createFrozenDocumentServiceFactory(props.documentServiceFactory),
|
|
201
201
|
});
|
|
202
202
|
}
|
package/src/frozenServices.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { TypedEventEmitter } from "@fluid-internal/client-utils";
|
|
7
7
|
import type { IDisposable } from "@fluidframework/core-interfaces";
|
|
8
|
+
import { isPromiseLike } from "@fluidframework/core-utils/internal";
|
|
8
9
|
import {
|
|
9
10
|
ScopeType,
|
|
10
11
|
type ConnectionMode,
|
|
@@ -28,13 +29,38 @@ import {
|
|
|
28
29
|
|
|
29
30
|
import type { IConnectionStateChangeReason } from "./contracts.js";
|
|
30
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Creation of a FrozenDocumentServiceFactory which wraps an existing
|
|
34
|
+
* DocumentServiceFactory to provide a storage-only document service.
|
|
35
|
+
*
|
|
36
|
+
* @param documentServiceFactory - The underlying DocumentServiceFactory to wrap.
|
|
37
|
+
* @returns A FrozenDocumentServiceFactory
|
|
38
|
+
* @legacy @alpha
|
|
39
|
+
*/
|
|
40
|
+
export function createFrozenDocumentServiceFactory(
|
|
41
|
+
factory?: IDocumentServiceFactory | Promise<IDocumentServiceFactory>,
|
|
42
|
+
): IDocumentServiceFactory {
|
|
43
|
+
// Sync path
|
|
44
|
+
return factory instanceof FrozenDocumentServiceFactory
|
|
45
|
+
? factory
|
|
46
|
+
: new FrozenDocumentServiceFactory(factory);
|
|
47
|
+
}
|
|
48
|
+
|
|
31
49
|
export class FrozenDocumentServiceFactory implements IDocumentServiceFactory {
|
|
32
|
-
constructor(
|
|
50
|
+
constructor(
|
|
51
|
+
private readonly documentServiceFactory?:
|
|
52
|
+
| IDocumentServiceFactory
|
|
53
|
+
| Promise<IDocumentServiceFactory>,
|
|
54
|
+
) {}
|
|
33
55
|
|
|
34
56
|
async createDocumentService(resolvedUrl: IResolvedUrl): Promise<IDocumentService> {
|
|
57
|
+
let factory = this.documentServiceFactory;
|
|
58
|
+
if (isPromiseLike(factory)) {
|
|
59
|
+
factory = await this.documentServiceFactory;
|
|
60
|
+
}
|
|
35
61
|
return new FrozenDocumentService(
|
|
36
62
|
resolvedUrl,
|
|
37
|
-
await
|
|
63
|
+
await factory?.createDocumentService(resolvedUrl),
|
|
38
64
|
);
|
|
39
65
|
}
|
|
40
66
|
async createContainer(): Promise<IDocumentService> {
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
export { ConnectionState } from "./connectionState.js";
|
|
7
7
|
export { type ContainerAlpha, waitContainerToCatchUp, asLegacyAlpha } from "./container.js";
|
|
8
|
+
export { createFrozenDocumentServiceFactory } from "./frozenServices.js";
|
|
8
9
|
export {
|
|
9
10
|
createDetachedContainer,
|
|
10
11
|
loadExistingContainer,
|
package/src/packageVersion.ts
CHANGED