@powerduck/tree 0.7.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.
@@ -0,0 +1,161 @@
1
+ import { Oas32Document } from '@powerduck/openapi-parser';
2
+ import { T as TreeNode } from '../types-DVz8c2Yd.cjs';
3
+
4
+ /** Metadata attached to OpenAPI tree nodes. */
5
+ interface OpenApiNodeMetadata {
6
+ /** HTTP method for operation nodes. */
7
+ method?: string;
8
+ /** API path for operation and path nodes. */
9
+ path?: string;
10
+ /** operationId for operation nodes. */
11
+ operationId?: string;
12
+ /** Whether the operation is deprecated. */
13
+ deprecated?: boolean;
14
+ /** Short summary for display. */
15
+ summary?: string;
16
+ /** JSON pointer to the source object in the document. */
17
+ pointer?: string;
18
+ /** Source of the navigation grouping. */
19
+ source?: "tag" | "tag-group" | "oas32-parent" | "fallback" | "section";
20
+ /** Node kind for icon selection. */
21
+ kind?: OpenApiNodeKind;
22
+ /** Drag group isolation key (e.g. "apis", "components", "webhooks"). */
23
+ section?: string;
24
+ }
25
+ type OpenApiNodeKind = "root" | "section" | "tag-group" | "tag" | "path" | "operation" | "webhook" | "component" | "schema" | "uncategorized";
26
+ type OpenApiTreeNode = TreeNode<OpenApiNodeMetadata>;
27
+ /** Options for building the OpenAPI navigation tree. */
28
+ interface OpenApiTreeOptions {
29
+ /** Show nodes marked with x-internal or x-scalar-ignore. Default false. */
30
+ showInternal?: boolean;
31
+ /** Include components/schemas section. Default true. */
32
+ showComponents?: boolean;
33
+ /** Include webhooks section. Default true. */
34
+ showWebhooks?: boolean;
35
+ /** Maximum depth to expand. Default 2 (group -> tag -> operation). */
36
+ defaultExpandDepth?: number;
37
+ }
38
+ interface OpenApiTreeBuildResult {
39
+ root: OpenApiTreeNode;
40
+ warnings: string[];
41
+ }
42
+ /**
43
+ * Builds an OpenAPI navigation tree from an OpenAPI 3.x document.
44
+ *
45
+ * Navigation strategy (in priority order):
46
+ * 1. OAS 3.2 native parent-nested tags (when any tag has a `parent` field)
47
+ * 2. x-tagGroups (with powerduck nested `groups` extension)
48
+ * 3. Flat tag grouping (fallback)
49
+ *
50
+ * Supported extensions: x-order, x-displayName, x-internal, x-scalar-ignore,
51
+ * x-tagGroups (with nested groups).
52
+ */
53
+ declare function buildOpenApiTree(document: Oas32Document | Record<string, unknown> | null | undefined, options?: OpenApiTreeOptions): OpenApiTreeBuildResult;
54
+
55
+ /** Metadata attached to JSON Schema tree nodes. */
56
+ interface SchemaNodeMetadata {
57
+ /** JSON path segments from root to this node. */
58
+ jsonPath: string[];
59
+ /** Schema type (string, object, array, etc.). May be an array for multi-type. */
60
+ type?: string | string[];
61
+ /** Format hint (email, date-time, etc.). */
62
+ format?: string;
63
+ /** Whether this property is required in its parent object. */
64
+ required?: boolean;
65
+ /** Whether this schema is deprecated. */
66
+ deprecated?: boolean;
67
+ /** Short description. */
68
+ description?: string;
69
+ /** Whether this is a leaf (no children to expand). */
70
+ isLeaf?: boolean;
71
+ /** Node kind for icon selection. */
72
+ kind?: SchemaNodeKind;
73
+ /** For array nodes, whether items are defined. */
74
+ hasItems?: boolean;
75
+ }
76
+ type SchemaNodeKind = "root" | "object" | "property" | "array" | "items" | "string" | "number" | "integer" | "boolean" | "null" | "enum" | "anyOf" | "oneOf" | "allOf" | "ref" | "unknown";
77
+ type SchemaTreeNode = TreeNode<SchemaNodeMetadata>;
78
+ /** Options for building the JSON Schema tree. */
79
+ interface SchemaTreeOptions {
80
+ /** Maximum recursion depth. Default 8. Prevents infinite loops on circular schemas. */
81
+ maxDepth?: number;
82
+ /** Include deprecated properties. Default true. */
83
+ showDeprecated?: boolean;
84
+ /** Expand allOf/anyOf/oneOf branches. Default true. */
85
+ expandCombinators?: boolean;
86
+ /** Show array items as a child node. Default true. */
87
+ showArrayItems?: boolean;
88
+ }
89
+ interface SchemaTreeBuildResult {
90
+ root: SchemaTreeNode;
91
+ warnings: string[];
92
+ }
93
+ /**
94
+ * Builds a deeply expanded tree from a JSON Schema object.
95
+ *
96
+ * Each node carries a jsonPath for jumping to the corresponding line in a
97
+ * schema editor. Handles nested objects, arrays (items), allOf/anyOf/oneOf,
98
+ * $ref (with circular reference detection), and enums.
99
+ */
100
+ declare function buildSchemaTree(schema: Record<string, unknown> | null | undefined, options?: SchemaTreeOptions): SchemaTreeBuildResult;
101
+ /**
102
+ * Finds the schema tree node at the given JSON path.
103
+ * Returns undefined if not found.
104
+ */
105
+ declare function findSchemaNodeByPath(root: SchemaTreeNode, jsonPath: string[]): SchemaTreeNode | undefined;
106
+ /**
107
+ * Formats a type label for display (e.g. "string", "object", "string | null").
108
+ */
109
+ declare function formatSchemaType(metadata: SchemaNodeMetadata): string;
110
+
111
+ /** Metadata attached to documentation tree nodes. */
112
+ interface DocNodeMetadata {
113
+ /** HTTP method for operation nodes. */
114
+ method?: string;
115
+ /** API path for operation and path nodes. */
116
+ path?: string;
117
+ /** operationId for operation nodes. */
118
+ operationId?: string;
119
+ /** Whether the operation is deprecated. */
120
+ deprecated?: boolean;
121
+ /** Short summary for display. */
122
+ summary?: string;
123
+ /** Description for rich text rendering. */
124
+ description?: string;
125
+ /** JSON pointer to the source object. */
126
+ pointer?: string;
127
+ /** Parameter location (query/path/header/cookie) for parameter nodes. */
128
+ paramIn?: string;
129
+ /** Whether a parameter is required. */
130
+ required?: boolean;
131
+ /** HTTP status code for response nodes. */
132
+ statusCode?: string;
133
+ /** Content type for media type nodes. */
134
+ contentType?: string;
135
+ /** Node kind for icon selection. */
136
+ kind?: DocNodeKind;
137
+ /** Source of the navigation grouping. */
138
+ source?: "tag" | "tag-group" | "oas32-parent" | "fallback";
139
+ /** Number of operations in this node's subtree (for count badges). */
140
+ operationCount?: number;
141
+ }
142
+ type DocNodeKind = "root" | "tag-group" | "tag" | "operation" | "parameters" | "parameter" | "request-body" | "responses" | "response" | "content" | "webhook" | "component" | "schema" | "uncategorized";
143
+ type DocTreeNode = TreeNode<DocNodeMetadata>;
144
+ /** Options for building the documentation tree. */
145
+ interface DocTreeOptions {
146
+ /** Show nodes marked with x-internal or x-scalar-ignore. Default false. */
147
+ showInternal?: boolean;
148
+ /** Include components/schemas section. Default true. */
149
+ showComponents?: boolean;
150
+ /** Include webhooks section. Default true. */
151
+ showWebhooks?: boolean;
152
+ /** Expand operation details (parameters, request body, responses). Default true. */
153
+ expandOperationDetails?: boolean;
154
+ }
155
+ interface DocTreeBuildResult {
156
+ root: DocTreeNode;
157
+ warnings: string[];
158
+ }
159
+ declare function buildDocTree(document: Oas32Document | Record<string, unknown> | null | undefined, options?: DocTreeOptions): DocTreeBuildResult;
160
+
161
+ export { type DocNodeKind, type DocNodeMetadata, type DocTreeBuildResult, type DocTreeNode, type DocTreeOptions, type OpenApiNodeKind, type OpenApiNodeMetadata, type OpenApiTreeBuildResult, type OpenApiTreeNode, type OpenApiTreeOptions, type SchemaNodeKind, type SchemaNodeMetadata, type SchemaTreeBuildResult, type SchemaTreeNode, type SchemaTreeOptions, buildDocTree, buildOpenApiTree, buildSchemaTree, findSchemaNodeByPath, formatSchemaType };
@@ -0,0 +1,161 @@
1
+ import { Oas32Document } from '@powerduck/openapi-parser';
2
+ import { T as TreeNode } from '../types-DVz8c2Yd.js';
3
+
4
+ /** Metadata attached to OpenAPI tree nodes. */
5
+ interface OpenApiNodeMetadata {
6
+ /** HTTP method for operation nodes. */
7
+ method?: string;
8
+ /** API path for operation and path nodes. */
9
+ path?: string;
10
+ /** operationId for operation nodes. */
11
+ operationId?: string;
12
+ /** Whether the operation is deprecated. */
13
+ deprecated?: boolean;
14
+ /** Short summary for display. */
15
+ summary?: string;
16
+ /** JSON pointer to the source object in the document. */
17
+ pointer?: string;
18
+ /** Source of the navigation grouping. */
19
+ source?: "tag" | "tag-group" | "oas32-parent" | "fallback" | "section";
20
+ /** Node kind for icon selection. */
21
+ kind?: OpenApiNodeKind;
22
+ /** Drag group isolation key (e.g. "apis", "components", "webhooks"). */
23
+ section?: string;
24
+ }
25
+ type OpenApiNodeKind = "root" | "section" | "tag-group" | "tag" | "path" | "operation" | "webhook" | "component" | "schema" | "uncategorized";
26
+ type OpenApiTreeNode = TreeNode<OpenApiNodeMetadata>;
27
+ /** Options for building the OpenAPI navigation tree. */
28
+ interface OpenApiTreeOptions {
29
+ /** Show nodes marked with x-internal or x-scalar-ignore. Default false. */
30
+ showInternal?: boolean;
31
+ /** Include components/schemas section. Default true. */
32
+ showComponents?: boolean;
33
+ /** Include webhooks section. Default true. */
34
+ showWebhooks?: boolean;
35
+ /** Maximum depth to expand. Default 2 (group -> tag -> operation). */
36
+ defaultExpandDepth?: number;
37
+ }
38
+ interface OpenApiTreeBuildResult {
39
+ root: OpenApiTreeNode;
40
+ warnings: string[];
41
+ }
42
+ /**
43
+ * Builds an OpenAPI navigation tree from an OpenAPI 3.x document.
44
+ *
45
+ * Navigation strategy (in priority order):
46
+ * 1. OAS 3.2 native parent-nested tags (when any tag has a `parent` field)
47
+ * 2. x-tagGroups (with powerduck nested `groups` extension)
48
+ * 3. Flat tag grouping (fallback)
49
+ *
50
+ * Supported extensions: x-order, x-displayName, x-internal, x-scalar-ignore,
51
+ * x-tagGroups (with nested groups).
52
+ */
53
+ declare function buildOpenApiTree(document: Oas32Document | Record<string, unknown> | null | undefined, options?: OpenApiTreeOptions): OpenApiTreeBuildResult;
54
+
55
+ /** Metadata attached to JSON Schema tree nodes. */
56
+ interface SchemaNodeMetadata {
57
+ /** JSON path segments from root to this node. */
58
+ jsonPath: string[];
59
+ /** Schema type (string, object, array, etc.). May be an array for multi-type. */
60
+ type?: string | string[];
61
+ /** Format hint (email, date-time, etc.). */
62
+ format?: string;
63
+ /** Whether this property is required in its parent object. */
64
+ required?: boolean;
65
+ /** Whether this schema is deprecated. */
66
+ deprecated?: boolean;
67
+ /** Short description. */
68
+ description?: string;
69
+ /** Whether this is a leaf (no children to expand). */
70
+ isLeaf?: boolean;
71
+ /** Node kind for icon selection. */
72
+ kind?: SchemaNodeKind;
73
+ /** For array nodes, whether items are defined. */
74
+ hasItems?: boolean;
75
+ }
76
+ type SchemaNodeKind = "root" | "object" | "property" | "array" | "items" | "string" | "number" | "integer" | "boolean" | "null" | "enum" | "anyOf" | "oneOf" | "allOf" | "ref" | "unknown";
77
+ type SchemaTreeNode = TreeNode<SchemaNodeMetadata>;
78
+ /** Options for building the JSON Schema tree. */
79
+ interface SchemaTreeOptions {
80
+ /** Maximum recursion depth. Default 8. Prevents infinite loops on circular schemas. */
81
+ maxDepth?: number;
82
+ /** Include deprecated properties. Default true. */
83
+ showDeprecated?: boolean;
84
+ /** Expand allOf/anyOf/oneOf branches. Default true. */
85
+ expandCombinators?: boolean;
86
+ /** Show array items as a child node. Default true. */
87
+ showArrayItems?: boolean;
88
+ }
89
+ interface SchemaTreeBuildResult {
90
+ root: SchemaTreeNode;
91
+ warnings: string[];
92
+ }
93
+ /**
94
+ * Builds a deeply expanded tree from a JSON Schema object.
95
+ *
96
+ * Each node carries a jsonPath for jumping to the corresponding line in a
97
+ * schema editor. Handles nested objects, arrays (items), allOf/anyOf/oneOf,
98
+ * $ref (with circular reference detection), and enums.
99
+ */
100
+ declare function buildSchemaTree(schema: Record<string, unknown> | null | undefined, options?: SchemaTreeOptions): SchemaTreeBuildResult;
101
+ /**
102
+ * Finds the schema tree node at the given JSON path.
103
+ * Returns undefined if not found.
104
+ */
105
+ declare function findSchemaNodeByPath(root: SchemaTreeNode, jsonPath: string[]): SchemaTreeNode | undefined;
106
+ /**
107
+ * Formats a type label for display (e.g. "string", "object", "string | null").
108
+ */
109
+ declare function formatSchemaType(metadata: SchemaNodeMetadata): string;
110
+
111
+ /** Metadata attached to documentation tree nodes. */
112
+ interface DocNodeMetadata {
113
+ /** HTTP method for operation nodes. */
114
+ method?: string;
115
+ /** API path for operation and path nodes. */
116
+ path?: string;
117
+ /** operationId for operation nodes. */
118
+ operationId?: string;
119
+ /** Whether the operation is deprecated. */
120
+ deprecated?: boolean;
121
+ /** Short summary for display. */
122
+ summary?: string;
123
+ /** Description for rich text rendering. */
124
+ description?: string;
125
+ /** JSON pointer to the source object. */
126
+ pointer?: string;
127
+ /** Parameter location (query/path/header/cookie) for parameter nodes. */
128
+ paramIn?: string;
129
+ /** Whether a parameter is required. */
130
+ required?: boolean;
131
+ /** HTTP status code for response nodes. */
132
+ statusCode?: string;
133
+ /** Content type for media type nodes. */
134
+ contentType?: string;
135
+ /** Node kind for icon selection. */
136
+ kind?: DocNodeKind;
137
+ /** Source of the navigation grouping. */
138
+ source?: "tag" | "tag-group" | "oas32-parent" | "fallback";
139
+ /** Number of operations in this node's subtree (for count badges). */
140
+ operationCount?: number;
141
+ }
142
+ type DocNodeKind = "root" | "tag-group" | "tag" | "operation" | "parameters" | "parameter" | "request-body" | "responses" | "response" | "content" | "webhook" | "component" | "schema" | "uncategorized";
143
+ type DocTreeNode = TreeNode<DocNodeMetadata>;
144
+ /** Options for building the documentation tree. */
145
+ interface DocTreeOptions {
146
+ /** Show nodes marked with x-internal or x-scalar-ignore. Default false. */
147
+ showInternal?: boolean;
148
+ /** Include components/schemas section. Default true. */
149
+ showComponents?: boolean;
150
+ /** Include webhooks section. Default true. */
151
+ showWebhooks?: boolean;
152
+ /** Expand operation details (parameters, request body, responses). Default true. */
153
+ expandOperationDetails?: boolean;
154
+ }
155
+ interface DocTreeBuildResult {
156
+ root: DocTreeNode;
157
+ warnings: string[];
158
+ }
159
+ declare function buildDocTree(document: Oas32Document | Record<string, unknown> | null | undefined, options?: DocTreeOptions): DocTreeBuildResult;
160
+
161
+ export { type DocNodeKind, type DocNodeMetadata, type DocTreeBuildResult, type DocTreeNode, type DocTreeOptions, type OpenApiNodeKind, type OpenApiNodeMetadata, type OpenApiTreeBuildResult, type OpenApiTreeNode, type OpenApiTreeOptions, type SchemaNodeKind, type SchemaNodeMetadata, type SchemaTreeBuildResult, type SchemaTreeNode, type SchemaTreeOptions, buildDocTree, buildOpenApiTree, buildSchemaTree, findSchemaNodeByPath, formatSchemaType };
@@ -0,0 +1 @@
1
+ import{buildDocTree as o,buildOpenApiTree as r,buildSchemaTree as m,findSchemaNodeByPath as p,formatSchemaType as t}from"../chunk-YSSQNJPQ.js";import"../chunk-5KF7QUTD.js";export{o as buildDocTree,r as buildOpenApiTree,m as buildSchemaTree,p as findSchemaNodeByPath,t as formatSchemaType};
@@ -0,0 +1 @@
1
+ function n(n){return null!=n}function e(n,r){for(const t of n){if(t.id===r)return t;if(t.children?.length){const n=e(t.children,r);if(n)return n}}}function r(n,e,t=[]){for(const i of n){const n=[...t,i];if(i.id===e)return{nodes:n,target:i,parent:t[t.length-1],ancestorIds:t.map(n=>n.id)};if(i.children?.length){const t=r(i.children,e,n);if(t)return t}}return null}function t(n){const e=[],r=n=>{if(n.children?.length)for(const e of n.children)r(e);else e.push(n)};for(const e of n)r(e);return e}function i(n){let e=0;const r=n=>{e+=1;for(const e of n.children??[])r(e)};for(const e of n)r(e);return e}function o(n){let e=0;const r=(n,t)=>{e=Math.max(e,t);for(const e of n.children??[])r(e,t+1)};for(const e of n)r(e,1);return e}function c(n){return[...n].sort((n,e)=>{const r=n.order??Number.MAX_SAFE_INTEGER,t=e.order??Number.MAX_SAFE_INTEGER;if(r!==t)return r-t;return n.name.localeCompare(e.name,"en-US",{numeric:!0,sensitivity:"base"})||n.id.localeCompare(e.id)})}function l(n){return c(n).map(n=>n.children?.length?{...n,children:l(n.children)}:n)}function d(e,r){const t=r.query.trim().toLowerCase();if(!t)return e;const i=r.keepAncestors??!0,o=e=>{const r=(e.children??[]).map(o).filter(n),c=(n=>n.name.toLowerCase().includes(t)||n.id.toLowerCase().includes(t))(e);return(c||r.length)&&(i||c)?r.length===(e.children?.length??0)?e:{...e,children:r}:null};return e.map(o).filter(n)}function f(n,e={}){const r=e.maxDepth??1/0,t=e.onlyWithChildren??!0,i=[],o=(n,e)=>{if(e>r)return;const c=(n.children?.length??0)>0;t&&!c||i.push(n.id);for(const r of n.children??[])o(r,e+1)};for(const e of n)o(e,1);return i}function u(n){const e=[],r=n=>{const t=n.children;if(t&&0!==t.length){e.push(n.id);for(const n of t)r(n)}};for(const e of n)r(e);return e}function h(n){const e=[],r=(n,t)=>{e.push({node:n,depth:t});for(const e of n.children??[])r(e,t+1)};for(const e of n)r(e,1);return e}function s(n,e,r){let t=!1;const i=n.map(n=>{if(n.id===e)return t=!0,r(n);if(n.children?.length){const i=s(n.children,e,r);if(i!==n.children)return t=!0,{...n,children:i}}return n});return t?i:n}function a(n,e){const r=[];let t=!1;for(const i of n)if(i.id!==e){if(i.children?.length){const n=a(i.children,e);if(n!==i.children){t=!0,r.push({...i,children:n});continue}}r.push(i)}else t=!0;return t?r:n}function p(n,e,r){let t=!1;const i=n.map(n=>{if(n.id===e)return t=!0,{...n,children:[...n.children??[],r]};if(n.children?.length){const i=p(n.children,e,r);if(i!==n.children)return t=!0,{...n,children:i}}return n});return t?i:n}function m(n,e,r){const t=(n,r)=>{const i=n.findIndex(n=>n.id===e);if(-1!==i)return{array:n,index:i,parentId:r};for(const e of n)if(e.children?.length){const n=t(e.children,e.id);if(n)return n}return null},i=t(n,null);if(!i)return null;const{array:o,index:c,parentId:l}=i,d=Math.max(0,Math.min(r,o.length-1));if(d===c)return{nodes:n,moved:o[c],parentId:l,fromIndex:c,toIndex:c};const f=[...o],[u]=f.splice(c,1);f.splice(d,0,u);const h=n=>null===l?f:n.map(n=>n.id===l?{...n,children:f}:n.children?.length?{...n,children:h(n.children)}:n);return{nodes:h(n),moved:u,parentId:l,fromIndex:c,toIndex:d}}function g(n,e,t,i){let o=null;if(null!==t){const i=r(n,e);if(i&&i.ancestorIds.includes(t))return null}const c=n=>{const r=[];let t=!1;for(const i of n)if(i.id!==e){if(i.children?.length){const n=c(i.children);if(n!==i.children){t=!0,r.push({...i,children:n});continue}}r.push(i)}else o=i,t=!0;return t?r:n},l=c(n);if(!o)return null;if(null===t){const n=i??l.length,e=[...l];return e.splice(Math.max(0,Math.min(n,e.length)),0,o),e}let d=!1;const f=n=>n.map(n=>{if(n.id===t){d=!0;const e=[...n.children??[]],r=i??e.length;return e.splice(Math.max(0,Math.min(r,e.length)),0,o),{...n,children:e}}return n.children?.length?{...n,children:f(n.children)}:n}),u=f(l);return d?u:null}export{n as isTreeNode,e as findNode,r as findPath,t as getLeaves,i as countNodes,o as getMaxDepth,c as sortNodes,l as sortTree,d as filterTree,f as getExpandableIds,u as getBranchIds,h as flattenTree,s as updateNode,a as removeNode,p as insertChild,m as reorderNode,g as moveNode};
File without changes
@@ -0,0 +1 @@
1
+ import{sortNodes as e}from"./chunk-5KF7QUTD.js";var t=["get","put","post","delete","options","head","patch","trace"],n={showInternal:!1,showComponents:!0,showWebhooks:!0,defaultExpandDepth:2};function o(e){return"object"!=typeof e||null===e||Array.isArray(e)?null:e}function r(e){return"string"==typeof e&&e.trim().length>0?e.trim():void 0}function a(e){return"boolean"==typeof e?e:void 0}function s(e){return Array.isArray(e)?e:void 0}function i(e,t){return!t&&(!0===a(e["x-scalar-ignore"])||!0===a(e["x-internal"]))}function c(e){return"number"==typeof(t=e["x-order"])&&Number.isFinite(t)?t:void 0;var t}function d(e){return r(e["x-displayName"])}function p(t,n,o,r){const a=new Map;for(const e of t)a.set(e.name,e);const s=new Map;for(const e of t){if(!e.parent){s.set(e.name,null);continue}if(!a.has(e.parent)){r.push(`Tag "${e.name}" references unknown parent "${e.parent}", treating as root.`),s.set(e.name,null);continue}const t=[e.name];let n=e.parent,o=!1;for(;n;){if(t.includes(n)){o=!0,r.push(`Circular tag reference detected: ${t.join(" -> ")} -> ${n}. Breaking cycle.`);break}t.push(n),n=a.get(n)?.parent}s.set(e.name,o?null:e.parent)}const d=new Map;for(const e of n){if(i(e.raw,o.showInternal))continue;const t=e.tags.length>0?e.tags:["Other"];for(const n of t){const t=d.get(n)??[];t.push(e),d.set(n,t)}}const p=new Map;for(const e of t){const t=s.get(e.name)??null??"__root__",n=p.get(t)??[];n.push(e),p.set(t,n)}const u=t=>{const n=p.get(t)??[];return e(n.map(t=>{const n=(t=>{const n=(d.get(t.name)??[]).map(e=>({id:`op:${t.name}:${e.id}`,name:e.name,order:c(e.raw),metadata:{method:e.method,path:e.path,operationId:e.operationId,deprecated:e.deprecated,summary:e.summary,pointer:e.pointer,source:"oas32-parent",kind:"operation"}}));return{id:`tag:${t.name}`,name:t.displayName,order:t.order,children:e(n),metadata:{source:"oas32-parent",kind:"tag"}}})(t),o=u(t.name);return o.length>0&&(n.children=e([...n.children??[],...o])),n}))},m=u("__root__"),f=d.get("Other")??[];if(f.length>0){const t=f.map(e=>({id:`op:Other:${e.id}`,name:e.name,order:c(e.raw),metadata:{method:e.method,path:e.path,operationId:e.operationId,deprecated:e.deprecated,summary:e.summary,pointer:e.pointer,source:"fallback",kind:"operation"}}));m.push({id:"tag:Other",name:"Other",order:Number.MAX_SAFE_INTEGER,children:e(t),metadata:{source:"fallback",kind:"tag"}})}return e(m)}function u(u,m={}){const f={...n,...m},h=[],l=o(u);if(!l)return{root:{id:"root",name:"OpenAPI",children:[],metadata:{kind:"root"}},warnings:["Document is null or not an object."]};const g=function(e){const n=o(e.paths);if(!n)return[];const i=[];for(const[e,c]of Object.entries(n)){const n=o(c);if(n)for(const c of t){const t=n[c];if(null==t)continue;const d=o(t);if(!d)continue;const p=r(d.operationId),u=r(d.summary),m=s(d.tags)?.filter(e=>"string"==typeof e).map(e=>e.trim()).filter(e=>e.length>0)??[],f=u??p??`${c.toUpperCase()} ${e}`,h=p??`${c}:${e}`,l=`/paths/${encodeURIComponent(e)}/${c}`;i.push({id:h,path:e,method:c,name:f,summary:u,operationId:p,deprecated:!0===a(d.deprecated),tags:m,pointer:l,raw:d})}}return i}(l),y=function(e){const t=s(e.tags);if(!t)return[];const n=[];for(const e of t){const t=o(e),a=r(t?.name);a&&t&&n.push({name:a,displayName:d(t)??a,description:r(t.description),parent:r(t.parent),order:c(t),raw:t})}return n}(l);let $;if(function(e){return e.some(e=>void 0!==e.parent)}(y))$=p(y,g,f,h);else{const t=function(e){const t=s(e["x-tagGroups"]);if(!t)return[];const n=(e,t)=>{const a=o(e),i=r(a?.name),d=s(a?.tags)?.filter(e=>"string"==typeof e).map(e=>e.trim()).filter(e=>e.length>0)??[];if(!i)return null;const p=s(a?.groups)?.map((e,t)=>n(e,t)).filter(e=>null!==e)??[];return{name:i,tags:d,groups:p.length>0?p:void 0,order:c(a??{})??t}};return t.map((e,t)=>n(e,t)).filter(e=>null!==e)}(l);$=t.length>0?function(t,n,o,r){const a=new Map;for(const e of n)a.set(e.name,e.displayName);const s=new Map;for(const e of o)if(!i(e.raw,r.showInternal))for(const t of e.tags){const n=s.get(t)??[];n.push(e),s.set(t,n)}const d=e=>(s.get(e)??[]).map(t=>({id:`op:${e}:${t.id}`,name:t.name,order:c(t.raw),metadata:{method:t.method,path:t.path,operationId:t.operationId,deprecated:t.deprecated,summary:t.summary,pointer:t.pointer,source:"tag-group",kind:"operation"}})),p=t=>({id:`tag:${t}`,name:a.get(t)??t,children:e(d(t)),metadata:{source:"tag-group",kind:"tag"}}),u=t=>{const n=[];for(const e of t.tags){const t=s.get(e);t?.length&&n.push(p(e))}for(const e of t.groups??[])n.push(u(e));return{id:`tag-group:${t.name}`,name:t.name,order:t.order,children:e(n),metadata:{source:"tag-group",kind:"tag-group"}}};return e(t.map(u))}(t,y,g,f):function(t,n,o){const r=new Map,a=new Map;for(let e=0;e<t.length;e+=1){const n=t[e];a.set(n.name,n.order??e)}for(const e of n){if(i(e.raw,o.showInternal))continue;const t=e.tags.length>0?e.tags:["Other"];for(const n of t){const t=r.get(n)??[];t.push(e),r.set(n,t)}}const s=new Map;for(const e of t)s.set(e.name,e.displayName);const d=[];for(const[t,n]of r){const o=n.map(e=>({id:`op:${t}:${e.id}`,name:e.name,order:c(e.raw),metadata:{method:e.method,path:e.path,operationId:e.operationId,deprecated:e.deprecated,summary:e.summary,pointer:e.pointer,source:"tag",kind:"operation"}}));d.push({id:`tag:${t}`,name:s.get(t)??t,order:"Other"===t?Number.MAX_SAFE_INTEGER:a.get(t),children:e(o),metadata:{source:"tag",kind:"tag"}})}return e(d)}(y,g,f)}const k=function(n,s){if(!s.showWebhooks)return;const d=o(n.webhooks);if(!d)return;const p=[];for(const[e,n]of Object.entries(d)){const d=o(n);if(d)for(const n of t){const t=o(d[n]);if(!t||i(t,s.showInternal))continue;const u=r(t.operationId),m=r(t.summary),f=m??u??`${n.toUpperCase()} ${e}`;p.push({id:`webhook:${e}:${n}`,name:f,order:c(t),metadata:{method:n,path:e,operationId:u,deprecated:!0===a(t.deprecated),summary:m,pointer:`/webhooks/${encodeURIComponent(e)}/${n}`,source:"tag",kind:"webhook"}})}}return 0!==p.length?{id:"section:webhooks",name:"Webhooks",order:Number.MAX_SAFE_INTEGER-2,children:e(p),metadata:{source:"section",kind:"section",section:"webhooks"}}:void 0}(l,f),w=function(t,n){if(!n.showComponents)return;const r=o(t.components),a=o(r?.schemas);if(!a)return;const s=[];for(const[e,t]of Object.entries(a)){const r=o(t);r&&!i(r,n.showInternal)&&s.push({id:`schema:${e}`,name:e,order:c(r),metadata:{pointer:`/components/schemas/${encodeURIComponent(e)}`,source:"tag",kind:"schema"}})}return 0!==s.length?{id:"section:components",name:"Components",order:Number.MAX_SAFE_INTEGER-1,children:e(s),metadata:{source:"section",kind:"section",section:"components"}}:void 0}(l,f),b=[{id:"section:apis",name:"APIs",children:$,metadata:{kind:"section",source:"section",section:"apis"},order:0},...k?[k]:[],...w?[w]:[]];return{root:{id:"root",name:"OpenAPI",children:e(b),metadata:{kind:"root"}},warnings:h}}var m={openapi:0,info:1,servers:2,paths:3,webhooks:4,components:5,security:6,tags:7,externalDocs:8,jsonSchemaDialect:9},f={maxDepth:8,showDeprecated:!0,expandCombinators:!0,showArrayItems:!0},h=new Set(["string","number","integer","boolean","null"]);function l(e){return"object"!=typeof e||null===e||Array.isArray(e)?null:e}function g(e){return"string"==typeof e&&e.trim().length>0?e.trim():void 0}function y(e){return"boolean"==typeof e?e:void 0}function $(e){return Array.isArray(e)?e:void 0}function k(e){return e?Array.isArray(e)?e.join(" | "):e:"any"}function w(t,n,o,r,a,s){const i=function(e){const t=e.type;return"string"==typeof t||Array.isArray(t)&&t.every(e=>"string"==typeof e)?t:void 0}(n),c=g(n.format),d=g(n.description),p=!0===y(n.deprecated),u=function(e){if(!e)return"unknown";switch(Array.isArray(e)?e[0]:e){case"object":return"object";case"array":return"array";case"string":return"string";case"number":return"number";case"integer":return"integer";case"boolean":return"boolean";case"null":return"null";default:return"unknown"}}(i),f={jsonPath:o,type:i,format:c,required:s,deprecated:p,description:d,kind:u},k=g(n.$ref);if(k){if(a.refStack.has(k))return a.warnings.push(`Circular $ref detected at ${o.join(".")}: ${k}. Breaking recursion.`),{id:o.join(".")||"root",name:t,metadata:{...f,kind:"ref",isLeaf:!0}};a.refStack.add(k)}let b,I=function(e){return!!e&&(Array.isArray(e)?e.every(e=>h.has(e)):h.has(e))}(i);if(r>=a.options.maxDepth)return k&&a.refStack.delete(k),{id:o.join(".")||"root",name:t,metadata:{...f,isLeaf:!0}};const A=l(n.properties);if(A){const t=$(n.required)??[],s=new Set(t.filter(e=>"string"==typeof e)),i=[];for(const[e,t]of Object.entries(A)){const n=l(t);n&&((a.options.showDeprecated||!0!==y(n.deprecated))&&i.push(w(e,n,[...o,"properties",e],r+1,a,s.has(e))))}b=[...b??[],...e(i)],I=!1}if(a.options.showArrayItems&&"array"===i){const e=l(n.items);if(e){b=[...b??[],w("items",e,[...o,"items"],r+1,a,!1)],I=!1}else f.hasItems=!1}if(a.options.expandCombinators){const t=[{key:"allOf",kind:"allOf"},{key:"anyOf",kind:"anyOf"},{key:"oneOf",kind:"oneOf"}];for(const{key:s,kind:i}of t){const t=$(n[s]);if(!t?.length)continue;const c=t.map((e,t)=>{const n=l(e);return n?w(`[${t}]`,n,[...o,s,String(t)],r+1,a,!1):{id:`${o.join(".")}.${s}[${t}]`,name:`[${t}]`,metadata:{jsonPath:[...o,s,String(t)],kind:"unknown",isLeaf:!0}}});b=[...b??[],{id:`${o.join(".")}.${s}`,name:s,children:e(c),metadata:{jsonPath:[...o,s],kind:i}}],I=!1}}const O=$(n.enum);return O?.length&&!b?.length&&(f.kind="enum",I=!0),k&&a.refStack.delete(k),{id:o.join(".")||"root",name:t,order:m[t],metadata:{...f,isLeaf:I},children:b}}function b(e,t={}){const n={...f,...t},o=[],r=l(e);if(!r)return{root:{id:"root",name:"Schema",metadata:{jsonPath:[],kind:"root",isLeaf:!0}},warnings:["Schema is null or not an object."]};return{root:w("root",r,[],0,{options:n,warnings:o,refStack:new Set},!0),warnings:o}}function I(e,t){if(0===t.length)return e;const n=t.join("."),o=[e];for(;o.length>0;){const e=o.shift();if(!e)continue;const t=e.metadata?.jsonPath?.join(".");if(t===n)return e;for(const t of e.children??[])o.push(t)}}function A(e){return"enum"===e.kind?"enum":"ref"===e.kind?"$ref":e.format?`${k(e.type)} (${e.format})`:k(e.type)}var O=["get","put","post","delete","options","head","patch","trace"],j={showInternal:!1,showComponents:!1,showWebhooks:!0,expandOperationDetails:!0};function _(e){return"object"!=typeof e||null===e||Array.isArray(e)?null:e}function C(e){return"string"==typeof e&&e.trim().length>0?e.trim():void 0}function v(e){return"boolean"==typeof e?e:void 0}function N(e){return Array.isArray(e)?e:void 0}function M(e,t){return!t&&(!0===v(e["x-scalar-ignore"])||!0===v(e["x-internal"]))}function E(e){const t=e["x-order"];return"number"==typeof t&&Number.isFinite(t)?t:void 0}function R(e){return C(e["x-displayName"])}function x(t,n){const o=[],r=N(t.parameters);if(r?.length){const t=function(t,n){const o=[];for(const e of t){const t=_(e);if(!t)continue;const r=C(t.name),a=C(t.in);if(!r||!a)continue;const s=`${a}:${r}`;o.push({id:`${n}/parameters/${encodeURIComponent(s)}`,name:r,metadata:{paramIn:a,required:!0===v(t.required),description:C(t.description),pointer:`${n}/parameters`,kind:"parameter"}})}return e(o)}(r,n);t.length>0&&o.push({id:`${n}/parameters`,name:"Parameters",children:t,metadata:{pointer:`${n}/parameters`,kind:"parameters"}})}const a=_(t.requestBody);if(a){const e=_(a.content),t=[];if(e)for(const[o]of Object.entries(e))t.push({id:`${n}/requestBody/content/${encodeURIComponent(o)}`,name:o,metadata:{contentType:o,pointer:`${n}/requestBody/content/${encodeURIComponent(o)}`,kind:"content"}});o.push({id:`${n}/requestBody`,name:"Request Body",metadata:{description:C(a.description),required:!0===v(a.required),pointer:`${n}/requestBody`,kind:"request-body"},children:t.length>0?t:void 0})}const s=_(t.responses);if(s){const t=function(t,n){const o=[];for(const[e,r]of Object.entries(t)){const t=_(r);if(!t)continue;const a=C(t.description),s=_(t.content),i=[];if(s)for(const[t]of Object.entries(s))i.push({id:`${n}/responses/${encodeURIComponent(e)}/content/${encodeURIComponent(t)}`,name:t,metadata:{contentType:t,pointer:`${n}/responses/${encodeURIComponent(e)}/content/${encodeURIComponent(t)}`,kind:"content"}});o.push({id:`${n}/responses/${encodeURIComponent(e)}`,name:e,metadata:{statusCode:e,description:a,pointer:`${n}/responses/${encodeURIComponent(e)}`,kind:"response"},children:i.length>0?i:void 0})}return e(o)}(s,n);t.length>0&&o.push({id:`${n}/responses`,name:"Responses",children:t,metadata:{pointer:`${n}/responses`,kind:"responses"}})}return o}function S(e,t,n,o){const r=t.expandOperationDetails?x(e.raw,e.pointer):void 0;return{id:`op:${o}:${e.id}`,name:e.name,order:E(e.raw),metadata:{method:e.method,path:e.path,operationId:e.operationId,deprecated:e.deprecated,summary:e.summary,description:e.description,pointer:e.pointer,source:n,kind:"operation"},children:r&&r.length>0?r:void 0}}function U(t,n,o,r){const a=new Map;for(const e of t)a.set(e.name,e);const s=new Map;for(const e of t){if(!e.parent){s.set(e.name,null);continue}if(!a.has(e.parent)){r.push(`Tag "${e.name}" references unknown parent "${e.parent}", treating as root.`),s.set(e.name,null);continue}const t=[e.name];let n=e.parent,o=!1;for(;n;){if(t.includes(n)){o=!0,r.push(`Circular tag reference detected: ${t.join(" -> ")} -> ${n}. Breaking cycle.`);break}t.push(n),n=a.get(n)?.parent}s.set(e.name,o?null:e.parent)}const i=new Map;for(const e of n){if(M(e.raw,o.showInternal))continue;const t=e.tags.length>0?e.tags:["Other"];for(const n of t){const t=i.get(n)??[];t.push(e),i.set(n,t)}}const c=new Map;for(const e of t){const t=s.get(e.name)??null??"__root__",n=c.get(t)??[];n.push(e),c.set(t,n)}const d=t=>{const n=c.get(t)??[];return e(n.map(t=>{const n=(t=>{const n=(i.get(t.name)??[]).map(e=>S(e,o,"oas32-parent",t.name));return{id:`tag:${t.name}`,name:t.displayName,order:t.order,children:e(n),metadata:{description:t.description,source:"oas32-parent",kind:"tag"}}})(t),r=d(t.name);return r.length>0&&(n.children=e([...n.children??[],...r])),n}))},p=d("__root__"),u=i.get("Other")??[];if(u.length>0){const t=u.map(e=>S(e,o,"fallback","Other"));p.push({id:"tag:Other",name:"Other",order:Number.MAX_SAFE_INTEGER,children:e(t),metadata:{source:"fallback",kind:"tag"}})}return e(p)}function D(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){const e=_(n);if(!e||"string"!=typeof e.name)continue;const o={name:e.name};Array.isArray(e.tags)&&(o.tags=e.tags.filter(e=>"string"==typeof e)),Array.isArray(e.groups)&&(o.groups=D(e.groups)),t.push(o)}return t}function q(t,n,o,r,a,s=0){const i=[];if(t.tags)for(const s of t.tags){const t=n.get(s);if(!t||0===t.length)continue;const c=t.map(e=>S(e,a,"tag-group",s));i.push({id:`tag:${s}`,name:o.get(s)??s,order:r.get(s),children:e(c),metadata:{source:"tag-group",kind:"tag"}})}if(t.groups)for(const e of t.groups)i.push(q(e,n,o,r,a,s+1));return{id:`tag-group:${t.name}`,name:t.name,order:1e3*s,children:e(i),metadata:{source:"tag-group",kind:"tag-group"}}}function T(t,n,o,r){const a=new Map,s=new Map,i=new Map;for(let e=0;e<n.length;e+=1)s.set(n[e].name,e),i.set(n[e].name,n[e].displayName);for(const e of o){if(M(e.raw,r.showInternal))continue;const t=e.tags.length>0?e.tags:["Other"];for(const n of t){const t=a.get(n)??[];t.push(e),a.set(n,t)}}const c=D(t["x-tagGroups"]).map(e=>q(e,a,i,s,r)),d=a.get("Other");if(d&&d.length>0){const t=d.map(e=>S(e,r,"fallback","Other"));c.push({id:"tag:Other",name:"Other",order:Number.MAX_SAFE_INTEGER,children:e(t),metadata:{source:"fallback",kind:"tag"}})}return e(c)}function G(e){return e.map(e=>{const t=e.children?G(e.children):void 0,n="operation"===e.metadata?.kind?1:0,o=t?.reduce((e,t)=>e+(t.metadata?.operationCount??0),0)??0;return{...e,children:t,metadata:{...e.metadata,operationCount:n+o}}})}function F(t,n={}){const o={...j,...n},r=[],a=_(t);if(!a)return{root:{id:"root",name:"API Documentation",children:[],metadata:{kind:"root"}},warnings:["Document is null or not an object."]};const s=function(e){const t=_(e.paths);if(!t)return[];const n=[];for(const[e,o]of Object.entries(t)){const t=_(o);if(t)for(const o of O){const r=_(t[o]);if(!r)continue;const a=C(r.operationId),s=C(r.summary),i=C(r.description),c=N(r.tags)?.filter(e=>"string"==typeof e).map(e=>e.trim()).filter(e=>e.length>0)??[],d=s??a??`${o.toUpperCase()} ${e}`,p=a??`${o}:${e}`,u=`/paths/${encodeURIComponent(e)}/${o}`;n.push({id:p,path:e,method:o,name:d,summary:s,description:i,operationId:a,deprecated:!0===v(r.deprecated),tags:c,pointer:u,raw:r})}}return n}(a),i=function(e){const t=N(e.tags);if(!t)return[];const n=[];for(const e of t){const t=_(e),o=C(t?.name);o&&t&&n.push({name:o,displayName:R(t)??o,description:C(t.description),parent:C(t.parent),order:E(t)})}return n}(a);let c;c=function(e){return e.some(e=>void 0!==e.parent)}(i)?U(i,s,o,r):function(e){return Array.isArray(e["x-tagGroups"])&&e["x-tagGroups"].length>0}(a)?T(a,i,s,o):function(t,n,o){const r=new Map,a=new Map;for(let e=0;e<t.length;e+=1)a.set(t[e].name,e);for(const e of n){if(M(e.raw,o.showInternal))continue;const t=e.tags.length>0?e.tags:["Other"];for(const n of t){const t=r.get(n)??[];t.push(e),r.set(n,t)}}const s=new Map;for(const e of t)s.set(e.name,e.displayName);const i=[];for(const[t,n]of r){const r=n.map(e=>S(e,o,"tag",t));i.push({id:`tag:${t}`,name:s.get(t)??t,order:"Other"===t?Number.MAX_SAFE_INTEGER:a.get(t),children:e(r),metadata:{source:"tag",kind:"tag"}})}return e(i)}(i,s,o);const d=function(t,n){if(!n.showComponents)return;const o=_(t.components),r=_(o?.schemas);if(!r)return;const a=[];for(const[e,t]of Object.entries(r)){const o=_(t);o&&!M(o,n.showInternal)&&a.push({id:`schema:${e}`,name:e,order:E(o),metadata:{description:C(o.description),pointer:`/components/schemas/${encodeURIComponent(e)}`,source:"tag",kind:"schema"}})}return 0!==a.length?{id:"section:components",name:"Components",order:Number.MAX_SAFE_INTEGER-1,children:e(a),metadata:{source:"tag",kind:"component"}}:void 0}(a,o),p=G([...c,...d?[d]:[]]);return{root:{id:"root",name:"API Documentation",children:e(p),metadata:{kind:"root"}},warnings:r}}export{u as buildOpenApiTree,b as buildSchemaTree,I as findSchemaNodeByPath,A as formatSchemaType,F as buildDocTree};
@@ -0,0 +1 @@
1
+ "use strict";var n,e=Object.defineProperty,r=Object.getOwnPropertyDescriptor,t=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,i={};function c(n){return null!=n}function l(n,e){for(const r of n){if(r.id===e)return r;if(r.children?.length){const n=l(r.children,e);if(n)return n}}}function d(n,e,r=[]){for(const t of n){const n=[...r,t];if(t.id===e)return{nodes:n,target:t,parent:r[r.length-1],ancestorIds:r.map(n=>n.id)};if(t.children?.length){const r=d(t.children,e,n);if(r)return r}}return null}function f(n){const e=[],r=n=>{if(n.children?.length)for(const e of n.children)r(e);else e.push(n)};for(const e of n)r(e);return e}function s(n){let e=0;const r=n=>{e+=1;for(const e of n.children??[])r(e)};for(const e of n)r(e);return e}function u(n){let e=0;const r=(n,t)=>{e=Math.max(e,t);for(const e of n.children??[])r(e,t+1)};for(const e of n)r(e,1);return e}function h(n){return[...n].sort((n,e)=>{const r=n.order??Number.MAX_SAFE_INTEGER,t=e.order??Number.MAX_SAFE_INTEGER;if(r!==t)return r-t;return n.name.localeCompare(e.name,"en-US",{numeric:!0,sensitivity:"base"})||n.id.localeCompare(e.id)})}function a(n){return h(n).map(n=>n.children?.length?{...n,children:a(n.children)}:n)}function p(n,e){const r=e.query.trim().toLowerCase();if(!r)return n;const t=e.keepAncestors??!0,o=n=>{const e=(n.children??[]).map(o).filter(c),i=(n=>n.name.toLowerCase().includes(r)||n.id.toLowerCase().includes(r))(n);return(i||e.length)&&(t||i)?e.length===(n.children?.length??0)?n:{...n,children:e}:null};return n.map(o).filter(c)}function m(n,e={}){const r=e.maxDepth??1/0,t=e.onlyWithChildren??!0,o=[],i=(n,e)=>{if(e>r)return;const c=(n.children?.length??0)>0;t&&!c||o.push(n.id);for(const r of n.children??[])i(r,e+1)};for(const e of n)i(e,1);return o}function g(n){const e=[],r=n=>{const t=n.children;if(t&&0!==t.length){e.push(n.id);for(const n of t)r(n)}};for(const e of n)r(e);return e}function x(n){const e=[],r=(n,t)=>{e.push({node:n,depth:t});for(const e of n.children??[])r(e,t+1)};for(const e of n)r(e,1);return e}function I(n,e,r){let t=!1;const o=n.map(n=>{if(n.id===e)return t=!0,r(n);if(n.children?.length){const o=I(n.children,e,r);if(o!==n.children)return t=!0,{...n,children:o}}return n});return t?o:n}function N(n,e){const r=[];let t=!1;for(const o of n)if(o.id!==e){if(o.children?.length){const n=N(o.children,e);if(n!==o.children){t=!0,r.push({...o,children:n});continue}}r.push(o)}else t=!0;return t?r:n}function b(n,e,r){let t=!1;const o=n.map(n=>{if(n.id===e)return t=!0,{...n,children:[...n.children??[],r]};if(n.children?.length){const o=b(n.children,e,r);if(o!==n.children)return t=!0,{...n,children:o}}return n});return t?o:n}function y(n,e,r){const t=(n,r)=>{const o=n.findIndex(n=>n.id===e);if(-1!==o)return{array:n,index:o,parentId:r};for(const e of n)if(e.children?.length){const n=t(e.children,e.id);if(n)return n}return null},o=t(n,null);if(!o)return null;const{array:i,index:c,parentId:l}=o,d=Math.max(0,Math.min(r,i.length-1));if(d===c)return{nodes:n,moved:i[c],parentId:l,fromIndex:c,toIndex:c};const f=[...i],[s]=f.splice(c,1);f.splice(d,0,s);const u=n=>null===l?f:n.map(n=>n.id===l?{...n,children:f}:n.children?.length?{...n,children:u(n.children)}:n);return{nodes:u(n),moved:s,parentId:l,fromIndex:c,toIndex:d}}function M(n,e,r,t){let o=null;if(null!==r){const t=d(n,e);if(t&&t.ancestorIds.includes(r))return null}const i=n=>{const r=[];let t=!1;for(const c of n)if(c.id!==e){if(c.children?.length){const n=i(c.children);if(n!==c.children){t=!0,r.push({...c,children:n});continue}}r.push(c)}else o=c,t=!0;return t?r:n},c=i(n);if(!o)return null;if(null===r){const n=t??c.length,e=[...c];return e.splice(Math.max(0,Math.min(n,e.length)),0,o),e}let l=!1;const f=n=>n.map(n=>{if(n.id===r){l=!0;const e=[...n.children??[]],r=t??e.length;return e.splice(Math.max(0,Math.min(r,e.length)),0,o),{...n,children:e}}return n.children?.length?{...n,children:f(n.children)}:n}),s=f(c);return l?s:null}((n,r)=>{for(var t in r)e(n,t,{get:r[t],enumerable:!0})})(i,{countNodes:()=>s,filterTree:()=>p,findNode:()=>l,findPath:()=>d,flattenTree:()=>x,getBranchIds:()=>g,getExpandableIds:()=>m,getLeaves:()=>f,getMaxDepth:()=>u,insertChild:()=>b,isTreeNode:()=>c,moveNode:()=>M,removeNode:()=>N,reorderNode:()=>y,sortNodes:()=>h,sortTree:()=>a,updateNode:()=>I}),module.exports=(n=i,((n,i,c,l)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let d of t(i))o.call(n,d)||d===c||e(n,d,{get:()=>i[d],enumerable:!(l=r(i,d))||l.enumerable});return n})(e({},"__esModule",{value:!0}),n));
@@ -0,0 +1,107 @@
1
+ import { T as TreeNode, F as FilterTreeOptions, a as TreePath, E as ExpandOptions } from '../types-DVz8c2Yd.cjs';
2
+
3
+ declare function isTreeNode<TMetadata>(value: TreeNode<TMetadata> | null | undefined): value is TreeNode<TMetadata>;
4
+ /**
5
+ * Finds a node by id in a tree. Returns undefined if not found.
6
+ */
7
+ declare function findNode<TMetadata>(nodes: TreeNode<TMetadata>[], id: string): TreeNode<TMetadata> | undefined;
8
+ /**
9
+ * Finds the full path from root to the node with the given id.
10
+ * Returns null if the node is not found.
11
+ */
12
+ declare function findPath<TMetadata>(nodes: TreeNode<TMetadata>[], id: string, ancestors?: TreeNode<TMetadata>[]): TreePath<TMetadata> | null;
13
+ /**
14
+ * Returns all leaf nodes (nodes with no children).
15
+ */
16
+ declare function getLeaves<TMetadata>(nodes: TreeNode<TMetadata>[]): TreeNode<TMetadata>[];
17
+ /**
18
+ * Returns the total number of nodes in the tree.
19
+ */
20
+ declare function countNodes<TMetadata>(nodes: TreeNode<TMetadata>[]): number;
21
+ /**
22
+ * Returns the maximum depth of the tree. Root-level nodes are depth 1.
23
+ */
24
+ declare function getMaxDepth<TMetadata>(nodes: TreeNode<TMetadata>[]): number;
25
+ /**
26
+ * Sorts nodes by order (ascending), then by name (locale-aware, numeric).
27
+ * Nodes without an order value sort after those with one.
28
+ *
29
+ * Returns a new array; does not mutate the input.
30
+ */
31
+ declare function sortNodes<TMetadata>(nodes: TreeNode<TMetadata>[]): TreeNode<TMetadata>[];
32
+ /**
33
+ * Recursively sorts all nodes in the tree by order, then name.
34
+ * Returns a new tree; does not mutate the input.
35
+ */
36
+ declare function sortTree<TMetadata>(nodes: TreeNode<TMetadata>[]): TreeNode<TMetadata>[];
37
+ /**
38
+ * Filters a tree by query. Matching nodes and (optionally) their ancestors
39
+ * are retained. Returns a new tree; does not mutate the input.
40
+ *
41
+ * When no query is provided, the original nodes are returned unchanged.
42
+ */
43
+ declare function filterTree<TMetadata>(nodes: TreeNode<TMetadata>[], options: FilterTreeOptions): TreeNode<TMetadata>[];
44
+ /**
45
+ * Returns the IDs of all nodes that should be expanded based on options.
46
+ *
47
+ * @param nodes - The root nodes.
48
+ * @param options - maxDepth (default Infinity), onlyWithChildren (default true).
49
+ */
50
+ declare function getExpandableIds<TMetadata>(nodes: TreeNode<TMetadata>[], options?: ExpandOptions): string[];
51
+ /**
52
+ * Returns the IDs of all branch nodes (nodes with at least one child).
53
+ */
54
+ declare function getBranchIds<TMetadata>(nodes: TreeNode<TMetadata>[]): string[];
55
+ /**
56
+ * Flattens a tree into a list of nodes with their depth.
57
+ * Parent nodes appear before their children (pre-order traversal).
58
+ */
59
+ declare function flattenTree<TMetadata>(nodes: TreeNode<TMetadata>[]): Array<{
60
+ node: TreeNode<TMetadata>;
61
+ depth: number;
62
+ }>;
63
+ /**
64
+ * Returns a new tree with the node at the given id replaced.
65
+ * If the id is not found, the original tree is returned unchanged.
66
+ */
67
+ declare function updateNode<TMetadata>(nodes: TreeNode<TMetadata>[], id: string, updater: (node: TreeNode<TMetadata>) => TreeNode<TMetadata>): TreeNode<TMetadata>[];
68
+ /**
69
+ * Returns a new tree with the node at the given id removed.
70
+ * If the id is not found, the original tree is returned unchanged.
71
+ */
72
+ declare function removeNode<TMetadata>(nodes: TreeNode<TMetadata>[], id: string): TreeNode<TMetadata>[];
73
+ /**
74
+ * Returns a new tree with a child inserted at the given parent id.
75
+ * If the parent id is not found, the original tree is returned unchanged.
76
+ */
77
+ declare function insertChild<TMetadata>(nodes: TreeNode<TMetadata>[], parentId: string, child: TreeNode<TMetadata>): TreeNode<TMetadata>[];
78
+ /**
79
+ * Result of a reorder operation.
80
+ */
81
+ interface ReorderResult<TMetadata> {
82
+ /** The reordered tree. */
83
+ nodes: TreeNode<TMetadata>[];
84
+ /** The moved node. */
85
+ moved: TreeNode<TMetadata>;
86
+ /** ID of the parent containing the moved node, or null for root. */
87
+ parentId: string | null;
88
+ /** Original index within the parent's children. */
89
+ fromIndex: number;
90
+ /** New index within the parent's children. */
91
+ toIndex: number;
92
+ }
93
+ /**
94
+ * Moves a node to a new position within the same parent.
95
+ *
96
+ * Returns the reordered tree and metadata about the move. If the node id
97
+ * is not found, returns null.
98
+ */
99
+ declare function reorderNode<TMetadata>(nodes: TreeNode<TMetadata>[], nodeId: string, toIndex: number): ReorderResult<TMetadata> | null;
100
+ /**
101
+ * Moves a node to a different parent.
102
+ *
103
+ * Returns the new tree, or null if either the source or target is not found.
104
+ */
105
+ declare function moveNode<TMetadata>(nodes: TreeNode<TMetadata>[], nodeId: string, targetParentId: string | null, targetIndex?: number): TreeNode<TMetadata>[] | null;
106
+
107
+ export { ExpandOptions, FilterTreeOptions, type ReorderResult, TreeNode, TreePath, countNodes, filterTree, findNode, findPath, flattenTree, getBranchIds, getExpandableIds, getLeaves, getMaxDepth, insertChild, isTreeNode, moveNode, removeNode, reorderNode, sortNodes, sortTree, updateNode };
@@ -0,0 +1,107 @@
1
+ import { T as TreeNode, F as FilterTreeOptions, a as TreePath, E as ExpandOptions } from '../types-DVz8c2Yd.js';
2
+
3
+ declare function isTreeNode<TMetadata>(value: TreeNode<TMetadata> | null | undefined): value is TreeNode<TMetadata>;
4
+ /**
5
+ * Finds a node by id in a tree. Returns undefined if not found.
6
+ */
7
+ declare function findNode<TMetadata>(nodes: TreeNode<TMetadata>[], id: string): TreeNode<TMetadata> | undefined;
8
+ /**
9
+ * Finds the full path from root to the node with the given id.
10
+ * Returns null if the node is not found.
11
+ */
12
+ declare function findPath<TMetadata>(nodes: TreeNode<TMetadata>[], id: string, ancestors?: TreeNode<TMetadata>[]): TreePath<TMetadata> | null;
13
+ /**
14
+ * Returns all leaf nodes (nodes with no children).
15
+ */
16
+ declare function getLeaves<TMetadata>(nodes: TreeNode<TMetadata>[]): TreeNode<TMetadata>[];
17
+ /**
18
+ * Returns the total number of nodes in the tree.
19
+ */
20
+ declare function countNodes<TMetadata>(nodes: TreeNode<TMetadata>[]): number;
21
+ /**
22
+ * Returns the maximum depth of the tree. Root-level nodes are depth 1.
23
+ */
24
+ declare function getMaxDepth<TMetadata>(nodes: TreeNode<TMetadata>[]): number;
25
+ /**
26
+ * Sorts nodes by order (ascending), then by name (locale-aware, numeric).
27
+ * Nodes without an order value sort after those with one.
28
+ *
29
+ * Returns a new array; does not mutate the input.
30
+ */
31
+ declare function sortNodes<TMetadata>(nodes: TreeNode<TMetadata>[]): TreeNode<TMetadata>[];
32
+ /**
33
+ * Recursively sorts all nodes in the tree by order, then name.
34
+ * Returns a new tree; does not mutate the input.
35
+ */
36
+ declare function sortTree<TMetadata>(nodes: TreeNode<TMetadata>[]): TreeNode<TMetadata>[];
37
+ /**
38
+ * Filters a tree by query. Matching nodes and (optionally) their ancestors
39
+ * are retained. Returns a new tree; does not mutate the input.
40
+ *
41
+ * When no query is provided, the original nodes are returned unchanged.
42
+ */
43
+ declare function filterTree<TMetadata>(nodes: TreeNode<TMetadata>[], options: FilterTreeOptions): TreeNode<TMetadata>[];
44
+ /**
45
+ * Returns the IDs of all nodes that should be expanded based on options.
46
+ *
47
+ * @param nodes - The root nodes.
48
+ * @param options - maxDepth (default Infinity), onlyWithChildren (default true).
49
+ */
50
+ declare function getExpandableIds<TMetadata>(nodes: TreeNode<TMetadata>[], options?: ExpandOptions): string[];
51
+ /**
52
+ * Returns the IDs of all branch nodes (nodes with at least one child).
53
+ */
54
+ declare function getBranchIds<TMetadata>(nodes: TreeNode<TMetadata>[]): string[];
55
+ /**
56
+ * Flattens a tree into a list of nodes with their depth.
57
+ * Parent nodes appear before their children (pre-order traversal).
58
+ */
59
+ declare function flattenTree<TMetadata>(nodes: TreeNode<TMetadata>[]): Array<{
60
+ node: TreeNode<TMetadata>;
61
+ depth: number;
62
+ }>;
63
+ /**
64
+ * Returns a new tree with the node at the given id replaced.
65
+ * If the id is not found, the original tree is returned unchanged.
66
+ */
67
+ declare function updateNode<TMetadata>(nodes: TreeNode<TMetadata>[], id: string, updater: (node: TreeNode<TMetadata>) => TreeNode<TMetadata>): TreeNode<TMetadata>[];
68
+ /**
69
+ * Returns a new tree with the node at the given id removed.
70
+ * If the id is not found, the original tree is returned unchanged.
71
+ */
72
+ declare function removeNode<TMetadata>(nodes: TreeNode<TMetadata>[], id: string): TreeNode<TMetadata>[];
73
+ /**
74
+ * Returns a new tree with a child inserted at the given parent id.
75
+ * If the parent id is not found, the original tree is returned unchanged.
76
+ */
77
+ declare function insertChild<TMetadata>(nodes: TreeNode<TMetadata>[], parentId: string, child: TreeNode<TMetadata>): TreeNode<TMetadata>[];
78
+ /**
79
+ * Result of a reorder operation.
80
+ */
81
+ interface ReorderResult<TMetadata> {
82
+ /** The reordered tree. */
83
+ nodes: TreeNode<TMetadata>[];
84
+ /** The moved node. */
85
+ moved: TreeNode<TMetadata>;
86
+ /** ID of the parent containing the moved node, or null for root. */
87
+ parentId: string | null;
88
+ /** Original index within the parent's children. */
89
+ fromIndex: number;
90
+ /** New index within the parent's children. */
91
+ toIndex: number;
92
+ }
93
+ /**
94
+ * Moves a node to a new position within the same parent.
95
+ *
96
+ * Returns the reordered tree and metadata about the move. If the node id
97
+ * is not found, returns null.
98
+ */
99
+ declare function reorderNode<TMetadata>(nodes: TreeNode<TMetadata>[], nodeId: string, toIndex: number): ReorderResult<TMetadata> | null;
100
+ /**
101
+ * Moves a node to a different parent.
102
+ *
103
+ * Returns the new tree, or null if either the source or target is not found.
104
+ */
105
+ declare function moveNode<TMetadata>(nodes: TreeNode<TMetadata>[], nodeId: string, targetParentId: string | null, targetIndex?: number): TreeNode<TMetadata>[] | null;
106
+
107
+ export { ExpandOptions, FilterTreeOptions, type ReorderResult, TreeNode, TreePath, countNodes, filterTree, findNode, findPath, flattenTree, getBranchIds, getExpandableIds, getLeaves, getMaxDepth, insertChild, isTreeNode, moveNode, removeNode, reorderNode, sortNodes, sortTree, updateNode };
@@ -0,0 +1 @@
1
+ import"../chunk-NHPRTISE.js";import{countNodes as o,filterTree as r,findNode as m,findPath as p,flattenTree as t,getBranchIds as c,getExpandableIds as h,getLeaves as i,getMaxDepth as j,insertChild as k,isTreeNode as n,moveNode as s,removeNode as u,reorderNode as T,sortNodes as e,sortTree as f,updateNode as x}from"../chunk-5KF7QUTD.js";export{o as countNodes,r as filterTree,m as findNode,p as findPath,t as flattenTree,c as getBranchIds,h as getExpandableIds,i as getLeaves,j as getMaxDepth,k as insertChild,n as isTreeNode,s as moveNode,u as removeNode,T as reorderNode,e as sortNodes,f as sortTree,x as updateNode};