@fluidframework/datastore 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 (145) hide show
  1. package/.eslintrc.js +5 -7
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +273 -0
  4. package/README.md +41 -0
  5. package/api-extractor-lint.json +4 -0
  6. package/api-extractor.json +2 -2
  7. package/api-report/datastore.api.md +168 -0
  8. package/dist/channelContext.cjs +86 -0
  9. package/dist/channelContext.cjs.map +1 -0
  10. package/dist/channelContext.d.ts +15 -9
  11. package/dist/channelContext.d.ts.map +1 -1
  12. package/dist/{channelDeltaConnection.js → channelDeltaConnection.cjs} +14 -15
  13. package/dist/channelDeltaConnection.cjs.map +1 -0
  14. package/dist/channelDeltaConnection.d.ts +4 -5
  15. package/dist/channelDeltaConnection.d.ts.map +1 -1
  16. package/dist/{channelStorageService.js → channelStorageService.cjs} +13 -16
  17. package/dist/channelStorageService.cjs.map +1 -0
  18. package/dist/channelStorageService.d.ts +2 -2
  19. package/dist/channelStorageService.d.ts.map +1 -1
  20. package/dist/{dataStoreRuntime.js → dataStoreRuntime.cjs} +302 -225
  21. package/dist/dataStoreRuntime.cjs.map +1 -0
  22. package/dist/dataStoreRuntime.d.ts +81 -37
  23. package/dist/dataStoreRuntime.d.ts.map +1 -1
  24. package/dist/datastore-alpha.d.ts +317 -0
  25. package/dist/datastore-beta.d.ts +47 -0
  26. package/dist/datastore-public.d.ts +47 -0
  27. package/dist/datastore-untrimmed.d.ts +324 -0
  28. package/dist/{fluidHandle.js → fluidHandle.cjs} +44 -16
  29. package/dist/fluidHandle.cjs.map +1 -0
  30. package/dist/fluidHandle.d.ts +33 -6
  31. package/dist/fluidHandle.d.ts.map +1 -1
  32. package/dist/index.cjs +15 -0
  33. package/dist/index.cjs.map +1 -0
  34. package/dist/index.d.ts +2 -2
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/localChannelContext.cjs +190 -0
  37. package/dist/localChannelContext.cjs.map +1 -0
  38. package/dist/localChannelContext.d.ts +12 -21
  39. package/dist/localChannelContext.d.ts.map +1 -1
  40. package/dist/{localChannelStorageService.js → localChannelStorageService.cjs} +3 -3
  41. package/dist/localChannelStorageService.cjs.map +1 -0
  42. package/dist/localChannelStorageService.d.ts.map +1 -1
  43. package/dist/remoteChannelContext.cjs +124 -0
  44. package/dist/remoteChannelContext.cjs.map +1 -0
  45. package/dist/remoteChannelContext.d.ts +5 -10
  46. package/dist/remoteChannelContext.d.ts.map +1 -1
  47. package/dist/tsdoc-metadata.json +11 -0
  48. package/lib/{channelContext.d.ts → channelContext.d.mts} +16 -10
  49. package/lib/channelContext.d.mts.map +1 -0
  50. package/lib/channelContext.mjs +78 -0
  51. package/lib/channelContext.mjs.map +1 -0
  52. package/lib/{channelDeltaConnection.d.ts → channelDeltaConnection.d.mts} +4 -5
  53. package/lib/channelDeltaConnection.d.mts.map +1 -0
  54. package/lib/{channelDeltaConnection.js → channelDeltaConnection.mjs} +11 -12
  55. package/lib/channelDeltaConnection.mjs.map +1 -0
  56. package/lib/{channelStorageService.d.ts → channelStorageService.d.mts} +2 -2
  57. package/lib/channelStorageService.d.mts.map +1 -0
  58. package/lib/{channelStorageService.js → channelStorageService.mjs} +13 -16
  59. package/lib/channelStorageService.mjs.map +1 -0
  60. package/lib/{dataStoreRuntime.d.ts → dataStoreRuntime.d.mts} +81 -37
  61. package/lib/dataStoreRuntime.d.mts.map +1 -0
  62. package/lib/{dataStoreRuntime.js → dataStoreRuntime.mjs} +286 -209
  63. package/lib/dataStoreRuntime.mjs.map +1 -0
  64. package/lib/datastore-alpha.d.mts +317 -0
  65. package/lib/datastore-beta.d.mts +47 -0
  66. package/lib/datastore-public.d.mts +47 -0
  67. package/lib/datastore-untrimmed.d.mts +324 -0
  68. package/lib/fluidHandle.d.mts +57 -0
  69. package/lib/fluidHandle.d.mts.map +1 -0
  70. package/lib/{fluidHandle.js → fluidHandle.mjs} +44 -16
  71. package/lib/fluidHandle.mjs.map +1 -0
  72. package/lib/index.d.mts +7 -0
  73. package/lib/index.d.mts.map +1 -0
  74. package/lib/index.mjs +7 -0
  75. package/lib/index.mjs.map +1 -0
  76. package/lib/{localChannelContext.d.ts → localChannelContext.d.mts} +13 -22
  77. package/lib/localChannelContext.d.mts.map +1 -0
  78. package/lib/{localChannelContext.js → localChannelContext.mjs} +73 -85
  79. package/lib/localChannelContext.mjs.map +1 -0
  80. package/lib/localChannelStorageService.d.mts.map +1 -0
  81. package/lib/{localChannelStorageService.js → localChannelStorageService.mjs} +2 -2
  82. package/lib/localChannelStorageService.mjs.map +1 -0
  83. package/lib/{remoteChannelContext.d.ts → remoteChannelContext.d.mts} +7 -12
  84. package/lib/remoteChannelContext.d.mts.map +1 -0
  85. package/lib/remoteChannelContext.mjs +120 -0
  86. package/lib/remoteChannelContext.mjs.map +1 -0
  87. package/package.json +107 -72
  88. package/{lib/index.js → prettier.config.cjs} +4 -3
  89. package/src/channelContext.ts +168 -71
  90. package/src/channelDeltaConnection.ts +52 -47
  91. package/src/channelStorageService.ts +59 -55
  92. package/src/dataStoreRuntime.ts +1158 -983
  93. package/src/fluidHandle.ts +92 -64
  94. package/src/index.ts +8 -2
  95. package/src/localChannelContext.ts +278 -272
  96. package/src/localChannelStorageService.ts +48 -46
  97. package/src/remoteChannelContext.ts +237 -300
  98. package/tsc-multi.test.json +4 -0
  99. package/tsconfig.json +11 -13
  100. package/dist/channelContext.js +0 -35
  101. package/dist/channelContext.js.map +0 -1
  102. package/dist/channelDeltaConnection.js.map +0 -1
  103. package/dist/channelStorageService.js.map +0 -1
  104. package/dist/dataStoreRuntime.js.map +0 -1
  105. package/dist/fluidHandle.js.map +0 -1
  106. package/dist/index.js +0 -19
  107. package/dist/index.js.map +0 -1
  108. package/dist/localChannelContext.js +0 -202
  109. package/dist/localChannelContext.js.map +0 -1
  110. package/dist/localChannelStorageService.js.map +0 -1
  111. package/dist/packageVersion.d.ts +0 -9
  112. package/dist/packageVersion.d.ts.map +0 -1
  113. package/dist/packageVersion.js +0 -12
  114. package/dist/packageVersion.js.map +0 -1
  115. package/dist/remoteChannelContext.js +0 -207
  116. package/dist/remoteChannelContext.js.map +0 -1
  117. package/lib/channelContext.d.ts.map +0 -1
  118. package/lib/channelContext.js +0 -29
  119. package/lib/channelContext.js.map +0 -1
  120. package/lib/channelDeltaConnection.d.ts.map +0 -1
  121. package/lib/channelDeltaConnection.js.map +0 -1
  122. package/lib/channelStorageService.d.ts.map +0 -1
  123. package/lib/channelStorageService.js.map +0 -1
  124. package/lib/dataStoreRuntime.d.ts.map +0 -1
  125. package/lib/dataStoreRuntime.js.map +0 -1
  126. package/lib/fluidHandle.d.ts +0 -30
  127. package/lib/fluidHandle.d.ts.map +0 -1
  128. package/lib/fluidHandle.js.map +0 -1
  129. package/lib/index.d.ts +0 -7
  130. package/lib/index.d.ts.map +0 -1
  131. package/lib/index.js.map +0 -1
  132. package/lib/localChannelContext.d.ts.map +0 -1
  133. package/lib/localChannelContext.js.map +0 -1
  134. package/lib/localChannelStorageService.d.ts.map +0 -1
  135. package/lib/localChannelStorageService.js.map +0 -1
  136. package/lib/packageVersion.d.ts +0 -9
  137. package/lib/packageVersion.d.ts.map +0 -1
  138. package/lib/packageVersion.js +0 -9
  139. package/lib/packageVersion.js.map +0 -1
  140. package/lib/remoteChannelContext.d.ts.map +0 -1
  141. package/lib/remoteChannelContext.js +0 -203
  142. package/lib/remoteChannelContext.js.map +0 -1
  143. package/src/packageVersion.ts +0 -9
  144. package/tsconfig.esnext.json +0 -7
  145. /package/lib/{localChannelStorageService.d.ts → localChannelStorageService.d.mts} +0 -0
@@ -3,313 +3,250 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { ITelemetryLogger } from "@fluidframework/common-definitions";
7
- import { assert } from "@fluidframework/common-utils";
8
- import { DataCorruptionError } from "@fluidframework/container-utils";
6
+ import { assert, LazyPromise } from "@fluidframework/core-utils";
9
7
  import { IFluidHandle } from "@fluidframework/core-interfaces";
10
- import {
11
- IChannel,
12
- IChannelAttributes,
13
- IFluidDataStoreRuntime,
14
- IChannelFactory,
15
- } from "@fluidframework/datastore-definitions";
8
+ import { IChannel, IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
16
9
  import { IDocumentStorageService } from "@fluidframework/driver-definitions";
17
- import { readAndParse } from "@fluidframework/driver-utils";
18
- import {
19
- ISequencedDocumentMessage,
20
- ISnapshotTree,
21
- } from "@fluidframework/protocol-definitions";
10
+ import { ISequencedDocumentMessage, ISnapshotTree } from "@fluidframework/protocol-definitions";
22
11
  import {
23
- CreateChildSummarizerNodeFn,
24
- IFluidDataStoreContext,
25
- IGarbageCollectionData,
26
- IGarbageCollectionDetailsBase,
27
- ISummarizeInternalResult,
28
- ISummarizeResult,
29
- ISummarizerNodeWithGC,
30
- ITelemetryContext,
12
+ CreateChildSummarizerNodeFn,
13
+ IFluidDataStoreContext,
14
+ IGarbageCollectionData,
15
+ IExperimentalIncrementalSummaryContext,
16
+ ISummarizeInternalResult,
17
+ ISummarizeResult,
18
+ ISummarizerNodeWithGC,
19
+ ITelemetryContext,
31
20
  } from "@fluidframework/runtime-definitions";
32
- import { ChildLogger, TelemetryDataTag, ThresholdCounter } from "@fluidframework/telemetry-utils";
33
21
  import {
34
- attributesBlobKey,
35
- createServiceEndpoints,
36
- IChannelContext,
37
- summarizeChannelAsync,
22
+ createChildLogger,
23
+ ITelemetryLoggerExt,
24
+ ThresholdCounter,
25
+ } from "@fluidframework/telemetry-utils";
26
+ import {
27
+ ChannelServiceEndpoints,
28
+ createChannelServiceEndpoints,
29
+ IChannelContext,
30
+ loadChannel,
31
+ loadChannelFactoryAndAttributes,
32
+ summarizeChannelAsync,
38
33
  } from "./channelContext";
39
- import { ChannelDeltaConnection } from "./channelDeltaConnection";
40
- import { ChannelStorageService } from "./channelStorageService";
41
34
  import { ISharedObjectRegistry } from "./dataStoreRuntime";
42
35
 
43
36
  export class RemoteChannelContext implements IChannelContext {
44
- private isLoaded = false;
45
- private pending: ISequencedDocumentMessage[] | undefined = [];
46
- private channelP: Promise<IChannel> | undefined;
47
- private channel: IChannel | undefined;
48
- private readonly services: {
49
- readonly deltaConnection: ChannelDeltaConnection;
50
- readonly objectStorage: ChannelStorageService;
51
- };
52
- private readonly summarizerNode: ISummarizerNodeWithGC;
53
- private readonly subLogger: ITelemetryLogger;
54
- private readonly thresholdOpsCounter: ThresholdCounter;
55
- private static readonly pendingOpsCountThreshold = 1000;
56
-
57
- constructor(
58
- private readonly runtime: IFluidDataStoreRuntime,
59
- private readonly dataStoreContext: IFluidDataStoreContext,
60
- storageService: IDocumentStorageService,
61
- submitFn: (content: any, localOpMetadata: unknown) => void,
62
- dirtyFn: (address: string) => void,
63
- addedGCOutboundReferenceFn: (srcHandle: IFluidHandle, outboundHandle: IFluidHandle) => void,
64
- private readonly id: string,
65
- baseSnapshot: ISnapshotTree,
66
- private readonly registry: ISharedObjectRegistry,
67
- extraBlobs: Map<string, ArrayBufferLike> | undefined,
68
- createSummarizerNode: CreateChildSummarizerNodeFn,
69
- getBaseGCDetails: () => Promise<IGarbageCollectionDetailsBase>,
70
- private readonly attachMessageType?: string,
71
- ) {
72
- assert(!this.id.includes("/"), 0x310 /* Channel context ID cannot contain slashes */);
73
-
74
- this.subLogger = ChildLogger.create(this.runtime.logger, "RemoteChannelContext");
75
-
76
- this.services = createServiceEndpoints(
77
- this.id,
78
- this.dataStoreContext.connected,
79
- submitFn,
80
- () => dirtyFn(this.id),
81
- addedGCOutboundReferenceFn,
82
- storageService,
83
- this.subLogger,
84
- baseSnapshot,
85
- extraBlobs);
86
-
87
- const thisSummarizeInternal =
88
- async (fullTree: boolean, trackState: boolean, telemetryContext?: ITelemetryContext) =>
89
- this.summarizeInternal(fullTree, trackState, telemetryContext);
90
-
91
- this.summarizerNode = createSummarizerNode(
92
- thisSummarizeInternal,
93
- async (fullGC?: boolean) => this.getGCDataInternal(fullGC),
94
- async () => getBaseGCDetails(),
95
- );
96
-
97
- this.thresholdOpsCounter = new ThresholdCounter(
98
- RemoteChannelContext.pendingOpsCountThreshold,
99
- this.subLogger,
100
- );
101
- }
102
-
103
- // eslint-disable-next-line @typescript-eslint/promise-function-async
104
- public getChannel(): Promise<IChannel> {
105
- if (this.channelP === undefined) {
106
- this.channelP = this.loadChannel();
107
- }
108
-
109
- return this.channelP;
110
- }
111
-
112
- public setConnectionState(connected: boolean, clientId?: string) {
113
- // Connection events are ignored if the data store is not yet loaded
114
- if (!this.isLoaded) {
115
- return;
116
- }
117
-
118
- this.services.deltaConnection.setConnectionState(connected);
119
- }
120
-
121
- public applyStashedOp(message: ISequencedDocumentMessage): unknown {
122
- assert(this.isLoaded, 0x194 /* "Remote channel must be loaded when rebasing op" */);
123
- return this.services.deltaConnection.applyStashedOp(message);
124
- }
125
-
126
- public processOp(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void {
127
- this.summarizerNode.invalidate(message.sequenceNumber);
128
-
129
- if (this.isLoaded) {
130
- this.services.deltaConnection.process(message, local, localOpMetadata);
131
- } else {
132
- assert(!local, 0x195 /* "Remote channel must not be local when processing op" */);
133
- assert(this.pending !== undefined, 0x23e /* "pending is undefined" */);
134
- this.pending.push(message);
135
- this.thresholdOpsCounter.sendIfMultiple("StorePendingOps", this.pending.length);
136
- }
137
- }
138
-
139
- public reSubmit(content: any, localOpMetadata: unknown) {
140
- assert(this.isLoaded, 0x196 /* "Remote channel must be loaded when resubmitting op" */);
141
-
142
- this.services.deltaConnection.reSubmit(content, localOpMetadata);
143
- }
144
-
145
- public rollback(content: any, localOpMetadata: unknown) {
146
- assert(this.isLoaded, 0x2f0 /* "Remote channel must be loaded when rolling back op" */);
147
-
148
- this.services.deltaConnection.rollback(content, localOpMetadata);
149
- }
150
-
151
- /**
152
- * Returns a summary at the current sequence number.
153
- * @param fullTree - true to bypass optimizations and force a full summary tree
154
- * @param trackState - This tells whether we should track state from this summary.
155
- * @param telemetryContext - summary data passed through the layers for telemetry purposes
156
- */
157
- public async summarize(
158
- fullTree: boolean = false,
159
- trackState: boolean = true,
160
- telemetryContext?: ITelemetryContext,
161
- ): Promise<ISummarizeResult> {
162
- return this.summarizerNode.summarize(fullTree, trackState, telemetryContext);
163
- }
164
-
165
- private async summarizeInternal(
166
- fullTree: boolean,
167
- trackState: boolean,
168
- telemetryContext?: ITelemetryContext,
169
- ): Promise<ISummarizeInternalResult> {
170
- const channel = await this.getChannel();
171
- const summarizeResult = await summarizeChannelAsync(channel, fullTree, trackState, telemetryContext);
172
- return { ...summarizeResult, id: this.id };
173
- }
174
-
175
- private async loadChannel(): Promise<IChannel> {
176
- assert(!this.isLoaded, 0x197 /* "Remote channel must not already be loaded when loading" */);
177
-
178
- let attributes: IChannelAttributes | undefined;
179
- if (await this.services.objectStorage.contains(attributesBlobKey)) {
180
- attributes = await readAndParse<IChannelAttributes | undefined>(
181
- this.services.objectStorage,
182
- attributesBlobKey);
183
- }
184
-
185
- let factory: IChannelFactory | undefined;
186
- // this is a backward compatibility case where
187
- // the attach message doesn't include
188
- // the attributes. Since old attach messages
189
- // will not have attributes we need to keep
190
- // this as long as we support old attach messages
191
- if (attributes === undefined) {
192
- if (this.attachMessageType === undefined) {
193
- // TODO: dataStoreId may require a different tag from PackageData #7488
194
- throw new DataCorruptionError("channelTypeNotAvailable", {
195
- channelId: {
196
- value: this.id,
197
- tag: TelemetryDataTag.PackageData,
198
- },
199
- dataStoreId: {
200
- value: this.dataStoreContext.id,
201
- tag: TelemetryDataTag.PackageData,
202
- },
203
- dataStorePackagePath: this.dataStoreContext.packagePath.join("/"),
204
- });
205
- }
206
- factory = this.registry.get(this.attachMessageType);
207
- if (factory === undefined) {
208
- // TODO: dataStoreId may require a different tag from PackageData #7488
209
- throw new DataCorruptionError("channelFactoryNotRegisteredForAttachMessageType", {
210
- channelId: {
211
- value: this.id,
212
- tag: TelemetryDataTag.PackageData,
213
- },
214
- dataStoreId: {
215
- value: this.dataStoreContext.id,
216
- tag: TelemetryDataTag.PackageData,
217
- },
218
- dataStorePackagePath: this.dataStoreContext.packagePath.join("/"),
219
- channelFactoryType: this.attachMessageType,
220
- });
221
- }
222
- attributes = factory.attributes;
223
- } else {
224
- factory = this.registry.get(attributes.type);
225
- if (factory === undefined) {
226
- // TODO: dataStoreId may require a different tag from PackageData #7488
227
- throw new DataCorruptionError("channelFactoryNotRegisteredForGivenType", {
228
- channelId: {
229
- value: this.id,
230
- tag: TelemetryDataTag.PackageData,
231
- },
232
- dataStoreId: {
233
- value: this.dataStoreContext.id,
234
- tag: TelemetryDataTag.PackageData,
235
- },
236
- dataStorePackagePath: this.dataStoreContext.packagePath.join("/"),
237
- channelFactoryType: attributes.type,
238
- });
239
- }
240
- }
241
-
242
- // Compare snapshot version to collaborative object version
243
- if (attributes.snapshotFormatVersion !== undefined
244
- && attributes.snapshotFormatVersion !== factory.attributes.snapshotFormatVersion) {
245
- this.subLogger.sendTelemetryEvent(
246
- {
247
- eventName: "ChannelAttributesVersionMismatch",
248
- channelType: { value: attributes.type, tag: TelemetryDataTag.PackageData },
249
- channelSnapshotVersion: {
250
- value: `${attributes.snapshotFormatVersion}@${attributes.packageVersion}`,
251
- tag: TelemetryDataTag.PackageData,
252
- },
253
- channelCodeVersion: {
254
- value: `${factory.attributes.snapshotFormatVersion}@${factory.attributes.packageVersion}`,
255
- tag: TelemetryDataTag.PackageData,
256
- },
257
- },
258
- );
259
- }
260
-
261
- const channel = await factory.load(
262
- this.runtime,
263
- this.id,
264
- this.services,
265
- attributes);
266
-
267
- // Send all pending messages to the channel
268
- assert(this.pending !== undefined, 0x23f /* "pending undefined" */);
269
- for (const message of this.pending) {
270
- this.services.deltaConnection.process(message, false, undefined /* localOpMetadata */);
271
- }
272
- this.thresholdOpsCounter.send("ProcessPendingOps", this.pending.length);
273
-
274
- // Commit changes.
275
- this.channel = channel;
276
- this.pending = undefined;
277
- this.isLoaded = true;
278
-
279
- // Because have some await between we created the service and here, the connection state might have changed
280
- // and we don't propagate the connection state when we are not loaded. So we have to set it again here.
281
- this.services.deltaConnection.setConnectionState(this.dataStoreContext.connected);
282
- return this.channel;
283
- }
284
-
285
- /**
286
- * Returns the data used for garbage collection. This includes a list of GC nodes that represent this context.
287
- * Each node has a set of outbound routes to other GC nodes in the document.
288
- * If there is no new data in this context since the last summary, previous GC data is used.
289
- * If there is new data, the GC data is generated again (by calling getGCDataInternal).
290
- * @param fullGC - true to bypass optimizations and force full generation of GC data.
291
- */
292
- public async getGCData(fullGC: boolean = false): Promise<IGarbageCollectionData> {
293
- return this.summarizerNode.getGCData(fullGC);
294
- }
295
-
296
- /**
297
- * Generates the data used for garbage collection. This is called when there is new data since last summary. It
298
- * loads the context and calls into the channel to get its GC data.
299
- * @param fullGC - true to bypass optimizations and force full generation of GC data.
300
- */
301
- private async getGCDataInternal(fullGC: boolean = false): Promise<IGarbageCollectionData> {
302
- const channel = await this.getChannel();
303
- return channel.getGCData(fullGC);
304
- }
305
-
306
- public updateUsedRoutes(usedRoutes: string[], gcTimestamp?: number) {
307
- /**
308
- * Currently, DDSes are always considered referenced and are not garbage collected. Update the summarizer node's
309
- * used routes to contain a route to this channel context.
310
- * Once we have GC at DDS level, this will be updated to use the passed usedRoutes. See -
311
- * https://github.com/microsoft/FluidFramework/issues/4611
312
- */
313
- this.summarizerNode.updateUsedRoutes([""]);
314
- }
37
+ private isLoaded = false;
38
+ private pending: ISequencedDocumentMessage[] | undefined = [];
39
+ private readonly channelP: Promise<IChannel>;
40
+ private channel: IChannel | undefined;
41
+ private readonly services: ChannelServiceEndpoints;
42
+ private readonly summarizerNode: ISummarizerNodeWithGC;
43
+ private readonly subLogger: ITelemetryLoggerExt;
44
+ private readonly thresholdOpsCounter: ThresholdCounter;
45
+ private static readonly pendingOpsCountThreshold = 1000;
46
+
47
+ constructor(
48
+ runtime: IFluidDataStoreRuntime,
49
+ dataStoreContext: IFluidDataStoreContext,
50
+ storageService: IDocumentStorageService,
51
+ submitFn: (content: any, localOpMetadata: unknown) => void,
52
+ dirtyFn: (address: string) => void,
53
+ addedGCOutboundReferenceFn: (srcHandle: IFluidHandle, outboundHandle: IFluidHandle) => void,
54
+ private readonly id: string,
55
+ baseSnapshot: ISnapshotTree,
56
+ registry: ISharedObjectRegistry,
57
+ extraBlobs: Map<string, ArrayBufferLike> | undefined,
58
+ createSummarizerNode: CreateChildSummarizerNodeFn,
59
+ attachMessageType?: string,
60
+ ) {
61
+ assert(!this.id.includes("/"), 0x310 /* Channel context ID cannot contain slashes */);
62
+
63
+ this.subLogger = createChildLogger({
64
+ logger: runtime.logger,
65
+ namespace: "RemoteChannelContext",
66
+ });
67
+
68
+ this.services = createChannelServiceEndpoints(
69
+ dataStoreContext.connected,
70
+ submitFn,
71
+ () => dirtyFn(this.id),
72
+ addedGCOutboundReferenceFn,
73
+ storageService,
74
+ this.subLogger,
75
+ baseSnapshot,
76
+ extraBlobs,
77
+ );
78
+
79
+ this.channelP = new LazyPromise<IChannel>(async () => {
80
+ const { attributes, factory } = await loadChannelFactoryAndAttributes(
81
+ dataStoreContext,
82
+ this.services,
83
+ this.id,
84
+ registry,
85
+ attachMessageType,
86
+ );
87
+
88
+ const channel = await loadChannel(
89
+ runtime,
90
+ attributes,
91
+ factory,
92
+ this.services,
93
+ this.subLogger,
94
+ this.id,
95
+ );
96
+
97
+ // Send all pending messages to the channel
98
+ assert(this.pending !== undefined, 0x23f /* "pending undefined" */);
99
+ for (const message of this.pending) {
100
+ this.services.deltaConnection.process(
101
+ message,
102
+ false,
103
+ undefined /* localOpMetadata */,
104
+ );
105
+ }
106
+ this.thresholdOpsCounter.send("ProcessPendingOps", this.pending.length);
107
+
108
+ // Commit changes.
109
+ this.channel = channel;
110
+ this.pending = undefined;
111
+ this.isLoaded = true;
112
+
113
+ // Because have some await between we created the service and here, the connection state might have changed
114
+ // and we don't propagate the connection state when we are not loaded. So we have to set it again here.
115
+ this.services.deltaConnection.setConnectionState(dataStoreContext.connected);
116
+ return this.channel;
117
+ });
118
+
119
+ const thisSummarizeInternal = async (
120
+ fullTree: boolean,
121
+ trackState: boolean,
122
+ telemetryContext?: ITelemetryContext,
123
+ incrementalSummaryContext?: IExperimentalIncrementalSummaryContext,
124
+ ) =>
125
+ this.summarizeInternal(
126
+ fullTree,
127
+ trackState,
128
+ telemetryContext,
129
+ incrementalSummaryContext,
130
+ );
131
+
132
+ this.summarizerNode = createSummarizerNode(
133
+ thisSummarizeInternal,
134
+ async (fullGC?: boolean) => this.getGCDataInternal(fullGC),
135
+ );
136
+
137
+ this.thresholdOpsCounter = new ThresholdCounter(
138
+ RemoteChannelContext.pendingOpsCountThreshold,
139
+ this.subLogger,
140
+ );
141
+ }
142
+
143
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
144
+ public getChannel(): Promise<IChannel> {
145
+ return this.channelP;
146
+ }
147
+
148
+ public setConnectionState(connected: boolean, clientId?: string) {
149
+ // Connection events are ignored if the data store is not yet loaded
150
+ if (!this.isLoaded) {
151
+ return;
152
+ }
153
+
154
+ this.services.deltaConnection.setConnectionState(connected);
155
+ }
156
+
157
+ public applyStashedOp(content: any): unknown {
158
+ assert(this.isLoaded, 0x194 /* "Remote channel must be loaded when rebasing op" */);
159
+ return this.services.deltaConnection.applyStashedOp(content);
160
+ }
161
+
162
+ public processOp(
163
+ message: ISequencedDocumentMessage,
164
+ local: boolean,
165
+ localOpMetadata: unknown,
166
+ ): void {
167
+ this.summarizerNode.invalidate(message.sequenceNumber);
168
+
169
+ if (this.isLoaded) {
170
+ this.services.deltaConnection.process(message, local, localOpMetadata);
171
+ } else {
172
+ assert(!local, 0x195 /* "Remote channel must not be local when processing op" */);
173
+ assert(this.pending !== undefined, 0x23e /* "pending is undefined" */);
174
+ this.pending.push(message);
175
+ this.thresholdOpsCounter.sendIfMultiple("StorePendingOps", this.pending.length);
176
+ }
177
+ }
178
+
179
+ public reSubmit(content: any, localOpMetadata: unknown) {
180
+ assert(this.isLoaded, 0x196 /* "Remote channel must be loaded when resubmitting op" */);
181
+
182
+ this.services.deltaConnection.reSubmit(content, localOpMetadata);
183
+ }
184
+
185
+ public rollback(content: any, localOpMetadata: unknown) {
186
+ assert(this.isLoaded, 0x2f0 /* "Remote channel must be loaded when rolling back op" */);
187
+
188
+ this.services.deltaConnection.rollback(content, localOpMetadata);
189
+ }
190
+
191
+ /**
192
+ * Returns a summary at the current sequence number.
193
+ * @param fullTree - true to bypass optimizations and force a full summary tree
194
+ * @param trackState - This tells whether we should track state from this summary.
195
+ * @param telemetryContext - summary data passed through the layers for telemetry purposes
196
+ */
197
+ public async summarize(
198
+ fullTree: boolean = false,
199
+ trackState: boolean = true,
200
+ telemetryContext?: ITelemetryContext,
201
+ ): Promise<ISummarizeResult> {
202
+ return this.summarizerNode.summarize(fullTree, trackState, telemetryContext);
203
+ }
204
+
205
+ private async summarizeInternal(
206
+ fullTree: boolean,
207
+ trackState: boolean,
208
+ telemetryContext?: ITelemetryContext,
209
+ incrementalSummaryContext?: IExperimentalIncrementalSummaryContext,
210
+ ): Promise<ISummarizeInternalResult> {
211
+ const channel = await this.getChannel();
212
+ const summarizeResult = await summarizeChannelAsync(
213
+ channel,
214
+ fullTree,
215
+ trackState,
216
+ telemetryContext,
217
+ incrementalSummaryContext,
218
+ );
219
+ return { ...summarizeResult, id: this.id };
220
+ }
221
+
222
+ /**
223
+ * Returns the data used for garbage collection. This includes a list of GC nodes that represent this context.
224
+ * Each node has a set of outbound routes to other GC nodes in the document.
225
+ * If there is no new data in this context since the last summary, previous GC data is used.
226
+ * If there is new data, the GC data is generated again (by calling getGCDataInternal).
227
+ * @param fullGC - true to bypass optimizations and force full generation of GC data.
228
+ */
229
+ public async getGCData(fullGC: boolean = false): Promise<IGarbageCollectionData> {
230
+ return this.summarizerNode.getGCData(fullGC);
231
+ }
232
+
233
+ /**
234
+ * Generates the data used for garbage collection. This is called when there is new data since last summary. It
235
+ * loads the context and calls into the channel to get its GC data.
236
+ * @param fullGC - true to bypass optimizations and force full generation of GC data.
237
+ */
238
+ private async getGCDataInternal(fullGC: boolean = false): Promise<IGarbageCollectionData> {
239
+ const channel = await this.getChannel();
240
+ return channel.getGCData(fullGC);
241
+ }
242
+
243
+ public updateUsedRoutes(usedRoutes: string[]) {
244
+ /**
245
+ * Currently, DDSes are always considered referenced and are not garbage collected. Update the summarizer node's
246
+ * used routes to contain a route to this channel context.
247
+ * Once we have GC at DDS level, this will be updated to use the passed usedRoutes. See -
248
+ * https://github.com/microsoft/FluidFramework/issues/4611
249
+ */
250
+ this.summarizerNode.updateUsedRoutes([""]);
251
+ }
315
252
  }
@@ -0,0 +1,4 @@
1
+ {
2
+ "targets": [{ "extname": ".cjs", "module": "CommonJS", "moduleResolution": "Node16" }],
3
+ "projects": ["./tsconfig.json", "./src/test/tsconfig.json"]
4
+ }
package/tsconfig.json CHANGED
@@ -1,14 +1,12 @@
1
1
  {
2
- "extends": "@fluidframework/build-common/ts-common-config.json",
3
- "compilerOptions": {
4
- "composite": true,
5
- "rootDir": "./src",
6
- "outDir": "./dist"
7
- },
8
- "include": [
9
- "src/**/*"
10
- ],
11
- "exclude": [
12
- "src/test/**/*"
13
- ]
14
- }
2
+ "extends": [
3
+ "../../../common/build/build-common/tsconfig.base.json",
4
+ "../../../common/build/build-common/tsconfig.cjs.json",
5
+ ],
6
+ "include": ["src/**/*"],
7
+ "exclude": ["src/test/**/*"],
8
+ "compilerOptions": {
9
+ "rootDir": "./src",
10
+ "outDir": "./dist",
11
+ },
12
+ }
@@ -1,35 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
- * Licensed under the MIT License.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.summarizeChannelAsync = exports.summarizeChannel = exports.createServiceEndpoints = exports.attributesBlobKey = void 0;
8
- const runtime_utils_1 = require("@fluidframework/runtime-utils");
9
- const channelDeltaConnection_1 = require("./channelDeltaConnection");
10
- const channelStorageService_1 = require("./channelStorageService");
11
- exports.attributesBlobKey = ".attributes";
12
- function createServiceEndpoints(id, connected, submitFn, dirtyFn, addedGCOutboundReferenceFn, storageService, logger, tree, extraBlobs) {
13
- const deltaConnection = new channelDeltaConnection_1.ChannelDeltaConnection(id, connected, (message, localOpMetadata) => submitFn(message, localOpMetadata), dirtyFn, addedGCOutboundReferenceFn);
14
- const objectStorage = new channelStorageService_1.ChannelStorageService(tree, storageService, logger, extraBlobs);
15
- return {
16
- deltaConnection,
17
- objectStorage,
18
- };
19
- }
20
- exports.createServiceEndpoints = createServiceEndpoints;
21
- function summarizeChannel(channel, fullTree = false, trackState = false, telemetryContext) {
22
- const summarizeResult = channel.getAttachSummary(fullTree, trackState, telemetryContext);
23
- // Add the channel attributes to the returned result.
24
- (0, runtime_utils_1.addBlobToSummary)(summarizeResult, exports.attributesBlobKey, JSON.stringify(channel.attributes));
25
- return summarizeResult;
26
- }
27
- exports.summarizeChannel = summarizeChannel;
28
- async function summarizeChannelAsync(channel, fullTree = false, trackState = false, telemetryContext) {
29
- const summarizeResult = await channel.summarize(fullTree, trackState, telemetryContext);
30
- // Add the channel attributes to the returned result.
31
- (0, runtime_utils_1.addBlobToSummary)(summarizeResult, exports.attributesBlobKey, JSON.stringify(channel.attributes));
32
- return summarizeResult;
33
- }
34
- exports.summarizeChannelAsync = summarizeChannelAsync;
35
- //# sourceMappingURL=channelContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"channelContext.js","sourceRoot":"","sources":["../src/channelContext.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAaH,iEAAiE;AACjE,qEAAkE;AAClE,mEAAgE;AAEnD,QAAA,iBAAiB,GAAG,aAAa,CAAC;AAsC/C,SAAgB,sBAAsB,CAClC,EAAU,EACV,SAAkB,EAClB,QAA0D,EAC1D,OAAmB,EACnB,0BAA2F,EAC3F,cAAuC,EACvC,MAAwB,EACxB,IAAoB,EACpB,UAAyC;IAEzC,MAAM,eAAe,GAAG,IAAI,+CAAsB,CAC9C,EAAE,EACF,SAAS,EACT,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC,EAChE,OAAO,EACP,0BAA0B,CAAC,CAAC;IAChC,MAAM,aAAa,GAAG,IAAI,6CAAqB,CAAC,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAE1F,OAAO;QACH,eAAe;QACf,aAAa;KAChB,CAAC;AACN,CAAC;AAvBD,wDAuBC;AAED,SAAgB,gBAAgB,CAC5B,OAAiB,EACjB,WAAoB,KAAK,EACzB,aAAsB,KAAK,EAC3B,gBAAoC;IAEpC,MAAM,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC,QAAQ,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;IAEzF,qDAAqD;IACrD,IAAA,gCAAgB,EAAC,eAAe,EAAE,yBAAiB,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IACzF,OAAO,eAAe,CAAC;AAC3B,CAAC;AAXD,4CAWC;AAEM,KAAK,UAAU,qBAAqB,CACvC,OAAiB,EACjB,WAAoB,KAAK,EACzB,aAAsB,KAAK,EAC3B,gBAAoC;IAEpC,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;IAExF,qDAAqD;IACrD,IAAA,gCAAgB,EAAC,eAAe,EAAE,yBAAiB,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IACzF,OAAO,eAAe,CAAC;AAC3B,CAAC;AAXD,sDAWC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { IChannel } from \"@fluidframework/datastore-definitions\";\nimport { IDocumentStorageService } from \"@fluidframework/driver-definitions\";\nimport { ISequencedDocumentMessage, ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport {\n IGarbageCollectionData,\n ISummarizeResult,\n ISummaryTreeWithStats,\n ITelemetryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport { addBlobToSummary } from \"@fluidframework/runtime-utils\";\nimport { ChannelDeltaConnection } from \"./channelDeltaConnection\";\nimport { ChannelStorageService } from \"./channelStorageService\";\n\nexport const attributesBlobKey = \".attributes\";\n\nexport interface IChannelContext {\n getChannel(): Promise<IChannel>;\n\n setConnectionState(connected: boolean, clientId?: string);\n\n processOp(message: ISequencedDocumentMessage, local: boolean, localOpMetadata?: unknown): void;\n\n summarize(\n fullTree?: boolean,\n trackState?: boolean,\n telemetryContext?: ITelemetryContext,\n ): Promise<ISummarizeResult>;\n\n reSubmit(content: any, localOpMetadata: unknown): void;\n\n applyStashedOp(content: any): unknown;\n\n rollback(message: any, localOpMetadata: unknown): void;\n\n /**\n * Returns the data used for garbage collection. This includes a list of GC nodes that represent this context\n * including any of its children. Each node has a set of outbound routes to other GC nodes in the document.\n * @param fullGC - true to bypass optimizations and force full generation of GC data.\n */\n getGCData(fullGC?: boolean): Promise<IGarbageCollectionData>;\n\n /**\n * After GC has run, called to notify this context of routes that are used in it. These are used for the following:\n * 1. To identify if this context is being referenced in the document or not.\n * 2. To identify if this context or any of its children's used routes changed since last summary.\n * 3. They are added to the summary generated by this context.\n * 4. To update the timestamp when this context is marked as unreferenced.\n */\n updateUsedRoutes(usedRoutes: string[], gcTimestamp?: number): void;\n}\n\nexport function createServiceEndpoints(\n id: string,\n connected: boolean,\n submitFn: (content: any, localOpMetadata: unknown) => void,\n dirtyFn: () => void,\n addedGCOutboundReferenceFn: (srcHandle: IFluidHandle, outboundHandle: IFluidHandle) => void,\n storageService: IDocumentStorageService,\n logger: ITelemetryLogger,\n tree?: ISnapshotTree,\n extraBlobs?: Map<string, ArrayBufferLike>,\n) {\n const deltaConnection = new ChannelDeltaConnection(\n id,\n connected,\n (message, localOpMetadata) => submitFn(message, localOpMetadata),\n dirtyFn,\n addedGCOutboundReferenceFn);\n const objectStorage = new ChannelStorageService(tree, storageService, logger, extraBlobs);\n\n return {\n deltaConnection,\n objectStorage,\n };\n}\n\nexport function summarizeChannel(\n channel: IChannel,\n fullTree: boolean = false,\n trackState: boolean = false,\n telemetryContext?: ITelemetryContext,\n): ISummaryTreeWithStats {\n const summarizeResult = channel.getAttachSummary(fullTree, trackState, telemetryContext);\n\n // Add the channel attributes to the returned result.\n addBlobToSummary(summarizeResult, attributesBlobKey, JSON.stringify(channel.attributes));\n return summarizeResult;\n}\n\nexport async function summarizeChannelAsync(\n channel: IChannel,\n fullTree: boolean = false,\n trackState: boolean = false,\n telemetryContext?: ITelemetryContext,\n): Promise<ISummaryTreeWithStats> {\n const summarizeResult = await channel.summarize(fullTree, trackState, telemetryContext);\n\n // Add the channel attributes to the returned result.\n addBlobToSummary(summarizeResult, attributesBlobKey, JSON.stringify(channel.attributes));\n return summarizeResult;\n}\n"]}