@voidhash/mimic 0.0.1 → 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.
- package/.turbo/turbo-build.log +257 -42
- package/dist/Document.cjs +152 -0
- package/dist/Document.d.cts +67 -0
- package/dist/Document.d.cts.map +1 -0
- package/dist/Document.d.mts +68 -0
- package/dist/Document.d.mts.map +1 -0
- package/dist/Document.mjs +147 -0
- package/dist/Document.mjs.map +1 -0
- package/dist/EffectSchema.cjs +180 -0
- package/dist/EffectSchema.d.cts +84 -0
- package/dist/EffectSchema.d.cts.map +1 -0
- package/dist/EffectSchema.d.mts +84 -0
- package/dist/EffectSchema.d.mts.map +1 -0
- package/dist/EffectSchema.mjs +176 -0
- package/dist/EffectSchema.mjs.map +1 -0
- package/dist/FractionalIndex.cjs +365 -0
- package/dist/FractionalIndex.mjs +364 -0
- package/dist/FractionalIndex.mjs.map +1 -0
- package/dist/Operation.cjs +53 -0
- package/dist/Operation.d.cts +39 -0
- package/dist/Operation.d.cts.map +1 -0
- package/dist/Operation.d.mts +39 -0
- package/dist/Operation.d.mts.map +1 -0
- package/dist/Operation.mjs +46 -0
- package/dist/Operation.mjs.map +1 -0
- package/dist/OperationDefinition.cjs +13 -0
- package/dist/OperationDefinition.d.cts +12 -0
- package/dist/OperationDefinition.d.cts.map +1 -0
- package/dist/OperationDefinition.d.mts +12 -0
- package/dist/OperationDefinition.d.mts.map +1 -0
- package/dist/OperationDefinition.mjs +13 -0
- package/dist/OperationDefinition.mjs.map +1 -0
- package/dist/OperationPath.cjs +148 -0
- package/dist/OperationPath.d.cts +60 -0
- package/dist/OperationPath.d.cts.map +1 -0
- package/dist/OperationPath.d.mts +60 -0
- package/dist/OperationPath.d.mts.map +1 -0
- package/dist/OperationPath.mjs +138 -0
- package/dist/OperationPath.mjs.map +1 -0
- package/dist/{Presence-gWrmGBeu.cjs → Presence.cjs} +4 -39
- package/dist/{Presence-N8u7Eppr.d.mts → Presence.d.cts} +2 -2
- package/dist/Presence.d.cts.map +1 -0
- package/dist/{Presence-DKKP4v5X.d.cts → Presence.d.mts} +2 -2
- package/dist/Presence.d.mts.map +1 -0
- package/dist/{Presence-DdMVKcOv.mjs → Presence.mjs} +3 -28
- package/dist/Presence.mjs.map +1 -0
- package/dist/Primitive.cjs +52 -0
- package/dist/Primitive.d.cts +20 -0
- package/dist/Primitive.d.cts.map +1 -0
- package/dist/Primitive.d.mts +20 -0
- package/dist/Primitive.d.mts.map +1 -0
- package/dist/Primitive.mjs +48 -0
- package/dist/Primitive.mjs.map +1 -0
- package/dist/ProxyEnvironment.cjs +34 -0
- package/dist/ProxyEnvironment.d.cts +31 -0
- package/dist/ProxyEnvironment.d.cts.map +1 -0
- package/dist/ProxyEnvironment.d.mts +31 -0
- package/dist/ProxyEnvironment.d.mts.map +1 -0
- package/dist/ProxyEnvironment.mjs +29 -0
- package/dist/ProxyEnvironment.mjs.map +1 -0
- package/dist/Transaction.cjs +66 -0
- package/dist/Transaction.d.cts +56 -0
- package/dist/Transaction.d.cts.map +1 -0
- package/dist/Transaction.d.mts +56 -0
- package/dist/Transaction.d.mts.map +1 -0
- package/dist/Transaction.mjs +58 -0
- package/dist/Transaction.mjs.map +1 -0
- package/dist/Transform.cjs +11 -0
- package/dist/Transform.d.cts +21 -0
- package/dist/Transform.d.cts.map +1 -0
- package/dist/Transform.d.mts +21 -0
- package/dist/Transform.d.mts.map +1 -0
- package/dist/Transform.mjs +6 -0
- package/dist/Transform.mjs.map +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.cjs +14 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.mjs +14 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectSpread2.cjs +27 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectSpread2.mjs +27 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPrimitive.cjs +16 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPrimitive.mjs +16 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPropertyKey.cjs +11 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPropertyKey.mjs +11 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/typeof.cjs +18 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/typeof.mjs +12 -0
- package/dist/_virtual/rolldown_runtime.cjs +43 -0
- package/dist/{chunk-CLMFDpHK.mjs → _virtual/rolldown_runtime.mjs} +1 -1
- package/dist/client/ClientDocument.cjs +590 -0
- package/dist/client/ClientDocument.d.cts +161 -0
- package/dist/client/ClientDocument.d.cts.map +1 -0
- package/dist/client/ClientDocument.d.mts +162 -0
- package/dist/client/ClientDocument.d.mts.map +1 -0
- package/dist/client/ClientDocument.mjs +586 -0
- package/dist/client/ClientDocument.mjs.map +1 -0
- package/dist/client/Rebase.cjs +204 -0
- package/dist/client/Rebase.d.cts +87 -0
- package/dist/client/Rebase.d.cts.map +1 -0
- package/dist/client/Rebase.d.mts +88 -0
- package/dist/client/Rebase.d.mts.map +1 -0
- package/dist/client/Rebase.mjs +198 -0
- package/dist/client/Rebase.mjs.map +1 -0
- package/dist/client/StateMonitor.cjs +133 -0
- package/dist/client/StateMonitor.d.cts +122 -0
- package/dist/client/StateMonitor.d.cts.map +1 -0
- package/dist/client/StateMonitor.d.mts +122 -0
- package/dist/client/StateMonitor.d.mts.map +1 -0
- package/dist/client/StateMonitor.mjs +129 -0
- package/dist/client/StateMonitor.mjs.map +1 -0
- package/dist/client/Transport.cjs +11 -0
- package/dist/client/Transport.d.cts +237 -0
- package/dist/client/Transport.d.cts.map +1 -0
- package/dist/client/Transport.d.mts +237 -0
- package/dist/client/Transport.d.mts.map +1 -0
- package/dist/client/Transport.mjs +6 -0
- package/dist/client/Transport.mjs.map +1 -0
- package/dist/client/WebSocketTransport.cjs +396 -0
- package/dist/client/WebSocketTransport.d.cts +29 -0
- package/dist/client/WebSocketTransport.d.cts.map +1 -0
- package/dist/client/WebSocketTransport.d.mts +29 -0
- package/dist/client/WebSocketTransport.d.mts.map +1 -0
- package/dist/client/WebSocketTransport.mjs +392 -0
- package/dist/client/WebSocketTransport.mjs.map +1 -0
- package/dist/client/errors.cjs +135 -0
- package/dist/client/errors.d.cts +87 -0
- package/dist/client/errors.d.cts.map +1 -0
- package/dist/client/errors.d.mts +87 -0
- package/dist/client/errors.d.mts.map +1 -0
- package/dist/client/errors.mjs +127 -0
- package/dist/client/errors.mjs.map +1 -0
- package/dist/client/index.cjs +22 -1424
- package/dist/client/index.d.cts +8 -692
- package/dist/client/index.d.mts +8 -692
- package/dist/client/index.mjs +9 -1413
- package/dist/index.cjs +30 -2529
- package/dist/index.d.cts +12 -143
- package/dist/index.d.mts +12 -143
- package/dist/index.mjs +13 -2526
- package/dist/primitives/Array.cjs +302 -0
- package/dist/primitives/Array.d.cts +95 -0
- package/dist/primitives/Array.d.cts.map +1 -0
- package/dist/primitives/Array.d.mts +95 -0
- package/dist/primitives/Array.d.mts.map +1 -0
- package/dist/primitives/Array.mjs +301 -0
- package/dist/primitives/Array.mjs.map +1 -0
- package/dist/primitives/Boolean.cjs +95 -0
- package/dist/primitives/Boolean.d.cts +44 -0
- package/dist/primitives/Boolean.d.cts.map +1 -0
- package/dist/primitives/Boolean.d.mts +44 -0
- package/dist/primitives/Boolean.d.mts.map +1 -0
- package/dist/primitives/Boolean.mjs +94 -0
- package/dist/primitives/Boolean.mjs.map +1 -0
- package/dist/primitives/Either.cjs +200 -0
- package/dist/primitives/Either.d.cts +113 -0
- package/dist/primitives/Either.d.cts.map +1 -0
- package/dist/primitives/Either.d.mts +113 -0
- package/dist/primitives/Either.d.mts.map +1 -0
- package/dist/primitives/Either.mjs +199 -0
- package/dist/primitives/Either.mjs.map +1 -0
- package/dist/primitives/Lazy.cjs +46 -0
- package/dist/primitives/Lazy.d.cts +46 -0
- package/dist/primitives/Lazy.d.cts.map +1 -0
- package/dist/primitives/Lazy.d.mts +46 -0
- package/dist/primitives/Lazy.d.mts.map +1 -0
- package/dist/primitives/Lazy.mjs +46 -0
- package/dist/primitives/Lazy.mjs.map +1 -0
- package/dist/primitives/Literal.cjs +91 -0
- package/dist/primitives/Literal.d.cts +46 -0
- package/dist/primitives/Literal.d.cts.map +1 -0
- package/dist/primitives/Literal.d.mts +46 -0
- package/dist/primitives/Literal.d.mts.map +1 -0
- package/dist/primitives/Literal.mjs +90 -0
- package/dist/primitives/Literal.mjs.map +1 -0
- package/dist/primitives/Number.cjs +115 -0
- package/dist/primitives/Number.d.cts +54 -0
- package/dist/primitives/Number.d.cts.map +1 -0
- package/dist/primitives/Number.d.mts +54 -0
- package/dist/primitives/Number.d.mts.map +1 -0
- package/dist/primitives/Number.mjs +114 -0
- package/dist/primitives/Number.mjs.map +1 -0
- package/dist/primitives/String.cjs +127 -0
- package/dist/primitives/String.d.cts +56 -0
- package/dist/primitives/String.d.cts.map +1 -0
- package/dist/primitives/String.d.mts +56 -0
- package/dist/primitives/String.d.mts.map +1 -0
- package/dist/primitives/String.mjs +126 -0
- package/dist/primitives/String.mjs.map +1 -0
- package/dist/primitives/Struct.cjs +207 -0
- package/dist/primitives/Struct.d.cts +96 -0
- package/dist/primitives/Struct.d.cts.map +1 -0
- package/dist/primitives/Struct.d.mts +97 -0
- package/dist/primitives/Struct.d.mts.map +1 -0
- package/dist/primitives/Struct.mjs +206 -0
- package/dist/primitives/Struct.mjs.map +1 -0
- package/dist/primitives/Tree.cjs +575 -0
- package/dist/primitives/Tree.d.cts +185 -0
- package/dist/primitives/Tree.d.cts.map +1 -0
- package/dist/primitives/Tree.d.mts +185 -0
- package/dist/primitives/Tree.d.mts.map +1 -0
- package/dist/primitives/Tree.mjs +574 -0
- package/dist/primitives/Tree.mjs.map +1 -0
- package/dist/primitives/TreeNode.cjs +73 -0
- package/dist/primitives/TreeNode.d.cts +92 -0
- package/dist/primitives/TreeNode.d.cts.map +1 -0
- package/dist/primitives/TreeNode.d.mts +93 -0
- package/dist/primitives/TreeNode.d.mts.map +1 -0
- package/dist/primitives/TreeNode.mjs +72 -0
- package/dist/primitives/TreeNode.mjs.map +1 -0
- package/dist/primitives/Union.cjs +170 -0
- package/dist/primitives/Union.d.cts +81 -0
- package/dist/primitives/Union.d.cts.map +1 -0
- package/dist/primitives/Union.d.mts +81 -0
- package/dist/primitives/Union.d.mts.map +1 -0
- package/dist/primitives/Union.mjs +169 -0
- package/dist/primitives/Union.mjs.map +1 -0
- package/dist/primitives/shared.cjs +60 -0
- package/dist/primitives/shared.d.cts +147 -0
- package/dist/primitives/shared.d.cts.map +1 -0
- package/dist/primitives/shared.d.mts +147 -0
- package/dist/primitives/shared.d.mts.map +1 -0
- package/dist/primitives/shared.mjs +58 -0
- package/dist/primitives/shared.mjs.map +1 -0
- package/dist/server/ServerDocument.cjs +110 -0
- package/dist/server/ServerDocument.d.cts +98 -0
- package/dist/server/ServerDocument.d.cts.map +1 -0
- package/dist/server/ServerDocument.d.mts +99 -0
- package/dist/server/ServerDocument.d.mts.map +1 -0
- package/dist/server/ServerDocument.mjs +106 -0
- package/dist/server/ServerDocument.mjs.map +1 -0
- package/dist/server/errors.cjs +85 -0
- package/dist/server/errors.d.cts +53 -0
- package/dist/server/errors.d.cts.map +1 -0
- package/dist/server/errors.d.mts +53 -0
- package/dist/server/errors.d.mts.map +1 -0
- package/dist/server/errors.mjs +81 -0
- package/dist/server/errors.mjs.map +1 -0
- package/dist/server/index.cjs +9 -185
- package/dist/server/index.d.cts +3 -148
- package/dist/server/index.d.mts +3 -148
- package/dist/server/index.mjs +3 -181
- package/dist/types/index.cjs +16 -0
- package/dist/types/index.d.cts +16 -0
- package/dist/types/index.d.cts.map +1 -0
- package/dist/types/index.d.mts +16 -0
- package/dist/types/index.d.mts.map +1 -0
- package/dist/types/index.mjs +12 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/utils/tree-helpers.cjs +443 -0
- package/dist/utils/tree-helpers.d.cts +280 -0
- package/dist/utils/tree-helpers.d.cts.map +1 -0
- package/dist/utils/tree-helpers.d.mts +280 -0
- package/dist/utils/tree-helpers.d.mts.map +1 -0
- package/dist/utils/tree-helpers.mjs +439 -0
- package/dist/utils/tree-helpers.mjs.map +1 -0
- package/package.json +2 -2
- package/src/index.ts +2 -0
- package/src/primitives/shared.ts +7 -1
- package/src/types/index.ts +137 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/tree-helpers.ts +648 -0
- package/tsdown.config.ts +1 -1
- package/dist/Document-ChuFrTk1.cjs +0 -571
- package/dist/Document-CwiAFTIq.mjs +0 -438
- package/dist/Document-CwiAFTIq.mjs.map +0 -1
- package/dist/Presence-DKKP4v5X.d.cts.map +0 -1
- package/dist/Presence-DdMVKcOv.mjs.map +0 -1
- package/dist/Presence-N8u7Eppr.d.mts.map +0 -1
- package/dist/Primitive-CvFVxR8_.d.cts +0 -1175
- package/dist/Primitive-CvFVxR8_.d.cts.map +0 -1
- package/dist/Primitive-lEhQyGVL.d.mts +0 -1175
- package/dist/Primitive-lEhQyGVL.d.mts.map +0 -1
- package/dist/client/index.d.cts.map +0 -1
- package/dist/client/index.d.mts.map +0 -1
- package/dist/client/index.mjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/server/index.d.cts.map +0 -1
- package/dist/server/index.d.mts.map +0 -1
- package/dist/server/index.mjs.map +0 -1
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import { __export } from "../_virtual/rolldown_runtime.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/tree-helpers.ts
|
|
4
|
+
var tree_helpers_exports = /* @__PURE__ */ __export({
|
|
5
|
+
buildNodeTypeMap: () => buildNodeTypeMap,
|
|
6
|
+
canAddChildType: () => canAddChildType,
|
|
7
|
+
findNode: () => findNode,
|
|
8
|
+
findNodeById: () => findNodeById,
|
|
9
|
+
findNodeWithPath: () => findNodeWithPath,
|
|
10
|
+
findNodes: () => findNodes,
|
|
11
|
+
flattenTree: () => flattenTree,
|
|
12
|
+
getAllNodeTypes: () => getAllNodeTypes,
|
|
13
|
+
getAllowedChildTypes: () => getAllowedChildTypes,
|
|
14
|
+
getAllowedChildTypesForNode: () => getAllowedChildTypesForNode,
|
|
15
|
+
getAncestors: () => getAncestors,
|
|
16
|
+
getDescendants: () => getDescendants,
|
|
17
|
+
getNodeDepth: () => getNodeDepth,
|
|
18
|
+
getNodePrimitive: () => getNodePrimitive,
|
|
19
|
+
getNodeTypeByName: () => getNodeTypeByName,
|
|
20
|
+
getParent: () => getParent,
|
|
21
|
+
getSiblings: () => getSiblings,
|
|
22
|
+
getSubtree: () => getSubtree,
|
|
23
|
+
isAncestorOf: () => isAncestorOf,
|
|
24
|
+
isChildTypeAllowed: () => isChildTypeAllowed,
|
|
25
|
+
mapTree: () => mapTree,
|
|
26
|
+
traverse: () => traverse
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Find a node by ID in a tree snapshot.
|
|
30
|
+
*
|
|
31
|
+
* @param snapshot - The root tree snapshot
|
|
32
|
+
* @param id - The node ID to find
|
|
33
|
+
* @returns The node snapshot if found, undefined otherwise
|
|
34
|
+
*/
|
|
35
|
+
function findNodeById(snapshot, id) {
|
|
36
|
+
if (!snapshot) return void 0;
|
|
37
|
+
if (snapshot.id === id) return snapshot;
|
|
38
|
+
for (const child of snapshot.children) {
|
|
39
|
+
const found = findNodeById(child, id);
|
|
40
|
+
if (found) return found;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Find a node by ID with full path information.
|
|
45
|
+
*
|
|
46
|
+
* @param snapshot - The root tree snapshot
|
|
47
|
+
* @param id - The node ID to find
|
|
48
|
+
* @returns NodeSearchResult with node, path, and depth, or undefined if not found
|
|
49
|
+
*/
|
|
50
|
+
function findNodeWithPath(snapshot, id) {
|
|
51
|
+
if (!snapshot) return void 0;
|
|
52
|
+
const search = (node, currentPath, depth) => {
|
|
53
|
+
const path = [...currentPath, node.id];
|
|
54
|
+
if (node.id === id) return {
|
|
55
|
+
node,
|
|
56
|
+
path,
|
|
57
|
+
depth
|
|
58
|
+
};
|
|
59
|
+
for (const child of node.children) {
|
|
60
|
+
const result = search(child, path, depth + 1);
|
|
61
|
+
if (result) return result;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
return search(snapshot, [], 0);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get the parent node of a given node ID.
|
|
68
|
+
*
|
|
69
|
+
* @param snapshot - The root tree snapshot
|
|
70
|
+
* @param nodeId - The ID of the node whose parent we want
|
|
71
|
+
* @returns ParentSearchResult with parent node and child index, or undefined
|
|
72
|
+
*/
|
|
73
|
+
function getParent(snapshot, nodeId) {
|
|
74
|
+
if (!snapshot) return void 0;
|
|
75
|
+
for (let i = 0; i < snapshot.children.length; i++) {
|
|
76
|
+
const child = snapshot.children[i];
|
|
77
|
+
if (child && child.id === nodeId) return {
|
|
78
|
+
parent: snapshot,
|
|
79
|
+
childIndex: i
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
for (const child of snapshot.children) {
|
|
83
|
+
const result = getParent(child, nodeId);
|
|
84
|
+
if (result) return result;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get a subtree rooted at a specific node ID.
|
|
89
|
+
*
|
|
90
|
+
* @param snapshot - The root tree snapshot
|
|
91
|
+
* @param nodeId - The ID of the node to use as new root
|
|
92
|
+
* @returns The subtree snapshot, or undefined if node not found
|
|
93
|
+
*/
|
|
94
|
+
function getSubtree(snapshot, nodeId) {
|
|
95
|
+
return findNodeById(snapshot, nodeId);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get all ancestor nodes from a node up to the root.
|
|
99
|
+
*
|
|
100
|
+
* @param snapshot - The root tree snapshot
|
|
101
|
+
* @param nodeId - The ID of the node
|
|
102
|
+
* @returns Array of ancestor snapshots from immediate parent to root, or empty array
|
|
103
|
+
*/
|
|
104
|
+
function getAncestors(snapshot, nodeId) {
|
|
105
|
+
if (!snapshot) return [];
|
|
106
|
+
const result = findNodeWithPath(snapshot, nodeId);
|
|
107
|
+
if (!result || result.path.length <= 1) return [];
|
|
108
|
+
const ancestorIds = result.path.slice(0, -1);
|
|
109
|
+
const ancestors = [];
|
|
110
|
+
for (let i = ancestorIds.length - 1; i >= 0; i--) {
|
|
111
|
+
const id = ancestorIds[i];
|
|
112
|
+
if (id) {
|
|
113
|
+
const ancestor = findNodeById(snapshot, id);
|
|
114
|
+
if (ancestor) ancestors.push(ancestor);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return ancestors;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get all descendant nodes of a given node (flat array).
|
|
121
|
+
*
|
|
122
|
+
* @param snapshot - The root tree snapshot
|
|
123
|
+
* @param nodeId - The ID of the node (if undefined, returns all descendants of root)
|
|
124
|
+
* @returns Flat array of all descendant node snapshots
|
|
125
|
+
*/
|
|
126
|
+
function getDescendants(snapshot, nodeId) {
|
|
127
|
+
if (!snapshot) return [];
|
|
128
|
+
const startNode = nodeId ? findNodeById(snapshot, nodeId) : snapshot;
|
|
129
|
+
if (!startNode) return [];
|
|
130
|
+
const descendants = [];
|
|
131
|
+
const collect = (node) => {
|
|
132
|
+
for (const child of node.children) {
|
|
133
|
+
descendants.push(child);
|
|
134
|
+
collect(child);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
collect(startNode);
|
|
138
|
+
return descendants;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Get siblings of a node (nodes with the same parent).
|
|
142
|
+
*
|
|
143
|
+
* @param snapshot - The root tree snapshot
|
|
144
|
+
* @param nodeId - The ID of the node
|
|
145
|
+
* @param includeSelf - Whether to include the node itself (default: false)
|
|
146
|
+
* @returns Array of sibling snapshots
|
|
147
|
+
*/
|
|
148
|
+
function getSiblings(snapshot, nodeId, includeSelf = false) {
|
|
149
|
+
if (!snapshot) return [];
|
|
150
|
+
const parentResult = getParent(snapshot, nodeId);
|
|
151
|
+
if (!parentResult) return [];
|
|
152
|
+
const siblings = parentResult.parent.children;
|
|
153
|
+
if (includeSelf) return siblings;
|
|
154
|
+
return siblings.filter((s) => s.id !== nodeId);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Find the first node matching a predicate.
|
|
158
|
+
*
|
|
159
|
+
* @param snapshot - The root tree snapshot
|
|
160
|
+
* @param predicate - Function to test each node
|
|
161
|
+
* @returns First matching node snapshot, or undefined
|
|
162
|
+
*/
|
|
163
|
+
function findNode(snapshot, predicate) {
|
|
164
|
+
if (!snapshot) return void 0;
|
|
165
|
+
if (predicate(snapshot)) return snapshot;
|
|
166
|
+
for (const child of snapshot.children) {
|
|
167
|
+
const found = findNode(child, predicate);
|
|
168
|
+
if (found) return found;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Find all nodes matching a predicate.
|
|
173
|
+
*
|
|
174
|
+
* @param snapshot - The root tree snapshot
|
|
175
|
+
* @param predicate - Function to test each node
|
|
176
|
+
* @returns Array of matching node snapshots
|
|
177
|
+
*/
|
|
178
|
+
function findNodes(snapshot, predicate) {
|
|
179
|
+
if (!snapshot) return [];
|
|
180
|
+
const results = [];
|
|
181
|
+
const search = (node) => {
|
|
182
|
+
if (predicate(node)) results.push(node);
|
|
183
|
+
for (const child of node.children) search(child);
|
|
184
|
+
};
|
|
185
|
+
search(snapshot);
|
|
186
|
+
return results;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get the depth of a specific node (0 = root).
|
|
190
|
+
*
|
|
191
|
+
* @param snapshot - The root tree snapshot
|
|
192
|
+
* @param nodeId - The ID of the node
|
|
193
|
+
* @returns The depth, or -1 if not found
|
|
194
|
+
*/
|
|
195
|
+
function getNodeDepth(snapshot, nodeId) {
|
|
196
|
+
if (!snapshot) return -1;
|
|
197
|
+
const result = findNodeWithPath(snapshot, nodeId);
|
|
198
|
+
return result ? result.depth : -1;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Check if one node is an ancestor of another.
|
|
202
|
+
*
|
|
203
|
+
* @param snapshot - The root tree snapshot
|
|
204
|
+
* @param ancestorId - Potential ancestor node ID
|
|
205
|
+
* @param descendantId - Potential descendant node ID
|
|
206
|
+
* @returns true if ancestorId is an ancestor of descendantId
|
|
207
|
+
*/
|
|
208
|
+
function isAncestorOf(snapshot, ancestorId, descendantId) {
|
|
209
|
+
if (!snapshot) return false;
|
|
210
|
+
const result = findNodeWithPath(snapshot, descendantId);
|
|
211
|
+
if (!result) return false;
|
|
212
|
+
return result.path.slice(0, -1).includes(ancestorId);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Traverse the tree and call a visitor function for each node.
|
|
216
|
+
* Return false from visitor to stop traversal.
|
|
217
|
+
*
|
|
218
|
+
* @param snapshot - The root tree snapshot
|
|
219
|
+
* @param visitor - Function called for each node (return false to stop)
|
|
220
|
+
* @param options - Traversal options (order: 'pre' | 'post')
|
|
221
|
+
*/
|
|
222
|
+
function traverse(snapshot, visitor, options = {}) {
|
|
223
|
+
if (!snapshot) return;
|
|
224
|
+
const { order = "pre" } = options;
|
|
225
|
+
const visit = (node, depth) => {
|
|
226
|
+
if (order === "pre") {
|
|
227
|
+
if (visitor(node, depth) === false) return false;
|
|
228
|
+
}
|
|
229
|
+
for (const child of node.children) if (!visit(child, depth + 1)) return false;
|
|
230
|
+
if (order === "post") {
|
|
231
|
+
if (visitor(node, depth) === false) return false;
|
|
232
|
+
}
|
|
233
|
+
return true;
|
|
234
|
+
};
|
|
235
|
+
visit(snapshot, 0);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Flatten the tree into an array with parent information.
|
|
239
|
+
*
|
|
240
|
+
* @param snapshot - The root tree snapshot
|
|
241
|
+
* @returns Array of { node, parentId, depth } objects
|
|
242
|
+
*/
|
|
243
|
+
function flattenTree(snapshot) {
|
|
244
|
+
if (!snapshot) return [];
|
|
245
|
+
const result = [];
|
|
246
|
+
const flatten = (node, parentId, depth) => {
|
|
247
|
+
result.push({
|
|
248
|
+
node,
|
|
249
|
+
parentId,
|
|
250
|
+
depth
|
|
251
|
+
});
|
|
252
|
+
for (const child of node.children) flatten(child, node.id, depth + 1);
|
|
253
|
+
};
|
|
254
|
+
flatten(snapshot, null, 0);
|
|
255
|
+
return result;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Map over all nodes in the tree, transforming each node's data.
|
|
259
|
+
* Preserves tree structure while transforming node content.
|
|
260
|
+
*
|
|
261
|
+
* @param snapshot - The root tree snapshot
|
|
262
|
+
* @param mapper - Function to transform each node
|
|
263
|
+
* @returns New tree structure with transformed nodes, or undefined
|
|
264
|
+
*/
|
|
265
|
+
function mapTree(snapshot, mapper) {
|
|
266
|
+
if (!snapshot) return void 0;
|
|
267
|
+
const map = (node, depth) => {
|
|
268
|
+
return {
|
|
269
|
+
value: mapper(node, depth),
|
|
270
|
+
children: node.children.map((child) => map(child, depth + 1))
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
return map(snapshot, 0);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Build a lookup map from node type strings to their TreeNodePrimitive definitions.
|
|
277
|
+
* Useful for resolving snapshot node types back to their schema definitions.
|
|
278
|
+
*
|
|
279
|
+
* @param tree - The TreePrimitive to analyze
|
|
280
|
+
* @returns Map from type string to TreeNodePrimitive
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```ts
|
|
284
|
+
* const typeMap = buildNodeTypeMap(fileTree);
|
|
285
|
+
* const folderPrimitive = typeMap.get("folder"); // FolderNode
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
function buildNodeTypeMap(tree) {
|
|
289
|
+
const map = /* @__PURE__ */ new Map();
|
|
290
|
+
const visited = /* @__PURE__ */ new Set();
|
|
291
|
+
const visit = (node) => {
|
|
292
|
+
if (visited.has(node.type)) return;
|
|
293
|
+
visited.add(node.type);
|
|
294
|
+
map.set(node.type, node);
|
|
295
|
+
for (const child of node.children) visit(child);
|
|
296
|
+
};
|
|
297
|
+
visit(tree.root);
|
|
298
|
+
return map;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Get the TreeNodePrimitive definition for a snapshot node.
|
|
302
|
+
* Requires the tree schema to resolve the type string to its primitive.
|
|
303
|
+
*
|
|
304
|
+
* @param tree - The TreePrimitive schema
|
|
305
|
+
* @param snapshot - The node snapshot to get the primitive for
|
|
306
|
+
* @returns The TreeNodePrimitive, or undefined if not found
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```ts
|
|
310
|
+
* const node = findNodeById(treeSnapshot, "some-id");
|
|
311
|
+
* const primitive = getNodePrimitive(fileTree, node);
|
|
312
|
+
* // primitive is FolderNode or FileNode depending on node.type
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
function getNodePrimitive(tree, snapshot) {
|
|
316
|
+
return getNodeTypeByName(tree, snapshot.type);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Get the allowed child types for a snapshot node.
|
|
320
|
+
* Combines schema lookup with the node's allowed children.
|
|
321
|
+
*
|
|
322
|
+
* @param tree - The TreePrimitive schema
|
|
323
|
+
* @param snapshot - The node snapshot to get allowed children for
|
|
324
|
+
* @returns Array of allowed child TreeNodePrimitives, or empty array if not found
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts
|
|
328
|
+
* const node = findNodeById(treeSnapshot, "folder-id");
|
|
329
|
+
* const allowedChildren = getAllowedChildTypesForNode(fileTree, node);
|
|
330
|
+
* // Returns [FolderNode, FileNode] if the folder can contain both
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
function getAllowedChildTypesForNode(tree, snapshot) {
|
|
334
|
+
const primitive = getNodePrimitive(tree, snapshot);
|
|
335
|
+
if (!primitive) return [];
|
|
336
|
+
return primitive.children;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Check if a child type is allowed for a specific snapshot node.
|
|
340
|
+
*
|
|
341
|
+
* @param tree - The TreePrimitive schema
|
|
342
|
+
* @param parentSnapshot - The parent node snapshot
|
|
343
|
+
* @param childTypeName - The type string of the potential child
|
|
344
|
+
* @returns true if the child type is allowed
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* ```ts
|
|
348
|
+
* const folder = findNodeById(treeSnapshot, "folder-id");
|
|
349
|
+
* canAddChildType(fileTree, folder, "file"); // true
|
|
350
|
+
* canAddChildType(fileTree, folder, "unknown"); // false
|
|
351
|
+
* ```
|
|
352
|
+
*/
|
|
353
|
+
function canAddChildType(tree, parentSnapshot, childTypeName) {
|
|
354
|
+
const primitive = getNodePrimitive(tree, parentSnapshot);
|
|
355
|
+
if (!primitive) return false;
|
|
356
|
+
return primitive.isChildAllowed(childTypeName);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Get all allowed child node types for a specific node type.
|
|
360
|
+
*
|
|
361
|
+
* @param nodeType - The TreeNodePrimitive to get children for
|
|
362
|
+
* @returns Array of allowed child TreeNodePrimitives
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```ts
|
|
366
|
+
* const FolderNode = TreeNode("folder", { ... });
|
|
367
|
+
* const FileNode = TreeNode("file", { ... });
|
|
368
|
+
*
|
|
369
|
+
* // Get allowed children for FolderNode
|
|
370
|
+
* const allowedChildren = getAllowedChildTypes(FolderNode);
|
|
371
|
+
* // Returns [FolderNode, FileNode] if folder can contain both
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
function getAllowedChildTypes(nodeType) {
|
|
375
|
+
return nodeType.children;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Get all unique node types reachable in a tree schema.
|
|
379
|
+
* Recursively traverses the tree structure starting from the root.
|
|
380
|
+
*
|
|
381
|
+
* @param tree - The TreePrimitive to analyze
|
|
382
|
+
* @returns Array of all unique TreeNodePrimitives in the tree schema
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* ```ts
|
|
386
|
+
* const fileTree = Tree({ root: FolderNode });
|
|
387
|
+
* const allNodeTypes = getAllNodeTypes(fileTree);
|
|
388
|
+
* // Returns [FolderNode, FileNode] - all possible node types
|
|
389
|
+
* ```
|
|
390
|
+
*/
|
|
391
|
+
function getAllNodeTypes(tree) {
|
|
392
|
+
const visited = /* @__PURE__ */ new Set();
|
|
393
|
+
const result = [];
|
|
394
|
+
const visit = (node) => {
|
|
395
|
+
if (visited.has(node.type)) return;
|
|
396
|
+
visited.add(node.type);
|
|
397
|
+
result.push(node);
|
|
398
|
+
for (const child of node.children) visit(child);
|
|
399
|
+
};
|
|
400
|
+
visit(tree.root);
|
|
401
|
+
return result;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Get the node type primitive by its type string from a tree schema.
|
|
405
|
+
*
|
|
406
|
+
* @param tree - The TreePrimitive to search
|
|
407
|
+
* @param typeName - The type string to find (e.g., "folder", "file")
|
|
408
|
+
* @returns The matching TreeNodePrimitive, or undefined if not found
|
|
409
|
+
*
|
|
410
|
+
* @example
|
|
411
|
+
* ```ts
|
|
412
|
+
* const fileTree = Tree({ root: FolderNode });
|
|
413
|
+
* const folderType = getNodeTypeByName(fileTree, "folder");
|
|
414
|
+
* // Returns FolderNode
|
|
415
|
+
* ```
|
|
416
|
+
*/
|
|
417
|
+
function getNodeTypeByName(tree, typeName) {
|
|
418
|
+
return getAllNodeTypes(tree).find((node) => node.type === typeName);
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Check if a child type is allowed under a parent type.
|
|
422
|
+
*
|
|
423
|
+
* @param parentType - The parent TreeNodePrimitive
|
|
424
|
+
* @param childTypeName - The type string of the potential child
|
|
425
|
+
* @returns true if the child type is allowed
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```ts
|
|
429
|
+
* isChildTypeAllowed(FolderNode, "file"); // true if folder can contain files
|
|
430
|
+
* isChildTypeAllowed(FileNode, "folder"); // false - files can't have children
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
function isChildTypeAllowed(parentType, childTypeName) {
|
|
434
|
+
return parentType.isChildAllowed(childTypeName);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
//#endregion
|
|
438
|
+
export { tree_helpers_exports };
|
|
439
|
+
//# sourceMappingURL=tree-helpers.mjs.map
|
|
@@ -0,0 +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,SAA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0.
|
|
3
|
+
"version": "0.0.3",
|
|
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": "0.0.3"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"effect": "^3.19.12"
|
package/src/index.ts
CHANGED
|
@@ -11,3 +11,5 @@ export * as ProxyEnvironment from "./ProxyEnvironment.js";
|
|
|
11
11
|
export * as Transform from "./Transform.js";
|
|
12
12
|
export * as Presence from "./Presence.js";
|
|
13
13
|
export * as EffectSchema from "./EffectSchema.js";
|
|
14
|
+
export * as Types from "./types/index.js";
|
|
15
|
+
export * as TreeHelpers from "./utils/tree-helpers.js";
|
package/src/primitives/shared.ts
CHANGED
|
@@ -119,7 +119,13 @@ export interface Primitive<TState, TProxy, TRequired extends boolean = false, TH
|
|
|
119
119
|
*/
|
|
120
120
|
export type IsDefined<T> = T extends Primitive<any, any, infer D, any> ? D : false;
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Infer whether a primitive is required.
|
|
124
|
+
* Alias for IsDefined for clarity.
|
|
125
|
+
*/
|
|
126
|
+
export type IsRequired<T> = IsDefined<T>;
|
|
127
|
+
|
|
128
|
+
|
|
123
129
|
// =============================================================================
|
|
124
130
|
// Validation Errors
|
|
125
131
|
// =============================================================================
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consolidated type inference utilities for all primitives.
|
|
3
|
+
*
|
|
4
|
+
* This module re-exports all inference types from a single location
|
|
5
|
+
* for convenient access across the mimic package.
|
|
6
|
+
*
|
|
7
|
+
* @since 0.0.1
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// =============================================================================
|
|
11
|
+
// Core Inference Types (from shared.ts)
|
|
12
|
+
// =============================================================================
|
|
13
|
+
|
|
14
|
+
export type {
|
|
15
|
+
// Core primitive types
|
|
16
|
+
Primitive,
|
|
17
|
+
AnyPrimitive,
|
|
18
|
+
PrimitiveInternal,
|
|
19
|
+
|
|
20
|
+
// State and proxy inference
|
|
21
|
+
InferState,
|
|
22
|
+
InferProxy,
|
|
23
|
+
|
|
24
|
+
// Input inference
|
|
25
|
+
InferSetInput,
|
|
26
|
+
InferUpdateInput,
|
|
27
|
+
|
|
28
|
+
// Snapshot inference
|
|
29
|
+
InferSnapshot,
|
|
30
|
+
|
|
31
|
+
// Required/default status inference
|
|
32
|
+
HasDefault,
|
|
33
|
+
IsDefined,
|
|
34
|
+
IsRequired,
|
|
35
|
+
|
|
36
|
+
// Utility types
|
|
37
|
+
MaybeUndefined,
|
|
38
|
+
NeedsValue,
|
|
39
|
+
Optional,
|
|
40
|
+
|
|
41
|
+
// Validator type
|
|
42
|
+
Validator,
|
|
43
|
+
} from "../primitives/shared.js";
|
|
44
|
+
|
|
45
|
+
// =============================================================================
|
|
46
|
+
// Struct Inference Types
|
|
47
|
+
// =============================================================================
|
|
48
|
+
|
|
49
|
+
export type {
|
|
50
|
+
InferStructState,
|
|
51
|
+
InferStructSnapshot,
|
|
52
|
+
StructSetInput,
|
|
53
|
+
StructUpdateValue,
|
|
54
|
+
StructProxy,
|
|
55
|
+
} from "../primitives/Struct.js";
|
|
56
|
+
|
|
57
|
+
// =============================================================================
|
|
58
|
+
// Array Inference Types
|
|
59
|
+
// =============================================================================
|
|
60
|
+
|
|
61
|
+
export type {
|
|
62
|
+
ArrayState,
|
|
63
|
+
ArraySnapshot,
|
|
64
|
+
ArrayEntrySnapshot,
|
|
65
|
+
ArrayEntry,
|
|
66
|
+
ArraySetInput,
|
|
67
|
+
ArrayUpdateInput,
|
|
68
|
+
ArrayElementSetInput,
|
|
69
|
+
ArrayProxy,
|
|
70
|
+
} from "../primitives/Array.js";
|
|
71
|
+
|
|
72
|
+
// =============================================================================
|
|
73
|
+
// Tree Inference Types
|
|
74
|
+
// =============================================================================
|
|
75
|
+
|
|
76
|
+
export type {
|
|
77
|
+
TreeState,
|
|
78
|
+
TreeNodeState,
|
|
79
|
+
TypedTreeNodeState,
|
|
80
|
+
TreeNodeSnapshot,
|
|
81
|
+
InferTreeSnapshot,
|
|
82
|
+
TreeSetInput,
|
|
83
|
+
TreeUpdateInput,
|
|
84
|
+
TreeNodeUpdateValue,
|
|
85
|
+
TreeNodeDataSetInput,
|
|
86
|
+
TreeProxy,
|
|
87
|
+
TypedNodeProxy,
|
|
88
|
+
TreeNodeProxyBase,
|
|
89
|
+
} from "../primitives/Tree.js";
|
|
90
|
+
|
|
91
|
+
// =============================================================================
|
|
92
|
+
// TreeNode Inference Types
|
|
93
|
+
// =============================================================================
|
|
94
|
+
|
|
95
|
+
export type {
|
|
96
|
+
AnyTreeNodePrimitive,
|
|
97
|
+
InferTreeNodeDataState,
|
|
98
|
+
InferTreeNodeType,
|
|
99
|
+
InferTreeNodeChildren,
|
|
100
|
+
TreeNodeSelfType,
|
|
101
|
+
TreeNodeConfig,
|
|
102
|
+
TreeNodeChildrenInput,
|
|
103
|
+
} from "../primitives/TreeNode.js";
|
|
104
|
+
|
|
105
|
+
export { TreeNodePrimitive, TreeNodeSelf } from "../primitives/TreeNode.js";
|
|
106
|
+
|
|
107
|
+
// =============================================================================
|
|
108
|
+
// Union Inference Types
|
|
109
|
+
// =============================================================================
|
|
110
|
+
|
|
111
|
+
export type {
|
|
112
|
+
InferUnionState,
|
|
113
|
+
InferUnionSnapshot,
|
|
114
|
+
UnionVariants,
|
|
115
|
+
} from "../primitives/Union.js";
|
|
116
|
+
|
|
117
|
+
// =============================================================================
|
|
118
|
+
// Either Inference Types
|
|
119
|
+
// =============================================================================
|
|
120
|
+
|
|
121
|
+
export type {
|
|
122
|
+
InferEitherState,
|
|
123
|
+
InferEitherSnapshot,
|
|
124
|
+
ScalarPrimitive,
|
|
125
|
+
} from "../primitives/Either.js";
|
|
126
|
+
|
|
127
|
+
// =============================================================================
|
|
128
|
+
// Lazy Inference Types
|
|
129
|
+
// =============================================================================
|
|
130
|
+
|
|
131
|
+
export type {
|
|
132
|
+
InferLazyState,
|
|
133
|
+
InferLazyProxy,
|
|
134
|
+
InferLazySnapshot,
|
|
135
|
+
InferLazySetInput,
|
|
136
|
+
InferLazyUpdateInput,
|
|
137
|
+
} from "../primitives/Lazy.js";
|