@fluidframework/odsp-driver 0.52.0-44610 → 0.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/dist/createFile.d.ts.map +1 -1
  2. package/dist/createFile.js +5 -4
  3. package/dist/createFile.js.map +1 -1
  4. package/dist/epochTracker.d.ts +2 -1
  5. package/dist/epochTracker.d.ts.map +1 -1
  6. package/dist/epochTracker.js +50 -21
  7. package/dist/epochTracker.js.map +1 -1
  8. package/dist/fetchSnapshot.d.ts.map +1 -1
  9. package/dist/fetchSnapshot.js +15 -14
  10. package/dist/fetchSnapshot.js.map +1 -1
  11. package/dist/getFileLink.js +3 -3
  12. package/dist/getFileLink.js.map +1 -1
  13. package/dist/odspDeltaStorageService.d.ts +3 -3
  14. package/dist/odspDeltaStorageService.d.ts.map +1 -1
  15. package/dist/odspDeltaStorageService.js +7 -4
  16. package/dist/odspDeltaStorageService.js.map +1 -1
  17. package/dist/odspDocumentDeltaConnection.d.ts.map +1 -1
  18. package/dist/odspDocumentDeltaConnection.js +2 -0
  19. package/dist/odspDocumentDeltaConnection.js.map +1 -1
  20. package/dist/odspDocumentService.d.ts.map +1 -1
  21. package/dist/odspDocumentService.js +3 -3
  22. package/dist/odspDocumentService.js.map +1 -1
  23. package/dist/odspDocumentStorageManager.d.ts.map +1 -1
  24. package/dist/odspDocumentStorageManager.js +29 -26
  25. package/dist/odspDocumentStorageManager.js.map +1 -1
  26. package/dist/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
  27. package/dist/odspDriverUrlResolverForShareLink.js +4 -3
  28. package/dist/odspDriverUrlResolverForShareLink.js.map +1 -1
  29. package/dist/odspError.d.ts.map +1 -1
  30. package/dist/odspError.js +3 -1
  31. package/dist/odspError.js.map +1 -1
  32. package/dist/odspUtils.d.ts.map +1 -1
  33. package/dist/odspUtils.js +31 -22
  34. package/dist/odspUtils.js.map +1 -1
  35. package/dist/packageVersion.d.ts +1 -1
  36. package/dist/packageVersion.d.ts.map +1 -1
  37. package/dist/packageVersion.js +1 -1
  38. package/dist/packageVersion.js.map +1 -1
  39. package/dist/zipItDataRepresentationUtils.d.ts.map +1 -1
  40. package/dist/zipItDataRepresentationUtils.js +3 -3
  41. package/dist/zipItDataRepresentationUtils.js.map +1 -1
  42. package/lib/createFile.d.ts.map +1 -1
  43. package/lib/createFile.js +6 -5
  44. package/lib/createFile.js.map +1 -1
  45. package/lib/epochTracker.d.ts +2 -1
  46. package/lib/epochTracker.d.ts.map +1 -1
  47. package/lib/epochTracker.js +50 -21
  48. package/lib/epochTracker.js.map +1 -1
  49. package/lib/fetchSnapshot.d.ts.map +1 -1
  50. package/lib/fetchSnapshot.js +15 -14
  51. package/lib/fetchSnapshot.js.map +1 -1
  52. package/lib/getFileLink.js +4 -4
  53. package/lib/getFileLink.js.map +1 -1
  54. package/lib/odspDeltaStorageService.d.ts +3 -3
  55. package/lib/odspDeltaStorageService.d.ts.map +1 -1
  56. package/lib/odspDeltaStorageService.js +7 -4
  57. package/lib/odspDeltaStorageService.js.map +1 -1
  58. package/lib/odspDocumentDeltaConnection.d.ts.map +1 -1
  59. package/lib/odspDocumentDeltaConnection.js +2 -0
  60. package/lib/odspDocumentDeltaConnection.js.map +1 -1
  61. package/lib/odspDocumentService.d.ts.map +1 -1
  62. package/lib/odspDocumentService.js +4 -4
  63. package/lib/odspDocumentService.js.map +1 -1
  64. package/lib/odspDocumentStorageManager.d.ts.map +1 -1
  65. package/lib/odspDocumentStorageManager.js +31 -28
  66. package/lib/odspDocumentStorageManager.js.map +1 -1
  67. package/lib/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
  68. package/lib/odspDriverUrlResolverForShareLink.js +5 -4
  69. package/lib/odspDriverUrlResolverForShareLink.js.map +1 -1
  70. package/lib/odspError.d.ts.map +1 -1
  71. package/lib/odspError.js +3 -1
  72. package/lib/odspError.js.map +1 -1
  73. package/lib/odspUtils.d.ts.map +1 -1
  74. package/lib/odspUtils.js +33 -24
  75. package/lib/odspUtils.js.map +1 -1
  76. package/lib/packageVersion.d.ts +1 -1
  77. package/lib/packageVersion.d.ts.map +1 -1
  78. package/lib/packageVersion.js +1 -1
  79. package/lib/packageVersion.js.map +1 -1
  80. package/lib/zipItDataRepresentationUtils.d.ts.map +1 -1
  81. package/lib/zipItDataRepresentationUtils.js +3 -3
  82. package/lib/zipItDataRepresentationUtils.js.map +1 -1
  83. package/package.json +12 -12
  84. package/src/createFile.ts +13 -9
  85. package/src/epochTracker.ts +50 -20
  86. package/src/fetchSnapshot.ts +15 -8
  87. package/src/getFileLink.ts +10 -4
  88. package/src/odspDeltaStorageService.ts +10 -3
  89. package/src/odspDocumentDeltaConnection.ts +2 -0
  90. package/src/odspDocumentService.ts +8 -4
  91. package/src/odspDocumentStorageManager.ts +48 -28
  92. package/src/odspDriverUrlResolverForShareLink.ts +8 -3
  93. package/src/odspError.ts +5 -1
  94. package/src/odspUtils.ts +43 -34
  95. package/src/packageVersion.ts +1 -1
  96. package/src/zipItDataRepresentationUtils.ts +4 -7
@@ -1 +1 @@
1
- {"version":3,"file":"createFile.d.ts","sourceRoot":"","sources":["../src/createFile.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,EAAe,YAAY,EAAgB,MAAM,sCAAsC,CAAC;AAC/F,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAEtE,OAAO,EACH,UAAU,EACV,+BAA+B,EAC/B,gBAAgB,EACnB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACH,gBAAgB,EAGhB,mBAAmB,EAEtB,MAAM,aAAa,CAAC;AAErB,OAAO,EAGH,YAAY,EAGf,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAU9C;;;GAGG;AACH,wBAAsB,kBAAkB,CACpC,eAAe,EAAE,+BAA+B,EAChD,WAAW,EAAE,YAAY,EACzB,MAAM,EAAE,gBAAgB,EACxB,gBAAgB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,gBAAgB,EAAE,OAAO,GAC1B,OAAO,CAAC,gBAAgB,CAAC,CA8C3B;AAED,wBAAsB,uBAAuB,CACzC,eAAe,EAAE,+BAA+B,EAChD,WAAW,EAAE,YAAY,EACzB,MAAM,EAAE,gBAAgB,EACxB,YAAY,EAAE,YAAY,GAC3B,OAAO,CAAC,MAAM,CAAC,CA+CjB;AAED,wBAAsB,6BAA6B,CAC/C,eAAe,EAAE,+BAA+B,EAChD,WAAW,EAAE,YAAY,EACzB,MAAM,EAAE,gBAAgB,EACxB,gBAAgB,EAAE,YAAY,EAC9B,YAAY,EAAE,YAAY,GAC3B,OAAO,CAAC,mBAAmB,CAAC,CAmD9B;AA+BD;;GAEG;AACH,wBAAgB,wCAAwC,CAAC,OAAO,EAAE,YAAY,GAAG,gBAAgB,CAoDhG"}
@@ -7,10 +7,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.convertSummaryToSnapshotTreeForCreateNew = exports.createNewFluidFileFromSummary = exports.createNewEmptyFluidFile = exports.createNewFluidFile = void 0;
8
8
  const common_utils_1 = require("@fluidframework/common-utils");
9
9
  const driver_utils_1 = require("@fluidframework/driver-utils");
10
- const odsp_doclib_utils_1 = require("@fluidframework/odsp-doclib-utils");
11
10
  const protocol_base_1 = require("@fluidframework/protocol-base");
12
11
  const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
13
12
  const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
13
+ const odsp_driver_definitions_1 = require("@fluidframework/odsp-driver-definitions");
14
+ const driver_definitions_1 = require("@fluidframework/driver-definitions");
14
15
  const getUrlAndHeadersWithAuth_1 = require("./getUrlAndHeadersWithAuth");
15
16
  const odspUtils_1 = require("./odspUtils");
16
17
  const createOdspUrl_1 = require("./createOdspUrl");
@@ -29,7 +30,7 @@ const isInvalidFileName = (fileName) => {
29
30
  async function createNewFluidFile(getStorageToken, newFileInfo, logger, createNewSummary, epochTracker, fileEntry, createNewCaching) {
30
31
  // Check for valid filename before the request to create file is actually made.
31
32
  if (isInvalidFileName(newFileInfo.filename)) {
32
- odsp_doclib_utils_1.throwOdspNetworkError("invalidFilename", odsp_doclib_utils_1.invalidFileNameStatusCode);
33
+ throw new driver_utils_1.NonRetryableError("createNewInvalidFilename", "Invalid filename", odsp_driver_definitions_1.OdspErrorType.invalidFileNameError);
33
34
  }
34
35
  let itemId;
35
36
  let summaryHandle = "";
@@ -86,7 +87,7 @@ async function createNewEmptyFluidFile(getStorageToken, newFileInfo, logger, epo
86
87
  }, "createFile"), "createFile", logger);
87
88
  const content = fetchResponse.content;
88
89
  if (!content || !content.id) {
89
- odsp_doclib_utils_1.throwOdspNetworkError("couldNotParseItemFromVroomResponse", odsp_doclib_utils_1.fetchIncorrectResponse);
90
+ throw new driver_utils_1.NonRetryableError("createEmptyFileNoItemId", "ODSP CreateFile call returned no item ID", driver_definitions_1.DriverErrorType.incorrectServerResponse);
90
91
  }
91
92
  event.end(Object.assign({ headers: Object.keys(headers).length !== 0 ? true : undefined }, fetchResponse.commonSpoHeaders));
92
93
  return content.id;
@@ -114,7 +115,7 @@ async function createNewFluidFileFromSummary(getStorageToken, newFileInfo, logge
114
115
  }, "createFile"), "createFile", logger);
115
116
  const content = fetchResponse.content;
116
117
  if (!content || !content.itemId) {
117
- odsp_doclib_utils_1.throwOdspNetworkError("couldNotParseItemFromVroomResponse", odsp_doclib_utils_1.fetchIncorrectResponse);
118
+ throw new driver_utils_1.NonRetryableError("createFileNoItemId", "ODSP CreateFile call returned no item ID", driver_definitions_1.DriverErrorType.incorrectServerResponse);
118
119
  }
119
120
  event.end(Object.assign({ headers: Object.keys(headers).length !== 0 ? true : undefined, attempts: options.refresh ? 2 : 1 }, fetchResponse.commonSpoHeaders));
120
121
  return content;
@@ -1 +1 @@
1
- {"version":3,"file":"createFile.js","sourceRoot":"","sources":["../src/createFile.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA0E;AAC1E,+DAAmF;AACnF,yEAI2C;AAC3C,iEAA2D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K,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;gBAEhF,KAAK,GAAG;oBACJ,IAAI,EAAE,MAAM;oBACZ,OAAO;oBACP,QAAQ;iBACX,CAAC;gBACF,MAAM;aACT;YACD,KAAK,kCAAW,CAAC,MAAM,CAAC,CAAC;gBACrB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;aACtE;YACD,OAAO,CAAC,CAAC;gBACL,MAAM,IAAI,KAAK,CAAC,qBAAqB,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;aAC9D;SACJ;QAED,MAAM,KAAK,GAAyB;YAChC,IAAI,EAAE,kBAAkB,CAAC,GAAG,CAAC;YAC7B,IAAI,EAAE,0BAAU,CAAC,aAAa,CAAC;YAC/B,KAAK;YACL,YAAY;SACf,CAAC;QACF,MAAA,YAAY,CAAC,OAAO,0CAAE,IAAI,CAAC,KAAK,EAAE;KACrC;IAED,OAAO,YAAY,CAAC;AACxB,CAAC;AApDD,4FAoDC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, Uint8ArrayToString } from \"@fluidframework/common-utils\";\nimport { getDocAttributesFromProtocolSummary } from \"@fluidframework/driver-utils\";\nimport {\n fetchIncorrectResponse,\n invalidFileNameStatusCode,\n throwOdspNetworkError,\n} from \"@fluidframework/odsp-doclib-utils\";\nimport { getGitType } from \"@fluidframework/protocol-base\";\nimport { SummaryType, ISummaryTree, ISummaryBlob } from \"@fluidframework/protocol-definitions\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport {\n IFileEntry,\n InstrumentedStorageTokenFetcher,\n IOdspResolvedUrl,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport {\n IOdspSummaryTree,\n OdspSummaryTreeValue,\n OdspSummaryTreeEntry,\n ICreateFileResponse,\n IOdspSummaryPayload,\n} from \"./contracts\";\nimport { getUrlAndHeadersWithAuth } from \"./getUrlAndHeadersWithAuth\";\nimport {\n createCacheSnapshotKey,\n getWithRetryForTokenRefresh,\n INewFileInfo,\n getOrigin,\n ISnapshotContents,\n} from \"./odspUtils\";\nimport { createOdspUrl } from \"./createOdspUrl\";\nimport { getApiRoot } from \"./odspUrlHelper\";\nimport { EpochTracker } from \"./epochTracker\";\nimport { OdspDriverUrlResolver } from \"./odspDriverUrlResolver\";\nimport { convertCreateNewSummaryTreeToTreeAndBlobs } from \"./createNewUtils\";\nimport { runWithRetry } from \"./retryUtils\";\n\nconst isInvalidFileName = (fileName: string): boolean => {\n const invalidCharsRegex = /[\"*/:<>?\\\\|]+/g;\n return !!fileName.match(invalidCharsRegex);\n};\n\n/**\n * Creates a new Fluid file.\n * Returns resolved url\n */\nexport async function createNewFluidFile(\n getStorageToken: InstrumentedStorageTokenFetcher,\n newFileInfo: INewFileInfo,\n logger: ITelemetryLogger,\n createNewSummary: ISummaryTree | undefined,\n epochTracker: EpochTracker,\n fileEntry: IFileEntry,\n createNewCaching: boolean,\n): Promise<IOdspResolvedUrl> {\n // Check for valid filename before the request to create file is actually made.\n if (isInvalidFileName(newFileInfo.filename)) {\n throwOdspNetworkError(\"invalidFilename\", invalidFileNameStatusCode);\n }\n\n let itemId: string;\n let summaryHandle: string = \"\";\n let sharingLink: string | undefined;\n let sharingLinkErrorReason: string | undefined;\n if (createNewSummary === undefined) {\n itemId = await createNewEmptyFluidFile(getStorageToken, newFileInfo, logger, epochTracker);\n } else {\n const content = await createNewFluidFileFromSummary(\n getStorageToken, newFileInfo, logger, createNewSummary, epochTracker);\n itemId = content.itemId;\n summaryHandle = content.id;\n sharingLink = content.sharingLink;\n sharingLinkErrorReason = content.sharingLinkErrorReason;\n }\n\n const odspUrl = createOdspUrl({... newFileInfo, itemId, dataStorePath: \"/\"});\n const resolver = new OdspDriverUrlResolver();\n const odspResolvedUrl = await resolver.resolve({ url: odspUrl });\n fileEntry.docId = odspResolvedUrl.hashedDocumentId;\n fileEntry.resolvedUrl = odspResolvedUrl;\n\n if(sharingLink || sharingLinkErrorReason) {\n odspResolvedUrl.shareLinkInfo = {\n createLink: {\n type: newFileInfo.createLinkType,\n link: sharingLink,\n error: sharingLinkErrorReason,\n },\n };\n }\n\n if (createNewSummary !== undefined && createNewCaching) {\n assert(summaryHandle !== undefined, 0x203 /* \"Summary handle is undefined\" */);\n // converting summary and getting sequence number\n const snapshot: ISnapshotContents = convertCreateNewSummaryTreeToTreeAndBlobs(createNewSummary, summaryHandle);\n // caching the converted summary\n await epochTracker.put(createCacheSnapshotKey(odspResolvedUrl), snapshot);\n }\n return odspResolvedUrl;\n}\n\nexport async function createNewEmptyFluidFile(\n getStorageToken: InstrumentedStorageTokenFetcher,\n newFileInfo: INewFileInfo,\n logger: ITelemetryLogger,\n epochTracker: EpochTracker,\n): Promise<string> {\n const filePath = newFileInfo.filePath ? encodeURIComponent(`/${newFileInfo.filePath}`) : \"\";\n // add .tmp extension to empty file (host is expected to rename)\n const encodedFilename = encodeURIComponent(`${newFileInfo.filename}.tmp`);\n const initialUrl =\n `${getApiRoot(getOrigin(newFileInfo.siteUrl))}/drives/${newFileInfo.driveId}/items/root:/${filePath\n }/${encodedFilename}:/content?@name.conflictBehavior=rename&select=id,name,parentReference`;\n\n return getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await getStorageToken(options, \"CreateNewFile\");\n\n return PerformanceEvent.timedExecAsync(\n logger,\n { eventName: \"createNewEmptyFile\" },\n async (event) => {\n const { url, headers } = getUrlAndHeadersWithAuth(initialUrl, storageToken);\n headers[\"Content-Type\"] = \"application/json\";\n\n const fetchResponse = await runWithRetry(\n async () => epochTracker.fetchAndParseAsJSON<ICreateFileResponse>(\n url,\n {\n body: undefined,\n headers,\n method: \"PUT\",\n },\n \"createFile\",\n ),\n \"createFile\",\n logger,\n );\n\n const content = fetchResponse.content;\n if (!content || !content.id) {\n throwOdspNetworkError(\"couldNotParseItemFromVroomResponse\", fetchIncorrectResponse);\n }\n event.end({\n headers: Object.keys(headers).length !== 0 ? true : undefined,\n ...fetchResponse.commonSpoHeaders,\n });\n return content.id;\n },\n { end: true, cancel: \"error\" });\n });\n}\n\nexport async function createNewFluidFileFromSummary(\n getStorageToken: InstrumentedStorageTokenFetcher,\n newFileInfo: INewFileInfo,\n logger: ITelemetryLogger,\n createNewSummary: ISummaryTree,\n epochTracker: EpochTracker,\n): Promise<ICreateFileResponse> {\n const filePath = newFileInfo.filePath ? encodeURIComponent(`/${newFileInfo.filePath}`) : \"\";\n const encodedFilename = encodeURIComponent(newFileInfo.filename);\n const baseUrl =\n `${getApiRoot(getOrigin(newFileInfo.siteUrl))}/drives/${newFileInfo.driveId}/items/root:` +\n `${filePath}/${encodedFilename}`;\n\n const containerSnapshot = convertSummaryIntoContainerSnapshot(createNewSummary);\n const initialUrl = `${baseUrl}:/opStream/snapshots/snapshot${newFileInfo.createLinkType ?\n `?createLinkType=${newFileInfo.createLinkType}` : \"\"}`;\n\n return getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await getStorageToken(options, \"CreateNewFile\");\n\n return PerformanceEvent.timedExecAsync(\n logger,\n { eventName: \"createNewFile\" },\n async (event) => {\n const { url, headers } = getUrlAndHeadersWithAuth(initialUrl, storageToken);\n headers[\"Content-Type\"] = \"application/json\";\n\n const fetchResponse = await runWithRetry(\n async () => epochTracker.fetchAndParseAsJSON<ICreateFileResponse>(\n url,\n {\n body: JSON.stringify(containerSnapshot),\n headers,\n method: \"POST\",\n },\n \"createFile\",\n ),\n \"createFile\",\n logger,\n );\n\n const content = fetchResponse.content;\n if (!content || !content.itemId) {\n throwOdspNetworkError(\"couldNotParseItemFromVroomResponse\", fetchIncorrectResponse);\n }\n event.end({\n headers: Object.keys(headers).length !== 0 ? true : undefined,\n attempts: options.refresh ? 2 : 1,\n ...fetchResponse.commonSpoHeaders,\n });\n return content;\n },\n );\n });\n}\n\nfunction convertSummaryIntoContainerSnapshot(createNewSummary: ISummaryTree) {\n const appSummary = createNewSummary.tree[\".app\"] as ISummaryTree;\n const protocolSummary = createNewSummary.tree[\".protocol\"] as ISummaryTree;\n if (!(appSummary && protocolSummary)) {\n throw new Error(\"App and protocol summary required for create new path!!\");\n }\n const documentAttributes = getDocAttributesFromProtocolSummary(protocolSummary);\n const attributesSummaryBlob: ISummaryBlob = {\n type: SummaryType.Blob,\n content: JSON.stringify(documentAttributes),\n };\n protocolSummary.tree.attributes = attributesSummaryBlob;\n const convertedCreateNewSummary: ISummaryTree = {\n type: SummaryType.Tree,\n tree: {\n \".protocol\": protocolSummary,\n \".app\": appSummary,\n },\n };\n const snapshotTree = convertSummaryToSnapshotTreeForCreateNew(convertedCreateNewSummary);\n const snapshot: IOdspSummaryPayload = {\n entries: snapshotTree.entries ?? [],\n message: \"app\",\n sequenceNumber: documentAttributes.sequenceNumber,\n type: \"container\",\n };\n return snapshot;\n}\n\n/**\n * Converts a summary tree to ODSP tree\n */\nexport function convertSummaryToSnapshotTreeForCreateNew(summary: ISummaryTree): IOdspSummaryTree {\n const snapshotTree: IOdspSummaryTree = {\n type: \"tree\",\n entries: [],\n };\n\n const keys = Object.keys(summary.tree);\n for (const key of keys) {\n const summaryObject = summary.tree[key];\n\n let value: OdspSummaryTreeValue;\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 true,\n // the tree entry is considered unreferenced.\n let unreferenced: true | undefined;\n\n switch (summaryObject.type) {\n case SummaryType.Tree: {\n value = convertSummaryToSnapshotTreeForCreateNew(summaryObject);\n unreferenced = summaryObject.unreferenced;\n break;\n }\n case SummaryType.Blob: {\n const content = typeof summaryObject.content === \"string\" ?\n summaryObject.content : Uint8ArrayToString(summaryObject.content, \"base64\");\n const encoding = typeof summaryObject.content === \"string\" ? \"utf-8\" : \"base64\";\n\n value = {\n type: \"blob\",\n content,\n encoding,\n };\n break;\n }\n case SummaryType.Handle: {\n throw new Error(\"No handle should be present for first summary!!\");\n }\n default: {\n throw new Error(`Unknown tree type ${summaryObject.type}`);\n }\n }\n\n const entry: OdspSummaryTreeEntry = {\n path: encodeURIComponent(key),\n type: getGitType(summaryObject),\n value,\n unreferenced,\n };\n snapshotTree.entries?.push(entry);\n }\n\n return snapshotTree;\n}\n"]}
1
+ {"version":3,"file":"createFile.js","sourceRoot":"","sources":["../src/createFile.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA0E;AAC1E,+DAAsG;AACtG,iEAA2D;AAC3D,+EAA+F;AAE/F,qEAAmE;AACnE,qFAKiD;AACjD,2EAAqE;AAQrE,yEAAsE;AACtE,2CAMqB;AACrB,mDAAgD;AAChD,mDAA6C;AAE7C,mEAAgE;AAChE,qDAA6E;AAC7E,6CAA4C;AAE5C,MAAM,iBAAiB,GAAG,CAAC,QAAgB,EAAW,EAAE;IACpD,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;IAC3C,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;AAC/C,CAAC,CAAC;AAEF;;;GAGG;AACI,KAAK,UAAU,kBAAkB,CACpC,eAAgD,EAChD,WAAyB,EACzB,MAAwB,EACxB,gBAA0C,EAC1C,YAA0B,EAC1B,SAAqB,EACrB,gBAAyB;IAEzB,+EAA+E;IAC/E,IAAI,iBAAiB,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE;QACzC,MAAM,IAAI,gCAAiB,CACvB,0BAA0B,EAAE,kBAAkB,EAAE,uCAAa,CAAC,oBAAoB,CAAC,CAAC;KAC3F;IAED,IAAI,MAAc,CAAC;IACnB,IAAI,aAAa,GAAW,EAAE,CAAC;IAC/B,IAAI,WAA+B,CAAC;IACpC,IAAI,sBAA0C,CAAC;IAC/C,IAAI,gBAAgB,KAAK,SAAS,EAAE;QAChC,MAAM,GAAG,MAAM,uBAAuB,CAAC,eAAe,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;KAC9F;SA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AEnC,QAAQ,aAAa,CAAC,IAAI,EAAE;YACxB,KAAK,kCAAW,CAAC,IAAI,CAAC,CAAC;gBACnB,KAAK,GAAG,wCAAwC,CAAC,aAAa,CAAC,CAAC;gBAChE,YAAY,GAAG,aAAa,CAAC,YAAY,CAAC;gBAC1C,MAAM;aACT;YACD,KAAK,kCAAW,CAAC,IAAI,CAAC,CAAC;gBACnB,MAAM,OAAO,GAAG,OAAO,aAAa,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC;oBACvD,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,iCAAkB,CAAC,aAAa,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;gBAChF,MAAM,QAAQ,GAAG,OAAO,aAAa,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;gBAEhF,KAAK,GAAG;oBACJ,IAAI,EAAE,MAAM;oBACZ,OAAO;oBACP,QAAQ;iBACX,CAAC;gBACF,MAAM;aACT;YACD,KAAK,kCAAW,CAAC,MAAM,CAAC,CAAC;gBACrB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;aACtE;YACD,OAAO,CAAC,CAAC;gBACL,MAAM,IAAI,KAAK,CAAC,qBAAqB,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;aAC9D;SACJ;QAED,MAAM,KAAK,GAAyB;YAChC,IAAI,EAAE,kBAAkB,CAAC,GAAG,CAAC;YAC7B,IAAI,EAAE,0BAAU,CAAC,aAAa,CAAC;YAC/B,KAAK;YACL,YAAY;SACf,CAAC;QACF,MAAA,YAAY,CAAC,OAAO,0CAAE,IAAI,CAAC,KAAK,EAAE;KACrC;IAED,OAAO,YAAY,CAAC;AACxB,CAAC;AApDD,4FAoDC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, Uint8ArrayToString } from \"@fluidframework/common-utils\";\nimport { getDocAttributesFromProtocolSummary, NonRetryableError } from \"@fluidframework/driver-utils\";\nimport { getGitType } from \"@fluidframework/protocol-base\";\nimport { SummaryType, ISummaryTree, ISummaryBlob } from \"@fluidframework/protocol-definitions\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport {\n IFileEntry,\n InstrumentedStorageTokenFetcher,\n IOdspResolvedUrl,\n OdspErrorType,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport { DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport {\n IOdspSummaryTree,\n OdspSummaryTreeValue,\n OdspSummaryTreeEntry,\n ICreateFileResponse,\n IOdspSummaryPayload,\n} from \"./contracts\";\nimport { getUrlAndHeadersWithAuth } from \"./getUrlAndHeadersWithAuth\";\nimport {\n createCacheSnapshotKey,\n getWithRetryForTokenRefresh,\n INewFileInfo,\n getOrigin,\n ISnapshotContents,\n} from \"./odspUtils\";\nimport { createOdspUrl } from \"./createOdspUrl\";\nimport { getApiRoot } from \"./odspUrlHelper\";\nimport { EpochTracker } from \"./epochTracker\";\nimport { OdspDriverUrlResolver } from \"./odspDriverUrlResolver\";\nimport { convertCreateNewSummaryTreeToTreeAndBlobs } from \"./createNewUtils\";\nimport { runWithRetry } from \"./retryUtils\";\n\nconst isInvalidFileName = (fileName: string): boolean => {\n const invalidCharsRegex = /[\"*/:<>?\\\\|]+/g;\n return !!fileName.match(invalidCharsRegex);\n};\n\n/**\n * Creates a new Fluid file.\n * Returns resolved url\n */\nexport async function createNewFluidFile(\n getStorageToken: InstrumentedStorageTokenFetcher,\n newFileInfo: INewFileInfo,\n logger: ITelemetryLogger,\n createNewSummary: ISummaryTree | undefined,\n epochTracker: EpochTracker,\n fileEntry: IFileEntry,\n createNewCaching: boolean,\n): Promise<IOdspResolvedUrl> {\n // Check for valid filename before the request to create file is actually made.\n if (isInvalidFileName(newFileInfo.filename)) {\n throw new NonRetryableError(\n \"createNewInvalidFilename\", \"Invalid filename\", OdspErrorType.invalidFileNameError);\n }\n\n let itemId: string;\n let summaryHandle: string = \"\";\n let sharingLink: string | undefined;\n let sharingLinkErrorReason: string | undefined;\n if (createNewSummary === undefined) {\n itemId = await createNewEmptyFluidFile(getStorageToken, newFileInfo, logger, epochTracker);\n } else {\n const content = await createNewFluidFileFromSummary(\n getStorageToken, newFileInfo, logger, createNewSummary, epochTracker);\n itemId = content.itemId;\n summaryHandle = content.id;\n sharingLink = content.sharingLink;\n sharingLinkErrorReason = content.sharingLinkErrorReason;\n }\n\n const odspUrl = createOdspUrl({... newFileInfo, itemId, dataStorePath: \"/\"});\n const resolver = new OdspDriverUrlResolver();\n const odspResolvedUrl = await resolver.resolve({ url: odspUrl });\n fileEntry.docId = odspResolvedUrl.hashedDocumentId;\n fileEntry.resolvedUrl = odspResolvedUrl;\n\n if(sharingLink || sharingLinkErrorReason) {\n odspResolvedUrl.shareLinkInfo = {\n createLink: {\n type: newFileInfo.createLinkType,\n link: sharingLink,\n error: sharingLinkErrorReason,\n },\n };\n }\n\n if (createNewSummary !== undefined && createNewCaching) {\n assert(summaryHandle !== undefined, 0x203 /* \"Summary handle is undefined\" */);\n // converting summary and getting sequence number\n const snapshot: ISnapshotContents = convertCreateNewSummaryTreeToTreeAndBlobs(createNewSummary, summaryHandle);\n // caching the converted summary\n await epochTracker.put(createCacheSnapshotKey(odspResolvedUrl), snapshot);\n }\n return odspResolvedUrl;\n}\n\nexport async function createNewEmptyFluidFile(\n getStorageToken: InstrumentedStorageTokenFetcher,\n newFileInfo: INewFileInfo,\n logger: ITelemetryLogger,\n epochTracker: EpochTracker,\n): Promise<string> {\n const filePath = newFileInfo.filePath ? encodeURIComponent(`/${newFileInfo.filePath}`) : \"\";\n // add .tmp extension to empty file (host is expected to rename)\n const encodedFilename = encodeURIComponent(`${newFileInfo.filename}.tmp`);\n const initialUrl =\n `${getApiRoot(getOrigin(newFileInfo.siteUrl))}/drives/${newFileInfo.driveId}/items/root:/${filePath\n }/${encodedFilename}:/content?@name.conflictBehavior=rename&select=id,name,parentReference`;\n\n return getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await getStorageToken(options, \"CreateNewFile\");\n\n return PerformanceEvent.timedExecAsync(\n logger,\n { eventName: \"createNewEmptyFile\" },\n async (event) => {\n const { url, headers } = getUrlAndHeadersWithAuth(initialUrl, storageToken);\n headers[\"Content-Type\"] = \"application/json\";\n\n const fetchResponse = await runWithRetry(\n async () => epochTracker.fetchAndParseAsJSON<ICreateFileResponse>(\n url,\n {\n body: undefined,\n headers,\n method: \"PUT\",\n },\n \"createFile\",\n ),\n \"createFile\",\n logger,\n );\n\n const content = fetchResponse.content;\n if (!content || !content.id) {\n throw new NonRetryableError(\n \"createEmptyFileNoItemId\",\n \"ODSP CreateFile call returned no item ID\",\n DriverErrorType.incorrectServerResponse);\n }\n event.end({\n headers: Object.keys(headers).length !== 0 ? true : undefined,\n ...fetchResponse.commonSpoHeaders,\n });\n return content.id;\n },\n { end: true, cancel: \"error\" });\n });\n}\n\nexport async function createNewFluidFileFromSummary(\n getStorageToken: InstrumentedStorageTokenFetcher,\n newFileInfo: INewFileInfo,\n logger: ITelemetryLogger,\n createNewSummary: ISummaryTree,\n epochTracker: EpochTracker,\n): Promise<ICreateFileResponse> {\n const filePath = newFileInfo.filePath ? encodeURIComponent(`/${newFileInfo.filePath}`) : \"\";\n const encodedFilename = encodeURIComponent(newFileInfo.filename);\n const baseUrl =\n `${getApiRoot(getOrigin(newFileInfo.siteUrl))}/drives/${newFileInfo.driveId}/items/root:` +\n `${filePath}/${encodedFilename}`;\n\n const containerSnapshot = convertSummaryIntoContainerSnapshot(createNewSummary);\n const initialUrl = `${baseUrl}:/opStream/snapshots/snapshot${newFileInfo.createLinkType ?\n `?createLinkType=${newFileInfo.createLinkType}` : \"\"}`;\n\n return getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await getStorageToken(options, \"CreateNewFile\");\n\n return PerformanceEvent.timedExecAsync(\n logger,\n { eventName: \"createNewFile\" },\n async (event) => {\n const { url, headers } = getUrlAndHeadersWithAuth(initialUrl, storageToken);\n headers[\"Content-Type\"] = \"application/json\";\n\n const fetchResponse = await runWithRetry(\n async () => epochTracker.fetchAndParseAsJSON<ICreateFileResponse>(\n url,\n {\n body: JSON.stringify(containerSnapshot),\n headers,\n method: \"POST\",\n },\n \"createFile\",\n ),\n \"createFile\",\n logger,\n );\n\n const content = fetchResponse.content;\n if (!content || !content.itemId) {\n throw new NonRetryableError(\n \"createFileNoItemId\",\n \"ODSP CreateFile call returned no item ID\",\n DriverErrorType.incorrectServerResponse);\n }\n event.end({\n headers: Object.keys(headers).length !== 0 ? true : undefined,\n attempts: options.refresh ? 2 : 1,\n ...fetchResponse.commonSpoHeaders,\n });\n return content;\n },\n );\n });\n}\n\nfunction convertSummaryIntoContainerSnapshot(createNewSummary: ISummaryTree) {\n const appSummary = createNewSummary.tree[\".app\"] as ISummaryTree;\n const protocolSummary = createNewSummary.tree[\".protocol\"] as ISummaryTree;\n if (!(appSummary && protocolSummary)) {\n throw new Error(\"App and protocol summary required for create new path!!\");\n }\n const documentAttributes = getDocAttributesFromProtocolSummary(protocolSummary);\n const attributesSummaryBlob: ISummaryBlob = {\n type: SummaryType.Blob,\n content: JSON.stringify(documentAttributes),\n };\n protocolSummary.tree.attributes = attributesSummaryBlob;\n const convertedCreateNewSummary: ISummaryTree = {\n type: SummaryType.Tree,\n tree: {\n \".protocol\": protocolSummary,\n \".app\": appSummary,\n },\n };\n const snapshotTree = convertSummaryToSnapshotTreeForCreateNew(convertedCreateNewSummary);\n const snapshot: IOdspSummaryPayload = {\n entries: snapshotTree.entries ?? [],\n message: \"app\",\n sequenceNumber: documentAttributes.sequenceNumber,\n type: \"container\",\n };\n return snapshot;\n}\n\n/**\n * Converts a summary tree to ODSP tree\n */\nexport function convertSummaryToSnapshotTreeForCreateNew(summary: ISummaryTree): IOdspSummaryTree {\n const snapshotTree: IOdspSummaryTree = {\n type: \"tree\",\n entries: [],\n };\n\n const keys = Object.keys(summary.tree);\n for (const key of keys) {\n const summaryObject = summary.tree[key];\n\n let value: OdspSummaryTreeValue;\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 true,\n // the tree entry is considered unreferenced.\n let unreferenced: true | undefined;\n\n switch (summaryObject.type) {\n case SummaryType.Tree: {\n value = convertSummaryToSnapshotTreeForCreateNew(summaryObject);\n unreferenced = summaryObject.unreferenced;\n break;\n }\n case SummaryType.Blob: {\n const content = typeof summaryObject.content === \"string\" ?\n summaryObject.content : Uint8ArrayToString(summaryObject.content, \"base64\");\n const encoding = typeof summaryObject.content === \"string\" ? \"utf-8\" : \"base64\";\n\n value = {\n type: \"blob\",\n content,\n encoding,\n };\n break;\n }\n case SummaryType.Handle: {\n throw new Error(\"No handle should be present for first summary!!\");\n }\n default: {\n throw new Error(`Unknown tree type ${summaryObject.type}`);\n }\n }\n\n const entry: OdspSummaryTreeEntry = {\n path: encodeURIComponent(key),\n type: getGitType(summaryObject),\n value,\n unreferenced,\n };\n snapshotTree.entries?.push(entry);\n }\n\n return snapshotTree;\n}\n"]}
@@ -11,6 +11,7 @@ import { IOdspCache, INonPersistentCache, IPersistedFileCache } from "./odspCach
11
11
  export declare type FetchType = "blob" | "createBlob" | "createFile" | "joinSession" | "ops" | "test" | "snapshotTree" | "treesLatest" | "uploadSummary" | "push" | "versions";
12
12
  export declare type FetchTypeInternal = FetchType | "cache";
13
13
  export declare const Odsp409Error = "Odsp409Error";
14
+ export declare const defaultCacheExpiryTimeoutMs: number;
14
15
  /**
15
16
  * This class is a wrapper around fetch calls. It adds epoch to the request made so that the
16
17
  * server can match it with its epoch value in order to match the version.
@@ -52,7 +53,7 @@ export declare class EpochTracker implements IPersistedFileCache {
52
53
  }, fetchType: FetchType, addInBody?: boolean): Promise<IOdspResponse<ArrayBuffer>>;
53
54
  private addEpochInRequest;
54
55
  private addParamInBody;
55
- private formatClientCorelationId;
56
+ private formatClientCorrelationId;
56
57
  protected validateEpochFromResponse(epochFromResponse: string | undefined, fetchType: FetchTypeInternal, fromCache?: boolean): void;
57
58
  private checkForEpochError;
58
59
  private checkForEpochErrorCore;
@@ -1 +1 @@
1
- {"version":3,"file":"epochTracker.d.ts","sourceRoot":"","sources":["../src/epochTracker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAEtE,OAAO,EAAmB,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAClE,OAAO,EAGH,MAAM,EACN,UAAU,EACV,eAAe,EAElB,MAAM,yCAAyC,CAAC;AAGjD,OAAO,EAAyC,aAAa,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EACH,UAAU,EACV,mBAAmB,EACnB,mBAAmB,EACrB,MAAM,aAAa,CAAC;AAGtB,oBAAY,SAAS,GAAG,MAAM,GAAG,YAAY,GAAG,YAAY,GAAG,aAAa,GAAG,KAAK,GAAG,MAAM,GAAG,cAAc,GAC1G,aAAa,GAAG,eAAe,GAAG,MAAM,GAAG,UAAU,CAAC;AAE1D,oBAAY,iBAAiB,GAAG,SAAS,GAAG,OAAO,CAAC;AAEpD,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAE3C;;;;;GAKG;AACH,qBAAa,YAAa,YAAW,mBAAmB;IAQhD,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,eAAe;IACzC,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,UAAU;IACxC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,gBAAgB;IAT/C,OAAO,CAAC,WAAW,CAAqB;IAExC,SAAgB,WAAW,EAAE,WAAW,CAAC;IACzC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IAEnC,OAAO,CAAC,iBAAiB,CAAK;gBAEP,KAAK,EAAE,eAAe,EACtB,SAAS,EAAE,UAAU,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CAAC,yBAAyB,CAC/B,iBAAiB,EAAE,MAAM,GAAG,SAAS,EACrC,SAAS,EAAE,iBAAiB,EAC5B,SAAS,GAAE,OAAe;YAahB,kBAAkB;IA4BhC,OAAO,CAAC,sBAAsB;IAW9B,OAAO,CAAC,kBAAkB;CAG7B;AAED,qBAAa,0BAA2B,SAAQ,YAAY;IACxD,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAwB;IAE5D,SAAS,CAAC,yBAAyB,CAC/B,iBAAiB,EAAE,MAAM,GAAG,SAAS,EACrC,SAAS,EAAE,SAAS,EACpB,SAAS,GAAE,OAAe;IAUjB,GAAG,CACZ,KAAK,EAAE,MAAM,GACd,OAAO,CAAC,GAAG,CAAC;IAuBF,mBAAmB,CAAC,CAAC,EAC9B,GAAG,EAAE,MAAM,EACX,YAAY,EAAE;QAAC,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,EACpC,SAAS,EAAE,SAAS,EACpB,SAAS,GAAE,OAAe,GAC3B,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;CAgD/B;AAED,MAAM,WAAW,gBAAgB;IAC7B,KAAK,EAAE,UAAU,CAAC;IAClB,YAAY,EAAE,YAAY,CAAC;CAC9B;AAED,wBAAgB,yBAAyB,CACrC,iBAAiB,EAAE,eAAe,EAClC,kBAAkB,EAAE,mBAAmB,EACvC,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,CAU9C"}
@@ -4,10 +4,9 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.createOdspCacheAndTracker = exports.EpochTrackerWithRedemption = exports.EpochTracker = exports.Odsp409Error = void 0;
7
+ exports.createOdspCacheAndTracker = exports.EpochTrackerWithRedemption = exports.EpochTracker = exports.defaultCacheExpiryTimeoutMs = exports.Odsp409Error = void 0;
8
8
  const uuid_1 = require("uuid");
9
9
  const common_utils_1 = require("@fluidframework/common-utils");
10
- const odsp_doclib_utils_1 = require("@fluidframework/odsp-doclib-utils");
11
10
  const driver_utils_1 = require("@fluidframework/driver-utils");
12
11
  const odsp_driver_definitions_1 = require("@fluidframework/odsp-driver-definitions");
13
12
  const driver_definitions_1 = require("@fluidframework/driver-definitions");
@@ -15,6 +14,7 @@ const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
15
14
  const odspUtils_1 = require("./odspUtils");
16
15
  const contracts_1 = require("./contracts");
17
16
  exports.Odsp409Error = "Odsp409Error";
17
+ exports.defaultCacheExpiryTimeoutMs = 2 * 24 * 60 * 60 * 1000;
18
18
  /**
19
19
  * This class is a wrapper around fetch calls. It adds epoch to the request made so that the
20
20
  * server can match it with its epoch value in order to match the version.
@@ -44,18 +44,39 @@ class EpochTracker {
44
44
  });
45
45
  }
46
46
  async get(entry) {
47
+ var _a;
47
48
  try {
49
+ // Return undefined so that the ops/snapshots are grabbed from the server instead of the cache
48
50
  const value = await this.cache.get(this.fileEntryFromEntry(entry));
51
+ // Version mismatch between what the runtime expects and what it recieved.
52
+ // The cached value should not be used
49
53
  if (value === undefined || value.version !== contracts_1.persistedCacheValueVersion) {
50
54
  return undefined;
51
55
  }
52
56
  common_utils_1.assert(value.fluidEpoch !== undefined, 0x1dc /* "all entries have to have epoch" */);
53
57
  if (this._fluidEpoch === undefined) {
54
58
  this.setEpoch(value.fluidEpoch, true, "cache");
59
+ // Epoch mismatch, the cached value is considerably different from what the current state of
60
+ // the runtime and should not be used
55
61
  }
56
62
  else if (this._fluidEpoch !== value.fluidEpoch) {
57
63
  return undefined;
58
64
  }
65
+ // Expire the cached snapshot if it's older than the defaultCacheExpiryTimeoutMs and immediately
66
+ // expire all old caches that do not have cacheEntryTime
67
+ if (entry.type === odsp_driver_definitions_1.snapshotKey) {
68
+ const cacheTime = (_a = value.value) === null || _a === void 0 ? void 0 : _a.cacheEntryTime;
69
+ const currentTime = Date.now();
70
+ if (cacheTime === undefined || currentTime - cacheTime >= exports.defaultCacheExpiryTimeoutMs) {
71
+ this.logger.sendTelemetryEvent({
72
+ eventName: "odspVersionsCacheExpired",
73
+ duration: currentTime - cacheTime,
74
+ maxCacheAgeMs: exports.defaultCacheExpiryTimeoutMs,
75
+ });
76
+ await this.removeEntries();
77
+ return undefined;
78
+ }
79
+ }
59
80
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
60
81
  return value.value;
61
82
  }
@@ -65,7 +86,13 @@ class EpochTracker {
65
86
  }
66
87
  }
67
88
  async put(entry, value) {
89
+ var _a;
68
90
  common_utils_1.assert(this._fluidEpoch !== undefined, 0x1dd /* "no epoch" */);
91
+ // For snapshots, the value should have the cacheEntryTime. This will be used to expire snapshots older
92
+ // than the defaultCacheExpiryTimeoutMs.
93
+ if (entry.type === odsp_driver_definitions_1.snapshotKey) {
94
+ value.cacheEntryTime = (_a = value.cacheEntryTime) !== null && _a !== void 0 ? _a : Date.now();
95
+ }
69
96
  const data = {
70
97
  value,
71
98
  version: contracts_1.persistedCacheValueVersion,
@@ -107,14 +134,14 @@ class EpochTracker {
107
134
  * @param addInBody - Pass True if caller wants to add epoch in post body.
108
135
  */
109
136
  async fetchAndParseAsJSON(url, fetchOptions, fetchType, addInBody = false) {
110
- const clientCorelationId = this.formatClientCorelationId();
137
+ const clientCorrelationId = this.formatClientCorrelationId();
111
138
  // Add epoch in fetch request.
112
- this.addEpochInRequest(fetchOptions, addInBody, clientCorelationId);
139
+ this.addEpochInRequest(fetchOptions, addInBody, clientCorrelationId);
113
140
  let epochFromResponse;
114
141
  return this.rateLimiter.schedule(async () => odspUtils_1.fetchAndParseAsJSONHelper(url, fetchOptions)).then((response) => {
115
142
  epochFromResponse = response.headers.get("x-fluid-epoch");
116
143
  this.validateEpochFromResponse(epochFromResponse, fetchType);
117
- response.commonSpoHeaders = Object.assign(Object.assign({}, response.commonSpoHeaders), { "X-RequestStats": clientCorelationId });
144
+ response.commonSpoHeaders = Object.assign(Object.assign({}, response.commonSpoHeaders), { "X-RequestStats": clientCorrelationId });
118
145
  return response;
119
146
  }).catch(async (error) => {
120
147
  // Get the server epoch from error in case we don't have it as if undefined we won't be able
@@ -125,7 +152,7 @@ class EpochTracker {
125
152
  await this.checkForEpochError(error, epochFromResponse, fetchType);
126
153
  throw error;
127
154
  }).catch((error) => {
128
- const fluidError = telemetry_utils_1.normalizeError(error, { props: { "X-RequestStats": clientCorelationId } });
155
+ const fluidError = telemetry_utils_1.normalizeError(error, { props: { XRequestStatsHeader: clientCorrelationId } });
129
156
  throw fluidError;
130
157
  });
131
158
  }
@@ -137,14 +164,14 @@ class EpochTracker {
137
164
  * @param addInBody - Pass True if caller wants to add epoch in post body.
138
165
  */
139
166
  async fetchArray(url, fetchOptions, fetchType, addInBody = false) {
140
- const clientCorelationId = this.formatClientCorelationId();
167
+ const clientCorrelationId = this.formatClientCorrelationId();
141
168
  // Add epoch in fetch request.
142
- this.addEpochInRequest(fetchOptions, addInBody, clientCorelationId);
169
+ this.addEpochInRequest(fetchOptions, addInBody, clientCorrelationId);
143
170
  let epochFromResponse;
144
171
  return this.rateLimiter.schedule(async () => odspUtils_1.fetchArray(url, fetchOptions)).then((response) => {
145
172
  epochFromResponse = response.headers.get("x-fluid-epoch");
146
173
  this.validateEpochFromResponse(epochFromResponse, fetchType);
147
- response.commonSpoHeaders = Object.assign(Object.assign({}, response.commonSpoHeaders), { "X-RequestStats": clientCorelationId });
174
+ response.commonSpoHeaders = Object.assign(Object.assign({}, response.commonSpoHeaders), { "X-RequestStats": clientCorrelationId });
148
175
  return response;
149
176
  }).catch(async (error) => {
150
177
  // Get the server epoch from error in case we don't have it as if undefined we won't be able
@@ -155,14 +182,14 @@ class EpochTracker {
155
182
  await this.checkForEpochError(error, epochFromResponse, fetchType);
156
183
  throw error;
157
184
  }).catch((error) => {
158
- const fluidError = telemetry_utils_1.normalizeError(error, { props: { "X-RequestStats": clientCorelationId } });
185
+ const fluidError = telemetry_utils_1.normalizeError(error, { props: { XRequestStatsHeader: clientCorrelationId } });
159
186
  throw fluidError;
160
187
  });
161
188
  }
162
- addEpochInRequest(fetchOptions, addInBody, clientCorelationId) {
189
+ addEpochInRequest(fetchOptions, addInBody, clientCorrelationId) {
163
190
  if (addInBody) {
164
191
  const headers = {};
165
- headers["X-RequestStats"] = clientCorelationId;
192
+ headers["X-RequestStats"] = clientCorrelationId;
166
193
  if (this.fluidEpoch !== undefined) {
167
194
  headers["x-fluid-epoch"] = this.fluidEpoch;
168
195
  }
@@ -174,7 +201,7 @@ class EpochTracker {
174
201
  common_utils_1.assert(fetchOptions.headers !== undefined, 0x282 /* "Headers should be present now" */);
175
202
  fetchOptions.headers[key] = val;
176
203
  };
177
- addHeader("X-RequestStats", clientCorelationId);
204
+ addHeader("X-RequestStats", clientCorrelationId);
178
205
  if (this.fluidEpoch !== undefined) {
179
206
  addHeader("x-fluid-epoch", this.fluidEpoch);
180
207
  }
@@ -197,11 +224,14 @@ class EpochTracker {
197
224
  });
198
225
  fetchOptions.body = formParams.join("\r\n");
199
226
  }
200
- formatClientCorelationId() {
227
+ formatClientCorrelationId() {
201
228
  return `driverId=${this.driverId}, RequestNumber=${this.networkCallNumber++}`;
202
229
  }
203
230
  validateEpochFromResponse(epochFromResponse, fetchType, fromCache = false) {
204
- this.checkForEpochErrorCore(epochFromResponse);
231
+ const error = this.checkForEpochErrorCore(epochFromResponse);
232
+ if (error !== undefined) {
233
+ throw error;
234
+ }
205
235
  if (epochFromResponse !== undefined) {
206
236
  if (this._fluidEpoch === undefined) {
207
237
  this.setEpoch(epochFromResponse, fromCache, fetchType);
@@ -210,11 +240,8 @@ class EpochTracker {
210
240
  }
211
241
  async checkForEpochError(error, epochFromResponse, fetchType, fromCache = false) {
212
242
  if (telemetry_utils_1.isFluidError(error) && error.errorType === driver_definitions_1.DriverErrorType.fileOverwrittenInStorage) {
213
- try {
214
- // This will only throw if it is an epoch error.
215
- this.checkForEpochErrorCore(epochFromResponse);
216
- }
217
- catch (epochError) {
243
+ const epochError = this.checkForEpochErrorCore(epochFromResponse);
244
+ if (epochError !== undefined) {
218
245
  common_utils_1.assert(telemetry_utils_1.isFluidError(epochError), 0x21f /* "epochError expected to be thrown by throwOdspNetworkError and of known type" */);
219
246
  epochError.addTelemetryProperties({
220
247
  fromCache,
@@ -237,7 +264,9 @@ class EpochTracker {
237
264
  // initializes this value. Sometimes response does not contain epoch as it is still in
238
265
  // implementation phase at server side. In that case also, don't compare it with our epoch value.
239
266
  if (this.fluidEpoch && epochFromResponse && (this.fluidEpoch !== epochFromResponse)) {
240
- odsp_doclib_utils_1.throwOdspNetworkError("epochMismatch", odsp_doclib_utils_1.fluidEpochMismatchError);
267
+ // This is similar in nature to how fluidEpochMismatchError (409) is handled.
268
+ // Difference - client detected mismatch, instead of server detecting it.
269
+ return new driver_utils_1.NonRetryableError("epochMismatch", "Epoch mismatch", driver_definitions_1.DriverErrorType.fileOverwrittenInStorage);
241
270
  }
242
271
  }
243
272
  fileEntryFromEntry(entry) {
@@ -1 +1 @@
1
- {"version":3,"file":"epochTracker.js","sourceRoot":"","sources":["../src/epochTracker.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAAkC;AAClC,+DAAgE;AAEhE,yEAAmG;AACnG,+DAA4E;AAE5E,qFAOiD;AACjD,2EAAqE;AACrE,qEAAiG;AACjG,2CAAmF;AAMnF,2CAAmF;AAOtE,QAAA,YAAY,GAAG,cAAc,CAAC;AAE3C;;;;;GAKG;AACH,MAAa,YAAY;IAOrB,YACuB,KAAsB,EACtB,SAAqB,EACrB,MAAwB;QAFxB,UAAK,GAAL,KAAK,CAAiB;QACtB,cAAS,GAAT,SAAS,CAAY;QACrB,WAAM,GAAN,MAAM,CAAkB;QAN9B,aAAQ,GAAG,SAAI,EAAE,CAAC;QACnC,8DAA8D;QACtD,sBAAiB,GAAG,CAAC,CAAC;QAM1B,sDAAsD;QACtD,IAAI,CAAC,WAAW,GAAG,IAAI,0BAAW,CAAC,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,+BAA+B;IACxB,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;IAExB,MAAM,YAAY,GAAG,IAAI,0BAA0B,CAAC,iBAAiB,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAC1F,OAAO;QACH,KAAK,kCACE,kBAAkB,KACrB,cAAc,EAAE,YAAY,GAC/B;QACD,YAAY;KACf,CAAC;AACN,CAAC;AAdD,8DAcC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { assert, Deferred } from \"@fluidframework/common-utils\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { fluidEpochMismatchError, throwOdspNetworkError } from \"@fluidframework/odsp-doclib-utils\";\nimport { ThrottlingError, RateLimiter } from \"@fluidframework/driver-utils\";\nimport { IConnected } from \"@fluidframework/protocol-definitions\";\nimport {\n snapshotKey,\n ICacheEntry,\n IEntry,\n IFileEntry,\n IPersistedCache,\n IOdspError,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport { DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport { PerformanceEvent, isFluidError, normalizeError } from \"@fluidframework/telemetry-utils\";\nimport { fetchAndParseAsJSONHelper, fetchArray, IOdspResponse } from \"./odspUtils\";\nimport {\n IOdspCache,\n INonPersistentCache,\n IPersistedFileCache,\n } from \"./odspCache\";\nimport { IVersionedValueWithEpoch, persistedCacheValueVersion } from \"./contracts\";\n\nexport type FetchType = \"blob\" | \"createBlob\" | \"createFile\" | \"joinSession\" | \"ops\" | \"test\" | \"snapshotTree\" |\n \"treesLatest\" | \"uploadSummary\" | \"push\" | \"versions\";\n\nexport type FetchTypeInternal = FetchType | \"cache\";\n\nexport const Odsp409Error = \"Odsp409Error\";\n\n/**\n * This class is a wrapper around fetch calls. It adds epoch to the request made so that the\n * server can match it with its epoch value in order to match the version.\n * It also validates the epoch value received in response of fetch calls. If the epoch does not match,\n * then it also clears all the cached entries for the given container.\n */\nexport class EpochTracker implements IPersistedFileCache {\n private _fluidEpoch: string | undefined;\n\n public readonly rateLimiter: RateLimiter;\n private readonly driverId = uuid();\n // This tracks the request number made by the driver instance.\n private networkCallNumber = 1;\n constructor(\n protected readonly cache: IPersistedCache,\n protected readonly fileEntry: IFileEntry,\n protected readonly logger: ITelemetryLogger,\n ) {\n // Limits the max number of concurrent requests to 24.\n this.rateLimiter = new RateLimiter(24);\n }\n\n // public for UT purposes only!\n public setEpoch(epoch: string, fromCache: boolean, fetchType: FetchTypeInternal) {\n assert(this._fluidEpoch === undefined, 0x1db /* \"epoch exists\" */);\n this._fluidEpoch = epoch;\n\n this.logger.sendTelemetryEvent(\n {\n eventName: \"EpochLearnedFirstTime\",\n epoch,\n fetchType,\n fromCache,\n },\n );\n }\n\n public async get(\n entry: IEntry,\n ): Promise<any> {\n try {\n const value: IVersionedValueWithEpoch = await this.cache.get(this.fileEntryFromEntry(entry));\n if (value === undefined || value.version !== persistedCacheValueVersion) {\n return undefined;\n }\n assert(value.fluidEpoch !== undefined, 0x1dc /* \"all entries have to have epoch\" */);\n if (this._fluidEpoch === undefined) {\n this.setEpoch(value.fluidEpoch, true, \"cache\");\n } else if (this._fluidEpoch !== value.fluidEpoch) {\n return undefined;\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value.value;\n } catch (error) {\n this.logger.sendErrorEvent({ eventName: \"cacheFetchError\", type: entry.type }, error);\n return undefined;\n }\n }\n\n public async put(entry: IEntry, value: any) {\n assert(this._fluidEpoch !== undefined, 0x1dd /* \"no epoch\" */);\n const data: IVersionedValueWithEpoch = {\n value,\n version: persistedCacheValueVersion,\n fluidEpoch: this._fluidEpoch,\n };\n return this.cache.put(this.fileEntryFromEntry(entry), data)\n .catch((error) => {\n this.logger.sendErrorEvent({ eventName: \"cachePutError\", type: entry.type }, error);\n throw error;\n });\n }\n\n public async removeEntries(): Promise<void> {\n try {\n return await this.cache.removeEntries(this.fileEntry);\n } catch (error) {\n this.logger.sendErrorEvent({ eventName: \"removeCacheEntries\" }, error);\n }\n }\n\n public get fluidEpoch() {\n return this._fluidEpoch;\n }\n\n public async validateEpochFromPush(details: IConnected) {\n const epoch = details.epoch;\n assert(epoch !== undefined, 0x09d /* \"Connection details should contain epoch\" */);\n try {\n this.validateEpochFromResponse(epoch, \"push\");\n } catch (error) {\n await this.checkForEpochError(error, epoch, \"push\");\n throw error;\n }\n }\n\n /**\n * Api to fetch the response for given request and parse it as json.\n * @param url - url of the request\n * @param fetchOptions - fetch options for request containing body, headers etc.\n * @param fetchType - method for which fetch is called.\n * @param addInBody - Pass True if caller wants to add epoch in post body.\n */\n public async fetchAndParseAsJSON<T>(\n url: string,\n fetchOptions: RequestInit,\n fetchType: FetchType,\n addInBody: boolean = false,\n ): Promise<IOdspResponse<T>> {\n const clientCorelationId = this.formatClientCorelationId();\n // Add epoch in fetch request.\n this.addEpochInRequest(fetchOptions, addInBody, clientCorelationId);\n let epochFromResponse: string | undefined;\n return this.rateLimiter.schedule(\n async () => fetchAndParseAsJSONHelper<T>(url, fetchOptions),\n ).then((response) => {\n epochFromResponse = response.headers.get(\"x-fluid-epoch\");\n this.validateEpochFromResponse(epochFromResponse, fetchType);\n response.commonSpoHeaders = {\n ...response.commonSpoHeaders,\n \"X-RequestStats\": clientCorelationId,\n };\n return response;\n }).catch(async (error) => {\n // Get the server epoch from error in case we don't have it as if undefined we won't be able\n // to mark it as epoch error.\n if (epochFromResponse === undefined) {\n epochFromResponse = (error as IOdspError).serverEpoch;\n }\n await this.checkForEpochError(error, epochFromResponse, fetchType);\n throw error;\n }).catch((error) => {\n const fluidError = normalizeError(error, {props: {\"X-RequestStats\": clientCorelationId}});\n throw fluidError;\n });\n }\n\n /**\n * Api to fetch the response as it is for given request.\n * @param url - url of the request\n * @param fetchOptions - fetch options for request containing body, headers etc.\n * @param fetchType - method for which fetch is called.\n * @param addInBody - Pass True if caller wants to add epoch in post body.\n */\n public async fetchArray(\n url: string,\n fetchOptions: {[index: string]: any},\n fetchType: FetchType,\n addInBody: boolean = false,\n ) {\n const clientCorelationId = this.formatClientCorelationId();\n // Add epoch in fetch request.\n this.addEpochInRequest(fetchOptions, addInBody, clientCorelationId);\n let epochFromResponse: string | undefined;\n return this.rateLimiter.schedule(\n async () => fetchArray(url, fetchOptions),\n ).then((response) => {\n epochFromResponse = response.headers.get(\"x-fluid-epoch\");\n this.validateEpochFromResponse(epochFromResponse, fetchType);\n response.commonSpoHeaders = {\n ...response.commonSpoHeaders,\n \"X-RequestStats\": clientCorelationId,\n };\n return response;\n }).catch(async (error) => {\n // Get the server epoch from error in case we don't have it as if undefined we won't be able\n // to mark it as epoch error.\n if (epochFromResponse === undefined) {\n epochFromResponse = (error as IOdspError).serverEpoch;\n }\n await this.checkForEpochError(error, epochFromResponse, fetchType);\n throw error;\n }).catch((error) => {\n const fluidError = normalizeError(error, {props: {\"X-RequestStats\": clientCorelationId}});\n throw fluidError;\n });\n }\n\n private addEpochInRequest(\n fetchOptions: RequestInit,\n addInBody: boolean,\n clientCorelationId: string,\n ) {\n if (addInBody) {\n const headers: {[key: string]: string} = {};\n headers[\"X-RequestStats\"] = clientCorelationId;\n if (this.fluidEpoch !== undefined) {\n headers[\"x-fluid-epoch\"] = this.fluidEpoch;\n }\n this.addParamInBody(fetchOptions, headers);\n } else {\n const addHeader = (key: string, val: string) => {\n fetchOptions.headers = {\n ...fetchOptions.headers,\n };\n assert(fetchOptions.headers !== undefined, 0x282 /* \"Headers should be present now\" */);\n fetchOptions.headers[key] = val;\n };\n addHeader(\"X-RequestStats\", clientCorelationId);\n if (this.fluidEpoch !== undefined) {\n addHeader(\"x-fluid-epoch\", this.fluidEpoch);\n }\n }\n }\n\n private addParamInBody(fetchOptions: RequestInit, headers: {[key: string]: string}) {\n // We use multi part form request for post body where we want to use this.\n // So extract the form boundary to mark the end of form.\n const body = fetchOptions.body;\n assert(typeof body === \"string\", 0x21d /* \"body is not string\" */);\n const splitBody = body.split(\"\\r\\n\");\n const firstLine = splitBody.shift();\n assert(firstLine !== undefined && firstLine.startsWith(\"--\"), 0x21e /* \"improper boundary format\" */);\n const formParams = [firstLine];\n Object.entries(headers).forEach(([key, value]) => {\n formParams.push(`${key}: ${value}`);\n });\n splitBody.forEach((value: string) => {\n formParams.push(value);\n });\n fetchOptions.body = formParams.join(\"\\r\\n\");\n }\n\n private formatClientCorelationId() {\n return `driverId=${this.driverId}, RequestNumber=${this.networkCallNumber++}`;\n }\n\n protected validateEpochFromResponse(\n epochFromResponse: string | undefined,\n fetchType: FetchTypeInternal,\n fromCache: boolean = false,\n ) {\n this.checkForEpochErrorCore(epochFromResponse);\n if (epochFromResponse !== undefined) {\n if (this._fluidEpoch === undefined) {\n this.setEpoch(epochFromResponse, fromCache, fetchType);\n }\n }\n }\n\n private async checkForEpochError(\n error: unknown,\n epochFromResponse: string | null | undefined,\n fetchType: FetchTypeInternal,\n fromCache: boolean = false,\n ) {\n if (isFluidError(error) && error.errorType === DriverErrorType.fileOverwrittenInStorage) {\n try {\n // This will only throw if it is an epoch error.\n this.checkForEpochErrorCore(epochFromResponse);\n } catch (epochError) {\n assert(isFluidError(epochError),\n 0x21f /* \"epochError expected to be thrown by throwOdspNetworkError and of known type\" */);\n epochError.addTelemetryProperties({\n fromCache,\n clientEpoch: this.fluidEpoch,\n fetchType,\n });\n this.logger.sendErrorEvent({ eventName: \"fileOverwrittenInStorage\" }, epochError);\n // If the epoch mismatches, then clear all entries for such file entry from cache.\n await this.removeEntries();\n throw epochError;\n }\n // If it was categorized as epoch error but the epoch returned in response matches with the client epoch\n // then it was coherency 409, so rethrow it as throttling error so that it can retried. Default throttling\n // time is 1s.\n throw new ThrottlingError(\"coherency409\", error.message, 1, { [Odsp409Error]: true });\n }\n }\n\n private checkForEpochErrorCore(epochFromResponse: string | null | undefined) {\n // If epoch is undefined, then don't compare it because initially for createNew or TreesLatest\n // initializes this value. Sometimes response does not contain epoch as it is still in\n // implementation phase at server side. In that case also, don't compare it with our epoch value.\n if (this.fluidEpoch && epochFromResponse && (this.fluidEpoch !== epochFromResponse)) {\n throwOdspNetworkError(\"epochMismatch\", fluidEpochMismatchError);\n }\n }\n\n private fileEntryFromEntry(entry: IEntry): ICacheEntry {\n return { ...entry, file: this.fileEntry };\n }\n}\n\nexport class EpochTrackerWithRedemption extends EpochTracker {\n private readonly treesLatestDeferral = new Deferred<void>();\n\n protected validateEpochFromResponse(\n epochFromResponse: string | undefined,\n fetchType: FetchType,\n fromCache: boolean = false,\n ) {\n super.validateEpochFromResponse(epochFromResponse, fetchType, fromCache);\n\n // Any successful call means we have access to a file, i.e. any redemption that was required already happened.\n // That covers cases of \"treesLatest\" as well as \"getVersions\" or \"createFile\" - all the ways we can start\n // exploring a file.\n this.treesLatestDeferral.resolve();\n }\n\n public async get(\n entry: IEntry,\n ): Promise<any> {\n let result = super.get(entry);\n\n // equivalence of what happens in fetchAndParseAsJSON()\n if (entry.type === snapshotKey) {\n result = result\n .then((value) => {\n // If there is nothing in cache, we need to wait for network call to complete (and do redemption)\n // Otherwise file was redeemed in prior session, so if joinSession failed, we should not retry\n if (value !== undefined) {\n this.treesLatestDeferral.resolve();\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value;\n })\n .catch((error) => {\n this.treesLatestDeferral.reject(error);\n throw error;\n });\n }\n return result;\n }\n\n public async fetchAndParseAsJSON<T>(\n url: string,\n fetchOptions: {[index: string]: any},\n fetchType: FetchType,\n addInBody: boolean = false,\n ): Promise<IOdspResponse<T>> {\n // Optimize the flow if we know that treesLatestDeferral was already completed by the timer we started\n // joinSession call. If we did - there is no reason to repeat the call as it will fail with same error.\n const completed = this.treesLatestDeferral.isCompleted;\n\n try {\n return await super.fetchAndParseAsJSON<T>(url, fetchOptions, fetchType, addInBody);\n } catch (error) {\n // Only handling here treesLatest. If createFile failed, we should never try to do joinSession.\n // Similar, if getVersions failed, we should not do any further storage calls.\n // So treesLatest is the only call that can have parallel joinSession request.\n if (fetchType === \"treesLatest\") {\n this.treesLatestDeferral.reject(error);\n }\n if (fetchType !== \"joinSession\" || error.statusCode < 401 || error.statusCode > 404 || completed) {\n throw error;\n }\n }\n\n // It is joinSession failing with 401..404 error\n // Repeat after waiting for treeLatest succeeding (or fail if it failed).\n // No special handling after first call - if file has been deleted, then it's game over.\n\n // Ensure we have some safety here - we do not want to deadlock if we got logic somewhere wrong.\n // If we waited too long, we will log error event and proceed with call.\n // It may result in failure for user, but refreshing document would address it.\n // Thus we use rather long timeout (not to get these failures as much as possible), but not large enough\n // to unblock the process.\n await PerformanceEvent.timedExecAsync(\n this.logger,\n { eventName: \"JoinSessionSyncWait\" },\n async (event) => {\n const timeoutRes = 51; // anything will work here\n let timer: ReturnType<typeof setTimeout>;\n const timeoutP = new Promise<number>((accept) => {\n timer = setTimeout(() => { accept(timeoutRes); }, 15000);\n });\n const res = await Promise.race([\n timeoutP,\n // cancel timeout to unblock UTs (otherwise Node process does not exit for 15 sec)\n this.treesLatestDeferral.promise.finally(() => clearTimeout(timer))]);\n if (res === timeoutRes) {\n event.cancel();\n }\n },\n { start: true, end: true, cancel: \"generic\" });\n return super.fetchAndParseAsJSON<T>(url, fetchOptions, fetchType, addInBody);\n }\n}\n\nexport interface ICacheAndTracker {\n cache: IOdspCache;\n epochTracker: EpochTracker;\n}\n\nexport function createOdspCacheAndTracker(\n persistedCacheArg: IPersistedCache,\n nonpersistentCache: INonPersistentCache,\n fileEntry: IFileEntry,\n logger: ITelemetryLogger): ICacheAndTracker\n{\n const epochTracker = new EpochTrackerWithRedemption(persistedCacheArg, fileEntry, logger);\n return {\n cache: {\n ...nonpersistentCache,\n persistedCache: epochTracker,\n },\n epochTracker,\n };\n}\n"]}
1
+ {"version":3,"file":"epochTracker.js","sourceRoot":"","sources":["../src/epochTracker.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAAkC;AAClC,+DAAgE;AAEhE,+DAA+F;AAE/F,qFAOiD;AACjD,2EAAqE;AACrE,qEAAiG;AACjG,2CAAmF;AAMnF,2CAAmF;AAOtE,QAAA,YAAY,GAAG,cAAc,CAAC;A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,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;IACjF,CAAC;CACJ;AA9FD,gEA8FC;AAOD,SAAgB,yBAAyB,CACrC,iBAAkC,EAClC,kBAAuC,EACvC,SAAqB,EACrB,MAAwB;IAExB,MAAM,YAAY,GAAG,IAAI,0BAA0B,CAAC,iBAAiB,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAC1F,OAAO;QACH,KAAK,kCACE,kBAAkB,KACrB,cAAc,EAAE,YAAY,GAC/B;QACD,YAAY;KACf,CAAC;AACN,CAAC;AAdD,8DAcC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { assert, Deferred } from \"@fluidframework/common-utils\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { ThrottlingError, RateLimiter, NonRetryableError } from \"@fluidframework/driver-utils\";\nimport { IConnected } from \"@fluidframework/protocol-definitions\";\nimport {\n snapshotKey,\n ICacheEntry,\n IEntry,\n IFileEntry,\n IPersistedCache,\n IOdspError,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport { DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport { PerformanceEvent, isFluidError, normalizeError } from \"@fluidframework/telemetry-utils\";\nimport { fetchAndParseAsJSONHelper, fetchArray, IOdspResponse } from \"./odspUtils\";\nimport {\n IOdspCache,\n INonPersistentCache,\n IPersistedFileCache,\n } from \"./odspCache\";\nimport { IVersionedValueWithEpoch, persistedCacheValueVersion } from \"./contracts\";\n\nexport type FetchType = \"blob\" | \"createBlob\" | \"createFile\" | \"joinSession\" | \"ops\" | \"test\" | \"snapshotTree\" |\n \"treesLatest\" | \"uploadSummary\" | \"push\" | \"versions\";\n\nexport type FetchTypeInternal = FetchType | \"cache\";\n\nexport const Odsp409Error = \"Odsp409Error\";\n\nexport const defaultCacheExpiryTimeoutMs: number = 2 * 24 * 60 * 60 * 1000;\n\n/**\n * This class is a wrapper around fetch calls. It adds epoch to the request made so that the\n * server can match it with its epoch value in order to match the version.\n * It also validates the epoch value received in response of fetch calls. If the epoch does not match,\n * then it also clears all the cached entries for the given container.\n */\nexport class EpochTracker implements IPersistedFileCache {\n private _fluidEpoch: string | undefined;\n\n public readonly rateLimiter: RateLimiter;\n private readonly driverId = uuid();\n // This tracks the request number made by the driver instance.\n private networkCallNumber = 1;\n constructor(\n protected readonly cache: IPersistedCache,\n protected readonly fileEntry: IFileEntry,\n protected readonly logger: ITelemetryLogger,\n ) {\n // Limits the max number of concurrent requests to 24.\n this.rateLimiter = new RateLimiter(24);\n }\n\n // public for UT purposes only!\n public setEpoch(epoch: string, fromCache: boolean, fetchType: FetchTypeInternal) {\n assert(this._fluidEpoch === undefined, 0x1db /* \"epoch exists\" */);\n this._fluidEpoch = epoch;\n\n this.logger.sendTelemetryEvent(\n {\n eventName: \"EpochLearnedFirstTime\",\n epoch,\n fetchType,\n fromCache,\n },\n );\n }\n\n public async get(\n entry: IEntry,\n ): Promise<any> {\n try {\n // Return undefined so that the ops/snapshots are grabbed from the server instead of the cache\n const value: IVersionedValueWithEpoch = await this.cache.get(this.fileEntryFromEntry(entry));\n // Version mismatch between what the runtime expects and what it recieved.\n // The cached value should not be used\n if (value === undefined || value.version !== persistedCacheValueVersion) {\n return undefined;\n }\n assert(value.fluidEpoch !== undefined, 0x1dc /* \"all entries have to have epoch\" */);\n if (this._fluidEpoch === undefined) {\n this.setEpoch(value.fluidEpoch, true, \"cache\");\n // Epoch mismatch, the cached value is considerably different from what the current state of\n // the runtime and should not be used\n } else if (this._fluidEpoch !== value.fluidEpoch) {\n return undefined;\n }\n // Expire the cached snapshot if it's older than the defaultCacheExpiryTimeoutMs and immediately\n // expire all old caches that do not have cacheEntryTime\n if (entry.type === snapshotKey) {\n const cacheTime = value.value?.cacheEntryTime;\n const currentTime = Date.now();\n if (cacheTime === undefined || currentTime - cacheTime >= defaultCacheExpiryTimeoutMs) {\n this.logger.sendTelemetryEvent(\n {\n eventName: \"odspVersionsCacheExpired\",\n duration: currentTime - cacheTime,\n maxCacheAgeMs: defaultCacheExpiryTimeoutMs,\n });\n await this.removeEntries();\n return undefined;\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value.value;\n } catch (error) {\n this.logger.sendErrorEvent({ eventName: \"cacheFetchError\", type: entry.type }, error);\n return undefined;\n }\n }\n\n public async put(entry: IEntry, value: any) {\n assert(this._fluidEpoch !== undefined, 0x1dd /* \"no epoch\" */);\n // For snapshots, the value should have the cacheEntryTime. This will be used to expire snapshots older\n // than the defaultCacheExpiryTimeoutMs.\n if (entry.type === snapshotKey) {\n value.cacheEntryTime = value.cacheEntryTime ?? Date.now();\n }\n const data: IVersionedValueWithEpoch = {\n value,\n version: persistedCacheValueVersion,\n fluidEpoch: this._fluidEpoch,\n };\n return this.cache.put(this.fileEntryFromEntry(entry), data)\n .catch((error) => {\n this.logger.sendErrorEvent({ eventName: \"cachePutError\", type: entry.type }, error);\n throw error;\n });\n }\n\n public async removeEntries(): Promise<void> {\n try {\n return await this.cache.removeEntries(this.fileEntry);\n } catch (error) {\n this.logger.sendErrorEvent({ eventName: \"removeCacheEntries\" }, error);\n }\n }\n\n public get fluidEpoch() {\n return this._fluidEpoch;\n }\n\n public async validateEpochFromPush(details: IConnected) {\n const epoch = details.epoch;\n assert(epoch !== undefined, 0x09d /* \"Connection details should contain epoch\" */);\n try {\n this.validateEpochFromResponse(epoch, \"push\");\n } catch (error) {\n await this.checkForEpochError(error, epoch, \"push\");\n throw error;\n }\n }\n\n /**\n * Api to fetch the response for given request and parse it as json.\n * @param url - url of the request\n * @param fetchOptions - fetch options for request containing body, headers etc.\n * @param fetchType - method for which fetch is called.\n * @param addInBody - Pass True if caller wants to add epoch in post body.\n */\n public async fetchAndParseAsJSON<T>(\n url: string,\n fetchOptions: RequestInit,\n fetchType: FetchType,\n addInBody: boolean = false,\n ): Promise<IOdspResponse<T>> {\n const clientCorrelationId = this.formatClientCorrelationId();\n // Add epoch in fetch request.\n this.addEpochInRequest(fetchOptions, addInBody, clientCorrelationId);\n let epochFromResponse: string | undefined;\n return this.rateLimiter.schedule(\n async () => fetchAndParseAsJSONHelper<T>(url, fetchOptions),\n ).then((response) => {\n epochFromResponse = response.headers.get(\"x-fluid-epoch\");\n this.validateEpochFromResponse(epochFromResponse, fetchType);\n response.commonSpoHeaders = {\n ...response.commonSpoHeaders,\n \"X-RequestStats\": clientCorrelationId,\n };\n return response;\n }).catch(async (error) => {\n // Get the server epoch from error in case we don't have it as if undefined we won't be able\n // to mark it as epoch error.\n if (epochFromResponse === undefined) {\n epochFromResponse = (error as IOdspError).serverEpoch;\n }\n await this.checkForEpochError(error, epochFromResponse, fetchType);\n throw error;\n }).catch((error) => {\n const fluidError = normalizeError(error, { props: { XRequestStatsHeader: clientCorrelationId }});\n throw fluidError;\n });\n }\n\n /**\n * Api to fetch the response as it is for given request.\n * @param url - url of the request\n * @param fetchOptions - fetch options for request containing body, headers etc.\n * @param fetchType - method for which fetch is called.\n * @param addInBody - Pass True if caller wants to add epoch in post body.\n */\n public async fetchArray(\n url: string,\n fetchOptions: {[index: string]: any},\n fetchType: FetchType,\n addInBody: boolean = false,\n ) {\n const clientCorrelationId = this.formatClientCorrelationId();\n // Add epoch in fetch request.\n this.addEpochInRequest(fetchOptions, addInBody, clientCorrelationId);\n let epochFromResponse: string | undefined;\n return this.rateLimiter.schedule(\n async () => fetchArray(url, fetchOptions),\n ).then((response) => {\n epochFromResponse = response.headers.get(\"x-fluid-epoch\");\n this.validateEpochFromResponse(epochFromResponse, fetchType);\n response.commonSpoHeaders = {\n ...response.commonSpoHeaders,\n \"X-RequestStats\": clientCorrelationId,\n };\n return response;\n }).catch(async (error) => {\n // Get the server epoch from error in case we don't have it as if undefined we won't be able\n // to mark it as epoch error.\n if (epochFromResponse === undefined) {\n epochFromResponse = (error as IOdspError).serverEpoch;\n }\n await this.checkForEpochError(error, epochFromResponse, fetchType);\n throw error;\n }).catch((error) => {\n const fluidError = normalizeError(error, { props: { XRequestStatsHeader: clientCorrelationId }});\n throw fluidError;\n });\n }\n\n private addEpochInRequest(\n fetchOptions: RequestInit,\n addInBody: boolean,\n clientCorrelationId: string,\n ) {\n if (addInBody) {\n const headers: {[key: string]: string} = {};\n headers[\"X-RequestStats\"] = clientCorrelationId;\n if (this.fluidEpoch !== undefined) {\n headers[\"x-fluid-epoch\"] = this.fluidEpoch;\n }\n this.addParamInBody(fetchOptions, headers);\n } else {\n const addHeader = (key: string, val: string) => {\n fetchOptions.headers = {\n ...fetchOptions.headers,\n };\n assert(fetchOptions.headers !== undefined, 0x282 /* \"Headers should be present now\" */);\n fetchOptions.headers[key] = val;\n };\n addHeader(\"X-RequestStats\", clientCorrelationId);\n if (this.fluidEpoch !== undefined) {\n addHeader(\"x-fluid-epoch\", this.fluidEpoch);\n }\n }\n }\n\n private addParamInBody(fetchOptions: RequestInit, headers: {[key: string]: string}) {\n // We use multi part form request for post body where we want to use this.\n // So extract the form boundary to mark the end of form.\n const body = fetchOptions.body;\n assert(typeof body === \"string\", 0x21d /* \"body is not string\" */);\n const splitBody = body.split(\"\\r\\n\");\n const firstLine = splitBody.shift();\n assert(firstLine !== undefined && firstLine.startsWith(\"--\"), 0x21e /* \"improper boundary format\" */);\n const formParams = [firstLine];\n Object.entries(headers).forEach(([key, value]) => {\n formParams.push(`${key}: ${value}`);\n });\n splitBody.forEach((value: string) => {\n formParams.push(value);\n });\n fetchOptions.body = formParams.join(\"\\r\\n\");\n }\n\n private formatClientCorrelationId() {\n return `driverId=${this.driverId}, RequestNumber=${this.networkCallNumber++}`;\n }\n\n protected validateEpochFromResponse(\n epochFromResponse: string | undefined,\n fetchType: FetchTypeInternal,\n fromCache: boolean = false,\n ) {\n const error = this.checkForEpochErrorCore(epochFromResponse);\n if (error !== undefined) {\n throw error;\n }\n if (epochFromResponse !== undefined) {\n if (this._fluidEpoch === undefined) {\n this.setEpoch(epochFromResponse, fromCache, fetchType);\n }\n }\n }\n\n private async checkForEpochError(\n error: unknown,\n epochFromResponse: string | null | undefined,\n fetchType: FetchTypeInternal,\n fromCache: boolean = false,\n ) {\n if (isFluidError(error) && error.errorType === DriverErrorType.fileOverwrittenInStorage) {\n const epochError = this.checkForEpochErrorCore(epochFromResponse);\n if (epochError !== undefined) {\n assert(isFluidError(epochError),\n 0x21f /* \"epochError expected to be thrown by throwOdspNetworkError and of known type\" */);\n epochError.addTelemetryProperties({\n fromCache,\n clientEpoch: this.fluidEpoch,\n fetchType,\n });\n this.logger.sendErrorEvent({ eventName: \"fileOverwrittenInStorage\" }, epochError);\n // If the epoch mismatches, then clear all entries for such file entry from cache.\n await this.removeEntries();\n throw epochError;\n }\n // If it was categorized as epoch error but the epoch returned in response matches with the client epoch\n // then it was coherency 409, so rethrow it as throttling error so that it can retried. Default throttling\n // time is 1s.\n throw new ThrottlingError(\"coherency409\", error.message, 1, { [Odsp409Error]: true });\n }\n }\n\n private checkForEpochErrorCore(epochFromResponse: string | null | undefined) {\n // If epoch is undefined, then don't compare it because initially for createNew or TreesLatest\n // initializes this value. Sometimes response does not contain epoch as it is still in\n // implementation phase at server side. In that case also, don't compare it with our epoch value.\n if (this.fluidEpoch && epochFromResponse && (this.fluidEpoch !== epochFromResponse)) {\n // This is similar in nature to how fluidEpochMismatchError (409) is handled.\n // Difference - client detected mismatch, instead of server detecting it.\n return new NonRetryableError(\"epochMismatch\", \"Epoch mismatch\", DriverErrorType.fileOverwrittenInStorage);\n }\n }\n\n private fileEntryFromEntry(entry: IEntry): ICacheEntry {\n return { ...entry, file: this.fileEntry };\n }\n}\n\nexport class EpochTrackerWithRedemption extends EpochTracker {\n private readonly treesLatestDeferral = new Deferred<void>();\n\n protected validateEpochFromResponse(\n epochFromResponse: string | undefined,\n fetchType: FetchType,\n fromCache: boolean = false,\n ) {\n super.validateEpochFromResponse(epochFromResponse, fetchType, fromCache);\n\n // Any successful call means we have access to a file, i.e. any redemption that was required already happened.\n // That covers cases of \"treesLatest\" as well as \"getVersions\" or \"createFile\" - all the ways we can start\n // exploring a file.\n this.treesLatestDeferral.resolve();\n }\n\n public async get(\n entry: IEntry,\n ): Promise<any> {\n let result = super.get(entry);\n\n // equivalence of what happens in fetchAndParseAsJSON()\n if (entry.type === snapshotKey) {\n result = result\n .then((value) => {\n // If there is nothing in cache, we need to wait for network call to complete (and do redemption)\n // Otherwise file was redeemed in prior session, so if joinSession failed, we should not retry\n if (value !== undefined) {\n this.treesLatestDeferral.resolve();\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value;\n })\n .catch((error) => {\n this.treesLatestDeferral.reject(error);\n throw error;\n });\n }\n return result;\n }\n\n public async fetchAndParseAsJSON<T>(\n url: string,\n fetchOptions: {[index: string]: any},\n fetchType: FetchType,\n addInBody: boolean = false,\n ): Promise<IOdspResponse<T>> {\n // Optimize the flow if we know that treesLatestDeferral was already completed by the timer we started\n // joinSession call. If we did - there is no reason to repeat the call as it will fail with same error.\n const completed = this.treesLatestDeferral.isCompleted;\n\n try {\n return await super.fetchAndParseAsJSON<T>(url, fetchOptions, fetchType, addInBody);\n } catch (error) {\n // Only handling here treesLatest. If createFile failed, we should never try to do joinSession.\n // Similar, if getVersions failed, we should not do any further storage calls.\n // So treesLatest is the only call that can have parallel joinSession request.\n if (fetchType === \"treesLatest\") {\n this.treesLatestDeferral.reject(error);\n }\n if (fetchType !== \"joinSession\" || error.statusCode < 401 || error.statusCode > 404 || completed) {\n throw error;\n }\n }\n\n // It is joinSession failing with 401..404 error\n // Repeat after waiting for treeLatest succeeding (or fail if it failed).\n // No special handling after first call - if file has been deleted, then it's game over.\n\n // Ensure we have some safety here - we do not want to deadlock if we got logic somewhere wrong.\n // If we waited too long, we will log error event and proceed with call.\n // It may result in failure for user, but refreshing document would address it.\n // Thus we use rather long timeout (not to get these failures as much as possible), but not large enough\n // to unblock the process.\n await PerformanceEvent.timedExecAsync(\n this.logger,\n { eventName: \"JoinSessionSyncWait\" },\n async (event) => {\n const timeoutRes = 51; // anything will work here\n let timer: ReturnType<typeof setTimeout>;\n const timeoutP = new Promise<number>((accept) => {\n timer = setTimeout(() => { accept(timeoutRes); }, 15000);\n });\n const res = await Promise.race([\n timeoutP,\n // cancel timeout to unblock UTs (otherwise Node process does not exit for 15 sec)\n this.treesLatestDeferral.promise.finally(() => clearTimeout(timer))]);\n if (res === timeoutRes) {\n event.cancel();\n }\n },\n { start: true, end: true, cancel: \"generic\" });\n return super.fetchAndParseAsJSON<T>(url, fetchOptions, fetchType, addInBody);\n }\n}\n\nexport interface ICacheAndTracker {\n cache: IOdspCache;\n epochTracker: EpochTracker;\n}\n\nexport function createOdspCacheAndTracker(\n persistedCacheArg: IPersistedCache,\n nonpersistentCache: INonPersistentCache,\n fileEntry: IFileEntry,\n logger: ITelemetryLogger): ICacheAndTracker\n{\n const epochTracker = new EpochTrackerWithRedemption(persistedCacheArg, fileEntry, logger);\n return {\n cache: {\n ...nonpersistentCache,\n persistedCache: epochTracker,\n },\n epochTracker,\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"fetchSnapshot.d.ts","sourceRoot":"","sources":["../src/fetchSnapshot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAItE,OAAO,EACH,gBAAgB,EAChB,gBAAgB,EAEhB,+BAA+B,EAClC,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAuC,wBAAwB,EAA8B,MAAM,aAAa,CAAC;AAGxH,OAAO,EAKH,aAAa,EACb,iBAAiB,EACpB,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAC/B,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,SAAS,EAAE,MAAM,EACjB,iBAAi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