@fluidframework/ordered-collection 1.4.0-121020 → 2.0.0-dev-rc.1.0.0.225277

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/.eslintrc.js +5 -7
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +117 -0
  4. package/README.md +22 -1
  5. package/api-extractor-esm.json +4 -0
  6. package/api-extractor-lint.json +4 -0
  7. package/api-extractor.json +2 -2
  8. package/api-report/ordered-collection.api.md +111 -0
  9. package/dist/{consensusOrderedCollection.js → consensusOrderedCollection.cjs} +16 -12
  10. package/dist/consensusOrderedCollection.cjs.map +1 -0
  11. package/dist/consensusOrderedCollection.d.ts +1 -0
  12. package/dist/consensusOrderedCollection.d.ts.map +1 -1
  13. package/dist/{consensusOrderedCollectionFactory.js → consensusOrderedCollectionFactory.cjs} +3 -3
  14. package/dist/consensusOrderedCollectionFactory.cjs.map +1 -0
  15. package/dist/consensusOrderedCollectionFactory.d.ts.map +1 -1
  16. package/dist/{consensusQueue.js → consensusQueue.cjs} +5 -5
  17. package/dist/consensusQueue.cjs.map +1 -0
  18. package/dist/consensusQueue.d.ts +1 -0
  19. package/dist/consensusQueue.d.ts.map +1 -1
  20. package/dist/index.cjs +17 -0
  21. package/dist/index.cjs.map +1 -0
  22. package/dist/index.d.ts +4 -4
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/{interfaces.js → interfaces.cjs} +5 -2
  25. package/dist/interfaces.cjs.map +1 -0
  26. package/dist/interfaces.d.ts +11 -2
  27. package/dist/interfaces.d.ts.map +1 -1
  28. package/dist/ordered-collection-alpha.d.ts +226 -0
  29. package/dist/ordered-collection-beta.d.ts +35 -0
  30. package/dist/ordered-collection-public.d.ts +35 -0
  31. package/dist/ordered-collection-untrimmed.d.ts +246 -0
  32. package/dist/{packageVersion.js → packageVersion.cjs} +2 -2
  33. package/dist/packageVersion.cjs.map +1 -0
  34. package/dist/packageVersion.d.ts +1 -1
  35. package/dist/packageVersion.d.ts.map +1 -1
  36. package/dist/{snapshotableArray.js → snapshotableArray.cjs} +3 -3
  37. package/dist/snapshotableArray.cjs.map +1 -0
  38. package/dist/snapshotableArray.d.ts.map +1 -1
  39. package/dist/{testUtils.js → testUtils.cjs} +4 -2
  40. package/dist/testUtils.cjs.map +1 -0
  41. package/dist/testUtils.d.ts +2 -0
  42. package/dist/testUtils.d.ts.map +1 -1
  43. package/dist/tsdoc-metadata.json +11 -0
  44. package/lib/{consensusOrderedCollection.d.ts → consensusOrderedCollection.d.mts} +3 -2
  45. package/lib/consensusOrderedCollection.d.mts.map +1 -0
  46. package/lib/{consensusOrderedCollection.js → consensusOrderedCollection.mjs} +10 -6
  47. package/lib/consensusOrderedCollection.mjs.map +1 -0
  48. package/lib/{consensusOrderedCollectionFactory.d.ts → consensusOrderedCollectionFactory.d.mts} +2 -2
  49. package/lib/consensusOrderedCollectionFactory.d.mts.map +1 -0
  50. package/lib/{consensusOrderedCollectionFactory.js → consensusOrderedCollectionFactory.mjs} +3 -3
  51. package/lib/consensusOrderedCollectionFactory.mjs.map +1 -0
  52. package/lib/{consensusQueue.d.ts → consensusQueue.d.mts} +3 -2
  53. package/lib/consensusQueue.d.mts.map +1 -0
  54. package/lib/{consensusQueue.js → consensusQueue.mjs} +5 -5
  55. package/lib/consensusQueue.mjs.map +1 -0
  56. package/lib/index.d.mts +9 -0
  57. package/lib/index.d.mts.map +1 -0
  58. package/lib/index.mjs +9 -0
  59. package/lib/index.mjs.map +1 -0
  60. package/lib/{interfaces.d.ts → interfaces.d.mts} +12 -3
  61. package/lib/interfaces.d.mts.map +1 -0
  62. package/lib/{interfaces.js → interfaces.mjs} +4 -1
  63. package/lib/interfaces.mjs.map +1 -0
  64. package/lib/ordered-collection-alpha.d.mts +226 -0
  65. package/lib/ordered-collection-beta.d.mts +35 -0
  66. package/lib/ordered-collection-public.d.mts +35 -0
  67. package/lib/ordered-collection-untrimmed.d.mts +246 -0
  68. package/lib/{packageVersion.d.ts → packageVersion.d.mts} +2 -2
  69. package/lib/packageVersion.d.mts.map +1 -0
  70. package/lib/{packageVersion.js → packageVersion.mjs} +2 -2
  71. package/lib/packageVersion.mjs.map +1 -0
  72. package/lib/{snapshotableArray.d.ts → snapshotableArray.d.mts} +1 -1
  73. package/lib/snapshotableArray.d.mts.map +1 -0
  74. package/lib/{snapshotableArray.js → snapshotableArray.mjs} +2 -2
  75. package/lib/snapshotableArray.mjs.map +1 -0
  76. package/lib/{testUtils.d.ts → testUtils.d.mts} +4 -2
  77. package/lib/testUtils.d.mts.map +1 -0
  78. package/lib/{testUtils.js → testUtils.mjs} +4 -2
  79. package/lib/testUtils.mjs.map +1 -0
  80. package/package.json +136 -63
  81. package/prettier.config.cjs +8 -0
  82. package/src/consensusOrderedCollection.ts +340 -319
  83. package/src/consensusOrderedCollectionFactory.ts +33 -32
  84. package/src/consensusQueue.ts +42 -38
  85. package/src/index.ts +12 -4
  86. package/src/interfaces.ts +83 -74
  87. package/src/packageVersion.ts +1 -1
  88. package/src/snapshotableArray.ts +12 -12
  89. package/src/testUtils.ts +21 -18
  90. package/tsc-multi.test.json +4 -0
  91. package/tsconfig.json +11 -13
  92. package/dist/consensusOrderedCollection.js.map +0 -1
  93. package/dist/consensusOrderedCollectionFactory.js.map +0 -1
  94. package/dist/consensusQueue.js.map +0 -1
  95. package/dist/index.js +0 -21
  96. package/dist/index.js.map +0 -1
  97. package/dist/interfaces.js.map +0 -1
  98. package/dist/packageVersion.js.map +0 -1
  99. package/dist/snapshotableArray.js.map +0 -1
  100. package/dist/testUtils.js.map +0 -1
  101. package/lib/consensusOrderedCollection.d.ts.map +0 -1
  102. package/lib/consensusOrderedCollection.js.map +0 -1
  103. package/lib/consensusOrderedCollectionFactory.d.ts.map +0 -1
  104. package/lib/consensusOrderedCollectionFactory.js.map +0 -1
  105. package/lib/consensusQueue.d.ts.map +0 -1
  106. package/lib/consensusQueue.js.map +0 -1
  107. package/lib/index.d.ts +0 -9
  108. package/lib/index.d.ts.map +0 -1
  109. package/lib/index.js +0 -9
  110. package/lib/index.js.map +0 -1
  111. package/lib/interfaces.d.ts.map +0 -1
  112. package/lib/interfaces.js.map +0 -1
  113. package/lib/packageVersion.d.ts.map +0 -1
  114. package/lib/packageVersion.js.map +0 -1
  115. package/lib/snapshotableArray.d.ts.map +0 -1
  116. package/lib/snapshotableArray.js.map +0 -1
  117. package/lib/testUtils.d.ts.map +0 -1
  118. package/lib/testUtils.js.map +0 -1
  119. package/tsconfig.esnext.json +0 -7
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAEH,+DAA6C;AAC7C,mDAAiC;AACjC,+CAA6B;AAC7B,8CAA4B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport * from \"./consensusOrderedCollection\";\nexport * from \"./consensusQueue\";\nexport * from \"./interfaces\";\nexport * from \"./testUtils\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAUH,IAAY,eAGX;AAHD,WAAY,eAAe;IACvB,2DAAO,CAAA;IACP,6DAAQ,CAAA;AACZ,CAAC,EAHW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAG1B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n IFluidDataStoreRuntime,\n IChannelServices,\n IChannelAttributes,\n IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISharedObject, ISharedObjectEvents } from \"@fluidframework/shared-object-base\";\n\nexport enum ConsensusResult {\n Release,\n Complete,\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 */\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 */\nexport interface IConsensusOrderedCollectionFactory extends IChannelFactory {\n load(\n document: IFluidDataStoreRuntime,\n id: string,\n services: IChannelServices,\n attributes: IChannelAttributes): Promise<IConsensusOrderedCollection>;\n\n create(document: IFluidDataStoreRuntime, id: string): IConsensusOrderedCollection;\n}\n\n/**\n * Events notifying about addition, acquisition, release and completion of items\n */\nexport interface IConsensusOrderedCollectionEvents<T> extends ISharedObjectEvents {\n\n /**\n * Event fires when new item is added to the queue or\n * an item previously acquired is returned back to a queue (including client loosing connection)\n * @param newlyAdded - indicates if it's newly added item of previously acquired item\n */\n (event: \"add\", listener: (value: T, newlyAdded: boolean) => void): this;\n /**\n * Event fires when a client acquired an item\n * Fires both for locally acquired items, as well as items acquired by remote clients\n */\n (event: \"acquire\", listener: (value: T, clientId?: string) => void): this;\n\n /**\n * \"Complete event fires when a client completes an item.\n */\n (event: \"complete\", listener: (value: T) => void): this;\n\n /**\n * Event fires when locally acquired item is being released back to the queue.\n * Please note that release process is asynchronous, so it takes a while for it to happen\n * (\"add\" event will be fired as result of it)\n * @param intentional - indicates whether release was intentional (result of returning\n * ConsensusResult.Release from callback) or it happened as result of lost connection.\n */\n (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 */\nexport interface IConsensusOrderedCollection<T = any> extends ISharedObject<IConsensusOrderedCollectionEvents<T>> {\n\n /**\n * Adds a value to the collection\n */\n add(value: T): Promise<void>;\n\n /**\n * Retrieves a value from the collection.\n * @returns Returns true (and calls callback with acquired value) if collection was not empty.\n * Otherwise returns false.\n */\n acquire(callback: ConsensusCallback<T>): Promise<boolean>;\n\n /**\n * Wait for a value to be available and remove it from the consensus collection\n * Calls callback with retrieved value.\n */\n waitAndAcquire(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 */\nexport interface ISnapshotable<T> {\n asArray(): T[];\n\n loadFrom(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 */\nexport interface IOrderedCollection<T = any> extends ISnapshotable<T> {\n /**\n * Adds a value to the collection\n */\n add(value: T);\n\n /**\n * Retrieves a value from the collection.\n */\n remove(): T;\n\n /**\n * Return the size of the collection\n */\n size(): number;\n}\n"]}
@@ -1 +0,0 @@
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,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/ordered-collection\";\nexport const pkgVersion = \"1.4.0-121020\";\n"]}
@@ -1 +0,0 @@
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 +0,0 @@
1
- {"version":3,"file":"testUtils.js","sourceRoot":"","sources":["../src/testUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6CAGsB;AAEtB;;;GAGG;AACI,KAAK,UAAU,kBAAkB,CAAI,UAA0C;IAClF,IAAI,GAAkB,CAAC;IACvB,MAAM,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,KAAQ,EAAE,EAAE;QACxC,GAAG,GAAG,KAAK,CAAC;QACZ,OAAO,4BAAe,CAAC,QAAQ,CAAC;IACpC,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACf,CAAC;AAPD,gDAOC;AAED;;;GAGG;AACI,KAAK,UAAU,sBAAsB,CAAI,UAA0C;IACtF,IAAI,GAAkB,CAAC;IACvB,MAAM,UAAU,CAAC,cAAc,CAAC,KAAK,EAAE,KAAQ,EAAE,EAAE;QAC/C,GAAG,GAAG,KAAK,CAAC;QACZ,OAAO,4BAAe,CAAC,QAAQ,CAAC;IACpC,CAAC,CAAC,CAAC;IACH,OAAO,GAAQ,CAAC;AACpB,CAAC;AAPD,wDAOC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n ConsensusResult,\n IConsensusOrderedCollection,\n} from \"./interfaces\";\n\n/**\n * Helper method to acquire and complete an item\n * Should be used in test code only\n */\nexport async function acquireAndComplete<T>(collection: IConsensusOrderedCollection<T>): Promise<T | undefined> {\n let res: T | undefined;\n await collection.acquire(async (value: T) => {\n res = value;\n return ConsensusResult.Complete;\n });\n return res;\n}\n\n/**\n * Helper method to acquire and complete an item\n * Should be used in test code only\n */\nexport async function waitAcquireAndComplete<T>(collection: IConsensusOrderedCollection<T>): Promise<T> {\n let res: T | undefined;\n await collection.waitAndAcquire(async (value: T) => {\n res = value;\n return ConsensusResult.Complete;\n });\n return res as T;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"consensusOrderedCollection.d.ts","sourceRoot":"","sources":["../src/consensusOrderedCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,yBAAyB,EAAe,MAAM,sCAAsC,CAAC;AAC9F,OAAO,EACH,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACzB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAG5E,OAAO,EACH,iBAAiB,E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AAQ,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, \"fluid_consensusOrderedCollection_\");\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 +0,0 @@
1
- {"version":3,"file":"consensusOrderedCollectionFactory.d.ts","sourceRoot":"","sources":["../src/consensusOrderedCollectionFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EACnB,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,2BAA2B,EAAE,kCAAkC,EAAE,MAAM,cAAc,CAAC;AAG/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Ae,EAAE,CAAC;QAC7B,OAAO,UAAU,CAAC;IACtB,CAAC;;AAjCa,0BAAI,GAAG,mDAAmD,CAAC;AAElD,gCAAU,GAAuB;IACpD,IAAI,EAAE,qBAAqB,CAAC,IAAI;IAChC,qBAAqB,EAAE,KAAK;IAC5B,cAAc,EAAE,UAAU;CAC7B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ConsensusQueue } from \"./consensusQueue\";\nimport { IConsensusOrderedCollection, IConsensusOrderedCollectionFactory } from \"./interfaces\";\nimport { pkgVersion } from \"./packageVersion\";\n\n/**\n * The factory that defines the consensus queue\n */\nexport class ConsensusQueueFactory implements IConsensusOrderedCollectionFactory {\n public static Type = \"https://graph.microsoft.com/types/consensus-queue\";\n\n public static readonly Attributes: IChannelAttributes = {\n type: ConsensusQueueFactory.Type,\n snapshotFormatVersion: \"0.1\",\n packageVersion: pkgVersion,\n };\n\n public get type() {\n return ConsensusQueueFactory.Type;\n }\n\n public get attributes() {\n return ConsensusQueueFactory.Attributes;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}\n */\n public async load(\n runtime: IFluidDataStoreRuntime,\n id: string,\n services: IChannelServices,\n attributes: IChannelAttributes): Promise<IConsensusOrderedCollection> {\n const collection = new ConsensusQueue(id, runtime, attributes);\n await collection.load(services);\n return collection;\n }\n\n public create(document: IFluidDataStoreRuntime, id: string): IConsensusOrderedCollection {\n const collection = new ConsensusQueue(id, document, this.attributes);\n collection.initializeLocal();\n return collection;\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"consensusQueue.d.ts","sourceRoot":"","sources":["../src/consensusQueue.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,sBAAsB,EACtB,kBAAkB,EAClB,eAAe,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AC,IAAI,CAAsB,CAAC;IACtF,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,UAAU;QACpB,OAAO,IAAI,qBAAqB,EAAE,CAAC;IACvC,CAAC;IAED;;;OAGG;IACH,YAAmB,EAAU,EAAE,OAA+B,EAAE,UAA8B;QAC1F,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,iBAAiB,EAAK,CAAC,CAAC;IAC/D,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n IFluidDataStoreRuntime,\n IChannelAttributes,\n IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { ConsensusOrderedCollection } from \"./consensusOrderedCollection\";\nimport { ConsensusQueueFactory } from \"./consensusOrderedCollectionFactory\";\nimport { IOrderedCollection } from \"./interfaces\";\nimport { SnapshotableArray } from \"./snapshotableArray\";\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 public add(value: T) {\n this.data.push(value);\n }\n\n public remove(): T {\n if (this.size() === 0) {\n throw new Error(\"SnapshotableQueue is empty\");\n }\n return this.data.shift() as T;\n }\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 */\nexport class ConsensusQueue<T = any> extends ConsensusOrderedCollection<T> {\n /**\n * Create a new consensus queue\n *\n * @param runtime - data store runtime the new consensus queue belongs to\n * @param id - optional name of theconsensus queue\n * @returns newly create consensus queue (but not attached yet)\n */\n // eslint-disable-next-line @typescript-eslint/no-shadow\n public static create<T = any>(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, ConsensusQueueFactory.Type) as ConsensusQueue<T>;\n }\n\n /**\n * Get a factory for ConsensusQueue to register with the data store.\n *\n * @returns a factory that creates and load ConsensusQueue\n */\n public static getFactory(): IChannelFactory {\n return new ConsensusQueueFactory();\n }\n\n /**\n * Constructs a new consensus queue. If the object is non-local an id and service interfaces will\n * be provided\n */\n public constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes) {\n super(id, runtime, attributes, new SnapshotableQueue<T>());\n }\n}\n"]}
package/lib/index.d.ts DELETED
@@ -1,9 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- export * from "./consensusOrderedCollection";
6
- export * from "./consensusQueue";
7
- export * from "./interfaces";
8
- export * from "./testUtils";
9
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
package/lib/index.js DELETED
@@ -1,9 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- export * from "./consensusOrderedCollection";
6
- export * from "./consensusQueue";
7
- export * from "./interfaces";
8
- export * from "./testUtils";
9
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport * from \"./consensusOrderedCollection\";\nexport * from \"./consensusQueue\";\nexport * from \"./interfaces\";\nexport * from \"./testUtils\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRo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AAC,KAAK,EAAE,CAAC,EAAE,WAAW,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAAC;CACrF;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,WAAW,2BAA2B,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,aAAa,CAAC,iCAAiC,CAAC,CAAC,CAAC,CAAC;IAE7G;;OAEG;IACH,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7B;;;;OAIG;IACH,OAAO,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE1D;;;OAGG;IACH,cAAc,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjE;AAED;;;;;GAKG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC;IAC5B,OAAO,IAAI,CAAC,EAAE,CAAC;IAEf,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC;CAC/B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;IACjE;;OAEG;IACH,GAAG,CAAC,KAAK,EAAE,CAAC,OAAE;IAEd;;OAEG;IACH,MAAM,IAAI,CAAC,CAAC;IAEZ;;OAEG;IACH,IAAI,IAAI,MAAM,CAAC;CAClB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,MAAM,CAAN,IAAY,eAGX;AAHD,WAAY,eAAe;IACvB,2DAAO,CAAA;IACP,6DAAQ,CAAA;AACZ,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 IFluidDataStoreRuntime,\n IChannelServices,\n IChannelAttributes,\n IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISharedObject, ISharedObjectEvents } from \"@fluidframework/shared-object-base\";\n\nexport enum ConsensusResult {\n Release,\n Complete,\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 */\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 */\nexport interface IConsensusOrderedCollectionFactory extends IChannelFactory {\n load(\n document: IFluidDataStoreRuntime,\n id: string,\n services: IChannelServices,\n attributes: IChannelAttributes): Promise<IConsensusOrderedCollection>;\n\n create(document: IFluidDataStoreRuntime, id: string): IConsensusOrderedCollection;\n}\n\n/**\n * Events notifying about addition, acquisition, release and completion of items\n */\nexport interface IConsensusOrderedCollectionEvents<T> extends ISharedObjectEvents {\n\n /**\n * Event fires when new item is added to the queue or\n * an item previously acquired is returned back to a queue (including client loosing connection)\n * @param newlyAdded - indicates if it's newly added item of previously acquired item\n */\n (event: \"add\", listener: (value: T, newlyAdded: boolean) => void): this;\n /**\n * Event fires when a client acquired an item\n * Fires both for locally acquired items, as well as items acquired by remote clients\n */\n (event: \"acquire\", listener: (value: T, clientId?: string) => void): this;\n\n /**\n * \"Complete event fires when a client completes an item.\n */\n (event: \"complete\", listener: (value: T) => void): this;\n\n /**\n * Event fires when locally acquired item is being released back to the queue.\n * Please note that release process is asynchronous, so it takes a while for it to happen\n * (\"add\" event will be fired as result of it)\n * @param intentional - indicates whether release was intentional (result of returning\n * ConsensusResult.Release from callback) or it happened as result of lost connection.\n */\n (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 */\nexport interface IConsensusOrderedCollection<T = any> extends ISharedObject<IConsensusOrderedCollectionEvents<T>> {\n\n /**\n * Adds a value to the collection\n */\n add(value: T): Promise<void>;\n\n /**\n * Retrieves a value from the collection.\n * @returns Returns true (and calls callback with acquired value) if collection was not empty.\n * Otherwise returns false.\n */\n acquire(callback: ConsensusCallback<T>): Promise<boolean>;\n\n /**\n * Wait for a value to be available and remove it from the consensus collection\n * Calls callback with retrieved value.\n */\n waitAndAcquire(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 */\nexport interface ISnapshotable<T> {\n asArray(): T[];\n\n loadFrom(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 */\nexport interface IOrderedCollection<T = any> extends ISnapshotable<T> {\n /**\n * Adds a value to the collection\n */\n add(value: T);\n\n /**\n * Retrieves a value from the collection.\n */\n remove(): T;\n\n /**\n * Return the size of the collection\n */\n size(): number;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,uCAAuC,CAAC;AAC5D,eAAO,MAAM,UAAU,iBAAiB,CAAC"}
@@ -1 +0,0 @@
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,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/ordered-collection\";\nexport const pkgVersion = \"1.4.0-121020\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"snapshotableArray.d.ts","sourceRoot":"","sources":["../src/snapshotableArray.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,qBAAa,iBAAiB,CAAC,CAAC,CAAE,SAAQ,KAAK;IAC3C,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,CAAM;IAElB,OAAO;IAID,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAKxC,IAAI,IAAI,MAAM;CAGxB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"snapshotableArray.js","sourceRoot":"","sources":["../src/snapshotableArray.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAEtD,MAAM,OAAO,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,MAAM,CAAC,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","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 +0,0 @@
1
- {"version":3,"file":"testUtils.d.ts","sourceRoot":"","sources":["../src/testUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEH,2BAA2B,EAC9B,MAAM,cAAc,CAAC;AAEtB;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EAAE,UAAU,EAAE,2BAA2B,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAO9G;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,CAAC,CAAC,EAAE,UAAU,EAAE,2BAA2B,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAOtG"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"testUtils.js","sourceRoot":"","sources":["../src/testUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,eAAe,GAElB,MAAM,cAAc,CAAC;AAEtB;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAI,UAA0C;IAClF,IAAI,GAAkB,CAAC;IACvB,MAAM,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,KAAQ,EAAE,EAAE;QACxC,GAAG,GAAG,KAAK,CAAC;QACZ,OAAO,eAAe,CAAC,QAAQ,CAAC;IACpC,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACf,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAI,UAA0C;IACtF,IAAI,GAAkB,CAAC;IACvB,MAAM,UAAU,CAAC,cAAc,CAAC,KAAK,EAAE,KAAQ,EAAE,EAAE;QAC/C,GAAG,GAAG,KAAK,CAAC;QACZ,OAAO,eAAe,CAAC,QAAQ,CAAC;IACpC,CAAC,CAAC,CAAC;IACH,OAAO,GAAQ,CAAC;AACpB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n ConsensusResult,\n IConsensusOrderedCollection,\n} from \"./interfaces\";\n\n/**\n * Helper method to acquire and complete an item\n * Should be used in test code only\n */\nexport async function acquireAndComplete<T>(collection: IConsensusOrderedCollection<T>): Promise<T | undefined> {\n let res: T | undefined;\n await collection.acquire(async (value: T) => {\n res = value;\n return ConsensusResult.Complete;\n });\n return res;\n}\n\n/**\n * Helper method to acquire and complete an item\n * Should be used in test code only\n */\nexport async function waitAcquireAndComplete<T>(collection: IConsensusOrderedCollection<T>): Promise<T> {\n let res: T | undefined;\n await collection.waitAndAcquire(async (value: T) => {\n res = value;\n return ConsensusResult.Complete;\n });\n return res as T;\n}\n"]}
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./lib",
5
- "module": "esnext"
6
- },
7
- }