@kubb/ast 5.0.0-beta.94 → 5.0.0-beta.95
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 +42 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +37 -20
- package/dist/index.js +41 -8
- package/dist/index.js.map +1 -1
- package/dist/{types-CsAwiskn.d.ts → types-CqXMgUzC.d.ts} +24 -18
- package/dist/types.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { n as __name, t as __exportAll } from "./rolldown-runtime-CNktS9qV.js";
|
|
2
|
-
import { $ as sourceDef, $t as NodeDef, A as StatusCode, At as BreakNode, B as parameterDef, Bt as constDef, C as GenericOperationNode, Ct as PropertyNode, D as createOperation, Dt as InferSchemaNode, E as OperationNode, Et as propertyDef, F as requestBodyDef, Ft as JsxNode, G as UserFileNode, Gt as createJsx, H as FileNode, Ht as createBreak, I as ParameterLocation, It as TextNode, J as createImport, Jt as functionDef, K as createExport, Kt as createText, L as ParameterNode, Lt as TypeNode, M as responseDef, Mt as ConstNode, N as RequestBodyNode, Nt as FunctionNode, O as operationDef, Ot as ParserOptions, P as createRequestBody, Pt as JSDocNode, Q as importDef, Qt as DistributiveOmit, R as ParameterStyle, Rt as arrowFunctionDef, S as inputDef, St as schemaDef, T as HttpOperationNode, Tt as createProperty, U as ImportNode, Ut as createConst, V as ExportNode, Vt as createArrowFunction, W as SourceNode, Wt as createFunction, X as exportDef, Xt as textDef, Y as createSource, Yt as jsxDef, Z as fileDef, Zt as typeDef, _ as createOutput, _t as StringSchemaNode, a as Enforce, at as DatetimeSchemaNode, b as InputNode, bt as UrlSchemaNode, c as composeMacros, ct as NumberSchemaNode, d as Visitor, dt as RefSchemaNode, en as defineNode, et as ContentNode, f as VisitorContext, ft as ScalarSchemaNode, g as OutputNode, gt as SchemaType, h as Node, ht as SchemaNodeByType, i as createPrinter, it as DateSchemaNode, j as createResponse, jt as CodeNode, k as ResponseNode, kt as ArrowFunctionNode, l as defineMacro, lt as ObjectSchemaNode, m as transform, mt as SchemaNode, n as PrinterFactoryOptions, nn as NodeKind, nt as createContent, o as Macro, ot as EnumSchemaNode, p as collect, pt as ScalarSchemaType, q as createFile, qt as createType, r as PrinterPartial, rn as schemaTypes, rt as ArraySchemaNode, s as applyMacros, st as IntersectionSchemaNode, t as Printer, tn as BaseNode, tt as contentDef, u as ParentOf, ut as PrimitiveSchemaType, v as outputDef, vt as TimeSchemaNode, w as HttpMethod, wt as UserPropertyNode, x as createInput, xt as createSchema, y as InputMeta, yt as UnionSchemaNode, z as createParameter, zt as breakDef } from "./types-
|
|
3
|
-
|
|
2
|
+
import { $ as sourceDef, $t as NodeDef, A as StatusCode, At as BreakNode, B as parameterDef, Bt as constDef, C as GenericOperationNode, Ct as PropertyNode, D as createOperation, Dt as InferSchemaNode, E as OperationNode, Et as propertyDef, F as requestBodyDef, Ft as JsxNode, G as UserFileNode, Gt as createJsx, H as FileNode, Ht as createBreak, I as ParameterLocation, It as TextNode, J as createImport, Jt as functionDef, K as createExport, Kt as createText, L as ParameterNode, Lt as TypeNode, M as responseDef, Mt as ConstNode, N as RequestBodyNode, Nt as FunctionNode, O as operationDef, Ot as ParserOptions, P as createRequestBody, Pt as JSDocNode, Q as importDef, Qt as DistributiveOmit, R as ParameterStyle, Rt as arrowFunctionDef, S as inputDef, St as schemaDef, T as HttpOperationNode, Tt as createProperty, U as ImportNode, Ut as createConst, V as ExportNode, Vt as createArrowFunction, W as SourceNode, Wt as createFunction, X as exportDef, Xt as textDef, Y as createSource, Yt as jsxDef, Z as fileDef, Zt as typeDef, _ as createOutput, _t as StringSchemaNode, a as Enforce, at as DatetimeSchemaNode, b as InputNode, bt as UrlSchemaNode, c as composeMacros, ct as NumberSchemaNode, d as Visitor, dt as RefSchemaNode, en as defineNode, et as ContentNode, f as VisitorContext, ft as ScalarSchemaNode, g as OutputNode, gt as SchemaType, h as Node, ht as SchemaNodeByType, i as createPrinter, it as DateSchemaNode, j as createResponse, jt as CodeNode, k as ResponseNode, kt as ArrowFunctionNode, l as defineMacro, lt as ObjectSchemaNode, m as transform, mt as SchemaNode, n as PrinterFactoryOptions, nn as NodeKind, nt as createContent, o as Macro, ot as EnumSchemaNode, p as collect, pt as ScalarSchemaType, q as createFile, qt as createType, r as PrinterPartial, rn as schemaTypes, rt as ArraySchemaNode, s as applyMacros, st as IntersectionSchemaNode, t as Printer, tn as BaseNode, tt as contentDef, u as ParentOf, ut as PrimitiveSchemaType, v as outputDef, vt as TimeSchemaNode, w as HttpMethod, wt as UserPropertyNode, x as createInput, xt as createSchema, y as InputMeta, yt as UnionSchemaNode, z as createParameter, zt as breakDef } from "./types-CqXMgUzC.js";
|
|
4
3
|
//#region src/guards.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Narrows a `SchemaNode` to the variant that matches `type`.
|
|
@@ -83,6 +82,20 @@ declare function mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Genera
|
|
|
83
82
|
* `extractRefName('#/components/schemas/Pet') // 'Pet'`
|
|
84
83
|
*/
|
|
85
84
|
declare function extractRefName(ref: string): string;
|
|
85
|
+
/**
|
|
86
|
+
* Resolves the emitted name of the schema a ref node points at. Prefers `targetName` (set when
|
|
87
|
+
* the referenced schema was renamed, e.g. to break a collision), then the last segment of `ref`,
|
|
88
|
+
* then `name`, then the nested `schema.name`.
|
|
89
|
+
*
|
|
90
|
+
* Returns `null` for non-ref nodes or when no name resolves.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`
|
|
94
|
+
*
|
|
95
|
+
* @example Collision-renamed target
|
|
96
|
+
* `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Order', targetName: 'OrderSchema' }) // 'OrderSchema'`
|
|
97
|
+
*/
|
|
98
|
+
declare function resolveRefName(node: SchemaNode | null | undefined): string | null;
|
|
86
99
|
/**
|
|
87
100
|
* Builds a PascalCase child schema name by joining a parent name and property name.
|
|
88
101
|
* Returns `null` when there is no parent to nest under.
|
|
@@ -165,10 +178,7 @@ declare function findCircularSchemas(schemas: ReadonlyArray<SchemaNode>): Set<st
|
|
|
165
178
|
*
|
|
166
179
|
* @note Stops at the first matching circular ref.
|
|
167
180
|
*/
|
|
168
|
-
declare function containsCircularRef(node: SchemaNode | undefined, {
|
|
169
|
-
circularSchemas,
|
|
170
|
-
excludeName
|
|
171
|
-
}: {
|
|
181
|
+
declare function containsCircularRef(node: SchemaNode | undefined, { circularSchemas, excludeName }: {
|
|
172
182
|
circularSchemas: ReadonlySet<string>;
|
|
173
183
|
excludeName?: string;
|
|
174
184
|
}): boolean;
|
|
@@ -233,7 +243,7 @@ declare function mapSchemaMembers<TOutput>(node: UnionSchemaNode | IntersectionS
|
|
|
233
243
|
declare function mapSchemaItems<TOutput>(node: ArraySchemaNode, transform: SchemaTransform<TOutput>): Array<MappedSchema<TOutput>>;
|
|
234
244
|
//#endregion
|
|
235
245
|
//#region src/macros/macroDiscriminatorEnum.d.ts
|
|
236
|
-
type Props$
|
|
246
|
+
type Props$2 = {
|
|
237
247
|
propertyName: string;
|
|
238
248
|
values: Array<string>;
|
|
239
249
|
enumName?: string;
|
|
@@ -248,14 +258,10 @@ type Props$1 = {
|
|
|
248
258
|
* const next = applyMacros(objectSchema, [macro], { depth: 'shallow' })
|
|
249
259
|
* ```
|
|
250
260
|
*/
|
|
251
|
-
declare function macroDiscriminatorEnum({
|
|
252
|
-
propertyName,
|
|
253
|
-
values,
|
|
254
|
-
enumName
|
|
255
|
-
}: Props$1): Macro;
|
|
261
|
+
declare function macroDiscriminatorEnum({ propertyName, values, enumName }: Props$2): Macro;
|
|
256
262
|
//#endregion
|
|
257
263
|
//#region src/macros/macroEnumName.d.ts
|
|
258
|
-
type Props = {
|
|
264
|
+
type Props$1 = {
|
|
259
265
|
parentName: string | null | undefined;
|
|
260
266
|
propName: string;
|
|
261
267
|
enumSuffix: string;
|
|
@@ -270,11 +276,22 @@ type Props = {
|
|
|
270
276
|
* const named = applyMacros(propSchema, [macro], { depth: 'shallow' })
|
|
271
277
|
* ```
|
|
272
278
|
*/
|
|
273
|
-
declare function macroEnumName({
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
279
|
+
declare function macroEnumName({ parentName, propName, enumSuffix }: Props$1): Macro;
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/macros/macroRenameSchema.d.ts
|
|
282
|
+
type Props = {
|
|
283
|
+
from: string;
|
|
284
|
+
to: string;
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* Builds a macro that renames a schema consistently: the declaration (`name`) and every ref
|
|
288
|
+
* pointing at it (`targetName`) change together, so imports and printed references stay in
|
|
289
|
+
* sync. Renaming only one side by hand produces imports for files that are never generated.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* `const macro = macroRenameSchema({ from: 'Order', to: 'StoreOrder' })`
|
|
293
|
+
*/
|
|
294
|
+
declare function macroRenameSchema({ from, to }: Props): Macro;
|
|
278
295
|
//#endregion
|
|
279
296
|
//#region src/macros/macroSimplifyUnion.d.ts
|
|
280
297
|
/**
|
|
@@ -382,8 +399,8 @@ declare const nodeDefs: (NodeDef<InputNode, Partial<Omit<InputNode, "kind">>> |
|
|
|
382
399
|
type: "ipv6";
|
|
383
400
|
}) | ScalarSchemaNode, "kind">> | NodeDef<PropertyNode, UserPropertyNode> | NodeDef<ParameterNode, Pick<ParameterNode, "schema" | "name" | "in"> & Partial<Omit<ParameterNode, "schema" | "kind" | "name" | "in">>> | NodeDef<ConstNode, Omit<ConstNode, "kind">> | NodeDef<TypeNode, Omit<TypeNode, "kind">> | NodeDef<FunctionNode, Omit<FunctionNode, "kind">> | NodeDef<ArrowFunctionNode, Omit<ArrowFunctionNode, "kind">> | NodeDef<TextNode, string> | NodeDef<BreakNode, void> | NodeDef<JsxNode, string> | NodeDef<ImportNode, Omit<ImportNode, "kind">> | NodeDef<ExportNode, Omit<ExportNode, "kind">> | NodeDef<SourceNode, Omit<SourceNode, "kind">> | NodeDef<FileNode<object>, Omit<FileNode<object>, "kind">>)[];
|
|
384
401
|
declare namespace exports_d_exports {
|
|
385
|
-
export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateSchemaNode, DatetimeSchemaNode, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InferSchemaNode, InputMeta, InputNode, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeDef, NodeKind, NumberSchemaNode, ObjectSchemaNode, OperationNode, OutputNode, ParameterLocation, ParameterNode, ParameterStyle, ParentOf, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, arrowFunctionDef, breakDef, childName, collect, collectUsedSchemaNames, combineExports, combineImports, combineSources, composeMacros, constDef, containsCircularRef, contentDef, createPrinter, defineMacro, defineNode, enumPropName, exportDef, extractRefName, extractStringsFromNodes, factory_d_exports as factory, fileDef, findCircularSchemas, functionDef, importDef, inputDef, isHttpOperationNode, isStringType, jsxDef, macroDiscriminatorEnum, macroEnumName, macroSimplifyUnion, mapSchemaItems, mapSchemaMembers, mapSchemaProperties, mergeAdjacentObjectsLazy, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, sourceDef, syncSchemaRef, textDef, transform, typeDef };
|
|
402
|
+
export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateSchemaNode, DatetimeSchemaNode, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InferSchemaNode, InputMeta, InputNode, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeDef, NodeKind, NumberSchemaNode, ObjectSchemaNode, OperationNode, OutputNode, ParameterLocation, ParameterNode, ParameterStyle, ParentOf, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, arrowFunctionDef, breakDef, childName, collect, collectUsedSchemaNames, combineExports, combineImports, combineSources, composeMacros, constDef, containsCircularRef, contentDef, createPrinter, defineMacro, defineNode, enumPropName, exportDef, extractRefName, extractStringsFromNodes, factory_d_exports as factory, fileDef, findCircularSchemas, functionDef, importDef, inputDef, isHttpOperationNode, isStringType, jsxDef, macroDiscriminatorEnum, macroEnumName, macroRenameSchema, macroSimplifyUnion, mapSchemaItems, mapSchemaMembers, mapSchemaProperties, mergeAdjacentObjectsLazy, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, resolveRefName, responseDef, schemaDef, schemaTypes, sourceDef, syncSchemaRef, textDef, transform, typeDef };
|
|
386
403
|
}
|
|
387
404
|
//#endregion
|
|
388
|
-
export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateSchemaNode, type DatetimeSchemaNode, type DistributiveOmit, type Enforce, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InferSchemaNode, type InputMeta, type InputNode, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeDef, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type OutputNode, type ParameterLocation, type ParameterNode, type ParameterStyle, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, applyMacros, arrowFunctionDef, exports_d_exports as ast, breakDef, childName, collect, collectUsedSchemaNames, combineExports, combineImports, combineSources, composeMacros, constDef, containsCircularRef, contentDef, createPrinter, defineMacro, defineNode, enumPropName, exportDef, extractRefName, extractStringsFromNodes, factory_d_exports as factory, fileDef, findCircularSchemas, functionDef, importDef, inputDef, isHttpOperationNode, isStringType, jsxDef, macroDiscriminatorEnum, macroEnumName, macroSimplifyUnion, mapSchemaItems, mapSchemaMembers, mapSchemaProperties, mergeAdjacentObjectsLazy, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, sourceDef, syncSchemaRef, textDef, transform, typeDef };
|
|
405
|
+
export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateSchemaNode, type DatetimeSchemaNode, type DistributiveOmit, type Enforce, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InferSchemaNode, type InputMeta, type InputNode, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeDef, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type OutputNode, type ParameterLocation, type ParameterNode, type ParameterStyle, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, applyMacros, arrowFunctionDef, exports_d_exports as ast, breakDef, childName, collect, collectUsedSchemaNames, combineExports, combineImports, combineSources, composeMacros, constDef, containsCircularRef, contentDef, createPrinter, defineMacro, defineNode, enumPropName, exportDef, extractRefName, extractStringsFromNodes, factory_d_exports as factory, fileDef, findCircularSchemas, functionDef, importDef, inputDef, isHttpOperationNode, isStringType, jsxDef, macroDiscriminatorEnum, macroEnumName, macroRenameSchema, macroSimplifyUnion, mapSchemaItems, mapSchemaMembers, mapSchemaProperties, mergeAdjacentObjectsLazy, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, resolveRefName, responseDef, schemaDef, schemaTypes, sourceDef, syncSchemaRef, textDef, transform, typeDef };
|
|
389
406
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1378,16 +1378,21 @@ function extractRefName(ref) {
|
|
|
1378
1378
|
return ref.split("/").at(-1) ?? ref;
|
|
1379
1379
|
}
|
|
1380
1380
|
/**
|
|
1381
|
-
* Resolves the
|
|
1382
|
-
*
|
|
1381
|
+
* Resolves the emitted name of the schema a ref node points at. Prefers `targetName` (set when
|
|
1382
|
+
* the referenced schema was renamed, e.g. to break a collision), then the last segment of `ref`,
|
|
1383
|
+
* then `name`, then the nested `schema.name`.
|
|
1383
1384
|
*
|
|
1384
1385
|
* Returns `null` for non-ref nodes or when no name resolves.
|
|
1385
1386
|
*
|
|
1386
1387
|
* @example
|
|
1387
1388
|
* `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`
|
|
1389
|
+
*
|
|
1390
|
+
* @example Collision-renamed target
|
|
1391
|
+
* `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Order', targetName: 'OrderSchema' }) // 'OrderSchema'`
|
|
1388
1392
|
*/
|
|
1389
1393
|
function resolveRefName(node) {
|
|
1390
1394
|
if (!node || node.type !== "ref") return null;
|
|
1395
|
+
if (node.targetName) return node.targetName;
|
|
1391
1396
|
if (node.ref) return extractRefName(node.ref);
|
|
1392
1397
|
return node.name ?? node.schema?.name ?? null;
|
|
1393
1398
|
}
|
|
@@ -1495,10 +1500,6 @@ function collectReferencedSchemaNames(node, out = /* @__PURE__ */ new Set()) {
|
|
|
1495
1500
|
for (const name of collectSchemaRefs(node)) out.add(name);
|
|
1496
1501
|
return out;
|
|
1497
1502
|
}
|
|
1498
|
-
/**
|
|
1499
|
-
* Memoized two-level cache keyed first on the operations array, then on the schemas array.
|
|
1500
|
-
*/
|
|
1501
|
-
const collectUsedSchemaNamesMemo = memoize(/* @__PURE__ */ new WeakMap(), (ops) => memoize(/* @__PURE__ */ new WeakMap(), (schemas) => computeUsedSchemaNames(ops, schemas)));
|
|
1502
1503
|
function computeUsedSchemaNames(operations, schemas) {
|
|
1503
1504
|
const schemaMap = /* @__PURE__ */ new Map();
|
|
1504
1505
|
for (const schema of schemas) if (schema.name) schemaMap.set(schema.name, schema);
|
|
@@ -1538,7 +1539,7 @@ function computeUsedSchemaNames(operations, schemas) {
|
|
|
1538
1539
|
* ```
|
|
1539
1540
|
*/
|
|
1540
1541
|
function collectUsedSchemaNames(operations, schemas) {
|
|
1541
|
-
return
|
|
1542
|
+
return computeUsedSchemaNames(operations, schemas);
|
|
1542
1543
|
}
|
|
1543
1544
|
const EMPTY_CIRCULAR_SET = /* @__PURE__ */ new Set();
|
|
1544
1545
|
const findCircularSchemasMemo = memoize(/* @__PURE__ */ new WeakMap(), (schemas) => {
|
|
@@ -1702,6 +1703,36 @@ function macroEnumName({ parentName, propName, enumSuffix }) {
|
|
|
1702
1703
|
});
|
|
1703
1704
|
}
|
|
1704
1705
|
//#endregion
|
|
1706
|
+
//#region src/macros/macroRenameSchema.ts
|
|
1707
|
+
/**
|
|
1708
|
+
* Builds a macro that renames a schema consistently: the declaration (`name`) and every ref
|
|
1709
|
+
* pointing at it (`targetName`) change together, so imports and printed references stay in
|
|
1710
|
+
* sync. Renaming only one side by hand produces imports for files that are never generated.
|
|
1711
|
+
*
|
|
1712
|
+
* @example
|
|
1713
|
+
* `const macro = macroRenameSchema({ from: 'Order', to: 'StoreOrder' })`
|
|
1714
|
+
*/
|
|
1715
|
+
function macroRenameSchema({ from, to }) {
|
|
1716
|
+
return defineMacro({
|
|
1717
|
+
name: "rename-schema",
|
|
1718
|
+
schema(node) {
|
|
1719
|
+
const refNode = narrowSchema(node, "ref");
|
|
1720
|
+
if (!refNode) return node.name === from ? {
|
|
1721
|
+
...node,
|
|
1722
|
+
name: to
|
|
1723
|
+
} : void 0;
|
|
1724
|
+
const renamesDeclaration = refNode.name === from;
|
|
1725
|
+
const renamesTarget = resolveRefName(refNode) === from;
|
|
1726
|
+
if (!renamesDeclaration && !renamesTarget) return void 0;
|
|
1727
|
+
return {
|
|
1728
|
+
...refNode,
|
|
1729
|
+
...renamesDeclaration ? { name: to } : {},
|
|
1730
|
+
...renamesTarget ? { targetName: to } : {}
|
|
1731
|
+
};
|
|
1732
|
+
}
|
|
1733
|
+
});
|
|
1734
|
+
}
|
|
1735
|
+
//#endregion
|
|
1705
1736
|
//#region src/macros/macroSimplifyUnion.ts
|
|
1706
1737
|
/**
|
|
1707
1738
|
* Scalar primitive schema types used for union simplification and type narrowing.
|
|
@@ -1837,6 +1868,7 @@ var exports_exports = /* @__PURE__ */ __exportAll({
|
|
|
1837
1868
|
jsxDef: () => jsxDef,
|
|
1838
1869
|
macroDiscriminatorEnum: () => macroDiscriminatorEnum,
|
|
1839
1870
|
macroEnumName: () => macroEnumName,
|
|
1871
|
+
macroRenameSchema: () => macroRenameSchema,
|
|
1840
1872
|
macroSimplifyUnion: () => macroSimplifyUnion,
|
|
1841
1873
|
mapSchemaItems: () => mapSchemaItems,
|
|
1842
1874
|
mapSchemaMembers: () => mapSchemaMembers,
|
|
@@ -1850,6 +1882,7 @@ var exports_exports = /* @__PURE__ */ __exportAll({
|
|
|
1850
1882
|
parameterDef: () => parameterDef,
|
|
1851
1883
|
propertyDef: () => propertyDef,
|
|
1852
1884
|
requestBodyDef: () => requestBodyDef,
|
|
1885
|
+
resolveRefName: () => resolveRefName,
|
|
1853
1886
|
responseDef: () => responseDef,
|
|
1854
1887
|
schemaDef: () => schemaDef,
|
|
1855
1888
|
schemaTypes: () => schemaTypes,
|
|
@@ -1860,6 +1893,6 @@ var exports_exports = /* @__PURE__ */ __exportAll({
|
|
|
1860
1893
|
typeDef: () => typeDef
|
|
1861
1894
|
});
|
|
1862
1895
|
//#endregion
|
|
1863
|
-
export { applyMacros, arrowFunctionDef, exports_exports as ast, breakDef, childName, collect, collectUsedSchemaNames, combineExports, combineImports, combineSources, composeMacros, constDef, containsCircularRef, contentDef, createPrinter, defineMacro, defineNode, enumPropName, exportDef, extractRefName, extractStringsFromNodes, factory_exports as factory, fileDef, findCircularSchemas, functionDef, importDef, inputDef, isHttpOperationNode, isStringType, jsxDef, macroDiscriminatorEnum, macroEnumName, macroSimplifyUnion, mapSchemaItems, mapSchemaMembers, mapSchemaProperties, mergeAdjacentObjectsLazy, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, sourceDef, syncSchemaRef, textDef, transform, typeDef };
|
|
1896
|
+
export { applyMacros, arrowFunctionDef, exports_exports as ast, breakDef, childName, collect, collectUsedSchemaNames, combineExports, combineImports, combineSources, composeMacros, constDef, containsCircularRef, contentDef, createPrinter, defineMacro, defineNode, enumPropName, exportDef, extractRefName, extractStringsFromNodes, factory_exports as factory, fileDef, findCircularSchemas, functionDef, importDef, inputDef, isHttpOperationNode, isStringType, jsxDef, macroDiscriminatorEnum, macroEnumName, macroRenameSchema, macroSimplifyUnion, mapSchemaItems, mapSchemaMembers, mapSchemaProperties, mergeAdjacentObjectsLazy, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, resolveRefName, responseDef, schemaDef, schemaTypes, sourceDef, syncSchemaRef, textDef, transform, typeDef };
|
|
1864
1897
|
|
|
1865
1898
|
//# sourceMappingURL=index.js.map
|