@fluidframework/driver-utils 2.0.0-internal.3.0.5 → 2.0.0-internal.3.1.1

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 +2 -2
  5. package/dist/blobAggregationStorage.d.ts.map +1 -1
  6. package/dist/blobAggregationStorage.js +11 -6
  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 +2 -2
  66. package/lib/blobAggregationStorage.d.ts.map +1 -1
  67. package/lib/blobAggregationStorage.js +11 -6
  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 +128 -127
  129. package/prettier.config.cjs +1 -1
  130. package/src/blobAggregationStorage.ts +374 -322
  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,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,106 +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
- // logging the first failed retry instead of every attempt. We want to avoid filling telemetry
88
- // when we have tight loop of retrying in offline mode, but we also want to know what caused
89
- // the failure in the first place
90
- if(numRetries === 0) {
91
- logger.sendTelemetryEvent({
92
- eventName: `${fetchCallName}_firstFailed`,
93
- duration: performance.now() - startTime,
94
- fetchCallName,
95
- }, err);
96
- }
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
+ }
97
106
 
98
- numRetries++;
99
- lastError = err;
100
- // If the error is throttling error, then wait for the specified time before retrying.
101
- // If the waitTime is not specified, then we start with retrying immediately to max of 8s.
102
- retryAfterMs = getRetryDelayFromError(err) ?? Math.min(retryAfterMs * 2, 8000);
103
- if (progress.onRetry) {
104
- progress.onRetry(retryAfterMs, err);
105
- }
106
- await delay(retryAfterMs);
107
- }
108
- } while (!success);
109
- if (numRetries > 0) {
110
- logger.sendTelemetryEvent({
111
- eventName: `${fetchCallName}_lastError`,
112
- retry: numRetries,
113
- duration: performance.now() - startTime,
114
- fetchCallName,
115
- },
116
- lastError);
117
- }
118
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
119
- return result!;
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!;
120
131
  }
@@ -4,11 +4,11 @@
4
4
  */
5
5
 
6
6
  import {
7
- ISummaryTree,
8
- SummaryType,
9
- ISummaryBlob,
10
- ICommittedProposal,
11
- IDocumentAttributes,
7
+ ISummaryTree,
8
+ SummaryType,
9
+ ISummaryBlob,
10
+ ICommittedProposal,
11
+ IDocumentAttributes,
12
12
  } from "@fluidframework/protocol-definitions";
13
13
 
14
14
  /**
@@ -17,17 +17,17 @@ import {
17
17
  * @param protocolSummary - Summary of the protocol.
18
18
  */
19
19
  export function combineAppAndProtocolSummary(
20
- appSummary: ISummaryTree,
21
- protocolSummary: ISummaryTree,
20
+ appSummary: ISummaryTree,
21
+ protocolSummary: ISummaryTree,
22
22
  ): ISummaryTree {
23
- const createNewSummary: ISummaryTree = {
24
- type: SummaryType.Tree,
25
- tree: {
26
- ".protocol": protocolSummary,
27
- ".app": appSummary,
28
- },
29
- };
30
- return createNewSummary;
23
+ const createNewSummary: ISummaryTree = {
24
+ type: SummaryType.Tree,
25
+ tree: {
26
+ ".protocol": protocolSummary,
27
+ ".app": appSummary,
28
+ },
29
+ };
30
+ return createNewSummary;
31
31
  }
32
32
 
33
33
  /**
@@ -35,12 +35,12 @@ export function combineAppAndProtocolSummary(
35
35
  * @param protocolSummary - protocol summary from which the values are to be extracted.
36
36
  */
37
37
  export function getDocAttributesFromProtocolSummary(
38
- protocolSummary: ISummaryTree,
38
+ protocolSummary: ISummaryTree,
39
39
  ): 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;
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;
44
44
  }
45
45
 
46
46
  /**
@@ -48,9 +48,12 @@ export function getDocAttributesFromProtocolSummary(
48
48
  * @param protocolSummary - protocol summary from which the values are to be extracted.
49
49
  */
50
50
  export function getQuorumValuesFromProtocolSummary(
51
- protocolSummary: ISummaryTree,
51
+ protocolSummary: ISummaryTree,
52
52
  ): [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;
53
+ const quorumValuesBlob = protocolSummary.tree.quorumValues as ISummaryBlob;
54
+ const quorumValues = JSON.parse(quorumValuesBlob.content as string) as [
55
+ string,
56
+ ICommittedProposal,
57
+ ][];
58
+ return quorumValues;
56
59
  }