@fluidframework/shared-object-base 2.40.0-336023 → 2.40.0

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 (66) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/api-report/shared-object-base.legacy.alpha.api.md +1 -0
  3. package/dist/gcHandleVisitor.d.ts +1 -1
  4. package/dist/gcHandleVisitor.d.ts.map +1 -1
  5. package/dist/gcHandleVisitor.js +1 -1
  6. package/dist/gcHandleVisitor.js.map +1 -1
  7. package/dist/handle.d.ts +21 -1
  8. package/dist/handle.d.ts.map +1 -1
  9. package/dist/handle.js +10 -1
  10. package/dist/handle.js.map +1 -1
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +7 -1
  14. package/dist/index.js.map +1 -1
  15. package/dist/packageVersion.d.ts +1 -1
  16. package/dist/packageVersion.d.ts.map +1 -1
  17. package/dist/packageVersion.js +1 -1
  18. package/dist/packageVersion.js.map +1 -1
  19. package/dist/serializer.d.ts +3 -2
  20. package/dist/serializer.d.ts.map +1 -1
  21. package/dist/serializer.js +4 -2
  22. package/dist/serializer.js.map +1 -1
  23. package/dist/sharedObject.d.ts +11 -0
  24. package/dist/sharedObject.d.ts.map +1 -1
  25. package/dist/sharedObject.js +39 -6
  26. package/dist/sharedObject.js.map +1 -1
  27. package/dist/sharedObjectKernel.d.ts +186 -0
  28. package/dist/sharedObjectKernel.d.ts.map +1 -0
  29. package/dist/sharedObjectKernel.js +227 -0
  30. package/dist/sharedObjectKernel.js.map +1 -0
  31. package/lib/gcHandleVisitor.d.ts +1 -1
  32. package/lib/gcHandleVisitor.d.ts.map +1 -1
  33. package/lib/gcHandleVisitor.js +1 -1
  34. package/lib/gcHandleVisitor.js.map +1 -1
  35. package/lib/handle.d.ts +21 -1
  36. package/lib/handle.d.ts.map +1 -1
  37. package/lib/handle.js +8 -0
  38. package/lib/handle.js.map +1 -1
  39. package/lib/index.d.ts +2 -0
  40. package/lib/index.d.ts.map +1 -1
  41. package/lib/index.js +2 -0
  42. package/lib/index.js.map +1 -1
  43. package/lib/packageVersion.d.ts +1 -1
  44. package/lib/packageVersion.d.ts.map +1 -1
  45. package/lib/packageVersion.js +1 -1
  46. package/lib/packageVersion.js.map +1 -1
  47. package/lib/serializer.d.ts +3 -2
  48. package/lib/serializer.d.ts.map +1 -1
  49. package/lib/serializer.js +4 -2
  50. package/lib/serializer.js.map +1 -1
  51. package/lib/sharedObject.d.ts +11 -0
  52. package/lib/sharedObject.d.ts.map +1 -1
  53. package/lib/sharedObject.js +40 -7
  54. package/lib/sharedObject.js.map +1 -1
  55. package/lib/sharedObjectKernel.d.ts +186 -0
  56. package/lib/sharedObjectKernel.d.ts.map +1 -0
  57. package/lib/sharedObjectKernel.js +222 -0
  58. package/lib/sharedObjectKernel.js.map +1 -0
  59. package/package.json +15 -14
  60. package/src/gcHandleVisitor.ts +1 -4
  61. package/src/handle.ts +29 -1
  62. package/src/index.ts +11 -0
  63. package/src/packageVersion.ts +1 -1
  64. package/src/serializer.ts +7 -4
  65. package/src/sharedObject.ts +42 -5
  66. package/src/sharedObjectKernel.ts +467 -0
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
12
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
14
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
15
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
16
+ };
17
+ var _SharedObjectFromKernel_instances, _SharedObjectFromKernel_lazyData, _SharedObjectFromKernel_kernelArgs, _SharedObjectFromKernel_initializeData, _SharedObjectFromKernel_kernel_get;
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.makeSharedObjectKind = exports.mergeAPIs = exports.thisWrap = void 0;
20
+ const internal_1 = require("@fluidframework/core-utils/internal");
21
+ const sharedObject_js_1 = require("./sharedObject.js");
22
+ /**
23
+ * SharedObject implementation that delegates to a SharedKernel.
24
+ * @typeParam TOut - The type of the object exposed to the app.
25
+ * Once initialized, instances of this class forward properties to the `TOut` value provided by the factory.
26
+ * See {@link mergeAPIs} for more limitations.
27
+ *
28
+ * @remarks
29
+ * The App facing API (TOut) needs to be implemented by this object which also has to implement the runtime facing API (ISharedObject).
30
+ *
31
+ * Requiring both of these to be implemented by the same object adds some otherwise unnecessary coupling.
32
+ * This class is a workaround for that, which takes separate implementations of the two APIs and merges them into one using {@link mergeAPIs}.
33
+ */
34
+ class SharedObjectFromKernel extends sharedObject_js_1.SharedObject {
35
+ constructor(id, runtime, attributes, factory, telemetryContextPrefix) {
36
+ super(id, runtime, attributes, telemetryContextPrefix);
37
+ _SharedObjectFromKernel_instances.add(this);
38
+ this.factory = factory;
39
+ /**
40
+ * Lazy init here so kernel can be constructed in loadCore when loading from existing data.
41
+ *
42
+ * Explicit initialization to undefined is done so Proxy knows this property is from this class (via `Reflect.has`),
43
+ * not from the grafted APIs.
44
+ */
45
+ _SharedObjectFromKernel_lazyData.set(this, undefined);
46
+ _SharedObjectFromKernel_kernelArgs.set(this, void 0);
47
+ __classPrivateFieldSet(this, _SharedObjectFromKernel_kernelArgs, {
48
+ sharedObject: this,
49
+ serializer: this.serializer,
50
+ submitLocalMessage: (op, localOpMetadata) => this.submitLocalMessage(op, localOpMetadata),
51
+ eventEmitter: this,
52
+ logger: this.logger,
53
+ idCompressor: runtime.idCompressor,
54
+ lastSequenceNumber: () => this.deltaManager.lastSequenceNumber,
55
+ }, "f");
56
+ }
57
+ summarizeCore(serializer, telemetryContext, incrementalSummaryContext) {
58
+ return __classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "a", _SharedObjectFromKernel_kernel_get).summarizeCore(serializer, telemetryContext, incrementalSummaryContext);
59
+ }
60
+ initializeLocalCore() {
61
+ __classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "m", _SharedObjectFromKernel_initializeData).call(this, this.factory.create(__classPrivateFieldGet(this, _SharedObjectFromKernel_kernelArgs, "f")));
62
+ }
63
+ async loadCore(storage) {
64
+ __classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "m", _SharedObjectFromKernel_initializeData).call(this, await this.factory.loadCore(__classPrivateFieldGet(this, _SharedObjectFromKernel_kernelArgs, "f"), storage));
65
+ }
66
+ onDisconnect() {
67
+ __classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "a", _SharedObjectFromKernel_kernel_get).onDisconnect();
68
+ }
69
+ reSubmitCore(content, localOpMetadata) {
70
+ __classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "a", _SharedObjectFromKernel_kernel_get).reSubmitCore(content, localOpMetadata);
71
+ }
72
+ applyStashedOp(content) {
73
+ __classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "a", _SharedObjectFromKernel_kernel_get).applyStashedOp(content);
74
+ }
75
+ processCore() {
76
+ (0, internal_1.fail)("processCore should not be called");
77
+ }
78
+ processMessagesCore(messagesCollection) {
79
+ __classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "a", _SharedObjectFromKernel_kernel_get).processMessagesCore(messagesCollection);
80
+ }
81
+ rollback(content, localOpMetadata) {
82
+ if (__classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "a", _SharedObjectFromKernel_kernel_get).rollback === undefined) {
83
+ super.rollback(content, localOpMetadata);
84
+ }
85
+ else {
86
+ __classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "a", _SharedObjectFromKernel_kernel_get).rollback(content, localOpMetadata);
87
+ }
88
+ }
89
+ didAttach() {
90
+ __classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "a", _SharedObjectFromKernel_kernel_get).didAttach?.();
91
+ }
92
+ }
93
+ _SharedObjectFromKernel_lazyData = new WeakMap(), _SharedObjectFromKernel_kernelArgs = new WeakMap(), _SharedObjectFromKernel_instances = new WeakSet(), _SharedObjectFromKernel_initializeData = function _SharedObjectFromKernel_initializeData(data) {
94
+ (0, internal_1.assert)(__classPrivateFieldGet(this, _SharedObjectFromKernel_lazyData, "f") === undefined, "initializeData must be called first and only once");
95
+ __classPrivateFieldSet(this, _SharedObjectFromKernel_lazyData, data, "f");
96
+ // Make `this` implement TOut.
97
+ mergeAPIs(this, data.view);
98
+ }, _SharedObjectFromKernel_kernel_get = function _SharedObjectFromKernel_kernel_get() {
99
+ return (__classPrivateFieldGet(this, _SharedObjectFromKernel_lazyData, "f") ?? (0, internal_1.fail)("must initializeData first")).kernel;
100
+ };
101
+ /**
102
+ * When present on a method, it indicates the methods return value should be replaced with `this` (the wrapper)
103
+ * when wrapping the object with the method.
104
+ * @remarks
105
+ * This is useful when using {@link mergeAPIs} with methods where the return type is `this`, like `Map.set`.
106
+ * @internal
107
+ */
108
+ exports.thisWrap = Symbol("selfWrap");
109
+ /**
110
+ * Add getters to `base` which forward own properties from `extra`.
111
+ * @remarks
112
+ * This only handles use of "get" and "has".
113
+ * Therefore, APIs involving setting properties should not be used as `Extra`.
114
+ *
115
+ * Functions from `extra` are bound to the `extra` object and support {@link thisWrap}.
116
+ *
117
+ * Asserts when properties collide.
118
+ * @internal
119
+ */
120
+ function mergeAPIs(base, extra) {
121
+ for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(extra))) {
122
+ (0, internal_1.assert)(!Reflect.has(base, key), "colliding properties");
123
+ // Detect and special case functions.
124
+ // Currently this is done eagerly (when mergeAPIs is called) rather than lazily (when the property is read):
125
+ // this eager approach should result in slightly better performance,
126
+ // but if functions on `extra` are reassigned over time it will produce incorrect behavior.
127
+ // If this functionality is required, the design can be changed.
128
+ let getter;
129
+ // Bind functions to the extra object and handle thisWrap.
130
+ if (typeof descriptor.value === "function") {
131
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
132
+ const fromExtra = descriptor.value;
133
+ getter = () => forwardMethod(fromExtra, extra, base);
134
+ // To catch (and error on) cases where the function is reassigned and this eager binding approach is not appropriate, make it non-writable.
135
+ Object.defineProperty(extra, key, { ...descriptor, writable: false });
136
+ }
137
+ else {
138
+ getter = () => extra[key];
139
+ }
140
+ Object.defineProperty(base, key, {
141
+ configurable: false,
142
+ enumerable: descriptor.enumerable,
143
+ get: getter,
144
+ // If setters become required, support them here.
145
+ });
146
+ }
147
+ }
148
+ exports.mergeAPIs = mergeAPIs;
149
+ /**
150
+ * Wrap a method `f` of `oldThis` to be a method of `newThis`.
151
+ * @remarks
152
+ * The wrapped function will be called with `oldThis` as the `this` parameter.
153
+ * It also accounts for when `f` is marked with {@link thisWrap}.
154
+ */
155
+ function forwardMethod(f, oldThis, newThis) {
156
+ // eslint-disable-next-line unicorn/prefer-ternary
157
+ if (exports.thisWrap in f) {
158
+ return (...args) => {
159
+ const result = f.call(oldThis, ...args);
160
+ (0, internal_1.assert)(result === oldThis, "methods returning thisWrap should return this");
161
+ return newThis;
162
+ };
163
+ }
164
+ else {
165
+ return f.bind(oldThis);
166
+ }
167
+ }
168
+ /**
169
+ * Utility to create a {@link @fluidframework/datastore-definitions#IChannelFactory} classes.
170
+ * @remarks
171
+ * Use {@link makeSharedObjectKind} instead unless exposing the factory is required for legacy API compatibility.
172
+ * @internal
173
+ */
174
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
175
+ function makeChannelFactory(options) {
176
+ class ChannelFactory {
177
+ /**
178
+ * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory."type"}
179
+ */
180
+ get type() {
181
+ return ChannelFactory.Type;
182
+ }
183
+ /**
184
+ * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.attributes}
185
+ */
186
+ get attributes() {
187
+ return ChannelFactory.Attributes;
188
+ }
189
+ /**
190
+ * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}
191
+ */
192
+ async load(runtime, id, services, attributes) {
193
+ const shared = new SharedObjectFromKernel(id, runtime, attributes, options.factory, options.telemetryContextPrefix);
194
+ await shared.load(services);
195
+ return shared;
196
+ }
197
+ /**
198
+ * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}
199
+ */
200
+ create(runtime, id) {
201
+ const shared = new SharedObjectFromKernel(id, runtime, ChannelFactory.Attributes, options.factory, options.telemetryContextPrefix);
202
+ shared.initializeLocal();
203
+ return shared;
204
+ }
205
+ }
206
+ /**
207
+ * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory."type"}
208
+ */
209
+ ChannelFactory.Type = options.type;
210
+ /**
211
+ * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.attributes}
212
+ */
213
+ ChannelFactory.Attributes = options.attributes;
214
+ return ChannelFactory;
215
+ }
216
+ /**
217
+ * Utility to create a {@link SharedObjectKind}.
218
+ * @privateRemarks
219
+ * Using this API avoids having to subclasses any Fluid Framework types,
220
+ * reducing the coupling between the framework and the SharedObject implementation.
221
+ * @internal
222
+ */
223
+ function makeSharedObjectKind(options) {
224
+ return (0, sharedObject_js_1.createSharedObjectKind)(makeChannelFactory(options));
225
+ }
226
+ exports.makeSharedObjectKind = makeSharedObjectKind;
227
+ //# sourceMappingURL=sharedObjectKernel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharedObjectKernel.js","sourceRoot":"","sources":["../src/sharedObjectKernel.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;AAIH,kEAAmE;AAmBnE,uDAK2B;AAkE3B;;;;;;;;;;;GAW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I,CAAC;IAE3C;;OAEG;IACoB,yBAAU,GAAuB,OAAO,CAAC,UAAU,CAAC;IAsD5E,OAAO,cAAc,CAAC;AACvB,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,oBAAoB,CACnC,OAA+B;IAE/B,OAAO,IAAA,wCAAsB,EAAI,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;AAC/D,CAAC;AAJD,oDAIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport type { IFluidLoadable } from \"@fluidframework/core-interfaces\";\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIChannelStorageService,\n\ttype IChannel,\n\ttype IChannelAttributes,\n\ttype IChannelFactory,\n\ttype IChannelServices,\n\ttype IFluidDataStoreRuntime,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor/internal\";\nimport {\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n\ttype IExperimentalIncrementalSummaryContext,\n\ttype IRuntimeMessageCollection,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport type { ITelemetryLoggerExt } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { IFluidSerializer } from \"./serializer.js\";\nimport {\n\tcreateSharedObjectKind,\n\tSharedObject,\n\ttype ISharedObjectKind,\n\ttype SharedObjectKind,\n} from \"./sharedObject.js\";\nimport { ISharedObjectEvents, type ISharedObject } from \"./types.js\";\nimport type { IChannelView } from \"./utils.js\";\n\n/**\n * Functionality specific to a particular kind of {@link ISharedObject}.\n * @remarks\n * Shared objects expose APIs for two consumers:\n *\n * 1. The runtime, which uses {@link @fluidframework/datastore-definitions#IChannel} to summarize and apply ops and {@link @fluidframework/datastore-definitions#IChannelFactory} to create the load summaries.\n *\n * 2. The app, which uses shared object kind specific APIs to read and write data.\n *\n * There is some common functionality all shared objects use, provided by {@link SharedObject} and {@link SharedObjectCore}.\n * SharedKernel describes the portion of the behavior required by the runtime which\n * differs between different kinds of shared objects.\n *\n * {@link makeSharedObjectKind} is then used to wrap up the kernel into a full {@link ISharedObject} implementation.\n * The runtime specific APIs are then type erased into a {@link SharedObjectKind}.\n * @privateRemarks\n * Unlike the `SharedObject` class, this interface is internal, and thus can be adjusted more easily.\n * Therefore this interface is not intended to address all needs, and will likely need small changes as it gets more adoption.\n *\n * @internal\n */\nexport interface SharedKernel {\n\t/**\n\t * {@inheritDoc SharedObject.summarizeCore}\n\t */\n\tsummarizeCore(\n\t\tserializer: IFluidSerializer,\n\t\ttelemetryContext: ITelemetryContext | undefined,\n\t\tincrementalSummaryContext: IExperimentalIncrementalSummaryContext | undefined,\n\t): ISummaryTreeWithStats;\n\n\t/**\n\t * {@inheritDoc SharedObjectCore.onDisconnect}\n\t */\n\tonDisconnect(): void;\n\n\t/**\n\t * {@inheritDoc SharedObjectCore.reSubmitCore}\n\t */\n\treSubmitCore(content: unknown, localOpMetadata: unknown): void;\n\n\t/**\n\t * {@inheritDoc SharedObjectCore.applyStashedOp}\n\t */\n\tapplyStashedOp(content: unknown): void;\n\n\t/**\n\t * {@inheritDoc SharedObjectCore.processMessagesCore}\n\t */\n\tprocessMessagesCore(messagesCollection: IRuntimeMessageCollection): void;\n\n\t/**\n\t * {@inheritDoc SharedObjectCore.rollback}\n\t */\n\trollback?(content: unknown, localOpMetadata: unknown): void;\n\n\t/**\n\t * {@inheritDoc SharedObjectCore.didAttach}\n\t */\n\tdidAttach?(): void;\n}\n\n/**\n * SharedObject implementation that delegates to a SharedKernel.\n * @typeParam TOut - The type of the object exposed to the app.\n * Once initialized, instances of this class forward properties to the `TOut` value provided by the factory.\n * See {@link mergeAPIs} for more limitations.\n *\n * @remarks\n * The App facing API (TOut) needs to be implemented by this object which also has to implement the runtime facing API (ISharedObject).\n *\n * Requiring both of these to be implemented by the same object adds some otherwise unnecessary coupling.\n * This class is a workaround for that, which takes separate implementations of the two APIs and merges them into one using {@link mergeAPIs}.\n */\nclass SharedObjectFromKernel<\n\tTOut extends object,\n\tTEvent extends ISharedObjectEvents,\n> extends SharedObject<TEvent> {\n\t/**\n\t * Lazy init here so kernel can be constructed in loadCore when loading from existing data.\n\t *\n\t * Explicit initialization to undefined is done so Proxy knows this property is from this class (via `Reflect.has`),\n\t * not from the grafted APIs.\n\t */\n\t#lazyData: FactoryOut<TOut> | undefined = undefined;\n\n\treadonly #kernelArgs: KernelArgs;\n\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\tpublic readonly factory: SharedKernelFactory<TOut>,\n\t\ttelemetryContextPrefix: string,\n\t) {\n\t\tsuper(id, runtime, attributes, telemetryContextPrefix);\n\n\t\tthis.#kernelArgs = {\n\t\t\tsharedObject: this,\n\t\t\tserializer: this.serializer,\n\t\t\tsubmitLocalMessage: (op, localOpMetadata) =>\n\t\t\t\tthis.submitLocalMessage(op, localOpMetadata),\n\t\t\teventEmitter: this,\n\t\t\tlogger: this.logger,\n\t\t\tidCompressor: runtime.idCompressor,\n\t\t\tlastSequenceNumber: () => this.deltaManager.lastSequenceNumber,\n\t\t};\n\t}\n\n\tprotected override summarizeCore(\n\t\tserializer: IFluidSerializer,\n\t\ttelemetryContext?: ITelemetryContext,\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext,\n\t): ISummaryTreeWithStats {\n\t\treturn this.#kernel.summarizeCore(serializer, telemetryContext, incrementalSummaryContext);\n\t}\n\n\tprotected override initializeLocalCore(): void {\n\t\tthis.#initializeData(this.factory.create(this.#kernelArgs));\n\t}\n\n\t#initializeData(data: FactoryOut<TOut>): void {\n\t\tassert(this.#lazyData === undefined, \"initializeData must be called first and only once\");\n\t\tthis.#lazyData = data;\n\n\t\t// Make `this` implement TOut.\n\t\tmergeAPIs(this, data.view);\n\t}\n\n\tget #kernel(): SharedKernel {\n\t\treturn (this.#lazyData ?? fail(\"must initializeData first\")).kernel;\n\t}\n\n\tprotected override async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tthis.#initializeData(await this.factory.loadCore(this.#kernelArgs, storage));\n\t}\n\n\tprotected override onDisconnect(): void {\n\t\tthis.#kernel.onDisconnect();\n\t}\n\n\tprotected override reSubmitCore(content: unknown, localOpMetadata: unknown): void {\n\t\tthis.#kernel.reSubmitCore(content, localOpMetadata);\n\t}\n\n\tprotected override applyStashedOp(content: unknown): void {\n\t\tthis.#kernel.applyStashedOp(content);\n\t}\n\n\tprotected override processCore(): void {\n\t\tfail(\"processCore should not be called\");\n\t}\n\n\tprotected override processMessagesCore(messagesCollection: IRuntimeMessageCollection): void {\n\t\tthis.#kernel.processMessagesCore(messagesCollection);\n\t}\n\n\tprotected override rollback(content: unknown, localOpMetadata: unknown): void {\n\t\tif (this.#kernel.rollback === undefined) {\n\t\t\tsuper.rollback(content, localOpMetadata);\n\t\t} else {\n\t\t\tthis.#kernel.rollback(content, localOpMetadata);\n\t\t}\n\t}\n\n\tprotected override didAttach(): void {\n\t\tthis.#kernel.didAttach?.();\n\t}\n}\n\n/**\n * When present on a method, it indicates the methods return value should be replaced with `this` (the wrapper)\n * when wrapping the object with the method.\n * @remarks\n * This is useful when using {@link mergeAPIs} with methods where the return type is `this`, like `Map.set`.\n * @internal\n */\nexport const thisWrap: unique symbol = Symbol(\"selfWrap\");\n\n/**\n * A {@link SharedKernel} providing the implementation of some distributed data structure (DDS) and the needed runtime facing APIs,\n * and a separate view object which exposes the app facing APIs (`T`)\n * for reading and writing data which are specific to this particular data structure.\n * @remarks\n * Output from {@link SharedKernelFactory}.\n * This is an alternative to defining DDSs by sub-classing {@link SharedObject}.\n * @internal\n */\nexport interface FactoryOut<T extends object> {\n\treadonly kernel: SharedKernel;\n\treadonly view: T;\n}\n\n/**\n * A factory for creating DDSs.\n * @remarks\n * Outputs {@link FactoryOut}.\n * This is an alternative to directly implementing {@link @fluidframework/datastore-definitions#IChannelFactory}.\n * Use with {@link makeSharedObjectKind} to create a {@link SharedObjectKind}.\n * @internal\n */\nexport interface SharedKernelFactory<T extends object> {\n\tcreate(args: KernelArgs): FactoryOut<T>;\n\n\t/**\n\t * Create combined with {@link SharedObjectCore.loadCore}.\n\t */\n\tloadCore(args: KernelArgs, storage: IChannelStorageService): Promise<FactoryOut<T>>;\n}\n\n/**\n * Inputs for building a {@link SharedKernel} via {@link SharedKernelFactory}.\n * @internal\n */\nexport interface KernelArgs {\n\t/**\n\t * The shared object whose behavior is being implemented.\n\t */\n\treadonly sharedObject: IChannelView & IFluidLoadable;\n\t/**\n\t * {@inheritdoc SharedObject.serializer}\n\t */\n\treadonly serializer: IFluidSerializer;\n\t/**\n\t * {@inheritdoc SharedObjectCore.submitLocalMessage}\n\t */\n\treadonly submitLocalMessage: (op: unknown, localOpMetadata: unknown) => void;\n\t/**\n\t * Top level emitter for events for this object.\n\t * @remarks\n\t * This is needed since the separate kernel and view from {@link FactoryOut} currently have to be recombined,\n\t * and having this as its own thing helps accomplish that.\n\t */\n\treadonly eventEmitter: TypedEventEmitter<ISharedObjectEvents>;\n\t/**\n\t * {@inheritdoc SharedObjectCore.logger}\n\t */\n\treadonly logger: ITelemetryLoggerExt;\n\t/**\n\t * {@inheritdoc @fluidframework/datastore-definitions#IFluidDataStoreRuntime.idCompressor}\n\t */\n\treadonly idCompressor: IIdCompressor | undefined;\n\t/**\n\t * {@inheritdoc @fluidframework/container-definitions#IDeltaManager.lastSequenceNumber}\n\t */\n\treadonly lastSequenceNumber: () => number;\n}\n\n/**\n * Add getters to `base` which forward own properties from `extra`.\n * @remarks\n * This only handles use of \"get\" and \"has\".\n * Therefore, APIs involving setting properties should not be used as `Extra`.\n *\n * Functions from `extra` are bound to the `extra` object and support {@link thisWrap}.\n *\n * Asserts when properties collide.\n * @internal\n */\nexport function mergeAPIs<const Base extends object, const Extra extends object>(\n\tbase: Base,\n\textra: Extra,\n): asserts base is Base & Extra {\n\tfor (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(extra))) {\n\t\tassert(!Reflect.has(base, key), \"colliding properties\");\n\n\t\t// Detect and special case functions.\n\t\t// Currently this is done eagerly (when mergeAPIs is called) rather than lazily (when the property is read):\n\t\t// this eager approach should result in slightly better performance,\n\t\t// but if functions on `extra` are reassigned over time it will produce incorrect behavior.\n\t\t// If this functionality is required, the design can be changed.\n\t\tlet getter: () => unknown;\n\t\t// Bind functions to the extra object and handle thisWrap.\n\t\tif (typeof descriptor.value === \"function\") {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\tconst fromExtra: () => Extra | Base = descriptor.value;\n\t\t\tgetter = () => forwardMethod(fromExtra, extra, base);\n\t\t\t// To catch (and error on) cases where the function is reassigned and this eager binding approach is not appropriate, make it non-writable.\n\t\t\tObject.defineProperty(extra, key, { ...descriptor, writable: false });\n\t\t} else {\n\t\t\tgetter = () => extra[key];\n\t\t}\n\n\t\tObject.defineProperty(base, key, {\n\t\t\tconfigurable: false,\n\t\t\tenumerable: descriptor.enumerable,\n\t\t\tget: getter,\n\t\t\t// If setters become required, support them here.\n\t\t});\n\t}\n}\n\n/**\n * Wrap a method `f` of `oldThis` to be a method of `newThis`.\n * @remarks\n * The wrapped function will be called with `oldThis` as the `this` parameter.\n * It also accounts for when `f` is marked with {@link thisWrap}.\n */\nfunction forwardMethod<TArgs extends [], TReturn>(\n\tf: (...args: TArgs) => TReturn,\n\toldThis: TReturn,\n\tnewThis: TReturn,\n): (...args: TArgs) => TReturn {\n\t// eslint-disable-next-line unicorn/prefer-ternary\n\tif (thisWrap in f) {\n\t\treturn (...args: TArgs) => {\n\t\t\tconst result = f.call(oldThis, ...args);\n\t\t\tassert(result === oldThis, \"methods returning thisWrap should return this\");\n\t\t\treturn newThis;\n\t\t};\n\t} else {\n\t\treturn f.bind(oldThis);\n\t}\n}\n\n/**\n * Options for creating a {@link SharedObjectKind} via {@link makeSharedObjectKind}.\n * @typeParam T - The type of the object exposed to the app.\n * This can optionally include members from {@link ISharedObject} which will be provided automatically.\n * @internal\n */\nexport interface SharedObjectOptions<T extends object> {\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.\"type\"}\n\t */\n\treadonly type: string;\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.attributes}\n\t */\n\treadonly attributes: IChannelAttributes;\n\n\t/**\n\t * The factory used to create the kernel and its view.\n\t * @remarks\n\t * The view produced by this factory will be grafted onto the {@link SharedObject} using {@link mergeAPIs}.\n\t * See {@link mergeAPIs} for more information on limitations that apply.\n\t */\n\treadonly factory: SharedKernelFactory<Omit<T, keyof ISharedObject>>;\n\n\t/**\n\t * {@inheritDoc SharedObject.telemetryContextPrefix}\n\t */\n\treadonly telemetryContextPrefix: string;\n}\n\n/**\n * Utility to create a {@link @fluidframework/datastore-definitions#IChannelFactory} classes.\n * @remarks\n * Use {@link makeSharedObjectKind} instead unless exposing the factory is required for legacy API compatibility.\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nfunction makeChannelFactory<T extends object>(options: SharedObjectOptions<T>) {\n\tclass ChannelFactory implements IChannelFactory<T> {\n\t\t/**\n\t\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.\"type\"}\n\t\t */\n\t\tpublic static readonly Type = options.type;\n\n\t\t/**\n\t\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.attributes}\n\t\t */\n\t\tpublic static readonly Attributes: IChannelAttributes = options.attributes;\n\n\t\t/**\n\t\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.\"type\"}\n\t\t */\n\t\tpublic get type(): string {\n\t\t\treturn ChannelFactory.Type;\n\t\t}\n\n\t\t/**\n\t\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.attributes}\n\t\t */\n\t\tpublic get attributes(): IChannelAttributes {\n\t\t\treturn ChannelFactory.Attributes;\n\t\t}\n\n\t\t/**\n\t\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}\n\t\t */\n\t\tpublic async load(\n\t\t\truntime: IFluidDataStoreRuntime,\n\t\t\tid: string,\n\t\t\tservices: IChannelServices,\n\t\t\tattributes: IChannelAttributes,\n\t\t): Promise<T & IChannel> {\n\t\t\tconst shared = new SharedObjectFromKernel(\n\t\t\t\tid,\n\t\t\t\truntime,\n\t\t\t\tattributes,\n\t\t\t\toptions.factory,\n\t\t\t\toptions.telemetryContextPrefix,\n\t\t\t);\n\t\t\tawait shared.load(services);\n\t\t\treturn shared as unknown as T & IChannel;\n\t\t}\n\n\t\t/**\n\t\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}\n\t\t */\n\t\tpublic create(runtime: IFluidDataStoreRuntime, id: string): T & IChannel {\n\t\t\tconst shared = new SharedObjectFromKernel(\n\t\t\t\tid,\n\t\t\t\truntime,\n\t\t\t\tChannelFactory.Attributes,\n\t\t\t\toptions.factory,\n\t\t\t\toptions.telemetryContextPrefix,\n\t\t\t);\n\n\t\t\tshared.initializeLocal();\n\n\t\t\treturn shared as unknown as T & IChannel;\n\t\t}\n\t}\n\n\treturn ChannelFactory;\n}\n\n/**\n * Utility to create a {@link SharedObjectKind}.\n * @privateRemarks\n * Using this API avoids having to subclasses any Fluid Framework types,\n * reducing the coupling between the framework and the SharedObject implementation.\n * @internal\n */\nexport function makeSharedObjectKind<T extends object>(\n\toptions: SharedObjectOptions<T>,\n): ISharedObjectKind<T> & SharedObjectKind<T> {\n\treturn createSharedObjectKind<T>(makeChannelFactory(options));\n}\n"]}
@@ -14,6 +14,6 @@ import { FluidSerializer } from "./serializer.js";
14
14
  export declare class GCHandleVisitor extends FluidSerializer {
15
15
  private readonly visitedHandlePaths;
16
16
  getVisitedHandlePaths(): string[];
17
- protected bindAndEncodeHandle(handle: IFluidHandleInternal, bind: IFluidHandleInternal): ISerializedHandle;
17
+ protected bindAndEncodeHandle(handle: IFluidHandleInternal): ISerializedHandle;
18
18
  }
19
19
  //# sourceMappingURL=gcHandleVisitor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gcHandleVisitor.d.ts","sourceRoot":"","sources":["../src/gcHandleVisitor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAEhF,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;;;GAKG;AACH,qBAAa,eAAgB,SAAQ,eAAe;IACnD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA0B;IACtD,qBAAqB,IAAI,MAAM,EAAE;IAIxC,SAAS,CAAC,mBAAmB,CAC5B,MAAM,EAAE,oBAAoB,EAC5B,IAAI,EAAE,oBAAoB,GACxB,iBAAiB;CAUpB"}
1
+ {"version":3,"file":"gcHandleVisitor.d.ts","sourceRoot":"","sources":["../src/gcHandleVisitor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAEhF,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;;;GAKG;AACH,qBAAa,eAAgB,SAAQ,eAAe;IACnD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA0B;IACtD,qBAAqB,IAAI,MAAM,EAAE;IAIxC,SAAS,CAAC,mBAAmB,CAAC,MAAM,EAAE,oBAAoB,GAAG,iBAAiB;CAU9E"}
@@ -17,7 +17,7 @@ export class GCHandleVisitor extends FluidSerializer {
17
17
  getVisitedHandlePaths() {
18
18
  return [...this.visitedHandlePaths];
19
19
  }
20
- bindAndEncodeHandle(handle, bind) {
20
+ bindAndEncodeHandle(handle) {
21
21
  this.visitedHandlePaths.add(handle.absolutePath);
22
22
  // Just return a dummy value. The serialization itself is not used.
23
23
  // It's especially important we don't bind since that has side effects that are irrelevant to GC.
@@ -1 +1 @@
1
- {"version":3,"file":"gcHandleVisitor.js","sourceRoot":"","sources":["../src/gcHandleVisitor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;;;GAKG;AACH,MAAM,OAAO,eAAgB,SAAQ,eAAe;IAApD;;QACkB,uBAAkB,GAAgB,IAAI,GAAG,EAAE,CAAC;IAkB9D,CAAC;IAjBO,qBAAqB;QAC3B,OAAO,CAAC,GAAG,IAAI,CAAC,kBAAkB,CAAC,CAAC;IACrC,CAAC;IAES,mBAAmB,CAC5B,MAA4B,EAC5B,IAA0B;QAE1B,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAEjD,mEAAmE;QACnE,iGAAiG;QACjG,OAAO;YACN,IAAI,EAAE,kBAAkB;YACxB,GAAG,EAAE,8BAA8B;SACnC,CAAC;IACH,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { type IFluidHandleInternal } from \"@fluidframework/core-interfaces/internal\";\nimport { type ISerializedHandle } from \"@fluidframework/runtime-utils/internal\";\n\nimport { FluidSerializer } from \"./serializer.js\";\n\n/**\n * Implementation of IFluidSerializer used by GC to visit all the handles in the DDS to collect its outbound routes\n *\n * @remarks - This is given to DDS code that typically produces a serialization of the data, which is then ignored.\n * All that is needed is getSerializedRoutes() to get the routes. This strategy could be optimized if needed.\n */\nexport class GCHandleVisitor extends FluidSerializer {\n\tprivate readonly visitedHandlePaths: Set<string> = new Set();\n\tpublic getVisitedHandlePaths(): string[] {\n\t\treturn [...this.visitedHandlePaths];\n\t}\n\n\tprotected bindAndEncodeHandle(\n\t\thandle: IFluidHandleInternal,\n\t\tbind: IFluidHandleInternal,\n\t): ISerializedHandle {\n\t\tthis.visitedHandlePaths.add(handle.absolutePath);\n\n\t\t// Just return a dummy value. The serialization itself is not used.\n\t\t// It's especially important we don't bind since that has side effects that are irrelevant to GC.\n\t\treturn {\n\t\t\ttype: \"__fluid_handle__\",\n\t\t\turl: \"UNUSED (see GCHandleVisitor)\",\n\t\t};\n\t}\n}\n"]}
1
+ {"version":3,"file":"gcHandleVisitor.js","sourceRoot":"","sources":["../src/gcHandleVisitor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;;;GAKG;AACH,MAAM,OAAO,eAAgB,SAAQ,eAAe;IAApD;;QACkB,uBAAkB,GAAgB,IAAI,GAAG,EAAE,CAAC;IAe9D,CAAC;IAdO,qBAAqB;QAC3B,OAAO,CAAC,GAAG,IAAI,CAAC,kBAAkB,CAAC,CAAC;IACrC,CAAC;IAES,mBAAmB,CAAC,MAA4B;QACzD,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAEjD,mEAAmE;QACnE,iGAAiG;QACjG,OAAO;YACN,IAAI,EAAE,kBAAkB;YACxB,GAAG,EAAE,8BAA8B;SACnC,CAAC;IACH,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { type IFluidHandleInternal } from \"@fluidframework/core-interfaces/internal\";\nimport { type ISerializedHandle } from \"@fluidframework/runtime-utils/internal\";\n\nimport { FluidSerializer } from \"./serializer.js\";\n\n/**\n * Implementation of IFluidSerializer used by GC to visit all the handles in the DDS to collect its outbound routes\n *\n * @remarks - This is given to DDS code that typically produces a serialization of the data, which is then ignored.\n * All that is needed is getSerializedRoutes() to get the routes. This strategy could be optimized if needed.\n */\nexport class GCHandleVisitor extends FluidSerializer {\n\tprivate readonly visitedHandlePaths: Set<string> = new Set();\n\tpublic getVisitedHandlePaths(): string[] {\n\t\treturn [...this.visitedHandlePaths];\n\t}\n\n\tprotected bindAndEncodeHandle(handle: IFluidHandleInternal): ISerializedHandle {\n\t\tthis.visitedHandlePaths.add(handle.absolutePath);\n\n\t\t// Just return a dummy value. The serialization itself is not used.\n\t\t// It's especially important we don't bind since that has side effects that are irrelevant to GC.\n\t\treturn {\n\t\t\ttype: \"__fluid_handle__\",\n\t\t\turl: \"UNUSED (see GCHandleVisitor)\",\n\t\t};\n\t}\n}\n"]}
package/lib/handle.d.ts CHANGED
@@ -6,6 +6,26 @@ import { type IFluidHandleInternal } from "@fluidframework/core-interfaces/inter
6
6
  import { FluidObjectHandle } from "@fluidframework/datastore/internal";
7
7
  import type { IFluidDataStoreRuntimeExperimental } from "@fluidframework/datastore-definitions/internal";
8
8
  import { ISharedObject } from "./types.js";
9
+ /**
10
+ * Handle for a shared object. See also {@link SharedObjectHandle}.
11
+ * Supports binding other handles to the underlying Shared Object (see {@link ISharedObjectHandle.bind}).
12
+ *
13
+ * @internal
14
+ */
15
+ export interface ISharedObjectHandle extends IFluidHandleInternal<ISharedObject> {
16
+ /**
17
+ * Binds the given handle to this DDS or attach the given handle if this DDS is attached.
18
+ * A bound handle will also be attached once this DDS is attached.
19
+ *
20
+ * @param handle - The target handle to bind to this DDS
21
+ */
22
+ bind(handle: IFluidHandleInternal): void;
23
+ }
24
+ /**
25
+ * Type guard for {@link ISharedObjectHandle}.
26
+ * @internal
27
+ */
28
+ export declare function isISharedObjectHandle(handle: unknown): handle is ISharedObjectHandle;
9
29
  /**
10
30
  * Handle for a shared object.
11
31
  *
@@ -17,7 +37,7 @@ import { ISharedObject } from "./types.js";
17
37
  * {@link @fluidframework/datastore#FluidDataStoreRuntime.request} recognizes requests in the form of
18
38
  * '/\<shared object id\>' and loads shared object.
19
39
  */
20
- export declare class SharedObjectHandle extends FluidObjectHandle<ISharedObject> {
40
+ export declare class SharedObjectHandle extends FluidObjectHandle<ISharedObject> implements ISharedObjectHandle {
21
41
  protected readonly value: ISharedObject;
22
42
  private readonly runtime;
23
43
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAEvE,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,gDAAgD,CAAC;AAEzG,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;;;;GAUG;AACH,qBAAa,kBAAmB,SAAQ,iBAAiB,CAAC,aAAa,CAAC;IAgBtE,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,aAAa;IAGvC,OAAO,CAAC,QAAQ,CAAC,OAAO;IAlBzB;;OAEG;IACH,IAAW,UAAU,IAAI,OAAO,CAE/B;IAED;;;;;;OAMG;gBAEiB,KAAK,EAAE,aAAa,EACvC,IAAI,EAAE,MAAM,EAEK,OAAO,EAAE,kCAAkC;IAK7D;;;OAGG;IACI,WAAW,IAAI,IAAI;IAKnB,IAAI,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI;CAQ/C"}
1
+ {"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAEvE,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,gDAAgD,CAAC;AAGzG,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,WAAW,mBAAoB,SAAQ,oBAAoB,CAAC,aAAa,CAAC;IAC/E;;;;;OAKG;IACH,IAAI,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,CAAC;CACzC;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,mBAAmB,CAEpF;AAED;;;;;;;;;;GAUG;AACH,qBAAa,kBACZ,SAAQ,iBAAiB,CAAC,aAAa,CACvC,YAAW,mBAAmB;IAiB7B,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,aAAa;IAGvC,OAAO,CAAC,QAAQ,CAAC,OAAO;IAlBzB;;OAEG;IACH,IAAW,UAAU,IAAI,OAAO,CAE/B;IAED;;;;;;OAMG;gBAEiB,KAAK,EAAE,aAAa,EACvC,IAAI,EAAE,MAAM,EAEK,OAAO,EAAE,kCAAkC;IAK7D;;;OAGG;IACI,WAAW,IAAI,IAAI;IAKnB,IAAI,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI;CAQ/C"}
package/lib/handle.js CHANGED
@@ -3,6 +3,14 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { FluidObjectHandle } from "@fluidframework/datastore/internal";
6
+ import { isFluidHandle } from "@fluidframework/runtime-utils";
7
+ /**
8
+ * Type guard for {@link ISharedObjectHandle}.
9
+ * @internal
10
+ */
11
+ export function isISharedObjectHandle(handle) {
12
+ return isFluidHandle(handle) && typeof handle.bind === "function";
13
+ }
6
14
  /**
7
15
  * Handle for a shared object.
8
16
  *
package/lib/handle.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"handle.js","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAMvE;;;;;;;;;;GAUG;AACH,MAAM,OAAO,kBAAmB,SAAQ,iBAAgC;IACvE;;OAEG;IACH,IAAW,UAAU;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;IAChC,CAAC;IAED;;;;;;OAMG;IACH,YACoB,KAAoB,EACvC,IAAY;IACZ,gDAAgD;IAC/B,OAA2C;QAE5D,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;QAL7B,UAAK,GAAL,KAAK,CAAe;QAGtB,YAAO,GAAP,OAAO,CAAoC;IAG7D,CAAC;IAED;;;OAGG;IACI,WAAW;QACjB,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;QAC3B,KAAK,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;IAEM,IAAI,CAAC,MAA4B;QACvC,mFAAmF;QACnF,8GAA8G;QAC9G,wEAAwE;QACxE,IAAI,IAAI,CAAC,OAAO,CAAC,aAAa,KAAK,IAAI,EAAE,CAAC;YACzC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACpB,CAAC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { type IFluidHandleInternal } from \"@fluidframework/core-interfaces/internal\";\nimport { FluidObjectHandle } from \"@fluidframework/datastore/internal\";\n// eslint-disable-next-line import/no-deprecated\nimport type { IFluidDataStoreRuntimeExperimental } from \"@fluidframework/datastore-definitions/internal\";\n\nimport { ISharedObject } from \"./types.js\";\n\n/**\n * Handle for a shared object.\n *\n * @remarks\n *\n * This object is used for already loaded (in-memory) shared objects and is used only for serialization purposes.\n *\n * De-serialization process goes through {@link @fluidframework/datastore#FluidObjectHandle}, and request flow:\n * {@link @fluidframework/datastore#FluidDataStoreRuntime.request} recognizes requests in the form of\n * '/\\<shared object id\\>' and loads shared object.\n */\nexport class SharedObjectHandle extends FluidObjectHandle<ISharedObject> {\n\t/**\n\t * Whether services have been attached for the associated shared object.\n\t */\n\tpublic get isAttached(): boolean {\n\t\treturn this.value.isAttached();\n\t}\n\n\t/**\n\t * Creates a new SharedObjectHandle.\n\t * @param value - The shared object this handle is for.\n\t * @param path - The id of the shared object. It is also the path to this object relative to the routeContext.\n\t * @param routeContext - The parent {@link @fluidframework/core-interfaces#IFluidHandleContext} that has a route\n\t * to this handle.\n\t */\n\tconstructor(\n\t\tprotected readonly value: ISharedObject,\n\t\tpath: string,\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tprivate readonly runtime: IFluidDataStoreRuntimeExperimental,\n\t) {\n\t\tsuper(value, path, runtime.IFluidHandleContext);\n\t}\n\n\t/**\n\t * Attaches all bound handles first (which may in turn attach further handles), then attaches this handle.\n\t * When attaching the handle, it registers the associated shared object.\n\t */\n\tpublic attachGraph(): void {\n\t\tthis.value.bindToContext();\n\t\tsuper.attachGraph();\n\t}\n\n\tpublic bind(handle: IFluidHandleInternal): void {\n\t\t// We don't bind handles in staging mode to defer the attachment of any new objects\n\t\t// until we've exited staging mode. This way if we discard changes or a new handle is not present in the final\n\t\t// committed state, we will never end up attaching the discarded object.\n\t\tif (this.runtime.inStagingMode !== true) {\n\t\t\tsuper.bind(handle);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"handle.js","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAGvE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAoB9D;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAe;IACpD,OAAO,aAAa,CAAC,MAAM,CAAC,IAAI,OAAQ,MAA8B,CAAC,IAAI,KAAK,UAAU,CAAC;AAC5F,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,OAAO,kBACZ,SAAQ,iBAAgC;IAGxC;;OAEG;IACH,IAAW,UAAU;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;IAChC,CAAC;IAED;;;;;;OAMG;IACH,YACoB,KAAoB,EACvC,IAAY;IACZ,gDAAgD;IAC/B,OAA2C;QAE5D,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;QAL7B,UAAK,GAAL,KAAK,CAAe;QAGtB,YAAO,GAAP,OAAO,CAAoC;IAG7D,CAAC;IAED;;;OAGG;IACI,WAAW;QACjB,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;QAC3B,KAAK,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;IAEM,IAAI,CAAC,MAA4B;QACvC,mFAAmF;QACnF,8GAA8G;QAC9G,wEAAwE;QACxE,IAAI,IAAI,CAAC,OAAO,CAAC,aAAa,KAAK,IAAI,EAAE,CAAC;YACzC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACpB,CAAC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { type IFluidHandleInternal } from \"@fluidframework/core-interfaces/internal\";\nimport { FluidObjectHandle } from \"@fluidframework/datastore/internal\";\n// eslint-disable-next-line import/no-deprecated\nimport type { IFluidDataStoreRuntimeExperimental } from \"@fluidframework/datastore-definitions/internal\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils\";\n\nimport { ISharedObject } from \"./types.js\";\n\n/**\n * Handle for a shared object. See also {@link SharedObjectHandle}.\n * Supports binding other handles to the underlying Shared Object (see {@link ISharedObjectHandle.bind}).\n *\n * @internal\n */\nexport interface ISharedObjectHandle extends IFluidHandleInternal<ISharedObject> {\n\t/**\n\t * Binds the given handle to this DDS or attach the given handle if this DDS is attached.\n\t * A bound handle will also be attached once this DDS is attached.\n\t *\n\t * @param handle - The target handle to bind to this DDS\n\t */\n\tbind(handle: IFluidHandleInternal): void;\n}\n\n/**\n * Type guard for {@link ISharedObjectHandle}.\n * @internal\n */\nexport function isISharedObjectHandle(handle: unknown): handle is ISharedObjectHandle {\n\treturn isFluidHandle(handle) && typeof (handle as ISharedObjectHandle).bind === \"function\";\n}\n\n/**\n * Handle for a shared object.\n *\n * @remarks\n *\n * This object is used for already loaded (in-memory) shared objects and is used only for serialization purposes.\n *\n * De-serialization process goes through {@link @fluidframework/datastore#FluidObjectHandle}, and request flow:\n * {@link @fluidframework/datastore#FluidDataStoreRuntime.request} recognizes requests in the form of\n * '/\\<shared object id\\>' and loads shared object.\n */\nexport class SharedObjectHandle\n\textends FluidObjectHandle<ISharedObject>\n\timplements ISharedObjectHandle\n{\n\t/**\n\t * Whether services have been attached for the associated shared object.\n\t */\n\tpublic get isAttached(): boolean {\n\t\treturn this.value.isAttached();\n\t}\n\n\t/**\n\t * Creates a new SharedObjectHandle.\n\t * @param value - The shared object this handle is for.\n\t * @param path - The id of the shared object. It is also the path to this object relative to the routeContext.\n\t * @param routeContext - The parent {@link @fluidframework/core-interfaces#IFluidHandleContext} that has a route\n\t * to this handle.\n\t */\n\tconstructor(\n\t\tprotected readonly value: ISharedObject,\n\t\tpath: string,\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tprivate readonly runtime: IFluidDataStoreRuntimeExperimental,\n\t) {\n\t\tsuper(value, path, runtime.IFluidHandleContext);\n\t}\n\n\t/**\n\t * Attaches all bound handles first (which may in turn attach further handles), then attaches this handle.\n\t * When attaching the handle, it registers the associated shared object.\n\t */\n\tpublic attachGraph(): void {\n\t\tthis.value.bindToContext();\n\t\tsuper.attachGraph();\n\t}\n\n\tpublic bind(handle: IFluidHandleInternal): void {\n\t\t// We don't bind handles in staging mode to defer the attachment of any new objects\n\t\t// until we've exited staging mode. This way if we discard changes or a new handle is not present in the final\n\t\t// committed state, we will never end up attaching the discarded object.\n\t\tif (this.runtime.inStagingMode !== true) {\n\t\t\tsuper.bind(handle);\n\t\t}\n\t}\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -2,9 +2,11 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ export { ISharedObjectHandle, isISharedObjectHandle } from "./handle.js";
5
6
  export { FluidSerializer, IFluidSerializer } from "./serializer.js";
6
7
  export { SharedObject, SharedObjectCore, ISharedObjectKind, SharedObjectKind, createSharedObjectKind, } from "./sharedObject.js";
7
8
  export { ISharedObject, ISharedObjectEvents } from "./types.js";
8
9
  export { createSingleBlobSummary, makeHandlesSerializable, parseHandles, serializeHandles, bindHandles, type IChannelView, } from "./utils.js";
9
10
  export { ValueType } from "./valueType.js";
11
+ export { SharedKernel, thisWrap, KernelArgs, makeSharedObjectKind, SharedKernelFactory, FactoryOut, SharedObjectOptions, mergeAPIs, } from "./sharedObjectKernel.js";
10
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EACN,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EACN,uBAAuB,EACvB,uBAAuB,EACvB,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,KAAK,YAAY,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EACN,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EACN,uBAAuB,EACvB,uBAAuB,EACvB,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,KAAK,YAAY,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACN,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,oBAAoB,EACpB,mBAAmB,EACnB,UAAU,EACV,mBAAmB,EACnB,SAAS,GACT,MAAM,yBAAyB,CAAC"}
package/lib/index.js CHANGED
@@ -2,8 +2,10 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ export { isISharedObjectHandle } from "./handle.js";
5
6
  export { FluidSerializer } from "./serializer.js";
6
7
  export { SharedObject, SharedObjectCore, createSharedObjectKind, } from "./sharedObject.js";
7
8
  export { createSingleBlobSummary, makeHandlesSerializable, parseHandles, serializeHandles, bindHandles, } from "./utils.js";
8
9
  export { ValueType } from "./valueType.js";
10
+ export { thisWrap, makeSharedObjectKind, mergeAPIs, } from "./sharedObjectKernel.js";
9
11
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAoB,MAAM,iBAAiB,CAAC;AACpE,OAAO,EACN,YAAY,EACZ,gBAAgB,EAGhB,sBAAsB,GACtB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACN,uBAAuB,EACvB,uBAAuB,EACvB,YAAY,EACZ,gBAAgB,EAChB,WAAW,GAEX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { FluidSerializer, IFluidSerializer } from \"./serializer.js\";\nexport {\n\tSharedObject,\n\tSharedObjectCore,\n\tISharedObjectKind,\n\tSharedObjectKind,\n\tcreateSharedObjectKind,\n} from \"./sharedObject.js\";\nexport { ISharedObject, ISharedObjectEvents } from \"./types.js\";\nexport {\n\tcreateSingleBlobSummary,\n\tmakeHandlesSerializable,\n\tparseHandles,\n\tserializeHandles,\n\tbindHandles,\n\ttype IChannelView,\n} from \"./utils.js\";\nexport { ValueType } from \"./valueType.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAuB,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,eAAe,EAAoB,MAAM,iBAAiB,CAAC;AACpE,OAAO,EACN,YAAY,EACZ,gBAAgB,EAGhB,sBAAsB,GACtB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACN,uBAAuB,EACvB,uBAAuB,EACvB,YAAY,EACZ,gBAAgB,EAChB,WAAW,GAEX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAEN,QAAQ,EAER,oBAAoB,EAIpB,SAAS,GACT,MAAM,yBAAyB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { ISharedObjectHandle, isISharedObjectHandle } from \"./handle.js\";\nexport { FluidSerializer, IFluidSerializer } from \"./serializer.js\";\nexport {\n\tSharedObject,\n\tSharedObjectCore,\n\tISharedObjectKind,\n\tSharedObjectKind,\n\tcreateSharedObjectKind,\n} from \"./sharedObject.js\";\nexport { ISharedObject, ISharedObjectEvents } from \"./types.js\";\nexport {\n\tcreateSingleBlobSummary,\n\tmakeHandlesSerializable,\n\tparseHandles,\n\tserializeHandles,\n\tbindHandles,\n\ttype IChannelView,\n} from \"./utils.js\";\nexport { ValueType } from \"./valueType.js\";\nexport {\n\tSharedKernel,\n\tthisWrap,\n\tKernelArgs,\n\tmakeSharedObjectKind,\n\tSharedKernelFactory,\n\tFactoryOut,\n\tSharedObjectOptions,\n\tmergeAPIs,\n} from \"./sharedObjectKernel.js\";\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/shared-object-base";
8
- export declare const pkgVersion = "2.40.0-336023";
8
+ export declare const pkgVersion = "2.40.0";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,uCAAuC,CAAC;AAC5D,eAAO,MAAM,UAAU,kBAAkB,CAAC"}
1
+ {"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,uCAAuC,CAAC;AAC5D,eAAO,MAAM,UAAU,WAAW,CAAC"}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export const pkgName = "@fluidframework/shared-object-base";
8
- export const pkgVersion = "2.40.0-336023";
8
+ export const pkgVersion = "2.40.0";
9
9
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,oCAAoC,CAAC;AAC5D,MAAM,CAAC,MAAM,UAAU,GAAG,eAAe,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/shared-object-base\";\nexport const pkgVersion = \"2.40.0-336023\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,oCAAoC,CAAC;AAC5D,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/shared-object-base\";\nexport const pkgVersion = \"2.40.0\";\n"]}
@@ -5,6 +5,7 @@
5
5
  import { IFluidHandle } from "@fluidframework/core-interfaces";
6
6
  import { IFluidHandleContext, type IFluidHandleInternal } from "@fluidframework/core-interfaces/internal";
7
7
  import { type ISerializedHandle } from "@fluidframework/runtime-utils/internal";
8
+ import { type ISharedObjectHandle } from "./handle.js";
8
9
  /**
9
10
  * @legacy
10
11
  * @alpha
@@ -81,7 +82,7 @@ export declare class FluidSerializer implements IFluidSerializer {
81
82
  * If the given 'value' is an IFluidHandle, returns the encoded IFluidHandle.
82
83
  * Otherwise returns the original 'value'. Used by 'encode()' and 'stringify()'.
83
84
  */
84
- protected encodeValue(value: unknown, bind?: IFluidHandleInternal): unknown;
85
+ protected encodeValue(value: unknown, bind?: ISharedObjectHandle): unknown;
85
86
  /**
86
87
  * If the given 'value' is an encoded IFluidHandle, returns the decoded IFluidHandle.
87
88
  * Otherwise returns the original 'value'. Used by 'decode()' and 'parse()'.
@@ -100,6 +101,6 @@ export declare class FluidSerializer implements IFluidSerializer {
100
101
  * @param bind - The binding context for the handle (the handle will become attached whenever this context is attached).
101
102
  * @returns The serialized handle.
102
103
  */
103
- protected bindAndEncodeHandle(handle: IFluidHandleInternal, bind: IFluidHandleInternal): ISerializedHandle;
104
+ protected bindAndEncodeHandle(handle: IFluidHandleInternal, bind: ISharedObjectHandle): ISerializedHandle;
104
105
  }
105
106
  //# sourceMappingURL=serializer.d.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AAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,oBAAoB,GAAG,OAAO;IAUlE;;;;;;;;OAQG;IACI,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAStC;;;;OAIG;IACI,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,GAAG,MAAM;IAK5D;;OAEG;IACI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIpC;;;OAGG;IACH,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,mBAAmB,GAAG,OAAO;IAS1E;;;OAGG;IACH,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAmB9C;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IA4C1B;;;;;;OAMG;IACH,SAAS,CAAC,mBAAmB,CAC5B,MAAM,EAAE,oBAAoB,EAC5B,IAAI,EAAE,mBAAmB,GACvB,iBAAiB;CAIpB"}
package/lib/serializer.js CHANGED
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import { assert, shallowCloneObject } from "@fluidframework/core-utils/internal";
6
6
  import { encodeHandleForSerialization, generateHandleContextPath, isSerializedHandle, isFluidHandle, toFluidHandleInternal, RemoteFluidObjectHandle, } from "@fluidframework/runtime-utils/internal";
7
+ import { isISharedObjectHandle } from "./handle.js";
7
8
  /**
8
9
  * Data Store serializer implementation
9
10
  * @internal
@@ -29,6 +30,7 @@ export class FluidSerializer {
29
30
  * Any unbound handles encountered are bound to the provided IFluidHandle.
30
31
  */
31
32
  encode(input, bind) {
33
+ assert(isISharedObjectHandle(bind), 0xb8c /* bind must be an ISharedObjectHandle */);
32
34
  // If the given 'input' cannot contain handles, return it immediately. Otherwise,
33
35
  // return the result of 'recursivelyReplace()'.
34
36
  // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
@@ -59,8 +61,8 @@ export class FluidSerializer {
59
61
  * being bound to the given bind context in the process.
60
62
  */
61
63
  stringify(input, bind) {
62
- const bindInternal = toFluidHandleInternal(bind);
63
- return JSON.stringify(input, (key, value) => this.encodeValue(value, bindInternal));
64
+ assert(isISharedObjectHandle(bind), 0xb8d /* bind must be an ISharedObjectHandle */);
65
+ return JSON.stringify(input, (key, value) => this.encodeValue(value, bind));
64
66
  }
65
67
  /**
66
68
  * Parses the serialized data - context must match the context with which the JSON was stringified
@@ -1 +1 @@
1
- {"version":3,"file":"serializer.js","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EACN,4BAA4B,EAC5B,yBAAyB,EACzB,kBAAkB,EAClB,aAAa,EACb,qBAAqB,EAErB,uBAAuB,GACvB,MAAM,wCAAwC,CAAC;AAuChD;;;GAGG;AACH,MAAM,OAAO,eAAe;IAG3B,YAAoC,OAA4B;QAA5B,YAAO,GAAP,OAAO,CAAqB;QAC/D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC;QACzB,OAAO,IAAI,CAAC,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YAC7C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC;QACpC,CAAC;IACF,CAAC;IAED,IAAW,gBAAgB;QAC1B,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;;;;;;OAQG;IACI,MAAM,CAAC,KAAc,EAAE,IAA0B;QACvD,kFAAkF;QAClF,+CAA+C;QAC/C,yEAAyE;QACzE,OAAO,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;YAC1C,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC;YACnE,CAAC,CAAC,KAAK,CAAC;IACV,CAAC;IAED;;;;;;;;O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C,KAAK,CAAC,CAAC;oBAEpC,+EAA+E;oBAC/E,KAAK,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;gBACvB,CAAC;YACF,CAAC;QACF,CAAC;QACD,OAAO,KAAK,IAAI,KAAK,CAAC;IACvB,CAAC;IAED;;;;;;OAMG;IACO,mBAAmB,CAC5B,MAA4B,EAC5B,IAA0B;QAE1B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClB,OAAO,4BAA4B,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;CACD","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 {\n\tIFluidHandleContext,\n\ttype IFluidHandleInternal,\n} from \"@fluidframework/core-interfaces/internal\";\nimport { assert, shallowCloneObject } from \"@fluidframework/core-utils/internal\";\nimport {\n\tencodeHandleForSerialization,\n\tgenerateHandleContextPath,\n\tisSerializedHandle,\n\tisFluidHandle,\n\ttoFluidHandleInternal,\n\ttype ISerializedHandle,\n\tRemoteFluidObjectHandle,\n} from \"@fluidframework/runtime-utils/internal\";\n\n/**\n * @legacy\n * @alpha\n */\nexport interface IFluidSerializer {\n\t/**\n\t * Given a mostly-plain object that may have handle objects embedded within, will return a fully-plain object\n\t * where any embedded IFluidHandles have been replaced with a serializable form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clones all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t */\n\tencode(value: unknown, bind: IFluidHandle): unknown;\n\n\t/**\n\t * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n\t * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t *\n\t * The decoded handles are implicitly bound to the handle context of this serializer.\n\t */\n\tdecode(input: unknown): unknown;\n\n\t/**\n\t * Stringifies a given value. Converts any IFluidHandle to its stringified equivalent.\n\t */\n\tstringify(value: unknown, bind: IFluidHandle): string;\n\n\t/**\n\t * Parses the given JSON input string and returns the JavaScript object defined by it. Any Fluid\n\t * handles will be realized as part of the parse\n\t */\n\tparse(value: string): unknown;\n}\n\n/**\n * Data Store serializer implementation\n * @internal\n */\nexport class FluidSerializer implements IFluidSerializer {\n\tprivate readonly root: IFluidHandleContext;\n\n\tpublic constructor(private readonly context: IFluidHandleContext) {\n\t\tthis.root = this.context;\n\t\twhile (this.root.routeContext !== undefined) {\n\t\t\tthis.root = this.root.routeContext;\n\t\t}\n\t}\n\n\tpublic get IFluidSerializer(): IFluidSerializer {\n\t\treturn this;\n\t}\n\n\t/**\n\t * Given a mostly-jsonable object tree that may have handle objects embedded within, will return a\n\t * fully-jsonable object tree where any embedded IFluidHandles have been replaced with a serializable form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t *\n\t * Any unbound handles encountered are bound to the provided IFluidHandle.\n\t */\n\tpublic encode(input: unknown, bind: IFluidHandleInternal): unknown {\n\t\t// If the given 'input' cannot contain handles, return it immediately. Otherwise,\n\t\t// return the result of 'recursivelyReplace()'.\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\treturn !!input && typeof input === \"object\"\n\t\t\t? this.recursivelyReplace(input, this.encodeValue.bind(this), bind)\n\t\t\t: input;\n\t}\n\n\t/**\n\t * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n\t * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t *\n\t * The decoded handles are implicitly bound to the handle context of this serializer.\n\t */\n\tpublic decode(input: unknown): unknown {\n\t\t// If the given 'input' cannot contain handles, return it immediately. Otherwise,\n\t\t// return the result of 'recursivelyReplace()'.\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\treturn !!input && typeof input === \"object\"\n\t\t\t? this.recursivelyReplace(input, this.decodeValue.bind(this))\n\t\t\t: input;\n\t}\n\n\t/**\n\t * Serializes the input object into a JSON string.\n\t * Any IFluidHandles in the object will be replaced with their serialized form before stringify,\n\t * being bound to the given bind context in the process.\n\t */\n\tpublic stringify(input: unknown, bind: IFluidHandle): string {\n\t\tconst bindInternal = toFluidHandleInternal(bind);\n\t\treturn JSON.stringify(input, (key, value) => this.encodeValue(value, bindInternal));\n\t}\n\n\t/**\n\t * Parses the serialized data - context must match the context with which the JSON was stringified\n\t */\n\tpublic parse(input: string): unknown {\n\t\treturn JSON.parse(input, (key, value) => this.decodeValue(value));\n\t}\n\n\t/**\n\t * If the given 'value' is an IFluidHandle, returns the encoded IFluidHandle.\n\t * Otherwise returns the original 'value'. Used by 'encode()' and 'stringify()'.\n\t */\n\tprotected encodeValue(value: unknown, bind?: IFluidHandleInternal): unknown {\n\t\t// If 'value' is an IFluidHandle return its encoded form.\n\t\tif (isFluidHandle(value)) {\n\t\t\tassert(bind !== undefined, 0xa93 /* Cannot encode a handle without a bind context */);\n\t\t\treturn this.bindAndEncodeHandle(toFluidHandleInternal(value), bind);\n\t\t}\n\t\treturn value;\n\t}\n\n\t/**\n\t * If the given 'value' is an encoded IFluidHandle, returns the decoded IFluidHandle.\n\t * Otherwise returns the original 'value'. Used by 'decode()' and 'parse()'.\n\t */\n\tprotected decodeValue(value: unknown): unknown {\n\t\t// If 'value' is a serialized IFluidHandle return the deserialized result.\n\t\tif (isSerializedHandle(value)) {\n\t\t\t// Old documents may have handles with relative path in their summaries. Convert these to absolute\n\t\t\t// paths. This will ensure that future summaries will have absolute paths for these handles.\n\t\t\tconst absolutePath = value.url.startsWith(\"/\")\n\t\t\t\t? value.url\n\t\t\t\t: generateHandleContextPath(value.url, this.context);\n\n\t\t\treturn new RemoteFluidObjectHandle(\n\t\t\t\tabsolutePath,\n\t\t\t\tthis.root,\n\t\t\t\tvalue.payloadPending === true,\n\t\t\t);\n\t\t} else {\n\t\t\treturn value;\n\t\t}\n\t}\n\n\t/**\n\t * Invoked for non-null objects to recursively replace references to IFluidHandles.\n\t * Clones as-needed to avoid mutating the `input` object. If no IFluidHandles are present,\n\t * returns the original `input`.\n\t */\n\tprivate recursivelyReplace<TContext = unknown>(\n\t\tinput: object,\n\t\treplacer: (input: unknown, context?: TContext) => unknown,\n\t\tcontext?: TContext,\n\t): unknown {\n\t\t// Note: Caller is responsible for ensuring that `input` is defined / non-null.\n\t\t// (Required for Object.keys() below.)\n\n\t\t// Execute the `replace` on the current input. Note that Caller is responsible for ensuring that `input`\n\t\t// is a non-null object.\n\t\tconst maybeReplaced = replacer(input, context);\n\n\t\t// If either input or the replaced result is a Fluid Handle, there is no need to descend further.\n\t\t// IFluidHandles are always leaves in the object graph, and the code below cannot deal with IFluidHandle's structure.\n\t\tif (isFluidHandle(input) || isFluidHandle(maybeReplaced)) {\n\t\t\treturn maybeReplaced;\n\t\t}\n\n\t\t// Otherwise descend into the object graph looking for IFluidHandle instances.\n\t\tlet clone: object | undefined;\n\t\tfor (const key of Object.keys(input)) {\n\t\t\tconst value: unknown = input[key];\n\t\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\t\tif (!!value && typeof value === \"object\") {\n\t\t\t\t// Note: Except for IFluidHandle, `input` must not contain circular references (as object must\n\t\t\t\t// be JSON serializable.) Therefore, guarding against infinite recursion here would only\n\t\t\t\t// lead to a later error when attempting to stringify().\n\t\t\t\tconst replaced = this.recursivelyReplace(value, replacer, context);\n\n\t\t\t\t// If the `replaced` object is different than the original `value` then the subgraph contained one\n\t\t\t\t// or more handles. If this happens, we need to return a clone of the `input` object where the\n\t\t\t\t// current property is replaced by the `replaced` value.\n\t\t\t\tif (replaced !== value) {\n\t\t\t\t\t// Lazily create a shallow clone of the `input` object if we haven't done so already.\n\t\t\t\t\tclone ??= shallowCloneObject(input);\n\n\t\t\t\t\t// Overwrite the current property `key` in the clone with the `replaced` value.\n\t\t\t\t\tclone[key] = replaced;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn clone ?? input;\n\t}\n\n\t/**\n\t * Encodes the given IFluidHandle into a JSON-serializable form,\n\t * also binding it to another node to ensure it attaches at the right time.\n\t * @param handle - The IFluidHandle to serialize.\n\t * @param bind - The binding context for the handle (the handle will become attached whenever this context is attached).\n\t * @returns The serialized handle.\n\t */\n\tprotected bindAndEncodeHandle(\n\t\thandle: IFluidHandleInternal,\n\t\tbind: IFluidHandleInternal,\n\t): ISerializedHandle {\n\t\tbind.bind(handle);\n\t\treturn encodeHandleForSerialization(handle);\n\t}\n}\n"]}
1
+ {"version":3,"file":"serializer.js","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EACN,4BAA4B,EAC5B,yBAAyB,EACzB,kBAAkB,EAClB,aAAa,EACb,qBAAqB,EAErB,uBAAuB,GACvB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,qBAAqB,EAA4B,MAAM,aAAa,CAAC;AAuC9E;;;GAGG;AACH,MAAM,OAAO,eAAe;IAG3B,YAAoC,OAA4B;QAA5B,YAAO,GAAP,OAAO,CAAqB;QAC/D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC;QACzB,OAAO,IAAI,CAAC,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YAC7C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC;QACpC,CAAC;IACF,CAAC;IAED,IAAW,gBAAgB;QAC1B,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;;;;;;OAQG;IACI,MAAM,CAAC,KAAc,EAAE,IAA0B;QACvD,MAAM,CAAC,qBAAqB,CAAC,IAAI,CAA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AAI,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC1C,8FAA8F;gBAC9F,+FAA+F;gBAC/F,8DAA8D;gBAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;gBAEnE,kGAAkG;gBAClG,+FAA+F;gBAC/F,wDAAwD;gBACxD,IAAI,QAAQ,KAAK,KAAK,EAAE,CAAC;oBACxB,qFAAqF;oBACrF,KAAK,KAAK,kBAAkB,CAAC,KAAK,CAAC,CAAC;oBAEpC,+EAA+E;oBAC/E,KAAK,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;gBACvB,CAAC;YACF,CAAC;QACF,CAAC;QACD,OAAO,KAAK,IAAI,KAAK,CAAC;IACvB,CAAC;IAED;;;;;;OAMG;IACO,mBAAmB,CAC5B,MAA4B,EAC5B,IAAyB;QAEzB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClB,OAAO,4BAA4B,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;CACD","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 {\n\tIFluidHandleContext,\n\ttype IFluidHandleInternal,\n} from \"@fluidframework/core-interfaces/internal\";\nimport { assert, shallowCloneObject } from \"@fluidframework/core-utils/internal\";\nimport {\n\tencodeHandleForSerialization,\n\tgenerateHandleContextPath,\n\tisSerializedHandle,\n\tisFluidHandle,\n\ttoFluidHandleInternal,\n\ttype ISerializedHandle,\n\tRemoteFluidObjectHandle,\n} from \"@fluidframework/runtime-utils/internal\";\n\nimport { isISharedObjectHandle, type ISharedObjectHandle } from \"./handle.js\";\n\n/**\n * @legacy\n * @alpha\n */\nexport interface IFluidSerializer {\n\t/**\n\t * Given a mostly-plain object that may have handle objects embedded within, will return a fully-plain object\n\t * where any embedded IFluidHandles have been replaced with a serializable form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clones all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t */\n\tencode(value: unknown, bind: IFluidHandle): unknown;\n\n\t/**\n\t * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n\t * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t *\n\t * The decoded handles are implicitly bound to the handle context of this serializer.\n\t */\n\tdecode(input: unknown): unknown;\n\n\t/**\n\t * Stringifies a given value. Converts any IFluidHandle to its stringified equivalent.\n\t */\n\tstringify(value: unknown, bind: IFluidHandle): string;\n\n\t/**\n\t * Parses the given JSON input string and returns the JavaScript object defined by it. Any Fluid\n\t * handles will be realized as part of the parse\n\t */\n\tparse(value: string): unknown;\n}\n\n/**\n * Data Store serializer implementation\n * @internal\n */\nexport class FluidSerializer implements IFluidSerializer {\n\tprivate readonly root: IFluidHandleContext;\n\n\tpublic constructor(private readonly context: IFluidHandleContext) {\n\t\tthis.root = this.context;\n\t\twhile (this.root.routeContext !== undefined) {\n\t\t\tthis.root = this.root.routeContext;\n\t\t}\n\t}\n\n\tpublic get IFluidSerializer(): IFluidSerializer {\n\t\treturn this;\n\t}\n\n\t/**\n\t * Given a mostly-jsonable object tree that may have handle objects embedded within, will return a\n\t * fully-jsonable object tree where any embedded IFluidHandles have been replaced with a serializable form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t *\n\t * Any unbound handles encountered are bound to the provided IFluidHandle.\n\t */\n\tpublic encode(input: unknown, bind: IFluidHandleInternal): unknown {\n\t\tassert(isISharedObjectHandle(bind), 0xb8c /* bind must be an ISharedObjectHandle */);\n\t\t// If the given 'input' cannot contain handles, return it immediately. Otherwise,\n\t\t// return the result of 'recursivelyReplace()'.\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\treturn !!input && typeof input === \"object\"\n\t\t\t? this.recursivelyReplace(input, this.encodeValue.bind(this), bind)\n\t\t\t: input;\n\t}\n\n\t/**\n\t * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n\t * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t *\n\t * The decoded handles are implicitly bound to the handle context of this serializer.\n\t */\n\tpublic decode(input: unknown): unknown {\n\t\t// If the given 'input' cannot contain handles, return it immediately. Otherwise,\n\t\t// return the result of 'recursivelyReplace()'.\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\treturn !!input && typeof input === \"object\"\n\t\t\t? this.recursivelyReplace(input, this.decodeValue.bind(this))\n\t\t\t: input;\n\t}\n\n\t/**\n\t * Serializes the input object into a JSON string.\n\t * Any IFluidHandles in the object will be replaced with their serialized form before stringify,\n\t * being bound to the given bind context in the process.\n\t */\n\tpublic stringify(input: unknown, bind: IFluidHandle): string {\n\t\tassert(isISharedObjectHandle(bind), 0xb8d /* bind must be an ISharedObjectHandle */);\n\t\treturn JSON.stringify(input, (key, value) => this.encodeValue(value, bind));\n\t}\n\n\t/**\n\t * Parses the serialized data - context must match the context with which the JSON was stringified\n\t */\n\tpublic parse(input: string): unknown {\n\t\treturn JSON.parse(input, (key, value) => this.decodeValue(value));\n\t}\n\n\t/**\n\t * If the given 'value' is an IFluidHandle, returns the encoded IFluidHandle.\n\t * Otherwise returns the original 'value'. Used by 'encode()' and 'stringify()'.\n\t */\n\tprotected encodeValue(value: unknown, bind?: ISharedObjectHandle): unknown {\n\t\t// If 'value' is an IFluidHandle return its encoded form.\n\t\tif (isFluidHandle(value)) {\n\t\t\tassert(bind !== undefined, 0xa93 /* Cannot encode a handle without a bind context */);\n\t\t\treturn this.bindAndEncodeHandle(toFluidHandleInternal(value), bind);\n\t\t}\n\t\treturn value;\n\t}\n\n\t/**\n\t * If the given 'value' is an encoded IFluidHandle, returns the decoded IFluidHandle.\n\t * Otherwise returns the original 'value'. Used by 'decode()' and 'parse()'.\n\t */\n\tprotected decodeValue(value: unknown): unknown {\n\t\t// If 'value' is a serialized IFluidHandle return the deserialized result.\n\t\tif (isSerializedHandle(value)) {\n\t\t\t// Old documents may have handles with relative path in their summaries. Convert these to absolute\n\t\t\t// paths. This will ensure that future summaries will have absolute paths for these handles.\n\t\t\tconst absolutePath = value.url.startsWith(\"/\")\n\t\t\t\t? value.url\n\t\t\t\t: generateHandleContextPath(value.url, this.context);\n\n\t\t\treturn new RemoteFluidObjectHandle(\n\t\t\t\tabsolutePath,\n\t\t\t\tthis.root,\n\t\t\t\tvalue.payloadPending === true,\n\t\t\t);\n\t\t} else {\n\t\t\treturn value;\n\t\t}\n\t}\n\n\t/**\n\t * Invoked for non-null objects to recursively replace references to IFluidHandles.\n\t * Clones as-needed to avoid mutating the `input` object. If no IFluidHandles are present,\n\t * returns the original `input`.\n\t */\n\tprivate recursivelyReplace<TContext = unknown>(\n\t\tinput: object,\n\t\treplacer: (input: unknown, context?: TContext) => unknown,\n\t\tcontext?: TContext,\n\t): unknown {\n\t\t// Note: Caller is responsible for ensuring that `input` is defined / non-null.\n\t\t// (Required for Object.keys() below.)\n\n\t\t// Execute the `replace` on the current input. Note that Caller is responsible for ensuring that `input`\n\t\t// is a non-null object.\n\t\tconst maybeReplaced = replacer(input, context);\n\n\t\t// If either input or the replaced result is a Fluid Handle, there is no need to descend further.\n\t\t// IFluidHandles are always leaves in the object graph, and the code below cannot deal with IFluidHandle's structure.\n\t\tif (isFluidHandle(input) || isFluidHandle(maybeReplaced)) {\n\t\t\treturn maybeReplaced;\n\t\t}\n\n\t\t// Otherwise descend into the object graph looking for IFluidHandle instances.\n\t\tlet clone: object | undefined;\n\t\tfor (const key of Object.keys(input)) {\n\t\t\tconst value: unknown = input[key];\n\t\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\t\tif (!!value && typeof value === \"object\") {\n\t\t\t\t// Note: Except for IFluidHandle, `input` must not contain circular references (as object must\n\t\t\t\t// be JSON serializable.) Therefore, guarding against infinite recursion here would only\n\t\t\t\t// lead to a later error when attempting to stringify().\n\t\t\t\tconst replaced = this.recursivelyReplace(value, replacer, context);\n\n\t\t\t\t// If the `replaced` object is different than the original `value` then the subgraph contained one\n\t\t\t\t// or more handles. If this happens, we need to return a clone of the `input` object where the\n\t\t\t\t// current property is replaced by the `replaced` value.\n\t\t\t\tif (replaced !== value) {\n\t\t\t\t\t// Lazily create a shallow clone of the `input` object if we haven't done so already.\n\t\t\t\t\tclone ??= shallowCloneObject(input);\n\n\t\t\t\t\t// Overwrite the current property `key` in the clone with the `replaced` value.\n\t\t\t\t\tclone[key] = replaced;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn clone ?? input;\n\t}\n\n\t/**\n\t * Encodes the given IFluidHandle into a JSON-serializable form,\n\t * also binding it to another node to ensure it attaches at the right time.\n\t * @param handle - The IFluidHandle to serialize.\n\t * @param bind - The binding context for the handle (the handle will become attached whenever this context is attached).\n\t * @returns The serialized handle.\n\t */\n\tprotected bindAndEncodeHandle(\n\t\thandle: IFluidHandleInternal,\n\t\tbind: ISharedObjectHandle,\n\t): ISerializedHandle {\n\t\tbind.bind(handle);\n\t\treturn encodeHandleForSerialization(handle);\n\t}\n}\n"]}