@fluidframework/container-loader 2.0.0-dev.2.3.0.115467 → 2.0.0-dev.4.1.0.148229
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +18 -21
- package/.mocharc.js +2 -2
- package/README.md +65 -44
- package/api-extractor.json +2 -2
- package/closeAndGetPendingLocalState.md +51 -0
- package/dist/audience.d.ts +0 -1
- package/dist/audience.d.ts.map +1 -1
- package/dist/audience.js.map +1 -1
- package/dist/catchUpMonitor.d.ts.map +1 -1
- package/dist/catchUpMonitor.js.map +1 -1
- package/dist/collabWindowTracker.d.ts.map +1 -1
- package/dist/collabWindowTracker.js.map +1 -1
- package/dist/connectionManager.d.ts +5 -5
- package/dist/connectionManager.d.ts.map +1 -1
- package/dist/connectionManager.js +107 -44
- package/dist/connectionManager.js.map +1 -1
- package/dist/connectionState.d.ts.map +1 -1
- package/dist/connectionState.js.map +1 -1
- package/dist/connectionStateHandler.d.ts +7 -7
- package/dist/connectionStateHandler.d.ts.map +1 -1
- package/dist/connectionStateHandler.js +50 -21
- package/dist/connectionStateHandler.js.map +1 -1
- package/dist/container.d.ts +64 -5
- package/dist/container.d.ts.map +1 -1
- package/dist/container.js +329 -137
- package/dist/container.js.map +1 -1
- package/dist/containerContext.d.ts +19 -8
- package/dist/containerContext.d.ts.map +1 -1
- package/dist/containerContext.js +58 -14
- package/dist/containerContext.js.map +1 -1
- package/dist/containerStorageAdapter.d.ts +41 -2
- package/dist/containerStorageAdapter.d.ts.map +1 -1
- package/dist/containerStorageAdapter.js +88 -14
- package/dist/containerStorageAdapter.js.map +1 -1
- package/dist/contracts.d.ts +3 -3
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js.map +1 -1
- package/dist/deltaManager.d.ts +21 -8
- package/dist/deltaManager.d.ts.map +1 -1
- package/dist/deltaManager.js +112 -37
- package/dist/deltaManager.js.map +1 -1
- package/dist/deltaManagerProxy.d.ts +10 -22
- package/dist/deltaManagerProxy.d.ts.map +1 -1
- package/dist/deltaManagerProxy.js +14 -50
- package/dist/deltaManagerProxy.js.map +1 -1
- package/dist/deltaQueue.d.ts.map +1 -1
- package/dist/deltaQueue.js +4 -2
- package/dist/deltaQueue.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts +13 -4
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +38 -24
- package/dist/loader.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +2 -1
- package/dist/protocol.js.map +1 -1
- package/dist/protocolTreeDocumentStorageService.d.ts +6 -2
- package/dist/protocolTreeDocumentStorageService.d.ts.map +1 -1
- package/dist/protocolTreeDocumentStorageService.js +7 -4
- package/dist/protocolTreeDocumentStorageService.js.map +1 -1
- package/dist/quorum.d.ts.map +1 -1
- package/dist/quorum.js.map +1 -1
- package/dist/retriableDocumentStorageService.d.ts.map +1 -1
- package/dist/retriableDocumentStorageService.js +6 -2
- package/dist/retriableDocumentStorageService.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +8 -5
- package/dist/utils.js.map +1 -1
- package/lib/audience.d.ts +0 -1
- package/lib/audience.d.ts.map +1 -1
- package/lib/audience.js.map +1 -1
- package/lib/catchUpMonitor.d.ts.map +1 -1
- package/lib/catchUpMonitor.js.map +1 -1
- package/lib/collabWindowTracker.d.ts.map +1 -1
- package/lib/collabWindowTracker.js.map +1 -1
- package/lib/connectionManager.d.ts +5 -5
- package/lib/connectionManager.d.ts.map +1 -1
- package/lib/connectionManager.js +110 -47
- package/lib/connectionManager.js.map +1 -1
- package/lib/connectionState.d.ts.map +1 -1
- package/lib/connectionState.js.map +1 -1
- package/lib/connectionStateHandler.d.ts +7 -7
- package/lib/connectionStateHandler.d.ts.map +1 -1
- package/lib/connectionStateHandler.js +50 -21
- package/lib/connectionStateHandler.js.map +1 -1
- package/lib/container.d.ts +64 -5
- package/lib/container.d.ts.map +1 -1
- package/lib/container.js +336 -144
- package/lib/container.js.map +1 -1
- package/lib/containerContext.d.ts +19 -8
- package/lib/containerContext.d.ts.map +1 -1
- package/lib/containerContext.js +59 -15
- package/lib/containerContext.js.map +1 -1
- package/lib/containerStorageAdapter.d.ts +41 -2
- package/lib/containerStorageAdapter.d.ts.map +1 -1
- package/lib/containerStorageAdapter.js +86 -14
- package/lib/containerStorageAdapter.js.map +1 -1
- package/lib/contracts.d.ts +3 -3
- package/lib/contracts.d.ts.map +1 -1
- package/lib/contracts.js.map +1 -1
- package/lib/deltaManager.d.ts +21 -8
- package/lib/deltaManager.d.ts.map +1 -1
- package/lib/deltaManager.js +114 -39
- package/lib/deltaManager.js.map +1 -1
- package/lib/deltaManagerProxy.d.ts +10 -22
- package/lib/deltaManagerProxy.d.ts.map +1 -1
- package/lib/deltaManagerProxy.js +14 -50
- package/lib/deltaManagerProxy.js.map +1 -1
- package/lib/deltaQueue.d.ts.map +1 -1
- package/lib/deltaQueue.js +4 -2
- package/lib/deltaQueue.js.map +1 -1
- package/lib/index.d.ts +4 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/loader.d.ts +13 -4
- package/lib/loader.d.ts.map +1 -1
- package/lib/loader.js +37 -24
- package/lib/loader.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +2 -1
- package/lib/protocol.js.map +1 -1
- package/lib/protocolTreeDocumentStorageService.d.ts +6 -2
- package/lib/protocolTreeDocumentStorageService.d.ts.map +1 -1
- package/lib/protocolTreeDocumentStorageService.js +7 -4
- package/lib/protocolTreeDocumentStorageService.js.map +1 -1
- package/lib/quorum.d.ts.map +1 -1
- package/lib/quorum.js.map +1 -1
- package/lib/retriableDocumentStorageService.d.ts.map +1 -1
- package/lib/retriableDocumentStorageService.js +6 -2
- package/lib/retriableDocumentStorageService.js.map +1 -1
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +8 -5
- package/lib/utils.js.map +1 -1
- package/package.json +67 -56
- package/prettier.config.cjs +1 -1
- package/src/audience.ts +51 -46
- package/src/catchUpMonitor.ts +39 -37
- package/src/collabWindowTracker.ts +75 -70
- package/src/connectionManager.ts +1040 -941
- package/src/connectionState.ts +19 -19
- package/src/connectionStateHandler.ts +557 -463
- package/src/container.ts +2147 -1784
- package/src/containerContext.ts +417 -345
- package/src/containerStorageAdapter.ts +268 -154
- package/src/contracts.ts +155 -153
- package/src/deltaManager.ts +1074 -945
- package/src/deltaManagerProxy.ts +88 -137
- package/src/deltaQueue.ts +155 -151
- package/src/index.ts +13 -17
- package/src/loader.ts +434 -427
- package/src/packageVersion.ts +1 -1
- package/src/protocol.ts +93 -87
- package/src/protocolTreeDocumentStorageService.ts +34 -34
- package/src/quorum.ts +34 -34
- package/src/retriableDocumentStorageService.ts +118 -102
- package/src/utils.ts +93 -83
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +8 -12
package/src/containerContext.ts
CHANGED
|
@@ -4,360 +4,432 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
7
|
-
import { LazyPromise } from "@fluidframework/common-utils";
|
|
7
|
+
import { assert, LazyPromise, TypedEventEmitter } from "@fluidframework/common-utils";
|
|
8
8
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
IBatchMessage,
|
|
9
|
+
IAudience,
|
|
10
|
+
IContainerContext,
|
|
11
|
+
IDeltaManager,
|
|
12
|
+
ILoader,
|
|
13
|
+
IRuntime,
|
|
14
|
+
ICriticalContainerError,
|
|
15
|
+
AttachState,
|
|
16
|
+
ILoaderOptions,
|
|
17
|
+
IRuntimeFactory,
|
|
18
|
+
IProvideRuntimeFactory,
|
|
19
|
+
IFluidCodeDetails,
|
|
20
|
+
IFluidCodeDetailsComparer,
|
|
21
|
+
IProvideFluidCodeDetailsComparer,
|
|
22
|
+
ICodeDetailsLoader,
|
|
23
|
+
IFluidModuleWithDetails,
|
|
24
|
+
IBatchMessage,
|
|
26
25
|
} from "@fluidframework/container-definitions";
|
|
27
|
-
import {
|
|
28
|
-
IRequest,
|
|
29
|
-
IResponse,
|
|
30
|
-
FluidObject,
|
|
31
|
-
} from "@fluidframework/core-interfaces";
|
|
26
|
+
import { IRequest, IResponse, FluidObject } from "@fluidframework/core-interfaces";
|
|
32
27
|
import { IDocumentStorageService } from "@fluidframework/driver-definitions";
|
|
33
28
|
import { isFluidResolvedUrl } from "@fluidframework/driver-utils";
|
|
34
29
|
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
30
|
+
IClientConfiguration,
|
|
31
|
+
IClientDetails,
|
|
32
|
+
IDocumentMessage,
|
|
33
|
+
IQuorum,
|
|
34
|
+
IQuorumClients,
|
|
35
|
+
ISequencedDocumentMessage,
|
|
36
|
+
ISignalMessage,
|
|
37
|
+
ISnapshotTree,
|
|
38
|
+
ISummaryTree,
|
|
39
|
+
IVersion,
|
|
40
|
+
MessageType,
|
|
41
|
+
ISummaryContent,
|
|
47
42
|
} from "@fluidframework/protocol-definitions";
|
|
48
43
|
import { PerformanceEvent } from "@fluidframework/telemetry-utils";
|
|
49
|
-
import {
|
|
44
|
+
import { UsageError } from "@fluidframework/container-utils";
|
|
45
|
+
import { Container } from "./container";
|
|
50
46
|
|
|
51
47
|
const PackageNotFactoryError = "Code package does not implement IRuntimeFactory";
|
|
52
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Events that {@link ContainerContext} can emit through its lifecycle.
|
|
51
|
+
*
|
|
52
|
+
* "runtimeInstantiated" - When an {@link @fluidframework/container-definitions#IRuntime} has been instantiated (by
|
|
53
|
+
* calling instantiateRuntime() on the runtime factory), and this._runtime is set.
|
|
54
|
+
*
|
|
55
|
+
* "disposed" - When its dispose() method is called. The {@link ContainerContext} is no longer usable at that point.
|
|
56
|
+
*/
|
|
57
|
+
type ContextLifecycleEvents = "runtimeInstantiated" | "disposed";
|
|
58
|
+
|
|
53
59
|
export class ContainerContext implements IContainerContext {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
60
|
+
public static async createOrLoad(
|
|
61
|
+
container: Container,
|
|
62
|
+
scope: FluidObject,
|
|
63
|
+
codeLoader: ICodeDetailsLoader,
|
|
64
|
+
codeDetails: IFluidCodeDetails,
|
|
65
|
+
baseSnapshot: ISnapshotTree | undefined,
|
|
66
|
+
deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,
|
|
67
|
+
quorum: IQuorum,
|
|
68
|
+
loader: ILoader,
|
|
69
|
+
submitFn: (type: MessageType, contents: any, batch: boolean, appData: any) => number,
|
|
70
|
+
submitSummaryFn: (summaryOp: ISummaryContent, referenceSequenceNumber?: number) => number,
|
|
71
|
+
submitBatchFn: (batch: IBatchMessage[], referenceSequenceNumber?: number) => number,
|
|
72
|
+
submitSignalFn: (contents: any) => void,
|
|
73
|
+
disposeFn: (error?: ICriticalContainerError) => void,
|
|
74
|
+
closeFn: (error?: ICriticalContainerError) => void,
|
|
75
|
+
version: string,
|
|
76
|
+
updateDirtyContainerState: (dirty: boolean) => void,
|
|
77
|
+
existing: boolean,
|
|
78
|
+
pendingLocalState?: unknown,
|
|
79
|
+
): Promise<ContainerContext> {
|
|
80
|
+
const context = new ContainerContext(
|
|
81
|
+
container,
|
|
82
|
+
scope,
|
|
83
|
+
codeLoader,
|
|
84
|
+
codeDetails,
|
|
85
|
+
baseSnapshot,
|
|
86
|
+
deltaManager,
|
|
87
|
+
quorum,
|
|
88
|
+
loader,
|
|
89
|
+
submitFn,
|
|
90
|
+
submitSummaryFn,
|
|
91
|
+
submitBatchFn,
|
|
92
|
+
submitSignalFn,
|
|
93
|
+
disposeFn,
|
|
94
|
+
closeFn,
|
|
95
|
+
version,
|
|
96
|
+
updateDirtyContainerState,
|
|
97
|
+
existing,
|
|
98
|
+
pendingLocalState,
|
|
99
|
+
);
|
|
100
|
+
await context.instantiateRuntime(existing);
|
|
101
|
+
return context;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public readonly taggedLogger: ITelemetryLogger;
|
|
105
|
+
public readonly supportedFeatures: ReadonlyMap<string, unknown>;
|
|
106
|
+
|
|
107
|
+
public get clientId(): string | undefined {
|
|
108
|
+
return this.container.clientId;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* DISCLAIMER: this id is only for telemetry purposes. Not suitable for any other usages.
|
|
113
|
+
*/
|
|
114
|
+
public get id(): string {
|
|
115
|
+
const resolvedUrl = this.container.resolvedUrl;
|
|
116
|
+
if (isFluidResolvedUrl(resolvedUrl)) {
|
|
117
|
+
return resolvedUrl.id;
|
|
118
|
+
}
|
|
119
|
+
return "";
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public get clientDetails(): IClientDetails {
|
|
123
|
+
return this.container.clientDetails;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private _connected: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* When true, ops are free to flow
|
|
129
|
+
* When false, ops should be kept as pending or rejected
|
|
130
|
+
*/
|
|
131
|
+
public get connected(): boolean {
|
|
132
|
+
return this._connected;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public get canSummarize(): boolean {
|
|
136
|
+
return "summarize" in this.runtime;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public get serviceConfiguration(): IClientConfiguration | undefined {
|
|
140
|
+
return this.container.serviceConfiguration;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
public get audience(): IAudience {
|
|
144
|
+
return this.container.audience;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public get options(): ILoaderOptions {
|
|
148
|
+
return this.container.options;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
public get baseSnapshot() {
|
|
152
|
+
return this._baseSnapshot;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
public get storage(): IDocumentStorageService {
|
|
156
|
+
return this.container.storage;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private _runtime: IRuntime | undefined;
|
|
160
|
+
private get runtime() {
|
|
161
|
+
if (this._runtime === undefined) {
|
|
162
|
+
throw new Error("Attempted to access runtime before it was defined");
|
|
163
|
+
}
|
|
164
|
+
return this._runtime;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private _disposed = false;
|
|
168
|
+
|
|
169
|
+
public get disposed() {
|
|
170
|
+
return this._disposed;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
public get codeDetails() {
|
|
174
|
+
return this._codeDetails;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private readonly _quorum: IQuorum;
|
|
178
|
+
public get quorum(): IQuorumClients {
|
|
179
|
+
return this._quorum;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
private readonly _fluidModuleP: Promise<IFluidModuleWithDetails>;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* {@inheritDoc @fluidframework/container-definitions#IContainerContext.getEntryPoint}
|
|
186
|
+
*/
|
|
187
|
+
public async getEntryPoint?(): Promise<FluidObject | undefined> {
|
|
188
|
+
if (this._disposed) {
|
|
189
|
+
throw new UsageError("The context is already disposed");
|
|
190
|
+
}
|
|
191
|
+
if (this._runtime !== undefined) {
|
|
192
|
+
return this._runtime?.getEntryPoint?.();
|
|
193
|
+
}
|
|
194
|
+
return new Promise<FluidObject | undefined>((resolve, reject) => {
|
|
195
|
+
const runtimeInstantiatedHandler = () => {
|
|
196
|
+
assert(
|
|
197
|
+
this._runtime !== undefined,
|
|
198
|
+
0x5a3 /* runtimeInstantiated fired but runtime is still undefined */,
|
|
199
|
+
);
|
|
200
|
+
resolve(this._runtime.getEntryPoint?.());
|
|
201
|
+
this.lifecycleEvents.off("disposed", disposedHandler);
|
|
202
|
+
};
|
|
203
|
+
const disposedHandler = () => {
|
|
204
|
+
reject(new Error("ContainerContext was disposed"));
|
|
205
|
+
this.lifecycleEvents.off("runtimeInstantiated", runtimeInstantiatedHandler);
|
|
206
|
+
};
|
|
207
|
+
this.lifecycleEvents.once("runtimeInstantiated", runtimeInstantiatedHandler);
|
|
208
|
+
this.lifecycleEvents.once("disposed", disposedHandler);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Emits events about the container context's lifecycle.
|
|
214
|
+
* Use it to coordinate things inside the ContainerContext class.
|
|
215
|
+
*/
|
|
216
|
+
private readonly lifecycleEvents = new TypedEventEmitter<ContextLifecycleEvents>();
|
|
217
|
+
|
|
218
|
+
constructor(
|
|
219
|
+
private readonly container: Container,
|
|
220
|
+
public readonly scope: FluidObject,
|
|
221
|
+
private readonly codeLoader: ICodeDetailsLoader,
|
|
222
|
+
private readonly _codeDetails: IFluidCodeDetails,
|
|
223
|
+
private readonly _baseSnapshot: ISnapshotTree | undefined,
|
|
224
|
+
public readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,
|
|
225
|
+
quorum: IQuorum,
|
|
226
|
+
public readonly loader: ILoader,
|
|
227
|
+
public readonly submitFn: (
|
|
228
|
+
type: MessageType,
|
|
229
|
+
contents: any,
|
|
230
|
+
batch: boolean,
|
|
231
|
+
appData: any,
|
|
232
|
+
) => number,
|
|
233
|
+
public readonly submitSummaryFn: (
|
|
234
|
+
summaryOp: ISummaryContent,
|
|
235
|
+
referenceSequenceNumber?: number,
|
|
236
|
+
) => number,
|
|
237
|
+
/** @returns clientSequenceNumber of last message in a batch */
|
|
238
|
+
public readonly submitBatchFn: (
|
|
239
|
+
batch: IBatchMessage[],
|
|
240
|
+
referenceSequenceNumber?: number,
|
|
241
|
+
) => number,
|
|
242
|
+
public readonly submitSignalFn: (contents: any) => void,
|
|
243
|
+
public readonly disposeFn: (error?: ICriticalContainerError) => void,
|
|
244
|
+
public readonly closeFn: (error?: ICriticalContainerError) => void,
|
|
245
|
+
public readonly version: string,
|
|
246
|
+
public readonly updateDirtyContainerState: (dirty: boolean) => void,
|
|
247
|
+
public readonly existing: boolean,
|
|
248
|
+
public readonly pendingLocalState?: unknown,
|
|
249
|
+
) {
|
|
250
|
+
this._connected = this.container.connected;
|
|
251
|
+
this._quorum = quorum;
|
|
252
|
+
this.taggedLogger = container.subLogger;
|
|
253
|
+
this._fluidModuleP = new LazyPromise<IFluidModuleWithDetails>(async () =>
|
|
254
|
+
this.loadCodeModule(_codeDetails),
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
this.supportedFeatures = new Map([
|
|
258
|
+
/**
|
|
259
|
+
* This version of the loader accepts `referenceSequenceNumber`, provided by the container runtime,
|
|
260
|
+
* as a parameter to the `submitBatchFn` and `submitSummaryFn` functions.
|
|
261
|
+
* This is then used to set the reference sequence numbers of the submitted ops in the DeltaManager.
|
|
262
|
+
*/
|
|
263
|
+
["referenceSequenceNumbers", true],
|
|
264
|
+
]);
|
|
265
|
+
this.attachListener();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* @deprecated Temporary migratory API, to be removed when customers no longer need it.
|
|
270
|
+
* When removed, `ContainerContext` should only take an {@link @fluidframework/container-definitions#IQuorumClients}
|
|
271
|
+
* rather than an {@link @fluidframework/protocol-definitions#IQuorum}.
|
|
272
|
+
* See {@link @fluidframework/container-definitions#IContainerContext} for more details.
|
|
273
|
+
*/
|
|
274
|
+
public getSpecifiedCodeDetails(): IFluidCodeDetails | undefined {
|
|
275
|
+
return (this._quorum.get("code") ?? this._quorum.get("code2")) as
|
|
276
|
+
| IFluidCodeDetails
|
|
277
|
+
| undefined;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
public dispose(error?: Error): void {
|
|
281
|
+
if (this._disposed) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
this._disposed = true;
|
|
285
|
+
|
|
286
|
+
this.lifecycleEvents.emit("disposed");
|
|
287
|
+
this.runtime.dispose(error);
|
|
288
|
+
this._quorum.dispose();
|
|
289
|
+
this.deltaManager.dispose();
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
public getLoadedFromVersion(): IVersion | undefined {
|
|
293
|
+
return this.container.loadedFromVersion;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
public get attachState(): AttachState {
|
|
297
|
+
return this.container.attachState;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Create a summary. Used when attaching or serializing a detached container.
|
|
302
|
+
*
|
|
303
|
+
* @param blobRedirectTable - A table passed during the attach process. While detached, blob upload is supported
|
|
304
|
+
* using IDs generated locally. After attach, these IDs cannot be used, so this table maps the old local IDs to the
|
|
305
|
+
* new storage IDs so requests can be redirected.
|
|
306
|
+
*/
|
|
307
|
+
public createSummary(blobRedirectTable?: Map<string, string>): ISummaryTree {
|
|
308
|
+
return this.runtime.createSummary(blobRedirectTable);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
public setConnectionState(connected: boolean, clientId?: string) {
|
|
312
|
+
const runtime = this.runtime;
|
|
313
|
+
this._connected = connected;
|
|
314
|
+
runtime.setConnectionState(connected, clientId);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
public process(message: ISequencedDocumentMessage, local: boolean) {
|
|
318
|
+
this.runtime.process(message, local);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
public processSignal(message: ISignalMessage, local: boolean) {
|
|
322
|
+
this.runtime.processSignal(message, local);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
public async request(path: IRequest): Promise<IResponse> {
|
|
326
|
+
return this.runtime.request(path);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
public async getAbsoluteUrl(relativeUrl: string): Promise<string | undefined> {
|
|
330
|
+
return this.container.getAbsoluteUrl(relativeUrl);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
public getPendingLocalState(): unknown {
|
|
334
|
+
return this.runtime.getPendingLocalState();
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Determines if the current code details of the context
|
|
339
|
+
* satisfy the incoming constraint code details
|
|
340
|
+
*/
|
|
341
|
+
public async satisfies(constraintCodeDetails: IFluidCodeDetails) {
|
|
342
|
+
const comparers: IFluidCodeDetailsComparer[] = [];
|
|
343
|
+
|
|
344
|
+
const maybeCompareCodeLoader = this.codeLoader;
|
|
345
|
+
if (maybeCompareCodeLoader.IFluidCodeDetailsComparer !== undefined) {
|
|
346
|
+
comparers.push(maybeCompareCodeLoader.IFluidCodeDetailsComparer);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const moduleWithDetails = await this._fluidModuleP;
|
|
350
|
+
const maybeCompareExport: Partial<IProvideFluidCodeDetailsComparer> | undefined =
|
|
351
|
+
moduleWithDetails.module?.fluidExport;
|
|
352
|
+
if (maybeCompareExport?.IFluidCodeDetailsComparer !== undefined) {
|
|
353
|
+
comparers.push(maybeCompareExport.IFluidCodeDetailsComparer);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// if there are not comparers it is not possible to know
|
|
357
|
+
// if the current satisfy the incoming, so return false,
|
|
358
|
+
// as assuming they do not satisfy is safer .e.g we will
|
|
359
|
+
// reload, rather than potentially running with
|
|
360
|
+
// incompatible code
|
|
361
|
+
if (comparers.length === 0) {
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
for (const comparer of comparers) {
|
|
366
|
+
const satisfies = await comparer.satisfies(
|
|
367
|
+
moduleWithDetails.details,
|
|
368
|
+
constraintCodeDetails,
|
|
369
|
+
);
|
|
370
|
+
if (satisfies === false) {
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
public async notifyOpReplay(message: ISequencedDocumentMessage): Promise<void> {
|
|
378
|
+
return this.runtime.notifyOpReplay?.(message);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// #region private
|
|
382
|
+
|
|
383
|
+
private async getRuntimeFactory(): Promise<IRuntimeFactory> {
|
|
384
|
+
const fluidExport: FluidObject<IProvideRuntimeFactory> | undefined = (
|
|
385
|
+
await this._fluidModuleP
|
|
386
|
+
).module?.fluidExport;
|
|
387
|
+
const runtimeFactory = fluidExport?.IRuntimeFactory;
|
|
388
|
+
if (runtimeFactory === undefined) {
|
|
389
|
+
throw new Error(PackageNotFactoryError);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return runtimeFactory;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
private async instantiateRuntime(existing: boolean) {
|
|
396
|
+
const runtimeFactory = await this.getRuntimeFactory();
|
|
397
|
+
this._runtime = await PerformanceEvent.timedExecAsync(
|
|
398
|
+
this.taggedLogger,
|
|
399
|
+
{ eventName: "InstantiateRuntime" },
|
|
400
|
+
async () => runtimeFactory.instantiateRuntime(this, existing),
|
|
401
|
+
);
|
|
402
|
+
this.lifecycleEvents.emit("runtimeInstantiated");
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
private attachListener() {
|
|
406
|
+
this.container.once("attaching", () => {
|
|
407
|
+
this.runtime.setAttachState(AttachState.Attaching);
|
|
408
|
+
});
|
|
409
|
+
this.container.once("attached", () => {
|
|
410
|
+
this.runtime.setAttachState(AttachState.Attached);
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
private async loadCodeModule(codeDetails: IFluidCodeDetails): Promise<IFluidModuleWithDetails> {
|
|
415
|
+
const loadCodeResult = await PerformanceEvent.timedExecAsync(
|
|
416
|
+
this.taggedLogger,
|
|
417
|
+
{ eventName: "CodeLoad" },
|
|
418
|
+
async () => this.codeLoader.load(codeDetails),
|
|
419
|
+
);
|
|
420
|
+
|
|
421
|
+
if ("module" in loadCodeResult) {
|
|
422
|
+
const { module, details } = loadCodeResult;
|
|
423
|
+
return {
|
|
424
|
+
module,
|
|
425
|
+
details: details ?? codeDetails,
|
|
426
|
+
};
|
|
427
|
+
} else {
|
|
428
|
+
// If "module" is not in the result, we are using a legacy ICodeLoader. Fix the result up with details.
|
|
429
|
+
// Once usage drops to 0 we can remove this compat path.
|
|
430
|
+
this.taggedLogger.sendTelemetryEvent({ eventName: "LegacyCodeLoader" });
|
|
431
|
+
return loadCodeResult;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
// #endregion
|
|
363
435
|
}
|