@fluidframework/ordered-collection 0.59.2000-63294 → 0.59.3000-66610
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/dist/consensusOrderedCollection.js +10 -10
- package/dist/consensusOrderedCollection.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/snapshotableArray.js +1 -1
- package/dist/snapshotableArray.js.map +1 -1
- package/lib/consensusOrderedCollection.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/package.json +13 -12
- package/src/consensusOrderedCollection.ts +2 -2
- package/src/packageVersion.ts +1 -1
|
@@ -40,7 +40,7 @@ class ConsensusOrderedCollection extends shared_object_base_1.SharedObject {
|
|
|
40
40
|
// Disconnect order matters because it defines the order items go back to the queue.
|
|
41
41
|
// So we put items back to queue only when we process our own removeMember event.
|
|
42
42
|
runtime.getQuorum().on("removeMember", (clientId) => {
|
|
43
|
-
common_utils_1.assert(!!clientId, 0x067 /* "Missing clientId for removal!" */);
|
|
43
|
+
(0, common_utils_1.assert)(!!clientId, 0x067 /* "Missing clientId for removal!" */);
|
|
44
44
|
this.removeClient(clientId);
|
|
45
45
|
});
|
|
46
46
|
}
|
|
@@ -79,7 +79,7 @@ class ConsensusOrderedCollection extends shared_object_base_1.SharedObject {
|
|
|
79
79
|
this.release(result.acquireId);
|
|
80
80
|
this.emit("localRelease", result.value, true /* intentional */);
|
|
81
81
|
break;
|
|
82
|
-
default: common_utils_1.unreachableCase(res);
|
|
82
|
+
default: (0, common_utils_1.unreachableCase)(res);
|
|
83
83
|
}
|
|
84
84
|
return true;
|
|
85
85
|
}
|
|
@@ -159,14 +159,14 @@ class ConsensusOrderedCollection extends shared_object_base_1.SharedObject {
|
|
|
159
159
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
|
|
160
160
|
*/
|
|
161
161
|
async loadCore(storage) {
|
|
162
|
-
common_utils_1.assert(this.jobTracking.size === 0, 0x068 /* "On consensusOrderedCollection load, job tracking size > 0" */);
|
|
162
|
+
(0, common_utils_1.assert)(this.jobTracking.size === 0, 0x068 /* "On consensusOrderedCollection load, job tracking size > 0" */);
|
|
163
163
|
const blob = await storage.readBlob(snapshotFileNameTracking);
|
|
164
|
-
const rawContentTracking = common_utils_1.bufferToString(blob, "utf8");
|
|
164
|
+
const rawContentTracking = (0, common_utils_1.bufferToString)(blob, "utf8");
|
|
165
165
|
const content = this.deserializeValue(rawContentTracking, this.serializer);
|
|
166
166
|
this.jobTracking = new Map(content);
|
|
167
|
-
common_utils_1.assert(this.data.size() === 0, 0x069 /* "On consensusOrderedCollection load, data size > 0" */);
|
|
167
|
+
(0, common_utils_1.assert)(this.data.size() === 0, 0x069 /* "On consensusOrderedCollection load, data size > 0" */);
|
|
168
168
|
const blob2 = await storage.readBlob(snapshotFileNameData);
|
|
169
|
-
const rawContentData = common_utils_1.bufferToString(blob2, "utf8");
|
|
169
|
+
const rawContentData = (0, common_utils_1.bufferToString)(blob2, "utf8");
|
|
170
170
|
const content2 = this.deserializeValue(rawContentData, this.serializer);
|
|
171
171
|
this.data.loadFrom(content2);
|
|
172
172
|
}
|
|
@@ -194,7 +194,7 @@ class ConsensusOrderedCollection extends shared_object_base_1.SharedObject {
|
|
|
194
194
|
case "release":
|
|
195
195
|
this.releaseCore(op.acquireId);
|
|
196
196
|
break;
|
|
197
|
-
default: common_utils_1.unreachableCase(op);
|
|
197
|
+
default: (0, common_utils_1.unreachableCase)(op);
|
|
198
198
|
}
|
|
199
199
|
if (local) {
|
|
200
200
|
// Resolve the pending promise for this operation now that we have received an ack for it.
|
|
@@ -204,7 +204,7 @@ class ConsensusOrderedCollection extends shared_object_base_1.SharedObject {
|
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
206
|
async submit(message) {
|
|
207
|
-
common_utils_1.assert(this.isAttached(), 0x06a /* "Trying to submit message while detached!" */);
|
|
207
|
+
(0, common_utils_1.assert)(this.isAttached(), 0x06a /* "Trying to submit message while detached!" */);
|
|
208
208
|
return this.newAckBasedPromise((resolve) => {
|
|
209
209
|
// Send the resolve function as the localOpMetadata. This will be provided back to us when the
|
|
210
210
|
// op is ack'd.
|
|
@@ -232,11 +232,11 @@ class ConsensusOrderedCollection extends shared_object_base_1.SharedObject {
|
|
|
232
232
|
async acquireInternal() {
|
|
233
233
|
if (!this.isAttached()) {
|
|
234
234
|
// can be undefined if queue is empty
|
|
235
|
-
return this.acquireCore(uuid_1.v4(), idForLocalUnattachedClient);
|
|
235
|
+
return this.acquireCore((0, uuid_1.v4)(), idForLocalUnattachedClient);
|
|
236
236
|
}
|
|
237
237
|
return this.submit({
|
|
238
238
|
opName: "acquire",
|
|
239
|
-
acquireId: uuid_1.v4(),
|
|
239
|
+
acquireId: (0, uuid_1.v4)(),
|
|
240
240
|
});
|
|
241
241
|
}
|
|
242
242
|
removeClient(clientIdToRemove) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consensusOrderedCollection.js","sourceRoot":"","sources":["../src/consensusOrderedCollection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAwF;AACxF,+EAA8F;AAM9F,2EAAoF;AAEpF,iEAAmE;AACnE,+BAAkC;AAClC,6CAMsB;AAEtB,MAAM,oBAAoB,GAAG,QAAQ,CAAC;AACtC,MAAM,wBAAwB,GAAG,aAAa,CAAC;AAwD/C,MAAM,0BAA0B,GAAG,SAAS,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAa,0BACT,SAAQ,iCAAkD;IAM1D;;;OAGG;IACH,YACI,EAAU,EACV,OAA+B,EAC/B,UAA8B,EACb,IAA2B;QAE5C,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QAFd,SAAI,GAAJ,IAAI,CAAuB;QAbhD;;WAEG;QACK,gBAAW,GAAuB,IAAI,G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AA8C;YAC5D,MAAM,EAAE,SAAS;YACjB,SAAS,EAAE,SAAI,EAAE;SACpB,CAAC,CAAC;IACP,CAAC;IAEO,YAAY,CAAC,gBAAyB;QAC1C,MAAM,KAAK,GAAQ,EAAE,CAAC;QACtB,KAAK,MAAM,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE;YAC7D,IAAI,QAAQ,KAAK,gBAAgB,EAAE;gBAC/B,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;aACrB;SACJ;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;IAC1E,CAAC;IAEO,cAAc,CAAC,KAAK,EAAE,UAA4B;QACtD,OAAO,UAAU,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC;IAEO,gBAAgB,CAAC,OAAe,EAAE,UAA4B;QAClE,+DAA+D;QAC/D,OAAO,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAES,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ;AA9RD,gEA8RC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert , bufferToString, unreachableCase } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n} from \"@fluidframework/datastore-definitions\";\nimport { IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n ConsensusCallback,\n ConsensusResult,\n IConsensusOrderedCollection,\n IOrderedCollection,\n IConsensusOrderedCollectionEvents,\n} from \"./interfaces\";\n\nconst snapshotFileNameData = \"header\";\nconst snapshotFileNameTracking = \"jobTracking\";\n\ninterface IConsensusOrderedCollectionValue<T> {\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n readonly acquireId: string;\n\n // The actual value\n readonly value: T;\n}\n\n/**\n * An operation for consensus ordered collection\n */\ninterface IConsensusOrderedCollectionAddOperation {\n opName: \"add\";\n // serialized value\n value: string;\n}\n\ninterface IConsensusOrderedCollectionAcquireOperation {\n opName: \"acquire\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ninterface IConsensusOrderedCollectionCompleteOperation {\n opName: \"complete\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ninterface IConsensusOrderedCollectionReleaseOperation {\n opName: \"release\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ntype IConsensusOrderedCollectionOperation =\n IConsensusOrderedCollectionAddOperation |\n IConsensusOrderedCollectionAcquireOperation |\n IConsensusOrderedCollectionCompleteOperation |\n 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 */\nexport class ConsensusOrderedCollection<T = any>\n extends SharedObject<IConsensusOrderedCollectionEvents<T>> implements IConsensusOrderedCollection<T> {\n /**\n * The set of values that have been acquired but not yet completed or released\n */\n private jobTracking: JobTrackingInfo<T> = new Map();\n\n /**\n * Constructs a new consensus collection. If the object is non-local an id and service interfaces will\n * be provided\n */\n protected constructor(\n id: string,\n runtime: IFluidDataStoreRuntime,\n attributes: IChannelAttributes,\n private readonly data: IOrderedCollection<T>,\n ) {\n super(id, runtime, attributes);\n\n // We can't simply call this.removeClient(this.runtime.clientId) in on runtime disconnected,\n // because other clients may disconnect concurrently.\n // Disconnect order matters because it defines the order items go back to the queue.\n // So we put items back to queue only when we process our own removeMember event.\n runtime.getQuorum().on(\"removeMember\", (clientId: string) => {\n assert(!!clientId, 0x067 /* \"Missing clientId for removal!\" */);\n this.removeClient(clientId);\n });\n }\n\n /**\n * Add a value to the consensus collection.\n */\n public async add(value: T): Promise<void> {\n const valueSer = this.serializeValue(value, this.serializer);\n\n if (!this.isAttached()) {\n // For the case where this is not attached yet, explicitly JSON\n // clone the value to match the behavior of going thru the wire.\n const addValue = this.deserializeValue(valueSer, this.serializer) as T;\n this.addCore(addValue);\n return;\n }\n\n await this.submit<IConsensusOrderedCollectionAddOperation>({\n opName: \"add\",\n value: valueSer,\n });\n }\n\n /**\n * Remove a value from the consensus collection. If the collection is empty, returns false.\n * Otherwise calls callback with the value\n */\n public async acquire(callback: ConsensusCallback<T>): Promise<boolean> {\n const result = await this.acquireInternal();\n if (result === undefined) {\n return false;\n }\n\n const res = await callback(result.value);\n\n switch (res) {\n case ConsensusResult.Complete:\n await this.complete(result.acquireId);\n break;\n case ConsensusResult.Release:\n this.release(result.acquireId);\n this.emit(\"localRelease\", result.value, true /* intentional */);\n break;\n default: unreachableCase(res);\n }\n\n return true;\n }\n\n /**\n * Wait for a value to be available and acquire it from the consensus collection\n */\n public async waitAndAcquire(callback: ConsensusCallback<T>): Promise<void> {\n do {\n if (this.data.size() === 0) {\n // Wait for new entry before trying to acquire again\n await this.newAckBasedPromise<T>((resolve) => {\n this.once(\"add\", resolve);\n });\n }\n } while (!(await this.acquire(callback)));\n }\n\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n // If we are transitioning from unattached to attached mode,\n // then we are losing all checked out work!\n this.removeClient(idForLocalUnattachedClient);\n\n const builder = new SummaryTreeBuilder();\n let blobContent = this.serializeValue(this.data.asArray(), serializer);\n builder.addBlob(snapshotFileNameData, blobContent);\n blobContent = this.serializeValue(Array.from(this.jobTracking.entries()), serializer);\n builder.addBlob(snapshotFileNameTracking, blobContent);\n return builder.getSummaryTree();\n }\n\n protected isActive() {\n return this.runtime.connected && this.runtime.deltaManager.active;\n }\n\n protected async complete(acquireId: string) {\n if (!this.isAttached()) {\n this.completeCore(acquireId);\n return;\n }\n\n // if not active, this item already was released to queue (as observed by other clients)\n if (this.isActive()) {\n await this.submit<IConsensusOrderedCollectionCompleteOperation>({\n opName: \"complete\",\n acquireId,\n });\n }\n }\n\n protected completeCore(acquireId: string) {\n // Note: item may be no longer in jobTracking and returned back to queue!\n const rec = this.jobTracking.get(acquireId);\n if (rec !== undefined) {\n this.jobTracking.delete(acquireId);\n this.emit(\"complete\", rec.value);\n }\n }\n\n protected release(acquireId: string) {\n if (!this.isAttached()) {\n this.releaseCore(acquireId);\n return;\n }\n\n // if not active, this item already was released to queue (as observed by other clients)\n if (this.isActive()) {\n this.submit<IConsensusOrderedCollectionReleaseOperation>({\n opName: \"release\",\n acquireId,\n }).catch((error) => {\n this.runtime.logger.sendErrorEvent({ eventName: \"ConsensusQueue_release\" }, error);\n });\n }\n }\n\n protected releaseCore(acquireId: string) {\n // Note: item may be no longer in jobTracking and returned back to queue!\n const rec = this.jobTracking.get(acquireId);\n if (rec !== undefined) {\n this.jobTracking.delete(acquireId);\n this.data.add(rec.value);\n this.emit(\"add\", rec.value, false /* newlyAdded */);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n assert(this.jobTracking.size === 0, 0x068 /* \"On consensusOrderedCollection load, job tracking size > 0\" */);\n const blob = await storage.readBlob(snapshotFileNameTracking);\n const rawContentTracking = bufferToString(blob, \"utf8\");\n const content = this.deserializeValue(rawContentTracking, this.serializer);\n this.jobTracking = new Map(content) as JobTrackingInfo<T>;\n\n assert(this.data.size() === 0, 0x069 /* \"On consensusOrderedCollection load, data size > 0\" */);\n const blob2 = await storage.readBlob(snapshotFileNameData);\n const rawContentData = bufferToString(blob2, \"utf8\");\n const content2 = this.deserializeValue(rawContentData, this.serializer) as T[];\n this.data.loadFrom(content2);\n }\n\n protected onDisconnect() {\n for (const [, { value, clientId }] of this.jobTracking) {\n if (clientId === this.runtime.clientId) {\n this.emit(\"localRelease\", value, false /* intentional */);\n }\n }\n }\n\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation) {\n const op: IConsensusOrderedCollectionOperation = message.contents;\n let value: IConsensusOrderedCollectionValue<T> | undefined;\n switch (op.opName) {\n case \"add\":\n this.addCore(this.deserializeValue(op.value, this.serializer) as T);\n break;\n\n case \"acquire\":\n value = this.acquireCore(op.acquireId, message.clientId);\n break;\n\n case \"complete\":\n this.completeCore(op.acquireId);\n break;\n\n case \"release\":\n this.releaseCore(op.acquireId);\n break;\n\n default: unreachableCase(op);\n }\n if (local) {\n // Resolve the pending promise for this operation now that we have received an ack for it.\n const resolve = localOpMetadata as PendingResolve<T>;\n resolve(value);\n }\n }\n }\n\n private async submit<TMessage extends IConsensusOrderedCollectionOperation>(\n message: TMessage,\n ): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n assert(this.isAttached(), 0x06a /* \"Trying to submit message while detached!\" */);\n\n return this.newAckBasedPromise<IConsensusOrderedCollectionValue<T> | undefined>((resolve) => {\n // Send the resolve function as the localOpMetadata. This will be provided back to us when the\n // op is ack'd.\n this.submitLocalMessage(message, resolve);\n // If we fail due to runtime being disposed, it's better to return undefined then unhandled exception.\n }).catch((error) => undefined);\n }\n\n private addCore(value: T) {\n this.data.add(value);\n this.emit(\"add\", value, true /* newlyAdded */);\n }\n\n private acquireCore(acquireId: string, clientId?: string): IConsensusOrderedCollectionValue<T> | undefined {\n if (this.data.size() === 0) {\n return undefined;\n }\n const value = this.data.remove();\n\n const value2: IConsensusOrderedCollectionValue<T> = {\n acquireId,\n value,\n };\n this.jobTracking.set(value2.acquireId, { value, clientId });\n\n this.emit(\"acquire\", value, clientId);\n return value2;\n }\n\n private async acquireInternal(): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n if (!this.isAttached()) {\n // can be undefined if queue is empty\n return this.acquireCore(uuid(), idForLocalUnattachedClient);\n }\n\n return this.submit<IConsensusOrderedCollectionAcquireOperation>({\n opName: \"acquire\",\n acquireId: uuid(),\n });\n }\n\n private removeClient(clientIdToRemove?: string) {\n const added: T[] = [];\n for (const [acquireId, { value, clientId }] of this.jobTracking) {\n if (clientId === clientIdToRemove) {\n this.jobTracking.delete(acquireId);\n this.data.add(value);\n added.push(value);\n }\n }\n\n // Raise all events only after all state changes are completed,\n // to guarantee same ordering of operations if collection is manipulated from events.\n added.map((value) => this.emit(\"add\", value, false /* newlyAdded */));\n }\n\n private serializeValue(value, serializer: IFluidSerializer) {\n return serializer.stringify(value, this.handle);\n }\n\n private deserializeValue(content: string, serializer: IFluidSerializer) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return serializer.parse(content);\n }\n\n protected applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"consensusOrderedCollection.js","sourceRoot":"","sources":["../src/consensusOrderedCollection.ts"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;IAEO,cAAc,CAAC,KAAK,EAAE,UAA4B;QACtD,OAAO,UAAU,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC;IAEO,gBAAgB,CAAC,OAAe,EAAE,UAA4B;QAClE,+DAA+D;QAC/D,OAAO,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAES,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ;AA9RD,gEA8RC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, bufferToString, unreachableCase } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n} from \"@fluidframework/datastore-definitions\";\nimport { IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n ConsensusCallback,\n ConsensusResult,\n IConsensusOrderedCollection,\n IOrderedCollection,\n IConsensusOrderedCollectionEvents,\n} from \"./interfaces\";\n\nconst snapshotFileNameData = \"header\";\nconst snapshotFileNameTracking = \"jobTracking\";\n\ninterface IConsensusOrderedCollectionValue<T> {\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n readonly acquireId: string;\n\n // The actual value\n readonly value: T;\n}\n\n/**\n * An operation for consensus ordered collection\n */\ninterface IConsensusOrderedCollectionAddOperation {\n opName: \"add\";\n // serialized value\n value: string;\n}\n\ninterface IConsensusOrderedCollectionAcquireOperation {\n opName: \"acquire\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ninterface IConsensusOrderedCollectionCompleteOperation {\n opName: \"complete\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ninterface IConsensusOrderedCollectionReleaseOperation {\n opName: \"release\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ntype IConsensusOrderedCollectionOperation =\n IConsensusOrderedCollectionAddOperation |\n IConsensusOrderedCollectionAcquireOperation |\n IConsensusOrderedCollectionCompleteOperation |\n 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 */\nexport class ConsensusOrderedCollection<T = any>\n extends SharedObject<IConsensusOrderedCollectionEvents<T>> implements IConsensusOrderedCollection<T> {\n /**\n * The set of values that have been acquired but not yet completed or released\n */\n private jobTracking: JobTrackingInfo<T> = new Map();\n\n /**\n * Constructs a new consensus collection. If the object is non-local an id and service interfaces will\n * be provided\n */\n protected constructor(\n id: string,\n runtime: IFluidDataStoreRuntime,\n attributes: IChannelAttributes,\n private readonly data: IOrderedCollection<T>,\n ) {\n super(id, runtime, attributes);\n\n // We can't simply call this.removeClient(this.runtime.clientId) in on runtime disconnected,\n // because other clients may disconnect concurrently.\n // Disconnect order matters because it defines the order items go back to the queue.\n // So we put items back to queue only when we process our own removeMember event.\n runtime.getQuorum().on(\"removeMember\", (clientId: string) => {\n assert(!!clientId, 0x067 /* \"Missing clientId for removal!\" */);\n this.removeClient(clientId);\n });\n }\n\n /**\n * Add a value to the consensus collection.\n */\n public async add(value: T): Promise<void> {\n const valueSer = this.serializeValue(value, this.serializer);\n\n if (!this.isAttached()) {\n // For the case where this is not attached yet, explicitly JSON\n // clone the value to match the behavior of going thru the wire.\n const addValue = this.deserializeValue(valueSer, this.serializer) as T;\n this.addCore(addValue);\n return;\n }\n\n await this.submit<IConsensusOrderedCollectionAddOperation>({\n opName: \"add\",\n value: valueSer,\n });\n }\n\n /**\n * Remove a value from the consensus collection. If the collection is empty, returns false.\n * Otherwise calls callback with the value\n */\n public async acquire(callback: ConsensusCallback<T>): Promise<boolean> {\n const result = await this.acquireInternal();\n if (result === undefined) {\n return false;\n }\n\n const res = await callback(result.value);\n\n switch (res) {\n case ConsensusResult.Complete:\n await this.complete(result.acquireId);\n break;\n case ConsensusResult.Release:\n this.release(result.acquireId);\n this.emit(\"localRelease\", result.value, true /* intentional */);\n break;\n default: unreachableCase(res);\n }\n\n return true;\n }\n\n /**\n * Wait for a value to be available and acquire it from the consensus collection\n */\n public async waitAndAcquire(callback: ConsensusCallback<T>): Promise<void> {\n do {\n if (this.data.size() === 0) {\n // Wait for new entry before trying to acquire again\n await this.newAckBasedPromise<T>((resolve) => {\n this.once(\"add\", resolve);\n });\n }\n } while (!(await this.acquire(callback)));\n }\n\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n // If we are transitioning from unattached to attached mode,\n // then we are losing all checked out work!\n this.removeClient(idForLocalUnattachedClient);\n\n const builder = new SummaryTreeBuilder();\n let blobContent = this.serializeValue(this.data.asArray(), serializer);\n builder.addBlob(snapshotFileNameData, blobContent);\n blobContent = this.serializeValue(Array.from(this.jobTracking.entries()), serializer);\n builder.addBlob(snapshotFileNameTracking, blobContent);\n return builder.getSummaryTree();\n }\n\n protected isActive() {\n return this.runtime.connected && this.runtime.deltaManager.active;\n }\n\n protected async complete(acquireId: string) {\n if (!this.isAttached()) {\n this.completeCore(acquireId);\n return;\n }\n\n // if not active, this item already was released to queue (as observed by other clients)\n if (this.isActive()) {\n await this.submit<IConsensusOrderedCollectionCompleteOperation>({\n opName: \"complete\",\n acquireId,\n });\n }\n }\n\n protected completeCore(acquireId: string) {\n // Note: item may be no longer in jobTracking and returned back to queue!\n const rec = this.jobTracking.get(acquireId);\n if (rec !== undefined) {\n this.jobTracking.delete(acquireId);\n this.emit(\"complete\", rec.value);\n }\n }\n\n protected release(acquireId: string) {\n if (!this.isAttached()) {\n this.releaseCore(acquireId);\n return;\n }\n\n // if not active, this item already was released to queue (as observed by other clients)\n if (this.isActive()) {\n this.submit<IConsensusOrderedCollectionReleaseOperation>({\n opName: \"release\",\n acquireId,\n }).catch((error) => {\n this.runtime.logger.sendErrorEvent({ eventName: \"ConsensusQueue_release\" }, error);\n });\n }\n }\n\n protected releaseCore(acquireId: string) {\n // Note: item may be no longer in jobTracking and returned back to queue!\n const rec = this.jobTracking.get(acquireId);\n if (rec !== undefined) {\n this.jobTracking.delete(acquireId);\n this.data.add(rec.value);\n this.emit(\"add\", rec.value, false /* newlyAdded */);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n assert(this.jobTracking.size === 0, 0x068 /* \"On consensusOrderedCollection load, job tracking size > 0\" */);\n const blob = await storage.readBlob(snapshotFileNameTracking);\n const rawContentTracking = bufferToString(blob, \"utf8\");\n const content = this.deserializeValue(rawContentTracking, this.serializer);\n this.jobTracking = new Map(content) as JobTrackingInfo<T>;\n\n assert(this.data.size() === 0, 0x069 /* \"On consensusOrderedCollection load, data size > 0\" */);\n const blob2 = await storage.readBlob(snapshotFileNameData);\n const rawContentData = bufferToString(blob2, \"utf8\");\n const content2 = this.deserializeValue(rawContentData, this.serializer) as T[];\n this.data.loadFrom(content2);\n }\n\n protected onDisconnect() {\n for (const [, { value, clientId }] of this.jobTracking) {\n if (clientId === this.runtime.clientId) {\n this.emit(\"localRelease\", value, false /* intentional */);\n }\n }\n }\n\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation) {\n const op: IConsensusOrderedCollectionOperation = message.contents;\n let value: IConsensusOrderedCollectionValue<T> | undefined;\n switch (op.opName) {\n case \"add\":\n this.addCore(this.deserializeValue(op.value, this.serializer) as T);\n break;\n\n case \"acquire\":\n value = this.acquireCore(op.acquireId, message.clientId);\n break;\n\n case \"complete\":\n this.completeCore(op.acquireId);\n break;\n\n case \"release\":\n this.releaseCore(op.acquireId);\n break;\n\n default: unreachableCase(op);\n }\n if (local) {\n // Resolve the pending promise for this operation now that we have received an ack for it.\n const resolve = localOpMetadata as PendingResolve<T>;\n resolve(value);\n }\n }\n }\n\n private async submit<TMessage extends IConsensusOrderedCollectionOperation>(\n message: TMessage,\n ): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n assert(this.isAttached(), 0x06a /* \"Trying to submit message while detached!\" */);\n\n return this.newAckBasedPromise<IConsensusOrderedCollectionValue<T> | undefined>((resolve) => {\n // Send the resolve function as the localOpMetadata. This will be provided back to us when the\n // op is ack'd.\n this.submitLocalMessage(message, resolve);\n // If we fail due to runtime being disposed, it's better to return undefined then unhandled exception.\n }).catch((error) => undefined);\n }\n\n private addCore(value: T) {\n this.data.add(value);\n this.emit(\"add\", value, true /* newlyAdded */);\n }\n\n private acquireCore(acquireId: string, clientId?: string): IConsensusOrderedCollectionValue<T> | undefined {\n if (this.data.size() === 0) {\n return undefined;\n }\n const value = this.data.remove();\n\n const value2: IConsensusOrderedCollectionValue<T> = {\n acquireId,\n value,\n };\n this.jobTracking.set(value2.acquireId, { value, clientId });\n\n this.emit(\"acquire\", value, clientId);\n return value2;\n }\n\n private async acquireInternal(): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n if (!this.isAttached()) {\n // can be undefined if queue is empty\n return this.acquireCore(uuid(), idForLocalUnattachedClient);\n }\n\n return this.submit<IConsensusOrderedCollectionAcquireOperation>({\n opName: \"acquire\",\n acquireId: uuid(),\n });\n }\n\n private removeClient(clientIdToRemove?: string) {\n const added: T[] = [];\n for (const [acquireId, { value, clientId }] of this.jobTracking) {\n if (clientId === clientIdToRemove) {\n this.jobTracking.delete(acquireId);\n this.data.add(value);\n added.push(value);\n }\n }\n\n // Raise all events only after all state changes are completed,\n // to guarantee same ordering of operations if collection is manipulated from events.\n added.map((value) => this.emit(\"add\", value, false /* newlyAdded */));\n }\n\n private serializeValue(value, serializer: IFluidSerializer) {\n return serializer.stringify(value, this.handle);\n }\n\n private deserializeValue(content: string, serializer: IFluidSerializer) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return serializer.parse(content);\n }\n\n protected applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
|
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 = "0.59.
|
|
8
|
+
export declare const pkgVersion = "0.59.3000-66610";
|
|
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 = "0.59.
|
|
11
|
+
exports.pkgVersion = "0.59.3000-66610";
|
|
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,iBAAiB,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 = \"0.59.
|
|
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,iBAAiB,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 = \"0.59.3000-66610\";\n"]}
|
|
@@ -15,7 +15,7 @@ class SnapshotableArray extends Array {
|
|
|
15
15
|
return this.data;
|
|
16
16
|
}
|
|
17
17
|
async loadFrom(from) {
|
|
18
|
-
common_utils_1.assert(this.data.length === 0, 0x06b /* "Loading snapshot into a non-empty collection" */);
|
|
18
|
+
(0, common_utils_1.assert)(this.data.length === 0, 0x06b /* "Loading snapshot into a non-empty collection" */);
|
|
19
19
|
this.data = from;
|
|
20
20
|
}
|
|
21
21
|
size() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshotableArray.js","sourceRoot":"","sources":["../src/snapshotableArray.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AAEtD,MAAa,iBAAqB,SAAQ,KAAK;IAA/C;;QACc,SAAI,GAAQ,EAAE,CAAC;IAc7B,CAAC;IAZU,OAAO;QACV,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,IAAS;QAC3B,qBAAM,
|
|
1
|
+
{"version":3,"file":"snapshotableArray.js","sourceRoot":"","sources":["../src/snapshotableArray.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AAEtD,MAAa,iBAAqB,SAAQ,KAAK;IAA/C;;QACc,SAAI,GAAQ,EAAE,CAAC;IAc7B,CAAC;IAZU,OAAO;QACV,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,IAAS;QAC3B,IAAA,qBAAM,EAAC,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,KAAK,CAAC,oDAAoD,CAAC,CAAC;QAC3F,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IAEM,IAAI;QACP,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IAC5B,CAAC;CACJ;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/common-utils\";\n\nexport class SnapshotableArray<T> extends Array {\n protected data: T[] = [];\n\n public asArray() {\n return this.data;\n }\n\n public async loadFrom(from: T[]): Promise<void> {\n assert(this.data.length === 0, 0x06b /* \"Loading snapshot into a non-empty collection\" */);\n this.data = from;\n }\n\n public size(): number {\n return this.data.length;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consensusOrderedCollection.js","sourceRoot":"","sources":["../src/consensusOrderedCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAG,cAAc,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACxF,OAAO,EAA6B,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAM9F,OAAO,EAAoB,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAEpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MA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AAC;IAEO,gBAAgB,CAAC,OAAe,EAAE,UAA4B;QAClE,+DAA+D;QAC/D,OAAO,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAES,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert , bufferToString, unreachableCase } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n} from \"@fluidframework/datastore-definitions\";\nimport { IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n ConsensusCallback,\n ConsensusResult,\n IConsensusOrderedCollection,\n IOrderedCollection,\n IConsensusOrderedCollectionEvents,\n} from \"./interfaces\";\n\nconst snapshotFileNameData = \"header\";\nconst snapshotFileNameTracking = \"jobTracking\";\n\ninterface IConsensusOrderedCollectionValue<T> {\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n readonly acquireId: string;\n\n // The actual value\n readonly value: T;\n}\n\n/**\n * An operation for consensus ordered collection\n */\ninterface IConsensusOrderedCollectionAddOperation {\n opName: \"add\";\n // serialized value\n value: string;\n}\n\ninterface IConsensusOrderedCollectionAcquireOperation {\n opName: \"acquire\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ninterface IConsensusOrderedCollectionCompleteOperation {\n opName: \"complete\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ninterface IConsensusOrderedCollectionReleaseOperation {\n opName: \"release\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ntype IConsensusOrderedCollectionOperation =\n IConsensusOrderedCollectionAddOperation |\n IConsensusOrderedCollectionAcquireOperation |\n IConsensusOrderedCollectionCompleteOperation |\n 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 */\nexport class ConsensusOrderedCollection<T = any>\n extends SharedObject<IConsensusOrderedCollectionEvents<T>> implements IConsensusOrderedCollection<T> {\n /**\n * The set of values that have been acquired but not yet completed or released\n */\n private jobTracking: JobTrackingInfo<T> = new Map();\n\n /**\n * Constructs a new consensus collection. If the object is non-local an id and service interfaces will\n * be provided\n */\n protected constructor(\n id: string,\n runtime: IFluidDataStoreRuntime,\n attributes: IChannelAttributes,\n private readonly data: IOrderedCollection<T>,\n ) {\n super(id, runtime, attributes);\n\n // We can't simply call this.removeClient(this.runtime.clientId) in on runtime disconnected,\n // because other clients may disconnect concurrently.\n // Disconnect order matters because it defines the order items go back to the queue.\n // So we put items back to queue only when we process our own removeMember event.\n runtime.getQuorum().on(\"removeMember\", (clientId: string) => {\n assert(!!clientId, 0x067 /* \"Missing clientId for removal!\" */);\n this.removeClient(clientId);\n });\n }\n\n /**\n * Add a value to the consensus collection.\n */\n public async add(value: T): Promise<void> {\n const valueSer = this.serializeValue(value, this.serializer);\n\n if (!this.isAttached()) {\n // For the case where this is not attached yet, explicitly JSON\n // clone the value to match the behavior of going thru the wire.\n const addValue = this.deserializeValue(valueSer, this.serializer) as T;\n this.addCore(addValue);\n return;\n }\n\n await this.submit<IConsensusOrderedCollectionAddOperation>({\n opName: \"add\",\n value: valueSer,\n });\n }\n\n /**\n * Remove a value from the consensus collection. If the collection is empty, returns false.\n * Otherwise calls callback with the value\n */\n public async acquire(callback: ConsensusCallback<T>): Promise<boolean> {\n const result = await this.acquireInternal();\n if (result === undefined) {\n return false;\n }\n\n const res = await callback(result.value);\n\n switch (res) {\n case ConsensusResult.Complete:\n await this.complete(result.acquireId);\n break;\n case ConsensusResult.Release:\n this.release(result.acquireId);\n this.emit(\"localRelease\", result.value, true /* intentional */);\n break;\n default: unreachableCase(res);\n }\n\n return true;\n }\n\n /**\n * Wait for a value to be available and acquire it from the consensus collection\n */\n public async waitAndAcquire(callback: ConsensusCallback<T>): Promise<void> {\n do {\n if (this.data.size() === 0) {\n // Wait for new entry before trying to acquire again\n await this.newAckBasedPromise<T>((resolve) => {\n this.once(\"add\", resolve);\n });\n }\n } while (!(await this.acquire(callback)));\n }\n\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n // If we are transitioning from unattached to attached mode,\n // then we are losing all checked out work!\n this.removeClient(idForLocalUnattachedClient);\n\n const builder = new SummaryTreeBuilder();\n let blobContent = this.serializeValue(this.data.asArray(), serializer);\n builder.addBlob(snapshotFileNameData, blobContent);\n blobContent = this.serializeValue(Array.from(this.jobTracking.entries()), serializer);\n builder.addBlob(snapshotFileNameTracking, blobContent);\n return builder.getSummaryTree();\n }\n\n protected isActive() {\n return this.runtime.connected && this.runtime.deltaManager.active;\n }\n\n protected async complete(acquireId: string) {\n if (!this.isAttached()) {\n this.completeCore(acquireId);\n return;\n }\n\n // if not active, this item already was released to queue (as observed by other clients)\n if (this.isActive()) {\n await this.submit<IConsensusOrderedCollectionCompleteOperation>({\n opName: \"complete\",\n acquireId,\n });\n }\n }\n\n protected completeCore(acquireId: string) {\n // Note: item may be no longer in jobTracking and returned back to queue!\n const rec = this.jobTracking.get(acquireId);\n if (rec !== undefined) {\n this.jobTracking.delete(acquireId);\n this.emit(\"complete\", rec.value);\n }\n }\n\n protected release(acquireId: string) {\n if (!this.isAttached()) {\n this.releaseCore(acquireId);\n return;\n }\n\n // if not active, this item already was released to queue (as observed by other clients)\n if (this.isActive()) {\n this.submit<IConsensusOrderedCollectionReleaseOperation>({\n opName: \"release\",\n acquireId,\n }).catch((error) => {\n this.runtime.logger.sendErrorEvent({ eventName: \"ConsensusQueue_release\" }, error);\n });\n }\n }\n\n protected releaseCore(acquireId: string) {\n // Note: item may be no longer in jobTracking and returned back to queue!\n const rec = this.jobTracking.get(acquireId);\n if (rec !== undefined) {\n this.jobTracking.delete(acquireId);\n this.data.add(rec.value);\n this.emit(\"add\", rec.value, false /* newlyAdded */);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n assert(this.jobTracking.size === 0, 0x068 /* \"On consensusOrderedCollection load, job tracking size > 0\" */);\n const blob = await storage.readBlob(snapshotFileNameTracking);\n const rawContentTracking = bufferToString(blob, \"utf8\");\n const content = this.deserializeValue(rawContentTracking, this.serializer);\n this.jobTracking = new Map(content) as JobTrackingInfo<T>;\n\n assert(this.data.size() === 0, 0x069 /* \"On consensusOrderedCollection load, data size > 0\" */);\n const blob2 = await storage.readBlob(snapshotFileNameData);\n const rawContentData = bufferToString(blob2, \"utf8\");\n const content2 = this.deserializeValue(rawContentData, this.serializer) as T[];\n this.data.loadFrom(content2);\n }\n\n protected onDisconnect() {\n for (const [, { value, clientId }] of this.jobTracking) {\n if (clientId === this.runtime.clientId) {\n this.emit(\"localRelease\", value, false /* intentional */);\n }\n }\n }\n\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation) {\n const op: IConsensusOrderedCollectionOperation = message.contents;\n let value: IConsensusOrderedCollectionValue<T> | undefined;\n switch (op.opName) {\n case \"add\":\n this.addCore(this.deserializeValue(op.value, this.serializer) as T);\n break;\n\n case \"acquire\":\n value = this.acquireCore(op.acquireId, message.clientId);\n break;\n\n case \"complete\":\n this.completeCore(op.acquireId);\n break;\n\n case \"release\":\n this.releaseCore(op.acquireId);\n break;\n\n default: unreachableCase(op);\n }\n if (local) {\n // Resolve the pending promise for this operation now that we have received an ack for it.\n const resolve = localOpMetadata as PendingResolve<T>;\n resolve(value);\n }\n }\n }\n\n private async submit<TMessage extends IConsensusOrderedCollectionOperation>(\n message: TMessage,\n ): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n assert(this.isAttached(), 0x06a /* \"Trying to submit message while detached!\" */);\n\n return this.newAckBasedPromise<IConsensusOrderedCollectionValue<T> | undefined>((resolve) => {\n // Send the resolve function as the localOpMetadata. This will be provided back to us when the\n // op is ack'd.\n this.submitLocalMessage(message, resolve);\n // If we fail due to runtime being disposed, it's better to return undefined then unhandled exception.\n }).catch((error) => undefined);\n }\n\n private addCore(value: T) {\n this.data.add(value);\n this.emit(\"add\", value, true /* newlyAdded */);\n }\n\n private acquireCore(acquireId: string, clientId?: string): IConsensusOrderedCollectionValue<T> | undefined {\n if (this.data.size() === 0) {\n return undefined;\n }\n const value = this.data.remove();\n\n const value2: IConsensusOrderedCollectionValue<T> = {\n acquireId,\n value,\n };\n this.jobTracking.set(value2.acquireId, { value, clientId });\n\n this.emit(\"acquire\", value, clientId);\n return value2;\n }\n\n private async acquireInternal(): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n if (!this.isAttached()) {\n // can be undefined if queue is empty\n return this.acquireCore(uuid(), idForLocalUnattachedClient);\n }\n\n return this.submit<IConsensusOrderedCollectionAcquireOperation>({\n opName: \"acquire\",\n acquireId: uuid(),\n });\n }\n\n private removeClient(clientIdToRemove?: string) {\n const added: T[] = [];\n for (const [acquireId, { value, clientId }] of this.jobTracking) {\n if (clientId === clientIdToRemove) {\n this.jobTracking.delete(acquireId);\n this.data.add(value);\n added.push(value);\n }\n }\n\n // Raise all events only after all state changes are completed,\n // to guarantee same ordering of operations if collection is manipulated from events.\n added.map((value) => this.emit(\"add\", value, false /* newlyAdded */));\n }\n\n private serializeValue(value, serializer: IFluidSerializer) {\n return serializer.stringify(value, this.handle);\n }\n\n private deserializeValue(content: string, serializer: IFluidSerializer) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return serializer.parse(content);\n }\n\n protected applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"consensusOrderedCollection.js","sourceRoot":"","sources":["../src/consensusOrderedCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACvF,OAAO,EAA6B,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAM9F,OAAO,EAAoB,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAEpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAEH,eAAe,GAIlB,MAAM,cAAc,CAAC;AAEtB,MAAM,oBAAoB,GAAG,QAAQ,CAAC;AACtC,MAAM,wBAAwB,GAAG,aAAa,CAAC;AAwD/C,MAAM,0BAA0B,GAAG,SAAS,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAM,OAAO,0BACT,SAAQ,YAAkD;IAM1D;;;OAGG;IACH,YACI,EAAU,EACV,OAA+B,EAC/B,UAA8B,EACb,IAA2B;QAE5C,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QAFd,SAAI,GAAJ,IAAI,CAAuB;QAbhD;;WAEG;QACK,gBAAW,GAAuB,IAAI,GAAG,EAAE,CAAC;QAchD,4FAA4F;QAC5F,qDAAqD;QACrD,oFA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AC,CAAC;IACP,CAAC;IAEO,YAAY,CAAC,gBAAyB;QAC1C,MAAM,KAAK,GAAQ,EAAE,CAAC;QACtB,KAAK,MAAM,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE;YAC7D,IAAI,QAAQ,KAAK,gBAAgB,EAAE;gBAC/B,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;aACrB;SACJ;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;IAC1E,CAAC;IAEO,cAAc,CAAC,KAAK,EAAE,UAA4B;QACtD,OAAO,UAAU,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC;IAEO,gBAAgB,CAAC,OAAe,EAAE,UAA4B;QAClE,+DAA+D;QAC/D,OAAO,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAES,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, bufferToString, unreachableCase } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n} from \"@fluidframework/datastore-definitions\";\nimport { IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n ConsensusCallback,\n ConsensusResult,\n IConsensusOrderedCollection,\n IOrderedCollection,\n IConsensusOrderedCollectionEvents,\n} from \"./interfaces\";\n\nconst snapshotFileNameData = \"header\";\nconst snapshotFileNameTracking = \"jobTracking\";\n\ninterface IConsensusOrderedCollectionValue<T> {\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n readonly acquireId: string;\n\n // The actual value\n readonly value: T;\n}\n\n/**\n * An operation for consensus ordered collection\n */\ninterface IConsensusOrderedCollectionAddOperation {\n opName: \"add\";\n // serialized value\n value: string;\n}\n\ninterface IConsensusOrderedCollectionAcquireOperation {\n opName: \"acquire\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ninterface IConsensusOrderedCollectionCompleteOperation {\n opName: \"complete\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ninterface IConsensusOrderedCollectionReleaseOperation {\n opName: \"release\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ntype IConsensusOrderedCollectionOperation =\n IConsensusOrderedCollectionAddOperation |\n IConsensusOrderedCollectionAcquireOperation |\n IConsensusOrderedCollectionCompleteOperation |\n 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 */\nexport class ConsensusOrderedCollection<T = any>\n extends SharedObject<IConsensusOrderedCollectionEvents<T>> implements IConsensusOrderedCollection<T> {\n /**\n * The set of values that have been acquired but not yet completed or released\n */\n private jobTracking: JobTrackingInfo<T> = new Map();\n\n /**\n * Constructs a new consensus collection. If the object is non-local an id and service interfaces will\n * be provided\n */\n protected constructor(\n id: string,\n runtime: IFluidDataStoreRuntime,\n attributes: IChannelAttributes,\n private readonly data: IOrderedCollection<T>,\n ) {\n super(id, runtime, attributes);\n\n // We can't simply call this.removeClient(this.runtime.clientId) in on runtime disconnected,\n // because other clients may disconnect concurrently.\n // Disconnect order matters because it defines the order items go back to the queue.\n // So we put items back to queue only when we process our own removeMember event.\n runtime.getQuorum().on(\"removeMember\", (clientId: string) => {\n assert(!!clientId, 0x067 /* \"Missing clientId for removal!\" */);\n this.removeClient(clientId);\n });\n }\n\n /**\n * Add a value to the consensus collection.\n */\n public async add(value: T): Promise<void> {\n const valueSer = this.serializeValue(value, this.serializer);\n\n if (!this.isAttached()) {\n // For the case where this is not attached yet, explicitly JSON\n // clone the value to match the behavior of going thru the wire.\n const addValue = this.deserializeValue(valueSer, this.serializer) as T;\n this.addCore(addValue);\n return;\n }\n\n await this.submit<IConsensusOrderedCollectionAddOperation>({\n opName: \"add\",\n value: valueSer,\n });\n }\n\n /**\n * Remove a value from the consensus collection. If the collection is empty, returns false.\n * Otherwise calls callback with the value\n */\n public async acquire(callback: ConsensusCallback<T>): Promise<boolean> {\n const result = await this.acquireInternal();\n if (result === undefined) {\n return false;\n }\n\n const res = await callback(result.value);\n\n switch (res) {\n case ConsensusResult.Complete:\n await this.complete(result.acquireId);\n break;\n case ConsensusResult.Release:\n this.release(result.acquireId);\n this.emit(\"localRelease\", result.value, true /* intentional */);\n break;\n default: unreachableCase(res);\n }\n\n return true;\n }\n\n /**\n * Wait for a value to be available and acquire it from the consensus collection\n */\n public async waitAndAcquire(callback: ConsensusCallback<T>): Promise<void> {\n do {\n if (this.data.size() === 0) {\n // Wait for new entry before trying to acquire again\n await this.newAckBasedPromise<T>((resolve) => {\n this.once(\"add\", resolve);\n });\n }\n } while (!(await this.acquire(callback)));\n }\n\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n // If we are transitioning from unattached to attached mode,\n // then we are losing all checked out work!\n this.removeClient(idForLocalUnattachedClient);\n\n const builder = new SummaryTreeBuilder();\n let blobContent = this.serializeValue(this.data.asArray(), serializer);\n builder.addBlob(snapshotFileNameData, blobContent);\n blobContent = this.serializeValue(Array.from(this.jobTracking.entries()), serializer);\n builder.addBlob(snapshotFileNameTracking, blobContent);\n return builder.getSummaryTree();\n }\n\n protected isActive() {\n return this.runtime.connected && this.runtime.deltaManager.active;\n }\n\n protected async complete(acquireId: string) {\n if (!this.isAttached()) {\n this.completeCore(acquireId);\n return;\n }\n\n // if not active, this item already was released to queue (as observed by other clients)\n if (this.isActive()) {\n await this.submit<IConsensusOrderedCollectionCompleteOperation>({\n opName: \"complete\",\n acquireId,\n });\n }\n }\n\n protected completeCore(acquireId: string) {\n // Note: item may be no longer in jobTracking and returned back to queue!\n const rec = this.jobTracking.get(acquireId);\n if (rec !== undefined) {\n this.jobTracking.delete(acquireId);\n this.emit(\"complete\", rec.value);\n }\n }\n\n protected release(acquireId: string) {\n if (!this.isAttached()) {\n this.releaseCore(acquireId);\n return;\n }\n\n // if not active, this item already was released to queue (as observed by other clients)\n if (this.isActive()) {\n this.submit<IConsensusOrderedCollectionReleaseOperation>({\n opName: \"release\",\n acquireId,\n }).catch((error) => {\n this.runtime.logger.sendErrorEvent({ eventName: \"ConsensusQueue_release\" }, error);\n });\n }\n }\n\n protected releaseCore(acquireId: string) {\n // Note: item may be no longer in jobTracking and returned back to queue!\n const rec = this.jobTracking.get(acquireId);\n if (rec !== undefined) {\n this.jobTracking.delete(acquireId);\n this.data.add(rec.value);\n this.emit(\"add\", rec.value, false /* newlyAdded */);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n assert(this.jobTracking.size === 0, 0x068 /* \"On consensusOrderedCollection load, job tracking size > 0\" */);\n const blob = await storage.readBlob(snapshotFileNameTracking);\n const rawContentTracking = bufferToString(blob, \"utf8\");\n const content = this.deserializeValue(rawContentTracking, this.serializer);\n this.jobTracking = new Map(content) as JobTrackingInfo<T>;\n\n assert(this.data.size() === 0, 0x069 /* \"On consensusOrderedCollection load, data size > 0\" */);\n const blob2 = await storage.readBlob(snapshotFileNameData);\n const rawContentData = bufferToString(blob2, \"utf8\");\n const content2 = this.deserializeValue(rawContentData, this.serializer) as T[];\n this.data.loadFrom(content2);\n }\n\n protected onDisconnect() {\n for (const [, { value, clientId }] of this.jobTracking) {\n if (clientId === this.runtime.clientId) {\n this.emit(\"localRelease\", value, false /* intentional */);\n }\n }\n }\n\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation) {\n const op: IConsensusOrderedCollectionOperation = message.contents;\n let value: IConsensusOrderedCollectionValue<T> | undefined;\n switch (op.opName) {\n case \"add\":\n this.addCore(this.deserializeValue(op.value, this.serializer) as T);\n break;\n\n case \"acquire\":\n value = this.acquireCore(op.acquireId, message.clientId);\n break;\n\n case \"complete\":\n this.completeCore(op.acquireId);\n break;\n\n case \"release\":\n this.releaseCore(op.acquireId);\n break;\n\n default: unreachableCase(op);\n }\n if (local) {\n // Resolve the pending promise for this operation now that we have received an ack for it.\n const resolve = localOpMetadata as PendingResolve<T>;\n resolve(value);\n }\n }\n }\n\n private async submit<TMessage extends IConsensusOrderedCollectionOperation>(\n message: TMessage,\n ): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n assert(this.isAttached(), 0x06a /* \"Trying to submit message while detached!\" */);\n\n return this.newAckBasedPromise<IConsensusOrderedCollectionValue<T> | undefined>((resolve) => {\n // Send the resolve function as the localOpMetadata. This will be provided back to us when the\n // op is ack'd.\n this.submitLocalMessage(message, resolve);\n // If we fail due to runtime being disposed, it's better to return undefined then unhandled exception.\n }).catch((error) => undefined);\n }\n\n private addCore(value: T) {\n this.data.add(value);\n this.emit(\"add\", value, true /* newlyAdded */);\n }\n\n private acquireCore(acquireId: string, clientId?: string): IConsensusOrderedCollectionValue<T> | undefined {\n if (this.data.size() === 0) {\n return undefined;\n }\n const value = this.data.remove();\n\n const value2: IConsensusOrderedCollectionValue<T> = {\n acquireId,\n value,\n };\n this.jobTracking.set(value2.acquireId, { value, clientId });\n\n this.emit(\"acquire\", value, clientId);\n return value2;\n }\n\n private async acquireInternal(): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n if (!this.isAttached()) {\n // can be undefined if queue is empty\n return this.acquireCore(uuid(), idForLocalUnattachedClient);\n }\n\n return this.submit<IConsensusOrderedCollectionAcquireOperation>({\n opName: \"acquire\",\n acquireId: uuid(),\n });\n }\n\n private removeClient(clientIdToRemove?: string) {\n const added: T[] = [];\n for (const [acquireId, { value, clientId }] of this.jobTracking) {\n if (clientId === clientIdToRemove) {\n this.jobTracking.delete(acquireId);\n this.data.add(value);\n added.push(value);\n }\n }\n\n // Raise all events only after all state changes are completed,\n // to guarantee same ordering of operations if collection is manipulated from events.\n added.map((value) => this.emit(\"add\", value, false /* newlyAdded */));\n }\n\n private serializeValue(value, serializer: IFluidSerializer) {\n return serializer.stringify(value, this.handle);\n }\n\n private deserializeValue(content: string, serializer: IFluidSerializer) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return serializer.parse(content);\n }\n\n protected applyStashedOp() {\n throw new Error(\"not implemented\");\n }\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 = "0.59.
|
|
8
|
+
export declare const pkgVersion = "0.59.3000-66610";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/lib/packageVersion.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export const pkgName = "@fluidframework/ordered-collection";
|
|
8
|
-
export const pkgVersion = "0.59.
|
|
8
|
+
export const pkgVersion = "0.59.3000-66610";
|
|
9
9
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,oCAAoC,CAAC;AAC5D,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,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 = \"0.59.
|
|
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,iBAAiB,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 = \"0.59.3000-66610\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/ordered-collection",
|
|
3
|
-
"version": "0.59.
|
|
3
|
+
"version": "0.59.3000-66610",
|
|
4
4
|
"description": "Consensus Collection",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -62,20 +62,21 @@
|
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@fluidframework/common-utils": "^0.32.1",
|
|
64
64
|
"@fluidframework/core-interfaces": "^0.43.1000",
|
|
65
|
-
"@fluidframework/datastore-definitions": "0.59.
|
|
65
|
+
"@fluidframework/datastore-definitions": "0.59.3000-66610",
|
|
66
66
|
"@fluidframework/protocol-definitions": "^0.1028.1000",
|
|
67
|
-
"@fluidframework/runtime-definitions": "0.59.
|
|
68
|
-
"@fluidframework/runtime-utils": "0.59.
|
|
69
|
-
"@fluidframework/shared-object-base": "0.59.
|
|
67
|
+
"@fluidframework/runtime-definitions": "0.59.3000-66610",
|
|
68
|
+
"@fluidframework/runtime-utils": "0.59.3000-66610",
|
|
69
|
+
"@fluidframework/shared-object-base": "0.59.3000-66610",
|
|
70
70
|
"uuid": "^8.3.1"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@fluid-internal/test-dds-utils": "0.59.
|
|
73
|
+
"@fluid-internal/test-dds-utils": "0.59.3000-66610",
|
|
74
74
|
"@fluidframework/build-common": "^0.23.0",
|
|
75
|
-
"@fluidframework/
|
|
76
|
-
"@fluidframework/
|
|
77
|
-
"@fluidframework/
|
|
78
|
-
"@fluidframework/
|
|
75
|
+
"@fluidframework/build-tools": "^0.2.66048",
|
|
76
|
+
"@fluidframework/eslint-config-fluid": "^0.28.2000-0",
|
|
77
|
+
"@fluidframework/mocha-test-setup": "0.59.3000-66610",
|
|
78
|
+
"@fluidframework/ordered-collection-previous": "npm:@fluidframework/ordered-collection@0.59.2000",
|
|
79
|
+
"@fluidframework/test-runtime-utils": "0.59.3000-66610",
|
|
79
80
|
"@microsoft/api-extractor": "^7.22.2",
|
|
80
81
|
"@rushstack/eslint-config": "^2.5.1",
|
|
81
82
|
"@types/mocha": "^8.2.2",
|
|
@@ -98,11 +99,11 @@
|
|
|
98
99
|
"mocha": "^8.4.0",
|
|
99
100
|
"nyc": "^15.0.0",
|
|
100
101
|
"rimraf": "^2.6.2",
|
|
101
|
-
"typescript": "~4.
|
|
102
|
+
"typescript": "~4.5.5",
|
|
102
103
|
"typescript-formatter": "7.1.0"
|
|
103
104
|
},
|
|
104
105
|
"typeValidation": {
|
|
105
|
-
"version": "0.59.
|
|
106
|
+
"version": "0.59.3000",
|
|
106
107
|
"broken": {}
|
|
107
108
|
}
|
|
108
109
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { assert
|
|
6
|
+
import { assert, bufferToString, unreachableCase } from "@fluidframework/common-utils";
|
|
7
7
|
import { ISequencedDocumentMessage, MessageType } from "@fluidframework/protocol-definitions";
|
|
8
8
|
import {
|
|
9
9
|
IChannelAttributes,
|
|
@@ -78,7 +78,7 @@ type PendingResolve<T> = (value: IConsensusOrderedCollectionValue<T> | undefined
|
|
|
78
78
|
* Key is the acquireId from when it was acquired
|
|
79
79
|
* Value is the acquired value, and the id of the client who acquired it, or undefined for unattached client
|
|
80
80
|
*/
|
|
81
|
-
type JobTrackingInfo<T> = Map<string, { value: T
|
|
81
|
+
type JobTrackingInfo<T> = Map<string, { value: T; clientId: string | undefined; }>;
|
|
82
82
|
const idForLocalUnattachedClient = undefined;
|
|
83
83
|
|
|
84
84
|
/**
|
package/src/packageVersion.ts
CHANGED