@fluidframework/driver-utils 2.80.0 → 2.81.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @fluidframework/driver-utils
2
2
 
3
+ ## 2.81.0
4
+
5
+ Dependency updates only.
6
+
3
7
  ## 2.80.0
4
8
 
5
9
  Dependency updates only.
@@ -1 +1 @@
1
- {"version":3,"file":"insecureUrlResolver.d.ts","sourceRoot":"","sources":["../src/insecureUrlResolver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAE3D,OAAO,EAEN,YAAY,EACZ,YAAY,EACZ,MAAM,6CAA6C,CAAC;AAGrD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,mBAAoB,YAAW,YAAY;IAItD,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAT/B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA4C;gBAGhD,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,aAAa,GAAE,OAAe;IAGnC,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;IA+C1E,OAAO,CAAC,aAAa;IAmDR,cAAc,CAC1B,WAAW,EAAE,YAAY,EACzB,WAAW,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC;IAgBX,sBAAsB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,QAAQ;CAU1D"}
1
+ {"version":3,"file":"insecureUrlResolver.d.ts","sourceRoot":"","sources":["../src/insecureUrlResolver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAE3D,OAAO,EAEN,YAAY,EACZ,YAAY,EACZ,MAAM,6CAA6C,CAAC;AAErD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,mBAAoB,YAAW,YAAY;IAItD,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAT/B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA4C;gBAGhD,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,aAAa,GAAE,OAAe;IAGnC,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;IA+C1E,OAAO,CAAC,aAAa;IAmDR,cAAc,CAC1B,WAAW,EAAE,YAAY,EACzB,WAAW,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC;IAgBX,sBAAsB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,QAAQ;CAU1D"}
@@ -3,14 +3,10 @@
3
3
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
4
  * Licensed under the MIT License.
5
5
  */
6
- var __importDefault = (this && this.__importDefault) || function (mod) {
7
- return (mod && mod.__esModule) ? mod : { "default": mod };
8
- };
9
6
  Object.defineProperty(exports, "__esModule", { value: true });
10
7
  exports.InsecureUrlResolver = void 0;
11
8
  const internal_1 = require("@fluidframework/core-utils/internal");
12
9
  const internal_2 = require("@fluidframework/driver-definitions/internal");
13
- const axios_1 = __importDefault(require("axios"));
14
10
  /**
15
11
  * As the name implies this is not secure and should not be used in production. It simply makes the example easier
16
12
  * to get up and running.
@@ -64,15 +60,22 @@ class InsecureUrlResolver {
64
60
  if (maybeResolvedUrl) {
65
61
  return maybeResolvedUrl;
66
62
  }
67
- const headers = {
68
- Authorization: `Bearer ${this.bearer}`,
69
- };
70
- const resolvedP = axios_1.default.post(`${this.hostUrl}/apis/load`, {
71
- url: request.url,
72
- }, {
73
- headers,
63
+ const resolvedP = fetch(`${this.hostUrl}/apis/load`, {
64
+ method: "POST",
65
+ headers: {
66
+ Authorization: `Bearer ${this.bearer}`,
67
+ "Content-Type": "application/json",
68
+ },
69
+ body: JSON.stringify({
70
+ url: request.url,
71
+ }),
72
+ }).then(async (response) => {
73
+ if (!response.ok) {
74
+ throw new Error(`HTTP error! status: ${response.status}`);
75
+ }
76
+ return response.json();
74
77
  });
75
- this.cache.set(request.url, resolvedP.then((resolved) => resolved.data));
78
+ this.cache.set(request.url, resolvedP);
76
79
  return this.cache.get(request.url);
77
80
  }
78
81
  }
@@ -1 +1 @@
1
- {"version":3,"file":"insecureUrlResolver.js","sourceRoot":"","sources":["../src/insecureUrlResolver.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAGH,kEAA6D;AAC7D,0EAIqD;AACrD,kDAA0B;AAE1B;;;;;;;;;;;;;;GAcG;AACH,MAAa,mBAAmB;IAG/B,YACkB,OAAe,EACf,UAAkB,EAClB,UAAkB,EAClB,cAAsB,EACtB,QAAgB,EAChB,MAAc,EACd,gBAAyB,KAAK;QAN9B,YAAO,GAAP,OAAO,CAAQ;QACf,eAAU,GAAV,UAAU,CAAQ;QAClB,eAAU,GAAV,U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B;QAEnB,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QAC3C,MAAM,CAAC,EAAE,AAAD,EAAG,UAAU,CAAC,GAAG,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAE9D,IAAA,iBAAM,EAAC,CAAC,CAAC,UAAU,EAAE,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAExE,IAAI,GAAG,GAAG,WAAW,CAAC;QACtB,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACrB,CAAC;QAED,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,kBAAkB,CAChF,UAAU,CACV,IAAI,GAAG,EAAE,CAAC;IACZ,CAAC;IAEM,sBAAsB,CAAC,QAAiB;QAC9C,MAAM,gBAAgB,GAAa;YAClC,yEAAyE;YACzE,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,aAAa,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO;YACrE,OAAO,EAAE;gBACR,CAAC,uBAAY,CAAC,SAAS,CAAC,EAAE,IAAI;aAC9B;SACD,CAAC;QACF,OAAO,gBAAgB,CAAC;IACzB,CAAC;CACD;AA5ID,kDA4IC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IRequest } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tDriverHeader,\n\tIResolvedUrl,\n\tIUrlResolver,\n} from \"@fluidframework/driver-definitions/internal\";\nimport Axios from \"axios\";\n\n/**\n * As the name implies this is not secure and should not be used in production. It simply makes the example easier\n * to get up and running.\n *\n * In our example we run a simple web server via webpack-dev-server. This defines a URL format of the form\n * http://localhost:8080/<documentId>/<path>.\n *\n * We then need to map that to a Fluid based URL. These are of the form\n * https://orderingUrl/<tenantId>/<documentId>/<path>.\n *\n * The tenantId/documentId pair defines the 'full' document ID the service makes use of. The path is then an optional\n * part of the URL that the document interprets and maps to a data store. It's exactly similar to how a web service\n * works or a router inside of a single page app framework.\n * @internal\n */\nexport class InsecureUrlResolver implements IUrlResolver {\n\tprivate readonly cache = new Map<string, Promise<IResolvedUrl>>();\n\n\tconstructor(\n\t\tprivate readonly hostUrl: string,\n\t\tprivate readonly ordererUrl: string,\n\t\tprivate readonly storageUrl: string,\n\t\tprivate readonly deltaStreamUrl: string,\n\t\tprivate readonly tenantId: string,\n\t\tprivate readonly bearer: string,\n\t\tprivate readonly isForNodeTest: boolean = false,\n\t) {}\n\n\tpublic async resolve(request: IRequest): Promise<IResolvedUrl | undefined> {\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\tif (request.headers?.[DriverHeader.createNew]) {\n\t\t\tconst [, queryString] = request.url.split(\"?\");\n\t\t\tconst searchParams = new URLSearchParams(queryString);\n\t\t\tconst fileName = searchParams.get(\"fileName\");\n\t\t\treturn this.resolveHelper(fileName);\n\t\t}\n\t\tconst parsedUrl = new URL(request.url);\n\t\t// If hosts match then we use the local tenant information. Otherwise we make a REST call out to the hosting\n\t\t// service using our bearer token.\n\t\tif (this.isForNodeTest) {\n\t\t\tconst [, documentId, tmpRelativePath] = parsedUrl.pathname.substr(1).split(\"/\");\n\t\t\tconst relativePath = tmpRelativePath ?? \"\";\n\t\t\treturn this.resolveHelper(documentId, relativePath, parsedUrl.search);\n\t\t} else if (parsedUrl.host === window.location.host) {\n\t\t\tconst fullPath = parsedUrl.pathname.substr(1);\n\t\t\tconst documentId = fullPath.split(\"/\")[0];\n\t\t\tconst documentRelativePath = fullPath.slice(documentId.length);\n\t\t\treturn this.resolveHelper(documentId, documentRelativePath);\n\t\t} else {\n\t\t\tconst maybeResolvedUrl = this.cache.get(request.url);\n\t\t\tif (maybeResolvedUrl) {\n\t\t\t\treturn maybeResolvedUrl;\n\t\t\t}\n\n\t\t\tconst headers = {\n\t\t\t\tAuthorization: `Bearer ${this.bearer}`,\n\t\t\t};\n\t\t\tconst resolvedP = Axios.post<IResolvedUrl>(\n\t\t\t\t`${this.hostUrl}/apis/load`,\n\t\t\t\t{\n\t\t\t\t\turl: request.url,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\theaders,\n\t\t\t\t},\n\t\t\t);\n\t\t\tthis.cache.set(\n\t\t\t\trequest.url,\n\t\t\t\tresolvedP.then((resolved) => resolved.data),\n\t\t\t);\n\n\t\t\treturn this.cache.get(request.url);\n\t\t}\n\t}\n\n\tprivate resolveHelper(\n\t\tdocumentId: string | null,\n\t\tdocumentRelativePath: string = \"\",\n\t\tqueryParams: string = \"\",\n\t): IResolvedUrl {\n\t\tconst encodedTenantId = encodeURIComponent(this.tenantId);\n\t\tconst host = new URL(this.ordererUrl).host;\n\t\t// when the document ID is not provided we need to resolve a special create new document URL.\n\t\t// the actual container ID will be generated by the driver.\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\tif (!documentId) {\n\t\t\tconst createNewResponse: IResolvedUrl = {\n\t\t\t\tendpoints: {\n\t\t\t\t\tdeltaStorageUrl: `${this.ordererUrl}/deltas/${encodedTenantId}/new`,\n\t\t\t\t\tdeltaStreamUrl: this.deltaStreamUrl,\n\t\t\t\t\tordererUrl: this.ordererUrl,\n\t\t\t\t\tstorageUrl: `${this.storageUrl}/repos/${encodedTenantId}`,\n\t\t\t\t},\n\t\t\t\t// document ID is ignored by the driver for new container requests\n\t\t\t\tid: \"\",\n\t\t\t\ttokens: {},\n\t\t\t\ttype: \"fluid\",\n\t\t\t\turl: `https://${host}/${encodedTenantId}/new`,\n\t\t\t};\n\t\t\treturn createNewResponse;\n\t\t}\n\t\tconst encodedDocId = encodeURIComponent(documentId);\n\t\tconst relativePath =\n\t\t\t!documentRelativePath || documentRelativePath.startsWith(\"/\")\n\t\t\t\t? documentRelativePath\n\t\t\t\t: `/${documentRelativePath}`;\n\t\tconst documentUrl = `https://${host}/${encodedTenantId}/${encodedDocId}${relativePath}${queryParams}`;\n\n\t\tconst deltaStorageUrl = `${this.ordererUrl}/deltas/${encodedTenantId}/${encodedDocId}`;\n\t\tconst storageUrl = `${this.storageUrl}/repos/${encodedTenantId}`;\n\n\t\tconst response: IResolvedUrl = {\n\t\t\tendpoints: {\n\t\t\t\tdeltaStorageUrl,\n\t\t\t\tdeltaStreamUrl: this.deltaStreamUrl,\n\t\t\t\tordererUrl: this.ordererUrl,\n\t\t\t\tstorageUrl,\n\t\t\t},\n\t\t\tid: documentId,\n\t\t\ttokens: {},\n\t\t\ttype: \"fluid\",\n\t\t\turl: documentUrl,\n\t\t};\n\t\treturn response;\n\t}\n\n\tpublic async getAbsoluteUrl(\n\t\tresolvedUrl: IResolvedUrl,\n\t\trelativeUrl: string,\n\t): Promise<string> {\n\t\tconst parsedUrl = new URL(resolvedUrl.url);\n\t\tconst [, , documentId] = parsedUrl.pathname?.split(\"/\") ?? [];\n\n\t\tassert(!!documentId, 0x273 /* \"Invalid document id from parsed URL\" */);\n\n\t\tlet url = relativeUrl;\n\t\tif (url.startsWith(\"/\")) {\n\t\t\turl = url.substr(1);\n\t\t}\n\n\t\treturn `${this.hostUrl}/${encodeURIComponent(this.tenantId)}/${encodeURIComponent(\n\t\t\tdocumentId,\n\t\t)}/${url}`;\n\t}\n\n\tpublic createCreateNewRequest(fileName?: string): IRequest {\n\t\tconst createNewRequest: IRequest = {\n\t\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\t\turl: fileName ? `${this.hostUrl}?fileName=${fileName}` : this.hostUrl,\n\t\t\theaders: {\n\t\t\t\t[DriverHeader.createNew]: true,\n\t\t\t},\n\t\t};\n\t\treturn createNewRequest;\n\t}\n}\n"]}
1
+ {"version":3,"file":"insecureUrlResolver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AClC,yEAAyE;YACzE,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,aAAa,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO;YACrE,OAAO,EAAE;gBACR,CAAC,uBAAY,CAAC,SAAS,CAAC,EAAE,IAAI;aAC9B;SACD,CAAC;QACF,OAAO,gBAAgB,CAAC;IACzB,CAAC;CACD;AA5ID,kDA4IC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IRequest } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tDriverHeader,\n\tIResolvedUrl,\n\tIUrlResolver,\n} from \"@fluidframework/driver-definitions/internal\";\n\n/**\n * As the name implies this is not secure and should not be used in production. It simply makes the example easier\n * to get up and running.\n *\n * In our example we run a simple web server via webpack-dev-server. This defines a URL format of the form\n * http://localhost:8080/<documentId>/<path>.\n *\n * We then need to map that to a Fluid based URL. These are of the form\n * https://orderingUrl/<tenantId>/<documentId>/<path>.\n *\n * The tenantId/documentId pair defines the 'full' document ID the service makes use of. The path is then an optional\n * part of the URL that the document interprets and maps to a data store. It's exactly similar to how a web service\n * works or a router inside of a single page app framework.\n * @internal\n */\nexport class InsecureUrlResolver implements IUrlResolver {\n\tprivate readonly cache = new Map<string, Promise<IResolvedUrl>>();\n\n\tconstructor(\n\t\tprivate readonly hostUrl: string,\n\t\tprivate readonly ordererUrl: string,\n\t\tprivate readonly storageUrl: string,\n\t\tprivate readonly deltaStreamUrl: string,\n\t\tprivate readonly tenantId: string,\n\t\tprivate readonly bearer: string,\n\t\tprivate readonly isForNodeTest: boolean = false,\n\t) {}\n\n\tpublic async resolve(request: IRequest): Promise<IResolvedUrl | undefined> {\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\tif (request.headers?.[DriverHeader.createNew]) {\n\t\t\tconst [, queryString] = request.url.split(\"?\");\n\t\t\tconst searchParams = new URLSearchParams(queryString);\n\t\t\tconst fileName = searchParams.get(\"fileName\");\n\t\t\treturn this.resolveHelper(fileName);\n\t\t}\n\t\tconst parsedUrl = new URL(request.url);\n\t\t// If hosts match then we use the local tenant information. Otherwise we make a REST call out to the hosting\n\t\t// service using our bearer token.\n\t\tif (this.isForNodeTest) {\n\t\t\tconst [, documentId, tmpRelativePath] = parsedUrl.pathname.substr(1).split(\"/\");\n\t\t\tconst relativePath = tmpRelativePath ?? \"\";\n\t\t\treturn this.resolveHelper(documentId, relativePath, parsedUrl.search);\n\t\t} else if (parsedUrl.host === window.location.host) {\n\t\t\tconst fullPath = parsedUrl.pathname.substr(1);\n\t\t\tconst documentId = fullPath.split(\"/\")[0];\n\t\t\tconst documentRelativePath = fullPath.slice(documentId.length);\n\t\t\treturn this.resolveHelper(documentId, documentRelativePath);\n\t\t} else {\n\t\t\tconst maybeResolvedUrl = this.cache.get(request.url);\n\t\t\tif (maybeResolvedUrl) {\n\t\t\t\treturn maybeResolvedUrl;\n\t\t\t}\n\n\t\t\tconst resolvedP = fetch(`${this.hostUrl}/apis/load`, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\tAuthorization: `Bearer ${this.bearer}`,\n\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\turl: request.url,\n\t\t\t\t}),\n\t\t\t}).then(async (response) => {\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tthrow new Error(`HTTP error! status: ${response.status}`);\n\t\t\t\t}\n\t\t\t\treturn response.json() as Promise<IResolvedUrl>;\n\t\t\t});\n\t\t\tthis.cache.set(request.url, resolvedP);\n\n\t\t\treturn this.cache.get(request.url);\n\t\t}\n\t}\n\n\tprivate resolveHelper(\n\t\tdocumentId: string | null,\n\t\tdocumentRelativePath: string = \"\",\n\t\tqueryParams: string = \"\",\n\t): IResolvedUrl {\n\t\tconst encodedTenantId = encodeURIComponent(this.tenantId);\n\t\tconst host = new URL(this.ordererUrl).host;\n\t\t// when the document ID is not provided we need to resolve a special create new document URL.\n\t\t// the actual container ID will be generated by the driver.\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\tif (!documentId) {\n\t\t\tconst createNewResponse: IResolvedUrl = {\n\t\t\t\tendpoints: {\n\t\t\t\t\tdeltaStorageUrl: `${this.ordererUrl}/deltas/${encodedTenantId}/new`,\n\t\t\t\t\tdeltaStreamUrl: this.deltaStreamUrl,\n\t\t\t\t\tordererUrl: this.ordererUrl,\n\t\t\t\t\tstorageUrl: `${this.storageUrl}/repos/${encodedTenantId}`,\n\t\t\t\t},\n\t\t\t\t// document ID is ignored by the driver for new container requests\n\t\t\t\tid: \"\",\n\t\t\t\ttokens: {},\n\t\t\t\ttype: \"fluid\",\n\t\t\t\turl: `https://${host}/${encodedTenantId}/new`,\n\t\t\t};\n\t\t\treturn createNewResponse;\n\t\t}\n\t\tconst encodedDocId = encodeURIComponent(documentId);\n\t\tconst relativePath =\n\t\t\t!documentRelativePath || documentRelativePath.startsWith(\"/\")\n\t\t\t\t? documentRelativePath\n\t\t\t\t: `/${documentRelativePath}`;\n\t\tconst documentUrl = `https://${host}/${encodedTenantId}/${encodedDocId}${relativePath}${queryParams}`;\n\n\t\tconst deltaStorageUrl = `${this.ordererUrl}/deltas/${encodedTenantId}/${encodedDocId}`;\n\t\tconst storageUrl = `${this.storageUrl}/repos/${encodedTenantId}`;\n\n\t\tconst response: IResolvedUrl = {\n\t\t\tendpoints: {\n\t\t\t\tdeltaStorageUrl,\n\t\t\t\tdeltaStreamUrl: this.deltaStreamUrl,\n\t\t\t\tordererUrl: this.ordererUrl,\n\t\t\t\tstorageUrl,\n\t\t\t},\n\t\t\tid: documentId,\n\t\t\ttokens: {},\n\t\t\ttype: \"fluid\",\n\t\t\turl: documentUrl,\n\t\t};\n\t\treturn response;\n\t}\n\n\tpublic async getAbsoluteUrl(\n\t\tresolvedUrl: IResolvedUrl,\n\t\trelativeUrl: string,\n\t): Promise<string> {\n\t\tconst parsedUrl = new URL(resolvedUrl.url);\n\t\tconst [, , documentId] = parsedUrl.pathname?.split(\"/\") ?? [];\n\n\t\tassert(!!documentId, 0x273 /* \"Invalid document id from parsed URL\" */);\n\n\t\tlet url = relativeUrl;\n\t\tif (url.startsWith(\"/\")) {\n\t\t\turl = url.substr(1);\n\t\t}\n\n\t\treturn `${this.hostUrl}/${encodeURIComponent(this.tenantId)}/${encodeURIComponent(\n\t\t\tdocumentId,\n\t\t)}/${url}`;\n\t}\n\n\tpublic createCreateNewRequest(fileName?: string): IRequest {\n\t\tconst createNewRequest: IRequest = {\n\t\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\t\turl: fileName ? `${this.hostUrl}?fileName=${fileName}` : this.hostUrl,\n\t\t\theaders: {\n\t\t\t\t[DriverHeader.createNew]: true,\n\t\t\t},\n\t\t};\n\t\treturn createNewRequest;\n\t}\n}\n"]}
@@ -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/driver-utils";
8
- export declare const pkgVersion = "2.80.0";
8
+ export declare const pkgVersion = "2.81.0";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -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/driver-utils";
11
- exports.pkgVersion = "2.80.0";
11
+ exports.pkgVersion = "2.81.0";
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,8BAA8B,CAAC;AACzC,QAAA,UAAU,GAAG,QAAQ,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/driver-utils\";\nexport const pkgVersion = \"2.80.0\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,8BAA8B,CAAC;AACzC,QAAA,UAAU,GAAG,QAAQ,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/driver-utils\";\nexport const pkgVersion = \"2.81.0\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"prefetchDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/prefetchDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,+BAA+B,EAC/B,aAAa,EACb,QAAQ,EACR,MAAM,6CAA6C,CAAC;AAGrD,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAG/E;;GAEG;AACH,qBAAa,8BAA+B,SAAQ,2BAA2B;IAE9E,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA+C;IAC7E,OAAO,CAAC,eAAe,CAAQ;IAE/B,IAAW,QAAQ,IAAI,+BAA+B,GAAG,SAAS,CAKjE;IAEY,eAAe,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAclE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAGxD,YAAY,IAAI,IAAI;YAKb,UAAU;IAqBxB,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,gBAAgB;CAkBxB"}
1
+ {"version":3,"file":"prefetchDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/prefetchDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,+BAA+B,EAC/B,aAAa,EACb,QAAQ,EACR,MAAM,6CAA6C,CAAC;AAGrD,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAG/E;;GAEG;AACH,qBAAa,8BAA+B,SAAQ,2BAA2B;IAE9E,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA+C;IAC7E,OAAO,CAAC,eAAe,CAAQ;IAE/B,IAAW,QAAQ,IAAI,+BAA+B,GAAG,SAAS,CAKjE;IAEY,eAAe,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAmBlE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAGxD,YAAY,IAAI,IAAI;YAKb,UAAU;IA0BxB,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,gBAAgB;CAoBxB"}
@@ -27,12 +27,17 @@ class PrefetchDocumentStorageService extends documentStorageServiceProxy_js_1.Do
27
27
  async getSnapshotTree(version) {
28
28
  const p = this.internalStorageService.getSnapshotTree(version);
29
29
  if (this.prefetchEnabled) {
30
- // We don't care if the prefetch succeeds
31
- void p.then((tree) => {
30
+ // Fire-and-forget prefetch - we don't care if it succeeds.
31
+ // The .catch() prevents unhandled rejection when p rejects, since
32
+ // p.then() creates a derived promise that also rejects if p rejects.
33
+ // Callers awaiting the returned p will still receive the error.
34
+ p.then((tree) => {
32
35
  if (tree === null || tree === undefined) {
33
36
  return;
34
37
  }
35
38
  this.prefetchTree(tree);
39
+ }).catch(() => {
40
+ // Intentionally empty - error will be handled by caller awaiting p
36
41
  });
37
42
  }
38
43
  return p;
@@ -51,12 +56,20 @@ class PrefetchDocumentStorageService extends documentStorageServiceProxy_js_1.Do
51
56
  return prefetchedBlobP;
52
57
  }
53
58
  const prefetchedBlobPFromStorage = this.internalStorageService.readBlob(blobId);
54
- this.prefetchCache.set(blobId, prefetchedBlobPFromStorage.catch((error) => {
59
+ // Attach error handler for side effects only:
60
+ // 1. Clear cache on retryable errors so next read retries
61
+ // 2. Prevent unhandled rejection warning for fire-and-forget prefetch
62
+ // Note: Callers who await the cached promise will still see the rejection
63
+ prefetchedBlobPFromStorage.catch((error) => {
55
64
  if ((0, network_js_1.canRetryOnError)(error)) {
56
- this.prefetchCache.delete(blobId);
65
+ // Only clear cache if our promise is still the cached one
66
+ // (avoids race condition with concurrent requests)
67
+ if (this.prefetchCache.get(blobId) === prefetchedBlobPFromStorage) {
68
+ this.prefetchCache.delete(blobId);
69
+ }
57
70
  }
58
- throw error;
59
- }));
71
+ });
72
+ this.prefetchCache.set(blobId, prefetchedBlobPFromStorage);
60
73
  return prefetchedBlobPFromStorage;
61
74
  }
62
75
  return this.internalStorageService.readBlob(blobId);
@@ -65,16 +78,23 @@ class PrefetchDocumentStorageService extends documentStorageServiceProxy_js_1.Do
65
78
  const secondary = [];
66
79
  this.prefetchTreeCore(tree, secondary);
67
80
  for (const blob of secondary) {
68
- // We don't care if the prefetch succeeds
69
- void this.cachedRead(blob);
81
+ // Skip if already cached (avoids unnecessary async overhead)
82
+ if (this.prefetchCache.has(blob)) {
83
+ continue;
84
+ }
85
+ // Fire-and-forget prefetch. The .catch() prevents unhandled rejection
86
+ // since cachedRead is async and returns a separate promise chain.
87
+ this.cachedRead(blob).catch(() => { });
70
88
  }
71
89
  }
72
90
  prefetchTreeCore(tree, secondary) {
73
91
  for (const [blobKey, blob] of Object.entries(tree.blobs)) {
74
92
  if (blobKey.startsWith(".") || blobKey === "header" || blobKey.startsWith("quorum")) {
75
- if (blob !== null) {
76
- // We don't care if the prefetch succeeds
77
- void this.cachedRead(blob);
93
+ // Skip if already cached (avoids unnecessary async overhead)
94
+ if (blob !== null && !this.prefetchCache.has(blob)) {
95
+ // Fire-and-forget prefetch. The .catch() prevents unhandled rejection
96
+ // since cachedRead is async and returns a separate promise chain.
97
+ this.cachedRead(blob).catch(() => { });
78
98
  }
79
99
  }
80
100
  else if (!blobKey.startsWith("deltas")) {
@@ -1 +1 @@
1
- {"version":3,"file":"prefetchDocumentStorageService.js","sourceRoot":"","sources":["../src/prefetchDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,0EAAkF;AAElF,qFAA+E;AAC/E,6CAA+C;AAE/C;;GAEG;AACH,MAAa,8BAA+B,SAAQ,4DAA2B;IAA/E;;QACC,qCAAqC;QACpB,kBAAa,GAAG,IAAI,GAAG,EAAoC,CAAC;QACrE,oBAAe,GAAG,IAAI,CAAC;IAgFhC,CAAC;IA9EA,IAAW,QAAQ;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC;QACtD,IAAI,QAAQ,EAAE,CAAC;YACd,OAAO,EAAE,GAAG,QAAQ,EAAE,OAAO,EAAE,8BAAmB,CAAC,SAAS,EAAE,CAAC;QAChE,CAAC;IACF,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,OAAkB;QAC9C,MAAM,CAAC,GAAG,IAAI,CAAC,sBAAsB,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAC/D,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YAC1B,yCAAyC;YACzC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,IAAsC,EAAE,EAAE;gBACtD,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBACzC,OAAO;gBACR,CAAC;gBACD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,CAAC,CAAC;IACV,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,MAAc;QACnC,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IACM,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AAC,KAAK,CAAC,EAAE,CAAC;YAC1D,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACrF,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;oBACnB,yCAAyC;oBACzC,KAAK,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;gBAC5B,CAAC;YACF,CAAC;iBAAM,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC1C,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;oBACnB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACtB,CAAC;YACF,CAAC;QACF,CAAC;QAED,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACjD,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC3C,CAAC;IACF,CAAC;CACD;AAnFD,wEAmFC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tIDocumentStorageServicePolicies,\n\tISnapshotTree,\n\tIVersion,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { LoaderCachingPolicy } from \"@fluidframework/driver-definitions/internal\";\n\nimport { DocumentStorageServiceProxy } from \"./documentStorageServiceProxy.js\";\nimport { canRetryOnError } from \"./network.js\";\n\n/**\n * @internal\n */\nexport class PrefetchDocumentStorageService extends DocumentStorageServiceProxy {\n\t// BlobId -> blob prefetchCache cache\n\tprivate readonly prefetchCache = new Map<string, Promise<ArrayBufferLike>>();\n\tprivate prefetchEnabled = true;\n\n\tpublic get policies(): IDocumentStorageServicePolicies | undefined {\n\t\tconst policies = this.internalStorageService.policies;\n\t\tif (policies) {\n\t\t\treturn { ...policies, caching: LoaderCachingPolicy.NoCaching };\n\t\t}\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n\t\tconst p = this.internalStorageService.getSnapshotTree(version);\n\t\tif (this.prefetchEnabled) {\n\t\t\t// We don't care if the prefetch succeeds\n\t\t\tvoid p.then((tree: ISnapshotTree | null | undefined) => {\n\t\t\t\tif (tree === null || tree === undefined) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.prefetchTree(tree);\n\t\t\t});\n\t\t}\n\t\treturn p;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\treturn this.cachedRead(blobId);\n\t}\n\tpublic stopPrefetch(): void {\n\t\tthis.prefetchEnabled = false;\n\t\tthis.prefetchCache.clear();\n\t}\n\n\tprivate async cachedRead(blobId: string): Promise<ArrayBufferLike> {\n\t\tif (this.prefetchEnabled) {\n\t\t\tconst prefetchedBlobP = this.prefetchCache.get(blobId);\n\t\t\tif (prefetchedBlobP !== undefined) {\n\t\t\t\treturn prefetchedBlobP;\n\t\t\t}\n\t\t\tconst prefetchedBlobPFromStorage = this.internalStorageService.readBlob(blobId);\n\t\t\tthis.prefetchCache.set(\n\t\t\t\tblobId,\n\t\t\t\tprefetchedBlobPFromStorage.catch((error) => {\n\t\t\t\t\tif (canRetryOnError(error)) {\n\t\t\t\t\t\tthis.prefetchCache.delete(blobId);\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}),\n\t\t\t);\n\t\t\treturn prefetchedBlobPFromStorage;\n\t\t}\n\t\treturn this.internalStorageService.readBlob(blobId);\n\t}\n\n\tprivate prefetchTree(tree: ISnapshotTree): void {\n\t\tconst secondary: string[] = [];\n\t\tthis.prefetchTreeCore(tree, secondary);\n\n\t\tfor (const blob of secondary) {\n\t\t\t// We don't care if the prefetch succeeds\n\t\t\tvoid this.cachedRead(blob);\n\t\t}\n\t}\n\n\tprivate prefetchTreeCore(tree: ISnapshotTree, secondary: string[]): void {\n\t\tfor (const [blobKey, blob] of Object.entries(tree.blobs)) {\n\t\t\tif (blobKey.startsWith(\".\") || blobKey === \"header\" || blobKey.startsWith(\"quorum\")) {\n\t\t\t\tif (blob !== null) {\n\t\t\t\t\t// We don't care if the prefetch succeeds\n\t\t\t\t\tvoid this.cachedRead(blob);\n\t\t\t\t}\n\t\t\t} else if (!blobKey.startsWith(\"deltas\")) {\n\t\t\t\tif (blob !== null) {\n\t\t\t\t\tsecondary.push(blob);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const subTree of Object.values(tree.trees)) {\n\t\t\tthis.prefetchTreeCore(subTree, secondary);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"prefetchDocumentStorageService.js","sourceRoot":"","sources":["../src/prefetchDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,0EAAkF;AAElF,qFAA+E;AAC/E,6CAA+C;AAE/C;;GAEG;AACH,MAAa,8BAA+B,SAAQ,4DAA2B;IAA/E;;QACC,qCAAqC;QACpB,kBAAa,GAAG,IAAI,GAAG,EAAoC,CAAC;QACrE,oBAAe,GAAG,IAAI,CAAC;IAiGhC,CAAC;IA/FA,IAAW,QAAQ;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC;QACtD,IAAI,QAAQ,EAAE,CAAC;YACd,OAAO,EAAE,GAAG,QAAQ,EAAE,OAAO,EAAE,8BAAmB,CAAC,SAAS,EAAE,CAAC;QAChE,CAAC;IACF,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,OAAkB;QAC9C,MAAM,CAAC,GAAG,IAAI,CAAC,sBAAsB,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAC/D,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YAC1B,2DAA2D;YAC3D,kEAAkE;YAClE,qEAAqE;YACrE,gEAAgE;YAChE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAsC,EAAE,EAA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EAAE,CAAC;gBAC1C,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;oBACnB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACtB,CAAC;YACF,CAAC;QACF,CAAC;QAED,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACjD,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC3C,CAAC;IACF,CAAC;CACD;AApGD,wEAoGC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tIDocumentStorageServicePolicies,\n\tISnapshotTree,\n\tIVersion,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { LoaderCachingPolicy } from \"@fluidframework/driver-definitions/internal\";\n\nimport { DocumentStorageServiceProxy } from \"./documentStorageServiceProxy.js\";\nimport { canRetryOnError } from \"./network.js\";\n\n/**\n * @internal\n */\nexport class PrefetchDocumentStorageService extends DocumentStorageServiceProxy {\n\t// BlobId -> blob prefetchCache cache\n\tprivate readonly prefetchCache = new Map<string, Promise<ArrayBufferLike>>();\n\tprivate prefetchEnabled = true;\n\n\tpublic get policies(): IDocumentStorageServicePolicies | undefined {\n\t\tconst policies = this.internalStorageService.policies;\n\t\tif (policies) {\n\t\t\treturn { ...policies, caching: LoaderCachingPolicy.NoCaching };\n\t\t}\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n\t\tconst p = this.internalStorageService.getSnapshotTree(version);\n\t\tif (this.prefetchEnabled) {\n\t\t\t// Fire-and-forget prefetch - we don't care if it succeeds.\n\t\t\t// The .catch() prevents unhandled rejection when p rejects, since\n\t\t\t// p.then() creates a derived promise that also rejects if p rejects.\n\t\t\t// Callers awaiting the returned p will still receive the error.\n\t\t\tp.then((tree: ISnapshotTree | null | undefined) => {\n\t\t\t\tif (tree === null || tree === undefined) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.prefetchTree(tree);\n\t\t\t}).catch(() => {\n\t\t\t\t// Intentionally empty - error will be handled by caller awaiting p\n\t\t\t});\n\t\t}\n\t\treturn p;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\treturn this.cachedRead(blobId);\n\t}\n\tpublic stopPrefetch(): void {\n\t\tthis.prefetchEnabled = false;\n\t\tthis.prefetchCache.clear();\n\t}\n\n\tprivate async cachedRead(blobId: string): Promise<ArrayBufferLike> {\n\t\tif (this.prefetchEnabled) {\n\t\t\tconst prefetchedBlobP = this.prefetchCache.get(blobId);\n\t\t\tif (prefetchedBlobP !== undefined) {\n\t\t\t\treturn prefetchedBlobP;\n\t\t\t}\n\t\t\tconst prefetchedBlobPFromStorage = this.internalStorageService.readBlob(blobId);\n\t\t\t// Attach error handler for side effects only:\n\t\t\t// 1. Clear cache on retryable errors so next read retries\n\t\t\t// 2. Prevent unhandled rejection warning for fire-and-forget prefetch\n\t\t\t// Note: Callers who await the cached promise will still see the rejection\n\t\t\tprefetchedBlobPFromStorage.catch((error) => {\n\t\t\t\tif (canRetryOnError(error)) {\n\t\t\t\t\t// Only clear cache if our promise is still the cached one\n\t\t\t\t\t// (avoids race condition with concurrent requests)\n\t\t\t\t\tif (this.prefetchCache.get(blobId) === prefetchedBlobPFromStorage) {\n\t\t\t\t\t\tthis.prefetchCache.delete(blobId);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis.prefetchCache.set(blobId, prefetchedBlobPFromStorage);\n\t\t\treturn prefetchedBlobPFromStorage;\n\t\t}\n\t\treturn this.internalStorageService.readBlob(blobId);\n\t}\n\n\tprivate prefetchTree(tree: ISnapshotTree): void {\n\t\tconst secondary: string[] = [];\n\t\tthis.prefetchTreeCore(tree, secondary);\n\n\t\tfor (const blob of secondary) {\n\t\t\t// Skip if already cached (avoids unnecessary async overhead)\n\t\t\tif (this.prefetchCache.has(blob)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Fire-and-forget prefetch. The .catch() prevents unhandled rejection\n\t\t\t// since cachedRead is async and returns a separate promise chain.\n\t\t\tthis.cachedRead(blob).catch(() => {});\n\t\t}\n\t}\n\n\tprivate prefetchTreeCore(tree: ISnapshotTree, secondary: string[]): void {\n\t\tfor (const [blobKey, blob] of Object.entries(tree.blobs)) {\n\t\t\tif (blobKey.startsWith(\".\") || blobKey === \"header\" || blobKey.startsWith(\"quorum\")) {\n\t\t\t\t// Skip if already cached (avoids unnecessary async overhead)\n\t\t\t\tif (blob !== null && !this.prefetchCache.has(blob)) {\n\t\t\t\t\t// Fire-and-forget prefetch. The .catch() prevents unhandled rejection\n\t\t\t\t\t// since cachedRead is async and returns a separate promise chain.\n\t\t\t\t\tthis.cachedRead(blob).catch(() => {});\n\t\t\t\t}\n\t\t\t} else if (!blobKey.startsWith(\"deltas\")) {\n\t\t\t\tif (blob !== null) {\n\t\t\t\t\tsecondary.push(blob);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const subTree of Object.values(tree.trees)) {\n\t\t\tthis.prefetchTreeCore(subTree, secondary);\n\t\t}\n\t}\n}\n"]}
package/eslint.config.mts CHANGED
@@ -1,8 +1,8 @@
1
- /* eslint-disable */
2
- /**
3
- * GENERATED FILE - DO NOT EDIT DIRECTLY.
4
- * To regenerate: pnpm tsx scripts/generate-flat-eslint-configs.ts --typescript
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
5
4
  */
5
+
6
6
  import type { Linter } from "eslint";
7
7
  import { minimalDeprecated } from "../../../common/build/eslint-config-fluid/flat.mts";
8
8
 
@@ -1 +1 @@
1
- {"version":3,"file":"insecureUrlResolver.d.ts","sourceRoot":"","sources":["../src/insecureUrlResolver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC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,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAT/B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA4C;gBAGhD,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,aAAa,GAAE,OAAe;IAGnC,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;IA+C1E,OAAO,CAAC,aAAa;IAmDR,cAAc,CAC1B,WAAW,EAAE,YAAY,EACzB,WAAW,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC;IAgBX,sBAAsB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,QAAQ;CAU1D"}
@@ -4,7 +4,6 @@
4
4
  */
5
5
  import { assert } from "@fluidframework/core-utils/internal";
6
6
  import { DriverHeader, } from "@fluidframework/driver-definitions/internal";
7
- import Axios from "axios";
8
7
  /**
9
8
  * As the name implies this is not secure and should not be used in production. It simply makes the example easier
10
9
  * to get up and running.
@@ -58,15 +57,22 @@ export class InsecureUrlResolver {
58
57
  if (maybeResolvedUrl) {
59
58
  return maybeResolvedUrl;
60
59
  }
61
- const headers = {
62
- Authorization: `Bearer ${this.bearer}`,
63
- };
64
- const resolvedP = Axios.post(`${this.hostUrl}/apis/load`, {
65
- url: request.url,
66
- }, {
67
- headers,
60
+ const resolvedP = fetch(`${this.hostUrl}/apis/load`, {
61
+ method: "POST",
62
+ headers: {
63
+ Authorization: `Bearer ${this.bearer}`,
64
+ "Content-Type": "application/json",
65
+ },
66
+ body: JSON.stringify({
67
+ url: request.url,
68
+ }),
69
+ }).then(async (response) => {
70
+ if (!response.ok) {
71
+ throw new Error(`HTTP error! status: ${response.status}`);
72
+ }
73
+ return response.json();
68
74
  });
69
- this.cache.set(request.url, resolvedP.then((resolved) => resolved.data));
75
+ this.cache.set(request.url, resolvedP);
70
76
  return this.cache.get(request.url);
71
77
  }
72
78
  }
@@ -1 +1 @@
1
- {"version":3,"file":"insecureUrlResolver.js","sourceRoot":"","sources":["../src/insecureUrlResolver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EACN,YAAY,GAGZ,MAAM,6CAA6C,CAAC;AACrD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,mBAAmB;IAG/B,YACkB,OAAe,EACf,UAAkB,EAClB,UAAkB,EAClB,cAAsB,EACtB,QAAgB,EAChB,MAAc,EACd,gBAAyB,KAAK;QAN9B,YAAO,GAAP,OAAO,CAAQ;QACf,eAAU,GAAV,UAAU,CAAQ;QAClB,eAAU,GAAV,UAAU,CAAQ;QAClB,mBAAc,GAAd,cAAc,CAAQ;QACtB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,kBAAa,GAAb,aAAa,CAAiB;QAT/B,UAAK,GAAG,IAAI,GAAG,EAAiC,CAAC;IAU/D,CAAC;IAEG,KAAK,CAAC,OAAO,CAAC,OAAiB;QACrC,yEAAyE;QACzE,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,CAAC;YAC/C,MAAM,CAAC,EAAE,WAAW,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC/C,MAAM,YAAY,GAAG,IAAI,eAAe,CAAC,WAAW,CAAC,CAAC;YACtD,MAAM,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,CAA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,IAAI,GAAG,EAAE,CAAC;IACZ,CAAC;IAEM,sBAAsB,CAAC,QAAiB;QAC9C,MAAM,gBAAgB,GAAa;YAClC,yEAAyE;YACzE,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,aAAa,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO;YACrE,OAAO,EAAE;gBACR,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,IAAI;aAC9B;SACD,CAAC;QACF,OAAO,gBAAgB,CAAC;IACzB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IRequest } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tDriverHeader,\n\tIResolvedUrl,\n\tIUrlResolver,\n} from \"@fluidframework/driver-definitions/internal\";\nimport Axios from \"axios\";\n\n/**\n * As the name implies this is not secure and should not be used in production. It simply makes the example easier\n * to get up and running.\n *\n * In our example we run a simple web server via webpack-dev-server. This defines a URL format of the form\n * http://localhost:8080/<documentId>/<path>.\n *\n * We then need to map that to a Fluid based URL. These are of the form\n * https://orderingUrl/<tenantId>/<documentId>/<path>.\n *\n * The tenantId/documentId pair defines the 'full' document ID the service makes use of. The path is then an optional\n * part of the URL that the document interprets and maps to a data store. It's exactly similar to how a web service\n * works or a router inside of a single page app framework.\n * @internal\n */\nexport class InsecureUrlResolver implements IUrlResolver {\n\tprivate readonly cache = new Map<string, Promise<IResolvedUrl>>();\n\n\tconstructor(\n\t\tprivate readonly hostUrl: string,\n\t\tprivate readonly ordererUrl: string,\n\t\tprivate readonly storageUrl: string,\n\t\tprivate readonly deltaStreamUrl: string,\n\t\tprivate readonly tenantId: string,\n\t\tprivate readonly bearer: string,\n\t\tprivate readonly isForNodeTest: boolean = false,\n\t) {}\n\n\tpublic async resolve(request: IRequest): Promise<IResolvedUrl | undefined> {\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\tif (request.headers?.[DriverHeader.createNew]) {\n\t\t\tconst [, queryString] = request.url.split(\"?\");\n\t\t\tconst searchParams = new URLSearchParams(queryString);\n\t\t\tconst fileName = searchParams.get(\"fileName\");\n\t\t\treturn this.resolveHelper(fileName);\n\t\t}\n\t\tconst parsedUrl = new URL(request.url);\n\t\t// If hosts match then we use the local tenant information. Otherwise we make a REST call out to the hosting\n\t\t// service using our bearer token.\n\t\tif (this.isForNodeTest) {\n\t\t\tconst [, documentId, tmpRelativePath] = parsedUrl.pathname.substr(1).split(\"/\");\n\t\t\tconst relativePath = tmpRelativePath ?? \"\";\n\t\t\treturn this.resolveHelper(documentId, relativePath, parsedUrl.search);\n\t\t} else if (parsedUrl.host === window.location.host) {\n\t\t\tconst fullPath = parsedUrl.pathname.substr(1);\n\t\t\tconst documentId = fullPath.split(\"/\")[0];\n\t\t\tconst documentRelativePath = fullPath.slice(documentId.length);\n\t\t\treturn this.resolveHelper(documentId, documentRelativePath);\n\t\t} else {\n\t\t\tconst maybeResolvedUrl = this.cache.get(request.url);\n\t\t\tif (maybeResolvedUrl) {\n\t\t\t\treturn maybeResolvedUrl;\n\t\t\t}\n\n\t\t\tconst headers = {\n\t\t\t\tAuthorization: `Bearer ${this.bearer}`,\n\t\t\t};\n\t\t\tconst resolvedP = Axios.post<IResolvedUrl>(\n\t\t\t\t`${this.hostUrl}/apis/load`,\n\t\t\t\t{\n\t\t\t\t\turl: request.url,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\theaders,\n\t\t\t\t},\n\t\t\t);\n\t\t\tthis.cache.set(\n\t\t\t\trequest.url,\n\t\t\t\tresolvedP.then((resolved) => resolved.data),\n\t\t\t);\n\n\t\t\treturn this.cache.get(request.url);\n\t\t}\n\t}\n\n\tprivate resolveHelper(\n\t\tdocumentId: string | null,\n\t\tdocumentRelativePath: string = \"\",\n\t\tqueryParams: string = \"\",\n\t): IResolvedUrl {\n\t\tconst encodedTenantId = encodeURIComponent(this.tenantId);\n\t\tconst host = new URL(this.ordererUrl).host;\n\t\t// when the document ID is not provided we need to resolve a special create new document URL.\n\t\t// the actual container ID will be generated by the driver.\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\tif (!documentId) {\n\t\t\tconst createNewResponse: IResolvedUrl = {\n\t\t\t\tendpoints: {\n\t\t\t\t\tdeltaStorageUrl: `${this.ordererUrl}/deltas/${encodedTenantId}/new`,\n\t\t\t\t\tdeltaStreamUrl: this.deltaStreamUrl,\n\t\t\t\t\tordererUrl: this.ordererUrl,\n\t\t\t\t\tstorageUrl: `${this.storageUrl}/repos/${encodedTenantId}`,\n\t\t\t\t},\n\t\t\t\t// document ID is ignored by the driver for new container requests\n\t\t\t\tid: \"\",\n\t\t\t\ttokens: {},\n\t\t\t\ttype: \"fluid\",\n\t\t\t\turl: `https://${host}/${encodedTenantId}/new`,\n\t\t\t};\n\t\t\treturn createNewResponse;\n\t\t}\n\t\tconst encodedDocId = encodeURIComponent(documentId);\n\t\tconst relativePath =\n\t\t\t!documentRelativePath || documentRelativePath.startsWith(\"/\")\n\t\t\t\t? documentRelativePath\n\t\t\t\t: `/${documentRelativePath}`;\n\t\tconst documentUrl = `https://${host}/${encodedTenantId}/${encodedDocId}${relativePath}${queryParams}`;\n\n\t\tconst deltaStorageUrl = `${this.ordererUrl}/deltas/${encodedTenantId}/${encodedDocId}`;\n\t\tconst storageUrl = `${this.storageUrl}/repos/${encodedTenantId}`;\n\n\t\tconst response: IResolvedUrl = {\n\t\t\tendpoints: {\n\t\t\t\tdeltaStorageUrl,\n\t\t\t\tdeltaStreamUrl: this.deltaStreamUrl,\n\t\t\t\tordererUrl: this.ordererUrl,\n\t\t\t\tstorageUrl,\n\t\t\t},\n\t\t\tid: documentId,\n\t\t\ttokens: {},\n\t\t\ttype: \"fluid\",\n\t\t\turl: documentUrl,\n\t\t};\n\t\treturn response;\n\t}\n\n\tpublic async getAbsoluteUrl(\n\t\tresolvedUrl: IResolvedUrl,\n\t\trelativeUrl: string,\n\t): Promise<string> {\n\t\tconst parsedUrl = new URL(resolvedUrl.url);\n\t\tconst [, , documentId] = parsedUrl.pathname?.split(\"/\") ?? [];\n\n\t\tassert(!!documentId, 0x273 /* \"Invalid document id from parsed URL\" */);\n\n\t\tlet url = relativeUrl;\n\t\tif (url.startsWith(\"/\")) {\n\t\t\turl = url.substr(1);\n\t\t}\n\n\t\treturn `${this.hostUrl}/${encodeURIComponent(this.tenantId)}/${encodeURIComponent(\n\t\t\tdocumentId,\n\t\t)}/${url}`;\n\t}\n\n\tpublic createCreateNewRequest(fileName?: string): IRequest {\n\t\tconst createNewRequest: IRequest = {\n\t\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\t\turl: fileName ? `${this.hostUrl}?fileName=${fileName}` : this.hostUrl,\n\t\t\theaders: {\n\t\t\t\t[DriverHeader.createNew]: true,\n\t\t\t},\n\t\t};\n\t\treturn createNewRequest;\n\t}\n}\n"]}
1
+ {"version":3,"file":"insecureUrlResolver.js","sourceRoot":"","sources":["../src/insecureUrlResolver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EACN,YAAY,GAGZ,MAAM,6CAA6C,CAAC;AAErD;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,mBAAmB;IAG/B,YACkB,OAAe,EACf,UAAkB,EAClB,UAAkB,EAClB,cAAsB,EACtB,QAAgB,EAChB,MAAc,EACd,gBAAyB,KAAK;QAN9B,YAAO,GAAP,OAAO,CAAQ;QACf,eAAU,GAAV,UAAU,CAAQ;QAClB,eAAU,GAAV,UAAU,CAAQ;QAClB,mBAAc,GAAd,cAAc,CAAQ;QACtB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,kBAAa,GAAb,aAAa,CAAiB;QAT/B,UAAK,GAAG,IAAI,GAAG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QAAQ,CAAC;IACjB,CAAC;IAEM,KAAK,CAAC,cAAc,CAC1B,WAAyB,EACzB,WAAmB;QAEnB,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QAC3C,MAAM,CAAC,EAAE,AAAD,EAAG,UAAU,CAAC,GAAG,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAE9D,MAAM,CAAC,CAAC,CAAC,UAAU,EAAE,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAExE,IAAI,GAAG,GAAG,WAAW,CAAC;QACtB,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACrB,CAAC;QAED,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,kBAAkB,CAChF,UAAU,CACV,IAAI,GAAG,EAAE,CAAC;IACZ,CAAC;IAEM,sBAAsB,CAAC,QAAiB;QAC9C,MAAM,gBAAgB,GAAa;YAClC,yEAAyE;YACzE,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,aAAa,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO;YACrE,OAAO,EAAE;gBACR,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,IAAI;aAC9B;SACD,CAAC;QACF,OAAO,gBAAgB,CAAC;IACzB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IRequest } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tDriverHeader,\n\tIResolvedUrl,\n\tIUrlResolver,\n} from \"@fluidframework/driver-definitions/internal\";\n\n/**\n * As the name implies this is not secure and should not be used in production. It simply makes the example easier\n * to get up and running.\n *\n * In our example we run a simple web server via webpack-dev-server. This defines a URL format of the form\n * http://localhost:8080/<documentId>/<path>.\n *\n * We then need to map that to a Fluid based URL. These are of the form\n * https://orderingUrl/<tenantId>/<documentId>/<path>.\n *\n * The tenantId/documentId pair defines the 'full' document ID the service makes use of. The path is then an optional\n * part of the URL that the document interprets and maps to a data store. It's exactly similar to how a web service\n * works or a router inside of a single page app framework.\n * @internal\n */\nexport class InsecureUrlResolver implements IUrlResolver {\n\tprivate readonly cache = new Map<string, Promise<IResolvedUrl>>();\n\n\tconstructor(\n\t\tprivate readonly hostUrl: string,\n\t\tprivate readonly ordererUrl: string,\n\t\tprivate readonly storageUrl: string,\n\t\tprivate readonly deltaStreamUrl: string,\n\t\tprivate readonly tenantId: string,\n\t\tprivate readonly bearer: string,\n\t\tprivate readonly isForNodeTest: boolean = false,\n\t) {}\n\n\tpublic async resolve(request: IRequest): Promise<IResolvedUrl | undefined> {\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\tif (request.headers?.[DriverHeader.createNew]) {\n\t\t\tconst [, queryString] = request.url.split(\"?\");\n\t\t\tconst searchParams = new URLSearchParams(queryString);\n\t\t\tconst fileName = searchParams.get(\"fileName\");\n\t\t\treturn this.resolveHelper(fileName);\n\t\t}\n\t\tconst parsedUrl = new URL(request.url);\n\t\t// If hosts match then we use the local tenant information. Otherwise we make a REST call out to the hosting\n\t\t// service using our bearer token.\n\t\tif (this.isForNodeTest) {\n\t\t\tconst [, documentId, tmpRelativePath] = parsedUrl.pathname.substr(1).split(\"/\");\n\t\t\tconst relativePath = tmpRelativePath ?? \"\";\n\t\t\treturn this.resolveHelper(documentId, relativePath, parsedUrl.search);\n\t\t} else if (parsedUrl.host === window.location.host) {\n\t\t\tconst fullPath = parsedUrl.pathname.substr(1);\n\t\t\tconst documentId = fullPath.split(\"/\")[0];\n\t\t\tconst documentRelativePath = fullPath.slice(documentId.length);\n\t\t\treturn this.resolveHelper(documentId, documentRelativePath);\n\t\t} else {\n\t\t\tconst maybeResolvedUrl = this.cache.get(request.url);\n\t\t\tif (maybeResolvedUrl) {\n\t\t\t\treturn maybeResolvedUrl;\n\t\t\t}\n\n\t\t\tconst resolvedP = fetch(`${this.hostUrl}/apis/load`, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\tAuthorization: `Bearer ${this.bearer}`,\n\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\turl: request.url,\n\t\t\t\t}),\n\t\t\t}).then(async (response) => {\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tthrow new Error(`HTTP error! status: ${response.status}`);\n\t\t\t\t}\n\t\t\t\treturn response.json() as Promise<IResolvedUrl>;\n\t\t\t});\n\t\t\tthis.cache.set(request.url, resolvedP);\n\n\t\t\treturn this.cache.get(request.url);\n\t\t}\n\t}\n\n\tprivate resolveHelper(\n\t\tdocumentId: string | null,\n\t\tdocumentRelativePath: string = \"\",\n\t\tqueryParams: string = \"\",\n\t): IResolvedUrl {\n\t\tconst encodedTenantId = encodeURIComponent(this.tenantId);\n\t\tconst host = new URL(this.ordererUrl).host;\n\t\t// when the document ID is not provided we need to resolve a special create new document URL.\n\t\t// the actual container ID will be generated by the driver.\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\tif (!documentId) {\n\t\t\tconst createNewResponse: IResolvedUrl = {\n\t\t\t\tendpoints: {\n\t\t\t\t\tdeltaStorageUrl: `${this.ordererUrl}/deltas/${encodedTenantId}/new`,\n\t\t\t\t\tdeltaStreamUrl: this.deltaStreamUrl,\n\t\t\t\t\tordererUrl: this.ordererUrl,\n\t\t\t\t\tstorageUrl: `${this.storageUrl}/repos/${encodedTenantId}`,\n\t\t\t\t},\n\t\t\t\t// document ID is ignored by the driver for new container requests\n\t\t\t\tid: \"\",\n\t\t\t\ttokens: {},\n\t\t\t\ttype: \"fluid\",\n\t\t\t\turl: `https://${host}/${encodedTenantId}/new`,\n\t\t\t};\n\t\t\treturn createNewResponse;\n\t\t}\n\t\tconst encodedDocId = encodeURIComponent(documentId);\n\t\tconst relativePath =\n\t\t\t!documentRelativePath || documentRelativePath.startsWith(\"/\")\n\t\t\t\t? documentRelativePath\n\t\t\t\t: `/${documentRelativePath}`;\n\t\tconst documentUrl = `https://${host}/${encodedTenantId}/${encodedDocId}${relativePath}${queryParams}`;\n\n\t\tconst deltaStorageUrl = `${this.ordererUrl}/deltas/${encodedTenantId}/${encodedDocId}`;\n\t\tconst storageUrl = `${this.storageUrl}/repos/${encodedTenantId}`;\n\n\t\tconst response: IResolvedUrl = {\n\t\t\tendpoints: {\n\t\t\t\tdeltaStorageUrl,\n\t\t\t\tdeltaStreamUrl: this.deltaStreamUrl,\n\t\t\t\tordererUrl: this.ordererUrl,\n\t\t\t\tstorageUrl,\n\t\t\t},\n\t\t\tid: documentId,\n\t\t\ttokens: {},\n\t\t\ttype: \"fluid\",\n\t\t\turl: documentUrl,\n\t\t};\n\t\treturn response;\n\t}\n\n\tpublic async getAbsoluteUrl(\n\t\tresolvedUrl: IResolvedUrl,\n\t\trelativeUrl: string,\n\t): Promise<string> {\n\t\tconst parsedUrl = new URL(resolvedUrl.url);\n\t\tconst [, , documentId] = parsedUrl.pathname?.split(\"/\") ?? [];\n\n\t\tassert(!!documentId, 0x273 /* \"Invalid document id from parsed URL\" */);\n\n\t\tlet url = relativeUrl;\n\t\tif (url.startsWith(\"/\")) {\n\t\t\turl = url.substr(1);\n\t\t}\n\n\t\treturn `${this.hostUrl}/${encodeURIComponent(this.tenantId)}/${encodeURIComponent(\n\t\t\tdocumentId,\n\t\t)}/${url}`;\n\t}\n\n\tpublic createCreateNewRequest(fileName?: string): IRequest {\n\t\tconst createNewRequest: IRequest = {\n\t\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\t\turl: fileName ? `${this.hostUrl}?fileName=${fileName}` : this.hostUrl,\n\t\t\theaders: {\n\t\t\t\t[DriverHeader.createNew]: true,\n\t\t\t},\n\t\t};\n\t\treturn createNewRequest;\n\t}\n}\n"]}
@@ -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/driver-utils";
8
- export declare const pkgVersion = "2.80.0";
8
+ export declare const pkgVersion = "2.81.0";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export const pkgName = "@fluidframework/driver-utils";
8
- export const pkgVersion = "2.80.0";
8
+ export const pkgVersion = "2.81.0";
9
9
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,8BAA8B,CAAC;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,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/driver-utils\";\nexport const pkgVersion = \"2.80.0\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,8BAA8B,CAAC;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,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/driver-utils\";\nexport const pkgVersion = \"2.81.0\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"prefetchDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/prefetchDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,+BAA+B,EAC/B,aAAa,EACb,QAAQ,EACR,MAAM,6CAA6C,CAAC;AAGrD,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAG/E;;GAEG;AACH,qBAAa,8BAA+B,SAAQ,2BAA2B;IAE9E,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA+C;IAC7E,OAAO,CAAC,eAAe,CAAQ;IAE/B,IAAW,QAAQ,IAAI,+BAA+B,GAAG,SAAS,CAKjE;IAEY,eAAe,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAclE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAGxD,YAAY,IAAI,IAAI;YAKb,UAAU;IAqBxB,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,gBAAgB;CAkBxB"}
1
+ {"version":3,"file":"prefetchDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/prefetchDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,+BAA+B,EAC/B,aAAa,EACb,QAAQ,EACR,MAAM,6CAA6C,CAAC;AAGrD,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAG/E;;GAEG;AACH,qBAAa,8BAA+B,SAAQ,2BAA2B;IAE9E,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA+C;IAC7E,OAAO,CAAC,eAAe,CAAQ;IAE/B,IAAW,QAAQ,IAAI,+BAA+B,GAAG,SAAS,CAKjE;IAEY,eAAe,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAmBlE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAGxD,YAAY,IAAI,IAAI;YAKb,UAAU;IA0BxB,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,gBAAgB;CAoBxB"}
@@ -24,12 +24,17 @@ export class PrefetchDocumentStorageService extends DocumentStorageServiceProxy
24
24
  async getSnapshotTree(version) {
25
25
  const p = this.internalStorageService.getSnapshotTree(version);
26
26
  if (this.prefetchEnabled) {
27
- // We don't care if the prefetch succeeds
28
- void p.then((tree) => {
27
+ // Fire-and-forget prefetch - we don't care if it succeeds.
28
+ // The .catch() prevents unhandled rejection when p rejects, since
29
+ // p.then() creates a derived promise that also rejects if p rejects.
30
+ // Callers awaiting the returned p will still receive the error.
31
+ p.then((tree) => {
29
32
  if (tree === null || tree === undefined) {
30
33
  return;
31
34
  }
32
35
  this.prefetchTree(tree);
36
+ }).catch(() => {
37
+ // Intentionally empty - error will be handled by caller awaiting p
33
38
  });
34
39
  }
35
40
  return p;
@@ -48,12 +53,20 @@ export class PrefetchDocumentStorageService extends DocumentStorageServiceProxy
48
53
  return prefetchedBlobP;
49
54
  }
50
55
  const prefetchedBlobPFromStorage = this.internalStorageService.readBlob(blobId);
51
- this.prefetchCache.set(blobId, prefetchedBlobPFromStorage.catch((error) => {
56
+ // Attach error handler for side effects only:
57
+ // 1. Clear cache on retryable errors so next read retries
58
+ // 2. Prevent unhandled rejection warning for fire-and-forget prefetch
59
+ // Note: Callers who await the cached promise will still see the rejection
60
+ prefetchedBlobPFromStorage.catch((error) => {
52
61
  if (canRetryOnError(error)) {
53
- this.prefetchCache.delete(blobId);
62
+ // Only clear cache if our promise is still the cached one
63
+ // (avoids race condition with concurrent requests)
64
+ if (this.prefetchCache.get(blobId) === prefetchedBlobPFromStorage) {
65
+ this.prefetchCache.delete(blobId);
66
+ }
54
67
  }
55
- throw error;
56
- }));
68
+ });
69
+ this.prefetchCache.set(blobId, prefetchedBlobPFromStorage);
57
70
  return prefetchedBlobPFromStorage;
58
71
  }
59
72
  return this.internalStorageService.readBlob(blobId);
@@ -62,16 +75,23 @@ export class PrefetchDocumentStorageService extends DocumentStorageServiceProxy
62
75
  const secondary = [];
63
76
  this.prefetchTreeCore(tree, secondary);
64
77
  for (const blob of secondary) {
65
- // We don't care if the prefetch succeeds
66
- void this.cachedRead(blob);
78
+ // Skip if already cached (avoids unnecessary async overhead)
79
+ if (this.prefetchCache.has(blob)) {
80
+ continue;
81
+ }
82
+ // Fire-and-forget prefetch. The .catch() prevents unhandled rejection
83
+ // since cachedRead is async and returns a separate promise chain.
84
+ this.cachedRead(blob).catch(() => { });
67
85
  }
68
86
  }
69
87
  prefetchTreeCore(tree, secondary) {
70
88
  for (const [blobKey, blob] of Object.entries(tree.blobs)) {
71
89
  if (blobKey.startsWith(".") || blobKey === "header" || blobKey.startsWith("quorum")) {
72
- if (blob !== null) {
73
- // We don't care if the prefetch succeeds
74
- void this.cachedRead(blob);
90
+ // Skip if already cached (avoids unnecessary async overhead)
91
+ if (blob !== null && !this.prefetchCache.has(blob)) {
92
+ // Fire-and-forget prefetch. The .catch() prevents unhandled rejection
93
+ // since cachedRead is async and returns a separate promise chain.
94
+ this.cachedRead(blob).catch(() => { });
75
95
  }
76
96
  }
77
97
  else if (!blobKey.startsWith("deltas")) {
@@ -1 +1 @@
1
- {"version":3,"file":"prefetchDocumentStorageService.js","sourceRoot":"","sources":["../src/prefetchDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAC;AAElF,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,8BAA+B,SAAQ,2BAA2B;IAA/E;;QACC,qCAAqC;QACpB,kBAAa,GAAG,IAAI,GAAG,EAAoC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AC;oBACnB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACtB,CAAC;YACF,CAAC;QACF,CAAC;QAED,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACjD,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC3C,CAAC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tIDocumentStorageServicePolicies,\n\tISnapshotTree,\n\tIVersion,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { LoaderCachingPolicy } from \"@fluidframework/driver-definitions/internal\";\n\nimport { DocumentStorageServiceProxy } from \"./documentStorageServiceProxy.js\";\nimport { canRetryOnError } from \"./network.js\";\n\n/**\n * @internal\n */\nexport class PrefetchDocumentStorageService extends DocumentStorageServiceProxy {\n\t// BlobId -> blob prefetchCache cache\n\tprivate readonly prefetchCache = new Map<string, Promise<ArrayBufferLike>>();\n\tprivate prefetchEnabled = true;\n\n\tpublic get policies(): IDocumentStorageServicePolicies | undefined {\n\t\tconst policies = this.internalStorageService.policies;\n\t\tif (policies) {\n\t\t\treturn { ...policies, caching: LoaderCachingPolicy.NoCaching };\n\t\t}\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n\t\tconst p = this.internalStorageService.getSnapshotTree(version);\n\t\tif (this.prefetchEnabled) {\n\t\t\t// We don't care if the prefetch succeeds\n\t\t\tvoid p.then((tree: ISnapshotTree | null | undefined) => {\n\t\t\t\tif (tree === null || tree === undefined) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.prefetchTree(tree);\n\t\t\t});\n\t\t}\n\t\treturn p;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\treturn this.cachedRead(blobId);\n\t}\n\tpublic stopPrefetch(): void {\n\t\tthis.prefetchEnabled = false;\n\t\tthis.prefetchCache.clear();\n\t}\n\n\tprivate async cachedRead(blobId: string): Promise<ArrayBufferLike> {\n\t\tif (this.prefetchEnabled) {\n\t\t\tconst prefetchedBlobP = this.prefetchCache.get(blobId);\n\t\t\tif (prefetchedBlobP !== undefined) {\n\t\t\t\treturn prefetchedBlobP;\n\t\t\t}\n\t\t\tconst prefetchedBlobPFromStorage = this.internalStorageService.readBlob(blobId);\n\t\t\tthis.prefetchCache.set(\n\t\t\t\tblobId,\n\t\t\t\tprefetchedBlobPFromStorage.catch((error) => {\n\t\t\t\t\tif (canRetryOnError(error)) {\n\t\t\t\t\t\tthis.prefetchCache.delete(blobId);\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}),\n\t\t\t);\n\t\t\treturn prefetchedBlobPFromStorage;\n\t\t}\n\t\treturn this.internalStorageService.readBlob(blobId);\n\t}\n\n\tprivate prefetchTree(tree: ISnapshotTree): void {\n\t\tconst secondary: string[] = [];\n\t\tthis.prefetchTreeCore(tree, secondary);\n\n\t\tfor (const blob of secondary) {\n\t\t\t// We don't care if the prefetch succeeds\n\t\t\tvoid this.cachedRead(blob);\n\t\t}\n\t}\n\n\tprivate prefetchTreeCore(tree: ISnapshotTree, secondary: string[]): void {\n\t\tfor (const [blobKey, blob] of Object.entries(tree.blobs)) {\n\t\t\tif (blobKey.startsWith(\".\") || blobKey === \"header\" || blobKey.startsWith(\"quorum\")) {\n\t\t\t\tif (blob !== null) {\n\t\t\t\t\t// We don't care if the prefetch succeeds\n\t\t\t\t\tvoid this.cachedRead(blob);\n\t\t\t\t}\n\t\t\t} else if (!blobKey.startsWith(\"deltas\")) {\n\t\t\t\tif (blob !== null) {\n\t\t\t\t\tsecondary.push(blob);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const subTree of Object.values(tree.trees)) {\n\t\t\tthis.prefetchTreeCore(subTree, secondary);\n\t\t}\n\t}\n}\n"]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CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tIDocumentStorageServicePolicies,\n\tISnapshotTree,\n\tIVersion,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { LoaderCachingPolicy } from \"@fluidframework/driver-definitions/internal\";\n\nimport { DocumentStorageServiceProxy } from \"./documentStorageServiceProxy.js\";\nimport { canRetryOnError } from \"./network.js\";\n\n/**\n * @internal\n */\nexport class PrefetchDocumentStorageService extends DocumentStorageServiceProxy {\n\t// BlobId -> blob prefetchCache cache\n\tprivate readonly prefetchCache = new Map<string, Promise<ArrayBufferLike>>();\n\tprivate prefetchEnabled = true;\n\n\tpublic get policies(): IDocumentStorageServicePolicies | undefined {\n\t\tconst policies = this.internalStorageService.policies;\n\t\tif (policies) {\n\t\t\treturn { ...policies, caching: LoaderCachingPolicy.NoCaching };\n\t\t}\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n\t\tconst p = this.internalStorageService.getSnapshotTree(version);\n\t\tif (this.prefetchEnabled) {\n\t\t\t// Fire-and-forget prefetch - we don't care if it succeeds.\n\t\t\t// The .catch() prevents unhandled rejection when p rejects, since\n\t\t\t// p.then() creates a derived promise that also rejects if p rejects.\n\t\t\t// Callers awaiting the returned p will still receive the error.\n\t\t\tp.then((tree: ISnapshotTree | null | undefined) => {\n\t\t\t\tif (tree === null || tree === undefined) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.prefetchTree(tree);\n\t\t\t}).catch(() => {\n\t\t\t\t// Intentionally empty - error will be handled by caller awaiting p\n\t\t\t});\n\t\t}\n\t\treturn p;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\treturn this.cachedRead(blobId);\n\t}\n\tpublic stopPrefetch(): void {\n\t\tthis.prefetchEnabled = false;\n\t\tthis.prefetchCache.clear();\n\t}\n\n\tprivate async cachedRead(blobId: string): Promise<ArrayBufferLike> {\n\t\tif (this.prefetchEnabled) {\n\t\t\tconst prefetchedBlobP = this.prefetchCache.get(blobId);\n\t\t\tif (prefetchedBlobP !== undefined) {\n\t\t\t\treturn prefetchedBlobP;\n\t\t\t}\n\t\t\tconst prefetchedBlobPFromStorage = this.internalStorageService.readBlob(blobId);\n\t\t\t// Attach error handler for side effects only:\n\t\t\t// 1. Clear cache on retryable errors so next read retries\n\t\t\t// 2. Prevent unhandled rejection warning for fire-and-forget prefetch\n\t\t\t// Note: Callers who await the cached promise will still see the rejection\n\t\t\tprefetchedBlobPFromStorage.catch((error) => {\n\t\t\t\tif (canRetryOnError(error)) {\n\t\t\t\t\t// Only clear cache if our promise is still the cached one\n\t\t\t\t\t// (avoids race condition with concurrent requests)\n\t\t\t\t\tif (this.prefetchCache.get(blobId) === prefetchedBlobPFromStorage) {\n\t\t\t\t\t\tthis.prefetchCache.delete(blobId);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis.prefetchCache.set(blobId, prefetchedBlobPFromStorage);\n\t\t\treturn prefetchedBlobPFromStorage;\n\t\t}\n\t\treturn this.internalStorageService.readBlob(blobId);\n\t}\n\n\tprivate prefetchTree(tree: ISnapshotTree): void {\n\t\tconst secondary: string[] = [];\n\t\tthis.prefetchTreeCore(tree, secondary);\n\n\t\tfor (const blob of secondary) {\n\t\t\t// Skip if already cached (avoids unnecessary async overhead)\n\t\t\tif (this.prefetchCache.has(blob)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Fire-and-forget prefetch. The .catch() prevents unhandled rejection\n\t\t\t// since cachedRead is async and returns a separate promise chain.\n\t\t\tthis.cachedRead(blob).catch(() => {});\n\t\t}\n\t}\n\n\tprivate prefetchTreeCore(tree: ISnapshotTree, secondary: string[]): void {\n\t\tfor (const [blobKey, blob] of Object.entries(tree.blobs)) {\n\t\t\tif (blobKey.startsWith(\".\") || blobKey === \"header\" || blobKey.startsWith(\"quorum\")) {\n\t\t\t\t// Skip if already cached (avoids unnecessary async overhead)\n\t\t\t\tif (blob !== null && !this.prefetchCache.has(blob)) {\n\t\t\t\t\t// Fire-and-forget prefetch. The .catch() prevents unhandled rejection\n\t\t\t\t\t// since cachedRead is async and returns a separate promise chain.\n\t\t\t\t\tthis.cachedRead(blob).catch(() => {});\n\t\t\t\t}\n\t\t\t} else if (!blobKey.startsWith(\"deltas\")) {\n\t\t\t\tif (blob !== null) {\n\t\t\t\t\tsecondary.push(blob);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const subTree of Object.values(tree.trees)) {\n\t\t\tthis.prefetchTreeCore(subTree, secondary);\n\t\t}\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/driver-utils",
3
- "version": "2.80.0",
3
+ "version": "2.81.0",
4
4
  "description": "Collection of utility functions for Fluid drivers",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -69,24 +69,23 @@
69
69
  "temp-directory": "nyc/.nyc_output"
70
70
  },
71
71
  "dependencies": {
72
- "@fluid-internal/client-utils": "~2.80.0",
73
- "@fluidframework/core-interfaces": "~2.80.0",
74
- "@fluidframework/core-utils": "~2.80.0",
75
- "@fluidframework/driver-definitions": "~2.80.0",
76
- "@fluidframework/telemetry-utils": "~2.80.0",
77
- "axios": "^1.8.4",
72
+ "@fluid-internal/client-utils": "~2.81.0",
73
+ "@fluidframework/core-interfaces": "~2.81.0",
74
+ "@fluidframework/core-utils": "~2.81.0",
75
+ "@fluidframework/driver-definitions": "~2.81.0",
76
+ "@fluidframework/telemetry-utils": "~2.81.0",
78
77
  "lz4js": "^0.2.0",
79
78
  "uuid": "^11.1.0"
80
79
  },
81
80
  "devDependencies": {
82
81
  "@arethetypeswrong/cli": "^0.18.2",
83
82
  "@biomejs/biome": "~1.9.3",
84
- "@fluid-internal/mocha-test-setup": "~2.80.0",
85
- "@fluid-tools/build-cli": "^0.62.0",
83
+ "@fluid-internal/mocha-test-setup": "~2.81.0",
84
+ "@fluid-tools/build-cli": "^0.63.0",
86
85
  "@fluidframework/build-common": "^2.0.3",
87
- "@fluidframework/build-tools": "^0.62.0",
88
- "@fluidframework/driver-utils-previous": "npm:@fluidframework/driver-utils@2.74.0",
89
- "@fluidframework/eslint-config-fluid": "~2.80.0",
86
+ "@fluidframework/build-tools": "^0.63.0",
87
+ "@fluidframework/driver-utils-previous": "npm:@fluidframework/driver-utils@2.80.0",
88
+ "@fluidframework/eslint-config-fluid": "~2.81.0",
90
89
  "@microsoft/api-extractor": "7.52.11",
91
90
  "@types/mocha": "^10.0.10",
92
91
  "@types/node": "^18.19.0",
@@ -10,7 +10,6 @@ import {
10
10
  IResolvedUrl,
11
11
  IUrlResolver,
12
12
  } from "@fluidframework/driver-definitions/internal";
13
- import Axios from "axios";
14
13
 
15
14
  /**
16
15
  * As the name implies this is not secure and should not be used in production. It simply makes the example easier
@@ -66,22 +65,22 @@ export class InsecureUrlResolver implements IUrlResolver {
66
65
  return maybeResolvedUrl;
67
66
  }
68
67
 
69
- const headers = {
70
- Authorization: `Bearer ${this.bearer}`,
71
- };
72
- const resolvedP = Axios.post<IResolvedUrl>(
73
- `${this.hostUrl}/apis/load`,
74
- {
75
- url: request.url,
68
+ const resolvedP = fetch(`${this.hostUrl}/apis/load`, {
69
+ method: "POST",
70
+ headers: {
71
+ Authorization: `Bearer ${this.bearer}`,
72
+ "Content-Type": "application/json",
76
73
  },
77
- {
78
- headers,
79
- },
80
- );
81
- this.cache.set(
82
- request.url,
83
- resolvedP.then((resolved) => resolved.data),
84
- );
74
+ body: JSON.stringify({
75
+ url: request.url,
76
+ }),
77
+ }).then(async (response) => {
78
+ if (!response.ok) {
79
+ throw new Error(`HTTP error! status: ${response.status}`);
80
+ }
81
+ return response.json() as Promise<IResolvedUrl>;
82
+ });
83
+ this.cache.set(request.url, resolvedP);
85
84
 
86
85
  return this.cache.get(request.url);
87
86
  }
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/driver-utils";
9
- export const pkgVersion = "2.80.0";
9
+ export const pkgVersion = "2.81.0";
@@ -31,12 +31,17 @@ export class PrefetchDocumentStorageService extends DocumentStorageServiceProxy
31
31
  public async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {
32
32
  const p = this.internalStorageService.getSnapshotTree(version);
33
33
  if (this.prefetchEnabled) {
34
- // We don't care if the prefetch succeeds
35
- void p.then((tree: ISnapshotTree | null | undefined) => {
34
+ // Fire-and-forget prefetch - we don't care if it succeeds.
35
+ // The .catch() prevents unhandled rejection when p rejects, since
36
+ // p.then() creates a derived promise that also rejects if p rejects.
37
+ // Callers awaiting the returned p will still receive the error.
38
+ p.then((tree: ISnapshotTree | null | undefined) => {
36
39
  if (tree === null || tree === undefined) {
37
40
  return;
38
41
  }
39
42
  this.prefetchTree(tree);
43
+ }).catch(() => {
44
+ // Intentionally empty - error will be handled by caller awaiting p
40
45
  });
41
46
  }
42
47
  return p;
@@ -57,15 +62,20 @@ export class PrefetchDocumentStorageService extends DocumentStorageServiceProxy
57
62
  return prefetchedBlobP;
58
63
  }
59
64
  const prefetchedBlobPFromStorage = this.internalStorageService.readBlob(blobId);
60
- this.prefetchCache.set(
61
- blobId,
62
- prefetchedBlobPFromStorage.catch((error) => {
63
- if (canRetryOnError(error)) {
65
+ // Attach error handler for side effects only:
66
+ // 1. Clear cache on retryable errors so next read retries
67
+ // 2. Prevent unhandled rejection warning for fire-and-forget prefetch
68
+ // Note: Callers who await the cached promise will still see the rejection
69
+ prefetchedBlobPFromStorage.catch((error) => {
70
+ if (canRetryOnError(error)) {
71
+ // Only clear cache if our promise is still the cached one
72
+ // (avoids race condition with concurrent requests)
73
+ if (this.prefetchCache.get(blobId) === prefetchedBlobPFromStorage) {
64
74
  this.prefetchCache.delete(blobId);
65
75
  }
66
- throw error;
67
- }),
68
- );
76
+ }
77
+ });
78
+ this.prefetchCache.set(blobId, prefetchedBlobPFromStorage);
69
79
  return prefetchedBlobPFromStorage;
70
80
  }
71
81
  return this.internalStorageService.readBlob(blobId);
@@ -76,17 +86,24 @@ export class PrefetchDocumentStorageService extends DocumentStorageServiceProxy
76
86
  this.prefetchTreeCore(tree, secondary);
77
87
 
78
88
  for (const blob of secondary) {
79
- // We don't care if the prefetch succeeds
80
- void this.cachedRead(blob);
89
+ // Skip if already cached (avoids unnecessary async overhead)
90
+ if (this.prefetchCache.has(blob)) {
91
+ continue;
92
+ }
93
+ // Fire-and-forget prefetch. The .catch() prevents unhandled rejection
94
+ // since cachedRead is async and returns a separate promise chain.
95
+ this.cachedRead(blob).catch(() => {});
81
96
  }
82
97
  }
83
98
 
84
99
  private prefetchTreeCore(tree: ISnapshotTree, secondary: string[]): void {
85
100
  for (const [blobKey, blob] of Object.entries(tree.blobs)) {
86
101
  if (blobKey.startsWith(".") || blobKey === "header" || blobKey.startsWith("quorum")) {
87
- if (blob !== null) {
88
- // We don't care if the prefetch succeeds
89
- void this.cachedRead(blob);
102
+ // Skip if already cached (avoids unnecessary async overhead)
103
+ if (blob !== null && !this.prefetchCache.has(blob)) {
104
+ // Fire-and-forget prefetch. The .catch() prevents unhandled rejection
105
+ // since cachedRead is async and returns a separate promise chain.
106
+ this.cachedRead(blob).catch(() => {});
90
107
  }
91
108
  } else if (!blobKey.startsWith("deltas")) {
92
109
  if (blob !== null) {
package/.eslintrc.cjs DELETED
@@ -1,30 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- module.exports = {
7
- extends: [
8
- require.resolve("@fluidframework/eslint-config-fluid/minimal-deprecated"),
9
- "prettier",
10
- ],
11
- parserOptions: {
12
- project: ["./tsconfig.json", "./src/test/tsconfig.json"],
13
- },
14
- rules: {
15
- "import-x/no-nodejs-modules": ["error"],
16
- "@fluid-internal/fluid/no-unchecked-record-access": "warn",
17
-
18
- // Disabled because the rule is crashing on this package - AB#51780
19
- "@typescript-eslint/unbound-method": "off",
20
- },
21
- overrides: [
22
- {
23
- // Rules only for test files
24
- files: ["*.spec.ts", "src/test/**"],
25
- rules: {
26
- "import-x/no-nodejs-modules": "off", // Node libraries are OK for test files.
27
- },
28
- },
29
- ],
30
- };