@fluidframework/container-loader 1.4.0-121020 → 2.0.0-dev-rc.1.0.0.224419

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 (333) hide show
  1. package/.eslintrc.js +18 -21
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +364 -0
  4. package/README.md +152 -56
  5. package/api-extractor-lint.json +4 -0
  6. package/api-extractor.json +2 -2
  7. package/api-report/container-loader.api.md +143 -0
  8. package/dist/{audience.js → audience.cjs} +15 -13
  9. package/dist/audience.cjs.map +1 -0
  10. package/dist/audience.d.ts +4 -6
  11. package/dist/audience.d.ts.map +1 -1
  12. package/dist/catchUpMonitor.cjs +43 -0
  13. package/dist/catchUpMonitor.cjs.map +1 -0
  14. package/dist/catchUpMonitor.d.ts +29 -0
  15. package/dist/catchUpMonitor.d.ts.map +1 -0
  16. package/dist/{connectionManager.js → connectionManager.cjs} +397 -240
  17. package/dist/connectionManager.cjs.map +1 -0
  18. package/dist/connectionManager.d.ts +23 -33
  19. package/dist/connectionManager.d.ts.map +1 -1
  20. package/dist/{connectionState.js → connectionState.cjs} +5 -7
  21. package/dist/connectionState.cjs.map +1 -0
  22. package/dist/connectionState.d.ts +3 -5
  23. package/dist/connectionState.d.ts.map +1 -1
  24. package/dist/connectionStateHandler.cjs +474 -0
  25. package/dist/connectionStateHandler.cjs.map +1 -0
  26. package/dist/connectionStateHandler.d.ts +127 -29
  27. package/dist/connectionStateHandler.d.ts.map +1 -1
  28. package/dist/container-loader-alpha.d.ts +274 -0
  29. package/dist/container-loader-beta.d.ts +75 -0
  30. package/dist/container-loader-public.d.ts +75 -0
  31. package/dist/container-loader-untrimmed.d.ts +331 -0
  32. package/dist/container.cjs +1585 -0
  33. package/dist/container.cjs.map +1 -0
  34. package/dist/container.d.ts +227 -83
  35. package/dist/container.d.ts.map +1 -1
  36. package/dist/containerContext.cjs +74 -0
  37. package/dist/containerContext.cjs.map +1 -0
  38. package/dist/containerContext.d.ts +33 -59
  39. package/dist/containerContext.d.ts.map +1 -1
  40. package/dist/containerStorageAdapter.cjs +234 -0
  41. package/dist/containerStorageAdapter.cjs.map +1 -0
  42. package/dist/containerStorageAdapter.d.ts +48 -23
  43. package/dist/containerStorageAdapter.d.ts.map +1 -1
  44. package/dist/{contracts.js → contracts.cjs} +5 -5
  45. package/dist/contracts.cjs.map +1 -0
  46. package/dist/contracts.d.ts +45 -17
  47. package/dist/contracts.d.ts.map +1 -1
  48. package/dist/debugLogger.cjs +101 -0
  49. package/dist/debugLogger.cjs.map +1 -0
  50. package/dist/debugLogger.d.ts +30 -0
  51. package/dist/debugLogger.d.ts.map +1 -0
  52. package/dist/{deltaManager.js → deltaManager.cjs} +379 -186
  53. package/dist/deltaManager.cjs.map +1 -0
  54. package/dist/deltaManager.d.ts +54 -18
  55. package/dist/deltaManager.d.ts.map +1 -1
  56. package/dist/{deltaQueue.js → deltaQueue.cjs} +29 -28
  57. package/dist/deltaQueue.cjs.map +1 -0
  58. package/dist/deltaQueue.d.ts +3 -4
  59. package/dist/deltaQueue.d.ts.map +1 -1
  60. package/dist/disposal.cjs +25 -0
  61. package/dist/disposal.cjs.map +1 -0
  62. package/dist/disposal.d.ts +13 -0
  63. package/dist/disposal.d.ts.map +1 -0
  64. package/dist/error.cjs +32 -0
  65. package/dist/error.cjs.map +1 -0
  66. package/dist/error.d.ts +23 -0
  67. package/dist/error.d.ts.map +1 -0
  68. package/dist/index.cjs +19 -0
  69. package/dist/index.cjs.map +1 -0
  70. package/dist/index.d.ts +5 -2
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/loader.cjs +148 -0
  73. package/dist/loader.cjs.map +1 -0
  74. package/dist/loader.d.ts +38 -19
  75. package/dist/loader.d.ts.map +1 -1
  76. package/dist/location-redirection-utilities/index.cjs +11 -0
  77. package/dist/location-redirection-utilities/index.cjs.map +1 -0
  78. package/dist/location-redirection-utilities/index.d.ts +6 -0
  79. package/dist/location-redirection-utilities/index.d.ts.map +1 -0
  80. package/dist/location-redirection-utilities/resolveWithLocationRedirection.cjs +53 -0
  81. package/dist/location-redirection-utilities/resolveWithLocationRedirection.cjs.map +1 -0
  82. package/dist/location-redirection-utilities/resolveWithLocationRedirection.d.ts +24 -0
  83. package/dist/location-redirection-utilities/resolveWithLocationRedirection.d.ts.map +1 -0
  84. package/dist/{collabWindowTracker.js → noopHeuristic.cjs} +37 -39
  85. package/dist/noopHeuristic.cjs.map +1 -0
  86. package/dist/noopHeuristic.d.ts +23 -0
  87. package/dist/noopHeuristic.d.ts.map +1 -0
  88. package/dist/{packageVersion.js → packageVersion.cjs} +2 -2
  89. package/dist/packageVersion.cjs.map +1 -0
  90. package/dist/packageVersion.d.ts +1 -1
  91. package/dist/packageVersion.d.ts.map +1 -1
  92. package/dist/protocol.cjs +99 -0
  93. package/dist/protocol.cjs.map +1 -0
  94. package/dist/protocol.d.ts +38 -0
  95. package/dist/protocol.d.ts.map +1 -0
  96. package/dist/{protocolTreeDocumentStorageService.js → protocolTreeDocumentStorageService.cjs} +8 -5
  97. package/dist/protocolTreeDocumentStorageService.cjs.map +1 -0
  98. package/dist/protocolTreeDocumentStorageService.d.ts +8 -4
  99. package/dist/protocolTreeDocumentStorageService.d.ts.map +1 -1
  100. package/dist/quorum.cjs +16 -0
  101. package/dist/quorum.cjs.map +1 -0
  102. package/dist/quorum.d.ts +1 -14
  103. package/dist/quorum.d.ts.map +1 -1
  104. package/dist/{retriableDocumentStorageService.js → retriableDocumentStorageService.cjs} +36 -21
  105. package/dist/retriableDocumentStorageService.cjs.map +1 -0
  106. package/dist/retriableDocumentStorageService.d.ts +7 -5
  107. package/dist/retriableDocumentStorageService.d.ts.map +1 -1
  108. package/dist/tsdoc-metadata.json +11 -0
  109. package/dist/{utils.js → utils.cjs} +52 -14
  110. package/dist/utils.cjs.map +1 -0
  111. package/dist/utils.d.ts +34 -1
  112. package/dist/utils.d.ts.map +1 -1
  113. package/lib/{audience.d.ts → audience.d.mts} +4 -10
  114. package/lib/audience.d.mts.map +1 -0
  115. package/lib/{audience.js → audience.mjs} +15 -17
  116. package/lib/audience.mjs.map +1 -0
  117. package/lib/catchUpMonitor.d.mts +29 -0
  118. package/lib/catchUpMonitor.d.mts.map +1 -0
  119. package/lib/catchUpMonitor.mjs +39 -0
  120. package/lib/catchUpMonitor.mjs.map +1 -0
  121. package/lib/{connectionManager.d.ts → connectionManager.d.mts} +23 -33
  122. package/lib/connectionManager.d.mts.map +1 -0
  123. package/lib/{connectionManager.js → connectionManager.mjs} +378 -218
  124. package/lib/connectionManager.mjs.map +1 -0
  125. package/lib/{connectionState.d.ts → connectionState.d.mts} +3 -5
  126. package/lib/connectionState.d.mts.map +1 -0
  127. package/lib/{connectionState.js → connectionState.mjs} +4 -6
  128. package/lib/connectionState.mjs.map +1 -0
  129. package/lib/connectionStateHandler.d.mts +179 -0
  130. package/lib/connectionStateHandler.d.mts.map +1 -0
  131. package/lib/connectionStateHandler.mjs +469 -0
  132. package/lib/connectionStateHandler.mjs.map +1 -0
  133. package/lib/container-loader-alpha.d.mts +274 -0
  134. package/lib/container-loader-beta.d.mts +75 -0
  135. package/lib/container-loader-public.d.mts +75 -0
  136. package/lib/container-loader-untrimmed.d.mts +331 -0
  137. package/lib/container.d.mts +382 -0
  138. package/lib/container.d.mts.map +1 -0
  139. package/lib/container.mjs +1579 -0
  140. package/lib/container.mjs.map +1 -0
  141. package/lib/containerContext.d.mts +58 -0
  142. package/lib/containerContext.d.mts.map +1 -0
  143. package/lib/containerContext.mjs +70 -0
  144. package/lib/containerContext.mjs.map +1 -0
  145. package/lib/containerStorageAdapter.d.mts +73 -0
  146. package/lib/containerStorageAdapter.d.mts.map +1 -0
  147. package/lib/containerStorageAdapter.mjs +228 -0
  148. package/lib/containerStorageAdapter.mjs.map +1 -0
  149. package/lib/{contracts.d.ts → contracts.d.mts} +45 -17
  150. package/lib/contracts.d.mts.map +1 -0
  151. package/lib/{contracts.js → contracts.mjs} +4 -4
  152. package/lib/contracts.mjs.map +1 -0
  153. package/lib/debugLogger.d.mts +30 -0
  154. package/lib/debugLogger.d.mts.map +1 -0
  155. package/lib/debugLogger.mjs +93 -0
  156. package/lib/debugLogger.mjs.map +1 -0
  157. package/lib/{deltaManager.d.ts → deltaManager.d.mts} +54 -18
  158. package/lib/deltaManager.d.mts.map +1 -0
  159. package/lib/{deltaManager.js → deltaManager.mjs} +361 -165
  160. package/lib/deltaManager.mjs.map +1 -0
  161. package/lib/{deltaQueue.d.ts → deltaQueue.d.mts} +3 -4
  162. package/lib/deltaQueue.d.mts.map +1 -0
  163. package/lib/{deltaQueue.js → deltaQueue.mjs} +25 -24
  164. package/lib/deltaQueue.mjs.map +1 -0
  165. package/lib/disposal.d.mts +13 -0
  166. package/lib/disposal.d.mts.map +1 -0
  167. package/lib/disposal.mjs +21 -0
  168. package/lib/disposal.mjs.map +1 -0
  169. package/lib/error.d.mts +23 -0
  170. package/lib/error.d.mts.map +1 -0
  171. package/lib/error.mjs +28 -0
  172. package/lib/error.mjs.map +1 -0
  173. package/lib/index.d.mts +11 -0
  174. package/lib/index.d.mts.map +1 -0
  175. package/lib/index.mjs +10 -0
  176. package/lib/index.mjs.map +1 -0
  177. package/lib/{loader.d.ts → loader.d.mts} +39 -20
  178. package/lib/loader.d.mts.map +1 -0
  179. package/lib/loader.mjs +143 -0
  180. package/lib/loader.mjs.map +1 -0
  181. package/lib/location-redirection-utilities/index.d.mts +6 -0
  182. package/lib/location-redirection-utilities/index.d.mts.map +1 -0
  183. package/lib/location-redirection-utilities/index.mjs +6 -0
  184. package/lib/location-redirection-utilities/index.mjs.map +1 -0
  185. package/lib/location-redirection-utilities/resolveWithLocationRedirection.d.mts +24 -0
  186. package/lib/location-redirection-utilities/resolveWithLocationRedirection.d.mts.map +1 -0
  187. package/lib/location-redirection-utilities/resolveWithLocationRedirection.mjs +48 -0
  188. package/lib/location-redirection-utilities/resolveWithLocationRedirection.mjs.map +1 -0
  189. package/lib/noopHeuristic.d.mts +23 -0
  190. package/lib/noopHeuristic.d.mts.map +1 -0
  191. package/lib/{collabWindowTracker.js → noopHeuristic.mjs} +33 -35
  192. package/lib/noopHeuristic.mjs.map +1 -0
  193. package/lib/{packageVersion.d.ts → packageVersion.d.mts} +1 -1
  194. package/lib/{packageVersion.d.ts.map → packageVersion.d.mts.map} +1 -1
  195. package/lib/{packageVersion.js → packageVersion.mjs} +2 -2
  196. package/lib/packageVersion.mjs.map +1 -0
  197. package/lib/protocol.d.mts +38 -0
  198. package/lib/protocol.d.mts.map +1 -0
  199. package/lib/protocol.mjs +94 -0
  200. package/lib/protocol.mjs.map +1 -0
  201. package/lib/{protocolTreeDocumentStorageService.d.ts → protocolTreeDocumentStorageService.d.mts} +8 -4
  202. package/lib/protocolTreeDocumentStorageService.d.mts.map +1 -0
  203. package/lib/{protocolTreeDocumentStorageService.js → protocolTreeDocumentStorageService.mjs} +8 -5
  204. package/lib/protocolTreeDocumentStorageService.mjs.map +1 -0
  205. package/lib/quorum.d.mts +4 -0
  206. package/lib/quorum.d.mts.map +1 -0
  207. package/lib/quorum.mjs +12 -0
  208. package/lib/quorum.mjs.map +1 -0
  209. package/lib/{retriableDocumentStorageService.d.ts → retriableDocumentStorageService.d.mts} +7 -5
  210. package/lib/retriableDocumentStorageService.d.mts.map +1 -0
  211. package/lib/{retriableDocumentStorageService.js → retriableDocumentStorageService.mjs} +35 -20
  212. package/lib/retriableDocumentStorageService.mjs.map +1 -0
  213. package/lib/utils.d.mts +67 -0
  214. package/lib/utils.d.mts.map +1 -0
  215. package/lib/{utils.js → utils.mjs} +47 -11
  216. package/lib/utils.mjs.map +1 -0
  217. package/package.json +163 -70
  218. package/prettier.config.cjs +8 -0
  219. package/src/audience.ts +59 -49
  220. package/src/catchUpMonitor.ts +61 -0
  221. package/src/connectionManager.ts +1154 -910
  222. package/src/connectionState.ts +22 -25
  223. package/src/connectionStateHandler.ts +689 -319
  224. package/src/container.ts +2476 -1792
  225. package/src/containerContext.ts +98 -330
  226. package/src/containerStorageAdapter.ts +301 -105
  227. package/src/contracts.ts +184 -146
  228. package/src/debugLogger.ts +123 -0
  229. package/src/deltaManager.ts +1165 -900
  230. package/src/deltaQueue.ts +156 -152
  231. package/src/disposal.ts +25 -0
  232. package/src/error.ts +44 -0
  233. package/src/index.ts +14 -15
  234. package/src/loader.ts +356 -427
  235. package/src/location-redirection-utilities/index.ts +9 -0
  236. package/src/location-redirection-utilities/resolveWithLocationRedirection.ts +61 -0
  237. package/src/noopHeuristic.ts +107 -0
  238. package/src/packageVersion.ts +1 -1
  239. package/src/protocol.ts +150 -0
  240. package/src/protocolTreeDocumentStorageService.ts +35 -35
  241. package/src/quorum.ts +11 -50
  242. package/src/retriableDocumentStorageService.ts +135 -95
  243. package/src/utils.ts +159 -86
  244. package/tsc-multi.test.json +4 -0
  245. package/tsconfig.json +10 -12
  246. package/dist/audience.js.map +0 -1
  247. package/dist/collabWindowTracker.d.ts +0 -19
  248. package/dist/collabWindowTracker.d.ts.map +0 -1
  249. package/dist/collabWindowTracker.js.map +0 -1
  250. package/dist/connectionManager.js.map +0 -1
  251. package/dist/connectionState.js.map +0 -1
  252. package/dist/connectionStateHandler.js +0 -280
  253. package/dist/connectionStateHandler.js.map +0 -1
  254. package/dist/container.js +0 -1284
  255. package/dist/container.js.map +0 -1
  256. package/dist/containerContext.js +0 -217
  257. package/dist/containerContext.js.map +0 -1
  258. package/dist/containerStorageAdapter.js +0 -104
  259. package/dist/containerStorageAdapter.js.map +0 -1
  260. package/dist/contracts.js.map +0 -1
  261. package/dist/deltaManager.js.map +0 -1
  262. package/dist/deltaManagerProxy.d.ts +0 -54
  263. package/dist/deltaManagerProxy.d.ts.map +0 -1
  264. package/dist/deltaManagerProxy.js +0 -115
  265. package/dist/deltaManagerProxy.js.map +0 -1
  266. package/dist/deltaQueue.js.map +0 -1
  267. package/dist/index.js +0 -16
  268. package/dist/index.js.map +0 -1
  269. package/dist/loader.js +0 -241
  270. package/dist/loader.js.map +0 -1
  271. package/dist/packageVersion.js.map +0 -1
  272. package/dist/protocolTreeDocumentStorageService.js.map +0 -1
  273. package/dist/quorum.js +0 -44
  274. package/dist/quorum.js.map +0 -1
  275. package/dist/retriableDocumentStorageService.js.map +0 -1
  276. package/dist/utils.js.map +0 -1
  277. package/lib/audience.d.ts.map +0 -1
  278. package/lib/audience.js.map +0 -1
  279. package/lib/collabWindowTracker.d.ts +0 -19
  280. package/lib/collabWindowTracker.d.ts.map +0 -1
  281. package/lib/collabWindowTracker.js.map +0 -1
  282. package/lib/connectionManager.d.ts.map +0 -1
  283. package/lib/connectionManager.js.map +0 -1
  284. package/lib/connectionState.d.ts.map +0 -1
  285. package/lib/connectionState.js.map +0 -1
  286. package/lib/connectionStateHandler.d.ts +0 -81
  287. package/lib/connectionStateHandler.d.ts.map +0 -1
  288. package/lib/connectionStateHandler.js +0 -276
  289. package/lib/connectionStateHandler.js.map +0 -1
  290. package/lib/container.d.ts +0 -238
  291. package/lib/container.d.ts.map +0 -1
  292. package/lib/container.js +0 -1276
  293. package/lib/container.js.map +0 -1
  294. package/lib/containerContext.d.ts +0 -84
  295. package/lib/containerContext.d.ts.map +0 -1
  296. package/lib/containerContext.js +0 -213
  297. package/lib/containerContext.js.map +0 -1
  298. package/lib/containerStorageAdapter.d.ts +0 -48
  299. package/lib/containerStorageAdapter.d.ts.map +0 -1
  300. package/lib/containerStorageAdapter.js +0 -99
  301. package/lib/containerStorageAdapter.js.map +0 -1
  302. package/lib/contracts.d.ts.map +0 -1
  303. package/lib/contracts.js.map +0 -1
  304. package/lib/deltaManager.d.ts.map +0 -1
  305. package/lib/deltaManager.js.map +0 -1
  306. package/lib/deltaManagerProxy.d.ts +0 -54
  307. package/lib/deltaManagerProxy.d.ts.map +0 -1
  308. package/lib/deltaManagerProxy.js +0 -110
  309. package/lib/deltaManagerProxy.js.map +0 -1
  310. package/lib/deltaQueue.d.ts.map +0 -1
  311. package/lib/deltaQueue.js.map +0 -1
  312. package/lib/index.d.ts +0 -8
  313. package/lib/index.d.ts.map +0 -1
  314. package/lib/index.js +0 -8
  315. package/lib/index.js.map +0 -1
  316. package/lib/loader.d.ts.map +0 -1
  317. package/lib/loader.js +0 -236
  318. package/lib/loader.js.map +0 -1
  319. package/lib/packageVersion.js.map +0 -1
  320. package/lib/protocolTreeDocumentStorageService.d.ts.map +0 -1
  321. package/lib/protocolTreeDocumentStorageService.js.map +0 -1
  322. package/lib/quorum.d.ts +0 -21
  323. package/lib/quorum.d.ts.map +0 -1
  324. package/lib/quorum.js +0 -38
  325. package/lib/quorum.js.map +0 -1
  326. package/lib/retriableDocumentStorageService.d.ts.map +0 -1
  327. package/lib/retriableDocumentStorageService.js.map +0 -1
  328. package/lib/utils.d.ts +0 -34
  329. package/lib/utils.d.ts.map +0 -1
  330. package/lib/utils.js.map +0 -1
  331. package/src/collabWindowTracker.ts +0 -102
  332. package/src/deltaManagerProxy.ts +0 -158
  333. package/tsconfig.esnext.json +0 -7
package/lib/loader.mjs ADDED
@@ -0,0 +1,143 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { v4 as uuid } from "uuid";
6
+ import { mixinMonitoringContext, PerformanceEvent, sessionStorageConfigProvider, createChildMonitoringContext, UsageError, } from "@fluidframework/telemetry-utils";
7
+ import { LoaderHeader, } from "@fluidframework/container-definitions";
8
+ import { Container } from "./container.mjs";
9
+ import { tryParseCompatibleResolvedUrl } from "./utils.mjs";
10
+ import { pkgVersion } from "./packageVersion.mjs";
11
+ import { DebugLogger } from "./debugLogger.mjs";
12
+ function ensureResolvedUrlDefined(resolved) {
13
+ if (resolved === undefined) {
14
+ throw new Error(`Object is not a IResolveUrl.`);
15
+ }
16
+ }
17
+ /**
18
+ * @internal
19
+ */
20
+ export class RelativeLoader {
21
+ constructor(container, loader) {
22
+ this.container = container;
23
+ this.loader = loader;
24
+ }
25
+ async resolve(request) {
26
+ if (request.url.startsWith("/")) {
27
+ ensureResolvedUrlDefined(this.container.resolvedUrl);
28
+ const container = await this.container.clone({
29
+ resolvedUrl: { ...this.container.resolvedUrl },
30
+ version: request.headers?.[LoaderHeader.version] ?? undefined,
31
+ loadMode: request.headers?.[LoaderHeader.loadMode],
32
+ }, {
33
+ canReconnect: request.headers?.[LoaderHeader.reconnect],
34
+ clientDetailsOverride: request.headers?.[LoaderHeader.clientDetails],
35
+ });
36
+ return container;
37
+ }
38
+ if (this.loader === undefined) {
39
+ throw new Error("Cannot resolve external containers");
40
+ }
41
+ return this.loader.resolve(request);
42
+ }
43
+ }
44
+ /**
45
+ * Manages Fluid resource loading
46
+ * @alpha
47
+ */
48
+ export class Loader {
49
+ constructor(loaderProps) {
50
+ const { urlResolver, documentServiceFactory, codeLoader, options, scope, logger, detachedBlobStorage, configProvider, protocolHandlerBuilder, } = loaderProps;
51
+ const telemetryProps = {
52
+ loaderId: uuid(),
53
+ loaderVersion: pkgVersion,
54
+ };
55
+ const subMc = mixinMonitoringContext(DebugLogger.mixinDebugLogger("fluid:telemetry", logger, {
56
+ all: telemetryProps,
57
+ }), sessionStorageConfigProvider.value, configProvider);
58
+ this.services = {
59
+ urlResolver,
60
+ documentServiceFactory,
61
+ codeLoader,
62
+ options: options ?? {},
63
+ scope: options?.provideScopeLoader !== false ? { ...scope, ILoader: this } : { ...scope },
64
+ detachedBlobStorage,
65
+ protocolHandlerBuilder,
66
+ subLogger: subMc.logger,
67
+ };
68
+ this.mc = createChildMonitoringContext({
69
+ logger: this.services.subLogger,
70
+ namespace: "Loader",
71
+ });
72
+ }
73
+ async createDetachedContainer(codeDetails, createDetachedProps) {
74
+ return Container.createDetached({
75
+ ...createDetachedProps,
76
+ ...this.services,
77
+ }, codeDetails);
78
+ }
79
+ async rehydrateDetachedContainerFromSnapshot(snapshot, createDetachedProps) {
80
+ return Container.rehydrateDetachedFromSnapshot({
81
+ ...createDetachedProps,
82
+ ...this.services,
83
+ }, snapshot);
84
+ }
85
+ async resolve(request, pendingLocalState) {
86
+ const eventName = pendingLocalState === undefined ? "Resolve" : "ResolveWithPendingState";
87
+ return PerformanceEvent.timedExecAsync(this.mc.logger, { eventName }, async () => {
88
+ const resolved = await this.resolveCore(request, pendingLocalState !== undefined ? JSON.parse(pendingLocalState) : undefined);
89
+ return resolved.container;
90
+ });
91
+ }
92
+ async resolveCore(request, pendingLocalState) {
93
+ const resolvedAsFluid = await this.services.urlResolver.resolve(request);
94
+ ensureResolvedUrlDefined(resolvedAsFluid);
95
+ // Parse URL into data stores
96
+ const parsed = tryParseCompatibleResolvedUrl(resolvedAsFluid.url);
97
+ if (parsed === undefined) {
98
+ throw new Error(`Invalid URL ${resolvedAsFluid.url}`);
99
+ }
100
+ if (pendingLocalState !== undefined) {
101
+ const parsedPendingUrl = tryParseCompatibleResolvedUrl(pendingLocalState.url);
102
+ if (parsedPendingUrl?.id !== parsed.id ||
103
+ parsedPendingUrl?.path.replace(/\/$/, "") !== parsed.path.replace(/\/$/, "")) {
104
+ const message = `URL ${resolvedAsFluid.url} does not match pending state URL ${pendingLocalState.url}`;
105
+ throw new Error(message);
106
+ }
107
+ }
108
+ request.headers ?? (request.headers = {});
109
+ // If set in both query string and headers, use query string. Also write the value from the query string into the header either way.
110
+ request.headers[LoaderHeader.version] =
111
+ parsed.version ?? request.headers[LoaderHeader.version];
112
+ const fromSequenceNumber = request.headers[LoaderHeader.sequenceNumber];
113
+ const opsBeforeReturn = request.headers[LoaderHeader.loadMode]?.opsBeforeReturn;
114
+ if (opsBeforeReturn === "sequenceNumber" &&
115
+ (fromSequenceNumber === undefined || fromSequenceNumber < 0)) {
116
+ // If opsBeforeReturn is set to "sequenceNumber", then fromSequenceNumber should be set to a non-negative integer.
117
+ throw new UsageError("sequenceNumber must be set to a non-negative integer");
118
+ }
119
+ else if (opsBeforeReturn !== "sequenceNumber" && fromSequenceNumber !== undefined) {
120
+ // If opsBeforeReturn is not set to "sequenceNumber", then fromSequenceNumber should be undefined (default value).
121
+ // In this case, we should throw an error since opsBeforeReturn is not explicitly set to "sequenceNumber".
122
+ throw new UsageError('opsBeforeReturn must be set to "sequenceNumber"');
123
+ }
124
+ return {
125
+ container: await this.loadContainer(request, resolvedAsFluid, pendingLocalState),
126
+ parsed,
127
+ };
128
+ }
129
+ async loadContainer(request, resolvedUrl, pendingLocalState) {
130
+ return Container.load({
131
+ resolvedUrl,
132
+ version: request.headers?.[LoaderHeader.version] ?? undefined,
133
+ loadMode: request.headers?.[LoaderHeader.loadMode],
134
+ pendingLocalState,
135
+ loadToSequenceNumber: request.headers?.[LoaderHeader.sequenceNumber],
136
+ }, {
137
+ canReconnect: request.headers?.[LoaderHeader.reconnect],
138
+ clientDetailsOverride: request.headers?.[LoaderHeader.clientDetails],
139
+ ...this.services,
140
+ });
141
+ }
142
+ }
143
+ //# sourceMappingURL=loader.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.mjs","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM;OAC1B,EAEN,sBAAsB,EAEtB,gBAAgB,EAChB,4BAA4B,EAC5B,4BAA4B,EAC5B,UAAU,GACV,MAAM,iCAAiC;OAOjC,EAMN,YAAY,GAGZ,MAAM,uCAAuC;OAQvC,EAAE,SAAS,EAA0B;OACrC,EAAc,6BAA6B,EAAE;OAC7C,EAAE,UAAU,EAAE;OAEd,EAAE,WAAW,EAAE;AAEtB,SAAS,wBAAwB,CAChC,QAAkC;IAElC,IAAI,QAAQ,KAAK,SAAS,EAAE;QAC3B,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;KAChD;AACF,CAAC;AACD;;GAEG;AACH,MAAM,OAAO,cAAc;IAC1B,YACkB,SAAoB,EACpB,MAA2B;QAD3B,cAAS,GAAT,SAAS,CAAW;QACpB,WAAM,GAAN,MAAM,CAAqB;IAC1C,CAAC;IAEG,KAAK,CAAC,OAAO,CAAC,OAAiB;QACrC,IAAI,OAAO,CAAC,GAAG,C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(c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport {\n\tITelemetryLoggerExt,\n\tmixinMonitoringContext,\n\tMonitoringContext,\n\tPerformanceEvent,\n\tsessionStorageConfigProvider,\n\tcreateChildMonitoringContext,\n\tUsageError,\n} from \"@fluidframework/telemetry-utils\";\nimport {\n\tITelemetryBaseLogger,\n\tFluidObject,\n\tIRequest,\n\tIConfigProviderBase,\n} from \"@fluidframework/core-interfaces\";\nimport {\n\tIContainer,\n\tIFluidModule,\n\tIHostLoader,\n\tILoader,\n\tILoaderOptions as ILoaderOptions1,\n\tLoaderHeader,\n\tIProvideFluidCodeDetailsComparer,\n\tIFluidCodeDetails,\n} from \"@fluidframework/container-definitions\";\nimport {\n\tIDocumentServiceFactory,\n\tIDocumentStorageService,\n\tIResolvedUrl,\n\tIUrlResolver,\n} from \"@fluidframework/driver-definitions\";\nimport { IClientDetails } from \"@fluidframework/protocol-definitions\";\nimport { Container, IPendingContainerState } from \"./container\";\nimport { IParsedUrl, tryParseCompatibleResolvedUrl } from \"./utils\";\nimport { pkgVersion } from \"./packageVersion\";\nimport { ProtocolHandlerBuilder } from \"./protocol\";\nimport { DebugLogger } from \"./debugLogger\";\n\nfunction ensureResolvedUrlDefined(\n\tresolved: IResolvedUrl | undefined,\n): asserts resolved is IResolvedUrl {\n\tif (resolved === undefined) {\n\t\tthrow new Error(`Object is not a IResolveUrl.`);\n\t}\n}\n/**\n * @internal\n */\nexport class RelativeLoader implements ILoader {\n\tconstructor(\n\t\tprivate readonly container: Container,\n\t\tprivate readonly loader: ILoader | undefined,\n\t) {}\n\n\tpublic async resolve(request: IRequest): Promise<IContainer> {\n\t\tif (request.url.startsWith(\"/\")) {\n\t\t\tensureResolvedUrlDefined(this.container.resolvedUrl);\n\t\t\tconst container = await this.container.clone(\n\t\t\t\t{\n\t\t\t\t\tresolvedUrl: { ...this.container.resolvedUrl },\n\t\t\t\t\tversion: request.headers?.[LoaderHeader.version] ?? undefined,\n\t\t\t\t\tloadMode: request.headers?.[LoaderHeader.loadMode],\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcanReconnect: request.headers?.[LoaderHeader.reconnect],\n\t\t\t\t\tclientDetailsOverride: request.headers?.[LoaderHeader.clientDetails],\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn container;\n\t\t}\n\n\t\tif (this.loader === undefined) {\n\t\t\tthrow new Error(\"Cannot resolve external containers\");\n\t\t}\n\t\treturn this.loader.resolve(request);\n\t}\n}\n\n/**\n * @alpha\n */\nexport interface ILoaderOptions extends ILoaderOptions1 {\n\tsummarizeProtocolTree?: boolean;\n}\n\n/**\n * @deprecated IFluidModuleWithDetails interface is moved to\n * {@link @fluidframework/container-definitions#IFluidModuleWithDetails}\n * to have all the code loading modules in one package. #8193\n * Encapsulates a module entry point with corresponding code details.\n * @alpha\n */\nexport interface IFluidModuleWithDetails {\n\t/** Fluid code module that implements the runtime factory needed to instantiate the container runtime. */\n\tmodule: IFluidModule;\n\t/**\n\t * Code details associated with the module. Represents a document schema this module supports.\n\t * If the code loader implements the {@link @fluidframework/core-interfaces#IFluidCodeDetailsComparer} interface,\n\t * it'll be called to determine whether the module code details satisfy the new code proposal in the quorum.\n\t */\n\tdetails: IFluidCodeDetails;\n}\n\n/**\n * @deprecated ICodeDetailsLoader interface is moved to {@link @fluidframework/container-definition#ICodeDetailsLoader}\n * to have code loading modules in one package. #8193\n * Fluid code loader resolves a code module matching the document schema, i.e. code details, such as\n * a package name and package version range.\n * @alpha\n */\nexport interface ICodeDetailsLoader extends Partial<IProvideFluidCodeDetailsComparer> {\n\t/**\n\t * Load the code module (package) that is capable to interact with the document.\n\t *\n\t * @param source - Code proposal that articulates the current schema the document is written in.\n\t * @returns Code module entry point along with the code details associated with it.\n\t */\n\tload(source: IFluidCodeDetails): Promise<IFluidModuleWithDetails>;\n}\n\n/**\n * Services and properties necessary for creating a loader\n * @alpha\n */\nexport interface ILoaderProps {\n\t/**\n\t * The url resolver used by the loader for resolving external urls\n\t * into Fluid urls such that the container specified by the\n\t * external url can be loaded.\n\t */\n\treadonly urlResolver: IUrlResolver;\n\t/**\n\t * The document service factory take the Fluid url provided\n\t * by the resolved url and constructs all the necessary services\n\t * for communication with the container's server.\n\t */\n\treadonly documentServiceFactory: IDocumentServiceFactory;\n\t/**\n\t * The code loader handles loading the necessary code\n\t * for running a container once it is loaded.\n\t */\n\treadonly codeLoader: ICodeDetailsLoader;\n\n\t/**\n\t * A property bag of options used by various layers\n\t * to control features\n\t */\n\treadonly options?: ILoaderOptions;\n\n\t/**\n\t * Scope is provided to all container and is a set of shared\n\t * services for container's to integrate with their host environment.\n\t */\n\treadonly scope?: FluidObject;\n\n\t/**\n\t * The logger that all telemetry should be pushed to.\n\t */\n\treadonly logger?: ITelemetryBaseLogger;\n\n\t/**\n\t * Blobs storage for detached containers.\n\t */\n\treadonly detachedBlobStorage?: IDetachedBlobStorage;\n\n\t/**\n\t * The configuration provider which may be used to control features.\n\t */\n\treadonly configProvider?: IConfigProviderBase;\n\n\t/**\n\t * Optional property for allowing the container to use a custom\n\t * protocol implementation for handling the quorum and/or the audience.\n\t */\n\treadonly protocolHandlerBuilder?: ProtocolHandlerBuilder;\n}\n\n/**\n * Services and properties used by and exposed by the loader\n * @alpha\n */\nexport interface ILoaderServices {\n\t/**\n\t * The url resolver used by the loader for resolving external urls\n\t * into Fluid urls such that the container specified by the\n\t * external url can be loaded.\n\t */\n\treadonly urlResolver: IUrlResolver;\n\t/**\n\t * The document service factory take the Fluid url provided\n\t * by the resolved url and constructs all the necessary services\n\t * for communication with the container's server.\n\t */\n\treadonly documentServiceFactory: IDocumentServiceFactory;\n\t/**\n\t * The code loader handles loading the necessary code\n\t * for running a container once it is loaded.\n\t */\n\treadonly codeLoader: ICodeDetailsLoader;\n\n\t/**\n\t * A property bag of options used by various layers\n\t * to control features\n\t */\n\treadonly options: ILoaderOptions;\n\n\t/**\n\t * Scope is provided to all container and is a set of shared\n\t * services for container's to integrate with their host environment.\n\t */\n\treadonly scope: FluidObject;\n\n\t/**\n\t * The logger downstream consumers should construct their loggers from\n\t */\n\treadonly subLogger: ITelemetryLoggerExt;\n\n\t/**\n\t * Blobs storage for detached containers.\n\t */\n\treadonly detachedBlobStorage?: IDetachedBlobStorage;\n\n\t/**\n\t * Optional property for allowing the container to use a custom\n\t * protocol implementation for handling the quorum and/or the audience.\n\t */\n\treadonly protocolHandlerBuilder?: ProtocolHandlerBuilder;\n}\n\n/**\n * Subset of IDocumentStorageService which only supports createBlob() and readBlob(). This is used to support\n * blobs in detached containers.\n * @alpha\n */\nexport type IDetachedBlobStorage = Pick<IDocumentStorageService, \"createBlob\" | \"readBlob\"> & {\n\tsize: number;\n\t/**\n\t * Return an array of all blob IDs present in storage\n\t */\n\tgetBlobIds(): string[];\n};\n\n/**\n * Manages Fluid resource loading\n * @alpha\n */\nexport class Loader implements IHostLoader {\n\tpublic readonly services: ILoaderServices;\n\tprivate readonly mc: MonitoringContext;\n\n\tconstructor(loaderProps: ILoaderProps) {\n\t\tconst {\n\t\t\turlResolver,\n\t\t\tdocumentServiceFactory,\n\t\t\tcodeLoader,\n\t\t\toptions,\n\t\t\tscope,\n\t\t\tlogger,\n\t\t\tdetachedBlobStorage,\n\t\t\tconfigProvider,\n\t\t\tprotocolHandlerBuilder,\n\t\t} = loaderProps;\n\n\t\tconst telemetryProps = {\n\t\t\tloaderId: uuid(),\n\t\t\tloaderVersion: pkgVersion,\n\t\t};\n\n\t\tconst subMc = mixinMonitoringContext(\n\t\t\tDebugLogger.mixinDebugLogger(\"fluid:telemetry\", logger, {\n\t\t\t\tall: telemetryProps,\n\t\t\t}),\n\t\t\tsessionStorageConfigProvider.value,\n\t\t\tconfigProvider,\n\t\t);\n\n\t\tthis.services = {\n\t\t\turlResolver,\n\t\t\tdocumentServiceFactory,\n\t\t\tcodeLoader,\n\t\t\toptions: options ?? {},\n\t\t\tscope:\n\t\t\t\toptions?.provideScopeLoader !== false ? { ...scope, ILoader: this } : { ...scope },\n\t\t\tdetachedBlobStorage,\n\t\t\tprotocolHandlerBuilder,\n\t\t\tsubLogger: subMc.logger,\n\t\t};\n\t\tthis.mc = createChildMonitoringContext({\n\t\t\tlogger: this.services.subLogger,\n\t\t\tnamespace: \"Loader\",\n\t\t});\n\t}\n\n\tpublic async createDetachedContainer(\n\t\tcodeDetails: IFluidCodeDetails,\n\t\tcreateDetachedProps?: {\n\t\t\tcanReconnect?: boolean;\n\t\t\tclientDetailsOverride?: IClientDetails;\n\t\t},\n\t): Promise<IContainer> {\n\t\treturn Container.createDetached(\n\t\t\t{\n\t\t\t\t...createDetachedProps,\n\t\t\t\t...this.services,\n\t\t\t},\n\t\t\tcodeDetails,\n\t\t);\n\t}\n\n\tpublic async rehydrateDetachedContainerFromSnapshot(\n\t\tsnapshot: string,\n\t\tcreateDetachedProps?: {\n\t\t\tcanReconnect?: boolean;\n\t\t\tclientDetailsOverride?: IClientDetails;\n\t\t},\n\t): Promise<IContainer> {\n\t\treturn Container.rehydrateDetachedFromSnapshot(\n\t\t\t{\n\t\t\t\t...createDetachedProps,\n\t\t\t\t...this.services,\n\t\t\t},\n\t\t\tsnapshot,\n\t\t);\n\t}\n\n\tpublic async resolve(request: IRequest, pendingLocalState?: string): Promise<IContainer> {\n\t\tconst eventName = pendingLocalState === undefined ? \"Resolve\" : \"ResolveWithPendingState\";\n\t\treturn PerformanceEvent.timedExecAsync(this.mc.logger, { eventName }, async () => {\n\t\t\tconst resolved = await this.resolveCore(\n\t\t\t\trequest,\n\t\t\t\tpendingLocalState !== undefined ? JSON.parse(pendingLocalState) : undefined,\n\t\t\t);\n\t\t\treturn resolved.container;\n\t\t});\n\t}\n\n\tprivate async resolveCore(\n\t\trequest: IRequest,\n\t\tpendingLocalState?: IPendingContainerState,\n\t): Promise<{ container: Container; parsed: IParsedUrl }> {\n\t\tconst resolvedAsFluid = await this.services.urlResolver.resolve(request);\n\t\tensureResolvedUrlDefined(resolvedAsFluid);\n\n\t\t// Parse URL into data stores\n\t\tconst parsed = tryParseCompatibleResolvedUrl(resolvedAsFluid.url);\n\t\tif (parsed === undefined) {\n\t\t\tthrow new Error(`Invalid URL ${resolvedAsFluid.url}`);\n\t\t}\n\n\t\tif (pendingLocalState !== undefined) {\n\t\t\tconst parsedPendingUrl = tryParseCompatibleResolvedUrl(pendingLocalState.url);\n\t\t\tif (\n\t\t\t\tparsedPendingUrl?.id !== parsed.id ||\n\t\t\t\tparsedPendingUrl?.path.replace(/\\/$/, \"\") !== parsed.path.replace(/\\/$/, \"\")\n\t\t\t) {\n\t\t\t\tconst message = `URL ${resolvedAsFluid.url} does not match pending state URL ${pendingLocalState.url}`;\n\t\t\t\tthrow new Error(message);\n\t\t\t}\n\t\t}\n\n\t\trequest.headers ??= {};\n\t\t// If set in both query string and headers, use query string. Also write the value from the query string into the header either way.\n\t\trequest.headers[LoaderHeader.version] =\n\t\t\tparsed.version ?? request.headers[LoaderHeader.version];\n\t\tconst fromSequenceNumber = request.headers[LoaderHeader.sequenceNumber] as\n\t\t\t| number\n\t\t\t| undefined;\n\t\tconst opsBeforeReturn = request.headers[LoaderHeader.loadMode]?.opsBeforeReturn as\n\t\t\t| string\n\t\t\t| undefined;\n\n\t\tif (\n\t\t\topsBeforeReturn === \"sequenceNumber\" &&\n\t\t\t(fromSequenceNumber === undefined || fromSequenceNumber < 0)\n\t\t) {\n\t\t\t// If opsBeforeReturn is set to \"sequenceNumber\", then fromSequenceNumber should be set to a non-negative integer.\n\t\t\tthrow new UsageError(\"sequenceNumber must be set to a non-negative integer\");\n\t\t} else if (opsBeforeReturn !== \"sequenceNumber\" && fromSequenceNumber !== undefined) {\n\t\t\t// If opsBeforeReturn is not set to \"sequenceNumber\", then fromSequenceNumber should be undefined (default value).\n\t\t\t// In this case, we should throw an error since opsBeforeReturn is not explicitly set to \"sequenceNumber\".\n\t\t\tthrow new UsageError('opsBeforeReturn must be set to \"sequenceNumber\"');\n\t\t}\n\n\t\treturn {\n\t\t\tcontainer: await this.loadContainer(request, resolvedAsFluid, pendingLocalState),\n\t\t\tparsed,\n\t\t};\n\t}\n\n\tprivate async loadContainer(\n\t\trequest: IRequest,\n\t\tresolvedUrl: IResolvedUrl,\n\t\tpendingLocalState?: IPendingContainerState,\n\t): Promise<Container> {\n\t\treturn Container.load(\n\t\t\t{\n\t\t\t\tresolvedUrl,\n\t\t\t\tversion: request.headers?.[LoaderHeader.version] ?? undefined,\n\t\t\t\tloadMode: request.headers?.[LoaderHeader.loadMode],\n\t\t\t\tpendingLocalState,\n\t\t\t\tloadToSequenceNumber: request.headers?.[LoaderHeader.sequenceNumber],\n\t\t\t},\n\t\t\t{\n\t\t\t\tcanReconnect: request.headers?.[LoaderHeader.reconnect],\n\t\t\t\tclientDetailsOverride: request.headers?.[LoaderHeader.clientDetails],\n\t\t\t\t...this.services,\n\t\t\t},\n\t\t);\n\t}\n}\n"]}
@@ -0,0 +1,6 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export { isLocationRedirectionError, resolveWithLocationRedirectionHandling, } from "./resolveWithLocationRedirection.mjs";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/location-redirection-utilities/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EACN,0BAA0B,EAC1B,sCAAsC,GACtC"}
@@ -0,0 +1,6 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export { isLocationRedirectionError, resolveWithLocationRedirectionHandling, } from "./resolveWithLocationRedirection.mjs";
6
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/location-redirection-utilities/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EACN,0BAA0B,EAC1B,sCAAsC,GACtC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\tisLocationRedirectionError,\n\tresolveWithLocationRedirectionHandling,\n} from \"./resolveWithLocationRedirection\";\n"]}
@@ -0,0 +1,24 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { ITelemetryBaseLogger, IRequest } from "@fluidframework/core-interfaces";
6
+ import { ILocationRedirectionError, IUrlResolver } from "@fluidframework/driver-definitions";
7
+ /**
8
+ * Checks if the error is location redirection error.
9
+ * @param error - error whose type is to be determined.
10
+ * @returns `true` is the error is location redirection error, otherwise `false`.
11
+ * @internal
12
+ */
13
+ export declare function isLocationRedirectionError(error: any): error is ILocationRedirectionError;
14
+ /**
15
+ * Handles location redirection while fulfilling the loader request.
16
+ * @param api - Callback in which user can wrap the loader.resolve or loader.request call.
17
+ * @param request - request to be resolved.
18
+ * @param urlResolver - resolver used to resolve the url.
19
+ * @param logger - logger to send events.
20
+ * @returns Response from the API call.
21
+ * @alpha
22
+ */
23
+ export declare function resolveWithLocationRedirectionHandling<T>(api: (request: IRequest) => Promise<T>, request: IRequest, urlResolver: IUrlResolver, logger?: ITelemetryBaseLogger): Promise<T>;
24
+ //# sourceMappingURL=resolveWithLocationRedirection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveWithLocationRedirection.d.ts","sourceRoot":"","sources":["../../src/location-redirection-utilities/resolveWithLocationRedirection.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,iCAAiC;OACzE,EAEN,yBAAyB,EACzB,YAAY,EACZ,MAAM,oCAAoC;AAG3C;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,yBAAyB,CAMzF;AAED;;;;;;;;GAQG;AACH,wBAAsB,sCAAsC,CAAC,CAAC,EAC7D,GAAG,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,EACtC,OAAO,EAAE,QAAQ,EACjB,WAAW,EAAE,YAAY,EACzB,MAAM,CAAC,EAAE,oBAAoB,GAC3B,OAAO,CAAC,CAAC,CAAC,CAmBZ"}
@@ -0,0 +1,48 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { DriverErrorTypes, } from "@fluidframework/driver-definitions";
6
+ import { createChildLogger } from "@fluidframework/telemetry-utils";
7
+ /**
8
+ * Checks if the error is location redirection error.
9
+ * @param error - error whose type is to be determined.
10
+ * @returns `true` is the error is location redirection error, otherwise `false`.
11
+ * @internal
12
+ */
13
+ export function isLocationRedirectionError(error) {
14
+ return (typeof error === "object" &&
15
+ error !== null &&
16
+ error.errorType === DriverErrorTypes.locationRedirection);
17
+ }
18
+ /**
19
+ * Handles location redirection while fulfilling the loader request.
20
+ * @param api - Callback in which user can wrap the loader.resolve or loader.request call.
21
+ * @param request - request to be resolved.
22
+ * @param urlResolver - resolver used to resolve the url.
23
+ * @param logger - logger to send events.
24
+ * @returns Response from the API call.
25
+ * @alpha
26
+ */
27
+ export async function resolveWithLocationRedirectionHandling(api, request, urlResolver, logger) {
28
+ let req = request;
29
+ const childLogger = createChildLogger({ logger, namespace: "LocationRedirection" });
30
+ for (;;) {
31
+ try {
32
+ return await api(req);
33
+ }
34
+ catch (error) {
35
+ if (!isLocationRedirectionError(error)) {
36
+ throw error;
37
+ }
38
+ childLogger.sendTelemetryEvent({ eventName: "LocationRedirectionError" });
39
+ const resolvedUrl = error.redirectUrl;
40
+ // Generate the new request with new location details from the resolved url. For datastore/relative path,
41
+ // we don't need to pass "/" as host could have asked for a specific data store. So driver need to
42
+ // extract it from the resolved url.
43
+ const absoluteUrl = await urlResolver.getAbsoluteUrl(resolvedUrl, "", undefined);
44
+ req = { url: absoluteUrl, headers: req.headers };
45
+ }
46
+ }
47
+ }
48
+ //# sourceMappingURL=resolveWithLocationRedirection.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveWithLocationRedirection.mjs","sourceRoot":"","sources":["../../src/location-redirection-utilities/resolveWithLocationRedirection.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAGI,EACN,gBAAgB,GAGhB,MAAM,oCAAoC;OACpC,EAAE,iBAAiB,EAAE,MAAM,iCAAiC;AAEnE;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CAAC,KAAU;IACpD,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,KAAK,CAAC,SAAS,KAAK,gBAAgB,CAAC,mBAAmB,CACxD,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,sCAAsC,CAC3D,GAAsC,EACtC,OAAiB,EACjB,WAAyB,EACzB,MAA6B;IAE7B,IAAI,GAAG,GAAa,OAAO,CAAC;IAC5B,MAAM,WAAW,GAAG,iBAAiB,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,qBAAqB,EAAE,CAAC,CAAC;IACpF,SAAS;QACR,IAAI;YACH,OAAO,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC;SACtB;QAAC,OAAO,KAAU,EAAE;YACpB,IAAI,CAAC,0BAA0B,CAAC,KAAK,CAAC,EAAE;gBACvC,MAAM,KAAK,CAAC;aACZ;YACD,WAAW,CAAC,kBAAkB,CAAC,EAAE,SAAS,EAAE,0BAA0B,EAAE,CAAC,CAAC;YAC1E,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC;YACtC,yGAAyG;YACzG,kGAAkG;YAClG,oCAAoC;YACpC,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,cAAc,CAAC,WAAW,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;YACjF,GAAG,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;SACjD;KACD;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseLogger, IRequest } from \"@fluidframework/core-interfaces\";\nimport {\n\tDriverErrorTypes,\n\tILocationRedirectionError,\n\tIUrlResolver,\n} from \"@fluidframework/driver-definitions\";\nimport { createChildLogger } from \"@fluidframework/telemetry-utils\";\n\n/**\n * Checks if the error is location redirection error.\n * @param error - error whose type is to be determined.\n * @returns `true` is the error is location redirection error, otherwise `false`.\n * @internal\n */\nexport function isLocationRedirectionError(error: any): error is ILocationRedirectionError {\n\treturn (\n\t\ttypeof error === \"object\" &&\n\t\terror !== null &&\n\t\terror.errorType === DriverErrorTypes.locationRedirection\n\t);\n}\n\n/**\n * Handles location redirection while fulfilling the loader request.\n * @param api - Callback in which user can wrap the loader.resolve or loader.request call.\n * @param request - request to be resolved.\n * @param urlResolver - resolver used to resolve the url.\n * @param logger - logger to send events.\n * @returns Response from the API call.\n * @alpha\n */\nexport async function resolveWithLocationRedirectionHandling<T>(\n\tapi: (request: IRequest) => Promise<T>,\n\trequest: IRequest,\n\turlResolver: IUrlResolver,\n\tlogger?: ITelemetryBaseLogger,\n): Promise<T> {\n\tlet req: IRequest = request;\n\tconst childLogger = createChildLogger({ logger, namespace: \"LocationRedirection\" });\n\tfor (;;) {\n\t\ttry {\n\t\t\treturn await api(req);\n\t\t} catch (error: any) {\n\t\t\tif (!isLocationRedirectionError(error)) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tchildLogger.sendTelemetryEvent({ eventName: \"LocationRedirectionError\" });\n\t\t\tconst resolvedUrl = error.redirectUrl;\n\t\t\t// Generate the new request with new location details from the resolved url. For datastore/relative path,\n\t\t\t// we don't need to pass \"/\" as host could have asked for a specific data store. So driver need to\n\t\t\t// extract it from the resolved url.\n\t\t\tconst absoluteUrl = await urlResolver.getAbsoluteUrl(resolvedUrl, \"\", undefined);\n\t\t\treq = { url: absoluteUrl, headers: req.headers };\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,23 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { TypedEventEmitter } from "@fluid-internal/client-utils";
6
+ import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
7
+ import { IEvent } from "@fluidframework/core-interfaces";
8
+ export interface INoopSenderEvents extends IEvent {
9
+ (event: "wantsNoop", listener: () => void): any;
10
+ }
11
+ export declare class NoopHeuristic extends TypedEventEmitter<INoopSenderEvents> {
12
+ private readonly NoopCountFrequency;
13
+ private opsProcessedSinceOpSent;
14
+ private readonly timer;
15
+ constructor(NoopTimeFrequency?: number, NoopCountFrequency?: number);
16
+ /**
17
+ * Schedules as ack to the server to update the reference sequence number
18
+ */
19
+ notifyMessageProcessed(message: ISequencedDocumentMessage): void;
20
+ notifyDisconnect(): void;
21
+ notifyMessageSent(): void;
22
+ }
23
+ //# sourceMappingURL=noopHeuristic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noopHeuristic.d.ts","sourceRoot":"","sources":["../src/noopHeuristic.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,iBAAiB,EAAE,MAAM,8BAA8B;OAEzD,EAAE,yBAAyB,EAAE,MAAM,sCAAsC;OAEzE,EAAE,MAAM,EAAE,MAAM,iCAAiC;AAKxD,MAAM,WAAW,iBAAkB,SAAQ,MAAM;IAChD,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;CAC3C;AAqBD,qBAAa,aAAc,SAAQ,iBAAiB,CAAC,iBAAiB,CAAC;IAMrE,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IALpC,OAAO,CAAC,uBAAuB,CAAK;IACpC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAoB;gBAGzC,iBAAiB,GAAE,MAAiC,EACnC,kBAAkB,GAAE,MAAkC;IAcxE;;OAEG;IACI,sBAAsB,CAAC,OAAO,EAAE,yBAAyB,GAAG,IAAI;IAqChE,gBAAgB,IAAI,IAAI;IAKxB,iBAAiB,IAAI,IAAI;CAIhC"}
@@ -2,8 +2,8 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { assert, Timer } from "@fluidframework/common-utils";
6
- import { MessageType } from "@fluidframework/protocol-definitions";
5
+ import { TypedEventEmitter } from "@fluid-internal/client-utils";
6
+ import { assert, Timer } from "@fluidframework/core-utils";
7
7
  import { isRuntimeMessage } from "@fluidframework/driver-utils";
8
8
  const defaultNoopTimeFrequency = 2000;
9
9
  const defaultNoopCountFrequency = 50;
@@ -26,17 +26,17 @@ const defaultNoopCountFrequency = 50;
26
26
  // server timeout of 2000ms should be reconsidered to be increased.
27
27
  // 2. If there are more than 50 ops received without sending any ops, send noop to keep collab window small.
28
28
  // Note that system ops (including noops themselves) are excluded, so it's 1 noop per 50 real ops.
29
- export class CollabWindowTracker {
30
- constructor(submit, NoopTimeFrequency = defaultNoopTimeFrequency, NoopCountFrequency = defaultNoopCountFrequency) {
31
- this.submit = submit;
29
+ export class NoopHeuristic extends TypedEventEmitter {
30
+ constructor(NoopTimeFrequency = defaultNoopTimeFrequency, NoopCountFrequency = defaultNoopCountFrequency) {
31
+ super();
32
32
  this.NoopCountFrequency = NoopCountFrequency;
33
- this.opsCountSinceNoop = 0;
33
+ this.opsProcessedSinceOpSent = 0;
34
34
  if (NoopTimeFrequency !== Infinity) {
35
35
  this.timer = new Timer(NoopTimeFrequency, () => {
36
- // Can get here due to this.stopSequenceNumberUpdate() not resetting timer.
37
- // Also timer callback can fire even after timer cancellation if it was queued before cancellation.
38
- if (this.opsCountSinceNoop !== 0) {
39
- this.submitNoop(false /* immediate */);
36
+ // We allow the timer to expire even if an op is sent or we disconnect.
37
+ // This condition is to guard against trying to send a noop anyway in that case.
38
+ if (this.opsProcessedSinceOpSent !== 0) {
39
+ this.emit("wantsNoop");
40
40
  }
41
41
  });
42
42
  }
@@ -44,13 +44,7 @@ export class CollabWindowTracker {
44
44
  /**
45
45
  * Schedules as ack to the server to update the reference sequence number
46
46
  */
47
- scheduleSequenceNumberUpdate(message, immediateNoOp) {
48
- // While processing a message, an immediate no-op can be requested.
49
- // i.e. to expedite approve or commit phase of quorum.
50
- if (immediateNoOp) {
51
- this.submitNoop(true /* immediate */);
52
- return;
53
- }
47
+ notifyMessageProcessed(message) {
54
48
  // We don't acknowledge no-ops to avoid acknowledgement cycles (i.e. ack the MSN
55
49
  // update, which updates the MSN, then ack the update, etc...).
56
50
  // Intent here is for runtime (and DDSes) not to keep too much tracking state / memory
@@ -58,31 +52,35 @@ export class CollabWindowTracker {
58
52
  if (!isRuntimeMessage(message)) {
59
53
  return;
60
54
  }
61
- this.opsCountSinceNoop++;
62
- if (this.opsCountSinceNoop >= this.NoopCountFrequency) {
63
- this.submitNoop(false /* immediate */);
64
- return;
55
+ this.opsProcessedSinceOpSent++;
56
+ if (this.opsProcessedSinceOpSent === this.NoopCountFrequency) {
57
+ // Wait to send a noop if we are still synchronously processing ops. This guards against two things:
58
+ // 1. If we're processing many ops, we may pass the frequency threshold many times. We only need to send one noop at the very end in this case.
59
+ // 2. We may send another (non-noop) op in response to processing those ops, e.g. an Accept op.
60
+ queueMicrotask(() => {
61
+ if (this.opsProcessedSinceOpSent >= this.NoopCountFrequency) {
62
+ this.emit("wantsNoop");
63
+ assert(this.opsProcessedSinceOpSent === 0, 0x243 /* "Expected a noop to be synchronously sent" */);
64
+ }
65
+ return;
66
+ });
65
67
  }
66
68
  if (this.timer !== undefined) {
67
- if (this.opsCountSinceNoop === 1) {
69
+ // Start the timer if we newly have ops that want a noop.
70
+ // If the timer was already running (e.g. we surpassed the op count and sent a noop) this will reset it to its full duration.
71
+ if (this.opsProcessedSinceOpSent === 1) {
68
72
  this.timer.restart();
69
73
  }
70
74
  assert(this.timer.hasTimer, 0x242 /* "has timer" */);
71
75
  }
72
76
  }
73
- submitNoop(immediate) {
74
- // Anything other than null is immediate noop
75
- this.submit(MessageType.NoOp, immediate ? "" : null);
76
- assert(this.opsCountSinceNoop === 0, 0x243 /* "stopSequenceNumberUpdate should be called as result of sending any op!" */);
77
+ notifyDisconnect() {
78
+ // No need to noop for any ops processed prior to disconnect - we are already removed from MSN calculation.
79
+ this.opsProcessedSinceOpSent = 0;
77
80
  }
78
- stopSequenceNumberUpdate() {
79
- this.opsCountSinceNoop = 0;
80
- // Ideally, we cancel timer here. But that will result in too often set/reset cycle if this client
81
- // keeps sending ops. In most cases it's actually better to let it expire (at most - 4 times per second)
82
- // for nothing, then have a ton of set/reset cycles.
83
- // Note that Timer.restart() is smart and will not change timer expiration if we keep extending timer
84
- // expiration - it will restart the timer instead when it fires with adjusted expiration.
85
- // this.timer.clear();
81
+ notifyMessageSent() {
82
+ // Sending any message is as good as a noop for updating MSN.
83
+ this.opsProcessedSinceOpSent = 0;
86
84
  }
87
85
  }
88
- //# sourceMappingURL=collabWindowTracker.js.map
86
+ //# sourceMappingURL=noopHeuristic.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noopHeuristic.mjs","sourceRoot":"","sources":["../src/noopHeuristic.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,iBAAiB,EAAE,MAAM,8BAA8B;OACzD,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,4BAA4B;OAEnD,EAAE,gBAAgB,EAAE,MAAM,8BAA8B;AAG/D,MAAM,wBAAwB,GAAG,IAAI,CAAC;AACtC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAMrC,6FAA6F;AAC7F,4GAA4G;AAC5G,yGAAyG;AACzG,2CAA2C;AAC3C,oHAAoH;AACpH,2FAA2F;AAC3F,kHAAkH;AAClH,+CAA+C;AAC/C,gHAAgH;AAChH,yFAAyF;AACzF,qHAAqH;AACrH,oDAAoD;A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yDAAyD;YACzD,6HAA6H;YAC7H,IAAI,IAAI,CAAC,uBAAuB,KAAK,CAAC,EAAE;gBACvC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;aACrB;YAED,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;SACrD;IACF,CAAC;IAEM,gBAAgB;QACtB,2GAA2G;QAC3G,IAAI,CAAC,uBAAuB,GAAG,CAAC,CAAC;IAClC,CAAC;IAEM,iBAAiB;QACvB,6DAA6D;QAC7D,IAAI,CAAC,uBAAuB,GAAG,CAAC,CAAC;IAClC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { assert, Timer } from \"@fluidframework/core-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { isRuntimeMessage } from \"@fluidframework/driver-utils\";\nimport { IEvent } from \"@fluidframework/core-interfaces\";\n\nconst defaultNoopTimeFrequency = 2000;\nconst defaultNoopCountFrequency = 50;\n\nexport interface INoopSenderEvents extends IEvent {\n\t(event: \"wantsNoop\", listener: () => void);\n}\n\n// Here are key considerations when deciding conditions for when to send non-immediate noops:\n// 1. Sending them too often results in increase in file size and bandwidth, as well as catch up performance\n// 2. Sending too infrequently ensures that collab window is large, and as result Sequence DDS would have\n// large catchUp blobs - see Issue #6364\n// 3. Similarly, processes that rely on \"core\" snapshot (and can't parse trailing ops, including above), like search\n// parser in SPO, will result in non-accurate results due to presence of catch up blobs.\n// 4. Ordering service used 250ms timeout to coalesce non-immediate noops. It was changed to 2000 ms to allow more\n// aggressive noop sending from client side.\n// 5. Number of ops sent by all clients is proportional to number of \"write\" clients (every client sends noops),\n// but number of sequenced noops is a function of time (one op per 2 seconds at most).\n// We should consider impact to both outbound traffic (might be huge, depends on number of clients) and file size.\n// Please also see Issue #5629 for more discussions.\n//\n// With that, the current algorithm is as follows:\n// 1. Sent noop 2000 ms of receiving an op if no ops were sent by this client within this timeframe.\n// This will ensure that MSN moves forward with reasonable speed. If that results in too many sequenced noops,\n// server timeout of 2000ms should be reconsidered to be increased.\n// 2. If there are more than 50 ops received without sending any ops, send noop to keep collab window small.\n// Note that system ops (including noops themselves) are excluded, so it's 1 noop per 50 real ops.\nexport class NoopHeuristic extends TypedEventEmitter<INoopSenderEvents> {\n\tprivate opsProcessedSinceOpSent = 0;\n\tprivate readonly timer: Timer | undefined;\n\n\tconstructor(\n\t\tNoopTimeFrequency: number = defaultNoopTimeFrequency,\n\t\tprivate readonly NoopCountFrequency: number = defaultNoopCountFrequency,\n\t) {\n\t\tsuper();\n\t\tif (NoopTimeFrequency !== Infinity) {\n\t\t\tthis.timer = new Timer(NoopTimeFrequency, () => {\n\t\t\t\t// We allow the timer to expire even if an op is sent or we disconnect.\n\t\t\t\t// This condition is to guard against trying to send a noop anyway in that case.\n\t\t\t\tif (this.opsProcessedSinceOpSent !== 0) {\n\t\t\t\t\tthis.emit(\"wantsNoop\");\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Schedules as ack to the server to update the reference sequence number\n\t */\n\tpublic notifyMessageProcessed(message: ISequencedDocumentMessage): void {\n\t\t// We don't acknowledge no-ops to avoid acknowledgement cycles (i.e. ack the MSN\n\t\t// update, which updates the MSN, then ack the update, etc...).\n\t\t// Intent here is for runtime (and DDSes) not to keep too much tracking state / memory\n\t\t// due to runtime ops from other clients.\n\t\tif (!isRuntimeMessage(message)) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.opsProcessedSinceOpSent++;\n\t\tif (this.opsProcessedSinceOpSent === this.NoopCountFrequency) {\n\t\t\t// Wait to send a noop if we are still synchronously processing ops. This guards against two things:\n\t\t\t// 1. If we're processing many ops, we may pass the frequency threshold many times. We only need to send one noop at the very end in this case.\n\t\t\t// 2. We may send another (non-noop) op in response to processing those ops, e.g. an Accept op.\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tif (this.opsProcessedSinceOpSent >= this.NoopCountFrequency) {\n\t\t\t\t\tthis.emit(\"wantsNoop\");\n\t\t\t\t\tassert(\n\t\t\t\t\t\tthis.opsProcessedSinceOpSent === 0,\n\t\t\t\t\t\t0x243 /* \"Expected a noop to be synchronously sent\" */,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t});\n\t\t}\n\n\t\tif (this.timer !== undefined) {\n\t\t\t// Start the timer if we newly have ops that want a noop.\n\t\t\t// If the timer was already running (e.g. we surpassed the op count and sent a noop) this will reset it to its full duration.\n\t\t\tif (this.opsProcessedSinceOpSent === 1) {\n\t\t\t\tthis.timer.restart();\n\t\t\t}\n\n\t\t\tassert(this.timer.hasTimer, 0x242 /* \"has timer\" */);\n\t\t}\n\t}\n\n\tpublic notifyDisconnect(): void {\n\t\t// No need to noop for any ops processed prior to disconnect - we are already removed from MSN calculation.\n\t\tthis.opsProcessedSinceOpSent = 0;\n\t}\n\n\tpublic notifyMessageSent(): void {\n\t\t// Sending any message is as good as a noop for updating MSN.\n\t\tthis.opsProcessedSinceOpSent = 0;\n\t}\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/container-loader";
8
- export declare const pkgVersion = "1.4.0-121020";
8
+ export declare const pkgVersion = "2.0.0-dev-rc.1.0.0.224419";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,qCAAqC,CAAC;AAC1D,eAAO,MAAM,UAAU,iBAAiB,CAAC"}
1
+ {"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,qCAAqC,CAAC;AAC1D,eAAO,MAAM,UAAU,8BAA8B,CAAC"}
@@ -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/container-loader";
8
- export const pkgVersion = "1.4.0-121020";
9
- //# sourceMappingURL=packageVersion.js.map
8
+ export const pkgVersion = "2.0.0-dev-rc.1.0.0.224419";
9
+ //# sourceMappingURL=packageVersion.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packageVersion.mjs","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,kCAAkC,CAAC;AAC1D,MAAM,CAAC,MAAM,UAAU,GAAG,2BAA2B,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/container-loader\";\nexport const pkgVersion = \"2.0.0-dev-rc.1.0.0.224419\";\n"]}
@@ -0,0 +1,38 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IAudienceOwner } from "@fluidframework/container-definitions";
6
+ import { IProtocolHandler as IBaseProtocolHandler, IQuorumSnapshot, ProtocolOpHandler } from "@fluidframework/protocol-base";
7
+ import { IDocumentAttributes, IProcessMessageResult, ISequencedDocumentMessage, ISignalMessage } from "@fluidframework/protocol-definitions";
8
+ export declare enum SignalType {
9
+ ClientJoin = "join",
10
+ ClientLeave = "leave",
11
+ Clear = "clear"
12
+ }
13
+ /**
14
+ * Function to be used for creating a protocol handler.
15
+ * @alpha
16
+ */
17
+ export type ProtocolHandlerBuilder = (attributes: IDocumentAttributes, snapshot: IQuorumSnapshot, sendProposal: (key: string, value: any) => number) => IProtocolHandler;
18
+ /**
19
+ * @alpha
20
+ */
21
+ export interface IProtocolHandler extends IBaseProtocolHandler {
22
+ readonly audience: IAudienceOwner;
23
+ processSignal(message: ISignalMessage): any;
24
+ }
25
+ export declare class ProtocolHandler extends ProtocolOpHandler implements IProtocolHandler {
26
+ readonly audience: IAudienceOwner;
27
+ private readonly shouldClientHaveLeft;
28
+ constructor(attributes: IDocumentAttributes, quorumSnapshot: IQuorumSnapshot, sendProposal: (key: string, value: any) => number, audience: IAudienceOwner, shouldClientHaveLeft: (clientId: string) => boolean);
29
+ processMessage(message: ISequencedDocumentMessage, local: boolean): IProcessMessageResult;
30
+ processSignal(message: ISignalMessage): void;
31
+ }
32
+ /**
33
+ * Function to check whether the protocol handler should process the Signal.
34
+ * The protocol handler should strictly handle only ClientJoin, ClientLeave
35
+ * and Clear signal types.
36
+ */
37
+ export declare function protocolHandlerShouldProcessSignal(message: ISignalMessage): boolean;
38
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,cAAc,EAAE,MAAM,uCAAuC;OAE/D,EACN,gBAAgB,IAAI,oBAAoB,EACxC,eAAe,EACf,iBAAiB,EACjB,MAAM,+BAA+B;OAC/B,EACN,mBAAmB,EACnB,qBAAqB,EACrB,yBAAyB,EAEzB,cAAc,EAEd,MAAM,sCAAsC;AAG7C,oBAAY,UAAU;IACrB,UAAU,SAAS;IACnB,WAAW,UAAU;IACrB,KAAK,UAAU;CACf;AAED;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,CACpC,UAAU,EAAE,mBAAmB,EAC/B,QAAQ,EAAE,eAAe,EACzB,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,MAAM,KAC7C,gBAAgB,CAAC;AAEtB;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,oBAAoB;IAC7D,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,aAAa,CAAC,OAAO,EAAE,cAAc,OAAE;CACvC;AAED,qBAAa,eAAgB,SAAQ,iBAAkB,YAAW,gBAAgB;aAKhE,QAAQ,EAAE,cAAc;IACxC,OAAO,CAAC,QAAQ,CAAC,oBAAoB;gBAJrC,UAAU,EAAE,mBAAmB,EAC/B,cAAc,EAAE,eAAe,EAC/B,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,MAAM,EACjC,QAAQ,EAAE,cAAc,EACvB,oBAAoB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO;IAqB9D,cAAc,CACpB,OAAO,EAAE,yBAAyB,EAClC,KAAK,EAAE,OAAO,GACZ,qBAAqB;IAuBjB,aAAa,CAAC,OAAO,EAAE,cAAc;CAgC5C;AAED;;;;GAIG;AACH,wBAAgB,kCAAkC,CAAC,OAAO,EAAE,cAAc,WAWzE"}
@@ -0,0 +1,94 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { canBeCoalescedByService } from "@fluidframework/driver-utils";
6
+ import { ProtocolOpHandler, } from "@fluidframework/protocol-base";
7
+ import { MessageType, } from "@fluidframework/protocol-definitions";
8
+ // ADO: #1986: Start using enum from protocol-base.
9
+ export var SignalType;
10
+ (function (SignalType) {
11
+ SignalType["ClientJoin"] = "join";
12
+ SignalType["ClientLeave"] = "leave";
13
+ SignalType["Clear"] = "clear";
14
+ })(SignalType || (SignalType = {}));
15
+ export class ProtocolHandler extends ProtocolOpHandler {
16
+ constructor(attributes, quorumSnapshot, sendProposal, audience, shouldClientHaveLeft) {
17
+ super(attributes.minimumSequenceNumber, attributes.sequenceNumber, quorumSnapshot.members, quorumSnapshot.proposals, quorumSnapshot.values, sendProposal);
18
+ this.audience = audience;
19
+ this.shouldClientHaveLeft = shouldClientHaveLeft;
20
+ // Join / leave signals are ignored for "write" clients in favor of join / leave ops
21
+ this.quorum.on("addMember", (clientId, details) => audience.addMember(clientId, details.client));
22
+ this.quorum.on("removeMember", (clientId) => audience.removeMember(clientId));
23
+ for (const [clientId, details] of this.quorum.getMembers()) {
24
+ this.audience.addMember(clientId, details.client);
25
+ }
26
+ }
27
+ processMessage(message, local) {
28
+ // Check and report if we're getting messages from a clientId that we previously
29
+ // flagged as shouldHaveLeft, or from a client that's not in the quorum but should be
30
+ if (message.clientId != null) {
31
+ const client = this.quorum.getMember(message.clientId);
32
+ if (client === undefined && message.type !== MessageType.ClientJoin) {
33
+ // pre-0.58 error message: messageClientIdMissingFromQuorum
34
+ throw new Error("Remote message's clientId is missing from the quorum");
35
+ }
36
+ // Here checking canBeCoalescedByService is used as an approximation of "is benign to process despite being unexpected".
37
+ // It's still not good to see these messages from unexpected clientIds, but since they don't harm the integrity of the
38
+ // document we don't need to blow up aggressively.
39
+ if (this.shouldClientHaveLeft(message.clientId) && !canBeCoalescedByService(message)) {
40
+ // pre-0.58 error message: messageClientIdShouldHaveLeft
41
+ throw new Error("Remote message's clientId already should have left");
42
+ }
43
+ }
44
+ return super.processMessage(message, local);
45
+ }
46
+ processSignal(message) {
47
+ const innerContent = message.content;
48
+ switch (innerContent.type) {
49
+ case SignalType.Clear: {
50
+ const members = this.audience.getMembers();
51
+ for (const [clientId, client] of members) {
52
+ if (client.mode === "read") {
53
+ this.audience.removeMember(clientId);
54
+ }
55
+ }
56
+ break;
57
+ }
58
+ case SignalType.ClientJoin: {
59
+ const newClient = innerContent.content;
60
+ // Ignore write clients - quorum will control such clients.
61
+ if (newClient.client.mode === "read") {
62
+ this.audience.addMember(newClient.clientId, newClient.client);
63
+ }
64
+ break;
65
+ }
66
+ case SignalType.ClientLeave: {
67
+ const leftClientId = innerContent.content;
68
+ // Ignore write clients - quorum will control such clients.
69
+ if (this.audience.getMember(leftClientId)?.mode === "read") {
70
+ this.audience.removeMember(leftClientId);
71
+ }
72
+ break;
73
+ }
74
+ default:
75
+ break;
76
+ }
77
+ }
78
+ }
79
+ /**
80
+ * Function to check whether the protocol handler should process the Signal.
81
+ * The protocol handler should strictly handle only ClientJoin, ClientLeave
82
+ * and Clear signal types.
83
+ */
84
+ export function protocolHandlerShouldProcessSignal(message) {
85
+ // Signal originates from server
86
+ if (message.clientId === null) {
87
+ const innerContent = message.content;
88
+ return (innerContent.type === SignalType.Clear ||
89
+ innerContent.type === SignalType.ClientJoin ||
90
+ innerContent.type === SignalType.ClientLeave);
91
+ }
92
+ return false;
93
+ }
94
+ //# sourceMappingURL=protocol.mjs.map