@fluidframework/tree 2.10.0-305357 → 2.10.0-306579

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 (234) hide show
  1. package/.eslintrc.cjs +56 -25
  2. package/api-report/tree.alpha.api.md +3 -2
  3. package/api-report/tree.beta.api.md +3 -2
  4. package/api-report/tree.legacy.alpha.api.md +3 -2
  5. package/api-report/tree.legacy.public.api.md +3 -2
  6. package/api-report/tree.public.api.md +3 -2
  7. package/dist/core/forest/forest.d.ts +5 -1
  8. package/dist/core/forest/forest.d.ts.map +1 -1
  9. package/dist/core/forest/forest.js.map +1 -1
  10. package/dist/core/index.d.ts +1 -1
  11. package/dist/core/index.d.ts.map +1 -1
  12. package/dist/core/index.js.map +1 -1
  13. package/dist/core/schema-stored/storedSchemaRepository.d.ts +7 -3
  14. package/dist/core/schema-stored/storedSchemaRepository.d.ts.map +1 -1
  15. package/dist/core/schema-stored/storedSchemaRepository.js +4 -6
  16. package/dist/core/schema-stored/storedSchemaRepository.js.map +1 -1
  17. package/dist/core/tree/anchorSet.d.ts +8 -5
  18. package/dist/core/tree/anchorSet.d.ts.map +1 -1
  19. package/dist/core/tree/anchorSet.js +12 -11
  20. package/dist/core/tree/anchorSet.js.map +1 -1
  21. package/dist/events/emitter.d.ts +21 -9
  22. package/dist/events/emitter.d.ts.map +1 -1
  23. package/dist/events/emitter.js +36 -21
  24. package/dist/events/emitter.js.map +1 -1
  25. package/dist/events/listeners.d.ts +16 -5
  26. package/dist/events/listeners.d.ts.map +1 -1
  27. package/dist/events/listeners.js.map +1 -1
  28. package/dist/feature-libraries/chunked-forest/chunkTree.js +1 -1
  29. package/dist/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  30. package/dist/feature-libraries/chunked-forest/chunkedForest.d.ts +3 -2
  31. package/dist/feature-libraries/chunked-forest/chunkedForest.d.ts.map +1 -1
  32. package/dist/feature-libraries/chunked-forest/chunkedForest.js +14 -9
  33. package/dist/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  34. package/dist/feature-libraries/flex-tree/context.d.ts +3 -2
  35. package/dist/feature-libraries/flex-tree/context.d.ts.map +1 -1
  36. package/dist/feature-libraries/flex-tree/context.js +3 -3
  37. package/dist/feature-libraries/flex-tree/context.js.map +1 -1
  38. package/dist/feature-libraries/flex-tree/lazyField.js +1 -1
  39. package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
  40. package/dist/feature-libraries/flex-tree/lazyNode.js +1 -1
  41. package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  42. package/dist/feature-libraries/flex-tree/utilities.js +1 -1
  43. package/dist/feature-libraries/flex-tree/utilities.js.map +1 -1
  44. package/dist/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
  45. package/dist/feature-libraries/modular-schema/comparison.js +3 -0
  46. package/dist/feature-libraries/modular-schema/comparison.js.map +1 -1
  47. package/dist/feature-libraries/modular-schema/discrepancies.d.ts +2 -2
  48. package/dist/feature-libraries/modular-schema/discrepancies.d.ts.map +1 -1
  49. package/dist/feature-libraries/modular-schema/discrepancies.js +90 -44
  50. package/dist/feature-libraries/modular-schema/discrepancies.js.map +1 -1
  51. package/dist/feature-libraries/modular-schema/genericFieldKind.js +2 -2
  52. package/dist/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  53. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +1 -1
  54. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  55. package/dist/feature-libraries/object-forest/objectForest.d.ts +2 -2
  56. package/dist/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
  57. package/dist/feature-libraries/object-forest/objectForest.js +6 -8
  58. package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
  59. package/dist/feature-libraries/schema-index/schemaSummarizer.js +1 -1
  60. package/dist/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  61. package/dist/feature-libraries/sequence-field/compose.js +2 -2
  62. package/dist/feature-libraries/sequence-field/compose.js.map +1 -1
  63. package/dist/feature-libraries/sequence-field/markListFactory.js +1 -1
  64. package/dist/feature-libraries/sequence-field/markListFactory.js.map +1 -1
  65. package/dist/packageVersion.d.ts +1 -1
  66. package/dist/packageVersion.js +1 -1
  67. package/dist/packageVersion.js.map +1 -1
  68. package/dist/shared-tree/schematizingTreeView.js +2 -2
  69. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  70. package/dist/shared-tree/treeApi.js +2 -2
  71. package/dist/shared-tree/treeApi.js.map +1 -1
  72. package/dist/shared-tree/treeCheckout.js +7 -7
  73. package/dist/shared-tree/treeCheckout.js.map +1 -1
  74. package/dist/shared-tree-core/branch.d.ts +7 -7
  75. package/dist/shared-tree-core/branch.d.ts.map +1 -1
  76. package/dist/shared-tree-core/branch.js +35 -25
  77. package/dist/shared-tree-core/branch.js.map +1 -1
  78. package/dist/shared-tree-core/editManager.js +4 -4
  79. package/dist/shared-tree-core/editManager.js.map +1 -1
  80. package/dist/shared-tree-core/sharedTreeCore.js +5 -5
  81. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  82. package/dist/simple-tree/api/schemaFactory.d.ts +66 -10
  83. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  84. package/dist/simple-tree/api/schemaFactory.js +34 -9
  85. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  86. package/dist/simple-tree/api/treeNodeApi.js +4 -4
  87. package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
  88. package/dist/simple-tree/arrayNode.js +1 -1
  89. package/dist/simple-tree/arrayNode.js.map +1 -1
  90. package/dist/simple-tree/core/treeNodeKernel.d.ts +3 -3
  91. package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  92. package/dist/simple-tree/core/treeNodeKernel.js +7 -8
  93. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  94. package/dist/simple-tree/proxies.js +1 -1
  95. package/dist/simple-tree/proxies.js.map +1 -1
  96. package/dist/simple-tree/schemaTypes.d.ts +26 -1
  97. package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
  98. package/dist/simple-tree/schemaTypes.js.map +1 -1
  99. package/dist/simple-tree/treeNodeValid.js +2 -2
  100. package/dist/simple-tree/treeNodeValid.js.map +1 -1
  101. package/dist/util/nestedMap.d.ts.map +1 -1
  102. package/dist/util/nestedMap.js.map +1 -1
  103. package/lib/core/forest/forest.d.ts +5 -1
  104. package/lib/core/forest/forest.d.ts.map +1 -1
  105. package/lib/core/forest/forest.js.map +1 -1
  106. package/lib/core/index.d.ts +1 -1
  107. package/lib/core/index.d.ts.map +1 -1
  108. package/lib/core/index.js.map +1 -1
  109. package/lib/core/schema-stored/storedSchemaRepository.d.ts +7 -3
  110. package/lib/core/schema-stored/storedSchemaRepository.d.ts.map +1 -1
  111. package/lib/core/schema-stored/storedSchemaRepository.js +4 -6
  112. package/lib/core/schema-stored/storedSchemaRepository.js.map +1 -1
  113. package/lib/core/tree/anchorSet.d.ts +8 -5
  114. package/lib/core/tree/anchorSet.d.ts.map +1 -1
  115. package/lib/core/tree/anchorSet.js +12 -11
  116. package/lib/core/tree/anchorSet.js.map +1 -1
  117. package/lib/events/emitter.d.ts +21 -9
  118. package/lib/events/emitter.d.ts.map +1 -1
  119. package/lib/events/emitter.js +37 -22
  120. package/lib/events/emitter.js.map +1 -1
  121. package/lib/events/listeners.d.ts +16 -5
  122. package/lib/events/listeners.d.ts.map +1 -1
  123. package/lib/events/listeners.js.map +1 -1
  124. package/lib/feature-libraries/chunked-forest/chunkTree.js +1 -1
  125. package/lib/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  126. package/lib/feature-libraries/chunked-forest/chunkedForest.d.ts +3 -2
  127. package/lib/feature-libraries/chunked-forest/chunkedForest.d.ts.map +1 -1
  128. package/lib/feature-libraries/chunked-forest/chunkedForest.js +14 -9
  129. package/lib/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  130. package/lib/feature-libraries/flex-tree/context.d.ts +3 -2
  131. package/lib/feature-libraries/flex-tree/context.d.ts.map +1 -1
  132. package/lib/feature-libraries/flex-tree/context.js +3 -3
  133. package/lib/feature-libraries/flex-tree/context.js.map +1 -1
  134. package/lib/feature-libraries/flex-tree/lazyField.js +1 -1
  135. package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
  136. package/lib/feature-libraries/flex-tree/lazyNode.js +1 -1
  137. package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  138. package/lib/feature-libraries/flex-tree/utilities.js +1 -1
  139. package/lib/feature-libraries/flex-tree/utilities.js.map +1 -1
  140. package/lib/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
  141. package/lib/feature-libraries/modular-schema/comparison.js +3 -0
  142. package/lib/feature-libraries/modular-schema/comparison.js.map +1 -1
  143. package/lib/feature-libraries/modular-schema/discrepancies.d.ts +2 -2
  144. package/lib/feature-libraries/modular-schema/discrepancies.d.ts.map +1 -1
  145. package/lib/feature-libraries/modular-schema/discrepancies.js +91 -45
  146. package/lib/feature-libraries/modular-schema/discrepancies.js.map +1 -1
  147. package/lib/feature-libraries/modular-schema/genericFieldKind.js +2 -2
  148. package/lib/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  149. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +1 -1
  150. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  151. package/lib/feature-libraries/object-forest/objectForest.d.ts +2 -2
  152. package/lib/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
  153. package/lib/feature-libraries/object-forest/objectForest.js +6 -8
  154. package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
  155. package/lib/feature-libraries/schema-index/schemaSummarizer.js +1 -1
  156. package/lib/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  157. package/lib/feature-libraries/sequence-field/compose.js +2 -2
  158. package/lib/feature-libraries/sequence-field/compose.js.map +1 -1
  159. package/lib/feature-libraries/sequence-field/markListFactory.js +1 -1
  160. package/lib/feature-libraries/sequence-field/markListFactory.js.map +1 -1
  161. package/lib/packageVersion.d.ts +1 -1
  162. package/lib/packageVersion.js +1 -1
  163. package/lib/packageVersion.js.map +1 -1
  164. package/lib/shared-tree/schematizingTreeView.js +2 -2
  165. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  166. package/lib/shared-tree/treeApi.js +2 -2
  167. package/lib/shared-tree/treeApi.js.map +1 -1
  168. package/lib/shared-tree/treeCheckout.js +7 -7
  169. package/lib/shared-tree/treeCheckout.js.map +1 -1
  170. package/lib/shared-tree-core/branch.d.ts +7 -7
  171. package/lib/shared-tree-core/branch.d.ts.map +1 -1
  172. package/lib/shared-tree-core/branch.js +36 -26
  173. package/lib/shared-tree-core/branch.js.map +1 -1
  174. package/lib/shared-tree-core/editManager.js +4 -4
  175. package/lib/shared-tree-core/editManager.js.map +1 -1
  176. package/lib/shared-tree-core/sharedTreeCore.js +5 -5
  177. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  178. package/lib/simple-tree/api/schemaFactory.d.ts +66 -10
  179. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  180. package/lib/simple-tree/api/schemaFactory.js +34 -9
  181. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  182. package/lib/simple-tree/api/treeNodeApi.js +4 -4
  183. package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
  184. package/lib/simple-tree/arrayNode.js +1 -1
  185. package/lib/simple-tree/arrayNode.js.map +1 -1
  186. package/lib/simple-tree/core/treeNodeKernel.d.ts +3 -3
  187. package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  188. package/lib/simple-tree/core/treeNodeKernel.js +7 -8
  189. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  190. package/lib/simple-tree/proxies.js +1 -1
  191. package/lib/simple-tree/proxies.js.map +1 -1
  192. package/lib/simple-tree/schemaTypes.d.ts +26 -1
  193. package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
  194. package/lib/simple-tree/schemaTypes.js.map +1 -1
  195. package/lib/simple-tree/treeNodeValid.js +2 -2
  196. package/lib/simple-tree/treeNodeValid.js.map +1 -1
  197. package/lib/util/nestedMap.d.ts.map +1 -1
  198. package/lib/util/nestedMap.js.map +1 -1
  199. package/package.json +20 -20
  200. package/src/core/forest/forest.ts +6 -1
  201. package/src/core/index.ts +1 -1
  202. package/src/core/schema-stored/storedSchemaRepository.ts +10 -13
  203. package/src/core/tree/anchorSet.ts +13 -20
  204. package/src/events/emitter.ts +45 -24
  205. package/src/events/listeners.ts +17 -5
  206. package/src/feature-libraries/chunked-forest/chunkTree.ts +1 -1
  207. package/src/feature-libraries/chunked-forest/chunkedForest.ts +8 -14
  208. package/src/feature-libraries/flex-tree/context.ts +5 -7
  209. package/src/feature-libraries/flex-tree/lazyField.ts +1 -1
  210. package/src/feature-libraries/flex-tree/lazyNode.ts +1 -1
  211. package/src/feature-libraries/flex-tree/utilities.ts +1 -1
  212. package/src/feature-libraries/modular-schema/comparison.ts +4 -0
  213. package/src/feature-libraries/modular-schema/discrepancies.ts +116 -50
  214. package/src/feature-libraries/modular-schema/genericFieldKind.ts +2 -2
  215. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +1 -1
  216. package/src/feature-libraries/object-forest/objectForest.ts +5 -11
  217. package/src/feature-libraries/schema-index/schemaSummarizer.ts +1 -1
  218. package/src/feature-libraries/sequence-field/compose.ts +2 -2
  219. package/src/feature-libraries/sequence-field/markListFactory.ts +1 -1
  220. package/src/packageVersion.ts +1 -1
  221. package/src/shared-tree/schematizingTreeView.ts +2 -2
  222. package/src/shared-tree/treeApi.ts +2 -2
  223. package/src/shared-tree/treeCheckout.ts +7 -7
  224. package/src/shared-tree-core/branch.ts +30 -30
  225. package/src/shared-tree-core/editManager.ts +4 -4
  226. package/src/shared-tree-core/sharedTreeCore.ts +5 -5
  227. package/src/simple-tree/api/schemaFactory.ts +37 -11
  228. package/src/simple-tree/api/treeNodeApi.ts +4 -4
  229. package/src/simple-tree/arrayNode.ts +1 -1
  230. package/src/simple-tree/core/treeNodeKernel.ts +8 -10
  231. package/src/simple-tree/proxies.ts +1 -1
  232. package/src/simple-tree/schemaTypes.ts +26 -1
  233. package/src/simple-tree/treeNodeValid.ts +2 -2
  234. package/src/util/nestedMap.ts +1 -0
@@ -1 +1 @@
1
- {"version":3,"file":"nestedMap.js","sourceRoot":"","sources":["../../src/util/nestedMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAiB1D;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAChC,GAAiC,EACjC,IAAU,EACV,IAAU,EACV,KAAY;IAEZ,IAAI,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC7B,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC5B,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAC;QACrB,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACzB,CAAC;IACD,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IACD,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC1B,OAAO,SAAS,CAAC;AAClB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAChC,MAA4C,EAC5C,WAAyC,EACzC,QAAiB;IAEjB,KAAK,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,MAAM,EAAE,CAAC;QAC1C,IAAI,gBAAgB,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,gBAAgB,KAAK,SAAS,EAAE,CAAC;YACpC,gBAAgB,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC;YACxC,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,g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ors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { oob } from \"@fluidframework/core-utils/internal\";\nimport type { MapGetSet } from \"./utils.js\";\n\n/**\n * A dictionary whose values are keyed off of two objects (key1, key2).\n * As it is a nested map, size() will return the number of distinct key1s.\n * If you need constant-time access to the number of values, use SizedNestedMap instead.\n *\n * This code assumes values will not be undefined (keys can be undefined).\n */\nexport type NestedMap<Key1, Key2, Value> = Map<Key1, Map<Key2, Value>>;\n\n/**\n * A read-only version of {@link NestedMap}.\n */\nexport type ReadonlyNestedMap<Key1, Key2, Value> = ReadonlyMap<Key1, ReadonlyMap<Key2, Value>>;\n\n/**\n * If (key1, key2) already has a value in the map, it is returned, otherwise value is added under (key1, key2) and undefined is returned.\n */\nexport function tryAddToNestedMap<Key1, Key2, Value>(\n\tmap: NestedMap<Key1, Key2, Value>,\n\tkey1: Key1,\n\tkey2: Key2,\n\tvalue: Value,\n): Value | undefined {\n\tlet innerMap = map.get(key1);\n\tif (innerMap === undefined) {\n\t\tinnerMap = new Map();\n\t\tmap.set(key1, innerMap);\n\t}\n\tif (innerMap.has(key2)) {\n\t\treturn innerMap.get(key2);\n\t}\n\tinnerMap.set(key2, value);\n\treturn undefined;\n}\n\n/**\n * Copies over all entries from the source map into the destination map.\n *\n * @param source - The map to copy data from. Not mutated.\n * @param destination - The map to copy data into. Both the outer and inner map may be mutated.\n * @param override - Whether existing entries in `destination` should be replaced by corresponding entries in `source`.\n *\n * @remarks - This function performs deep copying when necessary.\n * This ensures that mutating `destination` after this call will not result in unexpected mutations to `source`.\n */\nexport function populateNestedMap<Key1, Key2, Value>(\n\tsource: ReadonlyNestedMap<Key1, Key2, Value>,\n\tdestination: NestedMap<Key1, Key2, Value>,\n\toverride: boolean,\n): void {\n\tfor (const [key1, sourceInner] of source) {\n\t\tlet destinationInner = destination.get(key1);\n\t\tif (destinationInner === undefined) {\n\t\t\tdestinationInner = new Map(sourceInner);\n\t\t\tdestination.set(key1, destinationInner);\n\t\t} else {\n\t\t\tfor (const [key2, value] of sourceInner) {\n\t\t\t\tif (override || !destinationInner.has(key2)) {\n\t\t\t\t\tdestinationInner.set(key2, value);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Sets the value at (key1, key2) in map to value.\n * If there already is a value for (key1, key2), it is replaced with the provided one.\n */\nexport function setInNestedMap<Key1, Key2, Value>(\n\tmap: NestedMap<Key1, Key2, Value>,\n\tkey1: Key1,\n\tkey2: Key2,\n\tvalue: Value,\n): void {\n\tconst innerMap = getOrAddInMap(map, key1, new Map<Key2, Value>());\n\tinnerMap.set(key2, value);\n}\n\n/**\n * Sets the value at `key` in map to value if not already present.\n * Returns the value at `key` after setting it.\n * This is equivalent to a get or default that adds the default to the map.\n */\nexport function getOrAddInMap<Key, Value>(\n\tmap: MapGetSet<Key, Value>,\n\tkey: Key,\n\tvalue: Value,\n): Value {\n\tconst currentValue = map.get(key);\n\tif (currentValue !== undefined) {\n\t\treturn currentValue;\n\t}\n\tmap.set(key, value);\n\treturn value;\n}\n\n/**\n * Sets the value at `key` in `map` to `generateValue()` if not already present.\n * Returns the value at `key` after setting it.\n */\nexport function getOrAddInMapLazy<Key, Value>(\n\tmap: MapGetSet<Key, Value>,\n\tkey: Key,\n\tgenerateValue: () => Value,\n): Value {\n\tconst currentValue = map.get(key);\n\tif (currentValue !== undefined) {\n\t\treturn currentValue;\n\t}\n\n\tconst value = generateValue();\n\tmap.set(key, value);\n\treturn value;\n}\n\n/**\n * Returns the value at (key1, key2) in map, or undefined if not present.\n */\nexport function tryGetFromNestedMap<Key1, Key2, Value>(\n\tmap: NestedMap<Key1, Key2, Value>,\n\tkey1: Key1,\n\tkey2: Key2,\n): Value | undefined {\n\tconst innerMap = map.get(key1);\n\tif (innerMap === undefined) {\n\t\treturn undefined;\n\t}\n\treturn innerMap.get(key2);\n}\n\n/**\n * If (key1, key2) is not in the map, add value to the map.\n * Returns whatever is at (key1, key2) in map (which will be value if it was empty before).\n */\nexport function getOrAddInNestedMap<Key1, Key2, Value>(\n\tmap: NestedMap<Key1, Key2, Value>,\n\tkey1: Key1,\n\tkey2: Key2,\n\tvalue: Value,\n): Value {\n\tconst existing = tryAddToNestedMap(map, key1, key2, value);\n\tif (existing !== undefined) {\n\t\treturn existing;\n\t}\n\treturn value;\n}\n\n/**\n * Does not change map.\n * If (key1, key2) is not in map, returns value.\n * If (key1, key2) is in map, return its entry.\n */\nexport function getOrDefaultInNestedMap<Key1, Key2, Value>(\n\tmap: NestedMap<Key1, Key2, Value>,\n\tkey1: Key1,\n\tkey2: Key2,\n\tvalue: Value,\n): Value {\n\tconst existing = tryGetFromNestedMap(map, key1, key2);\n\tif (existing !== undefined) {\n\t\treturn existing;\n\t}\n\treturn value;\n}\n\n/**\n * Removes the value at (key1, key2) from the map.\n *\n * @returns true iff found.\n */\nexport function deleteFromNestedMap<Key1, Key2, Value>(\n\tmap: NestedMap<Key1, Key2, Value>,\n\tkey1: Key1,\n\tkey2: Key2,\n): boolean {\n\tconst innerMap = map.get(key1);\n\tif (innerMap === undefined) {\n\t\treturn false;\n\t}\n\tconst deleted = innerMap.delete(key2);\n\tif (innerMap.size === 0) {\n\t\tmap.delete(key1);\n\t}\n\treturn deleted;\n}\n\n/**\n * Converts a nested map to a flat list of triplets.\n */\nexport function nestedMapToFlatList<Key1, Key2, Value>(\n\tmap: ReadonlyNestedMap<Key1, Key2, Value>,\n): [Key1, Key2, Value][] {\n\tconst list: [Key1, Key2, Value][] = [];\n\tmap.forEach((innerMap, key1) => {\n\t\tinnerMap.forEach((val, key2) => {\n\t\t\tlist.push([key1, key2, val]);\n\t\t});\n\t});\n\treturn list;\n}\n\n/**\n * Builds a nested map from a flat list of triplets.\n */\nexport function nestedMapFromFlatList<Key1, Key2, Value>(\n\tlist: readonly (readonly [Key1, Key2, Value])[],\n): NestedMap<Key1, Key2, Value> {\n\tconst map = new Map<Key1, Map<Key2, Value>>();\n\tfor (const [key1, key2, val] of list) {\n\t\tgetOrAddInMap(map, key1, new Map<Key2, Value>()).set(key2, val);\n\t}\n\treturn map;\n}\n\nexport function forEachInNestedMap<Key1, Key2, Value>(\n\tmap: ReadonlyNestedMap<Key1, Key2, Value>,\n\tdelegate: (value: Value, key1: Key1, key2: Key2) => void,\n): void {\n\tmap.forEach((innerMap, keyFirst) => {\n\t\tinnerMap.forEach((val, keySecond) => {\n\t\t\tdelegate(val, keyFirst, keySecond);\n\t\t});\n\t});\n}\n\n/**\n * Maps the `input` map values using the provided `delegate`.\n *\n * @param input - The `NestedMap` whose contents are being mapped.\n * @param delegate - The delegate to use for mapping values,\n * @returns A new `NestedMap` with the same keys as `input`, but with the values produced by `delegate`.\n */\nexport function mapNestedMap<Key1, Key2, ValueIn, ValueOut = ValueIn>(\n\tinput: ReadonlyNestedMap<Key1, Key2, ValueIn>,\n\tdelegate: (value: ValueIn, key1: Key1, key2: Key2) => ValueOut,\n): NestedMap<Key1, Key2, ValueOut> {\n\tconst output = new Map<Key1, Map<Key2, ValueOut>>();\n\tinput.forEach((inputInnerMap, keyFirst) => {\n\t\tconst outputInnerMap = new Map<Key2, ValueOut>();\n\t\tinputInnerMap.forEach((val, keySecond) => {\n\t\t\tconst mappedValue = delegate(val, keyFirst, keySecond);\n\t\t\toutputInnerMap.set(keySecond, mappedValue);\n\t\t});\n\t\toutput.set(keyFirst, outputInnerMap);\n\t});\n\treturn output;\n}\n\n/**\n * Map with two keys; same semantics as NestedMap, but maintains a size count for the entire collection.\n * Note: undefined is not supported as a value, and will cause incorrect behavior.\n */\nexport class SizedNestedMap<Key1, Key2, Value> {\n\tprivate readonly nestedMap: NestedMap<Key1, Key2, Value> = new Map();\n\tprivate count = 0;\n\n\t/**\n\t * Returns the total number of elements in this nested map.\n\t */\n\tpublic get size(): number {\n\t\treturn this.count;\n\t}\n\n\t/**\n\t * If (key1, key2) already has a value in the map, it is returned, otherwise value is added under (key1, key2) and undefined is\n\t * returned.\n\t */\n\tpublic tryGet(key1: Key1, key2: Key2): Value | undefined {\n\t\treturn tryGetFromNestedMap(this.nestedMap, key1, key2);\n\t}\n\n\t/**\n\t * Does not change map.\n\t * If (key1, key2) is not in map, returns value.\n\t * If (key1, key2) is in map, return its entry.\n\t */\n\tpublic getOrDefault(key1: Key1, key2: Key2, value: Value): Value {\n\t\treturn getOrDefaultInNestedMap(this.nestedMap, key1, key2, value);\n\t}\n\n\t/**\n\t * If (key1, key2) already has a value in the map, it is returned, otherwise value is added under (key1, key2) and undefined is\n\t * returned.\n\t */\n\tpublic tryAdd(key1: Key1, key2: Key2, value: Value): Value | undefined {\n\t\tconst currentVal = tryAddToNestedMap(this.nestedMap, key1, key2, value);\n\t\tif (currentVal === undefined) {\n\t\t\tthis.count++;\n\t\t}\n\t\treturn currentVal;\n\t}\n\n\t/**\n\t * Sets the value at (key1, key2) in map to value.\n\t * If there already is a value for (key1, key2), it is replaced with the provided one.\n\t */\n\tpublic set(key1: Key1, key2: Key2, value: Value): void {\n\t\tif (this.tryAdd(key1, key2, value) !== undefined) {\n\t\t\tsetInNestedMap(this.nestedMap, key1, key2, value);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the value at (key1, key2) from the map.\n\t * Returns true iff found.\n\t */\n\tpublic delete(key1: Key1, key2: Key2): boolean {\n\t\tconst deleted = deleteFromNestedMap(this.nestedMap, key1, key2);\n\t\tif (deleted) {\n\t\t\tthis.count--;\n\t\t}\n\t\treturn deleted;\n\t}\n\n\t/**\n\t * Runs the supplied delegate for every (value, key1, key2).\n\t */\n\tpublic forEach(delegate: (value: Value, key1: Key1, key2: Key2) => void): void {\n\t\tforEachInNestedMap(this.nestedMap, delegate);\n\t}\n\n\t/**\n\t * Clears the map.\n\t */\n\tpublic clear(): void {\n\t\tthis.count = 0;\n\t\tthis.nestedMap.clear();\n\t}\n\n\tpublic values(): IterableIterator<Value> {\n\t\treturn (\n\t\t\tArray.from(this.nestedMap.values()).flatMap((innerMap) => innerMap.values())[0] ?? oob()\n\t\t);\n\t}\n\n\tpublic [Symbol.iterator](): IterableIterator<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AC,IAAU,EAAE,IAAU,EAAE,KAAY;QAC9C,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,SAAS,EAAE,CAAC;YAClD,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QACnD,CAAC;IACF,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,IAAU,EAAE,IAAU;QACnC,MAAM,OAAO,GAAG,mBAAmB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAChE,IAAI,OAAO,EAAE,CAAC;YACb,IAAI,CAAC,KAAK,EAAE,CAAC;QACd,CAAC;QACD,OAAO,OAAO,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,QAAwD;QACtE,kBAAkB,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACI,KAAK;QACX,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACf,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;IAEM,MAAM;QACZ,OAAO,CACN,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CACxF,CAAC;IACH,CAAC;IAEM,CAAC,MAAM,CAAC,QAAQ,CAAC;QACvB,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC1C,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { oob } from \"@fluidframework/core-utils/internal\";\n\nimport type { MapGetSet } from \"./utils.js\";\n\n/**\n * A dictionary whose values are keyed off of two objects (key1, key2).\n * As it is a nested map, size() will return the number of distinct key1s.\n * If you need constant-time access to the number of values, use SizedNestedMap instead.\n *\n * This code assumes values will not be undefined (keys can be undefined).\n */\nexport type NestedMap<Key1, Key2, Value> = Map<Key1, Map<Key2, Value>>;\n\n/**\n * A read-only version of {@link NestedMap}.\n */\nexport type ReadonlyNestedMap<Key1, Key2, Value> = ReadonlyMap<Key1, ReadonlyMap<Key2, Value>>;\n\n/**\n * If (key1, key2) already has a value in the map, it is returned, otherwise value is added under (key1, key2) and undefined is returned.\n */\nexport function tryAddToNestedMap<Key1, Key2, Value>(\n\tmap: NestedMap<Key1, Key2, Value>,\n\tkey1: Key1,\n\tkey2: Key2,\n\tvalue: Value,\n): Value | undefined {\n\tlet innerMap = map.get(key1);\n\tif (innerMap === undefined) {\n\t\tinnerMap = new Map();\n\t\tmap.set(key1, innerMap);\n\t}\n\tif (innerMap.has(key2)) {\n\t\treturn innerMap.get(key2);\n\t}\n\tinnerMap.set(key2, value);\n\treturn undefined;\n}\n\n/**\n * Copies over all entries from the source map into the destination map.\n *\n * @param source - The map to copy data from. Not mutated.\n * @param destination - The map to copy data into. Both the outer and inner map may be mutated.\n * @param override - Whether existing entries in `destination` should be replaced by corresponding entries in `source`.\n *\n * @remarks - This function performs deep copying when necessary.\n * This ensures that mutating `destination` after this call will not result in unexpected mutations to `source`.\n */\nexport function populateNestedMap<Key1, Key2, Value>(\n\tsource: ReadonlyNestedMap<Key1, Key2, Value>,\n\tdestination: NestedMap<Key1, Key2, Value>,\n\toverride: boolean,\n): void {\n\tfor (const [key1, sourceInner] of source) {\n\t\tlet destinationInner = destination.get(key1);\n\t\tif (destinationInner === undefined) {\n\t\t\tdestinationInner = new Map(sourceInner);\n\t\t\tdestination.set(key1, destinationInner);\n\t\t} else {\n\t\t\tfor (const [key2, value] of sourceInner) {\n\t\t\t\tif (override || !destinationInner.has(key2)) {\n\t\t\t\t\tdestinationInner.set(key2, value);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Sets the value at (key1, key2) in map to value.\n * If there already is a value for (key1, key2), it is replaced with the provided one.\n */\nexport function setInNestedMap<Key1, Key2, Value>(\n\tmap: NestedMap<Key1, Key2, Value>,\n\tkey1: Key1,\n\tkey2: Key2,\n\tvalue: Value,\n): void {\n\tconst innerMap = getOrAddInMap(map, key1, new Map<Key2, Value>());\n\tinnerMap.set(key2, value);\n}\n\n/**\n * Sets the value at `key` in map to value if not already present.\n * Returns the value at `key` after setting it.\n * This is equivalent to a get or default that adds the default to the map.\n */\nexport function getOrAddInMap<Key, Value>(\n\tmap: MapGetSet<Key, Value>,\n\tkey: Key,\n\tvalue: Value,\n): Value {\n\tconst currentValue = map.get(key);\n\tif (currentValue !== undefined) {\n\t\treturn currentValue;\n\t}\n\tmap.set(key, value);\n\treturn value;\n}\n\n/**\n * Sets the value at `key` in `map` to `generateValue()` if not already present.\n * Returns the value at `key` after setting it.\n */\nexport function getOrAddInMapLazy<Key, Value>(\n\tmap: MapGetSet<Key, Value>,\n\tkey: Key,\n\tgenerateValue: () => Value,\n): Value {\n\tconst currentValue = map.get(key);\n\tif (currentValue !== undefined) {\n\t\treturn currentValue;\n\t}\n\n\tconst value = generateValue();\n\tmap.set(key, value);\n\treturn value;\n}\n\n/**\n * Returns the value at (key1, key2) in map, or undefined if not present.\n */\nexport function tryGetFromNestedMap<Key1, Key2, Value>(\n\tmap: NestedMap<Key1, Key2, Value>,\n\tkey1: Key1,\n\tkey2: Key2,\n): Value | undefined {\n\tconst innerMap = map.get(key1);\n\tif (innerMap === undefined) {\n\t\treturn undefined;\n\t}\n\treturn innerMap.get(key2);\n}\n\n/**\n * If (key1, key2) is not in the map, add value to the map.\n * Returns whatever is at (key1, key2) in map (which will be value if it was empty before).\n */\nexport function getOrAddInNestedMap<Key1, Key2, Value>(\n\tmap: NestedMap<Key1, Key2, Value>,\n\tkey1: Key1,\n\tkey2: Key2,\n\tvalue: Value,\n): Value {\n\tconst existing = tryAddToNestedMap(map, key1, key2, value);\n\tif (existing !== undefined) {\n\t\treturn existing;\n\t}\n\treturn value;\n}\n\n/**\n * Does not change map.\n * If (key1, key2) is not in map, returns value.\n * If (key1, key2) is in map, return its entry.\n */\nexport function getOrDefaultInNestedMap<Key1, Key2, Value>(\n\tmap: NestedMap<Key1, Key2, Value>,\n\tkey1: Key1,\n\tkey2: Key2,\n\tvalue: Value,\n): Value {\n\tconst existing = tryGetFromNestedMap(map, key1, key2);\n\tif (existing !== undefined) {\n\t\treturn existing;\n\t}\n\treturn value;\n}\n\n/**\n * Removes the value at (key1, key2) from the map.\n *\n * @returns true iff found.\n */\nexport function deleteFromNestedMap<Key1, Key2, Value>(\n\tmap: NestedMap<Key1, Key2, Value>,\n\tkey1: Key1,\n\tkey2: Key2,\n): boolean {\n\tconst innerMap = map.get(key1);\n\tif (innerMap === undefined) {\n\t\treturn false;\n\t}\n\tconst deleted = innerMap.delete(key2);\n\tif (innerMap.size === 0) {\n\t\tmap.delete(key1);\n\t}\n\treturn deleted;\n}\n\n/**\n * Converts a nested map to a flat list of triplets.\n */\nexport function nestedMapToFlatList<Key1, Key2, Value>(\n\tmap: ReadonlyNestedMap<Key1, Key2, Value>,\n): [Key1, Key2, Value][] {\n\tconst list: [Key1, Key2, Value][] = [];\n\tmap.forEach((innerMap, key1) => {\n\t\tinnerMap.forEach((val, key2) => {\n\t\t\tlist.push([key1, key2, val]);\n\t\t});\n\t});\n\treturn list;\n}\n\n/**\n * Builds a nested map from a flat list of triplets.\n */\nexport function nestedMapFromFlatList<Key1, Key2, Value>(\n\tlist: readonly (readonly [Key1, Key2, Value])[],\n): NestedMap<Key1, Key2, Value> {\n\tconst map = new Map<Key1, Map<Key2, Value>>();\n\tfor (const [key1, key2, val] of list) {\n\t\tgetOrAddInMap(map, key1, new Map<Key2, Value>()).set(key2, val);\n\t}\n\treturn map;\n}\n\nexport function forEachInNestedMap<Key1, Key2, Value>(\n\tmap: ReadonlyNestedMap<Key1, Key2, Value>,\n\tdelegate: (value: Value, key1: Key1, key2: Key2) => void,\n): void {\n\tmap.forEach((innerMap, keyFirst) => {\n\t\tinnerMap.forEach((val, keySecond) => {\n\t\t\tdelegate(val, keyFirst, keySecond);\n\t\t});\n\t});\n}\n\n/**\n * Maps the `input` map values using the provided `delegate`.\n *\n * @param input - The `NestedMap` whose contents are being mapped.\n * @param delegate - The delegate to use for mapping values,\n * @returns A new `NestedMap` with the same keys as `input`, but with the values produced by `delegate`.\n */\nexport function mapNestedMap<Key1, Key2, ValueIn, ValueOut = ValueIn>(\n\tinput: ReadonlyNestedMap<Key1, Key2, ValueIn>,\n\tdelegate: (value: ValueIn, key1: Key1, key2: Key2) => ValueOut,\n): NestedMap<Key1, Key2, ValueOut> {\n\tconst output = new Map<Key1, Map<Key2, ValueOut>>();\n\tinput.forEach((inputInnerMap, keyFirst) => {\n\t\tconst outputInnerMap = new Map<Key2, ValueOut>();\n\t\tinputInnerMap.forEach((val, keySecond) => {\n\t\t\tconst mappedValue = delegate(val, keyFirst, keySecond);\n\t\t\toutputInnerMap.set(keySecond, mappedValue);\n\t\t});\n\t\toutput.set(keyFirst, outputInnerMap);\n\t});\n\treturn output;\n}\n\n/**\n * Map with two keys; same semantics as NestedMap, but maintains a size count for the entire collection.\n * Note: undefined is not supported as a value, and will cause incorrect behavior.\n */\nexport class SizedNestedMap<Key1, Key2, Value> {\n\tprivate readonly nestedMap: NestedMap<Key1, Key2, Value> = new Map();\n\tprivate count = 0;\n\n\t/**\n\t * Returns the total number of elements in this nested map.\n\t */\n\tpublic get size(): number {\n\t\treturn this.count;\n\t}\n\n\t/**\n\t * If (key1, key2) already has a value in the map, it is returned, otherwise value is added under (key1, key2) and undefined is\n\t * returned.\n\t */\n\tpublic tryGet(key1: Key1, key2: Key2): Value | undefined {\n\t\treturn tryGetFromNestedMap(this.nestedMap, key1, key2);\n\t}\n\n\t/**\n\t * Does not change map.\n\t * If (key1, key2) is not in map, returns value.\n\t * If (key1, key2) is in map, return its entry.\n\t */\n\tpublic getOrDefault(key1: Key1, key2: Key2, value: Value): Value {\n\t\treturn getOrDefaultInNestedMap(this.nestedMap, key1, key2, value);\n\t}\n\n\t/**\n\t * If (key1, key2) already has a value in the map, it is returned, otherwise value is added under (key1, key2) and undefined is\n\t * returned.\n\t */\n\tpublic tryAdd(key1: Key1, key2: Key2, value: Value): Value | undefined {\n\t\tconst currentVal = tryAddToNestedMap(this.nestedMap, key1, key2, value);\n\t\tif (currentVal === undefined) {\n\t\t\tthis.count++;\n\t\t}\n\t\treturn currentVal;\n\t}\n\n\t/**\n\t * Sets the value at (key1, key2) in map to value.\n\t * If there already is a value for (key1, key2), it is replaced with the provided one.\n\t */\n\tpublic set(key1: Key1, key2: Key2, value: Value): void {\n\t\tif (this.tryAdd(key1, key2, value) !== undefined) {\n\t\t\tsetInNestedMap(this.nestedMap, key1, key2, value);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the value at (key1, key2) from the map.\n\t * Returns true iff found.\n\t */\n\tpublic delete(key1: Key1, key2: Key2): boolean {\n\t\tconst deleted = deleteFromNestedMap(this.nestedMap, key1, key2);\n\t\tif (deleted) {\n\t\t\tthis.count--;\n\t\t}\n\t\treturn deleted;\n\t}\n\n\t/**\n\t * Runs the supplied delegate for every (value, key1, key2).\n\t */\n\tpublic forEach(delegate: (value: Value, key1: Key1, key2: Key2) => void): void {\n\t\tforEachInNestedMap(this.nestedMap, delegate);\n\t}\n\n\t/**\n\t * Clears the map.\n\t */\n\tpublic clear(): void {\n\t\tthis.count = 0;\n\t\tthis.nestedMap.clear();\n\t}\n\n\tpublic values(): IterableIterator<Value> {\n\t\treturn (\n\t\t\tArray.from(this.nestedMap.values()).flatMap((innerMap) => innerMap.values())[0] ?? oob()\n\t\t);\n\t}\n\n\tpublic [Symbol.iterator](): IterableIterator<[Key1, Map<Key2, Value>]> {\n\t\treturn this.nestedMap[Symbol.iterator]();\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/tree",
3
- "version": "2.10.0-305357",
3
+ "version": "2.10.0-306579",
4
4
  "description": "Distributed tree",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -89,17 +89,17 @@
89
89
  "temp-directory": "nyc/.nyc_output"
90
90
  },
91
91
  "dependencies": {
92
- "@fluid-internal/client-utils": "2.10.0-305357",
93
- "@fluidframework/container-runtime": "2.10.0-305357",
94
- "@fluidframework/core-interfaces": "2.10.0-305357",
95
- "@fluidframework/core-utils": "2.10.0-305357",
96
- "@fluidframework/datastore-definitions": "2.10.0-305357",
97
- "@fluidframework/driver-definitions": "2.10.0-305357",
98
- "@fluidframework/id-compressor": "2.10.0-305357",
99
- "@fluidframework/runtime-definitions": "2.10.0-305357",
100
- "@fluidframework/runtime-utils": "2.10.0-305357",
101
- "@fluidframework/shared-object-base": "2.10.0-305357",
102
- "@fluidframework/telemetry-utils": "2.10.0-305357",
92
+ "@fluid-internal/client-utils": "2.10.0-306579",
93
+ "@fluidframework/container-runtime": "2.10.0-306579",
94
+ "@fluidframework/core-interfaces": "2.10.0-306579",
95
+ "@fluidframework/core-utils": "2.10.0-306579",
96
+ "@fluidframework/datastore-definitions": "2.10.0-306579",
97
+ "@fluidframework/driver-definitions": "2.10.0-306579",
98
+ "@fluidframework/id-compressor": "2.10.0-306579",
99
+ "@fluidframework/runtime-definitions": "2.10.0-306579",
100
+ "@fluidframework/runtime-utils": "2.10.0-306579",
101
+ "@fluidframework/shared-object-base": "2.10.0-306579",
102
+ "@fluidframework/telemetry-utils": "2.10.0-306579",
103
103
  "@sinclair/typebox": "^0.32.29",
104
104
  "@tylerbu/sorted-btree-es6": "^1.8.0",
105
105
  "@types/ungap__structured-clone": "^1.2.0",
@@ -109,19 +109,19 @@
109
109
  "devDependencies": {
110
110
  "@arethetypeswrong/cli": "^0.16.4",
111
111
  "@biomejs/biome": "~1.9.3",
112
- "@fluid-internal/mocha-test-setup": "2.10.0-305357",
113
- "@fluid-private/stochastic-test-utils": "2.10.0-305357",
114
- "@fluid-private/test-dds-utils": "2.10.0-305357",
115
- "@fluid-private/test-drivers": "2.10.0-305357",
112
+ "@fluid-internal/mocha-test-setup": "2.10.0-306579",
113
+ "@fluid-private/stochastic-test-utils": "2.10.0-306579",
114
+ "@fluid-private/test-dds-utils": "2.10.0-306579",
115
+ "@fluid-private/test-drivers": "2.10.0-306579",
116
116
  "@fluid-tools/benchmark": "^0.50.0",
117
117
  "@fluid-tools/build-cli": "^0.50.0",
118
118
  "@fluidframework/build-common": "^2.0.3",
119
119
  "@fluidframework/build-tools": "^0.50.0",
120
- "@fluidframework/container-definitions": "2.10.0-305357",
121
- "@fluidframework/container-loader": "2.10.0-305357",
120
+ "@fluidframework/container-definitions": "2.10.0-306579",
121
+ "@fluidframework/container-loader": "2.10.0-306579",
122
122
  "@fluidframework/eslint-config-fluid": "^5.4.0",
123
- "@fluidframework/test-runtime-utils": "2.10.0-305357",
124
- "@fluidframework/test-utils": "2.10.0-305357",
123
+ "@fluidframework/test-runtime-utils": "2.10.0-306579",
124
+ "@fluidframework/test-utils": "2.10.0-306579",
125
125
  "@fluidframework/tree-previous": "npm:@fluidframework/tree@2.5.0",
126
126
  "@microsoft/api-extractor": "7.47.8",
127
127
  "@types/diff": "^3.5.1",
@@ -58,7 +58,12 @@ export interface ForestEvents {
58
58
  *
59
59
  * When invalidating, all outstanding cursors must be freed or cleared.
60
60
  */
61
- export interface IForestSubscription extends Listenable<ForestEvents> {
61
+ export interface IForestSubscription {
62
+ /**
63
+ * Events for this forest.
64
+ */
65
+ readonly events: Listenable<ForestEvents>;
66
+
62
67
  /**
63
68
  * Set of anchors this forest is tracking.
64
69
  *
package/src/core/index.ts CHANGED
@@ -121,7 +121,7 @@ export {
121
121
  type TreeFieldStoredSchema,
122
122
  ValueSchema,
123
123
  TreeNodeStoredSchema,
124
- type TreeStoredSchemaSubscription as TreeStoredSchemaSubscription,
124
+ type TreeStoredSchemaSubscription,
125
125
  type MutableTreeStoredSchema,
126
126
  type FieldKindIdentifier,
127
127
  type FieldKindData,
@@ -37,9 +37,12 @@ export interface SchemaEvents {
37
37
  /**
38
38
  * A collection of stored schema that fires events in response to changes.
39
39
  */
40
- export interface TreeStoredSchemaSubscription
41
- extends Listenable<SchemaEvents>,
42
- TreeStoredSchema {}
40
+ export interface TreeStoredSchemaSubscription extends TreeStoredSchema {
41
+ /**
42
+ * Events for this schema subscription.
43
+ */
44
+ readonly events: Listenable<SchemaEvents>;
45
+ }
43
46
 
44
47
  /**
45
48
  * Mutable collection of stored schema.
@@ -59,7 +62,8 @@ export interface MutableTreeStoredSchema extends TreeStoredSchemaSubscription {
59
62
  export class TreeStoredSchemaRepository implements MutableTreeStoredSchema {
60
63
  protected nodeSchemaData: BTree<TreeNodeSchemaIdentifier, TreeNodeStoredSchema>;
61
64
  protected rootFieldSchemaData: TreeFieldStoredSchema;
62
- protected readonly events = createEmitter<SchemaEvents>();
65
+ protected readonly _events = createEmitter<SchemaEvents>();
66
+ public readonly events: Listenable<SchemaEvents> = this._events;
63
67
 
64
68
  /**
65
69
  * Copies in the provided schema. If `data` is an TreeStoredSchemaRepository, it will be cheap-cloned.
@@ -92,13 +96,6 @@ export class TreeStoredSchemaRepository implements MutableTreeStoredSchema {
92
96
  }
93
97
  }
94
98
 
95
- public on<K extends keyof SchemaEvents>(
96
- eventName: K,
97
- listener: SchemaEvents[K],
98
- ): () => void {
99
- return this.events.on(eventName, listener);
100
- }
101
-
102
99
  public get nodeSchema(): ReadonlyMap<TreeNodeSchemaIdentifier, TreeNodeStoredSchema> {
103
100
  // Btree implements iterator, but not in a type-safe way
104
101
  return this.nodeSchemaData as unknown as ReadonlyMap<
@@ -112,12 +109,12 @@ export class TreeStoredSchemaRepository implements MutableTreeStoredSchema {
112
109
  }
113
110
 
114
111
  public apply(newSchema: TreeStoredSchema): void {
115
- this.events.emit("beforeSchemaChange", newSchema);
112
+ this._events.emit("beforeSchemaChange", newSchema);
116
113
  const clone = new TreeStoredSchemaRepository(newSchema);
117
114
  // In the future, we could use btree's delta functionality to do a more efficient update
118
115
  this.rootFieldSchemaData = clone.rootFieldSchemaData;
119
116
  this.nodeSchemaData = clone.nodeSchemaData;
120
- this.events.emit("afterSchemaChange", newSchema);
117
+ this._events.emit("afterSchemaChange", newSchema);
121
118
  }
122
119
 
123
120
  public clone(): TreeStoredSchemaRepository {
@@ -206,7 +206,12 @@ export interface AnchorSetRootEvents {
206
206
  /**
207
207
  * Node in a tree of anchors.
208
208
  */
209
- export interface AnchorNode extends UpPath<AnchorNode>, Listenable<AnchorEvents> {
209
+ export interface AnchorNode extends UpPath<AnchorNode> {
210
+ /**
211
+ * Events for this anchor node.
212
+ */
213
+ readonly events: Listenable<AnchorEvents>;
214
+
210
215
  /**
211
216
  * Allows access to data stored on the Anchor in "slots".
212
217
  * Use {@link anchorSlot} to create slots.
@@ -277,8 +282,10 @@ export function anchorSlot<TContent>(): AnchorSlot<TContent> {
277
282
  *
278
283
  * @sealed
279
284
  */
280
- export class AnchorSet implements Listenable<AnchorSetRootEvents>, AnchorLocator {
281
- private readonly events = createEmitter<AnchorSetRootEvents>();
285
+ export class AnchorSet implements AnchorLocator {
286
+ readonly #events = createEmitter<AnchorSetRootEvents>();
287
+ public readonly events: Listenable<AnchorSetRootEvents> = this.#events;
288
+
282
289
  /**
283
290
  * Incrementing counter to give each anchor in this set a unique index for its identifier.
284
291
  * "0" is reserved for the `NeverAnchor`.
@@ -312,7 +319,7 @@ export class AnchorSet implements Listenable<AnchorSetRootEvents>, AnchorLocator
312
319
  private activeVisitor?: DeltaVisitor;
313
320
 
314
321
  public constructor() {
315
- this.on("treeChanging", () => {
322
+ this.events.on("treeChanging", () => {
316
323
  this.generationNumber += 1;
317
324
  });
318
325
  }
@@ -344,13 +351,6 @@ export class AnchorSet implements Listenable<AnchorSetRootEvents>, AnchorLocator
344
351
  }
345
352
  }
346
353
 
347
- public on<K extends keyof AnchorSetRootEvents>(
348
- eventName: K,
349
- listener: AnchorSetRootEvents[K],
350
- ): () => void {
351
- return this.events.on(eventName, listener);
352
- }
353
-
354
354
  /**
355
355
  * Check if there are currently no anchors tracked.
356
356
  * Mainly for testing anchor cleanup.
@@ -792,7 +792,7 @@ export class AnchorSet implements Listenable<AnchorSetRootEvents>, AnchorLocator
792
792
  notifyChildrenChanging(): void {
793
793
  this.maybeWithNode(
794
794
  (p) => p.events.emit("childrenChanging", p),
795
- () => this.anchorSet.events.emit("childrenChanging", this.anchorSet),
795
+ () => this.anchorSet.#events.emit("childrenChanging", this.anchorSet),
796
796
  );
797
797
  },
798
798
  notifyChildrenChanged(): void {
@@ -1098,7 +1098,7 @@ export class AnchorSet implements Listenable<AnchorSetRootEvents>, AnchorLocator
1098
1098
  this.parentField = undefined;
1099
1099
  },
1100
1100
  };
1101
- this.events.emit("treeChanging", this);
1101
+ this.#events.emit("treeChanging", this);
1102
1102
  this.activeVisitor = visitor;
1103
1103
  return visitor;
1104
1104
  }
@@ -1209,13 +1209,6 @@ class PathNode extends ReferenceCountedBase implements UpPath<PathNode>, AnchorN
1209
1209
  super(1);
1210
1210
  }
1211
1211
 
1212
- public on<K extends keyof AnchorEvents>(
1213
- eventName: K,
1214
- listener: AnchorEvents[K],
1215
- ): () => void {
1216
- return this.events.on(eventName, listener);
1217
- }
1218
-
1219
1212
  public child(key: FieldKey, index: number): UpPath<AnchorNode> {
1220
1213
  // Fast path: if child exists, return it.
1221
1214
  return (
@@ -3,7 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { setInNestedMap } from "../util/index.js";
6
+ import { UsageError } from "@fluidframework/telemetry-utils/internal";
7
+ import { getOrCreate } from "../util/index.js";
7
8
  import type { Listenable, Listeners, Off } from "./listeners.js";
8
9
 
9
10
  /**
@@ -63,7 +64,7 @@ export interface HasListeners<TListeners extends Listeners<TListeners>> {
63
64
  /**
64
65
  * Provides an API for subscribing to and listening to events.
65
66
  *
66
- * @remarks Classes wishing to emit events may either extend this class or compose over it.
67
+ * @remarks Classes wishing to emit events may either extend this class, compose over it, or expose it as a property of type {@link Listenable}.
67
68
  *
68
69
  * @example Extending this class
69
70
  *
@@ -97,13 +98,27 @@ export interface HasListeners<TListeners extends Listeners<TListeners>> {
97
98
  * }
98
99
  * }
99
100
  * ```
101
+ *
102
+ * @example Exposing this class as a property
103
+ *
104
+ * ```typescript
105
+ * class MyExposingClass {
106
+ * private readonly _events = createEmitter<MyEvents>();
107
+ * public readonly events: Listenable<MyEvents> = this._events;
108
+ *
109
+ * private load() {
110
+ * this._events.emit("loaded");
111
+ * const results: number[] = this._events.emitAndCollect("computed");
112
+ * }
113
+ * }
114
+ * ```
100
115
  */
101
116
  export class EventEmitter<TListeners extends Listeners<TListeners>>
102
117
  implements Listenable<TListeners>, HasListeners<TListeners>
103
118
  {
104
119
  protected readonly listeners = new Map<
105
120
  keyof TListeners,
106
- Map<Off, (...args: any[]) => TListeners[keyof TListeners]>
121
+ Set<(...args: any[]) => TListeners[keyof TListeners]>
107
122
  >();
108
123
 
109
124
  // Because this is protected and not public, calling this externally (not from a subclass) makes sending events to the constructed instance impossible.
@@ -118,11 +133,10 @@ export class EventEmitter<TListeners extends Listeners<TListeners>>
118
133
  if (listeners !== undefined) {
119
134
  // Current tsc (5.4.5) cannot spread `args` into `listener()`.
120
135
  const argArray: unknown[] = args;
121
-
122
136
  // This explicitly copies listeners so that new listeners added during this call to emit will not receive this event.
123
- for (const [off, listener] of [...listeners]) {
137
+ for (const listener of [...listeners]) {
124
138
  // If listener has been unsubscribed while invoking other listeners, skip it.
125
- if (listeners.has(off)) {
139
+ if (listeners.has(listener)) {
126
140
  listener(...argArray);
127
141
  }
128
142
  }
@@ -145,29 +159,32 @@ export class EventEmitter<TListeners extends Listeners<TListeners>>
145
159
  return [];
146
160
  }
147
161
 
148
- /**
149
- * Register an event listener.
150
- * @param eventName - the name of the event
151
- * @param listener - the handler to run when the event is fired by the emitter
152
- * @returns a function which will deregister the listener when run.
153
- * This function will error if called more than once.
154
- */
155
162
  public on<K extends keyof Listeners<TListeners>>(
156
163
  eventName: K,
157
164
  listener: TListeners[K],
158
165
  ): Off {
159
- const off: Off = () => {
160
- const currentListeners = this.listeners.get(eventName);
161
- if (currentListeners?.delete(off) === true) {
162
- if (currentListeners.size === 0) {
163
- this.listeners.delete(eventName);
164
- this.noListeners?.(eventName);
165
- }
166
- }
167
- };
166
+ const listeners = getOrCreate(this.listeners, eventName, () => new Set());
167
+ if (listeners.has(listener)) {
168
+ const eventDescription =
169
+ typeof eventName === "symbol" ? eventName.description : String(eventName.toString());
168
170
 
169
- setInNestedMap(this.listeners, eventName, off, listener);
170
- return off;
171
+ throw new UsageError(
172
+ `Attempted to register the same listener object twice for event ${eventDescription}`,
173
+ );
174
+ }
175
+ listeners.add(listener);
176
+ return () => this.off(eventName, listener);
177
+ }
178
+
179
+ public off<K extends keyof Listeners<TListeners>>(
180
+ eventName: K,
181
+ listener: TListeners[K],
182
+ ): void {
183
+ const listeners = this.listeners.get(eventName);
184
+ if (listeners?.delete(listener) === true && listeners.size === 0) {
185
+ this.listeners.delete(eventName);
186
+ this.noListeners?.(eventName);
187
+ }
171
188
  }
172
189
 
173
190
  public hasListeners(eventName?: keyof TListeners): boolean {
@@ -225,6 +242,10 @@ class ComposableEventEmitter<TListeners extends Listeners<TListeners>>
225
242
  * public on<K extends keyof MyEvents>(eventName: K, listener: MyEvents[K]): Off {
226
243
  * return this.events.on(eventName, listener);
227
244
  * }
245
+ *
246
+ * public off<K extends keyof MyEvents>(eventName: K, listener: MyEvents[K]): void {
247
+ * return this.events.off(eventName, listener);
248
+ * }
228
249
  * }
229
250
  * ```
230
251
  */
@@ -50,13 +50,25 @@ export interface Listenable<TListeners extends object> {
50
50
  /**
51
51
  * Register an event listener.
52
52
  * @param eventName - The name of the event.
53
- * @param listener - the handler to run when the event is fired by the emitter
54
- * @returns a {@link Off | function} which will deregister the listener when called.
55
- * This deregistration function is idempotent and therefore may be safely called more than once with no effect.
56
- * @remarks Do not register the exact same `listener` object for the same event more than once.
57
- * Doing so will result in undefined behavior, and is not guaranteed to behave the same in future versions of this library.
53
+ * @param listener - The listener function to run when the event is fired.
54
+ * @returns A {@link Off | function} which will deregister the listener when called.
55
+ * Calling the deregistration function more than once will have no effect.
56
+ *
57
+ * Listeners may also be deregistered by passing the listener to {@link Listenable.off | off()}.
58
+ * @remarks Registering the exact same `listener` object for the same event more than once will throw an error.
59
+ * If registering the same listener for the same event multiple times is desired, consider using a wrapper function for the second subscription.
58
60
  */
59
61
  on<K extends keyof Listeners<TListeners>>(eventName: K, listener: TListeners[K]): Off;
62
+
63
+ /**
64
+ * Deregister an event listener.
65
+ * @param eventName - The name of the event.
66
+ * @param listener - The listener function to remove from the current set of event listeners.
67
+ * @remarks If `listener` is not currently registered, this method will have no effect.
68
+ *
69
+ * Listeners may also be deregistered by calling the {@link Off | deregistration function} returned when they are {@link Listenable.on | registered}.
70
+ */
71
+ off<K extends keyof Listeners<TListeners>>(eventName: K, listener: TListeners[K]): void;
60
72
  }
61
73
 
62
74
  /**
@@ -134,7 +134,7 @@ export class Chunker implements IChunker {
134
134
  if (cached !== undefined) {
135
135
  return cached;
136
136
  }
137
- this.unregisterSchemaCallback = this.schema.on("afterSchemaChange", () =>
137
+ this.unregisterSchemaCallback = this.schema.events.on("afterSchemaChange", () =>
138
138
  this.schemaChanged(),
139
139
  );
140
140
  return this.tryShapeFromSchema(this.schema, this.policy, schema, this.typeShapes);
@@ -28,7 +28,7 @@ import {
28
28
  mapCursorField,
29
29
  rootFieldKey,
30
30
  } from "../../core/index.js";
31
- import { createEmitter } from "../../events/index.js";
31
+ import { createEmitter, type Listenable } from "../../events/index.js";
32
32
  import { assertValidRange, brand, fail, getOrAddEmptyToMap } from "../../util/index.js";
33
33
 
34
34
  import { BasicChunk, BasicChunkCursor, type SiblingsOrKey } from "./basicChunk.js";
@@ -53,7 +53,8 @@ interface StackNode {
53
53
  export class ChunkedForest implements IEditableForest {
54
54
  private activeVisitor?: DeltaVisitor;
55
55
 
56
- private readonly events = createEmitter<ForestEvents>();
56
+ readonly #events = createEmitter<ForestEvents>();
57
+ public readonly events: Listenable<ForestEvents> = this.#events;
57
58
 
58
59
  /**
59
60
  * @param roots - dummy node above the root under which detached fields are stored. All content of the forest is reachable from this.
@@ -73,13 +74,6 @@ export class ChunkedForest implements IEditableForest {
73
74
  return this.roots.fields.size === 0;
74
75
  }
75
76
 
76
- public on<K extends keyof ForestEvents>(
77
- eventName: K,
78
- listener: ForestEvents[K],
79
- ): () => void {
80
- return this.events.on(eventName, listener);
81
- }
82
-
83
77
  public clone(schema: TreeStoredSchemaSubscription, anchors: AnchorSet): ChunkedForest {
84
78
  this.roots.referenceAdded();
85
79
  return new ChunkedForest(this.roots, schema, this.chunker.clone(schema), anchors);
@@ -119,11 +113,11 @@ export class ChunkedForest implements IEditableForest {
119
113
  this.forest.activeVisitor = undefined;
120
114
  },
121
115
  destroy(detachedField: FieldKey, count: number): void {
122
- this.forest.events.emit("beforeChange");
116
+ this.forest.#events.emit("beforeChange");
123
117
  this.forest.roots.fields.delete(detachedField);
124
118
  },
125
119
  create(content: ProtoNodes, destination: FieldKey): void {
126
- this.forest.events.emit("beforeChange");
120
+ this.forest.#events.emit("beforeChange");
127
121
  const chunks: TreeChunk[] = content.map((c) =>
128
122
  chunkTree(c, {
129
123
  policy: this.forest.chunker,
@@ -131,7 +125,7 @@ export class ChunkedForest implements IEditableForest {
131
125
  }),
132
126
  );
133
127
  this.forest.roots.fields.set(destination, chunks);
134
- this.forest.events.emit("afterRootFieldCreated", destination);
128
+ this.forest.#events.emit("afterRootFieldCreated", destination);
135
129
  },
136
130
  attach(source: FieldKey, count: number, destination: PlaceIndex): void {
137
131
  this.attachEdit(source, count, destination);
@@ -146,7 +140,7 @@ export class ChunkedForest implements IEditableForest {
146
140
  * @param destination - The index in the current field at which to attach the content.
147
141
  */
148
142
  attachEdit(source: FieldKey, count: number, destination: PlaceIndex): void {
149
- this.forest.events.emit("beforeChange");
143
+ this.forest.#events.emit("beforeChange");
150
144
  const sourceField = this.forest.roots.fields.get(source) ?? [];
151
145
  this.forest.roots.fields.delete(source);
152
146
  if (sourceField.length === 0) {
@@ -166,7 +160,7 @@ export class ChunkedForest implements IEditableForest {
166
160
  * If not specified, the detached range is destroyed.
167
161
  */
168
162
  detachEdit(source: Range, destination: FieldKey | undefined): void {
169
- this.forest.events.emit("beforeChange");
163
+ this.forest.#events.emit("beforeChange");
170
164
  const parent = this.getParent();
171
165
  const sourceField = parent.mutableChunk.fields.get(parent.key) ?? [];
172
166
 
@@ -49,7 +49,8 @@ export interface FlexTreeContext {
49
49
  * A common context of a "forest" of FlexTrees.
50
50
  * It handles group operations like transforming cursors into anchors for edits.
51
51
  */
52
- export interface FlexTreeHydratedContext extends FlexTreeContext, Listenable<ForestEvents> {
52
+ export interface FlexTreeHydratedContext extends FlexTreeContext {
53
+ readonly events: Listenable<ForestEvents>;
53
54
  /**
54
55
  * Gets the root field of the tree.
55
56
  */
@@ -92,7 +93,7 @@ export class Context implements FlexTreeHydratedContext, IDisposable {
92
93
  public readonly nodeKeyManager: NodeKeyManager,
93
94
  ) {
94
95
  this.eventUnregister = [
95
- this.checkout.forest.on("beforeChange", () => {
96
+ this.checkout.forest.events.on("beforeChange", () => {
96
97
  this.prepareForEdit();
97
98
  }),
98
99
  ];
@@ -160,11 +161,8 @@ export class Context implements FlexTreeHydratedContext, IDisposable {
160
161
  return field;
161
162
  }
162
163
 
163
- public on<K extends keyof ForestEvents>(
164
- eventName: K,
165
- listener: ForestEvents[K],
166
- ): () => void {
167
- return this.checkout.forest.on(eventName, listener);
164
+ public get events(): Listenable<ForestEvents> {
165
+ return this.checkout.forest.events;
168
166
  }
169
167
  }
170
168
 
@@ -151,7 +151,7 @@ export abstract class LazyField extends LazyEntity<FieldAnchor> implements FlexT
151
151
  const anchorNode =
152
152
  context.checkout.forest.anchors.locate(fieldAnchor.parent) ??
153
153
  fail("parent anchor node should always exist since field is under a node");
154
- this.offAfterDestroy = anchorNode.on("afterDestroy", () => {
154
+ this.offAfterDestroy = anchorNode.events.on("afterDestroy", () => {
155
155
  this[disposeSymbol]();
156
156
  });
157
157
  }
@@ -89,7 +89,7 @@ export class LazyTreeNode extends LazyEntity<Anchor> implements FlexTreeNode {
89
89
  this.storedSchema = context.schema.nodeSchema.get(this.schema) ?? fail("missing schema");
90
90
  assert(cursor.mode === CursorLocationType.Nodes, 0x783 /* must be in nodes mode */);
91
91
  anchorNode.slots.set(flexTreeSlot, this);
92
- this.#removeDeleteCallback = anchorNode.on("afterDestroy", cleanupTree);
92
+ this.#removeDeleteCallback = anchorNode.events.on("afterDestroy", cleanupTree);
93
93
  }
94
94
 
95
95
  public borrowCursor(): ITreeCursorSynchronous {
@@ -99,7 +99,7 @@ export function getSchemaAndPolicy(nodeOrField: FlexTreeEntity): SchemaAndPolicy
99
99
  */
100
100
  export function indexForAt(index: number, length: number): number | undefined {
101
101
  let finalIndex = Math.trunc(+index);
102
- if (isNaN(finalIndex)) {
102
+ if (Number.isNaN(finalIndex)) {
103
103
  finalIndex = 0;
104
104
  }
105
105
  if (finalIndex < -length || finalIndex >= length) {
@@ -54,6 +54,10 @@ export function allowsTreeSuperset(
54
54
  return false;
55
55
  }
56
56
 
57
+ if (superset instanceof LeafNodeStoredSchema) {
58
+ return false;
59
+ }
60
+
57
61
  assert(
58
62
  original instanceof MapNodeStoredSchema || original instanceof ObjectNodeStoredSchema,
59
63
  0x893 /* unsupported node kind */,