@fluidframework/ordered-collection 2.12.0 → 2.20.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.cjs +1 -4
- package/CHANGELOG.md +8 -0
- package/dist/consensusOrderedCollection.d.ts.map +1 -1
- package/dist/consensusOrderedCollection.js +22 -13
- 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 +2 -0
- package/dist/consensusQueue.js.map +1 -1
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/package.json +2 -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/lib/consensusOrderedCollection.d.ts.map +1 -1
- package/lib/consensusOrderedCollection.js +22 -13
- 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 +2 -0
- 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/package.json +15 -15
- package/src/consensusOrderedCollection.ts +40 -26
- package/src/consensusOrderedCollectionFactory.ts +4 -2
- package/src/consensusQueue.ts +3 -1
- package/src/interfaces.ts +4 -0
- package/src/packageVersion.ts +1 -1
- package/src/snapshotableArray.ts +1 -1
package/.eslintrc.cjs
CHANGED
|
@@ -4,10 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
module.exports = {
|
|
7
|
-
extends: [
|
|
8
|
-
require.resolve("@fluidframework/eslint-config-fluid/minimal-deprecated"),
|
|
9
|
-
"prettier",
|
|
10
|
-
],
|
|
7
|
+
extends: [require.resolve("@fluidframework/eslint-config-fluid/recommended"), "prettier"],
|
|
11
8
|
parserOptions: {
|
|
12
9
|
project: ["./tsconfig.json", "./src/test/tsconfig.json"],
|
|
13
10
|
},
|
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consensusOrderedCollection.d.ts","sourceRoot":"","sources":["../src/consensusOrderedCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAEN,yBAAyB,EACzB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAErF,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,6CAA6C,CAAC;AAG7F,OAAO,EACN,iBAAiB,EAEjB,2BAA2B,EAC3B,iCAAiC,EACjC,kBAAkB,EAClB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"consensusOrderedCollection.d.ts","sourceRoot":"","sources":["../src/consensusOrderedCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAEN,yBAAyB,EACzB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAErF,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,6CAA6C,CAAC;AAG7F,OAAO,EACN,iBAAiB,EAEjB,2B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AAC,WAAW,CACpB,OAAO,EAAE,yBAAyB,EAClC,KAAK,EAAE,OAAO,EACd,eAAe,EAAE,OAAO,GACtB,IAAI;YAyCO,MAAM;IAepB,OAAO,CAAC,OAAO;IAKf,OAAO,CAAC,WAAW;YAmBL,eAAe;IAY7B,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,gBAAgB;IAIxB,SAAS,CAAC,cAAc,IAAI,IAAI;CAGhC"}
|
|
@@ -26,6 +26,8 @@ const idForLocalUnattachedClient = undefined;
|
|
|
26
26
|
* @legacy
|
|
27
27
|
* @alpha
|
|
28
28
|
*/
|
|
29
|
+
// TODO: #22835 Use undefined instead of any (breaking change)
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
31
|
class ConsensusOrderedCollection extends internal_4.SharedObject {
|
|
30
32
|
/**
|
|
31
33
|
* Constructs a new consensus collection. If the object is non-local an id and service interfaces will
|
|
@@ -76,15 +78,18 @@ class ConsensusOrderedCollection extends internal_4.SharedObject {
|
|
|
76
78
|
}
|
|
77
79
|
const res = await callback(result.value);
|
|
78
80
|
switch (res) {
|
|
79
|
-
case interfaces_js_1.ConsensusResult.Complete:
|
|
81
|
+
case interfaces_js_1.ConsensusResult.Complete: {
|
|
80
82
|
await this.complete(result.acquireId);
|
|
81
83
|
break;
|
|
82
|
-
|
|
84
|
+
}
|
|
85
|
+
case interfaces_js_1.ConsensusResult.Release: {
|
|
83
86
|
this.release(result.acquireId);
|
|
84
87
|
this.emit("localRelease", result.value, true /* intentional */);
|
|
85
88
|
break;
|
|
86
|
-
|
|
89
|
+
}
|
|
90
|
+
default: {
|
|
87
91
|
(0, internal_1.unreachableCase)(res);
|
|
92
|
+
}
|
|
88
93
|
}
|
|
89
94
|
return true;
|
|
90
95
|
}
|
|
@@ -108,7 +113,7 @@ class ConsensusOrderedCollection extends internal_4.SharedObject {
|
|
|
108
113
|
const builder = new internal_3.SummaryTreeBuilder();
|
|
109
114
|
let blobContent = this.serializeValue(this.data.asArray(), serializer);
|
|
110
115
|
builder.addBlob(snapshotFileNameData, blobContent);
|
|
111
|
-
blobContent = this.serializeValue(
|
|
116
|
+
blobContent = this.serializeValue([...this.jobTracking.entries()], serializer);
|
|
112
117
|
builder.addBlob(snapshotFileNameTracking, blobContent);
|
|
113
118
|
return builder.getSummaryTree();
|
|
114
119
|
}
|
|
@@ -187,25 +192,30 @@ class ConsensusOrderedCollection extends internal_4.SharedObject {
|
|
|
187
192
|
const op = message.contents;
|
|
188
193
|
let value;
|
|
189
194
|
switch (op.opName) {
|
|
190
|
-
case "add":
|
|
191
|
-
if (op.deserializedValue
|
|
192
|
-
this.addCore(op.
|
|
195
|
+
case "add": {
|
|
196
|
+
if (op.deserializedValue === undefined) {
|
|
197
|
+
this.addCore(this.deserializeValue(op.value, this.serializer));
|
|
193
198
|
}
|
|
194
199
|
else {
|
|
195
|
-
this.addCore(
|
|
200
|
+
this.addCore(op.deserializedValue);
|
|
196
201
|
}
|
|
197
202
|
break;
|
|
198
|
-
|
|
203
|
+
}
|
|
204
|
+
case "acquire": {
|
|
199
205
|
value = this.acquireCore(op.acquireId, message.clientId ?? undefined);
|
|
200
206
|
break;
|
|
201
|
-
|
|
207
|
+
}
|
|
208
|
+
case "complete": {
|
|
202
209
|
this.completeCore(op.acquireId);
|
|
203
210
|
break;
|
|
204
|
-
|
|
211
|
+
}
|
|
212
|
+
case "release": {
|
|
205
213
|
this.releaseCore(op.acquireId);
|
|
206
214
|
break;
|
|
207
|
-
|
|
215
|
+
}
|
|
216
|
+
default: {
|
|
208
217
|
(0, internal_1.unreachableCase)(op);
|
|
218
|
+
}
|
|
209
219
|
}
|
|
210
220
|
if (local) {
|
|
211
221
|
// Resolve the pending promise for this operation now that we have received an ack for it.
|
|
@@ -267,7 +277,6 @@ class ConsensusOrderedCollection extends internal_4.SharedObject {
|
|
|
267
277
|
return serializer.stringify(value, this.handle);
|
|
268
278
|
}
|
|
269
279
|
deserializeValue(content, serializer) {
|
|
270
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
271
280
|
return serializer.parse(content);
|
|
272
281
|
}
|
|
273
282
|
applyStashedOp() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consensusOrderedCollection.js","sourceRoot":"","sources":["../src/consensusOrderedCollection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA8D;AAC9D,kEAA8E;AAM9E,0EAGqD;AAErD,qEAA4E;AAC5E,0EAA6F;AAC7F,+BAAkC;AAElC,mDAMyB;AAEzB,MAAM,oBAAoB,GAAG,QAAQ,CAAC;AACtC,MAAM,wBAAwB,GAAG,aAAa,CAAC;AAyD/C,MAAM,0BAA0B,GAAG,SAAS,CAAC;AAE7C;;;;;;;;;;GAUG;AACH,MAAa,0BACZ,SAAQ,uBAAkD;IAQ1D;;;OAGG;IACH,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B,EACb,IAA2B;QAE5C,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,mCAAmC,CAAC,CAAC;QAFnD,SAAI,GAAJ,IAAI,CAAuB;QAb7C;;WAEG;QACK,gBAAW,GAAuB,IAAI,GAAG,EAAE,CAAC;QAcnD,4FAA4F;QAC5F,qDAAqD;QACrD,oFAAoF;QACpF,iFAAiF;QACjF,OAAO,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,cAAc,EAAE,CAAC,QAAgB,EAAE,EAAE;YAC3D,IAAA,iBAAM,EAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,qCAAqC,CAAC,CAAC;YAChE,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,GAAG,CAAC,KAAQ;QACxB,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAE7D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A,SAAI,GAAE;SACjB,CAAC,CAAC;IACJ,CAAC;IAEO,YAAY,CAAC,gBAAyB;QAC7C,MAAM,KAAK,GAAQ,EAAE,CAAC;QACtB,KAAK,MAAM,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACjE,IAAI,QAAQ,KAAK,gBAAgB,EAAE,CAAC;gBACnC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;gBACnC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBACrB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnB,CAAC;QACF,CAAC;QAED,+DAA+D;QAC/D,qFAAqF;QACrF,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC;IACvE,CAAC;IAEO,cAAc,CAAC,KAAK,EAAE,UAA4B;QACzD,OAAO,UAAU,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACjD,CAAC;IAEO,gBAAgB,CAAC,OAAe,EAAE,UAA4B;QACrE,+DAA+D;QAC/D,OAAO,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAES,cAAc;QACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;CACD;AAtTD,gEAsTC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport {\n\tMessageType,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport { IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base/internal\";\nimport { v4 as uuid } from \"uuid\";\n\nimport {\n\tConsensusCallback,\n\tConsensusResult,\n\tIConsensusOrderedCollection,\n\tIConsensusOrderedCollectionEvents,\n\tIOrderedCollection,\n} from \"./interfaces.js\";\n\nconst snapshotFileNameData = \"header\";\nconst snapshotFileNameTracking = \"jobTracking\";\n\ninterface IConsensusOrderedCollectionValue<T> {\n\t// an ID used to indicate acquired item.\n\t// Used in acquire/release/complete ops.\n\treadonly acquireId: string;\n\n\t// The actual value\n\treadonly value: T;\n}\n\n/**\n * An operation for consensus ordered collection\n */\ninterface IConsensusOrderedCollectionAddOperation<T> {\n\topName: \"add\";\n\t// serialized value\n\tvalue: string;\n\tdeserializedValue?: T;\n}\n\ninterface IConsensusOrderedCollectionAcquireOperation {\n\topName: \"acquire\";\n\t// an ID used to indicate acquired item.\n\t// Used in acquire/release/complete ops.\n\tacquireId: string;\n}\n\ninterface IConsensusOrderedCollectionCompleteOperation {\n\topName: \"complete\";\n\t// an ID used to indicate acquired item.\n\t// Used in acquire/release/complete ops.\n\tacquireId: string;\n}\n\ninterface IConsensusOrderedCollectionReleaseOperation {\n\topName: \"release\";\n\t// an ID used to indicate acquired item.\n\t// Used in acquire/release/complete ops.\n\tacquireId: string;\n}\n\ntype IConsensusOrderedCollectionOperation<T> =\n\t| IConsensusOrderedCollectionAddOperation<T>\n\t| IConsensusOrderedCollectionAcquireOperation\n\t| IConsensusOrderedCollectionCompleteOperation\n\t| IConsensusOrderedCollectionReleaseOperation;\n\n/** The type of the resolve function to call after the local operation is ack'd */\ntype PendingResolve<T> = (value: IConsensusOrderedCollectionValue<T> | undefined) => void;\n\n/**\n * For job tracking, we need to keep track of which client \"owns\" a given value.\n * Key is the acquireId from when it was acquired\n * Value is the acquired value, and the id of the client who acquired it, or undefined for unattached client\n */\ntype JobTrackingInfo<T> = Map<string, { value: T; clientId: string | undefined }>;\nconst idForLocalUnattachedClient = undefined;\n\n/**\n * Implementation of a consensus collection shared object\n *\n * Implements the shared object's communication, and the semantics around the\n * release/complete mechanism following acquire.\n *\n * Generally not used directly. A derived type will pass in a backing data type\n * IOrderedCollection that will define the deterministic add/acquire order and snapshot ability.\n * @legacy\n * @alpha\n */\nexport class ConsensusOrderedCollection<T = any>\n\textends SharedObject<IConsensusOrderedCollectionEvents<T>>\n\timplements IConsensusOrderedCollection<T>\n{\n\t/**\n\t * The set of values that have been acquired but not yet completed or released\n\t */\n\tprivate jobTracking: JobTrackingInfo<T> = new Map();\n\n\t/**\n\t * Constructs a new consensus collection. If the object is non-local an id and service interfaces will\n\t * be provided\n\t */\n\tprotected constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\tprivate readonly data: IOrderedCollection<T>,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_consensusOrderedCollection_\");\n\n\t\t// We can't simply call this.removeClient(this.runtime.clientId) in on runtime disconnected,\n\t\t// because other clients may disconnect concurrently.\n\t\t// Disconnect order matters because it defines the order items go back to the queue.\n\t\t// So we put items back to queue only when we process our own removeMember event.\n\t\truntime.getQuorum().on(\"removeMember\", (clientId: string) => {\n\t\t\tassert(!!clientId, 0x067 /* \"Missing clientId for removal!\" */);\n\t\t\tthis.removeClient(clientId);\n\t\t});\n\t}\n\n\t/**\n\t * Add a value to the consensus collection.\n\t */\n\tpublic async add(value: T): Promise<void> {\n\t\tconst valueSer = this.serializeValue(value, this.serializer);\n\n\t\tif (!this.isAttached()) {\n\t\t\t// For the case where this is not attached yet, explicitly JSON\n\t\t\t// clone the value to match the behavior of going thru the wire.\n\t\t\tconst addValue = this.deserializeValue(valueSer, this.serializer) as T;\n\t\t\tthis.addCore(addValue);\n\t\t\treturn;\n\t\t}\n\n\t\tawait this.submit<IConsensusOrderedCollectionAddOperation<T>>({\n\t\t\topName: \"add\",\n\t\t\tvalue: valueSer,\n\t\t\tdeserializedValue: value,\n\t\t});\n\t}\n\n\t/**\n\t * Remove a value from the consensus collection. If the collection is empty, returns false.\n\t * Otherwise calls callback with the value\n\t */\n\tpublic async acquire(callback: ConsensusCallback<T>): Promise<boolean> {\n\t\tconst result = await this.acquireInternal();\n\t\tif (result === undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst res = await callback(result.value);\n\n\t\tswitch (res) {\n\t\t\tcase ConsensusResult.Complete:\n\t\t\t\tawait this.complete(result.acquireId);\n\t\t\t\tbreak;\n\t\t\tcase ConsensusResult.Release:\n\t\t\t\tthis.release(result.acquireId);\n\t\t\t\tthis.emit(\"localRelease\", result.value, true /* intentional */);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tunreachableCase(res);\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Wait for a value to be available and acquire it from the consensus collection\n\t */\n\tpublic async waitAndAcquire(callback: ConsensusCallback<T>): Promise<void> {\n\t\tdo {\n\t\t\tif (this.data.size() === 0) {\n\t\t\t\t// Wait for new entry before trying to acquire again\n\t\t\t\tawait this.newAckBasedPromise<T>((resolve) => {\n\t\t\t\t\tthis.once(\"add\", resolve);\n\t\t\t\t});\n\t\t\t}\n\t\t} while (!(await this.acquire(callback)));\n\t}\n\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\t// If we are transitioning from unattached to attached mode,\n\t\t// then we are losing all checked out work!\n\t\tthis.removeClient(idForLocalUnattachedClient);\n\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tlet blobContent = this.serializeValue(this.data.asArray(), serializer);\n\t\tbuilder.addBlob(snapshotFileNameData, blobContent);\n\t\tblobContent = this.serializeValue(Array.from(this.jobTracking.entries()), serializer);\n\t\tbuilder.addBlob(snapshotFileNameTracking, blobContent);\n\t\treturn builder.getSummaryTree();\n\t}\n\n\tprotected isActive() {\n\t\treturn this.runtime.connected && this.deltaManager.active;\n\t}\n\n\tprotected async complete(acquireId: string) {\n\t\tif (!this.isAttached()) {\n\t\t\tthis.completeCore(acquireId);\n\t\t\treturn;\n\t\t}\n\n\t\t// if not active, this item already was released to queue (as observed by other clients)\n\t\tif (this.isActive()) {\n\t\t\tawait this.submit<IConsensusOrderedCollectionCompleteOperation>({\n\t\t\t\topName: \"complete\",\n\t\t\t\tacquireId,\n\t\t\t});\n\t\t}\n\t}\n\n\tprotected completeCore(acquireId: string) {\n\t\t// Note: item may be no longer in jobTracking and returned back to queue!\n\t\tconst rec = this.jobTracking.get(acquireId);\n\t\tif (rec !== undefined) {\n\t\t\tthis.jobTracking.delete(acquireId);\n\t\t\tthis.emit(\"complete\", rec.value);\n\t\t}\n\t}\n\n\tprotected release(acquireId: string) {\n\t\tif (!this.isAttached()) {\n\t\t\tthis.releaseCore(acquireId);\n\t\t\treturn;\n\t\t}\n\n\t\t// if not active, this item already was released to queue (as observed by other clients)\n\t\tif (this.isActive()) {\n\t\t\tthis.submit<IConsensusOrderedCollectionReleaseOperation>({\n\t\t\t\topName: \"release\",\n\t\t\t\tacquireId,\n\t\t\t}).catch((error) => {\n\t\t\t\tthis.logger.sendErrorEvent({ eventName: \"ConsensusQueue_release\" }, error);\n\t\t\t});\n\t\t}\n\t}\n\n\tprotected releaseCore(acquireId: string) {\n\t\t// Note: item may be no longer in jobTracking and returned back to queue!\n\t\tconst rec = this.jobTracking.get(acquireId);\n\t\tif (rec !== undefined) {\n\t\t\tthis.jobTracking.delete(acquireId);\n\t\t\tthis.data.add(rec.value);\n\t\t\tthis.emit(\"add\", rec.value, false /* newlyAdded */);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tassert(\n\t\t\tthis.jobTracking.size === 0,\n\t\t\t0x068 /* \"On consensusOrderedCollection load, job tracking size > 0\" */,\n\t\t);\n\t\tconst blob = await storage.readBlob(snapshotFileNameTracking);\n\t\tconst rawContentTracking = bufferToString(blob, \"utf8\");\n\t\tconst content = this.deserializeValue(rawContentTracking, this.serializer);\n\t\tthis.jobTracking = new Map(content) as JobTrackingInfo<T>;\n\n\t\tassert(\n\t\t\tthis.data.size() === 0,\n\t\t\t0x069 /* \"On consensusOrderedCollection load, data size > 0\" */,\n\t\t);\n\t\tconst blob2 = await storage.readBlob(snapshotFileNameData);\n\t\tconst rawContentData = bufferToString(blob2, \"utf8\");\n\t\tconst content2 = this.deserializeValue(rawContentData, this.serializer) as T[];\n\t\tthis.data.loadFrom(content2);\n\t}\n\n\tprotected onDisconnect() {\n\t\tfor (const [, { value, clientId }] of this.jobTracking) {\n\t\t\tif (clientId === this.runtime.clientId) {\n\t\t\t\tthis.emit(\"localRelease\", value, false /* intentional */);\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t) {\n\t\tif (message.type === MessageType.Operation) {\n\t\t\tconst op = message.contents as IConsensusOrderedCollectionOperation<T>;\n\t\t\tlet value: IConsensusOrderedCollectionValue<T> | undefined;\n\t\t\tswitch (op.opName) {\n\t\t\t\tcase \"add\":\n\t\t\t\t\tif (op.deserializedValue !== undefined) {\n\t\t\t\t\t\tthis.addCore(op.deserializedValue);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.addCore(this.deserializeValue(op.value, this.serializer) as T);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase \"acquire\":\n\t\t\t\t\tvalue = this.acquireCore(op.acquireId, message.clientId ?? undefined);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase \"complete\":\n\t\t\t\t\tthis.completeCore(op.acquireId);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase \"release\":\n\t\t\t\t\tthis.releaseCore(op.acquireId);\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\t\t\t\t\tunreachableCase(op);\n\t\t\t}\n\t\t\tif (local) {\n\t\t\t\t// Resolve the pending promise for this operation now that we have received an ack for it.\n\t\t\t\tconst resolve = localOpMetadata as PendingResolve<T>;\n\t\t\t\tresolve(value);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async submit<TMessage extends IConsensusOrderedCollectionOperation<T>>(\n\t\tmessage: TMessage,\n\t): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n\t\tassert(this.isAttached(), 0x06a /* \"Trying to submit message while detached!\" */);\n\n\t\treturn this.newAckBasedPromise<IConsensusOrderedCollectionValue<T> | undefined>(\n\t\t\t(resolve) => {\n\t\t\t\t// Send the resolve function as the localOpMetadata. This will be provided back to us when the\n\t\t\t\t// op is ack'd.\n\t\t\t\tthis.submitLocalMessage(message, resolve);\n\t\t\t\t// If we fail due to runtime being disposed, it's better to return undefined then unhandled exception.\n\t\t\t},\n\t\t).catch((error) => undefined);\n\t}\n\n\tprivate addCore(value: T) {\n\t\tthis.data.add(value);\n\t\tthis.emit(\"add\", value, true /* newlyAdded */);\n\t}\n\n\tprivate acquireCore(\n\t\tacquireId: string,\n\t\tclientId?: string,\n\t): IConsensusOrderedCollectionValue<T> | undefined {\n\t\tif (this.data.size() === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst value = this.data.remove();\n\n\t\tconst value2: IConsensusOrderedCollectionValue<T> = {\n\t\t\tacquireId,\n\t\t\tvalue,\n\t\t};\n\t\tthis.jobTracking.set(value2.acquireId, { value, clientId });\n\n\t\tthis.emit(\"acquire\", value, clientId);\n\t\treturn value2;\n\t}\n\n\tprivate async acquireInternal(): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n\t\tif (!this.isAttached()) {\n\t\t\t// can be undefined if queue is empty\n\t\t\treturn this.acquireCore(uuid(), idForLocalUnattachedClient);\n\t\t}\n\n\t\treturn this.submit<IConsensusOrderedCollectionAcquireOperation>({\n\t\t\topName: \"acquire\",\n\t\t\tacquireId: uuid(),\n\t\t});\n\t}\n\n\tprivate removeClient(clientIdToRemove?: string) {\n\t\tconst added: T[] = [];\n\t\tfor (const [acquireId, { value, clientId }] of this.jobTracking) {\n\t\t\tif (clientId === clientIdToRemove) {\n\t\t\t\tthis.jobTracking.delete(acquireId);\n\t\t\t\tthis.data.add(value);\n\t\t\t\tadded.push(value);\n\t\t\t}\n\t\t}\n\n\t\t// Raise all events only after all state changes are completed,\n\t\t// to guarantee same ordering of operations if collection is manipulated from events.\n\t\tadded.map((value) => this.emit(\"add\", value, false /* newlyAdded */));\n\t}\n\n\tprivate serializeValue(value, serializer: IFluidSerializer) {\n\t\treturn serializer.stringify(value, this.handle);\n\t}\n\n\tprivate deserializeValue(content: string, serializer: IFluidSerializer) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn serializer.parse(content);\n\t}\n\n\tprotected applyStashedOp(): void {\n\t\tthrow new Error(\"not implemented\");\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"consensusOrderedCollection.js","sourceRoot":"","sources":["../src/consensusOrderedCollection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA8D;AAC9D,kEAA8E;AAM9E,0EAGqD;AAErD,qEAA4E;AAC5E,0EAA6F;AAC7F,+BAAkC;AAElC,mDAMyB;AAEzB,MAAM,oBAAoB,GAAG,QAAQ,CAAC;AACtC,MAAM,wBAAwB,GAAG,aAAa,CAAC;AA2D/C,MAAM,0BAA0B,GAAG,SAAS,CAAC;AAE7C;;;;;;;;;;GAUG;AAEH,8DAA8D;AAC9D,8DAA8D;AAC9D,MAAa,0BACZ,SAAQ,uBAAkD;IAQ1D;;;OAGG;IACH,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B,EACb,IAA2B;QAE5C,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,mCAAmC,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,CAAC;YACnB,CAAC;QACF,CAAC;QAED,+DAA+D;QAC/D,qFAAqF;QACrF,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC;IACvE,CAAC;IAEO,cAAc,CAAC,KAAK,EAAE,UAA4B;QACzD,OAAO,UAAU,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACjD,CAAC;IAEO,gBAAgB,CAAC,OAAe,EAAE,UAA4B;QACrE,OAAO,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAES,cAAc;QACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;CACD;AA/TD,gEA+TC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport {\n\tMessageType,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport { IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base/internal\";\nimport { v4 as uuid } from \"uuid\";\n\nimport {\n\tConsensusCallback,\n\tConsensusResult,\n\tIConsensusOrderedCollection,\n\tIConsensusOrderedCollectionEvents,\n\tIOrderedCollection,\n} from \"./interfaces.js\";\n\nconst snapshotFileNameData = \"header\";\nconst snapshotFileNameTracking = \"jobTracking\";\n\ninterface IConsensusOrderedCollectionValue<T> {\n\t// an ID used to indicate acquired item.\n\t// Used in acquire/release/complete ops.\n\treadonly acquireId: string;\n\n\t// The actual value\n\treadonly value: T;\n}\n\n/**\n * An operation for consensus ordered collection\n */\ninterface IConsensusOrderedCollectionAddOperation<T> {\n\topName: \"add\";\n\t// serialized value\n\tvalue: string;\n\tdeserializedValue?: T;\n}\n\ninterface IConsensusOrderedCollectionAcquireOperation {\n\topName: \"acquire\";\n\t// an ID used to indicate acquired item.\n\t// Used in acquire/release/complete ops.\n\tacquireId: string;\n}\n\ninterface IConsensusOrderedCollectionCompleteOperation {\n\topName: \"complete\";\n\t// an ID used to indicate acquired item.\n\t// Used in acquire/release/complete ops.\n\tacquireId: string;\n}\n\ninterface IConsensusOrderedCollectionReleaseOperation {\n\topName: \"release\";\n\t// an ID used to indicate acquired item.\n\t// Used in acquire/release/complete ops.\n\tacquireId: string;\n}\n\ntype IConsensusOrderedCollectionOperation<T> =\n\t| IConsensusOrderedCollectionAddOperation<T>\n\t| IConsensusOrderedCollectionAcquireOperation\n\t| IConsensusOrderedCollectionCompleteOperation\n\t| IConsensusOrderedCollectionReleaseOperation;\n\n/**\n * The type of the resolve function to call after the local operation is acknowledged.\n */\ntype PendingResolve<T> = (value: IConsensusOrderedCollectionValue<T> | undefined) => void;\n\n/**\n * For job tracking, we need to keep track of which client \"owns\" a given value.\n * Key is the acquireId from when it was acquired\n * Value is the acquired value, and the id of the client who acquired it, or undefined for unattached client\n */\ntype JobTrackingInfo<T> = Map<string, { value: T; clientId: string | undefined }>;\nconst idForLocalUnattachedClient = undefined;\n\n/**\n * Implementation of a consensus collection shared object\n *\n * Implements the shared object's communication, and the semantics around the\n * release/complete mechanism following acquire.\n *\n * Generally not used directly. A derived type will pass in a backing data type\n * IOrderedCollection that will define the deterministic add/acquire order and snapshot ability.\n * @legacy\n * @alpha\n */\n\n// TODO: #22835 Use undefined instead of any (breaking change)\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class ConsensusOrderedCollection<T = any>\n\textends SharedObject<IConsensusOrderedCollectionEvents<T>>\n\timplements IConsensusOrderedCollection<T>\n{\n\t/**\n\t * The set of values that have been acquired but not yet completed or released\n\t */\n\tprivate jobTracking: JobTrackingInfo<T> = new Map();\n\n\t/**\n\t * Constructs a new consensus collection. If the object is non-local an id and service interfaces will\n\t * be provided\n\t */\n\tprotected constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\tprivate readonly data: IOrderedCollection<T>,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_consensusOrderedCollection_\");\n\n\t\t// We can't simply call this.removeClient(this.runtime.clientId) in on runtime disconnected,\n\t\t// because other clients may disconnect concurrently.\n\t\t// Disconnect order matters because it defines the order items go back to the queue.\n\t\t// So we put items back to queue only when we process our own removeMember event.\n\t\truntime.getQuorum().on(\"removeMember\", (clientId: string) => {\n\t\t\tassert(!!clientId, 0x067 /* \"Missing clientId for removal!\" */);\n\t\t\tthis.removeClient(clientId);\n\t\t});\n\t}\n\n\t/**\n\t * Add a value to the consensus collection.\n\t */\n\tpublic async add(value: T): Promise<void> {\n\t\tconst valueSer = this.serializeValue(value, this.serializer);\n\n\t\tif (!this.isAttached()) {\n\t\t\t// For the case where this is not attached yet, explicitly JSON\n\t\t\t// clone the value to match the behavior of going thru the wire.\n\t\t\tconst addValue = this.deserializeValue(valueSer, this.serializer) as T;\n\t\t\tthis.addCore(addValue);\n\t\t\treturn;\n\t\t}\n\n\t\tawait this.submit<IConsensusOrderedCollectionAddOperation<T>>({\n\t\t\topName: \"add\",\n\t\t\tvalue: valueSer,\n\t\t\tdeserializedValue: value,\n\t\t});\n\t}\n\n\t/**\n\t * Remove a value from the consensus collection. If the collection is empty, returns false.\n\t * Otherwise calls callback with the value\n\t */\n\tpublic async acquire(callback: ConsensusCallback<T>): Promise<boolean> {\n\t\tconst result = await this.acquireInternal();\n\t\tif (result === undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst res = await callback(result.value);\n\n\t\tswitch (res) {\n\t\t\tcase ConsensusResult.Complete: {\n\t\t\t\tawait this.complete(result.acquireId);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase ConsensusResult.Release: {\n\t\t\t\tthis.release(result.acquireId);\n\t\t\t\tthis.emit(\"localRelease\", result.value, true /* intentional */);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tunreachableCase(res);\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Wait for a value to be available and acquire it from the consensus collection\n\t */\n\tpublic async waitAndAcquire(callback: ConsensusCallback<T>): Promise<void> {\n\t\tdo {\n\t\t\tif (this.data.size() === 0) {\n\t\t\t\t// Wait for new entry before trying to acquire again\n\t\t\t\tawait this.newAckBasedPromise<T>((resolve) => {\n\t\t\t\t\tthis.once(\"add\", resolve);\n\t\t\t\t});\n\t\t\t}\n\t\t} while (!(await this.acquire(callback)));\n\t}\n\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\t// If we are transitioning from unattached to attached mode,\n\t\t// then we are losing all checked out work!\n\t\tthis.removeClient(idForLocalUnattachedClient);\n\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tlet blobContent = this.serializeValue(this.data.asArray(), serializer);\n\t\tbuilder.addBlob(snapshotFileNameData, blobContent);\n\t\tblobContent = this.serializeValue([...this.jobTracking.entries()], serializer);\n\t\tbuilder.addBlob(snapshotFileNameTracking, blobContent);\n\t\treturn builder.getSummaryTree();\n\t}\n\n\tprotected isActive(): boolean {\n\t\treturn this.runtime.connected && this.deltaManager.active;\n\t}\n\n\tprotected async complete(acquireId: string): Promise<void> {\n\t\tif (!this.isAttached()) {\n\t\t\tthis.completeCore(acquireId);\n\t\t\treturn;\n\t\t}\n\n\t\t// if not active, this item already was released to queue (as observed by other clients)\n\t\tif (this.isActive()) {\n\t\t\tawait this.submit<IConsensusOrderedCollectionCompleteOperation>({\n\t\t\t\topName: \"complete\",\n\t\t\t\tacquireId,\n\t\t\t});\n\t\t}\n\t}\n\n\tprotected completeCore(acquireId: string): void {\n\t\t// Note: item may be no longer in jobTracking and returned back to queue!\n\t\tconst rec = this.jobTracking.get(acquireId);\n\t\tif (rec !== undefined) {\n\t\t\tthis.jobTracking.delete(acquireId);\n\t\t\tthis.emit(\"complete\", rec.value);\n\t\t}\n\t}\n\n\tprotected release(acquireId: string): void {\n\t\tif (!this.isAttached()) {\n\t\t\tthis.releaseCore(acquireId);\n\t\t\treturn;\n\t\t}\n\n\t\t// if not active, this item already was released to queue (as observed by other clients)\n\t\tif (this.isActive()) {\n\t\t\tthis.submit<IConsensusOrderedCollectionReleaseOperation>({\n\t\t\t\topName: \"release\",\n\t\t\t\tacquireId,\n\t\t\t}).catch((error) => {\n\t\t\t\tthis.logger.sendErrorEvent({ eventName: \"ConsensusQueue_release\" }, error);\n\t\t\t});\n\t\t}\n\t}\n\n\tprotected releaseCore(acquireId: string): void {\n\t\t// Note: item may be no longer in jobTracking and returned back to queue!\n\t\tconst rec = this.jobTracking.get(acquireId);\n\t\tif (rec !== undefined) {\n\t\t\tthis.jobTracking.delete(acquireId);\n\t\t\tthis.data.add(rec.value);\n\t\t\tthis.emit(\"add\", rec.value, false /* newlyAdded */);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tassert(\n\t\t\tthis.jobTracking.size === 0,\n\t\t\t0x068 /* \"On consensusOrderedCollection load, job tracking size > 0\" */,\n\t\t);\n\t\tconst blob = await storage.readBlob(snapshotFileNameTracking);\n\t\tconst rawContentTracking = bufferToString(blob, \"utf8\");\n\t\tconst content = this.deserializeValue(rawContentTracking, this.serializer);\n\t\tthis.jobTracking = new Map(\n\t\t\tcontent as Iterable<[string, { value: T; clientId: string | undefined }]>,\n\t\t);\n\n\t\tassert(\n\t\t\tthis.data.size() === 0,\n\t\t\t0x069 /* \"On consensusOrderedCollection load, data size > 0\" */,\n\t\t);\n\t\tconst blob2 = await storage.readBlob(snapshotFileNameData);\n\t\tconst rawContentData = bufferToString(blob2, \"utf8\");\n\t\tconst content2 = this.deserializeValue(rawContentData, this.serializer) as T[];\n\t\tthis.data.loadFrom(content2);\n\t}\n\n\tprotected onDisconnect(): void {\n\t\tfor (const [, { value, clientId }] of this.jobTracking) {\n\t\t\tif (clientId === this.runtime.clientId) {\n\t\t\t\tthis.emit(\"localRelease\", value, false /* intentional */);\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t): void {\n\t\tif (message.type === MessageType.Operation) {\n\t\t\tconst op = message.contents as IConsensusOrderedCollectionOperation<T>;\n\t\t\tlet value: IConsensusOrderedCollectionValue<T> | undefined;\n\t\t\tswitch (op.opName) {\n\t\t\t\tcase \"add\": {\n\t\t\t\t\tif (op.deserializedValue === undefined) {\n\t\t\t\t\t\tthis.addCore(this.deserializeValue(op.value, this.serializer) as T);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.addCore(op.deserializedValue);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase \"acquire\": {\n\t\t\t\t\tvalue = this.acquireCore(op.acquireId, message.clientId ?? undefined);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase \"complete\": {\n\t\t\t\t\tthis.completeCore(op.acquireId);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase \"release\": {\n\t\t\t\t\tthis.releaseCore(op.acquireId);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\tunreachableCase(op);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (local) {\n\t\t\t\t// Resolve the pending promise for this operation now that we have received an ack for it.\n\t\t\t\tconst resolve = localOpMetadata as PendingResolve<T>;\n\t\t\t\tresolve(value);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async submit<TMessage extends IConsensusOrderedCollectionOperation<T>>(\n\t\tmessage: TMessage,\n\t): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n\t\tassert(this.isAttached(), 0x06a /* \"Trying to submit message while detached!\" */);\n\n\t\treturn this.newAckBasedPromise<IConsensusOrderedCollectionValue<T> | undefined>(\n\t\t\t(resolve) => {\n\t\t\t\t// Send the resolve function as the localOpMetadata. This will be provided back to us when the\n\t\t\t\t// op is ack'd.\n\t\t\t\tthis.submitLocalMessage(message, resolve);\n\t\t\t\t// If we fail due to runtime being disposed, it's better to return undefined then unhandled exception.\n\t\t\t},\n\t\t).catch((error) => undefined);\n\t}\n\n\tprivate addCore(value: T): void {\n\t\tthis.data.add(value);\n\t\tthis.emit(\"add\", value, true /* newlyAdded */);\n\t}\n\n\tprivate acquireCore(\n\t\tacquireId: string,\n\t\tclientId?: string,\n\t): IConsensusOrderedCollectionValue<T> | undefined {\n\t\tif (this.data.size() === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst value = this.data.remove();\n\n\t\tconst value2: IConsensusOrderedCollectionValue<T> = {\n\t\t\tacquireId,\n\t\t\tvalue,\n\t\t};\n\t\tthis.jobTracking.set(value2.acquireId, { value, clientId });\n\n\t\tthis.emit(\"acquire\", value, clientId);\n\t\treturn value2;\n\t}\n\n\tprivate async acquireInternal(): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n\t\tif (!this.isAttached()) {\n\t\t\t// can be undefined if queue is empty\n\t\t\treturn this.acquireCore(uuid(), idForLocalUnattachedClient);\n\t\t}\n\n\t\treturn this.submit<IConsensusOrderedCollectionAcquireOperation>({\n\t\t\topName: \"acquire\",\n\t\t\tacquireId: uuid(),\n\t\t});\n\t}\n\n\tprivate removeClient(clientIdToRemove?: string): void {\n\t\tconst added: T[] = [];\n\t\tfor (const [acquireId, { value, clientId }] of this.jobTracking) {\n\t\t\tif (clientId === clientIdToRemove) {\n\t\t\t\tthis.jobTracking.delete(acquireId);\n\t\t\t\tthis.data.add(value);\n\t\t\t\tadded.push(value);\n\t\t\t}\n\t\t}\n\n\t\t// Raise all events only after all state changes are completed,\n\t\t// to guarantee same ordering of operations if collection is manipulated from events.\n\t\tadded.map((value) => this.emit(\"add\", value, false /* newlyAdded */));\n\t}\n\n\tprivate serializeValue(value, serializer: IFluidSerializer): string {\n\t\treturn serializer.stringify(value, this.handle);\n\t}\n\n\tprivate deserializeValue(content: string, serializer: IFluidSerializer): unknown {\n\t\treturn serializer.parse(content);\n\t}\n\n\tprotected applyStashedOp(): void {\n\t\tthrow new Error(\"not implemented\");\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consensusOrderedCollectionFactory.d.ts","sourceRoot":"","sources":["../src/consensusOrderedCollectionFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,MAAM,gDAAgD,CAAC;AAGxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACN,2BAA2B,EAC3B,kCAAkC,EAClC,MAAM,iBAAiB,CAAC;AAGzB;;;;GAIG;AACH,qBAAa,qBAAsB,YAAW,kCAAkC;IAC/E,OAAc,IAAI,SAAuD;IAEzE,gBAAuB,UAAU,EAAE,kBAAkB,CAInD;IAEF,IAAW,IAAI,
|
|
1
|
+
{"version":3,"file":"consensusOrderedCollectionFactory.d.ts","sourceRoot":"","sources":["../src/consensusOrderedCollectionFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,MAAM,gDAAgD,CAAC;AAGxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACN,2BAA2B,EAC3B,kCAAkC,EAClC,MAAM,iBAAiB,CAAC;AAGzB;;;;GAIG;AACH,qBAAa,qBAAsB,YAAW,kCAAkC;IAC/E,OAAc,IAAI,SAAuD;IAEzE,gBAAuB,UAAU,EAAE,kBAAkB,CAInD;IAEF,IAAW,IAAI,IAAI,MAAM,CAExB;IAED,IAAW,UAAU,IAAI,kBAAkB,CAE1C;IAED;;OAEG;IACU,IAAI,CAChB,OAAO,EAAE,sBAAsB,EAC/B,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,gBAAgB,EAC1B,UAAU,EAAE,kBAAkB,GAC5B,OAAO,CAAC,2BAA2B,CAAC;IAMhC,MAAM,CAAC,QAAQ,EAAE,sBAAsB,EAAE,EAAE,EAAE,MAAM,GAAG,2BAA2B;CAKxF;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,sNAAgD,CAAC;AAE5E;;;;GAIG;AAGH,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,GAAG,IAAI,mBAAmB,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consensusOrderedCollectionFactory.js","sourceRoot":"","sources":["../src/consensusOrderedCollectionFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,0EAAqF;AAErF,2DAA0D;AAK1D,2DAAiD;AAEjD;;;;GAIG;AACH,MAAa,qBAAqB;IASjC,IAAW,IAAI;QACd,OAAO,qBAAqB,CAAC,IAAI,CAAC;IACnC,CAAC;IAED,IAAW,UAAU;QACpB,OAAO,qBAAqB,CAAC,UAAU,CAAC;IACzC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAI,CAChB,OAA+B,EAC/B,EAAU,EACV,QAA0B,EAC1B,UAA8B;QAE9B,MAAM,UAAU,GAAG,IAAI,uCAAmB,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QACpE,MAAM,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChC,OAAO,UAAU,CAAC;IACnB,CAAC;IAEM,MAAM,CAAC,QAAgC,EAAE,EAAU;QACzD,MAAM,UAAU,GAAG,IAAI,uCAAmB,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAC1E,UAAU,CAAC,eAAe,EAAE,CAAC;QAC7B,OAAO,UAAU,CAAC;IACnB,CAAC;;AAnCF,sDAoCC;AAnCc,0BAAI,GAAG,mDAAmD,CAAC;AAElD,gCAAU,GAAuB;IACvD,IAAI,EAAE,qBAAqB,CAAC,IAAI;IAChC,qBAAqB,EAAE,KAAK;IAC5B,cAAc,EAAE,8BAAU;CAC1B,CAAC;AA+BH;;;;GAIG;AACU,QAAA,cAAc,GAAG,IAAA,iCAAsB,EAAC,qBAAqB,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelServices,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { createSharedObjectKind } from \"@fluidframework/shared-object-base/internal\";\n\nimport { ConsensusQueueClass } from \"./consensusQueue.js\";\nimport {\n\tIConsensusOrderedCollection,\n\tIConsensusOrderedCollectionFactory,\n} from \"./interfaces.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\n\n/**\n * The factory that defines the consensus queue\n *\n * @internal\n */\nexport class ConsensusQueueFactory implements IConsensusOrderedCollectionFactory {\n\tpublic static Type = \"https://graph.microsoft.com/types/consensus-queue\";\n\n\tpublic static readonly Attributes: IChannelAttributes = {\n\t\ttype: ConsensusQueueFactory.Type,\n\t\tsnapshotFormatVersion: \"0.1\",\n\t\tpackageVersion: pkgVersion,\n\t};\n\n\tpublic get type() {\n\t\treturn ConsensusQueueFactory.Type;\n\t}\n\n\tpublic get attributes() {\n\t\treturn ConsensusQueueFactory.Attributes;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}\n\t */\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tid: string,\n\t\tservices: IChannelServices,\n\t\tattributes: IChannelAttributes,\n\t): Promise<IConsensusOrderedCollection> {\n\t\tconst collection = new ConsensusQueueClass(id, runtime, attributes);\n\t\tawait collection.load(services);\n\t\treturn collection;\n\t}\n\n\tpublic create(document: IFluidDataStoreRuntime, id: string): IConsensusOrderedCollection {\n\t\tconst collection = new ConsensusQueueClass(id, document, this.attributes);\n\t\tcollection.initializeLocal();\n\t\treturn collection;\n\t}\n}\n\n/**\n * {@inheritDoc ConsensusQueueClass}\n * @legacy\n * @alpha\n */\nexport const ConsensusQueue = createSharedObjectKind(ConsensusQueueFactory);\n\n/**\n * {@inheritDoc ConsensusQueueClass}\n * @legacy\n * @alpha\n */\nexport type ConsensusQueue<T = any> = ConsensusQueueClass<T>;\n"]}
|
|
1
|
+
{"version":3,"file":"consensusOrderedCollectionFactory.js","sourceRoot":"","sources":["../src/consensusOrderedCollectionFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,0EAAqF;AAErF,2DAA0D;AAK1D,2DAAiD;AAEjD;;;;GAIG;AACH,MAAa,qBAAqB;IASjC,IAAW,IAAI;QACd,OAAO,qBAAqB,CAAC,IAAI,CAAC;IACnC,CAAC;IAED,IAAW,UAAU;QACpB,OAAO,qBAAqB,CAAC,UAAU,CAAC;IACzC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAI,CAChB,OAA+B,EAC/B,EAAU,EACV,QAA0B,EAC1B,UAA8B;QAE9B,MAAM,UAAU,GAAG,IAAI,uCAAmB,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QACpE,MAAM,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChC,OAAO,UAAU,CAAC;IACnB,CAAC;IAEM,MAAM,CAAC,QAAgC,EAAE,EAAU;QACzD,MAAM,UAAU,GAAG,IAAI,uCAAmB,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAC1E,UAAU,CAAC,eAAe,EAAE,CAAC;QAC7B,OAAO,UAAU,CAAC;IACnB,CAAC;;AAnCF,sDAoCC;AAnCc,0BAAI,GAAG,mDAAmD,CAAC;AAElD,gCAAU,GAAuB;IACvD,IAAI,EAAE,qBAAqB,CAAC,IAAI;IAChC,qBAAqB,EAAE,KAAK;IAC5B,cAAc,EAAE,8BAAU;CAC1B,CAAC;AA+BH;;;;GAIG;AACU,QAAA,cAAc,GAAG,IAAA,iCAAsB,EAAC,qBAAqB,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelServices,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { createSharedObjectKind } from \"@fluidframework/shared-object-base/internal\";\n\nimport { ConsensusQueueClass } from \"./consensusQueue.js\";\nimport {\n\tIConsensusOrderedCollection,\n\tIConsensusOrderedCollectionFactory,\n} from \"./interfaces.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\n\n/**\n * The factory that defines the consensus queue\n *\n * @internal\n */\nexport class ConsensusQueueFactory implements IConsensusOrderedCollectionFactory {\n\tpublic static Type = \"https://graph.microsoft.com/types/consensus-queue\";\n\n\tpublic static readonly Attributes: IChannelAttributes = {\n\t\ttype: ConsensusQueueFactory.Type,\n\t\tsnapshotFormatVersion: \"0.1\",\n\t\tpackageVersion: pkgVersion,\n\t};\n\n\tpublic get type(): string {\n\t\treturn ConsensusQueueFactory.Type;\n\t}\n\n\tpublic get attributes(): IChannelAttributes {\n\t\treturn ConsensusQueueFactory.Attributes;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}\n\t */\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tid: string,\n\t\tservices: IChannelServices,\n\t\tattributes: IChannelAttributes,\n\t): Promise<IConsensusOrderedCollection> {\n\t\tconst collection = new ConsensusQueueClass(id, runtime, attributes);\n\t\tawait collection.load(services);\n\t\treturn collection;\n\t}\n\n\tpublic create(document: IFluidDataStoreRuntime, id: string): IConsensusOrderedCollection {\n\t\tconst collection = new ConsensusQueueClass(id, document, this.attributes);\n\t\tcollection.initializeLocal();\n\t\treturn collection;\n\t}\n}\n\n/**\n * {@inheritDoc ConsensusQueueClass}\n * @legacy\n * @alpha\n */\nexport const ConsensusQueue = createSharedObjectKind(ConsensusQueueFactory);\n\n/**\n * {@inheritDoc ConsensusQueueClass}\n * @legacy\n * @alpha\n */\n// TODO: #22835 Use undefined instead of any (breaking change)\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ConsensusQueue<T = any> = ConsensusQueueClass<T>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consensusQueue.d.ts","sourceRoot":"","sources":["../src/consensusQueue.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,MAAM,gDAAgD,CAAC;AAExD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAoB7E;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"consensusQueue.d.ts","sourceRoot":"","sources":["../src/consensusQueue.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,MAAM,gDAAgD,CAAC;AAExD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAoB7E;;;;;;GAMG;AAGH,qBAAa,mBAAmB,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,0BAA0B,CAAC,CAAC,CAAC;IAC9E;;;OAGG;gBAEF,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,sBAAsB,EAC/B,UAAU,EAAE,kBAAkB;CAI/B"}
|
package/dist/consensusQueue.js
CHANGED
|
@@ -28,6 +28,8 @@ class SnapshotableQueue extends snapshotableArray_js_1.SnapshotableArray {
|
|
|
28
28
|
* @legacy
|
|
29
29
|
* @alpha
|
|
30
30
|
*/
|
|
31
|
+
// TODO: #22835 Use undefined instead of any (breaking change)
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
33
|
class ConsensusQueueClass extends consensusOrderedCollection_js_1.ConsensusOrderedCollection {
|
|
32
34
|
/**
|
|
33
35
|
* Constructs a new consensus queue. If the object is non-local an id and service interfaces will
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consensusQueue.js","sourceRoot":"","sources":["../src/consensusQueue.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,mFAA6E;AAE7E,iEAA2D;AAE3D;;GAEG;AACH,MAAM,iBAAqB,SAAQ,wCAAoB;IAC/C,GAAG,CAAC,KAAQ;QAClB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAEM,MAAM;QACZ,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,EAAO,CAAC;IAC/B,CAAC;CACD;AAED;;;;;;GAMG;AACH,MAAa,mBAA6B,SAAQ,0DAA6B;IAC9E;;;OAGG;IACH,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B;QAE9B,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,iBAAiB,EAAK,CAAC,CAAC;IAC5D,CAAC;CACD;AAZD,kDAYC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n} from \"@fluidframework/datastore-definitions/internal\";\n\nimport { ConsensusOrderedCollection } from \"./consensusOrderedCollection.js\";\nimport { IOrderedCollection } from \"./interfaces.js\";\nimport { SnapshotableArray } from \"./snapshotableArray.js\";\n\n/**\n * An JS array based queue implementation that is the backing data structure for ConsensusQueue\n */\nclass SnapshotableQueue<T> extends SnapshotableArray<T> implements IOrderedCollection<T> {\n\tpublic add(value: T) {\n\t\tthis.data.push(value);\n\t}\n\n\tpublic remove(): T {\n\t\tif (this.size() === 0) {\n\t\t\tthrow new Error(\"SnapshotableQueue is empty\");\n\t\t}\n\t\treturn this.data.shift() as T;\n\t}\n}\n\n/**\n * Implementation of a consensus stack\n *\n * An derived type of ConsensusOrderedCollection with a queue as the backing data and order.\n * @legacy\n * @alpha\n */\nexport class ConsensusQueueClass<T = any> extends ConsensusOrderedCollection<T> {\n\t/**\n\t * Constructs a new consensus queue. If the object is non-local an id and service interfaces will\n\t * be provided\n\t */\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, new SnapshotableQueue<T>());\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"consensusQueue.js","sourceRoot":"","sources":["../src/consensusQueue.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,mFAA6E;AAE7E,iEAA2D;AAE3D;;GAEG;AACH,MAAM,iBAAqB,SAAQ,wCAAoB;IAC/C,GAAG,CAAC,KAAQ;QAClB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAEM,MAAM;QACZ,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,EAAO,CAAC;IAC/B,CAAC;CACD;AAED;;;;;;GAMG;AACH,8DAA8D;AAC9D,8DAA8D;AAC9D,MAAa,mBAA6B,SAAQ,0DAA6B;IAC9E;;;OAGG;IACH,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B;QAE9B,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,iBAAiB,EAAK,CAAC,CAAC;IAC5D,CAAC;CACD;AAZD,kDAYC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n} from \"@fluidframework/datastore-definitions/internal\";\n\nimport { ConsensusOrderedCollection } from \"./consensusOrderedCollection.js\";\nimport { IOrderedCollection } from \"./interfaces.js\";\nimport { SnapshotableArray } from \"./snapshotableArray.js\";\n\n/**\n * An JS array based queue implementation that is the backing data structure for ConsensusQueue\n */\nclass SnapshotableQueue<T> extends SnapshotableArray<T> implements IOrderedCollection<T> {\n\tpublic add(value: T): void {\n\t\tthis.data.push(value);\n\t}\n\n\tpublic remove(): T {\n\t\tif (this.size() === 0) {\n\t\t\tthrow new Error(\"SnapshotableQueue is empty\");\n\t\t}\n\t\treturn this.data.shift() as T;\n\t}\n}\n\n/**\n * Implementation of a consensus stack\n *\n * An derived type of ConsensusOrderedCollection with a queue as the backing data and order.\n * @legacy\n * @alpha\n */\n// TODO: #22835 Use undefined instead of any (breaking change)\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class ConsensusQueueClass<T = any> extends ConsensusOrderedCollection<T> {\n\t/**\n\t * Constructs a new consensus queue. If the object is non-local an id and service interfaces will\n\t * be provided\n\t */\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, new SnapshotableQueue<T>());\n\t}\n}\n"]}
|
package/dist/interfaces.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,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GG;;;AAaH;;;GAGG;AACH,IAAY,eAGX;AAHD,WAAY,eAAe;IAC1B,2DAAO,CAAA;IACP,6DAAQ,CAAA;AACT,CAAC,EAHW,eAAe,+BAAf,eAAe,QAG1B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIChannelAttributes,\n\tIChannelFactory,\n\tIFluidDataStoreRuntime,\n\tIChannelServices,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport {\n\tISharedObject,\n\tISharedObjectEvents,\n} from \"@fluidframework/shared-object-base/internal\";\n\n/**\n * @legacy\n * @alpha\n */\nexport enum ConsensusResult {\n\tRelease,\n\tComplete,\n}\n\n/**\n * Callback provided to acquire() and waitAndAcquire() methods.\n * @returns ConsensusResult indicating whether item was completed, or releases back to the queue.\n * @legacy\n * @alpha\n */\nexport type ConsensusCallback<T> = (value: T) => Promise<ConsensusResult>;\n\n/**\n * Consensus Ordered Collection channel factory interface\n *\n * Extends the base IChannelFactory to return a more definite type of IConsensusOrderedCollection\n * Use for the runtime to create and load distributed data structure by type name of each channel\n * @internal\n */\nexport interface IConsensusOrderedCollectionFactory extends IChannelFactory {\n\tload(\n\t\tdocument: IFluidDataStoreRuntime,\n\t\tid: string,\n\t\tservices: IChannelServices,\n\t\tattributes: IChannelAttributes,\n\t): Promise<IConsensusOrderedCollection>;\n\n\tcreate(document: IFluidDataStoreRuntime, id: string): IConsensusOrderedCollection;\n}\n\n/**\n * Events notifying about addition, acquisition, release and completion of items\n * @legacy\n * @alpha\n */\nexport interface IConsensusOrderedCollectionEvents<T> extends ISharedObjectEvents {\n\t/**\n\t * Event fires when new item is added to the queue or\n\t * an item previously acquired is returned back to a queue (including client loosing connection)\n\t * @param newlyAdded - indicates if it's newly added item of previously acquired item\n\t */\n\t(event: \"add\", listener: (value: T, newlyAdded: boolean) => void): this;\n\t/**\n\t * Event fires when a client acquired an item\n\t * Fires both for locally acquired items, as well as items acquired by remote clients\n\t */\n\t(event: \"acquire\", listener: (value: T, clientId?: string) => void): this;\n\n\t/**\n\t * \"Complete event fires when a client completes an item.\n\t */\n\t(event: \"complete\", listener: (value: T) => void): this;\n\n\t/**\n\t * Event fires when locally acquired item is being released back to the queue.\n\t * Please note that release process is asynchronous, so it takes a while for it to happen\n\t * (\"add\" event will be fired as result of it)\n\t * @param intentional - indicates whether release was intentional (result of returning\n\t * ConsensusResult.Release from callback) or it happened as result of lost connection.\n\t */\n\t(event: \"localRelease\", listener: (value: T, intentional: boolean) => void): this;\n}\n\n/**\n * Consensus Ordered Collection interface\n *\n * An consensus ordered collection is a distributed data structure, which\n * holds a collection of JSON-able or handles, and has a\n * deterministic add/remove order.\n *\n * @remarks\n * The order the server receive the add/remove operation determines the\n * order those operation are applied to the collection. Different clients\n * issuing `add` or `acquire` operations at the same time will be sequenced.\n * The order dictates which `add` is done first, thus determining the order\n * in which it appears in the collection. It also determines which client\n * will get the first removed item, etc. All operations are asynchronous.\n * A function `waitAndAcquire` is provided to wait for and remove an entry in the collection.\n *\n * As a client acquires an item, it processes it and then returns a value (via callback)\n * indicating whether it has completed processing the item, or whether the item should be\n * released back to the collection for another client to process.\n *\n * All objects added to the collection will be cloned (via JSON).\n * They will not be references to the original input object. Thus changed to\n * the input object will not reflect the object in the collection.\n * @legacy\n * @alpha\n */\nexport interface IConsensusOrderedCollection<T = any>\n\textends ISharedObject<IConsensusOrderedCollectionEvents<T>> {\n\t/**\n\t * Adds a value to the collection\n\t */\n\tadd(value: T): Promise<void>;\n\n\t/**\n\t * Retrieves a value from the collection.\n\t * @returns Returns true (and calls callback with acquired value) if collection was not empty.\n\t * Otherwise returns false.\n\t */\n\tacquire(callback: ConsensusCallback<T>): Promise<boolean>;\n\n\t/**\n\t * Wait for a value to be available and remove it from the consensus collection\n\t * Calls callback with retrieved value.\n\t */\n\twaitAndAcquire(callback: ConsensusCallback<T>): Promise<void>;\n}\n\n/**\n * Interface for object that can be snapshoted\n *\n * TODO: move this to be use in other place\n * TODO: currently input and output is not symmetrical, can they become symmetrical?\n * @legacy\n * @alpha\n */\nexport interface ISnapshotable<T> {\n\tasArray(): T[];\n\n\tloadFrom(values: T[]): void;\n}\n\n/**\n * Ordered Collection interface\n *\n * Collection of objects that has deterministic add and remove ordering.\n * Object implementing this interface can be used as the data backing\n * for the ConsensusOrderedCollection\n * @legacy\n * @alpha\n */\nexport interface IOrderedCollection<T = any> extends ISnapshotable<T> {\n\t/**\n\t * Adds a value to the collection\n\t */\n\tadd(value: T);\n\n\t/**\n\t * Retrieves a value from the collection.\n\t */\n\tremove(): T;\n\n\t/**\n\t * Return the size of the collection\n\t */\n\tsize(): number;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAaH;;;GAGG;AACH,IAAY,eAGX;AAHD,WAAY,eAAe;IAC1B,2DAAO,CAAA;IACP,6DAAQ,CAAA;AACT,CAAC,EAHW,eAAe,+BAAf,eAAe,QAG1B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIChannelAttributes,\n\tIChannelFactory,\n\tIFluidDataStoreRuntime,\n\tIChannelServices,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport {\n\tISharedObject,\n\tISharedObjectEvents,\n} from \"@fluidframework/shared-object-base/internal\";\n\n/**\n * @legacy\n * @alpha\n */\nexport enum ConsensusResult {\n\tRelease,\n\tComplete,\n}\n\n/**\n * Callback provided to acquire() and waitAndAcquire() methods.\n * @returns ConsensusResult indicating whether item was completed, or releases back to the queue.\n * @legacy\n * @alpha\n */\nexport type ConsensusCallback<T> = (value: T) => Promise<ConsensusResult>;\n\n/**\n * Consensus Ordered Collection channel factory interface\n *\n * Extends the base IChannelFactory to return a more definite type of IConsensusOrderedCollection\n * Use for the runtime to create and load distributed data structure by type name of each channel\n * @internal\n */\nexport interface IConsensusOrderedCollectionFactory extends IChannelFactory {\n\tload(\n\t\tdocument: IFluidDataStoreRuntime,\n\t\tid: string,\n\t\tservices: IChannelServices,\n\t\tattributes: IChannelAttributes,\n\t): Promise<IConsensusOrderedCollection>;\n\n\tcreate(document: IFluidDataStoreRuntime, id: string): IConsensusOrderedCollection;\n}\n\n/**\n * Events notifying about addition, acquisition, release and completion of items\n * @legacy\n * @alpha\n */\nexport interface IConsensusOrderedCollectionEvents<T> extends ISharedObjectEvents {\n\t/**\n\t * Event fires when new item is added to the queue or\n\t * an item previously acquired is returned back to a queue (including client loosing connection)\n\t * @param newlyAdded - indicates if it's newly added item of previously acquired item\n\t */\n\t(event: \"add\", listener: (value: T, newlyAdded: boolean) => void): this;\n\t/**\n\t * Event fires when a client acquired an item\n\t * Fires both for locally acquired items, as well as items acquired by remote clients\n\t */\n\t(event: \"acquire\", listener: (value: T, clientId?: string) => void): this;\n\n\t/**\n\t * \"Complete event fires when a client completes an item.\n\t */\n\t(event: \"complete\", listener: (value: T) => void): this;\n\n\t/**\n\t * Event fires when locally acquired item is being released back to the queue.\n\t * Please note that release process is asynchronous, so it takes a while for it to happen\n\t * (\"add\" event will be fired as result of it)\n\t * @param intentional - indicates whether release was intentional (result of returning\n\t * ConsensusResult.Release from callback) or it happened as result of lost connection.\n\t */\n\t(event: \"localRelease\", listener: (value: T, intentional: boolean) => void): this;\n}\n\n/**\n * Consensus Ordered Collection interface\n *\n * An consensus ordered collection is a distributed data structure, which\n * holds a collection of JSON-able or handles, and has a\n * deterministic add/remove order.\n *\n * @remarks\n * The order the server receive the add/remove operation determines the\n * order those operation are applied to the collection. Different clients\n * issuing `add` or `acquire` operations at the same time will be sequenced.\n * The order dictates which `add` is done first, thus determining the order\n * in which it appears in the collection. It also determines which client\n * will get the first removed item, etc. All operations are asynchronous.\n * A function `waitAndAcquire` is provided to wait for and remove an entry in the collection.\n *\n * As a client acquires an item, it processes it and then returns a value (via callback)\n * indicating whether it has completed processing the item, or whether the item should be\n * released back to the collection for another client to process.\n *\n * All objects added to the collection will be cloned (via JSON).\n * They will not be references to the original input object. Thus changed to\n * the input object will not reflect the object in the collection.\n * @legacy\n * @alpha\n */\n// TODO: #22835 Use undefined instead of any (breaking change)\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface IConsensusOrderedCollection<T = any>\n\textends ISharedObject<IConsensusOrderedCollectionEvents<T>> {\n\t/**\n\t * Adds a value to the collection\n\t */\n\tadd(value: T): Promise<void>;\n\n\t/**\n\t * Retrieves a value from the collection.\n\t * @returns Returns true (and calls callback with acquired value) if collection was not empty.\n\t * Otherwise returns false.\n\t */\n\tacquire(callback: ConsensusCallback<T>): Promise<boolean>;\n\n\t/**\n\t * Wait for a value to be available and remove it from the consensus collection\n\t * Calls callback with retrieved value.\n\t */\n\twaitAndAcquire(callback: ConsensusCallback<T>): Promise<void>;\n}\n\n/**\n * Interface for object that can be snapshoted\n *\n * TODO: move this to be use in other place\n * TODO: currently input and output is not symmetrical, can they become symmetrical?\n * @legacy\n * @alpha\n */\nexport interface ISnapshotable<T> {\n\tasArray(): T[];\n\n\tloadFrom(values: T[]): void;\n}\n\n/**\n * Ordered Collection interface\n *\n * Collection of objects that has deterministic add and remove ordering.\n * Object implementing this interface can be used as the data backing\n * for the ConsensusOrderedCollection\n * @legacy\n * @alpha\n */\n// TODO: #22835 Use undefined instead of any (breaking change)\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface IOrderedCollection<T = any> extends ISnapshotable<T> {\n\t/**\n\t * Adds a value to the collection\n\t */\n\tadd(value: T);\n\n\t/**\n\t * Retrieves a value from the collection.\n\t */\n\tremove(): T;\n\n\t/**\n\t * Return the size of the collection\n\t */\n\tsize(): number;\n}\n"]}
|
package/dist/package.json
CHANGED
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/ordered-collection";
|
|
8
|
-
export declare const pkgVersion = "2.
|
|
8
|
+
export declare const pkgVersion = "2.20.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/ordered-collection";
|
|
11
|
-
exports.pkgVersion = "2.
|
|
11
|
+
exports.pkgVersion = "2.20.0";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,oCAAoC,CAAC;AAC/C,QAAA,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/ordered-collection\";\nexport const pkgVersion = \"2.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,oCAAoC,CAAC;AAC/C,QAAA,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/ordered-collection\";\nexport const pkgVersion = \"2.20.0\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshotableArray.d.ts","sourceRoot":"","sources":["../src/snapshotableArray.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,qBAAa,iBAAiB,CAAC,CAAC,CAAE,SAAQ,KAAK;IAC9C,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,CAAM;IAElB,OAAO;
|
|
1
|
+
{"version":3,"file":"snapshotableArray.d.ts","sourceRoot":"","sources":["../src/snapshotableArray.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,qBAAa,iBAAiB,CAAC,CAAC,CAAE,SAAQ,KAAK;IAC9C,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,CAAM;IAElB,OAAO,IAAI,CAAC,EAAE;IAIR,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAKxC,IAAI,IAAI,MAAM;CAGrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshotableArray.js","sourceRoot":"","sources":["../src/snapshotableArray.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAE7D,MAAa,iBAAqB,SAAQ,KAAK;IAA/C;;QACW,SAAI,GAAQ,EAAE,CAAC;IAc1B,CAAC;IAZO,OAAO;QACb,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,IAAS;QAC9B,IAAA,iBAAM,EAAC,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,KAAK,CAAC,oDAAoD,CAAC,CAAC;QAC3F,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;IAEM,IAAI;QACV,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IACzB,CAAC;CACD;AAfD,8CAeC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nexport class SnapshotableArray<T> extends Array {\n\tprotected data: T[] = [];\n\n\tpublic asArray() {\n\t\treturn this.data;\n\t}\n\n\tpublic async loadFrom(from: T[]): Promise<void> {\n\t\tassert(this.data.length === 0, 0x06b /* \"Loading snapshot into a non-empty collection\" */);\n\t\tthis.data = from;\n\t}\n\n\tpublic size(): number {\n\t\treturn this.data.length;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"snapshotableArray.js","sourceRoot":"","sources":["../src/snapshotableArray.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAE7D,MAAa,iBAAqB,SAAQ,KAAK;IAA/C;;QACW,SAAI,GAAQ,EAAE,CAAC;IAc1B,CAAC;IAZO,OAAO;QACb,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,IAAS;QAC9B,IAAA,iBAAM,EAAC,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,KAAK,CAAC,oDAAoD,CAAC,CAAC;QAC3F,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;IAEM,IAAI;QACV,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IACzB,CAAC;CACD;AAfD,8CAeC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nexport class SnapshotableArray<T> extends Array {\n\tprotected data: T[] = [];\n\n\tpublic asArray(): T[] {\n\t\treturn this.data;\n\t}\n\n\tpublic async loadFrom(from: T[]): Promise<void> {\n\t\tassert(this.data.length === 0, 0x06b /* \"Loading snapshot into a non-empty collection\" */);\n\t\tthis.data = from;\n\t}\n\n\tpublic size(): number {\n\t\treturn this.data.length;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consensusOrderedCollection.d.ts","sourceRoot":"","sources":["../src/consensusOrderedCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAEN,yBAAyB,EACzB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAErF,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,6CAA6C,CAAC;AAG7F,OAAO,EACN,iBAAiB,EAEjB,2BAA2B,EAC3B,iCAAiC,EACjC,kBAAkB,EAClB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"consensusOrderedCollection.d.ts","sourceRoot":"","sources":["../src/consensusOrderedCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAEN,yBAAyB,EACzB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAErF,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,6CAA6C,CAAC;AAG7F,OAAO,EACN,iBAAiB,EAEjB,2BAA2B,EAC3B,iCAAiC,EACjC,kBAAkB,EAClB,MAAM,iBAAiB,CAAC;AAgEzB;;;;;;;;;;GAUG;AAIH,qBAAa,0BAA0B,CAAC,CAAC,GAAG,GAAG,CAC9C,SAAQ,YAAY,CAAC,iCAAiC,CAAC,CAAC,CAAC,CACzD,YAAW,2BAA2B,CAAC,CAAC,CAAC;IAexC,OAAO,CAAC,QAAQ,CAAC,IAAI;IAbtB;;OAEG;IACH,OAAO,CAAC,WAAW,CAAiC;IAEpD;;;OAGG;IACH,SAAS,aACR,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,sBAAsB,EAC/B,UAAU,EAAE,kBAAkB,EACb,IAAI,EAAE,kBAAkB,CAAC,CAAC,CAAC;IAc7C;;OAEG;IACU,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBzC;;;OAGG;IACU,OAAO,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IA0BtE;;OAEG;IACU,cAAc,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAW1E,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,gBAAgB,GAAG,qBAAqB;IAa5E,SAAS,CAAC,QAAQ,IAAI,OAAO;cAIb,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAe1D,SAAS,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAS/C,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAiB1C,SAAS,CAAC,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAU9C;;OAEG;cACa,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBxE,SAAS,CAAC,YAAY,IAAI,IAAI;IAQ9B,SAAS,CAAC,WAAW,CACpB,OAAO,EAAE,yBAAyB,EAClC,KAAK,EAAE,OAAO,EACd,eAAe,EAAE,OAAO,GACtB,IAAI;YAyCO,MAAM;IAepB,OAAO,CAAC,OAAO;IAKf,OAAO,CAAC,WAAW;YAmBL,eAAe;IAY7B,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,gBAAgB;IAIxB,SAAS,CAAC,cAAc,IAAI,IAAI;CAGhC"}
|
|
@@ -23,6 +23,8 @@ const idForLocalUnattachedClient = undefined;
|
|
|
23
23
|
* @legacy
|
|
24
24
|
* @alpha
|
|
25
25
|
*/
|
|
26
|
+
// TODO: #22835 Use undefined instead of any (breaking change)
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
28
|
export class ConsensusOrderedCollection extends SharedObject {
|
|
27
29
|
/**
|
|
28
30
|
* Constructs a new consensus collection. If the object is non-local an id and service interfaces will
|
|
@@ -73,15 +75,18 @@ export class ConsensusOrderedCollection extends SharedObject {
|
|
|
73
75
|
}
|
|
74
76
|
const res = await callback(result.value);
|
|
75
77
|
switch (res) {
|
|
76
|
-
case ConsensusResult.Complete:
|
|
78
|
+
case ConsensusResult.Complete: {
|
|
77
79
|
await this.complete(result.acquireId);
|
|
78
80
|
break;
|
|
79
|
-
|
|
81
|
+
}
|
|
82
|
+
case ConsensusResult.Release: {
|
|
80
83
|
this.release(result.acquireId);
|
|
81
84
|
this.emit("localRelease", result.value, true /* intentional */);
|
|
82
85
|
break;
|
|
83
|
-
|
|
86
|
+
}
|
|
87
|
+
default: {
|
|
84
88
|
unreachableCase(res);
|
|
89
|
+
}
|
|
85
90
|
}
|
|
86
91
|
return true;
|
|
87
92
|
}
|
|
@@ -105,7 +110,7 @@ export class ConsensusOrderedCollection extends SharedObject {
|
|
|
105
110
|
const builder = new SummaryTreeBuilder();
|
|
106
111
|
let blobContent = this.serializeValue(this.data.asArray(), serializer);
|
|
107
112
|
builder.addBlob(snapshotFileNameData, blobContent);
|
|
108
|
-
blobContent = this.serializeValue(
|
|
113
|
+
blobContent = this.serializeValue([...this.jobTracking.entries()], serializer);
|
|
109
114
|
builder.addBlob(snapshotFileNameTracking, blobContent);
|
|
110
115
|
return builder.getSummaryTree();
|
|
111
116
|
}
|
|
@@ -184,25 +189,30 @@ export class ConsensusOrderedCollection extends SharedObject {
|
|
|
184
189
|
const op = message.contents;
|
|
185
190
|
let value;
|
|
186
191
|
switch (op.opName) {
|
|
187
|
-
case "add":
|
|
188
|
-
if (op.deserializedValue
|
|
189
|
-
this.addCore(op.
|
|
192
|
+
case "add": {
|
|
193
|
+
if (op.deserializedValue === undefined) {
|
|
194
|
+
this.addCore(this.deserializeValue(op.value, this.serializer));
|
|
190
195
|
}
|
|
191
196
|
else {
|
|
192
|
-
this.addCore(
|
|
197
|
+
this.addCore(op.deserializedValue);
|
|
193
198
|
}
|
|
194
199
|
break;
|
|
195
|
-
|
|
200
|
+
}
|
|
201
|
+
case "acquire": {
|
|
196
202
|
value = this.acquireCore(op.acquireId, message.clientId ?? undefined);
|
|
197
203
|
break;
|
|
198
|
-
|
|
204
|
+
}
|
|
205
|
+
case "complete": {
|
|
199
206
|
this.completeCore(op.acquireId);
|
|
200
207
|
break;
|
|
201
|
-
|
|
208
|
+
}
|
|
209
|
+
case "release": {
|
|
202
210
|
this.releaseCore(op.acquireId);
|
|
203
211
|
break;
|
|
204
|
-
|
|
212
|
+
}
|
|
213
|
+
default: {
|
|
205
214
|
unreachableCase(op);
|
|
215
|
+
}
|
|
206
216
|
}
|
|
207
217
|
if (local) {
|
|
208
218
|
// Resolve the pending promise for this operation now that we have received an ack for it.
|
|
@@ -264,7 +274,6 @@ export class ConsensusOrderedCollection extends SharedObject {
|
|
|
264
274
|
return serializer.stringify(value, this.handle);
|
|
265
275
|
}
|
|
266
276
|
deserializeValue(content, serializer) {
|
|
267
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
268
277
|
return serializer.parse(content);
|
|
269
278
|
}
|
|
270
279
|
applyStashedOp() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consensusOrderedCollection.js","sourceRoot":"","sources":["../src/consensusOrderedCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAM9E,OAAO,EACN,WAAW,GAEX,MAAM,6CAA6C,CAAC;AAErD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAoB,YAAY,EAAE,MAAM,6CAA6C,CAAC;AAC7F,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC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AAK,CAAC,CAAC;gBACrB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnB,CAAC;QACF,CAAC;QAED,+DAA+D;QAC/D,qFAAqF;QACrF,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC;IACvE,CAAC;IAEO,cAAc,CAAC,KAAK,EAAE,UAA4B;QACzD,OAAO,UAAU,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACjD,CAAC;IAEO,gBAAgB,CAAC,OAAe,EAAE,UAA4B;QACrE,+DAA+D;QAC/D,OAAO,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAES,cAAc;QACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport {\n\tMessageType,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport { IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base/internal\";\nimport { v4 as uuid } from \"uuid\";\n\nimport {\n\tConsensusCallback,\n\tConsensusResult,\n\tIConsensusOrderedCollection,\n\tIConsensusOrderedCollectionEvents,\n\tIOrderedCollection,\n} from \"./interfaces.js\";\n\nconst snapshotFileNameData = \"header\";\nconst snapshotFileNameTracking = \"jobTracking\";\n\ninterface IConsensusOrderedCollectionValue<T> {\n\t// an ID used to indicate acquired item.\n\t// Used in acquire/release/complete ops.\n\treadonly acquireId: string;\n\n\t// The actual value\n\treadonly value: T;\n}\n\n/**\n * An operation for consensus ordered collection\n */\ninterface IConsensusOrderedCollectionAddOperation<T> {\n\topName: \"add\";\n\t// serialized value\n\tvalue: string;\n\tdeserializedValue?: T;\n}\n\ninterface IConsensusOrderedCollectionAcquireOperation {\n\topName: \"acquire\";\n\t// an ID used to indicate acquired item.\n\t// Used in acquire/release/complete ops.\n\tacquireId: string;\n}\n\ninterface IConsensusOrderedCollectionCompleteOperation {\n\topName: \"complete\";\n\t// an ID used to indicate acquired item.\n\t// Used in acquire/release/complete ops.\n\tacquireId: string;\n}\n\ninterface IConsensusOrderedCollectionReleaseOperation {\n\topName: \"release\";\n\t// an ID used to indicate acquired item.\n\t// Used in acquire/release/complete ops.\n\tacquireId: string;\n}\n\ntype IConsensusOrderedCollectionOperation<T> =\n\t| IConsensusOrderedCollectionAddOperation<T>\n\t| IConsensusOrderedCollectionAcquireOperation\n\t| IConsensusOrderedCollectionCompleteOperation\n\t| IConsensusOrderedCollectionReleaseOperation;\n\n/** The type of the resolve function to call after the local operation is ack'd */\ntype PendingResolve<T> = (value: IConsensusOrderedCollectionValue<T> | undefined) => void;\n\n/**\n * For job tracking, we need to keep track of which client \"owns\" a given value.\n * Key is the acquireId from when it was acquired\n * Value is the acquired value, and the id of the client who acquired it, or undefined for unattached client\n */\ntype JobTrackingInfo<T> = Map<string, { value: T; clientId: string | undefined }>;\nconst idForLocalUnattachedClient = undefined;\n\n/**\n * Implementation of a consensus collection shared object\n *\n * Implements the shared object's communication, and the semantics around the\n * release/complete mechanism following acquire.\n *\n * Generally not used directly. A derived type will pass in a backing data type\n * IOrderedCollection that will define the deterministic add/acquire order and snapshot ability.\n * @legacy\n * @alpha\n */\nexport class ConsensusOrderedCollection<T = any>\n\textends SharedObject<IConsensusOrderedCollectionEvents<T>>\n\timplements IConsensusOrderedCollection<T>\n{\n\t/**\n\t * The set of values that have been acquired but not yet completed or released\n\t */\n\tprivate jobTracking: JobTrackingInfo<T> = new Map();\n\n\t/**\n\t * Constructs a new consensus collection. If the object is non-local an id and service interfaces will\n\t * be provided\n\t */\n\tprotected constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\tprivate readonly data: IOrderedCollection<T>,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_consensusOrderedCollection_\");\n\n\t\t// We can't simply call this.removeClient(this.runtime.clientId) in on runtime disconnected,\n\t\t// because other clients may disconnect concurrently.\n\t\t// Disconnect order matters because it defines the order items go back to the queue.\n\t\t// So we put items back to queue only when we process our own removeMember event.\n\t\truntime.getQuorum().on(\"removeMember\", (clientId: string) => {\n\t\t\tassert(!!clientId, 0x067 /* \"Missing clientId for removal!\" */);\n\t\t\tthis.removeClient(clientId);\n\t\t});\n\t}\n\n\t/**\n\t * Add a value to the consensus collection.\n\t */\n\tpublic async add(value: T): Promise<void> {\n\t\tconst valueSer = this.serializeValue(value, this.serializer);\n\n\t\tif (!this.isAttached()) {\n\t\t\t// For the case where this is not attached yet, explicitly JSON\n\t\t\t// clone the value to match the behavior of going thru the wire.\n\t\t\tconst addValue = this.deserializeValue(valueSer, this.serializer) as T;\n\t\t\tthis.addCore(addValue);\n\t\t\treturn;\n\t\t}\n\n\t\tawait this.submit<IConsensusOrderedCollectionAddOperation<T>>({\n\t\t\topName: \"add\",\n\t\t\tvalue: valueSer,\n\t\t\tdeserializedValue: value,\n\t\t});\n\t}\n\n\t/**\n\t * Remove a value from the consensus collection. If the collection is empty, returns false.\n\t * Otherwise calls callback with the value\n\t */\n\tpublic async acquire(callback: ConsensusCallback<T>): Promise<boolean> {\n\t\tconst result = await this.acquireInternal();\n\t\tif (result === undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst res = await callback(result.value);\n\n\t\tswitch (res) {\n\t\t\tcase ConsensusResult.Complete:\n\t\t\t\tawait this.complete(result.acquireId);\n\t\t\t\tbreak;\n\t\t\tcase ConsensusResult.Release:\n\t\t\t\tthis.release(result.acquireId);\n\t\t\t\tthis.emit(\"localRelease\", result.value, true /* intentional */);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tunreachableCase(res);\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Wait for a value to be available and acquire it from the consensus collection\n\t */\n\tpublic async waitAndAcquire(callback: ConsensusCallback<T>): Promise<void> {\n\t\tdo {\n\t\t\tif (this.data.size() === 0) {\n\t\t\t\t// Wait for new entry before trying to acquire again\n\t\t\t\tawait this.newAckBasedPromise<T>((resolve) => {\n\t\t\t\t\tthis.once(\"add\", resolve);\n\t\t\t\t});\n\t\t\t}\n\t\t} while (!(await this.acquire(callback)));\n\t}\n\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\t// If we are transitioning from unattached to attached mode,\n\t\t// then we are losing all checked out work!\n\t\tthis.removeClient(idForLocalUnattachedClient);\n\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tlet blobContent = this.serializeValue(this.data.asArray(), serializer);\n\t\tbuilder.addBlob(snapshotFileNameData, blobContent);\n\t\tblobContent = this.serializeValue(Array.from(this.jobTracking.entries()), serializer);\n\t\tbuilder.addBlob(snapshotFileNameTracking, blobContent);\n\t\treturn builder.getSummaryTree();\n\t}\n\n\tprotected isActive() {\n\t\treturn this.runtime.connected && this.deltaManager.active;\n\t}\n\n\tprotected async complete(acquireId: string) {\n\t\tif (!this.isAttached()) {\n\t\t\tthis.completeCore(acquireId);\n\t\t\treturn;\n\t\t}\n\n\t\t// if not active, this item already was released to queue (as observed by other clients)\n\t\tif (this.isActive()) {\n\t\t\tawait this.submit<IConsensusOrderedCollectionCompleteOperation>({\n\t\t\t\topName: \"complete\",\n\t\t\t\tacquireId,\n\t\t\t});\n\t\t}\n\t}\n\n\tprotected completeCore(acquireId: string) {\n\t\t// Note: item may be no longer in jobTracking and returned back to queue!\n\t\tconst rec = this.jobTracking.get(acquireId);\n\t\tif (rec !== undefined) {\n\t\t\tthis.jobTracking.delete(acquireId);\n\t\t\tthis.emit(\"complete\", rec.value);\n\t\t}\n\t}\n\n\tprotected release(acquireId: string) {\n\t\tif (!this.isAttached()) {\n\t\t\tthis.releaseCore(acquireId);\n\t\t\treturn;\n\t\t}\n\n\t\t// if not active, this item already was released to queue (as observed by other clients)\n\t\tif (this.isActive()) {\n\t\t\tthis.submit<IConsensusOrderedCollectionReleaseOperation>({\n\t\t\t\topName: \"release\",\n\t\t\t\tacquireId,\n\t\t\t}).catch((error) => {\n\t\t\t\tthis.logger.sendErrorEvent({ eventName: \"ConsensusQueue_release\" }, error);\n\t\t\t});\n\t\t}\n\t}\n\n\tprotected releaseCore(acquireId: string) {\n\t\t// Note: item may be no longer in jobTracking and returned back to queue!\n\t\tconst rec = this.jobTracking.get(acquireId);\n\t\tif (rec !== undefined) {\n\t\t\tthis.jobTracking.delete(acquireId);\n\t\t\tthis.data.add(rec.value);\n\t\t\tthis.emit(\"add\", rec.value, false /* newlyAdded */);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tassert(\n\t\t\tthis.jobTracking.size === 0,\n\t\t\t0x068 /* \"On consensusOrderedCollection load, job tracking size > 0\" */,\n\t\t);\n\t\tconst blob = await storage.readBlob(snapshotFileNameTracking);\n\t\tconst rawContentTracking = bufferToString(blob, \"utf8\");\n\t\tconst content = this.deserializeValue(rawContentTracking, this.serializer);\n\t\tthis.jobTracking = new Map(content) as JobTrackingInfo<T>;\n\n\t\tassert(\n\t\t\tthis.data.size() === 0,\n\t\t\t0x069 /* \"On consensusOrderedCollection load, data size > 0\" */,\n\t\t);\n\t\tconst blob2 = await storage.readBlob(snapshotFileNameData);\n\t\tconst rawContentData = bufferToString(blob2, \"utf8\");\n\t\tconst content2 = this.deserializeValue(rawContentData, this.serializer) as T[];\n\t\tthis.data.loadFrom(content2);\n\t}\n\n\tprotected onDisconnect() {\n\t\tfor (const [, { value, clientId }] of this.jobTracking) {\n\t\t\tif (clientId === this.runtime.clientId) {\n\t\t\t\tthis.emit(\"localRelease\", value, false /* intentional */);\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t) {\n\t\tif (message.type === MessageType.Operation) {\n\t\t\tconst op = message.contents as IConsensusOrderedCollectionOperation<T>;\n\t\t\tlet value: IConsensusOrderedCollectionValue<T> | undefined;\n\t\t\tswitch (op.opName) {\n\t\t\t\tcase \"add\":\n\t\t\t\t\tif (op.deserializedValue !== undefined) {\n\t\t\t\t\t\tthis.addCore(op.deserializedValue);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.addCore(this.deserializeValue(op.value, this.serializer) as T);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase \"acquire\":\n\t\t\t\t\tvalue = this.acquireCore(op.acquireId, message.clientId ?? undefined);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase \"complete\":\n\t\t\t\t\tthis.completeCore(op.acquireId);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase \"release\":\n\t\t\t\t\tthis.releaseCore(op.acquireId);\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\t\t\t\t\tunreachableCase(op);\n\t\t\t}\n\t\t\tif (local) {\n\t\t\t\t// Resolve the pending promise for this operation now that we have received an ack for it.\n\t\t\t\tconst resolve = localOpMetadata as PendingResolve<T>;\n\t\t\t\tresolve(value);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async submit<TMessage extends IConsensusOrderedCollectionOperation<T>>(\n\t\tmessage: TMessage,\n\t): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n\t\tassert(this.isAttached(), 0x06a /* \"Trying to submit message while detached!\" */);\n\n\t\treturn this.newAckBasedPromise<IConsensusOrderedCollectionValue<T> | undefined>(\n\t\t\t(resolve) => {\n\t\t\t\t// Send the resolve function as the localOpMetadata. This will be provided back to us when the\n\t\t\t\t// op is ack'd.\n\t\t\t\tthis.submitLocalMessage(message, resolve);\n\t\t\t\t// If we fail due to runtime being disposed, it's better to return undefined then unhandled exception.\n\t\t\t},\n\t\t).catch((error) => undefined);\n\t}\n\n\tprivate addCore(value: T) {\n\t\tthis.data.add(value);\n\t\tthis.emit(\"add\", value, true /* newlyAdded */);\n\t}\n\n\tprivate acquireCore(\n\t\tacquireId: string,\n\t\tclientId?: string,\n\t): IConsensusOrderedCollectionValue<T> | undefined {\n\t\tif (this.data.size() === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst value = this.data.remove();\n\n\t\tconst value2: IConsensusOrderedCollectionValue<T> = {\n\t\t\tacquireId,\n\t\t\tvalue,\n\t\t};\n\t\tthis.jobTracking.set(value2.acquireId, { value, clientId });\n\n\t\tthis.emit(\"acquire\", value, clientId);\n\t\treturn value2;\n\t}\n\n\tprivate async acquireInternal(): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n\t\tif (!this.isAttached()) {\n\t\t\t// can be undefined if queue is empty\n\t\t\treturn this.acquireCore(uuid(), idForLocalUnattachedClient);\n\t\t}\n\n\t\treturn this.submit<IConsensusOrderedCollectionAcquireOperation>({\n\t\t\topName: \"acquire\",\n\t\t\tacquireId: uuid(),\n\t\t});\n\t}\n\n\tprivate removeClient(clientIdToRemove?: string) {\n\t\tconst added: T[] = [];\n\t\tfor (const [acquireId, { value, clientId }] of this.jobTracking) {\n\t\t\tif (clientId === clientIdToRemove) {\n\t\t\t\tthis.jobTracking.delete(acquireId);\n\t\t\t\tthis.data.add(value);\n\t\t\t\tadded.push(value);\n\t\t\t}\n\t\t}\n\n\t\t// Raise all events only after all state changes are completed,\n\t\t// to guarantee same ordering of operations if collection is manipulated from events.\n\t\tadded.map((value) => this.emit(\"add\", value, false /* newlyAdded */));\n\t}\n\n\tprivate serializeValue(value, serializer: IFluidSerializer) {\n\t\treturn serializer.stringify(value, this.handle);\n\t}\n\n\tprivate deserializeValue(content: string, serializer: IFluidSerializer) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn serializer.parse(content);\n\t}\n\n\tprotected applyStashedOp(): void {\n\t\tthrow new Error(\"not implemented\");\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"consensusOrderedCollection.js","sourceRoot":"","sources":["../src/consensusOrderedCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAM9E,OAAO,EACN,WAAW,GAEX,MAAM,6CAA6C,CAAC;AAErD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAoB,YAAY,EAAE,MAAM,6CAA6C,CAAC;AAC7F,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAEN,eAAe,GAIf,MAAM,iBAAiB,CAAC;AAEzB,MAAM,oBAAoB,GAAG,QAAQ,CAAC;AACtC,MAAM,wBAAwB,GAAG,aAAa,CAAC;AA2D/C,MAAM,0BAA0B,GAAG,SAAS,CAAC;AAE7C;;;;;;;;;;GAUG;AAEH,8DAA8D;AAC9D,8DAA8D;AAC9D,MAAM,OAAO,0BACZ,SAAQ,YAAkD;IAQ1D;;;OAGG;IACH,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B,EACb,IAA2B;QAE5C,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,mCAAmC,CAAC,CAAC;QAFnD,SAAI,GAAJ,IAAI,CAAuB;QAb7C;;WAEG;QACK,gBAAW,GAAuB,IAAI,GAAG,EAAE,CAAC;QAc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BAAgB,CAAC,CAAC,CAAC;IACvE,CAAC;IAEO,cAAc,CAAC,KAAK,EAAE,UAA4B;QACzD,OAAO,UAAU,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACjD,CAAC;IAEO,gBAAgB,CAAC,OAAe,EAAE,UAA4B;QACrE,OAAO,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAES,cAAc;QACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport {\n\tMessageType,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport { IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base/internal\";\nimport { v4 as uuid } from \"uuid\";\n\nimport {\n\tConsensusCallback,\n\tConsensusResult,\n\tIConsensusOrderedCollection,\n\tIConsensusOrderedCollectionEvents,\n\tIOrderedCollection,\n} from \"./interfaces.js\";\n\nconst snapshotFileNameData = \"header\";\nconst snapshotFileNameTracking = \"jobTracking\";\n\ninterface IConsensusOrderedCollectionValue<T> {\n\t// an ID used to indicate acquired item.\n\t// Used in acquire/release/complete ops.\n\treadonly acquireId: string;\n\n\t// The actual value\n\treadonly value: T;\n}\n\n/**\n * An operation for consensus ordered collection\n */\ninterface IConsensusOrderedCollectionAddOperation<T> {\n\topName: \"add\";\n\t// serialized value\n\tvalue: string;\n\tdeserializedValue?: T;\n}\n\ninterface IConsensusOrderedCollectionAcquireOperation {\n\topName: \"acquire\";\n\t// an ID used to indicate acquired item.\n\t// Used in acquire/release/complete ops.\n\tacquireId: string;\n}\n\ninterface IConsensusOrderedCollectionCompleteOperation {\n\topName: \"complete\";\n\t// an ID used to indicate acquired item.\n\t// Used in acquire/release/complete ops.\n\tacquireId: string;\n}\n\ninterface IConsensusOrderedCollectionReleaseOperation {\n\topName: \"release\";\n\t// an ID used to indicate acquired item.\n\t// Used in acquire/release/complete ops.\n\tacquireId: string;\n}\n\ntype IConsensusOrderedCollectionOperation<T> =\n\t| IConsensusOrderedCollectionAddOperation<T>\n\t| IConsensusOrderedCollectionAcquireOperation\n\t| IConsensusOrderedCollectionCompleteOperation\n\t| IConsensusOrderedCollectionReleaseOperation;\n\n/**\n * The type of the resolve function to call after the local operation is acknowledged.\n */\ntype PendingResolve<T> = (value: IConsensusOrderedCollectionValue<T> | undefined) => void;\n\n/**\n * For job tracking, we need to keep track of which client \"owns\" a given value.\n * Key is the acquireId from when it was acquired\n * Value is the acquired value, and the id of the client who acquired it, or undefined for unattached client\n */\ntype JobTrackingInfo<T> = Map<string, { value: T; clientId: string | undefined }>;\nconst idForLocalUnattachedClient = undefined;\n\n/**\n * Implementation of a consensus collection shared object\n *\n * Implements the shared object's communication, and the semantics around the\n * release/complete mechanism following acquire.\n *\n * Generally not used directly. A derived type will pass in a backing data type\n * IOrderedCollection that will define the deterministic add/acquire order and snapshot ability.\n * @legacy\n * @alpha\n */\n\n// TODO: #22835 Use undefined instead of any (breaking change)\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class ConsensusOrderedCollection<T = any>\n\textends SharedObject<IConsensusOrderedCollectionEvents<T>>\n\timplements IConsensusOrderedCollection<T>\n{\n\t/**\n\t * The set of values that have been acquired but not yet completed or released\n\t */\n\tprivate jobTracking: JobTrackingInfo<T> = new Map();\n\n\t/**\n\t * Constructs a new consensus collection. If the object is non-local an id and service interfaces will\n\t * be provided\n\t */\n\tprotected constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\tprivate readonly data: IOrderedCollection<T>,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_consensusOrderedCollection_\");\n\n\t\t// We can't simply call this.removeClient(this.runtime.clientId) in on runtime disconnected,\n\t\t// because other clients may disconnect concurrently.\n\t\t// Disconnect order matters because it defines the order items go back to the queue.\n\t\t// So we put items back to queue only when we process our own removeMember event.\n\t\truntime.getQuorum().on(\"removeMember\", (clientId: string) => {\n\t\t\tassert(!!clientId, 0x067 /* \"Missing clientId for removal!\" */);\n\t\t\tthis.removeClient(clientId);\n\t\t});\n\t}\n\n\t/**\n\t * Add a value to the consensus collection.\n\t */\n\tpublic async add(value: T): Promise<void> {\n\t\tconst valueSer = this.serializeValue(value, this.serializer);\n\n\t\tif (!this.isAttached()) {\n\t\t\t// For the case where this is not attached yet, explicitly JSON\n\t\t\t// clone the value to match the behavior of going thru the wire.\n\t\t\tconst addValue = this.deserializeValue(valueSer, this.serializer) as T;\n\t\t\tthis.addCore(addValue);\n\t\t\treturn;\n\t\t}\n\n\t\tawait this.submit<IConsensusOrderedCollectionAddOperation<T>>({\n\t\t\topName: \"add\",\n\t\t\tvalue: valueSer,\n\t\t\tdeserializedValue: value,\n\t\t});\n\t}\n\n\t/**\n\t * Remove a value from the consensus collection. If the collection is empty, returns false.\n\t * Otherwise calls callback with the value\n\t */\n\tpublic async acquire(callback: ConsensusCallback<T>): Promise<boolean> {\n\t\tconst result = await this.acquireInternal();\n\t\tif (result === undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst res = await callback(result.value);\n\n\t\tswitch (res) {\n\t\t\tcase ConsensusResult.Complete: {\n\t\t\t\tawait this.complete(result.acquireId);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase ConsensusResult.Release: {\n\t\t\t\tthis.release(result.acquireId);\n\t\t\t\tthis.emit(\"localRelease\", result.value, true /* intentional */);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tunreachableCase(res);\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Wait for a value to be available and acquire it from the consensus collection\n\t */\n\tpublic async waitAndAcquire(callback: ConsensusCallback<T>): Promise<void> {\n\t\tdo {\n\t\t\tif (this.data.size() === 0) {\n\t\t\t\t// Wait for new entry before trying to acquire again\n\t\t\t\tawait this.newAckBasedPromise<T>((resolve) => {\n\t\t\t\t\tthis.once(\"add\", resolve);\n\t\t\t\t});\n\t\t\t}\n\t\t} while (!(await this.acquire(callback)));\n\t}\n\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\t// If we are transitioning from unattached to attached mode,\n\t\t// then we are losing all checked out work!\n\t\tthis.removeClient(idForLocalUnattachedClient);\n\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tlet blobContent = this.serializeValue(this.data.asArray(), serializer);\n\t\tbuilder.addBlob(snapshotFileNameData, blobContent);\n\t\tblobContent = this.serializeValue([...this.jobTracking.entries()], serializer);\n\t\tbuilder.addBlob(snapshotFileNameTracking, blobContent);\n\t\treturn builder.getSummaryTree();\n\t}\n\n\tprotected isActive(): boolean {\n\t\treturn this.runtime.connected && this.deltaManager.active;\n\t}\n\n\tprotected async complete(acquireId: string): Promise<void> {\n\t\tif (!this.isAttached()) {\n\t\t\tthis.completeCore(acquireId);\n\t\t\treturn;\n\t\t}\n\n\t\t// if not active, this item already was released to queue (as observed by other clients)\n\t\tif (this.isActive()) {\n\t\t\tawait this.submit<IConsensusOrderedCollectionCompleteOperation>({\n\t\t\t\topName: \"complete\",\n\t\t\t\tacquireId,\n\t\t\t});\n\t\t}\n\t}\n\n\tprotected completeCore(acquireId: string): void {\n\t\t// Note: item may be no longer in jobTracking and returned back to queue!\n\t\tconst rec = this.jobTracking.get(acquireId);\n\t\tif (rec !== undefined) {\n\t\t\tthis.jobTracking.delete(acquireId);\n\t\t\tthis.emit(\"complete\", rec.value);\n\t\t}\n\t}\n\n\tprotected release(acquireId: string): void {\n\t\tif (!this.isAttached()) {\n\t\t\tthis.releaseCore(acquireId);\n\t\t\treturn;\n\t\t}\n\n\t\t// if not active, this item already was released to queue (as observed by other clients)\n\t\tif (this.isActive()) {\n\t\t\tthis.submit<IConsensusOrderedCollectionReleaseOperation>({\n\t\t\t\topName: \"release\",\n\t\t\t\tacquireId,\n\t\t\t}).catch((error) => {\n\t\t\t\tthis.logger.sendErrorEvent({ eventName: \"ConsensusQueue_release\" }, error);\n\t\t\t});\n\t\t}\n\t}\n\n\tprotected releaseCore(acquireId: string): void {\n\t\t// Note: item may be no longer in jobTracking and returned back to queue!\n\t\tconst rec = this.jobTracking.get(acquireId);\n\t\tif (rec !== undefined) {\n\t\t\tthis.jobTracking.delete(acquireId);\n\t\t\tthis.data.add(rec.value);\n\t\t\tthis.emit(\"add\", rec.value, false /* newlyAdded */);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tassert(\n\t\t\tthis.jobTracking.size === 0,\n\t\t\t0x068 /* \"On consensusOrderedCollection load, job tracking size > 0\" */,\n\t\t);\n\t\tconst blob = await storage.readBlob(snapshotFileNameTracking);\n\t\tconst rawContentTracking = bufferToString(blob, \"utf8\");\n\t\tconst content = this.deserializeValue(rawContentTracking, this.serializer);\n\t\tthis.jobTracking = new Map(\n\t\t\tcontent as Iterable<[string, { value: T; clientId: string | undefined }]>,\n\t\t);\n\n\t\tassert(\n\t\t\tthis.data.size() === 0,\n\t\t\t0x069 /* \"On consensusOrderedCollection load, data size > 0\" */,\n\t\t);\n\t\tconst blob2 = await storage.readBlob(snapshotFileNameData);\n\t\tconst rawContentData = bufferToString(blob2, \"utf8\");\n\t\tconst content2 = this.deserializeValue(rawContentData, this.serializer) as T[];\n\t\tthis.data.loadFrom(content2);\n\t}\n\n\tprotected onDisconnect(): void {\n\t\tfor (const [, { value, clientId }] of this.jobTracking) {\n\t\t\tif (clientId === this.runtime.clientId) {\n\t\t\t\tthis.emit(\"localRelease\", value, false /* intentional */);\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t): void {\n\t\tif (message.type === MessageType.Operation) {\n\t\t\tconst op = message.contents as IConsensusOrderedCollectionOperation<T>;\n\t\t\tlet value: IConsensusOrderedCollectionValue<T> | undefined;\n\t\t\tswitch (op.opName) {\n\t\t\t\tcase \"add\": {\n\t\t\t\t\tif (op.deserializedValue === undefined) {\n\t\t\t\t\t\tthis.addCore(this.deserializeValue(op.value, this.serializer) as T);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.addCore(op.deserializedValue);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase \"acquire\": {\n\t\t\t\t\tvalue = this.acquireCore(op.acquireId, message.clientId ?? undefined);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase \"complete\": {\n\t\t\t\t\tthis.completeCore(op.acquireId);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase \"release\": {\n\t\t\t\t\tthis.releaseCore(op.acquireId);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\tunreachableCase(op);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (local) {\n\t\t\t\t// Resolve the pending promise for this operation now that we have received an ack for it.\n\t\t\t\tconst resolve = localOpMetadata as PendingResolve<T>;\n\t\t\t\tresolve(value);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async submit<TMessage extends IConsensusOrderedCollectionOperation<T>>(\n\t\tmessage: TMessage,\n\t): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n\t\tassert(this.isAttached(), 0x06a /* \"Trying to submit message while detached!\" */);\n\n\t\treturn this.newAckBasedPromise<IConsensusOrderedCollectionValue<T> | undefined>(\n\t\t\t(resolve) => {\n\t\t\t\t// Send the resolve function as the localOpMetadata. This will be provided back to us when the\n\t\t\t\t// op is ack'd.\n\t\t\t\tthis.submitLocalMessage(message, resolve);\n\t\t\t\t// If we fail due to runtime being disposed, it's better to return undefined then unhandled exception.\n\t\t\t},\n\t\t).catch((error) => undefined);\n\t}\n\n\tprivate addCore(value: T): void {\n\t\tthis.data.add(value);\n\t\tthis.emit(\"add\", value, true /* newlyAdded */);\n\t}\n\n\tprivate acquireCore(\n\t\tacquireId: string,\n\t\tclientId?: string,\n\t): IConsensusOrderedCollectionValue<T> | undefined {\n\t\tif (this.data.size() === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst value = this.data.remove();\n\n\t\tconst value2: IConsensusOrderedCollectionValue<T> = {\n\t\t\tacquireId,\n\t\t\tvalue,\n\t\t};\n\t\tthis.jobTracking.set(value2.acquireId, { value, clientId });\n\n\t\tthis.emit(\"acquire\", value, clientId);\n\t\treturn value2;\n\t}\n\n\tprivate async acquireInternal(): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n\t\tif (!this.isAttached()) {\n\t\t\t// can be undefined if queue is empty\n\t\t\treturn this.acquireCore(uuid(), idForLocalUnattachedClient);\n\t\t}\n\n\t\treturn this.submit<IConsensusOrderedCollectionAcquireOperation>({\n\t\t\topName: \"acquire\",\n\t\t\tacquireId: uuid(),\n\t\t});\n\t}\n\n\tprivate removeClient(clientIdToRemove?: string): void {\n\t\tconst added: T[] = [];\n\t\tfor (const [acquireId, { value, clientId }] of this.jobTracking) {\n\t\t\tif (clientId === clientIdToRemove) {\n\t\t\t\tthis.jobTracking.delete(acquireId);\n\t\t\t\tthis.data.add(value);\n\t\t\t\tadded.push(value);\n\t\t\t}\n\t\t}\n\n\t\t// Raise all events only after all state changes are completed,\n\t\t// to guarantee same ordering of operations if collection is manipulated from events.\n\t\tadded.map((value) => this.emit(\"add\", value, false /* newlyAdded */));\n\t}\n\n\tprivate serializeValue(value, serializer: IFluidSerializer): string {\n\t\treturn serializer.stringify(value, this.handle);\n\t}\n\n\tprivate deserializeValue(content: string, serializer: IFluidSerializer): unknown {\n\t\treturn serializer.parse(content);\n\t}\n\n\tprotected applyStashedOp(): void {\n\t\tthrow new Error(\"not implemented\");\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consensusOrderedCollectionFactory.d.ts","sourceRoot":"","sources":["../src/consensusOrderedCollectionFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,MAAM,gDAAgD,CAAC;AAGxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACN,2BAA2B,EAC3B,kCAAkC,EAClC,MAAM,iBAAiB,CAAC;AAGzB;;;;GAIG;AACH,qBAAa,qBAAsB,YAAW,kCAAkC;IAC/E,OAAc,IAAI,SAAuD;IAEzE,gBAAuB,UAAU,EAAE,kBAAkB,CAInD;IAEF,IAAW,IAAI,
|
|
1
|
+
{"version":3,"file":"consensusOrderedCollectionFactory.d.ts","sourceRoot":"","sources":["../src/consensusOrderedCollectionFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,MAAM,gDAAgD,CAAC;AAGxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACN,2BAA2B,EAC3B,kCAAkC,EAClC,MAAM,iBAAiB,CAAC;AAGzB;;;;GAIG;AACH,qBAAa,qBAAsB,YAAW,kCAAkC;IAC/E,OAAc,IAAI,SAAuD;IAEzE,gBAAuB,UAAU,EAAE,kBAAkB,CAInD;IAEF,IAAW,IAAI,IAAI,MAAM,CAExB;IAED,IAAW,UAAU,IAAI,kBAAkB,CAE1C;I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AAE,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAC1E,UAAU,CAAC,eAAe,EAAE,CAAC;QAC7B,OAAO,UAAU,CAAC;IACnB,CAAC;;AAlCa,0BAAI,GAAG,mDAAmD,CAAC;AAElD,gCAAU,GAAuB;IACvD,IAAI,EAAE,qBAAqB,CAAC,IAAI;IAChC,qBAAqB,EAAE,KAAK;IAC5B,cAAc,EAAE,UAAU;CAC1B,CAAC;AA+BH;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,sBAAsB,CAAC,qBAAqB,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelServices,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { createSharedObjectKind } from \"@fluidframework/shared-object-base/internal\";\n\nimport { ConsensusQueueClass } from \"./consensusQueue.js\";\nimport {\n\tIConsensusOrderedCollection,\n\tIConsensusOrderedCollectionFactory,\n} from \"./interfaces.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\n\n/**\n * The factory that defines the consensus queue\n *\n * @internal\n */\nexport class ConsensusQueueFactory implements IConsensusOrderedCollectionFactory {\n\tpublic static Type = \"https://graph.microsoft.com/types/consensus-queue\";\n\n\tpublic static readonly Attributes: IChannelAttributes = {\n\t\ttype: ConsensusQueueFactory.Type,\n\t\tsnapshotFormatVersion: \"0.1\",\n\t\tpackageVersion: pkgVersion,\n\t};\n\n\tpublic get type() {\n\t\treturn ConsensusQueueFactory.Type;\n\t}\n\n\tpublic get attributes() {\n\t\treturn ConsensusQueueFactory.Attributes;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}\n\t */\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tid: string,\n\t\tservices: IChannelServices,\n\t\tattributes: IChannelAttributes,\n\t): Promise<IConsensusOrderedCollection> {\n\t\tconst collection = new ConsensusQueueClass(id, runtime, attributes);\n\t\tawait collection.load(services);\n\t\treturn collection;\n\t}\n\n\tpublic create(document: IFluidDataStoreRuntime, id: string): IConsensusOrderedCollection {\n\t\tconst collection = new ConsensusQueueClass(id, document, this.attributes);\n\t\tcollection.initializeLocal();\n\t\treturn collection;\n\t}\n}\n\n/**\n * {@inheritDoc ConsensusQueueClass}\n * @legacy\n * @alpha\n */\nexport const ConsensusQueue = createSharedObjectKind(ConsensusQueueFactory);\n\n/**\n * {@inheritDoc ConsensusQueueClass}\n * @legacy\n * @alpha\n */\nexport type ConsensusQueue<T = any> = ConsensusQueueClass<T>;\n"]}
|
|
1
|
+
{"version":3,"file":"consensusOrderedCollectionFactory.js","sourceRoot":"","sources":["../src/consensusOrderedCollectionFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,sBAAsB,EAAE,MAAM,6CAA6C,CAAC;AAErF,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAK1D,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD;;;;GAIG;AACH,MAAM,OAAO,qBAAqB;IASjC,IAAW,IAAI;QACd,OAAO,qBAAqB,CAAC,IAAI,CAAC;IACnC,CAAC;IAED,IAAW,UAAU;QACpB,OAAO,qBAAqB,CAAC,UAAU,CAAC;IACzC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAI,CAChB,OAA+B,EAC/B,EAAU,EACV,QAA0B,EAC1B,UAA8B;QAE9B,MAAM,UAAU,GAAG,IAAI,mBAAmB,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QACpE,MAAM,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChC,OAAO,UAAU,CAAC;IACnB,CAAC;IAEM,MAAM,CAAC,QAAgC,EAAE,EAAU;QACzD,MAAM,UAAU,GAAG,IAAI,mBAAmB,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAC1E,UAAU,CAAC,eAAe,EAAE,CAAC;QAC7B,OAAO,UAAU,CAAC;IACnB,CAAC;;AAlCa,0BAAI,GAAG,mDAAmD,CAAC;AAElD,gCAAU,GAAuB;IACvD,IAAI,EAAE,qBAAqB,CAAC,IAAI;IAChC,qBAAqB,EAAE,KAAK;IAC5B,cAAc,EAAE,UAAU;CAC1B,CAAC;AA+BH;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,sBAAsB,CAAC,qBAAqB,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelServices,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { createSharedObjectKind } from \"@fluidframework/shared-object-base/internal\";\n\nimport { ConsensusQueueClass } from \"./consensusQueue.js\";\nimport {\n\tIConsensusOrderedCollection,\n\tIConsensusOrderedCollectionFactory,\n} from \"./interfaces.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\n\n/**\n * The factory that defines the consensus queue\n *\n * @internal\n */\nexport class ConsensusQueueFactory implements IConsensusOrderedCollectionFactory {\n\tpublic static Type = \"https://graph.microsoft.com/types/consensus-queue\";\n\n\tpublic static readonly Attributes: IChannelAttributes = {\n\t\ttype: ConsensusQueueFactory.Type,\n\t\tsnapshotFormatVersion: \"0.1\",\n\t\tpackageVersion: pkgVersion,\n\t};\n\n\tpublic get type(): string {\n\t\treturn ConsensusQueueFactory.Type;\n\t}\n\n\tpublic get attributes(): IChannelAttributes {\n\t\treturn ConsensusQueueFactory.Attributes;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}\n\t */\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tid: string,\n\t\tservices: IChannelServices,\n\t\tattributes: IChannelAttributes,\n\t): Promise<IConsensusOrderedCollection> {\n\t\tconst collection = new ConsensusQueueClass(id, runtime, attributes);\n\t\tawait collection.load(services);\n\t\treturn collection;\n\t}\n\n\tpublic create(document: IFluidDataStoreRuntime, id: string): IConsensusOrderedCollection {\n\t\tconst collection = new ConsensusQueueClass(id, document, this.attributes);\n\t\tcollection.initializeLocal();\n\t\treturn collection;\n\t}\n}\n\n/**\n * {@inheritDoc ConsensusQueueClass}\n * @legacy\n * @alpha\n */\nexport const ConsensusQueue = createSharedObjectKind(ConsensusQueueFactory);\n\n/**\n * {@inheritDoc ConsensusQueueClass}\n * @legacy\n * @alpha\n */\n// TODO: #22835 Use undefined instead of any (breaking change)\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ConsensusQueue<T = any> = ConsensusQueueClass<T>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consensusQueue.d.ts","sourceRoot":"","sources":["../src/consensusQueue.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,MAAM,gDAAgD,CAAC;AAExD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAoB7E;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"consensusQueue.d.ts","sourceRoot":"","sources":["../src/consensusQueue.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,MAAM,gDAAgD,CAAC;AAExD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAoB7E;;;;;;GAMG;AAGH,qBAAa,mBAAmB,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,0BAA0B,CAAC,CAAC,CAAC;IAC9E;;;OAGG;gBAEF,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,sBAAsB,EAC/B,UAAU,EAAE,kBAAkB;CAI/B"}
|
package/lib/consensusQueue.js
CHANGED
|
@@ -25,6 +25,8 @@ class SnapshotableQueue extends SnapshotableArray {
|
|
|
25
25
|
* @legacy
|
|
26
26
|
* @alpha
|
|
27
27
|
*/
|
|
28
|
+
// TODO: #22835 Use undefined instead of any (breaking change)
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
30
|
export class ConsensusQueueClass extends ConsensusOrderedCollection {
|
|
29
31
|
/**
|
|
30
32
|
* Constructs a new consensus queue. If the object is non-local an id and service interfaces will
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consensusQueue.js","sourceRoot":"","sources":["../src/consensusQueue.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAE7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;GAEG;AACH,MAAM,iBAAqB,SAAQ,iBAAoB;IAC/C,GAAG,CAAC,KAAQ;QAClB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAEM,MAAM;QACZ,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,EAAO,CAAC;IAC/B,CAAC;CACD;AAED;;;;;;GAMG;AACH,MAAM,OAAO,mBAA6B,SAAQ,0BAA6B;IAC9E;;;OAGG;IACH,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B;QAE9B,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,iBAAiB,EAAK,CAAC,CAAC;IAC5D,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n} from \"@fluidframework/datastore-definitions/internal\";\n\nimport { ConsensusOrderedCollection } from \"./consensusOrderedCollection.js\";\nimport { IOrderedCollection } from \"./interfaces.js\";\nimport { SnapshotableArray } from \"./snapshotableArray.js\";\n\n/**\n * An JS array based queue implementation that is the backing data structure for ConsensusQueue\n */\nclass SnapshotableQueue<T> extends SnapshotableArray<T> implements IOrderedCollection<T> {\n\tpublic add(value: T) {\n\t\tthis.data.push(value);\n\t}\n\n\tpublic remove(): T {\n\t\tif (this.size() === 0) {\n\t\t\tthrow new Error(\"SnapshotableQueue is empty\");\n\t\t}\n\t\treturn this.data.shift() as T;\n\t}\n}\n\n/**\n * Implementation of a consensus stack\n *\n * An derived type of ConsensusOrderedCollection with a queue as the backing data and order.\n * @legacy\n * @alpha\n */\nexport class ConsensusQueueClass<T = any> extends ConsensusOrderedCollection<T> {\n\t/**\n\t * Constructs a new consensus queue. If the object is non-local an id and service interfaces will\n\t * be provided\n\t */\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, new SnapshotableQueue<T>());\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"consensusQueue.js","sourceRoot":"","sources":["../src/consensusQueue.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAE7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;GAEG;AACH,MAAM,iBAAqB,SAAQ,iBAAoB;IAC/C,GAAG,CAAC,KAAQ;QAClB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAEM,MAAM;QACZ,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,EAAO,CAAC;IAC/B,CAAC;CACD;AAED;;;;;;GAMG;AACH,8DAA8D;AAC9D,8DAA8D;AAC9D,MAAM,OAAO,mBAA6B,SAAQ,0BAA6B;IAC9E;;;OAGG;IACH,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B;QAE9B,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,iBAAiB,EAAK,CAAC,CAAC;IAC5D,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n} from \"@fluidframework/datastore-definitions/internal\";\n\nimport { ConsensusOrderedCollection } from \"./consensusOrderedCollection.js\";\nimport { IOrderedCollection } from \"./interfaces.js\";\nimport { SnapshotableArray } from \"./snapshotableArray.js\";\n\n/**\n * An JS array based queue implementation that is the backing data structure for ConsensusQueue\n */\nclass SnapshotableQueue<T> extends SnapshotableArray<T> implements IOrderedCollection<T> {\n\tpublic add(value: T): void {\n\t\tthis.data.push(value);\n\t}\n\n\tpublic remove(): T {\n\t\tif (this.size() === 0) {\n\t\t\tthrow new Error(\"SnapshotableQueue is empty\");\n\t\t}\n\t\treturn this.data.shift() as T;\n\t}\n}\n\n/**\n * Implementation of a consensus stack\n *\n * An derived type of ConsensusOrderedCollection with a queue as the backing data and order.\n * @legacy\n * @alpha\n */\n// TODO: #22835 Use undefined instead of any (breaking change)\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class ConsensusQueueClass<T = any> extends ConsensusOrderedCollection<T> {\n\t/**\n\t * Constructs a new consensus queue. If the object is non-local an id and service interfaces will\n\t * be provided\n\t */\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, new SnapshotableQueue<T>());\n\t}\n}\n"]}
|
package/lib/interfaces.d.ts.map
CHANGED
|
@@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.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAaH;;;GAGG;AACH,MAAM,CAAN,IAAY,eAGX;AAHD,WAAY,eAAe;IAC1B,2DAAO,CAAA;IACP,6DAAQ,CAAA;AACT,CAAC,EAHW,eAAe,KAAf,eAAe,QAG1B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIChannelAttributes,\n\tIChannelFactory,\n\tIFluidDataStoreRuntime,\n\tIChannelServices,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport {\n\tISharedObject,\n\tISharedObjectEvents,\n} from \"@fluidframework/shared-object-base/internal\";\n\n/**\n * @legacy\n * @alpha\n */\nexport enum ConsensusResult {\n\tRelease,\n\tComplete,\n}\n\n/**\n * Callback provided to acquire() and waitAndAcquire() methods.\n * @returns ConsensusResult indicating whether item was completed, or releases back to the queue.\n * @legacy\n * @alpha\n */\nexport type ConsensusCallback<T> = (value: T) => Promise<ConsensusResult>;\n\n/**\n * Consensus Ordered Collection channel factory interface\n *\n * Extends the base IChannelFactory to return a more definite type of IConsensusOrderedCollection\n * Use for the runtime to create and load distributed data structure by type name of each channel\n * @internal\n */\nexport interface IConsensusOrderedCollectionFactory extends IChannelFactory {\n\tload(\n\t\tdocument: IFluidDataStoreRuntime,\n\t\tid: string,\n\t\tservices: IChannelServices,\n\t\tattributes: IChannelAttributes,\n\t): Promise<IConsensusOrderedCollection>;\n\n\tcreate(document: IFluidDataStoreRuntime, id: string): IConsensusOrderedCollection;\n}\n\n/**\n * Events notifying about addition, acquisition, release and completion of items\n * @legacy\n * @alpha\n */\nexport interface IConsensusOrderedCollectionEvents<T> extends ISharedObjectEvents {\n\t/**\n\t * Event fires when new item is added to the queue or\n\t * an item previously acquired is returned back to a queue (including client loosing connection)\n\t * @param newlyAdded - indicates if it's newly added item of previously acquired item\n\t */\n\t(event: \"add\", listener: (value: T, newlyAdded: boolean) => void): this;\n\t/**\n\t * Event fires when a client acquired an item\n\t * Fires both for locally acquired items, as well as items acquired by remote clients\n\t */\n\t(event: \"acquire\", listener: (value: T, clientId?: string) => void): this;\n\n\t/**\n\t * \"Complete event fires when a client completes an item.\n\t */\n\t(event: \"complete\", listener: (value: T) => void): this;\n\n\t/**\n\t * Event fires when locally acquired item is being released back to the queue.\n\t * Please note that release process is asynchronous, so it takes a while for it to happen\n\t * (\"add\" event will be fired as result of it)\n\t * @param intentional - indicates whether release was intentional (result of returning\n\t * ConsensusResult.Release from callback) or it happened as result of lost connection.\n\t */\n\t(event: \"localRelease\", listener: (value: T, intentional: boolean) => void): this;\n}\n\n/**\n * Consensus Ordered Collection interface\n *\n * An consensus ordered collection is a distributed data structure, which\n * holds a collection of JSON-able or handles, and has a\n * deterministic add/remove order.\n *\n * @remarks\n * The order the server receive the add/remove operation determines the\n * order those operation are applied to the collection. Different clients\n * issuing `add` or `acquire` operations at the same time will be sequenced.\n * The order dictates which `add` is done first, thus determining the order\n * in which it appears in the collection. It also determines which client\n * will get the first removed item, etc. All operations are asynchronous.\n * A function `waitAndAcquire` is provided to wait for and remove an entry in the collection.\n *\n * As a client acquires an item, it processes it and then returns a value (via callback)\n * indicating whether it has completed processing the item, or whether the item should be\n * released back to the collection for another client to process.\n *\n * All objects added to the collection will be cloned (via JSON).\n * They will not be references to the original input object. Thus changed to\n * the input object will not reflect the object in the collection.\n * @legacy\n * @alpha\n */\nexport interface IConsensusOrderedCollection<T = any>\n\textends ISharedObject<IConsensusOrderedCollectionEvents<T>> {\n\t/**\n\t * Adds a value to the collection\n\t */\n\tadd(value: T): Promise<void>;\n\n\t/**\n\t * Retrieves a value from the collection.\n\t * @returns Returns true (and calls callback with acquired value) if collection was not empty.\n\t * Otherwise returns false.\n\t */\n\tacquire(callback: ConsensusCallback<T>): Promise<boolean>;\n\n\t/**\n\t * Wait for a value to be available and remove it from the consensus collection\n\t * Calls callback with retrieved value.\n\t */\n\twaitAndAcquire(callback: ConsensusCallback<T>): Promise<void>;\n}\n\n/**\n * Interface for object that can be snapshoted\n *\n * TODO: move this to be use in other place\n * TODO: currently input and output is not symmetrical, can they become symmetrical?\n * @legacy\n * @alpha\n */\nexport interface ISnapshotable<T> {\n\tasArray(): T[];\n\n\tloadFrom(values: T[]): void;\n}\n\n/**\n * Ordered Collection interface\n *\n * Collection of objects that has deterministic add and remove ordering.\n * Object implementing this interface can be used as the data backing\n * for the ConsensusOrderedCollection\n * @legacy\n * @alpha\n */\nexport interface IOrderedCollection<T = any> extends ISnapshotable<T> {\n\t/**\n\t * Adds a value to the collection\n\t */\n\tadd(value: T);\n\n\t/**\n\t * Retrieves a value from the collection.\n\t */\n\tremove(): T;\n\n\t/**\n\t * Return the size of the collection\n\t */\n\tsize(): number;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAaH;;;GAGG;AACH,MAAM,CAAN,IAAY,eAGX;AAHD,WAAY,eAAe;IAC1B,2DAAO,CAAA;IACP,6DAAQ,CAAA;AACT,CAAC,EAHW,eAAe,KAAf,eAAe,QAG1B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIChannelAttributes,\n\tIChannelFactory,\n\tIFluidDataStoreRuntime,\n\tIChannelServices,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport {\n\tISharedObject,\n\tISharedObjectEvents,\n} from \"@fluidframework/shared-object-base/internal\";\n\n/**\n * @legacy\n * @alpha\n */\nexport enum ConsensusResult {\n\tRelease,\n\tComplete,\n}\n\n/**\n * Callback provided to acquire() and waitAndAcquire() methods.\n * @returns ConsensusResult indicating whether item was completed, or releases back to the queue.\n * @legacy\n * @alpha\n */\nexport type ConsensusCallback<T> = (value: T) => Promise<ConsensusResult>;\n\n/**\n * Consensus Ordered Collection channel factory interface\n *\n * Extends the base IChannelFactory to return a more definite type of IConsensusOrderedCollection\n * Use for the runtime to create and load distributed data structure by type name of each channel\n * @internal\n */\nexport interface IConsensusOrderedCollectionFactory extends IChannelFactory {\n\tload(\n\t\tdocument: IFluidDataStoreRuntime,\n\t\tid: string,\n\t\tservices: IChannelServices,\n\t\tattributes: IChannelAttributes,\n\t): Promise<IConsensusOrderedCollection>;\n\n\tcreate(document: IFluidDataStoreRuntime, id: string): IConsensusOrderedCollection;\n}\n\n/**\n * Events notifying about addition, acquisition, release and completion of items\n * @legacy\n * @alpha\n */\nexport interface IConsensusOrderedCollectionEvents<T> extends ISharedObjectEvents {\n\t/**\n\t * Event fires when new item is added to the queue or\n\t * an item previously acquired is returned back to a queue (including client loosing connection)\n\t * @param newlyAdded - indicates if it's newly added item of previously acquired item\n\t */\n\t(event: \"add\", listener: (value: T, newlyAdded: boolean) => void): this;\n\t/**\n\t * Event fires when a client acquired an item\n\t * Fires both for locally acquired items, as well as items acquired by remote clients\n\t */\n\t(event: \"acquire\", listener: (value: T, clientId?: string) => void): this;\n\n\t/**\n\t * \"Complete event fires when a client completes an item.\n\t */\n\t(event: \"complete\", listener: (value: T) => void): this;\n\n\t/**\n\t * Event fires when locally acquired item is being released back to the queue.\n\t * Please note that release process is asynchronous, so it takes a while for it to happen\n\t * (\"add\" event will be fired as result of it)\n\t * @param intentional - indicates whether release was intentional (result of returning\n\t * ConsensusResult.Release from callback) or it happened as result of lost connection.\n\t */\n\t(event: \"localRelease\", listener: (value: T, intentional: boolean) => void): this;\n}\n\n/**\n * Consensus Ordered Collection interface\n *\n * An consensus ordered collection is a distributed data structure, which\n * holds a collection of JSON-able or handles, and has a\n * deterministic add/remove order.\n *\n * @remarks\n * The order the server receive the add/remove operation determines the\n * order those operation are applied to the collection. Different clients\n * issuing `add` or `acquire` operations at the same time will be sequenced.\n * The order dictates which `add` is done first, thus determining the order\n * in which it appears in the collection. It also determines which client\n * will get the first removed item, etc. All operations are asynchronous.\n * A function `waitAndAcquire` is provided to wait for and remove an entry in the collection.\n *\n * As a client acquires an item, it processes it and then returns a value (via callback)\n * indicating whether it has completed processing the item, or whether the item should be\n * released back to the collection for another client to process.\n *\n * All objects added to the collection will be cloned (via JSON).\n * They will not be references to the original input object. Thus changed to\n * the input object will not reflect the object in the collection.\n * @legacy\n * @alpha\n */\n// TODO: #22835 Use undefined instead of any (breaking change)\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface IConsensusOrderedCollection<T = any>\n\textends ISharedObject<IConsensusOrderedCollectionEvents<T>> {\n\t/**\n\t * Adds a value to the collection\n\t */\n\tadd(value: T): Promise<void>;\n\n\t/**\n\t * Retrieves a value from the collection.\n\t * @returns Returns true (and calls callback with acquired value) if collection was not empty.\n\t * Otherwise returns false.\n\t */\n\tacquire(callback: ConsensusCallback<T>): Promise<boolean>;\n\n\t/**\n\t * Wait for a value to be available and remove it from the consensus collection\n\t * Calls callback with retrieved value.\n\t */\n\twaitAndAcquire(callback: ConsensusCallback<T>): Promise<void>;\n}\n\n/**\n * Interface for object that can be snapshoted\n *\n * TODO: move this to be use in other place\n * TODO: currently input and output is not symmetrical, can they become symmetrical?\n * @legacy\n * @alpha\n */\nexport interface ISnapshotable<T> {\n\tasArray(): T[];\n\n\tloadFrom(values: T[]): void;\n}\n\n/**\n * Ordered Collection interface\n *\n * Collection of objects that has deterministic add and remove ordering.\n * Object implementing this interface can be used as the data backing\n * for the ConsensusOrderedCollection\n * @legacy\n * @alpha\n */\n// TODO: #22835 Use undefined instead of any (breaking change)\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface IOrderedCollection<T = any> extends ISnapshotable<T> {\n\t/**\n\t * Adds a value to the collection\n\t */\n\tadd(value: T);\n\n\t/**\n\t * Retrieves a value from the collection.\n\t */\n\tremove(): T;\n\n\t/**\n\t * Return the size of the collection\n\t */\n\tsize(): number;\n}\n"]}
|
package/lib/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/ordered-collection";
|
|
8
|
-
export declare const pkgVersion = "2.
|
|
8
|
+
export declare const pkgVersion = "2.20.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/lib/packageVersion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,oCAAoC,CAAC;AAC5D,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/ordered-collection\";\nexport const pkgVersion = \"2.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,oCAAoC,CAAC;AAC5D,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/ordered-collection\";\nexport const pkgVersion = \"2.20.0\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshotableArray.d.ts","sourceRoot":"","sources":["../src/snapshotableArray.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,qBAAa,iBAAiB,CAAC,CAAC,CAAE,SAAQ,KAAK;IAC9C,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,CAAM;IAElB,OAAO;
|
|
1
|
+
{"version":3,"file":"snapshotableArray.d.ts","sourceRoot":"","sources":["../src/snapshotableArray.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,qBAAa,iBAAiB,CAAC,CAAC,CAAE,SAAQ,KAAK;IAC9C,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,CAAM;IAElB,OAAO,IAAI,CAAC,EAAE;IAIR,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAKxC,IAAI,IAAI,MAAM;CAGrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshotableArray.js","sourceRoot":"","sources":["../src/snapshotableArray.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,MAAM,OAAO,iBAAqB,SAAQ,KAAK;IAA/C;;QACW,SAAI,GAAQ,EAAE,CAAC;IAc1B,CAAC;IAZO,OAAO;QACb,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,IAAS;QAC9B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,KAAK,CAAC,oDAAoD,CAAC,CAAC;QAC3F,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;IAEM,IAAI;QACV,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IACzB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nexport class SnapshotableArray<T> extends Array {\n\tprotected data: T[] = [];\n\n\tpublic asArray() {\n\t\treturn this.data;\n\t}\n\n\tpublic async loadFrom(from: T[]): Promise<void> {\n\t\tassert(this.data.length === 0, 0x06b /* \"Loading snapshot into a non-empty collection\" */);\n\t\tthis.data = from;\n\t}\n\n\tpublic size(): number {\n\t\treturn this.data.length;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"snapshotableArray.js","sourceRoot":"","sources":["../src/snapshotableArray.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,MAAM,OAAO,iBAAqB,SAAQ,KAAK;IAA/C;;QACW,SAAI,GAAQ,EAAE,CAAC;IAc1B,CAAC;IAZO,OAAO;QACb,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,IAAS;QAC9B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,KAAK,CAAC,oDAAoD,CAAC,CAAC;QAC3F,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;IAEM,IAAI;QACV,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IACzB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nexport class SnapshotableArray<T> extends Array {\n\tprotected data: T[] = [];\n\n\tpublic asArray(): T[] {\n\t\treturn this.data;\n\t}\n\n\tpublic async loadFrom(from: T[]): Promise<void> {\n\t\tassert(this.data.length === 0, 0x06b /* \"Loading snapshot into a non-empty collection\" */);\n\t\tthis.data = from;\n\t}\n\n\tpublic size(): number {\n\t\treturn this.data.length;\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/ordered-collection",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.0",
|
|
4
4
|
"description": "Consensus Collection",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -69,30 +69,30 @@
|
|
|
69
69
|
"temp-directory": "nyc/.nyc_output"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@fluid-internal/client-utils": "~2.
|
|
73
|
-
"@fluidframework/core-interfaces": "~2.
|
|
74
|
-
"@fluidframework/core-utils": "~2.
|
|
75
|
-
"@fluidframework/datastore-definitions": "~2.
|
|
76
|
-
"@fluidframework/driver-definitions": "~2.
|
|
77
|
-
"@fluidframework/runtime-definitions": "~2.
|
|
78
|
-
"@fluidframework/runtime-utils": "~2.
|
|
79
|
-
"@fluidframework/shared-object-base": "~2.
|
|
80
|
-
"@fluidframework/telemetry-utils": "~2.
|
|
72
|
+
"@fluid-internal/client-utils": "~2.20.0",
|
|
73
|
+
"@fluidframework/core-interfaces": "~2.20.0",
|
|
74
|
+
"@fluidframework/core-utils": "~2.20.0",
|
|
75
|
+
"@fluidframework/datastore-definitions": "~2.20.0",
|
|
76
|
+
"@fluidframework/driver-definitions": "~2.20.0",
|
|
77
|
+
"@fluidframework/runtime-definitions": "~2.20.0",
|
|
78
|
+
"@fluidframework/runtime-utils": "~2.20.0",
|
|
79
|
+
"@fluidframework/shared-object-base": "~2.20.0",
|
|
80
|
+
"@fluidframework/telemetry-utils": "~2.20.0",
|
|
81
81
|
"uuid": "^9.0.0"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@arethetypeswrong/cli": "^0.17.1",
|
|
85
85
|
"@biomejs/biome": "~1.9.3",
|
|
86
|
-
"@fluid-internal/mocha-test-setup": "~2.
|
|
87
|
-
"@fluid-private/test-dds-utils": "~2.
|
|
86
|
+
"@fluid-internal/mocha-test-setup": "~2.20.0",
|
|
87
|
+
"@fluid-private/test-dds-utils": "~2.20.0",
|
|
88
88
|
"@fluid-tools/build-cli": "^0.51.0",
|
|
89
89
|
"@fluidframework/build-common": "^2.0.3",
|
|
90
90
|
"@fluidframework/build-tools": "^0.51.0",
|
|
91
91
|
"@fluidframework/eslint-config-fluid": "^5.6.0",
|
|
92
|
-
"@fluidframework/ordered-collection-previous": "npm:@fluidframework/ordered-collection@2.
|
|
93
|
-
"@fluidframework/test-runtime-utils": "~2.
|
|
92
|
+
"@fluidframework/ordered-collection-previous": "npm:@fluidframework/ordered-collection@2.13.0",
|
|
93
|
+
"@fluidframework/test-runtime-utils": "~2.20.0",
|
|
94
94
|
"@microsoft/api-extractor": "7.47.8",
|
|
95
|
-
"@types/mocha": "^
|
|
95
|
+
"@types/mocha": "^10.0.10",
|
|
96
96
|
"@types/node": "^18.19.0",
|
|
97
97
|
"@types/uuid": "^9.0.2",
|
|
98
98
|
"c8": "^8.0.1",
|
|
@@ -76,7 +76,9 @@ type IConsensusOrderedCollectionOperation<T> =
|
|
|
76
76
|
| IConsensusOrderedCollectionCompleteOperation
|
|
77
77
|
| IConsensusOrderedCollectionReleaseOperation;
|
|
78
78
|
|
|
79
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* The type of the resolve function to call after the local operation is acknowledged.
|
|
81
|
+
*/
|
|
80
82
|
type PendingResolve<T> = (value: IConsensusOrderedCollectionValue<T> | undefined) => void;
|
|
81
83
|
|
|
82
84
|
/**
|
|
@@ -98,6 +100,9 @@ const idForLocalUnattachedClient = undefined;
|
|
|
98
100
|
* @legacy
|
|
99
101
|
* @alpha
|
|
100
102
|
*/
|
|
103
|
+
|
|
104
|
+
// TODO: #22835 Use undefined instead of any (breaking change)
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
101
106
|
export class ConsensusOrderedCollection<T = any>
|
|
102
107
|
extends SharedObject<IConsensusOrderedCollectionEvents<T>>
|
|
103
108
|
implements IConsensusOrderedCollection<T>
|
|
@@ -163,15 +168,18 @@ export class ConsensusOrderedCollection<T = any>
|
|
|
163
168
|
const res = await callback(result.value);
|
|
164
169
|
|
|
165
170
|
switch (res) {
|
|
166
|
-
case ConsensusResult.Complete:
|
|
171
|
+
case ConsensusResult.Complete: {
|
|
167
172
|
await this.complete(result.acquireId);
|
|
168
173
|
break;
|
|
169
|
-
|
|
174
|
+
}
|
|
175
|
+
case ConsensusResult.Release: {
|
|
170
176
|
this.release(result.acquireId);
|
|
171
177
|
this.emit("localRelease", result.value, true /* intentional */);
|
|
172
178
|
break;
|
|
173
|
-
|
|
179
|
+
}
|
|
180
|
+
default: {
|
|
174
181
|
unreachableCase(res);
|
|
182
|
+
}
|
|
175
183
|
}
|
|
176
184
|
|
|
177
185
|
return true;
|
|
@@ -199,16 +207,16 @@ export class ConsensusOrderedCollection<T = any>
|
|
|
199
207
|
const builder = new SummaryTreeBuilder();
|
|
200
208
|
let blobContent = this.serializeValue(this.data.asArray(), serializer);
|
|
201
209
|
builder.addBlob(snapshotFileNameData, blobContent);
|
|
202
|
-
blobContent = this.serializeValue(
|
|
210
|
+
blobContent = this.serializeValue([...this.jobTracking.entries()], serializer);
|
|
203
211
|
builder.addBlob(snapshotFileNameTracking, blobContent);
|
|
204
212
|
return builder.getSummaryTree();
|
|
205
213
|
}
|
|
206
214
|
|
|
207
|
-
protected isActive() {
|
|
215
|
+
protected isActive(): boolean {
|
|
208
216
|
return this.runtime.connected && this.deltaManager.active;
|
|
209
217
|
}
|
|
210
218
|
|
|
211
|
-
protected async complete(acquireId: string) {
|
|
219
|
+
protected async complete(acquireId: string): Promise<void> {
|
|
212
220
|
if (!this.isAttached()) {
|
|
213
221
|
this.completeCore(acquireId);
|
|
214
222
|
return;
|
|
@@ -223,7 +231,7 @@ export class ConsensusOrderedCollection<T = any>
|
|
|
223
231
|
}
|
|
224
232
|
}
|
|
225
233
|
|
|
226
|
-
protected completeCore(acquireId: string) {
|
|
234
|
+
protected completeCore(acquireId: string): void {
|
|
227
235
|
// Note: item may be no longer in jobTracking and returned back to queue!
|
|
228
236
|
const rec = this.jobTracking.get(acquireId);
|
|
229
237
|
if (rec !== undefined) {
|
|
@@ -232,7 +240,7 @@ export class ConsensusOrderedCollection<T = any>
|
|
|
232
240
|
}
|
|
233
241
|
}
|
|
234
242
|
|
|
235
|
-
protected release(acquireId: string) {
|
|
243
|
+
protected release(acquireId: string): void {
|
|
236
244
|
if (!this.isAttached()) {
|
|
237
245
|
this.releaseCore(acquireId);
|
|
238
246
|
return;
|
|
@@ -249,7 +257,7 @@ export class ConsensusOrderedCollection<T = any>
|
|
|
249
257
|
}
|
|
250
258
|
}
|
|
251
259
|
|
|
252
|
-
protected releaseCore(acquireId: string) {
|
|
260
|
+
protected releaseCore(acquireId: string): void {
|
|
253
261
|
// Note: item may be no longer in jobTracking and returned back to queue!
|
|
254
262
|
const rec = this.jobTracking.get(acquireId);
|
|
255
263
|
if (rec !== undefined) {
|
|
@@ -270,7 +278,9 @@ export class ConsensusOrderedCollection<T = any>
|
|
|
270
278
|
const blob = await storage.readBlob(snapshotFileNameTracking);
|
|
271
279
|
const rawContentTracking = bufferToString(blob, "utf8");
|
|
272
280
|
const content = this.deserializeValue(rawContentTracking, this.serializer);
|
|
273
|
-
this.jobTracking = new Map(
|
|
281
|
+
this.jobTracking = new Map(
|
|
282
|
+
content as Iterable<[string, { value: T; clientId: string | undefined }]>,
|
|
283
|
+
);
|
|
274
284
|
|
|
275
285
|
assert(
|
|
276
286
|
this.data.size() === 0,
|
|
@@ -282,7 +292,7 @@ export class ConsensusOrderedCollection<T = any>
|
|
|
282
292
|
this.data.loadFrom(content2);
|
|
283
293
|
}
|
|
284
294
|
|
|
285
|
-
protected onDisconnect() {
|
|
295
|
+
protected onDisconnect(): void {
|
|
286
296
|
for (const [, { value, clientId }] of this.jobTracking) {
|
|
287
297
|
if (clientId === this.runtime.clientId) {
|
|
288
298
|
this.emit("localRelease", value, false /* intentional */);
|
|
@@ -294,33 +304,38 @@ export class ConsensusOrderedCollection<T = any>
|
|
|
294
304
|
message: ISequencedDocumentMessage,
|
|
295
305
|
local: boolean,
|
|
296
306
|
localOpMetadata: unknown,
|
|
297
|
-
) {
|
|
307
|
+
): void {
|
|
298
308
|
if (message.type === MessageType.Operation) {
|
|
299
309
|
const op = message.contents as IConsensusOrderedCollectionOperation<T>;
|
|
300
310
|
let value: IConsensusOrderedCollectionValue<T> | undefined;
|
|
301
311
|
switch (op.opName) {
|
|
302
|
-
case "add":
|
|
303
|
-
if (op.deserializedValue
|
|
304
|
-
this.addCore(op.deserializedValue);
|
|
305
|
-
} else {
|
|
312
|
+
case "add": {
|
|
313
|
+
if (op.deserializedValue === undefined) {
|
|
306
314
|
this.addCore(this.deserializeValue(op.value, this.serializer) as T);
|
|
315
|
+
} else {
|
|
316
|
+
this.addCore(op.deserializedValue);
|
|
307
317
|
}
|
|
308
318
|
break;
|
|
319
|
+
}
|
|
309
320
|
|
|
310
|
-
case "acquire":
|
|
321
|
+
case "acquire": {
|
|
311
322
|
value = this.acquireCore(op.acquireId, message.clientId ?? undefined);
|
|
312
323
|
break;
|
|
324
|
+
}
|
|
313
325
|
|
|
314
|
-
case "complete":
|
|
326
|
+
case "complete": {
|
|
315
327
|
this.completeCore(op.acquireId);
|
|
316
328
|
break;
|
|
329
|
+
}
|
|
317
330
|
|
|
318
|
-
case "release":
|
|
331
|
+
case "release": {
|
|
319
332
|
this.releaseCore(op.acquireId);
|
|
320
333
|
break;
|
|
334
|
+
}
|
|
321
335
|
|
|
322
|
-
default:
|
|
336
|
+
default: {
|
|
323
337
|
unreachableCase(op);
|
|
338
|
+
}
|
|
324
339
|
}
|
|
325
340
|
if (local) {
|
|
326
341
|
// Resolve the pending promise for this operation now that we have received an ack for it.
|
|
@@ -345,7 +360,7 @@ export class ConsensusOrderedCollection<T = any>
|
|
|
345
360
|
).catch((error) => undefined);
|
|
346
361
|
}
|
|
347
362
|
|
|
348
|
-
private addCore(value: T) {
|
|
363
|
+
private addCore(value: T): void {
|
|
349
364
|
this.data.add(value);
|
|
350
365
|
this.emit("add", value, true /* newlyAdded */);
|
|
351
366
|
}
|
|
@@ -381,7 +396,7 @@ export class ConsensusOrderedCollection<T = any>
|
|
|
381
396
|
});
|
|
382
397
|
}
|
|
383
398
|
|
|
384
|
-
private removeClient(clientIdToRemove?: string) {
|
|
399
|
+
private removeClient(clientIdToRemove?: string): void {
|
|
385
400
|
const added: T[] = [];
|
|
386
401
|
for (const [acquireId, { value, clientId }] of this.jobTracking) {
|
|
387
402
|
if (clientId === clientIdToRemove) {
|
|
@@ -396,12 +411,11 @@ export class ConsensusOrderedCollection<T = any>
|
|
|
396
411
|
added.map((value) => this.emit("add", value, false /* newlyAdded */));
|
|
397
412
|
}
|
|
398
413
|
|
|
399
|
-
private serializeValue(value, serializer: IFluidSerializer) {
|
|
414
|
+
private serializeValue(value, serializer: IFluidSerializer): string {
|
|
400
415
|
return serializer.stringify(value, this.handle);
|
|
401
416
|
}
|
|
402
417
|
|
|
403
|
-
private deserializeValue(content: string, serializer: IFluidSerializer) {
|
|
404
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
418
|
+
private deserializeValue(content: string, serializer: IFluidSerializer): unknown {
|
|
405
419
|
return serializer.parse(content);
|
|
406
420
|
}
|
|
407
421
|
|
|
@@ -31,11 +31,11 @@ export class ConsensusQueueFactory implements IConsensusOrderedCollectionFactory
|
|
|
31
31
|
packageVersion: pkgVersion,
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
public get type() {
|
|
34
|
+
public get type(): string {
|
|
35
35
|
return ConsensusQueueFactory.Type;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
public get attributes() {
|
|
38
|
+
public get attributes(): IChannelAttributes {
|
|
39
39
|
return ConsensusQueueFactory.Attributes;
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -72,4 +72,6 @@ export const ConsensusQueue = createSharedObjectKind(ConsensusQueueFactory);
|
|
|
72
72
|
* @legacy
|
|
73
73
|
* @alpha
|
|
74
74
|
*/
|
|
75
|
+
// TODO: #22835 Use undefined instead of any (breaking change)
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
77
|
export type ConsensusQueue<T = any> = ConsensusQueueClass<T>;
|
package/src/consensusQueue.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { SnapshotableArray } from "./snapshotableArray.js";
|
|
|
16
16
|
* An JS array based queue implementation that is the backing data structure for ConsensusQueue
|
|
17
17
|
*/
|
|
18
18
|
class SnapshotableQueue<T> extends SnapshotableArray<T> implements IOrderedCollection<T> {
|
|
19
|
-
public add(value: T) {
|
|
19
|
+
public add(value: T): void {
|
|
20
20
|
this.data.push(value);
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -35,6 +35,8 @@ class SnapshotableQueue<T> extends SnapshotableArray<T> implements IOrderedColle
|
|
|
35
35
|
* @legacy
|
|
36
36
|
* @alpha
|
|
37
37
|
*/
|
|
38
|
+
// TODO: #22835 Use undefined instead of any (breaking change)
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
40
|
export class ConsensusQueueClass<T = any> extends ConsensusOrderedCollection<T> {
|
|
39
41
|
/**
|
|
40
42
|
* Constructs a new consensus queue. If the object is non-local an id and service interfaces will
|
package/src/interfaces.ts
CHANGED
|
@@ -108,6 +108,8 @@ export interface IConsensusOrderedCollectionEvents<T> extends ISharedObjectEvent
|
|
|
108
108
|
* @legacy
|
|
109
109
|
* @alpha
|
|
110
110
|
*/
|
|
111
|
+
// TODO: #22835 Use undefined instead of any (breaking change)
|
|
112
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
111
113
|
export interface IConsensusOrderedCollection<T = any>
|
|
112
114
|
extends ISharedObject<IConsensusOrderedCollectionEvents<T>> {
|
|
113
115
|
/**
|
|
@@ -152,6 +154,8 @@ export interface ISnapshotable<T> {
|
|
|
152
154
|
* @legacy
|
|
153
155
|
* @alpha
|
|
154
156
|
*/
|
|
157
|
+
// TODO: #22835 Use undefined instead of any (breaking change)
|
|
158
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
155
159
|
export interface IOrderedCollection<T = any> extends ISnapshotable<T> {
|
|
156
160
|
/**
|
|
157
161
|
* Adds a value to the collection
|
package/src/packageVersion.ts
CHANGED