@voidhash/mimic 0.0.8 → 1.0.0-beta.1
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.
- package/.turbo/turbo-build.log +5 -5
- package/dist/types/index.mjs.map +1 -1
- package/dist/utils/tree-helpers.mjs.map +1 -1
- package/package.json +2 -2
- package/src/client/index.ts +7 -7
- package/src/index.ts +11 -11
- package/src/server/index.ts +3 -3
- package/src/types/index.ts +9 -9
- package/src/utils/index.ts +1 -1
- package/src/utils/tree-helpers.ts +2 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @voidhash/mimic@0.0.
|
|
2
|
+
> @voidhash/mimic@1.0.0-beta.1 build /home/runner/work/mimic/mimic/packages/mimic
|
|
3
3
|
> tsdown
|
|
4
4
|
|
|
5
5
|
[34mℹ[39m tsdown [2mv0.18.2[22m powered by rolldown [2mv1.0.0-beta.55[22m
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mTransform.d.cts[39m [2m 0.48 kB[22m [2m│ gzip: 0.26 kB[22m
|
|
122
122
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mOperationDefinition.d.cts[39m [2m 0.36 kB[22m [2m│ gzip: 0.21 kB[22m
|
|
123
123
|
[34mℹ[39m [33m[CJS][39m 67 files, total: 181.04 kB
|
|
124
|
-
[32m✔[39m Build complete in [
|
|
124
|
+
[32m✔[39m Build complete in [32m6408ms[39m
|
|
125
125
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mindex.mjs[22m [2m 1.01 kB[22m [2m│ gzip: 0.28 kB[22m
|
|
126
126
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mclient/index.mjs[22m [2m 0.99 kB[22m [2m│ gzip: 0.28 kB[22m
|
|
127
127
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mserver/index.mjs[22m [2m 0.41 kB[22m [2m│ gzip: 0.17 kB[22m
|
|
@@ -169,7 +169,7 @@
|
|
|
169
169
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mDocument.mjs [2m 4.00 kB[22m [2m│ gzip: 1.40 kB[22m
|
|
170
170
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/Number.mjs [2m 3.99 kB[22m [2m│ gzip: 1.19 kB[22m
|
|
171
171
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mserver/errors.mjs.map [2m 3.86 kB[22m [2m│ gzip: 0.96 kB[22m
|
|
172
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mtypes/index.mjs.map [2m 3.
|
|
172
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mtypes/index.mjs.map [2m 3.71 kB[22m [2m│ gzip: 0.78 kB[22m
|
|
173
173
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mutils/tree-helpers.d.mts.map [2m 3.61 kB[22m [2m│ gzip: 1.31 kB[22m
|
|
174
174
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mclient/StateMonitor.mjs [2m 3.60 kB[22m [2m│ gzip: 1.23 kB[22m
|
|
175
175
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mprimitives/shared.mjs [2m 3.55 kB[22m [2m│ gzip: 1.25 kB[22m
|
|
@@ -266,5 +266,5 @@
|
|
|
266
266
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mclient/WebSocketTransport.d.mts[39m [2m 1.22 kB[22m [2m│ gzip: 0.55 kB[22m
|
|
267
267
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mTransform.d.mts[39m [2m 0.48 kB[22m [2m│ gzip: 0.26 kB[22m
|
|
268
268
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mOperationDefinition.d.mts[39m [2m 0.36 kB[22m [2m│ gzip: 0.22 kB[22m
|
|
269
|
-
[34mℹ[39m [34m[ESM][39m 144 files, total: 845.
|
|
270
|
-
[32m✔[39m Build complete in [
|
|
269
|
+
[34mℹ[39m [34m[ESM][39m 144 files, total: 845.42 kB
|
|
270
|
+
[32m✔[39m Build complete in [32m6457ms[39m
|
package/dist/types/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/types/index.ts"],"sourcesContent":["/**\n * Consolidated type inference utilities for all primitives.\n *\n * This module re-exports all inference types from a single location\n * for convenient access across the mimic package.\n *\n * @since 0.0.1\n */\n\n// =============================================================================\n// Core Inference Types (from shared.ts)\n// =============================================================================\n\nexport type {\n // Core primitive types\n Primitive,\n AnyPrimitive,\n PrimitiveInternal,\n\n // State and proxy inference\n InferState,\n InferProxy,\n\n // Input inference\n InferSetInput,\n InferUpdateInput,\n\n // Snapshot inference\n InferSnapshot,\n\n // Required/default status inference\n HasDefault,\n IsDefined,\n IsRequired,\n\n // Utility types\n MaybeUndefined,\n NeedsValue,\n Optional,\n\n // Validator type\n Validator,\n} from \"../primitives/shared
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/types/index.ts"],"sourcesContent":["/**\n * Consolidated type inference utilities for all primitives.\n *\n * This module re-exports all inference types from a single location\n * for convenient access across the mimic package.\n *\n * @since 0.0.1\n */\n\n// =============================================================================\n// Core Inference Types (from shared.ts)\n// =============================================================================\n\nexport type {\n // Core primitive types\n Primitive,\n AnyPrimitive,\n PrimitiveInternal,\n\n // State and proxy inference\n InferState,\n InferProxy,\n\n // Input inference\n InferSetInput,\n InferUpdateInput,\n\n // Snapshot inference\n InferSnapshot,\n\n // Required/default status inference\n HasDefault,\n IsDefined,\n IsRequired,\n\n // Utility types\n MaybeUndefined,\n NeedsValue,\n Optional,\n\n // Validator type\n Validator,\n} from \"../primitives/shared\";\n\n// =============================================================================\n// Struct Inference Types\n// =============================================================================\n\nexport type {\n InferStructState,\n InferStructSnapshot,\n StructSetInput,\n StructUpdateValue,\n StructProxy,\n} from \"../primitives/Struct\";\n\n// =============================================================================\n// Array Inference Types\n// =============================================================================\n\nexport type {\n ArrayState,\n ArraySnapshot,\n ArrayEntrySnapshot,\n ArrayEntry,\n ArraySetInput,\n ArrayUpdateInput,\n ArrayElementSetInput,\n ArrayProxy,\n} from \"../primitives/Array\";\n\n// =============================================================================\n// Tree Inference Types\n// =============================================================================\n\nexport type {\n TreeState,\n TreeNodeState,\n TypedTreeNodeState,\n TreeNodeSnapshot,\n InferTreeSnapshot,\n TreeSetInput,\n TreeUpdateInput,\n TreeNodeUpdateValue,\n TreeNodeDataSetInput,\n TreeProxy,\n TypedNodeProxy,\n TreeNodeProxyBase,\n} from \"../primitives/Tree\";\n\n// =============================================================================\n// TreeNode Inference Types\n// =============================================================================\n\nexport type {\n AnyTreeNodePrimitive,\n InferTreeNodeDataState,\n InferTreeNodeType,\n InferTreeNodeChildren,\n TreeNodeSelfType,\n TreeNodeConfig,\n TreeNodeChildrenInput,\n} from \"../primitives/TreeNode\";\n\nexport { TreeNodePrimitive, TreeNodeSelf } from \"../primitives/TreeNode\";\n\n// =============================================================================\n// Union Inference Types\n// =============================================================================\n\nexport type {\n InferUnionState,\n InferUnionSnapshot,\n UnionVariants,\n} from \"../primitives/Union\";\n\n// =============================================================================\n// Either Inference Types\n// =============================================================================\n\nexport type {\n InferEitherState,\n InferEitherSnapshot,\n ScalarPrimitive,\n} from \"../primitives/Either\";\n\n// =============================================================================\n// Lazy Inference Types\n// =============================================================================\n\nexport type {\n InferLazyState,\n InferLazyProxy,\n InferLazySnapshot,\n InferLazySetInput,\n InferLazyUpdateInput,\n} from \"../primitives/Lazy\";\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree-helpers.mjs","names":["ancestors: TreeNodeSnapshot<TNode>[]","descendants: TreeNodeSnapshot<TNode>[]","results: TreeNodeSnapshot<TNode>[]","result: FlattenedNode<TNode>[]","result: AnyTreeNodePrimitive[]"],"sources":["../../src/utils/tree-helpers.ts"],"sourcesContent":["/**\n * Tree snapshot utility functions.\n *\n * Standalone helpers for traversing and querying tree snapshots.\n * All functions handle undefined snapshots gracefully.\n *\n * @since 0.0.1\n */\n\nimport type { TreeNodeSnapshot, TreePrimitive } from \"../primitives/Tree.js\";\nimport type { AnyTreeNodePrimitive } from \"../primitives/TreeNode.js\";\n\n// =============================================================================\n// Result Types\n// =============================================================================\n\n/**\n * Result of finding a node with path information.\n */\nexport interface NodeSearchResult<TNode extends AnyTreeNodePrimitive> {\n readonly node: TreeNodeSnapshot<TNode>;\n readonly path: readonly string[]; // Array of node IDs from root to this node\n readonly depth: number;\n}\n\n/**\n * Result of finding a parent node.\n */\nexport interface ParentSearchResult<TNode extends AnyTreeNodePrimitive> {\n readonly parent: TreeNodeSnapshot<TNode>;\n readonly childIndex: number; // Index of the target node in parent's children\n}\n\n/**\n * Flattened node with parent information.\n */\nexport interface FlattenedNode<TNode extends AnyTreeNodePrimitive> {\n readonly node: TreeNodeSnapshot<TNode>;\n readonly parentId: string | null;\n readonly depth: number;\n}\n\n/**\n * Options for tree traversal.\n */\nexport interface TraverseOptions {\n readonly order?: \"pre\" | \"post\";\n}\n\n// =============================================================================\n// Core Functions\n// =============================================================================\n\n/**\n * Find a node by ID in a tree snapshot.\n *\n * @param snapshot - The root tree snapshot\n * @param id - The node ID to find\n * @returns The node snapshot if found, undefined otherwise\n */\nexport function findNodeById<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n id: string\n): TreeNodeSnapshot<TNode> | undefined {\n if (!snapshot) return undefined;\n if (snapshot.id === id) return snapshot;\n\n for (const child of snapshot.children) {\n const found = findNodeById(child as TreeNodeSnapshot<TNode>, id);\n if (found) return found;\n }\n\n return undefined;\n}\n\n/**\n * Find a node by ID with full path information.\n *\n * @param snapshot - The root tree snapshot\n * @param id - The node ID to find\n * @returns NodeSearchResult with node, path, and depth, or undefined if not found\n */\nexport function findNodeWithPath<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n id: string\n): NodeSearchResult<TNode> | undefined {\n if (!snapshot) return undefined;\n\n const search = (\n node: TreeNodeSnapshot<TNode>,\n currentPath: string[],\n depth: number\n ): NodeSearchResult<TNode> | undefined => {\n const path = [...currentPath, node.id];\n\n if (node.id === id) {\n return { node, path, depth };\n }\n\n for (const child of node.children) {\n const result = search(child as TreeNodeSnapshot<TNode>, path, depth + 1);\n if (result) return result;\n }\n\n return undefined;\n };\n\n return search(snapshot, [], 0);\n}\n\n/**\n * Get the parent node of a given node ID.\n *\n * @param snapshot - The root tree snapshot\n * @param nodeId - The ID of the node whose parent we want\n * @returns ParentSearchResult with parent node and child index, or undefined\n */\nexport function getParent<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n nodeId: string\n): ParentSearchResult<TNode> | undefined {\n if (!snapshot) return undefined;\n\n // Check if any direct child is the target\n for (let i = 0; i < snapshot.children.length; i++) {\n const child = snapshot.children[i];\n if (child && child.id === nodeId) {\n return {\n parent: snapshot,\n childIndex: i,\n };\n }\n }\n\n // Recursively search children\n for (const child of snapshot.children) {\n const result = getParent(child as TreeNodeSnapshot<TNode>, nodeId);\n if (result) return result;\n }\n\n return undefined;\n}\n\n/**\n * Get a subtree rooted at a specific node ID.\n *\n * @param snapshot - The root tree snapshot\n * @param nodeId - The ID of the node to use as new root\n * @returns The subtree snapshot, or undefined if node not found\n */\nexport function getSubtree<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n nodeId: string\n): TreeNodeSnapshot<TNode> | undefined {\n return findNodeById(snapshot, nodeId);\n}\n\n/**\n * Get all ancestor nodes from a node up to the root.\n *\n * @param snapshot - The root tree snapshot\n * @param nodeId - The ID of the node\n * @returns Array of ancestor snapshots from immediate parent to root, or empty array\n */\nexport function getAncestors<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n nodeId: string\n): readonly TreeNodeSnapshot<TNode>[] {\n if (!snapshot) return [];\n\n const result = findNodeWithPath(snapshot, nodeId);\n if (!result || result.path.length <= 1) return [];\n\n // Path includes the node itself, so we need all nodes except the last one\n const ancestorIds = result.path.slice(0, -1);\n const ancestors: TreeNodeSnapshot<TNode>[] = [];\n\n // Collect ancestors in reverse order (parent first, root last)\n for (let i = ancestorIds.length - 1; i >= 0; i--) {\n const id = ancestorIds[i];\n if (id) {\n const ancestor = findNodeById(snapshot, id);\n if (ancestor) {\n ancestors.push(ancestor);\n }\n }\n }\n\n return ancestors;\n}\n\n/**\n * Get all descendant nodes of a given node (flat array).\n *\n * @param snapshot - The root tree snapshot\n * @param nodeId - The ID of the node (if undefined, returns all descendants of root)\n * @returns Flat array of all descendant node snapshots\n */\nexport function getDescendants<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n nodeId?: string\n): readonly TreeNodeSnapshot<TNode>[] {\n if (!snapshot) return [];\n\n const startNode = nodeId ? findNodeById(snapshot, nodeId) : snapshot;\n if (!startNode) return [];\n\n const descendants: TreeNodeSnapshot<TNode>[] = [];\n\n const collect = (node: TreeNodeSnapshot<TNode>) => {\n for (const child of node.children) {\n descendants.push(child as TreeNodeSnapshot<TNode>);\n collect(child as TreeNodeSnapshot<TNode>);\n }\n };\n\n collect(startNode);\n return descendants;\n}\n\n/**\n * Get siblings of a node (nodes with the same parent).\n *\n * @param snapshot - The root tree snapshot\n * @param nodeId - The ID of the node\n * @param includeSelf - Whether to include the node itself (default: false)\n * @returns Array of sibling snapshots\n */\nexport function getSiblings<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n nodeId: string,\n includeSelf: boolean = false\n): readonly TreeNodeSnapshot<TNode>[] {\n if (!snapshot) return [];\n\n const parentResult = getParent(snapshot, nodeId);\n\n // If no parent, this is the root - root has no siblings\n if (!parentResult) return [];\n\n const siblings = parentResult.parent.children as readonly TreeNodeSnapshot<TNode>[];\n\n if (includeSelf) {\n return siblings;\n }\n\n return siblings.filter((s) => s.id !== nodeId);\n}\n\n// =============================================================================\n// Query Functions\n// =============================================================================\n\n/**\n * Find the first node matching a predicate.\n *\n * @param snapshot - The root tree snapshot\n * @param predicate - Function to test each node\n * @returns First matching node snapshot, or undefined\n */\nexport function findNode<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n predicate: (node: TreeNodeSnapshot<TNode>) => boolean\n): TreeNodeSnapshot<TNode> | undefined {\n if (!snapshot) return undefined;\n\n if (predicate(snapshot)) return snapshot;\n\n for (const child of snapshot.children) {\n const found = findNode(child as TreeNodeSnapshot<TNode>, predicate);\n if (found) return found;\n }\n\n return undefined;\n}\n\n/**\n * Find all nodes matching a predicate.\n *\n * @param snapshot - The root tree snapshot\n * @param predicate - Function to test each node\n * @returns Array of matching node snapshots\n */\nexport function findNodes<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n predicate: (node: TreeNodeSnapshot<TNode>) => boolean\n): readonly TreeNodeSnapshot<TNode>[] {\n if (!snapshot) return [];\n\n const results: TreeNodeSnapshot<TNode>[] = [];\n\n const search = (node: TreeNodeSnapshot<TNode>) => {\n if (predicate(node)) {\n results.push(node);\n }\n for (const child of node.children) {\n search(child as TreeNodeSnapshot<TNode>);\n }\n };\n\n search(snapshot);\n return results;\n}\n\n/**\n * Get the depth of a specific node (0 = root).\n *\n * @param snapshot - The root tree snapshot\n * @param nodeId - The ID of the node\n * @returns The depth, or -1 if not found\n */\nexport function getNodeDepth<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n nodeId: string\n): number {\n if (!snapshot) return -1;\n\n const result = findNodeWithPath(snapshot, nodeId);\n return result ? result.depth : -1;\n}\n\n/**\n * Check if one node is an ancestor of another.\n *\n * @param snapshot - The root tree snapshot\n * @param ancestorId - Potential ancestor node ID\n * @param descendantId - Potential descendant node ID\n * @returns true if ancestorId is an ancestor of descendantId\n */\nexport function isAncestorOf<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n ancestorId: string,\n descendantId: string\n): boolean {\n if (!snapshot) return false;\n\n const result = findNodeWithPath(snapshot, descendantId);\n if (!result) return false;\n\n // Check if ancestorId is in the path (excluding the descendant itself)\n return result.path.slice(0, -1).includes(ancestorId);\n}\n\n// =============================================================================\n// Traversal Functions\n// =============================================================================\n\n/**\n * Traverse the tree and call a visitor function for each node.\n * Return false from visitor to stop traversal.\n *\n * @param snapshot - The root tree snapshot\n * @param visitor - Function called for each node (return false to stop)\n * @param options - Traversal options (order: 'pre' | 'post')\n */\nexport function traverse<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n visitor: (node: TreeNodeSnapshot<TNode>, depth: number) => void | false,\n options: TraverseOptions = {}\n): void {\n if (!snapshot) return;\n\n const { order = \"pre\" } = options;\n\n const visit = (node: TreeNodeSnapshot<TNode>, depth: number): boolean => {\n if (order === \"pre\") {\n const result = visitor(node, depth);\n if (result === false) return false;\n }\n\n for (const child of node.children) {\n const shouldContinue = visit(child as TreeNodeSnapshot<TNode>, depth + 1);\n if (!shouldContinue) return false;\n }\n\n if (order === \"post\") {\n const result = visitor(node, depth);\n if (result === false) return false;\n }\n\n return true;\n };\n\n visit(snapshot, 0);\n}\n\n/**\n * Flatten the tree into an array with parent information.\n *\n * @param snapshot - The root tree snapshot\n * @returns Array of { node, parentId, depth } objects\n */\nexport function flattenTree<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined\n): readonly FlattenedNode<TNode>[] {\n if (!snapshot) return [];\n\n const result: FlattenedNode<TNode>[] = [];\n\n const flatten = (\n node: TreeNodeSnapshot<TNode>,\n parentId: string | null,\n depth: number\n ) => {\n result.push({ node, parentId, depth });\n\n for (const child of node.children) {\n flatten(child as TreeNodeSnapshot<TNode>, node.id, depth + 1);\n }\n };\n\n flatten(snapshot, null, 0);\n return result;\n}\n\n/**\n * Map over all nodes in the tree, transforming each node's data.\n * Preserves tree structure while transforming node content.\n *\n * @param snapshot - The root tree snapshot\n * @param mapper - Function to transform each node\n * @returns New tree structure with transformed nodes, or undefined\n */\nexport function mapTree<TNode extends AnyTreeNodePrimitive, R>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n mapper: (node: TreeNodeSnapshot<TNode>, depth: number) => R\n): { value: R; children: ReturnType<typeof mapTree<TNode, R>>[] } | undefined {\n if (!snapshot) return undefined;\n\n const map = (\n node: TreeNodeSnapshot<TNode>,\n depth: number\n ): { value: R; children: ReturnType<typeof mapTree<TNode, R>>[] } => {\n const value = mapper(node, depth);\n const children = node.children.map((child) =>\n map(child as TreeNodeSnapshot<TNode>, depth + 1)\n );\n return { value, children };\n };\n\n return map(snapshot, 0);\n}\n\n// =============================================================================\n// Schema Functions (work with TreeNodePrimitive, not snapshots)\n// =============================================================================\n\n/**\n * Build a lookup map from node type strings to their TreeNodePrimitive definitions.\n * Useful for resolving snapshot node types back to their schema definitions.\n *\n * @param tree - The TreePrimitive to analyze\n * @returns Map from type string to TreeNodePrimitive\n *\n * @example\n * ```ts\n * const typeMap = buildNodeTypeMap(fileTree);\n * const folderPrimitive = typeMap.get(\"folder\"); // FolderNode\n * ```\n */\nexport function buildNodeTypeMap<TRoot extends AnyTreeNodePrimitive>(\n tree: TreePrimitive<TRoot>\n): Map<string, AnyTreeNodePrimitive> {\n const map = 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 map.set(node.type, node);\n\n for (const child of node.children) {\n visit(child);\n }\n };\n\n visit(tree.root);\n return map;\n}\n\n/**\n * Get the TreeNodePrimitive definition for a snapshot node.\n * Requires the tree schema to resolve the type string to its primitive.\n *\n * @param tree - The TreePrimitive schema\n * @param snapshot - The node snapshot to get the primitive for\n * @returns The TreeNodePrimitive, or undefined if not found\n *\n * @example\n * ```ts\n * const node = findNodeById(treeSnapshot, \"some-id\");\n * const primitive = getNodePrimitive(fileTree, node);\n * // primitive is FolderNode or FileNode depending on node.type\n * ```\n */\nexport function getNodePrimitive<TRoot extends AnyTreeNodePrimitive>(\n tree: TreePrimitive<TRoot>,\n snapshot: TreeNodeSnapshot<AnyTreeNodePrimitive>\n): AnyTreeNodePrimitive | undefined {\n return getNodeTypeByName(tree, snapshot.type);\n}\n\n/**\n * Get the allowed child types for a snapshot node.\n * Combines schema lookup with the node's allowed children.\n *\n * @param tree - The TreePrimitive schema\n * @param snapshot - The node snapshot to get allowed children for\n * @returns Array of allowed child TreeNodePrimitives, or empty array if not found\n *\n * @example\n * ```ts\n * const node = findNodeById(treeSnapshot, \"folder-id\");\n * const allowedChildren = getAllowedChildTypesForNode(fileTree, node);\n * // Returns [FolderNode, FileNode] if the folder can contain both\n * ```\n */\nexport function getAllowedChildTypesForNode<TRoot extends AnyTreeNodePrimitive>(\n tree: TreePrimitive<TRoot>,\n snapshot: TreeNodeSnapshot<AnyTreeNodePrimitive>\n): readonly AnyTreeNodePrimitive[] {\n const primitive = getNodePrimitive(tree, snapshot);\n if (!primitive) return [];\n return primitive.children;\n}\n\n/**\n * Check if a child type is allowed for a specific snapshot node.\n *\n * @param tree - The TreePrimitive schema\n * @param parentSnapshot - The parent node snapshot\n * @param childTypeName - The type string of the potential child\n * @returns true if the child type is allowed\n *\n * @example\n * ```ts\n * const folder = findNodeById(treeSnapshot, \"folder-id\");\n * canAddChildType(fileTree, folder, \"file\"); // true\n * canAddChildType(fileTree, folder, \"unknown\"); // false\n * ```\n */\nexport function canAddChildType<TRoot extends AnyTreeNodePrimitive>(\n tree: TreePrimitive<TRoot>,\n parentSnapshot: TreeNodeSnapshot<AnyTreeNodePrimitive>,\n childTypeName: string\n): boolean {\n const primitive = getNodePrimitive(tree, parentSnapshot);\n if (!primitive) return false;\n return primitive.isChildAllowed(childTypeName);\n}\n\n/**\n * Get all allowed child node types for a specific node type.\n *\n * @param nodeType - The TreeNodePrimitive to get children for\n * @returns Array of allowed child TreeNodePrimitives\n *\n * @example\n * ```ts\n * const FolderNode = TreeNode(\"folder\", { ... });\n * const FileNode = TreeNode(\"file\", { ... });\n *\n * // Get allowed children for FolderNode\n * const allowedChildren = getAllowedChildTypes(FolderNode);\n * // Returns [FolderNode, FileNode] if folder can contain both\n * ```\n */\nexport function getAllowedChildTypes<TNode extends AnyTreeNodePrimitive>(\n nodeType: TNode\n): readonly AnyTreeNodePrimitive[] {\n return nodeType.children;\n}\n\n/**\n * Get all unique node types reachable in a tree schema.\n * Recursively traverses the tree structure starting from the root.\n *\n * @param tree - The TreePrimitive to analyze\n * @returns Array of all unique TreeNodePrimitives in the tree schema\n *\n * @example\n * ```ts\n * const fileTree = Tree({ root: FolderNode });\n * const allNodeTypes = getAllNodeTypes(fileTree);\n * // Returns [FolderNode, FileNode] - all possible node types\n * ```\n */\nexport function getAllNodeTypes<TRoot extends AnyTreeNodePrimitive>(\n tree: TreePrimitive<TRoot>\n): readonly AnyTreeNodePrimitive[] {\n const visited = new Set<string>();\n const result: AnyTreeNodePrimitive[] = [];\n\n const visit = (node: AnyTreeNodePrimitive) => {\n if (visited.has(node.type)) return;\n visited.add(node.type);\n result.push(node);\n\n for (const child of node.children) {\n visit(child);\n }\n };\n\n visit(tree.root);\n return result;\n}\n\n/**\n * Get the node type primitive by its type string from a tree schema.\n *\n * @param tree - The TreePrimitive to search\n * @param typeName - The type string to find (e.g., \"folder\", \"file\")\n * @returns The matching TreeNodePrimitive, or undefined if not found\n *\n * @example\n * ```ts\n * const fileTree = Tree({ root: FolderNode });\n * const folderType = getNodeTypeByName(fileTree, \"folder\");\n * // Returns FolderNode\n * ```\n */\nexport function getNodeTypeByName<TRoot extends AnyTreeNodePrimitive>(\n tree: TreePrimitive<TRoot>,\n typeName: string\n): AnyTreeNodePrimitive | undefined {\n const allTypes = getAllNodeTypes(tree);\n return allTypes.find((node) => node.type === typeName);\n}\n\n/**\n * Check if a child type is allowed under a parent type.\n *\n * @param parentType - The parent TreeNodePrimitive\n * @param childTypeName - The type string of the potential child\n * @returns true if the child type is allowed\n *\n * @example\n * ```ts\n * isChildTypeAllowed(FolderNode, \"file\"); // true if folder can contain files\n * isChildTypeAllowed(FileNode, \"folder\"); // false - files can't have children\n * ```\n */\nexport function isChildTypeAllowed(\n parentType: AnyTreeNodePrimitive,\n childTypeName: string\n): boolean {\n return parentType.isChildAllowed(childTypeName);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA,SAAgB,aACd,UACA,IACqC;AACrC,KAAI,CAAC,SAAU,QAAO;AACtB,KAAI,SAAS,OAAO,GAAI,QAAO;AAE/B,MAAK,MAAM,SAAS,SAAS,UAAU;EACrC,MAAM,QAAQ,aAAa,OAAkC,GAAG;AAChE,MAAI,MAAO,QAAO;;;;;;;;;;AAatB,SAAgB,iBACd,UACA,IACqC;AACrC,KAAI,CAAC,SAAU,QAAO;CAEtB,MAAM,UACJ,MACA,aACA,UACwC;EACxC,MAAM,OAAO,CAAC,GAAG,aAAa,KAAK,GAAG;AAEtC,MAAI,KAAK,OAAO,GACd,QAAO;GAAE;GAAM;GAAM;GAAO;AAG9B,OAAK,MAAM,SAAS,KAAK,UAAU;GACjC,MAAM,SAAS,OAAO,OAAkC,MAAM,QAAQ,EAAE;AACxE,OAAI,OAAQ,QAAO;;;AAMvB,QAAO,OAAO,UAAU,EAAE,EAAE,EAAE;;;;;;;;;AAUhC,SAAgB,UACd,UACA,QACuC;AACvC,KAAI,CAAC,SAAU,QAAO;AAGtB,MAAK,IAAI,IAAI,GAAG,IAAI,SAAS,SAAS,QAAQ,KAAK;EACjD,MAAM,QAAQ,SAAS,SAAS;AAChC,MAAI,SAAS,MAAM,OAAO,OACxB,QAAO;GACL,QAAQ;GACR,YAAY;GACb;;AAKL,MAAK,MAAM,SAAS,SAAS,UAAU;EACrC,MAAM,SAAS,UAAU,OAAkC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SAAS;;;;;;;;;;;;;;;;AAiBlB,SAAgB,gBACd,MACiC;CACjC,MAAM,0BAAU,IAAI,KAAa;CACjC,MAAMC,SAAiC,EAAE;CAEzC,MAAM,SAAS,SAA+B;AAC5C,MAAI,QAAQ,IAAI,KAAK,KAAK,CAAE;AAC5B,UAAQ,IAAI,KAAK,KAAK;AACtB,SAAO,KAAK,KAAK;AAEjB,OAAK,MAAM,SAAS,KAAK,SACvB,OAAM,MAAM;;AAIhB,OAAM,KAAK,KAAK;AAChB,QAAO;;;;;;;;;;;;;;;;AAiBT,SAAgB,kBACd,MACA,UACkC;AAElC,QADiB,gBAAgB,KAAK,CACtB,MAAM,SAAS,KAAK,SAAS,SAAS;;;;;;;;;;;;;;;AAgBxD,SAAgB,mBACd,YACA,eACS;AACT,QAAO,WAAW,eAAe,cAAc"}
|
|
1
|
+
{"version":3,"file":"tree-helpers.mjs","names":["ancestors: TreeNodeSnapshot<TNode>[]","descendants: TreeNodeSnapshot<TNode>[]","results: TreeNodeSnapshot<TNode>[]","result: FlattenedNode<TNode>[]","result: AnyTreeNodePrimitive[]"],"sources":["../../src/utils/tree-helpers.ts"],"sourcesContent":["/**\n * Tree snapshot utility functions.\n *\n * Standalone helpers for traversing and querying tree snapshots.\n * All functions handle undefined snapshots gracefully.\n *\n * @since 0.0.1\n */\n\nimport type { TreeNodeSnapshot, TreePrimitive } from \"../primitives/Tree\";\nimport type { AnyTreeNodePrimitive } from \"../primitives/TreeNode\";\n\n// =============================================================================\n// Result Types\n// =============================================================================\n\n/**\n * Result of finding a node with path information.\n */\nexport interface NodeSearchResult<TNode extends AnyTreeNodePrimitive> {\n readonly node: TreeNodeSnapshot<TNode>;\n readonly path: readonly string[]; // Array of node IDs from root to this node\n readonly depth: number;\n}\n\n/**\n * Result of finding a parent node.\n */\nexport interface ParentSearchResult<TNode extends AnyTreeNodePrimitive> {\n readonly parent: TreeNodeSnapshot<TNode>;\n readonly childIndex: number; // Index of the target node in parent's children\n}\n\n/**\n * Flattened node with parent information.\n */\nexport interface FlattenedNode<TNode extends AnyTreeNodePrimitive> {\n readonly node: TreeNodeSnapshot<TNode>;\n readonly parentId: string | null;\n readonly depth: number;\n}\n\n/**\n * Options for tree traversal.\n */\nexport interface TraverseOptions {\n readonly order?: \"pre\" | \"post\";\n}\n\n// =============================================================================\n// Core Functions\n// =============================================================================\n\n/**\n * Find a node by ID in a tree snapshot.\n *\n * @param snapshot - The root tree snapshot\n * @param id - The node ID to find\n * @returns The node snapshot if found, undefined otherwise\n */\nexport function findNodeById<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n id: string\n): TreeNodeSnapshot<TNode> | undefined {\n if (!snapshot) return undefined;\n if (snapshot.id === id) return snapshot;\n\n for (const child of snapshot.children) {\n const found = findNodeById(child as TreeNodeSnapshot<TNode>, id);\n if (found) return found;\n }\n\n return undefined;\n}\n\n/**\n * Find a node by ID with full path information.\n *\n * @param snapshot - The root tree snapshot\n * @param id - The node ID to find\n * @returns NodeSearchResult with node, path, and depth, or undefined if not found\n */\nexport function findNodeWithPath<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n id: string\n): NodeSearchResult<TNode> | undefined {\n if (!snapshot) return undefined;\n\n const search = (\n node: TreeNodeSnapshot<TNode>,\n currentPath: string[],\n depth: number\n ): NodeSearchResult<TNode> | undefined => {\n const path = [...currentPath, node.id];\n\n if (node.id === id) {\n return { node, path, depth };\n }\n\n for (const child of node.children) {\n const result = search(child as TreeNodeSnapshot<TNode>, path, depth + 1);\n if (result) return result;\n }\n\n return undefined;\n };\n\n return search(snapshot, [], 0);\n}\n\n/**\n * Get the parent node of a given node ID.\n *\n * @param snapshot - The root tree snapshot\n * @param nodeId - The ID of the node whose parent we want\n * @returns ParentSearchResult with parent node and child index, or undefined\n */\nexport function getParent<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n nodeId: string\n): ParentSearchResult<TNode> | undefined {\n if (!snapshot) return undefined;\n\n // Check if any direct child is the target\n for (let i = 0; i < snapshot.children.length; i++) {\n const child = snapshot.children[i];\n if (child && child.id === nodeId) {\n return {\n parent: snapshot,\n childIndex: i,\n };\n }\n }\n\n // Recursively search children\n for (const child of snapshot.children) {\n const result = getParent(child as TreeNodeSnapshot<TNode>, nodeId);\n if (result) return result;\n }\n\n return undefined;\n}\n\n/**\n * Get a subtree rooted at a specific node ID.\n *\n * @param snapshot - The root tree snapshot\n * @param nodeId - The ID of the node to use as new root\n * @returns The subtree snapshot, or undefined if node not found\n */\nexport function getSubtree<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n nodeId: string\n): TreeNodeSnapshot<TNode> | undefined {\n return findNodeById(snapshot, nodeId);\n}\n\n/**\n * Get all ancestor nodes from a node up to the root.\n *\n * @param snapshot - The root tree snapshot\n * @param nodeId - The ID of the node\n * @returns Array of ancestor snapshots from immediate parent to root, or empty array\n */\nexport function getAncestors<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n nodeId: string\n): readonly TreeNodeSnapshot<TNode>[] {\n if (!snapshot) return [];\n\n const result = findNodeWithPath(snapshot, nodeId);\n if (!result || result.path.length <= 1) return [];\n\n // Path includes the node itself, so we need all nodes except the last one\n const ancestorIds = result.path.slice(0, -1);\n const ancestors: TreeNodeSnapshot<TNode>[] = [];\n\n // Collect ancestors in reverse order (parent first, root last)\n for (let i = ancestorIds.length - 1; i >= 0; i--) {\n const id = ancestorIds[i];\n if (id) {\n const ancestor = findNodeById(snapshot, id);\n if (ancestor) {\n ancestors.push(ancestor);\n }\n }\n }\n\n return ancestors;\n}\n\n/**\n * Get all descendant nodes of a given node (flat array).\n *\n * @param snapshot - The root tree snapshot\n * @param nodeId - The ID of the node (if undefined, returns all descendants of root)\n * @returns Flat array of all descendant node snapshots\n */\nexport function getDescendants<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n nodeId?: string\n): readonly TreeNodeSnapshot<TNode>[] {\n if (!snapshot) return [];\n\n const startNode = nodeId ? findNodeById(snapshot, nodeId) : snapshot;\n if (!startNode) return [];\n\n const descendants: TreeNodeSnapshot<TNode>[] = [];\n\n const collect = (node: TreeNodeSnapshot<TNode>) => {\n for (const child of node.children) {\n descendants.push(child as TreeNodeSnapshot<TNode>);\n collect(child as TreeNodeSnapshot<TNode>);\n }\n };\n\n collect(startNode);\n return descendants;\n}\n\n/**\n * Get siblings of a node (nodes with the same parent).\n *\n * @param snapshot - The root tree snapshot\n * @param nodeId - The ID of the node\n * @param includeSelf - Whether to include the node itself (default: false)\n * @returns Array of sibling snapshots\n */\nexport function getSiblings<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n nodeId: string,\n includeSelf: boolean = false\n): readonly TreeNodeSnapshot<TNode>[] {\n if (!snapshot) return [];\n\n const parentResult = getParent(snapshot, nodeId);\n\n // If no parent, this is the root - root has no siblings\n if (!parentResult) return [];\n\n const siblings = parentResult.parent.children as readonly TreeNodeSnapshot<TNode>[];\n\n if (includeSelf) {\n return siblings;\n }\n\n return siblings.filter((s) => s.id !== nodeId);\n}\n\n// =============================================================================\n// Query Functions\n// =============================================================================\n\n/**\n * Find the first node matching a predicate.\n *\n * @param snapshot - The root tree snapshot\n * @param predicate - Function to test each node\n * @returns First matching node snapshot, or undefined\n */\nexport function findNode<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n predicate: (node: TreeNodeSnapshot<TNode>) => boolean\n): TreeNodeSnapshot<TNode> | undefined {\n if (!snapshot) return undefined;\n\n if (predicate(snapshot)) return snapshot;\n\n for (const child of snapshot.children) {\n const found = findNode(child as TreeNodeSnapshot<TNode>, predicate);\n if (found) return found;\n }\n\n return undefined;\n}\n\n/**\n * Find all nodes matching a predicate.\n *\n * @param snapshot - The root tree snapshot\n * @param predicate - Function to test each node\n * @returns Array of matching node snapshots\n */\nexport function findNodes<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n predicate: (node: TreeNodeSnapshot<TNode>) => boolean\n): readonly TreeNodeSnapshot<TNode>[] {\n if (!snapshot) return [];\n\n const results: TreeNodeSnapshot<TNode>[] = [];\n\n const search = (node: TreeNodeSnapshot<TNode>) => {\n if (predicate(node)) {\n results.push(node);\n }\n for (const child of node.children) {\n search(child as TreeNodeSnapshot<TNode>);\n }\n };\n\n search(snapshot);\n return results;\n}\n\n/**\n * Get the depth of a specific node (0 = root).\n *\n * @param snapshot - The root tree snapshot\n * @param nodeId - The ID of the node\n * @returns The depth, or -1 if not found\n */\nexport function getNodeDepth<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n nodeId: string\n): number {\n if (!snapshot) return -1;\n\n const result = findNodeWithPath(snapshot, nodeId);\n return result ? result.depth : -1;\n}\n\n/**\n * Check if one node is an ancestor of another.\n *\n * @param snapshot - The root tree snapshot\n * @param ancestorId - Potential ancestor node ID\n * @param descendantId - Potential descendant node ID\n * @returns true if ancestorId is an ancestor of descendantId\n */\nexport function isAncestorOf<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n ancestorId: string,\n descendantId: string\n): boolean {\n if (!snapshot) return false;\n\n const result = findNodeWithPath(snapshot, descendantId);\n if (!result) return false;\n\n // Check if ancestorId is in the path (excluding the descendant itself)\n return result.path.slice(0, -1).includes(ancestorId);\n}\n\n// =============================================================================\n// Traversal Functions\n// =============================================================================\n\n/**\n * Traverse the tree and call a visitor function for each node.\n * Return false from visitor to stop traversal.\n *\n * @param snapshot - The root tree snapshot\n * @param visitor - Function called for each node (return false to stop)\n * @param options - Traversal options (order: 'pre' | 'post')\n */\nexport function traverse<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n visitor: (node: TreeNodeSnapshot<TNode>, depth: number) => void | false,\n options: TraverseOptions = {}\n): void {\n if (!snapshot) return;\n\n const { order = \"pre\" } = options;\n\n const visit = (node: TreeNodeSnapshot<TNode>, depth: number): boolean => {\n if (order === \"pre\") {\n const result = visitor(node, depth);\n if (result === false) return false;\n }\n\n for (const child of node.children) {\n const shouldContinue = visit(child as TreeNodeSnapshot<TNode>, depth + 1);\n if (!shouldContinue) return false;\n }\n\n if (order === \"post\") {\n const result = visitor(node, depth);\n if (result === false) return false;\n }\n\n return true;\n };\n\n visit(snapshot, 0);\n}\n\n/**\n * Flatten the tree into an array with parent information.\n *\n * @param snapshot - The root tree snapshot\n * @returns Array of { node, parentId, depth } objects\n */\nexport function flattenTree<TNode extends AnyTreeNodePrimitive>(\n snapshot: TreeNodeSnapshot<TNode> | undefined\n): readonly FlattenedNode<TNode>[] {\n if (!snapshot) return [];\n\n const result: FlattenedNode<TNode>[] = [];\n\n const flatten = (\n node: TreeNodeSnapshot<TNode>,\n parentId: string | null,\n depth: number\n ) => {\n result.push({ node, parentId, depth });\n\n for (const child of node.children) {\n flatten(child as TreeNodeSnapshot<TNode>, node.id, depth + 1);\n }\n };\n\n flatten(snapshot, null, 0);\n return result;\n}\n\n/**\n * Map over all nodes in the tree, transforming each node's data.\n * Preserves tree structure while transforming node content.\n *\n * @param snapshot - The root tree snapshot\n * @param mapper - Function to transform each node\n * @returns New tree structure with transformed nodes, or undefined\n */\nexport function mapTree<TNode extends AnyTreeNodePrimitive, R>(\n snapshot: TreeNodeSnapshot<TNode> | undefined,\n mapper: (node: TreeNodeSnapshot<TNode>, depth: number) => R\n): { value: R; children: ReturnType<typeof mapTree<TNode, R>>[] } | undefined {\n if (!snapshot) return undefined;\n\n const map = (\n node: TreeNodeSnapshot<TNode>,\n depth: number\n ): { value: R; children: ReturnType<typeof mapTree<TNode, R>>[] } => {\n const value = mapper(node, depth);\n const children = node.children.map((child) =>\n map(child as TreeNodeSnapshot<TNode>, depth + 1)\n );\n return { value, children };\n };\n\n return map(snapshot, 0);\n}\n\n// =============================================================================\n// Schema Functions (work with TreeNodePrimitive, not snapshots)\n// =============================================================================\n\n/**\n * Build a lookup map from node type strings to their TreeNodePrimitive definitions.\n * Useful for resolving snapshot node types back to their schema definitions.\n *\n * @param tree - The TreePrimitive to analyze\n * @returns Map from type string to TreeNodePrimitive\n *\n * @example\n * ```ts\n * const typeMap = buildNodeTypeMap(fileTree);\n * const folderPrimitive = typeMap.get(\"folder\"); // FolderNode\n * ```\n */\nexport function buildNodeTypeMap<TRoot extends AnyTreeNodePrimitive>(\n tree: TreePrimitive<TRoot>\n): Map<string, AnyTreeNodePrimitive> {\n const map = 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 map.set(node.type, node);\n\n for (const child of node.children) {\n visit(child);\n }\n };\n\n visit(tree.root);\n return map;\n}\n\n/**\n * Get the TreeNodePrimitive definition for a snapshot node.\n * Requires the tree schema to resolve the type string to its primitive.\n *\n * @param tree - The TreePrimitive schema\n * @param snapshot - The node snapshot to get the primitive for\n * @returns The TreeNodePrimitive, or undefined if not found\n *\n * @example\n * ```ts\n * const node = findNodeById(treeSnapshot, \"some-id\");\n * const primitive = getNodePrimitive(fileTree, node);\n * // primitive is FolderNode or FileNode depending on node.type\n * ```\n */\nexport function getNodePrimitive<TRoot extends AnyTreeNodePrimitive>(\n tree: TreePrimitive<TRoot>,\n snapshot: TreeNodeSnapshot<AnyTreeNodePrimitive>\n): AnyTreeNodePrimitive | undefined {\n return getNodeTypeByName(tree, snapshot.type);\n}\n\n/**\n * Get the allowed child types for a snapshot node.\n * Combines schema lookup with the node's allowed children.\n *\n * @param tree - The TreePrimitive schema\n * @param snapshot - The node snapshot to get allowed children for\n * @returns Array of allowed child TreeNodePrimitives, or empty array if not found\n *\n * @example\n * ```ts\n * const node = findNodeById(treeSnapshot, \"folder-id\");\n * const allowedChildren = getAllowedChildTypesForNode(fileTree, node);\n * // Returns [FolderNode, FileNode] if the folder can contain both\n * ```\n */\nexport function getAllowedChildTypesForNode<TRoot extends AnyTreeNodePrimitive>(\n tree: TreePrimitive<TRoot>,\n snapshot: TreeNodeSnapshot<AnyTreeNodePrimitive>\n): readonly AnyTreeNodePrimitive[] {\n const primitive = getNodePrimitive(tree, snapshot);\n if (!primitive) return [];\n return primitive.children;\n}\n\n/**\n * Check if a child type is allowed for a specific snapshot node.\n *\n * @param tree - The TreePrimitive schema\n * @param parentSnapshot - The parent node snapshot\n * @param childTypeName - The type string of the potential child\n * @returns true if the child type is allowed\n *\n * @example\n * ```ts\n * const folder = findNodeById(treeSnapshot, \"folder-id\");\n * canAddChildType(fileTree, folder, \"file\"); // true\n * canAddChildType(fileTree, folder, \"unknown\"); // false\n * ```\n */\nexport function canAddChildType<TRoot extends AnyTreeNodePrimitive>(\n tree: TreePrimitive<TRoot>,\n parentSnapshot: TreeNodeSnapshot<AnyTreeNodePrimitive>,\n childTypeName: string\n): boolean {\n const primitive = getNodePrimitive(tree, parentSnapshot);\n if (!primitive) return false;\n return primitive.isChildAllowed(childTypeName);\n}\n\n/**\n * Get all allowed child node types for a specific node type.\n *\n * @param nodeType - The TreeNodePrimitive to get children for\n * @returns Array of allowed child TreeNodePrimitives\n *\n * @example\n * ```ts\n * const FolderNode = TreeNode(\"folder\", { ... });\n * const FileNode = TreeNode(\"file\", { ... });\n *\n * // Get allowed children for FolderNode\n * const allowedChildren = getAllowedChildTypes(FolderNode);\n * // Returns [FolderNode, FileNode] if folder can contain both\n * ```\n */\nexport function getAllowedChildTypes<TNode extends AnyTreeNodePrimitive>(\n nodeType: TNode\n): readonly AnyTreeNodePrimitive[] {\n return nodeType.children;\n}\n\n/**\n * Get all unique node types reachable in a tree schema.\n * Recursively traverses the tree structure starting from the root.\n *\n * @param tree - The TreePrimitive to analyze\n * @returns Array of all unique TreeNodePrimitives in the tree schema\n *\n * @example\n * ```ts\n * const fileTree = Tree({ root: FolderNode });\n * const allNodeTypes = getAllNodeTypes(fileTree);\n * // Returns [FolderNode, FileNode] - all possible node types\n * ```\n */\nexport function getAllNodeTypes<TRoot extends AnyTreeNodePrimitive>(\n tree: TreePrimitive<TRoot>\n): readonly AnyTreeNodePrimitive[] {\n const visited = new Set<string>();\n const result: AnyTreeNodePrimitive[] = [];\n\n const visit = (node: AnyTreeNodePrimitive) => {\n if (visited.has(node.type)) return;\n visited.add(node.type);\n result.push(node);\n\n for (const child of node.children) {\n visit(child);\n }\n };\n\n visit(tree.root);\n return result;\n}\n\n/**\n * Get the node type primitive by its type string from a tree schema.\n *\n * @param tree - The TreePrimitive to search\n * @param typeName - The type string to find (e.g., \"folder\", \"file\")\n * @returns The matching TreeNodePrimitive, or undefined if not found\n *\n * @example\n * ```ts\n * const fileTree = Tree({ root: FolderNode });\n * const folderType = getNodeTypeByName(fileTree, \"folder\");\n * // Returns FolderNode\n * ```\n */\nexport function getNodeTypeByName<TRoot extends AnyTreeNodePrimitive>(\n tree: TreePrimitive<TRoot>,\n typeName: string\n): AnyTreeNodePrimitive | undefined {\n const allTypes = getAllNodeTypes(tree);\n return allTypes.find((node) => node.type === typeName);\n}\n\n/**\n * Check if a child type is allowed under a parent type.\n *\n * @param parentType - The parent TreeNodePrimitive\n * @param childTypeName - The type string of the potential child\n * @returns true if the child type is allowed\n *\n * @example\n * ```ts\n * isChildTypeAllowed(FolderNode, \"file\"); // true if folder can contain files\n * isChildTypeAllowed(FileNode, \"folder\"); // false - files can't have children\n * ```\n */\nexport function isChildTypeAllowed(\n parentType: AnyTreeNodePrimitive,\n childTypeName: string\n): boolean {\n return parentType.isChildAllowed(childTypeName);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA,SAAgB,aACd,UACA,IACqC;AACrC,KAAI,CAAC,SAAU,QAAO;AACtB,KAAI,SAAS,OAAO,GAAI,QAAO;AAE/B,MAAK,MAAM,SAAS,SAAS,UAAU;EACrC,MAAM,QAAQ,a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|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voidhash/mimic",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
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.
|
|
34
|
+
"@voidhash/tsconfig": "1.0.0-beta.1"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"effect": "^3.19.12"
|
package/src/client/index.ts
CHANGED
|
@@ -11,37 +11,37 @@
|
|
|
11
11
|
// Presence (re-exported from core for convenience)
|
|
12
12
|
// =============================================================================
|
|
13
13
|
|
|
14
|
-
export * as Presence from "../Presence
|
|
14
|
+
export * as Presence from "../Presence";
|
|
15
15
|
|
|
16
16
|
// =============================================================================
|
|
17
17
|
// Main Client Document
|
|
18
18
|
// =============================================================================
|
|
19
19
|
|
|
20
|
-
export * as ClientDocument from "./ClientDocument
|
|
20
|
+
export * as ClientDocument from "./ClientDocument";
|
|
21
21
|
|
|
22
22
|
// =============================================================================
|
|
23
23
|
// Transport Interface
|
|
24
24
|
// =============================================================================
|
|
25
25
|
|
|
26
|
-
export * as Transport from "./Transport
|
|
26
|
+
export * as Transport from "./Transport";
|
|
27
27
|
|
|
28
28
|
// =============================================================================
|
|
29
29
|
// WebSocket Transport
|
|
30
30
|
// =============================================================================
|
|
31
31
|
|
|
32
|
-
export * as WebSocketTransport from "./WebSocketTransport
|
|
32
|
+
export * as WebSocketTransport from "./WebSocketTransport";
|
|
33
33
|
|
|
34
34
|
// =============================================================================
|
|
35
35
|
// Rebase Logic
|
|
36
36
|
// =============================================================================
|
|
37
37
|
|
|
38
|
-
export * as Rebase from "./Rebase
|
|
38
|
+
export * as Rebase from "./Rebase";
|
|
39
39
|
|
|
40
40
|
// =============================================================================
|
|
41
41
|
// State Monitoring
|
|
42
42
|
// =============================================================================
|
|
43
43
|
|
|
44
|
-
export * as StateMonitor from "./StateMonitor
|
|
44
|
+
export * as StateMonitor from "./StateMonitor";
|
|
45
45
|
|
|
46
46
|
// =============================================================================
|
|
47
47
|
// Errors
|
|
@@ -58,4 +58,4 @@ export {
|
|
|
58
58
|
InvalidStateError,
|
|
59
59
|
WebSocketError,
|
|
60
60
|
AuthenticationError,
|
|
61
|
-
} from "./errors
|
|
61
|
+
} from "./errors";
|
package/src/index.ts
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* @since 0.0.1
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
export * as Primitive from "./Primitive
|
|
6
|
-
export * as Document from "./Document
|
|
7
|
-
export * as Transaction from "./Transaction
|
|
8
|
-
export * as Operation from "./Operation
|
|
9
|
-
export * as OperationPath from "./OperationPath
|
|
10
|
-
export * as ProxyEnvironment from "./ProxyEnvironment
|
|
11
|
-
export * as Transform from "./Transform
|
|
12
|
-
export * as Presence from "./Presence
|
|
13
|
-
export * as EffectSchema from "./EffectSchema
|
|
14
|
-
export * as Types from "./types/index
|
|
15
|
-
export * as TreeHelpers from "./utils/tree-helpers
|
|
5
|
+
export * as Primitive from "./Primitive";
|
|
6
|
+
export * as Document from "./Document";
|
|
7
|
+
export * as Transaction from "./Transaction";
|
|
8
|
+
export * as Operation from "./Operation";
|
|
9
|
+
export * as OperationPath from "./OperationPath";
|
|
10
|
+
export * as ProxyEnvironment from "./ProxyEnvironment";
|
|
11
|
+
export * as Transform from "./Transform";
|
|
12
|
+
export * as Presence from "./Presence";
|
|
13
|
+
export * as EffectSchema from "./EffectSchema";
|
|
14
|
+
export * as Types from "./types/index";
|
|
15
|
+
export * as TreeHelpers from "./utils/tree-helpers";
|
package/src/server/index.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// Server Document
|
|
12
12
|
// =============================================================================
|
|
13
13
|
|
|
14
|
-
export * as ServerDocument from "./ServerDocument
|
|
14
|
+
export * as ServerDocument from "./ServerDocument";
|
|
15
15
|
|
|
16
16
|
// =============================================================================
|
|
17
17
|
// Errors
|
|
@@ -24,7 +24,7 @@ export {
|
|
|
24
24
|
StateValidationError,
|
|
25
25
|
EmptyTransactionError,
|
|
26
26
|
DuplicateTransactionError,
|
|
27
|
-
} from "./errors
|
|
27
|
+
} from "./errors";
|
|
28
28
|
|
|
29
29
|
// =============================================================================
|
|
30
30
|
// Re-export Types (for convenience)
|
|
@@ -37,4 +37,4 @@ export type {
|
|
|
37
37
|
SnapshotMessage,
|
|
38
38
|
SubmitResult,
|
|
39
39
|
ServerDocumentOptions,
|
|
40
|
-
} from "./ServerDocument
|
|
40
|
+
} from "./ServerDocument";
|
package/src/types/index.ts
CHANGED
|
@@ -40,7 +40,7 @@ export type {
|
|
|
40
40
|
|
|
41
41
|
// Validator type
|
|
42
42
|
Validator,
|
|
43
|
-
} from "../primitives/shared
|
|
43
|
+
} from "../primitives/shared";
|
|
44
44
|
|
|
45
45
|
// =============================================================================
|
|
46
46
|
// Struct Inference Types
|
|
@@ -52,7 +52,7 @@ export type {
|
|
|
52
52
|
StructSetInput,
|
|
53
53
|
StructUpdateValue,
|
|
54
54
|
StructProxy,
|
|
55
|
-
} from "../primitives/Struct
|
|
55
|
+
} from "../primitives/Struct";
|
|
56
56
|
|
|
57
57
|
// =============================================================================
|
|
58
58
|
// Array Inference Types
|
|
@@ -67,7 +67,7 @@ export type {
|
|
|
67
67
|
ArrayUpdateInput,
|
|
68
68
|
ArrayElementSetInput,
|
|
69
69
|
ArrayProxy,
|
|
70
|
-
} from "../primitives/Array
|
|
70
|
+
} from "../primitives/Array";
|
|
71
71
|
|
|
72
72
|
// =============================================================================
|
|
73
73
|
// Tree Inference Types
|
|
@@ -86,7 +86,7 @@ export type {
|
|
|
86
86
|
TreeProxy,
|
|
87
87
|
TypedNodeProxy,
|
|
88
88
|
TreeNodeProxyBase,
|
|
89
|
-
} from "../primitives/Tree
|
|
89
|
+
} from "../primitives/Tree";
|
|
90
90
|
|
|
91
91
|
// =============================================================================
|
|
92
92
|
// TreeNode Inference Types
|
|
@@ -100,9 +100,9 @@ export type {
|
|
|
100
100
|
TreeNodeSelfType,
|
|
101
101
|
TreeNodeConfig,
|
|
102
102
|
TreeNodeChildrenInput,
|
|
103
|
-
} from "../primitives/TreeNode
|
|
103
|
+
} from "../primitives/TreeNode";
|
|
104
104
|
|
|
105
|
-
export { TreeNodePrimitive, TreeNodeSelf } from "../primitives/TreeNode
|
|
105
|
+
export { TreeNodePrimitive, TreeNodeSelf } from "../primitives/TreeNode";
|
|
106
106
|
|
|
107
107
|
// =============================================================================
|
|
108
108
|
// Union Inference Types
|
|
@@ -112,7 +112,7 @@ export type {
|
|
|
112
112
|
InferUnionState,
|
|
113
113
|
InferUnionSnapshot,
|
|
114
114
|
UnionVariants,
|
|
115
|
-
} from "../primitives/Union
|
|
115
|
+
} from "../primitives/Union";
|
|
116
116
|
|
|
117
117
|
// =============================================================================
|
|
118
118
|
// Either Inference Types
|
|
@@ -122,7 +122,7 @@ export type {
|
|
|
122
122
|
InferEitherState,
|
|
123
123
|
InferEitherSnapshot,
|
|
124
124
|
ScalarPrimitive,
|
|
125
|
-
} from "../primitives/Either
|
|
125
|
+
} from "../primitives/Either";
|
|
126
126
|
|
|
127
127
|
// =============================================================================
|
|
128
128
|
// Lazy Inference Types
|
|
@@ -134,4 +134,4 @@ export type {
|
|
|
134
134
|
InferLazySnapshot,
|
|
135
135
|
InferLazySetInput,
|
|
136
136
|
InferLazyUpdateInput,
|
|
137
|
-
} from "../primitives/Lazy
|
|
137
|
+
} from "../primitives/Lazy";
|
package/src/utils/index.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* @since 0.0.1
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type { TreeNodeSnapshot, TreePrimitive } from "../primitives/Tree
|
|
11
|
-
import type { AnyTreeNodePrimitive } from "../primitives/TreeNode
|
|
10
|
+
import type { TreeNodeSnapshot, TreePrimitive } from "../primitives/Tree";
|
|
11
|
+
import type { AnyTreeNodePrimitive } from "../primitives/TreeNode";
|
|
12
12
|
|
|
13
13
|
// =============================================================================
|
|
14
14
|
// Result Types
|