@fluidframework/ordered-collection 2.0.0-internal.3.0.2 → 2.0.0-internal.3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +5 -7
- package/.mocharc.js +2 -2
- package/README.md +1 -1
- package/api-extractor.json +2 -2
- package/dist/consensusOrderedCollection.d.ts.map +1 -1
- package/dist/consensusOrderedCollection.js +4 -2
- package/dist/consensusOrderedCollection.js.map +1 -1
- package/dist/consensusOrderedCollectionFactory.d.ts.map +1 -1
- package/dist/consensusOrderedCollectionFactory.js.map +1 -1
- package/dist/consensusQueue.d.ts.map +1 -1
- package/dist/consensusQueue.js.map +1 -1
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/snapshotableArray.d.ts.map +1 -1
- package/dist/snapshotableArray.js.map +1 -1
- package/dist/testUtils.d.ts.map +1 -1
- package/dist/testUtils.js.map +1 -1
- package/lib/consensusOrderedCollection.d.ts.map +1 -1
- package/lib/consensusOrderedCollection.js +4 -2
- package/lib/consensusOrderedCollection.js.map +1 -1
- package/lib/consensusOrderedCollectionFactory.d.ts.map +1 -1
- package/lib/consensusOrderedCollectionFactory.js.map +1 -1
- package/lib/consensusQueue.d.ts.map +1 -1
- package/lib/consensusQueue.js.map +1 -1
- package/lib/interfaces.d.ts.map +1 -1
- package/lib/interfaces.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/snapshotableArray.d.ts.map +1 -1
- package/lib/snapshotableArray.js.map +1 -1
- package/lib/testUtils.d.ts.map +1 -1
- package/lib/testUtils.js +1 -1
- package/lib/testUtils.js.map +1 -1
- package/package.json +45 -44
- package/prettier.config.cjs +1 -1
- package/src/consensusOrderedCollection.ts +337 -318
- package/src/consensusOrderedCollectionFactory.ts +33 -32
- package/src/consensusQueue.ts +41 -37
- package/src/interfaces.ts +74 -74
- package/src/packageVersion.ts +1 -1
- package/src/snapshotableArray.ts +11 -11
- package/src/testUtils.ts +19 -18
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +9 -13
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
19
|
+
public static Type = "https://graph.microsoft.com/types/consensus-queue";
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
public static readonly Attributes: IChannelAttributes = {
|
|
22
|
+
type: ConsensusQueueFactory.Type,
|
|
23
|
+
snapshotFormatVersion: "0.1",
|
|
24
|
+
packageVersion: pkgVersion,
|
|
25
|
+
};
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
public get type() {
|
|
28
|
+
return ConsensusQueueFactory.Type;
|
|
29
|
+
}
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
public get attributes() {
|
|
32
|
+
return ConsensusQueueFactory.Attributes;
|
|
33
|
+
}
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
}
|
package/src/consensusQueue.ts
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
public add(value: T) {
|
|
21
|
+
this.data.push(value);
|
|
22
|
+
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
16
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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>
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
125
|
+
asArray(): T[];
|
|
126
126
|
|
|
127
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
}
|
package/src/packageVersion.ts
CHANGED
package/src/snapshotableArray.ts
CHANGED
|
@@ -6,18 +6,18 @@
|
|
|
6
6
|
import { assert } from "@fluidframework/common-utils";
|
|
7
7
|
|
|
8
8
|
export class SnapshotableArray<T> extends Array {
|
|
9
|
-
|
|
9
|
+
protected data: T[] = [];
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
public asArray() {
|
|
12
|
+
return this.data;
|
|
13
|
+
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
21
|
-
|
|
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>(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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>(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
}
|
package/tsconfig.esnext.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
}
|