@fluidframework/tree 2.51.0 → 2.52.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 (579) hide show
  1. package/.vscode/settings.json +0 -1
  2. package/CHANGELOG.md +43 -0
  3. package/api-report/tree.alpha.api.md +3 -2
  4. package/dist/codec/codec.d.ts +2 -1
  5. package/dist/codec/codec.d.ts.map +1 -1
  6. package/dist/codec/codec.js +4 -3
  7. package/dist/codec/codec.js.map +1 -1
  8. package/dist/core/index.d.ts +1 -1
  9. package/dist/core/index.d.ts.map +1 -1
  10. package/dist/core/index.js +3 -2
  11. package/dist/core/index.js.map +1 -1
  12. package/dist/core/rebase/index.d.ts +1 -1
  13. package/dist/core/rebase/index.d.ts.map +1 -1
  14. package/dist/core/rebase/index.js +2 -1
  15. package/dist/core/rebase/index.js.map +1 -1
  16. package/dist/core/rebase/types.d.ts +3 -1
  17. package/dist/core/rebase/types.d.ts.map +1 -1
  18. package/dist/core/rebase/types.js +2 -1
  19. package/dist/core/rebase/types.js.map +1 -1
  20. package/dist/core/schema-stored/schema.d.ts +1 -23
  21. package/dist/core/schema-stored/schema.d.ts.map +1 -1
  22. package/dist/core/schema-stored/schema.js +2 -2
  23. package/dist/core/schema-stored/schema.js.map +1 -1
  24. package/dist/core/tree/detachedFieldIndex.d.ts.map +1 -1
  25. package/dist/core/tree/detachedFieldIndex.js +2 -3
  26. package/dist/core/tree/detachedFieldIndex.js.map +1 -1
  27. package/dist/core/tree/detachedFieldIndexCodecCommon.d.ts +17 -0
  28. package/dist/core/tree/detachedFieldIndexCodecCommon.d.ts.map +1 -0
  29. package/dist/core/tree/detachedFieldIndexCodecCommon.js +68 -0
  30. package/dist/core/tree/detachedFieldIndexCodecCommon.js.map +1 -0
  31. package/dist/core/tree/detachedFieldIndexCodecV1.d.ts +11 -0
  32. package/dist/core/tree/detachedFieldIndexCodecV1.d.ts.map +1 -0
  33. package/dist/core/tree/detachedFieldIndexCodecV1.js +55 -0
  34. package/dist/core/tree/detachedFieldIndexCodecV1.js.map +1 -0
  35. package/dist/core/tree/detachedFieldIndexCodecV2.d.ts +11 -0
  36. package/dist/core/tree/detachedFieldIndexCodecV2.d.ts.map +1 -0
  37. package/dist/core/tree/detachedFieldIndexCodecV2.js +49 -0
  38. package/dist/core/tree/detachedFieldIndexCodecV2.js.map +1 -0
  39. package/dist/core/tree/detachedFieldIndexCodecs.d.ts +11 -0
  40. package/dist/core/tree/detachedFieldIndexCodecs.d.ts.map +1 -0
  41. package/dist/core/tree/detachedFieldIndexCodecs.js +26 -0
  42. package/dist/core/tree/detachedFieldIndexCodecs.js.map +1 -0
  43. package/dist/core/tree/detachedFieldIndexFormatCommon.d.ts +37 -0
  44. package/dist/core/tree/detachedFieldIndexFormatCommon.d.ts.map +1 -0
  45. package/dist/core/tree/{detachedFieldIndexFormat.js → detachedFieldIndexFormatCommon.js} +18 -13
  46. package/dist/core/tree/detachedFieldIndexFormatCommon.js.map +1 -0
  47. package/dist/core/tree/detachedFieldIndexFormatV1.d.ts +13 -0
  48. package/dist/core/tree/detachedFieldIndexFormatV1.d.ts.map +1 -0
  49. package/dist/core/tree/detachedFieldIndexFormatV1.js +12 -0
  50. package/dist/core/tree/detachedFieldIndexFormatV1.js.map +1 -0
  51. package/dist/core/tree/detachedFieldIndexFormatV2.d.ts +14 -0
  52. package/dist/core/tree/detachedFieldIndexFormatV2.d.ts.map +1 -0
  53. package/dist/core/tree/detachedFieldIndexFormatV2.js +14 -0
  54. package/dist/core/tree/detachedFieldIndexFormatV2.js.map +1 -0
  55. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +9 -9
  56. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  57. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js +21 -21
  58. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  59. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts +4 -2
  60. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts.map +1 -1
  61. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js +4 -4
  62. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js.map +1 -1
  63. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +50 -31
  64. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
  65. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js +74 -61
  66. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  67. package/dist/feature-libraries/chunked-forest/codec/format.d.ts +20 -14
  68. package/dist/feature-libraries/chunked-forest/codec/format.d.ts.map +1 -1
  69. package/dist/feature-libraries/chunked-forest/codec/format.js +18 -12
  70. package/dist/feature-libraries/chunked-forest/codec/format.js.map +1 -1
  71. package/{lib/feature-libraries/chunked-forest/codec/nodeShape.d.ts → dist/feature-libraries/chunked-forest/codec/nodeEncoder.d.ts} +20 -14
  72. package/dist/feature-libraries/chunked-forest/codec/nodeEncoder.d.ts.map +1 -0
  73. package/dist/feature-libraries/chunked-forest/codec/{nodeShape.js → nodeEncoder.js} +23 -17
  74. package/dist/feature-libraries/chunked-forest/codec/nodeEncoder.js.map +1 -0
  75. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts +7 -7
  76. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts.map +1 -1
  77. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.js +22 -22
  78. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.js.map +1 -1
  79. package/dist/feature-libraries/chunked-forest/codec/uncompressedEncode.js +2 -2
  80. package/dist/feature-libraries/chunked-forest/codec/uncompressedEncode.js.map +1 -1
  81. package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts +5 -1
  82. package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  83. package/dist/feature-libraries/default-schema/defaultFieldKinds.js +14 -2
  84. package/dist/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  85. package/dist/feature-libraries/default-schema/defaultSchema.d.ts.map +1 -1
  86. package/dist/feature-libraries/default-schema/defaultSchema.js +0 -2
  87. package/dist/feature-libraries/default-schema/defaultSchema.js.map +1 -1
  88. package/dist/feature-libraries/default-schema/index.d.ts +1 -1
  89. package/dist/feature-libraries/default-schema/index.d.ts.map +1 -1
  90. package/dist/feature-libraries/default-schema/index.js +2 -2
  91. package/dist/feature-libraries/default-schema/index.js.map +1 -1
  92. package/dist/feature-libraries/default-schema/schemaChecker.d.ts +14 -4
  93. package/dist/feature-libraries/default-schema/schemaChecker.d.ts.map +1 -1
  94. package/dist/feature-libraries/default-schema/schemaChecker.js +31 -26
  95. package/dist/feature-libraries/default-schema/schemaChecker.js.map +1 -1
  96. package/dist/feature-libraries/index.d.ts +1 -2
  97. package/dist/feature-libraries/index.d.ts.map +1 -1
  98. package/dist/feature-libraries/index.js +2 -4
  99. package/dist/feature-libraries/index.js.map +1 -1
  100. package/dist/feature-libraries/modular-schema/comparison.d.ts +5 -6
  101. package/dist/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
  102. package/dist/feature-libraries/modular-schema/comparison.js +15 -16
  103. package/dist/feature-libraries/modular-schema/comparison.js.map +1 -1
  104. package/dist/feature-libraries/modular-schema/modularChangeFormat.d.ts +9 -3
  105. package/dist/feature-libraries/modular-schema/modularChangeFormat.d.ts.map +1 -1
  106. package/dist/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
  107. package/dist/feature-libraries/object-forest/objectForest.js +2 -3
  108. package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
  109. package/dist/index.d.ts +1 -1
  110. package/dist/index.d.ts.map +1 -1
  111. package/dist/index.js +6 -2
  112. package/dist/index.js.map +1 -1
  113. package/dist/packageVersion.d.ts +1 -1
  114. package/dist/packageVersion.js +1 -1
  115. package/dist/packageVersion.js.map +1 -1
  116. package/dist/shared-tree/independentView.d.ts +8 -0
  117. package/dist/shared-tree/independentView.d.ts.map +1 -1
  118. package/dist/shared-tree/independentView.js +23 -11
  119. package/dist/shared-tree/independentView.js.map +1 -1
  120. package/dist/shared-tree/schematizeTree.js +1 -1
  121. package/dist/shared-tree/schematizeTree.js.map +1 -1
  122. package/dist/shared-tree/schematizingTreeView.d.ts +0 -1
  123. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  124. package/dist/shared-tree/schematizingTreeView.js +7 -10
  125. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  126. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  127. package/dist/shared-tree/sharedTree.js +1 -29
  128. package/dist/shared-tree/sharedTree.js.map +1 -1
  129. package/dist/shared-tree/treeAlpha.d.ts +20 -6
  130. package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
  131. package/dist/shared-tree/treeAlpha.js +9 -4
  132. package/dist/shared-tree/treeAlpha.js.map +1 -1
  133. package/dist/shared-tree/treeCheckout.d.ts +2 -1
  134. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  135. package/dist/shared-tree/treeCheckout.js +32 -0
  136. package/dist/shared-tree/treeCheckout.js.map +1 -1
  137. package/dist/shared-tree-core/branch.d.ts.map +1 -1
  138. package/dist/shared-tree-core/branch.js +1 -1
  139. package/dist/shared-tree-core/branch.js.map +1 -1
  140. package/dist/simple-tree/api/conciseTree.d.ts +2 -2
  141. package/dist/simple-tree/api/conciseTree.d.ts.map +1 -1
  142. package/dist/simple-tree/api/conciseTree.js +6 -6
  143. package/dist/simple-tree/api/conciseTree.js.map +1 -1
  144. package/dist/simple-tree/api/configuration.d.ts +8 -2
  145. package/dist/simple-tree/api/configuration.d.ts.map +1 -1
  146. package/dist/simple-tree/api/configuration.js.map +1 -1
  147. package/dist/simple-tree/api/create.d.ts +8 -7
  148. package/dist/simple-tree/api/create.d.ts.map +1 -1
  149. package/dist/simple-tree/api/create.js +35 -22
  150. package/dist/simple-tree/api/create.js.map +1 -1
  151. package/dist/simple-tree/api/customTree.d.ts +25 -4
  152. package/dist/simple-tree/api/customTree.d.ts.map +1 -1
  153. package/dist/simple-tree/api/customTree.js +42 -16
  154. package/dist/simple-tree/api/customTree.js.map +1 -1
  155. package/dist/simple-tree/api/discrepancies.d.ts +98 -0
  156. package/dist/simple-tree/api/discrepancies.d.ts.map +1 -0
  157. package/dist/simple-tree/api/discrepancies.js +255 -0
  158. package/dist/simple-tree/api/discrepancies.js.map +1 -0
  159. package/dist/simple-tree/api/schemaCompatibilityTester.d.ts +9 -7
  160. package/dist/simple-tree/api/schemaCompatibilityTester.d.ts.map +1 -1
  161. package/dist/simple-tree/api/schemaCompatibilityTester.js +18 -117
  162. package/dist/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
  163. package/dist/simple-tree/api/schemaFactory.d.ts +7 -4
  164. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  165. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  166. package/dist/simple-tree/api/storedSchema.d.ts.map +1 -1
  167. package/dist/simple-tree/api/storedSchema.js +5 -1
  168. package/dist/simple-tree/api/storedSchema.js.map +1 -1
  169. package/dist/simple-tree/api/treeBeta.d.ts +2 -2
  170. package/dist/simple-tree/api/treeBeta.d.ts.map +1 -1
  171. package/dist/simple-tree/api/treeBeta.js +10 -4
  172. package/dist/simple-tree/api/treeBeta.js.map +1 -1
  173. package/dist/simple-tree/api/verboseTree.d.ts +2 -2
  174. package/dist/simple-tree/api/verboseTree.d.ts.map +1 -1
  175. package/dist/simple-tree/api/verboseTree.js +15 -15
  176. package/dist/simple-tree/api/verboseTree.js.map +1 -1
  177. package/dist/simple-tree/core/allowedTypes.d.ts +20 -4
  178. package/dist/simple-tree/core/allowedTypes.d.ts.map +1 -1
  179. package/dist/simple-tree/core/allowedTypes.js +45 -13
  180. package/dist/simple-tree/core/allowedTypes.js.map +1 -1
  181. package/dist/simple-tree/core/context.d.ts +13 -2
  182. package/dist/simple-tree/core/context.d.ts.map +1 -1
  183. package/dist/simple-tree/core/context.js +22 -9
  184. package/dist/simple-tree/core/context.js.map +1 -1
  185. package/dist/simple-tree/core/index.d.ts +2 -2
  186. package/dist/simple-tree/core/index.d.ts.map +1 -1
  187. package/dist/simple-tree/core/index.js +3 -1
  188. package/dist/simple-tree/core/index.js.map +1 -1
  189. package/dist/simple-tree/core/treeNodeKernel.d.ts +1 -1
  190. package/dist/simple-tree/core/treeNodeKernel.js +1 -1
  191. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  192. package/dist/simple-tree/core/treeNodeValid.d.ts +1 -1
  193. package/dist/simple-tree/core/treeNodeValid.d.ts.map +1 -1
  194. package/dist/simple-tree/core/treeNodeValid.js +8 -1
  195. package/dist/simple-tree/core/treeNodeValid.js.map +1 -1
  196. package/dist/simple-tree/core/walkSchema.d.ts +3 -0
  197. package/dist/simple-tree/core/walkSchema.d.ts.map +1 -1
  198. package/dist/simple-tree/core/walkSchema.js +2 -0
  199. package/dist/simple-tree/core/walkSchema.js.map +1 -1
  200. package/dist/simple-tree/createContext.d.ts +2 -0
  201. package/dist/simple-tree/createContext.d.ts.map +1 -1
  202. package/dist/simple-tree/createContext.js +3 -1
  203. package/dist/simple-tree/createContext.js.map +1 -1
  204. package/dist/simple-tree/fieldSchema.d.ts +1 -0
  205. package/dist/simple-tree/fieldSchema.d.ts.map +1 -1
  206. package/dist/simple-tree/fieldSchema.js +1 -0
  207. package/dist/simple-tree/fieldSchema.js.map +1 -1
  208. package/dist/simple-tree/index.d.ts +4 -4
  209. package/dist/simple-tree/index.d.ts.map +1 -1
  210. package/dist/simple-tree/index.js +7 -8
  211. package/dist/simple-tree/index.js.map +1 -1
  212. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  213. package/dist/simple-tree/node-kinds/array/arrayNode.js +1 -1
  214. package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  215. package/dist/simple-tree/node-kinds/index.d.ts +1 -1
  216. package/dist/simple-tree/node-kinds/index.d.ts.map +1 -1
  217. package/dist/simple-tree/node-kinds/index.js +1 -2
  218. package/dist/simple-tree/node-kinds/index.js.map +1 -1
  219. package/dist/simple-tree/node-kinds/object/index.d.ts +1 -1
  220. package/dist/simple-tree/node-kinds/object/index.d.ts.map +1 -1
  221. package/dist/simple-tree/node-kinds/object/index.js +1 -2
  222. package/dist/simple-tree/node-kinds/object/index.js.map +1 -1
  223. package/dist/simple-tree/node-kinds/object/objectNode.d.ts +2 -7
  224. package/dist/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  225. package/dist/simple-tree/node-kinds/object/objectNode.js +4 -18
  226. package/dist/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  227. package/dist/simple-tree/prepareForInsertion.d.ts +5 -5
  228. package/dist/simple-tree/prepareForInsertion.d.ts.map +1 -1
  229. package/dist/simple-tree/prepareForInsertion.js +9 -3
  230. package/dist/simple-tree/prepareForInsertion.js.map +1 -1
  231. package/dist/simple-tree/toStoredSchema.d.ts +3 -0
  232. package/dist/simple-tree/toStoredSchema.d.ts.map +1 -1
  233. package/dist/simple-tree/toStoredSchema.js +3 -0
  234. package/dist/simple-tree/toStoredSchema.js.map +1 -1
  235. package/dist/simple-tree/unhydratedFlexTreeFromInsertable.d.ts +2 -2
  236. package/dist/simple-tree/unhydratedFlexTreeFromInsertable.d.ts.map +1 -1
  237. package/dist/simple-tree/unhydratedFlexTreeFromInsertable.js.map +1 -1
  238. package/dist/simple-tree/walkFieldSchema.d.ts +1 -0
  239. package/dist/simple-tree/walkFieldSchema.d.ts.map +1 -1
  240. package/dist/simple-tree/walkFieldSchema.js +1 -0
  241. package/dist/simple-tree/walkFieldSchema.js.map +1 -1
  242. package/lib/codec/codec.d.ts +2 -1
  243. package/lib/codec/codec.d.ts.map +1 -1
  244. package/lib/codec/codec.js +4 -3
  245. package/lib/codec/codec.js.map +1 -1
  246. package/lib/core/index.d.ts +1 -1
  247. package/lib/core/index.d.ts.map +1 -1
  248. package/lib/core/index.js +1 -1
  249. package/lib/core/index.js.map +1 -1
  250. package/lib/core/rebase/index.d.ts +1 -1
  251. package/lib/core/rebase/index.d.ts.map +1 -1
  252. package/lib/core/rebase/index.js +1 -1
  253. package/lib/core/rebase/index.js.map +1 -1
  254. package/lib/core/rebase/types.d.ts +3 -1
  255. package/lib/core/rebase/types.d.ts.map +1 -1
  256. package/lib/core/rebase/types.js +1 -0
  257. package/lib/core/rebase/types.js.map +1 -1
  258. package/lib/core/schema-stored/schema.d.ts +1 -23
  259. package/lib/core/schema-stored/schema.d.ts.map +1 -1
  260. package/lib/core/schema-stored/schema.js +2 -2
  261. package/lib/core/schema-stored/schema.js.map +1 -1
  262. package/lib/core/tree/detachedFieldIndex.d.ts.map +1 -1
  263. package/lib/core/tree/detachedFieldIndex.js +2 -3
  264. package/lib/core/tree/detachedFieldIndex.js.map +1 -1
  265. package/lib/core/tree/detachedFieldIndexCodecCommon.d.ts +17 -0
  266. package/lib/core/tree/detachedFieldIndexCodecCommon.d.ts.map +1 -0
  267. package/lib/core/tree/detachedFieldIndexCodecCommon.js +64 -0
  268. package/lib/core/tree/detachedFieldIndexCodecCommon.js.map +1 -0
  269. package/lib/core/tree/detachedFieldIndexCodecV1.d.ts +11 -0
  270. package/lib/core/tree/detachedFieldIndexCodecV1.d.ts.map +1 -0
  271. package/lib/core/tree/detachedFieldIndexCodecV1.js +51 -0
  272. package/lib/core/tree/detachedFieldIndexCodecV1.js.map +1 -0
  273. package/lib/core/tree/detachedFieldIndexCodecV2.d.ts +11 -0
  274. package/lib/core/tree/detachedFieldIndexCodecV2.d.ts.map +1 -0
  275. package/lib/core/tree/detachedFieldIndexCodecV2.js +45 -0
  276. package/lib/core/tree/detachedFieldIndexCodecV2.js.map +1 -0
  277. package/lib/core/tree/detachedFieldIndexCodecs.d.ts +11 -0
  278. package/lib/core/tree/detachedFieldIndexCodecs.d.ts.map +1 -0
  279. package/lib/core/tree/detachedFieldIndexCodecs.js +21 -0
  280. package/lib/core/tree/detachedFieldIndexCodecs.js.map +1 -0
  281. package/lib/core/tree/detachedFieldIndexFormatCommon.d.ts +37 -0
  282. package/lib/core/tree/detachedFieldIndexFormatCommon.d.ts.map +1 -0
  283. package/lib/core/tree/{detachedFieldIndexFormat.js → detachedFieldIndexFormatCommon.js} +13 -10
  284. package/lib/core/tree/detachedFieldIndexFormatCommon.js.map +1 -0
  285. package/lib/core/tree/detachedFieldIndexFormatV1.d.ts +13 -0
  286. package/lib/core/tree/detachedFieldIndexFormatV1.d.ts.map +1 -0
  287. package/lib/core/tree/detachedFieldIndexFormatV1.js +9 -0
  288. package/lib/core/tree/detachedFieldIndexFormatV1.js.map +1 -0
  289. package/lib/core/tree/detachedFieldIndexFormatV2.d.ts +14 -0
  290. package/lib/core/tree/detachedFieldIndexFormatV2.d.ts.map +1 -0
  291. package/lib/core/tree/detachedFieldIndexFormatV2.js +11 -0
  292. package/lib/core/tree/detachedFieldIndexFormatV2.js.map +1 -0
  293. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +9 -9
  294. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  295. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js +19 -19
  296. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  297. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts +4 -2
  298. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts.map +1 -1
  299. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js +4 -4
  300. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js.map +1 -1
  301. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +50 -31
  302. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
  303. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js +70 -57
  304. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  305. package/lib/feature-libraries/chunked-forest/codec/format.d.ts +20 -14
  306. package/lib/feature-libraries/chunked-forest/codec/format.d.ts.map +1 -1
  307. package/lib/feature-libraries/chunked-forest/codec/format.js +17 -11
  308. package/lib/feature-libraries/chunked-forest/codec/format.js.map +1 -1
  309. package/{dist/feature-libraries/chunked-forest/codec/nodeShape.d.ts → lib/feature-libraries/chunked-forest/codec/nodeEncoder.d.ts} +20 -14
  310. package/lib/feature-libraries/chunked-forest/codec/nodeEncoder.d.ts.map +1 -0
  311. package/lib/feature-libraries/chunked-forest/codec/{nodeShape.js → nodeEncoder.js} +21 -15
  312. package/lib/feature-libraries/chunked-forest/codec/nodeEncoder.js.map +1 -0
  313. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts +7 -7
  314. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts.map +1 -1
  315. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.js +19 -19
  316. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.js.map +1 -1
  317. package/lib/feature-libraries/chunked-forest/codec/uncompressedEncode.js +2 -2
  318. package/lib/feature-libraries/chunked-forest/codec/uncompressedEncode.js.map +1 -1
  319. package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts +5 -1
  320. package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  321. package/lib/feature-libraries/default-schema/defaultFieldKinds.js +14 -2
  322. package/lib/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  323. package/lib/feature-libraries/default-schema/defaultSchema.d.ts.map +1 -1
  324. package/lib/feature-libraries/default-schema/defaultSchema.js +0 -2
  325. package/lib/feature-libraries/default-schema/defaultSchema.js.map +1 -1
  326. package/lib/feature-libraries/default-schema/index.d.ts +1 -1
  327. package/lib/feature-libraries/default-schema/index.d.ts.map +1 -1
  328. package/lib/feature-libraries/default-schema/index.js +1 -1
  329. package/lib/feature-libraries/default-schema/index.js.map +1 -1
  330. package/lib/feature-libraries/default-schema/schemaChecker.d.ts +14 -4
  331. package/lib/feature-libraries/default-schema/schemaChecker.d.ts.map +1 -1
  332. package/lib/feature-libraries/default-schema/schemaChecker.js +29 -24
  333. package/lib/feature-libraries/default-schema/schemaChecker.js.map +1 -1
  334. package/lib/feature-libraries/index.d.ts +1 -2
  335. package/lib/feature-libraries/index.d.ts.map +1 -1
  336. package/lib/feature-libraries/index.js +1 -2
  337. package/lib/feature-libraries/index.js.map +1 -1
  338. package/lib/feature-libraries/modular-schema/comparison.d.ts +5 -6
  339. package/lib/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
  340. package/lib/feature-libraries/modular-schema/comparison.js +14 -14
  341. package/lib/feature-libraries/modular-schema/comparison.js.map +1 -1
  342. package/lib/feature-libraries/modular-schema/modularChangeFormat.d.ts +9 -3
  343. package/lib/feature-libraries/modular-schema/modularChangeFormat.d.ts.map +1 -1
  344. package/lib/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
  345. package/lib/feature-libraries/object-forest/objectForest.js +3 -4
  346. package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
  347. package/lib/index.d.ts +1 -1
  348. package/lib/index.d.ts.map +1 -1
  349. package/lib/index.js +2 -2
  350. package/lib/index.js.map +1 -1
  351. package/lib/packageVersion.d.ts +1 -1
  352. package/lib/packageVersion.js +1 -1
  353. package/lib/packageVersion.js.map +1 -1
  354. package/lib/shared-tree/independentView.d.ts +8 -0
  355. package/lib/shared-tree/independentView.d.ts.map +1 -1
  356. package/lib/shared-tree/independentView.js +21 -10
  357. package/lib/shared-tree/independentView.js.map +1 -1
  358. package/lib/shared-tree/schematizeTree.js +1 -1
  359. package/lib/shared-tree/schematizeTree.js.map +1 -1
  360. package/lib/shared-tree/schematizingTreeView.d.ts +0 -1
  361. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  362. package/lib/shared-tree/schematizingTreeView.js +8 -11
  363. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  364. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  365. package/lib/shared-tree/sharedTree.js +2 -30
  366. package/lib/shared-tree/sharedTree.js.map +1 -1
  367. package/lib/shared-tree/treeAlpha.d.ts +20 -6
  368. package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
  369. package/lib/shared-tree/treeAlpha.js +10 -5
  370. package/lib/shared-tree/treeAlpha.js.map +1 -1
  371. package/lib/shared-tree/treeCheckout.d.ts +2 -1
  372. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  373. package/lib/shared-tree/treeCheckout.js +33 -1
  374. package/lib/shared-tree/treeCheckout.js.map +1 -1
  375. package/lib/shared-tree-core/branch.d.ts.map +1 -1
  376. package/lib/shared-tree-core/branch.js +1 -1
  377. package/lib/shared-tree-core/branch.js.map +1 -1
  378. package/lib/simple-tree/api/conciseTree.d.ts +2 -2
  379. package/lib/simple-tree/api/conciseTree.d.ts.map +1 -1
  380. package/lib/simple-tree/api/conciseTree.js +6 -6
  381. package/lib/simple-tree/api/conciseTree.js.map +1 -1
  382. package/lib/simple-tree/api/configuration.d.ts +8 -2
  383. package/lib/simple-tree/api/configuration.d.ts.map +1 -1
  384. package/lib/simple-tree/api/configuration.js.map +1 -1
  385. package/lib/simple-tree/api/create.d.ts +8 -7
  386. package/lib/simple-tree/api/create.d.ts.map +1 -1
  387. package/lib/simple-tree/api/create.js +38 -25
  388. package/lib/simple-tree/api/create.js.map +1 -1
  389. package/lib/simple-tree/api/customTree.d.ts +25 -4
  390. package/lib/simple-tree/api/customTree.d.ts.map +1 -1
  391. package/lib/simple-tree/api/customTree.js +43 -17
  392. package/lib/simple-tree/api/customTree.js.map +1 -1
  393. package/lib/simple-tree/api/discrepancies.d.ts +98 -0
  394. package/lib/simple-tree/api/discrepancies.d.ts.map +1 -0
  395. package/lib/simple-tree/{discrepancies.js → api/discrepancies.js} +80 -206
  396. package/lib/simple-tree/api/discrepancies.js.map +1 -0
  397. package/lib/simple-tree/api/schemaCompatibilityTester.d.ts +9 -7
  398. package/lib/simple-tree/api/schemaCompatibilityTester.d.ts.map +1 -1
  399. package/lib/simple-tree/api/schemaCompatibilityTester.js +19 -118
  400. package/lib/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
  401. package/lib/simple-tree/api/schemaFactory.d.ts +7 -4
  402. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  403. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  404. package/lib/simple-tree/api/storedSchema.d.ts.map +1 -1
  405. package/lib/simple-tree/api/storedSchema.js +6 -2
  406. package/lib/simple-tree/api/storedSchema.js.map +1 -1
  407. package/lib/simple-tree/api/treeBeta.d.ts +2 -2
  408. package/lib/simple-tree/api/treeBeta.d.ts.map +1 -1
  409. package/lib/simple-tree/api/treeBeta.js +8 -2
  410. package/lib/simple-tree/api/treeBeta.js.map +1 -1
  411. package/lib/simple-tree/api/verboseTree.d.ts +2 -2
  412. package/lib/simple-tree/api/verboseTree.d.ts.map +1 -1
  413. package/lib/simple-tree/api/verboseTree.js +9 -9
  414. package/lib/simple-tree/api/verboseTree.js.map +1 -1
  415. package/lib/simple-tree/core/allowedTypes.d.ts +20 -4
  416. package/lib/simple-tree/core/allowedTypes.d.ts.map +1 -1
  417. package/lib/simple-tree/core/allowedTypes.js +42 -12
  418. package/lib/simple-tree/core/allowedTypes.js.map +1 -1
  419. package/lib/simple-tree/core/context.d.ts +13 -2
  420. package/lib/simple-tree/core/context.d.ts.map +1 -1
  421. package/lib/simple-tree/core/context.js +22 -9
  422. package/lib/simple-tree/core/context.js.map +1 -1
  423. package/lib/simple-tree/core/index.d.ts +2 -2
  424. package/lib/simple-tree/core/index.d.ts.map +1 -1
  425. package/lib/simple-tree/core/index.js +2 -2
  426. package/lib/simple-tree/core/index.js.map +1 -1
  427. package/lib/simple-tree/core/treeNodeKernel.d.ts +1 -1
  428. package/lib/simple-tree/core/treeNodeKernel.js +1 -1
  429. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  430. package/lib/simple-tree/core/treeNodeValid.d.ts +1 -1
  431. package/lib/simple-tree/core/treeNodeValid.d.ts.map +1 -1
  432. package/lib/simple-tree/core/treeNodeValid.js +8 -1
  433. package/lib/simple-tree/core/treeNodeValid.js.map +1 -1
  434. package/lib/simple-tree/core/walkSchema.d.ts +3 -0
  435. package/lib/simple-tree/core/walkSchema.d.ts.map +1 -1
  436. package/lib/simple-tree/core/walkSchema.js +2 -0
  437. package/lib/simple-tree/core/walkSchema.js.map +1 -1
  438. package/lib/simple-tree/createContext.d.ts +2 -0
  439. package/lib/simple-tree/createContext.d.ts.map +1 -1
  440. package/lib/simple-tree/createContext.js +3 -1
  441. package/lib/simple-tree/createContext.js.map +1 -1
  442. package/lib/simple-tree/fieldSchema.d.ts +1 -0
  443. package/lib/simple-tree/fieldSchema.d.ts.map +1 -1
  444. package/lib/simple-tree/fieldSchema.js +1 -0
  445. package/lib/simple-tree/fieldSchema.js.map +1 -1
  446. package/lib/simple-tree/index.d.ts +4 -4
  447. package/lib/simple-tree/index.d.ts.map +1 -1
  448. package/lib/simple-tree/index.js +4 -4
  449. package/lib/simple-tree/index.js.map +1 -1
  450. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  451. package/lib/simple-tree/node-kinds/array/arrayNode.js +1 -1
  452. package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  453. package/lib/simple-tree/node-kinds/index.d.ts +1 -1
  454. package/lib/simple-tree/node-kinds/index.d.ts.map +1 -1
  455. package/lib/simple-tree/node-kinds/index.js +1 -1
  456. package/lib/simple-tree/node-kinds/index.js.map +1 -1
  457. package/lib/simple-tree/node-kinds/object/index.d.ts +1 -1
  458. package/lib/simple-tree/node-kinds/object/index.d.ts.map +1 -1
  459. package/lib/simple-tree/node-kinds/object/index.js +1 -1
  460. package/lib/simple-tree/node-kinds/object/index.js.map +1 -1
  461. package/lib/simple-tree/node-kinds/object/objectNode.d.ts +2 -7
  462. package/lib/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  463. package/lib/simple-tree/node-kinds/object/objectNode.js +3 -16
  464. package/lib/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  465. package/lib/simple-tree/prepareForInsertion.d.ts +5 -5
  466. package/lib/simple-tree/prepareForInsertion.d.ts.map +1 -1
  467. package/lib/simple-tree/prepareForInsertion.js +11 -5
  468. package/lib/simple-tree/prepareForInsertion.js.map +1 -1
  469. package/lib/simple-tree/toStoredSchema.d.ts +3 -0
  470. package/lib/simple-tree/toStoredSchema.d.ts.map +1 -1
  471. package/lib/simple-tree/toStoredSchema.js +3 -0
  472. package/lib/simple-tree/toStoredSchema.js.map +1 -1
  473. package/lib/simple-tree/unhydratedFlexTreeFromInsertable.d.ts +2 -2
  474. package/lib/simple-tree/unhydratedFlexTreeFromInsertable.d.ts.map +1 -1
  475. package/lib/simple-tree/unhydratedFlexTreeFromInsertable.js +1 -1
  476. package/lib/simple-tree/unhydratedFlexTreeFromInsertable.js.map +1 -1
  477. package/lib/simple-tree/walkFieldSchema.d.ts +1 -0
  478. package/lib/simple-tree/walkFieldSchema.d.ts.map +1 -1
  479. package/lib/simple-tree/walkFieldSchema.js +1 -0
  480. package/lib/simple-tree/walkFieldSchema.js.map +1 -1
  481. package/package.json +23 -23
  482. package/src/codec/codec.ts +4 -3
  483. package/src/core/index.ts +2 -0
  484. package/src/core/rebase/index.ts +2 -0
  485. package/src/core/rebase/types.ts +4 -0
  486. package/src/core/schema-stored/schema.ts +2 -26
  487. package/src/core/tree/detachedFieldIndex.ts +4 -6
  488. package/src/core/tree/detachedFieldIndexCodecCommon.ts +87 -0
  489. package/src/core/tree/{detachedFieldIndexCodec.ts → detachedFieldIndexCodecV1.ts} +22 -68
  490. package/src/core/tree/detachedFieldIndexCodecV2.ts +72 -0
  491. package/src/core/tree/detachedFieldIndexCodecs.ts +44 -0
  492. package/src/core/tree/{detachedFieldIndexFormat.ts → detachedFieldIndexFormatCommon.ts} +32 -23
  493. package/src/core/tree/detachedFieldIndexFormatV1.ts +15 -0
  494. package/src/core/tree/detachedFieldIndexFormatV2.ts +17 -0
  495. package/src/feature-libraries/chunked-forest/codec/README.md +1 -1
  496. package/src/feature-libraries/chunked-forest/codec/chunkDecoding.ts +25 -25
  497. package/src/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.ts +10 -6
  498. package/src/feature-libraries/chunked-forest/codec/compressedEncode.ts +96 -73
  499. package/src/feature-libraries/chunked-forest/codec/format.ts +20 -14
  500. package/src/feature-libraries/chunked-forest/codec/{nodeShape.ts → nodeEncoder.ts} +23 -17
  501. package/src/feature-libraries/chunked-forest/codec/schemaBasedEncode.ts +34 -34
  502. package/src/feature-libraries/chunked-forest/codec/uncompressedEncode.ts +5 -5
  503. package/src/feature-libraries/default-schema/defaultFieldKinds.ts +10 -0
  504. package/src/feature-libraries/default-schema/defaultSchema.ts +0 -2
  505. package/src/feature-libraries/default-schema/index.ts +1 -1
  506. package/src/feature-libraries/default-schema/schemaChecker.ts +47 -30
  507. package/src/feature-libraries/index.ts +1 -3
  508. package/src/feature-libraries/modular-schema/comparison.ts +14 -29
  509. package/src/feature-libraries/object-forest/objectForest.ts +10 -6
  510. package/src/index.ts +5 -0
  511. package/src/packageVersion.ts +1 -1
  512. package/src/shared-tree/independentView.ts +45 -19
  513. package/src/shared-tree/schematizeTree.ts +1 -1
  514. package/src/shared-tree/schematizingTreeView.ts +16 -13
  515. package/src/shared-tree/sharedTree.ts +2 -42
  516. package/src/shared-tree/treeAlpha.ts +30 -18
  517. package/src/shared-tree/treeCheckout.ts +54 -10
  518. package/src/shared-tree-core/branch.ts +1 -6
  519. package/src/simple-tree/api/conciseTree.ts +9 -7
  520. package/src/simple-tree/api/configuration.ts +8 -2
  521. package/src/simple-tree/api/create.ts +49 -36
  522. package/src/simple-tree/api/customTree.ts +59 -20
  523. package/src/simple-tree/{discrepancies.ts → api/discrepancies.ts} +128 -303
  524. package/src/simple-tree/api/schemaCompatibilityTester.ts +27 -151
  525. package/src/simple-tree/api/schemaFactory.ts +7 -4
  526. package/src/simple-tree/api/storedSchema.ts +6 -9
  527. package/src/simple-tree/api/treeBeta.ts +17 -4
  528. package/src/simple-tree/api/verboseTree.ts +17 -8
  529. package/src/simple-tree/core/allowedTypes.ts +54 -21
  530. package/src/simple-tree/core/context.ts +24 -22
  531. package/src/simple-tree/core/index.ts +2 -1
  532. package/src/simple-tree/core/treeNodeKernel.ts +1 -1
  533. package/src/simple-tree/core/treeNodeValid.ts +9 -2
  534. package/src/simple-tree/core/walkSchema.ts +3 -0
  535. package/src/simple-tree/createContext.ts +6 -1
  536. package/src/simple-tree/fieldSchema.ts +1 -0
  537. package/src/simple-tree/index.ts +5 -10
  538. package/src/simple-tree/node-kinds/array/arrayNode.ts +32 -19
  539. package/src/simple-tree/node-kinds/index.ts +0 -1
  540. package/src/simple-tree/node-kinds/object/index.ts +0 -1
  541. package/src/simple-tree/node-kinds/object/objectNode.ts +9 -27
  542. package/src/simple-tree/prepareForInsertion.ts +17 -9
  543. package/src/simple-tree/toStoredSchema.ts +3 -0
  544. package/src/simple-tree/unhydratedFlexTreeFromInsertable.ts +6 -2
  545. package/src/simple-tree/walkFieldSchema.ts +1 -0
  546. package/dist/core/tree/detachedFieldIndexCodec.d.ts +0 -11
  547. package/dist/core/tree/detachedFieldIndexCodec.d.ts.map +0 -1
  548. package/dist/core/tree/detachedFieldIndexCodec.js +0 -100
  549. package/dist/core/tree/detachedFieldIndexCodec.js.map +0 -1
  550. package/dist/core/tree/detachedFieldIndexFormat.d.ts +0 -33
  551. package/dist/core/tree/detachedFieldIndexFormat.d.ts.map +0 -1
  552. package/dist/core/tree/detachedFieldIndexFormat.js.map +0 -1
  553. package/dist/feature-libraries/chunked-forest/codec/nodeShape.d.ts.map +0 -1
  554. package/dist/feature-libraries/chunked-forest/codec/nodeShape.js.map +0 -1
  555. package/dist/feature-libraries/initializeForest.d.ts +0 -18
  556. package/dist/feature-libraries/initializeForest.d.ts.map +0 -1
  557. package/dist/feature-libraries/initializeForest.js +0 -35
  558. package/dist/feature-libraries/initializeForest.js.map +0 -1
  559. package/dist/simple-tree/discrepancies.d.ts +0 -167
  560. package/dist/simple-tree/discrepancies.d.ts.map +0 -1
  561. package/dist/simple-tree/discrepancies.js +0 -382
  562. package/dist/simple-tree/discrepancies.js.map +0 -1
  563. package/lib/core/tree/detachedFieldIndexCodec.d.ts +0 -11
  564. package/lib/core/tree/detachedFieldIndexCodec.d.ts.map +0 -1
  565. package/lib/core/tree/detachedFieldIndexCodec.js +0 -96
  566. package/lib/core/tree/detachedFieldIndexCodec.js.map +0 -1
  567. package/lib/core/tree/detachedFieldIndexFormat.d.ts +0 -33
  568. package/lib/core/tree/detachedFieldIndexFormat.d.ts.map +0 -1
  569. package/lib/core/tree/detachedFieldIndexFormat.js.map +0 -1
  570. package/lib/feature-libraries/chunked-forest/codec/nodeShape.d.ts.map +0 -1
  571. package/lib/feature-libraries/chunked-forest/codec/nodeShape.js.map +0 -1
  572. package/lib/feature-libraries/initializeForest.d.ts +0 -18
  573. package/lib/feature-libraries/initializeForest.d.ts.map +0 -1
  574. package/lib/feature-libraries/initializeForest.js +0 -31
  575. package/lib/feature-libraries/initializeForest.js.map +0 -1
  576. package/lib/simple-tree/discrepancies.d.ts +0 -167
  577. package/lib/simple-tree/discrepancies.d.ts.map +0 -1
  578. package/lib/simple-tree/discrepancies.js.map +0 -1
  579. package/src/feature-libraries/initializeForest.ts +0 -55
@@ -5,30 +5,36 @@
5
5
  import { type ITreeCursorSynchronous, type TreeNodeSchemaIdentifier } from "../../../core/index.js";
6
6
  import type { Counter, DeduplicationTable } from "./chunkCodecUtilities.js";
7
7
  import { type BufferFormat, Shape } from "./chunkEncodingGeneric.js";
8
- import { type EncoderCache, type FieldEncoder, type KeyedFieldEncoder, type NodeEncoder } from "./compressedEncode.js";
8
+ import { type EncoderContext, type FieldEncoder, type KeyedFieldEncoder, type NodeEncoder } from "./compressedEncode.js";
9
9
  import type { EncodedChunkShape, EncodedFieldShape, EncodedValueShape } from "./format.js";
10
- export declare class NodeShape extends Shape<EncodedChunkShape> implements NodeEncoder {
10
+ /**
11
+ * Encodes a node with the {@link EncodedNodeShape} shape.
12
+ * @remarks
13
+ * The fact this is also a Shape is an implementation detail of the encoder: that allows the shape it uses to be itself,
14
+ * which is an easy way to keep all the related code together without extra objects.
15
+ */
16
+ export declare class NodeShapeBasedEncoder extends Shape<EncodedChunkShape> implements NodeEncoder {
11
17
  readonly type: undefined | TreeNodeSchemaIdentifier;
12
18
  readonly value: EncodedValueShape;
13
19
  /**
14
20
  * Encoders for a specific set of fields, by key, in the order they will be encoded.
15
21
  * These are fields for which specialized encoding is provided as an optimization.
16
- * Using these for a given field instead of falling back to {@link NodeShape.specializedFieldEncoders} is often more efficient:
22
+ * Using these for a given field instead of falling back to {@link NodeShapeBasedEncoder.specializedFieldEncoders} is often more efficient:
17
23
  * this avoids the need to explicitly include the key and shape in the encoded data for each node instance.
18
24
  * Instead, this information is here, and thus is encoded only once as part of the node shape.
19
25
  * These encoders will be used, even if the field they apply to is empty (which can add overhead for fields which are usually empty).
20
26
  *
21
- * Any fields not included here will be encoded using {@link NodeShape.otherFieldsEncoder}.
22
- * If {@link NodeShape.otherFieldsEncoder} is undefined, then this must handle all non-empty fields.
27
+ * Any fields not included here will be encoded using {@link NodeShapeBasedEncoder.otherFieldsEncoder}.
28
+ * If {@link NodeShapeBasedEncoder.otherFieldsEncoder} is undefined, then this must handle all non-empty fields.
23
29
  */
24
30
  readonly specializedFieldEncoders: readonly KeyedFieldEncoder[];
25
31
  /**
26
- * Encoder for all other fields that are not in {@link NodeShape.specializedFieldEncoders}. These fields must
32
+ * Encoder for all other fields that are not in {@link NodeShapeBasedEncoder.specializedFieldEncoders}. These fields must
27
33
  * be encoded after the specialized fields.
28
34
  */
29
35
  readonly otherFieldsEncoder: undefined | FieldEncoder;
30
36
  /**
31
- * Set of keys for fields that are encoded using {@link NodeShape.specializedFieldEncoders}.
37
+ * Set of keys for fields that are encoded using {@link NodeShapeBasedEncoder.specializedFieldEncoders}.
32
38
  * TODO: Ensure uniform chunks, encoding and identifier generation sort fields the same.
33
39
  */
34
40
  private readonly specializedFieldKeys;
@@ -36,25 +42,25 @@ export declare class NodeShape extends Shape<EncodedChunkShape> implements NodeE
36
42
  /**
37
43
  * Encoders for a specific set of fields, by key, in the order they will be encoded.
38
44
  * These are fields for which specialized encoding is provided as an optimization.
39
- * Using these for a given field instead of falling back to {@link NodeShape.specializedFieldEncoders} is often more efficient:
45
+ * Using these for a given field instead of falling back to {@link NodeShapeBasedEncoder.specializedFieldEncoders} is often more efficient:
40
46
  * this avoids the need to explicitly include the key and shape in the encoded data for each node instance.
41
47
  * Instead, this information is here, and thus is encoded only once as part of the node shape.
42
48
  * These encoders will be used, even if the field they apply to is empty (which can add overhead for fields which are usually empty).
43
49
  *
44
- * Any fields not included here will be encoded using {@link NodeShape.otherFieldsEncoder}.
45
- * If {@link NodeShape.otherFieldsEncoder} is undefined, then this must handle all non-empty fields.
50
+ * Any fields not included here will be encoded using {@link NodeShapeBasedEncoder.otherFieldsEncoder}.
51
+ * If {@link NodeShapeBasedEncoder.otherFieldsEncoder} is undefined, then this must handle all non-empty fields.
46
52
  */
47
53
  specializedFieldEncoders: readonly KeyedFieldEncoder[],
48
54
  /**
49
- * Encoder for all other fields that are not in {@link NodeShape.specializedFieldEncoders}. These fields must
55
+ * Encoder for all other fields that are not in {@link NodeShapeBasedEncoder.specializedFieldEncoders}. These fields must
50
56
  * be encoded after the specialized fields.
51
57
  */
52
58
  otherFieldsEncoder: undefined | FieldEncoder);
53
59
  private getValueToEncode;
54
- encodeNode(cursor: ITreeCursorSynchronous, cache: EncoderCache, outputBuffer: BufferFormat<EncodedChunkShape>): void;
60
+ encodeNode(cursor: ITreeCursorSynchronous, context: EncoderContext, outputBuffer: BufferFormat<EncodedChunkShape>): void;
55
61
  encodeShape(identifiers: DeduplicationTable<string>, shapes: DeduplicationTable<Shape<EncodedChunkShape>>): EncodedChunkShape;
56
62
  countReferencedShapesAndIdentifiers(identifiers: Counter<string>, shapeDiscovered: (shape: Shape<EncodedChunkShape>) => void): void;
57
- get shape(): NodeShape;
63
+ get shape(): Shape<EncodedChunkShape>;
58
64
  }
59
65
  export declare function encodeFieldShapes(fieldEncoders: readonly KeyedFieldEncoder[], identifiers: DeduplicationTable<string>, shapes: DeduplicationTable<Shape<EncodedChunkShape>>): EncodedFieldShape[] | undefined;
60
- //# sourceMappingURL=nodeShape.d.ts.map
66
+ //# sourceMappingURL=nodeEncoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodeEncoder.d.ts","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/nodeEncoder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAEN,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAG7B,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EAAE,KAAK,YAAY,EAAmB,KAAK,EAAE,MAAM,2BAA2B,CAAC;AACtF,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAEhB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE3F;;;;;GAKG;AACH,qBAAa,qBAAsB,SAAQ,KAAK,CAAC,iBAAiB,CAAE,YAAW,WAAW;aAQxE,IAAI,EAAE,SAAS,GAAG,wBAAwB;aAC1C,KAAK,EAAE,iBAAiB;IACxC;;;;;;;;;;OAUG;aACa,wBAAwB,EAAE,SAAS,iBAAiB,EAAE;IACtE;;;OAGG;aACa,kBAAkB,EAAE,SAAS,GAAG,YAAY;IAzB7D;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAgB;gBAGpC,IAAI,EAAE,SAAS,GAAG,wBAAwB,EAC1C,KAAK,EAAE,iBAAiB;IACxC;;;;;;;;;;OAUG;IACa,wBAAwB,EAAE,SAAS,iBAAiB,EAAE;IACtE;;;OAGG;IACa,kBAAkB,EAAE,SAAS,GAAG,YAAY;IAM7D,OAAO,CAAC,gBAAgB;IAajB,UAAU,CAChB,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,cAAc,EACvB,YAAY,EAAE,YAAY,CAAC,iBAAiB,CAAC,GAC3C,IAAI;IAgCA,WAAW,CACjB,WAAW,EAAE,kBAAkB,CAAC,MAAM,CAAC,EACvC,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,GAClD,iBAAiB;IAWb,mCAAmC,CACzC,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,EAC5B,eAAe,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,iBAAiB,CAAC,KAAK,IAAI,GACxD,IAAI;IAeP,IAAW,KAAK,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAE3C;CACD;AAED,wBAAgB,iBAAiB,CAChC,aAAa,EAAE,SAAS,iBAAiB,EAAE,EAC3C,WAAW,EAAE,kBAAkB,CAAC,MAAM,CAAC,EACvC,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,GAClD,iBAAiB,EAAE,GAAG,SAAS,CAUjC"}
@@ -8,22 +8,28 @@ import { forEachField, } from "../../../core/index.js";
8
8
  import { brand } from "../../../util/index.js";
9
9
  import { IdentifierToken, Shape } from "./chunkEncodingGeneric.js";
10
10
  import { encodeValue, } from "./compressedEncode.js";
11
- export class NodeShape extends Shape {
11
+ /**
12
+ * Encodes a node with the {@link EncodedNodeShape} shape.
13
+ * @remarks
14
+ * The fact this is also a Shape is an implementation detail of the encoder: that allows the shape it uses to be itself,
15
+ * which is an easy way to keep all the related code together without extra objects.
16
+ */
17
+ export class NodeShapeBasedEncoder extends Shape {
12
18
  constructor(type, value,
13
19
  /**
14
20
  * Encoders for a specific set of fields, by key, in the order they will be encoded.
15
21
  * These are fields for which specialized encoding is provided as an optimization.
16
- * Using these for a given field instead of falling back to {@link NodeShape.specializedFieldEncoders} is often more efficient:
22
+ * Using these for a given field instead of falling back to {@link NodeShapeBasedEncoder.specializedFieldEncoders} is often more efficient:
17
23
  * this avoids the need to explicitly include the key and shape in the encoded data for each node instance.
18
24
  * Instead, this information is here, and thus is encoded only once as part of the node shape.
19
25
  * These encoders will be used, even if the field they apply to is empty (which can add overhead for fields which are usually empty).
20
26
  *
21
- * Any fields not included here will be encoded using {@link NodeShape.otherFieldsEncoder}.
22
- * If {@link NodeShape.otherFieldsEncoder} is undefined, then this must handle all non-empty fields.
27
+ * Any fields not included here will be encoded using {@link NodeShapeBasedEncoder.otherFieldsEncoder}.
28
+ * If {@link NodeShapeBasedEncoder.otherFieldsEncoder} is undefined, then this must handle all non-empty fields.
23
29
  */
24
30
  specializedFieldEncoders,
25
31
  /**
26
- * Encoder for all other fields that are not in {@link NodeShape.specializedFieldEncoders}. These fields must
32
+ * Encoder for all other fields that are not in {@link NodeShapeBasedEncoder.specializedFieldEncoders}. These fields must
27
33
  * be encoded after the specialized fields.
28
34
  */
29
35
  otherFieldsEncoder) {
@@ -34,29 +40,29 @@ export class NodeShape extends Shape {
34
40
  this.otherFieldsEncoder = otherFieldsEncoder;
35
41
  this.specializedFieldKeys = new Set(this.specializedFieldEncoders.map((f) => f.key));
36
42
  }
37
- getValueToEncode(cursor, cache) {
43
+ getValueToEncode(cursor, context) {
38
44
  if (this.value === 0) {
39
45
  assert(typeof cursor.value === "string", 0x9aa /* identifier must be type string */);
40
46
  if (isStableId(cursor.value)) {
41
- const sessionSpaceCompressedId = cache.idCompressor.tryRecompress(cursor.value);
47
+ const sessionSpaceCompressedId = context.idCompressor.tryRecompress(cursor.value);
42
48
  if (sessionSpaceCompressedId !== undefined) {
43
- return cache.idCompressor.normalizeToOpSpace(sessionSpaceCompressedId);
49
+ return context.idCompressor.normalizeToOpSpace(sessionSpaceCompressedId);
44
50
  }
45
51
  }
46
52
  }
47
53
  return cursor.value;
48
54
  }
49
- encodeNode(cursor, cache, outputBuffer) {
55
+ encodeNode(cursor, context, outputBuffer) {
50
56
  if (this.type === undefined) {
51
57
  outputBuffer.push(new IdentifierToken(cursor.type));
52
58
  }
53
59
  else {
54
60
  assert(cursor.type === this.type, 0x741 /* type must match shape */);
55
61
  }
56
- encodeValue(this.getValueToEncode(cursor, cache), this.value, outputBuffer);
62
+ encodeValue(this.getValueToEncode(cursor, context), this.value, outputBuffer);
57
63
  for (const fieldEncoder of this.specializedFieldEncoders) {
58
64
  cursor.enterField(brand(fieldEncoder.key));
59
- fieldEncoder.encoder.encodeField(cursor, cache, outputBuffer);
65
+ fieldEncoder.encoder.encodeField(cursor, context, outputBuffer);
60
66
  cursor.exitField();
61
67
  }
62
68
  const otherFieldsBuffer = [];
@@ -65,7 +71,7 @@ export class NodeShape extends Shape {
65
71
  if (!this.specializedFieldKeys.has(key)) {
66
72
  assert(this.otherFieldsEncoder !== undefined, 0x742 /* had extra local fields when shape does not support them */);
67
73
  otherFieldsBuffer.push(new IdentifierToken(key));
68
- this.otherFieldsEncoder.encodeField(cursor, cache, otherFieldsBuffer);
74
+ this.otherFieldsEncoder.encodeField(cursor, context, otherFieldsBuffer);
69
75
  }
70
76
  });
71
77
  if (this.otherFieldsEncoder !== undefined) {
@@ -115,10 +121,10 @@ function encodeIdentifier(identifier, identifiers) {
115
121
  function encodeOptionalIdentifier(identifier, identifiers) {
116
122
  return identifier === undefined ? undefined : encodeIdentifier(identifier, identifiers);
117
123
  }
118
- function encodeOptionalFieldShape(shape, shapes) {
119
- return shape === undefined ? undefined : dedupShape(shape.shape, shapes);
124
+ function encodeOptionalFieldShape(encoder, shapes) {
125
+ return encoder === undefined ? undefined : dedupShape(encoder.shape, shapes);
120
126
  }
121
127
  function dedupShape(shape, shapes) {
122
128
  return shapes.valueToIndex.get(shape) ?? fail(0xb51 /* missing shape */);
123
129
  }
124
- //# sourceMappingURL=nodeShape.js.map
130
+ //# sourceMappingURL=nodeEncoder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodeEncoder.js","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/nodeEncoder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AAEpE,OAAO,EAIN,YAAY,GAEZ,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAG/C,OAAO,EAAqB,eAAe,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AACtF,OAAO,EAKN,WAAW,GACX,MAAM,uBAAuB,CAAC;AAG/B;;;;;GAKG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAwB;IAOlE,YACiB,IAA0C,EAC1C,KAAwB;IACxC;;;;;;;;;;OAUG;IACa,wBAAsD;IACtE;;;OAGG;IACa,kBAA4C;QAE5D,KAAK,EAAE,CAAC;QApBQ,SAAI,GAAJ,IAAI,CAAsC;QAC1C,UAAK,GAAL,KAAK,CAAmB;QAYxB,6BAAwB,GAAxB,wBAAwB,CAA8B;QAKtD,uBAAkB,GAAlB,kBAAkB,CAA0B;QAG5D,IAAI,CAAC,oBAAoB,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACtF,CAAC;IAEO,gBAAgB,CAAC,MAA8B,EAAE,OAAuB;QAC/E,IAAI,IAAI,CAAC,KAAK,KAAK,CAAC,EAAE,CAAC;YACtB,MAAM,CAAC,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,EAAE,KAAK,CAAC,oCAAoC,CAAC,CAAC;YACrF,IAAI,UAAU,CAAC,MAAM,CA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AAC,mBAAmB,CAAC,CAAC;AAC1E,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\nimport { isStableId } from \"@fluidframework/id-compressor/internal\";\n\nimport {\n\ttype FieldKey,\n\ttype ITreeCursorSynchronous,\n\ttype TreeNodeSchemaIdentifier,\n\tforEachField,\n\ttype Value,\n} from \"../../../core/index.js\";\nimport { brand } from \"../../../util/index.js\";\n\nimport type { Counter, DeduplicationTable } from \"./chunkCodecUtilities.js\";\nimport { type BufferFormat, IdentifierToken, Shape } from \"./chunkEncodingGeneric.js\";\nimport {\n\ttype EncoderContext,\n\ttype FieldEncoder,\n\ttype KeyedFieldEncoder,\n\ttype NodeEncoder,\n\tencodeValue,\n} from \"./compressedEncode.js\";\nimport type { EncodedChunkShape, EncodedFieldShape, EncodedValueShape } from \"./format.js\";\n\n/**\n * Encodes a node with the {@link EncodedNodeShape} shape.\n * @remarks\n * The fact this is also a Shape is an implementation detail of the encoder: that allows the shape it uses to be itself,\n * which is an easy way to keep all the related code together without extra objects.\n */\nexport class NodeShapeBasedEncoder extends Shape<EncodedChunkShape> implements NodeEncoder {\n\t/**\n\t * Set of keys for fields that are encoded using {@link NodeShapeBasedEncoder.specializedFieldEncoders}.\n\t * TODO: Ensure uniform chunks, encoding and identifier generation sort fields the same.\n\t */\n\tprivate readonly specializedFieldKeys: Set<FieldKey>;\n\n\tpublic constructor(\n\t\tpublic readonly type: undefined | TreeNodeSchemaIdentifier,\n\t\tpublic readonly value: EncodedValueShape,\n\t\t/**\n\t\t * Encoders for a specific set of fields, by key, in the order they will be encoded.\n\t\t * These are fields for which specialized encoding is provided as an optimization.\n\t\t * Using these for a given field instead of falling back to {@link NodeShapeBasedEncoder.specializedFieldEncoders} is often more efficient:\n\t\t * this avoids the need to explicitly include the key and shape in the encoded data for each node instance.\n\t\t * Instead, this information is here, and thus is encoded only once as part of the node shape.\n\t\t * These encoders will be used, even if the field they apply to is empty (which can add overhead for fields which are usually empty).\n\t\t *\n\t\t * Any fields not included here will be encoded using {@link NodeShapeBasedEncoder.otherFieldsEncoder}.\n\t\t * If {@link NodeShapeBasedEncoder.otherFieldsEncoder} is undefined, then this must handle all non-empty fields.\n\t\t */\n\t\tpublic readonly specializedFieldEncoders: readonly KeyedFieldEncoder[],\n\t\t/**\n\t\t * Encoder for all other fields that are not in {@link NodeShapeBasedEncoder.specializedFieldEncoders}. These fields must\n\t\t * be encoded after the specialized fields.\n\t\t */\n\t\tpublic readonly otherFieldsEncoder: undefined | FieldEncoder,\n\t) {\n\t\tsuper();\n\t\tthis.specializedFieldKeys = new Set(this.specializedFieldEncoders.map((f) => f.key));\n\t}\n\n\tprivate getValueToEncode(cursor: ITreeCursorSynchronous, context: EncoderContext): Value {\n\t\tif (this.value === 0) {\n\t\t\tassert(typeof cursor.value === \"string\", 0x9aa /* identifier must be type string */);\n\t\t\tif (isStableId(cursor.value)) {\n\t\t\t\tconst sessionSpaceCompressedId = context.idCompressor.tryRecompress(cursor.value);\n\t\t\t\tif (sessionSpaceCompressedId !== undefined) {\n\t\t\t\t\treturn context.idCompressor.normalizeToOpSpace(sessionSpaceCompressedId);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn cursor.value;\n\t}\n\n\tpublic encodeNode(\n\t\tcursor: ITreeCursorSynchronous,\n\t\tcontext: EncoderContext,\n\t\toutputBuffer: BufferFormat<EncodedChunkShape>,\n\t): void {\n\t\tif (this.type === undefined) {\n\t\t\toutputBuffer.push(new IdentifierToken(cursor.type));\n\t\t} else {\n\t\t\tassert(cursor.type === this.type, 0x741 /* type must match shape */);\n\t\t}\n\t\tencodeValue(this.getValueToEncode(cursor, context), this.value, outputBuffer);\n\t\tfor (const fieldEncoder of this.specializedFieldEncoders) {\n\t\t\tcursor.enterField(brand(fieldEncoder.key));\n\t\t\tfieldEncoder.encoder.encodeField(cursor, context, outputBuffer);\n\t\t\tcursor.exitField();\n\t\t}\n\n\t\tconst otherFieldsBuffer: BufferFormat<EncodedChunkShape> = [];\n\n\t\tforEachField(cursor, () => {\n\t\t\tconst key = cursor.getFieldKey();\n\t\t\tif (!this.specializedFieldKeys.has(key)) {\n\t\t\t\tassert(\n\t\t\t\t\tthis.otherFieldsEncoder !== undefined,\n\t\t\t\t\t0x742 /* had extra local fields when shape does not support them */,\n\t\t\t\t);\n\t\t\t\totherFieldsBuffer.push(new IdentifierToken(key));\n\t\t\t\tthis.otherFieldsEncoder.encodeField(cursor, context, otherFieldsBuffer);\n\t\t\t}\n\t\t});\n\n\t\tif (this.otherFieldsEncoder !== undefined) {\n\t\t\toutputBuffer.push(otherFieldsBuffer);\n\t\t}\n\t}\n\n\tpublic encodeShape(\n\t\tidentifiers: DeduplicationTable<string>,\n\t\tshapes: DeduplicationTable<Shape<EncodedChunkShape>>,\n\t): EncodedChunkShape {\n\t\treturn {\n\t\t\tc: {\n\t\t\t\ttype: encodeOptionalIdentifier(this.type, identifiers),\n\t\t\t\tvalue: this.value,\n\t\t\t\tfields: encodeFieldShapes(this.specializedFieldEncoders, identifiers, shapes),\n\t\t\t\textraFields: encodeOptionalFieldShape(this.otherFieldsEncoder, shapes),\n\t\t\t},\n\t\t};\n\t}\n\n\tpublic countReferencedShapesAndIdentifiers(\n\t\tidentifiers: Counter<string>,\n\t\tshapeDiscovered: (shape: Shape<EncodedChunkShape>) => void,\n\t): void {\n\t\tif (this.type !== undefined) {\n\t\t\tidentifiers.add(this.type);\n\t\t}\n\n\t\tfor (const fieldEncoder of this.specializedFieldEncoders) {\n\t\t\tidentifiers.add(fieldEncoder.key);\n\t\t\tshapeDiscovered(fieldEncoder.encoder.shape);\n\t\t}\n\n\t\tif (this.otherFieldsEncoder !== undefined) {\n\t\t\tshapeDiscovered(this.otherFieldsEncoder.shape);\n\t\t}\n\t}\n\n\tpublic get shape(): Shape<EncodedChunkShape> {\n\t\treturn this;\n\t}\n}\n\nexport function encodeFieldShapes(\n\tfieldEncoders: readonly KeyedFieldEncoder[],\n\tidentifiers: DeduplicationTable<string>,\n\tshapes: DeduplicationTable<Shape<EncodedChunkShape>>,\n): EncodedFieldShape[] | undefined {\n\tif (fieldEncoders.length === 0) {\n\t\treturn undefined;\n\t}\n\treturn fieldEncoders.map((fieldEncoder) => [\n\t\t// key\n\t\tencodeIdentifier(fieldEncoder.key, identifiers),\n\t\t// shape\n\t\tshapes.valueToIndex.get(fieldEncoder.encoder.shape) ?? fail(0xb50 /* missing shape */),\n\t]);\n}\n\nfunction encodeIdentifier(\n\tidentifier: string,\n\tidentifiers: DeduplicationTable<string>,\n): string | number {\n\treturn identifiers.valueToIndex.get(identifier) ?? identifier;\n}\n\nfunction encodeOptionalIdentifier(\n\tidentifier: string | undefined,\n\tidentifiers: DeduplicationTable<string>,\n): string | number | undefined {\n\treturn identifier === undefined ? undefined : encodeIdentifier(identifier, identifiers);\n}\n\nfunction encodeOptionalFieldShape(\n\tencoder: FieldEncoder | undefined,\n\tshapes: DeduplicationTable<Shape<EncodedChunkShape>>,\n): number | undefined {\n\treturn encoder === undefined ? undefined : dedupShape(encoder.shape, shapes);\n}\n\nfunction dedupShape(\n\tshape: Shape<EncodedChunkShape>,\n\tshapes: DeduplicationTable<Shape<EncodedChunkShape>>,\n): number {\n\treturn shapes.valueToIndex.get(shape) ?? fail(0xb51 /* missing shape */);\n}\n"]}
@@ -5,10 +5,10 @@
5
5
  import type { IIdCompressor } from "@fluidframework/id-compressor";
6
6
  import { type StoredSchemaCollection, type TreeFieldStoredSchema, type TreeNodeSchemaIdentifier } from "../../../core/index.js";
7
7
  import type { FullSchemaPolicy } from "../../modular-schema/index.js";
8
- import { EncoderCache, type FieldEncoder, type FieldShaper, type TreeShaper } from "./compressedEncode.js";
8
+ import { EncoderContext, type FieldEncoder, type FieldEncodeBuilder, type NodeEncodeBuilder } from "./compressedEncode.js";
9
9
  import type { FieldBatch } from "./fieldBatch.js";
10
10
  import { type EncodedFieldBatch } from "./format.js";
11
- import { NodeShape } from "./nodeShape.js";
11
+ import { NodeShapeBasedEncoder } from "./nodeEncoder.js";
12
12
  /**
13
13
  * Encode data from `fieldBatch` in into an `EncodedChunk`.
14
14
  *
@@ -16,14 +16,14 @@ import { NodeShape } from "./nodeShape.js";
16
16
  * TODO: This function should eventually also take in the root FieldSchema to more efficiently compress the nodes.
17
17
  */
18
18
  export declare function schemaCompressedEncode(schema: StoredSchemaCollection, policy: FullSchemaPolicy, fieldBatch: FieldBatch, idCompressor: IIdCompressor): EncodedFieldBatch;
19
- export declare function buildCache(schema: StoredSchemaCollection, policy: FullSchemaPolicy, idCompressor: IIdCompressor): EncoderCache;
19
+ export declare function buildContext(storedSchema: StoredSchemaCollection, policy: FullSchemaPolicy, idCompressor: IIdCompressor): EncoderContext;
20
20
  /**
21
- * Selects shapes to use to encode fields.
21
+ * Selects an encoder to use to encode fields.
22
22
  */
23
- export declare function fieldShaper(treeHandler: TreeShaper, field: TreeFieldStoredSchema, cache: EncoderCache, storedSchema: StoredSchemaCollection): FieldEncoder;
23
+ export declare function getFieldEncoder(nodeBuilder: NodeEncodeBuilder, field: TreeFieldStoredSchema, context: EncoderContext, storedSchema: StoredSchemaCollection): FieldEncoder;
24
24
  /**
25
- * Selects shapes to use to encode trees.
25
+ * Selects an encoder to use to encode nodes.
26
26
  */
27
- export declare function treeShaper(fullSchema: StoredSchemaCollection, policy: FullSchemaPolicy, fieldHandler: FieldShaper, schemaName: TreeNodeSchemaIdentifier): NodeShape;
27
+ export declare function getNodeEncoder(fieldBuilder: FieldEncodeBuilder, storedSchema: StoredSchemaCollection, schemaName: TreeNodeSchemaIdentifier): NodeShapeBasedEncoder;
28
28
  export declare function oneFromSet<T>(set: ReadonlySet<T> | undefined): T | undefined;
29
29
  //# sourceMappingURL=schemaBasedEncode.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemaBasedEncode.d.ts","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/schemaBasedEncode.ts"],"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{"version":3,"file":"schemaBasedEncode.d.ts","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/schemaBasedEncode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EAIN,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAI7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,EACN,cAAc,EACd,KAAK,YAAY,EACjB,KAAK,kBAAkB,EAEvB,KAAK,iBAAiB,EAItB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,KAAK,iBAAiB,EAAwC,MAAM,aAAa,CAAC;AAC3F,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACrC,MAAM,EAAE,sBAAsB,EAC9B,MAAM,EAAE,gBAAgB,EACxB,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,aAAa,GACzB,iBAAiB,CAEnB;AAED,wBAAgB,YAAY,CAC3B,YAAY,EAAE,sBAAsB,EACpC,MAAM,EAAE,gBAAgB,EACxB,YAAY,EAAE,aAAa,GACzB,cAAc,CAUhB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC9B,WAAW,EAAE,iBAAiB,EAC9B,KAAK,EAAE,qBAAqB,EAC5B,OAAO,EAAE,cAAc,EACvB,YAAY,EAAE,sBAAsB,GAClC,YAAY,CA8Bd;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC7B,YAAY,EAAE,kBAAkB,EAChC,YAAY,EAAE,sBAAsB,EACpC,UAAU,EAAE,wBAAwB,GAClC,qBAAqB,CAoCvB;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,CAAC,GAAG,SAAS,CAU5E"}
@@ -4,9 +4,9 @@
4
4
  */
5
5
  import { assert, unreachableCase, fail } from "@fluidframework/core-utils/internal";
6
6
  import { LeafNodeStoredSchema, MapNodeStoredSchema, ObjectNodeStoredSchema, ValueSchema, Multiplicity, identifierFieldKindIdentifier, } from "../../../core/index.js";
7
- import { EncoderCache, anyNodeEncoder, asFieldEncoder, compressedEncode, } from "./compressedEncode.js";
7
+ import { EncoderContext, anyNodeEncoder, asFieldEncoder, compressedEncode, } from "./compressedEncode.js";
8
8
  import { SpecialField } from "./format.js";
9
- import { NodeShape } from "./nodeShape.js";
9
+ import { NodeShapeBasedEncoder } from "./nodeEncoder.js";
10
10
  /**
11
11
  * Encode data from `fieldBatch` in into an `EncodedChunk`.
12
12
  *
@@ -14,19 +14,19 @@ import { NodeShape } from "./nodeShape.js";
14
14
  * TODO: This function should eventually also take in the root FieldSchema to more efficiently compress the nodes.
15
15
  */
16
16
  export function schemaCompressedEncode(schema, policy, fieldBatch, idCompressor) {
17
- return compressedEncode(fieldBatch, buildCache(schema, policy, idCompressor));
17
+ return compressedEncode(fieldBatch, buildContext(schema, policy, idCompressor));
18
18
  }
19
- export function buildCache(schema, policy, idCompressor) {
20
- const cache = new EncoderCache((fieldHandler, schemaName) => treeShaper(schema, policy, fieldHandler, schemaName), (treeHandler, field) => fieldShaper(treeHandler, field, cache, schema), policy.fieldKinds, idCompressor);
21
- return cache;
19
+ export function buildContext(storedSchema, policy, idCompressor) {
20
+ const context = new EncoderContext((fieldBuilder, schemaName) => getNodeEncoder(fieldBuilder, storedSchema, schemaName), (nodeBuilder, fieldSchema) => getFieldEncoder(nodeBuilder, fieldSchema, context, storedSchema), policy.fieldKinds, idCompressor);
21
+ return context;
22
22
  }
23
23
  /**
24
- * Selects shapes to use to encode fields.
24
+ * Selects an encoder to use to encode fields.
25
25
  */
26
- export function fieldShaper(treeHandler, field, cache, storedSchema) {
27
- const kind = cache.fieldShapes.get(field.kind) ?? fail(0xb52 /* missing FieldKind */);
26
+ export function getFieldEncoder(nodeBuilder, field, context, storedSchema) {
27
+ const kind = context.fieldShapes.get(field.kind) ?? fail(0xb52 /* missing FieldKind */);
28
28
  const type = oneFromSet(field.types);
29
- const nodeEncoder = type !== undefined ? treeHandler.shapeFromTree(type) : anyNodeEncoder;
29
+ const nodeEncoder = type !== undefined ? nodeBuilder.nodeEncoderFromSchema(type) : anyNodeEncoder;
30
30
  if (kind.multiplicity === Multiplicity.Single) {
31
31
  if (field.kind === identifierFieldKindIdentifier) {
32
32
  assert(type !== undefined, 0x999 /* field type must be defined in identifier field */);
@@ -34,37 +34,37 @@ export function fieldShaper(treeHandler, field, cache, storedSchema) {
34
34
  assert(nodeSchema !== undefined, 0x99a /* nodeSchema must be defined */);
35
35
  assert(nodeSchema instanceof LeafNodeStoredSchema, 0x99b /* nodeSchema must be LeafNodeStoredSchema */);
36
36
  assert(nodeSchema.leafValue === ValueSchema.String, 0x99c /* identifier field can only be type string */);
37
- const identifierNodeEncoder = new NodeShape(type, SpecialField.Identifier, [], undefined);
37
+ const identifierNodeEncoder = new NodeShapeBasedEncoder(type, SpecialField.Identifier, [], undefined);
38
38
  return asFieldEncoder(identifierNodeEncoder);
39
39
  }
40
40
  return asFieldEncoder(nodeEncoder);
41
41
  }
42
42
  else {
43
- return cache.nestedArray(nodeEncoder);
43
+ return context.nestedArrayEncoder(nodeEncoder);
44
44
  }
45
45
  }
46
46
  /**
47
- * Selects shapes to use to encode trees.
47
+ * Selects an encoder to use to encode nodes.
48
48
  */
49
- export function treeShaper(fullSchema, policy, fieldHandler, schemaName) {
50
- const schema = fullSchema.nodeSchema.get(schemaName) ?? fail(0xb53 /* missing node schema */);
49
+ export function getNodeEncoder(fieldBuilder, storedSchema, schemaName) {
50
+ const schema = storedSchema.nodeSchema.get(schemaName) ?? fail(0xb53 /* missing node schema */);
51
51
  if (schema instanceof ObjectNodeStoredSchema) {
52
52
  // TODO:Performance:
53
53
  // consider moving some optional and sequence fields to extra fields if they are commonly empty
54
54
  // to reduce encoded size.
55
55
  const objectNodeFields = [];
56
56
  for (const [key, field] of schema.objectNodeFields ?? []) {
57
- objectNodeFields.push({ key, encoder: fieldHandler.shapeFromField(field) });
57
+ objectNodeFields.push({ key, encoder: fieldBuilder.fieldEncoderFromSchema(field) });
58
58
  }
59
- const shape = new NodeShape(schemaName, false, objectNodeFields, undefined);
59
+ const shape = new NodeShapeBasedEncoder(schemaName, false, objectNodeFields, undefined);
60
60
  return shape;
61
61
  }
62
62
  if (schema instanceof LeafNodeStoredSchema) {
63
- const shape = new NodeShape(schemaName, valueShapeFromSchema(schema.leafValue), [], undefined);
63
+ const shape = new NodeShapeBasedEncoder(schemaName, valueShapeFromSchema(schema.leafValue), [], undefined);
64
64
  return shape;
65
65
  }
66
66
  if (schema instanceof MapNodeStoredSchema) {
67
- const shape = new NodeShape(schemaName, false, [], fieldHandler.shapeFromField(schema.mapFields));
67
+ const shape = new NodeShapeBasedEncoder(schemaName, false, [], fieldBuilder.fieldEncoderFromSchema(schema.mapFields));
68
68
  return shape;
69
69
  }
70
70
  fail(0xb54 /* unsupported node kind */);
@@ -1 +1 @@
1
- {"version":3,"file":"schemaBasedEncode.js","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/schemaBasedEncode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAGpF,OAAO,EACN,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,EAItB,WAAW,EACX,YAAY,EACZ,6BAA6B,GAC7B,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACN,YAAY,EAKZ,cAAc,EACd,cAAc,EACd,gBAAgB,GAChB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAkD,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3F,OAAO,EAAE,S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AAC,IAAI,CAAC,CAAC;QACf;YACC,eAAe,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase, fail } from \"@fluidframework/core-utils/internal\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\n\nimport {\n\tLeafNodeStoredSchema,\n\tMapNodeStoredSchema,\n\tObjectNodeStoredSchema,\n\ttype StoredSchemaCollection,\n\ttype TreeFieldStoredSchema,\n\ttype TreeNodeSchemaIdentifier,\n\tValueSchema,\n\tMultiplicity,\n\tidentifierFieldKindIdentifier,\n} from \"../../../core/index.js\";\nimport type { FullSchemaPolicy } from \"../../modular-schema/index.js\";\n\nimport {\n\tEncoderCache,\n\ttype FieldEncoder,\n\ttype FieldShaper,\n\ttype KeyedFieldEncoder,\n\ttype TreeShaper,\n\tanyNodeEncoder,\n\tasFieldEncoder,\n\tcompressedEncode,\n} from \"./compressedEncode.js\";\nimport type { FieldBatch } from \"./fieldBatch.js\";\nimport { type EncodedFieldBatch, type EncodedValueShape, SpecialField } from \"./format.js\";\nimport { NodeShape } from \"./nodeShape.js\";\n\n/**\n * Encode data from `fieldBatch` in into an `EncodedChunk`.\n *\n * Optimized for encoded size and encoding performance.\n * TODO: This function should eventually also take in the root FieldSchema to more efficiently compress the nodes.\n */\nexport function schemaCompressedEncode(\n\tschema: StoredSchemaCollection,\n\tpolicy: FullSchemaPolicy,\n\tfieldBatch: FieldBatch,\n\tidCompressor: IIdCompressor,\n): EncodedFieldBatch {\n\treturn compressedEncode(fieldBatch, buildCache(schema, policy, idCompressor));\n}\n\nexport function buildCache(\n\tschema: StoredSchemaCollection,\n\tpolicy: FullSchemaPolicy,\n\tidCompressor: IIdCompressor,\n): EncoderCache {\n\tconst cache: EncoderCache = new EncoderCache(\n\t\t(fieldHandler: FieldShaper, schemaName: TreeNodeSchemaIdentifier) =>\n\t\t\ttreeShaper(schema, policy, fieldHandler, schemaName),\n\t\t(treeHandler: TreeShaper, field: TreeFieldStoredSchema) =>\n\t\t\tfieldShaper(treeHandler, field, cache, schema),\n\t\tpolicy.fieldKinds,\n\t\tidCompressor,\n\t);\n\treturn cache;\n}\n\n/**\n * Selects shapes to use to encode fields.\n */\nexport function fieldShaper(\n\ttreeHandler: TreeShaper,\n\tfield: TreeFieldStoredSchema,\n\tcache: EncoderCache,\n\tstoredSchema: StoredSchemaCollection,\n): FieldEncoder {\n\tconst kind = cache.fieldShapes.get(field.kind) ?? fail(0xb52 /* missing FieldKind */);\n\tconst type = oneFromSet(field.types);\n\tconst nodeEncoder = type !== undefined ? treeHandler.shapeFromTree(type) : anyNodeEncoder;\n\tif (kind.multiplicity === Multiplicity.Single) {\n\t\tif (field.kind === identifierFieldKindIdentifier) {\n\t\t\tassert(type !== undefined, 0x999 /* field type must be defined in identifier field */);\n\t\t\tconst nodeSchema = storedSchema.nodeSchema.get(type);\n\t\t\tassert(nodeSchema !== undefined, 0x99a /* nodeSchema must be defined */);\n\t\t\tassert(\n\t\t\t\tnodeSchema instanceof LeafNodeStoredSchema,\n\t\t\t\t0x99b /* nodeSchema must be LeafNodeStoredSchema */,\n\t\t\t);\n\t\t\tassert(\n\t\t\t\tnodeSchema.leafValue === ValueSchema.String,\n\t\t\t\t0x99c /* identifier field can only be type string */,\n\t\t\t);\n\t\t\tconst identifierNodeEncoder = new NodeShape(\n\t\t\t\ttype,\n\t\t\t\tSpecialField.Identifier,\n\t\t\t\t[],\n\t\t\t\tundefined,\n\t\t\t);\n\t\t\treturn asFieldEncoder(identifierNodeEncoder);\n\t\t}\n\t\treturn asFieldEncoder(nodeEncoder);\n\t} else {\n\t\treturn cache.nestedArray(nodeEncoder);\n\t}\n}\n\n/**\n * Selects shapes to use to encode trees.\n */\nexport function treeShaper(\n\tfullSchema: StoredSchemaCollection,\n\tpolicy: FullSchemaPolicy,\n\tfieldHandler: FieldShaper,\n\tschemaName: TreeNodeSchemaIdentifier,\n): NodeShape {\n\tconst schema =\n\t\tfullSchema.nodeSchema.get(schemaName) ?? fail(0xb53 /* missing node schema */);\n\n\tif (schema instanceof ObjectNodeStoredSchema) {\n\t\t// TODO:Performance:\n\t\t// consider moving some optional and sequence fields to extra fields if they are commonly empty\n\t\t// to reduce encoded size.\n\n\t\tconst objectNodeFields: KeyedFieldEncoder[] = [];\n\t\tfor (const [key, field] of schema.objectNodeFields ?? []) {\n\t\t\tobjectNodeFields.push({ key, encoder: fieldHandler.shapeFromField(field) });\n\t\t}\n\n\t\tconst shape = new NodeShape(schemaName, false, objectNodeFields, undefined);\n\t\treturn shape;\n\t}\n\tif (schema instanceof LeafNodeStoredSchema) {\n\t\tconst shape = new NodeShape(\n\t\t\tschemaName,\n\t\t\tvalueShapeFromSchema(schema.leafValue),\n\t\t\t[],\n\t\t\tundefined,\n\t\t);\n\t\treturn shape;\n\t}\n\tif (schema instanceof MapNodeStoredSchema) {\n\t\tconst shape = new NodeShape(\n\t\t\tschemaName,\n\t\t\tfalse,\n\t\t\t[],\n\t\t\tfieldHandler.shapeFromField(schema.mapFields),\n\t\t);\n\t\treturn shape;\n\t}\n\tfail(0xb54 /* unsupported node kind */);\n}\n\nexport function oneFromSet<T>(set: ReadonlySet<T> | undefined): T | undefined {\n\tif (set === undefined) {\n\t\treturn undefined;\n\t}\n\tif (set.size !== 1) {\n\t\treturn undefined;\n\t}\n\tfor (const item of set) {\n\t\treturn item;\n\t}\n}\n\nfunction valueShapeFromSchema(schema: ValueSchema | undefined): undefined | EncodedValueShape {\n\tswitch (schema) {\n\t\tcase undefined:\n\t\t\treturn false;\n\t\tcase ValueSchema.Number:\n\t\tcase ValueSchema.String:\n\t\tcase ValueSchema.Boolean:\n\t\tcase ValueSchema.FluidHandle:\n\t\t\treturn true;\n\t\tcase ValueSchema.Null:\n\t\t\treturn [null];\n\t\tdefault:\n\t\t\tunreachableCase(schema);\n\t}\n}\n"]}
1
+ {"version":3,"file":"schemaBasedEnc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,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,GAAG,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC;AAED,SAAS,oBAAoB,CAAC,MAA+B;IAC5D,QAAQ,MAAM,EAAE,CAAC;QAChB,KAAK,SAAS;YACb,OAAO,KAAK,CAAC;QACd,KAAK,WAAW,CAAC,MAAM,CAAC;QACxB,KAAK,WAAW,CAAC,MAAM,CAAC;QACxB,KAAK,WAAW,CAAC,OAAO,CAAC;QACzB,KAAK,WAAW,CAAC,WAAW;YAC3B,OAAO,IAAI,CAAC;QACb,KAAK,WAAW,CAAC,IAAI;YACpB,OAAO,CAAC,IAAI,CAAC,CAAC;QACf;YACC,eAAe,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase, fail } from \"@fluidframework/core-utils/internal\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\n\nimport {\n\tLeafNodeStoredSchema,\n\tMapNodeStoredSchema,\n\tObjectNodeStoredSchema,\n\ttype StoredSchemaCollection,\n\ttype TreeFieldStoredSchema,\n\ttype TreeNodeSchemaIdentifier,\n\tValueSchema,\n\tMultiplicity,\n\tidentifierFieldKindIdentifier,\n} from \"../../../core/index.js\";\nimport type { FullSchemaPolicy } from \"../../modular-schema/index.js\";\n\nimport {\n\tEncoderContext,\n\ttype FieldEncoder,\n\ttype FieldEncodeBuilder,\n\ttype KeyedFieldEncoder,\n\ttype NodeEncodeBuilder,\n\tanyNodeEncoder,\n\tasFieldEncoder,\n\tcompressedEncode,\n} from \"./compressedEncode.js\";\nimport type { FieldBatch } from \"./fieldBatch.js\";\nimport { type EncodedFieldBatch, type EncodedValueShape, SpecialField } from \"./format.js\";\nimport { NodeShapeBasedEncoder } from \"./nodeEncoder.js\";\n\n/**\n * Encode data from `fieldBatch` in into an `EncodedChunk`.\n *\n * Optimized for encoded size and encoding performance.\n * TODO: This function should eventually also take in the root FieldSchema to more efficiently compress the nodes.\n */\nexport function schemaCompressedEncode(\n\tschema: StoredSchemaCollection,\n\tpolicy: FullSchemaPolicy,\n\tfieldBatch: FieldBatch,\n\tidCompressor: IIdCompressor,\n): EncodedFieldBatch {\n\treturn compressedEncode(fieldBatch, buildContext(schema, policy, idCompressor));\n}\n\nexport function buildContext(\n\tstoredSchema: StoredSchemaCollection,\n\tpolicy: FullSchemaPolicy,\n\tidCompressor: IIdCompressor,\n): EncoderContext {\n\tconst context: EncoderContext = new EncoderContext(\n\t\t(fieldBuilder: FieldEncodeBuilder, schemaName: TreeNodeSchemaIdentifier) =>\n\t\t\tgetNodeEncoder(fieldBuilder, storedSchema, schemaName),\n\t\t(nodeBuilder: NodeEncodeBuilder, fieldSchema: TreeFieldStoredSchema) =>\n\t\t\tgetFieldEncoder(nodeBuilder, fieldSchema, context, storedSchema),\n\t\tpolicy.fieldKinds,\n\t\tidCompressor,\n\t);\n\treturn context;\n}\n\n/**\n * Selects an encoder to use to encode fields.\n */\nexport function getFieldEncoder(\n\tnodeBuilder: NodeEncodeBuilder,\n\tfield: TreeFieldStoredSchema,\n\tcontext: EncoderContext,\n\tstoredSchema: StoredSchemaCollection,\n): FieldEncoder {\n\tconst kind = context.fieldShapes.get(field.kind) ?? fail(0xb52 /* missing FieldKind */);\n\tconst type = oneFromSet(field.types);\n\tconst nodeEncoder =\n\t\ttype !== undefined ? nodeBuilder.nodeEncoderFromSchema(type) : anyNodeEncoder;\n\tif (kind.multiplicity === Multiplicity.Single) {\n\t\tif (field.kind === identifierFieldKindIdentifier) {\n\t\t\tassert(type !== undefined, 0x999 /* field type must be defined in identifier field */);\n\t\t\tconst nodeSchema = storedSchema.nodeSchema.get(type);\n\t\t\tassert(nodeSchema !== undefined, 0x99a /* nodeSchema must be defined */);\n\t\t\tassert(\n\t\t\t\tnodeSchema instanceof LeafNodeStoredSchema,\n\t\t\t\t0x99b /* nodeSchema must be LeafNodeStoredSchema */,\n\t\t\t);\n\t\t\tassert(\n\t\t\t\tnodeSchema.leafValue === ValueSchema.String,\n\t\t\t\t0x99c /* identifier field can only be type string */,\n\t\t\t);\n\t\t\tconst identifierNodeEncoder = new NodeShapeBasedEncoder(\n\t\t\t\ttype,\n\t\t\t\tSpecialField.Identifier,\n\t\t\t\t[],\n\t\t\t\tundefined,\n\t\t\t);\n\t\t\treturn asFieldEncoder(identifierNodeEncoder);\n\t\t}\n\t\treturn asFieldEncoder(nodeEncoder);\n\t} else {\n\t\treturn context.nestedArrayEncoder(nodeEncoder);\n\t}\n}\n\n/**\n * Selects an encoder to use to encode nodes.\n */\nexport function getNodeEncoder(\n\tfieldBuilder: FieldEncodeBuilder,\n\tstoredSchema: StoredSchemaCollection,\n\tschemaName: TreeNodeSchemaIdentifier,\n): NodeShapeBasedEncoder {\n\tconst schema =\n\t\tstoredSchema.nodeSchema.get(schemaName) ?? fail(0xb53 /* missing node schema */);\n\n\tif (schema instanceof ObjectNodeStoredSchema) {\n\t\t// TODO:Performance:\n\t\t// consider moving some optional and sequence fields to extra fields if they are commonly empty\n\t\t// to reduce encoded size.\n\n\t\tconst objectNodeFields: KeyedFieldEncoder[] = [];\n\t\tfor (const [key, field] of schema.objectNodeFields ?? []) {\n\t\t\tobjectNodeFields.push({ key, encoder: fieldBuilder.fieldEncoderFromSchema(field) });\n\t\t}\n\n\t\tconst shape = new NodeShapeBasedEncoder(schemaName, false, objectNodeFields, undefined);\n\t\treturn shape;\n\t}\n\tif (schema instanceof LeafNodeStoredSchema) {\n\t\tconst shape = new NodeShapeBasedEncoder(\n\t\t\tschemaName,\n\t\t\tvalueShapeFromSchema(schema.leafValue),\n\t\t\t[],\n\t\t\tundefined,\n\t\t);\n\t\treturn shape;\n\t}\n\tif (schema instanceof MapNodeStoredSchema) {\n\t\tconst shape = new NodeShapeBasedEncoder(\n\t\t\tschemaName,\n\t\t\tfalse,\n\t\t\t[],\n\t\t\tfieldBuilder.fieldEncoderFromSchema(schema.mapFields),\n\t\t);\n\t\treturn shape;\n\t}\n\tfail(0xb54 /* unsupported node kind */);\n}\n\nexport function oneFromSet<T>(set: ReadonlySet<T> | undefined): T | undefined {\n\tif (set === undefined) {\n\t\treturn undefined;\n\t}\n\tif (set.size !== 1) {\n\t\treturn undefined;\n\t}\n\tfor (const item of set) {\n\t\treturn item;\n\t}\n}\n\nfunction valueShapeFromSchema(schema: ValueSchema | undefined): undefined | EncodedValueShape {\n\tswitch (schema) {\n\t\tcase undefined:\n\t\t\treturn false;\n\t\tcase ValueSchema.Number:\n\t\tcase ValueSchema.String:\n\t\tcase ValueSchema.Boolean:\n\t\tcase ValueSchema.FluidHandle:\n\t\t\treturn true;\n\t\tcase ValueSchema.Null:\n\t\t\treturn [null];\n\t\tdefault:\n\t\t\tunreachableCase(schema);\n\t}\n}\n"]}
@@ -18,14 +18,14 @@ export function uncompressedEncode(batch) {
18
18
  version,
19
19
  identifiers: [],
20
20
  // A single shape used to encode all fields.
21
- shapes: [{ c: anyTreeShape }, { a: anyArray }],
21
+ shapes: [{ c: anyNodeShape }, { a: anyArray }],
22
22
  // Wrap up each field as an indicator to use the above shape, and its encoded data.
23
23
  data: rootFields.map((data) => [arrayIndex, data]),
24
24
  };
25
25
  }
26
26
  const treeIndex = 0;
27
27
  const arrayIndex = 1;
28
- const anyTreeShape = {
28
+ const anyNodeShape = {
29
29
  extraFields: arrayIndex,
30
30
  };
31
31
  const anyArray = treeIndex;
@@ -1 +1 @@
1
- {"version":3,"file":"uncompressedEncode.js","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/uncompressedEncode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEN,YAAY,EACZ,WAAW,GACX,MAAM,wBAAwB,CAAC;AAIhC,OAAO,EAIN,OAAO,GACP,MAAM,aAAa,CAAC;AAGrB;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CA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,CAAC;IAClB,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\ttype ITreeCursorSynchronous,\n\tforEachField,\n\tforEachNode,\n} from \"../../../core/index.js\";\nimport type { FluidSerializableReadOnly } from \"../../valueUtilities.js\";\n\nimport type { FieldBatch } from \"./fieldBatch.js\";\nimport {\n\ttype EncodedFieldBatch,\n\ttype EncodedNestedArray,\n\ttype EncodedTreeShape,\n\tversion,\n} from \"./format.js\";\nimport type { ShapeIndex } from \"./formatGeneric.js\";\n\n/**\n * Encode data from `cursor` in the simplest way supported by `EncodedChunk`.\n *\n * No polymorphism, identifier deduplication or schema based compression.\n * Just uses two hard coded shapes and inline identifiers.\n *\n * This is intended as a simple reference implementation with minimal code and dependencies.\n */\nexport function uncompressedEncode(batch: FieldBatch): EncodedFieldBatch {\n\tconst rootFields = batch.map(encodeSequence);\n\treturn {\n\t\tversion,\n\t\tidentifiers: [],\n\t\t// A single shape used to encode all fields.\n\t\tshapes: [{ c: anyTreeShape }, { a: anyArray }],\n\t\t// Wrap up each field as an indicator to use the above shape, and its encoded data.\n\t\tdata: rootFields.map((data) => [arrayIndex, data]),\n\t};\n}\n\nconst treeIndex: ShapeIndex = 0;\nconst arrayIndex: ShapeIndex = 1;\n\nconst anyTreeShape: EncodedTreeShape = {\n\textraFields: arrayIndex,\n};\n\nconst anyArray: EncodedNestedArray = treeIndex;\n\n/**\n * Encode a field using the hard coded shape above.\n * @remarks\n * Since this shape contains no information about the actual schema, all schema/shape information is inline in the data:\n * that is why this encoding is called \"uncompressed\".\n */\nfunction encodeSequence(cursor: ITreeCursorSynchronous): FluidSerializableReadOnly[] {\n\tconst data: FluidSerializableReadOnly[] = [];\n\tforEachNode(cursor, () => {\n\t\tdata.push(cursor.type);\n\t\tconst value = cursor.value;\n\t\tdata.push(value !== undefined);\n\t\tif (value !== undefined) {\n\t\t\tdata.push(value);\n\t\t}\n\t\tconst local: FluidSerializableReadOnly[] = [];\n\t\tforEachField(cursor, () => {\n\t\t\tconst key = cursor.getFieldKey();\n\t\t\tlocal.push(key, encodeSequence(cursor));\n\t\t});\n\t\tdata.push(local);\n\t});\n\treturn data;\n}\n"]}
1
+ {"version":3,"file":"uncompressedEncode.js","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/uncompressedEncode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEN,YAAY,EACZ,WAAW,GACX,MAAM,wBAAwB,CAAC;AAIhC,OAAO,EAIN,OAAO,GACP,MAAM,aAAa,CAAC;AAGrB;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAiB;IACnD,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAC7C,OAAO;QACN,OAAO;QACP,WAAW,EAAE,EAAE;QACf,4CAA4C;QAC5C,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC;QAC9C,mFAAmF;QACnF,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;KAClD,CAAC;AACH,CAAC;AAED,MAAM,SAAS,GAAe,CAAC,CAAC;AAChC,MAAM,UAAU,GAAe,CAAC,CAAC;AAEjC,MAAM,YAAY,GAAqB;IACtC,WAAW,EAAE,UAAU;CACvB,CAAC;AAEF,MAAM,QAAQ,GAA4B,SAAS,CAAC;AAEpD;;;;;GAKG;AACH,SAAS,cAAc,CAAC,MAA8B;IACrD,MAAM,IAAI,GAAgC,EAAE,CAAC;IAC7C,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE;QACxB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACvB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC;QAC/B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACzB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;QACD,MAAM,KAAK,GAAgC,EAAE,CAAC;QAC9C,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE;YACzB,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;YACjC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\ttype ITreeCursorSynchronous,\n\tforEachField,\n\tforEachNode,\n} from \"../../../core/index.js\";\nimport type { FluidSerializableReadOnly } from \"../../valueUtilities.js\";\n\nimport type { FieldBatch } from \"./fieldBatch.js\";\nimport {\n\ttype EncodedFieldBatch,\n\ttype EncodedNestedArrayShape,\n\ttype EncodedNodeShape,\n\tversion,\n} from \"./format.js\";\nimport type { ShapeIndex } from \"./formatGeneric.js\";\n\n/**\n * Encode data from `cursor` in the simplest way supported by `EncodedChunk`.\n *\n * No polymorphism, identifier deduplication or schema based compression.\n * Just uses two hard coded shapes and inline identifiers.\n *\n * This is intended as a simple reference implementation with minimal code and dependencies.\n */\nexport function uncompressedEncode(batch: FieldBatch): EncodedFieldBatch {\n\tconst rootFields = batch.map(encodeSequence);\n\treturn {\n\t\tversion,\n\t\tidentifiers: [],\n\t\t// A single shape used to encode all fields.\n\t\tshapes: [{ c: anyNodeShape }, { a: anyArray }],\n\t\t// Wrap up each field as an indicator to use the above shape, and its encoded data.\n\t\tdata: rootFields.map((data) => [arrayIndex, data]),\n\t};\n}\n\nconst treeIndex: ShapeIndex = 0;\nconst arrayIndex: ShapeIndex = 1;\n\nconst anyNodeShape: EncodedNodeShape = {\n\textraFields: arrayIndex,\n};\n\nconst anyArray: EncodedNestedArrayShape = treeIndex;\n\n/**\n * Encode a field using the hard coded shape above.\n * @remarks\n * Since this shape contains no information about the actual schema, all schema/shape information is inline in the data:\n * that is why this encoding is called \"uncompressed\".\n */\nfunction encodeSequence(cursor: ITreeCursorSynchronous): FluidSerializableReadOnly[] {\n\tconst data: FluidSerializableReadOnly[] = [];\n\tforEachNode(cursor, () => {\n\t\tdata.push(cursor.type);\n\t\tconst value = cursor.value;\n\t\tdata.push(value !== undefined);\n\t\tif (value !== undefined) {\n\t\t\tdata.push(value);\n\t\t}\n\t\tconst local: FluidSerializableReadOnly[] = [];\n\t\tforEachField(cursor, () => {\n\t\t\tconst key = cursor.getFieldKey();\n\t\t\tlocal.push(key, encodeSequence(cursor));\n\t\t});\n\t\tdata.push(local);\n\t});\n\treturn data;\n}\n"]}
@@ -35,6 +35,10 @@ export declare const required: FieldKindWithEditor<ValueFieldEditor, Multiplicit
35
35
  export declare const sequence: FieldKindWithEditor<import("../sequence-field/sequenceFieldEditor.js").SequenceFieldEditor, Multiplicity.Sequence, "Sequence">;
36
36
  /**
37
37
  * Exactly one identifier.
38
+ *
39
+ * TODO: this is almost the same as identifier, but apparently unused.
40
+ * Confirm if this is truly unused since before the document format was stabilized, and remove if possible.
41
+ * @deprecated Superseded by {@link identifier}.
38
42
  */
39
43
  export declare const nodeKey: FieldKindWithEditor<FieldEditor<0>, Multiplicity.Single, "NodeKey">;
40
44
  /**
@@ -69,7 +73,7 @@ export declare const identifier: FieldKindWithEditor<FieldEditor<0>, Multiplicit
69
73
  *
70
74
  * See {@link emptyField} for a constant, reusable field using Forbidden.
71
75
  */
72
- export declare const forbidden: FieldKindWithEditor<FieldEditor<0>, Multiplicity.Forbidden, "Forbidden">;
76
+ export declare const forbidden: FieldKindWithEditor<FieldEditor<0>, Multiplicity.Forbidden, FieldKindIdentifier>;
73
77
  export declare const fieldKindConfigurations: ReadonlyMap<number, FieldKindConfiguration>;
74
78
  /**
75
79
  * All supported field kinds.
@@ -1 +1 @@
1
- {"version":3,"file":"defaultFieldKinds.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/default-schema/defaultFieldKinds.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,KAAK,YAAY,EAEjB,KAAK,mBAAmB,EACxB,4BAA4B,EAC5B,YAAY,EACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAEN,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,KAAK,sBAAsB,EAE3B,mBAAmB,EACnB,KAAK,aAAa,EAIlB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACN,KAAK,iBAAiB,EAGtB,MAAM,4BAA4B,CAAC;AAKpC;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,kBAAkB,CAAC,CAAC,CAcjD,CAAC;AAEF,MAAM,WAAW,gBAAiB,SAAQ,WAAW,CAAC,iBAAiB,CAAC;IACvE;;;OAGG;IACH,GAAG,CAAC,GAAG,EAAE;QAAE,IAAI,EAAE,YAAY,CAAC;QAAC,MAAM,EAAE,YAAY,CAAA;KAAE,GAAG,iBAAiB,CAAC;CAC1E;AAGD;;GAEG;AACH,eAAO,MAAM,QAAQ,0HAQpB,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,gBAM9B,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,kBAAkB,CAAC,iBAAiB,EAAE,gBAAgB,CAGtF,CAAC;AAIF;;GAEG;AACH,eAAO,MAAM,QAAQ,qEAWpB,CAAC;AAIF;;GAEG;AACH,eAAO,MAAM,QAAQ,gIASpB,CAAC;AAIF;;GAEG;AACH,eAAO,MAAM,OAAO,qEAWnB,CAAC;AAIF;;GAEG;AACH,eAAO,MAAM,UAAU,wEAWtB,C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Y,CAAC,QAAQ,CAAC;CAAG;AACrF,MAAM,WAAW,QAAS,SAAQ,aAAa,CAAC,UAAU,EAAE,YAAY,CAAC,QAAQ,CAAC;CAAG;AACrF,MAAM,WAAW,UAAW,SAAQ,aAAa,CAAC,YAAY,EAAE,YAAY,CAAC,MAAM,CAAC;CAAG;AACvF,MAAM,WAAW,SAChB,SAAQ,aAAa,CAAC,OAAO,4BAA4B,EAAE,YAAY,CAAC,SAAS,CAAC;CAAG;AAEtF;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE;IAExB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC4B,CAAC"}
@@ -44,7 +44,13 @@ const requiredIdentifier = "Value";
44
44
  /**
45
45
  * Exactly one item.
46
46
  */
47
- export const required = new FieldKindWithEditor(requiredIdentifier, Multiplicity.Single, valueChangeHandler, (types, other) => (other.kind === sequence.identifier ||
47
+ export const required = new FieldKindWithEditor(requiredIdentifier, Multiplicity.Single, valueChangeHandler, (types, other) =>
48
+ // By omitting Identifier here,
49
+ // this is making a policy choice that a schema upgrade cannot be done from required to identifier.
50
+ // Since an identifier can be upgraded into a required field,
51
+ // preventing the inverse helps ensure that schema upgrades are monotonic.
52
+ // Which direction is allowed is a subjective policy choice.
53
+ (other.kind === sequence.identifier ||
48
54
  other.kind === requiredIdentifier ||
49
55
  other.kind === optional.identifier ||
50
56
  other.kind === nodeKey.identifier) &&
@@ -60,6 +66,10 @@ new Set([]));
60
66
  const nodeKeyIdentifier = "NodeKey";
61
67
  /**
62
68
  * Exactly one identifier.
69
+ *
70
+ * TODO: this is almost the same as identifier, but apparently unused.
71
+ * Confirm if this is truly unused since before the document format was stabilized, and remove if possible.
72
+ * @deprecated Superseded by {@link identifier}.
63
73
  */
64
74
  export const nodeKey = new FieldKindWithEditor(nodeKeyIdentifier, Multiplicity.Single, noChangeHandler, (types, other) => (other.kind === sequence.identifier ||
65
75
  other.kind === requiredIdentifier ||
@@ -70,7 +80,9 @@ const identifierFieldIdentifier = "Identifier";
70
80
  /**
71
81
  * Exactly one identifier.
72
82
  */
73
- export const identifier = new FieldKindWithEditor(identifierFieldIdentifier, Multiplicity.Single, noChangeHandler, (types, other) => (other.kind === sequence.identifier ||
83
+ export const identifier = new FieldKindWithEditor(identifierFieldIdentifier, Multiplicity.Single, noChangeHandler, (types, other) =>
84
+ // Allows upgrading from identifier to required: which way this upgrade is allowed to go is a subjective policy choice.
85
+ (other.kind === sequence.identifier ||
74
86
  other.kind === requiredIdentifier ||
75
87
  other.kind === optional.identifier ||
76
88
  other.kind === identifierFieldIdentifier) &&
@@ -1 +1 @@
1
- {"version":3,"file":"defaultFieldKinds.js","sourceRoot":"","sources":["../../../src/feature-libraries/default-schema/defaultFieldKinds.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAE3D,OAAO,EAIN,4BAA4B,EAC5B,YAAY,GACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAMN,mBAAmB,EAGnB,kCAAkC,EAClC,+BAA+B,GAC/B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEN,qBAAqB,EACrB,mBAAmB,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAExE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAA0B;IACrD,OAAO,EAAE,+BAA+B,CAAC;QACxC,OAAO,EAAE,CAAC,OAAU,EAAE,OAAU,EAAE,EAAE,CAAC,CAAC;QACtC,MAAM,EAAE,CAAC,OAAU,EAAE,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AQ,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAC5F,CAAC;AAcF;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAOnB,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { fail } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\ttype ChangeAtomId,\n\ttype DeltaDetachedNodeId,\n\ttype FieldKindIdentifier,\n\tforbiddenFieldKindIdentifier,\n\tMultiplicity,\n} from \"../../core/index.js\";\nimport {\n\ttype FieldChangeDelta,\n\ttype FieldChangeHandler,\n\ttype FieldEditor,\n\ttype FieldKindConfiguration,\n\ttype FieldKindConfigurationEntry,\n\tFieldKindWithEditor,\n\ttype FlexFieldKind,\n\ttype ToDelta,\n\tallowsTreeSchemaIdentifierSuperset,\n\treferenceFreeFieldChangeRebaser,\n} from \"../modular-schema/index.js\";\nimport {\n\ttype OptionalChangeset,\n\toptionalChangeHandler,\n\toptionalFieldEditor,\n} from \"../optional-field/index.js\";\nimport { sequenceFieldChangeHandler } from \"../sequence-field/index.js\";\n\nimport { noChangeCodecFamily } from \"./noChangeCodecs.js\";\n\n/**\n * ChangeHandler that only handles no-op / identity changes.\n */\nexport const noChangeHandler: FieldChangeHandler<0> = {\n\trebaser: referenceFreeFieldChangeRebaser({\n\t\tcompose: (change1: 0, change2: 0) => 0,\n\t\tinvert: (changes: 0) => 0,\n\t\trebase: (change: 0, over: 0) => 0,\n\t}),\n\tcodecsFactory: () => noChangeCodecFamily,\n\teditor: { buildChildChanges: () => fail(0xb0d /* Child changes not supported */) },\n\tintoDelta: (change, deltaFromChild: ToDelta): FieldChangeDelta => ({}),\n\trelevantRemovedRoots: (change): Iterable<DeltaDetachedNodeId> => [],\n\tisEmpty: (change: 0) => true,\n\tgetNestedChanges: (change: 0) => [],\n\tcreateEmpty: () => 0,\n\tgetCrossFieldKeys: () => [],\n};\n\nexport interface ValueFieldEditor extends FieldEditor<OptionalChangeset> {\n\t/**\n\t * Creates a change which replaces the current value of the field with `newValue`.\n\t * @param ids - The ids for the fill and detach fields.\n\t */\n\tset(ids: { fill: ChangeAtomId; detach: ChangeAtomId }): OptionalChangeset;\n}\n\nconst optionalIdentifier = \"Optional\";\n/**\n * 0 or 1 items.\n */\nexport const optional = new FieldKindWithEditor(\n\toptionalIdentifier,\n\tMultiplicity.Optional,\n\toptionalChangeHandler,\n\t(types, other) =>\n\t\t(other.kind === sequence.identifier || other.kind === optionalIdentifier) &&\n\t\tallowsTreeSchemaIdentifierSuperset(types, other.types),\n\tnew Set([]),\n);\n\nexport const valueFieldEditor: ValueFieldEditor = {\n\t...optionalFieldEditor,\n\tset: (ids: {\n\t\tfill: ChangeAtomId;\n\t\tdetach: ChangeAtomId;\n\t}): OptionalChangeset => optionalFieldEditor.set(false, ids),\n};\n\nexport const valueChangeHandler: FieldChangeHandler<OptionalChangeset, ValueFieldEditor> = {\n\t...optional.changeHandler,\n\teditor: valueFieldEditor,\n};\n\nconst requiredIdentifier = \"Value\";\n\n/**\n * Exactly one item.\n */\nexport const required = new FieldKindWithEditor(\n\trequiredIdentifier,\n\tMultiplicity.Single,\n\tvalueChangeHandler,\n\t(types, other) =>\n\t\t(other.kind === sequence.identifier ||\n\t\t\tother.kind === requiredIdentifier ||\n\t\t\tother.kind === optional.identifier ||\n\t\t\tother.kind === nodeKey.identifier) &&\n\t\tallowsTreeSchemaIdentifierSuperset(types, other.types),\n\tnew Set(),\n);\n\nconst sequenceIdentifier = \"Sequence\";\n\n/**\n * 0 or more items.\n */\nexport const sequence = new FieldKindWithEditor(\n\tsequenceIdentifier,\n\tMultiplicity.Sequence,\n\tsequenceFieldChangeHandler,\n\t(types, other) =>\n\t\tother.kind === sequenceIdentifier &&\n\t\tallowsTreeSchemaIdentifierSuperset(types, other.types),\n\t// TODO: add normalizer/importers for handling ops from other kinds.\n\tnew Set([]),\n);\n\nconst nodeKeyIdentifier = \"NodeKey\";\n\n/**\n * Exactly one identifier.\n */\nexport const nodeKey = new FieldKindWithEditor(\n\tnodeKeyIdentifier,\n\tMultiplicity.Single,\n\tnoChangeHandler,\n\t(types, other) =>\n\t\t(other.kind === sequence.identifier ||\n\t\t\tother.kind === requiredIdentifier ||\n\t\t\tother.kind === optional.identifier ||\n\t\t\tother.kind === nodeKeyIdentifier) &&\n\t\tallowsTreeSchemaIdentifierSuperset(types, other.types),\n\tnew Set(),\n);\n\nconst identifierFieldIdentifier = \"Identifier\";\n\n/**\n * Exactly one identifier.\n */\nexport const identifier = new FieldKindWithEditor(\n\tidentifierFieldIdentifier,\n\tMultiplicity.Single,\n\tnoChangeHandler,\n\t(types, other) =>\n\t\t(other.kind === sequence.identifier ||\n\t\t\tother.kind === requiredIdentifier ||\n\t\t\tother.kind === optional.identifier ||\n\t\t\tother.kind === identifierFieldIdentifier) &&\n\t\tallowsTreeSchemaIdentifierSuperset(types, other.types),\n\tnew Set(),\n);\n\n/**\n * Exactly 0 items.\n *\n * Using Forbidden makes what types are listed for allowed in a field irrelevant\n * since the field will never have values in it.\n *\n * Using Forbidden is equivalent to picking a kind that permits empty (like sequence or optional)\n * and having no allowed types (or only never types).\n * Because of this, its possible to express everything constraint wise without Forbidden,\n * but using Forbidden can be more semantically clear than optional with no allowed types.\n *\n * For view schema, this can be useful if you need to:\n * - run a specific out of schema handler when a field is present,\n * but otherwise are ignoring or tolerating (ex: via extra fields) unmentioned fields.\n * - prevent a specific field from being used as an extra field\n * (perhaps for some past of future compatibility reason)\n * - keep a field in a schema for metadata purposes\n * (ex: for improved error messaging, error handling or documentation)\n * that is not used in this specific version of the schema (ex: to document what it was or will be used for).\n *\n * For stored schema, this can be useful if you need to:\n * - have a field which can have its schema updated to Optional or Sequence of any type.\n * - to exclude a field from extra fields\n * - for the schema system to use as a default for fields which aren't declared\n * (ex: when updating a field that did not exist into one that does)\n *\n * See {@link emptyField} for a constant, reusable field using Forbidden.\n */\nexport const forbidden = new FieldKindWithEditor(\n\tforbiddenFieldKindIdentifier,\n\tMultiplicity.Forbidden,\n\tnoChangeHandler,\n\t// All multiplicities other than Value support empty.\n\t(types, other) => fieldKinds.get(other.kind)?.multiplicity !== Multiplicity.Single,\n\tnew Set(),\n);\n\nexport const fieldKindConfigurations: ReadonlyMap<number, FieldKindConfiguration> = new Map([\n\t[\n\t\t1,\n\t\tnew Map<FieldKindIdentifier, FieldKindConfigurationEntry>([\n\t\t\t[nodeKey.identifier, { kind: nodeKey, formatVersion: 1 }],\n\t\t\t[required.identifier, { kind: required, formatVersion: 1 }],\n\t\t\t[optional.identifier, { kind: optional, formatVersion: 1 }],\n\t\t\t[sequence.identifier, { kind: sequence, formatVersion: 1 }],\n\t\t\t[forbidden.identifier, { kind: forbidden, formatVersion: 1 }],\n\t\t\t[identifier.identifier, { kind: identifier, formatVersion: 1 }],\n\t\t]),\n\t],\n\t[\n\t\t2,\n\t\tnew Map<FieldKindIdentifier, FieldKindConfigurationEntry>([\n\t\t\t[nodeKey.identifier, { kind: nodeKey, formatVersion: 1 }],\n\t\t\t[required.identifier, { kind: required, formatVersion: 2 }],\n\t\t\t[optional.identifier, { kind: optional, formatVersion: 2 }],\n\t\t\t[sequence.identifier, { kind: sequence, formatVersion: 1 }],\n\t\t\t[forbidden.identifier, { kind: forbidden, formatVersion: 1 }],\n\t\t\t[identifier.identifier, { kind: identifier, formatVersion: 1 }],\n\t\t]),\n\t],\n\t[\n\t\t3,\n\t\tnew Map<FieldKindIdentifier, FieldKindConfigurationEntry>([\n\t\t\t[nodeKey.identifier, { kind: nodeKey, formatVersion: 1 }],\n\t\t\t[required.identifier, { kind: required, formatVersion: 2 }],\n\t\t\t[optional.identifier, { kind: optional, formatVersion: 2 }],\n\t\t\t[sequence.identifier, { kind: sequence, formatVersion: 2 }],\n\t\t\t[forbidden.identifier, { kind: forbidden, formatVersion: 1 }],\n\t\t\t[identifier.identifier, { kind: identifier, formatVersion: 1 }],\n\t\t]),\n\t],\n\t[\n\t\t4,\n\t\tnew Map<FieldKindIdentifier, FieldKindConfigurationEntry>([\n\t\t\t[nodeKey.identifier, { kind: nodeKey, formatVersion: 1 }],\n\t\t\t[required.identifier, { kind: required, formatVersion: 2 }],\n\t\t\t[optional.identifier, { kind: optional, formatVersion: 2 }],\n\t\t\t[sequence.identifier, { kind: sequence, formatVersion: 3 }],\n\t\t\t[forbidden.identifier, { kind: forbidden, formatVersion: 1 }],\n\t\t\t[identifier.identifier, { kind: identifier, formatVersion: 1 }],\n\t\t]),\n\t],\n]);\n\n/**\n * All supported field kinds.\n *\n * @privateRemarks\n * Before making a SharedTree format change which impacts which set of field kinds are allowed,\n * code which uses this should be audited for compatibility considerations.\n */\nexport const fieldKinds: ReadonlyMap<FieldKindIdentifier, FieldKindWithEditor> = new Map(\n\t[required, optional, sequence, nodeKey, identifier, forbidden].map((s) => [s.identifier, s]),\n);\n\n// Create named Aliases for nicer intellisense.\n\n// TODO: Find a way to make docs like {@inheritDoc required} work in vscode.\n// TODO: ensure thy work in generated docs.\n// TODO: add these comments to the rest of the cases below.\nexport interface Required extends FlexFieldKind<\"Value\", Multiplicity.Single> {}\nexport interface Optional extends FlexFieldKind<\"Optional\", Multiplicity.Optional> {}\nexport interface Sequence extends FlexFieldKind<\"Sequence\", Multiplicity.Sequence> {}\nexport interface Identifier extends FlexFieldKind<\"Identifier\", Multiplicity.Single> {}\nexport interface Forbidden\n\textends FlexFieldKind<typeof forbiddenFieldKindIdentifier, Multiplicity.Forbidden> {}\n\n/**\n * Default FieldKinds with their editor types erased.\n */\nexport const FieldKinds: {\n\t// TODO: inheritDoc for these somehow\n\treadonly required: Required;\n\treadonly optional: Optional;\n\treadonly sequence: Sequence;\n\treadonly identifier: Identifier;\n\treadonly forbidden: Forbidden;\n} = { required, optional, sequence, identifier, forbidden };\n"]}
1
+ {"version":3,"file":"defaultFieldKinds.js","sourceRoot":"","sources":["../../../src/feature-libraries/default-schema/defaultFieldKinds.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAE3D,OAAO,EAIN,4BAA4B,EAC5B,YAAY,GACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAMN,mBAAmB,EAGnB,kCAAkC,EAClC,+BAA+B,GAC/B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEN,qBAAqB,EACrB,mBAAmB,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAExE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAA0B;IACrD,OAAO,EAAE,+BAA+B,CAAC;QACxC,OAAO,EAAE,CAAC,OAAU,EAAE,OAAU,EAAE,EAAE,CAAC,CAAC;QACtC,MAAM,EAAE,CAAC,OAAU,EAAE,EAAE,CAAC,CAAC;QACzB,MAAM,EAAE,CAAC,MAAS,EAAE,IAAO,EAAE,EAAE,CAAC,CAAC;KACjC,CAAC;IACF,aAAa,EAAE,GAAG,EAAE,CAAC,mBAAmB;IACxC,MAAM,EAAE,EAAE,iBAAiB,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,iCAAiC,CAAC,EAAE;IAClF,SAAS,EAAE,CAAC,MAAM,EAAE,cAAuB,EAAoB,EAAE,CAAC,CAAC,EAAE,CAAC;IACtE,oBAAoB,EAAE,CAAC,MAAM,EAAiC,EAAE,CAAC,EAAE;IACnE,OAAO,EAAE,CAAC,MAAS,EAAE,EAAE,CAAC,IAAI;IAC5B,gBAAgB,EAAE,CAAC,MAAS,EAAE,EAAE,CAAC,EAAE;IACnC,WAAW,EAAE,GAAG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U,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC;SAC/D,CAAC;KACF;IACD;QACC,CAAC;QACD,IAAI,GAAG,CAAmD;YACzD,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC;YACzD,CAAC,QAAQ,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC;YAC3D,CAAC,QAAQ,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC;YAC3D,CAAC,QAAQ,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC;YAC3D,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC;YAC7D,CAAC,UAAU,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC;SAC/D,CAAC;KACF;CACD,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAA0D,IAAI,GAAG,CACvF,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAC5F,CAAC;AAcF;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAOnB,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { fail } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\ttype ChangeAtomId,\n\ttype DeltaDetachedNodeId,\n\ttype FieldKindIdentifier,\n\tforbiddenFieldKindIdentifier,\n\tMultiplicity,\n} from \"../../core/index.js\";\nimport {\n\ttype FieldChangeDelta,\n\ttype FieldChangeHandler,\n\ttype FieldEditor,\n\ttype FieldKindConfiguration,\n\ttype FieldKindConfigurationEntry,\n\tFieldKindWithEditor,\n\ttype FlexFieldKind,\n\ttype ToDelta,\n\tallowsTreeSchemaIdentifierSuperset,\n\treferenceFreeFieldChangeRebaser,\n} from \"../modular-schema/index.js\";\nimport {\n\ttype OptionalChangeset,\n\toptionalChangeHandler,\n\toptionalFieldEditor,\n} from \"../optional-field/index.js\";\nimport { sequenceFieldChangeHandler } from \"../sequence-field/index.js\";\n\nimport { noChangeCodecFamily } from \"./noChangeCodecs.js\";\n\n/**\n * ChangeHandler that only handles no-op / identity changes.\n */\nexport const noChangeHandler: FieldChangeHandler<0> = {\n\trebaser: referenceFreeFieldChangeRebaser({\n\t\tcompose: (change1: 0, change2: 0) => 0,\n\t\tinvert: (changes: 0) => 0,\n\t\trebase: (change: 0, over: 0) => 0,\n\t}),\n\tcodecsFactory: () => noChangeCodecFamily,\n\teditor: { buildChildChanges: () => fail(0xb0d /* Child changes not supported */) },\n\tintoDelta: (change, deltaFromChild: ToDelta): FieldChangeDelta => ({}),\n\trelevantRemovedRoots: (change): Iterable<DeltaDetachedNodeId> => [],\n\tisEmpty: (change: 0) => true,\n\tgetNestedChanges: (change: 0) => [],\n\tcreateEmpty: () => 0,\n\tgetCrossFieldKeys: () => [],\n};\n\nexport interface ValueFieldEditor extends FieldEditor<OptionalChangeset> {\n\t/**\n\t * Creates a change which replaces the current value of the field with `newValue`.\n\t * @param ids - The ids for the fill and detach fields.\n\t */\n\tset(ids: { fill: ChangeAtomId; detach: ChangeAtomId }): OptionalChangeset;\n}\n\nconst optionalIdentifier = \"Optional\";\n/**\n * 0 or 1 items.\n */\nexport const optional = new FieldKindWithEditor(\n\toptionalIdentifier,\n\tMultiplicity.Optional,\n\toptionalChangeHandler,\n\t(types, other) =>\n\t\t(other.kind === sequence.identifier || other.kind === optionalIdentifier) &&\n\t\tallowsTreeSchemaIdentifierSuperset(types, other.types),\n\tnew Set([]),\n);\n\nexport const valueFieldEditor: ValueFieldEditor = {\n\t...optionalFieldEditor,\n\tset: (ids: {\n\t\tfill: ChangeAtomId;\n\t\tdetach: ChangeAtomId;\n\t}): OptionalChangeset => optionalFieldEditor.set(false, ids),\n};\n\nexport const valueChangeHandler: FieldChangeHandler<OptionalChangeset, ValueFieldEditor> = {\n\t...optional.changeHandler,\n\teditor: valueFieldEditor,\n};\n\nconst requiredIdentifier = \"Value\";\n\n/**\n * Exactly one item.\n */\nexport const required = new FieldKindWithEditor(\n\trequiredIdentifier,\n\tMultiplicity.Single,\n\tvalueChangeHandler,\n\t(types, other) =>\n\t\t// By omitting Identifier here,\n\t\t// this is making a policy choice that a schema upgrade cannot be done from required to identifier.\n\t\t// Since an identifier can be upgraded into a required field,\n\t\t// preventing the inverse helps ensure that schema upgrades are monotonic.\n\t\t// Which direction is allowed is a subjective policy choice.\n\t\t(other.kind === sequence.identifier ||\n\t\t\tother.kind === requiredIdentifier ||\n\t\t\tother.kind === optional.identifier ||\n\t\t\tother.kind === nodeKey.identifier) &&\n\t\tallowsTreeSchemaIdentifierSuperset(types, other.types),\n\tnew Set(),\n);\n\nconst sequenceIdentifier = \"Sequence\";\n\n/**\n * 0 or more items.\n */\nexport const sequence = new FieldKindWithEditor(\n\tsequenceIdentifier,\n\tMultiplicity.Sequence,\n\tsequenceFieldChangeHandler,\n\t(types, other) =>\n\t\tother.kind === sequenceIdentifier &&\n\t\tallowsTreeSchemaIdentifierSuperset(types, other.types),\n\t// TODO: add normalizer/importers for handling ops from other kinds.\n\tnew Set([]),\n);\n\nconst nodeKeyIdentifier = \"NodeKey\";\n\n/**\n * Exactly one identifier.\n *\n * TODO: this is almost the same as identifier, but apparently unused.\n * Confirm if this is truly unused since before the document format was stabilized, and remove if possible.\n * @deprecated Superseded by {@link identifier}.\n */\nexport const nodeKey = new FieldKindWithEditor(\n\tnodeKeyIdentifier,\n\tMultiplicity.Single,\n\tnoChangeHandler,\n\t(types, other) =>\n\t\t(other.kind === sequence.identifier ||\n\t\t\tother.kind === requiredIdentifier ||\n\t\t\tother.kind === optional.identifier ||\n\t\t\tother.kind === nodeKeyIdentifier) &&\n\t\tallowsTreeSchemaIdentifierSuperset(types, other.types),\n\tnew Set(),\n);\n\nconst identifierFieldIdentifier = \"Identifier\";\n\n/**\n * Exactly one identifier.\n */\nexport const identifier = new FieldKindWithEditor(\n\tidentifierFieldIdentifier,\n\tMultiplicity.Single,\n\tnoChangeHandler,\n\t(types, other) =>\n\t\t// Allows upgrading from identifier to required: which way this upgrade is allowed to go is a subjective policy choice.\n\t\t(other.kind === sequence.identifier ||\n\t\t\tother.kind === requiredIdentifier ||\n\t\t\tother.kind === optional.identifier ||\n\t\t\tother.kind === identifierFieldIdentifier) &&\n\t\tallowsTreeSchemaIdentifierSuperset(types, other.types),\n\tnew Set(),\n);\n\n/**\n * Exactly 0 items.\n *\n * Using Forbidden makes what types are listed for allowed in a field irrelevant\n * since the field will never have values in it.\n *\n * Using Forbidden is equivalent to picking a kind that permits empty (like sequence or optional)\n * and having no allowed types (or only never types).\n * Because of this, its possible to express everything constraint wise without Forbidden,\n * but using Forbidden can be more semantically clear than optional with no allowed types.\n *\n * For view schema, this can be useful if you need to:\n * - run a specific out of schema handler when a field is present,\n * but otherwise are ignoring or tolerating (ex: via extra fields) unmentioned fields.\n * - prevent a specific field from being used as an extra field\n * (perhaps for some past of future compatibility reason)\n * - keep a field in a schema for metadata purposes\n * (ex: for improved error messaging, error handling or documentation)\n * that is not used in this specific version of the schema (ex: to document what it was or will be used for).\n *\n * For stored schema, this can be useful if you need to:\n * - have a field which can have its schema updated to Optional or Sequence of any type.\n * - to exclude a field from extra fields\n * - for the schema system to use as a default for fields which aren't declared\n * (ex: when updating a field that did not exist into one that does)\n *\n * See {@link emptyField} for a constant, reusable field using Forbidden.\n */\nexport const forbidden = new FieldKindWithEditor(\n\tforbiddenFieldKindIdentifier,\n\tMultiplicity.Forbidden,\n\tnoChangeHandler,\n\t// All multiplicities other than Value support empty.\n\t(types, other) => fieldKinds.get(other.kind)?.multiplicity !== Multiplicity.Single,\n\tnew Set(),\n);\n\nexport const fieldKindConfigurations: ReadonlyMap<number, FieldKindConfiguration> = new Map([\n\t[\n\t\t1,\n\t\tnew Map<FieldKindIdentifier, FieldKindConfigurationEntry>([\n\t\t\t[nodeKey.identifier, { kind: nodeKey, formatVersion: 1 }],\n\t\t\t[required.identifier, { kind: required, formatVersion: 1 }],\n\t\t\t[optional.identifier, { kind: optional, formatVersion: 1 }],\n\t\t\t[sequence.identifier, { kind: sequence, formatVersion: 1 }],\n\t\t\t[forbidden.identifier, { kind: forbidden, formatVersion: 1 }],\n\t\t\t[identifier.identifier, { kind: identifier, formatVersion: 1 }],\n\t\t]),\n\t],\n\t[\n\t\t2,\n\t\tnew Map<FieldKindIdentifier, FieldKindConfigurationEntry>([\n\t\t\t[nodeKey.identifier, { kind: nodeKey, formatVersion: 1 }],\n\t\t\t[required.identifier, { kind: required, formatVersion: 2 }],\n\t\t\t[optional.identifier, { kind: optional, formatVersion: 2 }],\n\t\t\t[sequence.identifier, { kind: sequence, formatVersion: 1 }],\n\t\t\t[forbidden.identifier, { kind: forbidden, formatVersion: 1 }],\n\t\t\t[identifier.identifier, { kind: identifier, formatVersion: 1 }],\n\t\t]),\n\t],\n\t[\n\t\t3,\n\t\tnew Map<FieldKindIdentifier, FieldKindConfigurationEntry>([\n\t\t\t[nodeKey.identifier, { kind: nodeKey, formatVersion: 1 }],\n\t\t\t[required.identifier, { kind: required, formatVersion: 2 }],\n\t\t\t[optional.identifier, { kind: optional, formatVersion: 2 }],\n\t\t\t[sequence.identifier, { kind: sequence, formatVersion: 2 }],\n\t\t\t[forbidden.identifier, { kind: forbidden, formatVersion: 1 }],\n\t\t\t[identifier.identifier, { kind: identifier, formatVersion: 1 }],\n\t\t]),\n\t],\n\t[\n\t\t4,\n\t\tnew Map<FieldKindIdentifier, FieldKindConfigurationEntry>([\n\t\t\t[nodeKey.identifier, { kind: nodeKey, formatVersion: 1 }],\n\t\t\t[required.identifier, { kind: required, formatVersion: 2 }],\n\t\t\t[optional.identifier, { kind: optional, formatVersion: 2 }],\n\t\t\t[sequence.identifier, { kind: sequence, formatVersion: 3 }],\n\t\t\t[forbidden.identifier, { kind: forbidden, formatVersion: 1 }],\n\t\t\t[identifier.identifier, { kind: identifier, formatVersion: 1 }],\n\t\t]),\n\t],\n]);\n\n/**\n * All supported field kinds.\n *\n * @privateRemarks\n * Before making a SharedTree format change which impacts which set of field kinds are allowed,\n * code which uses this should be audited for compatibility considerations.\n */\nexport const fieldKinds: ReadonlyMap<FieldKindIdentifier, FieldKindWithEditor> = new Map(\n\t[required, optional, sequence, nodeKey, identifier, forbidden].map((s) => [s.identifier, s]),\n);\n\n// Create named Aliases for nicer intellisense.\n\n// TODO: Find a way to make docs like {@inheritDoc required} work in vscode.\n// TODO: ensure thy work in generated docs.\n// TODO: add these comments to the rest of the cases below.\nexport interface Required extends FlexFieldKind<\"Value\", Multiplicity.Single> {}\nexport interface Optional extends FlexFieldKind<\"Optional\", Multiplicity.Optional> {}\nexport interface Sequence extends FlexFieldKind<\"Sequence\", Multiplicity.Sequence> {}\nexport interface Identifier extends FlexFieldKind<\"Identifier\", Multiplicity.Single> {}\nexport interface Forbidden\n\textends FlexFieldKind<typeof forbiddenFieldKindIdentifier, Multiplicity.Forbidden> {}\n\n/**\n * Default FieldKinds with their editor types erased.\n */\nexport const FieldKinds: {\n\t// TODO: inheritDoc for these somehow\n\treadonly required: Required;\n\treadonly optional: Optional;\n\treadonly sequence: Sequence;\n\treadonly identifier: Identifier;\n\treadonly forbidden: Forbidden;\n} = { required, optional, sequence, identifier, forbidden };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"defaultSchema.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/default-schema/defaultSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAInE;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,gBAIjC,CAAC"}
1
+ {"version":3,"file":"defaultSchema.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/default-schema/defaultSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAInE;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,gBAEjC,CAAC"}
@@ -8,7 +8,5 @@ import { fieldKinds } from "./defaultFieldKinds.js";
8
8
  */
9
9
  export const defaultSchemaPolicy = {
10
10
  fieldKinds,
11
- validateSchema: false,
12
- allowUnknownOptionalFields: () => false,
13
11
  };
14
12
  //# sourceMappingURL=defaultSchema.js.map