@fluidframework/tree 2.53.0 → 2.60.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 (424) hide show
  1. package/.eslintrc.cjs +0 -19
  2. package/.mocharc.customBenchmarks.cjs +1 -9
  3. package/CHANGELOG.md +56 -0
  4. package/api-report/tree.alpha.api.md +50 -36
  5. package/api-report/tree.beta.api.md +15 -1
  6. package/api-report/{tree.legacy.alpha.api.md → tree.legacy.beta.api.md} +5 -5
  7. package/api-report/tree.legacy.public.api.md +1 -1
  8. package/api-report/tree.public.api.md +1 -1
  9. package/dist/alpha.d.ts +8 -2
  10. package/dist/beta.d.ts +3 -0
  11. package/dist/codec/codec.d.ts +43 -6
  12. package/dist/codec/codec.d.ts.map +1 -1
  13. package/dist/codec/codec.js +22 -2
  14. package/dist/codec/codec.js.map +1 -1
  15. package/dist/codec/index.d.ts +1 -1
  16. package/dist/codec/index.d.ts.map +1 -1
  17. package/dist/codec/index.js +4 -1
  18. package/dist/codec/index.js.map +1 -1
  19. package/dist/external-utilities/index.d.ts +1 -1
  20. package/dist/external-utilities/index.d.ts.map +1 -1
  21. package/dist/external-utilities/index.js +2 -1
  22. package/dist/external-utilities/index.js.map +1 -1
  23. package/dist/external-utilities/typeboxValidator.d.ts +6 -1
  24. package/dist/external-utilities/typeboxValidator.d.ts.map +1 -1
  25. package/dist/external-utilities/typeboxValidator.js +7 -1
  26. package/dist/external-utilities/typeboxValidator.js.map +1 -1
  27. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +10 -1
  28. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  29. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js +28 -5
  30. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  31. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts +19 -2
  32. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts.map +1 -1
  33. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js +10 -2
  34. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js.map +1 -1
  35. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts +59 -4
  36. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  37. package/dist/feature-libraries/chunked-forest/codec/codecs.js +9 -2
  38. package/dist/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  39. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +46 -8
  40. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
  41. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js +91 -16
  42. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  43. package/dist/feature-libraries/chunked-forest/codec/format.d.ts +14 -0
  44. package/dist/feature-libraries/chunked-forest/codec/format.d.ts.map +1 -1
  45. package/dist/feature-libraries/chunked-forest/codec/format.js +10 -1
  46. package/dist/feature-libraries/chunked-forest/codec/format.js.map +1 -1
  47. package/dist/feature-libraries/chunked-forest/codec/index.d.ts +1 -1
  48. package/dist/feature-libraries/chunked-forest/codec/index.d.ts.map +1 -1
  49. package/dist/feature-libraries/chunked-forest/codec/index.js.map +1 -1
  50. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts +8 -3
  51. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts.map +1 -1
  52. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.js +17 -6
  53. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.js.map +1 -1
  54. package/dist/feature-libraries/chunked-forest/index.d.ts +1 -1
  55. package/dist/feature-libraries/chunked-forest/index.d.ts.map +1 -1
  56. package/dist/feature-libraries/chunked-forest/index.js.map +1 -1
  57. package/dist/feature-libraries/forest-summary/codec.d.ts.map +1 -1
  58. package/dist/feature-libraries/forest-summary/codec.js +3 -0
  59. package/dist/feature-libraries/forest-summary/codec.js.map +1 -1
  60. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts +13 -8
  61. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  62. package/dist/feature-libraries/forest-summary/forestSummarizer.js +76 -38
  63. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  64. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +178 -0
  65. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -0
  66. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js +322 -0
  67. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -0
  68. package/dist/feature-libraries/forest-summary/index.d.ts +1 -1
  69. package/dist/feature-libraries/forest-summary/index.d.ts.map +1 -1
  70. package/dist/feature-libraries/forest-summary/index.js +2 -1
  71. package/dist/feature-libraries/forest-summary/index.js.map +1 -1
  72. package/dist/feature-libraries/index.d.ts +1 -1
  73. package/dist/feature-libraries/index.d.ts.map +1 -1
  74. package/dist/feature-libraries/index.js +2 -1
  75. package/dist/feature-libraries/index.js.map +1 -1
  76. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts +2 -2
  77. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  78. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +1 -1
  79. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  80. package/dist/feature-libraries/modular-schema/modularChangeFormat.d.ts +6 -9
  81. package/dist/feature-libraries/modular-schema/modularChangeFormat.d.ts.map +1 -1
  82. package/dist/feature-libraries/treeCompressionUtils.d.ts +15 -0
  83. package/dist/feature-libraries/treeCompressionUtils.d.ts.map +1 -1
  84. package/dist/feature-libraries/treeCompressionUtils.js +16 -1
  85. package/dist/feature-libraries/treeCompressionUtils.js.map +1 -1
  86. package/dist/index.d.ts +3 -3
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.js +6 -2
  89. package/dist/index.js.map +1 -1
  90. package/dist/jsonDomainSchema.d.ts +1 -1
  91. package/dist/jsonDomainSchema.d.ts.map +1 -1
  92. package/dist/packageVersion.d.ts +1 -1
  93. package/dist/packageVersion.js +1 -1
  94. package/dist/packageVersion.js.map +1 -1
  95. package/dist/shared-tree/schematizingTreeView.d.ts +1 -1
  96. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  97. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  98. package/dist/shared-tree/sharedTree.d.ts +23 -6
  99. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  100. package/dist/shared-tree/sharedTree.js +4 -1
  101. package/dist/shared-tree/sharedTree.js.map +1 -1
  102. package/dist/shared-tree/sharedTreeChangeFamily.d.ts +2 -2
  103. package/dist/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  104. package/dist/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  105. package/dist/shared-tree/tree.d.ts.map +1 -1
  106. package/dist/shared-tree/tree.js +3 -0
  107. package/dist/shared-tree/tree.js.map +1 -1
  108. package/dist/shared-tree/treeAlpha.d.ts +9 -11
  109. package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
  110. package/dist/shared-tree/treeAlpha.js.map +1 -1
  111. package/dist/shared-tree/treeCheckout.d.ts +2 -2
  112. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  113. package/dist/shared-tree/treeCheckout.js.map +1 -1
  114. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  115. package/dist/shared-tree-core/sharedTreeCore.js +13 -0
  116. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  117. package/dist/sharedTreeAttributes.d.ts +2 -2
  118. package/dist/sharedTreeAttributes.js +2 -2
  119. package/dist/sharedTreeAttributes.js.map +1 -1
  120. package/dist/simple-tree/api/conciseTree.d.ts.map +1 -1
  121. package/dist/simple-tree/api/conciseTree.js +1 -1
  122. package/dist/simple-tree/api/conciseTree.js.map +1 -1
  123. package/dist/simple-tree/api/customTree.d.ts +39 -11
  124. package/dist/simple-tree/api/customTree.d.ts.map +1 -1
  125. package/dist/simple-tree/api/customTree.js +79 -19
  126. package/dist/simple-tree/api/customTree.js.map +1 -1
  127. package/dist/simple-tree/api/getJsonSchema.d.ts +7 -2
  128. package/dist/simple-tree/api/getJsonSchema.d.ts.map +1 -1
  129. package/dist/simple-tree/api/getJsonSchema.js +1 -0
  130. package/dist/simple-tree/api/getJsonSchema.js.map +1 -1
  131. package/dist/simple-tree/api/index.d.ts +2 -1
  132. package/dist/simple-tree/api/index.d.ts.map +1 -1
  133. package/dist/simple-tree/api/index.js +4 -1
  134. package/dist/simple-tree/api/index.js.map +1 -1
  135. package/dist/simple-tree/api/schemaCreationUtilities.d.ts +1 -1
  136. package/dist/simple-tree/api/schemaCreationUtilities.js +1 -1
  137. package/dist/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  138. package/dist/simple-tree/api/schemaFactory.d.ts +9 -6
  139. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  140. package/dist/simple-tree/api/schemaFactory.js +8 -7
  141. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  142. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +13 -17
  143. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
  144. package/dist/simple-tree/api/schemaFactoryAlpha.js +21 -25
  145. package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
  146. package/dist/simple-tree/api/schemaFactoryBeta.d.ts +20 -0
  147. package/dist/simple-tree/api/schemaFactoryBeta.d.ts.map +1 -0
  148. package/dist/simple-tree/api/schemaFactoryBeta.js +26 -0
  149. package/dist/simple-tree/api/schemaFactoryBeta.js.map +1 -0
  150. package/dist/simple-tree/api/simpleSchemaToJsonSchema.d.ts +0 -2
  151. package/dist/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -1
  152. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +6 -3
  153. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  154. package/dist/simple-tree/api/transactionTypes.d.ts +1 -0
  155. package/dist/simple-tree/api/transactionTypes.d.ts.map +1 -1
  156. package/dist/simple-tree/api/transactionTypes.js.map +1 -1
  157. package/dist/simple-tree/api/tree.d.ts +68 -74
  158. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  159. package/dist/simple-tree/api/tree.js.map +1 -1
  160. package/dist/simple-tree/api/verboseTree.d.ts.map +1 -1
  161. package/dist/simple-tree/api/verboseTree.js +3 -3
  162. package/dist/simple-tree/api/verboseTree.js.map +1 -1
  163. package/dist/simple-tree/core/simpleNodeSchemaBase.d.ts +6 -0
  164. package/dist/simple-tree/core/simpleNodeSchemaBase.d.ts.map +1 -1
  165. package/dist/simple-tree/core/simpleNodeSchemaBase.js.map +1 -1
  166. package/dist/simple-tree/fieldSchema.d.ts +3 -4
  167. package/dist/simple-tree/fieldSchema.d.ts.map +1 -1
  168. package/dist/simple-tree/fieldSchema.js +0 -3
  169. package/dist/simple-tree/fieldSchema.js.map +1 -1
  170. package/dist/simple-tree/index.d.ts +1 -1
  171. package/dist/simple-tree/index.d.ts.map +1 -1
  172. package/dist/simple-tree/index.js +4 -2
  173. package/dist/simple-tree/index.js.map +1 -1
  174. package/dist/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
  175. package/dist/simple-tree/node-kinds/record/recordNode.js +2 -3
  176. package/dist/simple-tree/node-kinds/record/recordNode.js.map +1 -1
  177. package/dist/simple-tree/simpleSchema.d.ts +12 -0
  178. package/dist/simple-tree/simpleSchema.d.ts.map +1 -1
  179. package/dist/simple-tree/simpleSchema.js.map +1 -1
  180. package/dist/simple-tree/toStoredSchema.d.ts +0 -3
  181. package/dist/simple-tree/toStoredSchema.d.ts.map +1 -1
  182. package/dist/simple-tree/toStoredSchema.js +0 -3
  183. package/dist/simple-tree/toStoredSchema.js.map +1 -1
  184. package/dist/tableSchema.d.ts +11 -80
  185. package/dist/tableSchema.d.ts.map +1 -1
  186. package/dist/tableSchema.js +200 -117
  187. package/dist/tableSchema.js.map +1 -1
  188. package/dist/treeFactory.d.ts +1 -2
  189. package/dist/treeFactory.d.ts.map +1 -1
  190. package/dist/treeFactory.js +1 -2
  191. package/dist/treeFactory.js.map +1 -1
  192. package/lib/alpha.d.ts +8 -2
  193. package/lib/beta.d.ts +3 -0
  194. package/lib/codec/codec.d.ts +43 -6
  195. package/lib/codec/codec.d.ts.map +1 -1
  196. package/lib/codec/codec.js +19 -1
  197. package/lib/codec/codec.js.map +1 -1
  198. package/lib/codec/index.d.ts +1 -1
  199. package/lib/codec/index.d.ts.map +1 -1
  200. package/lib/codec/index.js +1 -1
  201. package/lib/codec/index.js.map +1 -1
  202. package/lib/external-utilities/index.d.ts +1 -1
  203. package/lib/external-utilities/index.d.ts.map +1 -1
  204. package/lib/external-utilities/index.js +1 -1
  205. package/lib/external-utilities/index.js.map +1 -1
  206. package/lib/external-utilities/typeboxValidator.d.ts +6 -1
  207. package/lib/external-utilities/typeboxValidator.d.ts.map +1 -1
  208. package/lib/external-utilities/typeboxValidator.js +6 -0
  209. package/lib/external-utilities/typeboxValidator.js.map +1 -1
  210. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +10 -1
  211. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  212. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js +27 -5
  213. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  214. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts +19 -2
  215. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts.map +1 -1
  216. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js +10 -2
  217. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js.map +1 -1
  218. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts +59 -4
  219. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  220. package/lib/feature-libraries/chunked-forest/codec/codecs.js +10 -3
  221. package/lib/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  222. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +46 -8
  223. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
  224. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js +87 -14
  225. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  226. package/lib/feature-libraries/chunked-forest/codec/format.d.ts +14 -0
  227. package/lib/feature-libraries/chunked-forest/codec/format.d.ts.map +1 -1
  228. package/lib/feature-libraries/chunked-forest/codec/format.js +9 -0
  229. package/lib/feature-libraries/chunked-forest/codec/format.js.map +1 -1
  230. package/lib/feature-libraries/chunked-forest/codec/index.d.ts +1 -1
  231. package/lib/feature-libraries/chunked-forest/codec/index.d.ts.map +1 -1
  232. package/lib/feature-libraries/chunked-forest/codec/index.js.map +1 -1
  233. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts +8 -3
  234. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts.map +1 -1
  235. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.js +18 -7
  236. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.js.map +1 -1
  237. package/lib/feature-libraries/chunked-forest/index.d.ts +1 -1
  238. package/lib/feature-libraries/chunked-forest/index.d.ts.map +1 -1
  239. package/lib/feature-libraries/chunked-forest/index.js.map +1 -1
  240. package/lib/feature-libraries/forest-summary/codec.d.ts.map +1 -1
  241. package/lib/feature-libraries/forest-summary/codec.js +3 -0
  242. package/lib/feature-libraries/forest-summary/codec.js.map +1 -1
  243. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts +13 -8
  244. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  245. package/lib/feature-libraries/forest-summary/forestSummarizer.js +75 -37
  246. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  247. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +178 -0
  248. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -0
  249. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js +318 -0
  250. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -0
  251. package/lib/feature-libraries/forest-summary/index.d.ts +1 -1
  252. package/lib/feature-libraries/forest-summary/index.d.ts.map +1 -1
  253. package/lib/feature-libraries/forest-summary/index.js +1 -1
  254. package/lib/feature-libraries/forest-summary/index.js.map +1 -1
  255. package/lib/feature-libraries/index.d.ts +1 -1
  256. package/lib/feature-libraries/index.d.ts.map +1 -1
  257. package/lib/feature-libraries/index.js +1 -1
  258. package/lib/feature-libraries/index.js.map +1 -1
  259. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts +2 -2
  260. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  261. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +3 -3
  262. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  263. package/lib/feature-libraries/modular-schema/modularChangeFormat.d.ts +6 -9
  264. package/lib/feature-libraries/modular-schema/modularChangeFormat.d.ts.map +1 -1
  265. package/lib/feature-libraries/treeCompressionUtils.d.ts +15 -0
  266. package/lib/feature-libraries/treeCompressionUtils.d.ts.map +1 -1
  267. package/lib/feature-libraries/treeCompressionUtils.js +15 -0
  268. package/lib/feature-libraries/treeCompressionUtils.js.map +1 -1
  269. package/lib/index.d.ts +3 -3
  270. package/lib/index.d.ts.map +1 -1
  271. package/lib/index.js +4 -4
  272. package/lib/index.js.map +1 -1
  273. package/lib/jsonDomainSchema.d.ts +1 -1
  274. package/lib/jsonDomainSchema.d.ts.map +1 -1
  275. package/lib/packageVersion.d.ts +1 -1
  276. package/lib/packageVersion.js +1 -1
  277. package/lib/packageVersion.js.map +1 -1
  278. package/lib/shared-tree/schematizingTreeView.d.ts +1 -1
  279. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  280. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  281. package/lib/shared-tree/sharedTree.d.ts +23 -6
  282. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  283. package/lib/shared-tree/sharedTree.js +4 -1
  284. package/lib/shared-tree/sharedTree.js.map +1 -1
  285. package/lib/shared-tree/sharedTreeChangeFamily.d.ts +2 -2
  286. package/lib/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  287. package/lib/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  288. package/lib/shared-tree/tree.d.ts.map +1 -1
  289. package/lib/shared-tree/tree.js +3 -0
  290. package/lib/shared-tree/tree.js.map +1 -1
  291. package/lib/shared-tree/treeAlpha.d.ts +9 -11
  292. package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
  293. package/lib/shared-tree/treeAlpha.js.map +1 -1
  294. package/lib/shared-tree/treeCheckout.d.ts +2 -2
  295. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  296. package/lib/shared-tree/treeCheckout.js.map +1 -1
  297. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  298. package/lib/shared-tree-core/sharedTreeCore.js +13 -0
  299. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  300. package/lib/sharedTreeAttributes.d.ts +2 -2
  301. package/lib/sharedTreeAttributes.js +2 -2
  302. package/lib/sharedTreeAttributes.js.map +1 -1
  303. package/lib/simple-tree/api/conciseTree.d.ts.map +1 -1
  304. package/lib/simple-tree/api/conciseTree.js +2 -2
  305. package/lib/simple-tree/api/conciseTree.js.map +1 -1
  306. package/lib/simple-tree/api/customTree.d.ts +39 -11
  307. package/lib/simple-tree/api/customTree.d.ts.map +1 -1
  308. package/lib/simple-tree/api/customTree.js +79 -19
  309. package/lib/simple-tree/api/customTree.js.map +1 -1
  310. package/lib/simple-tree/api/getJsonSchema.d.ts +7 -2
  311. package/lib/simple-tree/api/getJsonSchema.d.ts.map +1 -1
  312. package/lib/simple-tree/api/getJsonSchema.js +1 -0
  313. package/lib/simple-tree/api/getJsonSchema.js.map +1 -1
  314. package/lib/simple-tree/api/index.d.ts +2 -1
  315. package/lib/simple-tree/api/index.d.ts.map +1 -1
  316. package/lib/simple-tree/api/index.js +2 -1
  317. package/lib/simple-tree/api/index.js.map +1 -1
  318. package/lib/simple-tree/api/schemaCreationUtilities.d.ts +1 -1
  319. package/lib/simple-tree/api/schemaCreationUtilities.js +1 -1
  320. package/lib/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  321. package/lib/simple-tree/api/schemaFactory.d.ts +9 -6
  322. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  323. package/lib/simple-tree/api/schemaFactory.js +6 -6
  324. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  325. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +13 -17
  326. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
  327. package/lib/simple-tree/api/schemaFactoryAlpha.js +22 -26
  328. package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
  329. package/lib/simple-tree/api/schemaFactoryBeta.d.ts +20 -0
  330. package/lib/simple-tree/api/schemaFactoryBeta.d.ts.map +1 -0
  331. package/lib/simple-tree/api/schemaFactoryBeta.js +22 -0
  332. package/lib/simple-tree/api/schemaFactoryBeta.js.map +1 -0
  333. package/lib/simple-tree/api/simpleSchemaToJsonSchema.d.ts +0 -2
  334. package/lib/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -1
  335. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +6 -3
  336. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  337. package/lib/simple-tree/api/transactionTypes.d.ts +1 -0
  338. package/lib/simple-tree/api/transactionTypes.d.ts.map +1 -1
  339. package/lib/simple-tree/api/transactionTypes.js.map +1 -1
  340. package/lib/simple-tree/api/tree.d.ts +68 -74
  341. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  342. package/lib/simple-tree/api/tree.js.map +1 -1
  343. package/lib/simple-tree/api/verboseTree.d.ts.map +1 -1
  344. package/lib/simple-tree/api/verboseTree.js +4 -4
  345. package/lib/simple-tree/api/verboseTree.js.map +1 -1
  346. package/lib/simple-tree/core/simpleNodeSchemaBase.d.ts +6 -0
  347. package/lib/simple-tree/core/simpleNodeSchemaBase.d.ts.map +1 -1
  348. package/lib/simple-tree/core/simpleNodeSchemaBase.js.map +1 -1
  349. package/lib/simple-tree/fieldSchema.d.ts +3 -4
  350. package/lib/simple-tree/fieldSchema.d.ts.map +1 -1
  351. package/lib/simple-tree/fieldSchema.js +0 -3
  352. package/lib/simple-tree/fieldSchema.js.map +1 -1
  353. package/lib/simple-tree/index.d.ts +1 -1
  354. package/lib/simple-tree/index.d.ts.map +1 -1
  355. package/lib/simple-tree/index.js +1 -1
  356. package/lib/simple-tree/index.js.map +1 -1
  357. package/lib/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
  358. package/lib/simple-tree/node-kinds/record/recordNode.js +2 -3
  359. package/lib/simple-tree/node-kinds/record/recordNode.js.map +1 -1
  360. package/lib/simple-tree/simpleSchema.d.ts +12 -0
  361. package/lib/simple-tree/simpleSchema.d.ts.map +1 -1
  362. package/lib/simple-tree/simpleSchema.js.map +1 -1
  363. package/lib/simple-tree/toStoredSchema.d.ts +0 -3
  364. package/lib/simple-tree/toStoredSchema.d.ts.map +1 -1
  365. package/lib/simple-tree/toStoredSchema.js +0 -3
  366. package/lib/simple-tree/toStoredSchema.js.map +1 -1
  367. package/lib/tableSchema.d.ts +11 -80
  368. package/lib/tableSchema.d.ts.map +1 -1
  369. package/lib/tableSchema.js +201 -118
  370. package/lib/tableSchema.js.map +1 -1
  371. package/lib/treeFactory.d.ts +1 -2
  372. package/lib/treeFactory.d.ts.map +1 -1
  373. package/lib/treeFactory.js +1 -2
  374. package/lib/treeFactory.js.map +1 -1
  375. package/package.json +22 -22
  376. package/src/codec/codec.ts +52 -7
  377. package/src/codec/index.ts +4 -0
  378. package/src/external-utilities/index.ts +1 -1
  379. package/src/external-utilities/typeboxValidator.ts +7 -1
  380. package/src/feature-libraries/chunked-forest/codec/chunkDecoding.ts +38 -4
  381. package/src/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.ts +10 -3
  382. package/src/feature-libraries/chunked-forest/codec/codecs.ts +96 -8
  383. package/src/feature-libraries/chunked-forest/codec/compressedEncode.ts +123 -19
  384. package/src/feature-libraries/chunked-forest/codec/format.ts +11 -0
  385. package/src/feature-libraries/chunked-forest/codec/index.ts +4 -0
  386. package/src/feature-libraries/chunked-forest/codec/schemaBasedEncode.ts +28 -3
  387. package/src/feature-libraries/chunked-forest/index.ts +2 -0
  388. package/src/feature-libraries/forest-summary/codec.ts +3 -0
  389. package/src/feature-libraries/forest-summary/forestSummarizer.ts +118 -50
  390. package/src/feature-libraries/forest-summary/incrementalSummaryBuilder.ts +511 -0
  391. package/src/feature-libraries/forest-summary/index.ts +1 -1
  392. package/src/feature-libraries/index.ts +5 -1
  393. package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +8 -4
  394. package/src/feature-libraries/treeCompressionUtils.ts +19 -0
  395. package/src/index.ts +6 -1
  396. package/src/packageVersion.ts +1 -1
  397. package/src/shared-tree/schematizingTreeView.ts +1 -1
  398. package/src/shared-tree/sharedTree.ts +37 -4
  399. package/src/shared-tree/sharedTreeChangeFamily.ts +2 -2
  400. package/src/shared-tree/tree.ts +3 -0
  401. package/src/shared-tree/treeAlpha.ts +10 -11
  402. package/src/shared-tree/treeCheckout.ts +2 -2
  403. package/src/shared-tree-core/sharedTreeCore.ts +17 -0
  404. package/src/sharedTreeAttributes.ts +2 -2
  405. package/src/simple-tree/api/conciseTree.ts +2 -1
  406. package/src/simple-tree/api/customTree.ts +102 -32
  407. package/src/simple-tree/api/getJsonSchema.ts +7 -2
  408. package/src/simple-tree/api/index.ts +3 -0
  409. package/src/simple-tree/api/schemaCreationUtilities.ts +1 -1
  410. package/src/simple-tree/api/schemaFactory.ts +21 -14
  411. package/src/simple-tree/api/schemaFactoryAlpha.ts +29 -30
  412. package/src/simple-tree/api/schemaFactoryBeta.ts +28 -0
  413. package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +7 -3
  414. package/src/simple-tree/api/transactionTypes.ts +1 -0
  415. package/src/simple-tree/api/tree.ts +75 -81
  416. package/src/simple-tree/api/verboseTree.ts +42 -39
  417. package/src/simple-tree/core/simpleNodeSchemaBase.ts +6 -0
  418. package/src/simple-tree/fieldSchema.ts +3 -4
  419. package/src/simple-tree/index.ts +3 -0
  420. package/src/simple-tree/node-kinds/record/recordNode.ts +2 -3
  421. package/src/simple-tree/simpleSchema.ts +12 -0
  422. package/src/simple-tree/toStoredSchema.ts +0 -3
  423. package/src/tableSchema.ts +261 -243
  424. package/src/treeFactory.ts +1 -2
@@ -2,13 +2,13 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { customFromCursor, replaceHandles, } from "./customTree.js";
5
+ import { customFromCursor, replaceHandles, KeyEncodingOptions, } from "./customTree.js";
6
6
  /**
7
7
  * Used to read a node cursor as a ConciseTree.
8
8
  */
9
9
  export function conciseFromCursor(reader, context, options) {
10
10
  const config = {
11
- useStoredKeys: false,
11
+ keys: KeyEncodingOptions.usePropertyKeys,
12
12
  ...options,
13
13
  };
14
14
  const storedSchemaMap = context.flexContext.schema.nodeSchema;
@@ -1 +1 @@
1
- {"version":3,"file":"conciseTree.js","sourceRoot":"","sources":["../../../src/simple-tree/api/conciseTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EACN,gBAAgB,EAChB,cAAc,GAGd,MAAM,iBAAiB,CAAC;AAwBzB;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAChC,MAAmB,EACnB,OAAgB,EAChB,OAA4B;IAE5B,MAAM,MAAM,GAAkC;QAC7C,aAAa,EAAE,KAAK;QACpB,GAAG,OAAO;KACV,CAAC;IAEF,MAAM,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC;IAC9D,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IAEjC,OAAO,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,sBAAsB,CAC9B,MAAmB,EACnB,OAAsC,EACtC,YAAuD,EACvD,MAA2C;IAE3C,OAAO,gBAAgB,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,sBAAsB,CAAC,CAAC;AACxF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACxC,IAAiB,EACjB,QAA4B;IAE5B,OAAO,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAmB,CAAC;AACzD,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidHandle } from \"@fluidframework/core-interfaces\";\n\nimport type { ITreeCursor, TreeNodeStoredSchema } from \"../../core/index.js\";\nimport type { TreeNodeSchema, TreeLeafValue, Context } from \"../core/index.js\";\n\nimport {\n\tcustomFromCursor,\n\treplaceHandles,\n\ttype TreeEncodingOptions,\n\ttype HandleConverter,\n} from \"./customTree.js\";\n\n/**\n * Concise encoding of a {@link TreeNode} or {@link TreeLeafValue}.\n * @remarks\n * This is \"concise\" meaning that explicit type information is omitted.\n * If the schema is compatible with {@link ITreeConfigurationOptions.preventAmbiguity},\n * types will be lossless and compatible with {@link (TreeAlpha:interface).create} (unless the options are used to customize it).\n *\n * Every {@link TreeNode} is an array or object.\n * Any IFluidHandle values have been replaced by `THandle`.\n * @privateRemarks\n * This can store all possible simple trees,\n * but it can not store all possible trees representable by our internal representations like FlexTree and JsonableTree.\n * @alpha\n */\nexport type ConciseTree<THandle = IFluidHandle> =\n\t| Exclude<TreeLeafValue, IFluidHandle>\n\t| THandle\n\t| ConciseTree<THandle>[]\n\t| {\n\t\t\t[key: string]: ConciseTree<THandle>;\n\t };\n\n/**\n * Used to read a node cursor as a ConciseTree.\n */\nexport function conciseFromCursor(\n\treader: ITreeCursor,\n\tcontext: Context,\n\toptions: TreeEncodingOptions,\n): ConciseTree {\n\tconst config: Required<TreeEncodingOptions> = {\n\t\tuseStoredKeys: false,\n\t\t...options,\n\t};\n\n\tconst storedSchemaMap = context.flexContext.schema.nodeSchema;\n\tconst schemaMap = context.schema;\n\n\treturn conciseFromCursorInner(reader, config, storedSchemaMap, schemaMap);\n}\n\nfunction conciseFromCursorInner(\n\treader: ITreeCursor,\n\toptions: Required<TreeEncodingOptions>,\n\tstoredSchema: ReadonlyMap<string, TreeNodeStoredSchema>,\n\tschema: ReadonlyMap<string, TreeNodeSchema>,\n): ConciseTree {\n\treturn customFromCursor(reader, options, storedSchema, schema, conciseFromCursorInner);\n}\n\n/**\n * Clones tree, replacing any handles.\n * @remarks A strongly typed version of {@link replaceHandles}.\n * @alpha\n */\nexport function replaceConciseTreeHandles<T>(\n\ttree: ConciseTree,\n\treplacer: HandleConverter<T>,\n): ConciseTree<T> {\n\treturn replaceHandles(tree, replacer) as ConciseTree<T>;\n}\n"]}
1
+ {"version":3,"file":"conciseTree.js","sourceRoot":"","sources":["../../../src/simple-tree/api/conciseTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EACN,gBAAgB,EAChB,cAAc,EAGd,kBAAkB,GAClB,MAAM,iBAAiB,CAAC;AAwBzB;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAChC,MAAmB,EACnB,OAAgB,EAChB,OAA4B;IAE5B,MAAM,MAAM,GAAkC;QAC7C,IAAI,EAAE,kBAAkB,CAAC,eAAe;QACxC,GAAG,OAAO;KACV,CAAC;IAEF,MAAM,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC;IAC9D,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IAEjC,OAAO,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,sBAAsB,CAC9B,MAAmB,EACnB,OAAsC,EACtC,YAAuD,EACvD,MAA2C;IAE3C,OAAO,gBAAgB,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,sBAAsB,CAAC,CAAC;AACxF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACxC,IAAiB,EACjB,QAA4B;IAE5B,OAAO,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAmB,CAAC;AACzD,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidHandle } from \"@fluidframework/core-interfaces\";\n\nimport type { ITreeCursor, TreeNodeStoredSchema } from \"../../core/index.js\";\nimport type { TreeNodeSchema, TreeLeafValue, Context } from \"../core/index.js\";\n\nimport {\n\tcustomFromCursor,\n\treplaceHandles,\n\ttype TreeEncodingOptions,\n\ttype HandleConverter,\n\tKeyEncodingOptions,\n} from \"./customTree.js\";\n\n/**\n * Concise encoding of a {@link TreeNode} or {@link TreeLeafValue}.\n * @remarks\n * This is \"concise\" meaning that explicit type information is omitted.\n * If the schema is compatible with {@link ITreeConfigurationOptions.preventAmbiguity},\n * types will be lossless and compatible with {@link (TreeAlpha:interface).create} (unless the options are used to customize it).\n *\n * Every {@link TreeNode} is an array or object.\n * Any IFluidHandle values have been replaced by `THandle`.\n * @privateRemarks\n * This can store all possible simple trees,\n * but it can not store all possible trees representable by our internal representations like FlexTree and JsonableTree.\n * @alpha\n */\nexport type ConciseTree<THandle = IFluidHandle> =\n\t| Exclude<TreeLeafValue, IFluidHandle>\n\t| THandle\n\t| ConciseTree<THandle>[]\n\t| {\n\t\t\t[key: string]: ConciseTree<THandle>;\n\t };\n\n/**\n * Used to read a node cursor as a ConciseTree.\n */\nexport function conciseFromCursor(\n\treader: ITreeCursor,\n\tcontext: Context,\n\toptions: TreeEncodingOptions,\n): ConciseTree {\n\tconst config: Required<TreeEncodingOptions> = {\n\t\tkeys: KeyEncodingOptions.usePropertyKeys,\n\t\t...options,\n\t};\n\n\tconst storedSchemaMap = context.flexContext.schema.nodeSchema;\n\tconst schemaMap = context.schema;\n\n\treturn conciseFromCursorInner(reader, config, storedSchemaMap, schemaMap);\n}\n\nfunction conciseFromCursorInner(\n\treader: ITreeCursor,\n\toptions: Required<TreeEncodingOptions>,\n\tstoredSchema: ReadonlyMap<string, TreeNodeStoredSchema>,\n\tschema: ReadonlyMap<string, TreeNodeSchema>,\n): ConciseTree {\n\treturn customFromCursor(reader, options, storedSchema, schema, conciseFromCursorInner);\n}\n\n/**\n * Clones tree, replacing any handles.\n * @remarks A strongly typed version of {@link replaceHandles}.\n * @alpha\n */\nexport function replaceConciseTreeHandles<T>(\n\ttree: ConciseTree,\n\treplacer: HandleConverter<T>,\n): ConciseTree<T> {\n\treturn replaceHandles(tree, replacer) as ConciseTree<T>;\n}\n"]}
@@ -8,24 +8,52 @@ import type { TreeNodeSchema, TreeLeafValue } from "../core/index.js";
8
8
  /**
9
9
  * Options for how to interpret or encode a tree when schema information is available.
10
10
  * @alpha
11
+ * @input
11
12
  */
12
- export interface TreeEncodingOptions {
13
+ export interface TreeEncodingOptions<TKeyOptions = KeyEncodingOptions> {
13
14
  /**
14
- * If true, use the stored keys of object nodes.
15
- * If false, use the property keys.
15
+ * How to handle field keys.
16
16
  * @remarks
17
17
  * Has no effect on {@link NodeKind}s other than {@link NodeKind.Object}.
18
18
  *
19
19
  * {@link SchemaFactoryObjectOptions.allowUnknownOptionalFields|Unknown optional field} will be omitted when using property keys.
20
- * @defaultValue false.
21
- * @privateRemarks
22
- * TODO AB#43548:
23
- * Replace this with an enum that provides three options:
24
- * - `usePropertyKeys`: use property keys. Supported for import and export.
25
- * - `allStoredKeys`: use stored keys, and include unknown optional fields. Supported for export only, at least for the short term.
26
- * - `knownStoredKeys`: use stored keys but do not include unknown optional fields. Supported for import and export.
20
+ * @defaultValue {@link KeyEncodingOptions.usePropertyKeys}.
27
21
  */
28
- readonly useStoredKeys?: boolean;
22
+ readonly keys?: TKeyOptions;
23
+ }
24
+ /**
25
+ * Options for how to interpret a tree when schema information is available.
26
+ * @alpha
27
+ * @input
28
+ */
29
+ export type TreeParsingOptions = TreeEncodingOptions<KeyEncodingOptions.usePropertyKeys | KeyEncodingOptions.knownStoredKeys>;
30
+ /**
31
+ * Options for how to encode keys in a tree.
32
+ * @alpha
33
+ * @input
34
+ */
35
+ export declare enum KeyEncodingOptions {
36
+ /**
37
+ * Use property keys.
38
+ * @remarks
39
+ * Supported for import and export.
40
+ * {@link SchemaFactoryObjectOptions.allowUnknownOptionalFields|Unknown optional fields} will be omitted when using property keys.
41
+ */
42
+ usePropertyKeys = "usePropertyKeys",
43
+ /**
44
+ * Use stored keys, and include {@link SchemaFactoryObjectOptions.allowUnknownOptionalFields|Unknown optional fields}.
45
+ * @remarks
46
+ * Currently only supported for export.
47
+ */
48
+ allStoredKeys = "allStoredKeys",
49
+ /**
50
+ * Use stored keys but do not include {@link SchemaFactoryObjectOptions.allowUnknownOptionalFields|Unknown optional fields}.
51
+ * @remarks
52
+ * Supported for import and export.
53
+ * For export, this omits unknown optional fields.
54
+ * For import, any unexpected fields are errors, regardless of {@link SchemaFactoryObjectOptions.allowUnknownOptionalFields}.
55
+ */
56
+ knownStoredKeys = "knownStoredKeys"
29
57
  }
30
58
  /**
31
59
  * Options for how to interpret a `ConciseTree<TCustom>` without relying on schema.
@@ -1 +1 @@
1
- {"version":3,"file":"customTree.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/customTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAKp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Y,EAAE,WAAW,CAAC,MAAM,EAAE,oBAAoB,CAAC,EACvD,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,KACvC,MAAM,GACT,UAAU,CAAC,MAAM,CAAC,CA6CpB;AAuDD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAC5C,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,WAAW,CAAC,wBAAwB,EAAE,oBAAoB,CAAC,EACnE,YAAY,EAAE,CACb,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,WAAW,CAAC,wBAAwB,EAAE,oBAAoB,CAAC,KAC/D,MAAM,GACT,UAAU,CAAC,MAAM,CAAC,CAgCpB;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,oBAAoB,GAAG,WAAW,GAAG,SAAS,CAU5F;AAED;;;;;GAKG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,IAAI,CAAC,IAAI,EAAE,YAAY,KAAK,OAAO,CAAC;AAEvE;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,OAAO,CAStF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAIpD"}
@@ -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
- import { assert, fail } from "@fluidframework/core-utils/internal";
5
+ import { assert, fail, unreachableCase } from "@fluidframework/core-utils/internal";
6
6
  import { isFluidHandle } from "@fluidframework/runtime-utils/internal";
7
7
  import { UsageError } from "@fluidframework/telemetry-utils/internal";
8
8
  import { EmptyKey, forEachField, inCursorField, LeafNodeStoredSchema, mapCursorField, ObjectNodeStoredSchema, } from "../../core/index.js";
@@ -10,6 +10,35 @@ import { FieldKinds, valueSchemaAllows } from "../../feature-libraries/index.js"
10
10
  import { cloneWithReplacements } from "../../util/index.js";
11
11
  import { booleanSchema, handleSchema, nullSchema, numberSchema, stringSchema, } from "../leafNodeSchema.js";
12
12
  import { isObjectNodeSchema } from "../node-kinds/index.js";
13
+ /**
14
+ * Options for how to encode keys in a tree.
15
+ * @alpha
16
+ * @input
17
+ */
18
+ export var KeyEncodingOptions;
19
+ (function (KeyEncodingOptions) {
20
+ /**
21
+ * Use property keys.
22
+ * @remarks
23
+ * Supported for import and export.
24
+ * {@link SchemaFactoryObjectOptions.allowUnknownOptionalFields|Unknown optional fields} will be omitted when using property keys.
25
+ */
26
+ KeyEncodingOptions["usePropertyKeys"] = "usePropertyKeys";
27
+ /**
28
+ * Use stored keys, and include {@link SchemaFactoryObjectOptions.allowUnknownOptionalFields|Unknown optional fields}.
29
+ * @remarks
30
+ * Currently only supported for export.
31
+ */
32
+ KeyEncodingOptions["allStoredKeys"] = "allStoredKeys";
33
+ /**
34
+ * Use stored keys but do not include {@link SchemaFactoryObjectOptions.allowUnknownOptionalFields|Unknown optional fields}.
35
+ * @remarks
36
+ * Supported for import and export.
37
+ * For export, this omits unknown optional fields.
38
+ * For import, any unexpected fields are errors, regardless of {@link SchemaFactoryObjectOptions.allowUnknownOptionalFields}.
39
+ */
40
+ KeyEncodingOptions["knownStoredKeys"] = "knownStoredKeys";
41
+ })(KeyEncodingOptions || (KeyEncodingOptions = {}));
13
42
  /**
14
43
  * Builds an {@link CustomTree} from a cursor in Nodes mode.
15
44
  *
@@ -51,24 +80,10 @@ export function customFromCursor(reader, options, storedSchema, schema, childHan
51
80
  forEachField(reader, () => {
52
81
  assert(reader.getFieldLength() === 1, 0xa19 /* invalid children number */);
53
82
  const storedKey = reader.getFieldKey();
54
- let key;
55
- if (!options.useStoredKeys) {
56
- const viewSchema = schema.get(type) ?? fail(0xbff /* missing schema for type in cursor */);
57
- if (isObjectNodeSchema(viewSchema)) {
58
- const propertyKey = viewSchema.storedKeyToPropertyKey.get(storedKey);
59
- if (propertyKey === undefined) {
60
- assert(viewSchema.allowUnknownOptionalFields, 0xc00 /* found unknown field where not allowed */);
61
- // Skip unknown optional fields when using property keys.
62
- return;
63
- }
64
- key = propertyKey;
65
- }
66
- else {
67
- key = storedKey;
68
- }
69
- }
70
- else {
71
- key = storedKey;
83
+ const key = getKeyFromOptions(options.keys, type, storedKey, schema);
84
+ if (key === undefined) {
85
+ // Skip unknown optional fields when using property keys or only known stored keys.
86
+ return;
72
87
  }
73
88
  reader.enterNode(0);
74
89
  fields[key] = childHandler(reader, options, storedSchema, schema);
@@ -79,6 +94,51 @@ export function customFromCursor(reader, options, storedSchema, schema, childHan
79
94
  }
80
95
  }
81
96
  }
97
+ /**
98
+ * Returns the key if one should be used, and undefined if the field should be omitted/skipped.
99
+ *
100
+ * @param schema - Collection of known view schema.
101
+ * If `options` is not `KeyEncodingOptions.allStoredKeys`, this must provide the schema for the `type`.
102
+ * Note that if using this to perform a recursive walk, and `schema` has all view schema reachable from the starting type,
103
+ * then it should be safe to use the same schema map on every invocation since types missing from it will only be
104
+ * encountered after traversing unknown optional fields which for which this will return undefined.
105
+ *
106
+ * @remarks
107
+ * Asserts that if encountering an unknown optional field, the schema allows them.
108
+ * This is not robustly validated in all cases: when in allStoredKeys, it is not checked
109
+ * (since the view schema might not even be available).
110
+ */
111
+ function getKeyFromOptions(options, type, storedKey, schema) {
112
+ switch (options) {
113
+ case KeyEncodingOptions.allStoredKeys:
114
+ // Since this case might be inside of an unknown optional field,
115
+ // it must not depend on there being a view schema.
116
+ // Fortunately, its possible to implement this case without one.
117
+ return storedKey;
118
+ case KeyEncodingOptions.usePropertyKeys:
119
+ case KeyEncodingOptions.knownStoredKeys: {
120
+ // Both these cases avoid traversing into unknown optional fields,
121
+ // so a view schema should be available.
122
+ const viewSchema = schema.get(type) ?? fail(0xbff /* missing schema for type in cursor */);
123
+ if (isObjectNodeSchema(viewSchema)) {
124
+ const propertyKey = viewSchema.storedKeyToPropertyKey.get(storedKey);
125
+ if (propertyKey === undefined) {
126
+ assert(viewSchema.allowUnknownOptionalFields, 0xc00 /* found unknown field where not allowed */);
127
+ // Skip unknown optional fields when using property keys or only known stored keys.
128
+ return undefined;
129
+ }
130
+ else {
131
+ return options === KeyEncodingOptions.usePropertyKeys ? propertyKey : storedKey;
132
+ }
133
+ }
134
+ else {
135
+ return storedKey;
136
+ }
137
+ }
138
+ default:
139
+ unreachableCase(options);
140
+ }
141
+ }
82
142
  /**
83
143
  * Builds an {@link CustomTree} from a cursor in Nodes mode.
84
144
  * @remarks
@@ -1 +1 @@
1
- {"version":3,"file":"customTree.js","sourceRoot":"","sources":["../../../src/simple-tree/api/customTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EACN,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,sBAAsB,GAMtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EACN,aAAa,EACb,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,YAAY,GACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAqD5D;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,gBAAgB,CAC/B,MAAmB,EACnB,OAAsC,EACtC,YAAuD,EACvD,MAA2C,EAC3C,YAKW;IAEX,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;IAEzB,QAAQ,IAAI,EAAE,CAAC;QACd,KAAK,YAAY,CAAC,UAAU,C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;IACF,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAA4B;IAClE,IAAI,MAAM,YAAY,sBAAsB,EAAE,CAAC;QAC9C,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC9C,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;YACnD,kFAAkF;YAClF,6FAA6F;YAC7F,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,IAAI,KAAK,CAAC,EAAE,KAAK,CAAC,oBAAoB,CAAC,CAAC;YACvE,OAAO,KAAK,CAAC,KAAK,CAAC;QACpB,CAAC;IACF,CAAC;AACF,CAAC;AAUD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,cAAc,CAAI,IAAa,EAAE,QAA4B;IAC5E,OAAO,qBAAqB,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QACrD,kDAAkD;QAClD,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,CAAC;aAAM,CAAC;YACP,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QAC/B,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC5C,MAAM,IAAI,UAAU,CACnB,kDAAkD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,wCAAwC,CAC9G,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tEmptyKey,\n\tforEachField,\n\tinCursorField,\n\tLeafNodeStoredSchema,\n\tmapCursorField,\n\tObjectNodeStoredSchema,\n\ttype FieldKey,\n\ttype ITreeCursor,\n\ttype TreeNodeSchemaIdentifier,\n\ttype TreeNodeStoredSchema,\n\ttype TreeTypeSet,\n} from \"../../core/index.js\";\nimport { FieldKinds, valueSchemaAllows } from \"../../feature-libraries/index.js\";\nimport { cloneWithReplacements } from \"../../util/index.js\";\nimport type { TreeNodeSchema, TreeLeafValue } from \"../core/index.js\";\nimport {\n\tbooleanSchema,\n\thandleSchema,\n\tnullSchema,\n\tnumberSchema,\n\tstringSchema,\n} from \"../leafNodeSchema.js\";\nimport { isObjectNodeSchema } from \"../node-kinds/index.js\";\n\n/**\n * Options for how to interpret or encode a tree when schema information is available.\n * @alpha\n */\nexport interface TreeEncodingOptions {\n\t/**\n\t * If true, use the stored keys of object nodes.\n\t * If false, use the property keys.\n\t * @remarks\n\t * Has no effect on {@link NodeKind}s other than {@link NodeKind.Object}.\n\t *\n\t * {@link SchemaFactoryObjectOptions.allowUnknownOptionalFields|Unknown optional field} will be omitted when using property keys.\n\t * @defaultValue false.\n\t * @privateRemarks\n\t * TODO AB#43548:\n\t * Replace this with an enum that provides three options:\n\t * - `usePropertyKeys`: use property keys. Supported for import and export.\n\t * - `allStoredKeys`: use stored keys, and include unknown optional fields. Supported for export only, at least for the short term.\n\t * - `knownStoredKeys`: use stored keys but do not include unknown optional fields. Supported for import and export.\n\t */\n\treadonly useStoredKeys?: boolean;\n}\n\n/**\n * Options for how to interpret a `ConciseTree<TCustom>` without relying on schema.\n */\nexport interface SchemalessParseOptions {\n\t/**\n\t * Converts stored keys into whatever key the tree is using in its encoding.\n\t */\n\tkeyConverter?: {\n\t\tparse(type: string, inputKey: string): FieldKey;\n\t\tencode(type: string, key: FieldKey): string;\n\t};\n}\n\n/**\n * Tree representation with fields as properties and customized handle and child representations.\n */\nexport type CustomTree<TChild> = CustomTreeNode<TChild> | CustomTreeValue;\n\n/**\n * TreeLeafValue except the handle type is customized.\n */\nexport type CustomTreeValue = TreeLeafValue;\n\n/**\n * Tree node representation with fields as properties and customized child representation.\n */\nexport type CustomTreeNode<TChild> = TChild[] | { [key: string]: TChild };\n\n/**\n * Builds an {@link CustomTree} from a cursor in Nodes mode.\n *\n * @param reader - The cursor to read from.\n * @param options - Options for how to interpret the tree.\n * @param storedSchema - Schema which the cursor must comply with.\n * Must be be possible to map to a view schema (mainly that sequences can only occur in the special ArrayNode pattern).\n * Must include even unknown optional fields.\n * @param schema - View schema used to derive the property keys for fields when `options` selects them via {@link TreeEncodingOptions.useStoredKeys}.\n * @param childHandler - Function to handle children of the cursor.\n *\n * @remarks\n * This can handle unknown optional fields only because they are included in the `storedSchema` and `schema` is only needed when using property keys, which also skips unknown optional fields.\n */\nexport function customFromCursor<TChild>(\n\treader: ITreeCursor,\n\toptions: Required<TreeEncodingOptions>,\n\tstoredSchema: ReadonlyMap<string, TreeNodeStoredSchema>,\n\tschema: ReadonlyMap<string, TreeNodeSchema>,\n\tchildHandler: (\n\t\treader: ITreeCursor,\n\t\toptions: Required<TreeEncodingOptions>,\n\t\tstoredSchema: ReadonlyMap<string, TreeNodeStoredSchema>,\n\t\tschema: ReadonlyMap<string, TreeNodeSchema>,\n\t) => TChild,\n): CustomTree<TChild> {\n\tconst type = reader.type;\n\n\tswitch (type) {\n\t\tcase numberSchema.identifier:\n\t\tcase booleanSchema.identifier:\n\t\tcase nullSchema.identifier:\n\t\tcase stringSchema.identifier:\n\t\t\tassert(reader.value !== undefined, 0xa50 /* out of schema: missing value */);\n\t\t\tassert(!isFluidHandle(reader.value), 0xa51 /* out of schema: unexpected FluidHandle */);\n\t\t\treturn reader.value;\n\t\tcase handleSchema.identifier:\n\t\t\tassert(reader.value !== undefined, 0xa52 /* out of schema: missing value */);\n\t\t\tassert(isFluidHandle(reader.value), 0xa53 /* out of schema: expected FluidHandle */);\n\t\t\treturn reader.value;\n\t\tdefault: {\n\t\t\tassert(reader.value === undefined, 0xa54 /* out of schema: unexpected value */);\n\t\t\tconst nodeSchema =\n\t\t\t\tstoredSchema.get(type) ?? fail(0xb2e /* missing schema for type in cursor */);\n\t\t\tconst arrayTypes = tryStoredSchemaAsArray(nodeSchema);\n\n\t\t\tif (arrayTypes !== undefined) {\n\t\t\t\tconst fields = inCursorField(reader, EmptyKey, () =>\n\t\t\t\t\tmapCursorField(reader, () => childHandler(reader, options, storedSchema, schema)),\n\t\t\t\t);\n\t\t\t\treturn fields;\n\t\t\t} else {\n\t\t\t\tconst fields: Record<string, TChild> = {};\n\t\t\t\tforEachField(reader, () => {\n\t\t\t\t\tassert(reader.getFieldLength() === 1, 0xa19 /* invalid children number */);\n\t\t\t\t\tconst storedKey = reader.getFieldKey();\n\t\t\t\t\tlet key: string;\n\t\t\t\t\tif (!options.useStoredKeys) {\n\t\t\t\t\t\tconst viewSchema =\n\t\t\t\t\t\t\tschema.get(type) ?? fail(0xbff /* missing schema for type in cursor */);\n\t\t\t\t\t\tif (isObjectNodeSchema(viewSchema)) {\n\t\t\t\t\t\t\tconst propertyKey = viewSchema.storedKeyToPropertyKey.get(storedKey);\n\t\t\t\t\t\t\tif (propertyKey === undefined) {\n\t\t\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\t\t\tviewSchema.allowUnknownOptionalFields,\n\t\t\t\t\t\t\t\t\t0xc00 /* found unknown field where not allowed */,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t// Skip unknown optional fields when using property keys.\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tkey = propertyKey;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tkey = storedKey;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tkey = storedKey;\n\t\t\t\t\t}\n\t\t\t\t\treader.enterNode(0);\n\t\t\t\t\tfields[key] = childHandler(reader, options, storedSchema, schema);\n\t\t\t\t\treader.exitNode();\n\t\t\t\t});\n\t\t\t\treturn fields;\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Builds an {@link CustomTree} from a cursor in Nodes mode.\n * @remarks\n * Uses stored keys and stored schema.\n */\nexport function customFromCursorStored<TChild>(\n\treader: ITreeCursor,\n\tschema: ReadonlyMap<TreeNodeSchemaIdentifier, TreeNodeStoredSchema>,\n\tchildHandler: (\n\t\treader: ITreeCursor,\n\t\tschema: ReadonlyMap<TreeNodeSchemaIdentifier, TreeNodeStoredSchema>,\n\t) => TChild,\n): CustomTree<TChild> {\n\tconst type = reader.type;\n\tconst nodeSchema = schema.get(type) ?? fail(0xb30 /* missing schema for type in cursor */);\n\n\tif (nodeSchema instanceof LeafNodeStoredSchema) {\n\t\tassert(valueSchemaAllows(nodeSchema.leafValue, reader.value), 0xa9c /* invalid value */);\n\t\treturn reader.value;\n\t}\n\n\tassert(reader.value === undefined, 0xa9d /* out of schema: unexpected value */);\n\n\tconst arrayTypes = tryStoredSchemaAsArray(nodeSchema);\n\tif (arrayTypes !== undefined) {\n\t\tconst field = inCursorField(reader, EmptyKey, () =>\n\t\t\tmapCursorField(reader, () => childHandler(reader, schema)),\n\t\t);\n\t\treturn field;\n\t}\n\n\tconst fields: Record<string, TChild> = {};\n\tforEachField(reader, () => {\n\t\tconst children = mapCursorField(reader, () => childHandler(reader, schema));\n\t\tif (children.length === 1) {\n\t\t\tconst storedKey = reader.getFieldKey();\n\t\t\t// Length is checked above.\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tfields[storedKey] = children[0]!;\n\t\t} else {\n\t\t\tassert(children.length === 0, 0xa9e /* invalid children number */);\n\t\t}\n\t});\n\treturn fields;\n}\n\n/**\n * Checks if `schema` could correspond to a simple-tree array node.\n * If it is an array schema, returns the allowed types for the array field.\n * Otherwise returns `undefined`.\n * @remarks\n * If the schema was defined by the public API, this will be accurate since there is no way to define an object node with a sequence field.\n */\nexport function tryStoredSchemaAsArray(schema: TreeNodeStoredSchema): TreeTypeSet | undefined {\n\tif (schema instanceof ObjectNodeStoredSchema) {\n\t\tconst empty = schema.getFieldSchema(EmptyKey);\n\t\tif (empty.kind === FieldKinds.sequence.identifier) {\n\t\t\t// This assert can only be hit by schema created not using the public API surface.\n\t\t\t// If at some point this case needs to be tolerated, it can be replaced by \"return undefined\"\n\t\t\tassert(schema.objectNodeFields.size === 1, 0xa9f /* invalid schema */);\n\t\t\treturn empty.types;\n\t\t}\n\t}\n}\n\n/**\n * Options for how to transcode handles.\n * @remarks\n * Can be applied using {@link replaceHandles}.\n * @alpha\n */\nexport type HandleConverter<TCustom> = (data: IFluidHandle) => TCustom;\n\n/**\n * Clones tree, replacing any handles.\n * @remarks\n * This can be useful converting data containing handles to JSON compatible formats,\n * or just asserting that data does not contain handles.\n *\n * Reversing this replacement depends on how the replacer encodes handles, and can often be impossible if the replacer\n * does not have all the necessary context to restore the handles\n * (e.g. if the handles are something insufficiently descriptive,\n * if data referenced by the handle got garbage collected,\n * if the encoded form of the handle can't be differentiated from other data,\n * or the replacer doesn't have access to the correct Fluid container to to restore them from).\n *\n * Code attempting to reverse this replacement may want to use {@link cloneWithReplacements}.\n * @alpha\n */\nexport function replaceHandles<T>(tree: unknown, replacer: HandleConverter<T>): unknown {\n\treturn cloneWithReplacements(tree, \"\", (key, value) => {\n\t\t// eslint-disable-next-line unicorn/prefer-ternary\n\t\tif (isFluidHandle(value)) {\n\t\t\treturn { clone: false, value: replacer(value) };\n\t\t} else {\n\t\t\treturn { clone: true, value };\n\t\t}\n\t});\n}\n\n/**\n * Throws a `UsageError` indicating that a type is unknown in the current context.\n */\nexport function unknownTypeError(type: string): never {\n\tthrow new UsageError(\n\t\t`Failed to parse tree due to occurrence of type ${JSON.stringify(type)} which is not defined in this context.`,\n\t);\n}\n"]}
1
+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AAE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,CAAC;aAAM,CAAC;YACP,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QAC/B,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC5C,MAAM,IAAI,UAAU,CACnB,kDAAkD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,wCAAwC,CAC9G,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { assert, fail, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tEmptyKey,\n\tforEachField,\n\tinCursorField,\n\tLeafNodeStoredSchema,\n\tmapCursorField,\n\tObjectNodeStoredSchema,\n\ttype FieldKey,\n\ttype ITreeCursor,\n\ttype TreeNodeSchemaIdentifier,\n\ttype TreeNodeStoredSchema,\n\ttype TreeTypeSet,\n} from \"../../core/index.js\";\nimport { FieldKinds, valueSchemaAllows } from \"../../feature-libraries/index.js\";\nimport { cloneWithReplacements } from \"../../util/index.js\";\nimport type { TreeNodeSchema, TreeLeafValue } from \"../core/index.js\";\nimport {\n\tbooleanSchema,\n\thandleSchema,\n\tnullSchema,\n\tnumberSchema,\n\tstringSchema,\n} from \"../leafNodeSchema.js\";\nimport { isObjectNodeSchema } from \"../node-kinds/index.js\";\n\n/**\n * Options for how to interpret or encode a tree when schema information is available.\n * @alpha\n * @input\n */\nexport interface TreeEncodingOptions<TKeyOptions = KeyEncodingOptions> {\n\t/**\n\t * How to handle field keys.\n\t * @remarks\n\t * Has no effect on {@link NodeKind}s other than {@link NodeKind.Object}.\n\t *\n\t * {@link SchemaFactoryObjectOptions.allowUnknownOptionalFields|Unknown optional field} will be omitted when using property keys.\n\t * @defaultValue {@link KeyEncodingOptions.usePropertyKeys}.\n\t */\n\treadonly keys?: TKeyOptions;\n}\n\n/**\n * Options for how to interpret a tree when schema information is available.\n * @alpha\n * @input\n */\nexport type TreeParsingOptions = TreeEncodingOptions<\n\tKeyEncodingOptions.usePropertyKeys | KeyEncodingOptions.knownStoredKeys\n>;\n\n/**\n * Options for how to encode keys in a tree.\n * @alpha\n * @input\n */\nexport enum KeyEncodingOptions {\n\t/**\n\t * Use property keys.\n\t * @remarks\n\t * Supported for import and export.\n\t * {@link SchemaFactoryObjectOptions.allowUnknownOptionalFields|Unknown optional fields} will be omitted when using property keys.\n\t */\n\tusePropertyKeys = \"usePropertyKeys\",\n\t/**\n\t * Use stored keys, and include {@link SchemaFactoryObjectOptions.allowUnknownOptionalFields|Unknown optional fields}.\n\t * @remarks\n\t * Currently only supported for export.\n\t */\n\tallStoredKeys = \"allStoredKeys\",\n\t/**\n\t * Use stored keys but do not include {@link SchemaFactoryObjectOptions.allowUnknownOptionalFields|Unknown optional fields}.\n\t * @remarks\n\t * Supported for import and export.\n\t * For export, this omits unknown optional fields.\n\t * For import, any unexpected fields are errors, regardless of {@link SchemaFactoryObjectOptions.allowUnknownOptionalFields}.\n\t */\n\tknownStoredKeys = \"knownStoredKeys\",\n}\n\n/**\n * Options for how to interpret a `ConciseTree<TCustom>` without relying on schema.\n */\nexport interface SchemalessParseOptions {\n\t/**\n\t * Converts stored keys into whatever key the tree is using in its encoding.\n\t */\n\tkeyConverter?: {\n\t\tparse(type: string, inputKey: string): FieldKey;\n\t\tencode(type: string, key: FieldKey): string;\n\t};\n}\n\n/**\n * Tree representation with fields as properties and customized handle and child representations.\n */\nexport type CustomTree<TChild> = CustomTreeNode<TChild> | CustomTreeValue;\n\n/**\n * TreeLeafValue except the handle type is customized.\n */\nexport type CustomTreeValue = TreeLeafValue;\n\n/**\n * Tree node representation with fields as properties and customized child representation.\n */\nexport type CustomTreeNode<TChild> = TChild[] | { [key: string]: TChild };\n\n/**\n * Builds an {@link CustomTree} from a cursor in Nodes mode.\n *\n * @param reader - The cursor to read from.\n * @param options - Options for how to interpret the tree.\n * @param storedSchema - Schema which the cursor must comply with.\n * Must be be possible to map to a view schema (mainly that sequences can only occur in the special ArrayNode pattern).\n * Must include even unknown optional fields.\n * @param schema - View schema used to derive the property keys for fields when `options` selects them via {@link TreeEncodingOptions.useStoredKeys}.\n * @param childHandler - Function to handle children of the cursor.\n *\n * @remarks\n * This can handle unknown optional fields only because they are included in the `storedSchema` and `schema` is only needed when using property keys, which also skips unknown optional fields.\n */\nexport function customFromCursor<TChild>(\n\treader: ITreeCursor,\n\toptions: Required<TreeEncodingOptions>,\n\tstoredSchema: ReadonlyMap<string, TreeNodeStoredSchema>,\n\tschema: ReadonlyMap<string, TreeNodeSchema>,\n\tchildHandler: (\n\t\treader: ITreeCursor,\n\t\toptions: Required<TreeEncodingOptions>,\n\t\tstoredSchema: ReadonlyMap<string, TreeNodeStoredSchema>,\n\t\tschema: ReadonlyMap<string, TreeNodeSchema>,\n\t) => TChild,\n): CustomTree<TChild> {\n\tconst type = reader.type;\n\n\tswitch (type) {\n\t\tcase numberSchema.identifier:\n\t\tcase booleanSchema.identifier:\n\t\tcase nullSchema.identifier:\n\t\tcase stringSchema.identifier:\n\t\t\tassert(reader.value !== undefined, 0xa50 /* out of schema: missing value */);\n\t\t\tassert(!isFluidHandle(reader.value), 0xa51 /* out of schema: unexpected FluidHandle */);\n\t\t\treturn reader.value;\n\t\tcase handleSchema.identifier:\n\t\t\tassert(reader.value !== undefined, 0xa52 /* out of schema: missing value */);\n\t\t\tassert(isFluidHandle(reader.value), 0xa53 /* out of schema: expected FluidHandle */);\n\t\t\treturn reader.value;\n\t\tdefault: {\n\t\t\tassert(reader.value === undefined, 0xa54 /* out of schema: unexpected value */);\n\t\t\tconst nodeSchema =\n\t\t\t\tstoredSchema.get(type) ?? fail(0xb2e /* missing schema for type in cursor */);\n\t\t\tconst arrayTypes = tryStoredSchemaAsArray(nodeSchema);\n\n\t\t\tif (arrayTypes !== undefined) {\n\t\t\t\tconst fields = inCursorField(reader, EmptyKey, () =>\n\t\t\t\t\tmapCursorField(reader, () => childHandler(reader, options, storedSchema, schema)),\n\t\t\t\t);\n\t\t\t\treturn fields;\n\t\t\t} else {\n\t\t\t\tconst fields: Record<string, TChild> = {};\n\t\t\t\tforEachField(reader, () => {\n\t\t\t\t\tassert(reader.getFieldLength() === 1, 0xa19 /* invalid children number */);\n\t\t\t\t\tconst storedKey = reader.getFieldKey();\n\t\t\t\t\tconst key = getKeyFromOptions(options.keys, type, storedKey, schema);\n\t\t\t\t\tif (key === undefined) {\n\t\t\t\t\t\t// Skip unknown optional fields when using property keys or only known stored keys.\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\treader.enterNode(0);\n\t\t\t\t\tfields[key] = childHandler(reader, options, storedSchema, schema);\n\t\t\t\t\treader.exitNode();\n\t\t\t\t});\n\t\t\t\treturn fields;\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Returns the key if one should be used, and undefined if the field should be omitted/skipped.\n *\n * @param schema - Collection of known view schema.\n * If `options` is not `KeyEncodingOptions.allStoredKeys`, this must provide the schema for the `type`.\n * Note that if using this to perform a recursive walk, and `schema` has all view schema reachable from the starting type,\n * then it should be safe to use the same schema map on every invocation since types missing from it will only be\n * encountered after traversing unknown optional fields which for which this will return undefined.\n *\n * @remarks\n * Asserts that if encountering an unknown optional field, the schema allows them.\n * This is not robustly validated in all cases: when in allStoredKeys, it is not checked\n * (since the view schema might not even be available).\n */\nfunction getKeyFromOptions(\n\toptions: KeyEncodingOptions,\n\ttype: TreeNodeSchemaIdentifier,\n\tstoredKey: FieldKey,\n\tschema: ReadonlyMap<string, TreeNodeSchema>,\n): string | undefined {\n\tswitch (options) {\n\t\tcase KeyEncodingOptions.allStoredKeys:\n\t\t\t// Since this case might be inside of an unknown optional field,\n\t\t\t// it must not depend on there being a view schema.\n\t\t\t// Fortunately, its possible to implement this case without one.\n\t\t\treturn storedKey;\n\t\tcase KeyEncodingOptions.usePropertyKeys:\n\t\tcase KeyEncodingOptions.knownStoredKeys: {\n\t\t\t// Both these cases avoid traversing into unknown optional fields,\n\t\t\t// so a view schema should be available.\n\t\t\tconst viewSchema =\n\t\t\t\tschema.get(type) ?? fail(0xbff /* missing schema for type in cursor */);\n\t\t\tif (isObjectNodeSchema(viewSchema)) {\n\t\t\t\tconst propertyKey = viewSchema.storedKeyToPropertyKey.get(storedKey);\n\t\t\t\tif (propertyKey === undefined) {\n\t\t\t\t\tassert(\n\t\t\t\t\t\tviewSchema.allowUnknownOptionalFields,\n\t\t\t\t\t\t0xc00 /* found unknown field where not allowed */,\n\t\t\t\t\t);\n\t\t\t\t\t// Skip unknown optional fields when using property keys or only known stored keys.\n\t\t\t\t\treturn undefined;\n\t\t\t\t} else {\n\t\t\t\t\treturn options === KeyEncodingOptions.usePropertyKeys ? propertyKey : storedKey;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn storedKey;\n\t\t\t}\n\t\t}\n\t\tdefault:\n\t\t\tunreachableCase(options);\n\t}\n}\n\n/**\n * Builds an {@link CustomTree} from a cursor in Nodes mode.\n * @remarks\n * Uses stored keys and stored schema.\n */\nexport function customFromCursorStored<TChild>(\n\treader: ITreeCursor,\n\tschema: ReadonlyMap<TreeNodeSchemaIdentifier, TreeNodeStoredSchema>,\n\tchildHandler: (\n\t\treader: ITreeCursor,\n\t\tschema: ReadonlyMap<TreeNodeSchemaIdentifier, TreeNodeStoredSchema>,\n\t) => TChild,\n): CustomTree<TChild> {\n\tconst type = reader.type;\n\tconst nodeSchema = schema.get(type) ?? fail(0xb30 /* missing schema for type in cursor */);\n\n\tif (nodeSchema instanceof LeafNodeStoredSchema) {\n\t\tassert(valueSchemaAllows(nodeSchema.leafValue, reader.value), 0xa9c /* invalid value */);\n\t\treturn reader.value;\n\t}\n\n\tassert(reader.value === undefined, 0xa9d /* out of schema: unexpected value */);\n\n\tconst arrayTypes = tryStoredSchemaAsArray(nodeSchema);\n\tif (arrayTypes !== undefined) {\n\t\tconst field = inCursorField(reader, EmptyKey, () =>\n\t\t\tmapCursorField(reader, () => childHandler(reader, schema)),\n\t\t);\n\t\treturn field;\n\t}\n\n\tconst fields: Record<string, TChild> = {};\n\tforEachField(reader, () => {\n\t\tconst children = mapCursorField(reader, () => childHandler(reader, schema));\n\t\tif (children.length === 1) {\n\t\t\tconst storedKey = reader.getFieldKey();\n\t\t\t// Length is checked above.\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tfields[storedKey] = children[0]!;\n\t\t} else {\n\t\t\tassert(children.length === 0, 0xa9e /* invalid children number */);\n\t\t}\n\t});\n\treturn fields;\n}\n\n/**\n * Checks if `schema` could correspond to a simple-tree array node.\n * If it is an array schema, returns the allowed types for the array field.\n * Otherwise returns `undefined`.\n * @remarks\n * If the schema was defined by the public API, this will be accurate since there is no way to define an object node with a sequence field.\n */\nexport function tryStoredSchemaAsArray(schema: TreeNodeStoredSchema): TreeTypeSet | undefined {\n\tif (schema instanceof ObjectNodeStoredSchema) {\n\t\tconst empty = schema.getFieldSchema(EmptyKey);\n\t\tif (empty.kind === FieldKinds.sequence.identifier) {\n\t\t\t// This assert can only be hit by schema created not using the public API surface.\n\t\t\t// If at some point this case needs to be tolerated, it can be replaced by \"return undefined\"\n\t\t\tassert(schema.objectNodeFields.size === 1, 0xa9f /* invalid schema */);\n\t\t\treturn empty.types;\n\t\t}\n\t}\n}\n\n/**\n * Options for how to transcode handles.\n * @remarks\n * Can be applied using {@link replaceHandles}.\n * @alpha\n */\nexport type HandleConverter<TCustom> = (data: IFluidHandle) => TCustom;\n\n/**\n * Clones tree, replacing any handles.\n * @remarks\n * This can be useful converting data containing handles to JSON compatible formats,\n * or just asserting that data does not contain handles.\n *\n * Reversing this replacement depends on how the replacer encodes handles, and can often be impossible if the replacer\n * does not have all the necessary context to restore the handles\n * (e.g. if the handles are something insufficiently descriptive,\n * if data referenced by the handle got garbage collected,\n * if the encoded form of the handle can't be differentiated from other data,\n * or the replacer doesn't have access to the correct Fluid container to to restore them from).\n *\n * Code attempting to reverse this replacement may want to use {@link cloneWithReplacements}.\n * @alpha\n */\nexport function replaceHandles<T>(tree: unknown, replacer: HandleConverter<T>): unknown {\n\treturn cloneWithReplacements(tree, \"\", (key, value) => {\n\t\t// eslint-disable-next-line unicorn/prefer-ternary\n\t\tif (isFluidHandle(value)) {\n\t\t\treturn { clone: false, value: replacer(value) };\n\t\t} else {\n\t\t\treturn { clone: true, value };\n\t\t}\n\t});\n}\n\n/**\n * Throws a `UsageError` indicating that a type is unknown in the current context.\n */\nexport function unknownTypeError(type: string): never {\n\tthrow new UsageError(\n\t\t`Failed to parse tree due to occurrence of type ${JSON.stringify(type)} which is not defined in this context.`,\n\t);\n}\n"]}
@@ -4,12 +4,16 @@
4
4
  */
5
5
  import type { JsonTreeSchema } from "./jsonSchema.js";
6
6
  import type { ImplicitAllowedTypes } from "../core/index.js";
7
- import type { TreeEncodingOptions } from "./customTree.js";
7
+ import type { TreeParsingOptions } from "./customTree.js";
8
8
  /**
9
9
  * Options for how to interpret or encode a tree when schema information is available.
10
+ * @remarks
11
+ * This currently extends {@link TreeParsingOptions},
12
+ * removing the option to declare {@link KeyEncodingOptions.allStoredKeys} since this option is currently not supported.
13
+ * @input
10
14
  * @alpha
11
15
  */
12
- export interface TreeSchemaEncodingOptions extends TreeEncodingOptions {
16
+ export interface TreeSchemaEncodingOptions extends TreeParsingOptions {
13
17
  /**
14
18
  * If true, fields with default providers (like {@link SchemaFactory.identifier}) will be required.
15
19
  * If false, they will be optional.
@@ -70,6 +74,7 @@ export interface TreeSchemaEncodingOptions extends TreeEncodingOptions {
70
74
  * 1. VerboseTree and (Done) ConciseTree
71
75
  * 2. (Done) With and without requiring values with defaults (for insertion vs reading)
72
76
  * 3. (Done) Using stored keys and property keys.
77
+ * 4. Control over unknown optional fields and staged allowed types (able to manually control them and/or get them from some context).
73
78
  *
74
79
  * This takes in `ImplicitAllowedTypes` since underlying `toJsonSchema` can't handle optional roots.
75
80
  *
@@ -1 +1 @@
1
- {"version":3,"file":"getJsonSchema.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/getJsonSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAG3D;;;GAGG;AACH,MAAM,WAAW,yBAA0B,SAAQ,mBAAmB;IACrE;;;;;;OAMG;IACH,QAAQ,CAAC,yBAAyB,CAAC,EAAE,OAAO,CAAC;CAC7C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,wBAAgB,aAAa,CAC5B,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAC1C,cAAc,CAGhB"}
1
+ {"version":3,"file":"getJsonSchema.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/getJsonSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAG1D;;;;;;;GAOG;AACH,MAAM,WAAW,yBAA0B,SAAQ,kBAAkB;IACpE;;;;;;OAMG;IACH,QAAQ,CAAC,yBAAyB,CAAC,EAAE,OAAO,CAAC;CAC7C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,wBAAgB,aAAa,CAC5B,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAC1C,cAAc,CAGhB"}
@@ -55,6 +55,7 @@ import { TreeViewConfigurationAlpha } from "./configuration.js";
55
55
  * 1. VerboseTree and (Done) ConciseTree
56
56
  * 2. (Done) With and without requiring values with defaults (for insertion vs reading)
57
57
  * 3. (Done) Using stored keys and property keys.
58
+ * 4. Control over unknown optional fields and staged allowed types (able to manually control them and/or get them from some context).
58
59
  *
59
60
  * This takes in `ImplicitAllowedTypes` since underlying `toJsonSchema` can't handle optional roots.
60
61
  *
@@ -1 +1 @@
1
- {"version":3,"file":"getJsonSchema.js","sourceRoot":"","sources":["../../../src/simple-tree/api/getJsonSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAiBhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,MAAM,UAAU,aAAa,CAC5B,MAA4B,EAC5B,OAA4C;IAE5C,MAAM,UAAU,GAAG,IAAI,0BAA0B,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9D,OAAO,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { JsonTreeSchema } from \"./jsonSchema.js\";\nimport type { ImplicitAllowedTypes } from \"../core/index.js\";\nimport { toJsonSchema } from \"./simpleSchemaToJsonSchema.js\";\nimport type { TreeEncodingOptions } from \"./customTree.js\";\nimport { TreeViewConfigurationAlpha } from \"./configuration.js\";\n\n/**\n * Options for how to interpret or encode a tree when schema information is available.\n * @alpha\n */\nexport interface TreeSchemaEncodingOptions extends TreeEncodingOptions {\n\t/**\n\t * If true, fields with default providers (like {@link SchemaFactory.identifier}) will be required.\n\t * If false, they will be optional.\n\t * @remarks\n\t * Has no effect on {@link NodeKind}s other than {@link NodeKind.Object}.\n\t * @defaultValue false.\n\t */\n\treadonly requireFieldsWithDefaults?: boolean;\n}\n\n/**\n * Creates a {@link https://json-schema.org/ | JSON Schema} representation of the provided {@link TreeNodeSchema}.\n *\n * @remarks\n * Useful when communicating the schema to external libraries or services.\n * Caches the result for future calls.\n *\n * @example\n *\n * A Shared Tree schema like the following:\n *\n * ```typescript\n * class MyObject extends schemaFactory.object(\"MyObject\", {\n * \tfoo: schemaFactory.number,\n * \tbar: schemaFactory.optional(schemaFactory.string),\n * });\n * ```\n *\n * Will yield JSON Schema like the following:\n *\n * ```json\n * {\n * \t\"$defs\": {\n * \t\t\"com.fluidframework.leaf.string\": {\n * \t\t\t\"type\": \"string\",\n * \t\t},\n * \t\t\"com.fluidframework.leaf.number\": {\n * \t\t\t\"type\": \"number\",\n * \t\t},\n * \t\t\"com.myapp.MyObject\": {\n * \t\t\t\"type\": \"object\",\n * \t\t\t\"properties\": {\n * \t\t\t\t\"foo\": { \"$ref\": \"com.fluidframework.leaf.number\" },\n * \t\t\t\t\"bar\": { \"$ref\": \"com.fluidframework.leaf.string\" },\n * \t\t\t},\n * \t\t\t\"required\": [\"foo\"],\n * \t\t},\n * \t},\n * \t\"$ref\": \"#/$defs/com.myapp.MyObject\",\n * }\n * ```\n *\n * @privateRemarks In the future, we may wish to move this to a more discoverable API location.\n * For now, while still an experimental API, it is surfaced as a free function.\n *\n * TODO:\n * This API should allow generating JSON schema for the whole matrix of combinations:\n *\n * 1. VerboseTree and (Done) ConciseTree\n * 2. (Done) With and without requiring values with defaults (for insertion vs reading)\n * 3. (Done) Using stored keys and property keys.\n *\n * This takes in `ImplicitAllowedTypes` since underlying `toJsonSchema` can't handle optional roots.\n *\n * @alpha\n */\nexport function getJsonSchema(\n\tschema: ImplicitAllowedTypes,\n\toptions: Required<TreeSchemaEncodingOptions>,\n): JsonTreeSchema {\n\tconst treeSchema = new TreeViewConfigurationAlpha({ schema });\n\treturn toJsonSchema(treeSchema, options);\n}\n"]}
1
+ {"version":3,"file":"getJsonSchema.js","sourceRoot":"","sources":["../../../src/simple-tree/api/getJsonSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAqBhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,MAAM,UAAU,aAAa,CAC5B,MAA4B,EAC5B,OAA4C;IAE5C,MAAM,UAAU,GAAG,IAAI,0BAA0B,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9D,OAAO,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { JsonTreeSchema } from \"./jsonSchema.js\";\nimport type { ImplicitAllowedTypes } from \"../core/index.js\";\nimport { toJsonSchema } from \"./simpleSchemaToJsonSchema.js\";\nimport type { TreeParsingOptions } from \"./customTree.js\";\nimport { TreeViewConfigurationAlpha } from \"./configuration.js\";\n\n/**\n * Options for how to interpret or encode a tree when schema information is available.\n * @remarks\n * This currently extends {@link TreeParsingOptions},\n * removing the option to declare {@link KeyEncodingOptions.allStoredKeys} since this option is currently not supported.\n * @input\n * @alpha\n */\nexport interface TreeSchemaEncodingOptions extends TreeParsingOptions {\n\t/**\n\t * If true, fields with default providers (like {@link SchemaFactory.identifier}) will be required.\n\t * If false, they will be optional.\n\t * @remarks\n\t * Has no effect on {@link NodeKind}s other than {@link NodeKind.Object}.\n\t * @defaultValue false.\n\t */\n\treadonly requireFieldsWithDefaults?: boolean;\n}\n\n/**\n * Creates a {@link https://json-schema.org/ | JSON Schema} representation of the provided {@link TreeNodeSchema}.\n *\n * @remarks\n * Useful when communicating the schema to external libraries or services.\n * Caches the result for future calls.\n *\n * @example\n *\n * A Shared Tree schema like the following:\n *\n * ```typescript\n * class MyObject extends schemaFactory.object(\"MyObject\", {\n * \tfoo: schemaFactory.number,\n * \tbar: schemaFactory.optional(schemaFactory.string),\n * });\n * ```\n *\n * Will yield JSON Schema like the following:\n *\n * ```json\n * {\n * \t\"$defs\": {\n * \t\t\"com.fluidframework.leaf.string\": {\n * \t\t\t\"type\": \"string\",\n * \t\t},\n * \t\t\"com.fluidframework.leaf.number\": {\n * \t\t\t\"type\": \"number\",\n * \t\t},\n * \t\t\"com.myapp.MyObject\": {\n * \t\t\t\"type\": \"object\",\n * \t\t\t\"properties\": {\n * \t\t\t\t\"foo\": { \"$ref\": \"com.fluidframework.leaf.number\" },\n * \t\t\t\t\"bar\": { \"$ref\": \"com.fluidframework.leaf.string\" },\n * \t\t\t},\n * \t\t\t\"required\": [\"foo\"],\n * \t\t},\n * \t},\n * \t\"$ref\": \"#/$defs/com.myapp.MyObject\",\n * }\n * ```\n *\n * @privateRemarks In the future, we may wish to move this to a more discoverable API location.\n * For now, while still an experimental API, it is surfaced as a free function.\n *\n * TODO:\n * This API should allow generating JSON schema for the whole matrix of combinations:\n *\n * 1. VerboseTree and (Done) ConciseTree\n * 2. (Done) With and without requiring values with defaults (for insertion vs reading)\n * 3. (Done) Using stored keys and property keys.\n * 4. Control over unknown optional fields and staged allowed types (able to manually control them and/or get them from some context).\n *\n * This takes in `ImplicitAllowedTypes` since underlying `toJsonSchema` can't handle optional roots.\n *\n * @alpha\n */\nexport function getJsonSchema(\n\tschema: ImplicitAllowedTypes,\n\toptions: Required<TreeSchemaEncodingOptions>,\n): JsonTreeSchema {\n\tconst treeSchema = new TreeViewConfigurationAlpha({ schema });\n\treturn toJsonSchema(treeSchema, options);\n}\n"]}
@@ -8,6 +8,7 @@ export type { ITree, TreeView, ViewableTree, TreeViewEvents, SchemaCompatibility
8
8
  export { asTreeViewAlpha } from "./tree.js";
9
9
  export { type SchemaStatics, schemaStatics } from "./schemaStatics.js";
10
10
  export { SchemaFactory, type ScopedSchemaName, type SchemaFactoryObjectOptions, type NodeSchemaOptions, type NodeSchemaOptionsAlpha, } from "./schemaFactory.js";
11
+ export { SchemaFactoryBeta } from "./schemaFactoryBeta.js";
11
12
  export { SchemaFactoryAlpha, type SchemaStaticsAlpha } from "./schemaFactoryAlpha.js";
12
13
  export type { ValidateRecursiveSchema, FixRecursiveArraySchema, ValidateRecursiveSchemaTemplate, FixRecursiveRecursionLimit, } from "./schemaFactoryRecursive.js";
13
14
  export { allowUnused } from "./schemaFactoryRecursive.js";
@@ -21,7 +22,7 @@ export { getSimpleSchema } from "./getSimpleSchema.js";
21
22
  export { SchemaCompatibilityTester } from "./schemaCompatibilityTester.js";
22
23
  export type { Unenforced, FieldSchemaAlphaUnsafe, ArrayNodeCustomizableSchemaUnsafe, MapNodeCustomizableSchemaUnsafe, System_Unsafe, TreeRecordNodeUnsafe, } from "./typesUnsafe.js";
23
24
  export { type VerboseTreeNode, type VerboseTree, applySchemaToParserOptions, cursorFromVerbose, verboseFromCursor, replaceVerboseTreeHandles, } from "./verboseTree.js";
24
- export { type TreeEncodingOptions, customFromCursorStored, type CustomTreeNode, type CustomTreeValue, tryStoredSchemaAsArray, replaceHandles, type HandleConverter, } from "./customTree.js";
25
+ export { type TreeEncodingOptions, customFromCursorStored, type CustomTreeNode, type CustomTreeValue, tryStoredSchemaAsArray, replaceHandles, type HandleConverter, KeyEncodingOptions, type TreeParsingOptions, } from "./customTree.js";
25
26
  export { type ConciseTree, conciseFromCursor, replaceConciseTreeHandles, } from "./conciseTree.js";
26
27
  export { TreeBeta, type NodeChangedData, type TreeChangeEventsBeta } from "./treeBeta.js";
27
28
  export { createSimpleTreeIndex, type SimpleTreeIndex } from "./simpleTreeIndex.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources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,KAAK,WAAW,EAChB,iBAAiB,EACjB,yBAAyB,GACzB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,KAAK,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC1F,OAAO,EAAE,qBAAqB,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EACN,qBAAqB,EACrB,KAAK,eAAe,GACpB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACN,sBAAsB,EACtB,sBAAsB,GACtB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,KAAK,6BAA6B,EAClC,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,QAAQ,GACR,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,YAAY,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
@@ -6,6 +6,7 @@ export { TreeViewConfiguration, TreeViewConfigurationAlpha, } from "./configurat
6
6
  export { asTreeViewAlpha } from "./tree.js";
7
7
  export { schemaStatics } from "./schemaStatics.js";
8
8
  export { SchemaFactory, } from "./schemaFactory.js";
9
+ export { SchemaFactoryBeta } from "./schemaFactoryBeta.js";
9
10
  export { SchemaFactoryAlpha } from "./schemaFactoryAlpha.js";
10
11
  export { allowUnused } from "./schemaFactoryRecursive.js";
11
12
  export { adaptEnum, enumFromStrings, singletonSchema, } from "./schemaCreationUtilities.js";
@@ -15,7 +16,7 @@ export { getJsonSchema } from "./getJsonSchema.js";
15
16
  export { getSimpleSchema } from "./getSimpleSchema.js";
16
17
  export { SchemaCompatibilityTester } from "./schemaCompatibilityTester.js";
17
18
  export { applySchemaToParserOptions, cursorFromVerbose, verboseFromCursor, replaceVerboseTreeHandles, } from "./verboseTree.js";
18
- export { customFromCursorStored, tryStoredSchemaAsArray, replaceHandles, } from "./customTree.js";
19
+ export { customFromCursorStored, tryStoredSchemaAsArray, replaceHandles, KeyEncodingOptions, } from "./customTree.js";
19
20
  export { conciseFromCursor, replaceConciseTreeHandles, } from "./conciseTree.js";
20
21
  export { TreeBeta } from "./treeBeta.js";
21
22
  export { createSimpleTreeIndex } from "./simpleTreeIndex.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/simple-tree/api/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EACN,qBAAqB,EACrB,0BAA0B,GAC1B,MAAM,oBAAoB,CAAC;AAY5B,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAsB,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EACN,aAAa,GAKb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAA2B,MAAM,yBAAyB,CAAC;AAOtF,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EACN,SAAS,EACT,eAAe,EACf,eAAe,GACf,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,qBAAqB,EACrB,2BAA2B,EAC3B,YAAY,EACZ,WAAW,EAEX,YAAY,GACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAmB/C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAU3E,OAAO,EAGN,0BAA0B,EAC1B,iBAAiB,EACjB,iBAAiB,EACjB,yBAAyB,GACzB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAEN,sBAAsB,EAGtB,sBAAsB,EACtB,cAAc,GAEd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAEN,iBAAiB,EACjB,yBAAyB,GACzB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,QAAQ,EAAmD,MAAM,eAAe,CAAC;AAC1F,OAAO,EAAE,qBAAqB,EAAwB,MAAM,sBAAsB,CAAC;AACnF,OAAO,EACN,qBAAqB,GAErB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACN,sBAAsB,EACtB,sBAAsB,GACtB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAUN,QAAQ,GACR,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport type {\n\tTreeSchema,\n\tITreeViewConfiguration,\n\tITreeConfigurationOptions,\n} from \"./configuration.js\";\nexport {\n\tTreeViewConfiguration,\n\tTreeViewConfigurationAlpha,\n} from \"./configuration.js\";\nexport type {\n\tITree,\n\tTreeView,\n\tViewableTree,\n\tTreeViewEvents,\n\tSchemaCompatibilityStatus,\n\tTreeViewAlpha,\n\tTreeBranch,\n\tTreeBranchEvents,\n\tITreeAlpha,\n} from \"./tree.js\";\nexport { asTreeViewAlpha } from \"./tree.js\";\nexport { type SchemaStatics, schemaStatics } from \"./schemaStatics.js\";\nexport {\n\tSchemaFactory,\n\ttype ScopedSchemaName,\n\ttype SchemaFactoryObjectOptions,\n\ttype NodeSchemaOptions,\n\ttype NodeSchemaOptionsAlpha,\n} from \"./schemaFactory.js\";\nexport { SchemaFactoryAlpha, type SchemaStaticsAlpha } from \"./schemaFactoryAlpha.js\";\nexport type {\n\tValidateRecursiveSchema,\n\tFixRecursiveArraySchema,\n\tValidateRecursiveSchemaTemplate,\n\tFixRecursiveRecursionLimit,\n} from \"./schemaFactoryRecursive.js\";\nexport { allowUnused } from \"./schemaFactoryRecursive.js\";\nexport {\n\tadaptEnum,\n\tenumFromStrings,\n\tsingletonSchema,\n} from \"./schemaCreationUtilities.js\";\nexport {\n\tgetIdentifierFromNode,\n\tgetPropertyKeyFromStoredKey,\n\tgetStoredKey,\n\ttreeNodeApi,\n\ttype TreeNodeApi,\n\ttryGetSchema,\n} from \"./treeNodeApi.js\";\nexport { createFromCursor } from \"./create.js\";\nexport {\n\ttype JsonSchemaId,\n\ttype JsonSchemaType,\n\ttype JsonObjectNodeSchema,\n\ttype JsonArrayNodeSchema,\n\ttype JsonMapNodeSchema,\n\ttype JsonLeafNodeSchema,\n\ttype JsonSchemaRef,\n\ttype JsonRefPath,\n\ttype JsonNodeSchema,\n\ttype JsonNodeSchemaBase,\n\ttype JsonTreeSchema,\n\ttype JsonFieldSchema,\n\ttype JsonLeafSchemaType,\n\ttype JsonRecordNodeSchema,\n\ttype JsonStringKeyPatternProperties,\n} from \"./jsonSchema.js\";\nexport type { TreeSchemaEncodingOptions } from \"./getJsonSchema.js\";\nexport { getJsonSchema } from \"./getJsonSchema.js\";\nexport { getSimpleSchema } from \"./getSimpleSchema.js\";\nexport { SchemaCompatibilityTester } from \"./schemaCompatibilityTester.js\";\nexport type {\n\tUnenforced,\n\tFieldSchemaAlphaUnsafe,\n\tArrayNodeCustomizableSchemaUnsafe,\n\tMapNodeCustomizableSchemaUnsafe,\n\tSystem_Unsafe,\n\tTreeRecordNodeUnsafe,\n} from \"./typesUnsafe.js\";\n\nexport {\n\ttype VerboseTreeNode,\n\ttype VerboseTree,\n\tapplySchemaToParserOptions,\n\tcursorFromVerbose,\n\tverboseFromCursor,\n\treplaceVerboseTreeHandles,\n} from \"./verboseTree.js\";\n\nexport {\n\ttype TreeEncodingOptions,\n\tcustomFromCursorStored,\n\ttype CustomTreeNode,\n\ttype CustomTreeValue,\n\ttryStoredSchemaAsArray,\n\treplaceHandles,\n\ttype HandleConverter,\n} from \"./customTree.js\";\n\nexport {\n\ttype ConciseTree,\n\tconciseFromCursor,\n\treplaceConciseTreeHandles,\n} from \"./conciseTree.js\";\n\nexport { TreeBeta, type NodeChangedData, type TreeChangeEventsBeta } from \"./treeBeta.js\";\nexport { createSimpleTreeIndex, type SimpleTreeIndex } from \"./simpleTreeIndex.js\";\nexport {\n\tcreateIdentifierIndex,\n\ttype IdentifierIndex,\n} from \"./identifierIndex.js\";\n\nexport {\n\textractPersistedSchema,\n\tcomparePersistedSchema,\n} from \"./storedSchema.js\";\n\nexport {\n\ttype TransactionConstraint,\n\ttype NodeInDocumentConstraint,\n\ttype RunTransactionParams,\n\ttype VoidTransactionCallbackStatus,\n\ttype TransactionCallbackStatus,\n\ttype TransactionResult,\n\ttype TransactionResultExt,\n\ttype TransactionResultSuccess,\n\ttype TransactionResultFailed,\n\trollback,\n} from \"./transactionTypes.js\";\n\nexport { generateSchemaFromSimpleSchema } from \"./schemaFromSimple.js\";\nexport { toSimpleTreeSchema } from \"./viewSchemaToSimpleSchema.js\";\nexport type { TreeChangeEvents } from \"./treeChangeEvents.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/simple-tree/api/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EACN,qBAAqB,EACrB,0BAA0B,GAC1B,MAAM,oBAAoB,CAAC;AAY5B,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAsB,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EACN,aAAa,GAKb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAA2B,MAAM,yBAAyB,CAAC;AAOtF,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EACN,SAAS,EACT,eAAe,EACf,eAAe,GACf,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,qBAAqB,EACrB,2BAA2B,EAC3B,YAAY,EACZ,WAAW,EAEX,YAAY,GACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAmB/C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAU3E,OAAO,EAGN,0BAA0B,EAC1B,iBAAiB,EACjB,iBAAiB,EACjB,yBAAyB,GACzB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAEN,sBAAsB,EAGtB,sBAAsB,EACtB,cAAc,EAEd,kBAAkB,GAElB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAEN,iBAAiB,EACjB,yBAAyB,GACzB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,QAAQ,EAAmD,MAAM,eAAe,CAAC;AAC1F,OAAO,EAAE,qBAAqB,EAAwB,MAAM,sBAAsB,CAAC;AACnF,OAAO,EACN,qBAAqB,GAErB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACN,sBAAsB,EACtB,sBAAsB,GACtB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAUN,QAAQ,GACR,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport type {\n\tTreeSchema,\n\tITreeViewConfiguration,\n\tITreeConfigurationOptions,\n} from \"./configuration.js\";\nexport {\n\tTreeViewConfiguration,\n\tTreeViewConfigurationAlpha,\n} from \"./configuration.js\";\nexport type {\n\tITree,\n\tTreeView,\n\tViewableTree,\n\tTreeViewEvents,\n\tSchemaCompatibilityStatus,\n\tTreeViewAlpha,\n\tTreeBranch,\n\tTreeBranchEvents,\n\tITreeAlpha,\n} from \"./tree.js\";\nexport { asTreeViewAlpha } from \"./tree.js\";\nexport { type SchemaStatics, schemaStatics } from \"./schemaStatics.js\";\nexport {\n\tSchemaFactory,\n\ttype ScopedSchemaName,\n\ttype SchemaFactoryObjectOptions,\n\ttype NodeSchemaOptions,\n\ttype NodeSchemaOptionsAlpha,\n} from \"./schemaFactory.js\";\nexport { SchemaFactoryBeta } from \"./schemaFactoryBeta.js\";\nexport { SchemaFactoryAlpha, type SchemaStaticsAlpha } from \"./schemaFactoryAlpha.js\";\nexport type {\n\tValidateRecursiveSchema,\n\tFixRecursiveArraySchema,\n\tValidateRecursiveSchemaTemplate,\n\tFixRecursiveRecursionLimit,\n} from \"./schemaFactoryRecursive.js\";\nexport { allowUnused } from \"./schemaFactoryRecursive.js\";\nexport {\n\tadaptEnum,\n\tenumFromStrings,\n\tsingletonSchema,\n} from \"./schemaCreationUtilities.js\";\nexport {\n\tgetIdentifierFromNode,\n\tgetPropertyKeyFromStoredKey,\n\tgetStoredKey,\n\ttreeNodeApi,\n\ttype TreeNodeApi,\n\ttryGetSchema,\n} from \"./treeNodeApi.js\";\nexport { createFromCursor } from \"./create.js\";\nexport {\n\ttype JsonSchemaId,\n\ttype JsonSchemaType,\n\ttype JsonObjectNodeSchema,\n\ttype JsonArrayNodeSchema,\n\ttype JsonMapNodeSchema,\n\ttype JsonLeafNodeSchema,\n\ttype JsonSchemaRef,\n\ttype JsonRefPath,\n\ttype JsonNodeSchema,\n\ttype JsonNodeSchemaBase,\n\ttype JsonTreeSchema,\n\ttype JsonFieldSchema,\n\ttype JsonLeafSchemaType,\n\ttype JsonRecordNodeSchema,\n\ttype JsonStringKeyPatternProperties,\n} from \"./jsonSchema.js\";\nexport type { TreeSchemaEncodingOptions } from \"./getJsonSchema.js\";\nexport { getJsonSchema } from \"./getJsonSchema.js\";\nexport { getSimpleSchema } from \"./getSimpleSchema.js\";\nexport { SchemaCompatibilityTester } from \"./schemaCompatibilityTester.js\";\nexport type {\n\tUnenforced,\n\tFieldSchemaAlphaUnsafe,\n\tArrayNodeCustomizableSchemaUnsafe,\n\tMapNodeCustomizableSchemaUnsafe,\n\tSystem_Unsafe,\n\tTreeRecordNodeUnsafe,\n} from \"./typesUnsafe.js\";\n\nexport {\n\ttype VerboseTreeNode,\n\ttype VerboseTree,\n\tapplySchemaToParserOptions,\n\tcursorFromVerbose,\n\tverboseFromCursor,\n\treplaceVerboseTreeHandles,\n} from \"./verboseTree.js\";\n\nexport {\n\ttype TreeEncodingOptions,\n\tcustomFromCursorStored,\n\ttype CustomTreeNode,\n\ttype CustomTreeValue,\n\ttryStoredSchemaAsArray,\n\treplaceHandles,\n\ttype HandleConverter,\n\tKeyEncodingOptions,\n\ttype TreeParsingOptions,\n} from \"./customTree.js\";\n\nexport {\n\ttype ConciseTree,\n\tconciseFromCursor,\n\treplaceConciseTreeHandles,\n} from \"./conciseTree.js\";\n\nexport { TreeBeta, type NodeChangedData, type TreeChangeEventsBeta } from \"./treeBeta.js\";\nexport { createSimpleTreeIndex, type SimpleTreeIndex } from \"./simpleTreeIndex.js\";\nexport {\n\tcreateIdentifierIndex,\n\ttype IdentifierIndex,\n} from \"./identifierIndex.js\";\n\nexport {\n\textractPersistedSchema,\n\tcomparePersistedSchema,\n} from \"./storedSchema.js\";\n\nexport {\n\ttype TransactionConstraint,\n\ttype NodeInDocumentConstraint,\n\ttype RunTransactionParams,\n\ttype VoidTransactionCallbackStatus,\n\ttype TransactionCallbackStatus,\n\ttype TransactionResult,\n\ttype TransactionResultExt,\n\ttype TransactionResultSuccess,\n\ttype TransactionResultFailed,\n\trollback,\n} from \"./transactionTypes.js\";\n\nexport { generateSchemaFromSimpleSchema } from \"./schemaFromSimple.js\";\nexport { toSimpleTreeSchema } from \"./viewSchemaToSimpleSchema.js\";\nexport type { TreeChangeEvents } from \"./treeChangeEvents.js\";\n"]}
@@ -27,7 +27,7 @@ export declare function singletonSchema<TScope extends string, TName extends str
27
27
  * @remarks
28
28
  * The string value of the enum is used as the name of the schema: callers must ensure that it is stable and unique.
29
29
  * Numeric enums values have the value implicitly converted into a string.
30
- * Consider making a dedicated schema factory with a nested scope (for example using {@link SchemaFactoryAlpha.scopedFactory}) to avoid the enum members colliding with other schema.
30
+ * Consider making a dedicated schema factory with a nested scope (for example using {@link SchemaFactoryBeta.scopedFactory}) to avoid the enum members colliding with other schema.
31
31
  * @example
32
32
  * ```typescript
33
33
  * const schemaFactory = new SchemaFactory("com.myApp");
@@ -56,7 +56,7 @@ export function singletonSchema(factory, name) {
56
56
  * @remarks
57
57
  * The string value of the enum is used as the name of the schema: callers must ensure that it is stable and unique.
58
58
  * Numeric enums values have the value implicitly converted into a string.
59
- * Consider making a dedicated schema factory with a nested scope (for example using {@link SchemaFactoryAlpha.scopedFactory}) to avoid the enum members colliding with other schema.
59
+ * Consider making a dedicated schema factory with a nested scope (for example using {@link SchemaFactoryBeta.scopedFactory}) to avoid the enum members colliding with other schema.
60
60
  * @example
61
61
  * ```typescript
62
62
  * const schemaFactory = new SchemaFactory("com.myApp");
@@ -1 +1 @@
1
- {"version":3,"file":"schemaCreationUtilities.js","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaCreationUtilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAanE;;;;;;;GAOG;AAEH;;;;;;;GAOG;AACH,wCAAwC;AACxC,4EAA4E;AAC5E,MAAM,UAAU,eAAe,CAC9B,OAAqC,EACrC,IAAW;;IAEX,MAAM,eAAgB,SAAQ,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QACrD,YAAmB,IAA+C;YACjE,KAAK,CAAC,IAAI,I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,MAAM,UAAU,GAIZ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACxB,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC5B,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE;YACvC,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,KAAK;YACnB,QAAQ,EAAE,KAAK;YACf,KAAK,EAAE,IAAI;SACX,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AACvC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\n\nimport type { SchemaFactory, ScopedSchemaName } from \"./schemaFactory.js\";\nimport type {\n\tNodeFromSchema,\n\tInternalTreeNode,\n\tNodeKind,\n\tTreeNode,\n\tTreeNodeSchema,\n\tTreeNodeSchemaClass,\n} from \"../core/index.js\";\nimport type { UnionToTuple } from \"../../util/index.js\";\n\n/*\n * This file does two things:\n *\n * 1. Provides tools for making schema for cases like enums.\n *\n * 2. Demonstrates the kinds of schema utilities apps can write.\n * Nothing in here needs access to package internal APIs.\n */\n\n/**\n * Create a schema for a node with no state.\n * @remarks\n * This is commonly used in unions when the only information needed is which kind of node the value is.\n * Enums are a common example of this pattern.\n * @see {@link adaptEnum}\n * @beta\n */\n// Return type is intentionally derived.\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function singletonSchema<TScope extends string, TName extends string | number>(\n\tfactory: SchemaFactory<TScope, TName>,\n\tname: TName,\n) {\n\tclass SingletonSchema extends factory.object(name, {}) {\n\t\tpublic constructor(data?: InternalTreeNode | Record<string, never>) {\n\t\t\tsuper(data ?? {});\n\t\t}\n\t\tpublic get value(): TName {\n\t\t\treturn name;\n\t\t}\n\n\t\tpublic static override toString(): string {\n\t\t\treturn `SingletonSchema(${name})`;\n\t\t}\n\n\t\tpublic static [Symbol.toStringTag] = `SingletonSchema(${name})`;\n\t}\n\n\ttype SingletonNodeType = TreeNode & { readonly value: TName };\n\n\t// Returning SingletonSchema without a type conversion results in TypeScript generating something like `readonly \"__#124291@#brand\": unknown;`\n\t// for the private brand field of TreeNode.\n\t// This numeric id doesn't seem to be stable over incremental builds, and thus causes diffs in the API extractor reports.\n\t// This is avoided by doing this type conversion.\n\t// The conversion is done via assignment instead of `as` to get stronger type safety.\n\tconst toReturn: TreeNodeSchemaClass<\n\t\tScopedSchemaName<TScope, TName>,\n\t\tNodeKind.Object,\n\t\tSingletonNodeType,\n\t\tRecord<string, never>,\n\t\ttrue,\n\t\tRecord<string, never>,\n\t\tundefined\n\t> = SingletonSchema;\n\n\treturn toReturn;\n}\n\n/**\n * Converts an enum into a collection of schema which can be used in a union.\n *\n * @typeParam TScope - The scope of the provided factory.\n * There is a known issue where if a factory is provided that is typed as a {@link SchemaFactoryAlpha}, and its scope contains a \".\" character,\n * the inferred type for the scope will end up as a union of the scope up to the first \".\" character and the scope as it should be.\n * This can be mitigated by explicitly providing the TScope type parameter or by typing the provided factory as a {@link SchemaFactory} instead of a {@link SchemaFactoryAlpha}.\n *\n * @remarks\n * The string value of the enum is used as the name of the schema: callers must ensure that it is stable and unique.\n * Numeric enums values have the value implicitly converted into a string.\n * Consider making a dedicated schema factory with a nested scope (for example using {@link SchemaFactoryAlpha.scopedFactory}) to avoid the enum members colliding with other schema.\n * @example\n * ```typescript\n * const schemaFactory = new SchemaFactory(\"com.myApp\");\n * // An enum for use in the tree. Must have string keys.\n * enum Mode {\n * \ta = \"A\",\n * \tb = \"B\",\n * }\n * // Define the schema for each member of the enum using a nested scope to group them together.\n * const ModeNodes = adaptEnum(new SchemaFactory(`${schemaFactory.scope}.Mode`), Mode);\n * // Defined the types of the nodes which correspond to this the schema.\n * type ModeNodes = TreeNodeFromImplicitAllowedTypes<(typeof ModeNodes.schema)>;\n * // An example schema which has an enum as a child.\n * class Parent extends schemaFactory.object(\"Parent\", {\n * \t// adaptEnum's return value has a \".schema\" property can be use as an `AllowedTypes` array allowing any of the members of the enum.\n * \tmode: ModeNodes.schema,\n * }) {}\n *\n * // Example usage of enum based nodes, showing what type to use and that `.value` can be used to read out the enum value.\n * function getValue(node: ModeNodes): Mode {\n * \treturn node.value;\n * }\n *\n * // Example constructing a tree containing an enum node from an enum value.\n * // The syntax `new ModeNodes.a()` is also supported.\n * function setValue(node: Parent): void {\n * \tnode.mode = ModeNodes(Mode.a);\n * }\n * ```\n * @privateRemarks\n * TODO: AB#43345: see TScope known issue above, and other references to this work item.\n *\n * @see {@link enumFromStrings} for a similar function that works on arrays of strings instead of an enum.\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function adaptEnum<\n\tTScope extends string,\n\tconst TEnum extends Record<string, string | number>,\n>(factory: SchemaFactory<TScope>, members: TEnum) {\n\ttype Values = TEnum[keyof TEnum];\n\tconst values = Object.values(members) as Values[];\n\tconst inverse = new Map(Object.entries(members).map(([key, value]) => [value, key])) as Map<\n\t\tValues,\n\t\tkeyof TEnum\n\t>;\n\n\tif (inverse.size !== values.length) {\n\t\tthrow new UsageError(\"All members of enums must have distinct values.\");\n\t}\n\n\ttype TOut = {\n\t\treadonly [Property in keyof TEnum]: ReturnType<\n\t\t\ttypeof singletonSchema<TScope, TEnum[Property]>\n\t\t>;\n\t};\n\n\ttype SchemaArray = UnionToTuple<TOut[keyof TEnum]>;\n\tconst schemaArray: TreeNodeSchema[] = [];\n\n\t// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n\tconst factoryOut = <TValue extends Values>(value: TValue) => {\n\t\treturn new out[\n\t\t\tinverse.get(value) ?? fail(0xb31 /* missing enum value */)\n\t\t\t// \"extends unknown\" is required here to handle when TValue is an union: each member of the union should be processed independently.\n\t\t]() as TValue extends unknown\n\t\t\t? NodeFromSchema<ReturnType<typeof singletonSchema<TScope, TValue>>>\n\t\t\t: never;\n\t};\n\tconst out = factoryOut as typeof factoryOut & TOut & { readonly schema: SchemaArray };\n\tfor (const [key, value] of enumEntries(members)) {\n\t\tconst schema = singletonSchema(factory, value);\n\t\tschemaArray.push(schema);\n\t\tObject.defineProperty(out, key, {\n\t\t\tenumerable: true,\n\t\t\tconfigurable: false,\n\t\t\twritable: false,\n\t\t\tvalue: schema,\n\t\t});\n\t}\n\n\tObject.defineProperty(out, \"schema\", {\n\t\tenumerable: true,\n\t\tconfigurable: false,\n\t\twritable: false,\n\t\tvalue: schemaArray,\n\t});\n\n\treturn out;\n}\n\n/**\n * Returns en \"entries\" (like Object.entries) for an enum object, omitting the\n * {@link https://www.typescriptlang.org/docs/handbook/enums.html#reverse-mappings|reverse mappings}\n */\nexport function enumEntries(\n\tenumObject: Record<string, string | number>,\n): [string, string | number][] {\n\t// Skip reverse mapping for numeric entries.\n\t// For numeric entries, TypeScript defines an additional property keyed with the number implicitly converted to a string.\n\t// Note TypeScript can overwrite its own enum entries in some edge cases (see https://github.com/microsoft/TypeScript/issues/48956), so it's not possible to handle all cases correctly.\n\treturn Object.entries(enumObject).filter(([key, value]) => {\n\t\t// All reverse mapping must also have a inverse mapping (the regular forward mapping) to a number:\n\t\tconst inverse = enumObject[value];\n\t\tif (typeof inverse !== \"number\") {\n\t\t\t// Known not to be a reverse mapping, so keep it.\n\t\t\treturn true;\n\t\t}\n\t\t// At this point, it is expected that all remaining cases are reverse mappings,\n\t\t// but do some asserts to ensure that the above logic is sufficient.\n\t\tassert(\n\t\t\ttypeof value === \"string\",\n\t\t\t0xbe4 /* expected reverse mapping and thus a string value */,\n\t\t);\n\t\tassert(\n\t\t\tNumber.parseFloat(key).toString() === key,\n\t\t\t0xbe5 /* expected reverse mapping and thus a key that is a normalized number */,\n\t\t);\n\t\t// Discard the reverse mapping.\n\t\treturn false;\n\t});\n}\n\n/**\n * Converts an array of distinct strings into a collection of schema which can be used like an enum style union.\n * @remarks\n * The returned collection is also a function which can be used to convert strings into {@link Unhydrated} nodes in the union.\n * Each node type has a `.value` getter which returns the associated string.\n *\n * The produced nodes use the provided strings as their `name`, and don't store any data beyond that.\n * @example\n * ```typescript\n * const schemaFactory = new SchemaFactory(\"com.myApp\");\n * const Mode = enumFromStrings(schemaFactory, [\"Fun\", \"Cool\"]);\n * type Mode = TreeNodeFromImplicitAllowedTypes<typeof Mode.schema>;\n * const nodeFromString: Mode = Mode(\"Fun\");\n * const nodeFromSchema: Mode = new Mode.Fun();\n *\n * // Schema nodes have a strongly typed `.value` property.\n * const nameFromNode: \"Fun\" | \"Cool\" = nodeFromSchema.value;\n *\n * class Parent extends schemaFactory.object(\"Parent\", { mode: Mode.schema }) {}\n * ```\n * @see {@link adaptEnum} for a similar function that works on enums instead of arrays of strings.\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function enumFromStrings<\n\tTScope extends string,\n\tconst Members extends readonly string[],\n>(factory: SchemaFactory<TScope>, members: Members) {\n\tconst names = new Set(members);\n\tif (names.size !== members.length) {\n\t\tthrow new UsageError(\"All members of enums must have distinct names\");\n\t}\n\n\ttype MembersUnion = Members[number];\n\n\t// Get all keys of the Members tuple which are numeric strings as union of numbers:\n\ttype Indexes = Extract<keyof Members, `${number}`> extends `${infer N extends number}`\n\t\t? N\n\t\t: never;\n\n\ttype TOut = {\n\t\t[Index in Indexes as Members[Index]]: ReturnType<\n\t\t\ttypeof singletonSchema<TScope, Members[Index] & string>\n\t\t>;\n\t};\n\n\t// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n\tconst factoryOut = <TValue extends MembersUnion>(value: TValue) => {\n\t\t// \"extends unknown\" is required here to handle when TValue is an union: each member of the union should be processed independently.\n\t\treturn new recordOut[value]() as TValue extends unknown\n\t\t\t? NodeFromSchema<ReturnType<typeof singletonSchema<TScope, TValue>>>\n\t\t\t: never;\n\t};\n\n\ttype SchemaArray = UnionToTuple<MembersUnion extends unknown ? TOut[MembersUnion] : never>;\n\tconst schemaArray: TreeNodeSchema[] = [];\n\n\tconst out = factoryOut as typeof factoryOut & TOut & { readonly schema: SchemaArray };\n\tconst recordOut = out as Record<MembersUnion, new () => unknown>;\n\tfor (const name of members) {\n\t\tconst schema = singletonSchema(factory, name);\n\t\tschemaArray.push(schema);\n\t\tObject.defineProperty(out, name, {\n\t\t\tenumerable: true,\n\t\t\tconfigurable: false,\n\t\t\twritable: false,\n\t\t\tvalue: schema,\n\t\t});\n\t}\n\n\tObject.defineProperty(out, \"schema\", {\n\t\tenumerable: true,\n\t\tconfigurable: false,\n\t\twritable: false,\n\t\tvalue: schemaArray,\n\t});\n\n\treturn out;\n}\n\n// TODO: This generates an invalid d.ts file if exported due to a bug https://github.com/microsoft/TypeScript/issues/58688.\n// TODO: replace enumFromStrings above with this simpler implementation when the TypeScript bug is resolved.\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nfunction _enumFromStrings2<TScope extends string, const Members extends readonly string[]>(\n\tfactory: SchemaFactory<TScope>,\n\tmembers: Members,\n) {\n\tconst enumObject: {\n\t\t[key in keyof Members as Members[key] extends string\n\t\t\t? Members[key]\n\t\t\t: string]: Members[key] extends string ? Members[key] : string;\n\t} = Object.create(null);\n\tfor (const name of members) {\n\t\tObject.defineProperty(enumObject, name, {\n\t\t\tenumerable: true,\n\t\t\tconfigurable: false,\n\t\t\twritable: false,\n\t\t\tvalue: name,\n\t\t});\n\t}\n\n\treturn adaptEnum(factory, enumObject);\n}\n"]}
1
+ {"version":3,"file":"schemaCreationUtilities.js","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaCreationUtilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAanE;;;;;;;GAOG;AAEH;;;;;;;GAOG;AACH,wCAAwC;AACxC,4EAA4E;AAC5E,MAAM,UAAU,eAAe,CAC9B,OAAqC,E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H,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,2HAA2H;AAC3H,4GAA4G;AAC5G,4EAA4E;AAC5E,SAAS,iBAAiB,CACzB,OAA8B,EAC9B,OAAgB;IAEhB,MAAM,UAAU,GAIZ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACxB,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC5B,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE;YACvC,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,KAAK;YACnB,QAAQ,EAAE,KAAK;YACf,KAAK,EAAE,IAAI;SACX,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AACvC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\n\nimport type { SchemaFactory, ScopedSchemaName } from \"./schemaFactory.js\";\nimport type {\n\tNodeFromSchema,\n\tInternalTreeNode,\n\tNodeKind,\n\tTreeNode,\n\tTreeNodeSchema,\n\tTreeNodeSchemaClass,\n} from \"../core/index.js\";\nimport type { UnionToTuple } from \"../../util/index.js\";\n\n/*\n * This file does two things:\n *\n * 1. Provides tools for making schema for cases like enums.\n *\n * 2. Demonstrates the kinds of schema utilities apps can write.\n * Nothing in here needs access to package internal APIs.\n */\n\n/**\n * Create a schema for a node with no state.\n * @remarks\n * This is commonly used in unions when the only information needed is which kind of node the value is.\n * Enums are a common example of this pattern.\n * @see {@link adaptEnum}\n * @beta\n */\n// Return type is intentionally derived.\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function singletonSchema<TScope extends string, TName extends string | number>(\n\tfactory: SchemaFactory<TScope, TName>,\n\tname: TName,\n) {\n\tclass SingletonSchema extends factory.object(name, {}) {\n\t\tpublic constructor(data?: InternalTreeNode | Record<string, never>) {\n\t\t\tsuper(data ?? {});\n\t\t}\n\t\tpublic get value(): TName {\n\t\t\treturn name;\n\t\t}\n\n\t\tpublic static override toString(): string {\n\t\t\treturn `SingletonSchema(${name})`;\n\t\t}\n\n\t\tpublic static [Symbol.toStringTag] = `SingletonSchema(${name})`;\n\t}\n\n\ttype SingletonNodeType = TreeNode & { readonly value: TName };\n\n\t// Returning SingletonSchema without a type conversion results in TypeScript generating something like `readonly \"__#124291@#brand\": unknown;`\n\t// for the private brand field of TreeNode.\n\t// This numeric id doesn't seem to be stable over incremental builds, and thus causes diffs in the API extractor reports.\n\t// This is avoided by doing this type conversion.\n\t// The conversion is done via assignment instead of `as` to get stronger type safety.\n\tconst toReturn: TreeNodeSchemaClass<\n\t\tScopedSchemaName<TScope, TName>,\n\t\tNodeKind.Object,\n\t\tSingletonNodeType,\n\t\tRecord<string, never>,\n\t\ttrue,\n\t\tRecord<string, never>,\n\t\tundefined\n\t> = SingletonSchema;\n\n\treturn toReturn;\n}\n\n/**\n * Converts an enum into a collection of schema which can be used in a union.\n *\n * @typeParam TScope - The scope of the provided factory.\n * There is a known issue where if a factory is provided that is typed as a {@link SchemaFactoryAlpha}, and its scope contains a \".\" character,\n * the inferred type for the scope will end up as a union of the scope up to the first \".\" character and the scope as it should be.\n * This can be mitigated by explicitly providing the TScope type parameter or by typing the provided factory as a {@link SchemaFactory} instead of a {@link SchemaFactoryAlpha}.\n *\n * @remarks\n * The string value of the enum is used as the name of the schema: callers must ensure that it is stable and unique.\n * Numeric enums values have the value implicitly converted into a string.\n * Consider making a dedicated schema factory with a nested scope (for example using {@link SchemaFactoryBeta.scopedFactory}) to avoid the enum members colliding with other schema.\n * @example\n * ```typescript\n * const schemaFactory = new SchemaFactory(\"com.myApp\");\n * // An enum for use in the tree. Must have string keys.\n * enum Mode {\n * \ta = \"A\",\n * \tb = \"B\",\n * }\n * // Define the schema for each member of the enum using a nested scope to group them together.\n * const ModeNodes = adaptEnum(new SchemaFactory(`${schemaFactory.scope}.Mode`), Mode);\n * // Defined the types of the nodes which correspond to this the schema.\n * type ModeNodes = TreeNodeFromImplicitAllowedTypes<(typeof ModeNodes.schema)>;\n * // An example schema which has an enum as a child.\n * class Parent extends schemaFactory.object(\"Parent\", {\n * \t// adaptEnum's return value has a \".schema\" property can be use as an `AllowedTypes` array allowing any of the members of the enum.\n * \tmode: ModeNodes.schema,\n * }) {}\n *\n * // Example usage of enum based nodes, showing what type to use and that `.value` can be used to read out the enum value.\n * function getValue(node: ModeNodes): Mode {\n * \treturn node.value;\n * }\n *\n * // Example constructing a tree containing an enum node from an enum value.\n * // The syntax `new ModeNodes.a()` is also supported.\n * function setValue(node: Parent): void {\n * \tnode.mode = ModeNodes(Mode.a);\n * }\n * ```\n * @privateRemarks\n * TODO: AB#43345: see TScope known issue above, and other references to this work item.\n *\n * @see {@link enumFromStrings} for a similar function that works on arrays of strings instead of an enum.\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function adaptEnum<\n\tTScope extends string,\n\tconst TEnum extends Record<string, string | number>,\n>(factory: SchemaFactory<TScope>, members: TEnum) {\n\ttype Values = TEnum[keyof TEnum];\n\tconst values = Object.values(members) as Values[];\n\tconst inverse = new Map(Object.entries(members).map(([key, value]) => [value, key])) as Map<\n\t\tValues,\n\t\tkeyof TEnum\n\t>;\n\n\tif (inverse.size !== values.length) {\n\t\tthrow new UsageError(\"All members of enums must have distinct values.\");\n\t}\n\n\ttype TOut = {\n\t\treadonly [Property in keyof TEnum]: ReturnType<\n\t\t\ttypeof singletonSchema<TScope, TEnum[Property]>\n\t\t>;\n\t};\n\n\ttype SchemaArray = UnionToTuple<TOut[keyof TEnum]>;\n\tconst schemaArray: TreeNodeSchema[] = [];\n\n\t// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n\tconst factoryOut = <TValue extends Values>(value: TValue) => {\n\t\treturn new out[\n\t\t\tinverse.get(value) ?? fail(0xb31 /* missing enum value */)\n\t\t\t// \"extends unknown\" is required here to handle when TValue is an union: each member of the union should be processed independently.\n\t\t]() as TValue extends unknown\n\t\t\t? NodeFromSchema<ReturnType<typeof singletonSchema<TScope, TValue>>>\n\t\t\t: never;\n\t};\n\tconst out = factoryOut as typeof factoryOut & TOut & { readonly schema: SchemaArray };\n\tfor (const [key, value] of enumEntries(members)) {\n\t\tconst schema = singletonSchema(factory, value);\n\t\tschemaArray.push(schema);\n\t\tObject.defineProperty(out, key, {\n\t\t\tenumerable: true,\n\t\t\tconfigurable: false,\n\t\t\twritable: false,\n\t\t\tvalue: schema,\n\t\t});\n\t}\n\n\tObject.defineProperty(out, \"schema\", {\n\t\tenumerable: true,\n\t\tconfigurable: false,\n\t\twritable: false,\n\t\tvalue: schemaArray,\n\t});\n\n\treturn out;\n}\n\n/**\n * Returns en \"entries\" (like Object.entries) for an enum object, omitting the\n * {@link https://www.typescriptlang.org/docs/handbook/enums.html#reverse-mappings|reverse mappings}\n */\nexport function enumEntries(\n\tenumObject: Record<string, string | number>,\n): [string, string | number][] {\n\t// Skip reverse mapping for numeric entries.\n\t// For numeric entries, TypeScript defines an additional property keyed with the number implicitly converted to a string.\n\t// Note TypeScript can overwrite its own enum entries in some edge cases (see https://github.com/microsoft/TypeScript/issues/48956), so it's not possible to handle all cases correctly.\n\treturn Object.entries(enumObject).filter(([key, value]) => {\n\t\t// All reverse mapping must also have a inverse mapping (the regular forward mapping) to a number:\n\t\tconst inverse = enumObject[value];\n\t\tif (typeof inverse !== \"number\") {\n\t\t\t// Known not to be a reverse mapping, so keep it.\n\t\t\treturn true;\n\t\t}\n\t\t// At this point, it is expected that all remaining cases are reverse mappings,\n\t\t// but do some asserts to ensure that the above logic is sufficient.\n\t\tassert(\n\t\t\ttypeof value === \"string\",\n\t\t\t0xbe4 /* expected reverse mapping and thus a string value */,\n\t\t);\n\t\tassert(\n\t\t\tNumber.parseFloat(key).toString() === key,\n\t\t\t0xbe5 /* expected reverse mapping and thus a key that is a normalized number */,\n\t\t);\n\t\t// Discard the reverse mapping.\n\t\treturn false;\n\t});\n}\n\n/**\n * Converts an array of distinct strings into a collection of schema which can be used like an enum style union.\n * @remarks\n * The returned collection is also a function which can be used to convert strings into {@link Unhydrated} nodes in the union.\n * Each node type has a `.value` getter which returns the associated string.\n *\n * The produced nodes use the provided strings as their `name`, and don't store any data beyond that.\n * @example\n * ```typescript\n * const schemaFactory = new SchemaFactory(\"com.myApp\");\n * const Mode = enumFromStrings(schemaFactory, [\"Fun\", \"Cool\"]);\n * type Mode = TreeNodeFromImplicitAllowedTypes<typeof Mode.schema>;\n * const nodeFromString: Mode = Mode(\"Fun\");\n * const nodeFromSchema: Mode = new Mode.Fun();\n *\n * // Schema nodes have a strongly typed `.value` property.\n * const nameFromNode: \"Fun\" | \"Cool\" = nodeFromSchema.value;\n *\n * class Parent extends schemaFactory.object(\"Parent\", { mode: Mode.schema }) {}\n * ```\n * @see {@link adaptEnum} for a similar function that works on enums instead of arrays of strings.\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function enumFromStrings<\n\tTScope extends string,\n\tconst Members extends readonly string[],\n>(factory: SchemaFactory<TScope>, members: Members) {\n\tconst names = new Set(members);\n\tif (names.size !== members.length) {\n\t\tthrow new UsageError(\"All members of enums must have distinct names\");\n\t}\n\n\ttype MembersUnion = Members[number];\n\n\t// Get all keys of the Members tuple which are numeric strings as union of numbers:\n\ttype Indexes = Extract<keyof Members, `${number}`> extends `${infer N extends number}`\n\t\t? N\n\t\t: never;\n\n\ttype TOut = {\n\t\t[Index in Indexes as Members[Index]]: ReturnType<\n\t\t\ttypeof singletonSchema<TScope, Members[Index] & string>\n\t\t>;\n\t};\n\n\t// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n\tconst factoryOut = <TValue extends MembersUnion>(value: TValue) => {\n\t\t// \"extends unknown\" is required here to handle when TValue is an union: each member of the union should be processed independently.\n\t\treturn new recordOut[value]() as TValue extends unknown\n\t\t\t? NodeFromSchema<ReturnType<typeof singletonSchema<TScope, TValue>>>\n\t\t\t: never;\n\t};\n\n\ttype SchemaArray = UnionToTuple<MembersUnion extends unknown ? TOut[MembersUnion] : never>;\n\tconst schemaArray: TreeNodeSchema[] = [];\n\n\tconst out = factoryOut as typeof factoryOut & TOut & { readonly schema: SchemaArray };\n\tconst recordOut = out as Record<MembersUnion, new () => unknown>;\n\tfor (const name of members) {\n\t\tconst schema = singletonSchema(factory, name);\n\t\tschemaArray.push(schema);\n\t\tObject.defineProperty(out, name, {\n\t\t\tenumerable: true,\n\t\t\tconfigurable: false,\n\t\t\twritable: false,\n\t\t\tvalue: schema,\n\t\t});\n\t}\n\n\tObject.defineProperty(out, \"schema\", {\n\t\tenumerable: true,\n\t\tconfigurable: false,\n\t\twritable: false,\n\t\tvalue: schemaArray,\n\t});\n\n\treturn out;\n}\n\n// TODO: This generates an invalid d.ts file if exported due to a bug https://github.com/microsoft/TypeScript/issues/58688.\n// TODO: replace enumFromStrings above with this simpler implementation when the TypeScript bug is resolved.\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nfunction _enumFromStrings2<TScope extends string, const Members extends readonly string[]>(\n\tfactory: SchemaFactory<TScope>,\n\tmembers: Members,\n) {\n\tconst enumObject: {\n\t\t[key in keyof Members as Members[key] extends string\n\t\t\t? Members[key]\n\t\t\t: string]: Members[key] extends string ? Members[key] : string;\n\t} = Object.create(null);\n\tfor (const name of members) {\n\t\tObject.defineProperty(enumObject, name, {\n\t\t\tenumerable: true,\n\t\t\tconfigurable: false,\n\t\t\twritable: false,\n\t\t\tvalue: name,\n\t\t});\n\t}\n\n\treturn adaptEnum(factory, enumObject);\n}\n"]}