@fluidframework/tree 2.93.0 → 2.101.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 (273) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/INCREMENTAL_SUMMARY.md +89 -0
  3. package/README.md +6 -0
  4. package/api-report/tree.alpha.api.md +6 -1
  5. package/api-report/tree.beta.api.md +3 -1
  6. package/api-report/tree.legacy.beta.api.md +3 -1
  7. package/dist/core/change-family/changeFamily.d.ts +23 -0
  8. package/dist/core/change-family/changeFamily.d.ts.map +1 -1
  9. package/dist/core/change-family/changeFamily.js.map +1 -1
  10. package/dist/core/tree/detachedFieldIndexCodecV1.d.ts.map +1 -1
  11. package/dist/core/tree/detachedFieldIndexCodecV1.js +2 -0
  12. package/dist/core/tree/detachedFieldIndexCodecV1.js.map +1 -1
  13. package/dist/core/tree/detachedFieldIndexCodecV2.d.ts.map +1 -1
  14. package/dist/core/tree/detachedFieldIndexCodecV2.js +2 -0
  15. package/dist/core/tree/detachedFieldIndexCodecV2.js.map +1 -1
  16. package/dist/feature-libraries/chunked-forest/basicChunk.d.ts +25 -1
  17. package/dist/feature-libraries/chunked-forest/basicChunk.d.ts.map +1 -1
  18. package/dist/feature-libraries/chunked-forest/basicChunk.js +71 -18
  19. package/dist/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  20. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +13 -4
  21. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  22. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js +31 -4
  23. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  24. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts +27 -0
  25. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  26. package/dist/feature-libraries/chunked-forest/codec/codecs.js +5 -2
  27. package/dist/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  28. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +10 -2
  29. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
  30. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js +7 -2
  31. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  32. package/dist/feature-libraries/chunked-forest/codec/format/formatGeneric.d.ts +1 -2
  33. package/dist/feature-libraries/chunked-forest/codec/format/formatGeneric.d.ts.map +1 -1
  34. package/dist/feature-libraries/chunked-forest/codec/format/formatGeneric.js +0 -1
  35. package/dist/feature-libraries/chunked-forest/codec/format/formatGeneric.js.map +1 -1
  36. package/dist/feature-libraries/chunked-forest/codec/format/index.d.ts +1 -1
  37. package/dist/feature-libraries/chunked-forest/codec/format/index.d.ts.map +1 -1
  38. package/dist/feature-libraries/chunked-forest/codec/format/index.js +2 -1
  39. package/dist/feature-libraries/chunked-forest/codec/format/index.js.map +1 -1
  40. package/dist/feature-libraries/chunked-forest/codec/format/versions.d.ts +10 -2
  41. package/dist/feature-libraries/chunked-forest/codec/format/versions.d.ts.map +1 -1
  42. package/dist/feature-libraries/chunked-forest/codec/format/versions.js +15 -1
  43. package/dist/feature-libraries/chunked-forest/codec/format/versions.js.map +1 -1
  44. package/dist/feature-libraries/chunked-forest/codec/nodeEncoder.d.ts.map +1 -1
  45. package/dist/feature-libraries/chunked-forest/codec/nodeEncoder.js +9 -1
  46. package/dist/feature-libraries/chunked-forest/codec/nodeEncoder.js.map +1 -1
  47. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts +3 -3
  48. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts.map +1 -1
  49. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.js +8 -8
  50. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.js.map +1 -1
  51. package/dist/feature-libraries/chunked-forest/uniformChunk.d.ts +6 -1
  52. package/dist/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  53. package/dist/feature-libraries/chunked-forest/uniformChunk.js +25 -1
  54. package/dist/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  55. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +19 -0
  56. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -1
  57. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js +76 -22
  58. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
  59. package/dist/feature-libraries/modular-schema/genericFieldKindFormat.d.ts +2 -14
  60. package/dist/feature-libraries/modular-schema/genericFieldKindFormat.d.ts.map +1 -1
  61. package/dist/feature-libraries/modular-schema/genericFieldKindFormat.js +1 -17
  62. package/dist/feature-libraries/modular-schema/genericFieldKindFormat.js.map +1 -1
  63. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.d.ts.map +1 -1
  64. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.js +4 -0
  65. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.js.map +1 -1
  66. package/dist/packageVersion.d.ts +1 -1
  67. package/dist/packageVersion.d.ts.map +1 -1
  68. package/dist/packageVersion.js +1 -1
  69. package/dist/packageVersion.js.map +1 -1
  70. package/dist/shared-tree/independentView.d.ts.map +1 -1
  71. package/dist/shared-tree/independentView.js +2 -0
  72. package/dist/shared-tree/independentView.js.map +1 -1
  73. package/dist/shared-tree/sharedTree.d.ts +35 -1
  74. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  75. package/dist/shared-tree/sharedTree.js +6 -0
  76. package/dist/shared-tree/sharedTree.js.map +1 -1
  77. package/dist/shared-tree/sharedTreeChangeCodecs.js +1 -0
  78. package/dist/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
  79. package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
  80. package/dist/shared-tree/treeAlpha.js +2 -0
  81. package/dist/shared-tree/treeAlpha.js.map +1 -1
  82. package/dist/shared-tree/treeCheckout.d.ts +1 -1
  83. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  84. package/dist/shared-tree/treeCheckout.js +2 -0
  85. package/dist/shared-tree/treeCheckout.js.map +1 -1
  86. package/dist/shared-tree-core/editManagerCodecs.d.ts +3 -0
  87. package/dist/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
  88. package/dist/shared-tree-core/editManagerCodecs.js.map +1 -1
  89. package/dist/shared-tree-core/editManagerCodecsCommons.d.ts +14 -0
  90. package/dist/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -1
  91. package/dist/shared-tree-core/editManagerCodecsCommons.js +14 -0
  92. package/dist/shared-tree-core/editManagerCodecsCommons.js.map +1 -1
  93. package/dist/shared-tree-core/editManagerCodecsV1toV4.d.ts +3 -0
  94. package/dist/shared-tree-core/editManagerCodecsV1toV4.d.ts.map +1 -1
  95. package/dist/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -1
  96. package/dist/shared-tree-core/editManagerCodecsVSharedBranches.d.ts +3 -0
  97. package/dist/shared-tree-core/editManagerCodecsVSharedBranches.d.ts.map +1 -1
  98. package/dist/shared-tree-core/editManagerCodecsVSharedBranches.js.map +1 -1
  99. package/dist/shared-tree-core/editManagerSummarizer.d.ts +9 -1
  100. package/dist/shared-tree-core/editManagerSummarizer.d.ts.map +1 -1
  101. package/dist/shared-tree-core/editManagerSummarizer.js +20 -5
  102. package/dist/shared-tree-core/editManagerSummarizer.js.map +1 -1
  103. package/dist/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -1
  104. package/dist/shared-tree-core/messageCodecV1ToV4.js +4 -0
  105. package/dist/shared-tree-core/messageCodecV1ToV4.js.map +1 -1
  106. package/dist/shared-tree-core/messageCodecVSharedBranches.d.ts.map +1 -1
  107. package/dist/shared-tree-core/messageCodecVSharedBranches.js +4 -0
  108. package/dist/shared-tree-core/messageCodecVSharedBranches.js.map +1 -1
  109. package/dist/shared-tree-core/sharedTreeCore.d.ts +4 -0
  110. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  111. package/dist/shared-tree-core/sharedTreeCore.js +1 -1
  112. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  113. package/dist/simple-tree/api/schemaFactory.d.ts +3 -3
  114. package/dist/simple-tree/api/schemaFactory.js +3 -3
  115. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  116. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +17 -1
  117. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
  118. package/dist/simple-tree/api/schemaFactoryAlpha.js +9 -0
  119. package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
  120. package/dist/tableSchema.d.ts.map +1 -1
  121. package/dist/tableSchema.js +102 -20
  122. package/dist/tableSchema.js.map +1 -1
  123. package/docs/user-facing/isolated-declarations.md +147 -0
  124. package/lib/core/change-family/changeFamily.d.ts +23 -0
  125. package/lib/core/change-family/changeFamily.d.ts.map +1 -1
  126. package/lib/core/change-family/changeFamily.js.map +1 -1
  127. package/lib/core/tree/detachedFieldIndexCodecV1.d.ts.map +1 -1
  128. package/lib/core/tree/detachedFieldIndexCodecV1.js +2 -0
  129. package/lib/core/tree/detachedFieldIndexCodecV1.js.map +1 -1
  130. package/lib/core/tree/detachedFieldIndexCodecV2.d.ts.map +1 -1
  131. package/lib/core/tree/detachedFieldIndexCodecV2.js +2 -0
  132. package/lib/core/tree/detachedFieldIndexCodecV2.js.map +1 -1
  133. package/lib/feature-libraries/chunked-forest/basicChunk.d.ts +25 -1
  134. package/lib/feature-libraries/chunked-forest/basicChunk.d.ts.map +1 -1
  135. package/lib/feature-libraries/chunked-forest/basicChunk.js +72 -19
  136. package/lib/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  137. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +13 -4
  138. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  139. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js +32 -5
  140. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  141. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts +27 -0
  142. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  143. package/lib/feature-libraries/chunked-forest/codec/codecs.js +6 -3
  144. package/lib/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  145. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +10 -2
  146. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
  147. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js +8 -3
  148. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  149. package/lib/feature-libraries/chunked-forest/codec/format/formatGeneric.d.ts +1 -2
  150. package/lib/feature-libraries/chunked-forest/codec/format/formatGeneric.d.ts.map +1 -1
  151. package/lib/feature-libraries/chunked-forest/codec/format/formatGeneric.js +0 -1
  152. package/lib/feature-libraries/chunked-forest/codec/format/formatGeneric.js.map +1 -1
  153. package/lib/feature-libraries/chunked-forest/codec/format/index.d.ts +1 -1
  154. package/lib/feature-libraries/chunked-forest/codec/format/index.d.ts.map +1 -1
  155. package/lib/feature-libraries/chunked-forest/codec/format/index.js +1 -1
  156. package/lib/feature-libraries/chunked-forest/codec/format/index.js.map +1 -1
  157. package/lib/feature-libraries/chunked-forest/codec/format/versions.d.ts +10 -2
  158. package/lib/feature-libraries/chunked-forest/codec/format/versions.d.ts.map +1 -1
  159. package/lib/feature-libraries/chunked-forest/codec/format/versions.js +13 -0
  160. package/lib/feature-libraries/chunked-forest/codec/format/versions.js.map +1 -1
  161. package/lib/feature-libraries/chunked-forest/codec/nodeEncoder.d.ts.map +1 -1
  162. package/lib/feature-libraries/chunked-forest/codec/nodeEncoder.js +9 -1
  163. package/lib/feature-libraries/chunked-forest/codec/nodeEncoder.js.map +1 -1
  164. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts +3 -3
  165. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts.map +1 -1
  166. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.js +8 -8
  167. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.js.map +1 -1
  168. package/lib/feature-libraries/chunked-forest/uniformChunk.d.ts +6 -1
  169. package/lib/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  170. package/lib/feature-libraries/chunked-forest/uniformChunk.js +26 -2
  171. package/lib/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  172. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +19 -0
  173. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -1
  174. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js +76 -22
  175. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
  176. package/lib/feature-libraries/modular-schema/genericFieldKindFormat.d.ts +2 -14
  177. package/lib/feature-libraries/modular-schema/genericFieldKindFormat.d.ts.map +1 -1
  178. package/lib/feature-libraries/modular-schema/genericFieldKindFormat.js +1 -17
  179. package/lib/feature-libraries/modular-schema/genericFieldKindFormat.js.map +1 -1
  180. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.d.ts.map +1 -1
  181. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.js +4 -0
  182. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.js.map +1 -1
  183. package/lib/packageVersion.d.ts +1 -1
  184. package/lib/packageVersion.d.ts.map +1 -1
  185. package/lib/packageVersion.js +1 -1
  186. package/lib/packageVersion.js.map +1 -1
  187. package/lib/shared-tree/independentView.d.ts.map +1 -1
  188. package/lib/shared-tree/independentView.js +2 -0
  189. package/lib/shared-tree/independentView.js.map +1 -1
  190. package/lib/shared-tree/sharedTree.d.ts +35 -1
  191. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  192. package/lib/shared-tree/sharedTree.js +6 -0
  193. package/lib/shared-tree/sharedTree.js.map +1 -1
  194. package/lib/shared-tree/sharedTreeChangeCodecs.js +1 -0
  195. package/lib/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
  196. package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
  197. package/lib/shared-tree/treeAlpha.js +2 -0
  198. package/lib/shared-tree/treeAlpha.js.map +1 -1
  199. package/lib/shared-tree/treeCheckout.d.ts +1 -1
  200. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  201. package/lib/shared-tree/treeCheckout.js +2 -0
  202. package/lib/shared-tree/treeCheckout.js.map +1 -1
  203. package/lib/shared-tree-core/editManagerCodecs.d.ts +3 -0
  204. package/lib/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
  205. package/lib/shared-tree-core/editManagerCodecs.js.map +1 -1
  206. package/lib/shared-tree-core/editManagerCodecsCommons.d.ts +14 -0
  207. package/lib/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -1
  208. package/lib/shared-tree-core/editManagerCodecsCommons.js +14 -0
  209. package/lib/shared-tree-core/editManagerCodecsCommons.js.map +1 -1
  210. package/lib/shared-tree-core/editManagerCodecsV1toV4.d.ts +3 -0
  211. package/lib/shared-tree-core/editManagerCodecsV1toV4.d.ts.map +1 -1
  212. package/lib/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -1
  213. package/lib/shared-tree-core/editManagerCodecsVSharedBranches.d.ts +3 -0
  214. package/lib/shared-tree-core/editManagerCodecsVSharedBranches.d.ts.map +1 -1
  215. package/lib/shared-tree-core/editManagerCodecsVSharedBranches.js.map +1 -1
  216. package/lib/shared-tree-core/editManagerSummarizer.d.ts +9 -1
  217. package/lib/shared-tree-core/editManagerSummarizer.d.ts.map +1 -1
  218. package/lib/shared-tree-core/editManagerSummarizer.js +20 -5
  219. package/lib/shared-tree-core/editManagerSummarizer.js.map +1 -1
  220. package/lib/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -1
  221. package/lib/shared-tree-core/messageCodecV1ToV4.js +4 -0
  222. package/lib/shared-tree-core/messageCodecV1ToV4.js.map +1 -1
  223. package/lib/shared-tree-core/messageCodecVSharedBranches.d.ts.map +1 -1
  224. package/lib/shared-tree-core/messageCodecVSharedBranches.js +4 -0
  225. package/lib/shared-tree-core/messageCodecVSharedBranches.js.map +1 -1
  226. package/lib/shared-tree-core/sharedTreeCore.d.ts +4 -0
  227. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  228. package/lib/shared-tree-core/sharedTreeCore.js +1 -1
  229. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  230. package/lib/simple-tree/api/schemaFactory.d.ts +3 -3
  231. package/lib/simple-tree/api/schemaFactory.js +3 -3
  232. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  233. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +17 -1
  234. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
  235. package/lib/simple-tree/api/schemaFactoryAlpha.js +9 -0
  236. package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
  237. package/lib/tableSchema.d.ts.map +1 -1
  238. package/lib/tableSchema.js +103 -21
  239. package/lib/tableSchema.js.map +1 -1
  240. package/package.json +24 -24
  241. package/src/core/change-family/changeFamily.ts +25 -0
  242. package/src/core/tree/detachedFieldIndexCodecV1.ts +2 -0
  243. package/src/core/tree/detachedFieldIndexCodecV2.ts +2 -0
  244. package/src/feature-libraries/chunked-forest/basicChunk.ts +76 -20
  245. package/src/feature-libraries/chunked-forest/codec/chunkDecoding.ts +61 -12
  246. package/src/feature-libraries/chunked-forest/codec/codecs.ts +34 -1
  247. package/src/feature-libraries/chunked-forest/codec/compressedEncode.ts +9 -3
  248. package/src/feature-libraries/chunked-forest/codec/format/formatGeneric.ts +0 -1
  249. package/src/feature-libraries/chunked-forest/codec/format/index.ts +1 -0
  250. package/src/feature-libraries/chunked-forest/codec/format/versions.ts +15 -0
  251. package/src/feature-libraries/chunked-forest/codec/nodeEncoder.ts +9 -1
  252. package/src/feature-libraries/chunked-forest/codec/schemaBasedEncode.ts +9 -1
  253. package/src/feature-libraries/chunked-forest/uniformChunk.ts +32 -2
  254. package/src/feature-libraries/forest-summary/incrementalSummaryBuilder.ts +116 -31
  255. package/src/feature-libraries/modular-schema/genericFieldKindFormat.ts +3 -21
  256. package/src/feature-libraries/modular-schema/modularChangeCodecV1.ts +4 -0
  257. package/src/packageVersion.ts +1 -1
  258. package/src/shared-tree/independentView.ts +2 -0
  259. package/src/shared-tree/sharedTree.ts +41 -1
  260. package/src/shared-tree/sharedTreeChangeCodecs.ts +1 -0
  261. package/src/shared-tree/treeAlpha.ts +2 -0
  262. package/src/shared-tree/treeCheckout.ts +2 -0
  263. package/src/shared-tree-core/editManagerCodecs.ts +3 -0
  264. package/src/shared-tree-core/editManagerCodecsCommons.ts +29 -0
  265. package/src/shared-tree-core/editManagerCodecsV1toV4.ts +3 -0
  266. package/src/shared-tree-core/editManagerCodecsVSharedBranches.ts +3 -0
  267. package/src/shared-tree-core/editManagerSummarizer.ts +17 -5
  268. package/src/shared-tree-core/messageCodecV1ToV4.ts +4 -0
  269. package/src/shared-tree-core/messageCodecVSharedBranches.ts +5 -1
  270. package/src/shared-tree-core/sharedTreeCore.ts +8 -1
  271. package/src/simple-tree/api/schemaFactory.ts +3 -3
  272. package/src/simple-tree/api/schemaFactoryAlpha.ts +34 -3
  273. package/src/tableSchema.ts +134 -35
@@ -0,0 +1,147 @@
1
+ # Isolated declarations
2
+
3
+ This document covers TypeScript's `isolatedDeclarations` option, its use in optimizing large TypeScript builds, and the complications that arise in such setups when using SharedTree schema.
4
+
5
+ The approaches described in this document can be applied to other TypeScript types that are problematic for use with `isolatedDeclarations`: only some minor details are actually specific to SharedTree schema.
6
+
7
+ ## TypeScript background
8
+
9
+ Official documentation for [TypeScript's isolatedDeclarations](https://www.typescriptlang.org/tsconfig/#isolatedDeclarations).
10
+
11
+ Added in TypeScript 5.5: [TypeScript: Documentation - TypeScript 5.5](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations).
12
+
13
+ Important for this document is that `isolatedDeclarations` requires that the types of all exported values be determinable without reading any imported files or parsing expressions.
14
+ Specifically, type inference cannot depend on the types of expressions or contents of other files (beyond referring to types imported from them).
15
+ This means that:
16
+
17
+ - It's possible to emit a `.d.ts` file as a pure function of the input file, without reading any other imported files.
18
+ - The logic needed to do this `.d.ts` emission is relatively simple and practical to implement in third-party tools.
19
+
20
+ This means it's possible for a build system to compile all required `.d.ts` files in parallel, without any need to respect dependency order between projects.
21
+ Once that is done, all the projects can be type checked in parallel.
22
+
23
+ This prevents the dependency graph from delaying parts of the build, and can greatly speed up builds with long project dependency chains.
24
+
25
+ One way to do the first pass (which generates `.d.ts` files) is with the TypeScript compiler, using the following options (requiring at least TypeScript 5.6 for these specific options):
26
+
27
+ ```jsonc
28
+ {
29
+ "compilerOptions": {
30
+ // Enable `.d.ts` generation.
31
+ "declaration": true,
32
+ // Skip JavaScript emissions: it can be done later.
33
+ "emitDeclarationOnly": true,
34
+ // Skip type checking: this is done in the second pass instead.
35
+ "noCheck": true,
36
+
37
+ // Optional: Limit TypeScript to handling simple cases which other tools could also handle.
38
+ // If compatible with this option,
39
+ // typically a faster tool than the TypeScript compiler (like oxc) would be used.
40
+ // If using such a tool, only the second pass would use the TypeScript compiler,
41
+ // and it would use this option instead.
42
+ "isolatedDeclarations": true,
43
+
44
+ // Optional: Omit `@internal` APIs from `.d.ts` files.
45
+ "stripInternal": true,
46
+ // ... Your project will require additional project specific options
47
+ }
48
+ }
49
+ ```
50
+
51
+ The second pass can then run full type checking (with `noEmit` if using a separate operation to emit the JavaScript files).
52
+
53
+ Such builds can further be sped up by using a faster third-party tool for the first pass like [oxc's isolatedDeclaration API](https://oxc.rs/docs/guide/usage/transformer/isolated-declarations.html).
54
+
55
+ ## SharedTree schema background
56
+
57
+ For SharedTree, we require both runtime and compile-time types for schema, and want an easy way to derive the runtime and compile-time types for the TreeNodes from those.
58
+
59
+ TypeScript provides a few ways to declare both at once without having to repeat it in the code (once as an expression, and once as a type).
60
+
61
+ - Using the type of an expression, and its value.
62
+ - Using a specific language feature that does both at once, like `class` or `enum`
63
+
64
+ SharedTree schema use both of these tools together, using `class`. In this example, consider a class named `Foo`:
65
+
66
+ - The class `Foo` is the schema:
67
+ - The expression `Foo` is the schema.
68
+ When the user needs to refer to a node type at runtime, they use the schema to do so.
69
+ - The type of the schema is `typeof Foo`: this is usually inferred when passing the schema into something, but occasionally explicitly stated.
70
+ - The type `Foo` is the node:
71
+ - The type named `Foo` is the node type, avoiding the need to add an extra declaration.
72
+ - This type comes from the non-static members of the class/schema `Foo`, and can be extended with additional class members to express type and runtime data together.
73
+
74
+ To support recursive schema, schema are occasionally referenced as `() => Foo` to allow forward references.
75
+
76
+ To avoid limitations in TypeScript `.d.ts` emission for recursive schema — and to get better IntelliSense and error messages — schema must use explicitly named types (like a class or interface) rather than simple `type` declarations.
77
+
78
+ The portion of the class that directly works with the underlying tree content is generated via `SchemaFactory` so we can control the API for building it and intercept all access to data as needed.
79
+ This also allows common functionality to be shared across all schema classes (such as static implementations of the various schema interfaces for schema reflection, and centralized control of schema scopes and other settings).
80
+
81
+ ## `isolatedDeclarations` and tree schema
82
+
83
+ `isolatedDeclarations` bans exporting values whose types depend on the types of expressions.
84
+
85
+ This includes base classes when the base class expression is not simply a single identifier referring to a value with an explicit type.
86
+
87
+ Thus when both runtime and compile-time data are needed about something, the trick of using an expression and its type is no longer valid.
88
+
89
+ ### Recommended approach:
90
+
91
+ This assumes the tooling in question is already:
92
+
93
+ - building a monorepo or large collection of TypeScript projects (often one package per project, but this is not a requirement).
94
+ - using `isolatedDeclarations`.
95
+ - having a separate "emit" phase (for emitting `.d.ts` files) and "type check" phase of the TypeScript build.
96
+ - running all projects' "emit" phase in parallel.
97
+ - wanting to use SharedTree schema in a way that makes it hard to keep this setup.
98
+
99
+ To add SharedTree schema to such a setup:
100
+
101
+ - Factor your code to minimize the need to export schema from both files and projects.
102
+ - For schema that are file-exported but not project-exported, mark them as `@internal` and use `stripInternal`.
103
+ - If inconsistent tagging becomes a problem (package-exported types accidentally referencing tagged types causing type errors that are hard to diagnose), use API Extractor as a linter to validate tagging is done consistently.
104
+ - For projects that still export schema, pick one of:
105
+ 1. Simplify the exported types as much as is practical, including using tools like `eraseSchemaDetails`, and specify the simplified types explicitly.
106
+ (Recommended if this is easy to do)
107
+ 2. Remove `isolatedDeclarations`, and do the `.d.ts` emission using the TypeScript compiler, keeping the separate emit and type-check passes.
108
+ This might require delaying this emission until some or all of the dependencies of the project have had their types emitted.
109
+ This does not require any new dependencies for the full type-checking phase (that can still be fully parallel), nor delaying `.d.ts` emission for projects that reference this one (assuming they still use `isolatedDeclarations`).
110
+ If picking this option, you likely also want to refactor the code to minimize the size and dependencies of the impacted package.
111
+ (Recommended when option 1 isn't straightforward, and the project in question isn't exceptionally slow to emit `.d.ts` files using TypeScript using the options listed at the top of this document)
112
+ 3. Explicitly pre-generate the `.d.ts` files.
113
+ As a last resort (other than disabling the optimized build setup), the `.d.ts` files can be generated the same as the above option. However, instead of generating them during the emit phase, generate them with a separate command and commit them to the repo. During the type check phase of the build, error if they are out of date.
114
+ (Recommended when the above options (1 and 2) are not suitable)
115
+
116
+ ### Mitigations:
117
+
118
+ An exhaustive list of things that can be done to mitigate issues related to use of SharedTree schema with `isolatedDeclarations`.
119
+ The recommendations above use a subset of these approaches.
120
+
121
+ 1. Reduce the pain of having to restate types from expressions:
122
+ - Add types that mirror the runtime APIs, making it practical (and supported — no `@system` types or unnamable types) to express any type explicitly without relying on inferred expression types. SharedTree tries to provide such types, but more may be helpful.
123
+ - Export fewer types:
124
+ - Put the code that uses a schema in the same file as the schema (often inside its class as an implementation of an interface for that class)
125
+ - Type-erase the complex types (which include the actual shared tree fields and similar) before exporting them. See `eraseSchemaDetails()`
126
+ - If applying mitigation 2 (below), the relevant scopes for minimizing exports change accordingly.
127
+ 2. Reduce where the rules of `isolatedDeclarations` apply:
128
+ - Split up packages or add more tsconfig files within them to allow finer-grained scoping of this option.
129
+ - If the goal of using `isolatedDeclarations` is to reduce the critical path for type checking packages, then realistically this restriction only needs to apply to types transitively reachable from package exports, not all module exports. Some ways to achieve this:
130
+ - Use `stripInternal`, then mark offending non-package-exported APIs with `@internal`. Optionally use [API Extractor](https://api-extractor.com/) to ensure types reachable from the non-`@internal` types are not tagged `@internal`.
131
+ - Get TypeScript to add such an option. It would be nice if TypeScript had a way to restrict the `.d.ts` emission it does to only things reachable from an entry point (or set of entry points) or (as an alternative feature) limit it to types directly in some entry point (and error for referenced types not included in that entry point). If TypeScript had such a feature, it would help with lots of things and would pair well with an option for only applying `isolatedDeclarations` restrictions to types that are included in the entry points. We would also need to confirm the third-party tool being used to generate the `.d.ts` file also could work in these cases.
132
+ - Use a tool other than TypeScript to enforce `isolatedDeclarations` in a way that reflects your actual needs. For example, whatever tool is actually generating package `.d.ts` files, ensure it does not object to code that violates this rule if it's not package-exported (similar to above), then use that tool itself to enforce the code will work for it rather than also having TypeScript enforce it. Might pair well with a lint rule to flag incompatible exported types (which could be suppressed for non-package-exported ones).
133
+
134
+ ### Solutions:
135
+
136
+ An exhaustive list of things that can be done to fix issues related to use of SharedTree schema with `isolatedDeclarations`.
137
+ The recommendations above use a subset of these approaches.
138
+
139
+ - Don't use `isolatedDeclarations` for the tsconfigs that contain files that export schema.
140
+ - This could be parts of packages, or whole packages. Applying this to portions of packages that contain no package-exported types might handle some use cases well.
141
+ - You can still do a two-pass build, with the first pass just emitting `.d.ts` files. For projects exporting SharedTree schema, do this using TypeScript instead of a third-party tool, and ensure that the dependencies of these projects have their types emitted first (in dependency order). The second type-checking pass can still be fully parallel.
142
+ - Handwrite all those types, duplicating the data expressed in the expressions (ideally paired with the above mitigations to make this less painful).
143
+ - Use a code generator to produce the needed types. The TypeScript compiler with `emitDeclarationOnly` is such a tool.
144
+ - This can replace the non-TypeScript tool previously used to emit `.d.ts` files for these cases.
145
+ - This could generate code that is used by whatever tool would process the TypeScript to emit the `.d.ts`, instead of the developer-written source files.
146
+ - The files emitted could either be generated as needed (possibly slowing down the processing of dependencies), committed as part of the code (similar to if they were handwritten), or published alongside the code through some other mechanism (like via a package that contains them already generated, as is normal for TypeScript packages).
147
+ - Replace SharedTree's schema language with one that avoids this problem by expressing everything as class members directly without any typed expressions or expression-based inheritance (this would likely be a mess, with many limitations and poor error reporting, but is technically possible).
@@ -17,6 +17,29 @@ export interface ChangeEncodingContext {
17
17
  readonly revision: RevisionTag | undefined;
18
18
  readonly idCompressor: IIdCompressor;
19
19
  readonly schema?: SchemaAndPolicy;
20
+ /**
21
+ * `true` when this context is encoding to or decoding from a summary blob.
22
+ * `false` when this context is for an op (or any other non-summary path,
23
+ * including utility encoders that aren't tied to persistence).
24
+ *
25
+ * @remarks
26
+ * Used to gate decode-time recovery behavior — for example, healing of
27
+ * unresolvable identifier IDs — that should only run when loading a
28
+ * (possibly broken) attach-summary blob, never when applying ops.
29
+ */
30
+ readonly isSummary: boolean;
31
+ /**
32
+ * If `true`, identifier values that the local id-compressor cannot resolve
33
+ * during decode are healed into deterministic stable UUIDs instead of
34
+ * throwing. See {@link FieldBatchEncodingContext.healUnresolvableIdentifiersOnDecode}.
35
+ * Only takes effect when `isSummary` is also `true`.
36
+ */
37
+ readonly healUnresolvableIdentifiersOnDecode?: boolean;
38
+ /**
39
+ * The SharedTree's shared-object id, used as input to the deterministic
40
+ * UUID derivation when {@link healUnresolvableIdentifiersOnDecode} triggers.
41
+ */
42
+ readonly sharedObjectId?: string;
20
43
  }
21
44
  export type ChangeFamilyCodec<TChange> = IJsonCodec<TChange, JsonCompatibleReadOnly, JsonCompatibleReadOnly, ChangeEncodingContext>;
22
45
  export interface ChangeFamilyEditor {
@@ -1 +1 @@
1
- {"version":3,"file":"changeFamily.d.ts","sourceRoot":"","sources":["../../../src/core/change-family/changeFamily.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MA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B,IAAI,IAAI,CAAC;IAEzB;;;;;;;OAOG;IACH,eAAe,IAAI,IAAI,CAAC;CACxB"}
@@ -1 +1 @@
1
- {"version":3,"file":"changeFamily.js","sourceRoot":"","sources":["../../../src/core/change-family/changeFamily.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IIdCompressor, SessionId } from \"@fluidframework/id-compressor\";\n\nimport type { ICodecFamily, IJsonCodec } from \"../../codec/index.js\";\nimport type { SchemaAndPolicy } from \"../../core/index.js\";\nimport type { JsonCompatibleReadOnly } from \"../../util/index.js\";\nimport type { ChangeRebaser, RevisionTag, TaggedChange } from \"../rebase/index.js\";\n\nexport interface ChangeFamily<TEditor extends ChangeFamilyEditor, TChange> {\n\tbuildEditor(\n\t\tmintRevisionTag: () => RevisionTag,\n\t\tchangeReceiver: (change: TaggedChange<TChange>) => void,\n\t): TEditor;\n\n\treadonly rebaser: ChangeRebaser<TChange>;\n\treadonly codecs: ICodecFamily<TChange, ChangeEncodingContext>;\n}\n\nexport interface ChangeEncodingContext {\n\treadonly originatorId: SessionId;\n\treadonly revision: RevisionTag | undefined;\n\treadonly idCompressor: IIdCompressor;\n\treadonly schema?: SchemaAndPolicy;\n}\n\nexport type ChangeFamilyCodec<TChange> = IJsonCodec<\n\tTChange,\n\tJsonCompatibleReadOnly,\n\tJsonCompatibleReadOnly,\n\tChangeEncodingContext\n>;\n\nexport interface ChangeFamilyEditor {\n\t/**\n\t * Must be called when a new transaction starts.\n\t *\n\t * Note: transactions are an optional feature. It is valid to make edits outside of a transaction.\n\t *\n\t * For each call to this function, a matching call to `exitTransaction` must be made at a later time.\n\t * Can be called repeatedly to indicate the start of nesting transactions.\n\t */\n\tenterTransaction(): void;\n\n\t/**\n\t * Must be called when a transaction ends.\n\t *\n\t * Note: transactions are an optional feature. It is valid to make edits outside of a transaction.\n\t *\n\t * For each call to this function, a matching call to `enterTransaction` must be made at an earlier time.\n\t * Can be called repeatedly to indicate the end of nesting transactions.\n\t */\n\texitTransaction(): void;\n}\n"]}
1
+ {"version":3,"file":"changeFamily.js","sourceRoot":"","sources":["../../../src/core/change-family/changeFamily.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IIdCompressor, SessionId } from \"@fluidframework/id-compressor\";\n\nimport type { ICodecFamily, IJsonCodec } from \"../../codec/index.js\";\nimport type { SchemaAndPolicy } from \"../../core/index.js\";\n// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Referenced by doc comments\nimport type { FieldBatchEncodingContext } from \"../../feature-libraries/index.js\";\nimport type { JsonCompatibleReadOnly } from \"../../util/index.js\";\nimport type { ChangeRebaser, RevisionTag, TaggedChange } from \"../rebase/index.js\";\n\nexport interface ChangeFamily<TEditor extends ChangeFamilyEditor, TChange> {\n\tbuildEditor(\n\t\tmintRevisionTag: () => RevisionTag,\n\t\tchangeReceiver: (change: TaggedChange<TChange>) => void,\n\t): TEditor;\n\n\treadonly rebaser: ChangeRebaser<TChange>;\n\treadonly codecs: ICodecFamily<TChange, ChangeEncodingContext>;\n}\n\nexport interface ChangeEncodingContext {\n\treadonly originatorId: SessionId;\n\treadonly revision: RevisionTag | undefined;\n\treadonly idCompressor: IIdCompressor;\n\treadonly schema?: SchemaAndPolicy;\n\t/**\n\t * `true` when this context is encoding to or decoding from a summary blob.\n\t * `false` when this context is for an op (or any other non-summary path,\n\t * including utility encoders that aren't tied to persistence).\n\t *\n\t * @remarks\n\t * Used to gate decode-time recovery behavior — for example, healing of\n\t * unresolvable identifier IDs — that should only run when loading a\n\t * (possibly broken) attach-summary blob, never when applying ops.\n\t */\n\treadonly isSummary: boolean;\n\t/**\n\t * If `true`, identifier values that the local id-compressor cannot resolve\n\t * during decode are healed into deterministic stable UUIDs instead of\n\t * throwing. See {@link FieldBatchEncodingContext.healUnresolvableIdentifiersOnDecode}.\n\t * Only takes effect when `isSummary` is also `true`.\n\t */\n\treadonly healUnresolvableIdentifiersOnDecode?: boolean;\n\t/**\n\t * The SharedTree's shared-object id, used as input to the deterministic\n\t * UUID derivation when {@link healUnresolvableIdentifiersOnDecode} triggers.\n\t */\n\treadonly sharedObjectId?: string;\n}\n\nexport type ChangeFamilyCodec<TChange> = IJsonCodec<\n\tTChange,\n\tJsonCompatibleReadOnly,\n\tJsonCompatibleReadOnly,\n\tChangeEncodingContext\n>;\n\nexport interface ChangeFamilyEditor {\n\t/**\n\t * Must be called when a new transaction starts.\n\t *\n\t * Note: transactions are an optional feature. It is valid to make edits outside of a transaction.\n\t *\n\t * For each call to this function, a matching call to `exitTransaction` must be made at a later time.\n\t * Can be called repeatedly to indicate the start of nesting transactions.\n\t */\n\tenterTransaction(): void;\n\n\t/**\n\t * Must be called when a transaction ends.\n\t *\n\t * Note: transactions are an optional feature. It is valid to make edits outside of a transaction.\n\t *\n\t * For each call to this function, a matching call to `enterTransaction` must be made at an earlier time.\n\t * Can be called repeatedly to indicate the end of nesting transactions.\n\t */\n\texitTransaction(): void;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"detachedFieldIndexCodecV1.d.ts","sourceRoot":"","sources":["../../../src/core/tree/detachedFieldIndexCodecV1.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,sBAAsB,CAAC;AAEvE,OAAO,EAEN,KAAK,gBAAgB,EAGrB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,KAAK,EAAE,wBAAwB,EAAS,MAAM,8BAA8B,CAAC;AAgDpF,wBAAgB,8BAA8B,CAC7C,gBAAgB,EAAE,gBAAgB,EAClC,YAAY,EAAE,aAAa,GACzB,cAAc,CAAC,wBAAwB,CAAC,CAO1C"}
1
+ {"version":3,"file":"detachedFieldIndexCodecV1.d.ts","sourceRoot":"","sources":["../../../src/core/tree/detachedFieldIndexCodecV1.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,sBAAsB,CAAC;AAEvE,OAAO,EAEN,KAAK,gBAAgB,EAGrB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,KAAK,EAAE,wBAAwB,EAAS,MAAM,8BAA8B,CAAC;AAkDpF,wBAAgB,8BAA8B,CAC7C,gBAAgB,EAAE,gBAAgB,EAClC,YAAY,EAAE,aAAa,GACzB,cAAc,CAAC,wBAAwB,CAAC,CAO1C"}
@@ -41,6 +41,8 @@ class MajorCodec {
41
41
  originatorId: this.revisionTagCodec.localSessionId,
42
42
  idCompressor: this.idCompressor,
43
43
  revision: undefined,
44
+ // DetachedFieldIndex codecs are only used by the summarizer.
45
+ isSummary: true,
44
46
  });
45
47
  }
46
48
  }
@@ -1 +1 @@
1
- {"version":3,"file":"detachedFieldIndexCodecV1.js","sourceRoot":"","sources":["../../../src/core/tree/detachedFieldIndexCodecV1.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAI7D,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAIN,iBAAiB,GACjB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,yCAAyC,EAAE,MAAM,oCAAoC,CAAC;AAC/F,OAAO,EAAE,+BAA+B,EAAE,MAAM,qCAAqC,CAAC;AAGtF,MAAM,UAAU;IACf,YACkB,gBAAkC,EAClC,YAA2B;QAD3B,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,iBAAY,GAAZ,YAAY,CAAe;IAC1C,CAAC;IAEG,MAAM,CAAC,KAAY;QACzB,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACvE,MAAM,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/C;;;;;;;;;;;;;;;;WAgBG;QACH,MAAM,CACL,EAAE,KAAK,MAAM,IAAI,EAAE,IAAI,CAAC,EACxB,KAAK,CAAC,kEAAkE,CACxE,CAAC;QACF,OAAO,EAAE,CAAC;IACX,CAAC;IAEM,MAAM,CAAC,KAAyB;QACtC,MAAM,CACL,KAAK,KAAK,MAAM,IAAI,KAAK,IAAI,CAAC,EAC9B,KAAK,CAAC,kEAAkE,CACxE,CAAC;QACF,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE;YAC1C,YAAY,EAAE,IAAI,CAAC,gBAAgB,CAAC,cAAc;YAClD,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,QAAQ,EAAE,SAAS;SACnB,CAAC,CAAC;IACJ,CAAC;CACD;AAED,MAAM,UAAU,8BAA8B,CAC7C,gBAAkC,EAClC,YAA2B;IAE3B,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC;IAClE,OAAO,yCAAyC,CAC/C,UAAU,EACV,KAAK,CAAC,+BAA+B,CAAC,EAAE,CAAC,EACzC,iBAAiB,CACjB,CAAC;AACH,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\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\n\nimport type { CodecAndSchema, IJsonCodec } from \"../../codec/index.js\";\nimport { brand } from \"../../util/index.js\";\nimport {\n\ttype EncodedRevisionTag,\n\ttype RevisionTagCodec,\n\ttype RevisionTag,\n\tRevisionTagSchema,\n} from \"../rebase/index.js\";\n\nimport { makeDetachedFieldIndexCodecFromMajorCodec } from \"./detachedFieldIndexCodecCommon.js\";\nimport { DetachedFieldIndexFormatVersion } from \"./detachedFieldIndexFormatCommon.js\";\nimport type { DetachedFieldSummaryData, Major } from \"./detachedFieldIndexTypes.js\";\n\nclass MajorCodec implements IJsonCodec<Major, EncodedRevisionTag> {\n\tpublic constructor(\n\t\tprivate readonly revisionTagCodec: RevisionTagCodec,\n\t\tprivate readonly idCompressor: IIdCompressor,\n\t) {}\n\n\tpublic encode(major: Major): EncodedRevisionTag {\n\t\tassert(major !== undefined, 0x88e /* Unexpected undefined revision */);\n\t\tconst id = this.revisionTagCodec.encode(major);\n\t\t/**\n\t\t * Preface: this codec is only used at summarization time (not for ops).\n\t\t * Note that the decode path must provide a session id in which to interpret the revision tag.\n\t\t * The revision associated with a detached root generally comes from the session which detaches that subtree,\n\t\t * which isn't generally the local session (nor is it available at decode time with the layering of the tree\n\t\t * package), despite decode using the local session id.\n\t\t *\n\t\t * This is made OK by enforcing that all ids on encode/decode are non-local, since local ids won't be interpretable\n\t\t * at decode time.\n\t\t * This assert is valid because the revision for an acked edit will have already been finalized, and a revision\n\t\t * for a local-only edit will be finalizable at summarization time (local edits can only occur on a summarizing client\n\t\t * if they're created while detached, and local ids made while detached are finalized before generating the attach summary).\n\t\t *\n\t\t * WARNING: the above is true when the whole container transitions from detached to attached,\n\t\t * but not when the container is already attached and it's just the shared-tree that is attaching.\n\t\t * The assert below will fail in such a scenario. This is addressed in the v2 codec.\n\t\t */\n\t\tassert(\n\t\t\tid === \"root\" || id >= 0,\n\t\t\t0x88f /* Expected final id on encode of detached field index revision */,\n\t\t);\n\t\treturn id;\n\t}\n\n\tpublic decode(major: EncodedRevisionTag): RevisionTag {\n\t\tassert(\n\t\t\tmajor === \"root\" || major >= 0,\n\t\t\t0x890 /* Expected final id on decode of detached field index revision */,\n\t\t);\n\t\treturn this.revisionTagCodec.decode(major, {\n\t\t\toriginatorId: this.revisionTagCodec.localSessionId,\n\t\t\tidCompressor: this.idCompressor,\n\t\t\trevision: undefined,\n\t\t});\n\t}\n}\n\nexport function makeDetachedNodeToFieldCodecV1(\n\trevisionTagCodec: RevisionTagCodec,\n\tidCompressor: IIdCompressor,\n): CodecAndSchema<DetachedFieldSummaryData> {\n\tconst majorCodec = new MajorCodec(revisionTagCodec, idCompressor);\n\treturn makeDetachedFieldIndexCodecFromMajorCodec(\n\t\tmajorCodec,\n\t\tbrand(DetachedFieldIndexFormatVersion.v1),\n\t\tRevisionTagSchema,\n\t);\n}\n"]}
1
+ {"version":3,"file":"detachedFieldIndexCodecV1.js","sourceRoot":"","sources":["../../../src/core/tree/detachedFieldIndexCodecV1.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAI7D,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAIN,iBAAiB,GACjB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,yCAAyC,EAAE,MAAM,oCAAoC,CAAC;AAC/F,OAAO,EAAE,+BAA+B,EAAE,MAAM,qCAAqC,CAAC;AAGtF,MAAM,UAAU;IACf,YACkB,gBAAkC,EAClC,YAA2B;QAD3B,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,iBAAY,GAAZ,YAAY,CAAe;IAC1C,CAAC;IAEG,MAAM,CAAC,KAAY;QACzB,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACvE,MAAM,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/C;;;;;;;;;;;;;;;;WAgBG;QACH,MAAM,CACL,EAAE,KAAK,MAAM,IAAI,EAAE,IAAI,CAAC,EACxB,KAAK,CAAC,kEAAkE,CACxE,CAAC;QACF,OAAO,EAAE,CAAC;IACX,CAAC;IAEM,MAAM,CAAC,KAAyB;QACtC,MAAM,CACL,KAAK,KAAK,MAAM,IAAI,KAAK,IAAI,CAAC,EAC9B,KAAK,CAAC,kEAAkE,CACxE,CAAC;QACF,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE;YAC1C,YAAY,EAAE,IAAI,CAAC,gBAAgB,CAAC,cAAc;YAClD,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,QAAQ,EAAE,SAAS;YACnB,6DAA6D;YAC7D,SAAS,EAAE,IAAI;SACf,CAAC,CAAC;IACJ,CAAC;CACD;AAED,MAAM,UAAU,8BAA8B,CAC7C,gBAAkC,EAClC,YAA2B;IAE3B,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC;IAClE,OAAO,yCAAyC,CAC/C,UAAU,EACV,KAAK,CAAC,+BAA+B,CAAC,EAAE,CAAC,EACzC,iBAAiB,CACjB,CAAC;AACH,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\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\n\nimport type { CodecAndSchema, IJsonCodec } from \"../../codec/index.js\";\nimport { brand } from \"../../util/index.js\";\nimport {\n\ttype EncodedRevisionTag,\n\ttype RevisionTagCodec,\n\ttype RevisionTag,\n\tRevisionTagSchema,\n} from \"../rebase/index.js\";\n\nimport { makeDetachedFieldIndexCodecFromMajorCodec } from \"./detachedFieldIndexCodecCommon.js\";\nimport { DetachedFieldIndexFormatVersion } from \"./detachedFieldIndexFormatCommon.js\";\nimport type { DetachedFieldSummaryData, Major } from \"./detachedFieldIndexTypes.js\";\n\nclass MajorCodec implements IJsonCodec<Major, EncodedRevisionTag> {\n\tpublic constructor(\n\t\tprivate readonly revisionTagCodec: RevisionTagCodec,\n\t\tprivate readonly idCompressor: IIdCompressor,\n\t) {}\n\n\tpublic encode(major: Major): EncodedRevisionTag {\n\t\tassert(major !== undefined, 0x88e /* Unexpected undefined revision */);\n\t\tconst id = this.revisionTagCodec.encode(major);\n\t\t/**\n\t\t * Preface: this codec is only used at summarization time (not for ops).\n\t\t * Note that the decode path must provide a session id in which to interpret the revision tag.\n\t\t * The revision associated with a detached root generally comes from the session which detaches that subtree,\n\t\t * which isn't generally the local session (nor is it available at decode time with the layering of the tree\n\t\t * package), despite decode using the local session id.\n\t\t *\n\t\t * This is made OK by enforcing that all ids on encode/decode are non-local, since local ids won't be interpretable\n\t\t * at decode time.\n\t\t * This assert is valid because the revision for an acked edit will have already been finalized, and a revision\n\t\t * for a local-only edit will be finalizable at summarization time (local edits can only occur on a summarizing client\n\t\t * if they're created while detached, and local ids made while detached are finalized before generating the attach summary).\n\t\t *\n\t\t * WARNING: the above is true when the whole container transitions from detached to attached,\n\t\t * but not when the container is already attached and it's just the shared-tree that is attaching.\n\t\t * The assert below will fail in such a scenario. This is addressed in the v2 codec.\n\t\t */\n\t\tassert(\n\t\t\tid === \"root\" || id >= 0,\n\t\t\t0x88f /* Expected final id on encode of detached field index revision */,\n\t\t);\n\t\treturn id;\n\t}\n\n\tpublic decode(major: EncodedRevisionTag): RevisionTag {\n\t\tassert(\n\t\t\tmajor === \"root\" || major >= 0,\n\t\t\t0x890 /* Expected final id on decode of detached field index revision */,\n\t\t);\n\t\treturn this.revisionTagCodec.decode(major, {\n\t\t\toriginatorId: this.revisionTagCodec.localSessionId,\n\t\t\tidCompressor: this.idCompressor,\n\t\t\trevision: undefined,\n\t\t\t// DetachedFieldIndex codecs are only used by the summarizer.\n\t\t\tisSummary: true,\n\t\t});\n\t}\n}\n\nexport function makeDetachedNodeToFieldCodecV1(\n\trevisionTagCodec: RevisionTagCodec,\n\tidCompressor: IIdCompressor,\n): CodecAndSchema<DetachedFieldSummaryData> {\n\tconst majorCodec = new MajorCodec(revisionTagCodec, idCompressor);\n\treturn makeDetachedFieldIndexCodecFromMajorCodec(\n\t\tmajorCodec,\n\t\tbrand(DetachedFieldIndexFormatVersion.v1),\n\t\tRevisionTagSchema,\n\t);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"detachedFieldIndexCodecV2.d.ts","sourceRoot":"","sources":["../../../src/core/tree/detachedFieldIndexCodecV2.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,+BAA+B,CAAC;AAG7E,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,sBAAsB,CAAC;AACvE,OAAO,KAAK,EAAsB,gBAAgB,EAAe,MAAM,oBAAoB,CAAC;AAK5F,OAAO,KAAK,EAAE,wBAAwB,EAAS,MAAM,8BAA8B,CAAC;AAwCpF,wBAAgB,8BAA8B,CAC7C,gBAAgB,EAAE,gBAAgB,EAClC,YAAY,EAAE,aAAa,GACzB,cAAc,CAAC,wBAAwB,CAAC,CAO1C"}
1
+ {"version":3,"file":"detachedFieldIndexCodecV2.d.ts","sourceRoot":"","sources":["../../../src/core/tree/detachedFieldIndexCodecV2.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,+BAA+B,CAAC;AAG7E,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,sBAAsB,CAAC;AACvE,OAAO,KAAK,EAAsB,gBAAgB,EAAe,MAAM,oBAAoB,CAAC;AAK5F,OAAO,KAAK,EAAE,wBAAwB,EAAS,MAAM,8BAA8B,CAAC;AA0CpF,wBAAgB,8BAA8B,CAC7C,gBAAgB,EAAE,gBAAgB,EAClC,YAAY,EAAE,aAAa,GACzB,cAAc,CAAC,wBAAwB,CAAC,CAO1C"}
@@ -35,6 +35,8 @@ class MajorCodec {
35
35
  originatorId: this.revisionTagCodec.localSessionId,
36
36
  idCompressor: this.idCompressor,
37
37
  revision: undefined,
38
+ // DetachedFieldIndex codecs are only used by the summarizer.
39
+ isSummary: true,
38
40
  });
39
41
  }
40
42
  }
@@ -1 +1 @@
1
- {"version":3,"file":"detachedFieldIndexCodecV2.js","sourceRoot":"","sources":["../../../src/core/tree/detachedFieldIndexCodecV2.ts"],"names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AK,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE;YAC1C,YAAY,EAAE,IAAI,CAAC,gBAAgB,CAAC,cAAc;YAClD,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,QAAQ,EAAE,SAAS;SACnB,CAAC,CAAC;IACJ,CAAC;CACD;AAED,MAAM,UAAU,8BAA8B,CAC7C,gBAAkC,EAClC,YAA2B;IAE3B,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC;IAClE,OAAO,yCAAyC,CAC/C,UAAU,EACV,+BAA+B,CAAC,EAAE,EAClC,wBAAwB,CACxB,CAAC;AACH,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\";\nimport type { IIdCompressor, StableId } from \"@fluidframework/id-compressor\";\nimport { isStableId } from \"@fluidframework/id-compressor/internal\";\n\nimport type { CodecAndSchema, IJsonCodec } from \"../../codec/index.js\";\nimport type { EncodedRevisionTag, RevisionTagCodec, RevisionTag } from \"../rebase/index.js\";\n\nimport { makeDetachedFieldIndexCodecFromMajorCodec } from \"./detachedFieldIndexCodecCommon.js\";\nimport { DetachedFieldIndexFormatVersion } from \"./detachedFieldIndexFormatCommon.js\";\nimport { StableOrFinalRevisionTag } from \"./detachedFieldIndexFormatV2.js\";\nimport type { DetachedFieldSummaryData, Major } from \"./detachedFieldIndexTypes.js\";\n\nclass MajorCodec implements IJsonCodec<Major> {\n\tpublic constructor(\n\t\tprivate readonly revisionTagCodec: RevisionTagCodec,\n\t\tprivate readonly idCompressor: IIdCompressor,\n\t) {}\n\n\tpublic encode(major: Major): EncodedRevisionTag | StableId {\n\t\tassert(major !== undefined, 0xbfb /* Unexpected undefined revision */);\n\t\tconst id = this.revisionTagCodec.encode(major);\n\n\t\tif (id !== \"root\" && id < 0) {\n\t\t\t/**\n\t\t\t * This code path handles the case where the major revision is not finalized.\n\t\t\t * This can happen the SharedTree is being attached to an already attached container.\n\t\t\t */\n\t\t\tassert(major !== \"root\", 0xbfc /* Major revision cannot be 'root' */);\n\t\t\tconst long = this.idCompressor.decompress(major);\n\t\t\treturn long;\n\t\t}\n\t\treturn id;\n\t}\n\n\tpublic decode(major: EncodedRevisionTag | StableId): RevisionTag {\n\t\tassert(\n\t\t\tmajor === \"root\" || (typeof major === \"string\" && isStableId(major)) || major >= 0,\n\t\t\t0xbfd /* Expected root, stable, or final compressed id */,\n\t\t);\n\t\tif (typeof major === \"string\" && isStableId(major)) {\n\t\t\treturn this.idCompressor.recompress(major);\n\t\t}\n\t\treturn this.revisionTagCodec.decode(major, {\n\t\t\toriginatorId: this.revisionTagCodec.localSessionId,\n\t\t\tidCompressor: this.idCompressor,\n\t\t\trevision: undefined,\n\t\t});\n\t}\n}\n\nexport function makeDetachedNodeToFieldCodecV2(\n\trevisionTagCodec: RevisionTagCodec,\n\tidCompressor: IIdCompressor,\n): CodecAndSchema<DetachedFieldSummaryData> {\n\tconst majorCodec = new MajorCodec(revisionTagCodec, idCompressor);\n\treturn makeDetachedFieldIndexCodecFromMajorCodec(\n\t\tmajorCodec,\n\t\tDetachedFieldIndexFormatVersion.v2,\n\t\tStableOrFinalRevisionTag,\n\t);\n}\n"]}
1
+ {"version":3,"file":"detachedFieldIndexCodecV2.js","sourceRoot":"","sources":["../../../src/core/tree/detachedFieldIndexCodecV2.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AAKpE,OAAO,EAAE,yCAAyC,EAAE,MAAM,oCAAoC,CAAC;AAC/F,OAAO,EAAE,+BAA+B,EAAE,MAAM,qCAAqC,CAAC;AACtF,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAG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U,8BAA8B,CAC7C,gBAAkC,EAClC,YAA2B;IAE3B,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC;IAClE,OAAO,yCAAyC,CAC/C,UAAU,EACV,+BAA+B,CAAC,EAAE,EAClC,wBAAwB,CACxB,CAAC;AACH,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\";\nimport type { IIdCompressor, StableId } from \"@fluidframework/id-compressor\";\nimport { isStableId } from \"@fluidframework/id-compressor/internal\";\n\nimport type { CodecAndSchema, IJsonCodec } from \"../../codec/index.js\";\nimport type { EncodedRevisionTag, RevisionTagCodec, RevisionTag } from \"../rebase/index.js\";\n\nimport { makeDetachedFieldIndexCodecFromMajorCodec } from \"./detachedFieldIndexCodecCommon.js\";\nimport { DetachedFieldIndexFormatVersion } from \"./detachedFieldIndexFormatCommon.js\";\nimport { StableOrFinalRevisionTag } from \"./detachedFieldIndexFormatV2.js\";\nimport type { DetachedFieldSummaryData, Major } from \"./detachedFieldIndexTypes.js\";\n\nclass MajorCodec implements IJsonCodec<Major> {\n\tpublic constructor(\n\t\tprivate readonly revisionTagCodec: RevisionTagCodec,\n\t\tprivate readonly idCompressor: IIdCompressor,\n\t) {}\n\n\tpublic encode(major: Major): EncodedRevisionTag | StableId {\n\t\tassert(major !== undefined, 0xbfb /* Unexpected undefined revision */);\n\t\tconst id = this.revisionTagCodec.encode(major);\n\n\t\tif (id !== \"root\" && id < 0) {\n\t\t\t/**\n\t\t\t * This code path handles the case where the major revision is not finalized.\n\t\t\t * This can happen the SharedTree is being attached to an already attached container.\n\t\t\t */\n\t\t\tassert(major !== \"root\", 0xbfc /* Major revision cannot be 'root' */);\n\t\t\tconst long = this.idCompressor.decompress(major);\n\t\t\treturn long;\n\t\t}\n\t\treturn id;\n\t}\n\n\tpublic decode(major: EncodedRevisionTag | StableId): RevisionTag {\n\t\tassert(\n\t\t\tmajor === \"root\" || (typeof major === \"string\" && isStableId(major)) || major >= 0,\n\t\t\t0xbfd /* Expected root, stable, or final compressed id */,\n\t\t);\n\t\tif (typeof major === \"string\" && isStableId(major)) {\n\t\t\treturn this.idCompressor.recompress(major);\n\t\t}\n\t\treturn this.revisionTagCodec.decode(major, {\n\t\t\toriginatorId: this.revisionTagCodec.localSessionId,\n\t\t\tidCompressor: this.idCompressor,\n\t\t\trevision: undefined,\n\t\t\t// DetachedFieldIndex codecs are only used by the summarizer.\n\t\t\tisSummary: true,\n\t\t});\n\t}\n}\n\nexport function makeDetachedNodeToFieldCodecV2(\n\trevisionTagCodec: RevisionTagCodec,\n\tidCompressor: IIdCompressor,\n): CodecAndSchema<DetachedFieldSummaryData> {\n\tconst majorCodec = new MajorCodec(revisionTagCodec, idCompressor);\n\treturn makeDetachedFieldIndexCodecFromMajorCodec(\n\t\tmajorCodec,\n\t\tDetachedFieldIndexFormatVersion.v2,\n\t\tStableOrFinalRevisionTag,\n\t);\n}\n"]}
@@ -96,10 +96,27 @@ export declare class BasicChunkCursor extends SynchronousCursor implements Chunk
96
96
  atChunkRoot(): boolean;
97
97
  fork(): BasicChunkCursor;
98
98
  get mode(): CursorLocationType;
99
+ /**
100
+ * Asserts that the node-only stacks (`indexOfChunkStack` and `indexWithinChunkStack`) are in sync with `siblingStack`.
101
+ * Since `siblingStack` interleaves field and node levels while the node-only stacks are pushed/popped only on node-level transitions,
102
+ * their length should always equal the number of node levels traversed.
103
+ */
104
+ private assertChunkStacksMatchNodeDepth;
99
105
  getFieldKey(): FieldKey;
100
106
  private getStackedFieldKey;
101
107
  private getStackedNodeIndex;
102
- private getStackedNode;
108
+ private getStackedChunkIndex;
109
+ private getStackedChunk;
110
+ /**
111
+ * Converts a {@link height}, which contains field and node levels, into the corresponding depth/index
112
+ * for the node-only stacks ({@link indexOfChunkStack} and {@link indexWithinChunkStack}), which are
113
+ * only pushed on node-level transitions.
114
+ *
115
+ * @param height - A depth in {@link siblingStack} to convert. Defaults to {@link siblingStack}'s
116
+ * current length, which gives the current depth of the node-only stacks.
117
+ * @returns `floor(height / 2)` — the number of node levels at or below the given stack height.
118
+ */
119
+ private getNodeOnlyHeightFromHeight;
103
120
  getFieldLength(): number;
104
121
  enterNode(index: number): void;
105
122
  getPath(prefix?: PathRootPrefix): UpPath;
@@ -116,6 +133,13 @@ export declare class BasicChunkCursor extends SynchronousCursor implements Chunk
116
133
  exitField(): void;
117
134
  exitNode(): void;
118
135
  private getNode;
136
+ /**
137
+ * Resolves the chunks that make up the field the cursor is currently in. At the root, this is
138
+ * {@link root} directly. Otherwise, the cursor must be in {@link CursorLocationType.Fields} mode,
139
+ * and the result is looked up on the parent node using the current field key.
140
+ *
141
+ * @returns The chunks that make up the field the cursor is currently in.
142
+ */
119
143
  private getField;
120
144
  get value(): Value;
121
145
  get type(): TreeType;
@@ -1 +1 @@
1
- {"version":3,"file":"basicChunk.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/chunked-forest/basicChunk.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,kBAAkB,EAClB,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC7B,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,MAAM,EACX,KAAK,KAAK,EACV,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,WAAW,EAEX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAc,MAAM,uBAAuB,CAAC;AAEtE;;GAEG;AACH,qBAAa,UAAW,SAAQ,oBAAqB,YAAW,SAAS;IAShE,IAAI,EAAE,wBAAwB;IACrC;;;;;;;OAOG;IACI,MAAM,EAAE,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,CAAC;IACzC;;OAEG;IACI,KAAK,CAAC;IArBd,SA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YpB,UAAU,IAAI,OAAO;IAmBrB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAoDlC,SAAS,IAAI,OAAO;IAmBpB,QAAQ,IAAI,OAAO;IAiC1B,OAAO,CAAC,gBAAgB;IAUjB,SAAS,IAAI,IAAI;IAmBjB,QAAQ,IAAI,IAAI;IAqBvB,OAAO,CAAC,OAAO;IAOf;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IAkBhB,IAAW,KAAK,IAAI,KAAK,CAKxB;IAED,IAAW,IAAI,IAAI,QAAQ,CAK1B;IAED,IAAW,UAAU,IAAI,MAAM,CAa9B;IAED;;;OAGG;IACH,OAAO,CAAC,YAAY;IAUpB,IAAW,UAAU,IAAI,MAAM,CAQ9B;IAED,IAAW,WAAW,IAAI,MAAM,CAK/B;CACD"}
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { assert, oob, fail } from "@fluidframework/core-utils/internal";
5
+ import { assert, oob, fail, debugAssert } from "@fluidframework/core-utils/internal";
6
6
  import { cursorChunk, dummyRoot, } from "../../core/index.js";
7
7
  import { ReferenceCountedBase } from "../../util/index.js";
8
8
  import { SynchronousCursor, prefixPath } from "../treeCursorUtils.js";
@@ -126,16 +126,21 @@ export class BasicChunkCursor extends SynchronousCursor {
126
126
  if (this.nestedCursor !== undefined) {
127
127
  return this.nestedCursor.mode;
128
128
  }
129
- // Compute the number of nodes deep the current depth is.
130
- // We want the floor of the result, which can computed using a bitwise shift assuming the depth is less than 2^31, which seems safe.
131
- // eslint-disable-next-line no-bitwise
132
- const halfHeight = (this.siblingStack.length + 1) >> 1;
133
- assert(this.indexOfChunkStack.length === halfHeight, 0x51c /* unexpected indexOfChunkStack */);
134
- assert(this.indexWithinChunkStack.length === halfHeight, 0x51d /* unexpected indexWithinChunkStack */);
129
+ this.assertChunkStacksMatchNodeDepth();
135
130
  return this.siblingStack.length % 2 === 0
136
131
  ? 1 /* CursorLocationType.Fields */
137
132
  : 0 /* CursorLocationType.Nodes */;
138
133
  }
134
+ /**
135
+ * Asserts that the node-only stacks (`indexOfChunkStack` and `indexWithinChunkStack`) are in sync with `siblingStack`.
136
+ * Since `siblingStack` interleaves field and node levels while the node-only stacks are pushed/popped only on node-level transitions,
137
+ * their length should always equal the number of node levels traversed.
138
+ */
139
+ assertChunkStacksMatchNodeDepth() {
140
+ const halfHeight = this.getNodeOnlyHeightFromHeight();
141
+ assert(this.indexOfChunkStack.length === halfHeight, 0x51c /* unexpected indexOfChunkStack */);
142
+ assert(this.indexWithinChunkStack.length === halfHeight, 0x51d /* unexpected indexWithinChunkStack */);
143
+ }
139
144
  getFieldKey() {
140
145
  if (this.nestedCursor !== undefined) {
141
146
  return this.nestedCursor.getFieldKey();
@@ -153,9 +158,30 @@ export class BasicChunkCursor extends SynchronousCursor {
153
158
  assert(height >= 0, 0x521 /* must not be above root */);
154
159
  return this.indexStack[height] ?? oob();
155
160
  }
156
- getStackedNode(height) {
157
- const index = this.getStackedNodeIndex(height);
158
- return this.siblingStack[height][index];
161
+ getStackedChunkIndex(height) {
162
+ assert(height % 2 === 1, 0xcf3 /* must be node height */);
163
+ assert(height >= 0, 0xcf4 /* must not be above root */);
164
+ return this.indexOfChunkStack[this.getNodeOnlyHeightFromHeight(height)] ?? oob();
165
+ }
166
+ getStackedChunk(height) {
167
+ const index = this.getStackedChunkIndex(height);
168
+ const chunk = this.siblingStack[height][index];
169
+ debugAssert(() => chunk instanceof BasicChunk || "only basic chunks are expected");
170
+ return chunk;
171
+ }
172
+ /**
173
+ * Converts a {@link height}, which contains field and node levels, into the corresponding depth/index
174
+ * for the node-only stacks ({@link indexOfChunkStack} and {@link indexWithinChunkStack}), which are
175
+ * only pushed on node-level transitions.
176
+ *
177
+ * @param height - A depth in {@link siblingStack} to convert. Defaults to {@link siblingStack}'s
178
+ * current length, which gives the current depth of the node-only stacks.
179
+ * @returns `floor(height / 2)` — the number of node levels at or below the given stack height.
180
+ */
181
+ getNodeOnlyHeightFromHeight(height = this.siblingStack.length) {
182
+ // The bitwise shift computes the floor, which is valid assuming the depth is less than 2^31, which seems safe.
183
+ // eslint-disable-next-line no-bitwise
184
+ return height >> 1;
159
185
  }
160
186
  getFieldLength() {
161
187
  if (this.nestedCursor !== undefined) {
@@ -252,6 +278,11 @@ export class BasicChunkCursor extends SynchronousCursor {
252
278
  assert(this.mode === 0 /* CursorLocationType.Nodes */, 0x528 /* must be in nodes mode */);
253
279
  this.siblingStack.push(this.siblings);
254
280
  this.indexStack.push(this.index);
281
+ // Save the chunk array position of the current node. When siblings contain
282
+ // multi node chunks, the flat node index diverges from the array position,
283
+ // so getField needs this to locate the parent in the sibling array.
284
+ this.indexOfChunkStack.push(this.indexOfChunk);
285
+ this.indexWithinChunkStack.push(this.indexWithinChunk);
255
286
  // For fields, siblings are only used for key lookup and
256
287
  // nextField and which has arbitrary iteration order,
257
288
  // so making a array of just key here works.
@@ -259,6 +290,7 @@ export class BasicChunkCursor extends SynchronousCursor {
259
290
  // at the cost of an allocation here.
260
291
  this.index = 0;
261
292
  this.siblings = [key];
293
+ this.assertChunkStacksMatchNodeDepth();
262
294
  }
263
295
  nextField() {
264
296
  if (this.nestedCursor !== undefined) {
@@ -281,8 +313,11 @@ export class BasicChunkCursor extends SynchronousCursor {
281
313
  }
282
314
  this.siblingStack.push(this.siblings);
283
315
  this.indexStack.push(this.index);
316
+ this.indexOfChunkStack.push(this.indexOfChunk);
317
+ this.indexWithinChunkStack.push(this.indexWithinChunk);
284
318
  this.index = 0;
285
319
  this.siblings = [...fields.keys()]; // TODO: avoid this copy
320
+ this.assertChunkStacksMatchNodeDepth();
286
321
  return true;
287
322
  }
288
323
  seekNodes(offset) {
@@ -339,12 +374,11 @@ export class BasicChunkCursor extends SynchronousCursor {
339
374
  }
340
375
  this.siblingStack.push(this.siblings);
341
376
  this.indexStack.push(this.index);
342
- this.indexOfChunkStack.push(this.indexOfChunk);
343
- this.indexWithinChunkStack.push(this.indexWithinChunk);
344
377
  this.index = 0;
345
378
  this.siblings = siblings;
346
379
  this.indexOfChunk = 0;
347
380
  this.indexWithinChunk = 0;
381
+ this.assertChunkStacksMatchNodeDepth();
348
382
  this.initNestedCursor();
349
383
  return true;
350
384
  }
@@ -389,6 +423,12 @@ export class BasicChunkCursor extends SynchronousCursor {
389
423
  this.siblings =
390
424
  this.siblingStack.pop() ?? fail(0xaf0 /* Unexpected siblingStack.length */);
391
425
  this.index = this.indexStack.pop() ?? fail(0xaf1 /* Unexpected indexStack.length */);
426
+ this.indexOfChunk =
427
+ this.indexOfChunkStack.pop() ?? fail(0xcf5 /* Unexpected indexOfChunkStack.length */);
428
+ this.indexWithinChunk =
429
+ this.indexWithinChunkStack.pop() ??
430
+ fail(0xcf6 /* Unexpected indexWithinChunkStack.length */);
431
+ this.assertChunkStacksMatchNodeDepth();
392
432
  }
393
433
  exitNode() {
394
434
  if (this.nestedCursor !== undefined) {
@@ -401,22 +441,35 @@ export class BasicChunkCursor extends SynchronousCursor {
401
441
  this.siblings =
402
442
  this.siblingStack.pop() ?? fail(0xaf2 /* Unexpected siblingStack.length */);
403
443
  this.index = this.indexStack.pop() ?? fail(0xaf3 /* Unexpected indexStack.length */);
404
- this.indexOfChunk =
405
- this.indexOfChunkStack.pop() ?? fail(0xaf4 /* Unexpected indexOfChunkStack.length */);
406
- this.indexWithinChunk =
407
- this.indexWithinChunkStack.pop() ??
408
- fail(0xaf5 /* Unexpected indexWithinChunkStack.length */);
444
+ // At the Fields level these aren't semantically used, but reset for consistent state
445
+ // (so a fully-iterated cursor matches a fresh cursor at the same logical position).
446
+ this.indexOfChunk = 0;
447
+ this.indexWithinChunk = 0;
448
+ this.assertChunkStacksMatchNodeDepth();
409
449
  }
410
450
  getNode() {
411
451
  assert(this.mode === 0 /* CursorLocationType.Nodes */, 0x52f /* can only get node when in node */);
412
- return this.siblings[this.index];
452
+ const chunk = this.siblings[this.indexOfChunk];
453
+ debugAssert(() => chunk instanceof BasicChunk || "only basic chunks are expected");
454
+ return chunk;
413
455
  }
456
+ /**
457
+ * Resolves the chunks that make up the field the cursor is currently in. At the root, this is
458
+ * {@link root} directly. Otherwise, the cursor must be in {@link CursorLocationType.Fields} mode,
459
+ * and the result is looked up on the parent node using the current field key.
460
+ *
461
+ * @returns The chunks that make up the field the cursor is currently in.
462
+ */
414
463
  getField() {
415
464
  if (this.siblingStack.length === 0) {
416
465
  return this.root;
417
466
  }
418
467
  assert(this.mode === 1 /* CursorLocationType.Fields */, 0x530 /* can only get field when in fields */);
419
- const parent = this.getStackedNode(this.indexStack.length - 1);
468
+ // The parent node is the `BasicChunk` in the node array at the top of
469
+ // `siblingStack` while we are in `CursorLocationType.Fields` mode. We need the parent
470
+ // since a field's chunks are stored on the parent node's `BasicChunk.fields` map, not on
471
+ // the cursor itself.
472
+ const parent = this.getStackedChunk(this.siblingStack.length - 1);
420
473
  const key = this.getFieldKey();
421
474
  const field = parent.fields.get(key) ?? [];
422
475
  return field;