@fluidframework/driver-utils 2.0.0-dev.2.3.0.115467 → 2.0.0-dev.4.1.0.148229

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 (180) hide show
  1. package/.eslintrc.js +17 -19
  2. package/.mocharc.js +2 -2
  3. package/api-extractor.json +2 -2
  4. package/dist/buildSnapshotTree.d.ts.map +1 -1
  5. package/dist/buildSnapshotTree.js.map +1 -1
  6. package/dist/documentStorageServiceProxy.d.ts.map +1 -1
  7. package/dist/documentStorageServiceProxy.js.map +1 -1
  8. package/dist/error.d.ts.map +1 -1
  9. package/dist/error.js.map +1 -1
  10. package/dist/fluidResolvedUrl.d.ts +8 -0
  11. package/dist/fluidResolvedUrl.d.ts.map +1 -1
  12. package/dist/fluidResolvedUrl.js +8 -0
  13. package/dist/fluidResolvedUrl.js.map +1 -1
  14. package/dist/index.d.ts +4 -10
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +2 -19
  17. package/dist/index.js.map +1 -1
  18. package/dist/insecureUrlResolver.d.ts.map +1 -1
  19. package/dist/insecureUrlResolver.js +2 -1
  20. package/dist/insecureUrlResolver.js.map +1 -1
  21. package/dist/messageRecognition.d.ts +0 -20
  22. package/dist/messageRecognition.d.ts.map +1 -1
  23. package/dist/messageRecognition.js +1 -37
  24. package/dist/messageRecognition.js.map +1 -1
  25. package/dist/network.d.ts +0 -15
  26. package/dist/network.d.ts.map +1 -1
  27. package/dist/network.js +4 -3
  28. package/dist/network.js.map +1 -1
  29. package/dist/networkUtils.d.ts +0 -10
  30. package/dist/networkUtils.d.ts.map +1 -1
  31. package/dist/networkUtils.js +3 -35
  32. package/dist/networkUtils.js.map +1 -1
  33. package/dist/packageVersion.d.ts +1 -1
  34. package/dist/packageVersion.js +1 -1
  35. package/dist/packageVersion.js.map +1 -1
  36. package/dist/parallelRequests.d.ts.map +1 -1
  37. package/dist/parallelRequests.js +52 -23
  38. package/dist/parallelRequests.js.map +1 -1
  39. package/dist/prefetchDocumentStorageService.d.ts.map +1 -1
  40. package/dist/prefetchDocumentStorageService.js.map +1 -1
  41. package/dist/rateLimiter.d.ts.map +1 -1
  42. package/dist/rateLimiter.js.map +1 -1
  43. package/dist/readAndParse.d.ts.map +1 -1
  44. package/dist/readAndParse.js.map +1 -1
  45. package/dist/runWithRetry.d.ts.map +1 -1
  46. package/dist/runWithRetry.js +10 -0
  47. package/dist/runWithRetry.js.map +1 -1
  48. package/dist/summaryForCreateNew.d.ts +21 -1
  49. package/dist/summaryForCreateNew.d.ts.map +1 -1
  50. package/dist/summaryForCreateNew.js +26 -1
  51. package/dist/summaryForCreateNew.js.map +1 -1
  52. package/dist/treeConversions.d.ts.map +1 -1
  53. package/dist/treeConversions.js +6 -10
  54. package/dist/treeConversions.js.map +1 -1
  55. package/lib/buildSnapshotTree.d.ts.map +1 -1
  56. package/lib/buildSnapshotTree.js.map +1 -1
  57. package/lib/documentStorageServiceProxy.d.ts.map +1 -1
  58. package/lib/documentStorageServiceProxy.js.map +1 -1
  59. package/lib/error.d.ts.map +1 -1
  60. package/lib/error.js.map +1 -1
  61. package/lib/fluidResolvedUrl.d.ts +8 -0
  62. package/lib/fluidResolvedUrl.d.ts.map +1 -1
  63. package/lib/fluidResolvedUrl.js +8 -0
  64. package/lib/fluidResolvedUrl.js.map +1 -1
  65. package/lib/index.d.ts +4 -10
  66. package/lib/index.d.ts.map +1 -1
  67. package/lib/index.js +3 -9
  68. package/lib/index.js.map +1 -1
  69. package/lib/insecureUrlResolver.d.ts.map +1 -1
  70. package/lib/insecureUrlResolver.js +2 -1
  71. package/lib/insecureUrlResolver.js.map +1 -1
  72. package/lib/messageRecognition.d.ts +0 -20
  73. package/lib/messageRecognition.d.ts.map +1 -1
  74. package/lib/messageRecognition.js +1 -36
  75. package/lib/messageRecognition.js.map +1 -1
  76. package/lib/network.d.ts +0 -15
  77. package/lib/network.d.ts.map +1 -1
  78. package/lib/network.js +4 -3
  79. package/lib/network.js.map +1 -1
  80. package/lib/networkUtils.d.ts +0 -10
  81. package/lib/networkUtils.d.ts.map +1 -1
  82. package/lib/networkUtils.js +2 -33
  83. package/lib/networkUtils.js.map +1 -1
  84. package/lib/packageVersion.d.ts +1 -1
  85. package/lib/packageVersion.js +1 -1
  86. package/lib/packageVersion.js.map +1 -1
  87. package/lib/parallelRequests.d.ts.map +1 -1
  88. package/lib/parallelRequests.js +53 -24
  89. package/lib/parallelRequests.js.map +1 -1
  90. package/lib/prefetchDocumentStorageService.d.ts.map +1 -1
  91. package/lib/prefetchDocumentStorageService.js.map +1 -1
  92. package/lib/rateLimiter.d.ts.map +1 -1
  93. package/lib/rateLimiter.js.map +1 -1
  94. package/lib/readAndParse.d.ts.map +1 -1
  95. package/lib/readAndParse.js.map +1 -1
  96. package/lib/runWithRetry.d.ts.map +1 -1
  97. package/lib/runWithRetry.js +10 -0
  98. package/lib/runWithRetry.js.map +1 -1
  99. package/lib/summaryForCreateNew.d.ts +21 -1
  100. package/lib/summaryForCreateNew.d.ts.map +1 -1
  101. package/lib/summaryForCreateNew.js +24 -0
  102. package/lib/summaryForCreateNew.js.map +1 -1
  103. package/lib/treeConversions.d.ts.map +1 -1
  104. package/lib/treeConversions.js +9 -13
  105. package/lib/treeConversions.js.map +1 -1
  106. package/package.json +54 -52
  107. package/prettier.config.cjs +1 -1
  108. package/src/buildSnapshotTree.ts +54 -51
  109. package/src/documentStorageServiceProxy.ts +49 -43
  110. package/src/error.ts +5 -7
  111. package/src/fluidResolvedUrl.ts +17 -6
  112. package/src/index.ts +4 -14
  113. package/src/insecureUrlResolver.ts +127 -116
  114. package/src/messageRecognition.ts +14 -44
  115. package/src/network.ts +112 -126
  116. package/src/networkUtils.ts +19 -48
  117. package/src/packageVersion.ts +1 -1
  118. package/src/parallelRequests.ts +591 -510
  119. package/src/prefetchDocumentStorageService.ts +76 -74
  120. package/src/rateLimiter.ts +29 -29
  121. package/src/readAndParse.ts +7 -4
  122. package/src/runWithRetry.ts +106 -84
  123. package/src/summaryForCreateNew.ts +74 -25
  124. package/src/treeConversions.ts +47 -70
  125. package/tsconfig.esnext.json +6 -6
  126. package/tsconfig.json +8 -12
  127. package/dist/blobAggregationStorage.d.ts +0 -43
  128. package/dist/blobAggregationStorage.d.ts.map +0 -1
  129. package/dist/blobAggregationStorage.js +0 -318
  130. package/dist/blobAggregationStorage.js.map +0 -1
  131. package/dist/blobCacheStorageService.d.ts +0 -16
  132. package/dist/blobCacheStorageService.d.ts.map +0 -1
  133. package/dist/blobCacheStorageService.js +0 -29
  134. package/dist/blobCacheStorageService.js.map +0 -1
  135. package/dist/emptyDocumentDeltaStorageService.d.ts +0 -13
  136. package/dist/emptyDocumentDeltaStorageService.d.ts.map +0 -1
  137. package/dist/emptyDocumentDeltaStorageService.js +0 -20
  138. package/dist/emptyDocumentDeltaStorageService.js.map +0 -1
  139. package/dist/multiDocumentServiceFactory.d.ts +0 -16
  140. package/dist/multiDocumentServiceFactory.d.ts.map +0 -1
  141. package/dist/multiDocumentServiceFactory.js +0 -63
  142. package/dist/multiDocumentServiceFactory.js.map +0 -1
  143. package/dist/multiUrlResolver.d.ts +0 -20
  144. package/dist/multiUrlResolver.d.ts.map +0 -1
  145. package/dist/multiUrlResolver.js +0 -45
  146. package/dist/multiUrlResolver.js.map +0 -1
  147. package/dist/treeUtils.d.ts +0 -51
  148. package/dist/treeUtils.d.ts.map +0 -1
  149. package/dist/treeUtils.js +0 -85
  150. package/dist/treeUtils.js.map +0 -1
  151. package/lib/blobAggregationStorage.d.ts +0 -43
  152. package/lib/blobAggregationStorage.d.ts.map +0 -1
  153. package/lib/blobAggregationStorage.js +0 -313
  154. package/lib/blobAggregationStorage.js.map +0 -1
  155. package/lib/blobCacheStorageService.d.ts +0 -16
  156. package/lib/blobCacheStorageService.d.ts.map +0 -1
  157. package/lib/blobCacheStorageService.js +0 -25
  158. package/lib/blobCacheStorageService.js.map +0 -1
  159. package/lib/emptyDocumentDeltaStorageService.d.ts +0 -13
  160. package/lib/emptyDocumentDeltaStorageService.d.ts.map +0 -1
  161. package/lib/emptyDocumentDeltaStorageService.js +0 -16
  162. package/lib/emptyDocumentDeltaStorageService.js.map +0 -1
  163. package/lib/multiDocumentServiceFactory.d.ts +0 -16
  164. package/lib/multiDocumentServiceFactory.d.ts.map +0 -1
  165. package/lib/multiDocumentServiceFactory.js +0 -59
  166. package/lib/multiDocumentServiceFactory.js.map +0 -1
  167. package/lib/multiUrlResolver.d.ts +0 -20
  168. package/lib/multiUrlResolver.d.ts.map +0 -1
  169. package/lib/multiUrlResolver.js +0 -40
  170. package/lib/multiUrlResolver.js.map +0 -1
  171. package/lib/treeUtils.d.ts +0 -51
  172. package/lib/treeUtils.d.ts.map +0 -1
  173. package/lib/treeUtils.js +0 -80
  174. package/lib/treeUtils.js.map +0 -1
  175. package/src/blobAggregationStorage.ts +0 -374
  176. package/src/blobCacheStorageService.ts +0 -32
  177. package/src/emptyDocumentDeltaStorageService.ts +0 -24
  178. package/src/multiDocumentServiceFactory.ts +0 -80
  179. package/src/multiUrlResolver.ts +0 -51
  180. package/src/treeUtils.ts +0 -111
@@ -3,90 +3,92 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { LoaderCachingPolicy } from "@fluidframework/driver-definitions";
6
- import {
7
- ISnapshotTree,
8
- IVersion,
9
- } from "@fluidframework/protocol-definitions";
6
+ import { ISnapshotTree, IVersion } from "@fluidframework/protocol-definitions";
10
7
  import { DocumentStorageServiceProxy } from "./documentStorageServiceProxy";
11
8
  import { canRetryOnError } from "./network";
12
9
 
13
10
  export class PrefetchDocumentStorageService extends DocumentStorageServiceProxy {
14
- // BlobId -> blob prefetchCache cache
15
- private readonly prefetchCache = new Map<string, Promise<ArrayBufferLike>>();
16
- private prefetchEnabled = true;
11
+ // BlobId -> blob prefetchCache cache
12
+ private readonly prefetchCache = new Map<string, Promise<ArrayBufferLike>>();
13
+ private prefetchEnabled = true;
17
14
 
18
- public get policies() {
19
- const policies = this.internalStorageService.policies;
20
- if (policies) {
21
- return { ...policies, caching: LoaderCachingPolicy.NoCaching };
22
- }
23
- }
15
+ public get policies() {
16
+ const policies = this.internalStorageService.policies;
17
+ if (policies) {
18
+ return { ...policies, caching: LoaderCachingPolicy.NoCaching };
19
+ }
20
+ }
24
21
 
25
- public async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {
26
- const p = this.internalStorageService.getSnapshotTree(version);
27
- if (this.prefetchEnabled) {
28
- // We don't care if the prefetch succeeds
29
- void p.then((tree: ISnapshotTree | null | undefined) => {
30
- if (tree === null || tree === undefined) { return; }
31
- this.prefetchTree(tree);
32
- });
33
- }
34
- return p;
35
- }
22
+ public async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {
23
+ const p = this.internalStorageService.getSnapshotTree(version);
24
+ if (this.prefetchEnabled) {
25
+ // We don't care if the prefetch succeeds
26
+ void p.then((tree: ISnapshotTree | null | undefined) => {
27
+ if (tree === null || tree === undefined) {
28
+ return;
29
+ }
30
+ this.prefetchTree(tree);
31
+ });
32
+ }
33
+ return p;
34
+ }
36
35
 
37
- public async readBlob(blobId: string): Promise<ArrayBufferLike> {
38
- return this.cachedRead(blobId);
39
- }
40
- public stopPrefetch() {
41
- this.prefetchEnabled = false;
42
- this.prefetchCache.clear();
43
- }
36
+ public async readBlob(blobId: string): Promise<ArrayBufferLike> {
37
+ return this.cachedRead(blobId);
38
+ }
39
+ public stopPrefetch() {
40
+ this.prefetchEnabled = false;
41
+ this.prefetchCache.clear();
42
+ }
44
43
 
45
- private async cachedRead(blobId: string): Promise<ArrayBufferLike> {
46
- if (this.prefetchEnabled) {
47
- const prefetchedBlobP = this.prefetchCache.get(blobId);
48
- if (prefetchedBlobP !== undefined) {
49
- return prefetchedBlobP;
50
- }
51
- const prefetchedBlobPFromStorage = this.internalStorageService.readBlob(blobId);
52
- this.prefetchCache.set(blobId, prefetchedBlobPFromStorage.catch((error) => {
53
- if (canRetryOnError(error)) {
54
- this.prefetchCache.delete(blobId);
55
- }
56
- throw error;
57
- }));
58
- return prefetchedBlobPFromStorage;
59
- }
60
- return this.internalStorageService.readBlob(blobId);
61
- }
44
+ private async cachedRead(blobId: string): Promise<ArrayBufferLike> {
45
+ if (this.prefetchEnabled) {
46
+ const prefetchedBlobP = this.prefetchCache.get(blobId);
47
+ if (prefetchedBlobP !== undefined) {
48
+ return prefetchedBlobP;
49
+ }
50
+ const prefetchedBlobPFromStorage = this.internalStorageService.readBlob(blobId);
51
+ this.prefetchCache.set(
52
+ blobId,
53
+ prefetchedBlobPFromStorage.catch((error) => {
54
+ if (canRetryOnError(error)) {
55
+ this.prefetchCache.delete(blobId);
56
+ }
57
+ throw error;
58
+ }),
59
+ );
60
+ return prefetchedBlobPFromStorage;
61
+ }
62
+ return this.internalStorageService.readBlob(blobId);
63
+ }
62
64
 
63
- private prefetchTree(tree: ISnapshotTree) {
64
- const secondary: string[] = [];
65
- this.prefetchTreeCore(tree, secondary);
65
+ private prefetchTree(tree: ISnapshotTree) {
66
+ const secondary: string[] = [];
67
+ this.prefetchTreeCore(tree, secondary);
66
68
 
67
- for (const blob of secondary) {
68
- // We don't care if the prefetch succeeds
69
- void this.cachedRead(blob);
70
- }
71
- }
69
+ for (const blob of secondary) {
70
+ // We don't care if the prefetch succeeds
71
+ void this.cachedRead(blob);
72
+ }
73
+ }
72
74
 
73
- private prefetchTreeCore(tree: ISnapshotTree, secondary: string[]) {
74
- for (const blobKey of Object.keys(tree.blobs)) {
75
- const blob = tree.blobs[blobKey];
76
- if (blobKey.startsWith(".") || blobKey === "header" || blobKey.startsWith("quorum")) {
77
- if (blob !== null) {
78
- // We don't care if the prefetch succeeds
79
- void this.cachedRead(blob);
80
- }
81
- } else if (!blobKey.startsWith("deltas")) {
82
- if (blob !== null) {
83
- secondary.push(blob);
84
- }
85
- }
86
- }
75
+ private prefetchTreeCore(tree: ISnapshotTree, secondary: string[]) {
76
+ for (const blobKey of Object.keys(tree.blobs)) {
77
+ const blob = tree.blobs[blobKey];
78
+ if (blobKey.startsWith(".") || blobKey === "header" || blobKey.startsWith("quorum")) {
79
+ if (blob !== null) {
80
+ // We don't care if the prefetch succeeds
81
+ void this.cachedRead(blob);
82
+ }
83
+ } else if (!blobKey.startsWith("deltas")) {
84
+ if (blob !== null) {
85
+ secondary.push(blob);
86
+ }
87
+ }
88
+ }
87
89
 
88
- for (const subTree of Object.keys(tree.trees)) {
89
- this.prefetchTreeCore(tree.trees[subTree], secondary);
90
- }
91
- }
90
+ for (const subTree of Object.keys(tree.trees)) {
91
+ this.prefetchTreeCore(tree.trees[subTree], secondary);
92
+ }
93
+ }
92
94
  }
@@ -6,38 +6,38 @@
6
6
  import { assert } from "@fluidframework/common-utils";
7
7
 
8
8
  export class RateLimiter {
9
- private readonly tasks: (() => void)[] = [];
10
- constructor(private maxRequests: number) {
11
- assert(maxRequests > 0, 0x0ae /* "Tried to create rate limiter with 0 max requests!" */);
12
- }
9
+ private readonly tasks: (() => void)[] = [];
10
+ constructor(private maxRequests: number) {
11
+ assert(maxRequests > 0, 0x0ae /* "Tried to create rate limiter with 0 max requests!" */);
12
+ }
13
13
 
14
- public get waitQueueLength(): number {
15
- return this.tasks.length;
16
- }
14
+ public get waitQueueLength(): number {
15
+ return this.tasks.length;
16
+ }
17
17
 
18
- // Run when one of the tasks finished running.
19
- // Release next task if we have one, or allow more tasks to run in future.
20
- protected readonly release = () => {
21
- const task = this.tasks.shift();
22
- if (task !== undefined) {
23
- return task();
24
- }
25
- this.maxRequests++;
26
- };
18
+ // Run when one of the tasks finished running.
19
+ // Release next task if we have one, or allow more tasks to run in future.
20
+ protected readonly release = () => {
21
+ const task = this.tasks.shift();
22
+ if (task !== undefined) {
23
+ return task();
24
+ }
25
+ this.maxRequests++;
26
+ };
27
27
 
28
- protected async acquire() {
29
- if (this.maxRequests > 0) {
30
- this.maxRequests--;
31
- return;
32
- }
28
+ protected async acquire() {
29
+ if (this.maxRequests > 0) {
30
+ this.maxRequests--;
31
+ return;
32
+ }
33
33
 
34
- return new Promise<void>((resolve) => {
35
- this.tasks.push(resolve);
36
- });
37
- }
34
+ return new Promise<void>((resolve) => {
35
+ this.tasks.push(resolve);
36
+ });
37
+ }
38
38
 
39
- public async schedule<T>(work: () => Promise<T>) {
40
- await this.acquire();
41
- return work().finally(this.release);
42
- }
39
+ public async schedule<T>(work: () => Promise<T>) {
40
+ await this.acquire();
41
+ return work().finally(this.release);
42
+ }
43
43
  }
@@ -18,8 +18,11 @@ import { IDocumentStorageService } from "@fluidframework/driver-definitions";
18
18
  *
19
19
  * @returns The object that we decoded and parsed via `JSON.parse`.
20
20
  */
21
- export async function readAndParse<T>(storage: Pick<IDocumentStorageService, "readBlob">, id: string): Promise<T> {
22
- const blob = await storage.readBlob(id);
23
- const decoded = bufferToString(blob, "utf8");
24
- return JSON.parse(decoded) as T;
21
+ export async function readAndParse<T>(
22
+ storage: Pick<IDocumentStorageService, "readBlob">,
23
+ id: string,
24
+ ): Promise<T> {
25
+ const blob = await storage.readBlob(id);
26
+ const decoded = bufferToString(blob, "utf8");
27
+ return JSON.parse(decoded) as T;
25
28
  }
@@ -15,95 +15,117 @@ import { NonRetryableError } from ".";
15
15
  * It allows caller to control cancellation, as well as learn about any delays.
16
16
  */
17
17
  export interface IProgress {
18
- /**
19
- * Abort signal used to cancel operation.
20
- *
21
- * @remarks Note that most of the layers do not use this signal yet. We need to change that over time.
22
- * Please consult with API documentation / implementation.
23
- * Note that number of layers may not check this signal while holding this request in a queue,
24
- * so it may take a while it takes effect. This can be improved in the future.
25
- *
26
- * The layers in question are:
27
- *
28
- * - driver (RateLimiter)
29
- *
30
- * - runWithRetry
31
- */
32
- cancel?: AbortSignal;
18
+ /**
19
+ * Abort signal used to cancel operation.
20
+ *
21
+ * @remarks Note that most of the layers do not use this signal yet. We need to change that over time.
22
+ * Please consult with API documentation / implementation.
23
+ * Note that number of layers may not check this signal while holding this request in a queue,
24
+ * so it may take a while it takes effect. This can be improved in the future.
25
+ *
26
+ * The layers in question are:
27
+ *
28
+ * - driver (RateLimiter)
29
+ *
30
+ * - runWithRetry
31
+ */
32
+ cancel?: AbortSignal;
33
33
 
34
- /**
35
- * Called whenever api returns cancellable error and the call is going to be retried.
36
- * Any exception thrown from this call back result in cancellation of operation
37
- * and propagation of thrown exception.
38
- * @param delayInMs - delay before next retry. This value will depend on internal back-off logic,
39
- * as well as information provided by service (like 429 error asking to wait for some time before retry)
40
- * @param error - error object returned from the call.
41
- */
42
- onRetry?(delayInMs: number, error: any): void;
34
+ /**
35
+ * Called whenever api returns cancellable error and the call is going to be retried.
36
+ * Any exception thrown from this call back result in cancellation of operation
37
+ * and propagation of thrown exception.
38
+ * @param delayInMs - delay before next retry. This value will depend on internal back-off logic,
39
+ * as well as information provided by service (like 429 error asking to wait for some time before retry)
40
+ * @param error - error object returned from the call.
41
+ */
42
+ onRetry?(delayInMs: number, error: any): void;
43
43
  }
44
44
 
45
45
  export async function runWithRetry<T>(
46
- api: (cancel?: AbortSignal) => Promise<T>,
47
- fetchCallName: string,
48
- logger: ITelemetryLogger,
49
- progress: IProgress,
46
+ api: (cancel?: AbortSignal) => Promise<T>,
47
+ fetchCallName: string,
48
+ logger: ITelemetryLogger,
49
+ progress: IProgress,
50
50
  ): Promise<T> {
51
- let result: T | undefined;
52
- let success = false;
53
- let retryAfterMs = 1000; // has to be positive!
54
- let numRetries = 0;
55
- const startTime = performance.now();
56
- let lastError: any;
57
- do {
58
- try {
59
- result = await api(progress.cancel);
60
- success = true;
61
- } catch (err) {
62
- // If it is not retriable, then just throw the error.
63
- if (!canRetryOnError(err)) {
64
- logger.sendTelemetryEvent({
65
- eventName: `${fetchCallName}_cancel`,
66
- retry: numRetries,
67
- duration: performance.now() - startTime,
68
- fetchCallName,
69
- }, err);
70
- throw err;
71
- }
51
+ let result: T | undefined;
52
+ let success = false;
53
+ let retryAfterMs = 1000; // has to be positive!
54
+ let numRetries = 0;
55
+ const startTime = performance.now();
56
+ let lastError: any;
57
+ do {
58
+ try {
59
+ result = await api(progress.cancel);
60
+ success = true;
61
+ } catch (err) {
62
+ // If it is not retriable, then just throw the error.
63
+ if (!canRetryOnError(err)) {
64
+ logger.sendTelemetryEvent(
65
+ {
66
+ eventName: `${fetchCallName}_cancel`,
67
+ retry: numRetries,
68
+ duration: performance.now() - startTime,
69
+ fetchCallName,
70
+ },
71
+ err,
72
+ );
73
+ throw err;
74
+ }
72
75
 
73
- if (progress.cancel?.aborted === true) {
74
- logger.sendTelemetryEvent({
75
- eventName: `${fetchCallName}_runWithRetryAborted`,
76
- retry: numRetries,
77
- duration: performance.now() - startTime,
78
- fetchCallName,
79
- }, err);
80
- throw new NonRetryableError(
81
- "runWithRetry was Aborted",
82
- DriverErrorType.genericError,
83
- { driverVersion: pkgVersion, fetchCallName },
84
- );
85
- }
76
+ if (progress.cancel?.aborted === true) {
77
+ logger.sendTelemetryEvent(
78
+ {
79
+ eventName: `${fetchCallName}_runWithRetryAborted`,
80
+ retry: numRetries,
81
+ duration: performance.now() - startTime,
82
+ fetchCallName,
83
+ },
84
+ err,
85
+ );
86
+ throw new NonRetryableError(
87
+ "runWithRetry was Aborted",
88
+ DriverErrorType.genericError,
89
+ { driverVersion: pkgVersion, fetchCallName },
90
+ );
91
+ }
86
92
 
87
- numRetries++;
88
- lastError = err;
89
- // If the error is throttling error, then wait for the specified time before retrying.
90
- // If the waitTime is not specified, then we start with retrying immediately to max of 8s.
91
- retryAfterMs = getRetryDelayFromError(err) ?? Math.min(retryAfterMs * 2, 8000);
92
- if (progress.onRetry) {
93
- progress.onRetry(retryAfterMs, err);
94
- }
95
- await delay(retryAfterMs);
96
- }
97
- } while (!success);
98
- if (numRetries > 0) {
99
- logger.sendTelemetryEvent({
100
- eventName: `${fetchCallName}_lastError`,
101
- retry: numRetries,
102
- duration: performance.now() - startTime,
103
- fetchCallName,
104
- },
105
- lastError);
106
- }
107
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
108
- return result!;
93
+ // logging the first failed retry instead of every attempt. We want to avoid filling telemetry
94
+ // when we have tight loop of retrying in offline mode, but we also want to know what caused
95
+ // the failure in the first place
96
+ if (numRetries === 0) {
97
+ logger.sendTelemetryEvent(
98
+ {
99
+ eventName: `${fetchCallName}_firstFailed`,
100
+ duration: performance.now() - startTime,
101
+ fetchCallName,
102
+ },
103
+ err,
104
+ );
105
+ }
106
+
107
+ numRetries++;
108
+ lastError = err;
109
+ // If the error is throttling error, then wait for the specified time before retrying.
110
+ // If the waitTime is not specified, then we start with retrying immediately to max of 8s.
111
+ retryAfterMs = getRetryDelayFromError(err) ?? Math.min(retryAfterMs * 2, 8000);
112
+ if (progress.onRetry) {
113
+ progress.onRetry(retryAfterMs, err);
114
+ }
115
+ await delay(retryAfterMs);
116
+ }
117
+ } while (!success);
118
+ if (numRetries > 0) {
119
+ logger.sendTelemetryEvent(
120
+ {
121
+ eventName: `${fetchCallName}_lastError`,
122
+ retry: numRetries,
123
+ duration: performance.now() - startTime,
124
+ fetchCallName,
125
+ },
126
+ lastError,
127
+ );
128
+ }
129
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
130
+ return result!;
109
131
  }
@@ -3,31 +3,77 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
+ import { assert } from "@fluidframework/common-utils";
6
7
  import {
7
- ISummaryTree,
8
- SummaryType,
9
- ISummaryBlob,
10
- ICommittedProposal,
11
- IDocumentAttributes,
8
+ ISummaryTree,
9
+ SummaryType,
10
+ ISummaryBlob,
11
+ ICommittedProposal,
12
+ IDocumentAttributes,
12
13
  } from "@fluidframework/protocol-definitions";
13
14
 
15
+ /**
16
+ * Defines the current layout of an .app + .protocol summary tree
17
+ * this is used internally for create new, and single commit summary
18
+ * @internal
19
+ */
20
+ export interface CombinedAppAndProtocolSummary extends ISummaryTree {
21
+ tree: {
22
+ [".app"]: ISummaryTree;
23
+ [".protocol"]: ISummaryTree;
24
+ };
25
+ }
26
+
27
+ /**
28
+ * Validates the current layout of an .app + .protocol summary tree
29
+ * this is used internally for create new, and single commit summary
30
+ * @internal
31
+ */
32
+ export function isCombinedAppAndProtocolSummary(
33
+ summary: ISummaryTree | undefined,
34
+ ): summary is CombinedAppAndProtocolSummary {
35
+ if (
36
+ summary?.tree === undefined ||
37
+ summary.tree?.[".app"]?.type !== SummaryType.Tree ||
38
+ summary.tree?.[".protocol"]?.type !== SummaryType.Tree
39
+ ) {
40
+ return false;
41
+ }
42
+ const treeKeys = Object.keys(summary.tree);
43
+ if (treeKeys.length !== 2) {
44
+ return false;
45
+ }
46
+ return true;
47
+ }
48
+
14
49
  /**
15
50
  * Combine the app summary and protocol summary in 1 tree.
16
51
  * @param appSummary - Summary of the app.
17
52
  * @param protocolSummary - Summary of the protocol.
53
+ * @internal
54
+ *
55
+ * @deprecated 2.0.0-internal.3.4.0 - Not intended for public use. Will be moved to container-loader and no longer exported in an upcoming release.
18
56
  */
19
57
  export function combineAppAndProtocolSummary(
20
- appSummary: ISummaryTree,
21
- protocolSummary: ISummaryTree,
22
- ): ISummaryTree {
23
- const createNewSummary: ISummaryTree = {
24
- type: SummaryType.Tree,
25
- tree: {
26
- ".protocol": protocolSummary,
27
- ".app": appSummary,
28
- },
29
- };
30
- return createNewSummary;
58
+ appSummary: ISummaryTree,
59
+ protocolSummary: ISummaryTree,
60
+ ): CombinedAppAndProtocolSummary {
61
+ assert(
62
+ !isCombinedAppAndProtocolSummary(appSummary),
63
+ 0x5a8 /* app summary is already a combined tree! */,
64
+ );
65
+ assert(
66
+ !isCombinedAppAndProtocolSummary(protocolSummary),
67
+ 0x5a9 /* protocol summary is already a combined tree! */,
68
+ );
69
+ const createNewSummary: CombinedAppAndProtocolSummary = {
70
+ type: SummaryType.Tree,
71
+ tree: {
72
+ ".protocol": protocolSummary,
73
+ ".app": appSummary,
74
+ },
75
+ };
76
+ return createNewSummary;
31
77
  }
32
78
 
33
79
  /**
@@ -35,12 +81,12 @@ export function combineAppAndProtocolSummary(
35
81
  * @param protocolSummary - protocol summary from which the values are to be extracted.
36
82
  */
37
83
  export function getDocAttributesFromProtocolSummary(
38
- protocolSummary: ISummaryTree,
84
+ protocolSummary: ISummaryTree,
39
85
  ): IDocumentAttributes {
40
- const attributesBlob = protocolSummary.tree.attributes as ISummaryBlob;
41
- const documentAttributes = JSON.parse(attributesBlob.content as string) as IDocumentAttributes;
42
- documentAttributes.term = documentAttributes.term ?? 1;
43
- return documentAttributes;
86
+ const attributesBlob = protocolSummary.tree.attributes as ISummaryBlob;
87
+ const documentAttributes = JSON.parse(attributesBlob.content as string) as IDocumentAttributes;
88
+ documentAttributes.term = documentAttributes.term ?? 1;
89
+ return documentAttributes;
44
90
  }
45
91
 
46
92
  /**
@@ -48,9 +94,12 @@ export function getDocAttributesFromProtocolSummary(
48
94
  * @param protocolSummary - protocol summary from which the values are to be extracted.
49
95
  */
50
96
  export function getQuorumValuesFromProtocolSummary(
51
- protocolSummary: ISummaryTree,
97
+ protocolSummary: ISummaryTree,
52
98
  ): [string, ICommittedProposal][] {
53
- const quorumValuesBlob = protocolSummary.tree.quorumValues as ISummaryBlob;
54
- const quorumValues = JSON.parse(quorumValuesBlob.content as string) as [string, ICommittedProposal][];
55
- return quorumValues;
99
+ const quorumValuesBlob = protocolSummary.tree.quorumValues as ISummaryBlob;
100
+ const quorumValues = JSON.parse(quorumValuesBlob.content as string) as [
101
+ string,
102
+ ICommittedProposal,
103
+ ][];
104
+ return quorumValues;
56
105
  }