@fluidframework/driver-utils 2.0.0-internal.3.0.2 → 2.0.0-internal.3.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.
Files changed (155) hide show
  1. package/.eslintrc.js +17 -19
  2. package/.mocharc.js +2 -2
  3. package/api-extractor.json +2 -2
  4. package/dist/blobAggregationStorage.d.ts +15 -2
  5. package/dist/blobAggregationStorage.d.ts.map +1 -1
  6. package/dist/blobAggregationStorage.js +22 -13
  7. package/dist/blobAggregationStorage.js.map +1 -1
  8. package/dist/blobCacheStorageService.d.ts.map +1 -1
  9. package/dist/blobCacheStorageService.js.map +1 -1
  10. package/dist/buildSnapshotTree.d.ts.map +1 -1
  11. package/dist/buildSnapshotTree.js.map +1 -1
  12. package/dist/documentStorageServiceProxy.d.ts.map +1 -1
  13. package/dist/documentStorageServiceProxy.js.map +1 -1
  14. package/dist/emptyDocumentDeltaStorageService.d.ts.map +1 -1
  15. package/dist/emptyDocumentDeltaStorageService.js.map +1 -1
  16. package/dist/error.d.ts.map +1 -1
  17. package/dist/error.js.map +1 -1
  18. package/dist/fluidResolvedUrl.d.ts.map +1 -1
  19. package/dist/fluidResolvedUrl.js.map +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/insecureUrlResolver.d.ts.map +1 -1
  24. package/dist/insecureUrlResolver.js +2 -1
  25. package/dist/insecureUrlResolver.js.map +1 -1
  26. package/dist/mapWithExpiration.d.ts.map +1 -1
  27. package/dist/mapWithExpiration.js +5 -3
  28. package/dist/mapWithExpiration.js.map +1 -1
  29. package/dist/messageRecognition.d.ts.map +1 -1
  30. package/dist/messageRecognition.js.map +1 -1
  31. package/dist/multiDocumentServiceFactory.d.ts.map +1 -1
  32. package/dist/multiDocumentServiceFactory.js.map +1 -1
  33. package/dist/multiUrlResolver.d.ts.map +1 -1
  34. package/dist/multiUrlResolver.js.map +1 -1
  35. package/dist/network.d.ts +1 -1
  36. package/dist/network.d.ts.map +1 -1
  37. package/dist/network.js +4 -3
  38. package/dist/network.js.map +1 -1
  39. package/dist/networkUtils.d.ts.map +1 -1
  40. package/dist/networkUtils.js +2 -3
  41. package/dist/networkUtils.js.map +1 -1
  42. package/dist/packageVersion.d.ts +1 -1
  43. package/dist/packageVersion.js +1 -1
  44. package/dist/packageVersion.js.map +1 -1
  45. package/dist/parallelRequests.d.ts.map +1 -1
  46. package/dist/parallelRequests.js +19 -9
  47. package/dist/parallelRequests.js.map +1 -1
  48. package/dist/prefetchDocumentStorageService.d.ts.map +1 -1
  49. package/dist/prefetchDocumentStorageService.js.map +1 -1
  50. package/dist/rateLimiter.d.ts.map +1 -1
  51. package/dist/rateLimiter.js.map +1 -1
  52. package/dist/readAndParse.d.ts.map +1 -1
  53. package/dist/readAndParse.js.map +1 -1
  54. package/dist/runWithRetry.d.ts.map +1 -1
  55. package/dist/runWithRetry.js.map +1 -1
  56. package/dist/summaryForCreateNew.d.ts.map +1 -1
  57. package/dist/summaryForCreateNew.js.map +1 -1
  58. package/dist/treeConversions.d.ts.map +1 -1
  59. package/dist/treeConversions.js +1 -4
  60. package/dist/treeConversions.js.map +1 -1
  61. package/dist/treeUtils.d.ts +10 -10
  62. package/dist/treeUtils.d.ts.map +1 -1
  63. package/dist/treeUtils.js +10 -10
  64. package/dist/treeUtils.js.map +1 -1
  65. package/lib/blobAggregationStorage.d.ts +15 -2
  66. package/lib/blobAggregationStorage.d.ts.map +1 -1
  67. package/lib/blobAggregationStorage.js +22 -13
  68. package/lib/blobAggregationStorage.js.map +1 -1
  69. package/lib/blobCacheStorageService.d.ts.map +1 -1
  70. package/lib/blobCacheStorageService.js.map +1 -1
  71. package/lib/buildSnapshotTree.d.ts.map +1 -1
  72. package/lib/buildSnapshotTree.js.map +1 -1
  73. package/lib/documentStorageServiceProxy.d.ts.map +1 -1
  74. package/lib/documentStorageServiceProxy.js.map +1 -1
  75. package/lib/emptyDocumentDeltaStorageService.d.ts.map +1 -1
  76. package/lib/emptyDocumentDeltaStorageService.js.map +1 -1
  77. package/lib/error.d.ts.map +1 -1
  78. package/lib/error.js.map +1 -1
  79. package/lib/fluidResolvedUrl.d.ts.map +1 -1
  80. package/lib/fluidResolvedUrl.js.map +1 -1
  81. package/lib/index.d.ts +1 -1
  82. package/lib/index.d.ts.map +1 -1
  83. package/lib/index.js +1 -1
  84. package/lib/index.js.map +1 -1
  85. package/lib/insecureUrlResolver.d.ts.map +1 -1
  86. package/lib/insecureUrlResolver.js +2 -1
  87. package/lib/insecureUrlResolver.js.map +1 -1
  88. package/lib/mapWithExpiration.d.ts.map +1 -1
  89. package/lib/mapWithExpiration.js +5 -3
  90. package/lib/mapWithExpiration.js.map +1 -1
  91. package/lib/messageRecognition.d.ts.map +1 -1
  92. package/lib/messageRecognition.js +1 -1
  93. package/lib/messageRecognition.js.map +1 -1
  94. package/lib/multiDocumentServiceFactory.d.ts.map +1 -1
  95. package/lib/multiDocumentServiceFactory.js.map +1 -1
  96. package/lib/multiUrlResolver.d.ts.map +1 -1
  97. package/lib/multiUrlResolver.js.map +1 -1
  98. package/lib/network.d.ts +1 -1
  99. package/lib/network.d.ts.map +1 -1
  100. package/lib/network.js +4 -3
  101. package/lib/network.js.map +1 -1
  102. package/lib/networkUtils.d.ts.map +1 -1
  103. package/lib/networkUtils.js +2 -3
  104. package/lib/networkUtils.js.map +1 -1
  105. package/lib/packageVersion.d.ts +1 -1
  106. package/lib/packageVersion.js +1 -1
  107. package/lib/packageVersion.js.map +1 -1
  108. package/lib/parallelRequests.d.ts.map +1 -1
  109. package/lib/parallelRequests.js +19 -9
  110. package/lib/parallelRequests.js.map +1 -1
  111. package/lib/prefetchDocumentStorageService.d.ts.map +1 -1
  112. package/lib/prefetchDocumentStorageService.js.map +1 -1
  113. package/lib/rateLimiter.d.ts.map +1 -1
  114. package/lib/rateLimiter.js.map +1 -1
  115. package/lib/readAndParse.d.ts.map +1 -1
  116. package/lib/readAndParse.js.map +1 -1
  117. package/lib/runWithRetry.d.ts.map +1 -1
  118. package/lib/runWithRetry.js.map +1 -1
  119. package/lib/summaryForCreateNew.d.ts.map +1 -1
  120. package/lib/summaryForCreateNew.js.map +1 -1
  121. package/lib/treeConversions.d.ts.map +1 -1
  122. package/lib/treeConversions.js +4 -7
  123. package/lib/treeConversions.js.map +1 -1
  124. package/lib/treeUtils.d.ts +10 -10
  125. package/lib/treeUtils.d.ts.map +1 -1
  126. package/lib/treeUtils.js +11 -11
  127. package/lib/treeUtils.js.map +1 -1
  128. package/package.json +43 -64
  129. package/prettier.config.cjs +1 -1
  130. package/src/blobAggregationStorage.ts +380 -324
  131. package/src/blobCacheStorageService.ts +20 -17
  132. package/src/buildSnapshotTree.ts +54 -51
  133. package/src/documentStorageServiceProxy.ts +49 -43
  134. package/src/emptyDocumentDeltaStorageService.ts +11 -10
  135. package/src/error.ts +5 -7
  136. package/src/fluidResolvedUrl.ts +9 -6
  137. package/src/index.ts +5 -1
  138. package/src/insecureUrlResolver.ts +127 -116
  139. package/src/mapWithExpiration.ts +111 -104
  140. package/src/messageRecognition.ts +25 -19
  141. package/src/multiDocumentServiceFactory.ts +73 -62
  142. package/src/multiUrlResolver.ts +26 -29
  143. package/src/network.ts +114 -112
  144. package/src/networkUtils.ts +37 -34
  145. package/src/packageVersion.ts +1 -1
  146. package/src/parallelRequests.ts +571 -509
  147. package/src/prefetchDocumentStorageService.ts +76 -74
  148. package/src/rateLimiter.ts +29 -29
  149. package/src/readAndParse.ts +7 -4
  150. package/src/runWithRetry.ts +105 -94
  151. package/src/summaryForCreateNew.ts +27 -24
  152. package/src/treeConversions.ts +48 -70
  153. package/src/treeUtils.ts +70 -74
  154. package/tsconfig.esnext.json +6 -6
  155. package/tsconfig.json +8 -12
@@ -3,30 +3,33 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { IDocumentStorageService, IDocumentStorageServicePolicies } from "@fluidframework/driver-definitions";
6
+ import {
7
+ IDocumentStorageService,
8
+ IDocumentStorageServicePolicies,
9
+ } from "@fluidframework/driver-definitions";
7
10
  import { DocumentStorageServiceProxy } from "./documentStorageServiceProxy";
8
11
 
9
12
  /**
10
13
  * IDocumentStorageService adapter with pre-cached blobs.
11
14
  */
12
15
  export class BlobCacheStorageService extends DocumentStorageServiceProxy {
13
- constructor(
14
- internalStorageService: IDocumentStorageService,
15
- private readonly blobs: Map<string, ArrayBufferLike>,
16
- ) {
17
- super(internalStorageService);
18
- }
16
+ constructor(
17
+ internalStorageService: IDocumentStorageService,
18
+ private readonly blobs: Map<string, ArrayBufferLike>,
19
+ ) {
20
+ super(internalStorageService);
21
+ }
19
22
 
20
- public get policies(): IDocumentStorageServicePolicies | undefined {
21
- return this.internalStorageService.policies;
22
- }
23
+ public get policies(): IDocumentStorageServicePolicies | undefined {
24
+ return this.internalStorageService.policies;
25
+ }
23
26
 
24
- public async readBlob(id: string): Promise<ArrayBufferLike> {
25
- const blob = this.blobs.get(id);
26
- if (blob !== undefined) {
27
- return blob;
28
- }
27
+ public async readBlob(id: string): Promise<ArrayBufferLike> {
28
+ const blob = this.blobs.get(id);
29
+ if (blob !== undefined) {
30
+ return blob;
31
+ }
29
32
 
30
- return this.internalStorageService.readBlob(id);
31
- }
33
+ return this.internalStorageService.readBlob(id);
34
+ }
32
35
  }
@@ -6,57 +6,60 @@
6
6
  import { assert, stringToBuffer } from "@fluidframework/common-utils";
7
7
  import * as git from "@fluidframework/gitresources";
8
8
  import {
9
- FileMode,
10
- ISnapshotTree,
11
- ITreeEntry,
12
- TreeEntry,
9
+ FileMode,
10
+ ISnapshotTree,
11
+ ITreeEntry,
12
+ TreeEntry,
13
13
  } from "@fluidframework/protocol-definitions";
14
14
  import { buildHierarchy } from "@fluidframework/protocol-base";
15
15
  import { v4 as uuid } from "uuid";
16
16
 
17
17
  function flattenCore(
18
- path: string,
19
- treeEntries: ITreeEntry[],
20
- blobMap: Map<string, ArrayBufferLike>,
18
+ path: string,
19
+ treeEntries: ITreeEntry[],
20
+ blobMap: Map<string, ArrayBufferLike>,
21
21
  ): git.ITreeEntry[] {
22
- const entries: git.ITreeEntry[] = [];
23
- for (const treeEntry of treeEntries) {
24
- const subPath = `${path}${treeEntry.path}`;
22
+ const entries: git.ITreeEntry[] = [];
23
+ for (const treeEntry of treeEntries) {
24
+ const subPath = `${path}${treeEntry.path}`;
25
25
 
26
- if (treeEntry.type === TreeEntry.Blob) {
27
- const blob = treeEntry.value;
28
- const buffer = stringToBuffer(blob.contents, blob.encoding);
29
- const id = uuid();
30
- blobMap.set(id, buffer);
26
+ if (treeEntry.type === TreeEntry.Blob) {
27
+ const blob = treeEntry.value;
28
+ const buffer = stringToBuffer(blob.contents, blob.encoding);
29
+ const id = uuid();
30
+ blobMap.set(id, buffer);
31
31
 
32
- const entry: git.ITreeEntry = {
33
- mode: FileMode[treeEntry.mode],
34
- path: subPath,
35
- sha: id,
36
- size: 0,
37
- type: "blob",
38
- url: "",
39
- };
40
- entries.push(entry);
41
- } else if (treeEntry.type === TreeEntry.Tree) {
42
- assert(treeEntry.type === TreeEntry.Tree, 0x101 /* "Unexpected tree entry type on flatten!" */);
43
- const t = treeEntry.value;
44
- const entry: git.ITreeEntry = {
45
- mode: FileMode[treeEntry.mode],
46
- path: subPath,
47
- sha: "",
48
- size: -1,
49
- type: "tree",
50
- url: "",
51
- };
52
- entries.push(entry);
32
+ const entry: git.ITreeEntry = {
33
+ mode: FileMode[treeEntry.mode],
34
+ path: subPath,
35
+ sha: id,
36
+ size: 0,
37
+ type: "blob",
38
+ url: "",
39
+ };
40
+ entries.push(entry);
41
+ } else if (treeEntry.type === TreeEntry.Tree) {
42
+ assert(
43
+ treeEntry.type === TreeEntry.Tree,
44
+ 0x101 /* "Unexpected tree entry type on flatten!" */,
45
+ );
46
+ const t = treeEntry.value;
47
+ const entry: git.ITreeEntry = {
48
+ mode: FileMode[treeEntry.mode],
49
+ path: subPath,
50
+ sha: "",
51
+ size: -1,
52
+ type: "tree",
53
+ url: "",
54
+ };
55
+ entries.push(entry);
53
56
 
54
- const subTreeEntries = flattenCore(`${subPath}/`, t.entries, blobMap);
55
- entries.push(...subTreeEntries);
56
- }
57
- }
57
+ const subTreeEntries = flattenCore(`${subPath}/`, t.entries, blobMap);
58
+ entries.push(...subTreeEntries);
59
+ }
60
+ }
58
61
 
59
- return entries;
62
+ return entries;
60
63
  }
61
64
 
62
65
  /**
@@ -67,12 +70,12 @@ function flattenCore(
67
70
  * @returns A flatten with of the ITreeEntry
68
71
  */
69
72
  function flatten(tree: ITreeEntry[], blobMap: Map<string, ArrayBufferLike>): git.ITree {
70
- const entries = flattenCore("", tree, blobMap);
71
- return {
72
- sha: "",
73
- tree: entries,
74
- url: "",
75
- };
73
+ const entries = flattenCore("", tree, blobMap);
74
+ return {
75
+ sha: "",
76
+ tree: entries,
77
+ url: "",
78
+ };
76
79
  }
77
80
 
78
81
  /**
@@ -84,9 +87,9 @@ function flatten(tree: ITreeEntry[], blobMap: Map<string, ArrayBufferLike>): git
84
87
  * @returns the hierarchical tree
85
88
  */
86
89
  export function buildSnapshotTree(
87
- entries: ITreeEntry[],
88
- blobMap: Map<string, ArrayBufferLike>,
90
+ entries: ITreeEntry[],
91
+ blobMap: Map<string, ArrayBufferLike>,
89
92
  ): ISnapshotTree {
90
- const flattened = flatten(entries, blobMap);
91
- return buildHierarchy(flattened);
93
+ const flattened = flatten(entries, blobMap);
94
+ return buildHierarchy(flattened);
92
95
  }
@@ -4,62 +4,68 @@
4
4
  */
5
5
 
6
6
  import {
7
- FetchSource,
8
- IDocumentStorageService,
9
- IDocumentStorageServicePolicies,
10
- ISummaryContext,
7
+ FetchSource,
8
+ IDocumentStorageService,
9
+ IDocumentStorageServicePolicies,
10
+ ISummaryContext,
11
11
  } from "@fluidframework/driver-definitions";
12
12
  import {
13
- ICreateBlobResponse,
14
- ISnapshotTree,
15
- ISummaryHandle,
16
- ISummaryTree,
17
- IVersion,
13
+ ICreateBlobResponse,
14
+ ISnapshotTree,
15
+ ISummaryHandle,
16
+ ISummaryTree,
17
+ IVersion,
18
18
  } from "@fluidframework/protocol-definitions";
19
19
 
20
20
  export class DocumentStorageServiceProxy implements IDocumentStorageService {
21
- private _policies: IDocumentStorageServicePolicies | undefined;
21
+ private _policies: IDocumentStorageServicePolicies | undefined;
22
22
 
23
- public set policies(policies: IDocumentStorageServicePolicies | undefined) {
24
- this._policies = policies;
25
- }
23
+ public set policies(policies: IDocumentStorageServicePolicies | undefined) {
24
+ this._policies = policies;
25
+ }
26
26
 
27
- public get policies() {
28
- return this._policies ?? this.internalStorageService.policies;
29
- }
27
+ public get policies() {
28
+ return this._policies ?? this.internalStorageService.policies;
29
+ }
30
30
 
31
- public get repositoryUrl(): string {
32
- return this.internalStorageService.repositoryUrl;
33
- }
31
+ public get repositoryUrl(): string {
32
+ return this.internalStorageService.repositoryUrl;
33
+ }
34
34
 
35
- constructor(protected readonly internalStorageService: IDocumentStorageService) { }
35
+ constructor(protected readonly internalStorageService: IDocumentStorageService) {}
36
36
 
37
- public async getSnapshotTree(version?: IVersion, scenarioName?: string): Promise<ISnapshotTree | null> {
38
- return this.internalStorageService.getSnapshotTree(version, scenarioName);
39
- }
37
+ public async getSnapshotTree(
38
+ version?: IVersion,
39
+ scenarioName?: string,
40
+ ): Promise<ISnapshotTree | null> {
41
+ return this.internalStorageService.getSnapshotTree(version, scenarioName);
42
+ }
40
43
 
41
- public async getVersions(
42
- versionId: string | null,
43
- count: number,
44
- scenarioName?: string,
45
- fetchSource?: FetchSource,
46
- ): Promise<IVersion[]> {
47
- return this.internalStorageService.getVersions(versionId, count, scenarioName, fetchSource);
48
- }
44
+ public async getVersions(
45
+ versionId: string | null,
46
+ count: number,
47
+ scenarioName?: string,
48
+ fetchSource?: FetchSource,
49
+ ): Promise<IVersion[]> {
50
+ return this.internalStorageService.getVersions(versionId, count, scenarioName, fetchSource);
51
+ }
49
52
 
50
- public async uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string> {
51
- return this.internalStorageService.uploadSummaryWithContext(summary, context);
52
- }
53
+ public async uploadSummaryWithContext(
54
+ summary: ISummaryTree,
55
+ context: ISummaryContext,
56
+ ): Promise<string> {
57
+ return this.internalStorageService.uploadSummaryWithContext(summary, context);
58
+ }
53
59
 
54
- public async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {
55
- return this.internalStorageService.downloadSummary(handle);
56
- }
60
+ public async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {
61
+ return this.internalStorageService.downloadSummary(handle);
62
+ }
57
63
 
58
- public async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {
59
- return this.internalStorageService.createBlob(file);
60
- }
64
+ public async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {
65
+ return this.internalStorageService.createBlob(file);
66
+ }
61
67
 
62
- public async readBlob(blobId: string): Promise<ArrayBufferLike> {
63
- return this.internalStorageService.readBlob(blobId);
64
- }
68
+ public async readBlob(blobId: string): Promise<ArrayBufferLike> {
69
+ return this.internalStorageService.readBlob(blobId);
70
+ }
65
71
  }
@@ -11,14 +11,15 @@ import { Queue } from "./parallelRequests";
11
11
  * Implementation of IDocumentDeltaStorageService that will always return an empty message queue when fetching messages
12
12
  */
13
13
  export class EmptyDocumentDeltaStorageService implements IDocumentDeltaStorageService {
14
- public fetchMessages(from: number,
15
- _to: number | undefined,
16
- _abortSignal?: AbortSignal,
17
- _cachedOnly?: boolean,
18
- _fetchReason?: string,
19
- ): IStream<ISequencedDocumentMessage[]> {
20
- const queue = new Queue<ISequencedDocumentMessage[]>();
21
- queue.pushDone();
22
- return queue;
23
- }
14
+ public fetchMessages(
15
+ from: number,
16
+ _to: number | undefined,
17
+ _abortSignal?: AbortSignal,
18
+ _cachedOnly?: boolean,
19
+ _fetchReason?: string,
20
+ ): IStream<ISequencedDocumentMessage[]> {
21
+ const queue = new Queue<ISequencedDocumentMessage[]>();
22
+ queue.pushDone();
23
+ return queue;
24
+ }
24
25
  }
package/src/error.ts CHANGED
@@ -8,12 +8,10 @@ import { IFluidErrorBase, LoggingError } from "@fluidframework/telemetry-utils";
8
8
 
9
9
  /** Error indicating an API is being used improperly resulting in an invalid operation. */
10
10
  export class UsageError extends LoggingError implements IDriverErrorBase, IFluidErrorBase {
11
- readonly errorType = DriverErrorType.usageError;
12
- readonly canRetry = false;
11
+ readonly errorType = DriverErrorType.usageError;
12
+ readonly canRetry = false;
13
13
 
14
- constructor(
15
- message: string,
16
- ) {
17
- super(message, { usageError: true });
18
- }
14
+ constructor(message: string) {
15
+ super(message, { usageError: true });
16
+ }
19
17
  }
@@ -5,11 +5,14 @@
5
5
 
6
6
  import { IResolvedUrl, IFluidResolvedUrl } from "@fluidframework/driver-definitions";
7
7
 
8
- export const isFluidResolvedUrl =
9
- (resolved: IResolvedUrl | undefined): resolved is IFluidResolvedUrl => resolved?.type === "fluid";
8
+ export const isFluidResolvedUrl = (
9
+ resolved: IResolvedUrl | undefined,
10
+ ): resolved is IFluidResolvedUrl => resolved?.type === "fluid";
10
11
 
11
- export function ensureFluidResolvedUrl(resolved: IResolvedUrl | undefined): asserts resolved is IFluidResolvedUrl {
12
- if (!isFluidResolvedUrl(resolved)) {
13
- throw new Error(`resolved is not a Fluid url. Type: ${resolved?.type}`);
14
- }
12
+ export function ensureFluidResolvedUrl(
13
+ resolved: IResolvedUrl | undefined,
14
+ ): asserts resolved is IFluidResolvedUrl {
15
+ if (!isFluidResolvedUrl(resolved)) {
16
+ throw new Error(`resolved is not a Fluid url. Type: ${resolved?.type}`);
17
+ }
15
18
  }
package/src/index.ts CHANGED
@@ -59,4 +59,8 @@ export {
59
59
  getQuorumValuesFromProtocolSummary,
60
60
  } from "./summaryForCreateNew";
61
61
  export { convertSummaryTreeToSnapshotITree } from "./treeConversions";
62
- export { convertSnapshotAndBlobsToSummaryTree, ISummaryTreeAssemblerProps, SummaryTreeAssembler } from "./treeUtils";
62
+ export {
63
+ convertSnapshotAndBlobsToSummaryTree,
64
+ ISummaryTreeAssemblerProps,
65
+ SummaryTreeAssembler,
66
+ } from "./treeUtils";
@@ -7,10 +7,10 @@ import { parse } from "url";
7
7
  import { assert } from "@fluidframework/common-utils";
8
8
  import { IRequest } from "@fluidframework/core-interfaces";
9
9
  import {
10
- IFluidResolvedUrl,
11
- IResolvedUrl,
12
- IUrlResolver,
13
- DriverHeader,
10
+ IFluidResolvedUrl,
11
+ IResolvedUrl,
12
+ IUrlResolver,
13
+ DriverHeader,
14
14
  } from "@fluidframework/driver-definitions";
15
15
  import Axios from "axios";
16
16
 
@@ -29,128 +29,139 @@ import Axios from "axios";
29
29
  * works or a router inside of a single page app framework.
30
30
  */
31
31
  export class InsecureUrlResolver implements IUrlResolver {
32
- private readonly cache = new Map<string, Promise<IResolvedUrl>>();
32
+ private readonly cache = new Map<string, Promise<IResolvedUrl>>();
33
33
 
34
- constructor(
35
- private readonly hostUrl: string,
36
- private readonly ordererUrl: string,
37
- private readonly storageUrl: string,
38
- private readonly tenantId: string,
39
- private readonly bearer: string,
40
- private readonly isForNodeTest: boolean = false,
41
- ) { }
34
+ constructor(
35
+ private readonly hostUrl: string,
36
+ private readonly ordererUrl: string,
37
+ private readonly storageUrl: string,
38
+ private readonly tenantId: string,
39
+ private readonly bearer: string,
40
+ private readonly isForNodeTest: boolean = false,
41
+ ) {}
42
42
 
43
- public async resolve(request: IRequest): Promise<IResolvedUrl | undefined> {
44
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
45
- if (request.headers?.[DriverHeader.createNew]) {
46
- const [, queryString] = request.url.split("?");
47
- const searchParams = new URLSearchParams(queryString);
48
- const fileName = searchParams.get("fileName");
49
- return this.resolveHelper(fileName);
50
- }
51
- const parsedUrl = new URL(request.url);
52
- // If hosts match then we use the local tenant information. Otherwise we make a REST call out to the hosting
53
- // service using our bearer token.
54
- if (this.isForNodeTest) {
55
- const [, documentId, tmpRelativePath] = parsedUrl.pathname.substr(1).split("/");
56
- const relativePath = tmpRelativePath === undefined ? "" : tmpRelativePath;
57
- return this.resolveHelper(documentId, relativePath, parsedUrl.search);
58
- } else if (parsedUrl.host === window.location.host) {
59
- const fullPath = parsedUrl.pathname.substr(1);
60
- const documentId = fullPath.split("/")[0];
61
- const documentRelativePath = fullPath.slice(documentId.length);
62
- return this.resolveHelper(documentId, documentRelativePath);
63
- } else {
64
- const maybeResolvedUrl = this.cache.get(request.url);
65
- if (maybeResolvedUrl) {
66
- return maybeResolvedUrl;
67
- }
43
+ public async resolve(request: IRequest): Promise<IResolvedUrl | undefined> {
44
+ // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
45
+ if (request.headers?.[DriverHeader.createNew]) {
46
+ const [, queryString] = request.url.split("?");
47
+ const searchParams = new URLSearchParams(queryString);
48
+ const fileName = searchParams.get("fileName");
49
+ return this.resolveHelper(fileName);
50
+ }
51
+ const parsedUrl = new URL(request.url);
52
+ // If hosts match then we use the local tenant information. Otherwise we make a REST call out to the hosting
53
+ // service using our bearer token.
54
+ if (this.isForNodeTest) {
55
+ const [, documentId, tmpRelativePath] = parsedUrl.pathname.substr(1).split("/");
56
+ const relativePath = tmpRelativePath === undefined ? "" : tmpRelativePath;
57
+ return this.resolveHelper(documentId, relativePath, parsedUrl.search);
58
+ } else if (parsedUrl.host === window.location.host) {
59
+ const fullPath = parsedUrl.pathname.substr(1);
60
+ const documentId = fullPath.split("/")[0];
61
+ const documentRelativePath = fullPath.slice(documentId.length);
62
+ return this.resolveHelper(documentId, documentRelativePath);
63
+ } else {
64
+ const maybeResolvedUrl = this.cache.get(request.url);
65
+ if (maybeResolvedUrl) {
66
+ return maybeResolvedUrl;
67
+ }
68
68
 
69
- const headers = {
70
- Authorization: `Bearer ${this.bearer}`,
71
- };
72
- const resolvedP = Axios.post<IResolvedUrl>(
73
- `${this.hostUrl}/api/v1/load`,
74
- {
75
- url: request.url,
76
- },
77
- {
78
- headers,
79
- });
80
- this.cache.set(request.url, resolvedP.then((resolved) => resolved.data));
69
+ const headers = {
70
+ Authorization: `Bearer ${this.bearer}`,
71
+ };
72
+ const resolvedP = Axios.post<IResolvedUrl>(
73
+ `${this.hostUrl}/api/v1/load`,
74
+ {
75
+ url: request.url,
76
+ },
77
+ {
78
+ headers,
79
+ },
80
+ );
81
+ this.cache.set(
82
+ request.url,
83
+ resolvedP.then((resolved) => resolved.data),
84
+ );
81
85
 
82
- return this.cache.get(request.url);
83
- }
84
- }
86
+ return this.cache.get(request.url);
87
+ }
88
+ }
85
89
 
86
- private resolveHelper(documentId: string | null, documentRelativePath: string = "", queryParams: string = "") {
87
- const encodedTenantId = encodeURIComponent(this.tenantId);
88
- const host = new URL(this.ordererUrl).host;
89
- // when the document ID is not provided we need to resolve a special create new document URL.
90
- // the actual container ID will be generated by the driver.
91
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
92
- if (!documentId) {
93
- const createNewResponse: IFluidResolvedUrl = {
94
- endpoints: {
95
- deltaStorageUrl: `${this.ordererUrl}/deltas/${encodedTenantId}/new`,
96
- ordererUrl: this.ordererUrl,
97
- storageUrl: `${this.storageUrl}/repos/${encodedTenantId}`,
98
- },
99
- // document ID is ignored by the driver for new container requests
100
- id: "",
101
- tokens: {},
102
- type: "fluid",
103
- url: `fluid://${host}/${encodedTenantId}/new`,
104
- };
105
- return createNewResponse;
106
- }
107
- const encodedDocId = encodeURIComponent(documentId);
108
- const relativePath = !documentRelativePath || documentRelativePath.startsWith("/")
109
- ? documentRelativePath : `/${documentRelativePath}`;
110
- const documentUrl = `fluid://${host}/${encodedTenantId}/${encodedDocId}${relativePath}${queryParams}`;
90
+ private resolveHelper(
91
+ documentId: string | null,
92
+ documentRelativePath: string = "",
93
+ queryParams: string = "",
94
+ ) {
95
+ const encodedTenantId = encodeURIComponent(this.tenantId);
96
+ const host = new URL(this.ordererUrl).host;
97
+ // when the document ID is not provided we need to resolve a special create new document URL.
98
+ // the actual container ID will be generated by the driver.
99
+ // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
100
+ if (!documentId) {
101
+ const createNewResponse: IFluidResolvedUrl = {
102
+ endpoints: {
103
+ deltaStorageUrl: `${this.ordererUrl}/deltas/${encodedTenantId}/new`,
104
+ ordererUrl: this.ordererUrl,
105
+ storageUrl: `${this.storageUrl}/repos/${encodedTenantId}`,
106
+ },
107
+ // document ID is ignored by the driver for new container requests
108
+ id: "",
109
+ tokens: {},
110
+ type: "fluid",
111
+ url: `fluid://${host}/${encodedTenantId}/new`,
112
+ };
113
+ return createNewResponse;
114
+ }
115
+ const encodedDocId = encodeURIComponent(documentId);
116
+ const relativePath =
117
+ !documentRelativePath || documentRelativePath.startsWith("/")
118
+ ? documentRelativePath
119
+ : `/${documentRelativePath}`;
120
+ const documentUrl = `fluid://${host}/${encodedTenantId}/${encodedDocId}${relativePath}${queryParams}`;
111
121
 
112
- const deltaStorageUrl = `${this.ordererUrl}/deltas/${encodedTenantId}/${encodedDocId}`;
113
- const storageUrl = `${this.storageUrl}/repos/${encodedTenantId}`;
122
+ const deltaStorageUrl = `${this.ordererUrl}/deltas/${encodedTenantId}/${encodedDocId}`;
123
+ const storageUrl = `${this.storageUrl}/repos/${encodedTenantId}`;
114
124
 
115
- const response: IFluidResolvedUrl = {
116
- endpoints: {
117
- deltaStorageUrl,
118
- ordererUrl: this.ordererUrl,
119
- storageUrl,
120
- },
121
- id: documentId,
122
- tokens: {},
123
- type: "fluid",
124
- url: documentUrl,
125
- };
126
- return response;
127
- }
125
+ const response: IFluidResolvedUrl = {
126
+ endpoints: {
127
+ deltaStorageUrl,
128
+ ordererUrl: this.ordererUrl,
129
+ storageUrl,
130
+ },
131
+ id: documentId,
132
+ tokens: {},
133
+ type: "fluid",
134
+ url: documentUrl,
135
+ };
136
+ return response;
137
+ }
128
138
 
129
- public async getAbsoluteUrl(resolvedUrl: IResolvedUrl, relativeUrl: string): Promise<string> {
130
- const fluidResolvedUrl = resolvedUrl as IFluidResolvedUrl;
139
+ public async getAbsoluteUrl(resolvedUrl: IResolvedUrl, relativeUrl: string): Promise<string> {
140
+ const fluidResolvedUrl = resolvedUrl as IFluidResolvedUrl;
131
141
 
132
- const parsedUrl = parse(fluidResolvedUrl.url);
133
- const [, , documentId] = parsedUrl.pathname?.split("/") ?? [];
134
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
135
- assert(!!documentId, 0x273 /* "Invalid document id from parsed URL" */);
142
+ const parsedUrl = parse(fluidResolvedUrl.url);
143
+ const [, , documentId] = parsedUrl.pathname?.split("/") ?? [];
144
+ // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
145
+ assert(!!documentId, 0x273 /* "Invalid document id from parsed URL" */);
136
146
 
137
- let url = relativeUrl;
138
- if (url.startsWith("/")) {
139
- url = url.substr(1);
140
- }
147
+ let url = relativeUrl;
148
+ if (url.startsWith("/")) {
149
+ url = url.substr(1);
150
+ }
141
151
 
142
- return `${this.hostUrl}/${encodeURIComponent(
143
- this.tenantId)}/${encodeURIComponent(documentId)}/${url}`;
144
- }
152
+ return `${this.hostUrl}/${encodeURIComponent(this.tenantId)}/${encodeURIComponent(
153
+ documentId,
154
+ )}/${url}`;
155
+ }
145
156
 
146
- public createCreateNewRequest(fileName?: string): IRequest {
147
- const createNewRequest: IRequest = {
148
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
149
- url: fileName ? `${this.hostUrl}?fileName=${fileName}` : this.hostUrl,
150
- headers: {
151
- [DriverHeader.createNew]: true,
152
- },
153
- };
154
- return createNewRequest;
155
- }
157
+ public createCreateNewRequest(fileName?: string): IRequest {
158
+ const createNewRequest: IRequest = {
159
+ // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
160
+ url: fileName ? `${this.hostUrl}?fileName=${fileName}` : this.hostUrl,
161
+ headers: {
162
+ [DriverHeader.createNew]: true,
163
+ },
164
+ };
165
+ return createNewRequest;
166
+ }
156
167
  }