@fluidframework/tree 2.42.0 → 2.43.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 (542) hide show
  1. package/CHANGELOG.md +189 -0
  2. package/api-report/tree.alpha.api.md +72 -25
  3. package/api-report/tree.beta.api.md +34 -0
  4. package/api-report/tree.legacy.alpha.api.md +1 -0
  5. package/api-report/tree.legacy.public.api.md +1 -0
  6. package/api-report/tree.public.api.md +1 -0
  7. package/dist/alpha.d.ts +12 -6
  8. package/dist/beta.d.ts +6 -1
  9. package/dist/core/index.d.ts +1 -1
  10. package/dist/core/index.d.ts.map +1 -1
  11. package/dist/core/index.js +5 -2
  12. package/dist/core/index.js.map +1 -1
  13. package/dist/core/schema-stored/formatV2.d.ts +80 -0
  14. package/dist/core/schema-stored/formatV2.d.ts.map +1 -0
  15. package/dist/core/schema-stored/formatV2.js +55 -0
  16. package/dist/core/schema-stored/formatV2.js.map +1 -0
  17. package/dist/core/schema-stored/index.d.ts +3 -1
  18. package/dist/core/schema-stored/index.d.ts.map +1 -1
  19. package/dist/core/schema-stored/index.js +5 -2
  20. package/dist/core/schema-stored/index.js.map +1 -1
  21. package/dist/core/schema-stored/schema.d.ts +49 -17
  22. package/dist/core/schema-stored/schema.d.ts.map +1 -1
  23. package/dist/core/schema-stored/schema.js +65 -22
  24. package/dist/core/schema-stored/schema.js.map +1 -1
  25. package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.d.ts +9 -7
  26. package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.d.ts.map +1 -1
  27. package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js +13 -9
  28. package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js.map +1 -1
  29. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +3 -3
  30. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
  31. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js +6 -6
  32. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  33. package/dist/feature-libraries/chunked-forest/codec/nodeShape.d.ts +1 -1
  34. package/dist/feature-libraries/chunked-forest/codec/nodeShape.d.ts.map +1 -1
  35. package/dist/feature-libraries/chunked-forest/codec/nodeShape.js +3 -3
  36. package/dist/feature-libraries/chunked-forest/codec/nodeShape.js.map +1 -1
  37. package/dist/feature-libraries/detachedFieldIndexSummarizer.d.ts +8 -3
  38. package/dist/feature-libraries/detachedFieldIndexSummarizer.d.ts.map +1 -1
  39. package/dist/feature-libraries/detachedFieldIndexSummarizer.js +2 -5
  40. package/dist/feature-libraries/detachedFieldIndexSummarizer.js.map +1 -1
  41. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts +24 -25
  42. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  43. package/dist/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  44. package/dist/feature-libraries/flex-tree/index.d.ts +0 -1
  45. package/dist/feature-libraries/flex-tree/index.d.ts.map +1 -1
  46. package/dist/feature-libraries/flex-tree/index.js +1 -7
  47. package/dist/feature-libraries/flex-tree/index.js.map +1 -1
  48. package/dist/feature-libraries/flex-tree/lazyEntity.d.ts +2 -2
  49. package/dist/feature-libraries/flex-tree/lazyEntity.d.ts.map +1 -1
  50. package/dist/feature-libraries/flex-tree/lazyEntity.js +3 -0
  51. package/dist/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
  52. package/dist/feature-libraries/flex-tree/lazyField.d.ts +1 -2
  53. package/dist/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  54. package/dist/feature-libraries/flex-tree/lazyField.js +2 -5
  55. package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
  56. package/dist/feature-libraries/flex-tree/lazyNode.d.ts +5 -5
  57. package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  58. package/dist/feature-libraries/flex-tree/lazyNode.js +15 -7
  59. package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  60. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts +8 -3
  61. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  62. package/dist/feature-libraries/forest-summary/forestSummarizer.js +2 -5
  63. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  64. package/dist/feature-libraries/index.d.ts +2 -2
  65. package/dist/feature-libraries/index.d.ts.map +1 -1
  66. package/dist/feature-libraries/index.js +1 -2
  67. package/dist/feature-libraries/index.js.map +1 -1
  68. package/dist/feature-libraries/mapTreeCursor.d.ts +16 -2
  69. package/dist/feature-libraries/mapTreeCursor.d.ts.map +1 -1
  70. package/dist/feature-libraries/mapTreeCursor.js.map +1 -1
  71. package/dist/feature-libraries/modular-schema/fieldKindWithEditor.d.ts.map +1 -1
  72. package/dist/feature-libraries/modular-schema/fieldKindWithEditor.js +2 -0
  73. package/dist/feature-libraries/modular-schema/fieldKindWithEditor.js.map +1 -1
  74. package/dist/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
  75. package/dist/feature-libraries/object-forest/objectForest.js +2 -0
  76. package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
  77. package/dist/feature-libraries/schema-edits/schemaChangeCodecs.d.ts.map +1 -1
  78. package/dist/feature-libraries/schema-edits/schemaChangeCodecs.js +8 -4
  79. package/dist/feature-libraries/schema-edits/schemaChangeCodecs.js.map +1 -1
  80. package/dist/feature-libraries/schema-edits/schemaChangeFormat.d.ts +2 -36
  81. package/dist/feature-libraries/schema-edits/schemaChangeFormat.d.ts.map +1 -1
  82. package/dist/feature-libraries/schema-edits/schemaChangeFormat.js +3 -3
  83. package/dist/feature-libraries/schema-edits/schemaChangeFormat.js.map +1 -1
  84. package/dist/feature-libraries/schema-index/codec.d.ts.map +1 -1
  85. package/dist/feature-libraries/schema-index/codec.js +59 -9
  86. package/dist/feature-libraries/schema-index/codec.js.map +1 -1
  87. package/dist/feature-libraries/schema-index/formatV1.d.ts +1 -1
  88. package/dist/feature-libraries/schema-index/formatV2.d.ts +42 -0
  89. package/dist/feature-libraries/schema-index/formatV2.d.ts.map +1 -0
  90. package/dist/feature-libraries/schema-index/formatV2.js +26 -0
  91. package/dist/feature-libraries/schema-index/formatV2.js.map +1 -0
  92. package/dist/feature-libraries/schema-index/index.d.ts +2 -1
  93. package/dist/feature-libraries/schema-index/index.d.ts.map +1 -1
  94. package/dist/feature-libraries/schema-index/index.js +4 -2
  95. package/dist/feature-libraries/schema-index/index.js.map +1 -1
  96. package/dist/feature-libraries/schema-index/schemaSummarizer.d.ts +7 -2
  97. package/dist/feature-libraries/schema-index/schemaSummarizer.d.ts.map +1 -1
  98. package/dist/feature-libraries/schema-index/schemaSummarizer.js +6 -6
  99. package/dist/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  100. package/dist/index.d.ts +2 -2
  101. package/dist/index.d.ts.map +1 -1
  102. package/dist/index.js.map +1 -1
  103. package/dist/packageVersion.d.ts +1 -1
  104. package/dist/packageVersion.js +1 -1
  105. package/dist/packageVersion.js.map +1 -1
  106. package/dist/shared-tree/schematizeTree.d.ts.map +1 -1
  107. package/dist/shared-tree/schematizeTree.js +1 -0
  108. package/dist/shared-tree/schematizeTree.js.map +1 -1
  109. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  110. package/dist/shared-tree/schematizingTreeView.js +3 -3
  111. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  112. package/dist/shared-tree/sharedTree.d.ts +5 -1
  113. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  114. package/dist/shared-tree/sharedTree.js +34 -5
  115. package/dist/shared-tree/sharedTree.js.map +1 -1
  116. package/dist/shared-tree/treeAlpha.d.ts +39 -1
  117. package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
  118. package/dist/shared-tree/treeAlpha.js +117 -11
  119. package/dist/shared-tree/treeAlpha.js.map +1 -1
  120. package/dist/shared-tree-core/editManagerSummarizer.d.ts +8 -3
  121. package/dist/shared-tree-core/editManagerSummarizer.d.ts.map +1 -1
  122. package/dist/shared-tree-core/editManagerSummarizer.js +2 -5
  123. package/dist/shared-tree-core/editManagerSummarizer.js.map +1 -1
  124. package/dist/shared-tree-core/sharedTreeCore.d.ts +18 -7
  125. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  126. package/dist/shared-tree-core/sharedTreeCore.js +15 -2
  127. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  128. package/dist/simple-tree/api/configuration.d.ts +15 -3
  129. package/dist/simple-tree/api/configuration.d.ts.map +1 -1
  130. package/dist/simple-tree/api/configuration.js +40 -22
  131. package/dist/simple-tree/api/configuration.js.map +1 -1
  132. package/dist/simple-tree/api/index.d.ts +1 -1
  133. package/dist/simple-tree/api/index.d.ts.map +1 -1
  134. package/dist/simple-tree/api/index.js +4 -4
  135. package/dist/simple-tree/api/index.js.map +1 -1
  136. package/dist/simple-tree/api/schemaCompatibilityTester.js +1 -1
  137. package/dist/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
  138. package/dist/simple-tree/api/schemaCreationUtilities.d.ts +3 -3
  139. package/dist/simple-tree/api/schemaCreationUtilities.js +3 -3
  140. package/dist/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  141. package/dist/simple-tree/api/schemaFactory.d.ts +15 -11
  142. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  143. package/dist/simple-tree/api/schemaFactory.js +4 -0
  144. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  145. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +41 -11
  146. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
  147. package/dist/simple-tree/api/schemaFactoryAlpha.js +31 -4
  148. package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
  149. package/dist/simple-tree/api/storedSchema.js +2 -2
  150. package/dist/simple-tree/api/storedSchema.js.map +1 -1
  151. package/dist/simple-tree/api/treeChangeEvents.d.ts +8 -3
  152. package/dist/simple-tree/api/treeChangeEvents.d.ts.map +1 -1
  153. package/dist/simple-tree/api/treeChangeEvents.js.map +1 -1
  154. package/dist/simple-tree/api/treeNodeApi.d.ts +3 -0
  155. package/dist/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  156. package/dist/simple-tree/api/treeNodeApi.js +1 -1
  157. package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
  158. package/dist/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
  159. package/dist/simple-tree/api/viewSchemaToSimpleSchema.js +5 -0
  160. package/dist/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
  161. package/dist/simple-tree/core/context.d.ts +3 -3
  162. package/dist/simple-tree/core/context.d.ts.map +1 -1
  163. package/dist/simple-tree/core/context.js.map +1 -1
  164. package/dist/simple-tree/core/getOrCreateNode.d.ts +9 -0
  165. package/dist/simple-tree/core/getOrCreateNode.d.ts.map +1 -1
  166. package/dist/simple-tree/core/getOrCreateNode.js +12 -1
  167. package/dist/simple-tree/core/getOrCreateNode.js.map +1 -1
  168. package/dist/simple-tree/core/index.d.ts +2 -2
  169. package/dist/simple-tree/core/index.d.ts.map +1 -1
  170. package/dist/simple-tree/core/index.js +3 -1
  171. package/dist/simple-tree/core/index.js.map +1 -1
  172. package/dist/simple-tree/core/treeNodeKernel.js +2 -2
  173. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  174. package/dist/simple-tree/core/treeNodeSchema.d.ts +68 -1
  175. package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  176. package/dist/simple-tree/core/treeNodeSchema.js +24 -1
  177. package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
  178. package/dist/simple-tree/core/unhydratedFlexTree.d.ts +5 -9
  179. package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  180. package/dist/simple-tree/core/unhydratedFlexTree.js +12 -31
  181. package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  182. package/dist/simple-tree/core/walkSchema.d.ts +3 -3
  183. package/dist/simple-tree/core/walkSchema.d.ts.map +1 -1
  184. package/dist/simple-tree/core/walkSchema.js +9 -5
  185. package/dist/simple-tree/core/walkSchema.js.map +1 -1
  186. package/dist/simple-tree/createContext.js +1 -1
  187. package/dist/simple-tree/createContext.js.map +1 -1
  188. package/dist/simple-tree/getTreeNodeForField.d.ts +1 -1
  189. package/dist/simple-tree/getTreeNodeForField.d.ts.map +1 -1
  190. package/dist/simple-tree/getTreeNodeForField.js +3 -3
  191. package/dist/simple-tree/getTreeNodeForField.js.map +1 -1
  192. package/dist/simple-tree/index.d.ts +6 -6
  193. package/dist/simple-tree/index.d.ts.map +1 -1
  194. package/dist/simple-tree/index.js +8 -5
  195. package/dist/simple-tree/index.js.map +1 -1
  196. package/dist/simple-tree/leafNodeSchema.d.ts +4 -1
  197. package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
  198. package/dist/simple-tree/leafNodeSchema.js +1 -0
  199. package/dist/simple-tree/leafNodeSchema.js.map +1 -1
  200. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts +3 -1
  201. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  202. package/dist/simple-tree/node-kinds/array/arrayNode.js +21 -16
  203. package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  204. package/dist/simple-tree/node-kinds/map/mapNode.d.ts +3 -2
  205. package/dist/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
  206. package/dist/simple-tree/node-kinds/map/mapNode.js +11 -5
  207. package/dist/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  208. package/dist/simple-tree/node-kinds/object/objectNode.d.ts +3 -2
  209. package/dist/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  210. package/dist/simple-tree/node-kinds/object/objectNode.js +12 -7
  211. package/dist/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  212. package/dist/simple-tree/prepareForInsertion.d.ts.map +1 -1
  213. package/dist/simple-tree/prepareForInsertion.js +5 -1
  214. package/dist/simple-tree/prepareForInsertion.js.map +1 -1
  215. package/dist/simple-tree/schemaTypes.d.ts +63 -30
  216. package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
  217. package/dist/simple-tree/schemaTypes.js +73 -40
  218. package/dist/simple-tree/schemaTypes.js.map +1 -1
  219. package/dist/simple-tree/simpleSchema.d.ts +22 -4
  220. package/dist/simple-tree/simpleSchema.d.ts.map +1 -1
  221. package/dist/simple-tree/simpleSchema.js.map +1 -1
  222. package/dist/simple-tree/toStoredSchema.d.ts +4 -0
  223. package/dist/simple-tree/toStoredSchema.d.ts.map +1 -1
  224. package/dist/simple-tree/toStoredSchema.js +15 -4
  225. package/dist/simple-tree/toStoredSchema.js.map +1 -1
  226. package/dist/simple-tree/treeNodeValid.d.ts.map +1 -1
  227. package/dist/simple-tree/treeNodeValid.js +1 -2
  228. package/dist/simple-tree/treeNodeValid.js.map +1 -1
  229. package/dist/simple-tree/walkFieldSchema.d.ts.map +1 -1
  230. package/dist/simple-tree/walkFieldSchema.js +1 -1
  231. package/dist/simple-tree/walkFieldSchema.js.map +1 -1
  232. package/dist/tableSchema.d.ts +1 -1
  233. package/dist/util/typeUtils.d.ts +2 -2
  234. package/dist/util/typeUtils.js.map +1 -1
  235. package/dist/util/utils.d.ts +2 -0
  236. package/dist/util/utils.d.ts.map +1 -1
  237. package/dist/util/utils.js.map +1 -1
  238. package/lib/alpha.d.ts +12 -6
  239. package/lib/beta.d.ts +6 -1
  240. package/lib/core/index.d.ts +1 -1
  241. package/lib/core/index.d.ts.map +1 -1
  242. package/lib/core/index.js +1 -1
  243. package/lib/core/index.js.map +1 -1
  244. package/lib/core/schema-stored/formatV2.d.ts +80 -0
  245. package/lib/core/schema-stored/formatV2.d.ts.map +1 -0
  246. package/lib/core/schema-stored/formatV2.js +52 -0
  247. package/lib/core/schema-stored/formatV2.js.map +1 -0
  248. package/lib/core/schema-stored/index.d.ts +3 -1
  249. package/lib/core/schema-stored/index.d.ts.map +1 -1
  250. package/lib/core/schema-stored/index.js +3 -1
  251. package/lib/core/schema-stored/index.js.map +1 -1
  252. package/lib/core/schema-stored/schema.d.ts +49 -17
  253. package/lib/core/schema-stored/schema.d.ts.map +1 -1
  254. package/lib/core/schema-stored/schema.js +63 -21
  255. package/lib/core/schema-stored/schema.js.map +1 -1
  256. package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.d.ts +9 -7
  257. package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.d.ts.map +1 -1
  258. package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js +11 -7
  259. package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js.map +1 -1
  260. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +3 -3
  261. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
  262. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js +7 -7
  263. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  264. package/lib/feature-libraries/chunked-forest/codec/nodeShape.d.ts +1 -1
  265. package/lib/feature-libraries/chunked-forest/codec/nodeShape.d.ts.map +1 -1
  266. package/lib/feature-libraries/chunked-forest/codec/nodeShape.js +3 -3
  267. package/lib/feature-libraries/chunked-forest/codec/nodeShape.js.map +1 -1
  268. package/lib/feature-libraries/detachedFieldIndexSummarizer.d.ts +8 -3
  269. package/lib/feature-libraries/detachedFieldIndexSummarizer.d.ts.map +1 -1
  270. package/lib/feature-libraries/detachedFieldIndexSummarizer.js +2 -5
  271. package/lib/feature-libraries/detachedFieldIndexSummarizer.js.map +1 -1
  272. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts +24 -25
  273. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  274. package/lib/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  275. package/lib/feature-libraries/flex-tree/index.d.ts +0 -1
  276. package/lib/feature-libraries/flex-tree/index.d.ts.map +1 -1
  277. package/lib/feature-libraries/flex-tree/index.js +0 -1
  278. package/lib/feature-libraries/flex-tree/index.js.map +1 -1
  279. package/lib/feature-libraries/flex-tree/lazyEntity.d.ts +2 -2
  280. package/lib/feature-libraries/flex-tree/lazyEntity.d.ts.map +1 -1
  281. package/lib/feature-libraries/flex-tree/lazyEntity.js +3 -0
  282. package/lib/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
  283. package/lib/feature-libraries/flex-tree/lazyField.d.ts +1 -2
  284. package/lib/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  285. package/lib/feature-libraries/flex-tree/lazyField.js +3 -6
  286. package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
  287. package/lib/feature-libraries/flex-tree/lazyNode.d.ts +5 -5
  288. package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  289. package/lib/feature-libraries/flex-tree/lazyNode.js +15 -7
  290. package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  291. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts +8 -3
  292. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  293. package/lib/feature-libraries/forest-summary/forestSummarizer.js +2 -5
  294. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  295. package/lib/feature-libraries/index.d.ts +2 -2
  296. package/lib/feature-libraries/index.d.ts.map +1 -1
  297. package/lib/feature-libraries/index.js +1 -1
  298. package/lib/feature-libraries/index.js.map +1 -1
  299. package/lib/feature-libraries/mapTreeCursor.d.ts +16 -2
  300. package/lib/feature-libraries/mapTreeCursor.d.ts.map +1 -1
  301. package/lib/feature-libraries/mapTreeCursor.js.map +1 -1
  302. package/lib/feature-libraries/modular-schema/fieldKindWithEditor.d.ts.map +1 -1
  303. package/lib/feature-libraries/modular-schema/fieldKindWithEditor.js +2 -0
  304. package/lib/feature-libraries/modular-schema/fieldKindWithEditor.js.map +1 -1
  305. package/lib/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
  306. package/lib/feature-libraries/object-forest/objectForest.js +2 -0
  307. package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
  308. package/lib/feature-libraries/schema-edits/schemaChangeCodecs.d.ts.map +1 -1
  309. package/lib/feature-libraries/schema-edits/schemaChangeCodecs.js +8 -4
  310. package/lib/feature-libraries/schema-edits/schemaChangeCodecs.js.map +1 -1
  311. package/lib/feature-libraries/schema-edits/schemaChangeFormat.d.ts +2 -36
  312. package/lib/feature-libraries/schema-edits/schemaChangeFormat.d.ts.map +1 -1
  313. package/lib/feature-libraries/schema-edits/schemaChangeFormat.js +3 -3
  314. package/lib/feature-libraries/schema-edits/schemaChangeFormat.js.map +1 -1
  315. package/lib/feature-libraries/schema-index/codec.d.ts.map +1 -1
  316. package/lib/feature-libraries/schema-index/codec.js +60 -10
  317. package/lib/feature-libraries/schema-index/codec.js.map +1 -1
  318. package/lib/feature-libraries/schema-index/formatV1.d.ts +1 -1
  319. package/lib/feature-libraries/schema-index/formatV2.d.ts +42 -0
  320. package/lib/feature-libraries/schema-index/formatV2.d.ts.map +1 -0
  321. package/lib/feature-libraries/schema-index/formatV2.js +23 -0
  322. package/lib/feature-libraries/schema-index/formatV2.js.map +1 -0
  323. package/lib/feature-libraries/schema-index/index.d.ts +2 -1
  324. package/lib/feature-libraries/schema-index/index.d.ts.map +1 -1
  325. package/lib/feature-libraries/schema-index/index.js +2 -1
  326. package/lib/feature-libraries/schema-index/index.js.map +1 -1
  327. package/lib/feature-libraries/schema-index/schemaSummarizer.d.ts +7 -2
  328. package/lib/feature-libraries/schema-index/schemaSummarizer.d.ts.map +1 -1
  329. package/lib/feature-libraries/schema-index/schemaSummarizer.js +6 -6
  330. package/lib/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  331. package/lib/index.d.ts +2 -2
  332. package/lib/index.d.ts.map +1 -1
  333. package/lib/index.js.map +1 -1
  334. package/lib/packageVersion.d.ts +1 -1
  335. package/lib/packageVersion.js +1 -1
  336. package/lib/packageVersion.js.map +1 -1
  337. package/lib/shared-tree/schematizeTree.d.ts.map +1 -1
  338. package/lib/shared-tree/schematizeTree.js +1 -0
  339. package/lib/shared-tree/schematizeTree.js.map +1 -1
  340. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  341. package/lib/shared-tree/schematizingTreeView.js +4 -4
  342. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  343. package/lib/shared-tree/sharedTree.d.ts +5 -1
  344. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  345. package/lib/shared-tree/sharedTree.js +34 -5
  346. package/lib/shared-tree/sharedTree.js.map +1 -1
  347. package/lib/shared-tree/treeAlpha.d.ts +39 -1
  348. package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
  349. package/lib/shared-tree/treeAlpha.js +111 -5
  350. package/lib/shared-tree/treeAlpha.js.map +1 -1
  351. package/lib/shared-tree-core/editManagerSummarizer.d.ts +8 -3
  352. package/lib/shared-tree-core/editManagerSummarizer.d.ts.map +1 -1
  353. package/lib/shared-tree-core/editManagerSummarizer.js +2 -5
  354. package/lib/shared-tree-core/editManagerSummarizer.js.map +1 -1
  355. package/lib/shared-tree-core/sharedTreeCore.d.ts +18 -7
  356. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  357. package/lib/shared-tree-core/sharedTreeCore.js +15 -2
  358. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  359. package/lib/simple-tree/api/configuration.d.ts +15 -3
  360. package/lib/simple-tree/api/configuration.d.ts.map +1 -1
  361. package/lib/simple-tree/api/configuration.js +42 -24
  362. package/lib/simple-tree/api/configuration.js.map +1 -1
  363. package/lib/simple-tree/api/index.d.ts +1 -1
  364. package/lib/simple-tree/api/index.d.ts.map +1 -1
  365. package/lib/simple-tree/api/index.js +1 -1
  366. package/lib/simple-tree/api/index.js.map +1 -1
  367. package/lib/simple-tree/api/schemaCompatibilityTester.js +1 -1
  368. package/lib/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
  369. package/lib/simple-tree/api/schemaCreationUtilities.d.ts +3 -3
  370. package/lib/simple-tree/api/schemaCreationUtilities.js +3 -3
  371. package/lib/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  372. package/lib/simple-tree/api/schemaFactory.d.ts +15 -11
  373. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  374. package/lib/simple-tree/api/schemaFactory.js +4 -0
  375. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  376. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +41 -11
  377. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
  378. package/lib/simple-tree/api/schemaFactoryAlpha.js +31 -4
  379. package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
  380. package/lib/simple-tree/api/storedSchema.js +2 -2
  381. package/lib/simple-tree/api/storedSchema.js.map +1 -1
  382. package/lib/simple-tree/api/treeChangeEvents.d.ts +8 -3
  383. package/lib/simple-tree/api/treeChangeEvents.d.ts.map +1 -1
  384. package/lib/simple-tree/api/treeChangeEvents.js.map +1 -1
  385. package/lib/simple-tree/api/treeNodeApi.d.ts +3 -0
  386. package/lib/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  387. package/lib/simple-tree/api/treeNodeApi.js +2 -2
  388. package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
  389. package/lib/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
  390. package/lib/simple-tree/api/viewSchemaToSimpleSchema.js +5 -0
  391. package/lib/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
  392. package/lib/simple-tree/core/context.d.ts +3 -3
  393. package/lib/simple-tree/core/context.d.ts.map +1 -1
  394. package/lib/simple-tree/core/context.js.map +1 -1
  395. package/lib/simple-tree/core/getOrCreateNode.d.ts +9 -0
  396. package/lib/simple-tree/core/getOrCreateNode.d.ts.map +1 -1
  397. package/lib/simple-tree/core/getOrCreateNode.js +10 -0
  398. package/lib/simple-tree/core/getOrCreateNode.js.map +1 -1
  399. package/lib/simple-tree/core/index.d.ts +2 -2
  400. package/lib/simple-tree/core/index.d.ts.map +1 -1
  401. package/lib/simple-tree/core/index.js +2 -2
  402. package/lib/simple-tree/core/index.js.map +1 -1
  403. package/lib/simple-tree/core/treeNodeKernel.js +2 -2
  404. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  405. package/lib/simple-tree/core/treeNodeSchema.d.ts +68 -1
  406. package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  407. package/lib/simple-tree/core/treeNodeSchema.js +21 -0
  408. package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
  409. package/lib/simple-tree/core/unhydratedFlexTree.d.ts +5 -9
  410. package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  411. package/lib/simple-tree/core/unhydratedFlexTree.js +15 -34
  412. package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  413. package/lib/simple-tree/core/walkSchema.d.ts +3 -3
  414. package/lib/simple-tree/core/walkSchema.d.ts.map +1 -1
  415. package/lib/simple-tree/core/walkSchema.js +9 -5
  416. package/lib/simple-tree/core/walkSchema.js.map +1 -1
  417. package/lib/simple-tree/createContext.js +1 -1
  418. package/lib/simple-tree/createContext.js.map +1 -1
  419. package/lib/simple-tree/getTreeNodeForField.d.ts +1 -1
  420. package/lib/simple-tree/getTreeNodeForField.d.ts.map +1 -1
  421. package/lib/simple-tree/getTreeNodeForField.js +1 -1
  422. package/lib/simple-tree/getTreeNodeForField.js.map +1 -1
  423. package/lib/simple-tree/index.d.ts +6 -6
  424. package/lib/simple-tree/index.d.ts.map +1 -1
  425. package/lib/simple-tree/index.js +4 -4
  426. package/lib/simple-tree/index.js.map +1 -1
  427. package/lib/simple-tree/leafNodeSchema.d.ts +4 -1
  428. package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
  429. package/lib/simple-tree/leafNodeSchema.js +2 -1
  430. package/lib/simple-tree/leafNodeSchema.js.map +1 -1
  431. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts +3 -1
  432. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  433. package/lib/simple-tree/node-kinds/array/arrayNode.js +13 -8
  434. package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  435. package/lib/simple-tree/node-kinds/map/mapNode.d.ts +3 -2
  436. package/lib/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
  437. package/lib/simple-tree/node-kinds/map/mapNode.js +14 -8
  438. package/lib/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  439. package/lib/simple-tree/node-kinds/object/objectNode.d.ts +3 -2
  440. package/lib/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  441. package/lib/simple-tree/node-kinds/object/objectNode.js +14 -9
  442. package/lib/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  443. package/lib/simple-tree/prepareForInsertion.d.ts.map +1 -1
  444. package/lib/simple-tree/prepareForInsertion.js +5 -1
  445. package/lib/simple-tree/prepareForInsertion.js.map +1 -1
  446. package/lib/simple-tree/schemaTypes.d.ts +63 -30
  447. package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
  448. package/lib/simple-tree/schemaTypes.js +70 -36
  449. package/lib/simple-tree/schemaTypes.js.map +1 -1
  450. package/lib/simple-tree/simpleSchema.d.ts +22 -4
  451. package/lib/simple-tree/simpleSchema.d.ts.map +1 -1
  452. package/lib/simple-tree/simpleSchema.js.map +1 -1
  453. package/lib/simple-tree/toStoredSchema.d.ts +4 -0
  454. package/lib/simple-tree/toStoredSchema.d.ts.map +1 -1
  455. package/lib/simple-tree/toStoredSchema.js +15 -4
  456. package/lib/simple-tree/toStoredSchema.js.map +1 -1
  457. package/lib/simple-tree/treeNodeValid.d.ts.map +1 -1
  458. package/lib/simple-tree/treeNodeValid.js +1 -2
  459. package/lib/simple-tree/treeNodeValid.js.map +1 -1
  460. package/lib/simple-tree/walkFieldSchema.d.ts.map +1 -1
  461. package/lib/simple-tree/walkFieldSchema.js +1 -1
  462. package/lib/simple-tree/walkFieldSchema.js.map +1 -1
  463. package/lib/tableSchema.d.ts +1 -1
  464. package/lib/util/typeUtils.d.ts +2 -2
  465. package/lib/util/typeUtils.js.map +1 -1
  466. package/lib/util/utils.d.ts +2 -0
  467. package/lib/util/utils.d.ts.map +1 -1
  468. package/lib/util/utils.js.map +1 -1
  469. package/package.json +23 -23
  470. package/src/core/index.ts +3 -1
  471. package/src/core/schema-stored/formatV2.ts +78 -0
  472. package/src/core/schema-stored/index.ts +4 -1
  473. package/src/core/schema-stored/schema.ts +123 -33
  474. package/src/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.ts +16 -11
  475. package/src/feature-libraries/chunked-forest/codec/compressedEncode.ts +16 -7
  476. package/src/feature-libraries/chunked-forest/codec/nodeShape.ts +4 -4
  477. package/src/feature-libraries/detachedFieldIndexSummarizer.ts +9 -16
  478. package/src/feature-libraries/flex-tree/flexTreeTypes.ts +33 -30
  479. package/src/feature-libraries/flex-tree/index.ts +0 -8
  480. package/src/feature-libraries/flex-tree/lazyEntity.ts +5 -1
  481. package/src/feature-libraries/flex-tree/lazyField.ts +5 -8
  482. package/src/feature-libraries/flex-tree/lazyNode.ts +17 -8
  483. package/src/feature-libraries/forest-summary/forestSummarizer.ts +9 -16
  484. package/src/feature-libraries/index.ts +1 -1
  485. package/src/feature-libraries/mapTreeCursor.ts +17 -8
  486. package/src/feature-libraries/modular-schema/fieldKindWithEditor.ts +2 -0
  487. package/src/feature-libraries/object-forest/objectForest.ts +3 -0
  488. package/src/feature-libraries/schema-edits/schemaChangeCodecs.ts +11 -6
  489. package/src/feature-libraries/schema-edits/schemaChangeFormat.ts +3 -3
  490. package/src/feature-libraries/schema-index/codec.ts +73 -14
  491. package/src/feature-libraries/schema-index/formatV2.ts +30 -0
  492. package/src/feature-libraries/schema-index/index.ts +2 -1
  493. package/src/feature-libraries/schema-index/schemaSummarizer.ts +11 -18
  494. package/src/index.ts +6 -0
  495. package/src/packageVersion.ts +1 -1
  496. package/src/shared-tree/schematizeTree.ts +1 -0
  497. package/src/shared-tree/schematizingTreeView.ts +8 -5
  498. package/src/shared-tree/sharedTree.ts +42 -12
  499. package/src/shared-tree/treeAlpha.ts +196 -6
  500. package/src/shared-tree-core/editManagerSummarizer.ts +9 -16
  501. package/src/shared-tree-core/sharedTreeCore.ts +33 -24
  502. package/src/simple-tree/api/configuration.ts +59 -27
  503. package/src/simple-tree/api/index.ts +3 -3
  504. package/src/simple-tree/api/schemaCompatibilityTester.ts +1 -1
  505. package/src/simple-tree/api/schemaCreationUtilities.ts +3 -3
  506. package/src/simple-tree/api/schemaFactory.ts +16 -11
  507. package/src/simple-tree/api/schemaFactoryAlpha.ts +53 -8
  508. package/src/simple-tree/api/storedSchema.ts +4 -4
  509. package/src/simple-tree/api/treeChangeEvents.ts +8 -3
  510. package/src/simple-tree/api/treeNodeApi.ts +5 -2
  511. package/src/simple-tree/api/viewSchemaToSimpleSchema.ts +5 -0
  512. package/src/simple-tree/core/context.ts +3 -3
  513. package/src/simple-tree/core/getOrCreateNode.ts +14 -0
  514. package/src/simple-tree/core/index.ts +7 -1
  515. package/src/simple-tree/core/treeNodeKernel.ts +2 -2
  516. package/src/simple-tree/core/treeNodeSchema.ts +113 -1
  517. package/src/simple-tree/core/unhydratedFlexTree.ts +22 -44
  518. package/src/simple-tree/core/walkSchema.ts +16 -7
  519. package/src/simple-tree/createContext.ts +1 -1
  520. package/src/simple-tree/getTreeNodeForField.ts +3 -1
  521. package/src/simple-tree/index.ts +12 -5
  522. package/src/simple-tree/leafNodeSchema.ts +9 -1
  523. package/src/simple-tree/node-kinds/array/arrayNode.ts +20 -9
  524. package/src/simple-tree/node-kinds/map/mapNode.ts +21 -6
  525. package/src/simple-tree/node-kinds/object/objectNode.ts +29 -12
  526. package/src/simple-tree/prepareForInsertion.ts +5 -1
  527. package/src/simple-tree/schemaTypes.ts +151 -71
  528. package/src/simple-tree/simpleSchema.ts +27 -5
  529. package/src/simple-tree/toStoredSchema.ts +17 -4
  530. package/src/simple-tree/treeNodeValid.ts +1 -1
  531. package/src/simple-tree/walkFieldSchema.ts +5 -1
  532. package/src/util/typeUtils.ts +2 -2
  533. package/src/util/utils.ts +2 -0
  534. package/dist/feature-libraries/flex-tree/navigation.d.ts +0 -46
  535. package/dist/feature-libraries/flex-tree/navigation.d.ts.map +0 -1
  536. package/dist/feature-libraries/flex-tree/navigation.js +0 -104
  537. package/dist/feature-libraries/flex-tree/navigation.js.map +0 -1
  538. package/lib/feature-libraries/flex-tree/navigation.d.ts +0 -46
  539. package/lib/feature-libraries/flex-tree/navigation.d.ts.map +0 -1
  540. package/lib/feature-libraries/flex-tree/navigation.js +0 -97
  541. package/lib/feature-libraries/flex-tree/navigation.js.map +0 -1
  542. package/src/feature-libraries/flex-tree/navigation.ts +0 -121
@@ -4,7 +4,7 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.decodeFieldSchema = exports.encodeFieldSchema = exports.storedSchemaDecodeDispatcher = exports.LeafNodeStoredSchema = exports.MapNodeStoredSchema = exports.ObjectNodeStoredSchema = exports.TreeNodeStoredSchema = exports.identifierFieldKindIdentifier = exports.storedEmptyFieldSchema = exports.forbiddenFieldKindIdentifier = exports.ValueSchema = exports.SchemaVersion = void 0;
7
+ exports.decodeFieldSchema = exports.encodeFieldSchemaV2 = exports.encodeFieldSchemaV1 = exports.storedSchemaDecodeDispatcher = exports.LeafNodeStoredSchema = exports.MapNodeStoredSchema = exports.ObjectNodeStoredSchema = exports.TreeNodeStoredSchema = exports.identifierFieldKindIdentifier = exports.storedEmptyFieldSchema = exports.forbiddenFieldKindIdentifier = exports.ValueSchema = exports.SchemaVersion = void 0;
8
8
  const internal_1 = require("@fluidframework/core-utils/internal");
9
9
  const index_js_1 = require("../../codec/index.js");
10
10
  const index_js_2 = require("../../util/index.js");
@@ -15,6 +15,10 @@ const formatV1_js_1 = require("./formatV1.js");
15
15
  var SchemaVersion;
16
16
  (function (SchemaVersion) {
17
17
  SchemaVersion[SchemaVersion["v1"] = 1] = "v1";
18
+ /**
19
+ * Adds persisted metadata to the node schema and field schema.
20
+ */
21
+ SchemaVersion[SchemaVersion["v2"] = 2] = "v2";
18
22
  })(SchemaVersion || (exports.SchemaVersion = SchemaVersion = {}));
19
23
  /**
20
24
  * Schema for what {@link TreeLeafValue} is allowed on a Leaf node.
@@ -53,6 +57,7 @@ exports.storedEmptyFieldSchema = {
53
57
  kind: (0, index_js_2.brand)(exports.forbiddenFieldKindIdentifier),
54
58
  // This type set also forces the field to be empty not not allowing any types as all.
55
59
  types: new Set(),
60
+ persistedMetadata: undefined,
56
61
  };
57
62
  /**
58
63
  * Identifier used for the FieldKind for fields of type identifier.
@@ -61,6 +66,13 @@ exports.identifierFieldKindIdentifier = "Identifier";
61
66
  /**
62
67
  */
63
68
  class TreeNodeStoredSchema {
69
+ /**
70
+ * Constructor for a TreeNodeStoredSchema.
71
+ * @param metadata - Persisted metadata for this node schema.
72
+ */
73
+ constructor(metadata) {
74
+ this.metadata = metadata;
75
+ }
64
76
  }
65
77
  exports.TreeNodeStoredSchema = TreeNodeStoredSchema;
66
78
  /**
@@ -74,11 +86,25 @@ class ObjectNodeStoredSchema extends TreeNodeStoredSchema {
74
86
  * This allows us short friendly field keys which can be ergonomically used as field names in code.
75
87
  * It also interoperates well with mapFields being used as a map with arbitrary data as keys.
76
88
  */
77
- constructor(objectNodeFields) {
78
- super();
89
+ constructor(objectNodeFields, metadata) {
90
+ super(metadata);
79
91
  this.objectNodeFields = objectNodeFields;
80
92
  }
81
- encode() {
93
+ encodeV1() {
94
+ const fieldsObject = this.encodeFieldsObject(encodeFieldSchemaV1);
95
+ return {
96
+ object: fieldsObject,
97
+ };
98
+ }
99
+ encodeV2() {
100
+ const fieldsObject = this.encodeFieldsObject(encodeFieldSchemaV2);
101
+ const kind = { object: fieldsObject };
102
+ return { kind, metadata: this.metadata };
103
+ }
104
+ getFieldSchema(field) {
105
+ return this.objectNodeFields.get(field) ?? exports.storedEmptyFieldSchema;
106
+ }
107
+ encodeFieldsObject(encodeFieldSchema) {
82
108
  const fieldsObject = Object.create(null);
83
109
  // Sort fields to ensure output is identical for for equivalent schema (since field order is not considered significant).
84
110
  // This makes comparing schema easier, and ensures chunk reuse for schema summaries isn't needlessly broken.
@@ -90,12 +116,7 @@ class ObjectNodeStoredSchema extends TreeNodeStoredSchema {
90
116
  value: encodeFieldSchema(this.objectNodeFields.get(key) ?? (0, internal_1.fail)(0xae7 /* missing field */)),
91
117
  });
92
118
  }
93
- return {
94
- object: fieldsObject,
95
- };
96
- }
97
- getFieldSchema(field) {
98
- return this.objectNodeFields.get(field) ?? exports.storedEmptyFieldSchema;
119
+ return fieldsObject;
99
120
  }
100
121
  }
101
122
  exports.ObjectNodeStoredSchema = ObjectNodeStoredSchema;
@@ -110,15 +131,19 @@ class MapNodeStoredSchema extends TreeNodeStoredSchema {
110
131
  * since no nodes can ever be in schema if you use `FieldKind.Value` here
111
132
  * (that would require infinite children).
112
133
  */
113
- constructor(mapFields) {
114
- super();
134
+ constructor(mapFields, metadata) {
135
+ super(metadata);
115
136
  this.mapFields = mapFields;
116
137
  }
117
- encode() {
138
+ encodeV1() {
118
139
  return {
119
- map: encodeFieldSchema(this.mapFields),
140
+ map: encodeFieldSchemaV1(this.mapFields),
120
141
  };
121
142
  }
143
+ encodeV2() {
144
+ const kind = { map: encodeFieldSchemaV2(this.mapFields) };
145
+ return { kind, metadata: this.metadata };
146
+ }
122
147
  getFieldSchema(field) {
123
148
  return this.mapFields;
124
149
  }
@@ -140,29 +165,38 @@ class LeafNodeStoredSchema extends TreeNodeStoredSchema {
140
165
  * This is simply one approach that can work for modeling them in the internal schema representation.
141
166
  */
142
167
  constructor(leafValue) {
143
- super();
168
+ // No metadata for leaf nodes.
169
+ super(undefined);
144
170
  this.leafValue = leafValue;
145
171
  }
146
- encode() {
172
+ encodeV1() {
147
173
  return {
148
174
  leaf: encodeValueSchema(this.leafValue),
149
175
  };
150
176
  }
177
+ encodeV2() {
178
+ return {
179
+ // No metadata for leaf nodes, so don't emit a metadata field.
180
+ kind: {
181
+ leaf: encodeValueSchema(this.leafValue),
182
+ },
183
+ };
184
+ }
151
185
  getFieldSchema(field) {
152
186
  return exports.storedEmptyFieldSchema;
153
187
  }
154
188
  }
155
189
  exports.LeafNodeStoredSchema = LeafNodeStoredSchema;
156
190
  exports.storedSchemaDecodeDispatcher = new index_js_1.DiscriminatedUnionDispatcher({
157
- leaf: (data) => new LeafNodeStoredSchema(decodeValueSchema(data)),
158
- object: (data) => {
191
+ leaf: (data) => (metadata) => new LeafNodeStoredSchema(decodeValueSchema(data)),
192
+ object: (data) => (metadata) => {
159
193
  const map = new Map();
160
194
  for (const [key, value] of Object.entries(data)) {
161
195
  map.set(key, decodeFieldSchema(value));
162
196
  }
163
- return new ObjectNodeStoredSchema(map);
197
+ return new ObjectNodeStoredSchema(map, metadata);
164
198
  },
165
- map: (data) => new MapNodeStoredSchema(decodeFieldSchema(data)),
199
+ map: (data) => (metadata) => new MapNodeStoredSchema(decodeFieldSchema(data), metadata),
166
200
  });
167
201
  const valueSchemaEncode = new Map([
168
202
  [ValueSchema.Number, formatV1_js_1.PersistedValueSchema.Number],
@@ -178,19 +212,28 @@ function encodeValueSchema(inMemory) {
178
212
  function decodeValueSchema(inMemory) {
179
213
  return valueSchemaDecode.get(inMemory) ?? (0, internal_1.fail)(0xae9 /* missing ValueSchema */);
180
214
  }
181
- function encodeFieldSchema(schema) {
215
+ function encodeFieldSchemaV1(schema) {
182
216
  return {
183
217
  kind: schema.kind,
184
218
  // Types are sorted by identifier to improve stability of persisted data to increase chance of schema blob reuse.
185
219
  types: [...schema.types].sort(),
186
220
  };
187
221
  }
188
- exports.encodeFieldSchema = encodeFieldSchema;
222
+ exports.encodeFieldSchemaV1 = encodeFieldSchemaV1;
223
+ function encodeFieldSchemaV2(schema) {
224
+ const fieldSchema = encodeFieldSchemaV1(schema);
225
+ // Omit metadata from the output if it is undefined
226
+ return schema.persistedMetadata !== undefined
227
+ ? { ...fieldSchema, metadata: schema.persistedMetadata }
228
+ : { ...fieldSchema };
229
+ }
230
+ exports.encodeFieldSchemaV2 = encodeFieldSchemaV2;
189
231
  function decodeFieldSchema(schema) {
190
232
  const out = {
191
233
  // TODO: maybe provide actual FieldKind objects here, error on unrecognized kinds.
192
234
  kind: schema.kind,
193
235
  types: new Set(schema.types),
236
+ persistedMetadata: schema.metadata,
194
237
  };
195
238
  return out;
196
239
  }
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/core/schema-stored/schema.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA2D;AAE3D,mDAAoE;AACpE,kDAAyE;AAEzE,+CAOuB;AAGvB;;GAEG;AACH,IAAY,aAEX;AAFD,WAAY,aAAa;IACxB,6CAAM,CAAA;AACP,CAAC,EAFW,aAAa,6BAAb,aAAa,QAExB;AAED;;;;;;;;GAQG;AACH,IAAY,WAMX;AAND,WAAY,WAAW;IACtB,iDAAM,CAAA;IACN,iDAAM,CAAA;IACN,mDAAO,CAAA;IACP,2DAAW,CAAA;IACX,6CAAI,CAAA;AACL,CAAC,EANW,WAAW,2BAAX,WAAW,QAMtB;AA0FD;;;;;;;;;GASG;AACU,QAAA,4BAA4B,GAAG,WAAW,CAAC;AAExD;;;GAGG;AACU,QAAA,sBAAsB,GAA0B;IAC5D,4CAA4C;IAC5C,IAAI,EAAE,IAAA,gBAAK,EAAC,oCAA4B,CAAC;IACzC,qFAAqF;IACrF,KAAK,EAAE,IAAI,GAAG,EAAE;CAChB,CAAC;AAEF;;GAEG;AACU,QAAA,6BAA6B,GAAG,YAAY,CAAC;AAE1D;GACG;AACH,MAAsB,oBAAoB;CAezC;AAfD,oDAeC;AAED;GACG;AACH,MAAa,sBAAuB,SAAQ,oBAAoB;IAC/D;;;;;;;OAOG;IACH,YACiB,gBAA8D;QAE9E,KAAK,EAAE,CAAC;QAF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EH,MAAM,iBAAiB,GAAG,IAAA,oBAAS,EAAC,iBAAiB,CAAC,CAAC;AAEvD,SAAS,iBAAiB,CAAC,QAAqB;IAC/C,OAAO,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,IAAA,eAAI,EAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;AAC1F,CAAC;AAED,SAAS,iBAAiB,CAAC,QAA8B;IACxD,OAAO,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,IAAA,eAAI,EAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;AACjF,CAAC;AAED,SAAgB,iBAAiB,CAAC,MAA6B;IAC9D,OAAO;QACN,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,iHAAiH;QACjH,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE;KAC/B,CAAC;AACH,CAAC;AAND,8CAMC;AAED,SAAgB,iBAAiB,CAAC,MAAyB;IAC1D,MAAM,GAAG,GAA0B;QAClC,kFAAkF;QAClF,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,KAAK,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;KAC5B,CAAC;IACF,OAAO,GAAG,CAAC;AACZ,CAAC;AAPD,8CAOC","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 { DiscriminatedUnionDispatcher } from \"../../codec/index.js\";\nimport { type MakeNominal, brand, invertMap } from \"../../util/index.js\";\n\nimport {\n\ttype FieldKey,\n\ttype FieldKindIdentifier,\n\ttype FieldSchemaFormat,\n\tPersistedValueSchema,\n\ttype TreeNodeSchemaDataFormat,\n\ttype TreeNodeSchemaIdentifier,\n} from \"./formatV1.js\";\nimport type { Multiplicity } from \"./multiplicity.js\";\n\n/**\n * The format version for the schema.\n */\nexport enum SchemaVersion {\n\tv1 = 1,\n}\n\n/**\n * Schema for what {@link TreeLeafValue} is allowed on a Leaf node.\n * @privateRemarks\n * See also {@link TreeValue}.\n * If further stabilizing this,\n * consider the implications of how this might prevent adding of new leaf types in the future.\n * Maybe add a disclaimer that it might be extended like on {@link NodeKind}?\n * @alpha\n */\nexport enum ValueSchema {\n\tNumber,\n\tString,\n\tBoolean,\n\tFluidHandle,\n\tNull,\n}\n\n/**\n * Set of allowed tree types.\n * Providing multiple values here allows polymorphism, tagged union style.\n *\n * In the future, this could be extended to allow inlining a TreeNodeStoredSchema here\n * (or some similar structural schema system).\n * For structural types which could go here, there are a few interesting options:\n *\n * - Allow replacing the whole set with a structural type for terminal / non-tree data,\n * and use this as a replacement for values on the tree nodes.\n *\n * - Allow expression structural constraints for child trees, for example requiring specific traits\n * (ex: via TreeNodeStoredSchema), instead of by type.\n *\n * There are two ways this could work:\n *\n * - Constrain the child nodes based on their shape:\n * this makes schema safe editing difficult because nodes would incur extra editing constraints to prevent them\n * from going out of schema based on their location in such a field.\n *\n * - Constrain the types allowed based on which types guarantee their data will always meet the constraints.\n *\n * Care would need to be taken to make sure this is sound for the schema updating mechanisms.\n */\nexport type TreeTypeSet = ReadonlySet<TreeNodeSchemaIdentifier>;\n\n/**\n * Declarative portion of a Field Kind.\n *\n * @remarks\n * Enough info about a field kind to know if a given tree is is schema.\n */\nexport interface FieldKindData {\n\treadonly identifier: FieldKindIdentifier;\n\treadonly multiplicity: Multiplicity;\n}\n\n/**\n * Everything needed to define what it means for a tree to be in schema.\n */\nexport interface SchemaAndPolicy {\n\treadonly schema: StoredSchemaCollection;\n\treadonly policy: SchemaPolicy;\n}\n\n/**\n * Extra data needed to interpret schema.\n */\nexport interface SchemaPolicy {\n\t/**\n\t * Policy information about FieldKinds:\n\t * This is typically stored as code, not in documents, and defines how to handle fields based on their kind.\n\t * It is assumed that all users of a document will have exactly the same FieldKind policies,\n\t * though older applications might be missing some,\n\t * and will be unable to process any changes that use those FieldKinds.\n\t */\n\treadonly fieldKinds: ReadonlyMap<FieldKindIdentifier, FieldKindData>;\n\n\t/**\n\t * If true, new content inserted into the tree should be validated against the stored schema.\n\t */\n\treadonly validateSchema: boolean;\n\n\t/**\n\t * Whether to allow a document to be opened when a particular stored schema (identified by `identifier`)\n\t * contains optional fields that are not known to the view schema.\n\t *\n\t * @privateRemarks\n\t * Plumbing this in via `SchemaPolicy` avoids needing to walk the view schema representation repeatedly in places\n\t * that need it (schema validation, view vs stored compatibility checks).\n\t */\n\tallowUnknownOptionalFields(identifier: TreeNodeSchemaIdentifier): boolean;\n}\n\n/**\n * Schema for a field.\n * Object implementing this interface should never be modified.\n */\nexport interface TreeFieldStoredSchema {\n\treadonly kind: FieldKindIdentifier;\n\n\t/**\n\t * The set of allowed child types.\n\t * If not specified, types are unconstrained.\n\t */\n\treadonly types: TreeTypeSet;\n}\n\n/**\n * Identifier used for the FieldKind for fields which must be empty.\n *\n * @remarks\n * This mainly show up in:\n *\n * 1. The root default field for documents.\n *\n * 2. The schema used for out of schema fields (which thus must be empty/not exist) on object and leaf nodes.\n */\nexport const forbiddenFieldKindIdentifier = \"Forbidden\";\n\n/**\n * A schema for empty fields (fields which must always be empty).\n * There are multiple ways this could be encoded, but this is the most explicit.\n */\nexport const storedEmptyFieldSchema: TreeFieldStoredSchema = {\n\t// This kind requires the field to be empty.\n\tkind: brand(forbiddenFieldKindIdentifier),\n\t// This type set also forces the field to be empty not not allowing any types as all.\n\ttypes: new Set(),\n};\n\n/**\n * Identifier used for the FieldKind for fields of type identifier.\n */\nexport const identifierFieldKindIdentifier = \"Identifier\";\n\n/**\n */\nexport abstract class TreeNodeStoredSchema {\n\tprotected _typeCheck!: MakeNominal;\n\n\t/**\n\t * @privateRemarks\n\t * Returns TreeNodeSchemaDataFormat.\n\t * This is uses an opaque type to avoid leaking these types out of the package,\n\t * and is runtime validated by the codec.\n\t */\n\tpublic abstract encode(): TreeNodeSchemaDataFormat;\n\n\t/**\n\t * Returns the schema for the provided field.\n\t */\n\tpublic abstract getFieldSchema(field: FieldKey): TreeFieldStoredSchema;\n}\n\n/**\n */\nexport class ObjectNodeStoredSchema extends TreeNodeStoredSchema {\n\t/**\n\t * @param objectNodeFields -\n\t * Schema for fields with keys scoped to this TreeNodeStoredSchema.\n\t * This refers to the TreeFieldStoredSchema directly\n\t * (as opposed to just supporting FieldSchemaIdentifier and having a central FieldKey -\\> TreeFieldStoredSchema map).\n\t * This allows us short friendly field keys which can be ergonomically used as field names in code.\n\t * It also interoperates well with mapFields being used as a map with arbitrary data as keys.\n\t */\n\tpublic constructor(\n\t\tpublic readonly objectNodeFields: ReadonlyMap<FieldKey, TreeFieldStoredSchema>,\n\t) {\n\t\tsuper();\n\t}\n\n\tpublic override encode(): TreeNodeSchemaDataFormat {\n\t\tconst fieldsObject: Record<string, FieldSchemaFormat> = Object.create(null);\n\t\t// Sort fields to ensure output is identical for for equivalent schema (since field order is not considered significant).\n\t\t// This makes comparing schema easier, and ensures chunk reuse for schema summaries isn't needlessly broken.\n\t\tfor (const key of [...this.objectNodeFields.keys()].sort()) {\n\t\t\tObject.defineProperty(fieldsObject, key, {\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true,\n\t\t\t\twritable: true,\n\t\t\t\tvalue: encodeFieldSchema(\n\t\t\t\t\tthis.objectNodeFields.get(key) ?? fail(0xae7 /* missing field */),\n\t\t\t\t),\n\t\t\t});\n\t\t}\n\t\treturn {\n\t\t\tobject: fieldsObject,\n\t\t};\n\t}\n\n\tpublic override getFieldSchema(field: FieldKey): TreeFieldStoredSchema {\n\t\treturn this.objectNodeFields.get(field) ?? storedEmptyFieldSchema;\n\t}\n}\n\n/**\n */\nexport class MapNodeStoredSchema extends TreeNodeStoredSchema {\n\t/**\n\t * @param mapFields -\n\t * Allows using the fields as a map, with the keys being\n\t * FieldKeys and the values being constrained by this TreeFieldStoredSchema.\n\t * Usually `FieldKind.Value` should NOT be used here\n\t * since no nodes can ever be in schema if you use `FieldKind.Value` here\n\t * (that would require infinite children).\n\t */\n\tpublic constructor(public readonly mapFields: TreeFieldStoredSchema) {\n\t\tsuper();\n\t}\n\n\tpublic override encode(): TreeNodeSchemaDataFormat {\n\t\treturn {\n\t\t\tmap: encodeFieldSchema(this.mapFields),\n\t\t};\n\t}\n\n\tpublic override getFieldSchema(field: FieldKey): TreeFieldStoredSchema {\n\t\treturn this.mapFields;\n\t}\n}\n\n/**\n */\nexport class LeafNodeStoredSchema extends TreeNodeStoredSchema {\n\t/**\n\t * @param leafValue -\n\t * There are several approaches for how to store actual data in the tree\n\t * (special node types, special field contents, data on nodes etc.)\n\t * as well as several options about how the data should be modeled at this level\n\t * (byte sequence? javascript type? json?),\n\t * as well as options for how much of this would be exposed in the schema language\n\t * (ex: would all nodes with values be special built-ins, or could any schema add them?)\n\t * A simple easy to do in javascript approach is taken here:\n\t * this is not intended to be a suggestion of what approach to take, or what to expose in the schema language.\n\t * This is simply one approach that can work for modeling them in the internal schema representation.\n\t */\n\tpublic constructor(public readonly leafValue: ValueSchema) {\n\t\tsuper();\n\t}\n\n\tpublic override encode(): TreeNodeSchemaDataFormat {\n\t\treturn {\n\t\t\tleaf: encodeValueSchema(this.leafValue),\n\t\t};\n\t}\n\n\tpublic override getFieldSchema(field: FieldKey): TreeFieldStoredSchema {\n\t\treturn storedEmptyFieldSchema;\n\t}\n}\n\nexport const storedSchemaDecodeDispatcher: DiscriminatedUnionDispatcher<\n\tTreeNodeSchemaDataFormat,\n\t[],\n\tTreeNodeStoredSchema\n> = new DiscriminatedUnionDispatcher({\n\tleaf: (data: PersistedValueSchema) => new LeafNodeStoredSchema(decodeValueSchema(data)),\n\tobject: (\n\t\tdata: Record<TreeNodeSchemaIdentifier, FieldSchemaFormat>,\n\t): TreeNodeStoredSchema => {\n\t\tconst map = new Map();\n\t\tfor (const [key, value] of Object.entries(data)) {\n\t\t\tmap.set(key, decodeFieldSchema(value));\n\t\t}\n\t\treturn new ObjectNodeStoredSchema(map);\n\t},\n\tmap: (data: FieldSchemaFormat) => new MapNodeStoredSchema(decodeFieldSchema(data)),\n});\n\nconst valueSchemaEncode = new Map([\n\t[ValueSchema.Number, PersistedValueSchema.Number],\n\t[ValueSchema.String, PersistedValueSchema.String],\n\t[ValueSchema.Boolean, PersistedValueSchema.Boolean],\n\t[ValueSchema.FluidHandle, PersistedValueSchema.FluidHandle],\n\t[ValueSchema.Null, PersistedValueSchema.Null],\n]);\n\nconst valueSchemaDecode = invertMap(valueSchemaEncode);\n\nfunction encodeValueSchema(inMemory: ValueSchema): PersistedValueSchema {\n\treturn valueSchemaEncode.get(inMemory) ?? fail(0xae8 /* missing PersistedValueSchema */);\n}\n\nfunction decodeValueSchema(inMemory: PersistedValueSchema): ValueSchema {\n\treturn valueSchemaDecode.get(inMemory) ?? fail(0xae9 /* missing ValueSchema */);\n}\n\nexport function encodeFieldSchema(schema: TreeFieldStoredSchema): FieldSchemaFormat {\n\treturn {\n\t\tkind: schema.kind,\n\t\t// Types are sorted by identifier to improve stability of persisted data to increase chance of schema blob reuse.\n\t\ttypes: [...schema.types].sort(),\n\t};\n}\n\nexport function decodeFieldSchema(schema: FieldSchemaFormat): TreeFieldStoredSchema {\n\tconst out: TreeFieldStoredSchema = {\n\t\t// TODO: maybe provide actual FieldKind objects here, error on unrecognized kinds.\n\t\tkind: schema.kind,\n\t\ttypes: new Set(schema.types),\n\t};\n\treturn out;\n}\n\n/**\n * Document schema data that can be stored in a document.\n *\n * @remarks\n * Note: the owner of this may modify it over time:\n * thus if needing to hand onto a specific version, make a copy.\n */\nexport interface TreeStoredSchema extends StoredSchemaCollection {\n\t/**\n\t * Schema for the root field which contains the whole tree.\n\t */\n\treadonly rootFieldSchema: TreeFieldStoredSchema;\n}\n\n/**\n * Collection of TreeNodeSchema data that can be stored in a document.\n *\n * @remarks\n * Note: the owner of this may modify it over time:\n * thus if needing to hang onto a specific version, make a copy.\n */\nexport interface StoredSchemaCollection {\n\t/**\n\t * {@inheritdoc StoredSchemaCollection}\n\t */\n\treadonly nodeSchema: ReadonlyMap<TreeNodeSchemaIdentifier, TreeNodeStoredSchema>;\n}\n"]}
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/core/schema-stored/schema.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA2D;AAE3D,mDAAoE;AACpE,kDAK6B;AAE7B,+CAOuB;AASvB;;GAEG;AACH,IAAY,aAMX;AAND,WAAY,aAAa;IACxB,6CAAM,CAAA;IACN;;OAEG;IACH,6CAAM,CAAA;AACP,CAAC,EANW,aAAa,6BAAb,aAAa,QAMxB;AAID;;;;;;;;GAQG;AACH,IAAY,WAMX;AAND,WAAY,WAAW;IACtB,iDAAM,CAAA;IACN,iDAAM,CAAA;IACN,mDAAO,CAAA;IACP,2DAAW,CAAA;IACX,6CAAI,CAAA;AACL,CAAC,EANW,WAAW,2BAAX,WAAW,QAMtB;AAmGD;;;;;;;;;GASG;AACU,QAAA,4BAA4B,GAAG,WAAW,CAAC;AAExD;;;GAGG;AACU,QAAA,sBAAsB,GAA0B;IAC5D,4CAA4C;IAC5C,IAAI,EAAE,IAAA,gBAAK,EAAC,oCAA4B,CAAC;IACzC,qFAAqF;IACrF,KAAK,EAAE,IAAI,GAAG,EAAE;IAChB,iBAAiB,EAAE,SAAS;CAC5B,CAAC;AAEF;;GAEG;AACU,QAAA,6BAA6B,GAAG,YAAY,CAAC;AAE1D;GACG;AACH,MAAsB,oBAAoB;IAGzC;;;OAGG;IACH,YAAmC,QAA6C;QAA7C,aAAQ,GAAR,QAAQ,CAAqC;IAAG,CAAC;CAiBpF;AAxBD,oDAwBC;AAED;GACG;AACH,MAAa,sBAAuB,SAAQ,oBAAoB;IAC/D;;;;;;;OAOG;IACH,YACiB,gBAA8D,EAC9E,QAA8C;QAE9C,KAAK,CAAC,QAAQ,CAAC,CAAC;QAHA,qBAAgB,GAAhB,gBAAgB,CAA8C;IAI/E,CAAC;IAEe,QAAQ;QACvB,MAAM,YAAY,GACjB,IAAI,CAAC,kBAAkB,CAAC,m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ACjB,iHAAiH;QACjH,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE;KAC/B,CAAC;AACH,CAAC;AAND,kDAMC;AAED,SAAgB,mBAAmB,CAAC,MAA6B;IAChE,MAAM,WAAW,GAAwB,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAErE,mDAAmD;IACnD,OAAO,MAAM,CAAC,iBAAiB,KAAK,SAAS;QAC5C,CAAC,CAAC,EAAE,GAAG,WAAW,EAAE,QAAQ,EAAE,MAAM,CAAC,iBAAiB,EAAE;QACxD,CAAC,CAAC,EAAE,GAAG,WAAW,EAAE,CAAC;AACvB,CAAC;AAPD,kDAOC;AAED,SAAgB,iBAAiB,CAAC,MAA2B;IAC5D,MAAM,GAAG,GAA0B;QAClC,kFAAkF;QAClF,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,KAAK,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;QAC5B,iBAAiB,EAAE,MAAM,CAAC,QAAQ;KAClC,CAAC;IACF,OAAO,GAAG,CAAC;AACZ,CAAC;AARD,8CAQC","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 { DiscriminatedUnionDispatcher } from \"../../codec/index.js\";\nimport {\n\ttype JsonCompatibleReadOnlyObject,\n\ttype MakeNominal,\n\tbrand,\n\tinvertMap,\n} from \"../../util/index.js\";\n\nimport {\n\ttype FieldKey,\n\ttype FieldKindIdentifier,\n\ttype FieldSchemaFormat as FieldSchemaFormatV1,\n\tPersistedValueSchema,\n\ttype TreeNodeSchemaDataFormat as TreeNodeSchemaDataFormatV1,\n\ttype TreeNodeSchemaIdentifier,\n} from \"./formatV1.js\";\nimport type {\n\tFieldSchemaFormat as FieldSchemaFormatV2,\n\tPersistedMetadataFormat,\n\tTreeNodeSchemaUnionFormat,\n\tTreeNodeSchemaDataFormat as TreeNodeSchemaDataFormatV2,\n} from \"./formatV2.js\";\nimport type { Multiplicity } from \"./multiplicity.js\";\n\n/**\n * The format version for the schema.\n */\nexport enum SchemaVersion {\n\tv1 = 1,\n\t/**\n\t * Adds persisted metadata to the node schema and field schema.\n\t */\n\tv2 = 2,\n}\n\ntype FieldSchemaFormat = FieldSchemaFormatV1 | FieldSchemaFormatV2;\n\n/**\n * Schema for what {@link TreeLeafValue} is allowed on a Leaf node.\n * @privateRemarks\n * See also {@link TreeValue}.\n * If further stabilizing this,\n * consider the implications of how this might prevent adding of new leaf types in the future.\n * Maybe add a disclaimer that it might be extended like on {@link NodeKind}?\n * @alpha\n */\nexport enum ValueSchema {\n\tNumber,\n\tString,\n\tBoolean,\n\tFluidHandle,\n\tNull,\n}\n\n/**\n * Set of allowed tree types.\n * Providing multiple values here allows polymorphism, tagged union style.\n *\n * In the future, this could be extended to allow inlining a TreeNodeStoredSchema here\n * (or some similar structural schema system).\n * For structural types which could go here, there are a few interesting options:\n *\n * - Allow replacing the whole set with a structural type for terminal / non-tree data,\n * and use this as a replacement for values on the tree nodes.\n *\n * - Allow expression structural constraints for child trees, for example requiring specific traits\n * (ex: via TreeNodeStoredSchema), instead of by type.\n *\n * There are two ways this could work:\n *\n * - Constrain the child nodes based on their shape:\n * this makes schema safe editing difficult because nodes would incur extra editing constraints to prevent them\n * from going out of schema based on their location in such a field.\n *\n * - Constrain the types allowed based on which types guarantee their data will always meet the constraints.\n *\n * Care would need to be taken to make sure this is sound for the schema updating mechanisms.\n */\nexport type TreeTypeSet = ReadonlySet<TreeNodeSchemaIdentifier>;\n\n/**\n * Declarative portion of a Field Kind.\n *\n * @remarks\n * Enough info about a field kind to know if a given tree is is schema.\n */\nexport interface FieldKindData {\n\treadonly identifier: FieldKindIdentifier;\n\treadonly multiplicity: Multiplicity;\n}\n\n/**\n * Everything needed to define what it means for a tree to be in schema.\n */\nexport interface SchemaAndPolicy {\n\treadonly schema: StoredSchemaCollection;\n\treadonly policy: SchemaPolicy;\n}\n\n/**\n * Extra data needed to interpret schema.\n */\nexport interface SchemaPolicy {\n\t/**\n\t * Policy information about FieldKinds:\n\t * This is typically stored as code, not in documents, and defines how to handle fields based on their kind.\n\t * It is assumed that all users of a document will have exactly the same FieldKind policies,\n\t * though older applications might be missing some,\n\t * and will be unable to process any changes that use those FieldKinds.\n\t */\n\treadonly fieldKinds: ReadonlyMap<FieldKindIdentifier, FieldKindData>;\n\n\t/**\n\t * If true, new content inserted into the tree should be validated against the stored schema.\n\t */\n\treadonly validateSchema: boolean;\n\n\t/**\n\t * Whether to allow a document to be opened when a particular stored schema (identified by `identifier`)\n\t * contains optional fields that are not known to the view schema.\n\t *\n\t * @privateRemarks\n\t * Plumbing this in via `SchemaPolicy` avoids needing to walk the view schema representation repeatedly in places\n\t * that need it (schema validation, view vs stored compatibility checks).\n\t */\n\tallowUnknownOptionalFields(identifier: TreeNodeSchemaIdentifier): boolean;\n}\n\n/**\n * Schema for a field.\n * Object implementing this interface should never be modified.\n */\nexport interface TreeFieldStoredSchema {\n\treadonly kind: FieldKindIdentifier;\n\n\t/**\n\t * The set of allowed child types.\n\t * If not specified, types are unconstrained.\n\t */\n\treadonly types: TreeTypeSet;\n\n\t/**\n\t * Portion of the metadata which can be persisted.\n\t * @remarks\n\t * Discarded when encoding to {@link SchemaFormatVersion.V1}.\n\t * @privateRemarks\n\t * This field corresponds to the `metadata` field in the persisted schema format.\n\t */\n\treadonly persistedMetadata: JsonCompatibleReadOnlyObject | undefined;\n}\n\n/**\n * Identifier used for the FieldKind for fields which must be empty.\n *\n * @remarks\n * This mainly show up in:\n *\n * 1. The root default field for documents.\n *\n * 2. The schema used for out of schema fields (which thus must be empty/not exist) on object and leaf nodes.\n */\nexport const forbiddenFieldKindIdentifier = \"Forbidden\";\n\n/**\n * A schema for empty fields (fields which must always be empty).\n * There are multiple ways this could be encoded, but this is the most explicit.\n */\nexport const storedEmptyFieldSchema: TreeFieldStoredSchema = {\n\t// This kind requires the field to be empty.\n\tkind: brand(forbiddenFieldKindIdentifier),\n\t// This type set also forces the field to be empty not not allowing any types as all.\n\ttypes: new Set(),\n\tpersistedMetadata: undefined,\n};\n\n/**\n * Identifier used for the FieldKind for fields of type identifier.\n */\nexport const identifierFieldKindIdentifier = \"Identifier\";\n\n/**\n */\nexport abstract class TreeNodeStoredSchema {\n\tprotected _typeCheck!: MakeNominal;\n\n\t/**\n\t * Constructor for a TreeNodeStoredSchema.\n\t * @param metadata - Persisted metadata for this node schema.\n\t */\n\tpublic constructor(public readonly metadata: PersistedMetadataFormat | undefined) {}\n\n\t/**\n\t * Encode in the v1 schema format.\n\t */\n\tpublic abstract encodeV1(): TreeNodeSchemaDataFormatV1;\n\n\t/**\n\t * Encode in the v2 schema format.\n\t * @remarks Post-condition: if metadata was specified on the input schema, it will be present in the output.\n\t */\n\tpublic abstract encodeV2(): TreeNodeSchemaDataFormatV2;\n\n\t/**\n\t * Returns the schema for the provided field.\n\t */\n\tpublic abstract getFieldSchema(field: FieldKey): TreeFieldStoredSchema;\n}\n\n/**\n */\nexport class ObjectNodeStoredSchema extends TreeNodeStoredSchema {\n\t/**\n\t * @param objectNodeFields -\n\t * Schema for fields with keys scoped to this TreeNodeStoredSchema.\n\t * This refers to the TreeFieldStoredSchema directly\n\t * (as opposed to just supporting FieldSchemaIdentifier and having a central FieldKey -\\> TreeFieldStoredSchema map).\n\t * This allows us short friendly field keys which can be ergonomically used as field names in code.\n\t * It also interoperates well with mapFields being used as a map with arbitrary data as keys.\n\t */\n\tpublic constructor(\n\t\tpublic readonly objectNodeFields: ReadonlyMap<FieldKey, TreeFieldStoredSchema>,\n\t\tmetadata?: PersistedMetadataFormat | undefined,\n\t) {\n\t\tsuper(metadata);\n\t}\n\n\tpublic override encodeV1(): TreeNodeSchemaDataFormatV1 {\n\t\tconst fieldsObject: Record<string, FieldSchemaFormat> =\n\t\t\tthis.encodeFieldsObject(encodeFieldSchemaV1);\n\n\t\treturn {\n\t\t\tobject: fieldsObject,\n\t\t};\n\t}\n\n\tpublic override encodeV2(): TreeNodeSchemaDataFormatV2 {\n\t\tconst fieldsObject: Record<string, FieldSchemaFormat> =\n\t\t\tthis.encodeFieldsObject(encodeFieldSchemaV2);\n\t\tconst kind = { object: fieldsObject };\n\n\t\treturn { kind, metadata: this.metadata };\n\t}\n\n\tpublic override getFieldSchema(field: FieldKey): TreeFieldStoredSchema {\n\t\treturn this.objectNodeFields.get(field) ?? storedEmptyFieldSchema;\n\t}\n\n\tprivate encodeFieldsObject(\n\t\tencodeFieldSchema: (storedFieldSchema: TreeFieldStoredSchema) => FieldSchemaFormat,\n\t): Record<string, FieldSchemaFormat> {\n\t\tconst fieldsObject: Record<string, FieldSchemaFormat> = Object.create(null);\n\t\t// Sort fields to ensure output is identical for for equivalent schema (since field order is not considered significant).\n\t\t// This makes comparing schema easier, and ensures chunk reuse for schema summaries isn't needlessly broken.\n\t\tfor (const key of [...this.objectNodeFields.keys()].sort()) {\n\t\t\tObject.defineProperty(fieldsObject, key, {\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true,\n\t\t\t\twritable: true,\n\t\t\t\tvalue: encodeFieldSchema(\n\t\t\t\t\tthis.objectNodeFields.get(key) ?? fail(0xae7 /* missing field */),\n\t\t\t\t),\n\t\t\t});\n\t\t}\n\t\treturn fieldsObject;\n\t}\n}\n\n/**\n */\nexport class MapNodeStoredSchema extends TreeNodeStoredSchema {\n\t/**\n\t * @param mapFields -\n\t * Allows using the fields as a map, with the keys being\n\t * FieldKeys and the values being constrained by this TreeFieldStoredSchema.\n\t * Usually `FieldKind.Value` should NOT be used here\n\t * since no nodes can ever be in schema if you use `FieldKind.Value` here\n\t * (that would require infinite children).\n\t */\n\tpublic constructor(\n\t\tpublic readonly mapFields: TreeFieldStoredSchema,\n\t\tmetadata?: PersistedMetadataFormat | undefined,\n\t) {\n\t\tsuper(metadata);\n\t}\n\n\tpublic override encodeV1(): TreeNodeSchemaDataFormatV1 {\n\t\treturn {\n\t\t\tmap: encodeFieldSchemaV1(this.mapFields),\n\t\t};\n\t}\n\n\tpublic override encodeV2(): TreeNodeSchemaDataFormatV2 {\n\t\tconst kind = { map: encodeFieldSchemaV2(this.mapFields) };\n\t\treturn { kind, metadata: this.metadata };\n\t}\n\n\tpublic override getFieldSchema(field: FieldKey): TreeFieldStoredSchema {\n\t\treturn this.mapFields;\n\t}\n}\n\n/**\n */\nexport class LeafNodeStoredSchema extends TreeNodeStoredSchema {\n\t/**\n\t * @param leafValue -\n\t * There are several approaches for how to store actual data in the tree\n\t * (special node types, special field contents, data on nodes etc.)\n\t * as well as several options about how the data should be modeled at this level\n\t * (byte sequence? javascript type? json?),\n\t * as well as options for how much of this would be exposed in the schema language\n\t * (ex: would all nodes with values be special built-ins, or could any schema add them?)\n\t * A simple easy to do in javascript approach is taken here:\n\t * this is not intended to be a suggestion of what approach to take, or what to expose in the schema language.\n\t * This is simply one approach that can work for modeling them in the internal schema representation.\n\t */\n\tpublic constructor(public readonly leafValue: ValueSchema) {\n\t\t// No metadata for leaf nodes.\n\t\tsuper(undefined);\n\t}\n\n\tpublic override encodeV1(): TreeNodeSchemaDataFormatV1 {\n\t\treturn {\n\t\t\tleaf: encodeValueSchema(this.leafValue),\n\t\t};\n\t}\n\n\tpublic override encodeV2(): TreeNodeSchemaDataFormatV2 {\n\t\treturn {\n\t\t\t// No metadata for leaf nodes, so don't emit a metadata field.\n\t\t\tkind: {\n\t\t\t\tleaf: encodeValueSchema(this.leafValue),\n\t\t\t},\n\t\t};\n\t}\n\n\tpublic override getFieldSchema(field: FieldKey): TreeFieldStoredSchema {\n\t\treturn storedEmptyFieldSchema;\n\t}\n}\n\n/**\n * Decoder wrapper function for {@link TreeNodeStoredSchema} implementations.\n * Curries the constructor so that the caller can inject metadata.\n */\ntype StoredSchemaDecoder = (\n\tmetadata: PersistedMetadataFormat | undefined,\n) => TreeNodeStoredSchema;\n\nexport const storedSchemaDecodeDispatcher: DiscriminatedUnionDispatcher<\n\tTreeNodeSchemaUnionFormat,\n\t[],\n\tStoredSchemaDecoder\n> = new DiscriminatedUnionDispatcher({\n\tleaf: (data: PersistedValueSchema) => (metadata) =>\n\t\tnew LeafNodeStoredSchema(decodeValueSchema(data)),\n\tobject: (data: Record<TreeNodeSchemaIdentifier, FieldSchemaFormat>) => (metadata) => {\n\t\tconst map = new Map();\n\t\tfor (const [key, value] of Object.entries(data)) {\n\t\t\tmap.set(key, decodeFieldSchema(value));\n\t\t}\n\t\treturn new ObjectNodeStoredSchema(map, metadata);\n\t},\n\tmap: (data: FieldSchemaFormat) => (metadata) =>\n\t\tnew MapNodeStoredSchema(decodeFieldSchema(data), metadata),\n});\n\nconst valueSchemaEncode = new Map([\n\t[ValueSchema.Number, PersistedValueSchema.Number],\n\t[ValueSchema.String, PersistedValueSchema.String],\n\t[ValueSchema.Boolean, PersistedValueSchema.Boolean],\n\t[ValueSchema.FluidHandle, PersistedValueSchema.FluidHandle],\n\t[ValueSchema.Null, PersistedValueSchema.Null],\n]);\n\nconst valueSchemaDecode = invertMap(valueSchemaEncode);\n\nfunction encodeValueSchema(inMemory: ValueSchema): PersistedValueSchema {\n\treturn valueSchemaEncode.get(inMemory) ?? fail(0xae8 /* missing PersistedValueSchema */);\n}\n\nfunction decodeValueSchema(inMemory: PersistedValueSchema): ValueSchema {\n\treturn valueSchemaDecode.get(inMemory) ?? fail(0xae9 /* missing ValueSchema */);\n}\n\nexport function encodeFieldSchemaV1(schema: TreeFieldStoredSchema): FieldSchemaFormatV1 {\n\treturn {\n\t\tkind: schema.kind,\n\t\t// Types are sorted by identifier to improve stability of persisted data to increase chance of schema blob reuse.\n\t\ttypes: [...schema.types].sort(),\n\t};\n}\n\nexport function encodeFieldSchemaV2(schema: TreeFieldStoredSchema): FieldSchemaFormatV2 {\n\tconst fieldSchema: FieldSchemaFormatV1 = encodeFieldSchemaV1(schema);\n\n\t// Omit metadata from the output if it is undefined\n\treturn schema.persistedMetadata !== undefined\n\t\t? { ...fieldSchema, metadata: schema.persistedMetadata }\n\t\t: { ...fieldSchema };\n}\n\nexport function decodeFieldSchema(schema: FieldSchemaFormatV2): TreeFieldStoredSchema {\n\tconst out: TreeFieldStoredSchema = {\n\t\t// TODO: maybe provide actual FieldKind objects here, error on unrecognized kinds.\n\t\tkind: schema.kind,\n\t\ttypes: new Set(schema.types),\n\t\tpersistedMetadata: schema.metadata,\n\t};\n\treturn out;\n}\n\n/**\n * Document schema data that can be stored in a document.\n *\n * @remarks\n * Note: the owner of this may modify it over time:\n * thus if needing to hand onto a specific version, make a copy.\n */\nexport interface TreeStoredSchema extends StoredSchemaCollection {\n\t/**\n\t * Schema for the root field which contains the whole tree.\n\t */\n\treadonly rootFieldSchema: TreeFieldStoredSchema;\n}\n\n/**\n * Collection of TreeNodeSchema data that can be stored in a document.\n *\n * @remarks\n * Note: the owner of this may modify it over time:\n * thus if needing to hang onto a specific version, make a copy.\n */\nexport interface StoredSchemaCollection {\n\t/**\n\t * {@inheritdoc StoredSchemaCollection}\n\t */\n\treadonly nodeSchema: ReadonlyMap<TreeNodeSchemaIdentifier, TreeNodeStoredSchema>;\n}\n"]}
@@ -26,13 +26,14 @@ export declare class IdentifierToken {
26
26
  */
27
27
  export type BufferFormat<TEncodedShape> = (FluidSerializableReadOnly | Shape<TEncodedShape> | IdentifierToken | BufferFormat<TEncodedShape>)[];
28
28
  /**
29
- * Replace shapes and identifiers in buffer and any nested arrays.
29
+ * Takes already encoded content in `buffer` and deeply searches, replacing each `IdentifierToken` and `Shape`
30
+ * with references to their encodings in the returned `EncodedFieldBatchGeneric`.
30
31
  *
31
32
  * This looks inside nested arrays (including transitively) but not inside objects.
32
33
  *
33
34
  * Note that this modifies `buffer` to avoid having to copy it.
34
35
  */
35
- export declare function handleShapesAndIdentifiers<TEncodedShape>(version: number, buffer: BufferFormat<TEncodedShape>[], identifierFilter?: CounterFilter<string>): EncodedFieldBatchGeneric<TEncodedShape>;
36
+ export declare function updateShapesAndIdentifiersEncoding<TEncodedShape>(version: number, buffer: BufferFormat<TEncodedShape>[], identifierFilter?: CounterFilter<string>): EncodedFieldBatchGeneric<TEncodedShape>;
36
37
  /**
37
38
  * A tree shape.
38
39
  * This similar to a schema for a tree, though it may be more or less specific than the actual schema system used.
@@ -49,8 +50,8 @@ export declare function handleShapesAndIdentifiers<TEncodedShape>(version: numbe
49
50
  * Comparison by content would be difficult due to shape containing references to other shapes.
50
51
  *
51
52
  * @privateRemarks
52
- * Unlike with identifiers, conversion from the initial form (this class / IdentifierToken) is done by the `encodeShape` method, not by general purpose logic in `handleShapesAndIdentifiers`.
53
- * For `handleShapesAndIdentifiers` to do the conversion without help from `encodeShape`,
53
+ * Unlike with identifiers, conversion from the initial form (this class / IdentifierToken) is done by the `encodeShape` method, not by general purpose logic in `updateShapesAndIdentifiersEncoding`.
54
+ * For `updateShapesAndIdentifiersEncoding` to do the conversion without help from `encodeShape`,
54
55
  * instances of this Shape class would have to either be or output an object that is identical to the `TEncodedShape` format except with all shape references as object references instead of indexes.
55
56
  * Those objects would have to be deeply traversed looking for shape objects to replace with reference indexes.
56
57
  * This is possible, but making it type safe would involve generating derived types from the `TEncodedShape` deeply replacing any shape references, as well as requiring deep traversal of all objects in the encoded output.
@@ -58,16 +59,17 @@ export declare function handleShapesAndIdentifiers<TEncodedShape>(version: numbe
58
59
  */
59
60
  export declare abstract class Shape<TEncodedShape> {
60
61
  /**
61
- * Count this shape's contents.
62
+ * Enumerate all contents of this shape that can get replaced with references (for better compression/deduplication) during encoding.
63
+ * This currently includes shapes and identifiers.
62
64
  *
63
65
  * Used to discover referenced shapes (to ensure they are included in the `shapes` passed to `encodeShape`),
64
66
  * as well as count usages of shapes and identifiers for more efficient dictionary encoding. See {@link Counter}.
65
67
  *
66
- * @param shapes - must be invoked with each directly referenced shape (which must provided to `encodeShape`).
68
+ * @param shapeDiscovered - must be invoked with each directly referenced shape (which must be provided to `encodeShape`).
67
69
  * Can be invoked multiple times if a shape is referenced more than once for more efficient dictionary encoding.
68
70
  * Should not be invoked with `this` unless this shape references itself.
69
71
  */
70
- abstract count(identifiers: Counter<string>, shapes: (shape: Shape<TEncodedShape>) => void): void;
72
+ abstract countReferencedShapesAndIdentifiers(identifiers: Counter<string>, shapeDiscovered: (shape: Shape<TEncodedShape>) => void): void;
71
73
  /**
72
74
  * Produce the final encoded format for this shape.
73
75
  *
@@ -1 +1 @@
1
- {"version":3,"file":"chunkEncodingGeneric.d.ts","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAEzE,OAAO,EACN,OAAO,EACP,KAAK,aAAa,EAClB,KAAK,kBAAkB,EAEvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAEnE;;;;;;;;GAQG;AACH,qBAAa,eAAe;aACQ,UAAU,EAAE,MAAM;gBAAlB,UAAU,EAAE,MAAM;CACrD;AAED;;;;;GAKG;AACH,MAAM,MAAM,YAAY,CAAC,aAAa,IAAI,CACvC,yBAAyB,GACzB,KAAK,CAAC,aAAa,CAAC,GACpB,eAAe,GACf,YAAY,CAAC,aAAa,CAAC,CAC7B,EAAE,CAAC;AAEJ;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,aAAa,EACvD,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,YAAY,CAAC,aAAa,CAAC,EAAE,EACrC,gBAAgB,GAAE,aAAa,CAAC,MAAM,CAAwB,GAC5D,wBAAwB,CAAC,aAAa,CAAC,CAwEzC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,8BAAsB,KAAK,CAAC,aAAa;IACxC;;;;;;;;;OASG;aACa,KAAK,CACpB,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,EAC5B,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,KAAK,IAAI,GAC3C,IAAI;IAEP;;;;;;;OAOG;aACa,WAAW,CAC1B,WAAW,EAAE,kBAAkB,CAAC,MAAM,CAAC,EACvC,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,GAC9C,aAAa;CAChB"}
1
+ {"version":3,"file":"chunkEncodingGeneric.d.ts","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAEzE,OAAO,EACN,OAAO,EACP,KAAK,aAAa,EAClB,KAAK,kBAAkB,EAEvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAEnE;;;;;;;;GAQG;AACH,qBAAa,eAAe;aACQ,UAAU,EAAE,MAAM;gBAAlB,UAAU,EAAE,MAAM;CACrD;AAED;;;;;GAKG;AACH,MAAM,MAAM,YAAY,CAAC,aAAa,IAAI,CACvC,yBAAyB,GACzB,KAAK,CAAC,aAAa,CAAC,GACpB,eAAe,GACf,YAAY,CAAC,aAAa,CAAC,CAC7B,EAAE,CAAC;AAEJ;;;;;;;GAOG;AACH,wBAAgB,kCAAkC,CAAC,aAAa,EAC/D,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,YAAY,CAAC,aAAa,CAAC,EAAE,EACrC,gBAAgB,GAAE,aAAa,CAAC,MAAM,CAAwB,GAC5D,wBAAwB,CAAC,aAAa,CAAC,CA2EzC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,8BAAsB,KAAK,CAAC,aAAa;IACxC;;;;;;;;;;OAUG;aACa,mCAAmC,CAClD,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,EAC5B,eAAe,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,KAAK,IAAI,GACpD,IAAI;IAEP;;;;;;;OAOG;aACa,WAAW,CAC1B,WAAW,EAAE,kBAAkB,CAAC,MAAM,CAAC,EACvC,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,GAC9C,aAAa;CAChB"}
@@ -4,7 +4,7 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.Shape = exports.handleShapesAndIdentifiers = exports.IdentifierToken = void 0;
7
+ exports.Shape = exports.updateShapesAndIdentifiersEncoding = exports.IdentifierToken = void 0;
8
8
  const internal_1 = require("@fluidframework/core-utils/internal");
9
9
  const chunkCodecUtilities_js_1 = require("./chunkCodecUtilities.js");
10
10
  /**
@@ -23,13 +23,14 @@ class IdentifierToken {
23
23
  }
24
24
  exports.IdentifierToken = IdentifierToken;
25
25
  /**
26
- * Replace shapes and identifiers in buffer and any nested arrays.
26
+ * Takes already encoded content in `buffer` and deeply searches, replacing each `IdentifierToken` and `Shape`
27
+ * with references to their encodings in the returned `EncodedFieldBatchGeneric`.
27
28
  *
28
29
  * This looks inside nested arrays (including transitively) but not inside objects.
29
30
  *
30
31
  * Note that this modifies `buffer` to avoid having to copy it.
31
32
  */
32
- function handleShapesAndIdentifiers(version, buffer, identifierFilter = chunkCodecUtilities_js_1.jsonMinimizingFilter) {
33
+ function updateShapesAndIdentifiersEncoding(version, buffer, identifierFilter = chunkCodecUtilities_js_1.jsonMinimizingFilter) {
33
34
  const identifiers = new chunkCodecUtilities_js_1.Counter();
34
35
  const shapes = new chunkCodecUtilities_js_1.Counter();
35
36
  // Shapes can reference other shapes (and identifiers), so we need to traverse the shape graph.
@@ -43,6 +44,9 @@ function handleShapesAndIdentifiers(version, buffer, identifierFilter = chunkCod
43
44
  shapeToCount.push(shape);
44
45
  }
45
46
  };
47
+ // A collection of all arrays transitively reachable (via arrays) from buffer.
48
+ // These are all the arrays whose contents are searched for shapes and identifiers which are then replaced
49
+ // with references. This uses a breadth first traversal, but the actual order is not important.
46
50
  const arrays = [buffer];
47
51
  for (const array of arrays) {
48
52
  for (const item of array) {
@@ -68,9 +72,9 @@ function handleShapesAndIdentifiers(version, buffer, identifierFilter = chunkCod
68
72
  }
69
73
  // Traverse shape graph, discovering and counting all shape to shape and shape to identifier references.
70
74
  {
71
- let item;
72
- while ((item = shapeToCount.pop()) !== undefined) {
73
- item.count(identifiers, shapeDiscovered);
75
+ let shape;
76
+ while ((shape = shapeToCount.pop()) !== undefined) {
77
+ shape.countReferencedShapesAndIdentifiers(identifiers, shapeDiscovered);
74
78
  }
75
79
  }
76
80
  // Determine substitutions for identifiers and shapes:
@@ -96,7 +100,7 @@ function handleShapesAndIdentifiers(version, buffer, identifierFilter = chunkCod
96
100
  data: buffer,
97
101
  };
98
102
  }
99
- exports.handleShapesAndIdentifiers = handleShapesAndIdentifiers;
103
+ exports.updateShapesAndIdentifiersEncoding = updateShapesAndIdentifiersEncoding;
100
104
  /**
101
105
  * A tree shape.
102
106
  * This similar to a schema for a tree, though it may be more or less specific than the actual schema system used.
@@ -113,8 +117,8 @@ exports.handleShapesAndIdentifiers = handleShapesAndIdentifiers;
113
117
  * Comparison by content would be difficult due to shape containing references to other shapes.
114
118
  *
115
119
  * @privateRemarks
116
- * Unlike with identifiers, conversion from the initial form (this class / IdentifierToken) is done by the `encodeShape` method, not by general purpose logic in `handleShapesAndIdentifiers`.
117
- * For `handleShapesAndIdentifiers` to do the conversion without help from `encodeShape`,
120
+ * Unlike with identifiers, conversion from the initial form (this class / IdentifierToken) is done by the `encodeShape` method, not by general purpose logic in `updateShapesAndIdentifiersEncoding`.
121
+ * For `updateShapesAndIdentifiersEncoding` to do the conversion without help from `encodeShape`,
118
122
  * instances of this Shape class would have to either be or output an object that is identical to the `TEncodedShape` format except with all shape references as object references instead of indexes.
119
123
  * Those objects would have to be deeply traversed looking for shape objects to replace with reference indexes.
120
124
  * This is possible, but making it type safe would involve generating derived types from the `TEncodedShape` deeply replacing any shape references, as well as requiring deep traversal of all objects in the encoded output.
@@ -1 +1 @@
1
- {"version":3,"file":"chunkEncodingGeneric.js","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA2D;AAK3D,qEAKkC;AAGlC;;;;;;;;GAQG;AACH,MAAa,eAAe;IAC3B,YAAmC,UAAkB;QAAlB,eAAU,GAAV,UAAU,CAAQ;IAAG,CAAC;CACzD;AAFD,0CAEC;AAeD;;;;;;GAMG;AACH,SAAgB,0BAA0B,CACzC,OAAe,EACf,MAAqC,EACrC,mBAA0C,6CAAoB;IAE9D,MAAM,WAAW,GAAG,IAAI,gCAAO,EAAU,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAI,gCAAO,EAAwB,CAAC;IACnD,+FAA+F;IAC/F,iCAAiC;IACjC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAwB,CAAC;IACnD,MAAM,YAAY,GAA2B,EAAE,CAAC;IAChD,MAAM,eAAe,GAAG,CAAC,KAA2B,EAAQ,EAAE;QAC7D,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAClB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5B,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACtB,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC;IACF,CAAC,CAAC;IAEF,MAAM,MAAM,GAAkC,CAAC,MAAM,CAAC,CAAC;IACvD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC5B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YAC1B,IAAI,IAAI,YAAY,eAAe,EAAE,CAAC;gBACrC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAClC,CAAC;iBAAM,IAAI,IAAI,YAAY,KAAK,EAAE,CAAC;gBAClC,eAAe,CAAC,IAAI,CAAC,CAAC;YACvB,C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AY,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAA,eAAI,EAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;YACrF,CAAC;QACF,CAAC;IACF,CAAC;IAED,MAAM,aAAa,GAAG,UAAU,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAC3D,KAAK,CAAC,WAAW,CAAC,eAAe,EAAE,UAAU,CAAC,CAC9C,CAAC;IAEF,OAAO;QACN,OAAO;QACP,wDAAwD;QACxD,WAAW,EAAE,eAAe,CAAC,YAAwB;QACrD,MAAM,EAAE,aAAa;QACrB,IAAI,EAAE,MAAuB;KAC7B,CAAC;AACH,CAAC;AA5ED,gEA4EC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAsB,KAAK;CA4B1B;AA5BD,sBA4BC","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 type { TreeValue } from \"../../../core/index.js\";\nimport type { FluidSerializableReadOnly } from \"../../valueUtilities.js\";\n\nimport {\n\tCounter,\n\ttype CounterFilter,\n\ttype DeduplicationTable,\n\tjsonMinimizingFilter,\n} from \"./chunkCodecUtilities.js\";\nimport type { EncodedFieldBatchGeneric } from \"./formatGeneric.js\";\n\n/**\n * An identifier which can be compressed using {@link Counter}.\n *\n * @remarks\n * Compression of Identifiers is done after the output is otherwise generated to enable counting all the usages.\n * To avoid having to decode the decode the data array to determine which data is an identifier and which is some other string,\n * some recognizable representation is required.\n * Using a class and checking its prototype works for this, and is why IdentifierToken is a class.\n */\nexport class IdentifierToken {\n\tpublic constructor(public readonly identifier: string) {}\n}\n\n/**\n * Format for data emitted during encoding, before dictionary compression of identifiers.\n *\n * @remarks\n * These buffers are mutated after construction if they contain identifiers or shapes.\n */\nexport type BufferFormat<TEncodedShape> = (\n\t| FluidSerializableReadOnly\n\t| Shape<TEncodedShape>\n\t| IdentifierToken\n\t| BufferFormat<TEncodedShape>\n)[];\n\n/**\n * Replace shapes and identifiers in buffer and any nested arrays.\n *\n * This looks inside nested arrays (including transitively) but not inside objects.\n *\n * Note that this modifies `buffer` to avoid having to copy it.\n */\nexport function handleShapesAndIdentifiers<TEncodedShape>(\n\tversion: number,\n\tbuffer: BufferFormat<TEncodedShape>[],\n\tidentifierFilter: CounterFilter<string> = jsonMinimizingFilter,\n): EncodedFieldBatchGeneric<TEncodedShape> {\n\tconst identifiers = new Counter<string>();\n\tconst shapes = new Counter<Shape<TEncodedShape>>();\n\t// Shapes can reference other shapes (and identifiers), so we need to traverse the shape graph.\n\t// These collections enable that.\n\tconst shapesSeen = new Set<Shape<TEncodedShape>>();\n\tconst shapeToCount: Shape<TEncodedShape>[] = [];\n\tconst shapeDiscovered = (shape: Shape<TEncodedShape>): void => {\n\t\tshapes.add(shape);\n\t\tif (!shapesSeen.has(shape)) {\n\t\t\tshapesSeen.add(shape);\n\t\t\tshapeToCount.push(shape);\n\t\t}\n\t};\n\n\tconst arrays: BufferFormat<TEncodedShape>[] = [buffer];\n\tfor (const array of arrays) {\n\t\tfor (const item of array) {\n\t\t\tif (item instanceof IdentifierToken) {\n\t\t\t\tidentifiers.add(item.identifier);\n\t\t\t} else if (item instanceof Shape) {\n\t\t\t\tshapeDiscovered(item);\n\t\t\t} else if (Array.isArray(item)) {\n\t\t\t\t// In JS it is legal to push items to an array which is being iterated,\n\t\t\t\t// and they will be visited in order.\n\t\t\t\tarrays.push(item);\n\t\t\t} else if (\n\t\t\t\titem !== null &&\n\t\t\t\ttypeof item === \"object\" &&\n\t\t\t\t(item as Record<string, unknown>).shape instanceof Shape\n\t\t\t) {\n\t\t\t\t// because \"serializable\" is allowed in buffer and it has type `any`, its very easy to mess up including of shapes in the buffer.\n\t\t\t\t// This catches the easiest way to get it wrong.\n\t\t\t\tfail(0xb4b /* encoder interface instead of shape written to stream */);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Traverse shape graph, discovering and counting all shape to shape and shape to identifier references.\n\t{\n\t\tlet item: Shape<TEncodedShape> | undefined;\n\t\twhile ((item = shapeToCount.pop()) !== undefined) {\n\t\t\titem.count(identifiers, shapeDiscovered);\n\t\t}\n\t}\n\n\t// Determine substitutions for identifiers and shapes:\n\tconst identifierTable = identifiers.buildTable(identifierFilter);\n\tconst shapeTable = shapes.buildTable();\n\n\tfor (const array of arrays) {\n\t\tfor (let index = 0; index < array.length; index++) {\n\t\t\tconst item = array[index];\n\t\t\tif (item instanceof IdentifierToken) {\n\t\t\t\tarray[index] = identifierTable.valueToIndex.get(item.identifier) ?? item.identifier;\n\t\t\t} else if (item instanceof Shape) {\n\t\t\t\tarray[index] = shapeTable.valueToIndex.get(item) ?? fail(0xb4c /* missing shape */);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst encodedShapes = shapeTable.indexToValue.map((shape) =>\n\t\tshape.encodeShape(identifierTable, shapeTable),\n\t);\n\n\treturn {\n\t\tversion,\n\t\t// TODO: fix readonly typing issues to remove this cast.\n\t\tidentifiers: identifierTable.indexToValue as string[],\n\t\tshapes: encodedShapes,\n\t\tdata: buffer as TreeValue[][],\n\t};\n}\n\n/**\n * A tree shape.\n * This similar to a schema for a tree, though it may be more or less specific than the actual schema system used.\n * Can be encoded into a `TEncodedShape`: when doing so encodes references to shapes (if needed) using {@link Counter}:\n * this can include recursive references (direct or indirect).\n *\n * @remarks\n * Deduplication of shapes is done after the output is otherwise generated (including identifier dictionary encoding).\n * To avoid having to decode the data array to determine which data is a shape and which is some other object,\n * some recognizable representation is required.\n * Using a class and checking its prototype works for this, and is why Shape is a class.\n *\n * Note that deduplication compares shapes by object identity not by content, so encoders must ensure shapes are not duplicated to achieve efficient encoding.\n * Comparison by content would be difficult due to shape containing references to other shapes.\n *\n * @privateRemarks\n * Unlike with identifiers, conversion from the initial form (this class / IdentifierToken) is done by the `encodeShape` method, not by general purpose logic in `handleShapesAndIdentifiers`.\n * For `handleShapesAndIdentifiers` to do the conversion without help from `encodeShape`,\n * instances of this Shape class would have to either be or output an object that is identical to the `TEncodedShape` format except with all shape references as object references instead of indexes.\n * Those objects would have to be deeply traversed looking for shape objects to replace with reference indexes.\n * This is possible, but making it type safe would involve generating derived types from the `TEncodedShape` deeply replacing any shape references, as well as requiring deep traversal of all objects in the encoded output.\n * Such an approach seemed less maintainable and readable than the design taken here which avoids the need for those derived types.\n */\nexport abstract class Shape<TEncodedShape> {\n\t/**\n\t * Count this shape's contents.\n\t *\n\t * Used to discover referenced shapes (to ensure they are included in the `shapes` passed to `encodeShape`),\n\t * as well as count usages of shapes and identifiers for more efficient dictionary encoding. See {@link Counter}.\n\t *\n\t * @param shapes - must be invoked with each directly referenced shape (which must provided to `encodeShape`).\n\t * Can be invoked multiple times if a shape is referenced more than once for more efficient dictionary encoding.\n\t * Should not be invoked with `this` unless this shape references itself.\n\t */\n\tpublic abstract count(\n\t\tidentifiers: Counter<string>,\n\t\tshapes: (shape: Shape<TEncodedShape>) => void,\n\t): void;\n\n\t/**\n\t * Produce the final encoded format for this shape.\n\t *\n\t * @param identifiers - a subset of identifiers used in this tree, and their corresponding indexes to use for the dictionary encoding.\n\t * Can be used to encode identifiers referenced by this shape.\n\t * @param shapes - includes a superset of shapes reported by count.\n\t * Used to encode references to shapes as numbers.\n\t */\n\tpublic abstract encodeShape(\n\t\tidentifiers: DeduplicationTable<string>,\n\t\tshapes: DeduplicationTable<Shape<TEncodedShape>>,\n\t): TEncodedShape;\n}\n"]}
1
+ {"version":3,"file":"chunkEncodingGeneric.js","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA2D;AAK3D,qEAKkC;AAGlC;;;;;;;;GAQG;AACH,MAAa,eAAe;IAC3B,YAAmC,UAAkB;QAAlB,eAAU,GAAV,UAAU,CAAQ;IAAG,CAAC;CACzD;AAFD,0CAEC;AAeD;;;;;;;GAOG;AACH,SAAgB,kCAAkC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AC;IAEF,OAAO;QACN,OAAO;QACP,wDAAwD;QACxD,WAAW,EAAE,eAAe,CAAC,YAAwB;QACrD,MAAM,EAAE,aAAa;QACrB,IAAI,EAAE,MAAuB;KAC7B,CAAC;AACH,CAAC;AA/ED,gFA+EC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAsB,KAAK;CA6B1B;AA7BD,sBA6BC","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 type { TreeValue } from \"../../../core/index.js\";\nimport type { FluidSerializableReadOnly } from \"../../valueUtilities.js\";\n\nimport {\n\tCounter,\n\ttype CounterFilter,\n\ttype DeduplicationTable,\n\tjsonMinimizingFilter,\n} from \"./chunkCodecUtilities.js\";\nimport type { EncodedFieldBatchGeneric } from \"./formatGeneric.js\";\n\n/**\n * An identifier which can be compressed using {@link Counter}.\n *\n * @remarks\n * Compression of Identifiers is done after the output is otherwise generated to enable counting all the usages.\n * To avoid having to decode the decode the data array to determine which data is an identifier and which is some other string,\n * some recognizable representation is required.\n * Using a class and checking its prototype works for this, and is why IdentifierToken is a class.\n */\nexport class IdentifierToken {\n\tpublic constructor(public readonly identifier: string) {}\n}\n\n/**\n * Format for data emitted during encoding, before dictionary compression of identifiers.\n *\n * @remarks\n * These buffers are mutated after construction if they contain identifiers or shapes.\n */\nexport type BufferFormat<TEncodedShape> = (\n\t| FluidSerializableReadOnly\n\t| Shape<TEncodedShape>\n\t| IdentifierToken\n\t| BufferFormat<TEncodedShape>\n)[];\n\n/**\n * Takes already encoded content in `buffer` and deeply searches, replacing each `IdentifierToken` and `Shape`\n * with references to their encodings in the returned `EncodedFieldBatchGeneric`.\n *\n * This looks inside nested arrays (including transitively) but not inside objects.\n *\n * Note that this modifies `buffer` to avoid having to copy it.\n */\nexport function updateShapesAndIdentifiersEncoding<TEncodedShape>(\n\tversion: number,\n\tbuffer: BufferFormat<TEncodedShape>[],\n\tidentifierFilter: CounterFilter<string> = jsonMinimizingFilter,\n): EncodedFieldBatchGeneric<TEncodedShape> {\n\tconst identifiers = new Counter<string>();\n\tconst shapes = new Counter<Shape<TEncodedShape>>();\n\t// Shapes can reference other shapes (and identifiers), so we need to traverse the shape graph.\n\t// These collections enable that.\n\tconst shapesSeen = new Set<Shape<TEncodedShape>>();\n\tconst shapeToCount: Shape<TEncodedShape>[] = [];\n\tconst shapeDiscovered = (shape: Shape<TEncodedShape>): void => {\n\t\tshapes.add(shape);\n\t\tif (!shapesSeen.has(shape)) {\n\t\t\tshapesSeen.add(shape);\n\t\t\tshapeToCount.push(shape);\n\t\t}\n\t};\n\n\t// A collection of all arrays transitively reachable (via arrays) from buffer.\n\t// These are all the arrays whose contents are searched for shapes and identifiers which are then replaced\n\t// with references. This uses a breadth first traversal, but the actual order is not important.\n\tconst arrays: BufferFormat<TEncodedShape>[] = [buffer];\n\tfor (const array of arrays) {\n\t\tfor (const item of array) {\n\t\t\tif (item instanceof IdentifierToken) {\n\t\t\t\tidentifiers.add(item.identifier);\n\t\t\t} else if (item instanceof Shape) {\n\t\t\t\tshapeDiscovered(item);\n\t\t\t} else if (Array.isArray(item)) {\n\t\t\t\t// In JS it is legal to push items to an array which is being iterated,\n\t\t\t\t// and they will be visited in order.\n\t\t\t\tarrays.push(item);\n\t\t\t} else if (\n\t\t\t\titem !== null &&\n\t\t\t\ttypeof item === \"object\" &&\n\t\t\t\t(item as Record<string, unknown>).shape instanceof Shape\n\t\t\t) {\n\t\t\t\t// because \"serializable\" is allowed in buffer and it has type `any`, its very easy to mess up including of shapes in the buffer.\n\t\t\t\t// This catches the easiest way to get it wrong.\n\t\t\t\tfail(0xb4b /* encoder interface instead of shape written to stream */);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Traverse shape graph, discovering and counting all shape to shape and shape to identifier references.\n\t{\n\t\tlet shape: Shape<TEncodedShape> | undefined;\n\t\twhile ((shape = shapeToCount.pop()) !== undefined) {\n\t\t\tshape.countReferencedShapesAndIdentifiers(identifiers, shapeDiscovered);\n\t\t}\n\t}\n\n\t// Determine substitutions for identifiers and shapes:\n\tconst identifierTable = identifiers.buildTable(identifierFilter);\n\tconst shapeTable = shapes.buildTable();\n\n\tfor (const array of arrays) {\n\t\tfor (let index = 0; index < array.length; index++) {\n\t\t\tconst item = array[index];\n\t\t\tif (item instanceof IdentifierToken) {\n\t\t\t\tarray[index] = identifierTable.valueToIndex.get(item.identifier) ?? item.identifier;\n\t\t\t} else if (item instanceof Shape) {\n\t\t\t\tarray[index] = shapeTable.valueToIndex.get(item) ?? fail(0xb4c /* missing shape */);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst encodedShapes = shapeTable.indexToValue.map((shape) =>\n\t\tshape.encodeShape(identifierTable, shapeTable),\n\t);\n\n\treturn {\n\t\tversion,\n\t\t// TODO: fix readonly typing issues to remove this cast.\n\t\tidentifiers: identifierTable.indexToValue as string[],\n\t\tshapes: encodedShapes,\n\t\tdata: buffer as TreeValue[][],\n\t};\n}\n\n/**\n * A tree shape.\n * This similar to a schema for a tree, though it may be more or less specific than the actual schema system used.\n * Can be encoded into a `TEncodedShape`: when doing so encodes references to shapes (if needed) using {@link Counter}:\n * this can include recursive references (direct or indirect).\n *\n * @remarks\n * Deduplication of shapes is done after the output is otherwise generated (including identifier dictionary encoding).\n * To avoid having to decode the data array to determine which data is a shape and which is some other object,\n * some recognizable representation is required.\n * Using a class and checking its prototype works for this, and is why Shape is a class.\n *\n * Note that deduplication compares shapes by object identity not by content, so encoders must ensure shapes are not duplicated to achieve efficient encoding.\n * Comparison by content would be difficult due to shape containing references to other shapes.\n *\n * @privateRemarks\n * Unlike with identifiers, conversion from the initial form (this class / IdentifierToken) is done by the `encodeShape` method, not by general purpose logic in `updateShapesAndIdentifiersEncoding`.\n * For `updateShapesAndIdentifiersEncoding` to do the conversion without help from `encodeShape`,\n * instances of this Shape class would have to either be or output an object that is identical to the `TEncodedShape` format except with all shape references as object references instead of indexes.\n * Those objects would have to be deeply traversed looking for shape objects to replace with reference indexes.\n * This is possible, but making it type safe would involve generating derived types from the `TEncodedShape` deeply replacing any shape references, as well as requiring deep traversal of all objects in the encoded output.\n * Such an approach seemed less maintainable and readable than the design taken here which avoids the need for those derived types.\n */\nexport abstract class Shape<TEncodedShape> {\n\t/**\n\t * Enumerate all contents of this shape that can get replaced with references (for better compression/deduplication) during encoding.\n\t * This currently includes shapes and identifiers.\n\t *\n\t * Used to discover referenced shapes (to ensure they are included in the `shapes` passed to `encodeShape`),\n\t * as well as count usages of shapes and identifiers for more efficient dictionary encoding. See {@link Counter}.\n\t *\n\t * @param shapeDiscovered - must be invoked with each directly referenced shape (which must be provided to `encodeShape`).\n\t * Can be invoked multiple times if a shape is referenced more than once for more efficient dictionary encoding.\n\t * Should not be invoked with `this` unless this shape references itself.\n\t */\n\tpublic abstract countReferencedShapesAndIdentifiers(\n\t\tidentifiers: Counter<string>,\n\t\tshapeDiscovered: (shape: Shape<TEncodedShape>) => void,\n\t): void;\n\n\t/**\n\t * Produce the final encoded format for this shape.\n\t *\n\t * @param identifiers - a subset of identifiers used in this tree, and their corresponding indexes to use for the dictionary encoding.\n\t * Can be used to encode identifiers referenced by this shape.\n\t * @param shapes - includes a superset of shapes reported by count.\n\t * Used to encode references to shapes as numbers.\n\t */\n\tpublic abstract encodeShape(\n\t\tidentifiers: DeduplicationTable<string>,\n\t\tshapes: DeduplicationTable<Shape<TEncodedShape>>,\n\t): TEncodedShape;\n}\n"]}
@@ -81,7 +81,7 @@ export declare class AnyShape extends ShapeGeneric<EncodedChunkShape> {
81
81
  private constructor();
82
82
  static readonly instance: AnyShape;
83
83
  encodeShape(identifiers: DeduplicationTable<string>, shapes: DeduplicationTable<Shape>): EncodedChunkShape;
84
- count(identifiers: Counter<string>, shapes: (shape: Shape) => void): void;
84
+ countReferencedShapesAndIdentifiers(identifiers: Counter<string>, shapeDiscovered: (shape: Shape) => void): void;
85
85
  static encodeField(cursor: ITreeCursorSynchronous, cache: EncoderCache, outputBuffer: BufferFormat, shape: FieldEncoder): void;
86
86
  static encodeNode(cursor: ITreeCursorSynchronous, cache: EncoderCache, outputBuffer: BufferFormat, shape: NodeEncoder): void;
87
87
  static encodeNodes(cursor: ITreeCursorSynchronous, cache: EncoderCache, outputBuffer: BufferFormat, shape: NodesEncoder): void;
@@ -108,7 +108,7 @@ export declare class InlineArrayShape extends ShapeGeneric<EncodedChunkShape> im
108
108
  encodeNodes(cursor: ITreeCursorSynchronous, shapes: EncoderCache, outputBuffer: BufferFormat): void;
109
109
  encodeField(cursor: ITreeCursorSynchronous, shapes: EncoderCache, outputBuffer: BufferFormat): void;
110
110
  encodeShape(identifiers: DeduplicationTable<string>, shapes: DeduplicationTable<Shape>): EncodedChunkShape;
111
- count(identifiers: Counter<string>, shapes: (shape: Shape) => void): void;
111
+ countReferencedShapesAndIdentifiers(identifiers: Counter<string>, shapeDiscovered: (shape: Shape) => void): void;
112
112
  get shape(): this;
113
113
  }
114
114
  /**
@@ -120,7 +120,7 @@ export declare class NestedArrayShape extends ShapeGeneric<EncodedChunkShape> im
120
120
  constructor(inner: NodeEncoder);
121
121
  encodeField(cursor: ITreeCursorSynchronous, cache: EncoderCache, outputBuffer: BufferFormat): void;
122
122
  encodeShape(identifiers: DeduplicationTable<string>, shapes: DeduplicationTable<Shape>): EncodedChunkShape;
123
- count(identifiers: Counter<string>, shapes: (shape: Shape) => void): void;
123
+ countReferencedShapesAndIdentifiers(identifiers: Counter<string>, shapeDiscovered: (shape: Shape) => void): void;
124
124
  }
125
125
  /**
126
126
  * Encode `value` with `shape` into `outputBuffer`.
@@ -1 +1 @@
1
- {"version":3,"file":"compressedEncode.d.ts","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/compressedEncode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EAEN,KAAK,QAAQ,EACb,KAAK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IAAI;CAGhF;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAC1B,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,iBAAiB,EACxB,YAAY,EAAE,YAAY,GACxB,IAAI,CAwBN;AAED,qBAAa,YAAa,YAAW,UAAU,EAAE,WAAW;IAI1D,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,YAAY;aACb,WAAW,EAAE,WAAW,CAAC,mBAAmB,EAAE,aAAa,CAAC;aAC5D,YAAY,EAAE,aAAa;IAN5C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAyD;IAC1F,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAiD;gBAE5D,WAAW,EAAE,eAAe,EAC5B,YAAY,EAAE,gBAAgB,EAC/B,WAAW,EAAE,WAAW,CAAC,mBAAmB,EAAE,aAAa,CAAC,EAC5D,YAAY,EAAE,aAAa;IAGrC,aAAa,CAAC,UAAU,EAAE,wBAAwB,GAAG,WAAW;IAMhE,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,gBAAgB;IAIjD,cAAc,CAAC,KAAK,EAAE,qBAAqB,GAAG,YAAY;CAGjE;AAED,MAAM,WAAW,UAAU;IAC1B,aAAa,CAAC,UAAU,EAAE,wBAAwB,GAAG,WAAW,CAAC;CACjE;AAED,MAAM,WAAW,WAAW;IAC3B,cAAc,CAAC,KAAK,EAAE,qBAAqB,GAAG,YAAY,CAAC;CAC3D;AAED,MAAM,MAAM,gBAAgB,GAAG,CAC9B,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,qBAAqB,KACxB,YAAY,CAAC;AAElB,MAAM,MAAM,eAAe,GAAG,CAC7B,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,wBAAwB,KAChC,WAAW,CAAC"}
1
+ {"version":3,"file":"compressedEncode.d.ts","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/compressedEncode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAG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@@ function compressedEncode(fieldBatch, cache) {
25
25
  exports.anyFieldEncoder.encodeField(cursor, cache, buffer);
26
26
  batchBuffer.push(buffer);
27
27
  }
28
- return (0, chunkEncodingGeneric_js_1.handleShapesAndIdentifiers)(format_js_1.version, batchBuffer);
28
+ return (0, chunkEncodingGeneric_js_1.updateShapesAndIdentifiersEncoding)(format_js_1.version, batchBuffer);
29
29
  }
30
30
  exports.compressedEncode = compressedEncode;
31
31
  /**
@@ -65,7 +65,7 @@ class AnyShape extends chunkEncodingGeneric_js_1.Shape {
65
65
  const encodedAnyShape = 0;
66
66
  return { d: encodedAnyShape };
67
67
  }
68
- count(identifiers, shapes) { }
68
+ countReferencedShapesAndIdentifiers(identifiers, shapeDiscovered) { }
69
69
  static encodeField(cursor, cache, outputBuffer, shape) {
70
70
  outputBuffer.push(shape.shape);
71
71
  shape.encodeField(cursor, cache, outputBuffer);
@@ -151,8 +151,8 @@ class InlineArrayShape extends chunkEncodingGeneric_js_1.Shape {
151
151
  },
152
152
  };
153
153
  }
154
- count(identifiers, shapes) {
155
- shapes(this.inner.shape);
154
+ countReferencedShapesAndIdentifiers(identifiers, shapeDiscovered) {
155
+ shapeDiscovered(this.inner.shape);
156
156
  }
157
157
  get shape() {
158
158
  return this;
@@ -203,8 +203,8 @@ class NestedArrayShape extends chunkEncodingGeneric_js_1.Shape {
203
203
  a: shape,
204
204
  };
205
205
  }
206
- count(identifiers, shapes) {
207
- shapes(this.inner.shape);
206
+ countReferencedShapesAndIdentifiers(identifiers, shapeDiscovered) {
207
+ shapeDiscovered(this.inner.shape);
208
208
  }
209
209
  }
210
210
  exports.NestedArrayShape = NestedArrayShape;