@voidhash/mimic 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (273) hide show
  1. package/.turbo/turbo-build.log +257 -42
  2. package/dist/Document.cjs +152 -0
  3. package/dist/Document.d.cts +67 -0
  4. package/dist/Document.d.cts.map +1 -0
  5. package/dist/Document.d.mts +68 -0
  6. package/dist/Document.d.mts.map +1 -0
  7. package/dist/Document.mjs +147 -0
  8. package/dist/Document.mjs.map +1 -0
  9. package/dist/EffectSchema.cjs +180 -0
  10. package/dist/EffectSchema.d.cts +84 -0
  11. package/dist/EffectSchema.d.cts.map +1 -0
  12. package/dist/EffectSchema.d.mts +84 -0
  13. package/dist/EffectSchema.d.mts.map +1 -0
  14. package/dist/EffectSchema.mjs +176 -0
  15. package/dist/EffectSchema.mjs.map +1 -0
  16. package/dist/FractionalIndex.cjs +365 -0
  17. package/dist/FractionalIndex.mjs +364 -0
  18. package/dist/FractionalIndex.mjs.map +1 -0
  19. package/dist/Operation.cjs +53 -0
  20. package/dist/Operation.d.cts +39 -0
  21. package/dist/Operation.d.cts.map +1 -0
  22. package/dist/Operation.d.mts +39 -0
  23. package/dist/Operation.d.mts.map +1 -0
  24. package/dist/Operation.mjs +46 -0
  25. package/dist/Operation.mjs.map +1 -0
  26. package/dist/OperationDefinition.cjs +13 -0
  27. package/dist/OperationDefinition.d.cts +12 -0
  28. package/dist/OperationDefinition.d.cts.map +1 -0
  29. package/dist/OperationDefinition.d.mts +12 -0
  30. package/dist/OperationDefinition.d.mts.map +1 -0
  31. package/dist/OperationDefinition.mjs +13 -0
  32. package/dist/OperationDefinition.mjs.map +1 -0
  33. package/dist/OperationPath.cjs +148 -0
  34. package/dist/OperationPath.d.cts +60 -0
  35. package/dist/OperationPath.d.cts.map +1 -0
  36. package/dist/OperationPath.d.mts +60 -0
  37. package/dist/OperationPath.d.mts.map +1 -0
  38. package/dist/OperationPath.mjs +138 -0
  39. package/dist/OperationPath.mjs.map +1 -0
  40. package/dist/{Presence-gWrmGBeu.cjs → Presence.cjs} +4 -39
  41. package/dist/{Presence-N8u7Eppr.d.mts → Presence.d.cts} +2 -2
  42. package/dist/Presence.d.cts.map +1 -0
  43. package/dist/{Presence-DKKP4v5X.d.cts → Presence.d.mts} +2 -2
  44. package/dist/Presence.d.mts.map +1 -0
  45. package/dist/{Presence-DdMVKcOv.mjs → Presence.mjs} +3 -28
  46. package/dist/Presence.mjs.map +1 -0
  47. package/dist/Primitive.cjs +52 -0
  48. package/dist/Primitive.d.cts +20 -0
  49. package/dist/Primitive.d.cts.map +1 -0
  50. package/dist/Primitive.d.mts +20 -0
  51. package/dist/Primitive.d.mts.map +1 -0
  52. package/dist/Primitive.mjs +48 -0
  53. package/dist/Primitive.mjs.map +1 -0
  54. package/dist/ProxyEnvironment.cjs +34 -0
  55. package/dist/ProxyEnvironment.d.cts +31 -0
  56. package/dist/ProxyEnvironment.d.cts.map +1 -0
  57. package/dist/ProxyEnvironment.d.mts +31 -0
  58. package/dist/ProxyEnvironment.d.mts.map +1 -0
  59. package/dist/ProxyEnvironment.mjs +29 -0
  60. package/dist/ProxyEnvironment.mjs.map +1 -0
  61. package/dist/Transaction.cjs +66 -0
  62. package/dist/Transaction.d.cts +56 -0
  63. package/dist/Transaction.d.cts.map +1 -0
  64. package/dist/Transaction.d.mts +56 -0
  65. package/dist/Transaction.d.mts.map +1 -0
  66. package/dist/Transaction.mjs +58 -0
  67. package/dist/Transaction.mjs.map +1 -0
  68. package/dist/Transform.cjs +11 -0
  69. package/dist/Transform.d.cts +21 -0
  70. package/dist/Transform.d.cts.map +1 -0
  71. package/dist/Transform.d.mts +21 -0
  72. package/dist/Transform.d.mts.map +1 -0
  73. package/dist/Transform.mjs +6 -0
  74. package/dist/Transform.mjs.map +1 -0
  75. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.cjs +14 -0
  76. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.mjs +14 -0
  77. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectSpread2.cjs +27 -0
  78. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectSpread2.mjs +27 -0
  79. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPrimitive.cjs +16 -0
  80. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPrimitive.mjs +16 -0
  81. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPropertyKey.cjs +11 -0
  82. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPropertyKey.mjs +11 -0
  83. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/typeof.cjs +18 -0
  84. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/typeof.mjs +12 -0
  85. package/dist/_virtual/rolldown_runtime.cjs +43 -0
  86. package/dist/{chunk-CLMFDpHK.mjs → _virtual/rolldown_runtime.mjs} +1 -1
  87. package/dist/client/ClientDocument.cjs +590 -0
  88. package/dist/client/ClientDocument.d.cts +161 -0
  89. package/dist/client/ClientDocument.d.cts.map +1 -0
  90. package/dist/client/ClientDocument.d.mts +162 -0
  91. package/dist/client/ClientDocument.d.mts.map +1 -0
  92. package/dist/client/ClientDocument.mjs +586 -0
  93. package/dist/client/ClientDocument.mjs.map +1 -0
  94. package/dist/client/Rebase.cjs +204 -0
  95. package/dist/client/Rebase.d.cts +87 -0
  96. package/dist/client/Rebase.d.cts.map +1 -0
  97. package/dist/client/Rebase.d.mts +88 -0
  98. package/dist/client/Rebase.d.mts.map +1 -0
  99. package/dist/client/Rebase.mjs +198 -0
  100. package/dist/client/Rebase.mjs.map +1 -0
  101. package/dist/client/StateMonitor.cjs +133 -0
  102. package/dist/client/StateMonitor.d.cts +122 -0
  103. package/dist/client/StateMonitor.d.cts.map +1 -0
  104. package/dist/client/StateMonitor.d.mts +122 -0
  105. package/dist/client/StateMonitor.d.mts.map +1 -0
  106. package/dist/client/StateMonitor.mjs +129 -0
  107. package/dist/client/StateMonitor.mjs.map +1 -0
  108. package/dist/client/Transport.cjs +11 -0
  109. package/dist/client/Transport.d.cts +237 -0
  110. package/dist/client/Transport.d.cts.map +1 -0
  111. package/dist/client/Transport.d.mts +237 -0
  112. package/dist/client/Transport.d.mts.map +1 -0
  113. package/dist/client/Transport.mjs +6 -0
  114. package/dist/client/Transport.mjs.map +1 -0
  115. package/dist/client/WebSocketTransport.cjs +396 -0
  116. package/dist/client/WebSocketTransport.d.cts +29 -0
  117. package/dist/client/WebSocketTransport.d.cts.map +1 -0
  118. package/dist/client/WebSocketTransport.d.mts +29 -0
  119. package/dist/client/WebSocketTransport.d.mts.map +1 -0
  120. package/dist/client/WebSocketTransport.mjs +392 -0
  121. package/dist/client/WebSocketTransport.mjs.map +1 -0
  122. package/dist/client/errors.cjs +135 -0
  123. package/dist/client/errors.d.cts +87 -0
  124. package/dist/client/errors.d.cts.map +1 -0
  125. package/dist/client/errors.d.mts +87 -0
  126. package/dist/client/errors.d.mts.map +1 -0
  127. package/dist/client/errors.mjs +127 -0
  128. package/dist/client/errors.mjs.map +1 -0
  129. package/dist/client/index.cjs +22 -1424
  130. package/dist/client/index.d.cts +8 -692
  131. package/dist/client/index.d.mts +8 -692
  132. package/dist/client/index.mjs +9 -1413
  133. package/dist/index.cjs +20 -2973
  134. package/dist/index.d.cts +12 -419
  135. package/dist/index.d.mts +12 -419
  136. package/dist/index.mjs +13 -2968
  137. package/dist/primitives/Array.cjs +302 -0
  138. package/dist/primitives/Array.d.cts +95 -0
  139. package/dist/primitives/Array.d.cts.map +1 -0
  140. package/dist/primitives/Array.d.mts +95 -0
  141. package/dist/primitives/Array.d.mts.map +1 -0
  142. package/dist/primitives/Array.mjs +301 -0
  143. package/dist/primitives/Array.mjs.map +1 -0
  144. package/dist/primitives/Boolean.cjs +95 -0
  145. package/dist/primitives/Boolean.d.cts +44 -0
  146. package/dist/primitives/Boolean.d.cts.map +1 -0
  147. package/dist/primitives/Boolean.d.mts +44 -0
  148. package/dist/primitives/Boolean.d.mts.map +1 -0
  149. package/dist/primitives/Boolean.mjs +94 -0
  150. package/dist/primitives/Boolean.mjs.map +1 -0
  151. package/dist/primitives/Either.cjs +200 -0
  152. package/dist/primitives/Either.d.cts +113 -0
  153. package/dist/primitives/Either.d.cts.map +1 -0
  154. package/dist/primitives/Either.d.mts +113 -0
  155. package/dist/primitives/Either.d.mts.map +1 -0
  156. package/dist/primitives/Either.mjs +199 -0
  157. package/dist/primitives/Either.mjs.map +1 -0
  158. package/dist/primitives/Lazy.cjs +46 -0
  159. package/dist/primitives/Lazy.d.cts +46 -0
  160. package/dist/primitives/Lazy.d.cts.map +1 -0
  161. package/dist/primitives/Lazy.d.mts +46 -0
  162. package/dist/primitives/Lazy.d.mts.map +1 -0
  163. package/dist/primitives/Lazy.mjs +46 -0
  164. package/dist/primitives/Lazy.mjs.map +1 -0
  165. package/dist/primitives/Literal.cjs +91 -0
  166. package/dist/primitives/Literal.d.cts +46 -0
  167. package/dist/primitives/Literal.d.cts.map +1 -0
  168. package/dist/primitives/Literal.d.mts +46 -0
  169. package/dist/primitives/Literal.d.mts.map +1 -0
  170. package/dist/primitives/Literal.mjs +90 -0
  171. package/dist/primitives/Literal.mjs.map +1 -0
  172. package/dist/primitives/Number.cjs +115 -0
  173. package/dist/primitives/Number.d.cts +54 -0
  174. package/dist/primitives/Number.d.cts.map +1 -0
  175. package/dist/primitives/Number.d.mts +54 -0
  176. package/dist/primitives/Number.d.mts.map +1 -0
  177. package/dist/primitives/Number.mjs +114 -0
  178. package/dist/primitives/Number.mjs.map +1 -0
  179. package/dist/primitives/String.cjs +127 -0
  180. package/dist/primitives/String.d.cts +56 -0
  181. package/dist/primitives/String.d.cts.map +1 -0
  182. package/dist/primitives/String.d.mts +56 -0
  183. package/dist/primitives/String.d.mts.map +1 -0
  184. package/dist/primitives/String.mjs +126 -0
  185. package/dist/primitives/String.mjs.map +1 -0
  186. package/dist/primitives/Struct.cjs +207 -0
  187. package/dist/primitives/Struct.d.cts +96 -0
  188. package/dist/primitives/Struct.d.cts.map +1 -0
  189. package/dist/primitives/Struct.d.mts +97 -0
  190. package/dist/primitives/Struct.d.mts.map +1 -0
  191. package/dist/primitives/Struct.mjs +206 -0
  192. package/dist/primitives/Struct.mjs.map +1 -0
  193. package/dist/primitives/Tree.cjs +575 -0
  194. package/dist/primitives/Tree.d.cts +185 -0
  195. package/dist/primitives/Tree.d.cts.map +1 -0
  196. package/dist/primitives/Tree.d.mts +185 -0
  197. package/dist/primitives/Tree.d.mts.map +1 -0
  198. package/dist/primitives/Tree.mjs +574 -0
  199. package/dist/primitives/Tree.mjs.map +1 -0
  200. package/dist/primitives/TreeNode.cjs +73 -0
  201. package/dist/primitives/TreeNode.d.cts +92 -0
  202. package/dist/primitives/TreeNode.d.cts.map +1 -0
  203. package/dist/primitives/TreeNode.d.mts +93 -0
  204. package/dist/primitives/TreeNode.d.mts.map +1 -0
  205. package/dist/primitives/TreeNode.mjs +72 -0
  206. package/dist/primitives/TreeNode.mjs.map +1 -0
  207. package/dist/primitives/Union.cjs +170 -0
  208. package/dist/primitives/Union.d.cts +81 -0
  209. package/dist/primitives/Union.d.cts.map +1 -0
  210. package/dist/primitives/Union.d.mts +81 -0
  211. package/dist/primitives/Union.d.mts.map +1 -0
  212. package/dist/primitives/Union.mjs +169 -0
  213. package/dist/primitives/Union.mjs.map +1 -0
  214. package/dist/primitives/shared.cjs +60 -0
  215. package/dist/primitives/shared.d.cts +147 -0
  216. package/dist/primitives/shared.d.cts.map +1 -0
  217. package/dist/primitives/shared.d.mts +147 -0
  218. package/dist/primitives/shared.d.mts.map +1 -0
  219. package/dist/primitives/shared.mjs +58 -0
  220. package/dist/primitives/shared.mjs.map +1 -0
  221. package/dist/server/ServerDocument.cjs +110 -0
  222. package/dist/server/ServerDocument.d.cts +98 -0
  223. package/dist/server/ServerDocument.d.cts.map +1 -0
  224. package/dist/server/ServerDocument.d.mts +99 -0
  225. package/dist/server/ServerDocument.d.mts.map +1 -0
  226. package/dist/server/ServerDocument.mjs +106 -0
  227. package/dist/server/ServerDocument.mjs.map +1 -0
  228. package/dist/server/errors.cjs +85 -0
  229. package/dist/server/errors.d.cts +53 -0
  230. package/dist/server/errors.d.cts.map +1 -0
  231. package/dist/server/errors.d.mts +53 -0
  232. package/dist/server/errors.d.mts.map +1 -0
  233. package/dist/server/errors.mjs +81 -0
  234. package/dist/server/errors.mjs.map +1 -0
  235. package/dist/server/index.cjs +9 -185
  236. package/dist/server/index.d.cts +3 -148
  237. package/dist/server/index.d.mts +3 -148
  238. package/dist/server/index.mjs +3 -181
  239. package/dist/types/index.cjs +16 -0
  240. package/dist/types/index.d.cts +16 -0
  241. package/dist/types/index.d.cts.map +1 -0
  242. package/dist/types/index.d.mts +16 -0
  243. package/dist/types/index.d.mts.map +1 -0
  244. package/dist/types/index.mjs +12 -0
  245. package/dist/types/index.mjs.map +1 -0
  246. package/dist/utils/tree-helpers.cjs +443 -0
  247. package/dist/utils/tree-helpers.d.cts +280 -0
  248. package/dist/utils/tree-helpers.d.cts.map +1 -0
  249. package/dist/utils/tree-helpers.d.mts +280 -0
  250. package/dist/utils/tree-helpers.d.mts.map +1 -0
  251. package/dist/utils/tree-helpers.mjs +439 -0
  252. package/dist/utils/tree-helpers.mjs.map +1 -0
  253. package/package.json +2 -2
  254. package/tsdown.config.ts +1 -1
  255. package/dist/Document-ChuFrTk1.cjs +0 -571
  256. package/dist/Document-CwiAFTIq.mjs +0 -438
  257. package/dist/Document-CwiAFTIq.mjs.map +0 -1
  258. package/dist/Presence-DKKP4v5X.d.cts.map +0 -1
  259. package/dist/Presence-DdMVKcOv.mjs.map +0 -1
  260. package/dist/Presence-N8u7Eppr.d.mts.map +0 -1
  261. package/dist/Primitive-DqQFc3Gu.d.mts +0 -1180
  262. package/dist/Primitive-DqQFc3Gu.d.mts.map +0 -1
  263. package/dist/Primitive-awpEjnKL.d.cts +0 -1180
  264. package/dist/Primitive-awpEjnKL.d.cts.map +0 -1
  265. package/dist/client/index.d.cts.map +0 -1
  266. package/dist/client/index.d.mts.map +0 -1
  267. package/dist/client/index.mjs.map +0 -1
  268. package/dist/index.d.cts.map +0 -1
  269. package/dist/index.d.mts.map +0 -1
  270. package/dist/index.mjs.map +0 -1
  271. package/dist/server/index.d.cts.map +0 -1
  272. package/dist/server/index.d.mts.map +0 -1
  273. package/dist/server/index.mjs.map +0 -1
@@ -0,0 +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"],"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 * 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 */\n set(nodes: TreeState<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 defaultValue: TreeState<TRoot> | undefined;\n readonly root: TRoot;\n readonly validators: readonly Validator<TreeState<TRoot>>[];\n}\n\n/** Input type for tree set() - tree state */\nexport type TreeSetInput<TRoot extends AnyTreeNodePrimitive> = TreeState<TRoot>;\n\n/** Input type for tree update() - same as set() for trees */\nexport type TreeUpdateInput<TRoot extends AnyTreeNodePrimitive> = TreeState<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 */\n default(defaultValue: TreeState<TRoot>): TreePrimitive<TRoot, TRequired, true> {\n return new TreePrimitive({\n ...this._schema,\n defaultValue,\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 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: (nodes: TreeState<TRoot>) => {\n env.addOperation(\n Operation.fromDefinition(operationPath, this._opDefinitions.set, nodes)\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.defaultValue !== undefined) {\n return this._schema.defaultValue;\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 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 defaultValue: undefined,\n root: options.root,\n validators: [],\n });\n"],"mappings":";;;;;;;;;;;;;AA6CA,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,oBACJ,OACA,QACA,gBACY;AACZ,KAAI,gBAAgB,KAAM,QAAO;AACjC,KAAI,gBAAgB,OAAQ,QAAO;AAGnC,QADoB,iBAAiB,OAAO,OAAO,CAChC,SAAS,YAAY;;;;;AAM1C,MAAM,0BAA0B,MAAqB,UAAiC;CACpF,MAAM,UAAUC,eAA+B;AAC/C,QAAO,OAAO,QAAQC,mBAAmC,MAAM,OAAO,QAAQ,CAAC;;AAqLjF,IAAa,gBAAb,MAAa,cAEb;CAuCE,YAAY,QAAoC;wBAtCvC,QAAO;wBACP;wBACA;wBACA;wBACA;wBACA;wBACA;wBAEQ;wBACT;wBAES,kBAAiB;GAChC,KAAKC,KAAyB;IAC5B,MAAM;IACN,SAAS,OAAO;IAChB,QAAQ,OAAO;IACf,QAAQ,YAAY;IACrB,CAAC;GACF,QAAQA,KAAyB;IAC/B,MAAM;IACN,SAAS,OAAO;IAChB,QAAQ,OAAO;IACf,QAAQ,YAAY;IACr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IAAI,gBACR,cAAc,UAAU,kCAAkC,WAAW,oBAFlD,oBAAoB,SAAS,KAAI,MAAK,EAAE,KAAK,CAAC,KAAK,KAAK,IAGzC,SACnC;;;;AAwxBP,MAAa,QACX,YAEA,IAAI,cAAc;CAChB,UAAU;CACV,cAAc;CACd,MAAM,QAAQ;CACd,YAAY,EAAE;CACf,CAAC"}
@@ -0,0 +1,73 @@
1
+ const require_defineProperty = require('../_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.cjs');
2
+
3
+ //#region src/primitives/TreeNode.ts
4
+ /**
5
+ * Symbol used to identify the Self placeholder
6
+ */
7
+ const TreeNodeSelfSymbol = Symbol.for("TreeNode.Self");
8
+ /**
9
+ * Special placeholder for self-referential tree nodes.
10
+ * Use this in the children array when a node type can contain itself.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const FolderNode = TreeNode("folder", {
15
+ * data: Struct({ name: String() }),
16
+ * children: [TreeNodeSelf], // Folder can contain other folders
17
+ * });
18
+ * ```
19
+ */
20
+ const TreeNodeSelf = {
21
+ _tag: "TreeNodeSelf",
22
+ _symbol: TreeNodeSelfSymbol
23
+ };
24
+ /**
25
+ * Check if a value is the Self placeholder
26
+ */
27
+ const isSelf = (value) => {
28
+ return typeof value === "object" && value !== null && "_symbol" in value && value._symbol === TreeNodeSelfSymbol;
29
+ };
30
+ /**
31
+ * TreeNodePrimitive - defines a node type with its data schema and allowed children
32
+ */
33
+ var TreeNodePrimitive = class {
34
+ constructor(type, config) {
35
+ require_defineProperty._defineProperty(this, "_tag", "TreeNodePrimitive");
36
+ require_defineProperty._defineProperty(this, "_Type", void 0);
37
+ require_defineProperty._defineProperty(this, "_Data", void 0);
38
+ require_defineProperty._defineProperty(this, "_Children", void 0);
39
+ require_defineProperty._defineProperty(this, "TSetInput", void 0);
40
+ require_defineProperty._defineProperty(this, "TUpdateInput", void 0);
41
+ require_defineProperty._defineProperty(this, "_type", void 0);
42
+ require_defineProperty._defineProperty(this, "_data", void 0);
43
+ require_defineProperty._defineProperty(this, "_children", void 0);
44
+ require_defineProperty._defineProperty(this, "_resolvedChildren", void 0);
45
+ this._type = type;
46
+ this._data = config.data;
47
+ this._children = config.children;
48
+ }
49
+ /** Get the node type identifier */
50
+ get type() {
51
+ return this._type;
52
+ }
53
+ /** Get the data primitive */
54
+ get data() {
55
+ return this._data;
56
+ }
57
+ /** Get resolved children (resolves lazy thunk if needed, replaces Self with this node) */
58
+ get children() {
59
+ if (this._resolvedChildren === void 0) this._resolvedChildren = (typeof this._children === "function" ? this._children() : this._children).map((child) => isSelf(child) ? this : child);
60
+ return this._resolvedChildren;
61
+ }
62
+ /** Check if a child type is allowed */
63
+ isChildAllowed(childType) {
64
+ return this.children.some((child) => child.type === childType);
65
+ }
66
+ };
67
+ /** Creates a new TreeNodePrimitive with the given type and config */
68
+ const TreeNode = (type, config) => new TreeNodePrimitive(type, config);
69
+
70
+ //#endregion
71
+ exports.TreeNode = TreeNode;
72
+ exports.TreeNodePrimitive = TreeNodePrimitive;
73
+ exports.TreeNodeSelf = TreeNodeSelf;
@@ -0,0 +1,92 @@
1
+ import { InferSetInput, InferState, InferUpdateInput } from "./shared.cjs";
2
+ import { StructPrimitive } from "./Struct.cjs";
3
+
4
+ //#region src/primitives/TreeNode.d.ts
5
+
6
+ /**
7
+ * Branded type for TreeNodeSelf - distinguishable at compile time
8
+ */
9
+ declare const SelfBrand: unique symbol;
10
+ interface TreeNodeSelfType {
11
+ readonly _tag: "TreeNodeSelf";
12
+ readonly _brand: typeof SelfBrand;
13
+ }
14
+ /**
15
+ * Special placeholder for self-referential tree nodes.
16
+ * Use this in the children array when a node type can contain itself.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const FolderNode = TreeNode("folder", {
21
+ * data: Struct({ name: String() }),
22
+ * children: [TreeNodeSelf], // Folder can contain other folders
23
+ * });
24
+ * ```
25
+ */
26
+ declare const TreeNodeSelf: TreeNodeSelfType;
27
+ /**
28
+ * Type utility to resolve Self placeholders to the actual node type
29
+ */
30
+ type ResolveSelf<T, TSelf extends AnyTreeNodePrimitive> = T extends TreeNodeSelfType ? TSelf : T;
31
+ /**
32
+ * Type utility to resolve all children in a tuple, replacing Self with the node type
33
+ */
34
+ type ResolveChildrenUnion<TChildren, TSelf extends AnyTreeNodePrimitive> = TChildren extends readonly (infer U)[] ? ResolveSelf<U, TSelf> : never;
35
+ /**
36
+ * The type for children - either a direct array or a lazy function (for self-referential nodes).
37
+ */
38
+ type TreeNodeChildrenInput = readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[] | (() => readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[]);
39
+ /**
40
+ * Any TreeNodePrimitive type - used for generic constraints.
41
+ */
42
+ type AnyTreeNodePrimitive = TreeNodePrimitive<string, StructPrimitive<any>, any>;
43
+ /**
44
+ * Infer the data state type from a TreeNodePrimitive
45
+ */
46
+ type InferTreeNodeDataState<T extends AnyTreeNodePrimitive> = T extends TreeNodePrimitive<any, infer TData, any> ? InferState<TData> : never;
47
+ /**
48
+ * Infer the type literal from a TreeNodePrimitive
49
+ */
50
+ type InferTreeNodeType<T extends AnyTreeNodePrimitive> = T extends TreeNodePrimitive<infer TType, any, any> ? TType : never;
51
+ /**
52
+ * Infer the allowed children from a TreeNodePrimitive
53
+ */
54
+ type InferTreeNodeChildren<T> = T extends TreeNodePrimitive<any, any, infer TChildren> ? TChildren : never;
55
+ /**
56
+ * Configuration for a TreeNode primitive
57
+ */
58
+ interface TreeNodeConfig<TData$1 extends StructPrimitive<any>, TChildren extends readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[]> {
59
+ readonly data: TData$1;
60
+ readonly children: TChildren | (() => TChildren);
61
+ }
62
+ /**
63
+ * TreeNodePrimitive - defines a node type with its data schema and allowed children
64
+ */
65
+ declare class TreeNodePrimitive<TType extends string, TData$1 extends StructPrimitive<any>, TChildren extends AnyTreeNodePrimitive = AnyTreeNodePrimitive> {
66
+ readonly _tag: "TreeNodePrimitive";
67
+ readonly _Type: TType;
68
+ readonly _Data: TData$1;
69
+ readonly _Children: TChildren;
70
+ /** For InferSetInput compatibility - delegates to the data struct's set input type */
71
+ readonly TSetInput: InferSetInput<TData$1>;
72
+ /** For InferUpdateInput compatibility - delegates to the data struct's update input type */
73
+ readonly TUpdateInput: InferUpdateInput<TData$1>;
74
+ private readonly _type;
75
+ private readonly _data;
76
+ private readonly _children;
77
+ private _resolvedChildren;
78
+ constructor(type: TType, config: TreeNodeConfig<TData$1, readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[]>);
79
+ /** Get the node type identifier */
80
+ get type(): TType;
81
+ /** Get the data primitive */
82
+ get data(): TData$1;
83
+ /** Get resolved children (resolves lazy thunk if needed, replaces Self with this node) */
84
+ get children(): readonly AnyTreeNodePrimitive[];
85
+ /** Check if a child type is allowed */
86
+ isChildAllowed(childType: string): boolean;
87
+ }
88
+ /** Creates a new TreeNodePrimitive with the given type and config */
89
+ declare const TreeNode: <TType extends string, TData$1 extends StructPrimitive<any>, const TChildren extends readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[]>(type: TType, config: TreeNodeConfig<TData$1, TChildren>) => TreeNodePrimitive<TType, TData$1, ResolveChildrenUnion<TChildren, TreeNodePrimitive<TType, TData$1, any>>>;
90
+ //#endregion
91
+ export { AnyTreeNodePrimitive, InferTreeNodeChildren, InferTreeNodeDataState, InferTreeNodeType, TreeNode, TreeNodeChildrenInput, TreeNodeConfig, TreeNodePrimitive, TreeNodeSelf, TreeNodeSelfType };
92
+ //# sourceMappingURL=TreeNode.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TreeNode.d.cts","names":[],"sources":["../../src/primitives/TreeNode.ts"],"sourcesContent":[],"mappings":";;;;;;AAE2C;AAW3C;AAiBA,cAlBc,SAkBoH,EAAA,OAAvG,MAAA;AAYtB,UA7BY,gBAAA,CA6BD;EAAkB,SAAA,IAAA,EAAA,cAAA;EAChC,SAAA,MAAA,EAAA,OA5BwB,SA4BxB;;;;;AAAsC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 import { StructPrimitive } from "./Struct.mjs";
3
+ import "../Primitive.mjs";
4
+
5
+ //#region src/primitives/TreeNode.d.ts
6
+
7
+ /**
8
+ * Branded type for TreeNodeSelf - distinguishable at compile time
9
+ */
10
+ declare const SelfBrand: unique symbol;
11
+ interface TreeNodeSelfType {
12
+ readonly _tag: "TreeNodeSelf";
13
+ readonly _brand: typeof SelfBrand;
14
+ }
15
+ /**
16
+ * Special placeholder for self-referential tree nodes.
17
+ * Use this in the children array when a node type can contain itself.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const FolderNode = TreeNode("folder", {
22
+ * data: Struct({ name: String() }),
23
+ * children: [TreeNodeSelf], // Folder can contain other folders
24
+ * });
25
+ * ```
26
+ */
27
+ declare const TreeNodeSelf: TreeNodeSelfType;
28
+ /**
29
+ * Type utility to resolve Self placeholders to the actual node type
30
+ */
31
+ type ResolveSelf<T, TSelf extends AnyTreeNodePrimitive> = T extends TreeNodeSelfType ? TSelf : T;
32
+ /**
33
+ * Type utility to resolve all children in a tuple, replacing Self with the node type
34
+ */
35
+ type ResolveChildrenUnion<TChildren, TSelf extends AnyTreeNodePrimitive> = TChildren extends readonly (infer U)[] ? ResolveSelf<U, TSelf> : never;
36
+ /**
37
+ * The type for children - either a direct array or a lazy function (for self-referential nodes).
38
+ */
39
+ type TreeNodeChildrenInput = readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[] | (() => readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[]);
40
+ /**
41
+ * Any TreeNodePrimitive type - used for generic constraints.
42
+ */
43
+ type AnyTreeNodePrimitive = TreeNodePrimitive<string, StructPrimitive<any>, any>;
44
+ /**
45
+ * Infer the data state type from a TreeNodePrimitive
46
+ */
47
+ type InferTreeNodeDataState<T extends AnyTreeNodePrimitive> = T extends TreeNodePrimitive<any, infer TData, any> ? InferState<TData> : never;
48
+ /**
49
+ * Infer the type literal from a TreeNodePrimitive
50
+ */
51
+ type InferTreeNodeType<T extends AnyTreeNodePrimitive> = T extends TreeNodePrimitive<infer TType, any, any> ? TType : never;
52
+ /**
53
+ * Infer the allowed children from a TreeNodePrimitive
54
+ */
55
+ type InferTreeNodeChildren<T> = T extends TreeNodePrimitive<any, any, infer TChildren> ? TChildren : never;
56
+ /**
57
+ * Configuration for a TreeNode primitive
58
+ */
59
+ interface TreeNodeConfig<TData$1 extends StructPrimitive<any>, TChildren extends readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[]> {
60
+ readonly data: TData$1;
61
+ readonly children: TChildren | (() => TChildren);
62
+ }
63
+ /**
64
+ * TreeNodePrimitive - defines a node type with its data schema and allowed children
65
+ */
66
+ declare class TreeNodePrimitive<TType extends string, TData$1 extends StructPrimitive<any>, TChildren extends AnyTreeNodePrimitive = AnyTreeNodePrimitive> {
67
+ readonly _tag: "TreeNodePrimitive";
68
+ readonly _Type: TType;
69
+ readonly _Data: TData$1;
70
+ readonly _Children: TChildren;
71
+ /** For InferSetInput compatibility - delegates to the data struct's set input type */
72
+ readonly TSetInput: InferSetInput<TData$1>;
73
+ /** For InferUpdateInput compatibility - delegates to the data struct's update input type */
74
+ readonly TUpdateInput: InferUpdateInput<TData$1>;
75
+ private readonly _type;
76
+ private readonly _data;
77
+ private readonly _children;
78
+ private _resolvedChildren;
79
+ constructor(type: TType, config: TreeNodeConfig<TData$1, readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[]>);
80
+ /** Get the node type identifier */
81
+ get type(): TType;
82
+ /** Get the data primitive */
83
+ get data(): TData$1;
84
+ /** Get resolved children (resolves lazy thunk if needed, replaces Self with this node) */
85
+ get children(): readonly AnyTreeNodePrimitive[];
86
+ /** Check if a child type is allowed */
87
+ isChildAllowed(childType: string): boolean;
88
+ }
89
+ /** Creates a new TreeNodePrimitive with the given type and config */
90
+ declare const TreeNode: <TType extends string, TData$1 extends StructPrimitive<any>, const TChildren extends readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[]>(type: TType, config: TreeNodeConfig<TData$1, TChildren>) => TreeNodePrimitive<TType, TData$1, ResolveChildrenUnion<TChildren, TreeNodePrimitive<TType, TData$1, any>>>;
91
+ //#endregion
92
+ export { AnyTreeNodePrimitive, InferTreeNodeChildren, InferTreeNodeDataState, InferTreeNodeType, TreeNode, TreeNodeChildrenInput, TreeNodeConfig, TreeNodePrimitive, TreeNodeSelf, TreeNodeSelfType };
93
+ //# sourceMappingURL=TreeNode.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TreeNode.d.mts","names":[],"sources":["../../src/primitives/TreeNode.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAE2C;AAW3C,cADc,SACmB,EAAA,OAAA,MAEP;AAeb,UAjBI,gBAAA,CAiBU;EAYtB,SAAA,IAAA,EAAW,cAAA;EAAkB,SAAA,MAAA,EAAA,OA3BR,SA2BQ;;;;;;AACM;;;;;;;AAaxC;AAA8C,cA1BjC,YA0BiC,EA1BnB,gBA0BmB;;;;KAdzC,WAc8I,CAAA,CAAA,EAAA,cAdjH,oBAciH,CAAA,GAbjJ,CAaiJ,SAbvI,gBAauI,GAbpH,KAaoH,GAb5G,CAa4G;AAKnJ;AAKA;;KAlBK,oBAmBH,CAAA,SAAA,EAAA,cAnBiD,oBAmBjD,CAAA,GAlBA,SAkBA,SAAA,SAAA,CAAA,KAAA,EAAA,CAAA,EAAA,GAjBI,WAiBJ,CAjBgB,CAiBhB,EAjBmB,KAiBnB,CAAA,GAAA,KAAA;;;;AAA+D,KAXrD,qBAAA,GAWqD,SAAA,CAXnB,oBAWmB,GAXI,gBAWJ,CAAA,EAAA,GAAA,CAAA,GAAA,GAAA,SAAA,CAX2C,oBAW3C,GAXkE,gBAWlE,CAAA,EAAA,CAAA;AAKjE;;;AACY,KAZA,oBAAA,GAAuB,iBAYvB,CAAA,MAAA,EAZiD,eAYjD,CAAA,GAAA,CAAA,EAAA,GAAA,CAAA;;AAKZ;AAMA;AACgB,KAnBJ,sBAmBI,CAAA,UAnB6B,oBAmB7B,CAAA,GAlBd,CAkBc,SAlB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B,EAAA,SAAA,CAzC0C,oBAyC1C,GAzCiE,gBAyCjE,CAAA,EAAA,CAAA;EAAO;EAAtB,IAAA,IAAA,CAAA,CAAA,EAlCI,KAkCJ;EACW;EAAO,IAAA,IAAA,CAAA,CAAA,EA9Bd,OA8Bc;EAA4B;EAA6B,IAAA,QAAA,CAAA,CAAA,EAAA,SAzB1D,oBAyB0D,EAAA;EAAO;EAAzB,cAAA,CAAA,SAAA,EAAA,MAAA,CAAA,EAAA,OAAA;;;AAA/C,cAPP,QAOO,EAAA,CAAA,cAAA,MAAA,EAAA,gBALJ,eAKI,CAAA,GAAA,CAAA,EAAA,wBAAA,SAAA,CAJgB,oBAIhB,GAJuC,gBAIvC,CAAA,EAAA,CAAA,CAAA,IAAA,EAFZ,KAEY,EAAA,MAAA,EADV,cACU,CADK,OACL,EADY,SACZ,CAAA,EAAA,GAAjB,iBAAiB,CAAC,KAAD,EAAQ,OAAR,EAAe,oBAAf,CAAoC,SAApC,EAA+C,iBAA/C,CAAiE,KAAjE,EAAwE,OAAxE,EAAA,GAAA,CAAA,CAAA,CAAA"}
@@ -0,0 +1,72 @@
1
+ import { _defineProperty } from "../_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.mjs";
2
+
3
+ //#region src/primitives/TreeNode.ts
4
+ /**
5
+ * Symbol used to identify the Self placeholder
6
+ */
7
+ const TreeNodeSelfSymbol = Symbol.for("TreeNode.Self");
8
+ /**
9
+ * Special placeholder for self-referential tree nodes.
10
+ * Use this in the children array when a node type can contain itself.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const FolderNode = TreeNode("folder", {
15
+ * data: Struct({ name: String() }),
16
+ * children: [TreeNodeSelf], // Folder can contain other folders
17
+ * });
18
+ * ```
19
+ */
20
+ const TreeNodeSelf = {
21
+ _tag: "TreeNodeSelf",
22
+ _symbol: TreeNodeSelfSymbol
23
+ };
24
+ /**
25
+ * Check if a value is the Self placeholder
26
+ */
27
+ const isSelf = (value) => {
28
+ return typeof value === "object" && value !== null && "_symbol" in value && value._symbol === TreeNodeSelfSymbol;
29
+ };
30
+ /**
31
+ * TreeNodePrimitive - defines a node type with its data schema and allowed children
32
+ */
33
+ var TreeNodePrimitive = class {
34
+ constructor(type, config) {
35
+ _defineProperty(this, "_tag", "TreeNodePrimitive");
36
+ _defineProperty(this, "_Type", void 0);
37
+ _defineProperty(this, "_Data", void 0);
38
+ _defineProperty(this, "_Children", void 0);
39
+ _defineProperty(this, "TSetInput", void 0);
40
+ _defineProperty(this, "TUpdateInput", void 0);
41
+ _defineProperty(this, "_type", void 0);
42
+ _defineProperty(this, "_data", void 0);
43
+ _defineProperty(this, "_children", void 0);
44
+ _defineProperty(this, "_resolvedChildren", void 0);
45
+ this._type = type;
46
+ this._data = config.data;
47
+ this._children = config.children;
48
+ }
49
+ /** Get the node type identifier */
50
+ get type() {
51
+ return this._type;
52
+ }
53
+ /** Get the data primitive */
54
+ get data() {
55
+ return this._data;
56
+ }
57
+ /** Get resolved children (resolves lazy thunk if needed, replaces Self with this node) */
58
+ get children() {
59
+ if (this._resolvedChildren === void 0) this._resolvedChildren = (typeof this._children === "function" ? this._children() : this._children).map((child) => isSelf(child) ? this : child);
60
+ return this._resolvedChildren;
61
+ }
62
+ /** Check if a child type is allowed */
63
+ isChildAllowed(childType) {
64
+ return this.children.some((child) => child.type === childType);
65
+ }
66
+ };
67
+ /** Creates a new TreeNodePrimitive with the given type and config */
68
+ const TreeNode = (type, config) => new TreeNodePrimitive(type, config);
69
+
70
+ //#endregion
71
+ export { TreeNode, TreeNodePrimitive, TreeNodeSelf };
72
+ //# sourceMappingURL=TreeNode.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TreeNode.mjs","names":["TreeNodeSelf: TreeNodeSelfType"],"sources":["../../src/primitives/TreeNode.ts"],"sourcesContent":["import type { InferState } from \"../Primitive\";\nimport type { InferSetInput, InferUpdateInput } from \"./shared\";\nimport { StructPrimitive } from \"./Struct\";\n\n/**\n * Symbol used to identify the Self placeholder\n */\nconst TreeNodeSelfSymbol = Symbol.for(\"TreeNode.Self\");\n\n/**\n * Branded type for TreeNodeSelf - distinguishable at compile time\n */\ndeclare const SelfBrand: unique symbol;\nexport interface TreeNodeSelfType {\n readonly _tag: \"TreeNodeSelf\";\n readonly _brand: typeof SelfBrand;\n}\n\n/**\n * Special placeholder for self-referential tree nodes.\n * Use this in the children array when a node type can contain itself.\n * \n * @example\n * ```typescript\n * const FolderNode = TreeNode(\"folder\", {\n * data: Struct({ name: String() }),\n * children: [TreeNodeSelf], // Folder can contain other folders\n * });\n * ```\n */\nexport const TreeNodeSelf: TreeNodeSelfType = { _tag: \"TreeNodeSelf\", _symbol: TreeNodeSelfSymbol } as unknown as TreeNodeSelfType;\n\n/**\n * Check if a value is the Self placeholder\n */\nconst isSelf = (value: unknown): boolean => {\n return typeof value === \"object\" && value !== null && \"_symbol\" in value && (value as any)._symbol === TreeNodeSelfSymbol;\n};\n\n/**\n * Type utility to resolve Self placeholders to the actual node type\n */\ntype ResolveSelf<T, TSelf extends AnyTreeNodePrimitive> = \n T extends TreeNodeSelfType ? TSelf : T;\n\n/**\n * Type utility to resolve all children in a tuple, replacing Self with the node type\n */\ntype ResolveChildrenUnion<TChildren, TSelf extends AnyTreeNodePrimitive> = \n TChildren extends readonly (infer U)[] \n ? ResolveSelf<U, TSelf> \n : never;\n\n/**\n * The type for children - either a direct array or a lazy function (for self-referential nodes).\n */\nexport type TreeNodeChildrenInput = readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[] | (() => readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[]);\n\n/**\n * Any TreeNodePrimitive type - used for generic constraints.\n */\nexport type AnyTreeNodePrimitive = TreeNodePrimitive<string, StructPrimitive<any>, any>;\n\n/**\n * Infer the data state type from a TreeNodePrimitive\n */\nexport type InferTreeNodeDataState<T extends AnyTreeNodePrimitive> = \n T extends TreeNodePrimitive<any, infer TData, any> ? InferState<TData> : never;\n\n/**\n * Infer the type literal from a TreeNodePrimitive\n */\nexport type InferTreeNodeType<T extends AnyTreeNodePrimitive> =\n T extends TreeNodePrimitive<infer TType, any, any> ? TType : never;\n\n/**\n * Infer the allowed children from a TreeNodePrimitive\n */\nexport type InferTreeNodeChildren<T> = \n T extends TreeNodePrimitive<any, any, infer TChildren> ? TChildren : never;\n\n/**\n * Configuration for a TreeNode primitive\n */\nexport interface TreeNodeConfig<\n TData extends StructPrimitive<any>,\n TChildren extends readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[]\n> {\n readonly data: TData;\n readonly children: TChildren | (() => TChildren);\n}\n\n/**\n * TreeNodePrimitive - defines a node type with its data schema and allowed children\n */\nexport class TreeNodePrimitive<\n TType extends string,\n TData extends StructPrimitive<any>,\n TChildren extends AnyTreeNodePrimitive = AnyTreeNodePrimitive\n> {\n readonly _tag = \"TreeNodePrimitive\" as const;\n readonly _Type!: TType;\n readonly _Data!: TData;\n readonly _Children!: TChildren;\n \n /** For InferSetInput compatibility - delegates to the data struct's set input type */\n readonly TSetInput!: InferSetInput<TData>;\n /** For InferUpdateInput compatibility - delegates to the data struct's update input type */\n readonly TUpdateInput!: InferUpdateInput<TData>;\n\n private readonly _type: TType;\n private readonly _data: TData;\n private readonly _children: TreeNodeChildrenInput;\n private _resolvedChildren: readonly AnyTreeNodePrimitive[] | undefined;\n\n constructor(type: TType, config: TreeNodeConfig<TData, readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[]>) {\n this._type = type;\n this._data = config.data;\n this._children = config.children;\n }\n\n /** Get the node type identifier */\n get type(): TType {\n return this._type;\n }\n\n /** Get the data primitive */\n get data(): TData {\n return this._data;\n }\n\n /** Get resolved children (resolves lazy thunk if needed, replaces Self with this node) */\n get children(): readonly AnyTreeNodePrimitive[] {\n if (this._resolvedChildren === undefined) {\n const resolved = typeof this._children === \"function\"\n ? (this._children as () => readonly AnyTreeNodePrimitive[])()\n : this._children;\n // Replace Self placeholders with this node\n this._resolvedChildren = resolved.map(child => isSelf(child) ? this : child) as readonly AnyTreeNodePrimitive[];\n }\n return this._resolvedChildren;\n }\n\n /** Check if a child type is allowed */\n isChildAllowed(childType: string): boolean {\n return this.children.some(child => child.type === childType);\n }\n}\n\n/** Creates a new TreeNodePrimitive with the given type and config */\nexport const TreeNode = <\n TType extends string,\n TData extends StructPrimitive<any>,\n const TChildren extends readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[]\n>(\n type: TType,\n config: TreeNodeConfig<TData, TChildren>\n): TreeNodePrimitive<TType, TData, ResolveChildrenUnion<TChildren, TreeNodePrimitive<TType, TData, any>>> =>\n new TreeNodePrimitive(type, config) as TreeNodePrimitive<TType, TData, ResolveChildrenUnion<TChildren, TreeNodePrimitive<TType, TData, any>>>;\n\n"],"mappings":";;;;;;AAOA,MAAM,qBAAqB,OAAO,IAAI,gBAAgB;;;;;;;;;;;;;AAuBtD,MAAaA,eAAiC;CAAE,MAAM;CAAgB,SAAS;CAAoB;;;;AAKnG,MAAM,UAAU,UAA4B;AAC1C,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,aAAa,SAAU,MAAc,YAAY;;;;;AA2DzG,IAAa,oBAAb,MAIE;CAgBA,YAAY,MAAa,QAAqF;wBAfrG,QAAO;wBACP;wBACA;wBACA;wBAGA;wBAEA;wBAEQ;wBACA;wBACA;wBACT;AAGN,OAAK,QAAQ;AACb,OAAK,QAAQ,OAAO;AACpB,OAAK,YAAY,OAAO;;;CAI1B,IAAI,OAAc;AAChB,SAAO,KAAK;;;CAId,IAAI,OAAc;AAChB,SAAO,KAAK;;;CAId,IAAI,WAA4C;AAC9C,MAAI,KAAK,sBAAsB,OAK7B,MAAK,qBAJY,OAAO,KAAK,cAAc,aACtC,KAAK,WAAqD,GAC3D,KAAK,WAEyB,KAAI,UAAS,OAAO,MAAM,GAAG,OAAO,MAAM;AAE9E,SAAO,KAAK;;;CAId,eAAe,WAA4B;AACzC,SAAO,KAAK,SAAS,MAAK,UAAS,MAAM,SAAS,UAAU;;;;AAKhE,MAAa,YAKX,MACA,WAEA,IAAI,kBAAkB,MAAM,OAAO"}