@fluidframework/tree 2.11.0 → 2.12.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 (537) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/api-report/tree.alpha.api.md +2 -2
  3. package/api-report/tree.beta.api.md +1 -1
  4. package/api-report/tree.legacy.alpha.api.md +1 -1
  5. package/api-report/tree.legacy.public.api.md +1 -1
  6. package/api-report/tree.public.api.md +1 -1
  7. package/dist/core/index.d.ts +2 -2
  8. package/dist/core/index.d.ts.map +1 -1
  9. package/dist/core/index.js +5 -3
  10. package/dist/core/index.js.map +1 -1
  11. package/dist/core/rebase/utils.d.ts.map +1 -1
  12. package/dist/core/rebase/utils.js +2 -9
  13. package/dist/core/rebase/utils.js.map +1 -1
  14. package/dist/core/schema-stored/format.d.ts +0 -3
  15. package/dist/core/schema-stored/format.d.ts.map +1 -1
  16. package/dist/core/schema-stored/format.js.map +1 -1
  17. package/dist/core/schema-stored/schema.d.ts +12 -10
  18. package/dist/core/schema-stored/schema.d.ts.map +1 -1
  19. package/dist/core/schema-stored/schema.js +3 -5
  20. package/dist/core/schema-stored/schema.js.map +1 -1
  21. package/dist/core/schema-view/index.d.ts +1 -1
  22. package/dist/core/schema-view/index.d.ts.map +1 -1
  23. package/dist/core/schema-view/index.js +1 -2
  24. package/dist/core/schema-view/index.js.map +1 -1
  25. package/dist/core/schema-view/view.d.ts +0 -7
  26. package/dist/core/schema-view/view.d.ts.map +1 -1
  27. package/dist/core/schema-view/view.js +1 -12
  28. package/dist/core/schema-view/view.js.map +1 -1
  29. package/dist/{feature-libraries/chunked-forest → core/tree}/chunk.d.ts +2 -1
  30. package/dist/core/tree/chunk.d.ts.map +1 -0
  31. package/dist/{feature-libraries/chunked-forest → core/tree}/chunk.js +2 -2
  32. package/dist/core/tree/chunk.js.map +1 -0
  33. package/dist/core/tree/index.d.ts +1 -0
  34. package/dist/core/tree/index.d.ts.map +1 -1
  35. package/dist/core/tree/index.js +5 -1
  36. package/dist/core/tree/index.js.map +1 -1
  37. package/dist/core/tree/treeTextFormat.d.ts +0 -5
  38. package/dist/core/tree/treeTextFormat.d.ts.map +1 -1
  39. package/dist/core/tree/treeTextFormat.js.map +1 -1
  40. package/dist/core/tree/types.d.ts +0 -5
  41. package/dist/core/tree/types.d.ts.map +1 -1
  42. package/dist/core/tree/types.js +0 -1
  43. package/dist/core/tree/types.js.map +1 -1
  44. package/dist/feature-libraries/chunked-forest/basicChunk.d.ts +1 -2
  45. package/dist/feature-libraries/chunked-forest/basicChunk.d.ts.map +1 -1
  46. package/dist/feature-libraries/chunked-forest/basicChunk.js +14 -14
  47. package/dist/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  48. package/dist/feature-libraries/chunked-forest/chunkTree.d.ts +1 -2
  49. package/dist/feature-libraries/chunked-forest/chunkTree.d.ts.map +1 -1
  50. package/dist/feature-libraries/chunked-forest/chunkTree.js +2 -3
  51. package/dist/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  52. package/dist/feature-libraries/chunked-forest/chunkedForest.d.ts +1 -2
  53. package/dist/feature-libraries/chunked-forest/chunkedForest.d.ts.map +1 -1
  54. package/dist/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  55. package/dist/feature-libraries/chunked-forest/codec/chunkCodecUtilities.d.ts +1 -2
  56. package/dist/feature-libraries/chunked-forest/codec/chunkCodecUtilities.d.ts.map +1 -1
  57. package/dist/feature-libraries/chunked-forest/codec/chunkCodecUtilities.js.map +1 -1
  58. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +1 -2
  59. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  60. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  61. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts +1 -1
  62. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts.map +1 -1
  63. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js.map +1 -1
  64. package/dist/feature-libraries/chunked-forest/emptyChunk.d.ts +1 -1
  65. package/dist/feature-libraries/chunked-forest/emptyChunk.d.ts.map +1 -1
  66. package/dist/feature-libraries/chunked-forest/emptyChunk.js +2 -3
  67. package/dist/feature-libraries/chunked-forest/emptyChunk.js.map +1 -1
  68. package/dist/feature-libraries/chunked-forest/index.d.ts +1 -1
  69. package/dist/feature-libraries/chunked-forest/index.d.ts.map +1 -1
  70. package/dist/feature-libraries/chunked-forest/index.js +5 -5
  71. package/dist/feature-libraries/chunked-forest/index.js.map +1 -1
  72. package/dist/feature-libraries/chunked-forest/sequenceChunk.d.ts +1 -1
  73. package/dist/feature-libraries/chunked-forest/sequenceChunk.d.ts.map +1 -1
  74. package/dist/feature-libraries/chunked-forest/sequenceChunk.js +2 -2
  75. package/dist/feature-libraries/chunked-forest/sequenceChunk.js.map +1 -1
  76. package/dist/feature-libraries/chunked-forest/uniformChunk.d.ts +1 -2
  77. package/dist/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  78. package/dist/feature-libraries/chunked-forest/uniformChunk.js +13 -13
  79. package/dist/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  80. package/dist/feature-libraries/default-schema/defaultSchema.d.ts.map +1 -1
  81. package/dist/feature-libraries/default-schema/defaultSchema.js +1 -0
  82. package/dist/feature-libraries/default-schema/defaultSchema.js.map +1 -1
  83. package/dist/feature-libraries/default-schema/schemaChecker.d.ts.map +1 -1
  84. package/dist/feature-libraries/default-schema/schemaChecker.js +2 -1
  85. package/dist/feature-libraries/default-schema/schemaChecker.js.map +1 -1
  86. package/dist/feature-libraries/index.d.ts +1 -1
  87. package/dist/feature-libraries/index.d.ts.map +1 -1
  88. package/dist/feature-libraries/index.js +6 -2
  89. package/dist/feature-libraries/index.js.map +1 -1
  90. package/dist/feature-libraries/indexing/anchorTreeIndex.d.ts +8 -1
  91. package/dist/feature-libraries/indexing/anchorTreeIndex.d.ts.map +1 -1
  92. package/dist/feature-libraries/indexing/anchorTreeIndex.js +31 -5
  93. package/dist/feature-libraries/indexing/anchorTreeIndex.js.map +1 -1
  94. package/dist/feature-libraries/modular-schema/discrepancies.d.ts +84 -24
  95. package/dist/feature-libraries/modular-schema/discrepancies.d.ts.map +1 -1
  96. package/dist/feature-libraries/modular-schema/discrepancies.js +32 -33
  97. package/dist/feature-libraries/modular-schema/discrepancies.js.map +1 -1
  98. package/dist/feature-libraries/modular-schema/index.d.ts +1 -1
  99. package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
  100. package/dist/feature-libraries/modular-schema/index.js +5 -1
  101. package/dist/feature-libraries/modular-schema/index.js.map +1 -1
  102. package/dist/feature-libraries/modular-schema/isNeverTree.d.ts +0 -1
  103. package/dist/feature-libraries/modular-schema/isNeverTree.d.ts.map +1 -1
  104. package/dist/feature-libraries/modular-schema/isNeverTree.js +0 -1
  105. package/dist/feature-libraries/modular-schema/isNeverTree.js.map +1 -1
  106. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV1.d.ts +6 -6
  107. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV1.d.ts.map +1 -1
  108. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV2.d.ts +7 -7
  109. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV2.d.ts.map +1 -1
  110. package/dist/feature-libraries/schema-edits/schemaChangeFormat.d.ts +12 -12
  111. package/dist/feature-libraries/sequence-field/formatV1.d.ts +99 -99
  112. package/dist/feature-libraries/sequence-field/formatV1.d.ts.map +1 -1
  113. package/dist/feature-libraries/sequence-field/formatV2.d.ts +76 -76
  114. package/dist/feature-libraries/sequence-field/formatV2.d.ts.map +1 -1
  115. package/dist/feature-libraries/sequence-field/formatV3.d.ts +54 -54
  116. package/dist/feature-libraries/sequence-field/types.d.ts +0 -1
  117. package/dist/feature-libraries/sequence-field/types.d.ts.map +1 -1
  118. package/dist/feature-libraries/sequence-field/types.js.map +1 -1
  119. package/dist/index.d.ts +4 -5
  120. package/dist/index.d.ts.map +1 -1
  121. package/dist/index.js +1 -14
  122. package/dist/index.js.map +1 -1
  123. package/dist/packageVersion.d.ts +1 -1
  124. package/dist/packageVersion.js +1 -1
  125. package/dist/packageVersion.js.map +1 -1
  126. package/dist/shared-tree/index.d.ts +1 -1
  127. package/dist/shared-tree/index.d.ts.map +1 -1
  128. package/dist/shared-tree/index.js.map +1 -1
  129. package/dist/shared-tree/schematizeTree.d.ts +1 -1
  130. package/dist/shared-tree/schematizeTree.d.ts.map +1 -1
  131. package/dist/shared-tree/schematizeTree.js +6 -6
  132. package/dist/shared-tree/schematizeTree.js.map +1 -1
  133. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  134. package/dist/shared-tree/schematizingTreeView.js +8 -12
  135. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  136. package/dist/shared-tree/sharedTree.d.ts +25 -7
  137. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  138. package/dist/shared-tree/sharedTree.js +104 -15
  139. package/dist/shared-tree/sharedTree.js.map +1 -1
  140. package/dist/shared-tree/treeCheckout.d.ts +35 -12
  141. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  142. package/dist/shared-tree/treeCheckout.js +159 -127
  143. package/dist/shared-tree/treeCheckout.js.map +1 -1
  144. package/dist/shared-tree-core/branch.d.ts +13 -35
  145. package/dist/shared-tree-core/branch.d.ts.map +1 -1
  146. package/dist/shared-tree-core/branch.js +12 -77
  147. package/dist/shared-tree-core/branch.js.map +1 -1
  148. package/dist/shared-tree-core/branchCommitEnricher.d.ts +7 -1
  149. package/dist/shared-tree-core/branchCommitEnricher.d.ts.map +1 -1
  150. package/dist/shared-tree-core/branchCommitEnricher.js +16 -18
  151. package/dist/shared-tree-core/branchCommitEnricher.js.map +1 -1
  152. package/dist/shared-tree-core/editManager.d.ts.map +1 -1
  153. package/dist/shared-tree-core/editManager.js +2 -2
  154. package/dist/shared-tree-core/editManager.js.map +1 -1
  155. package/dist/shared-tree-core/index.d.ts +3 -3
  156. package/dist/shared-tree-core/index.d.ts.map +1 -1
  157. package/dist/shared-tree-core/index.js +2 -2
  158. package/dist/shared-tree-core/index.js.map +1 -1
  159. package/dist/shared-tree-core/sharedTreeCore.d.ts +2 -9
  160. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  161. package/dist/shared-tree-core/sharedTreeCore.js +4 -16
  162. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  163. package/dist/shared-tree-core/transaction.d.ts +38 -0
  164. package/dist/shared-tree-core/transaction.d.ts.map +1 -1
  165. package/dist/shared-tree-core/transaction.js +118 -6
  166. package/dist/shared-tree-core/transaction.js.map +1 -1
  167. package/dist/simple-tree/api/conciseTree.d.ts.map +1 -1
  168. package/dist/simple-tree/api/conciseTree.js +1 -1
  169. package/dist/simple-tree/api/conciseTree.js.map +1 -1
  170. package/dist/simple-tree/api/create.d.ts.map +1 -1
  171. package/dist/simple-tree/api/create.js +5 -1
  172. package/dist/simple-tree/api/create.js.map +1 -1
  173. package/dist/simple-tree/api/customTree.d.ts +14 -2
  174. package/dist/simple-tree/api/customTree.d.ts.map +1 -1
  175. package/dist/simple-tree/api/customTree.js +53 -3
  176. package/dist/simple-tree/api/customTree.js.map +1 -1
  177. package/dist/simple-tree/api/index.d.ts +2 -2
  178. package/dist/simple-tree/api/index.d.ts.map +1 -1
  179. package/dist/simple-tree/api/index.js +4 -1
  180. package/dist/simple-tree/api/index.js.map +1 -1
  181. package/dist/simple-tree/api/schemaFactory.d.ts +48 -0
  182. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  183. package/dist/simple-tree/api/schemaFactory.js +5 -2
  184. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  185. package/dist/simple-tree/api/simpleSchema.d.ts +3 -1
  186. package/dist/simple-tree/api/simpleSchema.d.ts.map +1 -1
  187. package/dist/simple-tree/api/simpleSchema.js.map +1 -1
  188. package/dist/simple-tree/api/simpleTreeIndex.js +3 -1
  189. package/dist/simple-tree/api/simpleTreeIndex.js.map +1 -1
  190. package/dist/simple-tree/api/storedSchema.d.ts +4 -4
  191. package/dist/simple-tree/api/storedSchema.d.ts.map +1 -1
  192. package/dist/simple-tree/api/storedSchema.js +8 -21
  193. package/dist/simple-tree/api/storedSchema.js.map +1 -1
  194. package/dist/simple-tree/api/tree.d.ts +1 -0
  195. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  196. package/dist/simple-tree/api/tree.js.map +1 -1
  197. package/dist/simple-tree/api/verboseTree.js +1 -1
  198. package/dist/simple-tree/api/verboseTree.js.map +1 -1
  199. package/dist/simple-tree/api/view.d.ts +14 -9
  200. package/dist/simple-tree/api/view.d.ts.map +1 -1
  201. package/dist/simple-tree/api/view.js +129 -40
  202. package/dist/simple-tree/api/view.js.map +1 -1
  203. package/dist/simple-tree/index.d.ts +2 -2
  204. package/dist/simple-tree/index.d.ts.map +1 -1
  205. package/dist/simple-tree/index.js +5 -2
  206. package/dist/simple-tree/index.js.map +1 -1
  207. package/dist/simple-tree/leafNodeSchema.d.ts +0 -15
  208. package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
  209. package/dist/simple-tree/leafNodeSchema.js +0 -15
  210. package/dist/simple-tree/leafNodeSchema.js.map +1 -1
  211. package/dist/simple-tree/objectNode.d.ts +8 -3
  212. package/dist/simple-tree/objectNode.d.ts.map +1 -1
  213. package/dist/simple-tree/objectNode.js +18 -2
  214. package/dist/simple-tree/objectNode.js.map +1 -1
  215. package/dist/simple-tree/objectNodeTypes.d.ts +4 -0
  216. package/dist/simple-tree/objectNodeTypes.d.ts.map +1 -1
  217. package/dist/simple-tree/objectNodeTypes.js.map +1 -1
  218. package/dist/simple-tree/schemaTypes.d.ts +4 -2
  219. package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
  220. package/dist/simple-tree/schemaTypes.js.map +1 -1
  221. package/dist/simple-tree/toStoredSchema.d.ts.map +1 -1
  222. package/dist/simple-tree/toStoredSchema.js +18 -13
  223. package/dist/simple-tree/toStoredSchema.js.map +1 -1
  224. package/dist/util/brand.d.ts +0 -2
  225. package/dist/util/brand.d.ts.map +1 -1
  226. package/dist/util/brand.js +0 -1
  227. package/dist/util/brand.js.map +1 -1
  228. package/dist/util/index.d.ts +1 -1
  229. package/dist/util/index.d.ts.map +1 -1
  230. package/dist/util/index.js +2 -1
  231. package/dist/util/index.js.map +1 -1
  232. package/dist/util/typeCheck.d.ts +0 -2
  233. package/dist/util/typeCheck.d.ts.map +1 -1
  234. package/dist/util/typeCheck.js.map +1 -1
  235. package/dist/util/utils.d.ts +13 -0
  236. package/dist/util/utils.d.ts.map +1 -1
  237. package/dist/util/utils.js +23 -1
  238. package/dist/util/utils.js.map +1 -1
  239. package/lib/core/index.d.ts +2 -2
  240. package/lib/core/index.d.ts.map +1 -1
  241. package/lib/core/index.js +2 -2
  242. package/lib/core/index.js.map +1 -1
  243. package/lib/core/rebase/utils.d.ts.map +1 -1
  244. package/lib/core/rebase/utils.js +3 -10
  245. package/lib/core/rebase/utils.js.map +1 -1
  246. package/lib/core/schema-stored/format.d.ts +0 -3
  247. package/lib/core/schema-stored/format.d.ts.map +1 -1
  248. package/lib/core/schema-stored/format.js.map +1 -1
  249. package/lib/core/schema-stored/schema.d.ts +12 -10
  250. package/lib/core/schema-stored/schema.d.ts.map +1 -1
  251. package/lib/core/schema-stored/schema.js +3 -5
  252. package/lib/core/schema-stored/schema.js.map +1 -1
  253. package/lib/core/schema-view/index.d.ts +1 -1
  254. package/lib/core/schema-view/index.d.ts.map +1 -1
  255. package/lib/core/schema-view/index.js +1 -1
  256. package/lib/core/schema-view/index.js.map +1 -1
  257. package/lib/core/schema-view/view.d.ts +0 -7
  258. package/lib/core/schema-view/view.d.ts.map +1 -1
  259. package/lib/core/schema-view/view.js +0 -11
  260. package/lib/core/schema-view/view.js.map +1 -1
  261. package/lib/{feature-libraries/chunked-forest → core/tree}/chunk.d.ts +2 -1
  262. package/lib/core/tree/chunk.d.ts.map +1 -0
  263. package/lib/{feature-libraries/chunked-forest → core/tree}/chunk.js +1 -1
  264. package/lib/core/tree/chunk.js.map +1 -0
  265. package/lib/core/tree/index.d.ts +1 -0
  266. package/lib/core/tree/index.d.ts.map +1 -1
  267. package/lib/core/tree/index.js +1 -0
  268. package/lib/core/tree/index.js.map +1 -1
  269. package/lib/core/tree/treeTextFormat.d.ts +0 -5
  270. package/lib/core/tree/treeTextFormat.d.ts.map +1 -1
  271. package/lib/core/tree/treeTextFormat.js.map +1 -1
  272. package/lib/core/tree/types.d.ts +0 -5
  273. package/lib/core/tree/types.d.ts.map +1 -1
  274. package/lib/core/tree/types.js +0 -1
  275. package/lib/core/tree/types.js.map +1 -1
  276. package/lib/feature-libraries/chunked-forest/basicChunk.d.ts +1 -2
  277. package/lib/feature-libraries/chunked-forest/basicChunk.d.ts.map +1 -1
  278. package/lib/feature-libraries/chunked-forest/basicChunk.js +1 -1
  279. package/lib/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  280. package/lib/feature-libraries/chunked-forest/chunkTree.d.ts +1 -2
  281. package/lib/feature-libraries/chunked-forest/chunkTree.d.ts.map +1 -1
  282. package/lib/feature-libraries/chunked-forest/chunkTree.js +1 -2
  283. package/lib/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  284. package/lib/feature-libraries/chunked-forest/chunkedForest.d.ts +1 -2
  285. package/lib/feature-libraries/chunked-forest/chunkedForest.d.ts.map +1 -1
  286. package/lib/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  287. package/lib/feature-libraries/chunked-forest/codec/chunkCodecUtilities.d.ts +1 -2
  288. package/lib/feature-libraries/chunked-forest/codec/chunkCodecUtilities.d.ts.map +1 -1
  289. package/lib/feature-libraries/chunked-forest/codec/chunkCodecUtilities.js.map +1 -1
  290. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +1 -2
  291. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  292. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  293. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts +1 -1
  294. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts.map +1 -1
  295. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js.map +1 -1
  296. package/lib/feature-libraries/chunked-forest/emptyChunk.d.ts +1 -1
  297. package/lib/feature-libraries/chunked-forest/emptyChunk.d.ts.map +1 -1
  298. package/lib/feature-libraries/chunked-forest/emptyChunk.js +1 -2
  299. package/lib/feature-libraries/chunked-forest/emptyChunk.js.map +1 -1
  300. package/lib/feature-libraries/chunked-forest/index.d.ts +1 -1
  301. package/lib/feature-libraries/chunked-forest/index.d.ts.map +1 -1
  302. package/lib/feature-libraries/chunked-forest/index.js +1 -1
  303. package/lib/feature-libraries/chunked-forest/index.js.map +1 -1
  304. package/lib/feature-libraries/chunked-forest/sequenceChunk.d.ts +1 -1
  305. package/lib/feature-libraries/chunked-forest/sequenceChunk.d.ts.map +1 -1
  306. package/lib/feature-libraries/chunked-forest/sequenceChunk.js +1 -1
  307. package/lib/feature-libraries/chunked-forest/sequenceChunk.js.map +1 -1
  308. package/lib/feature-libraries/chunked-forest/uniformChunk.d.ts +1 -2
  309. package/lib/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  310. package/lib/feature-libraries/chunked-forest/uniformChunk.js +1 -1
  311. package/lib/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  312. package/lib/feature-libraries/default-schema/defaultSchema.d.ts.map +1 -1
  313. package/lib/feature-libraries/default-schema/defaultSchema.js +1 -0
  314. package/lib/feature-libraries/default-schema/defaultSchema.js.map +1 -1
  315. package/lib/feature-libraries/default-schema/schemaChecker.d.ts.map +1 -1
  316. package/lib/feature-libraries/default-schema/schemaChecker.js +2 -1
  317. package/lib/feature-libraries/default-schema/schemaChecker.js.map +1 -1
  318. package/lib/feature-libraries/index.d.ts +1 -1
  319. package/lib/feature-libraries/index.d.ts.map +1 -1
  320. package/lib/feature-libraries/index.js +1 -1
  321. package/lib/feature-libraries/index.js.map +1 -1
  322. package/lib/feature-libraries/indexing/anchorTreeIndex.d.ts +8 -1
  323. package/lib/feature-libraries/indexing/anchorTreeIndex.d.ts.map +1 -1
  324. package/lib/feature-libraries/indexing/anchorTreeIndex.js +31 -5
  325. package/lib/feature-libraries/indexing/anchorTreeIndex.js.map +1 -1
  326. package/lib/feature-libraries/modular-schema/discrepancies.d.ts +84 -24
  327. package/lib/feature-libraries/modular-schema/discrepancies.d.ts.map +1 -1
  328. package/lib/feature-libraries/modular-schema/discrepancies.js +25 -28
  329. package/lib/feature-libraries/modular-schema/discrepancies.js.map +1 -1
  330. package/lib/feature-libraries/modular-schema/index.d.ts +1 -1
  331. package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
  332. package/lib/feature-libraries/modular-schema/index.js +1 -1
  333. package/lib/feature-libraries/modular-schema/index.js.map +1 -1
  334. package/lib/feature-libraries/modular-schema/isNeverTree.d.ts +0 -1
  335. package/lib/feature-libraries/modular-schema/isNeverTree.d.ts.map +1 -1
  336. package/lib/feature-libraries/modular-schema/isNeverTree.js +0 -1
  337. package/lib/feature-libraries/modular-schema/isNeverTree.js.map +1 -1
  338. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV1.d.ts +6 -6
  339. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV1.d.ts.map +1 -1
  340. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV2.d.ts +7 -7
  341. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV2.d.ts.map +1 -1
  342. package/lib/feature-libraries/schema-edits/schemaChangeFormat.d.ts +12 -12
  343. package/lib/feature-libraries/sequence-field/formatV1.d.ts +99 -99
  344. package/lib/feature-libraries/sequence-field/formatV1.d.ts.map +1 -1
  345. package/lib/feature-libraries/sequence-field/formatV2.d.ts +76 -76
  346. package/lib/feature-libraries/sequence-field/formatV2.d.ts.map +1 -1
  347. package/lib/feature-libraries/sequence-field/formatV3.d.ts +54 -54
  348. package/lib/feature-libraries/sequence-field/types.d.ts +0 -1
  349. package/lib/feature-libraries/sequence-field/types.d.ts.map +1 -1
  350. package/lib/feature-libraries/sequence-field/types.js.map +1 -1
  351. package/lib/index.d.ts +4 -5
  352. package/lib/index.d.ts.map +1 -1
  353. package/lib/index.js +2 -3
  354. package/lib/index.js.map +1 -1
  355. package/lib/packageVersion.d.ts +1 -1
  356. package/lib/packageVersion.js +1 -1
  357. package/lib/packageVersion.js.map +1 -1
  358. package/lib/shared-tree/index.d.ts +1 -1
  359. package/lib/shared-tree/index.d.ts.map +1 -1
  360. package/lib/shared-tree/index.js.map +1 -1
  361. package/lib/shared-tree/schematizeTree.d.ts +1 -1
  362. package/lib/shared-tree/schematizeTree.d.ts.map +1 -1
  363. package/lib/shared-tree/schematizeTree.js +7 -7
  364. package/lib/shared-tree/schematizeTree.js.map +1 -1
  365. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  366. package/lib/shared-tree/schematizingTreeView.js +10 -14
  367. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  368. package/lib/shared-tree/sharedTree.d.ts +25 -7
  369. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  370. package/lib/shared-tree/sharedTree.js +105 -16
  371. package/lib/shared-tree/sharedTree.js.map +1 -1
  372. package/lib/shared-tree/treeCheckout.d.ts +35 -12
  373. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  374. package/lib/shared-tree/treeCheckout.js +161 -129
  375. package/lib/shared-tree/treeCheckout.js.map +1 -1
  376. package/lib/shared-tree-core/branch.d.ts +13 -35
  377. package/lib/shared-tree-core/branch.d.ts.map +1 -1
  378. package/lib/shared-tree-core/branch.js +12 -76
  379. package/lib/shared-tree-core/branch.js.map +1 -1
  380. package/lib/shared-tree-core/branchCommitEnricher.d.ts +7 -1
  381. package/lib/shared-tree-core/branchCommitEnricher.d.ts.map +1 -1
  382. package/lib/shared-tree-core/branchCommitEnricher.js +16 -18
  383. package/lib/shared-tree-core/branchCommitEnricher.js.map +1 -1
  384. package/lib/shared-tree-core/editManager.d.ts.map +1 -1
  385. package/lib/shared-tree-core/editManager.js +3 -3
  386. package/lib/shared-tree-core/editManager.js.map +1 -1
  387. package/lib/shared-tree-core/index.d.ts +3 -3
  388. package/lib/shared-tree-core/index.d.ts.map +1 -1
  389. package/lib/shared-tree-core/index.js +2 -2
  390. package/lib/shared-tree-core/index.js.map +1 -1
  391. package/lib/shared-tree-core/sharedTreeCore.d.ts +2 -9
  392. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  393. package/lib/shared-tree-core/sharedTreeCore.js +4 -16
  394. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  395. package/lib/shared-tree-core/transaction.d.ts +38 -0
  396. package/lib/shared-tree-core/transaction.d.ts.map +1 -1
  397. package/lib/shared-tree-core/transaction.js +112 -1
  398. package/lib/shared-tree-core/transaction.js.map +1 -1
  399. package/lib/simple-tree/api/conciseTree.d.ts.map +1 -1
  400. package/lib/simple-tree/api/conciseTree.js +2 -2
  401. package/lib/simple-tree/api/conciseTree.js.map +1 -1
  402. package/lib/simple-tree/api/create.d.ts.map +1 -1
  403. package/lib/simple-tree/api/create.js +5 -1
  404. package/lib/simple-tree/api/create.js.map +1 -1
  405. package/lib/simple-tree/api/customTree.d.ts +14 -2
  406. package/lib/simple-tree/api/customTree.d.ts.map +1 -1
  407. package/lib/simple-tree/api/customTree.js +50 -2
  408. package/lib/simple-tree/api/customTree.js.map +1 -1
  409. package/lib/simple-tree/api/index.d.ts +2 -2
  410. package/lib/simple-tree/api/index.d.ts.map +1 -1
  411. package/lib/simple-tree/api/index.js +2 -1
  412. package/lib/simple-tree/api/index.js.map +1 -1
  413. package/lib/simple-tree/api/schemaFactory.d.ts +48 -0
  414. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  415. package/lib/simple-tree/api/schemaFactory.js +4 -1
  416. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  417. package/lib/simple-tree/api/simpleSchema.d.ts +3 -1
  418. package/lib/simple-tree/api/simpleSchema.d.ts.map +1 -1
  419. package/lib/simple-tree/api/simpleSchema.js.map +1 -1
  420. package/lib/simple-tree/api/simpleTreeIndex.js +3 -1
  421. package/lib/simple-tree/api/simpleTreeIndex.js.map +1 -1
  422. package/lib/simple-tree/api/storedSchema.d.ts +4 -4
  423. package/lib/simple-tree/api/storedSchema.d.ts.map +1 -1
  424. package/lib/simple-tree/api/storedSchema.js +5 -18
  425. package/lib/simple-tree/api/storedSchema.js.map +1 -1
  426. package/lib/simple-tree/api/tree.d.ts +1 -0
  427. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  428. package/lib/simple-tree/api/tree.js.map +1 -1
  429. package/lib/simple-tree/api/verboseTree.js +2 -2
  430. package/lib/simple-tree/api/verboseTree.js.map +1 -1
  431. package/lib/simple-tree/api/view.d.ts +14 -9
  432. package/lib/simple-tree/api/view.d.ts.map +1 -1
  433. package/lib/simple-tree/api/view.js +131 -42
  434. package/lib/simple-tree/api/view.js.map +1 -1
  435. package/lib/simple-tree/index.d.ts +2 -2
  436. package/lib/simple-tree/index.d.ts.map +1 -1
  437. package/lib/simple-tree/index.js +2 -2
  438. package/lib/simple-tree/index.js.map +1 -1
  439. package/lib/simple-tree/leafNodeSchema.d.ts +0 -15
  440. package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
  441. package/lib/simple-tree/leafNodeSchema.js +0 -15
  442. package/lib/simple-tree/leafNodeSchema.js.map +1 -1
  443. package/lib/simple-tree/objectNode.d.ts +8 -3
  444. package/lib/simple-tree/objectNode.d.ts.map +1 -1
  445. package/lib/simple-tree/objectNode.js +16 -1
  446. package/lib/simple-tree/objectNode.js.map +1 -1
  447. package/lib/simple-tree/objectNodeTypes.d.ts +4 -0
  448. package/lib/simple-tree/objectNodeTypes.d.ts.map +1 -1
  449. package/lib/simple-tree/objectNodeTypes.js.map +1 -1
  450. package/lib/simple-tree/schemaTypes.d.ts +4 -2
  451. package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
  452. package/lib/simple-tree/schemaTypes.js.map +1 -1
  453. package/lib/simple-tree/toStoredSchema.d.ts.map +1 -1
  454. package/lib/simple-tree/toStoredSchema.js +19 -14
  455. package/lib/simple-tree/toStoredSchema.js.map +1 -1
  456. package/lib/util/brand.d.ts +0 -2
  457. package/lib/util/brand.d.ts.map +1 -1
  458. package/lib/util/brand.js +0 -1
  459. package/lib/util/brand.js.map +1 -1
  460. package/lib/util/index.d.ts +1 -1
  461. package/lib/util/index.d.ts.map +1 -1
  462. package/lib/util/index.js +1 -1
  463. package/lib/util/index.js.map +1 -1
  464. package/lib/util/typeCheck.d.ts +0 -2
  465. package/lib/util/typeCheck.d.ts.map +1 -1
  466. package/lib/util/typeCheck.js.map +1 -1
  467. package/lib/util/utils.d.ts +13 -0
  468. package/lib/util/utils.d.ts.map +1 -1
  469. package/lib/util/utils.js +21 -0
  470. package/lib/util/utils.js.map +1 -1
  471. package/package.json +22 -22
  472. package/src/core/index.ts +5 -1
  473. package/src/core/rebase/utils.ts +17 -20
  474. package/src/core/schema-stored/format.ts +0 -3
  475. package/src/core/schema-stored/schema.ts +13 -10
  476. package/src/core/schema-view/index.ts +0 -1
  477. package/src/core/schema-view/view.ts +0 -11
  478. package/src/{feature-libraries/chunked-forest → core/tree}/chunk.ts +4 -4
  479. package/src/core/tree/index.ts +8 -0
  480. package/src/core/tree/treeTextFormat.ts +0 -5
  481. package/src/core/tree/types.ts +0 -5
  482. package/src/feature-libraries/chunked-forest/basicChunk.ts +4 -2
  483. package/src/feature-libraries/chunked-forest/chunkTree.ts +2 -1
  484. package/src/feature-libraries/chunked-forest/chunkedForest.ts +2 -1
  485. package/src/feature-libraries/chunked-forest/codec/chunkCodecUtilities.ts +1 -2
  486. package/src/feature-libraries/chunked-forest/codec/chunkDecoding.ts +6 -2
  487. package/src/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.ts +1 -1
  488. package/src/feature-libraries/chunked-forest/emptyChunk.ts +4 -2
  489. package/src/feature-libraries/chunked-forest/index.ts +1 -1
  490. package/src/feature-libraries/chunked-forest/sequenceChunk.ts +1 -1
  491. package/src/feature-libraries/chunked-forest/uniformChunk.ts +4 -1
  492. package/src/feature-libraries/default-schema/defaultSchema.ts +1 -0
  493. package/src/feature-libraries/default-schema/schemaChecker.ts +4 -1
  494. package/src/feature-libraries/index.ts +13 -0
  495. package/src/feature-libraries/indexing/anchorTreeIndex.ts +34 -5
  496. package/src/feature-libraries/modular-schema/discrepancies.ts +76 -38
  497. package/src/feature-libraries/modular-schema/index.ts +13 -0
  498. package/src/feature-libraries/modular-schema/isNeverTree.ts +0 -2
  499. package/src/feature-libraries/sequence-field/types.ts +0 -1
  500. package/src/index.ts +1 -29
  501. package/src/packageVersion.ts +1 -1
  502. package/src/shared-tree/index.ts +1 -0
  503. package/src/shared-tree/schematizeTree.ts +6 -10
  504. package/src/shared-tree/schematizingTreeView.ts +11 -21
  505. package/src/shared-tree/sharedTree.ts +173 -41
  506. package/src/shared-tree/treeCheckout.ts +224 -175
  507. package/src/shared-tree-core/branch.ts +29 -122
  508. package/src/shared-tree-core/branchCommitEnricher.ts +19 -20
  509. package/src/shared-tree-core/editManager.ts +3 -8
  510. package/src/shared-tree-core/index.ts +2 -1
  511. package/src/shared-tree-core/sharedTreeCore.ts +8 -19
  512. package/src/shared-tree-core/transaction.ts +145 -0
  513. package/src/simple-tree/api/conciseTree.ts +2 -2
  514. package/src/simple-tree/api/create.ts +5 -1
  515. package/src/simple-tree/api/customTree.ts +69 -1
  516. package/src/simple-tree/api/index.ts +12 -2
  517. package/src/simple-tree/api/schemaFactory.ts +62 -1
  518. package/src/simple-tree/api/simpleSchema.ts +3 -1
  519. package/src/simple-tree/api/simpleTreeIndex.ts +2 -0
  520. package/src/simple-tree/api/storedSchema.ts +7 -22
  521. package/src/simple-tree/api/tree.ts +6 -0
  522. package/src/simple-tree/api/verboseTree.ts +2 -2
  523. package/src/simple-tree/api/view.ts +197 -51
  524. package/src/simple-tree/index.ts +6 -0
  525. package/src/simple-tree/leafNodeSchema.ts +0 -19
  526. package/src/simple-tree/objectNode.ts +26 -2
  527. package/src/simple-tree/objectNodeTypes.ts +5 -0
  528. package/src/simple-tree/schemaTypes.ts +7 -2
  529. package/src/simple-tree/toStoredSchema.ts +25 -19
  530. package/src/util/brand.ts +0 -2
  531. package/src/util/index.ts +1 -0
  532. package/src/util/typeCheck.ts +0 -2
  533. package/src/util/utils.ts +26 -0
  534. package/dist/feature-libraries/chunked-forest/chunk.d.ts.map +0 -1
  535. package/dist/feature-libraries/chunked-forest/chunk.js.map +0 -1
  536. package/lib/feature-libraries/chunked-forest/chunk.d.ts.map +0 -1
  537. package/lib/feature-libraries/chunked-forest/chunk.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"anchorTreeIndex.js","sourceRoot":"","sources":["../../../src/feature-libraries/indexing/anchorTreeIndex.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAC7D,kDAAuE;AACvE,kDAkB6B;AAE7B,oDAAmD;AAenD;;;;;;;GAOG;AACH,MAAa,eAAe;IA4B3B;;;;;;OAMG;IACH,YACkB,MAA2B,EAC3B,OAEe,EACf,QAAyE,EACzE,eAA6D;QAL7D,WAAM,GAAN,MAAM,CAAqB;QAC3B,YAAO,GAAP,OAAO,CAEQ;QACf,aAAQ,GAAR,QAAQ,CAAiE;QACzE,oBAAe,GAAf,eAAe,CAA8C;QAtCxE,aAAQ,GAAG,KAAK,CAAC;QACxB;;;;WAIG;QACc,eAAU,GAAG,IAAI,GAAG,EAAoD,CAAC;QAC1F;;WAEG;QACc,eAAU,GAAG,IAAI,GAAG,EAAsB,CAAC;QAC5D;;WAEG;QACc,cAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;QACzD;;WAEG;QACc,YAAO,GAAG,IAAI,GAAG,EAAwB,CAAC;QAC3D;;;WAGG;QACc,cAAS,GAAG,I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Aa,CAAC,EAAE,CAAC;YAC9D,OAAO,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;QACrC,CAAC;IACF,CAAC;CACD;AA7XD,0CA6XC;AAED;;GAEG;AACH,SAAS,WAAW,CACnB,WAA8C,EAC9C,MAAqC;IAErC,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,SAAgB,UAAU,CAAI,KAAmB;IAChD,OAAO,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;AAC1B,CAAC;AAFD,gCAEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { disposeSymbol, fail, getOrCreate } from \"../../util/index.js\";\nimport {\n\ttype Anchor,\n\ttype AnchorNode,\n\ttype FieldKey,\n\ttype TreeNodeSchemaIdentifier,\n\tforEachField,\n\tforEachNode,\n\ttype ITreeSubscriptionCursor,\n\tcreateAnnouncedVisitor,\n\ttype IForestSubscription,\n\ttype AnnouncedVisitor,\n\tCursorLocationType,\n\trootField,\n\ttype UpPath,\n\ttype ProtoNodes,\n\tkeyAsDetachedField,\n\tcompareUpPaths,\n\tTreeNavigationResult,\n} from \"../../core/index.js\";\nimport type { TreeIndex, TreeIndexKey, TreeIndexNodes } from \"./types.js\";\nimport { TreeStatus } from \"../flex-tree/index.js\";\n\n/**\n * A function that gets the value to index a node on, must be pure and functional.\n * The given cursor should point to the node that will be indexed.\n *\n * @returns a value the index will use as the key for the given node\n *\n * @remarks\n * This function does not own the cursor in any way, it walks the cursor to find the key the node is indexed on\n * but returns the cursor to the state it was in before being passed to the function. It should also not be disposed by this function\n * and must be disposed elsewhere.\n */\nexport type KeyFinder<TKey extends TreeIndexKey> = (tree: ITreeSubscriptionCursor) => TKey;\n\n/**\n * An index from some arbitrary keys to anchor nodes. Keys can be anything that is a {@link TreeValue}.\n * A key can map to multiple nodes but each collection of nodes only results in a single value.\n *\n * @remarks\n * Detached nodes are stored in the index but filtered out when any public facing apis are called. This means that\n * calling {@link keys} will not include any keys that are stored in the index but only map to detached nodes.\n */\nexport class AnchorTreeIndex<TKey extends TreeIndexKey, TValue>\n\timplements TreeIndex<TKey, TValue>\n{\n\tpublic disposed = false;\n\t/**\n\t * Caches {@link KeyFinder}s for each schema definition. If a schema maps to null, it does not\n\t * need to be considered at all for this index. This allows us to skip subtrees that aren't relevant\n\t * as a performance optimization.\n\t */\n\tprivate readonly keyFinders = new Map<TreeNodeSchemaIdentifier, KeyFinder<TKey> | null>();\n\t/**\n\t * The actual index from keys to anchor nodes.\n\t */\n\tprivate readonly keyToNodes = new Map<TKey, AnchorNode[]>();\n\t/**\n\t * Maintained for efficient removal of anchor nodes from the index when updating their keys\n\t */\n\tprivate readonly nodeToKey = new Map<AnchorNode, TKey>();\n\t/**\n\t * Keeps track of anchors for disposal.\n\t */\n\tprivate readonly anchors = new Map<AnchorNode, Anchor[]>();\n\t/**\n\t * The key finder that is registered on the forest to keep this index updated, maintained\n\t * here for deregistration on disposal\n\t */\n\tprivate readonly keyFinder = this.acquireVisitor.bind(this);\n\n\t/**\n\t * @param forest - the forest that is being indexed\n\t * @param indexer - a function that retrieves the key finder based on a given schema or undefined if the schema does not have an associated key finder\n\t * @param getValue - a pure and functional function that returns the associated value of one or more anchor nodes, can be used to map and filter the indexed anchor nodes\n\t * so that the values returned from the index are more usable\n\t * @param checkTreeStatus - a function that gets the tree status from an anchor node, used for filtering out detached nodes\n\t */\n\tpublic constructor(\n\t\tprivate readonly forest: IForestSubscription,\n\t\tprivate readonly indexer: (\n\t\t\tschemaId: TreeNodeSchemaIdentifier,\n\t\t) => KeyFinder<TKey> | undefined,\n\t\tprivate readonly getValue: (anchorNodes: TreeIndexNodes<AnchorNode>) => TValue | undefined,\n\t\tprivate readonly checkTreeStatus: (node: AnchorNode) => TreeStatus | undefined,\n\t) {\n\t\tthis.forest.registerAnnouncedVisitor(this.keyFinder);\n\n\t\tconst detachedFieldKeys: FieldKey[] = [];\n\t\tconst detachedFieldsCursor = forest.getCursorAboveDetachedFields();\n\t\tforEachField(detachedFieldsCursor, (field) => {\n\t\t\tdetachedFieldKeys.push(field.getFieldKey());\n\t\t});\n\n\t\t// index all existing trees (this includes the primary document tree and all other detached/removed trees)\n\t\tfor (const fieldKey of detachedFieldKeys) {\n\t\t\tconst cursor = forest.allocateCursor();\n\t\t\tforest.tryMoveCursorToField({ fieldKey, parent: undefined }, cursor);\n\t\t\tthis.indexField(cursor);\n\t\t\tcursor.free();\n\t\t}\n\t}\n\n\t/**\n\t * Creates an announced visitor that responds to edits to the forest and updates the index accordingly.\n\t */\n\tprivate acquireVisitor(): AnnouncedVisitor {\n\t\tthis.checkNotDisposed(\n\t\t\t\"visitor getter should be deregistered from the forest when index is disposed\",\n\t\t);\n\t\tlet parentField: FieldKey | undefined;\n\t\tlet parent: UpPath | undefined;\n\n\t\treturn createAnnouncedVisitor({\n\t\t\t// nodes (and their entire subtrees) are added to the index as soon as they are created\n\t\t\tafterCreate: (content: ProtoNodes, destination: FieldKey) => {\n\t\t\t\tconst detachedCursor = this.forest.allocateCursor();\n\t\t\t\tassert(\n\t\t\t\t\tthis.forest.tryMoveCursorToField(\n\t\t\t\t\t\t{ fieldKey: destination, parent: undefined },\n\t\t\t\t\t\tdetachedCursor,\n\t\t\t\t\t) === TreeNavigationResult.Ok,\n\t\t\t\t\t0xa8a /* destination of created nodes must be a valid detached field */,\n\t\t\t\t);\n\t\t\t\tthis.indexField(detachedCursor);\n\t\t\t\tdetachedCursor.free();\n\t\t\t},\n\t\t\t// when a replace happens, the keys of previously indexed nodes could be changed so we must re-index them\n\t\t\tafterReplace: () => {\n\t\t\t\tassert(parent !== undefined, 0xa8b /* must have a parent */);\n\t\t\t\tconst cursor = this.forest.allocateCursor();\n\t\t\t\tthis.forest.moveCursorToPath(parent, cursor);\n\t\t\t\tassert(\n\t\t\t\t\tcursor.mode === CursorLocationType.Nodes,\n\t\t\t\t\t0xa8c /* replace should happen in a node */,\n\t\t\t\t);\n\t\t\t\tcursor.exitNode();\n\t\t\t\t// we must re-index the spine because the key finders allow for any value under a subtree to be the key\n\t\t\t\t// this means that a replace can cause the key for any node up its spine to be changed\n\t\t\t\tthis.indexSpine(cursor);\n\t\t\t\tcursor.clear();\n\t\t\t},\n\t\t\t// the methods below are used to keep track of the path that has been traversed by the visitor\n\t\t\t// this is required so that cursors can be moved to the correct location when index updates are required\n\t\t\tenterNode(index: number): void {\n\t\t\t\tassert(parentField !== undefined, 0xa8d /* must be in a field to enter node */);\n\n\t\t\t\tparent = {\n\t\t\t\t\tparent,\n\t\t\t\t\tparentField,\n\t\t\t\t\tparentIndex: index,\n\t\t\t\t};\n\t\t\t\tparentField = undefined;\n\t\t\t},\n\t\t\texitNode(index: number): void {\n\t\t\t\tassert(parent !== undefined, 0xa8e /* must have parent node */);\n\t\t\t\tconst temp = parent;\n\t\t\t\tparentField = temp.parentField;\n\t\t\t\tparent = temp.parent;\n\t\t\t},\n\t\t\tenterField: (key: FieldKey) => {\n\t\t\t\tparentField = key;\n\t\t\t},\n\t\t\texitField(key: FieldKey): void {\n\t\t\t\tparentField = undefined;\n\t\t\t},\n\t\t});\n\t}\n\n\t/**\n\t * Returns the value associated with the given key if it has been indexed\n\t */\n\tpublic get(key: TKey): TValue | undefined {\n\t\tthis.checkNotDisposed();\n\t\treturn this.getFilteredValue(this.keyToNodes.get(key));\n\t}\n\n\t/**\n\t * Returns true iff the key exists in the index\n\t */\n\tpublic has(key: TKey): boolean {\n\t\tthis.checkNotDisposed();\n\t\treturn this.get(key) !== undefined;\n\t}\n\n\t/**\n\t * Returns the number of values that are indexed\n\t */\n\tpublic get size(): number {\n\t\tthis.checkNotDisposed();\n\t\tlet s = 0;\n\t\tfor (const nodes of this.keyToNodes.values()) {\n\t\t\tif (this.getFilteredValue(nodes) !== undefined) {\n\t\t\t\ts += 1;\n\t\t\t}\n\t\t}\n\t\treturn s;\n\t}\n\n\t/**\n\t * Returns all keys in the index\n\t */\n\tpublic *keys(): IterableIterator<TKey> {\n\t\tthis.checkNotDisposed();\n\t\tfor (const [key, nodes] of this.keyToNodes.entries()) {\n\t\t\tif (this.getFilteredValue(nodes) !== undefined) {\n\t\t\t\tyield key;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Returns an iterable of values in the index\n\t */\n\tpublic *values(): IterableIterator<TValue> {\n\t\tthis.checkNotDisposed();\n\t\tfor (const nodes of this.keyToNodes.values()) {\n\t\t\tconst filtered = this.getFilteredValue(nodes);\n\t\t\tif (filtered !== undefined) {\n\t\t\t\tyield filtered;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Returns an iterable of key, value pairs for every entry in the index\n\t */\n\tpublic *entries(): IterableIterator<[TKey, TValue]> {\n\t\tthis.checkNotDisposed();\n\t\tfor (const [key, nodes] of this.keyToNodes.entries()) {\n\t\t\tconst filtered = this.getFilteredValue(nodes);\n\t\t\tif (filtered !== undefined) {\n\t\t\t\tyield [key, filtered];\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic [Symbol.iterator](): IterableIterator<[TKey, TValue]> {\n\t\tthis.checkNotDisposed();\n\t\treturn this.entries();\n\t}\n\n\t/**\n\t * Applies the provided callback to each entry in the index.\n\t */\n\tpublic forEach(\n\t\tcallbackfn: (value: TValue, key: TKey, map: AnchorTreeIndex<TKey, TValue>) => void,\n\t\tthisArg?: unknown,\n\t): void {\n\t\tthis.checkNotDisposed();\n\t\tfor (const [key, nodes] of this.keyToNodes.entries()) {\n\t\t\tconst filtered = this.getFilteredValue(nodes);\n\t\t\tif (filtered !== undefined) {\n\t\t\t\tcallbackfn.call(thisArg, filtered, key, this);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Returns an iterable of key, value pairs for every entry in the index, including ones that are detached.\n\t * This function should only be used for testing purposes, it is not exposed as part of the public {@link TreeIndex} API.\n\t */\n\tpublic *allEntries(): IterableIterator<[TKey, TValue]> {\n\t\tthis.checkNotDisposed();\n\t\tfor (const [key, nodes] of this.keyToNodes.entries()) {\n\t\t\tconst value = this.getValue(nodes as unknown as TreeIndexNodes<AnchorNode>);\n\t\t\tif (value !== undefined) {\n\t\t\t\tyield [key, value];\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic dispose(): void {\n\t\tthis[disposeSymbol]();\n\t}\n\n\t/**\n\t * Disposes this index and all the anchors it holds onto.\n\t */\n\tpublic [disposeSymbol](): void {\n\t\tthis.checkNotDisposed(\"index is already disposed\");\n\t\tfor (const anchors of this.anchors.values()) {\n\t\t\tfor (const anchor of anchors) {\n\t\t\t\tthis.forest.forgetAnchor(anchor);\n\t\t\t}\n\t\t}\n\t\tthis.keyToNodes.clear();\n\t\tthis.anchors.clear();\n\t\tthis.forest.deregisterAnnouncedVisitor(this.keyFinder);\n\t\tthis.disposed = true;\n\t}\n\n\tprivate checkNotDisposed(errorMessage?: string): void {\n\t\tif (this.disposed) {\n\t\t\tif (errorMessage !== undefined) {\n\t\t\t\tthrow new Error(errorMessage);\n\t\t\t}\n\t\t\tassert(false, 0xa8f /* invalid operation on a disposed index */);\n\t\t}\n\t}\n\n\t/**\n\t * Given a cursor in node mode, indexes it.\n\t */\n\tprivate indexNode(nodeCursor: ITreeSubscriptionCursor): void {\n\t\tconst keyFinder = getOrCreate(\n\t\t\tthis.keyFinders,\n\t\t\t// the node schema type to look up\n\t\t\tnodeCursor.type,\n\t\t\t// if the indexer does not return a key finder for this schema, we cache a null value to indicate the indexer\n\t\t\t// does not need to be called if this schema is encountered in the future\n\t\t\t(schema) => this.indexer(schema) ?? null,\n\t\t);\n\n\t\tif (keyFinder !== null) {\n\t\t\tconst expectedPath = nodeCursor.getPath();\n\t\t\tconst key = keyFinder(nodeCursor);\n\t\t\t// TODO: determine perf impact of this check, alternative is not doing it in which case (if the key finder is not pure and functional),\n\t\t\t// an error may be thrown further down the line if the structure of the nodes aren't expected or the contents of the index could be inaccurate\n\t\t\tif (!compareUpPaths(nodeCursor.getPath(), expectedPath)) {\n\t\t\t\tthrow new Error(\"key finder should be pure and functional\");\n\t\t\t}\n\t\t\tconst anchor = nodeCursor.buildAnchor();\n\t\t\tconst anchorNode = this.forest.anchors.locate(anchor) ?? fail(\"expected anchor node\");\n\n\t\t\t// check if this anchor node already exists in the index\n\t\t\tconst existingKey = this.nodeToKey.get(anchorNode);\n\t\t\tif (existingKey !== undefined) {\n\t\t\t\t// if the node already exists but has the same key, we return early\n\t\t\t\tif (existingKey === key) {\n\t\t\t\t\tthis.forest.forgetAnchor(anchor);\n\t\t\t\t\treturn;\n\t\t\t\t} else {\n\t\t\t\t\t// if the node has a different key, we remove the existing one first because it means the key had been detached\n\t\t\t\t\tthis.removeAnchor(anchorNode, existingKey);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tgetOrCreate(this.keyToNodes, key, () => []).push(anchorNode);\n\t\t\tthis.nodeToKey.set(anchorNode, key);\n\n\t\t\tgetOrCreate(this.anchors, anchorNode, () => []).push(anchor);\n\t\t\t// when the anchor node is destroyed, delete it from the index\n\t\t\tanchorNode.events.on(\"afterDestroy\", () => {\n\t\t\t\tthis.removeAnchor(anchorNode, key);\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Given a cursor in field mode, recursively indexes all nodes under the field.\n\t */\n\tprivate indexField(fieldCursor: ITreeSubscriptionCursor): void {\n\t\tforEachNode(fieldCursor, (nodeCursor) => {\n\t\t\tthis.indexNode(nodeCursor);\n\n\t\t\tforEachField(nodeCursor, (f) => {\n\t\t\t\tthis.indexField(f);\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Given a cursor in field mode, indexes all nodes under the field and then indexes all nodes up the spine.\n\t */\n\tprivate indexSpine(cursor: ITreeSubscriptionCursor): void {\n\t\tthis.indexField(cursor);\n\n\t\tif (keyAsDetachedField(cursor.getFieldKey()) !== rootField) {\n\t\t\tcursor.exitField();\n\t\t\tcursor.exitNode();\n\t\t} else {\n\t\t\t// return early if we're already at the root field\n\t\t\treturn;\n\t\t}\n\n\t\t// walk up the spine and index nodes until we reach the root\n\t\twhile (\n\t\t\tcursor.mode === CursorLocationType.Fields &&\n\t\t\tkeyAsDetachedField(cursor.getFieldKey()) !== rootField\n\t\t) {\n\t\t\tforEachNode(cursor, (nodeCursor) => {\n\t\t\t\tthis.indexNode(nodeCursor);\n\t\t\t});\n\n\t\t\tcursor.exitField();\n\t\t\tcursor.exitNode();\n\t\t}\n\t}\n\n\tprivate removeAnchor(anchorNode: AnchorNode, key: TKey): void {\n\t\tconst indexedNodes = this.keyToNodes.get(key);\n\t\tassert(\n\t\t\tindexedNodes !== undefined,\n\t\t\t0xa90 /* destroyed anchor node should be tracked by index */,\n\t\t);\n\t\tconst index = indexedNodes.indexOf(anchorNode);\n\t\tassert(index !== -1, 0xa91 /* destroyed anchor node should be tracked by index */);\n\t\tconst newNodes = filterNodes(indexedNodes, (n) => n !== anchorNode);\n\t\tif (newNodes !== undefined && newNodes.length > 0) {\n\t\t\tthis.keyToNodes.set(key, newNodes);\n\t\t} else {\n\t\t\tthis.keyToNodes.delete(key);\n\t\t}\n\t\tthis.nodeToKey.delete(anchorNode);\n\t\tassert(\n\t\t\tthis.anchors.delete(anchorNode),\n\t\t\t0xa92 /* destroyed anchor should be tracked by index */,\n\t\t);\n\t}\n\n\t/**\n\t * Filters out any anchor nodes that are detached and returns the value for the remaining nodes.\n\t */\n\tprivate getFilteredValue(anchorNodes: AnchorNode[] | undefined): TValue | undefined {\n\t\tconst attachedNodes = filterNodes(anchorNodes, (anchorNode) => {\n\t\t\tconst nodeStatus = this.checkTreeStatus(anchorNode);\n\t\t\treturn nodeStatus === TreeStatus.InDocument;\n\t\t});\n\n\t\tif (attachedNodes !== undefined && hasElement(attachedNodes)) {\n\t\t\treturn this.getValue(attachedNodes);\n\t\t}\n\t}\n}\n\n/**\n * Filters the given anchor nodes based on the given filter function.\n */\nfunction filterNodes(\n\tanchorNodes: readonly AnchorNode[] | undefined,\n\tfilter: (node: AnchorNode) => boolean,\n): AnchorNode[] | undefined {\n\tif (anchorNodes !== undefined) {\n\t\treturn anchorNodes.filter(filter);\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Checks that an array is of the type {@link TreeIndexNodes} and has at least one element.\n */\nexport function hasElement<T>(array: readonly T[]): array is TreeIndexNodes<T> {\n\treturn array.length >= 1;\n}\n"]}
1
+ {"version":3,"file":"anchorTreeIndex.js","sourceRoot":"","sources":["../../../src/feature-libraries/indexing/anchorTreeIndex.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAC7D,kDAAuE;AACvE,kDAkB6B;AAE7B,oDAAmD;AAenD;;;;;;;GAOG;AACH,MAAa,eAAe;IA4B3B;;;;;;;;OAQG;IACH,YACkB,MAA2B,EAC3B,OAEe,EACf,QAAyE,EACzE,eAA6D,EAC7D,iBAAiB,KAAK;QANtB,WAAM,GAAN,MAAM,CAAqB;QAC3B,YAAO,GAAP,OAAO,CAEQ;QACf,aAAQ,GAAR,QAAQ,CAAiE;QACzE,oBAAe,GAAf,eAAe,CAA8C;QAC7D,mBAAc,GAAd,cAAc,CAAQ;QAzCjC,aAAQ,GAAG,KAAK,CAAC;QACxB;;;;WAIG;QACc,eAAU,GAAG,IAAI,GAAG,EAAoD,CAAC;QAC1F;;WAEG;QACc,eAAU,GAAG,IAAI,GAAG,EAAsB,CAAC;QAC5D;;WAEG;QACc,cAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;QACzD;;WAEG;QACc,YAAO,GAAG,IAAI,GAAG,EAAwB,CAAC;QAC3D;;;WAGG;QACc,cAAS,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAoB3D,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAErD,MAAM,iBAAiB,GAAe,EAAE,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K,SAAS,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACnD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QACpC,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7B,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAClC,IAAA,iBAAM,EACL,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,EAC/B,KAAK,CAAC,iDAAiD,CACvD,CAAC;IACH,CAAC;IAED;;OAEG;IACK,gBAAgB,CAAC,WAAqC;QAC7D,MAAM,aAAa,GAAG,WAAW,CAAC,WAAW,EAAE,CAAC,UAAU,EAAE,EAAE;YAC7D,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;YACpD,OAAO,UAAU,KAAK,qBAAU,CAAC,UAAU,CAAC;QAC7C,CAAC,CAAC,CAAC;QAEH,IAAI,aAAa,KAAK,SAAS,IAAI,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;YAC9D,OAAO,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;QACrC,CAAC;IACF,CAAC;CACD;AA1ZD,0CA0ZC;AAED;;GAEG;AACH,SAAS,WAAW,CACnB,WAA8C,EAC9C,MAAqC;IAErC,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,SAAgB,UAAU,CAAI,KAAmB;IAChD,OAAO,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;AAC1B,CAAC;AAFD,gCAEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { disposeSymbol, fail, getOrCreate } from \"../../util/index.js\";\nimport {\n\ttype Anchor,\n\ttype AnchorNode,\n\ttype FieldKey,\n\ttype TreeNodeSchemaIdentifier,\n\tforEachField,\n\tforEachNode,\n\ttype ITreeSubscriptionCursor,\n\tcreateAnnouncedVisitor,\n\ttype IForestSubscription,\n\ttype AnnouncedVisitor,\n\tCursorLocationType,\n\trootField,\n\ttype UpPath,\n\ttype ProtoNodes,\n\tkeyAsDetachedField,\n\tcompareUpPaths,\n\tTreeNavigationResult,\n} from \"../../core/index.js\";\nimport type { TreeIndex, TreeIndexKey, TreeIndexNodes } from \"./types.js\";\nimport { TreeStatus } from \"../flex-tree/index.js\";\n\n/**\n * A function that gets the value to index a node on, must be pure and functional.\n * The given cursor should point to the node that will be indexed.\n *\n * @returns a value the index will use as the key for the given node\n *\n * @remarks\n * This function does not own the cursor in any way, it walks the cursor to find the key the node is indexed on\n * but returns the cursor to the state it was in before being passed to the function. It should also not be disposed by this function\n * and must be disposed elsewhere.\n */\nexport type KeyFinder<TKey extends TreeIndexKey> = (tree: ITreeSubscriptionCursor) => TKey;\n\n/**\n * An index from some arbitrary keys to anchor nodes. Keys can be anything that is a {@link TreeValue}.\n * A key can map to multiple nodes but each collection of nodes only results in a single value.\n *\n * @remarks\n * Detached nodes are stored in the index but filtered out when any public facing apis are called. This means that\n * calling {@link keys} will not include any keys that are stored in the index but only map to detached nodes.\n */\nexport class AnchorTreeIndex<TKey extends TreeIndexKey, TValue>\n\timplements TreeIndex<TKey, TValue>\n{\n\tpublic disposed = false;\n\t/**\n\t * Caches {@link KeyFinder}s for each schema definition. If a schema maps to null, it does not\n\t * need to be considered at all for this index. This allows us to skip subtrees that aren't relevant\n\t * as a performance optimization.\n\t */\n\tprivate readonly keyFinders = new Map<TreeNodeSchemaIdentifier, KeyFinder<TKey> | null>();\n\t/**\n\t * The actual index from keys to anchor nodes.\n\t */\n\tprivate readonly keyToNodes = new Map<TKey, AnchorNode[]>();\n\t/**\n\t * Maintained for efficient removal of anchor nodes from the index when updating their keys\n\t */\n\tprivate readonly nodeToKey = new Map<AnchorNode, TKey>();\n\t/**\n\t * Keeps track of anchors for disposal.\n\t */\n\tprivate readonly anchors = new Map<AnchorNode, Anchor[]>();\n\t/**\n\t * The key finder that is registered on the forest to keep this index updated, maintained\n\t * here for deregistration on disposal\n\t */\n\tprivate readonly keyFinder = this.acquireVisitor.bind(this);\n\n\t/**\n\t * @param forest - the forest that is being indexed\n\t * @param indexer - a function that retrieves the key finder based on a given schema or undefined if the schema does not have an associated key finder\n\t * @param getValue - a pure and functional function that returns the associated value of one or more anchor nodes, can be used to map and filter the indexed anchor nodes\n\t * so that the values returned from the index are more usable\n\t * @param checkTreeStatus - a function that gets the tree status from an anchor node, used for filtering out detached nodes\n\t * @param isShallowIndex - indicates if this index is shallow, meaning that it only allows nodes to be keyed off of fields directly under them rather than anywhere in their subtree.\n\t * As a performance optimization, re-indexing up the spine can be turned off for shallow indexes.\n\t */\n\tpublic constructor(\n\t\tprivate readonly forest: IForestSubscription,\n\t\tprivate readonly indexer: (\n\t\t\tschemaId: TreeNodeSchemaIdentifier,\n\t\t) => KeyFinder<TKey> | undefined,\n\t\tprivate readonly getValue: (anchorNodes: TreeIndexNodes<AnchorNode>) => TValue | undefined,\n\t\tprivate readonly checkTreeStatus: (node: AnchorNode) => TreeStatus | undefined,\n\t\tprivate readonly isShallowIndex = false,\n\t) {\n\t\tthis.forest.registerAnnouncedVisitor(this.keyFinder);\n\n\t\tconst detachedFieldKeys: FieldKey[] = [];\n\t\tconst detachedFieldsCursor = forest.getCursorAboveDetachedFields();\n\t\tforEachField(detachedFieldsCursor, (field) => {\n\t\t\tdetachedFieldKeys.push(field.getFieldKey());\n\t\t});\n\n\t\t// index all existing trees (this includes the primary document tree and all other detached/removed trees)\n\t\tfor (const fieldKey of detachedFieldKeys) {\n\t\t\tconst cursor = forest.allocateCursor();\n\t\t\tforest.tryMoveCursorToField({ fieldKey, parent: undefined }, cursor);\n\t\t\tthis.indexField(cursor);\n\t\t\tcursor.free();\n\t\t}\n\t}\n\n\t/**\n\t * Creates an announced visitor that responds to edits to the forest and updates the index accordingly.\n\t */\n\tprivate acquireVisitor(): AnnouncedVisitor {\n\t\tthis.checkNotDisposed(\n\t\t\t\"visitor getter should be deregistered from the forest when index is disposed\",\n\t\t);\n\t\tlet parentField: FieldKey | undefined;\n\t\tlet parent: UpPath | undefined;\n\n\t\treturn createAnnouncedVisitor({\n\t\t\t// nodes (and their entire subtrees) are added to the index as soon as they are created\n\t\t\tafterCreate: (content: ProtoNodes, destination: FieldKey) => {\n\t\t\t\tconst detachedCursor = this.forest.allocateCursor();\n\t\t\t\tassert(\n\t\t\t\t\tthis.forest.tryMoveCursorToField(\n\t\t\t\t\t\t{ fieldKey: destination, parent: undefined },\n\t\t\t\t\t\tdetachedCursor,\n\t\t\t\t\t) === TreeNavigationResult.Ok,\n\t\t\t\t\t0xa8a /* destination of created nodes must be a valid detached field */,\n\t\t\t\t);\n\t\t\t\tthis.indexField(detachedCursor);\n\t\t\t\tdetachedCursor.free();\n\t\t\t},\n\t\t\tafterAttach: () => {\n\t\t\t\tassert(parent !== undefined, 0xa99 /* must have a parent */);\n\t\t\t\tthis.reIndexSpine(parent);\n\t\t\t},\n\t\t\tafterDetach: () => {\n\t\t\t\tassert(parent !== undefined, 0xa9a /* must have a parent */);\n\t\t\t\tthis.reIndexSpine(parent);\n\t\t\t},\n\t\t\t// when a replace happens, the keys of previously indexed nodes could be changed so we must re-index them\n\t\t\tafterReplace: () => {\n\t\t\t\tassert(parent !== undefined, 0xa8b /* must have a parent */);\n\t\t\t\tconst cursor = this.forest.allocateCursor();\n\t\t\t\tthis.forest.moveCursorToPath(parent, cursor);\n\t\t\t\tassert(\n\t\t\t\t\tcursor.mode === CursorLocationType.Nodes,\n\t\t\t\t\t0xa8c /* replace should happen in a node */,\n\t\t\t\t);\n\t\t\t\tcursor.exitNode();\n\t\t\t\tthis.indexField(cursor);\n\t\t\t\tif (!this.isShallowIndex) {\n\t\t\t\t\t// we must also re-index the spine if the key finders allow for any value under a subtree to be the key\n\t\t\t\t\t// this means that a replace can cause the key for any node up its spine to be changed\n\t\t\t\t\tthis.indexSpine(cursor);\n\t\t\t\t}\n\t\t\t\tcursor.clear();\n\t\t\t},\n\t\t\t// the methods below are used to keep track of the path that has been traversed by the visitor\n\t\t\t// this is required so that cursors can be moved to the correct location when index updates are required\n\t\t\tenterNode(index: number): void {\n\t\t\t\tassert(parentField !== undefined, 0xa8d /* must be in a field to enter node */);\n\n\t\t\t\tparent = {\n\t\t\t\t\tparent,\n\t\t\t\t\tparentField,\n\t\t\t\t\tparentIndex: index,\n\t\t\t\t};\n\t\t\t\tparentField = undefined;\n\t\t\t},\n\t\t\texitNode(index: number): void {\n\t\t\t\tassert(parent !== undefined, 0xa8e /* must have parent node */);\n\t\t\t\tconst temp = parent;\n\t\t\t\tparentField = temp.parentField;\n\t\t\t\tparent = temp.parent;\n\t\t\t},\n\t\t\tenterField: (key: FieldKey) => {\n\t\t\t\tparentField = key;\n\t\t\t},\n\t\t\texitField(key: FieldKey): void {\n\t\t\t\tparentField = undefined;\n\t\t\t},\n\t\t});\n\t}\n\n\t/**\n\t * Returns the value associated with the given key if it has been indexed\n\t */\n\tpublic get(key: TKey): TValue | undefined {\n\t\tthis.checkNotDisposed();\n\t\treturn this.getFilteredValue(this.keyToNodes.get(key));\n\t}\n\n\t/**\n\t * Returns true iff the key exists in the index\n\t */\n\tpublic has(key: TKey): boolean {\n\t\tthis.checkNotDisposed();\n\t\treturn this.get(key) !== undefined;\n\t}\n\n\t/**\n\t * Returns the number of values that are indexed\n\t */\n\tpublic get size(): number {\n\t\tthis.checkNotDisposed();\n\t\tlet s = 0;\n\t\tfor (const nodes of this.keyToNodes.values()) {\n\t\t\tif (this.getFilteredValue(nodes) !== undefined) {\n\t\t\t\ts += 1;\n\t\t\t}\n\t\t}\n\t\treturn s;\n\t}\n\n\t/**\n\t * Returns all keys in the index\n\t */\n\tpublic *keys(): IterableIterator<TKey> {\n\t\tthis.checkNotDisposed();\n\t\tfor (const [key, nodes] of this.keyToNodes.entries()) {\n\t\t\tif (this.getFilteredValue(nodes) !== undefined) {\n\t\t\t\tyield key;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Returns an iterable of values in the index\n\t */\n\tpublic *values(): IterableIterator<TValue> {\n\t\tthis.checkNotDisposed();\n\t\tfor (const nodes of this.keyToNodes.values()) {\n\t\t\tconst filtered = this.getFilteredValue(nodes);\n\t\t\tif (filtered !== undefined) {\n\t\t\t\tyield filtered;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Returns an iterable of key, value pairs for every entry in the index\n\t */\n\tpublic *entries(): IterableIterator<[TKey, TValue]> {\n\t\tthis.checkNotDisposed();\n\t\tfor (const [key, nodes] of this.keyToNodes.entries()) {\n\t\t\tconst filtered = this.getFilteredValue(nodes);\n\t\t\tif (filtered !== undefined) {\n\t\t\t\tyield [key, filtered];\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic [Symbol.iterator](): IterableIterator<[TKey, TValue]> {\n\t\tthis.checkNotDisposed();\n\t\treturn this.entries();\n\t}\n\n\t/**\n\t * Applies the provided callback to each entry in the index.\n\t */\n\tpublic forEach(\n\t\tcallbackfn: (value: TValue, key: TKey, map: AnchorTreeIndex<TKey, TValue>) => void,\n\t\tthisArg?: unknown,\n\t): void {\n\t\tthis.checkNotDisposed();\n\t\tfor (const [key, nodes] of this.keyToNodes.entries()) {\n\t\t\tconst filtered = this.getFilteredValue(nodes);\n\t\t\tif (filtered !== undefined) {\n\t\t\t\tcallbackfn.call(thisArg, filtered, key, this);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Returns an iterable of key, value pairs for every entry in the index, including ones that are detached.\n\t * This function should only be used for testing purposes, it is not exposed as part of the public {@link TreeIndex} API.\n\t */\n\tpublic *allEntries(): IterableIterator<[TKey, TValue]> {\n\t\tthis.checkNotDisposed();\n\t\tfor (const [key, nodes] of this.keyToNodes.entries()) {\n\t\t\tconst value = this.getValue(nodes as unknown as TreeIndexNodes<AnchorNode>);\n\t\t\tif (value !== undefined) {\n\t\t\t\tyield [key, value];\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic dispose(): void {\n\t\tthis[disposeSymbol]();\n\t}\n\n\t/**\n\t * Disposes this index and all the anchors it holds onto.\n\t */\n\tpublic [disposeSymbol](): void {\n\t\tthis.checkNotDisposed(\"index is already disposed\");\n\t\tfor (const anchors of this.anchors.values()) {\n\t\t\tfor (const anchor of anchors) {\n\t\t\t\tthis.forest.forgetAnchor(anchor);\n\t\t\t}\n\t\t}\n\t\tthis.keyToNodes.clear();\n\t\tthis.anchors.clear();\n\t\tthis.forest.deregisterAnnouncedVisitor(this.keyFinder);\n\t\tthis.disposed = true;\n\t}\n\n\t/**\n\t * Checks if the spine needs to be re-indexed and if so, re-indexes it starting from the given path.\n\t */\n\tprivate reIndexSpine(path: UpPath): void {\n\t\tif (!this.isShallowIndex) {\n\t\t\tconst cursor = this.forest.allocateCursor();\n\t\t\tthis.forest.moveCursorToPath(path, cursor);\n\t\t\tassert(\n\t\t\t\tcursor.mode === CursorLocationType.Nodes,\n\t\t\t\t0xa9b /* attach should happen in a node */,\n\t\t\t);\n\t\t\tcursor.exitNode();\n\t\t\tthis.indexSpine(cursor);\n\t\t\tcursor.clear();\n\t\t}\n\t}\n\n\tprivate checkNotDisposed(errorMessage?: string): void {\n\t\tif (this.disposed) {\n\t\t\tif (errorMessage !== undefined) {\n\t\t\t\tthrow new Error(errorMessage);\n\t\t\t}\n\t\t\tassert(false, 0xa8f /* invalid operation on a disposed index */);\n\t\t}\n\t}\n\n\t/**\n\t * Given a cursor in node mode, indexes it.\n\t */\n\tprivate indexNode(nodeCursor: ITreeSubscriptionCursor): void {\n\t\tconst keyFinder = getOrCreate(\n\t\t\tthis.keyFinders,\n\t\t\t// the node schema type to look up\n\t\t\tnodeCursor.type,\n\t\t\t// if the indexer does not return a key finder for this schema, we cache a null value to indicate the indexer\n\t\t\t// does not need to be called if this schema is encountered in the future\n\t\t\t(schema) => this.indexer(schema) ?? null,\n\t\t);\n\n\t\tif (keyFinder !== null) {\n\t\t\tconst expectedPath = nodeCursor.getPath();\n\t\t\tconst key = keyFinder(nodeCursor);\n\t\t\t// TODO: determine perf impact of this check, alternative is not doing it in which case (if the key finder is not pure and functional),\n\t\t\t// an error may be thrown further down the line if the structure of the nodes aren't expected or the contents of the index could be inaccurate\n\t\t\tif (!compareUpPaths(nodeCursor.getPath(), expectedPath)) {\n\t\t\t\tthrow new Error(\"key finder should be pure and functional\");\n\t\t\t}\n\t\t\tconst anchor = nodeCursor.buildAnchor();\n\t\t\tconst anchorNode = this.forest.anchors.locate(anchor) ?? fail(\"expected anchor node\");\n\n\t\t\t// check if this anchor node already exists in the index\n\t\t\tconst existingKey = this.nodeToKey.get(anchorNode);\n\t\t\tif (existingKey !== undefined) {\n\t\t\t\t// if the node already exists but has the same key, we return early\n\t\t\t\tif (existingKey === key) {\n\t\t\t\t\tthis.forest.forgetAnchor(anchor);\n\t\t\t\t\treturn;\n\t\t\t\t} else {\n\t\t\t\t\t// if the node has a different key, we remove the existing one first because it means the key had been detached\n\t\t\t\t\tthis.removeAnchor(anchorNode, existingKey);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tgetOrCreate(this.keyToNodes, key, () => []).push(anchorNode);\n\t\t\tthis.nodeToKey.set(anchorNode, key);\n\n\t\t\tgetOrCreate(this.anchors, anchorNode, () => []).push(anchor);\n\t\t\t// when the anchor node is destroyed, delete it from the index\n\t\t\tanchorNode.events.on(\"afterDestroy\", () => {\n\t\t\t\tthis.removeAnchor(anchorNode, key);\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Given a cursor in field mode, recursively indexes all nodes under the field.\n\t */\n\tprivate indexField(fieldCursor: ITreeSubscriptionCursor): void {\n\t\tforEachNode(fieldCursor, (nodeCursor) => {\n\t\t\tthis.indexNode(nodeCursor);\n\n\t\t\tforEachField(nodeCursor, (f) => {\n\t\t\t\tthis.indexField(f);\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Given a cursor in field mode, indexes all nodes under the field and then indexes all nodes up the spine.\n\t */\n\tprivate indexSpine(cursor: ITreeSubscriptionCursor): void {\n\t\tif (keyAsDetachedField(cursor.getFieldKey()) !== rootField) {\n\t\t\tcursor.exitField();\n\t\t\tcursor.exitNode();\n\t\t} else {\n\t\t\t// return early if we're already at the root field\n\t\t\treturn;\n\t\t}\n\n\t\t// walk up the spine and index nodes until we reach the root\n\t\twhile (\n\t\t\tcursor.mode === CursorLocationType.Fields &&\n\t\t\tkeyAsDetachedField(cursor.getFieldKey()) !== rootField\n\t\t) {\n\t\t\tforEachNode(cursor, (nodeCursor) => {\n\t\t\t\tthis.indexNode(nodeCursor);\n\t\t\t});\n\n\t\t\tcursor.exitField();\n\t\t\tcursor.exitNode();\n\t\t}\n\t}\n\n\tprivate removeAnchor(anchorNode: AnchorNode, key: TKey): void {\n\t\tconst indexedNodes = this.keyToNodes.get(key);\n\t\tassert(\n\t\t\tindexedNodes !== undefined,\n\t\t\t0xa90 /* destroyed anchor node should be tracked by index */,\n\t\t);\n\t\tconst index = indexedNodes.indexOf(anchorNode);\n\t\tassert(index !== -1, 0xa91 /* destroyed anchor node should be tracked by index */);\n\t\tconst newNodes = filterNodes(indexedNodes, (n) => n !== anchorNode);\n\t\tif (newNodes !== undefined && newNodes.length > 0) {\n\t\t\tthis.keyToNodes.set(key, newNodes);\n\t\t} else {\n\t\t\tthis.keyToNodes.delete(key);\n\t\t}\n\t\tthis.nodeToKey.delete(anchorNode);\n\t\tassert(\n\t\t\tthis.anchors.delete(anchorNode),\n\t\t\t0xa92 /* destroyed anchor should be tracked by index */,\n\t\t);\n\t}\n\n\t/**\n\t * Filters out any anchor nodes that are detached and returns the value for the remaining nodes.\n\t */\n\tprivate getFilteredValue(anchorNodes: AnchorNode[] | undefined): TValue | undefined {\n\t\tconst attachedNodes = filterNodes(anchorNodes, (anchorNode) => {\n\t\t\tconst nodeStatus = this.checkTreeStatus(anchorNode);\n\t\t\treturn nodeStatus === TreeStatus.InDocument;\n\t\t});\n\n\t\tif (attachedNodes !== undefined && hasElement(attachedNodes)) {\n\t\t\treturn this.getValue(attachedNodes);\n\t\t}\n\t}\n}\n\n/**\n * Filters the given anchor nodes based on the given filter function.\n */\nfunction filterNodes(\n\tanchorNodes: readonly AnchorNode[] | undefined,\n\tfilter: (node: AnchorNode) => boolean,\n): AnchorNode[] | undefined {\n\tif (anchorNodes !== undefined) {\n\t\treturn anchorNodes.filter(filter);\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Checks that an array is of the type {@link TreeIndexNodes} and has at least one element.\n */\nexport function hasElement<T>(array: readonly T[]): array is TreeIndexNodes<T> {\n\treturn array.length >= 1;\n}\n"]}
@@ -2,8 +2,9 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { type FieldKindIdentifier, type TreeStoredSchema, type ValueSchema } from "../../core/index.js";
5
+ import { type FieldKey, type FieldKindIdentifier, type TreeNodeSchemaIdentifier, type TreeStoredSchema, type ValueSchema } from "../../core/index.js";
6
6
  /**
7
+ * Discriminated union (keyed on `mismatch`) of discrepancies between a view and stored schema.
7
8
  * @remarks
8
9
  *
9
10
  * 1. FieldDiscrepancy
@@ -37,39 +38,64 @@ import { type FieldKindIdentifier, type TreeStoredSchema, type ValueSchema } fro
37
38
  */
38
39
  export type Discrepancy = FieldDiscrepancy | NodeDiscrepancy;
39
40
  export type NodeDiscrepancy = NodeKindDiscrepancy | NodeFieldsDiscrepancy;
41
+ /**
42
+ * A discrepancy in the declaration of a field.
43
+ */
40
44
  export type FieldDiscrepancy = AllowedTypeDiscrepancy | FieldKindDiscrepancy | ValueSchemaDiscrepancy;
41
- export interface AllowedTypeDiscrepancy {
42
- identifier: string | undefined;
45
+ /**
46
+ * Information about where a field discrepancy is located within a collection of schema.
47
+ */
48
+ export interface FieldDiscrepancyLocation {
49
+ /**
50
+ * The {@link TreeNodeSchemaIdentifier} that contains the discrepancy.
51
+ *
52
+ * Undefined iff the discrepancy is part of the root field schema.
53
+ */
54
+ identifier: TreeNodeSchemaIdentifier | undefined;
55
+ /**
56
+ * The {@link FieldKey} for the field that contains the discrepancy.
57
+ * Undefined when:
58
+ * - the discrepancy is part of the root field schema
59
+ * - the discrepancy is for 'all fields' of a map node
60
+ */
61
+ fieldKey: FieldKey | undefined;
62
+ }
63
+ /**
64
+ * A discrepancy in the allowed types of a field.
65
+ *
66
+ * @remarks
67
+ * This reports the symmetric difference of allowed types in view/stored to enable more efficient checks for compatibility
68
+ */
69
+ export interface AllowedTypeDiscrepancy extends FieldDiscrepancyLocation {
43
70
  mismatch: "allowedTypes";
44
71
  /**
45
- * List of allowed type identifiers in viewed schema
72
+ * List of allowed type identifiers in viewed schema which are not allowed in stored schema
46
73
  */
47
- view: string[];
74
+ view: TreeNodeSchemaIdentifier[];
48
75
  /**
49
- * List of allowed type identifiers in stored schema
76
+ * List of allowed type identifiers in stored schema which are not allowed in view schema
50
77
  */
51
- stored: string[];
78
+ stored: TreeNodeSchemaIdentifier[];
52
79
  }
53
- export interface FieldKindDiscrepancy {
54
- identifier: string | undefined;
80
+ export interface FieldKindDiscrepancy extends FieldDiscrepancyLocation {
55
81
  mismatch: "fieldKind";
56
82
  view: FieldKindIdentifier;
57
83
  stored: FieldKindIdentifier;
58
84
  }
59
85
  export interface ValueSchemaDiscrepancy {
60
- identifier: string;
86
+ identifier: TreeNodeSchemaIdentifier;
61
87
  mismatch: "valueSchema";
62
88
  view: ValueSchema | undefined;
63
89
  stored: ValueSchema | undefined;
64
90
  }
65
91
  export interface NodeKindDiscrepancy {
66
- identifier: string;
92
+ identifier: TreeNodeSchemaIdentifier;
67
93
  mismatch: "nodeKind";
68
94
  view: SchemaFactoryNodeKind | undefined;
69
95
  stored: SchemaFactoryNodeKind | undefined;
70
96
  }
71
97
  export interface NodeFieldsDiscrepancy {
72
- identifier: string;
98
+ identifier: TreeNodeSchemaIdentifier;
73
99
  mismatch: "fields";
74
100
  differences: FieldDiscrepancy[];
75
101
  }
@@ -77,19 +103,13 @@ type SchemaFactoryNodeKind = "object" | "leaf" | "map";
77
103
  /**
78
104
  * Finds and reports discrepancies between a view schema and a stored schema.
79
105
  *
80
- * The workflow for finding schema incompatibilities:
81
- * 1. Compare the two root schemas to identify any `FieldDiscrepancy`.
82
- *
83
- * 2. For each node schema in the `view`:
84
- * - Verify if the node schema exists in the stored. If it does, ensure that the `SchemaFactoryNodeKind` are
85
- * consistent. Otherwise this difference is treated as `NodeKindDiscrepancy`
86
- * - If a node schema with the same identifier exists in both view and stored, and their `SchemaFactoryNodeKind`
87
- * are consistent, perform a exhaustive validation to identify all `FieldDiscrepancy`.
88
- *
89
- * 3. For each node schema in the stored, verify if it exists in the view. The overlapping parts were already
90
- * addressed in the previous step.
106
+ * See documentation on {@link Discrepancy} for details of possible discrepancies.
107
+ * @remarks
108
+ * This function does not attempt to distinguish between equivalent representations of a node/field involving extraneous never trees.
109
+ * For example, a Forbidden field with allowed type set `[]` is equivalent to an optional field with allowed type set `[]`,
110
+ * as well as an optional field with an allowed type set containing only unconstructable types.
91
111
  *
92
- * @returns the discrepancies between two TreeStoredSchema objects
112
+ * It is up to the caller to determine whether such discrepancies matter.
93
113
  */
94
114
  export declare function getAllowedContentDiscrepancies(view: TreeStoredSchema, stored: TreeStoredSchema): Iterable<Discrepancy>;
95
115
  /**
@@ -110,5 +130,45 @@ export declare function getAllowedContentDiscrepancies(view: TreeStoredSchema, s
110
130
  * validating internal fields.
111
131
  */
112
132
  export declare function isRepoSuperset(view: TreeStoredSchema, stored: TreeStoredSchema): boolean;
133
+ /**
134
+ * A linear extension of a partially-ordered set of `T`s. See:
135
+ * https://en.wikipedia.org/wiki/Linear_extension
136
+ *
137
+ * The linear extension is represented as a lookup from each poset element to its index in the linear extension.
138
+ */
139
+ export type LinearExtension<T> = Map<T, number>;
140
+ /**
141
+ * A realizer for a partially-ordered set. See:
142
+ * https://en.wikipedia.org/wiki/Order_dimension
143
+ */
144
+ export type Realizer<T> = LinearExtension<T>[];
145
+ /**
146
+ * A realizer for the partial order of field kind relaxability.
147
+ *
148
+ * It seems extremely likely that this partial order will remain dimension 2 over time (i.e. the set of allowed relaxations can be visualized
149
+ * with a [dominance drawing](https://en.wikipedia.org/wiki/Dominance_drawing)), so this strategy allows efficient comarison between field kinds
150
+ * without excessive casework.
151
+ *
152
+ * Hasse diagram for the partial order is shown below (lower fields can be relaxed to higher fields):
153
+ * ```
154
+ * sequence
155
+ * |
156
+ * optional
157
+ * | \
158
+ * required forbidden
159
+ * |
160
+ * identifier
161
+ * ```
162
+ */
163
+ export declare const fieldRealizer: Realizer<FieldKindIdentifier>;
164
+ export declare const PosetComparisonResult: {
165
+ readonly Less: "<";
166
+ readonly Greater: ">";
167
+ readonly Equal: "=";
168
+ readonly Incomparable: "||";
169
+ };
170
+ type PosetComparisonResult = (typeof PosetComparisonResult)[keyof typeof PosetComparisonResult];
171
+ export declare function comparePosetElements<T>(a: T, b: T, realizer: Realizer<T>): PosetComparisonResult;
172
+ export declare function posetLte<T>(a: T, b: T, realizer: Realizer<T>): boolean;
113
173
  export {};
114
174
  //# sourceMappingURL=discrepancies.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"discrepancies.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/modular-schema/discrepancies.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,KAAK,mBAAmB,EAQxB,KAAK,gBAAgB,EAErB,KAAK,WAAW,EAChB,MAAM,qBAAqB,CAAC;AAO7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,MAAM,WAAW,GAAG,gBAAgB,GAAG,eAAe,CAAC;AAE7D,MAAM,MAAM,eAAe,GAAG,mBAAmB,GAAG,qBAAqB,CAAC;AAE1E,MAAM,M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EAAE,gBAAgB,GAAG,OAAO,CAkCxF"}
1
+ {"version":3,"file":"discrepancies.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/modular-schema/discrepancies.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,KAAK,QAAQ,EACb,KAAK,mBAAmB,EAMxB,KAAK,wBAAwB,EAE7B,KAAK,gBAAgB,EAErB,KAAK,WAAW,EAChB,MAAM,qBAAqB,CAAC;AAO7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,MAAM,WAAW,GAAG,gBAAgB,GAAG,eAAe,CAAC;AAE7D,MAAM,MAAM,eAAe,GAAG,mBAAmB,GAAG,qBAAqB,CAAC;AAE1E;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACzB,sBAAsB,GACtB,oBAAoB,GACpB,sBAAsB,CAAC;AAE1B;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC;;;;OAIG;IACH,UAAU,EAAE,wBAAwB,GAAG,SAAS,CAAC;IACjD;;;;;OAKG;IACH,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC;CAC/B;AAED;;;;;GAKG;AACH,MAAM,WAAW,sBAAuB,SAAQ,wBAAwB;IACvE,QAAQ,EAAE,cAAc,CAAC;IACzB;;OAEG;IACH,IAAI,EAAE,wBAAwB,EAAE,CAAC;IACjC;;OAEG;IACH,MAAM,EAAE,wBAAwB,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,oBAAqB,SAAQ,wBAAwB;IACrE,QAAQ,EAAE,WAAW,CAAC;IACtB,IAAI,EAAE,mBAAmB,CAAC;IAC1B,MAAM,EAAE,mBAAmB,CAAC;CAC5B;AAED,MAAM,WAAW,sBAAsB;IACtC,UAAU,EAAE,wBAAwB,CAAC;IACrC,QAAQ,EAAE,aAAa,CAAC;IACxB,IAAI,EAAE,WAAW,GAAG,SAAS,CAAC;IAC9B,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC;CAChC;AAED,MA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QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,CAKtE"}
@@ -4,7 +4,7 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.isRepoSuperset = exports.getAllowedContentDiscrepancies = void 0;
7
+ exports.posetLte = exports.comparePosetElements = exports.PosetComparisonResult = exports.fieldRealizer = exports.isRepoSuperset = exports.getAllowedContentDiscrepancies = void 0;
8
8
  const internal_1 = require("@fluidframework/core-utils/internal");
9
9
  const index_js_1 = require("../../core/index.js");
10
10
  const index_js_2 = require("../../util/index.js");
@@ -23,23 +23,17 @@ function getNodeSchemaType(nodeSchema) {
23
23
  /**
24
24
  * Finds and reports discrepancies between a view schema and a stored schema.
25
25
  *
26
- * The workflow for finding schema incompatibilities:
27
- * 1. Compare the two root schemas to identify any `FieldDiscrepancy`.
28
- *
29
- * 2. For each node schema in the `view`:
30
- * - Verify if the node schema exists in the stored. If it does, ensure that the `SchemaFactoryNodeKind` are
31
- * consistent. Otherwise this difference is treated as `NodeKindDiscrepancy`
32
- * - If a node schema with the same identifier exists in both view and stored, and their `SchemaFactoryNodeKind`
33
- * are consistent, perform a exhaustive validation to identify all `FieldDiscrepancy`.
34
- *
35
- * 3. For each node schema in the stored, verify if it exists in the view. The overlapping parts were already
36
- * addressed in the previous step.
26
+ * See documentation on {@link Discrepancy} for details of possible discrepancies.
27
+ * @remarks
28
+ * This function does not attempt to distinguish between equivalent representations of a node/field involving extraneous never trees.
29
+ * For example, a Forbidden field with allowed type set `[]` is equivalent to an optional field with allowed type set `[]`,
30
+ * as well as an optional field with an allowed type set containing only unconstructable types.
37
31
  *
38
- * @returns the discrepancies between two TreeStoredSchema objects
32
+ * It is up to the caller to determine whether such discrepancies matter.
39
33
  */
40
34
  function* getAllowedContentDiscrepancies(view, stored) {
41
35
  // check root schema discrepancies
42
- yield* getFieldDiscrepancies(view.rootFieldSchema, stored.rootFieldSchema);
36
+ yield* getFieldDiscrepancies(view.rootFieldSchema, stored.rootFieldSchema, undefined, undefined);
43
37
  for (const result of compareMaps(view.nodeSchema, stored.nodeSchema)) {
44
38
  switch (result.type) {
45
39
  case "aExtra": {
@@ -86,7 +80,7 @@ function* getNodeDiscrepancies(identifier, view, stored) {
86
80
  }
87
81
  switch (viewType) {
88
82
  case "object": {
89
- const differences = Array.from(trackObjectNodeDiscrepancies(view, stored));
83
+ const differences = Array.from(trackObjectNodeDiscrepancies(identifier, view, stored));
90
84
  if (differences.length > 0) {
91
85
  yield {
92
86
  identifier,
@@ -97,7 +91,7 @@ function* getNodeDiscrepancies(identifier, view, stored) {
97
91
  break;
98
92
  }
99
93
  case "map":
100
- yield* getFieldDiscrepancies(view.mapFields, stored.mapFields, identifier);
94
+ yield* getFieldDiscrepancies(view.mapFields, stored.mapFields, identifier, undefined);
101
95
  break;
102
96
  case "leaf": {
103
97
  const viewValue = view.leafValue;
@@ -121,7 +115,7 @@ function* getNodeDiscrepancies(identifier, view, stored) {
121
115
  *
122
116
  * @param keyOrRoot - If the key is missing, it indicates that this is the root field schema.
123
117
  */
124
- function* getFieldDiscrepancies(view, stored, keyOrRoot) {
118
+ function* getFieldDiscrepancies(view, stored, identifier, fieldKey) {
125
119
  // Only track the symmetric differences of two sets.
126
120
  const findSetDiscrepancies = (a, b) => {
127
121
  const aDiff = [...a].filter((value) => !b.has(value));
@@ -131,7 +125,8 @@ function* getFieldDiscrepancies(view, stored, keyOrRoot) {
131
125
  const [viewExtra, storedExtra] = findSetDiscrepancies(view.types, stored.types);
132
126
  if (viewExtra.length > 0 || storedExtra.length > 0) {
133
127
  yield {
134
- identifier: keyOrRoot,
128
+ identifier,
129
+ fieldKey,
135
130
  mismatch: "allowedTypes",
136
131
  view: viewExtra,
137
132
  stored: storedExtra,
@@ -139,14 +134,15 @@ function* getFieldDiscrepancies(view, stored, keyOrRoot) {
139
134
  }
140
135
  if (view.kind !== stored.kind) {
141
136
  yield {
142
- identifier: keyOrRoot,
137
+ identifier,
138
+ fieldKey,
143
139
  mismatch: "fieldKind",
144
140
  view: view.kind,
145
141
  stored: stored.kind,
146
142
  };
147
143
  }
148
144
  }
149
- function* trackObjectNodeDiscrepancies(view, stored) {
145
+ function* trackObjectNodeDiscrepancies(identifier, view, stored) {
150
146
  /**
151
147
  * Similar to the logic used for tracking discrepancies between two node schemas, we will identify
152
148
  * three types of differences:
@@ -167,7 +163,8 @@ function* trackObjectNodeDiscrepancies(view, stored) {
167
163
  break;
168
164
  }
169
165
  yield {
170
- identifier: fieldKey,
166
+ identifier,
167
+ fieldKey,
171
168
  mismatch: "fieldKind",
172
169
  view: result.value.kind,
173
170
  stored: index_js_1.storedEmptyFieldSchema.kind,
@@ -181,7 +178,8 @@ function* trackObjectNodeDiscrepancies(view, stored) {
181
178
  break;
182
179
  }
183
180
  yield {
184
- identifier: fieldKey,
181
+ identifier,
182
+ fieldKey,
185
183
  mismatch: "fieldKind",
186
184
  view: index_js_1.storedEmptyFieldSchema.kind,
187
185
  stored: result.value.kind,
@@ -189,12 +187,11 @@ function* trackObjectNodeDiscrepancies(view, stored) {
189
187
  break;
190
188
  }
191
189
  case "both": {
192
- yield* getFieldDiscrepancies(result.valueA, result.valueB, fieldKey);
190
+ yield* getFieldDiscrepancies(result.valueA, result.valueB, identifier, fieldKey);
193
191
  break;
194
192
  }
195
- default: {
193
+ default:
196
194
  break;
197
- }
198
195
  }
199
196
  }
200
197
  }
@@ -268,7 +265,7 @@ function isFieldDiscrepancyCompatible(discrepancy) {
268
265
  return discrepancy.stored.length === 0;
269
266
  }
270
267
  case "fieldKind": {
271
- return posetLte(discrepancy.stored, discrepancy.view, fieldRealizer);
268
+ return posetLte(discrepancy.stored, discrepancy.view, exports.fieldRealizer);
272
269
  }
273
270
  case "valueSchema": {
274
271
  return false;
@@ -308,7 +305,7 @@ const FieldKindIdentifiers = {
308
305
  * identifier
309
306
  * ```
310
307
  */
311
- const fieldRealizer = [
308
+ exports.fieldRealizer = [
312
309
  [
313
310
  FieldKindIdentifiers.forbidden,
314
311
  FieldKindIdentifiers.identifier,
@@ -324,7 +321,7 @@ const fieldRealizer = [
324
321
  FieldKindIdentifiers.sequence,
325
322
  ],
326
323
  ].map((extension) => new Map(extension.map((identifier, index) => [identifier, index])));
327
- const PosetComparisonResult = {
324
+ exports.PosetComparisonResult = {
328
325
  Less: "<",
329
326
  Greater: ">",
330
327
  Equal: "=",
@@ -346,16 +343,18 @@ function comparePosetElements(a, b, realizer) {
346
343
  }
347
344
  return hasLessThanResult
348
345
  ? hasGreaterThanResult
349
- ? PosetComparisonResult.Incomparable
350
- : PosetComparisonResult.Less
346
+ ? exports.PosetComparisonResult.Incomparable
347
+ : exports.PosetComparisonResult.Less
351
348
  : hasGreaterThanResult
352
- ? PosetComparisonResult.Greater
353
- : PosetComparisonResult.Equal;
349
+ ? exports.PosetComparisonResult.Greater
350
+ : exports.PosetComparisonResult.Equal;
354
351
  }
352
+ exports.comparePosetElements = comparePosetElements;
355
353
  function posetLte(a, b, realizer) {
356
354
  const comparison = comparePosetElements(a, b, realizer);
357
- return (comparison === PosetComparisonResult.Less || comparison === PosetComparisonResult.Equal);
355
+ return (comparison === exports.PosetComparisonResult.Less || comparison === exports.PosetComparisonResult.Equal);
358
356
  }
357
+ exports.posetLte = posetLte;
359
358
  function throwUnsupportedNodeType(type) {
360
359
  throw new TypeError(`Unsupported node stored schema type: ${type}`);
361
360
  }
@@ -1 +1 @@
1
- {"version":3,"file":"discrepancies.js","sourceRoot":"","sources":["../../../src/feature-libraries/modular-schema/discrepancies.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAE7D,kDAY6B;AAC7B,kDAA4C;AAyF5C,SAAS,iBAAiB,CAAC,UAAgC;IAC1D,IAAI,UAAU,YAAY,iCAAsB,EAAE,CAAC;QAClD,OAAO,QAAQ,CAAC;IACjB,CAAC;SAAM,IAA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,CAAC,oBAAoB;YACrB,CAAC,CAAC,qBAAqB,CAAC,YAAY;YACpC,CAAC,CAAC,qBAAqB,CAAC,IAAI;QAC7B,CAAC,CAAC,oBAAoB;YACrB,CAAC,CAAC,qBAAqB,CAAC,OAAO;YAC/B,CAAC,CAAC,qBAAqB,CAAC,KAAK,CAAC;AACjC,CAAC;AAED,SAAS,QAAQ,CAAI,CAAI,EAAE,CAAI,EAAE,QAAqB;IACrD,MAAM,UAAU,GAAG,oBAAoB,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;IACxD,OAAO,CACN,UAAU,KAAK,qBAAqB,CAAC,IAAI,IAAI,UAAU,KAAK,qBAAqB,CAAC,KAAK,CACvF,CAAC;AACH,CAAC;AAED,SAAS,wBAAwB,CAAC,IAAY;IAC7C,MAAM,IAAI,SAAS,CAAC,wCAAwC,IAAI,EAAE,CAAC,CAAC;AACrE,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\ttype FieldKindIdentifier,\n\tLeafNodeStoredSchema,\n\tMapNodeStoredSchema,\n\tObjectNodeStoredSchema,\n\tstoredEmptyFieldSchema,\n\ttype TreeFieldStoredSchema,\n\ttype TreeNodeSchemaIdentifier,\n\ttype TreeNodeStoredSchema,\n\ttype TreeStoredSchema,\n\ttype TreeTypeSet,\n\ttype ValueSchema,\n} from \"../../core/index.js\";\nimport { brand } from \"../../util/index.js\";\n\n// TODO:\n// The comparisons in this file seem redundant with those in comparison.ts.\n// Rather than both existing, one of which just returns boolean and the other which returns additional details, a simple comparison which returns everything needed should be used.\n\n/**\n * @remarks\n *\n * 1. FieldDiscrepancy\n *\n * `FieldDiscrepancy` represents the differences between two `TreeFieldStoredSchema` objects. It consists of\n * three types of incompatibilities:\n *\n * - FieldKindDiscrepancy: Indicates the differences in `FieldKindIdentifier` between two `TreeFieldStoredSchema`\n * objects (e.g., optional, required, sequence, etc.).\n * - AllowedTypesDiscrepancy: Indicates the differences in the allowed child types between the two schemas.\n * - ValueSchemaDiscrepancy: Specifically indicates the differences in the `ValueSchema` of two\n * `LeafNodeStoredSchema` objects.\n *\n * 2. NodeDiscrepancy\n *\n * `NodeDiscrepancy` represents the differences between two `TreeNodeStoredSchema` objects and includes:\n *\n * - NodeKindDiscrepancy: Indicates the differences in the types of `TreeNodeStoredSchema` (currently supports\n * `ObjectNodeStoredSchema`, `MapNodeStoredSchema`, and `LeafNodeStoredSchema`).\n * - NodeFieldsDiscrepancy: Indicates the `FieldDiscrepancy` of `TreeFieldStoredSchema` within two\n * `TreeNodeStoredSchema`. It includes an array of `FieldDiscrepancy` instances in the `differences` field.\n *\n * When comparing two nodes for compatibility, it only makes sense to compare their fields if the nodes are of\n * the same kind (map, object, leaf).\n *\n * 3. Discrepancy\n *\n * Discrepancy consists of both `NodeDiscrepancy` and `FieldDiscrepancy`, representing any kind of\n * schema differences. See {@link getAllowedContentDiscrepancies} for more details about how we process it\n * and the ordering.\n */\nexport type Discrepancy = FieldDiscrepancy | NodeDiscrepancy;\n\nexport type NodeDiscrepancy = NodeKindDiscrepancy | NodeFieldsDiscrepancy;\n\nexport type FieldDiscrepancy =\n\t| AllowedTypeDiscrepancy\n\t| FieldKindDiscrepancy\n\t| ValueSchemaDiscrepancy;\n\nexport interface AllowedTypeDiscrepancy {\n\tidentifier: string | undefined; // undefined indicates root field schema\n\tmismatch: \"allowedTypes\";\n\t/**\n\t * List of allowed type identifiers in viewed schema\n\t */\n\tview: string[];\n\t/**\n\t * List of allowed type identifiers in stored schema\n\t */\n\tstored: string[];\n}\n\nexport interface FieldKindDiscrepancy {\n\tidentifier: string | undefined; // undefined indicates root field schema\n\tmismatch: \"fieldKind\";\n\tview: FieldKindIdentifier;\n\tstored: FieldKindIdentifier;\n}\n\nexport interface ValueSchemaDiscrepancy {\n\tidentifier: string;\n\tmismatch: \"valueSchema\";\n\tview: ValueSchema | undefined;\n\tstored: ValueSchema | undefined;\n}\n\nexport interface NodeKindDiscrepancy {\n\tidentifier: string;\n\tmismatch: \"nodeKind\";\n\tview: SchemaFactoryNodeKind | undefined;\n\tstored: SchemaFactoryNodeKind | undefined;\n}\n\nexport interface NodeFieldsDiscrepancy {\n\tidentifier: string;\n\tmismatch: \"fields\";\n\tdifferences: FieldDiscrepancy[];\n}\n\ntype SchemaFactoryNodeKind = \"object\" | \"leaf\" | \"map\";\n\nfunction getNodeSchemaType(nodeSchema: TreeNodeStoredSchema): SchemaFactoryNodeKind {\n\tif (nodeSchema instanceof ObjectNodeStoredSchema) {\n\t\treturn \"object\";\n\t} else if (nodeSchema instanceof MapNodeStoredSchema) {\n\t\treturn \"map\";\n\t} else if (nodeSchema instanceof LeafNodeStoredSchema) {\n\t\treturn \"leaf\";\n\t}\n\tthrowUnsupportedNodeType(nodeSchema.constructor.name);\n}\n\n/**\n * Finds and reports discrepancies between a view schema and a stored schema.\n *\n * The workflow for finding schema incompatibilities:\n * 1. Compare the two root schemas to identify any `FieldDiscrepancy`.\n *\n * 2. For each node schema in the `view`:\n * - Verify if the node schema exists in the stored. If it does, ensure that the `SchemaFactoryNodeKind` are\n * consistent. Otherwise this difference is treated as `NodeKindDiscrepancy`\n * - If a node schema with the same identifier exists in both view and stored, and their `SchemaFactoryNodeKind`\n * are consistent, perform a exhaustive validation to identify all `FieldDiscrepancy`.\n *\n * 3. For each node schema in the stored, verify if it exists in the view. The overlapping parts were already\n * addressed in the previous step.\n *\n * @returns the discrepancies between two TreeStoredSchema objects\n */\nexport function* getAllowedContentDiscrepancies(\n\tview: TreeStoredSchema,\n\tstored: TreeStoredSchema,\n): Iterable<Discrepancy> {\n\t// check root schema discrepancies\n\tyield* getFieldDiscrepancies(view.rootFieldSchema, stored.rootFieldSchema);\n\n\tfor (const result of compareMaps(view.nodeSchema, stored.nodeSchema)) {\n\t\tswitch (result.type) {\n\t\t\tcase \"aExtra\": {\n\t\t\t\tconst viewType = getNodeSchemaType(result.value);\n\t\t\t\tyield {\n\t\t\t\t\tidentifier: result.key,\n\t\t\t\t\tmismatch: \"nodeKind\",\n\t\t\t\t\tview: viewType,\n\t\t\t\t\tstored: undefined,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"bExtra\": {\n\t\t\t\tconst storedType = getNodeSchemaType(result.value);\n\t\t\t\tyield {\n\t\t\t\t\tidentifier: result.key,\n\t\t\t\t\tmismatch: \"nodeKind\",\n\t\t\t\t\tview: undefined,\n\t\t\t\t\tstored: storedType,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"both\": {\n\t\t\t\tyield* getNodeDiscrepancies(result.key, result.valueA, result.valueB);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\nfunction* getNodeDiscrepancies(\n\tidentifier: TreeNodeSchemaIdentifier,\n\tview: TreeNodeStoredSchema,\n\tstored: TreeNodeStoredSchema,\n): Iterable<Discrepancy> {\n\tconst viewType = getNodeSchemaType(view);\n\tconst storedType = getNodeSchemaType(stored);\n\tif (viewType !== storedType) {\n\t\tyield {\n\t\t\tidentifier,\n\t\t\tmismatch: \"nodeKind\",\n\t\t\tview: viewType,\n\t\t\tstored: storedType,\n\t\t};\n\t\treturn;\n\t}\n\n\tswitch (viewType) {\n\t\tcase \"object\": {\n\t\t\tconst differences = Array.from(\n\t\t\t\ttrackObjectNodeDiscrepancies(\n\t\t\t\t\tview as ObjectNodeStoredSchema,\n\t\t\t\t\tstored as ObjectNodeStoredSchema,\n\t\t\t\t),\n\t\t\t);\n\t\t\tif (differences.length > 0) {\n\t\t\t\tyield {\n\t\t\t\t\tidentifier,\n\t\t\t\t\tmismatch: \"fields\",\n\t\t\t\t\tdifferences,\n\t\t\t\t} satisfies NodeFieldsDiscrepancy;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase \"map\":\n\t\t\tyield* getFieldDiscrepancies(\n\t\t\t\t(view as MapNodeStoredSchema).mapFields,\n\t\t\t\t(stored as MapNodeStoredSchema).mapFields,\n\t\t\t\tidentifier,\n\t\t\t);\n\t\t\tbreak;\n\t\tcase \"leaf\": {\n\t\t\tconst viewValue = (view as LeafNodeStoredSchema).leafValue;\n\t\t\tconst storedValue = (stored as LeafNodeStoredSchema).leafValue;\n\t\t\tif (viewValue !== storedValue) {\n\t\t\t\tyield {\n\t\t\t\t\tidentifier,\n\t\t\t\t\tmismatch: \"valueSchema\",\n\t\t\t\t\tview: viewValue,\n\t\t\t\t\tstored: storedValue,\n\t\t\t\t};\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tdefault:\n\t\t\tbreak;\n\t}\n}\n\n/**\n * The function to track the discrepancies between two field stored schemas.\n *\n * @param keyOrRoot - If the key is missing, it indicates that this is the root field schema.\n */\nfunction* getFieldDiscrepancies(\n\tview: TreeFieldStoredSchema,\n\tstored: TreeFieldStoredSchema,\n\tkeyOrRoot?: string,\n): Iterable<FieldDiscrepancy> {\n\t// Only track the symmetric differences of two sets.\n\tconst findSetDiscrepancies = (\n\t\ta: TreeTypeSet,\n\t\tb: TreeTypeSet,\n\t): [TreeNodeSchemaIdentifier[], TreeNodeSchemaIdentifier[]] => {\n\t\tconst aDiff = [...a].filter((value) => !b.has(value));\n\t\tconst bDiff = [...b].filter((value) => !a.has(value));\n\t\treturn [aDiff, bDiff];\n\t};\n\n\tconst [viewExtra, storedExtra] = findSetDiscrepancies(view.types, stored.types);\n\tif (viewExtra.length > 0 || storedExtra.length > 0) {\n\t\tyield {\n\t\t\tidentifier: keyOrRoot,\n\t\t\tmismatch: \"allowedTypes\",\n\t\t\tview: viewExtra,\n\t\t\tstored: storedExtra,\n\t\t} satisfies AllowedTypeDiscrepancy;\n\t}\n\n\tif (view.kind !== stored.kind) {\n\t\tyield {\n\t\t\tidentifier: keyOrRoot,\n\t\t\tmismatch: \"fieldKind\",\n\t\t\tview: view.kind,\n\t\t\tstored: stored.kind,\n\t\t} satisfies FieldKindDiscrepancy;\n\t}\n}\n\nfunction* trackObjectNodeDiscrepancies(\n\tview: ObjectNodeStoredSchema,\n\tstored: ObjectNodeStoredSchema,\n): Iterable<FieldDiscrepancy> {\n\t/**\n\t * Similar to the logic used for tracking discrepancies between two node schemas, we will identify\n\t * three types of differences:\n\t * 1. Fields that exist in the view schema but not in the stored schema.\n\t * 2. Fields that exist in both schemas but have different contents.\n\t * 3. Fields that exist in the stored schema but not in the view schema.\n\t *\n\t * First, the view schema is iterated to track the first two types of differences.\n\t * Then, the stored schema is iterated to find the third type.\n\t */\n\n\tfor (const result of compareMaps(view.objectNodeFields, stored.objectNodeFields)) {\n\t\tconst fieldKey = result.key;\n\t\tswitch (result.type) {\n\t\t\tcase \"aExtra\": {\n\t\t\t\tif (result.value.kind === storedEmptyFieldSchema.kind) {\n\t\t\t\t\t// In one of view/stored, this field is explicitly forbidden, but in the other it is implicitly forbidden\n\t\t\t\t\t// (by way of omission). We treat these identically anyway.\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tyield {\n\t\t\t\t\tidentifier: fieldKey,\n\t\t\t\t\tmismatch: \"fieldKind\",\n\t\t\t\t\tview: result.value.kind,\n\t\t\t\t\tstored: storedEmptyFieldSchema.kind,\n\t\t\t\t} satisfies FieldKindDiscrepancy;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"bExtra\": {\n\t\t\t\tif (result.value.kind === storedEmptyFieldSchema.kind) {\n\t\t\t\t\t// In one of view/stored, this field is explicitly forbidden, but in the other it is implicitly forbidden\n\t\t\t\t\t// (by way of omission). We treat these identically anyway.\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tyield {\n\t\t\t\t\tidentifier: fieldKey,\n\t\t\t\t\tmismatch: \"fieldKind\",\n\t\t\t\t\tview: storedEmptyFieldSchema.kind,\n\t\t\t\t\tstored: result.value.kind,\n\t\t\t\t} satisfies FieldKindDiscrepancy;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"both\": {\n\t\t\t\tyield* getFieldDiscrepancies(result.valueA, result.valueB, fieldKey);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction* compareMaps<K, V1, V2>(\n\ta: ReadonlyMap<K, V1>,\n\tb: ReadonlyMap<K, V2>,\n): Iterable<\n\t| { type: \"aExtra\"; key: K; value: V1 }\n\t| { type: \"bExtra\"; key: K; value: V2 }\n\t| { type: \"both\"; key: K; valueA: V1; valueB: V2 }\n> {\n\tfor (const [key, valueA] of a) {\n\t\tconst valueB = b.get(key);\n\t\tyield valueB === undefined\n\t\t\t? { type: \"aExtra\", key, value: valueA }\n\t\t\t: { type: \"both\", key, valueA, valueB };\n\t}\n\tfor (const [key, valueB] of b) {\n\t\tif (!a.has(key)) {\n\t\t\tyield { type: \"bExtra\", key, value: valueB };\n\t\t}\n\t}\n}\n/**\n * @remarks\n *\n * This function uses incompatibilities to determine if changes to a document schema are backward-compatible, i.e., it determines\n * whether the `view` schema allows a superset of the documents that the `stored` schema allows.\n * According to the policy of schema evolution, `isRepoSuperset` supports three types of changes:\n * 1. Adding an optional field to an object node.\n * 2. Expanding the set of allowed types for a field.\n * 3. Relaxing a field kind to a more general field kind.\n *\n * Notes: We expect isRepoSuperset to return consistent results with allowsRepoSuperset. However, currently there are some scenarios\n * where the inconsistency will occur:\n *\n * - Different Node Kinds: If a and b have different node kinds (e.g., a is an objectNodeSchema and b is a mapNodeSchema),\n * `isRepoSuperset` will determine that a can never be the superset of b. In contrast, `allowsRepoSuperset` will continue\n * validating internal fields.\n */\nexport function isRepoSuperset(view: TreeStoredSchema, stored: TreeStoredSchema): boolean {\n\tconst discrepancies = getAllowedContentDiscrepancies(view, stored);\n\n\tfor (const discrepancy of discrepancies) {\n\t\tswitch (discrepancy.mismatch) {\n\t\t\tcase \"nodeKind\": {\n\t\t\t\tif (discrepancy.stored !== undefined) {\n\t\t\t\t\t// It's fine for the view schema to know of a node type that the stored schema doesn't know about.\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"valueSchema\":\n\t\t\tcase \"allowedTypes\":\n\t\t\tcase \"fieldKind\": {\n\t\t\t\tif (!isFieldDiscrepancyCompatible(discrepancy)) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"fields\": {\n\t\t\t\tif (\n\t\t\t\t\tdiscrepancy.differences.some(\n\t\t\t\t\t\t(difference) => !isFieldDiscrepancyCompatible(difference),\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t// No default\n\t\t}\n\t}\n\treturn true;\n}\n\nfunction isFieldDiscrepancyCompatible(discrepancy: FieldDiscrepancy): boolean {\n\tswitch (discrepancy.mismatch) {\n\t\tcase \"allowedTypes\": {\n\t\t\t// Since we only track the symmetric difference between the allowed types in the view and\n\t\t\t// stored schemas, it's sufficient to check if any extra allowed types still exist in the\n\t\t\t// stored schema.\n\t\t\treturn discrepancy.stored.length === 0;\n\t\t}\n\t\tcase \"fieldKind\": {\n\t\t\treturn posetLte(discrepancy.stored, discrepancy.view, fieldRealizer);\n\t\t}\n\t\tcase \"valueSchema\": {\n\t\t\treturn false;\n\t\t}\n\t\t// No default\n\t}\n\treturn false;\n}\n\n/**\n * A linear extension of a partially-ordered set of `T`s. See:\n * https://en.wikipedia.org/wiki/Linear_extension\n *\n * The linear extension is represented as a lookup from each poset element to its index in the linear extension.\n */\ntype LinearExtension<T> = Map<T, number>;\n\n/**\n * A realizer for a partially-ordered set. See:\n * https://en.wikipedia.org/wiki/Order_dimension\n */\ntype Realizer<T> = LinearExtension<T>[];\n\n/**\n * @privateRemarks\n * TODO: Knowledge of specific field kinds is not appropriate for modular schema.\n * This bit of field comparison should be dependency injected by default-schema if this comparison logic remains in modular-schema\n * (this is analogous to what is done in comparison.ts).\n */\nconst FieldKindIdentifiers = {\n\tforbidden: brand<FieldKindIdentifier>(\"Forbidden\"),\n\trequired: brand<FieldKindIdentifier>(\"Value\"),\n\tidentifier: brand<FieldKindIdentifier>(\"Identifier\"),\n\toptional: brand<FieldKindIdentifier>(\"Optional\"),\n\tsequence: brand<FieldKindIdentifier>(\"Sequence\"),\n};\n\n/**\n * A realizer for the partial order of field kind relaxability.\n *\n * It seems extremely likely that this partial order will remain dimension 2 over time (i.e. the set of allowed relaxations can be visualized\n * with a [dominance drawing](https://en.wikipedia.org/wiki/Dominance_drawing)), so this strategy allows efficient comarison between field kinds\n * without excessive casework.\n *\n * Hasse diagram for the partial order is shown below (lower fields can be relaxed to higher fields):\n * ```\n * sequence\n * |\n * optional\n * | \\\n * required forbidden\n * |\n * identifier\n * ```\n */\nconst fieldRealizer: Realizer<FieldKindIdentifier> = [\n\t[\n\t\tFieldKindIdentifiers.forbidden,\n\t\tFieldKindIdentifiers.identifier,\n\t\tFieldKindIdentifiers.required,\n\t\tFieldKindIdentifiers.optional,\n\t\tFieldKindIdentifiers.sequence,\n\t],\n\t[\n\t\tFieldKindIdentifiers.identifier,\n\t\tFieldKindIdentifiers.required,\n\t\tFieldKindIdentifiers.forbidden,\n\t\tFieldKindIdentifiers.optional,\n\t\tFieldKindIdentifiers.sequence,\n\t],\n].map((extension) => new Map(extension.map((identifier, index) => [identifier, index])));\n\nconst PosetComparisonResult = {\n\tLess: \"<\",\n\tGreater: \">\",\n\tEqual: \"=\",\n\tIncomparable: \"||\",\n} as const;\ntype PosetComparisonResult =\n\t(typeof PosetComparisonResult)[keyof typeof PosetComparisonResult];\n\nfunction comparePosetElements<T>(a: T, b: T, realizer: Realizer<T>): PosetComparisonResult {\n\tlet hasLessThanResult = false;\n\tlet hasGreaterThanResult = false;\n\tfor (const extension of realizer) {\n\t\tconst aIndex = extension.get(a);\n\t\tconst bIndex = extension.get(b);\n\t\tassert(aIndex !== undefined && bIndex !== undefined, 0xa72 /* Invalid realizer */);\n\t\tif (aIndex < bIndex) {\n\t\t\thasLessThanResult = true;\n\t\t} else if (aIndex > bIndex) {\n\t\t\thasGreaterThanResult = true;\n\t\t}\n\t}\n\n\treturn hasLessThanResult\n\t\t? hasGreaterThanResult\n\t\t\t? PosetComparisonResult.Incomparable\n\t\t\t: PosetComparisonResult.Less\n\t\t: hasGreaterThanResult\n\t\t\t? PosetComparisonResult.Greater\n\t\t\t: PosetComparisonResult.Equal;\n}\n\nfunction posetLte<T>(a: T, b: T, realizer: Realizer<T>): boolean {\n\tconst comparison = comparePosetElements(a, b, realizer);\n\treturn (\n\t\tcomparison === PosetComparisonResult.Less || comparison === PosetComparisonResult.Equal\n\t);\n}\n\nfunction throwUnsupportedNodeType(type: string): never {\n\tthrow new TypeError(`Unsupported node stored schema type: ${type}`);\n}\n"]}
1
+ {"version":3,"file":"discrepancies.js","sourceRoot":"","sources":["../../../src/feature-libraries/modular-schema/discrepancies.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAE7D,kDAa6B;AAC7B,kDAA4C;AAoH5C,SAAS,iBAAiB,CAAC,UAAgC;IAC1D,IAAI,UAAU,YAAY,iCAAsB,EAAE,CAAC;QAClD,OAAO,QAAQ,CAAC;IACjB,CAAC;SAAM,IAAI,UAAU,YAAY,8BAAmB,EAAE,CAAC;QACtD,OAAO,KAAK,CAAC;IACd,CAAC;SAAM,IAAI,UAAU,YAAY,+BAAoB,EAAE,CAAC;QACvD,OAAO,MAAM,CAAC;IACf,CAAC;IACD,wBAAwB,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;;;;GAUG;AACH,QAAe,CAAC,CAAC,8BAA8B,CAC9C,IAAsB,EACtB,MAAwB;IAExB,kCAAkC;IAClC,KAAK,CAAC,CAAC,qBAAqB,CAC3B,IAAI,CAAC,eAAe,EACpB,MAAM,CAAC,eAAe,E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AC,CAAC;IACxD,OAAO,CACN,UAAU,KAAK,6BAAqB,CAAC,IAAI,IAAI,UAAU,KAAK,6BAAqB,CAAC,KAAK,CACvF,CAAC;AACH,CAAC;AALD,4BAKC;AAED,SAAS,wBAAwB,CAAC,IAAY;IAC7C,MAAM,IAAI,SAAS,CAAC,wCAAwC,IAAI,EAAE,CAAC,CAAC;AACrE,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\ttype FieldKey,\n\ttype FieldKindIdentifier,\n\tLeafNodeStoredSchema,\n\tMapNodeStoredSchema,\n\tObjectNodeStoredSchema,\n\tstoredEmptyFieldSchema,\n\ttype TreeFieldStoredSchema,\n\ttype TreeNodeSchemaIdentifier,\n\ttype TreeNodeStoredSchema,\n\ttype TreeStoredSchema,\n\ttype TreeTypeSet,\n\ttype ValueSchema,\n} from \"../../core/index.js\";\nimport { brand } from \"../../util/index.js\";\n\n// TODO:\n// The comparisons in this file seem redundant with those in comparison.ts.\n// Rather than both existing, one of which just returns boolean and the other which returns additional details, a simple comparison which returns everything needed should be used.\n\n/**\n * Discriminated union (keyed on `mismatch`) of discrepancies between a view and stored schema.\n * @remarks\n *\n * 1. FieldDiscrepancy\n *\n * `FieldDiscrepancy` represents the differences between two `TreeFieldStoredSchema` objects. It consists of\n * three types of incompatibilities:\n *\n * - FieldKindDiscrepancy: Indicates the differences in `FieldKindIdentifier` between two `TreeFieldStoredSchema`\n * objects (e.g., optional, required, sequence, etc.).\n * - AllowedTypesDiscrepancy: Indicates the differences in the allowed child types between the two schemas.\n * - ValueSchemaDiscrepancy: Specifically indicates the differences in the `ValueSchema` of two\n * `LeafNodeStoredSchema` objects.\n *\n * 2. NodeDiscrepancy\n *\n * `NodeDiscrepancy` represents the differences between two `TreeNodeStoredSchema` objects and includes:\n *\n * - NodeKindDiscrepancy: Indicates the differences in the types of `TreeNodeStoredSchema` (currently supports\n * `ObjectNodeStoredSchema`, `MapNodeStoredSchema`, and `LeafNodeStoredSchema`).\n * - NodeFieldsDiscrepancy: Indicates the `FieldDiscrepancy` of `TreeFieldStoredSchema` within two\n * `TreeNodeStoredSchema`. It includes an array of `FieldDiscrepancy` instances in the `differences` field.\n *\n * When comparing two nodes for compatibility, it only makes sense to compare their fields if the nodes are of\n * the same kind (map, object, leaf).\n *\n * 3. Discrepancy\n *\n * Discrepancy consists of both `NodeDiscrepancy` and `FieldDiscrepancy`, representing any kind of\n * schema differences. See {@link getAllowedContentDiscrepancies} for more details about how we process it\n * and the ordering.\n */\nexport type Discrepancy = FieldDiscrepancy | NodeDiscrepancy;\n\nexport type NodeDiscrepancy = NodeKindDiscrepancy | NodeFieldsDiscrepancy;\n\n/**\n * A discrepancy in the declaration of a field.\n */\nexport type FieldDiscrepancy =\n\t| AllowedTypeDiscrepancy\n\t| FieldKindDiscrepancy\n\t| ValueSchemaDiscrepancy;\n\n/**\n * Information about where a field discrepancy is located within a collection of schema.\n */\nexport interface FieldDiscrepancyLocation {\n\t/**\n\t * The {@link TreeNodeSchemaIdentifier} that contains the discrepancy.\n\t *\n\t * Undefined iff the discrepancy is part of the root field schema.\n\t */\n\tidentifier: TreeNodeSchemaIdentifier | undefined;\n\t/**\n\t * The {@link FieldKey} for the field that contains the discrepancy.\n\t * Undefined when:\n\t * - the discrepancy is part of the root field schema\n\t * - the discrepancy is for 'all fields' of a map node\n\t */\n\tfieldKey: FieldKey | undefined;\n}\n\n/**\n * A discrepancy in the allowed types of a field.\n *\n * @remarks\n * This reports the symmetric difference of allowed types in view/stored to enable more efficient checks for compatibility\n */\nexport interface AllowedTypeDiscrepancy extends FieldDiscrepancyLocation {\n\tmismatch: \"allowedTypes\";\n\t/**\n\t * List of allowed type identifiers in viewed schema which are not allowed in stored schema\n\t */\n\tview: TreeNodeSchemaIdentifier[];\n\t/**\n\t * List of allowed type identifiers in stored schema which are not allowed in view schema\n\t */\n\tstored: TreeNodeSchemaIdentifier[];\n}\n\nexport interface FieldKindDiscrepancy extends FieldDiscrepancyLocation {\n\tmismatch: \"fieldKind\";\n\tview: FieldKindIdentifier;\n\tstored: FieldKindIdentifier;\n}\n\nexport interface ValueSchemaDiscrepancy {\n\tidentifier: TreeNodeSchemaIdentifier;\n\tmismatch: \"valueSchema\";\n\tview: ValueSchema | undefined;\n\tstored: ValueSchema | undefined;\n}\n\nexport interface NodeKindDiscrepancy {\n\tidentifier: TreeNodeSchemaIdentifier;\n\tmismatch: \"nodeKind\";\n\tview: SchemaFactoryNodeKind | undefined;\n\tstored: SchemaFactoryNodeKind | undefined;\n}\n\nexport interface NodeFieldsDiscrepancy {\n\tidentifier: TreeNodeSchemaIdentifier;\n\tmismatch: \"fields\";\n\tdifferences: FieldDiscrepancy[];\n}\n\ntype SchemaFactoryNodeKind = \"object\" | \"leaf\" | \"map\";\n\nfunction getNodeSchemaType(nodeSchema: TreeNodeStoredSchema): SchemaFactoryNodeKind {\n\tif (nodeSchema instanceof ObjectNodeStoredSchema) {\n\t\treturn \"object\";\n\t} else if (nodeSchema instanceof MapNodeStoredSchema) {\n\t\treturn \"map\";\n\t} else if (nodeSchema instanceof LeafNodeStoredSchema) {\n\t\treturn \"leaf\";\n\t}\n\tthrowUnsupportedNodeType(nodeSchema.constructor.name);\n}\n\n/**\n * Finds and reports discrepancies between a view schema and a stored schema.\n *\n * See documentation on {@link Discrepancy} for details of possible discrepancies.\n * @remarks\n * This function does not attempt to distinguish between equivalent representations of a node/field involving extraneous never trees.\n * For example, a Forbidden field with allowed type set `[]` is equivalent to an optional field with allowed type set `[]`,\n * as well as an optional field with an allowed type set containing only unconstructable types.\n *\n * It is up to the caller to determine whether such discrepancies matter.\n */\nexport function* getAllowedContentDiscrepancies(\n\tview: TreeStoredSchema,\n\tstored: TreeStoredSchema,\n): Iterable<Discrepancy> {\n\t// check root schema discrepancies\n\tyield* getFieldDiscrepancies(\n\t\tview.rootFieldSchema,\n\t\tstored.rootFieldSchema,\n\t\tundefined,\n\t\tundefined,\n\t);\n\n\tfor (const result of compareMaps(view.nodeSchema, stored.nodeSchema)) {\n\t\tswitch (result.type) {\n\t\t\tcase \"aExtra\": {\n\t\t\t\tconst viewType = getNodeSchemaType(result.value);\n\t\t\t\tyield {\n\t\t\t\t\tidentifier: result.key,\n\t\t\t\t\tmismatch: \"nodeKind\",\n\t\t\t\t\tview: viewType,\n\t\t\t\t\tstored: undefined,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"bExtra\": {\n\t\t\t\tconst storedType = getNodeSchemaType(result.value);\n\t\t\t\tyield {\n\t\t\t\t\tidentifier: result.key,\n\t\t\t\t\tmismatch: \"nodeKind\",\n\t\t\t\t\tview: undefined,\n\t\t\t\t\tstored: storedType,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"both\": {\n\t\t\t\tyield* getNodeDiscrepancies(result.key, result.valueA, result.valueB);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\nfunction* getNodeDiscrepancies(\n\tidentifier: TreeNodeSchemaIdentifier,\n\tview: TreeNodeStoredSchema,\n\tstored: TreeNodeStoredSchema,\n): Iterable<Discrepancy> {\n\tconst viewType = getNodeSchemaType(view);\n\tconst storedType = getNodeSchemaType(stored);\n\tif (viewType !== storedType) {\n\t\tyield {\n\t\t\tidentifier,\n\t\t\tmismatch: \"nodeKind\",\n\t\t\tview: viewType,\n\t\t\tstored: storedType,\n\t\t};\n\t\treturn;\n\t}\n\n\tswitch (viewType) {\n\t\tcase \"object\": {\n\t\t\tconst differences = Array.from(\n\t\t\t\ttrackObjectNodeDiscrepancies(\n\t\t\t\t\tidentifier,\n\t\t\t\t\tview as ObjectNodeStoredSchema,\n\t\t\t\t\tstored as ObjectNodeStoredSchema,\n\t\t\t\t),\n\t\t\t);\n\t\t\tif (differences.length > 0) {\n\t\t\t\tyield {\n\t\t\t\t\tidentifier,\n\t\t\t\t\tmismatch: \"fields\",\n\t\t\t\t\tdifferences,\n\t\t\t\t} satisfies NodeFieldsDiscrepancy;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase \"map\":\n\t\t\tyield* getFieldDiscrepancies(\n\t\t\t\t(view as MapNodeStoredSchema).mapFields,\n\t\t\t\t(stored as MapNodeStoredSchema).mapFields,\n\t\t\t\tidentifier,\n\t\t\t\tundefined,\n\t\t\t);\n\t\t\tbreak;\n\t\tcase \"leaf\": {\n\t\t\tconst viewValue = (view as LeafNodeStoredSchema).leafValue;\n\t\t\tconst storedValue = (stored as LeafNodeStoredSchema).leafValue;\n\t\t\tif (viewValue !== storedValue) {\n\t\t\t\tyield {\n\t\t\t\t\tidentifier,\n\t\t\t\t\tmismatch: \"valueSchema\",\n\t\t\t\t\tview: viewValue,\n\t\t\t\t\tstored: storedValue,\n\t\t\t\t};\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tdefault:\n\t\t\tbreak;\n\t}\n}\n\n/**\n * The function to track the discrepancies between two field stored schemas.\n *\n * @param keyOrRoot - If the key is missing, it indicates that this is the root field schema.\n */\nfunction* getFieldDiscrepancies(\n\tview: TreeFieldStoredSchema,\n\tstored: TreeFieldStoredSchema,\n\tidentifier: TreeNodeSchemaIdentifier | undefined,\n\tfieldKey: FieldKey | undefined,\n): Iterable<FieldDiscrepancy> {\n\t// Only track the symmetric differences of two sets.\n\tconst findSetDiscrepancies = (\n\t\ta: TreeTypeSet,\n\t\tb: TreeTypeSet,\n\t): [TreeNodeSchemaIdentifier[], TreeNodeSchemaIdentifier[]] => {\n\t\tconst aDiff = [...a].filter((value) => !b.has(value));\n\t\tconst bDiff = [...b].filter((value) => !a.has(value));\n\t\treturn [aDiff, bDiff];\n\t};\n\n\tconst [viewExtra, storedExtra] = findSetDiscrepancies(view.types, stored.types);\n\tif (viewExtra.length > 0 || storedExtra.length > 0) {\n\t\tyield {\n\t\t\tidentifier,\n\t\t\tfieldKey,\n\t\t\tmismatch: \"allowedTypes\",\n\t\t\tview: viewExtra,\n\t\t\tstored: storedExtra,\n\t\t} satisfies AllowedTypeDiscrepancy;\n\t}\n\n\tif (view.kind !== stored.kind) {\n\t\tyield {\n\t\t\tidentifier,\n\t\t\tfieldKey,\n\t\t\tmismatch: \"fieldKind\",\n\t\t\tview: view.kind,\n\t\t\tstored: stored.kind,\n\t\t} satisfies FieldKindDiscrepancy;\n\t}\n}\n\nfunction* trackObjectNodeDiscrepancies(\n\tidentifier: TreeNodeSchemaIdentifier,\n\tview: ObjectNodeStoredSchema,\n\tstored: ObjectNodeStoredSchema,\n): Iterable<FieldDiscrepancy> {\n\t/**\n\t * Similar to the logic used for tracking discrepancies between two node schemas, we will identify\n\t * three types of differences:\n\t * 1. Fields that exist in the view schema but not in the stored schema.\n\t * 2. Fields that exist in both schemas but have different contents.\n\t * 3. Fields that exist in the stored schema but not in the view schema.\n\t *\n\t * First, the view schema is iterated to track the first two types of differences.\n\t * Then, the stored schema is iterated to find the third type.\n\t */\n\n\tfor (const result of compareMaps(view.objectNodeFields, stored.objectNodeFields)) {\n\t\tconst fieldKey = result.key;\n\t\tswitch (result.type) {\n\t\t\tcase \"aExtra\": {\n\t\t\t\tif (result.value.kind === storedEmptyFieldSchema.kind) {\n\t\t\t\t\t// In one of view/stored, this field is explicitly forbidden, but in the other it is implicitly forbidden\n\t\t\t\t\t// (by way of omission). We treat these identically anyway.\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tyield {\n\t\t\t\t\tidentifier,\n\t\t\t\t\tfieldKey,\n\t\t\t\t\tmismatch: \"fieldKind\",\n\t\t\t\t\tview: result.value.kind,\n\t\t\t\t\tstored: storedEmptyFieldSchema.kind,\n\t\t\t\t} satisfies FieldKindDiscrepancy;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"bExtra\": {\n\t\t\t\tif (result.value.kind === storedEmptyFieldSchema.kind) {\n\t\t\t\t\t// In one of view/stored, this field is explicitly forbidden, but in the other it is implicitly forbidden\n\t\t\t\t\t// (by way of omission). We treat these identically anyway.\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tyield {\n\t\t\t\t\tidentifier,\n\t\t\t\t\tfieldKey,\n\t\t\t\t\tmismatch: \"fieldKind\",\n\t\t\t\t\tview: storedEmptyFieldSchema.kind,\n\t\t\t\t\tstored: result.value.kind,\n\t\t\t\t} satisfies FieldKindDiscrepancy;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"both\": {\n\t\t\t\tyield* getFieldDiscrepancies(result.valueA, result.valueB, identifier, fieldKey);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\nfunction* compareMaps<K, V1, V2>(\n\ta: ReadonlyMap<K, V1>,\n\tb: ReadonlyMap<K, V2>,\n): Iterable<\n\t| { type: \"aExtra\"; key: K; value: V1 }\n\t| { type: \"bExtra\"; key: K; value: V2 }\n\t| { type: \"both\"; key: K; valueA: V1; valueB: V2 }\n> {\n\tfor (const [key, valueA] of a) {\n\t\tconst valueB = b.get(key);\n\t\tyield valueB === undefined\n\t\t\t? { type: \"aExtra\", key, value: valueA }\n\t\t\t: { type: \"both\", key, valueA, valueB };\n\t}\n\tfor (const [key, valueB] of b) {\n\t\tif (!a.has(key)) {\n\t\t\tyield { type: \"bExtra\", key, value: valueB };\n\t\t}\n\t}\n}\n/**\n * @remarks\n *\n * This function uses incompatibilities to determine if changes to a document schema are backward-compatible, i.e., it determines\n * whether the `view` schema allows a superset of the documents that the `stored` schema allows.\n * According to the policy of schema evolution, `isRepoSuperset` supports three types of changes:\n * 1. Adding an optional field to an object node.\n * 2. Expanding the set of allowed types for a field.\n * 3. Relaxing a field kind to a more general field kind.\n *\n * Notes: We expect isRepoSuperset to return consistent results with allowsRepoSuperset. However, currently there are some scenarios\n * where the inconsistency will occur:\n *\n * - Different Node Kinds: If a and b have different node kinds (e.g., a is an objectNodeSchema and b is a mapNodeSchema),\n * `isRepoSuperset` will determine that a can never be the superset of b. In contrast, `allowsRepoSuperset` will continue\n * validating internal fields.\n */\nexport function isRepoSuperset(view: TreeStoredSchema, stored: TreeStoredSchema): boolean {\n\tconst discrepancies = getAllowedContentDiscrepancies(view, stored);\n\n\tfor (const discrepancy of discrepancies) {\n\t\tswitch (discrepancy.mismatch) {\n\t\t\tcase \"nodeKind\": {\n\t\t\t\tif (discrepancy.stored !== undefined) {\n\t\t\t\t\t// It's fine for the view schema to know of a node type that the stored schema doesn't know about.\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"valueSchema\":\n\t\t\tcase \"allowedTypes\":\n\t\t\tcase \"fieldKind\": {\n\t\t\t\tif (!isFieldDiscrepancyCompatible(discrepancy)) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"fields\": {\n\t\t\t\tif (\n\t\t\t\t\tdiscrepancy.differences.some(\n\t\t\t\t\t\t(difference) => !isFieldDiscrepancyCompatible(difference),\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t// No default\n\t\t}\n\t}\n\treturn true;\n}\n\nfunction isFieldDiscrepancyCompatible(discrepancy: FieldDiscrepancy): boolean {\n\tswitch (discrepancy.mismatch) {\n\t\tcase \"allowedTypes\": {\n\t\t\t// Since we only track the symmetric difference between the allowed types in the view and\n\t\t\t// stored schemas, it's sufficient to check if any extra allowed types still exist in the\n\t\t\t// stored schema.\n\t\t\treturn discrepancy.stored.length === 0;\n\t\t}\n\t\tcase \"fieldKind\": {\n\t\t\treturn posetLte(discrepancy.stored, discrepancy.view, fieldRealizer);\n\t\t}\n\t\tcase \"valueSchema\": {\n\t\t\treturn false;\n\t\t}\n\t\t// No default\n\t}\n\treturn false;\n}\n\n/**\n * A linear extension of a partially-ordered set of `T`s. See:\n * https://en.wikipedia.org/wiki/Linear_extension\n *\n * The linear extension is represented as a lookup from each poset element to its index in the linear extension.\n */\nexport type LinearExtension<T> = Map<T, number>;\n\n/**\n * A realizer for a partially-ordered set. See:\n * https://en.wikipedia.org/wiki/Order_dimension\n */\nexport type Realizer<T> = LinearExtension<T>[];\n\n/**\n * @privateRemarks\n * TODO: Knowledge of specific field kinds is not appropriate for modular schema.\n * This bit of field comparison should be dependency injected by default-schema if this comparison logic remains in modular-schema\n * (this is analogous to what is done in comparison.ts).\n */\nconst FieldKindIdentifiers = {\n\tforbidden: brand<FieldKindIdentifier>(\"Forbidden\"),\n\trequired: brand<FieldKindIdentifier>(\"Value\"),\n\tidentifier: brand<FieldKindIdentifier>(\"Identifier\"),\n\toptional: brand<FieldKindIdentifier>(\"Optional\"),\n\tsequence: brand<FieldKindIdentifier>(\"Sequence\"),\n};\n\n/**\n * A realizer for the partial order of field kind relaxability.\n *\n * It seems extremely likely that this partial order will remain dimension 2 over time (i.e. the set of allowed relaxations can be visualized\n * with a [dominance drawing](https://en.wikipedia.org/wiki/Dominance_drawing)), so this strategy allows efficient comarison between field kinds\n * without excessive casework.\n *\n * Hasse diagram for the partial order is shown below (lower fields can be relaxed to higher fields):\n * ```\n * sequence\n * |\n * optional\n * | \\\n * required forbidden\n * |\n * identifier\n * ```\n */\nexport const fieldRealizer: Realizer<FieldKindIdentifier> = [\n\t[\n\t\tFieldKindIdentifiers.forbidden,\n\t\tFieldKindIdentifiers.identifier,\n\t\tFieldKindIdentifiers.required,\n\t\tFieldKindIdentifiers.optional,\n\t\tFieldKindIdentifiers.sequence,\n\t],\n\t[\n\t\tFieldKindIdentifiers.identifier,\n\t\tFieldKindIdentifiers.required,\n\t\tFieldKindIdentifiers.forbidden,\n\t\tFieldKindIdentifiers.optional,\n\t\tFieldKindIdentifiers.sequence,\n\t],\n].map((extension) => new Map(extension.map((identifier, index) => [identifier, index])));\n\nexport const PosetComparisonResult = {\n\tLess: \"<\",\n\tGreater: \">\",\n\tEqual: \"=\",\n\tIncomparable: \"||\",\n} as const;\ntype PosetComparisonResult =\n\t(typeof PosetComparisonResult)[keyof typeof PosetComparisonResult];\n\nexport function comparePosetElements<T>(\n\ta: T,\n\tb: T,\n\trealizer: Realizer<T>,\n): PosetComparisonResult {\n\tlet hasLessThanResult = false;\n\tlet hasGreaterThanResult = false;\n\tfor (const extension of realizer) {\n\t\tconst aIndex = extension.get(a);\n\t\tconst bIndex = extension.get(b);\n\t\tassert(aIndex !== undefined && bIndex !== undefined, 0xa72 /* Invalid realizer */);\n\t\tif (aIndex < bIndex) {\n\t\t\thasLessThanResult = true;\n\t\t} else if (aIndex > bIndex) {\n\t\t\thasGreaterThanResult = true;\n\t\t}\n\t}\n\n\treturn hasLessThanResult\n\t\t? hasGreaterThanResult\n\t\t\t? PosetComparisonResult.Incomparable\n\t\t\t: PosetComparisonResult.Less\n\t\t: hasGreaterThanResult\n\t\t\t? PosetComparisonResult.Greater\n\t\t\t: PosetComparisonResult.Equal;\n}\n\nexport function posetLte<T>(a: T, b: T, realizer: Realizer<T>): boolean {\n\tconst comparison = comparePosetElements(a, b, realizer);\n\treturn (\n\t\tcomparison === PosetComparisonResult.Less || comparison === PosetComparisonResult.Equal\n\t);\n}\n\nfunction throwUnsupportedNodeType(type: string): never {\n\tthrow new TypeError(`Unsupported node stored schema type: ${type}`);\n}\n"]}
@@ -15,5 +15,5 @@ export type { GenericChangeset } from "./genericFieldKindTypes.js";
15
15
  export { ModularChangeFamily, ModularEditBuilder, type EditDescription, type GlobalEditDescription, type FieldEditDescription, rebaseRevisionMetadataFromInfo, intoDelta, relevantRemovedRoots, updateRefreshers, } from "./modularChangeFamily.js";
16
16
  export { makeModularChangeCodecFamily } from "./modularChangeCodecs.js";
17
17
  export type { FieldKindConfiguration, FieldKindConfigurationEntry, } from "./fieldKindConfiguration.js";
18
- export { getAllowedContentDiscrepancies, isRepoSuperset, } from "./discrepancies.js";
18
+ export { getAllowedContentDiscrepancies, isRepoSuperset, type AllowedTypeDiscrepancy, type FieldKindDiscrepancy, type ValueSchemaDiscrepancy, type FieldDiscrepancy, type NodeDiscrepancy, type NodeKindDiscrepancy, type NodeFieldsDiscrepancy, type LinearExtension, type Realizer, fieldRealizer, PosetComparisonResult, comparePosetElements, posetLte, } from "./discrepancies.js";
19
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/modular-schema/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,kBAAkB,EAClB,kCAAkC,EAClC,mBAAmB,EACnB,kBAAkB,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EACN,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,gBAAgB,EAChB,kBAAkB,GAClB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EACvB,oBAAoB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EACN,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,+BAA+B,EAC/B,KAAK,sBAAsB,EAC3B,KAAK,6BAA6B,EAClC,KAAK,OAAO,EACZ,eAAe,EACf,KAAK,0BAA0B,GAC/B,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACX,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,MAAM,GACN,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACN,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,GAChB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EACN,mBAAmB,EACnB,kBAAkB,EAClB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,8BAA8B,EAC9B,SAAS,EACT,oBAAoB,EACpB,gBAAgB,GAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AACxE,YAAY,EACX,sBAAsB,EACtB,2BAA2B,GAC3B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACN,8BAA8B,EAC9B,cAAc,GACd,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/modular-schema/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,kBAAkB,EAClB,kCAAkC,EAClC,mBAAmB,EACnB,kBAAkB,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EACN,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,gBAAgB,EAChB,kBAAkB,GAClB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EACvB,oBAAoB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EACN,KAAK,kBAAkB,E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