@fluidframework/tree 2.53.0-350190 → 2.53.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 (236) hide show
  1. package/.eslintrc.cjs +14 -2
  2. package/CHANGELOG.md +125 -0
  3. package/api-report/tree.alpha.api.md +11 -13
  4. package/dist/core/tree/visitDelta.d.ts +1 -1
  5. package/dist/core/tree/visitDelta.d.ts.map +1 -1
  6. package/dist/core/tree/visitDelta.js.map +1 -1
  7. package/dist/feature-libraries/chunked-forest/index.d.ts +1 -0
  8. package/dist/feature-libraries/chunked-forest/index.d.ts.map +1 -1
  9. package/dist/feature-libraries/chunked-forest/index.js +3 -1
  10. package/dist/feature-libraries/chunked-forest/index.js.map +1 -1
  11. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts +2 -4
  12. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  13. package/dist/feature-libraries/default-schema/defaultEditBuilder.js +3 -0
  14. package/dist/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  15. package/dist/feature-libraries/default-schema/noChangeCodecs.d.ts +1 -1
  16. package/dist/feature-libraries/default-schema/noChangeCodecs.d.ts.map +1 -1
  17. package/dist/feature-libraries/default-schema/noChangeCodecs.js.map +1 -1
  18. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts +4 -0
  19. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  20. package/dist/feature-libraries/forest-summary/forestSummarizer.js +5 -5
  21. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  22. package/dist/feature-libraries/index.d.ts +1 -1
  23. package/dist/feature-libraries/index.d.ts.map +1 -1
  24. package/dist/feature-libraries/index.js +4 -2
  25. package/dist/feature-libraries/index.js.map +1 -1
  26. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +1 -0
  27. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  28. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV1.d.ts +1 -1
  29. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV1.d.ts.map +1 -1
  30. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV1.js.map +1 -1
  31. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts +1 -1
  32. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts.map +1 -1
  33. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  34. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts +1 -1
  35. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts.map +1 -1
  36. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.js.map +1 -1
  37. package/dist/feature-libraries/sequence-field/sequenceFieldCodecs.d.ts +1 -1
  38. package/dist/feature-libraries/sequence-field/sequenceFieldCodecs.d.ts.map +1 -1
  39. package/dist/feature-libraries/sequence-field/sequenceFieldCodecs.js.map +1 -1
  40. package/dist/feature-libraries/sequence-field/types.d.ts +1 -1
  41. package/dist/feature-libraries/sequence-field/types.d.ts.map +1 -1
  42. package/dist/feature-libraries/sequence-field/types.js.map +1 -1
  43. package/dist/index.js +3 -2
  44. package/dist/index.js.map +1 -1
  45. package/dist/packageVersion.d.ts +1 -1
  46. package/dist/packageVersion.d.ts.map +1 -1
  47. package/dist/packageVersion.js +1 -1
  48. package/dist/packageVersion.js.map +1 -1
  49. package/dist/shared-tree/independentView.d.ts.map +1 -1
  50. package/dist/shared-tree/independentView.js +1 -1
  51. package/dist/shared-tree/independentView.js.map +1 -1
  52. package/dist/shared-tree/index.d.ts +0 -1
  53. package/dist/shared-tree/index.d.ts.map +1 -1
  54. package/dist/shared-tree/index.js.map +1 -1
  55. package/dist/shared-tree/schematizeTree.d.ts +23 -60
  56. package/dist/shared-tree/schematizeTree.d.ts.map +1 -1
  57. package/dist/shared-tree/schematizeTree.js +59 -151
  58. package/dist/shared-tree/schematizeTree.js.map +1 -1
  59. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  60. package/dist/shared-tree/schematizingTreeView.js +8 -8
  61. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  62. package/dist/shared-tree-core/defaultResubmitMachine.d.ts +2 -1
  63. package/dist/shared-tree-core/defaultResubmitMachine.d.ts.map +1 -1
  64. package/dist/shared-tree-core/defaultResubmitMachine.js.map +1 -1
  65. package/dist/simple-tree/core/allowedTypes.d.ts +14 -14
  66. package/dist/simple-tree/core/allowedTypes.d.ts.map +1 -1
  67. package/dist/simple-tree/core/allowedTypes.js.map +1 -1
  68. package/dist/simple-tree/core/treeNode.d.ts +0 -3
  69. package/dist/simple-tree/core/treeNode.d.ts.map +1 -1
  70. package/dist/simple-tree/core/treeNode.js +3 -3
  71. package/dist/simple-tree/core/treeNode.js.map +1 -1
  72. package/dist/simple-tree/core/treeNodeValid.d.ts.map +1 -1
  73. package/dist/simple-tree/core/treeNodeValid.js +0 -3
  74. package/dist/simple-tree/core/treeNodeValid.js.map +1 -1
  75. package/dist/simple-tree/fieldSchema.d.ts +2 -1
  76. package/dist/simple-tree/fieldSchema.d.ts.map +1 -1
  77. package/dist/simple-tree/fieldSchema.js.map +1 -1
  78. package/dist/simple-tree/index.d.ts +1 -1
  79. package/dist/simple-tree/index.d.ts.map +1 -1
  80. package/dist/simple-tree/index.js +3 -2
  81. package/dist/simple-tree/index.js.map +1 -1
  82. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  83. package/dist/simple-tree/node-kinds/array/arrayNode.js +5 -5
  84. package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  85. package/dist/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
  86. package/dist/simple-tree/node-kinds/map/mapNode.js +1 -1
  87. package/dist/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  88. package/dist/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  89. package/dist/simple-tree/node-kinds/object/objectNode.js +2 -2
  90. package/dist/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  91. package/dist/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
  92. package/dist/simple-tree/node-kinds/record/recordNode.js +1 -1
  93. package/dist/simple-tree/node-kinds/record/recordNode.js.map +1 -1
  94. package/dist/tableSchema.d.ts +25 -32
  95. package/dist/tableSchema.d.ts.map +1 -1
  96. package/dist/tableSchema.js +10 -24
  97. package/dist/tableSchema.js.map +1 -1
  98. package/docs/.attachments/cell-ordering/C-knows-of-ABC.png +0 -0
  99. package/docs/.attachments/cell-ordering/C-knows-of-C.png +0 -0
  100. package/docs/.attachments/cell-ordering/XvsA.png +0 -0
  101. package/docs/.attachments/cell-ordering/compose-a-b.png +0 -0
  102. package/docs/.attachments/cell-ordering/compose-a-ref-p1-b-ref-p2.png +0 -0
  103. package/docs/.attachments/cell-ordering/compose-b-no-ref-to-ca.png +0 -0
  104. package/docs/.attachments/cell-ordering/rebase-ab-over-x.png +0 -0
  105. package/docs/.attachments/cell-ordering/rebase-b-over-x.png +0 -0
  106. package/docs/.attachments/cell-ordering/rebase-b2-over-x.png +0 -0
  107. package/docs/.attachments/cell-ordering/rebase-b2.png +0 -0
  108. package/docs/.attachments/cell-ordering/rebase-to-abprime.png +0 -0
  109. package/docs/.attachments/cell-ordering/rebase-to-bprime.png +0 -0
  110. package/docs/main/cell-ordering.md +638 -0
  111. package/lib/core/tree/visitDelta.d.ts +1 -1
  112. package/lib/core/tree/visitDelta.d.ts.map +1 -1
  113. package/lib/core/tree/visitDelta.js.map +1 -1
  114. package/lib/feature-libraries/chunked-forest/index.d.ts +1 -0
  115. package/lib/feature-libraries/chunked-forest/index.d.ts.map +1 -1
  116. package/lib/feature-libraries/chunked-forest/index.js +1 -0
  117. package/lib/feature-libraries/chunked-forest/index.js.map +1 -1
  118. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts +2 -4
  119. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  120. package/lib/feature-libraries/default-schema/defaultEditBuilder.js +4 -1
  121. package/lib/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  122. package/lib/feature-libraries/default-schema/noChangeCodecs.d.ts +1 -1
  123. package/lib/feature-libraries/default-schema/noChangeCodecs.d.ts.map +1 -1
  124. package/lib/feature-libraries/default-schema/noChangeCodecs.js.map +1 -1
  125. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts +4 -0
  126. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  127. package/lib/feature-libraries/forest-summary/forestSummarizer.js +1 -1
  128. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  129. package/lib/feature-libraries/index.d.ts +1 -1
  130. package/lib/feature-libraries/index.d.ts.map +1 -1
  131. package/lib/feature-libraries/index.js +1 -1
  132. package/lib/feature-libraries/index.js.map +1 -1
  133. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +1 -0
  134. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  135. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.d.ts +1 -1
  136. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.d.ts.map +1 -1
  137. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.js +1 -1
  138. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.js.map +1 -1
  139. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts +1 -1
  140. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts.map +1 -1
  141. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js +1 -1
  142. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  143. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts +1 -1
  144. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts.map +1 -1
  145. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.js +1 -1
  146. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.js.map +1 -1
  147. package/lib/feature-libraries/sequence-field/sequenceFieldCodecs.d.ts +1 -1
  148. package/lib/feature-libraries/sequence-field/sequenceFieldCodecs.d.ts.map +1 -1
  149. package/lib/feature-libraries/sequence-field/sequenceFieldCodecs.js.map +1 -1
  150. package/lib/feature-libraries/sequence-field/types.d.ts +1 -1
  151. package/lib/feature-libraries/sequence-field/types.d.ts.map +1 -1
  152. package/lib/feature-libraries/sequence-field/types.js.map +1 -1
  153. package/lib/index.js +1 -1
  154. package/lib/index.js.map +1 -1
  155. package/lib/packageVersion.d.ts +1 -1
  156. package/lib/packageVersion.d.ts.map +1 -1
  157. package/lib/packageVersion.js +1 -1
  158. package/lib/packageVersion.js.map +1 -1
  159. package/lib/shared-tree/independentView.d.ts.map +1 -1
  160. package/lib/shared-tree/independentView.js +2 -2
  161. package/lib/shared-tree/independentView.js.map +1 -1
  162. package/lib/shared-tree/index.d.ts +0 -1
  163. package/lib/shared-tree/index.d.ts.map +1 -1
  164. package/lib/shared-tree/index.js.map +1 -1
  165. package/lib/shared-tree/schematizeTree.d.ts +23 -60
  166. package/lib/shared-tree/schematizeTree.d.ts.map +1 -1
  167. package/lib/shared-tree/schematizeTree.js +60 -150
  168. package/lib/shared-tree/schematizeTree.js.map +1 -1
  169. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  170. package/lib/shared-tree/schematizingTreeView.js +11 -11
  171. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  172. package/lib/shared-tree-core/defaultResubmitMachine.d.ts +2 -1
  173. package/lib/shared-tree-core/defaultResubmitMachine.d.ts.map +1 -1
  174. package/lib/shared-tree-core/defaultResubmitMachine.js.map +1 -1
  175. package/lib/simple-tree/core/allowedTypes.d.ts +14 -14
  176. package/lib/simple-tree/core/allowedTypes.d.ts.map +1 -1
  177. package/lib/simple-tree/core/allowedTypes.js.map +1 -1
  178. package/lib/simple-tree/core/treeNode.d.ts +0 -3
  179. package/lib/simple-tree/core/treeNode.d.ts.map +1 -1
  180. package/lib/simple-tree/core/treeNode.js +3 -3
  181. package/lib/simple-tree/core/treeNode.js.map +1 -1
  182. package/lib/simple-tree/core/treeNodeValid.d.ts.map +1 -1
  183. package/lib/simple-tree/core/treeNodeValid.js +0 -3
  184. package/lib/simple-tree/core/treeNodeValid.js.map +1 -1
  185. package/lib/simple-tree/fieldSchema.d.ts +2 -1
  186. package/lib/simple-tree/fieldSchema.d.ts.map +1 -1
  187. package/lib/simple-tree/fieldSchema.js.map +1 -1
  188. package/lib/simple-tree/index.d.ts +1 -1
  189. package/lib/simple-tree/index.d.ts.map +1 -1
  190. package/lib/simple-tree/index.js +1 -1
  191. package/lib/simple-tree/index.js.map +1 -1
  192. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  193. package/lib/simple-tree/node-kinds/array/arrayNode.js +5 -5
  194. package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  195. package/lib/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
  196. package/lib/simple-tree/node-kinds/map/mapNode.js +1 -1
  197. package/lib/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  198. package/lib/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  199. package/lib/simple-tree/node-kinds/object/objectNode.js +2 -2
  200. package/lib/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  201. package/lib/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
  202. package/lib/simple-tree/node-kinds/record/recordNode.js +1 -1
  203. package/lib/simple-tree/node-kinds/record/recordNode.js.map +1 -1
  204. package/lib/tableSchema.d.ts +25 -32
  205. package/lib/tableSchema.d.ts.map +1 -1
  206. package/lib/tableSchema.js +11 -25
  207. package/lib/tableSchema.js.map +1 -1
  208. package/package.json +20 -20
  209. package/src/core/tree/visitDelta.ts +3 -1
  210. package/src/feature-libraries/chunked-forest/index.ts +1 -0
  211. package/src/feature-libraries/default-schema/defaultEditBuilder.ts +12 -5
  212. package/src/feature-libraries/default-schema/noChangeCodecs.ts +1 -1
  213. package/src/feature-libraries/forest-summary/forestSummarizer.ts +1 -1
  214. package/src/feature-libraries/index.ts +2 -0
  215. package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +1 -0
  216. package/src/feature-libraries/sequence-field/sequenceFieldCodecV1.ts +4 -2
  217. package/src/feature-libraries/sequence-field/sequenceFieldCodecV2.ts +4 -2
  218. package/src/feature-libraries/sequence-field/sequenceFieldCodecV3.ts +4 -2
  219. package/src/feature-libraries/sequence-field/sequenceFieldCodecs.ts +1 -1
  220. package/src/feature-libraries/sequence-field/types.ts +1 -1
  221. package/src/packageVersion.ts +1 -1
  222. package/src/shared-tree/independentView.ts +6 -2
  223. package/src/shared-tree/index.ts +0 -2
  224. package/src/shared-tree/schematizeTree.ts +83 -199
  225. package/src/shared-tree/schematizingTreeView.ts +17 -9
  226. package/src/shared-tree-core/defaultResubmitMachine.ts +2 -1
  227. package/src/simple-tree/core/allowedTypes.ts +25 -16
  228. package/src/simple-tree/core/treeNode.ts +3 -3
  229. package/src/simple-tree/core/treeNodeValid.ts +0 -3
  230. package/src/simple-tree/fieldSchema.ts +2 -1
  231. package/src/simple-tree/index.ts +1 -3
  232. package/src/simple-tree/node-kinds/array/arrayNode.ts +29 -36
  233. package/src/simple-tree/node-kinds/map/mapNode.ts +4 -1
  234. package/src/simple-tree/node-kinds/object/objectNode.ts +5 -2
  235. package/src/simple-tree/node-kinds/record/recordNode.ts +4 -1
  236. package/src/tableSchema.ts +40 -35
package/.eslintrc.cjs CHANGED
@@ -89,6 +89,19 @@ module.exports = {
89
89
  "unicorn/switch-case-braces": "off",
90
90
  "unicorn/text-encoding-identifier-case": "off",
91
91
 
92
+ "@typescript-eslint/no-restricted-imports": [
93
+ "error",
94
+ {
95
+ "patterns": [
96
+ {
97
+ "group": ["./index.js", "**/../index.js"],
98
+ "message":
99
+ "Importing from a parent index file tends to cause cyclic dependencies. Import from a more specific sibling file instead.",
100
+ },
101
+ ],
102
+ },
103
+ ],
104
+
92
105
  // #endregion
93
106
  },
94
107
  overrides: [
@@ -102,11 +115,10 @@ module.exports = {
102
115
  "@typescript-eslint/explicit-function-return-type": "off",
103
116
  },
104
117
  },
105
- // TODO: Remove this override once this config has been updated to extend at least the "recommended" base config.
106
118
  {
107
119
  files: ["src/test/**/*.generated.ts*"],
108
120
  rules: {
109
- "@typescript-eslint/no-explicit-any": ["off"],
121
+ "@typescript-eslint/no-restricted-imports": ["off"],
110
122
  },
111
123
  },
112
124
  ],
package/CHANGELOG.md CHANGED
@@ -1,5 +1,130 @@
1
1
  # @fluidframework/tree
2
2
 
3
+ ## 2.53.0
4
+
5
+ ### Minor Changes
6
+
7
+ - TableSchema's "removeColumn" API now removes corresponding cells (alpha) ([#25213](https://github.com/microsoft/FluidFramework/pull/25213)) [b665ba8320d](https://github.com/microsoft/FluidFramework/commit/b665ba8320d9ab6d1b87de81bdf54c2fde20e5c1)
8
+
9
+ Previously, the [removeColumn](https://fluidframework.com/docs/api/fluid-framework/tableschema-namespace/table-interface#removecolumn-methodsignature) API on Table nodes derived from [TableSchema](https://fluidframework.com/docs/api/fluid-framework/tableschema-namespace/) (alpha) only removed the `Column` node from the list of columns tracked by the table.
10
+ To also remove the corresponding cells from the table (which are stored on the `Row` nodes), the user was required to write a custom transaction that removed the column and cells.
11
+
12
+ The motivation for this design was due to performance concerns with transactions.
13
+ Those concerns are still relevant, but the data leak risk of dropping columns without removing corresponding cells seems a greater risk, and we have plans to address the performance issues with transactions.
14
+
15
+ - Adds staged allowed types to SchemaFactoryAlpha ([#25116](https://github.com/microsoft/FluidFramework/pull/25116)) [59baf03ac7f](https://github.com/microsoft/FluidFramework/commit/59baf03ac7f2f2779533c8c63e1de85c01a0d39a)
16
+
17
+ This adds the `staged` API to [`SchemaFactoryAlpha`](https://fluidframework.com/docs/api/fluid-framework/schemafactoryalpha-class).
18
+ Staged allowed types can be used for schema evolution to add members to an [`AllowedTypes`](https://fluidframework.com/docs/api/fluid-framework/allowedtypes-typealias) while supporting cross version collaboration.
19
+
20
+ Staged allowed types are [allowed types](https://fluidframework.com/docs/api/fluid-framework/allowedtypes-typealias) that can be upgraded by [schema upgrades](https://fluidframework.com/docs/api/fluid-framework/treeview-interface#upgradeschema-methodsignature).
21
+ Before being upgraded, any attempt to insert or move a node to a location which requires its type to be upgraded to be valid will throw an error.
22
+
23
+ To add a new member to an `AllowedTypes`, add the type wrapped by `staged`.
24
+ For example, migrating an array which previously supported only numbers to support both numbers and strings would start by deploying a version of the app using `staged`:
25
+
26
+ ```typescript
27
+ class TestArray extends schemaFactoryAlpha.arrayAlpha("TestArray", [
28
+ SchemaFactoryAlpha.number,
29
+ SchemaFactoryAlpha.staged(SchemaFactoryAlpha.string),
30
+ ]) {}
31
+ ```
32
+
33
+ Once enough clients have this code update, it is safe to allow writing strings to the array.
34
+ To allow writing strings to the array, a code change must be made to remove the staged annotation:
35
+
36
+ ```typescript
37
+ class TestArray extends schemaFactoryAlpha.arrayAlpha("TestArray", [
38
+ schemaFactoryAlpha.number,
39
+ schemaFactoryAlpha.string,
40
+ ]) {}
41
+ ```
42
+
43
+ Then when opening old documents [upgradeSchema](https://fluidframework.com/docs/api/fluid-framework/treeview-interface#upgradeschema-methodsignature) is used to upgrade the stored schema:
44
+
45
+ ```typescript
46
+ view.upgradeSchema();
47
+ ```
48
+
49
+ The `@alpha` API [extractPersistedSchema](https://fluidframework.com/docs/api/fluid-framework#extractpersistedschema-function) now takes the schema as an `ImplicitAnnotatedFieldSchema` and an additional parameter to filter which staged upgrades it includes.
50
+
51
+ Below is a full example of how the schema migration process works.
52
+ This can also be found in the [tests](https://github.com/microsoft/FluidFramework/blob/main/packages/dds/tree/src/test/simple-tree/api/stagedSchemaUpgrade.spec.ts).
53
+
54
+ ```typescript
55
+ // Schema A: only number allowed
56
+ const schemaA = SchemaFactoryAlpha.optional([SchemaFactoryAlpha.number]);
57
+
58
+ // Schema B: number or string (string is staged)
59
+ const schemaB = SchemaFactoryAlpha.optional([
60
+ SchemaFactoryAlpha.number,
61
+ SchemaFactoryAlpha.staged(SchemaFactoryAlpha.string),
62
+ ]);
63
+
64
+ // Schema C: number or string, both fully allowed
65
+ const schemaC = SchemaFactoryAlpha.optional([
66
+ SchemaFactoryAlpha.number,
67
+ SchemaFactoryAlpha.string,
68
+ ]);
69
+
70
+ // Initialize with schema A.
71
+ const configA = new TreeViewConfiguration({
72
+ schema: schemaA,
73
+ });
74
+ const viewA = treeA.viewWith(configA);
75
+ viewA.initialize(5);
76
+
77
+ // Since we are running all the different versions of the app in the same process making changes synchronously,
78
+ // an explicit flush is needed to make them available to each other.
79
+ synchronizeTrees();
80
+
81
+ assert.deepEqual(viewA.root, 5);
82
+
83
+ // View the same document with a second tree using schema B.
84
+ const configB = new TreeViewConfiguration({
85
+ schema: schemaB,
86
+ });
87
+ const viewB = treeB.viewWith(configB);
88
+ // B cannot write strings to the root.
89
+ assert.throws(() => (viewB.root = "test"));
90
+
91
+ // View the same document with a third tree using schema C.
92
+ const configC = new TreeViewConfiguration({
93
+ schema: schemaC,
94
+ });
95
+ const viewC = treeC.viewWith(configC);
96
+ // Upgrade to schema C
97
+ viewC.upgradeSchema();
98
+ // Use the newly enabled schema.
99
+ viewC.root = "test";
100
+
101
+ synchronizeTrees();
102
+
103
+ // View A is now incompatible with the stored schema:
104
+ assert.equal(viewA.compatibility.canView, false);
105
+
106
+ // View B can still read the document, and now sees the string root which relies on the staged schema.
107
+ assert.deepEqual(viewB.root, "test");
108
+ ```
109
+
110
+ - Allow edits in arrays to be concurrent to dependent edits of transactions with violated constraints ([#25191](https://github.com/microsoft/FluidFramework/pull/25191)) [ef64bae6ab2](https://github.com/microsoft/FluidFramework/commit/ef64bae6ab2848c67d778d14ad56ae021f54ac7a)
111
+
112
+ Before this release, making concurrent edits to an array could lead to assertion error `0x8a2` being thrown if the following conditions were met:
113
+
114
+ - Some edit `e1` was a transaction with a constraint that turned out to be violated by edits concurrent to (and sequenced before) `e1`
115
+ - Some edit `e2` was dependent on `e1` (from before the violation of its constraint)
116
+ - Some edit `e3` was concurrent to and sequenced after both `e1` and `e2`
117
+ - `e3` was either concurrent to or the revert of some other edit `e0` that predated `e1`, `e2`, and `e3`.
118
+ - `e0` and `e2` made edits to the same gap (that is, in the same space between nodes) in the sequence/array.
119
+
120
+ After this release, these scenarios will work as expected (that is, no assertion error thrown).
121
+
122
+ - Export TreeNode not only as a type ([#25226](https://github.com/microsoft/FluidFramework/pull/25226)) [eefb9522c01](https://github.com/microsoft/FluidFramework/commit/eefb9522c019ac68d8b4f40d7134116c78a1f2a5)
123
+
124
+ `TreeNode` can now be used as a runtime object.
125
+ This enables checking if an object is a `TreeNode` with `instanceof`.
126
+ `TreeNode` has customized `instanceof` support so it can detect `TreeNode` instances, even if they hide their prototype like [POJO mode nodes](https://fluidframework.com/docs/api/fluid-framework/schemafactory-class#schemafactory-remarks) do.
127
+
3
128
  ## 2.52.0
4
129
 
5
130
  ### Minor Changes
@@ -15,7 +15,7 @@ export function adaptEnum<TScope extends string, const TEnum extends Record<stri
15
15
  }, Record<string, never>, true, Record<string, never>, undefined>; }[keyof TEnum]>;
16
16
  };
17
17
 
18
- // @alpha
18
+ // @alpha @input
19
19
  export interface AllowedTypeMetadata {
20
20
  readonly custom?: unknown;
21
21
  readonly stagedSchemaUpgrade?: SchemaUpgrade;
@@ -24,7 +24,7 @@ export interface AllowedTypeMetadata {
24
24
  // @public @system
25
25
  export type AllowedTypes = readonly LazyItem<TreeNodeSchema>[];
26
26
 
27
- // @alpha
27
+ // @alpha @input
28
28
  export interface AllowedTypesMetadata {
29
29
  readonly custom?: unknown;
30
30
  }
@@ -32,16 +32,16 @@ export interface AllowedTypesMetadata {
32
32
  // @alpha
33
33
  export function allowUnused<T>(t?: T): void;
34
34
 
35
- // @alpha
35
+ // @alpha @sealed
36
36
  export interface AnnotatedAllowedType<T = LazyItem<TreeNodeSchema>> {
37
37
  readonly metadata: AllowedTypeMetadata;
38
38
  readonly type: T;
39
39
  }
40
40
 
41
- // @alpha
42
- export interface AnnotatedAllowedTypes {
41
+ // @alpha @sealed
42
+ export interface AnnotatedAllowedTypes<T = LazyItem<TreeNodeSchema>> {
43
43
  readonly metadata: AllowedTypesMetadata;
44
- readonly types: readonly (AnnotatedAllowedType | LazyItem<TreeNodeSchema>)[];
44
+ readonly types: readonly AnnotatedAllowedType<T>[];
45
45
  }
46
46
 
47
47
  // @public @system
@@ -298,10 +298,10 @@ export type IdentifierIndex = SimpleTreeIndex<string, TreeNode>;
298
298
  // @public
299
299
  export type ImplicitAllowedTypes = AllowedTypes | TreeNodeSchema;
300
300
 
301
- // @alpha
301
+ // @alpha @input
302
302
  export type ImplicitAnnotatedAllowedTypes = TreeNodeSchema | AnnotatedAllowedType | AnnotatedAllowedTypes | readonly (AnnotatedAllowedType | LazyItem<TreeNodeSchema>)[];
303
303
 
304
- // @alpha
304
+ // @alpha @input
305
305
  export type ImplicitAnnotatedFieldSchema = FieldSchema | ImplicitAnnotatedAllowedTypes;
306
306
 
307
307
  // @public
@@ -623,10 +623,8 @@ export interface NodeSchemaOptionsAlpha<out TCustomMetadata = unknown> extends N
623
623
  // @alpha
624
624
  export const noopValidator: JsonValidator;
625
625
 
626
- // @alpha
627
- export interface NormalizedAnnotatedAllowedTypes {
628
- readonly metadata: AllowedTypesMetadata;
629
- readonly types: readonly AnnotatedAllowedType<TreeNodeSchema>[];
626
+ // @alpha @sealed
627
+ export interface NormalizedAnnotatedAllowedTypes extends AnnotatedAllowedTypes<TreeNodeSchema> {
630
628
  }
631
629
 
632
630
  // @public @system
@@ -1570,7 +1568,7 @@ export type UnannotateAllowedTypesList<T extends readonly (AnnotatedAllowedType
1570
1568
  };
1571
1569
 
1572
1570
  // @alpha @system
1573
- export type UnannotateImplicitAllowedTypes<T extends ImplicitAnnotatedAllowedTypes> = T extends AnnotatedAllowedTypes ? UnannotateAllowedTypes<T> : T extends AnnotatedAllowedType ? UnannotateAllowedTypesList<[T]> : T extends readonly (AnnotatedAllowedType | LazyItem<TreeNodeSchema>)[] ? UnannotateAllowedTypesList<T> : T extends TreeNodeSchema ? T : never;
1571
+ export type UnannotateImplicitAllowedTypes<T extends ImplicitAnnotatedAllowedTypes> = T extends AnnotatedAllowedTypes ? UnannotateAllowedTypes<T> : T extends AnnotatedAllowedType ? UnannotateAllowedTypesList<[T]> : T extends readonly (AnnotatedAllowedType | LazyItem<TreeNodeSchema>)[] ? UnannotateAllowedTypesList<T> : T extends TreeNodeSchema ? T : ImplicitAllowedTypes;
1574
1572
 
1575
1573
  // @alpha @system
1576
1574
  export type UnannotateImplicitFieldSchema<T extends ImplicitAnnotatedFieldSchema> = T extends ImplicitAnnotatedAllowedTypes ? UnannotateImplicitAllowedTypes<T> : T;
@@ -2,12 +2,12 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import type { RevisionTag } from "../index.js";
6
5
  import type { FieldKey } from "../schema-stored/index.js";
7
6
  import { type ITreeCursorSynchronous } from "./cursor.js";
8
7
  import type * as Delta from "./delta.js";
9
8
  import type { DetachedFieldIndex } from "./detachedFieldIndex.js";
10
9
  import type { NodeIndex, PlaceIndex, Range } from "./pathTree.js";
10
+ import type { RevisionTag } from "../rebase/index.js";
11
11
  /**
12
12
  * Implementation notes:
13
13
  *
@@ -1 +1 @@
1
- {"version":3,"file":"visitDelta.d.ts","sourceRoot":"","sources":["../../../src/core/tree/visitDelta.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAa,MAAM,aAAa,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAkB,KAAK,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,KAAK,KAAK,KAAK,MAAM,YAAY,CAAC;AAEzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE,OAAO,KAAK,EAAE,SAAS,EAAE,UA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KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AACxD,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 { type NestedMap, setInNestedMap, tryGetFromNestedMap } from \"../../util/index.js\";\nimport type { RevisionTag, TreeChunk } from \"../index.js\";\nimport type { FieldKey } from \"../schema-stored/index.js\";\n\nimport { mapCursorField, type ITreeCursorSynchronous } from \"./cursor.js\";\nimport type * as Delta from \"./delta.js\";\nimport { areDetachedNodeIdsEqual, offsetDetachId } from \"./deltaUtil.js\";\nimport type { DetachedFieldIndex } from \"./detachedFieldIndex.js\";\nimport type { ForestRootId, Major, Minor } from \"./detachedFieldIndexTypes.js\";\nimport type { NodeIndex, PlaceIndex, Range } from \"./pathTree.js\";\n\n/**\n * Implementation notes:\n *\n * The visit is organized into four phases:\n * 1. a detach pass\n * 2. root transfers\n * 3. an attach pass\n * 4. root destructions\n *\n * The core idea is that before content can be attached, it must first exist and be in a detached field.\n *\n * While the detach pass ensures that nodes to be attached are in a detached state, it does not guarantee that they\n * reside in the correct detached field. That is the responsibility of the root transfers phase.\n *\n * The attach phase carries out attaches.\n *\n * After the attach phase, roots destruction is carried out.\n * This needs to happen last to allow modifications to detached roots to be applied before they are destroyed.\n *\n * The details of the delta visit algorithm can impact how/when events are emitted by the objects that own the visitors.\n * For example, as of 2024-03-27, the subtreeChanged event of an AnchorNode is emitted when exiting a node during a\n * delta visit, and thus the two-pass nature of the algorithm means the event fires twice for any given change.\n */\n\n/**\n * Crawls the given `delta`, calling `visitor`'s callback for each change encountered.\n * Each successive call to the visitor callbacks assumes that the change described by earlier calls have been applied\n * to the document tree. For example, for a change that removes the first and third node of a field, the visitor calls\n * will first call detach with a range from indices 0 to 1 then call detach with a range from indices 1 to 2.\n *\n * @param delta - The delta to be crawled.\n * @param visitor - The object to notify of the changes encountered.\n * @param detachedFieldIndex - Index responsible for keeping track of the existing detached fields.\n * @param latestRevision - The latest revision tag associated with this delta.\n */\nexport function visitDelta(\n\tdelta: Delta.Root,\n\tvisitor: DeltaVisitor,\n\tdetachedFieldIndex: DetachedFieldIndex,\n\tlatestRevision: RevisionTag | undefined,\n): void {\n\tconst detachPassRoots: Map<ForestRootId, Delta.FieldMap> = new Map();\n\tconst attachPassRoots: Map<ForestRootId, Delta.FieldMap> = new Map();\n\tconst rootTransfers: Delta.DetachedNodeRename[] = [];\n\tconst rootDestructions: Delta.DetachedNodeDestruction[] = [];\n\tconst refreshers: NestedMap<Major, Minor, ITreeCursorSynchronous> = new Map();\n\tdelta.refreshers?.forEach(({ id: { major, minor }, trees }) => {\n\t\tconst treeCursors = nodeCursorsFromChunk(trees);\n\t\tfor (let i = 0; i < trees.topLevelLength; i += 1) {\n\t\t\tconst offsettedId = minor + i;\n\t\t\tsetInNestedMap(refreshers, major, offsettedId, treeCursors[i]);\n\t\t}\n\t});\n\tconst detachConfig: PassConfig = {\n\t\tfunc: detachPass,\n\t\tlatestRevision,\n\t\trefreshers,\n\t\tdetachedFieldIndex,\n\t\tdetachPassRoots,\n\t\tattachPassRoots,\n\t\trootTransfers,\n\t\trootDestructions,\n\t};\n\tprocessBuilds(delta.build, detachConfig, visitor);\n\tprocessGlobal(delta.global, detachConfig, visitor);\n\tprocessRename(delta.rename, detachConfig);\n\tvisitFieldMarks(delta.fields, visitor, detachConfig);\n\tfixedPointVisitOfRoots(visitor, detachPassRoots, detachConfig);\n\ttransferRoots(\n\t\trootTransfers,\n\t\tattachPassRoots,\n\t\tdetachedFieldIndex,\n\t\tvisitor,\n\t\trefreshers,\n\t\tlatestRevision,\n\t);\n\tconst attachConfig: PassConfig = {\n\t\tfunc: attachPass,\n\t\tlatestRevision,\n\t\trefreshers,\n\t\tdetachedFieldIndex,\n\t\tdetachPassRoots,\n\t\tattachPassRoots,\n\t\trootTransfers,\n\t\trootDestructions,\n\t};\n\tvisitFieldMarks(delta.fields, visitor, attachConfig);\n\tfixedPointVisitOfRoots(visitor, attachPassRoots, attachConfig);\n\tcollectDestroys(delta.destroy, attachConfig);\n\tfor (const { id, count } of rootDestructions) {\n\t\tfor (let i = 0; i < count; i += 1) {\n\t\t\tconst offsetId = offsetDetachId(id, i);\n\t\t\tconst root = detachedFieldIndex.getEntry(offsetId);\n\t\t\tconst field = detachedFieldIndex.toFieldKey(root);\n\t\t\tvisitor.destroy(field, 1);\n\t\t\tdetachedFieldIndex.deleteEntry(offsetId);\n\t\t}\n\t}\n}\n\n/**\n * Visits all nodes in `roots` until none are left.\n * This function tolerates entries being added to and removed from `roots` as part of visits.\n * @param visitor - The visitor to visit the roots with.\n * @param roots - The initial set of roots to visit.\n * Individual entries are removed prior to being visited.\n * @param config - The configuration to use for visits.\n */\nfunction fixedPointVisitOfRoots(\n\tvisitor: DeltaVisitor,\n\troots: Map<ForestRootId, Delta.FieldMap>,\n\tconfig: PassConfig,\n): void {\n\twhile (roots.size > 0) {\n\t\tfor (const [root, modifications] of roots) {\n\t\t\troots.delete(root);\n\t\t\tconst field = config.detachedFieldIndex.toFieldKey(root);\n\t\t\tvisitor.enterField(field);\n\t\t\t// Note: each visit may lead to `roots` being populated with new entries or having some entries removed.\n\t\t\tvisitNode(0, modifications, visitor, config);\n\t\t\tvisitor.exitField(field);\n\t\t}\n\t}\n}\n\n/**\n * Transfers roots from one detached field to another.\n * This occurs in the following circumstances:\n * - A changeset moves then removes a node\n * - A changeset restores then moves a node\n * - A changeset restores then removes a node\n * TODO#5481: update the DetachedFieldIndex instead of moving the nodes around.\n *\n * @param rootTransfers - The transfers to perform.\n * @param mapToUpdate - A map to update based on the transfers being performed.\n * @param detachedFieldIndex - The index to update based on the transfers being performed.\n * @param visitor - The visitor to inform of the transfers being performed.\n */\nfunction transferRoots(\n\trootTransfers: readonly Delta.DetachedNodeRename[],\n\tmapToUpdate: Map<ForestRootId, unknown>,\n\tdetachedFieldIndex: DetachedFieldIndex,\n\tvisitor: DeltaVisitor,\n\trefreshers: NestedMap<Major, Minor, ITreeCursorSynchronous>,\n\trevision?: RevisionTag,\n): void {\n\ttype AtomizedNodeRename = Omit<Delta.DetachedNodeRename, \"count\">;\n\tlet nextBatch = rootTransfers.flatMap(({ oldId, newId, count }) => {\n\t\tconst atomized: AtomizedNodeRename[] = [];\n\t\t// It's possible for a detached node to be revived transiently such that it ends up back in the same detached field.\n\t\t// Making such a transfer wouldn't just be inefficient, it would lead us to mistakenly think we have moved all content\n\t\t// out of the source detached field, and would lead us to delete the tree index entry for that source detached field.\n\t\t// This would effectively result in the tree index missing an entry for the detached field.\n\t\t// This if statement prevents that from happening.\n\t\tif (!areDetachedNodeIdsEqual(oldId, newId)) {\n\t\t\tfor (let i = 0; i < count; i += 1) {\n\t\t\t\tatomized.push({ oldId: offsetDetachId(oldId, i), newId: offsetDetachId(newId, i) });\n\t\t\t}\n\t\t}\n\t\treturn atomized;\n\t});\n\twhile (nextBatch.length > 0) {\n\t\tconst delayed: AtomizedNodeRename[] = [];\n\t\tconst priorSize = nextBatch.length;\n\t\tfor (const { oldId, newId } of nextBatch) {\n\t\t\tlet oldRootId = detachedFieldIndex.tryGetEntry(oldId);\n\t\t\tif (oldRootId === undefined) {\n\t\t\t\tconst tree = tryGetFromNestedMap(refreshers, oldId.major, oldId.minor);\n\t\t\t\tif (tree !== undefined) {\n\t\t\t\t\tbuildTrees(oldId, [tree], detachedFieldIndex, revision, visitor);\n\t\t\t\t\toldRootId = detachedFieldIndex.getEntry(oldId);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (oldRootId === undefined) {\n\t\t\t\t// The source field is not populated.\n\t\t\t\t// This can happen when another rename needs to be performed first.\n\t\t\t\tdelayed.push({ oldId, newId });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlet newRootId = detachedFieldIndex.tryGetEntry(newId);\n\t\t\tif (newRootId !== undefined) {\n\t\t\t\t// The destination field is already occupied.\n\t\t\t\t// This can happen when another rename needs to be performed first.\n\t\t\t\tdelayed.push({ oldId, newId });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tnewRootId = detachedFieldIndex.createEntry(newId, revision);\n\t\t\tconst fields = mapToUpdate.get(oldRootId);\n\t\t\tif (fields !== undefined) {\n\t\t\t\tmapToUpdate.delete(oldRootId);\n\t\t\t\tmapToUpdate.set(newRootId, fields);\n\t\t\t}\n\t\t\tconst oldField = detachedFieldIndex.toFieldKey(oldRootId);\n\t\t\tconst newField = detachedFieldIndex.toFieldKey(newRootId);\n\t\t\tvisitor.enterField(oldField);\n\t\t\tvisitor.detach({ start: 0, end: 1 }, newField, newId, false);\n\t\t\tvisitor.exitField(oldField);\n\t\t\tdetachedFieldIndex.deleteEntry(oldId);\n\t\t}\n\t\tassert(delayed.length < priorSize, 0x7cf /* transferRoots should make progress */);\n\t\tnextBatch = delayed;\n\t}\n}\n\n/**\n * Visitor for changes in a delta.\n * Must be freed after use.\n */\nexport interface DeltaVisitor {\n\t/**\n\t * Frees/releases the visitor.\n\t *\n\t * Must be called once the visitor finished traversing the delta for a couple of reasons:\n\t *\n\t * 1. Some visitors, such as those from forests, are put into a special mode while they have a visitor, forbidding some actions (like making more visitors).\n\t *\n\t * 2. Some visitors, such as those from an anchorSet, defer some events for batching purposes until the visitor is freed.\n\t */\n\tfree(): void;\n\t/**\n\t * Creates nodes for the given content in a new detached field.\n\t * @param content - The content to create.\n\t * @param destination - The key for a new detached field.\n\t * A field with this key must not already exist.\n\t */\n\tcreate(content: readonly ITreeCursorSynchronous[], destination: FieldKey): void;\n\t/**\n\t * Recursively destroys the given detached field and all of the nodes within it.\n\t * @param detachedField - The key for the detached field to destroy.\n\t * @param count - The number of nodes being destroyed.\n\t * Expected to match the number of nodes in the detached field being destroyed.\n\t */\n\tdestroy(detachedField: FieldKey, count: number): void;\n\t/**\n\t * Transfers all the nodes from a detached field to the current field.\n\t * @param source - The detached field to transfer the nodes from.\n\t * @param count - The number of nodes being attached.\n\t * Expected to match the number of nodes in the source detached field.\n\t * @param destination - The index at which to attach the nodes.\n\t */\n\tattach(source: FieldKey, count: number, destination: PlaceIndex): void;\n\t/**\n\t * Transfers a range of nodes from the current field to a new detached field.\n\t * @param source - The bounds of the range of nodes to detach.\n\t * @param destination - The key for a new detached field.\n\t * A field with this key must not already exist.\n\t * @param id - The ID assigned to the first detached node as a result of the detach. The other nodes in the detached range are assigned subsequent IDs.\n\t * @param isReplaced - Whether the detached content will be replaced by a later attach.\n\t * This is not guaranteed to be true in all cases where it could be true,\n\t * but it is guaranteed to be true in all cases where a later attach is needed to keep the data compliant with the schema.\n\t */\n\tdetach(\n\t\tsource: Range,\n\t\tdestination: FieldKey,\n\t\tid: Delta.DetachedNodeId,\n\t\tisReplaced: boolean,\n\t): void;\n\n\t/**\n\t * Tells the visitor that it should update its \"current location\" to be the Node at the specified index\n\t * within the Field that is the current \"current location\".\n\t * Future calls to methods of {@link DeltaVisitor} will assume that's the location where their effects are happening.\n\t * @param index - The index (within the Field) of the node that should become the new \"current location\".\n\t *\n\t * @remarks This should only be called when the \"current location\" is a Field.\n\t */\n\tenterNode(index: NodeIndex): void;\n\n\t/**\n\t * Tells the visitor that it should update its \"current location\" to be the Field which contains the Node\n\t * that is the current \"current location\".\n\t * Future calls to methods of {@link DeltaVisitor} will assume that's the location where their effects are happening.\n\t * @param index - The index (within its Field) of the node that is being exited.\n\t *\n\t * @remarks This should only be called when the \"current location\" is a Node.\n\t */\n\texitNode(index: NodeIndex): void;\n\n\t/**\n\t * Tells the visitor that it should update its \"current location\" to be the Field with the specified key,\n\t * within the Node that is the current \"current location\".\n\t * Future calls to methods of {@link DeltaVisitor} will assume that's the location where their effects are happening.\n\t * @param key - The key of the field that should become the new \"current location\".\n\t *\n\t * @remarks This should only be called when the \"current location\" is a Node.\n\t */\n\tenterField(key: FieldKey): void;\n\n\t/**\n\t * Tells the visitor that it should update its \"current location\" to be the Node which contains the Field\n\t * that is the current \"current location\".\n\t * Future calls to methods of {@link DeltaVisitor} will assume that's the location where their effects are happening.\n\t * @param key - The key of the field that is being exited.\n\t *\n\t * @remarks This should only be called when the \"current location\" is a Field.\n\t */\n\texitField(key: FieldKey): void;\n}\n\ninterface PassConfig {\n\treadonly func: Pass;\n\n\t/**\n\t * The latest revision tag associated with the given delta. This is used to keep track\n\t * of when repair data should be garbage collected.\n\t */\n\treadonly latestRevision: RevisionTag | undefined;\n\n\treadonly detachedFieldIndex: DetachedFieldIndex;\n\t/**\n\t * A mapping between forest root id and trees that represent refresher data. Each entry is only\n\t * created in the forest once needed.\n\t */\n\treadonly refreshers: NestedMap<Major, Minor, ITreeCursorSynchronous>;\n\t/**\n\t * Nested changes on roots that need to be visited as part of the detach pass.\n\t * Each entry is removed when its associated changes are visited.\n\t */\n\treadonly detachPassRoots: Map<ForestRootId, Delta.FieldMap>;\n\t/**\n\t * Nested changes on roots that need to be visited as part of the attach pass.\n\t * Each entry is removed when its associated changes are visited.\n\t * Some of these roots will attached during the attach pass, in which case the nested changes are visited after\n\t * the node is attached.\n\t * Some of these nodes will never be attached, in which case we visit them in their detached fields at the end of\n\t * the attach pass. Note that such a visit might lead to more nodes being attached, including nodes were visited as\n\t * roots.\n\t */\n\treadonly attachPassRoots: Map<ForestRootId, Delta.FieldMap>;\n\t/**\n\t * Represents transfers of roots from one detached field to another.\n\t */\n\treadonly rootTransfers: Delta.DetachedNodeRename[];\n\t/**\n\t * Represents roots that need to be destroyed.\n\t * Collected as part of the detach pass.\n\t * Carried out at the end of the attach pass.\n\t */\n\treadonly rootDestructions: Delta.DetachedNodeDestruction[];\n}\n\ntype Pass = (delta: Delta.FieldChanges, visitor: DeltaVisitor, config: PassConfig) => void;\n\nfunction visitFieldMarks(\n\tfields: Delta.FieldMap | undefined,\n\tvisitor: DeltaVisitor,\n\tconfig: PassConfig,\n): void {\n\tif (fields !== undefined) {\n\t\tfor (const [key, field] of fields) {\n\t\t\tvisitor.enterField(key);\n\t\t\tconfig.func(field, visitor, config);\n\t\t\tvisitor.exitField(key);\n\t\t}\n\t}\n}\n\nfunction visitNode(\n\tindex: number,\n\tfields: Delta.FieldMap | undefined,\n\tvisitor: DeltaVisitor,\n\tconfig: PassConfig,\n): void {\n\tif (fields !== undefined) {\n\t\tvisitor.enterNode(index);\n\t\tvisitFieldMarks(fields, visitor, config);\n\t\tvisitor.exitNode(index);\n\t}\n}\n\n/**\n * Performs the following:\n * - Collects all roots that may need an attach pass\n * - Executes detaches (bottom-up)\n */\nfunction detachPass(\n\tfieldChanges: Delta.FieldChanges,\n\tvisitor: DeltaVisitor,\n\tconfig: PassConfig,\n): void {\n\tlet index = 0;\n\tfor (const mark of fieldChanges) {\n\t\tif (mark.fields !== undefined) {\n\t\t\tassert(\n\t\t\t\tmark.attach === undefined || mark.detach !== undefined,\n\t\t\t\t0x7d0 /* Invalid nested changes on an additive mark */,\n\t\t\t);\n\t\t\tvisitNode(index, mark.fields, visitor, config);\n\t\t}\n\t\tif (mark.detach !== undefined) {\n\t\t\tfor (let i = 0; i < mark.count; i += 1) {\n\t\t\t\tconst id = offsetDetachId(mark.detach, i);\n\t\t\t\tconst root = config.detachedFieldIndex.createEntry(id, config.latestRevision);\n\t\t\t\tif (mark.fields !== undefined) {\n\t\t\t\t\tconfig.attachPassRoots.set(root, mark.fields);\n\t\t\t\t}\n\t\t\t\tconst field = config.detachedFieldIndex.toFieldKey(root);\n\t\t\t\tvisitor.detach({ start: index, end: index + 1 }, field, id, mark.attach !== undefined);\n\t\t\t}\n\t\t}\n\t\tif (mark.detach === undefined && mark.attach === undefined) {\n\t\t\tindex += mark.count;\n\t\t}\n\t}\n}\n\nfunction buildTrees(\n\tid: Delta.DetachedNodeId,\n\ttrees: readonly ITreeCursorSynchronous[],\n\tdetachedFieldIndex: DetachedFieldIndex,\n\tlatestRevision: RevisionTag | undefined,\n\tvisitor: DeltaVisitor,\n): void {\n\tfor (const [i, tree] of trees.entries()) {\n\t\tconst offsettedId = offsetDetachId(id, i);\n\t\tlet root = detachedFieldIndex.tryGetEntry(offsettedId);\n\t\tassert(root === undefined, 0x929 /* Unable to build tree that already exists */);\n\t\troot = detachedFieldIndex.createEntry(offsettedId, latestRevision);\n\t\tconst field = detachedFieldIndex.toFieldKey(root);\n\t\tvisitor.create([tree], field);\n\t}\n}\n\nfunction processBuilds(\n\tbuilds: readonly Delta.DetachedNodeBuild[] | undefined,\n\tconfig: PassConfig,\n\tvisitor: DeltaVisitor,\n): void {\n\tif (builds !== undefined) {\n\t\tfor (const { id, trees } of builds) {\n\t\t\tbuildTrees(\n\t\t\t\tid,\n\t\t\t\tnodeCursorsFromChunk(trees),\n\t\t\t\tconfig.detachedFieldIndex,\n\t\t\t\tconfig.latestRevision,\n\t\t\t\tvisitor,\n\t\t\t);\n\t\t}\n\t}\n}\n\nfunction processGlobal(\n\tglobal: readonly Delta.DetachedNodeChanges[] | undefined,\n\tconfig: PassConfig,\n\tvisitor: DeltaVisitor,\n): void {\n\tif (global !== undefined) {\n\t\tfor (const { id, fields } of global) {\n\t\t\tlet root = config.detachedFieldIndex.tryGetEntry(id);\n\t\t\tif (root === undefined) {\n\t\t\t\tconst tree = tryGetFromNestedMap(config.refreshers, id.major, id.minor);\n\t\t\t\tassert(tree !== undefined, 0x928 /* refresher data not found */);\n\t\t\t\tbuildTrees(id, [tree], config.detachedFieldIndex, config.latestRevision, visitor);\n\t\t\t\troot = config.detachedFieldIndex.getEntry(id);\n\t\t\t}\n\t\t\t// the revision is updated for any refresher data included in the delta that is used\n\t\t\tconfig.detachedFieldIndex.updateLatestRevision(id, config.latestRevision);\n\t\t\tconfig.detachPassRoots.set(root, fields);\n\t\t\tconfig.attachPassRoots.set(root, fields);\n\t\t}\n\t}\n}\n\nfunction processRename(\n\trename: readonly Delta.DetachedNodeRename[] | undefined,\n\tconfig: PassConfig,\n): void {\n\tif (rename !== undefined) {\n\t\tconfig.rootTransfers.push(...rename);\n\t}\n}\n\nfunction collectDestroys(\n\tdestroys: readonly Delta.DetachedNodeDestruction[] | undefined,\n\tconfig: PassConfig,\n): void {\n\tif (destroys !== undefined) {\n\t\tconfig.rootDestructions.push(...destroys);\n\t}\n}\n\n/**\n * Preforms the following:\n * - Executes attaches (top-down) applying nested changes on the attached nodes\n */\nfunction attachPass(\n\tfieldChanges: Delta.FieldChanges,\n\tvisitor: DeltaVisitor,\n\tconfig: PassConfig,\n): void {\n\tlet index = 0;\n\tfor (const mark of fieldChanges) {\n\t\tif (mark.attach !== undefined) {\n\t\t\tfor (let i = 0; i < mark.count; i += 1) {\n\t\t\t\tconst offsetAttachId = offsetDetachId(mark.attach, i);\n\t\t\t\tlet sourceRoot = config.detachedFieldIndex.tryGetEntry(offsetAttachId);\n\t\t\t\tif (sourceRoot === undefined) {\n\t\t\t\t\tconst tree = tryGetFromNestedMap(\n\t\t\t\t\t\tconfig.refreshers,\n\t\t\t\t\t\toffsetAttachId.major,\n\t\t\t\t\t\toffsetAttachId.minor,\n\t\t\t\t\t);\n\t\t\t\t\tassert(tree !== undefined, 0x92a /* refresher data not found */);\n\t\t\t\t\tbuildTrees(\n\t\t\t\t\t\toffsetAttachId,\n\t\t\t\t\t\t[tree],\n\t\t\t\t\t\tconfig.detachedFieldIndex,\n\t\t\t\t\t\tconfig.latestRevision,\n\t\t\t\t\t\tvisitor,\n\t\t\t\t\t);\n\t\t\t\t\tsourceRoot = config.detachedFieldIndex.getEntry(offsetAttachId);\n\t\t\t\t}\n\t\t\t\tconst sourceField = config.detachedFieldIndex.toFieldKey(sourceRoot);\n\t\t\t\tconst offsetIndex = index + i;\n\t\t\t\tvisitor.attach(sourceField, 1, offsetIndex);\n\t\t\t\tconfig.detachedFieldIndex.deleteEntry(offsetAttachId);\n\t\t\t\tconst fields = config.attachPassRoots.get(sourceRoot);\n\t\t\t\tif (fields !== undefined) {\n\t\t\t\t\tconfig.attachPassRoots.delete(sourceRoot);\n\t\t\t\t\tvisitNode(offsetIndex, fields, visitor, config);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (mark.detach === undefined && mark.fields !== undefined) {\n\t\t\tvisitNode(index, mark.fields, visitor, config);\n\t\t}\n\t\tif (mark.detach === undefined || mark.attach !== undefined) {\n\t\t\tindex += mark.count;\n\t\t}\n\t}\n}\n\n/**\n * Converts a chunk of trees into an array of cursors.\n *\n * TODO: Update the visitDelta logic and downstream APIs to avoid splitting up sequences into individual nodes.\n */\nfunction nodeCursorsFromChunk(trees: TreeChunk): ITreeCursorSynchronous[] {\n\treturn mapCursorField(trees.cursor(), (c) => c.fork());\n}\n"]}
1
+ {"version":3,"file":"visitDelta.js","sourceRoot":"","sources":["../../../src/core/tree/visitDelta.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAE7D,kDAA0F;AAI1F,2CAA0E;AAE1E,iDAAyE;AAOzE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CACzB,KAAiB,EACjB,OAAqB,EACrB,kBAAsC,EACtC,cAAuC;IAEvC,MAAM,eAAe,GAAsC,IAAI,GAAG,EAAE,CAAC;IACrE,MAAM,eAAe,GAAsC,IAAI,GAAG,EAAE,CAAC;IACrE,MAAM,aAAa,GAA+B,EAAE,CAAC;IACrD,MAAM,gBAAgB,GAAoC,EAAE,CAAC;IAC7D,MAAM,UAAU,GAAoD,IAAI,GAAG,EAAE,CAAC;IAC9E,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;QAC7D,MAAM,WAAW,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;QAChD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YAClD,MAAM,WAAW,GAAG,KAAK,GAAG,CAAC,CAAC;YAC9B,IAAA,yBAAc,EAAC,UAAU,EAAE,KAAK,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AC;AAED;;;;GAIG;AACH,SAAS,oBAAoB,CAAC,KAAgB;IAC7C,OAAO,IAAA,0BAAc,EAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AACxD,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 { type NestedMap, setInNestedMap, tryGetFromNestedMap } from \"../../util/index.js\";\n\nimport type { FieldKey } from \"../schema-stored/index.js\";\n\nimport { mapCursorField, type ITreeCursorSynchronous } from \"./cursor.js\";\nimport type * as Delta from \"./delta.js\";\nimport { areDetachedNodeIdsEqual, offsetDetachId } from \"./deltaUtil.js\";\nimport type { DetachedFieldIndex } from \"./detachedFieldIndex.js\";\nimport type { ForestRootId, Major, Minor } from \"./detachedFieldIndexTypes.js\";\nimport type { NodeIndex, PlaceIndex, Range } from \"./pathTree.js\";\nimport type { RevisionTag } from \"../rebase/index.js\";\nimport type { TreeChunk } from \"./chunk.js\";\n\n/**\n * Implementation notes:\n *\n * The visit is organized into four phases:\n * 1. a detach pass\n * 2. root transfers\n * 3. an attach pass\n * 4. root destructions\n *\n * The core idea is that before content can be attached, it must first exist and be in a detached field.\n *\n * While the detach pass ensures that nodes to be attached are in a detached state, it does not guarantee that they\n * reside in the correct detached field. That is the responsibility of the root transfers phase.\n *\n * The attach phase carries out attaches.\n *\n * After the attach phase, roots destruction is carried out.\n * This needs to happen last to allow modifications to detached roots to be applied before they are destroyed.\n *\n * The details of the delta visit algorithm can impact how/when events are emitted by the objects that own the visitors.\n * For example, as of 2024-03-27, the subtreeChanged event of an AnchorNode is emitted when exiting a node during a\n * delta visit, and thus the two-pass nature of the algorithm means the event fires twice for any given change.\n */\n\n/**\n * Crawls the given `delta`, calling `visitor`'s callback for each change encountered.\n * Each successive call to the visitor callbacks assumes that the change described by earlier calls have been applied\n * to the document tree. For example, for a change that removes the first and third node of a field, the visitor calls\n * will first call detach with a range from indices 0 to 1 then call detach with a range from indices 1 to 2.\n *\n * @param delta - The delta to be crawled.\n * @param visitor - The object to notify of the changes encountered.\n * @param detachedFieldIndex - Index responsible for keeping track of the existing detached fields.\n * @param latestRevision - The latest revision tag associated with this delta.\n */\nexport function visitDelta(\n\tdelta: Delta.Root,\n\tvisitor: DeltaVisitor,\n\tdetachedFieldIndex: DetachedFieldIndex,\n\tlatestRevision: RevisionTag | undefined,\n): void {\n\tconst detachPassRoots: Map<ForestRootId, Delta.FieldMap> = new Map();\n\tconst attachPassRoots: Map<ForestRootId, Delta.FieldMap> = new Map();\n\tconst rootTransfers: Delta.DetachedNodeRename[] = [];\n\tconst rootDestructions: Delta.DetachedNodeDestruction[] = [];\n\tconst refreshers: NestedMap<Major, Minor, ITreeCursorSynchronous> = new Map();\n\tdelta.refreshers?.forEach(({ id: { major, minor }, trees }) => {\n\t\tconst treeCursors = nodeCursorsFromChunk(trees);\n\t\tfor (let i = 0; i < trees.topLevelLength; i += 1) {\n\t\t\tconst offsettedId = minor + i;\n\t\t\tsetInNestedMap(refreshers, major, offsettedId, treeCursors[i]);\n\t\t}\n\t});\n\tconst detachConfig: PassConfig = {\n\t\tfunc: detachPass,\n\t\tlatestRevision,\n\t\trefreshers,\n\t\tdetachedFieldIndex,\n\t\tdetachPassRoots,\n\t\tattachPassRoots,\n\t\trootTransfers,\n\t\trootDestructions,\n\t};\n\tprocessBuilds(delta.build, detachConfig, visitor);\n\tprocessGlobal(delta.global, detachConfig, visitor);\n\tprocessRename(delta.rename, detachConfig);\n\tvisitFieldMarks(delta.fields, visitor, detachConfig);\n\tfixedPointVisitOfRoots(visitor, detachPassRoots, detachConfig);\n\ttransferRoots(\n\t\trootTransfers,\n\t\tattachPassRoots,\n\t\tdetachedFieldIndex,\n\t\tvisitor,\n\t\trefreshers,\n\t\tlatestRevision,\n\t);\n\tconst attachConfig: PassConfig = {\n\t\tfunc: attachPass,\n\t\tlatestRevision,\n\t\trefreshers,\n\t\tdetachedFieldIndex,\n\t\tdetachPassRoots,\n\t\tattachPassRoots,\n\t\trootTransfers,\n\t\trootDestructions,\n\t};\n\tvisitFieldMarks(delta.fields, visitor, attachConfig);\n\tfixedPointVisitOfRoots(visitor, attachPassRoots, attachConfig);\n\tcollectDestroys(delta.destroy, attachConfig);\n\tfor (const { id, count } of rootDestructions) {\n\t\tfor (let i = 0; i < count; i += 1) {\n\t\t\tconst offsetId = offsetDetachId(id, i);\n\t\t\tconst root = detachedFieldIndex.getEntry(offsetId);\n\t\t\tconst field = detachedFieldIndex.toFieldKey(root);\n\t\t\tvisitor.destroy(field, 1);\n\t\t\tdetachedFieldIndex.deleteEntry(offsetId);\n\t\t}\n\t}\n}\n\n/**\n * Visits all nodes in `roots` until none are left.\n * This function tolerates entries being added to and removed from `roots` as part of visits.\n * @param visitor - The visitor to visit the roots with.\n * @param roots - The initial set of roots to visit.\n * Individual entries are removed prior to being visited.\n * @param config - The configuration to use for visits.\n */\nfunction fixedPointVisitOfRoots(\n\tvisitor: DeltaVisitor,\n\troots: Map<ForestRootId, Delta.FieldMap>,\n\tconfig: PassConfig,\n): void {\n\twhile (roots.size > 0) {\n\t\tfor (const [root, modifications] of roots) {\n\t\t\troots.delete(root);\n\t\t\tconst field = config.detachedFieldIndex.toFieldKey(root);\n\t\t\tvisitor.enterField(field);\n\t\t\t// Note: each visit may lead to `roots` being populated with new entries or having some entries removed.\n\t\t\tvisitNode(0, modifications, visitor, config);\n\t\t\tvisitor.exitField(field);\n\t\t}\n\t}\n}\n\n/**\n * Transfers roots from one detached field to another.\n * This occurs in the following circumstances:\n * - A changeset moves then removes a node\n * - A changeset restores then moves a node\n * - A changeset restores then removes a node\n * TODO#5481: update the DetachedFieldIndex instead of moving the nodes around.\n *\n * @param rootTransfers - The transfers to perform.\n * @param mapToUpdate - A map to update based on the transfers being performed.\n * @param detachedFieldIndex - The index to update based on the transfers being performed.\n * @param visitor - The visitor to inform of the transfers being performed.\n */\nfunction transferRoots(\n\trootTransfers: readonly Delta.DetachedNodeRename[],\n\tmapToUpdate: Map<ForestRootId, unknown>,\n\tdetachedFieldIndex: DetachedFieldIndex,\n\tvisitor: DeltaVisitor,\n\trefreshers: NestedMap<Major, Minor, ITreeCursorSynchronous>,\n\trevision?: RevisionTag,\n): void {\n\ttype AtomizedNodeRename = Omit<Delta.DetachedNodeRename, \"count\">;\n\tlet nextBatch = rootTransfers.flatMap(({ oldId, newId, count }) => {\n\t\tconst atomized: AtomizedNodeRename[] = [];\n\t\t// It's possible for a detached node to be revived transiently such that it ends up back in the same detached field.\n\t\t// Making such a transfer wouldn't just be inefficient, it would lead us to mistakenly think we have moved all content\n\t\t// out of the source detached field, and would lead us to delete the tree index entry for that source detached field.\n\t\t// This would effectively result in the tree index missing an entry for the detached field.\n\t\t// This if statement prevents that from happening.\n\t\tif (!areDetachedNodeIdsEqual(oldId, newId)) {\n\t\t\tfor (let i = 0; i < count; i += 1) {\n\t\t\t\tatomized.push({ oldId: offsetDetachId(oldId, i), newId: offsetDetachId(newId, i) });\n\t\t\t}\n\t\t}\n\t\treturn atomized;\n\t});\n\twhile (nextBatch.length > 0) {\n\t\tconst delayed: AtomizedNodeRename[] = [];\n\t\tconst priorSize = nextBatch.length;\n\t\tfor (const { oldId, newId } of nextBatch) {\n\t\t\tlet oldRootId = detachedFieldIndex.tryGetEntry(oldId);\n\t\t\tif (oldRootId === undefined) {\n\t\t\t\tconst tree = tryGetFromNestedMap(refreshers, oldId.major, oldId.minor);\n\t\t\t\tif (tree !== undefined) {\n\t\t\t\t\tbuildTrees(oldId, [tree], detachedFieldIndex, revision, visitor);\n\t\t\t\t\toldRootId = detachedFieldIndex.getEntry(oldId);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (oldRootId === undefined) {\n\t\t\t\t// The source field is not populated.\n\t\t\t\t// This can happen when another rename needs to be performed first.\n\t\t\t\tdelayed.push({ oldId, newId });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlet newRootId = detachedFieldIndex.tryGetEntry(newId);\n\t\t\tif (newRootId !== undefined) {\n\t\t\t\t// The destination field is already occupied.\n\t\t\t\t// This can happen when another rename needs to be performed first.\n\t\t\t\tdelayed.push({ oldId, newId });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tnewRootId = detachedFieldIndex.createEntry(newId, revision);\n\t\t\tconst fields = mapToUpdate.get(oldRootId);\n\t\t\tif (fields !== undefined) {\n\t\t\t\tmapToUpdate.delete(oldRootId);\n\t\t\t\tmapToUpdate.set(newRootId, fields);\n\t\t\t}\n\t\t\tconst oldField = detachedFieldIndex.toFieldKey(oldRootId);\n\t\t\tconst newField = detachedFieldIndex.toFieldKey(newRootId);\n\t\t\tvisitor.enterField(oldField);\n\t\t\tvisitor.detach({ start: 0, end: 1 }, newField, newId, false);\n\t\t\tvisitor.exitField(oldField);\n\t\t\tdetachedFieldIndex.deleteEntry(oldId);\n\t\t}\n\t\tassert(delayed.length < priorSize, 0x7cf /* transferRoots should make progress */);\n\t\tnextBatch = delayed;\n\t}\n}\n\n/**\n * Visitor for changes in a delta.\n * Must be freed after use.\n */\nexport interface DeltaVisitor {\n\t/**\n\t * Frees/releases the visitor.\n\t *\n\t * Must be called once the visitor finished traversing the delta for a couple of reasons:\n\t *\n\t * 1. Some visitors, such as those from forests, are put into a special mode while they have a visitor, forbidding some actions (like making more visitors).\n\t *\n\t * 2. Some visitors, such as those from an anchorSet, defer some events for batching purposes until the visitor is freed.\n\t */\n\tfree(): void;\n\t/**\n\t * Creates nodes for the given content in a new detached field.\n\t * @param content - The content to create.\n\t * @param destination - The key for a new detached field.\n\t * A field with this key must not already exist.\n\t */\n\tcreate(content: readonly ITreeCursorSynchronous[], destination: FieldKey): void;\n\t/**\n\t * Recursively destroys the given detached field and all of the nodes within it.\n\t * @param detachedField - The key for the detached field to destroy.\n\t * @param count - The number of nodes being destroyed.\n\t * Expected to match the number of nodes in the detached field being destroyed.\n\t */\n\tdestroy(detachedField: FieldKey, count: number): void;\n\t/**\n\t * Transfers all the nodes from a detached field to the current field.\n\t * @param source - The detached field to transfer the nodes from.\n\t * @param count - The number of nodes being attached.\n\t * Expected to match the number of nodes in the source detached field.\n\t * @param destination - The index at which to attach the nodes.\n\t */\n\tattach(source: FieldKey, count: number, destination: PlaceIndex): void;\n\t/**\n\t * Transfers a range of nodes from the current field to a new detached field.\n\t * @param source - The bounds of the range of nodes to detach.\n\t * @param destination - The key for a new detached field.\n\t * A field with this key must not already exist.\n\t * @param id - The ID assigned to the first detached node as a result of the detach. The other nodes in the detached range are assigned subsequent IDs.\n\t * @param isReplaced - Whether the detached content will be replaced by a later attach.\n\t * This is not guaranteed to be true in all cases where it could be true,\n\t * but it is guaranteed to be true in all cases where a later attach is needed to keep the data compliant with the schema.\n\t */\n\tdetach(\n\t\tsource: Range,\n\t\tdestination: FieldKey,\n\t\tid: Delta.DetachedNodeId,\n\t\tisReplaced: boolean,\n\t): void;\n\n\t/**\n\t * Tells the visitor that it should update its \"current location\" to be the Node at the specified index\n\t * within the Field that is the current \"current location\".\n\t * Future calls to methods of {@link DeltaVisitor} will assume that's the location where their effects are happening.\n\t * @param index - The index (within the Field) of the node that should become the new \"current location\".\n\t *\n\t * @remarks This should only be called when the \"current location\" is a Field.\n\t */\n\tenterNode(index: NodeIndex): void;\n\n\t/**\n\t * Tells the visitor that it should update its \"current location\" to be the Field which contains the Node\n\t * that is the current \"current location\".\n\t * Future calls to methods of {@link DeltaVisitor} will assume that's the location where their effects are happening.\n\t * @param index - The index (within its Field) of the node that is being exited.\n\t *\n\t * @remarks This should only be called when the \"current location\" is a Node.\n\t */\n\texitNode(index: NodeIndex): void;\n\n\t/**\n\t * Tells the visitor that it should update its \"current location\" to be the Field with the specified key,\n\t * within the Node that is the current \"current location\".\n\t * Future calls to methods of {@link DeltaVisitor} will assume that's the location where their effects are happening.\n\t * @param key - The key of the field that should become the new \"current location\".\n\t *\n\t * @remarks This should only be called when the \"current location\" is a Node.\n\t */\n\tenterField(key: FieldKey): void;\n\n\t/**\n\t * Tells the visitor that it should update its \"current location\" to be the Node which contains the Field\n\t * that is the current \"current location\".\n\t * Future calls to methods of {@link DeltaVisitor} will assume that's the location where their effects are happening.\n\t * @param key - The key of the field that is being exited.\n\t *\n\t * @remarks This should only be called when the \"current location\" is a Field.\n\t */\n\texitField(key: FieldKey): void;\n}\n\ninterface PassConfig {\n\treadonly func: Pass;\n\n\t/**\n\t * The latest revision tag associated with the given delta. This is used to keep track\n\t * of when repair data should be garbage collected.\n\t */\n\treadonly latestRevision: RevisionTag | undefined;\n\n\treadonly detachedFieldIndex: DetachedFieldIndex;\n\t/**\n\t * A mapping between forest root id and trees that represent refresher data. Each entry is only\n\t * created in the forest once needed.\n\t */\n\treadonly refreshers: NestedMap<Major, Minor, ITreeCursorSynchronous>;\n\t/**\n\t * Nested changes on roots that need to be visited as part of the detach pass.\n\t * Each entry is removed when its associated changes are visited.\n\t */\n\treadonly detachPassRoots: Map<ForestRootId, Delta.FieldMap>;\n\t/**\n\t * Nested changes on roots that need to be visited as part of the attach pass.\n\t * Each entry is removed when its associated changes are visited.\n\t * Some of these roots will attached during the attach pass, in which case the nested changes are visited after\n\t * the node is attached.\n\t * Some of these nodes will never be attached, in which case we visit them in their detached fields at the end of\n\t * the attach pass. Note that such a visit might lead to more nodes being attached, including nodes were visited as\n\t * roots.\n\t */\n\treadonly attachPassRoots: Map<ForestRootId, Delta.FieldMap>;\n\t/**\n\t * Represents transfers of roots from one detached field to another.\n\t */\n\treadonly rootTransfers: Delta.DetachedNodeRename[];\n\t/**\n\t * Represents roots that need to be destroyed.\n\t * Collected as part of the detach pass.\n\t * Carried out at the end of the attach pass.\n\t */\n\treadonly rootDestructions: Delta.DetachedNodeDestruction[];\n}\n\ntype Pass = (delta: Delta.FieldChanges, visitor: DeltaVisitor, config: PassConfig) => void;\n\nfunction visitFieldMarks(\n\tfields: Delta.FieldMap | undefined,\n\tvisitor: DeltaVisitor,\n\tconfig: PassConfig,\n): void {\n\tif (fields !== undefined) {\n\t\tfor (const [key, field] of fields) {\n\t\t\tvisitor.enterField(key);\n\t\t\tconfig.func(field, visitor, config);\n\t\t\tvisitor.exitField(key);\n\t\t}\n\t}\n}\n\nfunction visitNode(\n\tindex: number,\n\tfields: Delta.FieldMap | undefined,\n\tvisitor: DeltaVisitor,\n\tconfig: PassConfig,\n): void {\n\tif (fields !== undefined) {\n\t\tvisitor.enterNode(index);\n\t\tvisitFieldMarks(fields, visitor, config);\n\t\tvisitor.exitNode(index);\n\t}\n}\n\n/**\n * Performs the following:\n * - Collects all roots that may need an attach pass\n * - Executes detaches (bottom-up)\n */\nfunction detachPass(\n\tfieldChanges: Delta.FieldChanges,\n\tvisitor: DeltaVisitor,\n\tconfig: PassConfig,\n): void {\n\tlet index = 0;\n\tfor (const mark of fieldChanges) {\n\t\tif (mark.fields !== undefined) {\n\t\t\tassert(\n\t\t\t\tmark.attach === undefined || mark.detach !== undefined,\n\t\t\t\t0x7d0 /* Invalid nested changes on an additive mark */,\n\t\t\t);\n\t\t\tvisitNode(index, mark.fields, visitor, config);\n\t\t}\n\t\tif (mark.detach !== undefined) {\n\t\t\tfor (let i = 0; i < mark.count; i += 1) {\n\t\t\t\tconst id = offsetDetachId(mark.detach, i);\n\t\t\t\tconst root = config.detachedFieldIndex.createEntry(id, config.latestRevision);\n\t\t\t\tif (mark.fields !== undefined) {\n\t\t\t\t\tconfig.attachPassRoots.set(root, mark.fields);\n\t\t\t\t}\n\t\t\t\tconst field = config.detachedFieldIndex.toFieldKey(root);\n\t\t\t\tvisitor.detach({ start: index, end: index + 1 }, field, id, mark.attach !== undefined);\n\t\t\t}\n\t\t}\n\t\tif (mark.detach === undefined && mark.attach === undefined) {\n\t\t\tindex += mark.count;\n\t\t}\n\t}\n}\n\nfunction buildTrees(\n\tid: Delta.DetachedNodeId,\n\ttrees: readonly ITreeCursorSynchronous[],\n\tdetachedFieldIndex: DetachedFieldIndex,\n\tlatestRevision: RevisionTag | undefined,\n\tvisitor: DeltaVisitor,\n): void {\n\tfor (const [i, tree] of trees.entries()) {\n\t\tconst offsettedId = offsetDetachId(id, i);\n\t\tlet root = detachedFieldIndex.tryGetEntry(offsettedId);\n\t\tassert(root === undefined, 0x929 /* Unable to build tree that already exists */);\n\t\troot = detachedFieldIndex.createEntry(offsettedId, latestRevision);\n\t\tconst field = detachedFieldIndex.toFieldKey(root);\n\t\tvisitor.create([tree], field);\n\t}\n}\n\nfunction processBuilds(\n\tbuilds: readonly Delta.DetachedNodeBuild[] | undefined,\n\tconfig: PassConfig,\n\tvisitor: DeltaVisitor,\n): void {\n\tif (builds !== undefined) {\n\t\tfor (const { id, trees } of builds) {\n\t\t\tbuildTrees(\n\t\t\t\tid,\n\t\t\t\tnodeCursorsFromChunk(trees),\n\t\t\t\tconfig.detachedFieldIndex,\n\t\t\t\tconfig.latestRevision,\n\t\t\t\tvisitor,\n\t\t\t);\n\t\t}\n\t}\n}\n\nfunction processGlobal(\n\tglobal: readonly Delta.DetachedNodeChanges[] | undefined,\n\tconfig: PassConfig,\n\tvisitor: DeltaVisitor,\n): void {\n\tif (global !== undefined) {\n\t\tfor (const { id, fields } of global) {\n\t\t\tlet root = config.detachedFieldIndex.tryGetEntry(id);\n\t\t\tif (root === undefined) {\n\t\t\t\tconst tree = tryGetFromNestedMap(config.refreshers, id.major, id.minor);\n\t\t\t\tassert(tree !== undefined, 0x928 /* refresher data not found */);\n\t\t\t\tbuildTrees(id, [tree], config.detachedFieldIndex, config.latestRevision, visitor);\n\t\t\t\troot = config.detachedFieldIndex.getEntry(id);\n\t\t\t}\n\t\t\t// the revision is updated for any refresher data included in the delta that is used\n\t\t\tconfig.detachedFieldIndex.updateLatestRevision(id, config.latestRevision);\n\t\t\tconfig.detachPassRoots.set(root, fields);\n\t\t\tconfig.attachPassRoots.set(root, fields);\n\t\t}\n\t}\n}\n\nfunction processRename(\n\trename: readonly Delta.DetachedNodeRename[] | undefined,\n\tconfig: PassConfig,\n): void {\n\tif (rename !== undefined) {\n\t\tconfig.rootTransfers.push(...rename);\n\t}\n}\n\nfunction collectDestroys(\n\tdestroys: readonly Delta.DetachedNodeDestruction[] | undefined,\n\tconfig: PassConfig,\n): void {\n\tif (destroys !== undefined) {\n\t\tconfig.rootDestructions.push(...destroys);\n\t}\n}\n\n/**\n * Preforms the following:\n * - Executes attaches (top-down) applying nested changes on the attached nodes\n */\nfunction attachPass(\n\tfieldChanges: Delta.FieldChanges,\n\tvisitor: DeltaVisitor,\n\tconfig: PassConfig,\n): void {\n\tlet index = 0;\n\tfor (const mark of fieldChanges) {\n\t\tif (mark.attach !== undefined) {\n\t\t\tfor (let i = 0; i < mark.count; i += 1) {\n\t\t\t\tconst offsetAttachId = offsetDetachId(mark.attach, i);\n\t\t\t\tlet sourceRoot = config.detachedFieldIndex.tryGetEntry(offsetAttachId);\n\t\t\t\tif (sourceRoot === undefined) {\n\t\t\t\t\tconst tree = tryGetFromNestedMap(\n\t\t\t\t\t\tconfig.refreshers,\n\t\t\t\t\t\toffsetAttachId.major,\n\t\t\t\t\t\toffsetAttachId.minor,\n\t\t\t\t\t);\n\t\t\t\t\tassert(tree !== undefined, 0x92a /* refresher data not found */);\n\t\t\t\t\tbuildTrees(\n\t\t\t\t\t\toffsetAttachId,\n\t\t\t\t\t\t[tree],\n\t\t\t\t\t\tconfig.detachedFieldIndex,\n\t\t\t\t\t\tconfig.latestRevision,\n\t\t\t\t\t\tvisitor,\n\t\t\t\t\t);\n\t\t\t\t\tsourceRoot = config.detachedFieldIndex.getEntry(offsetAttachId);\n\t\t\t\t}\n\t\t\t\tconst sourceField = config.detachedFieldIndex.toFieldKey(sourceRoot);\n\t\t\t\tconst offsetIndex = index + i;\n\t\t\t\tvisitor.attach(sourceField, 1, offsetIndex);\n\t\t\t\tconfig.detachedFieldIndex.deleteEntry(offsetAttachId);\n\t\t\t\tconst fields = config.attachPassRoots.get(sourceRoot);\n\t\t\t\tif (fields !== undefined) {\n\t\t\t\t\tconfig.attachPassRoots.delete(sourceRoot);\n\t\t\t\t\tvisitNode(offsetIndex, fields, visitor, config);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (mark.detach === undefined && mark.fields !== undefined) {\n\t\t\tvisitNode(index, mark.fields, visitor, config);\n\t\t}\n\t\tif (mark.detach === undefined || mark.attach !== undefined) {\n\t\t\tindex += mark.count;\n\t\t}\n\t}\n}\n\n/**\n * Converts a chunk of trees into an array of cursors.\n *\n * TODO: Update the visitDelta logic and downstream APIs to avoid splitting up sequences into individual nodes.\n */\nfunction nodeCursorsFromChunk(trees: TreeChunk): ITreeCursorSynchronous[] {\n\treturn mapCursorField(trees.cursor(), (c) => c.fork());\n}\n"]}
@@ -7,4 +7,5 @@ export { type TreeChunk, dummyRoot } from "../../core/index.js";
7
7
  export { chunkTree, defaultChunkPolicy, makeTreeChunker, type IChunker, chunkFieldSingle, chunkField, } from "./chunkTree.js";
8
8
  export { buildChunkedForest } from "./chunkedForest.js";
9
9
  export { EncodedFieldBatch, type FieldBatch, type FieldBatchCodec, makeFieldBatchCodec, type FieldBatchEncodingContext, fluidVersionToFieldBatchCodecWriteVersion, } from "./codec/index.js";
10
+ export { emptyChunk } from "./emptyChunk.js";
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/chunked-forest/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,KAAK,SAAS,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EACN,SAAS,EACT,kBAAkB,EAClB,eAAe,EACf,KAAK,QAAQ,EACb,gBAAgB,EAChB,UAAU,GACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EACN,iBAAiB,EACjB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,mBAAmB,EACnB,KAAK,yBAAyB,EAC9B,yCAAyC,GACzC,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/chunked-forest/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,KAAK,SAAS,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EACN,SAAS,EACT,kBAAkB,EAClB,eAAe,EACf,KAAK,QAAQ,EACb,gBAAgB,EAChB,UAAU,GACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EACN,iBAAiB,EACjB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,mBAAmB,EACnB,KAAK,yBAAyB,EAC9B,yCAAyC,GACzC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
@@ -4,7 +4,7 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.fluidVersionToFieldBatchCodecWriteVersion = exports.makeFieldBatchCodec = exports.EncodedFieldBatch = exports.buildChunkedForest = exports.chunkField = exports.chunkFieldSingle = exports.makeTreeChunker = exports.defaultChunkPolicy = exports.chunkTree = exports.dummyRoot = exports.ChunkShape = exports.uniformChunk = void 0;
7
+ exports.emptyChunk = exports.fluidVersionToFieldBatchCodecWriteVersion = exports.makeFieldBatchCodec = exports.EncodedFieldBatch = exports.buildChunkedForest = exports.chunkField = exports.chunkFieldSingle = exports.makeTreeChunker = exports.defaultChunkPolicy = exports.chunkTree = exports.dummyRoot = exports.ChunkShape = exports.uniformChunk = void 0;
8
8
  var uniformChunk_js_1 = require("./uniformChunk.js");
9
9
  Object.defineProperty(exports, "uniformChunk", { enumerable: true, get: function () { return uniformChunk_js_1.uniformChunk; } });
10
10
  Object.defineProperty(exports, "ChunkShape", { enumerable: true, get: function () { return uniformChunk_js_1.ChunkShape; } });
@@ -22,4 +22,6 @@ var index_js_2 = require("./codec/index.js");
22
22
  Object.defineProperty(exports, "EncodedFieldBatch", { enumerable: true, get: function () { return index_js_2.EncodedFieldBatch; } });
23
23
  Object.defineProperty(exports, "makeFieldBatchCodec", { enumerable: true, get: function () { return index_js_2.makeFieldBatchCodec; } });
24
24
  Object.defineProperty(exports, "fluidVersionToFieldBatchCodecWriteVersion", { enumerable: true, get: function () { return index_js_2.fluidVersionToFieldBatchCodecWriteVersion; } });
25
+ var emptyChunk_js_1 = require("./emptyChunk.js");
26
+ Object.defineProperty(exports, "emptyChunk", { enumerable: true, get: function () { return emptyChunk_js_1.emptyChunk; } });
25
27
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/feature-libraries/chunked-forest/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,qDAA6D;AAApD,+GAAA,YAAY,OAAA;AAAE,6GAAA,UAAU,OAAA;AACjC,gDAAgE;AAAvC,qGAAA,SAAS,OAAA;AAClC,+CAOwB;AANvB,yGAAA,SAAS,OAAA;AACT,kHAAA,kBAAkB,OAAA;AAClB,+GAAA,eAAe,OAAA;AAEf,gHAAA,gBAAgB,OAAA;AAChB,0GAAA,UAAU,OAAA;AAEX,uDAAwD;AAA/C,sHAAA,kBAAkB,OAAA;AAC3B,6CAO0B;AANzB,6GAAA,iBAAiB,OAAA;AAGjB,+GAAA,mBAAmB,OAAA;AAEnB,qIAAA,yCAAyC,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { uniformChunk, ChunkShape } from \"./uniformChunk.js\";\nexport { type TreeChunk, dummyRoot } from \"../../core/index.js\";\nexport {\n\tchunkTree,\n\tdefaultChunkPolicy,\n\tmakeTreeChunker,\n\ttype IChunker,\n\tchunkFieldSingle,\n\tchunkField,\n} from \"./chunkTree.js\";\nexport { buildChunkedForest } from \"./chunkedForest.js\";\nexport {\n\tEncodedFieldBatch,\n\ttype FieldBatch,\n\ttype FieldBatchCodec,\n\tmakeFieldBatchCodec,\n\ttype FieldBatchEncodingContext,\n\tfluidVersionToFieldBatchCodecWriteVersion,\n} from \"./codec/index.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/feature-libraries/chunked-forest/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,qDAA6D;AAApD,+GAAA,YAAY,OAAA;AAAE,6GAAA,UAAU,OAAA;AACjC,gDAAgE;AAAvC,qGAAA,SAAS,OAAA;AAClC,+CAOwB;AANvB,yGAAA,SAAS,OAAA;AACT,kHAAA,kBAAkB,OAAA;AAClB,+GAAA,eAAe,OAAA;AAEf,gHAAA,gBAAgB,OAAA;AAChB,0GAAA,UAAU,OAAA;AAEX,uDAAwD;AAA/C,sHAAA,kBAAkB,OAAA;AAC3B,6CAO0B;AANzB,6GAAA,iBAAiB,OAAA;AAGjB,+GAAA,mBAAmB,OAAA;AAEnB,qIAAA,yCAAyC,OAAA;AAE1C,iDAA6C;AAApC,2GAAA,UAAU,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { uniformChunk, ChunkShape } from \"./uniformChunk.js\";\nexport { type TreeChunk, dummyRoot } from \"../../core/index.js\";\nexport {\n\tchunkTree,\n\tdefaultChunkPolicy,\n\tmakeTreeChunker,\n\ttype IChunker,\n\tchunkFieldSingle,\n\tchunkField,\n} from \"./chunkTree.js\";\nexport { buildChunkedForest } from \"./chunkedForest.js\";\nexport {\n\tEncodedFieldBatch,\n\ttype FieldBatch,\n\ttype FieldBatchCodec,\n\tmakeFieldBatchCodec,\n\ttype FieldBatchEncodingContext,\n\tfluidVersionToFieldBatchCodecWriteVersion,\n} from \"./codec/index.js\";\nexport { emptyChunk } from \"./emptyChunk.js\";\n"]}
@@ -116,16 +116,14 @@ export interface ValueFieldEditBuilder<TContent> {
116
116
  /**
117
117
  * Issues a change which replaces the current newContent of the field with `newContent`.
118
118
  * @param newContent - the new content for the field.
119
- * The cursor can be in either Field or Node mode and must represent exactly one node.
120
119
  */
121
120
  set(newContent: TContent): void;
122
121
  }
123
122
  export interface OptionalFieldEditBuilder<TContent> {
124
123
  /**
125
- * Issues a change which replaces the current newContent of the field with `newContent`
124
+ * Issues a change which replaces the current newContent of the field with `newContent`.
126
125
  * @param newContent - the new content for the field.
127
- * If provided, the cursor can be in either Field or Node mode and must represent exactly one node.
128
- * @param wasEmpty - whether the field is empty when creating this change
126
+ * @param wasEmpty - whether the field is empty when creating this change.
129
127
  */
130
128
  set(newContent: TContent | undefined, wasEmpty: boolean): void;
131
129
  }
@@ -1 +1 @@
1
- {"version":3,"file":"defaultEditBuilder.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/default-schema/defaultEditBuilder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAEN,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,MAAM,EAGX,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAKN,KAAK,gBAAgB,EAIrB,MAAM,4BAA4B,CAAC;AAWpC,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;AAEhD;;;;GAIG;AACH,qBAAa,mBACZ,YAAW,YAAY,CAAC,kBAAkB,EAAE,g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IAAI;IAClE;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,GAAG,IAAI,CAAC;IAElD;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC;CAC/C"}
1
+ {"version":3,"file":"defaultEditBuilder.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/default-schema/defaultEditBuilder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAEN,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,MAAM,EAGX,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAKN,KAAK,gBAAgB,EAIrB,MAAM,4BAA4B,CAAC;AAWpC,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;AAEhD;;;;GAIG;AACH,qBAAa,mBACZ,YAAW,YAAY,CAAC,kBAAkB,EAAE,gBAAgB,CAAC;IAE7D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAsB;gBAEjC,MAAM,EAAE,YAAY,CAAC,gBAAgB,EAAE,qBAAqB,CAAC;IAIhF,IAAW,OAAO,IAAI,aAAa,CAAC,gBAAgB,CAAC,CAEpD;IAED,IAAW,MAAM,IAAI,YAAY,CAAC,gBAAgB,EAAE,qBAAqB,CAAC,CAEzE;IAEM,WAAW,CACjB,eAAe,EAAE,MAAM,WAAW,EAClC,cAAc,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,gBAAgB,CAAC,KAAK,IAAI,GAC9D,kBAAkB;CAGrB;AA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,IAAI;IAGxB,eAAe,IAAI,IAAI;IAIvB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI3C,+BAA+B,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAInD,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG,qBAAqB,CAAC,SAAS,CAAC;IA8BhE,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,wBAAwB,CAAC,SAAS,CAAC;IAwCtE,IAAI,CACV,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,gBAAgB,EAAE,WAAW,EAC7B,SAAS,EAAE,MAAM,GACf,IAAI;IAoGA,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,wBAAwB,CAAC,SAAS,CAAC;CAsC7E;AAED,MAAM,WAAW,qBAAqB,CAAC,QAAQ;IAC9C;;;OAGG;IACH,GAAG,CAAC,UAAU,EAAE,QAAQ,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,wBAAwB,CAAC,QAAQ;IACjD;;;;OAIG;IACH,GAAG,CAAC,UAAU,EAAE,QAAQ,GAAG,SAAS,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC;CAC/D;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAClE;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,GAAG,IAAI,CAAC;IAElD;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC;CAC/C"}
@@ -80,6 +80,7 @@ class DefaultEditBuilder {
80
80
  valueField(field) {
81
81
  return {
82
82
  set: (newContent) => {
83
+ (0, internal_1.assert)(newContent.topLevelLength === 1, 0xc12 /* Value fields should have a single top level node */);
83
84
  const revision = this.mintRevisionTag();
84
85
  const fill = { localId: this.modularBuilder.generateId(), revision };
85
86
  const detach = { localId: this.modularBuilder.generateId(), revision };
@@ -102,6 +103,8 @@ class DefaultEditBuilder {
102
103
  optionalField(field) {
103
104
  return {
104
105
  set: (newContent, wasEmpty) => {
106
+ // The choice to ban empty chunks here instead of treating them as a clear is a subjective choice made to err of the side of more explicitness and stricter validation.
107
+ (0, internal_1.assert)(newContent === undefined || newContent.topLevelLength === 1, 0xc13 /* optional fields should have a single top level node, or undefined */);
105
108
  const edits = [];
106
109
  let optionalChange;
107
110
  const revision = this.mintRevisionTag();