@fluidframework/counter 0.54.2 → 0.55.0-48551

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.js CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  module.exports = {
7
7
  "extends": [
8
- "@fluidframework/eslint-config-fluid/eslint7"
8
+ "@fluidframework/eslint-config-fluid"
9
9
  ],
10
10
  "parserOptions": {
11
11
  "project": ["./tsconfig.json", "./src/test/tsconfig.json"]
package/dist/counter.d.ts CHANGED
@@ -2,10 +2,10 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { IFluidSerializer } from "@fluidframework/core-interfaces";
6
- import { ISequencedDocumentMessage, ITree } from "@fluidframework/protocol-definitions";
5
+ import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
7
6
  import { IFluidDataStoreRuntime, IChannelStorageService, IChannelFactory } from "@fluidframework/datastore-definitions";
8
- import { SharedObject } from "@fluidframework/shared-object-base";
7
+ import { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
8
+ import { IFluidSerializer, SharedObject } from "@fluidframework/shared-object-base";
9
9
  import { ISharedCounter, ISharedCounterEvents } from "./interfaces";
10
10
  /**
11
11
  * A `SharedCounter` is a shared object which holds a number that can be incremented or decremented.
@@ -64,12 +64,12 @@ export declare class SharedCounter extends SharedObject<ISharedCounterEvents> im
64
64
  increment(incrementAmount: number): void;
65
65
  private incrementCore;
66
66
  /**
67
- * Create a snapshot for the counter
67
+ * Create a summary for the counter
68
68
  *
69
- * @returns the snapshot of the current state of the counter
69
+ * @returns the summary of the current state of the counter
70
70
  * @internal
71
71
  */
72
- protected snapshotCore(serializer: IFluidSerializer): ITree;
72
+ protected summarizeCore(serializer: IFluidSerializer, fullTree: boolean): ISummaryTreeWithStats;
73
73
  /**
74
74
  * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
75
75
  * @intern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ends shared_object_base_1.SharedObject {
91
91
  this.emit("incremented", incrementAmount, this._value);
92
92
  }
93
93
  /**
94
- * Create a snapshot for the counter
94
+ * Create a summary for the counter
95
95
  *
96
- * @returns the snapshot of the current state of the counter
96
+ * @returns the summary of the current state of the counter
97
97
  * @internal
98
98
  */
99
- snapshotCore(serializer) {
99
+ summarizeCore(serializer, fullTree) {
100
100
  // Get a serializable form of data
101
101
  const content = {
102
102
  value: this.value,
103
103
  };
104
- // And then construct the tree for it
105
- const tree = {
106
- entries: [
107
- {
108
- mode: protocol_definitions_1.FileMode.File,
109
- path: snapshotFileName,
110
- type: protocol_definitions_1.TreeEntry.Blob,
111
- value: {
112
- contents: JSON.stringify(content),
113
- encoding: "utf-8",
114
- },
115
- },
116
- ],
117
- };
118
- return tree;
104
+ // And then construct the summary for it
105
+ return shared_object_base_1.createSingleBlobSummary(snapshotFileName, JSON.stringify(content));
119
106
  }
120
107
  /**
121
108
  * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
@@ -1 +1 @@
1
- {"version":3,"file":"counter.js","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+EAM8C;AAM9C,+DAA4D;AAC5D,2EAAkE;AAClE,qDAAkD;AAmBlD,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAa,aAAc,SAAQ,iCAAkC;IAArE;;QAqBY,WAAM,GAAW,CAAC,CAAC;IAqH/B,CAAC;IAzIG;;;;;;OAMG;IACI,MAAM,CAAC,MAAM,CAAC,OAA+B,EAAE,EAAW;QAC7D,OAAO,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,+BAAc,CAAC,IAAI,CAAkB,CAAC;IAC3E,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,UAAU;QACpB,OAAO,IAAI,+BAAc,EAAE,CAAC;IAChC,CAAC;IAID;;OAEG;IACH,IAAW,KAAK;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ED;;;OAGG;IACO,YAAY;IACtB,CAAC;IAED;;;OAGG;IACO,YAAY,KAAK,CAAC;IAE5B;;;;;;;;OAQG;IACO,WAAW,CAAC,OAAkC,EAAE,KAAc,EAAE,eAAwB;QAC9F,IAAI,OAAO,CAAC,IAAI,KAAK,kCAAW,CAAC,SAAS,IAAI,CAAC,KAAK,EAAE;YAClD,MAAM,EAAE,GAAG,OAAO,CAAC,QAA+B,CAAC;YAEnD,QAAQ,EAAE,CAAC,IAAI,EAAE;gBACb,KAAK,WAAW;oBACZ,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC;oBACvC,MAAM;gBAEV;oBACI,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;aAC5C;SACJ;IACL,CAAC;IAED;;;OAGG;IACO,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ;AA1ID,sCA0IC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidSerializer } from \"@fluidframework/core-interfaces\";\nimport {\n FileMode,\n ISequencedDocumentMessage,\n ITree,\n MessageType,\n TreeEntry,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport { SharedObject } from \"@fluidframework/shared-object-base\";\nimport { CounterFactory } from \"./counterFactory\";\nimport { ISharedCounter, ISharedCounterEvents } from \"./interfaces\";\n\n/**\n * Describes the op format for incrementing the counter\n */\ninterface IIncrementOperation {\n type: \"increment\";\n incrementAmount: number;\n}\n\n/**\n * Used in snapshotting.\n */\ninterface ICounterSnapshotFormat {\n // The value of the counter\n value: number;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * A `SharedCounter` is a shared object which holds a number that can be incremented or decremented.\n * @public\n *\n * @remarks\n * ### Creation\n *\n * To create a `SharedCounter`, get the factory and call create with a runtime and string ID:\n *\n * ```typescript\n * const factory = SharedCounter.getFactory();\n * const counter = factory.create(this.runtime, id) as SharedCounter;\n * ```\n *\n * ### Usage\n *\n * Once created, you can call `increment` to modify the value with either a positive or negative number:\n *\n * ```typescript\n * counter.increment(10); // add 10 to the counter value\n * counter.increment(-5); // subtract 5 from the counter value\n * ```\n *\n * To observe changes to the value (including those from remote clients), register for the `\"incremented\"` event:\n *\n * ```typescript\n * counter.on(\"incremented\", (incrementAmount, newValue) => {\n * console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);\n * });\n * ```\n */\nexport class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {\n /**\n * Create a new shared counter\n *\n * @param runtime - data store runtime the new shared counter belongs to\n * @param id - optional name of the shared counter\n * @returns newly create shared counter (but not attached yet)\n */\n public static create(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, CounterFactory.Type) as SharedCounter;\n }\n\n /**\n * Get a factory for SharedCounter to register with the data store.\n *\n * @returns a factory that creates and load SharedCounter\n */\n public static getFactory(): IChannelFactory {\n return new CounterFactory();\n }\n\n private _value: number = 0;\n\n /**\n * {@inheritDoc ISharedCounter.value}\n */\n public get value() {\n return this._value;\n }\n\n /**\n * {@inheritDoc ISharedCounter.increment}\n */\n public increment(incrementAmount: number) {\n // Incrementing by floating point numbers will be eventually inconsistent, since the order in which the\n // increments are applied affects the result. A more-robust solution would be required to support this.\n if (incrementAmount % 1 !== 0) {\n throw new Error(\"Must increment by a whole number\");\n }\n\n const op: IIncrementOperation = {\n type: \"increment\",\n incrementAmount,\n };\n\n this.incrementCore(incrementAmount);\n this.submitLocalMessage(op);\n }\n\n private incrementCore(incrementAmount: number) {\n this._value += incrementAmount;\n this.emit(\"incremented\", incrementAmount, this._value);\n }\n\n /**\n * Create a snapshot for the counter\n *\n * @returns the snapshot of the current state of the counter\n * @internal\n */\n protected snapshotCore(serializer: IFluidSerializer): ITree {\n // Get a serializable form of data\n const content: ICounterSnapshotFormat = {\n value: this.value,\n };\n\n // And then construct the tree for it\n const tree: ITree = {\n entries: [\n {\n mode: FileMode.File,\n path: snapshotFileName,\n type: TreeEntry.Blob,\n value: {\n contents: JSON.stringify(content),\n encoding: \"utf-8\",\n },\n },\n ],\n };\n\n return tree;\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n * @internal\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n const content = await readAndParse<ICounterSnapshotFormat>(storage, snapshotFileName);\n\n this._value = content.value;\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.registerCore}\n * @internal\n */\n protected registerCore() {\n }\n\n /**\n * Called when the object has disconnected from the delta stream.\n * @internal\n */\n protected onDisconnect() { }\n\n /**\n * Process a counter 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 * @internal\n */\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation && !local) {\n const op = message.contents as IIncrementOperation;\n\n switch (op.type) {\n case \"increment\":\n this.incrementCore(op.incrementAmount);\n break;\n\n default:\n throw new Error(\"Unknown operation\");\n }\n }\n }\n\n /**\n * Not implemented.\n * @internal\n */\n protected applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
1
+ {"version":3,"file":"counter.js","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+EAA+F;AAM/F,+DAA4D;AAE5D,2EAA6G;AAC7G,qDAAkD;AAmBlD,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAa,aAAc,SAAQ,iCAAkC;IAArE;;QAqBY,WAAM,GAAW,CAAC,CAAC;IA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CAAC,CAAC;QAEtF,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAChC,CAAC;IAED;;;OAGG;IACO,YAAY;IACtB,CAAC;IAED;;;OAGG;IACO,YAAY,KAAK,CAAC;IAE5B;;;;;;;;OAQG;IACO,WAAW,CAAC,OAAkC,EAAE,KAAc,EAAE,eAAwB;QAC9F,IAAI,OAAO,CAAC,IAAI,KAAK,kCAAW,CAAC,SAAS,IAAI,CAAC,KAAK,EAAE;YAClD,MAAM,EAAE,GAAG,OAAO,CAAC,QAA+B,CAAC;YAEnD,QAAQ,EAAE,CAAC,IAAI,EAAE;gBACb,KAAK,WAAW;oBACZ,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC;oBACvC,MAAM;gBAEV;oBACI,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;aAC5C;SACJ;IACL,CAAC;IAED;;;OAGG;IACO,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ;AA5HD,sCA4HC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { createSingleBlobSummary, IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { CounterFactory } from \"./counterFactory\";\nimport { ISharedCounter, ISharedCounterEvents } from \"./interfaces\";\n\n/**\n * Describes the op format for incrementing the counter\n */\ninterface IIncrementOperation {\n type: \"increment\";\n incrementAmount: number;\n}\n\n/**\n * Used in snapshotting.\n */\ninterface ICounterSnapshotFormat {\n // The value of the counter\n value: number;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * A `SharedCounter` is a shared object which holds a number that can be incremented or decremented.\n * @public\n *\n * @remarks\n * ### Creation\n *\n * To create a `SharedCounter`, get the factory and call create with a runtime and string ID:\n *\n * ```typescript\n * const factory = SharedCounter.getFactory();\n * const counter = factory.create(this.runtime, id) as SharedCounter;\n * ```\n *\n * ### Usage\n *\n * Once created, you can call `increment` to modify the value with either a positive or negative number:\n *\n * ```typescript\n * counter.increment(10); // add 10 to the counter value\n * counter.increment(-5); // subtract 5 from the counter value\n * ```\n *\n * To observe changes to the value (including those from remote clients), register for the `\"incremented\"` event:\n *\n * ```typescript\n * counter.on(\"incremented\", (incrementAmount, newValue) => {\n * console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);\n * });\n * ```\n */\nexport class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {\n /**\n * Create a new shared counter\n *\n * @param runtime - data store runtime the new shared counter belongs to\n * @param id - optional name of the shared counter\n * @returns newly create shared counter (but not attached yet)\n */\n public static create(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, CounterFactory.Type) as SharedCounter;\n }\n\n /**\n * Get a factory for SharedCounter to register with the data store.\n *\n * @returns a factory that creates and load SharedCounter\n */\n public static getFactory(): IChannelFactory {\n return new CounterFactory();\n }\n\n private _value: number = 0;\n\n /**\n * {@inheritDoc ISharedCounter.value}\n */\n public get value() {\n return this._value;\n }\n\n /**\n * {@inheritDoc ISharedCounter.increment}\n */\n public increment(incrementAmount: number) {\n // Incrementing by floating point numbers will be eventually inconsistent, since the order in which the\n // increments are applied affects the result. A more-robust solution would be required to support this.\n if (incrementAmount % 1 !== 0) {\n throw new Error(\"Must increment by a whole number\");\n }\n\n const op: IIncrementOperation = {\n type: \"increment\",\n incrementAmount,\n };\n\n this.incrementCore(incrementAmount);\n this.submitLocalMessage(op);\n }\n\n private incrementCore(incrementAmount: number) {\n this._value += incrementAmount;\n this.emit(\"incremented\", incrementAmount, this._value);\n }\n\n /**\n * Create a summary for the counter\n *\n * @returns the summary of the current state of the counter\n * @internal\n */\n protected summarizeCore(serializer: IFluidSerializer, fullTree: boolean): ISummaryTreeWithStats {\n // Get a serializable form of data\n const content: ICounterSnapshotFormat = {\n value: this.value,\n };\n\n // And then construct the summary for it\n return createSingleBlobSummary(snapshotFileName, JSON.stringify(content));\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n * @internal\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n const content = await readAndParse<ICounterSnapshotFormat>(storage, snapshotFileName);\n\n this._value = content.value;\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.registerCore}\n * @internal\n */\n protected registerCore() {\n }\n\n /**\n * Called when the object has disconnected from the delta stream.\n * @internal\n */\n protected onDisconnect() { }\n\n /**\n * Process a counter 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 * @internal\n */\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation && !local) {\n const op = message.contents as IIncrementOperation;\n\n switch (op.type) {\n case \"increment\":\n this.incrementCore(op.incrementAmount);\n break;\n\n default:\n throw new Error(\"Unknown operation\");\n }\n }\n }\n\n /**\n * Not implemented.\n * @internal\n */\n protected applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/counter";
8
- export declare const pkgVersion = "0.54.2";
8
+ export declare const pkgVersion = "0.55.0-48551";
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,WAAW,CAAC"}
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,iBAAiB,CAAC"}
@@ -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 = "0.54.2";
11
+ exports.pkgVersion = "0.55.0-48551";
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,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 = \"0.54.2\";\n"]}
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,cAAc,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 = \"0.55.0-48551\";\n"]}
package/lib/counter.d.ts CHANGED
@@ -2,10 +2,10 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { IFluidSerializer } from "@fluidframework/core-interfaces";
6
- import { ISequencedDocumentMessage, ITree } from "@fluidframework/protocol-definitions";
5
+ import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
7
6
  import { IFluidDataStoreRuntime, IChannelStorageService, IChannelFactory } from "@fluidframework/datastore-definitions";
8
- import { SharedObject } from "@fluidframework/shared-object-base";
7
+ import { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
8
+ import { IFluidSerializer, SharedObject } from "@fluidframework/shared-object-base";
9
9
  import { ISharedCounter, ISharedCounterEvents } from "./interfaces";
10
10
  /**
11
11
  * A `SharedCounter` is a shared object which holds a number that can be incremented or decremented.
@@ -64,12 +64,12 @@ export declare class SharedCounter extends SharedObject<ISharedCounterEvents> im
64
64
  increment(incrementAmount: number): void;
65
65
  private incrementCore;
66
66
  /**
67
- * Create a snapshot for the counter
67
+ * Create a summary for the counter
68
68
  *
69
- * @returns the snapshot of the current state of the counter
69
+ * @returns the summary of the current state of the counter
70
70
  * @internal
71
71
  */
72
- protected snapshotCore(serializer: IFluidSerializer): ITree;
72
+ protected summarizeCore(serializer: IFluidSerializer, fullTree: boolean): ISummaryTreeWithStats;
73
73
  /**
74
74
  * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
75
75
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"counter.d.ts","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAEH,yBAAyB,EACzB,KAAK,EAGR,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACH,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EAClB,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAElE,OAAO,EAA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CAAC;AAoBpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,aAAc,SAAQ,YAAY,CAAC,oBAAoB,CAAE,YAAW,cAAc;IAC3F;;;;;;OAMG;WACW,MAAM,CAAC,OAAO,EAAE,sBAAsB,EAAE,EAAE,CAAC,EAAE,MAAM;IAIjE;;;;OAIG;WACW,UAAU,IAAI,eAAe;IAI3C,OAAO,CAAC,MAAM,CAAa;IAE3B;;OAEG;IACH,IAAW,KAAK,WAEf;IAED;;OAEG;IACI,SAAS,CAAC,eAAe,EAAE,MAAM;IAgBxC,OAAO,CAAC,aAAa;IAKrB;;;;;OAKG;IACH,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,gBAAgB,EAAE,QAAQ,EAAE,OAAO,GAAG,qBAAqB;IAU/F;;;OAGG;cACa,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAMxE;;;OAGG;IACH,SAAS,CAAC,YAAY;IAGtB;;;OAGG;IACH,SAAS,CAAC,YAAY;IAEtB;;;;;;;;OAQG;IACH,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,yBAAyB,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO;IAelG;;;OAGG;IACH,SAAS,CAAC,cAAc;CAG3B"}
package/lib/counter.js CHANGED
@@ -2,9 +2,9 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { FileMode, MessageType, TreeEntry, } from "@fluidframework/protocol-definitions";
5
+ import { MessageType } from "@fluidframework/protocol-definitions";
6
6
  import { readAndParse } from "@fluidframework/driver-utils";
7
- import { SharedObject } from "@fluidframework/shared-object-base";
7
+ import { createSingleBlobSummary, SharedObject } from "@fluidframework/shared-object-base";
8
8
  import { CounterFactory } from "./counterFactory";
9
9
  const snapshotFileName = "header";
10
10
  /**
@@ -88,31 +88,18 @@ export class SharedCounter extends SharedObject {
88
88
  this.emit("incremented", incrementAmount, this._value);
89
89
  }
90
90
  /**
91
- * Create a snapshot for the counter
91
+ * Create a summary for the counter
92
92
  *
93
- * @returns the snapshot of the current state of the counter
93
+ * @returns the summary of the current state of the counter
94
94
  * @internal
95
95
  */
96
- snapshotCore(serializer) {
96
+ summarizeCore(serializer, fullTree) {
97
97
  // Get a serializable form of data
98
98
  const content = {
99
99
  value: this.value,
100
100
  };
101
- // And then construct the tree for it
102
- const tree = {
103
- entries: [
104
- {
105
- mode: FileMode.File,
106
- path: snapshotFileName,
107
- type: TreeEntry.Blob,
108
- value: {
109
- contents: JSON.stringify(content),
110
- encoding: "utf-8",
111
- },
112
- },
113
- ],
114
- };
115
- return tree;
101
+ // And then construct the summary for it
102
+ return createSingleBlobSummary(snapshotFileName, JSON.stringify(content));
116
103
  }
117
104
  /**
118
105
  * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
@@ -1 +1 @@
1
- {"version":3,"file":"counter.js","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACH,QAAQ,EAGR,WAAW,EACX,SAAS,GACZ,MAAM,sCAAsC,CAAC;AAM9C,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAmBlD,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,OAAO,aAAc,SAAQ,YAAkC;IAArE;;QAqBY,WAAM,GAAW,CAAC,CAAC;IAqH/B,CAAC;IAzIG;;;;;;OAMG;IACI,MAAM,CAAC,MAAM,CAAC,OAA+B,EAAE,EAAW;QAC7D,OAAO,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,cAAc,CAAC,IAAI,CAAkB,CAAC;IAC3E,CAAC;I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CAAyB,OAAO,EAAE,gBAAgB,CAAC,CAAC;QAEtF,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAChC,CAAC;IAED;;;OAGG;IACO,YAAY;IACtB,CAAC;IAED;;;OAGG;IACO,YAAY,KAAK,CAAC;IAE5B;;;;;;;;OAQG;IACO,WAAW,CAAC,OAAkC,EAAE,KAAc,EAAE,eAAwB;QAC9F,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,SAAS,IAAI,CAAC,KAAK,EAAE;YAClD,MAAM,EAAE,GAAG,OAAO,CAAC,QAA+B,CAAC;YAEnD,QAAQ,EAAE,CAAC,IAAI,EAAE;gBACb,KAAK,WAAW;oBACZ,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC;oBACvC,MAAM;gBAEV;oBACI,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;aAC5C;SACJ;IACL,CAAC;IAED;;;OAGG;IACO,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 { IFluidSerializer } from \"@fluidframework/core-interfaces\";\nimport {\n FileMode,\n ISequencedDocumentMessage,\n ITree,\n MessageType,\n TreeEntry,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport { SharedObject } from \"@fluidframework/shared-object-base\";\nimport { CounterFactory } from \"./counterFactory\";\nimport { ISharedCounter, ISharedCounterEvents } from \"./interfaces\";\n\n/**\n * Describes the op format for incrementing the counter\n */\ninterface IIncrementOperation {\n type: \"increment\";\n incrementAmount: number;\n}\n\n/**\n * Used in snapshotting.\n */\ninterface ICounterSnapshotFormat {\n // The value of the counter\n value: number;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * A `SharedCounter` is a shared object which holds a number that can be incremented or decremented.\n * @public\n *\n * @remarks\n * ### Creation\n *\n * To create a `SharedCounter`, get the factory and call create with a runtime and string ID:\n *\n * ```typescript\n * const factory = SharedCounter.getFactory();\n * const counter = factory.create(this.runtime, id) as SharedCounter;\n * ```\n *\n * ### Usage\n *\n * Once created, you can call `increment` to modify the value with either a positive or negative number:\n *\n * ```typescript\n * counter.increment(10); // add 10 to the counter value\n * counter.increment(-5); // subtract 5 from the counter value\n * ```\n *\n * To observe changes to the value (including those from remote clients), register for the `\"incremented\"` event:\n *\n * ```typescript\n * counter.on(\"incremented\", (incrementAmount, newValue) => {\n * console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);\n * });\n * ```\n */\nexport class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {\n /**\n * Create a new shared counter\n *\n * @param runtime - data store runtime the new shared counter belongs to\n * @param id - optional name of the shared counter\n * @returns newly create shared counter (but not attached yet)\n */\n public static create(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, CounterFactory.Type) as SharedCounter;\n }\n\n /**\n * Get a factory for SharedCounter to register with the data store.\n *\n * @returns a factory that creates and load SharedCounter\n */\n public static getFactory(): IChannelFactory {\n return new CounterFactory();\n }\n\n private _value: number = 0;\n\n /**\n * {@inheritDoc ISharedCounter.value}\n */\n public get value() {\n return this._value;\n }\n\n /**\n * {@inheritDoc ISharedCounter.increment}\n */\n public increment(incrementAmount: number) {\n // Incrementing by floating point numbers will be eventually inconsistent, since the order in which the\n // increments are applied affects the result. A more-robust solution would be required to support this.\n if (incrementAmount % 1 !== 0) {\n throw new Error(\"Must increment by a whole number\");\n }\n\n const op: IIncrementOperation = {\n type: \"increment\",\n incrementAmount,\n };\n\n this.incrementCore(incrementAmount);\n this.submitLocalMessage(op);\n }\n\n private incrementCore(incrementAmount: number) {\n this._value += incrementAmount;\n this.emit(\"incremented\", incrementAmount, this._value);\n }\n\n /**\n * Create a snapshot for the counter\n *\n * @returns the snapshot of the current state of the counter\n * @internal\n */\n protected snapshotCore(serializer: IFluidSerializer): ITree {\n // Get a serializable form of data\n const content: ICounterSnapshotFormat = {\n value: this.value,\n };\n\n // And then construct the tree for it\n const tree: ITree = {\n entries: [\n {\n mode: FileMode.File,\n path: snapshotFileName,\n type: TreeEntry.Blob,\n value: {\n contents: JSON.stringify(content),\n encoding: \"utf-8\",\n },\n },\n ],\n };\n\n return tree;\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n * @internal\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n const content = await readAndParse<ICounterSnapshotFormat>(storage, snapshotFileName);\n\n this._value = content.value;\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.registerCore}\n * @internal\n */\n protected registerCore() {\n }\n\n /**\n * Called when the object has disconnected from the delta stream.\n * @internal\n */\n protected onDisconnect() { }\n\n /**\n * Process a counter 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 * @internal\n */\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation && !local) {\n const op = message.contents as IIncrementOperation;\n\n switch (op.type) {\n case \"increment\":\n this.incrementCore(op.incrementAmount);\n break;\n\n default:\n throw new Error(\"Unknown operation\");\n }\n }\n }\n\n /**\n * Not implemented.\n * @internal\n */\n protected applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
1
+ {"version":3,"file":"counter.js","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAA8B,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAM/F,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE5D,OAAO,EAAE,uBAAuB,EAA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AC,KAAK;SACpB,CAAC;QAEF,wCAAwC;QACxC,OAAO,uBAAuB,CAAC,gBAAgB,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,QAAQ,CAAC,OAA+B;QACpD,MAAM,OAAO,GAAG,MAAM,YAAY,CAAyB,OAAO,EAAE,gBAAgB,CAAC,CAAC;QAEtF,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAChC,CAAC;IAED;;;OAGG;IACO,YAAY;IACtB,CAAC;IAED;;;OAGG;IACO,YAAY,KAAK,CAAC;IAE5B;;;;;;;;OAQG;IACO,WAAW,CAAC,OAAkC,EAAE,KAAc,EAAE,eAAwB;QAC9F,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,SAAS,IAAI,CAAC,KAAK,EAAE;YAClD,MAAM,EAAE,GAAG,OAAO,CAAC,QAA+B,CAAC;YAEnD,QAAQ,EAAE,CAAC,IAAI,EAAE;gBACb,KAAK,WAAW;oBACZ,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC;oBACvC,MAAM;gBAEV;oBACI,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;aAC5C;SACJ;IACL,CAAC;IAED;;;OAGG;IACO,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 { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { createSingleBlobSummary, IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { CounterFactory } from \"./counterFactory\";\nimport { ISharedCounter, ISharedCounterEvents } from \"./interfaces\";\n\n/**\n * Describes the op format for incrementing the counter\n */\ninterface IIncrementOperation {\n type: \"increment\";\n incrementAmount: number;\n}\n\n/**\n * Used in snapshotting.\n */\ninterface ICounterSnapshotFormat {\n // The value of the counter\n value: number;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * A `SharedCounter` is a shared object which holds a number that can be incremented or decremented.\n * @public\n *\n * @remarks\n * ### Creation\n *\n * To create a `SharedCounter`, get the factory and call create with a runtime and string ID:\n *\n * ```typescript\n * const factory = SharedCounter.getFactory();\n * const counter = factory.create(this.runtime, id) as SharedCounter;\n * ```\n *\n * ### Usage\n *\n * Once created, you can call `increment` to modify the value with either a positive or negative number:\n *\n * ```typescript\n * counter.increment(10); // add 10 to the counter value\n * counter.increment(-5); // subtract 5 from the counter value\n * ```\n *\n * To observe changes to the value (including those from remote clients), register for the `\"incremented\"` event:\n *\n * ```typescript\n * counter.on(\"incremented\", (incrementAmount, newValue) => {\n * console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);\n * });\n * ```\n */\nexport class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {\n /**\n * Create a new shared counter\n *\n * @param runtime - data store runtime the new shared counter belongs to\n * @param id - optional name of the shared counter\n * @returns newly create shared counter (but not attached yet)\n */\n public static create(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, CounterFactory.Type) as SharedCounter;\n }\n\n /**\n * Get a factory for SharedCounter to register with the data store.\n *\n * @returns a factory that creates and load SharedCounter\n */\n public static getFactory(): IChannelFactory {\n return new CounterFactory();\n }\n\n private _value: number = 0;\n\n /**\n * {@inheritDoc ISharedCounter.value}\n */\n public get value() {\n return this._value;\n }\n\n /**\n * {@inheritDoc ISharedCounter.increment}\n */\n public increment(incrementAmount: number) {\n // Incrementing by floating point numbers will be eventually inconsistent, since the order in which the\n // increments are applied affects the result. A more-robust solution would be required to support this.\n if (incrementAmount % 1 !== 0) {\n throw new Error(\"Must increment by a whole number\");\n }\n\n const op: IIncrementOperation = {\n type: \"increment\",\n incrementAmount,\n };\n\n this.incrementCore(incrementAmount);\n this.submitLocalMessage(op);\n }\n\n private incrementCore(incrementAmount: number) {\n this._value += incrementAmount;\n this.emit(\"incremented\", incrementAmount, this._value);\n }\n\n /**\n * Create a summary for the counter\n *\n * @returns the summary of the current state of the counter\n * @internal\n */\n protected summarizeCore(serializer: IFluidSerializer, fullTree: boolean): ISummaryTreeWithStats {\n // Get a serializable form of data\n const content: ICounterSnapshotFormat = {\n value: this.value,\n };\n\n // And then construct the summary for it\n return createSingleBlobSummary(snapshotFileName, JSON.stringify(content));\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n * @internal\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n const content = await readAndParse<ICounterSnapshotFormat>(storage, snapshotFileName);\n\n this._value = content.value;\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.registerCore}\n * @internal\n */\n protected registerCore() {\n }\n\n /**\n * Called when the object has disconnected from the delta stream.\n * @internal\n */\n protected onDisconnect() { }\n\n /**\n * Process a counter 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 * @internal\n */\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation && !local) {\n const op = message.contents as IIncrementOperation;\n\n switch (op.type) {\n case \"increment\":\n this.incrementCore(op.incrementAmount);\n break;\n\n default:\n throw new Error(\"Unknown operation\");\n }\n }\n }\n\n /**\n * Not implemented.\n * @internal\n */\n protected applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/counter";
8
- export declare const pkgVersion = "0.54.2";
8
+ export declare const pkgVersion = "0.55.0-48551";
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,WAAW,CAAC"}
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,iBAAiB,CAAC"}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export const pkgName = "@fluidframework/counter";
8
- export const pkgVersion = "0.54.2";
8
+ export const pkgVersion = "0.55.0-48551";
9
9
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,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 = \"0.54.2\";\n"]}
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,cAAc,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 = \"0.55.0-48551\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/counter",
3
- "version": "0.54.2",
3
+ "version": "0.55.0-48551",
4
4
  "description": "Counter DDS",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": "https://github.com/microsoft/FluidFramework",
@@ -23,7 +23,7 @@
23
23
  "ci:build:docs": "api-extractor run --typescript-compiler-folder ../../../node_modules/typescript && copyfiles -u 1 ./_api-extractor-temp/* ../../../_api-extractor-temp/",
24
24
  "clean": "rimraf dist lib *.tsbuildinfo *.build.log",
25
25
  "eslint": "eslint --format stylish src",
26
- "eslint:fix": "eslint --format stylish src --fix",
26
+ "eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
27
27
  "lint": "npm run eslint",
28
28
  "lint:fix": "npm run eslint:fix",
29
29
  "test": "npm run test:mocha",
@@ -55,31 +55,33 @@
55
55
  "dependencies": {
56
56
  "@fluidframework/common-utils": "^0.32.1",
57
57
  "@fluidframework/core-interfaces": "^0.41.0",
58
- "@fluidframework/datastore-definitions": "^0.54.2",
59
- "@fluidframework/driver-utils": "^0.54.2",
58
+ "@fluidframework/datastore-definitions": "0.55.0-48551",
59
+ "@fluidframework/driver-utils": "0.55.0-48551",
60
60
  "@fluidframework/protocol-definitions": "^0.1026.0",
61
- "@fluidframework/shared-object-base": "^0.54.2"
61
+ "@fluidframework/runtime-definitions": "0.55.0-48551",
62
+ "@fluidframework/shared-object-base": "0.55.0-48551"
62
63
  },
63
64
  "devDependencies": {
64
65
  "@fluidframework/build-common": "^0.23.0",
65
- "@fluidframework/eslint-config-fluid": "^0.24.0",
66
- "@fluidframework/mocha-test-setup": "^0.54.2",
67
- "@fluidframework/test-runtime-utils": "^0.54.2",
66
+ "@fluidframework/eslint-config-fluid": "^0.25.0-0",
67
+ "@fluidframework/mocha-test-setup": "0.55.0-48551",
68
+ "@fluidframework/test-runtime-utils": "0.55.0-48551",
68
69
  "@microsoft/api-extractor": "^7.16.1",
70
+ "@rushstack/eslint-config": "^2.5.1",
69
71
  "@types/mocha": "^8.2.2",
70
72
  "@types/node": "^14.18.0",
71
- "@typescript-eslint/eslint-plugin": "~4.14.0",
72
- "@typescript-eslint/parser": "~4.14.0",
73
+ "@typescript-eslint/eslint-plugin": "~5.9.0",
74
+ "@typescript-eslint/parser": "~5.9.0",
73
75
  "concurrently": "^6.2.0",
74
76
  "copyfiles": "^2.1.0",
75
77
  "cross-env": "^7.0.2",
76
- "eslint": "~7.18.0",
78
+ "eslint": "~8.6.0",
79
+ "eslint-plugin-editorconfig": "~3.2.0",
77
80
  "eslint-plugin-eslint-comments": "~3.2.0",
78
- "eslint-plugin-import": "~2.22.1",
81
+ "eslint-plugin-import": "~2.25.4",
79
82
  "eslint-plugin-no-null": "~1.0.2",
80
- "eslint-plugin-prefer-arrow": "~1.2.2",
81
- "eslint-plugin-react": "~7.22.0",
82
- "eslint-plugin-unicorn": "~26.0.1",
83
+ "eslint-plugin-react": "~7.28.0",
84
+ "eslint-plugin-unicorn": "~40.0.0",
83
85
  "mocha": "^8.4.0",
84
86
  "nyc": "^15.0.0",
85
87
  "rimraf": "^2.6.2",
package/src/counter.ts CHANGED
@@ -3,21 +3,15 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { IFluidSerializer } from "@fluidframework/core-interfaces";
7
- import {
8
- FileMode,
9
- ISequencedDocumentMessage,
10
- ITree,
11
- MessageType,
12
- TreeEntry,
13
- } from "@fluidframework/protocol-definitions";
6
+ import { ISequencedDocumentMessage, MessageType } from "@fluidframework/protocol-definitions";
14
7
  import {
15
8
  IFluidDataStoreRuntime,
16
9
  IChannelStorageService,
17
10
  IChannelFactory,
18
11
  } from "@fluidframework/datastore-definitions";
19
12
  import { readAndParse } from "@fluidframework/driver-utils";
20
- import { SharedObject } from "@fluidframework/shared-object-base";
13
+ import { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
14
+ import { createSingleBlobSummary, IFluidSerializer, SharedObject } from "@fluidframework/shared-object-base";
21
15
  import { CounterFactory } from "./counterFactory";
22
16
  import { ISharedCounter, ISharedCounterEvents } from "./interfaces";
23
17
 
@@ -125,33 +119,19 @@ export class SharedCounter extends SharedObject<ISharedCounterEvents> implements
125
119
  }
126
120
 
127
121
  /**
128
- * Create a snapshot for the counter
122
+ * Create a summary for the counter
129
123
  *
130
- * @returns the snapshot of the current state of the counter
124
+ * @returns the summary of the current state of the counter
131
125
  * @internal
132
126
  */
133
- protected snapshotCore(serializer: IFluidSerializer): ITree {
127
+ protected summarizeCore(serializer: IFluidSerializer, fullTree: boolean): ISummaryTreeWithStats {
134
128
  // Get a serializable form of data
135
129
  const content: ICounterSnapshotFormat = {
136
130
  value: this.value,
137
131
  };
138
132
 
139
- // And then construct the tree for it
140
- const tree: ITree = {
141
- entries: [
142
- {
143
- mode: FileMode.File,
144
- path: snapshotFileName,
145
- type: TreeEntry.Blob,
146
- value: {
147
- contents: JSON.stringify(content),
148
- encoding: "utf-8",
149
- },
150
- },
151
- ],
152
- };
153
-
154
- return tree;
133
+ // And then construct the summary for it
134
+ return createSingleBlobSummary(snapshotFileName, JSON.stringify(content));
155
135
  }
156
136
 
157
137
  /**
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/counter";
9
- export const pkgVersion = "0.54.2";
9
+ export const pkgVersion = "0.55.0-48551";