@fluidframework/tree 2.40.0 → 2.41.0-338186

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 (198) hide show
  1. package/api-report/tree.alpha.api.md +1 -1
  2. package/dist/feature-libraries/default-schema/schemaChecker.d.ts.map +1 -1
  3. package/dist/feature-libraries/default-schema/schemaChecker.js +0 -7
  4. package/dist/feature-libraries/default-schema/schemaChecker.js.map +1 -1
  5. package/dist/feature-libraries/flex-tree/context.d.ts +16 -14
  6. package/dist/feature-libraries/flex-tree/context.d.ts.map +1 -1
  7. package/dist/feature-libraries/flex-tree/context.js +12 -18
  8. package/dist/feature-libraries/flex-tree/context.js.map +1 -1
  9. package/dist/feature-libraries/flex-tree/index.d.ts +1 -1
  10. package/dist/feature-libraries/flex-tree/index.d.ts.map +1 -1
  11. package/dist/feature-libraries/flex-tree/index.js +1 -2
  12. package/dist/feature-libraries/flex-tree/index.js.map +1 -1
  13. package/dist/feature-libraries/flex-tree/lazyField.d.ts +1 -5
  14. package/dist/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  15. package/dist/feature-libraries/flex-tree/lazyField.js +2 -16
  16. package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
  17. package/dist/feature-libraries/flex-tree/utilities.d.ts +6 -6
  18. package/dist/feature-libraries/flex-tree/utilities.d.ts.map +1 -1
  19. package/dist/feature-libraries/flex-tree/utilities.js +6 -7
  20. package/dist/feature-libraries/flex-tree/utilities.js.map +1 -1
  21. package/dist/feature-libraries/index.d.ts +1 -1
  22. package/dist/feature-libraries/index.d.ts.map +1 -1
  23. package/dist/feature-libraries/index.js +1 -2
  24. package/dist/feature-libraries/index.js.map +1 -1
  25. package/dist/packageVersion.d.ts +1 -1
  26. package/dist/packageVersion.d.ts.map +1 -1
  27. package/dist/packageVersion.js +1 -1
  28. package/dist/packageVersion.js.map +1 -1
  29. package/dist/shared-tree/checkoutFlexTreeView.d.ts +7 -3
  30. package/dist/shared-tree/checkoutFlexTreeView.d.ts.map +1 -1
  31. package/dist/shared-tree/checkoutFlexTreeView.js +11 -2
  32. package/dist/shared-tree/checkoutFlexTreeView.js.map +1 -1
  33. package/dist/shared-tree/schematizeTree.d.ts +1 -1
  34. package/dist/shared-tree/schematizeTree.js +1 -1
  35. package/dist/shared-tree/schematizeTree.js.map +1 -1
  36. package/dist/shared-tree/schematizingTreeView.d.ts +3 -0
  37. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  38. package/dist/shared-tree/schematizingTreeView.js +13 -7
  39. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  40. package/dist/shared-tree/treeAlpha.d.ts +1 -4
  41. package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
  42. package/dist/shared-tree/treeAlpha.js +6 -1
  43. package/dist/shared-tree/treeAlpha.js.map +1 -1
  44. package/dist/simple-tree/api/create.d.ts +5 -1
  45. package/dist/simple-tree/api/create.d.ts.map +1 -1
  46. package/dist/simple-tree/api/create.js +10 -11
  47. package/dist/simple-tree/api/create.js.map +1 -1
  48. package/dist/simple-tree/api/index.d.ts +2 -2
  49. package/dist/simple-tree/api/index.d.ts.map +1 -1
  50. package/dist/simple-tree/api/index.js +2 -2
  51. package/dist/simple-tree/api/index.js.map +1 -1
  52. package/dist/simple-tree/api/storedSchema.d.ts +1 -8
  53. package/dist/simple-tree/api/storedSchema.d.ts.map +1 -1
  54. package/dist/simple-tree/api/storedSchema.js +3 -14
  55. package/dist/simple-tree/api/storedSchema.js.map +1 -1
  56. package/dist/simple-tree/arrayNode.d.ts.map +1 -1
  57. package/dist/simple-tree/arrayNode.js +3 -9
  58. package/dist/simple-tree/arrayNode.js.map +1 -1
  59. package/dist/simple-tree/core/unhydratedFlexTree.d.ts +4 -4
  60. package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  61. package/dist/simple-tree/core/unhydratedFlexTree.js +9 -5
  62. package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  63. package/dist/simple-tree/index.d.ts +3 -2
  64. package/dist/simple-tree/index.d.ts.map +1 -1
  65. package/dist/simple-tree/index.js +6 -4
  66. package/dist/simple-tree/index.js.map +1 -1
  67. package/dist/simple-tree/mapNode.d.ts.map +1 -1
  68. package/dist/simple-tree/mapNode.js +17 -20
  69. package/dist/simple-tree/mapNode.js.map +1 -1
  70. package/dist/simple-tree/objectNode.d.ts.map +1 -1
  71. package/dist/simple-tree/objectNode.js +2 -4
  72. package/dist/simple-tree/objectNode.js.map +1 -1
  73. package/dist/simple-tree/prepareForInsertion.d.ts +30 -0
  74. package/dist/simple-tree/prepareForInsertion.d.ts.map +1 -0
  75. package/dist/simple-tree/prepareForInsertion.js +137 -0
  76. package/dist/simple-tree/prepareForInsertion.js.map +1 -0
  77. package/dist/simple-tree/proxies.d.ts +1 -12
  78. package/dist/simple-tree/proxies.d.ts.map +1 -1
  79. package/dist/simple-tree/proxies.js +10 -106
  80. package/dist/simple-tree/proxies.js.map +1 -1
  81. package/dist/simple-tree/toMapTree.d.ts +1 -1
  82. package/dist/simple-tree/toMapTree.js +1 -1
  83. package/dist/simple-tree/toMapTree.js.map +1 -1
  84. package/dist/tableSchema.d.ts +108 -59
  85. package/dist/tableSchema.d.ts.map +1 -1
  86. package/dist/tableSchema.js +93 -44
  87. package/dist/tableSchema.js.map +1 -1
  88. package/lib/feature-libraries/default-schema/schemaChecker.d.ts.map +1 -1
  89. package/lib/feature-libraries/default-schema/schemaChecker.js +0 -7
  90. package/lib/feature-libraries/default-schema/schemaChecker.js.map +1 -1
  91. package/lib/feature-libraries/flex-tree/context.d.ts +16 -14
  92. package/lib/feature-libraries/flex-tree/context.d.ts.map +1 -1
  93. package/lib/feature-libraries/flex-tree/context.js +11 -16
  94. package/lib/feature-libraries/flex-tree/context.js.map +1 -1
  95. package/lib/feature-libraries/flex-tree/index.d.ts +1 -1
  96. package/lib/feature-libraries/flex-tree/index.d.ts.map +1 -1
  97. package/lib/feature-libraries/flex-tree/index.js +1 -1
  98. package/lib/feature-libraries/flex-tree/index.js.map +1 -1
  99. package/lib/feature-libraries/flex-tree/lazyField.d.ts +1 -5
  100. package/lib/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  101. package/lib/feature-libraries/flex-tree/lazyField.js +1 -14
  102. package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
  103. package/lib/feature-libraries/flex-tree/utilities.d.ts +6 -6
  104. package/lib/feature-libraries/flex-tree/utilities.d.ts.map +1 -1
  105. package/lib/feature-libraries/flex-tree/utilities.js +6 -7
  106. package/lib/feature-libraries/flex-tree/utilities.js.map +1 -1
  107. package/lib/feature-libraries/index.d.ts +1 -1
  108. package/lib/feature-libraries/index.d.ts.map +1 -1
  109. package/lib/feature-libraries/index.js +1 -1
  110. package/lib/feature-libraries/index.js.map +1 -1
  111. package/lib/packageVersion.d.ts +1 -1
  112. package/lib/packageVersion.d.ts.map +1 -1
  113. package/lib/packageVersion.js +1 -1
  114. package/lib/packageVersion.js.map +1 -1
  115. package/lib/shared-tree/checkoutFlexTreeView.d.ts +7 -3
  116. package/lib/shared-tree/checkoutFlexTreeView.d.ts.map +1 -1
  117. package/lib/shared-tree/checkoutFlexTreeView.js +12 -3
  118. package/lib/shared-tree/checkoutFlexTreeView.js.map +1 -1
  119. package/lib/shared-tree/schematizeTree.d.ts +1 -1
  120. package/lib/shared-tree/schematizeTree.js +1 -1
  121. package/lib/shared-tree/schematizeTree.js.map +1 -1
  122. package/lib/shared-tree/schematizingTreeView.d.ts +3 -0
  123. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  124. package/lib/shared-tree/schematizingTreeView.js +14 -8
  125. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  126. package/lib/shared-tree/treeAlpha.d.ts +1 -4
  127. package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
  128. package/lib/shared-tree/treeAlpha.js +7 -2
  129. package/lib/shared-tree/treeAlpha.js.map +1 -1
  130. package/lib/simple-tree/api/create.d.ts +5 -1
  131. package/lib/simple-tree/api/create.d.ts.map +1 -1
  132. package/lib/simple-tree/api/create.js +8 -10
  133. package/lib/simple-tree/api/create.js.map +1 -1
  134. package/lib/simple-tree/api/index.d.ts +2 -2
  135. package/lib/simple-tree/api/index.d.ts.map +1 -1
  136. package/lib/simple-tree/api/index.js +2 -2
  137. package/lib/simple-tree/api/index.js.map +1 -1
  138. package/lib/simple-tree/api/storedSchema.d.ts +1 -8
  139. package/lib/simple-tree/api/storedSchema.d.ts.map +1 -1
  140. package/lib/simple-tree/api/storedSchema.js +2 -12
  141. package/lib/simple-tree/api/storedSchema.js.map +1 -1
  142. package/lib/simple-tree/arrayNode.d.ts.map +1 -1
  143. package/lib/simple-tree/arrayNode.js +4 -10
  144. package/lib/simple-tree/arrayNode.js.map +1 -1
  145. package/lib/simple-tree/core/unhydratedFlexTree.d.ts +4 -4
  146. package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  147. package/lib/simple-tree/core/unhydratedFlexTree.js +9 -5
  148. package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  149. package/lib/simple-tree/index.d.ts +3 -2
  150. package/lib/simple-tree/index.d.ts.map +1 -1
  151. package/lib/simple-tree/index.js +3 -2
  152. package/lib/simple-tree/index.js.map +1 -1
  153. package/lib/simple-tree/mapNode.d.ts.map +1 -1
  154. package/lib/simple-tree/mapNode.js +3 -6
  155. package/lib/simple-tree/mapNode.js.map +1 -1
  156. package/lib/simple-tree/objectNode.d.ts.map +1 -1
  157. package/lib/simple-tree/objectNode.js +4 -6
  158. package/lib/simple-tree/objectNode.js.map +1 -1
  159. package/lib/simple-tree/prepareForInsertion.d.ts +30 -0
  160. package/lib/simple-tree/prepareForInsertion.d.ts.map +1 -0
  161. package/lib/simple-tree/prepareForInsertion.js +131 -0
  162. package/lib/simple-tree/prepareForInsertion.js.map +1 -0
  163. package/lib/simple-tree/proxies.d.ts +1 -12
  164. package/lib/simple-tree/proxies.d.ts.map +1 -1
  165. package/lib/simple-tree/proxies.js +1 -96
  166. package/lib/simple-tree/proxies.js.map +1 -1
  167. package/lib/simple-tree/toMapTree.d.ts +1 -1
  168. package/lib/simple-tree/toMapTree.js +1 -1
  169. package/lib/simple-tree/toMapTree.js.map +1 -1
  170. package/lib/tableSchema.d.ts +108 -59
  171. package/lib/tableSchema.d.ts.map +1 -1
  172. package/lib/tableSchema.js +94 -45
  173. package/lib/tableSchema.js.map +1 -1
  174. package/lib/tsdoc-metadata.json +1 -1
  175. package/package.json +25 -25
  176. package/src/feature-libraries/default-schema/schemaChecker.ts +0 -8
  177. package/src/feature-libraries/flex-tree/context.ts +18 -20
  178. package/src/feature-libraries/flex-tree/index.ts +0 -1
  179. package/src/feature-libraries/flex-tree/lazyField.ts +2 -14
  180. package/src/feature-libraries/flex-tree/utilities.ts +8 -8
  181. package/src/feature-libraries/index.ts +0 -1
  182. package/src/packageVersion.ts +1 -1
  183. package/src/shared-tree/checkoutFlexTreeView.ts +10 -6
  184. package/src/shared-tree/schematizeTree.ts +1 -1
  185. package/src/shared-tree/schematizingTreeView.ts +14 -14
  186. package/src/shared-tree/treeAlpha.ts +21 -5
  187. package/src/simple-tree/api/create.ts +15 -15
  188. package/src/simple-tree/api/index.ts +6 -2
  189. package/src/simple-tree/api/storedSchema.ts +2 -19
  190. package/src/simple-tree/arrayNode.ts +9 -20
  191. package/src/simple-tree/core/unhydratedFlexTree.ts +10 -5
  192. package/src/simple-tree/index.ts +6 -5
  193. package/src/simple-tree/mapNode.ts +8 -12
  194. package/src/simple-tree/objectNode.ts +3 -12
  195. package/src/simple-tree/prepareForInsertion.ts +236 -0
  196. package/src/simple-tree/proxies.ts +2 -147
  197. package/src/simple-tree/toMapTree.ts +1 -1
  198. package/src/tableSchema.ts +310 -158
@@ -11,8 +11,9 @@ import {
11
11
  rootField,
12
12
  type SchemaAndPolicy,
13
13
  } from "../../core/index.js";
14
+ import type { FlexTreeContext } from "./context.js";
14
15
 
15
- import { TreeStatus, type FlexTreeEntity } from "./flexTreeTypes.js";
16
+ import { TreeStatus } from "./flexTreeTypes.js";
16
17
  /**
17
18
  * Checks the detached field and returns the TreeStatus based on whether or not the detached field is a root field.
18
19
  * @param detachedField - the detached field you want to check.
@@ -75,15 +76,14 @@ export interface DetachedFieldCache {
75
76
  }
76
77
 
77
78
  /**
78
- * Utility function to get a {@link SchemaAndPolicy} object from a {@link FlexTreeNode} or {@link FlexTreeField}.
79
- * @param nodeOrField - {@link FlexTreeNode} or {@link FlexTreeField} to get the schema and policy from.
80
- * @returns A {@link SchemaAndPolicy} object with the stored schema and policy from the node or field provided.
81
- * For {@link Unhydrated} nodes this schema may only describe the types allowed subtree for this particular entity.
79
+ * Utility function to get a {@link SchemaAndPolicy} object from a {@link FlexTreeContext}.
80
+ * @returns A {@link SchemaAndPolicy} object with the stored schema and policy from the context provided.
81
+ * For {@link Unhydrated} contexts this schema may only describe the types allowed subtree for this particular entity.
82
82
  */
83
- export function getSchemaAndPolicy(nodeOrField: FlexTreeEntity): SchemaAndPolicy {
83
+ export function getSchemaAndPolicy(context: FlexTreeContext): SchemaAndPolicy {
84
84
  return {
85
- schema: nodeOrField.context.schema,
86
- policy: nodeOrField.context.schemaPolicy,
85
+ schema: context.schema,
86
+ policy: context.schemaPolicy,
87
87
  };
88
88
  }
89
89
 
@@ -158,7 +158,6 @@ export {
158
158
  type FlexTreeEntity,
159
159
  type FlexTreeField,
160
160
  type FlexTreeNode,
161
- getTreeContext,
162
161
  TreeStatus,
163
162
  Context,
164
163
  type FlexTreeNodeEvents,
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/tree";
9
- export const pkgVersion = "2.40.0";
9
+ export const pkgVersion = "2.41.0-338186";
@@ -5,10 +5,9 @@
5
5
 
6
6
  import { assert } from "@fluidframework/core-utils/internal";
7
7
  import {
8
- type Context,
8
+ Context,
9
9
  type FlexTreeField,
10
10
  type NodeIdentifierManager,
11
- getTreeContext,
12
11
  type FlexTreeHydratedContext,
13
12
  type FullSchemaPolicy,
14
13
  } from "../feature-libraries/index.js";
@@ -19,6 +18,10 @@ import type { ITreeCheckout, ITreeCheckoutFork } from "./treeCheckout.js";
19
18
 
20
19
  /**
21
20
  * An editable view of a (version control style) branch of a shared tree.
21
+ * @remarks
22
+ * Does not depend on stored schema, and thus can live across schema changes.
23
+ * @privateRemarks
24
+ * This has no state beyond the context, so it likely should be replaced with just the context.
22
25
  */
23
26
  export class CheckoutFlexTreeView<out TCheckout extends ITreeCheckout = ITreeCheckout> {
24
27
  /**
@@ -30,9 +33,11 @@ export class CheckoutFlexTreeView<out TCheckout extends ITreeCheckout = ITreeChe
30
33
  public readonly context: Context;
31
34
 
32
35
  /**
33
- * Get a typed view of the tree content using the flex-tree API.
36
+ * Get a view of the tree content using the flex-tree API.
34
37
  */
35
- public readonly flexTree: FlexTreeField;
38
+ public get flexTree(): FlexTreeField {
39
+ return this.context.root;
40
+ }
36
41
 
37
42
  private disposed = false;
38
43
 
@@ -48,9 +53,8 @@ export class CheckoutFlexTreeView<out TCheckout extends ITreeCheckout = ITreeChe
48
53
  public readonly nodeKeyManager: NodeIdentifierManager,
49
54
  private readonly onDispose?: () => void,
50
55
  ) {
51
- this.context = getTreeContext(schema, this.checkout, nodeKeyManager);
56
+ this.context = new Context(schema, this.checkout, nodeKeyManager);
52
57
  contextToTreeViewMap.set(this.context, this);
53
- this.flexTree = this.context.root;
54
58
  }
55
59
 
56
60
  public [disposeSymbol](): void {
@@ -159,7 +159,7 @@ function normalizeNewFieldContent(
159
159
  * This function should only be called when the tree is uninitialized (no schema or content).
160
160
  * @remarks
161
161
  *
162
- * If the proposed schema (from `treeContent`) is not compatible with the emptry tree, this function handles using an intermediate schema
162
+ * If the proposed schema (from `treeContent`) is not compatible with the empty tree, this function handles using an intermediate schema
163
163
  * which supports the empty tree as well as the final tree content.
164
164
  */
165
165
  export function initialize(checkout: ITreeCheckout, treeContent: TreeStoredContent): void {
@@ -33,9 +33,6 @@ import {
33
33
  SchemaCompatibilityTester,
34
34
  type InsertableContent,
35
35
  type TreeViewConfiguration,
36
- mapTreeFromNodeData,
37
- prepareContentForHydration,
38
- comparePersistedSchemaInternal,
39
36
  type TreeViewAlpha,
40
37
  type InsertableField,
41
38
  type ReadableField,
@@ -55,6 +52,7 @@ import {
55
52
  SimpleContextSlot,
56
53
  areImplicitFieldSchemaEqual,
57
54
  createUnknownOptionalFieldPolicy,
55
+ prepareForInsertionContextless,
58
56
  } from "../simple-tree/index.js";
59
57
  import {
60
58
  type Breakable,
@@ -99,6 +97,9 @@ export class SchematizingSimpleTreeView<
99
97
 
100
98
  private readonly viewSchema: SchemaCompatibilityTester;
101
99
 
100
+ /**
101
+ * Events to unregister upon disposal.
102
+ */
102
103
  private readonly unregisterCallbacks = new Set<() => void>();
103
104
 
104
105
  public disposed = false;
@@ -173,19 +174,19 @@ export class SchematizingSimpleTreeView<
173
174
  }
174
175
 
175
176
  this.runSchemaEdit(() => {
176
- const mapTree = mapTreeFromNodeData(
177
+ const schema = this.viewSchema.viewSchemaAsStored;
178
+ const mapTree = prepareForInsertionContextless(
177
179
  content as InsertableContent | undefined,
178
180
  this.rootFieldSchema,
179
- this.nodeKeyManager,
180
181
  {
181
- schema: this.checkout.storedSchema,
182
+ schema,
182
183
  policy: this.schemaPolicy,
183
184
  },
185
+ this,
184
186
  );
185
187
 
186
- prepareContentForHydration(mapTree, this.checkout.forest);
187
188
  initialize(this.checkout, {
188
- schema: this.viewSchema.viewSchemaAsStored,
189
+ schema,
189
190
  initialTree: mapTree === undefined ? undefined : cursorForMapTreeNode(mapTree),
190
191
  });
191
192
  });
@@ -323,15 +324,14 @@ export class SchematizingSimpleTreeView<
323
324
  private update(): void {
324
325
  this.disposeView();
325
326
 
326
- const compatibility = comparePersistedSchemaInternal(
327
- this.checkout.storedSchema,
328
- this.viewSchema,
329
- canInitialize(this.checkout),
330
- );
327
+ const compatibility = this.viewSchema.checkCompatibility(this.checkout.storedSchema);
331
328
 
332
329
  let lastRoot =
333
330
  this.compatibility.canView && this.view !== undefined ? this.root : undefined;
334
- this.currentCompatibility = compatibility;
331
+ this.currentCompatibility = {
332
+ ...compatibility,
333
+ canInitialize: canInitialize(this.checkout),
334
+ };
335
335
 
336
336
  if (compatibility.canView) {
337
337
  // Trigger "rootChanged" if the root changes in the future.
@@ -36,6 +36,7 @@ import {
36
36
  extractPersistedSchema,
37
37
  type TreeBranch,
38
38
  TreeViewConfigurationAlpha,
39
+ mapTreeFromNodeData,
39
40
  } from "../simple-tree/index.js";
40
41
  import type { JsonCompatible } from "../util/index.js";
41
42
  import { noopValidator, type FluidClientVersion, type ICodecOptions } from "../codec/index.js";
@@ -53,6 +54,7 @@ import {
53
54
  import { independentInitializedView, type ViewContent } from "./independentView.js";
54
55
  import { SchematizingSimpleTreeView, ViewSlot } from "./schematizingTreeView.js";
55
56
  import { currentVersion } from "../codec/index.js";
57
+ import { createFromMapTree } from "../simple-tree/index.js";
56
58
 
57
59
  /**
58
60
  * Extensions to {@link (Tree:interface)} and {@link (TreeBeta:interface)} which are not yet stable.
@@ -80,11 +82,8 @@ export interface TreeAlpha {
80
82
  * When providing a {@link TreeNodeSchemaClass}, this is the same as invoking its constructor except that an unhydrated node can also be provided.
81
83
  * This function exists as a generalization that can be used in other cases as well,
82
84
  * such as when `undefined` might be allowed (for an optional field), or when the type should be inferred from the data when more than one type is possible.
83
- *
84
- * Like with {@link TreeNodeSchemaClass}'s constructor, it's an error to provide an existing node to this API.
85
- * For that case, use {@link (TreeBeta:interface).clone}.
86
85
  * @privateRemarks
87
- * There should be a way to provide a source for defaulted identifiers, wither via this API or some way to add them to its output later.
86
+ * There should be a way to provide a source for defaulted identifiers, either via this API or some way to add them to its output later.
88
87
  */
89
88
  create<const TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema>(
90
89
  schema: UnsafeUnknownSchema extends TSchema
@@ -229,7 +228,24 @@ export const TreeAlpha: TreeAlpha = {
229
228
  return view;
230
229
  },
231
230
 
232
- create: createFromInsertable,
231
+ create<const TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema>(
232
+ schema: UnsafeUnknownSchema extends TSchema
233
+ ? ImplicitFieldSchema
234
+ : TSchema & ImplicitFieldSchema,
235
+ data: InsertableField<TSchema>,
236
+ ): Unhydrated<
237
+ TSchema extends ImplicitFieldSchema
238
+ ? TreeFieldFromImplicitField<TSchema>
239
+ : TreeNode | TreeLeafValue | undefined
240
+ > {
241
+ const mapTree = mapTreeFromNodeData(data as InsertableField<UnsafeUnknownSchema>, schema);
242
+ const result = mapTree === undefined ? undefined : createFromMapTree(schema, mapTree);
243
+ return result as Unhydrated<
244
+ TSchema extends ImplicitFieldSchema
245
+ ? TreeFieldFromImplicitField<TSchema>
246
+ : TreeNode | TreeLeafValue | undefined
247
+ >;
248
+ },
233
249
 
234
250
  importConcise<TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema>(
235
251
  schema: UnsafeUnknownSchema extends TSchema
@@ -5,7 +5,11 @@
5
5
 
6
6
  import { assert } from "@fluidframework/core-utils/internal";
7
7
 
8
- import type { ITreeCursorSynchronous, SchemaAndPolicy } from "../../core/index.js";
8
+ import type {
9
+ ExclusiveMapTree,
10
+ ITreeCursorSynchronous,
11
+ SchemaAndPolicy,
12
+ } from "../../core/index.js";
9
13
  import type {
10
14
  ImplicitFieldSchema,
11
15
  TreeFieldFromImplicitField,
@@ -24,12 +28,10 @@ import {
24
28
  import {
25
29
  cursorForMapTreeNode,
26
30
  defaultSchemaPolicy,
27
- FieldKinds,
28
31
  mapTreeFromCursor,
29
32
  type NodeIdentifierManager,
30
33
  } from "../../feature-libraries/index.js";
31
34
  import { isFieldInSchema } from "../../feature-libraries/index.js";
32
- import { toStoredSchema } from "../toStoredSchema.js";
33
35
  import { inSchemaOrThrow, mapTreeFromNodeData } from "../toMapTree.js";
34
36
  import { getUnhydratedContext } from "../createContext.js";
35
37
  import { createUnknownOptionalFieldPolicy } from "../objectNode.js";
@@ -88,24 +90,12 @@ export function cursorFromInsertable<
88
90
  ):
89
91
  | ITreeCursorSynchronous
90
92
  | (TSchema extends FieldSchema<FieldKind.Optional> ? undefined : never) {
91
- const storedSchema = toStoredSchema(schema);
92
- const schemaValidationPolicy: SchemaAndPolicy = {
93
- policy: defaultSchemaPolicy,
94
- // TODO: optimize: This isn't the most efficient operation since its not cached, and has to convert all the schema.
95
- schema: storedSchema,
96
- };
97
-
98
93
  const mapTree = mapTreeFromNodeData(
99
94
  data as InsertableField<UnsafeUnknownSchema>,
100
95
  schema,
101
96
  context,
102
- schemaValidationPolicy,
103
97
  );
104
98
  if (mapTree === undefined) {
105
- assert(
106
- storedSchema.rootFieldSchema.kind === FieldKinds.optional.identifier,
107
- 0xa10 /* missing non-optional field */,
108
- );
109
99
  return undefined as TSchema extends FieldSchema<FieldKind.Optional> ? undefined : never;
110
100
  }
111
101
  return cursorForMapTreeNode(mapTree);
@@ -144,6 +134,16 @@ export function createFromCursor<const TSchema extends ImplicitFieldSchema>(
144
134
  // Length asserted above, so this is safe. This assert is done instead of checking for undefined after indexing to ensure a length greater than 1 also errors.
145
135
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
146
136
  const mapTree = mapTrees[0]!;
137
+ return createFromMapTree(schema, mapTree);
138
+ }
139
+
140
+ /**
141
+ * Creates an unhydrated simple-tree field from an ExclusiveMapTree.
142
+ */
143
+ export function createFromMapTree<const TSchema extends ImplicitFieldSchema>(
144
+ schema: TSchema,
145
+ mapTree: ExclusiveMapTree,
146
+ ): Unhydrated<TreeFieldFromImplicitField<TSchema>> {
147
147
  const mapTreeNode = UnhydratedFlexTreeNode.getOrCreate(
148
148
  getUnhydratedContext(schema),
149
149
  mapTree,
@@ -45,7 +45,12 @@ export {
45
45
  singletonSchema,
46
46
  } from "./schemaCreationUtilities.js";
47
47
  export { treeNodeApi, type TreeNodeApi, tryGetSchema } from "./treeNodeApi.js";
48
- export { createFromInsertable, cursorFromInsertable, createFromCursor } from "./create.js";
48
+ export {
49
+ createFromInsertable,
50
+ cursorFromInsertable,
51
+ createFromCursor,
52
+ createFromMapTree,
53
+ } from "./create.js";
49
54
  export {
50
55
  type JsonSchemaId,
51
56
  type JsonSchemaType,
@@ -107,7 +112,6 @@ export {
107
112
 
108
113
  export {
109
114
  extractPersistedSchema,
110
- comparePersistedSchemaInternal,
111
115
  comparePersistedSchema,
112
116
  } from "./storedSchema.js";
113
117
 
@@ -4,7 +4,6 @@
4
4
  */
5
5
 
6
6
  import type { FluidClientVersion, ICodecOptions } from "../../codec/index.js";
7
- import type { TreeStoredSchema } from "../../core/index.js";
8
7
  import {
9
8
  defaultSchemaPolicy,
10
9
  encodeTreeSchema,
@@ -96,8 +95,7 @@ export function comparePersistedSchema(
96
95
  persisted: JsonCompatible,
97
96
  view: ImplicitFieldSchema,
98
97
  options: ICodecOptions,
99
- canInitialize: boolean,
100
- ): SchemaCompatibilityStatus {
98
+ ): Omit<SchemaCompatibilityStatus, "canInitialize"> {
101
99
  // Any version can be passed down to makeSchemaCodec here.
102
100
  // We only use the decode part, which always dispatches to the correct codec based on the version in the data, not the version passed to `makeSchemaCodec`.
103
101
  const schemaCodec = makeSchemaCodec(options, SchemaCodecVersion.v1);
@@ -107,20 +105,5 @@ export function comparePersistedSchema(
107
105
  {},
108
106
  normalizeFieldSchema(view),
109
107
  );
110
- return comparePersistedSchemaInternal(stored, viewSchema, canInitialize);
111
- }
112
-
113
- /**
114
- * Compute compatibility for viewing a document with `stored` schema using `viewSchema`.
115
- * `canInitialize` is passed through to the return value unchanged and otherwise unused.
116
- */
117
- export function comparePersistedSchemaInternal(
118
- stored: TreeStoredSchema,
119
- viewSchema: SchemaCompatibilityTester,
120
- canInitialize: boolean,
121
- ): SchemaCompatibilityStatus {
122
- return {
123
- ...viewSchema.checkCompatibility(stored),
124
- canInitialize,
125
- };
108
+ return viewSchema.checkCompatibility(stored);
126
109
  }
@@ -10,10 +10,8 @@ import { EmptyKey, type ExclusiveMapTree } from "../core/index.js";
10
10
  import {
11
11
  type FlexTreeNode,
12
12
  type FlexTreeSequenceField,
13
- getSchemaAndPolicy,
14
13
  isFlexTreeNode,
15
14
  } from "../feature-libraries/index.js";
16
- import { prepareContentForHydration } from "./proxies.js";
17
15
  import {
18
16
  normalizeAllowedTypes,
19
17
  unannotateImplicitAllowedTypes,
@@ -41,6 +39,7 @@ import {
41
39
  type TreeNodeSchemaClass,
42
40
  } from "./core/index.js";
43
41
  import { type InsertableContent, mapTreeFromNodeData } from "./toMapTree.js";
42
+ import { prepareArrayForInsertion } from "./prepareForInsertion.js";
44
43
  import {
45
44
  getKernel,
46
45
  UnhydratedFlexTreeNode,
@@ -860,24 +859,14 @@ abstract class CustomArrayNodeBase<const T extends ImplicitAllowedTypes>
860
859
  | IterableTreeArrayContent<InsertableContent>
861
860
  )[];
862
861
 
863
- const mapTrees = content
864
- .flatMap((c): InsertableContent[] =>
865
- c instanceof IterableTreeArrayContent ? Array.from(c) : [c],
866
- )
867
- .map((c) =>
868
- mapTreeFromNodeData(
869
- c,
870
- this.simpleSchema,
871
- sequenceField.context.isHydrated()
872
- ? sequenceField.context.nodeKeyManager
873
- : undefined,
874
- getSchemaAndPolicy(sequenceField),
875
- ),
876
- );
877
-
878
- if (sequenceField.context.isHydrated()) {
879
- prepareContentForHydration(mapTrees, sequenceField.context.checkout.forest);
880
- }
862
+ const contentArray = content.flatMap((c): InsertableContent[] =>
863
+ c instanceof IterableTreeArrayContent ? Array.from(c) : [c],
864
+ );
865
+ const mapTrees = prepareArrayForInsertion(
866
+ contentArray,
867
+ this.simpleSchema,
868
+ sequenceField.context,
869
+ );
881
870
 
882
871
  return mapTrees;
883
872
  }
@@ -69,7 +69,7 @@ interface LocationInField {
69
69
  * An unhydrated implementation of {@link FlexTreeNode} which wraps a {@link MapTree}.
70
70
  * @remarks
71
71
  * MapTreeNodes are unconditionally cached -
72
- * when retrieved via {@link getOrCreateNode}, the same {@link MapTree} object will always produce the same `UnhydratedFlexTreeNode` object.
72
+ * when retrieved via {@link getOrCreateNodeFromInnerNode}, the same {@link MapTree} object will always produce the same `UnhydratedFlexTreeNode` object.
73
73
  *
74
74
  * Create a `UnhydratedFlexTreeNode` by calling {@link getOrCreate}.
75
75
  */
@@ -112,9 +112,9 @@ export class UnhydratedFlexTreeNode implements FlexTreeNode {
112
112
  * Create a new UnhydratedFlexTreeNode.
113
113
  * @param location - the parentage of this node, if it is being created underneath an existing node and field, or undefined if not
114
114
  * @remarks This class (and its subclasses) should not be directly constructed outside of this module.
115
- * Instead, use {@link getOrCreateNode} to create a UnhydratedFlexTreeNode from a {@link MapTree}.
115
+ * Instead, use {@link getOrCreateNodeFromInnerNode} to create a UnhydratedFlexTreeNode from a {@link MapTree}.
116
116
  * A `UnhydratedFlexTreeNode` may never be constructed more than once for the same {@link MapTree} object.
117
- * Instead, it should always be acquired via {@link getOrCreateNode}.
117
+ * Instead, it should always be acquired via {@link getOrCreateNodeFromInnerNode}.
118
118
  */
119
119
  public constructor(
120
120
  public readonly simpleContext: Context,
@@ -548,7 +548,7 @@ function getFieldKeyCache(
548
548
 
549
549
  /**
550
550
  * If there exists a {@link UnhydratedFlexTreeNode} for the given {@link MapTree}, returns it, otherwise returns `undefined`.
551
- * @remarks {@link UnhydratedFlexTreeNode | UnhydratedFlexTreeNodes} are created via {@link getOrCreateNode}.
551
+ * @remarks {@link UnhydratedFlexTreeNode | UnhydratedFlexTreeNodes} are created via {@link getOrCreateNodeFromInnerNode}.
552
552
  */
553
553
  export function tryUnhydratedFlexTreeNode(
554
554
  mapTree: MapTree,
@@ -597,7 +597,12 @@ function getOrCreateField(
597
597
  return new UnhydratedTreeSequenceField(parent.simpleContext, schema, key, parent, onEdit);
598
598
  }
599
599
 
600
- return new UnhydratedFlexTreeField(parent.simpleContext, schema, key, parent, onEdit);
600
+ // TODO: this seems to used by unknown optional fields. They should probably use "optional" not "Forbidden" schema.
601
+ if (schema === FieldKinds.forbidden.identifier) {
602
+ return new UnhydratedFlexTreeField(parent.simpleContext, schema, key, parent, onEdit);
603
+ }
604
+
605
+ return fail("unsupported field kind");
601
606
  }
602
607
 
603
608
  // #endregion Caching and unboxing utilities
@@ -79,7 +79,6 @@ export {
79
79
  extractPersistedSchema,
80
80
  comparePersistedSchema,
81
81
  type ConciseTree,
82
- comparePersistedSchemaInternal,
83
82
  SchemaCompatibilityTester,
84
83
  type Unenforced,
85
84
  type System_Unsafe,
@@ -123,6 +122,7 @@ export {
123
122
  type FixRecursiveRecursionLimit,
124
123
  schemaStatics,
125
124
  type TreeChangeEvents,
125
+ createFromMapTree,
126
126
  } from "./api/index.js";
127
127
  export type {
128
128
  SimpleTreeSchema,
@@ -184,10 +184,7 @@ export {
184
184
  type NodeSchemaMetadata,
185
185
  evaluateLazySchema,
186
186
  } from "./schemaTypes.js";
187
- export {
188
- getTreeNodeForField,
189
- prepareContentForHydration,
190
- } from "./proxies.js";
187
+ export { getTreeNodeForField } from "./proxies.js";
191
188
  export {
192
189
  TreeArrayNode,
193
190
  IterableTreeArrayContent,
@@ -220,6 +217,10 @@ export {
220
217
  type FactoryContent,
221
218
  type FactoryContentObject,
222
219
  } from "./toMapTree.js";
220
+ export {
221
+ prepareForInsertion,
222
+ prepareForInsertionContextless,
223
+ } from "./prepareForInsertion.js";
223
224
  export { toStoredSchema, getStoredSchema } from "./toStoredSchema.js";
224
225
  export {
225
226
  numberSchema,
@@ -4,13 +4,12 @@
4
4
  */
5
5
 
6
6
  import { Lazy } from "@fluidframework/core-utils/internal";
7
- import {
8
- type FlexTreeNode,
9
- type FlexTreeOptionalField,
10
- type OptionalFieldEditBuilder,
11
- getSchemaAndPolicy,
7
+ import type {
8
+ FlexTreeNode,
9
+ FlexTreeOptionalField,
10
+ OptionalFieldEditBuilder,
12
11
  } from "../feature-libraries/index.js";
13
- import { getTreeNodeForField, prepareContentForHydration } from "./proxies.js";
12
+ import { getTreeNodeForField } from "./proxies.js";
14
13
  import {
15
14
  createFieldSchema,
16
15
  FieldKind,
@@ -42,6 +41,7 @@ import {
42
41
  type FactoryContent,
43
42
  type InsertableContent,
44
43
  } from "./toMapTree.js";
44
+ import { prepareForInsertion } from "./prepareForInsertion.js";
45
45
  import { brand, count, type RestrictiveStringRecord } from "../util/index.js";
46
46
  import { TreeNodeValid, type MostDerivedData } from "./treeNodeValid.js";
47
47
  import type { ExclusiveMapTree } from "../core/index.js";
@@ -191,17 +191,13 @@ abstract class CustomMapNodeBase<const T extends ImplicitAllowedTypes> extends T
191
191
  public set(key: string, value: InsertableTreeNodeFromImplicitAllowedTypes<T>): this {
192
192
  const kernel = getKernel(this);
193
193
  const node = this.innerNode;
194
- const mapTree = mapTreeFromNodeData(
194
+ const mapTree = prepareForInsertion(
195
195
  value as InsertableContent | undefined,
196
196
  createFieldSchema(FieldKind.Optional, kernel.schema.info as ImplicitAllowedTypes),
197
- node.context.isHydrated() ? node.context.nodeKeyManager : undefined,
198
- getSchemaAndPolicy(node),
197
+ node.context,
199
198
  );
200
199
 
201
200
  const field = node.getBoxed(brand(key));
202
- if (node.context.isHydrated()) {
203
- prepareContentForHydration(mapTree, node.context.checkout.forest);
204
- }
205
201
 
206
202
  this.editor(key).set(mapTree, field.length === 0);
207
203
  return this;
@@ -13,9 +13,8 @@ import {
13
13
  type FlexTreeNode,
14
14
  type FlexTreeOptionalField,
15
15
  type FlexTreeRequiredField,
16
- getSchemaAndPolicy,
17
16
  } from "../feature-libraries/index.js";
18
- import { getTreeNodeForField, prepareContentForHydration } from "./proxies.js";
17
+ import { getTreeNodeForField } from "./proxies.js";
19
18
  import {
20
19
  type ImplicitFieldSchema,
21
20
  getStoredKey,
@@ -47,6 +46,7 @@ import {
47
46
  getOrCreateInnerNode,
48
47
  } from "./core/index.js";
49
48
  import { mapTreeFromNodeData, type InsertableContent } from "./toMapTree.js";
49
+ import { prepareForInsertion } from "./prepareForInsertion.js";
50
50
  import type { RestrictiveStringRecord, FlattenKeys } from "../util/index.js";
51
51
  import {
52
52
  isObjectNodeSchema,
@@ -328,16 +328,7 @@ export function setField(
328
328
  simpleFieldSchema: FieldSchema,
329
329
  value: InsertableContent | undefined,
330
330
  ): void {
331
- const mapTree = mapTreeFromNodeData(
332
- value,
333
- simpleFieldSchema,
334
- field.context.isHydrated() ? field.context.nodeKeyManager : undefined,
335
- getSchemaAndPolicy(field),
336
- );
337
-
338
- if (field.context.isHydrated()) {
339
- prepareContentForHydration(mapTree, field.context.checkout.forest);
340
- }
331
+ const mapTree = prepareForInsertion(value, simpleFieldSchema, field.context);
341
332
 
342
333
  switch (field.schema) {
343
334
  case FieldKinds.required.identifier: {