@fluidframework/odsp-driver 2.0.0-internal.2.2.1 → 2.0.0-internal.2.3.0
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/.eslintrc.js +1 -1
- package/dist/WriteBufferUtils.d.ts.map +1 -1
- package/dist/WriteBufferUtils.js +0 -1
- package/dist/WriteBufferUtils.js.map +1 -1
- package/dist/contractsPublic.d.ts.map +1 -1
- package/dist/contractsPublic.js.map +1 -1
- package/dist/createFile.d.ts +2 -6
- package/dist/createFile.d.ts.map +1 -1
- package/dist/createFile.js +13 -125
- package/dist/createFile.js.map +1 -1
- package/dist/createNewUtils.d.ts +16 -0
- package/dist/createNewUtils.d.ts.map +1 -1
- package/dist/createNewUtils.js +131 -1
- package/dist/createNewUtils.js.map +1 -1
- package/dist/fetchSnapshot.js +1 -1
- package/dist/fetchSnapshot.js.map +1 -1
- package/dist/localOdspDriver/localOdspDocumentServiceFactory.d.ts.map +1 -1
- package/dist/localOdspDriver/localOdspDocumentServiceFactory.js +1 -1
- package/dist/localOdspDriver/localOdspDocumentServiceFactory.js.map +1 -1
- package/dist/odspDelayLoadedDeltaStream.d.ts +75 -0
- package/dist/odspDelayLoadedDeltaStream.d.ts.map +1 -0
- package/dist/odspDelayLoadedDeltaStream.js +259 -0
- package/dist/odspDelayLoadedDeltaStream.js.map +1 -0
- package/dist/odspDocumentDeltaConnection.d.ts +1 -3
- package/dist/odspDocumentDeltaConnection.d.ts.map +1 -1
- package/dist/odspDocumentDeltaConnection.js +6 -6
- package/dist/odspDocumentDeltaConnection.js.map +1 -1
- package/dist/odspDocumentService.d.ts +10 -25
- package/dist/odspDocumentService.d.ts.map +1 -1
- package/dist/odspDocumentService.js +71 -204
- package/dist/odspDocumentService.js.map +1 -1
- package/dist/odspDocumentServiceFactory.d.ts.map +1 -1
- package/dist/odspDocumentServiceFactory.js +1 -2
- package/dist/odspDocumentServiceFactory.js.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.d.ts +1 -3
- package/dist/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.js +3 -3
- package/dist/odspDocumentServiceFactoryCore.js.map +1 -1
- package/dist/odspDocumentServiceFactoryWithCodeSplit.d.ts +4 -0
- package/dist/odspDocumentServiceFactoryWithCodeSplit.d.ts.map +1 -1
- package/dist/odspDocumentServiceFactoryWithCodeSplit.js +5 -20
- package/dist/odspDocumentServiceFactoryWithCodeSplit.js.map +1 -1
- package/dist/odspDocumentStorageManager.d.ts.map +1 -1
- package/dist/odspDocumentStorageManager.js +0 -2
- package/dist/odspDocumentStorageManager.js.map +1 -1
- package/dist/odspDocumentStorageServiceBase.d.ts.map +1 -1
- package/dist/odspDocumentStorageServiceBase.js +0 -2
- package/dist/odspDocumentStorageServiceBase.js.map +1 -1
- package/dist/odspSummaryUploadManager.d.ts.map +1 -1
- package/dist/odspSummaryUploadManager.js +0 -2
- package/dist/odspSummaryUploadManager.js.map +1 -1
- package/dist/odspUtils.d.ts +10 -1
- package/dist/odspUtils.d.ts.map +1 -1
- package/dist/odspUtils.js +5 -1
- package/dist/odspUtils.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/zipItDataRepresentationUtils.d.ts.map +1 -1
- package/dist/zipItDataRepresentationUtils.js +0 -1
- package/dist/zipItDataRepresentationUtils.js.map +1 -1
- package/lib/WriteBufferUtils.d.ts.map +1 -1
- package/lib/WriteBufferUtils.js +0 -1
- package/lib/WriteBufferUtils.js.map +1 -1
- package/lib/contractsPublic.d.ts.map +1 -1
- package/lib/contractsPublic.js.map +1 -1
- package/lib/createFile.d.ts +2 -6
- package/lib/createFile.d.ts.map +1 -1
- package/lib/createFile.js +15 -126
- package/lib/createFile.js.map +1 -1
- package/lib/createNewUtils.d.ts +16 -0
- package/lib/createNewUtils.d.ts.map +1 -1
- package/lib/createNewUtils.js +129 -1
- package/lib/createNewUtils.js.map +1 -1
- package/lib/fetchSnapshot.js +1 -1
- package/lib/fetchSnapshot.js.map +1 -1
- package/lib/localOdspDriver/localOdspDocumentServiceFactory.d.ts.map +1 -1
- package/lib/localOdspDriver/localOdspDocumentServiceFactory.js +1 -1
- package/lib/localOdspDriver/localOdspDocumentServiceFactory.js.map +1 -1
- package/lib/odspDelayLoadedDeltaStream.d.ts +75 -0
- package/lib/odspDelayLoadedDeltaStream.d.ts.map +1 -0
- package/lib/odspDelayLoadedDeltaStream.js +255 -0
- package/lib/odspDelayLoadedDeltaStream.js.map +1 -0
- package/lib/odspDocumentDeltaConnection.d.ts +1 -3
- package/lib/odspDocumentDeltaConnection.d.ts.map +1 -1
- package/lib/odspDocumentDeltaConnection.js +6 -6
- package/lib/odspDocumentDeltaConnection.js.map +1 -1
- package/lib/odspDocumentService.d.ts +10 -25
- package/lib/odspDocumentService.d.ts.map +1 -1
- package/lib/odspDocumentService.js +56 -207
- package/lib/odspDocumentService.js.map +1 -1
- package/lib/odspDocumentServiceFactory.d.ts.map +1 -1
- package/lib/odspDocumentServiceFactory.js +1 -2
- package/lib/odspDocumentServiceFactory.js.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.d.ts +1 -3
- package/lib/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.js +3 -3
- package/lib/odspDocumentServiceFactoryCore.js.map +1 -1
- package/lib/odspDocumentServiceFactoryWithCodeSplit.d.ts +4 -0
- package/lib/odspDocumentServiceFactoryWithCodeSplit.d.ts.map +1 -1
- package/lib/odspDocumentServiceFactoryWithCodeSplit.js +5 -1
- package/lib/odspDocumentServiceFactoryWithCodeSplit.js.map +1 -1
- package/lib/odspDocumentStorageManager.d.ts.map +1 -1
- package/lib/odspDocumentStorageManager.js +0 -2
- package/lib/odspDocumentStorageManager.js.map +1 -1
- package/lib/odspDocumentStorageServiceBase.d.ts.map +1 -1
- package/lib/odspDocumentStorageServiceBase.js +0 -2
- package/lib/odspDocumentStorageServiceBase.js.map +1 -1
- package/lib/odspSummaryUploadManager.d.ts.map +1 -1
- package/lib/odspSummaryUploadManager.js +0 -2
- package/lib/odspSummaryUploadManager.js.map +1 -1
- package/lib/odspUtils.d.ts +10 -1
- package/lib/odspUtils.d.ts.map +1 -1
- package/lib/odspUtils.js +3 -0
- package/lib/odspUtils.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/zipItDataRepresentationUtils.d.ts.map +1 -1
- package/lib/zipItDataRepresentationUtils.js +0 -1
- package/lib/zipItDataRepresentationUtils.js.map +1 -1
- package/package.json +13 -12
- package/src/WriteBufferUtils.ts +0 -1
- package/src/contractsPublic.ts +0 -1
- package/src/createFile.ts +23 -168
- package/src/createNewUtils.ts +188 -2
- package/src/fetchSnapshot.ts +1 -1
- package/src/localOdspDriver/localOdspDocumentServiceFactory.ts +0 -1
- package/src/odspDelayLoadedDeltaStream.ts +359 -0
- package/src/odspDocumentDeltaConnection.ts +4 -7
- package/src/odspDocumentService.ts +63 -283
- package/src/odspDocumentServiceFactory.ts +0 -2
- package/src/odspDocumentServiceFactoryCore.ts +1 -3
- package/src/odspDocumentServiceFactoryWithCodeSplit.ts +4 -1
- package/src/odspDocumentStorageManager.ts +0 -4
- package/src/odspDocumentStorageServiceBase.ts +0 -3
- package/src/odspSummaryUploadManager.ts +0 -4
- package/src/odspUtils.ts +16 -1
- package/src/packageVersion.ts +1 -1
- package/src/zipItDataRepresentationUtils.ts +0 -1
- package/dist/getSocketIo.d.ts +0 -11
- package/dist/getSocketIo.d.ts.map +0 -1
- package/dist/getSocketIo.js +0 -20
- package/dist/getSocketIo.js.map +0 -1
- package/lib/getSocketIo.d.ts +0 -11
- package/lib/getSocketIo.d.ts.map +0 -1
- package/lib/getSocketIo.js +0 -13
- package/lib/getSocketIo.js.map +0 -1
- package/src/getSocketIo.ts +0 -14
package/src/createFile.ts
CHANGED
|
@@ -3,29 +3,23 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { getGitType } from "@fluidframework/protocol-base";
|
|
10
|
-
import { SummaryType, ISummaryTree, ISummaryBlob } from "@fluidframework/protocol-definitions";
|
|
6
|
+
import { assert } from "@fluidframework/common-utils";
|
|
7
|
+
import { NonRetryableError } from "@fluidframework/driver-utils";
|
|
8
|
+
import { ISummaryTree } from "@fluidframework/protocol-definitions";
|
|
11
9
|
import { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
12
10
|
import { PerformanceEvent } from "@fluidframework/telemetry-utils";
|
|
13
11
|
import {
|
|
14
|
-
IFileEntry,
|
|
15
12
|
InstrumentedStorageTokenFetcher,
|
|
16
13
|
IOdspResolvedUrl,
|
|
17
14
|
OdspErrorType,
|
|
18
15
|
ShareLinkInfoType,
|
|
19
16
|
ISharingLinkKind,
|
|
20
17
|
ShareLinkTypes,
|
|
18
|
+
IFileEntry,
|
|
21
19
|
} from "@fluidframework/odsp-driver-definitions";
|
|
22
20
|
import { DriverErrorType } from "@fluidframework/driver-definitions";
|
|
23
21
|
import {
|
|
24
|
-
IOdspSummaryTree,
|
|
25
|
-
OdspSummaryTreeValue,
|
|
26
|
-
OdspSummaryTreeEntry,
|
|
27
22
|
ICreateFileResponse,
|
|
28
|
-
IOdspSummaryPayload,
|
|
29
23
|
} from "./contracts";
|
|
30
24
|
import { getUrlAndHeadersWithAuth } from "./getUrlAndHeadersWithAuth";
|
|
31
25
|
import {
|
|
@@ -33,15 +27,14 @@ import {
|
|
|
33
27
|
createCacheSnapshotKey,
|
|
34
28
|
getWithRetryForTokenRefresh,
|
|
35
29
|
INewFileInfo,
|
|
36
|
-
getOrigin
|
|
37
|
-
maxUmpPostBodySize,
|
|
30
|
+
getOrigin
|
|
38
31
|
} from "./odspUtils";
|
|
39
32
|
import { ISnapshotContents } from "./odspPublicUtils";
|
|
40
33
|
import { createOdspUrl } from "./createOdspUrl";
|
|
41
34
|
import { getApiRoot } from "./odspUrlHelper";
|
|
42
35
|
import { EpochTracker } from "./epochTracker";
|
|
43
36
|
import { OdspDriverUrlResolver } from "./odspDriverUrlResolver";
|
|
44
|
-
import { convertCreateNewSummaryTreeToTreeAndBlobs } from "./createNewUtils";
|
|
37
|
+
import { convertCreateNewSummaryTreeToTreeAndBlobs, convertSummaryIntoContainerSnapshot, createNewFluidContainerCore } from "./createNewUtils";
|
|
45
38
|
import { runWithRetry } from "./retryUtils";
|
|
46
39
|
import { pkgVersion as driverVersion } from "./packageVersion";
|
|
47
40
|
import { ClpCompliantAppHeader } from "./contractsPublic";
|
|
@@ -66,7 +59,7 @@ export async function createNewFluidFile(
|
|
|
66
59
|
forceAccessTokenViaAuthorizationHeader: boolean,
|
|
67
60
|
isClpCompliantApp?: boolean,
|
|
68
61
|
enableSingleRequestForShareLinkWithCreate?: boolean,
|
|
69
|
-
enableShareLinkWithCreate?: boolean
|
|
62
|
+
enableShareLinkWithCreate?: boolean
|
|
70
63
|
): Promise<IOdspResolvedUrl> {
|
|
71
64
|
// Check for valid filename before the request to create file is actually made.
|
|
72
65
|
if (isInvalidFileName(newFileInfo.filename)) {
|
|
@@ -255,160 +248,22 @@ export async function createNewFluidFileFromSummary(
|
|
|
255
248
|
const initialUrl =
|
|
256
249
|
`${baseUrl}:/opStream/snapshots/snapshot${createShareLinkParam ? `?${createShareLinkParam}` : ""}`;
|
|
257
250
|
|
|
258
|
-
return
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
postBody += `Content-Type: application/json\r\n`;
|
|
274
|
-
postBody += `_post: 1\r\n`;
|
|
275
|
-
postBody += `\r\n${snapshotBody}\r\n`;
|
|
276
|
-
postBody += `\r\n--${formBoundary}--`;
|
|
277
|
-
|
|
278
|
-
if (postBody.length <= maxUmpPostBodySize) {
|
|
279
|
-
const urlObj = new URL(initialUrl);
|
|
280
|
-
urlObj.searchParams.set("ump", "1");
|
|
281
|
-
url = urlObj.href;
|
|
282
|
-
headers = {
|
|
283
|
-
"Content-Type": `multipart/form-data;boundary=${formBoundary}`,
|
|
284
|
-
};
|
|
285
|
-
addInBody = true;
|
|
286
|
-
} else {
|
|
287
|
-
const parts = getUrlAndHeadersWithAuth(
|
|
288
|
-
initialUrl, storageToken, forceAccessTokenViaAuthorizationHeader);
|
|
289
|
-
url = parts.url;
|
|
290
|
-
headers = {
|
|
291
|
-
...parts.headers,
|
|
292
|
-
"Content-Type": "application/json",
|
|
293
|
-
};
|
|
294
|
-
postBody = snapshotBody;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const fetchResponse = await runWithRetry(
|
|
298
|
-
async () => epochTracker.fetchAndParseAsJSON<ICreateFileResponse>(
|
|
299
|
-
url,
|
|
300
|
-
{
|
|
301
|
-
body: postBody,
|
|
302
|
-
headers,
|
|
303
|
-
method: "POST",
|
|
304
|
-
},
|
|
305
|
-
"createFile",
|
|
306
|
-
addInBody,
|
|
307
|
-
),
|
|
308
|
-
"createFile",
|
|
309
|
-
logger,
|
|
310
|
-
);
|
|
311
|
-
|
|
312
|
-
const content = fetchResponse.content;
|
|
313
|
-
if (!content || !content.itemId) {
|
|
314
|
-
throw new NonRetryableError(
|
|
315
|
-
"ODSP CreateFile call returned no item ID",
|
|
316
|
-
DriverErrorType.incorrectServerResponse,
|
|
317
|
-
{ driverVersion });
|
|
318
|
-
}
|
|
319
|
-
event.end({
|
|
320
|
-
headers: Object.keys(headers).length !== 0 ? true : undefined,
|
|
321
|
-
attempts: options.refresh ? 2 : 1,
|
|
322
|
-
...fetchResponse.propsToLog,
|
|
323
|
-
});
|
|
324
|
-
return content;
|
|
325
|
-
},
|
|
326
|
-
);
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
function convertSummaryIntoContainerSnapshot(createNewSummary: ISummaryTree) {
|
|
331
|
-
const appSummary = createNewSummary.tree[".app"] as ISummaryTree;
|
|
332
|
-
const protocolSummary = createNewSummary.tree[".protocol"] as ISummaryTree;
|
|
333
|
-
if (!(appSummary && protocolSummary)) {
|
|
334
|
-
throw new Error("App and protocol summary required for create new path!!");
|
|
335
|
-
}
|
|
336
|
-
const documentAttributes = getDocAttributesFromProtocolSummary(protocolSummary);
|
|
337
|
-
const attributesSummaryBlob: ISummaryBlob = {
|
|
338
|
-
type: SummaryType.Blob,
|
|
339
|
-
content: JSON.stringify(documentAttributes),
|
|
340
|
-
};
|
|
341
|
-
protocolSummary.tree.attributes = attributesSummaryBlob;
|
|
342
|
-
const convertedCreateNewSummary: ISummaryTree = {
|
|
343
|
-
type: SummaryType.Tree,
|
|
344
|
-
tree: {
|
|
345
|
-
".protocol": protocolSummary,
|
|
346
|
-
".app": appSummary,
|
|
347
|
-
},
|
|
348
|
-
};
|
|
349
|
-
const snapshotTree = convertSummaryToSnapshotTreeForCreateNew(convertedCreateNewSummary);
|
|
350
|
-
const snapshot: IOdspSummaryPayload = {
|
|
351
|
-
entries: snapshotTree.entries ?? [],
|
|
352
|
-
message: "app",
|
|
353
|
-
sequenceNumber: documentAttributes.sequenceNumber,
|
|
354
|
-
type: "container",
|
|
355
|
-
};
|
|
356
|
-
return snapshot;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* Converts a summary tree to ODSP tree
|
|
361
|
-
*/
|
|
362
|
-
export function convertSummaryToSnapshotTreeForCreateNew(summary: ISummaryTree): IOdspSummaryTree {
|
|
363
|
-
const snapshotTree: IOdspSummaryTree = {
|
|
364
|
-
type: "tree",
|
|
365
|
-
entries: [],
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
const keys = Object.keys(summary.tree);
|
|
369
|
-
for (const key of keys) {
|
|
370
|
-
const summaryObject = summary.tree[key];
|
|
371
|
-
|
|
372
|
-
let value: OdspSummaryTreeValue;
|
|
373
|
-
// Tracks if an entry is unreferenced. Currently, only tree entries can be marked as unreferenced. If the
|
|
374
|
-
// property is not present, the tree entry is considered referenced. If the property is present and is true,
|
|
375
|
-
// the tree entry is considered unreferenced.
|
|
376
|
-
let unreferenced: true | undefined;
|
|
377
|
-
|
|
378
|
-
switch (summaryObject.type) {
|
|
379
|
-
case SummaryType.Tree: {
|
|
380
|
-
value = convertSummaryToSnapshotTreeForCreateNew(summaryObject);
|
|
381
|
-
unreferenced = summaryObject.unreferenced;
|
|
382
|
-
break;
|
|
383
|
-
}
|
|
384
|
-
case SummaryType.Blob: {
|
|
385
|
-
const content = typeof summaryObject.content === "string" ?
|
|
386
|
-
summaryObject.content : Uint8ArrayToString(summaryObject.content, "base64");
|
|
387
|
-
const encoding = typeof summaryObject.content === "string" ? "utf-8" : "base64";
|
|
388
|
-
|
|
389
|
-
value = {
|
|
390
|
-
type: "blob",
|
|
391
|
-
content,
|
|
392
|
-
encoding,
|
|
393
|
-
};
|
|
394
|
-
break;
|
|
395
|
-
}
|
|
396
|
-
case SummaryType.Handle: {
|
|
397
|
-
throw new Error("No handle should be present for first summary!!");
|
|
398
|
-
}
|
|
399
|
-
default: {
|
|
400
|
-
throw new Error(`Unknown tree type ${summaryObject.type}`);
|
|
251
|
+
return createNewFluidContainerCore<ICreateFileResponse>({
|
|
252
|
+
containerSnapshot,
|
|
253
|
+
getStorageToken,
|
|
254
|
+
logger,
|
|
255
|
+
initialUrl,
|
|
256
|
+
forceAccessTokenViaAuthorizationHeader,
|
|
257
|
+
epochTracker,
|
|
258
|
+
telemetryName: "CreateNewFile",
|
|
259
|
+
fetchType: "createFile",
|
|
260
|
+
validateResponseCallback: content => {
|
|
261
|
+
if (!content || !content.itemId) {
|
|
262
|
+
throw new NonRetryableError(
|
|
263
|
+
"ODSP CreateFile call returned no item ID",
|
|
264
|
+
DriverErrorType.incorrectServerResponse,
|
|
265
|
+
{ driverVersion });
|
|
401
266
|
}
|
|
402
267
|
}
|
|
403
|
-
|
|
404
|
-
const entry: OdspSummaryTreeEntry = {
|
|
405
|
-
path: encodeURIComponent(key),
|
|
406
|
-
type: getGitType(summaryObject),
|
|
407
|
-
value,
|
|
408
|
-
unreferenced,
|
|
409
|
-
};
|
|
410
|
-
snapshotTree.entries?.push(entry);
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
return snapshotTree;
|
|
268
|
+
});
|
|
414
269
|
}
|
package/src/createNewUtils.ts
CHANGED
|
@@ -4,10 +4,19 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { v4 as uuid } from "uuid";
|
|
7
|
-
import { ISummaryTree, SummaryType, ISnapshotTree } from "@fluidframework/protocol-definitions";
|
|
7
|
+
import { ISummaryBlob, ISummaryTree, SummaryType, ISnapshotTree } from "@fluidframework/protocol-definitions";
|
|
8
8
|
import { getDocAttributesFromProtocolSummary } from "@fluidframework/driver-utils";
|
|
9
|
-
import { stringToBuffer, unreachableCase } from "@fluidframework/common-utils";
|
|
9
|
+
import { stringToBuffer, Uint8ArrayToString, unreachableCase } from "@fluidframework/common-utils";
|
|
10
|
+
import { getGitType } from "@fluidframework/protocol-base";
|
|
11
|
+
import { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
12
|
+
import { InstrumentedStorageTokenFetcher } from "@fluidframework/odsp-driver-definitions";
|
|
13
|
+
import { PerformanceEvent } from "@fluidframework/telemetry-utils";
|
|
14
|
+
import { IOdspSummaryPayload, IOdspSummaryTree, OdspSummaryTreeEntry, OdspSummaryTreeValue } from "./contracts";
|
|
15
|
+
import { getWithRetryForTokenRefresh, maxUmpPostBodySize } from "./odspUtils";
|
|
10
16
|
import { ISnapshotContents } from "./odspPublicUtils";
|
|
17
|
+
import { EpochTracker, FetchType } from "./epochTracker";
|
|
18
|
+
import { getUrlAndHeadersWithAuth } from "./getUrlAndHeadersWithAuth";
|
|
19
|
+
import { runWithRetry } from "./retryUtils";
|
|
11
20
|
|
|
12
21
|
/**
|
|
13
22
|
* Converts a summary(ISummaryTree) taken in detached container to snapshot tree and blobs
|
|
@@ -68,3 +77,180 @@ function convertCreateNewSummaryTreeToTreeAndBlobsCore(
|
|
|
68
77
|
}
|
|
69
78
|
return treeNode;
|
|
70
79
|
}
|
|
80
|
+
|
|
81
|
+
export function convertSummaryIntoContainerSnapshot(createNewSummary: ISummaryTree) {
|
|
82
|
+
const appSummary = createNewSummary.tree[".app"] as ISummaryTree;
|
|
83
|
+
const protocolSummary = createNewSummary.tree[".protocol"] as ISummaryTree;
|
|
84
|
+
if (!(appSummary && protocolSummary)) {
|
|
85
|
+
throw new Error("App and protocol summary required for create new path!!");
|
|
86
|
+
}
|
|
87
|
+
const documentAttributes = getDocAttributesFromProtocolSummary(protocolSummary);
|
|
88
|
+
const attributesSummaryBlob: ISummaryBlob = {
|
|
89
|
+
type: SummaryType.Blob,
|
|
90
|
+
content: JSON.stringify(documentAttributes),
|
|
91
|
+
};
|
|
92
|
+
protocolSummary.tree.attributes = attributesSummaryBlob;
|
|
93
|
+
const convertedCreateNewSummary: ISummaryTree = {
|
|
94
|
+
type: SummaryType.Tree,
|
|
95
|
+
tree: {
|
|
96
|
+
".protocol": protocolSummary,
|
|
97
|
+
".app": appSummary,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
const snapshotTree = convertSummaryToSnapshotTreeForCreateNew(convertedCreateNewSummary);
|
|
101
|
+
const snapshot: IOdspSummaryPayload = {
|
|
102
|
+
entries: snapshotTree.entries ?? [],
|
|
103
|
+
message: "app",
|
|
104
|
+
sequenceNumber: documentAttributes.sequenceNumber,
|
|
105
|
+
type: "container",
|
|
106
|
+
};
|
|
107
|
+
return snapshot;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Converts a summary tree to ODSP tree
|
|
112
|
+
*/
|
|
113
|
+
function convertSummaryToSnapshotTreeForCreateNew(summary: ISummaryTree): IOdspSummaryTree {
|
|
114
|
+
const snapshotTree: IOdspSummaryTree = {
|
|
115
|
+
type: "tree",
|
|
116
|
+
entries: [],
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const keys = Object.keys(summary.tree);
|
|
120
|
+
for (const key of keys) {
|
|
121
|
+
const summaryObject = summary.tree[key];
|
|
122
|
+
|
|
123
|
+
let value: OdspSummaryTreeValue;
|
|
124
|
+
// Tracks if an entry is unreferenced. Currently, only tree entries can be marked as unreferenced. If the
|
|
125
|
+
// property is not present, the tree entry is considered referenced. If the property is present and is true,
|
|
126
|
+
// the tree entry is considered unreferenced.
|
|
127
|
+
let unreferenced: true | undefined;
|
|
128
|
+
|
|
129
|
+
switch (summaryObject.type) {
|
|
130
|
+
case SummaryType.Tree: {
|
|
131
|
+
value = convertSummaryToSnapshotTreeForCreateNew(summaryObject);
|
|
132
|
+
unreferenced = summaryObject.unreferenced;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case SummaryType.Blob: {
|
|
136
|
+
const content = typeof summaryObject.content === "string" ?
|
|
137
|
+
summaryObject.content : Uint8ArrayToString(summaryObject.content, "base64");
|
|
138
|
+
const encoding = typeof summaryObject.content === "string" ? "utf-8" : "base64";
|
|
139
|
+
|
|
140
|
+
value = {
|
|
141
|
+
type: "blob",
|
|
142
|
+
content,
|
|
143
|
+
encoding,
|
|
144
|
+
};
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
case SummaryType.Handle: {
|
|
148
|
+
throw new Error("No handle should be present for first summary!!");
|
|
149
|
+
}
|
|
150
|
+
default: {
|
|
151
|
+
throw new Error(`Unknown tree type ${summaryObject.type}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const entry: OdspSummaryTreeEntry = {
|
|
156
|
+
path: encodeURIComponent(key),
|
|
157
|
+
type: getGitType(summaryObject),
|
|
158
|
+
value,
|
|
159
|
+
unreferenced,
|
|
160
|
+
};
|
|
161
|
+
snapshotTree.entries?.push(entry);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return snapshotTree;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export async function createNewFluidContainerCore<T>(args: {
|
|
168
|
+
containerSnapshot: IOdspSummaryPayload;
|
|
169
|
+
getStorageToken: InstrumentedStorageTokenFetcher;
|
|
170
|
+
logger: ITelemetryLogger;
|
|
171
|
+
initialUrl: string;
|
|
172
|
+
forceAccessTokenViaAuthorizationHeader: boolean;
|
|
173
|
+
epochTracker: EpochTracker;
|
|
174
|
+
telemetryName: string;
|
|
175
|
+
fetchType: FetchType;
|
|
176
|
+
validateResponseCallback?: (content: T) => void;
|
|
177
|
+
}): Promise<T> {
|
|
178
|
+
const {
|
|
179
|
+
containerSnapshot,
|
|
180
|
+
getStorageToken,
|
|
181
|
+
logger,
|
|
182
|
+
initialUrl,
|
|
183
|
+
forceAccessTokenViaAuthorizationHeader,
|
|
184
|
+
epochTracker,
|
|
185
|
+
telemetryName,
|
|
186
|
+
fetchType,
|
|
187
|
+
validateResponseCallback
|
|
188
|
+
} = args;
|
|
189
|
+
|
|
190
|
+
return getWithRetryForTokenRefresh(async (options) => {
|
|
191
|
+
const storageToken = await getStorageToken(options, telemetryName);
|
|
192
|
+
|
|
193
|
+
return PerformanceEvent.timedExecAsync(
|
|
194
|
+
logger,
|
|
195
|
+
{ eventName: telemetryName },
|
|
196
|
+
async (event) => {
|
|
197
|
+
const snapshotBody = JSON.stringify(containerSnapshot);
|
|
198
|
+
let url: string;
|
|
199
|
+
let headers: { [index: string]: string; };
|
|
200
|
+
let addInBody = false;
|
|
201
|
+
const formBoundary = uuid();
|
|
202
|
+
let postBody = `--${formBoundary}\r\n`;
|
|
203
|
+
postBody += `Authorization: Bearer ${storageToken}\r\n`;
|
|
204
|
+
postBody += `X-HTTP-Method-Override: POST\r\n`;
|
|
205
|
+
postBody += `Content-Type: application/json\r\n`;
|
|
206
|
+
postBody += `_post: 1\r\n`;
|
|
207
|
+
postBody += `\r\n${snapshotBody}\r\n`;
|
|
208
|
+
postBody += `\r\n--${formBoundary}--`;
|
|
209
|
+
|
|
210
|
+
if (postBody.length <= maxUmpPostBodySize) {
|
|
211
|
+
const urlObj = new URL(initialUrl);
|
|
212
|
+
urlObj.searchParams.set("ump", "1");
|
|
213
|
+
url = urlObj.href;
|
|
214
|
+
headers = {
|
|
215
|
+
"Content-Type": `multipart/form-data;boundary=${formBoundary}`,
|
|
216
|
+
};
|
|
217
|
+
addInBody = true;
|
|
218
|
+
} else {
|
|
219
|
+
const parts = getUrlAndHeadersWithAuth(
|
|
220
|
+
initialUrl, storageToken, forceAccessTokenViaAuthorizationHeader);
|
|
221
|
+
url = parts.url;
|
|
222
|
+
headers = {
|
|
223
|
+
...parts.headers,
|
|
224
|
+
"Content-Type": "application/json",
|
|
225
|
+
};
|
|
226
|
+
postBody = snapshotBody;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const fetchResponse = await runWithRetry(
|
|
230
|
+
async () => epochTracker.fetchAndParseAsJSON<T>(
|
|
231
|
+
url,
|
|
232
|
+
{
|
|
233
|
+
body: postBody,
|
|
234
|
+
headers,
|
|
235
|
+
method: "POST",
|
|
236
|
+
},
|
|
237
|
+
fetchType,
|
|
238
|
+
addInBody,
|
|
239
|
+
),
|
|
240
|
+
telemetryName,
|
|
241
|
+
logger,
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
validateResponseCallback?.(fetchResponse.content);
|
|
245
|
+
|
|
246
|
+
event.end({
|
|
247
|
+
headers: Object.keys(headers).length !== 0 ? true : undefined,
|
|
248
|
+
attempts: options.refresh ? 2 : 1,
|
|
249
|
+
...fetchResponse.propsToLog,
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
return fetchResponse.content;
|
|
253
|
+
},
|
|
254
|
+
);
|
|
255
|
+
});
|
|
256
|
+
}
|
package/src/fetchSnapshot.ts
CHANGED
|
@@ -370,7 +370,7 @@ async function fetchLatestSnapshotCore(
|
|
|
370
370
|
// Usually the latest fetch call is to the end of resources, so we start from the end.
|
|
371
371
|
for (let i = resources1.length - 1; i > 0; i--) {
|
|
372
372
|
const indResTime = resources1[i] as PerformanceResourceTiming;
|
|
373
|
-
const resource_name = indResTime.name;
|
|
373
|
+
const resource_name = indResTime.name.toString();
|
|
374
374
|
const resource_initiatortype = indResTime.initiatorType;
|
|
375
375
|
if ((resource_initiatortype.localeCompare("fetch") === 0)
|
|
376
376
|
&& (resource_name.localeCompare(response.requestUrl) === 0)) {
|
|
@@ -27,7 +27,6 @@ export class LocalOdspDocumentServiceFactory extends OdspDocumentServiceFactoryC
|
|
|
27
27
|
super(
|
|
28
28
|
(_options) => this.throwUnsupportedUsageError("Getting storage token"),
|
|
29
29
|
(_options) => this.throwUnsupportedUsageError("Getting websocket token"),
|
|
30
|
-
() => this.throwUnsupportedUsageError("Getting SocketIO Client"),
|
|
31
30
|
);
|
|
32
31
|
}
|
|
33
32
|
|