@fluidframework/counter 2.90.0-378676 → 2.91.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 +8 -0
- package/dist/counter.d.ts +0 -3
- package/dist/counter.d.ts.map +1 -1
- package/dist/counter.js +0 -3
- package/dist/counter.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/lib/counter.d.ts +0 -3
- package/lib/counter.d.ts.map +1 -1
- package/lib/counter.js +0 -3
- package/lib/counter.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/package.json +18 -18
- package/src/counter.ts +1 -4
- package/src/packageVersion.ts +1 -1
package/CHANGELOG.md
CHANGED
package/dist/counter.d.ts
CHANGED
|
@@ -52,9 +52,6 @@ export declare class SharedCounter extends SharedObject<ISharedCounterEvents> im
|
|
|
52
52
|
* Called when the object has disconnected from the delta stream.
|
|
53
53
|
*/
|
|
54
54
|
protected onDisconnect(): void;
|
|
55
|
-
/**
|
|
56
|
-
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.processMessagesCore}
|
|
57
|
-
*/
|
|
58
55
|
protected processMessagesCore(messagesCollection: IRuntimeMessageCollection): void;
|
|
59
56
|
private processMessage;
|
|
60
57
|
/**
|
package/dist/counter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"counter.d.ts","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACX,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,gDAAgD,CAAC;AAGxD,OAAO,KAAK,EACX,qBAAqB,EACrB,yBAAyB,EAGzB,MAAM,8CAA8C,C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Called when the object has disconnected from the delta stream.
|
|
83
83
|
*/
|
|
84
84
|
onDisconnect() { }
|
|
85
|
-
/**
|
|
86
|
-
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.processMessagesCore}
|
|
87
|
-
*/
|
|
88
85
|
processMessagesCore(messagesCollection) {
|
|
89
86
|
const { envelope, local, messagesContent } = messagesCollection;
|
|
90
87
|
for (const messageContent of messagesContent) {
|
package/dist/counter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"counter.js","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAM7D,0EAA0E;AAC1E,oEAAqE;AAQrE,0EAGqD;AAgCrD,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;;GAGG;AACH,MAAa,aACZ,SAAQ,uBAAkC;IAG1C,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B;QAE9B,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;QAG1C,WAAM,GAAW,CAAC,CAAC;QAE3B;;WAEG;QACc,eAAU,GAAwB,EAAE,CAAC;QAEtD;;WAEG;QACK,yBAAoB,GAAW,CAAC,CAAC;IAZzC,CAAC;IAcD;;OAEG;IACH,IAAW,KAAK;QACf,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IAED;;OAEG;IACI,SAAS,CAAC,eAAuB;QACvC,uGAAuG;QACvG,wGAAwG;QACxG,IAAI,eAAe,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACrD,CAAC;QAED,MAAM,EAAE,GAAwB;YAC/B,IAAI,EAAE,WAAW;YACjB,eAAe;SACf,CAAC;QACF,MAAM,SAAS,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAE9C,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;QACpC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,CAAC,OAAgB,EAAE,eAAwB;QAC5D,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAC7B,IAAA,iBAAM,EACL,OAAO,eAAe,KAAK,QAAQ,EACnC,KAAK,CAAC,wCAAwC,CAC9C,CAAC;QACF,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;QACxC,IAAA,iBAAM;QACL,sGAAsG;QACtG,SAAS,KAAK,SAAS;YACtB,SAAS,CAAC,SAAS,KAAK,eAAe;YACvC,SAAS,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI;YAC/B,SAAS,CAAC,eAAe,KAAK,OAAO,CAAC,eAAe,EACtD,KAAK,CAAC,6CAA6C,CACnD,CAAC;QACF,gFAAgF;QAChF,0EAA0E;QAC1E,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAC9C,CAAC;CACD;AA9KD,sCA8KC;AAED,SAAS,mBAAmB,CAAC,EAAW;IACvC,IAAA,iBAAM,EACL,OAAO,EAAE,KAAK,QAAQ;QACrB,EAAE,KAAK,IAAI;QACX,MAAM,IAAI,EAAE;QACZ,iBAAiB,IAAI,EAAE;QACvB,EAAE,CAAC,IAAI,KAAK,WAAW;QACvB,OAAO,EAAE,CAAC,eAAe,KAAK,QAAQ,EACvC,KAAK,CAAC,iCAAiC,CACvC,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { MessageType } from \"@fluidframework/driver-definitions/internal\";\nimport { readAndParse } from \"@fluidframework/driver-utils/internal\";\nimport type {\n\tISummaryTreeWithStats,\n\tIRuntimeMessageCollection,\n\tIRuntimeMessagesContent,\n\tISequencedMessageEnvelope,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport type { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tSharedObject,\n\tcreateSingleBlobSummary,\n} from \"@fluidframework/shared-object-base/internal\";\n\nimport type { ISharedCounter, ISharedCounterEvents } from \"./interfaces.js\";\n\n/**\n * Describes the operation (op) format for incrementing the {@link SharedCounter}.\n */\nexport interface IIncrementOperation {\n\ttype: \"increment\";\n\tincrementAmount: number;\n}\n\n/**\n * Represents a pending op that has been submitted but not yet ack'd.\n * Includes the messageId that was used when submitting the op.\n */\ninterface IPendingOperation {\n\ttype: \"increment\";\n\tincrementAmount: number;\n\tmessageId: number;\n}\n\n/**\n * @remarks Used in snapshotting.\n */\ninterface ICounterSnapshotFormat {\n\t/**\n\t * The value of the counter.\n\t */\n\tvalue: number;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * {@inheritDoc ISharedCounter}\n * @legacy @beta\n */\nexport class SharedCounter\n\textends SharedObject<ISharedCounterEvents>\n\timplements ISharedCounter\n{\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_counter_\");\n\t}\n\n\tprivate _value: number = 0;\n\n\t/**\n\t * Tracks pending local ops that have not been ack'd yet.\n\t */\n\tprivate readonly pendingOps: IPendingOperation[] = [];\n\n\t/**\n\t * The next message id to be used when submitting an op.\n\t */\n\tprivate nextPendingMessageId: number = 0;\n\n\t/**\n\t * {@inheritDoc ISharedCounter.value}\n\t */\n\tpublic get value(): number {\n\t\treturn this._value;\n\t}\n\n\t/**\n\t * {@inheritDoc ISharedCounter.increment}\n\t */\n\tpublic increment(incrementAmount: number): void {\n\t\t// Incrementing by floating point numbers will be eventually inconsistent, since the order in which the\n\t\t// increments are applied affects the result. A more-robust solution would be required to support this.\n\t\tif (incrementAmount % 1 !== 0) {\n\t\t\tthrow new Error(\"Must increment by a whole number\");\n\t\t}\n\n\t\tconst op: IIncrementOperation = {\n\t\t\ttype: \"increment\",\n\t\t\tincrementAmount,\n\t\t};\n\t\tconst messageId = this.nextPendingMessageId++;\n\n\t\tthis.incrementCore(incrementAmount);\n\t\t// We don't need to send the op if we are not attached yet.\n\t\tif (this.isAttached()) {\n\t\t\tthis.pendingOps.push({ ...op, messageId });\n\t\t\tthis.submitLocalMessage(op, messageId);\n\t\t}\n\t}\n\n\tprivate incrementCore(incrementAmount: number): void {\n\t\tthis._value += incrementAmount;\n\t\tthis.emit(\"incremented\", incrementAmount, this._value);\n\t}\n\n\t/**\n\t * Create a summary for the counter.\n\t *\n\t * @returns The summary of the current state of the counter.\n\t */\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\t// Get a serializable form of data\n\t\tconst content: ICounterSnapshotFormat = {\n\t\t\tvalue: this.value,\n\t\t};\n\n\t\t// And then construct the summary for it\n\t\treturn createSingleBlobSummary(snapshotFileName, JSON.stringify(content));\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst content = await readAndParse<ICounterSnapshotFormat>(storage, snapshotFileName);\n\n\t\tthis._value = content.value;\n\t}\n\n\t/**\n\t * Called when the object has disconnected from the delta stream.\n\t */\n\tprotected onDisconnect(): void {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.processMessagesCore}\n\t */\n\tprotected processMessagesCore(messagesCollection: IRuntimeMessageCollection): void {\n\t\tconst { envelope, local, messagesContent } = messagesCollection;\n\t\tfor (const messageContent of messagesContent) {\n\t\t\tthis.processMessage(envelope, messageContent, local);\n\t\t}\n\t}\n\n\tprivate processMessage(\n\t\tmessageEnvelope: ISequencedMessageEnvelope,\n\t\tmessageContent: IRuntimeMessagesContent,\n\t\tlocal: boolean,\n\t): void {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n\t\tif (messageEnvelope.type === MessageType.Operation) {\n\t\t\tconst op = messageContent.contents as IIncrementOperation;\n\n\t\t\t// If the message is local we have already optimistically processed\n\t\t\t// and we should now remove it from this.pendingOps.\n\t\t\t// If the message is from a remote client, we should process it.\n\t\t\tif (local) {\n\t\t\t\tconst pendingOp = this.pendingOps.shift();\n\t\t\t\tconst messageId = messageContent.localOpMetadata;\n\t\t\t\tassert(typeof messageId === \"number\", 0xc8e /* localOpMetadata should be a number */);\n\t\t\t\tassert(\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- using ?. could change behavior\n\t\t\t\t\tpendingOp !== undefined &&\n\t\t\t\t\t\tpendingOp.messageId === messageId &&\n\t\t\t\t\t\tpendingOp.type === op.type &&\n\t\t\t\t\t\tpendingOp.incrementAmount === op.incrementAmount,\n\t\t\t\t\t0xc8f /* local op mismatch */,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tswitch (op.type) {\n\t\t\t\t\tcase \"increment\": {\n\t\t\t\t\t\tthis.incrementCore(op.incrementAmount);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tthrow new Error(\"Unknown operation\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritdoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}\n\t */\n\tprotected applyStashedOp(op: unknown): void {\n\t\tconst counterOp = op as IIncrementOperation;\n\n\t\t// TODO: Clean up error code linter violations repo-wide.\n\n\t\tassert(counterOp.type === \"increment\", 0x3ec /* Op type is not increment */);\n\n\t\tthis.increment(counterOp.incrementAmount);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.rollback}\n\t * @sealed\n\t */\n\tprotected rollback(content: unknown, localOpMetadata: unknown): void {\n\t\tassertIsIncrementOp(content);\n\t\tassert(\n\t\t\ttypeof localOpMetadata === \"number\",\n\t\t\t0xc90 /* localOpMetadata should be a number */,\n\t\t);\n\t\tconst pendingOp = this.pendingOps.pop();\n\t\tassert(\n\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- using ?. could change behavior\n\t\t\tpendingOp !== undefined &&\n\t\t\t\tpendingOp.messageId === localOpMetadata &&\n\t\t\t\tpendingOp.type === content.type &&\n\t\t\t\tpendingOp.incrementAmount === content.incrementAmount,\n\t\t\t0xc91 /* op to rollback mismatch with pending op */,\n\t\t);\n\t\t// To rollback the optimistic increment we can increment by the opposite amount.\n\t\t// This will also emit another incremented event with the opposite amount.\n\t\tthis.incrementCore(-content.incrementAmount);\n\t}\n}\n\nfunction assertIsIncrementOp(op: unknown): asserts op is IIncrementOperation {\n\tassert(\n\t\ttypeof op === \"object\" &&\n\t\t\top !== null &&\n\t\t\t\"type\" in op &&\n\t\t\t\"incrementAmount\" in op &&\n\t\t\top.type === \"increment\" &&\n\t\t\ttypeof op.incrementAmount === \"number\",\n\t\t0xc92 /* invalid increment op format */,\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"counter.js","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAM7D,0EAA0E;AAC1E,oEAAqE;AAQrE,0EAGqD;AAgCrD,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;;GAGG;AACH,MAAa,aACZ,SAAQ,uBAAkC;IAG1C,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B;QAE9B,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;QAG1C,WAAM,GAAW,CAAC,CAAC;QAE3B;;WAEG;QACc,eAAU,GAAwB,EAAE,CAAC;QAEtD;;WAEG;QACK,yBAAoB,GAAW,CAAC,CAAC;IAZzC,CAAC;IAcD;;OAEG;IACH,IAAW,KAAK;QACf,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IAED;;OAEG;IACI,SAAS,C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rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { MessageType } from \"@fluidframework/driver-definitions/internal\";\nimport { readAndParse } from \"@fluidframework/driver-utils/internal\";\nimport type {\n\tISummaryTreeWithStats,\n\tIRuntimeMessageCollection,\n\tIRuntimeMessagesContent,\n\tISequencedMessageEnvelope,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport type { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tSharedObject,\n\tcreateSingleBlobSummary,\n} from \"@fluidframework/shared-object-base/internal\";\n\nimport type { ISharedCounter, ISharedCounterEvents } from \"./interfaces.js\";\n\n/**\n * Describes the operation (op) format for incrementing the {@link SharedCounter}.\n */\nexport interface IIncrementOperation {\n\ttype: \"increment\";\n\tincrementAmount: number;\n}\n\n/**\n * Represents a pending op that has been submitted but not yet ack'd.\n * Includes the messageId that was used when submitting the op.\n */\ninterface IPendingOperation {\n\ttype: \"increment\";\n\tincrementAmount: number;\n\tmessageId: number;\n}\n\n/**\n * @remarks Used in snapshotting.\n */\ninterface ICounterSnapshotFormat {\n\t/**\n\t * The value of the counter.\n\t */\n\tvalue: number;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * {@inheritDoc ISharedCounter}\n * @legacy @beta\n */\nexport class SharedCounter\n\textends SharedObject<ISharedCounterEvents>\n\timplements ISharedCounter\n{\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_counter_\");\n\t}\n\n\tprivate _value: number = 0;\n\n\t/**\n\t * Tracks pending local ops that have not been ack'd yet.\n\t */\n\tprivate readonly pendingOps: IPendingOperation[] = [];\n\n\t/**\n\t * The next message id to be used when submitting an op.\n\t */\n\tprivate nextPendingMessageId: number = 0;\n\n\t/**\n\t * {@inheritDoc ISharedCounter.value}\n\t */\n\tpublic get value(): number {\n\t\treturn this._value;\n\t}\n\n\t/**\n\t * {@inheritDoc ISharedCounter.increment}\n\t */\n\tpublic increment(incrementAmount: number): void {\n\t\t// Incrementing by floating point numbers will be eventually inconsistent, since the order in which the\n\t\t// increments are applied affects the result. A more-robust solution would be required to support this.\n\t\tif (incrementAmount % 1 !== 0) {\n\t\t\tthrow new Error(\"Must increment by a whole number\");\n\t\t}\n\n\t\tconst op: IIncrementOperation = {\n\t\t\ttype: \"increment\",\n\t\t\tincrementAmount,\n\t\t};\n\t\tconst messageId = this.nextPendingMessageId++;\n\n\t\tthis.incrementCore(incrementAmount);\n\t\t// We don't need to send the op if we are not attached yet.\n\t\tif (this.isAttached()) {\n\t\t\tthis.pendingOps.push({ ...op, messageId });\n\t\t\tthis.submitLocalMessage(op, messageId);\n\t\t}\n\t}\n\n\tprivate incrementCore(incrementAmount: number): void {\n\t\tthis._value += incrementAmount;\n\t\tthis.emit(\"incremented\", incrementAmount, this._value);\n\t}\n\n\t/**\n\t * Create a summary for the counter.\n\t *\n\t * @returns The summary of the current state of the counter.\n\t */\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\t// Get a serializable form of data\n\t\tconst content: ICounterSnapshotFormat = {\n\t\t\tvalue: this.value,\n\t\t};\n\n\t\t// And then construct the summary for it\n\t\treturn createSingleBlobSummary(snapshotFileName, JSON.stringify(content));\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst content = await readAndParse<ICounterSnapshotFormat>(storage, snapshotFileName);\n\n\t\tthis._value = content.value;\n\t}\n\n\t/**\n\t * Called when the object has disconnected from the delta stream.\n\t */\n\tprotected onDisconnect(): void {}\n\n\tprotected override processMessagesCore(messagesCollection: IRuntimeMessageCollection): void {\n\t\tconst { envelope, local, messagesContent } = messagesCollection;\n\t\tfor (const messageContent of messagesContent) {\n\t\t\tthis.processMessage(envelope, messageContent, local);\n\t\t}\n\t}\n\n\tprivate processMessage(\n\t\tmessageEnvelope: ISequencedMessageEnvelope,\n\t\tmessageContent: IRuntimeMessagesContent,\n\t\tlocal: boolean,\n\t): void {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n\t\tif (messageEnvelope.type === MessageType.Operation) {\n\t\t\tconst op = messageContent.contents as IIncrementOperation;\n\n\t\t\t// If the message is local we have already optimistically processed\n\t\t\t// and we should now remove it from this.pendingOps.\n\t\t\t// If the message is from a remote client, we should process it.\n\t\t\tif (local) {\n\t\t\t\tconst pendingOp = this.pendingOps.shift();\n\t\t\t\tconst messageId = messageContent.localOpMetadata;\n\t\t\t\tassert(typeof messageId === \"number\", 0xc8e /* localOpMetadata should be a number */);\n\t\t\t\tassert(\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- using ?. could change behavior\n\t\t\t\t\tpendingOp !== undefined &&\n\t\t\t\t\t\tpendingOp.messageId === messageId &&\n\t\t\t\t\t\tpendingOp.type === op.type &&\n\t\t\t\t\t\tpendingOp.incrementAmount === op.incrementAmount,\n\t\t\t\t\t0xc8f /* local op mismatch */,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tswitch (op.type) {\n\t\t\t\t\tcase \"increment\": {\n\t\t\t\t\t\tthis.incrementCore(op.incrementAmount);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tthrow new Error(\"Unknown operation\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritdoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}\n\t */\n\tprotected applyStashedOp(op: unknown): void {\n\t\tconst counterOp = op as IIncrementOperation;\n\n\t\t// TODO: Clean up error code linter violations repo-wide.\n\n\t\tassert(counterOp.type === \"increment\", 0x3ec /* Op type is not increment */);\n\n\t\tthis.increment(counterOp.incrementAmount);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.rollback}\n\t * @sealed\n\t */\n\tprotected rollback(content: unknown, localOpMetadata: unknown): void {\n\t\tassertIsIncrementOp(content);\n\t\tassert(\n\t\t\ttypeof localOpMetadata === \"number\",\n\t\t\t0xc90 /* localOpMetadata should be a number */,\n\t\t);\n\t\tconst pendingOp = this.pendingOps.pop();\n\t\tassert(\n\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- using ?. could change behavior\n\t\t\tpendingOp !== undefined &&\n\t\t\t\tpendingOp.messageId === localOpMetadata &&\n\t\t\t\tpendingOp.type === content.type &&\n\t\t\t\tpendingOp.incrementAmount === content.incrementAmount,\n\t\t\t0xc91 /* op to rollback mismatch with pending op */,\n\t\t);\n\t\t// To rollback the optimistic increment we can increment by the opposite amount.\n\t\t// This will also emit another incremented event with the opposite amount.\n\t\tthis.incrementCore(-content.incrementAmount);\n\t}\n}\n\nfunction assertIsIncrementOp(op: unknown): asserts op is IIncrementOperation {\n\tassert(\n\t\ttypeof op === \"object\" &&\n\t\t\top !== null &&\n\t\t\t\"type\" in op &&\n\t\t\t\"incrementAmount\" in op &&\n\t\t\top.type === \"increment\" &&\n\t\t\ttypeof op.incrementAmount === \"number\",\n\t\t0xc92 /* invalid increment op format */,\n\t);\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/counter";
|
|
8
|
-
export declare const pkgVersion = "2.
|
|
8
|
+
export declare const pkgVersion = "2.91.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,4BAA4B,CAAC;AACjD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,4BAA4B,CAAC;AACjD,eAAO,MAAM,UAAU,WAAW,CAAC"}
|
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/counter";
|
|
11
|
-
exports.pkgVersion = "2.
|
|
11
|
+
exports.pkgVersion = "2.91.0";
|
|
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,yBAAyB,CAAC;AACpC,QAAA,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,yBAAyB,CAAC;AACpC,QAAA,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/counter\";\nexport const pkgVersion = \"2.91.0\";\n"]}
|
package/lib/counter.d.ts
CHANGED
|
@@ -52,9 +52,6 @@ export declare class SharedCounter extends SharedObject<ISharedCounterEvents> im
|
|
|
52
52
|
* Called when the object has disconnected from the delta stream.
|
|
53
53
|
*/
|
|
54
54
|
protected onDisconnect(): void;
|
|
55
|
-
/**
|
|
56
|
-
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.processMessagesCore}
|
|
57
|
-
*/
|
|
58
55
|
protected processMessagesCore(messagesCollection: IRuntimeMessageCollection): void;
|
|
59
56
|
private processMessage;
|
|
60
57
|
/**
|
package/lib/counter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"counter.d.ts","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACX,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,gDAAgD,CAAC;AAGxD,OAAO,KAAK,EACX,qBAAqB,EACrB,yBAAyB,EAGzB,MAAM,8CAA8C,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AACpF,OAAO,EACN,YAAY,EAEZ,MAAM,6CAA6C,CAAC;AAErD,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,WAAW,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;CACxB;AAwBD;;;GAGG;AACH,qBAAa,aACZ,SAAQ,YAAY,CAAC,oBAAoB,CACzC,YAAW,cAAc;gBAGxB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,sBAAsB,EAC/B,UAAU,EAAE,kBAAkB;IAK/B,OAAO,CAAC,MAAM,CAAa;IAE3B;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA2B;IAEtD;;OAEG;IACH,OAAO,CAAC,oBAAoB,CAAa;IAEzC;;OAEG;IACH,IAAW,KAAK,IAAI,MAAM,CAEzB;IAED;;OAEG;IACI,SAAS,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI;IAqB/C,OAAO,C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AAC,UAAU,EAAE,gBAAgB,GAAG,qBAAqB;IAU5E;;OAEG;cACa,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAMxE;;OAEG;IACH,SAAS,CAAC,YAAY,IAAI,IAAI;cAEX,mBAAmB,CAAC,kBAAkB,EAAE,yBAAyB,GAAG,IAAI;IAO3F,OAAO,CAAC,cAAc;IAuCtB;;OAEG;IACH,SAAS,CAAC,cAAc,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI;IAU3C;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,GAAG,IAAI;CAmBpE"}
|
package/lib/counter.js
CHANGED
|
@@ -79,9 +79,6 @@ export class SharedCounter extends SharedObject {
|
|
|
79
79
|
* Called when the object has disconnected from the delta stream.
|
|
80
80
|
*/
|
|
81
81
|
onDisconnect() { }
|
|
82
|
-
/**
|
|
83
|
-
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.processMessagesCore}
|
|
84
|
-
*/
|
|
85
82
|
processMessagesCore(messagesCollection) {
|
|
86
83
|
const { envelope, local, messagesContent } = messagesCollection;
|
|
87
84
|
for (const messageContent of messagesContent) {
|
package/lib/counter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"counter.js","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAM7D,OAAO,EAAE,WAAW,EAAE,MAAM,6CAA6C,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAQrE,OAAO,EACN,YAAY,EACZ,uBAAuB,GACvB,MAAM,6CAA6C,CAAC;AAgCrD,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;;GAGG;AACH,MAAM,OAAO,aACZ,SAAQ,YAAkC;IAG1C,YACC,EAAU,E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M,CACL,OAAO,EAAE,KAAK,QAAQ;QACrB,EAAE,KAAK,IAAI;QACX,MAAM,IAAI,EAAE;QACZ,iBAAiB,IAAI,EAAE;QACvB,EAAE,CAAC,IAAI,KAAK,WAAW;QACvB,OAAO,EAAE,CAAC,eAAe,KAAK,QAAQ,EACvC,KAAK,CAAC,iCAAiC,CACvC,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { MessageType } from \"@fluidframework/driver-definitions/internal\";\nimport { readAndParse } from \"@fluidframework/driver-utils/internal\";\nimport type {\n\tISummaryTreeWithStats,\n\tIRuntimeMessageCollection,\n\tIRuntimeMessagesContent,\n\tISequencedMessageEnvelope,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport type { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tSharedObject,\n\tcreateSingleBlobSummary,\n} from \"@fluidframework/shared-object-base/internal\";\n\nimport type { ISharedCounter, ISharedCounterEvents } from \"./interfaces.js\";\n\n/**\n * Describes the operation (op) format for incrementing the {@link SharedCounter}.\n */\nexport interface IIncrementOperation {\n\ttype: \"increment\";\n\tincrementAmount: number;\n}\n\n/**\n * Represents a pending op that has been submitted but not yet ack'd.\n * Includes the messageId that was used when submitting the op.\n */\ninterface IPendingOperation {\n\ttype: \"increment\";\n\tincrementAmount: number;\n\tmessageId: number;\n}\n\n/**\n * @remarks Used in snapshotting.\n */\ninterface ICounterSnapshotFormat {\n\t/**\n\t * The value of the counter.\n\t */\n\tvalue: number;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * {@inheritDoc ISharedCounter}\n * @legacy @beta\n */\nexport class SharedCounter\n\textends SharedObject<ISharedCounterEvents>\n\timplements ISharedCounter\n{\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_counter_\");\n\t}\n\n\tprivate _value: number = 0;\n\n\t/**\n\t * Tracks pending local ops that have not been ack'd yet.\n\t */\n\tprivate readonly pendingOps: IPendingOperation[] = [];\n\n\t/**\n\t * The next message id to be used when submitting an op.\n\t */\n\tprivate nextPendingMessageId: number = 0;\n\n\t/**\n\t * {@inheritDoc ISharedCounter.value}\n\t */\n\tpublic get value(): number {\n\t\treturn this._value;\n\t}\n\n\t/**\n\t * {@inheritDoc ISharedCounter.increment}\n\t */\n\tpublic increment(incrementAmount: number): void {\n\t\t// Incrementing by floating point numbers will be eventually inconsistent, since the order in which the\n\t\t// increments are applied affects the result. A more-robust solution would be required to support this.\n\t\tif (incrementAmount % 1 !== 0) {\n\t\t\tthrow new Error(\"Must increment by a whole number\");\n\t\t}\n\n\t\tconst op: IIncrementOperation = {\n\t\t\ttype: \"increment\",\n\t\t\tincrementAmount,\n\t\t};\n\t\tconst messageId = this.nextPendingMessageId++;\n\n\t\tthis.incrementCore(incrementAmount);\n\t\t// We don't need to send the op if we are not attached yet.\n\t\tif (this.isAttached()) {\n\t\t\tthis.pendingOps.push({ ...op, messageId });\n\t\t\tthis.submitLocalMessage(op, messageId);\n\t\t}\n\t}\n\n\tprivate incrementCore(incrementAmount: number): void {\n\t\tthis._value += incrementAmount;\n\t\tthis.emit(\"incremented\", incrementAmount, this._value);\n\t}\n\n\t/**\n\t * Create a summary for the counter.\n\t *\n\t * @returns The summary of the current state of the counter.\n\t */\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\t// Get a serializable form of data\n\t\tconst content: ICounterSnapshotFormat = {\n\t\t\tvalue: this.value,\n\t\t};\n\n\t\t// And then construct the summary for it\n\t\treturn createSingleBlobSummary(snapshotFileName, JSON.stringify(content));\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst content = await readAndParse<ICounterSnapshotFormat>(storage, snapshotFileName);\n\n\t\tthis._value = content.value;\n\t}\n\n\t/**\n\t * Called when the object has disconnected from the delta stream.\n\t */\n\tprotected onDisconnect(): void {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.processMessagesCore}\n\t */\n\tprotected processMessagesCore(messagesCollection: IRuntimeMessageCollection): void {\n\t\tconst { envelope, local, messagesContent } = messagesCollection;\n\t\tfor (const messageContent of messagesContent) {\n\t\t\tthis.processMessage(envelope, messageContent, local);\n\t\t}\n\t}\n\n\tprivate processMessage(\n\t\tmessageEnvelope: ISequencedMessageEnvelope,\n\t\tmessageContent: IRuntimeMessagesContent,\n\t\tlocal: boolean,\n\t): void {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n\t\tif (messageEnvelope.type === MessageType.Operation) {\n\t\t\tconst op = messageContent.contents as IIncrementOperation;\n\n\t\t\t// If the message is local we have already optimistically processed\n\t\t\t// and we should now remove it from this.pendingOps.\n\t\t\t// If the message is from a remote client, we should process it.\n\t\t\tif (local) {\n\t\t\t\tconst pendingOp = this.pendingOps.shift();\n\t\t\t\tconst messageId = messageContent.localOpMetadata;\n\t\t\t\tassert(typeof messageId === \"number\", 0xc8e /* localOpMetadata should be a number */);\n\t\t\t\tassert(\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- using ?. could change behavior\n\t\t\t\t\tpendingOp !== undefined &&\n\t\t\t\t\t\tpendingOp.messageId === messageId &&\n\t\t\t\t\t\tpendingOp.type === op.type &&\n\t\t\t\t\t\tpendingOp.incrementAmount === op.incrementAmount,\n\t\t\t\t\t0xc8f /* local op mismatch */,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tswitch (op.type) {\n\t\t\t\t\tcase \"increment\": {\n\t\t\t\t\t\tthis.incrementCore(op.incrementAmount);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tthrow new Error(\"Unknown operation\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritdoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}\n\t */\n\tprotected applyStashedOp(op: unknown): void {\n\t\tconst counterOp = op as IIncrementOperation;\n\n\t\t// TODO: Clean up error code linter violations repo-wide.\n\n\t\tassert(counterOp.type === \"increment\", 0x3ec /* Op type is not increment */);\n\n\t\tthis.increment(counterOp.incrementAmount);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.rollback}\n\t * @sealed\n\t */\n\tprotected rollback(content: unknown, localOpMetadata: unknown): void {\n\t\tassertIsIncrementOp(content);\n\t\tassert(\n\t\t\ttypeof localOpMetadata === \"number\",\n\t\t\t0xc90 /* localOpMetadata should be a number */,\n\t\t);\n\t\tconst pendingOp = this.pendingOps.pop();\n\t\tassert(\n\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- using ?. could change behavior\n\t\t\tpendingOp !== undefined &&\n\t\t\t\tpendingOp.messageId === localOpMetadata &&\n\t\t\t\tpendingOp.type === content.type &&\n\t\t\t\tpendingOp.incrementAmount === content.incrementAmount,\n\t\t\t0xc91 /* op to rollback mismatch with pending op */,\n\t\t);\n\t\t// To rollback the optimistic increment we can increment by the opposite amount.\n\t\t// This will also emit another incremented event with the opposite amount.\n\t\tthis.incrementCore(-content.incrementAmount);\n\t}\n}\n\nfunction assertIsIncrementOp(op: unknown): asserts op is IIncrementOperation {\n\tassert(\n\t\ttypeof op === \"object\" &&\n\t\t\top !== null &&\n\t\t\t\"type\" in op &&\n\t\t\t\"incrementAmount\" in op &&\n\t\t\top.type === \"increment\" &&\n\t\t\ttypeof op.incrementAmount === \"number\",\n\t\t0xc92 /* invalid increment op format */,\n\t);\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,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;QACxC,MAAM;QACL,sGAAsG;QACtG,SAAS,KAAK,SAAS;YACtB,SAAS,CAAC,SAAS,KAAK,eAAe;YACvC,SAAS,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI;YAC/B,SAAS,CAAC,eAAe,KAAK,OAAO,CAAC,eAAe,EACtD,KAAK,CAAC,6CAA6C,CACnD,CAAC;QACF,gFAAgF;QAChF,0EAA0E;QAC1E,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAC9C,CAAC;CACD;AAED,SAAS,mBAAmB,CAAC,EAAW;IACvC,MAAM,CACL,OAAO,EAAE,KAAK,QAAQ;QACrB,EAAE,KAAK,IAAI;QACX,MAAM,IAAI,EAAE;QACZ,iBAAiB,IAAI,EAAE;QACvB,EAAE,CAAC,IAAI,KAAK,WAAW;QACvB,OAAO,EAAE,CAAC,eAAe,KAAK,QAAQ,EACvC,KAAK,CAAC,iCAAiC,CACvC,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { MessageType } from \"@fluidframework/driver-definitions/internal\";\nimport { readAndParse } from \"@fluidframework/driver-utils/internal\";\nimport type {\n\tISummaryTreeWithStats,\n\tIRuntimeMessageCollection,\n\tIRuntimeMessagesContent,\n\tISequencedMessageEnvelope,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport type { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tSharedObject,\n\tcreateSingleBlobSummary,\n} from \"@fluidframework/shared-object-base/internal\";\n\nimport type { ISharedCounter, ISharedCounterEvents } from \"./interfaces.js\";\n\n/**\n * Describes the operation (op) format for incrementing the {@link SharedCounter}.\n */\nexport interface IIncrementOperation {\n\ttype: \"increment\";\n\tincrementAmount: number;\n}\n\n/**\n * Represents a pending op that has been submitted but not yet ack'd.\n * Includes the messageId that was used when submitting the op.\n */\ninterface IPendingOperation {\n\ttype: \"increment\";\n\tincrementAmount: number;\n\tmessageId: number;\n}\n\n/**\n * @remarks Used in snapshotting.\n */\ninterface ICounterSnapshotFormat {\n\t/**\n\t * The value of the counter.\n\t */\n\tvalue: number;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * {@inheritDoc ISharedCounter}\n * @legacy @beta\n */\nexport class SharedCounter\n\textends SharedObject<ISharedCounterEvents>\n\timplements ISharedCounter\n{\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_counter_\");\n\t}\n\n\tprivate _value: number = 0;\n\n\t/**\n\t * Tracks pending local ops that have not been ack'd yet.\n\t */\n\tprivate readonly pendingOps: IPendingOperation[] = [];\n\n\t/**\n\t * The next message id to be used when submitting an op.\n\t */\n\tprivate nextPendingMessageId: number = 0;\n\n\t/**\n\t * {@inheritDoc ISharedCounter.value}\n\t */\n\tpublic get value(): number {\n\t\treturn this._value;\n\t}\n\n\t/**\n\t * {@inheritDoc ISharedCounter.increment}\n\t */\n\tpublic increment(incrementAmount: number): void {\n\t\t// Incrementing by floating point numbers will be eventually inconsistent, since the order in which the\n\t\t// increments are applied affects the result. A more-robust solution would be required to support this.\n\t\tif (incrementAmount % 1 !== 0) {\n\t\t\tthrow new Error(\"Must increment by a whole number\");\n\t\t}\n\n\t\tconst op: IIncrementOperation = {\n\t\t\ttype: \"increment\",\n\t\t\tincrementAmount,\n\t\t};\n\t\tconst messageId = this.nextPendingMessageId++;\n\n\t\tthis.incrementCore(incrementAmount);\n\t\t// We don't need to send the op if we are not attached yet.\n\t\tif (this.isAttached()) {\n\t\t\tthis.pendingOps.push({ ...op, messageId });\n\t\t\tthis.submitLocalMessage(op, messageId);\n\t\t}\n\t}\n\n\tprivate incrementCore(incrementAmount: number): void {\n\t\tthis._value += incrementAmount;\n\t\tthis.emit(\"incremented\", incrementAmount, this._value);\n\t}\n\n\t/**\n\t * Create a summary for the counter.\n\t *\n\t * @returns The summary of the current state of the counter.\n\t */\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\t// Get a serializable form of data\n\t\tconst content: ICounterSnapshotFormat = {\n\t\t\tvalue: this.value,\n\t\t};\n\n\t\t// And then construct the summary for it\n\t\treturn createSingleBlobSummary(snapshotFileName, JSON.stringify(content));\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst content = await readAndParse<ICounterSnapshotFormat>(storage, snapshotFileName);\n\n\t\tthis._value = content.value;\n\t}\n\n\t/**\n\t * Called when the object has disconnected from the delta stream.\n\t */\n\tprotected onDisconnect(): void {}\n\n\tprotected override processMessagesCore(messagesCollection: IRuntimeMessageCollection): void {\n\t\tconst { envelope, local, messagesContent } = messagesCollection;\n\t\tfor (const messageContent of messagesContent) {\n\t\t\tthis.processMessage(envelope, messageContent, local);\n\t\t}\n\t}\n\n\tprivate processMessage(\n\t\tmessageEnvelope: ISequencedMessageEnvelope,\n\t\tmessageContent: IRuntimeMessagesContent,\n\t\tlocal: boolean,\n\t): void {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n\t\tif (messageEnvelope.type === MessageType.Operation) {\n\t\t\tconst op = messageContent.contents as IIncrementOperation;\n\n\t\t\t// If the message is local we have already optimistically processed\n\t\t\t// and we should now remove it from this.pendingOps.\n\t\t\t// If the message is from a remote client, we should process it.\n\t\t\tif (local) {\n\t\t\t\tconst pendingOp = this.pendingOps.shift();\n\t\t\t\tconst messageId = messageContent.localOpMetadata;\n\t\t\t\tassert(typeof messageId === \"number\", 0xc8e /* localOpMetadata should be a number */);\n\t\t\t\tassert(\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- using ?. could change behavior\n\t\t\t\t\tpendingOp !== undefined &&\n\t\t\t\t\t\tpendingOp.messageId === messageId &&\n\t\t\t\t\t\tpendingOp.type === op.type &&\n\t\t\t\t\t\tpendingOp.incrementAmount === op.incrementAmount,\n\t\t\t\t\t0xc8f /* local op mismatch */,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tswitch (op.type) {\n\t\t\t\t\tcase \"increment\": {\n\t\t\t\t\t\tthis.incrementCore(op.incrementAmount);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tthrow new Error(\"Unknown operation\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritdoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}\n\t */\n\tprotected applyStashedOp(op: unknown): void {\n\t\tconst counterOp = op as IIncrementOperation;\n\n\t\t// TODO: Clean up error code linter violations repo-wide.\n\n\t\tassert(counterOp.type === \"increment\", 0x3ec /* Op type is not increment */);\n\n\t\tthis.increment(counterOp.incrementAmount);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.rollback}\n\t * @sealed\n\t */\n\tprotected rollback(content: unknown, localOpMetadata: unknown): void {\n\t\tassertIsIncrementOp(content);\n\t\tassert(\n\t\t\ttypeof localOpMetadata === \"number\",\n\t\t\t0xc90 /* localOpMetadata should be a number */,\n\t\t);\n\t\tconst pendingOp = this.pendingOps.pop();\n\t\tassert(\n\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- using ?. could change behavior\n\t\t\tpendingOp !== undefined &&\n\t\t\t\tpendingOp.messageId === localOpMetadata &&\n\t\t\t\tpendingOp.type === content.type &&\n\t\t\t\tpendingOp.incrementAmount === content.incrementAmount,\n\t\t\t0xc91 /* op to rollback mismatch with pending op */,\n\t\t);\n\t\t// To rollback the optimistic increment we can increment by the opposite amount.\n\t\t// This will also emit another incremented event with the opposite amount.\n\t\tthis.incrementCore(-content.incrementAmount);\n\t}\n}\n\nfunction assertIsIncrementOp(op: unknown): asserts op is IIncrementOperation {\n\tassert(\n\t\ttypeof op === \"object\" &&\n\t\t\top !== null &&\n\t\t\t\"type\" in op &&\n\t\t\t\"incrementAmount\" in op &&\n\t\t\top.type === \"increment\" &&\n\t\t\ttypeof op.incrementAmount === \"number\",\n\t\t0xc92 /* invalid increment op format */,\n\t);\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/counter";
|
|
8
|
-
export declare const pkgVersion = "2.
|
|
8
|
+
export declare const pkgVersion = "2.91.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,4BAA4B,CAAC;AACjD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,4BAA4B,CAAC;AACjD,eAAO,MAAM,UAAU,WAAW,CAAC"}
|
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,yBAAyB,CAAC;AACjD,MAAM,CAAC,MAAM,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,yBAAyB,CAAC;AACjD,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/counter\";\nexport const pkgVersion = \"2.91.0\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/counter",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.91.0",
|
|
4
4
|
"description": "Counter DDS",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -81,27 +81,27 @@
|
|
|
81
81
|
"temp-directory": "nyc/.nyc_output"
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"@fluidframework/core-interfaces": "2.
|
|
85
|
-
"@fluidframework/core-utils": "2.
|
|
86
|
-
"@fluidframework/datastore-definitions": "2.
|
|
87
|
-
"@fluidframework/driver-definitions": "2.
|
|
88
|
-
"@fluidframework/driver-utils": "2.
|
|
89
|
-
"@fluidframework/runtime-definitions": "2.
|
|
90
|
-
"@fluidframework/shared-object-base": "2.
|
|
84
|
+
"@fluidframework/core-interfaces": "~2.91.0",
|
|
85
|
+
"@fluidframework/core-utils": "~2.91.0",
|
|
86
|
+
"@fluidframework/datastore-definitions": "~2.91.0",
|
|
87
|
+
"@fluidframework/driver-definitions": "~2.91.0",
|
|
88
|
+
"@fluidframework/driver-utils": "~2.91.0",
|
|
89
|
+
"@fluidframework/runtime-definitions": "~2.91.0",
|
|
90
|
+
"@fluidframework/shared-object-base": "~2.91.0"
|
|
91
91
|
},
|
|
92
92
|
"devDependencies": {
|
|
93
93
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
94
|
-
"@biomejs/biome": "~
|
|
95
|
-
"@fluid-internal/mocha-test-setup": "2.
|
|
96
|
-
"@fluid-private/stochastic-test-utils": "2.
|
|
97
|
-
"@fluid-private/test-dds-utils": "2.
|
|
94
|
+
"@biomejs/biome": "~2.4.5",
|
|
95
|
+
"@fluid-internal/mocha-test-setup": "~2.91.0",
|
|
96
|
+
"@fluid-private/stochastic-test-utils": "~2.91.0",
|
|
97
|
+
"@fluid-private/test-dds-utils": "~2.91.0",
|
|
98
98
|
"@fluid-tools/build-cli": "^0.63.0",
|
|
99
99
|
"@fluidframework/build-common": "^2.0.3",
|
|
100
100
|
"@fluidframework/build-tools": "^0.63.0",
|
|
101
|
-
"@fluidframework/container-definitions": "2.
|
|
102
|
-
"@fluidframework/counter-previous": "npm:@fluidframework/counter@2.
|
|
103
|
-
"@fluidframework/eslint-config-fluid": "2.
|
|
104
|
-
"@fluidframework/test-runtime-utils": "2.
|
|
101
|
+
"@fluidframework/container-definitions": "~2.91.0",
|
|
102
|
+
"@fluidframework/counter-previous": "npm:@fluidframework/counter@2.83.0",
|
|
103
|
+
"@fluidframework/eslint-config-fluid": "~2.91.0",
|
|
104
|
+
"@fluidframework/test-runtime-utils": "~2.91.0",
|
|
105
105
|
"@microsoft/api-extractor": "7.52.11",
|
|
106
106
|
"@types/mocha": "^10.0.10",
|
|
107
107
|
"@types/node": "~20.19.30",
|
|
@@ -111,9 +111,9 @@
|
|
|
111
111
|
"cross-env": "^10.1.0",
|
|
112
112
|
"eslint": "~9.39.1",
|
|
113
113
|
"jiti": "^2.6.1",
|
|
114
|
-
"mocha": "^
|
|
114
|
+
"mocha": "^11.7.5",
|
|
115
115
|
"mocha-multi-reporters": "^1.5.1",
|
|
116
|
-
"rimraf": "^6.1.
|
|
116
|
+
"rimraf": "^6.1.3",
|
|
117
117
|
"typescript": "~5.4.5"
|
|
118
118
|
},
|
|
119
119
|
"typeValidation": {
|
package/src/counter.ts
CHANGED
|
@@ -148,10 +148,7 @@ export class SharedCounter
|
|
|
148
148
|
*/
|
|
149
149
|
protected onDisconnect(): void {}
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.processMessagesCore}
|
|
153
|
-
*/
|
|
154
|
-
protected processMessagesCore(messagesCollection: IRuntimeMessageCollection): void {
|
|
151
|
+
protected override processMessagesCore(messagesCollection: IRuntimeMessageCollection): void {
|
|
155
152
|
const { envelope, local, messagesContent } = messagesCollection;
|
|
156
153
|
for (const messageContent of messagesContent) {
|
|
157
154
|
this.processMessage(envelope, messageContent, local);
|
package/src/packageVersion.ts
CHANGED