@fluidframework/shared-object-base 0.54.0-47413 → 0.55.0-48551

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 (73) hide show
  1. package/.eslintrc.js +5 -2
  2. package/bench/src/index.ts +68 -0
  3. package/bench/src/util.ts +56 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +1 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/packageVersion.d.ts +1 -1
  9. package/dist/packageVersion.js +1 -1
  10. package/dist/packageVersion.js.map +1 -1
  11. package/dist/remoteObjectHandle.d.ts +32 -0
  12. package/dist/remoteObjectHandle.d.ts.map +1 -0
  13. package/dist/remoteObjectHandle.js +66 -0
  14. package/dist/remoteObjectHandle.js.map +1 -0
  15. package/dist/serializer.d.ts +82 -0
  16. package/dist/serializer.d.ts.map +1 -0
  17. package/dist/serializer.js +148 -0
  18. package/dist/serializer.js.map +1 -0
  19. package/dist/sharedObject.d.ts +54 -26
  20. package/dist/sharedObject.d.ts.map +1 -1
  21. package/dist/sharedObject.js +77 -75
  22. package/dist/sharedObject.js.map +1 -1
  23. package/dist/summarySerializer.d.ts +1 -1
  24. package/dist/summarySerializer.d.ts.map +1 -1
  25. package/dist/summarySerializer.js +2 -2
  26. package/dist/summarySerializer.js.map +1 -1
  27. package/dist/types.d.ts +8 -2
  28. package/dist/types.d.ts.map +1 -1
  29. package/dist/types.js.map +1 -1
  30. package/dist/utils.d.ts +10 -1
  31. package/dist/utils.d.ts.map +1 -1
  32. package/dist/utils.js +15 -5
  33. package/dist/utils.js.map +1 -1
  34. package/lib/index.d.ts +1 -0
  35. package/lib/index.d.ts.map +1 -1
  36. package/lib/index.js +1 -0
  37. package/lib/index.js.map +1 -1
  38. package/lib/packageVersion.d.ts +1 -1
  39. package/lib/packageVersion.js +1 -1
  40. package/lib/packageVersion.js.map +1 -1
  41. package/lib/remoteObjectHandle.d.ts +32 -0
  42. package/lib/remoteObjectHandle.d.ts.map +1 -0
  43. package/lib/remoteObjectHandle.js +62 -0
  44. package/lib/remoteObjectHandle.js.map +1 -0
  45. package/lib/serializer.d.ts +82 -0
  46. package/lib/serializer.d.ts.map +1 -0
  47. package/lib/serializer.js +143 -0
  48. package/lib/serializer.js.map +1 -0
  49. package/lib/sharedObject.d.ts +54 -26
  50. package/lib/sharedObject.d.ts.map +1 -1
  51. package/lib/sharedObject.js +75 -74
  52. package/lib/sharedObject.js.map +1 -1
  53. package/lib/summarySerializer.d.ts +1 -1
  54. package/lib/summarySerializer.d.ts.map +1 -1
  55. package/lib/summarySerializer.js +1 -1
  56. package/lib/summarySerializer.js.map +1 -1
  57. package/lib/types.d.ts +8 -2
  58. package/lib/types.d.ts.map +1 -1
  59. package/lib/types.js.map +1 -1
  60. package/lib/utils.d.ts +10 -1
  61. package/lib/utils.d.ts.map +1 -1
  62. package/lib/utils.js +13 -4
  63. package/lib/utils.js.map +1 -1
  64. package/package.json +54 -18
  65. package/src/index.ts +1 -0
  66. package/src/packageVersion.ts +1 -1
  67. package/src/remoteObjectHandle.ts +79 -0
  68. package/src/serializer.ts +216 -0
  69. package/src/sharedObject.ts +116 -97
  70. package/src/summarySerializer.ts +1 -1
  71. package/src/types.ts +9 -2
  72. package/src/utils.ts +17 -8
  73. package/tsconfig.json +5 -3
@@ -1 +1 @@
1
- {"version":3,"file":"sharedObject.d.ts","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAGtE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACjF,OAAO,EACH,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,gBAAgB,EACnB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,yBAAyB,EAAE,KAAK,EAAE,MAAM,sCAAsC,CAAC;AACxF,OAAO,E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"uuid";
6
6
  import { assert } from "@fluidframework/common-utils";
7
7
  import { AttachState } from "@fluidframework/container-definitions";
8
- import { convertToSummaryTreeWithStats, FluidSerializer } from "@fluidframework/runtime-utils";
9
8
  import { ChildLogger, EventEmitterWithErrorHandling } from "@fluidframework/telemetry-utils";
10
9
  import { DataProcessingError } from "@fluidframework/container-utils";
10
+ import { FluidSerializer } from "./serializer";
11
11
  import { SharedObjectHandle } from "./handle";
12
12
  import { SummarySerializer } from "./summarySerializer";
13
13
  /**
14
14
  * Base class from which all shared objects derive
15
15
  */
16
- export class SharedObject extends EventEmitterWithErrorHandling {
16
+ export class SharedObjectCore extends EventEmitterWithErrorHandling {
17
17
  /**
18
18
  * @param id - The id of the shared object
19
19
  * @param runtime - The IFluidDataStoreRuntime which contains the shared object
@@ -32,13 +32,8 @@ export class SharedObject extends EventEmitterWithErrorHandling {
32
32
  * True if the dds is bound to its parent.
33
33
  */
34
34
  this._isBoundToContext = false;
35
- /**
36
- * True while we are summarizing this object's data.
37
- */
38
- this._isSummarizing = false;
39
35
  this.handle = new SharedObjectHandle(this, id, runtime.IFluidHandleContext);
40
36
  this.logger = ChildLogger.create(runtime.logger, undefined, { all: { sharedObjectId: uuid() } });
41
- this._serializer = new FluidSerializer(this.runtime.channelsRoutingContext, (handle) => this.handleDecoded(handle));
42
37
  this.attachListeners();
43
38
  }
44
39
  /**
@@ -58,17 +53,6 @@ export class SharedObject extends EventEmitterWithErrorHandling {
58
53
  get connected() {
59
54
  return this._connected;
60
55
  }
61
- get serializer() {
62
- /**
63
- * During summarize, the SummarySerializer keeps track of IFluidHandles that are serialized. These handles
64
- * represent references to other Fluid objects and are used for garbage collection.
65
- *
66
- * This is fine for now. However, if we implement delay loading in DDss, they may load and de-serialize content
67
- * in summarize. When that happens, they may incorrectly hit this assert and we will have to change this.
68
- */
69
- assert(!this._isSummarizing, 0x075 /* "SummarySerializer should be used for serializing data during summary." */);
70
- return this._serializer;
71
- }
72
56
  /**
73
57
  * Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)
74
58
  * would result in same error thrown. If called multiple times, only first error is remembered.
@@ -159,62 +143,6 @@ export class SharedObject extends EventEmitterWithErrorHandling {
159
143
  isAttached() {
160
144
  return this.services !== undefined && this.runtime.attachState !== AttachState.Detached;
161
145
  }
162
- /**
163
- * {@inheritDoc (ISharedObject:interface).summarize}
164
- */
165
- summarize(fullTree = false, trackState = false) {
166
- // Set _isSummarizing to true. This flag is used to ensure that we only use SummarySerializer (created below)
167
- // to serialize handles in this object's data. The routes of these serialized handles are outbound routes
168
- // to other Fluid objects.
169
- assert(!this._isSummarizing, 0x076 /* "Possible re-entrancy! Summary should not already be in progress." */);
170
- this._isSummarizing = true;
171
- let summaryTree;
172
- try {
173
- const serializer = new SummarySerializer(this.runtime.channelsRoutingContext, (handle) => this.handleDecoded(handle));
174
- const snapshot = this.snapshotCore(serializer);
175
- summaryTree = convertToSummaryTreeWithStats(snapshot, fullTree);
176
- assert(this._isSummarizing, 0x077 /* "Possible re-entrancy! Summary should have been in progress." */);
177
- }
178
- finally {
179
- this._isSummarizing = false;
180
- }
181
- return summaryTree;
182
- }
183
- /**
184
- * {@inheritDoc (ISharedObject:interface).getGCData}
185
- */
186
- getGCData(fullGC = false) {
187
- // Set _isSummarizing to true. This flag is used to ensure that we only use SummarySerializer (created in
188
- // getGCDataCore) to serialize handles in this object's data.
189
- assert(!this._isSummarizing, 0x078 /* "Possible re-entrancy! Summary should not already be in progress." */);
190
- this._isSummarizing = true;
191
- let gcData;
192
- try {
193
- gcData = this.getGCDataCore();
194
- assert(this._isSummarizing, 0x079 /* "Possible re-entrancy! Summary should have been in progress." */);
195
- }
196
- finally {
197
- this._isSummarizing = false;
198
- }
199
- return gcData;
200
- }
201
- /**
202
- * Returns the GC data for this shared object. It contains a list of GC nodes that contains references to
203
- * other GC nodes.
204
- * Derived classes must override this to provide custom list of references to other GC nodes.
205
- */
206
- getGCDataCore() {
207
- // We run the full summarize logic to get the list of outbound routes from this object. This is a little
208
- // expensive but its okay for now. It will be updated to not use full summarize and make it more efficient.
209
- // See: https://github.com/microsoft/FluidFramework/issues/4547
210
- const serializer = new SummarySerializer(this.runtime.channelsRoutingContext, (handle) => this.handleDecoded(handle));
211
- this.snapshotCore(serializer);
212
- // The GC data for this shared object contains a single GC node. The outbound routes of this node are the
213
- // routes of handles serialized during snapshot.
214
- return {
215
- gcNodes: { "/": serializer.getSerializedRoutes() },
216
- };
217
- }
218
146
  /**
219
147
  * Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference
220
148
  * to another object in the container.
@@ -376,4 +304,77 @@ export class SharedObject extends EventEmitterWithErrorHandling {
376
304
  this.reSubmitCore(content, localOpMetadata);
377
305
  }
378
306
  }
307
+ /**
308
+ * SharedObject with simplified, synchronous summarization and GC
309
+ */
310
+ export class SharedObject extends SharedObjectCore {
311
+ /**
312
+ * @param id - The id of the shared object
313
+ * @param runtime - The IFluidDataStoreRuntime which contains the shared object
314
+ * @param attributes - Attributes of the shared object
315
+ */
316
+ constructor(id, runtime, attributes) {
317
+ super(id, runtime, attributes);
318
+ /**
319
+ * True while we are garbage collecting this object's data.
320
+ */
321
+ this._isGCing = false;
322
+ this._serializer = new FluidSerializer(this.runtime.channelsRoutingContext, (handle) => this.handleDecoded(handle));
323
+ }
324
+ get serializer() {
325
+ /**
326
+ * During garbage collection, the SummarySerializer keeps track of IFluidHandles that are serialized. These
327
+ * handles represent references to other Fluid objects.
328
+ *
329
+ * This is fine for now. However, if we implement delay loading in DDss, they may load and de-serialize content
330
+ * in summarize. When that happens, they may incorrectly hit this assert and we will have to change this.
331
+ */
332
+ assert(!this._isGCing, 0x075 /* "SummarySerializer should be used for serializing data during summary." */);
333
+ return this._serializer;
334
+ }
335
+ /**
336
+ * {@inheritDoc (ISharedObject:interface).getAttachSummary}
337
+ */
338
+ getAttachSummary(fullTree = false, trackState = false) {
339
+ return this.summarizeCore(this.serializer, fullTree);
340
+ }
341
+ /**
342
+ * {@inheritDoc (ISharedObject:interface).summarize}
343
+ */
344
+ async summarize(fullTree = false, trackState = false) {
345
+ return this.summarizeCore(this.serializer, fullTree);
346
+ }
347
+ /**
348
+ * {@inheritDoc (ISharedObject:interface).getGCData}
349
+ */
350
+ getGCData(fullGC = false) {
351
+ // Set _isGCing to true. This flag is used to ensure that we only use SummarySerializer to serialize handles
352
+ // in this object's data.
353
+ assert(!this._isGCing, 0x078 /* "Possible re-entrancy! Summary should not already be in progress." */);
354
+ this._isGCing = true;
355
+ let gcData;
356
+ try {
357
+ const serializer = new SummarySerializer(this.runtime.channelsRoutingContext, (handle) => this.handleDecoded(handle));
358
+ this.processGCDataCore(serializer);
359
+ // The GC data for this shared object contains a single GC node. The outbound routes of this node are the
360
+ // routes of handles serialized during summarization.
361
+ gcData = { gcNodes: { "/": serializer.getSerializedRoutes() } };
362
+ assert(this._isGCing, 0x079 /* "Possible re-entrancy! Summary should have been in progress." */);
363
+ }
364
+ finally {
365
+ this._isGCing = false;
366
+ }
367
+ return gcData;
368
+ }
369
+ /**
370
+ * Calls the serializer over all data in this object that reference other GC nodes.
371
+ * Derived classes must override this to provide custom list of references to other GC nodes.
372
+ */
373
+ processGCDataCore(serializer) {
374
+ // We run the full summarize logic to get the list of outbound routes from this object. This is a little
375
+ // expensive but its okay for now. It will be updated to not use full summarize and make it more efficient.
376
+ // See: https://github.com/microsoft/FluidFramework/issues/4547
377
+ this.summarizeCore(serializer, false);
378
+ }
379
+ }
379
380
  //# sourceMappingURL=sharedObject.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sharedObject.js","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,MAAM,EAAyB,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AAapE,OAAO,EAAE,6BAA6B,EAAE,eAAe,EAAE,MAAM,+B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\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, EventEmitterEventType } from \"@fluidframework/common-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IFluidHandle, IFluidSerializer } from \"@fluidframework/core-interfaces\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage, ITree } from \"@fluidframework/protocol-definitions\";\nimport {\n IGarbageCollectionData,\n ISummaryTreeWithStats,\n} from \"@fluidframework/runtime-definitions\";\nimport { convertToSummaryTreeWithStats, FluidSerializer } from \"@fluidframework/runtime-utils\";\nimport { ChildLogger, EventEmitterWithErrorHandling } from \"@fluidframework/telemetry-utils\";\nimport { DataProcessingError } from \"@fluidframework/container-utils\";\nimport { SharedObjectHandle } from \"./handle\";\nimport { SummarySerializer } from \"./summarySerializer\";\nimport { ISharedObject, ISharedObjectEvents } from \"./types\";\n\n/**\n * Base class from which all shared objects derive\n */\nexport abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends EventEmitterWithErrorHandling<TEvent> implements ISharedObject<TEvent> {\n /**\n * @param obj - The thing to check if it is a SharedObject\n * @returns Returns true if the thing is a SharedObject\n */\n public static is(obj: any): obj is SharedObject {\n return obj?.ISharedObject !== undefined;\n }\n\n public get ISharedObject() { return this; }\n public get IChannel() { return this; }\n public get IFluidLoadable() { return this; }\n\n /**\n * The handle referring to this SharedObject\n */\n public readonly handle: IFluidHandle;\n\n /**\n * Telemetry logger for the shared object\n */\n protected readonly logger: ITelemetryLogger;\n\n /**\n * Connection state\n */\n private _connected = false;\n\n /**\n * Services used by the shared object\n */\n private services: IChannelServices | undefined;\n\n /**\n * True if the dds is bound to its parent.\n */\n private _isBoundToContext: boolean = false;\n\n /**\n * True while we are summarizing this object's data.\n */\n private _isSummarizing: boolean = false;\n\n /**\n * Tracks error that closed this object.\n */\n private closeError?: ReturnType<typeof DataProcessingError.wrapIfUnrecognized>;\n\n /**\n * Gets the connection state\n * @returns The state of the connection\n */\n public get connected(): boolean {\n return this._connected;\n }\n\n protected get serializer(): IFluidSerializer {\n /**\n * During summarize, the SummarySerializer keeps track of IFluidHandles that are serialized. These handles\n * represent references to other Fluid objects and are used for garbage collection.\n *\n * This is fine for now. However, if we implement delay loading in DDss, they may load and de-serialize content\n * in summarize. When that happens, they may incorrectly hit this assert and we will have to change this.\n */\n assert(!this._isSummarizing,\n 0x075 /* \"SummarySerializer should be used for serializing data during summary.\" */);\n return this._serializer;\n }\n\n /**\n * The serializer to use to serialize / parse handles, if any.\n */\n private readonly _serializer: IFluidSerializer;\n\n /**\n * @param id - The id of the shared object\n * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n * @param attributes - Attributes of the shared object\n */\n constructor(\n public id: string,\n protected runtime: IFluidDataStoreRuntime,\n public readonly attributes: IChannelAttributes)\n {\n super((event: EventEmitterEventType, e: any) => this.eventListenerErrorHandler(event, e));\n\n this.handle = new SharedObjectHandle(\n this,\n id,\n runtime.IFluidHandleContext);\n\n this.logger = ChildLogger.create(\n runtime.logger,\n undefined,\n { all: { sharedObjectId: uuid() } },\n );\n\n this._serializer = new FluidSerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n\n this.attachListeners();\n }\n\n /**\n * Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)\n * would result in same error thrown. If called multiple times, only first error is remembered.\n * @param error - error object that is thrown whenever an attempt is made to modify this object\n */\n private closeWithError(error: any) {\n if (this.closeError === undefined) {\n this.closeError = error;\n }\n }\n\n /**\n * Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.\n */\n private verifyNotClosed() {\n if (this.closeError !== undefined) {\n throw this.closeError;\n }\n }\n\n /**\n * Event listener handler helper that can be used to react to exceptions thrown from event listeners\n * It wraps error with DataProcessingError, closes this object and throws resulting error.\n * See closeWithError() for more details\n * Ideally such situation never happens, as consumers of DDS should never throw exceptions\n * in event listeners (i.e. catch any of the issues and make determination on how to handle it).\n * When such exceptions propagate through, most likely data model is no longer consistent, i.e.\n * DDS state does not match what user sees. Because of it DDS moves to \"corrupted state\" and does not\n * allow processing of ops or local changes, which very quickly results in container closure.\n */\n private eventListenerErrorHandler(event: EventEmitterEventType, e: any) {\n const error = DataProcessingError.wrapIfUnrecognized(\n e,\n \"SharedObjectEventListenerException\");\n error.addTelemetryProperties({ emittedEventName: String(event) });\n\n this.closeWithError(error);\n throw error;\n }\n\n private attachListeners() {\n // Only listen to these events if not attached.\n if (!this.isAttached()) {\n this.runtime.once(\"attaching\", () => {\n // Calling this will let the dds to do any custom processing based on attached\n // like starting generating ops.\n this.didAttach();\n });\n }\n }\n\n /**\n * A shared object, after construction, can either be loaded in the case that it is already part of\n * a shared document. Or later attached if it is being newly added.\n * @param services - Services used by the shared object\n */\n public async load(services: IChannelServices): Promise<void> {\n if (this.runtime.attachState !== AttachState.Detached) {\n this.services = services;\n }\n await this.loadCore(services.objectStorage);\n if (this.runtime.attachState !== AttachState.Detached) {\n this.attachDeltaHandler();\n }\n }\n\n /**\n * Initializes the object as a local, non-shared object. This object can become shared after\n * it is attached to the document.\n */\n public initializeLocal(): void {\n this.initializeLocalCore();\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).bindToContext}\n */\n public bindToContext(): void {\n if (this._isBoundToContext) {\n return;\n }\n\n this._isBoundToContext = true;\n\n // Allow derived classes to perform custom processing prior to registering this object\n this.registerCore();\n\n this.runtime.bindChannel(this);\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).connect}\n */\n public connect(services: IChannelServices) {\n this.services = services;\n this.attachDeltaHandler();\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).isAttached}\n */\n public isAttached(): boolean {\n return this.services !== undefined && this.runtime.attachState !== AttachState.Detached;\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).summarize}\n */\n public summarize(fullTree: boolean = false, trackState: boolean = false): ISummaryTreeWithStats {\n // Set _isSummarizing to true. This flag is used to ensure that we only use SummarySerializer (created below)\n // to serialize handles in this object's data. The routes of these serialized handles are outbound routes\n // to other Fluid objects.\n assert(!this._isSummarizing, 0x076 /* \"Possible re-entrancy! Summary should not already be in progress.\" */);\n this._isSummarizing = true;\n\n let summaryTree: ISummaryTreeWithStats;\n try {\n const serializer = new SummarySerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n const snapshot: ITree = this.snapshotCore(serializer);\n summaryTree = convertToSummaryTreeWithStats(snapshot, fullTree);\n assert(this._isSummarizing, 0x077 /* \"Possible re-entrancy! Summary should have been in progress.\" */);\n } finally {\n this._isSummarizing = false;\n }\n return summaryTree;\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public getGCData(fullGC: boolean = false): IGarbageCollectionData {\n // Set _isSummarizing to true. This flag is used to ensure that we only use SummarySerializer (created in\n // getGCDataCore) to serialize handles in this object's data.\n assert(!this._isSummarizing, 0x078 /* \"Possible re-entrancy! Summary should not already be in progress.\" */);\n this._isSummarizing = true;\n\n let gcData: IGarbageCollectionData;\n try {\n gcData = this.getGCDataCore();\n assert(this._isSummarizing, 0x079 /* \"Possible re-entrancy! Summary should have been in progress.\" */);\n } finally {\n this._isSummarizing = false;\n }\n\n return gcData;\n }\n\n /**\n * Returns the GC data for this shared object. It contains a list of GC nodes that contains references to\n * other GC nodes.\n * Derived classes must override this to provide custom list of references to other GC nodes.\n */\n protected getGCDataCore(): IGarbageCollectionData {\n // We run the full summarize logic to get the list of outbound routes from this object. This is a little\n // expensive but its okay for now. It will be updated to not use full summarize and make it more efficient.\n // See: https://github.com/microsoft/FluidFramework/issues/4547\n const serializer = new SummarySerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n this.snapshotCore(serializer);\n\n // The GC data for this shared object contains a single GC node. The outbound routes of this node are the\n // routes of handles serialized during snapshot.\n return {\n gcNodes: { \"/\": serializer.getSerializedRoutes() },\n };\n }\n\n /**\n * Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference\n * to another object in the container.\n * @param decodedHandle - The handle of the Fluid object that is decoded.\n */\n protected handleDecoded(decodedHandle: IFluidHandle) {\n if (this.isAttached()) {\n // This represents an outbound reference from this object to the node represented by decodedHandle.\n this.services?.deltaConnection.addedGCOutboundReference?.(this.handle, decodedHandle);\n }\n }\n\n /**\n * Gets a form of the object that can be serialized.\n * @returns A tree representing the snapshot of the shared object.\n */\n protected abstract snapshotCore(serializer: IFluidSerializer): ITree;\n\n /**\n * Allows the distributed data type to perform custom loading\n * @param services - Storage used by the shared object\n */\n protected abstract loadCore(services: IChannelStorageService): Promise<void>;\n\n /**\n * Allows the distributed data type to perform custom local loading.\n */\n protected initializeLocalCore() {\n return;\n }\n\n /**\n * Allows the distributed data type the ability to perform custom processing once an attach has happened.\n */\n protected abstract registerCore();\n\n /**\n * Allows the distributive data type the ability to perform custom processing once an attach has happened.\n * Also called after non-local data type get loaded.\n */\n protected didAttach() {\n return;\n }\n\n /**\n * Derived classes must override this to do custom processing on a remote message.\n * @param message - The message to process\n * @param local - True if the shared object is local\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n protected abstract processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown);\n\n /**\n * Called when the object has disconnected from the delta stream.\n */\n protected abstract onDisconnect();\n\n /**\n * Submits a message by the local client to the runtime.\n * @param content - Content of the message\n * @param localOpMetadata - The local metadata associated with the message. This is kept locally by the runtime\n * and not sent to the server. This will be sent back when this message is received back from the server. This is\n * also sent if we are asked to resubmit the message.\n */\n protected submitLocalMessage(content: any, localOpMetadata: unknown = undefined): void {\n this.verifyNotClosed();\n if (this.isAttached()) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.submit(content, localOpMetadata);\n }\n }\n\n /**\n * Marks this object as dirty so that it is part of the next summary. It is called by a SharedSummaryBlock\n * that want to be part of summary but does not generate ops.\n */\n protected dirty(): void {\n if (!this.isAttached()) {\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.dirty();\n }\n\n /**\n * Called when the object has fully connected to the delta stream\n * Default implementation for DDS, override if different behavior is required.\n */\n protected onConnect() { }\n\n /**\n * Called when a message has to be resubmitted. This typically happens after a reconnection for unacked messages.\n * The default implementation here is to resubmit the same message. The client can override if different behavior\n * is required. It can choose to resubmit the same message, submit different / multiple messages or not submit\n * anything at all.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n protected reSubmitCore(content: any, localOpMetadata: unknown) {\n this.submitLocalMessage(content, localOpMetadata);\n }\n\n /**\n * Promises that are waiting for an ack from the server before resolving should use this instead of new Promise.\n * It ensures that if something changes that will interrupt that ack (e.g. the FluidDataStoreRuntime disposes),\n * the Promise will reject.\n * If runtime is disposed when this call is made, executor is not run and promise is rejected right away.\n */\n protected async newAckBasedPromise<T>(\n executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void,\n ): Promise<T> {\n let rejectBecauseDispose: () => void;\n return new Promise<T>((resolve, reject) => {\n rejectBecauseDispose =\n () => reject(new Error(\"FluidDataStoreRuntime disposed while this ack-based Promise was pending\"));\n\n if (this.runtime.disposed) {\n rejectBecauseDispose();\n return;\n }\n\n this.runtime.on(\"dispose\", rejectBecauseDispose);\n executor(resolve, reject);\n }).finally(() => {\n // Note: rejectBecauseDispose will never be undefined here\n this.runtime.off(\"dispose\", rejectBecauseDispose);\n });\n }\n\n private attachDeltaHandler() {\n // Services should already be there in case we are attaching delta handler.\n assert(this.services !== undefined, 0x07a /* \"Services should be there to attach delta handler\" */);\n this._isBoundToContext = true;\n // Allows objects to do any custom processing if it is attached.\n this.didAttach();\n\n // attachDeltaHandler is only called after services is assigned\n this.services.deltaConnection.attach({\n process: (message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) => {\n this.process(message, local, localOpMetadata);\n },\n setConnectionState: (connected: boolean) => {\n this.setConnectionState(connected);\n },\n reSubmit: (content: any, localOpMetadata: unknown) => {\n this.reSubmit(content, localOpMetadata);\n },\n applyStashedOp: (content: any): unknown => {\n return this.applyStashedOp(content);\n },\n });\n\n // Trigger initial state\n // attachDeltaHandler is only called after services is assigned\n this.setConnectionState(this.services.deltaConnection.connected);\n }\n\n /**\n * Set the state of connection to services.\n * @param connected - true if connected, false otherwise.\n */\n private setConnectionState(connected: boolean) {\n if (this._connected === connected) {\n // Not changing state, nothing the same.\n return;\n }\n\n // Should I change the state at the end? So that we *can't* send new stuff before we send old?\n this._connected = connected;\n\n if (!connected) {\n // Things that are true now...\n // - if we had a connection we can no longer send messages over it\n // - if we had outbound messages some may or may not be ACK'd. Won't know until next message\n //\n // - nack could get a new msn - but might as well do it in the join?\n this.onDisconnect();\n } else {\n // Call this for now so that DDSes like ConsensesOrderedCollection that maintain their own pending\n // messages will work.\n this.onConnect();\n }\n }\n\n /**\n * Handles a message being received from the remote delta server.\n * @param message - The message to process\n * @param local - Whether the message originated from the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n private process(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n this.verifyNotClosed(); // This will result in container closure.\n this.emit(\"pre-op\", message, local, this);\n this.processCore(message, local, localOpMetadata);\n this.emit(\"op\", message, local, this);\n }\n\n /**\n * Called when a message has to be resubmitted. This typically happens for unacked messages after a\n * reconnection.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n private reSubmit(content: any, localOpMetadata: unknown) {\n this.reSubmitCore(content, localOpMetadata);\n }\n\n protected abstract applyStashedOp(content: any): unknown;\n}\n"]}
1
+ {"version":3,"file":"sharedObject.js","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":"AAAA;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Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, EventEmitterEventType } from \"@fluidframework/common-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n IGarbageCollectionData,\n ISummaryTreeWithStats,\n} from \"@fluidframework/runtime-definitions\";\nimport { ChildLogger, EventEmitterWithErrorHandling } from \"@fluidframework/telemetry-utils\";\nimport { DataProcessingError } from \"@fluidframework/container-utils\";\nimport { FluidSerializer, IFluidSerializer } from \"./serializer\";\nimport { SharedObjectHandle } from \"./handle\";\nimport { SummarySerializer } from \"./summarySerializer\";\nimport { ISharedObject, ISharedObjectEvents } from \"./types\";\n\n/**\n * Base class from which all shared objects derive\n */\nexport abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends EventEmitterWithErrorHandling<TEvent> implements ISharedObject<TEvent> {\n /**\n * @param obj - The thing to check if it is a SharedObject\n * @returns Returns true if the thing is a SharedObject\n */\n public static is(obj: any): obj is SharedObjectCore {\n return obj?.ISharedObject !== undefined;\n }\n\n public get ISharedObject() { return this; }\n public get IChannel() { return this; }\n public get IFluidLoadable() { return this; }\n\n /**\n * The handle referring to this SharedObject\n */\n public readonly handle: IFluidHandle;\n\n /**\n * Telemetry logger for the shared object\n */\n protected readonly logger: ITelemetryLogger;\n\n /**\n * Connection state\n */\n private _connected = false;\n\n /**\n * Services used by the shared object\n */\n private services: IChannelServices | undefined;\n\n /**\n * True if the dds is bound to its parent.\n */\n private _isBoundToContext: boolean = false;\n\n /**\n * Tracks error that closed this object.\n */\n private closeError?: ReturnType<typeof DataProcessingError.wrapIfUnrecognized>;\n\n /**\n * Gets the connection state\n * @returns The state of the connection\n */\n public get connected(): boolean {\n return this._connected;\n }\n\n /**\n * @param id - The id of the shared object\n * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n * @param attributes - Attributes of the shared object\n */\n constructor(\n public id: string,\n protected runtime: IFluidDataStoreRuntime,\n public readonly attributes: IChannelAttributes)\n {\n super((event: EventEmitterEventType, e: any) => this.eventListenerErrorHandler(event, e));\n\n this.handle = new SharedObjectHandle(\n this,\n id,\n runtime.IFluidHandleContext);\n\n this.logger = ChildLogger.create(\n runtime.logger,\n undefined,\n { all: { sharedObjectId: uuid() } },\n );\n\n this.attachListeners();\n }\n\n /**\n * Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)\n * would result in same error thrown. If called multiple times, only first error is remembered.\n * @param error - error object that is thrown whenever an attempt is made to modify this object\n */\n private closeWithError(error: any) {\n if (this.closeError === undefined) {\n this.closeError = error;\n }\n }\n\n /**\n * Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.\n */\n private verifyNotClosed() {\n if (this.closeError !== undefined) {\n throw this.closeError;\n }\n }\n\n /**\n * Event listener handler helper that can be used to react to exceptions thrown from event listeners\n * It wraps error with DataProcessingError, closes this object and throws resulting error.\n * See closeWithError() for more details\n * Ideally such situation never happens, as consumers of DDS should never throw exceptions\n * in event listeners (i.e. catch any of the issues and make determination on how to handle it).\n * When such exceptions propagate through, most likely data model is no longer consistent, i.e.\n * DDS state does not match what user sees. Because of it DDS moves to \"corrupted state\" and does not\n * allow processing of ops or local changes, which very quickly results in container closure.\n */\n private eventListenerErrorHandler(event: EventEmitterEventType, e: any) {\n const error = DataProcessingError.wrapIfUnrecognized(\n e,\n \"SharedObjectEventListenerException\");\n error.addTelemetryProperties({ emittedEventName: String(event) });\n\n this.closeWithError(error);\n throw error;\n }\n\n private attachListeners() {\n // Only listen to these events if not attached.\n if (!this.isAttached()) {\n this.runtime.once(\"attaching\", () => {\n // Calling this will let the dds to do any custom processing based on attached\n // like starting generating ops.\n this.didAttach();\n });\n }\n }\n\n /**\n * A shared object, after construction, can either be loaded in the case that it is already part of\n * a shared document. Or later attached if it is being newly added.\n * @param services - Services used by the shared object\n */\n public async load(services: IChannelServices): Promise<void> {\n if (this.runtime.attachState !== AttachState.Detached) {\n this.services = services;\n }\n await this.loadCore(services.objectStorage);\n if (this.runtime.attachState !== AttachState.Detached) {\n this.attachDeltaHandler();\n }\n }\n\n /**\n * Initializes the object as a local, non-shared object. This object can become shared after\n * it is attached to the document.\n */\n public initializeLocal(): void {\n this.initializeLocalCore();\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).bindToContext}\n */\n public bindToContext(): void {\n if (this._isBoundToContext) {\n return;\n }\n\n this._isBoundToContext = true;\n\n // Allow derived classes to perform custom processing prior to registering this object\n this.registerCore();\n\n this.runtime.bindChannel(this);\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).connect}\n */\n public connect(services: IChannelServices) {\n this.services = services;\n this.attachDeltaHandler();\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).isAttached}\n */\n public isAttached(): boolean {\n return this.services !== undefined && this.runtime.attachState !== AttachState.Detached;\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).getAttachSummary}\n */\n public abstract getAttachSummary(fullTree?: boolean, trackState?: boolean): ISummaryTreeWithStats;\n\n /**\n * {@inheritDoc (ISharedObject:interface).summarize}\n */\n public abstract summarize(fullTree?: boolean, trackState?: boolean): Promise<ISummaryTreeWithStats>;\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public abstract getGCData(fullGC?: boolean): IGarbageCollectionData;\n\n /**\n * Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference\n * to another object in the container.\n * @param decodedHandle - The handle of the Fluid object that is decoded.\n */\n protected handleDecoded(decodedHandle: IFluidHandle) {\n if (this.isAttached()) {\n // This represents an outbound reference from this object to the node represented by decodedHandle.\n this.services?.deltaConnection.addedGCOutboundReference?.(this.handle, decodedHandle);\n }\n }\n\n /**\n * Allows the distributed data type to perform custom loading\n * @param services - Storage used by the shared object\n */\n protected abstract loadCore(services: IChannelStorageService): Promise<void>;\n\n /**\n * Allows the distributed data type to perform custom local loading.\n */\n protected initializeLocalCore() {\n return;\n }\n\n /**\n * Allows the distributed data type the ability to perform custom processing once an attach has happened.\n */\n protected abstract registerCore();\n\n /**\n * Allows the distributive data type the ability to perform custom processing once an attach has happened.\n * Also called after non-local data type get loaded.\n */\n protected didAttach() {\n return;\n }\n\n /**\n * Derived classes must override this to do custom processing on a remote message.\n * @param message - The message to process\n * @param local - True if the shared object is local\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n protected abstract processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown);\n\n /**\n * Called when the object has disconnected from the delta stream.\n */\n protected abstract onDisconnect();\n\n /**\n * Submits a message by the local client to the runtime.\n * @param content - Content of the message\n * @param localOpMetadata - The local metadata associated with the message. This is kept locally by the runtime\n * and not sent to the server. This will be sent back when this message is received back from the server. This is\n * also sent if we are asked to resubmit the message.\n */\n protected submitLocalMessage(content: any, localOpMetadata: unknown = undefined): void {\n this.verifyNotClosed();\n if (this.isAttached()) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.submit(content, localOpMetadata);\n }\n }\n\n /**\n * Marks this object as dirty so that it is part of the next summary. It is called by a SharedSummaryBlock\n * that want to be part of summary but does not generate ops.\n */\n protected dirty(): void {\n if (!this.isAttached()) {\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.dirty();\n }\n\n /**\n * Called when the object has fully connected to the delta stream\n * Default implementation for DDS, override if different behavior is required.\n */\n protected onConnect() { }\n\n /**\n * Called when a message has to be resubmitted. This typically happens after a reconnection for unacked messages.\n * The default implementation here is to resubmit the same message. The client can override if different behavior\n * is required. It can choose to resubmit the same message, submit different / multiple messages or not submit\n * anything at all.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n protected reSubmitCore(content: any, localOpMetadata: unknown) {\n this.submitLocalMessage(content, localOpMetadata);\n }\n\n /**\n * Promises that are waiting for an ack from the server before resolving should use this instead of new Promise.\n * It ensures that if something changes that will interrupt that ack (e.g. the FluidDataStoreRuntime disposes),\n * the Promise will reject.\n * If runtime is disposed when this call is made, executor is not run and promise is rejected right away.\n */\n protected async newAckBasedPromise<T>(\n executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void,\n ): Promise<T> {\n let rejectBecauseDispose: () => void;\n return new Promise<T>((resolve, reject) => {\n rejectBecauseDispose =\n () => reject(new Error(\"FluidDataStoreRuntime disposed while this ack-based Promise was pending\"));\n\n if (this.runtime.disposed) {\n rejectBecauseDispose();\n return;\n }\n\n this.runtime.on(\"dispose\", rejectBecauseDispose);\n executor(resolve, reject);\n }).finally(() => {\n // Note: rejectBecauseDispose will never be undefined here\n this.runtime.off(\"dispose\", rejectBecauseDispose);\n });\n }\n\n private attachDeltaHandler() {\n // Services should already be there in case we are attaching delta handler.\n assert(this.services !== undefined, 0x07a /* \"Services should be there to attach delta handler\" */);\n this._isBoundToContext = true;\n // Allows objects to do any custom processing if it is attached.\n this.didAttach();\n\n // attachDeltaHandler is only called after services is assigned\n this.services.deltaConnection.attach({\n process: (message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) => {\n this.process(message, local, localOpMetadata);\n },\n setConnectionState: (connected: boolean) => {\n this.setConnectionState(connected);\n },\n reSubmit: (content: any, localOpMetadata: unknown) => {\n this.reSubmit(content, localOpMetadata);\n },\n applyStashedOp: (content: any): unknown => {\n return this.applyStashedOp(content);\n },\n });\n\n // Trigger initial state\n // attachDeltaHandler is only called after services is assigned\n this.setConnectionState(this.services.deltaConnection.connected);\n }\n\n /**\n * Set the state of connection to services.\n * @param connected - true if connected, false otherwise.\n */\n private setConnectionState(connected: boolean) {\n if (this._connected === connected) {\n // Not changing state, nothing the same.\n return;\n }\n\n // Should I change the state at the end? So that we *can't* send new stuff before we send old?\n this._connected = connected;\n\n if (!connected) {\n // Things that are true now...\n // - if we had a connection we can no longer send messages over it\n // - if we had outbound messages some may or may not be ACK'd. Won't know until next message\n //\n // - nack could get a new msn - but might as well do it in the join?\n this.onDisconnect();\n } else {\n // Call this for now so that DDSes like ConsensesOrderedCollection that maintain their own pending\n // messages will work.\n this.onConnect();\n }\n }\n\n /**\n * Handles a message being received from the remote delta server.\n * @param message - The message to process\n * @param local - Whether the message originated from the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n private process(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n this.verifyNotClosed(); // This will result in container closure.\n this.emit(\"pre-op\", message, local, this);\n this.processCore(message, local, localOpMetadata);\n this.emit(\"op\", message, local, this);\n }\n\n /**\n * Called when a message has to be resubmitted. This typically happens for unacked messages after a\n * reconnection.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n private reSubmit(content: any, localOpMetadata: unknown) {\n this.reSubmitCore(content, localOpMetadata);\n }\n\n protected abstract applyStashedOp(content: any): unknown;\n}\n\n/**\n * SharedObject with simplified, synchronous summarization and GC\n */\nexport abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends SharedObjectCore<TEvent> {\n /**\n * True while we are garbage collecting this object's data.\n */\n private _isGCing: boolean = false;\n\n /**\n * The serializer to use to serialize / parse handles, if any.\n */\n private readonly _serializer: IFluidSerializer;\n\n protected get serializer(): IFluidSerializer {\n /**\n * During garbage collection, the SummarySerializer keeps track of IFluidHandles that are serialized. These\n * handles represent references to other Fluid objects.\n *\n * This is fine for now. However, if we implement delay loading in DDss, they may load and de-serialize content\n * in summarize. When that happens, they may incorrectly hit this assert and we will have to change this.\n */\n assert(!this._isGCing,\n 0x075 /* \"SummarySerializer should be used for serializing data during summary.\" */);\n return this._serializer;\n }\n\n /**\n * @param id - The id of the shared object\n * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n * @param attributes - Attributes of the shared object\n */\n constructor(\n id: string,\n runtime: IFluidDataStoreRuntime,\n attributes: IChannelAttributes)\n {\n super(id, runtime, attributes);\n\n this._serializer = new FluidSerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).getAttachSummary}\n */\n public getAttachSummary(fullTree: boolean = false, trackState: boolean = false): ISummaryTreeWithStats {\n return this.summarizeCore(this.serializer, fullTree);\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).summarize}\n */\n public async summarize(fullTree: boolean = false, trackState: boolean = false): Promise<ISummaryTreeWithStats> {\n return this.summarizeCore(this.serializer, fullTree);\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public getGCData(fullGC: boolean = false): IGarbageCollectionData {\n // Set _isGCing to true. This flag is used to ensure that we only use SummarySerializer to serialize handles\n // in this object's data.\n assert(!this._isGCing, 0x078 /* \"Possible re-entrancy! Summary should not already be in progress.\" */);\n this._isGCing = true;\n\n let gcData: IGarbageCollectionData;\n try {\n const serializer = new SummarySerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n this.processGCDataCore(serializer);\n // The GC data for this shared object contains a single GC node. The outbound routes of this node are the\n // routes of handles serialized during summarization.\n gcData = { gcNodes: { \"/\": serializer.getSerializedRoutes() } };\n assert(this._isGCing, 0x079 /* \"Possible re-entrancy! Summary should have been in progress.\" */);\n } finally {\n this._isGCing = false;\n }\n\n return gcData;\n }\n\n /**\n * Calls the serializer over all data in this object that reference other GC nodes.\n * Derived classes must override this to provide custom list of references to other GC nodes.\n */\n protected processGCDataCore(serializer: SummarySerializer) {\n // We run the full summarize logic to get the list of outbound routes from this object. This is a little\n // expensive but its okay for now. It will be updated to not use full summarize and make it more efficient.\n // See: https://github.com/microsoft/FluidFramework/issues/4547\n this.summarizeCore(serializer, false);\n }\n\n /**\n * Gets a form of the object that can be serialized.\n * @returns A tree representing the snapshot of the shared object.\n */\n protected abstract summarizeCore(serializer: IFluidSerializer, fullTree: boolean): ISummaryTreeWithStats;\n}\n"]}
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { IFluidHandle } from "@fluidframework/core-interfaces";
6
- import { FluidSerializer } from "@fluidframework/runtime-utils";
6
+ import { FluidSerializer } from "./serializer";
7
7
  /**
8
8
  * Serializer implementation for serializing handles during summary.
9
9
  */
@@ -1 +1 @@
1
- {"version":3,"file":"summarySerializer.d.ts","sourceRoot":"","sources":["../src/summarySerializer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,eAAe;IAClD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA0B;IACpD,mBAAmB,IAAI,MAAM,EAAE;IAItC,SAAS,CAAC,eAAe,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY;;;;CAIrE"}
1
+ {"version":3,"file":"summarySerializer.d.ts","sourceRoot":"","sources":["../src/summarySerializer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,eAAe;IAClD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA0B;IACpD,mBAAmB,IAAI,MAAM,EAAE;IAItC,SAAS,CAAC,eAAe,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY;;;;CAIrE"}
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { FluidSerializer } from "@fluidframework/runtime-utils";
5
+ import { FluidSerializer } from "./serializer";
6
6
  /**
7
7
  * Serializer implementation for serializing handles during summary.
8
8
  */
@@ -1 +1 @@
1
- {"version":3,"file":"summarySerializer.js","sourceRoot":"","sources":["../src/summarySerializer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,eAAe;IAAtD;;QACqB,qBAAgB,GAAgB,IAAI,GAAG,EAAE,CAAC;IAS/D,CAAC;IARU,mBAAmB;QACtB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC7C,CAAC;IAES,eAAe,CAAC,MAAoB,EAAE,IAAkB;QAC9D,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAC/C,OAAO,KAAK,CAAC,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { FluidSerializer } from \"@fluidframework/runtime-utils\";\n\n/**\n * Serializer implementation for serializing handles during summary.\n */\nexport class SummarySerializer extends FluidSerializer {\n private readonly serializedRoutes: Set<string> = new Set();\n public getSerializedRoutes(): string[] {\n return Array.from(this.serializedRoutes);\n }\n\n protected serializeHandle(handle: IFluidHandle, bind: IFluidHandle) {\n this.serializedRoutes.add(handle.absolutePath);\n return super.serializeHandle(handle, bind);\n }\n}\n"]}
1
+ {"version":3,"file":"summarySerializer.js","sourceRoot":"","sources":["../src/summarySerializer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,eAAe;IAAtD;;QACqB,qBAAgB,GAAgB,IAAI,GAAG,EAAE,CAAC;IAS/D,CAAC;IARU,mBAAmB;QACtB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC7C,CAAC;IAES,eAAe,CAAC,MAAoB,EAAE,IAAkB;QAC9D,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAC/C,OAAO,KAAK,CAAC,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { FluidSerializer } from \"./serializer\";\n\n/**\n * Serializer implementation for serializing handles during summary.\n */\nexport class SummarySerializer extends FluidSerializer {\n private readonly serializedRoutes: Set<string> = new Set();\n public getSerializedRoutes(): string[] {\n return Array.from(this.serializedRoutes);\n }\n\n protected serializeHandle(handle: IFluidHandle, bind: IFluidHandle) {\n this.serializedRoutes.add(handle.absolutePath);\n return super.serializeHandle(handle, bind);\n }\n}\n"]}
package/lib/types.d.ts CHANGED
@@ -24,10 +24,16 @@ export interface ISharedObject<TEvent extends ISharedObjectEvents = ISharedObjec
24
24
  */
25
25
  isAttached(): boolean;
26
26
  /**
27
- * Generates summary of the shared object.
27
+ * Generates summary of the channel synchronously.
28
28
  * @returns A tree representing the summary of the shared object.
29
29
  */
30
- summarize(fullTree?: boolean, trackState?: boolean): ISummaryTreeWithStats;
30
+ getAttachSummary(fullTree?: boolean, trackState?: boolean): ISummaryTreeWithStats;
31
+ /**
32
+ * Generates summary of the shared object asynchronously.
33
+ * This should not be called where the object can be modified while summarization is in progress.
34
+ * @returns A tree representing the summary of the channel.
35
+ */
36
+ summarize(fullTree?: boolean, trackState?: boolean): Promise<ISummaryTreeWithStats>;
31
37
  /**
32
38
  * Enables the channel to send and receive ops.
33
39
  * @param services - Services to connect to
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AACxG,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAEpG,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACpD,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,EACnB,QAAQ,EAAE,CAAC,EAAE,EAAE,yBAAyB,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,qBAAqB,KAAK,IAAI,OAAE;CACzG;AAED;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,MAAM,SAAS,mBAAmB,GAAG,mBAAmB,CACnF,SAAQ,QAAQ,EAAE,cAAc,CAAC,MAAM,CAAC;IACxC;;;OAGG;IACH,aAAa,IAAI,IAAI,CAAC;IAEtB;;;OAGG;IACH,UAAU,IAAI,OAAO,CAAC;IAEtB;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,qBAAqB,CAAC;IAE3E;;;OAGG;IACH,OAAO,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAE1C;;;;OAIG;IACH,SAAS,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,sBAAsB,CAAC;CACvD"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AACxG,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAEpG,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACpD,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,EACnB,QAAQ,EAAE,CAAC,EAAE,EAAE,yBAAyB,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,qBAAqB,KAAK,IAAI,OAAE;CACzG;AAED;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,MAAM,SAAS,mBAAmB,GAAG,mBAAmB,CACnF,SAAQ,QAAQ,EAAE,cAAc,CAAC,MAAM,CAAC;IACxC;;;OAGG;IACH,aAAa,IAAI,IAAI,CAAC;IAEtB;;;OAGG;IACH,UAAU,IAAI,OAAO,CAAC;IAEtB;;;OAGG;IACH,gBAAgB,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,qBAAqB,CAAC;IAElF;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAEpF;;;OAGG;IACH,OAAO,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAE1C;;;;OAIG;IACH,SAAS,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,sBAAsB,CAAC;CACvD"}
package/lib/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IErrorEvent, IEventProvider, IEventThisPlaceHolder } from \"@fluidframework/common-definitions\";\nimport { IChannel, IChannelServices } from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { IGarbageCollectionData, ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\n\nexport interface ISharedObjectEvents extends IErrorEvent {\n (event: \"pre-op\" | \"op\",\n listener: (op: ISequencedDocumentMessage, local: boolean, target: IEventThisPlaceHolder) => void);\n}\n\n/**\n * Base interface for shared objects from which other interfaces derive. Implemented by SharedObject\n */\nexport interface ISharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends IChannel, IEventProvider<TEvent> {\n /**\n * Binds the given shared object to its containing data store runtime, causing it to attach once\n * the runtime attaches.\n */\n bindToContext(): void;\n\n /**\n * Returns whether the given shared object is attached to storage.\n * @returns True if the given shared object is attached\n */\n isAttached(): boolean;\n\n /**\n * Generates summary of the shared object.\n * @returns A tree representing the summary of the shared object.\n */\n summarize(fullTree?: boolean, trackState?: boolean): ISummaryTreeWithStats;\n\n /**\n * Enables the channel to send and receive ops.\n * @param services - Services to connect to\n */\n connect(services: IChannelServices): void;\n\n /**\n * Returns the GC data for this shared object. It contains a list of GC nodes that contains references to\n * other GC nodes.\n * @param fullGC - true to bypass optimizations and force full generation of GC data.\n */\n getGCData(fullGC?: boolean): IGarbageCollectionData;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IErrorEvent, IEventProvider, IEventThisPlaceHolder } from \"@fluidframework/common-definitions\";\nimport { IChannel, IChannelServices } from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { IGarbageCollectionData, ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\n\nexport interface ISharedObjectEvents extends IErrorEvent {\n (event: \"pre-op\" | \"op\",\n listener: (op: ISequencedDocumentMessage, local: boolean, target: IEventThisPlaceHolder) => void);\n}\n\n/**\n * Base interface for shared objects from which other interfaces derive. Implemented by SharedObject\n */\nexport interface ISharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends IChannel, IEventProvider<TEvent> {\n /**\n * Binds the given shared object to its containing data store runtime, causing it to attach once\n * the runtime attaches.\n */\n bindToContext(): void;\n\n /**\n * Returns whether the given shared object is attached to storage.\n * @returns True if the given shared object is attached\n */\n isAttached(): boolean;\n\n /**\n * Generates summary of the channel synchronously.\n * @returns A tree representing the summary of the shared object.\n */\n getAttachSummary(fullTree?: boolean, trackState?: boolean): ISummaryTreeWithStats;\n\n /**\n * Generates summary of the shared object asynchronously.\n * This should not be called where the object can be modified while summarization is in progress.\n * @returns A tree representing the summary of the channel.\n */\n summarize(fullTree?: boolean, trackState?: boolean): Promise<ISummaryTreeWithStats>;\n\n /**\n * Enables the channel to send and receive ops.\n * @param services - Services to connect to\n */\n connect(services: IChannelServices): void;\n\n /**\n * Returns the GC data for this shared object. It contains a list of GC nodes that contains references to\n * other GC nodes.\n * @param fullGC - true to bypass optimizations and force full generation of GC data.\n */\n getGCData(fullGC?: boolean): IGarbageCollectionData;\n}\n"]}
package/lib/utils.d.ts CHANGED
@@ -2,7 +2,9 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { IFluidHandle, IFluidSerializer } from "@fluidframework/core-interfaces";
5
+ import { IFluidHandle } from "@fluidframework/core-interfaces";
6
+ import { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
7
+ import { IFluidSerializer } from "./serializer";
6
8
  /**
7
9
  * Given a mostly-plain object that may have handle objects embedded within, return a string representation of an object
8
10
  * where the handle objects have been replaced with a serializable form.
@@ -35,4 +37,11 @@ export declare function makeHandlesSerializable(value: any, serializer: IFluidSe
35
37
  * @returns The mostly-plain object with handle objects within
36
38
  */
37
39
  export declare function parseHandles(value: any, serializer: IFluidSerializer): any;
40
+ /**
41
+ * Create a new summary containing one blob
42
+ * @param key - the key for the blob in the summary
43
+ * @param content - blob content
44
+ * @returns The summary containing the blob
45
+ */
46
+ export declare function createSingleBlobSummary(key: string, content: string | Uint8Array): ISummaryTreeWithStats;
38
47
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,YAAY,EACZ,gBAAgB,EACnB,MAAM,iCAAiC,CAAC;AAEzC;;;;;;;;GAQG;AAEH,wBAAgB,gBAAgB,CAC5B,KAAK,EAAE,GAAG,EACV,UAAU,EAAE,gBAAgB,EAC5B,IAAI,EAAE,YAAY,GACnB,MAAM,GAAG,SAAS,CAOpB;AAED;;;;;;;;;;;GAWG;AAEH,wBAAgB,uBAAuB,CACnC,KAAK,EAAE,GAAG,EACV,UAAU,EAAE,gBAAgB,EAC5B,IAAI,EAAE,YAAY,OAMrB;AAED;;;;;;;GAOG;AAEH,wBAAgB,YAAY,CACxB,KAAK,EAAE,GAAG,EACV,UAAU,EAAE,gBAAgB,OAI/B"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAE5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC5B,KAAK,EAAE,GAAG,EACV,UAAU,EAAE,gBAAgB,EAC5B,IAAI,EAAE,YAAY,GACnB,MAAM,GAAG,SAAS,CAOpB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACnC,KAAK,EAAE,GAAG,EACV,UAAU,EAAE,gBAAgB,EAC5B,IAAI,EAAE,YAAY,OAMrB;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CACxB,KAAK,EAAE,GAAG,EACV,UAAU,EAAE,gBAAgB,OAI/B;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,UAAU,GAAG,qBAAqB,CAIxG"}
package/lib/utils.js CHANGED
@@ -2,6 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ import { SummaryTreeBuilder } from "@fluidframework/runtime-utils";
5
6
  /**
6
7
  * Given a mostly-plain object that may have handle objects embedded within, return a string representation of an object
7
8
  * where the handle objects have been replaced with a serializable form.
@@ -11,7 +12,6 @@
11
12
  * @param bind - Bind any other handles we find in the object against this given handle.
12
13
  * @returns Result of strigifying an object
13
14
  */
14
- // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
15
15
  export function serializeHandles(value, serializer, bind) {
16
16
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
17
17
  return value !== undefined
@@ -30,10 +30,9 @@ export function serializeHandles(value, serializer, bind) {
30
30
  * @param bind - Bind any other handles we find in the object against this given handle.
31
31
  * @returns The fully-plain object
32
32
  */
33
- // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
34
33
  export function makeHandlesSerializable(value, serializer, bind) {
35
34
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
36
- return serializer.replaceHandles(value, bind);
35
+ return serializer.encode(value, bind);
37
36
  }
38
37
  /**
39
38
  * Given a fully-plain object that may have serializable-form handles within, will return the mostly-plain object
@@ -43,9 +42,19 @@ export function makeHandlesSerializable(value, serializer, bind) {
43
42
  * @param context - The handle context for the container
44
43
  * @returns The mostly-plain object with handle objects within
45
44
  */
46
- // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
47
45
  export function parseHandles(value, serializer) {
48
46
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
49
47
  return value !== undefined ? serializer.parse(JSON.stringify(value)) : value;
50
48
  }
49
+ /**
50
+ * Create a new summary containing one blob
51
+ * @param key - the key for the blob in the summary
52
+ * @param content - blob content
53
+ * @returns The summary containing the blob
54
+ */
55
+ export function createSingleBlobSummary(key, content) {
56
+ const builder = new SummaryTreeBuilder();
57
+ builder.addBlob(key, content);
58
+ return builder.getSummaryTree();
59
+ }
51
60
  //# sourceMappingURL=utils.js.map
package/lib/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH;;;;;;;;GAQG;AACH,+DAA+D;AAC/D,MAAM,UAAU,gBAAgB,CAC5B,KAAU,EACV,UAA4B,EAC5B,IAAkB;IAElB,+DAA+D;IAC/D,OAAO,KAAK,KAAK,SAAS;QACtB,CAAC,CAAC,UAAU,CAAC,SAAS,CAClB,KAAK,EACL,IAAI,CAAC;QACT,CAAC,CAAC,KAAK,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,+DAA+D;AAC/D,MAAM,UAAU,uBAAuB,CACnC,KAAU,EACV,UAA4B,EAC5B,IAAkB;IAElB,+DAA+D;IAC/D,OAAO,UAAU,CAAC,cAAc,CAC5B,KAAK,EACL,IAAI,CAAC,CAAC;AACd,CAAC;AAED;;;;;;;GAOG;AACH,+DAA+D;AAC/D,MAAM,UAAU,YAAY,CACxB,KAAU,EACV,UAA4B;IAE5B,+DAA+D;IAC/D,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACjF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n IFluidHandle,\n IFluidSerializer,\n} from \"@fluidframework/core-interfaces\";\n\n/**\n * Given a mostly-plain object that may have handle objects embedded within, return a string representation of an object\n * where the handle objects have been replaced with a serializable form.\n * @param value - The mostly-plain object\n * @param serializer - The serializer that knows how to convert handles into serializable format\n * @param context - The handle context for the container\n * @param bind - Bind any other handles we find in the object against this given handle.\n * @returns Result of strigifying an object\n */\n// eslint-disable-next-line prefer-arrow/prefer-arrow-functions\nexport function serializeHandles(\n value: any,\n serializer: IFluidSerializer,\n bind: IFluidHandle,\n): string | undefined {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value !== undefined\n ? serializer.stringify(\n value,\n bind)\n : value;\n}\n\n/**\n * Given a mostly-plain object that may have handle objects embedded within, will return a fully-plain object\n * where any embedded IFluidHandles have been replaced with a serializable form.\n *\n * The original `input` object is not mutated. This method will shallowly clones all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n *\n * @param input - The mostly-plain object\n * @param context - The handle context for the container\n * @param bind - Bind any other handles we find in the object against this given handle.\n * @returns The fully-plain object\n */\n// eslint-disable-next-line prefer-arrow/prefer-arrow-functions\nexport function makeHandlesSerializable(\n value: any,\n serializer: IFluidSerializer,\n bind: IFluidHandle,\n) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return serializer.replaceHandles(\n value,\n bind);\n}\n\n/**\n * Given a fully-plain object that may have serializable-form handles within, will return the mostly-plain object\n * with handle objects created instead.\n * @param value - The fully-plain object\n * @param serializer - The serializer that knows how to convert serializable-form handles into handle objects\n * @param context - The handle context for the container\n * @returns The mostly-plain object with handle objects within\n */\n// eslint-disable-next-line prefer-arrow/prefer-arrow-functions\nexport function parseHandles(\n value: any,\n serializer: IFluidSerializer,\n) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value !== undefined ? serializer.parse(JSON.stringify(value)) : value;\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGnE;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAC5B,KAAU,EACV,UAA4B,EAC5B,IAAkB;IAElB,+DAA+D;IAC/D,OAAO,KAAK,KAAK,SAAS;QACtB,CAAC,CAAC,UAAU,CAAC,SAAS,CAClB,KAAK,EACL,IAAI,CAAC;QACT,CAAC,CAAC,KAAK,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,uBAAuB,CACnC,KAAU,EACV,UAA4B,EAC5B,IAAkB;IAElB,+DAA+D;IAC/D,OAAO,UAAU,CAAC,MAAM,CACpB,KAAK,EACL,IAAI,CAAC,CAAC;AACd,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CACxB,KAAU,EACV,UAA4B;IAE5B,+DAA+D;IAC/D,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACjF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,GAAW,EAAE,OAA4B;IAC7E,MAAM,OAAO,GAAG,IAAI,kBAAkB,EAAE,CAAC;IACzC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC9B,OAAO,OAAO,CAAC,cAAc,EAAE,CAAC;AACpC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { IFluidSerializer } from \"./serializer\";\n\n/**\n * Given a mostly-plain object that may have handle objects embedded within, return a string representation of an object\n * where the handle objects have been replaced with a serializable form.\n * @param value - The mostly-plain object\n * @param serializer - The serializer that knows how to convert handles into serializable format\n * @param context - The handle context for the container\n * @param bind - Bind any other handles we find in the object against this given handle.\n * @returns Result of strigifying an object\n */\nexport function serializeHandles(\n value: any,\n serializer: IFluidSerializer,\n bind: IFluidHandle,\n): string | undefined {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value !== undefined\n ? serializer.stringify(\n value,\n bind)\n : value;\n}\n\n/**\n * Given a mostly-plain object that may have handle objects embedded within, will return a fully-plain object\n * where any embedded IFluidHandles have been replaced with a serializable form.\n *\n * The original `input` object is not mutated. This method will shallowly clones all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n *\n * @param input - The mostly-plain object\n * @param context - The handle context for the container\n * @param bind - Bind any other handles we find in the object against this given handle.\n * @returns The fully-plain object\n */\nexport function makeHandlesSerializable(\n value: any,\n serializer: IFluidSerializer,\n bind: IFluidHandle,\n) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return serializer.encode(\n value,\n bind);\n}\n\n/**\n * Given a fully-plain object that may have serializable-form handles within, will return the mostly-plain object\n * with handle objects created instead.\n * @param value - The fully-plain object\n * @param serializer - The serializer that knows how to convert serializable-form handles into handle objects\n * @param context - The handle context for the container\n * @returns The mostly-plain object with handle objects within\n */\nexport function parseHandles(\n value: any,\n serializer: IFluidSerializer,\n) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value !== undefined ? serializer.parse(JSON.stringify(value)) : value;\n}\n\n/**\n * Create a new summary containing one blob\n * @param key - the key for the blob in the summary\n * @param content - blob content\n * @returns The summary containing the blob\n */\nexport function createSingleBlobSummary(key: string, content: string | Uint8Array): ISummaryTreeWithStats {\n const builder = new SummaryTreeBuilder();\n builder.addBlob(key, content);\n return builder.getSummaryTree();\n}\n"]}