@fluidframework/shared-object-base 1.4.0-115997 → 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 (144) hide show
  1. package/.eslintrc.js +5 -7
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +148 -0
  4. package/README.md +22 -1
  5. package/api-extractor-lint.json +4 -0
  6. package/api-extractor.json +2 -2
  7. package/api-report/shared-object-base.api.md +165 -0
  8. package/dist/{handle.js → handle.cjs} +13 -8
  9. package/dist/handle.cjs.map +1 -0
  10. package/dist/handle.d.ts +12 -7
  11. package/dist/handle.d.ts.map +1 -1
  12. package/dist/index.cjs +23 -0
  13. package/dist/index.cjs.map +1 -0
  14. package/dist/index.d.ts +6 -6
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/{packageVersion.js → packageVersion.cjs} +2 -2
  17. package/dist/packageVersion.cjs.map +1 -0
  18. package/dist/packageVersion.d.ts +1 -1
  19. package/dist/packageVersion.d.ts.map +1 -1
  20. package/dist/{remoteObjectHandle.js → remoteObjectHandle.cjs} +15 -20
  21. package/dist/remoteObjectHandle.cjs.map +1 -0
  22. package/dist/remoteObjectHandle.d.ts +1 -3
  23. package/dist/remoteObjectHandle.d.ts.map +1 -1
  24. package/dist/{serializer.js → serializer.cjs} +14 -12
  25. package/dist/serializer.cjs.map +1 -0
  26. package/dist/serializer.d.ts +8 -0
  27. package/dist/serializer.d.ts.map +1 -1
  28. package/dist/shared-object-base-alpha.d.ts +415 -0
  29. package/dist/shared-object-base-beta.d.ts +393 -0
  30. package/dist/shared-object-base-public.d.ts +393 -0
  31. package/dist/shared-object-base-untrimmed.d.ts +506 -0
  32. package/dist/{sharedObject.js → sharedObject.cjs} +71 -56
  33. package/dist/sharedObject.cjs.map +1 -0
  34. package/dist/sharedObject.d.ts +10 -13
  35. package/dist/sharedObject.d.ts.map +1 -1
  36. package/dist/{summarySerializer.js → summarySerializer.cjs} +3 -2
  37. package/dist/summarySerializer.cjs.map +1 -0
  38. package/dist/summarySerializer.d.ts +1 -0
  39. package/dist/summarySerializer.d.ts.map +1 -1
  40. package/dist/tsdoc-metadata.json +11 -0
  41. package/dist/{types.js → types.cjs} +1 -1
  42. package/dist/types.cjs.map +1 -0
  43. package/dist/types.d.ts +24 -2
  44. package/dist/types.d.ts.map +1 -1
  45. package/dist/{utils.js → utils.cjs} +6 -4
  46. package/dist/utils.cjs.map +1 -0
  47. package/dist/utils.d.ts +4 -0
  48. package/dist/utils.d.ts.map +1 -1
  49. package/dist/{valueType.js → valueType.cjs} +3 -2
  50. package/dist/valueType.cjs.map +1 -0
  51. package/dist/valueType.d.ts +1 -0
  52. package/dist/valueType.d.ts.map +1 -1
  53. package/lib/{handle.d.ts → handle.d.mts} +13 -8
  54. package/lib/handle.d.mts.map +1 -0
  55. package/lib/{handle.js → handle.mjs} +13 -8
  56. package/lib/handle.mjs.map +1 -0
  57. package/lib/index.d.mts +11 -0
  58. package/lib/index.d.mts.map +1 -0
  59. package/lib/index.mjs +10 -0
  60. package/lib/index.mjs.map +1 -0
  61. package/lib/{packageVersion.d.ts → packageVersion.d.mts} +1 -1
  62. package/lib/{packageVersion.d.ts.map → packageVersion.d.mts.map} +1 -1
  63. package/lib/{packageVersion.js → packageVersion.mjs} +2 -2
  64. package/lib/packageVersion.mjs.map +1 -0
  65. package/lib/{remoteObjectHandle.d.ts → remoteObjectHandle.d.mts} +1 -3
  66. package/lib/remoteObjectHandle.d.mts.map +1 -0
  67. package/lib/{remoteObjectHandle.js → remoteObjectHandle.mjs} +15 -20
  68. package/lib/remoteObjectHandle.mjs.map +1 -0
  69. package/lib/{serializer.d.ts → serializer.d.mts} +8 -0
  70. package/lib/serializer.d.mts.map +1 -0
  71. package/lib/{serializer.js → serializer.mjs} +14 -14
  72. package/lib/serializer.mjs.map +1 -0
  73. package/lib/shared-object-base-alpha.d.mts +415 -0
  74. package/lib/shared-object-base-beta.d.mts +393 -0
  75. package/lib/shared-object-base-public.d.mts +393 -0
  76. package/lib/shared-object-base-untrimmed.d.mts +506 -0
  77. package/lib/{sharedObject.d.ts → sharedObject.d.mts} +12 -15
  78. package/lib/sharedObject.d.mts.map +1 -0
  79. package/lib/{sharedObject.js → sharedObject.mjs} +66 -51
  80. package/lib/sharedObject.mjs.map +1 -0
  81. package/lib/{summarySerializer.d.ts → summarySerializer.d.mts} +2 -1
  82. package/lib/summarySerializer.d.mts.map +1 -0
  83. package/lib/{summarySerializer.js → summarySerializer.mjs} +3 -2
  84. package/lib/summarySerializer.mjs.map +1 -0
  85. package/lib/{types.d.ts → types.d.mts} +24 -2
  86. package/lib/types.d.mts.map +1 -0
  87. package/lib/{types.js → types.mjs} +1 -1
  88. package/lib/types.mjs.map +1 -0
  89. package/lib/{utils.d.ts → utils.d.mts} +5 -1
  90. package/lib/utils.d.mts.map +1 -0
  91. package/lib/{utils.js → utils.mjs} +6 -4
  92. package/lib/utils.mjs.map +1 -0
  93. package/lib/{valueType.d.ts → valueType.d.mts} +1 -0
  94. package/lib/{valueType.d.ts.map → valueType.d.mts.map} +1 -1
  95. package/lib/{valueType.js → valueType.mjs} +2 -1
  96. package/lib/valueType.mjs.map +1 -0
  97. package/package.json +102 -69
  98. package/prettier.config.cjs +8 -0
  99. package/src/handle.ts +38 -36
  100. package/src/index.ts +16 -6
  101. package/src/packageVersion.ts +1 -1
  102. package/src/remoteObjectHandle.ts +53 -58
  103. package/src/serializer.ts +190 -187
  104. package/src/sharedObject.ts +718 -642
  105. package/src/summarySerializer.ts +9 -8
  106. package/src/types.ts +56 -15
  107. package/src/utils.ts +24 -26
  108. package/src/valueType.ts +10 -9
  109. package/tsc-multi.test.json +4 -0
  110. package/tsconfig.json +10 -12
  111. package/bench/src/index.ts +0 -68
  112. package/bench/src/util.ts +0 -56
  113. package/dist/handle.js.map +0 -1
  114. package/dist/index.js +0 -23
  115. package/dist/index.js.map +0 -1
  116. package/dist/packageVersion.js.map +0 -1
  117. package/dist/remoteObjectHandle.js.map +0 -1
  118. package/dist/serializer.js.map +0 -1
  119. package/dist/sharedObject.js.map +0 -1
  120. package/dist/summarySerializer.js.map +0 -1
  121. package/dist/types.js.map +0 -1
  122. package/dist/utils.js.map +0 -1
  123. package/dist/valueType.js.map +0 -1
  124. package/lib/handle.d.ts.map +0 -1
  125. package/lib/handle.js.map +0 -1
  126. package/lib/index.d.ts +0 -11
  127. package/lib/index.d.ts.map +0 -1
  128. package/lib/index.js +0 -11
  129. package/lib/index.js.map +0 -1
  130. package/lib/packageVersion.js.map +0 -1
  131. package/lib/remoteObjectHandle.d.ts.map +0 -1
  132. package/lib/remoteObjectHandle.js.map +0 -1
  133. package/lib/serializer.d.ts.map +0 -1
  134. package/lib/serializer.js.map +0 -1
  135. package/lib/sharedObject.d.ts.map +0 -1
  136. package/lib/sharedObject.js.map +0 -1
  137. package/lib/summarySerializer.d.ts.map +0 -1
  138. package/lib/summarySerializer.js.map +0 -1
  139. package/lib/types.d.ts.map +0 -1
  140. package/lib/types.js.map +0 -1
  141. package/lib/utils.d.ts.map +0 -1
  142. package/lib/utils.js.map +0 -1
  143. package/lib/valueType.js.map +0 -1
  144. package/tsconfig.esnext.json +0 -7
@@ -0,0 +1,506 @@
1
+ import { EventEmitterEventType } from '@fluid-internal/client-utils';
2
+ import { EventEmitterWithErrorHandling } from '@fluidframework/telemetry-utils';
3
+ import { IChannel } from '@fluidframework/datastore-definitions';
4
+ import { IChannelAttributes } from '@fluidframework/datastore-definitions';
5
+ import { IChannelServices } from '@fluidframework/datastore-definitions';
6
+ import { IChannelStorageService } from '@fluidframework/datastore-definitions';
7
+ import { IErrorEvent } from '@fluidframework/core-interfaces';
8
+ import { IEventProvider } from '@fluidframework/core-interfaces';
9
+ import { IEventThisPlaceHolder } from '@fluidframework/core-interfaces';
10
+ import { IExperimentalIncrementalSummaryContext } from '@fluidframework/runtime-definitions';
11
+ import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
12
+ import { IFluidHandle } from '@fluidframework/core-interfaces';
13
+ import { IFluidHandleContext } from '@fluidframework/core-interfaces';
14
+ import { IGarbageCollectionData } from '@fluidframework/runtime-definitions';
15
+ import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
16
+ import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
17
+ import { ITelemetryContext } from '@fluidframework/runtime-definitions';
18
+ import { ITelemetryLoggerExt } from '@fluidframework/telemetry-utils';
19
+
20
+ /**
21
+ * Create a new summary containing one blob
22
+ * @param key - the key for the blob in the summary
23
+ * @param content - blob content
24
+ * @returns The summary containing the blob
25
+ * @internal
26
+ */
27
+ export declare function createSingleBlobSummary(key: string, content: string | Uint8Array): ISummaryTreeWithStats;
28
+
29
+ /**
30
+ * Data Store serializer implementation
31
+ * @internal
32
+ */
33
+ export declare class FluidSerializer implements IFluidSerializer {
34
+ private readonly context;
35
+ private readonly handleParsedCb;
36
+ private readonly root;
37
+ constructor(context: IFluidHandleContext, handleParsedCb: (handle: IFluidHandle) => void);
38
+ get IFluidSerializer(): this;
39
+ /**
40
+ * Given a mostly-jsonable object tree that may have handle objects embedded within, will return a
41
+ * fully-jsonable object tree where any embedded IFluidHandles have been replaced with a serializable form.
42
+ *
43
+ * The original `input` object is not mutated. This method will shallowly clone all objects in the path from
44
+ * the root to any replaced handles. (If no handles are found, returns the original object.)
45
+ *
46
+ * Any unbound handles encountered are bound to the provided IFluidHandle.
47
+ */
48
+ encode(input: any, bind: IFluidHandle): any;
49
+ /**
50
+ * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an
51
+ * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.
52
+ *
53
+ * The original `input` object is not mutated. This method will shallowly clone all objects in the path from
54
+ * the root to any replaced handles. (If no handles are found, returns the original object.)
55
+ *
56
+ * The decoded handles are implicitly bound to the handle context of this serializer.
57
+ */
58
+ decode(input: any): any;
59
+ stringify(input: any, bind: IFluidHandle): string;
60
+ parse(input: string): any;
61
+ private readonly encodeValue;
62
+ private readonly decodeValue;
63
+ private recursivelyReplace;
64
+ protected serializeHandle(handle: IFluidHandle, bind: IFluidHandle): {
65
+ type: string;
66
+ url: string;
67
+ };
68
+ }
69
+
70
+ /**
71
+ * @public
72
+ */
73
+ export declare interface IFluidSerializer {
74
+ /**
75
+ * Given a mostly-plain object that may have handle objects embedded within, will return a fully-plain object
76
+ * where any embedded IFluidHandles have been replaced with a serializable form.
77
+ *
78
+ * The original `input` object is not mutated. This method will shallowly clones all objects in the path from
79
+ * the root to any replaced handles. (If no handles are found, returns the original object.)
80
+ */
81
+ encode(value: any, bind: IFluidHandle): any;
82
+ /**
83
+ * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an
84
+ * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.
85
+ *
86
+ * The original `input` object is not mutated. This method will shallowly clone all objects in the path from
87
+ * the root to any replaced handles. (If no handles are found, returns the original object.)
88
+ *
89
+ * The decoded handles are implicitly bound to the handle context of this serializer.
90
+ */
91
+ decode(input: any): any;
92
+ /**
93
+ * Stringifies a given value. Converts any IFluidHandle to its stringified equivalent.
94
+ */
95
+ stringify(value: any, bind: IFluidHandle): string;
96
+ /**
97
+ * Parses the given JSON input string and returns the JavaScript object defined by it. Any Fluid
98
+ * handles will be realized as part of the parse
99
+ */
100
+ parse(value: string): any;
101
+ }
102
+
103
+ /**
104
+ * JSON serialized form of an IFluidHandle
105
+ * @internal
106
+ */
107
+ export declare interface ISerializedHandle {
108
+ type: "__fluid_handle__";
109
+ url: string;
110
+ }
111
+
112
+ /**
113
+ * Base interface for shared objects from which other interfaces derive. Implemented by SharedObject
114
+ * @public
115
+ */
116
+ export declare interface ISharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents> extends IChannel, IEventProvider<TEvent> {
117
+ /**
118
+ * Binds the given shared object to its containing data store runtime, causing it to attach once
119
+ * the runtime attaches.
120
+ */
121
+ bindToContext(): void;
122
+ /**
123
+ * Returns the GC data for this shared object. It contains a list of GC nodes that contains references to
124
+ * other GC nodes.
125
+ * @param fullGC - true to bypass optimizations and force full generation of GC data.
126
+ */
127
+ getGCData(fullGC?: boolean): IGarbageCollectionData;
128
+ }
129
+
130
+ /**
131
+ * Events emitted by {@link ISharedObject}.
132
+ * @public
133
+ */
134
+ export declare interface ISharedObjectEvents extends IErrorEvent {
135
+ /**
136
+ * Fires before an incoming operation (op) is applied to the shared object.
137
+ *
138
+ * @remarks Note: this should be considered an internal implementation detail. It is not recommended for external
139
+ * use.
140
+ *
141
+ * @eventProperty
142
+ */
143
+ (event: "pre-op", listener: (op: ISequencedDocumentMessage, local: boolean, target: IEventThisPlaceHolder) => void): any;
144
+ /**
145
+ * Fires after an incoming op is applied to the shared object.
146
+ *
147
+ * @remarks Note: this should be considered an internal implementation detail. It is not recommended for external
148
+ * use.
149
+ *
150
+ * @eventProperty
151
+ */
152
+ (event: "op", listener: (op: ISequencedDocumentMessage, local: boolean, target: IEventThisPlaceHolder) => void): any;
153
+ }
154
+
155
+ /**
156
+ * @internal
157
+ */
158
+ export declare const isSerializedHandle: (value: any) => value is ISerializedHandle;
159
+
160
+ /**
161
+ * Given a mostly-plain object that may have handle objects embedded within, will return a fully-plain object
162
+ * where any embedded IFluidHandles have been replaced with a serializable form.
163
+ *
164
+ * The original `input` object is not mutated. This method will shallowly clones all objects in the path from
165
+ * the root to any replaced handles. (If no handles are found, returns the original object.)
166
+ *
167
+ * @param input - The mostly-plain object
168
+ * @param context - The handle context for the container
169
+ * @param bind - Bind any other handles we find in the object against this given handle.
170
+ * @returns The fully-plain object
171
+ * @alpha
172
+ */
173
+ export declare function makeHandlesSerializable(value: any, serializer: IFluidSerializer, bind: IFluidHandle): any;
174
+
175
+ /**
176
+ * Given a fully-plain object that may have serializable-form handles within, will return the mostly-plain object
177
+ * with handle objects created instead.
178
+ * @param value - The fully-plain object
179
+ * @param serializer - The serializer that knows how to convert serializable-form handles into handle objects
180
+ * @param context - The handle context for the container
181
+ * @returns The mostly-plain object with handle objects within
182
+ * @alpha
183
+ */
184
+ export declare function parseHandles(value: any, serializer: IFluidSerializer): any;
185
+
186
+ /**
187
+ * Given a mostly-plain object that may have handle objects embedded within, return a string representation of an object
188
+ * where the handle objects have been replaced with a serializable form.
189
+ * @param value - The mostly-plain object
190
+ * @param serializer - The serializer that knows how to convert handles into serializable format
191
+ * @param context - The handle context for the container
192
+ * @param bind - Bind any other handles we find in the object against this given handle.
193
+ * @returns Result of strigifying an object
194
+ * @internal
195
+ */
196
+ export declare function serializeHandles(value: any, serializer: IFluidSerializer, bind: IFluidHandle): string | undefined;
197
+
198
+ /**
199
+ * SharedObject with simplified, synchronous summarization and GC.
200
+ * DDS implementations with async and incremental summarization should extend SharedObjectCore directly instead.
201
+ * @public
202
+ */
203
+ export declare abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents> extends SharedObjectCore<TEvent> {
204
+ private readonly telemetryContextPrefix;
205
+ /**
206
+ * True while we are garbage collecting this object's data.
207
+ */
208
+ private _isGCing;
209
+ /**
210
+ * The serializer to use to serialize / parse handles, if any.
211
+ */
212
+ private readonly _serializer;
213
+ protected get serializer(): IFluidSerializer;
214
+ /**
215
+ * @param id - The id of the shared object
216
+ * @param runtime - The IFluidDataStoreRuntime which contains the shared object
217
+ * @param attributes - Attributes of the shared object
218
+ */
219
+ constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes, telemetryContextPrefix: string);
220
+ /**
221
+ * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}
222
+ */
223
+ getAttachSummary(fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext): ISummaryTreeWithStats;
224
+ /**
225
+ * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}
226
+ */
227
+ summarize(fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext, incrementalSummaryContext?: IExperimentalIncrementalSummaryContext): Promise<ISummaryTreeWithStats>;
228
+ /**
229
+ * {@inheritDoc (ISharedObject:interface).getGCData}
230
+ */
231
+ getGCData(fullGC?: boolean): IGarbageCollectionData;
232
+ /**
233
+ * Calls the serializer over all data in this object that reference other GC nodes.
234
+ * Derived classes must override this to provide custom list of references to other GC nodes.
235
+ */
236
+ protected processGCDataCore(serializer: IFluidSerializer): void;
237
+ /**
238
+ * Gets a form of the object that can be serialized.
239
+ * @returns A tree representing the snapshot of the shared object.
240
+ */
241
+ protected abstract summarizeCore(serializer: IFluidSerializer, telemetryContext?: ITelemetryContext, incrementalSummaryContext?: IExperimentalIncrementalSummaryContext): ISummaryTreeWithStats;
242
+ private incrementTelemetryMetric;
243
+ }
244
+
245
+ /**
246
+ * Base class from which all shared objects derive.
247
+ * @public
248
+ */
249
+ export declare abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISharedObjectEvents> extends EventEmitterWithErrorHandling<TEvent> implements ISharedObject<TEvent> {
250
+ id: string;
251
+ protected runtime: IFluidDataStoreRuntime;
252
+ readonly attributes: IChannelAttributes;
253
+ get IFluidLoadable(): this;
254
+ private readonly opProcessingHelper;
255
+ private readonly callbacksHelper;
256
+ /**
257
+ * The handle referring to this SharedObject
258
+ */
259
+ readonly handle: IFluidHandle;
260
+ /**
261
+ * Telemetry logger for the shared object
262
+ */
263
+ protected readonly logger: ITelemetryLoggerExt;
264
+ private readonly mc;
265
+ /**
266
+ * Connection state
267
+ */
268
+ private _connected;
269
+ /**
270
+ * Services used by the shared object
271
+ */
272
+ private services;
273
+ /**
274
+ * True if the dds is bound to its parent.
275
+ */
276
+ private _isBoundToContext;
277
+ /**
278
+ * Tracks error that closed this object.
279
+ */
280
+ private closeError?;
281
+ /**
282
+ * Gets the connection state
283
+ * @returns The state of the connection
284
+ */
285
+ get connected(): boolean;
286
+ /**
287
+ * @param id - The id of the shared object
288
+ * @param runtime - The IFluidDataStoreRuntime which contains the shared object
289
+ * @param attributes - Attributes of the shared object
290
+ */
291
+ constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
292
+ /**
293
+ * This function is only supposed to be called from SharedObjectCore's constructor and
294
+ * depends on a few things being set already. assert() calls make sure of it.
295
+ * @returns The telemetry sampling helpers, so the constructor can be the one to assign them
296
+ * to variables to avoid complaints from TypeScript.
297
+ */
298
+ private setUpSampledTelemetryHelpers;
299
+ /**
300
+ * Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)
301
+ * would result in same error thrown. If called multiple times, only first error is remembered.
302
+ * @param error - error object that is thrown whenever an attempt is made to modify this object
303
+ */
304
+ private closeWithError;
305
+ /**
306
+ * Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.
307
+ */
308
+ private verifyNotClosed;
309
+ /**
310
+ * Event listener handler helper that can be used to react to exceptions thrown from event listeners
311
+ * It wraps error with DataProcessingError, closes this object and throws resulting error.
312
+ * See closeWithError() for more details
313
+ * Ideally such situation never happens, as consumers of DDS should never throw exceptions
314
+ * in event listeners (i.e. catch any of the issues and make determination on how to handle it).
315
+ * When such exceptions propagate through, most likely data model is no longer consistent, i.e.
316
+ * DDS state does not match what user sees. Because of it DDS moves to "corrupted state" and does not
317
+ * allow processing of ops or local changes, which very quickly results in container closure.
318
+ */
319
+ private eventListenerErrorHandler;
320
+ private attachListeners;
321
+ /**
322
+ * A shared object, after construction, can either be loaded in the case that it is already part of
323
+ * a shared document. Or later attached if it is being newly added.
324
+ * @param services - Services used by the shared object
325
+ */
326
+ load(services: IChannelServices): Promise<void>;
327
+ /**
328
+ * Initializes the object as a local, non-shared object. This object can become shared after
329
+ * it is attached to the document.
330
+ */
331
+ initializeLocal(): void;
332
+ /**
333
+ * {@inheritDoc (ISharedObject:interface).bindToContext}
334
+ */
335
+ bindToContext(): void;
336
+ /**
337
+ * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).connect}
338
+ */
339
+ connect(services: IChannelServices): void;
340
+ /**
341
+ * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).isAttached}
342
+ */
343
+ isAttached(): boolean;
344
+ /**
345
+ * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}
346
+ */
347
+ abstract getAttachSummary(fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext): ISummaryTreeWithStats;
348
+ /**
349
+ * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}
350
+ */
351
+ abstract summarize(fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext): Promise<ISummaryTreeWithStats>;
352
+ /**
353
+ * {@inheritDoc (ISharedObject:interface).getGCData}
354
+ */
355
+ abstract getGCData(fullGC?: boolean): IGarbageCollectionData;
356
+ /**
357
+ * Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference
358
+ * to another object in the container.
359
+ * @param decodedHandle - The handle of the Fluid object that is decoded.
360
+ */
361
+ protected handleDecoded(decodedHandle: IFluidHandle): void;
362
+ /**
363
+ * Allows the distributed data type to perform custom loading
364
+ * @param services - Storage used by the shared object
365
+ */
366
+ protected abstract loadCore(services: IChannelStorageService): Promise<void>;
367
+ /**
368
+ * Allows the distributed data type to perform custom local loading.
369
+ */
370
+ protected initializeLocalCore(): void;
371
+ /**
372
+ * Allows the distributive data type the ability to perform custom processing once an attach has happened.
373
+ * Also called after non-local data type get loaded.
374
+ */
375
+ protected didAttach(): void;
376
+ /**
377
+ * Derived classes must override this to do custom processing on a remote message.
378
+ * @param message - The message to process
379
+ * @param local - True if the shared object is local
380
+ * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
381
+ * For messages from a remote client, this will be undefined.
382
+ */
383
+ protected abstract processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): any;
384
+ /**
385
+ * Called when the object has disconnected from the delta stream.
386
+ */
387
+ protected abstract onDisconnect(): any;
388
+ /**
389
+ * Submits a message by the local client to the runtime.
390
+ * @param content - Content of the message
391
+ * @param localOpMetadata - The local metadata associated with the message. This is kept locally by the runtime
392
+ * and not sent to the server. This will be sent back when this message is received back from the server. This is
393
+ * also sent if we are asked to resubmit the message.
394
+ */
395
+ protected submitLocalMessage(content: any, localOpMetadata?: unknown): void;
396
+ /**
397
+ * Marks this object as dirty so that it is part of the next summary. It is called by a SharedSummaryBlock
398
+ * that want to be part of summary but does not generate ops.
399
+ */
400
+ protected dirty(): void;
401
+ /**
402
+ * Called when the object has fully connected to the delta stream
403
+ * Default implementation for DDS, override if different behavior is required.
404
+ */
405
+ protected onConnect(): void;
406
+ /**
407
+ * Called when a message has to be resubmitted. This typically happens after a reconnection for unacked messages.
408
+ * The default implementation here is to resubmit the same message. The client can override if different behavior
409
+ * is required. It can choose to resubmit the same message, submit different / multiple messages or not submit
410
+ * anything at all.
411
+ * @param content - The content of the original message.
412
+ * @param localOpMetadata - The local metadata associated with the original message.
413
+ */
414
+ protected reSubmitCore(content: any, localOpMetadata: unknown): void;
415
+ /**
416
+ * Promises that are waiting for an ack from the server before resolving should use this instead of new Promise.
417
+ * It ensures that if something changes that will interrupt that ack (e.g. the FluidDataStoreRuntime disposes),
418
+ * the Promise will reject.
419
+ * If runtime is disposed when this call is made, executor is not run and promise is rejected right away.
420
+ */
421
+ protected newAckBasedPromise<T>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
422
+ private attachDeltaHandler;
423
+ /**
424
+ * Set the state of connection to services.
425
+ * @param connected - true if connected, false otherwise.
426
+ */
427
+ private setConnectionState;
428
+ /**
429
+ * Handles a message being received from the remote delta server.
430
+ * @param message - The message to process
431
+ * @param local - Whether the message originated from the local client
432
+ * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
433
+ * For messages from a remote client, this will be undefined.
434
+ */
435
+ private process;
436
+ /**
437
+ * Called when a message has to be resubmitted. This typically happens for unacked messages after a
438
+ * reconnection.
439
+ * @param content - The content of the original message.
440
+ * @param localOpMetadata - The local metadata associated with the original message.
441
+ */
442
+ private reSubmit;
443
+ /**
444
+ * Revert an op
445
+ */
446
+ protected rollback(content: any, localOpMetadata: unknown): void;
447
+ /**
448
+ * Apply changes from an op. Used when rehydrating an attached container
449
+ * with pending changes. This prepares the SharedObject for seeing an ACK
450
+ * for the op or resubmitting the op upon reconnection.
451
+ * @param content - Contents of a stashed op.
452
+ * @returns localMetadata of the op, to be passed to process() or resubmit()
453
+ * when the op is ACKed or resubmitted, respectively
454
+ */
455
+ protected abstract applyStashedOp(content: any): unknown;
456
+ /**
457
+ * Emit an event. This function is only intended for use by DDS classes that extend SharedObject/SharedObjectCore,
458
+ * specifically to emit events that are part of the public interface of the DDS (i.e. those that can have listeners
459
+ * attached to them by the consumers of the DDS). It should not be called from outside the class or to emit events
460
+ * which are only internal to the DDS. Support for calling it from outside the DDS instance might be removed in the
461
+ * future.
462
+ * @param event - The event to emit.
463
+ * @param args - Arguments to pass to the event listeners.
464
+ * @returns `true` if the event had listeners, `false` otherwise.
465
+ */
466
+ emit(event: EventEmitterEventType, ...args: any[]): boolean;
467
+ /**
468
+ * Use to emit events inside {@link SharedObjectCore}, with no telemetry measurement
469
+ * done on the duration of the callbacks. Simply calls `super.emit()`.
470
+ * @param event - Event to emit
471
+ * @param args - Arguments for the event
472
+ * @returns Whatever `super.emit()` returns.
473
+ */
474
+ private emitInternal;
475
+ }
476
+
477
+ /**
478
+ * Serializer implementation for serializing handles during summary.
479
+ * @internal
480
+ */
481
+ export declare class SummarySerializer extends FluidSerializer {
482
+ private readonly serializedRoutes;
483
+ getSerializedRoutes(): string[];
484
+ protected serializeHandle(handle: IFluidHandle, bind: IFluidHandle): {
485
+ type: string;
486
+ url: string;
487
+ };
488
+ }
489
+
490
+ /**
491
+ * enum representing the possible types of a shared object
492
+ * @internal
493
+ */
494
+ export declare enum ValueType {
495
+ /**
496
+ * The value is a shared object
497
+ * @deprecated Instead store the handle of the shared object, rather than the shared object itself.
498
+ */
499
+ Shared = 0,
500
+ /**
501
+ * The value is a plain JavaScript object or handle. If a plain object, it may contain handles deeper within.
502
+ */
503
+ Plain = 1
504
+ }
505
+
506
+ export { }
@@ -2,18 +2,17 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { ITelemetryLogger } from "@fluidframework/common-definitions";
6
- import { EventEmitterEventType } from "@fluidframework/common-utils";
7
5
  import { IFluidHandle } from "@fluidframework/core-interfaces";
6
+ import { ITelemetryLoggerExt, EventEmitterWithErrorHandling } from "@fluidframework/telemetry-utils";
7
+ import { EventEmitterEventType } from "@fluid-internal/client-utils";
8
8
  import { IChannelAttributes, IFluidDataStoreRuntime, IChannelStorageService, IChannelServices } from "@fluidframework/datastore-definitions";
9
9
  import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
10
- import { IGarbageCollectionData, ISummaryTreeWithStats, ITelemetryContext } from "@fluidframework/runtime-definitions";
11
- import { EventEmitterWithErrorHandling } from "@fluidframework/telemetry-utils";
12
- import { IFluidSerializer } from "./serializer";
13
- import { SummarySerializer } from "./summarySerializer";
14
- import { ISharedObject, ISharedObjectEvents } from "./types";
10
+ import { IGarbageCollectionData, ISummaryTreeWithStats, ITelemetryContext, IExperimentalIncrementalSummaryContext } from "@fluidframework/runtime-definitions";
11
+ import { IFluidSerializer } from "./serializer.mjs";
12
+ import { ISharedObject, ISharedObjectEvents } from "./types.mjs";
15
13
  /**
16
- * Base class from which all shared objects derive
14
+ * Base class from which all shared objects derive.
15
+ * @public
17
16
  */
18
17
  export declare abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISharedObjectEvents> extends EventEmitterWithErrorHandling<TEvent> implements ISharedObject<TEvent> {
19
18
  id: string;
@@ -29,7 +28,7 @@ export declare abstract class SharedObjectCore<TEvent extends ISharedObjectEvent
29
28
  /**
30
29
  * Telemetry logger for the shared object
31
30
  */
32
- protected readonly logger: ITelemetryLogger;
31
+ protected readonly logger: ITelemetryLoggerExt;
33
32
  private readonly mc;
34
33
  /**
35
34
  * Connection state
@@ -228,9 +227,6 @@ export declare abstract class SharedObjectCore<TEvent extends ISharedObjectEvent
228
227
  * attached to them by the consumers of the DDS). It should not be called from outside the class or to emit events
229
228
  * which are only internal to the DDS. Support for calling it from outside the DDS instance might be removed in the
230
229
  * future.
231
- *
232
- * @internal
233
- *
234
230
  * @param event - The event to emit.
235
231
  * @param args - Arguments to pass to the event listeners.
236
232
  * @returns `true` if the event had listeners, `false` otherwise.
@@ -248,6 +244,7 @@ export declare abstract class SharedObjectCore<TEvent extends ISharedObjectEvent
248
244
  /**
249
245
  * SharedObject with simplified, synchronous summarization and GC.
250
246
  * DDS implementations with async and incremental summarization should extend SharedObjectCore directly instead.
247
+ * @public
251
248
  */
252
249
  export declare abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents> extends SharedObjectCore<TEvent> {
253
250
  private readonly telemetryContextPrefix;
@@ -273,7 +270,7 @@ export declare abstract class SharedObject<TEvent extends ISharedObjectEvents =
273
270
  /**
274
271
  * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}
275
272
  */
276
- summarize(fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext): Promise<ISummaryTreeWithStats>;
273
+ summarize(fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext, incrementalSummaryContext?: IExperimentalIncrementalSummaryContext): Promise<ISummaryTreeWithStats>;
277
274
  /**
278
275
  * {@inheritDoc (ISharedObject:interface).getGCData}
279
276
  */
@@ -282,12 +279,12 @@ export declare abstract class SharedObject<TEvent extends ISharedObjectEvents =
282
279
  * Calls the serializer over all data in this object that reference other GC nodes.
283
280
  * Derived classes must override this to provide custom list of references to other GC nodes.
284
281
  */
285
- protected processGCDataCore(serializer: SummarySerializer): void;
282
+ protected processGCDataCore(serializer: IFluidSerializer): void;
286
283
  /**
287
284
  * Gets a form of the object that can be serialized.
288
285
  * @returns A tree representing the snapshot of the shared object.
289
286
  */
290
- protected abstract summarizeCore(serializer: IFluidSerializer, telemetryContext?: ITelemetryContext): ISummaryTreeWithStats;
287
+ protected abstract summarizeCore(serializer: IFluidSerializer, telemetryContext?: ITelemetryContext, incrementalSummaryContext?: IExperimentalIncrementalSummaryContext): ISummaryTreeWithStats;
291
288
  private incrementTelemetryMetric;
292
289
  }
293
290
  //# sourceMappingURL=sharedObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharedObject.d.ts","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAGI,EAAE,YAAY,EAAwB,MAAM,iCAAiC;OAC7E,EACN,mBAAmB,EAGnB,6BAA6B,EAK7B,MAAM,iCAAiC;OAEjC,EAAE,qBAAqB,EAAE,MAAM,8BAA8B;OAE7D,EACN,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,gBAAgB,EAChB,MAAM,uCAAuC;OACvC,EAAE,yBAAyB,EAAE,MAAM,sCAAsC;OACzE,EACN,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,EAGjB,sCAAsC,EACtC,MAAM,qCAAqC;OACrC,EAAmB,gBAAgB,EAAE;OAGrC,EAAE,aAAa,EAAE,mBAAmB,EAAE;AAE7C;;;GAGG;AACH,8BAAsB,gBAAgB,CAAC,MAAM,SAAS,mBAAmB,GAAG,mBAAmB,CAC9F,SAAQ,6BAA6B,CAAC,MAAM,CAC5C,YAAW,aAAa,CAAC,MAAM,CAAC;IAsDxB,EAAE,EAAE,MAAM;IACjB,SAAS,CAAC,OAAO,EAAE,sBAAsB;aACzB,UAAU,EAAE,kBAAkB;IAtD/C,IAAW,cAAc,SAExB;IAED,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAyB;IAC5D,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAyB;IAEzD;;OAEG;IACH,SAAgB,MAAM,EAAE,YAAY,CAAC;IAErC;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;IAC/C,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAoB;IAEvC;;OAEG;IACH,OAAO,CAAC,UAAU,CAAS;IAE3B;;OAEG;IACH,OAAO,CAAC,QAAQ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