@fluidframework/driver-utils 2.0.0-dev.5.2.0.169897 → 2.0.0-dev.6.4.0.191258
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 +40 -0
- package/README.md +4 -3
- package/dist/adapters/compression/compressionTypes.d.ts +17 -0
- package/dist/adapters/compression/compressionTypes.d.ts.map +1 -0
- package/dist/adapters/compression/compressionTypes.js +17 -0
- package/dist/adapters/compression/compressionTypes.js.map +1 -0
- package/dist/adapters/compression/documentServiceCompressionAdapter.d.ts +13 -0
- package/dist/adapters/compression/documentServiceCompressionAdapter.d.ts.map +1 -0
- package/dist/adapters/compression/documentServiceCompressionAdapter.js +23 -0
- package/dist/adapters/compression/documentServiceCompressionAdapter.js.map +1 -0
- package/dist/adapters/compression/documentServiceFactoryCompressionAdapter.d.ts +16 -0
- package/dist/adapters/compression/documentServiceFactoryCompressionAdapter.d.ts.map +1 -0
- package/dist/adapters/compression/documentServiceFactoryCompressionAdapter.js +39 -0
- package/dist/adapters/compression/documentServiceFactoryCompressionAdapter.js.map +1 -0
- package/dist/adapters/compression/index.d.ts +8 -0
- package/dist/adapters/compression/index.d.ts.map +1 -0
- package/dist/adapters/compression/index.js +15 -0
- package/dist/adapters/compression/index.js.map +1 -0
- package/dist/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.d.ts +161 -0
- package/dist/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.d.ts.map +1 -0
- package/dist/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js +366 -0
- package/dist/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js.map +1 -0
- package/dist/adapters/compression/summaryblob/index.d.ts +6 -0
- package/dist/adapters/compression/summaryblob/index.d.ts.map +1 -0
- package/dist/adapters/compression/summaryblob/index.js +11 -0
- package/dist/adapters/compression/summaryblob/index.js.map +1 -0
- package/dist/adapters/index.d.ts +7 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +14 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/predefinedAdapters.d.ts +20 -0
- package/dist/adapters/predefinedAdapters.d.ts.map +1 -0
- package/dist/adapters/predefinedAdapters.js +51 -0
- package/dist/adapters/predefinedAdapters.js.map +1 -0
- package/dist/buildSnapshotTree.d.ts.map +1 -1
- package/dist/buildSnapshotTree.js +5 -4
- package/dist/buildSnapshotTree.js.map +1 -1
- package/dist/documentServiceFactoryProxy.d.ts +19 -0
- package/dist/documentServiceFactoryProxy.d.ts.map +1 -0
- package/dist/documentServiceFactoryProxy.js +27 -0
- package/dist/documentServiceFactoryProxy.js.map +1 -0
- package/dist/documentServiceProxy.d.ts +21 -0
- package/dist/documentServiceProxy.d.ts.map +1 -0
- package/dist/documentServiceProxy.js +36 -0
- package/dist/documentServiceProxy.js.map +1 -0
- package/dist/documentStorageServiceProxy.js +1 -2
- package/dist/documentStorageServiceProxy.js.map +1 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +2 -0
- package/dist/error.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/insecureUrlResolver.js +4 -6
- package/dist/insecureUrlResolver.js.map +1 -1
- package/dist/network.d.ts +2 -2
- package/dist/network.d.ts.map +1 -1
- package/dist/network.js +11 -5
- package/dist/network.js.map +1 -1
- package/dist/networkUtils.d.ts +1 -1
- package/dist/networkUtils.d.ts.map +1 -1
- package/dist/networkUtils.js +3 -4
- package/dist/networkUtils.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/parallelRequests.d.ts +3 -3
- package/dist/parallelRequests.d.ts.map +1 -1
- package/dist/parallelRequests.js +67 -48
- package/dist/parallelRequests.js.map +1 -1
- package/dist/prefetchDocumentStorageService.js +1 -1
- package/dist/prefetchDocumentStorageService.js.map +1 -1
- package/dist/rateLimiter.js +2 -2
- package/dist/rateLimiter.js.map +1 -1
- package/dist/readAndParse.js +2 -2
- package/dist/readAndParse.js.map +1 -1
- package/dist/runWithRetry.d.ts +8 -0
- package/dist/runWithRetry.d.ts.map +1 -1
- package/dist/runWithRetry.js +37 -13
- package/dist/runWithRetry.js.map +1 -1
- package/dist/summaryForCreateNew.d.ts +0 -9
- package/dist/summaryForCreateNew.d.ts.map +1 -1
- package/dist/summaryForCreateNew.js +4 -27
- package/dist/summaryForCreateNew.js.map +1 -1
- package/dist/treeConversions.d.ts.map +1 -1
- package/dist/treeConversions.js +4 -3
- package/dist/treeConversions.js.map +1 -1
- package/lib/adapters/compression/compressionTypes.d.ts +17 -0
- package/lib/adapters/compression/compressionTypes.d.ts.map +1 -0
- package/lib/adapters/compression/compressionTypes.js +14 -0
- package/lib/adapters/compression/compressionTypes.js.map +1 -0
- package/lib/adapters/compression/documentServiceCompressionAdapter.d.ts +13 -0
- package/lib/adapters/compression/documentServiceCompressionAdapter.d.ts.map +1 -0
- package/lib/adapters/compression/documentServiceCompressionAdapter.js +19 -0
- package/lib/adapters/compression/documentServiceCompressionAdapter.js.map +1 -0
- package/lib/adapters/compression/documentServiceFactoryCompressionAdapter.d.ts +16 -0
- package/lib/adapters/compression/documentServiceFactoryCompressionAdapter.d.ts.map +1 -0
- package/lib/adapters/compression/documentServiceFactoryCompressionAdapter.js +35 -0
- package/lib/adapters/compression/documentServiceFactoryCompressionAdapter.js.map +1 -0
- package/lib/adapters/compression/index.d.ts +8 -0
- package/lib/adapters/compression/index.d.ts.map +1 -0
- package/lib/adapters/compression/index.js +8 -0
- package/lib/adapters/compression/index.js.map +1 -0
- package/lib/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.d.ts +161 -0
- package/lib/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.d.ts.map +1 -0
- package/lib/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js +362 -0
- package/lib/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js.map +1 -0
- package/lib/adapters/compression/summaryblob/index.d.ts +6 -0
- package/lib/adapters/compression/summaryblob/index.d.ts.map +1 -0
- package/lib/adapters/compression/summaryblob/index.js +6 -0
- package/lib/adapters/compression/summaryblob/index.js.map +1 -0
- package/lib/adapters/index.d.ts +7 -0
- package/lib/adapters/index.d.ts.map +1 -0
- package/lib/adapters/index.js +7 -0
- package/lib/adapters/index.js.map +1 -0
- package/lib/adapters/predefinedAdapters.d.ts +20 -0
- package/lib/adapters/predefinedAdapters.d.ts.map +1 -0
- package/lib/adapters/predefinedAdapters.js +46 -0
- package/lib/adapters/predefinedAdapters.js.map +1 -0
- package/lib/buildSnapshotTree.d.ts.map +1 -1
- package/lib/buildSnapshotTree.js +4 -3
- package/lib/buildSnapshotTree.js.map +1 -1
- package/lib/documentServiceFactoryProxy.d.ts +19 -0
- package/lib/documentServiceFactoryProxy.d.ts.map +1 -0
- package/lib/documentServiceFactoryProxy.js +23 -0
- package/lib/documentServiceFactoryProxy.js.map +1 -0
- package/lib/documentServiceProxy.d.ts +21 -0
- package/lib/documentServiceProxy.d.ts.map +1 -0
- package/lib/documentServiceProxy.js +32 -0
- package/lib/documentServiceProxy.js.map +1 -0
- package/lib/documentStorageServiceProxy.js +1 -2
- package/lib/documentStorageServiceProxy.js.map +1 -1
- package/lib/error.d.ts.map +1 -1
- package/lib/error.js +2 -0
- package/lib/error.js.map +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -2
- package/lib/index.js.map +1 -1
- package/lib/insecureUrlResolver.js +3 -5
- package/lib/insecureUrlResolver.js.map +1 -1
- package/lib/network.d.ts +2 -2
- package/lib/network.d.ts.map +1 -1
- package/lib/network.js +14 -6
- package/lib/network.js.map +1 -1
- package/lib/networkUtils.d.ts +1 -1
- package/lib/networkUtils.d.ts.map +1 -1
- package/lib/networkUtils.js +3 -4
- package/lib/networkUtils.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/parallelRequests.d.ts +3 -3
- package/lib/parallelRequests.d.ts.map +1 -1
- package/lib/parallelRequests.js +37 -18
- package/lib/parallelRequests.js.map +1 -1
- package/lib/prefetchDocumentStorageService.js +1 -1
- package/lib/prefetchDocumentStorageService.js.map +1 -1
- package/lib/rateLimiter.js +1 -1
- package/lib/rateLimiter.js.map +1 -1
- package/lib/readAndParse.js +1 -1
- package/lib/readAndParse.js.map +1 -1
- package/lib/runWithRetry.d.ts +8 -0
- package/lib/runWithRetry.d.ts.map +1 -1
- package/lib/runWithRetry.js +30 -7
- package/lib/runWithRetry.js.map +1 -1
- package/lib/summaryForCreateNew.d.ts +0 -9
- package/lib/summaryForCreateNew.d.ts.map +1 -1
- package/lib/summaryForCreateNew.js +3 -25
- package/lib/summaryForCreateNew.js.map +1 -1
- package/lib/treeConversions.d.ts.map +1 -1
- package/lib/treeConversions.js +2 -1
- package/lib/treeConversions.js.map +1 -1
- package/package.json +24 -29
- package/src/adapters/compression/compressionTypes.ts +19 -0
- package/src/adapters/compression/documentServiceCompressionAdapter.ts +25 -0
- package/src/adapters/compression/documentServiceFactoryCompressionAdapter.ts +62 -0
- package/src/adapters/compression/index.ts +12 -0
- package/src/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.ts +447 -0
- package/src/adapters/compression/summaryblob/index.ts +9 -0
- package/src/adapters/index.ts +13 -0
- package/src/adapters/predefinedAdapters.ts +73 -0
- package/src/buildSnapshotTree.ts +4 -3
- package/src/documentServiceFactoryProxy.ts +47 -0
- package/src/documentServiceProxy.ts +46 -0
- package/src/error.ts +2 -0
- package/src/index.ts +6 -2
- package/src/insecureUrlResolver.ts +1 -1
- package/src/network.ts +10 -2
- package/src/networkUtils.ts +1 -1
- package/src/packageVersion.ts +1 -1
- package/src/parallelRequests.ts +10 -8
- package/src/rateLimiter.ts +1 -1
- package/src/readAndParse.ts +1 -1
- package/src/runWithRetry.ts +32 -7
- package/src/summaryForCreateNew.ts +0 -31
- package/src/treeConversions.ts +2 -1
package/lib/runWithRetry.js
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { isFluidError } from "@fluidframework/telemetry-utils";
|
|
6
|
+
import { performance } from "@fluid-internal/client-utils";
|
|
7
|
+
import { delay } from "@fluidframework/core-utils";
|
|
8
|
+
import { DriverErrorTypes } from "@fluidframework/driver-definitions";
|
|
7
9
|
import { canRetryOnError, getRetryDelayFromError } from "./network";
|
|
8
10
|
import { pkgVersion } from "./packageVersion";
|
|
9
11
|
import { NonRetryableError } from ".";
|
|
10
12
|
export async function runWithRetry(api, fetchCallName, logger, progress) {
|
|
11
|
-
var _a, _b;
|
|
12
13
|
let result;
|
|
13
14
|
let success = false;
|
|
14
15
|
let retryAfterMs = 1000; // has to be positive!
|
|
@@ -31,14 +32,21 @@ export async function runWithRetry(api, fetchCallName, logger, progress) {
|
|
|
31
32
|
}, err);
|
|
32
33
|
throw err;
|
|
33
34
|
}
|
|
34
|
-
if (
|
|
35
|
+
if (progress.cancel?.aborted === true) {
|
|
35
36
|
logger.sendTelemetryEvent({
|
|
36
37
|
eventName: `${fetchCallName}_runWithRetryAborted`,
|
|
37
38
|
retry: numRetries,
|
|
38
39
|
duration: performance.now() - startTime,
|
|
39
40
|
fetchCallName,
|
|
41
|
+
// TODO: Remove when typescript version of the repo contains the AbortSignal.reason property (AB#5045)
|
|
42
|
+
reason: progress.cancel.reason,
|
|
40
43
|
}, err);
|
|
41
|
-
throw new NonRetryableError("runWithRetry was Aborted",
|
|
44
|
+
throw new NonRetryableError("runWithRetry was Aborted", DriverErrorTypes.genericError, {
|
|
45
|
+
driverVersion: pkgVersion,
|
|
46
|
+
fetchCallName,
|
|
47
|
+
// TODO: Remove when typescript version of the repo contains the AbortSignal.reason property (AB#5045)
|
|
48
|
+
reason: progress.cancel.reason,
|
|
49
|
+
});
|
|
42
50
|
}
|
|
43
51
|
// logging the first failed retry instead of every attempt. We want to avoid filling telemetry
|
|
44
52
|
// when we have tight loop of retrying in offline mode, but we also want to know what caused
|
|
@@ -53,8 +61,9 @@ export async function runWithRetry(api, fetchCallName, logger, progress) {
|
|
|
53
61
|
numRetries++;
|
|
54
62
|
lastError = err;
|
|
55
63
|
// If the error is throttling error, then wait for the specified time before retrying.
|
|
56
|
-
|
|
57
|
-
|
|
64
|
+
retryAfterMs =
|
|
65
|
+
getRetryDelayFromError(err) ??
|
|
66
|
+
Math.min(retryAfterMs * 2, calculateMaxWaitTime(err));
|
|
58
67
|
if (progress.onRetry) {
|
|
59
68
|
progress.onRetry(retryAfterMs, err);
|
|
60
69
|
}
|
|
@@ -72,4 +81,18 @@ export async function runWithRetry(api, fetchCallName, logger, progress) {
|
|
|
72
81
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
73
82
|
return result;
|
|
74
83
|
}
|
|
84
|
+
const MaxReconnectDelayInMsWhenEndpointIsReachable = 30000;
|
|
85
|
+
const MaxReconnectDelayInMsWhenEndpointIsNotReachable = 8000;
|
|
86
|
+
/**
|
|
87
|
+
* In case endpoint(service or socket) is not reachable, then we maybe offline or may have got some transient error
|
|
88
|
+
* not related to endpoint, in that case we want to try at faster pace and hence the max wait is lesser 8s as compared
|
|
89
|
+
* to when endpoint is reachable in which case it is 30s.
|
|
90
|
+
* @param error - error based on which we decide max wait time.
|
|
91
|
+
* @returns Max wait time.
|
|
92
|
+
*/
|
|
93
|
+
export function calculateMaxWaitTime(error) {
|
|
94
|
+
return isFluidError(error) && error.getTelemetryProperties().endpointReached === true
|
|
95
|
+
? MaxReconnectDelayInMsWhenEndpointIsReachable
|
|
96
|
+
: MaxReconnectDelayInMsWhenEndpointIsNotReachable;
|
|
97
|
+
}
|
|
75
98
|
//# sourceMappingURL=runWithRetry.js.map
|
package/lib/runWithRetry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runWithRetry.js","sourceRoot":"","sources":["../src/runWithRetry.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"runWithRetry.js","sourceRoot":"","sources":["../src/runWithRetry.ts"],"names":[],"mappings":"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","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLoggerExt, isFluidError } from \"@fluidframework/telemetry-utils\";\nimport { performance } from \"@fluid-internal/client-utils\";\nimport { delay } from \"@fluidframework/core-utils\";\nimport { DriverErrorTypes } from \"@fluidframework/driver-definitions\";\nimport { canRetryOnError, getRetryDelayFromError } from \"./network\";\nimport { pkgVersion } from \"./packageVersion\";\nimport { NonRetryableError } from \".\";\n\n/**\n * Interface describing an object passed to various network APIs.\n * It allows caller to control cancellation, as well as learn about any delays.\n */\nexport interface IProgress {\n\t/**\n\t * Abort signal used to cancel operation.\n\t *\n\t * @remarks Note that most of the layers do not use this signal yet. We need to change that over time.\n\t * Please consult with API documentation / implementation.\n\t * Note that number of layers may not check this signal while holding this request in a queue,\n\t * so it may take a while it takes effect. This can be improved in the future.\n\t *\n\t * The layers in question are:\n\t *\n\t * - driver (RateLimiter)\n\t *\n\t * - runWithRetry\n\t */\n\tcancel?: AbortSignal;\n\n\t/**\n\t * Called whenever api returns cancellable error and the call is going to be retried.\n\t * Any exception thrown from this call back result in cancellation of operation\n\t * and propagation of thrown exception.\n\t * @param delayInMs - delay before next retry. This value will depend on internal back-off logic,\n\t * as well as information provided by service (like 429 error asking to wait for some time before retry)\n\t * @param error - error object returned from the call.\n\t */\n\tonRetry?(delayInMs: number, error: any): void;\n}\n\nexport async function runWithRetry<T>(\n\tapi: (cancel?: AbortSignal) => Promise<T>,\n\tfetchCallName: string,\n\tlogger: ITelemetryLoggerExt,\n\tprogress: IProgress,\n): Promise<T> {\n\tlet result: T | undefined;\n\tlet success = false;\n\tlet retryAfterMs = 1000; // has to be positive!\n\tlet numRetries = 0;\n\tconst startTime = performance.now();\n\tlet lastError: any;\n\tdo {\n\t\ttry {\n\t\t\tresult = await api(progress.cancel);\n\t\t\tsuccess = true;\n\t\t} catch (err) {\n\t\t\t// If it is not retriable, then just throw the error.\n\t\t\tif (!canRetryOnError(err)) {\n\t\t\t\tlogger.sendTelemetryEvent(\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: `${fetchCallName}_cancel`,\n\t\t\t\t\t\tretry: numRetries,\n\t\t\t\t\t\tduration: performance.now() - startTime,\n\t\t\t\t\t\tfetchCallName,\n\t\t\t\t\t},\n\t\t\t\t\terr,\n\t\t\t\t);\n\t\t\t\tthrow err;\n\t\t\t}\n\n\t\t\tif (progress.cancel?.aborted === true) {\n\t\t\t\tlogger.sendTelemetryEvent(\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: `${fetchCallName}_runWithRetryAborted`,\n\t\t\t\t\t\tretry: numRetries,\n\t\t\t\t\t\tduration: performance.now() - startTime,\n\t\t\t\t\t\tfetchCallName,\n\t\t\t\t\t\t// TODO: Remove when typescript version of the repo contains the AbortSignal.reason property (AB#5045)\n\t\t\t\t\t\treason: (progress.cancel as AbortSignal & { reason: any }).reason,\n\t\t\t\t\t},\n\t\t\t\t\terr,\n\t\t\t\t);\n\t\t\t\tthrow new NonRetryableError(\n\t\t\t\t\t\"runWithRetry was Aborted\",\n\t\t\t\t\tDriverErrorTypes.genericError,\n\t\t\t\t\t{\n\t\t\t\t\t\tdriverVersion: pkgVersion,\n\t\t\t\t\t\tfetchCallName,\n\t\t\t\t\t\t// TODO: Remove when typescript version of the repo contains the AbortSignal.reason property (AB#5045)\n\t\t\t\t\t\treason: (progress.cancel as AbortSignal & { reason: any }).reason,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// logging the first failed retry instead of every attempt. We want to avoid filling telemetry\n\t\t\t// when we have tight loop of retrying in offline mode, but we also want to know what caused\n\t\t\t// the failure in the first place\n\t\t\tif (numRetries === 0) {\n\t\t\t\tlogger.sendTelemetryEvent(\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: `${fetchCallName}_firstFailed`,\n\t\t\t\t\t\tduration: performance.now() - startTime,\n\t\t\t\t\t\tfetchCallName,\n\t\t\t\t\t},\n\t\t\t\t\terr,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tnumRetries++;\n\t\t\tlastError = err;\n\t\t\t// If the error is throttling error, then wait for the specified time before retrying.\n\t\t\tretryAfterMs =\n\t\t\t\tgetRetryDelayFromError(err) ??\n\t\t\t\tMath.min(retryAfterMs * 2, calculateMaxWaitTime(err));\n\t\t\tif (progress.onRetry) {\n\t\t\t\tprogress.onRetry(retryAfterMs, err);\n\t\t\t}\n\t\t\tawait delay(retryAfterMs);\n\t\t}\n\t} while (!success);\n\tif (numRetries > 0) {\n\t\tlogger.sendTelemetryEvent(\n\t\t\t{\n\t\t\t\teventName: `${fetchCallName}_lastError`,\n\t\t\t\tretry: numRetries,\n\t\t\t\tduration: performance.now() - startTime,\n\t\t\t\tfetchCallName,\n\t\t\t},\n\t\t\tlastError,\n\t\t);\n\t}\n\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\treturn result!;\n}\n\nconst MaxReconnectDelayInMsWhenEndpointIsReachable = 30000;\nconst MaxReconnectDelayInMsWhenEndpointIsNotReachable = 8000;\n\n/**\n * In case endpoint(service or socket) is not reachable, then we maybe offline or may have got some transient error\n * not related to endpoint, in that case we want to try at faster pace and hence the max wait is lesser 8s as compared\n * to when endpoint is reachable in which case it is 30s.\n * @param error - error based on which we decide max wait time.\n * @returns Max wait time.\n */\nexport function calculateMaxWaitTime(error: unknown): number {\n\treturn isFluidError(error) && error.getTelemetryProperties().endpointReached === true\n\t\t? MaxReconnectDelayInMsWhenEndpointIsReachable\n\t\t: MaxReconnectDelayInMsWhenEndpointIsNotReachable;\n}\n"]}
|
|
@@ -20,15 +20,6 @@ export interface CombinedAppAndProtocolSummary extends ISummaryTree {
|
|
|
20
20
|
* @internal
|
|
21
21
|
*/
|
|
22
22
|
export declare function isCombinedAppAndProtocolSummary(summary: ISummaryTree | undefined): summary is CombinedAppAndProtocolSummary;
|
|
23
|
-
/**
|
|
24
|
-
* Combine the app summary and protocol summary in 1 tree.
|
|
25
|
-
* @param appSummary - Summary of the app.
|
|
26
|
-
* @param protocolSummary - Summary of the protocol.
|
|
27
|
-
* @internal
|
|
28
|
-
*
|
|
29
|
-
* @deprecated 2.0.0-internal.3.4.0 - Not intended for public use. Will be moved to container-loader and no longer exported in an upcoming release.
|
|
30
|
-
*/
|
|
31
|
-
export declare function combineAppAndProtocolSummary(appSummary: ISummaryTree, protocolSummary: ISummaryTree): CombinedAppAndProtocolSummary;
|
|
32
23
|
/**
|
|
33
24
|
* Extract the attributes from the protocol summary.
|
|
34
25
|
* @param protocolSummary - protocol summary from which the values are to be extracted.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summaryForCreateNew.d.ts","sourceRoot":"","sources":["../src/summaryForCreateNew.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"summaryForCreateNew.d.ts","sourceRoot":"","sources":["../src/summaryForCreateNew.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,YAAY,EAGZ,kBAAkB,EAClB,mBAAmB,EACnB,MAAM,sCAAsC,CAAC;AAE9C;;;;GAIG;AACH,MAAM,WAAW,6BAA8B,SAAQ,YAAY;IAClE,IAAI,EAAE;QACL,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC;QACvB,CAAC,WAAW,CAAC,EAAE,YAAY,CAAC;KAC5B,CAAC;CACF;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC9C,OAAO,EAAE,YAAY,GAAG,SAAS,GAC/B,OAAO,IAAI,6BAA6B,CAa1C;AAED;;;GAGG;AACH,wBAAgB,mCAAmC,CAClD,eAAe,EAAE,YAAY,GAC3B,mBAAmB,CAGrB;AAED;;;GAGG;AACH,wBAAgB,kCAAkC,CACjD,eAAe,EAAE,YAAY,GAC3B,CAAC,MAAM,EAAE,kBAAkB,CAAC,EAAE,CAOhC"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { assert } from "@fluidframework/common-utils";
|
|
6
5
|
import { SummaryType, } from "@fluidframework/protocol-definitions";
|
|
7
6
|
/**
|
|
8
7
|
* Validates the current layout of an .app + .protocol summary tree
|
|
@@ -10,10 +9,9 @@ import { SummaryType, } from "@fluidframework/protocol-definitions";
|
|
|
10
9
|
* @internal
|
|
11
10
|
*/
|
|
12
11
|
export function isCombinedAppAndProtocolSummary(summary) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
((_d = (_c = summary.tree) === null || _c === void 0 ? void 0 : _c[".protocol"]) === null || _d === void 0 ? void 0 : _d.type) !== SummaryType.Tree) {
|
|
12
|
+
if (summary?.tree === undefined ||
|
|
13
|
+
summary.tree?.[".app"]?.type !== SummaryType.Tree ||
|
|
14
|
+
summary.tree?.[".protocol"]?.type !== SummaryType.Tree) {
|
|
17
15
|
return false;
|
|
18
16
|
}
|
|
19
17
|
const treeKeys = Object.keys(summary.tree);
|
|
@@ -22,26 +20,6 @@ export function isCombinedAppAndProtocolSummary(summary) {
|
|
|
22
20
|
}
|
|
23
21
|
return true;
|
|
24
22
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Combine the app summary and protocol summary in 1 tree.
|
|
27
|
-
* @param appSummary - Summary of the app.
|
|
28
|
-
* @param protocolSummary - Summary of the protocol.
|
|
29
|
-
* @internal
|
|
30
|
-
*
|
|
31
|
-
* @deprecated 2.0.0-internal.3.4.0 - Not intended for public use. Will be moved to container-loader and no longer exported in an upcoming release.
|
|
32
|
-
*/
|
|
33
|
-
export function combineAppAndProtocolSummary(appSummary, protocolSummary) {
|
|
34
|
-
assert(!isCombinedAppAndProtocolSummary(appSummary), 0x5a8 /* app summary is already a combined tree! */);
|
|
35
|
-
assert(!isCombinedAppAndProtocolSummary(protocolSummary), 0x5a9 /* protocol summary is already a combined tree! */);
|
|
36
|
-
const createNewSummary = {
|
|
37
|
-
type: SummaryType.Tree,
|
|
38
|
-
tree: {
|
|
39
|
-
".protocol": protocolSummary,
|
|
40
|
-
".app": appSummary,
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
return createNewSummary;
|
|
44
|
-
}
|
|
45
23
|
/**
|
|
46
24
|
* Extract the attributes from the protocol summary.
|
|
47
25
|
* @param protocolSummary - protocol summary from which the values are to be extracted.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summaryForCreateNew.js","sourceRoot":"","sources":["../src/summaryForCreateNew.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"summaryForCreateNew.js","sourceRoot":"","sources":["../src/summaryForCreateNew.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEN,WAAW,GAIX,MAAM,sCAAsC,CAAC;AAc9C;;;;GAIG;AACH,MAAM,UAAU,+BAA+B,CAC9C,OAAiC;IAEjC,IACC,OAAO,EAAE,IAAI,KAAK,SAAS;QAC3B,OAAO,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,IAAI,KAAK,WAAW,CAAC,IAAI;QACjD,OAAO,CAAC,IAAI,EAAE,CAAC,WAAW,CAAC,EAAE,IAAI,KAAK,WAAW,CAAC,IAAI,EACrD;QACD,OAAO,KAAK,CAAC;KACb;IACD,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;QAC1B,OAAO,KAAK,CAAC;KACb;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mCAAmC,CAClD,eAA6B;IAE7B,MAAM,cAAc,GAAG,eAAe,CAAC,IAAI,CAAC,UAA0B,CAAC;IACvE,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAiB,CAAwB,CAAC;AAC5E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kCAAkC,CACjD,eAA6B;IAE7B,MAAM,gBAAgB,GAAG,eAAe,CAAC,IAAI,CAAC,YAA4B,CAAC;IAC3E,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,OAAiB,CAG/D,CAAC;IACJ,OAAO,YAAY,CAAC;AACrB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tISummaryTree,\n\tSummaryType,\n\tISummaryBlob,\n\tICommittedProposal,\n\tIDocumentAttributes,\n} from \"@fluidframework/protocol-definitions\";\n\n/**\n * Defines the current layout of an .app + .protocol summary tree\n * this is used internally for create new, and single commit summary\n * @internal\n */\nexport interface CombinedAppAndProtocolSummary extends ISummaryTree {\n\ttree: {\n\t\t[\".app\"]: ISummaryTree;\n\t\t[\".protocol\"]: ISummaryTree;\n\t};\n}\n\n/**\n * Validates the current layout of an .app + .protocol summary tree\n * this is used internally for create new, and single commit summary\n * @internal\n */\nexport function isCombinedAppAndProtocolSummary(\n\tsummary: ISummaryTree | undefined,\n): summary is CombinedAppAndProtocolSummary {\n\tif (\n\t\tsummary?.tree === undefined ||\n\t\tsummary.tree?.[\".app\"]?.type !== SummaryType.Tree ||\n\t\tsummary.tree?.[\".protocol\"]?.type !== SummaryType.Tree\n\t) {\n\t\treturn false;\n\t}\n\tconst treeKeys = Object.keys(summary.tree);\n\tif (treeKeys.length !== 2) {\n\t\treturn false;\n\t}\n\treturn true;\n}\n\n/**\n * Extract the attributes from the protocol summary.\n * @param protocolSummary - protocol summary from which the values are to be extracted.\n */\nexport function getDocAttributesFromProtocolSummary(\n\tprotocolSummary: ISummaryTree,\n): IDocumentAttributes {\n\tconst attributesBlob = protocolSummary.tree.attributes as ISummaryBlob;\n\treturn JSON.parse(attributesBlob.content as string) as IDocumentAttributes;\n}\n\n/**\n * Extract quorum values from the protocol summary.\n * @param protocolSummary - protocol summary from which the values are to be extracted.\n */\nexport function getQuorumValuesFromProtocolSummary(\n\tprotocolSummary: ISummaryTree,\n): [string, ICommittedProposal][] {\n\tconst quorumValuesBlob = protocolSummary.tree.quorumValues as ISummaryBlob;\n\tconst quorumValues = JSON.parse(quorumValuesBlob.content as string) as [\n\t\tstring,\n\t\tICommittedProposal,\n\t][];\n\treturn quorumValues;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"treeConversions.d.ts","sourceRoot":"","sources":["../src/treeConversions.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"treeConversions.d.ts","sourceRoot":"","sources":["../src/treeConversions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,YAAY,EAAE,KAAK,EAA2B,MAAM,sCAAsC,CAAC;AAIpG;;;GAGG;AACH,wBAAgB,iCAAiC,CAAC,WAAW,EAAE,YAAY,GAAG,KAAK,CAgDlF"}
|
package/lib/treeConversions.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { Uint8ArrayToString
|
|
5
|
+
import { Uint8ArrayToString } from "@fluid-internal/client-utils";
|
|
6
|
+
import { unreachableCase } from "@fluidframework/core-utils";
|
|
6
7
|
import { SummaryType } from "@fluidframework/protocol-definitions";
|
|
7
8
|
import { AttachmentTreeEntry, BlobTreeEntry, TreeTreeEntry } from "./blob";
|
|
8
9
|
import { isCombinedAppAndProtocolSummary } from "./summaryForCreateNew";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"treeConversions.js","sourceRoot":"","sources":["../src/treeConversions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"treeConversions.js","sourceRoot":"","sources":["../src/treeConversions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAmC,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACpG,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC3E,OAAO,EAAE,+BAA+B,EAAE,MAAM,uBAAuB,CAAC;AAExE;;;GAGG;AACH,MAAM,UAAU,iCAAiC,CAAC,WAAyB;IAC1E,MAAM,OAAO,GAAiB,EAAE,CAAC;IACjC,MAAM,gBAAgB,GAAG,+BAA+B,CAAC,WAAW,CAAC,CAAC;IACtE,MAAM,iBAAiB,GAAG,gBAAgB;QACzC,CAAC,CAAC;YACA,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC;YACrD,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;SAC/C;QACH,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAEpC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,iBAAiB,EAAE;QAC7C,MAAM,CAAC,GAAG,gBAAgB,IAAI,GAAG,KAAK,YAAY,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC;QACzE,QAAQ,KAAK,CAAC,IAAI,EAAE;YACnB,KAAK,WAAW,CAAC,IAAI,CAAC,CAAC;gBACtB,IAAI,aAAqB,CAAC;gBAC1B,IAAI,QAAQ,GAAuB,OAAO,CAAC;gBAC3C,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,EAAE;oBACtC,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC;iBAC9B;qBAAM;oBACN,aAAa,GAAG,kBAAkB,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;oBAC5D,QAAQ,GAAG,QAAQ,CAAC;iBACpB;gBACD,OAAO,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,CAAC,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC,CAAC;gBAC5D,MAAM;aACN;YAED,KAAK,WAAW,CAAC,IAAI,CAAC,CAAC;gBACtB,OAAO,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,CAAC,EAAE,iCAAiC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAC7E,MAAM;aACN;YAED,KAAK,WAAW,CAAC,UAAU,CAAC,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC,IAAI,mBAAmB,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;gBACnD,MAAM;aACN;YAED,KAAK,WAAW,CAAC,MAAM,CAAC,CAAC;gBACxB,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;aAC/D;YAED;gBACC,eAAe,CAAC,KAAK,EAAE,8BAA8B,CAAC,CAAC;SACxD;KACD;IACD,OAAO;QACN,OAAO;QACP,YAAY,EAAE,WAAW,CAAC,YAAY;KACtC,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { Uint8ArrayToString } from \"@fluid-internal/client-utils\";\nimport { unreachableCase } from \"@fluidframework/core-utils\";\nimport { ISummaryTree, ITree, ITreeEntry, SummaryType } from \"@fluidframework/protocol-definitions\";\nimport { AttachmentTreeEntry, BlobTreeEntry, TreeTreeEntry } from \"./blob\";\nimport { isCombinedAppAndProtocolSummary } from \"./summaryForCreateNew\";\n\n/**\n * Converts ISummaryTree to ITree format.\n * @param summaryTree - summary tree in ISummaryTree format\n */\nexport function convertSummaryTreeToSnapshotITree(summaryTree: ISummaryTree): ITree {\n\tconst entries: ITreeEntry[] = [];\n\tconst adaptSummaryTree = isCombinedAppAndProtocolSummary(summaryTree);\n\tconst allSummaryEntries = adaptSummaryTree\n\t\t? [\n\t\t\t\t...Object.entries(summaryTree.tree[\".protocol\"].tree),\n\t\t\t\t...Object.entries(summaryTree.tree[\".app\"].tree),\n\t\t ]\n\t\t: Object.entries(summaryTree.tree);\n\n\tfor (const [key, value] of allSummaryEntries) {\n\t\tconst k = adaptSummaryTree && key === \"attributes\" ? \".attributes\" : key;\n\t\tswitch (value.type) {\n\t\t\tcase SummaryType.Blob: {\n\t\t\t\tlet parsedContent: string;\n\t\t\t\tlet encoding: \"utf-8\" | \"base64\" = \"utf-8\";\n\t\t\t\tif (typeof value.content === \"string\") {\n\t\t\t\t\tparsedContent = value.content;\n\t\t\t\t} else {\n\t\t\t\t\tparsedContent = Uint8ArrayToString(value.content, \"base64\");\n\t\t\t\t\tencoding = \"base64\";\n\t\t\t\t}\n\t\t\t\tentries.push(new BlobTreeEntry(k, parsedContent, encoding));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase SummaryType.Tree: {\n\t\t\t\tentries.push(new TreeTreeEntry(k, convertSummaryTreeToSnapshotITree(value)));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase SummaryType.Attachment: {\n\t\t\t\tentries.push(new AttachmentTreeEntry(k, value.id));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase SummaryType.Handle: {\n\t\t\t\tthrow new Error(\"Should not have Handle type in summary tree\");\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tunreachableCase(value, \"Unexpected summary tree type\");\n\t\t}\n\t}\n\treturn {\n\t\tentries,\n\t\tunreferenced: summaryTree.unreferenced,\n\t};\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/driver-utils",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
3
|
+
"version": "2.0.0-dev.6.4.0.191258",
|
|
4
4
|
"description": "Collection of utility functions for Fluid drivers",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"main": "dist/index.js",
|
|
15
15
|
"module": "lib/index.js",
|
|
16
16
|
"types": "dist/index.d.ts",
|
|
17
|
-
"
|
|
17
|
+
"c8": {
|
|
18
18
|
"all": true,
|
|
19
19
|
"cache-dir": "nyc/.cache",
|
|
20
20
|
"exclude": [
|
|
@@ -35,30 +35,31 @@
|
|
|
35
35
|
"temp-directory": "nyc/.nyc_output"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@
|
|
39
|
-
"@fluidframework/
|
|
40
|
-
"@fluidframework/core-
|
|
41
|
-
"@fluidframework/driver-definitions": "2.0.0-dev.
|
|
42
|
-
"@fluidframework/gitresources": "^0.
|
|
43
|
-
"@fluidframework/protocol-base": "^0.
|
|
38
|
+
"@fluid-internal/client-utils": "2.0.0-dev.6.4.0.191258",
|
|
39
|
+
"@fluidframework/core-interfaces": "2.0.0-dev.6.4.0.191258",
|
|
40
|
+
"@fluidframework/core-utils": "2.0.0-dev.6.4.0.191258",
|
|
41
|
+
"@fluidframework/driver-definitions": "2.0.0-dev.6.4.0.191258",
|
|
42
|
+
"@fluidframework/gitresources": "^1.0.1",
|
|
43
|
+
"@fluidframework/protocol-base": "^1.0.1",
|
|
44
44
|
"@fluidframework/protocol-definitions": "^1.1.0",
|
|
45
|
-
"@fluidframework/telemetry-utils": "2.0.0-dev.
|
|
45
|
+
"@fluidframework/telemetry-utils": "2.0.0-dev.6.4.0.191258",
|
|
46
46
|
"axios": "^0.26.0",
|
|
47
|
+
"lz4js": "^0.2.0",
|
|
47
48
|
"url": "^0.11.0",
|
|
48
|
-
"uuid": "^
|
|
49
|
+
"uuid": "^9.0.0"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
|
-
"@fluid-tools/build-cli": "^0.
|
|
52
|
-
"@fluidframework/build-common": "^
|
|
53
|
-
"@fluidframework/build-tools": "^0.
|
|
54
|
-
"@fluidframework/driver-utils-previous": "npm:@fluidframework/driver-utils@2.0.0-internal.
|
|
55
|
-
"@fluidframework/eslint-config-fluid": "^2.
|
|
56
|
-
"@fluidframework/mocha-test-setup": "2.0.0-dev.
|
|
52
|
+
"@fluid-tools/build-cli": "^0.22.0",
|
|
53
|
+
"@fluidframework/build-common": "^2.0.0",
|
|
54
|
+
"@fluidframework/build-tools": "^0.22.0",
|
|
55
|
+
"@fluidframework/driver-utils-previous": "npm:@fluidframework/driver-utils@2.0.0-internal.6.3.0",
|
|
56
|
+
"@fluidframework/eslint-config-fluid": "^2.1.0",
|
|
57
|
+
"@fluidframework/mocha-test-setup": "2.0.0-dev.6.4.0.191258",
|
|
57
58
|
"@microsoft/api-extractor": "^7.34.4",
|
|
58
59
|
"@types/mocha": "^9.1.1",
|
|
59
|
-
"@types/node": "^
|
|
60
|
+
"@types/node": "^16.18.38",
|
|
60
61
|
"@types/sinon": "^7.0.13",
|
|
61
|
-
"
|
|
62
|
+
"c8": "^7.7.1",
|
|
62
63
|
"copyfiles": "^2.4.1",
|
|
63
64
|
"cross-env": "^7.0.3",
|
|
64
65
|
"eslint": "~8.6.0",
|
|
@@ -66,18 +67,13 @@
|
|
|
66
67
|
"mocha-json-output-reporter": "^2.0.1",
|
|
67
68
|
"mocha-multi-reporters": "^1.5.1",
|
|
68
69
|
"moment": "^2.21.0",
|
|
69
|
-
"nyc": "^15.1.0",
|
|
70
70
|
"prettier": "~2.6.2",
|
|
71
71
|
"rimraf": "^4.4.0",
|
|
72
72
|
"sinon": "^7.4.2",
|
|
73
73
|
"typescript": "~4.5.5"
|
|
74
74
|
},
|
|
75
75
|
"typeValidation": {
|
|
76
|
-
"broken": {
|
|
77
|
-
"ClassDeclaration_DeltaStreamConnectionForbiddenError": {
|
|
78
|
-
"forwardCompat": false
|
|
79
|
-
}
|
|
80
|
-
}
|
|
76
|
+
"broken": {}
|
|
81
77
|
},
|
|
82
78
|
"scripts": {
|
|
83
79
|
"build": "fluid-build . --task build",
|
|
@@ -88,7 +84,7 @@
|
|
|
88
84
|
"build:genver": "gen-version",
|
|
89
85
|
"build:test": "tsc --project ./src/test/tsconfig.json",
|
|
90
86
|
"ci:build:docs": "api-extractor run --typescript-compiler-folder ../../../node_modules/typescript && copyfiles -u 1 ./_api-extractor-temp/* ../../../_api-extractor-temp/",
|
|
91
|
-
"clean": "rimraf dist lib *.tsbuildinfo *.build.log",
|
|
87
|
+
"clean": "rimraf --glob 'dist' 'lib' '*.tsbuildinfo' '*.build.log' '_api-extractor-temp' 'nyc'",
|
|
92
88
|
"eslint": "eslint --format stylish src",
|
|
93
89
|
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
94
90
|
"format": "npm run prettier:fix",
|
|
@@ -97,12 +93,11 @@
|
|
|
97
93
|
"prettier": "prettier --check . --ignore-path ../../../.prettierignore",
|
|
98
94
|
"prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
|
|
99
95
|
"test": "npm run test:mocha",
|
|
100
|
-
"test:coverage": "
|
|
101
|
-
"test:mocha": "mocha --ignore 'dist/test/types/*' --recursive dist/test -r node_modules/@fluidframework/mocha-test-setup
|
|
102
|
-
"test:mocha:multireport": "cross-env FLUID_TEST_MULTIREPORT=1 npm run test:mocha",
|
|
96
|
+
"test:coverage": "c8 npm test",
|
|
97
|
+
"test:mocha": "mocha --ignore 'dist/test/types/*' --recursive dist/test -r node_modules/@fluidframework/mocha-test-setup",
|
|
103
98
|
"test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
|
|
104
99
|
"tsc": "tsc",
|
|
105
100
|
"typetests:gen": "fluid-type-test-generator",
|
|
106
|
-
"typetests:prepare": "flub
|
|
101
|
+
"typetests:prepare": "flub typetests --dir . --reset --previous --normalize"
|
|
107
102
|
}
|
|
108
103
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export enum SummaryCompressionAlgorithm {
|
|
7
|
+
None = 0,
|
|
8
|
+
LZ4 = 1,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ICompressionStorageConfig {
|
|
12
|
+
algorithm: SummaryCompressionAlgorithm;
|
|
13
|
+
minSizeToCompress: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const DefaultCompressionStorageConfig = {
|
|
17
|
+
algorithm: SummaryCompressionAlgorithm.LZ4,
|
|
18
|
+
minSizeToCompress: 500,
|
|
19
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { IDocumentService, IDocumentStorageService } from "@fluidframework/driver-definitions";
|
|
7
|
+
import { DocumentServiceProxy } from "../../documentServiceProxy";
|
|
8
|
+
import { DocumentStorageServiceCompressionAdapter as DocumentStorageServiceSummaryBlobCompressionAdapter } from "./summaryblob";
|
|
9
|
+
import { ICompressionStorageConfig } from "./compressionTypes";
|
|
10
|
+
|
|
11
|
+
export class DocumentServiceCompressionAdapter extends DocumentServiceProxy {
|
|
12
|
+
constructor(service: IDocumentService, private readonly _config: ICompressionStorageConfig) {
|
|
13
|
+
super(service);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public async connectToStorage(): Promise<IDocumentStorageService> {
|
|
17
|
+
const storage = await super.connectToStorage();
|
|
18
|
+
const wrapped = new DocumentStorageServiceSummaryBlobCompressionAdapter(
|
|
19
|
+
storage,
|
|
20
|
+
this._config,
|
|
21
|
+
);
|
|
22
|
+
await wrapped.getSnapshotTree();
|
|
23
|
+
return wrapped;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
|
|
7
|
+
import {
|
|
8
|
+
IDocumentService,
|
|
9
|
+
IDocumentServiceFactory,
|
|
10
|
+
IResolvedUrl,
|
|
11
|
+
} from "@fluidframework/driver-definitions";
|
|
12
|
+
import { ISummaryTree } from "@fluidframework/protocol-definitions";
|
|
13
|
+
import { DocumentServiceFactoryProxy } from "../../documentServiceFactoryProxy";
|
|
14
|
+
import { ICompressionStorageConfig } from "..";
|
|
15
|
+
import { DocumentStorageServiceCompressionAdapter as DocumentStorageServiceSummaryBlobCompressionAdapter } from "./summaryblob";
|
|
16
|
+
import { DocumentServiceCompressionAdapter } from "./documentServiceCompressionAdapter";
|
|
17
|
+
|
|
18
|
+
export class DocumentServiceFactoryCompressionAdapter extends DocumentServiceFactoryProxy {
|
|
19
|
+
constructor(
|
|
20
|
+
serviceFactory: IDocumentServiceFactory,
|
|
21
|
+
private readonly _config: ICompressionStorageConfig,
|
|
22
|
+
) {
|
|
23
|
+
super(serviceFactory);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public async createContainer(
|
|
27
|
+
createNewSummary: ISummaryTree | undefined,
|
|
28
|
+
createNewResolvedUrl: IResolvedUrl,
|
|
29
|
+
logger?: ITelemetryBaseLogger,
|
|
30
|
+
clientIsSummarizer?: boolean,
|
|
31
|
+
): Promise<IDocumentService> {
|
|
32
|
+
if (createNewSummary !== undefined) {
|
|
33
|
+
// TODO : this is a hack to make sure that the initial summary is not compressed
|
|
34
|
+
// We must prevent the initial summary from being compressed because
|
|
35
|
+
// of the hack at packages/drivers/routerlicious-driver/src/createNewUtils.ts
|
|
36
|
+
// where the binary blob is converted to a string using UTF-8 encoding
|
|
37
|
+
// which is producing incorrect results for compressed data.
|
|
38
|
+
const configForInitial = {
|
|
39
|
+
...this._config,
|
|
40
|
+
minSizeToCompress: Number.POSITIVE_INFINITY,
|
|
41
|
+
};
|
|
42
|
+
const newAppSumary =
|
|
43
|
+
DocumentStorageServiceSummaryBlobCompressionAdapter.compressSummary(
|
|
44
|
+
createNewSummary.tree[".app"] as ISummaryTree,
|
|
45
|
+
configForInitial,
|
|
46
|
+
);
|
|
47
|
+
createNewSummary.tree[".app"] = newAppSumary;
|
|
48
|
+
}
|
|
49
|
+
const service = await this.serviceFactory.createContainer(
|
|
50
|
+
createNewSummary,
|
|
51
|
+
createNewResolvedUrl,
|
|
52
|
+
logger,
|
|
53
|
+
clientIsSummarizer,
|
|
54
|
+
);
|
|
55
|
+
return new DocumentServiceCompressionAdapter(service, this._config);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public async createDocumentService(resolvedUrl: IResolvedUrl): Promise<IDocumentService> {
|
|
59
|
+
const service = await this.serviceFactory.createDocumentService(resolvedUrl);
|
|
60
|
+
return new DocumentServiceCompressionAdapter(service, this._config);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
SummaryCompressionAlgorithm,
|
|
8
|
+
ICompressionStorageConfig,
|
|
9
|
+
DefaultCompressionStorageConfig,
|
|
10
|
+
} from "./compressionTypes";
|
|
11
|
+
export { DocumentServiceFactoryCompressionAdapter } from "./documentServiceFactoryCompressionAdapter";
|
|
12
|
+
export { blobHeadersBlobName } from "./summaryblob";
|