@fluidframework/tree 2.12.0 → 2.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (496) hide show
  1. package/CHANGELOG.md +154 -0
  2. package/api-report/tree.alpha.api.md +108 -22
  3. package/api-report/tree.beta.api.md +31 -15
  4. package/api-report/tree.legacy.alpha.api.md +31 -15
  5. package/api-report/tree.legacy.public.api.md +31 -15
  6. package/api-report/tree.public.api.md +31 -15
  7. package/assertTagging.config.mjs +14 -0
  8. package/dist/alpha.d.ts +14 -0
  9. package/dist/beta.d.ts +2 -0
  10. package/dist/core/index.d.ts +2 -2
  11. package/dist/core/index.d.ts.map +1 -1
  12. package/dist/core/index.js +6 -4
  13. package/dist/core/index.js.map +1 -1
  14. package/dist/core/rebase/index.d.ts +2 -2
  15. package/dist/core/rebase/index.d.ts.map +1 -1
  16. package/dist/core/rebase/index.js +5 -1
  17. package/dist/core/rebase/index.js.map +1 -1
  18. package/dist/core/rebase/types.d.ts +5 -4
  19. package/dist/core/rebase/types.d.ts.map +1 -1
  20. package/dist/core/rebase/types.js +29 -1
  21. package/dist/core/rebase/types.js.map +1 -1
  22. package/dist/core/rebase/utils.d.ts +10 -0
  23. package/dist/core/rebase/utils.d.ts.map +1 -1
  24. package/dist/core/rebase/utils.js +22 -1
  25. package/dist/core/rebase/utils.js.map +1 -1
  26. package/dist/core/tree/delta.d.ts +21 -26
  27. package/dist/core/tree/delta.d.ts.map +1 -1
  28. package/dist/core/tree/delta.js.map +1 -1
  29. package/dist/core/tree/deltaUtil.d.ts +1 -3
  30. package/dist/core/tree/deltaUtil.d.ts.map +1 -1
  31. package/dist/core/tree/deltaUtil.js +2 -14
  32. package/dist/core/tree/deltaUtil.js.map +1 -1
  33. package/dist/core/tree/index.d.ts +1 -1
  34. package/dist/core/tree/index.d.ts.map +1 -1
  35. package/dist/core/tree/index.js +1 -3
  36. package/dist/core/tree/index.js.map +1 -1
  37. package/dist/core/tree/visitDelta.d.ts.map +1 -1
  38. package/dist/core/tree/visitDelta.js +82 -80
  39. package/dist/core/tree/visitDelta.js.map +1 -1
  40. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts +10 -0
  41. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  42. package/dist/feature-libraries/default-schema/defaultEditBuilder.js +3 -0
  43. package/dist/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  44. package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  45. package/dist/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  46. package/dist/feature-libraries/deltaUtils.d.ts.map +1 -1
  47. package/dist/feature-libraries/deltaUtils.js +13 -0
  48. package/dist/feature-libraries/deltaUtils.js.map +1 -1
  49. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  50. package/dist/feature-libraries/forest-summary/forestSummarizer.js +1 -6
  51. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  52. package/dist/feature-libraries/index.d.ts +0 -1
  53. package/dist/feature-libraries/index.d.ts.map +1 -1
  54. package/dist/feature-libraries/index.js +2 -4
  55. package/dist/feature-libraries/index.js.map +1 -1
  56. package/dist/feature-libraries/modular-schema/crossFieldQueries.d.ts +5 -5
  57. package/dist/feature-libraries/modular-schema/crossFieldQueries.d.ts.map +1 -1
  58. package/dist/feature-libraries/modular-schema/crossFieldQueries.js +2 -3
  59. package/dist/feature-libraries/modular-schema/crossFieldQueries.js.map +1 -1
  60. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts +30 -6
  61. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  62. package/dist/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  63. package/dist/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
  64. package/dist/feature-libraries/modular-schema/genericFieldKind.js +2 -1
  65. package/dist/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  66. package/dist/feature-libraries/modular-schema/index.d.ts +2 -2
  67. package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
  68. package/dist/feature-libraries/modular-schema/index.js.map +1 -1
  69. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts +1 -1
  70. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  71. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +8 -8
  72. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  73. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts +5 -4
  74. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  75. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +186 -216
  76. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  77. package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts +23 -20
  78. package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
  79. package/dist/feature-libraries/modular-schema/modularChangeTypes.js +20 -0
  80. package/dist/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
  81. package/dist/feature-libraries/optional-field/optionalField.d.ts +3 -3
  82. package/dist/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
  83. package/dist/feature-libraries/optional-field/optionalField.js +24 -4
  84. package/dist/feature-libraries/optional-field/optionalField.js.map +1 -1
  85. package/dist/feature-libraries/sequence-field/moveEffectTable.d.ts +1 -1
  86. package/dist/feature-libraries/sequence-field/moveEffectTable.d.ts.map +1 -1
  87. package/dist/feature-libraries/sequence-field/moveEffectTable.js.map +1 -1
  88. package/dist/feature-libraries/sequence-field/rebase.js +4 -4
  89. package/dist/feature-libraries/sequence-field/rebase.js.map +1 -1
  90. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV1.js +1 -1
  91. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV1.js.map +1 -1
  92. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js +1 -1
  93. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  94. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.d.ts +2 -3
  95. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.d.ts.map +1 -1
  96. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  97. package/dist/feature-libraries/sequence-field/utils.d.ts +2 -2
  98. package/dist/feature-libraries/sequence-field/utils.d.ts.map +1 -1
  99. package/dist/feature-libraries/sequence-field/utils.js +50 -9
  100. package/dist/feature-libraries/sequence-field/utils.js.map +1 -1
  101. package/dist/feature-libraries/treeCursorUtils.d.ts.map +1 -1
  102. package/dist/feature-libraries/treeCursorUtils.js +4 -1
  103. package/dist/feature-libraries/treeCursorUtils.js.map +1 -1
  104. package/dist/index.d.ts +27 -3
  105. package/dist/index.d.ts.map +1 -1
  106. package/dist/index.js +5 -2
  107. package/dist/index.js.map +1 -1
  108. package/dist/legacy.d.ts +2 -0
  109. package/dist/package.json +2 -1
  110. package/dist/packageVersion.d.ts +1 -1
  111. package/dist/packageVersion.js +1 -1
  112. package/dist/packageVersion.js.map +1 -1
  113. package/dist/public.d.ts +2 -0
  114. package/dist/shared-tree/index.d.ts +3 -2
  115. package/dist/shared-tree/index.d.ts.map +1 -1
  116. package/dist/shared-tree/index.js +6 -3
  117. package/dist/shared-tree/index.js.map +1 -1
  118. package/dist/shared-tree/schematizingTreeView.d.ts +10 -1
  119. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  120. package/dist/shared-tree/schematizingTreeView.js +43 -0
  121. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  122. package/dist/shared-tree/sharedTree.d.ts +44 -21
  123. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  124. package/dist/shared-tree/sharedTree.js +41 -35
  125. package/dist/shared-tree/sharedTree.js.map +1 -1
  126. package/dist/shared-tree/transactionTypes.d.ts +105 -0
  127. package/dist/shared-tree/transactionTypes.d.ts.map +1 -0
  128. package/dist/shared-tree/transactionTypes.js +13 -0
  129. package/dist/shared-tree/transactionTypes.js.map +1 -0
  130. package/dist/shared-tree/treeApi.d.ts +1 -25
  131. package/dist/shared-tree/treeApi.d.ts.map +1 -1
  132. package/dist/shared-tree/treeApi.js +4 -8
  133. package/dist/shared-tree/treeApi.js.map +1 -1
  134. package/dist/shared-tree/treeCheckout.d.ts +4 -1
  135. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  136. package/dist/shared-tree/treeCheckout.js +142 -23
  137. package/dist/shared-tree/treeCheckout.js.map +1 -1
  138. package/dist/shared-tree-core/sharedTreeCore.js +1 -1
  139. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  140. package/dist/simple-tree/api/index.d.ts +1 -0
  141. package/dist/simple-tree/api/index.d.ts.map +1 -1
  142. package/dist/simple-tree/api/index.js +3 -1
  143. package/dist/simple-tree/api/index.js.map +1 -1
  144. package/dist/simple-tree/api/jsonSchema.d.ts +6 -0
  145. package/dist/simple-tree/api/jsonSchema.d.ts.map +1 -1
  146. package/dist/simple-tree/api/jsonSchema.js.map +1 -1
  147. package/dist/simple-tree/api/schemaFactory.d.ts +21 -12
  148. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  149. package/dist/simple-tree/api/schemaFactory.js +5 -2
  150. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  151. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +83 -0
  152. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -0
  153. package/dist/simple-tree/api/schemaFactoryAlpha.js +90 -0
  154. package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -0
  155. package/dist/simple-tree/api/simpleSchema.d.ts +5 -1
  156. package/dist/simple-tree/api/simpleSchema.d.ts.map +1 -1
  157. package/dist/simple-tree/api/simpleSchema.js.map +1 -1
  158. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +13 -10
  159. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  160. package/dist/simple-tree/api/testRecursiveDomain.d.ts +5 -5
  161. package/dist/simple-tree/api/tree.d.ts +60 -0
  162. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  163. package/dist/simple-tree/api/tree.js.map +1 -1
  164. package/dist/simple-tree/api/treeNodeApi.js +1 -1
  165. package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
  166. package/dist/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
  167. package/dist/simple-tree/api/viewSchemaToSimpleSchema.js +11 -11
  168. package/dist/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
  169. package/dist/simple-tree/arrayNode.d.ts +2 -2
  170. package/dist/simple-tree/arrayNode.d.ts.map +1 -1
  171. package/dist/simple-tree/arrayNode.js +3 -2
  172. package/dist/simple-tree/arrayNode.js.map +1 -1
  173. package/dist/simple-tree/core/treeNodeSchema.d.ts +10 -6
  174. package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  175. package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
  176. package/dist/simple-tree/index.d.ts +2 -2
  177. package/dist/simple-tree/index.d.ts.map +1 -1
  178. package/dist/simple-tree/index.js +3 -2
  179. package/dist/simple-tree/index.js.map +1 -1
  180. package/dist/simple-tree/leafNodeSchema.d.ts +5 -5
  181. package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
  182. package/dist/simple-tree/mapNode.d.ts +2 -2
  183. package/dist/simple-tree/mapNode.d.ts.map +1 -1
  184. package/dist/simple-tree/mapNode.js +2 -1
  185. package/dist/simple-tree/mapNode.js.map +1 -1
  186. package/dist/simple-tree/objectNode.d.ts +2 -2
  187. package/dist/simple-tree/objectNode.d.ts.map +1 -1
  188. package/dist/simple-tree/objectNode.js +2 -1
  189. package/dist/simple-tree/objectNode.js.map +1 -1
  190. package/dist/simple-tree/objectNodeTypes.d.ts +2 -2
  191. package/dist/simple-tree/objectNodeTypes.d.ts.map +1 -1
  192. package/dist/simple-tree/objectNodeTypes.js.map +1 -1
  193. package/dist/simple-tree/schemaTypes.d.ts +47 -1
  194. package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
  195. package/dist/simple-tree/schemaTypes.js.map +1 -1
  196. package/dist/simple-tree/toMapTree.js +1 -1
  197. package/dist/simple-tree/toMapTree.js.map +1 -1
  198. package/dist/util/bTreeUtils.d.ts +10 -0
  199. package/dist/util/bTreeUtils.d.ts.map +1 -0
  200. package/dist/util/bTreeUtils.js +52 -0
  201. package/dist/util/bTreeUtils.js.map +1 -0
  202. package/dist/util/idAllocator.d.ts +0 -2
  203. package/dist/util/idAllocator.d.ts.map +1 -1
  204. package/dist/util/idAllocator.js +0 -2
  205. package/dist/util/idAllocator.js.map +1 -1
  206. package/dist/util/index.d.ts +3 -2
  207. package/dist/util/index.d.ts.map +1 -1
  208. package/dist/util/index.js +7 -5
  209. package/dist/util/index.js.map +1 -1
  210. package/dist/util/rangeMap.d.ts +95 -43
  211. package/dist/util/rangeMap.d.ts.map +1 -1
  212. package/dist/util/rangeMap.js +202 -148
  213. package/dist/util/rangeMap.js.map +1 -1
  214. package/dist/util/utils.d.ts +26 -2
  215. package/dist/util/utils.d.ts.map +1 -1
  216. package/dist/util/utils.js +17 -2
  217. package/dist/util/utils.js.map +1 -1
  218. package/lib/alpha.d.ts +14 -0
  219. package/lib/beta.d.ts +2 -0
  220. package/lib/core/index.d.ts +2 -2
  221. package/lib/core/index.d.ts.map +1 -1
  222. package/lib/core/index.js +2 -2
  223. package/lib/core/index.js.map +1 -1
  224. package/lib/core/rebase/index.d.ts +2 -2
  225. package/lib/core/rebase/index.d.ts.map +1 -1
  226. package/lib/core/rebase/index.js +2 -2
  227. package/lib/core/rebase/index.js.map +1 -1
  228. package/lib/core/rebase/types.d.ts +5 -4
  229. package/lib/core/rebase/types.d.ts.map +1 -1
  230. package/lib/core/rebase/types.js +26 -1
  231. package/lib/core/rebase/types.js.map +1 -1
  232. package/lib/core/rebase/utils.d.ts +10 -0
  233. package/lib/core/rebase/utils.d.ts.map +1 -1
  234. package/lib/core/rebase/utils.js +20 -0
  235. package/lib/core/rebase/utils.js.map +1 -1
  236. package/lib/core/tree/delta.d.ts +21 -26
  237. package/lib/core/tree/delta.d.ts.map +1 -1
  238. package/lib/core/tree/delta.js.map +1 -1
  239. package/lib/core/tree/deltaUtil.d.ts +1 -3
  240. package/lib/core/tree/deltaUtil.d.ts.map +1 -1
  241. package/lib/core/tree/deltaUtil.js +1 -12
  242. package/lib/core/tree/deltaUtil.js.map +1 -1
  243. package/lib/core/tree/index.d.ts +1 -1
  244. package/lib/core/tree/index.d.ts.map +1 -1
  245. package/lib/core/tree/index.js +1 -1
  246. package/lib/core/tree/index.js.map +1 -1
  247. package/lib/core/tree/visitDelta.d.ts.map +1 -1
  248. package/lib/core/tree/visitDelta.js +82 -80
  249. package/lib/core/tree/visitDelta.js.map +1 -1
  250. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts +10 -0
  251. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  252. package/lib/feature-libraries/default-schema/defaultEditBuilder.js +3 -0
  253. package/lib/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  254. package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  255. package/lib/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  256. package/lib/feature-libraries/deltaUtils.d.ts.map +1 -1
  257. package/lib/feature-libraries/deltaUtils.js +13 -0
  258. package/lib/feature-libraries/deltaUtils.js.map +1 -1
  259. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  260. package/lib/feature-libraries/forest-summary/forestSummarizer.js +1 -6
  261. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  262. package/lib/feature-libraries/index.d.ts +0 -1
  263. package/lib/feature-libraries/index.d.ts.map +1 -1
  264. package/lib/feature-libraries/index.js +0 -1
  265. package/lib/feature-libraries/index.js.map +1 -1
  266. package/lib/feature-libraries/modular-schema/crossFieldQueries.d.ts +5 -5
  267. package/lib/feature-libraries/modular-schema/crossFieldQueries.d.ts.map +1 -1
  268. package/lib/feature-libraries/modular-schema/crossFieldQueries.js +2 -3
  269. package/lib/feature-libraries/modular-schema/crossFieldQueries.js.map +1 -1
  270. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts +30 -6
  271. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  272. package/lib/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  273. package/lib/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
  274. package/lib/feature-libraries/modular-schema/genericFieldKind.js +2 -1
  275. package/lib/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  276. package/lib/feature-libraries/modular-schema/index.d.ts +2 -2
  277. package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
  278. package/lib/feature-libraries/modular-schema/index.js.map +1 -1
  279. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts +1 -1
  280. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  281. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +4 -4
  282. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  283. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts +5 -4
  284. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  285. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +158 -186
  286. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  287. package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts +23 -20
  288. package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
  289. package/lib/feature-libraries/modular-schema/modularChangeTypes.js +18 -1
  290. package/lib/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
  291. package/lib/feature-libraries/optional-field/optionalField.d.ts +3 -3
  292. package/lib/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
  293. package/lib/feature-libraries/optional-field/optionalField.js +24 -4
  294. package/lib/feature-libraries/optional-field/optionalField.js.map +1 -1
  295. package/lib/feature-libraries/sequence-field/moveEffectTable.d.ts +1 -1
  296. package/lib/feature-libraries/sequence-field/moveEffectTable.d.ts.map +1 -1
  297. package/lib/feature-libraries/sequence-field/moveEffectTable.js.map +1 -1
  298. package/lib/feature-libraries/sequence-field/rebase.js +4 -4
  299. package/lib/feature-libraries/sequence-field/rebase.js.map +1 -1
  300. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.js +1 -1
  301. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.js.map +1 -1
  302. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js +1 -1
  303. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  304. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.d.ts +2 -3
  305. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.d.ts.map +1 -1
  306. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  307. package/lib/feature-libraries/sequence-field/utils.d.ts +2 -2
  308. package/lib/feature-libraries/sequence-field/utils.d.ts.map +1 -1
  309. package/lib/feature-libraries/sequence-field/utils.js +50 -9
  310. package/lib/feature-libraries/sequence-field/utils.js.map +1 -1
  311. package/lib/feature-libraries/treeCursorUtils.d.ts.map +1 -1
  312. package/lib/feature-libraries/treeCursorUtils.js +4 -1
  313. package/lib/feature-libraries/treeCursorUtils.js.map +1 -1
  314. package/lib/index.d.ts +27 -3
  315. package/lib/index.d.ts.map +1 -1
  316. package/lib/index.js +2 -2
  317. package/lib/index.js.map +1 -1
  318. package/lib/legacy.d.ts +2 -0
  319. package/lib/packageVersion.d.ts +1 -1
  320. package/lib/packageVersion.js +1 -1
  321. package/lib/packageVersion.js.map +1 -1
  322. package/lib/public.d.ts +2 -0
  323. package/lib/shared-tree/index.d.ts +3 -2
  324. package/lib/shared-tree/index.d.ts.map +1 -1
  325. package/lib/shared-tree/index.js +3 -2
  326. package/lib/shared-tree/index.js.map +1 -1
  327. package/lib/shared-tree/schematizingTreeView.d.ts +10 -1
  328. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  329. package/lib/shared-tree/schematizingTreeView.js +46 -3
  330. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  331. package/lib/shared-tree/sharedTree.d.ts +44 -21
  332. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  333. package/lib/shared-tree/sharedTree.js +40 -34
  334. package/lib/shared-tree/sharedTree.js.map +1 -1
  335. package/lib/shared-tree/transactionTypes.d.ts +105 -0
  336. package/lib/shared-tree/transactionTypes.d.ts.map +1 -0
  337. package/lib/shared-tree/transactionTypes.js +10 -0
  338. package/lib/shared-tree/transactionTypes.js.map +1 -0
  339. package/lib/shared-tree/treeApi.d.ts +1 -25
  340. package/lib/shared-tree/treeApi.d.ts.map +1 -1
  341. package/lib/shared-tree/treeApi.js +1 -5
  342. package/lib/shared-tree/treeApi.js.map +1 -1
  343. package/lib/shared-tree/treeCheckout.d.ts +4 -1
  344. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  345. package/lib/shared-tree/treeCheckout.js +143 -24
  346. package/lib/shared-tree/treeCheckout.js.map +1 -1
  347. package/lib/shared-tree-core/sharedTreeCore.js +1 -1
  348. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  349. package/lib/simple-tree/api/index.d.ts +1 -0
  350. package/lib/simple-tree/api/index.d.ts.map +1 -1
  351. package/lib/simple-tree/api/index.js +1 -0
  352. package/lib/simple-tree/api/index.js.map +1 -1
  353. package/lib/simple-tree/api/jsonSchema.d.ts +6 -0
  354. package/lib/simple-tree/api/jsonSchema.d.ts.map +1 -1
  355. package/lib/simple-tree/api/jsonSchema.js.map +1 -1
  356. package/lib/simple-tree/api/schemaFactory.d.ts +21 -12
  357. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  358. package/lib/simple-tree/api/schemaFactory.js +5 -2
  359. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  360. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +83 -0
  361. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -0
  362. package/lib/simple-tree/api/schemaFactoryAlpha.js +86 -0
  363. package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -0
  364. package/lib/simple-tree/api/simpleSchema.d.ts +5 -1
  365. package/lib/simple-tree/api/simpleSchema.d.ts.map +1 -1
  366. package/lib/simple-tree/api/simpleSchema.js.map +1 -1
  367. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +14 -11
  368. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  369. package/lib/simple-tree/api/testRecursiveDomain.d.ts +5 -5
  370. package/lib/simple-tree/api/tree.d.ts +60 -0
  371. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  372. package/lib/simple-tree/api/tree.js.map +1 -1
  373. package/lib/simple-tree/api/treeNodeApi.js +1 -1
  374. package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
  375. package/lib/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
  376. package/lib/simple-tree/api/viewSchemaToSimpleSchema.js +12 -12
  377. package/lib/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
  378. package/lib/simple-tree/arrayNode.d.ts +2 -2
  379. package/lib/simple-tree/arrayNode.d.ts.map +1 -1
  380. package/lib/simple-tree/arrayNode.js +3 -2
  381. package/lib/simple-tree/arrayNode.js.map +1 -1
  382. package/lib/simple-tree/core/treeNodeSchema.d.ts +10 -6
  383. package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  384. package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
  385. package/lib/simple-tree/index.d.ts +2 -2
  386. package/lib/simple-tree/index.d.ts.map +1 -1
  387. package/lib/simple-tree/index.js +1 -1
  388. package/lib/simple-tree/index.js.map +1 -1
  389. package/lib/simple-tree/leafNodeSchema.d.ts +5 -5
  390. package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
  391. package/lib/simple-tree/mapNode.d.ts +2 -2
  392. package/lib/simple-tree/mapNode.d.ts.map +1 -1
  393. package/lib/simple-tree/mapNode.js +2 -1
  394. package/lib/simple-tree/mapNode.js.map +1 -1
  395. package/lib/simple-tree/objectNode.d.ts +2 -2
  396. package/lib/simple-tree/objectNode.d.ts.map +1 -1
  397. package/lib/simple-tree/objectNode.js +2 -1
  398. package/lib/simple-tree/objectNode.js.map +1 -1
  399. package/lib/simple-tree/objectNodeTypes.d.ts +2 -2
  400. package/lib/simple-tree/objectNodeTypes.d.ts.map +1 -1
  401. package/lib/simple-tree/objectNodeTypes.js.map +1 -1
  402. package/lib/simple-tree/schemaTypes.d.ts +47 -1
  403. package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
  404. package/lib/simple-tree/schemaTypes.js.map +1 -1
  405. package/lib/simple-tree/toMapTree.js +1 -1
  406. package/lib/simple-tree/toMapTree.js.map +1 -1
  407. package/lib/util/bTreeUtils.d.ts +10 -0
  408. package/lib/util/bTreeUtils.d.ts.map +1 -0
  409. package/lib/util/bTreeUtils.js +47 -0
  410. package/lib/util/bTreeUtils.js.map +1 -0
  411. package/lib/util/idAllocator.d.ts +0 -2
  412. package/lib/util/idAllocator.d.ts.map +1 -1
  413. package/lib/util/idAllocator.js +0 -2
  414. package/lib/util/idAllocator.js.map +1 -1
  415. package/lib/util/index.d.ts +3 -2
  416. package/lib/util/index.d.ts.map +1 -1
  417. package/lib/util/index.js +3 -2
  418. package/lib/util/index.js.map +1 -1
  419. package/lib/util/rangeMap.d.ts +95 -43
  420. package/lib/util/rangeMap.d.ts.map +1 -1
  421. package/lib/util/rangeMap.js +200 -144
  422. package/lib/util/rangeMap.js.map +1 -1
  423. package/lib/util/utils.d.ts +26 -2
  424. package/lib/util/utils.d.ts.map +1 -1
  425. package/lib/util/utils.js +15 -1
  426. package/lib/util/utils.js.map +1 -1
  427. package/package.json +24 -24
  428. package/src/core/index.ts +5 -2
  429. package/src/core/rebase/index.ts +5 -0
  430. package/src/core/rebase/types.ts +33 -5
  431. package/src/core/rebase/utils.ts +27 -0
  432. package/src/core/tree/delta.ts +21 -26
  433. package/src/core/tree/deltaUtil.ts +1 -16
  434. package/src/core/tree/index.ts +0 -2
  435. package/src/core/tree/visitDelta.ts +108 -97
  436. package/src/feature-libraries/default-schema/defaultEditBuilder.ts +14 -1
  437. package/src/feature-libraries/default-schema/defaultFieldKinds.ts +2 -2
  438. package/src/feature-libraries/deltaUtils.ts +13 -0
  439. package/src/feature-libraries/forest-summary/forestSummarizer.ts +1 -6
  440. package/src/feature-libraries/index.ts +0 -1
  441. package/src/feature-libraries/modular-schema/crossFieldQueries.ts +12 -13
  442. package/src/feature-libraries/modular-schema/fieldChangeHandler.ts +33 -9
  443. package/src/feature-libraries/modular-schema/genericFieldKind.ts +6 -4
  444. package/src/feature-libraries/modular-schema/index.ts +3 -0
  445. package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +12 -11
  446. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +254 -248
  447. package/src/feature-libraries/modular-schema/modularChangeTypes.ts +51 -26
  448. package/src/feature-libraries/optional-field/optionalField.ts +37 -8
  449. package/src/feature-libraries/sequence-field/moveEffectTable.ts +1 -1
  450. package/src/feature-libraries/sequence-field/rebase.ts +9 -3
  451. package/src/feature-libraries/sequence-field/sequenceFieldCodecV1.ts +1 -1
  452. package/src/feature-libraries/sequence-field/sequenceFieldCodecV2.ts +1 -1
  453. package/src/feature-libraries/sequence-field/sequenceFieldToDelta.ts +3 -4
  454. package/src/feature-libraries/sequence-field/utils.ts +54 -11
  455. package/src/feature-libraries/treeCursorUtils.ts +6 -1
  456. package/src/index.ts +45 -6
  457. package/src/packageVersion.ts +1 -1
  458. package/src/shared-tree/index.ts +16 -3
  459. package/src/shared-tree/schematizingTreeView.ts +91 -2
  460. package/src/shared-tree/sharedTree.ts +69 -44
  461. package/src/shared-tree/transactionTypes.ts +125 -0
  462. package/src/shared-tree/treeApi.ts +1 -28
  463. package/src/shared-tree/treeCheckout.ts +166 -25
  464. package/src/shared-tree-core/sharedTreeCore.ts +1 -1
  465. package/src/simple-tree/api/index.ts +1 -0
  466. package/src/simple-tree/api/jsonSchema.ts +7 -0
  467. package/src/simple-tree/api/schemaFactory.ts +33 -6
  468. package/src/simple-tree/api/schemaFactoryAlpha.ts +253 -0
  469. package/src/simple-tree/api/simpleSchema.ts +6 -1
  470. package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +22 -12
  471. package/src/simple-tree/api/tree.ts +76 -4
  472. package/src/simple-tree/api/treeNodeApi.ts +1 -1
  473. package/src/simple-tree/api/viewSchemaToSimpleSchema.ts +19 -13
  474. package/src/simple-tree/arrayNode.ts +8 -2
  475. package/src/simple-tree/core/treeNodeSchema.ts +51 -7
  476. package/src/simple-tree/index.ts +3 -0
  477. package/src/simple-tree/mapNode.ts +7 -1
  478. package/src/simple-tree/objectNode.ts +7 -1
  479. package/src/simple-tree/objectNodeTypes.ts +4 -1
  480. package/src/simple-tree/schemaTypes.ts +50 -1
  481. package/src/simple-tree/toMapTree.ts +1 -1
  482. package/src/util/bTreeUtils.ts +60 -0
  483. package/src/util/idAllocator.ts +0 -2
  484. package/src/util/index.ts +5 -6
  485. package/src/util/rangeMap.ts +259 -184
  486. package/src/util/utils.ts +57 -4
  487. package/dist/feature-libraries/memoizedIdRangeAllocator.d.ts +0 -38
  488. package/dist/feature-libraries/memoizedIdRangeAllocator.d.ts.map +0 -1
  489. package/dist/feature-libraries/memoizedIdRangeAllocator.js +0 -74
  490. package/dist/feature-libraries/memoizedIdRangeAllocator.js.map +0 -1
  491. package/lib/feature-libraries/memoizedIdRangeAllocator.d.ts +0 -38
  492. package/lib/feature-libraries/memoizedIdRangeAllocator.d.ts.map +0 -1
  493. package/lib/feature-libraries/memoizedIdRangeAllocator.js +0 -71
  494. package/lib/feature-libraries/memoizedIdRangeAllocator.js.map +0 -1
  495. package/lib/package.json +0 -3
  496. package/src/feature-libraries/memoizedIdRangeAllocator.ts +0 -112
@@ -40,6 +40,7 @@ import {
40
40
  createFieldSchema,
41
41
  type DefaultProvider,
42
42
  getDefaultProvider,
43
+ type NodeSchemaOptions,
43
44
  } from "../schemaTypes.js";
44
45
  import { inPrototypeChain } from "../core/index.js";
45
46
  import type {
@@ -103,11 +104,15 @@ export function schemaFromValue(value: TreeValue): TreeNodeSchema {
103
104
 
104
105
  /**
105
106
  * Options when declaring an {@link SchemaFactory.object|object node}'s schema
107
+ *
108
+ * @alpha
106
109
  */
107
- export interface SchemaFactoryObjectOptions {
110
+ export interface SchemaFactoryObjectOptions<TCustomMetadata = unknown>
111
+ extends NodeSchemaOptions<TCustomMetadata> {
108
112
  /**
109
- * Opt in to viewing documents which have unknown optional fields for this object's identifier, i.e. optional fields
110
- * in the document schema which are not present in this object schema declaration.
113
+ * Allow nodes typed with this object node schema to contain optional fields that are not present in the schema declaration.
114
+ * Such nodes can come into existence either via import APIs (see remarks) or by way of collaboration with another client
115
+ * that has upgraded the document's schema to include those optional fields.
111
116
  *
112
117
  * @defaultValue `false`
113
118
  * @remarks
@@ -149,7 +154,9 @@ export interface SchemaFactoryObjectOptions {
149
154
  allowUnknownOptionalFields?: boolean;
150
155
  }
151
156
 
152
- export const defaultSchemaFactoryObjectOptions: Required<SchemaFactoryObjectOptions> = {
157
+ export const defaultSchemaFactoryObjectOptions: Required<
158
+ Omit<SchemaFactoryObjectOptions, "metadata">
159
+ > = {
153
160
  allowUnknownOptionalFields: false,
154
161
  };
155
162
 
@@ -400,6 +407,8 @@ export class SchemaFactory<
400
407
  /**
401
408
  * Define a structurally typed {@link TreeNodeSchema} for a {@link TreeMapNode}.
402
409
  *
410
+ * @param allowedTypes - The types that may appear as values in the map.
411
+ *
403
412
  * @remarks
404
413
  * The unique identifier for this Map is defined as a function of the provided types.
405
414
  * It is still scoped to this SchemaBuilder, but multiple calls with the same arguments will return the same schema object, providing somewhat structural typing.
@@ -436,6 +445,7 @@ export class SchemaFactory<
436
445
  * Define a {@link TreeNodeSchema} for a {@link TreeMapNode}.
437
446
  *
438
447
  * @param name - Unique identifier for this schema within this factory's scope.
448
+ * @param allowedTypes - The types that may appear as values in the map.
439
449
  *
440
450
  * @example
441
451
  * ```typescript
@@ -456,6 +466,8 @@ export class SchemaFactory<
456
466
  >;
457
467
 
458
468
  /**
469
+ * {@link SchemaFactory.map} implementation.
470
+ *
459
471
  * @privateRemarks
460
472
  * This should return `TreeNodeSchemaBoth`, however TypeScript gives an error if one of the overloads implicitly up-casts the return type of the implementation.
461
473
  * This seems like a TypeScript bug getting variance backwards for overload return types since it's erroring when the relation between the overload
@@ -530,12 +542,15 @@ export class SchemaFactory<
530
542
  implicitlyConstructable,
531
543
  // The current policy is customizable nodes don't get fake prototypes.
532
544
  !customizable,
545
+ undefined,
533
546
  );
534
547
  }
535
548
 
536
549
  /**
537
550
  * Define a structurally typed {@link TreeNodeSchema} for a {@link (TreeArrayNode:interface)}.
538
551
  *
552
+ * @param allowedTypes - The types that may appear in the array.
553
+ *
539
554
  * @remarks
540
555
  * The identifier for this Array is defined as a function of the provided types.
541
556
  * It is still scoped to this SchemaFactory, but multiple calls with the same arguments will return the same schema object, providing somewhat structural typing.
@@ -582,6 +597,7 @@ export class SchemaFactory<
582
597
  * Define (and add to this library) a {@link TreeNodeSchemaClass} for a {@link (TreeArrayNode:interface)}.
583
598
  *
584
599
  * @param name - Unique identifier for this schema within this factory's scope.
600
+ * @param allowedTypes - The types that may appear in the array.
585
601
  *
586
602
  * @example
587
603
  * ```typescript
@@ -604,6 +620,8 @@ export class SchemaFactory<
604
620
  >;
605
621
 
606
622
  /**
623
+ * {@link SchemaFactory.array} implementation.
624
+ *
607
625
  * @privateRemarks
608
626
  * This should return TreeNodeSchemaBoth: see note on "map" implementation for details.
609
627
  */
@@ -787,11 +805,20 @@ export class SchemaFactory<
787
805
  * `error TS2589: Type instantiation is excessively deep and possibly infinite.`
788
806
  * which otherwise gets reported at sometimes incorrect source locations that vary based on incremental builds.
789
807
  */
790
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
791
808
  public objectRecursive<
792
809
  const Name extends TName,
793
810
  const T extends Unenforced<RestrictiveStringRecord<ImplicitFieldSchema>>,
794
- >(name: Name, t: T) {
811
+ >(
812
+ name: Name,
813
+ t: T,
814
+ ): TreeNodeSchemaClass<
815
+ ScopedSchemaName<TScope, Name>,
816
+ NodeKind.Object,
817
+ TreeObjectNodeUnsafe<T, ScopedSchemaName<TScope, Name>>,
818
+ object & InsertableObjectFromSchemaRecordUnsafe<T>,
819
+ false,
820
+ T
821
+ > {
795
822
  type TScopedName = ScopedSchemaName<TScope, Name>;
796
823
  return this.object(
797
824
  name,
@@ -0,0 +1,253 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import type {
7
+ ScopedSchemaName,
8
+ InsertableObjectFromSchemaRecord,
9
+ TreeObjectNodeUnsafe,
10
+ InsertableObjectFromSchemaRecordUnsafe,
11
+ } from "../../internalTypes.js";
12
+ import {
13
+ defaultSchemaFactoryObjectOptions,
14
+ SchemaFactory,
15
+ type SchemaFactoryObjectOptions,
16
+ } from "./schemaFactory.js";
17
+ import type {
18
+ ImplicitAllowedTypes,
19
+ ImplicitFieldSchema,
20
+ InsertableTreeNodeFromImplicitAllowedTypes,
21
+ NodeSchemaOptions,
22
+ } from "../schemaTypes.js";
23
+ import { type TreeObjectNode, objectSchema } from "../objectNode.js";
24
+ import type { RestrictiveStringRecord } from "../../util/index.js";
25
+ import type { NodeKind, TreeNodeSchemaClass, WithType } from "../core/index.js";
26
+ import type {
27
+ InsertableTreeNodeFromImplicitAllowedTypesUnsafe,
28
+ TreeArrayNodeUnsafe,
29
+ TreeMapNodeUnsafe,
30
+ Unenforced,
31
+ } from "./typesUnsafe.js";
32
+ import { mapSchema, type MapNodeInsertableData, type TreeMapNode } from "../mapNode.js";
33
+ import { arraySchema, type TreeArrayNode } from "../arrayNode.js";
34
+
35
+ /**
36
+ * {@link SchemaFactory} with additional alpha APIs.
37
+ *
38
+ * @alpha
39
+ * @privateRemarks
40
+ *
41
+ * Some private methods on `SchemaFactory` are intentionally duplicated here to avoid increasing their exposure to `protected`.
42
+ * If we were to do so, they would be exposed on the public API surface of `SchemaFactory`.
43
+ */
44
+ export class SchemaFactoryAlpha<
45
+ out TScope extends string | undefined = string | undefined,
46
+ TName extends number | string = string,
47
+ > extends SchemaFactory<TScope, TName> {
48
+ private scoped2<Name extends TName | string>(name: Name): ScopedSchemaName<TScope, Name> {
49
+ return (
50
+ this.scope === undefined ? `${name}` : `${this.scope}.${name}`
51
+ ) as ScopedSchemaName<TScope, Name>;
52
+ }
53
+
54
+ /**
55
+ * Define a {@link TreeNodeSchemaClass} for a {@link TreeObjectNode}.
56
+ *
57
+ * @param name - Unique identifier for this schema within this factory's scope.
58
+ * @param fields - Schema for fields of the object node's schema. Defines what children can be placed under each key.
59
+ * @param options - Additional options for the schema.
60
+ */
61
+ public override object<
62
+ const Name extends TName,
63
+ const T extends RestrictiveStringRecord<ImplicitFieldSchema>,
64
+ const TCustomMetadata = unknown,
65
+ >(
66
+ name: Name,
67
+ fields: T,
68
+ options?: SchemaFactoryObjectOptions<TCustomMetadata>,
69
+ ): TreeNodeSchemaClass<
70
+ ScopedSchemaName<TScope, Name>,
71
+ NodeKind.Object,
72
+ TreeObjectNode<T, ScopedSchemaName<TScope, Name>>,
73
+ object & InsertableObjectFromSchemaRecord<T>,
74
+ true,
75
+ T,
76
+ never,
77
+ TCustomMetadata
78
+ > {
79
+ return objectSchema(
80
+ this.scoped2(name),
81
+ fields,
82
+ true,
83
+ options?.allowUnknownOptionalFields ??
84
+ defaultSchemaFactoryObjectOptions.allowUnknownOptionalFields,
85
+ options?.metadata,
86
+ );
87
+ }
88
+
89
+ /**
90
+ * {@inheritdoc SchemaFactory.objectRecursive}
91
+ */
92
+ public override objectRecursive<
93
+ const Name extends TName,
94
+ const T extends Unenforced<RestrictiveStringRecord<ImplicitFieldSchema>>,
95
+ const TCustomMetadata = unknown,
96
+ >(
97
+ name: Name,
98
+ t: T,
99
+ options?: SchemaFactoryObjectOptions<TCustomMetadata>,
100
+ ): TreeNodeSchemaClass<
101
+ ScopedSchemaName<TScope, Name>,
102
+ NodeKind.Object,
103
+ TreeObjectNodeUnsafe<T, ScopedSchemaName<TScope, Name>>,
104
+ object & InsertableObjectFromSchemaRecordUnsafe<T>,
105
+ false,
106
+ T,
107
+ never,
108
+ TCustomMetadata
109
+ > {
110
+ type TScopedName = ScopedSchemaName<TScope, Name>;
111
+ return this.object(
112
+ name,
113
+ t as T & RestrictiveStringRecord<ImplicitFieldSchema>,
114
+ options,
115
+ ) as unknown as TreeNodeSchemaClass<
116
+ TScopedName,
117
+ NodeKind.Object,
118
+ TreeObjectNodeUnsafe<T, TScopedName>,
119
+ object & InsertableObjectFromSchemaRecordUnsafe<T>,
120
+ false,
121
+ T,
122
+ never,
123
+ TCustomMetadata
124
+ >;
125
+ }
126
+
127
+ /**
128
+ * Define a {@link TreeNodeSchema} for a {@link TreeMapNode}.
129
+ *
130
+ * @param name - Unique identifier for this schema within this factory's scope.
131
+ * @param allowedTypes - The types that may appear as values in the map.
132
+ * @param options - Additional options for the schema.
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * class NamedMap extends factory.map("name", factory.number, {
137
+ * metadata: { description: "A map of numbers" }
138
+ * }) {}
139
+ * ```
140
+ */
141
+ public mapAlpha<
142
+ Name extends TName,
143
+ const T extends ImplicitAllowedTypes,
144
+ const TCustomMetadata = unknown,
145
+ >(
146
+ name: Name,
147
+ allowedTypes: T,
148
+ options?: NodeSchemaOptions<TCustomMetadata>,
149
+ ): TreeNodeSchemaClass<
150
+ ScopedSchemaName<TScope, Name>,
151
+ NodeKind.Map,
152
+ TreeMapNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Map>,
153
+ MapNodeInsertableData<T>,
154
+ true,
155
+ T,
156
+ undefined,
157
+ TCustomMetadata
158
+ > {
159
+ return mapSchema(this.scoped2(name), allowedTypes, true, true, options?.metadata);
160
+ }
161
+
162
+ /**
163
+ * {@inheritDoc SchemaFactory.objectRecursive}
164
+ */
165
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
166
+ public override mapRecursive<
167
+ Name extends TName,
168
+ const T extends Unenforced<ImplicitAllowedTypes>,
169
+ const TCustomMetadata = unknown,
170
+ >(name: Name, allowedTypes: T, options?: NodeSchemaOptions<TCustomMetadata>) {
171
+ return this.mapAlpha(
172
+ name,
173
+ allowedTypes as T & ImplicitAllowedTypes,
174
+ options,
175
+ ) as unknown as TreeNodeSchemaClass<
176
+ ScopedSchemaName<TScope, Name>,
177
+ NodeKind.Map,
178
+ TreeMapNodeUnsafe<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Map>,
179
+ | {
180
+ [Symbol.iterator](): Iterator<
181
+ [string, InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>]
182
+ >;
183
+ }
184
+ | {
185
+ readonly [P in string]: InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>;
186
+ },
187
+ false,
188
+ T,
189
+ undefined,
190
+ TCustomMetadata
191
+ >;
192
+ }
193
+
194
+ /**
195
+ * Define (and add to this library) a {@link TreeNodeSchemaClass} for a {@link (TreeArrayNode:interface)}.
196
+ *
197
+ * @param name - Unique identifier for this schema within this factory's scope.
198
+ * @param allowedTypes - The types that may appear in the array.
199
+ * @param options - Additional options for the schema.
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * class NamedArray extends factory.array("name", factory.number) {}
204
+ * ```
205
+ */
206
+ public arrayAlpha<
207
+ const Name extends TName,
208
+ const T extends ImplicitAllowedTypes,
209
+ const TCustomMetadata = unknown,
210
+ >(
211
+ name: Name,
212
+ allowedTypes: T,
213
+ options?: NodeSchemaOptions<TCustomMetadata>,
214
+ ): TreeNodeSchemaClass<
215
+ ScopedSchemaName<TScope, Name>,
216
+ NodeKind.Array,
217
+ TreeArrayNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Array>,
218
+ Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>,
219
+ true,
220
+ T,
221
+ undefined,
222
+ TCustomMetadata
223
+ > {
224
+ return arraySchema(this.scoped2(name), allowedTypes, true, true, options?.metadata);
225
+ }
226
+
227
+ /**
228
+ * {@inheritDoc SchemaFactory.objectRecursive}
229
+ */
230
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
231
+ public override arrayRecursive<
232
+ const Name extends TName,
233
+ const T extends Unenforced<ImplicitAllowedTypes>,
234
+ const TCustomMetadata = unknown,
235
+ >(name: Name, allowedTypes: T, options?: NodeSchemaOptions<TCustomMetadata>) {
236
+ return this.arrayAlpha(
237
+ name,
238
+ allowedTypes as T & ImplicitAllowedTypes,
239
+ options,
240
+ ) as unknown as TreeNodeSchemaClass<
241
+ ScopedSchemaName<TScope, Name>,
242
+ NodeKind.Array,
243
+ TreeArrayNodeUnsafe<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Array>,
244
+ {
245
+ [Symbol.iterator](): Iterator<InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>>;
246
+ },
247
+ false,
248
+ T,
249
+ undefined,
250
+ TCustomMetadata
251
+ >;
252
+ }
253
+ }
@@ -5,7 +5,7 @@
5
5
 
6
6
  import type { ValueSchema } from "../../core/index.js";
7
7
  import type { NodeKind } from "../core/index.js";
8
- import type { FieldKind, FieldSchemaMetadata } from "../schemaTypes.js";
8
+ import type { FieldKind, FieldSchemaMetadata, NodeSchemaMetadata } from "../schemaTypes.js";
9
9
 
10
10
  /**
11
11
  * Base interface for all {@link SimpleNodeSchema} implementations.
@@ -20,6 +20,11 @@ export interface SimpleNodeSchemaBase<TNodeKind extends NodeKind> {
20
20
  * @remarks can be used to type-switch between implementations.
21
21
  */
22
22
  readonly kind: TNodeKind;
23
+
24
+ /**
25
+ * {@inheritDoc NodeSchemaMetadata}
26
+ */
27
+ readonly metadata?: NodeSchemaMetadata | undefined;
23
28
  }
24
29
 
25
30
  /**
@@ -6,7 +6,7 @@
6
6
  import { unreachableCase } from "@fluidframework/core-utils/internal";
7
7
  import { UsageError } from "@fluidframework/telemetry-utils/internal";
8
8
  import { ValueSchema } from "../../core/index.js";
9
- import { getOrCreate, hasSingle, type Mutable } from "../../util/index.js";
9
+ import { copyProperty, getOrCreate, hasSingle, type Mutable } from "../../util/index.js";
10
10
  import type {
11
11
  JsonArrayNodeSchema,
12
12
  JsonFieldSchema,
@@ -100,11 +100,15 @@ function convertArrayNodeSchema(schema: SimpleArrayNodeSchema): JsonArrayNodeSch
100
100
  ? allowedTypes[0]
101
101
  : { anyOf: allowedTypes };
102
102
 
103
- return {
103
+ const output: Mutable<JsonArrayNodeSchema> = {
104
104
  type: "array",
105
105
  _treeNodeSchemaKind: NodeKind.Array,
106
106
  items,
107
107
  };
108
+
109
+ copyProperty(schema.metadata, "description", output);
110
+
111
+ return output;
108
112
  }
109
113
 
110
114
  function convertLeafNodeSchema(schema: SimpleLeafNodeSchema): JsonLeafNodeSchema {
@@ -137,9 +141,9 @@ function convertLeafNodeSchema(schema: SimpleLeafNodeSchema): JsonLeafNodeSchema
137
141
  function convertObjectNodeSchema(schema: SimpleObjectNodeSchema): JsonObjectNodeSchema {
138
142
  const properties: Record<string, JsonFieldSchema> = {};
139
143
  const required: string[] = [];
140
- for (const [key, value] of Object.entries(schema.fields)) {
144
+ for (const [key, fieldSchema] of Object.entries(schema.fields)) {
141
145
  const allowedTypes: JsonSchemaRef[] = [];
142
- for (const allowedType of value.allowedTypes) {
146
+ for (const allowedType of fieldSchema.allowedTypes) {
143
147
  allowedTypes.push(createSchemaRef(allowedType));
144
148
  }
145
149
 
@@ -149,24 +153,25 @@ function convertObjectNodeSchema(schema: SimpleObjectNodeSchema): JsonObjectNode
149
153
  anyOf: allowedTypes,
150
154
  };
151
155
 
152
- // Don't include "description" property at all if it's not present in the input.
153
- if (value.metadata?.description !== undefined) {
154
- output.description = value.metadata.description;
155
- }
156
-
156
+ copyProperty(fieldSchema.metadata, "description", output);
157
157
  properties[key] = output;
158
158
 
159
- if (value.kind === FieldKind.Required) {
159
+ if (fieldSchema.kind === FieldKind.Required) {
160
160
  required.push(key);
161
161
  }
162
162
  }
163
- return {
163
+
164
+ const transformedNode: Mutable<JsonObjectNodeSchema> = {
164
165
  type: "object",
165
166
  _treeNodeSchemaKind: NodeKind.Object,
166
167
  properties,
167
168
  required,
168
169
  additionalProperties: false,
169
170
  };
171
+
172
+ copyProperty(schema.metadata, "description", transformedNode);
173
+
174
+ return transformedNode;
170
175
  }
171
176
 
172
177
  function convertMapNodeSchema(schema: SimpleMapNodeSchema): JsonMapNodeSchema {
@@ -174,7 +179,8 @@ function convertMapNodeSchema(schema: SimpleMapNodeSchema): JsonMapNodeSchema {
174
179
  schema.allowedTypes.forEach((type) => {
175
180
  allowedTypes.push(createSchemaRef(type));
176
181
  });
177
- return {
182
+
183
+ const output: Mutable<JsonMapNodeSchema> = {
178
184
  type: "object",
179
185
  _treeNodeSchemaKind: NodeKind.Map,
180
186
  patternProperties: {
@@ -185,6 +191,10 @@ function convertMapNodeSchema(schema: SimpleMapNodeSchema): JsonMapNodeSchema {
185
191
  },
186
192
  },
187
193
  };
194
+
195
+ copyProperty(schema.metadata, "description", output);
196
+
197
+ return output;
188
198
  }
189
199
 
190
200
  function createSchemaRef(schemaId: string): JsonSchemaRef {
@@ -12,9 +12,16 @@ import type {
12
12
  RevertibleFactory,
13
13
  } from "../../core/index.js";
14
14
 
15
- // This is referenced by doc comments.
16
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, unused-imports/no-unused-imports
17
- import type { TreeAlpha } from "../../shared-tree/index.js";
15
+ import type {
16
+ RunTransactionParams,
17
+ VoidTransactionCallbackStatus,
18
+ TransactionCallbackStatus,
19
+ TransactionResult,
20
+ TransactionResultExt,
21
+ // This is referenced by doc comments.
22
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, unused-imports/no-unused-imports
23
+ TreeAlpha,
24
+ } from "../../shared-tree/index.js";
18
25
 
19
26
  import {
20
27
  type ImplicitFieldSchema,
@@ -35,7 +42,6 @@ import { markSchemaMostDerived } from "./schemaFactory.js";
35
42
  import { fail, getOrCreate } from "../../util/index.js";
36
43
  import type { MakeNominal } from "../../util/index.js";
37
44
  import { walkFieldSchema } from "../walkFieldSchema.js";
38
-
39
45
  /**
40
46
  * A tree from which a {@link TreeView} can be created.
41
47
  *
@@ -542,6 +548,72 @@ export interface TreeViewAlpha<
542
548
 
543
549
  // Override the base branch method to return a typed view rather than merely a branch.
544
550
  fork(): ReturnType<TreeBranch["fork"]> & TreeViewAlpha<TSchema>;
551
+
552
+ /**
553
+ * Run a transaction which applies one or more edits to the tree as a single atomic unit.
554
+ * @param transaction - The function to run as the body of the transaction.
555
+ * It should return a status object of {@link TransactionCallbackStatus | TransactionCallbackStatus } type.
556
+ * It includes a "rollback" property which may be returned as true at any point during the transaction. This will
557
+ * abort the transaction and discard any changes it made so far.
558
+ * "rollback" can be set to false or left undefined to indicate that the body of the transaction has successfully run.
559
+ * @param params - The optional parameters for the transaction. It includes the constraints that will be checked before the transaction begins.
560
+ * @returns A result object of {@link TransactionResultExt | TransactionResultExt} type. It includes the following:
561
+ * - A "success" flag indicating whether the transaction was successful or not.
562
+ * - The success of failure value as returned by the transaction function.
563
+ * @remarks
564
+ * This API will throw an error if the constraints are not met or something unexpected happens.
565
+ * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.
566
+ * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.
567
+ * However, using a transaction has the following additional consequences:
568
+ * - If reverted (e.g. via an "undo" operation), all the changes in the transaction are reverted together.
569
+ * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.
570
+ *
571
+ * Local change events will be emitted for each change as the transaction is being applied.
572
+ * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.
573
+ *
574
+ * Nested transactions:
575
+ * This API can be called from within the transaction callback of another runTransaction call. That will have slightly different behavior:
576
+ * - If the inner transaction fails, only the inner transaction will be rolled back and the outer transaction will continue.
577
+ * - Constraints will apply to the outermost transaction. Constraints are applied per commit and there will be one commit generated
578
+ * for the outermost transaction which includes all inner transactions.
579
+ * - Undo will undo the outermost transaction and all inner transactions.
580
+ */
581
+ runTransaction<TSuccessValue, TFailureValue>(
582
+ transaction: () => TransactionCallbackStatus<TSuccessValue, TFailureValue>,
583
+ params?: RunTransactionParams,
584
+ ): TransactionResultExt<TSuccessValue, TFailureValue>;
585
+ /**
586
+ * Run a transaction which applies one or more edits to the tree as a single atomic unit.
587
+ * @param transaction - The function to run as the body of the transaction. It may return the following:
588
+ * - Nothing to indicate that the body of the transaction has successfully run.
589
+ * - A status object of {@link VoidTransactionCallbackStatus | VoidTransactionCallbackStatus } type. It includes a "rollback" property which
590
+ * may be returned as true at any point during the transaction. This will abort the transaction and discard any changes it made so
591
+ * far. "rollback" can be set to false or left undefined to indicate that the body of the transaction has successfully run.
592
+ * @param params - The optional parameters for the transaction. It includes the constraints that will be checked before the transaction begins.
593
+ * @returns A result object of {@link TransactionResult | TransactionResult} type. It includes a "success" flag indicating whether the
594
+ * transaction was successful or not.
595
+ * @remarks
596
+ * This API will throw an error if the constraints are not met or something unexpected happens.
597
+ * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.
598
+ * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.
599
+ * However, using a transaction has the following additional consequences:
600
+ * - If reverted (e.g. via an "undo" operation), all the changes in the transaction are reverted together.
601
+ * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.
602
+ *
603
+ * Local change events will be emitted for each change as the transaction is being applied.
604
+ * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.
605
+ *
606
+ * Nested transactions:
607
+ * This API can be called from within the transaction callback of another runTransaction call. That will have slightly different behavior:
608
+ * - If the inner transaction fails, only the inner transaction will be rolled back and the outer transaction will continue.
609
+ * - Constraints will apply to the outermost transaction. Constraints are applied per commit and there will be one commit generated
610
+ * for the outermost transaction which includes all inner transactions.
611
+ * - Undo will undo the outermost transaction and all inner transactions.
612
+ */
613
+ runTransaction(
614
+ transaction: () => VoidTransactionCallbackStatus | void,
615
+ params?: RunTransactionParams,
616
+ ): TransactionResult;
545
617
  }
546
618
 
547
619
  /**
@@ -174,7 +174,7 @@ export const treeNodeApi: TreeNodeApi = {
174
174
  changedFields,
175
175
  (field) =>
176
176
  nodeSchema.storedKeyToPropertyKey.get(field) ??
177
- fail(`Could not find stored key '${field}' in schema.`),
177
+ fail("Could not find stored key in schema."),
178
178
  ),
179
179
  );
180
180
  listener({ changedProperties });
@@ -20,7 +20,7 @@ import type {
20
20
  SimpleTreeSchema,
21
21
  } from "./simpleSchema.js";
22
22
  import type { ValueSchema } from "../../core/index.js";
23
- import { getOrCreate, type Mutable } from "../../util/index.js";
23
+ import { copyProperty, getOrCreate, type Mutable } from "../../util/index.js";
24
24
  import { isObjectNodeSchema, type ObjectNodeSchema } from "../objectNodeTypes.js";
25
25
  import { NodeKind, type TreeNodeSchema } from "../core/index.js";
26
26
 
@@ -41,11 +41,7 @@ export function toSimpleTreeSchema(schema: ImplicitFieldSchema): SimpleTreeSchem
41
41
  definitions,
42
42
  };
43
43
 
44
- // Include the "description" property only if it's present on the input.
45
- if (normalizedSchema.metadata !== undefined) {
46
- output.metadata = normalizedSchema.metadata;
47
- }
48
-
44
+ copyProperty(normalizedSchema, "metadata", output);
49
45
  return output;
50
46
  }
51
47
 
@@ -95,20 +91,28 @@ function leafSchemaToSimpleSchema(schema: TreeNodeSchema): SimpleLeafNodeSchema
95
91
  function arraySchemaToSimpleSchema(schema: TreeNodeSchema): SimpleArrayNodeSchema {
96
92
  const fieldSchema = normalizeFieldSchema(schema.info as ImplicitAllowedTypes);
97
93
  const allowedTypes = allowedTypesFromFieldSchema(fieldSchema);
98
- return {
94
+ const output: Mutable<SimpleArrayNodeSchema> = {
99
95
  kind: NodeKind.Array,
100
96
  allowedTypes,
101
97
  };
98
+
99
+ copyProperty(schema, "metadata", output);
100
+
101
+ return output;
102
102
  }
103
103
 
104
104
  // TODO: Use a stronger type for map schemas once one is available (see object schema handler for an example).
105
105
  function mapSchemaToSimpleSchema(schema: TreeNodeSchema): SimpleMapNodeSchema {
106
106
  const fieldSchema = normalizeFieldSchema(schema.info as ImplicitAllowedTypes);
107
107
  const allowedTypes = allowedTypesFromFieldSchema(fieldSchema);
108
- return {
108
+ const output: Mutable<SimpleMapNodeSchema> = {
109
109
  kind: NodeKind.Map,
110
110
  allowedTypes,
111
111
  };
112
+
113
+ copyProperty(schema, "metadata", output);
114
+
115
+ return output;
112
116
  }
113
117
 
114
118
  function objectSchemaToSimpleSchema(schema: ObjectNodeSchema): SimpleObjectNodeSchema {
@@ -116,10 +120,15 @@ function objectSchemaToSimpleSchema(schema: ObjectNodeSchema): SimpleObjectNodeS
116
120
  for (const [key, field] of schema.fields) {
117
121
  fields[key] = fieldSchemaToSimpleSchema(field);
118
122
  }
119
- return {
123
+
124
+ const output: Mutable<SimpleObjectNodeSchema> = {
120
125
  kind: NodeKind.Object,
121
126
  fields,
122
127
  };
128
+
129
+ copyProperty(schema, "metadata", output);
130
+
131
+ return output;
123
132
  }
124
133
 
125
134
  /**
@@ -140,10 +149,7 @@ function fieldSchemaToSimpleSchema(schema: FieldSchema): SimpleFieldSchema {
140
149
  allowedTypes,
141
150
  };
142
151
 
143
- // Don't include "metadata" property at all if it's not present.
144
- if (schema.metadata !== undefined) {
145
- result.metadata = schema.metadata;
146
- }
152
+ copyProperty(schema, "metadata", result);
147
153
 
148
154
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
149
155
  (schema as any)[simpleFieldSchemaCacheSymbol] = result;