@fluidframework/container-loader 2.0.0-internal.3.0.5 → 2.0.0-internal.3.1.1

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