@fluidframework/driver-utils 2.81.0 → 2.82.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 (216) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/adapters/compression/documentServiceCompressionAdapter.d.ts +2 -2
  3. package/dist/adapters/compression/documentServiceCompressionAdapter.d.ts.map +1 -1
  4. package/dist/adapters/compression/documentServiceCompressionAdapter.js.map +1 -1
  5. package/dist/adapters/compression/documentServiceFactoryCompressionAdapter.d.ts +4 -4
  6. package/dist/adapters/compression/documentServiceFactoryCompressionAdapter.d.ts.map +1 -1
  7. package/dist/adapters/compression/documentServiceFactoryCompressionAdapter.js.map +1 -1
  8. package/dist/adapters/compression/index.d.ts +1 -1
  9. package/dist/adapters/compression/index.d.ts.map +1 -1
  10. package/dist/adapters/compression/index.js.map +1 -1
  11. package/dist/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.d.ts +2 -2
  12. package/dist/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.d.ts.map +1 -1
  13. package/dist/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js +15 -11
  14. package/dist/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js.map +1 -1
  15. package/dist/adapters/index.d.ts +1 -1
  16. package/dist/adapters/index.d.ts.map +1 -1
  17. package/dist/adapters/index.js.map +1 -1
  18. package/dist/adapters/predefinedAdapters.d.ts +3 -3
  19. package/dist/adapters/predefinedAdapters.d.ts.map +1 -1
  20. package/dist/adapters/predefinedAdapters.js +4 -1
  21. package/dist/adapters/predefinedAdapters.js.map +1 -1
  22. package/dist/blob.d.ts +2 -1
  23. package/dist/blob.d.ts.map +1 -1
  24. package/dist/blob.js +3 -1
  25. package/dist/blob.js.map +1 -1
  26. package/dist/buildSnapshotTree.d.ts +1 -1
  27. package/dist/buildSnapshotTree.d.ts.map +1 -1
  28. package/dist/buildSnapshotTree.js.map +1 -1
  29. package/dist/cacheUtils.js +1 -1
  30. package/dist/cacheUtils.js.map +1 -1
  31. package/dist/documentServiceFactoryProxy.d.ts +3 -3
  32. package/dist/documentServiceFactoryProxy.d.ts.map +1 -1
  33. package/dist/documentServiceFactoryProxy.js.map +1 -1
  34. package/dist/documentServiceProxy.d.ts +3 -3
  35. package/dist/documentServiceProxy.d.ts.map +1 -1
  36. package/dist/documentServiceProxy.js.map +1 -1
  37. package/dist/documentStorageServiceProxy.d.ts +2 -2
  38. package/dist/documentStorageServiceProxy.d.ts.map +1 -1
  39. package/dist/documentStorageServiceProxy.js +3 -1
  40. package/dist/documentStorageServiceProxy.js.map +1 -1
  41. package/dist/error.d.ts +2 -2
  42. package/dist/error.d.ts.map +1 -1
  43. package/dist/error.js.map +1 -1
  44. package/dist/index.d.ts +4 -4
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js.map +1 -1
  47. package/dist/insecureUrlResolver.d.ts +2 -2
  48. package/dist/insecureUrlResolver.d.ts.map +1 -1
  49. package/dist/insecureUrlResolver.js +4 -4
  50. package/dist/insecureUrlResolver.js.map +1 -1
  51. package/dist/messageRecognition.d.ts +3 -1
  52. package/dist/messageRecognition.d.ts.map +1 -1
  53. package/dist/messageRecognition.js +2 -0
  54. package/dist/messageRecognition.js.map +1 -1
  55. package/dist/network.d.ts +10 -6
  56. package/dist/network.d.ts.map +1 -1
  57. package/dist/network.js +18 -3
  58. package/dist/network.js.map +1 -1
  59. package/dist/networkUtils.d.ts +4 -3
  60. package/dist/networkUtils.d.ts.map +1 -1
  61. package/dist/networkUtils.js +6 -0
  62. package/dist/networkUtils.js.map +1 -1
  63. package/dist/packageVersion.d.ts +1 -1
  64. package/dist/packageVersion.js +1 -1
  65. package/dist/packageVersion.js.map +1 -1
  66. package/dist/parallelRequests.d.ts +8 -4
  67. package/dist/parallelRequests.d.ts.map +1 -1
  68. package/dist/parallelRequests.js +24 -21
  69. package/dist/parallelRequests.js.map +1 -1
  70. package/dist/prefetchDocumentStorageService.d.ts.map +1 -1
  71. package/dist/prefetchDocumentStorageService.js +8 -10
  72. package/dist/prefetchDocumentStorageService.js.map +1 -1
  73. package/dist/protocol/gitHelper.d.ts +1 -1
  74. package/dist/protocol/gitHelper.d.ts.map +1 -1
  75. package/dist/protocol/gitHelper.js +12 -6
  76. package/dist/protocol/gitHelper.js.map +1 -1
  77. package/dist/readAndParse.d.ts +1 -1
  78. package/dist/readAndParse.d.ts.map +1 -1
  79. package/dist/readAndParse.js.map +1 -1
  80. package/dist/runWithRetry.d.ts +4 -2
  81. package/dist/runWithRetry.d.ts.map +1 -1
  82. package/dist/runWithRetry.js +14 -11
  83. package/dist/runWithRetry.js.map +1 -1
  84. package/dist/storageUtils.d.ts +1 -1
  85. package/dist/storageUtils.d.ts.map +1 -1
  86. package/dist/storageUtils.js.map +1 -1
  87. package/dist/summaryForCreateNew.d.ts +2 -2
  88. package/dist/summaryForCreateNew.d.ts.map +1 -1
  89. package/dist/summaryForCreateNew.js.map +1 -1
  90. package/dist/treeConversions.d.ts +2 -2
  91. package/dist/treeConversions.d.ts.map +1 -1
  92. package/dist/treeConversions.js +3 -1
  93. package/dist/treeConversions.js.map +1 -1
  94. package/eslint.config.mts +2 -2
  95. package/lib/adapters/compression/documentServiceCompressionAdapter.d.ts +2 -2
  96. package/lib/adapters/compression/documentServiceCompressionAdapter.d.ts.map +1 -1
  97. package/lib/adapters/compression/documentServiceCompressionAdapter.js.map +1 -1
  98. package/lib/adapters/compression/documentServiceFactoryCompressionAdapter.d.ts +4 -4
  99. package/lib/adapters/compression/documentServiceFactoryCompressionAdapter.d.ts.map +1 -1
  100. package/lib/adapters/compression/documentServiceFactoryCompressionAdapter.js.map +1 -1
  101. package/lib/adapters/compression/index.d.ts +1 -1
  102. package/lib/adapters/compression/index.d.ts.map +1 -1
  103. package/lib/adapters/compression/index.js.map +1 -1
  104. package/lib/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.d.ts +2 -2
  105. package/lib/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.d.ts.map +1 -1
  106. package/lib/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js +15 -11
  107. package/lib/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js.map +1 -1
  108. package/lib/adapters/index.d.ts +1 -1
  109. package/lib/adapters/index.d.ts.map +1 -1
  110. package/lib/adapters/index.js.map +1 -1
  111. package/lib/adapters/predefinedAdapters.d.ts +3 -3
  112. package/lib/adapters/predefinedAdapters.d.ts.map +1 -1
  113. package/lib/adapters/predefinedAdapters.js +4 -1
  114. package/lib/adapters/predefinedAdapters.js.map +1 -1
  115. package/lib/blob.d.ts +2 -1
  116. package/lib/blob.d.ts.map +1 -1
  117. package/lib/blob.js +4 -2
  118. package/lib/blob.js.map +1 -1
  119. package/lib/buildSnapshotTree.d.ts +1 -1
  120. package/lib/buildSnapshotTree.d.ts.map +1 -1
  121. package/lib/buildSnapshotTree.js.map +1 -1
  122. package/lib/cacheUtils.js +1 -1
  123. package/lib/cacheUtils.js.map +1 -1
  124. package/lib/documentServiceFactoryProxy.d.ts +3 -3
  125. package/lib/documentServiceFactoryProxy.d.ts.map +1 -1
  126. package/lib/documentServiceFactoryProxy.js.map +1 -1
  127. package/lib/documentServiceProxy.d.ts +3 -3
  128. package/lib/documentServiceProxy.d.ts.map +1 -1
  129. package/lib/documentServiceProxy.js.map +1 -1
  130. package/lib/documentStorageServiceProxy.d.ts +2 -2
  131. package/lib/documentStorageServiceProxy.d.ts.map +1 -1
  132. package/lib/documentStorageServiceProxy.js +3 -1
  133. package/lib/documentStorageServiceProxy.js.map +1 -1
  134. package/lib/error.d.ts +2 -2
  135. package/lib/error.d.ts.map +1 -1
  136. package/lib/error.js.map +1 -1
  137. package/lib/index.d.ts +4 -4
  138. package/lib/index.d.ts.map +1 -1
  139. package/lib/index.js.map +1 -1
  140. package/lib/insecureUrlResolver.d.ts +2 -2
  141. package/lib/insecureUrlResolver.d.ts.map +1 -1
  142. package/lib/insecureUrlResolver.js +4 -4
  143. package/lib/insecureUrlResolver.js.map +1 -1
  144. package/lib/messageRecognition.d.ts +3 -1
  145. package/lib/messageRecognition.d.ts.map +1 -1
  146. package/lib/messageRecognition.js +2 -0
  147. package/lib/messageRecognition.js.map +1 -1
  148. package/lib/network.d.ts +10 -6
  149. package/lib/network.d.ts.map +1 -1
  150. package/lib/network.js +18 -3
  151. package/lib/network.js.map +1 -1
  152. package/lib/networkUtils.d.ts +4 -3
  153. package/lib/networkUtils.d.ts.map +1 -1
  154. package/lib/networkUtils.js +6 -0
  155. package/lib/networkUtils.js.map +1 -1
  156. package/lib/packageVersion.d.ts +1 -1
  157. package/lib/packageVersion.js +1 -1
  158. package/lib/packageVersion.js.map +1 -1
  159. package/lib/parallelRequests.d.ts +8 -4
  160. package/lib/parallelRequests.d.ts.map +1 -1
  161. package/lib/parallelRequests.js +24 -21
  162. package/lib/parallelRequests.js.map +1 -1
  163. package/lib/prefetchDocumentStorageService.d.ts.map +1 -1
  164. package/lib/prefetchDocumentStorageService.js +8 -10
  165. package/lib/prefetchDocumentStorageService.js.map +1 -1
  166. package/lib/protocol/gitHelper.d.ts +1 -1
  167. package/lib/protocol/gitHelper.d.ts.map +1 -1
  168. package/lib/protocol/gitHelper.js +12 -6
  169. package/lib/protocol/gitHelper.js.map +1 -1
  170. package/lib/readAndParse.d.ts +1 -1
  171. package/lib/readAndParse.d.ts.map +1 -1
  172. package/lib/readAndParse.js.map +1 -1
  173. package/lib/runWithRetry.d.ts +4 -2
  174. package/lib/runWithRetry.d.ts.map +1 -1
  175. package/lib/runWithRetry.js +15 -12
  176. package/lib/runWithRetry.js.map +1 -1
  177. package/lib/storageUtils.d.ts +1 -1
  178. package/lib/storageUtils.d.ts.map +1 -1
  179. package/lib/storageUtils.js.map +1 -1
  180. package/lib/summaryForCreateNew.d.ts +2 -2
  181. package/lib/summaryForCreateNew.d.ts.map +1 -1
  182. package/lib/summaryForCreateNew.js +1 -1
  183. package/lib/summaryForCreateNew.js.map +1 -1
  184. package/lib/treeConversions.d.ts +2 -2
  185. package/lib/treeConversions.d.ts.map +1 -1
  186. package/lib/treeConversions.js +3 -1
  187. package/lib/treeConversions.js.map +1 -1
  188. package/package.json +11 -10
  189. package/src/adapters/compression/documentServiceCompressionAdapter.ts +2 -2
  190. package/src/adapters/compression/documentServiceFactoryCompressionAdapter.ts +4 -4
  191. package/src/adapters/compression/index.ts +1 -1
  192. package/src/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.ts +25 -21
  193. package/src/adapters/index.ts +1 -1
  194. package/src/adapters/predefinedAdapters.ts +7 -4
  195. package/src/blob.ts +3 -7
  196. package/src/buildSnapshotTree.ts +6 -6
  197. package/src/cacheUtils.ts +1 -1
  198. package/src/documentServiceFactoryProxy.ts +3 -3
  199. package/src/documentServiceProxy.ts +3 -3
  200. package/src/documentStorageServiceProxy.ts +4 -2
  201. package/src/error.ts +2 -2
  202. package/src/index.ts +4 -4
  203. package/src/insecureUrlResolver.ts +7 -7
  204. package/src/messageRecognition.ts +4 -2
  205. package/src/network.ts +26 -12
  206. package/src/networkUtils.ts +12 -4
  207. package/src/packageVersion.ts +1 -1
  208. package/src/parallelRequests.ts +33 -30
  209. package/src/prefetchDocumentStorageService.ts +10 -10
  210. package/src/protocol/gitHelper.ts +15 -9
  211. package/src/readAndParse.ts +1 -1
  212. package/src/runWithRetry.ts +20 -14
  213. package/src/storageUtils.ts +1 -1
  214. package/src/summaryForCreateNew.ts +5 -1
  215. package/src/treeConversions.ts +5 -3
  216. package/biome.jsonc +0 -4
package/lib/network.d.ts CHANGED
@@ -2,9 +2,9 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { ITelemetryBaseProperties } from "@fluidframework/core-interfaces";
6
- import { IAuthorizationError, ILocationRedirectionError, IResolvedUrl, IThrottlingWarning, IDriverErrorBase } from "@fluidframework/driver-definitions/internal";
7
- import { IFluidErrorBase, LoggingError } from "@fluidframework/telemetry-utils/internal";
5
+ import type { ITelemetryBaseProperties } from "@fluidframework/core-interfaces";
6
+ import { type IAuthorizationError, type ILocationRedirectionError, type IResolvedUrl, type IThrottlingWarning, type IDriverErrorBase } from "@fluidframework/driver-definitions/internal";
7
+ import { type IFluidErrorBase, LoggingError } from "@fluidframework/telemetry-utils/internal";
8
8
  /**
9
9
  * @internal
10
10
  */
@@ -110,10 +110,14 @@ export declare class ThrottlingError extends LoggingError implements IThrottling
110
110
  constructor(message: string, retryAfterSeconds: number, props: DriverErrorTelemetryProps);
111
111
  }
112
112
  /**
113
+ * Creates a non-retryable write error.
114
+ *
113
115
  * @internal
114
116
  */
115
117
  export declare const createWriteError: (message: string, props: DriverErrorTelemetryProps) => NonRetryableError<"writeError">;
116
118
  /**
119
+ * Creates a generic network error, either throttling or non-throttling based on the provided retry information.
120
+ *
117
121
  * @internal
118
122
  */
119
123
  export declare function createGenericNetworkError(message: string, retryInfo: {
@@ -126,15 +130,15 @@ export declare function createGenericNetworkError(message: string, retryInfo: {
126
130
  * @param error - The error to inspect for ability to retry
127
131
  * @internal
128
132
  */
129
- export declare const canRetryOnError: (error: any) => boolean;
133
+ export declare const canRetryOnError: (error: unknown) => boolean;
130
134
  /**
131
135
  * Check retryAfterSeconds property on error
132
136
  * @internal
133
137
  */
134
- export declare const getRetryDelaySecondsFromError: (error: any) => number | undefined;
138
+ export declare const getRetryDelaySecondsFromError: (error: unknown) => number | undefined;
135
139
  /**
136
140
  * Check retryAfterSeconds property on error and convert to ms
137
141
  * @internal
138
142
  */
139
- export declare const getRetryDelayFromError: (error: any) => number | undefined;
143
+ export declare const getRetryDelayFromError: (error: unknown) => number | undefined;
140
144
  //# sourceMappingURL=network.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../src/network.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,wBA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AAC,iBAAiB,EAAE,MAAM;IALnC,QAAQ,CAAC,SAAS,oBAAoC;IACtD,QAAQ,CAAC,QAAQ,QAAQ;gBAGxB,OAAO,EAAE,MAAM,EACN,iBAAiB,EAAE,MAAM,EAClC,KAAK,EAAE,yBAAyB;CAIjC;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,YACnB,MAAM,SACR,yBAAyB,KAC9B,kBAAkB,YAAY,CACkC,CAAC;AAEpE;;;;GAIG;AACH,wBAAgB,yBAAyB,CACxC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE;IAAE,QAAQ,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,EACvD,KAAK,EAAE,yBAAyB,GAC9B,eAAe,GAAG,mBAAmB,CAKvC;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,UAAW,OAAO,KAAG,OAGG,CAAC;AAErD;;;GAGG;AACH,eAAO,MAAM,6BAA6B,UAAW,OAAO,KAAG,MAAM,GAAG,SAMvE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,UAAW,OAAO,KAAG,MAAM,GAAG,SAGhE,CAAC"}
package/lib/network.js CHANGED
@@ -134,10 +134,14 @@ export class ThrottlingError extends LoggingError {
134
134
  }
135
135
  }
136
136
  /**
137
+ * Creates a non-retryable write error.
138
+ *
137
139
  * @internal
138
140
  */
139
141
  export const createWriteError = (message, props) => new NonRetryableError(message, DriverErrorTypes.writeError, props);
140
142
  /**
143
+ * Creates a generic network error, either throttling or non-throttling based on the provided retry information.
144
+ *
141
145
  * @internal
142
146
  */
143
147
  export function createGenericNetworkError(message, retryInfo, props) {
@@ -152,15 +156,26 @@ export function createGenericNetworkError(message, retryInfo, props) {
152
156
  * @param error - The error to inspect for ability to retry
153
157
  * @internal
154
158
  */
155
- export const canRetryOnError = (error) => error?.canRetry === true;
159
+ export const canRetryOnError = (error) => typeof error === "object" &&
160
+ error !== null &&
161
+ error.canRetry === true;
156
162
  /**
157
163
  * Check retryAfterSeconds property on error
158
164
  * @internal
159
165
  */
160
- export const getRetryDelaySecondsFromError = (error) => error?.retryAfterSeconds;
166
+ export const getRetryDelaySecondsFromError = (error) => {
167
+ if (typeof error === "object" && error !== null) {
168
+ const retryAfterSeconds = error.retryAfterSeconds;
169
+ return typeof retryAfterSeconds === "number" ? retryAfterSeconds : undefined;
170
+ }
171
+ return undefined;
172
+ };
161
173
  /**
162
174
  * Check retryAfterSeconds property on error and convert to ms
163
175
  * @internal
164
176
  */
165
- export const getRetryDelayFromError = (error) => error?.retryAfterSeconds !== undefined ? error.retryAfterSeconds * 1000 : undefined;
177
+ export const getRetryDelayFromError = (error) => {
178
+ const retryAfterSeconds = getRetryDelaySecondsFromError(error);
179
+ return retryAfterSeconds === undefined ? undefined : retryAfterSeconds * 1000;
180
+ };
166
181
  //# sourceMappingURL=network.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"network.js","sourceRoot":"","sources":["../src/network.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAKN,gBAAgB,GAEhB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAmB,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAEzF;;GAEG;AACH,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACvB,qDAAO,CAAA;IACP,mDAAM,CAAA;IACN,qDAAO,CAAA;AACR,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ;IACvB,IACC,OAAO,SAAS,KAAK,QAAQ;QAC7B,SAAS,KAAK,IAAI;QAClB,OAAO,SAAS,CAAC,MAAM,KAAK,SAAS,EACpC,CAAC;QACF,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC;IACtE,CAAC;IACD,OAAO,YAAY,CAAC,OAAO,CAAC;AAC7B,CAAC;AAUD;;;GA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T License.\n */\n\nimport { ITelemetryBaseProperties } from \"@fluidframework/core-interfaces\";\nimport {\n\tIAuthorizationError,\n\tILocationRedirectionError,\n\tIResolvedUrl,\n\tIThrottlingWarning,\n\tDriverErrorTypes,\n\tIDriverErrorBase,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { IFluidErrorBase, LoggingError } from \"@fluidframework/telemetry-utils/internal\";\n\n/**\n * @internal\n */\nexport enum OnlineStatus {\n\tOffline,\n\tOnline,\n\tUnknown,\n}\n\n/**\n * It tells if we have local connection only - we might not have connection to web.\n * No solution for node.js (other than resolve dns names / ping specific sites)\n * Can also use window.addEventListener(\"online\" / \"offline\")\n * @internal\n */\nexport function isOnline(): OnlineStatus {\n\tif (\n\t\ttypeof navigator === \"object\" &&\n\t\tnavigator !== null &&\n\t\ttypeof navigator.onLine === \"boolean\"\n\t) {\n\t\treturn navigator.onLine ? OnlineStatus.Online : OnlineStatus.Offline;\n\t}\n\treturn OnlineStatus.Unknown;\n}\n\n/**\n * Telemetry props with driver-specific required properties\n * @internal\n */\nexport type DriverErrorTelemetryProps = ITelemetryBaseProperties & {\n\tdriverVersion: string | undefined;\n};\n\n/**\n * Generic network error class.\n * @internal\n */\nexport class GenericNetworkError\n\textends LoggingError\n\timplements IDriverErrorBase, IFluidErrorBase\n{\n\t/**\n\t * {@inheritDoc @fluidframework/telemetry-utils#IFluidErrorBase.errorType}\n\t */\n\treadonly errorType = DriverErrorTypes.genericNetworkError;\n\n\tconstructor(\n\t\tmessage: string,\n\t\treadonly canRetry: boolean,\n\t\tprops: DriverErrorTelemetryProps,\n\t) {\n\t\tsuper(message, props);\n\t}\n}\n\n/**\n * FluidInvalidSchema error class.\n * @internal\n */\nexport class FluidInvalidSchemaError\n\textends LoggingError\n\timplements IDriverErrorBase, IFluidErrorBase\n{\n\treadonly errorType = DriverErrorTypes.fluidInvalidSchema;\n\treadonly canRetry = false;\n\n\tconstructor(message: string, props: DriverErrorTelemetryProps) {\n\t\tsuper(message, props);\n\t}\n}\n\n/**\n * @internal\n */\nexport class DeltaStreamConnectionForbiddenError\n\textends LoggingError\n\timplements IDriverErrorBase, IFluidErrorBase\n{\n\tstatic readonly errorType = DriverErrorTypes.deltaStreamConnectionForbidden;\n\treadonly errorType = DeltaStreamConnectionForbiddenError.errorType;\n\treadonly canRetry = false;\n\treadonly storageOnlyReason: string | undefined;\n\n\tconstructor(message: string, props: DriverErrorTelemetryProps, storageOnlyReason?: string) {\n\t\tsuper(message, { ...props, statusCode: 400 });\n\t\tthis.storageOnlyReason = storageOnlyReason;\n\t}\n}\n\n/**\n * @internal\n */\nexport class AuthorizationError\n\textends LoggingError\n\timplements IAuthorizationError, IFluidErrorBase\n{\n\treadonly errorType = DriverErrorTypes.authorizationError;\n\n\t// These properties are not assigned in this class, but instead assigned in the super constructor.\n\t// When targeting ES 2022 or later, TypeScript would generate ES6 class fields for these properties if they did not use \"declare\".\n\t// That would override the own properties dynamically created in the super constructor\n\t// resulting in these properties always holding `undefined` instead of their desired values.\n\t// To prevent this undesired overriding,\n\t// these are declared using `declare` to indicate this definition is only for the TypeScript typing,\n\t// and the actual fields come from elsewhere.\n\tdeclare readonly claims?: string;\n\tdeclare readonly tenantId?: string;\n\n\treadonly canRetry = false;\n\n\tconstructor(\n\t\tmessage: string,\n\t\tclaims: string | undefined,\n\t\ttenantId: string | undefined,\n\t\tprops: DriverErrorTelemetryProps,\n\t) {\n\t\tif (claims !== undefined) {\n\t\t\tprops.claims = claims;\n\t\t}\n\t\tif (tenantId !== undefined) {\n\t\t\tprops.tenantId = tenantId;\n\t\t}\n\t\t// don't log claims or tenantId\n\t\tsuper(message, props, new Set([\"claims\", \"tenantId\"]));\n\t}\n}\n\n/**\n * @internal\n */\nexport class LocationRedirectionError\n\textends LoggingError\n\timplements ILocationRedirectionError, IFluidErrorBase\n{\n\treadonly errorType = DriverErrorTypes.locationRedirection;\n\treadonly canRetry = false;\n\n\tconstructor(\n\t\tmessage: string,\n\t\treadonly redirectUrl: IResolvedUrl,\n\t\tprops: DriverErrorTelemetryProps,\n\t) {\n\t\t// do not log redirectURL\n\t\tsuper(message, props, new Set([\"redirectUrl\"]));\n\t}\n}\n\n/**\n * @internal\n */\nexport class NetworkErrorBasic<T extends string>\n\textends LoggingError\n\timplements IFluidErrorBase\n{\n\tconstructor(\n\t\tmessage: string,\n\t\treadonly errorType: T,\n\t\treadonly canRetry: boolean,\n\t\tprops: DriverErrorTelemetryProps,\n\t) {\n\t\tsuper(message, props);\n\t}\n}\n\n/**\n * @internal\n */\nexport class NonRetryableError<T extends string> extends NetworkErrorBasic<T> {\n\tconstructor(\n\t\tmessage: string,\n\t\treadonly errorType: T,\n\t\tprops: DriverErrorTelemetryProps,\n\t) {\n\t\tsuper(message, errorType, false, props);\n\t}\n}\n\n/**\n * @internal\n */\nexport class RetryableError<T extends string> extends NetworkErrorBasic<T> {\n\tconstructor(\n\t\tmessage: string,\n\t\treadonly errorType: T,\n\t\tprops: DriverErrorTelemetryProps,\n\t) {\n\t\tsuper(message, errorType, true, props);\n\t}\n}\n\n/**\n * Throttling error class - used to communicate all throttling errors\n * @internal\n */\nexport class ThrottlingError\n\textends LoggingError\n\timplements IThrottlingWarning, IFluidErrorBase\n{\n\treadonly errorType = DriverErrorTypes.throttlingError;\n\treadonly canRetry = true;\n\n\tconstructor(\n\t\tmessage: string,\n\t\treadonly retryAfterSeconds: number,\n\t\tprops: DriverErrorTelemetryProps,\n\t) {\n\t\tsuper(message, props);\n\t}\n}\n\n/**\n * @internal\n */\nexport const createWriteError = (\n\tmessage: string,\n\tprops: DriverErrorTelemetryProps,\n): NonRetryableError<\"writeError\"> =>\n\tnew NonRetryableError(message, DriverErrorTypes.writeError, props);\n\n/**\n * @internal\n */\nexport function createGenericNetworkError(\n\tmessage: string,\n\tretryInfo: { canRetry: boolean; retryAfterMs?: number },\n\tprops: DriverErrorTelemetryProps,\n): ThrottlingError | GenericNetworkError {\n\tif (retryInfo.retryAfterMs !== undefined && retryInfo.canRetry) {\n\t\treturn new ThrottlingError(message, retryInfo.retryAfterMs / 1000, props);\n\t}\n\treturn new GenericNetworkError(message, retryInfo.canRetry, props);\n}\n\n/**\n * Check if a connection error can be retried. Unless explicitly allowed, retry is disallowed.\n * I.e. asserts or unexpected exceptions in our code result in container failure.\n * @param error - The error to inspect for ability to retry\n * @internal\n */\nexport const canRetryOnError = (error: any): boolean => error?.canRetry === true;\n\n/**\n * Check retryAfterSeconds property on error\n * @internal\n */\nexport const getRetryDelaySecondsFromError = (error: any): number | undefined =>\n\terror?.retryAfterSeconds as number | undefined;\n\n/**\n * Check retryAfterSeconds property on error and convert to ms\n * @internal\n */\nexport const getRetryDelayFromError = (error: any): number | undefined =>\n\terror?.retryAfterSeconds !== undefined ? error.retryAfterSeconds * 1000 : undefined;\n"]}
1
+ {"version":3,"file":"network.js","sourceRoot":"","sources":["../src/network.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,gBAAgB,GAMhB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAwB,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAE9F;;GAEG;AACH,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACvB,qDAAO,CAAA;IACP,mDAAM,CAAA;IACN,qDAAO,CAAA;AACR,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ;IACvB,IACC,OAAO,SAAS,KAAK,QAAQ;QAC7B,SAAS,KAAK,IAAI;QAClB,OAAO,SAAS,CAAC,MAAM,KAAK,SAAS,EACpC,CAAC;QACF,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC;IACtE,CAAC;IACD,OAAO,YAAY,CAAC,OAAO,CAAC;AAC7B,CAAC;AAUD;;;GAGG;AACH,MAAM,OAAO,mBACZ,SAAQ,YAAY;IAQpB,YACC,OAAe,EACN,QAAiB,EAC1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AAM,sBAAsB,GAAG,CAAC,KAAc,EAAsB,EAAE;IAC5E,MAAM,iBAAiB,GAAG,6BAA6B,CAAC,KAAK,CAAC,CAAC;IAC/D,OAAO,iBAAiB,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB,GAAG,IAAI,CAAC;AAC/E,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ITelemetryBaseProperties } from \"@fluidframework/core-interfaces\";\nimport {\n\tDriverErrorTypes,\n\ttype IAuthorizationError,\n\ttype ILocationRedirectionError,\n\ttype IResolvedUrl,\n\ttype IThrottlingWarning,\n\ttype IDriverErrorBase,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { type IFluidErrorBase, LoggingError } from \"@fluidframework/telemetry-utils/internal\";\n\n/**\n * @internal\n */\nexport enum OnlineStatus {\n\tOffline,\n\tOnline,\n\tUnknown,\n}\n\n/**\n * It tells if we have local connection only - we might not have connection to web.\n * No solution for node.js (other than resolve dns names / ping specific sites)\n * Can also use window.addEventListener(\"online\" / \"offline\")\n * @internal\n */\nexport function isOnline(): OnlineStatus {\n\tif (\n\t\ttypeof navigator === \"object\" &&\n\t\tnavigator !== null &&\n\t\ttypeof navigator.onLine === \"boolean\"\n\t) {\n\t\treturn navigator.onLine ? OnlineStatus.Online : OnlineStatus.Offline;\n\t}\n\treturn OnlineStatus.Unknown;\n}\n\n/**\n * Telemetry props with driver-specific required properties\n * @internal\n */\nexport type DriverErrorTelemetryProps = ITelemetryBaseProperties & {\n\tdriverVersion: string | undefined;\n};\n\n/**\n * Generic network error class.\n * @internal\n */\nexport class GenericNetworkError\n\textends LoggingError\n\timplements IDriverErrorBase, IFluidErrorBase\n{\n\t/**\n\t * {@inheritDoc @fluidframework/telemetry-utils#IFluidErrorBase.errorType}\n\t */\n\treadonly errorType = DriverErrorTypes.genericNetworkError;\n\n\tconstructor(\n\t\tmessage: string,\n\t\treadonly canRetry: boolean,\n\t\tprops: DriverErrorTelemetryProps,\n\t) {\n\t\tsuper(message, props);\n\t}\n}\n\n/**\n * FluidInvalidSchema error class.\n * @internal\n */\nexport class FluidInvalidSchemaError\n\textends LoggingError\n\timplements IDriverErrorBase, IFluidErrorBase\n{\n\treadonly errorType = DriverErrorTypes.fluidInvalidSchema;\n\treadonly canRetry = false;\n\n\tconstructor(message: string, props: DriverErrorTelemetryProps) {\n\t\tsuper(message, props);\n\t}\n}\n\n/**\n * @internal\n */\nexport class DeltaStreamConnectionForbiddenError\n\textends LoggingError\n\timplements IDriverErrorBase, IFluidErrorBase\n{\n\tstatic readonly errorType = DriverErrorTypes.deltaStreamConnectionForbidden;\n\treadonly errorType = DeltaStreamConnectionForbiddenError.errorType;\n\treadonly canRetry = false;\n\treadonly storageOnlyReason: string | undefined;\n\n\tconstructor(message: string, props: DriverErrorTelemetryProps, storageOnlyReason?: string) {\n\t\tsuper(message, { ...props, statusCode: 400 });\n\t\tthis.storageOnlyReason = storageOnlyReason;\n\t}\n}\n\n/**\n * @internal\n */\nexport class AuthorizationError\n\textends LoggingError\n\timplements IAuthorizationError, IFluidErrorBase\n{\n\treadonly errorType = DriverErrorTypes.authorizationError;\n\n\t// These properties are not assigned in this class, but instead assigned in the super constructor.\n\t// When targeting ES 2022 or later, TypeScript would generate ES6 class fields for these properties if they did not use \"declare\".\n\t// That would override the own properties dynamically created in the super constructor\n\t// resulting in these properties always holding `undefined` instead of their desired values.\n\t// To prevent this undesired overriding,\n\t// these are declared using `declare` to indicate this definition is only for the TypeScript typing,\n\t// and the actual fields come from elsewhere.\n\tdeclare readonly claims?: string;\n\tdeclare readonly tenantId?: string;\n\n\treadonly canRetry = false;\n\n\tconstructor(\n\t\tmessage: string,\n\t\tclaims: string | undefined,\n\t\ttenantId: string | undefined,\n\t\tprops: DriverErrorTelemetryProps,\n\t) {\n\t\tif (claims !== undefined) {\n\t\t\tprops.claims = claims;\n\t\t}\n\t\tif (tenantId !== undefined) {\n\t\t\tprops.tenantId = tenantId;\n\t\t}\n\t\t// don't log claims or tenantId\n\t\tsuper(message, props, new Set([\"claims\", \"tenantId\"]));\n\t}\n}\n\n/**\n * @internal\n */\nexport class LocationRedirectionError\n\textends LoggingError\n\timplements ILocationRedirectionError, IFluidErrorBase\n{\n\treadonly errorType = DriverErrorTypes.locationRedirection;\n\treadonly canRetry = false;\n\n\tconstructor(\n\t\tmessage: string,\n\t\treadonly redirectUrl: IResolvedUrl,\n\t\tprops: DriverErrorTelemetryProps,\n\t) {\n\t\t// do not log redirectURL\n\t\tsuper(message, props, new Set([\"redirectUrl\"]));\n\t}\n}\n\n/**\n * @internal\n */\nexport class NetworkErrorBasic<T extends string>\n\textends LoggingError\n\timplements IFluidErrorBase\n{\n\tconstructor(\n\t\tmessage: string,\n\t\treadonly errorType: T,\n\t\treadonly canRetry: boolean,\n\t\tprops: DriverErrorTelemetryProps,\n\t) {\n\t\tsuper(message, props);\n\t}\n}\n\n/**\n * @internal\n */\nexport class NonRetryableError<T extends string> extends NetworkErrorBasic<T> {\n\tconstructor(\n\t\tmessage: string,\n\t\treadonly errorType: T,\n\t\tprops: DriverErrorTelemetryProps,\n\t) {\n\t\tsuper(message, errorType, false, props);\n\t}\n}\n\n/**\n * @internal\n */\nexport class RetryableError<T extends string> extends NetworkErrorBasic<T> {\n\tconstructor(\n\t\tmessage: string,\n\t\treadonly errorType: T,\n\t\tprops: DriverErrorTelemetryProps,\n\t) {\n\t\tsuper(message, errorType, true, props);\n\t}\n}\n\n/**\n * Throttling error class - used to communicate all throttling errors\n * @internal\n */\nexport class ThrottlingError\n\textends LoggingError\n\timplements IThrottlingWarning, IFluidErrorBase\n{\n\treadonly errorType = DriverErrorTypes.throttlingError;\n\treadonly canRetry = true;\n\n\tconstructor(\n\t\tmessage: string,\n\t\treadonly retryAfterSeconds: number,\n\t\tprops: DriverErrorTelemetryProps,\n\t) {\n\t\tsuper(message, props);\n\t}\n}\n\n/**\n * Creates a non-retryable write error.\n *\n * @internal\n */\nexport const createWriteError = (\n\tmessage: string,\n\tprops: DriverErrorTelemetryProps,\n): NonRetryableError<\"writeError\"> =>\n\tnew NonRetryableError(message, DriverErrorTypes.writeError, props);\n\n/**\n * Creates a generic network error, either throttling or non-throttling based on the provided retry information.\n *\n * @internal\n */\nexport function createGenericNetworkError(\n\tmessage: string,\n\tretryInfo: { canRetry: boolean; retryAfterMs?: number },\n\tprops: DriverErrorTelemetryProps,\n): ThrottlingError | GenericNetworkError {\n\tif (retryInfo.retryAfterMs !== undefined && retryInfo.canRetry) {\n\t\treturn new ThrottlingError(message, retryInfo.retryAfterMs / 1000, props);\n\t}\n\treturn new GenericNetworkError(message, retryInfo.canRetry, props);\n}\n\n/**\n * Check if a connection error can be retried. Unless explicitly allowed, retry is disallowed.\n * I.e. asserts or unexpected exceptions in our code result in container failure.\n * @param error - The error to inspect for ability to retry\n * @internal\n */\nexport const canRetryOnError = (error: unknown): boolean =>\n\ttypeof error === \"object\" &&\n\terror !== null &&\n\t(error as { canRetry?: boolean }).canRetry === true;\n\n/**\n * Check retryAfterSeconds property on error\n * @internal\n */\nexport const getRetryDelaySecondsFromError = (error: unknown): number | undefined => {\n\tif (typeof error === \"object\" && error !== null) {\n\t\tconst retryAfterSeconds = (error as { retryAfterSeconds?: unknown }).retryAfterSeconds;\n\t\treturn typeof retryAfterSeconds === \"number\" ? retryAfterSeconds : undefined;\n\t}\n\treturn undefined;\n};\n\n/**\n * Check retryAfterSeconds property on error and convert to ms\n * @internal\n */\nexport const getRetryDelayFromError = (error: unknown): number | undefined => {\n\tconst retryAfterSeconds = getRetryDelaySecondsFromError(error);\n\treturn retryAfterSeconds === undefined ? undefined : retryAfterSeconds * 1000;\n};\n"]}
@@ -2,10 +2,11 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import type { ITelemetryErrorEventExt } from "@fluidframework/telemetry-utils/internal";
6
- import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
5
+ import type { ITelemetryErrorEventExt, ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
7
6
  /**
7
+ * Logs a network failure with additional context about online status and retry capability for the provided event.
8
+ *
8
9
  * @internal
9
10
  */
10
- export declare function logNetworkFailure(logger: ITelemetryLoggerExt, event: ITelemetryErrorEventExt, error?: any): void;
11
+ export declare function logNetworkFailure(logger: ITelemetryLoggerExt, event: ITelemetryErrorEventExt, error?: unknown): void;
11
12
  //# sourceMappingURL=networkUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"networkUtils.d.ts","sourceRoot":"","sources":["../src/networkUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACxF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAI/E;;GAEG;AACH,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,mBAAmB,EAC3B,KAAK,EAAE,uBAAuB,EAC9B,KAAK,CAAC,EAAE,GAAG,GACT,IAAI,CAkBN"}
1
+ {"version":3,"file":"networkUtils.d.ts","sourceRoot":"","sources":["../src/networkUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,uBAAuB,EACvB,mBAAmB,EACnB,MAAM,0CAA0C,CAAC;AAIlD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,mBAAmB,EAC3B,KAAK,EAAE,uBAAuB,EAC9B,KAAK,CAAC,EAAE,OAAO,GACb,IAAI,CAsBN"}
@@ -4,17 +4,23 @@
4
4
  */
5
5
  import { OnlineStatus, canRetryOnError, isOnline } from "./network.js";
6
6
  /**
7
+ * Logs a network failure with additional context about online status and retry capability for the provided event.
8
+ *
7
9
  * @internal
8
10
  */
9
11
  export function logNetworkFailure(logger, event, error) {
10
12
  const newEvent = { ...event };
13
+ // TODO: better typing
11
14
  const errorOnlineProp = error?.online;
12
15
  newEvent.online =
13
16
  typeof errorOnlineProp === "string" ? errorOnlineProp : OnlineStatus[isOnline()];
14
17
  if (typeof navigator === "object" && navigator !== null) {
18
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any -- TODO: use a real type
15
19
  const nav = navigator;
20
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
16
21
  const connection = nav.connection ?? nav.mozConnection ?? nav.webkitConnection;
17
22
  if (connection !== null && typeof connection === "object") {
23
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
18
24
  newEvent.connectionType = connection.type;
19
25
  }
20
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"networkUtils.js","sourceRoot":"","sources":["../src/networkUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEvE;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAChC,MAA2B,EAC3B,KAA8B,EAC9B,KAAW;IAEX,MAAM,QAAQ,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;IAE9B,MAAM,eAAe,GAAG,KAAK,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,MAAM;QACd,OAAO,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC;IAElF,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;QACzD,MAAM,GAAG,GAAG,SAAgB,CAAC;QAC7B,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,aAAa,IAAI,GAAG,CAAC,gBAAgB,CAAC;QAC/E,IAAI,UAAU,KAAK,IAAI,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;YAC3D,QAAQ,CAAC,cAAc,GAAG,UAAU,CAAC,IAAI,CAAC;QAC3C,CAAC;IACF,CAAC;IAED,gEAAgE;IAChE,QAAQ,CAAC,QAAQ,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;IACjE,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ITelemetryErrorEventExt } from \"@fluidframework/telemetry-utils/internal\";\nimport { ITelemetryLoggerExt } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { OnlineStatus, canRetryOnError, isOnline } from \"./network.js\";\n\n/**\n * @internal\n */\nexport function logNetworkFailure(\n\tlogger: ITelemetryLoggerExt,\n\tevent: ITelemetryErrorEventExt,\n\terror?: any,\n): void {\n\tconst newEvent = { ...event };\n\n\tconst errorOnlineProp = error?.online;\n\tnewEvent.online =\n\t\ttypeof errorOnlineProp === \"string\" ? errorOnlineProp : OnlineStatus[isOnline()];\n\n\tif (typeof navigator === \"object\" && navigator !== null) {\n\t\tconst nav = navigator as any;\n\t\tconst connection = nav.connection ?? nav.mozConnection ?? nav.webkitConnection;\n\t\tif (connection !== null && typeof connection === \"object\") {\n\t\t\tnewEvent.connectionType = connection.type;\n\t\t}\n\t}\n\n\t// non-retryable errors are fatal and should be logged as errors\n\tnewEvent.category = canRetryOnError(error) ? \"generic\" : \"error\";\n\tlogger.sendTelemetryEvent(newEvent, error);\n}\n"]}
1
+ {"version":3,"file":"networkUtils.js","sourceRoot":"","sources":["../src/networkUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEvE;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAChC,MAA2B,EAC3B,KAA8B,EAC9B,KAAe;IAEf,MAAM,QAAQ,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;IAE9B,sBAAsB;IACtB,MAAM,eAAe,GAAI,KAA8B,EAAE,MAAM,CAAC;IAChE,QAAQ,CAAC,MAAM;QACd,OAAO,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC;IAElF,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;QACzD,gIAAgI;QAChI,MAAM,GAAG,GAAG,SAAgB,CAAC;QAC7B,+GAA+G;QAC/G,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,aAAa,IAAI,GAAG,CAAC,gBAAgB,CAAC;QAC/E,IAAI,UAAU,KAAK,IAAI,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;YAC3D,+GAA+G;YAC/G,QAAQ,CAAC,cAAc,GAAG,UAAU,CAAC,IAAI,CAAC;QAC3C,CAAC;IACF,CAAC;IAED,gEAAgE;IAChE,QAAQ,CAAC,QAAQ,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;IACjE,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tITelemetryErrorEventExt,\n\tITelemetryLoggerExt,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { OnlineStatus, canRetryOnError, isOnline } from \"./network.js\";\n\n/**\n * Logs a network failure with additional context about online status and retry capability for the provided event.\n *\n * @internal\n */\nexport function logNetworkFailure(\n\tlogger: ITelemetryLoggerExt,\n\tevent: ITelemetryErrorEventExt,\n\terror?: unknown,\n): void {\n\tconst newEvent = { ...event };\n\n\t// TODO: better typing\n\tconst errorOnlineProp = (error as { online?: unknown })?.online;\n\tnewEvent.online =\n\t\ttypeof errorOnlineProp === \"string\" ? errorOnlineProp : OnlineStatus[isOnline()];\n\n\tif (typeof navigator === \"object\" && navigator !== null) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any -- TODO: use a real type\n\t\tconst nav = navigator as any;\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n\t\tconst connection = nav.connection ?? nav.mozConnection ?? nav.webkitConnection;\n\t\tif (connection !== null && typeof connection === \"object\") {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n\t\t\tnewEvent.connectionType = connection.type;\n\t\t}\n\t}\n\n\t// non-retryable errors are fatal and should be logged as errors\n\tnewEvent.category = canRetryOnError(error) ? \"generic\" : \"error\";\n\tlogger.sendTelemetryEvent(newEvent, error);\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/driver-utils";
8
- export declare const pkgVersion = "2.81.0";
8
+ export declare const pkgVersion = "2.82.0";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export const pkgName = "@fluidframework/driver-utils";
8
- export const pkgVersion = "2.81.0";
8
+ export const pkgVersion = "2.82.0";
9
9
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,8BAA8B,CAAC;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/driver-utils\";\nexport const pkgVersion = \"2.81.0\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,8BAA8B,CAAC;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/driver-utils\";\nexport const pkgVersion = \"2.82.0\";\n"]}
@@ -2,9 +2,9 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { ITelemetryBaseProperties } from "@fluidframework/core-interfaces";
6
- import { IDeltasFetchResult, IStream, IStreamResult, ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal";
7
- import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
5
+ import type { ITelemetryBaseProperties } from "@fluidframework/core-interfaces";
6
+ import type { IDeltasFetchResult, IStream, IStreamResult, ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal";
7
+ import { type ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
8
8
  /**
9
9
  * Helper class to organize parallel fetching of data
10
10
  * It can be used to concurrently do many requests, while consuming
@@ -58,7 +58,7 @@ export declare class Queue<T> implements IStream<T> {
58
58
  private deferred;
59
59
  private done;
60
60
  pushValue(value: T): void;
61
- pushError(error: any): void;
61
+ pushError(error: unknown): void;
62
62
  pushDone(): void;
63
63
  protected pushCore(value: Promise<IStreamResult<T>>): void;
64
64
  read(): Promise<IStreamResult<T>>;
@@ -82,10 +82,14 @@ export declare function requestOps(get: (from: number, to: number, telemetryProp
82
82
  */
83
83
  export declare const emptyMessageStream: IStream<ISequencedDocumentMessage[]>;
84
84
  /**
85
+ * Creates a stream from the provided promise of messages.
86
+ *
85
87
  * @internal
86
88
  */
87
89
  export declare function streamFromMessages(messagesArg: Promise<ISequencedDocumentMessage[]>): IStream<ISequencedDocumentMessage[]>;
88
90
  /**
91
+ * Wraps the provided stream to observe values as they are read.
92
+ *
89
93
  * @internal
90
94
  */
91
95
  export declare function streamObserver<T>(stream: IStream<T>, handler: (value: IStreamResult<T>) => void): IStream<T>;
@@ -1 +1 @@
1
- {"version":3,"file":"parallelRequests.d.ts","sourceRoot":"","sources":["../src/parallelRequests.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAE3E,OAAO,EACN,kBAAkB,EAClB,OAAO,EACP,aAAa,EACb,yBAAyB,EACzB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EACN,mBAAmB,EAEnB,MAAM,0CAA0C,CAAC;AAiBlD;;;;;;;;;;;;GAYG;AACH,qBAAa,gBAAgB,CAAC,CAAC;IAmB7B,OAAO,CAAC,EAAE;IACV,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAOhC,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IA5BlC,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0B;IAClD,OAAO,CAAC,YAAY,CAA2B;IAC/C,OAAO,CAAC,gBAAgB,CAAK;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;IACjD,OAAO,CAAC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KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,IAAI,GACxC,OAAO,CAAC,CAAC,CAAC,CAQZ"}
@@ -111,10 +111,8 @@ export class ParallelRequests {
111
111
  return undefined;
112
112
  }
113
113
  const from = this.latestRequested;
114
- if (this.to !== undefined) {
115
- if (this.to <= from) {
116
- return undefined;
117
- }
114
+ if (this.to !== undefined && this.to <= from) {
115
+ return undefined;
118
116
  }
119
117
  // this.latestRequested
120
118
  // inclusive on the right side! Exclusive on the left.
@@ -166,7 +164,7 @@ export class ParallelRequests {
166
164
  // If it pops into our view a lot, we would need to reconsider how we approach it.
167
165
  // Note that this is not visible to user other than potentially not hitting 100% of
168
166
  // what we can in perf domain.
169
- if (payload.length !== 0) {
167
+ if (payload.length > 0) {
170
168
  this.logger.sendErrorEvent({
171
169
  eventName: "ParallelRequests_GotExtra",
172
170
  from,
@@ -181,7 +179,20 @@ export class ParallelRequests {
181
179
  const fromOrig = from;
182
180
  const length = payload.length;
183
181
  let fullChunk = requestedLength <= length; // we can possible get more than we asked.
184
- if (length !== 0) {
182
+ if (length === 0) {
183
+ // 1. empty (partial) chunks should not be returned by various caching / adapter layers -
184
+ // they should fall back to next layer. This might be important invariant to hold to ensure
185
+ // that we are less likely have bugs where such layer would keep returning empty partial
186
+ // result on each call.
187
+ // 2. Current invariant is that callback does retries until it gets something,
188
+ // with the goal of failing if zero data is retrieved in given amount of time.
189
+ // This is very specific property of storage / ops, so this logic is not here, but given only
190
+ // one user of this class, we assert that to catch issues earlier.
191
+ // These invariant can be relaxed if needed.
192
+ assert(!partial, 0x10f /* "empty/partial chunks should not be returned by caching" */);
193
+ assert(!this.knewTo, 0x110 /* "callback should retry until valid fetch before it learns new boundary" */);
194
+ }
195
+ else {
185
196
  // We can get more than we asked for!
186
197
  // This can screw up logic in dispatch!
187
198
  // So push only batch size, and keep the rest for later - if conditions are favorable, we
@@ -201,19 +212,6 @@ export class ParallelRequests {
201
212
  this.results.set(from, data);
202
213
  from += data.length;
203
214
  }
204
- else {
205
- // 1. empty (partial) chunks should not be returned by various caching / adapter layers -
206
- // they should fall back to next layer. This might be important invariant to hold to ensure
207
- // that we are less likely have bugs where such layer would keep returning empty partial
208
- // result on each call.
209
- // 2. Current invariant is that callback does retries until it gets something,
210
- // with the goal of failing if zero data is retrieved in given amount of time.
211
- // This is very specific property of storage / ops, so this logic is not here, but given only
212
- // one user of this class, we assert that to catch issues earlier.
213
- // These invariant can be relaxed if needed.
214
- assert(!partial, 0x10f /* "empty/partial chunks should not be returned by caching" */);
215
- assert(!this.knewTo, 0x110 /* "callback should retry until valid fetch before it learns new boundary" */);
216
- }
217
215
  if (!partial && !fullChunk) {
218
216
  if (!this.knewTo) {
219
217
  if (this.to === undefined || this.to > from) {
@@ -238,7 +236,7 @@ export class ParallelRequests {
238
236
  if (to === this.latestRequested) {
239
237
  // we can go after full chunk at the end if we received partial chunk, or more than asked
240
238
  // Also if we got more than we asked to, we can actually use those ops!
241
- while (payload.length !== 0) {
239
+ while (payload.length > 0) {
242
240
  const data = payload.splice(0, requestedLength);
243
241
  this.results.set(from, data);
244
242
  from += data.length;
@@ -346,7 +344,7 @@ async function getSingleOpBatch(get, props, strongTo, logger, signal, scenarioNa
346
344
  const { messages, partialResult } = await get({ ...props, retry } /* telemetry props */);
347
345
  // If we got messages back, return them. Return regardless of whether we got messages back if we didn't
348
346
  // specify a "to", since we don't have an expectation of how many to receive.
349
- if (messages.length !== 0 || !strongTo) {
347
+ if (messages.length > 0 || !strongTo) {
350
348
  // Report this event if we waited to fetch ops due to being offline or throttling.
351
349
  telemetryEvent?.end({
352
350
  duration: totalRetryAfterTime,
@@ -507,6 +505,8 @@ export const emptyMessageStream = {
507
505
  },
508
506
  };
509
507
  /**
508
+ * Creates a stream from the provided promise of messages.
509
+ *
510
510
  * @internal
511
511
  */
512
512
  export function streamFromMessages(messagesArg) {
@@ -517,12 +517,15 @@ export function streamFromMessages(messagesArg) {
517
517
  return { done: true };
518
518
  }
519
519
  const value = await messages;
520
+ // eslint-disable-next-line require-atomic-updates
520
521
  messages = undefined;
521
522
  return value.length === 0 ? { done: true } : { done: false, value };
522
523
  },
523
524
  };
524
525
  }
525
526
  /**
527
+ * Wraps the provided stream to observe values as they are read.
528
+ *
526
529
  * @internal
527
530
  */
528
531
  export function streamObserver(stream, handler) {
@@ -1 +1 @@
1
- {"version":3,"file":"parallelRequests.js","sourceRoot":"","sources":["../src/parallelRequests.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAOvE,OAAO,EAEN,gBAAgB,GAChB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EACN,eAAe,EACf,yBAAyB,EACzB,sBAAsB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,sFAAsF;AACtF,OAAO,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,8GAA8G;AAC9G,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAIjC;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,gBAAgB;IAU5B,IAAY,OAAO;QAClB,OAAO,IAAI,CAAC,YAAY,KAAK,SAAS,CAAC;IACxC,CAAC;IACD,IAAW,QAAQ;QAClB,OAAO,IAAI,CAAC,YAAY,KAAK,UAAU,CAAC;IACzC,CAAC;IAED,YACC,IAAY,EACJ,EAAsB,EACb,WAAmB,EACnB,MAA2B,EAC3B,eAMgD,EAChD,gBAAwC;QAVjD,OAAE,GAAF,EAAE,CAAoB;QACb,gBAAW,GAAX,WAAW,CAAQ;QACnB,WAAM,GAAN,MAAM,CAAqB;QAC3B,oBAAe,GAAf,eAAe,CAMiC;QAChD,qBAAgB,GAAhB,gBAAgB,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AE1C,OAAO;QACN,IAAI,EAAE,KAAK,IAAI,EAAE;YAChB,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAClC,OAAO,CAAC,KAAK,CAAC,CAAC;YACf,OAAO,KAAK,CAAC;QACd,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { performanceNow } from \"@fluid-internal/client-utils\";\nimport { ITelemetryBaseProperties } from \"@fluidframework/core-interfaces\";\nimport { assert, Deferred } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIDeltasFetchResult,\n\tIStream,\n\tIStreamResult,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tPerformanceEvent,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tcanRetryOnError,\n\tcreateGenericNetworkError,\n\tgetRetryDelayFromError,\n} from \"./network.js\";\nimport { logNetworkFailure } from \"./networkUtils.js\";\n// For now, this package is versioned and released in unison with the specific drivers\nimport { pkgVersion as driverVersion } from \"./packageVersion.js\";\nimport { calculateMaxWaitTime } from \"./runWithRetry.js\";\n\n// We double this value in first try in when we calculate time to wait for in \"calculateMaxWaitTime\" function.\nconst MissingFetchDelayInMs = 50;\n\ntype WorkingState = \"working\" | \"done\" | \"canceled\";\n\n/**\n * Helper class to organize parallel fetching of data\n * It can be used to concurrently do many requests, while consuming\n * data in the right order. Take a look at UT for examples.\n * @param concurrency - level of concurrency\n * @param from - starting point of fetching data (inclusive)\n * @param to - ending point of fetching data. exclusive, or undefined if unknown\n * @param payloadSize - batch size\n * @param logger - logger to use\n * @param requestCallback - callback to request batches\n * @returns Queue that can be used to retrieve data\n * @internal\n */\nexport class ParallelRequests<T> {\n\tprivate latestRequested: number;\n\tprivate nextToDeliver: number;\n\tprivate readonly results = new Map<number, T[]>();\n\tprivate workingState: WorkingState = \"working\";\n\tprivate requestsInFlight = 0;\n\tprivate readonly endEvent = new Deferred<void>();\n\tprivate requests = 0;\n\tprivate readonly knewTo: boolean;\n\n\tprivate get working(): boolean {\n\t\treturn this.workingState === \"working\";\n\t}\n\tpublic get canceled(): boolean {\n\t\treturn this.workingState === \"canceled\";\n\t}\n\n\tconstructor(\n\t\tfrom: number,\n\t\tprivate to: number | undefined,\n\t\tprivate readonly payloadSize: number,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t\tprivate readonly requestCallback: (\n\t\t\trequest: number,\n\t\t\tfrom: number,\n\t\t\tto: number,\n\t\t\tstrongTo: boolean,\n\t\t\tprops: ITelemetryBaseProperties,\n\t\t) => Promise<{ partial: boolean; cancel: boolean; payload: T[] }>,\n\t\tprivate readonly responseCallback: (payload: T[]) => void,\n\t) {\n\t\tthis.latestRequested = from;\n\t\tthis.nextToDeliver = from;\n\t\tthis.knewTo = to !== undefined;\n\t}\n\n\tpublic cancel(): void {\n\t\tif (this.working) {\n\t\t\tthis.workingState = \"canceled\";\n\t\t\tthis.endEvent.resolve();\n\t\t}\n\t}\n\n\tpublic async run(concurrency: number): Promise<void> {\n\t\tassert(concurrency > 0, 0x102 /* \"invalid level of concurrency\" */);\n\t\tassert(this.working, 0x103 /* \"trying to parallel run while not working\" */);\n\n\t\tlet c = concurrency;\n\t\twhile (c > 0) {\n\t\t\tc--;\n\t\t\tthis.addRequest();\n\t\t}\n\t\tthis.dispatch(); // will recalculate and trigger this.endEvent if needed\n\t\treturn this.endEvent.promise;\n\t}\n\n\tprivate done(): void {\n\t\t// We should satisfy request fully.\n\t\tassert(this.to !== undefined, 0x104 /* \"undefined end point for parallel fetch\" */);\n\t\tassert(\n\t\t\tthis.nextToDeliver >= this.to,\n\t\t\t0x105 /* \"unexpected end point for parallel fetch\" */,\n\t\t);\n\t\tif (this.working) {\n\t\t\tthis.workingState = \"done\";\n\t\t\tthis.endEvent.resolve();\n\t\t}\n\t}\n\n\tprivate fail(error): void {\n\t\tif (this.working) {\n\t\t\tthis.workingState = \"done\";\n\t\t\tthis.endEvent.reject(error);\n\t\t}\n\t}\n\n\tprivate dispatch(): void {\n\t\twhile (this.working) {\n\t\t\tconst value = this.results.get(this.nextToDeliver);\n\t\t\tif (value === undefined) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tthis.results.delete(this.nextToDeliver);\n\t\t\tassert(\n\t\t\t\tvalue.length <= this.payloadSize,\n\t\t\t\t0x1d9 /* \"addRequestCore() should break into smaller chunks\" */,\n\t\t\t);\n\t\t\tthis.nextToDeliver += value.length;\n\t\t\tthis.responseCallback(value);\n\t\t}\n\n\t\t// Account for cancellation - state might be not in consistent state on cancelling operation\n\t\tif (this.working) {\n\t\t\tif (this.requestsInFlight === 0) {\n\t\t\t\t// we should have dispatched everything, no matter whether we knew about the end or not.\n\t\t\t\t// see comment in addRequestCore() around throwing away chunk if it's above this.to\n\t\t\t\tassert(\n\t\t\t\t\tthis.results.size === 0,\n\t\t\t\t\t0x107 /* \"ending dispatch with remaining results to be sent\" */,\n\t\t\t\t);\n\t\t\t\tthis.done();\n\t\t\t} else if (this.to !== undefined && this.nextToDeliver >= this.to) {\n\t\t\t\t// Learned about the end and dispatched all the ops up to it.\n\t\t\t\t// Ignore all the in-flight requests above boundary - unblock caller sooner.\n\t\t\t\tassert(\n\t\t\t\t\t!this.knewTo,\n\t\t\t\t\t0x108 /* \"ending results dispatch but knew in advance about more requests\" */,\n\t\t\t\t);\n\t\t\t\tthis.done();\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getNextChunk(): { from: number; to: number } | undefined {\n\t\tif (!this.working) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst from = this.latestRequested;\n\t\tif (this.to !== undefined) {\n\t\t\tif (this.to <= from) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\n\t\t// this.latestRequested\n\t\t// inclusive on the right side! Exclusive on the left.\n\t\tthis.latestRequested += this.payloadSize;\n\n\t\tif (this.to !== undefined) {\n\t\t\tthis.latestRequested = Math.min(this.to, this.latestRequested);\n\t\t}\n\n\t\tassert(from < this.latestRequested, 0x109 /* \"unexpected next chunk position\" */);\n\n\t\treturn { from, to: this.latestRequested };\n\t}\n\n\tprivate addRequest(): void {\n\t\tconst chunk = this.getNextChunk();\n\t\tif (chunk === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tthis.addRequestCore(chunk.from, chunk.to).catch(this.fail.bind(this));\n\t}\n\n\tprivate async addRequestCore(fromArg: number, toArg: number): Promise<void> {\n\t\tassert(this.working, 0x10a /* \"cannot add parallel request while not working\" */);\n\n\t\tlet from = fromArg;\n\t\tlet to = toArg;\n\n\t\t// to & from are exclusive\n\t\tthis.requestsInFlight++;\n\t\twhile (this.working) {\n\t\t\tconst requestedLength = to - from;\n\t\t\tassert(requestedLength > 0, 0x10b /* \"invalid parallel request range\" */);\n\n\t\t\t// We should not be wasting time asking for something useless.\n\t\t\tif (this.to !== undefined) {\n\t\t\t\tassert(from < this.to, 0x10c /* \"invalid parallel request start point\" */);\n\t\t\t\tassert(to <= this.to, 0x10d /* \"invalid parallel request end point\" */);\n\t\t\t}\n\n\t\t\tthis.requests++;\n\n\t\t\tconst promise = this.requestCallback(this.requests, from, to, this.to !== undefined, {});\n\n\t\t\t// dispatch any prior received data\n\t\t\tthis.dispatch();\n\n\t\t\tconst { payload, cancel, partial } = await promise;\n\n\t\t\tif (cancel) {\n\t\t\t\tthis.cancel();\n\t\t\t}\n\n\t\t\tif (this.to !== undefined && from >= this.to) {\n\t\t\t\t// while we were waiting for response, we learned on what is the boundary\n\t\t\t\t// We can get here (with actual result!) if situation changed while this request was in\n\t\t\t\t// flight, i.e. the end was extended over what we learn in some other request\n\t\t\t\t// While it's useful not to throw this result, this is very corner cases and makes logic\n\t\t\t\t// (including consistency checks) much harder to write correctly.\n\t\t\t\t// So for now, we are throwing this result out the window.\n\t\t\t\tassert(\n\t\t\t\t\t!this.knewTo,\n\t\t\t\t\t0x10e /* \"should not throw result if we knew about boundary in advance\" */,\n\t\t\t\t);\n\t\t\t\t// Learn how often it happens and if it's too wasteful to throw these chunks.\n\t\t\t\t// If it pops into our view a lot, we would need to reconsider how we approach it.\n\t\t\t\t// Note that this is not visible to user other than potentially not hitting 100% of\n\t\t\t\t// what we can in perf domain.\n\t\t\t\tif (payload.length !== 0) {\n\t\t\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\t\t\teventName: \"ParallelRequests_GotExtra\",\n\t\t\t\t\t\tfrom,\n\t\t\t\t\t\tto,\n\t\t\t\t\t\tend: this.to,\n\t\t\t\t\t\tlength: payload.length,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (this.working) {\n\t\t\t\tconst fromOrig = from;\n\t\t\t\tconst length = payload.length;\n\t\t\t\tlet fullChunk = requestedLength <= length; // we can possible get more than we asked.\n\n\t\t\t\tif (length !== 0) {\n\t\t\t\t\t// We can get more than we asked for!\n\t\t\t\t\t// This can screw up logic in dispatch!\n\t\t\t\t\t// So push only batch size, and keep the rest for later - if conditions are favorable, we\n\t\t\t\t\t// will be able to use it. If not (parallel request overlapping these ops), it's easier to\n\t\t\t\t\t// discard them and wait for another (overlapping) request to come in later.\n\t\t\t\t\tif (requestedLength < length) {\n\t\t\t\t\t\t// This is error in a sense that it's not expected and likely points bug in other layer.\n\t\t\t\t\t\t// This layer copes with this situation just fine.\n\t\t\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\t\t\teventName: \"ParallelRequests_Over\",\n\t\t\t\t\t\t\tfrom,\n\t\t\t\t\t\t\tto,\n\t\t\t\t\t\t\tlength,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tconst data = payload.splice(0, requestedLength);\n\t\t\t\t\tthis.results.set(from, data);\n\t\t\t\t\tfrom += data.length;\n\t\t\t\t} else {\n\t\t\t\t\t// 1. empty (partial) chunks should not be returned by various caching / adapter layers -\n\t\t\t\t\t// they should fall back to next layer. This might be important invariant to hold to ensure\n\t\t\t\t\t// that we are less likely have bugs where such layer would keep returning empty partial\n\t\t\t\t\t// result on each call.\n\t\t\t\t\t// 2. Current invariant is that callback does retries until it gets something,\n\t\t\t\t\t// with the goal of failing if zero data is retrieved in given amount of time.\n\t\t\t\t\t// This is very specific property of storage / ops, so this logic is not here, but given only\n\t\t\t\t\t// one user of this class, we assert that to catch issues earlier.\n\t\t\t\t\t// These invariant can be relaxed if needed.\n\t\t\t\t\tassert(\n\t\t\t\t\t\t!partial,\n\t\t\t\t\t\t0x10f /* \"empty/partial chunks should not be returned by caching\" */,\n\t\t\t\t\t);\n\t\t\t\t\tassert(\n\t\t\t\t\t\t!this.knewTo,\n\t\t\t\t\t\t0x110 /* \"callback should retry until valid fetch before it learns new boundary\" */,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (!partial && !fullChunk) {\n\t\t\t\t\tif (!this.knewTo) {\n\t\t\t\t\t\tif (this.to === undefined || this.to > from) {\n\t\t\t\t\t\t\t// The END\n\t\t\t\t\t\t\tthis.to = from;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t// We know that there are more items to be retrieved\n\t\t\t\t\t// Can we get partial chunk? Ideally storage indicates that's not a full chunk\n\t\t\t\t\t// Note that it's possible that not all ops hit storage yet.\n\t\t\t\t\t// We will come back to request more, and if we can't get any more ops soon, it's\n\t\t\t\t\t// catastrophic failure (see comment above on responsibility of callback to return something)\n\t\t\t\t\t// This layer will just keep trying until it gets full set.\n\t\t\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\t\t\teventName: \"ParallelRequests_Partial\",\n\t\t\t\t\t\tfrom: fromOrig,\n\t\t\t\t\t\tto,\n\t\t\t\t\t\tlength,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tif (to === this.latestRequested) {\n\t\t\t\t\t// we can go after full chunk at the end if we received partial chunk, or more than asked\n\t\t\t\t\t// Also if we got more than we asked to, we can actually use those ops!\n\t\t\t\t\twhile (payload.length !== 0) {\n\t\t\t\t\t\tconst data = payload.splice(0, requestedLength);\n\t\t\t\t\t\tthis.results.set(from, data);\n\t\t\t\t\t\tfrom += data.length;\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.latestRequested = from;\n\t\t\t\t\tfullChunk = true;\n\t\t\t\t}\n\n\t\t\t\tif (fullChunk) {\n\t\t\t\t\tconst chunk = this.getNextChunk();\n\t\t\t\t\tif (chunk === undefined) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tfrom = chunk.from;\n\t\t\t\t\tto = chunk.to;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis.requestsInFlight--;\n\t\tthis.dispatch();\n\t}\n}\n\n/**\n * Helper queue class to allow async push / pull\n * It's essentially a pipe allowing multiple writers, and single reader\n * @internal\n */\nexport class Queue<T> implements IStream<T> {\n\tprivate readonly queue: Promise<IStreamResult<T>>[] = [];\n\tprivate deferred: Deferred<IStreamResult<T>> | undefined;\n\tprivate done = false;\n\n\tpublic pushValue(value: T): void {\n\t\tthis.pushCore(Promise.resolve({ done: false, value }));\n\t}\n\n\tpublic pushError(error: any): void {\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n\t\tthis.pushCore(Promise.reject(error));\n\t\tthis.done = true;\n\t}\n\n\tpublic pushDone(): void {\n\t\tthis.pushCore(Promise.resolve({ done: true }));\n\t\tthis.done = true;\n\t}\n\n\tprotected pushCore(value: Promise<IStreamResult<T>>): void {\n\t\tassert(!this.done, 0x112 /* \"cannot push onto queue if done\" */);\n\t\tif (this.deferred) {\n\t\t\tassert(this.queue.length === 0, 0x113 /* \"deferred queue should be empty\" */);\n\t\t\tthis.deferred.resolve(value);\n\t\t\tthis.deferred = undefined;\n\t\t} else {\n\t\t\tthis.queue.push(value);\n\t\t}\n\t}\n\n\tpublic async read(): Promise<IStreamResult<T>> {\n\t\tassert(this.deferred === undefined, 0x114 /* \"cannot pop if deferred\" */);\n\t\tconst value = this.queue.shift();\n\t\tif (value !== undefined) {\n\t\t\treturn value;\n\t\t}\n\t\tassert(!this.done, 0x115 /* \"queue should not be done during pop\" */);\n\t\tthis.deferred = new Deferred<IStreamResult<T>>();\n\t\treturn this.deferred.promise;\n\t}\n}\n\nconst waitForOnline = async (): Promise<void> => {\n\t// Only wait if we have a strong signal that we're offline - otherwise assume we're online.\n\tif (globalThis.navigator?.onLine === false && globalThis.addEventListener !== undefined) {\n\t\treturn new Promise<void>((resolve) => {\n\t\t\tconst resolveAndRemoveListener = (): void => {\n\t\t\t\tresolve();\n\t\t\t\tglobalThis.removeEventListener(\"online\", resolveAndRemoveListener);\n\t\t\t};\n\t\t\tglobalThis.addEventListener(\"online\", resolveAndRemoveListener);\n\t\t});\n\t}\n};\n\n/**\n * Retrieve single batch of ops\n * @param request - request index\n * @param from - inclusive boundary\n * @param to - exclusive boundary\n * @param telemetryEvent - telemetry event used to track consecutive batch of requests\n * @param strongTo - tells if ops in range from...to have to be there and have to be retrieved.\n * If false, returning less ops would mean we reached end of file.\n * @param logger - logger object to use to log progress & errors\n * @param signal - cancelation signal\n * @param scenarioName - reason for fetching ops\n * @returns An object with resulting ops and cancellation / partial result flags\n */\nasync function getSingleOpBatch(\n\tget: (telemetryProps: ITelemetryBaseProperties) => Promise<IDeltasFetchResult>,\n\tprops: ITelemetryBaseProperties,\n\tstrongTo: boolean,\n\tlogger: ITelemetryLoggerExt,\n\tsignal?: AbortSignal,\n\tscenarioName?: string,\n): Promise<{ partial: boolean; cancel: boolean; payload: ISequencedDocumentMessage[] }> {\n\tlet lastSuccessTime: number | undefined;\n\tlet totalRetryAfterTime = 0;\n\tlet telemetryEvent: PerformanceEvent | undefined;\n\tlet retry: number = 0;\n\tconst nothing = { partial: false, cancel: true, payload: [] };\n\tlet waitStartTime: number = 0;\n\tlet waitTime = MissingFetchDelayInMs;\n\n\twhile (signal?.aborted !== true) {\n\t\tretry++;\n\t\tlet lastError: unknown;\n\t\tconst startTime = performanceNow();\n\n\t\ttry {\n\t\t\t// Issue async request for deltas\n\t\t\tconst { messages, partialResult } = await get({ ...props, retry } /* telemetry props */);\n\n\t\t\t// If we got messages back, return them. Return regardless of whether we got messages back if we didn't\n\t\t\t// specify a \"to\", since we don't have an expectation of how many to receive.\n\t\t\tif (messages.length !== 0 || !strongTo) {\n\t\t\t\t// Report this event if we waited to fetch ops due to being offline or throttling.\n\t\t\t\ttelemetryEvent?.end({\n\t\t\t\t\tduration: totalRetryAfterTime,\n\t\t\t\t\t...props,\n\t\t\t\t\treason: scenarioName,\n\t\t\t\t});\n\t\t\t\treturn { payload: messages, cancel: false, partial: partialResult };\n\t\t\t}\n\n\t\t\t// Otherwise, the storage gave us back an empty set of ops but we were expecting a non-empty set.\n\n\t\t\tif (lastSuccessTime === undefined) {\n\t\t\t\t// Take timestamp of the first time server responded successfully, even though it wasn't with the ops we asked for.\n\t\t\t\t// If we keep getting empty responses we'll eventually fail out below.\n\t\t\t\tlastSuccessTime = performanceNow();\n\t\t\t} else if (performanceNow() - lastSuccessTime > 30000) {\n\t\t\t\t// If we are connected and receiving proper responses from server, but can't get any ops back,\n\t\t\t\t// then give up after some time. This likely indicates the issue with ordering service not flushing\n\t\t\t\t// ops to storage quick enough, and possibly waiting for summaries, while summarizer can't get\n\t\t\t\t// current as it can't get ops.\n\t\t\t\tthrow createGenericNetworkError(\n\t\t\t\t\t// pre-0.58 error message: failedToRetrieveOpsFromStorage:TooManyRetries\n\t\t\t\t\t\"Failed to retrieve ops from storage (Too Many Retries)\",\n\t\t\t\t\t{ canRetry: false },\n\t\t\t\t\t{\n\t\t\t\t\t\tretry,\n\t\t\t\t\t\tdriverVersion,\n\t\t\t\t\t\t...props,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlastError = error;\n\t\t\tconst canRetry = canRetryOnError(error);\n\n\t\t\tconst retryAfter = getRetryDelayFromError(error);\n\n\t\t\t// This will log to error table only if the error is non-retryable\n\t\t\tlogNetworkFailure(\n\t\t\t\tlogger,\n\t\t\t\t{\n\t\t\t\t\teventName: \"GetDeltas_Error\",\n\t\t\t\t\t...props,\n\t\t\t\t\tretry,\n\t\t\t\t\tduration: performanceNow() - startTime,\n\t\t\t\t\tretryAfter,\n\t\t\t\t\treason: scenarioName,\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t);\n\n\t\t\tif (!canRetry) {\n\t\t\t\t// It's game over scenario.\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\n\t\tif (telemetryEvent === undefined) {\n\t\t\twaitStartTime = performanceNow();\n\t\t\ttelemetryEvent = PerformanceEvent.start(logger, {\n\t\t\t\teventName: \"GetDeltasWaitTime\",\n\t\t\t});\n\t\t}\n\n\t\twaitTime = calculateMaxWaitTime(waitTime, lastError);\n\n\t\t// If we get here something has gone wrong - either got an unexpected empty set of messages back or a real error.\n\t\t// Either way we will wait a little bit before retrying.\n\t\tawait new Promise<void>((resolve) => {\n\t\t\tsetTimeout(resolve, waitTime);\n\t\t});\n\n\t\t// If we believe we're offline, we assume there's no point in trying until we at least think we're online.\n\t\t// NOTE: This isn't strictly true for drivers that don't require network (e.g. local driver). Really this logic\n\t\t// should probably live in the driver.\n\t\tawait waitForOnline();\n\t\ttotalRetryAfterTime += performanceNow() - waitStartTime;\n\t}\n\n\treturn nothing;\n}\n\n/**\n * Request ops from storage\n * @param get - Getter callback to get individual batches\n * @param concurrency - Number of concurrent requests to make\n * @param fromTotal - starting sequence number to fetch (inclusive)\n * @param toTotal - max (exclusive) sequence number to fetch\n * @param payloadSize - Payload size\n * @param logger - Logger to log progress and errors\n * @param signal - Cancelation signal\n * @param scenarioName - Reason for fetching ops\n * @returns Messages fetched\n * @internal\n */\nexport function requestOps(\n\tget: (\n\t\tfrom: number,\n\t\tto: number,\n\t\ttelemetryProps: ITelemetryBaseProperties,\n\t) => Promise<IDeltasFetchResult>,\n\tconcurrency: number,\n\tfromTotal: number,\n\ttoTotal: number | undefined,\n\tpayloadSize: number,\n\tlogger: ITelemetryLoggerExt,\n\tsignal?: AbortSignal,\n\tscenarioName?: string,\n): IStream<ISequencedDocumentMessage[]> {\n\tlet requests = 0;\n\tlet lastFetch: number | undefined;\n\tlet length = 0;\n\tconst queue = new Queue<ISequencedDocumentMessage[]>();\n\n\tconst propsTotal: ITelemetryBaseProperties = {\n\t\tfromTotal,\n\t\ttoTotal,\n\t};\n\n\tconst telemetryEvent = PerformanceEvent.start(logger, {\n\t\teventName: \"GetDeltas\",\n\t\t...propsTotal,\n\t\treason: scenarioName,\n\t});\n\n\tconst manager = new ParallelRequests<ISequencedDocumentMessage>(\n\t\tfromTotal,\n\t\ttoTotal,\n\t\tpayloadSize,\n\t\tlogger,\n\t\tasync (\n\t\t\trequest: number,\n\t\t\tfrom: number,\n\t\t\tto: number,\n\t\t\tstrongTo: boolean,\n\t\t\tpropsPerRequest: ITelemetryBaseProperties,\n\t\t) => {\n\t\t\trequests++;\n\t\t\treturn getSingleOpBatch(\n\t\t\t\tasync (propsAll) => get(from, to, propsAll),\n\t\t\t\t{ request, from, to, ...propsTotal, ...propsPerRequest },\n\t\t\t\tstrongTo,\n\t\t\t\tlogger,\n\t\t\t\tsignal,\n\t\t\t\tscenarioName,\n\t\t\t);\n\t\t},\n\t\t(deltas: ISequencedDocumentMessage[]) => {\n\t\t\t// Assert continuing and right start.\n\t\t\tif (lastFetch === undefined) {\n\t\t\t\tassert(deltas[0].sequenceNumber === fromTotal, 0x26d /* \"wrong start\" */);\n\t\t\t} else {\n\t\t\t\tassert(deltas[0].sequenceNumber === lastFetch + 1, 0x26e /* \"wrong start\" */);\n\t\t\t}\n\t\t\tlastFetch = deltas[deltas.length - 1].sequenceNumber;\n\t\t\tassert(\n\t\t\t\tlastFetch - deltas[0].sequenceNumber + 1 === deltas.length,\n\t\t\t\t0x26f /* \"continuous and no duplicates\" */,\n\t\t\t);\n\t\t\tlength += deltas.length;\n\t\t\tqueue.pushValue(deltas);\n\t\t},\n\t);\n\n\t// Implement faster cancellation. getSingleOpBatch() checks signal, but only in between\n\t// waits (up to 10 seconds) and fetches (can take infinite amount of time).\n\t// While every such case should be improved and take into account signal (and thus cancel immediately),\n\t// it is beneficial to have catch-all\n\tconst listener = (event: Event): void => {\n\t\tmanager.cancel();\n\t};\n\tif (signal !== undefined) {\n\t\tsignal.addEventListener(\"abort\", listener);\n\t}\n\n\tmanager\n\t\t.run(concurrency)\n\t\t.finally(() => {\n\t\t\tif (signal !== undefined) {\n\t\t\t\tsignal.removeEventListener(\"abort\", listener);\n\t\t\t}\n\t\t})\n\t\t.then(() => {\n\t\t\tconst props = {\n\t\t\t\tlastFetch,\n\t\t\t\tlength,\n\t\t\t\trequests,\n\t\t\t};\n\t\t\tif (manager.canceled) {\n\t\t\t\ttelemetryEvent.cancel({ ...props, error: \"ops request cancelled by client\" });\n\t\t\t} else {\n\t\t\t\tassert(\n\t\t\t\t\ttoTotal === undefined || (lastFetch !== undefined && lastFetch >= toTotal - 1),\n\t\t\t\t\t0x270 /* \"All requested ops fetched\" */,\n\t\t\t\t);\n\t\t\t\ttelemetryEvent.end(props);\n\t\t\t}\n\t\t\tqueue.pushDone();\n\t\t})\n\t\t.catch((error) => {\n\t\t\ttelemetryEvent.cancel(\n\t\t\t\t{\n\t\t\t\t\tlastFetch,\n\t\t\t\t\tlength,\n\t\t\t\t\trequests,\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t);\n\t\t\tqueue.pushError(error);\n\t\t});\n\n\treturn queue;\n}\n\n/**\n * @internal\n */\nexport const emptyMessageStream: IStream<ISequencedDocumentMessage[]> = {\n\tread: async () => {\n\t\treturn { done: true };\n\t},\n};\n\n/**\n * @internal\n */\nexport function streamFromMessages(\n\tmessagesArg: Promise<ISequencedDocumentMessage[]>,\n): IStream<ISequencedDocumentMessage[]> {\n\tlet messages: Promise<ISequencedDocumentMessage[]> | undefined = messagesArg;\n\treturn {\n\t\tread: async () => {\n\t\t\tif (messages === undefined) {\n\t\t\t\treturn { done: true };\n\t\t\t}\n\t\t\tconst value = await messages;\n\t\t\tmessages = undefined;\n\t\t\treturn value.length === 0 ? { done: true } : { done: false, value };\n\t\t},\n\t};\n}\n\n/**\n * @internal\n */\nexport function streamObserver<T>(\n\tstream: IStream<T>,\n\thandler: (value: IStreamResult<T>) => void,\n): IStream<T> {\n\treturn {\n\t\tread: async () => {\n\t\t\tconst value = await stream.read();\n\t\t\thandler(value);\n\t\t\treturn value;\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"parallelRequests.js","sourceRoot":"","sources":["../src/parallelRequests.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAOvE,OAAO,EAEN,gBAAgB,GAChB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EACN,eAAe,EACf,yBAAyB,EACzB,sBAAsB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,sFAAsF;AACtF,OAAO,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,8GAA8G;AAC9G,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAIjC;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,gBAAgB;IAU5B,IAAY,OAAO;QAClB,OAAO,IAAI,CAAC,YAAY,KAAK,SAAS,CAAC;IACxC,CAAC;IACD,IAAW,QAAQ;QAClB,OAAO,IAAI,CAAC,YAAY,KAAK,UAAU,CAAC;IACzC,CAAC;IAED,YACC,IAAY,EACJ,EAAsB,EACb,WAAmB,EACnB,MAA2B,EAC3B,eAMgD,EAChD,gBAAwC;QAVjD,OAAE,GAAF,EAAE,CAAoB;QACb,gBAAW,GAAX,WAAW,C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;KACD,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC7B,MAAkB,EAClB,OAA0C;IAE1C,OAAO;QACN,IAAI,EAAE,KAAK,IAAI,EAAE;YAChB,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAClC,OAAO,CAAC,KAAK,CAAC,CAAC;YACf,OAAO,KAAK,CAAC;QACd,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { performanceNow } from \"@fluid-internal/client-utils\";\nimport type { ITelemetryBaseProperties } from \"@fluidframework/core-interfaces\";\nimport { assert, Deferred } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tIDeltasFetchResult,\n\tIStream,\n\tIStreamResult,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\ttype ITelemetryLoggerExt,\n\tPerformanceEvent,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tcanRetryOnError,\n\tcreateGenericNetworkError,\n\tgetRetryDelayFromError,\n} from \"./network.js\";\nimport { logNetworkFailure } from \"./networkUtils.js\";\n// For now, this package is versioned and released in unison with the specific drivers\nimport { pkgVersion as driverVersion } from \"./packageVersion.js\";\nimport { calculateMaxWaitTime } from \"./runWithRetry.js\";\n\n// We double this value in first try in when we calculate time to wait for in \"calculateMaxWaitTime\" function.\nconst MissingFetchDelayInMs = 50;\n\ntype WorkingState = \"working\" | \"done\" | \"canceled\";\n\n/**\n * Helper class to organize parallel fetching of data\n * It can be used to concurrently do many requests, while consuming\n * data in the right order. Take a look at UT for examples.\n * @param concurrency - level of concurrency\n * @param from - starting point of fetching data (inclusive)\n * @param to - ending point of fetching data. exclusive, or undefined if unknown\n * @param payloadSize - batch size\n * @param logger - logger to use\n * @param requestCallback - callback to request batches\n * @returns Queue that can be used to retrieve data\n * @internal\n */\nexport class ParallelRequests<T> {\n\tprivate latestRequested: number;\n\tprivate nextToDeliver: number;\n\tprivate readonly results = new Map<number, T[]>();\n\tprivate workingState: WorkingState = \"working\";\n\tprivate requestsInFlight = 0;\n\tprivate readonly endEvent = new Deferred<void>();\n\tprivate requests = 0;\n\tprivate readonly knewTo: boolean;\n\n\tprivate get working(): boolean {\n\t\treturn this.workingState === \"working\";\n\t}\n\tpublic get canceled(): boolean {\n\t\treturn this.workingState === \"canceled\";\n\t}\n\n\tconstructor(\n\t\tfrom: number,\n\t\tprivate to: number | undefined,\n\t\tprivate readonly payloadSize: number,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t\tprivate readonly requestCallback: (\n\t\t\trequest: number,\n\t\t\tfrom: number,\n\t\t\tto: number,\n\t\t\tstrongTo: boolean,\n\t\t\tprops: ITelemetryBaseProperties,\n\t\t) => Promise<{ partial: boolean; cancel: boolean; payload: T[] }>,\n\t\tprivate readonly responseCallback: (payload: T[]) => void,\n\t) {\n\t\tthis.latestRequested = from;\n\t\tthis.nextToDeliver = from;\n\t\tthis.knewTo = to !== undefined;\n\t}\n\n\tpublic cancel(): void {\n\t\tif (this.working) {\n\t\t\tthis.workingState = \"canceled\";\n\t\t\tthis.endEvent.resolve();\n\t\t}\n\t}\n\n\tpublic async run(concurrency: number): Promise<void> {\n\t\tassert(concurrency > 0, 0x102 /* \"invalid level of concurrency\" */);\n\t\tassert(this.working, 0x103 /* \"trying to parallel run while not working\" */);\n\n\t\tlet c = concurrency;\n\t\twhile (c > 0) {\n\t\t\tc--;\n\t\t\tthis.addRequest();\n\t\t}\n\t\tthis.dispatch(); // will recalculate and trigger this.endEvent if needed\n\t\treturn this.endEvent.promise;\n\t}\n\n\tprivate done(): void {\n\t\t// We should satisfy request fully.\n\t\tassert(this.to !== undefined, 0x104 /* \"undefined end point for parallel fetch\" */);\n\t\tassert(\n\t\t\tthis.nextToDeliver >= this.to,\n\t\t\t0x105 /* \"unexpected end point for parallel fetch\" */,\n\t\t);\n\t\tif (this.working) {\n\t\t\tthis.workingState = \"done\";\n\t\t\tthis.endEvent.resolve();\n\t\t}\n\t}\n\n\tprivate fail(error): void {\n\t\tif (this.working) {\n\t\t\tthis.workingState = \"done\";\n\t\t\tthis.endEvent.reject(error);\n\t\t}\n\t}\n\n\tprivate dispatch(): void {\n\t\twhile (this.working) {\n\t\t\tconst value = this.results.get(this.nextToDeliver);\n\t\t\tif (value === undefined) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tthis.results.delete(this.nextToDeliver);\n\t\t\tassert(\n\t\t\t\tvalue.length <= this.payloadSize,\n\t\t\t\t0x1d9 /* \"addRequestCore() should break into smaller chunks\" */,\n\t\t\t);\n\t\t\tthis.nextToDeliver += value.length;\n\t\t\tthis.responseCallback(value);\n\t\t}\n\n\t\t// Account for cancellation - state might be not in consistent state on cancelling operation\n\t\tif (this.working) {\n\t\t\tif (this.requestsInFlight === 0) {\n\t\t\t\t// we should have dispatched everything, no matter whether we knew about the end or not.\n\t\t\t\t// see comment in addRequestCore() around throwing away chunk if it's above this.to\n\t\t\t\tassert(\n\t\t\t\t\tthis.results.size === 0,\n\t\t\t\t\t0x107 /* \"ending dispatch with remaining results to be sent\" */,\n\t\t\t\t);\n\t\t\t\tthis.done();\n\t\t\t} else if (this.to !== undefined && this.nextToDeliver >= this.to) {\n\t\t\t\t// Learned about the end and dispatched all the ops up to it.\n\t\t\t\t// Ignore all the in-flight requests above boundary - unblock caller sooner.\n\t\t\t\tassert(\n\t\t\t\t\t!this.knewTo,\n\t\t\t\t\t0x108 /* \"ending results dispatch but knew in advance about more requests\" */,\n\t\t\t\t);\n\t\t\t\tthis.done();\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getNextChunk(): { from: number; to: number } | undefined {\n\t\tif (!this.working) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst from = this.latestRequested;\n\t\tif (this.to !== undefined && this.to <= from) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// this.latestRequested\n\t\t// inclusive on the right side! Exclusive on the left.\n\t\tthis.latestRequested += this.payloadSize;\n\n\t\tif (this.to !== undefined) {\n\t\t\tthis.latestRequested = Math.min(this.to, this.latestRequested);\n\t\t}\n\n\t\tassert(from < this.latestRequested, 0x109 /* \"unexpected next chunk position\" */);\n\n\t\treturn { from, to: this.latestRequested };\n\t}\n\n\tprivate addRequest(): void {\n\t\tconst chunk = this.getNextChunk();\n\t\tif (chunk === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tthis.addRequestCore(chunk.from, chunk.to).catch(this.fail.bind(this));\n\t}\n\n\tprivate async addRequestCore(fromArg: number, toArg: number): Promise<void> {\n\t\tassert(this.working, 0x10a /* \"cannot add parallel request while not working\" */);\n\n\t\tlet from = fromArg;\n\t\tlet to = toArg;\n\n\t\t// to & from are exclusive\n\t\tthis.requestsInFlight++;\n\t\twhile (this.working) {\n\t\t\tconst requestedLength = to - from;\n\t\t\tassert(requestedLength > 0, 0x10b /* \"invalid parallel request range\" */);\n\n\t\t\t// We should not be wasting time asking for something useless.\n\t\t\tif (this.to !== undefined) {\n\t\t\t\tassert(from < this.to, 0x10c /* \"invalid parallel request start point\" */);\n\t\t\t\tassert(to <= this.to, 0x10d /* \"invalid parallel request end point\" */);\n\t\t\t}\n\n\t\t\tthis.requests++;\n\n\t\t\tconst promise = this.requestCallback(this.requests, from, to, this.to !== undefined, {});\n\n\t\t\t// dispatch any prior received data\n\t\t\tthis.dispatch();\n\n\t\t\tconst { payload, cancel, partial } = await promise;\n\n\t\t\tif (cancel) {\n\t\t\t\tthis.cancel();\n\t\t\t}\n\n\t\t\tif (this.to !== undefined && from >= this.to) {\n\t\t\t\t// while we were waiting for response, we learned on what is the boundary\n\t\t\t\t// We can get here (with actual result!) if situation changed while this request was in\n\t\t\t\t// flight, i.e. the end was extended over what we learn in some other request\n\t\t\t\t// While it's useful not to throw this result, this is very corner cases and makes logic\n\t\t\t\t// (including consistency checks) much harder to write correctly.\n\t\t\t\t// So for now, we are throwing this result out the window.\n\t\t\t\tassert(\n\t\t\t\t\t!this.knewTo,\n\t\t\t\t\t0x10e /* \"should not throw result if we knew about boundary in advance\" */,\n\t\t\t\t);\n\t\t\t\t// Learn how often it happens and if it's too wasteful to throw these chunks.\n\t\t\t\t// If it pops into our view a lot, we would need to reconsider how we approach it.\n\t\t\t\t// Note that this is not visible to user other than potentially not hitting 100% of\n\t\t\t\t// what we can in perf domain.\n\t\t\t\tif (payload.length > 0) {\n\t\t\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\t\t\teventName: \"ParallelRequests_GotExtra\",\n\t\t\t\t\t\tfrom,\n\t\t\t\t\t\tto,\n\t\t\t\t\t\tend: this.to,\n\t\t\t\t\t\tlength: payload.length,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (this.working) {\n\t\t\t\tconst fromOrig = from;\n\t\t\t\tconst length = payload.length;\n\t\t\t\tlet fullChunk = requestedLength <= length; // we can possible get more than we asked.\n\n\t\t\t\tif (length === 0) {\n\t\t\t\t\t// 1. empty (partial) chunks should not be returned by various caching / adapter layers -\n\t\t\t\t\t// they should fall back to next layer. This might be important invariant to hold to ensure\n\t\t\t\t\t// that we are less likely have bugs where such layer would keep returning empty partial\n\t\t\t\t\t// result on each call.\n\t\t\t\t\t// 2. Current invariant is that callback does retries until it gets something,\n\t\t\t\t\t// with the goal of failing if zero data is retrieved in given amount of time.\n\t\t\t\t\t// This is very specific property of storage / ops, so this logic is not here, but given only\n\t\t\t\t\t// one user of this class, we assert that to catch issues earlier.\n\t\t\t\t\t// These invariant can be relaxed if needed.\n\t\t\t\t\tassert(\n\t\t\t\t\t\t!partial,\n\t\t\t\t\t\t0x10f /* \"empty/partial chunks should not be returned by caching\" */,\n\t\t\t\t\t);\n\t\t\t\t\tassert(\n\t\t\t\t\t\t!this.knewTo,\n\t\t\t\t\t\t0x110 /* \"callback should retry until valid fetch before it learns new boundary\" */,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t// We can get more than we asked for!\n\t\t\t\t\t// This can screw up logic in dispatch!\n\t\t\t\t\t// So push only batch size, and keep the rest for later - if conditions are favorable, we\n\t\t\t\t\t// will be able to use it. If not (parallel request overlapping these ops), it's easier to\n\t\t\t\t\t// discard them and wait for another (overlapping) request to come in later.\n\t\t\t\t\tif (requestedLength < length) {\n\t\t\t\t\t\t// This is error in a sense that it's not expected and likely points bug in other layer.\n\t\t\t\t\t\t// This layer copes with this situation just fine.\n\t\t\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\t\t\teventName: \"ParallelRequests_Over\",\n\t\t\t\t\t\t\tfrom,\n\t\t\t\t\t\t\tto,\n\t\t\t\t\t\t\tlength,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tconst data = payload.splice(0, requestedLength);\n\t\t\t\t\tthis.results.set(from, data);\n\t\t\t\t\tfrom += data.length;\n\t\t\t\t}\n\n\t\t\t\tif (!partial && !fullChunk) {\n\t\t\t\t\tif (!this.knewTo) {\n\t\t\t\t\t\tif (this.to === undefined || this.to > from) {\n\t\t\t\t\t\t\t// The END\n\t\t\t\t\t\t\tthis.to = from;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t// We know that there are more items to be retrieved\n\t\t\t\t\t// Can we get partial chunk? Ideally storage indicates that's not a full chunk\n\t\t\t\t\t// Note that it's possible that not all ops hit storage yet.\n\t\t\t\t\t// We will come back to request more, and if we can't get any more ops soon, it's\n\t\t\t\t\t// catastrophic failure (see comment above on responsibility of callback to return something)\n\t\t\t\t\t// This layer will just keep trying until it gets full set.\n\t\t\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\t\t\teventName: \"ParallelRequests_Partial\",\n\t\t\t\t\t\tfrom: fromOrig,\n\t\t\t\t\t\tto,\n\t\t\t\t\t\tlength,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tif (to === this.latestRequested) {\n\t\t\t\t\t// we can go after full chunk at the end if we received partial chunk, or more than asked\n\t\t\t\t\t// Also if we got more than we asked to, we can actually use those ops!\n\t\t\t\t\twhile (payload.length > 0) {\n\t\t\t\t\t\tconst data = payload.splice(0, requestedLength);\n\t\t\t\t\t\tthis.results.set(from, data);\n\t\t\t\t\t\tfrom += data.length;\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.latestRequested = from;\n\t\t\t\t\tfullChunk = true;\n\t\t\t\t}\n\n\t\t\t\tif (fullChunk) {\n\t\t\t\t\tconst chunk = this.getNextChunk();\n\t\t\t\t\tif (chunk === undefined) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tfrom = chunk.from;\n\t\t\t\t\tto = chunk.to;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis.requestsInFlight--;\n\t\tthis.dispatch();\n\t}\n}\n\n/**\n * Helper queue class to allow async push / pull\n * It's essentially a pipe allowing multiple writers, and single reader\n * @internal\n */\nexport class Queue<T> implements IStream<T> {\n\tprivate readonly queue: Promise<IStreamResult<T>>[] = [];\n\tprivate deferred: Deferred<IStreamResult<T>> | undefined;\n\tprivate done = false;\n\n\tpublic pushValue(value: T): void {\n\t\tthis.pushCore(Promise.resolve({ done: false, value }));\n\t}\n\n\tpublic pushError(error: unknown): void {\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n\t\tthis.pushCore(Promise.reject(error));\n\t\tthis.done = true;\n\t}\n\n\tpublic pushDone(): void {\n\t\tthis.pushCore(Promise.resolve({ done: true }));\n\t\tthis.done = true;\n\t}\n\n\tprotected pushCore(value: Promise<IStreamResult<T>>): void {\n\t\tassert(!this.done, 0x112 /* \"cannot push onto queue if done\" */);\n\t\tif (this.deferred) {\n\t\t\tassert(this.queue.length === 0, 0x113 /* \"deferred queue should be empty\" */);\n\t\t\tthis.deferred.resolve(value);\n\t\t\tthis.deferred = undefined;\n\t\t} else {\n\t\t\tthis.queue.push(value);\n\t\t}\n\t}\n\n\tpublic async read(): Promise<IStreamResult<T>> {\n\t\tassert(this.deferred === undefined, 0x114 /* \"cannot pop if deferred\" */);\n\t\tconst value = this.queue.shift();\n\t\tif (value !== undefined) {\n\t\t\treturn value;\n\t\t}\n\t\tassert(!this.done, 0x115 /* \"queue should not be done during pop\" */);\n\t\tthis.deferred = new Deferred<IStreamResult<T>>();\n\t\treturn this.deferred.promise;\n\t}\n}\n\nconst waitForOnline = async (): Promise<void> => {\n\t// Only wait if we have a strong signal that we're offline - otherwise assume we're online.\n\tif (globalThis.navigator?.onLine === false && globalThis.addEventListener !== undefined) {\n\t\treturn new Promise<void>((resolve) => {\n\t\t\tconst resolveAndRemoveListener = (): void => {\n\t\t\t\tresolve();\n\t\t\t\tglobalThis.removeEventListener(\"online\", resolveAndRemoveListener);\n\t\t\t};\n\t\t\tglobalThis.addEventListener(\"online\", resolveAndRemoveListener);\n\t\t});\n\t}\n};\n\n/**\n * Retrieve single batch of ops\n * @param request - request index\n * @param from - inclusive boundary\n * @param to - exclusive boundary\n * @param telemetryEvent - telemetry event used to track consecutive batch of requests\n * @param strongTo - tells if ops in range from...to have to be there and have to be retrieved.\n * If false, returning less ops would mean we reached end of file.\n * @param logger - logger object to use to log progress & errors\n * @param signal - cancelation signal\n * @param scenarioName - reason for fetching ops\n * @returns An object with resulting ops and cancellation / partial result flags\n */\nasync function getSingleOpBatch(\n\tget: (telemetryProps: ITelemetryBaseProperties) => Promise<IDeltasFetchResult>,\n\tprops: ITelemetryBaseProperties,\n\tstrongTo: boolean,\n\tlogger: ITelemetryLoggerExt,\n\tsignal?: AbortSignal,\n\tscenarioName?: string,\n): Promise<{ partial: boolean; cancel: boolean; payload: ISequencedDocumentMessage[] }> {\n\tlet lastSuccessTime: number | undefined;\n\tlet totalRetryAfterTime = 0;\n\tlet telemetryEvent: PerformanceEvent | undefined;\n\tlet retry: number = 0;\n\tconst nothing = { partial: false, cancel: true, payload: [] };\n\tlet waitStartTime: number = 0;\n\tlet waitTime = MissingFetchDelayInMs;\n\n\twhile (signal?.aborted !== true) {\n\t\tretry++;\n\t\tlet lastError: unknown;\n\t\tconst startTime = performanceNow();\n\n\t\ttry {\n\t\t\t// Issue async request for deltas\n\t\t\tconst { messages, partialResult } = await get({ ...props, retry } /* telemetry props */);\n\n\t\t\t// If we got messages back, return them. Return regardless of whether we got messages back if we didn't\n\t\t\t// specify a \"to\", since we don't have an expectation of how many to receive.\n\t\t\tif (messages.length > 0 || !strongTo) {\n\t\t\t\t// Report this event if we waited to fetch ops due to being offline or throttling.\n\t\t\t\ttelemetryEvent?.end({\n\t\t\t\t\tduration: totalRetryAfterTime,\n\t\t\t\t\t...props,\n\t\t\t\t\treason: scenarioName,\n\t\t\t\t});\n\t\t\t\treturn { payload: messages, cancel: false, partial: partialResult };\n\t\t\t}\n\n\t\t\t// Otherwise, the storage gave us back an empty set of ops but we were expecting a non-empty set.\n\n\t\t\tif (lastSuccessTime === undefined) {\n\t\t\t\t// Take timestamp of the first time server responded successfully, even though it wasn't with the ops we asked for.\n\t\t\t\t// If we keep getting empty responses we'll eventually fail out below.\n\t\t\t\tlastSuccessTime = performanceNow();\n\t\t\t} else if (performanceNow() - lastSuccessTime > 30000) {\n\t\t\t\t// If we are connected and receiving proper responses from server, but can't get any ops back,\n\t\t\t\t// then give up after some time. This likely indicates the issue with ordering service not flushing\n\t\t\t\t// ops to storage quick enough, and possibly waiting for summaries, while summarizer can't get\n\t\t\t\t// current as it can't get ops.\n\t\t\t\tthrow createGenericNetworkError(\n\t\t\t\t\t// pre-0.58 error message: failedToRetrieveOpsFromStorage:TooManyRetries\n\t\t\t\t\t\"Failed to retrieve ops from storage (Too Many Retries)\",\n\t\t\t\t\t{ canRetry: false },\n\t\t\t\t\t{\n\t\t\t\t\t\tretry,\n\t\t\t\t\t\tdriverVersion,\n\t\t\t\t\t\t...props,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlastError = error;\n\t\t\tconst canRetry = canRetryOnError(error);\n\n\t\t\tconst retryAfter = getRetryDelayFromError(error);\n\n\t\t\t// This will log to error table only if the error is non-retryable\n\t\t\tlogNetworkFailure(\n\t\t\t\tlogger,\n\t\t\t\t{\n\t\t\t\t\teventName: \"GetDeltas_Error\",\n\t\t\t\t\t...props,\n\t\t\t\t\tretry,\n\t\t\t\t\tduration: performanceNow() - startTime,\n\t\t\t\t\tretryAfter,\n\t\t\t\t\treason: scenarioName,\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t);\n\n\t\t\tif (!canRetry) {\n\t\t\t\t// It's game over scenario.\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\n\t\tif (telemetryEvent === undefined) {\n\t\t\twaitStartTime = performanceNow();\n\t\t\ttelemetryEvent = PerformanceEvent.start(logger, {\n\t\t\t\teventName: \"GetDeltasWaitTime\",\n\t\t\t});\n\t\t}\n\n\t\twaitTime = calculateMaxWaitTime(waitTime, lastError);\n\n\t\t// If we get here something has gone wrong - either got an unexpected empty set of messages back or a real error.\n\t\t// Either way we will wait a little bit before retrying.\n\t\tawait new Promise<void>((resolve) => {\n\t\t\tsetTimeout(resolve, waitTime);\n\t\t});\n\n\t\t// If we believe we're offline, we assume there's no point in trying until we at least think we're online.\n\t\t// NOTE: This isn't strictly true for drivers that don't require network (e.g. local driver). Really this logic\n\t\t// should probably live in the driver.\n\t\tawait waitForOnline();\n\t\ttotalRetryAfterTime += performanceNow() - waitStartTime;\n\t}\n\n\treturn nothing;\n}\n\n/**\n * Request ops from storage\n * @param get - Getter callback to get individual batches\n * @param concurrency - Number of concurrent requests to make\n * @param fromTotal - starting sequence number to fetch (inclusive)\n * @param toTotal - max (exclusive) sequence number to fetch\n * @param payloadSize - Payload size\n * @param logger - Logger to log progress and errors\n * @param signal - Cancelation signal\n * @param scenarioName - Reason for fetching ops\n * @returns Messages fetched\n * @internal\n */\nexport function requestOps(\n\tget: (\n\t\tfrom: number,\n\t\tto: number,\n\t\ttelemetryProps: ITelemetryBaseProperties,\n\t) => Promise<IDeltasFetchResult>,\n\tconcurrency: number,\n\tfromTotal: number,\n\ttoTotal: number | undefined,\n\tpayloadSize: number,\n\tlogger: ITelemetryLoggerExt,\n\tsignal?: AbortSignal,\n\tscenarioName?: string,\n): IStream<ISequencedDocumentMessage[]> {\n\tlet requests = 0;\n\tlet lastFetch: number | undefined;\n\tlet length = 0;\n\tconst queue = new Queue<ISequencedDocumentMessage[]>();\n\n\tconst propsTotal: ITelemetryBaseProperties = {\n\t\tfromTotal,\n\t\ttoTotal,\n\t};\n\n\tconst telemetryEvent = PerformanceEvent.start(logger, {\n\t\teventName: \"GetDeltas\",\n\t\t...propsTotal,\n\t\treason: scenarioName,\n\t});\n\n\tconst manager = new ParallelRequests<ISequencedDocumentMessage>(\n\t\tfromTotal,\n\t\ttoTotal,\n\t\tpayloadSize,\n\t\tlogger,\n\t\tasync (\n\t\t\trequest: number,\n\t\t\tfrom: number,\n\t\t\tto: number,\n\t\t\tstrongTo: boolean,\n\t\t\tpropsPerRequest: ITelemetryBaseProperties,\n\t\t) => {\n\t\t\trequests++;\n\t\t\treturn getSingleOpBatch(\n\t\t\t\tasync (propsAll) => get(from, to, propsAll),\n\t\t\t\t{ request, from, to, ...propsTotal, ...propsPerRequest },\n\t\t\t\tstrongTo,\n\t\t\t\tlogger,\n\t\t\t\tsignal,\n\t\t\t\tscenarioName,\n\t\t\t);\n\t\t},\n\t\t(deltas: ISequencedDocumentMessage[]) => {\n\t\t\t// Assert continuing and right start.\n\t\t\tif (lastFetch === undefined) {\n\t\t\t\tassert(deltas[0].sequenceNumber === fromTotal, 0x26d /* \"wrong start\" */);\n\t\t\t} else {\n\t\t\t\tassert(deltas[0].sequenceNumber === lastFetch + 1, 0x26e /* \"wrong start\" */);\n\t\t\t}\n\t\t\tlastFetch = deltas[deltas.length - 1].sequenceNumber;\n\t\t\tassert(\n\t\t\t\tlastFetch - deltas[0].sequenceNumber + 1 === deltas.length,\n\t\t\t\t0x26f /* \"continuous and no duplicates\" */,\n\t\t\t);\n\t\t\tlength += deltas.length;\n\t\t\tqueue.pushValue(deltas);\n\t\t},\n\t);\n\n\t// Implement faster cancellation. getSingleOpBatch() checks signal, but only in between\n\t// waits (up to 10 seconds) and fetches (can take infinite amount of time).\n\t// While every such case should be improved and take into account signal (and thus cancel immediately),\n\t// it is beneficial to have catch-all\n\tconst listener = (event: Event): void => {\n\t\tmanager.cancel();\n\t};\n\tif (signal !== undefined) {\n\t\tsignal.addEventListener(\"abort\", listener);\n\t}\n\n\tmanager\n\t\t.run(concurrency)\n\t\t.finally(() => {\n\t\t\tif (signal !== undefined) {\n\t\t\t\tsignal.removeEventListener(\"abort\", listener);\n\t\t\t}\n\t\t})\n\t\t.then(() => {\n\t\t\tconst props = {\n\t\t\t\tlastFetch,\n\t\t\t\tlength,\n\t\t\t\trequests,\n\t\t\t};\n\t\t\tif (manager.canceled) {\n\t\t\t\ttelemetryEvent.cancel({ ...props, error: \"ops request cancelled by client\" });\n\t\t\t} else {\n\t\t\t\tassert(\n\t\t\t\t\ttoTotal === undefined || (lastFetch !== undefined && lastFetch >= toTotal - 1),\n\t\t\t\t\t0x270 /* \"All requested ops fetched\" */,\n\t\t\t\t);\n\t\t\t\ttelemetryEvent.end(props);\n\t\t\t}\n\t\t\tqueue.pushDone();\n\t\t})\n\t\t.catch((error) => {\n\t\t\ttelemetryEvent.cancel(\n\t\t\t\t{\n\t\t\t\t\tlastFetch,\n\t\t\t\t\tlength,\n\t\t\t\t\trequests,\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t);\n\t\t\tqueue.pushError(error);\n\t\t});\n\n\treturn queue;\n}\n\n/**\n * @internal\n */\nexport const emptyMessageStream: IStream<ISequencedDocumentMessage[]> = {\n\tread: async () => {\n\t\treturn { done: true };\n\t},\n};\n\n/**\n * Creates a stream from the provided promise of messages.\n *\n * @internal\n */\nexport function streamFromMessages(\n\tmessagesArg: Promise<ISequencedDocumentMessage[]>,\n): IStream<ISequencedDocumentMessage[]> {\n\tlet messages: Promise<ISequencedDocumentMessage[]> | undefined = messagesArg;\n\treturn {\n\t\tread: async () => {\n\t\t\tif (messages === undefined) {\n\t\t\t\treturn { done: true };\n\t\t\t}\n\t\t\tconst value = await messages;\n\t\t\t// eslint-disable-next-line require-atomic-updates\n\t\t\tmessages = undefined;\n\t\t\treturn value.length === 0 ? { done: true } : { done: false, value };\n\t\t},\n\t};\n}\n\n/**\n * Wraps the provided stream to observe values as they are read.\n *\n * @internal\n */\nexport function streamObserver<T>(\n\tstream: IStream<T>,\n\thandler: (value: IStreamResult<T>) => void,\n): IStream<T> {\n\treturn {\n\t\tread: async () => {\n\t\t\tconst value = await stream.read();\n\t\t\thandler(value);\n\t\t\treturn value;\n\t\t},\n\t};\n}\n"]}