@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.
- package/CHANGELOG.md +14 -0
- package/api-report/shared-object-base.legacy.alpha.api.md +1 -0
- package/dist/gcHandleVisitor.d.ts +1 -1
- package/dist/gcHandleVisitor.d.ts.map +1 -1
- package/dist/gcHandleVisitor.js +1 -1
- package/dist/gcHandleVisitor.js.map +1 -1
- package/dist/handle.d.ts +21 -1
- package/dist/handle.d.ts.map +1 -1
- package/dist/handle.js +10 -1
- package/dist/handle.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/serializer.d.ts +3 -2
- package/dist/serializer.d.ts.map +1 -1
- package/dist/serializer.js +4 -2
- package/dist/serializer.js.map +1 -1
- package/dist/sharedObject.d.ts +11 -0
- package/dist/sharedObject.d.ts.map +1 -1
- package/dist/sharedObject.js +39 -6
- package/dist/sharedObject.js.map +1 -1
- package/dist/sharedObjectKernel.d.ts +186 -0
- package/dist/sharedObjectKernel.d.ts.map +1 -0
- package/dist/sharedObjectKernel.js +227 -0
- package/dist/sharedObjectKernel.js.map +1 -0
- package/lib/gcHandleVisitor.d.ts +1 -1
- package/lib/gcHandleVisitor.d.ts.map +1 -1
- package/lib/gcHandleVisitor.js +1 -1
- package/lib/gcHandleVisitor.js.map +1 -1
- package/lib/handle.d.ts +21 -1
- package/lib/handle.d.ts.map +1 -1
- package/lib/handle.js +8 -0
- package/lib/handle.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/serializer.d.ts +3 -2
- package/lib/serializer.d.ts.map +1 -1
- package/lib/serializer.js +4 -2
- package/lib/serializer.js.map +1 -1
- package/lib/sharedObject.d.ts +11 -0
- package/lib/sharedObject.d.ts.map +1 -1
- package/lib/sharedObject.js +40 -7
- package/lib/sharedObject.js.map +1 -1
- package/lib/sharedObjectKernel.d.ts +186 -0
- package/lib/sharedObjectKernel.d.ts.map +1 -0
- package/lib/sharedObjectKernel.js +222 -0
- package/lib/sharedObjectKernel.js.map +1 -0
- package/package.json +15 -14
- package/src/gcHandleVisitor.ts +1 -4
- package/src/handle.ts +29 -1
- package/src/index.ts +11 -0
- package/src/packageVersion.ts +1 -1
- package/src/serializer.ts +7 -4
- package/src/sharedObject.ts +42 -5
- package/src/sharedObjectKernel.ts +467 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
6
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
7
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
8
|
+
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");
|
|
9
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
10
|
+
};
|
|
11
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
12
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13
|
+
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");
|
|
14
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
15
|
+
};
|
|
16
|
+
var _SharedObjectFromKernel_instances, _SharedObjectFromKernel_lazyData, _SharedObjectFromKernel_kernelArgs, _SharedObjectFromKernel_initializeData, _SharedObjectFromKernel_kernel_get;
|
|
17
|
+
import { assert, fail } from "@fluidframework/core-utils/internal";
|
|
18
|
+
import { createSharedObjectKind, SharedObject, } from "./sharedObject.js";
|
|
19
|
+
/**
|
|
20
|
+
* SharedObject implementation that delegates to a SharedKernel.
|
|
21
|
+
* @typeParam TOut - The type of the object exposed to the app.
|
|
22
|
+
* Once initialized, instances of this class forward properties to the `TOut` value provided by the factory.
|
|
23
|
+
* See {@link mergeAPIs} for more limitations.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* The App facing API (TOut) needs to be implemented by this object which also has to implement the runtime facing API (ISharedObject).
|
|
27
|
+
*
|
|
28
|
+
* Requiring both of these to be implemented by the same object adds some otherwise unnecessary coupling.
|
|
29
|
+
* This class is a workaround for that, which takes separate implementations of the two APIs and merges them into one using {@link mergeAPIs}.
|
|
30
|
+
*/
|
|
31
|
+
class SharedObjectFromKernel extends SharedObject {
|
|
32
|
+
constructor(id, runtime, attributes, factory, telemetryContextPrefix) {
|
|
33
|
+
super(id, runtime, attributes, telemetryContextPrefix);
|
|
34
|
+
_SharedObjectFromKernel_instances.add(this);
|
|
35
|
+
this.factory = factory;
|
|
36
|
+
/**
|
|
37
|
+
* Lazy init here so kernel can be constructed in loadCore when loading from existing data.
|
|
38
|
+
*
|
|
39
|
+
* Explicit initialization to undefined is done so Proxy knows this property is from this class (via `Reflect.has`),
|
|
40
|
+
* not from the grafted APIs.
|
|
41
|
+
*/
|
|
42
|
+
_SharedObjectFromKernel_lazyData.set(this, undefined);
|
|
43
|
+
_SharedObjectFromKernel_kernelArgs.set(this, void 0);
|
|
44
|
+
__classPrivateFieldSet(this, _SharedObjectFromKernel_kernelArgs, {
|
|
45
|
+
sharedObject: this,
|
|
46
|
+
serializer: this.serializer,
|
|
47
|
+
submitLocalMessage: (op, localOpMetadata) => this.submitLocalMessage(op, localOpMetadata),
|
|
48
|
+
eventEmitter: this,
|
|
49
|
+
logger: this.logger,
|
|
50
|
+
idCompressor: runtime.idCompressor,
|
|
51
|
+
lastSequenceNumber: () => this.deltaManager.lastSequenceNumber,
|
|
52
|
+
}, "f");
|
|
53
|
+
}
|
|
54
|
+
summarizeCore(serializer, telemetryContext, incrementalSummaryContext) {
|
|
55
|
+
return __classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "a", _SharedObjectFromKernel_kernel_get).summarizeCore(serializer, telemetryContext, incrementalSummaryContext);
|
|
56
|
+
}
|
|
57
|
+
initializeLocalCore() {
|
|
58
|
+
__classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "m", _SharedObjectFromKernel_initializeData).call(this, this.factory.create(__classPrivateFieldGet(this, _SharedObjectFromKernel_kernelArgs, "f")));
|
|
59
|
+
}
|
|
60
|
+
async loadCore(storage) {
|
|
61
|
+
__classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "m", _SharedObjectFromKernel_initializeData).call(this, await this.factory.loadCore(__classPrivateFieldGet(this, _SharedObjectFromKernel_kernelArgs, "f"), storage));
|
|
62
|
+
}
|
|
63
|
+
onDisconnect() {
|
|
64
|
+
__classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "a", _SharedObjectFromKernel_kernel_get).onDisconnect();
|
|
65
|
+
}
|
|
66
|
+
reSubmitCore(content, localOpMetadata) {
|
|
67
|
+
__classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "a", _SharedObjectFromKernel_kernel_get).reSubmitCore(content, localOpMetadata);
|
|
68
|
+
}
|
|
69
|
+
applyStashedOp(content) {
|
|
70
|
+
__classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "a", _SharedObjectFromKernel_kernel_get).applyStashedOp(content);
|
|
71
|
+
}
|
|
72
|
+
processCore() {
|
|
73
|
+
fail("processCore should not be called");
|
|
74
|
+
}
|
|
75
|
+
processMessagesCore(messagesCollection) {
|
|
76
|
+
__classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "a", _SharedObjectFromKernel_kernel_get).processMessagesCore(messagesCollection);
|
|
77
|
+
}
|
|
78
|
+
rollback(content, localOpMetadata) {
|
|
79
|
+
if (__classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "a", _SharedObjectFromKernel_kernel_get).rollback === undefined) {
|
|
80
|
+
super.rollback(content, localOpMetadata);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
__classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "a", _SharedObjectFromKernel_kernel_get).rollback(content, localOpMetadata);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
didAttach() {
|
|
87
|
+
__classPrivateFieldGet(this, _SharedObjectFromKernel_instances, "a", _SharedObjectFromKernel_kernel_get).didAttach?.();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
_SharedObjectFromKernel_lazyData = new WeakMap(), _SharedObjectFromKernel_kernelArgs = new WeakMap(), _SharedObjectFromKernel_instances = new WeakSet(), _SharedObjectFromKernel_initializeData = function _SharedObjectFromKernel_initializeData(data) {
|
|
91
|
+
assert(__classPrivateFieldGet(this, _SharedObjectFromKernel_lazyData, "f") === undefined, "initializeData must be called first and only once");
|
|
92
|
+
__classPrivateFieldSet(this, _SharedObjectFromKernel_lazyData, data, "f");
|
|
93
|
+
// Make `this` implement TOut.
|
|
94
|
+
mergeAPIs(this, data.view);
|
|
95
|
+
}, _SharedObjectFromKernel_kernel_get = function _SharedObjectFromKernel_kernel_get() {
|
|
96
|
+
return (__classPrivateFieldGet(this, _SharedObjectFromKernel_lazyData, "f") ?? fail("must initializeData first")).kernel;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* When present on a method, it indicates the methods return value should be replaced with `this` (the wrapper)
|
|
100
|
+
* when wrapping the object with the method.
|
|
101
|
+
* @remarks
|
|
102
|
+
* This is useful when using {@link mergeAPIs} with methods where the return type is `this`, like `Map.set`.
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
105
|
+
export const thisWrap = Symbol("selfWrap");
|
|
106
|
+
/**
|
|
107
|
+
* Add getters to `base` which forward own properties from `extra`.
|
|
108
|
+
* @remarks
|
|
109
|
+
* This only handles use of "get" and "has".
|
|
110
|
+
* Therefore, APIs involving setting properties should not be used as `Extra`.
|
|
111
|
+
*
|
|
112
|
+
* Functions from `extra` are bound to the `extra` object and support {@link thisWrap}.
|
|
113
|
+
*
|
|
114
|
+
* Asserts when properties collide.
|
|
115
|
+
* @internal
|
|
116
|
+
*/
|
|
117
|
+
export function mergeAPIs(base, extra) {
|
|
118
|
+
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(extra))) {
|
|
119
|
+
assert(!Reflect.has(base, key), "colliding properties");
|
|
120
|
+
// Detect and special case functions.
|
|
121
|
+
// Currently this is done eagerly (when mergeAPIs is called) rather than lazily (when the property is read):
|
|
122
|
+
// this eager approach should result in slightly better performance,
|
|
123
|
+
// but if functions on `extra` are reassigned over time it will produce incorrect behavior.
|
|
124
|
+
// If this functionality is required, the design can be changed.
|
|
125
|
+
let getter;
|
|
126
|
+
// Bind functions to the extra object and handle thisWrap.
|
|
127
|
+
if (typeof descriptor.value === "function") {
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
129
|
+
const fromExtra = descriptor.value;
|
|
130
|
+
getter = () => forwardMethod(fromExtra, extra, base);
|
|
131
|
+
// To catch (and error on) cases where the function is reassigned and this eager binding approach is not appropriate, make it non-writable.
|
|
132
|
+
Object.defineProperty(extra, key, { ...descriptor, writable: false });
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
getter = () => extra[key];
|
|
136
|
+
}
|
|
137
|
+
Object.defineProperty(base, key, {
|
|
138
|
+
configurable: false,
|
|
139
|
+
enumerable: descriptor.enumerable,
|
|
140
|
+
get: getter,
|
|
141
|
+
// If setters become required, support them here.
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Wrap a method `f` of `oldThis` to be a method of `newThis`.
|
|
147
|
+
* @remarks
|
|
148
|
+
* The wrapped function will be called with `oldThis` as the `this` parameter.
|
|
149
|
+
* It also accounts for when `f` is marked with {@link thisWrap}.
|
|
150
|
+
*/
|
|
151
|
+
function forwardMethod(f, oldThis, newThis) {
|
|
152
|
+
// eslint-disable-next-line unicorn/prefer-ternary
|
|
153
|
+
if (thisWrap in f) {
|
|
154
|
+
return (...args) => {
|
|
155
|
+
const result = f.call(oldThis, ...args);
|
|
156
|
+
assert(result === oldThis, "methods returning thisWrap should return this");
|
|
157
|
+
return newThis;
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
return f.bind(oldThis);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Utility to create a {@link @fluidframework/datastore-definitions#IChannelFactory} classes.
|
|
166
|
+
* @remarks
|
|
167
|
+
* Use {@link makeSharedObjectKind} instead unless exposing the factory is required for legacy API compatibility.
|
|
168
|
+
* @internal
|
|
169
|
+
*/
|
|
170
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
171
|
+
function makeChannelFactory(options) {
|
|
172
|
+
class ChannelFactory {
|
|
173
|
+
/**
|
|
174
|
+
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory."type"}
|
|
175
|
+
*/
|
|
176
|
+
get type() {
|
|
177
|
+
return ChannelFactory.Type;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.attributes}
|
|
181
|
+
*/
|
|
182
|
+
get attributes() {
|
|
183
|
+
return ChannelFactory.Attributes;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}
|
|
187
|
+
*/
|
|
188
|
+
async load(runtime, id, services, attributes) {
|
|
189
|
+
const shared = new SharedObjectFromKernel(id, runtime, attributes, options.factory, options.telemetryContextPrefix);
|
|
190
|
+
await shared.load(services);
|
|
191
|
+
return shared;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}
|
|
195
|
+
*/
|
|
196
|
+
create(runtime, id) {
|
|
197
|
+
const shared = new SharedObjectFromKernel(id, runtime, ChannelFactory.Attributes, options.factory, options.telemetryContextPrefix);
|
|
198
|
+
shared.initializeLocal();
|
|
199
|
+
return shared;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory."type"}
|
|
204
|
+
*/
|
|
205
|
+
ChannelFactory.Type = options.type;
|
|
206
|
+
/**
|
|
207
|
+
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.attributes}
|
|
208
|
+
*/
|
|
209
|
+
ChannelFactory.Attributes = options.attributes;
|
|
210
|
+
return ChannelFactory;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Utility to create a {@link SharedObjectKind}.
|
|
214
|
+
* @privateRemarks
|
|
215
|
+
* Using this API avoids having to subclasses any Fluid Framework types,
|
|
216
|
+
* reducing the coupling between the framework and the SharedObject implementation.
|
|
217
|
+
* @internal
|
|
218
|
+
*/
|
|
219
|
+
export function makeSharedObjectKind(options) {
|
|
220
|
+
return createSharedObjectKind(makeChannelFactory(options));
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=sharedObjectKernel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sharedObjectKernel.js","sourceRoot":"","sources":["../src/sharedObjectKernel.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;;AAIH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC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,CAAC;;IA3DD;;OAEG;IACoB,mBAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAE3C;;OAEG;IACoB,yBAAU,GAAuB,OAAO,CAAC,UAAU,CAAC;IAsD5E,OAAO,cAAc,CAAC;AACvB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CACnC,OAA+B;IAE/B,OAAO,sBAAsB,CAAI,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;AAC/D,CAAC","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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/shared-object-base",
|
|
3
|
-
"version": "2.40.0
|
|
3
|
+
"version": "2.40.0",
|
|
4
4
|
"description": "Fluid base class for shared distributed data structures",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -69,29 +69,30 @@
|
|
|
69
69
|
"temp-directory": "nyc/.nyc_output"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@fluid-internal/client-utils": "2.40.0
|
|
73
|
-
"@fluidframework/container-definitions": "2.40.0
|
|
74
|
-
"@fluidframework/core-interfaces": "2.40.0
|
|
75
|
-
"@fluidframework/core-utils": "2.40.0
|
|
76
|
-
"@fluidframework/datastore": "2.40.0
|
|
77
|
-
"@fluidframework/datastore-definitions": "2.40.0
|
|
78
|
-
"@fluidframework/driver-definitions": "2.40.0
|
|
79
|
-
"@fluidframework/
|
|
80
|
-
"@fluidframework/runtime-
|
|
81
|
-
"@fluidframework/
|
|
72
|
+
"@fluid-internal/client-utils": "~2.40.0",
|
|
73
|
+
"@fluidframework/container-definitions": "~2.40.0",
|
|
74
|
+
"@fluidframework/core-interfaces": "~2.40.0",
|
|
75
|
+
"@fluidframework/core-utils": "~2.40.0",
|
|
76
|
+
"@fluidframework/datastore": "~2.40.0",
|
|
77
|
+
"@fluidframework/datastore-definitions": "~2.40.0",
|
|
78
|
+
"@fluidframework/driver-definitions": "~2.40.0",
|
|
79
|
+
"@fluidframework/id-compressor": "~2.40.0",
|
|
80
|
+
"@fluidframework/runtime-definitions": "~2.40.0",
|
|
81
|
+
"@fluidframework/runtime-utils": "~2.40.0",
|
|
82
|
+
"@fluidframework/telemetry-utils": "~2.40.0",
|
|
82
83
|
"uuid": "^9.0.0"
|
|
83
84
|
},
|
|
84
85
|
"devDependencies": {
|
|
85
86
|
"@arethetypeswrong/cli": "^0.17.1",
|
|
86
87
|
"@biomejs/biome": "~1.9.3",
|
|
87
|
-
"@fluid-internal/mocha-test-setup": "2.40.0
|
|
88
|
-
"@fluid-private/test-pairwise-generator": "2.40.0
|
|
88
|
+
"@fluid-internal/mocha-test-setup": "~2.40.0",
|
|
89
|
+
"@fluid-private/test-pairwise-generator": "~2.40.0",
|
|
89
90
|
"@fluid-tools/build-cli": "^0.55.0",
|
|
90
91
|
"@fluidframework/build-common": "^2.0.3",
|
|
91
92
|
"@fluidframework/build-tools": "^0.55.0",
|
|
92
93
|
"@fluidframework/eslint-config-fluid": "^5.7.3",
|
|
93
94
|
"@fluidframework/shared-object-base-previous": "npm:@fluidframework/shared-object-base@2.33.0",
|
|
94
|
-
"@fluidframework/test-runtime-utils": "2.40.0
|
|
95
|
+
"@fluidframework/test-runtime-utils": "~2.40.0",
|
|
95
96
|
"@microsoft/api-extractor": "7.52.5",
|
|
96
97
|
"@types/benchmark": "^2.1.0",
|
|
97
98
|
"@types/mocha": "^10.0.10",
|
package/src/gcHandleVisitor.ts
CHANGED
|
@@ -20,10 +20,7 @@ export class GCHandleVisitor extends FluidSerializer {
|
|
|
20
20
|
return [...this.visitedHandlePaths];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
protected bindAndEncodeHandle(
|
|
24
|
-
handle: IFluidHandleInternal,
|
|
25
|
-
bind: IFluidHandleInternal,
|
|
26
|
-
): ISerializedHandle {
|
|
23
|
+
protected bindAndEncodeHandle(handle: IFluidHandleInternal): ISerializedHandle {
|
|
27
24
|
this.visitedHandlePaths.add(handle.absolutePath);
|
|
28
25
|
|
|
29
26
|
// Just return a dummy value. The serialization itself is not used.
|
package/src/handle.ts
CHANGED
|
@@ -7,9 +7,34 @@ import { type IFluidHandleInternal } from "@fluidframework/core-interfaces/inter
|
|
|
7
7
|
import { FluidObjectHandle } from "@fluidframework/datastore/internal";
|
|
8
8
|
// eslint-disable-next-line import/no-deprecated
|
|
9
9
|
import type { IFluidDataStoreRuntimeExperimental } from "@fluidframework/datastore-definitions/internal";
|
|
10
|
+
import { isFluidHandle } from "@fluidframework/runtime-utils";
|
|
10
11
|
|
|
11
12
|
import { ISharedObject } from "./types.js";
|
|
12
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Handle for a shared object. See also {@link SharedObjectHandle}.
|
|
16
|
+
* Supports binding other handles to the underlying Shared Object (see {@link ISharedObjectHandle.bind}).
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export interface ISharedObjectHandle extends IFluidHandleInternal<ISharedObject> {
|
|
21
|
+
/**
|
|
22
|
+
* Binds the given handle to this DDS or attach the given handle if this DDS is attached.
|
|
23
|
+
* A bound handle will also be attached once this DDS is attached.
|
|
24
|
+
*
|
|
25
|
+
* @param handle - The target handle to bind to this DDS
|
|
26
|
+
*/
|
|
27
|
+
bind(handle: IFluidHandleInternal): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Type guard for {@link ISharedObjectHandle}.
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
export function isISharedObjectHandle(handle: unknown): handle is ISharedObjectHandle {
|
|
35
|
+
return isFluidHandle(handle) && typeof (handle as ISharedObjectHandle).bind === "function";
|
|
36
|
+
}
|
|
37
|
+
|
|
13
38
|
/**
|
|
14
39
|
* Handle for a shared object.
|
|
15
40
|
*
|
|
@@ -21,7 +46,10 @@ import { ISharedObject } from "./types.js";
|
|
|
21
46
|
* {@link @fluidframework/datastore#FluidDataStoreRuntime.request} recognizes requests in the form of
|
|
22
47
|
* '/\<shared object id\>' and loads shared object.
|
|
23
48
|
*/
|
|
24
|
-
export class SharedObjectHandle
|
|
49
|
+
export class SharedObjectHandle
|
|
50
|
+
extends FluidObjectHandle<ISharedObject>
|
|
51
|
+
implements ISharedObjectHandle
|
|
52
|
+
{
|
|
25
53
|
/**
|
|
26
54
|
* Whether services have been attached for the associated shared object.
|
|
27
55
|
*/
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
export { ISharedObjectHandle, isISharedObjectHandle } from "./handle.js";
|
|
6
7
|
export { FluidSerializer, IFluidSerializer } from "./serializer.js";
|
|
7
8
|
export {
|
|
8
9
|
SharedObject,
|
|
@@ -21,3 +22,13 @@ export {
|
|
|
21
22
|
type IChannelView,
|
|
22
23
|
} from "./utils.js";
|
|
23
24
|
export { ValueType } from "./valueType.js";
|
|
25
|
+
export {
|
|
26
|
+
SharedKernel,
|
|
27
|
+
thisWrap,
|
|
28
|
+
KernelArgs,
|
|
29
|
+
makeSharedObjectKind,
|
|
30
|
+
SharedKernelFactory,
|
|
31
|
+
FactoryOut,
|
|
32
|
+
SharedObjectOptions,
|
|
33
|
+
mergeAPIs,
|
|
34
|
+
} from "./sharedObjectKernel.js";
|
package/src/packageVersion.ts
CHANGED
package/src/serializer.ts
CHANGED
|
@@ -19,6 +19,8 @@ import {
|
|
|
19
19
|
RemoteFluidObjectHandle,
|
|
20
20
|
} from "@fluidframework/runtime-utils/internal";
|
|
21
21
|
|
|
22
|
+
import { isISharedObjectHandle, type ISharedObjectHandle } from "./handle.js";
|
|
23
|
+
|
|
22
24
|
/**
|
|
23
25
|
* @legacy
|
|
24
26
|
* @alpha
|
|
@@ -84,6 +86,7 @@ export class FluidSerializer implements IFluidSerializer {
|
|
|
84
86
|
* Any unbound handles encountered are bound to the provided IFluidHandle.
|
|
85
87
|
*/
|
|
86
88
|
public encode(input: unknown, bind: IFluidHandleInternal): unknown {
|
|
89
|
+
assert(isISharedObjectHandle(bind), 0xb8c /* bind must be an ISharedObjectHandle */);
|
|
87
90
|
// If the given 'input' cannot contain handles, return it immediately. Otherwise,
|
|
88
91
|
// return the result of 'recursivelyReplace()'.
|
|
89
92
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
@@ -116,8 +119,8 @@ export class FluidSerializer implements IFluidSerializer {
|
|
|
116
119
|
* being bound to the given bind context in the process.
|
|
117
120
|
*/
|
|
118
121
|
public stringify(input: unknown, bind: IFluidHandle): string {
|
|
119
|
-
|
|
120
|
-
return JSON.stringify(input, (key, value) => this.encodeValue(value,
|
|
122
|
+
assert(isISharedObjectHandle(bind), 0xb8d /* bind must be an ISharedObjectHandle */);
|
|
123
|
+
return JSON.stringify(input, (key, value) => this.encodeValue(value, bind));
|
|
121
124
|
}
|
|
122
125
|
|
|
123
126
|
/**
|
|
@@ -131,7 +134,7 @@ export class FluidSerializer implements IFluidSerializer {
|
|
|
131
134
|
* If the given 'value' is an IFluidHandle, returns the encoded IFluidHandle.
|
|
132
135
|
* Otherwise returns the original 'value'. Used by 'encode()' and 'stringify()'.
|
|
133
136
|
*/
|
|
134
|
-
protected encodeValue(value: unknown, bind?:
|
|
137
|
+
protected encodeValue(value: unknown, bind?: ISharedObjectHandle): unknown {
|
|
135
138
|
// If 'value' is an IFluidHandle return its encoded form.
|
|
136
139
|
if (isFluidHandle(value)) {
|
|
137
140
|
assert(bind !== undefined, 0xa93 /* Cannot encode a handle without a bind context */);
|
|
@@ -221,7 +224,7 @@ export class FluidSerializer implements IFluidSerializer {
|
|
|
221
224
|
*/
|
|
222
225
|
protected bindAndEncodeHandle(
|
|
223
226
|
handle: IFluidHandleInternal,
|
|
224
|
-
bind:
|
|
227
|
+
bind: ISharedObjectHandle,
|
|
225
228
|
): ISerializedHandle {
|
|
226
229
|
bind.bind(handle);
|
|
227
230
|
return encodeHandleForSerialization(handle);
|
package/src/sharedObject.ts
CHANGED
|
@@ -51,6 +51,7 @@ import {
|
|
|
51
51
|
tagCodeArtifacts,
|
|
52
52
|
type ICustomData,
|
|
53
53
|
type IFluidErrorBase,
|
|
54
|
+
LoggingError,
|
|
54
55
|
} from "@fluidframework/telemetry-utils/internal";
|
|
55
56
|
import { v4 as uuid } from "uuid";
|
|
56
57
|
|
|
@@ -519,6 +520,27 @@ export abstract class SharedObjectCore<
|
|
|
519
520
|
this.submitLocalMessage(content, localOpMetadata);
|
|
520
521
|
}
|
|
521
522
|
|
|
523
|
+
/**
|
|
524
|
+
* Called when a message has to be resubmitted but its content should be "squashed" if any subsequent pending changes
|
|
525
|
+
* override the content in the fashion described on {@link @fluidframework/datastore-definitions#IDeltaHandler.reSubmit}.
|
|
526
|
+
*
|
|
527
|
+
* @param content - The content of the original message.
|
|
528
|
+
* @param localOpMetadata - The local metadata associated with the original message.
|
|
529
|
+
*/
|
|
530
|
+
protected reSubmitSquashed(content: unknown, localOpMetadata: unknown): void {
|
|
531
|
+
const allowStagingModeWithoutSquashing =
|
|
532
|
+
loggerToMonitoringContext(this.logger).config.getBoolean(
|
|
533
|
+
"Fluid.SharedObject.AllowStagingModeWithoutSquashing",
|
|
534
|
+
) ??
|
|
535
|
+
(this.runtime.options.allowStagingModeWithoutSquashing as boolean | undefined) ??
|
|
536
|
+
true;
|
|
537
|
+
if (allowStagingModeWithoutSquashing) {
|
|
538
|
+
this.reSubmitCore(content, localOpMetadata);
|
|
539
|
+
} else {
|
|
540
|
+
this.throwUnsupported("reSubmitSquashed");
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
522
544
|
/**
|
|
523
545
|
* Promises that are waiting for an ack from the server before resolving should use this instead of new Promise.
|
|
524
546
|
* It ensures that if something changes that will interrupt that ack (e.g. the FluidDataStoreRuntime disposes),
|
|
@@ -565,8 +587,8 @@ export abstract class SharedObjectCore<
|
|
|
565
587
|
setConnectionState: (connected: boolean) => {
|
|
566
588
|
this.setConnectionState(connected);
|
|
567
589
|
},
|
|
568
|
-
reSubmit: (content: unknown, localOpMetadata: unknown) => {
|
|
569
|
-
this.reSubmit(content, localOpMetadata);
|
|
590
|
+
reSubmit: (content: unknown, localOpMetadata: unknown, squash?: boolean) => {
|
|
591
|
+
this.reSubmit(content, localOpMetadata, squash);
|
|
570
592
|
},
|
|
571
593
|
applyStashedOp: (content: unknown): void => {
|
|
572
594
|
this.applyStashedOp(parseHandles(content, this.serializer));
|
|
@@ -683,16 +705,24 @@ export abstract class SharedObjectCore<
|
|
|
683
705
|
* reconnection.
|
|
684
706
|
* @param content - The content of the original message.
|
|
685
707
|
* @param localOpMetadata - The local metadata associated with the original message.
|
|
708
|
+
* @param squash - Optional. If `true`, the message will be resubmitted in a squashed form. If `undefined` or `false`,
|
|
709
|
+
* the legacy behavior (no squashing) will be used. Defaults to `false` for backward compatibility.
|
|
686
710
|
*/
|
|
687
|
-
private reSubmit(content: unknown, localOpMetadata: unknown): void {
|
|
688
|
-
|
|
711
|
+
private reSubmit(content: unknown, localOpMetadata: unknown, squash?: boolean): void {
|
|
712
|
+
// Back-compat: squash argument may not be provided by container-runtime layer.
|
|
713
|
+
// Default to previous behavior (no squash).
|
|
714
|
+
if (squash ?? false) {
|
|
715
|
+
this.reSubmitSquashed(content, localOpMetadata);
|
|
716
|
+
} else {
|
|
717
|
+
this.reSubmitCore(content, localOpMetadata);
|
|
718
|
+
}
|
|
689
719
|
}
|
|
690
720
|
|
|
691
721
|
/**
|
|
692
722
|
* Revert an op
|
|
693
723
|
*/
|
|
694
724
|
protected rollback(content: unknown, localOpMetadata: unknown): void {
|
|
695
|
-
|
|
725
|
+
this.throwUnsupported("rollback");
|
|
696
726
|
}
|
|
697
727
|
|
|
698
728
|
/**
|
|
@@ -741,6 +771,13 @@ export abstract class SharedObjectCore<
|
|
|
741
771
|
private emitInternal(event: EventEmitterEventType, ...args: unknown[]): boolean {
|
|
742
772
|
return super.emit(event, ...args);
|
|
743
773
|
}
|
|
774
|
+
|
|
775
|
+
private throwUnsupported(featureName: string): never {
|
|
776
|
+
throw new LoggingError("Unsupported DDS feature", {
|
|
777
|
+
featureName,
|
|
778
|
+
...tagCodeArtifacts({ ddsType: this.attributes.type }),
|
|
779
|
+
});
|
|
780
|
+
}
|
|
744
781
|
}
|
|
745
782
|
|
|
746
783
|
/**
|