@fluidframework/odsp-driver 0.58.2002 → 0.59.1000
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/dist/compactSnapshotParser.d.ts +1 -0
- package/dist/compactSnapshotParser.d.ts.map +1 -1
- package/dist/compactSnapshotParser.js +8 -7
- package/dist/compactSnapshotParser.js.map +1 -1
- package/dist/createNewUtils.js +0 -1
- package/dist/createNewUtils.js.map +1 -1
- package/dist/epochTracker.d.ts +12 -0
- package/dist/epochTracker.d.ts.map +1 -1
- package/dist/epochTracker.js +18 -22
- package/dist/epochTracker.js.map +1 -1
- package/dist/fetchSnapshot.d.ts +11 -0
- package/dist/fetchSnapshot.d.ts.map +1 -1
- package/dist/fetchSnapshot.js +53 -68
- package/dist/fetchSnapshot.js.map +1 -1
- package/dist/odspDocumentService.d.ts +2 -1
- package/dist/odspDocumentService.d.ts.map +1 -1
- package/dist/odspDocumentService.js +14 -7
- package/dist/odspDocumentService.js.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.d.ts +2 -2
- package/dist/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.js +6 -6
- package/dist/odspDocumentServiceFactoryCore.js.map +1 -1
- package/dist/odspDocumentStorageManager.d.ts +0 -6
- package/dist/odspDocumentStorageManager.d.ts.map +1 -1
- package/dist/odspDocumentStorageManager.js +9 -58
- package/dist/odspDocumentStorageManager.js.map +1 -1
- package/dist/odspDriverUrlResolver.d.ts +2 -6
- package/dist/odspDriverUrlResolver.d.ts.map +1 -1
- package/dist/odspDriverUrlResolver.js +15 -10
- package/dist/odspDriverUrlResolver.js.map +1 -1
- package/dist/odspDriverUrlResolverForShareLink.d.ts +2 -6
- package/dist/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
- package/dist/odspDriverUrlResolverForShareLink.js +12 -9
- package/dist/odspDriverUrlResolverForShareLink.js.map +1 -1
- package/dist/odspSnapshotParser.d.ts.map +1 -1
- package/dist/odspSnapshotParser.js +1 -5
- package/dist/odspSnapshotParser.js.map +1 -1
- package/dist/odspSummaryUploadManager.d.ts.map +1 -1
- package/dist/odspSummaryUploadManager.js +9 -6
- package/dist/odspSummaryUploadManager.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/compactSnapshotParser.d.ts +1 -0
- package/lib/compactSnapshotParser.d.ts.map +1 -1
- package/lib/compactSnapshotParser.js +7 -6
- package/lib/compactSnapshotParser.js.map +1 -1
- package/lib/createNewUtils.js +0 -1
- package/lib/createNewUtils.js.map +1 -1
- package/lib/epochTracker.d.ts +12 -0
- package/lib/epochTracker.d.ts.map +1 -1
- package/lib/epochTracker.js +19 -23
- package/lib/epochTracker.js.map +1 -1
- package/lib/fetchSnapshot.d.ts +11 -0
- package/lib/fetchSnapshot.d.ts.map +1 -1
- package/lib/fetchSnapshot.js +55 -70
- package/lib/fetchSnapshot.js.map +1 -1
- package/lib/odspDocumentService.d.ts +2 -1
- package/lib/odspDocumentService.d.ts.map +1 -1
- package/lib/odspDocumentService.js +14 -7
- package/lib/odspDocumentService.js.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.d.ts +2 -2
- package/lib/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.js +6 -6
- package/lib/odspDocumentServiceFactoryCore.js.map +1 -1
- package/lib/odspDocumentStorageManager.d.ts +0 -6
- package/lib/odspDocumentStorageManager.d.ts.map +1 -1
- package/lib/odspDocumentStorageManager.js +9 -58
- package/lib/odspDocumentStorageManager.js.map +1 -1
- package/lib/odspDriverUrlResolver.d.ts +2 -6
- package/lib/odspDriverUrlResolver.d.ts.map +1 -1
- package/lib/odspDriverUrlResolver.js +14 -9
- package/lib/odspDriverUrlResolver.js.map +1 -1
- package/lib/odspDriverUrlResolverForShareLink.d.ts +2 -6
- package/lib/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
- package/lib/odspDriverUrlResolverForShareLink.js +10 -7
- package/lib/odspDriverUrlResolverForShareLink.js.map +1 -1
- package/lib/odspSnapshotParser.d.ts.map +1 -1
- package/lib/odspSnapshotParser.js +1 -5
- package/lib/odspSnapshotParser.js.map +1 -1
- package/lib/odspSummaryUploadManager.d.ts.map +1 -1
- package/lib/odspSummaryUploadManager.js +9 -6
- package/lib/odspSummaryUploadManager.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/package.json +19 -14
- package/src/compactSnapshotParser.ts +14 -12
- package/src/createNewUtils.ts +0 -1
- package/src/epochTracker.ts +34 -25
- package/src/fetchSnapshot.ts +57 -89
- package/src/odspDocumentService.ts +8 -5
- package/src/odspDocumentServiceFactoryCore.ts +7 -2
- package/src/odspDocumentStorageManager.ts +10 -64
- package/src/odspDriverUrlResolver.ts +18 -9
- package/src/odspDriverUrlResolverForShareLink.ts +11 -8
- package/src/odspSnapshotParser.ts +1 -4
- package/src/odspSummaryUploadManager.ts +7 -6
- package/src/packageVersion.ts +1 -1
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OdspDriverUrlResolverForShareLink = void 0;
|
|
2
4
|
/*!
|
|
3
5
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
6
|
* Licensed under the MIT License.
|
|
5
7
|
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.OdspDriverUrlResolverForShareLink = void 0;
|
|
8
8
|
const common_utils_1 = require("@fluidframework/common-utils");
|
|
9
|
-
const core_interfaces_1 = require("@fluidframework/core-interfaces");
|
|
10
9
|
const odspFluidFileLink_1 = require("./odspFluidFileLink");
|
|
11
10
|
const contractsPublic_1 = require("./contractsPublic");
|
|
12
11
|
const createOdspUrl_1 = require("./createOdspUrl");
|
|
@@ -131,22 +130,26 @@ class OdspDriverUrlResolverForShareLink {
|
|
|
131
130
|
* @param request - The relative data store path URL. For requesting a driver URL, this value should always be '/'
|
|
132
131
|
*/
|
|
133
132
|
async getAbsoluteUrl(resolvedUrl, dataStorePath, packageInfoSource) {
|
|
134
|
-
var _a;
|
|
133
|
+
var _a, _b, _c, _d;
|
|
135
134
|
const odspResolvedUrl = odspUtils_1.getOdspResolvedUrl(resolvedUrl);
|
|
136
135
|
const shareLink = await this.getShareLinkPromise(odspResolvedUrl);
|
|
137
136
|
const shareLinkUrl = new URL(shareLink);
|
|
138
|
-
// back-compat:
|
|
137
|
+
// back-compat: GitHub #9653
|
|
138
|
+
const isFluidPackage = (pkg) => typeof pkg === "object"
|
|
139
|
+
&& typeof (pkg === null || pkg === void 0 ? void 0 : pkg.name) === "string"
|
|
140
|
+
&& typeof (pkg === null || pkg === void 0 ? void 0 : pkg.fluid) === "object";
|
|
139
141
|
let containerPackageName;
|
|
140
142
|
if (packageInfoSource && "name" in packageInfoSource) {
|
|
141
143
|
containerPackageName = packageInfoSource.name;
|
|
144
|
+
// packageInfoSource is cast to any as it is typed to IContainerPackageInfo instead of IFluidCodeDetails
|
|
142
145
|
}
|
|
143
|
-
else if (
|
|
144
|
-
containerPackageName = packageInfoSource === null ||
|
|
146
|
+
else if (isFluidPackage((_a = packageInfoSource) === null || _a === void 0 ? void 0 : _a.package)) {
|
|
147
|
+
containerPackageName = (_b = packageInfoSource) === null || _b === void 0 ? void 0 : _b.package.name;
|
|
145
148
|
}
|
|
146
149
|
else {
|
|
147
|
-
containerPackageName = packageInfoSource === null ||
|
|
150
|
+
containerPackageName = (_c = packageInfoSource) === null || _c === void 0 ? void 0 : _c.package;
|
|
148
151
|
}
|
|
149
|
-
containerPackageName = containerPackageName !== null && containerPackageName !== void 0 ? containerPackageName : (
|
|
152
|
+
containerPackageName = containerPackageName !== null && containerPackageName !== void 0 ? containerPackageName : (_d = odspResolvedUrl.codeHint) === null || _d === void 0 ? void 0 : _d.containerPackageName;
|
|
150
153
|
odspFluidFileLink_1.storeLocatorInOdspUrl(shareLinkUrl, {
|
|
151
154
|
siteUrl: odspResolvedUrl.siteUrl,
|
|
152
155
|
driveId: odspResolvedUrl.driveId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspDriverUrlResolverForShareLink.js","sourceRoot":"","sources":["../src/odspDriverUrlResolverForShareLink.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA4D;AAC5D,qEAA8F;AAa9F,2DAK6B;AAC7B,uDAAiF;AACjF,mDAAgD;AAChD,mEAAgE;AAChE,2CAAmE;AACnE,+CAA4C;AAgB5C;;;;GAIG;AACH,MAAa,iCAAiC;IAK1C;;;;;;;;;OASG;IACH,YACI,qBAAyD,EACzD,MAA6B,EACZ,OAAgB;QAAhB,YAAO,GAAP,OAAO,CAAS;QAhBpB,qBAAgB,GAAG,IAAI,2BAAY,EAAkB,CAAC;QAkBnE,IAAI,CAAC,MAAM,GAAG,4BAAgB,CAAC,MAAM,CAAC,CAAC;QACvC,IAAI,qBAAqB,EAAE;YACvB,IAAI,CAAC,qBAAqB,mCACnB,qBAAqB,KACxB,YAAY,EAAE,qBAAqB,CAAC,YAAY,GACnD,CAAC;SACL;IACL,CAAC;IAED;;;OAGG;IACI,mBAAmB,CAAC,UAAe,EAAE,YAAoB;QAC5D,MAAM,SAAS,GAAG,yCAAqB,CAAC,UAAU,CAAC,CAAC;QAEpD,IAAI,CAAC,SAAS,EAAE;YACZ,OAAO,SAAS,CAAC;SACpB;QAED,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,aAAa,EAAE,GAAG,UAAU,CAAC,QAAQ,KAAK,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;QACtG,mGAAmG;QACnG,IAAI,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YAC/D,MAAM,WAAW,G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jD;aAAM,IAAI,gCAAc,CAAC,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,OAAO,CAAC,EAAE;YACnD,oBAAoB,GAAG,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,OAAO,CAAC,IAAI,CAAC;SAC1D;aAAM;YACH,oBAAoB,GAAG,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,OAAO,CAAC;SACrD;QACD,oBAAoB,GAAG,oBAAoB,aAApB,oBAAoB,cAApB,oBAAoB,SAAI,eAAe,CAAC,QAAQ,0CAAE,oBAAoB,CAAC;QAE9F,yCAAqB,CAAC,YAAY,EAAE;YAChC,OAAO,EAAE,eAAe,CAAC,OAAO;YAChC,OAAO,EAAE,eAAe,CAAC,OAAO;YAChC,MAAM,EAAE,eAAe,CAAC,MAAM;YAC9B,aAAa;YACb,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,oBAAoB;YACpB,WAAW,EAAE,eAAe,CAAC,WAAW;SAC3C,CAAC,CAAC;QAEH,OAAO,YAAY,CAAC,IAAI,CAAC;IAC7B,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,iBAAiB,CAAC,OAAe,EAAE,UAAqC;QAClF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;QAE7B,yCAAqB,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAEvC,OAAO,GAAG,CAAC,IAAI,CAAC;IACpB,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,cAAc,CAAC,OAAkC;QAC3D,OAAO,mDAA+B,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;CACJ;AA9LD,8EA8LC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { PromiseCache } from \"@fluidframework/common-utils\";\nimport { IFluidCodeDetails, IRequest, isFluidPackage } from \"@fluidframework/core-interfaces\";\nimport {\n IContainerPackageInfo,\n IResolvedUrl,\n IUrlResolver,\n} from \"@fluidframework/driver-definitions\";\nimport { ITelemetryBaseLogger, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport {\n IOdspResolvedUrl,\n IdentityType,\n OdspResourceTokenFetchOptions,\n TokenFetcher,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport {\n getLocatorFromOdspUrl,\n storeLocatorInOdspUrl,\n encodeOdspFluidDataStoreLocator,\n locatorQueryParamName,\n} from \"./odspFluidFileLink\";\nimport { OdspFluidDataStoreLocator, SharingLinkHeader } from \"./contractsPublic\";\nimport { createOdspUrl } from \"./createOdspUrl\";\nimport { OdspDriverUrlResolver } from \"./odspDriverUrlResolver\";\nimport { getOdspResolvedUrl, createOdspLogger } from \"./odspUtils\";\nimport { getFileLink } from \"./getFileLink\";\n\n/**\n * Properties passed to the code responsible for fetching share link for a file.\n */\nexport interface ShareLinkFetcherProps {\n /**\n * Callback method that is used to fetch access token necessary to call API that produces share link\n */\n tokenFetcher: TokenFetcher<OdspResourceTokenFetchOptions>;\n /**\n * Identity type determining the shape of share link as it differs for Enterprise and Consumer users.\n */\n identityType: IdentityType;\n}\n\n/**\n * Resolver to resolve urls like the ones created by createOdspUrl which is driver inner\n * url format and the ones which have things like driveId, siteId, itemId etc encoded in nav param.\n * This resolver also handles share links and try to generate one for the use by the app.\n */\nexport class OdspDriverUrlResolverForShareLink implements IUrlResolver {\n private readonly logger: ITelemetryLogger;\n private readonly sharingLinkCache = new PromiseCache<string, string>();\n private readonly shareLinkFetcherProps: ShareLinkFetcherProps | undefined;\n\n /**\n * Creates url resolver instance\n * @param shareLinkFetcherProps - properties used when fetching share link.\n * Can be set as 'undefined' for cases where share link is not needed. Currently, only\n * getAbsoluteUrl() method requires share link.\n * @param logger - logger object that is used as telemetry sink\n * @param appName - application name hint that is encoded with url produced by getAbsoluteUrl() method.\n * This hint is used by link handling logic which determines which app to redirect to when user\n * navigates directly to the link.\n */\n public constructor(\n shareLinkFetcherProps?: ShareLinkFetcherProps | undefined,\n logger?: ITelemetryBaseLogger,\n private readonly appName?: string,\n ) {\n this.logger = createOdspLogger(logger);\n if (shareLinkFetcherProps) {\n this.shareLinkFetcherProps = {\n ...shareLinkFetcherProps,\n tokenFetcher: shareLinkFetcherProps.tokenFetcher,\n };\n }\n }\n\n /**\n * Takes an already generated data store url (from requestUrl) and appends a path to the\n * existing data store information.\n */\n public appendDataStorePath(requestUrl: URL, pathToAppend: string): string | undefined {\n const fluidInfo = getLocatorFromOdspUrl(requestUrl);\n\n if (!fluidInfo) {\n return undefined;\n }\n\n const parsingUrl = new URL(fluidInfo.dataStorePath, `${requestUrl.protocol}//${requestUrl.hostname}`);\n // Determine if the caller is passing a query parameter or path since processing will be different.\n if (pathToAppend.startsWith(\"/?\") || pathToAppend.startsWith(\"?\")) {\n const queryParams = new URLSearchParams(pathToAppend);\n queryParams.forEach((value: string, key: string) => {\n parsingUrl.searchParams.append(key, value);\n });\n fluidInfo.dataStorePath = `${parsingUrl.pathname}${parsingUrl.search}`;\n } else {\n fluidInfo.dataStorePath = `${parsingUrl.pathname}${\n parsingUrl.pathname.endsWith(\"/\") || pathToAppend.startsWith(\"/\") ? \"\" : \"/\"\n }${pathToAppend}/${parsingUrl.search}`;\n }\n storeLocatorInOdspUrl(requestUrl, fluidInfo);\n\n return requestUrl.href;\n }\n\n private getKey(resolvedUrl: IOdspResolvedUrl): string {\n return `${resolvedUrl.siteUrl},${resolvedUrl.driveId},${resolvedUrl.itemId}`;\n }\n\n /**\n * Resolves request URL into driver details\n */\n public async resolve(request: IRequest): Promise<IOdspResolvedUrl> {\n const requestToBeResolved = { headers: request.headers, url: request.url };\n const isSharingLinkToRedeem = requestToBeResolved.headers?.[SharingLinkHeader.isSharingLinkToRedeem];\n try {\n const url = new URL(request.url);\n\n const odspFluidInfo = getLocatorFromOdspUrl(url);\n if (odspFluidInfo) {\n requestToBeResolved.url = createOdspUrl(odspFluidInfo);\n }\n } catch {\n // If the locator throws some error, then try to resolve the request as it is.\n }\n\n const odspResolvedUrl = await new OdspDriverUrlResolver().resolve(requestToBeResolved);\n\n if (isSharingLinkToRedeem) {\n // We need to remove the nav param if set by host when setting the sharelink as otherwise the shareLinkId\n // when redeeming the share link during the redeem fallback for trees latest call becomes greater than\n // the eligible length.\n odspResolvedUrl.shareLinkInfo = Object.assign(odspResolvedUrl.shareLinkInfo || {},\n {sharingLinkToRedeem: this.removeNavParam(request.url)});\n }\n if (odspResolvedUrl.itemId) {\n // Kick start the sharing link request if we don't have it already as a performance optimization.\n // For detached create new, we don't have an item id yet and therefore cannot generate a share link\n this.getShareLinkPromise(odspResolvedUrl).catch(() => {});\n }\n return odspResolvedUrl;\n }\n\n private removeNavParam(link: string): string {\n const url = new URL(link);\n const params = new URLSearchParams(url.search);\n params.delete(locatorQueryParamName);\n url.search = params.toString();\n return url.href;\n }\n\n private async getShareLinkPromise(resolvedUrl: IOdspResolvedUrl): Promise<string> {\n if (this.shareLinkFetcherProps === undefined) {\n throw new Error(\"Failed to get share link because share link fetcher props are missing\");\n }\n\n if (!(resolvedUrl.siteUrl && resolvedUrl.driveId && resolvedUrl.itemId)) {\n throw new Error(\"Failed to get share link because necessary information is missing \" +\n \"(e.g. siteUrl, driveId or itemId)\");\n }\n\n const key = this.getKey(resolvedUrl);\n const cachedLinkPromise = this.sharingLinkCache.get(key);\n if (cachedLinkPromise) {\n return cachedLinkPromise;\n }\n const newLinkPromise = getFileLink(\n this.shareLinkFetcherProps.tokenFetcher,\n resolvedUrl,\n this.shareLinkFetcherProps.identityType,\n this.logger,\n ).catch((error) => {\n // This should imply that error is a non-retriable error.\n this.logger.sendErrorEvent({ eventName: \"FluidFileUrlError\" }, error);\n this.sharingLinkCache.remove(key);\n throw error;\n });\n this.sharingLinkCache.add(key, async () => newLinkPromise);\n return newLinkPromise;\n }\n\n /**\n * Requests a driver + data store storage URL. Note that this method requires share link to be fetched\n * and it will throw in case share link fetcher props were not specified when instance was created.\n * @param resolvedUrl - The driver resolved URL\n * @param request - The relative data store path URL. For requesting a driver URL, this value should always be '/'\n */\n public async getAbsoluteUrl(\n resolvedUrl: IResolvedUrl,\n dataStorePath: string,\n packageInfoSource?: IContainerPackageInfo | IFluidCodeDetails,\n ): Promise<string> {\n const odspResolvedUrl = getOdspResolvedUrl(resolvedUrl);\n const shareLink = await this.getShareLinkPromise(odspResolvedUrl);\n const shareLinkUrl = new URL(shareLink);\n\n // back-compat: IFluidCodeDetails usage to be removed in 0.58.0\n let containerPackageName;\n if (packageInfoSource && \"name\" in packageInfoSource) {\n containerPackageName = packageInfoSource.name;\n } else if (isFluidPackage(packageInfoSource?.package)) {\n containerPackageName = packageInfoSource?.package.name;\n } else {\n containerPackageName = packageInfoSource?.package;\n }\n containerPackageName = containerPackageName ?? odspResolvedUrl.codeHint?.containerPackageName;\n\n storeLocatorInOdspUrl(shareLinkUrl, {\n siteUrl: odspResolvedUrl.siteUrl,\n driveId: odspResolvedUrl.driveId,\n itemId: odspResolvedUrl.itemId,\n dataStorePath,\n appName: this.appName,\n containerPackageName,\n fileVersion: odspResolvedUrl.fileVersion,\n });\n\n return shareLinkUrl.href;\n }\n\n /**\n * Crafts a supported document/driver URL\n */\n public static createDocumentUrl(baseUrl: string, driverInfo: OdspFluidDataStoreLocator) {\n const url = new URL(baseUrl);\n\n storeLocatorInOdspUrl(url, driverInfo);\n\n return url.href;\n }\n\n /**\n * Crafts a supported data store nav param\n */\n public static createNavParam(locator: OdspFluidDataStoreLocator) {\n return encodeOdspFluidDataStoreLocator(locator);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"odspDriverUrlResolverForShareLink.js","sourceRoot":"","sources":["../src/odspDriverUrlResolverForShareLink.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,+DAA4D;AAc5D,2DAK6B;AAC7B,uDAAiF;AACjF,mDAAgD;AAChD,mEAAgE;AAChE,2CAAmE;AACnE,+CAA4C;AAgB5C;;;;GAIG;AACH,MAAa,iCAAiC;IAK1C;;;;;;;;;OASG;IAC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B,oBAAoB,cAApB,oBAAoB,SAAI,eAAe,CAAC,QAAQ,0CAAE,oBAAoB,CAAC;QAE9F,yCAAqB,CAAC,YAAY,EAAE;YAChC,OAAO,EAAE,eAAe,CAAC,OAAO;YAChC,OAAO,EAAE,eAAe,CAAC,OAAO;YAChC,MAAM,EAAE,eAAe,CAAC,MAAM;YAC9B,aAAa;YACb,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,oBAAoB;YACpB,WAAW,EAAE,eAAe,CAAC,WAAW;SAC3C,CAAC,CAAC;QAEH,OAAO,YAAY,CAAC,IAAI,CAAC;IAC7B,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,iBAAiB,CAAC,OAAe,EAAE,UAAqC;QAClF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;QAE7B,yCAAqB,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAEvC,OAAO,GAAG,CAAC,IAAI,CAAC;IACpB,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,cAAc,CAAC,OAAkC;QAC3D,OAAO,mDAA+B,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;CACJ;AAlMD,8EAkMC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { PromiseCache } from \"@fluidframework/common-utils\";\nimport { IRequest } from \"@fluidframework/core-interfaces\";\nimport {\n IContainerPackageInfo,\n IResolvedUrl,\n IUrlResolver,\n} from \"@fluidframework/driver-definitions\";\nimport { ITelemetryBaseLogger, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport {\n IOdspResolvedUrl,\n IdentityType,\n OdspResourceTokenFetchOptions,\n TokenFetcher,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport {\n getLocatorFromOdspUrl,\n storeLocatorInOdspUrl,\n encodeOdspFluidDataStoreLocator,\n locatorQueryParamName,\n} from \"./odspFluidFileLink\";\nimport { OdspFluidDataStoreLocator, SharingLinkHeader } from \"./contractsPublic\";\nimport { createOdspUrl } from \"./createOdspUrl\";\nimport { OdspDriverUrlResolver } from \"./odspDriverUrlResolver\";\nimport { getOdspResolvedUrl, createOdspLogger } from \"./odspUtils\";\nimport { getFileLink } from \"./getFileLink\";\n\n/**\n * Properties passed to the code responsible for fetching share link for a file.\n */\nexport interface ShareLinkFetcherProps {\n /**\n * Callback method that is used to fetch access token necessary to call API that produces share link\n */\n tokenFetcher: TokenFetcher<OdspResourceTokenFetchOptions>;\n /**\n * Identity type determining the shape of share link as it differs for Enterprise and Consumer users.\n */\n identityType: IdentityType;\n}\n\n/**\n * Resolver to resolve urls like the ones created by createOdspUrl which is driver inner\n * url format and the ones which have things like driveId, siteId, itemId etc encoded in nav param.\n * This resolver also handles share links and try to generate one for the use by the app.\n */\nexport class OdspDriverUrlResolverForShareLink implements IUrlResolver {\n private readonly logger: ITelemetryLogger;\n private readonly sharingLinkCache = new PromiseCache<string, string>();\n private readonly shareLinkFetcherProps: ShareLinkFetcherProps | undefined;\n\n /**\n * Creates url resolver instance\n * @param shareLinkFetcherProps - properties used when fetching share link.\n * Can be set as 'undefined' for cases where share link is not needed. Currently, only\n * getAbsoluteUrl() method requires share link.\n * @param logger - logger object that is used as telemetry sink\n * @param appName - application name hint that is encoded with url produced by getAbsoluteUrl() method.\n * This hint is used by link handling logic which determines which app to redirect to when user\n * navigates directly to the link.\n */\n public constructor(\n shareLinkFetcherProps?: ShareLinkFetcherProps | undefined,\n logger?: ITelemetryBaseLogger,\n private readonly appName?: string,\n ) {\n this.logger = createOdspLogger(logger);\n if (shareLinkFetcherProps) {\n this.shareLinkFetcherProps = {\n ...shareLinkFetcherProps,\n tokenFetcher: shareLinkFetcherProps.tokenFetcher,\n };\n }\n }\n\n /**\n * Takes an already generated data store url (from requestUrl) and appends a path to the\n * existing data store information.\n */\n public appendDataStorePath(requestUrl: URL, pathToAppend: string): string | undefined {\n const fluidInfo = getLocatorFromOdspUrl(requestUrl);\n\n if (!fluidInfo) {\n return undefined;\n }\n\n const parsingUrl = new URL(fluidInfo.dataStorePath, `${requestUrl.protocol}//${requestUrl.hostname}`);\n // Determine if the caller is passing a query parameter or path since processing will be different.\n if (pathToAppend.startsWith(\"/?\") || pathToAppend.startsWith(\"?\")) {\n const queryParams = new URLSearchParams(pathToAppend);\n queryParams.forEach((value: string, key: string) => {\n parsingUrl.searchParams.append(key, value);\n });\n fluidInfo.dataStorePath = `${parsingUrl.pathname}${parsingUrl.search}`;\n } else {\n fluidInfo.dataStorePath = `${parsingUrl.pathname}${\n parsingUrl.pathname.endsWith(\"/\") || pathToAppend.startsWith(\"/\") ? \"\" : \"/\"\n }${pathToAppend}/${parsingUrl.search}`;\n }\n storeLocatorInOdspUrl(requestUrl, fluidInfo);\n\n return requestUrl.href;\n }\n\n private getKey(resolvedUrl: IOdspResolvedUrl): string {\n return `${resolvedUrl.siteUrl},${resolvedUrl.driveId},${resolvedUrl.itemId}`;\n }\n\n /**\n * Resolves request URL into driver details\n */\n public async resolve(request: IRequest): Promise<IOdspResolvedUrl> {\n const requestToBeResolved = { headers: request.headers, url: request.url };\n const isSharingLinkToRedeem = requestToBeResolved.headers?.[SharingLinkHeader.isSharingLinkToRedeem];\n try {\n const url = new URL(request.url);\n\n const odspFluidInfo = getLocatorFromOdspUrl(url);\n if (odspFluidInfo) {\n requestToBeResolved.url = createOdspUrl(odspFluidInfo);\n }\n } catch {\n // If the locator throws some error, then try to resolve the request as it is.\n }\n\n const odspResolvedUrl = await new OdspDriverUrlResolver().resolve(requestToBeResolved);\n\n if (isSharingLinkToRedeem) {\n // We need to remove the nav param if set by host when setting the sharelink as otherwise the shareLinkId\n // when redeeming the share link during the redeem fallback for trees latest call becomes greater than\n // the eligible length.\n odspResolvedUrl.shareLinkInfo = Object.assign(odspResolvedUrl.shareLinkInfo || {},\n {sharingLinkToRedeem: this.removeNavParam(request.url)});\n }\n if (odspResolvedUrl.itemId) {\n // Kick start the sharing link request if we don't have it already as a performance optimization.\n // For detached create new, we don't have an item id yet and therefore cannot generate a share link\n this.getShareLinkPromise(odspResolvedUrl).catch(() => {});\n }\n return odspResolvedUrl;\n }\n\n private removeNavParam(link: string): string {\n const url = new URL(link);\n const params = new URLSearchParams(url.search);\n params.delete(locatorQueryParamName);\n url.search = params.toString();\n return url.href;\n }\n\n private async getShareLinkPromise(resolvedUrl: IOdspResolvedUrl): Promise<string> {\n if (this.shareLinkFetcherProps === undefined) {\n throw new Error(\"Failed to get share link because share link fetcher props are missing\");\n }\n\n if (!(resolvedUrl.siteUrl && resolvedUrl.driveId && resolvedUrl.itemId)) {\n throw new Error(\"Failed to get share link because necessary information is missing \" +\n \"(e.g. siteUrl, driveId or itemId)\");\n }\n\n const key = this.getKey(resolvedUrl);\n const cachedLinkPromise = this.sharingLinkCache.get(key);\n if (cachedLinkPromise) {\n return cachedLinkPromise;\n }\n const newLinkPromise = getFileLink(\n this.shareLinkFetcherProps.tokenFetcher,\n resolvedUrl,\n this.shareLinkFetcherProps.identityType,\n this.logger,\n ).catch((error) => {\n // This should imply that error is a non-retriable error.\n this.logger.sendErrorEvent({ eventName: \"FluidFileUrlError\" }, error);\n this.sharingLinkCache.remove(key);\n throw error;\n });\n this.sharingLinkCache.add(key, async () => newLinkPromise);\n return newLinkPromise;\n }\n\n /**\n * Requests a driver + data store storage URL. Note that this method requires share link to be fetched\n * and it will throw in case share link fetcher props were not specified when instance was created.\n * @param resolvedUrl - The driver resolved URL\n * @param request - The relative data store path URL. For requesting a driver URL, this value should always be '/'\n */\n public async getAbsoluteUrl(\n resolvedUrl: IResolvedUrl,\n dataStorePath: string,\n packageInfoSource?: IContainerPackageInfo,\n ): Promise<string> {\n const odspResolvedUrl = getOdspResolvedUrl(resolvedUrl);\n const shareLink = await this.getShareLinkPromise(odspResolvedUrl);\n const shareLinkUrl = new URL(shareLink);\n // back-compat: GitHub #9653\n const isFluidPackage = (pkg: any) =>\n typeof pkg === \"object\"\n && typeof pkg?.name === \"string\"\n && typeof pkg?.fluid === \"object\";\n let containerPackageName;\n if (packageInfoSource && \"name\" in packageInfoSource) {\n containerPackageName = packageInfoSource.name;\n // packageInfoSource is cast to any as it is typed to IContainerPackageInfo instead of IFluidCodeDetails\n } else if (isFluidPackage((packageInfoSource as any)?.package)) {\n containerPackageName = (packageInfoSource as any)?.package.name;\n } else {\n containerPackageName = (packageInfoSource as any)?.package;\n }\n containerPackageName = containerPackageName ?? odspResolvedUrl.codeHint?.containerPackageName;\n\n storeLocatorInOdspUrl(shareLinkUrl, {\n siteUrl: odspResolvedUrl.siteUrl,\n driveId: odspResolvedUrl.driveId,\n itemId: odspResolvedUrl.itemId,\n dataStorePath,\n appName: this.appName,\n containerPackageName,\n fileVersion: odspResolvedUrl.fileVersion,\n });\n\n return shareLinkUrl.href;\n }\n\n /**\n * Crafts a supported document/driver URL\n */\n public static createDocumentUrl(baseUrl: string, driverInfo: OdspFluidDataStoreLocator) {\n const url = new URL(baseUrl);\n\n storeLocatorInOdspUrl(url, driverInfo);\n\n return url.href;\n }\n\n /**\n * Crafts a supported data store nav param\n */\n public static createNavParam(locator: OdspFluidDataStoreLocator) {\n return encodeOdspFluidDataStoreLocator(locator);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspSnapshotParser.d.ts","sourceRoot":"","sources":["../src/odspSnapshotParser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,aAAa,EAAuB,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"odspSnapshotParser.d.ts","sourceRoot":"","sources":["../src/odspSnapshotParser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,aAAa,EAAuB,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAwChD;;;GAGG;AACH,wBAAgB,yCAAyC,CACrD,YAAY,EAAE,aAAa,GAC5B,iBAAiB,CAgBnB"}
|
|
@@ -16,7 +16,7 @@ const common_utils_1 = require("@fluidframework/common-utils");
|
|
|
16
16
|
function buildHierarchy(flatTree) {
|
|
17
17
|
const lookup = {};
|
|
18
18
|
// id is required for root tree as it will be used to determine the version we loaded from.
|
|
19
|
-
const root = { id: flatTree.id, blobs: {},
|
|
19
|
+
const root = { id: flatTree.id, blobs: {}, trees: {} };
|
|
20
20
|
lookup[""] = root;
|
|
21
21
|
for (const entry of flatTree.entries) {
|
|
22
22
|
const lastIndex = entry.path.lastIndexOf("/");
|
|
@@ -28,7 +28,6 @@ function buildHierarchy(flatTree) {
|
|
|
28
28
|
if (entry.type === "tree") {
|
|
29
29
|
const newTree = {
|
|
30
30
|
blobs: {},
|
|
31
|
-
commits: {},
|
|
32
31
|
trees: {},
|
|
33
32
|
unreferenced: entry.unreferenced,
|
|
34
33
|
};
|
|
@@ -38,9 +37,6 @@ function buildHierarchy(flatTree) {
|
|
|
38
37
|
else if (entry.type === "blob") {
|
|
39
38
|
node.blobs[decodeURIComponent(entryPathBase)] = entry.id;
|
|
40
39
|
}
|
|
41
|
-
else if (entry.type === "commit") {
|
|
42
|
-
node.commits[decodeURIComponent(entryPathBase)] = entry.id;
|
|
43
|
-
}
|
|
44
40
|
}
|
|
45
41
|
return root;
|
|
46
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspSnapshotParser.js","sourceRoot":"","sources":["../src/odspSnapshotParser.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsE;AAKtE;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,QAA6B;IACjD,MAAM,MAAM,GAA0C,EAAE,CAAC;IACzD,2FAA2F;IAC3F,MAAM,IAAI,GAAsB,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"odspSnapshotParser.js","sourceRoot":"","sources":["../src/odspSnapshotParser.ts"],"names":[],"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AAO,IAAI,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,SAAgB,yCAAyC,CACrD,YAA2B;;IAE3B,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC9D,IAAI,YAAY,CAAC,KAAK,EAAE;QACpB,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;;YAChC,qBAAM,CAAC,IAAI,CAAC,QAAQ,KAAK,QAAQ,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAC5D,KAAK,CAAC,yDAAyD,CAAC,CAAC;YACrE,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,6BAAc,CAAC,IAAI,CAAC,OAAO,QAAE,IAAI,CAAC,QAAQ,mCAAI,MAAM,CAAC,CAAC,CAAC;QAC/F,CAAC,CAAC,CAAC;KACN;IACD,MAAM,GAAG,GAAsB;QAC3B,KAAK,EAAE,sBAAsB;QAC7B,GAAG,cAAE,YAAY,CAAC,GAAG,0CAAE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,oCAAK,EAAE;QAC/C,cAAc,EAAE,YAAY,CAAC,KAAK,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc;QAC5E,YAAY,EAAE,cAAc,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KACtD,CAAC;IACF,OAAO,GAAG,CAAC;AACf,CAAC;AAlBD,8FAkBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, stringToBuffer } from \"@fluidframework/common-utils\";\nimport * as api from \"@fluidframework/protocol-definitions\";\nimport { IOdspSnapshot, IOdspSnapshotCommit } from \"./contracts\";\nimport { ISnapshotContents } from \"./odspUtils\";\n\n/**\n * Build a tree hierarchy base on a flat tree\n *\n * @param flatTree - a flat tree\n * @param blobsShaToPathCache - Map with blobs sha as keys and values as path of the blob.\n * @returns the hierarchical tree\n */\nfunction buildHierarchy(flatTree: IOdspSnapshotCommit): api.ISnapshotTree {\n const lookup: { [path: string]: api.ISnapshotTree } = {};\n // id is required for root tree as it will be used to determine the version we loaded from.\n const root: api.ISnapshotTree = { id: flatTree.id, blobs: {}, trees: {} };\n lookup[\"\"] = root;\n\n for (const entry of flatTree.entries) {\n const lastIndex = entry.path.lastIndexOf(\"/\");\n const entryPathDir = entry.path.slice(0, Math.max(0, lastIndex));\n const entryPathBase = entry.path.slice(lastIndex + 1);\n\n // ODSP snapshots are created breadth-first so we can assume we see tree nodes prior to their contents\n const node = lookup[entryPathDir];\n\n // Add in either the blob or tree\n if (entry.type === \"tree\") {\n const newTree: api.ISnapshotTree = {\n blobs: {},\n trees: {},\n unreferenced: entry.unreferenced,\n };\n node.trees[decodeURIComponent(entryPathBase)] = newTree;\n lookup[entry.path] = newTree;\n } else if (entry.type === \"blob\") {\n node.blobs[decodeURIComponent(entryPathBase)] = entry.id;\n }\n }\n\n return root;\n}\n\n/**\n * Converts existing IOdspSnapshot to snapshot tree, blob array and ops\n * @param odspSnapshot - snapshot\n */\nexport function convertOdspSnapshotToSnapsohtTreeAndBlobs(\n odspSnapshot: IOdspSnapshot,\n): ISnapshotContents {\n const blobsWithBufferContent = new Map<string, ArrayBuffer>();\n if (odspSnapshot.blobs) {\n odspSnapshot.blobs.forEach((blob) => {\n assert(blob.encoding === \"base64\" || blob.encoding === undefined,\n 0x0a4 /* `Unexpected blob encoding type: '${blob.encoding}'` */);\n blobsWithBufferContent.set(blob.id, stringToBuffer(blob.content, blob.encoding ?? \"utf8\"));\n });\n }\n const val: ISnapshotContents = {\n blobs: blobsWithBufferContent,\n ops: odspSnapshot.ops?.map((op) => op.op) ?? [],\n sequenceNumber: odspSnapshot.trees && (odspSnapshot.trees[0]).sequenceNumber,\n snapshotTree: buildHierarchy(odspSnapshot.trees[0]),\n };\n return val;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspSummaryUploadManager.d.ts","sourceRoot":"","sources":["../src/odspSummaryUploadManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAEtE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAErE,OAAO,KAAK,GAAG,MAAM,sCAAsC,CAAC;AAC5D,OAAO,EAAE,+BAA+B,EAAE,MAAM,yCAAyC,CAAC;AAU1F,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAM9C;;;GAGG;AACH,qBAAa,wBAAwB;IAM7B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,eAAe;IAEhC,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,sCAAsC;IAR3D,OAAO,CAAC,yBAAyB,CAAqB;IACtD,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAoB;gBAGlB,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,+BAA+B,EACjE,MAAM,EAAE,gBAAgB,EACP,YAAY,EAAE,YAAY,EAC1B,sCAAsC,EAAE,OAAO;IAKvD,gBAAgB,CAAC,IAAI,EAAE,GAAG,CAAC,YAAY,EAAE,OAAO,EAAE,eAAe;YAqBhE,oBAAoB;
|
|
1
|
+
{"version":3,"file":"odspSummaryUploadManager.d.ts","sourceRoot":"","sources":["../src/odspSummaryUploadManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAEtE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAErE,OAAO,KAAK,GAAG,MAAM,sCAAsC,CAAC;AAC5D,OAAO,EAAE,+BAA+B,EAAE,MAAM,yCAAyC,CAAC;AAU1F,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAM9C;;;GAGG;AACH,qBAAa,wBAAwB;IAM7B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,eAAe;IAEhC,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,sCAAsC;IAR3D,OAAO,CAAC,yBAAyB,CAAqB;IACtD,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAoB;gBAGlB,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,+BAA+B,EACjE,MAAM,EAAE,gBAAgB,EACP,YAAY,EAAE,YAAY,EAC1B,sCAAsC,EAAE,OAAO;IAKvD,gBAAgB,CAAC,IAAI,EAAE,GAAG,CAAC,YAAY,EAAE,OAAO,EAAE,eAAe;YAqBhE,oBAAoB;IAgElC;;;;;;;;OAQG;YACW,4BAA4B;CAoG7C"}
|
|
@@ -64,14 +64,17 @@ class OdspSummaryUploadManager {
|
|
|
64
64
|
return id;
|
|
65
65
|
}
|
|
66
66
|
async writeSummaryTreeCore(parentHandle, referenceSequenceNumber, tree) {
|
|
67
|
-
const
|
|
67
|
+
const enableContainerTypeSummaryUpload = this.mc.config.getBoolean("Fluid.Driver.Odsp.EnableContainerTypeSummaryUpload");
|
|
68
|
+
const containsProtocolTree = enableContainerTypeSummaryUpload &&
|
|
69
|
+
Object.keys(tree.tree).includes(".protocol");
|
|
70
|
+
const { snapshotTree, blobs } = await this.convertSummaryToSnapshotTree(parentHandle, tree, ".app");
|
|
68
71
|
const snapshot = {
|
|
69
72
|
entries: snapshotTree.entries,
|
|
70
73
|
message: "app",
|
|
71
74
|
sequenceNumber: referenceSequenceNumber,
|
|
72
75
|
// no ack handle implies this is initial summary after empty file creation.
|
|
73
76
|
// send container payload so server will use it without a summary op
|
|
74
|
-
type: parentHandle === undefined ? "container" : "channel",
|
|
77
|
+
type: containsProtocolTree || parentHandle === undefined ? "container" : "channel",
|
|
75
78
|
};
|
|
76
79
|
return odspUtils_1.getWithRetryForTokenRefresh(async (options) => {
|
|
77
80
|
const storageToken = await this.getStorageToken(options, "WriteSummaryTree");
|
|
@@ -90,6 +93,8 @@ class OdspSummaryUploadManager {
|
|
|
90
93
|
blobs,
|
|
91
94
|
size: postBody.length,
|
|
92
95
|
referenceSequenceNumber,
|
|
96
|
+
type: snapshot.type,
|
|
97
|
+
enableContainerTypeSummaryUpload,
|
|
93
98
|
}, async () => {
|
|
94
99
|
const response = await this.epochTracker.fetchAndParseAsJSON(url, {
|
|
95
100
|
body: postBody,
|
|
@@ -109,9 +114,8 @@ class OdspSummaryUploadManager {
|
|
|
109
114
|
* @param path - Current path of node which is getting evaluated.
|
|
110
115
|
* @param markUnreferencedNodes - True if we should mark unreferenced nodes.
|
|
111
116
|
*/
|
|
112
|
-
async convertSummaryToSnapshotTree(parentHandle, tree, rootNodeName,
|
|
117
|
+
async convertSummaryToSnapshotTree(parentHandle, tree, rootNodeName, markUnreferencedNodes) {
|
|
113
118
|
var _a;
|
|
114
|
-
if (path === void 0) { path = ""; }
|
|
115
119
|
if (markUnreferencedNodes === void 0) { markUnreferencedNodes = (_a = this.mc.config.getBoolean("Fluid.Driver.Odsp.MarkUnreferencedNodes")) !== null && _a !== void 0 ? _a : true; }
|
|
116
120
|
const snapshotTree = {
|
|
117
121
|
type: "tree",
|
|
@@ -127,10 +131,9 @@ class OdspSummaryUploadManager {
|
|
|
127
131
|
// property is not present, the tree entry is considered referenced. If the property is present and is
|
|
128
132
|
// true (which is the only value it can have), the tree entry is considered unreferenced.
|
|
129
133
|
let unreferenced;
|
|
130
|
-
const currentPath = path === "" ? `${rootNodeName}/${key}` : `${path}/${key}`;
|
|
131
134
|
switch (summaryObject.type) {
|
|
132
135
|
case api.SummaryType.Tree: {
|
|
133
|
-
const result = await this.convertSummaryToSnapshotTree(parentHandle, summaryObject, rootNodeName
|
|
136
|
+
const result = await this.convertSummaryToSnapshotTree(parentHandle, summaryObject, rootNodeName);
|
|
134
137
|
value = result.snapshotTree;
|
|
135
138
|
unreferenced = markUnreferencedNodes ? summaryObject.unreferenced : undefined;
|
|
136
139
|
blobs += result.blobs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspSummaryUploadManager.js","sourceRoot":"","sources":["../src/odspSummaryUploadManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;AAGH,+DAA2F;AAE3F,iEAA2D;AAC3D,0EAA4D;AAE5D,qEAAiH;AAUjH,yEAAsE;AACtE,2CAA0D;AAE1D,4BAA4B;AAE5B;;;GAGG;AACH,MAAa,wBAAwB;IAKjC,YACqB,WAAmB,EACnB,eAAgD,EACjE,MAAwB,EACP,YAA0B,EAC1B,sCAA+C;QAJ/C,gBAAW,GAAX,WAAW,CAAQ;QACnB,oBAAe,GAAf,eAAe,CAAiC;QAEhD,iBAAY,GAAZ,YAAY,CAAc;QAC1B,2CAAsC,GAAtC,sCAAsC,CAAS;QAEhE,IAAI,CAAC,EAAE,GAAG,2CAAyB,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;IAEM,KAAK,CAAC,gBAAgB,CAAC,IAAsB,EAAE,OAAwB;QAC1E,8HAA8H;QAC9H,gIAAgI;QAChI,6GAA6G;QAC7G,IAAI,IAAI,CAAC,yBAAyB,KAAK,SAAS;YAC5C,IAAI,CAAC,yBAAyB,KAAK,OAAO,CAAC,cAAc,EAAE;YAC3D,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC;gBAC9B,SAAS,EAAE,mCAAmC;gBAC9C,0BAA0B,EAAE,OAAO,CAAC,cAAc;gBAClD,yBAAyB,EAAE,IAAI,CAAC,yBAAyB;aAC5D,CAAC,CAAC;SACN;QACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC;QACzG,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,C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C;CACJ;AAhND,4DAgNC;AAED,2BAA2B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, Uint8ArrayToString, unreachableCase } from \"@fluidframework/common-utils\";\nimport { ISummaryContext } from \"@fluidframework/driver-definitions\";\nimport { getGitType } from \"@fluidframework/protocol-base\";\nimport * as api from \"@fluidframework/protocol-definitions\";\nimport { InstrumentedStorageTokenFetcher } from \"@fluidframework/odsp-driver-definitions\";\nimport { loggerToMonitoringContext, MonitoringContext, PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport {\n IOdspSummaryPayload,\n IWriteSummaryResponse,\n IOdspSummaryTree,\n IOdspSummaryTreeBaseEntry,\n OdspSummaryTreeEntry,\n OdspSummaryTreeValue,\n} from \"./contracts\";\nimport { EpochTracker } from \"./epochTracker\";\nimport { getUrlAndHeadersWithAuth } from \"./getUrlAndHeadersWithAuth\";\nimport { getWithRetryForTokenRefresh } from \"./odspUtils\";\n\n/* eslint-disable max-len */\n\n/**\n * This class manages a summary upload. When it receives a call to upload summary, it converts the summary tree into\n * a snapshot tree and then uploads that to the server.\n */\nexport class OdspSummaryUploadManager {\n // Last proposed handle of the uploaded app summary.\n private lastSummaryProposalHandle: string | undefined;\n private readonly mc: MonitoringContext;\n\n constructor(\n private readonly snapshotUrl: string,\n private readonly getStorageToken: InstrumentedStorageTokenFetcher,\n logger: ITelemetryLogger,\n private readonly epochTracker: EpochTracker,\n private readonly forceAccessTokenViaAuthorizationHeader: boolean,\n ) {\n this.mc = loggerToMonitoringContext(logger);\n }\n\n public async writeSummaryTree(tree: api.ISummaryTree, context: ISummaryContext) {\n // If the last proposed handle is not the proposed handle of the acked summary(could happen when the last summary get nacked),\n // then re-initialize the caches with the previous ones else just update the previous caches with the caches from acked summary.\n // Don't bother logging if lastSummaryProposalHandle hasn't been set before; only log on a positive mismatch.\n if (this.lastSummaryProposalHandle !== undefined &&\n this.lastSummaryProposalHandle !== context.proposalHandle) {\n this.mc.logger.sendTelemetryEvent({\n eventName: \"LastSummaryProposedHandleMismatch\",\n ackedSummaryProposedHandle: context.proposalHandle,\n lastSummaryProposalHandle: this.lastSummaryProposalHandle,\n });\n }\n const result = await this.writeSummaryTreeCore(context.ackHandle, context.referenceSequenceNumber, tree);\n const id = result ? result.id : undefined;\n if (!result || !id) {\n throw new Error(`Failed to write summary tree`);\n }\n this.lastSummaryProposalHandle = id;\n return id;\n }\n\n private async writeSummaryTreeCore(\n parentHandle: string | undefined,\n referenceSequenceNumber: number,\n tree: api.ISummaryTree,\n ): Promise<IWriteSummaryResponse> {\n const { snapshotTree, blobs } = await this.convertSummaryToSnapshotTree(\n parentHandle,\n tree,\n \".app\",\n \"\",\n );\n const snapshot: IOdspSummaryPayload = {\n entries: snapshotTree.entries!,\n message: \"app\",\n sequenceNumber: referenceSequenceNumber,\n // no ack handle implies this is initial summary after empty file creation.\n // send container payload so server will use it without a summary op\n type: parentHandle === undefined ? \"container\" : \"channel\",\n };\n\n return getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await this.getStorageToken(options, \"WriteSummaryTree\");\n\n const { url, headers } = getUrlAndHeadersWithAuth(\n `${this.snapshotUrl}/snapshot`,\n storageToken,\n this.forceAccessTokenViaAuthorizationHeader,\n );\n headers[\"Content-Type\"] = \"application/json\";\n if (parentHandle) {\n headers[\"If-Match\"] = `fluid:containerid=${parentHandle}`;\n }\n\n const postBody = JSON.stringify(snapshot);\n\n return PerformanceEvent.timedExecAsync(this.mc.logger,\n {\n eventName: \"uploadSummary\",\n attempt: options.refresh ? 2 : 1,\n hasClaims: !!options.claims,\n hasTenantId: !!options.tenantId,\n headers: Object.keys(headers).length !== 0 ? true : undefined,\n blobs,\n size: postBody.length,\n referenceSequenceNumber,\n },\n async () => {\n const response = await this.epochTracker.fetchAndParseAsJSON<IWriteSummaryResponse>(\n url,\n {\n body: postBody,\n headers,\n method: \"POST\",\n },\n \"uploadSummary\");\n return response.content;\n });\n });\n }\n\n /**\n * Following are the goals of this function.\n * a.) Converts the summary tree to a snapshot/odsp tree to be uploaded. Always upload full snapshot tree.\n * @param parentHandle - Handle of the last uploaded summary or detach new summary.\n * @param tree - Summary Tree which will be converted to snapshot tree to be uploaded.\n * @param rootNodeName - Root node name of the summary tree.\n * @param path - Current path of node which is getting evaluated.\n * @param markUnreferencedNodes - True if we should mark unreferenced nodes.\n */\n private async convertSummaryToSnapshotTree(\n parentHandle: string | undefined,\n tree: api.ISummaryTree,\n rootNodeName: string,\n path: string = \"\",\n markUnreferencedNodes: boolean = this.mc.config.getBoolean(\"Fluid.Driver.Odsp.MarkUnreferencedNodes\") ?? true,\n ) {\n const snapshotTree: IOdspSummaryTree = {\n type: \"tree\",\n entries: [] as OdspSummaryTreeEntry[],\n };\n\n let blobs = 0;\n const keys = Object.keys(tree.tree);\n for (const key of keys) {\n const summaryObject = tree.tree[key];\n\n let id: string | undefined;\n let value: OdspSummaryTreeValue | undefined;\n\n // Tracks if an entry is unreferenced. Currently, only tree entries can be marked as unreferenced. If the\n // property is not present, the tree entry is considered referenced. If the property is present and is\n // true (which is the only value it can have), the tree entry is considered unreferenced.\n let unreferenced: true | undefined;\n const currentPath = path === \"\" ? `${rootNodeName}/${key}` : `${path}/${key}`;\n switch (summaryObject.type) {\n case api.SummaryType.Tree: {\n const result = await this.convertSummaryToSnapshotTree(\n parentHandle,\n summaryObject,\n rootNodeName,\n currentPath);\n value = result.snapshotTree;\n unreferenced = markUnreferencedNodes ? summaryObject.unreferenced : undefined;\n blobs += result.blobs;\n break;\n }\n case api.SummaryType.Blob: {\n if (typeof summaryObject.content === \"string\") {\n value = {\n type: \"blob\",\n content: summaryObject.content,\n encoding: \"utf-8\",\n };\n } else {\n value = {\n type: \"blob\",\n content: Uint8ArrayToString(summaryObject.content, \"base64\"),\n encoding: \"base64\",\n };\n }\n blobs++;\n break;\n }\n case api.SummaryType.Handle: {\n if (!parentHandle) {\n throw Error(\"Parent summary does not exist to reference by handle.\");\n }\n let handlePath = summaryObject.handle;\n if (handlePath.length > 0 && !handlePath.startsWith(\"/\")) {\n handlePath = `/${handlePath}`;\n }\n const pathKey = `${rootNodeName}${handlePath}`;\n id = `${parentHandle}/${pathKey}`;\n break;\n }\n case api.SummaryType.Attachment: {\n id = summaryObject.id;\n break;\n }\n default: {\n unreachableCase(summaryObject, `Unknown type: ${(summaryObject as any).type}`);\n }\n }\n\n const baseEntry: IOdspSummaryTreeBaseEntry = {\n path: encodeURIComponent(key),\n type: getGitType(summaryObject),\n };\n\n let entry: OdspSummaryTreeEntry;\n\n if (value) {\n assert(id === undefined, 0x0ad /* \"Snapshot entry has both a tree value and a referenced id!\" */);\n entry = {\n value,\n ...baseEntry,\n unreferenced,\n };\n } else if (id) {\n entry = {\n ...baseEntry,\n id,\n };\n } else {\n throw new Error(`Invalid tree entry for ${summaryObject.type}`);\n }\n\n snapshotTree.entries!.push(entry);\n }\n\n return { snapshotTree, blobs };\n }\n}\n\n/* eslint-enable max-len */\n"]}
|
|
1
|
+
{"version":3,"file":"odspSummaryUploadManager.js","sourceRoot":"","sources":["../src/odspSummaryUploadManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;AAGH,+DAA2F;AAE3F,iEAA2D;AAC3D,0EAA4D;AAE5D,qEAAiH;AAUjH,yEAAsE;AACtE,2CAA0D;AAE1D,4BAA4B;AAE5B;;;GAGG;AACH,MAAa,wBAAwB;IAKjC,YACqB,WAAmB,EACnB,eAAgD,EACjE,MAAwB,EACP,YAA0B,EAC1B,sCAA+C;QAJ/C,gBAAW,GAAX,WAAW,CAAQ;QACnB,oBAAe,GAAf,eAAe,CAAiC;QAEhD,iBAAY,GAAZ,YAAY,CAAc;QAC1B,2CAAsC,GAAtC,sCAAsC,CAAS;QAEhE,IAAI,CAAC,EAAE,GAAG,2CAAyB,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;IAEM,KAAK,CA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AC,IAAI,EAAE,CAAC,CAAC;iBAClF;aACJ;YAED,MAAM,SAAS,GAA8B;gBACzC,IAAI,EAAE,kBAAkB,CAAC,GAAG,CAAC;gBAC7B,IAAI,EAAE,0BAAU,CAAC,aAAa,CAAC;aAClC,CAAC;YAEF,IAAI,KAA2B,CAAC;YAEhC,IAAI,KAAK,EAAE;gBACP,qBAAM,CAAC,EAAE,KAAK,SAAS,EAAE,KAAK,CAAC,iEAAiE,CAAC,CAAC;gBAClG,KAAK,iCACD,KAAK,IACF,SAAS,KACZ,YAAY,GACf,CAAC;aACL;iBAAM,IAAI,EAAE,EAAE;gBACX,KAAK,mCACE,SAAS,KACZ,EAAE,GACL,CAAC;aACL;iBAAM;gBACH,MAAM,IAAI,KAAK,CAAC,0BAA0B,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;aACnE;YAED,YAAY,CAAC,OAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACrC;QAED,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IACnC,CAAC;CACJ;AAjND,4DAiNC;AAED,2BAA2B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, Uint8ArrayToString, unreachableCase } from \"@fluidframework/common-utils\";\nimport { ISummaryContext } from \"@fluidframework/driver-definitions\";\nimport { getGitType } from \"@fluidframework/protocol-base\";\nimport * as api from \"@fluidframework/protocol-definitions\";\nimport { InstrumentedStorageTokenFetcher } from \"@fluidframework/odsp-driver-definitions\";\nimport { loggerToMonitoringContext, MonitoringContext, PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport {\n IOdspSummaryPayload,\n IWriteSummaryResponse,\n IOdspSummaryTree,\n IOdspSummaryTreeBaseEntry,\n OdspSummaryTreeEntry,\n OdspSummaryTreeValue,\n} from \"./contracts\";\nimport { EpochTracker } from \"./epochTracker\";\nimport { getUrlAndHeadersWithAuth } from \"./getUrlAndHeadersWithAuth\";\nimport { getWithRetryForTokenRefresh } from \"./odspUtils\";\n\n/* eslint-disable max-len */\n\n/**\n * This class manages a summary upload. When it receives a call to upload summary, it converts the summary tree into\n * a snapshot tree and then uploads that to the server.\n */\nexport class OdspSummaryUploadManager {\n // Last proposed handle of the uploaded app summary.\n private lastSummaryProposalHandle: string | undefined;\n private readonly mc: MonitoringContext;\n\n constructor(\n private readonly snapshotUrl: string,\n private readonly getStorageToken: InstrumentedStorageTokenFetcher,\n logger: ITelemetryLogger,\n private readonly epochTracker: EpochTracker,\n private readonly forceAccessTokenViaAuthorizationHeader: boolean,\n ) {\n this.mc = loggerToMonitoringContext(logger);\n }\n\n public async writeSummaryTree(tree: api.ISummaryTree, context: ISummaryContext) {\n // If the last proposed handle is not the proposed handle of the acked summary(could happen when the last summary get nacked),\n // then re-initialize the caches with the previous ones else just update the previous caches with the caches from acked summary.\n // Don't bother logging if lastSummaryProposalHandle hasn't been set before; only log on a positive mismatch.\n if (this.lastSummaryProposalHandle !== undefined &&\n this.lastSummaryProposalHandle !== context.proposalHandle) {\n this.mc.logger.sendTelemetryEvent({\n eventName: \"LastSummaryProposedHandleMismatch\",\n ackedSummaryProposedHandle: context.proposalHandle,\n lastSummaryProposalHandle: this.lastSummaryProposalHandle,\n });\n }\n const result = await this.writeSummaryTreeCore(context.ackHandle, context.referenceSequenceNumber, tree);\n const id = result ? result.id : undefined;\n if (!result || !id) {\n throw new Error(`Failed to write summary tree`);\n }\n this.lastSummaryProposalHandle = id;\n return id;\n }\n\n private async writeSummaryTreeCore(\n parentHandle: string | undefined,\n referenceSequenceNumber: number,\n tree: api.ISummaryTree,\n ): Promise<IWriteSummaryResponse> {\n const enableContainerTypeSummaryUpload = this.mc.config.getBoolean(\"Fluid.Driver.Odsp.EnableContainerTypeSummaryUpload\");\n const containsProtocolTree = enableContainerTypeSummaryUpload &&\n Object.keys(tree.tree).includes(\".protocol\");\n const { snapshotTree, blobs } = await this.convertSummaryToSnapshotTree(\n parentHandle,\n tree,\n \".app\",\n );\n const snapshot: IOdspSummaryPayload = {\n entries: snapshotTree.entries!,\n message: \"app\",\n sequenceNumber: referenceSequenceNumber,\n // no ack handle implies this is initial summary after empty file creation.\n // send container payload so server will use it without a summary op\n type: containsProtocolTree || parentHandle === undefined ? \"container\" : \"channel\",\n };\n\n return getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await this.getStorageToken(options, \"WriteSummaryTree\");\n\n const { url, headers } = getUrlAndHeadersWithAuth(\n `${this.snapshotUrl}/snapshot`,\n storageToken,\n this.forceAccessTokenViaAuthorizationHeader,\n );\n headers[\"Content-Type\"] = \"application/json\";\n if (parentHandle) {\n headers[\"If-Match\"] = `fluid:containerid=${parentHandle}`;\n }\n\n const postBody = JSON.stringify(snapshot);\n\n return PerformanceEvent.timedExecAsync(this.mc.logger,\n {\n eventName: \"uploadSummary\",\n attempt: options.refresh ? 2 : 1,\n hasClaims: !!options.claims,\n hasTenantId: !!options.tenantId,\n headers: Object.keys(headers).length !== 0 ? true : undefined,\n blobs,\n size: postBody.length,\n referenceSequenceNumber,\n type: snapshot.type,\n enableContainerTypeSummaryUpload,\n },\n async () => {\n const response = await this.epochTracker.fetchAndParseAsJSON<IWriteSummaryResponse>(\n url,\n {\n body: postBody,\n headers,\n method: \"POST\",\n },\n \"uploadSummary\");\n return response.content;\n });\n });\n }\n\n /**\n * Following are the goals of this function.\n * a.) Converts the summary tree to a snapshot/odsp tree to be uploaded. Always upload full snapshot tree.\n * @param parentHandle - Handle of the last uploaded summary or detach new summary.\n * @param tree - Summary Tree which will be converted to snapshot tree to be uploaded.\n * @param rootNodeName - Root node name of the summary tree.\n * @param path - Current path of node which is getting evaluated.\n * @param markUnreferencedNodes - True if we should mark unreferenced nodes.\n */\n private async convertSummaryToSnapshotTree(\n parentHandle: string | undefined,\n tree: api.ISummaryTree,\n rootNodeName: string,\n markUnreferencedNodes: boolean = this.mc.config.getBoolean(\"Fluid.Driver.Odsp.MarkUnreferencedNodes\") ?? true,\n ) {\n const snapshotTree: IOdspSummaryTree = {\n type: \"tree\",\n entries: [] as OdspSummaryTreeEntry[],\n };\n\n let blobs = 0;\n const keys = Object.keys(tree.tree);\n for (const key of keys) {\n const summaryObject = tree.tree[key];\n\n let id: string | undefined;\n let value: OdspSummaryTreeValue | undefined;\n\n // Tracks if an entry is unreferenced. Currently, only tree entries can be marked as unreferenced. If the\n // property is not present, the tree entry is considered referenced. If the property is present and is\n // true (which is the only value it can have), the tree entry is considered unreferenced.\n let unreferenced: true | undefined;\n switch (summaryObject.type) {\n case api.SummaryType.Tree: {\n const result = await this.convertSummaryToSnapshotTree(\n parentHandle,\n summaryObject,\n rootNodeName);\n value = result.snapshotTree;\n unreferenced = markUnreferencedNodes ? summaryObject.unreferenced : undefined;\n blobs += result.blobs;\n break;\n }\n case api.SummaryType.Blob: {\n if (typeof summaryObject.content === \"string\") {\n value = {\n type: \"blob\",\n content: summaryObject.content,\n encoding: \"utf-8\",\n };\n } else {\n value = {\n type: \"blob\",\n content: Uint8ArrayToString(summaryObject.content, \"base64\"),\n encoding: \"base64\",\n };\n }\n blobs++;\n break;\n }\n case api.SummaryType.Handle: {\n if (!parentHandle) {\n throw Error(\"Parent summary does not exist to reference by handle.\");\n }\n let handlePath = summaryObject.handle;\n if (handlePath.length > 0 && !handlePath.startsWith(\"/\")) {\n handlePath = `/${handlePath}`;\n }\n const pathKey = `${rootNodeName}${handlePath}`;\n id = `${parentHandle}/${pathKey}`;\n break;\n }\n case api.SummaryType.Attachment: {\n id = summaryObject.id;\n break;\n }\n default: {\n unreachableCase(summaryObject, `Unknown type: ${(summaryObject as any).type}`);\n }\n }\n\n const baseEntry: IOdspSummaryTreeBaseEntry = {\n path: encodeURIComponent(key),\n type: getGitType(summaryObject),\n };\n\n let entry: OdspSummaryTreeEntry;\n\n if (value) {\n assert(id === undefined, 0x0ad /* \"Snapshot entry has both a tree value and a referenced id!\" */);\n entry = {\n value,\n ...baseEntry,\n unreferenced,\n };\n } else if (id) {\n entry = {\n ...baseEntry,\n id,\n };\n } else {\n throw new Error(`Invalid tree entry for ${summaryObject.type}`);\n }\n\n snapshotTree.entries!.push(entry);\n }\n\n return { snapshotTree, blobs };\n }\n}\n\n/* eslint-enable max-len */\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/odsp-driver";
|
|
8
|
-
export declare const pkgVersion = "0.
|
|
8
|
+
export declare const pkgVersion = "0.59.1000";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/odsp-driver";
|
|
11
|
-
exports.pkgVersion = "0.
|
|
11
|
+
exports.pkgVersion = "0.59.1000";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,6BAA6B,CAAC;AACxC,QAAA,UAAU,GAAG,WAAW,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/odsp-driver\";\nexport const pkgVersion = \"0.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,6BAA6B,CAAC;AACxC,QAAA,UAAU,GAAG,WAAW,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/odsp-driver\";\nexport const pkgVersion = \"0.59.1000\";\n"]}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { ISnapshotContents } from "./odspUtils";
|
|
6
6
|
import { ReadBuffer } from "./ReadBufferUtils";
|
|
7
7
|
export declare const snapshotMinReadVersion = "1.0";
|
|
8
|
+
export declare const currentReadVersion = "1.0";
|
|
8
9
|
/**
|
|
9
10
|
* Converts snapshot from binary compact representation to tree/blobs/ops.
|
|
10
11
|
* @param buffer - Compact snapshot to be parsed into tree/blobs/ops.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compactSnapshotParser.d.ts","sourceRoot":"","sources":["../src/compactSnapshotParser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"compactSnapshotParser.d.ts","sourceRoot":"","sources":["../src/compactSnapshotParser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAY/C,eAAO,MAAM,sBAAsB,QAAQ,CAAC;AAC5C,eAAO,MAAM,kBAAkB,QAAQ,CAAC;AA+FxC;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,UAAU,GAAG,iBAAiB,CAqBlF"}
|
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
import { assert } from "@fluidframework/common-utils";
|
|
6
6
|
import { assertBlobCoreInstance, assertBoolInstance, assertNodeCoreInstance, assertNumberInstance, getAndValidateNodeProps, TreeBuilder, } from "./zipItDataRepresentationUtils";
|
|
7
7
|
export const snapshotMinReadVersion = "1.0";
|
|
8
|
+
export const currentReadVersion = "1.0";
|
|
8
9
|
/**
|
|
9
10
|
* Recreates blobs section of the tree.
|
|
10
11
|
* @param node - tree node to read blob section from
|
|
11
12
|
*/
|
|
12
13
|
function readBlobSection(node) {
|
|
14
|
+
assertNodeCoreInstance(node, "TreeBlobs should be of type NodeCore");
|
|
13
15
|
const blobs = new Map();
|
|
14
16
|
for (let count = 0; count < node.length; ++count) {
|
|
15
17
|
const blob = node.getNode(count);
|
|
@@ -25,6 +27,7 @@ function readBlobSection(node) {
|
|
|
25
27
|
* @param node - tree node to read ops section from
|
|
26
28
|
*/
|
|
27
29
|
function readOpsSection(node) {
|
|
30
|
+
assertNodeCoreInstance(node, "Deltas should be of type NodeCore");
|
|
28
31
|
const ops = [];
|
|
29
32
|
const records = getAndValidateNodeProps(node, ["firstSequenceNumber", "deltas"]);
|
|
30
33
|
assertNumberInstance(records.firstSequenceNumber, "Seq number should be a number");
|
|
@@ -42,7 +45,6 @@ function readOpsSection(node) {
|
|
|
42
45
|
function readTreeSection(node) {
|
|
43
46
|
const snapshotTree = {
|
|
44
47
|
blobs: {},
|
|
45
|
-
commits: {},
|
|
46
48
|
trees: {},
|
|
47
49
|
};
|
|
48
50
|
for (let count = 0; count < node.length; count++) {
|
|
@@ -72,6 +74,7 @@ function readTreeSection(node) {
|
|
|
72
74
|
* @param node - tree node to de-serialize from
|
|
73
75
|
*/
|
|
74
76
|
function readSnapshotSection(node) {
|
|
77
|
+
assertNodeCoreInstance(node, "Snapshot should be of type NodeCore");
|
|
75
78
|
const records = getAndValidateNodeProps(node, ["id", "sequenceNumber", "treeNodes"]);
|
|
76
79
|
assertNodeCoreInstance(records.treeNodes, "TreeNodes should be of type NodeCore");
|
|
77
80
|
assertNumberInstance(records.sequenceNumber, "sequenceNumber should be of type number");
|
|
@@ -93,14 +96,12 @@ export function parseCompactSnapshotResponse(buffer) {
|
|
|
93
96
|
const builder = TreeBuilder.load(buffer);
|
|
94
97
|
assert(builder.length === 1, 0x219 /* "1 root should be there" */);
|
|
95
98
|
const root = builder.getNode(0);
|
|
96
|
-
const records = getAndValidateNodeProps(root, ["mrv", "cv", "snapshot", "blobs", "deltas"]);
|
|
99
|
+
const records = getAndValidateNodeProps(root, ["mrv", "cv", "snapshot", "blobs", "deltas"], false);
|
|
97
100
|
assertBlobCoreInstance(records.mrv, "minReadVersion should be of BlobCore type");
|
|
98
101
|
assertBlobCoreInstance(records.cv, "createVersion should be of BlobCore type");
|
|
99
102
|
assert(snapshotMinReadVersion >= records.mrv.toString(), 0x20f /* "Driver min read version should >= to server minReadVersion" */);
|
|
100
103
|
assert(records.cv.toString() >= snapshotMinReadVersion, 0x210 /* "Snapshot should be created with minReadVersion or above" */);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
assertNodeCoreInstance(records.deltas, "Deltas should be of type NodeCore");
|
|
104
|
-
return Object.assign(Object.assign({}, readSnapshotSection(records.snapshot)), { blobs: readBlobSection(records.blobs), ops: readOpsSection(records.deltas) });
|
|
104
|
+
assert(currentReadVersion === records.cv.toString(), 0x2c2 /* "Create Version should be equal to currentReadVersion" */);
|
|
105
|
+
return Object.assign(Object.assign({}, readSnapshotSection(records.snapshot)), { blobs: readBlobSection(records.blobs), ops: records.deltas !== undefined ? readOpsSection(records.deltas) : [] });
|
|
105
106
|
}
|
|
106
107
|
//# sourceMappingURL=compactSnapshotParser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compactSnapshotParser.js","sourceRoot":"","sources":["../src/compactSnapshotParser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAItD,OAAO,EACH,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,uBAAu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,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IAElD,sBAAsB,CAAC,OAAO,CAAC,GAAG,EAAE,2CAA2C,CAAC,CAAC;IACjF,sBAAsB,CAAC,OAAO,CAAC,EAAE,EAAE,0CAA0C,CAAC,CAAC;IAC/E,MAAM,CAAC,sBAAsB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,EACnD,KAAK,CAAC,kEAAkE,CAAC,CAAC;IAC9E,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,sBAAsB,EAClD,KAAK,CAAC,+DAA+D,CAAC,CAAC;IAE3E,sBAAsB,CAAC,OAAO,CAAC,QAAQ,EAAE,qCAAqC,CAAC,CAAC;IAChF,sBAAsB,CAAC,OAAO,CAAC,KAAK,EAAE,sCAAsC,CAAC,CAAC;IAC9E,sBAAsB,CAAC,OAAO,CAAC,MAAM,EAAE,mCAAmC,CAAC,CAAC;IAE5E,uCACO,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,KACxC,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,EACrC,GAAG,EAAE,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,IACrC;AACN,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport { ISnapshotContents } from \"./odspUtils\";\nimport { ReadBuffer } from \"./ReadBufferUtils\";\nimport {\n assertBlobCoreInstance,\n assertBoolInstance,\n assertNodeCoreInstance,\n assertNumberInstance,\n getAndValidateNodeProps,\n NodeCore,\n TreeBuilder,\n} from \"./zipItDataRepresentationUtils\";\n\nexport const snapshotMinReadVersion = \"1.0\";\n\ninterface ISnapshotSection {\n snapshotTree: ISnapshotTree,\n sequenceNumber: number,\n}\n\n/**\n * Recreates blobs section of the tree.\n * @param node - tree node to read blob section from\n */\nfunction readBlobSection(node: NodeCore) {\n const blobs: Map<string, ArrayBuffer> = new Map();\n for (let count = 0; count < node.length; ++count) {\n const blob = node.getNode(count);\n const records = getAndValidateNodeProps(blob, [\"id\", \"data\"]);\n assertBlobCoreInstance(records.data, \"data should be of BlobCore type\");\n assertBlobCoreInstance(records.id, \"blob id should be of BlobCore type\");\n blobs.set(records.id.toString(), records.data.arrayBuffer);\n }\n return blobs;\n}\n\n/**\n * Recreates ops section of the tree.\n * @param node - tree node to read ops section from\n */\nfunction readOpsSection(node: NodeCore) {\n const ops: ISequencedDocumentMessage[] = [];\n const records = getAndValidateNodeProps(node, [\"firstSequenceNumber\", \"deltas\"]);\n assertNumberInstance(records.firstSequenceNumber, \"Seq number should be a number\");\n assertNodeCoreInstance(records.deltas, \"Deltas should be a Node\");\n for (let i = 0; i < records.deltas.length; ++i) {\n ops.push(JSON.parse(records.deltas.getString(i)));\n }\n assert(records.firstSequenceNumber.valueOf() === ops[0].sequenceNumber, 0x280 /* \"Validate first op seq number\" */);\n return ops;\n}\n\n/**\n * Recreates snapshot tree out of tree representation.\n * @param node - tree node to de-serialize from\n */\nfunction readTreeSection(node: NodeCore) {\n const snapshotTree: ISnapshotTree = {\n blobs: {},\n commits: {},\n trees: {},\n };\n for (let count = 0; count < node.length; count++) {\n const treeNode = node.getNode(count);\n const records = getAndValidateNodeProps(treeNode,\n [\"name\", \"value\", \"children\", \"unreferenced\"], false);\n assertBlobCoreInstance(records.name, \"Path should be of BlobCore\");\n const path = records.name.toString();\n if (records.value !== undefined) {\n assertBlobCoreInstance(records.value, \"Blob value should be BlobCore\");\n snapshotTree.blobs[path] = records.value.toString();\n } else {\n assertNodeCoreInstance(records.children, \"Trees should be of type NodeCore\");\n snapshotTree.trees[path] = readTreeSection(records.children);\n }\n if (records.unreferenced !== undefined) {\n assertBoolInstance(records.unreferenced, \"Unreferenced flag should be bool\");\n const unreferenced = records.unreferenced.valueOf();\n assert(unreferenced, 0x281 /* \"Unreferenced if present should be true\" */);\n snapshotTree.unreferenced = unreferenced;\n }\n }\n return snapshotTree;\n}\n\n/**\n * Recreates snapshot tree out of tree representation.\n * @param node - tree node to de-serialize from\n */\nfunction readSnapshotSection(node: NodeCore): ISnapshotSection {\n const records = getAndValidateNodeProps(node,\n [\"id\", \"sequenceNumber\", \"treeNodes\"]);\n\n assertNodeCoreInstance(records.treeNodes, \"TreeNodes should be of type NodeCore\");\n assertNumberInstance(records.sequenceNumber, \"sequenceNumber should be of type number\");\n assertBlobCoreInstance(records.id, \"snapshotId should be BlobCore\");\n const snapshotTree: ISnapshotTree = readTreeSection(records.treeNodes);\n snapshotTree.id = records.id.toString();\n const sequenceNumber = records.sequenceNumber.valueOf();\n return {\n sequenceNumber,\n snapshotTree,\n };\n}\n\n/**\n * Converts snapshot from binary compact representation to tree/blobs/ops.\n * @param buffer - Compact snapshot to be parsed into tree/blobs/ops.\n * @returns - tree, blobs and ops from the snapshot.\n */\nexport function parseCompactSnapshotResponse(buffer: ReadBuffer): ISnapshotContents {\n const builder = TreeBuilder.load(buffer);\n assert(builder.length === 1, 0x219 /* \"1 root should be there\" */);\n const root = builder.getNode(0);\n\n const records = getAndValidateNodeProps(root,\n [\"mrv\", \"cv\", \"snapshot\", \"blobs\", \"deltas\"]);\n\n assertBlobCoreInstance(records.mrv, \"minReadVersion should be of BlobCore type\");\n assertBlobCoreInstance(records.cv, \"createVersion should be of BlobCore type\");\n assert(snapshotMinReadVersion >= records.mrv.toString(),\n 0x20f /* \"Driver min read version should >= to server minReadVersion\" */);\n assert(records.cv.toString() >= snapshotMinReadVersion,\n 0x210 /* \"Snapshot should be created with minReadVersion or above\" */);\n\n assertNodeCoreInstance(records.snapshot, \"Snapshot should be of type NodeCore\");\n assertNodeCoreInstance(records.blobs, \"TreeBlobs should be of type NodeCore\");\n assertNodeCoreInstance(records.deltas, \"Deltas should be of type NodeCore\");\n\n return {\n ...readSnapshotSection(records.snapshot),\n blobs: readBlobSection(records.blobs),\n ops: readOpsSection(records.deltas),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"compactSnapshotParser.js","sourceRoot":"","sources":["../src/compactSnapshotParser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAItD,OAAO,EACH,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,uBAAuB,EAGvB,WAAW,GACd,MAAM,gCAAgC,CAAC;AAExC,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,CAAC;AAC5C,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAOxC;;;GAGG;AACH,SAAS,eAAe,CAAC,IAAe;IACpC,sBAAsB,CAAC,IAAI,EAAE,sCAAsC,CAAC,CAAC;IACrE,MAAM,KAAK,GAA6B,IAAI,GAAG,EAAE,CAAC;IAClD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE;QAC9C,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACjC,MAAM,OAAO,GAAG,uBAAuB,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QAC9D,sBAAsB,CAAC,OAAO,CAAC,IAAI,EAAE,iCAAiC,CAAC,CAAC;QACxE,sBAAsB,CAAC,OAAO,CAAC,EAAE,EAAE,oCAAoC,CAAC,CAAC;QACzE,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;KAC9D;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc,CAAC,IAAe;IACnC,sBAAsB,CAAC,IAAI,EAAE,mCAAmC,CAAC,CAAC;IAClE,MA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AAC,EAAE,IACzE;AACN,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport { ISnapshotContents } from \"./odspUtils\";\nimport { ReadBuffer } from \"./ReadBufferUtils\";\nimport {\n assertBlobCoreInstance,\n assertBoolInstance,\n assertNodeCoreInstance,\n assertNumberInstance,\n getAndValidateNodeProps,\n NodeCore,\n NodeTypes,\n TreeBuilder,\n} from \"./zipItDataRepresentationUtils\";\n\nexport const snapshotMinReadVersion = \"1.0\";\nexport const currentReadVersion = \"1.0\";\n\ninterface ISnapshotSection {\n snapshotTree: ISnapshotTree,\n sequenceNumber: number,\n}\n\n/**\n * Recreates blobs section of the tree.\n * @param node - tree node to read blob section from\n */\nfunction readBlobSection(node: NodeTypes) {\n assertNodeCoreInstance(node, \"TreeBlobs should be of type NodeCore\");\n const blobs: Map<string, ArrayBuffer> = new Map();\n for (let count = 0; count < node.length; ++count) {\n const blob = node.getNode(count);\n const records = getAndValidateNodeProps(blob, [\"id\", \"data\"]);\n assertBlobCoreInstance(records.data, \"data should be of BlobCore type\");\n assertBlobCoreInstance(records.id, \"blob id should be of BlobCore type\");\n blobs.set(records.id.toString(), records.data.arrayBuffer);\n }\n return blobs;\n}\n\n/**\n * Recreates ops section of the tree.\n * @param node - tree node to read ops section from\n */\nfunction readOpsSection(node: NodeTypes) {\n assertNodeCoreInstance(node, \"Deltas should be of type NodeCore\");\n const ops: ISequencedDocumentMessage[] = [];\n const records = getAndValidateNodeProps(node, [\"firstSequenceNumber\", \"deltas\"]);\n assertNumberInstance(records.firstSequenceNumber, \"Seq number should be a number\");\n assertNodeCoreInstance(records.deltas, \"Deltas should be a Node\");\n for (let i = 0; i < records.deltas.length; ++i) {\n ops.push(JSON.parse(records.deltas.getString(i)));\n }\n assert(records.firstSequenceNumber.valueOf() === ops[0].sequenceNumber,\n 0x280 /* \"Validate first op seq number\" */);\n return ops;\n}\n\n/**\n * Recreates snapshot tree out of tree representation.\n * @param node - tree node to de-serialize from\n */\nfunction readTreeSection(node: NodeCore) {\n const snapshotTree: ISnapshotTree = {\n blobs: {},\n trees: {},\n };\n for (let count = 0; count < node.length; count++) {\n const treeNode = node.getNode(count);\n const records = getAndValidateNodeProps(treeNode,\n [\"name\", \"value\", \"children\", \"unreferenced\"], false);\n assertBlobCoreInstance(records.name, \"Path should be of BlobCore\");\n const path = records.name.toString();\n if (records.value !== undefined) {\n assertBlobCoreInstance(records.value, \"Blob value should be BlobCore\");\n snapshotTree.blobs[path] = records.value.toString();\n } else {\n assertNodeCoreInstance(records.children, \"Trees should be of type NodeCore\");\n snapshotTree.trees[path] = readTreeSection(records.children);\n }\n if (records.unreferenced !== undefined) {\n assertBoolInstance(records.unreferenced, \"Unreferenced flag should be bool\");\n const unreferenced = records.unreferenced.valueOf();\n assert(unreferenced, 0x281 /* \"Unreferenced if present should be true\" */);\n snapshotTree.unreferenced = unreferenced;\n }\n }\n return snapshotTree;\n}\n\n/**\n * Recreates snapshot tree out of tree representation.\n * @param node - tree node to de-serialize from\n */\nfunction readSnapshotSection(node: NodeTypes): ISnapshotSection {\n assertNodeCoreInstance(node, \"Snapshot should be of type NodeCore\");\n const records = getAndValidateNodeProps(node,\n [\"id\", \"sequenceNumber\", \"treeNodes\"]);\n\n assertNodeCoreInstance(records.treeNodes, \"TreeNodes should be of type NodeCore\");\n assertNumberInstance(records.sequenceNumber, \"sequenceNumber should be of type number\");\n assertBlobCoreInstance(records.id, \"snapshotId should be BlobCore\");\n const snapshotTree: ISnapshotTree = readTreeSection(records.treeNodes);\n snapshotTree.id = records.id.toString();\n const sequenceNumber = records.sequenceNumber.valueOf();\n return {\n sequenceNumber,\n snapshotTree,\n };\n}\n\n/**\n * Converts snapshot from binary compact representation to tree/blobs/ops.\n * @param buffer - Compact snapshot to be parsed into tree/blobs/ops.\n * @returns - tree, blobs and ops from the snapshot.\n */\nexport function parseCompactSnapshotResponse(buffer: ReadBuffer): ISnapshotContents {\n const builder = TreeBuilder.load(buffer);\n assert(builder.length === 1, 0x219 /* \"1 root should be there\" */);\n const root = builder.getNode(0);\n\n const records = getAndValidateNodeProps(root,\n [\"mrv\", \"cv\", \"snapshot\", \"blobs\", \"deltas\"], false);\n\n assertBlobCoreInstance(records.mrv, \"minReadVersion should be of BlobCore type\");\n assertBlobCoreInstance(records.cv, \"createVersion should be of BlobCore type\");\n assert(snapshotMinReadVersion >= records.mrv.toString(),\n 0x20f /* \"Driver min read version should >= to server minReadVersion\" */);\n assert(records.cv.toString() >= snapshotMinReadVersion,\n 0x210 /* \"Snapshot should be created with minReadVersion or above\" */);\n assert(currentReadVersion === records.cv.toString(),\n 0x2c2 /* \"Create Version should be equal to currentReadVersion\" */);\n return {\n ...readSnapshotSection(records.snapshot),\n blobs: readBlobSection(records.blobs),\n ops: records.deltas !== undefined ? readOpsSection(records.deltas) : [],\n };\n}\n"]}
|
package/lib/createNewUtils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createNewUtils.js","sourceRoot":"","sources":["../src/createNewUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAA+B,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAChG,OAAO,EAAE,mCAAmC,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAG/E;;GAEG;AACH,MAAM,UAAU,yCAAyC,CAAC,OAAqB,EAAE,MAAc;IAC3F,MAAM,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,WAAW,CAAiB,CAAC;IAClE,MAAM,kBAAkB,GAAG,mCAAmC,CAAC,eAAe,CAAC,CAAC;IAChF,MAAM,cAAc,GAAG,kBAAkB,CAA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qBAAsB,aAAqB,CAAC,IAAI,EAAE,CAAC,CAAC;aACtF;SACJ;KACJ;IACD,OAAO,QAAQ,CAAC;AACpB,CAAC","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 { ISnapshotTree, ISummaryTree, SummaryType } from \"@fluidframework/protocol-definitions\";\nimport { getDocAttributesFromProtocolSummary } from \"@fluidframework/driver-utils\";\nimport { stringToBuffer, unreachableCase } from \"@fluidframework/common-utils\";\nimport { ISnapshotContents } from \"./odspUtils\";\n\n/**\n * Converts a summary(ISummaryTree) taken in detached container to snapshot tree and blobs\n */\nexport function convertCreateNewSummaryTreeToTreeAndBlobs(summary: ISummaryTree, treeId: string): ISnapshotContents {\n const protocolSummary = summary.tree[\".protocol\"] as ISummaryTree;\n const documentAttributes = getDocAttributesFromProtocolSummary(protocolSummary);\n const sequenceNumber = documentAttributes.sequenceNumber;\n const blobs = new Map<string, ArrayBuffer>();\n const snapshotTree = convertCreateNewSummaryTreeToTreeAndBlobsCore(summary, blobs);\n snapshotTree.id = treeId;\n const snapshotTreeValue: ISnapshotContents = {\n snapshotTree,\n blobs,\n ops: [],\n sequenceNumber,\n };\n\n return snapshotTreeValue;\n}\n\nfunction convertCreateNewSummaryTreeToTreeAndBlobsCore(\n summary: ISummaryTree,\n blobs: Map<string, ArrayBuffer>,\n) {\n const treeNode: ISnapshotTree = {\n blobs: {},\n trees: {},\n unreferenced: summary.unreferenced,\n };\n const keys = Object.keys(summary.tree);\n for (const key of keys) {\n const summaryObject = summary.tree[key];\n\n switch (summaryObject.type) {\n case SummaryType.Tree: {\n treeNode.trees[key] =\n convertCreateNewSummaryTreeToTreeAndBlobsCore(summaryObject, blobs);\n break;\n }\n case SummaryType.Blob: {\n const contentBuffer = typeof summaryObject.content === \"string\" ?\n stringToBuffer(summaryObject.content, \"utf8\") : summaryObject.content;\n const blobId = uuid();\n treeNode.blobs[key] = blobId;\n blobs.set(blobId, contentBuffer);\n break;\n }\n case SummaryType.Handle:\n case SummaryType.Attachment: {\n throw new Error(`No ${summaryObject.type} should be present for detached summary!`);\n }\n default: {\n unreachableCase(summaryObject, `Unknown tree type ${(summaryObject as any).type}`);\n }\n }\n }\n return treeNode;\n}\n"]}
|
package/lib/epochTracker.d.ts
CHANGED
|
@@ -39,14 +39,26 @@ export declare class EpochTracker implements IPersistedFileCache {
|
|
|
39
39
|
* @param fetchOptions - fetch options for request containing body, headers etc.
|
|
40
40
|
* @param fetchType - method for which fetch is called.
|
|
41
41
|
* @param addInBody - Pass True if caller wants to add epoch in post body.
|
|
42
|
+
* @param fetchReason - fetch reason to add to the request.
|
|
42
43
|
*/
|
|
43
44
|
fetchAndParseAsJSON<T>(url: string, fetchOptions: RequestInit, fetchType: FetchType, addInBody?: boolean, fetchReason?: string): Promise<IOdspResponse<T>>;
|
|
45
|
+
/**
|
|
46
|
+
* Api to fetch the response for given request and parse it as json.
|
|
47
|
+
* @param url - url of the request
|
|
48
|
+
* @param fetchOptions - fetch options for request containing body, headers etc.
|
|
49
|
+
* @param fetchType - method for which fetch is called.
|
|
50
|
+
* @param addInBody - Pass True if caller wants to add epoch in post body.
|
|
51
|
+
* @param fetchReason - fetch reason to add to the request.
|
|
52
|
+
*/
|
|
53
|
+
fetch(url: string, fetchOptions: RequestInit, fetchType: FetchType, addInBody?: boolean, fetchReason?: string): Promise<IOdspResponse<Response>>;
|
|
54
|
+
private fetchCore;
|
|
44
55
|
/**
|
|
45
56
|
* Api to fetch the response as it is for given request.
|
|
46
57
|
* @param url - url of the request
|
|
47
58
|
* @param fetchOptions - fetch options for request containing body, headers etc.
|
|
48
59
|
* @param fetchType - method for which fetch is called.
|
|
49
60
|
* @param addInBody - Pass True if caller wants to add epoch in post body.
|
|
61
|
+
* @param fetchReason - fetch reason to add to the request.
|
|
50
62
|
*/
|
|
51
63
|
fetchArray(url: string, fetchOptions: {
|
|
52
64
|
[index: string]: any;
|
|
@@ -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;AACtE,OAAO,EAAmB,WAAW,EAAqB,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAClE,OAAO,EAGH,MAAM,EACN,UAAU,EACV,eAAe,EAElB,MAAM,yCAAyC,CAAC;AAGjD,OAAO,
|
|
1
|
+
{"version":3,"file":"epochTracker.d.ts","sourceRoot":"","sources":["../src/epochTracker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAmB,WAAW,EAAqB,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAClE,OAAO,EAGH,MAAM,EACN,UAAU,EACV,eAAe,EAElB,MAAM,yCAAyC,CAAC;AAGjD,OAAO,EAA0E,aAAa,EAAE,MAAM,aAAa,CAAC;AACpH,OAAO,EACH,UAAU,EACV,mBAAmB,EACnB,mBAAmB,EACrB,MAAM,aAAa,CAAC;AAKtB,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;AAG3C,eAAO,MAAM,2BAA2B,EAAE,MAAgC,CAAC;AAE3E;;;;;GAKG;AACH,qBAAa,YAAa,YAAW,mBAAmB;IAQhD,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,eAAe;IACzC,SAAS,CAAC,QAAQ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