@kubb/ast 5.0.0-beta.42 → 5.0.0-beta.44
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/dist/index.cjs +15 -407
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -18
- package/dist/index.js +3 -369
- package/dist/index.js.map +1 -1
- package/dist/{types-CEIHPTfs.d.ts → types-lc8xMmUs.d.ts} +2 -2
- package/dist/types.d.ts +1 -1
- package/dist/utils-BIcKgbbc.js +626 -0
- package/dist/utils-BIcKgbbc.js.map +1 -0
- package/dist/utils-CMRZrT-w.cjs +794 -0
- package/dist/utils-CMRZrT-w.cjs.map +1 -0
- package/dist/utils.cjs +18 -0
- package/dist/utils.d.ts +205 -0
- package/dist/utils.js +2 -0
- package/package.json +7 -3
- package/src/constants.ts +11 -0
- package/src/factory.ts +1 -1
- package/src/index.ts +2 -3
- package/src/resolvers.ts +1 -15
- package/src/signature.ts +1 -1
- package/src/transformers.ts +1 -1
- package/src/types.ts +1 -1
- package/src/{utils.ts → utils/ast.ts} +6 -6
- package/src/utils/index.ts +295 -0
- package/src/refs.ts +0 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk-C0LytTxp.js";
|
|
2
|
-
import { $ as update, $t as ScalarSchemaType, A as createBreak, At as FunctionParameterNode, B as createOperation, Bt as DateSchemaNode, C as PrinterFactoryOptions, Cn as httpMethods, Ct as HttpStatusCode, D as DistributiveOmit, Dt as ParameterNode, E as definePrinter, Et as ParameterLocation, F as createFunctionParameter, Ft as FileNode, G as createProperty, Gt as IntersectionSchemaNode, H as createParameter, Ht as EnumSchemaNode, I as createFunctionParameters, It as ImportNode, J as createSource, Jt as NumberSchemaNode, K as createResponse, Kt as Ipv4SchemaNode, L as createImport, Lt as SourceNode, M as createExport, Mt as ParameterGroupNode, N as createFile, Nt as ParamsTypeNode, O as UserFileNode, Ot as FunctionNodeType, P as createFunction, Pt as ExportNode, Q as syncOptionality, Qt as ScalarSchemaNode, R as createInput, Rt as ArraySchemaNode, S as Printer, Sn as VisitorDepth, St as ResponseNode, T as createPrinterFactory, Tt as StatusCode, U as createParameterGroup, Ut as EnumValueNode, V as createOutput, Vt as DatetimeSchemaNode, W as createParamsType, Wt as FormatStringSchemaNode, X as createText, Xt as PrimitiveSchemaType, Y as createStreamInput, Yt as ObjectSchemaNode, Z as createType, Zt as RefSchemaNode, _ as VisitorContext, _n as TypeDeclarationNode, _t as HttpMethod, a as createDiscriminantNode, an as TimeSchemaNode, at as defineSchemaDialect, b as transform, bn as NodeKind, bt as OperationNodeBase, c as findCircularSchemas, cn as PropertyNode, ct as DedupePlan, d as AsyncVisitor, dn as CodeNode, dt as Node, en as SchemaNode, et as InferSchemaNode, f as CollectOptions, fn as ConstNode, ft as InputMeta, g as Visitor, gn as TextNode, gt as GenericOperationNode, h as TransformOptions, hn as JsxNode, ht as OutputNode, i as containsCircularRef, in as StringSchemaNode, it as SchemaDialect, j as createConst, jt as FunctionParametersNode, k as createArrowFunction, kt as FunctionParamNode, l as isStringType, ln as ArrowFunctionNode, lt as applyDedupe, m as ParentOf, mn as JSDocNode, mt as InputStreamNode, n as caseParams, nn as SchemaType, nt as DispatchRule, o as createOperationParams, on as UnionSchemaNode, ot as BuildDedupePlanOptions, p as CollectVisitor, pn as FunctionNode, pt as InputNode, q as createSchema, qt as Ipv6SchemaNode, r as collectUsedSchemaNames, rn as SpecialSchemaType, rt as dispatch, s as extractStringsFromNodes, sn as UrlSchemaNode, st as DedupeCanonical, t as OperationParamsResolver, tn as SchemaNodeByType, tt as ParserOptions, u as syncSchemaRef, un as BreakNode, ut as buildDedupePlan, v as WalkOptions, vn as TypeNode, vt as HttpOperationNode, w as PrinterPartial, wn as schemaTypes, wt as MediaType, x as walk, xn as ScalarPrimitive, xt as OperationProtocol, y as collect, yn as BaseNode, yt as OperationNode, z as createJsx, zt as ComplexSchemaType } from "./types-
|
|
2
|
+
import { $ as update, $t as ScalarSchemaType, A as createBreak, At as FunctionParameterNode, B as createOperation, Bt as DateSchemaNode, C as PrinterFactoryOptions, Cn as httpMethods, Ct as HttpStatusCode, D as DistributiveOmit, Dt as ParameterNode, E as definePrinter, Et as ParameterLocation, F as createFunctionParameter, Ft as FileNode, G as createProperty, Gt as IntersectionSchemaNode, H as createParameter, Ht as EnumSchemaNode, I as createFunctionParameters, It as ImportNode, J as createSource, Jt as NumberSchemaNode, K as createResponse, Kt as Ipv4SchemaNode, L as createImport, Lt as SourceNode, M as createExport, Mt as ParameterGroupNode, N as createFile, Nt as ParamsTypeNode, O as UserFileNode, Ot as FunctionNodeType, P as createFunction, Pt as ExportNode, Q as syncOptionality, Qt as ScalarSchemaNode, R as createInput, Rt as ArraySchemaNode, S as Printer, Sn as VisitorDepth, St as ResponseNode, T as createPrinterFactory, Tt as StatusCode, U as createParameterGroup, Ut as EnumValueNode, V as createOutput, Vt as DatetimeSchemaNode, W as createParamsType, Wt as FormatStringSchemaNode, X as createText, Xt as PrimitiveSchemaType, Y as createStreamInput, Yt as ObjectSchemaNode, Z as createType, Zt as RefSchemaNode, _ as VisitorContext, _n as TypeDeclarationNode, _t as HttpMethod, a as createDiscriminantNode, an as TimeSchemaNode, at as defineSchemaDialect, b as transform, bn as NodeKind, bt as OperationNodeBase, c as findCircularSchemas, cn as PropertyNode, ct as DedupePlan, d as AsyncVisitor, dn as CodeNode, dt as Node, en as SchemaNode, et as InferSchemaNode, f as CollectOptions, fn as ConstNode, ft as InputMeta, g as Visitor, gn as TextNode, gt as GenericOperationNode, h as TransformOptions, hn as JsxNode, ht as OutputNode, i as containsCircularRef, in as StringSchemaNode, it as SchemaDialect, j as createConst, jt as FunctionParametersNode, k as createArrowFunction, kt as FunctionParamNode, l as isStringType, ln as ArrowFunctionNode, lt as applyDedupe, m as ParentOf, mn as JSDocNode, mt as InputStreamNode, n as caseParams, nn as SchemaType, nt as DispatchRule, o as createOperationParams, on as UnionSchemaNode, ot as BuildDedupePlanOptions, p as CollectVisitor, pn as FunctionNode, pt as InputNode, q as createSchema, qt as Ipv6SchemaNode, r as collectUsedSchemaNames, rn as SpecialSchemaType, rt as dispatch, s as extractStringsFromNodes, sn as UrlSchemaNode, st as DedupeCanonical, t as OperationParamsResolver, tn as SchemaNodeByType, tt as ParserOptions, u as syncSchemaRef, un as BreakNode, ut as buildDedupePlan, v as WalkOptions, vn as TypeNode, vt as HttpOperationNode, w as PrinterPartial, wn as schemaTypes, wt as MediaType, x as walk, xn as ScalarPrimitive, xt as OperationProtocol, y as collect, yn as BaseNode, yt as OperationNode, z as createJsx, zt as ComplexSchemaType } from "./types-lc8xMmUs.js";
|
|
3
3
|
|
|
4
4
|
//#region src/guards.d.ts
|
|
5
5
|
/**
|
|
@@ -68,23 +68,7 @@ declare function isHttpOperationNode(node: OperationNode): node is HttpOperation
|
|
|
68
68
|
*/
|
|
69
69
|
declare const isSchemaNode: (node: unknown) => node is SchemaNode;
|
|
70
70
|
//#endregion
|
|
71
|
-
//#region src/refs.d.ts
|
|
72
|
-
/**
|
|
73
|
-
* Returns the last path segment of a reference string.
|
|
74
|
-
*
|
|
75
|
-
* Example: `#/components/schemas/Pet` becomes `Pet`.
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```ts
|
|
79
|
-
* extractRefName('#/components/schemas/Pet') // 'Pet'
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
declare function extractRefName(ref: string): string;
|
|
83
|
-
//#endregion
|
|
84
71
|
//#region src/resolvers.d.ts
|
|
85
|
-
declare function findDiscriminator(mapping: Record<string, string> | undefined, ref: string | undefined): string | null;
|
|
86
|
-
declare function childName(parentName: string | null | undefined, propName: string): string | null;
|
|
87
|
-
declare function enumPropName(parentName: string | null | undefined, propName: string, enumSuffix: string): string;
|
|
88
72
|
/**
|
|
89
73
|
* Collects import entries for all `ref` schema nodes in `node`.
|
|
90
74
|
*/
|
|
@@ -170,5 +154,5 @@ declare function mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Genera
|
|
|
170
154
|
declare function simplifyUnion(members: Array<SchemaNode>): Array<SchemaNode>;
|
|
171
155
|
declare function setEnumName(propNode: SchemaNode, parentName: string | null | undefined, propName: string, enumSuffix: string): SchemaNode;
|
|
172
156
|
//#endregion
|
|
173
|
-
export { type ArraySchemaNode, type ArrowFunctionNode, type AsyncVisitor, type BaseNode, type BreakNode, type BuildDedupePlanOptions, type CodeNode, type CollectOptions, type CollectVisitor, type ComplexSchemaType, type ConstNode, type DateSchemaNode, type DatetimeSchemaNode, type DedupeCanonical, type DedupePlan, type DispatchRule, type DistributiveOmit, type EnumSchemaNode, type EnumValueNode, type ExportNode, type FileNode, type FormatStringSchemaNode, type FunctionNode, type FunctionNodeType, type FunctionParamNode, type FunctionParameterNode, type FunctionParametersNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type HttpStatusCode, type ImportNode, type InferSchemaNode, type InputMeta, type InputNode, type InputStreamNode, type IntersectionSchemaNode, type Ipv4SchemaNode, type Ipv6SchemaNode, type JSDocNode, type JsxNode, type MediaType, type Node, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type OperationNodeBase, type OperationParamsResolver, type OperationProtocol, type OutputNode, type ParameterGroupNode, type ParameterLocation, type ParameterNode, type ParamsTypeNode, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type ResponseNode, type ScalarPrimitive, type ScalarSchemaNode, type ScalarSchemaType, type SchemaDialect, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type SpecialSchemaType, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TransformOptions, type TypeDeclarationNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, type VisitorDepth, type WalkOptions, applyDedupe, buildDedupePlan, caseParams,
|
|
157
|
+
export { type ArraySchemaNode, type ArrowFunctionNode, type AsyncVisitor, type BaseNode, type BreakNode, type BuildDedupePlanOptions, type CodeNode, type CollectOptions, type CollectVisitor, type ComplexSchemaType, type ConstNode, type DateSchemaNode, type DatetimeSchemaNode, type DedupeCanonical, type DedupePlan, type DispatchRule, type DistributiveOmit, type EnumSchemaNode, type EnumValueNode, type ExportNode, type FileNode, type FormatStringSchemaNode, type FunctionNode, type FunctionNodeType, type FunctionParamNode, type FunctionParameterNode, type FunctionParametersNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type HttpStatusCode, type ImportNode, type InferSchemaNode, type InputMeta, type InputNode, type InputStreamNode, type IntersectionSchemaNode, type Ipv4SchemaNode, type Ipv6SchemaNode, type JSDocNode, type JsxNode, type MediaType, type Node, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type OperationNodeBase, type OperationParamsResolver, type OperationProtocol, type OutputNode, type ParameterGroupNode, type ParameterLocation, type ParameterNode, type ParamsTypeNode, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type ResponseNode, type ScalarPrimitive, type ScalarSchemaNode, type ScalarSchemaType, type SchemaDialect, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type SpecialSchemaType, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TransformOptions, type TypeDeclarationNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, type VisitorDepth, type WalkOptions, applyDedupe, buildDedupePlan, caseParams, collect, collectImports, collectUsedSchemaNames, containsCircularRef, createArrowFunction, createBreak, createConst, createDiscriminantNode, createExport, createFile, createFunction, createFunctionParameter, createFunctionParameters, createImport, createInput, createJsx, createOperation, createOperationParams, createOutput, createParameter, createParameterGroup, createParamsType, createPrinterFactory, createProperty, createResponse, createSchema, createSource, createStreamInput, createText, createType, definePrinter, defineSchemaDialect, dispatch, extractStringsFromNodes, findCircularSchemas, httpMethods, isHttpOperationNode, isInputNode, isOperationNode, isOutputNode, isSchemaNode, isStringType, mergeAdjacentObjectsLazy, narrowSchema, schemaSignature, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, update, walk };
|
|
174
158
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,224 +1,7 @@
|
|
|
1
1
|
import "./chunk-C0LytTxp.js";
|
|
2
|
+
import { S as visitorDepths, _ as isValidVarName, a as enumPropName, b as isScalarPrimitive, h as trimExtName, o as extractRefName, v as camelCase, x as schemaTypes, y as httpMethods } from "./utils-BIcKgbbc.js";
|
|
2
3
|
import { hash } from "node:crypto";
|
|
3
4
|
import path from "node:path";
|
|
4
|
-
//#region src/constants.ts
|
|
5
|
-
const visitorDepths = {
|
|
6
|
-
shallow: "shallow",
|
|
7
|
-
deep: "deep"
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Schema type discriminators used by all AST schema nodes.
|
|
11
|
-
*
|
|
12
|
-
* These values serve as stable discriminators across the AST (e.g., `schema.type === schemaTypes.object`).
|
|
13
|
-
* Grouped by category: primitives (`string`, `number`, `boolean`), structural types (`object`, `array`, `union`),
|
|
14
|
-
* and format-specific types (`date`, `uuid`, `email`). Use `isScalarPrimitive()` to check for scalar types.
|
|
15
|
-
*/
|
|
16
|
-
const schemaTypes = {
|
|
17
|
-
/**
|
|
18
|
-
* Text value.
|
|
19
|
-
*/
|
|
20
|
-
string: "string",
|
|
21
|
-
/**
|
|
22
|
-
* Floating-point number (`float`, `double`).
|
|
23
|
-
*/
|
|
24
|
-
number: "number",
|
|
25
|
-
/**
|
|
26
|
-
* Whole number (`int32`). Use `bigint` for `int64`.
|
|
27
|
-
*/
|
|
28
|
-
integer: "integer",
|
|
29
|
-
/**
|
|
30
|
-
* 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.
|
|
31
|
-
*/
|
|
32
|
-
bigint: "bigint",
|
|
33
|
-
/**
|
|
34
|
-
* Boolean value
|
|
35
|
-
*/
|
|
36
|
-
boolean: "boolean",
|
|
37
|
-
/**
|
|
38
|
-
* Explicit null value.
|
|
39
|
-
*/
|
|
40
|
-
null: "null",
|
|
41
|
-
/**
|
|
42
|
-
* Any value (no type restriction).
|
|
43
|
-
*/
|
|
44
|
-
any: "any",
|
|
45
|
-
/**
|
|
46
|
-
* Unknown value (must be narrowed before usage).
|
|
47
|
-
*/
|
|
48
|
-
unknown: "unknown",
|
|
49
|
-
/**
|
|
50
|
-
* No return value (`void`).
|
|
51
|
-
*/
|
|
52
|
-
void: "void",
|
|
53
|
-
/**
|
|
54
|
-
* Object with named properties.
|
|
55
|
-
*/
|
|
56
|
-
object: "object",
|
|
57
|
-
/**
|
|
58
|
-
* Sequential list of items.
|
|
59
|
-
*/
|
|
60
|
-
array: "array",
|
|
61
|
-
/**
|
|
62
|
-
* Fixed-length list with position-specific items.
|
|
63
|
-
*/
|
|
64
|
-
tuple: "tuple",
|
|
65
|
-
/**
|
|
66
|
-
* "One of" multiple schema members.
|
|
67
|
-
*/
|
|
68
|
-
union: "union",
|
|
69
|
-
/**
|
|
70
|
-
* "All of" multiple schema members.
|
|
71
|
-
*/
|
|
72
|
-
intersection: "intersection",
|
|
73
|
-
/**
|
|
74
|
-
* Enum schema.
|
|
75
|
-
*/
|
|
76
|
-
enum: "enum",
|
|
77
|
-
/**
|
|
78
|
-
* Reference to another schema.
|
|
79
|
-
*/
|
|
80
|
-
ref: "ref",
|
|
81
|
-
/**
|
|
82
|
-
* Calendar date (for example `2026-03-24`).
|
|
83
|
-
*/
|
|
84
|
-
date: "date",
|
|
85
|
-
/**
|
|
86
|
-
* Date-time value (for example `2026-03-24T09:00:00Z`).
|
|
87
|
-
*/
|
|
88
|
-
datetime: "datetime",
|
|
89
|
-
/**
|
|
90
|
-
* Time-only value (for example `09:00:00`).
|
|
91
|
-
*/
|
|
92
|
-
time: "time",
|
|
93
|
-
/**
|
|
94
|
-
* UUID value.
|
|
95
|
-
*/
|
|
96
|
-
uuid: "uuid",
|
|
97
|
-
/**
|
|
98
|
-
* Email address value.
|
|
99
|
-
*/
|
|
100
|
-
email: "email",
|
|
101
|
-
/**
|
|
102
|
-
* URL value.
|
|
103
|
-
*/
|
|
104
|
-
url: "url",
|
|
105
|
-
/**
|
|
106
|
-
* IPv4 address value.
|
|
107
|
-
*/
|
|
108
|
-
ipv4: "ipv4",
|
|
109
|
-
/**
|
|
110
|
-
* IPv6 address value.
|
|
111
|
-
*/
|
|
112
|
-
ipv6: "ipv6",
|
|
113
|
-
/**
|
|
114
|
-
* Binary/blob value.
|
|
115
|
-
*/
|
|
116
|
-
blob: "blob",
|
|
117
|
-
/**
|
|
118
|
-
* Impossible value (`never`).
|
|
119
|
-
*/
|
|
120
|
-
never: "never"
|
|
121
|
-
};
|
|
122
|
-
/**
|
|
123
|
-
* Scalar primitive schema types used for union simplification and type narrowing.
|
|
124
|
-
*
|
|
125
|
-
* Use `isScalarPrimitive()` to safely check whether a type is a scalar primitive.
|
|
126
|
-
*/
|
|
127
|
-
const SCALAR_PRIMITIVE_TYPES = new Set([
|
|
128
|
-
"string",
|
|
129
|
-
"number",
|
|
130
|
-
"integer",
|
|
131
|
-
"bigint",
|
|
132
|
-
"boolean"
|
|
133
|
-
]);
|
|
134
|
-
/**
|
|
135
|
-
* Type guard that returns `true` when `type` is a scalar primitive schema type.
|
|
136
|
-
*
|
|
137
|
-
* Use this to check if a schema type can be directly assigned without wrapping (e.g., `string | number | boolean`).
|
|
138
|
-
*/
|
|
139
|
-
function isScalarPrimitive(type) {
|
|
140
|
-
return SCALAR_PRIMITIVE_TYPES.has(type);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* HTTP method identifiers used by operation nodes.
|
|
144
|
-
*
|
|
145
|
-
* Includes all standard HTTP methods (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, TRACE).
|
|
146
|
-
*/
|
|
147
|
-
const httpMethods = {
|
|
148
|
-
get: "GET",
|
|
149
|
-
post: "POST",
|
|
150
|
-
put: "PUT",
|
|
151
|
-
patch: "PATCH",
|
|
152
|
-
delete: "DELETE",
|
|
153
|
-
head: "HEAD",
|
|
154
|
-
options: "OPTIONS",
|
|
155
|
-
trace: "TRACE"
|
|
156
|
-
};
|
|
157
|
-
//#endregion
|
|
158
|
-
//#region ../../internals/utils/src/casing.ts
|
|
159
|
-
/**
|
|
160
|
-
* Shared implementation for camelCase and PascalCase conversion.
|
|
161
|
-
* Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
|
|
162
|
-
* and capitalizes each word according to `pascal`.
|
|
163
|
-
*
|
|
164
|
-
* When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
|
|
165
|
-
*/
|
|
166
|
-
function toCamelOrPascal(text, pascal) {
|
|
167
|
-
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
168
|
-
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
169
|
-
if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
|
|
170
|
-
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
171
|
-
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Splits `text` on `.` and applies `transformPart` to each segment.
|
|
175
|
-
* The last segment receives `isLast = true`, all earlier segments receive `false`.
|
|
176
|
-
* Segments are joined with `/` to form a file path.
|
|
177
|
-
*
|
|
178
|
-
* Only splits on dots followed by a letter so that version numbers
|
|
179
|
-
* embedded in operationIds (e.g. `v2025.0`) are kept intact.
|
|
180
|
-
*
|
|
181
|
-
* Empty segments are filtered before joining. They arise when the text starts with
|
|
182
|
-
* a dot followed immediately by a letter (e.g. `..Schema` splits into `['..', 'Schema']`
|
|
183
|
-
* and `'..'` transforms to an empty string). Without this filter the join would produce
|
|
184
|
-
* a leading `/`, which `path.resolve` would interpret as an absolute path, allowing
|
|
185
|
-
* generated files to escape the configured output directory.
|
|
186
|
-
*/
|
|
187
|
-
function applyToFileParts(text, transformPart) {
|
|
188
|
-
const parts = text.split(/\.(?=[a-zA-Z])/);
|
|
189
|
-
return parts.map((part, i) => transformPart(part, i === parts.length - 1)).filter(Boolean).join("/");
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Converts `text` to camelCase.
|
|
193
|
-
* When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
|
|
194
|
-
*
|
|
195
|
-
* @example
|
|
196
|
-
* camelCase('hello-world') // 'helloWorld'
|
|
197
|
-
* camelCase('pet.petId', { isFile: true }) // 'pet/petId'
|
|
198
|
-
*/
|
|
199
|
-
function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
200
|
-
if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
|
|
201
|
-
prefix,
|
|
202
|
-
suffix
|
|
203
|
-
} : {}));
|
|
204
|
-
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Converts `text` to PascalCase.
|
|
208
|
-
* When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.
|
|
209
|
-
*
|
|
210
|
-
* @example
|
|
211
|
-
* pascalCase('hello-world') // 'HelloWorld'
|
|
212
|
-
* pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'
|
|
213
|
-
*/
|
|
214
|
-
function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
215
|
-
if (isFile) return applyToFileParts(text, (part, isLast) => isLast ? pascalCase(part, {
|
|
216
|
-
prefix,
|
|
217
|
-
suffix
|
|
218
|
-
}) : camelCase(part));
|
|
219
|
-
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
|
|
220
|
-
}
|
|
221
|
-
//#endregion
|
|
222
5
|
//#region ../../internals/utils/src/promise.ts
|
|
223
6
|
/**
|
|
224
7
|
* Wraps `factory` with a keyed cache backed by the provided store.
|
|
@@ -259,126 +42,6 @@ function memoize(store, factory) {
|
|
|
259
42
|
};
|
|
260
43
|
}
|
|
261
44
|
//#endregion
|
|
262
|
-
//#region ../../internals/utils/src/reserved.ts
|
|
263
|
-
/**
|
|
264
|
-
* JavaScript and Java reserved words.
|
|
265
|
-
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
266
|
-
*/
|
|
267
|
-
const reservedWords = new Set([
|
|
268
|
-
"abstract",
|
|
269
|
-
"arguments",
|
|
270
|
-
"boolean",
|
|
271
|
-
"break",
|
|
272
|
-
"byte",
|
|
273
|
-
"case",
|
|
274
|
-
"catch",
|
|
275
|
-
"char",
|
|
276
|
-
"class",
|
|
277
|
-
"const",
|
|
278
|
-
"continue",
|
|
279
|
-
"debugger",
|
|
280
|
-
"default",
|
|
281
|
-
"delete",
|
|
282
|
-
"do",
|
|
283
|
-
"double",
|
|
284
|
-
"else",
|
|
285
|
-
"enum",
|
|
286
|
-
"eval",
|
|
287
|
-
"export",
|
|
288
|
-
"extends",
|
|
289
|
-
"false",
|
|
290
|
-
"final",
|
|
291
|
-
"finally",
|
|
292
|
-
"float",
|
|
293
|
-
"for",
|
|
294
|
-
"function",
|
|
295
|
-
"goto",
|
|
296
|
-
"if",
|
|
297
|
-
"implements",
|
|
298
|
-
"import",
|
|
299
|
-
"in",
|
|
300
|
-
"instanceof",
|
|
301
|
-
"int",
|
|
302
|
-
"interface",
|
|
303
|
-
"let",
|
|
304
|
-
"long",
|
|
305
|
-
"native",
|
|
306
|
-
"new",
|
|
307
|
-
"null",
|
|
308
|
-
"package",
|
|
309
|
-
"private",
|
|
310
|
-
"protected",
|
|
311
|
-
"public",
|
|
312
|
-
"return",
|
|
313
|
-
"short",
|
|
314
|
-
"static",
|
|
315
|
-
"super",
|
|
316
|
-
"switch",
|
|
317
|
-
"synchronized",
|
|
318
|
-
"this",
|
|
319
|
-
"throw",
|
|
320
|
-
"throws",
|
|
321
|
-
"transient",
|
|
322
|
-
"true",
|
|
323
|
-
"try",
|
|
324
|
-
"typeof",
|
|
325
|
-
"var",
|
|
326
|
-
"void",
|
|
327
|
-
"volatile",
|
|
328
|
-
"while",
|
|
329
|
-
"with",
|
|
330
|
-
"yield",
|
|
331
|
-
"Array",
|
|
332
|
-
"Date",
|
|
333
|
-
"hasOwnProperty",
|
|
334
|
-
"Infinity",
|
|
335
|
-
"isFinite",
|
|
336
|
-
"isNaN",
|
|
337
|
-
"isPrototypeOf",
|
|
338
|
-
"length",
|
|
339
|
-
"Math",
|
|
340
|
-
"name",
|
|
341
|
-
"NaN",
|
|
342
|
-
"Number",
|
|
343
|
-
"Object",
|
|
344
|
-
"prototype",
|
|
345
|
-
"String",
|
|
346
|
-
"toString",
|
|
347
|
-
"undefined",
|
|
348
|
-
"valueOf"
|
|
349
|
-
]);
|
|
350
|
-
/**
|
|
351
|
-
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
352
|
-
*
|
|
353
|
-
* @example
|
|
354
|
-
* ```ts
|
|
355
|
-
* isValidVarName('status') // true
|
|
356
|
-
* isValidVarName('class') // false (reserved word)
|
|
357
|
-
* isValidVarName('42foo') // false (starts with digit)
|
|
358
|
-
* ```
|
|
359
|
-
*/
|
|
360
|
-
function isValidVarName(name) {
|
|
361
|
-
if (!name || reservedWords.has(name)) return false;
|
|
362
|
-
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
363
|
-
}
|
|
364
|
-
//#endregion
|
|
365
|
-
//#region ../../internals/utils/src/string.ts
|
|
366
|
-
/**
|
|
367
|
-
* Strips the file extension from a path or file name.
|
|
368
|
-
* Only removes the last `.ext` segment when the dot is not part of a directory name.
|
|
369
|
-
*
|
|
370
|
-
* @example
|
|
371
|
-
* trimExtName('petStore.ts') // 'petStore'
|
|
372
|
-
* trimExtName('/src/models/pet.ts') // '/src/models/pet'
|
|
373
|
-
* trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'
|
|
374
|
-
* trimExtName('noExtension') // 'noExtension'
|
|
375
|
-
*/
|
|
376
|
-
function trimExtName(text) {
|
|
377
|
-
const dotIndex = text.lastIndexOf(".");
|
|
378
|
-
if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
|
|
379
|
-
return text;
|
|
380
|
-
}
|
|
381
|
-
//#endregion
|
|
382
45
|
//#region src/guards.ts
|
|
383
46
|
/**
|
|
384
47
|
* Narrows a `SchemaNode` to the variant that matches `type`.
|
|
@@ -453,21 +116,6 @@ function isHttpOperationNode(node) {
|
|
|
453
116
|
*/
|
|
454
117
|
const isSchemaNode = isKind("Schema");
|
|
455
118
|
//#endregion
|
|
456
|
-
//#region src/refs.ts
|
|
457
|
-
/**
|
|
458
|
-
* Returns the last path segment of a reference string.
|
|
459
|
-
*
|
|
460
|
-
* Example: `#/components/schemas/Pet` becomes `Pet`.
|
|
461
|
-
*
|
|
462
|
-
* @example
|
|
463
|
-
* ```ts
|
|
464
|
-
* extractRefName('#/components/schemas/Pet') // 'Pet'
|
|
465
|
-
* ```
|
|
466
|
-
*/
|
|
467
|
-
function extractRefName(ref) {
|
|
468
|
-
return ref.split("/").at(-1) ?? ref;
|
|
469
|
-
}
|
|
470
|
-
//#endregion
|
|
471
119
|
//#region src/visitor.ts
|
|
472
120
|
/**
|
|
473
121
|
* Creates a small async concurrency limiter.
|
|
@@ -709,7 +357,7 @@ function collect(node, options) {
|
|
|
709
357
|
return Array.from(collectLazy(node, options));
|
|
710
358
|
}
|
|
711
359
|
//#endregion
|
|
712
|
-
//#region src/utils.ts
|
|
360
|
+
//#region src/utils/ast.ts
|
|
713
361
|
const plainStringTypes = new Set([
|
|
714
362
|
"string",
|
|
715
363
|
"uuid",
|
|
@@ -2531,20 +2179,6 @@ function createPrinterFactory(getKey) {
|
|
|
2531
2179
|
}
|
|
2532
2180
|
//#endregion
|
|
2533
2181
|
//#region src/resolvers.ts
|
|
2534
|
-
function findDiscriminator(mapping, ref) {
|
|
2535
|
-
if (!mapping || !ref) return null;
|
|
2536
|
-
return Object.entries(mapping).find(([, value]) => value === ref)?.[0] ?? null;
|
|
2537
|
-
}
|
|
2538
|
-
function childName(parentName, propName) {
|
|
2539
|
-
return parentName ? pascalCase([parentName, propName].join(" ")) : null;
|
|
2540
|
-
}
|
|
2541
|
-
function enumPropName(parentName, propName, enumSuffix) {
|
|
2542
|
-
return pascalCase([
|
|
2543
|
-
parentName,
|
|
2544
|
-
propName,
|
|
2545
|
-
enumSuffix
|
|
2546
|
-
].filter(Boolean).join(" "));
|
|
2547
|
-
}
|
|
2548
2182
|
/**
|
|
2549
2183
|
* Collects import entries for all `ref` schema nodes in `node`.
|
|
2550
2184
|
*/
|
|
@@ -2666,6 +2300,6 @@ function setEnumName(propNode, parentName, propName, enumSuffix) {
|
|
|
2666
2300
|
return propNode;
|
|
2667
2301
|
}
|
|
2668
2302
|
//#endregion
|
|
2669
|
-
export { applyDedupe, buildDedupePlan, caseParams,
|
|
2303
|
+
export { applyDedupe, buildDedupePlan, caseParams, collect, collectImports, collectUsedSchemaNames, containsCircularRef, createArrowFunction, createBreak, createConst, createDiscriminantNode, createExport, createFile, createFunction, createFunctionParameter, createFunctionParameters, createImport, createInput, createJsx, createOperation, createOperationParams, createOutput, createParameter, createParameterGroup, createParamsType, createPrinterFactory, createProperty, createResponse, createSchema, createSource, createStreamInput, createText, createType, definePrinter, defineSchemaDialect, dispatch, extractStringsFromNodes, findCircularSchemas, httpMethods, isHttpOperationNode, isInputNode, isOperationNode, isOutputNode, isSchemaNode, isStringType, mergeAdjacentObjectsLazy, narrowSchema, schemaSignature, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, update, walk };
|
|
2670
2304
|
|
|
2671
2305
|
//# sourceMappingURL=index.js.map
|