@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/src/contracts.ts CHANGED
@@ -3,31 +3,45 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
+ import { IErrorBase, ITelemetryProperties } from "@fluidframework/core-interfaces";
6
7
  import {
7
- ITelemetryProperties,
8
- } from "@fluidframework/common-definitions";
9
- import {
10
- IDeltaQueue,
11
- ReadOnlyInfo,
12
- IConnectionDetails,
13
- ICriticalContainerError,
14
- IFluidCodeDetails,
15
- isFluidPackage,
8
+ IConnectionDetails,
9
+ ICriticalContainerError,
10
+ IDeltaQueue,
11
+ IFluidCodeDetails,
12
+ isFluidPackage,
13
+ ReadOnlyInfo,
16
14
  } from "@fluidframework/container-definitions";
17
15
  import {
18
- ConnectionMode,
19
- IDocumentMessage,
20
- ISequencedDocumentMessage,
21
- IClientConfiguration,
22
- IClientDetails,
23
- ISignalMessage,
16
+ ConnectionMode,
17
+ IClientConfiguration,
18
+ IClientDetails,
19
+ IDocumentMessage,
20
+ ISequencedDocumentMessage,
21
+ ISignalClient,
22
+ ISignalMessage,
24
23
  } from "@fluidframework/protocol-definitions";
25
24
  import { IContainerPackageInfo } from "@fluidframework/driver-definitions";
26
25
 
27
26
  export enum ReconnectMode {
28
- Never = "Never",
29
- Disabled = "Disabled",
30
- Enabled = "Enabled",
27
+ Never = "Never",
28
+ Disabled = "Disabled",
29
+ Enabled = "Enabled",
30
+ }
31
+
32
+ export interface IConnectionStateChangeReason<T extends IErrorBase = IErrorBase> {
33
+ text: string;
34
+ error?: T;
35
+ }
36
+
37
+ /**
38
+ * Internal version of IConnectionDetails with props are only exposed internally
39
+ */
40
+ export interface IConnectionDetailsInternal extends IConnectionDetails {
41
+ mode: ConnectionMode;
42
+ version: string;
43
+ initialClients: ISignalClient[];
44
+ reason: IConnectionStateChangeReason;
31
45
  }
32
46
 
33
47
  /**
@@ -35,130 +49,152 @@ export enum ReconnectMode {
35
49
  * to relay service.
36
50
  */
37
51
  export interface IConnectionManager {
38
- readonly connected: boolean;
39
-
40
- readonly clientId: string | undefined;
41
-
42
- /** The queue of outbound delta messages */
43
- readonly outbound: IDeltaQueue<IDocumentMessage[]>;
44
-
45
- /** Details of client */
46
- readonly clientDetails: IClientDetails;
47
-
48
- /** Protocol version being used to communicate with the service */
49
- readonly version: string;
50
-
51
- /** Max message size allowed to the delta manager */
52
- readonly maxMessageSize: number;
53
-
54
- /** Service configuration provided by the service. */
55
- readonly serviceConfiguration: IClientConfiguration | undefined;
56
-
57
- readonly readOnlyInfo: ReadOnlyInfo;
58
-
59
- // Various connectivity propetries for telemetry describing type of current connection
60
- // Things like connection mode, service info, etc.
61
- // Called when connection state changes (connect / disconnect)
62
- readonly connectionProps: ITelemetryProperties;
63
-
64
- // Verbose information about connection logged to telemetry in case of issues with
65
- // maintaining healphy connection, including op gaps, not receiving join op in time, etc.
66
- // Contains details information, like sequence numbers at connection time, initial ops info, etc.
67
- readonly connectionVerboseProps: ITelemetryProperties;
68
-
69
- /**
70
- * Prepares message to be sent. Fills in clientSequenceNumber.
71
- * Called only when active connection is present.
72
- */
73
- prepareMessageToSend(message: Omit<IDocumentMessage, "clientSequenceNumber">): IDocumentMessage | undefined;
74
-
75
- /**
76
- * Called before incomming message is processed. Incomming messages can be comming from connection,
77
- * but also could come from storage.
78
- * This call allows connection manager to adjust knowledge about acked ops sent on previous connection.
79
- * Can be called at any time, including when there is no active connection.
80
- */
81
- beforeProcessingIncomingOp(message: ISequencedDocumentMessage): void;
82
-
83
- /**
84
- * Submits signal to relay service.
85
- * Called only when active connection is present.
86
- */
87
- submitSignal(content: any): void;
88
-
89
- /**
90
- * Submits messages to relay service.
91
- * Called only when active connection is present.
92
- */
93
- sendMessages(messages: IDocumentMessage[]): void;
94
-
95
- /**
96
- * Initiates connection to relay service (noop if already connected).
97
- */
98
- connect(connectionMode?: ConnectionMode): void;
99
-
100
- /**
101
- * Disposed connection manager
102
- */
103
- dispose(error?: ICriticalContainerError): void;
104
-
105
- get connectionMode(): ConnectionMode;
52
+ readonly connected: boolean;
53
+
54
+ readonly clientId: string | undefined;
55
+
56
+ /** The queue of outbound delta messages */
57
+ readonly outbound: IDeltaQueue<IDocumentMessage[]>;
58
+
59
+ /** Details of client */
60
+ readonly clientDetails: IClientDetails;
61
+
62
+ /** Protocol version being used to communicate with the service */
63
+ readonly version: string;
64
+
65
+ /** Max message size allowed to the delta manager */
66
+ readonly maxMessageSize: number;
67
+
68
+ /** Service configuration provided by the service. */
69
+ readonly serviceConfiguration: IClientConfiguration | undefined;
70
+
71
+ readonly readOnlyInfo: ReadOnlyInfo;
72
+
73
+ // Various connectivity properties for telemetry describing type of current connection
74
+ // Things like connection mode, service info, etc.
75
+ // Called when connection state changes (connect / disconnect)
76
+ readonly connectionProps: ITelemetryProperties;
77
+
78
+ // Verbose information about connection logged to telemetry in case of issues with
79
+ // maintaining healthy connection, including op gaps, not receiving join op in time, etc.
80
+ // Contains details information, like sequence numbers at connection time, initial ops info, etc.
81
+ readonly connectionVerboseProps: ITelemetryProperties;
82
+
83
+ /**
84
+ * Prepares message to be sent. Fills in clientSequenceNumber.
85
+ * Called only when active connection is present.
86
+ */
87
+ prepareMessageToSend(
88
+ message: Omit<IDocumentMessage, "clientSequenceNumber">,
89
+ ): IDocumentMessage | undefined;
90
+
91
+ /**
92
+ * Called before incoming message is processed. Incoming messages can be combing from connection,
93
+ * but also could come from storage.
94
+ * This call allows connection manager to adjust knowledge about acked ops sent on previous connection.
95
+ * Can be called at any time, including when there is no active connection.
96
+ */
97
+ beforeProcessingIncomingOp(message: ISequencedDocumentMessage): void;
98
+
99
+ /**
100
+ * Submits signal to relay service.
101
+ * Called only when active connection is present.
102
+ */
103
+ submitSignal(content: any, targetClientId?: string): void;
104
+
105
+ /**
106
+ * Submits messages to relay service.
107
+ * Called only when active connection is present.
108
+ */
109
+ sendMessages(messages: IDocumentMessage[]): void;
110
+
111
+ /**
112
+ * Initiates connection to relay service (noop if already connected).
113
+ */
114
+ connect(reason: IConnectionStateChangeReason, connectionMode?: ConnectionMode): void;
115
+
116
+ /**
117
+ * Disposed connection manager
118
+ */
119
+ dispose(error?: ICriticalContainerError, switchToReadonly?: boolean): void;
120
+
121
+ get connectionMode(): ConnectionMode;
106
122
  }
107
123
 
108
124
  /**
109
125
  * This interface represents a set of callbacks provided by DeltaManager to IConnectionManager on its creation
110
- * IConnectionManager instance will use them to communicate to DeltaManager abour various events.
126
+ * IConnectionManager instance will use them to communicate to DeltaManager about various events.
111
127
  */
112
128
  export interface IConnectionManagerFactoryArgs {
113
- /**
114
- * Called by connection manager for each incomming op. Some ops maybe delivered before
115
- * connectHandler is called (initial ops on socket connection)
116
- */
117
- readonly incomingOpHandler: (messages: ISequencedDocumentMessage[], reason: string) => void;
118
-
119
- /**
120
- * Called by connection manager for each incoming signals.
121
- * Maybe called before connectHandler is called (initial signals on socket connection)
122
- */
123
- readonly signalHandler: (message: ISignalMessage) => void;
124
-
125
- /**
126
- * Called when connection manager experiences delay in connecting to relay service.
127
- * This can happen because client is offline, or service is busy and asks to not connect for some time.
128
- * Can be called many times while not connected.
129
- * Situation is considered resolved when connection is established and connectHandler is called.
130
- */
131
- readonly reconnectionDelayHandler: (delayMs: number, error: unknown) => void;
132
-
133
- /**
134
- * Called by connection manager whwnever critical error happens and container should be closed.
135
- * Expects dispose() call in respose to this call.
136
- */
137
- readonly closeHandler: (error?: any) => void;
138
-
139
- /**
140
- * Called whenever connection to relay service is lost.
141
- */
142
- readonly disconnectHandler: (reason: string) => void;
143
-
144
- /**
145
- * Called whenever new connection to rely service is established
146
- */
147
- readonly connectHandler: (connection: IConnectionDetails) => void;
148
-
149
- /**
150
- * Called whenever ping/pong messages are roundtripped on connection.
151
- */
152
- readonly pongHandler: (latency: number) => void;
153
-
154
- /**
155
- * Called whenever connection type changes from writable to read-only or vice versa.
156
- * Connection can be read-only if user has no edit permissions, or if container forced
157
- * connection to be read-only.
158
- * This should not be confused with "read" / "write"connection mode which is internal
159
- * optimization.
160
- */
161
- readonly readonlyChangeHandler: (readonly?: boolean) => void;
129
+ /**
130
+ * Called by connection manager for each incoming op. Some ops maybe delivered before
131
+ * connectHandler is called (initial ops on socket connection)
132
+ */
133
+ readonly incomingOpHandler: (messages: ISequencedDocumentMessage[], reason: string) => void;
134
+
135
+ /**
136
+ * Called by connection manager for each incoming signal.
137
+ * May be called before connectHandler is called (due to initial signals on socket connection)
138
+ */
139
+ readonly signalHandler: (signals: ISignalMessage[]) => void;
140
+
141
+ /**
142
+ * Called when connection manager experiences delay in connecting to relay service.
143
+ * This can happen because client is offline, or service is busy and asks to not connect for some time.
144
+ * Can be called many times while not connected.
145
+ * Situation is considered resolved when connection is established and connectHandler is called.
146
+ */
147
+ readonly reconnectionDelayHandler: (delayMs: number, error: unknown) => void;
148
+
149
+ /**
150
+ * Called by connection manager whenever critical error happens and container should be closed.
151
+ * Expects dispose() call in response to this call.
152
+ */
153
+ readonly closeHandler: (error?: any) => void;
154
+
155
+ /**
156
+ * Called whenever connection to relay service is lost.
157
+ */
158
+ readonly disconnectHandler: (reason: IConnectionStateChangeReason) => void;
159
+
160
+ /**
161
+ * Called whenever new connection to rely service is established
162
+ */
163
+ readonly connectHandler: (connection: IConnectionDetailsInternal) => void;
164
+
165
+ /**
166
+ * Called whenever ping/pong messages are roundtripped on connection.
167
+ */
168
+ readonly pongHandler: (latency: number) => void;
169
+
170
+ /**
171
+ * Called whenever connection type changes from writable to read-only or vice versa.
172
+ *
173
+ * @remarks
174
+ *
175
+ * Connection can be read-only if user has no edit permissions, or if container forced
176
+ * connection to be read-only.
177
+ * This should not be confused with "read" / "write"connection mode which is internal
178
+ * optimization.
179
+ *
180
+ * @param readonly - Whether or not the container is now read-only.
181
+ * `undefined` indicates that user permissions are not yet known.
182
+ * @param readonlyConnectionReason - reason/error if any for the change
183
+ */
184
+ readonly readonlyChangeHandler: (
185
+ readonly?: boolean,
186
+ readonlyConnectionReason?: IConnectionStateChangeReason,
187
+ ) => void;
188
+
189
+ /**
190
+ * Called whenever we try to start establishing a new connection.
191
+ */
192
+ readonly establishConnectionHandler: (reason: IConnectionStateChangeReason) => void;
193
+
194
+ /**
195
+ * Called whenever we cancel the connection in progress.
196
+ */
197
+ readonly cancelConnectionHandler: (reason: IConnectionStateChangeReason) => void;
162
198
  }
163
199
 
164
200
  /**
@@ -166,14 +202,16 @@ export interface IConnectionManagerFactoryArgs {
166
202
  * @param codeDetails- - Data structure used to describe the code to load on the Fluid document
167
203
  * @returns The name of the Fluid package
168
204
  */
169
- export const getPackageName = (codeDetails: IFluidCodeDetails | undefined): IContainerPackageInfo => {
170
- let containerPackageName;
171
- if (codeDetails && "name" in codeDetails) {
172
- containerPackageName = codeDetails;
173
- } else if (isFluidPackage(codeDetails?.package)) {
174
- containerPackageName = codeDetails?.package.name;
175
- } else {
176
- containerPackageName = codeDetails?.package;
177
- }
178
- return { name: containerPackageName };
205
+ export const getPackageName = (
206
+ codeDetails: IFluidCodeDetails | undefined,
207
+ ): IContainerPackageInfo => {
208
+ let containerPackageName;
209
+ if (codeDetails && "name" in codeDetails) {
210
+ containerPackageName = codeDetails;
211
+ } else if (isFluidPackage(codeDetails?.package)) {
212
+ containerPackageName = codeDetails?.package.name;
213
+ } else {
214
+ containerPackageName = codeDetails?.package;
215
+ }
216
+ return { name: containerPackageName };
179
217
  };
@@ -0,0 +1,123 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import {
7
+ ITelemetryBaseEvent,
8
+ ITelemetryBaseLogger,
9
+ ITelemetryProperties,
10
+ } from "@fluidframework/core-interfaces";
11
+ import { performance } from "@fluid-internal/client-utils";
12
+
13
+ import {
14
+ ITelemetryLoggerExt,
15
+ ITelemetryLoggerPropertyBags,
16
+ createMultiSinkLogger,
17
+ eventNamespaceSeparator,
18
+ formatTick,
19
+ } from "@fluidframework/telemetry-utils";
20
+
21
+ // This import style is necessary to ensure the emitted JS code works in both CJS and ESM.
22
+ import debugPkg from "debug";
23
+ const { debug: registerDebug } = debugPkg;
24
+
25
+ import type { IDebugger } from "debug";
26
+
27
+ /**
28
+ * Implementation of debug logger
29
+ */
30
+ export class DebugLogger implements ITelemetryBaseLogger {
31
+ /**
32
+ * Mix in debug logger with another logger.
33
+ * Returned logger will output events to both newly created debug logger, as well as base logger
34
+ * @param namespace - Telemetry event name prefix to add to all events
35
+ * @param properties - Base properties to add to all events
36
+ * @param propertyGetters - Getters to add additional properties to all events
37
+ * @param baseLogger - Base logger to output events (in addition to debug logger being created). Can be undefined.
38
+ */
39
+ public static mixinDebugLogger(
40
+ namespace: string,
41
+ baseLogger?: ITelemetryBaseLogger,
42
+ properties?: ITelemetryLoggerPropertyBags,
43
+ ): ITelemetryLoggerExt {
44
+ // Setup base logger upfront, such that host can disable it (if needed)
45
+ const debug = registerDebug(namespace);
46
+
47
+ // Create one for errors that is always enabled
48
+ // It can be silenced by replacing console.error if the debug namespace is not enabled.
49
+ const debugErr = registerDebug(namespace);
50
+ debugErr.log = function (...args) {
51
+ if (debug.enabled === true) {
52
+ // if the namespace is enabled, just use the default logger
53
+ registerDebug.log(...args);
54
+ } else {
55
+ // other wise, use the console logger (which could be replaced and silenced)
56
+ console.error(...args);
57
+ }
58
+ };
59
+ debugErr.enabled = true;
60
+
61
+ return createMultiSinkLogger({
62
+ namespace,
63
+ loggers: [baseLogger, new DebugLogger(debug, debugErr)],
64
+ properties,
65
+ tryInheritProperties: true,
66
+ });
67
+ }
68
+
69
+ private constructor(
70
+ private readonly debug: IDebugger,
71
+ private readonly debugErr: IDebugger,
72
+ ) {}
73
+
74
+ /**
75
+ * Send an event to debug loggers
76
+ *
77
+ * @param event - the event to send
78
+ */
79
+ public send(event: ITelemetryBaseEvent): void {
80
+ const newEvent: ITelemetryProperties = { ...event };
81
+ const isError = newEvent.category === "error";
82
+ let logger = isError ? this.debugErr : this.debug;
83
+
84
+ // Use debug's coloring schema for base of the event
85
+ const index = event.eventName.lastIndexOf(eventNamespaceSeparator);
86
+ const name = event.eventName.substring(index + 1);
87
+ if (index > 0) {
88
+ logger = logger.extend(event.eventName.substring(0, index));
89
+ }
90
+ newEvent.eventName = undefined;
91
+
92
+ let tick = "";
93
+ tick = `tick=${formatTick(performance.now())}`;
94
+
95
+ // Extract stack to put it last, but also to avoid escaping '\n' in it by JSON.stringify below
96
+ const stack = newEvent.stack ?? "";
97
+ newEvent.stack = undefined;
98
+
99
+ // Watch out for circular references - they can come from two sources
100
+ // 1) error object - we do not control it and should remove it and retry
101
+ // 2) properties supplied by telemetry caller - that's a bug that should be addressed!
102
+ let payload: string;
103
+ try {
104
+ payload = JSON.stringify(newEvent);
105
+ } catch (error) {
106
+ newEvent.error = undefined;
107
+ payload = JSON.stringify(newEvent);
108
+ }
109
+
110
+ if (payload === "{}") {
111
+ payload = "";
112
+ }
113
+
114
+ // Force errors out, to help with diagnostics
115
+ if (isError) {
116
+ logger.enabled = true;
117
+ }
118
+
119
+ // Print multi-line.
120
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
121
+ logger(`${name} ${payload} ${tick} ${stack}`);
122
+ }
123
+ }