@fluidframework/ordered-collection 2.0.0-internal.3.0.0 → 2.0.0-internal.3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/.eslintrc.js +5 -7
  2. package/.mocharc.js +2 -2
  3. package/README.md +1 -1
  4. package/api-extractor.json +2 -2
  5. package/dist/consensusOrderedCollection.d.ts.map +1 -1
  6. package/dist/consensusOrderedCollection.js +4 -2
  7. package/dist/consensusOrderedCollection.js.map +1 -1
  8. package/dist/consensusOrderedCollectionFactory.d.ts.map +1 -1
  9. package/dist/consensusOrderedCollectionFactory.js.map +1 -1
  10. package/dist/consensusQueue.d.ts.map +1 -1
  11. package/dist/consensusQueue.js.map +1 -1
  12. package/dist/interfaces.d.ts.map +1 -1
  13. package/dist/interfaces.js.map +1 -1
  14. package/dist/packageVersion.d.ts +1 -1
  15. package/dist/packageVersion.js +1 -1
  16. package/dist/packageVersion.js.map +1 -1
  17. package/dist/snapshotableArray.d.ts.map +1 -1
  18. package/dist/snapshotableArray.js.map +1 -1
  19. package/dist/testUtils.d.ts.map +1 -1
  20. package/dist/testUtils.js.map +1 -1
  21. package/lib/consensusOrderedCollection.d.ts.map +1 -1
  22. package/lib/consensusOrderedCollection.js +4 -2
  23. package/lib/consensusOrderedCollection.js.map +1 -1
  24. package/lib/consensusOrderedCollectionFactory.d.ts.map +1 -1
  25. package/lib/consensusOrderedCollectionFactory.js.map +1 -1
  26. package/lib/consensusQueue.d.ts.map +1 -1
  27. package/lib/consensusQueue.js.map +1 -1
  28. package/lib/interfaces.d.ts.map +1 -1
  29. package/lib/interfaces.js.map +1 -1
  30. package/lib/packageVersion.d.ts +1 -1
  31. package/lib/packageVersion.js +1 -1
  32. package/lib/packageVersion.js.map +1 -1
  33. package/lib/snapshotableArray.d.ts.map +1 -1
  34. package/lib/snapshotableArray.js.map +1 -1
  35. package/lib/testUtils.d.ts.map +1 -1
  36. package/lib/testUtils.js +1 -1
  37. package/lib/testUtils.js.map +1 -1
  38. package/package.json +102 -101
  39. package/prettier.config.cjs +1 -1
  40. package/src/consensusOrderedCollection.ts +337 -318
  41. package/src/consensusOrderedCollectionFactory.ts +33 -32
  42. package/src/consensusQueue.ts +41 -37
  43. package/src/interfaces.ts +74 -74
  44. package/src/packageVersion.ts +1 -1
  45. package/src/snapshotableArray.ts +11 -11
  46. package/src/testUtils.ts +19 -18
  47. package/tsconfig.esnext.json +6 -6
  48. package/tsconfig.json +9 -13
@@ -4,9 +4,9 @@
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 { ConsensusQueue } from "./consensusQueue";
12
12
  import { IConsensusOrderedCollection, IConsensusOrderedCollectionFactory } from "./interfaces";
@@ -16,38 +16,39 @@ import { pkgVersion } from "./packageVersion";
16
16
  * The factory that defines the consensus queue
17
17
  */
18
18
  export class ConsensusQueueFactory implements IConsensusOrderedCollectionFactory {
19
- public static Type = "https://graph.microsoft.com/types/consensus-queue";
19
+ public static Type = "https://graph.microsoft.com/types/consensus-queue";
20
20
 
21
- public static readonly Attributes: IChannelAttributes = {
22
- type: ConsensusQueueFactory.Type,
23
- snapshotFormatVersion: "0.1",
24
- packageVersion: pkgVersion,
25
- };
21
+ public static readonly Attributes: IChannelAttributes = {
22
+ type: ConsensusQueueFactory.Type,
23
+ snapshotFormatVersion: "0.1",
24
+ packageVersion: pkgVersion,
25
+ };
26
26
 
27
- public get type() {
28
- return ConsensusQueueFactory.Type;
29
- }
27
+ public get type() {
28
+ return ConsensusQueueFactory.Type;
29
+ }
30
30
 
31
- public get attributes() {
32
- return ConsensusQueueFactory.Attributes;
33
- }
31
+ public get attributes() {
32
+ return ConsensusQueueFactory.Attributes;
33
+ }
34
34
 
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<IConsensusOrderedCollection> {
43
- const collection = new ConsensusQueue(id, runtime, attributes);
44
- await collection.load(services);
45
- return collection;
46
- }
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,
43
+ ): Promise<IConsensusOrderedCollection> {
44
+ const collection = new ConsensusQueue(id, runtime, attributes);
45
+ await collection.load(services);
46
+ return collection;
47
+ }
47
48
 
48
- public create(document: IFluidDataStoreRuntime, id: string): IConsensusOrderedCollection {
49
- const collection = new ConsensusQueue(id, document, this.attributes);
50
- collection.initializeLocal();
51
- return collection;
52
- }
49
+ public create(document: IFluidDataStoreRuntime, id: string): IConsensusOrderedCollection {
50
+ const collection = new ConsensusQueue(id, document, this.attributes);
51
+ collection.initializeLocal();
52
+ return collection;
53
+ }
53
54
  }
@@ -4,9 +4,9 @@
4
4
  */
5
5
 
6
6
  import {
7
- IFluidDataStoreRuntime,
8
- IChannelAttributes,
9
- IChannelFactory,
7
+ IFluidDataStoreRuntime,
8
+ IChannelAttributes,
9
+ IChannelFactory,
10
10
  } from "@fluidframework/datastore-definitions";
11
11
  import { ConsensusOrderedCollection } from "./consensusOrderedCollection";
12
12
  import { ConsensusQueueFactory } from "./consensusOrderedCollectionFactory";
@@ -17,16 +17,16 @@ import { SnapshotableArray } from "./snapshotableArray";
17
17
  * An JS array based queue implementation that is the backing data structure for ConsensusQueue
18
18
  */
19
19
  class SnapshotableQueue<T> extends SnapshotableArray<T> implements IOrderedCollection<T> {
20
- public add(value: T) {
21
- this.data.push(value);
22
- }
20
+ public add(value: T) {
21
+ this.data.push(value);
22
+ }
23
23
 
24
- public remove(): T {
25
- if (this.size() === 0) {
26
- throw new Error("SnapshotableQueue is empty");
27
- }
28
- return this.data.shift() as T;
29
- }
24
+ public remove(): T {
25
+ if (this.size() === 0) {
26
+ throw new Error("SnapshotableQueue is empty");
27
+ }
28
+ return this.data.shift() as T;
29
+ }
30
30
  }
31
31
 
32
32
  /**
@@ -35,31 +35,35 @@ class SnapshotableQueue<T> extends SnapshotableArray<T> implements IOrderedColle
35
35
  * An derived type of ConsensusOrderedCollection with a queue as the backing data and order.
36
36
  */
37
37
  export class ConsensusQueue<T = any> extends ConsensusOrderedCollection<T> {
38
- /**
39
- * Create a new consensus queue
40
- *
41
- * @param runtime - data store runtime the new consensus queue belongs to
42
- * @param id - optional name of theconsensus queue
43
- * @returns newly create consensus queue (but not attached yet)
44
- */
45
- public static create<T = any>(runtime: IFluidDataStoreRuntime, id?: string) {
46
- return runtime.createChannel(id, ConsensusQueueFactory.Type) as ConsensusQueue<T>;
47
- }
38
+ /**
39
+ * Create a new consensus queue
40
+ *
41
+ * @param runtime - data store runtime the new consensus queue belongs to
42
+ * @param id - optional name of theconsensus queue
43
+ * @returns newly create consensus queue (but not attached yet)
44
+ */
45
+ public static create<T = any>(runtime: IFluidDataStoreRuntime, id?: string) {
46
+ return runtime.createChannel(id, ConsensusQueueFactory.Type) as ConsensusQueue<T>;
47
+ }
48
48
 
49
- /**
50
- * Get a factory for ConsensusQueue to register with the data store.
51
- *
52
- * @returns a factory that creates and load ConsensusQueue
53
- */
54
- public static getFactory(): IChannelFactory {
55
- return new ConsensusQueueFactory();
56
- }
49
+ /**
50
+ * Get a factory for ConsensusQueue to register with the data store.
51
+ *
52
+ * @returns a factory that creates and load ConsensusQueue
53
+ */
54
+ public static getFactory(): IChannelFactory {
55
+ return new ConsensusQueueFactory();
56
+ }
57
57
 
58
- /**
59
- * Constructs a new consensus queue. If the object is non-local an id and service interfaces will
60
- * be provided
61
- */
62
- public constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes) {
63
- super(id, runtime, attributes, new SnapshotableQueue<T>());
64
- }
58
+ /**
59
+ * Constructs a new consensus queue. If the object is non-local an id and service interfaces will
60
+ * be provided
61
+ */
62
+ public constructor(
63
+ id: string,
64
+ runtime: IFluidDataStoreRuntime,
65
+ attributes: IChannelAttributes,
66
+ ) {
67
+ super(id, runtime, attributes, new SnapshotableQueue<T>());
68
+ }
65
69
  }
package/src/interfaces.ts CHANGED
@@ -4,16 +4,16 @@
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
 
14
14
  export enum ConsensusResult {
15
- Release,
16
- Complete,
15
+ Release,
16
+ Complete,
17
17
  }
18
18
 
19
19
  /**
@@ -29,45 +29,45 @@ export type ConsensusCallback<T> = (value: T) => Promise<ConsensusResult>;
29
29
  * Use for the runtime to create and load distributed data structure by type name of each channel
30
30
  */
31
31
  export interface IConsensusOrderedCollectionFactory extends IChannelFactory {
32
- load(
33
- document: IFluidDataStoreRuntime,
34
- id: string,
35
- services: IChannelServices,
36
- attributes: IChannelAttributes): Promise<IConsensusOrderedCollection>;
37
-
38
- create(document: IFluidDataStoreRuntime, id: string): IConsensusOrderedCollection;
32
+ load(
33
+ document: IFluidDataStoreRuntime,
34
+ id: string,
35
+ services: IChannelServices,
36
+ attributes: IChannelAttributes,
37
+ ): Promise<IConsensusOrderedCollection>;
38
+
39
+ create(document: IFluidDataStoreRuntime, id: string): IConsensusOrderedCollection;
39
40
  }
40
41
 
41
42
  /**
42
43
  * Events notifying about addition, acquisition, release and completion of items
43
44
  */
44
45
  export interface IConsensusOrderedCollectionEvents<T> extends ISharedObjectEvents {
45
-
46
- /**
47
- * Event fires when new item is added to the queue or
48
- * an item previously acquired is returned back to a queue (including client loosing connection)
49
- * @param newlyAdded - indicates if it's newly added item of previously acquired item
50
- */
51
- (event: "add", listener: (value: T, newlyAdded: boolean) => void): this;
52
- /**
53
- * Event fires when a client acquired an item
54
- * Fires both for locally acquired items, as well as items acquired by remote clients
55
- */
56
- (event: "acquire", listener: (value: T, clientId?: string) => void): this;
57
-
58
- /**
59
- * "Complete event fires when a client completes an item.
60
- */
61
- (event: "complete", listener: (value: T) => void): this;
62
-
63
- /**
64
- * Event fires when locally acquired item is being released back to the queue.
65
- * Please note that release process is asynchronous, so it takes a while for it to happen
66
- * ("add" event will be fired as result of it)
67
- * @param intentional - indicates whether release was intentional (result of returning
68
- * ConsensusResult.Release from callback) or it happened as result of lost connection.
69
- */
70
- (event: "localRelease", listener: (value: T, intentional: boolean) => void): this;
46
+ /**
47
+ * Event fires when new item is added to the queue or
48
+ * an item previously acquired is returned back to a queue (including client loosing connection)
49
+ * @param newlyAdded - indicates if it's newly added item of previously acquired item
50
+ */
51
+ (event: "add", listener: (value: T, newlyAdded: boolean) => void): this;
52
+ /**
53
+ * Event fires when a client acquired an item
54
+ * Fires both for locally acquired items, as well as items acquired by remote clients
55
+ */
56
+ (event: "acquire", listener: (value: T, clientId?: string) => void): this;
57
+
58
+ /**
59
+ * "Complete event fires when a client completes an item.
60
+ */
61
+ (event: "complete", listener: (value: T) => void): this;
62
+
63
+ /**
64
+ * Event fires when locally acquired item is being released back to the queue.
65
+ * Please note that release process is asynchronous, so it takes a while for it to happen
66
+ * ("add" event will be fired as result of it)
67
+ * @param intentional - indicates whether release was intentional (result of returning
68
+ * ConsensusResult.Release from callback) or it happened as result of lost connection.
69
+ */
70
+ (event: "localRelease", listener: (value: T, intentional: boolean) => void): this;
71
71
  }
72
72
 
73
73
  /**
@@ -94,25 +94,25 @@ export interface IConsensusOrderedCollectionEvents<T> extends ISharedObjectEvent
94
94
  * They will not be references to the original input object. Thus changed to
95
95
  * the input object will not reflect the object in the collection.
96
96
  */
97
- export interface IConsensusOrderedCollection<T = any> extends ISharedObject<IConsensusOrderedCollectionEvents<T>> {
98
-
99
- /**
100
- * Adds a value to the collection
101
- */
102
- add(value: T): Promise<void>;
103
-
104
- /**
105
- * Retrieves a value from the collection.
106
- * @returns Returns true (and calls callback with acquired value) if collection was not empty.
107
- * Otherwise returns false.
108
- */
109
- acquire(callback: ConsensusCallback<T>): Promise<boolean>;
110
-
111
- /**
112
- * Wait for a value to be available and remove it from the consensus collection
113
- * Calls callback with retrieved value.
114
- */
115
- waitAndAcquire(callback: ConsensusCallback<T>): Promise<void>;
97
+ export interface IConsensusOrderedCollection<T = any>
98
+ extends ISharedObject<IConsensusOrderedCollectionEvents<T>> {
99
+ /**
100
+ * Adds a value to the collection
101
+ */
102
+ add(value: T): Promise<void>;
103
+
104
+ /**
105
+ * Retrieves a value from the collection.
106
+ * @returns Returns true (and calls callback with acquired value) if collection was not empty.
107
+ * Otherwise returns false.
108
+ */
109
+ acquire(callback: ConsensusCallback<T>): Promise<boolean>;
110
+
111
+ /**
112
+ * Wait for a value to be available and remove it from the consensus collection
113
+ * Calls callback with retrieved value.
114
+ */
115
+ waitAndAcquire(callback: ConsensusCallback<T>): Promise<void>;
116
116
  }
117
117
 
118
118
  /**
@@ -122,9 +122,9 @@ export interface IConsensusOrderedCollection<T = any> extends ISharedObject<ICon
122
122
  * TODO: currently input and output is not symmetrical, can they become symmetrical?
123
123
  */
124
124
  export interface ISnapshotable<T> {
125
- asArray(): T[];
125
+ asArray(): T[];
126
126
 
127
- loadFrom(values: T[]): void;
127
+ loadFrom(values: T[]): void;
128
128
  }
129
129
 
130
130
  /**
@@ -135,18 +135,18 @@ export interface ISnapshotable<T> {
135
135
  * for the ConsensusOrderedCollection
136
136
  */
137
137
  export interface IOrderedCollection<T = any> extends ISnapshotable<T> {
138
- /**
139
- * Adds a value to the collection
140
- */
141
- add(value: T);
142
-
143
- /**
144
- * Retrieves a value from the collection.
145
- */
146
- remove(): T;
147
-
148
- /**
149
- * Return the size of the collection
150
- */
151
- size(): number;
138
+ /**
139
+ * Adds a value to the collection
140
+ */
141
+ add(value: T);
142
+
143
+ /**
144
+ * Retrieves a value from the collection.
145
+ */
146
+ remove(): T;
147
+
148
+ /**
149
+ * Return the size of the collection
150
+ */
151
+ size(): number;
152
152
  }
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/ordered-collection";
9
- export const pkgVersion = "2.0.0-internal.3.0.0";
9
+ export const pkgVersion = "2.0.0-internal.3.1.0";
@@ -6,18 +6,18 @@
6
6
  import { assert } from "@fluidframework/common-utils";
7
7
 
8
8
  export class SnapshotableArray<T> extends Array {
9
- protected data: T[] = [];
9
+ protected data: T[] = [];
10
10
 
11
- public asArray() {
12
- return this.data;
13
- }
11
+ public asArray() {
12
+ return this.data;
13
+ }
14
14
 
15
- public async loadFrom(from: T[]): Promise<void> {
16
- assert(this.data.length === 0, 0x06b /* "Loading snapshot into a non-empty collection" */);
17
- this.data = from;
18
- }
15
+ public async loadFrom(from: T[]): Promise<void> {
16
+ assert(this.data.length === 0, 0x06b /* "Loading snapshot into a non-empty collection" */);
17
+ this.data = from;
18
+ }
19
19
 
20
- public size(): number {
21
- return this.data.length;
22
- }
20
+ public size(): number {
21
+ return this.data.length;
22
+ }
23
23
  }
package/src/testUtils.ts CHANGED
@@ -3,33 +3,34 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import {
7
- ConsensusResult,
8
- IConsensusOrderedCollection,
9
- } from "./interfaces";
6
+ import { ConsensusResult, IConsensusOrderedCollection } from "./interfaces";
10
7
 
11
8
  /**
12
9
  * Helper method to acquire and complete an item
13
10
  * Should be used in test code only
14
11
  */
15
- export async function acquireAndComplete<T>(collection: IConsensusOrderedCollection<T>): Promise<T | undefined> {
16
- let res: T | undefined;
17
- await collection.acquire(async (value: T) => {
18
- res = value;
19
- return ConsensusResult.Complete;
20
- });
21
- return res;
12
+ export async function acquireAndComplete<T>(
13
+ collection: IConsensusOrderedCollection<T>,
14
+ ): Promise<T | undefined> {
15
+ let res: T | undefined;
16
+ await collection.acquire(async (value: T) => {
17
+ res = value;
18
+ return ConsensusResult.Complete;
19
+ });
20
+ return res;
22
21
  }
23
22
 
24
23
  /**
25
24
  * Helper method to acquire and complete an item
26
25
  * Should be used in test code only
27
26
  */
28
- export async function waitAcquireAndComplete<T>(collection: IConsensusOrderedCollection<T>): Promise<T> {
29
- let res: T | undefined;
30
- await collection.waitAndAcquire(async (value: T) => {
31
- res = value;
32
- return ConsensusResult.Complete;
33
- });
34
- return res as T;
27
+ export async function waitAcquireAndComplete<T>(
28
+ collection: IConsensusOrderedCollection<T>,
29
+ ): Promise<T> {
30
+ let res: T | undefined;
31
+ await collection.waitAndAcquire(async (value: T) => {
32
+ res = value;
33
+ return ConsensusResult.Complete;
34
+ });
35
+ return res as T;
35
36
  }
@@ -1,7 +1,7 @@
1
1
  {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./lib",
5
- "module": "esnext"
6
- },
7
- }
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./lib",
5
+ "module": "esnext",
6
+ },
7
+ }
package/tsconfig.json CHANGED
@@ -1,14 +1,10 @@
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": "@fluidframework/build-common/ts-common-config.json",
3
+ "exclude": ["src/test/**/*"],
4
+ "compilerOptions": {
5
+ "rootDir": "./src",
6
+ "outDir": "./dist",
7
+ "composite": true,
8
+ },
9
+ "include": ["src/**/*"],
10
+ }