@kubb/ast 5.28.6 → 5.29.0
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/README.md +19 -10
- package/dist/factory.cjs +6 -6
- package/dist/factory.d.cts +2 -2
- package/dist/factory.d.ts +2 -2
- package/dist/factory.js +2 -2
- package/dist/{combineFileMembers-B-mdjXrG.js → file-AcKQt60j.js} +137 -123
- package/dist/file-AcKQt60j.js.map +1 -0
- package/dist/{file-DJqd2j3y.d.cts → file-CLh8vdcR.d.cts} +20 -29
- package/dist/{file-lssk85C8.cjs → file-DVw2Htda.cjs} +13 -13
- package/dist/{file-lssk85C8.cjs.map → file-DVw2Htda.cjs.map} +1 -1
- package/dist/{combineFileMembers-DZCKxAN0.cjs → file-Db_PYobC.cjs} +136 -122
- package/dist/file-Db_PYobC.cjs.map +1 -0
- package/dist/{file-Dg70hXm3.d.ts → file-VRwu7Set.d.ts} +20 -29
- package/dist/{file-CO9KnOvT.js → file-pjdyWLJ0.js} +2 -2
- package/dist/{file-CO9KnOvT.js.map → file-pjdyWLJ0.js.map} +1 -1
- package/dist/file.cjs +6 -6
- package/dist/file.d.cts +1 -1
- package/dist/file.d.ts +1 -1
- package/dist/file.js +2 -2
- package/dist/{graph-DWlCmvm6.js → graph-Cu2-NiKi.js} +78 -15
- package/dist/graph-Cu2-NiKi.js.map +1 -0
- package/dist/{graph-D6Ffy9YD.cjs → graph-CymJtC1M.cjs} +78 -15
- package/dist/graph-CymJtC1M.cjs.map +1 -0
- package/dist/graph.cjs +1 -1
- package/dist/graph.d.cts +1 -1
- package/dist/graph.d.ts +1 -1
- package/dist/graph.js +1 -1
- package/dist/{index-BGhhO3z8.d.ts → index-B4DY8ewx.d.ts} +2 -2
- package/dist/{index-DjwCRndP.d.ts → index-BEvWuiSq.d.ts} +1 -1
- package/dist/{index-DphKh9u9.d.ts → index-BXHrCLGe.d.ts} +1 -1
- package/dist/{index-C4ZZnf_X.d.cts → index-BgmSdJKJ.d.cts} +2 -2
- package/dist/{index-CKd3ogUZ.d.cts → index-C0YF5kEb.d.cts} +2 -2
- package/dist/{index-Ck6nqnxZ.d.cts → index-CGvAotBX.d.cts} +2 -2
- package/dist/{index-DVX6E3vZ.d.ts → index-CHilsNw-.d.ts} +2 -2
- package/dist/{index-C0_Y9yA1.d.ts → index-CsySa8TT.d.ts} +2 -2
- package/dist/{index-BM3jzSca.d.ts → index-DA-Ztg07.d.ts} +1 -1
- package/dist/{index-CiVsdeOh.d.cts → index-DPGecgel.d.cts} +1 -1
- package/dist/{index-DdD4PIY8.d.cts → index-Dbtc7izw.d.cts} +1 -1
- package/dist/{index-DSW89P6k.d.cts → index-QDfAzfWY.d.cts} +1 -1
- package/dist/{index-B8ZxUpy4.d.ts → index-QZa0vqFW.d.ts} +1 -1
- package/dist/{index-7A3j-6Np.d.cts → index-oY3-BSwC.d.cts} +1 -1
- package/dist/index.cjs +8 -8
- package/dist/index.d.cts +9 -9
- package/dist/index.d.ts +9 -9
- package/dist/index.js +8 -8
- package/dist/isRecord-CwlfDtHp.cjs +16 -0
- package/dist/isRecord-CwlfDtHp.cjs.map +1 -0
- package/dist/isRecord-DaSp13D_.js +11 -0
- package/dist/isRecord-DaSp13D_.js.map +1 -0
- package/dist/{json-DeqPhPUQ.js → json-IKokiUCp.js} +34 -19
- package/dist/json-IKokiUCp.js.map +1 -0
- package/dist/{json-KV2VhBue.cjs → json-mEYdjumm.cjs} +34 -19
- package/dist/json-mEYdjumm.cjs.map +1 -0
- package/dist/json.cjs +1 -1
- package/dist/json.d.cts +1 -1
- package/dist/json.d.ts +1 -1
- package/dist/json.js +1 -1
- package/dist/{macro-3uGSg-ic.js → macro-DhgoqDs6.js} +2 -2
- package/dist/{macro-3uGSg-ic.js.map → macro-DhgoqDs6.js.map} +1 -1
- package/dist/{macro-Ywn4-0s5.cjs → macro-h3bm9G48.cjs} +2 -2
- package/dist/{macro-Ywn4-0s5.cjs.map → macro-h3bm9G48.cjs.map} +1 -1
- package/dist/macro.cjs +1 -1
- package/dist/macro.d.cts +1 -1
- package/dist/macro.d.ts +1 -1
- package/dist/macro.js +1 -1
- package/dist/{node-BeccjrHH.cjs → node-Dhh4jTDv.cjs} +2 -2
- package/dist/{node-BeccjrHH.cjs.map → node-Dhh4jTDv.cjs.map} +1 -1
- package/dist/{node-Dm56432_.js → node-Dy0mq_hi.js} +2 -2
- package/dist/{node-Dm56432_.js.map → node-Dy0mq_hi.js.map} +1 -1
- package/dist/node.cjs +2 -2
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +2 -2
- package/dist/{nodes-KgbYiyJQ.js → nodes-B-MW8yk-.js} +2 -2
- package/dist/{nodes-KgbYiyJQ.js.map → nodes-B-MW8yk-.js.map} +1 -1
- package/dist/{nodes-BGxHocS_.cjs → nodes-BjVv21pb.cjs} +12 -12
- package/dist/{nodes-BGxHocS_.cjs.map → nodes-BjVv21pb.cjs.map} +1 -1
- package/dist/promise-DMQPWp6M.cjs.map +1 -1
- package/dist/promise-bi4pc8Xr.js.map +1 -1
- package/dist/{schema-XGRiAvok.cjs → schema-CMe0Dvgd.cjs} +2 -2
- package/dist/{schema-XGRiAvok.cjs.map → schema-CMe0Dvgd.cjs.map} +1 -1
- package/dist/{schema-B05JSQRq.js → schema-CVIk19Mh.js} +2 -2
- package/dist/{schema-B05JSQRq.js.map → schema-CVIk19Mh.js.map} +1 -1
- package/dist/schema.cjs +2 -2
- package/dist/schema.d.cts +2 -2
- package/dist/schema.d.ts +2 -2
- package/dist/schema.js +2 -2
- package/dist/{visitor-xxcbpM5-.d.ts → visitor-BWHpwRgc.d.ts} +2 -2
- package/dist/{visitor-BIldddZd.d.cts → visitor-CPlsMCPZ.d.cts} +2 -2
- package/dist/{visitor-DA5yfOJz.js → visitor-CitcdWu0.js} +5 -10
- package/dist/visitor-CitcdWu0.js.map +1 -0
- package/dist/{visitor-DhuKS-7x.cjs → visitor-DT712cxr.cjs} +5 -10
- package/dist/visitor-DT712cxr.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/combineFileMembers-B-mdjXrG.js.map +0 -1
- package/dist/combineFileMembers-DZCKxAN0.cjs.map +0 -1
- package/dist/graph-D6Ffy9YD.cjs.map +0 -1
- package/dist/graph-DWlCmvm6.js.map +0 -1
- package/dist/json-DeqPhPUQ.js.map +0 -1
- package/dist/json-KV2VhBue.cjs.map +0 -1
- package/dist/visitor-DA5yfOJz.js.map +0 -1
- package/dist/visitor-DhuKS-7x.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -42,17 +42,26 @@ Defines the node tree, visitor pattern, factory functions, and type guards used
|
|
|
42
42
|
InputNode
|
|
43
43
|
├── schemas: SchemaNode[]
|
|
44
44
|
└── operations: OperationNode[]
|
|
45
|
-
├── parameters: ParameterNode[]
|
|
46
|
-
├── requestBody?:
|
|
47
|
-
└── responses: ResponseNode[]
|
|
45
|
+
├── parameters: ParameterNode[] → schema: SchemaNode
|
|
46
|
+
├── requestBody?: RequestBodyNode → content?: ContentNode[]
|
|
47
|
+
└── responses: ResponseNode[]
|
|
48
|
+
├── content?: ContentNode[]
|
|
49
|
+
└── headers?: ParameterNode[]
|
|
50
|
+
|
|
51
|
+
ContentNode
|
|
52
|
+
schema?: SchemaNode
|
|
53
|
+
stream?: { schema?: SchemaNode }
|
|
48
54
|
|
|
49
55
|
SchemaNode (discriminated union)
|
|
50
|
-
object → properties: PropertyNode[] → SchemaNode
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
object → properties: PropertyNode[] → schema: SchemaNode
|
|
57
|
+
additionalProperties?: SchemaNode | boolean
|
|
58
|
+
patternProperties?: Record<string, SchemaNode>
|
|
59
|
+
propertyNames?: SchemaNode
|
|
60
|
+
array | tuple → items: SchemaNode[], rest?: SchemaNode
|
|
61
|
+
union | intersection | not → members: SchemaNode[]
|
|
53
62
|
enum | ref | string | number | integer | bigint
|
|
54
|
-
boolean | null | any | unknown | void
|
|
55
|
-
date | datetime | time | uuid | email | url | blob
|
|
63
|
+
boolean | null | any | unknown | void | never
|
|
64
|
+
date | datetime | time | uuid | email | url | ipv4 | ipv6 | blob
|
|
56
65
|
```
|
|
57
66
|
|
|
58
67
|
## Usage
|
|
@@ -132,9 +141,9 @@ ast.ref.getName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }
|
|
|
132
141
|
|
|
133
142
|
## Adding a node
|
|
134
143
|
|
|
135
|
-
Adding a node touches
|
|
144
|
+
Adding a node touches four files, and a fifth when the node has children or a visitor callback.
|
|
136
145
|
|
|
137
|
-
1. Define the node type and its `createFoo` function in its own `src/nodes/*.ts` file
|
|
146
|
+
1. Define the node type and its `createFoo` function in its own `src/nodes/*.ts` file. Add the kind to `nodeKinds` in `src/constants.ts`.
|
|
138
147
|
2. Add the type to the `Node` union and re-export `createFoo` in `src/nodes/index.ts`, and export the type from `src/types.ts`.
|
|
139
148
|
3. When the node has children or a visitor callback, add it to `VISITOR_KEYS` and `VISITOR_KEY_BY_KIND` in `src/visitor.ts`.
|
|
140
149
|
|
package/dist/factory.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_schema = require("./schema-0YJZqRXb.cjs");
|
|
3
|
-
const
|
|
4
|
-
const require_nodes = require("./nodes-
|
|
3
|
+
const require_file = require("./file-Db_PYobC.cjs");
|
|
4
|
+
const require_nodes = require("./nodes-BjVv21pb.cjs");
|
|
5
5
|
exports.createArrowFunction = require_nodes.createArrowFunction;
|
|
6
6
|
exports.createBreak = require_nodes.createBreak;
|
|
7
7
|
exports.createConst = require_nodes.createConst;
|
|
8
8
|
exports.createContent = require_nodes.createContent;
|
|
9
|
-
exports.createExport =
|
|
10
|
-
exports.createFile =
|
|
9
|
+
exports.createExport = require_file.createExport;
|
|
10
|
+
exports.createFile = require_file.createFile;
|
|
11
11
|
exports.createFunction = require_nodes.createFunction;
|
|
12
|
-
exports.createImport =
|
|
12
|
+
exports.createImport = require_file.createImport;
|
|
13
13
|
exports.createInput = require_nodes.createInput;
|
|
14
14
|
exports.createJsx = require_nodes.createJsx;
|
|
15
15
|
exports.createOperation = require_nodes.createOperation;
|
|
@@ -19,6 +19,6 @@ exports.createProperty = require_nodes.createProperty;
|
|
|
19
19
|
exports.createRequestBody = require_nodes.createRequestBody;
|
|
20
20
|
exports.createResponse = require_nodes.createResponse;
|
|
21
21
|
exports.createSchema = require_schema.createSchema;
|
|
22
|
-
exports.createSource =
|
|
22
|
+
exports.createSource = require_file.createSource;
|
|
23
23
|
exports.createText = require_nodes.createText;
|
|
24
24
|
exports.createType = require_nodes.createType;
|
package/dist/factory.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as createArrowFunction, D as createJsx, E as createFunction, O as createText, T as createConst, c as Space, d as
|
|
1
|
+
import { C as createArrowFunction, D as createJsx, E as createFunction, O as createText, T as createConst, c as Space, d as createSource, f as createExport, i as ImportInput, k as createType, l as UserFileNode, o as ModuleName, p as createImport, t as ExportInput, u as createFile, w as createBreak } from "./file-CLh8vdcR.cjs";
|
|
2
2
|
import { $ as createSchema, _ as createParameter, d as createResponse, j as createInput, o as createOperation, p as createRequestBody, s as createOperations, tt as createProperty, x as createContent } from "./operation-B86IER5K.cjs";
|
|
3
|
-
import { t as Node } from "./index-
|
|
3
|
+
import { t as Node } from "./index-Dbtc7izw.cjs";
|
|
4
4
|
export { type ExportInput, type ImportInput, type ModuleName, Node, type Space, type UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createImport, createInput, createJsx, createOperation, createOperations, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType };
|
package/dist/factory.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as createArrowFunction, D as createJsx, E as createFunction, O as createText, T as createConst, c as Space, d as
|
|
1
|
+
import { C as createArrowFunction, D as createJsx, E as createFunction, O as createText, T as createConst, c as Space, d as createSource, f as createExport, i as ImportInput, k as createType, l as UserFileNode, o as ModuleName, p as createImport, t as ExportInput, u as createFile, w as createBreak } from "./file-VRwu7Set.js";
|
|
2
2
|
import { $ as createSchema, _ as createParameter, d as createResponse, j as createInput, o as createOperation, p as createRequestBody, s as createOperations, tt as createProperty, x as createContent } from "./operation-DJ7F0cFp.js";
|
|
3
|
-
import { t as Node } from "./index-
|
|
3
|
+
import { t as Node } from "./index-BEvWuiSq.js";
|
|
4
4
|
export { type ExportInput, type ImportInput, type ModuleName, Node, type Space, type UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createImport, createInput, createJsx, createOperation, createOperations, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType };
|
package/dist/factory.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { t as createSchema } from "./schema-CC008xgK.js";
|
|
2
|
-
import { a as
|
|
3
|
-
import { a as createOperation, c as createInput, d as createBreak, f as createConst, g as createType, h as createText, i as createParameter, l as createContent, m as createJsx, n as createResponse, o as createOperations, p as createFunction, r as createProperty, s as createRequestBody, u as createArrowFunction } from "./nodes-
|
|
2
|
+
import { a as createExport, n as createSource, o as createImport, t as createFile } from "./file-AcKQt60j.js";
|
|
3
|
+
import { a as createOperation, c as createInput, d as createBreak, f as createConst, g as createType, h as createText, i as createParameter, l as createContent, m as createJsx, n as createResponse, o as createOperations, p as createFunction, r as createProperty, s as createRequestBody, u as createArrowFunction } from "./nodes-B-MW8yk-.js";
|
|
4
4
|
export { createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createImport, createInput, createJsx, createOperation, createOperations, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "./rolldown-runtime-BYyVTPww.js";
|
|
2
|
+
import { hash } from "node:crypto";
|
|
2
3
|
import path from "node:path";
|
|
4
|
+
import { t as nodeKinds } from "./constants-UorsTFsa.js";
|
|
3
5
|
import process from "node:process";
|
|
4
6
|
import { t as memo } from "./promise-bi4pc8Xr.js";
|
|
5
|
-
import { hash } from "node:crypto";
|
|
6
|
-
import { t as nodeKinds } from "./constants-UorsTFsa.js";
|
|
7
7
|
import { n as getNodeText } from "./nodeText-DFak5VpX.js";
|
|
8
8
|
// src/utils/moduleNames.ts
|
|
9
9
|
/**
|
|
@@ -106,17 +106,7 @@ function toDeprecatedExport(names) {
|
|
|
106
106
|
asAlias: false
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
|
-
// src/nodes/
|
|
110
|
-
/** Builds a `createX` factory for a node whose only computed field is `kind`. */
|
|
111
|
-
function nodeFactory(kind) {
|
|
112
|
-
return (input) => {
|
|
113
|
-
return {
|
|
114
|
-
...input,
|
|
115
|
-
kind
|
|
116
|
-
};
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
// src/nodes/file.ts
|
|
109
|
+
// src/nodes/importExport.ts
|
|
120
110
|
function overrideSpace(names, { value, derived }) {
|
|
121
111
|
if (value == null || value === derived) return names;
|
|
122
112
|
const space = value ? "type" : "value";
|
|
@@ -127,7 +117,6 @@ function overrideSpace(names, { value, derived }) {
|
|
|
127
117
|
}
|
|
128
118
|
const isOverride = ({ value, derived }) => value !== void 0 && JSON.stringify(value) !== JSON.stringify(derived);
|
|
129
119
|
const DERIVED = Symbol.for("kubb.ast.derived");
|
|
130
|
-
/** The deprecated fields the caller set: a value equal to the one the spread node derived is dropped, so `names` decides it. */
|
|
131
120
|
function ownFields(input) {
|
|
132
121
|
const snapshot = input[DERIVED];
|
|
133
122
|
if (!snapshot) return {
|
|
@@ -144,15 +133,13 @@ function withoutDerived(input) {
|
|
|
144
133
|
return rest;
|
|
145
134
|
}
|
|
146
135
|
/**
|
|
147
|
-
* Creates an `ImportNode
|
|
148
|
-
*
|
|
149
|
-
* Fields a spread copies over unchanged are not overrides, so `{ ...imp, names }` uses the new `names`.
|
|
136
|
+
* Creates an `ImportNode` and fills the deprecated `name` and `isTypeOnly` from `names`. A deprecated field
|
|
137
|
+
* that differs from the one `names` gives overrides it.
|
|
150
138
|
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
* ```
|
|
139
|
+
* A spread keeps the record of the derived fields only when the original node has one, which a node made
|
|
140
|
+
* from `names` does. For a node made without `names`, or a JSON or `structuredClone` copy, leave out `name`
|
|
141
|
+
* and `isTypeOnly` before you pass new `names`, or the old `name` replaces the new `names` and the old
|
|
142
|
+
* `isTypeOnly` sets their space.
|
|
156
143
|
*/
|
|
157
144
|
function createImport(input) {
|
|
158
145
|
if (!input.names) return {
|
|
@@ -188,15 +175,8 @@ function createImport(input) {
|
|
|
188
175
|
};
|
|
189
176
|
}
|
|
190
177
|
/**
|
|
191
|
-
* Creates an `ExportNode
|
|
192
|
-
* `
|
|
193
|
-
* overrides, so `{ ...exp, names }` uses the new `names`.
|
|
194
|
-
*
|
|
195
|
-
* @example Named export
|
|
196
|
-
* ```ts
|
|
197
|
-
* createExport({ names: [{ name: 'Pet' }], path: './Pet' })
|
|
198
|
-
* // export { Pet } from './Pet'
|
|
199
|
-
* ```
|
|
178
|
+
* Creates an `ExportNode`, with the deprecated fields of {@link createImport}. For a node made without
|
|
179
|
+
* `names`, or a JSON or `structuredClone` copy, leave out `name` and `isTypeOnly` before you pass new `names`.
|
|
200
180
|
*/
|
|
201
181
|
function createExport(input) {
|
|
202
182
|
if (!input.names) return {
|
|
@@ -231,92 +211,6 @@ function createExport(input) {
|
|
|
231
211
|
kind: nodeKinds.export
|
|
232
212
|
};
|
|
233
213
|
}
|
|
234
|
-
/**
|
|
235
|
-
* Creates a `SourceNode` representing a fragment of source code within a file.
|
|
236
|
-
*
|
|
237
|
-
* @example
|
|
238
|
-
* ```ts
|
|
239
|
-
* createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], export: true })
|
|
240
|
-
* ```
|
|
241
|
-
*/
|
|
242
|
-
const createSource = nodeFactory(nodeKinds.source);
|
|
243
|
-
/**
|
|
244
|
-
* Creates a fully resolved `FileNode` from a file input descriptor.
|
|
245
|
-
*
|
|
246
|
-
* Computes:
|
|
247
|
-
* - `id` SHA256 hash of the file path
|
|
248
|
-
* - `name` `baseName` without extension
|
|
249
|
-
* - `extname` extension extracted from `baseName`
|
|
250
|
-
*
|
|
251
|
-
* Deduplicates:
|
|
252
|
-
* - `sources` via `combineSources`
|
|
253
|
-
* - `exports` via `combineExports`
|
|
254
|
-
* - `imports` via `combineImports` (also filters unused imports)
|
|
255
|
-
*
|
|
256
|
-
* @throws {Error} when `baseName` has no extension.
|
|
257
|
-
*
|
|
258
|
-
* @example
|
|
259
|
-
* ```ts
|
|
260
|
-
* const file = createFile({
|
|
261
|
-
* baseName: 'petStore.ts',
|
|
262
|
-
* path: 'src/models/petStore.ts',
|
|
263
|
-
* sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],
|
|
264
|
-
* imports: [createImport({ name: ['z'], path: 'zod' })],
|
|
265
|
-
* exports: [createExport({ name: ['Pet'], path: './petStore' })],
|
|
266
|
-
* })
|
|
267
|
-
* // file.id = SHA256 hash of 'src/models/petStore.ts'
|
|
268
|
-
* // file.name = 'petStore'
|
|
269
|
-
* // file.extname = '.ts'
|
|
270
|
-
* ```
|
|
271
|
-
*
|
|
272
|
-
* @example Copy a real file into the output
|
|
273
|
-
* ```ts
|
|
274
|
-
* const file = createFile({
|
|
275
|
-
* baseName: 'client.ts',
|
|
276
|
-
* path: 'src/gen/client.ts',
|
|
277
|
-
* copy: '/abs/path/to/templates/client.ts',
|
|
278
|
-
* })
|
|
279
|
-
* ```
|
|
280
|
-
*/
|
|
281
|
-
function createFile(input) {
|
|
282
|
-
const extname = path.extname(input.baseName);
|
|
283
|
-
if (!extname) throw new Error(`No extname found for ${input.baseName}`);
|
|
284
|
-
const resolvedExports = input.exports?.length ? combineExports(input.exports) : [];
|
|
285
|
-
const resolvedSources = input.sources?.length ? combineSources(input.sources) : [];
|
|
286
|
-
const resolvedImports = (() => {
|
|
287
|
-
if (!input.imports?.length) return [];
|
|
288
|
-
const sourceParts = [];
|
|
289
|
-
const localNames = /* @__PURE__ */ new Set();
|
|
290
|
-
for (const item of resolvedSources) {
|
|
291
|
-
const extracted = item.nodes && getNodeText(item.nodes);
|
|
292
|
-
if (extracted) sourceParts.push(extracted);
|
|
293
|
-
if (item.name) localNames.add(item.name);
|
|
294
|
-
}
|
|
295
|
-
const source = sourceParts.join("\n") || void 0;
|
|
296
|
-
return combineImports(input.imports, resolvedExports, source).flatMap((imp) => {
|
|
297
|
-
if (imp.path === input.path) return [];
|
|
298
|
-
const names = getNames(imp);
|
|
299
|
-
const kept = names.filter((item) => !localNames.has(item.alias ?? item.name));
|
|
300
|
-
if (!kept.length) return [];
|
|
301
|
-
return [kept.length === names.length ? imp : createImport({
|
|
302
|
-
path: imp.path,
|
|
303
|
-
...imp.root != null ? { root: imp.root } : {},
|
|
304
|
-
names: kept
|
|
305
|
-
})];
|
|
306
|
-
});
|
|
307
|
-
})();
|
|
308
|
-
return {
|
|
309
|
-
...input,
|
|
310
|
-
kind: nodeKinds.file,
|
|
311
|
-
id: hash("sha256", input.path, "hex"),
|
|
312
|
-
name: path.basename(input.baseName, extname),
|
|
313
|
-
extname,
|
|
314
|
-
imports: resolvedImports,
|
|
315
|
-
exports: resolvedExports,
|
|
316
|
-
sources: resolvedSources,
|
|
317
|
-
meta: input.meta ?? {}
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
214
|
// src/utils/combineFileMembers.ts
|
|
321
215
|
/**
|
|
322
216
|
* File-member merging. `combineImports` and `combineExports` deduplicate and sort the import and
|
|
@@ -324,7 +218,26 @@ function createFile(input) {
|
|
|
324
218
|
* `combineImports` also drops imports nothing references. This works on a file's members, not on
|
|
325
219
|
* schema content.
|
|
326
220
|
*/
|
|
327
|
-
const IDENTIFIER_RUN = /[\
|
|
221
|
+
const IDENTIFIER_RUN = /[\p{ID_Continue}$\u200C\u200D]+/gu;
|
|
222
|
+
const IDENTIFIER_CHAR = /[\p{ID_Continue}$\u200C\u200D]/u;
|
|
223
|
+
function codePointBefore({ source, index }) {
|
|
224
|
+
return [...source.slice(Math.max(0, index - 2), index)].at(-1);
|
|
225
|
+
}
|
|
226
|
+
function codePointAt({ source, index }) {
|
|
227
|
+
const point = source.codePointAt(index);
|
|
228
|
+
return point === void 0 ? void 0 : String.fromCodePoint(point);
|
|
229
|
+
}
|
|
230
|
+
function occursAsIdentifier({ source, name }) {
|
|
231
|
+
const isPart = (char) => char !== void 0 && IDENTIFIER_CHAR.test(char);
|
|
232
|
+
for (let index = source.indexOf(name); index !== -1; index = source.indexOf(name, index + 1)) if (!isPart(codePointBefore({
|
|
233
|
+
source,
|
|
234
|
+
index
|
|
235
|
+
})) && !isPart(codePointAt({
|
|
236
|
+
source,
|
|
237
|
+
index: index + name.length
|
|
238
|
+
}))) return true;
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
328
241
|
/**
|
|
329
242
|
* How many imports a file needs before indexing the source beats scanning it once per name.
|
|
330
243
|
*/
|
|
@@ -449,13 +362,17 @@ function combineExports(exports) {
|
|
|
449
362
|
/**
|
|
450
363
|
* Deduplicates and merges `ImportNode` objects, filtering out unused imports.
|
|
451
364
|
*
|
|
452
|
-
* Retains imports
|
|
453
|
-
* a
|
|
365
|
+
* Retains imports whose local name occurs in `source` as a whole identifier, or that are re-exported. A name
|
|
366
|
+
* that only occurs inside a longer identifier, such as `Pet` in `PetStatus`, counts as unused. One import per path,
|
|
367
|
+
* form and space. Returns a sorted, deduplicated, filtered array.
|
|
454
368
|
*/
|
|
455
369
|
function combineImports(imports, exports, source) {
|
|
456
370
|
const exportedNames = new Set(exports.flatMap((node) => getNames(node).map((item) => item.alias ?? item.name)));
|
|
457
371
|
const identifiers = source && imports.length > INDEX_ABOVE_IMPORTS ? new Set(source.match(IDENTIFIER_RUN)) : null;
|
|
458
|
-
const isUsed = (importName) => !source ||
|
|
372
|
+
const isUsed = (importName) => !source || exportedNames.has(importName) || (identifiers ? identifiers.has(importName) : occursAsIdentifier({
|
|
373
|
+
source,
|
|
374
|
+
name: importName
|
|
375
|
+
}));
|
|
459
376
|
const statements = toStatements(imports.filter((node) => node.path !== node.root), importForm);
|
|
460
377
|
const pathsWithUsedNamedImport = new Set(statements.filter(({ form, names }) => form === "named" && names.some((item) => isUsed(item.alias ?? item.name))).map(({ path }) => path));
|
|
461
378
|
const keep = (item, { form, path }) => isUsed(item.alias ?? item.name) || form !== "named" && pathsWithUsedNamedImport.has(path);
|
|
@@ -465,6 +382,103 @@ function combineImports(imports, exports, source) {
|
|
|
465
382
|
names
|
|
466
383
|
}));
|
|
467
384
|
}
|
|
468
|
-
|
|
385
|
+
// src/nodes/base.ts
|
|
386
|
+
/** Builds a `createX` factory for a node whose only computed field is `kind`. */
|
|
387
|
+
function nodeFactory(kind) {
|
|
388
|
+
return (input) => {
|
|
389
|
+
return {
|
|
390
|
+
...input,
|
|
391
|
+
kind
|
|
392
|
+
};
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
// src/nodes/file.ts
|
|
396
|
+
/**
|
|
397
|
+
* Creates a `SourceNode` representing a fragment of source code within a file.
|
|
398
|
+
*
|
|
399
|
+
* @example
|
|
400
|
+
* ```ts
|
|
401
|
+
* createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], export: true })
|
|
402
|
+
* ```
|
|
403
|
+
*/
|
|
404
|
+
const createSource = nodeFactory(nodeKinds.source);
|
|
405
|
+
/**
|
|
406
|
+
* Creates a fully resolved `FileNode` from a file input descriptor.
|
|
407
|
+
*
|
|
408
|
+
* Computes:
|
|
409
|
+
* - `id` SHA256 hash of the file path
|
|
410
|
+
* - `name` `baseName` without extension
|
|
411
|
+
* - `extname` extension extracted from `baseName`
|
|
412
|
+
*
|
|
413
|
+
* Deduplicates:
|
|
414
|
+
* - `sources` via `combineSources`
|
|
415
|
+
* - `exports` via `combineExports`
|
|
416
|
+
* - `imports` via `combineImports` (also filters unused imports)
|
|
417
|
+
*
|
|
418
|
+
* @throws {Error} when `baseName` has no extension.
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* ```ts
|
|
422
|
+
* const file = createFile({
|
|
423
|
+
* baseName: 'petStore.ts',
|
|
424
|
+
* path: 'src/models/petStore.ts',
|
|
425
|
+
* sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],
|
|
426
|
+
* imports: [createImport({ names: [{ name: 'z' }], path: 'zod' })],
|
|
427
|
+
* exports: [createExport({ names: [{ name: 'Pet' }], path: './petStore' })],
|
|
428
|
+
* })
|
|
429
|
+
* // file.id = SHA256 hash of 'src/models/petStore.ts'
|
|
430
|
+
* // file.name = 'petStore'
|
|
431
|
+
* // file.extname = '.ts'
|
|
432
|
+
* ```
|
|
433
|
+
*
|
|
434
|
+
* @example Copy a real file into the output
|
|
435
|
+
* ```ts
|
|
436
|
+
* const file = createFile({
|
|
437
|
+
* baseName: 'client.ts',
|
|
438
|
+
* path: 'src/gen/client.ts',
|
|
439
|
+
* copy: '/abs/path/to/templates/client.ts',
|
|
440
|
+
* })
|
|
441
|
+
* ```
|
|
442
|
+
*/
|
|
443
|
+
function createFile(input) {
|
|
444
|
+
const extname = path.extname(input.baseName);
|
|
445
|
+
if (!extname) throw new Error(`No extname found for ${input.baseName}`);
|
|
446
|
+
const resolvedExports = input.exports?.length ? combineExports(input.exports) : [];
|
|
447
|
+
const resolvedSources = input.sources?.length ? combineSources(input.sources) : [];
|
|
448
|
+
const resolvedImports = (() => {
|
|
449
|
+
if (!input.imports?.length) return [];
|
|
450
|
+
const sourceParts = [];
|
|
451
|
+
const localNames = /* @__PURE__ */ new Set();
|
|
452
|
+
for (const item of resolvedSources) {
|
|
453
|
+
const extracted = item.nodes && getNodeText(item.nodes);
|
|
454
|
+
if (extracted) sourceParts.push(extracted);
|
|
455
|
+
if (item.name) localNames.add(item.name);
|
|
456
|
+
}
|
|
457
|
+
const source = sourceParts.join("\n") || void 0;
|
|
458
|
+
return combineImports(input.imports, resolvedExports, source).flatMap((imp) => {
|
|
459
|
+
if (imp.path === input.path) return [];
|
|
460
|
+
const names = getNames(imp);
|
|
461
|
+
const kept = names.filter((item) => !localNames.has(item.alias ?? item.name));
|
|
462
|
+
if (!kept.length) return [];
|
|
463
|
+
return [kept.length === names.length ? imp : createImport({
|
|
464
|
+
path: imp.path,
|
|
465
|
+
...imp.root != null ? { root: imp.root } : {},
|
|
466
|
+
names: kept
|
|
467
|
+
})];
|
|
468
|
+
});
|
|
469
|
+
})();
|
|
470
|
+
return {
|
|
471
|
+
...input,
|
|
472
|
+
kind: nodeKinds.file,
|
|
473
|
+
id: hash("sha256", input.path, "hex"),
|
|
474
|
+
name: path.basename(input.baseName, extname),
|
|
475
|
+
extname,
|
|
476
|
+
imports: resolvedImports,
|
|
477
|
+
exports: resolvedExports,
|
|
478
|
+
sources: resolvedSources,
|
|
479
|
+
meta: input.meta ?? {}
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
export { createExport as a, getSpace as c, getRelativePath as i, isExported as l, createSource as n, createImport as o, nodeFactory as r, getNames as s, createFile as t };
|
|
469
483
|
|
|
470
|
-
//# sourceMappingURL=
|
|
484
|
+
//# sourceMappingURL=file-AcKQt60j.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-AcKQt60j.js","names":[],"sources":["../src/utils/moduleNames.ts","../src/nodes/importExport.ts","../src/utils/combineFileMembers.ts","../src/nodes/base.ts","../src/nodes/file.ts"],"sourcesContent":["import type { ExportNode, ImportNode, ModuleName, SourceNode, Space } from '../nodes/file.ts'\n\n/**\n * Returns the names an import or export brings across. A node built with the deprecated fields gets them from\n * those, each with an explicit `space`, so it prints exactly as before.\n */\nexport function getNames(node: ImportNode | ExportNode): Array<ModuleName> {\n if (node.names) return node.names\n return node.kind === 'Import' ? fromDeprecatedImport(node) : fromDeprecatedExport(node)\n}\n\n/**\n * Returns `true` when a source is an exported declaration. Reads the deprecated `isIndexable` and `isExportable`, in that order, when `export` is unset.\n */\nexport function isExported(source: Pick<SourceNode, 'export' | 'isIndexable' | 'isExportable'>): boolean {\n return !!(source.export ?? source.isIndexable ?? source.isExportable)\n}\n\nexport function getSpace(source: SourceNode): Space {\n if (source.space) return source.space\n if (source.isTypeOnly != null) return source.isTypeOnly ? 'type' : 'value'\n return source.nodes?.[0]?.kind === 'Type' ? 'type' : 'value'\n}\n\nexport type DeprecatedImport = Pick<ImportNode, 'name' | 'isTypeOnly' | 'isNameSpace'>\nexport type DeprecatedExport = Pick<ExportNode, 'name' | 'isTypeOnly' | 'asAlias'>\n\n/**\n * @deprecated Converts a node built with `name`, `isTypeOnly` and `isNameSpace` to `names`. Removed in Kubb v6.\n */\nfunction fromDeprecatedImport({ name, isTypeOnly, isNameSpace }: DeprecatedImport): Array<ModuleName> {\n const space: Space = isTypeOnly ? 'type' : 'value'\n if (!Array.isArray(name)) return [{ name: isNameSpace ? '*' : 'default', alias: name, space }]\n return name.map((item) => (typeof item === 'string' ? { name: item, space } : { name: item.propertyName, ...(item.name ? { alias: item.name } : {}), space }))\n}\n\n/**\n * @deprecated Converts a node built with `name`, `isTypeOnly` and `asAlias` to `names`. Removed in Kubb v6.\n */\nfunction fromDeprecatedExport({ name, isTypeOnly, asAlias }: DeprecatedExport): Array<ModuleName> {\n const space: Space = isTypeOnly ? 'type' : 'value'\n if (name == null) return [{ name: '*', space }]\n if (!Array.isArray(name)) return [asAlias ? { name: '*', alias: name, space } : { name, space }]\n return name.map((item) => ({ name: item, space }))\n}\n\n/**\n * @deprecated The old import fields for `names`, for code that still reads them. Removed in Kubb v6.\n */\nexport function toDeprecatedImport(names: ReadonlyArray<ModuleName>): DeprecatedImport {\n const isTypeOnly = names.length > 0 && names.every((item) => item.space === 'type')\n const [first] = names\n if (names.length === 1 && first?.alias && (first.name === '*' || first.name === 'default')) {\n return { name: first.alias, isTypeOnly, isNameSpace: first.name === '*' }\n }\n return { name: names.map((item) => (item.alias ? { propertyName: item.name, name: item.alias } : item.name)), isTypeOnly, isNameSpace: false }\n}\n\n/**\n * @deprecated The old export fields for `names`; an alias stands in for its name. Removed in Kubb v6.\n */\nexport function toDeprecatedExport(names: ReadonlyArray<ModuleName>): DeprecatedExport {\n const isTypeOnly = names.length > 0 && names.every((item) => item.space === 'type')\n const [first] = names\n if (names.length === 1 && first?.name === '*') {\n return first.alias ? { name: first.alias, isTypeOnly, asAlias: true } : { isTypeOnly, asAlias: false }\n }\n return { name: names.map((item) => item.alias ?? item.name), isTypeOnly, asAlias: false }\n}\n","import { nodeKinds } from '../constants.ts'\nimport { toDeprecatedExport, toDeprecatedImport } from '../utils/moduleNames.ts'\nimport type { ExportInput, ExportNode, ImportInput, ImportNode, ModuleName } from './file.ts'\n\ntype Override<TValue> = { value: TValue | null | undefined; derived: TValue | null | undefined }\n\nfunction overrideSpace(names: Array<ModuleName>, { value, derived }: Override<boolean>): Array<ModuleName> {\n if (value == null || value === derived) return names\n const space = value ? 'type' : 'value'\n return names.map((item) => ({ ...item, space }))\n}\n\nconst isOverride = ({ value, derived }: Override<unknown>): boolean => value !== undefined && JSON.stringify(value) !== JSON.stringify(derived)\n\n// Object spread copies symbol keys, so `{ ...imp, names }` carries the fields `imp` derived and they can be told apart from an override.\nconst DERIVED = Symbol.for('kubb.ast.derived')\n// `name` is stored as JSON, so changing the node's `name` array in place still counts as an override.\ntype Derived = { name: string | undefined; isTypeOnly?: boolean | null }\ntype WithDerived = { [DERIVED]?: Derived }\n\nfunction ownFields<TName>(input: { name?: TName; isTypeOnly?: boolean | null } & WithDerived): { name?: TName; isTypeOnly?: boolean | null } {\n const snapshot = input[DERIVED]\n if (!snapshot) return { name: input.name, isTypeOnly: input.isTypeOnly }\n return {\n name: JSON.stringify(input.name) === snapshot.name ? undefined : input.name,\n isTypeOnly: input.isTypeOnly === snapshot.isTypeOnly ? undefined : input.isTypeOnly,\n }\n}\n\nfunction withoutDerived<T extends object>(input: T): T {\n const { [DERIVED]: _, ...rest } = input as T & WithDerived\n return rest as T\n}\n\n/**\n * Creates an `ImportNode` and fills the deprecated `name` and `isTypeOnly` from `names`. A deprecated field\n * that differs from the one `names` gives overrides it.\n *\n * A spread keeps the record of the derived fields only when the original node has one, which a node made\n * from `names` does. For a node made without `names`, or a JSON or `structuredClone` copy, leave out `name`\n * and `isTypeOnly` before you pass new `names`, or the old `name` replaces the new `names` and the old\n * `isTypeOnly` sets their space.\n */\nexport function createImport(input: ImportInput): ImportNode {\n if (!input.names) return { ...withoutDerived(input), name: input.name ?? [], kind: nodeKinds.import }\n const own = ownFields(input)\n const derived = toDeprecatedImport(input.names)\n if (isOverride({ value: own.name, derived: derived.name })) return { ...withoutDerived(input), names: null, name: own.name ?? [], kind: nodeKinds.import }\n const names = overrideSpace(input.names, { value: own.isTypeOnly, derived: derived.isTypeOnly })\n const fields = toDeprecatedImport(names)\n const node: ImportNode & WithDerived = {\n ...input,\n ...fields,\n names,\n [DERIVED]: { name: JSON.stringify(fields.name), isTypeOnly: fields.isTypeOnly },\n kind: nodeKinds.import,\n }\n return node\n}\n\n/**\n * Creates an `ExportNode`, with the deprecated fields of {@link createImport}. For a node made without\n * `names`, or a JSON or `structuredClone` copy, leave out `name` and `isTypeOnly` before you pass new `names`.\n */\nexport function createExport(input: ExportInput): ExportNode {\n if (!input.names) return { ...withoutDerived(input), kind: nodeKinds.export }\n const own = ownFields(input)\n const derived = toDeprecatedExport(input.names)\n if (isOverride({ value: own.name, derived: derived.name })) return { ...withoutDerived(input), name: own.name, names: null, kind: nodeKinds.export }\n const names = overrideSpace(input.names, { value: own.isTypeOnly, derived: derived.isTypeOnly })\n const fields = toDeprecatedExport(names)\n const node: ExportNode & WithDerived = {\n ...input,\n ...fields,\n name: fields.name,\n names,\n [DERIVED]: { name: JSON.stringify(fields.name), isTypeOnly: fields.isTypeOnly },\n kind: nodeKinds.export,\n }\n return node\n}\n","/**\n * File-member merging. `combineImports` and `combineExports` deduplicate and sort the import and\n * export entries of one file, while `combineSources` deduplicates source entries in original order.\n * `combineImports` also drops imports nothing references. This works on a file's members, not on\n * schema content.\n */\nimport path from 'node:path'\nimport process from 'node:process'\nimport { memo } from '@internals/utils'\nimport type { ExportNode, ImportNode, ModuleName, SourceNode, Space } from '../nodes/file.ts'\nimport { createExport, createImport } from '../nodes/importExport.ts'\nimport { getNames, getSpace, isExported } from './moduleNames.ts'\n\n// The characters that continue a JavaScript identifier, so `éPet` and `PetStatus` are one identifier each, not a use of `Pet`.\nconst IDENTIFIER_RUN = /[\\p{ID_Continue}$\\u200C\\u200D]+/gu\nconst IDENTIFIER_CHAR = /[\\p{ID_Continue}$\\u200C\\u200D]/u\n\n// Whole code points, so a surrogate pair such as `𐐀` counts as the one character it is.\nfunction codePointBefore({ source, index }: { source: string; index: number }): string | undefined {\n return [...source.slice(Math.max(0, index - 2), index)].at(-1)\n}\n\nfunction codePointAt({ source, index }: { source: string; index: number }): string | undefined {\n const point = source.codePointAt(index)\n return point === undefined ? undefined : String.fromCodePoint(point)\n}\n\nfunction occursAsIdentifier({ source, name }: { source: string; name: string }): boolean {\n const isPart = (char: string | undefined) => char !== undefined && IDENTIFIER_CHAR.test(char)\n for (let index = source.indexOf(name); index !== -1; index = source.indexOf(name, index + 1)) {\n if (!isPart(codePointBefore({ source, index })) && !isPart(codePointAt({ source, index: index + name.length }))) return true\n }\n return false\n}\n\n/**\n * How many imports a file needs before indexing the source beats scanning it once per name.\n */\nconst INDEX_ABOVE_IMPORTS = 128\n\ntype Form = 'named' | 'default' | '*'\n\ntype Statement = { path: string; root?: string | null; form: Form; space: Space; names: Array<ModuleName> }\n\nconst importForm = (item: ModuleName): Form => (item.alias && (item.name === '*' || item.name === 'default') ? item.name : 'named')\nconst exportForm = (item: ModuleName): Form => (item.name === '*' ? '*' : 'named')\nconst label = (item: ModuleName): string => (item.alias ? `${item.name} as ${item.alias}` : item.name)\n\nfunction statementKey({ path, form, space, names }: Statement): string {\n return form === 'named' ? `${path}\\0named\\0${space}` : `${path}\\0${form}\\0${names[0]?.alias ?? ''}\\0${space}`\n}\n\nfunction toStatements(nodes: ReadonlyArray<ImportNode | ExportNode>, formOf: (item: ModuleName) => Form): Array<Statement> {\n return nodes.flatMap((node) => {\n const statements = new Map<string, Statement>()\n for (const item of getNames(node)) {\n const statement: Statement = {\n path: node.path,\n root: node.kind === 'Import' ? node.root : undefined,\n form: formOf(item),\n space: item.space ?? 'value',\n names: [],\n }\n const key = statementKey({ ...statement, names: [item] })\n const existing = statements.get(key) ?? statement\n statements.set(key, existing)\n existing.names.push(item)\n }\n return [...statements.values()]\n })\n}\n\n/**\n * Relative specifiers by `root`, then `path`. `createFile` sorts a file's imports again on every\n * merge, and the path math dominated that sort on large specs. Two levels keep the existing strings\n * as keys, so lookups reuse their hashes instead of hashing a new joined key each time.\n */\nconst specifierCache = memo.create<string, Map<string, string>>({ max: 10_000 })\n\n/**\n * Module specifier that imports `filePath` from the file at `root`: POSIX, relative to that file's directory, `./`-prefixed unless it climbs with `../`.\n *\n * @example\n * ```ts\n * getRelativePath('/root/src/models/pet.ts', '/root/lib/client.ts') // '../../lib/client.ts'\n * ```\n */\nexport function getRelativePath(root: string, filePath: string): string {\n // A relative input resolves against the working directory, so that directory is part of its key.\n const rootKey = path.isAbsolute(root) && path.isAbsolute(filePath) ? root : `${process.cwd()}\\u0000${root}`\n const byPath = memo(specifierCache, rootKey, () => new Map<string, string>())\n return memo(byPath, filePath, () => {\n const relative = path.relative(path.dirname(root), filePath).replaceAll('\\\\', '/')\n return relative.startsWith('../') ? relative : `./${relative}`\n })\n}\n\n/** The specifier a member is written with, so sorting on it gives the same order on every OS. */\nfunction specifier(node: { path: string; root?: string | null }): string {\n return node.root ? getRelativePath(node.root, node.path) : node.path\n}\n\nfunction sortKey(statement: Statement): string {\n const form = statement.form === 'named' ? '1' : '0'\n const space = statement.space === 'type' ? '0' : '1'\n return `${form}:${space}:${specifier(statement)}:${statement.names.map(label).toSorted().join('\\0')}`\n}\n\nfunction mergeStatements(statements: Array<Statement>, keep: (item: ModuleName, statement: Statement) => boolean = () => true): Array<Statement> {\n const merged = new Map<string, { statement: Statement; seen: Set<string> }>()\n const sorted = statements.map((statement) => ({ statement, key: sortKey(statement) })).sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0))\n\n for (const { statement } of sorted) {\n const key = statementKey(statement)\n const entry = merged.get(key) ?? { statement: { ...statement, names: [] }, seen: new Set<string>() }\n merged.set(key, entry)\n for (const item of statement.names) {\n const id = item.alias ?? item.name\n if (entry.seen.has(id) || !keep(item, statement)) continue\n entry.seen.add(id)\n entry.statement.names.push(item)\n }\n }\n\n const result = [...merged.values()].map(({ statement }) => statement)\n // A name kept as a value also serves its type uses, so a type statement from the same path must not bind it again.\n const bound = ({ path, item }: { path: string; item: ModuleName }) => `${path}\\0${item.alias ?? item.name}`\n const values = new Set(result.filter(({ space }) => space === 'value').flatMap(({ path, names }) => names.map((item) => bound({ path, item }))))\n return result\n .map((statement) =>\n statement.space === 'type' ? { ...statement, names: statement.names.filter((item) => !values.has(bound({ path: statement.path, item }))) } : statement,\n )\n .filter((statement) => statement.names.length > 0)\n}\n\n/**\n * Deduplicates `SourceNode` objects by `name + export + space`, keeping the first of each\n * key. An unnamed source only drops when the same node appears twice, so markdown can repeat a\n * paragraph or a table. Returns the deduplicated array in original order.\n */\nexport function combineSources(sources: Array<SourceNode>): Array<SourceNode> {\n const seen = new Set<SourceNode | string>()\n return sources.filter((source) => {\n const key = source.name != null ? `${source.name}:${isExported(source)}:${getSpace(source)}` : source\n if (seen.has(key)) return false\n seen.add(key)\n return true\n })\n}\n\n/**\n * Deduplicates and merges `ExportNode` objects: one export per path, form and space. Returns a sorted array.\n */\nexport function combineExports(exports: Array<ExportNode>): Array<ExportNode> {\n // Built through `createExport`, so a later `{ ...exp, names }` keeps the new names.\n return mergeStatements(toStatements(exports, exportForm)).map(({ path, names }) => createExport({ path, names }))\n}\n\n/**\n * Deduplicates and merges `ImportNode` objects, filtering out unused imports.\n *\n * Retains imports whose local name occurs in `source` as a whole identifier, or that are re-exported. A name\n * that only occurs inside a longer identifier, such as `Pet` in `PetStatus`, counts as unused. One import per path,\n * form and space. Returns a sorted, deduplicated, filtered array.\n */\nexport function combineImports(imports: Array<ImportNode>, exports: Array<ExportNode>, source?: string): Array<ImportNode> {\n // Build a lookup of all exported names to retain imports that are re-exported\n const exportedNames = new Set(exports.flatMap((node) => getNames(node).map((item) => item.alias ?? item.name)))\n // `createFile` re-runs on every merge into a file, so scanning the source once per import name\n // costs a heavily merged file that scan again for every fragment it already holds. Indexing pays\n // for itself there, and costs more than it saves on the small files the default output produces.\n const identifiers = source && imports.length > INDEX_ABOVE_IMPORTS ? new Set(source.match(IDENTIFIER_RUN)) : null\n\n const isUsed = (importName: string): boolean =>\n !source || exportedNames.has(importName) || (identifiers ? identifiers.has(importName) : occursAsIdentifier({ source, name: importName }))\n\n const statements = toStatements(\n imports.filter((node) => node.path !== node.root),\n importForm,\n )\n\n // Paths that keep at least one used named import. A default import from such a path is retained\n // even when its binding can't be found in `source` e.g. a generated `client` default import\n // alongside `import type { Client } from <same path>`, where merged grouped output omits the body.\n const pathsWithUsedNamedImport = new Set(\n statements.filter(({ form, names }) => form === 'named' && names.some((item) => isUsed(item.alias ?? item.name))).map(({ path }) => path),\n )\n const keep = (item: ModuleName, { form, path }: Statement) => isUsed(item.alias ?? item.name) || (form !== 'named' && pathsWithUsedNamedImport.has(path))\n\n return mergeStatements(statements, keep).map(({ path, root, names }) => createImport({ path, ...(root != null ? { root } : {}), names }))\n}\n","import type { ValueOf } from '@internals/utils'\nimport type { nodeKinds } from '../constants.ts'\n\n/**\n * `kind` values used by AST nodes.\n *\n * @example\n * ```ts\n * const kind: NodeKind = 'Schema'\n * ```\n */\nexport type NodeKind = ValueOf<typeof nodeKinds>\n\n/**\n * Base shape shared by all AST nodes.\n *\n * @example\n * ```ts\n * const base: BaseNode = { kind: 'Input' }\n * ```\n */\nexport type BaseNode = {\n /**\n * Node discriminator.\n */\n kind: NodeKind\n /**\n * Where the node comes from in the input, in the form the adapter's `locate` reads. Document\n * adapters such as OpenAPI and AsyncAPI use an RFC 6901 JSON pointer, for example\n * `#/components/schemas/Pet`. Plugins can copy it to the code nodes they emit.\n */\n pointer?: string\n}\n\n/** `Omit` applied to each member of a union, so the union survives. */\nexport type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never\n\n/** Builds a `createX` factory for a node whose only computed field is `kind`. */\nexport function nodeFactory<T extends BaseNode>(kind: T['kind']): (input: Omit<T, 'kind'>) => T {\n return (input) => {\n const node = { ...input, kind }\n return node as T\n }\n}\n","import { hash } from 'node:crypto'\nimport path from 'node:path'\nimport { nodeKinds } from '../constants.ts'\nimport { combineExports, combineImports, combineSources } from '../utils/combineFileMembers.ts'\nimport { getNames } from '../utils/moduleNames.ts'\nimport { getNodeText } from '../utils/nodeText.ts'\nimport { type BaseNode, nodeFactory } from './base.ts'\nimport type { CodeNode } from './code.ts'\nimport { createExport, createImport } from './importExport.ts'\n\nexport { createExport, createImport }\n\n/**\n * Supported file extensions.\n */\nexport type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`\n\nexport type ImportName = string | Array<string | { propertyName: string; name?: string }>\n\n/**\n * Whether a declaration exists only at compile time (`'type'`) or also at runtime (`'value'`).\n */\nexport type Space = 'type' | 'value'\n\n/**\n * One name an import or export brings across, as in the ECMAScript `ImportEntry` record.\n */\nexport type ModuleName = {\n /**\n * Name in the other module: `'default'` for its default export, `'*'` for the whole module.\n */\n name: string\n /**\n * Local name for an import, or the exported name for an export.\n */\n alias?: string | null\n /**\n * Type or value.\n * @default 'value'\n */\n space?: Space | null\n}\n\n/**\n * Represents a language-agnostic import/dependency declaration.\n *\n * @example Named import (TypeScript: `import { useState } from 'react'`)\n * ```ts\n * createImport({ names: [{ name: 'useState' }], path: 'react' })\n * ```\n *\n * @example Default import (TypeScript: `import React from 'react'`)\n * ```ts\n * createImport({ names: [{ name: 'default', alias: 'React' }], path: 'react' })\n * ```\n *\n * @example Type-only import (TypeScript: `import type { FC } from 'react'`)\n * ```ts\n * createImport({ names: [{ name: 'FC', space: 'type' }], path: 'react' })\n * ```\n *\n * @example Namespace import (TypeScript: `import * as React from 'react'`)\n * ```ts\n * createImport({ names: [{ name: '*', alias: 'React' }], path: 'react' })\n * ```\n */\nexport type ImportNode = BaseNode & {\n kind: 'Import'\n /**\n * The names the import brings in. `ast.file.getNames` also reads the deprecated fields.\n */\n names?: Array<ModuleName> | null\n /**\n * Import name(s) to be used.\n *\n * @deprecated Use `names`. Removed in Kubb v6.\n */\n name: ImportName\n /**\n * Path for the import.\n *\n * @example\n * `'@kubb/core'`\n */\n path: string\n /**\n * Add a type-only import prefix.\n *\n * @deprecated Set `space: 'type'` on each name. Removed in Kubb v6.\n */\n isTypeOnly?: boolean | null\n /**\n * Import the entire module as a namespace.\n *\n * @deprecated Use `{ name: '*', alias }` in `names`. Removed in Kubb v6.\n */\n isNameSpace?: boolean | null\n /**\n * When set, the import path is resolved relative to this root.\n */\n root?: string | null\n}\n\n/**\n * Represents a language-agnostic export/public API declaration.\n *\n * @example Named export (TypeScript: `export { Pets } from './Pets'`)\n * ```ts\n * createExport({ names: [{ name: 'Pets' }], path: './Pets' })\n * ```\n *\n * @example Type-only export (TypeScript: `export type { Pet } from './Pet'`)\n * ```ts\n * createExport({ names: [{ name: 'Pet', space: 'type' }], path: './Pet' })\n * ```\n *\n * @example Wildcard export (TypeScript: `export * from './utils'`)\n * ```ts\n * createExport({ names: [{ name: '*' }], path: './utils' })\n * ```\n *\n * @example Namespace alias (TypeScript: `export * as utils from './utils'`)\n * ```ts\n * createExport({ names: [{ name: '*', alias: 'utils' }], path: './utils' })\n * ```\n */\nexport type ExportNode = BaseNode & {\n kind: 'Export'\n /**\n * The names the export passes on. `ast.file.getNames` also reads the deprecated fields.\n */\n names?: Array<ModuleName> | null\n /**\n * Export name(s) to be used. When omitted, generates a wildcard export.\n *\n * @deprecated Use `names`. Removed in Kubb v6.\n */\n name?: string | Array<string> | null\n /**\n * Path for the export.\n *\n * @example\n * `'@kubb/core'`\n */\n path: string\n /**\n * Add a type-only export prefix.\n *\n * @deprecated Set `space: 'type'` on each name. Removed in Kubb v6.\n */\n isTypeOnly?: boolean | null\n /**\n * Export as an aliased namespace.\n *\n * @deprecated Use `{ name: '*', alias }` in `names`. Removed in Kubb v6.\n */\n asAlias?: boolean | null\n}\n\n/**\n * Represents a fragment of source code within a file.\n *\n * @example Named exportable source\n * ```ts\n * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], export: true })\n * ```\n *\n * @example Inline unnamed code block\n * ```ts\n * createSource({ nodes: [createText('const x = 1')] })\n * ```\n */\nexport type SourceNode = BaseNode & {\n kind: 'Source'\n /**\n * Optional name identifying this source (used for deduplication and barrel generation).\n */\n name?: string | null\n /**\n * Type or value. When unset, a source whose first node is a `Type` is a type.\n */\n space?: Space | null\n /**\n * Mark this source as a type-only export.\n *\n * @deprecated Use `space: 'type'`. Removed in Kubb v6.\n */\n isTypeOnly?: boolean | null\n /**\n * Mark this source as an exported declaration, which barrels list. The source text carries its own `export` keyword.\n */\n export?: boolean | null\n /**\n * Mark this exported source as the module's default export. Barrels skip it, since they can't re-export it by name.\n */\n default?: boolean | null\n /**\n * @deprecated Use `export`. Removed in Kubb v6.\n */\n isExportable?: boolean | null\n /**\n * @deprecated Use `export`. Removed in Kubb v6.\n */\n isIndexable?: boolean | null\n /**\n * Marks the source as a definition that importing files absorb instead of import. `expression` is\n * the declaration's right-hand side, such as `{ body: Pet }`.\n *\n * @deprecated Set `inline` on the file. Removed in Kubb v6.\n */\n inline?: { expression: string } | null\n /**\n * Child nodes that make up this source fragment, in DOM order.\n * Use a {@link TextNode} for raw string content.\n */\n nodes?: Array<CodeNode>\n}\n\n/**\n * Represents a fully resolved file in the AST.\n *\n * Created via `createFile()`, which computes the `id`, `name`, and `extname` from the input\n * and deduplicates `imports`, `exports`, and `sources`.\n *\n * @example\n * ```ts\n * const file = createFile({\n * baseName: 'petStore.ts',\n * path: 'src/models/petStore.ts',\n * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], export: true })],\n * imports: [createImport({ names: [{ name: 'z' }], path: 'zod' })],\n * exports: [createExport({ names: [{ name: 'Pet' }], path: './petStore' })],\n * })\n * // file.id = SHA256 hash of the path\n * // file.name = 'petStore'\n * // file.extname = '.ts'\n * ```\n */\nexport type FileNode<TMeta extends object = object> = BaseNode & {\n kind: 'File'\n /**\n * Unique identifier derived from a SHA256 hash of the file path. `createFile`\n * computes it, so callers do not need to provide it.\n */\n id: string\n /**\n * File name without extension, derived from `baseName`.\n *\n * @see https://nodejs.org/api/path.html#pathformatpathobject\n */\n name: string\n /**\n * File base name, including extension, shaped like `${name}${extname}`.\n *\n * @see https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\n baseName: `${string}.${string}`\n /**\n * Full qualified path to the file.\n */\n path: string\n /**\n * File extension extracted from `baseName`.\n */\n extname: Extname\n /**\n * Deduplicated list of source code fragments.\n */\n sources: Array<SourceNode>\n /**\n * Deduplicated list of import declarations.\n */\n imports: Array<ImportNode>\n /**\n * Deduplicated list of export declarations.\n */\n exports: Array<ExportNode>\n /**\n * Optional metadata attached to this file, read by plugins during barrel generation.\n */\n meta?: TMeta\n /**\n * Optional banner prepended to the generated file content.\n * Accepts `null` so `resolver.default.banner()` results can be passed directly.\n */\n banner?: string | null\n /**\n * Optional footer appended to the generated file content.\n * Accepts `null` so `resolver.default.footer()` results can be passed directly.\n */\n footer?: string | null\n /**\n * Absolute on-disk path to copy into the output, through the parser's `copy` hook when it has one.\n *\n * Use to emit a real source file shipped inside a package (a template) into the generated\n * folder. When set, `copy` provides the file content and any `sources` nodes are ignored for\n * output; `sources` may still carry `name`/`export` so barrel generation\n * treats the file the same as a rendered one.\n */\n copy?: string | null\n /**\n * Marks a file that is never written. Each file that imports from it gets the body of each imported declaration, such as `{ body: Pet }`, in place of its name.\n */\n inline?: boolean | null\n}\n\nexport type ImportInput = Omit<ImportNode, 'kind' | 'name'> & { name?: ImportName }\n\nexport type ExportInput = Omit<ExportNode, 'kind'>\n\n/**\n * Creates a `SourceNode` representing a fragment of source code within a file.\n *\n * @example\n * ```ts\n * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], export: true })\n * ```\n */\nexport const createSource = nodeFactory<SourceNode>(nodeKinds.source)\n\n/**\n * Input descriptor for {@link createFile}, before `id`, `name`, and `extname` are computed\n * and `imports`/`exports`/`sources` are deduplicated.\n */\nexport type UserFileNode<TMeta extends object = object> = Omit<FileNode<TMeta>, 'kind' | 'id' | 'name' | 'extname' | 'imports' | 'exports' | 'sources'> &\n Pick<Partial<FileNode<TMeta>>, 'imports' | 'exports' | 'sources'>\n\n/**\n * Creates a fully resolved `FileNode` from a file input descriptor.\n *\n * Computes:\n * - `id` SHA256 hash of the file path\n * - `name` `baseName` without extension\n * - `extname` extension extracted from `baseName`\n *\n * Deduplicates:\n * - `sources` via `combineSources`\n * - `exports` via `combineExports`\n * - `imports` via `combineImports` (also filters unused imports)\n *\n * @throws {Error} when `baseName` has no extension.\n *\n * @example\n * ```ts\n * const file = createFile({\n * baseName: 'petStore.ts',\n * path: 'src/models/petStore.ts',\n * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],\n * imports: [createImport({ names: [{ name: 'z' }], path: 'zod' })],\n * exports: [createExport({ names: [{ name: 'Pet' }], path: './petStore' })],\n * })\n * // file.id = SHA256 hash of 'src/models/petStore.ts'\n * // file.name = 'petStore'\n * // file.extname = '.ts'\n * ```\n *\n * @example Copy a real file into the output\n * ```ts\n * const file = createFile({\n * baseName: 'client.ts',\n * path: 'src/gen/client.ts',\n * copy: '/abs/path/to/templates/client.ts',\n * })\n * ```\n */\nexport function createFile<TMeta extends object = object>(input: UserFileNode<TMeta>): FileNode<TMeta> {\n const extname = path.extname(input.baseName) as `.${string}`\n if (!extname) {\n throw new Error(`No extname found for ${input.baseName}`)\n }\n\n const resolvedExports = input.exports?.length ? combineExports(input.exports) : []\n const resolvedSources = input.sources?.length ? combineSources(input.sources) : []\n\n // Skip building the source text and local-name set when there are no imports to resolve against them.\n const resolvedImports: Array<ImportNode> = (() => {\n if (!input.imports?.length) return []\n\n const sourceParts: Array<string> = []\n const localNames = new Set<string>()\n // Only the sources the file keeps count: an import used just by a dropped duplicate is unused.\n for (const item of resolvedSources) {\n const extracted = item.nodes && getNodeText(item.nodes)\n if (extracted) sourceParts.push(extracted)\n if (item.name) localNames.add(item.name)\n }\n const source = sourceParts.join('\\n') || undefined\n const combinedImports = combineImports(input.imports, resolvedExports, source)\n // Consolidating output (`mode: 'file'`) can put a symbol's definition and an import of it in the\n // same file: by path when the import still targets this file, by name when consolidation moved it.\n return combinedImports.flatMap((imp) => {\n if (imp.path === input.path) return []\n const names = getNames(imp)\n const kept = names.filter((item) => !localNames.has(item.alias ?? item.name))\n if (!kept.length) return []\n return [kept.length === names.length ? imp : createImport({ path: imp.path, ...(imp.root != null ? { root: imp.root } : {}), names: kept })]\n })\n })()\n\n return {\n ...input,\n kind: nodeKinds.file,\n id: hash('sha256', input.path, 'hex'),\n name: path.basename(input.baseName, extname),\n extname,\n imports: resolvedImports,\n exports: resolvedExports,\n sources: resolvedSources,\n meta: (input.meta ?? {}) as TMeta,\n }\n}\n"],"mappings":";;;;;;;;;;;;AAMA,SAAgB,SAAS,MAAkD;CACzE,IAAI,KAAK,OAAO,OAAO,KAAK;CAC5B,OAAO,KAAK,SAAS,WAAW,qBAAqB,IAAI,IAAI,qBAAqB,IAAI;AACxF;;;;AAKA,SAAgB,WAAW,QAA8E;CACvG,OAAO,CAAC,EAAE,OAAO,UAAU,OAAO,eAAe,OAAO;AAC1D;AAEA,SAAgB,SAAS,QAA2B;CAClD,IAAI,OAAO,OAAO,OAAO,OAAO;CAChC,IAAI,OAAO,cAAc,MAAM,OAAO,OAAO,aAAa,SAAS;CACnE,OAAO,OAAO,QAAQ,EAAE,EAAE,SAAS,SAAS,SAAS;AACvD;;;;AAQA,SAAS,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C7I,CAAC;CACH,EAAA,CAAG;CAEH,OAAO;EACL,GAAG;EACH,MAAM,UAAU;EAChB,IAAI,KAAK,UAAU,MAAM,MAAM,KAAK;EACpC,MAAM,KAAK,SAAS,MAAM,UAAU,OAAO;EAC3C;EACA,SAAS;EACT,SAAS;EACT,SAAS;EACT,MAAO,MAAM,QAAQ,CAAC;CACxB;AACF"}
|
|
@@ -307,6 +307,21 @@ declare function createBreak(): BreakNode;
|
|
|
307
307
|
* ```
|
|
308
308
|
*/
|
|
309
309
|
declare function createJsx(value: string): JsxNode;
|
|
310
|
+
/**
|
|
311
|
+
* Creates an `ImportNode` and fills the deprecated `name` and `isTypeOnly` from `names`. A deprecated field
|
|
312
|
+
* that differs from the one `names` gives overrides it.
|
|
313
|
+
*
|
|
314
|
+
* A spread keeps the record of the derived fields only when the original node has one, which a node made
|
|
315
|
+
* from `names` does. For a node made without `names`, or a JSON or `structuredClone` copy, leave out `name`
|
|
316
|
+
* and `isTypeOnly` before you pass new `names`, or the old `name` replaces the new `names` and the old
|
|
317
|
+
* `isTypeOnly` sets their space.
|
|
318
|
+
*/
|
|
319
|
+
declare function createImport(input: ImportInput): ImportNode;
|
|
320
|
+
/**
|
|
321
|
+
* Creates an `ExportNode`, with the deprecated fields of {@link createImport}. For a node made without
|
|
322
|
+
* `names`, or a JSON or `structuredClone` copy, leave out `name` and `isTypeOnly` before you pass new `names`.
|
|
323
|
+
*/
|
|
324
|
+
declare function createExport(input: ExportInput): ExportNode;
|
|
310
325
|
/**
|
|
311
326
|
* Supported file extensions.
|
|
312
327
|
*/
|
|
@@ -523,8 +538,8 @@ type SourceNode = BaseNode & {
|
|
|
523
538
|
* baseName: 'petStore.ts',
|
|
524
539
|
* path: 'src/models/petStore.ts',
|
|
525
540
|
* sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], export: true })],
|
|
526
|
-
* imports: [createImport({ name:
|
|
527
|
-
* exports: [createExport({ name:
|
|
541
|
+
* imports: [createImport({ names: [{ name: 'z' }], path: 'zod' })],
|
|
542
|
+
* exports: [createExport({ names: [{ name: 'Pet' }], path: './petStore' })],
|
|
528
543
|
* })
|
|
529
544
|
* // file.id = SHA256 hash of the path
|
|
530
545
|
* // file.name = 'petStore'
|
|
@@ -602,30 +617,6 @@ type ImportInput = Omit<ImportNode, 'kind' | 'name'> & {
|
|
|
602
617
|
name?: ImportName;
|
|
603
618
|
};
|
|
604
619
|
type ExportInput = Omit<ExportNode, 'kind'>;
|
|
605
|
-
/**
|
|
606
|
-
* Creates an `ImportNode`. A node built from `names` also gets the deprecated fields. A deprecated `name` or
|
|
607
|
-
* `isTypeOnly` that differs from the one `names` gives overrides it, so `{ ...imp, isTypeOnly: true }` still works.
|
|
608
|
-
* Fields a spread copies over unchanged are not overrides, so `{ ...imp, names }` uses the new `names`.
|
|
609
|
-
*
|
|
610
|
-
* @example Named import
|
|
611
|
-
* ```ts
|
|
612
|
-
* createImport({ names: [{ name: 'useState' }], path: 'react' })
|
|
613
|
-
* // import { useState } from 'react'
|
|
614
|
-
* ```
|
|
615
|
-
*/
|
|
616
|
-
declare function createImport(input: ImportInput): ImportNode;
|
|
617
|
-
/**
|
|
618
|
-
* Creates an `ExportNode`. A node built from `names` also gets the deprecated fields. A deprecated `name` or
|
|
619
|
-
* `isTypeOnly` that differs from the one `names` gives overrides it. Fields a spread copies over unchanged are not
|
|
620
|
-
* overrides, so `{ ...exp, names }` uses the new `names`.
|
|
621
|
-
*
|
|
622
|
-
* @example Named export
|
|
623
|
-
* ```ts
|
|
624
|
-
* createExport({ names: [{ name: 'Pet' }], path: './Pet' })
|
|
625
|
-
* // export { Pet } from './Pet'
|
|
626
|
-
* ```
|
|
627
|
-
*/
|
|
628
|
-
declare function createExport(input: ExportInput): ExportNode;
|
|
629
620
|
/**
|
|
630
621
|
* Creates a `SourceNode` representing a fragment of source code within a file.
|
|
631
622
|
*
|
|
@@ -661,8 +652,8 @@ type UserFileNode<TMeta extends object = object> = Omit<FileNode<TMeta>, 'kind'
|
|
|
661
652
|
* baseName: 'petStore.ts',
|
|
662
653
|
* path: 'src/models/petStore.ts',
|
|
663
654
|
* sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],
|
|
664
|
-
* imports: [createImport({ name:
|
|
665
|
-
* exports: [createExport({ name:
|
|
655
|
+
* imports: [createImport({ names: [{ name: 'z' }], path: 'zod' })],
|
|
656
|
+
* exports: [createExport({ names: [{ name: 'Pet' }], path: './petStore' })],
|
|
666
657
|
* })
|
|
667
658
|
* // file.id = SHA256 hash of 'src/models/petStore.ts'
|
|
668
659
|
* // file.name = 'petStore'
|
|
@@ -679,4 +670,4 @@ type UserFileNode<TMeta extends object = object> = Omit<FileNode<TMeta>, 'kind'
|
|
|
679
670
|
* ```
|
|
680
671
|
*/
|
|
681
672
|
declare function createFile<TMeta extends object = object>(input: UserFileNode<TMeta>): FileNode<TMeta>;
|
|
682
|
-
export { createArrowFunction as C, createJsx as D, createFunction as E, createText as O, TypeNode as S, createConst as T, ConstNode as _, ImportNode as a, JsxNode as b, Space as c,
|
|
673
|
+
export { createArrowFunction as C, createJsx as D, createFunction as E, createText as O, TypeNode as S, createConst as T, ConstNode as _, ImportNode as a, JsxNode as b, Space as c, createSource as d, createExport as f, CodeNode as g, BreakNode as h, ImportInput as i, createType as k, UserFileNode as l, ArrowFunctionNode as m, ExportNode as n, ModuleName as o, createImport as p, FileNode as r, SourceNode as s, ExportInput as t, createFile as u, FunctionNode as v, createBreak as w, TextNode as x, JSDocNode as y };
|