@fluidframework/tree 2.3.0-288113 → 2.3.1

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 (869) hide show
  1. package/.dependency-cruiser-known-violations.json +28 -40
  2. package/.vscode/Tree.code-workspace +0 -2
  3. package/CHANGELOG.md +92 -0
  4. package/README.md +6 -0
  5. package/alpha.d.ts +11 -0
  6. package/api-extractor/api-extractor-lint-alpha.cjs.json +5 -0
  7. package/api-extractor/api-extractor-lint-alpha.esm.json +5 -0
  8. package/api-extractor/api-extractor-lint-legacy.cjs.json +5 -0
  9. package/api-extractor/api-extractor-lint-legacy.esm.json +5 -0
  10. package/api-extractor/api-extractor.current.json +8 -0
  11. package/api-extractor/api-extractor.legacy.json +4 -0
  12. package/api-extractor.json +1 -1
  13. package/api-report/tree.alpha.api.md +21 -42
  14. package/api-report/tree.beta.api.md +21 -11
  15. package/api-report/tree.legacy.alpha.api.md +562 -0
  16. package/api-report/tree.legacy.public.api.md +559 -0
  17. package/api-report/tree.public.api.md +8 -13
  18. package/dist/alpha.d.ts +102 -0
  19. package/dist/beta.d.ts +6 -2
  20. package/dist/core/index.d.ts +1 -1
  21. package/dist/core/index.d.ts.map +1 -1
  22. package/dist/core/index.js +2 -2
  23. package/dist/core/index.js.map +1 -1
  24. package/dist/core/{revertible/revertible.d.ts → revertible.d.ts} +12 -0
  25. package/dist/core/revertible.d.ts.map +1 -0
  26. package/dist/core/revertible.js.map +1 -0
  27. package/dist/core/schema-stored/format.d.ts +3 -3
  28. package/dist/core/schema-stored/format.js +1 -1
  29. package/dist/core/schema-stored/format.js.map +1 -1
  30. package/dist/core/schema-stored/schema.d.ts +2 -7
  31. package/dist/core/schema-stored/schema.d.ts.map +1 -1
  32. package/dist/core/schema-stored/schema.js +4 -6
  33. package/dist/core/schema-stored/schema.js.map +1 -1
  34. package/dist/core/schema-stored/storedSchemaRepository.d.ts +1 -1
  35. package/dist/core/schema-stored/storedSchemaRepository.d.ts.map +1 -1
  36. package/dist/core/tree/anchorSet.d.ts.map +1 -1
  37. package/dist/core/tree/anchorSet.js +6 -2
  38. package/dist/core/tree/anchorSet.js.map +1 -1
  39. package/dist/core/tree/detachedFieldIndex.d.ts +0 -1
  40. package/dist/core/tree/detachedFieldIndex.d.ts.map +1 -1
  41. package/dist/core/tree/detachedFieldIndex.js +1 -0
  42. package/dist/core/tree/detachedFieldIndex.js.map +1 -1
  43. package/dist/core/tree/visitDelta.d.ts +7 -2
  44. package/dist/core/tree/visitDelta.d.ts.map +1 -1
  45. package/dist/core/tree/visitDelta.js.map +1 -1
  46. package/dist/events/emitter.d.ts +127 -0
  47. package/dist/events/emitter.d.ts.map +1 -0
  48. package/dist/events/{events.js → emitter.js} +48 -30
  49. package/dist/events/emitter.js.map +1 -0
  50. package/dist/events/index.d.ts +2 -1
  51. package/dist/events/index.d.ts.map +1 -1
  52. package/dist/events/index.js +4 -5
  53. package/dist/events/index.js.map +1 -1
  54. package/dist/events/interop.d.ts +36 -0
  55. package/dist/events/interop.d.ts.map +1 -0
  56. package/dist/{core/revertible/index.d.ts → events/interop.js} +3 -2
  57. package/dist/events/interop.js.map +1 -0
  58. package/dist/events/listeners.d.ts +65 -0
  59. package/dist/events/listeners.d.ts.map +1 -0
  60. package/{lib/core/revertible/index.d.ts → dist/events/listeners.js} +3 -2
  61. package/dist/events/listeners.js.map +1 -0
  62. package/dist/feature-libraries/chunked-forest/chunkTree.d.ts +25 -7
  63. package/dist/feature-libraries/chunked-forest/chunkTree.d.ts.map +1 -1
  64. package/dist/feature-libraries/chunked-forest/chunkTree.js +36 -15
  65. package/dist/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  66. package/dist/feature-libraries/chunked-forest/chunkedForest.d.ts +4 -2
  67. package/dist/feature-libraries/chunked-forest/chunkedForest.d.ts.map +1 -1
  68. package/dist/feature-libraries/chunked-forest/chunkedForest.js +12 -5
  69. package/dist/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  70. package/dist/feature-libraries/chunked-forest/uniformChunk.d.ts +15 -2
  71. package/dist/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  72. package/dist/feature-libraries/chunked-forest/uniformChunk.js +28 -2
  73. package/dist/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  74. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts +3 -1
  75. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  76. package/dist/feature-libraries/default-schema/defaultEditBuilder.js +5 -4
  77. package/dist/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  78. package/dist/feature-libraries/flex-map-tree/index.d.ts +1 -1
  79. package/dist/feature-libraries/flex-map-tree/index.d.ts.map +1 -1
  80. package/dist/feature-libraries/flex-map-tree/index.js +2 -1
  81. package/dist/feature-libraries/flex-map-tree/index.js.map +1 -1
  82. package/dist/feature-libraries/flex-map-tree/mapTreeNode.d.ts +35 -33
  83. package/dist/feature-libraries/flex-map-tree/mapTreeNode.d.ts.map +1 -1
  84. package/dist/feature-libraries/flex-map-tree/mapTreeNode.js +82 -103
  85. package/dist/feature-libraries/flex-map-tree/mapTreeNode.js.map +1 -1
  86. package/dist/feature-libraries/flex-tree/context.d.ts +30 -14
  87. package/dist/feature-libraries/flex-tree/context.d.ts.map +1 -1
  88. package/dist/feature-libraries/flex-tree/context.js +10 -7
  89. package/dist/feature-libraries/flex-tree/context.js.map +1 -1
  90. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts +57 -190
  91. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  92. package/dist/feature-libraries/flex-tree/flexTreeTypes.js +15 -3
  93. package/dist/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  94. package/dist/feature-libraries/flex-tree/index.d.ts +2 -3
  95. package/dist/feature-libraries/flex-tree/index.d.ts.map +1 -1
  96. package/dist/feature-libraries/flex-tree/index.js.map +1 -1
  97. package/dist/feature-libraries/flex-tree/lazyEntity.d.ts +3 -3
  98. package/dist/feature-libraries/flex-tree/lazyEntity.d.ts.map +1 -1
  99. package/dist/feature-libraries/flex-tree/lazyEntity.js +2 -10
  100. package/dist/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
  101. package/dist/feature-libraries/flex-tree/lazyField.d.ts +26 -28
  102. package/dist/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  103. package/dist/feature-libraries/flex-tree/lazyField.js +11 -14
  104. package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
  105. package/dist/feature-libraries/flex-tree/lazyNode.d.ts +5 -26
  106. package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  107. package/dist/feature-libraries/flex-tree/lazyNode.js +23 -74
  108. package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  109. package/dist/feature-libraries/flex-tree/unboxed.d.ts +4 -16
  110. package/dist/feature-libraries/flex-tree/unboxed.d.ts.map +1 -1
  111. package/dist/feature-libraries/flex-tree/unboxed.js +7 -41
  112. package/dist/feature-libraries/flex-tree/unboxed.js.map +1 -1
  113. package/dist/feature-libraries/flex-tree/utilities.d.ts +2 -2
  114. package/dist/feature-libraries/flex-tree/utilities.d.ts.map +1 -1
  115. package/dist/feature-libraries/flex-tree/utilities.js +3 -6
  116. package/dist/feature-libraries/flex-tree/utilities.js.map +1 -1
  117. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  118. package/dist/feature-libraries/forest-summary/forestSummarizer.js +4 -1
  119. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  120. package/dist/feature-libraries/index.d.ts +3 -5
  121. package/dist/feature-libraries/index.d.ts.map +1 -1
  122. package/dist/feature-libraries/index.js +5 -11
  123. package/dist/feature-libraries/index.js.map +1 -1
  124. package/dist/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
  125. package/dist/feature-libraries/modular-schema/comparison.js +3 -6
  126. package/dist/feature-libraries/modular-schema/comparison.js.map +1 -1
  127. package/dist/feature-libraries/modular-schema/discrepancies.d.ts.map +1 -1
  128. package/dist/feature-libraries/modular-schema/discrepancies.js +3 -13
  129. package/dist/feature-libraries/modular-schema/discrepancies.js.map +1 -1
  130. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +4 -1
  131. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  132. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts +2 -1
  133. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  134. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +12 -5
  135. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  136. package/dist/feature-libraries/schema-edits/schemaChangeFormat.d.ts +6 -6
  137. package/dist/feature-libraries/schema-index/format.d.ts +3 -3
  138. package/dist/feature-libraries/storedToViewSchema.d.ts.map +1 -1
  139. package/dist/feature-libraries/storedToViewSchema.js +2 -4
  140. package/dist/feature-libraries/storedToViewSchema.js.map +1 -1
  141. package/dist/feature-libraries/typed-schema/flexList.d.ts +3 -3
  142. package/dist/feature-libraries/typed-schema/flexList.js.map +1 -1
  143. package/dist/feature-libraries/typed-schema/index.d.ts +2 -2
  144. package/dist/feature-libraries/typed-schema/index.d.ts.map +1 -1
  145. package/dist/feature-libraries/typed-schema/index.js +2 -2
  146. package/dist/feature-libraries/typed-schema/index.js.map +1 -1
  147. package/dist/feature-libraries/typed-schema/schemaCollection.d.ts.map +1 -1
  148. package/dist/feature-libraries/typed-schema/schemaCollection.js +8 -10
  149. package/dist/feature-libraries/typed-schema/schemaCollection.js.map +1 -1
  150. package/dist/feature-libraries/typed-schema/typedTreeSchema.d.ts +17 -48
  151. package/dist/feature-libraries/typed-schema/typedTreeSchema.d.ts.map +1 -1
  152. package/dist/feature-libraries/typed-schema/typedTreeSchema.js +5 -37
  153. package/dist/feature-libraries/typed-schema/typedTreeSchema.js.map +1 -1
  154. package/dist/feature-libraries/typed-schema/view.d.ts +4 -6
  155. package/dist/feature-libraries/typed-schema/view.d.ts.map +1 -1
  156. package/dist/feature-libraries/typed-schema/view.js +5 -4
  157. package/dist/feature-libraries/typed-schema/view.js.map +1 -1
  158. package/dist/index.d.ts +4 -4
  159. package/dist/index.d.ts.map +1 -1
  160. package/dist/index.js +33 -36
  161. package/dist/index.js.map +1 -1
  162. package/dist/legacy.d.ts +83 -0
  163. package/dist/packageVersion.d.ts +1 -1
  164. package/dist/packageVersion.d.ts.map +1 -1
  165. package/dist/packageVersion.js +1 -1
  166. package/dist/packageVersion.js.map +1 -1
  167. package/dist/public.d.ts +0 -1
  168. package/dist/shared-tree/checkoutFlexTreeView.d.ts +53 -0
  169. package/dist/shared-tree/checkoutFlexTreeView.d.ts.map +1 -0
  170. package/dist/shared-tree/{treeView.js → checkoutFlexTreeView.js} +28 -6
  171. package/dist/shared-tree/checkoutFlexTreeView.js.map +1 -0
  172. package/dist/shared-tree/index.d.ts +3 -3
  173. package/dist/shared-tree/index.d.ts.map +1 -1
  174. package/dist/shared-tree/index.js +2 -2
  175. package/dist/shared-tree/index.js.map +1 -1
  176. package/dist/shared-tree/schematizeTree.d.ts +15 -4
  177. package/dist/shared-tree/schematizeTree.d.ts.map +1 -1
  178. package/dist/shared-tree/schematizeTree.js +7 -8
  179. package/dist/shared-tree/schematizeTree.js.map +1 -1
  180. package/dist/shared-tree/schematizingTreeView.d.ts +9 -4
  181. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  182. package/dist/shared-tree/schematizingTreeView.js +25 -12
  183. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  184. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  185. package/dist/shared-tree/sharedTree.js +2 -2
  186. package/dist/shared-tree/sharedTree.js.map +1 -1
  187. package/dist/shared-tree/sharedTreeChangeEnricher.d.ts +3 -1
  188. package/dist/shared-tree/sharedTreeChangeEnricher.d.ts.map +1 -1
  189. package/dist/shared-tree/sharedTreeChangeEnricher.js +6 -2
  190. package/dist/shared-tree/sharedTreeChangeEnricher.js.map +1 -1
  191. package/dist/shared-tree/sharedTreeChangeFamily.d.ts +3 -1
  192. package/dist/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  193. package/dist/shared-tree/sharedTreeChangeFamily.js +3 -2
  194. package/dist/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  195. package/dist/shared-tree/sharedTreeEditBuilder.d.ts +2 -1
  196. package/dist/shared-tree/sharedTreeEditBuilder.d.ts.map +1 -1
  197. package/dist/shared-tree/sharedTreeEditBuilder.js +2 -2
  198. package/dist/shared-tree/sharedTreeEditBuilder.js.map +1 -1
  199. package/dist/shared-tree/treeApi.d.ts +1 -3
  200. package/dist/shared-tree/treeApi.d.ts.map +1 -1
  201. package/dist/shared-tree/treeApi.js +6 -4
  202. package/dist/shared-tree/treeApi.js.map +1 -1
  203. package/dist/shared-tree/treeCheckout.d.ts +2 -13
  204. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  205. package/dist/shared-tree/treeCheckout.js +17 -1
  206. package/dist/shared-tree/treeCheckout.js.map +1 -1
  207. package/dist/shared-tree-core/branch.js +1 -1
  208. package/dist/shared-tree-core/branch.js.map +1 -1
  209. package/dist/simple-tree/api/create.d.ts.map +1 -1
  210. package/dist/simple-tree/api/create.js +1 -1
  211. package/dist/simple-tree/api/create.js.map +1 -1
  212. package/{lib/simple-tree → dist/simple-tree/api}/getJsonSchema.d.ts +1 -1
  213. package/dist/simple-tree/api/getJsonSchema.d.ts.map +1 -0
  214. package/dist/simple-tree/{getJsonSchema.js → api/getJsonSchema.js} +1 -1
  215. package/dist/simple-tree/api/getJsonSchema.js.map +1 -0
  216. package/{lib/simple-tree → dist/simple-tree/api}/getSimpleSchema.d.ts +1 -1
  217. package/dist/simple-tree/api/getSimpleSchema.d.ts.map +1 -0
  218. package/dist/simple-tree/{getSimpleSchema.js → api/getSimpleSchema.js} +1 -1
  219. package/dist/simple-tree/api/getSimpleSchema.js.map +1 -0
  220. package/dist/simple-tree/api/index.d.ts +5 -0
  221. package/dist/simple-tree/api/index.d.ts.map +1 -1
  222. package/dist/simple-tree/api/index.js +7 -1
  223. package/dist/simple-tree/api/index.js.map +1 -1
  224. package/{lib/simple-tree → dist/simple-tree/api}/jsonSchema.d.ts +1 -1
  225. package/dist/simple-tree/api/jsonSchema.d.ts.map +1 -0
  226. package/dist/simple-tree/api/jsonSchema.js.map +1 -0
  227. package/dist/simple-tree/api/schemaFactory.d.ts +45 -14
  228. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  229. package/dist/simple-tree/api/schemaFactory.js +43 -12
  230. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  231. package/dist/simple-tree/{simpleSchema.d.ts → api/simpleSchema.d.ts} +4 -4
  232. package/dist/simple-tree/api/simpleSchema.d.ts.map +1 -0
  233. package/dist/simple-tree/api/simpleSchema.js.map +1 -0
  234. package/dist/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -0
  235. package/dist/simple-tree/{simpleSchemaToJsonSchema.js → api/simpleSchemaToJsonSchema.js} +4 -4
  236. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -0
  237. package/dist/simple-tree/api/tree.d.ts +1 -21
  238. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  239. package/dist/simple-tree/api/tree.js +3 -38
  240. package/dist/simple-tree/api/tree.js.map +1 -1
  241. package/dist/simple-tree/api/treeApiBeta.d.ts +79 -0
  242. package/dist/simple-tree/api/treeApiBeta.d.ts.map +1 -0
  243. package/dist/simple-tree/api/treeApiBeta.js +26 -0
  244. package/dist/simple-tree/api/treeApiBeta.js.map +1 -0
  245. package/dist/simple-tree/api/treeNodeApi.d.ts +1 -1
  246. package/dist/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  247. package/dist/simple-tree/api/treeNodeApi.js +21 -19
  248. package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
  249. package/dist/simple-tree/api/verboseTree.js +2 -2
  250. package/dist/simple-tree/api/verboseTree.js.map +1 -1
  251. package/dist/simple-tree/{viewSchemaToSimpleSchema.d.ts → api/viewSchemaToSimpleSchema.d.ts} +1 -1
  252. package/dist/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -0
  253. package/dist/simple-tree/{viewSchemaToSimpleSchema.js → api/viewSchemaToSimpleSchema.js} +4 -4
  254. package/{lib/simple-tree → dist/simple-tree/api}/viewSchemaToSimpleSchema.js.map +1 -1
  255. package/dist/simple-tree/arrayNode.d.ts +2 -2
  256. package/dist/simple-tree/arrayNode.d.ts.map +1 -1
  257. package/dist/simple-tree/arrayNode.js +30 -21
  258. package/dist/simple-tree/arrayNode.js.map +1 -1
  259. package/dist/simple-tree/core/index.d.ts +3 -3
  260. package/dist/simple-tree/core/index.d.ts.map +1 -1
  261. package/dist/simple-tree/core/index.js +4 -1
  262. package/dist/simple-tree/core/index.js.map +1 -1
  263. package/dist/simple-tree/core/schemaCaching.d.ts +5 -0
  264. package/dist/simple-tree/core/schemaCaching.d.ts.map +1 -1
  265. package/dist/simple-tree/core/schemaCaching.js +10 -1
  266. package/dist/simple-tree/core/schemaCaching.js.map +1 -1
  267. package/dist/simple-tree/core/treeNodeKernel.d.ts +61 -3
  268. package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  269. package/dist/simple-tree/core/treeNodeKernel.js +166 -13
  270. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  271. package/dist/simple-tree/core/treeNodeSchema.d.ts +1 -1
  272. package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
  273. package/dist/simple-tree/core/types.d.ts +17 -20
  274. package/dist/simple-tree/core/types.d.ts.map +1 -1
  275. package/dist/simple-tree/core/types.js.map +1 -1
  276. package/dist/simple-tree/core/withType.d.ts +3 -2
  277. package/dist/simple-tree/core/withType.d.ts.map +1 -1
  278. package/dist/simple-tree/core/withType.js.map +1 -1
  279. package/dist/simple-tree/index.d.ts +7 -9
  280. package/dist/simple-tree/index.d.ts.map +1 -1
  281. package/dist/simple-tree/index.js +15 -6
  282. package/dist/simple-tree/index.js.map +1 -1
  283. package/dist/simple-tree/leafNodeSchema.d.ts +7 -9
  284. package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
  285. package/dist/simple-tree/leafNodeSchema.js +13 -11
  286. package/dist/simple-tree/leafNodeSchema.js.map +1 -1
  287. package/dist/simple-tree/mapNode.d.ts +1 -1
  288. package/dist/simple-tree/mapNode.d.ts.map +1 -1
  289. package/dist/simple-tree/mapNode.js +38 -29
  290. package/dist/simple-tree/mapNode.js.map +1 -1
  291. package/dist/simple-tree/objectNode.d.ts +9 -7
  292. package/dist/simple-tree/objectNode.d.ts.map +1 -1
  293. package/dist/simple-tree/objectNode.js +37 -31
  294. package/dist/simple-tree/objectNode.js.map +1 -1
  295. package/dist/simple-tree/proxies.d.ts +1 -14
  296. package/dist/simple-tree/proxies.d.ts.map +1 -1
  297. package/dist/simple-tree/proxies.js +12 -15
  298. package/dist/simple-tree/proxies.js.map +1 -1
  299. package/dist/simple-tree/proxyBinding.d.ts +2 -62
  300. package/dist/simple-tree/proxyBinding.d.ts.map +1 -1
  301. package/dist/simple-tree/proxyBinding.js +8 -181
  302. package/dist/simple-tree/proxyBinding.js.map +1 -1
  303. package/dist/simple-tree/schemaTypes.d.ts +7 -7
  304. package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
  305. package/dist/simple-tree/schemaTypes.js +4 -4
  306. package/dist/simple-tree/schemaTypes.js.map +1 -1
  307. package/dist/simple-tree/toFlexSchema.d.ts +11 -1
  308. package/dist/simple-tree/toFlexSchema.d.ts.map +1 -1
  309. package/dist/simple-tree/toFlexSchema.js +54 -31
  310. package/dist/simple-tree/toFlexSchema.js.map +1 -1
  311. package/dist/simple-tree/toMapTree.d.ts +25 -37
  312. package/dist/simple-tree/toMapTree.d.ts.map +1 -1
  313. package/dist/simple-tree/toMapTree.js +53 -16
  314. package/dist/simple-tree/toMapTree.js.map +1 -1
  315. package/dist/simple-tree/treeNodeValid.d.ts.map +1 -1
  316. package/dist/simple-tree/treeNodeValid.js +7 -10
  317. package/dist/simple-tree/treeNodeValid.js.map +1 -1
  318. package/dist/simple-tree/typesUnsafe.d.ts +13 -13
  319. package/dist/simple-tree/typesUnsafe.js.map +1 -1
  320. package/dist/simple-tree/walkSchema.d.ts +26 -0
  321. package/dist/simple-tree/walkSchema.d.ts.map +1 -0
  322. package/dist/simple-tree/walkSchema.js +49 -0
  323. package/dist/simple-tree/walkSchema.js.map +1 -0
  324. package/dist/treeFactory.d.ts +2 -1
  325. package/dist/treeFactory.d.ts.map +1 -1
  326. package/dist/treeFactory.js +2 -1
  327. package/dist/treeFactory.js.map +1 -1
  328. package/dist/util/typeUtils.d.ts +2 -2
  329. package/dist/util/typeUtils.js.map +1 -1
  330. package/legacy.d.ts +11 -0
  331. package/lib/alpha.d.ts +102 -0
  332. package/lib/beta.d.ts +6 -2
  333. package/lib/core/index.d.ts +1 -1
  334. package/lib/core/index.d.ts.map +1 -1
  335. package/lib/core/index.js +1 -1
  336. package/lib/core/index.js.map +1 -1
  337. package/lib/core/{revertible/revertible.d.ts → revertible.d.ts} +12 -0
  338. package/lib/core/revertible.d.ts.map +1 -0
  339. package/lib/core/revertible.js.map +1 -0
  340. package/lib/core/schema-stored/format.d.ts +3 -3
  341. package/lib/core/schema-stored/format.js +1 -1
  342. package/lib/core/schema-stored/format.js.map +1 -1
  343. package/lib/core/schema-stored/schema.d.ts +2 -7
  344. package/lib/core/schema-stored/schema.d.ts.map +1 -1
  345. package/lib/core/schema-stored/schema.js +4 -6
  346. package/lib/core/schema-stored/schema.js.map +1 -1
  347. package/lib/core/schema-stored/storedSchemaRepository.d.ts +1 -1
  348. package/lib/core/schema-stored/storedSchemaRepository.d.ts.map +1 -1
  349. package/lib/core/tree/anchorSet.d.ts.map +1 -1
  350. package/lib/core/tree/anchorSet.js +6 -2
  351. package/lib/core/tree/anchorSet.js.map +1 -1
  352. package/lib/core/tree/detachedFieldIndex.d.ts +0 -1
  353. package/lib/core/tree/detachedFieldIndex.d.ts.map +1 -1
  354. package/lib/core/tree/detachedFieldIndex.js +1 -0
  355. package/lib/core/tree/detachedFieldIndex.js.map +1 -1
  356. package/lib/core/tree/visitDelta.d.ts +7 -2
  357. package/lib/core/tree/visitDelta.d.ts.map +1 -1
  358. package/lib/core/tree/visitDelta.js.map +1 -1
  359. package/lib/events/emitter.d.ts +127 -0
  360. package/lib/events/emitter.d.ts.map +1 -0
  361. package/lib/events/{events.js → emitter.js} +48 -29
  362. package/lib/events/emitter.js.map +1 -0
  363. package/lib/events/index.d.ts +2 -1
  364. package/lib/events/index.d.ts.map +1 -1
  365. package/lib/events/index.js +1 -1
  366. package/lib/events/index.js.map +1 -1
  367. package/lib/events/interop.d.ts +36 -0
  368. package/lib/events/interop.d.ts.map +1 -0
  369. package/{src/core/revertible/index.ts → lib/events/interop.js} +2 -2
  370. package/lib/events/interop.js.map +1 -0
  371. package/lib/events/listeners.d.ts +65 -0
  372. package/lib/events/listeners.d.ts.map +1 -0
  373. package/lib/{core/revertible/index.js → events/listeners.js} +2 -2
  374. package/lib/events/listeners.js.map +1 -0
  375. package/lib/feature-libraries/chunked-forest/chunkTree.d.ts +25 -7
  376. package/lib/feature-libraries/chunked-forest/chunkTree.d.ts.map +1 -1
  377. package/lib/feature-libraries/chunked-forest/chunkTree.js +37 -16
  378. package/lib/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  379. package/lib/feature-libraries/chunked-forest/chunkedForest.d.ts +4 -2
  380. package/lib/feature-libraries/chunked-forest/chunkedForest.d.ts.map +1 -1
  381. package/lib/feature-libraries/chunked-forest/chunkedForest.js +12 -5
  382. package/lib/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  383. package/lib/feature-libraries/chunked-forest/uniformChunk.d.ts +15 -2
  384. package/lib/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  385. package/lib/feature-libraries/chunked-forest/uniformChunk.js +28 -2
  386. package/lib/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  387. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts +3 -1
  388. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  389. package/lib/feature-libraries/default-schema/defaultEditBuilder.js +5 -4
  390. package/lib/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  391. package/lib/feature-libraries/flex-map-tree/index.d.ts +1 -1
  392. package/lib/feature-libraries/flex-map-tree/index.d.ts.map +1 -1
  393. package/lib/feature-libraries/flex-map-tree/index.js +1 -1
  394. package/lib/feature-libraries/flex-map-tree/index.js.map +1 -1
  395. package/lib/feature-libraries/flex-map-tree/mapTreeNode.d.ts +35 -33
  396. package/lib/feature-libraries/flex-map-tree/mapTreeNode.d.ts.map +1 -1
  397. package/lib/feature-libraries/flex-map-tree/mapTreeNode.js +83 -104
  398. package/lib/feature-libraries/flex-map-tree/mapTreeNode.js.map +1 -1
  399. package/lib/feature-libraries/flex-tree/context.d.ts +30 -14
  400. package/lib/feature-libraries/flex-tree/context.d.ts.map +1 -1
  401. package/lib/feature-libraries/flex-tree/context.js +10 -7
  402. package/lib/feature-libraries/flex-tree/context.js.map +1 -1
  403. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts +57 -190
  404. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  405. package/lib/feature-libraries/flex-tree/flexTreeTypes.js +15 -2
  406. package/lib/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  407. package/lib/feature-libraries/flex-tree/index.d.ts +2 -3
  408. package/lib/feature-libraries/flex-tree/index.d.ts.map +1 -1
  409. package/lib/feature-libraries/flex-tree/index.js +1 -1
  410. package/lib/feature-libraries/flex-tree/index.js.map +1 -1
  411. package/lib/feature-libraries/flex-tree/lazyEntity.d.ts +3 -3
  412. package/lib/feature-libraries/flex-tree/lazyEntity.d.ts.map +1 -1
  413. package/lib/feature-libraries/flex-tree/lazyEntity.js +2 -10
  414. package/lib/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
  415. package/lib/feature-libraries/flex-tree/lazyField.d.ts +26 -28
  416. package/lib/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  417. package/lib/feature-libraries/flex-tree/lazyField.js +11 -13
  418. package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
  419. package/lib/feature-libraries/flex-tree/lazyNode.d.ts +5 -26
  420. package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  421. package/lib/feature-libraries/flex-tree/lazyNode.js +23 -72
  422. package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  423. package/lib/feature-libraries/flex-tree/unboxed.d.ts +4 -16
  424. package/lib/feature-libraries/flex-tree/unboxed.d.ts.map +1 -1
  425. package/lib/feature-libraries/flex-tree/unboxed.js +5 -37
  426. package/lib/feature-libraries/flex-tree/unboxed.js.map +1 -1
  427. package/lib/feature-libraries/flex-tree/utilities.d.ts +2 -2
  428. package/lib/feature-libraries/flex-tree/utilities.d.ts.map +1 -1
  429. package/lib/feature-libraries/flex-tree/utilities.js +3 -6
  430. package/lib/feature-libraries/flex-tree/utilities.js.map +1 -1
  431. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  432. package/lib/feature-libraries/forest-summary/forestSummarizer.js +4 -1
  433. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  434. package/lib/feature-libraries/index.d.ts +3 -5
  435. package/lib/feature-libraries/index.d.ts.map +1 -1
  436. package/lib/feature-libraries/index.js +5 -5
  437. package/lib/feature-libraries/index.js.map +1 -1
  438. package/lib/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
  439. package/lib/feature-libraries/modular-schema/comparison.js +3 -6
  440. package/lib/feature-libraries/modular-schema/comparison.js.map +1 -1
  441. package/lib/feature-libraries/modular-schema/discrepancies.d.ts.map +1 -1
  442. package/lib/feature-libraries/modular-schema/discrepancies.js +3 -13
  443. package/lib/feature-libraries/modular-schema/discrepancies.js.map +1 -1
  444. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +4 -1
  445. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  446. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts +2 -1
  447. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  448. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +12 -5
  449. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  450. package/lib/feature-libraries/schema-edits/schemaChangeFormat.d.ts +6 -6
  451. package/lib/feature-libraries/schema-index/format.d.ts +3 -3
  452. package/lib/feature-libraries/storedToViewSchema.d.ts.map +1 -1
  453. package/lib/feature-libraries/storedToViewSchema.js +3 -5
  454. package/lib/feature-libraries/storedToViewSchema.js.map +1 -1
  455. package/lib/feature-libraries/typed-schema/flexList.d.ts +3 -3
  456. package/lib/feature-libraries/typed-schema/flexList.js.map +1 -1
  457. package/lib/feature-libraries/typed-schema/index.d.ts +2 -2
  458. package/lib/feature-libraries/typed-schema/index.d.ts.map +1 -1
  459. package/lib/feature-libraries/typed-schema/index.js +2 -2
  460. package/lib/feature-libraries/typed-schema/index.js.map +1 -1
  461. package/lib/feature-libraries/typed-schema/schemaCollection.d.ts.map +1 -1
  462. package/lib/feature-libraries/typed-schema/schemaCollection.js +9 -11
  463. package/lib/feature-libraries/typed-schema/schemaCollection.js.map +1 -1
  464. package/lib/feature-libraries/typed-schema/typedTreeSchema.d.ts +17 -48
  465. package/lib/feature-libraries/typed-schema/typedTreeSchema.d.ts.map +1 -1
  466. package/lib/feature-libraries/typed-schema/typedTreeSchema.js +5 -36
  467. package/lib/feature-libraries/typed-schema/typedTreeSchema.js.map +1 -1
  468. package/lib/feature-libraries/typed-schema/view.d.ts +4 -6
  469. package/lib/feature-libraries/typed-schema/view.d.ts.map +1 -1
  470. package/lib/feature-libraries/typed-schema/view.js +5 -4
  471. package/lib/feature-libraries/typed-schema/view.js.map +1 -1
  472. package/lib/index.d.ts +4 -4
  473. package/lib/index.d.ts.map +1 -1
  474. package/lib/index.js +3 -5
  475. package/lib/index.js.map +1 -1
  476. package/lib/legacy.d.ts +83 -0
  477. package/lib/packageVersion.d.ts +1 -1
  478. package/lib/packageVersion.d.ts.map +1 -1
  479. package/lib/packageVersion.js +1 -1
  480. package/lib/packageVersion.js.map +1 -1
  481. package/lib/public.d.ts +0 -1
  482. package/lib/shared-tree/checkoutFlexTreeView.d.ts +53 -0
  483. package/lib/shared-tree/checkoutFlexTreeView.d.ts.map +1 -0
  484. package/lib/shared-tree/{treeView.js → checkoutFlexTreeView.js} +26 -5
  485. package/lib/shared-tree/checkoutFlexTreeView.js.map +1 -0
  486. package/lib/shared-tree/index.d.ts +3 -3
  487. package/lib/shared-tree/index.d.ts.map +1 -1
  488. package/lib/shared-tree/index.js +1 -1
  489. package/lib/shared-tree/index.js.map +1 -1
  490. package/lib/shared-tree/schematizeTree.d.ts +15 -4
  491. package/lib/shared-tree/schematizeTree.d.ts.map +1 -1
  492. package/lib/shared-tree/schematizeTree.js +8 -9
  493. package/lib/shared-tree/schematizeTree.js.map +1 -1
  494. package/lib/shared-tree/schematizingTreeView.d.ts +9 -4
  495. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  496. package/lib/shared-tree/schematizingTreeView.js +26 -13
  497. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  498. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  499. package/lib/shared-tree/sharedTree.js +2 -2
  500. package/lib/shared-tree/sharedTree.js.map +1 -1
  501. package/lib/shared-tree/sharedTreeChangeEnricher.d.ts +3 -1
  502. package/lib/shared-tree/sharedTreeChangeEnricher.d.ts.map +1 -1
  503. package/lib/shared-tree/sharedTreeChangeEnricher.js +6 -2
  504. package/lib/shared-tree/sharedTreeChangeEnricher.js.map +1 -1
  505. package/lib/shared-tree/sharedTreeChangeFamily.d.ts +3 -1
  506. package/lib/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  507. package/lib/shared-tree/sharedTreeChangeFamily.js +3 -2
  508. package/lib/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  509. package/lib/shared-tree/sharedTreeEditBuilder.d.ts +2 -1
  510. package/lib/shared-tree/sharedTreeEditBuilder.d.ts.map +1 -1
  511. package/lib/shared-tree/sharedTreeEditBuilder.js +2 -2
  512. package/lib/shared-tree/sharedTreeEditBuilder.js.map +1 -1
  513. package/lib/shared-tree/treeApi.d.ts +1 -3
  514. package/lib/shared-tree/treeApi.d.ts.map +1 -1
  515. package/lib/shared-tree/treeApi.js +7 -5
  516. package/lib/shared-tree/treeApi.js.map +1 -1
  517. package/lib/shared-tree/treeCheckout.d.ts +2 -13
  518. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  519. package/lib/shared-tree/treeCheckout.js +18 -2
  520. package/lib/shared-tree/treeCheckout.js.map +1 -1
  521. package/lib/shared-tree-core/branch.js +1 -1
  522. package/lib/shared-tree-core/branch.js.map +1 -1
  523. package/lib/simple-tree/api/create.d.ts.map +1 -1
  524. package/lib/simple-tree/api/create.js +2 -2
  525. package/lib/simple-tree/api/create.js.map +1 -1
  526. package/{dist/simple-tree → lib/simple-tree/api}/getJsonSchema.d.ts +1 -1
  527. package/lib/simple-tree/api/getJsonSchema.d.ts.map +1 -0
  528. package/lib/simple-tree/{getJsonSchema.js → api/getJsonSchema.js} +1 -1
  529. package/lib/simple-tree/api/getJsonSchema.js.map +1 -0
  530. package/{dist/simple-tree → lib/simple-tree/api}/getSimpleSchema.d.ts +1 -1
  531. package/lib/simple-tree/api/getSimpleSchema.d.ts.map +1 -0
  532. package/lib/simple-tree/{getSimpleSchema.js → api/getSimpleSchema.js} +1 -1
  533. package/lib/simple-tree/api/getSimpleSchema.js.map +1 -0
  534. package/lib/simple-tree/api/index.d.ts +5 -0
  535. package/lib/simple-tree/api/index.d.ts.map +1 -1
  536. package/lib/simple-tree/api/index.js +3 -0
  537. package/lib/simple-tree/api/index.js.map +1 -1
  538. package/{dist/simple-tree → lib/simple-tree/api}/jsonSchema.d.ts +1 -1
  539. package/lib/simple-tree/api/jsonSchema.d.ts.map +1 -0
  540. package/lib/simple-tree/api/jsonSchema.js.map +1 -0
  541. package/lib/simple-tree/api/schemaFactory.d.ts +45 -14
  542. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  543. package/lib/simple-tree/api/schemaFactory.js +43 -12
  544. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  545. package/lib/simple-tree/{simpleSchema.d.ts → api/simpleSchema.d.ts} +4 -4
  546. package/lib/simple-tree/api/simpleSchema.d.ts.map +1 -0
  547. package/lib/simple-tree/api/simpleSchema.js.map +1 -0
  548. package/lib/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -0
  549. package/lib/simple-tree/{simpleSchemaToJsonSchema.js → api/simpleSchemaToJsonSchema.js} +4 -4
  550. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -0
  551. package/lib/simple-tree/api/tree.d.ts +1 -21
  552. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  553. package/lib/simple-tree/api/tree.js +2 -34
  554. package/lib/simple-tree/api/tree.js.map +1 -1
  555. package/lib/simple-tree/api/treeApiBeta.d.ts +79 -0
  556. package/lib/simple-tree/api/treeApiBeta.d.ts.map +1 -0
  557. package/lib/simple-tree/api/treeApiBeta.js +23 -0
  558. package/lib/simple-tree/api/treeApiBeta.js.map +1 -0
  559. package/lib/simple-tree/api/treeNodeApi.d.ts +1 -1
  560. package/lib/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  561. package/lib/simple-tree/api/treeNodeApi.js +23 -21
  562. package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
  563. package/lib/simple-tree/api/verboseTree.js +1 -1
  564. package/lib/simple-tree/api/verboseTree.js.map +1 -1
  565. package/lib/simple-tree/{viewSchemaToSimpleSchema.d.ts → api/viewSchemaToSimpleSchema.d.ts} +1 -1
  566. package/lib/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -0
  567. package/lib/simple-tree/{viewSchemaToSimpleSchema.js → api/viewSchemaToSimpleSchema.js} +4 -4
  568. package/lib/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -0
  569. package/lib/simple-tree/arrayNode.d.ts +2 -2
  570. package/lib/simple-tree/arrayNode.d.ts.map +1 -1
  571. package/lib/simple-tree/arrayNode.js +33 -24
  572. package/lib/simple-tree/arrayNode.js.map +1 -1
  573. package/lib/simple-tree/core/index.d.ts +3 -3
  574. package/lib/simple-tree/core/index.d.ts.map +1 -1
  575. package/lib/simple-tree/core/index.js +2 -2
  576. package/lib/simple-tree/core/index.js.map +1 -1
  577. package/lib/simple-tree/core/schemaCaching.d.ts +5 -0
  578. package/lib/simple-tree/core/schemaCaching.d.ts.map +1 -1
  579. package/lib/simple-tree/core/schemaCaching.js +8 -0
  580. package/lib/simple-tree/core/schemaCaching.js.map +1 -1
  581. package/lib/simple-tree/core/treeNodeKernel.d.ts +61 -3
  582. package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  583. package/lib/simple-tree/core/treeNodeKernel.js +156 -5
  584. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  585. package/lib/simple-tree/core/treeNodeSchema.d.ts +1 -1
  586. package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
  587. package/lib/simple-tree/core/types.d.ts +17 -20
  588. package/lib/simple-tree/core/types.d.ts.map +1 -1
  589. package/lib/simple-tree/core/types.js.map +1 -1
  590. package/lib/simple-tree/core/withType.d.ts +3 -2
  591. package/lib/simple-tree/core/withType.d.ts.map +1 -1
  592. package/lib/simple-tree/core/withType.js.map +1 -1
  593. package/lib/simple-tree/index.d.ts +7 -9
  594. package/lib/simple-tree/index.d.ts.map +1 -1
  595. package/lib/simple-tree/index.js +5 -5
  596. package/lib/simple-tree/index.js.map +1 -1
  597. package/lib/simple-tree/leafNodeSchema.d.ts +7 -9
  598. package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
  599. package/lib/simple-tree/leafNodeSchema.js +14 -12
  600. package/lib/simple-tree/leafNodeSchema.js.map +1 -1
  601. package/lib/simple-tree/mapNode.d.ts +1 -1
  602. package/lib/simple-tree/mapNode.d.ts.map +1 -1
  603. package/lib/simple-tree/mapNode.js +38 -29
  604. package/lib/simple-tree/mapNode.js.map +1 -1
  605. package/lib/simple-tree/objectNode.d.ts +9 -7
  606. package/lib/simple-tree/objectNode.d.ts.map +1 -1
  607. package/lib/simple-tree/objectNode.js +40 -34
  608. package/lib/simple-tree/objectNode.js.map +1 -1
  609. package/lib/simple-tree/proxies.d.ts +1 -14
  610. package/lib/simple-tree/proxies.d.ts.map +1 -1
  611. package/lib/simple-tree/proxies.js +11 -14
  612. package/lib/simple-tree/proxies.js.map +1 -1
  613. package/lib/simple-tree/proxyBinding.d.ts +2 -62
  614. package/lib/simple-tree/proxyBinding.d.ts.map +1 -1
  615. package/lib/simple-tree/proxyBinding.js +6 -174
  616. package/lib/simple-tree/proxyBinding.js.map +1 -1
  617. package/lib/simple-tree/schemaTypes.d.ts +7 -7
  618. package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
  619. package/lib/simple-tree/schemaTypes.js +4 -4
  620. package/lib/simple-tree/schemaTypes.js.map +1 -1
  621. package/lib/simple-tree/toFlexSchema.d.ts +11 -1
  622. package/lib/simple-tree/toFlexSchema.d.ts.map +1 -1
  623. package/lib/simple-tree/toFlexSchema.js +29 -8
  624. package/lib/simple-tree/toFlexSchema.js.map +1 -1
  625. package/lib/simple-tree/toMapTree.d.ts +25 -37
  626. package/lib/simple-tree/toMapTree.d.ts.map +1 -1
  627. package/lib/simple-tree/toMapTree.js +54 -17
  628. package/lib/simple-tree/toMapTree.js.map +1 -1
  629. package/lib/simple-tree/treeNodeValid.d.ts.map +1 -1
  630. package/lib/simple-tree/treeNodeValid.js +8 -11
  631. package/lib/simple-tree/treeNodeValid.js.map +1 -1
  632. package/lib/simple-tree/typesUnsafe.d.ts +13 -13
  633. package/lib/simple-tree/typesUnsafe.js.map +1 -1
  634. package/lib/simple-tree/walkSchema.d.ts +26 -0
  635. package/lib/simple-tree/walkSchema.d.ts.map +1 -0
  636. package/lib/simple-tree/walkSchema.js +43 -0
  637. package/lib/simple-tree/walkSchema.js.map +1 -0
  638. package/lib/treeFactory.d.ts +2 -1
  639. package/lib/treeFactory.d.ts.map +1 -1
  640. package/lib/treeFactory.js +2 -1
  641. package/lib/treeFactory.js.map +1 -1
  642. package/lib/tsdoc-metadata.json +1 -1
  643. package/lib/util/typeUtils.d.ts +2 -2
  644. package/lib/util/typeUtils.js.map +1 -1
  645. package/package.json +57 -25
  646. package/src/core/index.ts +1 -1
  647. package/src/core/{revertible/revertible.ts → revertible.ts} +15 -0
  648. package/src/core/schema-stored/format.ts +1 -1
  649. package/src/core/schema-stored/schema.ts +6 -13
  650. package/src/core/tree/anchorSet.ts +18 -3
  651. package/src/core/tree/detachedFieldIndex.ts +6 -5
  652. package/src/core/tree/visitDelta.ts +7 -2
  653. package/src/events/{events.ts → emitter.ts} +52 -139
  654. package/src/events/index.ts +7 -7
  655. package/src/events/interop.ts +49 -0
  656. package/src/events/listeners.ts +68 -0
  657. package/src/feature-libraries/chunked-forest/chunkTree.ts +63 -18
  658. package/src/feature-libraries/chunked-forest/chunkedForest.ts +18 -4
  659. package/src/feature-libraries/chunked-forest/uniformChunk.ts +33 -0
  660. package/src/feature-libraries/default-schema/defaultEditBuilder.ts +5 -3
  661. package/src/feature-libraries/flex-map-tree/index.ts +1 -0
  662. package/src/feature-libraries/flex-map-tree/mapTreeNode.ts +135 -210
  663. package/src/feature-libraries/flex-tree/README.md +4 -75
  664. package/src/feature-libraries/flex-tree/context.ts +37 -16
  665. package/src/feature-libraries/flex-tree/flexTreeTypes.ts +69 -291
  666. package/src/feature-libraries/flex-tree/index.ts +7 -13
  667. package/src/feature-libraries/flex-tree/lazyEntity.ts +2 -11
  668. package/src/feature-libraries/flex-tree/lazyField.ts +49 -73
  669. package/src/feature-libraries/flex-tree/lazyNode.ts +25 -154
  670. package/src/feature-libraries/flex-tree/unboxed.ts +9 -68
  671. package/src/feature-libraries/flex-tree/utilities.ts +4 -8
  672. package/src/feature-libraries/forest-summary/forestSummarizer.ts +4 -1
  673. package/src/feature-libraries/index.ts +2 -27
  674. package/src/feature-libraries/modular-schema/comparison.ts +4 -6
  675. package/src/feature-libraries/modular-schema/discrepancies.ts +7 -16
  676. package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +4 -1
  677. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +14 -4
  678. package/src/feature-libraries/storedToViewSchema.ts +5 -6
  679. package/src/feature-libraries/typed-schema/flexList.ts +3 -3
  680. package/src/feature-libraries/typed-schema/index.ts +1 -3
  681. package/src/feature-libraries/typed-schema/schemaCollection.ts +15 -17
  682. package/src/feature-libraries/typed-schema/typedTreeSchema.ts +35 -127
  683. package/src/feature-libraries/typed-schema/view.ts +4 -13
  684. package/src/index.ts +4 -8
  685. package/src/packageVersion.ts +1 -1
  686. package/src/shared-tree/checkoutFlexTreeView.ts +89 -0
  687. package/src/shared-tree/index.ts +2 -7
  688. package/src/shared-tree/schematizeTree.ts +23 -12
  689. package/src/shared-tree/schematizingTreeView.ts +34 -24
  690. package/src/shared-tree/sharedTree.ts +6 -1
  691. package/src/shared-tree/sharedTreeChangeEnricher.ts +6 -1
  692. package/src/shared-tree/sharedTreeChangeFamily.ts +7 -1
  693. package/src/shared-tree/sharedTreeEditBuilder.ts +9 -4
  694. package/src/shared-tree/treeApi.ts +10 -10
  695. package/src/shared-tree/treeCheckout.ts +26 -15
  696. package/src/shared-tree-core/branch.ts +1 -1
  697. package/src/simple-tree/ProxyBinding.md +23 -23
  698. package/src/simple-tree/api/create.ts +8 -3
  699. package/src/simple-tree/{getJsonSchema.ts → api/getJsonSchema.ts} +3 -3
  700. package/src/simple-tree/{getSimpleSchema.ts → api/getSimpleSchema.ts} +3 -3
  701. package/src/simple-tree/api/index.ts +20 -0
  702. package/src/simple-tree/{jsonSchema.ts → api/jsonSchema.ts} +1 -1
  703. package/src/simple-tree/api/schemaFactory.ts +44 -13
  704. package/src/simple-tree/{simpleSchema.ts → api/simpleSchema.ts} +4 -4
  705. package/src/simple-tree/{simpleSchemaToJsonSchema.ts → api/simpleSchemaToJsonSchema.ts} +4 -4
  706. package/src/simple-tree/api/tree.ts +2 -71
  707. package/src/simple-tree/api/treeApiBeta.ts +101 -0
  708. package/src/simple-tree/api/treeNodeApi.ts +32 -23
  709. package/src/simple-tree/api/verboseTree.ts +1 -1
  710. package/src/simple-tree/{viewSchemaToSimpleSchema.ts → api/viewSchemaToSimpleSchema.ts} +5 -5
  711. package/src/simple-tree/arrayNode.ts +37 -31
  712. package/src/simple-tree/core/index.ts +4 -1
  713. package/src/simple-tree/core/schemaCaching.ts +10 -0
  714. package/src/simple-tree/core/treeNodeKernel.ts +198 -5
  715. package/src/simple-tree/core/treeNodeSchema.ts +1 -1
  716. package/src/simple-tree/core/types.ts +16 -27
  717. package/src/simple-tree/core/withType.ts +3 -1
  718. package/src/simple-tree/index.ts +29 -21
  719. package/src/simple-tree/leafNodeSchema.ts +24 -28
  720. package/src/simple-tree/mapNode.ts +47 -29
  721. package/src/simple-tree/objectNode.ts +51 -46
  722. package/src/simple-tree/proxies.ts +22 -51
  723. package/src/simple-tree/proxyBinding.ts +3 -254
  724. package/src/simple-tree/schemaTypes.ts +8 -8
  725. package/src/simple-tree/toFlexSchema.ts +40 -7
  726. package/src/simple-tree/toMapTree.ts +113 -79
  727. package/src/simple-tree/treeNodeValid.ts +10 -13
  728. package/src/simple-tree/typesUnsafe.ts +13 -13
  729. package/src/simple-tree/walkSchema.ts +81 -0
  730. package/src/treeFactory.ts +2 -1
  731. package/src/util/typeUtils.ts +2 -2
  732. package/dist/core/revertible/index.d.ts.map +0 -1
  733. package/dist/core/revertible/index.js +0 -10
  734. package/dist/core/revertible/index.js.map +0 -1
  735. package/dist/core/revertible/revertible.d.ts.map +0 -1
  736. package/dist/core/revertible/revertible.js.map +0 -1
  737. package/dist/domains/index.d.ts +0 -8
  738. package/dist/domains/index.d.ts.map +0 -1
  739. package/dist/domains/index.js +0 -20
  740. package/dist/domains/index.js.map +0 -1
  741. package/dist/domains/json/index.d.ts +0 -7
  742. package/dist/domains/json/index.d.ts.map +0 -1
  743. package/dist/domains/json/index.js +0 -17
  744. package/dist/domains/json/index.js.map +0 -1
  745. package/dist/domains/json/jsonCursor.d.ts +0 -52
  746. package/dist/domains/json/jsonCursor.d.ts.map +0 -1
  747. package/dist/domains/json/jsonCursor.js +0 -197
  748. package/dist/domains/json/jsonCursor.js.map +0 -1
  749. package/dist/domains/json/jsonDomainSchema.d.ts +0 -24
  750. package/dist/domains/json/jsonDomainSchema.d.ts.map +0 -1
  751. package/dist/domains/json/jsonDomainSchema.js +0 -32
  752. package/dist/domains/json/jsonDomainSchema.js.map +0 -1
  753. package/dist/domains/leafDomain.d.ts +0 -72
  754. package/dist/domains/leafDomain.d.ts.map +0 -1
  755. package/dist/domains/leafDomain.js +0 -88
  756. package/dist/domains/leafDomain.js.map +0 -1
  757. package/dist/domains/schemaBuilder.d.ts +0 -103
  758. package/dist/domains/schemaBuilder.d.ts.map +0 -1
  759. package/dist/domains/schemaBuilder.js +0 -121
  760. package/dist/domains/schemaBuilder.js.map +0 -1
  761. package/dist/domains/testRecursiveDomain.d.ts +0 -17
  762. package/dist/domains/testRecursiveDomain.d.ts.map +0 -1
  763. package/dist/domains/testRecursiveDomain.js +0 -35
  764. package/dist/domains/testRecursiveDomain.js.map +0 -1
  765. package/dist/events/events.d.ts +0 -207
  766. package/dist/events/events.d.ts.map +0 -1
  767. package/dist/events/events.js.map +0 -1
  768. package/dist/feature-libraries/schemaBuilder.d.ts +0 -31
  769. package/dist/feature-libraries/schemaBuilder.d.ts.map +0 -1
  770. package/dist/feature-libraries/schemaBuilder.js +0 -40
  771. package/dist/feature-libraries/schemaBuilder.js.map +0 -1
  772. package/dist/feature-libraries/schemaBuilderBase.d.ts +0 -191
  773. package/dist/feature-libraries/schemaBuilderBase.d.ts.map +0 -1
  774. package/dist/feature-libraries/schemaBuilderBase.js +0 -201
  775. package/dist/feature-libraries/schemaBuilderBase.js.map +0 -1
  776. package/dist/shared-tree/treeView.d.ts +0 -73
  777. package/dist/shared-tree/treeView.d.ts.map +0 -1
  778. package/dist/shared-tree/treeView.js.map +0 -1
  779. package/dist/simple-tree/getJsonSchema.d.ts.map +0 -1
  780. package/dist/simple-tree/getJsonSchema.js.map +0 -1
  781. package/dist/simple-tree/getSimpleSchema.d.ts.map +0 -1
  782. package/dist/simple-tree/getSimpleSchema.js.map +0 -1
  783. package/dist/simple-tree/jsonSchema.d.ts.map +0 -1
  784. package/dist/simple-tree/jsonSchema.js.map +0 -1
  785. package/dist/simple-tree/simpleSchema.d.ts.map +0 -1
  786. package/dist/simple-tree/simpleSchema.js.map +0 -1
  787. package/dist/simple-tree/simpleSchemaToJsonSchema.d.ts.map +0 -1
  788. package/dist/simple-tree/simpleSchemaToJsonSchema.js.map +0 -1
  789. package/dist/simple-tree/viewSchemaToSimpleSchema.d.ts.map +0 -1
  790. package/dist/simple-tree/viewSchemaToSimpleSchema.js.map +0 -1
  791. package/lib/core/revertible/index.d.ts.map +0 -1
  792. package/lib/core/revertible/index.js.map +0 -1
  793. package/lib/core/revertible/revertible.d.ts.map +0 -1
  794. package/lib/core/revertible/revertible.js.map +0 -1
  795. package/lib/domains/index.d.ts +0 -8
  796. package/lib/domains/index.d.ts.map +0 -1
  797. package/lib/domains/index.js +0 -8
  798. package/lib/domains/index.js.map +0 -1
  799. package/lib/domains/json/index.d.ts +0 -7
  800. package/lib/domains/json/index.d.ts.map +0 -1
  801. package/lib/domains/json/index.js +0 -7
  802. package/lib/domains/json/index.js.map +0 -1
  803. package/lib/domains/json/jsonCursor.d.ts +0 -52
  804. package/lib/domains/json/jsonCursor.d.ts.map +0 -1
  805. package/lib/domains/json/jsonCursor.js +0 -192
  806. package/lib/domains/json/jsonCursor.js.map +0 -1
  807. package/lib/domains/json/jsonDomainSchema.d.ts +0 -24
  808. package/lib/domains/json/jsonDomainSchema.d.ts.map +0 -1
  809. package/lib/domains/json/jsonDomainSchema.js +0 -29
  810. package/lib/domains/json/jsonDomainSchema.js.map +0 -1
  811. package/lib/domains/leafDomain.d.ts +0 -72
  812. package/lib/domains/leafDomain.d.ts.map +0 -1
  813. package/lib/domains/leafDomain.js +0 -85
  814. package/lib/domains/leafDomain.js.map +0 -1
  815. package/lib/domains/schemaBuilder.d.ts +0 -103
  816. package/lib/domains/schemaBuilder.d.ts.map +0 -1
  817. package/lib/domains/schemaBuilder.js +0 -117
  818. package/lib/domains/schemaBuilder.js.map +0 -1
  819. package/lib/domains/testRecursiveDomain.d.ts +0 -17
  820. package/lib/domains/testRecursiveDomain.d.ts.map +0 -1
  821. package/lib/domains/testRecursiveDomain.js +0 -32
  822. package/lib/domains/testRecursiveDomain.js.map +0 -1
  823. package/lib/events/events.d.ts +0 -207
  824. package/lib/events/events.d.ts.map +0 -1
  825. package/lib/events/events.js.map +0 -1
  826. package/lib/feature-libraries/schemaBuilder.d.ts +0 -31
  827. package/lib/feature-libraries/schemaBuilder.d.ts.map +0 -1
  828. package/lib/feature-libraries/schemaBuilder.js +0 -36
  829. package/lib/feature-libraries/schemaBuilder.js.map +0 -1
  830. package/lib/feature-libraries/schemaBuilderBase.d.ts +0 -191
  831. package/lib/feature-libraries/schemaBuilderBase.d.ts.map +0 -1
  832. package/lib/feature-libraries/schemaBuilderBase.js +0 -195
  833. package/lib/feature-libraries/schemaBuilderBase.js.map +0 -1
  834. package/lib/shared-tree/treeView.d.ts +0 -73
  835. package/lib/shared-tree/treeView.d.ts.map +0 -1
  836. package/lib/shared-tree/treeView.js.map +0 -1
  837. package/lib/simple-tree/getJsonSchema.d.ts.map +0 -1
  838. package/lib/simple-tree/getJsonSchema.js.map +0 -1
  839. package/lib/simple-tree/getSimpleSchema.d.ts.map +0 -1
  840. package/lib/simple-tree/getSimpleSchema.js.map +0 -1
  841. package/lib/simple-tree/jsonSchema.d.ts.map +0 -1
  842. package/lib/simple-tree/jsonSchema.js.map +0 -1
  843. package/lib/simple-tree/simpleSchema.d.ts.map +0 -1
  844. package/lib/simple-tree/simpleSchema.js.map +0 -1
  845. package/lib/simple-tree/simpleSchemaToJsonSchema.d.ts.map +0 -1
  846. package/lib/simple-tree/simpleSchemaToJsonSchema.js.map +0 -1
  847. package/lib/simple-tree/viewSchemaToSimpleSchema.d.ts.map +0 -1
  848. package/src/domains/README.md +0 -6
  849. package/src/domains/fence.json +0 -5
  850. package/src/domains/index.ts +0 -19
  851. package/src/domains/json/fence.json +0 -5
  852. package/src/domains/json/index.ts +0 -13
  853. package/src/domains/json/jsonCursor.ts +0 -247
  854. package/src/domains/json/jsonDomainSchema.ts +0 -47
  855. package/src/domains/leafDomain.ts +0 -97
  856. package/src/domains/schemaBuilder.ts +0 -153
  857. package/src/domains/testRecursiveDomain.ts +0 -38
  858. package/src/events/fence.json +0 -5
  859. package/src/feature-libraries/schemaBuilder.ts +0 -45
  860. package/src/feature-libraries/schemaBuilderBase.ts +0 -393
  861. package/src/shared-tree/treeView.ts +0 -113
  862. /package/dist/core/{revertible/revertible.js → revertible.js} +0 -0
  863. /package/dist/simple-tree/{jsonSchema.js → api/jsonSchema.js} +0 -0
  864. /package/dist/simple-tree/{simpleSchema.js → api/simpleSchema.js} +0 -0
  865. /package/dist/simple-tree/{simpleSchemaToJsonSchema.d.ts → api/simpleSchemaToJsonSchema.d.ts} +0 -0
  866. /package/lib/core/{revertible/revertible.js → revertible.js} +0 -0
  867. /package/lib/simple-tree/{jsonSchema.js → api/jsonSchema.js} +0 -0
  868. /package/lib/simple-tree/{simpleSchema.js → api/simpleSchema.js} +0 -0
  869. /package/lib/simple-tree/{simpleSchemaToJsonSchema.d.ts → api/simpleSchemaToJsonSchema.d.ts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"visitDelta.js","sourceRoot":"","sources":["../../../src/core/tree/visitDelta.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAq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AAC;YACrB,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport { type NestedMap, setInNestedMap, tryGetFromNestedMap } from \"../../util/index.js\";\nimport type { FieldKey } from \"../schema-stored/index.js\";\n\nimport type { ITreeCursorSynchronous } from \"./cursor.js\";\n// eslint-disable-next-line import/no-duplicates\nimport type * as Delta from \"./delta.js\";\n// Since ProtoNodes is reexported, import it directly to avoid forcing Delta to be reexported.\n// eslint-disable-next-line import/no-duplicates\nimport type { ProtoNodes } from \"./delta.js\";\nimport {\n\tareDetachedNodeIdsEqual,\n\tisAttachMark,\n\tisDetachMark,\n\tisReplaceMark,\n\toffsetDetachId,\n} from \"./deltaUtil.js\";\nimport type { DetachedFieldIndex } from \"./detachedFieldIndex.js\";\nimport type { ForestRootId, Major, Minor } from \"./detachedFieldIndexTypes.js\";\nimport type { NodeIndex, PlaceIndex, Range } from \"./pathTree.js\";\nimport type { RevisionTag } from \"../index.js\";\n\n/**\n * Implementation notes:\n *\n * The visit is organized into four phases:\n * 1. a detach pass\n * 2. root transfers\n * 3. an attach pass\n * 4. root destructions\n *\n * The core idea is that before content can be attached, it must first exist and be in a detached field.\n * The detach pass is therefore responsible for making sure that all roots that needs to be attached during the\n * attach pass are detached.\n * In practice, this means the detach pass must:\n * - Create all subtrees that need to be created\n * - Detach all moved nodes\n *\n * In addition to that, the detach pass also detaches nodes that need removing, with the exception of nodes that get\n * replaced. The reason for this exception is that we need to be able to communicate replaces as atomic operations.\n * In order to do that, we need to wait until we are sure that the content to attach is available as a detached root.\n * Replaces are therefore handled during the attach pass.\n * Note that this could theoretically lead to a situation where, in the attach pass, one replace wants to attach\n * a node that has yet to be detached by another replace. This does not occur in practice because we do not support\n * editing operations that would lead to this situation.\n *\n * While the detach pass ensures that nodes to be attached are in a detached state, it does not guarantee that they\n * reside in the correct detach field. That is the responsibility of the root transfers phase.\n *\n * The attach phase carries out attaches and replaces.\n *\n * After the attach phase, roots destruction is carried out.\n * This needs to happen last to allow modifications to detached roots to be applied before they are destroyed.\n *\n * The details of the delta visit algorithm can impact how/when events are emitted by the objects that own the visitors.\n * For example, as of 2024-03-27, the subtreecChanged event of an AnchorNode is emitted when exiting a node during a\n * delta visit, and thus the two-pass nature of the algorithm means the event fires twice for any given change.\n * This two-pass nature also means that the event may fire at a time where no change is visible in the tree. E.g.,\n * if a node is being replaced, when the event fires during the detach pass no change in the tree has happened so the\n * listener won't see any; then when it fires during the attach pass, the change will be visible in the event listener.\n */\n\n/**\n * Crawls the given `delta`, calling `visitor`'s callback for each change encountered.\n * Each successive call to the visitor callbacks assumes that the change described by earlier calls have been applied\n * to the document tree. For example, for a change that removes the first and third node of a field, the visitor calls\n * will first call detach with a range from indices 0 to 1 then call detach with a range from indices 1 to 2.\n *\n * @param delta - The delta to be crawled.\n * @param visitor - The object to notify of the changes encountered.\n * @param detachedFieldIndex - Index responsible for keeping track of the existing detached fields.\n * @param latestRevision - The latest revision tag associated with this delta.\n */\nexport function visitDelta(\n\tdelta: Delta.Root,\n\tvisitor: DeltaVisitor,\n\tdetachedFieldIndex: DetachedFieldIndex,\n\tlatestRevision: RevisionTag | undefined,\n): void {\n\tconst detachPassRoots: Map<ForestRootId, Delta.FieldMap> = new Map();\n\tconst attachPassRoots: Map<ForestRootId, Delta.FieldMap> = new Map();\n\tconst rootTransfers: Delta.DetachedNodeRename[] = [];\n\tconst rootDestructions: Delta.DetachedNodeDestruction[] = [];\n\tconst refreshers: NestedMap<Major, Minor, ITreeCursorSynchronous> = new Map();\n\tdelta.refreshers?.forEach(({ id: { major, minor }, trees }) => {\n\t\tfor (let i = 0; i < trees.length; i += 1) {\n\t\t\tconst offsettedId = minor + i;\n\t\t\tsetInNestedMap(refreshers, major, offsettedId, trees[i]);\n\t\t}\n\t});\n\tconst detachConfig: PassConfig = {\n\t\tfunc: detachPass,\n\t\tlatestRevision,\n\t\trefreshers,\n\t\tdetachedFieldIndex,\n\t\tdetachPassRoots,\n\t\tattachPassRoots,\n\t\trootTransfers,\n\t\trootDestructions,\n\t};\n\tprocessBuilds(delta.build, detachConfig, visitor);\n\tvisitFieldMarks(delta.fields, visitor, detachConfig);\n\tfixedPointVisitOfRoots(visitor, detachPassRoots, detachConfig);\n\ttransferRoots(\n\t\trootTransfers,\n\t\tattachPassRoots,\n\t\tdetachedFieldIndex,\n\t\tvisitor,\n\t\trefreshers,\n\t\tlatestRevision,\n\t);\n\tconst attachConfig: PassConfig = {\n\t\tfunc: attachPass,\n\t\tlatestRevision,\n\t\trefreshers,\n\t\tdetachedFieldIndex,\n\t\tdetachPassRoots,\n\t\tattachPassRoots,\n\t\trootTransfers,\n\t\trootDestructions,\n\t};\n\tvisitFieldMarks(delta.fields, visitor, attachConfig);\n\tfixedPointVisitOfRoots(visitor, attachPassRoots, attachConfig);\n\tcollectDestroys(delta.destroy, attachConfig);\n\tfor (const { id, count } of rootDestructions) {\n\t\tfor (let i = 0; i < count; i += 1) {\n\t\t\tconst offsetId = offsetDetachId(id, i);\n\t\t\tconst root = detachedFieldIndex.getEntry(offsetId);\n\t\t\tconst field = detachedFieldIndex.toFieldKey(root);\n\t\t\tvisitor.destroy(field, 1);\n\t\t\tdetachedFieldIndex.deleteEntry(offsetId);\n\t\t}\n\t}\n}\n\n/**\n * Visits all nodes in `roots` until none are left.\n * This function tolerates entries being added to and removed from `roots` as part of visits.\n * @param visitor - The visitor to visit the roots with.\n * @param roots - The initial set of roots to visit.\n * Individual entries are removed prior to being visited.\n * @param config - The configuration to use for visits.\n */\nfunction fixedPointVisitOfRoots(\n\tvisitor: DeltaVisitor,\n\troots: Map<ForestRootId, Delta.FieldMap>,\n\tconfig: PassConfig,\n): void {\n\twhile (roots.size > 0) {\n\t\tfor (const [root, modifications] of roots) {\n\t\t\troots.delete(root);\n\t\t\tconst field = config.detachedFieldIndex.toFieldKey(root);\n\t\t\tvisitor.enterField(field);\n\t\t\t// Note: each visit may lead to `roots` being populated with new entries or having some entries removed.\n\t\t\tvisitNode(0, modifications, visitor, config);\n\t\t\tvisitor.exitField(field);\n\t\t}\n\t}\n}\n\n/**\n * Transfers roots from one detached field to another.\n * This occurs in the following circumstances:\n * - A changeset moves then removes a node\n * - A changeset restores then moves a node\n * - A changeset restores then removes a node\n * TODO#5481: update the DetachedFieldIndex instead of moving the nodes around.\n *\n * @param rootTransfers - The transfers to perform.\n * @param mapToUpdate - A map to update based on the transfers being performed.\n * @param detachedFieldIndex - The index to update based on the transfers being performed.\n * @param visitor - The visitor to inform of the transfers being performed.\n */\nfunction transferRoots(\n\trootTransfers: readonly Delta.DetachedNodeRename[],\n\tmapToUpdate: Map<ForestRootId, unknown>,\n\tdetachedFieldIndex: DetachedFieldIndex,\n\tvisitor: DeltaVisitor,\n\trefreshers: NestedMap<Major, Minor, ITreeCursorSynchronous>,\n\trevision?: RevisionTag,\n): void {\n\ttype AtomizedNodeRename = Omit<Delta.DetachedNodeRename, \"count\">;\n\tlet nextBatch = rootTransfers.flatMap(({ oldId, newId, count }) => {\n\t\tconst atomized: AtomizedNodeRename[] = [];\n\t\t// It's possible for a detached node to be revived transiently such that it ends up back in the same detached field.\n\t\t// Making such a transfer wouldn't just be inefficient, it would lead us to mistakenly think we have moved all content\n\t\t// out of the source detached field, and would lead us to delete the tree index entry for that source detached field.\n\t\t// This would effectively result in the tree index missing an entry for the detached field.\n\t\t// This if statement prevents that from happening.\n\t\tif (!areDetachedNodeIdsEqual(oldId, newId)) {\n\t\t\tfor (let i = 0; i < count; i += 1) {\n\t\t\t\tatomized.push({ oldId: offsetDetachId(oldId, i), newId: offsetDetachId(newId, i) });\n\t\t\t}\n\t\t}\n\t\treturn atomized;\n\t});\n\twhile (nextBatch.length > 0) {\n\t\tconst delayed: AtomizedNodeRename[] = [];\n\t\tconst priorSize = nextBatch.length;\n\t\tfor (const { oldId, newId } of nextBatch) {\n\t\t\tlet oldRootId = detachedFieldIndex.tryGetEntry(oldId);\n\t\t\tif (oldRootId === undefined) {\n\t\t\t\tconst tree = tryGetFromNestedMap(refreshers, oldId.major, oldId.minor);\n\t\t\t\tif (tree !== undefined) {\n\t\t\t\t\tbuildTrees(oldId, [tree], detachedFieldIndex, revision, visitor);\n\t\t\t\t\toldRootId = detachedFieldIndex.getEntry(oldId);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (oldRootId === undefined) {\n\t\t\t\t// The source field is not populated.\n\t\t\t\t// This can happen when another rename needs to be performed first.\n\t\t\t\tdelayed.push({ oldId, newId });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlet newRootId = detachedFieldIndex.tryGetEntry(newId);\n\t\t\tif (newRootId !== undefined) {\n\t\t\t\t// The destination field is already occupied.\n\t\t\t\t// This can happen when another rename needs to be performed first.\n\t\t\t\tdelayed.push({ oldId, newId });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tnewRootId = detachedFieldIndex.createEntry(newId, revision);\n\t\t\tconst fields = mapToUpdate.get(oldRootId);\n\t\t\tif (fields !== undefined) {\n\t\t\t\tmapToUpdate.delete(oldRootId);\n\t\t\t\tmapToUpdate.set(newRootId, fields);\n\t\t\t}\n\t\t\tconst oldField = detachedFieldIndex.toFieldKey(oldRootId);\n\t\t\tconst newField = detachedFieldIndex.toFieldKey(newRootId);\n\t\t\tvisitor.enterField(oldField);\n\t\t\tvisitor.detach({ start: 0, end: 1 }, newField);\n\t\t\tvisitor.exitField(oldField);\n\t\t\tdetachedFieldIndex.deleteEntry(oldId);\n\t\t}\n\t\tassert(delayed.length < priorSize, 0x7cf /* transferRoots should make progress */);\n\t\tnextBatch = delayed;\n\t}\n}\n\n/**\n * Visitor for changes in a delta.\n * Must be freed after use.\n */\nexport interface DeltaVisitor {\n\t/**\n\t * Frees/releases the visitor. Must be called once the visitor is no longer needed, since trying to acquire\n\t * a new one before freeing an existing one is invalid.\n\t */\n\tfree(): void;\n\t/**\n\t * Creates nodes for the given content in a new detached field.\n\t * @param content - The content to create.\n\t * @param destination - The key for a new detached field.\n\t * A field with this key must not already exist.\n\t */\n\tcreate(content: ProtoNodes, destination: FieldKey): void;\n\t/**\n\t * Recursively destroys the given detached field and all of the nodes within it.\n\t * @param detachedField - The key for the detached field to destroy.\n\t * @param count - The number of nodes being destroyed.\n\t * Expected to match the number of nodes in the detached field being destroyed.\n\t */\n\tdestroy(detachedField: FieldKey, count: number): void;\n\t/**\n\t * Transfers all the nodes from a detached field to the current field.\n\t * @param source - The detached field to transfer the nodes from.\n\t * @param count - The number of nodes being attached.\n\t * Expected to match the number of nodes in the source detached field.\n\t * @param destination - The index at which to attach the nodes.\n\t */\n\tattach(source: FieldKey, count: number, destination: PlaceIndex): void;\n\t/**\n\t * Transfers a range of nodes from the current field to a new detached field.\n\t * @param source - The bounds of the range of nodes to detach.\n\t * @param destination - The key for a new detached field.\n\t * A field with this key must not already exist.\n\t */\n\tdetach(source: Range, destination: FieldKey): void;\n\t/**\n\t * Replaces a range of nodes in the current field by transferring them out to a new detached field\n\t * and transferring in all the nodes from an existing detached field in their place.\n\t * The number of nodes being detached must match the number of nodes being attached.\n\t * @param newContentSource - The detached field to transfer the new nodes from.\n\t * @param range - The bounds of the range of nodes to replace.\n\t * @param oldContentDestination - The key for a new detached field to transfer the old nodes to.\n\t */\n\treplace(newContentSource: FieldKey, range: Range, oldContentDestination: FieldKey): void;\n\n\t/**\n\t * Tells the visitor that it should update its \"current location\" to be the Node at the specified index\n\t * within the Field that is the current \"current location\".\n\t * Future calls to methods of {@link DeltaVisitor} will assume that's the location where their effects are happening.\n\t * @param index - The index (within the Field) of the node that should become the new \"current location\".\n\t *\n\t * @remarks This should only be called when the \"current location\" is a Field.\n\t */\n\tenterNode(index: NodeIndex): void;\n\n\t/**\n\t * Tells the visitor that it should update its \"current location\" to be the Field which contains the Node\n\t * that is the current \"current location\".\n\t * Future calls to methods of {@link DeltaVisitor} will assume that's the location where their effects are happening.\n\t * @param index - The index (within its Field) of the node that is being exited.\n\t *\n\t * @remarks This should only be called when the \"current location\" is a Node.\n\t */\n\texitNode(index: NodeIndex): void;\n\n\t/**\n\t * Tells the visitor that it should update its \"current location\" to be the Field with the specified key,\n\t * within the Node that is the current \"current location\".\n\t * Future calls to methods of {@link DeltaVisitor} will assume that's the location where their effects are happening.\n\t * @param key - The key of the field that should become the new \"current location\".\n\t *\n\t * @remarks This should only be called when the \"current location\" is a Node.\n\t */\n\tenterField(key: FieldKey): void;\n\n\t/**\n\t * Tells the visitor that it should update its \"current location\" to be the Node which contains the Field\n\t * that is the current \"current location\".\n\t * Future calls to methods of {@link DeltaVisitor} will assume that's the location where their effects are happening.\n\t * @param key - The key of the field that is being exited.\n\t *\n\t * @remarks This should only be called when the \"current location\" is a Field.\n\t */\n\texitField(key: FieldKey): void;\n}\n\ninterface PassConfig {\n\treadonly func: Pass;\n\n\t/**\n\t * The latest revision tag associated with the given delta. This is used to keep track\n\t * of when repair data should be garbage collected.\n\t */\n\treadonly latestRevision: RevisionTag | undefined;\n\n\treadonly detachedFieldIndex: DetachedFieldIndex;\n\t/**\n\t * A mapping between forest root id and trees that represent refresher data. Each entry is only\n\t * created in the forest once needed.\n\t */\n\treadonly refreshers: NestedMap<Major, Minor, ITreeCursorSynchronous>;\n\t/**\n\t * Nested changes on roots that need to be visited as part of the detach pass.\n\t * Each entry is removed when its associated changes are visited.\n\t */\n\treadonly detachPassRoots: Map<ForestRootId, Delta.FieldMap>;\n\t/**\n\t * Nested changes on roots that need to be visited as part of the attach pass.\n\t * Each entry is removed when its associated changes are visited.\n\t * Some of these roots will attached during the attach pass, in which case the nested changes are visited after\n\t * the node is attached.\n\t * Some of these nodes will never be attached, in which case we visit them in their detached fields at the end of\n\t * the attach pass. Note that such a visit might lead to more nodes being attached, including nodes were visited as\n\t * roots.\n\t */\n\treadonly attachPassRoots: Map<ForestRootId, Delta.FieldMap>;\n\t/**\n\t * Represents transfers of roots from one detached field to another.\n\t */\n\treadonly rootTransfers: Delta.DetachedNodeRename[];\n\t/**\n\t * Represents roots that need to be destroyed.\n\t * Collected as part of the detach pass.\n\t * Carried out at the end of the attach pass.\n\t */\n\treadonly rootDestructions: Delta.DetachedNodeDestruction[];\n}\n\ntype Pass = (delta: Delta.FieldChanges, visitor: DeltaVisitor, config: PassConfig) => void;\n\nfunction visitFieldMarks(\n\tfields: Delta.FieldMap | undefined,\n\tvisitor: DeltaVisitor,\n\tconfig: PassConfig,\n): void {\n\tif (fields !== undefined) {\n\t\tfor (const [key, field] of fields) {\n\t\t\tvisitor.enterField(key);\n\t\t\tconfig.func(field, visitor, config);\n\t\t\tvisitor.exitField(key);\n\t\t}\n\t}\n}\n\nfunction visitNode(\n\tindex: number,\n\tfields: Delta.FieldMap | undefined,\n\tvisitor: DeltaVisitor,\n\tconfig: PassConfig,\n): void {\n\tif (fields !== undefined) {\n\t\tvisitor.enterNode(index);\n\t\tvisitFieldMarks(fields, visitor, config);\n\t\tvisitor.exitNode(index);\n\t}\n}\n\n/**\n * Performs the following:\n * - Performs all root creations\n * - Collects all roots that may need a detach pass\n * - Collects all roots that may need an attach pass\n * - Collects all relocates\n * - Collects all destructions\n * - Executes detaches (bottom-up) provided they are not part of a replace\n * (because we want to wait until we are sure content to attach is available as a root)\n */\nfunction detachPass(\n\tdelta: Delta.FieldChanges,\n\tvisitor: DeltaVisitor,\n\tconfig: PassConfig,\n): void {\n\tif (delta.global !== undefined) {\n\t\tfor (const { id, fields } of delta.global) {\n\t\t\tlet root = config.detachedFieldIndex.tryGetEntry(id);\n\t\t\tif (root === undefined) {\n\t\t\t\tconst tree = tryGetFromNestedMap(config.refreshers, id.major, id.minor);\n\t\t\t\tassert(tree !== undefined, 0x928 /* refresher data not found */);\n\t\t\t\tbuildTrees(id, [tree], config.detachedFieldIndex, config.latestRevision, visitor);\n\t\t\t\troot = config.detachedFieldIndex.getEntry(id);\n\t\t\t}\n\t\t\t// the revision is updated for any refresher data included in the delta that is used\n\t\t\tconfig.detachedFieldIndex.updateLatestRevision(id, config.latestRevision);\n\t\t\tconfig.detachPassRoots.set(root, fields);\n\t\t\tconfig.attachPassRoots.set(root, fields);\n\t\t}\n\t}\n\tif (delta.rename !== undefined) {\n\t\tconfig.rootTransfers.push(...delta.rename);\n\t}\n\tif (delta.local !== undefined) {\n\t\tlet index = 0;\n\t\tfor (const mark of delta.local) {\n\t\t\tif (mark.fields !== undefined) {\n\t\t\t\tassert(\n\t\t\t\t\tmark.attach === undefined || mark.detach !== undefined,\n\t\t\t\t\t0x7d0 /* Invalid nested changes on an additive mark */,\n\t\t\t\t);\n\t\t\t\tvisitNode(index, mark.fields, visitor, config);\n\t\t\t}\n\t\t\tif (isDetachMark(mark)) {\n\t\t\t\tfor (let i = 0; i < mark.count; i += 1) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\tconst id = offsetDetachId(mark.detach!, i);\n\t\t\t\t\tconst root = config.detachedFieldIndex.createEntry(id, config.latestRevision);\n\t\t\t\t\tif (mark.fields !== undefined) {\n\t\t\t\t\t\tconfig.attachPassRoots.set(root, mark.fields);\n\t\t\t\t\t}\n\t\t\t\t\tconst field = config.detachedFieldIndex.toFieldKey(root);\n\t\t\t\t\tvisitor.detach({ start: index, end: index + 1 }, field);\n\t\t\t\t}\n\t\t\t} else if (!isAttachMark(mark)) {\n\t\t\t\tindex += mark.count;\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction buildTrees(\n\tid: Delta.DetachedNodeId,\n\ttrees: readonly ITreeCursorSynchronous[],\n\tdetachedFieldIndex: DetachedFieldIndex,\n\tlatestRevision: RevisionTag | undefined,\n\tvisitor: DeltaVisitor,\n): void {\n\tfor (const [i, tree] of trees.entries()) {\n\t\tconst offsettedId = offsetDetachId(id, i);\n\t\tlet root = detachedFieldIndex.tryGetEntry(offsettedId);\n\t\tassert(root === undefined, 0x929 /* Unable to build tree that already exists */);\n\t\troot = detachedFieldIndex.createEntry(offsettedId, latestRevision);\n\t\tconst field = detachedFieldIndex.toFieldKey(root);\n\t\tvisitor.create([tree], field);\n\t}\n}\n\nfunction processBuilds(\n\tbuilds: readonly Delta.DetachedNodeBuild[] | undefined,\n\tconfig: PassConfig,\n\tvisitor: DeltaVisitor,\n): void {\n\tif (builds !== undefined) {\n\t\tfor (const { id, trees } of builds) {\n\t\t\tbuildTrees(id, trees, config.detachedFieldIndex, config.latestRevision, visitor);\n\t\t}\n\t}\n}\n\nfunction collectDestroys(\n\tdestroys: readonly Delta.DetachedNodeDestruction[] | undefined,\n\tconfig: PassConfig,\n): void {\n\tif (destroys !== undefined) {\n\t\tconfig.rootDestructions.push(...destroys);\n\t}\n}\n\n/**\n * Preforms the following:\n * - Executes attaches (top-down) applying nested changes on the attached nodes\n * - Executes replaces (top-down) applying nested changes on the attached nodes\n * - Collects detached roots (from replaces) that need an attach pass\n */\nfunction attachPass(\n\tdelta: Delta.FieldChanges,\n\tvisitor: DeltaVisitor,\n\tconfig: PassConfig,\n): void {\n\tif (delta.local !== undefined) {\n\t\tlet index = 0;\n\t\tfor (const mark of delta.local) {\n\t\t\tif (isAttachMark(mark) || isReplaceMark(mark)) {\n\t\t\t\tfor (let i = 0; i < mark.count; i += 1) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\tconst offsetAttachId = offsetDetachId(mark.attach!, i);\n\t\t\t\t\tlet sourceRoot = config.detachedFieldIndex.tryGetEntry(offsetAttachId);\n\t\t\t\t\tif (sourceRoot === undefined) {\n\t\t\t\t\t\tconst tree = tryGetFromNestedMap(\n\t\t\t\t\t\t\tconfig.refreshers,\n\t\t\t\t\t\t\toffsetAttachId.major,\n\t\t\t\t\t\t\toffsetAttachId.minor,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tassert(tree !== undefined, 0x92a /* refresher data not found */);\n\t\t\t\t\t\tbuildTrees(\n\t\t\t\t\t\t\toffsetAttachId,\n\t\t\t\t\t\t\t[tree],\n\t\t\t\t\t\t\tconfig.detachedFieldIndex,\n\t\t\t\t\t\t\tconfig.latestRevision,\n\t\t\t\t\t\t\tvisitor,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tsourceRoot = config.detachedFieldIndex.getEntry(offsetAttachId);\n\t\t\t\t\t}\n\t\t\t\t\tconst sourceField = config.detachedFieldIndex.toFieldKey(sourceRoot);\n\t\t\t\t\tconst offsetIndex = index + i;\n\t\t\t\t\tif (isReplaceMark(mark)) {\n\t\t\t\t\t\tconst rootDestination = config.detachedFieldIndex.createEntry(\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\t\toffsetDetachId(mark.detach!, i),\n\t\t\t\t\t\t\tconfig.latestRevision,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst destinationField = config.detachedFieldIndex.toFieldKey(rootDestination);\n\t\t\t\t\t\tvisitor.replace(\n\t\t\t\t\t\t\tsourceField,\n\t\t\t\t\t\t\t{ start: offsetIndex, end: offsetIndex + 1 },\n\t\t\t\t\t\t\tdestinationField,\n\t\t\t\t\t\t);\n\t\t\t\t\t\t// We may need to do a second pass on the detached nodes\n\t\t\t\t\t\tif (mark.fields !== undefined) {\n\t\t\t\t\t\t\tconfig.attachPassRoots.set(rootDestination, mark.fields);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// This a simple attach\n\t\t\t\t\t\tvisitor.attach(sourceField, 1, offsetIndex);\n\t\t\t\t\t}\n\t\t\t\t\tconfig.detachedFieldIndex.deleteEntry(offsetAttachId);\n\t\t\t\t\tconst fields = config.attachPassRoots.get(sourceRoot);\n\t\t\t\t\tif (fields !== undefined) {\n\t\t\t\t\t\tconfig.attachPassRoots.delete(sourceRoot);\n\t\t\t\t\t\tvisitNode(offsetIndex, fields, visitor, config);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (!isDetachMark(mark) && mark.fields !== undefined) {\n\t\t\t\tvisitNode(index, mark.fields, visitor, config);\n\t\t\t}\n\t\t\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KAAK,SAAS,EAAE,CAAC;gBAC7D,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;YAChD,CAAC;YACD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzB,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC;YACrB,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport { type NestedMap, setInNestedMap, tryGetFromNestedMap } from \"../../util/index.js\";\nimport type { FieldKey } from \"../schema-stored/index.js\";\n\nimport type { ITreeCursorSynchronous } from \"./cursor.js\";\n// eslint-disable-next-line import/no-duplicates\nimport type * as Delta from \"./delta.js\";\n// Since ProtoNodes is reexported, import it directly to avoid forcing Delta to be reexported.\n// eslint-disable-next-line import/no-duplicates\nimport type { ProtoNodes } from \"./delta.js\";\nimport {\n\tareDetachedNodeIdsEqual,\n\tisAttachMark,\n\tisDetachMark,\n\tisReplaceMark,\n\toffsetDetachId,\n} from \"./deltaUtil.js\";\nimport type { DetachedFieldIndex } from \"./detachedFieldIndex.js\";\nimport type { ForestRootId, Major, Minor } from \"./detachedFieldIndexTypes.js\";\nimport type { NodeIndex, PlaceIndex, Range } from \"./pathTree.js\";\nimport type { RevisionTag } from \"../index.js\";\n\n/**\n * Implementation notes:\n *\n * The visit is organized into four phases:\n * 1. a detach pass\n * 2. root transfers\n * 3. an attach pass\n * 4. root destructions\n *\n * The core idea is that before content can be attached, it must first exist and be in a detached field.\n * The detach pass is therefore responsible for making sure that all roots that needs to be attached during the\n * attach pass are detached.\n * In practice, this means the detach pass must:\n * - Create all subtrees that need to be created\n * - Detach all moved nodes\n *\n * In addition to that, the detach pass also detaches nodes that need removing, with the exception of nodes that get\n * replaced. The reason for this exception is that we need to be able to communicate replaces as atomic operations.\n * In order to do that, we need to wait until we are sure that the content to attach is available as a detached root.\n * Replaces are therefore handled during the attach pass.\n * Note that this could theoretically lead to a situation where, in the attach pass, one replace wants to attach\n * a node that has yet to be detached by another replace. This does not occur in practice because we do not support\n * editing operations that would lead to this situation.\n *\n * While the detach pass ensures that nodes to be attached are in a detached state, it does not guarantee that they\n * reside in the correct detach field. That is the responsibility of the root transfers phase.\n *\n * The attach phase carries out attaches and replaces.\n *\n * After the attach phase, roots destruction is carried out.\n * This needs to happen last to allow modifications to detached roots to be applied before they are destroyed.\n *\n * The details of the delta visit algorithm can impact how/when events are emitted by the objects that own the visitors.\n * For example, as of 2024-03-27, the subtreecChanged event of an AnchorNode is emitted when exiting a node during a\n * delta visit, and thus the two-pass nature of the algorithm means the event fires twice for any given change.\n * This two-pass nature also means that the event may fire at a time where no change is visible in the tree. E.g.,\n * if a node is being replaced, when the event fires during the detach pass no change in the tree has happened so the\n * listener won't see any; then when it fires during the attach pass, the change will be visible in the event listener.\n */\n\n/**\n * Crawls the given `delta`, calling `visitor`'s callback for each change encountered.\n * Each successive call to the visitor callbacks assumes that the change described by earlier calls have been applied\n * to the document tree. For example, for a change that removes the first and third node of a field, the visitor calls\n * will first call detach with a range from indices 0 to 1 then call detach with a range from indices 1 to 2.\n *\n * @param delta - The delta to be crawled.\n * @param visitor - The object to notify of the changes encountered.\n * @param detachedFieldIndex - Index responsible for keeping track of the existing detached fields.\n * @param latestRevision - The latest revision tag associated with this delta.\n */\nexport function visitDelta(\n\tdelta: Delta.Root,\n\tvisitor: DeltaVisitor,\n\tdetachedFieldIndex: DetachedFieldIndex,\n\tlatestRevision: RevisionTag | undefined,\n): void {\n\tconst detachPassRoots: Map<ForestRootId, Delta.FieldMap> = new Map();\n\tconst attachPassRoots: Map<ForestRootId, Delta.FieldMap> = new Map();\n\tconst rootTransfers: Delta.DetachedNodeRename[] = [];\n\tconst rootDestructions: Delta.DetachedNodeDestruction[] = [];\n\tconst refreshers: NestedMap<Major, Minor, ITreeCursorSynchronous> = new Map();\n\tdelta.refreshers?.forEach(({ id: { major, minor }, trees }) => {\n\t\tfor (let i = 0; i < trees.length; i += 1) {\n\t\t\tconst offsettedId = minor + i;\n\t\t\tsetInNestedMap(refreshers, major, offsettedId, trees[i]);\n\t\t}\n\t});\n\tconst detachConfig: PassConfig = {\n\t\tfunc: detachPass,\n\t\tlatestRevision,\n\t\trefreshers,\n\t\tdetachedFieldIndex,\n\t\tdetachPassRoots,\n\t\tattachPassRoots,\n\t\trootTransfers,\n\t\trootDestructions,\n\t};\n\tprocessBuilds(delta.build, detachConfig, visitor);\n\tvisitFieldMarks(delta.fields, visitor, detachConfig);\n\tfixedPointVisitOfRoots(visitor, detachPassRoots, detachConfig);\n\ttransferRoots(\n\t\trootTransfers,\n\t\tattachPassRoots,\n\t\tdetachedFieldIndex,\n\t\tvisitor,\n\t\trefreshers,\n\t\tlatestRevision,\n\t);\n\tconst attachConfig: PassConfig = {\n\t\tfunc: attachPass,\n\t\tlatestRevision,\n\t\trefreshers,\n\t\tdetachedFieldIndex,\n\t\tdetachPassRoots,\n\t\tattachPassRoots,\n\t\trootTransfers,\n\t\trootDestructions,\n\t};\n\tvisitFieldMarks(delta.fields, visitor, attachConfig);\n\tfixedPointVisitOfRoots(visitor, attachPassRoots, attachConfig);\n\tcollectDestroys(delta.destroy, attachConfig);\n\tfor (const { id, count } of rootDestructions) {\n\t\tfor (let i = 0; i < count; i += 1) {\n\t\t\tconst offsetId = offsetDetachId(id, i);\n\t\t\tconst root = detachedFieldIndex.getEntry(offsetId);\n\t\t\tconst field = detachedFieldIndex.toFieldKey(root);\n\t\t\tvisitor.destroy(field, 1);\n\t\t\tdetachedFieldIndex.deleteEntry(offsetId);\n\t\t}\n\t}\n}\n\n/**\n * Visits all nodes in `roots` until none are left.\n * This function tolerates entries being added to and removed from `roots` as part of visits.\n * @param visitor - The visitor to visit the roots with.\n * @param roots - The initial set of roots to visit.\n * Individual entries are removed prior to being visited.\n * @param config - The configuration to use for visits.\n */\nfunction fixedPointVisitOfRoots(\n\tvisitor: DeltaVisitor,\n\troots: Map<ForestRootId, Delta.FieldMap>,\n\tconfig: PassConfig,\n): void {\n\twhile (roots.size > 0) {\n\t\tfor (const [root, modifications] of roots) {\n\t\t\troots.delete(root);\n\t\t\tconst field = config.detachedFieldIndex.toFieldKey(root);\n\t\t\tvisitor.enterField(field);\n\t\t\t// Note: each visit may lead to `roots` being populated with new entries or having some entries removed.\n\t\t\tvisitNode(0, modifications, visitor, config);\n\t\t\tvisitor.exitField(field);\n\t\t}\n\t}\n}\n\n/**\n * Transfers roots from one detached field to another.\n * This occurs in the following circumstances:\n * - A changeset moves then removes a node\n * - A changeset restores then moves a node\n * - A changeset restores then removes a node\n * TODO#5481: update the DetachedFieldIndex instead of moving the nodes around.\n *\n * @param rootTransfers - The transfers to perform.\n * @param mapToUpdate - A map to update based on the transfers being performed.\n * @param detachedFieldIndex - The index to update based on the transfers being performed.\n * @param visitor - The visitor to inform of the transfers being performed.\n */\nfunction transferRoots(\n\trootTransfers: readonly Delta.DetachedNodeRename[],\n\tmapToUpdate: Map<ForestRootId, unknown>,\n\tdetachedFieldIndex: DetachedFieldIndex,\n\tvisitor: DeltaVisitor,\n\trefreshers: NestedMap<Major, Minor, ITreeCursorSynchronous>,\n\trevision?: RevisionTag,\n): void {\n\ttype AtomizedNodeRename = Omit<Delta.DetachedNodeRename, \"count\">;\n\tlet nextBatch = rootTransfers.flatMap(({ oldId, newId, count }) => {\n\t\tconst atomized: AtomizedNodeRename[] = [];\n\t\t// It's possible for a detached node to be revived transiently such that it ends up back in the same detached field.\n\t\t// Making such a transfer wouldn't just be inefficient, it would lead us to mistakenly think we have moved all content\n\t\t// out of the source detached field, and would lead us to delete the tree index entry for that source detached field.\n\t\t// This would effectively result in the tree index missing an entry for the detached field.\n\t\t// This if statement prevents that from happening.\n\t\tif (!areDetachedNodeIdsEqual(oldId, newId)) {\n\t\t\tfor (let i = 0; i < count; i += 1) {\n\t\t\t\tatomized.push({ oldId: offsetDetachId(oldId, i), newId: offsetDetachId(newId, i) });\n\t\t\t}\n\t\t}\n\t\treturn atomized;\n\t});\n\twhile (nextBatch.length > 0) {\n\t\tconst delayed: AtomizedNodeRename[] = [];\n\t\tconst priorSize = nextBatch.length;\n\t\tfor (const { oldId, newId } of nextBatch) {\n\t\t\tlet oldRootId = detachedFieldIndex.tryGetEntry(oldId);\n\t\t\tif (oldRootId === undefined) {\n\t\t\t\tconst tree = tryGetFromNestedMap(refreshers, oldId.major, oldId.minor);\n\t\t\t\tif (tree !== undefined) {\n\t\t\t\t\tbuildTrees(oldId, [tree], detachedFieldIndex, revision, visitor);\n\t\t\t\t\toldRootId = detachedFieldIndex.getEntry(oldId);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (oldRootId === undefined) {\n\t\t\t\t// The source field is not populated.\n\t\t\t\t// This can happen when another rename needs to be performed first.\n\t\t\t\tdelayed.push({ oldId, newId });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlet newRootId = detachedFieldIndex.tryGetEntry(newId);\n\t\t\tif (newRootId !== undefined) {\n\t\t\t\t// The destination field is already occupied.\n\t\t\t\t// This can happen when another rename needs to be performed first.\n\t\t\t\tdelayed.push({ oldId, newId });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tnewRootId = detachedFieldIndex.createEntry(newId, revision);\n\t\t\tconst fields = mapToUpdate.get(oldRootId);\n\t\t\tif (fields !== undefined) {\n\t\t\t\tmapToUpdate.delete(oldRootId);\n\t\t\t\tmapToUpdate.set(newRootId, fields);\n\t\t\t}\n\t\t\tconst oldField = detachedFieldIndex.toFieldKey(oldRootId);\n\t\t\tconst newField = detachedFieldIndex.toFieldKey(newRootId);\n\t\t\tvisitor.enterField(oldField);\n\t\t\tvisitor.detach({ start: 0, end: 1 }, newField);\n\t\t\tvisitor.exitField(oldField);\n\t\t\tdetachedFieldIndex.deleteEntry(oldId);\n\t\t}\n\t\tassert(delayed.length < priorSize, 0x7cf /* transferRoots should make progress */);\n\t\tnextBatch = delayed;\n\t}\n}\n\n/**\n * Visitor for changes in a delta.\n * Must be freed after use.\n */\nexport interface DeltaVisitor {\n\t/**\n\t * Frees/releases the visitor.\n\t *\n\t * Must be called once the visitor finished traversing the delta for a couple of reasons:\n\t *\n\t * 1. Some visitors, such as those from forests, are put into a special mode while they have a visitor, forbidding some actions (like making more visitors).\n\t *\n\t * 2. Some visitors, such as those from an anchorSet, defer some events for batching purposes until the visitor is freed.\n\t */\n\tfree(): void;\n\t/**\n\t * Creates nodes for the given content in a new detached field.\n\t * @param content - The content to create.\n\t * @param destination - The key for a new detached field.\n\t * A field with this key must not already exist.\n\t */\n\tcreate(content: ProtoNodes, destination: FieldKey): void;\n\t/**\n\t * Recursively destroys the given detached field and all of the nodes within it.\n\t * @param detachedField - The key for the detached field to destroy.\n\t * @param count - The number of nodes being destroyed.\n\t * Expected to match the number of nodes in the detached field being destroyed.\n\t */\n\tdestroy(detachedField: FieldKey, count: number): void;\n\t/**\n\t * Transfers all the nodes from a detached field to the current field.\n\t * @param source - The detached field to transfer the nodes from.\n\t * @param count - The number of nodes being attached.\n\t * Expected to match the number of nodes in the source detached field.\n\t * @param destination - The index at which to attach the nodes.\n\t */\n\tattach(source: FieldKey, count: number, destination: PlaceIndex): void;\n\t/**\n\t * Transfers a range of nodes from the current field to a new detached field.\n\t * @param source - The bounds of the range of nodes to detach.\n\t * @param destination - The key for a new detached field.\n\t * A field with this key must not already exist.\n\t */\n\tdetach(source: Range, destination: FieldKey): void;\n\t/**\n\t * Replaces a range of nodes in the current field by transferring them out to a new detached field\n\t * and transferring in all the nodes from an existing detached field in their place.\n\t * The number of nodes being detached must match the number of nodes being attached.\n\t * @param newContentSource - The detached field to transfer the new nodes from.\n\t * @param range - The bounds of the range of nodes to replace.\n\t * @param oldContentDestination - The key for a new detached field to transfer the old nodes to.\n\t */\n\treplace(newContentSource: FieldKey, range: Range, oldContentDestination: FieldKey): void;\n\n\t/**\n\t * Tells the visitor that it should update its \"current location\" to be the Node at the specified index\n\t * within the Field that is the current \"current location\".\n\t * Future calls to methods of {@link DeltaVisitor} will assume that's the location where their effects are happening.\n\t * @param index - The index (within the Field) of the node that should become the new \"current location\".\n\t *\n\t * @remarks This should only be called when the \"current location\" is a Field.\n\t */\n\tenterNode(index: NodeIndex): void;\n\n\t/**\n\t * Tells the visitor that it should update its \"current location\" to be the Field which contains the Node\n\t * that is the current \"current location\".\n\t * Future calls to methods of {@link DeltaVisitor} will assume that's the location where their effects are happening.\n\t * @param index - The index (within its Field) of the node that is being exited.\n\t *\n\t * @remarks This should only be called when the \"current location\" is a Node.\n\t */\n\texitNode(index: NodeIndex): void;\n\n\t/**\n\t * Tells the visitor that it should update its \"current location\" to be the Field with the specified key,\n\t * within the Node that is the current \"current location\".\n\t * Future calls to methods of {@link DeltaVisitor} will assume that's the location where their effects are happening.\n\t * @param key - The key of the field that should become the new \"current location\".\n\t *\n\t * @remarks This should only be called when the \"current location\" is a Node.\n\t */\n\tenterField(key: FieldKey): void;\n\n\t/**\n\t * Tells the visitor that it should update its \"current location\" to be the Node which contains the Field\n\t * that is the current \"current location\".\n\t * Future calls to methods of {@link DeltaVisitor} will assume that's the location where their effects are happening.\n\t * @param key - The key of the field that is being exited.\n\t *\n\t * @remarks This should only be called when the \"current location\" is a Field.\n\t */\n\texitField(key: FieldKey): void;\n}\n\ninterface PassConfig {\n\treadonly func: Pass;\n\n\t/**\n\t * The latest revision tag associated with the given delta. This is used to keep track\n\t * of when repair data should be garbage collected.\n\t */\n\treadonly latestRevision: RevisionTag | undefined;\n\n\treadonly detachedFieldIndex: DetachedFieldIndex;\n\t/**\n\t * A mapping between forest root id and trees that represent refresher data. Each entry is only\n\t * created in the forest once needed.\n\t */\n\treadonly refreshers: NestedMap<Major, Minor, ITreeCursorSynchronous>;\n\t/**\n\t * Nested changes on roots that need to be visited as part of the detach pass.\n\t * Each entry is removed when its associated changes are visited.\n\t */\n\treadonly detachPassRoots: Map<ForestRootId, Delta.FieldMap>;\n\t/**\n\t * Nested changes on roots that need to be visited as part of the attach pass.\n\t * Each entry is removed when its associated changes are visited.\n\t * Some of these roots will attached during the attach pass, in which case the nested changes are visited after\n\t * the node is attached.\n\t * Some of these nodes will never be attached, in which case we visit them in their detached fields at the end of\n\t * the attach pass. Note that such a visit might lead to more nodes being attached, including nodes were visited as\n\t * roots.\n\t */\n\treadonly attachPassRoots: Map<ForestRootId, Delta.FieldMap>;\n\t/**\n\t * Represents transfers of roots from one detached field to another.\n\t */\n\treadonly rootTransfers: Delta.DetachedNodeRename[];\n\t/**\n\t * Represents roots that need to be destroyed.\n\t * Collected as part of the detach pass.\n\t * Carried out at the end of the attach pass.\n\t */\n\treadonly rootDestructions: Delta.DetachedNodeDestruction[];\n}\n\ntype Pass = (delta: Delta.FieldChanges, visitor: DeltaVisitor, config: PassConfig) => void;\n\nfunction visitFieldMarks(\n\tfields: Delta.FieldMap | undefined,\n\tvisitor: DeltaVisitor,\n\tconfig: PassConfig,\n): void {\n\tif (fields !== undefined) {\n\t\tfor (const [key, field] of fields) {\n\t\t\tvisitor.enterField(key);\n\t\t\tconfig.func(field, visitor, config);\n\t\t\tvisitor.exitField(key);\n\t\t}\n\t}\n}\n\nfunction visitNode(\n\tindex: number,\n\tfields: Delta.FieldMap | undefined,\n\tvisitor: DeltaVisitor,\n\tconfig: PassConfig,\n): void {\n\tif (fields !== undefined) {\n\t\tvisitor.enterNode(index);\n\t\tvisitFieldMarks(fields, visitor, config);\n\t\tvisitor.exitNode(index);\n\t}\n}\n\n/**\n * Performs the following:\n * - Performs all root creations\n * - Collects all roots that may need a detach pass\n * - Collects all roots that may need an attach pass\n * - Collects all relocates\n * - Collects all destructions\n * - Executes detaches (bottom-up) provided they are not part of a replace\n * (because we want to wait until we are sure content to attach is available as a root)\n */\nfunction detachPass(\n\tdelta: Delta.FieldChanges,\n\tvisitor: DeltaVisitor,\n\tconfig: PassConfig,\n): void {\n\tif (delta.global !== undefined) {\n\t\tfor (const { id, fields } of delta.global) {\n\t\t\tlet root = config.detachedFieldIndex.tryGetEntry(id);\n\t\t\tif (root === undefined) {\n\t\t\t\tconst tree = tryGetFromNestedMap(config.refreshers, id.major, id.minor);\n\t\t\t\tassert(tree !== undefined, 0x928 /* refresher data not found */);\n\t\t\t\tbuildTrees(id, [tree], config.detachedFieldIndex, config.latestRevision, visitor);\n\t\t\t\troot = config.detachedFieldIndex.getEntry(id);\n\t\t\t}\n\t\t\t// the revision is updated for any refresher data included in the delta that is used\n\t\t\tconfig.detachedFieldIndex.updateLatestRevision(id, config.latestRevision);\n\t\t\tconfig.detachPassRoots.set(root, fields);\n\t\t\tconfig.attachPassRoots.set(root, fields);\n\t\t}\n\t}\n\tif (delta.rename !== undefined) {\n\t\tconfig.rootTransfers.push(...delta.rename);\n\t}\n\tif (delta.local !== undefined) {\n\t\tlet index = 0;\n\t\tfor (const mark of delta.local) {\n\t\t\tif (mark.fields !== undefined) {\n\t\t\t\tassert(\n\t\t\t\t\tmark.attach === undefined || mark.detach !== undefined,\n\t\t\t\t\t0x7d0 /* Invalid nested changes on an additive mark */,\n\t\t\t\t);\n\t\t\t\tvisitNode(index, mark.fields, visitor, config);\n\t\t\t}\n\t\t\tif (isDetachMark(mark)) {\n\t\t\t\tfor (let i = 0; i < mark.count; i += 1) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\tconst id = offsetDetachId(mark.detach!, i);\n\t\t\t\t\tconst root = config.detachedFieldIndex.createEntry(id, config.latestRevision);\n\t\t\t\t\tif (mark.fields !== undefined) {\n\t\t\t\t\t\tconfig.attachPassRoots.set(root, mark.fields);\n\t\t\t\t\t}\n\t\t\t\t\tconst field = config.detachedFieldIndex.toFieldKey(root);\n\t\t\t\t\tvisitor.detach({ start: index, end: index + 1 }, field);\n\t\t\t\t}\n\t\t\t} else if (!isAttachMark(mark)) {\n\t\t\t\tindex += mark.count;\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction buildTrees(\n\tid: Delta.DetachedNodeId,\n\ttrees: readonly ITreeCursorSynchronous[],\n\tdetachedFieldIndex: DetachedFieldIndex,\n\tlatestRevision: RevisionTag | undefined,\n\tvisitor: DeltaVisitor,\n): void {\n\tfor (const [i, tree] of trees.entries()) {\n\t\tconst offsettedId = offsetDetachId(id, i);\n\t\tlet root = detachedFieldIndex.tryGetEntry(offsettedId);\n\t\tassert(root === undefined, 0x929 /* Unable to build tree that already exists */);\n\t\troot = detachedFieldIndex.createEntry(offsettedId, latestRevision);\n\t\tconst field = detachedFieldIndex.toFieldKey(root);\n\t\tvisitor.create([tree], field);\n\t}\n}\n\nfunction processBuilds(\n\tbuilds: readonly Delta.DetachedNodeBuild[] | undefined,\n\tconfig: PassConfig,\n\tvisitor: DeltaVisitor,\n): void {\n\tif (builds !== undefined) {\n\t\tfor (const { id, trees } of builds) {\n\t\t\tbuildTrees(id, trees, config.detachedFieldIndex, config.latestRevision, visitor);\n\t\t}\n\t}\n}\n\nfunction collectDestroys(\n\tdestroys: readonly Delta.DetachedNodeDestruction[] | undefined,\n\tconfig: PassConfig,\n): void {\n\tif (destroys !== undefined) {\n\t\tconfig.rootDestructions.push(...destroys);\n\t}\n}\n\n/**\n * Preforms the following:\n * - Executes attaches (top-down) applying nested changes on the attached nodes\n * - Executes replaces (top-down) applying nested changes on the attached nodes\n * - Collects detached roots (from replaces) that need an attach pass\n */\nfunction attachPass(\n\tdelta: Delta.FieldChanges,\n\tvisitor: DeltaVisitor,\n\tconfig: PassConfig,\n): void {\n\tif (delta.local !== undefined) {\n\t\tlet index = 0;\n\t\tfor (const mark of delta.local) {\n\t\t\tif (isAttachMark(mark) || isReplaceMark(mark)) {\n\t\t\t\tfor (let i = 0; i < mark.count; i += 1) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\tconst offsetAttachId = offsetDetachId(mark.attach!, i);\n\t\t\t\t\tlet sourceRoot = config.detachedFieldIndex.tryGetEntry(offsetAttachId);\n\t\t\t\t\tif (sourceRoot === undefined) {\n\t\t\t\t\t\tconst tree = tryGetFromNestedMap(\n\t\t\t\t\t\t\tconfig.refreshers,\n\t\t\t\t\t\t\toffsetAttachId.major,\n\t\t\t\t\t\t\toffsetAttachId.minor,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tassert(tree !== undefined, 0x92a /* refresher data not found */);\n\t\t\t\t\t\tbuildTrees(\n\t\t\t\t\t\t\toffsetAttachId,\n\t\t\t\t\t\t\t[tree],\n\t\t\t\t\t\t\tconfig.detachedFieldIndex,\n\t\t\t\t\t\t\tconfig.latestRevision,\n\t\t\t\t\t\t\tvisitor,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tsourceRoot = config.detachedFieldIndex.getEntry(offsetAttachId);\n\t\t\t\t\t}\n\t\t\t\t\tconst sourceField = config.detachedFieldIndex.toFieldKey(sourceRoot);\n\t\t\t\t\tconst offsetIndex = index + i;\n\t\t\t\t\tif (isReplaceMark(mark)) {\n\t\t\t\t\t\tconst rootDestination = config.detachedFieldIndex.createEntry(\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\t\toffsetDetachId(mark.detach!, i),\n\t\t\t\t\t\t\tconfig.latestRevision,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst destinationField = config.detachedFieldIndex.toFieldKey(rootDestination);\n\t\t\t\t\t\tvisitor.replace(\n\t\t\t\t\t\t\tsourceField,\n\t\t\t\t\t\t\t{ start: offsetIndex, end: offsetIndex + 1 },\n\t\t\t\t\t\t\tdestinationField,\n\t\t\t\t\t\t);\n\t\t\t\t\t\t// We may need to do a second pass on the detached nodes\n\t\t\t\t\t\tif (mark.fields !== undefined) {\n\t\t\t\t\t\t\tconfig.attachPassRoots.set(rootDestination, mark.fields);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// This a simple attach\n\t\t\t\t\t\tvisitor.attach(sourceField, 1, offsetIndex);\n\t\t\t\t\t}\n\t\t\t\t\tconfig.detachedFieldIndex.deleteEntry(offsetAttachId);\n\t\t\t\t\tconst fields = config.attachPassRoots.get(sourceRoot);\n\t\t\t\t\tif (fields !== undefined) {\n\t\t\t\t\t\tconfig.attachPassRoots.delete(sourceRoot);\n\t\t\t\t\t\tvisitNode(offsetIndex, fields, visitor, config);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (!isDetachMark(mark) && mark.fields !== undefined) {\n\t\t\t\tvisitNode(index, mark.fields, visitor, config);\n\t\t\t}\n\t\t\tif (!isDetachMark(mark)) {\n\t\t\t\tindex += mark.count;\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,127 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import type { Listenable, Listeners, Off } from "./listeners.js";
6
+ /**
7
+ * Interface for an event emitter that can emit typed events to subscribed listeners.
8
+ */
9
+ export interface IEmitter<TListeners extends Listeners<TListeners>> {
10
+ /**
11
+ * Emits an event with the specified name and arguments, notifying all subscribers by calling their registered listener functions.
12
+ * @param eventName - the name of the event to fire
13
+ * @param args - the arguments passed to the event listener functions
14
+ */
15
+ emit<K extends keyof Listeners<TListeners>>(eventName: K, ...args: Parameters<TListeners[K]>): void;
16
+ /**
17
+ * Emits an event with the specified name and arguments, notifying all subscribers by calling their registered listener functions.
18
+ * It also collects the return values of all listeners into an array.
19
+ *
20
+ * Warning: This method should be used with caution. It deviates from the standard event-based integration pattern as creates substantial coupling between the emitter and its listeners.
21
+ * For the majority of use-cases it is recommended to use the standard {@link IEmitter.emit} functionality.
22
+ * @param eventName - the name of the event to fire
23
+ * @param args - the arguments passed to the event listener functions
24
+ * @returns An array of the return values of each listener, preserving the order listeners were called.
25
+ */
26
+ emitAndCollect<K extends keyof Listeners<TListeners>>(eventName: K, ...args: Parameters<TListeners[K]>): ReturnType<TListeners[K]>[];
27
+ }
28
+ /**
29
+ * Called when the last listener for `eventName` is removed.
30
+ * Useful for determining when to clean up resources related to detecting when the event might occurs.
31
+ */
32
+ export type NoListenersCallback<TListeners extends object> = (eventName: keyof Listeners<TListeners>) => void;
33
+ /**
34
+ * Allows querying if an object has listeners.
35
+ * @sealed
36
+ */
37
+ export interface HasListeners<TListeners extends Listeners<TListeners>> {
38
+ /**
39
+ * When no `eventName` is provided, returns true iff there are any listeners.
40
+ *
41
+ * When `eventName` is provided, returns true iff there are listeners for that event.
42
+ *
43
+ * @remarks
44
+ * This can be used to know when its safe to cleanup data-structures which only exist to fire events for their listeners.
45
+ */
46
+ hasListeners(eventName?: keyof Listeners<TListeners>): boolean;
47
+ }
48
+ /**
49
+ * Provides an API for subscribing to and listening to events.
50
+ *
51
+ * @remarks Classes wishing to emit events may either extend this class or compose over it.
52
+ *
53
+ * @example Extending this class
54
+ *
55
+ * ```typescript
56
+ * interface MyEvents {
57
+ * loaded: () => void;
58
+ * computed: () => number;
59
+ * }
60
+ *
61
+ * class MyInheritanceClass extends EventEmitter<MyEvents> {
62
+ * private load() {
63
+ * this.emit("loaded");
64
+ * const results: number[] = this.emitAndCollect("computed");
65
+ * }
66
+ * }
67
+ * ```
68
+ *
69
+ * @example Composing over this class
70
+ *
71
+ * ```typescript
72
+ * class MyCompositionClass implements Listenable<MyEvents> {
73
+ * private readonly events = createEmitter<MyEvents>();
74
+ *
75
+ * private load() {
76
+ * this.events.emit("loaded");
77
+ * const results: number[] = this.events.emitAndCollect("computed");
78
+ * }
79
+ *
80
+ * public on<K extends keyof MyEvents>(eventName: K, listener: MyEvents[K]): () => void {
81
+ * return this.events.on(eventName, listener);
82
+ * }
83
+ * }
84
+ * ```
85
+ */
86
+ export declare class EventEmitter<TListeners extends Listeners<TListeners>> implements Listenable<TListeners>, HasListeners<TListeners> {
87
+ private readonly noListeners?;
88
+ protected readonly listeners: Map<keyof TListeners, Map<Off, (...args: any[]) => TListeners[keyof TListeners]>>;
89
+ protected constructor(noListeners?: NoListenersCallback<TListeners> | undefined);
90
+ protected emit<K extends keyof TListeners>(eventName: K, ...args: Parameters<TListeners[K]>): void;
91
+ protected emitAndCollect<K extends keyof TListeners>(eventName: K, ...args: Parameters<TListeners[K]>): ReturnType<TListeners[K]>[];
92
+ /**
93
+ * Register an event listener.
94
+ * @param eventName - the name of the event
95
+ * @param listener - the handler to run when the event is fired by the emitter
96
+ * @returns a function which will deregister the listener when run.
97
+ * This function will error if called more than once.
98
+ */
99
+ on<K extends keyof Listeners<TListeners>>(eventName: K, listener: TListeners[K]): Off;
100
+ hasListeners(eventName?: keyof TListeners): boolean;
101
+ }
102
+ /**
103
+ * Create a {@link Listenable} that can be instructed to emit events via the {@link IEmitter} interface.
104
+ *
105
+ * A class can delegate handling {@link Listenable} to the returned value while using it to emit the events.
106
+ * See also {@link EventEmitter} which be used as a base class to implement {@link Listenable} via extension.
107
+ * @example Forwarding events to the emitter
108
+ * ```typescript
109
+ * interface MyEvents {
110
+ * loaded(): void;
111
+ * }
112
+ *
113
+ * class MyClass implements Listenable<MyEvents> {
114
+ * private readonly events = createEmitterMinimal<MyEvents>();
115
+ *
116
+ * private load(): void {
117
+ * this.events.emit("loaded");
118
+ * }
119
+ *
120
+ * public on<K extends keyof MyEvents>(eventName: K, listener: MyEvents[K]): Off {
121
+ * return this.events.on(eventName, listener);
122
+ * }
123
+ * }
124
+ * ```
125
+ */
126
+ export declare function createEmitter<TListeners extends object>(noListeners?: NoListenersCallback<TListeners>): Listenable<TListeners> & IEmitter<TListeners> & HasListeners<TListeners>;
127
+ //# sourceMappingURL=emitter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitter.d.ts","sourceRoot":"","sources":["../../src/events/emitter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,QAAQ,CAAC,UAAU,SAAS,SAAS,CAAC,UAAU,CAAC;I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C,CAAC,CAAC,CAAC,GAChC,IAAI;IAgBP,SAAS,CAAC,cAAc,CAAC,CAAC,SAAS,MAAM,UAAU,EAClD,SAAS,EAAE,CAAC,EACZ,GAAG,IAAI,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAChC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE;IAa9B;;;;;;OAMG;IACI,EAAE,CAAC,CAAC,SAAS,MAAM,SAAS,CAAC,UAAU,CAAC,EAC9C,SAAS,EAAE,CAAC,EACZ,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,GACrB,GAAG;IAeC,YAAY,CAAC,SAAS,CAAC,EAAE,MAAM,UAAU,GAAG,OAAO;CAM1D;AA4BD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,aAAa,CAAC,UAAU,SAAS,MAAM,EACtD,WAAW,CAAC,EAAE,mBAAmB,CAAC,UAAU,CAAC,GAC3C,UAAU,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,YAAY,CAAC,UAAU,CAAC,CAE1E"}
@@ -2,17 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { getOrCreate } from "../util/index.js";
6
- /**
7
- * Create a {@link Listenable} that can be instructed to emit events via the {@link IEmitter} interface.
8
- *
9
- * A class can delegate handling {@link Listenable} to the returned value while using it to emit the events.
10
- * See also `EventEmitter` which be used as a base class to implement {@link Listenable} via extension.
11
- * @alpha
12
- */
13
- export function createEmitter(noListeners) {
14
- return new ComposableEventEmitter(noListeners);
15
- }
5
+ import { setInNestedMap } from "../util/index.js";
16
6
  /**
17
7
  * Provides an API for subscribing to and listening to events.
18
8
  *
@@ -22,32 +12,34 @@ export function createEmitter(noListeners) {
22
12
  *
23
13
  * ```typescript
24
14
  * interface MyEvents {
25
- * "loaded": () => void;
15
+ * loaded: () => void;
16
+ * computed: () => number;
26
17
  * }
27
18
  *
28
- * class MyClass extends EventEmitter<MyEvents> {
29
- * private load() {
30
- * this.emit("loaded");
31
- * }
19
+ * class MyInheritanceClass extends EventEmitter<MyEvents> {
20
+ * private load() {
21
+ * this.emit("loaded");
22
+ * const results: number[] = this.emitAndCollect("computed");
23
+ * }
32
24
  * }
33
25
  * ```
34
26
  *
35
27
  * @example Composing over this class
36
28
  *
37
29
  * ```typescript
38
- * class MyClass implements ISubscribable<MyEvents> {
39
- * private readonly events = createEmitter<MyEvents>();
30
+ * class MyCompositionClass implements Listenable<MyEvents> {
31
+ * private readonly events = createEmitter<MyEvents>();
40
32
  *
41
- * private load() {
42
- * this.events.emit("loaded");
43
- * }
33
+ * private load() {
34
+ * this.events.emit("loaded");
35
+ * const results: number[] = this.events.emitAndCollect("computed");
36
+ * }
44
37
  *
45
- * public on<K extends keyof MyEvents>(eventName: K, listener: MyEvents[K]): Off {
46
- * return this.events.on(eventName, listener);
47
- * }
38
+ * public on<K extends keyof MyEvents>(eventName: K, listener: MyEvents[K]): () => void {
39
+ * return this.events.on(eventName, listener);
40
+ * }
48
41
  * }
49
42
  * ```
50
- * @alpha
51
43
  */
52
44
  export class EventEmitter {
53
45
  // Because this is protected and not public, calling this externally (not from a subclass) makes sending events to the constructed instance impossible.
@@ -59,7 +51,7 @@ export class EventEmitter {
59
51
  emit(eventName, ...args) {
60
52
  const listeners = this.listeners.get(eventName);
61
53
  if (listeners !== undefined) {
62
- // Current TS (5.4.5) cannot spread `args` into `listener()`, but assigning to an array first makes it work.
54
+ // Current tsc (5.4.5) cannot spread `args` into `listener()`.
63
55
  const argArray = args;
64
56
  // This explicitly copies listeners so that new listeners added during this call to emit will not receive this event.
65
57
  for (const [off, listener] of [...listeners]) {
@@ -99,7 +91,7 @@ export class EventEmitter {
99
91
  }
100
92
  }
101
93
  };
102
- getOrCreate(this.listeners, eventName, () => new Map()).set(off, listener);
94
+ setInNestedMap(this.listeners, eventName, off, listener);
103
95
  return off;
104
96
  }
105
97
  hasListeners(eventName) {
@@ -112,7 +104,7 @@ export class EventEmitter {
112
104
  /**
113
105
  * This class exposes the constructor and the `emit` method of `EventEmitter`, elevating them from protected to public
114
106
  */
115
- export class ComposableEventEmitter extends EventEmitter {
107
+ class ComposableEventEmitter extends EventEmitter {
116
108
  constructor(noListeners) {
117
109
  super(noListeners);
118
110
  }
@@ -123,4 +115,31 @@ export class ComposableEventEmitter extends EventEmitter {
123
115
  return super.emitAndCollect(eventName, ...args);
124
116
  }
125
117
  }
126
- //# sourceMappingURL=events.js.map
118
+ /**
119
+ * Create a {@link Listenable} that can be instructed to emit events via the {@link IEmitter} interface.
120
+ *
121
+ * A class can delegate handling {@link Listenable} to the returned value while using it to emit the events.
122
+ * See also {@link EventEmitter} which be used as a base class to implement {@link Listenable} via extension.
123
+ * @example Forwarding events to the emitter
124
+ * ```typescript
125
+ * interface MyEvents {
126
+ * loaded(): void;
127
+ * }
128
+ *
129
+ * class MyClass implements Listenable<MyEvents> {
130
+ * private readonly events = createEmitterMinimal<MyEvents>();
131
+ *
132
+ * private load(): void {
133
+ * this.events.emit("loaded");
134
+ * }
135
+ *
136
+ * public on<K extends keyof MyEvents>(eventName: K, listener: MyEvents[K]): Off {
137
+ * return this.events.on(eventName, listener);
138
+ * }
139
+ * }
140
+ * ```
141
+ */
142
+ export function createEmitter(noListeners) {
143
+ return new ComposableEventEmitter(noListeners);
144
+ }
145
+ //# sourceMappingURL=emitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitter.js","sourceRoot":"","sources":["../../src/events/emitter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAyDlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,OAAO,YAAY;IAQxB,uJAAuJ;IACvJ,6FAA6F;IAC7F,YAAuC,WAA6C;QAA7C,gBAAW,GAAX,WAAW,CAAkC;QAPjE,cA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GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC5C,IAAI,gBAAgB,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;oBACjC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;oBACjC,IAAI,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,CAAC;gBAC/B,CAAC;YACF,CAAC;QACF,CAAC,CAAC;QAEF,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;QACzD,OAAO,GAAG,CAAC;IACZ,CAAC;IAEM,YAAY,CAAC,SAA4B;QAC/C,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,CAAC;QAClC,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;CACD;AAED;;GAEG;AACH,MAAM,sBACL,SAAQ,YAAwB;IAGhC,YAAmB,WAA6C;QAC/D,KAAK,CAAC,WAAW,CAAC,CAAC;IACpB,CAAC;IAEe,IAAI,CACnB,SAAY,EACZ,GAAG,IAA+B;QAElC,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;IACvC,CAAC;IAEe,cAAc,CAC7B,SAAY,EACZ,GAAG,IAA+B;QAElC,OAAO,KAAK,CAAC,cAAc,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC;CACD;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,aAAa,CAC5B,WAA6C;IAE7C,OAAO,IAAI,sBAAsB,CAAa,WAAW,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { setInNestedMap } from \"../util/index.js\";\nimport type { Listenable, Listeners, Off } from \"./listeners.js\";\n\n/**\n * Interface for an event emitter that can emit typed events to subscribed listeners.\n */\nexport interface IEmitter<TListeners extends Listeners<TListeners>> {\n\t/**\n\t * Emits an event with the specified name and arguments, notifying all subscribers by calling their registered listener functions.\n\t * @param eventName - the name of the event to fire\n\t * @param args - the arguments passed to the event listener functions\n\t */\n\temit<K extends keyof Listeners<TListeners>>(\n\t\teventName: K,\n\t\t...args: Parameters<TListeners[K]>\n\t): void;\n\n\t/**\n\t * Emits an event with the specified name and arguments, notifying all subscribers by calling their registered listener functions.\n\t * It also collects the return values of all listeners into an array.\n\t *\n\t * Warning: This method should be used with caution. It deviates from the standard event-based integration pattern as creates substantial coupling between the emitter and its listeners.\n\t * For the majority of use-cases it is recommended to use the standard {@link IEmitter.emit} functionality.\n\t * @param eventName - the name of the event to fire\n\t * @param args - the arguments passed to the event listener functions\n\t * @returns An array of the return values of each listener, preserving the order listeners were called.\n\t */\n\temitAndCollect<K extends keyof Listeners<TListeners>>(\n\t\teventName: K,\n\t\t...args: Parameters<TListeners[K]>\n\t): ReturnType<TListeners[K]>[];\n}\n\n/**\n * Called when the last listener for `eventName` is removed.\n * Useful for determining when to clean up resources related to detecting when the event might occurs.\n */\nexport type NoListenersCallback<TListeners extends object> = (\n\teventName: keyof Listeners<TListeners>,\n) => void;\n\n/**\n * Allows querying if an object has listeners.\n * @sealed\n */\nexport interface HasListeners<TListeners extends Listeners<TListeners>> {\n\t/**\n\t * When no `eventName` is provided, returns true iff there are any listeners.\n\t *\n\t * When `eventName` is provided, returns true iff there are listeners for that event.\n\t *\n\t * @remarks\n\t * This can be used to know when its safe to cleanup data-structures which only exist to fire events for their listeners.\n\t */\n\thasListeners(eventName?: keyof Listeners<TListeners>): boolean;\n}\n\n/**\n * Provides an API for subscribing to and listening to events.\n *\n * @remarks Classes wishing to emit events may either extend this class or compose over it.\n *\n * @example Extending this class\n *\n * ```typescript\n * interface MyEvents {\n * \tloaded: () => void;\n * \tcomputed: () => number;\n * }\n *\n * class MyInheritanceClass extends EventEmitter<MyEvents> {\n * \tprivate load() {\n * \t\tthis.emit(\"loaded\");\n * \t\tconst results: number[] = this.emitAndCollect(\"computed\");\n * \t}\n * }\n * ```\n *\n * @example Composing over this class\n *\n * ```typescript\n * class MyCompositionClass implements Listenable<MyEvents> {\n * \tprivate readonly events = createEmitter<MyEvents>();\n *\n * \tprivate load() {\n * \t\tthis.events.emit(\"loaded\");\n * \t\tconst results: number[] = this.events.emitAndCollect(\"computed\");\n * \t}\n *\n * \tpublic on<K extends keyof MyEvents>(eventName: K, listener: MyEvents[K]): () => void {\n * \t\treturn this.events.on(eventName, listener);\n * \t}\n * }\n * ```\n */\nexport class EventEmitter<TListeners extends Listeners<TListeners>>\n\timplements Listenable<TListeners>, HasListeners<TListeners>\n{\n\tprotected readonly listeners = new Map<\n\t\tkeyof TListeners,\n\t\tMap<Off, (...args: any[]) => TListeners[keyof TListeners]>\n\t>();\n\n\t// Because this is protected and not public, calling this externally (not from a subclass) makes sending events to the constructed instance impossible.\n\t// Instead, use the static `create` function to get an instance which allows emitting events.\n\tprotected constructor(private readonly noListeners?: NoListenersCallback<TListeners>) {}\n\n\tprotected emit<K extends keyof TListeners>(\n\t\teventName: K,\n\t\t...args: Parameters<TListeners[K]>\n\t): void {\n\t\tconst listeners = this.listeners.get(eventName);\n\t\tif (listeners !== undefined) {\n\t\t\t// Current tsc (5.4.5) cannot spread `args` into `listener()`.\n\t\t\tconst argArray: unknown[] = args;\n\n\t\t\t// This explicitly copies listeners so that new listeners added during this call to emit will not receive this event.\n\t\t\tfor (const [off, listener] of [...listeners]) {\n\t\t\t\t// If listener has been unsubscribed while invoking other listeners, skip it.\n\t\t\t\tif (listeners.has(off)) {\n\t\t\t\t\tlistener(...argArray);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected emitAndCollect<K extends keyof TListeners>(\n\t\teventName: K,\n\t\t...args: Parameters<TListeners[K]>\n\t): ReturnType<TListeners[K]>[] {\n\t\tconst listeners = this.listeners.get(eventName);\n\t\tif (listeners !== undefined) {\n\t\t\tconst argArray: unknown[] = args;\n\t\t\tconst resultArray: ReturnType<TListeners[K]>[] = [];\n\t\t\tfor (const listener of [...listeners.values()]) {\n\t\t\t\tresultArray.push(listener(...argArray));\n\t\t\t}\n\t\t\treturn resultArray;\n\t\t}\n\t\treturn [];\n\t}\n\n\t/**\n\t * Register an event listener.\n\t * @param eventName - the name of the event\n\t * @param listener - the handler to run when the event is fired by the emitter\n\t * @returns a function which will deregister the listener when run.\n\t * This function will error if called more than once.\n\t */\n\tpublic on<K extends keyof Listeners<TListeners>>(\n\t\teventName: K,\n\t\tlistener: TListeners[K],\n\t): Off {\n\t\tconst off: Off = () => {\n\t\t\tconst currentListeners = this.listeners.get(eventName);\n\t\t\tif (currentListeners?.delete(off) === true) {\n\t\t\t\tif (currentListeners.size === 0) {\n\t\t\t\t\tthis.listeners.delete(eventName);\n\t\t\t\t\tthis.noListeners?.(eventName);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tsetInNestedMap(this.listeners, eventName, off, listener);\n\t\treturn off;\n\t}\n\n\tpublic hasListeners(eventName?: keyof TListeners): boolean {\n\t\tif (eventName === undefined) {\n\t\t\treturn this.listeners.size !== 0;\n\t\t}\n\t\treturn this.listeners.has(eventName);\n\t}\n}\n\n/**\n * This class exposes the constructor and the `emit` method of `EventEmitter`, elevating them from protected to public\n */\nclass ComposableEventEmitter<TListeners extends Listeners<TListeners>>\n\textends EventEmitter<TListeners>\n\timplements IEmitter<TListeners>\n{\n\tpublic constructor(noListeners?: NoListenersCallback<TListeners>) {\n\t\tsuper(noListeners);\n\t}\n\n\tpublic override emit<K extends keyof TListeners>(\n\t\teventName: K,\n\t\t...args: Parameters<TListeners[K]>\n\t): void {\n\t\treturn super.emit(eventName, ...args);\n\t}\n\n\tpublic override emitAndCollect<K extends keyof TListeners>(\n\t\teventName: K,\n\t\t...args: Parameters<TListeners[K]>\n\t): ReturnType<TListeners[K]>[] {\n\t\treturn super.emitAndCollect(eventName, ...args);\n\t}\n}\n\n/**\n * Create a {@link Listenable} that can be instructed to emit events via the {@link IEmitter} interface.\n *\n * A class can delegate handling {@link Listenable} to the returned value while using it to emit the events.\n * See also {@link EventEmitter} which be used as a base class to implement {@link Listenable} via extension.\n * @example Forwarding events to the emitter\n * ```typescript\n * interface MyEvents {\n * \tloaded(): void;\n * }\n *\n * class MyClass implements Listenable<MyEvents> {\n * \tprivate readonly events = createEmitterMinimal<MyEvents>();\n *\n * \tprivate load(): void {\n * \t\tthis.events.emit(\"loaded\");\n * \t}\n *\n * \tpublic on<K extends keyof MyEvents>(eventName: K, listener: MyEvents[K]): Off {\n * \t\treturn this.events.on(eventName, listener);\n * \t}\n * }\n * ```\n */\nexport function createEmitter<TListeners extends object>(\n\tnoListeners?: NoListenersCallback<TListeners>,\n): Listenable<TListeners> & IEmitter<TListeners> & HasListeners<TListeners> {\n\treturn new ComposableEventEmitter<TListeners>(noListeners);\n}\n"]}
@@ -2,5 +2,6 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- export { createEmitter, EventEmitter, ComposableEventEmitter, type Listeners, type Listenable, type Off, type IsListener, type TransformListeners, type UnionToIntersection, type IEmitter, type NoListenersCallback, type HasListeners, } from "./events.js";
5
+ export { createEmitter, EventEmitter, type IEmitter, type NoListenersCallback, type HasListeners, } from "./emitter.js";
6
+ export { type Listeners, type Listenable, type Off, type IsListener, } from "./listeners.js";
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,aAAa,EACb,YAAY,EACZ,sBAAsB,EACtB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,GAAG,EACR,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,YAAY,GACjB,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,aAAa,EACb,YAAY,EACZ,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,YAAY,GACjB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACN,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,GAAG,EACR,KAAK,UAAU,GACf,MAAM,gBAAgB,CAAC"}
@@ -2,5 +2,5 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- export { createEmitter, EventEmitter, ComposableEventEmitter, } from "./events.js";
5
+ export { createEmitter, EventEmitter, } from "./emitter.js";
6
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,aAAa,EACb,YAAY,EACZ,sBAAsB,GAUtB,MAAM,aAAa,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\tcreateEmitter,\n\tEventEmitter,\n\tComposableEventEmitter,\n\ttype Listeners,\n\ttype Listenable,\n\ttype Off,\n\ttype IsListener,\n\ttype TransformListeners,\n\ttype UnionToIntersection,\n\ttype IEmitter,\n\ttype NoListenersCallback,\n\ttype HasListeners,\n} from \"./events.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,aAAa,EACb,YAAY,GAIZ,MAAM,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\tcreateEmitter,\n\tEventEmitter,\n\ttype IEmitter,\n\ttype NoListenersCallback,\n\ttype HasListeners,\n} from \"./emitter.js\";\n\nexport {\n\ttype Listeners,\n\ttype Listenable,\n\ttype Off,\n\ttype IsListener,\n} from \"./listeners.js\";\n"]}
@@ -0,0 +1,36 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import type { IEvent } from "@fluidframework/core-interfaces";
6
+ import type { Listeners } from "./listeners.js";
7
+ /**
8
+ * Convert a union of types to an intersection of those types. Useful for `TransformEvents`.
9
+ * @privateRemarks
10
+ * First an always true extends clause is used (T extends T) to distribute T into to a union of types contravariant over each member of the T union.
11
+ * Then the constraint on the type parameter in this new context is inferred, giving the intersection.
12
+ */
13
+ export type UnionToIntersection<T> = (T extends T ? (k: T) => unknown : never) extends (k: infer U) => unknown ? U : never;
14
+ /**
15
+ * Converts a {@link Listeners} type (i.e. the event registry for a {@link Listenable}) into a type consumable
16
+ * by an IEventProvider from `@fluidframework/core-interfaces`.
17
+ * @param E - the `Events` type to transform
18
+ * @param Target - an optional `IEvent` type that will be merged into the result along with the transformed `E`
19
+ *
20
+ * @example
21
+ *
22
+ * ```typescript
23
+ * interface MyEvents {
24
+ * load: (user: string, data: IUserData) => void;
25
+ * error: (errorCode: number) => void;
26
+ * }
27
+ *
28
+ * class MySharedObject extends SharedObject<TransformEvents<MyEvents, ISharedObjectEvents>> {
29
+ * // ...
30
+ * }
31
+ * ```
32
+ */
33
+ export type TransformListeners<TListeners extends Listeners<TListeners>, TTarget extends IEvent = IEvent> = {
34
+ [P in keyof Listeners<TListeners>]: (event: P, listener: TListeners[P]) => void;
35
+ } extends Record<string | number | symbol, infer Z> ? UnionToIntersection<Z> & TTarget : never;
36
+ //# sourceMappingURL=interop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interop.d.ts","sourceRoot":"","sources":["../../src/events/interop.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAIhD;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,GAAG,KAAK,CAAC,SAAS,CACtF,CAAC,EAAE,MAAM,CAAC,KACN,OAAO,GACT,CAAC,GACD,KAAK,CAAC;AAET;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,kBAAkB,CAC7B,UAAU,SAAS,SAAS,CAAC,UAAU,CAAC,EACxC,OAAO,SAAS,MAAM,GAAG,MAAM,IAC5B;KACF,CAAC,IAAI,MAAM,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;CAC/E,SAAS,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,MAAM,CAAC,CAAC,GAChD,mBAAmB,CAAC,CAAC,CAAC,GAAG,OAAO,GAChC,KAAK,CAAC"}
@@ -2,5 +2,5 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
-
6
- export { type Revertible, RevertibleStatus } from "./revertible.js";
5
+ export {};
6
+ //# sourceMappingURL=interop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interop.js","sourceRoot":"","sources":["../../src/events/interop.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IEvent } from \"@fluidframework/core-interfaces\";\nimport type { Listeners } from \"./listeners.js\";\n\n// TODO: this file is currently unused. Use it or remove it.\n\n/**\n * Convert a union of types to an intersection of those types. Useful for `TransformEvents`.\n * @privateRemarks\n * First an always true extends clause is used (T extends T) to distribute T into to a union of types contravariant over each member of the T union.\n * Then the constraint on the type parameter in this new context is inferred, giving the intersection.\n */\nexport type UnionToIntersection<T> = (T extends T ? (k: T) => unknown : never) extends (\n\tk: infer U,\n) => unknown\n\t? U\n\t: never;\n\n/**\n * Converts a {@link Listeners} type (i.e. the event registry for a {@link Listenable}) into a type consumable\n * by an IEventProvider from `@fluidframework/core-interfaces`.\n * @param E - the `Events` type to transform\n * @param Target - an optional `IEvent` type that will be merged into the result along with the transformed `E`\n *\n * @example\n *\n * ```typescript\n * interface MyEvents {\n * load: (user: string, data: IUserData) => void;\n * error: (errorCode: number) => void;\n * }\n *\n * class MySharedObject extends SharedObject<TransformEvents<MyEvents, ISharedObjectEvents>> {\n * // ...\n * }\n * ```\n */\nexport type TransformListeners<\n\tTListeners extends Listeners<TListeners>,\n\tTTarget extends IEvent = IEvent,\n> = {\n\t[P in keyof Listeners<TListeners>]: (event: P, listener: TListeners[P]) => void;\n} extends Record<string | number | symbol, infer Z>\n\t? UnionToIntersection<Z> & TTarget\n\t: never;\n"]}
@@ -0,0 +1,65 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * `true` iff the given type is an acceptable shape for a {@link Listeners | event} listener
7
+ * @public
8
+ */
9
+ export type IsListener<TListener> = TListener extends (...args: any[]) => void ? true : false;
10
+ /**
11
+ * Used to specify the kinds of events emitted by a {@link Listenable}.
12
+ *
13
+ * @remarks
14
+ * Any object type is a valid {@link Listeners}, but only the {@link IsListener | event-like} properties of that
15
+ * type will be included.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * interface MyEvents {
20
+ * load: (user: string, data: IUserData) => void;
21
+ * error: (errorCode: number) => void;
22
+ * }
23
+ * ```
24
+ *
25
+ * @public
26
+ */
27
+ export type Listeners<T extends object> = {
28
+ [P in (string | symbol) & keyof T as IsListener<T[P]> extends true ? P : never]: T[P];
29
+ };
30
+ /**
31
+ * An object which allows the registration of listeners so that subscribers can be notified when an event happens.
32
+ * @param TListeners - All the {@link Listeners | events} that this subscribable supports
33
+ *
34
+ * @privateRemarks
35
+ * `EventEmitter` can be used as a base class to implement this via extension.
36
+ * ```ts
37
+ * type MyEventEmitter = IEventEmitter<{
38
+ * load: (user: string, data: IUserData) => void;
39
+ * error: (errorCode: number) => void;
40
+ * }>
41
+ * ```
42
+ * {@link createEmitter} can help implement this interface via delegation.
43
+ *
44
+ * @sealed @public
45
+ */
46
+ export interface Listenable<TListeners extends object> {
47
+ /**
48
+ * Register an event listener.
49
+ * @param eventName - The name of the event.
50
+ * @param listener - the handler to run when the event is fired by the emitter
51
+ * @returns a {@link Off | function} which will deregister the listener when called.
52
+ * This deregistration function is idempotent and therefore may be safely called more than once with no effect.
53
+ * @remarks Do not register the exact same `listener` object for the same event more than once.
54
+ * Doing so will result in undefined behavior, and is not guaranteed to behave the same in future versions of this library.
55
+ */
56
+ on<K extends keyof Listeners<TListeners>>(eventName: K, listener: TListeners[K]): Off;
57
+ }
58
+ /**
59
+ * A function that, when called, will deregister an event listener subscription that was previously registered.
60
+ * @remarks
61
+ * It is returned by the {@link Listenable.on | event registration function} when event registration occurs.
62
+ * @public
63
+ */
64
+ export type Off = () => void;
65
+ //# sourceMappingURL=listeners.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listeners.d.ts","sourceRoot":"","sources":["../../src/events/listeners.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,SAAS,IAAI,SAAS,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;AAE9F;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI;KACxC,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;CACrF,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,UAAU,CAAC,UAAU,SAAS,MAAM;IACpD;;;;;;;;OAQG;IACH,EAAE,CAAC,CAAC,SAAS,MAAM,SAAS,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;CACtF;AAED;;;;;GAKG;AACH,MAAM,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC"}
@@ -2,5 +2,5 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- export { RevertibleStatus } from "./revertible.js";
6
- //# sourceMappingURL=index.js.map
5
+ export {};
6
+ //# sourceMappingURL=listeners.js.map