@fluidframework/cell 1.2.0-77818 → 1.2.0-78837
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/dist/cell.d.ts +10 -1
- package/dist/cell.d.ts.map +1 -1
- package/dist/cell.js +26 -12
- package/dist/cell.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/cell.d.ts +10 -1
- package/lib/cell.d.ts.map +1 -1
- package/lib/cell.js +26 -12
- package/lib/cell.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/package.json +9 -9
- package/src/cell.ts +30 -16
- package/src/packageVersion.ts +1 -1
package/dist/cell.d.ts
CHANGED
|
@@ -125,6 +125,11 @@ export declare class SharedCell<T = any> extends SharedObject<ISharedCellEvents<
|
|
|
125
125
|
* Call back on disconnect
|
|
126
126
|
*/
|
|
127
127
|
protected onDisconnect(): void;
|
|
128
|
+
/**
|
|
129
|
+
* Apply inner op
|
|
130
|
+
* @param content - ICellOperation content
|
|
131
|
+
*/
|
|
132
|
+
private applyInnerOp;
|
|
128
133
|
/**
|
|
129
134
|
* Process a cell operation
|
|
130
135
|
*
|
|
@@ -137,6 +142,10 @@ export declare class SharedCell<T = any> extends SharedObject<ISharedCellEvents<
|
|
|
137
142
|
private setCore;
|
|
138
143
|
private deleteCore;
|
|
139
144
|
private decode;
|
|
140
|
-
|
|
145
|
+
/**
|
|
146
|
+
* {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
|
|
147
|
+
* @internal
|
|
148
|
+
*/
|
|
149
|
+
protected applyStashedOp(content: unknown): unknown;
|
|
141
150
|
}
|
|
142
151
|
//# sourceMappingURL=cell.d.ts.map
|
package/dist/cell.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cell.d.ts","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E,UAAU,EAAE,kBAAkB;IAIvF;;OAEG;IACI,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS;IAIzC;;OAEG;IACI,GAAG,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC;IAqBjC;;OAEG;IACI,MAAM;IAeb;;OAEG;IACI,KAAK;IAIZ;;;;OAIG;IACH,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,gBAAgB,GAAG,qBAAqB;IAK5E;;OAEG;cACa,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAMxE;;OAEG;IACH,SAAS,CAAC,mBAAmB;IAI7B;;OAEG;IACH,SAAS,CAAC,YAAY;IAEtB;;;OAGG;IACH,OAAO,CAAC,YAAY;IAepB;;;;;;;OAOG;IACH,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,yBAAyB,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO;IAoBlG,OAAO,CAAC,OAAO;IAKf,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,MAAM;IAMd;;;OAGG;IACH,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;CAMtD"}
|
package/dist/cell.js
CHANGED
|
@@ -170,6 +170,22 @@ class SharedCell extends shared_object_base_1.SharedObject {
|
|
|
170
170
|
* Call back on disconnect
|
|
171
171
|
*/
|
|
172
172
|
onDisconnect() { }
|
|
173
|
+
/**
|
|
174
|
+
* Apply inner op
|
|
175
|
+
* @param content - ICellOperation content
|
|
176
|
+
*/
|
|
177
|
+
applyInnerOp(content) {
|
|
178
|
+
switch (content.type) {
|
|
179
|
+
case "setCell":
|
|
180
|
+
this.setCore(this.decode(content.value));
|
|
181
|
+
break;
|
|
182
|
+
case "deleteCell":
|
|
183
|
+
this.deleteCore();
|
|
184
|
+
break;
|
|
185
|
+
default:
|
|
186
|
+
throw new Error("Unknown operation");
|
|
187
|
+
}
|
|
188
|
+
}
|
|
173
189
|
/**
|
|
174
190
|
* Process a cell operation
|
|
175
191
|
*
|
|
@@ -191,16 +207,7 @@ class SharedCell extends shared_object_base_1.SharedObject {
|
|
|
191
207
|
}
|
|
192
208
|
if (message.type === protocol_definitions_1.MessageType.Operation && !local) {
|
|
193
209
|
const op = message.contents;
|
|
194
|
-
|
|
195
|
-
case "setCell":
|
|
196
|
-
this.setCore(this.decode(op.value));
|
|
197
|
-
break;
|
|
198
|
-
case "deleteCell":
|
|
199
|
-
this.deleteCore();
|
|
200
|
-
break;
|
|
201
|
-
default:
|
|
202
|
-
throw new Error("Unknown operation");
|
|
203
|
-
}
|
|
210
|
+
this.applyInnerOp(op);
|
|
204
211
|
}
|
|
205
212
|
}
|
|
206
213
|
setCore(value) {
|
|
@@ -216,8 +223,15 @@ class SharedCell extends shared_object_base_1.SharedObject {
|
|
|
216
223
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
217
224
|
return this.serializer.decode(value);
|
|
218
225
|
}
|
|
219
|
-
|
|
220
|
-
|
|
226
|
+
/**
|
|
227
|
+
* {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
|
|
228
|
+
* @internal
|
|
229
|
+
*/
|
|
230
|
+
applyStashedOp(content) {
|
|
231
|
+
const cellContent = content;
|
|
232
|
+
this.applyInnerOp(cellContent);
|
|
233
|
+
++this.messageId;
|
|
234
|
+
return this.messageId;
|
|
221
235
|
}
|
|
222
236
|
}
|
|
223
237
|
exports.SharedCell = SharedCell;
|
package/dist/cell.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cell.js","sourceRoot":"","sources":["../src/cell.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AACtD,+EAA8F;AAS9F,+DAA4D;AAC5D,2EAA6G;AAC7G,+CAA4C;AAsB5C,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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BAAiB,GAAG,eAAyB,CAAC;aACtD;YACD,OAAO;SACV;QAED,IAAI,OAAO,CAAC,IAAI,KAAK,kCAAW,CAAC,SAAS,IAAI,CAAC,KAAK,EAAE;YAClD,MAAM,EAAE,GAAG,OAAO,CAAC,QAA0B,CAAC;YAE9C,QAAQ,EAAE,CAAC,IAAI,EAAE;gBACb,KAAK,SAAS;oBACV,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;oBACpC,MAAM;gBAEV,KAAK,YAAY;oBACb,IAAI,CAAC,UAAU,EAAE,CAAC;oBAClB,MAAM;gBAEV;oBACI,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;aAC5C;SACJ;IACL,CAAC;IAEO,OAAO,CAAC,KAAsB;QAClC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAClB,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAEO,UAAU;QACd,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;QACtB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxB,CAAC;IAEO,MAAM,CAAC,SAAqB;QAChC,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC;QAC9B,+DAA+D;QAC/D,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IAES,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ;AAnMD,gCAmMC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelFactory,\n Serializable,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport { createSingleBlobSummary, IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { CellFactory } from \"./cellFactory\";\nimport { ISharedCell, ISharedCellEvents } from \"./interfaces\";\n\n/**\n * Description of a cell delta operation\n */\ntype ICellOperation = ISetCellOperation | IDeleteCellOperation;\n\ninterface ISetCellOperation {\n type: \"setCell\";\n value: ICellValue;\n}\n\ninterface IDeleteCellOperation {\n type: \"deleteCell\";\n}\n\ninterface ICellValue {\n // The actual value contained in the cell which needs to be wrapped to handle undefined\n value: any;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * The SharedCell distributed data structure can be used to store a single serializable value.\n *\n * @remarks\n * ### Creation\n *\n * To create a `SharedCell`, call the static create method:\n *\n * ```typescript\n * const myCell = SharedCell.create(this.runtime, id);\n * ```\n *\n * ### Usage\n *\n * The value stored in the cell can be set with the `.set()` method and retrieved with the `.get()` method:\n *\n * ```typescript\n * myCell.set(3);\n * console.log(myCell.get()); // 3\n * ```\n *\n * The value must only be plain JS objects or `SharedObject` handles (e.g. to another DDS or Fluid object).\n * In collaborative scenarios, the value is settled with a policy of _last write wins_.\n *\n * The `.delete()` method will delete the stored value from the cell:\n *\n * ```typescript\n * myCell.delete();\n * console.log(myCell.get()); // undefined\n * ```\n *\n * The `.empty()` method will check if the value is undefined.\n *\n * ```typescript\n * if (myCell.empty()) {\n * // myCell.get() will return undefined\n * } else {\n * // myCell.get() will return a non-undefined value\n * }\n * ```\n *\n * ### Eventing\n *\n * `SharedCell` is an `EventEmitter`, and will emit events when other clients make modifications. You should\n * register for these events and respond appropriately as the data is modified. `valueChanged` will be emitted\n * in response to a `set`, and `delete` will be emitted in response to a `delete`.\n */\nexport class SharedCell<T = any> extends SharedObject<ISharedCellEvents<T>>\n implements ISharedCell<T> {\n /**\n * Create a new shared cell\n *\n * @param runtime - data store runtime the new shared map belongs to\n * @param id - optional name of the shared map\n * @returns newly create shared map (but not attached yet)\n */\n public static create(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, CellFactory.Type) as SharedCell;\n }\n\n /**\n * Get a factory for SharedCell to register with the data store.\n *\n * @returns a factory that creates and load SharedCell\n */\n public static getFactory(): IChannelFactory {\n return new CellFactory();\n }\n /**\n * The data held by this cell.\n */\n private data: Serializable<T> | undefined;\n\n /**\n * This is used to assign a unique id to outgoing messages. It is used to track messages until\n * they are ack'd.\n */\n private messageId: number = -1;\n\n /**\n * This keeps track of the messageId of messages that have been ack'd. It is updated every time\n * we a message is ack'd with it's messageId.\n */\n private messageIdObserved: number = -1;\n\n /**\n * Constructs a new shared cell. If the object is non-local an id and service interfaces will\n * be provided\n *\n * @param runtime - data store runtime the shared map belongs to\n * @param id - optional name of the shared map\n */\n constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes) {\n super(id, runtime, attributes, \"fluid_cell_\");\n }\n\n /**\n * {@inheritDoc ISharedCell.get}\n */\n public get(): Serializable<T> | undefined {\n return this.data;\n }\n\n /**\n * {@inheritDoc ISharedCell.set}\n */\n public set(value: Serializable<T>) {\n // Serialize the value if required.\n const operationValue: ICellValue = {\n value: this.serializer.encode(value, this.handle),\n };\n\n // Set the value locally.\n this.setCore(value);\n\n // If we are not attached, don't submit the op.\n if (!this.isAttached()) {\n return;\n }\n\n const op: ISetCellOperation = {\n type: \"setCell\",\n value: operationValue,\n };\n this.submitLocalMessage(op, ++this.messageId);\n }\n\n /**\n * {@inheritDoc ISharedCell.delete}\n */\n public delete() {\n // Delete the value locally.\n this.deleteCore();\n\n // If we are not attached, don't submit the op.\n if (!this.isAttached()) {\n return;\n }\n\n const op: IDeleteCellOperation = {\n type: \"deleteCell\",\n };\n this.submitLocalMessage(op, ++this.messageId);\n }\n\n /**\n * {@inheritDoc ISharedCell.empty}\n */\n public empty() {\n return this.data === undefined;\n }\n\n /**\n * Create a summary for the cell\n *\n * @returns the summary of the current state of the cell\n */\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n const content: ICellValue = { value: this.data };\n return createSingleBlobSummary(snapshotFileName, serializer.stringify(content, this.handle));\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n const content = await readAndParse<ICellValue>(storage, snapshotFileName);\n\n this.data = this.decode(content);\n }\n\n /**\n * Initialize a local instance of cell\n */\n protected initializeLocalCore() {\n this.data = undefined;\n }\n\n /**\n * Call back on disconnect\n */\n protected onDisconnect() {}\n\n /**\n * Process a cell operation\n *\n * @param message - the message to prepare\n * @param local - whether the message was sent by the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (this.messageId !== this.messageIdObserved) {\n // We are waiting for an ACK on our change to this cell - we will ignore all messages until we get it.\n if (local) {\n const messageIdReceived = localOpMetadata as number;\n assert(messageIdReceived !== undefined && messageIdReceived <= this.messageId,\n 0x00c /* \"messageId is incorrect from from the local client's ACK\" */);\n\n // We got an ACK. Update messageIdObserved.\n this.messageIdObserved = localOpMetadata as number;\n }\n return;\n }\n\n if (message.type === MessageType.Operation && !local) {\n const op = message.contents as ICellOperation;\n\n switch (op.type) {\n case \"setCell\":\n this.setCore(this.decode(op.value));\n break;\n\n case \"deleteCell\":\n this.deleteCore();\n break;\n\n default:\n throw new Error(\"Unknown operation\");\n }\n }\n }\n\n private setCore(value: Serializable<T>) {\n this.data = value;\n this.emit(\"valueChanged\", value);\n }\n\n private deleteCore() {\n this.data = undefined;\n this.emit(\"delete\");\n }\n\n private decode(cellValue: ICellValue) {\n const value = cellValue.value;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return this.serializer.decode(value);\n }\n\n protected applyStashedOp() {\n throw new Error(\"not implemented\");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,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IAED;;;OAGG;IACO,cAAc,CAAC,OAAgB;QACrC,MAAM,WAAW,GAAG,OAAyB,CAAC;QAC9C,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QAC/B,EAAE,IAAI,CAAC,SAAS,CAAC;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;CACJ;AAjND,gCAiNC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelFactory,\n Serializable,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport { createSingleBlobSummary, IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { CellFactory } from \"./cellFactory\";\nimport { ISharedCell, ISharedCellEvents } from \"./interfaces\";\n\n/**\n * Description of a cell delta operation\n */\ntype ICellOperation = ISetCellOperation | IDeleteCellOperation;\n\ninterface ISetCellOperation {\n type: \"setCell\";\n value: ICellValue;\n}\n\ninterface IDeleteCellOperation {\n type: \"deleteCell\";\n}\n\ninterface ICellValue {\n // The actual value contained in the cell which needs to be wrapped to handle undefined\n value: any;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * The SharedCell distributed data structure can be used to store a single serializable value.\n *\n * @remarks\n * ### Creation\n *\n * To create a `SharedCell`, call the static create method:\n *\n * ```typescript\n * const myCell = SharedCell.create(this.runtime, id);\n * ```\n *\n * ### Usage\n *\n * The value stored in the cell can be set with the `.set()` method and retrieved with the `.get()` method:\n *\n * ```typescript\n * myCell.set(3);\n * console.log(myCell.get()); // 3\n * ```\n *\n * The value must only be plain JS objects or `SharedObject` handles (e.g. to another DDS or Fluid object).\n * In collaborative scenarios, the value is settled with a policy of _last write wins_.\n *\n * The `.delete()` method will delete the stored value from the cell:\n *\n * ```typescript\n * myCell.delete();\n * console.log(myCell.get()); // undefined\n * ```\n *\n * The `.empty()` method will check if the value is undefined.\n *\n * ```typescript\n * if (myCell.empty()) {\n * // myCell.get() will return undefined\n * } else {\n * // myCell.get() will return a non-undefined value\n * }\n * ```\n *\n * ### Eventing\n *\n * `SharedCell` is an `EventEmitter`, and will emit events when other clients make modifications. You should\n * register for these events and respond appropriately as the data is modified. `valueChanged` will be emitted\n * in response to a `set`, and `delete` will be emitted in response to a `delete`.\n */\nexport class SharedCell<T = any> extends SharedObject<ISharedCellEvents<T>>\n implements ISharedCell<T> {\n /**\n * Create a new shared cell\n *\n * @param runtime - data store runtime the new shared map belongs to\n * @param id - optional name of the shared map\n * @returns newly create shared map (but not attached yet)\n */\n public static create(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, CellFactory.Type) as SharedCell;\n }\n\n /**\n * Get a factory for SharedCell to register with the data store.\n *\n * @returns a factory that creates and load SharedCell\n */\n public static getFactory(): IChannelFactory {\n return new CellFactory();\n }\n /**\n * The data held by this cell.\n */\n private data: Serializable<T> | undefined;\n\n /**\n * This is used to assign a unique id to outgoing messages. It is used to track messages until\n * they are ack'd.\n */\n private messageId: number = -1;\n\n /**\n * This keeps track of the messageId of messages that have been ack'd. It is updated every time\n * we a message is ack'd with it's messageId.\n */\n private messageIdObserved: number = -1;\n\n /**\n * Constructs a new shared cell. If the object is non-local an id and service interfaces will\n * be provided\n *\n * @param runtime - data store runtime the shared map belongs to\n * @param id - optional name of the shared map\n */\n constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes) {\n super(id, runtime, attributes, \"fluid_cell_\");\n }\n\n /**\n * {@inheritDoc ISharedCell.get}\n */\n public get(): Serializable<T> | undefined {\n return this.data;\n }\n\n /**\n * {@inheritDoc ISharedCell.set}\n */\n public set(value: Serializable<T>) {\n // Serialize the value if required.\n const operationValue: ICellValue = {\n value: this.serializer.encode(value, this.handle),\n };\n\n // Set the value locally.\n this.setCore(value);\n\n // If we are not attached, don't submit the op.\n if (!this.isAttached()) {\n return;\n }\n\n const op: ISetCellOperation = {\n type: \"setCell\",\n value: operationValue,\n };\n this.submitLocalMessage(op, ++this.messageId);\n }\n\n /**\n * {@inheritDoc ISharedCell.delete}\n */\n public delete() {\n // Delete the value locally.\n this.deleteCore();\n\n // If we are not attached, don't submit the op.\n if (!this.isAttached()) {\n return;\n }\n\n const op: IDeleteCellOperation = {\n type: \"deleteCell\",\n };\n this.submitLocalMessage(op, ++this.messageId);\n }\n\n /**\n * {@inheritDoc ISharedCell.empty}\n */\n public empty() {\n return this.data === undefined;\n }\n\n /**\n * Create a summary for the cell\n *\n * @returns the summary of the current state of the cell\n */\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n const content: ICellValue = { value: this.data };\n return createSingleBlobSummary(snapshotFileName, serializer.stringify(content, this.handle));\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n const content = await readAndParse<ICellValue>(storage, snapshotFileName);\n\n this.data = this.decode(content);\n }\n\n /**\n * Initialize a local instance of cell\n */\n protected initializeLocalCore() {\n this.data = undefined;\n }\n\n /**\n * Call back on disconnect\n */\n protected onDisconnect() { }\n\n /**\n * Apply inner op\n * @param content - ICellOperation content\n */\n private applyInnerOp(content: ICellOperation) {\n switch (content.type) {\n case \"setCell\":\n this.setCore(this.decode(content.value));\n break;\n\n case \"deleteCell\":\n this.deleteCore();\n break;\n\n default:\n throw new Error(\"Unknown operation\");\n }\n }\n\n /**\n * Process a cell operation\n *\n * @param message - the message to prepare\n * @param local - whether the message was sent by the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (this.messageId !== this.messageIdObserved) {\n // We are waiting for an ACK on our change to this cell - we will ignore all messages until we get it.\n if (local) {\n const messageIdReceived = localOpMetadata as number;\n assert(messageIdReceived !== undefined && messageIdReceived <= this.messageId,\n 0x00c /* \"messageId is incorrect from from the local client's ACK\" */);\n\n // We got an ACK. Update messageIdObserved.\n this.messageIdObserved = localOpMetadata as number;\n }\n return;\n }\n\n if (message.type === MessageType.Operation && !local) {\n const op = message.contents as ICellOperation;\n this.applyInnerOp(op);\n }\n }\n\n private setCore(value: Serializable<T>) {\n this.data = value;\n this.emit(\"valueChanged\", value);\n }\n\n private deleteCore() {\n this.data = undefined;\n this.emit(\"delete\");\n }\n\n private decode(cellValue: ICellValue) {\n const value = cellValue.value;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return this.serializer.decode(value);\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}\n * @internal\n */\n protected applyStashedOp(content: unknown): unknown {\n const cellContent = content as ICellOperation;\n this.applyInnerOp(cellContent);\n ++this.messageId;\n return this.messageId;\n }\n}\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -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/cell";
|
|
8
|
-
export declare const pkgVersion = "1.2.0-
|
|
8
|
+
export declare const pkgVersion = "1.2.0-78837";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/cell";
|
|
11
|
-
exports.pkgVersion = "1.2.0-
|
|
11
|
+
exports.pkgVersion = "1.2.0-78837";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,sBAAsB,CAAC;AACjC,QAAA,UAAU,GAAG,aAAa,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/cell\";\nexport const pkgVersion = \"1.2.0-
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,sBAAsB,CAAC;AACjC,QAAA,UAAU,GAAG,aAAa,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/cell\";\nexport const pkgVersion = \"1.2.0-78837\";\n"]}
|
package/lib/cell.d.ts
CHANGED
|
@@ -125,6 +125,11 @@ export declare class SharedCell<T = any> extends SharedObject<ISharedCellEvents<
|
|
|
125
125
|
* Call back on disconnect
|
|
126
126
|
*/
|
|
127
127
|
protected onDisconnect(): void;
|
|
128
|
+
/**
|
|
129
|
+
* Apply inner op
|
|
130
|
+
* @param content - ICellOperation content
|
|
131
|
+
*/
|
|
132
|
+
private applyInnerOp;
|
|
128
133
|
/**
|
|
129
134
|
* Process a cell operation
|
|
130
135
|
*
|
|
@@ -137,6 +142,10 @@ export declare class SharedCell<T = any> extends SharedObject<ISharedCellEvents<
|
|
|
137
142
|
private setCore;
|
|
138
143
|
private deleteCore;
|
|
139
144
|
private decode;
|
|
140
|
-
|
|
145
|
+
/**
|
|
146
|
+
* {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
|
|
147
|
+
* @internal
|
|
148
|
+
*/
|
|
149
|
+
protected applyStashedOp(content: unknown): unknown;
|
|
141
150
|
}
|
|
142
151
|
//# sourceMappingURL=cell.d.ts.map
|
package/lib/cell.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cell.d.ts","sourceRoot":"","sources":["../src/cell.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,yBAAyB,EAAe,MAAM,sCAAsC,CAAC;AAC9F,OAAO,EACH,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EACf,YAAY,EACf,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAE5E,OAAO,EAA2B,gBAAgB,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAE7G,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAuB9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,qBAAa,UAAU,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,YAAY,CAAC,iBAAiB,CAAC,CAAC,CAAC,CACtE,YAAW,WAAW,CAAC,CAAC,CAAC;IACzB;;;;;;OAMG;WACW,MAAM,CAAC,OAAO,EAAE,sBAAsB,EAAE,EAAE,CAAC,EAAE,MAAM;IAIjE;;;;OAIG;WACW,UAAU,IAAI,eAAe;IAG3C;;OAEG;IACH,OAAO,CAAC,IAAI,CAA8B;IAE1C;;;OAGG;IACH,OAAO,CAAC,SAAS,CAAc;IAE/B;;;OAGG;IACH,OAAO,CAAC,iBAAiB,CAAc;IAEvC;;;;;;OAMG;gBACS,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,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BAAsB,EAAE,EAAE,CAAC,EAAE,MAAM;IAIjE;;;;OAIG;WACW,UAAU,IAAI,eAAe;IAG3C;;OAEG;IACH,OAAO,CAAC,IAAI,CAA8B;IAE1C;;;OAGG;IACH,OAAO,CAAC,SAAS,CAAc;IAE/B;;;OAGG;IACH,OAAO,CAAC,iBAAiB,CAAc;IAEvC;;;;;;OAMG;gBACS,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,kBAAkB;IAIvF;;OAEG;IACI,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS;IAIzC;;OAEG;IACI,GAAG,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC;IAqBjC;;OAEG;IACI,MAAM;IAeb;;OAEG;IACI,KAAK;IAIZ;;;;OAIG;IACH,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,gBAAgB,GAAG,qBAAqB;IAK5E;;OAEG;cACa,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAMxE;;OAEG;IACH,SAAS,CAAC,mBAAmB;IAI7B;;OAEG;IACH,SAAS,CAAC,YAAY;IAEtB;;;OAGG;IACH,OAAO,CAAC,YAAY;IAepB;;;;;;;OAOG;IACH,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,yBAAyB,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO;IAoBlG,OAAO,CAAC,OAAO;IAKf,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,MAAM;IAMd;;;OAGG;IACH,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;CAMtD"}
|
package/lib/cell.js
CHANGED
|
@@ -167,6 +167,22 @@ export class SharedCell extends SharedObject {
|
|
|
167
167
|
* Call back on disconnect
|
|
168
168
|
*/
|
|
169
169
|
onDisconnect() { }
|
|
170
|
+
/**
|
|
171
|
+
* Apply inner op
|
|
172
|
+
* @param content - ICellOperation content
|
|
173
|
+
*/
|
|
174
|
+
applyInnerOp(content) {
|
|
175
|
+
switch (content.type) {
|
|
176
|
+
case "setCell":
|
|
177
|
+
this.setCore(this.decode(content.value));
|
|
178
|
+
break;
|
|
179
|
+
case "deleteCell":
|
|
180
|
+
this.deleteCore();
|
|
181
|
+
break;
|
|
182
|
+
default:
|
|
183
|
+
throw new Error("Unknown operation");
|
|
184
|
+
}
|
|
185
|
+
}
|
|
170
186
|
/**
|
|
171
187
|
* Process a cell operation
|
|
172
188
|
*
|
|
@@ -188,16 +204,7 @@ export class SharedCell extends SharedObject {
|
|
|
188
204
|
}
|
|
189
205
|
if (message.type === MessageType.Operation && !local) {
|
|
190
206
|
const op = message.contents;
|
|
191
|
-
|
|
192
|
-
case "setCell":
|
|
193
|
-
this.setCore(this.decode(op.value));
|
|
194
|
-
break;
|
|
195
|
-
case "deleteCell":
|
|
196
|
-
this.deleteCore();
|
|
197
|
-
break;
|
|
198
|
-
default:
|
|
199
|
-
throw new Error("Unknown operation");
|
|
200
|
-
}
|
|
207
|
+
this.applyInnerOp(op);
|
|
201
208
|
}
|
|
202
209
|
}
|
|
203
210
|
setCore(value) {
|
|
@@ -213,8 +220,15 @@ export class SharedCell extends SharedObject {
|
|
|
213
220
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
214
221
|
return this.serializer.decode(value);
|
|
215
222
|
}
|
|
216
|
-
|
|
217
|
-
|
|
223
|
+
/**
|
|
224
|
+
* {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
|
|
225
|
+
* @internal
|
|
226
|
+
*/
|
|
227
|
+
applyStashedOp(content) {
|
|
228
|
+
const cellContent = content;
|
|
229
|
+
this.applyInnerOp(cellContent);
|
|
230
|
+
++this.messageId;
|
|
231
|
+
return this.messageId;
|
|
218
232
|
}
|
|
219
233
|
}
|
|
220
234
|
//# sourceMappingURL=cell.js.map
|
package/lib/cell.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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C;QAC9B,+DAA+D;QAC/D,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IAES,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelFactory,\n Serializable,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport { createSingleBlobSummary, IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { CellFactory } from \"./cellFactory\";\nimport { ISharedCell, ISharedCellEvents } from \"./interfaces\";\n\n/**\n * Description of a cell delta operation\n */\ntype ICellOperation = ISetCellOperation | IDeleteCellOperation;\n\ninterface ISetCellOperation {\n type: \"setCell\";\n value: ICellValue;\n}\n\ninterface IDeleteCellOperation {\n type: \"deleteCell\";\n}\n\ninterface ICellValue {\n // The actual value contained in the cell which needs to be wrapped to handle undefined\n value: any;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * The SharedCell distributed data structure can be used to store a single serializable value.\n *\n * @remarks\n * ### Creation\n *\n * To create a `SharedCell`, call the static create method:\n *\n * ```typescript\n * const myCell = SharedCell.create(this.runtime, id);\n * ```\n *\n * ### Usage\n *\n * The value stored in the cell can be set with the `.set()` method and retrieved with the `.get()` method:\n *\n * ```typescript\n * myCell.set(3);\n * console.log(myCell.get()); // 3\n * ```\n *\n * The value must only be plain JS objects or `SharedObject` handles (e.g. to another DDS or Fluid object).\n * In collaborative scenarios, the value is settled with a policy of _last write wins_.\n *\n * The `.delete()` method will delete the stored value from the cell:\n *\n * ```typescript\n * myCell.delete();\n * console.log(myCell.get()); // undefined\n * ```\n *\n * The `.empty()` method will check if the value is undefined.\n *\n * ```typescript\n * if (myCell.empty()) {\n * // myCell.get() will return undefined\n * } else {\n * // myCell.get() will return a non-undefined value\n * }\n * ```\n *\n * ### Eventing\n *\n * `SharedCell` is an `EventEmitter`, and will emit events when other clients make modifications. You should\n * register for these events and respond appropriately as the data is modified. `valueChanged` will be emitted\n * in response to a `set`, and `delete` will be emitted in response to a `delete`.\n */\nexport class SharedCell<T = any> extends SharedObject<ISharedCellEvents<T>>\n implements ISharedCell<T> {\n /**\n * Create a new shared cell\n *\n * @param runtime - data store runtime the new shared map belongs to\n * @param id - optional name of the shared map\n * @returns newly create shared map (but not attached yet)\n */\n public static create(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, CellFactory.Type) as SharedCell;\n }\n\n /**\n * Get a factory for SharedCell to register with the data store.\n *\n * @returns a factory that creates and load SharedCell\n */\n public static getFactory(): IChannelFactory {\n return new CellFactory();\n }\n /**\n * The data held by this cell.\n */\n private data: Serializable<T> | undefined;\n\n /**\n * This is used to assign a unique id to outgoing messages. It is used to track messages until\n * they are ack'd.\n */\n private messageId: number = -1;\n\n /**\n * This keeps track of the messageId of messages that have been ack'd. It is updated every time\n * we a message is ack'd with it's messageId.\n */\n private messageIdObserved: number = -1;\n\n /**\n * Constructs a new shared cell. If the object is non-local an id and service interfaces will\n * be provided\n *\n * @param runtime - data store runtime the shared map belongs to\n * @param id - optional name of the shared map\n */\n constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes) {\n super(id, runtime, attributes, \"fluid_cell_\");\n }\n\n /**\n * {@inheritDoc ISharedCell.get}\n */\n public get(): Serializable<T> | undefined {\n return this.data;\n }\n\n /**\n * {@inheritDoc ISharedCell.set}\n */\n public set(value: Serializable<T>) {\n // Serialize the value if required.\n const operationValue: ICellValue = {\n value: this.serializer.encode(value, this.handle),\n };\n\n // Set the value locally.\n this.setCore(value);\n\n // If we are not attached, don't submit the op.\n if (!this.isAttached()) {\n return;\n }\n\n const op: ISetCellOperation = {\n type: \"setCell\",\n value: operationValue,\n };\n this.submitLocalMessage(op, ++this.messageId);\n }\n\n /**\n * {@inheritDoc ISharedCell.delete}\n */\n public delete() {\n // Delete the value locally.\n this.deleteCore();\n\n // If we are not attached, don't submit the op.\n if (!this.isAttached()) {\n return;\n }\n\n const op: IDeleteCellOperation = {\n type: \"deleteCell\",\n };\n this.submitLocalMessage(op, ++this.messageId);\n }\n\n /**\n * {@inheritDoc ISharedCell.empty}\n */\n public empty() {\n return this.data === undefined;\n }\n\n /**\n * Create a summary for the cell\n *\n * @returns the summary of the current state of the cell\n */\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n const content: ICellValue = { value: this.data };\n return createSingleBlobSummary(snapshotFileName, serializer.stringify(content, this.handle));\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n const content = await readAndParse<ICellValue>(storage, snapshotFileName);\n\n this.data = this.decode(content);\n }\n\n /**\n * Initialize a local instance of cell\n */\n protected initializeLocalCore() {\n this.data = undefined;\n }\n\n /**\n * Call back on disconnect\n */\n protected onDisconnect() {}\n\n /**\n * Process a cell operation\n *\n * @param message - the message to prepare\n * @param local - whether the message was sent by the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (this.messageId !== this.messageIdObserved) {\n // We are waiting for an ACK on our change to this cell - we will ignore all messages until we get it.\n if (local) {\n const messageIdReceived = localOpMetadata as number;\n assert(messageIdReceived !== undefined && messageIdReceived <= this.messageId,\n 0x00c /* \"messageId is incorrect from from the local client's ACK\" */);\n\n // We got an ACK. Update messageIdObserved.\n this.messageIdObserved = localOpMetadata as number;\n }\n return;\n }\n\n if (message.type === MessageType.Operation && !local) {\n const op = message.contents as ICellOperation;\n\n switch (op.type) {\n case \"setCell\":\n this.setCore(this.decode(op.value));\n break;\n\n case \"deleteCell\":\n this.deleteCore();\n break;\n\n default:\n throw new Error(\"Unknown operation\");\n }\n }\n }\n\n private setCore(value: Serializable<T>) {\n this.data = value;\n this.emit(\"valueChanged\", value);\n }\n\n private deleteCore() {\n this.data = undefined;\n this.emit(\"delete\");\n }\n\n private decode(cellValue: ICellValue) {\n const value = cellValue.value;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return this.serializer.decode(value);\n }\n\n protected applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"cell.js","sourceRoot":"","sources":["../src/cell.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAA6B,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAS9F,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAoB,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAC7G,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAsB5C,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,OAAO,UAAoB,SAAQ,YAAkC;IAsCvE;;;;;;OAMG;IACH,YAAY,EAAU,EAAE,OAA+B,EAAE,UAA8B;QACnF,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;QApBlD;;;WAGG;QACK,cAAS,GAAW,CAAC,CAAC,CAAC;QAE/B;;;WAGG;QACK,sBAAiB,GAAW,CAAC,CAAC,CAAC;IAWvC,CAAC;IA7CD;;;;;;OAMG;IACI,MAAM,CAAC,MAAM,CAAC,OAA+B,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;QAED,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,SAAS,IAAI,CAAC,KAAK,EAAE;YAClD,MAAM,EAAE,GAAG,OAAO,CAAC,QAA0B,CAAC;YAC9C,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;SACzB;IACL,CAAC;IAEO,OAAO,CAAC,KAAsB;QAClC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAClB,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAEO,UAAU;QACd,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;QACtB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxB,CAAC;IAEO,MAAM,CAAC,SAAqB;QAChC,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC;QAC9B,+DAA+D;QAC/D,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IAED;;;OAGG;IACO,cAAc,CAAC,OAAgB;QACrC,MAAM,WAAW,GAAG,OAAyB,CAAC;QAC9C,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QAC/B,EAAE,IAAI,CAAC,SAAS,CAAC;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelFactory,\n Serializable,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport { createSingleBlobSummary, IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { CellFactory } from \"./cellFactory\";\nimport { ISharedCell, ISharedCellEvents } from \"./interfaces\";\n\n/**\n * Description of a cell delta operation\n */\ntype ICellOperation = ISetCellOperation | IDeleteCellOperation;\n\ninterface ISetCellOperation {\n type: \"setCell\";\n value: ICellValue;\n}\n\ninterface IDeleteCellOperation {\n type: \"deleteCell\";\n}\n\ninterface ICellValue {\n // The actual value contained in the cell which needs to be wrapped to handle undefined\n value: any;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * The SharedCell distributed data structure can be used to store a single serializable value.\n *\n * @remarks\n * ### Creation\n *\n * To create a `SharedCell`, call the static create method:\n *\n * ```typescript\n * const myCell = SharedCell.create(this.runtime, id);\n * ```\n *\n * ### Usage\n *\n * The value stored in the cell can be set with the `.set()` method and retrieved with the `.get()` method:\n *\n * ```typescript\n * myCell.set(3);\n * console.log(myCell.get()); // 3\n * ```\n *\n * The value must only be plain JS objects or `SharedObject` handles (e.g. to another DDS or Fluid object).\n * In collaborative scenarios, the value is settled with a policy of _last write wins_.\n *\n * The `.delete()` method will delete the stored value from the cell:\n *\n * ```typescript\n * myCell.delete();\n * console.log(myCell.get()); // undefined\n * ```\n *\n * The `.empty()` method will check if the value is undefined.\n *\n * ```typescript\n * if (myCell.empty()) {\n * // myCell.get() will return undefined\n * } else {\n * // myCell.get() will return a non-undefined value\n * }\n * ```\n *\n * ### Eventing\n *\n * `SharedCell` is an `EventEmitter`, and will emit events when other clients make modifications. You should\n * register for these events and respond appropriately as the data is modified. `valueChanged` will be emitted\n * in response to a `set`, and `delete` will be emitted in response to a `delete`.\n */\nexport class SharedCell<T = any> extends SharedObject<ISharedCellEvents<T>>\n implements ISharedCell<T> {\n /**\n * Create a new shared cell\n *\n * @param runtime - data store runtime the new shared map belongs to\n * @param id - optional name of the shared map\n * @returns newly create shared map (but not attached yet)\n */\n public static create(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, CellFactory.Type) as SharedCell;\n }\n\n /**\n * Get a factory for SharedCell to register with the data store.\n *\n * @returns a factory that creates and load SharedCell\n */\n public static getFactory(): IChannelFactory {\n return new CellFactory();\n }\n /**\n * The data held by this cell.\n */\n private data: Serializable<T> | undefined;\n\n /**\n * This is used to assign a unique id to outgoing messages. It is used to track messages until\n * they are ack'd.\n */\n private messageId: number = -1;\n\n /**\n * This keeps track of the messageId of messages that have been ack'd. It is updated every time\n * we a message is ack'd with it's messageId.\n */\n private messageIdObserved: number = -1;\n\n /**\n * Constructs a new shared cell. If the object is non-local an id and service interfaces will\n * be provided\n *\n * @param runtime - data store runtime the shared map belongs to\n * @param id - optional name of the shared map\n */\n constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes) {\n super(id, runtime, attributes, \"fluid_cell_\");\n }\n\n /**\n * {@inheritDoc ISharedCell.get}\n */\n public get(): Serializable<T> | undefined {\n return this.data;\n }\n\n /**\n * {@inheritDoc ISharedCell.set}\n */\n public set(value: Serializable<T>) {\n // Serialize the value if required.\n const operationValue: ICellValue = {\n value: this.serializer.encode(value, this.handle),\n };\n\n // Set the value locally.\n this.setCore(value);\n\n // If we are not attached, don't submit the op.\n if (!this.isAttached()) {\n return;\n }\n\n const op: ISetCellOperation = {\n type: \"setCell\",\n value: operationValue,\n };\n this.submitLocalMessage(op, ++this.messageId);\n }\n\n /**\n * {@inheritDoc ISharedCell.delete}\n */\n public delete() {\n // Delete the value locally.\n this.deleteCore();\n\n // If we are not attached, don't submit the op.\n if (!this.isAttached()) {\n return;\n }\n\n const op: IDeleteCellOperation = {\n type: \"deleteCell\",\n };\n this.submitLocalMessage(op, ++this.messageId);\n }\n\n /**\n * {@inheritDoc ISharedCell.empty}\n */\n public empty() {\n return this.data === undefined;\n }\n\n /**\n * Create a summary for the cell\n *\n * @returns the summary of the current state of the cell\n */\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n const content: ICellValue = { value: this.data };\n return createSingleBlobSummary(snapshotFileName, serializer.stringify(content, this.handle));\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n const content = await readAndParse<ICellValue>(storage, snapshotFileName);\n\n this.data = this.decode(content);\n }\n\n /**\n * Initialize a local instance of cell\n */\n protected initializeLocalCore() {\n this.data = undefined;\n }\n\n /**\n * Call back on disconnect\n */\n protected onDisconnect() { }\n\n /**\n * Apply inner op\n * @param content - ICellOperation content\n */\n private applyInnerOp(content: ICellOperation) {\n switch (content.type) {\n case \"setCell\":\n this.setCore(this.decode(content.value));\n break;\n\n case \"deleteCell\":\n this.deleteCore();\n break;\n\n default:\n throw new Error(\"Unknown operation\");\n }\n }\n\n /**\n * Process a cell operation\n *\n * @param message - the message to prepare\n * @param local - whether the message was sent by the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (this.messageId !== this.messageIdObserved) {\n // We are waiting for an ACK on our change to this cell - we will ignore all messages until we get it.\n if (local) {\n const messageIdReceived = localOpMetadata as number;\n assert(messageIdReceived !== undefined && messageIdReceived <= this.messageId,\n 0x00c /* \"messageId is incorrect from from the local client's ACK\" */);\n\n // We got an ACK. Update messageIdObserved.\n this.messageIdObserved = localOpMetadata as number;\n }\n return;\n }\n\n if (message.type === MessageType.Operation && !local) {\n const op = message.contents as ICellOperation;\n this.applyInnerOp(op);\n }\n }\n\n private setCore(value: Serializable<T>) {\n this.data = value;\n this.emit(\"valueChanged\", value);\n }\n\n private deleteCore() {\n this.data = undefined;\n this.emit(\"delete\");\n }\n\n private decode(cellValue: ICellValue) {\n const value = cellValue.value;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return this.serializer.decode(value);\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}\n * @internal\n */\n protected applyStashedOp(content: unknown): unknown {\n const cellContent = content as ICellOperation;\n this.applyInnerOp(cellContent);\n ++this.messageId;\n return this.messageId;\n }\n}\n"]}
|
package/lib/packageVersion.d.ts
CHANGED
|
@@ -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/cell";
|
|
8
|
-
export declare const pkgVersion = "1.2.0-
|
|
8
|
+
export declare const pkgVersion = "1.2.0-78837";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/lib/packageVersion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,sBAAsB,CAAC;AAC9C,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,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/cell\";\nexport const pkgVersion = \"1.2.0-
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,sBAAsB,CAAC;AAC9C,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,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/cell\";\nexport const pkgVersion = \"1.2.0-78837\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/cell",
|
|
3
|
-
"version": "1.2.0-
|
|
3
|
+
"version": "1.2.0-78837",
|
|
4
4
|
"description": "Distributed data structure for a single value",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -61,21 +61,21 @@
|
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@fluidframework/common-utils": "^0.32.1",
|
|
64
|
-
"@fluidframework/core-interfaces": "1.2.0-
|
|
65
|
-
"@fluidframework/datastore-definitions": "1.2.0-
|
|
66
|
-
"@fluidframework/driver-utils": "1.2.0-
|
|
64
|
+
"@fluidframework/core-interfaces": "1.2.0-78837",
|
|
65
|
+
"@fluidframework/datastore-definitions": "1.2.0-78837",
|
|
66
|
+
"@fluidframework/driver-utils": "1.2.0-78837",
|
|
67
67
|
"@fluidframework/protocol-definitions": "^0.1028.2000",
|
|
68
|
-
"@fluidframework/runtime-definitions": "1.2.0-
|
|
69
|
-
"@fluidframework/shared-object-base": "1.2.0-
|
|
68
|
+
"@fluidframework/runtime-definitions": "1.2.0-78837",
|
|
69
|
+
"@fluidframework/shared-object-base": "1.2.0-78837"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@fluid-internal/test-dds-utils": "1.2.0-
|
|
72
|
+
"@fluid-internal/test-dds-utils": "1.2.0-78837",
|
|
73
73
|
"@fluidframework/build-common": "^0.24.0",
|
|
74
74
|
"@fluidframework/build-tools": "^0.2.74327",
|
|
75
75
|
"@fluidframework/cell-previous": "npm:@fluidframework/cell@1.1.0",
|
|
76
76
|
"@fluidframework/eslint-config-fluid": "^0.28.2000",
|
|
77
|
-
"@fluidframework/mocha-test-setup": "1.2.0-
|
|
78
|
-
"@fluidframework/test-runtime-utils": "1.2.0-
|
|
77
|
+
"@fluidframework/mocha-test-setup": "1.2.0-78837",
|
|
78
|
+
"@fluidframework/test-runtime-utils": "1.2.0-78837",
|
|
79
79
|
"@microsoft/api-extractor": "^7.22.2",
|
|
80
80
|
"@rushstack/eslint-config": "^2.5.1",
|
|
81
81
|
"@types/mocha": "^9.1.1",
|
package/src/cell.ts
CHANGED
|
@@ -220,7 +220,26 @@ export class SharedCell<T = any> extends SharedObject<ISharedCellEvents<T>>
|
|
|
220
220
|
/**
|
|
221
221
|
* Call back on disconnect
|
|
222
222
|
*/
|
|
223
|
-
protected onDisconnect() {}
|
|
223
|
+
protected onDisconnect() { }
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Apply inner op
|
|
227
|
+
* @param content - ICellOperation content
|
|
228
|
+
*/
|
|
229
|
+
private applyInnerOp(content: ICellOperation) {
|
|
230
|
+
switch (content.type) {
|
|
231
|
+
case "setCell":
|
|
232
|
+
this.setCore(this.decode(content.value));
|
|
233
|
+
break;
|
|
234
|
+
|
|
235
|
+
case "deleteCell":
|
|
236
|
+
this.deleteCore();
|
|
237
|
+
break;
|
|
238
|
+
|
|
239
|
+
default:
|
|
240
|
+
throw new Error("Unknown operation");
|
|
241
|
+
}
|
|
242
|
+
}
|
|
224
243
|
|
|
225
244
|
/**
|
|
226
245
|
* Process a cell operation
|
|
@@ -246,19 +265,7 @@ export class SharedCell<T = any> extends SharedObject<ISharedCellEvents<T>>
|
|
|
246
265
|
|
|
247
266
|
if (message.type === MessageType.Operation && !local) {
|
|
248
267
|
const op = message.contents as ICellOperation;
|
|
249
|
-
|
|
250
|
-
switch (op.type) {
|
|
251
|
-
case "setCell":
|
|
252
|
-
this.setCore(this.decode(op.value));
|
|
253
|
-
break;
|
|
254
|
-
|
|
255
|
-
case "deleteCell":
|
|
256
|
-
this.deleteCore();
|
|
257
|
-
break;
|
|
258
|
-
|
|
259
|
-
default:
|
|
260
|
-
throw new Error("Unknown operation");
|
|
261
|
-
}
|
|
268
|
+
this.applyInnerOp(op);
|
|
262
269
|
}
|
|
263
270
|
}
|
|
264
271
|
|
|
@@ -278,7 +285,14 @@ export class SharedCell<T = any> extends SharedObject<ISharedCellEvents<T>>
|
|
|
278
285
|
return this.serializer.decode(value);
|
|
279
286
|
}
|
|
280
287
|
|
|
281
|
-
|
|
282
|
-
|
|
288
|
+
/**
|
|
289
|
+
* {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
|
|
290
|
+
* @internal
|
|
291
|
+
*/
|
|
292
|
+
protected applyStashedOp(content: unknown): unknown {
|
|
293
|
+
const cellContent = content as ICellOperation;
|
|
294
|
+
this.applyInnerOp(cellContent);
|
|
295
|
+
++this.messageId;
|
|
296
|
+
return this.messageId;
|
|
283
297
|
}
|
|
284
298
|
}
|
package/src/packageVersion.ts
CHANGED