@fluidframework/tree 2.22.1 → 2.23.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 (427) hide show
  1. package/.vscode/extensions.json +1 -0
  2. package/CHANGELOG.md +47 -0
  3. package/api-report/tree.alpha.api.md +31 -0
  4. package/dist/alpha.d.ts +1 -0
  5. package/dist/codec/codec.js +3 -3
  6. package/dist/codec/codec.js.map +1 -1
  7. package/dist/codec/discriminatedUnions.d.ts.map +1 -1
  8. package/dist/codec/discriminatedUnions.js +1 -1
  9. package/dist/codec/discriminatedUnions.js.map +1 -1
  10. package/dist/core/schema-stored/schema.d.ts.map +1 -1
  11. package/dist/core/schema-stored/schema.js +3 -3
  12. package/dist/core/schema-stored/schema.js.map +1 -1
  13. package/dist/core/tree/anchorSet.d.ts.map +1 -1
  14. package/dist/core/tree/anchorSet.js +18 -13
  15. package/dist/core/tree/anchorSet.js.map +1 -1
  16. package/dist/core/tree/treeTextFormat.js +1 -1
  17. package/dist/core/tree/treeTextFormat.js.map +1 -1
  18. package/dist/feature-libraries/chunked-forest/basicChunk.d.ts.map +1 -1
  19. package/dist/feature-libraries/chunked-forest/basicChunk.js +11 -8
  20. package/dist/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  21. package/dist/feature-libraries/chunked-forest/chunkTree.js +2 -2
  22. package/dist/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  23. package/dist/feature-libraries/chunked-forest/chunkedForest.js +3 -3
  24. package/dist/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  25. package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js +2 -2
  26. package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js.map +1 -1
  27. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
  28. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js +4 -3
  29. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  30. package/dist/feature-libraries/chunked-forest/codec/nodeShape.js +2 -2
  31. package/dist/feature-libraries/chunked-forest/codec/nodeShape.js.map +1 -1
  32. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncoding.d.ts.map +1 -1
  33. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncoding.js +3 -3
  34. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncoding.js.map +1 -1
  35. package/dist/feature-libraries/chunked-forest/emptyChunk.js +14 -14
  36. package/dist/feature-libraries/chunked-forest/emptyChunk.js.map +1 -1
  37. package/dist/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  38. package/dist/feature-libraries/chunked-forest/uniformChunk.js +6 -4
  39. package/dist/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  40. package/dist/feature-libraries/default-schema/defaultFieldKinds.js +1 -1
  41. package/dist/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  42. package/dist/feature-libraries/default-schema/schemaChecker.js +1 -1
  43. package/dist/feature-libraries/default-schema/schemaChecker.js.map +1 -1
  44. package/dist/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  45. package/dist/feature-libraries/flex-tree/lazyField.js +4 -3
  46. package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
  47. package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  48. package/dist/feature-libraries/flex-tree/lazyNode.js +5 -4
  49. package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  50. package/dist/feature-libraries/indexing/anchorTreeIndex.d.ts.map +1 -1
  51. package/dist/feature-libraries/indexing/anchorTreeIndex.js +1 -1
  52. package/dist/feature-libraries/indexing/anchorTreeIndex.js.map +1 -1
  53. package/dist/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
  54. package/dist/feature-libraries/modular-schema/comparison.js +6 -4
  55. package/dist/feature-libraries/modular-schema/comparison.js.map +1 -1
  56. package/dist/feature-libraries/modular-schema/isNeverTree.d.ts.map +1 -1
  57. package/dist/feature-libraries/modular-schema/isNeverTree.js +4 -4
  58. package/dist/feature-libraries/modular-schema/isNeverTree.js.map +1 -1
  59. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +4 -4
  60. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  61. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  62. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +10 -11
  63. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  64. package/dist/feature-libraries/node-key/mockNodeKeyManager.js +1 -1
  65. package/dist/feature-libraries/node-key/mockNodeKeyManager.js.map +1 -1
  66. package/dist/feature-libraries/object-forest/objectForest.js +1 -1
  67. package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
  68. package/dist/feature-libraries/schema-index/codec.js +1 -1
  69. package/dist/feature-libraries/schema-index/codec.js.map +1 -1
  70. package/dist/feature-libraries/sequence-field/compose.js +1 -1
  71. package/dist/feature-libraries/sequence-field/compose.js.map +1 -1
  72. package/dist/feature-libraries/sequence-field/invert.js +1 -1
  73. package/dist/feature-libraries/sequence-field/invert.js.map +1 -1
  74. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV1.js +1 -1
  75. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV1.js.map +1 -1
  76. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js +1 -1
  77. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  78. package/dist/feature-libraries/sequence-field/utils.js +1 -1
  79. package/dist/feature-libraries/sequence-field/utils.js.map +1 -1
  80. package/dist/feature-libraries/treeCursorUtils.d.ts.map +1 -1
  81. package/dist/feature-libraries/treeCursorUtils.js +6 -4
  82. package/dist/feature-libraries/treeCursorUtils.js.map +1 -1
  83. package/dist/index.d.ts +3 -1
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +5 -1
  86. package/dist/index.js.map +1 -1
  87. package/dist/jsonDomainSchema.d.ts +113 -0
  88. package/dist/jsonDomainSchema.d.ts.map +1 -0
  89. package/dist/jsonDomainSchema.js +101 -0
  90. package/dist/jsonDomainSchema.js.map +1 -0
  91. package/dist/packageVersion.d.ts +1 -1
  92. package/dist/packageVersion.js +1 -1
  93. package/dist/packageVersion.js.map +1 -1
  94. package/dist/serializableDomainSchema.d.ts +108 -0
  95. package/dist/serializableDomainSchema.d.ts.map +1 -0
  96. package/dist/serializableDomainSchema.js +90 -0
  97. package/dist/serializableDomainSchema.js.map +1 -0
  98. package/dist/shared-tree/index.d.ts +1 -1
  99. package/dist/shared-tree/index.d.ts.map +1 -1
  100. package/dist/shared-tree/index.js.map +1 -1
  101. package/dist/shared-tree/schematizeTree.js +1 -1
  102. package/dist/shared-tree/schematizeTree.js.map +1 -1
  103. package/dist/shared-tree/sharedTree.d.ts +37 -20
  104. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  105. package/dist/shared-tree/sharedTree.js +17 -17
  106. package/dist/shared-tree/sharedTree.js.map +1 -1
  107. package/dist/shared-tree/sharedTreeChangeFamily.js +1 -1
  108. package/dist/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  109. package/dist/shared-tree/treeApiAlpha.d.ts.map +1 -1
  110. package/dist/shared-tree/treeApiAlpha.js +4 -4
  111. package/dist/shared-tree/treeApiAlpha.js.map +1 -1
  112. package/dist/shared-tree/treeCheckout.js +1 -1
  113. package/dist/shared-tree/treeCheckout.js.map +1 -1
  114. package/dist/shared-tree-core/editManager.d.ts +11 -2
  115. package/dist/shared-tree-core/editManager.d.ts.map +1 -1
  116. package/dist/shared-tree-core/editManager.js +70 -34
  117. package/dist/shared-tree-core/editManager.js.map +1 -1
  118. package/dist/shared-tree-core/resubmitMachine.d.ts +2 -0
  119. package/dist/shared-tree-core/resubmitMachine.d.ts.map +1 -1
  120. package/dist/shared-tree-core/resubmitMachine.js.map +1 -1
  121. package/dist/shared-tree-core/sharedTreeCore.d.ts +10 -3
  122. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  123. package/dist/shared-tree-core/sharedTreeCore.js +42 -7
  124. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  125. package/dist/simple-tree/api/customTree.js +3 -3
  126. package/dist/simple-tree/api/customTree.js.map +1 -1
  127. package/dist/simple-tree/api/schemaCreationUtilities.js +1 -1
  128. package/dist/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  129. package/dist/simple-tree/api/schemaFactoryRecursive.d.ts +1 -1
  130. package/dist/simple-tree/api/schemaFactoryRecursive.js.map +1 -1
  131. package/dist/simple-tree/api/simpleTreeIndex.js +3 -3
  132. package/dist/simple-tree/api/simpleTreeIndex.js.map +1 -1
  133. package/dist/simple-tree/api/tree.js +1 -1
  134. package/dist/simple-tree/api/tree.js.map +1 -1
  135. package/dist/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  136. package/dist/simple-tree/api/treeNodeApi.js +9 -5
  137. package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
  138. package/dist/simple-tree/api/verboseTree.d.ts.map +1 -1
  139. package/dist/simple-tree/api/verboseTree.js +5 -4
  140. package/dist/simple-tree/api/verboseTree.js.map +1 -1
  141. package/dist/simple-tree/api/view.js +1 -1
  142. package/dist/simple-tree/api/view.js.map +1 -1
  143. package/dist/simple-tree/arrayNode.js +2 -2
  144. package/dist/simple-tree/arrayNode.js.map +1 -1
  145. package/dist/simple-tree/core/getOrCreateNode.d.ts.map +1 -1
  146. package/dist/simple-tree/core/getOrCreateNode.js +1 -1
  147. package/dist/simple-tree/core/getOrCreateNode.js.map +1 -1
  148. package/dist/simple-tree/core/schemaCaching.js +1 -1
  149. package/dist/simple-tree/core/schemaCaching.js.map +1 -1
  150. package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  151. package/dist/simple-tree/core/treeNodeKernel.js +6 -6
  152. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  153. package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  154. package/dist/simple-tree/core/unhydratedFlexTree.js +5 -5
  155. package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  156. package/dist/simple-tree/objectNode.js +2 -2
  157. package/dist/simple-tree/objectNode.js.map +1 -1
  158. package/dist/simple-tree/proxies.js +1 -1
  159. package/dist/simple-tree/proxies.js.map +1 -1
  160. package/dist/simple-tree/toMapTree.js +3 -3
  161. package/dist/simple-tree/toMapTree.js.map +1 -1
  162. package/dist/simple-tree/toStoredSchema.d.ts.map +1 -1
  163. package/dist/simple-tree/toStoredSchema.js +2 -1
  164. package/dist/simple-tree/toStoredSchema.js.map +1 -1
  165. package/dist/simple-tree/treeNodeValid.d.ts.map +1 -1
  166. package/dist/simple-tree/treeNodeValid.js +5 -2
  167. package/dist/simple-tree/treeNodeValid.js.map +1 -1
  168. package/dist/util/idAllocator.js +1 -1
  169. package/dist/util/idAllocator.js.map +1 -1
  170. package/dist/util/index.d.ts +2 -2
  171. package/dist/util/index.d.ts.map +1 -1
  172. package/dist/util/index.js +5 -4
  173. package/dist/util/index.js.map +1 -1
  174. package/dist/util/nestedMap.d.ts +2 -10
  175. package/dist/util/nestedMap.d.ts.map +1 -1
  176. package/dist/util/nestedMap.js +9 -28
  177. package/dist/util/nestedMap.js.map +1 -1
  178. package/dist/util/utils.d.ts +23 -6
  179. package/dist/util/utils.d.ts.map +1 -1
  180. package/dist/util/utils.js +46 -13
  181. package/dist/util/utils.js.map +1 -1
  182. package/lib/alpha.d.ts +1 -0
  183. package/lib/codec/codec.js +3 -3
  184. package/lib/codec/codec.js.map +1 -1
  185. package/lib/codec/discriminatedUnions.d.ts.map +1 -1
  186. package/lib/codec/discriminatedUnions.js +1 -1
  187. package/lib/codec/discriminatedUnions.js.map +1 -1
  188. package/lib/core/schema-stored/schema.d.ts.map +1 -1
  189. package/lib/core/schema-stored/schema.js +3 -3
  190. package/lib/core/schema-stored/schema.js.map +1 -1
  191. package/lib/core/tree/anchorSet.d.ts.map +1 -1
  192. package/lib/core/tree/anchorSet.js +19 -14
  193. package/lib/core/tree/anchorSet.js.map +1 -1
  194. package/lib/core/tree/treeTextFormat.js +1 -1
  195. package/lib/core/tree/treeTextFormat.js.map +1 -1
  196. package/lib/feature-libraries/chunked-forest/basicChunk.d.ts.map +1 -1
  197. package/lib/feature-libraries/chunked-forest/basicChunk.js +11 -8
  198. package/lib/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  199. package/lib/feature-libraries/chunked-forest/chunkTree.js +2 -2
  200. package/lib/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  201. package/lib/feature-libraries/chunked-forest/chunkedForest.js +3 -3
  202. package/lib/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  203. package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js +2 -2
  204. package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js.map +1 -1
  205. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
  206. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js +4 -3
  207. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  208. package/lib/feature-libraries/chunked-forest/codec/nodeShape.js +2 -2
  209. package/lib/feature-libraries/chunked-forest/codec/nodeShape.js.map +1 -1
  210. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncoding.d.ts.map +1 -1
  211. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncoding.js +3 -3
  212. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncoding.js.map +1 -1
  213. package/lib/feature-libraries/chunked-forest/emptyChunk.js +14 -14
  214. package/lib/feature-libraries/chunked-forest/emptyChunk.js.map +1 -1
  215. package/lib/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  216. package/lib/feature-libraries/chunked-forest/uniformChunk.js +6 -4
  217. package/lib/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  218. package/lib/feature-libraries/default-schema/defaultFieldKinds.js +1 -1
  219. package/lib/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  220. package/lib/feature-libraries/default-schema/schemaChecker.js +1 -1
  221. package/lib/feature-libraries/default-schema/schemaChecker.js.map +1 -1
  222. package/lib/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  223. package/lib/feature-libraries/flex-tree/lazyField.js +4 -3
  224. package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
  225. package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  226. package/lib/feature-libraries/flex-tree/lazyNode.js +5 -4
  227. package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  228. package/lib/feature-libraries/indexing/anchorTreeIndex.d.ts.map +1 -1
  229. package/lib/feature-libraries/indexing/anchorTreeIndex.js +1 -1
  230. package/lib/feature-libraries/indexing/anchorTreeIndex.js.map +1 -1
  231. package/lib/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
  232. package/lib/feature-libraries/modular-schema/comparison.js +6 -4
  233. package/lib/feature-libraries/modular-schema/comparison.js.map +1 -1
  234. package/lib/feature-libraries/modular-schema/isNeverTree.d.ts.map +1 -1
  235. package/lib/feature-libraries/modular-schema/isNeverTree.js +4 -4
  236. package/lib/feature-libraries/modular-schema/isNeverTree.js.map +1 -1
  237. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +4 -4
  238. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  239. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  240. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +11 -12
  241. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  242. package/lib/feature-libraries/node-key/mockNodeKeyManager.js +1 -1
  243. package/lib/feature-libraries/node-key/mockNodeKeyManager.js.map +1 -1
  244. package/lib/feature-libraries/object-forest/objectForest.js +1 -1
  245. package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
  246. package/lib/feature-libraries/schema-index/codec.js +1 -1
  247. package/lib/feature-libraries/schema-index/codec.js.map +1 -1
  248. package/lib/feature-libraries/sequence-field/compose.js +1 -1
  249. package/lib/feature-libraries/sequence-field/compose.js.map +1 -1
  250. package/lib/feature-libraries/sequence-field/invert.js +1 -1
  251. package/lib/feature-libraries/sequence-field/invert.js.map +1 -1
  252. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.js +1 -1
  253. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.js.map +1 -1
  254. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js +1 -1
  255. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  256. package/lib/feature-libraries/sequence-field/utils.js +1 -1
  257. package/lib/feature-libraries/sequence-field/utils.js.map +1 -1
  258. package/lib/feature-libraries/treeCursorUtils.d.ts.map +1 -1
  259. package/lib/feature-libraries/treeCursorUtils.js +6 -4
  260. package/lib/feature-libraries/treeCursorUtils.js.map +1 -1
  261. package/lib/index.d.ts +3 -1
  262. package/lib/index.d.ts.map +1 -1
  263. package/lib/index.js +2 -0
  264. package/lib/index.js.map +1 -1
  265. package/lib/jsonDomainSchema.d.ts +113 -0
  266. package/lib/jsonDomainSchema.d.ts.map +1 -0
  267. package/lib/jsonDomainSchema.js +98 -0
  268. package/lib/jsonDomainSchema.js.map +1 -0
  269. package/lib/packageVersion.d.ts +1 -1
  270. package/lib/packageVersion.js +1 -1
  271. package/lib/packageVersion.js.map +1 -1
  272. package/lib/serializableDomainSchema.d.ts +108 -0
  273. package/lib/serializableDomainSchema.d.ts.map +1 -0
  274. package/lib/serializableDomainSchema.js +87 -0
  275. package/lib/serializableDomainSchema.js.map +1 -0
  276. package/lib/shared-tree/index.d.ts +1 -1
  277. package/lib/shared-tree/index.d.ts.map +1 -1
  278. package/lib/shared-tree/index.js.map +1 -1
  279. package/lib/shared-tree/schematizeTree.js +1 -1
  280. package/lib/shared-tree/schematizeTree.js.map +1 -1
  281. package/lib/shared-tree/sharedTree.d.ts +37 -20
  282. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  283. package/lib/shared-tree/sharedTree.js +18 -18
  284. package/lib/shared-tree/sharedTree.js.map +1 -1
  285. package/lib/shared-tree/sharedTreeChangeFamily.js +1 -1
  286. package/lib/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  287. package/lib/shared-tree/treeApiAlpha.d.ts.map +1 -1
  288. package/lib/shared-tree/treeApiAlpha.js +4 -4
  289. package/lib/shared-tree/treeApiAlpha.js.map +1 -1
  290. package/lib/shared-tree/treeCheckout.js +1 -1
  291. package/lib/shared-tree/treeCheckout.js.map +1 -1
  292. package/lib/shared-tree-core/editManager.d.ts +11 -2
  293. package/lib/shared-tree-core/editManager.d.ts.map +1 -1
  294. package/lib/shared-tree-core/editManager.js +70 -34
  295. package/lib/shared-tree-core/editManager.js.map +1 -1
  296. package/lib/shared-tree-core/resubmitMachine.d.ts +2 -0
  297. package/lib/shared-tree-core/resubmitMachine.d.ts.map +1 -1
  298. package/lib/shared-tree-core/resubmitMachine.js.map +1 -1
  299. package/lib/shared-tree-core/sharedTreeCore.d.ts +10 -3
  300. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  301. package/lib/shared-tree-core/sharedTreeCore.js +42 -7
  302. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  303. package/lib/simple-tree/api/customTree.js +3 -3
  304. package/lib/simple-tree/api/customTree.js.map +1 -1
  305. package/lib/simple-tree/api/schemaCreationUtilities.js +1 -1
  306. package/lib/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  307. package/lib/simple-tree/api/schemaFactoryRecursive.d.ts +1 -1
  308. package/lib/simple-tree/api/schemaFactoryRecursive.js.map +1 -1
  309. package/lib/simple-tree/api/simpleTreeIndex.js +3 -3
  310. package/lib/simple-tree/api/simpleTreeIndex.js.map +1 -1
  311. package/lib/simple-tree/api/tree.js +1 -1
  312. package/lib/simple-tree/api/tree.js.map +1 -1
  313. package/lib/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  314. package/lib/simple-tree/api/treeNodeApi.js +9 -5
  315. package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
  316. package/lib/simple-tree/api/verboseTree.d.ts.map +1 -1
  317. package/lib/simple-tree/api/verboseTree.js +5 -4
  318. package/lib/simple-tree/api/verboseTree.js.map +1 -1
  319. package/lib/simple-tree/api/view.js +1 -1
  320. package/lib/simple-tree/api/view.js.map +1 -1
  321. package/lib/simple-tree/arrayNode.js +2 -2
  322. package/lib/simple-tree/arrayNode.js.map +1 -1
  323. package/lib/simple-tree/core/getOrCreateNode.d.ts.map +1 -1
  324. package/lib/simple-tree/core/getOrCreateNode.js +1 -1
  325. package/lib/simple-tree/core/getOrCreateNode.js.map +1 -1
  326. package/lib/simple-tree/core/schemaCaching.js +1 -1
  327. package/lib/simple-tree/core/schemaCaching.js.map +1 -1
  328. package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  329. package/lib/simple-tree/core/treeNodeKernel.js +6 -6
  330. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  331. package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  332. package/lib/simple-tree/core/unhydratedFlexTree.js +5 -5
  333. package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  334. package/lib/simple-tree/objectNode.js +2 -2
  335. package/lib/simple-tree/objectNode.js.map +1 -1
  336. package/lib/simple-tree/proxies.js +1 -1
  337. package/lib/simple-tree/proxies.js.map +1 -1
  338. package/lib/simple-tree/toMapTree.js +3 -3
  339. package/lib/simple-tree/toMapTree.js.map +1 -1
  340. package/lib/simple-tree/toStoredSchema.d.ts.map +1 -1
  341. package/lib/simple-tree/toStoredSchema.js +2 -1
  342. package/lib/simple-tree/toStoredSchema.js.map +1 -1
  343. package/lib/simple-tree/treeNodeValid.d.ts.map +1 -1
  344. package/lib/simple-tree/treeNodeValid.js +5 -2
  345. package/lib/simple-tree/treeNodeValid.js.map +1 -1
  346. package/lib/util/idAllocator.js +1 -1
  347. package/lib/util/idAllocator.js.map +1 -1
  348. package/lib/util/index.d.ts +2 -2
  349. package/lib/util/index.d.ts.map +1 -1
  350. package/lib/util/index.js +2 -2
  351. package/lib/util/index.js.map +1 -1
  352. package/lib/util/nestedMap.d.ts +2 -10
  353. package/lib/util/nestedMap.d.ts.map +1 -1
  354. package/lib/util/nestedMap.js +5 -23
  355. package/lib/util/nestedMap.js.map +1 -1
  356. package/lib/util/utils.d.ts +23 -6
  357. package/lib/util/utils.d.ts.map +1 -1
  358. package/lib/util/utils.js +42 -11
  359. package/lib/util/utils.js.map +1 -1
  360. package/package.json +22 -22
  361. package/src/codec/codec.ts +3 -3
  362. package/src/codec/discriminatedUnions.ts +2 -1
  363. package/src/core/schema-stored/schema.ts +5 -3
  364. package/src/core/tree/anchorSet.ts +37 -26
  365. package/src/core/tree/treeTextFormat.ts +1 -1
  366. package/src/feature-libraries/chunked-forest/basicChunk.ts +11 -8
  367. package/src/feature-libraries/chunked-forest/chunkTree.ts +2 -2
  368. package/src/feature-libraries/chunked-forest/chunkedForest.ts +3 -3
  369. package/src/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.ts +2 -2
  370. package/src/feature-libraries/chunked-forest/codec/compressedEncode.ts +4 -3
  371. package/src/feature-libraries/chunked-forest/codec/nodeShape.ts +2 -2
  372. package/src/feature-libraries/chunked-forest/codec/schemaBasedEncoding.ts +4 -3
  373. package/src/feature-libraries/chunked-forest/emptyChunk.ts +14 -14
  374. package/src/feature-libraries/chunked-forest/uniformChunk.ts +6 -4
  375. package/src/feature-libraries/default-schema/defaultFieldKinds.ts +1 -1
  376. package/src/feature-libraries/default-schema/schemaChecker.ts +1 -1
  377. package/src/feature-libraries/flex-tree/lazyField.ts +6 -8
  378. package/src/feature-libraries/flex-tree/lazyNode.ts +6 -4
  379. package/src/feature-libraries/indexing/anchorTreeIndex.ts +2 -1
  380. package/src/feature-libraries/modular-schema/comparison.ts +7 -5
  381. package/src/feature-libraries/modular-schema/isNeverTree.ts +6 -4
  382. package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +4 -4
  383. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +16 -12
  384. package/src/feature-libraries/node-key/mockNodeKeyManager.ts +1 -1
  385. package/src/feature-libraries/object-forest/objectForest.ts +1 -1
  386. package/src/feature-libraries/schema-index/codec.ts +1 -1
  387. package/src/feature-libraries/sequence-field/compose.ts +1 -1
  388. package/src/feature-libraries/sequence-field/invert.ts +1 -1
  389. package/src/feature-libraries/sequence-field/sequenceFieldCodecV1.ts +1 -1
  390. package/src/feature-libraries/sequence-field/sequenceFieldCodecV2.ts +1 -1
  391. package/src/feature-libraries/sequence-field/utils.ts +1 -1
  392. package/src/feature-libraries/treeCursorUtils.ts +6 -4
  393. package/src/index.ts +3 -1
  394. package/src/jsonDomainSchema.ts +129 -0
  395. package/src/packageVersion.ts +1 -1
  396. package/src/serializableDomainSchema.ts +121 -0
  397. package/src/shared-tree/index.ts +0 -1
  398. package/src/shared-tree/schematizeTree.ts +1 -1
  399. package/src/shared-tree/sharedTree.ts +31 -41
  400. package/src/shared-tree/sharedTreeChangeFamily.ts +1 -1
  401. package/src/shared-tree/treeApiAlpha.ts +12 -4
  402. package/src/shared-tree/treeCheckout.ts +1 -1
  403. package/src/shared-tree-core/editManager.ts +85 -47
  404. package/src/shared-tree-core/resubmitMachine.ts +2 -0
  405. package/src/shared-tree-core/sharedTreeCore.ts +62 -14
  406. package/src/simple-tree/api/customTree.ts +3 -3
  407. package/src/simple-tree/api/schemaCreationUtilities.ts +1 -1
  408. package/src/simple-tree/api/schemaFactoryRecursive.ts +1 -1
  409. package/src/simple-tree/api/simpleTreeIndex.ts +3 -3
  410. package/src/simple-tree/api/tree.ts +1 -1
  411. package/src/simple-tree/api/treeNodeApi.ts +11 -6
  412. package/src/simple-tree/api/verboseTree.ts +8 -4
  413. package/src/simple-tree/api/view.ts +1 -1
  414. package/src/simple-tree/arrayNode.ts +2 -2
  415. package/src/simple-tree/core/getOrCreateNode.ts +2 -1
  416. package/src/simple-tree/core/schemaCaching.ts +1 -1
  417. package/src/simple-tree/core/treeNodeKernel.ts +9 -6
  418. package/src/simple-tree/core/unhydratedFlexTree.ts +7 -5
  419. package/src/simple-tree/objectNode.ts +2 -2
  420. package/src/simple-tree/proxies.ts +1 -1
  421. package/src/simple-tree/toMapTree.ts +3 -3
  422. package/src/simple-tree/toStoredSchema.ts +2 -1
  423. package/src/simple-tree/treeNodeValid.ts +5 -2
  424. package/src/util/idAllocator.ts +1 -1
  425. package/src/util/index.ts +3 -2
  426. package/src/util/nestedMap.ts +9 -33
  427. package/src/util/utils.ts +52 -12
@@ -1 +1 @@
1
- {"version":3,"file":"treeNodeApi.js","sourceRoot":"","sources":["../../../src/simple-tree/api/treeNodeApi.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAElE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAmB,WAAW,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC5F,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAGN,WAAW,GAGX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,aAAa,EACb,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,YAAY,GACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EACN,SAAS,EACT,UAAU,EAEV,QAAQ,EAGR,oBAAoB,EACpB,4BAA4B,EAC5B,sBAAsB,EACtB,gBAAgB,EAChB,oBAAoB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,MAA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C,CAAC;IACjE,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, oob } from \"@fluidframework/core-utils/internal\";\n\nimport { EmptyKey, rootFieldKey } from \"../../core/index.js\";\nimport { type TreeStatus, isTreeValue, FieldKinds } from \"../../feature-libraries/index.js\";\nimport { fail, extractFromOpaque, isReadonlyArray } from \"../../util/index.js\";\nimport {\n\ttype TreeLeafValue,\n\ttype ImplicitFieldSchema,\n\tFieldSchema,\n\ttype ImplicitAllowedTypes,\n\ttype TreeNodeFromImplicitAllowedTypes,\n} from \"../schemaTypes.js\";\nimport {\n\tbooleanSchema,\n\thandleSchema,\n\tnullSchema,\n\tnumberSchema,\n\tstringSchema,\n} from \"../leafNodeSchema.js\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport type { Off } from \"@fluidframework/core-interfaces\";\nimport {\n\tgetKernel,\n\tisTreeNode,\n\ttype TreeNodeSchema,\n\tNodeKind,\n\ttype TreeNode,\n\ttype TreeChangeEvents,\n\ttryGetTreeNodeSchema,\n\tgetOrCreateNodeFromInnerNode,\n\tUnhydratedFlexTreeNode,\n\ttypeSchemaSymbol,\n\tgetOrCreateInnerNode,\n} from \"../core/index.js\";\nimport { isObjectNodeSchema } from \"../objectNodeTypes.js\";\nimport { isLazy, type LazyItem } from \"../flexList.js\";\n\n/**\n * Provides various functions for analyzing {@link TreeNode}s.\n * * @remarks\n * This type should only be used via the public `Tree` export.\n * @privateRemarks\n * Due to limitations of API-Extractor link resolution, this type can't be moved into internalTypes but should be considered just an implementation detail of the `Tree` export.\n *\n * Inlining the typing of this interface onto the `Tree` object provides slightly different .d.ts generation,\n * which avoids typescript expanding the type of TreeNodeSchema and thus encountering\n * https://github.com/microsoft/rushstack/issues/1958.\n * @sealed @public\n */\nexport interface TreeNodeApi {\n\t/**\n\t * The schema information for this node.\n\t */\n\tschema(node: TreeNode | TreeLeafValue): TreeNodeSchema;\n\n\t/**\n\t * Narrow the type of the given value if it satisfies the given schema.\n\t * @example\n\t * ```ts\n\t * if (node.is(myNode, Point)) {\n\t * const y = myNode.y; // `myNode` is now known to satisfy the `Point` schema and therefore has a `y` coordinate.\n\t * }\n\t * ```\n\t */\n\tis<TSchema extends ImplicitAllowedTypes>(\n\t\tvalue: unknown,\n\t\tschema: TSchema,\n\t): value is TreeNodeFromImplicitAllowedTypes<TSchema>;\n\n\t/**\n\t * Return the node under which this node resides in the tree (or undefined if this is a root node of the tree).\n\t */\n\tparent(node: TreeNode): TreeNode | undefined;\n\n\t/**\n\t * The key of the given node under its parent.\n\t * @remarks\n\t * If `node` is an element in a {@link (TreeArrayNode:interface)}, this returns the index of `node` in the array node (a `number`).\n\t * Otherwise, this returns the key of the field that it is under (a `string`).\n\t */\n\tkey(node: TreeNode): string | number;\n\n\t/**\n\t * Register an event listener on the given node.\n\t * @param node - The node whose events should be subscribed to.\n\t * @param eventName - Which event to subscribe to.\n\t * @param listener - The callback to trigger for the event. The tree can be read during the callback, but it is invalid to modify the tree during this callback.\n\t * @returns A callback function which will deregister the event.\n\t * This callback should be called only once.\n\t */\n\ton<K extends keyof TreeChangeEvents>(\n\t\tnode: TreeNode,\n\t\teventName: K,\n\t\tlistener: TreeChangeEvents[K],\n\t): () => void;\n\n\t/**\n\t * Returns the {@link TreeStatus} of the given node.\n\t */\n\tstatus(node: TreeNode): TreeStatus;\n\n\t/**\n\t * Returns the {@link SchemaFactory.identifier | identifier} of the given node in the most compressed form possible.\n\t * @remarks\n\t * If the node's identifier is a valid UUID that was automatically generated by the SharedTree, then this will return a process-unique integer corresponding to that identifier.\n\t * Note that the node must already have been inserted into the tree in order to retrieve a generated UUID (or shortId will error).\n\t * This is useful for performance-sensitive scenarios involving many nodes with identifiers that need to be compactly retained in memory or used for efficient lookup.\n\t *\n\t * If the node's identifier is any other user-provided string, then this will return that string.\n\t *\n\t * If the node has no identifier (that is, it has no {@link SchemaFactory.identifier | identifier} field), then this returns `undefined`.\n\t *\n\t * If the node has more than one identifier, then this will throw an error.\n\t *\n\t * The returned integer must not be serialized or preserved outside of the current process.\n\t * Its lifetime is that of the current in-memory instance of the FF container for this client, and it is not guaranteed to be unique or stable outside of that context.\n\t * The same node's identifier may, for example, be different across multiple sessions for the same client and document, or different across two clients in the same session.\n\t */\n\tshortId(node: TreeNode): number | string | undefined;\n}\n\n/**\n * The `Tree` object holds various functions for analyzing {@link TreeNode}s.\n */\nexport const treeNodeApi: TreeNodeApi = {\n\tparent(node: TreeNode): TreeNode | undefined {\n\t\tconst editNode = getOrCreateInnerNode(node).parentField.parent.parent;\n\t\tif (editNode === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst output = getOrCreateNodeFromInnerNode(editNode);\n\t\tassert(\n\t\t\t!isTreeValue(output),\n\t\t\t0x87f /* Parent can't be a leaf, so it should be a node not a value */,\n\t\t);\n\t\treturn output;\n\t},\n\tkey(node: TreeNode): string | number {\n\t\t// If the parent is undefined, then this node is under the root field,\n\t\t// so we know its key is the special root one.\n\t\tconst parent = treeNodeApi.parent(node);\n\t\tif (parent === undefined) {\n\t\t\treturn rootFieldKey;\n\t\t}\n\n\t\t// The flex-domain strictly operates in terms of \"stored keys\".\n\t\t// To find the associated developer-facing \"property key\", we need to look up the field associated with\n\t\t// the stored key from the flex-domain, and get property key its simple-domain counterpart was created with.\n\t\tconst storedKey = getStoredKey(node);\n\t\tconst parentSchema = treeNodeApi.schema(parent);\n\t\tconst propertyKey = getPropertyKeyFromStoredKey(parentSchema, storedKey);\n\t\treturn propertyKey;\n\t},\n\ton<K extends keyof TreeChangeEvents>(\n\t\tnode: TreeNode,\n\t\teventName: K,\n\t\tlistener: TreeChangeEvents[K],\n\t): Off {\n\t\tconst kernel = getKernel(node);\n\t\tswitch (eventName) {\n\t\t\tcase \"nodeChanged\": {\n\t\t\t\tconst nodeSchema = kernel.schema;\n\t\t\t\tif (isObjectNodeSchema(nodeSchema)) {\n\t\t\t\t\treturn kernel.events.on(\"childrenChangedAfterBatch\", ({ changedFields }) => {\n\t\t\t\t\t\tconst changedProperties = new Set(\n\t\t\t\t\t\t\tArray.from(\n\t\t\t\t\t\t\t\tchangedFields,\n\t\t\t\t\t\t\t\t(field) =>\n\t\t\t\t\t\t\t\t\tnodeSchema.storedKeyToPropertyKey.get(field) ??\n\t\t\t\t\t\t\t\t\tfail(\"Could not find stored key in schema.\"),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tlistener({ changedProperties });\n\t\t\t\t\t});\n\t\t\t\t} else if (nodeSchema.kind === NodeKind.Array) {\n\t\t\t\t\treturn kernel.events.on(\"childrenChangedAfterBatch\", () => {\n\t\t\t\t\t\tlistener({ changedProperties: undefined });\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\treturn kernel.events.on(\"childrenChangedAfterBatch\", ({ changedFields }) => {\n\t\t\t\t\t\tlistener({ changedProperties: changedFields });\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\tcase \"treeChanged\": {\n\t\t\t\treturn kernel.events.on(\"subtreeChangedAfterBatch\", () => listener({}));\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tthrow new UsageError(`No event named ${JSON.stringify(eventName)}.`);\n\t\t}\n\t},\n\tstatus(node: TreeNode): TreeStatus {\n\t\treturn getKernel(node).getStatus();\n\t},\n\tis<TSchema extends ImplicitAllowedTypes>(\n\t\tvalue: unknown,\n\t\tschema: TSchema,\n\t): value is TreeNodeFromImplicitAllowedTypes<TSchema> {\n\t\tconst actualSchema = tryGetSchema(value);\n\t\tif (actualSchema === undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tif (isReadonlyArray<LazyItem<TreeNodeSchema>>(schema)) {\n\t\t\tfor (const singleSchema of schema) {\n\t\t\t\tconst testSchema = isLazy(singleSchema) ? singleSchema() : singleSchema;\n\t\t\t\tif (testSchema === actualSchema) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t} else {\n\t\t\t// Linter is incorrect about this bering unnecessary: it does not compile without the type assertion.\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n\t\t\treturn (schema as TreeNodeSchema) === actualSchema;\n\t\t}\n\t},\n\tschema(node: TreeNode | TreeLeafValue): TreeNodeSchema {\n\t\treturn tryGetSchema(node) ?? fail(\"Not a tree node\");\n\t},\n\tshortId(node: TreeNode): number | string | undefined {\n\t\tconst schema = node[typeSchemaSymbol];\n\t\tif (!isObjectNodeSchema(schema)) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst flexNode = getOrCreateInnerNode(node);\n\t\tconst identifierFieldKeys = schema.identifierFieldKeys;\n\n\t\tswitch (identifierFieldKeys.length) {\n\t\t\tcase 0:\n\t\t\t\treturn undefined;\n\t\t\tcase 1: {\n\t\t\t\tconst identifier = flexNode.tryGetField(identifierFieldKeys[0] ?? oob())?.boxedAt(0);\n\t\t\t\tif (flexNode instanceof UnhydratedFlexTreeNode) {\n\t\t\t\t\tif (identifier === undefined) {\n\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t\"Tree.shortId cannot access default identifiers on unhydrated nodes\",\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn identifier.value as string;\n\t\t\t\t}\n\t\t\t\tassert(\n\t\t\t\t\tidentifier?.context.isHydrated() === true,\n\t\t\t\t\t0xa27 /* Expected hydrated identifier */,\n\t\t\t\t);\n\t\t\t\tconst identifierValue = identifier.value as string;\n\n\t\t\t\tconst localNodeKey =\n\t\t\t\t\tidentifier.context.nodeKeyManager.tryLocalizeNodeKey(identifierValue);\n\t\t\t\treturn localNodeKey !== undefined ? extractFromOpaque(localNodeKey) : identifierValue;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\"shortId() may not be called on a node with more than one identifier. Consider converting extraneous identifier fields to string fields.\",\n\t\t\t\t);\n\t\t}\n\t},\n};\n\n/**\n * Returns a schema for a value if the value is a {@link TreeNode} or a {@link TreeLeafValue}.\n * Returns undefined for other values.\n */\nexport function tryGetSchema(value: unknown): undefined | TreeNodeSchema {\n\tswitch (typeof value) {\n\t\tcase \"string\":\n\t\t\treturn stringSchema;\n\t\tcase \"number\":\n\t\t\treturn numberSchema;\n\t\tcase \"boolean\":\n\t\t\treturn booleanSchema;\n\t\tcase \"object\": {\n\t\t\tif (isTreeNode(value)) {\n\t\t\t\t// TODO: This case could be optimized, for example by placing the simple schema in a symbol on tree nodes.\n\t\t\t\treturn tryGetTreeNodeSchema(value);\n\t\t\t}\n\t\t\tif (value === null) {\n\t\t\t\treturn nullSchema;\n\t\t\t}\n\t\t\tif (isFluidHandle(value)) {\n\t\t\t\treturn handleSchema;\n\t\t\t}\n\t\t}\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\n/**\n * Gets the stored key with which the provided node is associated in the parent.\n */\nfunction getStoredKey(node: TreeNode): string | number {\n\t// Note: the flex domain strictly works with \"stored keys\", and knows nothing about the developer-facing\n\t// \"property keys\".\n\tconst parentField = getOrCreateInnerNode(node).parentField;\n\tif (parentField.parent.schema === FieldKinds.sequence.identifier) {\n\t\t// The parent of `node` is an array node\n\t\tassert(\n\t\t\tparentField.parent.key === EmptyKey,\n\t\t\t0xa28 /* When using index as key, field should use EmptyKey */,\n\t\t);\n\t\treturn parentField.index;\n\t}\n\n\t// The parent of `node` is an object, a map, or undefined. If undefined, then `node` is a root/detached node.\n\tassert(parentField.index === 0, 0xa29 /* When using field key as key, index should be 0 */);\n\treturn parentField.parent.key;\n}\n\n/**\n * Given a node schema, gets the property key corresponding with the provided {@link FieldProps.key | stored key}.\n */\nfunction getPropertyKeyFromStoredKey(\n\tschema: TreeNodeSchema,\n\tstoredKey: string | number,\n): string | number {\n\t// Only object nodes have the concept of a \"stored key\", differentiated from the developer-facing \"property key\".\n\t// For any other kind of node, the stored key and the property key are the same.\n\tif (schema.kind !== NodeKind.Object) {\n\t\treturn storedKey;\n\t}\n\n\tconst fields = schema.info as Record<string, ImplicitFieldSchema>;\n\n\t// Invariants:\n\t// - The set of all property keys under an object must be unique.\n\t// - The set of all stored keys (including those implicitly created from property keys) must be unique.\n\t// To find the property key associated with the provided stored key, first check for any stored key matches (which are optionally populated).\n\t// If we don't find any, then search for a matching property key.\n\tfor (const [propertyKey, fieldSchema] of Object.entries(fields)) {\n\t\tif (fieldSchema instanceof FieldSchema && fieldSchema.props?.key === storedKey) {\n\t\t\treturn propertyKey;\n\t\t}\n\t}\n\n\tif (fields[storedKey] === undefined) {\n\t\tfail(\"Existing stored key should always map to a property key\");\n\t}\n\n\treturn storedKey;\n}\n"]}
1
+ {"version":3,"file":"treeNodeApi.js","sourceRoot":"","sources":["../../../src/simple-tree/api/treeNodeApi.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAElE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAmB,WAAW,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC5F,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAGN,WAAW,GAGX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,aAAa,EACb,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,YAAY,GACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EACN,SAAS,EACT,UAAU,EAEV,QAAQ,EAGR,oBAAoB,EACpB,4BAA4B,EAC5B,sBAAsB,EACtB,gBAAgB,EAChB,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AI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACjE,IAAI,WAAW,YAAY,WAAW,IAAI,WAAW,CAAC,KAAK,EAAE,GAAG,KAAK,SAAS,EAAE,CAAC;YAChF,OAAO,WAAW,CAAC;QACpB,CAAC;IACF,CAAC;IAED,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,SAAS,EAAE,CAAC;QACrC,IAAI,CAAC,KAAK,CAAC,6DAA6D,CAAC,CAAC;IAC3E,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, oob } from \"@fluidframework/core-utils/internal\";\n\nimport { EmptyKey, rootFieldKey } from \"../../core/index.js\";\nimport { type TreeStatus, isTreeValue, FieldKinds } from \"../../feature-libraries/index.js\";\nimport { fail, extractFromOpaque, isReadonlyArray } from \"../../util/index.js\";\nimport {\n\ttype TreeLeafValue,\n\ttype ImplicitFieldSchema,\n\tFieldSchema,\n\ttype ImplicitAllowedTypes,\n\ttype TreeNodeFromImplicitAllowedTypes,\n} from \"../schemaTypes.js\";\nimport {\n\tbooleanSchema,\n\thandleSchema,\n\tnullSchema,\n\tnumberSchema,\n\tstringSchema,\n} from \"../leafNodeSchema.js\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport type { Off } from \"@fluidframework/core-interfaces\";\nimport {\n\tgetKernel,\n\tisTreeNode,\n\ttype TreeNodeSchema,\n\tNodeKind,\n\ttype TreeNode,\n\ttype TreeChangeEvents,\n\ttryGetTreeNodeSchema,\n\tgetOrCreateNodeFromInnerNode,\n\tUnhydratedFlexTreeNode,\n\ttypeSchemaSymbol,\n\tgetOrCreateInnerNode,\n} from \"../core/index.js\";\nimport { isObjectNodeSchema } from \"../objectNodeTypes.js\";\nimport { isLazy, type LazyItem } from \"../flexList.js\";\nimport { markSchemaMostDerived } from \"./schemaFactory.js\";\n\n/**\n * Provides various functions for analyzing {@link TreeNode}s.\n * * @remarks\n * This type should only be used via the public `Tree` export.\n * @privateRemarks\n * Due to limitations of API-Extractor link resolution, this type can't be moved into internalTypes but should be considered just an implementation detail of the `Tree` export.\n *\n * Inlining the typing of this interface onto the `Tree` object provides slightly different .d.ts generation,\n * which avoids typescript expanding the type of TreeNodeSchema and thus encountering\n * https://github.com/microsoft/rushstack/issues/1958.\n * @sealed @public\n */\nexport interface TreeNodeApi {\n\t/**\n\t * The schema information for this node.\n\t */\n\tschema(node: TreeNode | TreeLeafValue): TreeNodeSchema;\n\n\t/**\n\t * Narrow the type of the given value if it satisfies the given schema.\n\t * @example\n\t * ```ts\n\t * if (node.is(myNode, Point)) {\n\t * const y = myNode.y; // `myNode` is now known to satisfy the `Point` schema and therefore has a `y` coordinate.\n\t * }\n\t * ```\n\t */\n\tis<TSchema extends ImplicitAllowedTypes>(\n\t\tvalue: unknown,\n\t\tschema: TSchema,\n\t): value is TreeNodeFromImplicitAllowedTypes<TSchema>;\n\n\t/**\n\t * Return the node under which this node resides in the tree (or undefined if this is a root node of the tree).\n\t */\n\tparent(node: TreeNode): TreeNode | undefined;\n\n\t/**\n\t * The key of the given node under its parent.\n\t * @remarks\n\t * If `node` is an element in a {@link (TreeArrayNode:interface)}, this returns the index of `node` in the array node (a `number`).\n\t * Otherwise, this returns the key of the field that it is under (a `string`).\n\t */\n\tkey(node: TreeNode): string | number;\n\n\t/**\n\t * Register an event listener on the given node.\n\t * @param node - The node whose events should be subscribed to.\n\t * @param eventName - Which event to subscribe to.\n\t * @param listener - The callback to trigger for the event. The tree can be read during the callback, but it is invalid to modify the tree during this callback.\n\t * @returns A callback function which will deregister the event.\n\t * This callback should be called only once.\n\t */\n\ton<K extends keyof TreeChangeEvents>(\n\t\tnode: TreeNode,\n\t\teventName: K,\n\t\tlistener: TreeChangeEvents[K],\n\t): () => void;\n\n\t/**\n\t * Returns the {@link TreeStatus} of the given node.\n\t */\n\tstatus(node: TreeNode): TreeStatus;\n\n\t/**\n\t * Returns the {@link SchemaFactory.identifier | identifier} of the given node in the most compressed form possible.\n\t * @remarks\n\t * If the node's identifier is a valid UUID that was automatically generated by the SharedTree, then this will return a process-unique integer corresponding to that identifier.\n\t * Note that the node must already have been inserted into the tree in order to retrieve a generated UUID (or shortId will error).\n\t * This is useful for performance-sensitive scenarios involving many nodes with identifiers that need to be compactly retained in memory or used for efficient lookup.\n\t *\n\t * If the node's identifier is any other user-provided string, then this will return that string.\n\t *\n\t * If the node has no identifier (that is, it has no {@link SchemaFactory.identifier | identifier} field), then this returns `undefined`.\n\t *\n\t * If the node has more than one identifier, then this will throw an error.\n\t *\n\t * The returned integer must not be serialized or preserved outside of the current process.\n\t * Its lifetime is that of the current in-memory instance of the FF container for this client, and it is not guaranteed to be unique or stable outside of that context.\n\t * The same node's identifier may, for example, be different across multiple sessions for the same client and document, or different across two clients in the same session.\n\t */\n\tshortId(node: TreeNode): number | string | undefined;\n}\n\n/**\n * The `Tree` object holds various functions for analyzing {@link TreeNode}s.\n */\nexport const treeNodeApi: TreeNodeApi = {\n\tparent(node: TreeNode): TreeNode | undefined {\n\t\tconst editNode = getOrCreateInnerNode(node).parentField.parent.parent;\n\t\tif (editNode === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst output = getOrCreateNodeFromInnerNode(editNode);\n\t\tassert(\n\t\t\t!isTreeValue(output),\n\t\t\t0x87f /* Parent can't be a leaf, so it should be a node not a value */,\n\t\t);\n\t\treturn output;\n\t},\n\tkey(node: TreeNode): string | number {\n\t\t// If the parent is undefined, then this node is under the root field,\n\t\t// so we know its key is the special root one.\n\t\tconst parent = treeNodeApi.parent(node);\n\t\tif (parent === undefined) {\n\t\t\treturn rootFieldKey;\n\t\t}\n\n\t\t// The flex-domain strictly operates in terms of \"stored keys\".\n\t\t// To find the associated developer-facing \"property key\", we need to look up the field associated with\n\t\t// the stored key from the flex-domain, and get property key its simple-domain counterpart was created with.\n\t\tconst storedKey = getStoredKey(node);\n\t\tconst parentSchema = treeNodeApi.schema(parent);\n\t\tconst propertyKey = getPropertyKeyFromStoredKey(parentSchema, storedKey);\n\t\treturn propertyKey;\n\t},\n\ton<K extends keyof TreeChangeEvents>(\n\t\tnode: TreeNode,\n\t\teventName: K,\n\t\tlistener: TreeChangeEvents[K],\n\t): Off {\n\t\tconst kernel = getKernel(node);\n\t\tswitch (eventName) {\n\t\t\tcase \"nodeChanged\": {\n\t\t\t\tconst nodeSchema = kernel.schema;\n\t\t\t\tif (isObjectNodeSchema(nodeSchema)) {\n\t\t\t\t\treturn kernel.events.on(\"childrenChangedAfterBatch\", ({ changedFields }) => {\n\t\t\t\t\t\tconst changedProperties = new Set(\n\t\t\t\t\t\t\tArray.from(\n\t\t\t\t\t\t\t\tchangedFields,\n\t\t\t\t\t\t\t\t(field) =>\n\t\t\t\t\t\t\t\t\tnodeSchema.storedKeyToPropertyKey.get(field) ??\n\t\t\t\t\t\t\t\t\tfail(0xb36 /* Could not find stored key in schema. */),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tlistener({ changedProperties });\n\t\t\t\t\t});\n\t\t\t\t} else if (nodeSchema.kind === NodeKind.Array) {\n\t\t\t\t\treturn kernel.events.on(\"childrenChangedAfterBatch\", () => {\n\t\t\t\t\t\tlistener({ changedProperties: undefined });\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\treturn kernel.events.on(\"childrenChangedAfterBatch\", ({ changedFields }) => {\n\t\t\t\t\t\tlistener({ changedProperties: changedFields });\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\tcase \"treeChanged\": {\n\t\t\t\treturn kernel.events.on(\"subtreeChangedAfterBatch\", () => listener({}));\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tthrow new UsageError(`No event named ${JSON.stringify(eventName)}.`);\n\t\t}\n\t},\n\tstatus(node: TreeNode): TreeStatus {\n\t\treturn getKernel(node).getStatus();\n\t},\n\tis<TSchema extends ImplicitAllowedTypes>(\n\t\tvalue: unknown,\n\t\tschema: TSchema,\n\t): value is TreeNodeFromImplicitAllowedTypes<TSchema> {\n\t\t// This \"is\" utility would return false if the provided schema is a base type of the actual schema.\n\t\t// This could be confusing, and that case can only be hit when violating the rule that there is a single most derived schema that gets used (See documentation on TreeNodeSchemaClass).\n\t\t// Therefore this uses markSchemaMostDerived to ensure an informative usage error is thrown in the case where a base type is used.\n\n\t\tconst actualSchema = tryGetSchema(value);\n\t\tif (actualSchema === undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tif (isReadonlyArray<LazyItem<TreeNodeSchema>>(schema)) {\n\t\t\tfor (const singleSchema of schema) {\n\t\t\t\tconst testSchema = isLazy(singleSchema) ? singleSchema() : singleSchema;\n\t\t\t\tmarkSchemaMostDerived(testSchema);\n\t\t\t\tif (testSchema === actualSchema) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t} else {\n\t\t\tmarkSchemaMostDerived(schema);\n\t\t\treturn schema === actualSchema;\n\t\t}\n\t},\n\tschema(node: TreeNode | TreeLeafValue): TreeNodeSchema {\n\t\treturn tryGetSchema(node) ?? fail(0xb37 /* Not a tree node */);\n\t},\n\tshortId(node: TreeNode): number | string | undefined {\n\t\tconst schema = node[typeSchemaSymbol];\n\t\tif (!isObjectNodeSchema(schema)) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst flexNode = getOrCreateInnerNode(node);\n\t\tconst identifierFieldKeys = schema.identifierFieldKeys;\n\n\t\tswitch (identifierFieldKeys.length) {\n\t\t\tcase 0:\n\t\t\t\treturn undefined;\n\t\t\tcase 1: {\n\t\t\t\tconst identifier = flexNode.tryGetField(identifierFieldKeys[0] ?? oob())?.boxedAt(0);\n\t\t\t\tif (flexNode instanceof UnhydratedFlexTreeNode) {\n\t\t\t\t\tif (identifier === undefined) {\n\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t\"Tree.shortId cannot access default identifiers on unhydrated nodes\",\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn identifier.value as string;\n\t\t\t\t}\n\t\t\t\tassert(\n\t\t\t\t\tidentifier?.context.isHydrated() === true,\n\t\t\t\t\t0xa27 /* Expected hydrated identifier */,\n\t\t\t\t);\n\t\t\t\tconst identifierValue = identifier.value as string;\n\n\t\t\t\tconst localNodeKey =\n\t\t\t\t\tidentifier.context.nodeKeyManager.tryLocalizeNodeKey(identifierValue);\n\t\t\t\treturn localNodeKey !== undefined ? extractFromOpaque(localNodeKey) : identifierValue;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\"shortId() may not be called on a node with more than one identifier. Consider converting extraneous identifier fields to string fields.\",\n\t\t\t\t);\n\t\t}\n\t},\n};\n\n/**\n * Returns a schema for a value if the value is a {@link TreeNode} or a {@link TreeLeafValue}.\n * Returns undefined for other values.\n */\nexport function tryGetSchema(value: unknown): undefined | TreeNodeSchema {\n\tswitch (typeof value) {\n\t\tcase \"string\":\n\t\t\treturn stringSchema;\n\t\tcase \"number\":\n\t\t\treturn numberSchema;\n\t\tcase \"boolean\":\n\t\t\treturn booleanSchema;\n\t\tcase \"object\": {\n\t\t\tif (isTreeNode(value)) {\n\t\t\t\t// TODO: This case could be optimized, for example by placing the simple schema in a symbol on tree nodes.\n\t\t\t\treturn tryGetTreeNodeSchema(value);\n\t\t\t}\n\t\t\tif (value === null) {\n\t\t\t\treturn nullSchema;\n\t\t\t}\n\t\t\tif (isFluidHandle(value)) {\n\t\t\t\treturn handleSchema;\n\t\t\t}\n\t\t}\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\n/**\n * Gets the stored key with which the provided node is associated in the parent.\n */\nfunction getStoredKey(node: TreeNode): string | number {\n\t// Note: the flex domain strictly works with \"stored keys\", and knows nothing about the developer-facing\n\t// \"property keys\".\n\tconst parentField = getOrCreateInnerNode(node).parentField;\n\tif (parentField.parent.schema === FieldKinds.sequence.identifier) {\n\t\t// The parent of `node` is an array node\n\t\tassert(\n\t\t\tparentField.parent.key === EmptyKey,\n\t\t\t0xa28 /* When using index as key, field should use EmptyKey */,\n\t\t);\n\t\treturn parentField.index;\n\t}\n\n\t// The parent of `node` is an object, a map, or undefined. If undefined, then `node` is a root/detached node.\n\tassert(parentField.index === 0, 0xa29 /* When using field key as key, index should be 0 */);\n\treturn parentField.parent.key;\n}\n\n/**\n * Given a node schema, gets the property key corresponding with the provided {@link FieldProps.key | stored key}.\n */\nfunction getPropertyKeyFromStoredKey(\n\tschema: TreeNodeSchema,\n\tstoredKey: string | number,\n): string | number {\n\t// Only object nodes have the concept of a \"stored key\", differentiated from the developer-facing \"property key\".\n\t// For any other kind of node, the stored key and the property key are the same.\n\tif (schema.kind !== NodeKind.Object) {\n\t\treturn storedKey;\n\t}\n\n\tconst fields = schema.info as Record<string, ImplicitFieldSchema>;\n\n\t// Invariants:\n\t// - The set of all property keys under an object must be unique.\n\t// - The set of all stored keys (including those implicitly created from property keys) must be unique.\n\t// To find the property key associated with the provided stored key, first check for any stored key matches (which are optionally populated).\n\t// If we don't find any, then search for a matching property key.\n\tfor (const [propertyKey, fieldSchema] of Object.entries(fields)) {\n\t\tif (fieldSchema instanceof FieldSchema && fieldSchema.props?.key === storedKey) {\n\t\t\treturn propertyKey;\n\t\t}\n\t}\n\n\tif (fields[storedKey] === undefined) {\n\t\tfail(0xb38 /* Existing stored key should always map to a property key */);\n\t}\n\n\treturn storedKey;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"verboseTree.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/verboseTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAIpE,OAAO,EAIN,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,sBAAsB,EAE3B,MAAM,qBAAqB,C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AO,EAC7C,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,EAC5B,OAAO,EAAE,sBAAsB,CAAC,OAAO,CAAC,GACtC,sBAAsB,CAMxB;AA0FD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EACxC,MAAM,EAAE,WAAW,EACnB,UAAU,EAAE,oBAAoB,EAChC,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,GAC7B,WAAW,CAAC,OAAO,CAAC,CAStB"}
@@ -28,7 +28,7 @@ export function applySchemaToParserOptions(schema, options) {
28
28
  : {
29
29
  encode: (type, key) => {
30
30
  // translate stored key into property key.
31
- const simpleNodeSchema = context.schema.get(brand(type)) ?? fail("missing schema");
31
+ const simpleNodeSchema = context.schema.get(brand(type)) ?? fail(0xb39 /* missing schema */);
32
32
  if (isObjectNodeSchema(simpleNodeSchema)) {
33
33
  const propertyKey = simpleNodeSchema.storedKeyToPropertyKey.get(key);
34
34
  if (propertyKey !== undefined) {
@@ -46,9 +46,10 @@ export function applySchemaToParserOptions(schema, options) {
46
46
  return key;
47
47
  },
48
48
  parse: (type, inputKey) => {
49
- const simpleNodeSchema = context.schema.get(brand(type)) ?? fail("missing schema");
49
+ const simpleNodeSchema = context.schema.get(brand(type)) ?? fail(0xb3a /* missing schema */);
50
50
  if (isObjectNodeSchema(simpleNodeSchema)) {
51
- const info = simpleNodeSchema.flexKeyMap.get(inputKey) ?? fail("missing field info");
51
+ const info = simpleNodeSchema.flexKeyMap.get(inputKey) ??
52
+ fail(0xb3b /* missing field info */);
52
53
  return info.storedKey;
53
54
  }
54
55
  return brand(inputKey);
@@ -159,7 +160,7 @@ export function verboseFromCursor(reader, rootSchema, options) {
159
160
  }
160
161
  function verboseFromCursorInner(reader, options, schema) {
161
162
  const fields = customFromCursor(reader, options, schema, verboseFromCursorInner);
162
- const nodeSchema = schema.get(reader.type) ?? fail("missing schema for type in cursor");
163
+ const nodeSchema = schema.get(reader.type) ?? fail(0xb3c /* missing schema for type in cursor */);
163
164
  if (nodeSchema.kind === NodeKind.Leaf) {
164
165
  return fields;
165
166
  }
@@ -1 +1 @@
1
- {"version":3,"file":"verboseTree.js","sourceRoot":"","sources":["../../../src/simple-tree/api/verboseTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,OAAO,EACN,oBAAoB,EACpB,QAAQ,EACR,kBAAkB,GAKlB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAMlD,OAAO,EAAE,QAAQ,EAAuB,MAAM,kBAAkB,CAAC;AACjE,OAAO,EACN,WAAW,EACX,oBAAoB,EACpB,mBAAmB,GAEnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACN,aAAa,EACb,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,YAAY,GACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EACN,gBAAgB,GAIhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AA4G3D;;GAEG;AACH,MAAM,UAAU,0BAA0B,CACzC,MAA2B,EAC3B,OAA8B;IAE9B,MAAM,MAAM,GAAoC;QAC/C,aAAa,EAAE,KAAK;QACpB,GAAG,OAAO;KACV,CAAC;IAEF,MAAM,OAAO,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAE7C,OAAO;QACN,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,YAAY,EAAE,MAAM,CAAC,aAAa;YACjC,CAAC,CAAC,SAAS;YACX,CAAC,CAAC;gBACA,MAAM,EAAE,CAAC,IAAI,EAAE,GAAa,EAAU,EAAE;oBACvC,0CAA0C;oBAC1C,MAAM,gBAAgB,GA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sB,CAAC,CAAC;IACjF,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,mCAAmC,CAAC,CAAC;IACxF,IAAI,UAAU,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,EAAE,CAAC;QACvC,OAAO,MAAkC,CAAC;IAC3C,CAAC;IAED,OAAO;QACN,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,MAAM,EAAE,MAAiC;KACzC,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\taboveRootPlaceholder,\n\tEmptyKey,\n\tkeyAsDetachedField,\n\ttype FieldKey,\n\ttype ITreeCursor,\n\ttype ITreeCursorSynchronous,\n\ttype TreeNodeSchemaIdentifier,\n} from \"../../core/index.js\";\nimport { brand, fail } from \"../../util/index.js\";\nimport type {\n\tTreeLeafValue,\n\tImplicitFieldSchema,\n\tImplicitAllowedTypes,\n} from \"../schemaTypes.js\";\nimport { NodeKind, type TreeNodeSchema } from \"../core/index.js\";\nimport {\n\tisTreeValue,\n\tstackTreeFieldCursor,\n\tstackTreeNodeCursor,\n\ttype CursorAdapter,\n} from \"../../feature-libraries/index.js\";\nimport {\n\tbooleanSchema,\n\thandleSchema,\n\tnullSchema,\n\tnumberSchema,\n\tstringSchema,\n} from \"../leafNodeSchema.js\";\nimport { isObjectNodeSchema } from \"../objectNodeTypes.js\";\nimport {\n\tcustomFromCursor,\n\ttype CustomTreeNode,\n\ttype CustomTreeValue,\n\ttype EncodeOptions,\n} from \"./customTree.js\";\nimport { getUnhydratedContext } from \"../createContext.js\";\n\n/**\n * Verbose encoding of a {@link TreeNode} or {@link TreeLeafValue}.\n * @remarks\n * This is verbose meaning that every {@link TreeNode} is a {@link VerboseTreeNode}.\n * Any IFluidHandle values have been replaced by `THandle`.\n * @privateRemarks\n * This can store all possible simple trees,\n * but it can not store all possible trees representable by our internal representations like FlexTree and JsonableTree.\n * @alpha\n */\nexport type VerboseTree<THandle = IFluidHandle> =\n\t| VerboseTreeNode<THandle>\n\t| Exclude<TreeLeafValue, IFluidHandle>\n\t| THandle;\n\n/**\n * Verbose encoding of a {@link TreeNode}.\n * @remarks\n * This is verbose meaning that every {@link TreeNode} has an explicit `type` property, and `fields`.\n * This allowed VerboseTreeNode to be unambiguous regarding which type each node is without relying on symbols or hidden state.\n *\n * Any IFluidHandle values have been replaced by `THandle`. If the `THandle` is JSON compatible, then this type is JSON compatible as well.\n *\n * @privateRemarks\n * This type is only used for data which is copied into and out of the tree.\n * When being copied out, its fine to have the data be mutable since its a copy.\n *\n * When being copied in, we don't need to mutate, so we could use a readonly variant of this type.\n * however the copy in case (createFromVerbose) probably isn't harmed much by just reusing this type as is,\n * since if the caller has immutable data, TypeScript doesn't prevent assigning immutable data to a mutable type anyway.\n * Also relaxing the input methods to take readonly data would be a non-breaking change so it can be done later if desired.\n *\n * This format is simple-tree specialized alternative to {@link JsonableTree}.\n * This format allows for all simple-tree compatible trees to be represented.\n *\n * Unlike `JsonableTree`, leaf nodes are not boxed into node objects, and instead have their schema inferred from the value.\n * Additionally, sequence fields can only occur on a node that has a single sequence field (with the empty key)\n * replicating the behavior of simple-tree ArrayNodes.\n * @alpha\n */\nexport interface VerboseTreeNode<THandle = IFluidHandle> {\n\t/**\n\t * The meaning of this node.\n\t * Provides contexts/semantics for this node and its content.\n\t * @remarks\n\t * Typically used to associate a node with metadata (including a schema) and source code (types, behaviors, etc).\n\t * When used with this package's schema system, it will be the {@link TreeNodeSchemaCore.identifier}.\n\t */\n\ttype: string;\n\n\t/**\n\t * Content of this node.\n\t * For array nodes, an array of children.\n\t * For map and object nodes, an object which children under keys.\n\t * @remarks\n\t * For object nodes, the keys could be either the stored keys, or the property keys depending on usage.\n\t */\n\tfields:\n\t\t| VerboseTree<THandle>[]\n\t\t| {\n\t\t\t\t[key: string]: VerboseTree<THandle>;\n\t\t };\n}\n\n/**\n * Options for how to interpret a `VerboseTree<TCustom>` when schema information is available.\n * @alpha\n */\nexport interface ParseOptions<TCustom> {\n\t/**\n\t * Fixup custom input formats.\n\t * @remarks\n\t * Main usage is to handle IFluidHandles.\n\t * When targeting JSON compatibility,\n\t * this may be by throwing an error or including a placeholder.\n\t * Since IFluidHandles are special references to FLuid data which is garbage collected when not referenced by the container for long enough,\n\t * any scheme for encoding handles for storage outside the container (or in formats the container does not understand) is unreliable.\n\t */\n\tvalueConverter(data: VerboseTree<TCustom>): TreeLeafValue | VerboseTreeNode<TCustom>;\n\t/**\n\t * If true, interpret the input keys of object nodes as stored keys.\n\t * If false, interpret them as property keys.\n\t * @defaultValue false.\n\t */\n\treadonly useStoredKeys?: boolean;\n}\n\n/**\n * Options for how to interpret a `VerboseTree<TCustom>` without relying on schema.\n */\nexport interface SchemalessParseOptions<TCustom> {\n\t/**\n\t * Fixup custom input formats.\n\t * @remarks\n\t * See note on {@link ParseOptions.valueConverter}.\n\t */\n\tvalueConverter(data: VerboseTree<TCustom>): TreeLeafValue | VerboseTreeNode<TCustom>;\n\t/**\n\t * Converts stored keys into whatever key the tree is using in its encoding.\n\t */\n\tkeyConverter?: {\n\t\tparse(type: string, inputKey: string): FieldKey;\n\t\tencode(type: string, key: FieldKey): string;\n\t};\n}\n\n/**\n * Use info from `schema` to convert `options` to {@link SchemalessParseOptions}.\n */\nexport function applySchemaToParserOptions<TCustom>(\n\tschema: ImplicitFieldSchema,\n\toptions: ParseOptions<TCustom>,\n): SchemalessParseOptions<TCustom> {\n\tconst config: Required<ParseOptions<TCustom>> = {\n\t\tuseStoredKeys: false,\n\t\t...options,\n\t};\n\n\tconst context = getUnhydratedContext(schema);\n\n\treturn {\n\t\tvalueConverter: config.valueConverter,\n\t\tkeyConverter: config.useStoredKeys\n\t\t\t? undefined\n\t\t\t: {\n\t\t\t\t\tencode: (type, key: FieldKey): string => {\n\t\t\t\t\t\t// translate stored key into property key.\n\t\t\t\t\t\tconst simpleNodeSchema = context.schema.get(brand(type)) ?? fail(\"missing schema\");\n\t\t\t\t\t\tif (isObjectNodeSchema(simpleNodeSchema)) {\n\t\t\t\t\t\t\tconst propertyKey = simpleNodeSchema.storedKeyToPropertyKey.get(key);\n\t\t\t\t\t\t\tif (propertyKey !== undefined) {\n\t\t\t\t\t\t\t\treturn propertyKey;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Looking up an out of schema key.\n\t\t\t\t\t\t\t// This must point to a non-existent field.\n\t\t\t\t\t\t\t// It's possible that the key, if we returned it unmodified, could point to some data\n\t\t\t\t\t\t\t// (for example if looking up a key which is a stored key already when using property keys).\n\t\t\t\t\t\t\t// Thus return an arbitrary key that was selected randomly, so should not exist on non-adversarial data:\n\t\t\t\t\t\t\tconst arbitrary = \"arbitrary unused key: fe71614a-bf3e-43b3-b7b0-4cef39538e90\";\n\t\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\t\t!simpleNodeSchema.storedKeyToPropertyKey.has(brand(arbitrary)),\n\t\t\t\t\t\t\t\t0xa13 /* arbitrarily selected unused key was actually used */,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn arbitrary;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn key;\n\t\t\t\t\t},\n\t\t\t\t\tparse: (type, inputKey): FieldKey => {\n\t\t\t\t\t\tconst simpleNodeSchema = context.schema.get(brand(type)) ?? fail(\"missing schema\");\n\t\t\t\t\t\tif (isObjectNodeSchema(simpleNodeSchema)) {\n\t\t\t\t\t\t\tconst info =\n\t\t\t\t\t\t\t\tsimpleNodeSchema.flexKeyMap.get(inputKey) ?? fail(\"missing field info\");\n\t\t\t\t\t\t\treturn info.storedKey;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn brand(inputKey);\n\t\t\t\t\t},\n\t\t\t\t},\n\t};\n}\n\n/**\n * Used to read a VerboseTree as a node cursor.\n *\n * @returns an {@link ITreeCursorSynchronous} for a single node in nodes mode.\n */\nexport function cursorFromVerbose<TCustom>(\n\tdata: VerboseTree<TCustom>,\n\toptions: SchemalessParseOptions<TCustom>,\n): ITreeCursorSynchronous {\n\treturn stackTreeNodeCursor(verboseTreeAdapter(options), data);\n}\n\n/**\n * Used to read a VerboseTree[] as a field cursor.\n *\n * @returns an {@link ITreeCursorSynchronous} for a single field in fields mode.\n */\nexport function fieldCursorFromVerbose<TCustom>(\n\tdata: VerboseTree<TCustom>[],\n\toptions: SchemalessParseOptions<TCustom>,\n): ITreeCursorSynchronous {\n\treturn stackTreeFieldCursor(\n\t\tverboseTreeAdapter(options),\n\t\t{ type: aboveRootPlaceholder, fields: data },\n\t\tkeyAsDetachedField(EmptyKey),\n\t);\n}\n\nfunction verboseTreeAdapter<TCustom>(\n\toptions: SchemalessParseOptions<TCustom>,\n): CursorAdapter<VerboseTree<TCustom>> {\n\treturn {\n\t\tvalue: (input: VerboseTree<TCustom>) => {\n\t\t\tconst node = options.valueConverter(input);\n\t\t\treturn isTreeValue(node) ? node : undefined;\n\t\t},\n\t\ttype: (input: VerboseTree<TCustom>) => {\n\t\t\tconst node = options.valueConverter(input);\n\t\t\tswitch (typeof node) {\n\t\t\t\tcase \"number\":\n\t\t\t\t\treturn numberSchema.identifier as TreeNodeSchemaIdentifier;\n\t\t\t\tcase \"string\":\n\t\t\t\t\treturn stringSchema.identifier as TreeNodeSchemaIdentifier;\n\t\t\t\tcase \"boolean\":\n\t\t\t\t\treturn booleanSchema.identifier as TreeNodeSchemaIdentifier;\n\t\t\t\tdefault:\n\t\t\t\t\tif (node === null) {\n\t\t\t\t\t\treturn nullSchema.identifier as TreeNodeSchemaIdentifier;\n\t\t\t\t\t}\n\t\t\t\t\tif (isFluidHandle(node)) {\n\t\t\t\t\t\treturn handleSchema.identifier as TreeNodeSchemaIdentifier;\n\t\t\t\t\t}\n\t\t\t\t\treturn node.type as TreeNodeSchemaIdentifier;\n\t\t\t}\n\t\t},\n\t\tkeysFromNode: (input: VerboseTree<TCustom>): readonly FieldKey[] => {\n\t\t\tconst node = options.valueConverter(input);\n\t\t\tswitch (typeof node) {\n\t\t\t\tcase \"object\": {\n\t\t\t\t\tif (node === null) {\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t}\n\t\t\t\t\tif (isFluidHandle(node)) {\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t}\n\t\t\t\t\tif (Array.isArray(node.fields)) {\n\t\t\t\t\t\treturn node.fields.length === 0 ? [] : [EmptyKey];\n\t\t\t\t\t}\n\n\t\t\t\t\tconst inputKeys = Object.keys(node.fields);\n\t\t\t\t\tconst converter = options.keyConverter;\n\t\t\t\t\tif (converter === undefined) {\n\t\t\t\t\t\treturn inputKeys as FieldKey[];\n\t\t\t\t\t}\n\t\t\t\t\treturn inputKeys.map((k) => converter.parse(node.type, k));\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn [];\n\t\t\t}\n\t\t},\n\t\tgetFieldFromNode: (\n\t\t\tinput: VerboseTree<TCustom>,\n\t\t\tkey: FieldKey,\n\t\t): readonly VerboseTree<TCustom>[] => {\n\t\t\tconst node = options.valueConverter(input);\n\t\t\t// Object.prototype.hasOwnProperty can return true for strings (ex: with key \"0\"), so we have to filter them out.\n\t\t\t// Rather than just special casing strings, we can handle them with an early return for all primitives.\n\t\t\tif (typeof node !== \"object\") {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tif (node === null) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tif (isFluidHandle(node)) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tif (Array.isArray(node.fields)) {\n\t\t\t\treturn key === EmptyKey ? node.fields : [];\n\t\t\t}\n\n\t\t\tconst convertedKey =\n\t\t\t\toptions.keyConverter === undefined ? key : options.keyConverter.encode(node.type, key);\n\n\t\t\tif (Object.prototype.hasOwnProperty.call(node.fields, convertedKey)) {\n\t\t\t\tconst field = node.fields[convertedKey];\n\t\t\t\treturn field === undefined ? [] : [field];\n\t\t\t}\n\n\t\t\treturn [];\n\t\t},\n\t};\n}\n\n/**\n * Used to read a node cursor as a VerboseTree.\n */\nexport function verboseFromCursor<TCustom>(\n\treader: ITreeCursor,\n\trootSchema: ImplicitAllowedTypes,\n\toptions: EncodeOptions<TCustom>,\n): VerboseTree<TCustom> {\n\tconst config: Required<EncodeOptions<TCustom>> = {\n\t\tuseStoredKeys: false,\n\t\t...options,\n\t};\n\n\tconst schemaMap = getUnhydratedContext(rootSchema).schema;\n\n\treturn verboseFromCursorInner(reader, config, schemaMap);\n}\n\nfunction verboseFromCursorInner<TCustom>(\n\treader: ITreeCursor,\n\toptions: Required<EncodeOptions<TCustom>>,\n\tschema: ReadonlyMap<string, TreeNodeSchema>,\n): VerboseTree<TCustom> {\n\tconst fields = customFromCursor(reader, options, schema, verboseFromCursorInner);\n\tconst nodeSchema = schema.get(reader.type) ?? fail(\"missing schema for type in cursor\");\n\tif (nodeSchema.kind === NodeKind.Leaf) {\n\t\treturn fields as CustomTreeValue<TCustom>;\n\t}\n\n\treturn {\n\t\ttype: reader.type,\n\t\tfields: fields as CustomTreeNode<TCustom>,\n\t};\n}\n"]}
1
+ {"version":3,"file":"verboseTree.js","sourceRoot":"","sources":["../../../src/simple-tree/api/verboseTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,OAAO,EACN,oBAAoB,EACpB,QAAQ,EACR,kBAAkB,GAKlB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAMlD,OAAO,EAAE,QAAQ,EAAuB,MAAM,kBAAkB,CAAC;AACjE,OAAO,EACN,WAAW,EACX,oBAAoB,EACpB,m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,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC;gBACrE,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;gBACxC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YAC3C,CAAC;YAED,OAAO,EAAE,CAAC;QACX,CAAC;KACD,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAChC,MAAmB,EACnB,UAAgC,EAChC,OAA+B;IAE/B,MAAM,MAAM,GAAqC;QAChD,aAAa,EAAE,KAAK;QACpB,GAAG,OAAO;KACV,CAAC;IAEF,MAAM,SAAS,GAAG,oBAAoB,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC;IAE1D,OAAO,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,sBAAsB,CAC9B,MAAmB,EACnB,OAAyC,EACzC,MAA2C;IAE3C,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,sBAAsB,CAAC,CAAC;IACjF,MAAM,UAAU,GACf,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAChF,IAAI,UAAU,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,EAAE,CAAC;QACvC,OAAO,MAAkC,CAAC;IAC3C,CAAC;IAED,OAAO;QACN,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,MAAM,EAAE,MAAiC;KACzC,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\taboveRootPlaceholder,\n\tEmptyKey,\n\tkeyAsDetachedField,\n\ttype FieldKey,\n\ttype ITreeCursor,\n\ttype ITreeCursorSynchronous,\n\ttype TreeNodeSchemaIdentifier,\n} from \"../../core/index.js\";\nimport { brand, fail } from \"../../util/index.js\";\nimport type {\n\tTreeLeafValue,\n\tImplicitFieldSchema,\n\tImplicitAllowedTypes,\n} from \"../schemaTypes.js\";\nimport { NodeKind, type TreeNodeSchema } from \"../core/index.js\";\nimport {\n\tisTreeValue,\n\tstackTreeFieldCursor,\n\tstackTreeNodeCursor,\n\ttype CursorAdapter,\n} from \"../../feature-libraries/index.js\";\nimport {\n\tbooleanSchema,\n\thandleSchema,\n\tnullSchema,\n\tnumberSchema,\n\tstringSchema,\n} from \"../leafNodeSchema.js\";\nimport { isObjectNodeSchema } from \"../objectNodeTypes.js\";\nimport {\n\tcustomFromCursor,\n\ttype CustomTreeNode,\n\ttype CustomTreeValue,\n\ttype EncodeOptions,\n} from \"./customTree.js\";\nimport { getUnhydratedContext } from \"../createContext.js\";\n\n/**\n * Verbose encoding of a {@link TreeNode} or {@link TreeLeafValue}.\n * @remarks\n * This is verbose meaning that every {@link TreeNode} is a {@link VerboseTreeNode}.\n * Any IFluidHandle values have been replaced by `THandle`.\n * @privateRemarks\n * This can store all possible simple trees,\n * but it can not store all possible trees representable by our internal representations like FlexTree and JsonableTree.\n * @alpha\n */\nexport type VerboseTree<THandle = IFluidHandle> =\n\t| VerboseTreeNode<THandle>\n\t| Exclude<TreeLeafValue, IFluidHandle>\n\t| THandle;\n\n/**\n * Verbose encoding of a {@link TreeNode}.\n * @remarks\n * This is verbose meaning that every {@link TreeNode} has an explicit `type` property, and `fields`.\n * This allowed VerboseTreeNode to be unambiguous regarding which type each node is without relying on symbols or hidden state.\n *\n * Any IFluidHandle values have been replaced by `THandle`. If the `THandle` is JSON compatible, then this type is JSON compatible as well.\n *\n * @privateRemarks\n * This type is only used for data which is copied into and out of the tree.\n * When being copied out, its fine to have the data be mutable since its a copy.\n *\n * When being copied in, we don't need to mutate, so we could use a readonly variant of this type.\n * however the copy in case (createFromVerbose) probably isn't harmed much by just reusing this type as is,\n * since if the caller has immutable data, TypeScript doesn't prevent assigning immutable data to a mutable type anyway.\n * Also relaxing the input methods to take readonly data would be a non-breaking change so it can be done later if desired.\n *\n * This format is simple-tree specialized alternative to {@link JsonableTree}.\n * This format allows for all simple-tree compatible trees to be represented.\n *\n * Unlike `JsonableTree`, leaf nodes are not boxed into node objects, and instead have their schema inferred from the value.\n * Additionally, sequence fields can only occur on a node that has a single sequence field (with the empty key)\n * replicating the behavior of simple-tree ArrayNodes.\n * @alpha\n */\nexport interface VerboseTreeNode<THandle = IFluidHandle> {\n\t/**\n\t * The meaning of this node.\n\t * Provides contexts/semantics for this node and its content.\n\t * @remarks\n\t * Typically used to associate a node with metadata (including a schema) and source code (types, behaviors, etc).\n\t * When used with this package's schema system, it will be the {@link TreeNodeSchemaCore.identifier}.\n\t */\n\ttype: string;\n\n\t/**\n\t * Content of this node.\n\t * For array nodes, an array of children.\n\t * For map and object nodes, an object which children under keys.\n\t * @remarks\n\t * For object nodes, the keys could be either the stored keys, or the property keys depending on usage.\n\t */\n\tfields:\n\t\t| VerboseTree<THandle>[]\n\t\t| {\n\t\t\t\t[key: string]: VerboseTree<THandle>;\n\t\t };\n}\n\n/**\n * Options for how to interpret a `VerboseTree<TCustom>` when schema information is available.\n * @alpha\n */\nexport interface ParseOptions<TCustom> {\n\t/**\n\t * Fixup custom input formats.\n\t * @remarks\n\t * Main usage is to handle IFluidHandles.\n\t * When targeting JSON compatibility,\n\t * this may be by throwing an error or including a placeholder.\n\t * Since IFluidHandles are special references to FLuid data which is garbage collected when not referenced by the container for long enough,\n\t * any scheme for encoding handles for storage outside the container (or in formats the container does not understand) is unreliable.\n\t */\n\tvalueConverter(data: VerboseTree<TCustom>): TreeLeafValue | VerboseTreeNode<TCustom>;\n\t/**\n\t * If true, interpret the input keys of object nodes as stored keys.\n\t * If false, interpret them as property keys.\n\t * @defaultValue false.\n\t */\n\treadonly useStoredKeys?: boolean;\n}\n\n/**\n * Options for how to interpret a `VerboseTree<TCustom>` without relying on schema.\n */\nexport interface SchemalessParseOptions<TCustom> {\n\t/**\n\t * Fixup custom input formats.\n\t * @remarks\n\t * See note on {@link ParseOptions.valueConverter}.\n\t */\n\tvalueConverter(data: VerboseTree<TCustom>): TreeLeafValue | VerboseTreeNode<TCustom>;\n\t/**\n\t * Converts stored keys into whatever key the tree is using in its encoding.\n\t */\n\tkeyConverter?: {\n\t\tparse(type: string, inputKey: string): FieldKey;\n\t\tencode(type: string, key: FieldKey): string;\n\t};\n}\n\n/**\n * Use info from `schema` to convert `options` to {@link SchemalessParseOptions}.\n */\nexport function applySchemaToParserOptions<TCustom>(\n\tschema: ImplicitFieldSchema,\n\toptions: ParseOptions<TCustom>,\n): SchemalessParseOptions<TCustom> {\n\tconst config: Required<ParseOptions<TCustom>> = {\n\t\tuseStoredKeys: false,\n\t\t...options,\n\t};\n\n\tconst context = getUnhydratedContext(schema);\n\n\treturn {\n\t\tvalueConverter: config.valueConverter,\n\t\tkeyConverter: config.useStoredKeys\n\t\t\t? undefined\n\t\t\t: {\n\t\t\t\t\tencode: (type, key: FieldKey): string => {\n\t\t\t\t\t\t// translate stored key into property key.\n\t\t\t\t\t\tconst simpleNodeSchema =\n\t\t\t\t\t\t\tcontext.schema.get(brand(type)) ?? fail(0xb39 /* missing schema */);\n\t\t\t\t\t\tif (isObjectNodeSchema(simpleNodeSchema)) {\n\t\t\t\t\t\t\tconst propertyKey = simpleNodeSchema.storedKeyToPropertyKey.get(key);\n\t\t\t\t\t\t\tif (propertyKey !== undefined) {\n\t\t\t\t\t\t\t\treturn propertyKey;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Looking up an out of schema key.\n\t\t\t\t\t\t\t// This must point to a non-existent field.\n\t\t\t\t\t\t\t// It's possible that the key, if we returned it unmodified, could point to some data\n\t\t\t\t\t\t\t// (for example if looking up a key which is a stored key already when using property keys).\n\t\t\t\t\t\t\t// Thus return an arbitrary key that was selected randomly, so should not exist on non-adversarial data:\n\t\t\t\t\t\t\tconst arbitrary = \"arbitrary unused key: fe71614a-bf3e-43b3-b7b0-4cef39538e90\";\n\t\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\t\t!simpleNodeSchema.storedKeyToPropertyKey.has(brand(arbitrary)),\n\t\t\t\t\t\t\t\t0xa13 /* arbitrarily selected unused key was actually used */,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn arbitrary;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn key;\n\t\t\t\t\t},\n\t\t\t\t\tparse: (type, inputKey): FieldKey => {\n\t\t\t\t\t\tconst simpleNodeSchema =\n\t\t\t\t\t\t\tcontext.schema.get(brand(type)) ?? fail(0xb3a /* missing schema */);\n\t\t\t\t\t\tif (isObjectNodeSchema(simpleNodeSchema)) {\n\t\t\t\t\t\t\tconst info =\n\t\t\t\t\t\t\t\tsimpleNodeSchema.flexKeyMap.get(inputKey) ??\n\t\t\t\t\t\t\t\tfail(0xb3b /* missing field info */);\n\t\t\t\t\t\t\treturn info.storedKey;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn brand(inputKey);\n\t\t\t\t\t},\n\t\t\t\t},\n\t};\n}\n\n/**\n * Used to read a VerboseTree as a node cursor.\n *\n * @returns an {@link ITreeCursorSynchronous} for a single node in nodes mode.\n */\nexport function cursorFromVerbose<TCustom>(\n\tdata: VerboseTree<TCustom>,\n\toptions: SchemalessParseOptions<TCustom>,\n): ITreeCursorSynchronous {\n\treturn stackTreeNodeCursor(verboseTreeAdapter(options), data);\n}\n\n/**\n * Used to read a VerboseTree[] as a field cursor.\n *\n * @returns an {@link ITreeCursorSynchronous} for a single field in fields mode.\n */\nexport function fieldCursorFromVerbose<TCustom>(\n\tdata: VerboseTree<TCustom>[],\n\toptions: SchemalessParseOptions<TCustom>,\n): ITreeCursorSynchronous {\n\treturn stackTreeFieldCursor(\n\t\tverboseTreeAdapter(options),\n\t\t{ type: aboveRootPlaceholder, fields: data },\n\t\tkeyAsDetachedField(EmptyKey),\n\t);\n}\n\nfunction verboseTreeAdapter<TCustom>(\n\toptions: SchemalessParseOptions<TCustom>,\n): CursorAdapter<VerboseTree<TCustom>> {\n\treturn {\n\t\tvalue: (input: VerboseTree<TCustom>) => {\n\t\t\tconst node = options.valueConverter(input);\n\t\t\treturn isTreeValue(node) ? node : undefined;\n\t\t},\n\t\ttype: (input: VerboseTree<TCustom>) => {\n\t\t\tconst node = options.valueConverter(input);\n\t\t\tswitch (typeof node) {\n\t\t\t\tcase \"number\":\n\t\t\t\t\treturn numberSchema.identifier as TreeNodeSchemaIdentifier;\n\t\t\t\tcase \"string\":\n\t\t\t\t\treturn stringSchema.identifier as TreeNodeSchemaIdentifier;\n\t\t\t\tcase \"boolean\":\n\t\t\t\t\treturn booleanSchema.identifier as TreeNodeSchemaIdentifier;\n\t\t\t\tdefault:\n\t\t\t\t\tif (node === null) {\n\t\t\t\t\t\treturn nullSchema.identifier as TreeNodeSchemaIdentifier;\n\t\t\t\t\t}\n\t\t\t\t\tif (isFluidHandle(node)) {\n\t\t\t\t\t\treturn handleSchema.identifier as TreeNodeSchemaIdentifier;\n\t\t\t\t\t}\n\t\t\t\t\treturn node.type as TreeNodeSchemaIdentifier;\n\t\t\t}\n\t\t},\n\t\tkeysFromNode: (input: VerboseTree<TCustom>): readonly FieldKey[] => {\n\t\t\tconst node = options.valueConverter(input);\n\t\t\tswitch (typeof node) {\n\t\t\t\tcase \"object\": {\n\t\t\t\t\tif (node === null) {\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t}\n\t\t\t\t\tif (isFluidHandle(node)) {\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t}\n\t\t\t\t\tif (Array.isArray(node.fields)) {\n\t\t\t\t\t\treturn node.fields.length === 0 ? [] : [EmptyKey];\n\t\t\t\t\t}\n\n\t\t\t\t\tconst inputKeys = Object.keys(node.fields);\n\t\t\t\t\tconst converter = options.keyConverter;\n\t\t\t\t\tif (converter === undefined) {\n\t\t\t\t\t\treturn inputKeys as FieldKey[];\n\t\t\t\t\t}\n\t\t\t\t\treturn inputKeys.map((k) => converter.parse(node.type, k));\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn [];\n\t\t\t}\n\t\t},\n\t\tgetFieldFromNode: (\n\t\t\tinput: VerboseTree<TCustom>,\n\t\t\tkey: FieldKey,\n\t\t): readonly VerboseTree<TCustom>[] => {\n\t\t\tconst node = options.valueConverter(input);\n\t\t\t// Object.prototype.hasOwnProperty can return true for strings (ex: with key \"0\"), so we have to filter them out.\n\t\t\t// Rather than just special casing strings, we can handle them with an early return for all primitives.\n\t\t\tif (typeof node !== \"object\") {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tif (node === null) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tif (isFluidHandle(node)) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tif (Array.isArray(node.fields)) {\n\t\t\t\treturn key === EmptyKey ? node.fields : [];\n\t\t\t}\n\n\t\t\tconst convertedKey =\n\t\t\t\toptions.keyConverter === undefined ? key : options.keyConverter.encode(node.type, key);\n\n\t\t\tif (Object.prototype.hasOwnProperty.call(node.fields, convertedKey)) {\n\t\t\t\tconst field = node.fields[convertedKey];\n\t\t\t\treturn field === undefined ? [] : [field];\n\t\t\t}\n\n\t\t\treturn [];\n\t\t},\n\t};\n}\n\n/**\n * Used to read a node cursor as a VerboseTree.\n */\nexport function verboseFromCursor<TCustom>(\n\treader: ITreeCursor,\n\trootSchema: ImplicitAllowedTypes,\n\toptions: EncodeOptions<TCustom>,\n): VerboseTree<TCustom> {\n\tconst config: Required<EncodeOptions<TCustom>> = {\n\t\tuseStoredKeys: false,\n\t\t...options,\n\t};\n\n\tconst schemaMap = getUnhydratedContext(rootSchema).schema;\n\n\treturn verboseFromCursorInner(reader, config, schemaMap);\n}\n\nfunction verboseFromCursorInner<TCustom>(\n\treader: ITreeCursor,\n\toptions: Required<EncodeOptions<TCustom>>,\n\tschema: ReadonlyMap<string, TreeNodeSchema>,\n): VerboseTree<TCustom> {\n\tconst fields = customFromCursor(reader, options, schema, verboseFromCursorInner);\n\tconst nodeSchema =\n\t\tschema.get(reader.type) ?? fail(0xb3c /* missing schema for type in cursor */);\n\tif (nodeSchema.kind === NodeKind.Leaf) {\n\t\treturn fields as CustomTreeValue<TCustom>;\n\t}\n\n\treturn {\n\t\ttype: reader.type,\n\t\tfields: fields as CustomTreeNode<TCustom>,\n\t};\n}\n"]}
@@ -169,7 +169,7 @@ export class ViewSchema {
169
169
  // (unless its input is also never).
170
170
  for (const adapter of this.adapters?.tree ?? []) {
171
171
  if (isNeverTree(this.policy, this.viewSchemaAsStored, this.viewSchemaAsStored.nodeSchema.get(adapter.output))) {
172
- fail("tree adapter for stored adapter.output should not be never");
172
+ fail(0xb3d /* tree adapter for stored adapter.output should not be never */);
173
173
  }
174
174
  }
175
175
  const adapted = {
@@ -1 +1 @@
1
- {"version":3,"file":"view.js","sourceRoot":"","sources":["../../../src/simple-tree/api/view.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,iBAAiB,GAMjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EACN,UAAU,EAGV,8BAA8B,EAC9B,WAAW,EACX,qBAAqB,EACrB,aAAa,EACb,oBAAoB,GACpB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACN,oBAAoB,GAGpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAGtE;;GAEG;AACH,MAAM,OAAO,UAAU;IAUtB;;OAEG;IACH,YACiB,MAAwB,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AEF,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YAC/C,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YAC5C,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;QAC3C,CAAC;QAED,iEAAiE;QACjE,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;IAED;;OAEG;IACK,UAAU,CAAC,QAA+B;QACjD,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAClC,MAAM,KAAK,GAAkC,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACrE,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,QAAQ,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC;gBACrD,IAAI,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;oBAClC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;oBAChC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;gBAC/B,CAAC;YACF,CAAC;YAED,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;QACvC,CAAC;QACD,OAAO,QAAQ,CAAC;IACjB,CAAC;IAEO,SAAS,CAAC,QAA8B;QAC/C,sDAAsD;QACtD,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tAdaptedViewSchema,\n\ttype TreeNodeStoredSchema,\n\ttype Adapters,\n\ttype TreeFieldStoredSchema,\n\ttype TreeNodeSchemaIdentifier,\n\ttype TreeStoredSchema,\n} from \"../../core/index.js\";\nimport { fail } from \"../../util/index.js\";\nimport {\n\tFieldKinds,\n\ttype FullSchemaPolicy,\n\ttype FieldDiscrepancy,\n\tgetAllowedContentDiscrepancies,\n\tisNeverTree,\n\tPosetComparisonResult,\n\tfieldRealizer,\n\tcomparePosetElements,\n} from \"../../feature-libraries/index.js\";\nimport {\n\tnormalizeFieldSchema,\n\ttype FieldSchema,\n\ttype ImplicitFieldSchema,\n} from \"../schemaTypes.js\";\nimport { toStoredSchema } from \"../toStoredSchema.js\";\nimport { unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport type { SchemaCompatibilityStatus } from \"./tree.js\";\n\n/**\n * A collection of View information for schema, including policy.\n */\nexport class ViewSchema {\n\t/**\n\t * Cached conversion of the view schema in the stored schema format.\n\t */\n\tprivate readonly viewSchemaAsStored: TreeStoredSchema;\n\t/**\n\t * Normalized view schema (implicitly allowed view schema types are converted to their canonical form).\n\t */\n\tpublic readonly schema: FieldSchema;\n\n\t/**\n\t * @param viewSchema - Schema for the root field of this view.\n\t */\n\tpublic constructor(\n\t\tpublic readonly policy: FullSchemaPolicy,\n\t\tpublic readonly adapters: Adapters,\n\t\tviewSchema: ImplicitFieldSchema,\n\t) {\n\t\tthis.schema = normalizeFieldSchema(viewSchema);\n\t\tthis.viewSchemaAsStored = toStoredSchema(this.schema);\n\t}\n\n\t/**\n\t * Determines the compatibility of a stored document\n\t * (based on its stored schema) with a viewer (based on its view schema).\n\t *\n\t * Adapters can be provided to handle differences between the two schema.\n\t * Adapters should only use to types in the `view` SchemaRepository.\n\t *\n\t * TODO: this API violates the parse don't validate design philosophy.\n\t * It should be wrapped with (or replaced by) a parse style API.\n\t */\n\tpublic checkCompatibility(\n\t\tstored: TreeStoredSchema,\n\t): Omit<SchemaCompatibilityStatus, \"canInitialize\"> {\n\t\t// TODO: support adapters\n\t\t// const adapted = this.adaptRepo(stored);\n\n\t\t// View schema allows a subset of documents that stored schema does, and the discrepancies are allowed by policy\n\t\t// determined by the view schema (i.e. objects with extra optional fields in the stored schema have opted into allowing this.\n\t\t// In the future, this would also include things like:\n\t\t// - fields with more allowed types in the stored schema than in the view schema have out-of-schema \"unknown content\" adapters\n\t\tlet canView = true;\n\t\t// View schema allows a superset of documents that stored schema does, hence the document could be upgraded to use a persisted version\n\t\t// of this view schema as its stored schema.\n\t\tlet canUpgrade = true;\n\n\t\tconst updateCompatibilityFromFieldDiscrepancy = (discrepancy: FieldDiscrepancy): void => {\n\t\t\tswitch (discrepancy.mismatch) {\n\t\t\t\tcase \"allowedTypes\": {\n\t\t\t\t\t// Since we only track the symmetric difference between the allowed types in the view and\n\t\t\t\t\t// stored schemas, it's sufficient to check if any extra allowed types still exist in the\n\t\t\t\t\t// stored schema.\n\t\t\t\t\tif (\n\t\t\t\t\t\tdiscrepancy.stored.some(\n\t\t\t\t\t\t\t(identifier) =>\n\t\t\t\t\t\t\t\t!isNeverTree(this.policy, stored, stored.nodeSchema.get(identifier)),\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\t// Stored schema has extra allowed types that the view schema does not.\n\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tdiscrepancy.view.some(\n\t\t\t\t\t\t\t(identifier) =>\n\t\t\t\t\t\t\t\t!isNeverTree(\n\t\t\t\t\t\t\t\t\tthis.policy,\n\t\t\t\t\t\t\t\t\tthis.viewSchemaAsStored,\n\t\t\t\t\t\t\t\t\tthis.viewSchemaAsStored.nodeSchema.get(identifier),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\t// View schema has extra allowed types that the stored schema does not.\n\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"fieldKind\": {\n\t\t\t\t\tconst result = comparePosetElements(\n\t\t\t\t\t\tdiscrepancy.stored,\n\t\t\t\t\t\tdiscrepancy.view,\n\t\t\t\t\t\tfieldRealizer,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (result === PosetComparisonResult.Greater) {\n\t\t\t\t\t\t// Stored schema is more relaxed than view schema.\n\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tdiscrepancy.view === FieldKinds.forbidden.identifier &&\n\t\t\t\t\t\t\tdiscrepancy.identifier !== undefined &&\n\t\t\t\t\t\t\tthis.policy.allowUnknownOptionalFields(discrepancy.identifier)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// When the application has opted into it, we allow viewing documents which have additional\n\t\t\t\t\t\t\t// optional fields in the stored schema that are not present in the view schema.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (result === PosetComparisonResult.Less) {\n\t\t\t\t\t\t// View schema is more relaxed than stored schema.\n\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (result === PosetComparisonResult.Incomparable) {\n\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"valueSchema\": {\n\t\t\t\t\tcanView = false;\n\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tunreachableCase(discrepancy);\n\t\t\t}\n\t\t};\n\n\t\tfor (const discrepancy of getAllowedContentDiscrepancies(\n\t\t\tthis.viewSchemaAsStored,\n\t\t\tstored,\n\t\t)) {\n\t\t\tif (!canView && !canUpgrade) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tswitch (discrepancy.mismatch) {\n\t\t\t\tcase \"nodeKind\": {\n\t\t\t\t\tconst viewNodeSchema = this.viewSchemaAsStored.nodeSchema.get(\n\t\t\t\t\t\tdiscrepancy.identifier,\n\t\t\t\t\t);\n\t\t\t\t\tconst storedNodeSchema = stored.nodeSchema.get(discrepancy.identifier);\n\t\t\t\t\t// We conservatively do not allow node types to change.\n\t\t\t\t\t// The only time this might be valid in the sense that the data canonically converts is converting an object node\n\t\t\t\t\t// to a map node over the union of all the object fields' types.\n\t\t\t\t\tif (discrepancy.stored === undefined) {\n\t\t\t\t\t\tconst viewIsNever =\n\t\t\t\t\t\t\tviewNodeSchema !== undefined\n\t\t\t\t\t\t\t\t? isNeverTree(this.policy, this.viewSchemaAsStored, viewNodeSchema)\n\t\t\t\t\t\t\t\t: true;\n\t\t\t\t\t\tif (!viewIsNever) {\n\t\t\t\t\t\t\t// View schema has added a node type that the stored schema doesn't know about.\n\t\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (discrepancy.view === undefined) {\n\t\t\t\t\t\tconst storedIsNever =\n\t\t\t\t\t\t\tstoredNodeSchema !== undefined\n\t\t\t\t\t\t\t\t? isNeverTree(this.policy, stored, storedNodeSchema)\n\t\t\t\t\t\t\t\t: true;\n\t\t\t\t\t\tif (!storedIsNever) {\n\t\t\t\t\t\t\t// Stored schema has a node type that the view schema doesn't know about.\n\t\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Node type exists in both schemas but has changed. We conservatively never allow this.\n\t\t\t\t\t\tconst storedIsNever =\n\t\t\t\t\t\t\tstoredNodeSchema !== undefined\n\t\t\t\t\t\t\t\t? isNeverTree(this.policy, stored, storedNodeSchema)\n\t\t\t\t\t\t\t\t: true;\n\t\t\t\t\t\tconst viewIsNever =\n\t\t\t\t\t\t\tviewNodeSchema !== undefined\n\t\t\t\t\t\t\t\t? isNeverTree(this.policy, this.viewSchemaAsStored, viewNodeSchema)\n\t\t\t\t\t\t\t\t: true;\n\t\t\t\t\t\tif (!storedIsNever || !viewIsNever) {\n\t\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"valueSchema\":\n\t\t\t\tcase \"allowedTypes\":\n\t\t\t\tcase \"fieldKind\": {\n\t\t\t\t\tupdateCompatibilityFromFieldDiscrepancy(discrepancy);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"fields\": {\n\t\t\t\t\tdiscrepancy.differences.forEach(updateCompatibilityFromFieldDiscrepancy);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t// No default\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tcanView,\n\t\t\tcanUpgrade,\n\t\t\tisEquivalent: canView && canUpgrade,\n\t\t};\n\t}\n\n\t/**\n\t * Compute a schema that `original` could be viewed as using adapters as needed.\n\t *\n\t * TODO: have a way for callers to get invalidated on schema updates.\n\t */\n\tpublic adaptRepo(stored: TreeStoredSchema): AdaptedViewSchema {\n\t\t// Sanity check on adapters:\n\t\t// it's probably a bug if they use the never types,\n\t\t// since there never is a reason to have a never type as an adapter input,\n\t\t// and its impossible for an adapter to be correctly implemented if its output type is never\n\t\t// (unless its input is also never).\n\n\t\tfor (const adapter of this.adapters?.tree ?? []) {\n\t\t\tif (\n\t\t\t\tisNeverTree(\n\t\t\t\t\tthis.policy,\n\t\t\t\t\tthis.viewSchemaAsStored,\n\t\t\t\t\tthis.viewSchemaAsStored.nodeSchema.get(adapter.output),\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tfail(\"tree adapter for stored adapter.output should not be never\");\n\t\t\t}\n\t\t}\n\n\t\tconst adapted = {\n\t\t\trootFieldSchema: this.adaptField(stored.rootFieldSchema),\n\t\t\tnodeSchema: new Map<TreeNodeSchemaIdentifier, TreeNodeStoredSchema>(),\n\t\t};\n\n\t\tfor (const [key, schema] of stored.nodeSchema) {\n\t\t\tconst adapatedTree = this.adaptTree(schema);\n\t\t\tadapted.nodeSchema.set(key, adapatedTree);\n\t\t}\n\n\t\t// TODO: subset these adapters to the ones that were needed/used.\n\t\treturn new AdaptedViewSchema(this.adapters, adapted);\n\t}\n\n\t/**\n\t * Adapt original such that it allows member types which can be adapted to its specified types.\n\t */\n\tprivate adaptField(original: TreeFieldStoredSchema): TreeFieldStoredSchema {\n\t\tif (original.types !== undefined) {\n\t\t\tconst types: Set<TreeNodeSchemaIdentifier> = new Set(original.types);\n\t\t\tfor (const treeAdapter of this.adapters?.tree ?? []) {\n\t\t\t\tif (types.has(treeAdapter.input)) {\n\t\t\t\t\ttypes.delete(treeAdapter.input);\n\t\t\t\t\ttypes.add(treeAdapter.output);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { kind: original.kind, types };\n\t\t}\n\t\treturn original;\n\t}\n\n\tprivate adaptTree(original: TreeNodeStoredSchema): TreeNodeStoredSchema {\n\t\t// TODO: support adapters like missing field adapters.\n\t\treturn original;\n\t}\n}\n"]}
1
+ {"version":3,"file":"view.js","sourceRoot":"","sources":["../../../src/simple-tree/api/view.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,iBAAiB,GAMjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EACN,UAAU,EAGV,8BAA8B,EAC9B,WAAW,EACX,qBAAqB,EACrB,aAAa,EACb,oBAAoB,GACpB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACN,oBAAoB,GAGpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAGtE;;GAEG;AACH,MAAM,OAAO,UAAU;IAUtB;;OAEG;IACH,YACiB,MAAwB,EACxB,QAAkB,EAClC,UAA+B;QAFf,WAAM,GAAN,MAAM,CAAkB;QACxB,aAAQ,GAAR,QAAQ,CAAU;QAGlC,I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C/C,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YAC5C,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;QAC3C,CAAC;QAED,iEAAiE;QACjE,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;IAED;;OAEG;IACK,UAAU,CAAC,QAA+B;QACjD,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAClC,MAAM,KAAK,GAAkC,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACrE,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,QAAQ,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC;gBACrD,IAAI,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;oBAClC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;oBAChC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;gBAC/B,CAAC;YACF,CAAC;YAED,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;QACvC,CAAC;QACD,OAAO,QAAQ,CAAC;IACjB,CAAC;IAEO,SAAS,CAAC,QAA8B;QAC/C,sDAAsD;QACtD,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tAdaptedViewSchema,\n\ttype TreeNodeStoredSchema,\n\ttype Adapters,\n\ttype TreeFieldStoredSchema,\n\ttype TreeNodeSchemaIdentifier,\n\ttype TreeStoredSchema,\n} from \"../../core/index.js\";\nimport { fail } from \"../../util/index.js\";\nimport {\n\tFieldKinds,\n\ttype FullSchemaPolicy,\n\ttype FieldDiscrepancy,\n\tgetAllowedContentDiscrepancies,\n\tisNeverTree,\n\tPosetComparisonResult,\n\tfieldRealizer,\n\tcomparePosetElements,\n} from \"../../feature-libraries/index.js\";\nimport {\n\tnormalizeFieldSchema,\n\ttype FieldSchema,\n\ttype ImplicitFieldSchema,\n} from \"../schemaTypes.js\";\nimport { toStoredSchema } from \"../toStoredSchema.js\";\nimport { unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport type { SchemaCompatibilityStatus } from \"./tree.js\";\n\n/**\n * A collection of View information for schema, including policy.\n */\nexport class ViewSchema {\n\t/**\n\t * Cached conversion of the view schema in the stored schema format.\n\t */\n\tprivate readonly viewSchemaAsStored: TreeStoredSchema;\n\t/**\n\t * Normalized view schema (implicitly allowed view schema types are converted to their canonical form).\n\t */\n\tpublic readonly schema: FieldSchema;\n\n\t/**\n\t * @param viewSchema - Schema for the root field of this view.\n\t */\n\tpublic constructor(\n\t\tpublic readonly policy: FullSchemaPolicy,\n\t\tpublic readonly adapters: Adapters,\n\t\tviewSchema: ImplicitFieldSchema,\n\t) {\n\t\tthis.schema = normalizeFieldSchema(viewSchema);\n\t\tthis.viewSchemaAsStored = toStoredSchema(this.schema);\n\t}\n\n\t/**\n\t * Determines the compatibility of a stored document\n\t * (based on its stored schema) with a viewer (based on its view schema).\n\t *\n\t * Adapters can be provided to handle differences between the two schema.\n\t * Adapters should only use to types in the `view` SchemaRepository.\n\t *\n\t * TODO: this API violates the parse don't validate design philosophy.\n\t * It should be wrapped with (or replaced by) a parse style API.\n\t */\n\tpublic checkCompatibility(\n\t\tstored: TreeStoredSchema,\n\t): Omit<SchemaCompatibilityStatus, \"canInitialize\"> {\n\t\t// TODO: support adapters\n\t\t// const adapted = this.adaptRepo(stored);\n\n\t\t// View schema allows a subset of documents that stored schema does, and the discrepancies are allowed by policy\n\t\t// determined by the view schema (i.e. objects with extra optional fields in the stored schema have opted into allowing this.\n\t\t// In the future, this would also include things like:\n\t\t// - fields with more allowed types in the stored schema than in the view schema have out-of-schema \"unknown content\" adapters\n\t\tlet canView = true;\n\t\t// View schema allows a superset of documents that stored schema does, hence the document could be upgraded to use a persisted version\n\t\t// of this view schema as its stored schema.\n\t\tlet canUpgrade = true;\n\n\t\tconst updateCompatibilityFromFieldDiscrepancy = (discrepancy: FieldDiscrepancy): void => {\n\t\t\tswitch (discrepancy.mismatch) {\n\t\t\t\tcase \"allowedTypes\": {\n\t\t\t\t\t// Since we only track the symmetric difference between the allowed types in the view and\n\t\t\t\t\t// stored schemas, it's sufficient to check if any extra allowed types still exist in the\n\t\t\t\t\t// stored schema.\n\t\t\t\t\tif (\n\t\t\t\t\t\tdiscrepancy.stored.some(\n\t\t\t\t\t\t\t(identifier) =>\n\t\t\t\t\t\t\t\t!isNeverTree(this.policy, stored, stored.nodeSchema.get(identifier)),\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\t// Stored schema has extra allowed types that the view schema does not.\n\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tdiscrepancy.view.some(\n\t\t\t\t\t\t\t(identifier) =>\n\t\t\t\t\t\t\t\t!isNeverTree(\n\t\t\t\t\t\t\t\t\tthis.policy,\n\t\t\t\t\t\t\t\t\tthis.viewSchemaAsStored,\n\t\t\t\t\t\t\t\t\tthis.viewSchemaAsStored.nodeSchema.get(identifier),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\t// View schema has extra allowed types that the stored schema does not.\n\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"fieldKind\": {\n\t\t\t\t\tconst result = comparePosetElements(\n\t\t\t\t\t\tdiscrepancy.stored,\n\t\t\t\t\t\tdiscrepancy.view,\n\t\t\t\t\t\tfieldRealizer,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (result === PosetComparisonResult.Greater) {\n\t\t\t\t\t\t// Stored schema is more relaxed than view schema.\n\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tdiscrepancy.view === FieldKinds.forbidden.identifier &&\n\t\t\t\t\t\t\tdiscrepancy.identifier !== undefined &&\n\t\t\t\t\t\t\tthis.policy.allowUnknownOptionalFields(discrepancy.identifier)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// When the application has opted into it, we allow viewing documents which have additional\n\t\t\t\t\t\t\t// optional fields in the stored schema that are not present in the view schema.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (result === PosetComparisonResult.Less) {\n\t\t\t\t\t\t// View schema is more relaxed than stored schema.\n\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (result === PosetComparisonResult.Incomparable) {\n\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"valueSchema\": {\n\t\t\t\t\tcanView = false;\n\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tunreachableCase(discrepancy);\n\t\t\t}\n\t\t};\n\n\t\tfor (const discrepancy of getAllowedContentDiscrepancies(\n\t\t\tthis.viewSchemaAsStored,\n\t\t\tstored,\n\t\t)) {\n\t\t\tif (!canView && !canUpgrade) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tswitch (discrepancy.mismatch) {\n\t\t\t\tcase \"nodeKind\": {\n\t\t\t\t\tconst viewNodeSchema = this.viewSchemaAsStored.nodeSchema.get(\n\t\t\t\t\t\tdiscrepancy.identifier,\n\t\t\t\t\t);\n\t\t\t\t\tconst storedNodeSchema = stored.nodeSchema.get(discrepancy.identifier);\n\t\t\t\t\t// We conservatively do not allow node types to change.\n\t\t\t\t\t// The only time this might be valid in the sense that the data canonically converts is converting an object node\n\t\t\t\t\t// to a map node over the union of all the object fields' types.\n\t\t\t\t\tif (discrepancy.stored === undefined) {\n\t\t\t\t\t\tconst viewIsNever =\n\t\t\t\t\t\t\tviewNodeSchema !== undefined\n\t\t\t\t\t\t\t\t? isNeverTree(this.policy, this.viewSchemaAsStored, viewNodeSchema)\n\t\t\t\t\t\t\t\t: true;\n\t\t\t\t\t\tif (!viewIsNever) {\n\t\t\t\t\t\t\t// View schema has added a node type that the stored schema doesn't know about.\n\t\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (discrepancy.view === undefined) {\n\t\t\t\t\t\tconst storedIsNever =\n\t\t\t\t\t\t\tstoredNodeSchema !== undefined\n\t\t\t\t\t\t\t\t? isNeverTree(this.policy, stored, storedNodeSchema)\n\t\t\t\t\t\t\t\t: true;\n\t\t\t\t\t\tif (!storedIsNever) {\n\t\t\t\t\t\t\t// Stored schema has a node type that the view schema doesn't know about.\n\t\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Node type exists in both schemas but has changed. We conservatively never allow this.\n\t\t\t\t\t\tconst storedIsNever =\n\t\t\t\t\t\t\tstoredNodeSchema !== undefined\n\t\t\t\t\t\t\t\t? isNeverTree(this.policy, stored, storedNodeSchema)\n\t\t\t\t\t\t\t\t: true;\n\t\t\t\t\t\tconst viewIsNever =\n\t\t\t\t\t\t\tviewNodeSchema !== undefined\n\t\t\t\t\t\t\t\t? isNeverTree(this.policy, this.viewSchemaAsStored, viewNodeSchema)\n\t\t\t\t\t\t\t\t: true;\n\t\t\t\t\t\tif (!storedIsNever || !viewIsNever) {\n\t\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"valueSchema\":\n\t\t\t\tcase \"allowedTypes\":\n\t\t\t\tcase \"fieldKind\": {\n\t\t\t\t\tupdateCompatibilityFromFieldDiscrepancy(discrepancy);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"fields\": {\n\t\t\t\t\tdiscrepancy.differences.forEach(updateCompatibilityFromFieldDiscrepancy);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t// No default\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tcanView,\n\t\t\tcanUpgrade,\n\t\t\tisEquivalent: canView && canUpgrade,\n\t\t};\n\t}\n\n\t/**\n\t * Compute a schema that `original` could be viewed as using adapters as needed.\n\t *\n\t * TODO: have a way for callers to get invalidated on schema updates.\n\t */\n\tpublic adaptRepo(stored: TreeStoredSchema): AdaptedViewSchema {\n\t\t// Sanity check on adapters:\n\t\t// it's probably a bug if they use the never types,\n\t\t// since there never is a reason to have a never type as an adapter input,\n\t\t// and its impossible for an adapter to be correctly implemented if its output type is never\n\t\t// (unless its input is also never).\n\n\t\tfor (const adapter of this.adapters?.tree ?? []) {\n\t\t\tif (\n\t\t\t\tisNeverTree(\n\t\t\t\t\tthis.policy,\n\t\t\t\t\tthis.viewSchemaAsStored,\n\t\t\t\t\tthis.viewSchemaAsStored.nodeSchema.get(adapter.output),\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tfail(0xb3d /* tree adapter for stored adapter.output should not be never */);\n\t\t\t}\n\t\t}\n\n\t\tconst adapted = {\n\t\t\trootFieldSchema: this.adaptField(stored.rootFieldSchema),\n\t\t\tnodeSchema: new Map<TreeNodeSchemaIdentifier, TreeNodeStoredSchema>(),\n\t\t};\n\n\t\tfor (const [key, schema] of stored.nodeSchema) {\n\t\t\tconst adapatedTree = this.adaptTree(schema);\n\t\t\tadapted.nodeSchema.set(key, adapatedTree);\n\t\t}\n\n\t\t// TODO: subset these adapters to the ones that were needed/used.\n\t\treturn new AdaptedViewSchema(this.adapters, adapted);\n\t}\n\n\t/**\n\t * Adapt original such that it allows member types which can be adapted to its specified types.\n\t */\n\tprivate adaptField(original: TreeFieldStoredSchema): TreeFieldStoredSchema {\n\t\tif (original.types !== undefined) {\n\t\t\tconst types: Set<TreeNodeSchemaIdentifier> = new Set(original.types);\n\t\t\tfor (const treeAdapter of this.adapters?.tree ?? []) {\n\t\t\t\tif (types.has(treeAdapter.input)) {\n\t\t\t\t\ttypes.delete(treeAdapter.input);\n\t\t\t\t\ttypes.add(treeAdapter.output);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { kind: original.kind, types };\n\t\t}\n\t\treturn original;\n\t}\n\n\tprivate adaptTree(original: TreeNodeStoredSchema): TreeNodeStoredSchema {\n\t\t// TODO: support adapters like missing field adapters.\n\t\treturn original;\n\t}\n}\n"]}
@@ -276,7 +276,7 @@ class CustomArrayNodeBase extends TreeNodeWithArrayFeatures {
276
276
  // Therefore it must include `length`,
277
277
  // even though this "length" is never invoked (due to being shadowed by the proxy provided own property).
278
278
  get length() {
279
- return fail("Proxy should intercept length");
279
+ return fail(0xadb /* Proxy should intercept length */);
280
280
  }
281
281
  [(_CustomArrayNodeBase_instances = new WeakSet(), _CustomArrayNodeBase_mapTreesFromFieldData = function _CustomArrayNodeBase_mapTreesFromFieldData(value) {
282
282
  const sequenceField = getSequenceField(this);
@@ -415,7 +415,7 @@ class CustomArrayNodeBase extends TreeNodeWithArrayFeatures {
415
415
  throw new UsageError(`Concurrent editing and iteration is not allowed.`);
416
416
  }
417
417
  for (let i = 0; i < this.length; i++) {
418
- yield this.at(i) ?? fail("Index is out of bounds");
418
+ yield this.at(i) ?? fail(0xadc /* Index is out of bounds */);
419
419
  if (initialLastUpdatedStamp !== kernel.generationNumber) {
420
420
  throw new UsageError(`Concurrent editing and iteration is not allowed.`);
421
421
  }