@fluidframework/odsp-driver 1.1.0 → 1.2.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/dist/checkUrl.d.ts +1 -1
- package/dist/checkUrl.js +1 -1
- package/dist/checkUrl.js.map +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/contractsPublic.d.ts +1 -0
- package/dist/contractsPublic.d.ts.map +1 -1
- package/dist/contractsPublic.js.map +1 -1
- package/dist/getFileLink.js +0 -4
- package/dist/getFileLink.js.map +1 -1
- package/dist/localOdspDriver/localOdspDocumentService.d.ts +26 -0
- package/dist/localOdspDriver/localOdspDocumentService.d.ts.map +1 -0
- package/dist/localOdspDriver/localOdspDocumentService.js +39 -0
- package/dist/localOdspDriver/localOdspDocumentService.js.map +1 -0
- package/dist/localOdspDriver/localOdspDocumentServiceFactory.d.ts +24 -0
- package/dist/localOdspDriver/localOdspDocumentServiceFactory.d.ts.map +1 -0
- package/dist/localOdspDriver/localOdspDocumentServiceFactory.js +45 -0
- package/dist/localOdspDriver/localOdspDocumentServiceFactory.js.map +1 -0
- package/dist/localOdspDriver/localOdspDocumentStorageManager.d.ts +27 -0
- package/dist/localOdspDriver/localOdspDocumentStorageManager.d.ts.map +1 -0
- package/dist/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
- package/dist/localOdspDriver/localOdspDocumentStorageManager.js.map +1 -0
- package/dist/odspDeltaStorageService.js.map +1 -1
- package/dist/odspDocumentService.d.ts.map +1 -1
- package/dist/odspDocumentService.js.map +1 -1
- package/dist/odspDocumentServiceFactory.d.ts +2 -1
- package/dist/odspDocumentServiceFactory.d.ts.map +1 -1
- package/dist/odspDocumentServiceFactory.js +7 -1
- package/dist/odspDocumentServiceFactory.js.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.d.ts +3 -1
- package/dist/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.js.map +1 -1
- package/dist/odspDocumentStorageManager.d.ts +5 -23
- package/dist/odspDocumentStorageManager.d.ts.map +1 -1
- package/dist/odspDocumentStorageManager.js +52 -245
- package/dist/odspDocumentStorageManager.js.map +1 -1
- package/dist/odspDocumentStorageServiceBase.d.ts +58 -0
- package/dist/odspDocumentStorageServiceBase.d.ts.map +1 -0
- package/dist/odspDocumentStorageServiceBase.js +216 -0
- package/dist/odspDocumentStorageServiceBase.js.map +1 -0
- package/dist/odspDriverUrlResolver.js +1 -1
- package/dist/odspDriverUrlResolver.js.map +1 -1
- package/dist/odspDriverUrlResolverForShareLink.d.ts +8 -2
- package/dist/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
- package/dist/odspDriverUrlResolverForShareLink.js +11 -3
- package/dist/odspDriverUrlResolverForShareLink.js.map +1 -1
- package/dist/odspFluidFileLink.d.ts.map +1 -1
- package/dist/odspFluidFileLink.js +27 -21
- package/dist/odspFluidFileLink.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/checkUrl.d.ts +1 -1
- package/lib/checkUrl.js +1 -1
- package/lib/checkUrl.js.map +1 -1
- package/lib/constants.d.ts +1 -1
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +1 -1
- package/lib/constants.js.map +1 -1
- package/lib/contractsPublic.d.ts +1 -0
- package/lib/contractsPublic.d.ts.map +1 -1
- package/lib/contractsPublic.js.map +1 -1
- package/lib/getFileLink.js +0 -4
- package/lib/getFileLink.js.map +1 -1
- package/lib/localOdspDriver/localOdspDocumentService.d.ts +26 -0
- package/lib/localOdspDriver/localOdspDocumentService.d.ts.map +1 -0
- package/lib/localOdspDriver/localOdspDocumentService.js +35 -0
- package/lib/localOdspDriver/localOdspDocumentService.js.map +1 -0
- package/lib/localOdspDriver/localOdspDocumentServiceFactory.d.ts +24 -0
- package/lib/localOdspDriver/localOdspDocumentServiceFactory.d.ts.map +1 -0
- package/lib/localOdspDriver/localOdspDocumentServiceFactory.js +41 -0
- package/lib/localOdspDriver/localOdspDocumentServiceFactory.js.map +1 -0
- package/lib/localOdspDriver/localOdspDocumentStorageManager.d.ts +27 -0
- package/lib/localOdspDriver/localOdspDocumentStorageManager.d.ts.map +1 -0
- package/lib/localOdspDriver/localOdspDocumentStorageManager.js +62 -0
- package/lib/localOdspDriver/localOdspDocumentStorageManager.js.map +1 -0
- package/lib/odspDeltaStorageService.js.map +1 -1
- package/lib/odspDocumentService.d.ts.map +1 -1
- package/lib/odspDocumentService.js +1 -1
- package/lib/odspDocumentService.js.map +1 -1
- package/lib/odspDocumentServiceFactory.d.ts +2 -1
- package/lib/odspDocumentServiceFactory.d.ts.map +1 -1
- package/lib/odspDocumentServiceFactory.js +5 -0
- package/lib/odspDocumentServiceFactory.js.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.d.ts +3 -1
- package/lib/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.js.map +1 -1
- package/lib/odspDocumentStorageManager.d.ts +5 -23
- package/lib/odspDocumentStorageManager.d.ts.map +1 -1
- package/lib/odspDocumentStorageManager.js +53 -246
- package/lib/odspDocumentStorageManager.js.map +1 -1
- package/lib/odspDocumentStorageServiceBase.d.ts +58 -0
- package/lib/odspDocumentStorageServiceBase.d.ts.map +1 -0
- package/lib/odspDocumentStorageServiceBase.js +212 -0
- package/lib/odspDocumentStorageServiceBase.js.map +1 -0
- package/lib/odspDriverUrlResolver.js +1 -1
- package/lib/odspDriverUrlResolver.js.map +1 -1
- package/lib/odspDriverUrlResolverForShareLink.d.ts +8 -2
- package/lib/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
- package/lib/odspDriverUrlResolverForShareLink.js +11 -3
- package/lib/odspDriverUrlResolverForShareLink.js.map +1 -1
- package/lib/odspFluidFileLink.d.ts.map +1 -1
- package/lib/odspFluidFileLink.js +27 -21
- package/lib/odspFluidFileLink.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 +17 -12
- package/src/checkUrl.ts +1 -1
- package/src/constants.ts +1 -1
- package/src/contractsPublic.ts +1 -0
- package/src/getFileLink.ts +0 -5
- package/src/localOdspDriver/localOdspDocumentService.ts +54 -0
- package/src/localOdspDriver/localOdspDocumentServiceFactory.ts +67 -0
- package/src/localOdspDriver/localOdspDocumentStorageManager.ts +83 -0
- package/src/odspDeltaStorageService.ts +1 -1
- package/src/odspDocumentService.ts +5 -1
- package/src/odspDocumentServiceFactory.ts +7 -3
- package/src/odspDocumentServiceFactoryCore.ts +1 -1
- package/src/odspDocumentStorageManager.ts +81 -312
- package/src/odspDocumentStorageServiceBase.ts +268 -0
- package/src/odspDriverUrlResolver.ts +1 -1
- package/src/odspDriverUrlResolverForShareLink.ts +13 -1
- package/src/odspFluidFileLink.ts +26 -22
- package/src/packageVersion.ts +1 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { IDocumentStorageService, ISummaryContext, LoaderCachingPolicy } from "@fluidframework/driver-definitions";
|
|
6
|
+
import * as api from "@fluidframework/protocol-definitions";
|
|
7
|
+
import { ISnapshotContents } from "./odspPublicUtils";
|
|
8
|
+
declare class BlobCache {
|
|
9
|
+
private blobCacheTimeout;
|
|
10
|
+
private deferBlobCacheClear;
|
|
11
|
+
private readonly _blobCache;
|
|
12
|
+
private readonly blobsEvicted;
|
|
13
|
+
private blobCacheTimeoutDuration;
|
|
14
|
+
private readonly purgeEnabled;
|
|
15
|
+
get value(): Map<string, ArrayBuffer>;
|
|
16
|
+
addBlobs(blobs: Map<string, ArrayBuffer>): void;
|
|
17
|
+
/**
|
|
18
|
+
* Schedule a timer for clearing the blob cache or defer the current one.
|
|
19
|
+
*/
|
|
20
|
+
private scheduleClearBlobsCache;
|
|
21
|
+
getBlob(blobId: string): {
|
|
22
|
+
blobContent: ArrayBuffer | undefined;
|
|
23
|
+
evicted: boolean;
|
|
24
|
+
};
|
|
25
|
+
setBlob(blobId: string, blob: ArrayBuffer): Map<string, ArrayBuffer> | undefined;
|
|
26
|
+
}
|
|
27
|
+
export declare abstract class OdspDocumentStorageServiceBase implements IDocumentStorageService {
|
|
28
|
+
readonly policies: {
|
|
29
|
+
caching: LoaderCachingPolicy;
|
|
30
|
+
minBlobSize: number;
|
|
31
|
+
maximumCacheDurationMs: number;
|
|
32
|
+
};
|
|
33
|
+
protected readonly commitCache: Map<string, api.ISnapshotTree>;
|
|
34
|
+
private readonly attributesBlobHandles;
|
|
35
|
+
private _ops;
|
|
36
|
+
private _snapshotSequenceNumber;
|
|
37
|
+
protected readonly blobCache: BlobCache;
|
|
38
|
+
set ops(ops: api.ISequencedDocumentMessage[] | undefined);
|
|
39
|
+
get ops(): api.ISequencedDocumentMessage[] | undefined;
|
|
40
|
+
get snapshotSequenceNumber(): number | undefined;
|
|
41
|
+
get repositoryUrl(): string;
|
|
42
|
+
abstract createBlob(file: ArrayBufferLike): Promise<api.ICreateBlobResponse>;
|
|
43
|
+
private readBlobCore;
|
|
44
|
+
protected abstract fetchBlobFromStorage(blobId: string, evicted: boolean): Promise<ArrayBuffer>;
|
|
45
|
+
readBlob(blobId: string): Promise<ArrayBufferLike>;
|
|
46
|
+
getSnapshotTree(version?: api.IVersion, scenarioName?: string): Promise<api.ISnapshotTree | null>;
|
|
47
|
+
abstract getVersions(blobid: string | null, count: number, scenarioName?: string): Promise<api.IVersion[]>;
|
|
48
|
+
abstract uploadSummaryWithContext(summary: api.ISummaryTree, context: ISummaryContext): Promise<string>;
|
|
49
|
+
downloadSummary(commit: api.ISummaryHandle): Promise<api.ISummaryTree>;
|
|
50
|
+
protected setRootTree(id: string, tree: api.ISnapshotTree): void;
|
|
51
|
+
protected initBlobsCache(blobs: Map<string, ArrayBuffer>): void;
|
|
52
|
+
private readTree;
|
|
53
|
+
protected abstract fetchTreeFromSnapshot(id: string, scenarioName?: string): Promise<api.ISnapshotTree | undefined>;
|
|
54
|
+
private combineProtocolAndAppSnapshotTree;
|
|
55
|
+
protected initializeFromSnapshot(odspSnapshotCacheValue: ISnapshotContents): string | undefined;
|
|
56
|
+
}
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=odspDocumentStorageServiceBase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"odspDocumentStorageServiceBase.d.ts","sourceRoot":"","sources":["../src/odspDocumentStorageServiceBase.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACnH,OAAO,KAAK,GAAG,MAAM,sCAAsC,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAItD,cAAM,SAAS;IAEX,OAAO,CAAC,gBAAgB,CAA4C;IAIpE,OAAO,CAAC,mBAAmB,CAAkB;IAE7C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuC;IAGlE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA0B;IAKvD,OAAO,CAAC,wBAAwB,CAAiB;IAMjD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IAEtC,IAAW,KAAK,6BAEf;IAEM,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC;IAQ/C;;OAEG;IACH,OAAO,CAAC,uBAAuB;IA8BxB,OAAO,CAAC,MAAM,EAAE,MAAM;;;;IAQtB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW;CAiBnD;AAED,8BAAsB,8BAA+B,YAAW,uBAAuB;IACnF,QAAQ,CAAC,QAAQ;;;;MAgBf;IAEF,SAAS,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;IAInF,SAAS,CAAC,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,aAAa;IAIzD,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC;YAI1C,QAAQ;IAStB,SAAS,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,GAAG,SAAS,CAAC;IAEnH,OAAO,CAAC,iCAAiC;IAmBzC,SAAS,CAAC,sBAAsB,CAAC,sBAAsB,EAAE,iBAAiB,GAAG,MAAM,GAAG,SAAS;CAmBlG"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { assert } from "@fluidframework/common-utils";
|
|
6
|
+
import { LoaderCachingPolicy } from "@fluidframework/driver-definitions";
|
|
7
|
+
import { defaultCacheExpiryTimeoutMs } from "./epochTracker";
|
|
8
|
+
/* eslint-disable max-len */
|
|
9
|
+
class BlobCache {
|
|
10
|
+
constructor() {
|
|
11
|
+
// If the defer flag is set when the timeout fires, we'll reschedule rather than clear immediately
|
|
12
|
+
// This deferral approach is used (rather than clearing/resetting the timer) as current calling patterns trigger
|
|
13
|
+
// too many calls to setTimeout/clearTimeout.
|
|
14
|
+
this.deferBlobCacheClear = false;
|
|
15
|
+
this._blobCache = new Map();
|
|
16
|
+
// Tracks all blob IDs evicted from cache
|
|
17
|
+
this.blobsEvicted = new Set();
|
|
18
|
+
// Initial time-out to purge data from cache
|
|
19
|
+
// If this time out is very small, then we purge blobs from cache too soon and that results in a lot of
|
|
20
|
+
// requests to storage, which brings down perf and may trip protection limits causing 429s
|
|
21
|
+
this.blobCacheTimeoutDuration = 2 * 60 * 1000;
|
|
22
|
+
// SPO does not keep old snapshots around for long, so we are running chances of not
|
|
23
|
+
// being able to rehydrate data store / DDS in the future if we purge anything (and with blob de-duping,
|
|
24
|
+
// even if blob read by runtime, it could be read again in the future)
|
|
25
|
+
// So for now, purging is disabled.
|
|
26
|
+
this.purgeEnabled = false;
|
|
27
|
+
}
|
|
28
|
+
get value() {
|
|
29
|
+
return this._blobCache;
|
|
30
|
+
}
|
|
31
|
+
addBlobs(blobs) {
|
|
32
|
+
blobs.forEach((value, blobId) => {
|
|
33
|
+
this._blobCache.set(blobId, value);
|
|
34
|
+
});
|
|
35
|
+
// Reset the timer on cache set
|
|
36
|
+
this.scheduleClearBlobsCache();
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Schedule a timer for clearing the blob cache or defer the current one.
|
|
40
|
+
*/
|
|
41
|
+
scheduleClearBlobsCache() {
|
|
42
|
+
if (this.blobCacheTimeout !== undefined) {
|
|
43
|
+
// If we already have an outstanding timer, just signal that we should defer the clear
|
|
44
|
+
this.deferBlobCacheClear = true;
|
|
45
|
+
}
|
|
46
|
+
else if (this.purgeEnabled) {
|
|
47
|
+
// If we don't have an outstanding timer, set a timer
|
|
48
|
+
// When the timer runs out, we'll decide whether to proceed with the cache clear or reset the timer
|
|
49
|
+
const clearCacheOrDefer = () => {
|
|
50
|
+
this.blobCacheTimeout = undefined;
|
|
51
|
+
if (this.deferBlobCacheClear) {
|
|
52
|
+
this.deferBlobCacheClear = false;
|
|
53
|
+
this.scheduleClearBlobsCache();
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// NOTE: Slightly better algorithm here would be to purge either only big blobs,
|
|
57
|
+
// or sort them by size and purge enough big blobs to leave only 256Kb of small blobs in cache
|
|
58
|
+
// Purging is optimizing memory footprint. But count controls potential number of storage requests
|
|
59
|
+
// We want to optimize both - memory footprint and number of future requests to storage.
|
|
60
|
+
// Note that Container can realize data store or DDS on-demand at any point in time, so we do not
|
|
61
|
+
// control when blobs will be used.
|
|
62
|
+
this._blobCache.forEach((_, blobId) => this.blobsEvicted.add(blobId));
|
|
63
|
+
this._blobCache.clear();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
this.blobCacheTimeout = setTimeout(clearCacheOrDefer, this.blobCacheTimeoutDuration);
|
|
67
|
+
// any future storage reads that get into the cache should be cleared from cache rather quickly -
|
|
68
|
+
// there is not much value in keeping them longer
|
|
69
|
+
this.blobCacheTimeoutDuration = 10 * 1000;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
getBlob(blobId) {
|
|
73
|
+
// Reset the timer on attempted cache read
|
|
74
|
+
this.scheduleClearBlobsCache();
|
|
75
|
+
const blobContent = this._blobCache.get(blobId);
|
|
76
|
+
const evicted = this.blobsEvicted.has(blobId);
|
|
77
|
+
return { blobContent, evicted };
|
|
78
|
+
}
|
|
79
|
+
setBlob(blobId, blob) {
|
|
80
|
+
// This API is called as result of cache miss and reading blob from storage.
|
|
81
|
+
// Runtime never reads same blob twice.
|
|
82
|
+
// The only reason we may get read request for same blob is blob de-duping in summaries.
|
|
83
|
+
// Note that the bigger the size, the less likely blobs are the same, so there is very little benefit of caching big blobs.
|
|
84
|
+
// Images are the only exception - user may insert same image twice. But we currently do not de-dup them - only snapshot
|
|
85
|
+
// blobs are de-duped.
|
|
86
|
+
const size = blob.byteLength;
|
|
87
|
+
if (size < 256 * 1024) {
|
|
88
|
+
// Reset the timer on cache set
|
|
89
|
+
this.scheduleClearBlobsCache();
|
|
90
|
+
return this._blobCache.set(blobId, blob);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// we evicted it here by not caching.
|
|
94
|
+
this.blobsEvicted.add(blobId);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export class OdspDocumentStorageServiceBase {
|
|
99
|
+
constructor() {
|
|
100
|
+
this.policies = {
|
|
101
|
+
// By default, ODSP tells the container not to prefetch/cache.
|
|
102
|
+
caching: LoaderCachingPolicy.NoCaching,
|
|
103
|
+
// ODSP storage works better if it has less number of blobs / edges
|
|
104
|
+
// Runtime creating many small blobs results in sub-optimal perf.
|
|
105
|
+
// 2K seems like the sweat spot:
|
|
106
|
+
// The smaller the number, less blobs we aggregate. Most storages are very likely to have notion
|
|
107
|
+
// of minimal "cluster" size, so having small blobs is wasteful
|
|
108
|
+
// At the same time increasing the limit ensure that more blobs with user content are aggregated,
|
|
109
|
+
// reducing possibility for de-duping of same blobs (i.e. .attributes rolled into aggregate blob
|
|
110
|
+
// are not reused across data stores, or even within data store, resulting in duplication of content)
|
|
111
|
+
// Note that duplication of content should not have significant impact for bytes over wire as
|
|
112
|
+
// compression of http payload mostly takes care of it, but it does impact storage size and in-memory sizes.
|
|
113
|
+
minBlobSize: 2048,
|
|
114
|
+
maximumCacheDurationMs: defaultCacheExpiryTimeoutMs,
|
|
115
|
+
};
|
|
116
|
+
this.commitCache = new Map();
|
|
117
|
+
this.attributesBlobHandles = new Set();
|
|
118
|
+
this.blobCache = new BlobCache();
|
|
119
|
+
}
|
|
120
|
+
set ops(ops) {
|
|
121
|
+
assert(this._ops === undefined, 0x0a5 /* "Trying to set ops when they are already set!" */);
|
|
122
|
+
this._ops = ops;
|
|
123
|
+
}
|
|
124
|
+
get ops() {
|
|
125
|
+
return this._ops;
|
|
126
|
+
}
|
|
127
|
+
get snapshotSequenceNumber() {
|
|
128
|
+
return this._snapshotSequenceNumber;
|
|
129
|
+
}
|
|
130
|
+
get repositoryUrl() {
|
|
131
|
+
return "";
|
|
132
|
+
}
|
|
133
|
+
async readBlobCore(blobId) {
|
|
134
|
+
const { blobContent, evicted } = this.blobCache.getBlob(blobId);
|
|
135
|
+
return blobContent !== null && blobContent !== void 0 ? blobContent : this.fetchBlobFromStorage(blobId, evicted);
|
|
136
|
+
}
|
|
137
|
+
async readBlob(blobId) {
|
|
138
|
+
return this.readBlobCore(blobId);
|
|
139
|
+
}
|
|
140
|
+
async getSnapshotTree(version, scenarioName) {
|
|
141
|
+
let id;
|
|
142
|
+
if (!version || !version.id) {
|
|
143
|
+
const versions = await this.getVersions(null, 1, scenarioName);
|
|
144
|
+
if (!versions || versions.length === 0) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
id = versions[0].id;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
id = version.id;
|
|
151
|
+
}
|
|
152
|
+
const snapshotTree = await this.readTree(id, scenarioName);
|
|
153
|
+
if (!snapshotTree) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
if (snapshotTree.blobs) {
|
|
157
|
+
const attributesBlob = snapshotTree.blobs.attributes;
|
|
158
|
+
if (attributesBlob) {
|
|
159
|
+
this.attributesBlobHandles.add(attributesBlob);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// When we upload the container snapshot, we upload appTree in ".app" and protocol tree in ".protocol"
|
|
163
|
+
// So when we request the snapshot we get ".app" as tree and not as commit node as in the case just above.
|
|
164
|
+
const appTree = snapshotTree.trees[".app"];
|
|
165
|
+
const protocolTree = snapshotTree.trees[".protocol"];
|
|
166
|
+
return this.combineProtocolAndAppSnapshotTree(appTree, protocolTree);
|
|
167
|
+
}
|
|
168
|
+
async downloadSummary(commit) {
|
|
169
|
+
throw new Error("Not implemented yet");
|
|
170
|
+
}
|
|
171
|
+
setRootTree(id, tree) {
|
|
172
|
+
this.commitCache.set(id, tree);
|
|
173
|
+
}
|
|
174
|
+
initBlobsCache(blobs) {
|
|
175
|
+
this.blobCache.addBlobs(blobs);
|
|
176
|
+
}
|
|
177
|
+
async readTree(id, scenarioName) {
|
|
178
|
+
let tree = this.commitCache.get(id);
|
|
179
|
+
if (!tree) {
|
|
180
|
+
tree = await this.fetchTreeFromSnapshot(id, scenarioName);
|
|
181
|
+
}
|
|
182
|
+
return tree !== null && tree !== void 0 ? tree : null;
|
|
183
|
+
}
|
|
184
|
+
combineProtocolAndAppSnapshotTree(hierarchicalAppTree, hierarchicalProtocolTree) {
|
|
185
|
+
const summarySnapshotTree = {
|
|
186
|
+
blobs: Object.assign({}, hierarchicalAppTree.blobs),
|
|
187
|
+
trees: Object.assign(Object.assign({}, hierarchicalAppTree.trees), {
|
|
188
|
+
// the app tree could have a .protocol
|
|
189
|
+
// in that case we want to server protocol to override it
|
|
190
|
+
".protocol": hierarchicalProtocolTree }),
|
|
191
|
+
};
|
|
192
|
+
return summarySnapshotTree;
|
|
193
|
+
}
|
|
194
|
+
initializeFromSnapshot(odspSnapshotCacheValue) {
|
|
195
|
+
this._snapshotSequenceNumber = odspSnapshotCacheValue.sequenceNumber;
|
|
196
|
+
const { snapshotTree, blobs, ops } = odspSnapshotCacheValue;
|
|
197
|
+
// id should be undefined in case of just ops in snapshot.
|
|
198
|
+
let id;
|
|
199
|
+
if (snapshotTree) {
|
|
200
|
+
id = snapshotTree.id;
|
|
201
|
+
assert(id !== undefined, 0x221 /* "Root tree should contain the id" */);
|
|
202
|
+
this.setRootTree(id, snapshotTree);
|
|
203
|
+
}
|
|
204
|
+
if (blobs) {
|
|
205
|
+
this.initBlobsCache(blobs);
|
|
206
|
+
}
|
|
207
|
+
this.ops = ops;
|
|
208
|
+
return id;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/* eslint-enable max-len */
|
|
212
|
+
//# sourceMappingURL=odspDocumentStorageServiceBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"odspDocumentStorageServiceBase.js","sourceRoot":"","sources":["../src/odspDocumentStorageServiceBase.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAA4C,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEnH,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAG7D,4BAA4B;AAE5B,MAAM,SAAS;IAAf;QAGI,kGAAkG;QAClG,gHAAgH;QAChH,6CAA6C;QACrC,wBAAmB,GAAY,KAAK,CAAC;QAE5B,eAA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AAI,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,EAAE;YACP,IAAI,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC;SAC7D;QAED,OAAO,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,IAAI,CAAC;IACxB,CAAC;IAIO,iCAAiC,CACrC,mBAAsC,EACtC,wBAA2C;QAE3C,MAAM,mBAAmB,GAAsB;YAC3C,KAAK,oBACE,mBAAmB,CAAC,KAAK,CAC/B;YACD,KAAK,kCACE,mBAAmB,CAAC,KAAK;gBAC5B,sCAAsC;gBACtC,yDAAyD;gBACzD,WAAW,EAAE,wBAAwB,GACxC;SACJ,CAAC;QAEF,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAES,sBAAsB,CAAC,sBAAyC;QACtE,IAAI,CAAC,uBAAuB,GAAG,sBAAsB,CAAC,cAAc,CAAC;QACrE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,sBAAsB,CAAC;QAE5D,0DAA0D;QAC1D,IAAI,EAAsB,CAAC;QAC3B,IAAI,YAAY,EAAE;YACd,EAAE,GAAG,YAAY,CAAC,EAAE,CAAC;YACrB,MAAM,CAAC,EAAE,KAAK,SAAS,EAAE,KAAK,CAAC,uCAAuC,CAAC,CAAC;YACxE,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC;SACtC;QAED,IAAI,KAAK,EAAE;YACP,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;SAC9B;QAED,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,OAAO,EAAE,CAAC;IACd,CAAC;CACJ;AAED,2BAA2B","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 { IDocumentStorageService, ISummaryContext, LoaderCachingPolicy } from \"@fluidframework/driver-definitions\";\nimport * as api from \"@fluidframework/protocol-definitions\";\nimport { defaultCacheExpiryTimeoutMs } from \"./epochTracker\";\nimport { ISnapshotContents } from \"./odspPublicUtils\";\n\n/* eslint-disable max-len */\n\nclass BlobCache {\n // Save the timeout so we can cancel and reschedule it as needed\n private blobCacheTimeout: ReturnType<typeof setTimeout> | undefined;\n // If the defer flag is set when the timeout fires, we'll reschedule rather than clear immediately\n // This deferral approach is used (rather than clearing/resetting the timer) as current calling patterns trigger\n // too many calls to setTimeout/clearTimeout.\n private deferBlobCacheClear: boolean = false;\n\n private readonly _blobCache: Map<string, ArrayBuffer> = new Map();\n\n // Tracks all blob IDs evicted from cache\n private readonly blobsEvicted: Set<string> = new Set();\n\n // Initial time-out to purge data from cache\n // If this time out is very small, then we purge blobs from cache too soon and that results in a lot of\n // requests to storage, which brings down perf and may trip protection limits causing 429s\n private blobCacheTimeoutDuration = 2 * 60 * 1000;\n\n // SPO does not keep old snapshots around for long, so we are running chances of not\n // being able to rehydrate data store / DDS in the future if we purge anything (and with blob de-duping,\n // even if blob read by runtime, it could be read again in the future)\n // So for now, purging is disabled.\n private readonly purgeEnabled = false;\n\n public get value() {\n return this._blobCache;\n }\n\n public addBlobs(blobs: Map<string, ArrayBuffer>) {\n blobs.forEach((value, blobId) => {\n this._blobCache.set(blobId, value);\n });\n // Reset the timer on cache set\n this.scheduleClearBlobsCache();\n }\n\n /**\n * Schedule a timer for clearing the blob cache or defer the current one.\n */\n private scheduleClearBlobsCache() {\n if (this.blobCacheTimeout !== undefined) {\n // If we already have an outstanding timer, just signal that we should defer the clear\n this.deferBlobCacheClear = true;\n } else if (this.purgeEnabled) {\n // If we don't have an outstanding timer, set a timer\n // When the timer runs out, we'll decide whether to proceed with the cache clear or reset the timer\n const clearCacheOrDefer = () => {\n this.blobCacheTimeout = undefined;\n if (this.deferBlobCacheClear) {\n this.deferBlobCacheClear = false;\n this.scheduleClearBlobsCache();\n } else {\n // NOTE: Slightly better algorithm here would be to purge either only big blobs,\n // or sort them by size and purge enough big blobs to leave only 256Kb of small blobs in cache\n // Purging is optimizing memory footprint. But count controls potential number of storage requests\n // We want to optimize both - memory footprint and number of future requests to storage.\n // Note that Container can realize data store or DDS on-demand at any point in time, so we do not\n // control when blobs will be used.\n this._blobCache.forEach((_, blobId) => this.blobsEvicted.add(blobId));\n this._blobCache.clear();\n }\n };\n this.blobCacheTimeout = setTimeout(clearCacheOrDefer, this.blobCacheTimeoutDuration);\n // any future storage reads that get into the cache should be cleared from cache rather quickly -\n // there is not much value in keeping them longer\n this.blobCacheTimeoutDuration = 10 * 1000;\n }\n }\n\n public getBlob(blobId: string) {\n // Reset the timer on attempted cache read\n this.scheduleClearBlobsCache();\n const blobContent = this._blobCache.get(blobId);\n const evicted = this.blobsEvicted.has(blobId);\n return { blobContent, evicted };\n }\n\n public setBlob(blobId: string, blob: ArrayBuffer) {\n // This API is called as result of cache miss and reading blob from storage.\n // Runtime never reads same blob twice.\n // The only reason we may get read request for same blob is blob de-duping in summaries.\n // Note that the bigger the size, the less likely blobs are the same, so there is very little benefit of caching big blobs.\n // Images are the only exception - user may insert same image twice. But we currently do not de-dup them - only snapshot\n // blobs are de-duped.\n const size = blob.byteLength;\n if (size < 256 * 1024) {\n // Reset the timer on cache set\n this.scheduleClearBlobsCache();\n return this._blobCache.set(blobId, blob);\n } else {\n // we evicted it here by not caching.\n this.blobsEvicted.add(blobId);\n }\n }\n}\n\nexport abstract class OdspDocumentStorageServiceBase implements IDocumentStorageService {\n readonly policies = {\n // By default, ODSP tells the container not to prefetch/cache.\n caching: LoaderCachingPolicy.NoCaching,\n\n // ODSP storage works better if it has less number of blobs / edges\n // Runtime creating many small blobs results in sub-optimal perf.\n // 2K seems like the sweat spot:\n // The smaller the number, less blobs we aggregate. Most storages are very likely to have notion\n // of minimal \"cluster\" size, so having small blobs is wasteful\n // At the same time increasing the limit ensure that more blobs with user content are aggregated,\n // reducing possibility for de-duping of same blobs (i.e. .attributes rolled into aggregate blob\n // are not reused across data stores, or even within data store, resulting in duplication of content)\n // Note that duplication of content should not have significant impact for bytes over wire as\n // compression of http payload mostly takes care of it, but it does impact storage size and in-memory sizes.\n minBlobSize: 2048,\n maximumCacheDurationMs: defaultCacheExpiryTimeoutMs,\n };\n\n protected readonly commitCache: Map<string, api.ISnapshotTree> = new Map();\n\n private readonly attributesBlobHandles: Set<string> = new Set();\n\n private _ops: api.ISequencedDocumentMessage[] | undefined;\n\n private _snapshotSequenceNumber: number | undefined;\n\n protected readonly blobCache = new BlobCache();\n\n public set ops(ops: api.ISequencedDocumentMessage[] | undefined) {\n assert(this._ops === undefined, 0x0a5 /* \"Trying to set ops when they are already set!\" */);\n this._ops = ops;\n }\n\n public get ops(): api.ISequencedDocumentMessage[] | undefined {\n return this._ops;\n }\n\n public get snapshotSequenceNumber() {\n return this._snapshotSequenceNumber;\n }\n\n public get repositoryUrl(): string {\n return \"\";\n }\n\n public abstract createBlob(file: ArrayBufferLike): Promise<api.ICreateBlobResponse>;\n\n private async readBlobCore(blobId: string): Promise<ArrayBuffer> {\n const { blobContent, evicted } = this.blobCache.getBlob(blobId);\n return blobContent ?? this.fetchBlobFromStorage(blobId, evicted);\n }\n\n protected abstract fetchBlobFromStorage(blobId: string, evicted: boolean): Promise<ArrayBuffer>;\n\n public async readBlob(blobId: string): Promise<ArrayBufferLike> {\n return this.readBlobCore(blobId);\n }\n\n public async getSnapshotTree(version?: api.IVersion, scenarioName?: string): Promise<api.ISnapshotTree | null> {\n let id: string;\n if (!version || !version.id) {\n const versions = await this.getVersions(null, 1, scenarioName);\n if (!versions || versions.length === 0) {\n return null;\n }\n id = versions[0].id;\n } else {\n id = version.id;\n }\n\n const snapshotTree = await this.readTree(id, scenarioName);\n if (!snapshotTree) {\n return null;\n }\n\n if (snapshotTree.blobs) {\n const attributesBlob = snapshotTree.blobs.attributes;\n if (attributesBlob) {\n this.attributesBlobHandles.add(attributesBlob);\n }\n }\n\n // When we upload the container snapshot, we upload appTree in \".app\" and protocol tree in \".protocol\"\n // So when we request the snapshot we get \".app\" as tree and not as commit node as in the case just above.\n const appTree = snapshotTree.trees[\".app\"];\n const protocolTree = snapshotTree.trees[\".protocol\"];\n\n return this.combineProtocolAndAppSnapshotTree(appTree, protocolTree);\n }\n\n public abstract getVersions(blobid: string | null, count: number, scenarioName?: string): Promise<api.IVersion[]>;\n\n public abstract uploadSummaryWithContext(summary: api.ISummaryTree, context: ISummaryContext): Promise<string>;\n\n public async downloadSummary(commit: api.ISummaryHandle): Promise<api.ISummaryTree> {\n throw new Error(\"Not implemented yet\");\n }\n\n protected setRootTree(id: string, tree: api.ISnapshotTree) {\n this.commitCache.set(id, tree);\n }\n\n protected initBlobsCache(blobs: Map<string, ArrayBuffer>) {\n this.blobCache.addBlobs(blobs);\n }\n\n private async readTree(id: string, scenarioName?: string): Promise<api.ISnapshotTree | null> {\n let tree = this.commitCache.get(id);\n if (!tree) {\n tree = await this.fetchTreeFromSnapshot(id, scenarioName);\n }\n\n return tree ?? null;\n }\n\n protected abstract fetchTreeFromSnapshot(id: string, scenarioName?: string): Promise<api.ISnapshotTree | undefined>;\n\n private combineProtocolAndAppSnapshotTree(\n hierarchicalAppTree: api.ISnapshotTree,\n hierarchicalProtocolTree: api.ISnapshotTree,\n ) {\n const summarySnapshotTree: api.ISnapshotTree = {\n blobs: {\n ...hierarchicalAppTree.blobs,\n },\n trees: {\n ...hierarchicalAppTree.trees,\n // the app tree could have a .protocol\n // in that case we want to server protocol to override it\n \".protocol\": hierarchicalProtocolTree,\n },\n };\n\n return summarySnapshotTree;\n }\n\n protected initializeFromSnapshot(odspSnapshotCacheValue: ISnapshotContents): string | undefined {\n this._snapshotSequenceNumber = odspSnapshotCacheValue.sequenceNumber;\n const { snapshotTree, blobs, ops } = odspSnapshotCacheValue;\n\n // id should be undefined in case of just ops in snapshot.\n let id: string | undefined;\n if (snapshotTree) {\n id = snapshotTree.id;\n assert(id !== undefined, 0x221 /* \"Root tree should contain the id\" */);\n this.setRootTree(id, snapshotTree);\n }\n\n if (blobs) {\n this.initBlobsCache(blobs);\n }\n\n this.ops = ops;\n return id;\n }\n}\n\n/* eslint-enable max-len */\n"]}
|
|
@@ -89,7 +89,7 @@ export class OdspDriverUrlResolver {
|
|
|
89
89
|
fileName,
|
|
90
90
|
summarizer: false,
|
|
91
91
|
codeHint: {
|
|
92
|
-
containerPackageName: packageName ? packageName : undefined,
|
|
92
|
+
containerPackageName: packageName !== null && packageName !== void 0 ? packageName : undefined,
|
|
93
93
|
},
|
|
94
94
|
fileVersion: undefined,
|
|
95
95
|
shareLinkInfo,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspDriverUrlResolver.js","sourceRoot":"","sources":["../src/odspDriverUrlResolver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAEtD,OAAO,EACH,eAAe,EACf,YAAY,GAIf,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAoB,cAAc,EAAqB,MAAM,yCAAyC,CAAC;AAC9G,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,SAAS,UAAU,CAAC,OAAe,EAAE,OAAe,EAAE,MAAc,EAAE,WAAoB;IACtF,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IAC3C,MAAM,OAAO,GAAG,WAAW,CAAC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MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;KAC1D;IAED,IAAI,MAAM,KAAK,IAAI,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;KAC1D;IAED,IAAI,IAAI,KAAK,IAAI,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;KACtD;IAED,OAAO;QACH,OAAO;QACP,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC;QACpC,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC;QAClC,IAAI,EAAE,kBAAkB,CAAC,IAAI,CAAC;QAC9B,oBAAoB,EAAE,oBAAoB,CAAC,CAAC,CAAC,kBAAkB,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,SAAS;QACjG,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS;KACzE,CAAC;AACN,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { assert } from \"@fluidframework/common-utils\";\nimport { IRequest } from \"@fluidframework/core-interfaces\";\nimport {\n DriverErrorType,\n DriverHeader,\n IContainerPackageInfo,\n IResolvedUrl,\n IUrlResolver,\n} from \"@fluidframework/driver-definitions\";\nimport { IOdspResolvedUrl, ShareLinkTypes, ShareLinkInfoType } from \"@fluidframework/odsp-driver-definitions\";\nimport { NonRetryableError } from \"@fluidframework/driver-utils\";\nimport { createOdspUrl } from \"./createOdspUrl\";\nimport { getApiRoot } from \"./odspUrlHelper\";\nimport { getOdspResolvedUrl } from \"./odspUtils\";\nimport { getHashedDocumentId } from \"./odspPublicUtils\";\nimport { ClpCompliantAppHeader } from \"./contractsPublic\";\nimport { pkgVersion } from \"./packageVersion\";\n\nfunction getUrlBase(siteUrl: string, driveId: string, itemId: string, fileVersion?: string) {\n const siteOrigin = new URL(siteUrl).origin;\n const version = fileVersion ? `versions/${fileVersion}/` : \"\";\n return `${getApiRoot(siteOrigin)}/drives/${driveId}/items/${itemId}/${version}`;\n}\n\nfunction getSnapshotUrl(siteUrl: string, driveId: string, itemId: string, fileVersion?: string) {\n const urlBase = getUrlBase(siteUrl, driveId, itemId, fileVersion);\n return `${urlBase}opStream/snapshots`;\n}\n\nfunction getAttachmentPOSTUrl(siteUrl: string, driveId: string, itemId: string, fileVersion?: string) {\n const urlBase = getUrlBase(siteUrl, driveId, itemId, fileVersion);\n return `${urlBase}opStream/attachment`;\n}\n\nfunction getAttachmentGETUrl(siteUrl: string, driveId: string, itemId: string, fileVersion?: string) {\n const urlBase = getUrlBase(siteUrl, driveId, itemId, fileVersion);\n return `${urlBase}opStream/attachments`;\n}\n\nfunction getDeltaStorageUrl(siteUrl: string, driveId: string, itemId: string, fileVersion?: string) {\n const urlBase = getUrlBase(siteUrl, driveId, itemId, fileVersion);\n return `${urlBase}opStream`;\n}\n\n/**\n * Utility that enables us to handle paths provided with a beginning slash.\n * For example if a value of '/id1/id2' is provided, id1/id2 is returned.\n */\nfunction removeBeginningSlash(str: string): string {\n if (str.startsWith(\"/\")) {\n return str.substr(1);\n }\n\n return str;\n}\n\n/**\n * Resolver to resolve urls like the ones created by createOdspUrl which is driver inner\n * url format. Ex: `${siteUrl}?driveId=${driveId}&itemId=${itemId}&path=${path}`\n */\nexport class OdspDriverUrlResolver implements IUrlResolver {\n constructor() { }\n\n public async resolve(request: IRequest): Promise<IOdspResolvedUrl> {\n if (request.headers?.[DriverHeader.createNew]) {\n const [siteURL, queryString] = request.url.split(\"?\");\n\n const searchParams = new URLSearchParams(queryString);\n const fileName = request.headers[DriverHeader.createNew].fileName;\n const driveID = searchParams.get(\"driveId\");\n const filePath = searchParams.get(\"path\");\n const packageName = searchParams.get(\"containerPackageName\");\n const createLinkType = searchParams.get(\"createLinkType\");\n if (!(fileName && siteURL && driveID && filePath !== null && filePath !== undefined)) {\n throw new NonRetryableError(\n \"Proper new file params should be there!!\",\n DriverErrorType.genericError,\n { driverVersion: pkgVersion });\n }\n let shareLinkInfo: ShareLinkInfoType | undefined;\n if (createLinkType && createLinkType in ShareLinkTypes) {\n shareLinkInfo = {\n createLink: {\n type: ShareLinkTypes[createLinkType],\n },\n };\n }\n return {\n endpoints: {\n snapshotStorageUrl: \"\",\n attachmentGETStorageUrl: \"\",\n attachmentPOSTStorageUrl: \"\",\n deltaStorageUrl: \"\",\n },\n tokens: {},\n type: \"fluid\",\n odspResolvedUrl: true,\n id: \"odspCreateNew\",\n url: `fluid-odsp://${siteURL}?${queryString}&version=null`,\n siteUrl: siteURL,\n hashedDocumentId: \"\",\n driveId: driveID,\n itemId: \"\",\n fileName,\n summarizer: false,\n codeHint: {\n containerPackageName: packageName ? packageName : undefined,\n },\n fileVersion: undefined,\n shareLinkInfo,\n isClpCompliantApp: request.headers?.[ClpCompliantAppHeader.isClpCompliantApp],\n };\n }\n const { siteUrl, driveId, itemId, path, containerPackageName, fileVersion } = decodeOdspUrl(request.url);\n const hashedDocumentId = await getHashedDocumentId(driveId, itemId);\n assert(!hashedDocumentId.includes(\"/\"), 0x0a8 /* \"Docid should not contain slashes!!\" */);\n\n let documentUrl = `fluid-odsp://placeholder/placeholder/${hashedDocumentId}/${removeBeginningSlash(path)}`;\n\n if (request.url.length > 0) {\n // In case of any additional parameters add them back to the url\n const requestURL = new URL(request.url);\n const searchParams = requestURL.search;\n if (searchParams) {\n documentUrl += searchParams;\n }\n }\n\n const summarizer = !!request.headers?.[DriverHeader.summarizingClient];\n\n return {\n type: \"fluid\",\n odspResolvedUrl: true,\n endpoints: {\n snapshotStorageUrl: getSnapshotUrl(siteUrl, driveId, itemId, fileVersion),\n attachmentPOSTStorageUrl: getAttachmentPOSTUrl(siteUrl, driveId, itemId, fileVersion),\n attachmentGETStorageUrl: getAttachmentGETUrl(siteUrl, driveId, itemId, fileVersion),\n deltaStorageUrl: getDeltaStorageUrl(siteUrl, driveId, itemId, fileVersion),\n },\n id: hashedDocumentId,\n tokens: {},\n url: documentUrl,\n hashedDocumentId,\n siteUrl,\n driveId,\n itemId,\n fileName: \"\",\n summarizer,\n codeHint: {\n containerPackageName,\n },\n fileVersion,\n isClpCompliantApp: request.headers?.[ClpCompliantAppHeader.isClpCompliantApp],\n };\n }\n\n public async getAbsoluteUrl(\n resolvedUrl: IResolvedUrl,\n relativeUrl: string,\n packageInfoSource?: IContainerPackageInfo,\n ): Promise<string> {\n let dataStorePath = relativeUrl;\n if (dataStorePath.startsWith(\"/\")) {\n dataStorePath = dataStorePath.substr(1);\n }\n const odspResolvedUrl = getOdspResolvedUrl(resolvedUrl);\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 return createOdspUrl({\n ... odspResolvedUrl,\n containerPackageName,\n dataStorePath,\n });\n }\n}\n\nfunction decodeOdspUrl(url: string): {\n siteUrl: string;\n driveId: string;\n itemId: string;\n path: string;\n containerPackageName?: string;\n fileVersion?: string;\n} {\n const [siteUrl, queryString] = url.split(\"?\");\n\n const searchParams = new URLSearchParams(queryString);\n\n const driveId = searchParams.get(\"driveId\");\n const itemId = searchParams.get(\"itemId\");\n const path = searchParams.get(\"path\");\n const containerPackageName = searchParams.get(\"containerPackageName\");\n const fileVersion = searchParams.get(\"fileVersion\");\n\n if (driveId === null) {\n throw new Error(\"ODSP URL did not contain a drive id\");\n }\n\n if (itemId === null) {\n throw new Error(\"ODSP Url did not contain an item id\");\n }\n\n if (path === null) {\n throw new Error(\"ODSP Url did not contain a path\");\n }\n\n return {\n siteUrl,\n driveId: decodeURIComponent(driveId),\n itemId: decodeURIComponent(itemId),\n path: decodeURIComponent(path),\n containerPackageName: containerPackageName ? decodeURIComponent(containerPackageName) : undefined,\n fileVersion: fileVersion ? decodeURIComponent(fileVersion) : undefined,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"odspDriverUrlResolver.js","sourceRoot":"","sources":["../src/odspDriverUrlResolver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAEtD,OAAO,EACH,eAAe,EACf,YAAY,GAIf,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAoB,cAAc,EAAqB,MAAM,yCAAyC,CAAC;AAC9G,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,SAAS,UAAU,CAAC,OAAe,EAAE,OAAe,EAAE,MAAc,EAAE,WAAoB;IACtF,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IAC3C,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,YAAY,WAAW,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9D,OAAO,GAAG,UAAU,CAAC,UAAU,CAAC,WAAW,OAAO,UAAU,MAAM,IAAI,OAAO,EAAE,CAAC;AACpF,CAAC;AAED,SAAS,cAAc,CAAC,OAAe,EAAE,OAAe,E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C,CAAC;KACtD;IAED,OAAO;QACH,OAAO;QACP,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC;QACpC,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC;QAClC,IAAI,EAAE,kBAAkB,CAAC,IAAI,CAAC;QAC9B,oBAAoB,EAAE,oBAAoB,CAAC,CAAC,CAAC,kBAAkB,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,SAAS;QACjG,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS;KACzE,CAAC;AACN,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { assert } from \"@fluidframework/common-utils\";\nimport { IRequest } from \"@fluidframework/core-interfaces\";\nimport {\n DriverErrorType,\n DriverHeader,\n IContainerPackageInfo,\n IResolvedUrl,\n IUrlResolver,\n} from \"@fluidframework/driver-definitions\";\nimport { IOdspResolvedUrl, ShareLinkTypes, ShareLinkInfoType } from \"@fluidframework/odsp-driver-definitions\";\nimport { NonRetryableError } from \"@fluidframework/driver-utils\";\nimport { createOdspUrl } from \"./createOdspUrl\";\nimport { getApiRoot } from \"./odspUrlHelper\";\nimport { getOdspResolvedUrl } from \"./odspUtils\";\nimport { getHashedDocumentId } from \"./odspPublicUtils\";\nimport { ClpCompliantAppHeader } from \"./contractsPublic\";\nimport { pkgVersion } from \"./packageVersion\";\n\nfunction getUrlBase(siteUrl: string, driveId: string, itemId: string, fileVersion?: string) {\n const siteOrigin = new URL(siteUrl).origin;\n const version = fileVersion ? `versions/${fileVersion}/` : \"\";\n return `${getApiRoot(siteOrigin)}/drives/${driveId}/items/${itemId}/${version}`;\n}\n\nfunction getSnapshotUrl(siteUrl: string, driveId: string, itemId: string, fileVersion?: string) {\n const urlBase = getUrlBase(siteUrl, driveId, itemId, fileVersion);\n return `${urlBase}opStream/snapshots`;\n}\n\nfunction getAttachmentPOSTUrl(siteUrl: string, driveId: string, itemId: string, fileVersion?: string) {\n const urlBase = getUrlBase(siteUrl, driveId, itemId, fileVersion);\n return `${urlBase}opStream/attachment`;\n}\n\nfunction getAttachmentGETUrl(siteUrl: string, driveId: string, itemId: string, fileVersion?: string) {\n const urlBase = getUrlBase(siteUrl, driveId, itemId, fileVersion);\n return `${urlBase}opStream/attachments`;\n}\n\nfunction getDeltaStorageUrl(siteUrl: string, driveId: string, itemId: string, fileVersion?: string) {\n const urlBase = getUrlBase(siteUrl, driveId, itemId, fileVersion);\n return `${urlBase}opStream`;\n}\n\n/**\n * Utility that enables us to handle paths provided with a beginning slash.\n * For example if a value of '/id1/id2' is provided, id1/id2 is returned.\n */\nfunction removeBeginningSlash(str: string): string {\n if (str.startsWith(\"/\")) {\n return str.substr(1);\n }\n\n return str;\n}\n\n/**\n * Resolver to resolve urls like the ones created by createOdspUrl which is driver inner\n * url format. Ex: `${siteUrl}?driveId=${driveId}&itemId=${itemId}&path=${path}`\n */\nexport class OdspDriverUrlResolver implements IUrlResolver {\n constructor() { }\n\n public async resolve(request: IRequest): Promise<IOdspResolvedUrl> {\n if (request.headers?.[DriverHeader.createNew]) {\n const [siteURL, queryString] = request.url.split(\"?\");\n\n const searchParams = new URLSearchParams(queryString);\n const fileName = request.headers[DriverHeader.createNew].fileName;\n const driveID = searchParams.get(\"driveId\");\n const filePath = searchParams.get(\"path\");\n const packageName = searchParams.get(\"containerPackageName\");\n const createLinkType = searchParams.get(\"createLinkType\");\n if (!(fileName && siteURL && driveID && filePath !== null && filePath !== undefined)) {\n throw new NonRetryableError(\n \"Proper new file params should be there!!\",\n DriverErrorType.genericError,\n { driverVersion: pkgVersion });\n }\n let shareLinkInfo: ShareLinkInfoType | undefined;\n if (createLinkType && createLinkType in ShareLinkTypes) {\n shareLinkInfo = {\n createLink: {\n type: ShareLinkTypes[createLinkType],\n },\n };\n }\n return {\n endpoints: {\n snapshotStorageUrl: \"\",\n attachmentGETStorageUrl: \"\",\n attachmentPOSTStorageUrl: \"\",\n deltaStorageUrl: \"\",\n },\n tokens: {},\n type: \"fluid\",\n odspResolvedUrl: true,\n id: \"odspCreateNew\",\n url: `fluid-odsp://${siteURL}?${queryString}&version=null`,\n siteUrl: siteURL,\n hashedDocumentId: \"\",\n driveId: driveID,\n itemId: \"\",\n fileName,\n summarizer: false,\n codeHint: {\n containerPackageName: packageName ?? undefined,\n },\n fileVersion: undefined,\n shareLinkInfo,\n isClpCompliantApp: request.headers?.[ClpCompliantAppHeader.isClpCompliantApp],\n };\n }\n const { siteUrl, driveId, itemId, path, containerPackageName, fileVersion } = decodeOdspUrl(request.url);\n const hashedDocumentId = await getHashedDocumentId(driveId, itemId);\n assert(!hashedDocumentId.includes(\"/\"), 0x0a8 /* \"Docid should not contain slashes!!\" */);\n\n let documentUrl = `fluid-odsp://placeholder/placeholder/${hashedDocumentId}/${removeBeginningSlash(path)}`;\n\n if (request.url.length > 0) {\n // In case of any additional parameters add them back to the url\n const requestURL = new URL(request.url);\n const searchParams = requestURL.search;\n if (searchParams) {\n documentUrl += searchParams;\n }\n }\n\n const summarizer = !!request.headers?.[DriverHeader.summarizingClient];\n\n return {\n type: \"fluid\",\n odspResolvedUrl: true,\n endpoints: {\n snapshotStorageUrl: getSnapshotUrl(siteUrl, driveId, itemId, fileVersion),\n attachmentPOSTStorageUrl: getAttachmentPOSTUrl(siteUrl, driveId, itemId, fileVersion),\n attachmentGETStorageUrl: getAttachmentGETUrl(siteUrl, driveId, itemId, fileVersion),\n deltaStorageUrl: getDeltaStorageUrl(siteUrl, driveId, itemId, fileVersion),\n },\n id: hashedDocumentId,\n tokens: {},\n url: documentUrl,\n hashedDocumentId,\n siteUrl,\n driveId,\n itemId,\n fileName: \"\",\n summarizer,\n codeHint: {\n containerPackageName,\n },\n fileVersion,\n isClpCompliantApp: request.headers?.[ClpCompliantAppHeader.isClpCompliantApp],\n };\n }\n\n public async getAbsoluteUrl(\n resolvedUrl: IResolvedUrl,\n relativeUrl: string,\n packageInfoSource?: IContainerPackageInfo,\n ): Promise<string> {\n let dataStorePath = relativeUrl;\n if (dataStorePath.startsWith(\"/\")) {\n dataStorePath = dataStorePath.substr(1);\n }\n const odspResolvedUrl = getOdspResolvedUrl(resolvedUrl);\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 return createOdspUrl({\n ... odspResolvedUrl,\n containerPackageName,\n dataStorePath,\n });\n }\n}\n\nfunction decodeOdspUrl(url: string): {\n siteUrl: string;\n driveId: string;\n itemId: string;\n path: string;\n containerPackageName?: string;\n fileVersion?: string;\n} {\n const [siteUrl, queryString] = url.split(\"?\");\n\n const searchParams = new URLSearchParams(queryString);\n\n const driveId = searchParams.get(\"driveId\");\n const itemId = searchParams.get(\"itemId\");\n const path = searchParams.get(\"path\");\n const containerPackageName = searchParams.get(\"containerPackageName\");\n const fileVersion = searchParams.get(\"fileVersion\");\n\n if (driveId === null) {\n throw new Error(\"ODSP URL did not contain a drive id\");\n }\n\n if (itemId === null) {\n throw new Error(\"ODSP Url did not contain an item id\");\n }\n\n if (path === null) {\n throw new Error(\"ODSP Url did not contain a path\");\n }\n\n return {\n siteUrl,\n driveId: decodeURIComponent(driveId),\n itemId: decodeURIComponent(itemId),\n path: decodeURIComponent(path),\n containerPackageName: containerPackageName ? decodeURIComponent(containerPackageName) : undefined,\n fileVersion: fileVersion ? decodeURIComponent(fileVersion) : undefined,\n };\n}\n"]}
|
|
@@ -23,6 +23,7 @@ export interface ShareLinkFetcherProps {
|
|
|
23
23
|
*/
|
|
24
24
|
export declare class OdspDriverUrlResolverForShareLink implements IUrlResolver {
|
|
25
25
|
private readonly appName?;
|
|
26
|
+
private readonly getContext?;
|
|
26
27
|
private readonly logger;
|
|
27
28
|
private readonly sharingLinkCache;
|
|
28
29
|
private readonly shareLinkFetcherProps;
|
|
@@ -35,8 +36,10 @@ export declare class OdspDriverUrlResolverForShareLink implements IUrlResolver {
|
|
|
35
36
|
* @param appName - application name hint that is encoded with url produced by getAbsoluteUrl() method.
|
|
36
37
|
* This hint is used by link handling logic which determines which app to redirect to when user
|
|
37
38
|
* navigates directly to the link.
|
|
39
|
+
* @param getContext - callback function which is used to get context for given resolved url. If context
|
|
40
|
+
* is returned then it will be embedded into url returned by getAbsoluteUrl() method.
|
|
38
41
|
*/
|
|
39
|
-
constructor(shareLinkFetcherProps?: ShareLinkFetcherProps | undefined, logger?: ITelemetryBaseLogger, appName?: string | undefined);
|
|
42
|
+
constructor(shareLinkFetcherProps?: ShareLinkFetcherProps | undefined, logger?: ITelemetryBaseLogger, appName?: string | undefined, getContext?: ((resolvedUrl: IOdspResolvedUrl, dataStorePath: string) => Promise<string | undefined>) | undefined);
|
|
40
43
|
/**
|
|
41
44
|
* Takes an already generated data store url (from requestUrl) and appends a path to the
|
|
42
45
|
* existing data store information.
|
|
@@ -53,7 +56,9 @@ export declare class OdspDriverUrlResolverForShareLink implements IUrlResolver {
|
|
|
53
56
|
* Requests a driver + data store storage URL. Note that this method requires share link to be fetched
|
|
54
57
|
* and it will throw in case share link fetcher props were not specified when instance was created.
|
|
55
58
|
* @param resolvedUrl - The driver resolved URL
|
|
56
|
-
* @param
|
|
59
|
+
* @param dataStorePath - The relative data store path URL.
|
|
60
|
+
* For requesting a driver URL, this value should always be '/'
|
|
61
|
+
* @param packageInfoSource - optional, represents container package information to be included in url.
|
|
57
62
|
*/
|
|
58
63
|
getAbsoluteUrl(resolvedUrl: IResolvedUrl, dataStorePath: string, packageInfoSource?: IContainerPackageInfo): Promise<string>;
|
|
59
64
|
/**
|
|
@@ -62,6 +67,7 @@ export declare class OdspDriverUrlResolverForShareLink implements IUrlResolver {
|
|
|
62
67
|
static createDocumentUrl(baseUrl: string, driverInfo: OdspFluidDataStoreLocator): string;
|
|
63
68
|
/**
|
|
64
69
|
* Crafts a supported data store nav param
|
|
70
|
+
* @deprecated encodeOdspFluidDataStoreLocator should be used instead
|
|
65
71
|
*/
|
|
66
72
|
static createNavParam(locator: OdspFluidDataStoreLocator): string;
|
|
67
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspDriverUrlResolverForShareLink.d.ts","sourceRoot":"","sources":["../src/odspDriverUrlResolverForShareLink.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EACH,qBAAqB,EACrB,YAAY,EACZ,YAAY,EACf,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAoB,MAAM,oCAAoC,CAAC;AAC5F,OAAO,EACH,gBAAgB,EAChB,YAAY,EACZ,6BAA6B,EAC7B,YAAY,EACf,MAAM,yCAAyC,CAAC;AAOjD,OAAO,EAAE,yBAAyB,EAAqB,MAAM,mBAAmB,CAAC;AAMjF;;GAEG;AACH,MAAM,WAAW,qBAAqB;IAClC;;OAEG;IACH,YAAY,EAAE,YAAY,CAAC,6BAA6B,CAAC,CAAC;IAC1D;;OAEG;IACH,YAAY,EAAE,YAAY,CAAC;CAC9B;AAED;;;;GAIG;AACH,qBAAa,iCAAkC,YAAW,YAAY;
|
|
1
|
+
{"version":3,"file":"odspDriverUrlResolverForShareLink.d.ts","sourceRoot":"","sources":["../src/odspDriverUrlResolverForShareLink.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EACH,qBAAqB,EACrB,YAAY,EACZ,YAAY,EACf,MAAM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B,GAC1C,OAAO,CAAC,MAAM,CAAC;IAsClB;;OAEG;WACW,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB;IAQtF;;;OAGG;WACW,cAAc,CAAC,OAAO,EAAE,yBAAyB;CAGlE"}
|
|
@@ -24,9 +24,12 @@ export class OdspDriverUrlResolverForShareLink {
|
|
|
24
24
|
* @param appName - application name hint that is encoded with url produced by getAbsoluteUrl() method.
|
|
25
25
|
* This hint is used by link handling logic which determines which app to redirect to when user
|
|
26
26
|
* navigates directly to the link.
|
|
27
|
+
* @param getContext - callback function which is used to get context for given resolved url. If context
|
|
28
|
+
* is returned then it will be embedded into url returned by getAbsoluteUrl() method.
|
|
27
29
|
*/
|
|
28
|
-
constructor(shareLinkFetcherProps, logger, appName) {
|
|
30
|
+
constructor(shareLinkFetcherProps, logger, appName, getContext) {
|
|
29
31
|
this.appName = appName;
|
|
32
|
+
this.getContext = getContext;
|
|
30
33
|
this.sharingLinkCache = new PromiseCache();
|
|
31
34
|
this.logger = createOdspLogger(logger);
|
|
32
35
|
if (shareLinkFetcherProps) {
|
|
@@ -124,10 +127,12 @@ export class OdspDriverUrlResolverForShareLink {
|
|
|
124
127
|
* Requests a driver + data store storage URL. Note that this method requires share link to be fetched
|
|
125
128
|
* and it will throw in case share link fetcher props were not specified when instance was created.
|
|
126
129
|
* @param resolvedUrl - The driver resolved URL
|
|
127
|
-
* @param
|
|
130
|
+
* @param dataStorePath - The relative data store path URL.
|
|
131
|
+
* For requesting a driver URL, this value should always be '/'
|
|
132
|
+
* @param packageInfoSource - optional, represents container package information to be included in url.
|
|
128
133
|
*/
|
|
129
134
|
async getAbsoluteUrl(resolvedUrl, dataStorePath, packageInfoSource) {
|
|
130
|
-
var _a, _b, _c, _d;
|
|
135
|
+
var _a, _b, _c, _d, _e;
|
|
131
136
|
const odspResolvedUrl = getOdspResolvedUrl(resolvedUrl);
|
|
132
137
|
const shareLink = await this.getShareLinkPromise(odspResolvedUrl);
|
|
133
138
|
const shareLinkUrl = new URL(shareLink);
|
|
@@ -147,6 +152,7 @@ export class OdspDriverUrlResolverForShareLink {
|
|
|
147
152
|
containerPackageName = (_c = packageInfoSource) === null || _c === void 0 ? void 0 : _c.package;
|
|
148
153
|
}
|
|
149
154
|
containerPackageName = containerPackageName !== null && containerPackageName !== void 0 ? containerPackageName : (_d = odspResolvedUrl.codeHint) === null || _d === void 0 ? void 0 : _d.containerPackageName;
|
|
155
|
+
const context = await ((_e = this.getContext) === null || _e === void 0 ? void 0 : _e.call(this, odspResolvedUrl, dataStorePath));
|
|
150
156
|
storeLocatorInOdspUrl(shareLinkUrl, {
|
|
151
157
|
siteUrl: odspResolvedUrl.siteUrl,
|
|
152
158
|
driveId: odspResolvedUrl.driveId,
|
|
@@ -155,6 +161,7 @@ export class OdspDriverUrlResolverForShareLink {
|
|
|
155
161
|
appName: this.appName,
|
|
156
162
|
containerPackageName,
|
|
157
163
|
fileVersion: odspResolvedUrl.fileVersion,
|
|
164
|
+
context,
|
|
158
165
|
});
|
|
159
166
|
return shareLinkUrl.href;
|
|
160
167
|
}
|
|
@@ -168,6 +175,7 @@ export class OdspDriverUrlResolverForShareLink {
|
|
|
168
175
|
}
|
|
169
176
|
/**
|
|
170
177
|
* Crafts a supported data store nav param
|
|
178
|
+
* @deprecated encodeOdspFluidDataStoreLocator should be used instead
|
|
171
179
|
*/
|
|
172
180
|
static createNavParam(locator) {
|
|
173
181
|
return encodeOdspFluidDataStoreLocator(locator);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspDriverUrlResolverForShareLink.js","sourceRoot":"","sources":["../src/odspDriverUrlResolverForShareLink.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAc5D,OAAO,EACH,qBAAqB,EACrB,qBAAqB,EACrB,+BAA+B,EAC/B,qBAAqB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAA6B,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IAAI,iBAAiB,IAAI,MAAM,IAAI,iBAAiB,EAAE;YAClD,oBAAoB,GAAG,iBAAiB,CAAC,IAAI,CAAC;YAC9C,wGAAwG;SAC3G;aAAM,IAAI,cAAc,CAAC,MAAC,iBAAyB,0CAAE,OAAO,CAAC,EAAE;YAC5D,oBAAoB,GAAG,MAAC,iBAAyB,0CAAE,OAAO,CAAC,IAAI,CAAC;SACnE;aAAM;YACH,oBAAoB,GAAG,MAAC,iBAAyB,0CAAE,OAAO,CAAC;SAC9D;QACD,oBAAoB,GAAG,oBAAoB,aAApB,oBAAoB,cAApB,oBAAoB,GAAI,MAAA,eAAe,CAAC,QAAQ,0CAAE,oBAAoB,CAAC;QAE9F,qBAAqB,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,qBAAqB,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAEvC,OAAO,GAAG,CAAC,IAAI,CAAC;IACpB,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,cAAc,CAAC,OAAkC;QAC3D,OAAO,+BAA+B,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;CACJ","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
|
+
{"version":3,"file":"odspDriverUrlResolverForShareLink.js","sourceRoot":"","sources":["../src/odspDriverUrlResolverForShareLink.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CA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,IAAI,CAAC;IACpB,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,cAAc,CAAC,OAAkC;QAC3D,OAAO,+BAA+B,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;CACJ","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 * @param getContext - callback function which is used to get context for given resolved url. If context\n * is returned then it will be embedded into url returned by getAbsoluteUrl() method.\n */\n public constructor(\n shareLinkFetcherProps?: ShareLinkFetcherProps | undefined,\n logger?: ITelemetryBaseLogger,\n private readonly appName?: string,\n private readonly getContext?:\n (resolvedUrl: IOdspResolvedUrl, dataStorePath: string) => Promise<string | undefined>,\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 dataStorePath - The relative data store path URL.\n * For requesting a driver URL, this value should always be '/'\n * @param packageInfoSource - optional, represents container package information to be included in url.\n */\n public async getAbsoluteUrl(\n resolvedUrl: IResolvedUrl,\n dataStorePath: string,\n packageInfoSource?: IContainerPackageInfo,\n ): Promise<string> {\n const odspResolvedUrl = getOdspResolvedUrl(resolvedUrl);\n\n const shareLink = await this.getShareLinkPromise(odspResolvedUrl);\n const shareLinkUrl = new URL(shareLink);\n\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 const context = await this.getContext?.(odspResolvedUrl, dataStorePath);\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 context,\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 * @deprecated encodeOdspFluidDataStoreLocator should be used instead\n */\n public static createNavParam(locator: OdspFluidDataStoreLocator) {\n return encodeOdspFluidDataStoreLocator(locator);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspFluidFileLink.d.ts","sourceRoot":"","sources":["../src/odspFluidFileLink.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"odspFluidFileLink.d.ts","sourceRoot":"","sources":["../src/odspFluidFileLink.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAc9D;;;;GAIG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,yBAAyB,GAAG,MAAM,CAwB1F;AA2DD,eAAO,MAAM,qBAAqB,QAAQ,CAAC;AAE3C;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,yBAAyB,QAKjF;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,GAAG,GAAG,yBAAyB,GAAG,SAAS,CAYrF"}
|