@fluidframework/tree 2.4.0 → 2.5.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 (446) hide show
  1. package/.vscode/settings.json +12 -1
  2. package/CHANGELOG.md +371 -0
  3. package/api-report/tree.alpha.api.md +271 -80
  4. package/api-report/tree.beta.api.md +100 -51
  5. package/api-report/tree.legacy.alpha.api.md +99 -50
  6. package/api-report/tree.legacy.public.api.md +99 -50
  7. package/api-report/tree.public.api.md +99 -50
  8. package/dist/alpha.d.ts +32 -2
  9. package/dist/beta.d.ts +6 -0
  10. package/dist/codec/codec.d.ts +24 -0
  11. package/dist/codec/codec.d.ts.map +1 -1
  12. package/dist/codec/codec.js +26 -1
  13. package/dist/codec/codec.js.map +1 -1
  14. package/dist/codec/index.d.ts +1 -1
  15. package/dist/codec/index.d.ts.map +1 -1
  16. package/dist/codec/index.js +2 -1
  17. package/dist/codec/index.js.map +1 -1
  18. package/dist/core/rebase/index.d.ts +2 -2
  19. package/dist/core/rebase/index.d.ts.map +1 -1
  20. package/dist/core/rebase/index.js +2 -2
  21. package/dist/core/rebase/index.js.map +1 -1
  22. package/dist/core/rebase/types.d.ts +0 -4
  23. package/dist/core/rebase/types.d.ts.map +1 -1
  24. package/dist/core/rebase/types.js +1 -7
  25. package/dist/core/rebase/types.js.map +1 -1
  26. package/dist/core/rebase/utils.d.ts +1 -0
  27. package/dist/core/rebase/utils.d.ts.map +1 -1
  28. package/dist/core/rebase/utils.js +29 -4
  29. package/dist/core/rebase/utils.js.map +1 -1
  30. package/dist/events/interop.d.ts +1 -7
  31. package/dist/events/interop.d.ts.map +1 -1
  32. package/dist/events/interop.js.map +1 -1
  33. package/dist/feature-libraries/chunked-forest/basicChunk.js +1 -1
  34. package/dist/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  35. package/dist/feature-libraries/chunked-forest/uniformChunk.js +1 -1
  36. package/dist/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  37. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts +8 -1
  38. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  39. package/dist/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  40. package/dist/feature-libraries/flex-tree/lazyNode.d.ts +2 -1
  41. package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  42. package/dist/feature-libraries/flex-tree/lazyNode.js +3 -0
  43. package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  44. package/dist/feature-libraries/object-forest/objectForest.js +1 -1
  45. package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
  46. package/dist/feature-libraries/treeCursorUtils.js +2 -2
  47. package/dist/feature-libraries/treeCursorUtils.js.map +1 -1
  48. package/dist/index.d.ts +4 -4
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +12 -7
  51. package/dist/index.js.map +1 -1
  52. package/dist/internalTypes.d.ts +1 -1
  53. package/dist/internalTypes.d.ts.map +1 -1
  54. package/dist/internalTypes.js.map +1 -1
  55. package/dist/legacy.d.ts +6 -0
  56. package/dist/packageVersion.d.ts +1 -1
  57. package/dist/packageVersion.js +1 -1
  58. package/dist/packageVersion.js.map +1 -1
  59. package/dist/public.d.ts +6 -0
  60. package/dist/shared-tree/independentView.d.ts +57 -0
  61. package/dist/shared-tree/independentView.d.ts.map +1 -0
  62. package/dist/shared-tree/independentView.js +89 -0
  63. package/dist/shared-tree/independentView.js.map +1 -0
  64. package/dist/shared-tree/index.d.ts +3 -1
  65. package/dist/shared-tree/index.d.ts.map +1 -1
  66. package/dist/shared-tree/index.js +6 -1
  67. package/dist/shared-tree/index.js.map +1 -1
  68. package/dist/shared-tree/schematizingTreeView.d.ts +12 -8
  69. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  70. package/dist/shared-tree/schematizingTreeView.js +28 -0
  71. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  72. package/dist/shared-tree/sharedTree.d.ts +10 -7
  73. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  74. package/dist/shared-tree/sharedTree.js.map +1 -1
  75. package/dist/shared-tree/treeApi.d.ts +6 -6
  76. package/dist/shared-tree/treeApi.d.ts.map +1 -1
  77. package/dist/shared-tree/treeApi.js.map +1 -1
  78. package/dist/shared-tree/treeApiAlpha.d.ts +147 -0
  79. package/dist/shared-tree/treeApiAlpha.d.ts.map +1 -0
  80. package/dist/shared-tree/treeApiAlpha.js +122 -0
  81. package/dist/shared-tree/treeApiAlpha.js.map +1 -0
  82. package/dist/shared-tree/treeCheckout.d.ts +12 -7
  83. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  84. package/dist/shared-tree/treeCheckout.js +11 -4
  85. package/dist/shared-tree/treeCheckout.js.map +1 -1
  86. package/dist/shared-tree-core/editManager.d.ts +13 -6
  87. package/dist/shared-tree-core/editManager.d.ts.map +1 -1
  88. package/dist/shared-tree-core/editManager.js +80 -33
  89. package/dist/shared-tree-core/editManager.js.map +1 -1
  90. package/dist/shared-tree-core/sharedTreeCore.d.ts +1 -0
  91. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  92. package/dist/shared-tree-core/sharedTreeCore.js +28 -3
  93. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  94. package/dist/simple-tree/api/conciseTree.d.ts +2 -1
  95. package/dist/simple-tree/api/conciseTree.d.ts.map +1 -1
  96. package/dist/simple-tree/api/conciseTree.js.map +1 -1
  97. package/dist/simple-tree/api/create.d.ts +6 -24
  98. package/dist/simple-tree/api/create.d.ts.map +1 -1
  99. package/dist/simple-tree/api/create.js +4 -19
  100. package/dist/simple-tree/api/create.js.map +1 -1
  101. package/dist/simple-tree/api/customTree.d.ts +1 -0
  102. package/dist/simple-tree/api/customTree.d.ts.map +1 -1
  103. package/dist/simple-tree/api/customTree.js +2 -2
  104. package/dist/simple-tree/api/customTree.js.map +1 -1
  105. package/dist/simple-tree/api/index.d.ts +7 -7
  106. package/dist/simple-tree/api/index.d.ts.map +1 -1
  107. package/dist/simple-tree/api/index.js +10 -2
  108. package/dist/simple-tree/api/index.js.map +1 -1
  109. package/dist/simple-tree/api/schemaCreationUtilities.d.ts +25 -27
  110. package/dist/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
  111. package/dist/simple-tree/api/schemaCreationUtilities.js +31 -21
  112. package/dist/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  113. package/dist/simple-tree/api/schemaFactory.d.ts +16 -12
  114. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  115. package/dist/simple-tree/api/schemaFactory.js +4 -0
  116. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  117. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +3 -3
  118. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  119. package/dist/simple-tree/api/storedSchema.js +2 -2
  120. package/dist/simple-tree/api/storedSchema.js.map +1 -1
  121. package/dist/simple-tree/api/testRecursiveDomain.d.ts +5 -5
  122. package/dist/simple-tree/api/tree.d.ts +122 -5
  123. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  124. package/dist/simple-tree/api/tree.js +12 -4
  125. package/dist/simple-tree/api/tree.js.map +1 -1
  126. package/dist/simple-tree/api/treeApiBeta.d.ts +8 -5
  127. package/dist/simple-tree/api/treeApiBeta.d.ts.map +1 -1
  128. package/dist/simple-tree/api/treeApiBeta.js +3 -15
  129. package/dist/simple-tree/api/treeApiBeta.js.map +1 -1
  130. package/dist/simple-tree/api/typesUnsafe.d.ts +69 -17
  131. package/dist/simple-tree/api/typesUnsafe.d.ts.map +1 -1
  132. package/dist/simple-tree/api/typesUnsafe.js.map +1 -1
  133. package/dist/simple-tree/api/verboseTree.d.ts +3 -0
  134. package/dist/simple-tree/api/verboseTree.d.ts.map +1 -1
  135. package/dist/simple-tree/api/verboseTree.js.map +1 -1
  136. package/dist/simple-tree/arrayNode.d.ts +15 -4
  137. package/dist/simple-tree/arrayNode.d.ts.map +1 -1
  138. package/dist/simple-tree/arrayNode.js +1 -1
  139. package/dist/simple-tree/arrayNode.js.map +1 -1
  140. package/dist/simple-tree/core/getOrCreateNode.js.map +1 -1
  141. package/dist/simple-tree/core/treeNodeSchema.d.ts +51 -11
  142. package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  143. package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
  144. package/dist/simple-tree/core/unhydratedFlexTree.d.ts +2 -1
  145. package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  146. package/dist/simple-tree/core/unhydratedFlexTree.js +3 -0
  147. package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  148. package/dist/simple-tree/core/withType.d.ts +2 -1
  149. package/dist/simple-tree/core/withType.d.ts.map +1 -1
  150. package/dist/simple-tree/core/withType.js.map +1 -1
  151. package/dist/simple-tree/createContext.js +2 -2
  152. package/dist/simple-tree/createContext.js.map +1 -1
  153. package/dist/simple-tree/index.d.ts +6 -6
  154. package/dist/simple-tree/index.d.ts.map +1 -1
  155. package/dist/simple-tree/index.js +15 -5
  156. package/dist/simple-tree/index.js.map +1 -1
  157. package/dist/simple-tree/leafNodeSchema.d.ts +6 -5
  158. package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
  159. package/dist/simple-tree/leafNodeSchema.js +3 -0
  160. package/dist/simple-tree/leafNodeSchema.js.map +1 -1
  161. package/dist/simple-tree/mapNode.d.ts +1 -1
  162. package/dist/simple-tree/mapNode.d.ts.map +1 -1
  163. package/dist/simple-tree/mapNode.js +6 -0
  164. package/dist/simple-tree/mapNode.js.map +1 -1
  165. package/dist/simple-tree/objectNode.d.ts +4 -2
  166. package/dist/simple-tree/objectNode.d.ts.map +1 -1
  167. package/dist/simple-tree/objectNode.js.map +1 -1
  168. package/dist/simple-tree/schemaTypes.d.ts +210 -18
  169. package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
  170. package/dist/simple-tree/schemaTypes.js +66 -1
  171. package/dist/simple-tree/schemaTypes.js.map +1 -1
  172. package/dist/simple-tree/toMapTree.d.ts +4 -2
  173. package/dist/simple-tree/toMapTree.d.ts.map +1 -1
  174. package/dist/simple-tree/toMapTree.js.map +1 -1
  175. package/dist/simple-tree/{toFlexSchema.d.ts → toStoredSchema.d.ts} +1 -1
  176. package/dist/simple-tree/toStoredSchema.d.ts.map +1 -0
  177. package/dist/simple-tree/{toFlexSchema.js → toStoredSchema.js} +1 -1
  178. package/dist/simple-tree/toStoredSchema.js.map +1 -0
  179. package/dist/simple-tree/treeNodeValid.d.ts +5 -1
  180. package/dist/simple-tree/treeNodeValid.d.ts.map +1 -1
  181. package/dist/simple-tree/treeNodeValid.js +7 -1
  182. package/dist/simple-tree/treeNodeValid.js.map +1 -1
  183. package/dist/util/index.d.ts +3 -2
  184. package/dist/util/index.d.ts.map +1 -1
  185. package/dist/util/index.js +3 -1
  186. package/dist/util/index.js.map +1 -1
  187. package/dist/util/typeCheck.d.ts +9 -0
  188. package/dist/util/typeCheck.d.ts.map +1 -1
  189. package/dist/util/typeCheck.js.map +1 -1
  190. package/dist/util/typeUtils.d.ts +61 -0
  191. package/dist/util/typeUtils.d.ts.map +1 -1
  192. package/dist/util/typeUtils.js +27 -0
  193. package/dist/util/typeUtils.js.map +1 -1
  194. package/dist/util/utils.d.ts +7 -3
  195. package/dist/util/utils.d.ts.map +1 -1
  196. package/dist/util/utils.js +13 -3
  197. package/dist/util/utils.js.map +1 -1
  198. package/lib/alpha.d.ts +32 -2
  199. package/lib/beta.d.ts +6 -0
  200. package/lib/codec/codec.d.ts +24 -0
  201. package/lib/codec/codec.d.ts.map +1 -1
  202. package/lib/codec/codec.js +25 -0
  203. package/lib/codec/codec.js.map +1 -1
  204. package/lib/codec/index.d.ts +1 -1
  205. package/lib/codec/index.d.ts.map +1 -1
  206. package/lib/codec/index.js +1 -1
  207. package/lib/codec/index.js.map +1 -1
  208. package/lib/core/rebase/index.d.ts +2 -2
  209. package/lib/core/rebase/index.d.ts.map +1 -1
  210. package/lib/core/rebase/index.js +2 -2
  211. package/lib/core/rebase/index.js.map +1 -1
  212. package/lib/core/rebase/types.d.ts +0 -4
  213. package/lib/core/rebase/types.d.ts.map +1 -1
  214. package/lib/core/rebase/types.js +0 -5
  215. package/lib/core/rebase/types.js.map +1 -1
  216. package/lib/core/rebase/utils.d.ts +1 -0
  217. package/lib/core/rebase/utils.d.ts.map +1 -1
  218. package/lib/core/rebase/utils.js +27 -3
  219. package/lib/core/rebase/utils.js.map +1 -1
  220. package/lib/events/interop.d.ts +1 -7
  221. package/lib/events/interop.d.ts.map +1 -1
  222. package/lib/events/interop.js.map +1 -1
  223. package/lib/feature-libraries/chunked-forest/basicChunk.js +1 -1
  224. package/lib/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  225. package/lib/feature-libraries/chunked-forest/uniformChunk.js +1 -1
  226. package/lib/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  227. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts +8 -1
  228. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  229. package/lib/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  230. package/lib/feature-libraries/flex-tree/lazyNode.d.ts +2 -1
  231. package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  232. package/lib/feature-libraries/flex-tree/lazyNode.js +3 -0
  233. package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  234. package/lib/feature-libraries/object-forest/objectForest.js +1 -1
  235. package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
  236. package/lib/feature-libraries/treeCursorUtils.js +2 -2
  237. package/lib/feature-libraries/treeCursorUtils.js.map +1 -1
  238. package/lib/index.d.ts +4 -4
  239. package/lib/index.d.ts.map +1 -1
  240. package/lib/index.js +4 -3
  241. package/lib/index.js.map +1 -1
  242. package/lib/internalTypes.d.ts +1 -1
  243. package/lib/internalTypes.d.ts.map +1 -1
  244. package/lib/internalTypes.js.map +1 -1
  245. package/lib/legacy.d.ts +6 -0
  246. package/lib/packageVersion.d.ts +1 -1
  247. package/lib/packageVersion.js +1 -1
  248. package/lib/packageVersion.js.map +1 -1
  249. package/lib/public.d.ts +6 -0
  250. package/lib/shared-tree/independentView.d.ts +57 -0
  251. package/lib/shared-tree/independentView.d.ts.map +1 -0
  252. package/lib/shared-tree/independentView.js +84 -0
  253. package/lib/shared-tree/independentView.js.map +1 -0
  254. package/lib/shared-tree/index.d.ts +3 -1
  255. package/lib/shared-tree/index.d.ts.map +1 -1
  256. package/lib/shared-tree/index.js +2 -0
  257. package/lib/shared-tree/index.js.map +1 -1
  258. package/lib/shared-tree/schematizingTreeView.d.ts +12 -8
  259. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  260. package/lib/shared-tree/schematizingTreeView.js +29 -1
  261. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  262. package/lib/shared-tree/sharedTree.d.ts +10 -7
  263. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  264. package/lib/shared-tree/sharedTree.js.map +1 -1
  265. package/lib/shared-tree/treeApi.d.ts +6 -6
  266. package/lib/shared-tree/treeApi.d.ts.map +1 -1
  267. package/lib/shared-tree/treeApi.js.map +1 -1
  268. package/lib/shared-tree/treeApiAlpha.d.ts +147 -0
  269. package/lib/shared-tree/treeApiAlpha.d.ts.map +1 -0
  270. package/lib/shared-tree/treeApiAlpha.js +119 -0
  271. package/lib/shared-tree/treeApiAlpha.js.map +1 -0
  272. package/lib/shared-tree/treeCheckout.d.ts +12 -7
  273. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  274. package/lib/shared-tree/treeCheckout.js +11 -4
  275. package/lib/shared-tree/treeCheckout.js.map +1 -1
  276. package/lib/shared-tree-core/editManager.d.ts +13 -6
  277. package/lib/shared-tree-core/editManager.d.ts.map +1 -1
  278. package/lib/shared-tree-core/editManager.js +80 -33
  279. package/lib/shared-tree-core/editManager.js.map +1 -1
  280. package/lib/shared-tree-core/sharedTreeCore.d.ts +1 -0
  281. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  282. package/lib/shared-tree-core/sharedTreeCore.js +29 -4
  283. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  284. package/lib/simple-tree/api/conciseTree.d.ts +2 -1
  285. package/lib/simple-tree/api/conciseTree.d.ts.map +1 -1
  286. package/lib/simple-tree/api/conciseTree.js.map +1 -1
  287. package/lib/simple-tree/api/create.d.ts +6 -24
  288. package/lib/simple-tree/api/create.d.ts.map +1 -1
  289. package/lib/simple-tree/api/create.js +2 -16
  290. package/lib/simple-tree/api/create.js.map +1 -1
  291. package/lib/simple-tree/api/customTree.d.ts +1 -0
  292. package/lib/simple-tree/api/customTree.d.ts.map +1 -1
  293. package/lib/simple-tree/api/customTree.js +2 -2
  294. package/lib/simple-tree/api/customTree.js.map +1 -1
  295. package/lib/simple-tree/api/index.d.ts +7 -7
  296. package/lib/simple-tree/api/index.d.ts.map +1 -1
  297. package/lib/simple-tree/api/index.js +6 -4
  298. package/lib/simple-tree/api/index.js.map +1 -1
  299. package/lib/simple-tree/api/schemaCreationUtilities.d.ts +25 -27
  300. package/lib/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
  301. package/lib/simple-tree/api/schemaCreationUtilities.js +30 -19
  302. package/lib/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  303. package/lib/simple-tree/api/schemaFactory.d.ts +16 -12
  304. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  305. package/lib/simple-tree/api/schemaFactory.js +4 -0
  306. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  307. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +3 -3
  308. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  309. package/lib/simple-tree/api/storedSchema.js +1 -1
  310. package/lib/simple-tree/api/storedSchema.js.map +1 -1
  311. package/lib/simple-tree/api/testRecursiveDomain.d.ts +5 -5
  312. package/lib/simple-tree/api/tree.d.ts +122 -5
  313. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  314. package/lib/simple-tree/api/tree.js +9 -2
  315. package/lib/simple-tree/api/tree.js.map +1 -1
  316. package/lib/simple-tree/api/treeApiBeta.d.ts +8 -5
  317. package/lib/simple-tree/api/treeApiBeta.d.ts.map +1 -1
  318. package/lib/simple-tree/api/treeApiBeta.js +4 -16
  319. package/lib/simple-tree/api/treeApiBeta.js.map +1 -1
  320. package/lib/simple-tree/api/typesUnsafe.d.ts +69 -17
  321. package/lib/simple-tree/api/typesUnsafe.d.ts.map +1 -1
  322. package/lib/simple-tree/api/typesUnsafe.js.map +1 -1
  323. package/lib/simple-tree/api/verboseTree.d.ts +3 -0
  324. package/lib/simple-tree/api/verboseTree.d.ts.map +1 -1
  325. package/lib/simple-tree/api/verboseTree.js.map +1 -1
  326. package/lib/simple-tree/arrayNode.d.ts +15 -4
  327. package/lib/simple-tree/arrayNode.d.ts.map +1 -1
  328. package/lib/simple-tree/arrayNode.js +1 -1
  329. package/lib/simple-tree/arrayNode.js.map +1 -1
  330. package/lib/simple-tree/core/getOrCreateNode.js.map +1 -1
  331. package/lib/simple-tree/core/treeNodeSchema.d.ts +51 -11
  332. package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  333. package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
  334. package/lib/simple-tree/core/unhydratedFlexTree.d.ts +2 -1
  335. package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  336. package/lib/simple-tree/core/unhydratedFlexTree.js +4 -1
  337. package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  338. package/lib/simple-tree/core/withType.d.ts +2 -1
  339. package/lib/simple-tree/core/withType.d.ts.map +1 -1
  340. package/lib/simple-tree/core/withType.js.map +1 -1
  341. package/lib/simple-tree/createContext.js +1 -1
  342. package/lib/simple-tree/createContext.js.map +1 -1
  343. package/lib/simple-tree/index.d.ts +6 -6
  344. package/lib/simple-tree/index.d.ts.map +1 -1
  345. package/lib/simple-tree/index.js +5 -5
  346. package/lib/simple-tree/index.js.map +1 -1
  347. package/lib/simple-tree/leafNodeSchema.d.ts +6 -5
  348. package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
  349. package/lib/simple-tree/leafNodeSchema.js +3 -0
  350. package/lib/simple-tree/leafNodeSchema.js.map +1 -1
  351. package/lib/simple-tree/mapNode.d.ts +1 -1
  352. package/lib/simple-tree/mapNode.d.ts.map +1 -1
  353. package/lib/simple-tree/mapNode.js +6 -0
  354. package/lib/simple-tree/mapNode.js.map +1 -1
  355. package/lib/simple-tree/objectNode.d.ts +4 -2
  356. package/lib/simple-tree/objectNode.d.ts.map +1 -1
  357. package/lib/simple-tree/objectNode.js.map +1 -1
  358. package/lib/simple-tree/schemaTypes.d.ts +210 -18
  359. package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
  360. package/lib/simple-tree/schemaTypes.js +64 -1
  361. package/lib/simple-tree/schemaTypes.js.map +1 -1
  362. package/lib/simple-tree/toMapTree.d.ts +4 -2
  363. package/lib/simple-tree/toMapTree.d.ts.map +1 -1
  364. package/lib/simple-tree/toMapTree.js.map +1 -1
  365. package/lib/simple-tree/{toFlexSchema.d.ts → toStoredSchema.d.ts} +1 -1
  366. package/lib/simple-tree/toStoredSchema.d.ts.map +1 -0
  367. package/lib/simple-tree/{toFlexSchema.js → toStoredSchema.js} +1 -1
  368. package/lib/simple-tree/toStoredSchema.js.map +1 -0
  369. package/lib/simple-tree/treeNodeValid.d.ts +5 -1
  370. package/lib/simple-tree/treeNodeValid.d.ts.map +1 -1
  371. package/lib/simple-tree/treeNodeValid.js +7 -1
  372. package/lib/simple-tree/treeNodeValid.js.map +1 -1
  373. package/lib/util/index.d.ts +3 -2
  374. package/lib/util/index.d.ts.map +1 -1
  375. package/lib/util/index.js +1 -0
  376. package/lib/util/index.js.map +1 -1
  377. package/lib/util/typeCheck.d.ts +9 -0
  378. package/lib/util/typeCheck.d.ts.map +1 -1
  379. package/lib/util/typeCheck.js.map +1 -1
  380. package/lib/util/typeUtils.d.ts +61 -0
  381. package/lib/util/typeUtils.d.ts.map +1 -1
  382. package/lib/util/typeUtils.js +25 -1
  383. package/lib/util/typeUtils.js.map +1 -1
  384. package/lib/util/utils.d.ts +7 -3
  385. package/lib/util/utils.d.ts.map +1 -1
  386. package/lib/util/utils.js +13 -3
  387. package/lib/util/utils.js.map +1 -1
  388. package/package.json +55 -30
  389. package/src/codec/codec.ts +25 -0
  390. package/src/codec/index.ts +1 -0
  391. package/src/core/rebase/index.ts +1 -1
  392. package/src/core/rebase/types.ts +0 -12
  393. package/src/core/rebase/utils.ts +35 -3
  394. package/src/events/interop.ts +1 -12
  395. package/src/feature-libraries/chunked-forest/basicChunk.ts +1 -1
  396. package/src/feature-libraries/chunked-forest/uniformChunk.ts +1 -1
  397. package/src/feature-libraries/flex-tree/flexTreeTypes.ts +9 -0
  398. package/src/feature-libraries/flex-tree/lazyNode.ts +5 -0
  399. package/src/feature-libraries/object-forest/objectForest.ts +1 -1
  400. package/src/feature-libraries/treeCursorUtils.ts +2 -2
  401. package/src/index.ts +36 -6
  402. package/src/internalTypes.ts +4 -0
  403. package/src/packageVersion.ts +1 -1
  404. package/src/shared-tree/independentView.ts +176 -0
  405. package/src/shared-tree/index.ts +9 -1
  406. package/src/shared-tree/schematizingTreeView.ts +64 -13
  407. package/src/shared-tree/sharedTree.ts +29 -9
  408. package/src/shared-tree/treeApi.ts +19 -9
  409. package/src/shared-tree/treeApiAlpha.ts +401 -0
  410. package/src/shared-tree/treeCheckout.ts +28 -5
  411. package/src/shared-tree-core/editManager.ts +126 -59
  412. package/src/shared-tree-core/sharedTreeCore.ts +37 -8
  413. package/src/simple-tree/api/conciseTree.ts +2 -1
  414. package/src/simple-tree/api/create.ts +33 -65
  415. package/src/simple-tree/api/customTree.ts +3 -2
  416. package/src/simple-tree/api/index.ts +19 -8
  417. package/src/simple-tree/api/schemaCreationUtilities.ts +59 -37
  418. package/src/simple-tree/api/schemaFactory.ts +28 -12
  419. package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +3 -3
  420. package/src/simple-tree/api/storedSchema.ts +1 -1
  421. package/src/simple-tree/api/tree.ts +152 -7
  422. package/src/simple-tree/api/treeApiBeta.ts +35 -31
  423. package/src/simple-tree/api/typesUnsafe.ts +125 -30
  424. package/src/simple-tree/api/verboseTree.ts +3 -0
  425. package/src/simple-tree/arrayNode.ts +38 -17
  426. package/src/simple-tree/core/getOrCreateNode.ts +1 -1
  427. package/src/simple-tree/core/treeNodeSchema.ts +107 -34
  428. package/src/simple-tree/core/unhydratedFlexTree.ts +6 -0
  429. package/src/simple-tree/core/withType.ts +2 -1
  430. package/src/simple-tree/createContext.ts +1 -1
  431. package/src/simple-tree/index.ts +34 -3
  432. package/src/simple-tree/leafNodeSchema.ts +6 -1
  433. package/src/simple-tree/mapNode.ts +13 -4
  434. package/src/simple-tree/objectNode.ts +5 -3
  435. package/src/simple-tree/schemaTypes.ts +342 -36
  436. package/src/simple-tree/toMapTree.ts +4 -1
  437. package/src/simple-tree/treeNodeValid.ts +11 -1
  438. package/src/util/index.ts +7 -0
  439. package/src/util/typeCheck.ts +13 -0
  440. package/src/util/typeUtils.ts +87 -0
  441. package/src/util/utils.ts +20 -7
  442. package/dist/simple-tree/toFlexSchema.d.ts.map +0 -1
  443. package/dist/simple-tree/toFlexSchema.js.map +0 -1
  444. package/lib/simple-tree/toFlexSchema.d.ts.map +0 -1
  445. package/lib/simple-tree/toFlexSchema.js.map +0 -1
  446. /package/src/simple-tree/{toFlexSchema.ts → toStoredSchema.ts} +0 -0
@@ -4,21 +4,29 @@
4
4
  */
5
5
  import type { ErasedType, IFluidHandle } from "@fluidframework/core-interfaces";
6
6
  import type { NodeKeyManager } from "../feature-libraries/index.js";
7
- import { type MakeNominal } from "../util/index.js";
8
- import type { Unhydrated, NodeKind, TreeNodeSchema, TreeNodeSchemaClass } from "./core/index.js";
7
+ import { type MakeNominal, type UnionToIntersection } from "../util/index.js";
8
+ import type { Unhydrated, NodeKind, TreeNodeSchema, TreeNodeSchemaClass, TreeNode, TreeNodeSchemaCore } from "./core/index.js";
9
9
  import type { FieldKey } from "../core/index.js";
10
10
  import type { InsertableContent } from "./toMapTree.js";
11
11
  import { type FlexListToUnion, type LazyItem } from "./flexList.js";
12
12
  /**
13
13
  * Returns true if the given schema is a {@link TreeNodeSchemaClass}, or otherwise false if it is a {@link TreeNodeSchemaNonClass}.
14
14
  */
15
- export declare function isTreeNodeSchemaClass<Name extends string, Kind extends NodeKind, TNode, TBuild, ImplicitlyConstructable extends boolean, Info>(schema: TreeNodeSchema<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info>): schema is TreeNodeSchemaClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info>;
15
+ export declare function isTreeNodeSchemaClass<Name extends string, Kind extends NodeKind, TNode extends TreeNode | TreeLeafValue, TBuild, ImplicitlyConstructable extends boolean, Info>(schema: TreeNodeSchema<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info> | TreeNodeSchemaClass<Name, Kind, TNode & TreeNode, TBuild, ImplicitlyConstructable, Info>): schema is TreeNodeSchemaClass<Name, Kind, TNode & TreeNode, TBuild, ImplicitlyConstructable, Info>;
16
16
  /**
17
17
  * Types for use in fields.
18
18
  * @remarks
19
19
  * Type constraint used in schema declaration APIs.
20
+ *
21
+ * The order of types in the array is not significant.
22
+ * Additionally, it is legal for users of this type to have the runtime and compile time order of items within this array not match.
23
+ * Therefor to ensure type safety, these arrays should not be indexed, and instead just be iterated.
24
+ *
25
+ * Ideally this restriction would be modeled in the type itself, but it is not ergonomic to do so as there is no easy (when compared to arrays)
26
+ * way to declare and manipulate unordered sets of types in TypeScript.
27
+ *
20
28
  * Not intended for direct use outside of package.
21
- * @public
29
+ * @system @public
22
30
  */
23
31
  export type AllowedTypes = readonly LazyItem<TreeNodeSchema>[];
24
32
  /**
@@ -249,6 +257,25 @@ export declare function normalizeFieldSchema(schema: ImplicitFieldSchema): Field
249
257
  * recursive schemas may fail.
250
258
  */
251
259
  export declare function normalizeAllowedTypes(types: ImplicitAllowedTypes): ReadonlySet<TreeNodeSchema>;
260
+ /**
261
+ * Returns true if the given {@link ImplicitFieldSchema} are equivalent, otherwise false.
262
+ * @remarks Two ImplicitFieldSchema are considered equivalent if all of the following are true:
263
+ * 1. They have the same {@link FieldKind | kinds}.
264
+ * 2. They have {@link areFieldPropsEqual | equivalent FieldProps}.
265
+ * 3. They have the same exact set of allowed types. The allowed types must be (respectively) reference equal.
266
+ *
267
+ * For example, comparing an ImplicitFieldSchema that is a {@link TreeNodeSchema} to an ImplicitFieldSchema that is a {@link FieldSchema}
268
+ * will return true if they are the same kind, the FieldSchema has exactly one allowed type (the TreeNodeSchema), and they have equivalent FieldProps.
269
+ */
270
+ export declare function areImplicitFieldSchemaEqual(a: ImplicitFieldSchema, b: ImplicitFieldSchema): boolean;
271
+ /**
272
+ * Returns true if the given {@link FieldSchema} are equivalent, otherwise false.
273
+ * @remarks Two FieldSchema are considered equivalent if all of the following are true:
274
+ * 1. They have the same {@link FieldKind | kinds}.
275
+ * 2. They have {@link areFieldPropsEqual | equivalent FieldProps}.
276
+ * 3. They have the same exact set of allowed types. The allowed types must be reference equal.
277
+ */
278
+ export declare function areFieldSchemaEqual(a: FieldSchema, b: FieldSchema): boolean;
252
279
  /**
253
280
  * Types allowed in a field.
254
281
  * @remarks
@@ -264,35 +291,190 @@ export type ImplicitAllowedTypes = AllowedTypes | TreeNodeSchema;
264
291
  */
265
292
  export type ImplicitFieldSchema = FieldSchema | ImplicitAllowedTypes;
266
293
  /**
267
- * Converts ImplicitFieldSchema to the corresponding tree node's field type.
294
+ * Converts an `ImplicitFieldSchema` to a property type suitable for reading a field with this that schema.
295
+ *
296
+ * @typeparam TSchema - When non-exact schema are provided this errors on the side of returning too general of a type (a conservative union of all possibilities).
297
+ * This is ideal for "output APIs" - i.e. it converts the schema type to the runtime type that a user will _read_ from the tree.
298
+ * Examples of such "non-exact" schema include `ImplicitFieldSchema`, `ImplicitAllowedTypes`, and TypeScript unions of schema types.
268
299
  * @public
269
300
  */
270
- export type TreeFieldFromImplicitField<TSchema extends ImplicitFieldSchema = FieldSchema> = TSchema extends FieldSchema<infer Kind, infer Types> ? ApplyKind<TreeNodeFromImplicitAllowedTypes<Types>, Kind, false> : TSchema extends ImplicitAllowedTypes ? TreeNodeFromImplicitAllowedTypes<TSchema> : unknown;
301
+ export type TreeFieldFromImplicitField<TSchema extends ImplicitFieldSchema = FieldSchema> = TSchema extends FieldSchema<infer Kind, infer Types> ? ApplyKind<TreeNodeFromImplicitAllowedTypes<Types>, Kind> : TSchema extends ImplicitAllowedTypes ? TreeNodeFromImplicitAllowedTypes<TSchema> : TreeNode | TreeLeafValue | undefined;
271
302
  /**
272
303
  * Type of content that can be inserted into the tree for a field of the given schema.
304
+ *
305
+ * @see {@link Input}
306
+ *
307
+ * @typeparam TSchemaInput - Schema to process.
308
+ * @typeparam TSchema - Do not specify: default value used as implementation detail.
273
309
  * @public
274
310
  */
275
- export type InsertableTreeFieldFromImplicitField<TSchema extends ImplicitFieldSchema = FieldSchema> = TSchema extends FieldSchema<infer Kind, infer Types> ? ApplyKind<InsertableTreeNodeFromImplicitAllowedTypes<Types>, Kind, true> : TSchema extends ImplicitAllowedTypes ? InsertableTreeNodeFromImplicitAllowedTypes<TSchema> : unknown;
311
+ export type InsertableTreeFieldFromImplicitField<TSchemaInput extends ImplicitFieldSchema, TSchema = UnionToIntersection<TSchemaInput>> = [TSchema] extends [FieldSchema<infer Kind, infer Types>] ? ApplyKindInput<InsertableTreeNodeFromImplicitAllowedTypes<Types>, Kind, true> : [TSchema] extends [ImplicitAllowedTypes] ? InsertableTreeNodeFromImplicitAllowedTypes<TSchema> : never;
312
+ /**
313
+ * {@inheritdoc (UnsafeUnknownSchema:type)}
314
+ * @alpha
315
+ */
316
+ export declare const UnsafeUnknownSchema: unique symbol;
317
+ /**
318
+ * A special type which can be provided to some APIs as the schema type parameter when schema cannot easily be provided at compile time and an unsafe (instead of disabled) editing API is desired.
319
+ * @remarks
320
+ * When used, this means the TypeScript typing should err on the side of completeness (allow all inputs that could be valid).
321
+ * This introduces the risk that out-of-schema data could be allowed at compile time, and only error at runtime.
322
+ *
323
+ * @privateRemarks
324
+ * This only applies to APIs which input data which is expected to be in schema, since APIs outputting have easy mechanisms to do so in a type safe way even when the schema is unknown.
325
+ * In most cases that amounts to returning `TreeNode | TreeLeafValue`.
326
+ *
327
+ * This can be contrasted with the default behavior of TypeScript, which is to require the intersection of the possible types for input APIs,
328
+ * which for unknown schema defining input trees results in the `never` type.
329
+ *
330
+ * Any APIs which use this must produce UsageErrors when out of schema data is encountered, and never produce unrecoverable errors,
331
+ * or silently accept invalid data.
332
+ * This is currently only type exported from the package: the symbol is just used as a way to get a named type.
333
+ * @alpha
334
+ */
335
+ export type UnsafeUnknownSchema = typeof UnsafeUnknownSchema;
336
+ /**
337
+ * Content which could be inserted into a tree.
338
+ *
339
+ * @see {@link Input}
340
+ * @remarks
341
+ * Extended version of {@link InsertableTreeNodeFromImplicitAllowedTypes} that also allows {@link (UnsafeUnknownSchema:type)}.
342
+ * @alpha
343
+ */
344
+ export type Insertable<TSchema extends ImplicitAllowedTypes | UnsafeUnknownSchema> = TSchema extends ImplicitAllowedTypes ? InsertableTreeNodeFromImplicitAllowedTypes<TSchema> : InsertableContent;
345
+ /**
346
+ * Content which could be inserted into a field within a tree.
347
+ *
348
+ * @see {@link Input}
349
+ * @remarks
350
+ * Extended version of {@link InsertableTreeFieldFromImplicitField} that also allows {@link (UnsafeUnknownSchema:type)}.
351
+ * @alpha
352
+ */
353
+ export type InsertableField<TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema> = [
354
+ TSchema
355
+ ] extends [ImplicitFieldSchema] ? InsertableTreeFieldFromImplicitField<TSchema> : [TSchema] extends [UnsafeUnknownSchema] ? InsertableContent | undefined : never;
356
+ /**
357
+ * Content which could be read from a field within a tree.
358
+ *
359
+ * @remarks
360
+ * Extended version of {@link TreeFieldFromImplicitField} that also allows {@link (UnsafeUnknownSchema:type)}.
361
+ * Since reading from fields with non-exact schema is still safe, this is only useful (compared to {@link TreeFieldFromImplicitField}) when the schema is also used as input and thus allows {@link (UnsafeUnknownSchema:type)}
362
+ * for use
363
+ * @system @alpha
364
+ */
365
+ export type ReadableField<TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema> = TreeFieldFromImplicitField<ReadSchema<TSchema>>;
366
+ /**
367
+ * Adapter to remove {@link (UnsafeUnknownSchema:type)} from a schema type so it can be used with types for generating APIs for reading data.
368
+ *
369
+ * @remarks
370
+ * Since reading with non-exact schema is still safe, this is mainly useful when the schema is also used as input and thus allows {@link (UnsafeUnknownSchema:type)}.
371
+ * @system @alpha
372
+ */
373
+ export type ReadSchema<TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema> = [
374
+ TSchema
375
+ ] extends [ImplicitFieldSchema] ? TSchema : ImplicitFieldSchema;
276
376
  /**
277
377
  * Suitable for output.
278
378
  * For input must error on side of excluding undefined instead.
279
379
  * @system @public
280
380
  */
281
- export type ApplyKind<T, Kind extends FieldKind, DefaultsAreOptional extends boolean> = {
381
+ export type ApplyKind<T, Kind extends FieldKind> = {
282
382
  [FieldKind.Required]: T;
283
383
  [FieldKind.Optional]: T | undefined;
284
- [FieldKind.Identifier]: DefaultsAreOptional extends true ? T | undefined : T;
384
+ [FieldKind.Identifier]: T;
285
385
  }[Kind];
386
+ /**
387
+ * Suitable for input.
388
+ *
389
+ * @see {@link Input}
390
+ * @system @public
391
+ */
392
+ export type ApplyKindInput<T, Kind extends FieldKind, DefaultsAreOptional extends boolean> = [
393
+ Kind
394
+ ] extends [FieldKind.Required] ? T : [Kind] extends [FieldKind.Optional] ? T | undefined : [Kind] extends [FieldKind.Identifier] ? DefaultsAreOptional extends true ? T | undefined : T : never;
286
395
  /**
287
396
  * Type of tree node for a field of the given schema.
288
397
  * @public
289
398
  */
290
399
  export type TreeNodeFromImplicitAllowedTypes<TSchema extends ImplicitAllowedTypes = TreeNodeSchema> = TSchema extends TreeNodeSchema ? NodeFromSchema<TSchema> : TSchema extends AllowedTypes ? NodeFromSchema<FlexListToUnion<TSchema>> : unknown;
400
+ /**
401
+ * This type exists only to be linked from documentation to provide a single linkable place to document some details of
402
+ * "Input" types and how they handle schema.
403
+ *
404
+ * When a schema is used to describe data which is an input into an API, the API is [contravariant](https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)) over the schema.
405
+ * (See also, [TypeScript Variance Annotations](https://www.typescriptlang.org/docs/handbook/2/generics.html#variance-annotations)).
406
+ *
407
+ * Since these schema are expressed using TypeScript types, it is possible for the user of the API to provide non-exact values of these types which has implications that depended on the variance.
408
+ *
409
+ * Consider a field with schema type of `A | B` (where A and B are types of schema).
410
+ *
411
+ * - Reading the field behaves covariantly so {@link NodeFromSchema} of `<A | B>` is the same as `NodeFromSchema<A> | NodeFromSchema<B>`, indicating that either type of node can be read from the field.
412
+ * - Writing to the field behaves contravariantly. Since it is unknown if the node actually has a schema `A` or a schema `B`, the only legal values (known to be in schema regardless of which schema the underlying node has) are values which are legal for both `A & B`.
413
+ *
414
+ * Note that this is distinct from the case where the schema is `[A, B]`.
415
+ * In this case it is known that the field allows both A and B (the field can be set to an A or a B value).
416
+ * When `A | B` is used, the field might allow
417
+ * A but not B (so assigning a B value would be out of schema),
418
+ * B but not A (so assigning an A value would be out of schema)
419
+ * or both A and B.
420
+ *
421
+ * This gets more extreme when given completely unspecified schema.
422
+ * For example if a field is just provided {@link ImplicitFieldSchema}, nothing is known about the content of the field.
423
+ * This means that reading the field (via {@link TreeFieldFromImplicitField}) can give any valid tree field content,
424
+ * but there are no safe values which could be written to the field (since it is unknown what values would be out of schema) so {@link InsertableTreeFieldFromImplicitField} gives `never`.
425
+ *
426
+ * To implement this variance correctly, the computation of types for input and output have to use separate utilities
427
+ * which take very different approaches when encountering non-exact schema like unions or `ImplicitFieldSchema`.
428
+ * The utilities which behave contravariantly (as required to handle input correctly) link this documentation to indicate that this is how they behave.
429
+ *
430
+ * In addition to behaving contravariantly, these input type computation utilities often have further limitations.
431
+ * This is due to TypeScript making it difficult to implement this contravariance exactly.
432
+ * When faced with these implementation limitations these contravariant type computation utilities error on the side of producing overly strict requirements.
433
+ * For example in the above case of `A | B`, the utilities might compute an allowed insertable type as `never` even if there happens to be a common value accepted by both `A` and `B`.
434
+ * Future versions of the API can relax these requirements as the type computations are made more accurate.
435
+ *
436
+ * For a more concrete example: if {@link InsertableTreeFieldFromImplicitField} produced `never` for a schema `A | OptionalField<A>`,
437
+ * a future version could instead return a more flexible but still safe type, like `A`.
438
+ *
439
+ * More generally: try to avoid providing non-exact schema, especially for the fields of other schema.
440
+ * While these APIs attempt to handle such cases correctly, there are limitations and known bugs in this handling.
441
+ * Code using non-exact schema is much more likely to have its compilation break due to updates of this package or even TypeScript,
442
+ * and thus compilation breaks due to edge cases of non-exact schema handling, especially with recursive schema, are not considered breaking changes.
443
+ * This may change as the API become more stable.
444
+ *
445
+ * @privateRemarks
446
+ * There likely is a better way to share this documentation, but none was found at the time of writing.
447
+ *
448
+ * TODO: Once {@link InsertableField} is public, consider using it in the examples above.
449
+ * @system @public
450
+ */
451
+ export type Input<T extends never> = T;
291
452
  /**
292
453
  * Type of content that can be inserted into the tree for a node of the given schema.
454
+ *
455
+ * @see {@link Input}
456
+ *
457
+ * @typeparam TSchema - Schema to process.
458
+ *
459
+ * @privateRemarks
460
+ * This is a bit overly conservative, since cases like `A | [A]` give never and could give `A`.
293
461
  * @public
294
462
  */
295
- export type InsertableTreeNodeFromImplicitAllowedTypes<TSchema extends ImplicitAllowedTypes = TreeNodeSchema> = TSchema extends TreeNodeSchema ? InsertableTypedNode<TSchema> : TSchema extends AllowedTypes ? InsertableTypedNode<FlexListToUnion<TSchema>> : never;
463
+ export type InsertableTreeNodeFromImplicitAllowedTypes<TSchema extends ImplicitAllowedTypes> = [
464
+ TSchema
465
+ ] extends [TreeNodeSchema] ? InsertableTypedNode<TSchema> : [TSchema] extends [AllowedTypes] ? InsertableTreeNodeFromAllowedTypes<TSchema> : never;
466
+ /**
467
+ * Type of content that can be inserted into the tree for a node of the given schema.
468
+ *
469
+ * @see {@link Input}
470
+ *
471
+ * @typeparam TList - AllowedTypes to process
472
+ * @system @public
473
+ */
474
+ export type InsertableTreeNodeFromAllowedTypes<TList extends AllowedTypes> = TList extends readonly [
475
+ LazyItem<infer TSchema extends TreeNodeSchema>,
476
+ ...infer Rest extends AllowedTypes
477
+ ] ? InsertableTypedNode<TSchema> | InsertableTreeNodeFromAllowedTypes<Rest> : never;
296
478
  /**
297
479
  * Takes in `TreeNodeSchema[]` and returns a TypedNode union.
298
480
  * @public
@@ -301,21 +483,31 @@ export type NodeFromSchema<T extends TreeNodeSchema> = T extends TreeNodeSchema<
301
483
  /**
302
484
  * Data which can be used as a node to be inserted.
303
485
  * Either an unhydrated node, or content to build a new node.
486
+ *
487
+ * @see {@link Input}
488
+ *
489
+ * @typeparam TSchemaInput - Schema to process.
490
+ * @typeparam T - Do not specify: default value used as implementation detail.
491
+ * @privateRemarks
492
+ * This can't really be fully correct, since TreeNodeSchema's TNode is generally use covariantly but this code uses it contravariantly.
493
+ * That makes this TreeNodeSchema actually invariant with respect to TNode, but doing that would break all `extends TreeNodeSchema` clauses.
494
+ * As is, this works correctly in most realistic use-cases.
495
+ *
496
+ * One special case this makes is if the result of NodeFromSchema contains TreeNode, this must be an under constrained schema, so the result is set to never.
497
+ * Note that applying UnionToIntersection on the result of NodeFromSchema<T> does not work since it breaks booleans.
498
+ *
304
499
  * @public
305
500
  */
306
- export type InsertableTypedNode<T extends TreeNodeSchema> = (T extends {
307
- implicitlyConstructable: true;
308
- } ? NodeBuilderData<T> : never) | Unhydrated<NodeFromSchema<T>>;
501
+ export type InsertableTypedNode<TSchema extends TreeNodeSchema, T = UnionToIntersection<TSchema>> = (T extends TreeNodeSchema<string, NodeKind, TreeNode | TreeLeafValue, never, true> ? NodeBuilderData<T> : never) | (T extends TreeNodeSchema ? Unhydrated<TreeNode extends NodeFromSchema<T> ? never : NodeFromSchema<T>> : never);
309
502
  /**
310
503
  * Given a node's schema, return the corresponding object from which the node could be built.
311
504
  * @privateRemarks
312
- * Currently this assumes factory functions take exactly one argument.
313
- * This could be changed if needed.
314
- *
315
- * These factory functions can also take a FlexTreeNode, but this is not exposed in the public facing types.
505
+ * This uses TreeNodeSchemaCore, and thus depends on TreeNodeSchemaCore.createFromInsertable for the typing.
506
+ * This works almost the same as using TreeNodeSchema,
507
+ * except that the more complex typing in TreeNodeSchema case breaks for non-class schema and leaks in `undefined` from optional crete parameters.
316
508
  * @system @public
317
509
  */
318
- export type NodeBuilderData<T extends TreeNodeSchema> = T extends TreeNodeSchema<string, NodeKind, unknown, infer TBuild> ? TBuild : never;
510
+ export type NodeBuilderData<T extends TreeNodeSchemaCore<string, NodeKind, boolean>> = T extends TreeNodeSchemaCore<string, NodeKind, boolean, unknown, infer TBuild> ? TBuild : never;
319
511
  /**
320
512
  * Value that may be stored as a leaf node.
321
513
  * @remarks
@@ -1 +1 @@
1
- {"version":3,"file":"schemaTypes.d.ts","sourceRoot":"","sources":["../../src/simple-tree/schemaTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAIhF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,KAAK,WAAW,EAA0B,MAAM,kBAAkB,CAAC;AAC5E,OAAO,KAAK,EACX,UAAU,EACV,QAAQ,EACR,cAAc,EACd,mBAAmB,EACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAU,KAAK,eAAe,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE5E;;GAEG;AACH,wBAA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
6
6
  import { UsageError } from "@fluidframework/telemetry-utils/internal";
7
- import { brand, isReadonlyArray } from "../util/index.js";
7
+ import { brand, isReadonlyArray, compareSets, } from "../util/index.js";
8
8
  import { isLazy } from "./flexList.js";
9
9
  /**
10
10
  * Returns true if the given schema is a {@link TreeNodeSchemaClass}, or otherwise false if it is a {@link TreeNodeSchemaNonClass}.
@@ -155,6 +155,64 @@ export function normalizeAllowedTypes(types) {
155
155
  }
156
156
  return normalized;
157
157
  }
158
+ /**
159
+ * Returns true if the given {@link ImplicitFieldSchema} are equivalent, otherwise false.
160
+ * @remarks Two ImplicitFieldSchema are considered equivalent if all of the following are true:
161
+ * 1. They have the same {@link FieldKind | kinds}.
162
+ * 2. They have {@link areFieldPropsEqual | equivalent FieldProps}.
163
+ * 3. They have the same exact set of allowed types. The allowed types must be (respectively) reference equal.
164
+ *
165
+ * For example, comparing an ImplicitFieldSchema that is a {@link TreeNodeSchema} to an ImplicitFieldSchema that is a {@link FieldSchema}
166
+ * will return true if they are the same kind, the FieldSchema has exactly one allowed type (the TreeNodeSchema), and they have equivalent FieldProps.
167
+ */
168
+ export function areImplicitFieldSchemaEqual(a, b) {
169
+ return areFieldSchemaEqual(normalizeFieldSchema(a), normalizeFieldSchema(b));
170
+ }
171
+ /**
172
+ * Returns true if the given {@link FieldSchema} are equivalent, otherwise false.
173
+ * @remarks Two FieldSchema are considered equivalent if all of the following are true:
174
+ * 1. They have the same {@link FieldKind | kinds}.
175
+ * 2. They have {@link areFieldPropsEqual | equivalent FieldProps}.
176
+ * 3. They have the same exact set of allowed types. The allowed types must be reference equal.
177
+ */
178
+ export function areFieldSchemaEqual(a, b) {
179
+ if (a === b) {
180
+ return true;
181
+ }
182
+ if (a.kind !== b.kind) {
183
+ return false;
184
+ }
185
+ if (!areFieldPropsEqual(a.props, b.props)) {
186
+ return false;
187
+ }
188
+ return compareSets({ a: a.allowedTypeSet, b: b.allowedTypeSet });
189
+ }
190
+ /**
191
+ * Returns true if the given {@link FieldProps} are equivalent, otherwise false.
192
+ * @remarks FieldProps are considered equivalent if their keys and default providers are reference equal, and their metadata are {@link areMetadataEqual | equivalent}.
193
+ */
194
+ function areFieldPropsEqual(a, b) {
195
+ if (a === b) {
196
+ return true;
197
+ }
198
+ if (a?.key !== b?.key || a?.defaultProvider !== b?.defaultProvider) {
199
+ return false;
200
+ }
201
+ if (!areMetadataEqual(a?.metadata, b?.metadata)) {
202
+ return false;
203
+ }
204
+ return true;
205
+ }
206
+ /**
207
+ * Returns true if the given {@link FieldSchemaMetadata} are equivalent, otherwise false.
208
+ * @remarks FieldSchemaMetadata are considered equivalent if their custom data and descriptions are (respectively) reference equal.
209
+ */
210
+ function areMetadataEqual(a, b) {
211
+ if (a === b) {
212
+ return true;
213
+ }
214
+ return a?.custom === b?.custom && a?.description === b?.description;
215
+ }
158
216
  function evaluateLazySchema(value) {
159
217
  const evaluatedSchema = isLazy(value) ? value() : value;
160
218
  if (evaluatedSchema === undefined) {
@@ -162,4 +220,9 @@ function evaluateLazySchema(value) {
162
220
  }
163
221
  return evaluatedSchema;
164
222
  }
223
+ /**
224
+ * {@inheritdoc (UnsafeUnknownSchema:type)}
225
+ * @alpha
226
+ */
227
+ export const UnsafeUnknownSchema = Symbol("UnsafeUnknownSchema");
165
228
  //# sourceMappingURL=schemaTypes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemaTypes.js","sourceRoot":"","sources":["../../src/simple-tree/schemaTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAGtE,OAAO,EAAoB,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAS5E,OAAO,EAAE,MAAM,EAAuC,MAAM,eAAe,CAAC;AAE5E;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAQpC,MAAgF;IAEhF,OAAO,MAAM,CAAC,WAAW,KAAK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AC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IACxD,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QACnC,MAAM,IAAI,UAAU,CACnB,iHAAiH,CACjH,CAAC;IACH,CAAC;IACD,OAAO,eAAe,CAAC;AACxB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ErasedType, IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { Lazy } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { NodeKeyManager } from \"../feature-libraries/index.js\";\nimport { type MakeNominal, brand, isReadonlyArray } from \"../util/index.js\";\nimport type {\n\tUnhydrated,\n\tNodeKind,\n\tTreeNodeSchema,\n\tTreeNodeSchemaClass,\n} from \"./core/index.js\";\nimport type { FieldKey } from \"../core/index.js\";\nimport type { InsertableContent } from \"./toMapTree.js\";\nimport { isLazy, type FlexListToUnion, type LazyItem } from \"./flexList.js\";\n\n/**\n * Returns true if the given schema is a {@link TreeNodeSchemaClass}, or otherwise false if it is a {@link TreeNodeSchemaNonClass}.\n */\nexport function isTreeNodeSchemaClass<\n\tName extends string,\n\tKind extends NodeKind,\n\tTNode,\n\tTBuild,\n\tImplicitlyConstructable extends boolean,\n\tInfo,\n>(\n\tschema: TreeNodeSchema<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info>,\n): schema is TreeNodeSchemaClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info> {\n\treturn schema.constructor !== undefined;\n}\n\n/**\n * Types for use in fields.\n * @remarks\n * Type constraint used in schema declaration APIs.\n * Not intended for direct use outside of package.\n * @public\n */\nexport type AllowedTypes = readonly LazyItem<TreeNodeSchema>[];\n\n/**\n * Kind of a field on a node.\n * @remarks\n * More kinds may be added over time, so do not assume this is an exhaustive set.\n * @public\n */\nexport enum FieldKind {\n\t/**\n\t * A field which can be empty or filled.\n\t * @remarks\n\t * Allows 0 or one child.\n\t */\n\tOptional,\n\t/**\n\t * A field which must always be filled.\n\t * @remarks\n\t * Only allows exactly one child.\n\t */\n\tRequired,\n\t/**\n\t * A special field used for node identifiers.\n\t * @remarks\n\t * Only allows exactly one child.\n\t */\n\tIdentifier,\n}\n\n/**\n * Maps from a property key to its corresponding {@link FieldProps.key | stored key} for the provided\n * {@link ImplicitFieldSchema | field schema}.\n *\n * @remarks\n * If an explicit stored key was specified in the schema, it will be used.\n * Otherwise, the stored key is the same as the property key.\n */\nexport function getStoredKey(propertyKey: string, fieldSchema: ImplicitFieldSchema): FieldKey {\n\treturn brand(getExplicitStoredKey(fieldSchema) ?? propertyKey);\n}\n\n/**\n * Gets the {@link FieldProps.key | stored key} specified by the schema, if one was explicitly specified.\n * Otherwise, returns undefined.\n */\nexport function getExplicitStoredKey(fieldSchema: ImplicitFieldSchema): string | undefined {\n\treturn fieldSchema instanceof FieldSchema ? fieldSchema.props?.key : undefined;\n}\n\n/**\n * Additional information to provide to a {@link FieldSchema}.\n *\n * @typeParam TCustomMetadata - Custom metadata properties to associate with the field.\n * See {@link FieldSchemaMetadata.custom}.\n *\n * @public\n */\nexport interface FieldProps<TCustomMetadata = unknown> {\n\t/**\n\t * The unique identifier of a field, used in the persisted form of the tree.\n\t *\n\t * @remarks\n\t * If not explicitly set via the schema, this is the same as the schema's property key.\n\t *\n\t * Specifying a stored key that differs from the property key is particularly useful in refactoring scenarios.\n\t * To update the developer-facing API, while maintaining backwards compatibility with existing SharedTree data,\n\t * you can change the property key and specify the previous property key as the stored key.\n\t *\n\t * Notes:\n\t *\n\t * - Stored keys have no impact on standard JavaScript behavior, on tree nodes. For example, `Object.keys`\n\t * will always return the property keys specified in the schema, ignoring any stored keys that differ from\n\t * the property keys.\n\t *\n\t * - When specifying stored keys in an object schema, you must ensure that the final set of stored keys\n\t * (accounting for those implicitly derived from property keys) contains no duplicates.\n\t * This is validated at runtime.\n\t *\n\t * @example Refactoring code without breaking compatibility with existing data\n\t *\n\t * Consider some existing object schema:\n\t *\n\t * ```TypeScript\n\t * class Point extends schemaFactory.object(\"Point\", {\n\t * \txPosition: schemaFactory.number,\n\t * \tyPosition: schemaFactory.number,\n\t * \tzPosition: schemaFactory.optional(schemaFactory.number),\n\t * });\n\t * ```\n\t *\n\t * Developers using nodes of this type would access the the `xPosition` property as `point.xPosition`.\n\t *\n\t * We would like to refactor the schema to omit \"Position\" from the property keys, but application data has\n\t * already been persisted using the original property keys. To maintain compatibility with existing data,\n\t * we can refactor the schema as follows:\n\t *\n\t * ```TypeScript\n\t * class Point extends schemaFactory.object(\"Point\", {\n\t * \tx: schemaFactory.required(schemaFactory.number, { key: \"xPosition\" }),\n\t * \ty: schemaFactory.required(schemaFactory.number, { key: \"yPosition\" }),\n\t * \tz: schemaFactory.optional(schemaFactory.number, { key: \"zPosition\" }),\n\t * });\n\t * ```\n\t *\n\t * Now, developers can access the `x` property as `point.x`, while existing data can still be collaborated on.\n\t *\n\t * @defaultValue If not specified, the key that is persisted is the property key that was specified in the schema.\n\t */\n\treadonly key?: string;\n\n\t/**\n\t * A default provider used for fields which were not provided any values.\n\t * @privateRemarks\n\t * We are using an erased type here, as we want to expose this API but `InsertableContent` and `NodeKeyManager` are not public.\n\t */\n\treadonly defaultProvider?: DefaultProvider;\n\n\t/**\n\t * Optional metadata to associate with the field.\n\t * @remarks Note: this metadata is not persisted in the document.\n\t */\n\treadonly metadata?: FieldSchemaMetadata<TCustomMetadata>;\n}\n\n/**\n * A {@link FieldProvider} which requires additional context in order to produce its content\n */\nexport type ContextualFieldProvider = (\n\tcontext: NodeKeyManager,\n) => InsertableContent | undefined;\n/**\n * A {@link FieldProvider} which can produce its content in a vacuum\n */\nexport type ConstantFieldProvider = () => InsertableContent | undefined;\n/**\n * A function which produces content for a field every time that it is called\n */\nexport type FieldProvider = ContextualFieldProvider | ConstantFieldProvider;\n/**\n * Returns true if the given {@link FieldProvider} is a {@link ConstantFieldProvider}\n */\nexport function isConstant(\n\tfieldProvider: FieldProvider,\n): fieldProvider is ConstantFieldProvider {\n\treturn fieldProvider.length === 0;\n}\n\n/**\n * Provides a default value for a field.\n * @remarks\n * If present in a `FieldSchema`, when constructing new tree content that field can be omitted, and a default will be provided.\n * @system @sealed @public\n */\nexport interface DefaultProvider extends ErasedType<\"@fluidframework/tree.FieldProvider\"> {}\n\nexport function extractFieldProvider(input: DefaultProvider): FieldProvider {\n\treturn input as unknown as FieldProvider;\n}\n\nexport function getDefaultProvider(input: FieldProvider): DefaultProvider {\n\treturn input as unknown as DefaultProvider;\n}\n\n/**\n * Metadata associated with a {@link FieldSchema}.\n *\n * @remarks Specified via {@link FieldProps.metadata}.\n *\n * @sealed\n * @public\n */\nexport interface FieldSchemaMetadata<TCustomMetadata = unknown> {\n\t/**\n\t * User-defined metadata.\n\t */\n\treadonly custom?: TCustomMetadata;\n\n\t/**\n\t * The description of the field.\n\t *\n\t * @remarks\n\t *\n\t * If provided, will be used by the system in scenarios where a description of the field is useful.\n\t * E.g., when converting a field schema to {@link https://json-schema.org/ | JSON Schema}, this description will be\n\t * used as the `description` field.\n\t */\n\treadonly description?: string | undefined;\n}\n\n/**\n * Package internal construction API.\n */\nexport let createFieldSchema: <\n\tKind extends FieldKind = FieldKind,\n\tTypes extends ImplicitAllowedTypes = ImplicitAllowedTypes,\n\tTCustomMetadata = unknown,\n>(\n\tkind: Kind,\n\tallowedTypes: Types,\n\tprops?: FieldProps<TCustomMetadata>,\n) => FieldSchema<Kind, Types, TCustomMetadata>;\n\n/**\n * All policy for a specific field,\n * including functionality that does not have to be kept consistent across versions or deterministic.\n *\n * This can include policy for how to use this schema for \"view\" purposes, and well as how to expose editing APIs.\n * Use {@link SchemaFactory} to create the FieldSchema instances, for example {@link SchemaFactory.optional}.\n * @privateRemarks\n * Public access to the constructor is removed to prevent creating expressible but unsupported (or not stable) configurations.\n * {@link createFieldSchema} can be used internally to create instances.\n *\n * @typeParam TCustomMetadata - Custom metadata properties to associate with the field.\n * See {@link FieldSchemaMetadata.custom}.\n *\n * @sealed @public\n */\nexport class FieldSchema<\n\tout Kind extends FieldKind = FieldKind,\n\tout Types extends ImplicitAllowedTypes = ImplicitAllowedTypes,\n\tout TCustomMetadata = unknown,\n> {\n\tstatic {\n\t\tcreateFieldSchema = <\n\t\t\tKind2 extends FieldKind = FieldKind,\n\t\t\tTypes2 extends ImplicitAllowedTypes = ImplicitAllowedTypes,\n\t\t\tTCustomMetadata2 = unknown,\n\t\t>(\n\t\t\tkind: Kind2,\n\t\t\tallowedTypes: Types2,\n\t\t\tprops?: FieldProps<TCustomMetadata2>,\n\t\t) => new FieldSchema(kind, allowedTypes, props);\n\t}\n\t/**\n\t * This class is used with instanceof, and therefore should have nominal typing.\n\t * This field enforces that.\n\t */\n\tprotected _typeCheck!: MakeNominal;\n\n\tprivate readonly lazyTypes: Lazy<ReadonlySet<TreeNodeSchema>>;\n\n\t/**\n\t * What types of tree nodes are allowed in this field.\n\t * @remarks Counterpart to {@link FieldSchema.allowedTypes}, with any lazy definitions evaluated.\n\t */\n\tpublic get allowedTypeSet(): ReadonlySet<TreeNodeSchema> {\n\t\treturn this.lazyTypes.value;\n\t}\n\n\t/**\n\t * True if and only if, when constructing a node with this field, a value must be provided for it.\n\t */\n\tpublic readonly requiresValue: boolean;\n\n\t/**\n\t * {@inheritDoc FieldProps.metadata}\n\t */\n\tpublic get metadata(): FieldSchemaMetadata<TCustomMetadata> | undefined {\n\t\treturn this.props?.metadata;\n\t}\n\n\tprivate constructor(\n\t\t/**\n\t\t * The {@link https://en.wikipedia.org/wiki/Kind_(type_theory) | kind } of this field.\n\t\t * Determines the multiplicity, viewing and editing APIs as well as the merge resolution policy.\n\t\t */\n\t\tpublic readonly kind: Kind,\n\t\t/**\n\t\t * What types of tree nodes are allowed in this field.\n\t\t */\n\t\tpublic readonly allowedTypes: Types,\n\t\t/**\n\t\t * Optional properties associated with the field.\n\t\t */\n\t\tpublic readonly props?: FieldProps<TCustomMetadata>,\n\t) {\n\t\tthis.lazyTypes = new Lazy(() => normalizeAllowedTypes(this.allowedTypes));\n\t\t// TODO: optional fields should (by default) get a default provider that returns undefined, removing the need to special case them here:\n\t\tthis.requiresValue =\n\t\t\tthis.props?.defaultProvider === undefined && this.kind !== FieldKind.Optional;\n\t}\n}\n\n/**\n * Normalizes a {@link ImplicitFieldSchema} to a {@link FieldSchema}.\n */\nexport function normalizeFieldSchema(schema: ImplicitFieldSchema): FieldSchema {\n\treturn schema instanceof FieldSchema\n\t\t? schema\n\t\t: createFieldSchema(FieldKind.Required, schema);\n}\n/**\n * Normalizes a {@link ImplicitAllowedTypes} to a set of {@link TreeNodeSchema}s, by eagerly evaluating any\n * lazy schema declarations.\n *\n * @remarks Note: this must only be called after all required schemas have been declared, otherwise evaluation of\n * recursive schemas may fail.\n */\nexport function normalizeAllowedTypes(\n\ttypes: ImplicitAllowedTypes,\n): ReadonlySet<TreeNodeSchema> {\n\tconst normalized = new Set<TreeNodeSchema>();\n\tif (isReadonlyArray(types)) {\n\t\tfor (const lazyType of types) {\n\t\t\tnormalized.add(evaluateLazySchema(lazyType));\n\t\t}\n\t} else {\n\t\tnormalized.add(evaluateLazySchema(types));\n\t}\n\treturn normalized;\n}\n\nfunction evaluateLazySchema(value: LazyItem<TreeNodeSchema>): TreeNodeSchema {\n\tconst evaluatedSchema = isLazy(value) ? value() : value;\n\tif (evaluatedSchema === undefined) {\n\t\tthrow new UsageError(\n\t\t\t`Encountered an undefined schema. This could indicate that some referenced schema has not yet been instantiated.`,\n\t\t);\n\t}\n\treturn evaluatedSchema;\n}\n\n/**\n * Types allowed in a field.\n * @remarks\n * Implicitly treats a single type as an array of one type.\n * @public\n */\nexport type ImplicitAllowedTypes = AllowedTypes | TreeNodeSchema;\n\n/**\n * Schema for a field of a tree node.\n * @remarks\n * Implicitly treats {@link ImplicitAllowedTypes} as a Required field of that type.\n * @public\n */\nexport type ImplicitFieldSchema = FieldSchema | ImplicitAllowedTypes;\n\n/**\n * Converts ImplicitFieldSchema to the corresponding tree node's field type.\n * @public\n */\nexport type TreeFieldFromImplicitField<TSchema extends ImplicitFieldSchema = FieldSchema> =\n\tTSchema extends FieldSchema<infer Kind, infer Types>\n\t\t? ApplyKind<TreeNodeFromImplicitAllowedTypes<Types>, Kind, false>\n\t\t: TSchema extends ImplicitAllowedTypes\n\t\t\t? TreeNodeFromImplicitAllowedTypes<TSchema>\n\t\t\t: unknown;\n\n/**\n * Type of content that can be inserted into the tree for a field of the given schema.\n * @public\n */\nexport type InsertableTreeFieldFromImplicitField<\n\tTSchema extends ImplicitFieldSchema = FieldSchema,\n> = TSchema extends FieldSchema<infer Kind, infer Types>\n\t? ApplyKind<InsertableTreeNodeFromImplicitAllowedTypes<Types>, Kind, true>\n\t: TSchema extends ImplicitAllowedTypes\n\t\t? InsertableTreeNodeFromImplicitAllowedTypes<TSchema>\n\t\t: unknown;\n\n/**\n * Suitable for output.\n * For input must error on side of excluding undefined instead.\n * @system @public\n */\nexport type ApplyKind<T, Kind extends FieldKind, DefaultsAreOptional extends boolean> = {\n\t[FieldKind.Required]: T;\n\t[FieldKind.Optional]: T | undefined;\n\t[FieldKind.Identifier]: DefaultsAreOptional extends true ? T | undefined : T;\n}[Kind];\n\n/**\n * Type of tree node for a field of the given schema.\n * @public\n */\nexport type TreeNodeFromImplicitAllowedTypes<\n\tTSchema extends ImplicitAllowedTypes = TreeNodeSchema,\n> = TSchema extends TreeNodeSchema\n\t? NodeFromSchema<TSchema>\n\t: TSchema extends AllowedTypes\n\t\t? NodeFromSchema<FlexListToUnion<TSchema>>\n\t\t: unknown;\n\n/**\n * Type of content that can be inserted into the tree for a node of the given schema.\n * @public\n */\nexport type InsertableTreeNodeFromImplicitAllowedTypes<\n\tTSchema extends ImplicitAllowedTypes = TreeNodeSchema,\n> = TSchema extends TreeNodeSchema\n\t? InsertableTypedNode<TSchema>\n\t: TSchema extends AllowedTypes\n\t\t? InsertableTypedNode<FlexListToUnion<TSchema>>\n\t\t: never;\n\n/**\n * Takes in `TreeNodeSchema[]` and returns a TypedNode union.\n * @public\n */\nexport type NodeFromSchema<T extends TreeNodeSchema> = T extends TreeNodeSchema<\n\tstring,\n\tNodeKind,\n\tinfer TNode\n>\n\t? TNode\n\t: never;\n\n/**\n * Data which can be used as a node to be inserted.\n * Either an unhydrated node, or content to build a new node.\n * @public\n */\nexport type InsertableTypedNode<T extends TreeNodeSchema> =\n\t| (T extends { implicitlyConstructable: true } ? NodeBuilderData<T> : never)\n\t| Unhydrated<NodeFromSchema<T>>;\n\n/**\n * Given a node's schema, return the corresponding object from which the node could be built.\n * @privateRemarks\n * Currently this assumes factory functions take exactly one argument.\n * This could be changed if needed.\n *\n * These factory functions can also take a FlexTreeNode, but this is not exposed in the public facing types.\n * @system @public\n */\nexport type NodeBuilderData<T extends TreeNodeSchema> = T extends TreeNodeSchema<\n\tstring,\n\tNodeKind,\n\tunknown,\n\tinfer TBuild\n>\n\t? TBuild\n\t: never;\n\n/**\n * Value that may be stored as a leaf node.\n * @remarks\n * Some limitations apply, see the documentation for {@link SchemaFactory.number} and {@link SchemaFactory.string} for those restrictions.\n * @public\n */\n// eslint-disable-next-line @rushstack/no-new-null\nexport type TreeLeafValue = number | string | boolean | IFluidHandle | null;\n"]}
1
+ {"version":3,"file":"schemaTypes.js","sourceRoot":"","sources":["../../src/simple-tree/schemaTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAGtE,OAAO,EAEN,KAAK,EACL,eAAe,EAEf,WAAW,GAGX,MAAM,kBAAkB,CAAC;AAW1B,OAAO,EAAE,MAAM,EAAuC,MAAM,eAAe,CAAC;AAE5E;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAQpC,MAE2F;IAS3F,OAAO,MAAM,CAAC,WAAW,KAAK,SAAS,CAAC;AACzC,CAAC;AAmBD;;;;;GAKG;AACH,MAAM,CAAN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AAS,kBAAkB,CAAC,KAA+B;IAC1D,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IACxD,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QACnC,MAAM,IAAI,UAAU,CACnB,iHAAiH,CACjH,CAAC;IACH,CAAC;IACD,OAAO,eAAe,CAAC;AACxB,CAAC;AAmDD;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAkB,MAAM,CAAC,qBAAqB,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ErasedType, IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { Lazy } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { NodeKeyManager } from \"../feature-libraries/index.js\";\nimport {\n\ttype MakeNominal,\n\tbrand,\n\tisReadonlyArray,\n\ttype UnionToIntersection,\n\tcompareSets,\n\ttype requireTrue,\n\ttype areOnlyKeys,\n} from \"../util/index.js\";\nimport type {\n\tUnhydrated,\n\tNodeKind,\n\tTreeNodeSchema,\n\tTreeNodeSchemaClass,\n\tTreeNode,\n\tTreeNodeSchemaCore,\n} from \"./core/index.js\";\nimport type { FieldKey } from \"../core/index.js\";\nimport type { InsertableContent } from \"./toMapTree.js\";\nimport { isLazy, type FlexListToUnion, type LazyItem } from \"./flexList.js\";\n\n/**\n * Returns true if the given schema is a {@link TreeNodeSchemaClass}, or otherwise false if it is a {@link TreeNodeSchemaNonClass}.\n */\nexport function isTreeNodeSchemaClass<\n\tName extends string,\n\tKind extends NodeKind,\n\tTNode extends TreeNode | TreeLeafValue,\n\tTBuild,\n\tImplicitlyConstructable extends boolean,\n\tInfo,\n>(\n\tschema:\n\t\t| TreeNodeSchema<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info>\n\t\t| TreeNodeSchemaClass<Name, Kind, TNode & TreeNode, TBuild, ImplicitlyConstructable, Info>,\n): schema is TreeNodeSchemaClass<\n\tName,\n\tKind,\n\tTNode & TreeNode,\n\tTBuild,\n\tImplicitlyConstructable,\n\tInfo\n> {\n\treturn schema.constructor !== undefined;\n}\n\n/**\n * Types for use in fields.\n * @remarks\n * Type constraint used in schema declaration APIs.\n *\n * The order of types in the array is not significant.\n * Additionally, it is legal for users of this type to have the runtime and compile time order of items within this array not match.\n * Therefor to ensure type safety, these arrays should not be indexed, and instead just be iterated.\n *\n * Ideally this restriction would be modeled in the type itself, but it is not ergonomic to do so as there is no easy (when compared to arrays)\n * way to declare and manipulate unordered sets of types in TypeScript.\n *\n * Not intended for direct use outside of package.\n * @system @public\n */\nexport type AllowedTypes = readonly LazyItem<TreeNodeSchema>[];\n\n/**\n * Kind of a field on a node.\n * @remarks\n * More kinds may be added over time, so do not assume this is an exhaustive set.\n * @public\n */\nexport enum FieldKind {\n\t/**\n\t * A field which can be empty or filled.\n\t * @remarks\n\t * Allows 0 or one child.\n\t */\n\tOptional,\n\t/**\n\t * A field which must always be filled.\n\t * @remarks\n\t * Only allows exactly one child.\n\t */\n\tRequired,\n\t/**\n\t * A special field used for node identifiers.\n\t * @remarks\n\t * Only allows exactly one child.\n\t */\n\tIdentifier,\n}\n\n/**\n * Maps from a property key to its corresponding {@link FieldProps.key | stored key} for the provided\n * {@link ImplicitFieldSchema | field schema}.\n *\n * @remarks\n * If an explicit stored key was specified in the schema, it will be used.\n * Otherwise, the stored key is the same as the property key.\n */\nexport function getStoredKey(propertyKey: string, fieldSchema: ImplicitFieldSchema): FieldKey {\n\treturn brand(getExplicitStoredKey(fieldSchema) ?? propertyKey);\n}\n\n/**\n * Gets the {@link FieldProps.key | stored key} specified by the schema, if one was explicitly specified.\n * Otherwise, returns undefined.\n */\nexport function getExplicitStoredKey(fieldSchema: ImplicitFieldSchema): string | undefined {\n\treturn fieldSchema instanceof FieldSchema ? fieldSchema.props?.key : undefined;\n}\n\n/**\n * Additional information to provide to a {@link FieldSchema}.\n *\n * @typeParam TCustomMetadata - Custom metadata properties to associate with the field.\n * See {@link FieldSchemaMetadata.custom}.\n *\n * @public\n */\nexport interface FieldProps<TCustomMetadata = unknown> {\n\t/**\n\t * The unique identifier of a field, used in the persisted form of the tree.\n\t *\n\t * @remarks\n\t * If not explicitly set via the schema, this is the same as the schema's property key.\n\t *\n\t * Specifying a stored key that differs from the property key is particularly useful in refactoring scenarios.\n\t * To update the developer-facing API, while maintaining backwards compatibility with existing SharedTree data,\n\t * you can change the property key and specify the previous property key as the stored key.\n\t *\n\t * Notes:\n\t *\n\t * - Stored keys have no impact on standard JavaScript behavior, on tree nodes. For example, `Object.keys`\n\t * will always return the property keys specified in the schema, ignoring any stored keys that differ from\n\t * the property keys.\n\t *\n\t * - When specifying stored keys in an object schema, you must ensure that the final set of stored keys\n\t * (accounting for those implicitly derived from property keys) contains no duplicates.\n\t * This is validated at runtime.\n\t *\n\t * @example Refactoring code without breaking compatibility with existing data\n\t *\n\t * Consider some existing object schema:\n\t *\n\t * ```TypeScript\n\t * class Point extends schemaFactory.object(\"Point\", {\n\t * \txPosition: schemaFactory.number,\n\t * \tyPosition: schemaFactory.number,\n\t * \tzPosition: schemaFactory.optional(schemaFactory.number),\n\t * });\n\t * ```\n\t *\n\t * Developers using nodes of this type would access the the `xPosition` property as `point.xPosition`.\n\t *\n\t * We would like to refactor the schema to omit \"Position\" from the property keys, but application data has\n\t * already been persisted using the original property keys. To maintain compatibility with existing data,\n\t * we can refactor the schema as follows:\n\t *\n\t * ```TypeScript\n\t * class Point extends schemaFactory.object(\"Point\", {\n\t * \tx: schemaFactory.required(schemaFactory.number, { key: \"xPosition\" }),\n\t * \ty: schemaFactory.required(schemaFactory.number, { key: \"yPosition\" }),\n\t * \tz: schemaFactory.optional(schemaFactory.number, { key: \"zPosition\" }),\n\t * });\n\t * ```\n\t *\n\t * Now, developers can access the `x` property as `point.x`, while existing data can still be collaborated on.\n\t *\n\t * @defaultValue If not specified, the key that is persisted is the property key that was specified in the schema.\n\t */\n\treadonly key?: string;\n\n\t/**\n\t * A default provider used for fields which were not provided any values.\n\t * @privateRemarks\n\t * We are using an erased type here, as we want to expose this API but `InsertableContent` and `NodeKeyManager` are not public.\n\t */\n\treadonly defaultProvider?: DefaultProvider;\n\n\t/**\n\t * Optional metadata to associate with the field.\n\t * @remarks Note: this metadata is not persisted in the document.\n\t */\n\treadonly metadata?: FieldSchemaMetadata<TCustomMetadata>;\n}\n\n/**\n * A {@link FieldProvider} which requires additional context in order to produce its content\n */\nexport type ContextualFieldProvider = (\n\tcontext: NodeKeyManager,\n) => InsertableContent | undefined;\n/**\n * A {@link FieldProvider} which can produce its content in a vacuum\n */\nexport type ConstantFieldProvider = () => InsertableContent | undefined;\n/**\n * A function which produces content for a field every time that it is called\n */\nexport type FieldProvider = ContextualFieldProvider | ConstantFieldProvider;\n/**\n * Returns true if the given {@link FieldProvider} is a {@link ConstantFieldProvider}\n */\nexport function isConstant(\n\tfieldProvider: FieldProvider,\n): fieldProvider is ConstantFieldProvider {\n\treturn fieldProvider.length === 0;\n}\n\n/**\n * Provides a default value for a field.\n * @remarks\n * If present in a `FieldSchema`, when constructing new tree content that field can be omitted, and a default will be provided.\n * @system @sealed @public\n */\nexport interface DefaultProvider extends ErasedType<\"@fluidframework/tree.FieldProvider\"> {}\n\nexport function extractFieldProvider(input: DefaultProvider): FieldProvider {\n\treturn input as unknown as FieldProvider;\n}\n\nexport function getDefaultProvider(input: FieldProvider): DefaultProvider {\n\treturn input as unknown as DefaultProvider;\n}\n\n/**\n * Metadata associated with a {@link FieldSchema}.\n *\n * @remarks Specified via {@link FieldProps.metadata}.\n *\n * @sealed\n * @public\n */\nexport interface FieldSchemaMetadata<TCustomMetadata = unknown> {\n\t/**\n\t * User-defined metadata.\n\t */\n\treadonly custom?: TCustomMetadata;\n\n\t/**\n\t * The description of the field.\n\t *\n\t * @remarks\n\t *\n\t * If provided, will be used by the system in scenarios where a description of the field is useful.\n\t * E.g., when converting a field schema to {@link https://json-schema.org/ | JSON Schema}, this description will be\n\t * used as the `description` field.\n\t */\n\treadonly description?: string | undefined;\n}\n\n/**\n * Package internal construction API.\n */\nexport let createFieldSchema: <\n\tKind extends FieldKind = FieldKind,\n\tTypes extends ImplicitAllowedTypes = ImplicitAllowedTypes,\n\tTCustomMetadata = unknown,\n>(\n\tkind: Kind,\n\tallowedTypes: Types,\n\tprops?: FieldProps<TCustomMetadata>,\n) => FieldSchema<Kind, Types, TCustomMetadata>;\n\n/**\n * All policy for a specific field,\n * including functionality that does not have to be kept consistent across versions or deterministic.\n *\n * This can include policy for how to use this schema for \"view\" purposes, and well as how to expose editing APIs.\n * Use {@link SchemaFactory} to create the FieldSchema instances, for example {@link SchemaFactory.optional}.\n * @privateRemarks\n * Public access to the constructor is removed to prevent creating expressible but unsupported (or not stable) configurations.\n * {@link createFieldSchema} can be used internally to create instances.\n *\n * @typeParam TCustomMetadata - Custom metadata properties to associate with the field.\n * See {@link FieldSchemaMetadata.custom}.\n *\n * @sealed @public\n */\nexport class FieldSchema<\n\tout Kind extends FieldKind = FieldKind,\n\tout Types extends ImplicitAllowedTypes = ImplicitAllowedTypes,\n\tout TCustomMetadata = unknown,\n> {\n\tstatic {\n\t\tcreateFieldSchema = <\n\t\t\tKind2 extends FieldKind = FieldKind,\n\t\t\tTypes2 extends ImplicitAllowedTypes = ImplicitAllowedTypes,\n\t\t\tTCustomMetadata2 = unknown,\n\t\t>(\n\t\t\tkind: Kind2,\n\t\t\tallowedTypes: Types2,\n\t\t\tprops?: FieldProps<TCustomMetadata2>,\n\t\t) => new FieldSchema(kind, allowedTypes, props);\n\t}\n\t/**\n\t * This class is used with instanceof, and therefore should have nominal typing.\n\t * This field enforces that.\n\t */\n\tprotected _typeCheck!: MakeNominal;\n\n\tprivate readonly lazyTypes: Lazy<ReadonlySet<TreeNodeSchema>>;\n\n\t/**\n\t * What types of tree nodes are allowed in this field.\n\t * @remarks Counterpart to {@link FieldSchema.allowedTypes}, with any lazy definitions evaluated.\n\t */\n\tpublic get allowedTypeSet(): ReadonlySet<TreeNodeSchema> {\n\t\treturn this.lazyTypes.value;\n\t}\n\n\t/**\n\t * True if and only if, when constructing a node with this field, a value must be provided for it.\n\t */\n\tpublic readonly requiresValue: boolean;\n\n\t/**\n\t * {@inheritDoc FieldProps.metadata}\n\t */\n\tpublic get metadata(): FieldSchemaMetadata<TCustomMetadata> | undefined {\n\t\treturn this.props?.metadata;\n\t}\n\n\tprivate constructor(\n\t\t/**\n\t\t * The {@link https://en.wikipedia.org/wiki/Kind_(type_theory) | kind } of this field.\n\t\t * Determines the multiplicity, viewing and editing APIs as well as the merge resolution policy.\n\t\t */\n\t\tpublic readonly kind: Kind,\n\t\t/**\n\t\t * What types of tree nodes are allowed in this field.\n\t\t */\n\t\tpublic readonly allowedTypes: Types,\n\t\t/**\n\t\t * Optional properties associated with the field.\n\t\t */\n\t\tpublic readonly props?: FieldProps<TCustomMetadata>,\n\t) {\n\t\tthis.lazyTypes = new Lazy(() => normalizeAllowedTypes(this.allowedTypes));\n\t\t// TODO: optional fields should (by default) get a default provider that returns undefined, removing the need to special case them here:\n\t\tthis.requiresValue =\n\t\t\tthis.props?.defaultProvider === undefined && this.kind !== FieldKind.Optional;\n\t}\n}\n\n/**\n * Normalizes a {@link ImplicitFieldSchema} to a {@link FieldSchema}.\n */\nexport function normalizeFieldSchema(schema: ImplicitFieldSchema): FieldSchema {\n\treturn schema instanceof FieldSchema\n\t\t? schema\n\t\t: createFieldSchema(FieldKind.Required, schema);\n}\n/**\n * Normalizes a {@link ImplicitAllowedTypes} to a set of {@link TreeNodeSchema}s, by eagerly evaluating any\n * lazy schema declarations.\n *\n * @remarks Note: this must only be called after all required schemas have been declared, otherwise evaluation of\n * recursive schemas may fail.\n */\nexport function normalizeAllowedTypes(\n\ttypes: ImplicitAllowedTypes,\n): ReadonlySet<TreeNodeSchema> {\n\tconst normalized = new Set<TreeNodeSchema>();\n\tif (isReadonlyArray(types)) {\n\t\tfor (const lazyType of types) {\n\t\t\tnormalized.add(evaluateLazySchema(lazyType));\n\t\t}\n\t} else {\n\t\tnormalized.add(evaluateLazySchema(types));\n\t}\n\treturn normalized;\n}\n\n/**\n * Returns true if the given {@link ImplicitFieldSchema} are equivalent, otherwise false.\n * @remarks Two ImplicitFieldSchema are considered equivalent if all of the following are true:\n * 1. They have the same {@link FieldKind | kinds}.\n * 2. They have {@link areFieldPropsEqual | equivalent FieldProps}.\n * 3. They have the same exact set of allowed types. The allowed types must be (respectively) reference equal.\n *\n * For example, comparing an ImplicitFieldSchema that is a {@link TreeNodeSchema} to an ImplicitFieldSchema that is a {@link FieldSchema}\n * will return true if they are the same kind, the FieldSchema has exactly one allowed type (the TreeNodeSchema), and they have equivalent FieldProps.\n */\nexport function areImplicitFieldSchemaEqual(\n\ta: ImplicitFieldSchema,\n\tb: ImplicitFieldSchema,\n): boolean {\n\treturn areFieldSchemaEqual(normalizeFieldSchema(a), normalizeFieldSchema(b));\n}\n\n/**\n * Returns true if the given {@link FieldSchema} are equivalent, otherwise false.\n * @remarks Two FieldSchema are considered equivalent if all of the following are true:\n * 1. They have the same {@link FieldKind | kinds}.\n * 2. They have {@link areFieldPropsEqual | equivalent FieldProps}.\n * 3. They have the same exact set of allowed types. The allowed types must be reference equal.\n */\nexport function areFieldSchemaEqual(a: FieldSchema, b: FieldSchema): boolean {\n\tif (a === b) {\n\t\treturn true;\n\t}\n\n\tif (a.kind !== b.kind) {\n\t\treturn false;\n\t}\n\n\tif (!areFieldPropsEqual(a.props, b.props)) {\n\t\treturn false;\n\t}\n\n\treturn compareSets({ a: a.allowedTypeSet, b: b.allowedTypeSet });\n}\n\n/**\n * Returns true if the given {@link FieldProps} are equivalent, otherwise false.\n * @remarks FieldProps are considered equivalent if their keys and default providers are reference equal, and their metadata are {@link areMetadataEqual | equivalent}.\n */\nfunction areFieldPropsEqual(a: FieldProps | undefined, b: FieldProps | undefined): boolean {\n\t// If any new fields are added to FieldProps, this check will stop compiling as a reminder that this function needs to be updated.\n\ttype _keys = requireTrue<areOnlyKeys<FieldProps, \"key\" | \"defaultProvider\" | \"metadata\">>;\n\n\tif (a === b) {\n\t\treturn true;\n\t}\n\n\tif (a?.key !== b?.key || a?.defaultProvider !== b?.defaultProvider) {\n\t\treturn false;\n\t}\n\n\tif (!areMetadataEqual(a?.metadata, b?.metadata)) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\n/**\n * Returns true if the given {@link FieldSchemaMetadata} are equivalent, otherwise false.\n * @remarks FieldSchemaMetadata are considered equivalent if their custom data and descriptions are (respectively) reference equal.\n */\nfunction areMetadataEqual(\n\ta: FieldSchemaMetadata | undefined,\n\tb: FieldSchemaMetadata | undefined,\n): boolean {\n\t// If any new fields are added to FieldSchemaMetadata, this check will stop compiling as a reminder that this function needs to be updated.\n\ttype _keys = requireTrue<areOnlyKeys<FieldSchemaMetadata, \"custom\" | \"description\">>;\n\n\tif (a === b) {\n\t\treturn true;\n\t}\n\n\treturn a?.custom === b?.custom && a?.description === b?.description;\n}\n\nfunction evaluateLazySchema(value: LazyItem<TreeNodeSchema>): TreeNodeSchema {\n\tconst evaluatedSchema = isLazy(value) ? value() : value;\n\tif (evaluatedSchema === undefined) {\n\t\tthrow new UsageError(\n\t\t\t`Encountered an undefined schema. This could indicate that some referenced schema has not yet been instantiated.`,\n\t\t);\n\t}\n\treturn evaluatedSchema;\n}\n\n/**\n * Types allowed in a field.\n * @remarks\n * Implicitly treats a single type as an array of one type.\n * @public\n */\nexport type ImplicitAllowedTypes = AllowedTypes | TreeNodeSchema;\n\n/**\n * Schema for a field of a tree node.\n * @remarks\n * Implicitly treats {@link ImplicitAllowedTypes} as a Required field of that type.\n * @public\n */\nexport type ImplicitFieldSchema = FieldSchema | ImplicitAllowedTypes;\n\n/**\n * Converts an `ImplicitFieldSchema` to a property type suitable for reading a field with this that schema.\n *\n * @typeparam TSchema - When non-exact schema are provided this errors on the side of returning too general of a type (a conservative union of all possibilities).\n * This is ideal for \"output APIs\" - i.e. it converts the schema type to the runtime type that a user will _read_ from the tree.\n * Examples of such \"non-exact\" schema include `ImplicitFieldSchema`, `ImplicitAllowedTypes`, and TypeScript unions of schema types.\n * @public\n */\nexport type TreeFieldFromImplicitField<TSchema extends ImplicitFieldSchema = FieldSchema> =\n\tTSchema extends FieldSchema<infer Kind, infer Types>\n\t\t? ApplyKind<TreeNodeFromImplicitAllowedTypes<Types>, Kind>\n\t\t: TSchema extends ImplicitAllowedTypes\n\t\t\t? TreeNodeFromImplicitAllowedTypes<TSchema>\n\t\t\t: TreeNode | TreeLeafValue | undefined;\n\n/**\n * Type of content that can be inserted into the tree for a field of the given schema.\n *\n * @see {@link Input}\n *\n * @typeparam TSchemaInput - Schema to process.\n * @typeparam TSchema - Do not specify: default value used as implementation detail.\n * @public\n */\nexport type InsertableTreeFieldFromImplicitField<\n\tTSchemaInput extends ImplicitFieldSchema,\n\tTSchema = UnionToIntersection<TSchemaInput>,\n> = [TSchema] extends [FieldSchema<infer Kind, infer Types>]\n\t? ApplyKindInput<InsertableTreeNodeFromImplicitAllowedTypes<Types>, Kind, true>\n\t: [TSchema] extends [ImplicitAllowedTypes]\n\t\t? InsertableTreeNodeFromImplicitAllowedTypes<TSchema>\n\t\t: never;\n\n/**\n * {@inheritdoc (UnsafeUnknownSchema:type)}\n * @alpha\n */\nexport const UnsafeUnknownSchema: unique symbol = Symbol(\"UnsafeUnknownSchema\");\n\n/**\n * A special type which can be provided to some APIs as the schema type parameter when schema cannot easily be provided at compile time and an unsafe (instead of disabled) editing API is desired.\n * @remarks\n * When used, this means the TypeScript typing should err on the side of completeness (allow all inputs that could be valid).\n * This introduces the risk that out-of-schema data could be allowed at compile time, and only error at runtime.\n *\n * @privateRemarks\n * This only applies to APIs which input data which is expected to be in schema, since APIs outputting have easy mechanisms to do so in a type safe way even when the schema is unknown.\n * In most cases that amounts to returning `TreeNode | TreeLeafValue`.\n *\n * This can be contrasted with the default behavior of TypeScript, which is to require the intersection of the possible types for input APIs,\n * which for unknown schema defining input trees results in the `never` type.\n *\n * Any APIs which use this must produce UsageErrors when out of schema data is encountered, and never produce unrecoverable errors,\n * or silently accept invalid data.\n * This is currently only type exported from the package: the symbol is just used as a way to get a named type.\n * @alpha\n */\nexport type UnsafeUnknownSchema = typeof UnsafeUnknownSchema;\n\n/**\n * Content which could be inserted into a tree.\n *\n * @see {@link Input}\n * @remarks\n * Extended version of {@link InsertableTreeNodeFromImplicitAllowedTypes} that also allows {@link (UnsafeUnknownSchema:type)}.\n * @alpha\n */\nexport type Insertable<TSchema extends ImplicitAllowedTypes | UnsafeUnknownSchema> =\n\tTSchema extends ImplicitAllowedTypes\n\t\t? InsertableTreeNodeFromImplicitAllowedTypes<TSchema>\n\t\t: InsertableContent;\n\n/**\n * Content which could be inserted into a field within a tree.\n *\n * @see {@link Input}\n * @remarks\n * Extended version of {@link InsertableTreeFieldFromImplicitField} that also allows {@link (UnsafeUnknownSchema:type)}.\n * @alpha\n */\nexport type InsertableField<TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema> = [\n\tTSchema,\n] extends [ImplicitFieldSchema]\n\t? InsertableTreeFieldFromImplicitField<TSchema>\n\t: [TSchema] extends [UnsafeUnknownSchema]\n\t\t? InsertableContent | undefined\n\t\t: never;\n\n/**\n * Content which could be read from a field within a tree.\n *\n * @remarks\n * Extended version of {@link TreeFieldFromImplicitField} that also allows {@link (UnsafeUnknownSchema:type)}.\n * Since reading from fields with non-exact schema is still safe, this is only useful (compared to {@link TreeFieldFromImplicitField}) when the schema is also used as input and thus allows {@link (UnsafeUnknownSchema:type)}\n * for use\n * @system @alpha\n */\nexport type ReadableField<TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema> =\n\tTreeFieldFromImplicitField<ReadSchema<TSchema>>;\n\n/**\n * Adapter to remove {@link (UnsafeUnknownSchema:type)} from a schema type so it can be used with types for generating APIs for reading data.\n *\n * @remarks\n * Since reading with non-exact schema is still safe, this is mainly useful when the schema is also used as input and thus allows {@link (UnsafeUnknownSchema:type)}.\n * @system @alpha\n */\nexport type ReadSchema<TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema> = [\n\tTSchema,\n] extends [ImplicitFieldSchema]\n\t? TSchema\n\t: ImplicitFieldSchema;\n\n/**\n * Suitable for output.\n * For input must error on side of excluding undefined instead.\n * @system @public\n */\nexport type ApplyKind<T, Kind extends FieldKind> = {\n\t[FieldKind.Required]: T;\n\t[FieldKind.Optional]: T | undefined;\n\t[FieldKind.Identifier]: T;\n}[Kind];\n\n/**\n * Suitable for input.\n *\n * @see {@link Input}\n * @system @public\n */\nexport type ApplyKindInput<T, Kind extends FieldKind, DefaultsAreOptional extends boolean> = [\n\tKind,\n] extends [FieldKind.Required]\n\t? T\n\t: [Kind] extends [FieldKind.Optional]\n\t\t? T | undefined\n\t\t: [Kind] extends [FieldKind.Identifier]\n\t\t\t? DefaultsAreOptional extends true\n\t\t\t\t? T | undefined\n\t\t\t\t: T\n\t\t\t: never;\n\n/**\n * Type of tree node for a field of the given schema.\n * @public\n */\nexport type TreeNodeFromImplicitAllowedTypes<\n\tTSchema extends ImplicitAllowedTypes = TreeNodeSchema,\n> = TSchema extends TreeNodeSchema\n\t? NodeFromSchema<TSchema>\n\t: TSchema extends AllowedTypes\n\t\t? NodeFromSchema<FlexListToUnion<TSchema>>\n\t\t: unknown;\n\n/**\n * This type exists only to be linked from documentation to provide a single linkable place to document some details of\n * \"Input\" types and how they handle schema.\n *\n * When a schema is used to describe data which is an input into an API, the API is [contravariant](https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)) over the schema.\n * (See also, [TypeScript Variance Annotations](https://www.typescriptlang.org/docs/handbook/2/generics.html#variance-annotations)).\n *\n * Since these schema are expressed using TypeScript types, it is possible for the user of the API to provide non-exact values of these types which has implications that depended on the variance.\n *\n * Consider a field with schema type of `A | B` (where A and B are types of schema).\n *\n * - Reading the field behaves covariantly so {@link NodeFromSchema} of `<A | B>` is the same as `NodeFromSchema<A> | NodeFromSchema<B>`, indicating that either type of node can be read from the field.\n * - Writing to the field behaves contravariantly. Since it is unknown if the node actually has a schema `A` or a schema `B`, the only legal values (known to be in schema regardless of which schema the underlying node has) are values which are legal for both `A & B`.\n *\n * Note that this is distinct from the case where the schema is `[A, B]`.\n * In this case it is known that the field allows both A and B (the field can be set to an A or a B value).\n * When `A | B` is used, the field might allow\n * A but not B (so assigning a B value would be out of schema),\n * B but not A (so assigning an A value would be out of schema)\n * or both A and B.\n *\n * This gets more extreme when given completely unspecified schema.\n * For example if a field is just provided {@link ImplicitFieldSchema}, nothing is known about the content of the field.\n * This means that reading the field (via {@link TreeFieldFromImplicitField}) can give any valid tree field content,\n * but there are no safe values which could be written to the field (since it is unknown what values would be out of schema) so {@link InsertableTreeFieldFromImplicitField} gives `never`.\n *\n * To implement this variance correctly, the computation of types for input and output have to use separate utilities\n * which take very different approaches when encountering non-exact schema like unions or `ImplicitFieldSchema`.\n * The utilities which behave contravariantly (as required to handle input correctly) link this documentation to indicate that this is how they behave.\n *\n * In addition to behaving contravariantly, these input type computation utilities often have further limitations.\n * This is due to TypeScript making it difficult to implement this contravariance exactly.\n * When faced with these implementation limitations these contravariant type computation utilities error on the side of producing overly strict requirements.\n * For example in the above case of `A | B`, the utilities might compute an allowed insertable type as `never` even if there happens to be a common value accepted by both `A` and `B`.\n * Future versions of the API can relax these requirements as the type computations are made more accurate.\n *\n * For a more concrete example: if {@link InsertableTreeFieldFromImplicitField} produced `never` for a schema `A | OptionalField<A>`,\n * a future version could instead return a more flexible but still safe type, like `A`.\n *\n * More generally: try to avoid providing non-exact schema, especially for the fields of other schema.\n * While these APIs attempt to handle such cases correctly, there are limitations and known bugs in this handling.\n * Code using non-exact schema is much more likely to have its compilation break due to updates of this package or even TypeScript,\n * and thus compilation breaks due to edge cases of non-exact schema handling, especially with recursive schema, are not considered breaking changes.\n * This may change as the API become more stable.\n *\n * @privateRemarks\n * There likely is a better way to share this documentation, but none was found at the time of writing.\n *\n * TODO: Once {@link InsertableField} is public, consider using it in the examples above.\n * @system @public\n */\nexport type Input<T extends never> = T;\n\n/**\n * Type of content that can be inserted into the tree for a node of the given schema.\n *\n * @see {@link Input}\n *\n * @typeparam TSchema - Schema to process.\n *\n * @privateRemarks\n * This is a bit overly conservative, since cases like `A | [A]` give never and could give `A`.\n * @public\n */\nexport type InsertableTreeNodeFromImplicitAllowedTypes<TSchema extends ImplicitAllowedTypes> =\n\t[TSchema] extends [TreeNodeSchema]\n\t\t? InsertableTypedNode<TSchema>\n\t\t: [TSchema] extends [AllowedTypes]\n\t\t\t? InsertableTreeNodeFromAllowedTypes<TSchema>\n\t\t\t: never;\n\n/**\n * Type of content that can be inserted into the tree for a node of the given schema.\n *\n * @see {@link Input}\n *\n * @typeparam TList - AllowedTypes to process\n * @system @public\n */\nexport type InsertableTreeNodeFromAllowedTypes<TList extends AllowedTypes> =\n\tTList extends readonly [\n\t\tLazyItem<infer TSchema extends TreeNodeSchema>,\n\t\t...infer Rest extends AllowedTypes,\n\t]\n\t\t? InsertableTypedNode<TSchema> | InsertableTreeNodeFromAllowedTypes<Rest>\n\t\t: never;\n\n/**\n * Takes in `TreeNodeSchema[]` and returns a TypedNode union.\n * @public\n */\nexport type NodeFromSchema<T extends TreeNodeSchema> = T extends TreeNodeSchema<\n\tstring,\n\tNodeKind,\n\tinfer TNode\n>\n\t? TNode\n\t: never;\n\n/**\n * Data which can be used as a node to be inserted.\n * Either an unhydrated node, or content to build a new node.\n *\n * @see {@link Input}\n *\n * @typeparam TSchemaInput - Schema to process.\n * @typeparam T - Do not specify: default value used as implementation detail.\n * @privateRemarks\n * This can't really be fully correct, since TreeNodeSchema's TNode is generally use covariantly but this code uses it contravariantly.\n * That makes this TreeNodeSchema actually invariant with respect to TNode, but doing that would break all `extends TreeNodeSchema` clauses.\n * As is, this works correctly in most realistic use-cases.\n *\n * One special case this makes is if the result of NodeFromSchema contains TreeNode, this must be an under constrained schema, so the result is set to never.\n * Note that applying UnionToIntersection on the result of NodeFromSchema<T> does not work since it breaks booleans.\n *\n * @public\n */\nexport type InsertableTypedNode<\n\tTSchema extends TreeNodeSchema,\n\tT = UnionToIntersection<TSchema>,\n> =\n\t| (T extends TreeNodeSchema<string, NodeKind, TreeNode | TreeLeafValue, never, true>\n\t\t\t? NodeBuilderData<T>\n\t\t\t: never)\n\t| (T extends TreeNodeSchema\n\t\t\t? Unhydrated<TreeNode extends NodeFromSchema<T> ? never : NodeFromSchema<T>>\n\t\t\t: never);\n\n/**\n * Given a node's schema, return the corresponding object from which the node could be built.\n * @privateRemarks\n * This uses TreeNodeSchemaCore, and thus depends on TreeNodeSchemaCore.createFromInsertable for the typing.\n * This works almost the same as using TreeNodeSchema,\n * except that the more complex typing in TreeNodeSchema case breaks for non-class schema and leaks in `undefined` from optional crete parameters.\n * @system @public\n */\nexport type NodeBuilderData<T extends TreeNodeSchemaCore<string, NodeKind, boolean>> =\n\tT extends TreeNodeSchemaCore<string, NodeKind, boolean, unknown, infer TBuild>\n\t\t? TBuild\n\t\t: never;\n\n/**\n * Value that may be stored as a leaf node.\n * @remarks\n * Some limitations apply, see the documentation for {@link SchemaFactory.number} and {@link SchemaFactory.string} for those restrictions.\n * @public\n */\n// eslint-disable-next-line @rushstack/no-new-null\nexport type TreeLeafValue = number | string | boolean | IFluidHandle | null;\n"]}
@@ -81,6 +81,7 @@ export declare function addDefaultsToMapTree(mapTree: ExclusiveMapTree, allowedT
81
81
  * Content which can be used to build a node.
82
82
  * @remarks
83
83
  * Can contain unhydrated nodes, but can not be an unhydrated node at the root.
84
+ * @system @alpha
84
85
  */
85
86
  export type FactoryContent = IFluidHandle | string | number | boolean | null | Iterable<readonly [string, InsertableContent]> | readonly InsertableContent[] | FactoryContentObject;
86
87
  /**
@@ -89,13 +90,14 @@ export type FactoryContent = IFluidHandle | string | number | boolean | null | I
89
90
  * Can contain unhydrated nodes, but can not be an unhydrated node at the root.
90
91
  *
91
92
  * Supports object and map nodes.
93
+ * @system @alpha
92
94
  */
93
- type FactoryContentObject = {
95
+ export type FactoryContentObject = {
94
96
  readonly [P in string]?: InsertableContent;
95
97
  };
96
98
  /**
97
99
  * Content which can be inserted into a tree.
100
+ * @system @alpha
98
101
  */
99
102
  export type InsertableContent = Unhydrated<TreeNode> | FactoryContent;
100
- export {};
101
103
  //# sourceMappingURL=toMapTree.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"toMapTree.d.ts","sourceRoot":"","sources":["../../src/simple-tree/toMapTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAMN,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,+BAA+B,CAAC;AAIvC,OAAO,EAEN,KAAK,oBAAoB,EAKzB,KAAK,mBAAmB,EAIxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAMN,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,KAAK,UAAU,EAEf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,sBAAsB,EAAkB,MAAM,+BAA+B,CAAC;AAEvF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAEpE;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,iBAAiB,EACvB,YAAY,EAAE,oBAAoB,EAClC,OAAO,CAAC,EAAE,cAAc,EACxB,sBAAsB,CAAC,EAAE,eAAe,GACtC,gBAAgB,CAAC;AACpB,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,iBAAiB,GAAG,SAAS,EACnC,YAAY,EAAE,mBAAmB,EACjC,OAAO,CAAC,EAAE,cAAc,EACxB,sBAAsB,CAAC,EAAE,eAAe,GACtC,gBAAgB,GAAG,SAAS,CAAC;AA0FhC;;GAEG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,sBAAsB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