@fluidframework/register-collection 1.4.0-115997 → 2.0.0-dev-rc.1.0.0.224419

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/.eslintrc.js +5 -7
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +117 -0
  4. package/README.md +29 -8
  5. package/api-extractor-lint.json +4 -0
  6. package/api-extractor.json +2 -2
  7. package/api-report/register-collection.api.md +90 -0
  8. package/dist/{consensusRegisterCollection.js → consensusRegisterCollection.cjs} +31 -29
  9. package/dist/consensusRegisterCollection.cjs.map +1 -0
  10. package/dist/consensusRegisterCollection.d.ts +2 -1
  11. package/dist/consensusRegisterCollection.d.ts.map +1 -1
  12. package/dist/{consensusRegisterCollectionFactory.js → consensusRegisterCollectionFactory.cjs} +5 -4
  13. package/dist/consensusRegisterCollectionFactory.cjs.map +1 -0
  14. package/dist/consensusRegisterCollectionFactory.d.ts +2 -1
  15. package/dist/consensusRegisterCollectionFactory.d.ts.map +1 -1
  16. package/dist/index.cjs +14 -0
  17. package/dist/index.cjs.map +1 -0
  18. package/dist/index.d.ts +3 -3
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/{interfaces.js → interfaces.cjs} +3 -2
  21. package/dist/interfaces.cjs.map +1 -0
  22. package/dist/interfaces.d.ts +9 -5
  23. package/dist/interfaces.d.ts.map +1 -1
  24. package/dist/{packageVersion.js → packageVersion.cjs} +2 -2
  25. package/dist/packageVersion.cjs.map +1 -0
  26. package/dist/packageVersion.d.ts +1 -1
  27. package/dist/packageVersion.d.ts.map +1 -1
  28. package/dist/register-collection-alpha.d.ts +163 -0
  29. package/dist/register-collection-beta.d.ts +25 -0
  30. package/dist/register-collection-public.d.ts +25 -0
  31. package/dist/register-collection-untrimmed.d.ts +163 -0
  32. package/dist/tsdoc-metadata.json +11 -0
  33. package/lib/{consensusRegisterCollection.d.ts → consensusRegisterCollection.d.mts} +4 -3
  34. package/lib/consensusRegisterCollection.d.mts.map +1 -0
  35. package/lib/{consensusRegisterCollection.js → consensusRegisterCollection.mjs} +27 -25
  36. package/lib/consensusRegisterCollection.mjs.map +1 -0
  37. package/lib/{consensusRegisterCollectionFactory.d.ts → consensusRegisterCollectionFactory.d.mts} +3 -2
  38. package/lib/consensusRegisterCollectionFactory.d.mts.map +1 -0
  39. package/lib/{consensusRegisterCollectionFactory.js → consensusRegisterCollectionFactory.mjs} +5 -4
  40. package/lib/consensusRegisterCollectionFactory.mjs.map +1 -0
  41. package/lib/index.d.mts +8 -0
  42. package/lib/index.d.mts.map +1 -0
  43. package/lib/index.mjs +8 -0
  44. package/lib/index.mjs.map +1 -0
  45. package/lib/{interfaces.d.ts → interfaces.d.mts} +9 -5
  46. package/lib/interfaces.d.mts.map +1 -0
  47. package/lib/{interfaces.js → interfaces.mjs} +2 -1
  48. package/lib/interfaces.mjs.map +1 -0
  49. package/lib/{packageVersion.d.ts → packageVersion.d.mts} +1 -1
  50. package/lib/{packageVersion.d.ts.map → packageVersion.d.mts.map} +1 -1
  51. package/lib/{packageVersion.js → packageVersion.mjs} +2 -2
  52. package/lib/packageVersion.mjs.map +1 -0
  53. package/lib/register-collection-alpha.d.mts +163 -0
  54. package/lib/register-collection-beta.d.mts +25 -0
  55. package/lib/register-collection-public.d.mts +25 -0
  56. package/lib/register-collection-untrimmed.d.mts +163 -0
  57. package/package.json +97 -62
  58. package/prettier.config.cjs +8 -0
  59. package/src/consensusRegisterCollection.ts +307 -284
  60. package/src/consensusRegisterCollectionFactory.ts +39 -33
  61. package/src/index.ts +8 -3
  62. package/src/interfaces.ts +52 -43
  63. package/src/packageVersion.ts +1 -1
  64. package/tsc-multi.test.json +4 -0
  65. package/tsconfig.json +11 -13
  66. package/dist/consensusRegisterCollection.js.map +0 -1
  67. package/dist/consensusRegisterCollectionFactory.js.map +0 -1
  68. package/dist/index.js +0 -20
  69. package/dist/index.js.map +0 -1
  70. package/dist/interfaces.js.map +0 -1
  71. package/dist/packageVersion.js.map +0 -1
  72. package/lib/consensusRegisterCollection.d.ts.map +0 -1
  73. package/lib/consensusRegisterCollection.js.map +0 -1
  74. package/lib/consensusRegisterCollectionFactory.d.ts.map +0 -1
  75. package/lib/consensusRegisterCollectionFactory.js.map +0 -1
  76. package/lib/index.d.ts +0 -8
  77. package/lib/index.d.ts.map +0 -1
  78. package/lib/index.js +0 -8
  79. package/lib/index.js.map +0 -1
  80. package/lib/interfaces.d.ts.map +0 -1
  81. package/lib/interfaces.js.map +0 -1
  82. package/lib/packageVersion.js.map +0 -1
  83. package/tsconfig.esnext.json +0 -7
@@ -4,50 +4,56 @@
4
4
  */
5
5
 
6
6
  import {
7
- IChannelAttributes,
8
- IFluidDataStoreRuntime,
9
- IChannelServices,
7
+ IChannelAttributes,
8
+ IFluidDataStoreRuntime,
9
+ IChannelServices,
10
10
  } from "@fluidframework/datastore-definitions";
11
11
  import { ConsensusRegisterCollection } from "./consensusRegisterCollection";
12
12
  import { IConsensusRegisterCollection, IConsensusRegisterCollectionFactory } from "./interfaces";
13
13
  import { pkgVersion } from "./packageVersion";
14
14
 
15
15
  /**
16
- * The factory that defines the consensus queue
16
+ * The factory that defines the consensus queue.
17
+ * @alpha
17
18
  */
18
19
  export class ConsensusRegisterCollectionFactory implements IConsensusRegisterCollectionFactory {
19
- public static Type = "https://graph.microsoft.com/types/consensus-register-collection";
20
+ public static Type = "https://graph.microsoft.com/types/consensus-register-collection";
20
21
 
21
- public static readonly Attributes: IChannelAttributes = {
22
- type: ConsensusRegisterCollectionFactory.Type,
23
- snapshotFormatVersion: "0.1",
24
- packageVersion: pkgVersion,
25
- };
22
+ public static readonly Attributes: IChannelAttributes = {
23
+ type: ConsensusRegisterCollectionFactory.Type,
24
+ snapshotFormatVersion: "0.1",
25
+ packageVersion: pkgVersion,
26
+ };
26
27
 
27
- public get type() {
28
- return ConsensusRegisterCollectionFactory.Type;
29
- }
28
+ public get type() {
29
+ return ConsensusRegisterCollectionFactory.Type;
30
+ }
30
31
 
31
- public get attributes() {
32
- return ConsensusRegisterCollectionFactory.Attributes;
33
- }
32
+ public get attributes() {
33
+ return ConsensusRegisterCollectionFactory.Attributes;
34
+ }
34
35
 
35
- /**
36
- * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}
37
- */
38
- public async load(
39
- runtime: IFluidDataStoreRuntime,
40
- id: string,
41
- services: IChannelServices,
42
- attributes: IChannelAttributes): Promise<IConsensusRegisterCollection> {
43
- const collection = new ConsensusRegisterCollection(id, runtime, attributes);
44
- await collection.load(services);
45
- return collection;
46
- }
36
+ /**
37
+ * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}
38
+ */
39
+ public async load(
40
+ runtime: IFluidDataStoreRuntime,
41
+ id: string,
42
+ services: IChannelServices,
43
+ attributes: IChannelAttributes,
44
+ ): Promise<IConsensusRegisterCollection> {
45
+ const collection = new ConsensusRegisterCollection(id, runtime, attributes);
46
+ await collection.load(services);
47
+ return collection;
48
+ }
47
49
 
48
- public create(document: IFluidDataStoreRuntime, id: string): IConsensusRegisterCollection {
49
- const collection = new ConsensusRegisterCollection(id, document, ConsensusRegisterCollectionFactory.Attributes);
50
- collection.initializeLocal();
51
- return collection;
52
- }
50
+ public create(document: IFluidDataStoreRuntime, id: string): IConsensusRegisterCollection {
51
+ const collection = new ConsensusRegisterCollection(
52
+ id,
53
+ document,
54
+ ConsensusRegisterCollectionFactory.Attributes,
55
+ );
56
+ collection.initializeLocal();
57
+ return collection;
58
+ }
53
59
  }
package/src/index.ts CHANGED
@@ -3,6 +3,11 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- export * from "./consensusRegisterCollection";
7
- export * from "./consensusRegisterCollectionFactory";
8
- export * from "./interfaces";
6
+ export { ConsensusRegisterCollection } from "./consensusRegisterCollection";
7
+ export { ConsensusRegisterCollectionFactory } from "./consensusRegisterCollectionFactory";
8
+ export {
9
+ IConsensusRegisterCollection,
10
+ IConsensusRegisterCollectionEvents,
11
+ IConsensusRegisterCollectionFactory,
12
+ ReadPolicy,
13
+ } from "./interfaces";
package/src/interfaces.ts CHANGED
@@ -4,10 +4,10 @@
4
4
  */
5
5
 
6
6
  import {
7
- IFluidDataStoreRuntime,
8
- IChannelServices,
9
- IChannelAttributes,
10
- IChannelFactory,
7
+ IFluidDataStoreRuntime,
8
+ IChannelServices,
9
+ IChannelAttributes,
10
+ IChannelFactory,
11
11
  } from "@fluidframework/datastore-definitions";
12
12
  import { ISharedObject, ISharedObjectEvents } from "@fluidframework/shared-object-base";
13
13
 
@@ -15,29 +15,36 @@ import { ISharedObject, ISharedObjectEvents } from "@fluidframework/shared-objec
15
15
  * Consensus Register Collection channel factory interface
16
16
  *
17
17
  * Extends the base IChannelFactory to return a more definite type of IConsensusRegisterCollection
18
- * Use for the runtime to create and load distributed data structure by type name of each channel
18
+ * Use for the runtime to create and load distributed data structure by type name of each channel.
19
+ * @alpha
19
20
  */
20
21
  export interface IConsensusRegisterCollectionFactory extends IChannelFactory {
21
- /**
22
- * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}
23
- */
24
- load(
25
- document: IFluidDataStoreRuntime,
26
- id: string,
27
- services: IChannelServices,
28
- attributes: IChannelAttributes): Promise<IConsensusRegisterCollection>;
22
+ /**
23
+ * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}
24
+ */
25
+ load(
26
+ document: IFluidDataStoreRuntime,
27
+ id: string,
28
+ services: IChannelServices,
29
+ attributes: IChannelAttributes,
30
+ ): Promise<IConsensusRegisterCollection>;
29
31
 
30
- create(document: IFluidDataStoreRuntime, id: string): IConsensusRegisterCollection;
32
+ create(document: IFluidDataStoreRuntime, id: string): IConsensusRegisterCollection;
31
33
  }
32
34
 
35
+ /**
36
+ * Events emitted by {@link IConsensusRegisterCollection}.
37
+ * @alpha
38
+ */
33
39
  export interface IConsensusRegisterCollectionEvents extends ISharedObjectEvents {
34
- (event: "atomicChanged" | "versionChanged", listener: (key: string, value: any, local: boolean) => void);
40
+ (
41
+ event: "atomicChanged" | "versionChanged",
42
+ listener: (key: string, value: any, local: boolean) => void,
43
+ );
35
44
  }
36
45
 
37
46
  /**
38
- * Consensus Register Collection.
39
- *
40
- * A consensus register collection is a distributed data structure, which holds a set of registers with update
47
+ * A distributed data structure that holds a set of registers with update
41
48
  * versions. On concurrent updates, a register internally stores all possible versions of a value by using reference
42
49
  * sequence number of the incoming update.
43
50
  *
@@ -52,40 +59,42 @@ export interface IConsensusRegisterCollectionEvents extends ISharedObjectEvents
52
59
  * the value. So we can safely return the first value.
53
60
  *
54
61
  * LWW: The last write to a key always wins.
55
- *
62
+ * @alpha
56
63
  */
57
- export interface IConsensusRegisterCollection<T = any> extends ISharedObject<IConsensusRegisterCollectionEvents> {
58
- /**
59
- * Attempts to write a register with a value. Returns a promise to indicate the roundtrip completion.
60
- * For a non existent register, it will attempt to create a new register with the specified value.
61
- *
62
- * @returns Promise<true> if write was non-concurrent
63
- */
64
- write(key: string, value: T): Promise<boolean>;
64
+ export interface IConsensusRegisterCollection<T = any>
65
+ extends ISharedObject<IConsensusRegisterCollectionEvents> {
66
+ /**
67
+ * Attempts to write a register with a value. Returns a promise to indicate the roundtrip completion.
68
+ * For a non existent register, it will attempt to create a new register with the specified value.
69
+ *
70
+ * @returns Promise<true> if write was non-concurrent
71
+ */
72
+ write(key: string, value: T): Promise<boolean>;
65
73
 
66
- /**
67
- * Retrieves the agreed upon value for the register based on policy. Returns undefined if not present.
68
- */
69
- read(key: string, policy?: ReadPolicy): T | undefined;
74
+ /**
75
+ * Retrieves the agreed upon value for the register based on policy. Returns undefined if not present.
76
+ */
77
+ read(key: string, policy?: ReadPolicy): T | undefined;
70
78
 
71
- /**
72
- * Retrives all concurrent versions. Undefined if not present.
73
- */
74
- readVersions(key: string): T[] | undefined;
79
+ /**
80
+ * Retrives all concurrent versions. Undefined if not present.
81
+ */
82
+ readVersions(key: string): T[] | undefined;
75
83
 
76
- /**
77
- * Returns the keys.
78
- */
79
- keys(): string[];
84
+ /**
85
+ * Returns the keys.
86
+ */
87
+ keys(): string[];
80
88
  }
81
89
 
82
90
  /**
83
91
  * Read policies used when reading the map value.
92
+ * @alpha
84
93
  */
85
94
  export enum ReadPolicy {
86
- // On a concurrent update, returns the first agreed upon value amongst all clients.
87
- Atomic,
95
+ // On a concurrent update, returns the first agreed upon value amongst all clients.
96
+ Atomic,
88
97
 
89
- // Last writer wins. Simply returns the last written value.
90
- LWW,
98
+ // Last writer wins. Simply returns the last written value.
99
+ LWW,
91
100
  }
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/register-collection";
9
- export const pkgVersion = "1.4.0-115997";
9
+ export const pkgVersion = "2.0.0-dev-rc.1.0.0.224419";
@@ -0,0 +1,4 @@
1
+ {
2
+ "targets": [{ "extname": ".cjs", "module": "CommonJS", "moduleResolution": "Node10" }],
3
+ "projects": ["./tsconfig.json", "./src/test/tsconfig.json"]
4
+ }
package/tsconfig.json CHANGED
@@ -1,14 +1,12 @@
1
1
  {
2
- "extends": "@fluidframework/build-common/ts-common-config.json",
3
- "exclude": [
4
- "src/test/**/*"
5
- ],
6
- "compilerOptions": {
7
- "rootDir": "./src",
8
- "outDir": "./dist",
9
- "composite": true
10
- },
11
- "include": [
12
- "src/**/*"
13
- ]
14
- }
2
+ "extends": [
3
+ "../../../common/build/build-common/tsconfig.base.json",
4
+ "../../../common/build/build-common/tsconfig.cjs.json",
5
+ ],
6
+ "include": ["src/**/*"],
7
+ "exclude": ["src/test/**/*"],
8
+ "compilerOptions": {
9
+ "rootDir": "./src",
10
+ "outDir": "./dist",
11
+ },
12
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"consensusRegisterCollection.js","sourceRoot":"","sources":["../src/consensusRegisterCollection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAuF;AACvF,+EAA8F;AAO9F,2EAA6G;AAC7G,6FAA0F;AAC1F,6CAA4G;AAqB5G,MAAM,gBAAgB,GAAG,CAAI,cAAsB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DAA8D,CAAC,CAAC;SAC7E;QAED,wBAAwB;QACxB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAElC,sDAAsD;QACtD,IAAI,MAAM,EAAE;YACR,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;SACjD;QACD,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAE/C,OAAO,MAAM,CAAC;IAClB,CAAC;IAEO,SAAS,CAAC,KAAU,EAAE,UAA4B;QACtD,OAAO,UAAU,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC;IAEO,KAAK,CAAC,OAAe,EAAE,UAA4B;QACvD,+DAA+D;QAC/D,OAAO,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAES,cAAc;QACpB,uBAAuB;QACvB,OAAO,GAAG,EAAE,GAAG,CAAC,CAAC;IACrB,CAAC;CACJ;AArPD,kEAqPC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, bufferToString, unreachableCase } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { createSingleBlobSummary, IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { ConsensusRegisterCollectionFactory } from \"./consensusRegisterCollectionFactory\";\nimport { IConsensusRegisterCollection, ReadPolicy, IConsensusRegisterCollectionEvents } from \"./interfaces\";\n\ninterface ILocalData<T> {\n // Atomic version\n atomic: ILocalRegister<T>;\n\n // All concurrent versions awaiting consensus\n versions: ILocalRegister<T>[];\n}\n\ninterface ILocalRegister<T> {\n // Register value, wrapped for backwards compatibility with < 0.17\n value: {\n type: \"Plain\";\n value: T;\n };\n\n // The sequence number when last consensus was reached\n sequenceNumber: number;\n}\n\nconst newLocalRegister = <T>(sequenceNumber: number, value: T): ILocalRegister<T> => ({\n sequenceNumber,\n value: {\n type: \"Plain\",\n value,\n },\n});\n\n/**\n * An operation for consensus register collection\n */\ninterface IRegisterOperation {\n key: string;\n type: \"write\";\n serializedValue: string;\n\n // Message can be delivered with delay - resubmitted on reconnect.\n // As such, refSeq needs to reference seq # at the time op was created,\n // not when op was actually sent over wire (ISequencedDocumentMessage.referenceSequenceNumber),\n // as client can ingest ops in between.\n refSeq: number | undefined;\n}\n\n/**\n * IRegisterOperation format in versions \\< 0.17\n */\ninterface IRegisterOperationOld<T> {\n key: string;\n type: \"write\";\n value: {\n type: \"Plain\";\n value: T;\n };\n refSeq: number;\n}\n\n/** Incoming ops could match any of these types */\ntype IIncomingRegisterOperation<T> = IRegisterOperation | IRegisterOperationOld<T>;\n\n/** Distinguish between incoming op formats so we know which type it is */\nconst incomingOpMatchesCurrentFormat = (op): op is IRegisterOperation => \"serializedValue\" in op;\n\n/** The type of the resolve function to call after the local operation is ack'd */\ntype PendingResolve = (winner: boolean) => void;\n\nconst snapshotFileName = \"header\";\n\n/**\n * Implementation of a consensus register collection\n */\nexport class ConsensusRegisterCollection<T>\n extends SharedObject<IConsensusRegisterCollectionEvents> implements IConsensusRegisterCollection<T> {\n /**\n * Create a new consensus register collection\n *\n * @param runtime - data store runtime the new consensus register collection belongs to\n * @param id - optional name of the consensus register collection\n * @returns newly create consensus register collection (but not attached yet)\n */\n // eslint-disable-next-line @typescript-eslint/no-shadow\n public static create<T>(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, ConsensusRegisterCollectionFactory.Type) as ConsensusRegisterCollection<T>;\n }\n\n /**\n * Get a factory for ConsensusRegisterCollection to register with the data store.\n *\n * @returns a factory that creates and load ConsensusRegisterCollection\n */\n public static getFactory() {\n return new ConsensusRegisterCollectionFactory();\n }\n\n private readonly data = new Map<string, ILocalData<T>>();\n\n /**\n * Constructs a new consensus register collection. If the object is non-local an id and service interfaces will\n * be provided\n */\n public constructor(\n id: string,\n runtime: IFluidDataStoreRuntime,\n attributes: IChannelAttributes,\n ) {\n super(id, runtime, attributes, \"fluid_consensusRegisterCollection_\");\n }\n\n /**\n * Creates a new register or writes a new value.\n * Returns a promise that will resolve when the write is acked.\n *\n * @returns Promise<true> if write was non-concurrent\n */\n public async write(key: string, value: T): Promise<boolean> {\n const serializedValue = this.stringify(value, this.serializer);\n\n if (!this.isAttached()) {\n // JSON-roundtrip value for local writes to match the behavior of going through the wire\n this.processInboundWrite(key, this.parse(serializedValue, this.serializer), 0, 0, true);\n return true;\n }\n\n const message: IRegisterOperation = {\n key,\n type: \"write\",\n serializedValue,\n refSeq: this.runtime.deltaManager.lastSequenceNumber,\n };\n\n return this.newAckBasedPromise<boolean>((resolve) => {\n // Send the resolve function as the localOpMetadata. This will be provided back to us when the\n // op is ack'd.\n this.submitLocalMessage(message, resolve);\n // If we fail due to runtime being disposed, it's better to return false then unhandled exception.\n }).catch((error) => false);\n }\n\n /**\n * Returns the most recent local value of a register.\n * @param key - The key to read\n * @param readPolicy - The ReadPolicy to apply. Defaults to Atomic.\n */\n public read(key: string, readPolicy: ReadPolicy = ReadPolicy.Atomic): T | undefined {\n if (readPolicy === ReadPolicy.Atomic) {\n return this.readAtomic(key);\n }\n\n const versions = this.readVersions(key);\n\n if (versions !== undefined) {\n // We don't support deletion. So there should be at least one value.\n assert(versions.length > 0, 0x06c /* \"Value should be undefined or non-empty\" */);\n\n return versions[versions.length - 1];\n }\n }\n\n public readVersions(key: string): T[] | undefined {\n const data = this.data.get(key);\n return data?.versions.map((element: ILocalRegister<T>) => element.value.value);\n }\n\n public keys(): string[] {\n return [...this.data.keys()];\n }\n\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n const dataObj: { [key: string]: ILocalData<T>; } = {};\n this.data.forEach((v, k) => { dataObj[k] = v; });\n\n return createSingleBlobSummary(snapshotFileName, this.stringify(dataObj, serializer));\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n const blob = await storage.readBlob(snapshotFileName);\n const header = bufferToString(blob, \"utf8\");\n const dataObj = this.parse(header, this.serializer);\n\n for (const key of Object.keys(dataObj)) {\n assert(dataObj[key].atomic?.value.type !== \"Shared\",\n // eslint-disable-next-line max-len\n 0x06d /* \"SharedObjects contained in ConsensusRegisterCollection can no longer be deserialized as of 0.17\" */);\n\n this.data.set(key, dataObj[key]);\n }\n }\n\n protected onDisconnect() {}\n\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation) {\n const op: IIncomingRegisterOperation<T> = message.contents;\n switch (op.type) {\n case \"write\": {\n // backward compatibility: File at rest written with runtime <= 0.13 do not have refSeq\n // when the refSeq property didn't exist\n if (op.refSeq === undefined) {\n op.refSeq = message.referenceSequenceNumber;\n }\n // Message can be delivered with delay - e.g. resubmitted on reconnect.\n // Use the refSeq from when the op was created, not when it was transmitted\n const refSeqWhenCreated = op.refSeq;\n assert(refSeqWhenCreated <= message.referenceSequenceNumber,\n 0x06e /* \"Message's reference sequence number < op's reference sequence number!\" */);\n\n const value = incomingOpMatchesCurrentFormat(op)\n ? this.parse(op.serializedValue, this.serializer) as T\n : op.value.value;\n const winner = this.processInboundWrite(\n op.key,\n value,\n refSeqWhenCreated,\n message.sequenceNumber,\n local);\n if (local) {\n // Resolve the pending promise for this operation now that we have received an ack for it.\n const resolve = localOpMetadata as PendingResolve;\n resolve(winner);\n }\n break;\n }\n default: unreachableCase(op.type);\n }\n }\n }\n\n private readAtomic(key: string): T | undefined {\n const data = this.data.get(key);\n return data?.atomic.value.value;\n }\n\n /**\n * Process an inbound write op\n * @param key - Key that was written to\n * @param value - Incoming value\n * @param refSeq - RefSeq at the time of write on the remote client\n * @param sequenceNumber - Sequence Number of this write op\n * @param local - Did this write originate on this client\n */\n private processInboundWrite(\n key: string,\n value: T,\n refSeq: number,\n sequenceNumber: number,\n local: boolean,\n ): boolean {\n let data = this.data.get(key);\n // Atomic update if it's a new register or the write was not concurrent,\n // meaning our state was known to the remote client at the time of write\n const winner = data === undefined || refSeq >= data.atomic.sequenceNumber;\n if (winner) {\n const atomicUpdate = newLocalRegister<T>(\n sequenceNumber,\n value,\n );\n if (data === undefined) {\n data = {\n atomic: atomicUpdate,\n versions: [], // we'll update versions next, leave it empty for now\n };\n this.data.set(key, data);\n } else {\n data.atomic = atomicUpdate;\n }\n } else {\n assert(!!data, 0x06f /* \"data missing for non-atomic inbound update!\" */);\n }\n\n // Remove versions that were known to the remote client at the time of write\n while (data.versions.length > 0 && refSeq >= data.versions[0].sequenceNumber) {\n data.versions.shift();\n }\n\n const versionUpdate = newLocalRegister<T>(\n sequenceNumber,\n value,\n );\n\n // Asserts for data integrity\n if (!this.isAttached()) {\n assert(refSeq === 0 && sequenceNumber === 0,\n 0x070 /* \"sequence numbers are expected to be 0 when unattached\" */);\n } else if (data.versions.length > 0) {\n assert(sequenceNumber > data.versions[data.versions.length - 1].sequenceNumber,\n 0x071 /* \"Versions should naturally be ordered by sequenceNumber\" */);\n }\n\n // Push the new element.\n data.versions.push(versionUpdate);\n\n // Raise events at the end, to avoid reentrancy issues\n if (winner) {\n this.emit(\"atomicChanged\", key, value, local);\n }\n this.emit(\"versionChanged\", key, value, local);\n\n return winner;\n }\n\n private stringify(value: any, serializer: IFluidSerializer): string {\n return serializer.stringify(value, this.handle);\n }\n\n private parse(content: string, serializer: IFluidSerializer): any {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return serializer.parse(content);\n }\n\n protected applyStashedOp() {\n // empty implementation\n return () => { };\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"consensusRegisterCollectionFactory.js","sourceRoot":"","sources":["../src/consensusRegisterCollectionFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,+EAA4E;AAE5E,qDAA8C;AAE9C;;GAEG;AACH,MAAa,kCAAkC;IAS3C,IAAW,IAAI;QACX,OAAO,kCAAkC,CAAC,IAAI,CAAC;IACnD,CAAC;IAED,IAAW,UAAU;QACjB,OAAO,kCAAkC,CAAC,UAAU,CAAC;IACzD,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAI,CACb,OAA+B,EAC/B,EAAU,EACV,QAA0B,EAC1B,UAA8B;QAC9B,MAAM,UAAU,GAAG,IAAI,yDAA2B,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QAC5E,MAAM,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChC,OAAO,UAAU,CAAC;IACtB,CAAC;IAEM,MAAM,CAAC,QAAgC,EAAE,EAAU;QACtD,MAAM,UAAU,GAAG,IAAI,yDAA2B,CAAC,EAAE,EAAE,QAAQ,EAAE,kCAAkC,CAAC,UAAU,CAAC,CAAC;QAChH,UAAU,CAAC,eAAe,EAAE,CAAC;QAC7B,OAAO,UAAU,CAAC;IACtB,CAAC;;AAlCL,gFAmCC;AAlCiB,uCAAI,GAAG,iEAAiE,CAAC;AAEhE,6CAAU,GAAuB;IACpD,IAAI,EAAE,kCAAkC,CAAC,IAAI;IAC7C,qBAAqB,EAAE,KAAK;IAC5B,cAAc,EAAE,2BAAU;CAC7B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ConsensusRegisterCollection } from \"./consensusRegisterCollection\";\nimport { IConsensusRegisterCollection, IConsensusRegisterCollectionFactory } from \"./interfaces\";\nimport { pkgVersion } from \"./packageVersion\";\n\n/**\n * The factory that defines the consensus queue\n */\nexport class ConsensusRegisterCollectionFactory implements IConsensusRegisterCollectionFactory {\n public static Type = \"https://graph.microsoft.com/types/consensus-register-collection\";\n\n public static readonly Attributes: IChannelAttributes = {\n type: ConsensusRegisterCollectionFactory.Type,\n snapshotFormatVersion: \"0.1\",\n packageVersion: pkgVersion,\n };\n\n public get type() {\n return ConsensusRegisterCollectionFactory.Type;\n }\n\n public get attributes() {\n return ConsensusRegisterCollectionFactory.Attributes;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}\n */\n public async load(\n runtime: IFluidDataStoreRuntime,\n id: string,\n services: IChannelServices,\n attributes: IChannelAttributes): Promise<IConsensusRegisterCollection> {\n const collection = new ConsensusRegisterCollection(id, runtime, attributes);\n await collection.load(services);\n return collection;\n }\n\n public create(document: IFluidDataStoreRuntime, id: string): IConsensusRegisterCollection {\n const collection = new ConsensusRegisterCollection(id, document, ConsensusRegisterCollectionFactory.Attributes);\n collection.initializeLocal();\n return collection;\n }\n}\n"]}
package/dist/index.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
- * Licensed under the MIT License.
5
- */
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./consensusRegisterCollection"), exports);
18
- __exportStar(require("./consensusRegisterCollectionFactory"), exports);
19
- __exportStar(require("./interfaces"), exports);
20
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAEH,gEAA8C;AAC9C,uEAAqD;AACrD,+CAA6B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport * from \"./consensusRegisterCollection\";\nexport * from \"./consensusRegisterCollectionFactory\";\nexport * from \"./interfaces\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA8EH;;GAEG;AACH,IAAY,UAMX;AAND,WAAY,UAAU;IAClB,mFAAmF;IACnF,+CAAM,CAAA;IAEN,2DAA2D;IAC3D,yCAAG,CAAA;AACP,CAAC,EANW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAMrB","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n IFluidDataStoreRuntime,\n IChannelServices,\n IChannelAttributes,\n IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISharedObject, ISharedObjectEvents } from \"@fluidframework/shared-object-base\";\n\n/**\n * Consensus Register Collection channel factory interface\n *\n * Extends the base IChannelFactory to return a more definite type of IConsensusRegisterCollection\n * Use for the runtime to create and load distributed data structure by type name of each channel\n */\nexport interface IConsensusRegisterCollectionFactory extends IChannelFactory {\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}\n */\n load(\n document: IFluidDataStoreRuntime,\n id: string,\n services: IChannelServices,\n attributes: IChannelAttributes): Promise<IConsensusRegisterCollection>;\n\n create(document: IFluidDataStoreRuntime, id: string): IConsensusRegisterCollection;\n}\n\nexport interface IConsensusRegisterCollectionEvents extends ISharedObjectEvents {\n (event: \"atomicChanged\" | \"versionChanged\", listener: (key: string, value: any, local: boolean) => void);\n}\n\n/**\n * Consensus Register Collection.\n *\n * A consensus register collection is a distributed data structure, which holds a set of registers with update\n * versions. On concurrent updates, a register internally stores all possible versions of a value by using reference\n * sequence number of the incoming update.\n *\n * Using all the stored versions, we can then distinguish amongst different read policies. Below are the policies\n * we support:\n *\n * Atomic: Atomicity requires a linearizable register. A linearizable register behaves as if there is only a single\n * copy of the data, and that every operation appears to take effect atomically at one point in time. This definition\n * implies that operations are executed in an well-defined order. On a concurrent update, we perform a compare-and-set\n * operation, where we compare a register sequence number with the incoming reference sequence number.\n * The earliest operation overwriting prior sequence numbers wins since every client reaches to an agreement on\n * the value. So we can safely return the first value.\n *\n * LWW: The last write to a key always wins.\n *\n */\nexport interface IConsensusRegisterCollection<T = any> extends ISharedObject<IConsensusRegisterCollectionEvents> {\n /**\n * Attempts to write a register with a value. Returns a promise to indicate the roundtrip completion.\n * For a non existent register, it will attempt to create a new register with the specified value.\n *\n * @returns Promise<true> if write was non-concurrent\n */\n write(key: string, value: T): Promise<boolean>;\n\n /**\n * Retrieves the agreed upon value for the register based on policy. Returns undefined if not present.\n */\n read(key: string, policy?: ReadPolicy): T | undefined;\n\n /**\n * Retrives all concurrent versions. Undefined if not present.\n */\n readVersions(key: string): T[] | undefined;\n\n /**\n * Returns the keys.\n */\n keys(): string[];\n}\n\n/**\n * Read policies used when reading the map value.\n */\nexport enum ReadPolicy {\n // On a concurrent update, returns the first agreed upon value amongst all clients.\n Atomic,\n\n // Last writer wins. Simply returns the last written value.\n LWW,\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,qCAAqC,CAAC;AAChD,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/register-collection\";\nexport const pkgVersion = \"1.4.0-115997\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"consensusRegisterCollection.d.ts","sourceRoot":"","sources":["../src/consensusRegisterCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,yBAAyB,EAAe,MAAM,sCAAsC,CAAC;AAC9F,OAAO,EACH,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACzB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAA2B,gBAAgB,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAC7G,OAAO,EAAE,kCAAkC,EAAE,MAAM,sCAAsC,CAAC;AAC1F,OAAO,EAAE,4BAA4B,EAAE,UAAU,EAAE,kCAAkC,EAAE,MAAM,cAAc,CAAC;AAoE5G;;GAEG;AACH,qBAAa,2BAA2B,CAAC,CAAC,CACtC,SAAQ,YAAY,CAAC,kCAAkC,CAAE,YAAW,4BAA4B,CAAC,CAAC,CAAC;IACnG;;;;;;OAMG;WAEW,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,sBAAsB,EAAE,EAAE,CAAC,EAAE,MAAM;IAIpE;;;;OAIG;WACW,UAAU;IAIxB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAoC;IAEzD;;;OAGG;gBAEC,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,sBAAsB,EAC/B,UAAU,EAAE,kBAAkB;IAKlC;;;;;OAKG;IACU,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAwB3D;;;;OAIG;IACI,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,GAAE,UAA8B,GAAG,CAAC,GAAG,SAAS;IAe5E,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC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AS,CAAC,KAAU,EAAE,UAA4B;QACtD,OAAO,UAAU,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC;IAEO,KAAK,CAAC,OAAe,EAAE,UAA4B;QACvD,+DAA+D;QAC/D,OAAO,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAES,cAAc;QACpB,uBAAuB;QACvB,OAAO,GAAG,EAAE,GAAG,CAAC,CAAC;IACrB,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, bufferToString, unreachableCase } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { createSingleBlobSummary, IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { ConsensusRegisterCollectionFactory } from \"./consensusRegisterCollectionFactory\";\nimport { IConsensusRegisterCollection, ReadPolicy, IConsensusRegisterCollectionEvents } from \"./interfaces\";\n\ninterface ILocalData<T> {\n // Atomic version\n atomic: ILocalRegister<T>;\n\n // All concurrent versions awaiting consensus\n versions: ILocalRegister<T>[];\n}\n\ninterface ILocalRegister<T> {\n // Register value, wrapped for backwards compatibility with < 0.17\n value: {\n type: \"Plain\";\n value: T;\n };\n\n // The sequence number when last consensus was reached\n sequenceNumber: number;\n}\n\nconst newLocalRegister = <T>(sequenceNumber: number, value: T): ILocalRegister<T> => ({\n sequenceNumber,\n value: {\n type: \"Plain\",\n value,\n },\n});\n\n/**\n * An operation for consensus register collection\n */\ninterface IRegisterOperation {\n key: string;\n type: \"write\";\n serializedValue: string;\n\n // Message can be delivered with delay - resubmitted on reconnect.\n // As such, refSeq needs to reference seq # at the time op was created,\n // not when op was actually sent over wire (ISequencedDocumentMessage.referenceSequenceNumber),\n // as client can ingest ops in between.\n refSeq: number | undefined;\n}\n\n/**\n * IRegisterOperation format in versions \\< 0.17\n */\ninterface IRegisterOperationOld<T> {\n key: string;\n type: \"write\";\n value: {\n type: \"Plain\";\n value: T;\n };\n refSeq: number;\n}\n\n/** Incoming ops could match any of these types */\ntype IIncomingRegisterOperation<T> = IRegisterOperation | IRegisterOperationOld<T>;\n\n/** Distinguish between incoming op formats so we know which type it is */\nconst incomingOpMatchesCurrentFormat = (op): op is IRegisterOperation => \"serializedValue\" in op;\n\n/** The type of the resolve function to call after the local operation is ack'd */\ntype PendingResolve = (winner: boolean) => void;\n\nconst snapshotFileName = \"header\";\n\n/**\n * Implementation of a consensus register collection\n */\nexport class ConsensusRegisterCollection<T>\n extends SharedObject<IConsensusRegisterCollectionEvents> implements IConsensusRegisterCollection<T> {\n /**\n * Create a new consensus register collection\n *\n * @param runtime - data store runtime the new consensus register collection belongs to\n * @param id - optional name of the consensus register collection\n * @returns newly create consensus register collection (but not attached yet)\n */\n // eslint-disable-next-line @typescript-eslint/no-shadow\n public static create<T>(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, ConsensusRegisterCollectionFactory.Type) as ConsensusRegisterCollection<T>;\n }\n\n /**\n * Get a factory for ConsensusRegisterCollection to register with the data store.\n *\n * @returns a factory that creates and load ConsensusRegisterCollection\n */\n public static getFactory() {\n return new ConsensusRegisterCollectionFactory();\n }\n\n private readonly data = new Map<string, ILocalData<T>>();\n\n /**\n * Constructs a new consensus register collection. If the object is non-local an id and service interfaces will\n * be provided\n */\n public constructor(\n id: string,\n runtime: IFluidDataStoreRuntime,\n attributes: IChannelAttributes,\n ) {\n super(id, runtime, attributes, \"fluid_consensusRegisterCollection_\");\n }\n\n /**\n * Creates a new register or writes a new value.\n * Returns a promise that will resolve when the write is acked.\n *\n * @returns Promise<true> if write was non-concurrent\n */\n public async write(key: string, value: T): Promise<boolean> {\n const serializedValue = this.stringify(value, this.serializer);\n\n if (!this.isAttached()) {\n // JSON-roundtrip value for local writes to match the behavior of going through the wire\n this.processInboundWrite(key, this.parse(serializedValue, this.serializer), 0, 0, true);\n return true;\n }\n\n const message: IRegisterOperation = {\n key,\n type: \"write\",\n serializedValue,\n refSeq: this.runtime.deltaManager.lastSequenceNumber,\n };\n\n return this.newAckBasedPromise<boolean>((resolve) => {\n // Send the resolve function as the localOpMetadata. This will be provided back to us when the\n // op is ack'd.\n this.submitLocalMessage(message, resolve);\n // If we fail due to runtime being disposed, it's better to return false then unhandled exception.\n }).catch((error) => false);\n }\n\n /**\n * Returns the most recent local value of a register.\n * @param key - The key to read\n * @param readPolicy - The ReadPolicy to apply. Defaults to Atomic.\n */\n public read(key: string, readPolicy: ReadPolicy = ReadPolicy.Atomic): T | undefined {\n if (readPolicy === ReadPolicy.Atomic) {\n return this.readAtomic(key);\n }\n\n const versions = this.readVersions(key);\n\n if (versions !== undefined) {\n // We don't support deletion. So there should be at least one value.\n assert(versions.length > 0, 0x06c /* \"Value should be undefined or non-empty\" */);\n\n return versions[versions.length - 1];\n }\n }\n\n public readVersions(key: string): T[] | undefined {\n const data = this.data.get(key);\n return data?.versions.map((element: ILocalRegister<T>) => element.value.value);\n }\n\n public keys(): string[] {\n return [...this.data.keys()];\n }\n\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n const dataObj: { [key: string]: ILocalData<T>; } = {};\n this.data.forEach((v, k) => { dataObj[k] = v; });\n\n return createSingleBlobSummary(snapshotFileName, this.stringify(dataObj, serializer));\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n const blob = await storage.readBlob(snapshotFileName);\n const header = bufferToString(blob, \"utf8\");\n const dataObj = this.parse(header, this.serializer);\n\n for (const key of Object.keys(dataObj)) {\n assert(dataObj[key].atomic?.value.type !== \"Shared\",\n // eslint-disable-next-line max-len\n 0x06d /* \"SharedObjects contained in ConsensusRegisterCollection can no longer be deserialized as of 0.17\" */);\n\n this.data.set(key, dataObj[key]);\n }\n }\n\n protected onDisconnect() {}\n\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation) {\n const op: IIncomingRegisterOperation<T> = message.contents;\n switch (op.type) {\n case \"write\": {\n // backward compatibility: File at rest written with runtime <= 0.13 do not have refSeq\n // when the refSeq property didn't exist\n if (op.refSeq === undefined) {\n op.refSeq = message.referenceSequenceNumber;\n }\n // Message can be delivered with delay - e.g. resubmitted on reconnect.\n // Use the refSeq from when the op was created, not when it was transmitted\n const refSeqWhenCreated = op.refSeq;\n assert(refSeqWhenCreated <= message.referenceSequenceNumber,\n 0x06e /* \"Message's reference sequence number < op's reference sequence number!\" */);\n\n const value = incomingOpMatchesCurrentFormat(op)\n ? this.parse(op.serializedValue, this.serializer) as T\n : op.value.value;\n const winner = this.processInboundWrite(\n op.key,\n value,\n refSeqWhenCreated,\n message.sequenceNumber,\n local);\n if (local) {\n // Resolve the pending promise for this operation now that we have received an ack for it.\n const resolve = localOpMetadata as PendingResolve;\n resolve(winner);\n }\n break;\n }\n default: unreachableCase(op.type);\n }\n }\n }\n\n private readAtomic(key: string): T | undefined {\n const data = this.data.get(key);\n return data?.atomic.value.value;\n }\n\n /**\n * Process an inbound write op\n * @param key - Key that was written to\n * @param value - Incoming value\n * @param refSeq - RefSeq at the time of write on the remote client\n * @param sequenceNumber - Sequence Number of this write op\n * @param local - Did this write originate on this client\n */\n private processInboundWrite(\n key: string,\n value: T,\n refSeq: number,\n sequenceNumber: number,\n local: boolean,\n ): boolean {\n let data = this.data.get(key);\n // Atomic update if it's a new register or the write was not concurrent,\n // meaning our state was known to the remote client at the time of write\n const winner = data === undefined || refSeq >= data.atomic.sequenceNumber;\n if (winner) {\n const atomicUpdate = newLocalRegister<T>(\n sequenceNumber,\n value,\n );\n if (data === undefined) {\n data = {\n atomic: atomicUpdate,\n versions: [], // we'll update versions next, leave it empty for now\n };\n this.data.set(key, data);\n } else {\n data.atomic = atomicUpdate;\n }\n } else {\n assert(!!data, 0x06f /* \"data missing for non-atomic inbound update!\" */);\n }\n\n // Remove versions that were known to the remote client at the time of write\n while (data.versions.length > 0 && refSeq >= data.versions[0].sequenceNumber) {\n data.versions.shift();\n }\n\n const versionUpdate = newLocalRegister<T>(\n sequenceNumber,\n value,\n );\n\n // Asserts for data integrity\n if (!this.isAttached()) {\n assert(refSeq === 0 && sequenceNumber === 0,\n 0x070 /* \"sequence numbers are expected to be 0 when unattached\" */);\n } else if (data.versions.length > 0) {\n assert(sequenceNumber > data.versions[data.versions.length - 1].sequenceNumber,\n 0x071 /* \"Versions should naturally be ordered by sequenceNumber\" */);\n }\n\n // Push the new element.\n data.versions.push(versionUpdate);\n\n // Raise events at the end, to avoid reentrancy issues\n if (winner) {\n this.emit(\"atomicChanged\", key, value, local);\n }\n this.emit(\"versionChanged\", key, value, local);\n\n return winner;\n }\n\n private stringify(value: any, serializer: IFluidSerializer): string {\n return serializer.stringify(value, this.handle);\n }\n\n private parse(content: string, serializer: IFluidSerializer): any {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return serializer.parse(content);\n }\n\n protected applyStashedOp() {\n // empty implementation\n return () => { };\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"consensusRegisterCollectionFactory.d.ts","sourceRoot":"","sources":["../src/consensusRegisterCollectionFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EACnB,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,4BAA4B,EAAE,mCAAmC,EAAE,MAAM,cAAc,CAAC;AAGjG;;GAEG;AACH,qBAAa,kCAAmC,YAAW,mCAAmC;IAC1F,OAAc,IAAI,SAAqE;IAEvF,gBAAuB,UAAU,EAAE,kBAAkB,CAInD;IAEF,IAAW,IAAI,WAEd;IAED,IAAW,UAAU,uBAEpB;IAED;;OAEG;IACU,IAAI,CACb,OAAO,EAAE,sBAAsB,EAC/B,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,gBAAgB,EAC1B,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAAC,4BAA4B,CAAC;IAMnE,MAAM,CAAC,QAAQ,EAAE,sBAAsB,EAAE,EAAE,EAAE,MAAM,GAAG,4BAA4B;CAK5F"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"consensusRegisterCollectionFactory.js","sourceRoot":"","sources":["../src/consensusRegisterCollectionFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;GAEG;AACH,MAAM,OAAO,kCAAkC;IAS3C,IAAW,IAAI;QACX,OAAO,kCAAkC,CAAC,IAAI,CAAC;IACnD,CAAC;IAED,IAAW,UAAU;QACjB,OAAO,kCAAkC,CAAC,UAAU,CAAC;IACzD,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAI,CACb,OAA+B,EAC/B,EAAU,EACV,QAA0B,EAC1B,UAA8B;QAC9B,MAAM,UAAU,GAAG,IAAI,2BAA2B,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QAC5E,MAAM,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChC,OAAO,UAAU,CAAC;IACtB,CAAC;IAEM,MAAM,CAAC,QAAgC,EAAE,EAAU;QACtD,MAAM,UAAU,GAAG,IAAI,2BAA2B,CAAC,EAAE,EAAE,QAAQ,EAAE,kCAAkC,CAAC,UAAU,CAAC,CAAC;QAChH,UAAU,CAAC,eAAe,EAAE,CAAC;QAC7B,OAAO,UAAU,CAAC;IACtB,CAAC;;AAjCa,uCAAI,GAAG,iEAAiE,CAAC;AAEhE,6CAAU,GAAuB;IACpD,IAAI,EAAE,kCAAkC,CAAC,IAAI;IAC7C,qBAAqB,EAAE,KAAK;IAC5B,cAAc,EAAE,UAAU;CAC7B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ConsensusRegisterCollection } from \"./consensusRegisterCollection\";\nimport { IConsensusRegisterCollection, IConsensusRegisterCollectionFactory } from \"./interfaces\";\nimport { pkgVersion } from \"./packageVersion\";\n\n/**\n * The factory that defines the consensus queue\n */\nexport class ConsensusRegisterCollectionFactory implements IConsensusRegisterCollectionFactory {\n public static Type = \"https://graph.microsoft.com/types/consensus-register-collection\";\n\n public static readonly Attributes: IChannelAttributes = {\n type: ConsensusRegisterCollectionFactory.Type,\n snapshotFormatVersion: \"0.1\",\n packageVersion: pkgVersion,\n };\n\n public get type() {\n return ConsensusRegisterCollectionFactory.Type;\n }\n\n public get attributes() {\n return ConsensusRegisterCollectionFactory.Attributes;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}\n */\n public async load(\n runtime: IFluidDataStoreRuntime,\n id: string,\n services: IChannelServices,\n attributes: IChannelAttributes): Promise<IConsensusRegisterCollection> {\n const collection = new ConsensusRegisterCollection(id, runtime, attributes);\n await collection.load(services);\n return collection;\n }\n\n public create(document: IFluidDataStoreRuntime, id: string): IConsensusRegisterCollection {\n const collection = new ConsensusRegisterCollection(id, document, ConsensusRegisterCollectionFactory.Attributes);\n collection.initializeLocal();\n return collection;\n }\n}\n"]}
package/lib/index.d.ts DELETED
@@ -1,8 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- export * from "./consensusRegisterCollection";
6
- export * from "./consensusRegisterCollectionFactory";
7
- export * from "./interfaces";
8
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sCAAsC,CAAC;AACrD,cAAc,cAAc,CAAC"}
package/lib/index.js DELETED
@@ -1,8 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- export * from "./consensusRegisterCollection";
6
- export * from "./consensusRegisterCollectionFactory";
7
- export * from "./interfaces";
8
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sCAAsC,CAAC;AACrD,cAAc,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport * from \"./consensusRegisterCollection\";\nexport * from \"./consensusRegisterCollectionFactory\";\nexport * from \"./interfaces\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,sBAAsB,EACtB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EAClB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAExF;;;;;GAKG;AACH,MAAM,WAAW,mCAAoC,SAAQ,eAAe;IACxE;;OAEG;IACH,IAAI,CACA,QAAQ,EAAE,sBAAsB,EAChC,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,gBAAgB,EAC1B,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;IAE3E,MAAM,CAAC,QAAQ,EAAE,sBAAsB,EAAE,EAAE,EAAE,MAAM,GAAG,4BAA4B,CAAC;CACtF;AAED,MAAM,WAAW,kCAAmC,SAAQ,mBAAmB;IAC3E,CAAC,KAAK,EAAE,eAAe,GAAG,gBAAgB,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,OAAE;CAC5G;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,4BAA4B,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,aAAa,CAAC,kCAAkC,CAAC;IAC5G;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE/C;;OAEG;IACH,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,CAAC,GAAG,SAAS,CAAC;IAEtD;;OAEG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,SAAS,CAAC;IAE3C;;OAEG;IACH,IAAI,IAAI,MAAM,EAAE,CAAC;CACpB;AAED;;GAEG;AACH,oBAAY,UAAU;IAElB,MAAM,IAAA;IAGN,GAAG,IAAA;CACN"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA8EH;;GAEG;AACH,MAAM,CAAN,IAAY,UAMX;AAND,WAAY,UAAU;IAClB,mFAAmF;IACnF,+CAAM,CAAA;IAEN,2DAA2D;IAC3D,yCAAG,CAAA;AACP,CAAC,EANW,UAAU,KAAV,UAAU,QAMrB","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n IFluidDataStoreRuntime,\n IChannelServices,\n IChannelAttributes,\n IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISharedObject, ISharedObjectEvents } from \"@fluidframework/shared-object-base\";\n\n/**\n * Consensus Register Collection channel factory interface\n *\n * Extends the base IChannelFactory to return a more definite type of IConsensusRegisterCollection\n * Use for the runtime to create and load distributed data structure by type name of each channel\n */\nexport interface IConsensusRegisterCollectionFactory extends IChannelFactory {\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}\n */\n load(\n document: IFluidDataStoreRuntime,\n id: string,\n services: IChannelServices,\n attributes: IChannelAttributes): Promise<IConsensusRegisterCollection>;\n\n create(document: IFluidDataStoreRuntime, id: string): IConsensusRegisterCollection;\n}\n\nexport interface IConsensusRegisterCollectionEvents extends ISharedObjectEvents {\n (event: \"atomicChanged\" | \"versionChanged\", listener: (key: string, value: any, local: boolean) => void);\n}\n\n/**\n * Consensus Register Collection.\n *\n * A consensus register collection is a distributed data structure, which holds a set of registers with update\n * versions. On concurrent updates, a register internally stores all possible versions of a value by using reference\n * sequence number of the incoming update.\n *\n * Using all the stored versions, we can then distinguish amongst different read policies. Below are the policies\n * we support:\n *\n * Atomic: Atomicity requires a linearizable register. A linearizable register behaves as if there is only a single\n * copy of the data, and that every operation appears to take effect atomically at one point in time. This definition\n * implies that operations are executed in an well-defined order. On a concurrent update, we perform a compare-and-set\n * operation, where we compare a register sequence number with the incoming reference sequence number.\n * The earliest operation overwriting prior sequence numbers wins since every client reaches to an agreement on\n * the value. So we can safely return the first value.\n *\n * LWW: The last write to a key always wins.\n *\n */\nexport interface IConsensusRegisterCollection<T = any> extends ISharedObject<IConsensusRegisterCollectionEvents> {\n /**\n * Attempts to write a register with a value. Returns a promise to indicate the roundtrip completion.\n * For a non existent register, it will attempt to create a new register with the specified value.\n *\n * @returns Promise<true> if write was non-concurrent\n */\n write(key: string, value: T): Promise<boolean>;\n\n /**\n * Retrieves the agreed upon value for the register based on policy. Returns undefined if not present.\n */\n read(key: string, policy?: ReadPolicy): T | undefined;\n\n /**\n * Retrives all concurrent versions. Undefined if not present.\n */\n readVersions(key: string): T[] | undefined;\n\n /**\n * Returns the keys.\n */\n keys(): string[];\n}\n\n/**\n * Read policies used when reading the map value.\n */\nexport enum ReadPolicy {\n // On a concurrent update, returns the first agreed upon value amongst all clients.\n Atomic,\n\n // Last writer wins. Simply returns the last written value.\n LWW,\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,qCAAqC,CAAC;AAC7D,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/register-collection\";\nexport const pkgVersion = \"1.4.0-115997\";\n"]}
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./lib",
5
- "module": "esnext"
6
- },
7
- }