@fluidframework/tree 2.52.0 → 2.53.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 (488) hide show
  1. package/.eslintrc.cjs +14 -2
  2. package/CHANGELOG.md +125 -0
  3. package/api-report/tree.alpha.api.md +48 -41
  4. package/dist/alpha.d.ts +2 -1
  5. package/dist/core/tree/visitDelta.d.ts +1 -1
  6. package/dist/core/tree/visitDelta.d.ts.map +1 -1
  7. package/dist/core/tree/visitDelta.js.map +1 -1
  8. package/dist/feature-libraries/chunked-forest/index.d.ts +1 -0
  9. package/dist/feature-libraries/chunked-forest/index.d.ts.map +1 -1
  10. package/dist/feature-libraries/chunked-forest/index.js +3 -1
  11. package/dist/feature-libraries/chunked-forest/index.js.map +1 -1
  12. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts +2 -4
  13. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  14. package/dist/feature-libraries/default-schema/defaultEditBuilder.js +3 -0
  15. package/dist/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  16. package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  17. package/dist/feature-libraries/default-schema/defaultFieldKinds.js +1 -0
  18. package/dist/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  19. package/dist/feature-libraries/default-schema/noChangeCodecs.d.ts +1 -1
  20. package/dist/feature-libraries/default-schema/noChangeCodecs.d.ts.map +1 -1
  21. package/dist/feature-libraries/default-schema/noChangeCodecs.js.map +1 -1
  22. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts +4 -0
  23. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  24. package/dist/feature-libraries/forest-summary/forestSummarizer.js +5 -5
  25. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  26. package/dist/feature-libraries/index.d.ts +1 -1
  27. package/dist/feature-libraries/index.d.ts.map +1 -1
  28. package/dist/feature-libraries/index.js +4 -2
  29. package/dist/feature-libraries/index.js.map +1 -1
  30. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts +7 -0
  31. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  32. package/dist/feature-libraries/modular-schema/fieldChangeHandler.js +1 -0
  33. package/dist/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  34. package/dist/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
  35. package/dist/feature-libraries/modular-schema/genericFieldKind.js +1 -0
  36. package/dist/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  37. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +1 -0
  38. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  39. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts +9 -1
  40. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  41. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +49 -20
  42. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  43. package/dist/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
  44. package/dist/feature-libraries/optional-field/optionalField.js +3 -0
  45. package/dist/feature-libraries/optional-field/optionalField.js.map +1 -1
  46. package/dist/feature-libraries/sequence-field/sequenceFieldChangeRebaser.d.ts +1 -0
  47. package/dist/feature-libraries/sequence-field/sequenceFieldChangeRebaser.d.ts.map +1 -1
  48. package/dist/feature-libraries/sequence-field/sequenceFieldChangeRebaser.js +4 -0
  49. package/dist/feature-libraries/sequence-field/sequenceFieldChangeRebaser.js.map +1 -1
  50. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV1.d.ts +1 -1
  51. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV1.d.ts.map +1 -1
  52. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV1.js.map +1 -1
  53. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts +1 -1
  54. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts.map +1 -1
  55. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  56. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts +1 -1
  57. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts.map +1 -1
  58. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.js.map +1 -1
  59. package/dist/feature-libraries/sequence-field/sequenceFieldCodecs.d.ts +1 -1
  60. package/dist/feature-libraries/sequence-field/sequenceFieldCodecs.d.ts.map +1 -1
  61. package/dist/feature-libraries/sequence-field/sequenceFieldCodecs.js.map +1 -1
  62. package/dist/feature-libraries/sequence-field/types.d.ts +1 -1
  63. package/dist/feature-libraries/sequence-field/types.d.ts.map +1 -1
  64. package/dist/feature-libraries/sequence-field/types.js.map +1 -1
  65. package/dist/index.d.ts +1 -1
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +3 -2
  68. package/dist/index.js.map +1 -1
  69. package/dist/jsonDomainSchema.d.ts +5 -3
  70. package/dist/jsonDomainSchema.d.ts.map +1 -1
  71. package/dist/jsonDomainSchema.js.map +1 -1
  72. package/dist/packageVersion.d.ts +1 -1
  73. package/dist/packageVersion.js +1 -1
  74. package/dist/packageVersion.js.map +1 -1
  75. package/dist/shared-tree/independentView.d.ts.map +1 -1
  76. package/dist/shared-tree/independentView.js +1 -1
  77. package/dist/shared-tree/independentView.js.map +1 -1
  78. package/dist/shared-tree/index.d.ts +0 -1
  79. package/dist/shared-tree/index.d.ts.map +1 -1
  80. package/dist/shared-tree/index.js.map +1 -1
  81. package/dist/shared-tree/schematizeTree.d.ts +23 -60
  82. package/dist/shared-tree/schematizeTree.d.ts.map +1 -1
  83. package/dist/shared-tree/schematizeTree.js +59 -151
  84. package/dist/shared-tree/schematizeTree.js.map +1 -1
  85. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  86. package/dist/shared-tree/schematizingTreeView.js +11 -11
  87. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  88. package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
  89. package/dist/shared-tree/treeAlpha.js +9 -3
  90. package/dist/shared-tree/treeAlpha.js.map +1 -1
  91. package/dist/shared-tree-core/defaultResubmitMachine.d.ts +2 -1
  92. package/dist/shared-tree-core/defaultResubmitMachine.d.ts.map +1 -1
  93. package/dist/shared-tree-core/defaultResubmitMachine.js.map +1 -1
  94. package/dist/simple-tree/api/configuration.d.ts +3 -0
  95. package/dist/simple-tree/api/configuration.d.ts.map +1 -1
  96. package/dist/simple-tree/api/configuration.js +5 -1
  97. package/dist/simple-tree/api/configuration.js.map +1 -1
  98. package/dist/simple-tree/api/create.d.ts +4 -4
  99. package/dist/simple-tree/api/create.d.ts.map +1 -1
  100. package/dist/simple-tree/api/create.js +3 -6
  101. package/dist/simple-tree/api/create.js.map +1 -1
  102. package/dist/simple-tree/api/discrepancies.d.ts +5 -9
  103. package/dist/simple-tree/api/discrepancies.d.ts.map +1 -1
  104. package/dist/simple-tree/api/discrepancies.js +11 -10
  105. package/dist/simple-tree/api/discrepancies.js.map +1 -1
  106. package/dist/simple-tree/api/index.d.ts +3 -2
  107. package/dist/simple-tree/api/index.d.ts.map +1 -1
  108. package/dist/simple-tree/api/index.js +3 -2
  109. package/dist/simple-tree/api/index.js.map +1 -1
  110. package/dist/simple-tree/api/schemaCompatibilityTester.d.ts.map +1 -1
  111. package/dist/simple-tree/api/schemaCompatibilityTester.js +3 -4
  112. package/dist/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
  113. package/dist/simple-tree/api/schemaFactory.d.ts +9 -155
  114. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  115. package/dist/simple-tree/api/schemaFactory.js +4 -47
  116. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  117. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +157 -16
  118. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
  119. package/dist/simple-tree/api/schemaFactoryAlpha.js +33 -11
  120. package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
  121. package/dist/simple-tree/api/schemaFactoryRecursive.d.ts +1 -3
  122. package/dist/simple-tree/api/schemaFactoryRecursive.d.ts.map +1 -1
  123. package/dist/simple-tree/api/schemaFactoryRecursive.js +1 -7
  124. package/dist/simple-tree/api/schemaFactoryRecursive.js.map +1 -1
  125. package/dist/simple-tree/api/schemaStatics.d.ts +158 -0
  126. package/dist/simple-tree/api/schemaStatics.d.ts.map +1 -0
  127. package/dist/simple-tree/api/schemaStatics.js +59 -0
  128. package/dist/simple-tree/api/schemaStatics.js.map +1 -0
  129. package/dist/simple-tree/api/storedSchema.d.ts +5 -3
  130. package/dist/simple-tree/api/storedSchema.d.ts.map +1 -1
  131. package/dist/simple-tree/api/storedSchema.js +4 -2
  132. package/dist/simple-tree/api/storedSchema.js.map +1 -1
  133. package/dist/simple-tree/api/treeBeta.d.ts.map +1 -1
  134. package/dist/simple-tree/api/treeBeta.js +12 -6
  135. package/dist/simple-tree/api/treeBeta.js.map +1 -1
  136. package/dist/simple-tree/core/allowedTypes.d.ts +46 -30
  137. package/dist/simple-tree/core/allowedTypes.d.ts.map +1 -1
  138. package/dist/simple-tree/core/allowedTypes.js +20 -12
  139. package/dist/simple-tree/core/allowedTypes.js.map +1 -1
  140. package/dist/simple-tree/core/index.d.ts +5 -3
  141. package/dist/simple-tree/core/index.d.ts.map +1 -1
  142. package/dist/simple-tree/core/index.js +6 -1
  143. package/dist/simple-tree/core/index.js.map +1 -1
  144. package/dist/simple-tree/core/simpleNodeSchemaBase.d.ts +25 -0
  145. package/dist/simple-tree/core/simpleNodeSchemaBase.d.ts.map +1 -0
  146. package/dist/simple-tree/core/simpleNodeSchemaBase.js +7 -0
  147. package/dist/simple-tree/core/simpleNodeSchemaBase.js.map +1 -0
  148. package/dist/simple-tree/core/toStored.d.ts +32 -0
  149. package/dist/simple-tree/core/toStored.d.ts.map +1 -0
  150. package/dist/simple-tree/core/toStored.js +37 -0
  151. package/dist/simple-tree/core/toStored.js.map +1 -0
  152. package/dist/simple-tree/core/treeNode.d.ts +0 -3
  153. package/dist/simple-tree/core/treeNode.d.ts.map +1 -1
  154. package/dist/simple-tree/core/treeNode.js +3 -3
  155. package/dist/simple-tree/core/treeNode.js.map +1 -1
  156. package/dist/simple-tree/core/treeNodeSchema.d.ts +7 -2
  157. package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  158. package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
  159. package/dist/simple-tree/core/treeNodeValid.d.ts +6 -1
  160. package/dist/simple-tree/core/treeNodeValid.d.ts.map +1 -1
  161. package/dist/simple-tree/core/treeNodeValid.js +11 -6
  162. package/dist/simple-tree/core/treeNodeValid.js.map +1 -1
  163. package/dist/simple-tree/core/walkSchema.d.ts +19 -5
  164. package/dist/simple-tree/core/walkSchema.d.ts.map +1 -1
  165. package/dist/simple-tree/core/walkSchema.js +4 -2
  166. package/dist/simple-tree/core/walkSchema.js.map +1 -1
  167. package/dist/simple-tree/createContext.d.ts.map +1 -1
  168. package/dist/simple-tree/createContext.js +1 -1
  169. package/dist/simple-tree/createContext.js.map +1 -1
  170. package/dist/simple-tree/fieldSchema.d.ts +2 -1
  171. package/dist/simple-tree/fieldSchema.d.ts.map +1 -1
  172. package/dist/simple-tree/fieldSchema.js +1 -1
  173. package/dist/simple-tree/fieldSchema.js.map +1 -1
  174. package/dist/simple-tree/index.d.ts +4 -4
  175. package/dist/simple-tree/index.d.ts.map +1 -1
  176. package/dist/simple-tree/index.js +9 -2
  177. package/dist/simple-tree/index.js.map +1 -1
  178. package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
  179. package/dist/simple-tree/leafNodeSchema.js +1 -0
  180. package/dist/simple-tree/leafNodeSchema.js.map +1 -1
  181. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  182. package/dist/simple-tree/node-kinds/array/arrayNode.js +18 -4
  183. package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  184. package/dist/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
  185. package/dist/simple-tree/node-kinds/map/mapNode.js +9 -2
  186. package/dist/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  187. package/dist/simple-tree/node-kinds/object/objectNode.d.ts +2 -2
  188. package/dist/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  189. package/dist/simple-tree/node-kinds/object/objectNode.js +37 -26
  190. package/dist/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  191. package/dist/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
  192. package/dist/simple-tree/node-kinds/record/recordNode.js +9 -2
  193. package/dist/simple-tree/node-kinds/record/recordNode.js.map +1 -1
  194. package/dist/simple-tree/prepareForInsertion.d.ts +5 -5
  195. package/dist/simple-tree/prepareForInsertion.d.ts.map +1 -1
  196. package/dist/simple-tree/prepareForInsertion.js +10 -10
  197. package/dist/simple-tree/prepareForInsertion.js.map +1 -1
  198. package/dist/simple-tree/simpleSchema.d.ts +6 -21
  199. package/dist/simple-tree/simpleSchema.d.ts.map +1 -1
  200. package/dist/simple-tree/simpleSchema.js.map +1 -1
  201. package/dist/simple-tree/toStoredSchema.d.ts +35 -11
  202. package/dist/simple-tree/toStoredSchema.d.ts.map +1 -1
  203. package/dist/simple-tree/toStoredSchema.js +68 -33
  204. package/dist/simple-tree/toStoredSchema.js.map +1 -1
  205. package/dist/tableSchema.d.ts +25 -32
  206. package/dist/tableSchema.d.ts.map +1 -1
  207. package/dist/tableSchema.js +10 -24
  208. package/dist/tableSchema.js.map +1 -1
  209. package/docs/.attachments/cell-ordering/C-knows-of-ABC.png +0 -0
  210. package/docs/.attachments/cell-ordering/C-knows-of-C.png +0 -0
  211. package/docs/.attachments/cell-ordering/XvsA.png +0 -0
  212. package/docs/.attachments/cell-ordering/compose-a-b.png +0 -0
  213. package/docs/.attachments/cell-ordering/compose-a-ref-p1-b-ref-p2.png +0 -0
  214. package/docs/.attachments/cell-ordering/compose-b-no-ref-to-ca.png +0 -0
  215. package/docs/.attachments/cell-ordering/rebase-ab-over-x.png +0 -0
  216. package/docs/.attachments/cell-ordering/rebase-b-over-x.png +0 -0
  217. package/docs/.attachments/cell-ordering/rebase-b2-over-x.png +0 -0
  218. package/docs/.attachments/cell-ordering/rebase-b2.png +0 -0
  219. package/docs/.attachments/cell-ordering/rebase-to-abprime.png +0 -0
  220. package/docs/.attachments/cell-ordering/rebase-to-bprime.png +0 -0
  221. package/docs/main/cell-ordering.md +638 -0
  222. package/lib/alpha.d.ts +2 -1
  223. package/lib/core/tree/visitDelta.d.ts +1 -1
  224. package/lib/core/tree/visitDelta.d.ts.map +1 -1
  225. package/lib/core/tree/visitDelta.js.map +1 -1
  226. package/lib/feature-libraries/chunked-forest/index.d.ts +1 -0
  227. package/lib/feature-libraries/chunked-forest/index.d.ts.map +1 -1
  228. package/lib/feature-libraries/chunked-forest/index.js +1 -0
  229. package/lib/feature-libraries/chunked-forest/index.js.map +1 -1
  230. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts +2 -4
  231. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  232. package/lib/feature-libraries/default-schema/defaultEditBuilder.js +4 -1
  233. package/lib/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  234. package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  235. package/lib/feature-libraries/default-schema/defaultFieldKinds.js +1 -0
  236. package/lib/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  237. package/lib/feature-libraries/default-schema/noChangeCodecs.d.ts +1 -1
  238. package/lib/feature-libraries/default-schema/noChangeCodecs.d.ts.map +1 -1
  239. package/lib/feature-libraries/default-schema/noChangeCodecs.js.map +1 -1
  240. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts +4 -0
  241. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  242. package/lib/feature-libraries/forest-summary/forestSummarizer.js +1 -1
  243. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  244. package/lib/feature-libraries/index.d.ts +1 -1
  245. package/lib/feature-libraries/index.d.ts.map +1 -1
  246. package/lib/feature-libraries/index.js +1 -1
  247. package/lib/feature-libraries/index.js.map +1 -1
  248. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts +7 -0
  249. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  250. package/lib/feature-libraries/modular-schema/fieldChangeHandler.js +1 -0
  251. package/lib/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  252. package/lib/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
  253. package/lib/feature-libraries/modular-schema/genericFieldKind.js +1 -0
  254. package/lib/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  255. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +1 -0
  256. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  257. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts +9 -1
  258. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  259. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +50 -21
  260. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  261. package/lib/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
  262. package/lib/feature-libraries/optional-field/optionalField.js +3 -0
  263. package/lib/feature-libraries/optional-field/optionalField.js.map +1 -1
  264. package/lib/feature-libraries/sequence-field/sequenceFieldChangeRebaser.d.ts +1 -0
  265. package/lib/feature-libraries/sequence-field/sequenceFieldChangeRebaser.d.ts.map +1 -1
  266. package/lib/feature-libraries/sequence-field/sequenceFieldChangeRebaser.js +4 -0
  267. package/lib/feature-libraries/sequence-field/sequenceFieldChangeRebaser.js.map +1 -1
  268. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.d.ts +1 -1
  269. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.d.ts.map +1 -1
  270. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.js +1 -1
  271. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.js.map +1 -1
  272. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts +1 -1
  273. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts.map +1 -1
  274. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js +1 -1
  275. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  276. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts +1 -1
  277. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts.map +1 -1
  278. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.js +1 -1
  279. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.js.map +1 -1
  280. package/lib/feature-libraries/sequence-field/sequenceFieldCodecs.d.ts +1 -1
  281. package/lib/feature-libraries/sequence-field/sequenceFieldCodecs.d.ts.map +1 -1
  282. package/lib/feature-libraries/sequence-field/sequenceFieldCodecs.js.map +1 -1
  283. package/lib/feature-libraries/sequence-field/types.d.ts +1 -1
  284. package/lib/feature-libraries/sequence-field/types.d.ts.map +1 -1
  285. package/lib/feature-libraries/sequence-field/types.js.map +1 -1
  286. package/lib/index.d.ts +1 -1
  287. package/lib/index.d.ts.map +1 -1
  288. package/lib/index.js +1 -1
  289. package/lib/index.js.map +1 -1
  290. package/lib/jsonDomainSchema.d.ts +5 -3
  291. package/lib/jsonDomainSchema.d.ts.map +1 -1
  292. package/lib/jsonDomainSchema.js.map +1 -1
  293. package/lib/packageVersion.d.ts +1 -1
  294. package/lib/packageVersion.js +1 -1
  295. package/lib/packageVersion.js.map +1 -1
  296. package/lib/shared-tree/independentView.d.ts.map +1 -1
  297. package/lib/shared-tree/independentView.js +2 -2
  298. package/lib/shared-tree/independentView.js.map +1 -1
  299. package/lib/shared-tree/index.d.ts +0 -1
  300. package/lib/shared-tree/index.d.ts.map +1 -1
  301. package/lib/shared-tree/index.js.map +1 -1
  302. package/lib/shared-tree/schematizeTree.d.ts +23 -60
  303. package/lib/shared-tree/schematizeTree.d.ts.map +1 -1
  304. package/lib/shared-tree/schematizeTree.js +60 -150
  305. package/lib/shared-tree/schematizeTree.js.map +1 -1
  306. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  307. package/lib/shared-tree/schematizingTreeView.js +14 -14
  308. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  309. package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
  310. package/lib/shared-tree/treeAlpha.js +10 -4
  311. package/lib/shared-tree/treeAlpha.js.map +1 -1
  312. package/lib/shared-tree-core/defaultResubmitMachine.d.ts +2 -1
  313. package/lib/shared-tree-core/defaultResubmitMachine.d.ts.map +1 -1
  314. package/lib/shared-tree-core/defaultResubmitMachine.js.map +1 -1
  315. package/lib/simple-tree/api/configuration.d.ts +3 -0
  316. package/lib/simple-tree/api/configuration.d.ts.map +1 -1
  317. package/lib/simple-tree/api/configuration.js +6 -2
  318. package/lib/simple-tree/api/configuration.js.map +1 -1
  319. package/lib/simple-tree/api/create.d.ts +4 -4
  320. package/lib/simple-tree/api/create.d.ts.map +1 -1
  321. package/lib/simple-tree/api/create.js +3 -6
  322. package/lib/simple-tree/api/create.js.map +1 -1
  323. package/lib/simple-tree/api/discrepancies.d.ts +5 -9
  324. package/lib/simple-tree/api/discrepancies.d.ts.map +1 -1
  325. package/lib/simple-tree/api/discrepancies.js +11 -10
  326. package/lib/simple-tree/api/discrepancies.js.map +1 -1
  327. package/lib/simple-tree/api/index.d.ts +3 -2
  328. package/lib/simple-tree/api/index.d.ts.map +1 -1
  329. package/lib/simple-tree/api/index.js +2 -1
  330. package/lib/simple-tree/api/index.js.map +1 -1
  331. package/lib/simple-tree/api/schemaCompatibilityTester.d.ts.map +1 -1
  332. package/lib/simple-tree/api/schemaCompatibilityTester.js +4 -5
  333. package/lib/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
  334. package/lib/simple-tree/api/schemaFactory.d.ts +9 -155
  335. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  336. package/lib/simple-tree/api/schemaFactory.js +2 -45
  337. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  338. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +157 -16
  339. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
  340. package/lib/simple-tree/api/schemaFactoryAlpha.js +23 -1
  341. package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
  342. package/lib/simple-tree/api/schemaFactoryRecursive.d.ts +1 -3
  343. package/lib/simple-tree/api/schemaFactoryRecursive.d.ts.map +1 -1
  344. package/lib/simple-tree/api/schemaFactoryRecursive.js +0 -5
  345. package/lib/simple-tree/api/schemaFactoryRecursive.js.map +1 -1
  346. package/lib/simple-tree/api/schemaStatics.d.ts +158 -0
  347. package/lib/simple-tree/api/schemaStatics.d.ts.map +1 -0
  348. package/lib/simple-tree/api/schemaStatics.js +56 -0
  349. package/lib/simple-tree/api/schemaStatics.js.map +1 -0
  350. package/lib/simple-tree/api/storedSchema.d.ts +5 -3
  351. package/lib/simple-tree/api/storedSchema.d.ts.map +1 -1
  352. package/lib/simple-tree/api/storedSchema.js +6 -4
  353. package/lib/simple-tree/api/storedSchema.js.map +1 -1
  354. package/lib/simple-tree/api/treeBeta.d.ts.map +1 -1
  355. package/lib/simple-tree/api/treeBeta.js +8 -2
  356. package/lib/simple-tree/api/treeBeta.js.map +1 -1
  357. package/lib/simple-tree/core/allowedTypes.d.ts +46 -30
  358. package/lib/simple-tree/core/allowedTypes.d.ts.map +1 -1
  359. package/lib/simple-tree/core/allowedTypes.js +23 -12
  360. package/lib/simple-tree/core/allowedTypes.js.map +1 -1
  361. package/lib/simple-tree/core/index.d.ts +5 -3
  362. package/lib/simple-tree/core/index.d.ts.map +1 -1
  363. package/lib/simple-tree/core/index.js +3 -2
  364. package/lib/simple-tree/core/index.js.map +1 -1
  365. package/lib/simple-tree/core/simpleNodeSchemaBase.d.ts +25 -0
  366. package/lib/simple-tree/core/simpleNodeSchemaBase.d.ts.map +1 -0
  367. package/lib/simple-tree/core/simpleNodeSchemaBase.js +6 -0
  368. package/lib/simple-tree/core/simpleNodeSchemaBase.js.map +1 -0
  369. package/lib/simple-tree/core/toStored.d.ts +32 -0
  370. package/lib/simple-tree/core/toStored.d.ts.map +1 -0
  371. package/lib/simple-tree/core/toStored.js +32 -0
  372. package/lib/simple-tree/core/toStored.js.map +1 -0
  373. package/lib/simple-tree/core/treeNode.d.ts +0 -3
  374. package/lib/simple-tree/core/treeNode.d.ts.map +1 -1
  375. package/lib/simple-tree/core/treeNode.js +3 -3
  376. package/lib/simple-tree/core/treeNode.js.map +1 -1
  377. package/lib/simple-tree/core/treeNodeSchema.d.ts +7 -2
  378. package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  379. package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
  380. package/lib/simple-tree/core/treeNodeValid.d.ts +6 -1
  381. package/lib/simple-tree/core/treeNodeValid.d.ts.map +1 -1
  382. package/lib/simple-tree/core/treeNodeValid.js +9 -5
  383. package/lib/simple-tree/core/treeNodeValid.js.map +1 -1
  384. package/lib/simple-tree/core/walkSchema.d.ts +19 -5
  385. package/lib/simple-tree/core/walkSchema.d.ts.map +1 -1
  386. package/lib/simple-tree/core/walkSchema.js +4 -2
  387. package/lib/simple-tree/core/walkSchema.js.map +1 -1
  388. package/lib/simple-tree/createContext.d.ts.map +1 -1
  389. package/lib/simple-tree/createContext.js +2 -2
  390. package/lib/simple-tree/createContext.js.map +1 -1
  391. package/lib/simple-tree/fieldSchema.d.ts +2 -1
  392. package/lib/simple-tree/fieldSchema.d.ts.map +1 -1
  393. package/lib/simple-tree/fieldSchema.js +1 -1
  394. package/lib/simple-tree/fieldSchema.js.map +1 -1
  395. package/lib/simple-tree/index.d.ts +4 -4
  396. package/lib/simple-tree/index.d.ts.map +1 -1
  397. package/lib/simple-tree/index.js +2 -2
  398. package/lib/simple-tree/index.js.map +1 -1
  399. package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
  400. package/lib/simple-tree/leafNodeSchema.js +2 -1
  401. package/lib/simple-tree/leafNodeSchema.js.map +1 -1
  402. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  403. package/lib/simple-tree/node-kinds/array/arrayNode.js +21 -7
  404. package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  405. package/lib/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
  406. package/lib/simple-tree/node-kinds/map/mapNode.js +12 -5
  407. package/lib/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  408. package/lib/simple-tree/node-kinds/object/objectNode.d.ts +2 -2
  409. package/lib/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  410. package/lib/simple-tree/node-kinds/object/objectNode.js +16 -5
  411. package/lib/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  412. package/lib/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
  413. package/lib/simple-tree/node-kinds/record/recordNode.js +12 -5
  414. package/lib/simple-tree/node-kinds/record/recordNode.js.map +1 -1
  415. package/lib/simple-tree/prepareForInsertion.d.ts +5 -5
  416. package/lib/simple-tree/prepareForInsertion.d.ts.map +1 -1
  417. package/lib/simple-tree/prepareForInsertion.js +10 -10
  418. package/lib/simple-tree/prepareForInsertion.js.map +1 -1
  419. package/lib/simple-tree/simpleSchema.d.ts +6 -21
  420. package/lib/simple-tree/simpleSchema.d.ts.map +1 -1
  421. package/lib/simple-tree/simpleSchema.js.map +1 -1
  422. package/lib/simple-tree/toStoredSchema.d.ts +35 -11
  423. package/lib/simple-tree/toStoredSchema.d.ts.map +1 -1
  424. package/lib/simple-tree/toStoredSchema.js +67 -34
  425. package/lib/simple-tree/toStoredSchema.js.map +1 -1
  426. package/lib/tableSchema.d.ts +25 -32
  427. package/lib/tableSchema.d.ts.map +1 -1
  428. package/lib/tableSchema.js +11 -25
  429. package/lib/tableSchema.js.map +1 -1
  430. package/package.json +21 -21
  431. package/src/core/tree/visitDelta.ts +3 -1
  432. package/src/feature-libraries/chunked-forest/index.ts +1 -0
  433. package/src/feature-libraries/default-schema/defaultEditBuilder.ts +12 -5
  434. package/src/feature-libraries/default-schema/defaultFieldKinds.ts +1 -0
  435. package/src/feature-libraries/default-schema/noChangeCodecs.ts +1 -1
  436. package/src/feature-libraries/forest-summary/forestSummarizer.ts +1 -1
  437. package/src/feature-libraries/index.ts +2 -0
  438. package/src/feature-libraries/modular-schema/fieldChangeHandler.ts +9 -0
  439. package/src/feature-libraries/modular-schema/genericFieldKind.ts +1 -0
  440. package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +1 -0
  441. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +61 -19
  442. package/src/feature-libraries/optional-field/optionalField.ts +4 -0
  443. package/src/feature-libraries/sequence-field/sequenceFieldChangeRebaser.ts +4 -0
  444. package/src/feature-libraries/sequence-field/sequenceFieldCodecV1.ts +4 -2
  445. package/src/feature-libraries/sequence-field/sequenceFieldCodecV2.ts +4 -2
  446. package/src/feature-libraries/sequence-field/sequenceFieldCodecV3.ts +4 -2
  447. package/src/feature-libraries/sequence-field/sequenceFieldCodecs.ts +1 -1
  448. package/src/feature-libraries/sequence-field/types.ts +1 -1
  449. package/src/index.ts +2 -1
  450. package/src/jsonDomainSchema.ts +4 -0
  451. package/src/packageVersion.ts +1 -1
  452. package/src/shared-tree/independentView.ts +6 -2
  453. package/src/shared-tree/index.ts +0 -2
  454. package/src/shared-tree/schematizeTree.ts +83 -199
  455. package/src/shared-tree/schematizingTreeView.ts +26 -12
  456. package/src/shared-tree/treeAlpha.ts +18 -4
  457. package/src/shared-tree-core/defaultResubmitMachine.ts +2 -1
  458. package/src/simple-tree/api/configuration.ts +10 -2
  459. package/src/simple-tree/api/create.ts +5 -10
  460. package/src/simple-tree/api/discrepancies.ts +18 -17
  461. package/src/simple-tree/api/index.ts +2 -3
  462. package/src/simple-tree/api/schemaCompatibilityTester.ts +5 -9
  463. package/src/simple-tree/api/schemaFactory.ts +6 -250
  464. package/src/simple-tree/api/schemaFactoryAlpha.ts +174 -1
  465. package/src/simple-tree/api/schemaFactoryRecursive.ts +1 -25
  466. package/src/simple-tree/api/schemaStatics.ts +291 -0
  467. package/src/simple-tree/api/storedSchema.ts +12 -5
  468. package/src/simple-tree/api/treeBeta.ts +9 -2
  469. package/src/simple-tree/core/allowedTypes.ts +71 -42
  470. package/src/simple-tree/core/index.ts +9 -1
  471. package/src/simple-tree/core/simpleNodeSchemaBase.ts +30 -0
  472. package/src/simple-tree/core/toStored.ts +58 -0
  473. package/src/simple-tree/core/treeNode.ts +3 -3
  474. package/src/simple-tree/core/treeNodeSchema.ts +8 -2
  475. package/src/simple-tree/core/treeNodeValid.ts +14 -5
  476. package/src/simple-tree/core/walkSchema.ts +23 -6
  477. package/src/simple-tree/createContext.ts +5 -2
  478. package/src/simple-tree/fieldSchema.ts +4 -2
  479. package/src/simple-tree/index.ts +15 -6
  480. package/src/simple-tree/leafNodeSchema.ts +2 -1
  481. package/src/simple-tree/node-kinds/array/arrayNode.ts +58 -37
  482. package/src/simple-tree/node-kinds/map/mapNode.ts +26 -2
  483. package/src/simple-tree/node-kinds/object/objectNode.ts +37 -4
  484. package/src/simple-tree/node-kinds/record/recordNode.ts +23 -2
  485. package/src/simple-tree/prepareForInsertion.ts +12 -7
  486. package/src/simple-tree/simpleSchema.ts +6 -26
  487. package/src/simple-tree/toStoredSchema.ts +107 -44
  488. package/src/tableSchema.ts +40 -35
@@ -3,240 +3,124 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { assert, unreachableCase, fail } from "@fluidframework/core-utils/internal";
6
+ import { assert } from "@fluidframework/core-utils/internal";
7
7
 
8
- import {
9
- CursorLocationType,
10
- type ITreeCursorSynchronous,
11
- type TreeStoredSchema,
12
- rootFieldKey,
13
- schemaDataIsEmpty,
14
- } from "../core/index.js";
8
+ import { type TreeStoredSchema, rootFieldKey, schemaDataIsEmpty } from "../core/index.js";
15
9
  import {
16
10
  FieldKinds,
17
11
  allowsRepoSuperset,
18
- cursorForMapTreeField,
19
12
  defaultSchemaPolicy,
20
- mapTreeFromCursor,
13
+ type IDefaultEditBuilder,
14
+ type TreeChunk,
21
15
  } from "../feature-libraries/index.js";
22
- import { toStoredSchema, type SchemaCompatibilityTester } from "../simple-tree/index.js";
23
- import { isReadonlyArray } from "../util/index.js";
24
16
 
25
17
  import type { ITreeCheckout } from "./treeCheckout.js";
26
18
 
19
+ export function canInitialize(checkout: ITreeCheckout): boolean {
20
+ // Check for empty.
21
+ return checkout.forest.isEmpty && schemaDataIsEmpty(checkout.storedSchema);
22
+ }
23
+
27
24
  /**
28
- * Modify `storedSchema` and invoke `setInitialTree` when it's time to set the tree content.
29
- *
30
- * Requires `storedSchema` to be in its default/empty state.
31
- *
32
- * This is done in such a way that if the content (implicitly assumed to start empty)
33
- * is never out of schema.
34
- * This means that if the root field of the new schema requires content (like a value field),
35
- * a temporary intermediate schema is used so the initial empty state is not out of schema.
25
+ * Initialize a checkout with a schema and tree content.
26
+ * This function should only be called when the tree is uninitialized (no schema or content).
36
27
  *
37
- * Since this makes multiple changes, callers may want to wrap it in a transaction.
28
+ * @param checkout - The tree checkout to initialize.
29
+ * @param newSchema - The new schema to apply.
30
+ * @param contentFactory - A function that sets the initial tree content.
31
+ * Invoked after a schema containing all nodes from newSchema is applied.
32
+ * Note that the final root field schema may not have been applied yet: if the root is required, it will be optional at this time
33
+ * (so the root being empty before the insertion is not out of schema).
34
+ * @remarks
35
+ * If `newSchema` is not compatible with the empty tree, this function handles it using an intermediate schema
36
+ * which supports the empty tree as well as the final tree content.
37
+ * @privateRemarks
38
+ * This takes in a checkout using a subset of the checkout interface to enable easier unit testing.
38
39
  */
39
- export function initializeContent(
40
- schemaRepository: {
41
- storedSchema: ITreeCheckout["storedSchema"];
42
- updateSchema: ITreeCheckout["updateSchema"];
43
- },
40
+ export function initialize(
41
+ checkout: Pick<ITreeCheckout, "storedSchema" | "updateSchema">,
44
42
  newSchema: TreeStoredSchema,
45
43
  setInitialTree: () => void,
46
44
  ): void {
47
45
  assert(
48
- schemaDataIsEmpty(schemaRepository.storedSchema),
46
+ schemaDataIsEmpty(checkout.storedSchema),
49
47
  0x743 /* cannot initialize after a schema is set */,
50
48
  );
51
49
 
52
- const rootSchema = newSchema.rootFieldSchema;
53
- const rootKind = rootSchema.kind;
54
-
55
50
  // To keep the data in schema during the update, first define a schema that tolerates the current (empty) tree as well as the final (initial) tree.
56
- let incrementalSchemaUpdate: TreeStoredSchema;
57
- if (
58
- rootKind === FieldKinds.sequence.identifier ||
59
- rootKind === FieldKinds.optional.identifier
60
- ) {
61
- // These kinds are known to tolerate empty, so use the schema as is:
62
- incrementalSchemaUpdate = newSchema;
63
- } else {
64
- assert(rootKind === FieldKinds.required.identifier, 0x5c8 /* Unexpected kind */);
65
- // Replace value kind with optional kind in root field schema:
66
- incrementalSchemaUpdate = {
67
- nodeSchema: newSchema.nodeSchema,
68
- rootFieldSchema: {
69
- kind: FieldKinds.optional.identifier,
70
- types: rootSchema.types,
71
- persistedMetadata: rootSchema.persistedMetadata,
72
- },
73
- };
51
+ let intermediateSchema: TreeStoredSchema;
52
+ {
53
+ const rootSchema = newSchema.rootFieldSchema;
54
+ const rootKind = rootSchema.kind;
55
+ if (
56
+ rootKind === FieldKinds.sequence.identifier ||
57
+ rootKind === FieldKinds.optional.identifier
58
+ ) {
59
+ // These kinds are known to tolerate empty, so use the schema as is:
60
+ intermediateSchema = newSchema;
61
+ } else {
62
+ assert(rootKind === FieldKinds.required.identifier, 0x5c8 /* Unexpected kind */);
63
+ // Replace value kind with optional kind in root field schema:
64
+ intermediateSchema = {
65
+ nodeSchema: newSchema.nodeSchema,
66
+ rootFieldSchema: {
67
+ kind: FieldKinds.optional.identifier,
68
+ types: rootSchema.types,
69
+ persistedMetadata: rootSchema.persistedMetadata,
70
+ },
71
+ };
72
+ }
74
73
  }
75
74
 
76
75
  assert(
77
- allowsRepoSuperset(defaultSchemaPolicy, newSchema, incrementalSchemaUpdate),
76
+ allowsRepoSuperset(defaultSchemaPolicy, newSchema, intermediateSchema),
78
77
  0x5c9 /* Incremental Schema during update should allow a superset of the final schema */,
79
78
  );
80
- // Update to intermediate schema
81
- schemaRepository.updateSchema(incrementalSchemaUpdate);
82
- // Insert initial tree
79
+
80
+ checkout.updateSchema(intermediateSchema);
83
81
  setInitialTree();
84
82
 
85
83
  // If intermediate schema is not final desired schema, update to the final schema:
86
- if (incrementalSchemaUpdate !== newSchema) {
84
+ if (intermediateSchema !== newSchema) {
87
85
  // This makes the root more strict, so set allowNonSupersetSchema to true.
88
- schemaRepository.updateSchema(newSchema, true);
86
+ checkout.updateSchema(newSchema, true);
89
87
  }
90
88
  }
91
89
 
92
- export enum UpdateType {
93
- /**
94
- * Already compatible, no update needed.
95
- */
96
- None,
97
- /**
98
- * Schema can be upgraded leaving tree as is.
99
- */
100
- SchemaCompatible,
101
- /**
102
- * No update currently supported.
103
- */
104
- Incompatible,
105
- }
106
-
107
90
  /**
108
- * Returns how compatible updating checkout's schema is with the viewSchema.
109
- */
110
- export function evaluateUpdate(
111
- viewSchema: SchemaCompatibilityTester,
112
- checkout: ITreeCheckout,
113
- ): UpdateType {
114
- const compatibility = viewSchema.checkCompatibility(checkout.storedSchema);
115
-
116
- if (compatibility.canUpgrade && compatibility.canView) {
117
- // Compatible as is
118
- return UpdateType.None;
119
- }
120
-
121
- if (!compatibility.canUpgrade) {
122
- // Existing stored schema permits trees which are incompatible with the view schema, so schema can not be updated
123
- return UpdateType.Incompatible;
124
- }
125
-
126
- assert(!compatibility.canView, 0x8bd /* unexpected case */);
127
- assert(compatibility.canUpgrade, 0x8be /* unexpected case */);
128
-
129
- return UpdateType.SchemaCompatible;
130
- }
131
-
132
- export function canInitialize(checkout: ITreeCheckout): boolean {
133
- // Check for empty.
134
- return checkout.forest.isEmpty && schemaDataIsEmpty(checkout.storedSchema);
135
- }
136
-
137
- function normalizeNewFieldContent(
138
- content: readonly ITreeCursorSynchronous[] | ITreeCursorSynchronous | undefined,
139
- ): ITreeCursorSynchronous {
140
- if (content === undefined) {
141
- return cursorForMapTreeField([]);
142
- }
143
-
144
- if (isReadonlyArray(content)) {
145
- return cursorForMapTreeField(content.map((c) => mapTreeFromCursor(c)));
146
- }
147
-
148
- if (content.mode === CursorLocationType.Fields) {
149
- return content;
150
- }
151
-
152
- return cursorForMapTreeField([mapTreeFromCursor(content)]);
153
- }
154
-
155
- /**
156
- * Initialize a checkout with a schema and tree content.
157
- * This function should only be called when the tree is uninitialized (no schema or content).
158
- * @remarks
159
- *
160
- * If the proposed schema (from `treeContent`) is not compatible with the empty tree, this function handles using an intermediate schema
161
- * which supports the empty tree as well as the final tree content.
162
- */
163
- export function initialize(checkout: ITreeCheckout, treeContent: TreeStoredContent): void {
164
- checkout.transaction.start();
165
- try {
166
- initializeContent(checkout, treeContent.schema, () => {
167
- const field = { field: rootFieldKey, parent: undefined };
168
- const content = normalizeNewFieldContent(treeContent.initialTree);
169
- const contentChunk = checkout.forest.chunkField(content);
170
-
171
- switch (checkout.storedSchema.rootFieldSchema.kind) {
172
- case FieldKinds.optional.identifier: {
173
- const fieldEditor = checkout.editor.optionalField(field);
174
- assert(
175
- content.getFieldLength() <= 1,
176
- 0x7f4 /* optional field content should normalize at most one item */,
177
- );
178
- fieldEditor.set(contentChunk.topLevelLength === 0 ? undefined : contentChunk, true);
179
- break;
180
- }
181
- case FieldKinds.sequence.identifier: {
182
- const fieldEditor = checkout.editor.sequenceField(field);
183
- // TODO: should do an idempotent edit here.
184
- fieldEditor.insert(0, contentChunk);
185
- break;
186
- }
187
- default: {
188
- fail(0xac7 /* unexpected root field kind during initialize */);
189
- }
190
- }
191
- });
192
- } finally {
193
- checkout.transaction.commit();
194
- }
195
- }
196
-
197
- /**
198
- * Ensure a {@link ITreeCheckout} can be used with a given {@link SchemaCompatibilityTester}.
199
- *
91
+ * Construct a general purpose `setInitialTree` for use with {@link initialize} from a function that returns a chunk.
92
+ * @param contentFactory - A function that returns the initial tree content as a chunk.
93
+ * Invoked after a schema containing all nodes from newSchema is applied.
94
+ * Note that the final root field schema may not have been applied yet: if the root is required, it will be optional at this time
95
+ * (so the root being empty before the insertion is not out of schema).
200
96
  * @remarks
201
- * It is up to the caller to ensure that compatibility is reevaluated if the checkout's stored schema is edited in the future.
202
- *
203
- * @param viewSchema - View schema that `checkout` should be made compatible with.
204
- * @param allowedSchemaModifications - Flags enum describing the ways this is allowed to modify `checkout`.
205
- * @param checkout - To be modified as needed to be compatible with `viewSchema`.
206
- * @param treeContent - Content to be used to initialize `checkout`'s the tree if needed and allowed.
207
- * @returns true iff checkout now is compatible with `viewSchema`.
97
+ * This does not support sequence roots as they are not allowed in the public API surface.
98
+ * A test utility for them can be found as `initializeSequenceRoot` for testing internal logic which uses a sequence root.
208
99
  */
209
- export function ensureSchema(
210
- viewSchema: SchemaCompatibilityTester,
211
- checkout: ITreeCheckout,
212
- ): boolean {
213
- const updatedNeeded = evaluateUpdate(viewSchema, checkout);
214
- switch (updatedNeeded) {
215
- case UpdateType.None: {
216
- return true;
217
- }
218
- case UpdateType.Incompatible: {
219
- return false;
220
- }
221
- case UpdateType.SchemaCompatible: {
222
- checkout.updateSchema(toStoredSchema(viewSchema.viewSchema.root));
223
- return true;
224
- }
225
- default: {
226
- unreachableCase(updatedNeeded);
227
- }
228
- }
100
+ export function initializerFromChunk(
101
+ checkout: Pick<ITreeCheckout, "storedSchema"> & {
102
+ readonly editor: IDefaultEditBuilder;
103
+ },
104
+ contentFactory: () => TreeChunk,
105
+ ): () => void {
106
+ return () => initializeFromChunk(checkout, contentFactory());
229
107
  }
230
108
 
231
- /**
232
- * Content that can populate a `SharedTree`.
233
- */
234
- export interface TreeStoredContent {
235
- readonly schema: TreeStoredSchema;
236
-
237
- /**
238
- * Default tree content to initialize the tree with iff the tree is uninitialized
239
- * (meaning it does not even have any schema set at all).
240
- */
241
- readonly initialTree: readonly ITreeCursorSynchronous[] | ITreeCursorSynchronous | undefined;
109
+ function initializeFromChunk(
110
+ checkout: Pick<ITreeCheckout, "storedSchema"> & {
111
+ readonly editor: IDefaultEditBuilder;
112
+ },
113
+ contentChunk: TreeChunk,
114
+ ): void {
115
+ const field = { field: rootFieldKey, parent: undefined };
116
+ assert(
117
+ checkout.storedSchema.rootFieldSchema.kind === FieldKinds.optional.identifier,
118
+ 0xc11 /* initializerFromChunk only supports optional roots */,
119
+ );
120
+ const fieldEditor = checkout.editor.optionalField(field);
121
+ assert(
122
+ contentChunk.topLevelLength <= 1,
123
+ 0x7f4 /* optional field content should normalize at most one item */,
124
+ );
125
+ fieldEditor.set(contentChunk.topLevelLength === 0 ? undefined : contentChunk, true);
242
126
  }
@@ -16,7 +16,7 @@ import { anchorSlot } from "../core/index.js";
16
16
  import {
17
17
  type NodeIdentifierManager,
18
18
  defaultSchemaPolicy,
19
- cursorForMapTreeNode,
19
+ cursorForMapTreeField,
20
20
  TreeStatus,
21
21
  Context,
22
22
  } from "../feature-libraries/index.js";
@@ -51,10 +51,11 @@ import {
51
51
  areImplicitFieldSchemaEqual,
52
52
  prepareForInsertionContextless,
53
53
  type FieldSchema,
54
- toStoredSchema,
55
54
  tryDisposeTreeNode,
56
55
  FieldSchemaAlpha,
57
56
  TreeViewConfigurationAlpha,
57
+ toInitialSchema,
58
+ toUpgradeSchema,
58
59
  } from "../simple-tree/index.js";
59
60
  import {
60
61
  type Breakable,
@@ -63,7 +64,7 @@ import {
63
64
  type WithBreakable,
64
65
  } from "../util/index.js";
65
66
 
66
- import { canInitialize, ensureSchema, initialize } from "./schematizeTree.js";
67
+ import { canInitialize, initialize, initializerFromChunk } from "./schematizeTree.js";
67
68
  import type { ITreeCheckout, TreeCheckout } from "./treeCheckout.js";
68
69
 
69
70
  /**
@@ -172,7 +173,7 @@ export class SchematizingSimpleTreeView<
172
173
  }
173
174
 
174
175
  this.runSchemaEdit(() => {
175
- const schema = toStoredSchema(this.config.schema);
176
+ const schema = toInitialSchema(this.config.schema);
176
177
  const mapTree = prepareForInsertionContextless(
177
178
  content as InsertableContent | undefined,
178
179
  this.rootFieldSchema,
@@ -181,12 +182,22 @@ export class SchematizingSimpleTreeView<
181
182
  policy: defaultSchemaPolicy,
182
183
  },
183
184
  this,
185
+ schema.rootFieldSchema,
184
186
  );
185
187
 
186
- initialize(this.checkout, {
188
+ this.checkout.transaction.start();
189
+
190
+ initialize(
191
+ this.checkout,
187
192
  schema,
188
- initialTree: mapTree === undefined ? undefined : cursorForMapTreeNode(mapTree),
189
- });
193
+ initializerFromChunk(this.checkout, () => {
194
+ // This must be done after initial schema is set!
195
+ return this.checkout.forest.chunkField(
196
+ cursorForMapTreeField(mapTree === undefined ? [] : [mapTree]),
197
+ );
198
+ }),
199
+ );
200
+ this.checkout.transaction.commit();
190
201
  });
191
202
  }
192
203
 
@@ -205,10 +216,8 @@ export class SchematizingSimpleTreeView<
205
216
  );
206
217
  }
207
218
 
208
- this.runSchemaEdit(() => {
209
- const result = ensureSchema(this.viewSchema, this.checkout);
210
- assert(result, 0x8bf /* Schema upgrade should always work if canUpgrade is set. */);
211
- });
219
+ const newSchema = toUpgradeSchema(this.viewSchema.viewSchema.root);
220
+ this.runSchemaEdit(() => this.checkout.updateSchema(newSchema));
212
221
  }
213
222
 
214
223
  /**
@@ -436,7 +445,12 @@ export class SchematizingSimpleTreeView<
436
445
  );
437
446
  }
438
447
  const view = this.getFlexTreeContext();
439
- setField(view.root, this.rootFieldSchema, newRoot as InsertableContent | undefined);
448
+ setField(
449
+ view.root,
450
+ this.rootFieldSchema,
451
+ newRoot as InsertableContent | undefined,
452
+ this.checkout.storedSchema.rootFieldSchema,
453
+ );
440
454
  }
441
455
 
442
456
  // #region Branching
@@ -36,7 +36,6 @@ import {
36
36
  verboseFromCursor,
37
37
  type TreeEncodingOptions,
38
38
  type VerboseTree,
39
- toStoredSchema,
40
39
  extractPersistedSchema,
41
40
  type TreeBranch,
42
41
  TreeViewConfigurationAlpha,
@@ -52,6 +51,9 @@ import {
52
51
  tryGetTreeNodeForField,
53
52
  isObjectNodeSchema,
54
53
  isTreeNode,
54
+ toInitialSchema,
55
+ convertField,
56
+ toUnhydratedSchema,
55
57
  } from "../simple-tree/index.js";
56
58
  import { brand, extractFromOpaque, type JsonCompatible } from "../util/index.js";
57
59
  import {
@@ -493,7 +495,11 @@ export const TreeAlpha: TreeAlpha = {
493
495
  return undefined as Unhydrated<TreeFieldFromImplicitField<TSchema>>;
494
496
  }
495
497
  const cursor = cursorFromVerbose(data, schemalessConfig);
496
- return createFromCursor(schema, cursor);
498
+ return createFromCursor(
499
+ schema,
500
+ cursor,
501
+ convertField(normalizeFieldSchema(schema), toUnhydratedSchema),
502
+ );
497
503
  },
498
504
 
499
505
  exportConcise,
@@ -523,11 +529,18 @@ export const TreeAlpha: TreeAlpha = {
523
529
  const batch: FieldBatch = [cursor];
524
530
  // If none provided, create a compressor which will not compress anything.
525
531
  const idCompressor = options.idCompressor ?? createIdCompressor();
532
+
533
+ // Grabbing an existing stored schema from the node is important to ensure that unknown optional fields can be preserved.
534
+ // Note that if the node is unhydrated, this can result in all staged allowed types being included in the schema, which might be undesired.
535
+ const storedSchema = isTreeNode(node)
536
+ ? getKernel(node).context.flexContext.schema
537
+ : toInitialSchema(schema);
538
+
526
539
  const context: FieldBatchEncodingContext = {
527
540
  encodeType: TreeCompressionStrategy.Compressed,
528
541
  idCompressor,
529
542
  originatorId: idCompressor.localSessionId, // TODO: Why is this needed?
530
- schema: { schema: toStoredSchema(schema), policy: defaultSchemaPolicy },
543
+ schema: { schema: storedSchema, policy: defaultSchemaPolicy },
531
544
  };
532
545
  const result = codec.encode(batch, context);
533
546
  return result;
@@ -543,7 +556,8 @@ export const TreeAlpha: TreeAlpha = {
543
556
  const config = new TreeViewConfigurationAlpha({ schema });
544
557
  const content: ViewContent = {
545
558
  // Always use a v1 schema codec for consistency.
546
- schema: extractPersistedSchema(config, FluidClientVersion.v2_0),
559
+ // TODO: reevaluate how staged schema should behave in schema import/export APIs before stabilizing this.
560
+ schema: extractPersistedSchema(config.schema, FluidClientVersion.v2_0, () => true),
547
561
  tree: compressedData,
548
562
  idCompressor: options.idCompressor ?? createIdCompressor(),
549
563
  };
@@ -14,7 +14,8 @@ import {
14
14
  import type { GraphCommit, TaggedChange } from "../core/index.js";
15
15
  import { disposeSymbol, hasSome } from "../util/index.js";
16
16
 
17
- import type { ChangeEnricherReadonlyCheckout, ResubmitMachine } from "./index.js";
17
+ import type { ChangeEnricherReadonlyCheckout } from "./changeEnricher.js";
18
+ import type { ResubmitMachine } from "./resubmitMachine.js";
18
19
 
19
20
  interface PendingChange<TChange> {
20
21
  commit: GraphCommit<TChange>;
@@ -25,7 +25,11 @@ import {
25
25
  evaluateLazySchema,
26
26
  markSchemaMostDerived,
27
27
  } from "../core/index.js";
28
- import { toStoredSchema } from "../toStoredSchema.js";
28
+ import {
29
+ permissiveStoredSchemaGenerationOptions,
30
+ restrictiveStoredSchemaGenerationOptions,
31
+ toStoredSchema,
32
+ } from "../toStoredSchema.js";
29
33
  import {
30
34
  isArrayNodeSchema,
31
35
  isMapNodeSchema,
@@ -161,6 +165,9 @@ export interface ITreeViewConfiguration<
161
165
 
162
166
  /**
163
167
  * Configuration for {@link ViewableTree.viewWith}.
168
+ * @privateRemarks
169
+ * When `ImplicitAnnotatedFieldSchema` is stabilized, TSchema should be updated to use it.
170
+ * When doing this, the example for `staged` will need to be updated/simplified.
164
171
  * @sealed @public
165
172
  */
166
173
  export class TreeViewConfiguration<
@@ -213,7 +220,8 @@ export class TreeViewConfiguration<
213
220
 
214
221
  // Eagerly perform this conversion to surface errors sooner.
215
222
  // Includes detection of duplicate schema identifiers.
216
- toStoredSchema(config.schema);
223
+ toStoredSchema(config.schema, restrictiveStoredSchemaGenerationOptions);
224
+ toStoredSchema(config.schema, permissiveStoredSchemaGenerationOptions);
217
225
 
218
226
  const definitions = new Map<string, SimpleNodeSchema & TreeNodeSchema>();
219
227
 
@@ -13,12 +13,9 @@ import {
13
13
  mapCursorFields,
14
14
  type ITreeCursorSynchronous,
15
15
  type SchemaAndPolicy,
16
+ type TreeFieldStoredSchema,
16
17
  } from "../../core/index.js";
17
- import {
18
- normalizeFieldSchema,
19
- type ImplicitFieldSchema,
20
- type TreeFieldFromImplicitField,
21
- } from "../fieldSchema.js";
18
+ import type { ImplicitFieldSchema, TreeFieldFromImplicitField } from "../fieldSchema.js";
22
19
  import {
23
20
  type Context,
24
21
  getOrCreateNodeFromInnerNode,
@@ -32,33 +29,31 @@ import {
32
29
  throwOutOfSchema,
33
30
  } from "../../feature-libraries/index.js";
34
31
  import { getUnhydratedContext } from "../createContext.js";
35
- import { convertField } from "../toStoredSchema.js";
36
32
  import { unknownTypeError } from "./customTree.js";
37
33
 
38
34
  /**
39
35
  * Creates an unhydrated simple-tree field from a cursor in nodes mode.
40
36
  * @remarks
41
37
  * Does not support providing missing defaults values.
42
- * Validates the field is in schema using the provided `contextForNewNodes` of the default unhydrated context if not provided.
38
+ * Validates the field is in schema using `destinationSchema` the provided `contextForNewNodes` or the default unhydrated context if not provided.
43
39
  */
44
40
  export function createFromCursor<const TSchema extends ImplicitFieldSchema>(
45
41
  schema: TSchema,
46
42
  cursor: ITreeCursorSynchronous | undefined,
43
+ destinationSchema: TreeFieldStoredSchema,
47
44
  contextForNewNodes?: Context,
48
45
  ): Unhydrated<TreeFieldFromImplicitField<TSchema>> {
49
46
  const context = contextForNewNodes ?? getUnhydratedContext(schema);
50
47
  assert(context.flexContext.isHydrated() === false, 0xbfe /* Expected unhydrated context */);
51
48
  const mapTrees = cursor === undefined ? [] : [unhydratedFlexTreeFromCursor(context, cursor)];
52
49
 
53
- const rootFieldSchema = convertField(normalizeFieldSchema(schema));
54
-
55
50
  const schemaAndPolicy: SchemaAndPolicy = {
56
51
  policy: defaultSchemaPolicy,
57
52
  schema: context.flexContext.schema,
58
53
  };
59
54
 
60
55
  // Assuming the caller provides the correct `contextForNewNodes`, this should handle unknown optional fields.
61
- isFieldInSchema(mapTrees, rootFieldSchema, schemaAndPolicy, throwOutOfSchema);
56
+ isFieldInSchema(mapTrees, destinationSchema, schemaAndPolicy, throwOutOfSchema);
62
57
 
63
58
  if (mapTrees.length === 0) {
64
59
  return undefined as Unhydrated<TreeFieldFromImplicitField<TSchema>>;
@@ -89,11 +89,13 @@ export interface FieldDiscrepancyLocation {
89
89
  export interface AllowedTypeDiscrepancy extends FieldDiscrepancyLocation {
90
90
  readonly mismatch: "allowedTypes";
91
91
  /**
92
- * List of annotated allowed types in viewed schema which are not allowed in stored schema
92
+ * Annotated allowed types in viewed schema
93
+ * (excluding {@link SchemaStaticsAlpha.staged | staged} schema) which are not allowed in stored schema.
93
94
  */
94
95
  readonly view: readonly AnnotatedAllowedType<TreeNodeSchema>[];
95
96
  /**
96
- * List of allowed type identifiers in stored schema which are not allowed in view schema
97
+ * Allowed type identifiers in stored schema which are not allowed in view schema
98
+ * (including the view schema's {@link SchemaStaticsAlpha.staged | staged} schema).
97
99
  */
98
100
  readonly stored: readonly TreeNodeSchemaIdentifier[];
99
101
  }
@@ -296,28 +298,28 @@ function* getNodeDiscrepancies(
296
298
 
297
299
  /**
298
300
  * Returns the allowed types that are not present in both the given view and stored schemas.
299
- * It returns a tuple containing two arrays:
300
- * 1. The first array contains the allowed types that are present in the view schema but not in the stored schema.
301
- * 2. The second array contains the allowed types that are present in the stored schema but not in the view schema.
302
301
  */
303
302
  export function findExtraAllowedTypes(
304
303
  viewAllowedTypes: readonly AnnotatedAllowedType<TreeNodeSchema>[],
305
304
  storedAllowedTypes: TreeTypeSet,
306
- ): {
307
- viewExtra: readonly AnnotatedAllowedType<TreeNodeSchema>[];
308
- storedExtra: TreeNodeSchemaIdentifier[];
309
- } {
305
+ ): Pick<AllowedTypeDiscrepancy, "view" | "stored"> {
310
306
  const viewNodeSchemaIdentifiers = new Set(
311
307
  viewAllowedTypes.map((value) => value.type.identifier),
312
308
  );
313
309
 
314
- const viewExtra = viewAllowedTypes.filter(
315
- (value) => !storedAllowedTypes.has(brand(value.type.identifier)),
310
+ // TODO:
311
+ // Add detecting which SchemaUpgrades have been made.
312
+ // When doing so, each will fall into one of three states: staged, partially applied, or fully applied.
313
+ // This would allow for nicer compatibility errors and more detailed compatibility status in the future.
314
+ const view = viewAllowedTypes.filter(
315
+ (value) =>
316
+ !storedAllowedTypes.has(brand(value.type.identifier)) &&
317
+ value.metadata.stagedSchemaUpgrade === undefined,
316
318
  );
317
- const storedExtra = [...storedAllowedTypes].filter(
319
+ const stored = [...storedAllowedTypes].filter(
318
320
  (value) => !viewNodeSchemaIdentifiers.has(value),
319
321
  );
320
- return { viewExtra, storedExtra };
322
+ return { view, stored };
321
323
  }
322
324
 
323
325
  /**
@@ -384,14 +386,13 @@ function* getAllowedTypeDiscrepancies(
384
386
  identifier: TreeNodeSchemaIdentifier | undefined,
385
387
  fieldKey: FieldKey | undefined,
386
388
  ): Iterable<FieldDiscrepancy> {
387
- const { viewExtra, storedExtra } = findExtraAllowedTypes(view, stored);
388
- if (viewExtra.length > 0 || storedExtra.length > 0) {
389
+ const discrepancies = findExtraAllowedTypes(view, stored);
390
+ if (discrepancies.view.length > 0 || discrepancies.stored.length > 0) {
389
391
  yield {
392
+ ...discrepancies,
390
393
  identifier,
391
394
  fieldKey,
392
395
  mismatch: "allowedTypes",
393
- view: viewExtra,
394
- stored: storedExtra,
395
396
  } satisfies AllowedTypeDiscrepancy;
396
397
  }
397
398
  }
@@ -24,16 +24,15 @@ export type {
24
24
  ITreeAlpha,
25
25
  } from "./tree.js";
26
26
  export { asTreeViewAlpha } from "./tree.js";
27
+ export { type SchemaStatics, schemaStatics } from "./schemaStatics.js";
27
28
  export {
28
29
  SchemaFactory,
29
30
  type ScopedSchemaName,
30
31
  type SchemaFactoryObjectOptions,
31
- type SchemaStatics,
32
- schemaStatics,
33
32
  type NodeSchemaOptions,
34
33
  type NodeSchemaOptionsAlpha,
35
34
  } from "./schemaFactory.js";
36
- export { SchemaFactoryAlpha } from "./schemaFactoryAlpha.js";
35
+ export { SchemaFactoryAlpha, type SchemaStaticsAlpha } from "./schemaFactoryAlpha.js";
37
36
  export type {
38
37
  ValidateRecursiveSchema,
39
38
  FixRecursiveArraySchema,