@voidhash/mimic 0.0.5 → 0.0.6

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @voidhash/mimic@0.0.5 build /home/runner/work/mimic/mimic/packages/mimic
2
+ > @voidhash/mimic@0.0.6 build /home/runner/work/mimic/mimic/packages/mimic
3
3
  > tsdown
4
4
 
5
5
  ℹ tsdown v0.18.2 powered by rolldown v1.0.0-beta.55
@@ -11,7 +11,7 @@
11
11
  ℹ [CJS] dist/index.cjs  2.24 kB │ gzip: 0.40 kB
12
12
  ℹ [CJS] dist/client/index.cjs  1.92 kB │ gzip: 0.42 kB
13
13
  ℹ [CJS] dist/server/index.cjs  0.67 kB │ gzip: 0.26 kB
14
- ℹ [CJS] dist/primitives/Tree.cjs 29.93 kB │ gzip: 4.96 kB
14
+ ℹ [CJS] dist/primitives/Tree.cjs 29.98 kB │ gzip: 4.97 kB
15
15
  ℹ [CJS] dist/client/ClientDocument.cjs 20.36 kB │ gzip: 4.53 kB
16
16
  ℹ [CJS] dist/FractionalIndex.cjs 16.98 kB │ gzip: 3.39 kB
17
17
  ℹ [CJS] dist/utils/tree-helpers.cjs 13.42 kB │ gzip: 3.18 kB
@@ -52,8 +52,8 @@
52
52
  ℹ [CJS] dist/OperationDefinition.cjs  0.22 kB │ gzip: 0.16 kB
53
53
  ℹ [CJS] dist/client/Transport.cjs  0.21 kB │ gzip: 0.16 kB
54
54
  ℹ [CJS] dist/Transform.cjs  0.20 kB │ gzip: 0.16 kB
55
- ℹ [CJS] 44 files, total: 211.59 kB
56
- ℹ [CJS] dist/primitives/Tree.d.cts.map  6.78 kB │ gzip: 2.59 kB
55
+ ℹ [CJS] 44 files, total: 211.64 kB
56
+ ℹ [CJS] dist/primitives/Tree.d.cts.map  6.90 kB │ gzip: 2.60 kB
57
57
  ℹ [CJS] dist/primitives/Struct.d.cts.map  3.85 kB │ gzip: 1.62 kB
58
58
  ℹ [CJS] dist/utils/tree-helpers.d.cts.map  3.61 kB │ gzip: 1.31 kB
59
59
  ℹ [CJS] dist/primitives/Array.d.cts.map  3.27 kB │ gzip: 1.36 kB
@@ -88,7 +88,7 @@
88
88
  ℹ [CJS] dist/index.d.cts  1.05 kB │ gzip: 0.28 kB
89
89
  ℹ [CJS] dist/client/index.d.cts  1.01 kB │ gzip: 0.29 kB
90
90
  ℹ [CJS] dist/server/index.d.cts  0.65 kB │ gzip: 0.23 kB
91
- ℹ [CJS] dist/primitives/Tree.d.cts 13.44 kB │ gzip: 3.50 kB
91
+ ℹ [CJS] dist/primitives/Tree.d.cts 13.50 kB │ gzip: 3.50 kB
92
92
  ℹ [CJS] dist/utils/tree-helpers.d.cts 12.18 kB │ gzip: 2.52 kB
93
93
  ℹ [CJS] dist/client/Transport.d.cts  7.30 kB │ gzip: 1.84 kB
94
94
  ℹ [CJS] dist/primitives/shared.d.cts  6.87 kB │ gzip: 2.09 kB
@@ -120,15 +120,15 @@
120
120
  ℹ [CJS] dist/client/WebSocketTransport.d.cts  1.22 kB │ gzip: 0.55 kB
121
121
  ℹ [CJS] dist/Transform.d.cts  0.48 kB │ gzip: 0.26 kB
122
122
  ℹ [CJS] dist/OperationDefinition.d.cts  0.36 kB │ gzip: 0.21 kB
123
- ℹ [CJS] 67 files, total: 179.05 kB
124
- ✔ Build complete in 5588ms
123
+ ℹ [CJS] 67 files, total: 179.23 kB
124
+ ✔ Build complete in 6451ms
125
125
  ℹ [ESM] dist/index.mjs  1.01 kB │ gzip: 0.28 kB
126
126
  ℹ [ESM] dist/client/index.mjs  0.99 kB │ gzip: 0.28 kB
127
127
  ℹ [ESM] dist/server/index.mjs  0.41 kB │ gzip: 0.17 kB
128
- ℹ [ESM] dist/primitives/Tree.mjs.map 68.01 kB │ gzip: 12.80 kB
128
+ ℹ [ESM] dist/primitives/Tree.mjs.map 68.16 kB │ gzip: 12.83 kB
129
129
  ℹ [ESM] dist/FractionalIndex.mjs.map 52.10 kB │ gzip: 10.05 kB
130
130
  ℹ [ESM] dist/client/ClientDocument.mjs.map 46.96 kB │ gzip: 10.85 kB
131
- ℹ [ESM] dist/primitives/Tree.mjs 28.07 kB │ gzip: 4.92 kB
131
+ ℹ [ESM] dist/primitives/Tree.mjs 28.12 kB │ gzip: 4.93 kB
132
132
  ℹ [ESM] dist/primitives/Array.mjs.map 26.02 kB │ gzip: 6.47 kB
133
133
  ℹ [ESM] dist/utils/tree-helpers.mjs.map 24.70 kB │ gzip: 5.20 kB
134
134
  ℹ [ESM] dist/client/WebSocketTransport.mjs.map 23.44 kB │ gzip: 5.75 kB
@@ -155,8 +155,8 @@
155
155
  ℹ [ESM] dist/primitives/Boolean.mjs.map  7.45 kB │ gzip: 2.13 kB
156
156
  ℹ [ESM] dist/primitives/Literal.mjs.map  7.42 kB │ gzip: 2.17 kB
157
157
  ℹ [ESM] dist/OperationPath.mjs.map  7.30 kB │ gzip: 1.73 kB
158
+ ℹ [ESM] dist/primitives/Tree.d.mts.map  6.90 kB │ gzip: 2.60 kB
158
159
  ℹ [ESM] dist/primitives/Union.mjs  6.85 kB │ gzip: 1.75 kB
159
- ℹ [ESM] dist/primitives/Tree.d.mts.map  6.78 kB │ gzip: 2.59 kB
160
160
  ℹ [ESM] dist/EffectSchema.mjs  6.47 kB │ gzip: 1.59 kB
161
161
  ℹ [ESM] dist/primitives/TreeNode.mjs.map  6.47 kB │ gzip: 2.05 kB
162
162
  ℹ [ESM] dist/client/errors.mjs.map  5.68 kB │ gzip: 1.37 kB
@@ -234,7 +234,7 @@
234
234
  ℹ [ESM] dist/index.d.mts  1.05 kB │ gzip: 0.28 kB
235
235
  ℹ [ESM] dist/client/index.d.mts  1.01 kB │ gzip: 0.29 kB
236
236
  ℹ [ESM] dist/server/index.d.mts  0.65 kB │ gzip: 0.23 kB
237
- ℹ [ESM] dist/primitives/Tree.d.mts 13.44 kB │ gzip: 3.50 kB
237
+ ℹ [ESM] dist/primitives/Tree.d.mts 13.50 kB │ gzip: 3.50 kB
238
238
  ℹ [ESM] dist/utils/tree-helpers.d.mts 12.18 kB │ gzip: 2.52 kB
239
239
  ℹ [ESM] dist/client/Transport.d.mts  7.30 kB │ gzip: 1.84 kB
240
240
  ℹ [ESM] dist/primitives/shared.d.mts  6.87 kB │ gzip: 2.09 kB
@@ -266,5 +266,5 @@
266
266
  ℹ [ESM] dist/client/WebSocketTransport.d.mts  1.22 kB │ gzip: 0.55 kB
267
267
  ℹ [ESM] dist/Transform.d.mts  0.48 kB │ gzip: 0.26 kB
268
268
  ℹ [ESM] dist/OperationDefinition.d.mts  0.36 kB │ gzip: 0.22 kB
269
- ℹ [ESM] 144 files, total: 836.01 kB
270
- ✔ Build complete in 5619ms
269
+ ℹ [ESM] 144 files, total: 836.40 kB
270
+ ✔ Build complete in 6485ms
@@ -1 +1 @@
1
- {"version":3,"file":"Presence.d.mts","names":[],"sources":["../src/Presence.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;UAeiB;;;mBAGE,MAAA,CAAO,OAAO;;EAHhB,SAAA,KAAQ,EAKP,KALO;;;;;AAWR,UAAA,eAAe,CAAA,KAAA,CAEC,CAAA;EAMrB;EAKA,SAAA,MAAW,EAXJ,MAAA,CAAO,MAWA,CAXO,KAWC,CAAA;AASlC;AA8BA;;;AAAwE,KA5C5D,KA4C4D,CAAA,UA5C5C,QA4C4C,CAAA,GAAA,CAAA,CAAA,GA5C3B,CA4C2B,CAAA,OAAA,CAAA;;;AAmBxE;AACqB,KA3DT,WAAA,GAAc,QA2DL,CAAA,GAAA,CAAA;;;;AAcR,UAhEI,aAyEhB,CAAA,QAAA,OAAA,CAAA,CAAA;EARoB;EAAT,SAAA,IAAA,EA/DK,KA+DL;EAET;EAAK,SAAA,MAAA,CAAA,EAAA,MAAA;AAeR;;;;;;;;;;;;;;;;;;;;cApDa,uBAAyB,gBAAgB,WAAS,SAAS;;;;;;;;;;cAmB3D,4BACD,SAAS,0BAElB;;;;;;;;;cAYU,gCACD,SAAS,0BAElB;;;;;;;;cAeU,2BACD,SAAS,kCAEV"}
1
+ {"version":3,"file":"Presence.d.mts","names":[],"sources":["../src/Presence.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;UAeiB;;;mBAGE,MAAA,CAAO,OAAO;;EAHhB,SAAA,KAAQ,EAKP,KALO;;;;;AAWR,UAAA,eAAe,CAAA,KAEC,CAAA,CAAA;EAMrB;EAKA,SAAA,MAAW,EAXJ,MAAA,CAAO,MAWA,CAXO,KAWC,CAAA;AASlC;AA8BA;;;AAAwE,KA5C5D,KA4C4D,CAAA,UA5C5C,QA4C4C,CAAA,GAAA,CAAA,CAAA,GA5C3B,CA4C2B,CAAA,OAAA,CAAA;;;AAmBxE;AACqB,KA3DT,WAAA,GAAc,QA2DL,CAAA,GAAA,CAAA;;;;AAcR,UAhEI,aAyEhB,CAAA,QAAA,OAAA,CAAA,CAAA;EARoB;EAAT,SAAA,IAAA,EA/DK,KA+DL;EAET;EAAK,SAAA,MAAA,CAAA,EAAA,MAAA;AAeR;;;;;;;;;;;;;;;;;;;;cApDa,uBAAyB,gBAAgB,WAAS,SAAS;;;;;;;;;;cAmB3D,4BACD,SAAS,0BAElB;;;;;;;;;cAYU,gCACD,SAAS,0BAElB;;;;;;;;cAeU,2BACD,SAAS,kCAEV"}
@@ -132,7 +132,9 @@ var TreePrimitive = class TreePrimitive {
132
132
  }
133
133
  return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({
134
134
  id: node.id,
135
- type: node.type
135
+ type: node.type,
136
+ pos: node.pos,
137
+ parentId: node.parentId
136
138
  }, node.data), {}, { children });
137
139
  };
138
140
  return {
@@ -33,6 +33,8 @@ type TreeState<_TRoot extends AnyTreeNodePrimitive> = readonly TreeNodeState[];
33
33
  */
34
34
  type TreeNodeSnapshot<TNode extends AnyTreeNodePrimitive> = {
35
35
  readonly id: string;
36
+ readonly pos: string;
37
+ readonly parentId: string | null;
36
38
  readonly type: InferTreeNodeType<TNode>;
37
39
  readonly children: TreeNodeSnapshot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OAAA,EAAA,OAAA,EAAA,MAAA,CAAA,EAt7BiE,aAs7BjE,CAt7B+E,OAs7B/E,EAt7BsF,SAs7BtF,EAt7BiG,WAs7BjG,CAAA;EAR+B;;;EAElB,QAAA,sBAAA;EAAd;;;;;;;;;;;;;;;;;sBAhyBmB,kBAAkB,UAAU,UAAQ,UAAU;;;UAwxBnD,4BAA0B;;iBAE1B;;;cAIJ,uBAAsB,+BACxB,YAAY,aACpB,cAAc"}
@@ -33,6 +33,8 @@ type TreeState<_TRoot extends AnyTreeNodePrimitive> = readonly TreeNodeState[];
33
33
  */
34
34
  type TreeNodeSnapshot<TNode extends AnyTreeNodePrimitive> = {
35
35
  readonly id: string;
36
+ readonly pos: string;
37
+ readonly parentId: string | null;
36
38
  readonly type: InferTreeNodeType<TNode>;
37
39
  readonly children: TreeNodeSnapshot<InferTreeNodeChildren<TNode>>[];
38
40
  } & InferTreeNodeDataState<TNode>;
@@ -1 +1 @@
1
- {"version":3,"file":"Tree.d.mts","names":[],"sources":["../../src/primitives/Tree.ts"],"sourcesContent":[],"mappings":";;;;;;;AAkBA;AAWA;AAAkD,UAXjC,aAAA,CAWiC;EAEf,SAAA,EAAA,EAAA,MAAA;EAAlB,SAAA,IAAA,EAAA,MAAA;EAGuB,SAAA,QAAA,EAAA,MAAA,GAAA,IAAA;EAAvB,SAAA,GAAA,EAAA,MAAA;EAAsB,SAAA,IAAA,EAAA,OAAA;AAMvC;AAwDA;;;AAEiB,UArEA,kBAqEA,CAAA,cArEiC,oBAqEjC,CAAA,CAAA;EAC2C,SAAA,EAAA,EAAA,MAAA;EAAtB,SAAA,IAAA,EApErB,iBAoEqB,CApEH,KAoEG,CAAA;EAAjB,SAAA,QAAA,EAAA,MAAA,GAAA,IAAA;EACM,SAAA,GAAA,EAAA,MAAA;EAAvB,SAAA,IAAA,EAlEa,sBAkEb,CAlEoC,KAkEpC,CAAA;;AAKJ;;;AACY,KAlEA,SAkEA,CAAA,eAlEyB,oBAkEzB,CAAA,GA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iBAAA,OAAA;EAAW,QAAA,iBAAA;EAAhC,iBAAA,cAAA;EAgJnB,WAAA,CAAA,MAAA,EA1K5B,mBA0K4B,CA1KR,OA0KQ,CAAA;EAAV;EAA4B,QAAA,CAAA,CAAA,EArKtD,aAqKsD,CArKxC,OAqKwC,EAAA,IAAA,EArK3B,WAqK2B,CAAA;EAAV;EAApC,OAAA,CAAA,YAAA,EA7JE,gBA6JF,CA7JmB,OA6JnB,CAAA,CAAA,EA7J4B,aA6J5B,CA7J0C,OA6J1C,EA7JiD,SA6JjD,EAAA,IAAA,CAAA;EAlNT;EAAS,IAAA,IAAA,CAAA,CAAA,EA6DR,OA7DQ;EA0+BL;EAMJ,MAAA,CAQT,EAAA,EAAA,CAAA,KAAA,EAt7BiB,SAs7BjB,CAt7B2B,OAs7B3B,CAAA,EAAA,GAAA,OAAA,EAAA,OAAA,EAAA,MAAA,CAAA,EAt7BiE,aAs7BjE,CAt7B+E,OAs7B/E,EAt7BsF,SAs7BtF,EAt7BiG,WAs7BjG,CAAA;EAR+B;;;EAElB,QAAA,sBAAA;EAAd;;;;;;;;;;;;;;;;;sBAhyBmB,kBAAkB,UAAU,UAAQ,UAAU;;;UAwxBnD,4BAA0B;;iBAE1B;;;cAIJ,uBAAsB,+BACxB,YAAY,aACpB,cAAc"}
@@ -131,7 +131,9 @@ var TreePrimitive = class TreePrimitive {
131
131
  }
132
132
  return _objectSpread2(_objectSpread2({
133
133
  id: node.id,
134
- type: node.type
134
+ type: node.type,
135
+ pos: node.pos,
136
+ parentId: node.parentId
135
137
  }, node.data), {}, { children });
136
138
  };
137
139
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"Tree.mjs","names":["descendantIds: string[]","FractionalIndex.base62CharSet","FractionalIndex.generateKeyBetween","OperationDefinition.make","children: TreeNodeSnapshot<any>[]","Operation.fromDefinition","newState: TreeState<TRoot>","node","OperationPath.pathsOverlap","clientTokens","serverTokens","OperationPath.pathsEqual","OperationPath.isPrefix","result: TreeNodeState[]","prevChildPos: string | null"],"sources":["../../src/primitives/Tree.ts"],"sourcesContent":["import { Effect, Schema } from \"effect\";\nimport * as OperationDefinition from \"../OperationDefinition\";\nimport * as Operation from \"../Operation\";\nimport * as OperationPath from \"../OperationPath\";\nimport * as ProxyEnvironment from \"../ProxyEnvironment\";\nimport * as Transform from \"../Transform\";\nimport * as FractionalIndex from \"../FractionalIndex\";\nimport type { Primitive, PrimitiveInternal, Validator, InferProxy, AnyPrimitive, InferSetInput, InferUpdateInput } from \"./shared\";\nimport { ValidationError, applyDefaults } from \"./shared\";\nimport { runValidators } from \"./shared\";\nimport type { AnyTreeNodePrimitive, InferTreeNodeType, InferTreeNodeDataState, InferTreeNodeChildren } from \"./TreeNode\";\nimport { InferStructState, StructSetInput, StructUpdateValue } from \"./Struct\";\nimport { StructPrimitive } from \"./Struct\";\n\n\n/**\n * A node in the tree state (flat storage format)\n */\nexport interface TreeNodeState {\n readonly id: string; // Unique node identifier (UUID)\n readonly type: string; // Node type discriminator\n readonly parentId: string | null; // Parent node ID (null for root)\n readonly pos: string; // Fractional index for sibling ordering\n readonly data: unknown; // Node-specific data\n}\n\n/**\n * Typed node state for a specific node type\n */\nexport interface TypedTreeNodeState<TNode extends AnyTreeNodePrimitive> {\n readonly id: string;\n readonly type: InferTreeNodeType<TNode>;\n readonly parentId: string | null;\n readonly pos: string;\n readonly data: InferTreeNodeDataState<TNode>;\n}\n\n/**\n * The state type for trees - a flat array of nodes\n */\nexport type TreeState<_TRoot extends AnyTreeNodePrimitive> = readonly TreeNodeState[];\n\n/**\n * Helper to get children sorted by position\n */\nconst getOrderedChildren = (\n nodes: readonly TreeNodeState[],\n parentId: string | null\n): TreeNodeState[] => {\n return [...nodes]\n .filter(n => n.parentId === parentId)\n .sort((a, b) => a.pos < b.pos ? -1 : a.pos > b.pos ? 1 : 0);\n};\n\n/**\n * Get all descendant IDs of a node (recursive)\n */\nconst getDescendantIds = (\n nodes: readonly TreeNodeState[],\n nodeId: string\n): string[] => {\n const children = nodes.filter(n => n.parentId === nodeId);\n const descendantIds: string[] = [];\n for (const child of children) {\n descendantIds.push(child.id);\n descendantIds.push(...getDescendantIds(nodes, child.id));\n }\n return descendantIds;\n};\n\n/**\n * Check if moving a node to a new parent would create a cycle\n */\nconst wouldCreateCycle = (\n nodes: readonly TreeNodeState[],\n nodeId: string,\n newParentId: string | null\n): boolean => {\n if (newParentId === null) return false;\n if (newParentId === nodeId) return true;\n \n const descendants = getDescendantIds(nodes, nodeId);\n return descendants.includes(newParentId);\n};\n\n/**\n * Generate a fractional position between two positions\n */\nconst generateTreePosBetween = (left: string | null, right: string | null): string => {\n const charSet = FractionalIndex.base62CharSet();\n return Effect.runSync(FractionalIndex.generateKeyBetween(left, right, charSet));\n};\n\n/**\n * Snapshot of a single node for UI rendering (data properties spread at node level)\n */\nexport type TreeNodeSnapshot<TNode extends AnyTreeNodePrimitive> = {\n readonly id: string;\n readonly type: InferTreeNodeType<TNode>;\n readonly children: TreeNodeSnapshot<InferTreeNodeChildren<TNode>>[];\n} & InferTreeNodeDataState<TNode>;\n\n/**\n * Infer the snapshot type for a tree (recursive tree structure for UI)\n */\nexport type InferTreeSnapshot<T extends TreePrimitive<any>> =\n T extends TreePrimitive<infer TRoot> ? TreeNodeSnapshot<TRoot> : never;\n\n/**\n * Helper type to infer the update value type from a TreeNode's data.\n * Uses StructUpdateValue directly to get field-level partial update semantics.\n * All fields are optional in update operations.\n */\nexport type TreeNodeUpdateValue<TNode extends AnyTreeNodePrimitive> = \n TNode[\"data\"] extends StructPrimitive<infer TFields, any, any>\n ? StructUpdateValue<TFields>\n : InferUpdateInput<TNode[\"data\"]>;\n\n/**\n * Helper type to infer the input type for node data (respects field defaults).\n * Uses StructSetInput directly so that:\n * - Fields that are required AND have no default must be provided\n * - Fields that are optional OR have defaults can be omitted\n *\n * This bypasses the struct-level NeedsValue wrapper since tree inserts\n * always require a data object (even if empty for all-optional fields).\n */\nexport type TreeNodeDataSetInput<TNode extends AnyTreeNodePrimitive> =\n TNode[\"data\"] extends StructPrimitive<infer TFields, any, any>\n ? StructSetInput<TFields>\n : InferSetInput<TNode[\"data\"]>;\n\n// =============================================================================\n// Nested Input Types for set() and default()\n// =============================================================================\n\n/**\n * Type guard to check if a type is `any` or unknown (structural check).\n * Returns true if T is `any`, false otherwise.\n */\ntype IsAny<T> = 0 extends (1 & T) ? true : false;\n\n/**\n * Get children types, with special handling for self-referential nodes.\n * When InferTreeNodeChildren returns `any` (from TreeNodePrimitive<..., any>),\n * we fall back to using TNode itself as its own child type.\n * This handles the common case of self-referential nodes like:\n * FolderNode = TreeNode(\"folder\", { children: [TreeNodeSelf, FileNode] })\n * Where FolderNode's TChildren is resolved to FolderNode | FileNode,\n * but the self-referenced FolderNode has TChildren = any.\n */\ntype ResolveChildrenForInput<TNode extends AnyTreeNodePrimitive, TOriginalNode extends AnyTreeNodePrimitive> =\n IsAny<InferTreeNodeChildren<TNode>> extends true\n ? TOriginalNode // Self-reference: use the original node's type\n : InferTreeNodeChildren<TNode>;\n\n/**\n * Helper type that creates a properly typed node input for a specific node type.\n * This is the \"strict\" version that enforces exact property matching.\n *\n * The TOriginalNode parameter is used to track the original root node type\n * for proper self-reference resolution in deeply nested structures.\n */\ntype TreeNodeSetInputStrictWithRoot<TNode extends AnyTreeNodePrimitive, TOriginalNode extends AnyTreeNodePrimitive> = {\n readonly type: InferTreeNodeType<TNode>;\n readonly id?: string;\n readonly children: TreeNodeSetInputUnionWithRoot<ResolveChildrenForInput<TNode, TOriginalNode>, TOriginalNode>[];\n} & TreeNodeDataSetInput<TNode>;\n\n/**\n * Distributive conditional type that creates a union of TreeNodeSetInputStrict\n * for each node type in the union. This ensures proper type discrimination.\n *\n * When TNode is a union (e.g., FolderNode | FileNode), this distributes to:\n * TreeNodeSetInputStrict<FolderNode> | TreeNodeSetInputStrict<FileNode>\n *\n * This creates a proper discriminated union where excess property checking works.\n */\ntype TreeNodeSetInputUnionWithRoot<TNode extends AnyTreeNodePrimitive, TOriginalNode extends AnyTreeNodePrimitive> =\n TNode extends AnyTreeNodePrimitive ? TreeNodeSetInputStrictWithRoot<TNode, TOriginalNode> : never;\n\n/**\n * Helper type for single-parameter usage - uses TNode as its own original.\n */\ntype TreeNodeSetInputStrict<TNode extends AnyTreeNodePrimitive> =\n TreeNodeSetInputStrictWithRoot<TNode, TNode>;\n\n/**\n * Distributive conditional for single-parameter usage.\n */\nexport type TreeNodeSetInputUnion<TNode extends AnyTreeNodePrimitive> =\n TNode extends AnyTreeNodePrimitive ? TreeNodeSetInputStrict<TNode> : never;\n\n/**\n * Input type for a single node in a nested tree set/default operation.\n *\n * - `type` is REQUIRED - explicit type discriminator for the node\n * - `id` is optional - auto-generated if not provided\n * - `children` is a typed array of allowed child node inputs\n * - Data fields are spread at the node level (like TreeNodeSnapshot)\n *\n * When TNode is a union type (e.g., from InferTreeNodeChildren), this properly\n * distributes to create a discriminated union where:\n * - Each variant has its specific `type` literal\n * - Each variant has its specific data fields\n * - Excess property checking works correctly\n *\n * @example\n * ```typescript\n * const input: TreeNodeSetInput<BoardNode> = {\n * type: \"board\",\n * name: \"My Board\",\n * children: [\n * { type: \"column\", name: \"Todo\", children: [] }\n * ]\n * };\n * ```\n */\nexport type TreeNodeSetInput<TNode extends AnyTreeNodePrimitive> = TreeNodeSetInputUnion<TNode>;\n\n/**\n * Input type for tree set() and default() operations.\n * Accepts a nested tree structure that will be converted to flat TreeState internally.\n */\nexport type TreeSetInput<TRoot extends AnyTreeNodePrimitive> = TreeNodeSetInput<TRoot>;\n\n/**\n * Infer the set input type for a tree primitive.\n */\nexport type InferTreeSetInput<T extends TreePrimitive<any>> =\n T extends TreePrimitive<infer TRoot> ? TreeSetInput<TRoot> : never;\n\n/**\n * Internal type for processing any node input during conversion.\n * This is only used internally in _convertNestedToFlat and is not exported.\n * Allows us to keep the public TreeNodeSetInput<TNode> fully type-safe while\n * having a runtime-compatible type for internal processing.\n */\ntype InternalNodeInput = {\n readonly type: string;\n readonly id?: string;\n readonly children: InternalNodeInput[];\n readonly [key: string]: unknown;\n};\n\n/**\n * Typed proxy for a specific node type - provides type-safe data access\n */\nexport interface TypedNodeProxy<TNode extends AnyTreeNodePrimitive> {\n /** The node ID */\n readonly id: string;\n /** The node type */\n readonly type: InferTreeNodeType<TNode>;\n /** Access the node's data proxy */\n readonly data: InferProxy<TNode[\"data\"]>;\n /** Get the raw node state */\n get(): TypedTreeNodeState<TNode>;\n /** Updates only the specified data fields (partial update, handles nested structs recursively) */\n update(value: TreeNodeUpdateValue<TNode>): void;\n}\n\n/**\n * Node proxy with type narrowing capabilities\n */\nexport interface TreeNodeProxyBase<_TRoot extends AnyTreeNodePrimitive> {\n /** The node ID */\n readonly id: string;\n /** The node type (string) */\n readonly type: string;\n /** Type guard - narrows the proxy to a specific node type */\n is<TNode extends AnyTreeNodePrimitive>(\n nodeType: TNode\n ): this is TypedNodeProxy<TNode>;\n /** Type assertion - returns typed proxy (throws if wrong type) */\n as<TNode extends AnyTreeNodePrimitive>(\n nodeType: TNode\n ): TypedNodeProxy<TNode>;\n /** Get the raw node state */\n get(): TreeNodeState;\n}\n\n/**\n * Proxy for accessing and modifying tree nodes\n */\nexport interface TreeProxy<TRoot extends AnyTreeNodePrimitive> {\n /** Gets the entire tree state (flat array of nodes) */\n get(): TreeState<TRoot>;\n\n /** Replaces the entire tree with a nested input structure */\n set(input: TreeSetInput<TRoot>): void;\n \n /** Gets the root node state */\n root(): TypedTreeNodeState<TRoot> | undefined;\n \n /** Gets ordered children states of a parent (null for root's children) */\n children(parentId: string | null): TreeNodeState[];\n \n /** Gets a node proxy by ID with type narrowing capabilities */\n node(id: string): TreeNodeProxyBase<TRoot> | undefined;\n \n /** Insert a new node as the first child (applies defaults for node data) */\n insertFirst<TNode extends AnyTreeNodePrimitive>(\n parentId: string | null,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string;\n \n /** Insert a new node as the last child (applies defaults for node data) */\n insertLast<TNode extends AnyTreeNodePrimitive>(\n parentId: string | null,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string;\n \n /** Insert a new node at a specific index among siblings (applies defaults for node data) */\n insertAt<TNode extends AnyTreeNodePrimitive>(\n parentId: string | null,\n index: number,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string;\n \n /** Insert a new node after a sibling (applies defaults for node data) */\n insertAfter<TNode extends AnyTreeNodePrimitive>(\n siblingId: string,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string;\n \n /** Insert a new node before a sibling (applies defaults for node data) */\n insertBefore<TNode extends AnyTreeNodePrimitive>(\n siblingId: string,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string;\n \n /** Remove a node and all its descendants */\n remove(id: string): void;\n \n /** Move a node to a new parent at a specific index */\n move(nodeId: string, newParentId: string | null, toIndex: number): void;\n \n /** Move a node after a sibling */\n moveAfter(nodeId: string, siblingId: string): void;\n \n /** Move a node before a sibling */\n moveBefore(nodeId: string, siblingId: string): void;\n \n /** Move a node to be the first child of a parent */\n moveToFirst(nodeId: string, newParentId: string | null): void;\n \n /** Move a node to be the last child of a parent */\n moveToLast(nodeId: string, newParentId: string | null): void;\n \n /** Returns a typed proxy for a specific node's data */\n at<TNode extends AnyTreeNodePrimitive>(\n id: string,\n nodeType: TNode\n ): InferProxy<TNode[\"data\"]>;\n \n /** Updates only the specified data fields of a node (partial update) */\n updateAt<TNode extends AnyTreeNodePrimitive>(\n id: string,\n nodeType: TNode,\n value: TreeNodeUpdateValue<TNode>\n ): void;\n \n /** Convert tree to a nested snapshot for UI rendering */\n toSnapshot(): TreeNodeSnapshot<TRoot> | undefined;\n}\n\ninterface TreePrimitiveSchema<TRoot extends AnyTreeNodePrimitive> {\n readonly required: boolean;\n readonly defaultInput: TreeNodeSetInput<TRoot> | undefined;\n readonly root: TRoot;\n readonly validators: readonly Validator<TreeState<TRoot>>[];\n}\n\n/** Input type for tree update() - same as set() for trees (nested format) */\nexport type TreeUpdateInput<TRoot extends AnyTreeNodePrimitive> = TreeNodeSetInput<TRoot>;\n\nexport class TreePrimitive<TRoot extends AnyTreeNodePrimitive, TRequired extends boolean = false, THasDefault extends boolean = false>\n implements Primitive<TreeState<TRoot>, TreeProxy<TRoot>, TRequired, THasDefault, TreeSetInput<TRoot>, TreeUpdateInput<TRoot>>\n{\n readonly _tag = \"TreePrimitive\" as const;\n readonly _State!: TreeState<TRoot>;\n readonly _Proxy!: TreeProxy<TRoot>;\n readonly _TRequired!: TRequired;\n readonly _THasDefault!: THasDefault;\n readonly TSetInput!: TreeSetInput<TRoot>;\n readonly TUpdateInput!: TreeUpdateInput<TRoot>;\n\n private readonly _schema: TreePrimitiveSchema<TRoot>;\n private _nodeTypeRegistry: Map<string, AnyTreeNodePrimitive> | undefined;\n\n private readonly _opDefinitions = {\n set: OperationDefinition.make({\n kind: \"tree.set\" as const,\n payload: Schema.Unknown,\n target: Schema.Unknown,\n apply: (payload) => payload,\n }),\n insert: OperationDefinition.make({\n kind: \"tree.insert\" as const,\n payload: Schema.Unknown,\n target: Schema.Unknown,\n apply: (payload) => payload,\n }),\n remove: OperationDefinition.make({\n kind: \"tree.remove\" as const,\n payload: Schema.Unknown,\n target: Schema.Unknown,\n apply: (payload) => payload,\n }),\n move: OperationDefinition.make({\n kind: \"tree.move\" as const,\n payload: Schema.Unknown,\n target: Schema.Unknown,\n apply: (payload) => payload,\n }),\n };\n\n constructor(schema: TreePrimitiveSchema<TRoot>) {\n this._schema = schema;\n }\n\n /** Mark this tree as required */\n required(): TreePrimitive<TRoot, true, THasDefault> {\n return new TreePrimitive({\n ...this._schema,\n required: true,\n });\n }\n\n /** Set a default value for this tree (nested format) */\n default(defaultInput: TreeNodeSetInput<TRoot>): TreePrimitive<TRoot, TRequired, true> {\n return new TreePrimitive({\n ...this._schema,\n defaultInput,\n });\n }\n\n /** Get the root node type */\n get root(): TRoot {\n return this._schema.root;\n }\n\n /** Add a custom validation rule */\n refine(fn: (value: TreeState<TRoot>) => boolean, message: string): TreePrimitive<TRoot, TRequired, THasDefault> {\n return new TreePrimitive({\n ...this._schema,\n validators: [...this._schema.validators, { validate: fn, message }],\n });\n }\n\n /**\n * Build a registry of all node types reachable from root\n */\n private _buildNodeTypeRegistry(): Map<string, AnyTreeNodePrimitive> {\n if (this._nodeTypeRegistry !== undefined) {\n return this._nodeTypeRegistry;\n }\n\n const registry = new Map<string, AnyTreeNodePrimitive>();\n const visited = new Set<string>();\n\n const visit = (node: AnyTreeNodePrimitive) => {\n if (visited.has(node.type)) return;\n visited.add(node.type);\n registry.set(node.type, node);\n\n for (const child of node.children) {\n visit(child);\n }\n };\n\n visit(this._schema.root);\n this._nodeTypeRegistry = registry;\n return registry;\n }\n\n /**\n * Get a node type primitive by its type string\n */\n private _getNodeTypePrimitive(type: string): AnyTreeNodePrimitive {\n const registry = this._buildNodeTypeRegistry();\n const nodeType = registry.get(type);\n if (!nodeType) {\n throw new ValidationError(`Unknown node type: ${type}`);\n }\n return nodeType;\n }\n\n /**\n * Validate that a node type can be a child of a parent node type\n */\n private _validateChildType(\n parentType: string | null,\n childType: string\n ): void {\n if (parentType === null) {\n // Root level - child must be the root type\n if (childType !== this._schema.root.type) {\n throw new ValidationError(\n `Root node must be of type \"${this._schema.root.type}\", got \"${childType}\"`\n );\n }\n return;\n }\n\n const parentNodePrimitive = this._getNodeTypePrimitive(parentType);\n if (!parentNodePrimitive.isChildAllowed(childType)) {\n const allowedTypes = parentNodePrimitive.children.map(c => c.type).join(\", \");\n throw new ValidationError(\n `Node type \"${childType}\" is not allowed as a child of \"${parentType}\". ` +\n `Allowed types: ${allowedTypes || \"none\"}`\n );\n }\n }\n\n /**\n * Convert a nested TreeNodeSetInput to flat TreeState format.\n * Recursively processes nodes, generating IDs and positions as needed.\n *\n * @param input - The root nested input to convert\n * @param generateId - Optional ID generator (defaults to crypto.randomUUID)\n * @returns Flat TreeState array\n */\n private _convertNestedToFlat(\n input: TreeNodeSetInput<TRoot>,\n generateId: () => string = () => crypto.randomUUID()\n ): TreeState<TRoot> {\n const result: TreeNodeState[] = [];\n const seenIds = new Set<string>();\n\n const processNode = (\n nodeInput: InternalNodeInput,\n parentId: string | null,\n parentType: string | null,\n leftPos: string | null,\n rightPos: string | null\n ): void => {\n // Validate node type\n this._validateChildType(parentType, nodeInput.type);\n\n // Get the node primitive for this type\n const nodePrimitive = this._getNodeTypePrimitive(nodeInput.type);\n\n // Generate or use provided ID\n const id = nodeInput.id ?? generateId();\n\n // Check for duplicate IDs\n if (seenIds.has(id)) {\n throw new ValidationError(`Duplicate node ID: ${id}`);\n }\n seenIds.add(id);\n\n // Generate position\n const pos = generateTreePosBetween(leftPos, rightPos);\n\n // Extract data fields (everything except type, id, and children)\n const { type: _type, id: _id, children, ...dataFields } = nodeInput;\n\n // Apply defaults to node data\n const mergedData = applyDefaults(nodePrimitive.data as AnyPrimitive, dataFields);\n\n // Add this node to result\n result.push({\n id,\n type: nodeInput.type,\n parentId,\n pos,\n data: mergedData,\n });\n\n // Process children recursively\n let prevChildPos: string | null = null;\n for (let i = 0; i < children.length; i++) {\n const childInput = children[i]!;\n // Each child gets a position after the previous child\n processNode(childInput, id, nodeInput.type, prevChildPos, null);\n // Update prevChildPos to the pos that was just assigned (it's the last item in result)\n prevChildPos = result[result.length - 1]!.pos;\n }\n };\n\n // Process root node (cast to InternalNodeInput for internal processing)\n processNode(input as unknown as InternalNodeInput, null, null, null, null);\n\n return result as TreeState<TRoot>;\n }\n\n readonly _internal: PrimitiveInternal<TreeState<TRoot>, TreeProxy<TRoot>> = {\n createProxy: (\n env: ProxyEnvironment.ProxyEnvironment,\n operationPath: OperationPath.OperationPath\n ): TreeProxy<TRoot> => {\n // Helper to get current state\n const getCurrentState = (): TreeState<TRoot> => {\n const state = env.getState(operationPath) as TreeState<TRoot> | undefined;\n return state ?? [];\n };\n\n // Helper to get parent type from state\n const getParentType = (parentId: string | null): string | null => {\n if (parentId === null) return null;\n const state = getCurrentState();\n const parent = state.find(n => n.id === parentId);\n return parent?.type ?? null;\n };\n\n // Helper to create a node proxy with type narrowing\n const createNodeProxy = (nodeState: TreeNodeState): TreeNodeProxyBase<TRoot> => {\n return {\n id: nodeState.id,\n type: nodeState.type,\n \n is: <TNode extends AnyTreeNodePrimitive>(\n nodeType: TNode\n ): boolean => {\n return nodeState.type === nodeType.type;\n },\n \n as: <TNode extends AnyTreeNodePrimitive>(\n nodeType: TNode\n ): TypedNodeProxy<TNode> => {\n if (nodeState.type !== nodeType.type) {\n throw new ValidationError(\n `Node is of type \"${nodeState.type}\", not \"${nodeType.type}\"`\n );\n }\n const nodePath = operationPath.append(nodeState.id);\n const dataProxy = nodeType.data._internal.createProxy(env, nodePath) as InferProxy<TNode[\"data\"]>;\n return {\n id: nodeState.id,\n type: nodeType.type as InferTreeNodeType<TNode>,\n data: dataProxy,\n get: () => nodeState as TypedTreeNodeState<TNode>,\n update: (value: TreeNodeUpdateValue<TNode>) => {\n // Delegate to the data proxy's update method\n (dataProxy as { update: (v: unknown) => void }).update(value);\n },\n };\n },\n \n get: () => nodeState,\n } as TreeNodeProxyBase<TRoot>;\n };\n\n // Helper to build recursive snapshot\n const buildSnapshot = (\n nodeId: string,\n nodes: readonly TreeNodeState[]\n ): TreeNodeSnapshot<TRoot> | undefined => {\n const node = nodes.find(n => n.id === nodeId);\n if (!node) return undefined;\n\n const childNodes = getOrderedChildren(nodes, nodeId);\n const children: TreeNodeSnapshot<any>[] = [];\n for (const child of childNodes) {\n const childSnapshot = buildSnapshot(child.id, nodes);\n if (childSnapshot) {\n children.push(childSnapshot);\n }\n }\n\n // Spread data properties at node level\n return {\n id: node.id,\n type: node.type,\n ...(node.data as object),\n children,\n } as unknown as TreeNodeSnapshot<TRoot>;\n };\n\n return {\n get: (): TreeState<TRoot> => {\n return getCurrentState();\n },\n\n set: (input: TreeSetInput<TRoot>) => {\n // Convert nested input to flat TreeState using env.generateId for IDs\n const flatState = this._convertNestedToFlat(input, env.generateId);\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.set, flatState)\n );\n },\n\n root: (): TypedTreeNodeState<TRoot> | undefined => {\n const state = getCurrentState();\n const rootNode = state.find(n => n.parentId === null);\n return rootNode as TypedTreeNodeState<TRoot> | undefined;\n },\n\n children: (parentId: string | null): TreeNodeState[] => {\n const state = getCurrentState();\n return getOrderedChildren(state, parentId);\n },\n\n node: (id: string): TreeNodeProxyBase<TRoot> | undefined => {\n const state = getCurrentState();\n const nodeState = state.find(n => n.id === id);\n if (!nodeState) return undefined;\n return createNodeProxy(nodeState);\n },\n\n insertFirst: <TNode extends AnyTreeNodePrimitive>(\n parentId: string | null,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string => {\n const state = getCurrentState();\n const siblings = getOrderedChildren(state, parentId);\n const firstPos = siblings.length > 0 ? siblings[0]!.pos : null;\n const pos = generateTreePosBetween(null, firstPos);\n const id = env.generateId();\n\n // Validate parent exists (if not root)\n if (parentId !== null && !state.find(n => n.id === parentId)) {\n throw new ValidationError(`Parent node not found: ${parentId}`);\n }\n\n // Validate child type is allowed\n const parentType = getParentType(parentId);\n this._validateChildType(parentType, nodeType.type);\n\n // Validate single root\n if (parentId === null && state.some(n => n.parentId === null)) {\n throw new ValidationError(\"Tree already has a root node\");\n }\n\n // Apply defaults to node data\n const mergedData = applyDefaults(nodeType.data as AnyPrimitive, data as Partial<InferTreeNodeDataState<TNode>>) as InferTreeNodeDataState<TNode>;\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.insert, {\n id,\n type: nodeType.type,\n parentId,\n pos,\n data: mergedData,\n })\n );\n\n return id;\n },\n\n insertLast: <TNode extends AnyTreeNodePrimitive>(\n parentId: string | null,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string => {\n const state = getCurrentState();\n const siblings = getOrderedChildren(state, parentId);\n const lastPos = siblings.length > 0 ? siblings[siblings.length - 1]!.pos : null;\n const pos = generateTreePosBetween(lastPos, null);\n const id = env.generateId();\n\n // Validate parent exists (if not root)\n if (parentId !== null && !state.find(n => n.id === parentId)) {\n throw new ValidationError(`Parent node not found: ${parentId}`);\n }\n\n // Validate child type is allowed\n const parentType = getParentType(parentId);\n this._validateChildType(parentType, nodeType.type);\n\n // Validate single root\n if (parentId === null && state.some(n => n.parentId === null)) {\n throw new ValidationError(\"Tree already has a root node\");\n }\n\n // Apply defaults to node data\n const mergedData = applyDefaults(nodeType.data as AnyPrimitive, data as Partial<InferTreeNodeDataState<TNode>>) as InferTreeNodeDataState<TNode>;\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.insert, {\n id,\n type: nodeType.type,\n parentId,\n pos,\n data: mergedData,\n })\n );\n\n return id;\n },\n\n insertAt: <TNode extends AnyTreeNodePrimitive>(\n parentId: string | null,\n index: number,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string => {\n const state = getCurrentState();\n const siblings = getOrderedChildren(state, parentId);\n const clampedIndex = Math.max(0, Math.min(index, siblings.length));\n const leftPos = clampedIndex > 0 && siblings[clampedIndex - 1] ? siblings[clampedIndex - 1]!.pos : null;\n const rightPos = clampedIndex < siblings.length && siblings[clampedIndex] ? siblings[clampedIndex]!.pos : null;\n const pos = generateTreePosBetween(leftPos, rightPos);\n const id = env.generateId();\n\n // Validate parent exists (if not root)\n if (parentId !== null && !state.find(n => n.id === parentId)) {\n throw new ValidationError(`Parent node not found: ${parentId}`);\n }\n\n // Validate child type is allowed\n const parentType = getParentType(parentId);\n this._validateChildType(parentType, nodeType.type);\n\n // Validate single root\n if (parentId === null && state.some(n => n.parentId === null)) {\n throw new ValidationError(\"Tree already has a root node\");\n }\n\n // Apply defaults to node data\n const mergedData = applyDefaults(nodeType.data as AnyPrimitive, data as Partial<InferTreeNodeDataState<TNode>>) as InferTreeNodeDataState<TNode>;\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.insert, {\n id,\n type: nodeType.type,\n parentId,\n pos,\n data: mergedData,\n })\n );\n\n return id;\n },\n\n insertAfter: <TNode extends AnyTreeNodePrimitive>(\n siblingId: string,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string => {\n const state = getCurrentState();\n const sibling = state.find(n => n.id === siblingId);\n if (!sibling) {\n throw new ValidationError(`Sibling node not found: ${siblingId}`);\n }\n\n const parentId = sibling.parentId;\n const siblings = getOrderedChildren(state, parentId);\n const siblingIndex = siblings.findIndex(n => n.id === siblingId);\n const nextSibling = siblings[siblingIndex + 1];\n const pos = generateTreePosBetween(sibling.pos, nextSibling?.pos ?? null);\n const id = env.generateId();\n\n // Validate child type is allowed\n const parentType = getParentType(parentId);\n this._validateChildType(parentType, nodeType.type);\n\n // Apply defaults to node data\n const mergedData = applyDefaults(nodeType.data as AnyPrimitive, data as Partial<InferTreeNodeDataState<TNode>>) as InferTreeNodeDataState<TNode>;\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.insert, {\n id,\n type: nodeType.type,\n parentId,\n pos,\n data: mergedData,\n })\n );\n\n return id;\n },\n\n insertBefore: <TNode extends AnyTreeNodePrimitive>(\n siblingId: string,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string => {\n const state = getCurrentState();\n const sibling = state.find(n => n.id === siblingId);\n if (!sibling) {\n throw new ValidationError(`Sibling node not found: ${siblingId}`);\n }\n\n const parentId = sibling.parentId;\n const siblings = getOrderedChildren(state, parentId);\n const siblingIndex = siblings.findIndex(n => n.id === siblingId);\n const prevSibling = siblings[siblingIndex - 1];\n const pos = generateTreePosBetween(prevSibling?.pos ?? null, sibling.pos);\n const id = env.generateId();\n\n // Validate child type is allowed\n const parentType = getParentType(parentId);\n this._validateChildType(parentType, nodeType.type);\n\n // Apply defaults to node data\n const mergedData = applyDefaults(nodeType.data as AnyPrimitive, data as Partial<InferTreeNodeDataState<TNode>>) as InferTreeNodeDataState<TNode>;\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.insert, {\n id,\n type: nodeType.type,\n parentId,\n pos,\n data: mergedData,\n })\n );\n\n return id;\n },\n\n remove: (id: string) => {\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.remove, { id })\n );\n },\n\n move: (nodeId: string, newParentId: string | null, toIndex: number) => {\n const state = getCurrentState();\n const node = state.find(n => n.id === nodeId);\n if (!node) {\n throw new ValidationError(`Node not found: ${nodeId}`);\n }\n\n // Validate parent exists (if not moving to root)\n if (newParentId !== null && !state.find(n => n.id === newParentId)) {\n throw new ValidationError(`Parent node not found: ${newParentId}`);\n }\n\n // Validate no cycle\n if (wouldCreateCycle(state, nodeId, newParentId)) {\n throw new ValidationError(\"Move would create a cycle in the tree\");\n }\n\n // Validate child type is allowed in new parent\n const newParentType = newParentId === null ? null : state.find(n => n.id === newParentId)?.type ?? null;\n this._validateChildType(newParentType, node.type);\n\n // Validate not moving root to a parent\n if (node.parentId === null && newParentId !== null) {\n throw new ValidationError(\"Cannot move root node to have a parent\");\n }\n\n // Calculate new position among new siblings (excluding self)\n const siblings = getOrderedChildren(state, newParentId).filter(n => n.id !== nodeId);\n const clampedIndex = Math.max(0, Math.min(toIndex, siblings.length));\n const leftPos = clampedIndex > 0 && siblings[clampedIndex - 1] ? siblings[clampedIndex - 1]!.pos : null;\n const rightPos = clampedIndex < siblings.length && siblings[clampedIndex] ? siblings[clampedIndex]!.pos : null;\n const pos = generateTreePosBetween(leftPos, rightPos);\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.move, {\n id: nodeId,\n parentId: newParentId,\n pos,\n })\n );\n },\n\n moveAfter: (nodeId: string, siblingId: string) => {\n const state = getCurrentState();\n const node = state.find(n => n.id === nodeId);\n const sibling = state.find(n => n.id === siblingId);\n \n if (!node) {\n throw new ValidationError(`Node not found: ${nodeId}`);\n }\n if (!sibling) {\n throw new ValidationError(`Sibling node not found: ${siblingId}`);\n }\n\n const newParentId = sibling.parentId;\n\n // Validate no cycle\n if (wouldCreateCycle(state, nodeId, newParentId)) {\n throw new ValidationError(\"Move would create a cycle in the tree\");\n }\n\n // Validate child type is allowed in new parent\n const newParentType = newParentId === null ? null : state.find(n => n.id === newParentId)?.type ?? null;\n this._validateChildType(newParentType, node.type);\n\n // Validate not moving root to a parent\n if (node.parentId === null && newParentId !== null) {\n throw new ValidationError(\"Cannot move root node to have a parent\");\n }\n\n const siblings = getOrderedChildren(state, newParentId).filter(n => n.id !== nodeId);\n const siblingIndex = siblings.findIndex(n => n.id === siblingId);\n const nextSibling = siblings[siblingIndex + 1];\n const pos = generateTreePosBetween(sibling.pos, nextSibling?.pos ?? null);\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.move, {\n id: nodeId,\n parentId: newParentId,\n pos,\n })\n );\n },\n\n moveBefore: (nodeId: string, siblingId: string) => {\n const state = getCurrentState();\n const node = state.find(n => n.id === nodeId);\n const sibling = state.find(n => n.id === siblingId);\n \n if (!node) {\n throw new ValidationError(`Node not found: ${nodeId}`);\n }\n if (!sibling) {\n throw new ValidationError(`Sibling node not found: ${siblingId}`);\n }\n\n const newParentId = sibling.parentId;\n\n // Validate no cycle\n if (wouldCreateCycle(state, nodeId, newParentId)) {\n throw new ValidationError(\"Move would create a cycle in the tree\");\n }\n\n // Validate child type is allowed in new parent\n const newParentType = newParentId === null ? null : state.find(n => n.id === newParentId)?.type ?? null;\n this._validateChildType(newParentType, node.type);\n\n // Validate not moving root to a parent\n if (node.parentId === null && newParentId !== null) {\n throw new ValidationError(\"Cannot move root node to have a parent\");\n }\n\n const siblings = getOrderedChildren(state, newParentId).filter(n => n.id !== nodeId);\n const siblingIndex = siblings.findIndex(n => n.id === siblingId);\n const prevSibling = siblings[siblingIndex - 1];\n const pos = generateTreePosBetween(prevSibling?.pos ?? null, sibling.pos);\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.move, {\n id: nodeId,\n parentId: newParentId,\n pos,\n })\n );\n },\n\n moveToFirst: (nodeId: string, newParentId: string | null) => {\n const state = getCurrentState();\n const node = state.find(n => n.id === nodeId);\n \n if (!node) {\n throw new ValidationError(`Node not found: ${nodeId}`);\n }\n\n // Validate parent exists (if not moving to root)\n if (newParentId !== null && !state.find(n => n.id === newParentId)) {\n throw new ValidationError(`Parent node not found: ${newParentId}`);\n }\n\n // Validate no cycle\n if (wouldCreateCycle(state, nodeId, newParentId)) {\n throw new ValidationError(\"Move would create a cycle in the tree\");\n }\n\n // Validate child type is allowed in new parent\n const newParentType = newParentId === null ? null : state.find(n => n.id === newParentId)?.type ?? null;\n this._validateChildType(newParentType, node.type);\n\n // Validate not moving root to a parent\n if (node.parentId === null && newParentId !== null) {\n throw new ValidationError(\"Cannot move root node to have a parent\");\n }\n\n const siblings = getOrderedChildren(state, newParentId).filter(n => n.id !== nodeId);\n const firstPos = siblings.length > 0 ? siblings[0]!.pos : null;\n const pos = generateTreePosBetween(null, firstPos);\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.move, {\n id: nodeId,\n parentId: newParentId,\n pos,\n })\n );\n },\n\n moveToLast: (nodeId: string, newParentId: string | null) => {\n const state = getCurrentState();\n const node = state.find(n => n.id === nodeId);\n \n if (!node) {\n throw new ValidationError(`Node not found: ${nodeId}`);\n }\n\n // Validate parent exists (if not moving to root)\n if (newParentId !== null && !state.find(n => n.id === newParentId)) {\n throw new ValidationError(`Parent node not found: ${newParentId}`);\n }\n\n // Validate no cycle\n if (wouldCreateCycle(state, nodeId, newParentId)) {\n throw new ValidationError(\"Move would create a cycle in the tree\");\n }\n\n // Validate child type is allowed in new parent\n const newParentType = newParentId === null ? null : state.find(n => n.id === newParentId)?.type ?? null;\n this._validateChildType(newParentType, node.type);\n\n // Validate not moving root to a parent\n if (node.parentId === null && newParentId !== null) {\n throw new ValidationError(\"Cannot move root node to have a parent\");\n }\n\n const siblings = getOrderedChildren(state, newParentId).filter(n => n.id !== nodeId);\n const lastPos = siblings.length > 0 ? siblings[siblings.length - 1]!.pos : null;\n const pos = generateTreePosBetween(lastPos, null);\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.move, {\n id: nodeId,\n parentId: newParentId,\n pos,\n })\n );\n },\n\n at: <TNode extends AnyTreeNodePrimitive>(\n id: string,\n nodeType: TNode\n ): InferProxy<TNode[\"data\"]> => {\n // Get the node to verify its type\n const state = getCurrentState();\n const node = state.find(n => n.id === id);\n if (!node) {\n throw new ValidationError(`Node not found: ${id}`);\n }\n if (node.type !== nodeType.type) {\n throw new ValidationError(\n `Node is of type \"${node.type}\", not \"${nodeType.type}\"`\n );\n }\n\n const nodePath = operationPath.append(id);\n return nodeType.data._internal.createProxy(env, nodePath) as InferProxy<TNode[\"data\"]>;\n },\n\n updateAt: <TNode extends AnyTreeNodePrimitive>(\n id: string,\n nodeType: TNode,\n value: TreeNodeUpdateValue<TNode>\n ): void => {\n // Get the node to verify its type\n const state = getCurrentState();\n const node = state.find(n => n.id === id);\n if (!node) {\n throw new ValidationError(`Node not found: ${id}`);\n }\n if (node.type !== nodeType.type) {\n throw new ValidationError(\n `Node is of type \"${node.type}\", not \"${nodeType.type}\"`\n );\n }\n\n const nodePath = operationPath.append(id);\n const dataProxy = nodeType.data._internal.createProxy(env, nodePath);\n // Delegate to the data proxy's update method\n (dataProxy as { update: (v: unknown) => void }).update(value);\n },\n\n toSnapshot: (): TreeNodeSnapshot<TRoot> | undefined => {\n const state = getCurrentState();\n const rootNode = state.find(n => n.parentId === null);\n if (!rootNode) return undefined;\n return buildSnapshot(rootNode.id, state);\n },\n };\n },\n\n applyOperation: (\n state: TreeState<TRoot> | undefined,\n operation: Operation.Operation<any, any, any>\n ): TreeState<TRoot> => {\n const path = operation.path;\n const tokens = path.toTokens().filter((t: string) => t !== \"\");\n const currentState = state ?? [];\n\n let newState: TreeState<TRoot>;\n\n // If path is empty, this is a tree-level operation\n if (tokens.length === 0) {\n switch (operation.kind) {\n case \"tree.set\": {\n const payload = operation.payload;\n if (!globalThis.Array.isArray(payload)) {\n throw new ValidationError(`TreePrimitive.set requires an array payload`);\n }\n newState = payload as TreeState<TRoot>;\n break;\n }\n case \"tree.insert\": {\n const { id, type, parentId, pos, data } = operation.payload as {\n id: string;\n type: string;\n parentId: string | null;\n pos: string;\n data: unknown;\n };\n newState = [...currentState, { id, type, parentId, pos, data }] as TreeState<TRoot>;\n break;\n }\n case \"tree.remove\": {\n const { id } = operation.payload as { id: string };\n // Get all descendants to remove\n const descendantIds = getDescendantIds(currentState, id);\n const idsToRemove = new Set([id, ...descendantIds]);\n newState = currentState.filter(node => !idsToRemove.has(node.id));\n break;\n }\n case \"tree.move\": {\n const { id, parentId, pos } = operation.payload as {\n id: string;\n parentId: string | null;\n pos: string;\n };\n newState = currentState.map(node =>\n node.id === id ? { ...node, parentId, pos } : node\n ) as TreeState<TRoot>;\n break;\n }\n default:\n throw new ValidationError(`TreePrimitive cannot apply operation of kind: ${operation.kind}`);\n }\n } else {\n // Otherwise, delegate to the node's data primitive\n const nodeId = tokens[0]!;\n const nodeIndex = currentState.findIndex(node => node.id === nodeId);\n \n if (nodeIndex === -1) {\n throw new ValidationError(`Tree node not found with ID: ${nodeId}`);\n }\n\n const node = currentState[nodeIndex]!;\n const nodeTypePrimitive = this._getNodeTypePrimitive(node.type);\n const remainingPath = path.shift();\n const nodeOperation = {\n ...operation,\n path: remainingPath,\n };\n\n const newData = nodeTypePrimitive.data._internal.applyOperation(\n node.data as InferStructState<any> | undefined,\n nodeOperation\n );\n\n const mutableState = [...currentState];\n mutableState[nodeIndex] = { ...node, data: newData };\n newState = mutableState as TreeState<TRoot>;\n }\n\n // Run validators on the new state\n runValidators(newState, this._schema.validators);\n\n return newState;\n },\n\n getInitialState: (): TreeState<TRoot> | undefined => {\n if (this._schema.defaultInput !== undefined) {\n // Convert nested input to flat TreeState\n return this._convertNestedToFlat(this._schema.defaultInput);\n }\n\n // Automatically create a root node with default data\n const rootNodeType = this._schema.root;\n const rootData = rootNodeType.data._internal.getInitialState() ?? {};\n const rootId = crypto.randomUUID();\n const rootPos = generateTreePosBetween(null, null);\n\n return [{\n id: rootId,\n type: rootNodeType.type,\n parentId: null,\n pos: rootPos,\n data: rootData,\n }] as TreeState<TRoot>;\n },\n\n convertSetInputToState: (input: unknown): TreeState<TRoot> => {\n // Convert nested input format to flat TreeState\n return this._convertNestedToFlat(input as TreeNodeSetInput<TRoot>);\n },\n\n transformOperation: (\n clientOp: Operation.Operation<any, any, any>,\n serverOp: Operation.Operation<any, any, any>\n ): Transform.TransformResult => {\n const clientPath = clientOp.path;\n const serverPath = serverOp.path;\n\n // If paths don't overlap at all, no transformation needed\n if (!OperationPath.pathsOverlap(clientPath, serverPath)) {\n return { type: \"transformed\", operation: clientOp };\n }\n\n // Handle tree.remove from server - check if client is operating on removed node or descendants\n if (serverOp.kind === \"tree.remove\") {\n const removedId = (serverOp.payload as { id: string }).id;\n const clientTokens = clientPath.toTokens().filter((t: string) => t !== \"\");\n const serverTokens = serverPath.toTokens().filter((t: string) => t !== \"\");\n\n // Check if client operation targets the removed node or uses it\n if (clientOp.kind === \"tree.move\") {\n const movePayload = clientOp.payload as { id: string; parentId: string | null };\n // If moving the removed node or moving to a removed parent\n if (movePayload.id === removedId || movePayload.parentId === removedId) {\n return { type: \"noop\" };\n }\n }\n\n if (clientOp.kind === \"tree.insert\") {\n const insertPayload = clientOp.payload as { parentId: string | null };\n // If inserting into a removed parent\n if (insertPayload.parentId === removedId) {\n return { type: \"noop\" };\n }\n }\n\n // Check if client is operating on a node that was removed\n if (clientTokens.length > serverTokens.length) {\n const nodeId = clientTokens[serverTokens.length];\n if (nodeId === removedId) {\n return { type: \"noop\" };\n }\n }\n }\n\n // Both inserting - no conflict (fractional indexing handles order)\n if (serverOp.kind === \"tree.insert\" && clientOp.kind === \"tree.insert\") {\n return { type: \"transformed\", operation: clientOp };\n }\n\n // Both moving same node - client wins\n if (serverOp.kind === \"tree.move\" && clientOp.kind === \"tree.move\") {\n const serverMoveId = (serverOp.payload as { id: string }).id;\n const clientMoveId = (clientOp.payload as { id: string }).id;\n\n if (serverMoveId === clientMoveId) {\n return { type: \"transformed\", operation: clientOp };\n }\n // Different nodes - no conflict\n return { type: \"transformed\", operation: clientOp };\n }\n\n // For same exact path: client wins (last-write-wins)\n if (OperationPath.pathsEqual(clientPath, serverPath)) {\n return { type: \"transformed\", operation: clientOp };\n }\n\n // If server set entire tree and client is operating on a node\n if (serverOp.kind === \"tree.set\" && OperationPath.isPrefix(serverPath, clientPath)) {\n return { type: \"transformed\", operation: clientOp };\n }\n\n // Delegate to node data primitive for nested operations\n const clientTokens = clientPath.toTokens().filter((t: string) => t !== \"\");\n const serverTokens = serverPath.toTokens().filter((t: string) => t !== \"\");\n\n // Both operations target children of this tree\n if (clientTokens.length > 0 && serverTokens.length > 0) {\n const clientNodeId = clientTokens[0];\n const serverNodeId = serverTokens[0];\n\n // If operating on different nodes, no conflict\n if (clientNodeId !== serverNodeId) {\n return { type: \"transformed\", operation: clientOp };\n }\n\n // Same node - would need to delegate to node's data primitive\n // For simplicity, let client win\n return { type: \"transformed\", operation: clientOp };\n }\n\n // Default: no transformation needed\n return { type: \"transformed\", operation: clientOp };\n },\n };\n}\n\n/** Options for creating a Tree primitive */\nexport interface TreeOptions<TRoot extends AnyTreeNodePrimitive> {\n /** The root node type */\n readonly root: TRoot;\n}\n\n/** Creates a new TreePrimitive with the given root node type */\nexport const Tree = <TRoot extends AnyTreeNodePrimitive>(\n options: TreeOptions<TRoot>\n): TreePrimitive<TRoot, false, false> =>\n new TreePrimitive({\n required: false,\n defaultInput: undefined,\n root: options.root,\n validators: [],\n });\n"],"mappings":";;;;;;;;;;;;CAijBc;CAAa;CAAS;;;;;AApgBpC,MAAM,sBACJ,OACA,aACoB;AACpB,QAAO,CAAC,GAAG,MAAM,CACd,QAAO,MAAK,EAAE,aAAa,SAAS,CACpC,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,EAAE,MAAM,EAAE,MAAM,IAAI,EAAE;;;;;AAM/D,MAAM,oBACJ,OACA,WACa;CACb,MAAM,WAAW,MAAM,QAAO,MAAK,EAAE,aAAa,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GAGnD,MAAM,gBAAgB,KAAK,sBAAsB,UAAU,KAAK;GAGhE,MAAM,sBAAK,UAAU,2DAAM,YAAY;AAGvC,OAAI,QAAQ,IAAI,GAAG,CACjB,OAAM,IAAI,gBAAgB,sBAAsB,KAAK;AAEvD,WAAQ,IAAI,GAAG;GAGf,MAAM,MAAM,uBAAuB,SAAS,SAAS;GAGrD,MAAM,EAAE,MAAM,OAAO,IAAI,KAAK,wBAAa,sCAAe;GAG1D,MAAM,aAAa,cAAc,cAAc,MAAsB,WAAW;AAGhF,UAAO,KAAK;IACV;IACA,MAAM,UAAU;IAChB;IACA;IACA,MAAM;IACP,CAAC;GAGF,IAAIC,eAA8B;AAClC,QAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;IACxC,MAAM,aAAa,SAAS;AAE5B,gBAAY,YAAY,IAAI,UAAU,MAAM,cAAc,KAAK;AAE/D,mBAAe,OAAO,OAAO,SAAS,GAAI;;;AAK9C,cAAY,OAAuC,MAAM,MAAM,MAAM,KAAK;AAE1E,SAAO;;;;AA+xBX,MAAa,QACX,YAEA,IAAI,cAAc;CAChB,UAAU;CACV,cAAc;CACd,MAAM,QAAQ;CACd,YAAY,EAAE;CACf,CAAC"}
1
+ {"version":3,"file":"Tree.mjs","names":["descendantIds: string[]","FractionalIndex.base62CharSet","FractionalIndex.generateKeyBetween","OperationDefinition.make","children: TreeNodeSnapshot<any>[]","Operation.fromDefinition","newState: TreeState<TRoot>","node","OperationPath.pathsOverlap","clientTokens","serverTokens","OperationPath.pathsEqual","OperationPath.isPrefix","result: TreeNodeState[]","prevChildPos: string | null"],"sources":["../../src/primitives/Tree.ts"],"sourcesContent":["import { Effect, Schema } from \"effect\";\nimport * as OperationDefinition from \"../OperationDefinition\";\nimport * as Operation from \"../Operation\";\nimport * as OperationPath from \"../OperationPath\";\nimport * as ProxyEnvironment from \"../ProxyEnvironment\";\nimport * as Transform from \"../Transform\";\nimport * as FractionalIndex from \"../FractionalIndex\";\nimport type { Primitive, PrimitiveInternal, Validator, InferProxy, AnyPrimitive, InferSetInput, InferUpdateInput } from \"./shared\";\nimport { ValidationError, applyDefaults } from \"./shared\";\nimport { runValidators } from \"./shared\";\nimport type { AnyTreeNodePrimitive, InferTreeNodeType, InferTreeNodeDataState, InferTreeNodeChildren } from \"./TreeNode\";\nimport { InferStructState, StructSetInput, StructUpdateValue } from \"./Struct\";\nimport { StructPrimitive } from \"./Struct\";\n\n\n/**\n * A node in the tree state (flat storage format)\n */\nexport interface TreeNodeState {\n readonly id: string; // Unique node identifier (UUID)\n readonly type: string; // Node type discriminator\n readonly parentId: string | null; // Parent node ID (null for root)\n readonly pos: string; // Fractional index for sibling ordering\n readonly data: unknown; // Node-specific data\n}\n\n/**\n * Typed node state for a specific node type\n */\nexport interface TypedTreeNodeState<TNode extends AnyTreeNodePrimitive> {\n readonly id: string;\n readonly type: InferTreeNodeType<TNode>;\n readonly parentId: string | null;\n readonly pos: string;\n readonly data: InferTreeNodeDataState<TNode>;\n}\n\n/**\n * The state type for trees - a flat array of nodes\n */\nexport type TreeState<_TRoot extends AnyTreeNodePrimitive> = readonly TreeNodeState[];\n\n/**\n * Helper to get children sorted by position\n */\nconst getOrderedChildren = (\n nodes: readonly TreeNodeState[],\n parentId: string | null\n): TreeNodeState[] => {\n return [...nodes]\n .filter(n => n.parentId === parentId)\n .sort((a, b) => a.pos < b.pos ? -1 : a.pos > b.pos ? 1 : 0);\n};\n\n/**\n * Get all descendant IDs of a node (recursive)\n */\nconst getDescendantIds = (\n nodes: readonly TreeNodeState[],\n nodeId: string\n): string[] => {\n const children = nodes.filter(n => n.parentId === nodeId);\n const descendantIds: string[] = [];\n for (const child of children) {\n descendantIds.push(child.id);\n descendantIds.push(...getDescendantIds(nodes, child.id));\n }\n return descendantIds;\n};\n\n/**\n * Check if moving a node to a new parent would create a cycle\n */\nconst wouldCreateCycle = (\n nodes: readonly TreeNodeState[],\n nodeId: string,\n newParentId: string | null\n): boolean => {\n if (newParentId === null) return false;\n if (newParentId === nodeId) return true;\n \n const descendants = getDescendantIds(nodes, nodeId);\n return descendants.includes(newParentId);\n};\n\n/**\n * Generate a fractional position between two positions\n */\nconst generateTreePosBetween = (left: string | null, right: string | null): string => {\n const charSet = FractionalIndex.base62CharSet();\n return Effect.runSync(FractionalIndex.generateKeyBetween(left, right, charSet));\n};\n\n/**\n * Snapshot of a single node for UI rendering (data properties spread at node level)\n */\nexport type TreeNodeSnapshot<TNode extends AnyTreeNodePrimitive> = {\n readonly id: string;\n readonly pos: string;\n readonly parentId: string | null;\n readonly type: InferTreeNodeType<TNode>;\n readonly children: TreeNodeSnapshot<InferTreeNodeChildren<TNode>>[];\n} & InferTreeNodeDataState<TNode>;\n\n/**\n * Infer the snapshot type for a tree (recursive tree structure for UI)\n */\nexport type InferTreeSnapshot<T extends TreePrimitive<any>> =\n T extends TreePrimitive<infer TRoot> ? TreeNodeSnapshot<TRoot> : never;\n\n/**\n * Helper type to infer the update value type from a TreeNode's data.\n * Uses StructUpdateValue directly to get field-level partial update semantics.\n * All fields are optional in update operations.\n */\nexport type TreeNodeUpdateValue<TNode extends AnyTreeNodePrimitive> = \n TNode[\"data\"] extends StructPrimitive<infer TFields, any, any>\n ? StructUpdateValue<TFields>\n : InferUpdateInput<TNode[\"data\"]>;\n\n/**\n * Helper type to infer the input type for node data (respects field defaults).\n * Uses StructSetInput directly so that:\n * - Fields that are required AND have no default must be provided\n * - Fields that are optional OR have defaults can be omitted\n *\n * This bypasses the struct-level NeedsValue wrapper since tree inserts\n * always require a data object (even if empty for all-optional fields).\n */\nexport type TreeNodeDataSetInput<TNode extends AnyTreeNodePrimitive> =\n TNode[\"data\"] extends StructPrimitive<infer TFields, any, any>\n ? StructSetInput<TFields>\n : InferSetInput<TNode[\"data\"]>;\n\n// =============================================================================\n// Nested Input Types for set() and default()\n// =============================================================================\n\n/**\n * Type guard to check if a type is `any` or unknown (structural check).\n * Returns true if T is `any`, false otherwise.\n */\ntype IsAny<T> = 0 extends (1 & T) ? true : false;\n\n/**\n * Get children types, with special handling for self-referential nodes.\n * When InferTreeNodeChildren returns `any` (from TreeNodePrimitive<..., any>),\n * we fall back to using TNode itself as its own child type.\n * This handles the common case of self-referential nodes like:\n * FolderNode = TreeNode(\"folder\", { children: [TreeNodeSelf, FileNode] })\n * Where FolderNode's TChildren is resolved to FolderNode | FileNode,\n * but the self-referenced FolderNode has TChildren = any.\n */\ntype ResolveChildrenForInput<TNode extends AnyTreeNodePrimitive, TOriginalNode extends AnyTreeNodePrimitive> =\n IsAny<InferTreeNodeChildren<TNode>> extends true\n ? TOriginalNode // Self-reference: use the original node's type\n : InferTreeNodeChildren<TNode>;\n\n/**\n * Helper type that creates a properly typed node input for a specific node type.\n * This is the \"strict\" version that enforces exact property matching.\n *\n * The TOriginalNode parameter is used to track the original root node type\n * for proper self-reference resolution in deeply nested structures.\n */\ntype TreeNodeSetInputStrictWithRoot<TNode extends AnyTreeNodePrimitive, TOriginalNode extends AnyTreeNodePrimitive> = {\n readonly type: InferTreeNodeType<TNode>;\n readonly id?: string;\n readonly children: TreeNodeSetInputUnionWithRoot<ResolveChildrenForInput<TNode, TOriginalNode>, TOriginalNode>[];\n} & TreeNodeDataSetInput<TNode>;\n\n/**\n * Distributive conditional type that creates a union of TreeNodeSetInputStrict\n * for each node type in the union. This ensures proper type discrimination.\n *\n * When TNode is a union (e.g., FolderNode | FileNode), this distributes to:\n * TreeNodeSetInputStrict<FolderNode> | TreeNodeSetInputStrict<FileNode>\n *\n * This creates a proper discriminated union where excess property checking works.\n */\ntype TreeNodeSetInputUnionWithRoot<TNode extends AnyTreeNodePrimitive, TOriginalNode extends AnyTreeNodePrimitive> =\n TNode extends AnyTreeNodePrimitive ? TreeNodeSetInputStrictWithRoot<TNode, TOriginalNode> : never;\n\n/**\n * Helper type for single-parameter usage - uses TNode as its own original.\n */\ntype TreeNodeSetInputStrict<TNode extends AnyTreeNodePrimitive> =\n TreeNodeSetInputStrictWithRoot<TNode, TNode>;\n\n/**\n * Distributive conditional for single-parameter usage.\n */\nexport type TreeNodeSetInputUnion<TNode extends AnyTreeNodePrimitive> =\n TNode extends AnyTreeNodePrimitive ? TreeNodeSetInputStrict<TNode> : never;\n\n/**\n * Input type for a single node in a nested tree set/default operation.\n *\n * - `type` is REQUIRED - explicit type discriminator for the node\n * - `id` is optional - auto-generated if not provided\n * - `children` is a typed array of allowed child node inputs\n * - Data fields are spread at the node level (like TreeNodeSnapshot)\n *\n * When TNode is a union type (e.g., from InferTreeNodeChildren), this properly\n * distributes to create a discriminated union where:\n * - Each variant has its specific `type` literal\n * - Each variant has its specific data fields\n * - Excess property checking works correctly\n *\n * @example\n * ```typescript\n * const input: TreeNodeSetInput<BoardNode> = {\n * type: \"board\",\n * name: \"My Board\",\n * children: [\n * { type: \"column\", name: \"Todo\", children: [] }\n * ]\n * };\n * ```\n */\nexport type TreeNodeSetInput<TNode extends AnyTreeNodePrimitive> = TreeNodeSetInputUnion<TNode>;\n\n/**\n * Input type for tree set() and default() operations.\n * Accepts a nested tree structure that will be converted to flat TreeState internally.\n */\nexport type TreeSetInput<TRoot extends AnyTreeNodePrimitive> = TreeNodeSetInput<TRoot>;\n\n/**\n * Infer the set input type for a tree primitive.\n */\nexport type InferTreeSetInput<T extends TreePrimitive<any>> =\n T extends TreePrimitive<infer TRoot> ? TreeSetInput<TRoot> : never;\n\n/**\n * Internal type for processing any node input during conversion.\n * This is only used internally in _convertNestedToFlat and is not exported.\n * Allows us to keep the public TreeNodeSetInput<TNode> fully type-safe while\n * having a runtime-compatible type for internal processing.\n */\ntype InternalNodeInput = {\n readonly type: string;\n readonly id?: string;\n readonly children: InternalNodeInput[];\n readonly [key: string]: unknown;\n};\n\n/**\n * Typed proxy for a specific node type - provides type-safe data access\n */\nexport interface TypedNodeProxy<TNode extends AnyTreeNodePrimitive> {\n /** The node ID */\n readonly id: string;\n /** The node type */\n readonly type: InferTreeNodeType<TNode>;\n /** Access the node's data proxy */\n readonly data: InferProxy<TNode[\"data\"]>;\n /** Get the raw node state */\n get(): TypedTreeNodeState<TNode>;\n /** Updates only the specified data fields (partial update, handles nested structs recursively) */\n update(value: TreeNodeUpdateValue<TNode>): void;\n}\n\n/**\n * Node proxy with type narrowing capabilities\n */\nexport interface TreeNodeProxyBase<_TRoot extends AnyTreeNodePrimitive> {\n /** The node ID */\n readonly id: string;\n /** The node type (string) */\n readonly type: string;\n /** Type guard - narrows the proxy to a specific node type */\n is<TNode extends AnyTreeNodePrimitive>(\n nodeType: TNode\n ): this is TypedNodeProxy<TNode>;\n /** Type assertion - returns typed proxy (throws if wrong type) */\n as<TNode extends AnyTreeNodePrimitive>(\n nodeType: TNode\n ): TypedNodeProxy<TNode>;\n /** Get the raw node state */\n get(): TreeNodeState;\n}\n\n/**\n * Proxy for accessing and modifying tree nodes\n */\nexport interface TreeProxy<TRoot extends AnyTreeNodePrimitive> {\n /** Gets the entire tree state (flat array of nodes) */\n get(): TreeState<TRoot>;\n\n /** Replaces the entire tree with a nested input structure */\n set(input: TreeSetInput<TRoot>): void;\n \n /** Gets the root node state */\n root(): TypedTreeNodeState<TRoot> | undefined;\n \n /** Gets ordered children states of a parent (null for root's children) */\n children(parentId: string | null): TreeNodeState[];\n \n /** Gets a node proxy by ID with type narrowing capabilities */\n node(id: string): TreeNodeProxyBase<TRoot> | undefined;\n \n /** Insert a new node as the first child (applies defaults for node data) */\n insertFirst<TNode extends AnyTreeNodePrimitive>(\n parentId: string | null,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string;\n \n /** Insert a new node as the last child (applies defaults for node data) */\n insertLast<TNode extends AnyTreeNodePrimitive>(\n parentId: string | null,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string;\n \n /** Insert a new node at a specific index among siblings (applies defaults for node data) */\n insertAt<TNode extends AnyTreeNodePrimitive>(\n parentId: string | null,\n index: number,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string;\n \n /** Insert a new node after a sibling (applies defaults for node data) */\n insertAfter<TNode extends AnyTreeNodePrimitive>(\n siblingId: string,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string;\n \n /** Insert a new node before a sibling (applies defaults for node data) */\n insertBefore<TNode extends AnyTreeNodePrimitive>(\n siblingId: string,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string;\n \n /** Remove a node and all its descendants */\n remove(id: string): void;\n \n /** Move a node to a new parent at a specific index */\n move(nodeId: string, newParentId: string | null, toIndex: number): void;\n \n /** Move a node after a sibling */\n moveAfter(nodeId: string, siblingId: string): void;\n \n /** Move a node before a sibling */\n moveBefore(nodeId: string, siblingId: string): void;\n \n /** Move a node to be the first child of a parent */\n moveToFirst(nodeId: string, newParentId: string | null): void;\n \n /** Move a node to be the last child of a parent */\n moveToLast(nodeId: string, newParentId: string | null): void;\n \n /** Returns a typed proxy for a specific node's data */\n at<TNode extends AnyTreeNodePrimitive>(\n id: string,\n nodeType: TNode\n ): InferProxy<TNode[\"data\"]>;\n \n /** Updates only the specified data fields of a node (partial update) */\n updateAt<TNode extends AnyTreeNodePrimitive>(\n id: string,\n nodeType: TNode,\n value: TreeNodeUpdateValue<TNode>\n ): void;\n \n /** Convert tree to a nested snapshot for UI rendering */\n toSnapshot(): TreeNodeSnapshot<TRoot> | undefined;\n}\n\ninterface TreePrimitiveSchema<TRoot extends AnyTreeNodePrimitive> {\n readonly required: boolean;\n readonly defaultInput: TreeNodeSetInput<TRoot> | undefined;\n readonly root: TRoot;\n readonly validators: readonly Validator<TreeState<TRoot>>[];\n}\n\n/** Input type for tree update() - same as set() for trees (nested format) */\nexport type TreeUpdateInput<TRoot extends AnyTreeNodePrimitive> = TreeNodeSetInput<TRoot>;\n\nexport class TreePrimitive<TRoot extends AnyTreeNodePrimitive, TRequired extends boolean = false, THasDefault extends boolean = false>\n implements Primitive<TreeState<TRoot>, TreeProxy<TRoot>, TRequired, THasDefault, TreeSetInput<TRoot>, TreeUpdateInput<TRoot>>\n{\n readonly _tag = \"TreePrimitive\" as const;\n readonly _State!: TreeState<TRoot>;\n readonly _Proxy!: TreeProxy<TRoot>;\n readonly _TRequired!: TRequired;\n readonly _THasDefault!: THasDefault;\n readonly TSetInput!: TreeSetInput<TRoot>;\n readonly TUpdateInput!: TreeUpdateInput<TRoot>;\n\n private readonly _schema: TreePrimitiveSchema<TRoot>;\n private _nodeTypeRegistry: Map<string, AnyTreeNodePrimitive> | undefined;\n\n private readonly _opDefinitions = {\n set: OperationDefinition.make({\n kind: \"tree.set\" as const,\n payload: Schema.Unknown,\n target: Schema.Unknown,\n apply: (payload) => payload,\n }),\n insert: OperationDefinition.make({\n kind: \"tree.insert\" as const,\n payload: Schema.Unknown,\n target: Schema.Unknown,\n apply: (payload) => payload,\n }),\n remove: OperationDefinition.make({\n kind: \"tree.remove\" as const,\n payload: Schema.Unknown,\n target: Schema.Unknown,\n apply: (payload) => payload,\n }),\n move: OperationDefinition.make({\n kind: \"tree.move\" as const,\n payload: Schema.Unknown,\n target: Schema.Unknown,\n apply: (payload) => payload,\n }),\n };\n\n constructor(schema: TreePrimitiveSchema<TRoot>) {\n this._schema = schema;\n }\n\n /** Mark this tree as required */\n required(): TreePrimitive<TRoot, true, THasDefault> {\n return new TreePrimitive({\n ...this._schema,\n required: true,\n });\n }\n\n /** Set a default value for this tree (nested format) */\n default(defaultInput: TreeNodeSetInput<TRoot>): TreePrimitive<TRoot, TRequired, true> {\n return new TreePrimitive({\n ...this._schema,\n defaultInput,\n });\n }\n\n /** Get the root node type */\n get root(): TRoot {\n return this._schema.root;\n }\n\n /** Add a custom validation rule */\n refine(fn: (value: TreeState<TRoot>) => boolean, message: string): TreePrimitive<TRoot, TRequired, THasDefault> {\n return new TreePrimitive({\n ...this._schema,\n validators: [...this._schema.validators, { validate: fn, message }],\n });\n }\n\n /**\n * Build a registry of all node types reachable from root\n */\n private _buildNodeTypeRegistry(): Map<string, AnyTreeNodePrimitive> {\n if (this._nodeTypeRegistry !== undefined) {\n return this._nodeTypeRegistry;\n }\n\n const registry = new Map<string, AnyTreeNodePrimitive>();\n const visited = new Set<string>();\n\n const visit = (node: AnyTreeNodePrimitive) => {\n if (visited.has(node.type)) return;\n visited.add(node.type);\n registry.set(node.type, node);\n\n for (const child of node.children) {\n visit(child);\n }\n };\n\n visit(this._schema.root);\n this._nodeTypeRegistry = registry;\n return registry;\n }\n\n /**\n * Get a node type primitive by its type string\n */\n private _getNodeTypePrimitive(type: string): AnyTreeNodePrimitive {\n const registry = this._buildNodeTypeRegistry();\n const nodeType = registry.get(type);\n if (!nodeType) {\n throw new ValidationError(`Unknown node type: ${type}`);\n }\n return nodeType;\n }\n\n /**\n * Validate that a node type can be a child of a parent node type\n */\n private _validateChildType(\n parentType: string | null,\n childType: string\n ): void {\n if (parentType === null) {\n // Root level - child must be the root type\n if (childType !== this._schema.root.type) {\n throw new ValidationError(\n `Root node must be of type \"${this._schema.root.type}\", got \"${childType}\"`\n );\n }\n return;\n }\n\n const parentNodePrimitive = this._getNodeTypePrimitive(parentType);\n if (!parentNodePrimitive.isChildAllowed(childType)) {\n const allowedTypes = parentNodePrimitive.children.map(c => c.type).join(\", \");\n throw new ValidationError(\n `Node type \"${childType}\" is not allowed as a child of \"${parentType}\". ` +\n `Allowed types: ${allowedTypes || \"none\"}`\n );\n }\n }\n\n /**\n * Convert a nested TreeNodeSetInput to flat TreeState format.\n * Recursively processes nodes, generating IDs and positions as needed.\n *\n * @param input - The root nested input to convert\n * @param generateId - Optional ID generator (defaults to crypto.randomUUID)\n * @returns Flat TreeState array\n */\n private _convertNestedToFlat(\n input: TreeNodeSetInput<TRoot>,\n generateId: () => string = () => crypto.randomUUID()\n ): TreeState<TRoot> {\n const result: TreeNodeState[] = [];\n const seenIds = new Set<string>();\n\n const processNode = (\n nodeInput: InternalNodeInput,\n parentId: string | null,\n parentType: string | null,\n leftPos: string | null,\n rightPos: string | null\n ): void => {\n // Validate node type\n this._validateChildType(parentType, nodeInput.type);\n\n // Get the node primitive for this type\n const nodePrimitive = this._getNodeTypePrimitive(nodeInput.type);\n\n // Generate or use provided ID\n const id = nodeInput.id ?? generateId();\n\n // Check for duplicate IDs\n if (seenIds.has(id)) {\n throw new ValidationError(`Duplicate node ID: ${id}`);\n }\n seenIds.add(id);\n\n // Generate position\n const pos = generateTreePosBetween(leftPos, rightPos);\n\n // Extract data fields (everything except type, id, and children)\n const { type: _type, id: _id, children, ...dataFields } = nodeInput;\n\n // Apply defaults to node data\n const mergedData = applyDefaults(nodePrimitive.data as AnyPrimitive, dataFields);\n\n // Add this node to result\n result.push({\n id,\n type: nodeInput.type,\n parentId,\n pos,\n data: mergedData,\n });\n\n // Process children recursively\n let prevChildPos: string | null = null;\n for (let i = 0; i < children.length; i++) {\n const childInput = children[i]!;\n // Each child gets a position after the previous child\n processNode(childInput, id, nodeInput.type, prevChildPos, null);\n // Update prevChildPos to the pos that was just assigned (it's the last item in result)\n prevChildPos = result[result.length - 1]!.pos;\n }\n };\n\n // Process root node (cast to InternalNodeInput for internal processing)\n processNode(input as unknown as InternalNodeInput, null, null, null, null);\n\n return result as TreeState<TRoot>;\n }\n\n readonly _internal: PrimitiveInternal<TreeState<TRoot>, TreeProxy<TRoot>> = {\n createProxy: (\n env: ProxyEnvironment.ProxyEnvironment,\n operationPath: OperationPath.OperationPath\n ): TreeProxy<TRoot> => {\n // Helper to get current state\n const getCurrentState = (): TreeState<TRoot> => {\n const state = env.getState(operationPath) as TreeState<TRoot> | undefined;\n return state ?? [];\n };\n\n // Helper to get parent type from state\n const getParentType = (parentId: string | null): string | null => {\n if (parentId === null) return null;\n const state = getCurrentState();\n const parent = state.find(n => n.id === parentId);\n return parent?.type ?? null;\n };\n\n // Helper to create a node proxy with type narrowing\n const createNodeProxy = (nodeState: TreeNodeState): TreeNodeProxyBase<TRoot> => {\n return {\n id: nodeState.id,\n type: nodeState.type,\n \n is: <TNode extends AnyTreeNodePrimitive>(\n nodeType: TNode\n ): boolean => {\n return nodeState.type === nodeType.type;\n },\n \n as: <TNode extends AnyTreeNodePrimitive>(\n nodeType: TNode\n ): TypedNodeProxy<TNode> => {\n if (nodeState.type !== nodeType.type) {\n throw new ValidationError(\n `Node is of type \"${nodeState.type}\", not \"${nodeType.type}\"`\n );\n }\n const nodePath = operationPath.append(nodeState.id);\n const dataProxy = nodeType.data._internal.createProxy(env, nodePath) as InferProxy<TNode[\"data\"]>;\n return {\n id: nodeState.id,\n type: nodeType.type as InferTreeNodeType<TNode>,\n data: dataProxy,\n get: () => nodeState as TypedTreeNodeState<TNode>,\n update: (value: TreeNodeUpdateValue<TNode>) => {\n // Delegate to the data proxy's update method\n (dataProxy as { update: (v: unknown) => void }).update(value);\n },\n };\n },\n \n get: () => nodeState,\n } as TreeNodeProxyBase<TRoot>;\n };\n\n // Helper to build recursive snapshot\n const buildSnapshot = (\n nodeId: string,\n nodes: readonly TreeNodeState[]\n ): TreeNodeSnapshot<TRoot> | undefined => {\n const node = nodes.find(n => n.id === nodeId);\n if (!node) return undefined;\n\n const childNodes = getOrderedChildren(nodes, nodeId);\n const children: TreeNodeSnapshot<any>[] = [];\n for (const child of childNodes) {\n const childSnapshot = buildSnapshot(child.id, nodes);\n if (childSnapshot) {\n children.push(childSnapshot);\n }\n }\n\n // Spread data properties at node level\n return {\n id: node.id,\n type: node.type,\n pos: node.pos,\n parentId: node.parentId,\n ...(node.data as object),\n children,\n } as unknown as TreeNodeSnapshot<TRoot>;\n };\n\n return {\n get: (): TreeState<TRoot> => {\n return getCurrentState();\n },\n\n set: (input: TreeSetInput<TRoot>) => {\n // Convert nested input to flat TreeState using env.generateId for IDs\n const flatState = this._convertNestedToFlat(input, env.generateId);\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.set, flatState)\n );\n },\n\n root: (): TypedTreeNodeState<TRoot> | undefined => {\n const state = getCurrentState();\n const rootNode = state.find(n => n.parentId === null);\n return rootNode as TypedTreeNodeState<TRoot> | undefined;\n },\n\n children: (parentId: string | null): TreeNodeState[] => {\n const state = getCurrentState();\n return getOrderedChildren(state, parentId);\n },\n\n node: (id: string): TreeNodeProxyBase<TRoot> | undefined => {\n const state = getCurrentState();\n const nodeState = state.find(n => n.id === id);\n if (!nodeState) return undefined;\n return createNodeProxy(nodeState);\n },\n\n insertFirst: <TNode extends AnyTreeNodePrimitive>(\n parentId: string | null,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string => {\n const state = getCurrentState();\n const siblings = getOrderedChildren(state, parentId);\n const firstPos = siblings.length > 0 ? siblings[0]!.pos : null;\n const pos = generateTreePosBetween(null, firstPos);\n const id = env.generateId();\n\n // Validate parent exists (if not root)\n if (parentId !== null && !state.find(n => n.id === parentId)) {\n throw new ValidationError(`Parent node not found: ${parentId}`);\n }\n\n // Validate child type is allowed\n const parentType = getParentType(parentId);\n this._validateChildType(parentType, nodeType.type);\n\n // Validate single root\n if (parentId === null && state.some(n => n.parentId === null)) {\n throw new ValidationError(\"Tree already has a root node\");\n }\n\n // Apply defaults to node data\n const mergedData = applyDefaults(nodeType.data as AnyPrimitive, data as Partial<InferTreeNodeDataState<TNode>>) as InferTreeNodeDataState<TNode>;\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.insert, {\n id,\n type: nodeType.type,\n parentId,\n pos,\n data: mergedData,\n })\n );\n\n return id;\n },\n\n insertLast: <TNode extends AnyTreeNodePrimitive>(\n parentId: string | null,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string => {\n const state = getCurrentState();\n const siblings = getOrderedChildren(state, parentId);\n const lastPos = siblings.length > 0 ? siblings[siblings.length - 1]!.pos : null;\n const pos = generateTreePosBetween(lastPos, null);\n const id = env.generateId();\n\n // Validate parent exists (if not root)\n if (parentId !== null && !state.find(n => n.id === parentId)) {\n throw new ValidationError(`Parent node not found: ${parentId}`);\n }\n\n // Validate child type is allowed\n const parentType = getParentType(parentId);\n this._validateChildType(parentType, nodeType.type);\n\n // Validate single root\n if (parentId === null && state.some(n => n.parentId === null)) {\n throw new ValidationError(\"Tree already has a root node\");\n }\n\n // Apply defaults to node data\n const mergedData = applyDefaults(nodeType.data as AnyPrimitive, data as Partial<InferTreeNodeDataState<TNode>>) as InferTreeNodeDataState<TNode>;\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.insert, {\n id,\n type: nodeType.type,\n parentId,\n pos,\n data: mergedData,\n })\n );\n\n return id;\n },\n\n insertAt: <TNode extends AnyTreeNodePrimitive>(\n parentId: string | null,\n index: number,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string => {\n const state = getCurrentState();\n const siblings = getOrderedChildren(state, parentId);\n const clampedIndex = Math.max(0, Math.min(index, siblings.length));\n const leftPos = clampedIndex > 0 && siblings[clampedIndex - 1] ? siblings[clampedIndex - 1]!.pos : null;\n const rightPos = clampedIndex < siblings.length && siblings[clampedIndex] ? siblings[clampedIndex]!.pos : null;\n const pos = generateTreePosBetween(leftPos, rightPos);\n const id = env.generateId();\n\n // Validate parent exists (if not root)\n if (parentId !== null && !state.find(n => n.id === parentId)) {\n throw new ValidationError(`Parent node not found: ${parentId}`);\n }\n\n // Validate child type is allowed\n const parentType = getParentType(parentId);\n this._validateChildType(parentType, nodeType.type);\n\n // Validate single root\n if (parentId === null && state.some(n => n.parentId === null)) {\n throw new ValidationError(\"Tree already has a root node\");\n }\n\n // Apply defaults to node data\n const mergedData = applyDefaults(nodeType.data as AnyPrimitive, data as Partial<InferTreeNodeDataState<TNode>>) as InferTreeNodeDataState<TNode>;\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.insert, {\n id,\n type: nodeType.type,\n parentId,\n pos,\n data: mergedData,\n })\n );\n\n return id;\n },\n\n insertAfter: <TNode extends AnyTreeNodePrimitive>(\n siblingId: string,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string => {\n const state = getCurrentState();\n const sibling = state.find(n => n.id === siblingId);\n if (!sibling) {\n throw new ValidationError(`Sibling node not found: ${siblingId}`);\n }\n\n const parentId = sibling.parentId;\n const siblings = getOrderedChildren(state, parentId);\n const siblingIndex = siblings.findIndex(n => n.id === siblingId);\n const nextSibling = siblings[siblingIndex + 1];\n const pos = generateTreePosBetween(sibling.pos, nextSibling?.pos ?? null);\n const id = env.generateId();\n\n // Validate child type is allowed\n const parentType = getParentType(parentId);\n this._validateChildType(parentType, nodeType.type);\n\n // Apply defaults to node data\n const mergedData = applyDefaults(nodeType.data as AnyPrimitive, data as Partial<InferTreeNodeDataState<TNode>>) as InferTreeNodeDataState<TNode>;\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.insert, {\n id,\n type: nodeType.type,\n parentId,\n pos,\n data: mergedData,\n })\n );\n\n return id;\n },\n\n insertBefore: <TNode extends AnyTreeNodePrimitive>(\n siblingId: string,\n nodeType: TNode,\n data: TreeNodeDataSetInput<TNode>\n ): string => {\n const state = getCurrentState();\n const sibling = state.find(n => n.id === siblingId);\n if (!sibling) {\n throw new ValidationError(`Sibling node not found: ${siblingId}`);\n }\n\n const parentId = sibling.parentId;\n const siblings = getOrderedChildren(state, parentId);\n const siblingIndex = siblings.findIndex(n => n.id === siblingId);\n const prevSibling = siblings[siblingIndex - 1];\n const pos = generateTreePosBetween(prevSibling?.pos ?? null, sibling.pos);\n const id = env.generateId();\n\n // Validate child type is allowed\n const parentType = getParentType(parentId);\n this._validateChildType(parentType, nodeType.type);\n\n // Apply defaults to node data\n const mergedData = applyDefaults(nodeType.data as AnyPrimitive, data as Partial<InferTreeNodeDataState<TNode>>) as InferTreeNodeDataState<TNode>;\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.insert, {\n id,\n type: nodeType.type,\n parentId,\n pos,\n data: mergedData,\n })\n );\n\n return id;\n },\n\n remove: (id: string) => {\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.remove, { id })\n );\n },\n\n move: (nodeId: string, newParentId: string | null, toIndex: number) => {\n const state = getCurrentState();\n const node = state.find(n => n.id === nodeId);\n if (!node) {\n throw new ValidationError(`Node not found: ${nodeId}`);\n }\n\n // Validate parent exists (if not moving to root)\n if (newParentId !== null && !state.find(n => n.id === newParentId)) {\n throw new ValidationError(`Parent node not found: ${newParentId}`);\n }\n\n // Validate no cycle\n if (wouldCreateCycle(state, nodeId, newParentId)) {\n throw new ValidationError(\"Move would create a cycle in the tree\");\n }\n\n // Validate child type is allowed in new parent\n const newParentType = newParentId === null ? null : state.find(n => n.id === newParentId)?.type ?? null;\n this._validateChildType(newParentType, node.type);\n\n // Validate not moving root to a parent\n if (node.parentId === null && newParentId !== null) {\n throw new ValidationError(\"Cannot move root node to have a parent\");\n }\n\n // Calculate new position among new siblings (excluding self)\n const siblings = getOrderedChildren(state, newParentId).filter(n => n.id !== nodeId);\n const clampedIndex = Math.max(0, Math.min(toIndex, siblings.length));\n const leftPos = clampedIndex > 0 && siblings[clampedIndex - 1] ? siblings[clampedIndex - 1]!.pos : null;\n const rightPos = clampedIndex < siblings.length && siblings[clampedIndex] ? siblings[clampedIndex]!.pos : null;\n const pos = generateTreePosBetween(leftPos, rightPos);\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.move, {\n id: nodeId,\n parentId: newParentId,\n pos,\n })\n );\n },\n\n moveAfter: (nodeId: string, siblingId: string) => {\n const state = getCurrentState();\n const node = state.find(n => n.id === nodeId);\n const sibling = state.find(n => n.id === siblingId);\n \n if (!node) {\n throw new ValidationError(`Node not found: ${nodeId}`);\n }\n if (!sibling) {\n throw new ValidationError(`Sibling node not found: ${siblingId}`);\n }\n\n const newParentId = sibling.parentId;\n\n // Validate no cycle\n if (wouldCreateCycle(state, nodeId, newParentId)) {\n throw new ValidationError(\"Move would create a cycle in the tree\");\n }\n\n // Validate child type is allowed in new parent\n const newParentType = newParentId === null ? null : state.find(n => n.id === newParentId)?.type ?? null;\n this._validateChildType(newParentType, node.type);\n\n // Validate not moving root to a parent\n if (node.parentId === null && newParentId !== null) {\n throw new ValidationError(\"Cannot move root node to have a parent\");\n }\n\n const siblings = getOrderedChildren(state, newParentId).filter(n => n.id !== nodeId);\n const siblingIndex = siblings.findIndex(n => n.id === siblingId);\n const nextSibling = siblings[siblingIndex + 1];\n const pos = generateTreePosBetween(sibling.pos, nextSibling?.pos ?? null);\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.move, {\n id: nodeId,\n parentId: newParentId,\n pos,\n })\n );\n },\n\n moveBefore: (nodeId: string, siblingId: string) => {\n const state = getCurrentState();\n const node = state.find(n => n.id === nodeId);\n const sibling = state.find(n => n.id === siblingId);\n \n if (!node) {\n throw new ValidationError(`Node not found: ${nodeId}`);\n }\n if (!sibling) {\n throw new ValidationError(`Sibling node not found: ${siblingId}`);\n }\n\n const newParentId = sibling.parentId;\n\n // Validate no cycle\n if (wouldCreateCycle(state, nodeId, newParentId)) {\n throw new ValidationError(\"Move would create a cycle in the tree\");\n }\n\n // Validate child type is allowed in new parent\n const newParentType = newParentId === null ? null : state.find(n => n.id === newParentId)?.type ?? null;\n this._validateChildType(newParentType, node.type);\n\n // Validate not moving root to a parent\n if (node.parentId === null && newParentId !== null) {\n throw new ValidationError(\"Cannot move root node to have a parent\");\n }\n\n const siblings = getOrderedChildren(state, newParentId).filter(n => n.id !== nodeId);\n const siblingIndex = siblings.findIndex(n => n.id === siblingId);\n const prevSibling = siblings[siblingIndex - 1];\n const pos = generateTreePosBetween(prevSibling?.pos ?? null, sibling.pos);\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.move, {\n id: nodeId,\n parentId: newParentId,\n pos,\n })\n );\n },\n\n moveToFirst: (nodeId: string, newParentId: string | null) => {\n const state = getCurrentState();\n const node = state.find(n => n.id === nodeId);\n \n if (!node) {\n throw new ValidationError(`Node not found: ${nodeId}`);\n }\n\n // Validate parent exists (if not moving to root)\n if (newParentId !== null && !state.find(n => n.id === newParentId)) {\n throw new ValidationError(`Parent node not found: ${newParentId}`);\n }\n\n // Validate no cycle\n if (wouldCreateCycle(state, nodeId, newParentId)) {\n throw new ValidationError(\"Move would create a cycle in the tree\");\n }\n\n // Validate child type is allowed in new parent\n const newParentType = newParentId === null ? null : state.find(n => n.id === newParentId)?.type ?? null;\n this._validateChildType(newParentType, node.type);\n\n // Validate not moving root to a parent\n if (node.parentId === null && newParentId !== null) {\n throw new ValidationError(\"Cannot move root node to have a parent\");\n }\n\n const siblings = getOrderedChildren(state, newParentId).filter(n => n.id !== nodeId);\n const firstPos = siblings.length > 0 ? siblings[0]!.pos : null;\n const pos = generateTreePosBetween(null, firstPos);\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.move, {\n id: nodeId,\n parentId: newParentId,\n pos,\n })\n );\n },\n\n moveToLast: (nodeId: string, newParentId: string | null) => {\n const state = getCurrentState();\n const node = state.find(n => n.id === nodeId);\n \n if (!node) {\n throw new ValidationError(`Node not found: ${nodeId}`);\n }\n\n // Validate parent exists (if not moving to root)\n if (newParentId !== null && !state.find(n => n.id === newParentId)) {\n throw new ValidationError(`Parent node not found: ${newParentId}`);\n }\n\n // Validate no cycle\n if (wouldCreateCycle(state, nodeId, newParentId)) {\n throw new ValidationError(\"Move would create a cycle in the tree\");\n }\n\n // Validate child type is allowed in new parent\n const newParentType = newParentId === null ? null : state.find(n => n.id === newParentId)?.type ?? null;\n this._validateChildType(newParentType, node.type);\n\n // Validate not moving root to a parent\n if (node.parentId === null && newParentId !== null) {\n throw new ValidationError(\"Cannot move root node to have a parent\");\n }\n\n const siblings = getOrderedChildren(state, newParentId).filter(n => n.id !== nodeId);\n const lastPos = siblings.length > 0 ? siblings[siblings.length - 1]!.pos : null;\n const pos = generateTreePosBetween(lastPos, null);\n\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.move, {\n id: nodeId,\n parentId: newParentId,\n pos,\n })\n );\n },\n\n at: <TNode extends AnyTreeNodePrimitive>(\n id: string,\n nodeType: TNode\n ): InferProxy<TNode[\"data\"]> => {\n // Get the node to verify its type\n const state = getCurrentState();\n const node = state.find(n => n.id === id);\n if (!node) {\n throw new ValidationError(`Node not found: ${id}`);\n }\n if (node.type !== nodeType.type) {\n throw new ValidationError(\n `Node is of type \"${node.type}\", not \"${nodeType.type}\"`\n );\n }\n\n const nodePath = operationPath.append(id);\n return nodeType.data._internal.createProxy(env, nodePath) as InferProxy<TNode[\"data\"]>;\n },\n\n updateAt: <TNode extends AnyTreeNodePrimitive>(\n id: string,\n nodeType: TNode,\n value: TreeNodeUpdateValue<TNode>\n ): void => {\n // Get the node to verify its type\n const state = getCurrentState();\n const node = state.find(n => n.id === id);\n if (!node) {\n throw new ValidationError(`Node not found: ${id}`);\n }\n if (node.type !== nodeType.type) {\n throw new ValidationError(\n `Node is of type \"${node.type}\", not \"${nodeType.type}\"`\n );\n }\n\n const nodePath = operationPath.append(id);\n const dataProxy = nodeType.data._internal.createProxy(env, nodePath);\n // Delegate to the data proxy's update method\n (dataProxy as { update: (v: unknown) => void }).update(value);\n },\n\n toSnapshot: (): TreeNodeSnapshot<TRoot> | undefined => {\n const state = getCurrentState();\n const rootNode = state.find(n => n.parentId === null);\n if (!rootNode) return undefined;\n return buildSnapshot(rootNode.id, state);\n },\n };\n },\n\n applyOperation: (\n state: TreeState<TRoot> | undefined,\n operation: Operation.Operation<any, any, any>\n ): TreeState<TRoot> => {\n const path = operation.path;\n const tokens = path.toTokens().filter((t: string) => t !== \"\");\n const currentState = state ?? [];\n\n let newState: TreeState<TRoot>;\n\n // If path is empty, this is a tree-level operation\n if (tokens.length === 0) {\n switch (operation.kind) {\n case \"tree.set\": {\n const payload = operation.payload;\n if (!globalThis.Array.isArray(payload)) {\n throw new ValidationError(`TreePrimitive.set requires an array payload`);\n }\n newState = payload as TreeState<TRoot>;\n break;\n }\n case \"tree.insert\": {\n const { id, type, parentId, pos, data } = operation.payload as {\n id: string;\n type: string;\n parentId: string | null;\n pos: string;\n data: unknown;\n };\n newState = [...currentState, { id, type, parentId, pos, data }] as TreeState<TRoot>;\n break;\n }\n case \"tree.remove\": {\n const { id } = operation.payload as { id: string };\n // Get all descendants to remove\n const descendantIds = getDescendantIds(currentState, id);\n const idsToRemove = new Set([id, ...descendantIds]);\n newState = currentState.filter(node => !idsToRemove.has(node.id));\n break;\n }\n case \"tree.move\": {\n const { id, parentId, pos } = operation.payload as {\n id: string;\n parentId: string | null;\n pos: string;\n };\n newState = currentState.map(node =>\n node.id === id ? { ...node, parentId, pos } : node\n ) as TreeState<TRoot>;\n break;\n }\n default:\n throw new ValidationError(`TreePrimitive cannot apply operation of kind: ${operation.kind}`);\n }\n } else {\n // Otherwise, delegate to the node's data primitive\n const nodeId = tokens[0]!;\n const nodeIndex = currentState.findIndex(node => node.id === nodeId);\n \n if (nodeIndex === -1) {\n throw new ValidationError(`Tree node not found with ID: ${nodeId}`);\n }\n\n const node = currentState[nodeIndex]!;\n const nodeTypePrimitive = this._getNodeTypePrimitive(node.type);\n const remainingPath = path.shift();\n const nodeOperation = {\n ...operation,\n path: remainingPath,\n };\n\n const newData = nodeTypePrimitive.data._internal.applyOperation(\n node.data as InferStructState<any> | undefined,\n nodeOperation\n );\n\n const mutableState = [...currentState];\n mutableState[nodeIndex] = { ...node, data: newData };\n newState = mutableState as TreeState<TRoot>;\n }\n\n // Run validators on the new state\n runValidators(newState, this._schema.validators);\n\n return newState;\n },\n\n getInitialState: (): TreeState<TRoot> | undefined => {\n if (this._schema.defaultInput !== undefined) {\n // Convert nested input to flat TreeState\n return this._convertNestedToFlat(this._schema.defaultInput);\n }\n\n // Automatically create a root node with default data\n const rootNodeType = this._schema.root;\n const rootData = rootNodeType.data._internal.getInitialState() ?? {};\n const rootId = crypto.randomUUID();\n const rootPos = generateTreePosBetween(null, null);\n\n return [{\n id: rootId,\n type: rootNodeType.type,\n parentId: null,\n pos: rootPos,\n data: rootData,\n }] as TreeState<TRoot>;\n },\n\n convertSetInputToState: (input: unknown): TreeState<TRoot> => {\n // Convert nested input format to flat TreeState\n return this._convertNestedToFlat(input as TreeNodeSetInput<TRoot>);\n },\n\n transformOperation: (\n clientOp: Operation.Operation<any, any, any>,\n serverOp: Operation.Operation<any, any, any>\n ): Transform.TransformResult => {\n const clientPath = clientOp.path;\n const serverPath = serverOp.path;\n\n // If paths don't overlap at all, no transformation needed\n if (!OperationPath.pathsOverlap(clientPath, serverPath)) {\n return { type: \"transformed\", operation: clientOp };\n }\n\n // Handle tree.remove from server - check if client is operating on removed node or descendants\n if (serverOp.kind === \"tree.remove\") {\n const removedId = (serverOp.payload as { id: string }).id;\n const clientTokens = clientPath.toTokens().filter((t: string) => t !== \"\");\n const serverTokens = serverPath.toTokens().filter((t: string) => t !== \"\");\n\n // Check if client operation targets the removed node or uses it\n if (clientOp.kind === \"tree.move\") {\n const movePayload = clientOp.payload as { id: string; parentId: string | null };\n // If moving the removed node or moving to a removed parent\n if (movePayload.id === removedId || movePayload.parentId === removedId) {\n return { type: \"noop\" };\n }\n }\n\n if (clientOp.kind === \"tree.insert\") {\n const insertPayload = clientOp.payload as { parentId: string | null };\n // If inserting into a removed parent\n if (insertPayload.parentId === removedId) {\n return { type: \"noop\" };\n }\n }\n\n // Check if client is operating on a node that was removed\n if (clientTokens.length > serverTokens.length) {\n const nodeId = clientTokens[serverTokens.length];\n if (nodeId === removedId) {\n return { type: \"noop\" };\n }\n }\n }\n\n // Both inserting - no conflict (fractional indexing handles order)\n if (serverOp.kind === \"tree.insert\" && clientOp.kind === \"tree.insert\") {\n return { type: \"transformed\", operation: clientOp };\n }\n\n // Both moving same node - client wins\n if (serverOp.kind === \"tree.move\" && clientOp.kind === \"tree.move\") {\n const serverMoveId = (serverOp.payload as { id: string }).id;\n const clientMoveId = (clientOp.payload as { id: string }).id;\n\n if (serverMoveId === clientMoveId) {\n return { type: \"transformed\", operation: clientOp };\n }\n // Different nodes - no conflict\n return { type: \"transformed\", operation: clientOp };\n }\n\n // For same exact path: client wins (last-write-wins)\n if (OperationPath.pathsEqual(clientPath, serverPath)) {\n return { type: \"transformed\", operation: clientOp };\n }\n\n // If server set entire tree and client is operating on a node\n if (serverOp.kind === \"tree.set\" && OperationPath.isPrefix(serverPath, clientPath)) {\n return { type: \"transformed\", operation: clientOp };\n }\n\n // Delegate to node data primitive for nested operations\n const clientTokens = clientPath.toTokens().filter((t: string) => t !== \"\");\n const serverTokens = serverPath.toTokens().filter((t: string) => t !== \"\");\n\n // Both operations target children of this tree\n if (clientTokens.length > 0 && serverTokens.length > 0) {\n const clientNodeId = clientTokens[0];\n const serverNodeId = serverTokens[0];\n\n // If operating on different nodes, no conflict\n if (clientNodeId !== serverNodeId) {\n return { type: \"transformed\", operation: clientOp };\n }\n\n // Same node - would need to delegate to node's data primitive\n // For simplicity, let client win\n return { type: \"transformed\", operation: clientOp };\n }\n\n // Default: no transformation needed\n return { type: \"transformed\", operation: clientOp };\n },\n };\n}\n\n/** Options for creating a Tree primitive */\nexport interface TreeOptions<TRoot extends AnyTreeNodePrimitive> {\n /** The root node type */\n readonly root: TRoot;\n}\n\n/** Creates a new TreePrimitive with the given root node type */\nexport const Tree = <TRoot extends AnyTreeNodePrimitive>(\n options: TreeOptions<TRoot>\n): TreePrimitive<TRoot, false, false> =>\n new TreePrimitive({\n required: false,\n defaultInput: undefined,\n root: options.root,\n validators: [],\n });\n"],"mappings":";;;;;;;;;;;;CAmjBc;CAAa;CAAS;;;;;AAtgBpC,MAAM,sBACJ,OACA,aACoB;AACpB,QAAO,CAAC,GAAG,MAAM,CACd,QAAO,MAAK,EAAE,aAAa,SAAS,CACpC,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,EAAE,MAAM,EAAE,MAAM,IAAI,EAAE;;;;;AAM/D,MAAM,oBACJ,OACA,WACa;CACb,MAAM,WAAW,MAAM,QAAO,MAAK,EAAE,aAAa,OAAO;CACzD,MAAMA,gBAA0B,EAAE;AAClC,MAAK,MAAM,SAAS,UAAU;AAC5B,gBAAc,KAAK,MAAM,GAAG;AAC5B,gBAAc,KAAK,GAAG,iBAAiB,OAAO,MAAM,GAAG,CAAC;;AAE1D,QAAO;;;;;AAMT,MAAM,oBAC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AAK;AAEvD,WAAQ,IAAI,GAAG;GAGf,MAAM,MAAM,uBAAuB,SAAS,SAAS;GAGrD,MAAM,EAAE,MAAM,OAAO,IAAI,KAAK,wBAAa,sCAAe;GAG1D,MAAM,aAAa,cAAc,cAAc,MAAsB,WAAW;AAGhF,UAAO,KAAK;IACV;IACA,MAAM,UAAU;IAChB;IACA;IACA,MAAM;IACP,CAAC;GAGF,IAAIC,eAA8B;AAClC,QAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;IACxC,MAAM,aAAa,SAAS;AAE5B,gBAAY,YAAY,IAAI,UAAU,MAAM,cAAc,KAAK;AAE/D,mBAAe,OAAO,OAAO,SAAS,GAAI;;;AAK9C,cAAY,OAAuC,MAAM,MAAM,MAAM,KAAK;AAE1E,SAAO;;;;AAiyBX,MAAa,QACX,YAEA,IAAI,cAAc;CAChB,UAAU;CACV,cAAc;CACd,MAAM,QAAQ;CACd,YAAY,EAAE;CACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voidhash/mimic",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,7 +31,7 @@
31
31
  "typescript": "5.8.3",
32
32
  "vite-tsconfig-paths": "^5.1.4",
33
33
  "vitest": "^3.2.4",
34
- "@voidhash/tsconfig": "0.0.5"
34
+ "@voidhash/tsconfig": "0.0.6"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "effect": "^3.19.12"
@@ -96,6 +96,8 @@ const generateTreePosBetween = (left: string | null, right: string | null): stri
96
96
  */
97
97
  export type TreeNodeSnapshot<TNode extends AnyTreeNodePrimitive> = {
98
98
  readonly id: string;
99
+ readonly pos: string;
100
+ readonly parentId: string | null;
99
101
  readonly type: InferTreeNodeType<TNode>;
100
102
  readonly children: TreeNodeSnapshot<InferTreeNodeChildren<TNode>>[];
101
103
  } & InferTreeNodeDataState<TNode>;
@@ -668,6 +670,8 @@ export class TreePrimitive<TRoot extends AnyTreeNodePrimitive, TRequired extends
668
670
  return {
669
671
  id: node.id,
670
672
  type: node.type,
673
+ pos: node.pos,
674
+ parentId: node.parentId,
671
675
  ...(node.data as object),
672
676
  children,
673
677
  } as unknown as TreeNodeSnapshot<TRoot>;
@@ -294,15 +294,20 @@ describe("TreePrimitive", () => {
294
294
  const { env } = createEnvWithState(initialState);
295
295
  const proxy = fileSystemTree._internal.createProxy(env, OperationPath.make(""));
296
296
 
297
+
297
298
  const snapshot = proxy.toSnapshot();
298
299
  expect(snapshot).toBeDefined();
299
300
  expect(snapshot!.id).toBe("root");
300
301
  expect(snapshot!.type).toBe("folder");
302
+ expect(snapshot!.parentId).toBe(null);
303
+ expect(snapshot!.pos).toBe("a0");
301
304
  expect(snapshot!.name).toBe("Root"); // Data spread at node level
302
305
  expect(snapshot!.children).toHaveLength(2);
303
306
 
304
307
  const file1Snapshot = snapshot!.children[0]!;
305
308
  expect(file1Snapshot.id).toBe("file1");
309
+ expect(file1Snapshot.parentId).toBe("root");
310
+ expect(file1Snapshot.pos).toBe("a0");
306
311
  expect(file1Snapshot.name).toBe("File1");
307
312
  expect(file1Snapshot.children).toEqual([]);
308
313