@fluidframework/odsp-driver 0.59.2001 → 0.59.3000
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 +0 -1
- package/dist/ReadBufferUtils.js +2 -2
- package/dist/ReadBufferUtils.js.map +1 -1
- package/dist/WriteBufferUtils.js +14 -14
- package/dist/WriteBufferUtils.js.map +1 -1
- package/dist/checkUrl.js +1 -1
- package/dist/checkUrl.js.map +1 -1
- package/dist/compactSnapshotParser.js +27 -27
- package/dist/compactSnapshotParser.js.map +1 -1
- package/dist/compactSnapshotWriter.js +15 -15
- package/dist/compactSnapshotWriter.js.map +1 -1
- package/dist/contracts.d.ts +0 -1
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js.map +1 -1
- package/dist/createFile.js +15 -15
- package/dist/createFile.js.map +1 -1
- package/dist/createNewUtils.js +4 -4
- package/dist/createNewUtils.js.map +1 -1
- package/dist/epochTracker.d.ts.map +1 -1
- package/dist/epochTracker.js +11 -11
- package/dist/epochTracker.js.map +1 -1
- package/dist/fetch.js +1 -1
- package/dist/fetch.js.map +1 -1
- package/dist/fetchSnapshot.d.ts.map +1 -1
- package/dist/fetchSnapshot.js +19 -19
- package/dist/fetchSnapshot.js.map +1 -1
- package/dist/getFileLink.js +19 -19
- package/dist/getFileLink.js.map +1 -1
- package/dist/getQueryString.d.ts.map +1 -1
- package/dist/getQueryString.js.map +1 -1
- package/dist/getUrlAndHeadersWithAuth.d.ts.map +1 -1
- package/dist/getUrlAndHeadersWithAuth.js.map +1 -1
- package/dist/odspCache.d.ts.map +1 -1
- package/dist/odspCache.js.map +1 -1
- package/dist/odspDeltaStorageService.d.ts.map +1 -1
- package/dist/odspDeltaStorageService.js +5 -5
- package/dist/odspDeltaStorageService.js.map +1 -1
- package/dist/odspDocumentDeltaConnection.d.ts.map +1 -1
- package/dist/odspDocumentDeltaConnection.js +12 -12
- package/dist/odspDocumentDeltaConnection.js.map +1 -1
- package/dist/odspDocumentService.js +9 -8
- package/dist/odspDocumentService.js.map +1 -1
- package/dist/odspDocumentServiceFactory.js +1 -1
- package/dist/odspDocumentServiceFactory.js.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.js +20 -12
- package/dist/odspDocumentServiceFactoryCore.js.map +1 -1
- package/dist/odspDocumentStorageManager.d.ts +1 -0
- package/dist/odspDocumentStorageManager.d.ts.map +1 -1
- package/dist/odspDocumentStorageManager.js +34 -32
- package/dist/odspDocumentStorageManager.js.map +1 -1
- package/dist/odspDriverUrlResolver.js +10 -10
- package/dist/odspDriverUrlResolver.js.map +1 -1
- package/dist/odspDriverUrlResolverForShareLink.js +10 -10
- package/dist/odspDriverUrlResolverForShareLink.js.map +1 -1
- package/dist/odspError.d.ts +1 -1
- package/dist/odspError.d.ts.map +1 -1
- package/dist/odspError.js +1 -1
- package/dist/odspError.js.map +1 -1
- package/dist/odspFluidFileLink.js +2 -2
- package/dist/odspFluidFileLink.js.map +1 -1
- package/dist/odspPublicUtils.js +1 -1
- package/dist/odspPublicUtils.js.map +1 -1
- package/dist/odspSnapshotParser.js +3 -3
- package/dist/odspSnapshotParser.js.map +1 -1
- package/dist/odspSummaryUploadManager.js +7 -7
- package/dist/odspSummaryUploadManager.js.map +1 -1
- package/dist/odspUtils.js +9 -9
- package/dist/odspUtils.js.map +1 -1
- package/dist/opsCaching.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/prefetchLatestSnapshot.js +7 -7
- package/dist/prefetchLatestSnapshot.js.map +1 -1
- package/dist/retryErrorsStorageAdapter.d.ts.map +1 -1
- package/dist/retryErrorsStorageAdapter.js +1 -1
- package/dist/retryErrorsStorageAdapter.js.map +1 -1
- package/dist/retryUtils.js +4 -4
- package/dist/retryUtils.js.map +1 -1
- package/dist/vroom.js +3 -3
- package/dist/vroom.js.map +1 -1
- package/dist/zipItDataRepresentationUtils.d.ts.map +1 -1
- package/dist/zipItDataRepresentationUtils.js +21 -12
- package/dist/zipItDataRepresentationUtils.js.map +1 -1
- package/lib/WriteBufferUtils.js +1 -1
- package/lib/WriteBufferUtils.js.map +1 -1
- package/lib/compactSnapshotParser.js.map +1 -1
- package/lib/compactSnapshotWriter.js.map +1 -1
- package/lib/contracts.d.ts +0 -1
- package/lib/contracts.d.ts.map +1 -1
- package/lib/contracts.js.map +1 -1
- package/lib/createFile.js.map +1 -1
- package/lib/epochTracker.d.ts.map +1 -1
- package/lib/epochTracker.js +1 -1
- package/lib/epochTracker.js.map +1 -1
- package/lib/fetchSnapshot.d.ts.map +1 -1
- package/lib/fetchSnapshot.js.map +1 -1
- package/lib/getFileLink.js +6 -6
- package/lib/getFileLink.js.map +1 -1
- package/lib/getQueryString.d.ts.map +1 -1
- package/lib/getQueryString.js.map +1 -1
- package/lib/getUrlAndHeadersWithAuth.d.ts.map +1 -1
- package/lib/getUrlAndHeadersWithAuth.js.map +1 -1
- package/lib/odspCache.d.ts.map +1 -1
- package/lib/odspCache.js.map +1 -1
- package/lib/odspDeltaStorageService.d.ts.map +1 -1
- package/lib/odspDeltaStorageService.js.map +1 -1
- package/lib/odspDocumentDeltaConnection.d.ts.map +1 -1
- package/lib/odspDocumentDeltaConnection.js +1 -1
- package/lib/odspDocumentDeltaConnection.js.map +1 -1
- package/lib/odspDocumentService.js +2 -1
- package/lib/odspDocumentService.js.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.js +10 -2
- package/lib/odspDocumentServiceFactoryCore.js.map +1 -1
- package/lib/odspDocumentStorageManager.d.ts +1 -0
- package/lib/odspDocumentStorageManager.d.ts.map +1 -1
- package/lib/odspDocumentStorageManager.js +17 -15
- package/lib/odspDocumentStorageManager.js.map +1 -1
- package/lib/odspDriverUrlResolver.js +5 -5
- package/lib/odspDriverUrlResolver.js.map +1 -1
- package/lib/odspDriverUrlResolverForShareLink.js.map +1 -1
- package/lib/odspError.d.ts +1 -1
- package/lib/odspError.d.ts.map +1 -1
- package/lib/odspFluidFileLink.js.map +1 -1
- package/lib/odspSnapshotParser.js +1 -1
- package/lib/odspSnapshotParser.js.map +1 -1
- package/lib/odspUtils.js.map +1 -1
- package/lib/opsCaching.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/retryErrorsStorageAdapter.d.ts.map +1 -1
- package/lib/retryErrorsStorageAdapter.js.map +1 -1
- package/lib/retryUtils.js +1 -1
- package/lib/retryUtils.js.map +1 -1
- package/lib/vroom.js.map +1 -1
- package/lib/zipItDataRepresentationUtils.d.ts.map +1 -1
- package/lib/zipItDataRepresentationUtils.js +12 -3
- package/lib/zipItDataRepresentationUtils.js.map +1 -1
- package/package.json +14 -13
- package/src/compactSnapshotParser.ts +2 -2
- package/src/contracts.ts +4 -5
- package/src/createFile.ts +2 -2
- package/src/epochTracker.ts +9 -10
- package/src/fetchSnapshot.ts +10 -10
- package/src/getFileLink.ts +10 -10
- package/src/getQueryString.ts +1 -1
- package/src/getUrlAndHeadersWithAuth.ts +1 -1
- package/src/odspCache.ts +2 -2
- package/src/odspDeltaStorageService.ts +4 -5
- package/src/odspDocumentDeltaConnection.ts +2 -2
- package/src/odspDocumentService.ts +5 -5
- package/src/odspDocumentServiceFactoryCore.ts +13 -1
- package/src/odspDocumentStorageManager.ts +25 -18
- package/src/odspDriverUrlResolver.ts +2 -2
- package/src/odspDriverUrlResolverForShareLink.ts +1 -1
- package/src/odspSnapshotParser.ts +2 -2
- package/src/odspUtils.ts +6 -6
- package/src/opsCaching.ts +2 -2
- package/src/packageVersion.ts +1 -1
- package/src/retryErrorsStorageAdapter.ts +1 -1
- package/src/vroom.ts +1 -1
- package/src/zipItDataRepresentationUtils.ts +15 -13
package/dist/odspError.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspError.js","sourceRoot":"","sources":["../src/odspError.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yEAA2E;AAG3E;;GAEG;AACH,SAAgB,0BAA0B,CAAC,WAA6B,EAAE,OAAe;IACrF,iDAAiD;IACjD,MAAM,OAAO,GAAG,sBAAsB,OAAO,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;IACzE,MAAM,KAAK,GAAG,0CAAsB,
|
|
1
|
+
{"version":3,"file":"odspError.js","sourceRoot":"","sources":["../src/odspError.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yEAA2E;AAG3E;;GAEG;AACH,SAAgB,0BAA0B,CAAC,WAA6B,EAAE,OAAe;IACrF,iDAAiD;IACjD,MAAM,OAAO,GAAG,sBAAsB,OAAO,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;IACzE,MAAM,KAAK,GAAG,IAAA,0CAAsB,EAChC,OAAO,EACP,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,UAAU,CAAC,CAAC;IAE5B,KAAK,CAAC,sBAAsB,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC;IAE3E,OAAO,KAAK,CAAC;AACjB,CAAC;AAXD,gEAWC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createOdspNetworkError } from \"@fluidframework/odsp-doclib-utils\";\nimport { IOdspSocketError } from \"./contracts\";\n\n/**\n * Returns network error based on error object from ODSP socket (IOdspSocketError)\n */\nexport function errorObjectFromSocketError(socketError: IOdspSocketError, handler: string) {\n // pre-0.58 error message prefix: OdspSocketError\n const message = `ODSP socket error (${handler}): ${socketError.message}`;\n const error = createOdspNetworkError(\n message,\n socketError.code,\n socketError.retryAfter);\n\n error.addTelemetryProperties({ odspError: true, relayServiceError: true });\n\n return error;\n}\n"]}
|
|
@@ -37,7 +37,7 @@ function encodeOdspFluidDataStoreLocator(locator) {
|
|
|
37
37
|
if (locator.fileVersion) {
|
|
38
38
|
locatorSerialized += `&${fluidFileVersionParamName}=${encodeURIComponent(locator.fileVersion)}`;
|
|
39
39
|
}
|
|
40
|
-
return common_utils_1.fromUtf8ToBase64(locatorSerialized);
|
|
40
|
+
return (0, common_utils_1.fromUtf8ToBase64)(locatorSerialized);
|
|
41
41
|
}
|
|
42
42
|
exports.encodeOdspFluidDataStoreLocator = encodeOdspFluidDataStoreLocator;
|
|
43
43
|
/**
|
|
@@ -49,7 +49,7 @@ exports.encodeOdspFluidDataStoreLocator = encodeOdspFluidDataStoreLocator;
|
|
|
49
49
|
*/
|
|
50
50
|
function decodeOdspFluidDataStoreLocator(encodedLocatorValue, siteOriginUrl) {
|
|
51
51
|
var _a, _b, _c;
|
|
52
|
-
const locatorInfo = new URLSearchParams(common_utils_1.fromBase64ToUtf8(encodedLocatorValue));
|
|
52
|
+
const locatorInfo = new URLSearchParams((0, common_utils_1.fromBase64ToUtf8)(encodedLocatorValue));
|
|
53
53
|
const signatureValue = locatorInfo.get(fluidSignatureParamName);
|
|
54
54
|
if (signatureValue !== "1") {
|
|
55
55
|
return undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspFluidFileLink.js","sourceRoot":"","sources":["../src/odspFluidFileLink.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAkF;AAElF,2CAAkE;AAElE,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,uBAAuB,GAAG,OAAO,CAAC;AACxC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AACxC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,kCAAkC,GAAG,GAAG,CAAC;AAC/C,MAAM,yBAAyB,GAAG,GAAG,CAAC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,OAAO,EAAE;QACV,OAAO,SAAS,CAAC;KACpB;IAED,OAAO;QACH,OAAO,EAAE,OAAO,CAAC,IAAI;QACrB,OAAO;QACP,MAAM;QACN,aAAa;QACb,OAAO;QACP,oBAAoB;QACpB,WAAW;KACd,CAAC;AACN,CAAC;AAED,uGAAuG;AACvG,iEAAiE;AACpD,QAAA,qBAAqB,GAAG,KAAK,CAAC;AAE3C;;;;GAIG;AACH,SAAgB,qBAAqB,CAAC,GAAQ,EAAE,OAAkC;IAC9E,MAAM,mBAAmB,GAAG,+BAA+B,CAAC,OAAO,CAAC,CAAC;IACrE,0GAA0G;IAC1G,qCAAqC;IACrC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,6BAAqB,EAAE,mBAAmB,CAAC,CAAC;AACrE,CAAC;AALD,sDAKC;AAED;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAC,GAAQ;IAC1C,mGAAmG;IACnG,MAAM,mBAAmB,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,6BAAqB,CAAC,CAAC;IACxE,IAAI,CAAC,mBAAmB,EAAE;QACtB,OAAO,SAAS,CAAC;KACpB;IAED,qGAAqG;IACrG,oFAAoF;IACpF,MAAM,aAAa,GAAG,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,6BAAiB,CAAC,CAAC,CAAC,4BAAgB,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC;IAErG,OAAO,+BAA+B,CAAC,mBAAmB,EAAE,aAAa,CAAC,CAAC;AAC/E,CAAC;AAZD,sDAYC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { fromBase64ToUtf8, fromUtf8ToBase64 } from \"@fluidframework/common-utils\";\nimport { OdspFluidDataStoreLocator } from \"./contractsPublic\";\nimport { OdcFileSiteOrigin, OdcApiSiteOrigin } from \"./constants\";\n\nconst fluidSignature = \"1\";\nconst fluidSignatureParamName = \"fluid\";\nconst fluidSitePathParamName = \"s\";\nconst fluidDriveIdParamName = \"d\";\nconst fluidItemIdParamName = \"f\";\nconst fluidDataStorePathParamName = \"c\";\nconst fluidAppNameParamName = \"a\";\nconst fluidContainerPackageNameParamName = \"p\";\nconst fluidFileVersionParamName = \"v\";\n\n/**\n * Transforms given Fluid data store locator into string that can be embedded into url\n * @param locator - describes Fluid data store locator info to be encoded\n * @returns string representing encoded Fluid data store locator info\n */\nexport function encodeOdspFluidDataStoreLocator(locator: OdspFluidDataStoreLocator): string {\n const siteUrl = new URL(locator.siteUrl);\n const sitePath = encodeURIComponent(siteUrl.pathname);\n const driveId = encodeURIComponent(locator.driveId);\n const itemId = encodeURIComponent(locator.itemId);\n const dataStorePath = encodeURIComponent(locator.dataStorePath);\n\n let locatorSerialized = `${fluidSitePathParamName}=${sitePath}&${fluidDriveIdParamName}=${driveId}&${\n fluidItemIdParamName}=${itemId}&${fluidDataStorePathParamName}=${dataStorePath}&${\n fluidSignatureParamName}=${fluidSignature}`;\n if (locator.appName) {\n locatorSerialized += `&${fluidAppNameParamName}=${encodeURIComponent(locator.appName)}`;\n }\n if (locator.containerPackageName) {\n locatorSerialized += `&${fluidContainerPackageNameParamName}=${\n encodeURIComponent(locator.containerPackageName)}`;\n }\n if (locator.fileVersion) {\n locatorSerialized += `&${fluidFileVersionParamName}=${\n encodeURIComponent(locator.fileVersion)}`;\n }\n\n return fromUtf8ToBase64(locatorSerialized);\n}\n\n/**\n * Decodes given encoded value representing Fluid data store locator extracted from ODSP Fluid file link\n * @param encodedLocatorValue - encoded Fluid data store locator value which was produced by\n * encodeOdspFluidDataStoreLocator method\n * @param siteOriginUrl - site origin that will be appended to encoded relative path to form absolute file url\n * @returns object representing Fluid data store location in ODSP terms\n */\nfunction decodeOdspFluidDataStoreLocator(\n encodedLocatorValue: string,\n siteOriginUrl: string,\n): OdspFluidDataStoreLocator | undefined {\n const locatorInfo = new URLSearchParams(fromBase64ToUtf8(encodedLocatorValue));\n\n const signatureValue = locatorInfo.get(fluidSignatureParamName);\n if (signatureValue !== \"1\") {\n return undefined;\n }\n\n const sitePath = locatorInfo.get(fluidSitePathParamName);\n const driveId = locatorInfo.get(fluidDriveIdParamName);\n const itemId = locatorInfo.get(fluidItemIdParamName);\n const dataStorePath = locatorInfo.get(fluidDataStorePathParamName);\n const appName = locatorInfo.get(fluidAppNameParamName) ?? undefined;\n const containerPackageName = locatorInfo.get(fluidContainerPackageNameParamName) ?? undefined;\n const fileVersion = locatorInfo.get(fluidFileVersionParamName) ?? undefined;\n // \"\" is a valid value for dataStorePath so simply check for absence of the param;\n // the rest of params must be present and non-empty\n if (!sitePath || !driveId || !itemId || dataStorePath === null) {\n return undefined;\n }\n\n let siteUrl: URL | undefined;\n try {\n siteUrl = new URL(sitePath, siteOriginUrl);\n } catch {\n // Ignore failure to parse url as input might be malformed\n }\n\n if (!siteUrl) {\n return undefined;\n }\n\n return {\n siteUrl: siteUrl.href,\n driveId,\n itemId,\n dataStorePath,\n appName,\n containerPackageName,\n fileVersion,\n };\n}\n\n// This parameter is provided by host in the resolve request and it contains information about the file\n// like driveId, itemId, siteUrl, datastorePath, packageName etc.\nexport const locatorQueryParamName = \"nav\";\n\n/**\n * Embeds Fluid data store locator data into given ODSP url\n * @param url - file url in ODSP format (can be either canonical or share link)\n * @param locator - object representing Fluid data store location in ODSP terms\n */\nexport function storeLocatorInOdspUrl(url: URL, locator: OdspFluidDataStoreLocator) {\n const encodedLocatorValue = encodeOdspFluidDataStoreLocator(locator);\n // IMPORTANT: Do not apply encodeURIComponent to encodedLocatorValue, param value is automatically encoded\n // when set via URLSearchParams class\n url.searchParams.set(locatorQueryParamName, encodedLocatorValue);\n}\n\n/**\n * Extract ODSP Fluid data store locator object from given ODSP url. This extracts things like\n * driveId, ItemId, siteUrl etc from a url where these are encoded in nav query param.\n * @param url - ODSP url representing Fluid file link\n * @returns object representing Fluid data store location in ODSP terms\n */\nexport function getLocatorFromOdspUrl(url: URL): OdspFluidDataStoreLocator | undefined {\n // NOTE: No need to apply decodeURIComponent when accessing query params via URLSearchParams class.\n const encodedLocatorValue = url.searchParams.get(locatorQueryParamName);\n if (!encodedLocatorValue) {\n return undefined;\n }\n\n // IMPORTANT: ODC deviates from ODSP in that its file link origin is different from vroom api origin.\n // The following code passes vroom api origin as site origin instead of file origin.\n const siteOriginUrl = url.origin.toLowerCase() === OdcFileSiteOrigin ? OdcApiSiteOrigin : url.origin;\n\n return decodeOdspFluidDataStoreLocator(encodedLocatorValue, siteOriginUrl);\n}\n"]}
|
package/dist/odspPublicUtils.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.getHashedDocumentId = void 0;
|
|
|
8
8
|
const common_utils_1 = require("@fluidframework/common-utils");
|
|
9
9
|
async function getHashedDocumentId(driveId, itemId) {
|
|
10
10
|
const buffer = common_utils_1.IsoBuffer.from(`${driveId}_${itemId}`);
|
|
11
|
-
return encodeURIComponent(await common_utils_1.hashFile(buffer, "SHA-256", "base64"));
|
|
11
|
+
return encodeURIComponent(await (0, common_utils_1.hashFile)(buffer, "SHA-256", "base64"));
|
|
12
12
|
}
|
|
13
13
|
exports.getHashedDocumentId = getHashedDocumentId;
|
|
14
14
|
//# sourceMappingURL=odspPublicUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspPublicUtils.js","sourceRoot":"","sources":["../src/odspPublicUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAmE;AAE5D,KAAK,UAAU,mBAAmB,CAAC,OAAe,EAAE,MAAc;IACrE,MAAM,MAAM,GAAG,wBAAS,CAAC,IAAI,CAAC,GAAG,OAAO,IAAI,MAAM,EAAE,CAAC,CAAC;IACtD,OAAO,kBAAkB,CAAC,MAAM,uBAAQ,
|
|
1
|
+
{"version":3,"file":"odspPublicUtils.js","sourceRoot":"","sources":["../src/odspPublicUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAmE;AAE5D,KAAK,UAAU,mBAAmB,CAAC,OAAe,EAAE,MAAc;IACrE,MAAM,MAAM,GAAG,wBAAS,CAAC,IAAI,CAAC,GAAG,OAAO,IAAI,MAAM,EAAE,CAAC,CAAC;IACtD,OAAO,kBAAkB,CAAC,MAAM,IAAA,uBAAQ,EAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC3E,CAAC;AAHD,kDAGC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { hashFile, IsoBuffer } from \"@fluidframework/common-utils\";\n\nexport async function getHashedDocumentId(driveId: string, itemId: string): Promise<string> {\n const buffer = IsoBuffer.from(`${driveId}_${itemId}`);\n return encodeURIComponent(await hashFile(buffer, \"SHA-256\", \"base64\"));\n}\n"]}
|
|
@@ -50,14 +50,14 @@ function convertOdspSnapshotToSnapsohtTreeAndBlobs(odspSnapshot) {
|
|
|
50
50
|
if (odspSnapshot.blobs) {
|
|
51
51
|
odspSnapshot.blobs.forEach((blob) => {
|
|
52
52
|
var _a;
|
|
53
|
-
common_utils_1.assert(blob.encoding === "base64" || blob.encoding === undefined, 0x0a4 /* `Unexpected blob encoding type: '${blob.encoding}'` */);
|
|
54
|
-
blobsWithBufferContent.set(blob.id, common_utils_1.stringToBuffer(blob.content, (_a = blob.encoding) !== null && _a !== void 0 ? _a : "utf8"));
|
|
53
|
+
(0, common_utils_1.assert)(blob.encoding === "base64" || blob.encoding === undefined, 0x0a4 /* `Unexpected blob encoding type: '${blob.encoding}'` */);
|
|
54
|
+
blobsWithBufferContent.set(blob.id, (0, common_utils_1.stringToBuffer)(blob.content, (_a = blob.encoding) !== null && _a !== void 0 ? _a : "utf8"));
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
const val = {
|
|
58
58
|
blobs: blobsWithBufferContent,
|
|
59
59
|
ops: (_b = (_a = odspSnapshot.ops) === null || _a === void 0 ? void 0 : _a.map((op) => op.op)) !== null && _b !== void 0 ? _b : [],
|
|
60
|
-
sequenceNumber: odspSnapshot
|
|
60
|
+
sequenceNumber: odspSnapshot === null || odspSnapshot === void 0 ? void 0 : odspSnapshot.trees[0].sequenceNumber,
|
|
61
61
|
snapshotTree: buildHierarchy(odspSnapshot.trees[0]),
|
|
62
62
|
};
|
|
63
63
|
return val;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspSnapshotParser.js","sourceRoot":"","sources":["../src/odspSnapshotParser.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsE;AAKtE;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,QAA6B;IACjD,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"odspSnapshotParser.js","sourceRoot":"","sources":["../src/odspSnapshotParser.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsE;AAKtE;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,QAA6B;IACjD,MAAM,MAAM,GAA2C,EAAE,CAAC;IAC1D,2FAA2F;IAC3F,MAAM,IAAI,GAAsB,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IAC1E,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;IAElB,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,OAAO,EAAE;QAClC,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QAC9C,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;QACjE,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC;QAEtD,sGAAsG;QACtG,MAAM,IAAI,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;QAElC,iCAAiC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AAc,EAAE,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,KAAK,CAAC,CAAC,EAAE,cAAc;QACrD,YAAY,EAAE,cAAc,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KACtD,CAAC;IACF,OAAO,GAAG,CAAC;AACf,CAAC;AAlBD,8FAkBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, stringToBuffer } from \"@fluidframework/common-utils\";\nimport * as api from \"@fluidframework/protocol-definitions\";\nimport { IOdspSnapshot, IOdspSnapshotCommit } from \"./contracts\";\nimport { ISnapshotContents } from \"./odspUtils\";\n\n/**\n * Build a tree hierarchy base on a flat tree\n *\n * @param flatTree - a flat tree\n * @param blobsShaToPathCache - Map with blobs sha as keys and values as path of the blob.\n * @returns the hierarchical tree\n */\nfunction buildHierarchy(flatTree: IOdspSnapshotCommit): api.ISnapshotTree {\n const lookup: { [path: string]: api.ISnapshotTree; } = {};\n // id is required for root tree as it will be used to determine the version we loaded from.\n const root: api.ISnapshotTree = { id: flatTree.id, blobs: {}, trees: {} };\n lookup[\"\"] = root;\n\n for (const entry of flatTree.entries) {\n const lastIndex = entry.path.lastIndexOf(\"/\");\n const entryPathDir = entry.path.slice(0, Math.max(0, lastIndex));\n const entryPathBase = entry.path.slice(lastIndex + 1);\n\n // ODSP snapshots are created breadth-first so we can assume we see tree nodes prior to their contents\n const node = lookup[entryPathDir];\n\n // Add in either the blob or tree\n if (entry.type === \"tree\") {\n const newTree: api.ISnapshotTree = {\n blobs: {},\n trees: {},\n unreferenced: entry.unreferenced,\n };\n node.trees[decodeURIComponent(entryPathBase)] = newTree;\n lookup[entry.path] = newTree;\n } else if (entry.type === \"blob\") {\n node.blobs[decodeURIComponent(entryPathBase)] = entry.id;\n }\n }\n\n return root;\n}\n\n/**\n * Converts existing IOdspSnapshot to snapshot tree, blob array and ops\n * @param odspSnapshot - snapshot\n */\nexport function convertOdspSnapshotToSnapsohtTreeAndBlobs(\n odspSnapshot: IOdspSnapshot,\n): ISnapshotContents {\n const blobsWithBufferContent = new Map<string, ArrayBuffer>();\n if (odspSnapshot.blobs) {\n odspSnapshot.blobs.forEach((blob) => {\n assert(blob.encoding === \"base64\" || blob.encoding === undefined,\n 0x0a4 /* `Unexpected blob encoding type: '${blob.encoding}'` */);\n blobsWithBufferContent.set(blob.id, stringToBuffer(blob.content, blob.encoding ?? \"utf8\"));\n });\n }\n const val: ISnapshotContents = {\n blobs: blobsWithBufferContent,\n ops: odspSnapshot.ops?.map((op) => op.op) ?? [],\n sequenceNumber: odspSnapshot?.trees[0].sequenceNumber,\n snapshotTree: buildHierarchy(odspSnapshot.trees[0]),\n };\n return val;\n}\n"]}
|
|
@@ -41,7 +41,7 @@ class OdspSummaryUploadManager {
|
|
|
41
41
|
this.getStorageToken = getStorageToken;
|
|
42
42
|
this.epochTracker = epochTracker;
|
|
43
43
|
this.forceAccessTokenViaAuthorizationHeader = forceAccessTokenViaAuthorizationHeader;
|
|
44
|
-
this.mc = telemetry_utils_1.loggerToMonitoringContext(logger);
|
|
44
|
+
this.mc = (0, telemetry_utils_1.loggerToMonitoringContext)(logger);
|
|
45
45
|
}
|
|
46
46
|
async writeSummaryTree(tree, context) {
|
|
47
47
|
// If the last proposed handle is not the proposed handle of the acked summary(could happen when the last summary get nacked),
|
|
@@ -76,9 +76,9 @@ class OdspSummaryUploadManager {
|
|
|
76
76
|
// send container payload so server will use it without a summary op
|
|
77
77
|
type: containsProtocolTree || parentHandle === undefined ? "container" : "channel",
|
|
78
78
|
};
|
|
79
|
-
return odspUtils_1.getWithRetryForTokenRefresh(async (options) => {
|
|
79
|
+
return (0, odspUtils_1.getWithRetryForTokenRefresh)(async (options) => {
|
|
80
80
|
const storageToken = await this.getStorageToken(options, "WriteSummaryTree");
|
|
81
|
-
const { url, headers } = getUrlAndHeadersWithAuth_1.getUrlAndHeadersWithAuth(`${this.snapshotUrl}/snapshot`, storageToken, this.forceAccessTokenViaAuthorizationHeader);
|
|
81
|
+
const { url, headers } = (0, getUrlAndHeadersWithAuth_1.getUrlAndHeadersWithAuth)(`${this.snapshotUrl}/snapshot`, storageToken, this.forceAccessTokenViaAuthorizationHeader);
|
|
82
82
|
headers["Content-Type"] = "application/json";
|
|
83
83
|
if (parentHandle) {
|
|
84
84
|
headers["If-Match"] = `fluid:containerid=${parentHandle}`;
|
|
@@ -150,7 +150,7 @@ class OdspSummaryUploadManager {
|
|
|
150
150
|
else {
|
|
151
151
|
value = {
|
|
152
152
|
type: "blob",
|
|
153
|
-
content: common_utils_1.Uint8ArrayToString(summaryObject.content, "base64"),
|
|
153
|
+
content: (0, common_utils_1.Uint8ArrayToString)(summaryObject.content, "base64"),
|
|
154
154
|
encoding: "base64",
|
|
155
155
|
};
|
|
156
156
|
}
|
|
@@ -174,16 +174,16 @@ class OdspSummaryUploadManager {
|
|
|
174
174
|
break;
|
|
175
175
|
}
|
|
176
176
|
default: {
|
|
177
|
-
common_utils_1.unreachableCase(summaryObject, `Unknown type: ${summaryObject.type}`);
|
|
177
|
+
(0, common_utils_1.unreachableCase)(summaryObject, `Unknown type: ${summaryObject.type}`);
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
const baseEntry = {
|
|
181
181
|
path: encodeURIComponent(key),
|
|
182
|
-
type: protocol_base_1.getGitType(summaryObject),
|
|
182
|
+
type: (0, protocol_base_1.getGitType)(summaryObject),
|
|
183
183
|
};
|
|
184
184
|
let entry;
|
|
185
185
|
if (value) {
|
|
186
|
-
common_utils_1.assert(id === undefined, 0x0ad /* "Snapshot entry has both a tree value and a referenced id!" */);
|
|
186
|
+
(0, common_utils_1.assert)(id === undefined, 0x0ad /* "Snapshot entry has both a tree value and a referenced id!" */);
|
|
187
187
|
entry = Object.assign(Object.assign({ value }, baseEntry), { unreferenced });
|
|
188
188
|
}
|
|
189
189
|
else if (id) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspS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sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, Uint8ArrayToString, unreachableCase } from \"@fluidframework/common-utils\";\nimport { ISummaryContext } from \"@fluidframework/driver-definitions\";\nimport { getGitType } from \"@fluidframework/protocol-base\";\nimport * as api from \"@fluidframework/protocol-definitions\";\nimport { InstrumentedStorageTokenFetcher } from \"@fluidframework/odsp-driver-definitions\";\nimport { loggerToMonitoringContext, MonitoringContext, PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport {\n IOdspSummaryPayload,\n IWriteSummaryResponse,\n IOdspSummaryTree,\n IOdspSummaryTreeBaseEntry,\n OdspSummaryTreeEntry,\n OdspSummaryTreeValue,\n} from \"./contracts\";\nimport { EpochTracker } from \"./epochTracker\";\nimport { getUrlAndHeadersWithAuth } from \"./getUrlAndHeadersWithAuth\";\nimport { getWithRetryForTokenRefresh } from \"./odspUtils\";\n\n/* eslint-disable max-len */\n\n/**\n * This class manages a summary upload. When it receives a call to upload summary, it converts the summary tree into\n * a snapshot tree and then uploads that to the server.\n */\nexport class OdspSummaryUploadManager {\n // Last proposed handle of the uploaded app summary.\n private lastSummaryProposalHandle: string | undefined;\n private readonly mc: MonitoringContext;\n\n constructor(\n private readonly snapshotUrl: string,\n private readonly getStorageToken: InstrumentedStorageTokenFetcher,\n logger: ITelemetryLogger,\n private readonly epochTracker: EpochTracker,\n private readonly forceAccessTokenViaAuthorizationHeader: boolean,\n ) {\n this.mc = loggerToMonitoringContext(logger);\n }\n\n public async writeSummaryTree(tree: api.ISummaryTree, context: ISummaryContext) {\n // If the last proposed handle is not the proposed handle of the acked summary(could happen when the last summary get nacked),\n // then re-initialize the caches with the previous ones else just update the previous caches with the caches from acked summary.\n // Don't bother logging if lastSummaryProposalHandle hasn't been set before; only log on a positive mismatch.\n if (this.lastSummaryProposalHandle !== undefined &&\n this.lastSummaryProposalHandle !== context.proposalHandle) {\n this.mc.logger.sendTelemetryEvent({\n eventName: \"LastSummaryProposedHandleMismatch\",\n ackedSummaryProposedHandle: context.proposalHandle,\n lastSummaryProposalHandle: this.lastSummaryProposalHandle,\n });\n }\n const result = await this.writeSummaryTreeCore(context.ackHandle, context.referenceSequenceNumber, tree);\n const id = result ? result.id : undefined;\n if (!result || !id) {\n throw new Error(`Failed to write summary tree`);\n }\n this.lastSummaryProposalHandle = id;\n return id;\n }\n\n private async writeSummaryTreeCore(\n parentHandle: string | undefined,\n referenceSequenceNumber: number,\n tree: api.ISummaryTree,\n ): Promise<IWriteSummaryResponse> {\n const enableContainerTypeSummaryUpload = this.mc.config.getBoolean(\"Fluid.Driver.Odsp.EnableContainerTypeSummaryUpload\");\n const containsProtocolTree = enableContainerTypeSummaryUpload &&\n Object.keys(tree.tree).includes(\".protocol\");\n const { snapshotTree, blobs } = await this.convertSummaryToSnapshotTree(\n parentHandle,\n tree,\n \".app\",\n );\n const snapshot: IOdspSummaryPayload = {\n entries: snapshotTree.entries!,\n message: \"app\",\n sequenceNumber: referenceSequenceNumber,\n // no ack handle implies this is initial summary after empty file creation.\n // send container payload so server will use it without a summary op\n type: containsProtocolTree || parentHandle === undefined ? \"container\" : \"channel\",\n };\n\n return getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await this.getStorageToken(options, \"WriteSummaryTree\");\n\n const { url, headers } = getUrlAndHeadersWithAuth(\n `${this.snapshotUrl}/snapshot`,\n storageToken,\n this.forceAccessTokenViaAuthorizationHeader,\n );\n headers[\"Content-Type\"] = \"application/json\";\n if (parentHandle) {\n headers[\"If-Match\"] = `fluid:containerid=${parentHandle}`;\n }\n\n const postBody = JSON.stringify(snapshot);\n\n return PerformanceEvent.timedExecAsync(this.mc.logger,\n {\n eventName: \"uploadSummary\",\n attempt: options.refresh ? 2 : 1,\n hasClaims: !!options.claims,\n hasTenantId: !!options.tenantId,\n headers: Object.keys(headers).length !== 0 ? true : undefined,\n blobs,\n size: postBody.length,\n referenceSequenceNumber,\n type: snapshot.type,\n enableContainerTypeSummaryUpload,\n },\n async () => {\n const response = await this.epochTracker.fetchAndParseAsJSON<IWriteSummaryResponse>(\n url,\n {\n body: postBody,\n headers,\n method: \"POST\",\n },\n \"uploadSummary\");\n return response.content;\n });\n });\n }\n\n /**\n * Following are the goals of this function.\n * a.) Converts the summary tree to a snapshot/odsp tree to be uploaded. Always upload full snapshot tree.\n * @param parentHandle - Handle of the last uploaded summary or detach new summary.\n * @param tree - Summary Tree which will be converted to snapshot tree to be uploaded.\n * @param rootNodeName - Root node name of the summary tree.\n * @param path - Current path of node which is getting evaluated.\n * @param markUnreferencedNodes - True if we should mark unreferenced nodes.\n */\n private async convertSummaryToSnapshotTree(\n parentHandle: string | undefined,\n tree: api.ISummaryTree,\n rootNodeName: string,\n markUnreferencedNodes: boolean = this.mc.config.getBoolean(\"Fluid.Driver.Odsp.MarkUnreferencedNodes\") ?? true,\n ) {\n const snapshotTree: IOdspSummaryTree = {\n type: \"tree\",\n entries: [] as OdspSummaryTreeEntry[],\n };\n\n let blobs = 0;\n const keys = Object.keys(tree.tree);\n for (const key of keys) {\n const summaryObject = tree.tree[key];\n\n let id: string | undefined;\n let value: OdspSummaryTreeValue | undefined;\n\n // Tracks if an entry is unreferenced. Currently, only tree entries can be marked as unreferenced. If the\n // property is not present, the tree entry is considered referenced. If the property is present and is\n // true (which is the only value it can have), the tree entry is considered unreferenced.\n let unreferenced: true | undefined;\n switch (summaryObject.type) {\n case api.SummaryType.Tree: {\n const result = await this.convertSummaryToSnapshotTree(\n parentHandle,\n summaryObject,\n rootNodeName);\n value = result.snapshotTree;\n unreferenced = markUnreferencedNodes ? summaryObject.unreferenced : undefined;\n blobs += result.blobs;\n break;\n }\n case api.SummaryType.Blob: {\n if (typeof summaryObject.content === \"string\") {\n value = {\n type: \"blob\",\n content: summaryObject.content,\n encoding: \"utf-8\",\n };\n } else {\n value = {\n type: \"blob\",\n content: Uint8ArrayToString(summaryObject.content, \"base64\"),\n encoding: \"base64\",\n };\n }\n blobs++;\n break;\n }\n case api.SummaryType.Handle: {\n if (!parentHandle) {\n throw Error(\"Parent summary does not exist to reference by handle.\");\n }\n let handlePath = summaryObject.handle;\n if (handlePath.length > 0 && !handlePath.startsWith(\"/\")) {\n handlePath = `/${handlePath}`;\n }\n const pathKey = `${rootNodeName}${handlePath}`;\n id = `${parentHandle}/${pathKey}`;\n break;\n }\n case api.SummaryType.Attachment: {\n id = summaryObject.id;\n break;\n }\n default: {\n unreachableCase(summaryObject, `Unknown type: ${(summaryObject as any).type}`);\n }\n }\n\n const baseEntry: IOdspSummaryTreeBaseEntry = {\n path: encodeURIComponent(key),\n type: getGitType(summaryObject),\n };\n\n let entry: OdspSummaryTreeEntry;\n\n if (value) {\n assert(id === undefined, 0x0ad /* \"Snapshot entry has both a tree value and a referenced id!\" */);\n entry = {\n value,\n ...baseEntry,\n unreferenced,\n };\n } else if (id) {\n entry = {\n ...baseEntry,\n id,\n };\n } else {\n throw new Error(`Invalid tree entry for ${summaryObject.type}`);\n }\n\n snapshotTree.entries!.push(entry);\n }\n\n return { snapshotTree, blobs };\n }\n}\n\n/* eslint-enable max-len */\n"]}
|
|
1
|
+
{"version":3,"file":"odspSummaryUploadManager.js","sourceRoot":"","sources":["../src/odspSummaryUploadManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;AAGH,+DAA2F;AAE3F,iEAA2D;AAC3D,0EAA4D;AAE5D,qEAAiH;AAUjH,yEAAsE;AACtE,2CAA0D;AAE1D,4BAA4B;AAE5B;;;GAGG;AACH,MAAa,wBAAwB;IAKjC,YACqB,WAAmB,EACnB,eAAgD,EACjE,MAAwB,EACP,YAA0B,EAC1B,sCAA+C;QAJ/C,gBAAW,GAAX,WAAW,CAAQ;QACnB,oBAAe,GAAf,eAAe,CAAiC;QAEhD,iBAAY,GAAZ,YAAY,CAAc;QAC1B,2CAAsC,GAAtC,sCAAsC,CAAS;QAEhE,IAAI,C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,CAAC;oBACtB,MAAM;iBACT;gBACD,OAAO,CAAC,CAAC;oBACL,IAAA,8BAAe,EAAC,aAAa,EAAE,iBAAkB,aAAqB,CAAC,IAAI,EAAE,CAAC,CAAC;iBAClF;aACJ;YAED,MAAM,SAAS,GAA8B;gBACzC,IAAI,EAAE,kBAAkB,CAAC,GAAG,CAAC;gBAC7B,IAAI,EAAE,IAAA,0BAAU,EAAC,aAAa,CAAC;aAClC,CAAC;YAEF,IAAI,KAA2B,CAAC;YAEhC,IAAI,KAAK,EAAE;gBACP,IAAA,qBAAM,EAAC,EAAE,KAAK,SAAS,EAAE,KAAK,CAAC,iEAAiE,CAAC,CAAC;gBAClG,KAAK,iCACD,KAAK,IACF,SAAS,KACZ,YAAY,GACf,CAAC;aACL;iBAAM,IAAI,EAAE,EAAE;gBACX,KAAK,mCACE,SAAS,KACZ,EAAE,GACL,CAAC;aACL;iBAAM;gBACH,MAAM,IAAI,KAAK,CAAC,0BAA0B,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;aACnE;YAED,YAAY,CAAC,OAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACrC;QAED,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IACnC,CAAC;CACJ;AAjND,4DAiNC;AAED,2BAA2B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, Uint8ArrayToString, unreachableCase } from \"@fluidframework/common-utils\";\nimport { ISummaryContext } from \"@fluidframework/driver-definitions\";\nimport { getGitType } from \"@fluidframework/protocol-base\";\nimport * as api from \"@fluidframework/protocol-definitions\";\nimport { InstrumentedStorageTokenFetcher } from \"@fluidframework/odsp-driver-definitions\";\nimport { loggerToMonitoringContext, MonitoringContext, PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport {\n IOdspSummaryPayload,\n IWriteSummaryResponse,\n IOdspSummaryTree,\n IOdspSummaryTreeBaseEntry,\n OdspSummaryTreeEntry,\n OdspSummaryTreeValue,\n} from \"./contracts\";\nimport { EpochTracker } from \"./epochTracker\";\nimport { getUrlAndHeadersWithAuth } from \"./getUrlAndHeadersWithAuth\";\nimport { getWithRetryForTokenRefresh } from \"./odspUtils\";\n\n/* eslint-disable max-len */\n\n/**\n * This class manages a summary upload. When it receives a call to upload summary, it converts the summary tree into\n * a snapshot tree and then uploads that to the server.\n */\nexport class OdspSummaryUploadManager {\n // Last proposed handle of the uploaded app summary.\n private lastSummaryProposalHandle: string | undefined;\n private readonly mc: MonitoringContext;\n\n constructor(\n private readonly snapshotUrl: string,\n private readonly getStorageToken: InstrumentedStorageTokenFetcher,\n logger: ITelemetryLogger,\n private readonly epochTracker: EpochTracker,\n private readonly forceAccessTokenViaAuthorizationHeader: boolean,\n ) {\n this.mc = loggerToMonitoringContext(logger);\n }\n\n public async writeSummaryTree(tree: api.ISummaryTree, context: ISummaryContext) {\n // If the last proposed handle is not the proposed handle of the acked summary(could happen when the last summary get nacked),\n // then re-initialize the caches with the previous ones else just update the previous caches with the caches from acked summary.\n // Don't bother logging if lastSummaryProposalHandle hasn't been set before; only log on a positive mismatch.\n if (this.lastSummaryProposalHandle !== undefined &&\n this.lastSummaryProposalHandle !== context.proposalHandle) {\n this.mc.logger.sendTelemetryEvent({\n eventName: \"LastSummaryProposedHandleMismatch\",\n ackedSummaryProposedHandle: context.proposalHandle,\n lastSummaryProposalHandle: this.lastSummaryProposalHandle,\n });\n }\n const result = await this.writeSummaryTreeCore(context.ackHandle, context.referenceSequenceNumber, tree);\n const id = result ? result.id : undefined;\n if (!result || !id) {\n throw new Error(`Failed to write summary tree`);\n }\n this.lastSummaryProposalHandle = id;\n return id;\n }\n\n private async writeSummaryTreeCore(\n parentHandle: string | undefined,\n referenceSequenceNumber: number,\n tree: api.ISummaryTree,\n ): Promise<IWriteSummaryResponse> {\n const enableContainerTypeSummaryUpload = this.mc.config.getBoolean(\"Fluid.Driver.Odsp.EnableContainerTypeSummaryUpload\");\n const containsProtocolTree = enableContainerTypeSummaryUpload &&\n Object.keys(tree.tree).includes(\".protocol\");\n const { snapshotTree, blobs } = await this.convertSummaryToSnapshotTree(\n parentHandle,\n tree,\n \".app\",\n );\n const snapshot: IOdspSummaryPayload = {\n entries: snapshotTree.entries!,\n message: \"app\",\n sequenceNumber: referenceSequenceNumber,\n // no ack handle implies this is initial summary after empty file creation.\n // send container payload so server will use it without a summary op\n type: containsProtocolTree || parentHandle === undefined ? \"container\" : \"channel\",\n };\n\n return getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await this.getStorageToken(options, \"WriteSummaryTree\");\n\n const { url, headers } = getUrlAndHeadersWithAuth(\n `${this.snapshotUrl}/snapshot`,\n storageToken,\n this.forceAccessTokenViaAuthorizationHeader,\n );\n headers[\"Content-Type\"] = \"application/json\";\n if (parentHandle) {\n headers[\"If-Match\"] = `fluid:containerid=${parentHandle}`;\n }\n\n const postBody = JSON.stringify(snapshot);\n\n return PerformanceEvent.timedExecAsync(this.mc.logger,\n {\n eventName: \"uploadSummary\",\n attempt: options.refresh ? 2 : 1,\n hasClaims: !!options.claims,\n hasTenantId: !!options.tenantId,\n headers: Object.keys(headers).length !== 0 ? true : undefined,\n blobs,\n size: postBody.length,\n referenceSequenceNumber,\n type: snapshot.type,\n enableContainerTypeSummaryUpload,\n },\n async () => {\n const response = await this.epochTracker.fetchAndParseAsJSON<IWriteSummaryResponse>(\n url,\n {\n body: postBody,\n headers,\n method: \"POST\",\n },\n \"uploadSummary\");\n return response.content;\n });\n });\n }\n\n /**\n * Following are the goals of this function.\n * a.) Converts the summary tree to a snapshot/odsp tree to be uploaded. Always upload full snapshot tree.\n * @param parentHandle - Handle of the last uploaded summary or detach new summary.\n * @param tree - Summary Tree which will be converted to snapshot tree to be uploaded.\n * @param rootNodeName - Root node name of the summary tree.\n * @param path - Current path of node which is getting evaluated.\n * @param markUnreferencedNodes - True if we should mark unreferenced nodes.\n */\n private async convertSummaryToSnapshotTree(\n parentHandle: string | undefined,\n tree: api.ISummaryTree,\n rootNodeName: string,\n markUnreferencedNodes: boolean = this.mc.config.getBoolean(\"Fluid.Driver.Odsp.MarkUnreferencedNodes\") ?? true,\n ) {\n const snapshotTree: IOdspSummaryTree = {\n type: \"tree\",\n entries: [] as OdspSummaryTreeEntry[],\n };\n\n let blobs = 0;\n const keys = Object.keys(tree.tree);\n for (const key of keys) {\n const summaryObject = tree.tree[key];\n\n let id: string | undefined;\n let value: OdspSummaryTreeValue | undefined;\n\n // Tracks if an entry is unreferenced. Currently, only tree entries can be marked as unreferenced. If the\n // property is not present, the tree entry is considered referenced. If the property is present and is\n // true (which is the only value it can have), the tree entry is considered unreferenced.\n let unreferenced: true | undefined;\n switch (summaryObject.type) {\n case api.SummaryType.Tree: {\n const result = await this.convertSummaryToSnapshotTree(\n parentHandle,\n summaryObject,\n rootNodeName);\n value = result.snapshotTree;\n unreferenced = markUnreferencedNodes ? summaryObject.unreferenced : undefined;\n blobs += result.blobs;\n break;\n }\n case api.SummaryType.Blob: {\n if (typeof summaryObject.content === \"string\") {\n value = {\n type: \"blob\",\n content: summaryObject.content,\n encoding: \"utf-8\",\n };\n } else {\n value = {\n type: \"blob\",\n content: Uint8ArrayToString(summaryObject.content, \"base64\"),\n encoding: \"base64\",\n };\n }\n blobs++;\n break;\n }\n case api.SummaryType.Handle: {\n if (!parentHandle) {\n throw Error(\"Parent summary does not exist to reference by handle.\");\n }\n let handlePath = summaryObject.handle;\n if (handlePath.length > 0 && !handlePath.startsWith(\"/\")) {\n handlePath = `/${handlePath}`;\n }\n const pathKey = `${rootNodeName}${handlePath}`;\n id = `${parentHandle}/${pathKey}`;\n break;\n }\n case api.SummaryType.Attachment: {\n id = summaryObject.id;\n break;\n }\n default: {\n unreachableCase(summaryObject, `Unknown type: ${(summaryObject as any).type}`);\n }\n }\n\n const baseEntry: IOdspSummaryTreeBaseEntry = {\n path: encodeURIComponent(key),\n type: getGitType(summaryObject),\n };\n\n let entry: OdspSummaryTreeEntry;\n\n if (value) {\n assert(id === undefined, 0x0ad /* \"Snapshot entry has both a tree value and a referenced id!\" */);\n entry = {\n value,\n ...baseEntry,\n unreferenced,\n };\n } else if (id) {\n entry = {\n ...baseEntry,\n id,\n };\n } else {\n throw new Error(`Invalid tree entry for ${summaryObject.type}`);\n }\n\n snapshotTree.entries!.push(entry);\n }\n\n return { snapshotTree, blobs };\n }\n}\n\n/* eslint-enable max-len */\n"]}
|
package/dist/odspUtils.js
CHANGED
|
@@ -53,7 +53,7 @@ exports.getWithRetryForTokenRefresh = getWithRetryForTokenRefresh;
|
|
|
53
53
|
async function fetchHelper(requestInfo, requestInit) {
|
|
54
54
|
const start = common_utils_1.performance.now();
|
|
55
55
|
// Node-fetch and dom have conflicting typing, force them to work by casting for now
|
|
56
|
-
return fetch_1.fetch(requestInfo, requestInit).then(async (fetchResponse) => {
|
|
56
|
+
return (0, fetch_1.fetch)(requestInfo, requestInit).then(async (fetchResponse) => {
|
|
57
57
|
const response = fetchResponse;
|
|
58
58
|
// Let's assume we can retry.
|
|
59
59
|
if (!response) {
|
|
@@ -62,7 +62,7 @@ async function fetchHelper(requestInfo, requestInit) {
|
|
|
62
62
|
"No response from ODSP fetch call", driver_definitions_1.DriverErrorType.incorrectServerResponse, { driverVersion: packageVersion_1.pkgVersion });
|
|
63
63
|
}
|
|
64
64
|
if (!response.ok || response.status < 200 || response.status >= 300) {
|
|
65
|
-
odsp_doclib_utils_1.throwOdspNetworkError(
|
|
65
|
+
(0, odsp_doclib_utils_1.throwOdspNetworkError)(
|
|
66
66
|
// pre-0.58 error message prefix: odspFetchError
|
|
67
67
|
`ODSP fetch error [${response.status}]`, response.status, response, await response.text());
|
|
68
68
|
}
|
|
@@ -70,14 +70,14 @@ async function fetchHelper(requestInfo, requestInit) {
|
|
|
70
70
|
return {
|
|
71
71
|
content: response,
|
|
72
72
|
headers,
|
|
73
|
-
propsToLog: odsp_doclib_utils_1.getSPOAndGraphRequestIdsFromResponse(headers),
|
|
73
|
+
propsToLog: (0, odsp_doclib_utils_1.getSPOAndGraphRequestIdsFromResponse)(headers),
|
|
74
74
|
duration: common_utils_1.performance.now() - start,
|
|
75
75
|
};
|
|
76
76
|
}, (error) => {
|
|
77
77
|
// While we do not know for sure whether computer is offline, this error is not actionable and
|
|
78
78
|
// is pretty good indicator we are offline. Treating it as offline scenario will make it
|
|
79
79
|
// easier to see other errors in telemetry.
|
|
80
|
-
let online = driver_utils_1.isOnline();
|
|
80
|
+
let online = (0, driver_utils_1.isOnline)();
|
|
81
81
|
const errorText = `${error}`;
|
|
82
82
|
if (errorText === "TypeError: Failed to fetch") {
|
|
83
83
|
online = driver_utils_1.OnlineStatus.Offline;
|
|
@@ -142,7 +142,7 @@ async function fetchAndParseAsJSONHelper(requestInfo, requestInit) {
|
|
|
142
142
|
// (many ops) almost always ends up with this error - I'd guess 1% of op request end up here... It always
|
|
143
143
|
// succeeds on retry.
|
|
144
144
|
// So do not log error object itself.
|
|
145
|
-
odsp_doclib_utils_1.throwOdspNetworkError(
|
|
145
|
+
(0, odsp_doclib_utils_1.throwOdspNetworkError)(
|
|
146
146
|
// pre-0.58 error message: errorWhileParsingFetchResponse
|
|
147
147
|
"Error while parsing fetch response", odsp_doclib_utils_1.fetchIncorrectResponse, content, // response
|
|
148
148
|
text);
|
|
@@ -158,7 +158,7 @@ async function fetchAndParseAsJSONHelper(requestInfo, requestInit) {
|
|
|
158
158
|
}
|
|
159
159
|
exports.fetchAndParseAsJSONHelper = fetchAndParseAsJSONHelper;
|
|
160
160
|
function getOdspResolvedUrl(resolvedUrl) {
|
|
161
|
-
common_utils_1.assert(resolvedUrl.odspResolvedUrl === true, 0x1de /* "Not an ODSP resolved url" */);
|
|
161
|
+
(0, common_utils_1.assert)(resolvedUrl.odspResolvedUrl === true, 0x1de /* "Not an ODSP resolved url" */);
|
|
162
162
|
return resolvedUrl;
|
|
163
163
|
}
|
|
164
164
|
exports.getOdspResolvedUrl = getOdspResolvedUrl;
|
|
@@ -203,14 +203,14 @@ function toInstrumentedOdspTokenFetcher(logger, resolvedUrlParts, tokenFetcher,
|
|
|
203
203
|
hasClaims: !!options.claims,
|
|
204
204
|
hasTenantId: !!options.tenantId,
|
|
205
205
|
}, async (event) => tokenFetcher(Object.assign(Object.assign({}, options), resolvedUrlParts)).then((tokenResponse) => {
|
|
206
|
-
const token = odsp_driver_definitions_1.tokenFromResponse(tokenResponse);
|
|
206
|
+
const token = (0, odsp_driver_definitions_1.tokenFromResponse)(tokenResponse);
|
|
207
207
|
// This event alone generates so many events that is materially impacts cost of telemetry
|
|
208
208
|
// Thus do not report end event when it comes back quickly.
|
|
209
209
|
// Note that most of the hosts do not report if result is comming from cache or not,
|
|
210
210
|
// so we can't rely on that here. But always record if specified explicitly for cases such as
|
|
211
211
|
// calling trees/latest during load.
|
|
212
212
|
if (alwaysRecordTokenFetchTelemetry || event.duration >= 32) {
|
|
213
|
-
event.end({ fromCache: odsp_driver_definitions_1.isTokenFromCache(tokenResponse), isNull: token === null });
|
|
213
|
+
event.end({ fromCache: (0, odsp_driver_definitions_1.isTokenFromCache)(tokenResponse), isNull: token === null });
|
|
214
214
|
}
|
|
215
215
|
if (token === null && throwOnNullToken) {
|
|
216
216
|
throw new driver_utils_1.NonRetryableError(
|
|
@@ -222,7 +222,7 @@ function toInstrumentedOdspTokenFetcher(logger, resolvedUrlParts, tokenFetcher,
|
|
|
222
222
|
// There is an important but unofficial contract here where token providers can set canRetry: true
|
|
223
223
|
// to hook into the driver's retry logic (e.g. the retry loop when initiating a connection)
|
|
224
224
|
const rawCanRetry = error === null || error === void 0 ? void 0 : error.canRetry;
|
|
225
|
-
const tokenError = telemetry_utils_1.wrapError(error, (errorMessage) => new driver_utils_1.NetworkErrorBasic(`The Host-provided token fetcher for ${name} call threw an error: ${errorMessage}`, odsp_driver_definitions_1.OdspErrorType.fetchTokenError, typeof rawCanRetry === "boolean" ? rawCanRetry : false /* canRetry */, { method: name, driverVersion: packageVersion_1.pkgVersion }));
|
|
225
|
+
const tokenError = (0, telemetry_utils_1.wrapError)(error, (errorMessage) => new driver_utils_1.NetworkErrorBasic(`The Host-provided token fetcher for ${name} call threw an error: ${errorMessage}`, odsp_driver_definitions_1.OdspErrorType.fetchTokenError, typeof rawCanRetry === "boolean" ? rawCanRetry : false /* canRetry */, { method: name, driverVersion: packageVersion_1.pkgVersion }));
|
|
226
226
|
throw tokenError;
|
|
227
227
|
}), { cancel: "generic" });
|
|
228
228
|
};
|
package/dist/odspUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspUtils.js","sourceRoot":"","sources":["../src/odspUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,2EAAmF;AACnF,+DAMsC;AACtC,+DAAmE;AAEnE,qEAA2F;AAC3F,yEAI2C;AAC3C,qFAaiD;AACjD,mCAAgC;AAChC,qDAA+D;AAGlD,QAAA,iCAAiC,GAAG,mCAAmC,CAAC;AAErF,4DAA4D;AACrD,MAAM,SAAS,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;AAAjD,QAAA,SAAS,aAAwC;AAqB9D,SAAS,YAAY,CAAC,OAAgB;IAClC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,EAAE;QAC1C,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;KAC9B;IACD,OAAO,UAAU,CAAC;AACtB,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,2BAA2B,CAAI,GAAiD;IAClG,OAAO,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;QAC7C,MAAM,OAAO,GAAwB,EAAE,OAAO,EAAE,I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AK,CAAC;QACjB,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;YACT,kGAAkG;YAClG,2FAA2F;YAC3F,MAAM,WAAW,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,CAAC;YACpC,MAAM,UAAU,GAAG,2BAAS,CACxB,KAAK,EACL,CAAC,YAAY,EAAE,EAAE,CAAC,IAAI,gCAAiB,CACnC,uCAAuC,IAAI,yBAAyB,YAAY,EAAE,EAClF,uCAAa,CAAC,eAAe,EAC7B,OAAO,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,EACrE,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAb,2BAAa,EAAE,CAAC,CAAC,CAAC;YAC1C,MAAM,UAAU,CAAC;QACrB,CAAC,CAAC,EACF,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;IAC/B,CAAC,CAAC;AACN,CAAC;AAvDD,wEAuDC;AAED,SAAgB,sBAAsB,CAAC,eAAiC;IACpE,MAAM,UAAU,GAAgB;QAC5B,IAAI,EAAE,qCAAW;QACjB,GAAG,EAAE,EAAE;QACP,IAAI,EAAE;YACF,WAAW,EAAE,eAAe;YAC5B,KAAK,EAAE,eAAe,CAAC,gBAAgB;SAC1C;KACJ,CAAC;IACF,OAAO,UAAU,CAAC;AACtB,CAAC;AAVD,wDAUC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryProperties, ITelemetryBaseLogger, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { IResolvedUrl, DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport {\n isOnline,\n OnlineStatus,\n RetryableError,\n NonRetryableError,\n NetworkErrorBasic,\n} from \"@fluidframework/driver-utils\";\nimport { assert, performance } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport { ChildLogger, PerformanceEvent, wrapError } from \"@fluidframework/telemetry-utils\";\nimport {\n fetchIncorrectResponse,\n throwOdspNetworkError,\n getSPOAndGraphRequestIdsFromResponse,\n} from \"@fluidframework/odsp-doclib-utils\";\nimport {\n IOdspResolvedUrl,\n TokenFetchOptions,\n OdspErrorType,\n tokenFromResponse,\n isTokenFromCache,\n OdspResourceTokenFetchOptions,\n ShareLinkTypes,\n TokenFetcher,\n ICacheEntry,\n snapshotKey,\n InstrumentedStorageTokenFetcher,\n IOdspUrlParts,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport { fetch } from \"./fetch\";\nimport { pkgVersion as driverVersion } from \"./packageVersion\";\nimport { IOdspSnapshot } from \"./contracts\";\n\nexport const getWithRetryForTokenRefreshRepeat = \"getWithRetryForTokenRefreshRepeat\";\n\n/** Parse the given url and return the origin (host name) */\nexport const getOrigin = (url: string) => new URL(url).origin;\n\nexport interface ISnapshotContents {\n snapshotTree: ISnapshotTree,\n blobs: Map<string, ArrayBuffer>,\n ops: ISequencedDocumentMessage[],\n sequenceNumber: number | undefined,\n}\n\nexport interface IOdspResponse<T> {\n content: T;\n headers: Map<string, string>;\n propsToLog: ITelemetryProperties;\n duration: number,\n}\n\nexport interface TokenFetchOptionsEx extends TokenFetchOptions {\n /** previous error we hit in getWithRetryForTokenRefresh */\n previousError?: any;\n}\n\nfunction headersToMap(headers: Headers) {\n const newHeaders = new Map<string, string>();\n for (const [key, value] of headers.entries()) {\n newHeaders.set(key, value);\n }\n return newHeaders;\n}\n\n/**\n * This API should be used with pretty much all network calls (fetch, webSocket connection) in order\n * to correctly handle expired tokens. It relies on callback fetching token, and be able to refetch\n * token on failure. Only specific cases get retry call with refresh = true, all other / unknown errors\n * simply propagate to caller\n */\nexport async function getWithRetryForTokenRefresh<T>(get: (options: TokenFetchOptionsEx) => Promise<T>) {\n return get({ refresh: false }).catch(async (e) => {\n const options: TokenFetchOptionsEx = { refresh: true, previousError: e };\n switch (e.errorType) {\n // If the error is 401 or 403 refresh the token and try once more.\n case DriverErrorType.authorizationError:\n return get({ ...options, claims: e.claims, tenantId: e.tenantId });\n\n case DriverErrorType.incorrectServerResponse: // some error on the wire, retry once\n case OdspErrorType.fetchTokenError: // If the token was null, then retry once.\n return get(options);\n\n default:\n // Caller may determine that it wants one retry\n if (e[getWithRetryForTokenRefreshRepeat] === true) {\n return get(options);\n }\n throw e;\n }\n });\n}\n\nexport async function fetchHelper(\n requestInfo: RequestInfo,\n requestInit: RequestInit | undefined,\n): Promise<IOdspResponse<Response>> {\n const start = performance.now();\n\n // Node-fetch and dom have conflicting typing, force them to work by casting for now\n return fetch(requestInfo, requestInit).then(async (fetchResponse) => {\n const response = fetchResponse as any as Response;\n // Let's assume we can retry.\n if (!response) {\n throw new NonRetryableError(\n // pre-0.58 error message: No response from fetch call\n \"No response from ODSP fetch call\",\n DriverErrorType.incorrectServerResponse,\n { driverVersion });\n }\n if (!response.ok || response.status < 200 || response.status >= 300) {\n throwOdspNetworkError(\n // pre-0.58 error message prefix: odspFetchError\n `ODSP fetch error [${response.status}]`, response.status, response, await response.text());\n }\n\n const headers = headersToMap(response.headers);\n return {\n content: response,\n headers,\n propsToLog: getSPOAndGraphRequestIdsFromResponse(headers),\n duration: performance.now() - start,\n };\n }, (error) => {\n // While we do not know for sure whether computer is offline, this error is not actionable and\n // is pretty good indicator we are offline. Treating it as offline scenario will make it\n // easier to see other errors in telemetry.\n let online = isOnline();\n const errorText = `${error}`;\n if (errorText === \"TypeError: Failed to fetch\") {\n online = OnlineStatus.Offline;\n }\n // This error is thrown by fetch() when AbortSignal is provided and it gets cancelled\n if (error.name === \"AbortError\") {\n throw new RetryableError(\n \"Fetch Timeout (AbortError)\", OdspErrorType.fetchTimeout, { driverVersion });\n }\n // TCP/IP timeout\n if (errorText.indexOf(\"ETIMEDOUT\") !== -1) {\n throw new RetryableError(\n \"Fetch Timeout (ETIMEDOUT)\", OdspErrorType.fetchTimeout, { driverVersion });\n }\n\n //\n // WARNING: Do not log error object itself or any of its properties!\n // It could contain PII, like URI in message itself, or token in properties.\n // It is also non-serializable object due to circular references.\n //\n if (online === OnlineStatus.Offline) {\n throw new RetryableError(\n // pre-0.58 error message prefix: Offline\n `ODSP fetch failure (Offline): ${errorText}`, DriverErrorType.offlineError, { driverVersion });\n } else {\n throw new RetryableError(\n // pre-0.58 error message prefix: Fetch error\n `ODSP fetch failure: ${errorText}`, DriverErrorType.fetchFailure, { driverVersion });\n }\n });\n}\n\n/**\n * A utility function to fetch and parse as JSON with support for retries\n * @param requestInfo - fetch requestInfo, can be a string\n * @param requestInit - fetch requestInit\n */\nexport async function fetchArray(\n requestInfo: RequestInfo,\n requestInit: RequestInit | undefined,\n): Promise<IOdspResponse<ArrayBuffer>> {\n const { content, headers, propsToLog, duration } = await fetchHelper(requestInfo, requestInit);\n\n const arrayBuffer = await content.arrayBuffer();\n propsToLog.bodySize = arrayBuffer.byteLength;\n return {\n headers,\n content: arrayBuffer,\n propsToLog,\n duration,\n };\n}\n\n/**\n * A utility function to fetch and parse as JSON with support for retries\n * @param requestInfo - fetch requestInfo, can be a string\n * @param requestInit - fetch requestInit\n */\nexport async function fetchAndParseAsJSONHelper<T>(\n requestInfo: RequestInfo,\n requestInit: RequestInit | undefined,\n): Promise<IOdspResponse<T>> {\n const { content, headers, propsToLog, duration } = await fetchHelper(requestInfo, requestInit);\n let text: string | undefined;\n try {\n text = await content.text();\n } catch (e) {\n // JSON.parse() can fail and message would container full request URI, including\n // tokens... It fails for me with \"Unexpected end of JSON input\" quite often - an attempt to download big file\n // (many ops) almost always ends up with this error - I'd guess 1% of op request end up here... It always\n // succeeds on retry.\n // So do not log error object itself.\n throwOdspNetworkError(\n // pre-0.58 error message: errorWhileParsingFetchResponse\n \"Error while parsing fetch response\",\n fetchIncorrectResponse,\n content, // response\n text,\n );\n }\n\n propsToLog.bodySize = text.length;\n const res = {\n headers,\n content: JSON.parse(text),\n propsToLog,\n duration,\n };\n return res;\n}\n\nexport interface INewFileInfo {\n siteUrl: string;\n driveId: string;\n filename: string;\n filePath: string;\n /**\n * application can request creation of a share link along with the creation of a new file\n * by passing in an optional param to specify the kind of sharing link\n * (at the time of adding this comment Sept/2021), odsp only supports csl\n */\n createLinkType?: ShareLinkTypes;\n}\n\nexport function getOdspResolvedUrl(resolvedUrl: IResolvedUrl): IOdspResolvedUrl {\n assert((resolvedUrl as IOdspResolvedUrl).odspResolvedUrl === true, 0x1de /* \"Not an ODSP resolved url\" */);\n return resolvedUrl as IOdspResolvedUrl;\n}\n\nexport const createOdspLogger = (logger?: ITelemetryBaseLogger) =>\n ChildLogger.create(\n logger,\n \"OdspDriver\",\n { all :\n {\n driverVersion,\n },\n });\n\nexport function evalBlobsAndTrees(snapshot: IOdspSnapshot) {\n let numTrees = 0;\n let numBlobs = 0;\n let encodedBlobsSize = 0;\n let decodedBlobsSize = 0;\n for (const tree of snapshot.trees) {\n for (const treeEntry of tree.entries) {\n if (treeEntry.type === \"blob\") {\n numBlobs++;\n } else if (treeEntry.type === \"tree\") {\n numTrees++;\n }\n }\n }\n if (snapshot.blobs !== undefined) {\n for (const blob of snapshot.blobs) {\n decodedBlobsSize += blob.size;\n encodedBlobsSize += blob.content.length;\n }\n }\n return { numTrees, numBlobs, encodedBlobsSize, decodedBlobsSize };\n}\n\nexport function toInstrumentedOdspTokenFetcher(\n logger: ITelemetryLogger,\n resolvedUrlParts: IOdspUrlParts,\n tokenFetcher: TokenFetcher<OdspResourceTokenFetchOptions>,\n throwOnNullToken: boolean,\n): InstrumentedStorageTokenFetcher {\n return async (options: TokenFetchOptions, name: string, alwaysRecordTokenFetchTelemetry: boolean = false) => {\n // Telemetry note: if options.refresh is true, there is a potential perf issue:\n // Host should optimize and provide non-expired tokens on all critical paths.\n // Exceptions: race conditions around expiration, revoked tokens, host that does not care\n // (fluid-fetcher)\n return PerformanceEvent.timedExecAsync(\n logger,\n {\n eventName: `${name}_GetToken`,\n attempts: options.refresh ? 2 : 1,\n hasClaims: !!options.claims,\n hasTenantId: !!options.tenantId,\n },\n async (event) => tokenFetcher({\n ...options,\n ...resolvedUrlParts,\n }).then((tokenResponse) => {\n const token = tokenFromResponse(tokenResponse);\n // This event alone generates so many events that is materially impacts cost of telemetry\n // Thus do not report end event when it comes back quickly.\n // Note that most of the hosts do not report if result is comming from cache or not,\n // so we can't rely on that here. But always record if specified explicitly for cases such as\n // calling trees/latest during load.\n if (alwaysRecordTokenFetchTelemetry || event.duration >= 32) {\n event.end({ fromCache: isTokenFromCache(tokenResponse), isNull: token === null });\n }\n if (token === null && throwOnNullToken) {\n throw new NonRetryableError(\n // pre-0.58 error message: Token is null for ${name} call\n `The Host-provided token fetcher for ${name} call returned null`,\n OdspErrorType.fetchTokenError,\n { method: name, driverVersion });\n }\n return token;\n }, (error) => {\n // There is an important but unofficial contract here where token providers can set canRetry: true\n // to hook into the driver's retry logic (e.g. the retry loop when initiating a connection)\n const rawCanRetry = error?.canRetry;\n const tokenError = wrapError(\n error,\n (errorMessage) => new NetworkErrorBasic(\n `The Host-provided token fetcher for ${name} call threw an error: ${errorMessage}`,\n OdspErrorType.fetchTokenError,\n typeof rawCanRetry === \"boolean\" ? rawCanRetry : false /* canRetry */,\n { method: name, driverVersion }));\n throw tokenError;\n }),\n { cancel: \"generic\" });\n };\n}\n\nexport function createCacheSnapshotKey(odspResolvedUrl: IOdspResolvedUrl): ICacheEntry {\n const cacheEntry: ICacheEntry = {\n type: snapshotKey,\n key: \"\",\n file: {\n resolvedUrl: odspResolvedUrl,\n docId: odspResolvedUrl.hashedDocumentId,\n },\n };\n return cacheEntry;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"odspUtils.js","sourceRoot":"","sources":["../src/odspUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,2EAAmF;AACnF,+DAMsC;AACtC,+DAAmE;AAEnE,qEAA2F;AAC3F,yEAI2C;AAC3C,qFAaiD;AACjD,mCAAgC;AAChC,qDAA+D;AAGlD,QAAA,iCAAiC,GAA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,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;IAC/B,CAAC,CAAC;AACN,CAAC;AAvDD,wEAuDC;AAED,SAAgB,sBAAsB,CAAC,eAAiC;IACpE,MAAM,UAAU,GAAgB;QAC5B,IAAI,EAAE,qCAAW;QACjB,GAAG,EAAE,EAAE;QACP,IAAI,EAAE;YACF,WAAW,EAAE,eAAe;YAC5B,KAAK,EAAE,eAAe,CAAC,gBAAgB;SAC1C;KACJ,CAAC;IACF,OAAO,UAAU,CAAC;AACtB,CAAC;AAVD,wDAUC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryProperties, ITelemetryBaseLogger, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { IResolvedUrl, DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport {\n isOnline,\n OnlineStatus,\n RetryableError,\n NonRetryableError,\n NetworkErrorBasic,\n} from \"@fluidframework/driver-utils\";\nimport { assert, performance } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport { ChildLogger, PerformanceEvent, wrapError } from \"@fluidframework/telemetry-utils\";\nimport {\n fetchIncorrectResponse,\n throwOdspNetworkError,\n getSPOAndGraphRequestIdsFromResponse,\n} from \"@fluidframework/odsp-doclib-utils\";\nimport {\n IOdspResolvedUrl,\n TokenFetchOptions,\n OdspErrorType,\n tokenFromResponse,\n isTokenFromCache,\n OdspResourceTokenFetchOptions,\n ShareLinkTypes,\n TokenFetcher,\n ICacheEntry,\n snapshotKey,\n InstrumentedStorageTokenFetcher,\n IOdspUrlParts,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport { fetch } from \"./fetch\";\nimport { pkgVersion as driverVersion } from \"./packageVersion\";\nimport { IOdspSnapshot } from \"./contracts\";\n\nexport const getWithRetryForTokenRefreshRepeat = \"getWithRetryForTokenRefreshRepeat\";\n\n/** Parse the given url and return the origin (host name) */\nexport const getOrigin = (url: string) => new URL(url).origin;\n\nexport interface ISnapshotContents {\n snapshotTree: ISnapshotTree;\n blobs: Map<string, ArrayBuffer>;\n ops: ISequencedDocumentMessage[];\n sequenceNumber: number | undefined;\n}\n\nexport interface IOdspResponse<T> {\n content: T;\n headers: Map<string, string>;\n propsToLog: ITelemetryProperties;\n duration: number;\n}\n\nexport interface TokenFetchOptionsEx extends TokenFetchOptions {\n /** previous error we hit in getWithRetryForTokenRefresh */\n previousError?: any;\n}\n\nfunction headersToMap(headers: Headers) {\n const newHeaders = new Map<string, string>();\n for (const [key, value] of headers.entries()) {\n newHeaders.set(key, value);\n }\n return newHeaders;\n}\n\n/**\n * This API should be used with pretty much all network calls (fetch, webSocket connection) in order\n * to correctly handle expired tokens. It relies on callback fetching token, and be able to refetch\n * token on failure. Only specific cases get retry call with refresh = true, all other / unknown errors\n * simply propagate to caller\n */\nexport async function getWithRetryForTokenRefresh<T>(get: (options: TokenFetchOptionsEx) => Promise<T>) {\n return get({ refresh: false }).catch(async (e) => {\n const options: TokenFetchOptionsEx = { refresh: true, previousError: e };\n switch (e.errorType) {\n // If the error is 401 or 403 refresh the token and try once more.\n case DriverErrorType.authorizationError:\n return get({ ...options, claims: e.claims, tenantId: e.tenantId });\n\n case DriverErrorType.incorrectServerResponse: // some error on the wire, retry once\n case OdspErrorType.fetchTokenError: // If the token was null, then retry once.\n return get(options);\n\n default:\n // Caller may determine that it wants one retry\n if (e[getWithRetryForTokenRefreshRepeat] === true) {\n return get(options);\n }\n throw e;\n }\n });\n}\n\nexport async function fetchHelper(\n requestInfo: RequestInfo,\n requestInit: RequestInit | undefined,\n): Promise<IOdspResponse<Response>> {\n const start = performance.now();\n\n // Node-fetch and dom have conflicting typing, force them to work by casting for now\n return fetch(requestInfo, requestInit).then(async (fetchResponse) => {\n const response = fetchResponse as any as Response;\n // Let's assume we can retry.\n if (!response) {\n throw new NonRetryableError(\n // pre-0.58 error message: No response from fetch call\n \"No response from ODSP fetch call\",\n DriverErrorType.incorrectServerResponse,\n { driverVersion });\n }\n if (!response.ok || response.status < 200 || response.status >= 300) {\n throwOdspNetworkError(\n // pre-0.58 error message prefix: odspFetchError\n `ODSP fetch error [${response.status}]`, response.status, response, await response.text());\n }\n\n const headers = headersToMap(response.headers);\n return {\n content: response,\n headers,\n propsToLog: getSPOAndGraphRequestIdsFromResponse(headers),\n duration: performance.now() - start,\n };\n }, (error) => {\n // While we do not know for sure whether computer is offline, this error is not actionable and\n // is pretty good indicator we are offline. Treating it as offline scenario will make it\n // easier to see other errors in telemetry.\n let online = isOnline();\n const errorText = `${error}`;\n if (errorText === \"TypeError: Failed to fetch\") {\n online = OnlineStatus.Offline;\n }\n // This error is thrown by fetch() when AbortSignal is provided and it gets cancelled\n if (error.name === \"AbortError\") {\n throw new RetryableError(\n \"Fetch Timeout (AbortError)\", OdspErrorType.fetchTimeout, { driverVersion });\n }\n // TCP/IP timeout\n if (errorText.indexOf(\"ETIMEDOUT\") !== -1) {\n throw new RetryableError(\n \"Fetch Timeout (ETIMEDOUT)\", OdspErrorType.fetchTimeout, { driverVersion });\n }\n\n //\n // WARNING: Do not log error object itself or any of its properties!\n // It could contain PII, like URI in message itself, or token in properties.\n // It is also non-serializable object due to circular references.\n //\n if (online === OnlineStatus.Offline) {\n throw new RetryableError(\n // pre-0.58 error message prefix: Offline\n `ODSP fetch failure (Offline): ${errorText}`, DriverErrorType.offlineError, { driverVersion });\n } else {\n throw new RetryableError(\n // pre-0.58 error message prefix: Fetch error\n `ODSP fetch failure: ${errorText}`, DriverErrorType.fetchFailure, { driverVersion });\n }\n });\n}\n\n/**\n * A utility function to fetch and parse as JSON with support for retries\n * @param requestInfo - fetch requestInfo, can be a string\n * @param requestInit - fetch requestInit\n */\nexport async function fetchArray(\n requestInfo: RequestInfo,\n requestInit: RequestInit | undefined,\n): Promise<IOdspResponse<ArrayBuffer>> {\n const { content, headers, propsToLog, duration } = await fetchHelper(requestInfo, requestInit);\n\n const arrayBuffer = await content.arrayBuffer();\n propsToLog.bodySize = arrayBuffer.byteLength;\n return {\n headers,\n content: arrayBuffer,\n propsToLog,\n duration,\n };\n}\n\n/**\n * A utility function to fetch and parse as JSON with support for retries\n * @param requestInfo - fetch requestInfo, can be a string\n * @param requestInit - fetch requestInit\n */\nexport async function fetchAndParseAsJSONHelper<T>(\n requestInfo: RequestInfo,\n requestInit: RequestInit | undefined,\n): Promise<IOdspResponse<T>> {\n const { content, headers, propsToLog, duration } = await fetchHelper(requestInfo, requestInit);\n let text: string | undefined;\n try {\n text = await content.text();\n } catch (e) {\n // JSON.parse() can fail and message would container full request URI, including\n // tokens... It fails for me with \"Unexpected end of JSON input\" quite often - an attempt to download big file\n // (many ops) almost always ends up with this error - I'd guess 1% of op request end up here... It always\n // succeeds on retry.\n // So do not log error object itself.\n throwOdspNetworkError(\n // pre-0.58 error message: errorWhileParsingFetchResponse\n \"Error while parsing fetch response\",\n fetchIncorrectResponse,\n content, // response\n text,\n );\n }\n\n propsToLog.bodySize = text.length;\n const res = {\n headers,\n content: JSON.parse(text),\n propsToLog,\n duration,\n };\n return res;\n}\n\nexport interface INewFileInfo {\n siteUrl: string;\n driveId: string;\n filename: string;\n filePath: string;\n /**\n * application can request creation of a share link along with the creation of a new file\n * by passing in an optional param to specify the kind of sharing link\n * (at the time of adding this comment Sept/2021), odsp only supports csl\n */\n createLinkType?: ShareLinkTypes;\n}\n\nexport function getOdspResolvedUrl(resolvedUrl: IResolvedUrl): IOdspResolvedUrl {\n assert((resolvedUrl as IOdspResolvedUrl).odspResolvedUrl === true, 0x1de /* \"Not an ODSP resolved url\" */);\n return resolvedUrl as IOdspResolvedUrl;\n}\n\nexport const createOdspLogger = (logger?: ITelemetryBaseLogger) =>\n ChildLogger.create(\n logger,\n \"OdspDriver\",\n { all:\n {\n driverVersion,\n },\n });\n\nexport function evalBlobsAndTrees(snapshot: IOdspSnapshot) {\n let numTrees = 0;\n let numBlobs = 0;\n let encodedBlobsSize = 0;\n let decodedBlobsSize = 0;\n for (const tree of snapshot.trees) {\n for (const treeEntry of tree.entries) {\n if (treeEntry.type === \"blob\") {\n numBlobs++;\n } else if (treeEntry.type === \"tree\") {\n numTrees++;\n }\n }\n }\n if (snapshot.blobs !== undefined) {\n for (const blob of snapshot.blobs) {\n decodedBlobsSize += blob.size;\n encodedBlobsSize += blob.content.length;\n }\n }\n return { numTrees, numBlobs, encodedBlobsSize, decodedBlobsSize };\n}\n\nexport function toInstrumentedOdspTokenFetcher(\n logger: ITelemetryLogger,\n resolvedUrlParts: IOdspUrlParts,\n tokenFetcher: TokenFetcher<OdspResourceTokenFetchOptions>,\n throwOnNullToken: boolean,\n): InstrumentedStorageTokenFetcher {\n return async (options: TokenFetchOptions, name: string, alwaysRecordTokenFetchTelemetry: boolean = false) => {\n // Telemetry note: if options.refresh is true, there is a potential perf issue:\n // Host should optimize and provide non-expired tokens on all critical paths.\n // Exceptions: race conditions around expiration, revoked tokens, host that does not care\n // (fluid-fetcher)\n return PerformanceEvent.timedExecAsync(\n logger,\n {\n eventName: `${name}_GetToken`,\n attempts: options.refresh ? 2 : 1,\n hasClaims: !!options.claims,\n hasTenantId: !!options.tenantId,\n },\n async (event) => tokenFetcher({\n ...options,\n ...resolvedUrlParts,\n }).then((tokenResponse) => {\n const token = tokenFromResponse(tokenResponse);\n // This event alone generates so many events that is materially impacts cost of telemetry\n // Thus do not report end event when it comes back quickly.\n // Note that most of the hosts do not report if result is comming from cache or not,\n // so we can't rely on that here. But always record if specified explicitly for cases such as\n // calling trees/latest during load.\n if (alwaysRecordTokenFetchTelemetry || event.duration >= 32) {\n event.end({ fromCache: isTokenFromCache(tokenResponse), isNull: token === null });\n }\n if (token === null && throwOnNullToken) {\n throw new NonRetryableError(\n // pre-0.58 error message: Token is null for ${name} call\n `The Host-provided token fetcher for ${name} call returned null`,\n OdspErrorType.fetchTokenError,\n { method: name, driverVersion });\n }\n return token;\n }, (error) => {\n // There is an important but unofficial contract here where token providers can set canRetry: true\n // to hook into the driver's retry logic (e.g. the retry loop when initiating a connection)\n const rawCanRetry = error?.canRetry;\n const tokenError = wrapError(\n error,\n (errorMessage) => new NetworkErrorBasic(\n `The Host-provided token fetcher for ${name} call threw an error: ${errorMessage}`,\n OdspErrorType.fetchTokenError,\n typeof rawCanRetry === \"boolean\" ? rawCanRetry : false /* canRetry */,\n { method: name, driverVersion }));\n throw tokenError;\n }),\n { cancel: \"generic\" });\n };\n}\n\nexport function createCacheSnapshotKey(odspResolvedUrl: IOdspResolvedUrl): ICacheEntry {\n const cacheEntry: ICacheEntry = {\n type: snapshotKey,\n key: \"\",\n file: {\n resolvedUrl: odspResolvedUrl,\n docId: odspResolvedUrl.hashedDocumentId,\n },\n };\n return cacheEntry;\n}\n"]}
|
package/dist/opsCaching.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opsCaching.js","sourceRoot":"","sources":["../src/opsCaching.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+DAA2D;AAwB3D,MAAa,QAAQ;IAInB,YACE,sBAA8B,EACb,MAAwB,EACxB,KAAa,EACb,SAAiB,EACjB,gBAAgB,EACzB,eAAe;QAJN,WAAM,GAAN,MAAM,CAAkB;QACxB,UAAK,GAAL,KAAK,CAAQ;QACb,cAAS,GAAT,SAAS,CAAQ;QACjB,qBAAgB,GAAhB,gBAAgB,CAAA;QACzB,oBAAe,GAAf,eAAe,CAAA;QATR,YAAO,GAA+B,IAAI,GAAG,EAAE,CAAC;QAW3D;;WAEG;QACH,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,uBAAuB,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC;QACjG,IAAI,cAAc,KAAK,CAAC,EAAE;YACtB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,sBAAsB,CAAC,EAAE;gBAC1D,cAAc;gBACd,SAAS,EAAG,IAAI,CAAC,2BAA2B,EAAE;gBAC9C,KAAK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IAES,KAAK,CAAC,WAAmB,EAAE,OAAe;QAChD,4EAA4E;QAC5E,yCAAyC;QACzC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,IAAI,WAAW,EAAE,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;YAC/F,IAAI,CAAC,eAAe,GAAG,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;IACP,CAAC;IAES,aAAa;QACnB,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,gBAAgB,GAAG,CAAC,EAAE;YAC1C,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;gBACzB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;gBACvB,IAAI,CAAC,QAAQ,EAAE,CAAC;YACpB,CAAC,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;SAC7B;IACL,CAAC;IAEO,cAAc,CAAC,cAAsB;QACzC,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC;IAEO,uBAAuB,CAAC,cAAsB;QAClD,OAAO,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC;IAC3C,CAAC;IAEO,2BAA2B;QAC/B,MAAM,SAAS,GAAe,EAAE,CAAC;QACjC,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,sCAAsC;QACzE,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AAtLD,4BAsLC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { performance } from \"@fluidframework/common-utils\";\n\n// ISequencedDocumentMessage\nexport interface IMessage {\n sequenceNumber: number;\n}\n\nexport type CacheEntry = (IMessage | undefined)[];\n\nexport interface IBatch {\n remainingSlots: number;\n batchData: CacheEntry;\n /**\n * Tells if this batch is dirty, i.e. it contains ops that were not flushed to cache\n */\n dirty: boolean;\n}\n\nexport interface ICache {\n write(batchNumber: string, data: string): Promise<void>;\n read(batchNumber: string): Promise<string | undefined>;\n remove(): void;\n}\n\nexport class OpsCache {\n private readonly batches: Map<number, null | IBatch> = new Map();\n private timer: ReturnType<typeof setTimeout> | undefined;\n\n constructor(\n startingSequenceNumber: number,\n private readonly logger: ITelemetryLogger,\n private readonly cache: ICache,\n private readonly batchSize: number,\n private readonly timerGranularity,\n private totalOpsToCache,\n ) {\n /** initial batch is a special case because it will never be full - all ops prior (inclusive) to\n * startingSequenceNumber are never going to show up (undefined)\n */\n const remainingSlots = this.batchSize - this.getPositionInBatchArray(startingSequenceNumber) - 1;\n if (remainingSlots !== 0) {\n this.batches.set(this.getBatchNumber(startingSequenceNumber), {\n remainingSlots,\n batchData : this.initializeNewBatchDataArray(),\n dirty: false,\n });\n }\n }\n\n public dispose() {\n this.batches.clear();\n if (this.timer !== undefined) {\n clearTimeout(this.timer);\n this.timer = undefined;\n }\n }\n\n public flushOps() {\n for (const [key, value] of this.batches) {\n if (value === null || !value.dirty) {\n continue;\n }\n value.dirty = false;\n this.write(key, value);\n }\n }\n\n public addOps(ops: IMessage[]) {\n if (this.totalOpsToCache <= 0) {\n return;\n }\n\n for (const op of ops) {\n const batchNumber = this.getBatchNumber(op.sequenceNumber);\n const positionInBatch = this.getPositionInBatchArray(op.sequenceNumber);\n\n let currentBatch = this.batches.get(batchNumber);\n\n if (currentBatch === undefined) {\n currentBatch = {\n remainingSlots: this.batchSize - 1,\n batchData: this.initializeNewBatchDataArray(),\n dirty: true,\n };\n currentBatch.batchData[positionInBatch] = op;\n this.batches.set(batchNumber, currentBatch);\n } else if (currentBatch !== null && currentBatch.batchData[positionInBatch] === undefined) {\n currentBatch.batchData[positionInBatch] = op;\n currentBatch.remainingSlots--;\n currentBatch.dirty = true;\n } else {\n // Either batch was flushed or this op was already there - nothing to do!\n return;\n }\n\n if (currentBatch.remainingSlots === 0) {\n // batch is full, flush to cache\n this.write(batchNumber, currentBatch);\n this.batches.set(batchNumber, null);\n } else {\n this.scheduleTimer();\n }\n\n this.totalOpsToCache--;\n if (this.totalOpsToCache === 0) {\n this.logger.sendPerformanceEvent({ eventName: \"CacheOpsLimitHit\"});\n this.cache.remove();\n this.dispose();\n break;\n }\n }\n }\n\n /**\n * Retrieves ops from cache\n * @param from - inclusive\n * @param to - exclusive\n * @returns ops retrieved\n */\n private async getCore(from: number, to?: number): Promise<IMessage[]> {\n const messages: IMessage[] = [];\n let batchNumber = this.getBatchNumber(from);\n // eslint-disable-next-line no-constant-condition\n while (true) {\n const res = await this.cache.read(`${this.batchSize}_${batchNumber}`);\n if (res === undefined) {\n return messages;\n }\n const result: CacheEntry = JSON.parse(res);\n for (const op of result) {\n // Note that we write out undefined, but due to JSON.stringify, it turns into null!\n if (op) {\n if (to !== undefined && op.sequenceNumber >= to) {\n return messages;\n }\n if (messages.length === 0) {\n if (op.sequenceNumber > from) {\n return messages;\n } else if (op.sequenceNumber < from) {\n continue;\n }\n }\n messages.push(op);\n } else if (messages.length !== 0) {\n return messages;\n }\n }\n\n batchNumber++;\n }\n }\n\n /**\n * Retrieves ops from cache\n * @param from - inclusive\n * @param to - exclusive\n * @returns ops retrieved\n */\n public async get(from: number, to?: number): Promise<IMessage[]> {\n const start = performance.now();\n\n const messages = await this.getCore(from, to);\n\n const duration = performance.now() - start;\n if (messages.length > 0 || duration > 1000) {\n this.logger.sendPerformanceEvent({\n eventName: \"CacheOpsUsed\",\n from,\n to,\n length: messages.length,\n duration,\n });\n }\n return messages;\n }\n\n protected write(batchNumber: number, payload: IBatch) {\n // Errors are caught and logged by PersistedCacheWithErrorHandling that sits\n // in the adapter chain of cache adapters\n this.cache.write(`${this.batchSize}_${batchNumber}`, JSON.stringify(payload.batchData)).catch(() => {\n this.totalOpsToCache = 0;\n });\n }\n\n protected scheduleTimer() {\n if (!this.timer && this.timerGranularity > 0) {\n this.timer = setTimeout(() => {\n this.timer = undefined;\n this.flushOps();\n }, this.timerGranularity);\n }\n }\n\n private getBatchNumber(sequenceNumber: number) {\n return Math.floor(sequenceNumber / this.batchSize);\n }\n\n private getPositionInBatchArray(sequenceNumber: number) {\n return sequenceNumber % this.batchSize;\n }\n\n private initializeNewBatchDataArray() {\n const tempArray: IMessage[] = [];\n tempArray.length = this.batchSize; // fill with empty, undefined elements\n return tempArray;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"opsCaching.js","sourceRoot":"","sources":["../src/opsCaching.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+DAA2D;AAwB3D,MAAa,QAAQ;IAInB,YACE,sBAA8B,EACb,MAAwB,EACxB,KAAa,EACb,SAAiB,EACjB,gBAAgB,EACzB,eAAe;QAJN,WAAM,GAAN,MAAM,CAAkB;QACxB,UAAK,GAAL,KAAK,CAAQ;QACb,cAAS,GAAT,SAAS,CAAQ;QACjB,qBAAgB,GAAhB,gBAAgB,CAAA;QACzB,oBAAe,GAAf,eAAe,CAAA;QATR,YAAO,GAA+B,IAAI,GAAG,EAAE,CAAC;QAW3D;;WAEG;QACH,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,uBAAuB,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC;QACjG,IAAI,cAAc,KAAK,CAAC,EAAE;YACtB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,sBAAsB,CAAC,EAAE;gBAC1D,cAAc;gBACd,SAAS,EAAE,IAAI,CAAC,2BAA2B,EAAE;gBAC7C,KAAK,EAAE,KAAK;aACf,CAAC,CAAC;SACN;IACL,CAAC;IAEM,OAAO;QACV,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;YAC1B,YAAY,CAAC,IAAI,CAAC,KAAK,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C,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;YAC/F,IAAI,CAAC,eAAe,GAAG,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;IACP,CAAC;IAES,aAAa;QACnB,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,gBAAgB,GAAG,CAAC,EAAE;YAC1C,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;gBACzB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;gBACvB,IAAI,CAAC,QAAQ,EAAE,CAAC;YACpB,CAAC,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;SAC7B;IACL,CAAC;IAEO,cAAc,CAAC,cAAsB;QACzC,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC;IAEO,uBAAuB,CAAC,cAAsB;QAClD,OAAO,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC;IAC3C,CAAC;IAEO,2BAA2B;QAC/B,MAAM,SAAS,GAAe,EAAE,CAAC;QACjC,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,sCAAsC;QACzE,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AAtLD,4BAsLC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { performance } from \"@fluidframework/common-utils\";\n\n// ISequencedDocumentMessage\nexport interface IMessage {\n sequenceNumber: number;\n}\n\nexport type CacheEntry = (IMessage | undefined)[];\n\nexport interface IBatch {\n remainingSlots: number;\n batchData: CacheEntry;\n /**\n * Tells if this batch is dirty, i.e. it contains ops that were not flushed to cache\n */\n dirty: boolean;\n}\n\nexport interface ICache {\n write(batchNumber: string, data: string): Promise<void>;\n read(batchNumber: string): Promise<string | undefined>;\n remove(): void;\n}\n\nexport class OpsCache {\n private readonly batches: Map<number, null | IBatch> = new Map();\n private timer: ReturnType<typeof setTimeout> | undefined;\n\n constructor(\n startingSequenceNumber: number,\n private readonly logger: ITelemetryLogger,\n private readonly cache: ICache,\n private readonly batchSize: number,\n private readonly timerGranularity,\n private totalOpsToCache,\n ) {\n /** initial batch is a special case because it will never be full - all ops prior (inclusive) to\n * startingSequenceNumber are never going to show up (undefined)\n */\n const remainingSlots = this.batchSize - this.getPositionInBatchArray(startingSequenceNumber) - 1;\n if (remainingSlots !== 0) {\n this.batches.set(this.getBatchNumber(startingSequenceNumber), {\n remainingSlots,\n batchData: this.initializeNewBatchDataArray(),\n dirty: false,\n });\n }\n }\n\n public dispose() {\n this.batches.clear();\n if (this.timer !== undefined) {\n clearTimeout(this.timer);\n this.timer = undefined;\n }\n }\n\n public flushOps() {\n for (const [key, value] of this.batches) {\n if (value === null || !value.dirty) {\n continue;\n }\n value.dirty = false;\n this.write(key, value);\n }\n }\n\n public addOps(ops: IMessage[]) {\n if (this.totalOpsToCache <= 0) {\n return;\n }\n\n for (const op of ops) {\n const batchNumber = this.getBatchNumber(op.sequenceNumber);\n const positionInBatch = this.getPositionInBatchArray(op.sequenceNumber);\n\n let currentBatch = this.batches.get(batchNumber);\n\n if (currentBatch === undefined) {\n currentBatch = {\n remainingSlots: this.batchSize - 1,\n batchData: this.initializeNewBatchDataArray(),\n dirty: true,\n };\n currentBatch.batchData[positionInBatch] = op;\n this.batches.set(batchNumber, currentBatch);\n } else if (currentBatch !== null && currentBatch.batchData[positionInBatch] === undefined) {\n currentBatch.batchData[positionInBatch] = op;\n currentBatch.remainingSlots--;\n currentBatch.dirty = true;\n } else {\n // Either batch was flushed or this op was already there - nothing to do!\n return;\n }\n\n if (currentBatch.remainingSlots === 0) {\n // batch is full, flush to cache\n this.write(batchNumber, currentBatch);\n this.batches.set(batchNumber, null);\n } else {\n this.scheduleTimer();\n }\n\n this.totalOpsToCache--;\n if (this.totalOpsToCache === 0) {\n this.logger.sendPerformanceEvent({ eventName: \"CacheOpsLimitHit\" });\n this.cache.remove();\n this.dispose();\n break;\n }\n }\n }\n\n /**\n * Retrieves ops from cache\n * @param from - inclusive\n * @param to - exclusive\n * @returns ops retrieved\n */\n private async getCore(from: number, to?: number): Promise<IMessage[]> {\n const messages: IMessage[] = [];\n let batchNumber = this.getBatchNumber(from);\n // eslint-disable-next-line no-constant-condition\n while (true) {\n const res = await this.cache.read(`${this.batchSize}_${batchNumber}`);\n if (res === undefined) {\n return messages;\n }\n const result: CacheEntry = JSON.parse(res);\n for (const op of result) {\n // Note that we write out undefined, but due to JSON.stringify, it turns into null!\n if (op) {\n if (to !== undefined && op.sequenceNumber >= to) {\n return messages;\n }\n if (messages.length === 0) {\n if (op.sequenceNumber > from) {\n return messages;\n } else if (op.sequenceNumber < from) {\n continue;\n }\n }\n messages.push(op);\n } else if (messages.length !== 0) {\n return messages;\n }\n }\n\n batchNumber++;\n }\n }\n\n /**\n * Retrieves ops from cache\n * @param from - inclusive\n * @param to - exclusive\n * @returns ops retrieved\n */\n public async get(from: number, to?: number): Promise<IMessage[]> {\n const start = performance.now();\n\n const messages = await this.getCore(from, to);\n\n const duration = performance.now() - start;\n if (messages.length > 0 || duration > 1000) {\n this.logger.sendPerformanceEvent({\n eventName: \"CacheOpsUsed\",\n from,\n to,\n length: messages.length,\n duration,\n });\n }\n return messages;\n }\n\n protected write(batchNumber: number, payload: IBatch) {\n // Errors are caught and logged by PersistedCacheWithErrorHandling that sits\n // in the adapter chain of cache adapters\n this.cache.write(`${this.batchSize}_${batchNumber}`, JSON.stringify(payload.batchData)).catch(() => {\n this.totalOpsToCache = 0;\n });\n }\n\n protected scheduleTimer() {\n if (!this.timer && this.timerGranularity > 0) {\n this.timer = setTimeout(() => {\n this.timer = undefined;\n this.flushOps();\n }, this.timerGranularity);\n }\n }\n\n private getBatchNumber(sequenceNumber: number) {\n return Math.floor(sequenceNumber / this.batchSize);\n }\n\n private getPositionInBatchArray(sequenceNumber: number) {\n return sequenceNumber % this.batchSize;\n }\n\n private initializeNewBatchDataArray() {\n const tempArray: IMessage[] = [];\n tempArray.length = this.batchSize; // fill with empty, undefined elements\n return tempArray;\n }\n}\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/odsp-driver";
|
|
8
|
-
export declare const pkgVersion = "0.59.
|
|
8
|
+
export declare const pkgVersion = "0.59.3000";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/odsp-driver";
|
|
11
|
-
exports.pkgVersion = "0.59.
|
|
11
|
+
exports.pkgVersion = "0.59.3000";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,6BAA6B,CAAC;AACxC,QAAA,UAAU,GAAG,WAAW,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/odsp-driver\";\nexport const pkgVersion = \"0.59.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,6BAA6B,CAAC;AACxC,QAAA,UAAU,GAAG,WAAW,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/odsp-driver\";\nexport const pkgVersion = \"0.59.3000\";\n"]}
|
|
@@ -28,18 +28,18 @@ const fetchSnapshot_1 = require("./fetchSnapshot");
|
|
|
28
28
|
* @returns - True if the snapshot is cached, false otherwise.
|
|
29
29
|
*/
|
|
30
30
|
async function prefetchLatestSnapshot(resolvedUrl, getStorageToken, persistedCache, forceAccessTokenViaAuthorizationHeader, logger, hostSnapshotFetchOptions, enableRedeemFallback, fetchBinarySnapshotFormat, snapshotFormatFetchType) {
|
|
31
|
-
const odspLogger = odspUtils_1.createOdspLogger(telemetry_utils_1.ChildLogger.create(logger, "PrefetchSnapshot"));
|
|
32
|
-
const odspResolvedUrl = odspUtils_1.getOdspResolvedUrl(resolvedUrl);
|
|
31
|
+
const odspLogger = (0, odspUtils_1.createOdspLogger)(telemetry_utils_1.ChildLogger.create(logger, "PrefetchSnapshot"));
|
|
32
|
+
const odspResolvedUrl = (0, odspUtils_1.getOdspResolvedUrl)(resolvedUrl);
|
|
33
33
|
const resolvedUrlData = {
|
|
34
34
|
siteUrl: odspResolvedUrl.siteUrl,
|
|
35
35
|
driveId: odspResolvedUrl.driveId,
|
|
36
36
|
itemId: odspResolvedUrl.itemId,
|
|
37
37
|
};
|
|
38
|
-
const storageTokenFetcher = odspUtils_1.toInstrumentedOdspTokenFetcher(odspLogger, resolvedUrlData, getStorageToken, true /* throwOnNullToken */);
|
|
38
|
+
const storageTokenFetcher = (0, odspUtils_1.toInstrumentedOdspTokenFetcher)(odspLogger, resolvedUrlData, getStorageToken, true /* throwOnNullToken */);
|
|
39
39
|
const snapshotDownloader = async (finalOdspResolvedUrl, storageToken, snapshotOptions, controller) => {
|
|
40
|
-
return fetchSnapshot_1.downloadSnapshot(finalOdspResolvedUrl, storageToken, odspLogger, snapshotOptions, snapshotFormatFetchType, controller);
|
|
40
|
+
return (0, fetchSnapshot_1.downloadSnapshot)(finalOdspResolvedUrl, storageToken, odspLogger, snapshotOptions, snapshotFormatFetchType, controller);
|
|
41
41
|
};
|
|
42
|
-
const snapshotKey = odspUtils_1.createCacheSnapshotKey(odspResolvedUrl);
|
|
42
|
+
const snapshotKey = (0, odspUtils_1.createCacheSnapshotKey)(odspResolvedUrl);
|
|
43
43
|
let cacheP;
|
|
44
44
|
const putInCache = async (valueWithEpoch) => {
|
|
45
45
|
cacheP = persistedCache.put(snapshotKey, valueWithEpoch);
|
|
@@ -47,8 +47,8 @@ async function prefetchLatestSnapshot(resolvedUrl, getStorageToken, persistedCac
|
|
|
47
47
|
};
|
|
48
48
|
const removeEntries = async () => persistedCache.removeEntries(snapshotKey.file);
|
|
49
49
|
return telemetry_utils_1.PerformanceEvent.timedExecAsync(odspLogger, { eventName: "PrefetchLatestSnapshot" }, async () => {
|
|
50
|
-
await fetchSnapshot_1.fetchSnapshotWithRedeem(odspResolvedUrl, storageTokenFetcher, hostSnapshotFetchOptions, forceAccessTokenViaAuthorizationHeader, odspLogger, snapshotDownloader, putInCache, removeEntries, enableRedeemFallback);
|
|
51
|
-
common_utils_1.assert(cacheP !== undefined, 0x1e7 /* "caching was not performed!" */);
|
|
50
|
+
await (0, fetchSnapshot_1.fetchSnapshotWithRedeem)(odspResolvedUrl, storageTokenFetcher, hostSnapshotFetchOptions, forceAccessTokenViaAuthorizationHeader, odspLogger, snapshotDownloader, putInCache, removeEntries, enableRedeemFallback);
|
|
51
|
+
(0, common_utils_1.assert)(cacheP !== undefined, 0x1e7 /* "caching was not performed!" */);
|
|
52
52
|
await cacheP;
|
|
53
53
|
return true;
|
|
54
54
|
}).catch(async (error) => false);
|