@fluidframework/tree 2.5.0-302463 → 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 (365) hide show
  1. package/.vscode/settings.json +1 -0
  2. package/CHANGELOG.md +371 -0
  3. package/api-report/tree.alpha.api.md +151 -57
  4. package/api-report/tree.beta.api.md +29 -25
  5. package/api-report/tree.legacy.alpha.api.md +28 -24
  6. package/api-report/tree.legacy.public.api.md +28 -24
  7. package/api-report/tree.public.api.md +28 -24
  8. package/dist/alpha.d.ts +15 -0
  9. package/dist/codec/codec.d.ts +24 -0
  10. package/dist/codec/codec.d.ts.map +1 -1
  11. package/dist/codec/codec.js +26 -1
  12. package/dist/codec/codec.js.map +1 -1
  13. package/dist/codec/index.d.ts +1 -1
  14. package/dist/codec/index.d.ts.map +1 -1
  15. package/dist/codec/index.js +2 -1
  16. package/dist/codec/index.js.map +1 -1
  17. package/dist/core/rebase/index.d.ts +2 -2
  18. package/dist/core/rebase/index.d.ts.map +1 -1
  19. package/dist/core/rebase/index.js +2 -2
  20. package/dist/core/rebase/index.js.map +1 -1
  21. package/dist/core/rebase/types.d.ts +0 -4
  22. package/dist/core/rebase/types.d.ts.map +1 -1
  23. package/dist/core/rebase/types.js +1 -7
  24. package/dist/core/rebase/types.js.map +1 -1
  25. package/dist/core/rebase/utils.d.ts +1 -0
  26. package/dist/core/rebase/utils.d.ts.map +1 -1
  27. package/dist/core/rebase/utils.js +29 -4
  28. package/dist/core/rebase/utils.js.map +1 -1
  29. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts +8 -1
  30. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  31. package/dist/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  32. package/dist/feature-libraries/flex-tree/lazyNode.d.ts +2 -1
  33. package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  34. package/dist/feature-libraries/flex-tree/lazyNode.js +3 -0
  35. package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  36. package/dist/index.d.ts +3 -3
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +12 -6
  39. package/dist/index.js.map +1 -1
  40. package/dist/packageVersion.d.ts +1 -1
  41. package/dist/packageVersion.d.ts.map +1 -1
  42. package/dist/packageVersion.js +1 -1
  43. package/dist/packageVersion.js.map +1 -1
  44. package/dist/shared-tree/independentView.d.ts +57 -0
  45. package/dist/shared-tree/independentView.d.ts.map +1 -0
  46. package/dist/shared-tree/independentView.js +89 -0
  47. package/dist/shared-tree/independentView.js.map +1 -0
  48. package/dist/shared-tree/index.d.ts +3 -1
  49. package/dist/shared-tree/index.d.ts.map +1 -1
  50. package/dist/shared-tree/index.js +6 -1
  51. package/dist/shared-tree/index.js.map +1 -1
  52. package/dist/shared-tree/schematizingTreeView.d.ts +12 -8
  53. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  54. package/dist/shared-tree/schematizingTreeView.js +28 -0
  55. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  56. package/dist/shared-tree/sharedTree.d.ts +10 -7
  57. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  58. package/dist/shared-tree/sharedTree.js.map +1 -1
  59. package/dist/shared-tree/treeApiAlpha.d.ts +147 -0
  60. package/dist/shared-tree/treeApiAlpha.d.ts.map +1 -0
  61. package/dist/shared-tree/treeApiAlpha.js +122 -0
  62. package/dist/shared-tree/treeApiAlpha.js.map +1 -0
  63. package/dist/shared-tree/treeCheckout.d.ts +12 -7
  64. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  65. package/dist/shared-tree/treeCheckout.js +9 -4
  66. package/dist/shared-tree/treeCheckout.js.map +1 -1
  67. package/dist/shared-tree-core/editManager.d.ts +13 -6
  68. package/dist/shared-tree-core/editManager.d.ts.map +1 -1
  69. package/dist/shared-tree-core/editManager.js +70 -28
  70. package/dist/shared-tree-core/editManager.js.map +1 -1
  71. package/dist/shared-tree-core/sharedTreeCore.d.ts +1 -0
  72. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  73. package/dist/shared-tree-core/sharedTreeCore.js +28 -3
  74. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  75. package/dist/simple-tree/api/conciseTree.d.ts +2 -1
  76. package/dist/simple-tree/api/conciseTree.d.ts.map +1 -1
  77. package/dist/simple-tree/api/conciseTree.js.map +1 -1
  78. package/dist/simple-tree/api/create.d.ts +5 -23
  79. package/dist/simple-tree/api/create.d.ts.map +1 -1
  80. package/dist/simple-tree/api/create.js +4 -19
  81. package/dist/simple-tree/api/create.js.map +1 -1
  82. package/dist/simple-tree/api/customTree.d.ts +1 -0
  83. package/dist/simple-tree/api/customTree.d.ts.map +1 -1
  84. package/dist/simple-tree/api/customTree.js.map +1 -1
  85. package/dist/simple-tree/api/index.d.ts +5 -5
  86. package/dist/simple-tree/api/index.d.ts.map +1 -1
  87. package/dist/simple-tree/api/index.js +10 -1
  88. package/dist/simple-tree/api/index.js.map +1 -1
  89. package/dist/simple-tree/api/schemaCreationUtilities.d.ts +6 -16
  90. package/dist/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
  91. package/dist/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  92. package/dist/simple-tree/api/schemaFactory.d.ts +11 -11
  93. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  94. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  95. package/dist/simple-tree/api/storedSchema.js +2 -2
  96. package/dist/simple-tree/api/storedSchema.js.map +1 -1
  97. package/dist/simple-tree/api/testRecursiveDomain.d.ts +5 -5
  98. package/dist/simple-tree/api/tree.d.ts +115 -7
  99. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  100. package/dist/simple-tree/api/tree.js +12 -4
  101. package/dist/simple-tree/api/tree.js.map +1 -1
  102. package/dist/simple-tree/api/treeApiBeta.d.ts +8 -5
  103. package/dist/simple-tree/api/treeApiBeta.d.ts.map +1 -1
  104. package/dist/simple-tree/api/treeApiBeta.js +3 -15
  105. package/dist/simple-tree/api/treeApiBeta.js.map +1 -1
  106. package/dist/simple-tree/api/typesUnsafe.d.ts +1 -1
  107. package/dist/simple-tree/api/typesUnsafe.d.ts.map +1 -1
  108. package/dist/simple-tree/api/typesUnsafe.js.map +1 -1
  109. package/dist/simple-tree/api/verboseTree.d.ts +3 -0
  110. package/dist/simple-tree/api/verboseTree.d.ts.map +1 -1
  111. package/dist/simple-tree/api/verboseTree.js.map +1 -1
  112. package/dist/simple-tree/arrayNode.d.ts +1 -1
  113. package/dist/simple-tree/arrayNode.d.ts.map +1 -1
  114. package/dist/simple-tree/arrayNode.js +1 -1
  115. package/dist/simple-tree/arrayNode.js.map +1 -1
  116. package/dist/simple-tree/core/getOrCreateNode.js.map +1 -1
  117. package/dist/simple-tree/core/treeNodeSchema.d.ts +45 -9
  118. package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  119. package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
  120. package/dist/simple-tree/core/unhydratedFlexTree.d.ts +2 -1
  121. package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  122. package/dist/simple-tree/core/unhydratedFlexTree.js +3 -0
  123. package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  124. package/dist/simple-tree/core/withType.d.ts +1 -2
  125. package/dist/simple-tree/core/withType.d.ts.map +1 -1
  126. package/dist/simple-tree/core/withType.js.map +1 -1
  127. package/dist/simple-tree/createContext.js +2 -2
  128. package/dist/simple-tree/createContext.js.map +1 -1
  129. package/dist/simple-tree/index.d.ts +4 -4
  130. package/dist/simple-tree/index.d.ts.map +1 -1
  131. package/dist/simple-tree/index.js +15 -4
  132. package/dist/simple-tree/index.js.map +1 -1
  133. package/dist/simple-tree/leafNodeSchema.d.ts +6 -5
  134. package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
  135. package/dist/simple-tree/leafNodeSchema.js +3 -0
  136. package/dist/simple-tree/leafNodeSchema.js.map +1 -1
  137. package/dist/simple-tree/mapNode.d.ts +1 -1
  138. package/dist/simple-tree/mapNode.d.ts.map +1 -1
  139. package/dist/simple-tree/mapNode.js +3 -0
  140. package/dist/simple-tree/mapNode.js.map +1 -1
  141. package/dist/simple-tree/schemaTypes.d.ts +45 -7
  142. package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
  143. package/dist/simple-tree/schemaTypes.js +61 -1
  144. package/dist/simple-tree/schemaTypes.js.map +1 -1
  145. package/dist/simple-tree/{toFlexSchema.d.ts → toStoredSchema.d.ts} +1 -1
  146. package/dist/simple-tree/toStoredSchema.d.ts.map +1 -0
  147. package/dist/simple-tree/{toFlexSchema.js → toStoredSchema.js} +1 -1
  148. package/dist/simple-tree/toStoredSchema.js.map +1 -0
  149. package/dist/simple-tree/treeNodeValid.d.ts +5 -1
  150. package/dist/simple-tree/treeNodeValid.d.ts.map +1 -1
  151. package/dist/simple-tree/treeNodeValid.js +7 -1
  152. package/dist/simple-tree/treeNodeValid.js.map +1 -1
  153. package/dist/util/index.d.ts +1 -1
  154. package/dist/util/index.d.ts.map +1 -1
  155. package/dist/util/index.js.map +1 -1
  156. package/dist/util/typeCheck.d.ts +9 -0
  157. package/dist/util/typeCheck.d.ts.map +1 -1
  158. package/dist/util/typeCheck.js.map +1 -1
  159. package/dist/util/utils.d.ts +7 -3
  160. package/dist/util/utils.d.ts.map +1 -1
  161. package/dist/util/utils.js +13 -3
  162. package/dist/util/utils.js.map +1 -1
  163. package/lib/alpha.d.ts +15 -0
  164. package/lib/codec/codec.d.ts +24 -0
  165. package/lib/codec/codec.d.ts.map +1 -1
  166. package/lib/codec/codec.js +25 -0
  167. package/lib/codec/codec.js.map +1 -1
  168. package/lib/codec/index.d.ts +1 -1
  169. package/lib/codec/index.d.ts.map +1 -1
  170. package/lib/codec/index.js +1 -1
  171. package/lib/codec/index.js.map +1 -1
  172. package/lib/core/rebase/index.d.ts +2 -2
  173. package/lib/core/rebase/index.d.ts.map +1 -1
  174. package/lib/core/rebase/index.js +2 -2
  175. package/lib/core/rebase/index.js.map +1 -1
  176. package/lib/core/rebase/types.d.ts +0 -4
  177. package/lib/core/rebase/types.d.ts.map +1 -1
  178. package/lib/core/rebase/types.js +0 -5
  179. package/lib/core/rebase/types.js.map +1 -1
  180. package/lib/core/rebase/utils.d.ts +1 -0
  181. package/lib/core/rebase/utils.d.ts.map +1 -1
  182. package/lib/core/rebase/utils.js +27 -3
  183. package/lib/core/rebase/utils.js.map +1 -1
  184. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts +8 -1
  185. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  186. package/lib/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  187. package/lib/feature-libraries/flex-tree/lazyNode.d.ts +2 -1
  188. package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  189. package/lib/feature-libraries/flex-tree/lazyNode.js +3 -0
  190. package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  191. package/lib/index.d.ts +3 -3
  192. package/lib/index.d.ts.map +1 -1
  193. package/lib/index.js +3 -2
  194. package/lib/index.js.map +1 -1
  195. package/lib/packageVersion.d.ts +1 -1
  196. package/lib/packageVersion.d.ts.map +1 -1
  197. package/lib/packageVersion.js +1 -1
  198. package/lib/packageVersion.js.map +1 -1
  199. package/lib/shared-tree/independentView.d.ts +57 -0
  200. package/lib/shared-tree/independentView.d.ts.map +1 -0
  201. package/lib/shared-tree/independentView.js +84 -0
  202. package/lib/shared-tree/independentView.js.map +1 -0
  203. package/lib/shared-tree/index.d.ts +3 -1
  204. package/lib/shared-tree/index.d.ts.map +1 -1
  205. package/lib/shared-tree/index.js +2 -0
  206. package/lib/shared-tree/index.js.map +1 -1
  207. package/lib/shared-tree/schematizingTreeView.d.ts +12 -8
  208. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  209. package/lib/shared-tree/schematizingTreeView.js +29 -1
  210. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  211. package/lib/shared-tree/sharedTree.d.ts +10 -7
  212. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  213. package/lib/shared-tree/sharedTree.js.map +1 -1
  214. package/lib/shared-tree/treeApiAlpha.d.ts +147 -0
  215. package/lib/shared-tree/treeApiAlpha.d.ts.map +1 -0
  216. package/lib/shared-tree/treeApiAlpha.js +119 -0
  217. package/lib/shared-tree/treeApiAlpha.js.map +1 -0
  218. package/lib/shared-tree/treeCheckout.d.ts +12 -7
  219. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  220. package/lib/shared-tree/treeCheckout.js +9 -4
  221. package/lib/shared-tree/treeCheckout.js.map +1 -1
  222. package/lib/shared-tree-core/editManager.d.ts +13 -6
  223. package/lib/shared-tree-core/editManager.d.ts.map +1 -1
  224. package/lib/shared-tree-core/editManager.js +70 -28
  225. package/lib/shared-tree-core/editManager.js.map +1 -1
  226. package/lib/shared-tree-core/sharedTreeCore.d.ts +1 -0
  227. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  228. package/lib/shared-tree-core/sharedTreeCore.js +29 -4
  229. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  230. package/lib/simple-tree/api/conciseTree.d.ts +2 -1
  231. package/lib/simple-tree/api/conciseTree.d.ts.map +1 -1
  232. package/lib/simple-tree/api/conciseTree.js.map +1 -1
  233. package/lib/simple-tree/api/create.d.ts +5 -23
  234. package/lib/simple-tree/api/create.d.ts.map +1 -1
  235. package/lib/simple-tree/api/create.js +2 -16
  236. package/lib/simple-tree/api/create.js.map +1 -1
  237. package/lib/simple-tree/api/customTree.d.ts +1 -0
  238. package/lib/simple-tree/api/customTree.d.ts.map +1 -1
  239. package/lib/simple-tree/api/customTree.js.map +1 -1
  240. package/lib/simple-tree/api/index.d.ts +5 -5
  241. package/lib/simple-tree/api/index.d.ts.map +1 -1
  242. package/lib/simple-tree/api/index.js +5 -3
  243. package/lib/simple-tree/api/index.js.map +1 -1
  244. package/lib/simple-tree/api/schemaCreationUtilities.d.ts +6 -16
  245. package/lib/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
  246. package/lib/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  247. package/lib/simple-tree/api/schemaFactory.d.ts +11 -11
  248. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  249. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  250. package/lib/simple-tree/api/storedSchema.js +1 -1
  251. package/lib/simple-tree/api/storedSchema.js.map +1 -1
  252. package/lib/simple-tree/api/testRecursiveDomain.d.ts +5 -5
  253. package/lib/simple-tree/api/tree.d.ts +115 -7
  254. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  255. package/lib/simple-tree/api/tree.js +9 -2
  256. package/lib/simple-tree/api/tree.js.map +1 -1
  257. package/lib/simple-tree/api/treeApiBeta.d.ts +8 -5
  258. package/lib/simple-tree/api/treeApiBeta.d.ts.map +1 -1
  259. package/lib/simple-tree/api/treeApiBeta.js +4 -16
  260. package/lib/simple-tree/api/treeApiBeta.js.map +1 -1
  261. package/lib/simple-tree/api/typesUnsafe.d.ts +1 -1
  262. package/lib/simple-tree/api/typesUnsafe.d.ts.map +1 -1
  263. package/lib/simple-tree/api/typesUnsafe.js.map +1 -1
  264. package/lib/simple-tree/api/verboseTree.d.ts +3 -0
  265. package/lib/simple-tree/api/verboseTree.d.ts.map +1 -1
  266. package/lib/simple-tree/api/verboseTree.js.map +1 -1
  267. package/lib/simple-tree/arrayNode.d.ts +1 -1
  268. package/lib/simple-tree/arrayNode.d.ts.map +1 -1
  269. package/lib/simple-tree/arrayNode.js +1 -1
  270. package/lib/simple-tree/arrayNode.js.map +1 -1
  271. package/lib/simple-tree/core/getOrCreateNode.js.map +1 -1
  272. package/lib/simple-tree/core/treeNodeSchema.d.ts +45 -9
  273. package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  274. package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
  275. package/lib/simple-tree/core/unhydratedFlexTree.d.ts +2 -1
  276. package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  277. package/lib/simple-tree/core/unhydratedFlexTree.js +4 -1
  278. package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  279. package/lib/simple-tree/core/withType.d.ts +1 -2
  280. package/lib/simple-tree/core/withType.d.ts.map +1 -1
  281. package/lib/simple-tree/core/withType.js.map +1 -1
  282. package/lib/simple-tree/createContext.js +1 -1
  283. package/lib/simple-tree/createContext.js.map +1 -1
  284. package/lib/simple-tree/index.d.ts +4 -4
  285. package/lib/simple-tree/index.d.ts.map +1 -1
  286. package/lib/simple-tree/index.js +4 -4
  287. package/lib/simple-tree/index.js.map +1 -1
  288. package/lib/simple-tree/leafNodeSchema.d.ts +6 -5
  289. package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
  290. package/lib/simple-tree/leafNodeSchema.js +3 -0
  291. package/lib/simple-tree/leafNodeSchema.js.map +1 -1
  292. package/lib/simple-tree/mapNode.d.ts +1 -1
  293. package/lib/simple-tree/mapNode.d.ts.map +1 -1
  294. package/lib/simple-tree/mapNode.js +3 -0
  295. package/lib/simple-tree/mapNode.js.map +1 -1
  296. package/lib/simple-tree/schemaTypes.d.ts +45 -7
  297. package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
  298. package/lib/simple-tree/schemaTypes.js +59 -1
  299. package/lib/simple-tree/schemaTypes.js.map +1 -1
  300. package/lib/simple-tree/{toFlexSchema.d.ts → toStoredSchema.d.ts} +1 -1
  301. package/lib/simple-tree/toStoredSchema.d.ts.map +1 -0
  302. package/lib/simple-tree/{toFlexSchema.js → toStoredSchema.js} +1 -1
  303. package/lib/simple-tree/toStoredSchema.js.map +1 -0
  304. package/lib/simple-tree/treeNodeValid.d.ts +5 -1
  305. package/lib/simple-tree/treeNodeValid.d.ts.map +1 -1
  306. package/lib/simple-tree/treeNodeValid.js +7 -1
  307. package/lib/simple-tree/treeNodeValid.js.map +1 -1
  308. package/lib/util/index.d.ts +1 -1
  309. package/lib/util/index.d.ts.map +1 -1
  310. package/lib/util/index.js.map +1 -1
  311. package/lib/util/typeCheck.d.ts +9 -0
  312. package/lib/util/typeCheck.d.ts.map +1 -1
  313. package/lib/util/typeCheck.js.map +1 -1
  314. package/lib/util/utils.d.ts +7 -3
  315. package/lib/util/utils.d.ts.map +1 -1
  316. package/lib/util/utils.js +13 -3
  317. package/lib/util/utils.js.map +1 -1
  318. package/package.json +30 -21
  319. package/src/codec/codec.ts +25 -0
  320. package/src/codec/index.ts +1 -0
  321. package/src/core/rebase/index.ts +1 -1
  322. package/src/core/rebase/types.ts +0 -12
  323. package/src/core/rebase/utils.ts +35 -3
  324. package/src/feature-libraries/flex-tree/flexTreeTypes.ts +9 -0
  325. package/src/feature-libraries/flex-tree/lazyNode.ts +5 -0
  326. package/src/index.ts +20 -5
  327. package/src/packageVersion.ts +1 -1
  328. package/src/shared-tree/independentView.ts +176 -0
  329. package/src/shared-tree/index.ts +9 -1
  330. package/src/shared-tree/schematizingTreeView.ts +58 -11
  331. package/src/shared-tree/sharedTree.ts +29 -11
  332. package/src/shared-tree/treeApiAlpha.ts +401 -0
  333. package/src/shared-tree/treeCheckout.ts +26 -5
  334. package/src/shared-tree-core/editManager.ts +112 -54
  335. package/src/shared-tree-core/sharedTreeCore.ts +37 -8
  336. package/src/simple-tree/api/conciseTree.ts +2 -1
  337. package/src/simple-tree/api/create.ts +21 -58
  338. package/src/simple-tree/api/customTree.ts +1 -0
  339. package/src/simple-tree/api/index.ts +13 -7
  340. package/src/simple-tree/api/schemaCreationUtilities.ts +4 -5
  341. package/src/simple-tree/api/schemaFactory.ts +24 -12
  342. package/src/simple-tree/api/storedSchema.ts +1 -1
  343. package/src/simple-tree/api/tree.ts +136 -14
  344. package/src/simple-tree/api/treeApiBeta.ts +35 -35
  345. package/src/simple-tree/api/typesUnsafe.ts +1 -2
  346. package/src/simple-tree/api/verboseTree.ts +3 -0
  347. package/src/simple-tree/arrayNode.ts +4 -3
  348. package/src/simple-tree/core/getOrCreateNode.ts +1 -1
  349. package/src/simple-tree/core/treeNodeSchema.ts +99 -31
  350. package/src/simple-tree/core/unhydratedFlexTree.ts +6 -0
  351. package/src/simple-tree/core/withType.ts +1 -9
  352. package/src/simple-tree/createContext.ts +1 -1
  353. package/src/simple-tree/index.ts +15 -1
  354. package/src/simple-tree/leafNodeSchema.ts +6 -1
  355. package/src/simple-tree/mapNode.ts +7 -1
  356. package/src/simple-tree/schemaTypes.ts +128 -14
  357. package/src/simple-tree/treeNodeValid.ts +11 -1
  358. package/src/util/index.ts +1 -0
  359. package/src/util/typeCheck.ts +13 -0
  360. package/src/util/utils.ts +20 -7
  361. package/dist/simple-tree/toFlexSchema.d.ts.map +0 -1
  362. package/dist/simple-tree/toFlexSchema.js.map +0 -1
  363. package/lib/simple-tree/toFlexSchema.d.ts.map +0 -1
  364. package/lib/simple-tree/toFlexSchema.js.map +0 -1
  365. /package/src/simple-tree/{toFlexSchema.ts → toStoredSchema.ts} +0 -0
@@ -242,7 +242,7 @@ export interface MakeNominal {
242
242
  export type MapNodeInsertableData<T extends ImplicitAllowedTypes> = Iterable<readonly [string, InsertableTreeNodeFromImplicitAllowedTypes<T>]> | RestrictiveStringRecord<InsertableTreeNodeFromImplicitAllowedTypes<T>>;
243
243
 
244
244
  // @public
245
- type NodeBuilderData<T extends TreeNodeSchema> = T extends TreeNodeSchema<string, NodeKind, TreeNode | TreeLeafValue, infer TBuild> ? TBuild : never;
245
+ type NodeBuilderData<T extends TreeNodeSchemaCore<string, NodeKind, boolean>> = T extends TreeNodeSchemaCore<string, NodeKind, boolean, unknown, infer TBuild> ? TBuild : never;
246
246
 
247
247
  // @public
248
248
  type NodeBuilderDataUnsafe<T extends Unenforced<TreeNodeSchema>> = T extends TreeNodeSchemaUnsafe<string, NodeKind, unknown, infer TBuild> ? TBuild : never;
@@ -362,24 +362,24 @@ export interface SchemaCompatibilityStatus {
362
362
  // @public @sealed
363
363
  export class SchemaFactory<out TScope extends string | undefined = string | undefined, TName extends number | string = string> {
364
364
  constructor(scope: TScope);
365
- array<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(allowedTypes: T): TreeNodeSchemaNonClass<ScopedSchemaName<TScope, `Array<${string}>`>, NodeKind.Array, TreeArrayNode<T> & WithType<ScopedSchemaName<TScope, `Array<${string}>`>, NodeKind.Array>, Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>, true, T>;
366
- array<const Name extends TName, const T extends ImplicitAllowedTypes>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Array, TreeArrayNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Array>, Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>, true, T>;
365
+ array<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(allowedTypes: T): TreeNodeSchemaNonClass<ScopedSchemaName<TScope, `Array<${string}>`>, NodeKind.Array, TreeArrayNode<T> & WithType<ScopedSchemaName<TScope, `Array<${string}>`>, NodeKind.Array>, Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>, true, T, undefined>;
366
+ array<const Name extends TName, const T extends ImplicitAllowedTypes>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Array, TreeArrayNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Array>, Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>, true, T, undefined>;
367
367
  arrayRecursive<const Name extends TName, const T extends Unenforced<ImplicitAllowedTypes>>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Array, TreeArrayNodeUnsafe<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Array, unknown>, {
368
368
  [Symbol.iterator](): Iterator<InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>>;
369
- }, false, T>;
370
- readonly boolean: TreeNodeSchema<"com.fluidframework.leaf.boolean", NodeKind.Leaf, boolean, boolean>;
371
- readonly handle: TreeNodeSchema<"com.fluidframework.leaf.handle", NodeKind.Leaf, IFluidHandle<unknown>, IFluidHandle<unknown>>;
369
+ }, false, T, undefined>;
370
+ readonly boolean: TreeNodeSchemaNonClass<"com.fluidframework.leaf.boolean", NodeKind.Leaf, boolean, boolean, true, unknown, never>;
371
+ readonly handle: TreeNodeSchemaNonClass<"com.fluidframework.leaf.handle", NodeKind.Leaf, IFluidHandle<unknown>, IFluidHandle<unknown>, true, unknown, never>;
372
372
  get identifier(): FieldSchema<FieldKind.Identifier, typeof SchemaFactory.string>;
373
- map<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(allowedTypes: T): TreeNodeSchemaNonClass<ScopedSchemaName<TScope, `Map<${string}>`>, NodeKind.Map, TreeMapNode<T> & WithType<ScopedSchemaName<TScope, `Map<${string}>`>, NodeKind.Map>, MapNodeInsertableData<T>, true, T>;
374
- map<Name extends TName, const T extends ImplicitAllowedTypes>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Map, TreeMapNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Map>, MapNodeInsertableData<T>, true, T>;
373
+ map<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(allowedTypes: T): TreeNodeSchemaNonClass<ScopedSchemaName<TScope, `Map<${string}>`>, NodeKind.Map, TreeMapNode<T> & WithType<ScopedSchemaName<TScope, `Map<${string}>`>, NodeKind.Map>, MapNodeInsertableData<T>, true, T, undefined>;
374
+ map<Name extends TName, const T extends ImplicitAllowedTypes>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Map, TreeMapNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Map>, MapNodeInsertableData<T>, true, T, undefined>;
375
375
  mapRecursive<Name extends TName, const T extends Unenforced<ImplicitAllowedTypes>>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Map, TreeMapNodeUnsafe<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Map, unknown>, {
376
376
  [Symbol.iterator](): Iterator<[
377
377
  string,
378
378
  InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>
379
379
  ]>;
380
- }, false, T>;
381
- readonly null: TreeNodeSchema<"com.fluidframework.leaf.null", NodeKind.Leaf, null, null>;
382
- readonly number: TreeNodeSchema<"com.fluidframework.leaf.number", NodeKind.Leaf, number, number>;
380
+ }, false, T, undefined>;
381
+ readonly null: TreeNodeSchemaNonClass<"com.fluidframework.leaf.null", NodeKind.Leaf, null, null, true, unknown, never>;
382
+ readonly number: TreeNodeSchemaNonClass<"com.fluidframework.leaf.number", NodeKind.Leaf, number, number, true, unknown, never>;
383
383
  object<const Name extends TName, const T extends RestrictiveStringRecord<ImplicitFieldSchema>>(name: Name, fields: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Object, TreeObjectNode<T, ScopedSchemaName<TScope, Name>>, object & InsertableObjectFromSchemaRecord<T>, true, T>;
384
384
  objectRecursive<const Name extends TName, const T extends Unenforced<RestrictiveStringRecord<ImplicitFieldSchema>>>(name: Name, t: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Object, TreeObjectNodeUnsafe<T, ScopedSchemaName<TScope, Name>>, object & { readonly [Property in keyof T as FieldHasDefaultUnsafe<T[Property]> extends false ? Property : never]: InsertableTreeFieldFromImplicitFieldUnsafe<T[Property], UnionToIntersection_2<T[Property]>>; } & { readonly [Property_1 in keyof T as FieldHasDefaultUnsafe<T[Property_1]> extends true ? Property_1 : never]?: InsertableTreeFieldFromImplicitFieldUnsafe<T[Property_1], UnionToIntersection_2<T[Property_1]>> | undefined; }, false, T>;
385
385
  optional<const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldProps<TCustomMetadata>, "defaultProvider">): FieldSchema<FieldKind.Optional, T, TCustomMetadata>;
@@ -388,7 +388,7 @@ export class SchemaFactory<out TScope extends string | undefined = string | unde
388
388
  requiredRecursive<const T extends Unenforced<ImplicitAllowedTypes>>(t: T, props?: Omit<FieldProps, "defaultProvider">): FieldSchemaUnsafe<FieldKind.Required, T>;
389
389
  // (undocumented)
390
390
  readonly scope: TScope;
391
- readonly string: TreeNodeSchema<"com.fluidframework.leaf.string", NodeKind.Leaf, string, string>;
391
+ readonly string: TreeNodeSchemaNonClass<"com.fluidframework.leaf.string", NodeKind.Leaf, string, string, true, unknown, never>;
392
392
  }
393
393
 
394
394
  // @public
@@ -503,23 +503,26 @@ export type TreeNodeFromImplicitAllowedTypes<TSchema extends ImplicitAllowedType
503
503
  type TreeNodeFromImplicitAllowedTypesUnsafe<TSchema extends Unenforced<ImplicitAllowedTypes>> = TSchema extends TreeNodeSchemaUnsafe ? NodeFromSchemaUnsafe<TSchema> : TSchema extends AllowedTypesUnsafe ? NodeFromSchemaUnsafe<FlexListToUnion<TSchema>> : unknown;
504
504
 
505
505
  // @public @sealed
506
- export type TreeNodeSchema<Name extends string = string, Kind extends NodeKind = NodeKind, TNode extends TreeNode | TreeLeafValue = TreeNode | TreeLeafValue, TBuild = never, ImplicitlyConstructable extends boolean = boolean, Info = unknown> = TreeNodeSchemaClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info> | TreeNodeSchemaNonClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info>;
506
+ export type TreeNodeSchema<Name extends string = string, Kind extends NodeKind = NodeKind, TNode extends TreeNode | TreeLeafValue = TreeNode | TreeLeafValue, TBuild = never, ImplicitlyConstructable extends boolean = boolean, Info = unknown> = (TNode extends TreeNode ? TreeNodeSchemaClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info> : never) | TreeNodeSchemaNonClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info>;
507
507
 
508
508
  // @public @sealed
509
- export interface TreeNodeSchemaClass<out Name extends string = string, out Kind extends NodeKind = NodeKind, out TNode extends TreeNode | TreeLeafValue = TreeNode | TreeLeafValue, in TInsertable = never, out ImplicitlyConstructable extends boolean = boolean, out Info = unknown> extends TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info> {
510
- // @sealed
511
- new (data: TInsertable | InternalTreeNode): Unhydrated<TNode>;
512
- }
509
+ export type TreeNodeSchemaClass<Name extends string = string, Kind extends NodeKind = NodeKind, TNode extends TreeNode = TreeNode, TInsertable = never, ImplicitlyConstructable extends boolean = boolean, Info = unknown, TConstructorExtra = never> = TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info, TInsertable> & (undefined extends TConstructorExtra ? {
510
+ new (data?: TInsertable | InternalTreeNode | TConstructorExtra): Unhydrated<TNode>;
511
+ } : {
512
+ new (data: TInsertable | InternalTreeNode | TConstructorExtra): Unhydrated<TNode>;
513
+ });
513
514
 
514
515
  // @public
515
- export interface TreeNodeSchemaClassUnsafe<out Name extends string, out Kind extends NodeKind, out TNode extends Unenforced<TreeNode | TreeLeafValue>, in TInsertable, out ImplicitlyConstructable extends boolean, out Info> extends TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info> {
516
+ export interface TreeNodeSchemaClassUnsafe<out Name extends string, out Kind extends NodeKind, out TNode extends Unenforced<TreeNode>, in TInsertable, out ImplicitlyConstructable extends boolean, out Info> extends TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info> {
516
517
  // @sealed
517
518
  new (data: TInsertable | InternalTreeNode): Unhydrated<TNode>;
518
519
  }
519
520
 
520
521
  // @public @sealed
521
- export interface TreeNodeSchemaCore<out Name extends string, out Kind extends NodeKind, out ImplicitlyConstructable extends boolean, out Info = unknown> {
522
+ export interface TreeNodeSchemaCore<out Name extends string, out Kind extends NodeKind, out ImplicitlyConstructable extends boolean, out Info = unknown, out TInsertable = never> {
522
523
  readonly childTypes: ReadonlySet<TreeNodeSchema>;
524
+ // @sealed
525
+ createFromInsertable(data: TInsertable): Unhydrated<TreeNode | TreeLeafValue>;
523
526
  readonly identifier: Name;
524
527
  readonly implicitlyConstructable: ImplicitlyConstructable;
525
528
  readonly info: Info;
@@ -528,10 +531,11 @@ export interface TreeNodeSchemaCore<out Name extends string, out Kind extends No
528
531
  }
529
532
 
530
533
  // @public @sealed
531
- export interface TreeNodeSchemaNonClass<out Name extends string = string, out Kind extends NodeKind = NodeKind, out TNode extends TreeNode | TreeLeafValue = TreeNode | TreeLeafValue, in TInsertable = never, out ImplicitlyConstructable extends boolean = boolean, out Info = unknown> extends TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info> {
532
- // (undocumented)
533
- create(data: TInsertable): TNode;
534
- }
534
+ export type TreeNodeSchemaNonClass<Name extends string = string, Kind extends NodeKind = NodeKind, TNode extends TreeNode | TreeLeafValue = TreeNode | TreeLeafValue, TInsertable = never, ImplicitlyConstructable extends boolean = boolean, Info = unknown, TConstructorExtra = never> = TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info, TInsertable> & (undefined extends TConstructorExtra ? {
535
+ create(data?: TInsertable | TConstructorExtra): TNode;
536
+ } : {
537
+ create(data: TInsertable | TConstructorExtra): TNode;
538
+ });
535
539
 
536
540
  // @public
537
541
  interface TreeNodeSchemaNonClassUnsafe<out Name extends string, out Kind extends NodeKind, out TNode extends Unenforced<TreeNode | TreeLeafValue>, in TInsertable, out ImplicitlyConstructable extends boolean, out Info = unknown> extends TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info> {
@@ -619,7 +623,7 @@ export interface ViewableTree {
619
623
  export interface WithType<out TName extends string = string, out TKind extends NodeKind = NodeKind, out TInfo = unknown> {
620
624
  // @deprecated
621
625
  get [typeNameSymbol](): TName;
622
- get [typeSchemaSymbol](): TreeNodeSchemaClass<TName, TKind, TreeNode | TreeLeafValue, never, boolean, TInfo>;
626
+ get [typeSchemaSymbol](): TreeNodeSchemaClass<TName, TKind, TreeNode, never, boolean, TInfo>;
623
627
  }
624
628
 
625
629
  // (No @packageDocumentation comment for this package)
@@ -242,7 +242,7 @@ export interface MakeNominal {
242
242
  export type MapNodeInsertableData<T extends ImplicitAllowedTypes> = Iterable<readonly [string, InsertableTreeNodeFromImplicitAllowedTypes<T>]> | RestrictiveStringRecord<InsertableTreeNodeFromImplicitAllowedTypes<T>>;
243
243
 
244
244
  // @public
245
- type NodeBuilderData<T extends TreeNodeSchema> = T extends TreeNodeSchema<string, NodeKind, TreeNode | TreeLeafValue, infer TBuild> ? TBuild : never;
245
+ type NodeBuilderData<T extends TreeNodeSchemaCore<string, NodeKind, boolean>> = T extends TreeNodeSchemaCore<string, NodeKind, boolean, unknown, infer TBuild> ? TBuild : never;
246
246
 
247
247
  // @public
248
248
  type NodeBuilderDataUnsafe<T extends Unenforced<TreeNodeSchema>> = T extends TreeNodeSchemaUnsafe<string, NodeKind, unknown, infer TBuild> ? TBuild : never;
@@ -362,24 +362,24 @@ export interface SchemaCompatibilityStatus {
362
362
  // @public @sealed
363
363
  export class SchemaFactory<out TScope extends string | undefined = string | undefined, TName extends number | string = string> {
364
364
  constructor(scope: TScope);
365
- array<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(allowedTypes: T): TreeNodeSchemaNonClass<ScopedSchemaName<TScope, `Array<${string}>`>, NodeKind.Array, TreeArrayNode<T> & WithType<ScopedSchemaName<TScope, `Array<${string}>`>, NodeKind.Array>, Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>, true, T>;
366
- array<const Name extends TName, const T extends ImplicitAllowedTypes>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Array, TreeArrayNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Array>, Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>, true, T>;
365
+ array<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(allowedTypes: T): TreeNodeSchemaNonClass<ScopedSchemaName<TScope, `Array<${string}>`>, NodeKind.Array, TreeArrayNode<T> & WithType<ScopedSchemaName<TScope, `Array<${string}>`>, NodeKind.Array>, Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>, true, T, undefined>;
366
+ array<const Name extends TName, const T extends ImplicitAllowedTypes>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Array, TreeArrayNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Array>, Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>, true, T, undefined>;
367
367
  arrayRecursive<const Name extends TName, const T extends Unenforced<ImplicitAllowedTypes>>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Array, TreeArrayNodeUnsafe<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Array, unknown>, {
368
368
  [Symbol.iterator](): Iterator<InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>>;
369
- }, false, T>;
370
- readonly boolean: TreeNodeSchema<"com.fluidframework.leaf.boolean", NodeKind.Leaf, boolean, boolean>;
371
- readonly handle: TreeNodeSchema<"com.fluidframework.leaf.handle", NodeKind.Leaf, IFluidHandle<unknown>, IFluidHandle<unknown>>;
369
+ }, false, T, undefined>;
370
+ readonly boolean: TreeNodeSchemaNonClass<"com.fluidframework.leaf.boolean", NodeKind.Leaf, boolean, boolean, true, unknown, never>;
371
+ readonly handle: TreeNodeSchemaNonClass<"com.fluidframework.leaf.handle", NodeKind.Leaf, IFluidHandle<unknown>, IFluidHandle<unknown>, true, unknown, never>;
372
372
  get identifier(): FieldSchema<FieldKind.Identifier, typeof SchemaFactory.string>;
373
- map<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(allowedTypes: T): TreeNodeSchemaNonClass<ScopedSchemaName<TScope, `Map<${string}>`>, NodeKind.Map, TreeMapNode<T> & WithType<ScopedSchemaName<TScope, `Map<${string}>`>, NodeKind.Map>, MapNodeInsertableData<T>, true, T>;
374
- map<Name extends TName, const T extends ImplicitAllowedTypes>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Map, TreeMapNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Map>, MapNodeInsertableData<T>, true, T>;
373
+ map<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(allowedTypes: T): TreeNodeSchemaNonClass<ScopedSchemaName<TScope, `Map<${string}>`>, NodeKind.Map, TreeMapNode<T> & WithType<ScopedSchemaName<TScope, `Map<${string}>`>, NodeKind.Map>, MapNodeInsertableData<T>, true, T, undefined>;
374
+ map<Name extends TName, const T extends ImplicitAllowedTypes>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Map, TreeMapNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Map>, MapNodeInsertableData<T>, true, T, undefined>;
375
375
  mapRecursive<Name extends TName, const T extends Unenforced<ImplicitAllowedTypes>>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Map, TreeMapNodeUnsafe<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Map, unknown>, {
376
376
  [Symbol.iterator](): Iterator<[
377
377
  string,
378
378
  InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>
379
379
  ]>;
380
- }, false, T>;
381
- readonly null: TreeNodeSchema<"com.fluidframework.leaf.null", NodeKind.Leaf, null, null>;
382
- readonly number: TreeNodeSchema<"com.fluidframework.leaf.number", NodeKind.Leaf, number, number>;
380
+ }, false, T, undefined>;
381
+ readonly null: TreeNodeSchemaNonClass<"com.fluidframework.leaf.null", NodeKind.Leaf, null, null, true, unknown, never>;
382
+ readonly number: TreeNodeSchemaNonClass<"com.fluidframework.leaf.number", NodeKind.Leaf, number, number, true, unknown, never>;
383
383
  object<const Name extends TName, const T extends RestrictiveStringRecord<ImplicitFieldSchema>>(name: Name, fields: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Object, TreeObjectNode<T, ScopedSchemaName<TScope, Name>>, object & InsertableObjectFromSchemaRecord<T>, true, T>;
384
384
  objectRecursive<const Name extends TName, const T extends Unenforced<RestrictiveStringRecord<ImplicitFieldSchema>>>(name: Name, t: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Object, TreeObjectNodeUnsafe<T, ScopedSchemaName<TScope, Name>>, object & { readonly [Property in keyof T as FieldHasDefaultUnsafe<T[Property]> extends false ? Property : never]: InsertableTreeFieldFromImplicitFieldUnsafe<T[Property], UnionToIntersection_2<T[Property]>>; } & { readonly [Property_1 in keyof T as FieldHasDefaultUnsafe<T[Property_1]> extends true ? Property_1 : never]?: InsertableTreeFieldFromImplicitFieldUnsafe<T[Property_1], UnionToIntersection_2<T[Property_1]>> | undefined; }, false, T>;
385
385
  optional<const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldProps<TCustomMetadata>, "defaultProvider">): FieldSchema<FieldKind.Optional, T, TCustomMetadata>;
@@ -388,7 +388,7 @@ export class SchemaFactory<out TScope extends string | undefined = string | unde
388
388
  requiredRecursive<const T extends Unenforced<ImplicitAllowedTypes>>(t: T, props?: Omit<FieldProps, "defaultProvider">): FieldSchemaUnsafe<FieldKind.Required, T>;
389
389
  // (undocumented)
390
390
  readonly scope: TScope;
391
- readonly string: TreeNodeSchema<"com.fluidframework.leaf.string", NodeKind.Leaf, string, string>;
391
+ readonly string: TreeNodeSchemaNonClass<"com.fluidframework.leaf.string", NodeKind.Leaf, string, string, true, unknown, never>;
392
392
  }
393
393
 
394
394
  // @public
@@ -500,23 +500,26 @@ export type TreeNodeFromImplicitAllowedTypes<TSchema extends ImplicitAllowedType
500
500
  type TreeNodeFromImplicitAllowedTypesUnsafe<TSchema extends Unenforced<ImplicitAllowedTypes>> = TSchema extends TreeNodeSchemaUnsafe ? NodeFromSchemaUnsafe<TSchema> : TSchema extends AllowedTypesUnsafe ? NodeFromSchemaUnsafe<FlexListToUnion<TSchema>> : unknown;
501
501
 
502
502
  // @public @sealed
503
- export type TreeNodeSchema<Name extends string = string, Kind extends NodeKind = NodeKind, TNode extends TreeNode | TreeLeafValue = TreeNode | TreeLeafValue, TBuild = never, ImplicitlyConstructable extends boolean = boolean, Info = unknown> = TreeNodeSchemaClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info> | TreeNodeSchemaNonClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info>;
503
+ export type TreeNodeSchema<Name extends string = string, Kind extends NodeKind = NodeKind, TNode extends TreeNode | TreeLeafValue = TreeNode | TreeLeafValue, TBuild = never, ImplicitlyConstructable extends boolean = boolean, Info = unknown> = (TNode extends TreeNode ? TreeNodeSchemaClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info> : never) | TreeNodeSchemaNonClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info>;
504
504
 
505
505
  // @public @sealed
506
- export interface TreeNodeSchemaClass<out Name extends string = string, out Kind extends NodeKind = NodeKind, out TNode extends TreeNode | TreeLeafValue = TreeNode | TreeLeafValue, in TInsertable = never, out ImplicitlyConstructable extends boolean = boolean, out Info = unknown> extends TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info> {
507
- // @sealed
508
- new (data: TInsertable | InternalTreeNode): Unhydrated<TNode>;
509
- }
506
+ export type TreeNodeSchemaClass<Name extends string = string, Kind extends NodeKind = NodeKind, TNode extends TreeNode = TreeNode, TInsertable = never, ImplicitlyConstructable extends boolean = boolean, Info = unknown, TConstructorExtra = never> = TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info, TInsertable> & (undefined extends TConstructorExtra ? {
507
+ new (data?: TInsertable | InternalTreeNode | TConstructorExtra): Unhydrated<TNode>;
508
+ } : {
509
+ new (data: TInsertable | InternalTreeNode | TConstructorExtra): Unhydrated<TNode>;
510
+ });
510
511
 
511
512
  // @public
512
- export interface TreeNodeSchemaClassUnsafe<out Name extends string, out Kind extends NodeKind, out TNode extends Unenforced<TreeNode | TreeLeafValue>, in TInsertable, out ImplicitlyConstructable extends boolean, out Info> extends TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info> {
513
+ export interface TreeNodeSchemaClassUnsafe<out Name extends string, out Kind extends NodeKind, out TNode extends Unenforced<TreeNode>, in TInsertable, out ImplicitlyConstructable extends boolean, out Info> extends TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info> {
513
514
  // @sealed
514
515
  new (data: TInsertable | InternalTreeNode): Unhydrated<TNode>;
515
516
  }
516
517
 
517
518
  // @public @sealed
518
- export interface TreeNodeSchemaCore<out Name extends string, out Kind extends NodeKind, out ImplicitlyConstructable extends boolean, out Info = unknown> {
519
+ export interface TreeNodeSchemaCore<out Name extends string, out Kind extends NodeKind, out ImplicitlyConstructable extends boolean, out Info = unknown, out TInsertable = never> {
519
520
  readonly childTypes: ReadonlySet<TreeNodeSchema>;
521
+ // @sealed
522
+ createFromInsertable(data: TInsertable): Unhydrated<TreeNode | TreeLeafValue>;
520
523
  readonly identifier: Name;
521
524
  readonly implicitlyConstructable: ImplicitlyConstructable;
522
525
  readonly info: Info;
@@ -525,10 +528,11 @@ export interface TreeNodeSchemaCore<out Name extends string, out Kind extends No
525
528
  }
526
529
 
527
530
  // @public @sealed
528
- export interface TreeNodeSchemaNonClass<out Name extends string = string, out Kind extends NodeKind = NodeKind, out TNode extends TreeNode | TreeLeafValue = TreeNode | TreeLeafValue, in TInsertable = never, out ImplicitlyConstructable extends boolean = boolean, out Info = unknown> extends TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info> {
529
- // (undocumented)
530
- create(data: TInsertable): TNode;
531
- }
531
+ export type TreeNodeSchemaNonClass<Name extends string = string, Kind extends NodeKind = NodeKind, TNode extends TreeNode | TreeLeafValue = TreeNode | TreeLeafValue, TInsertable = never, ImplicitlyConstructable extends boolean = boolean, Info = unknown, TConstructorExtra = never> = TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info, TInsertable> & (undefined extends TConstructorExtra ? {
532
+ create(data?: TInsertable | TConstructorExtra): TNode;
533
+ } : {
534
+ create(data: TInsertable | TConstructorExtra): TNode;
535
+ });
532
536
 
533
537
  // @public
534
538
  interface TreeNodeSchemaNonClassUnsafe<out Name extends string, out Kind extends NodeKind, out TNode extends Unenforced<TreeNode | TreeLeafValue>, in TInsertable, out ImplicitlyConstructable extends boolean, out Info = unknown> extends TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info> {
@@ -616,7 +620,7 @@ export interface ViewableTree {
616
620
  export interface WithType<out TName extends string = string, out TKind extends NodeKind = NodeKind, out TInfo = unknown> {
617
621
  // @deprecated
618
622
  get [typeNameSymbol](): TName;
619
- get [typeSchemaSymbol](): TreeNodeSchemaClass<TName, TKind, TreeNode | TreeLeafValue, never, boolean, TInfo>;
623
+ get [typeSchemaSymbol](): TreeNodeSchemaClass<TName, TKind, TreeNode, never, boolean, TInfo>;
620
624
  }
621
625
 
622
626
  // (No @packageDocumentation comment for this package)
@@ -242,7 +242,7 @@ export interface MakeNominal {
242
242
  export type MapNodeInsertableData<T extends ImplicitAllowedTypes> = Iterable<readonly [string, InsertableTreeNodeFromImplicitAllowedTypes<T>]> | RestrictiveStringRecord<InsertableTreeNodeFromImplicitAllowedTypes<T>>;
243
243
 
244
244
  // @public
245
- type NodeBuilderData<T extends TreeNodeSchema> = T extends TreeNodeSchema<string, NodeKind, TreeNode | TreeLeafValue, infer TBuild> ? TBuild : never;
245
+ type NodeBuilderData<T extends TreeNodeSchemaCore<string, NodeKind, boolean>> = T extends TreeNodeSchemaCore<string, NodeKind, boolean, unknown, infer TBuild> ? TBuild : never;
246
246
 
247
247
  // @public
248
248
  type NodeBuilderDataUnsafe<T extends Unenforced<TreeNodeSchema>> = T extends TreeNodeSchemaUnsafe<string, NodeKind, unknown, infer TBuild> ? TBuild : never;
@@ -362,24 +362,24 @@ export interface SchemaCompatibilityStatus {
362
362
  // @public @sealed
363
363
  export class SchemaFactory<out TScope extends string | undefined = string | undefined, TName extends number | string = string> {
364
364
  constructor(scope: TScope);
365
- array<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(allowedTypes: T): TreeNodeSchemaNonClass<ScopedSchemaName<TScope, `Array<${string}>`>, NodeKind.Array, TreeArrayNode<T> & WithType<ScopedSchemaName<TScope, `Array<${string}>`>, NodeKind.Array>, Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>, true, T>;
366
- array<const Name extends TName, const T extends ImplicitAllowedTypes>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Array, TreeArrayNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Array>, Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>, true, T>;
365
+ array<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(allowedTypes: T): TreeNodeSchemaNonClass<ScopedSchemaName<TScope, `Array<${string}>`>, NodeKind.Array, TreeArrayNode<T> & WithType<ScopedSchemaName<TScope, `Array<${string}>`>, NodeKind.Array>, Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>, true, T, undefined>;
366
+ array<const Name extends TName, const T extends ImplicitAllowedTypes>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Array, TreeArrayNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Array>, Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>, true, T, undefined>;
367
367
  arrayRecursive<const Name extends TName, const T extends Unenforced<ImplicitAllowedTypes>>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Array, TreeArrayNodeUnsafe<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Array, unknown>, {
368
368
  [Symbol.iterator](): Iterator<InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>>;
369
- }, false, T>;
370
- readonly boolean: TreeNodeSchema<"com.fluidframework.leaf.boolean", NodeKind.Leaf, boolean, boolean>;
371
- readonly handle: TreeNodeSchema<"com.fluidframework.leaf.handle", NodeKind.Leaf, IFluidHandle<unknown>, IFluidHandle<unknown>>;
369
+ }, false, T, undefined>;
370
+ readonly boolean: TreeNodeSchemaNonClass<"com.fluidframework.leaf.boolean", NodeKind.Leaf, boolean, boolean, true, unknown, never>;
371
+ readonly handle: TreeNodeSchemaNonClass<"com.fluidframework.leaf.handle", NodeKind.Leaf, IFluidHandle<unknown>, IFluidHandle<unknown>, true, unknown, never>;
372
372
  get identifier(): FieldSchema<FieldKind.Identifier, typeof SchemaFactory.string>;
373
- map<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(allowedTypes: T): TreeNodeSchemaNonClass<ScopedSchemaName<TScope, `Map<${string}>`>, NodeKind.Map, TreeMapNode<T> & WithType<ScopedSchemaName<TScope, `Map<${string}>`>, NodeKind.Map>, MapNodeInsertableData<T>, true, T>;
374
- map<Name extends TName, const T extends ImplicitAllowedTypes>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Map, TreeMapNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Map>, MapNodeInsertableData<T>, true, T>;
373
+ map<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(allowedTypes: T): TreeNodeSchemaNonClass<ScopedSchemaName<TScope, `Map<${string}>`>, NodeKind.Map, TreeMapNode<T> & WithType<ScopedSchemaName<TScope, `Map<${string}>`>, NodeKind.Map>, MapNodeInsertableData<T>, true, T, undefined>;
374
+ map<Name extends TName, const T extends ImplicitAllowedTypes>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Map, TreeMapNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Map>, MapNodeInsertableData<T>, true, T, undefined>;
375
375
  mapRecursive<Name extends TName, const T extends Unenforced<ImplicitAllowedTypes>>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Map, TreeMapNodeUnsafe<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Map, unknown>, {
376
376
  [Symbol.iterator](): Iterator<[
377
377
  string,
378
378
  InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>
379
379
  ]>;
380
- }, false, T>;
381
- readonly null: TreeNodeSchema<"com.fluidframework.leaf.null", NodeKind.Leaf, null, null>;
382
- readonly number: TreeNodeSchema<"com.fluidframework.leaf.number", NodeKind.Leaf, number, number>;
380
+ }, false, T, undefined>;
381
+ readonly null: TreeNodeSchemaNonClass<"com.fluidframework.leaf.null", NodeKind.Leaf, null, null, true, unknown, never>;
382
+ readonly number: TreeNodeSchemaNonClass<"com.fluidframework.leaf.number", NodeKind.Leaf, number, number, true, unknown, never>;
383
383
  object<const Name extends TName, const T extends RestrictiveStringRecord<ImplicitFieldSchema>>(name: Name, fields: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Object, TreeObjectNode<T, ScopedSchemaName<TScope, Name>>, object & InsertableObjectFromSchemaRecord<T>, true, T>;
384
384
  objectRecursive<const Name extends TName, const T extends Unenforced<RestrictiveStringRecord<ImplicitFieldSchema>>>(name: Name, t: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Object, TreeObjectNodeUnsafe<T, ScopedSchemaName<TScope, Name>>, object & { readonly [Property in keyof T as FieldHasDefaultUnsafe<T[Property]> extends false ? Property : never]: InsertableTreeFieldFromImplicitFieldUnsafe<T[Property], UnionToIntersection_2<T[Property]>>; } & { readonly [Property_1 in keyof T as FieldHasDefaultUnsafe<T[Property_1]> extends true ? Property_1 : never]?: InsertableTreeFieldFromImplicitFieldUnsafe<T[Property_1], UnionToIntersection_2<T[Property_1]>> | undefined; }, false, T>;
385
385
  optional<const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldProps<TCustomMetadata>, "defaultProvider">): FieldSchema<FieldKind.Optional, T, TCustomMetadata>;
@@ -388,7 +388,7 @@ export class SchemaFactory<out TScope extends string | undefined = string | unde
388
388
  requiredRecursive<const T extends Unenforced<ImplicitAllowedTypes>>(t: T, props?: Omit<FieldProps, "defaultProvider">): FieldSchemaUnsafe<FieldKind.Required, T>;
389
389
  // (undocumented)
390
390
  readonly scope: TScope;
391
- readonly string: TreeNodeSchema<"com.fluidframework.leaf.string", NodeKind.Leaf, string, string>;
391
+ readonly string: TreeNodeSchemaNonClass<"com.fluidframework.leaf.string", NodeKind.Leaf, string, string, true, unknown, never>;
392
392
  }
393
393
 
394
394
  // @public
@@ -500,23 +500,26 @@ export type TreeNodeFromImplicitAllowedTypes<TSchema extends ImplicitAllowedType
500
500
  type TreeNodeFromImplicitAllowedTypesUnsafe<TSchema extends Unenforced<ImplicitAllowedTypes>> = TSchema extends TreeNodeSchemaUnsafe ? NodeFromSchemaUnsafe<TSchema> : TSchema extends AllowedTypesUnsafe ? NodeFromSchemaUnsafe<FlexListToUnion<TSchema>> : unknown;
501
501
 
502
502
  // @public @sealed
503
- export type TreeNodeSchema<Name extends string = string, Kind extends NodeKind = NodeKind, TNode extends TreeNode | TreeLeafValue = TreeNode | TreeLeafValue, TBuild = never, ImplicitlyConstructable extends boolean = boolean, Info = unknown> = TreeNodeSchemaClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info> | TreeNodeSchemaNonClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info>;
503
+ export type TreeNodeSchema<Name extends string = string, Kind extends NodeKind = NodeKind, TNode extends TreeNode | TreeLeafValue = TreeNode | TreeLeafValue, TBuild = never, ImplicitlyConstructable extends boolean = boolean, Info = unknown> = (TNode extends TreeNode ? TreeNodeSchemaClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info> : never) | TreeNodeSchemaNonClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info>;
504
504
 
505
505
  // @public @sealed
506
- export interface TreeNodeSchemaClass<out Name extends string = string, out Kind extends NodeKind = NodeKind, out TNode extends TreeNode | TreeLeafValue = TreeNode | TreeLeafValue, in TInsertable = never, out ImplicitlyConstructable extends boolean = boolean, out Info = unknown> extends TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info> {
507
- // @sealed
508
- new (data: TInsertable | InternalTreeNode): Unhydrated<TNode>;
509
- }
506
+ export type TreeNodeSchemaClass<Name extends string = string, Kind extends NodeKind = NodeKind, TNode extends TreeNode = TreeNode, TInsertable = never, ImplicitlyConstructable extends boolean = boolean, Info = unknown, TConstructorExtra = never> = TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info, TInsertable> & (undefined extends TConstructorExtra ? {
507
+ new (data?: TInsertable | InternalTreeNode | TConstructorExtra): Unhydrated<TNode>;
508
+ } : {
509
+ new (data: TInsertable | InternalTreeNode | TConstructorExtra): Unhydrated<TNode>;
510
+ });
510
511
 
511
512
  // @public
512
- export interface TreeNodeSchemaClassUnsafe<out Name extends string, out Kind extends NodeKind, out TNode extends Unenforced<TreeNode | TreeLeafValue>, in TInsertable, out ImplicitlyConstructable extends boolean, out Info> extends TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info> {
513
+ export interface TreeNodeSchemaClassUnsafe<out Name extends string, out Kind extends NodeKind, out TNode extends Unenforced<TreeNode>, in TInsertable, out ImplicitlyConstructable extends boolean, out Info> extends TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info> {
513
514
  // @sealed
514
515
  new (data: TInsertable | InternalTreeNode): Unhydrated<TNode>;
515
516
  }
516
517
 
517
518
  // @public @sealed
518
- export interface TreeNodeSchemaCore<out Name extends string, out Kind extends NodeKind, out ImplicitlyConstructable extends boolean, out Info = unknown> {
519
+ export interface TreeNodeSchemaCore<out Name extends string, out Kind extends NodeKind, out ImplicitlyConstructable extends boolean, out Info = unknown, out TInsertable = never> {
519
520
  readonly childTypes: ReadonlySet<TreeNodeSchema>;
521
+ // @sealed
522
+ createFromInsertable(data: TInsertable): Unhydrated<TreeNode | TreeLeafValue>;
520
523
  readonly identifier: Name;
521
524
  readonly implicitlyConstructable: ImplicitlyConstructable;
522
525
  readonly info: Info;
@@ -525,10 +528,11 @@ export interface TreeNodeSchemaCore<out Name extends string, out Kind extends No
525
528
  }
526
529
 
527
530
  // @public @sealed
528
- export interface TreeNodeSchemaNonClass<out Name extends string = string, out Kind extends NodeKind = NodeKind, out TNode extends TreeNode | TreeLeafValue = TreeNode | TreeLeafValue, in TInsertable = never, out ImplicitlyConstructable extends boolean = boolean, out Info = unknown> extends TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info> {
529
- // (undocumented)
530
- create(data: TInsertable): TNode;
531
- }
531
+ export type TreeNodeSchemaNonClass<Name extends string = string, Kind extends NodeKind = NodeKind, TNode extends TreeNode | TreeLeafValue = TreeNode | TreeLeafValue, TInsertable = never, ImplicitlyConstructable extends boolean = boolean, Info = unknown, TConstructorExtra = never> = TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info, TInsertable> & (undefined extends TConstructorExtra ? {
532
+ create(data?: TInsertable | TConstructorExtra): TNode;
533
+ } : {
534
+ create(data: TInsertable | TConstructorExtra): TNode;
535
+ });
532
536
 
533
537
  // @public
534
538
  interface TreeNodeSchemaNonClassUnsafe<out Name extends string, out Kind extends NodeKind, out TNode extends Unenforced<TreeNode | TreeLeafValue>, in TInsertable, out ImplicitlyConstructable extends boolean, out Info = unknown> extends TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info> {
@@ -616,7 +620,7 @@ export interface ViewableTree {
616
620
  export interface WithType<out TName extends string = string, out TKind extends NodeKind = NodeKind, out TInfo = unknown> {
617
621
  // @deprecated
618
622
  get [typeNameSymbol](): TName;
619
- get [typeSchemaSymbol](): TreeNodeSchemaClass<TName, TKind, TreeNode | TreeLeafValue, never, boolean, TInfo>;
623
+ get [typeSchemaSymbol](): TreeNodeSchemaClass<TName, TKind, TreeNode, never, boolean, TInfo>;
620
624
  }
621
625
 
622
626
  // (No @packageDocumentation comment for this package)
package/dist/alpha.d.ts CHANGED
@@ -94,9 +94,13 @@ export {
94
94
  TreeChangeEventsBeta,
95
95
 
96
96
  // @alpha APIs
97
+ BranchableTree,
98
+ ConciseTree,
99
+ EncodeOptions,
97
100
  FactoryContent,
98
101
  FactoryContentObject,
99
102
  FixRecursiveArraySchema,
103
+ FluidClientVersion,
100
104
  ForestOptions,
101
105
  ForestType,
102
106
  ICodecOptions,
@@ -120,23 +124,34 @@ export {
120
124
  JsonSchemaType,
121
125
  JsonTreeSchema,
122
126
  JsonValidator,
127
+ ParseOptions,
123
128
  PopUnion,
129
+ ReadSchema,
130
+ ReadableField,
124
131
  SchemaValidationFunction,
125
132
  SharedTreeFormatOptions,
126
133
  SharedTreeFormatVersion,
127
134
  SharedTreeOptions,
135
+ TreeAlpha,
128
136
  TreeBranch,
137
+ TreeBranchEvents,
129
138
  TreeBranchFork,
130
139
  TreeCompressionStrategy,
131
140
  TreeViewAlpha,
132
141
  UnionToTuple,
133
142
  UnsafeUnknownSchema,
143
+ VerboseTree,
144
+ VerboseTreeNode,
145
+ ViewContent,
134
146
  adaptEnum,
147
+ asTreeViewAlpha,
135
148
  comparePersistedSchema,
136
149
  enumFromStrings,
137
150
  extractPersistedSchema,
138
151
  getBranch,
139
152
  getJsonSchema,
153
+ independentInitializedView,
154
+ independentView,
140
155
  noopValidator,
141
156
  singletonSchema,
142
157
  typeboxValidator
@@ -180,4 +180,28 @@ export declare const unitCodec: IMultiFormatCodec<0, JsonCompatibleReadOnly, Jso
180
180
  * @returns An {@link IJsonCodec} which validates the data it encodes and decodes matches the provided schema.
181
181
  */
182
182
  export declare function withSchemaValidation<TInMemoryFormat, EncodedSchema extends TSchema, TEncodedFormat = JsonCompatibleReadOnly, TValidate = TEncodedFormat, TContext = ChangeEncodingContext>(schema: EncodedSchema, codec: IJsonCodec<TInMemoryFormat, TEncodedFormat, TValidate, TContext>, validator?: JsonValidator): IJsonCodec<TInMemoryFormat, TEncodedFormat, TValidate, TContext>;
183
+ /**
184
+ * Versions of Fluid Framework client packages.
185
+ * @remarks
186
+ * Used to express compatibility requirements by indicating the oldest version with which compatibility must be maintained.
187
+ * @privateRemarks
188
+ * This scheme assumes a single version will always be enough to communicate compatibility.
189
+ * For this to work, compatibility has to be strictly increasing.
190
+ * If this is violated (for example a subset of incompatible features from 3.x that are not in 3.0 are back ported to 2.x),
191
+ * a more complex scheme may be needed to allow safely opting into incompatible features in those cases:
192
+ * such a system can be added if/when its needed since it will be opt in and thus non-breaking.
193
+ *
194
+ * TODO: this should likely be defined higher in the stack and specified when creating the container, possibly as part of its schema.
195
+ * @alpha
196
+ */
197
+ export declare enum FluidClientVersion {
198
+ /** Fluid Framework Client 2.0 and newer. */
199
+ v2_0 = "v2_0",
200
+ /** Fluid Framework Client 2.1 and newer. */
201
+ v2_1 = "v2_1",
202
+ /** Fluid Framework Client 2.2 and newer. */
203
+ v2_2 = "v2_2",
204
+ /** Fluid Framework Client 2.4 and newer. */
205
+ v2_3 = "v2_3"
206
+ }
183
207
  //# sourceMappingURL=codec.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/codec/codec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAkB,MAAM,8BAA8B,CAAC;AAEzE,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,KAAK,sBAAsB,EAAQ,MAAM,kBAAkB,CAAC;AAErE;;;GAGG;AACH,MAAM,WAAW,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ;IACrD;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,GAAG,QAAQ,CAAC;CACnD;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ;IACrD;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,QAAQ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AAoB,CAAC,QAAQ,EAAE,QAAQ,EACtD,KAAK,EACF,iBAAiB,CAAC,QAAQ,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,QAAQ,CAAC,GACrF,UAAU,CAAC,QAAQ,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,QAAQ,CAAC,GAC/E,iBAAiB,CAAC,QAAQ,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,QAAQ,CAAC,CAEvF;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,iBAAiB,CACxC,CAAC,EACD,sBAAsB,EACtB,sBAAsB,EACtB,OAAO,CAUP,CAAC;AAEF;;;GAGG;AACH,wBAAgB,oBAAoB,CACnC,eAAe,EACf,aAAa,SAAS,OAAO,EAC7B,cAAc,GAAG,sBAAsB,EACvC,SAAS,GAAG,cAAc,EAC1B,QAAQ,GAAG,qBAAqB,EAEhC,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,UAAU,CAAC,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,CAAC,EACvE,SAAS,CAAC,EAAE,aAAa,GACvB,UAAU,CAAC,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,CAAC,CAqBlE;AAED;;;;;;;;;;;;;GAaG;AACH,oBAAY,kBAAkB;IAC7B,4CAA4C;IAC5C,IAAI,SAAS;IACb,4CAA4C;IAC5C,IAAI,SAAS;IACb,4CAA4C;IAC5C,IAAI,SAAS;IACb,4CAA4C;IAC5C,IAAI,SAAS;CACb"}
@@ -4,7 +4,7 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.withSchemaValidation = exports.unitCodec = exports.ensureBinaryEncoding = exports.withDefaultBinaryEncoding = exports.makeCodecFamily = void 0;
7
+ exports.FluidClientVersion = exports.withSchemaValidation = exports.unitCodec = exports.ensureBinaryEncoding = exports.withDefaultBinaryEncoding = exports.makeCodecFamily = void 0;
8
8
  const client_utils_1 = require("@fluid-internal/client-utils");
9
9
  const internal_1 = require("@fluidframework/core-utils/internal");
10
10
  const index_js_1 = require("../util/index.js");
@@ -109,4 +109,29 @@ function withSchemaValidation(schema, codec, validator) {
109
109
  };
110
110
  }
111
111
  exports.withSchemaValidation = withSchemaValidation;
112
+ /**
113
+ * Versions of Fluid Framework client packages.
114
+ * @remarks
115
+ * Used to express compatibility requirements by indicating the oldest version with which compatibility must be maintained.
116
+ * @privateRemarks
117
+ * This scheme assumes a single version will always be enough to communicate compatibility.
118
+ * For this to work, compatibility has to be strictly increasing.
119
+ * If this is violated (for example a subset of incompatible features from 3.x that are not in 3.0 are back ported to 2.x),
120
+ * a more complex scheme may be needed to allow safely opting into incompatible features in those cases:
121
+ * such a system can be added if/when its needed since it will be opt in and thus non-breaking.
122
+ *
123
+ * TODO: this should likely be defined higher in the stack and specified when creating the container, possibly as part of its schema.
124
+ * @alpha
125
+ */
126
+ var FluidClientVersion;
127
+ (function (FluidClientVersion) {
128
+ /** Fluid Framework Client 2.0 and newer. */
129
+ FluidClientVersion["v2_0"] = "v2_0";
130
+ /** Fluid Framework Client 2.1 and newer. */
131
+ FluidClientVersion["v2_1"] = "v2_1";
132
+ /** Fluid Framework Client 2.2 and newer. */
133
+ FluidClientVersion["v2_2"] = "v2_2";
134
+ /** Fluid Framework Client 2.4 and newer. */
135
+ FluidClientVersion["v2_3"] = "v2_3";
136
+ })(FluidClientVersion || (exports.FluidClientVersion = FluidClientVersion = {}));
112
137
  //# sourceMappingURL=codec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"codec.js","sourceRoot":"","sources":["../../src/codec/codec.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAyE;AACzE,kEAA6D;AAI7D,+CAAqE;AA+KrE;;;GAGG;AACH,SAAgB,eAAe,CAC9B,QAOC;IAED,MAAM,MAAM,GAGR,IAAI,GAAG,EAAE,CAAC;IACd,KAAK,MAAM,CAAC,aAAa,EAAE,KAAK,CAAC,IAAI,QAAQ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CAAC;QACD,MAAM,EAAE,CAAC,OAAkB,EAAE,OAAiB,EAAmB,EAAE;YAClE,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;gBACpC,IAAA,eAAI,EAAC,gCAAgC,CAAC,CAAC;YACxC,CAAC;YACD,2GAA2G;YAC3G,OAAO,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAA+B,CAAC;QACrE,CAAC;KACD,CAAC;AACH,CAAC;AA/BD,oDA+BC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IsoBuffer, bufferToString } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { Static, TAnySchema, TSchema } from \"@sinclair/typebox\";\n\nimport type { ChangeEncodingContext } from \"../core/index.js\";\nimport { type JsonCompatibleReadOnly, fail } from \"../util/index.js\";\n\n/**\n * Translates decoded data to encoded data.\n * @remarks Typically paired with an {@link IEncoder}.\n */\nexport interface IEncoder<TDecoded, TEncoded, TContext> {\n\t/**\n\t * Encodes `obj` into some encoded format.\n\t */\n\tencode(obj: TDecoded, context: TContext): TEncoded;\n}\n\n/**\n * Translates encoded data to decoded data.\n * @remarks Typically paired with an {@link IEncoder}.\n */\nexport interface IDecoder<TDecoded, TEncoded, TContext> {\n\t/**\n\t * Decodes `obj` from some encoded format.\n\t */\n\tdecode(obj: TEncoded, context: TContext): TDecoded;\n}\n\n/**\n * Validates data complies with some particular schema.\n * Implementations are typically created by a {@link JsonValidator}.\n * @alpha\n */\nexport interface SchemaValidationFunction<Schema extends TSchema> {\n\t/**\n\t * Returns whether the data matches a schema.\n\t */\n\tcheck(data: unknown): data is Static<Schema>;\n}\n\n/**\n * JSON schema validator compliant with draft 6 schema. See https://json-schema.org.\n * @alpha\n */\nexport interface JsonValidator {\n\t/**\n\t * Compiles the provided JSON schema into a validator for that schema.\n\t * @param schema - A valid draft 6 JSON schema\n\t * @remarks IFluidHandles--which have circular property references--are used in various places in SharedTree's persisted\n\t * format. Handles should only be contained in sections of data which are validated against the empty schema `{}`\n\t * (see https://datatracker.ietf.org/doc/html/draft-wright-json-schema-01#section-4.4).\n\t *\n\t * Implementations of `JsonValidator` must therefore tolerate these values, despite the input not being valid JSON.\n\t */\n\tcompile<Schema extends TSchema>(schema: Schema): SchemaValidationFunction<Schema>;\n}\n\n/**\n * Options relating to handling of persisted data.\n * @alpha\n */\nexport interface ICodecOptions {\n\t/**\n\t * {@link JsonValidator} which SharedTree uses to validate persisted data it reads & writes\n\t * matches the expected encoded format (i.e. the wire format for ops and summaries).\n\t *\n\t * See {@link noopValidator} and {@link typeboxValidator} for out-of-the-box implementations.\n\t *\n\t * This option is not \"on-by-default\" because JSON schema validation comes with a small but noticeable\n\t * runtime performance cost, and popular schema validation libraries have relatively large bundle size.\n\t *\n\t * SharedTree users are still encouraged to use a non-trivial validator (i.e. not `noopValidator`)\n\t * whenever reasonable: it gives better fail-fast behavior when unexpected encoded data is found,\n\t * which reduces the risk of unrecoverable data corruption.\n\t */\n\treadonly jsonValidator: JsonValidator;\n}\n\n/**\n * `TContext` allows passing context to the codec which may configure how data is encoded/decoded.\n * This parameter is typically used for:\n * - Codecs which can pick from multiple encoding options, and imbue the encoded data with information about which option was used.\n * The caller of such a codec can provide context about which encoding choice to make as part of the `encode` call without creating\n * additional codecs. Note that this pattern can always be implemented by having the caller create multiple codecs and selecting the\n * appropriate one, but depending on API layering this might be less ergonomic.\n * - Context for the object currently being encoded, which might enable more efficient encoding. When used in this fashion, the codec author\n * should be careful to include the context somewhere in the encoded data such that decoding can correctly round-trip.\n * For example, a composed set of codecs could implement a form of [dictionary coding](https://en.wikipedia.org/wiki/Dictionary_coder)\n * using a context map which was created by the top-level codec and passed to the inner codecs.\n * This pattern is used:\n * - To avoid repeatedly encoding session ids on commits (only recording it once at the top level)\n * @remarks `TEncoded` should always be valid Json (i.e. not contain functions), but due to TypeScript's handling\n * of index signatures and `JsonCompatibleReadOnly`'s index signature in the Json object case, specifying this as a\n * type-system level constraint makes code that uses this interface more difficult to write.\n *\n * If provided, `TValidate` allows the input type passed to `decode` to be different than `TEncoded`.\n * This is useful when, for example, the type being decoded is `unknown` and must be validated to be a `TEncoded` before being decoded to a `TDecoded`.\n */\nexport interface IJsonCodec<\n\tTDecoded,\n\tTEncoded = JsonCompatibleReadOnly,\n\tTValidate = TEncoded,\n\tTContext = void,\n> extends IEncoder<TDecoded, TEncoded, TContext>,\n\t\tIDecoder<TDecoded, TValidate, TContext> {\n\tencodedSchema?: TAnySchema;\n}\n\n/**\n * @remarks TODO: We might consider using DataView or some kind of writer instead of IsoBuffer.\n */\nexport interface IBinaryCodec<TDecoded, TContext = void>\n\textends IEncoder<TDecoded, IsoBuffer, TContext>,\n\t\tIDecoder<TDecoded, IsoBuffer, TContext> {}\n\n/**\n * Contains knowledge of how to encode some in-memory type into JSON and binary formats,\n * as well as how to decode those representations.\n *\n * @remarks Codecs are typically used in shared-tree to convert data into some persisted format.\n * For this common use case, any format for encoding that was ever actually used needs to\n * be supported for decoding in all future code versions.\n *\n * Using an {@link ICodecFamily} is the recommended strategy for managing this support, keeping in\n * mind evolution of encodings over time.\n */\nexport interface IMultiFormatCodec<\n\tTDecoded,\n\tTJsonEncoded extends JsonCompatibleReadOnly = JsonCompatibleReadOnly,\n\tTJsonValidate = TJsonEncoded,\n\tTContext = void,\n> {\n\tjson: IJsonCodec<TDecoded, TJsonEncoded, TJsonValidate, TContext>;\n\tbinary: IBinaryCodec<TDecoded, TContext>;\n\n\t/** Ensures multi-format codecs cannot also be single-format codecs. */\n\tencode?: never;\n\t/** Ensures multi-format codecs cannot also be single-format codecs. */\n\tdecode?: never;\n}\n\n/**\n * Represents a family of codecs that can be used to encode and decode data in different formats.\n * The family is identified by a format version, which is typically used to select the codec to use.\n *\n * Separating codecs into families rather than having a single codec support multiple versions (i.e. currying\n * the `formatVersion` parameter)\n * allows avoiding some duplicate work at encode/decode time, since the vast majority of document usage will not\n * involve mixed format versions.\n *\n * @privateRemarks - This interface currently assumes all codecs in a family require the same encode/decode context,\n * which isn't necessarily true.\n * This may need to be relaxed in the future.\n */\nexport interface ICodecFamily<TDecoded, TContext = void> {\n\t/**\n\t * @returns a codec that can be used to encode and decode data in the specified format.\n\t * @throws - if the format version is not supported by this family.\n\t * @remarks Implementations should typically emit telemetry (either indirectly by throwing a well-known error with\n\t * logged properties or directly using some logger) when a format version is requested that is not supported.\n\t * This ensures that applications can diagnose compatibility issues.\n\t */\n\tresolve(\n\t\tformatVersion: FormatVersion,\n\t): IMultiFormatCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>;\n\n\t/**\n\t * @returns an iterable of all format versions supported by this family.\n\t */\n\tgetSupportedFormats(): Iterable<FormatVersion>;\n}\n\n/**\n * A version stamp for encoded data.\n *\n * Undefined is tolerated to enable the scenario where data was not initially versioned.\n */\nexport type FormatVersion = number | undefined;\n\n/**\n * Creates a codec family from a registry of codecs.\n * Any codec that is not a {@link IMultiFormatCodec} will be wrapped with a default binary encoding.\n */\nexport function makeCodecFamily<TDecoded, TContext>(\n\tregistry: Iterable<\n\t\t[\n\t\t\tformatVersion: FormatVersion,\n\t\t\tcodec:\n\t\t\t\t| IMultiFormatCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>\n\t\t\t\t| IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>,\n\t\t]\n\t>,\n): ICodecFamily<TDecoded, TContext> {\n\tconst codecs: Map<\n\t\tFormatVersion,\n\t\tIMultiFormatCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>\n\t> = new Map();\n\tfor (const [formatVersion, codec] of registry) {\n\t\tif (codecs.has(formatVersion)) {\n\t\t\tfail(\"Duplicate codecs specified.\");\n\t\t}\n\t\tcodecs.set(formatVersion, ensureBinaryEncoding(codec));\n\t}\n\n\treturn {\n\t\tresolve(\n\t\t\tformatVersion: number,\n\t\t): IMultiFormatCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext> {\n\t\t\tconst codec = codecs.get(formatVersion);\n\t\t\tassert(codec !== undefined, 0x5e6 /* Requested coded for unsupported format. */);\n\t\t\treturn codec;\n\t\t},\n\t\tgetSupportedFormats(): Iterable<FormatVersion> {\n\t\t\treturn codecs.keys();\n\t\t},\n\t};\n}\n\nclass DefaultBinaryCodec<TDecoded, TContext> implements IBinaryCodec<TDecoded, TContext> {\n\tpublic constructor(\n\t\tprivate readonly jsonCodec: IJsonCodec<TDecoded, unknown, unknown, TContext>,\n\t) {}\n\n\tpublic encode(change: TDecoded, context: TContext): IsoBuffer {\n\t\tconst jsonable = this.jsonCodec.encode(change, context);\n\t\tconst json = JSON.stringify(jsonable);\n\t\treturn IsoBuffer.from(json);\n\t}\n\n\tpublic decode(change: IsoBuffer, context: TContext): TDecoded {\n\t\tconst json = bufferToString(change, \"utf8\");\n\t\tconst jsonable = JSON.parse(json);\n\t\treturn this.jsonCodec.decode(jsonable, context);\n\t}\n}\n\nfunction isJsonCodec<TDecoded, TContext>(\n\tcodec:\n\t\t| IMultiFormatCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>\n\t\t| IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>,\n): codec is IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext> {\n\treturn typeof codec.encode === \"function\" && typeof codec.decode === \"function\";\n}\n\n/**\n * Constructs a {@link IMultiFormatCodec} from a `IJsonCodec` using a generic binary encoding that simply writes\n * the json representation of the object to a buffer.\n */\nexport function withDefaultBinaryEncoding<TDecoded, TContext>(\n\tjsonCodec: IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>,\n): IMultiFormatCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext> {\n\treturn {\n\t\tjson: jsonCodec,\n\t\tbinary: new DefaultBinaryCodec(jsonCodec),\n\t};\n}\n\n/**\n * Ensures that the provided single or multi-format codec has a binary encoding.\n * Adapts the json encoding using {@link withDefaultBinaryEncoding} if necessary.\n */\nexport function ensureBinaryEncoding<TDecoded, TContext>(\n\tcodec:\n\t\t| IMultiFormatCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>\n\t\t| IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>,\n): IMultiFormatCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext> {\n\treturn isJsonCodec(codec) ? withDefaultBinaryEncoding(codec) : codec;\n}\n\n/**\n * Codec for objects which carry no information.\n */\nexport const unitCodec: IMultiFormatCodec<\n\t0,\n\tJsonCompatibleReadOnly,\n\tJsonCompatibleReadOnly,\n\tunknown\n> = {\n\tjson: {\n\t\tencode: () => 0,\n\t\tdecode: () => 0,\n\t},\n\tbinary: {\n\t\tencode: () => IsoBuffer.from(\"\"),\n\t\tdecode: () => 0,\n\t},\n};\n\n/**\n * Wraps a codec with JSON schema validation for its encoded type.\n * @returns An {@link IJsonCodec} which validates the data it encodes and decodes matches the provided schema.\n */\nexport function withSchemaValidation<\n\tTInMemoryFormat,\n\tEncodedSchema extends TSchema,\n\tTEncodedFormat = JsonCompatibleReadOnly,\n\tTValidate = TEncodedFormat,\n\tTContext = ChangeEncodingContext,\n>(\n\tschema: EncodedSchema,\n\tcodec: IJsonCodec<TInMemoryFormat, TEncodedFormat, TValidate, TContext>,\n\tvalidator?: JsonValidator,\n): IJsonCodec<TInMemoryFormat, TEncodedFormat, TValidate, TContext> {\n\tif (!validator) {\n\t\treturn codec;\n\t}\n\tconst compiledFormat = validator.compile(schema);\n\treturn {\n\t\tencode: (obj: TInMemoryFormat, context: TContext): TEncodedFormat => {\n\t\t\tconst encoded = codec.encode(obj, context);\n\t\t\tif (!compiledFormat.check(encoded)) {\n\t\t\t\tfail(\"Encoded schema should validate\");\n\t\t\t}\n\t\t\treturn encoded;\n\t\t},\n\t\tdecode: (encoded: TValidate, context: TContext): TInMemoryFormat => {\n\t\t\tif (!compiledFormat.check(encoded)) {\n\t\t\t\tfail(\"Encoded schema should validate\");\n\t\t\t}\n\t\t\t// TODO: would be nice to provide a more specific validate type to the inner codec than the outer one gets.\n\t\t\treturn codec.decode(encoded, context) as unknown as TInMemoryFormat;\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"codec.js","sourceRoot":"","sources":["../../src/codec/codec.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAyE;AACzE,kEAA6D;AAI7D,+CAAqE;AA+KrE;;;GAGG;AACH,SAAgB,eAAe,CAC9B,QAOC;IAED,MAAM,MAAM,GAGR,IAAI,GAAG,EAAE,CAAC;IACd,KAAK,MAAM,CAAC,aAAa,EAAE,KAAK,CAAC,IAAI,QAAQ,EAAE,CAAC;QAC/C,IAAI,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;YAC/B,IAAA,eAAI,EAAC,6BAA6B,CAAC,CAAC;QACrC,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,aAAa,EAAE,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,OAAO;QACN,OAAO,CACN,aAAqB;YAErB,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;YACxC,IAAA,iBAAM,EAAC,KAAK,KAAK,SAAS,EAAE,KAAK,CAAC,6CAA6C,CAAC,CAAC;YACjF,OAAO,KAAK,CAAC;QACd,CAAC;QACD,mBAAmB;YAClB,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;QACtB,CAAC;KACD,CAAC;AACH,CAAC;AAjCD,0CAiCC;AAED,MAAM,kBAAkB;IACvB,YACkB,SAA2D;QAA3D,cAAS,GAAT,SAAS,CAAkD;IAC1E,CAAC;IAEG,MAAM,CAAC,MAAgB,EAAE,OA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C,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;KACf;CACD,CAAC;AAEF;;;GAGG;AACH,SAAgB,oBAAoB,CAOnC,MAAqB,EACrB,KAAuE,EACvE,SAAyB;IAEzB,IAAI,CAAC,SAAS,EAAE,CAAC;QAChB,OAAO,KAAK,CAAC;IACd,CAAC;IACD,MAAM,cAAc,GAAG,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACjD,OAAO;QACN,MAAM,EAAE,CAAC,GAAoB,EAAE,OAAiB,EAAkB,EAAE;YACnE,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YAC3C,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;gBACpC,IAAA,eAAI,EAAC,gCAAgC,CAAC,CAAC;YACxC,CAAC;YACD,OAAO,OAAO,CAAC;QAChB,CAAC;QACD,MAAM,EAAE,CAAC,OAAkB,EAAE,OAAiB,EAAmB,EAAE;YAClE,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;gBACpC,IAAA,eAAI,EAAC,gCAAgC,CAAC,CAAC;YACxC,CAAC;YACD,2GAA2G;YAC3G,OAAO,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAA+B,CAAC;QACrE,CAAC;KACD,CAAC;AACH,CAAC;AA/BD,oDA+BC;AAED;;;;;;;;;;;;;GAaG;AACH,IAAY,kBASX;AATD,WAAY,kBAAkB;IAC7B,4CAA4C;IAC5C,mCAAa,CAAA;IACb,4CAA4C;IAC5C,mCAAa,CAAA;IACb,4CAA4C;IAC5C,mCAAa,CAAA;IACb,4CAA4C;IAC5C,mCAAa,CAAA;AACd,CAAC,EATW,kBAAkB,kCAAlB,kBAAkB,QAS7B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IsoBuffer, bufferToString } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { Static, TAnySchema, TSchema } from \"@sinclair/typebox\";\n\nimport type { ChangeEncodingContext } from \"../core/index.js\";\nimport { type JsonCompatibleReadOnly, fail } from \"../util/index.js\";\n\n/**\n * Translates decoded data to encoded data.\n * @remarks Typically paired with an {@link IEncoder}.\n */\nexport interface IEncoder<TDecoded, TEncoded, TContext> {\n\t/**\n\t * Encodes `obj` into some encoded format.\n\t */\n\tencode(obj: TDecoded, context: TContext): TEncoded;\n}\n\n/**\n * Translates encoded data to decoded data.\n * @remarks Typically paired with an {@link IEncoder}.\n */\nexport interface IDecoder<TDecoded, TEncoded, TContext> {\n\t/**\n\t * Decodes `obj` from some encoded format.\n\t */\n\tdecode(obj: TEncoded, context: TContext): TDecoded;\n}\n\n/**\n * Validates data complies with some particular schema.\n * Implementations are typically created by a {@link JsonValidator}.\n * @alpha\n */\nexport interface SchemaValidationFunction<Schema extends TSchema> {\n\t/**\n\t * Returns whether the data matches a schema.\n\t */\n\tcheck(data: unknown): data is Static<Schema>;\n}\n\n/**\n * JSON schema validator compliant with draft 6 schema. See https://json-schema.org.\n * @alpha\n */\nexport interface JsonValidator {\n\t/**\n\t * Compiles the provided JSON schema into a validator for that schema.\n\t * @param schema - A valid draft 6 JSON schema\n\t * @remarks IFluidHandles--which have circular property references--are used in various places in SharedTree's persisted\n\t * format. Handles should only be contained in sections of data which are validated against the empty schema `{}`\n\t * (see https://datatracker.ietf.org/doc/html/draft-wright-json-schema-01#section-4.4).\n\t *\n\t * Implementations of `JsonValidator` must therefore tolerate these values, despite the input not being valid JSON.\n\t */\n\tcompile<Schema extends TSchema>(schema: Schema): SchemaValidationFunction<Schema>;\n}\n\n/**\n * Options relating to handling of persisted data.\n * @alpha\n */\nexport interface ICodecOptions {\n\t/**\n\t * {@link JsonValidator} which SharedTree uses to validate persisted data it reads & writes\n\t * matches the expected encoded format (i.e. the wire format for ops and summaries).\n\t *\n\t * See {@link noopValidator} and {@link typeboxValidator} for out-of-the-box implementations.\n\t *\n\t * This option is not \"on-by-default\" because JSON schema validation comes with a small but noticeable\n\t * runtime performance cost, and popular schema validation libraries have relatively large bundle size.\n\t *\n\t * SharedTree users are still encouraged to use a non-trivial validator (i.e. not `noopValidator`)\n\t * whenever reasonable: it gives better fail-fast behavior when unexpected encoded data is found,\n\t * which reduces the risk of unrecoverable data corruption.\n\t */\n\treadonly jsonValidator: JsonValidator;\n}\n\n/**\n * `TContext` allows passing context to the codec which may configure how data is encoded/decoded.\n * This parameter is typically used for:\n * - Codecs which can pick from multiple encoding options, and imbue the encoded data with information about which option was used.\n * The caller of such a codec can provide context about which encoding choice to make as part of the `encode` call without creating\n * additional codecs. Note that this pattern can always be implemented by having the caller create multiple codecs and selecting the\n * appropriate one, but depending on API layering this might be less ergonomic.\n * - Context for the object currently being encoded, which might enable more efficient encoding. When used in this fashion, the codec author\n * should be careful to include the context somewhere in the encoded data such that decoding can correctly round-trip.\n * For example, a composed set of codecs could implement a form of [dictionary coding](https://en.wikipedia.org/wiki/Dictionary_coder)\n * using a context map which was created by the top-level codec and passed to the inner codecs.\n * This pattern is used:\n * - To avoid repeatedly encoding session ids on commits (only recording it once at the top level)\n * @remarks `TEncoded` should always be valid Json (i.e. not contain functions), but due to TypeScript's handling\n * of index signatures and `JsonCompatibleReadOnly`'s index signature in the Json object case, specifying this as a\n * type-system level constraint makes code that uses this interface more difficult to write.\n *\n * If provided, `TValidate` allows the input type passed to `decode` to be different than `TEncoded`.\n * This is useful when, for example, the type being decoded is `unknown` and must be validated to be a `TEncoded` before being decoded to a `TDecoded`.\n */\nexport interface IJsonCodec<\n\tTDecoded,\n\tTEncoded = JsonCompatibleReadOnly,\n\tTValidate = TEncoded,\n\tTContext = void,\n> extends IEncoder<TDecoded, TEncoded, TContext>,\n\t\tIDecoder<TDecoded, TValidate, TContext> {\n\tencodedSchema?: TAnySchema;\n}\n\n/**\n * @remarks TODO: We might consider using DataView or some kind of writer instead of IsoBuffer.\n */\nexport interface IBinaryCodec<TDecoded, TContext = void>\n\textends IEncoder<TDecoded, IsoBuffer, TContext>,\n\t\tIDecoder<TDecoded, IsoBuffer, TContext> {}\n\n/**\n * Contains knowledge of how to encode some in-memory type into JSON and binary formats,\n * as well as how to decode those representations.\n *\n * @remarks Codecs are typically used in shared-tree to convert data into some persisted format.\n * For this common use case, any format for encoding that was ever actually used needs to\n * be supported for decoding in all future code versions.\n *\n * Using an {@link ICodecFamily} is the recommended strategy for managing this support, keeping in\n * mind evolution of encodings over time.\n */\nexport interface IMultiFormatCodec<\n\tTDecoded,\n\tTJsonEncoded extends JsonCompatibleReadOnly = JsonCompatibleReadOnly,\n\tTJsonValidate = TJsonEncoded,\n\tTContext = void,\n> {\n\tjson: IJsonCodec<TDecoded, TJsonEncoded, TJsonValidate, TContext>;\n\tbinary: IBinaryCodec<TDecoded, TContext>;\n\n\t/** Ensures multi-format codecs cannot also be single-format codecs. */\n\tencode?: never;\n\t/** Ensures multi-format codecs cannot also be single-format codecs. */\n\tdecode?: never;\n}\n\n/**\n * Represents a family of codecs that can be used to encode and decode data in different formats.\n * The family is identified by a format version, which is typically used to select the codec to use.\n *\n * Separating codecs into families rather than having a single codec support multiple versions (i.e. currying\n * the `formatVersion` parameter)\n * allows avoiding some duplicate work at encode/decode time, since the vast majority of document usage will not\n * involve mixed format versions.\n *\n * @privateRemarks - This interface currently assumes all codecs in a family require the same encode/decode context,\n * which isn't necessarily true.\n * This may need to be relaxed in the future.\n */\nexport interface ICodecFamily<TDecoded, TContext = void> {\n\t/**\n\t * @returns a codec that can be used to encode and decode data in the specified format.\n\t * @throws - if the format version is not supported by this family.\n\t * @remarks Implementations should typically emit telemetry (either indirectly by throwing a well-known error with\n\t * logged properties or directly using some logger) when a format version is requested that is not supported.\n\t * This ensures that applications can diagnose compatibility issues.\n\t */\n\tresolve(\n\t\tformatVersion: FormatVersion,\n\t): IMultiFormatCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>;\n\n\t/**\n\t * @returns an iterable of all format versions supported by this family.\n\t */\n\tgetSupportedFormats(): Iterable<FormatVersion>;\n}\n\n/**\n * A version stamp for encoded data.\n *\n * Undefined is tolerated to enable the scenario where data was not initially versioned.\n */\nexport type FormatVersion = number | undefined;\n\n/**\n * Creates a codec family from a registry of codecs.\n * Any codec that is not a {@link IMultiFormatCodec} will be wrapped with a default binary encoding.\n */\nexport function makeCodecFamily<TDecoded, TContext>(\n\tregistry: Iterable<\n\t\t[\n\t\t\tformatVersion: FormatVersion,\n\t\t\tcodec:\n\t\t\t\t| IMultiFormatCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>\n\t\t\t\t| IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>,\n\t\t]\n\t>,\n): ICodecFamily<TDecoded, TContext> {\n\tconst codecs: Map<\n\t\tFormatVersion,\n\t\tIMultiFormatCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>\n\t> = new Map();\n\tfor (const [formatVersion, codec] of registry) {\n\t\tif (codecs.has(formatVersion)) {\n\t\t\tfail(\"Duplicate codecs specified.\");\n\t\t}\n\t\tcodecs.set(formatVersion, ensureBinaryEncoding(codec));\n\t}\n\n\treturn {\n\t\tresolve(\n\t\t\tformatVersion: number,\n\t\t): IMultiFormatCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext> {\n\t\t\tconst codec = codecs.get(formatVersion);\n\t\t\tassert(codec !== undefined, 0x5e6 /* Requested coded for unsupported format. */);\n\t\t\treturn codec;\n\t\t},\n\t\tgetSupportedFormats(): Iterable<FormatVersion> {\n\t\t\treturn codecs.keys();\n\t\t},\n\t};\n}\n\nclass DefaultBinaryCodec<TDecoded, TContext> implements IBinaryCodec<TDecoded, TContext> {\n\tpublic constructor(\n\t\tprivate readonly jsonCodec: IJsonCodec<TDecoded, unknown, unknown, TContext>,\n\t) {}\n\n\tpublic encode(change: TDecoded, context: TContext): IsoBuffer {\n\t\tconst jsonable = this.jsonCodec.encode(change, context);\n\t\tconst json = JSON.stringify(jsonable);\n\t\treturn IsoBuffer.from(json);\n\t}\n\n\tpublic decode(change: IsoBuffer, context: TContext): TDecoded {\n\t\tconst json = bufferToString(change, \"utf8\");\n\t\tconst jsonable = JSON.parse(json);\n\t\treturn this.jsonCodec.decode(jsonable, context);\n\t}\n}\n\nfunction isJsonCodec<TDecoded, TContext>(\n\tcodec:\n\t\t| IMultiFormatCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>\n\t\t| IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>,\n): codec is IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext> {\n\treturn typeof codec.encode === \"function\" && typeof codec.decode === \"function\";\n}\n\n/**\n * Constructs a {@link IMultiFormatCodec} from a `IJsonCodec` using a generic binary encoding that simply writes\n * the json representation of the object to a buffer.\n */\nexport function withDefaultBinaryEncoding<TDecoded, TContext>(\n\tjsonCodec: IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>,\n): IMultiFormatCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext> {\n\treturn {\n\t\tjson: jsonCodec,\n\t\tbinary: new DefaultBinaryCodec(jsonCodec),\n\t};\n}\n\n/**\n * Ensures that the provided single or multi-format codec has a binary encoding.\n * Adapts the json encoding using {@link withDefaultBinaryEncoding} if necessary.\n */\nexport function ensureBinaryEncoding<TDecoded, TContext>(\n\tcodec:\n\t\t| IMultiFormatCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>\n\t\t| IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext>,\n): IMultiFormatCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext> {\n\treturn isJsonCodec(codec) ? withDefaultBinaryEncoding(codec) : codec;\n}\n\n/**\n * Codec for objects which carry no information.\n */\nexport const unitCodec: IMultiFormatCodec<\n\t0,\n\tJsonCompatibleReadOnly,\n\tJsonCompatibleReadOnly,\n\tunknown\n> = {\n\tjson: {\n\t\tencode: () => 0,\n\t\tdecode: () => 0,\n\t},\n\tbinary: {\n\t\tencode: () => IsoBuffer.from(\"\"),\n\t\tdecode: () => 0,\n\t},\n};\n\n/**\n * Wraps a codec with JSON schema validation for its encoded type.\n * @returns An {@link IJsonCodec} which validates the data it encodes and decodes matches the provided schema.\n */\nexport function withSchemaValidation<\n\tTInMemoryFormat,\n\tEncodedSchema extends TSchema,\n\tTEncodedFormat = JsonCompatibleReadOnly,\n\tTValidate = TEncodedFormat,\n\tTContext = ChangeEncodingContext,\n>(\n\tschema: EncodedSchema,\n\tcodec: IJsonCodec<TInMemoryFormat, TEncodedFormat, TValidate, TContext>,\n\tvalidator?: JsonValidator,\n): IJsonCodec<TInMemoryFormat, TEncodedFormat, TValidate, TContext> {\n\tif (!validator) {\n\t\treturn codec;\n\t}\n\tconst compiledFormat = validator.compile(schema);\n\treturn {\n\t\tencode: (obj: TInMemoryFormat, context: TContext): TEncodedFormat => {\n\t\t\tconst encoded = codec.encode(obj, context);\n\t\t\tif (!compiledFormat.check(encoded)) {\n\t\t\t\tfail(\"Encoded schema should validate\");\n\t\t\t}\n\t\t\treturn encoded;\n\t\t},\n\t\tdecode: (encoded: TValidate, context: TContext): TInMemoryFormat => {\n\t\t\tif (!compiledFormat.check(encoded)) {\n\t\t\t\tfail(\"Encoded schema should validate\");\n\t\t\t}\n\t\t\t// TODO: would be nice to provide a more specific validate type to the inner codec than the outer one gets.\n\t\t\treturn codec.decode(encoded, context) as unknown as TInMemoryFormat;\n\t\t},\n\t};\n}\n\n/**\n * Versions of Fluid Framework client packages.\n * @remarks\n * Used to express compatibility requirements by indicating the oldest version with which compatibility must be maintained.\n * @privateRemarks\n * This scheme assumes a single version will always be enough to communicate compatibility.\n * For this to work, compatibility has to be strictly increasing.\n * If this is violated (for example a subset of incompatible features from 3.x that are not in 3.0 are back ported to 2.x),\n * a more complex scheme may be needed to allow safely opting into incompatible features in those cases:\n * such a system can be added if/when its needed since it will be opt in and thus non-breaking.\n *\n * TODO: this should likely be defined higher in the stack and specified when creating the container, possibly as part of its schema.\n * @alpha\n */\nexport enum FluidClientVersion {\n\t/** Fluid Framework Client 2.0 and newer. */\n\tv2_0 = \"v2_0\",\n\t/** Fluid Framework Client 2.1 and newer. */\n\tv2_1 = \"v2_1\",\n\t/** Fluid Framework Client 2.2 and newer. */\n\tv2_2 = \"v2_2\",\n\t/** Fluid Framework Client 2.4 and newer. */\n\tv2_3 = \"v2_3\",\n}\n"]}
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- export { type FormatVersion, type IBinaryCodec, type ICodecFamily, type ICodecOptions, type IDecoder, type IEncoder, type IJsonCodec, type IMultiFormatCodec, type JsonValidator, makeCodecFamily, type SchemaValidationFunction, unitCodec, withDefaultBinaryEncoding, withSchemaValidation, } from "./codec.js";
5
+ export { type FormatVersion, type IBinaryCodec, type ICodecFamily, type ICodecOptions, type IDecoder, type IEncoder, type IJsonCodec, type IMultiFormatCodec, type JsonValidator, makeCodecFamily, type SchemaValidationFunction, unitCodec, withDefaultBinaryEncoding, withSchemaValidation, FluidClientVersion, } from "./codec.js";
6
6
  export { DiscriminatedUnionDispatcher, type DiscriminatedUnionLibrary, unionOptions, } from "./discriminatedUnions.js";
7
7
  export { noopValidator } from "./noopValidator.js";
8
8
  export { Versioned, makeVersionedCodec, makeVersionedValidatedCodec, makeVersionDispatchingCodec, } from "./versioned/index.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/codec/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,eAAe,EACf,KAAK,wBAAwB,EAC7B,SAAS,EACT,yBAAyB,EACzB,oBAAoB,GACpB,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,4BAA4B,EAC5B,KAAK,yBAAyB,EAC9B,YAAY,GACZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACN,SAAS,EACT,kBAAkB,EAClB,2BAA2B,EAC3B,2BAA2B,GAC3B,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/codec/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,eAAe,EACf,KAAK,wBAAwB,EAC7B,SAAS,EACT,yBAAyB,EACzB,oBAAoB,EACpB,kBAAkB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,4BAA4B,EAC5B,KAAK,yBAAyB,EAC9B,YAAY,GACZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACN,SAAS,EACT,kBAAkB,EAClB,2BAA2B,EAC3B,2BAA2B,GAC3B,MAAM,sBAAsB,CAAC"}