@kubb/ast 5.0.0-beta.7 → 5.0.0-beta.71
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/LICENSE +17 -10
- package/README.md +53 -27
- package/dist/defineMacro-5Dvct8k_.cjs +114 -0
- package/dist/defineMacro-5Dvct8k_.cjs.map +1 -0
- package/dist/defineMacro-BXpTwp0y.d.ts +466 -0
- package/dist/defineMacro-VfsvblGi.js +98 -0
- package/dist/defineMacro-VfsvblGi.js.map +1 -0
- package/dist/index-DJEyS5y6.d.ts +2428 -0
- package/dist/index.cjs +198 -2239
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +98 -3400
- package/dist/index.js +149 -2160
- package/dist/index.js.map +1 -1
- package/dist/macros.cjs +130 -0
- package/dist/macros.cjs.map +1 -0
- package/dist/macros.d.ts +61 -0
- package/dist/macros.js +128 -0
- package/dist/macros.js.map +1 -0
- package/dist/operationParams-BaY12i2I.d.ts +148 -0
- package/dist/refs-D18OeCgb.js +117 -0
- package/dist/refs-D18OeCgb.js.map +1 -0
- package/dist/refs-DuP3_Leg.cjs +157 -0
- package/dist/refs-DuP3_Leg.cjs.map +1 -0
- package/dist/rolldown-runtime-CNktS9qV.js +17 -0
- package/dist/types-BsP1SK9j.d.ts +244 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.js +1 -0
- package/dist/utils.cjs +803 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.ts +354 -0
- package/dist/utils.js +777 -0
- package/dist/utils.js.map +1 -0
- package/dist/visitor-CQdSiClY.cjs +1749 -0
- package/dist/visitor-CQdSiClY.cjs.map +1 -0
- package/dist/visitor-dcVC5TOW.js +1313 -0
- package/dist/visitor-dcVC5TOW.js.map +1 -0
- package/package.json +17 -5
- package/dist/chunk--u3MIqq1.js +0 -8
- package/src/constants.ts +0 -228
- package/src/factory.ts +0 -742
- package/src/guards.ts +0 -110
- package/src/index.ts +0 -46
- package/src/infer.ts +0 -130
- package/src/mocks.ts +0 -176
- package/src/nodes/base.ts +0 -56
- package/src/nodes/code.ts +0 -304
- package/src/nodes/file.ts +0 -230
- package/src/nodes/function.ts +0 -223
- package/src/nodes/http.ts +0 -119
- package/src/nodes/index.ts +0 -86
- package/src/nodes/operation.ts +0 -111
- package/src/nodes/output.ts +0 -26
- package/src/nodes/parameter.ts +0 -41
- package/src/nodes/property.ts +0 -34
- package/src/nodes/response.ts +0 -43
- package/src/nodes/root.ts +0 -64
- package/src/nodes/schema.ts +0 -656
- package/src/printer.ts +0 -250
- package/src/refs.ts +0 -67
- package/src/resolvers.ts +0 -45
- package/src/transformers.ts +0 -159
- package/src/types.ts +0 -70
- package/src/utils.ts +0 -915
- package/src/visitor.ts +0 -592
package/dist/macros.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import "./rolldown-runtime-CNktS9qV.js";
|
|
2
|
+
import { lt as narrowSchema, o as createSchema, u as createProperty } from "./visitor-dcVC5TOW.js";
|
|
3
|
+
import { r as defineMacro } from "./defineMacro-VfsvblGi.js";
|
|
4
|
+
import { n as enumPropName } from "./refs-D18OeCgb.js";
|
|
5
|
+
//#region src/macros/macroDiscriminatorEnum.ts
|
|
6
|
+
/**
|
|
7
|
+
* Builds a macro that replaces a discriminator property's schema with a string enum of the given
|
|
8
|
+
* values. Object schemas that lack the property are returned unchanged.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const macro = macroDiscriminatorEnum({ propertyName: 'type', values: ['dog', 'cat'] })
|
|
13
|
+
* const next = applyMacros(objectSchema, [macro], { depth: 'shallow' })
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
function macroDiscriminatorEnum({ propertyName, values, enumName }) {
|
|
17
|
+
return defineMacro({
|
|
18
|
+
name: "discriminator-enum",
|
|
19
|
+
schema(node) {
|
|
20
|
+
const objectNode = narrowSchema(node, "object");
|
|
21
|
+
if (!objectNode?.properties?.length) return void 0;
|
|
22
|
+
if (!objectNode.properties.some((prop) => prop.name === propertyName)) return void 0;
|
|
23
|
+
return createSchema({
|
|
24
|
+
...objectNode,
|
|
25
|
+
properties: objectNode.properties.map((prop) => {
|
|
26
|
+
if (prop.name !== propertyName) return prop;
|
|
27
|
+
return createProperty({
|
|
28
|
+
...prop,
|
|
29
|
+
schema: createSchema({
|
|
30
|
+
type: "enum",
|
|
31
|
+
primitive: "string",
|
|
32
|
+
enumValues: values,
|
|
33
|
+
name: enumName,
|
|
34
|
+
readOnly: prop.schema.readOnly,
|
|
35
|
+
writeOnly: prop.schema.writeOnly
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/macros/macroEnumName.ts
|
|
45
|
+
/**
|
|
46
|
+
* Builds a macro that names an inline enum schema from its parent and property name. Boolean enums
|
|
47
|
+
* are left anonymous. Non-enum nodes are returned unchanged.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const macro = macroEnumName({ parentName: 'Pet', propName: 'status', enumSuffix: 'enum' })
|
|
52
|
+
* const named = applyMacros(propSchema, [macro], { depth: 'shallow' })
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
function macroEnumName({ parentName, propName, enumSuffix }) {
|
|
56
|
+
return defineMacro({
|
|
57
|
+
name: "enum-name",
|
|
58
|
+
schema(node) {
|
|
59
|
+
const enumNode = narrowSchema(node, "enum");
|
|
60
|
+
if (enumNode?.primitive === "boolean") return {
|
|
61
|
+
...node,
|
|
62
|
+
name: null
|
|
63
|
+
};
|
|
64
|
+
if (enumNode) return {
|
|
65
|
+
...node,
|
|
66
|
+
name: enumPropName(parentName, propName, enumSuffix)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/macros/macroSimplifyUnion.ts
|
|
73
|
+
/**
|
|
74
|
+
* Scalar primitive schema types used for union simplification and type narrowing.
|
|
75
|
+
*/
|
|
76
|
+
const SCALAR_PRIMITIVE_TYPES = new Set([
|
|
77
|
+
"string",
|
|
78
|
+
"number",
|
|
79
|
+
"integer",
|
|
80
|
+
"bigint",
|
|
81
|
+
"boolean"
|
|
82
|
+
]);
|
|
83
|
+
function isScalarPrimitive(type) {
|
|
84
|
+
return SCALAR_PRIMITIVE_TYPES.has(type);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Filters union members, dropping enum members that a broader scalar primitive already covers.
|
|
88
|
+
*/
|
|
89
|
+
function simplifyUnionMembers(members) {
|
|
90
|
+
const scalarPrimitives = new Set(members.filter((member) => isScalarPrimitive(member.type)).map((m) => m.type));
|
|
91
|
+
if (!scalarPrimitives.size) return members;
|
|
92
|
+
return members.filter((member) => {
|
|
93
|
+
const enumNode = narrowSchema(member, "enum");
|
|
94
|
+
if (!enumNode) return true;
|
|
95
|
+
const primitive = enumNode.primitive;
|
|
96
|
+
if (!primitive) return true;
|
|
97
|
+
if ((enumNode.namedEnumValues?.length ?? enumNode.enumValues?.length ?? 0) <= 1) return true;
|
|
98
|
+
if (scalarPrimitives.has(primitive)) return false;
|
|
99
|
+
if ((primitive === "integer" || primitive === "number") && (scalarPrimitives.has("integer") || scalarPrimitives.has("number"))) return false;
|
|
100
|
+
return true;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Removes union members a broader scalar primitive already covers, such as a multi-value string enum
|
|
105
|
+
* sitting next to a plain `string`. Single-value enums are kept.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* const next = applyMacros(unionSchema, [macroSimplifyUnion], { depth: 'shallow' })
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
const macroSimplifyUnion = defineMacro({
|
|
113
|
+
name: "simplify-union",
|
|
114
|
+
schema(node) {
|
|
115
|
+
const unionNode = narrowSchema(node, "union");
|
|
116
|
+
if (!unionNode?.members?.length) return void 0;
|
|
117
|
+
const simplified = simplifyUnionMembers(unionNode.members);
|
|
118
|
+
if (simplified.length === unionNode.members.length) return void 0;
|
|
119
|
+
return {
|
|
120
|
+
...unionNode,
|
|
121
|
+
members: simplified
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
//#endregion
|
|
126
|
+
export { macroDiscriminatorEnum, macroEnumName, macroSimplifyUnion };
|
|
127
|
+
|
|
128
|
+
//# sourceMappingURL=macros.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"macros.js","names":[],"sources":["../src/macros/macroDiscriminatorEnum.ts","../src/macros/macroEnumName.ts","../src/macros/macroSimplifyUnion.ts"],"sourcesContent":["import { defineMacro } from '../defineMacro.ts'\nimport { narrowSchema } from '../guards.ts'\nimport { createProperty } from '../nodes/property.ts'\nimport { createSchema } from '../nodes/schema.ts'\n\ntype Props = {\n propertyName: string\n values: Array<string>\n enumName?: string\n}\n\n/**\n * Builds a macro that replaces a discriminator property's schema with a string enum of the given\n * values. Object schemas that lack the property are returned unchanged.\n *\n * @example\n * ```ts\n * const macro = macroDiscriminatorEnum({ propertyName: 'type', values: ['dog', 'cat'] })\n * const next = applyMacros(objectSchema, [macro], { depth: 'shallow' })\n * ```\n */\nexport function macroDiscriminatorEnum({ propertyName, values, enumName }: Props) {\n return defineMacro({\n name: 'discriminator-enum',\n schema(node) {\n const objectNode = narrowSchema(node, 'object')\n if (!objectNode?.properties?.length) return undefined\n if (!objectNode.properties.some((prop) => prop.name === propertyName)) return undefined\n\n return createSchema({\n ...objectNode,\n properties: objectNode.properties.map((prop) => {\n if (prop.name !== propertyName) return prop\n\n return createProperty({\n ...prop,\n schema: createSchema({\n type: 'enum',\n primitive: 'string',\n enumValues: values,\n name: enumName,\n readOnly: prop.schema.readOnly,\n writeOnly: prop.schema.writeOnly,\n }),\n })\n }),\n })\n },\n })\n}\n","import { defineMacro } from '../defineMacro.ts'\nimport { narrowSchema } from '../guards.ts'\nimport { enumPropName } from '../utils/refs.ts'\n\ntype Props = {\n parentName: string | null | undefined\n propName: string\n enumSuffix: string\n}\n\n/**\n * Builds a macro that names an inline enum schema from its parent and property name. Boolean enums\n * are left anonymous. Non-enum nodes are returned unchanged.\n *\n * @example\n * ```ts\n * const macro = macroEnumName({ parentName: 'Pet', propName: 'status', enumSuffix: 'enum' })\n * const named = applyMacros(propSchema, [macro], { depth: 'shallow' })\n * ```\n */\nexport function macroEnumName({ parentName, propName, enumSuffix }: Props) {\n return defineMacro({\n name: 'enum-name',\n schema(node) {\n const enumNode = narrowSchema(node, 'enum')\n\n if (enumNode?.primitive === 'boolean') return { ...node, name: null }\n if (enumNode) return { ...node, name: enumPropName(parentName, propName, enumSuffix) }\n\n return undefined\n },\n })\n}\n","import { defineMacro } from '../defineMacro.ts'\nimport { narrowSchema } from '../guards.ts'\nimport type { SchemaNode } from '../nodes/schema.ts'\n\ntype ScalarPrimitive = 'string' | 'number' | 'integer' | 'bigint' | 'boolean'\n\n/**\n * Scalar primitive schema types used for union simplification and type narrowing.\n */\nconst SCALAR_PRIMITIVE_TYPES = new Set<ScalarPrimitive>(['string', 'number', 'integer', 'bigint', 'boolean'])\n\nfunction isScalarPrimitive(type: string): type is ScalarPrimitive {\n return SCALAR_PRIMITIVE_TYPES.has(type as ScalarPrimitive)\n}\n\n/**\n * Filters union members, dropping enum members that a broader scalar primitive already covers.\n */\nfunction simplifyUnionMembers(members: Array<SchemaNode>): Array<SchemaNode> {\n const scalarPrimitives = new Set(members.filter((member) => isScalarPrimitive(member.type)).map((m) => m.type))\n if (!scalarPrimitives.size) return members\n\n return members.filter((member) => {\n const enumNode = narrowSchema(member, 'enum')\n if (!enumNode) return true\n\n const primitive = enumNode.primitive\n if (!primitive) return true\n\n const enumValueCount = enumNode.namedEnumValues?.length ?? enumNode.enumValues?.length ?? 0\n if (enumValueCount <= 1) return true\n\n if (scalarPrimitives.has(primitive)) return false\n if ((primitive === 'integer' || primitive === 'number') && (scalarPrimitives.has('integer') || scalarPrimitives.has('number'))) return false\n\n return true\n })\n}\n\n/**\n * Removes union members a broader scalar primitive already covers, such as a multi-value string enum\n * sitting next to a plain `string`. Single-value enums are kept.\n *\n * @example\n * ```ts\n * const next = applyMacros(unionSchema, [macroSimplifyUnion], { depth: 'shallow' })\n * ```\n */\nexport const macroSimplifyUnion = defineMacro({\n name: 'simplify-union',\n schema(node) {\n const unionNode = narrowSchema(node, 'union')\n if (!unionNode?.members?.length) return undefined\n\n const simplified = simplifyUnionMembers(unionNode.members)\n if (simplified.length === unionNode.members.length) return undefined\n\n return { ...unionNode, members: simplified }\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;AAqBA,SAAgB,uBAAuB,EAAE,cAAc,QAAQ,YAAmB;CAChF,OAAO,YAAY;EACjB,MAAM;EACN,OAAO,MAAM;GACX,MAAM,aAAa,aAAa,MAAM,QAAQ;GAC9C,IAAI,CAAC,YAAY,YAAY,QAAQ,OAAO,KAAA;GAC5C,IAAI,CAAC,WAAW,WAAW,MAAM,SAAS,KAAK,SAAS,YAAY,GAAG,OAAO,KAAA;GAE9E,OAAO,aAAa;IAClB,GAAG;IACH,YAAY,WAAW,WAAW,KAAK,SAAS;KAC9C,IAAI,KAAK,SAAS,cAAc,OAAO;KAEvC,OAAO,eAAe;MACpB,GAAG;MACH,QAAQ,aAAa;OACnB,MAAM;OACN,WAAW;OACX,YAAY;OACZ,MAAM;OACN,UAAU,KAAK,OAAO;OACtB,WAAW,KAAK,OAAO;MACzB,CAAC;KACH,CAAC;IACH,CAAC;GACH,CAAC;EACH;CACF,CAAC;AACH;;;;;;;;;;;;;AC7BA,SAAgB,cAAc,EAAE,YAAY,UAAU,cAAqB;CACzE,OAAO,YAAY;EACjB,MAAM;EACN,OAAO,MAAM;GACX,MAAM,WAAW,aAAa,MAAM,MAA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|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { n as __name } from "./rolldown-runtime-CNktS9qV.js";
|
|
2
|
+
import { C as ParameterNode, O as FunctionParameterNode, f as OperationNode, k as FunctionParametersNode } from "./index-DJEyS5y6.js";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/operationParams.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Applies casing rules to parameter names and returns a new array without mutating the input.
|
|
7
|
+
*
|
|
8
|
+
* Run it before handing parameters to schema builders so output property keys get the right casing
|
|
9
|
+
* while `OperationNode.parameters` stays intact for other consumers. When `casing` is unset, the
|
|
10
|
+
* original array is returned unchanged.
|
|
11
|
+
*/
|
|
12
|
+
declare function caseParams(params: Array<ParameterNode>, casing: 'camelcase' | undefined): Array<ParameterNode>;
|
|
13
|
+
/**
|
|
14
|
+
* Resolver interface for {@link createOperationParams}.
|
|
15
|
+
*
|
|
16
|
+
* `ResolverTs` from `@kubb/plugin-ts` satisfies this interface and can be passed directly.
|
|
17
|
+
*/
|
|
18
|
+
type OperationParamsResolver = {
|
|
19
|
+
/**
|
|
20
|
+
* Resolves the type name for an individual parameter.
|
|
21
|
+
*
|
|
22
|
+
* @example Individual path parameter name
|
|
23
|
+
* `resolver.resolveParamName(node, param) // → 'DeletePetPathPetId'`
|
|
24
|
+
*/
|
|
25
|
+
resolveParamName(node: OperationNode, param: ParameterNode): string;
|
|
26
|
+
/**
|
|
27
|
+
* Resolves the request body type name.
|
|
28
|
+
*
|
|
29
|
+
* @example Request body type name
|
|
30
|
+
* `resolver.resolveDataName(node) // → 'CreatePetData'`
|
|
31
|
+
*/
|
|
32
|
+
resolveDataName(node: OperationNode): string;
|
|
33
|
+
/**
|
|
34
|
+
* Resolves the grouped path parameters type name.
|
|
35
|
+
* When the return value equals `resolveParamName`, no indexed access is emitted.
|
|
36
|
+
*
|
|
37
|
+
* @example Grouped path params type name
|
|
38
|
+
* `resolver.resolvePathParamsName(node, param) // → 'DeletePetPathParams'`
|
|
39
|
+
*/
|
|
40
|
+
resolvePathParamsName(node: OperationNode, param: ParameterNode): string;
|
|
41
|
+
/**
|
|
42
|
+
* Resolves the grouped query parameters type name.
|
|
43
|
+
* When the return value equals `resolveParamName`, an inline struct type is emitted instead.
|
|
44
|
+
*
|
|
45
|
+
* @example Grouped query params type name
|
|
46
|
+
* `resolver.resolveQueryParamsName(node, param) // → 'FindPetsByStatusQueryParams'`
|
|
47
|
+
*/
|
|
48
|
+
resolveQueryParamsName(node: OperationNode, param: ParameterNode): string;
|
|
49
|
+
/**
|
|
50
|
+
* Resolves the grouped header parameters type name.
|
|
51
|
+
* When the return value equals `resolveParamName`, an inline struct type is emitted instead.
|
|
52
|
+
*
|
|
53
|
+
* @example Grouped header params type name
|
|
54
|
+
* `resolver.resolveHeaderParamsName(node, param) // → 'DeletePetHeaderParams'`
|
|
55
|
+
*/
|
|
56
|
+
resolveHeaderParamsName(node: OperationNode, param: ParameterNode): string;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Options for {@link createOperationParams}.
|
|
60
|
+
*/
|
|
61
|
+
type CreateOperationParamsOptions = {
|
|
62
|
+
/**
|
|
63
|
+
* How all operation parameters are grouped in the function signature.
|
|
64
|
+
* - `'object'` wraps all params into a single destructured object `{ petId, data, params }`
|
|
65
|
+
* - `'inline'` emits each param category as a separate top-level parameter
|
|
66
|
+
*/
|
|
67
|
+
paramsType: 'object' | 'inline';
|
|
68
|
+
/**
|
|
69
|
+
* How path parameters are emitted when `paramsType` is `'inline'`.
|
|
70
|
+
* - `'object'` groups them as `{ petId, storeId }: PathParams`
|
|
71
|
+
* - `'inline'` spreads them as individual parameters `petId: string, storeId: string`
|
|
72
|
+
* - `'inlineSpread'` emits a single rest parameter `...pathParams: PathParams`
|
|
73
|
+
*/
|
|
74
|
+
pathParamsType: 'object' | 'inline' | 'inlineSpread';
|
|
75
|
+
/**
|
|
76
|
+
* Converts parameter names to camelCase before output.
|
|
77
|
+
*/
|
|
78
|
+
paramsCasing?: 'camelcase';
|
|
79
|
+
/**
|
|
80
|
+
* Resolver for parameter and request body type names.
|
|
81
|
+
* Pass `ResolverTs` from `@kubb/plugin-ts` directly.
|
|
82
|
+
* When omitted, falls back to the schema primitive or `'unknown'`.
|
|
83
|
+
*/
|
|
84
|
+
resolver?: OperationParamsResolver;
|
|
85
|
+
/**
|
|
86
|
+
* Default value for the path parameters binding when `pathParamsType` is `'object'`.
|
|
87
|
+
* Falls back to `'{}'` when all path params are optional.
|
|
88
|
+
*/
|
|
89
|
+
pathParamsDefault?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Extra parameters appended after the standard operation parameters.
|
|
92
|
+
*
|
|
93
|
+
* @example Plugin-specific trailing parameter
|
|
94
|
+
* ```ts
|
|
95
|
+
* extraParams: [createFunctionParameter({ name: 'options', type: 'Partial<RequestOptions>', default: '{}' })]
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
extraParams?: Array<FunctionParameterNode>;
|
|
99
|
+
/**
|
|
100
|
+
* Override the default parameter names used for body, query, header, and rest-path groups.
|
|
101
|
+
*
|
|
102
|
+
* Useful when targeting languages or frameworks with different naming conventions.
|
|
103
|
+
*
|
|
104
|
+
* @default { data: 'data', params: 'params', headers: 'headers', path: 'pathParams' }
|
|
105
|
+
*/
|
|
106
|
+
paramNames?: {
|
|
107
|
+
/**
|
|
108
|
+
* Name for the request body parameter.
|
|
109
|
+
* @default 'data'
|
|
110
|
+
*/
|
|
111
|
+
data?: string;
|
|
112
|
+
/**
|
|
113
|
+
* Name for the query parameters group parameter.
|
|
114
|
+
* @default 'params'
|
|
115
|
+
*/
|
|
116
|
+
params?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Name for the header parameters group parameter.
|
|
119
|
+
* @default 'headers'
|
|
120
|
+
*/
|
|
121
|
+
headers?: string;
|
|
122
|
+
/**
|
|
123
|
+
* Name for the rest path-parameters parameter when `pathParamsType` is `'inlineSpread'`.
|
|
124
|
+
* @default 'pathParams'
|
|
125
|
+
*/
|
|
126
|
+
path?: string;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Transforms every resolved type name before it lands in a parameter node, for framework-level
|
|
130
|
+
* type wrappers.
|
|
131
|
+
*
|
|
132
|
+
* @example Vue Query, wrap every parameter type with `MaybeRefOrGetter`
|
|
133
|
+
* `typeWrapper: (t) => \`MaybeRefOrGetter<${t}>\``
|
|
134
|
+
*/
|
|
135
|
+
typeWrapper?: (type: string) => string;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Converts an `OperationNode` into function parameters for code generation.
|
|
139
|
+
*
|
|
140
|
+
* Centralizes parameter grouping logic for all plugins. `paramsType` chooses between one
|
|
141
|
+
* destructured object parameter (`object`) and separate top-level parameters (`inline`), while
|
|
142
|
+
* `pathParamsType` controls how path params render in inline mode. Provide a `resolver` for type
|
|
143
|
+
* name resolution and `extraParams` for plugin-specific trailing parameters such as an `options` object.
|
|
144
|
+
*/
|
|
145
|
+
declare function createOperationParams(node: OperationNode, options: CreateOperationParamsOptions): FunctionParametersNode;
|
|
146
|
+
//#endregion
|
|
147
|
+
export { caseParams as n, createOperationParams as r, OperationParamsResolver as t };
|
|
148
|
+
//# sourceMappingURL=operationParams-BaY12i2I.d.ts.map
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import "./rolldown-runtime-CNktS9qV.js";
|
|
2
|
+
import { U as pascalCase, lt as narrowSchema, o as createSchema } from "./visitor-dcVC5TOW.js";
|
|
3
|
+
//#region src/utils/refs.ts
|
|
4
|
+
const plainStringTypes = new Set([
|
|
5
|
+
"string",
|
|
6
|
+
"uuid",
|
|
7
|
+
"email",
|
|
8
|
+
"url",
|
|
9
|
+
"datetime"
|
|
10
|
+
]);
|
|
11
|
+
/**
|
|
12
|
+
* Returns the last path segment of a reference string.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* `extractRefName('#/components/schemas/Pet') // 'Pet'`
|
|
16
|
+
*/
|
|
17
|
+
function extractRefName(ref) {
|
|
18
|
+
return ref.split("/").at(-1) ?? ref;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls
|
|
22
|
+
* back to `name` then nested `schema.name`.
|
|
23
|
+
*
|
|
24
|
+
* Returns `null` for non-ref nodes or when no name resolves.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`
|
|
28
|
+
*/
|
|
29
|
+
function resolveRefName(node) {
|
|
30
|
+
if (!node || node.type !== "ref") return null;
|
|
31
|
+
if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null;
|
|
32
|
+
return node.name ?? node.schema?.name ?? null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Builds a PascalCase child schema name by joining a parent name and property name.
|
|
36
|
+
* Returns `null` when there is no parent to nest under.
|
|
37
|
+
*
|
|
38
|
+
* @example Nested under a parent
|
|
39
|
+
* `childName('Order', 'shipping_address') // 'OrderShippingAddress'`
|
|
40
|
+
*
|
|
41
|
+
* @example No parent
|
|
42
|
+
* `childName(undefined, 'params') // null`
|
|
43
|
+
*/
|
|
44
|
+
function childName(parentName, propName) {
|
|
45
|
+
return parentName ? pascalCase([parentName, propName].join(" ")) : null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any
|
|
49
|
+
* empty parts.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`
|
|
53
|
+
*/
|
|
54
|
+
function enumPropName(parentName, propName, enumSuffix) {
|
|
55
|
+
return pascalCase([
|
|
56
|
+
parentName,
|
|
57
|
+
propName,
|
|
58
|
+
enumSuffix
|
|
59
|
+
].filter(Boolean).join(" "));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Merges a ref node with its resolved schema, giving usage-site fields precedence.
|
|
63
|
+
*
|
|
64
|
+
* Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the
|
|
65
|
+
* same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,
|
|
66
|
+
* `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref
|
|
67
|
+
* nodes and refs without a resolved `schema` are returned unchanged.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })
|
|
72
|
+
* const merged = syncSchemaRef(ref) // merges with resolved Pet schema
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
function syncSchemaRef(node) {
|
|
76
|
+
const ref = narrowSchema(node, "ref");
|
|
77
|
+
if (!ref) return node;
|
|
78
|
+
if (!ref.schema) return node;
|
|
79
|
+
const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref;
|
|
80
|
+
const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== void 0));
|
|
81
|
+
return createSchema({
|
|
82
|
+
...ref.schema,
|
|
83
|
+
...definedOverrides
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Type guard that returns `true` when a schema emits as a plain `string` type.
|
|
88
|
+
*
|
|
89
|
+
* Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`
|
|
90
|
+
* types, returns `true` only when `representation` is `'string'` rather than `'date'`.
|
|
91
|
+
*/
|
|
92
|
+
function isStringType(node) {
|
|
93
|
+
if (plainStringTypes.has(node.type)) return true;
|
|
94
|
+
const temporal = narrowSchema(node, "date") ?? narrowSchema(node, "time");
|
|
95
|
+
if (temporal) return temporal.representation !== "date";
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Derives a {@link ParamGroupType} for a query or header group from the resolver.
|
|
100
|
+
*
|
|
101
|
+
* Returns `null` when there is no resolver, no params, or the group name equals the
|
|
102
|
+
* individual param name (so there is no real group to emit).
|
|
103
|
+
*/
|
|
104
|
+
function resolveGroupType({ node, params, group, resolver }) {
|
|
105
|
+
if (!resolver || !params.length) return null;
|
|
106
|
+
const firstParam = params[0];
|
|
107
|
+
const groupName = (group === "query" ? resolver.resolveQueryParamsName : resolver.resolveHeaderParamsName).call(resolver, node, firstParam);
|
|
108
|
+
if (groupName === resolver.resolveParamName(node, firstParam)) return null;
|
|
109
|
+
return {
|
|
110
|
+
type: groupName,
|
|
111
|
+
optional: params.every((p) => !p.required)
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
//#endregion
|
|
115
|
+
export { resolveGroupType as a, isStringType as i, enumPropName as n, resolveRefName as o, extractRefName as r, syncSchemaRef as s, childName as t };
|
|
116
|
+
|
|
117
|
+
//# sourceMappingURL=refs-D18OeCgb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refs-D18OeCgb.js","names":[],"sources":["../src/utils/refs.ts"],"sourcesContent":["import { pascalCase } from '@internals/utils'\nimport { narrowSchema } from '../guards.ts'\nimport type { OperationNode, ParameterNode, SchemaNode } from '../nodes/index.ts'\nimport { createSchema, type SchemaType } from '../nodes/schema.ts'\nimport type { OperationParamsResolver, ParamGroupType } from './operationParams.ts'\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'] as const)\n\n/**\n * Returns the last path segment of a reference string.\n *\n * @example\n * `extractRefName('#/components/schemas/Pet') // 'Pet'`\n */\nexport function extractRefName(ref: string): string {\n return ref.split('/').at(-1) ?? ref\n}\n\n/**\n * Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls\n * back to `name` then nested `schema.name`.\n *\n * Returns `null` for non-ref nodes or when no name resolves.\n *\n * @example\n * `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`\n */\nexport function resolveRefName(node: SchemaNode | undefined): string | null {\n if (!node || node.type !== 'ref') return null\n if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null\n\n return node.name ?? node.schema?.name ?? null\n}\n\n/**\n * Builds a PascalCase child schema name by joining a parent name and property name.\n * Returns `null` when there is no parent to nest under.\n *\n * @example Nested under a parent\n * `childName('Order', 'shipping_address') // 'OrderShippingAddress'`\n *\n * @example No parent\n * `childName(undefined, 'params') // null`\n */\nexport function childName(parentName: string | null | undefined, propName: string): string | null {\n return parentName ? pascalCase([parentName, propName].join(' ')) : null\n}\n\n/**\n * Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any\n * empty parts.\n *\n * @example\n * `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`\n */\nexport function enumPropName(parentName: string | null | undefined, propName: string, enumSuffix: string): string {\n return pascalCase([parentName, propName, enumSuffix].filter(Boolean).join(' '))\n}\n\n/**\n * Merges a ref node with its resolved schema, giving usage-site fields precedence.\n *\n * Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the\n * same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,\n * `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref\n * nodes and refs without a resolved `schema` are returned unchanged.\n *\n * @example\n * ```ts\n * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })\n * const merged = syncSchemaRef(ref) // merges with resolved Pet schema\n * ```\n */\nexport function syncSchemaRef(node: SchemaNode): SchemaNode {\n const ref = narrowSchema(node, 'ref')\n\n if (!ref) return node\n if (!ref.schema) return node\n\n const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref\n\n // Filter out undefined override values so they don't shadow the resolved schema's fields.\n const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== undefined))\n\n return createSchema({ ...ref.schema, ...definedOverrides })\n}\n\n/**\n * Type guard that returns `true` when a schema emits as a plain `string` type.\n *\n * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`\n * types, returns `true` only when `representation` is `'string'` rather than `'date'`.\n */\nexport function isStringType(node: SchemaNode): boolean {\n if (plainStringTypes.has(node.type)) {\n return true\n }\n\n const temporal = narrowSchema(node, 'date') ?? narrowSchema(node, 'time')\n if (temporal) {\n return temporal.representation !== 'date'\n }\n\n return false\n}\n\n/**\n * Derives a {@link ParamGroupType} for a query or header group from the resolver.\n *\n * Returns `null` when there is no resolver, no params, or the group name equals the\n * individual param name (so there is no real group to emit).\n */\nexport function resolveGroupType({\n node,\n params,\n group,\n resolver,\n}: {\n node: OperationNode\n params: Array<ParameterNode>\n group: 'query' | 'header'\n resolver: OperationParamsResolver | undefined\n}): ParamGroupType | null {\n if (!resolver || !params.length) {\n return null\n }\n const firstParam = params[0]!\n const groupMethod = group === 'query' ? resolver.resolveQueryParamsName : resolver.resolveHeaderParamsName\n const groupName = groupMethod.call(resolver, node, firstParam)\n if (groupName === resolver.resolveParamName(node, firstParam)) {\n return null\n }\n return { type: groupName, optional: params.every((p) => !p.required) }\n}\n"],"mappings":";;;AAMA,MAAM,mBAAmB,IAAI,IAAgB;CAAC;CAAU;CAAQ;CAAS;CAAO;AAAU,CAAU;;;;;;;AAQpG,SAAgB,eAAe,KAAqB;CAClD,OAAO,IAAI,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK;AAClC;;;;;;;;;;AAWA,SAAgB,eAAe,MAA6C;CAC1E,IAAI,CAAC,QAAQ,KAAK,SAAS,OAAO,OAAO;CACzC,IAAI,KAAK,KAAK,OAAO,eAAe,KAAK,GAAG,KAAK,KAAK,QAAQ,KAAK,QAAQ,QAAQ;CAEnF,OAAO,KAAK,QAAQ,KAAK,QAAQ,QAAQ;AAC3C;;;;;;;;;;;AAYA,SAAgB,UAAU,YAAuC,UAAiC;CAChG,OAAO,aAAa,WAAW,CAAC,YAAY,QAAQ,CAAC,CAAC,KAAK,GAAG,CAAC,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/utils/refs.ts
|
|
3
|
+
const plainStringTypes = new Set([
|
|
4
|
+
"string",
|
|
5
|
+
"uuid",
|
|
6
|
+
"email",
|
|
7
|
+
"url",
|
|
8
|
+
"datetime"
|
|
9
|
+
]);
|
|
10
|
+
/**
|
|
11
|
+
* Returns the last path segment of a reference string.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* `extractRefName('#/components/schemas/Pet') // 'Pet'`
|
|
15
|
+
*/
|
|
16
|
+
function extractRefName(ref) {
|
|
17
|
+
return ref.split("/").at(-1) ?? ref;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls
|
|
21
|
+
* back to `name` then nested `schema.name`.
|
|
22
|
+
*
|
|
23
|
+
* Returns `null` for non-ref nodes or when no name resolves.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`
|
|
27
|
+
*/
|
|
28
|
+
function resolveRefName(node) {
|
|
29
|
+
if (!node || node.type !== "ref") return null;
|
|
30
|
+
if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null;
|
|
31
|
+
return node.name ?? node.schema?.name ?? null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Builds a PascalCase child schema name by joining a parent name and property name.
|
|
35
|
+
* Returns `null` when there is no parent to nest under.
|
|
36
|
+
*
|
|
37
|
+
* @example Nested under a parent
|
|
38
|
+
* `childName('Order', 'shipping_address') // 'OrderShippingAddress'`
|
|
39
|
+
*
|
|
40
|
+
* @example No parent
|
|
41
|
+
* `childName(undefined, 'params') // null`
|
|
42
|
+
*/
|
|
43
|
+
function childName(parentName, propName) {
|
|
44
|
+
return parentName ? require_visitor.pascalCase([parentName, propName].join(" ")) : null;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any
|
|
48
|
+
* empty parts.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`
|
|
52
|
+
*/
|
|
53
|
+
function enumPropName(parentName, propName, enumSuffix) {
|
|
54
|
+
return require_visitor.pascalCase([
|
|
55
|
+
parentName,
|
|
56
|
+
propName,
|
|
57
|
+
enumSuffix
|
|
58
|
+
].filter(Boolean).join(" "));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Merges a ref node with its resolved schema, giving usage-site fields precedence.
|
|
62
|
+
*
|
|
63
|
+
* Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the
|
|
64
|
+
* same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,
|
|
65
|
+
* `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref
|
|
66
|
+
* nodes and refs without a resolved `schema` are returned unchanged.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })
|
|
71
|
+
* const merged = syncSchemaRef(ref) // merges with resolved Pet schema
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
function syncSchemaRef(node) {
|
|
75
|
+
const ref = require_visitor.narrowSchema(node, "ref");
|
|
76
|
+
if (!ref) return node;
|
|
77
|
+
if (!ref.schema) return node;
|
|
78
|
+
const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref;
|
|
79
|
+
const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== void 0));
|
|
80
|
+
return require_visitor.createSchema({
|
|
81
|
+
...ref.schema,
|
|
82
|
+
...definedOverrides
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Type guard that returns `true` when a schema emits as a plain `string` type.
|
|
87
|
+
*
|
|
88
|
+
* Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`
|
|
89
|
+
* types, returns `true` only when `representation` is `'string'` rather than `'date'`.
|
|
90
|
+
*/
|
|
91
|
+
function isStringType(node) {
|
|
92
|
+
if (plainStringTypes.has(node.type)) return true;
|
|
93
|
+
const temporal = require_visitor.narrowSchema(node, "date") ?? require_visitor.narrowSchema(node, "time");
|
|
94
|
+
if (temporal) return temporal.representation !== "date";
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Derives a {@link ParamGroupType} for a query or header group from the resolver.
|
|
99
|
+
*
|
|
100
|
+
* Returns `null` when there is no resolver, no params, or the group name equals the
|
|
101
|
+
* individual param name (so there is no real group to emit).
|
|
102
|
+
*/
|
|
103
|
+
function resolveGroupType({ node, params, group, resolver }) {
|
|
104
|
+
if (!resolver || !params.length) return null;
|
|
105
|
+
const firstParam = params[0];
|
|
106
|
+
const groupName = (group === "query" ? resolver.resolveQueryParamsName : resolver.resolveHeaderParamsName).call(resolver, node, firstParam);
|
|
107
|
+
if (groupName === resolver.resolveParamName(node, firstParam)) return null;
|
|
108
|
+
return {
|
|
109
|
+
type: groupName,
|
|
110
|
+
optional: params.every((p) => !p.required)
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
Object.defineProperty(exports, "childName", {
|
|
115
|
+
enumerable: true,
|
|
116
|
+
get: function() {
|
|
117
|
+
return childName;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
Object.defineProperty(exports, "enumPropName", {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
get: function() {
|
|
123
|
+
return enumPropName;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
Object.defineProperty(exports, "extractRefName", {
|
|
127
|
+
enumerable: true,
|
|
128
|
+
get: function() {
|
|
129
|
+
return extractRefName;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
Object.defineProperty(exports, "isStringType", {
|
|
133
|
+
enumerable: true,
|
|
134
|
+
get: function() {
|
|
135
|
+
return isStringType;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
Object.defineProperty(exports, "resolveGroupType", {
|
|
139
|
+
enumerable: true,
|
|
140
|
+
get: function() {
|
|
141
|
+
return resolveGroupType;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
Object.defineProperty(exports, "resolveRefName", {
|
|
145
|
+
enumerable: true,
|
|
146
|
+
get: function() {
|
|
147
|
+
return resolveRefName;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
Object.defineProperty(exports, "syncSchemaRef", {
|
|
151
|
+
enumerable: true,
|
|
152
|
+
get: function() {
|
|
153
|
+
return syncSchemaRef;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
//# sourceMappingURL=refs-DuP3_Leg.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refs-DuP3_Leg.cjs","names":["pascalCase","narrowSchema","createSchema"],"sources":["../src/utils/refs.ts"],"sourcesContent":["import { pascalCase } from '@internals/utils'\nimport { narrowSchema } from '../guards.ts'\nimport type { OperationNode, ParameterNode, SchemaNode } from '../nodes/index.ts'\nimport { createSchema, type SchemaType } from '../nodes/schema.ts'\nimport type { OperationParamsResolver, ParamGroupType } from './operationParams.ts'\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'] as const)\n\n/**\n * Returns the last path segment of a reference string.\n *\n * @example\n * `extractRefName('#/components/schemas/Pet') // 'Pet'`\n */\nexport function extractRefName(ref: string): string {\n return ref.split('/').at(-1) ?? ref\n}\n\n/**\n * Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls\n * back to `name` then nested `schema.name`.\n *\n * Returns `null` for non-ref nodes or when no name resolves.\n *\n * @example\n * `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`\n */\nexport function resolveRefName(node: SchemaNode | undefined): string | null {\n if (!node || node.type !== 'ref') return null\n if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null\n\n return node.name ?? node.schema?.name ?? null\n}\n\n/**\n * Builds a PascalCase child schema name by joining a parent name and property name.\n * Returns `null` when there is no parent to nest under.\n *\n * @example Nested under a parent\n * `childName('Order', 'shipping_address') // 'OrderShippingAddress'`\n *\n * @example No parent\n * `childName(undefined, 'params') // null`\n */\nexport function childName(parentName: string | null | undefined, propName: string): string | null {\n return parentName ? pascalCase([parentName, propName].join(' ')) : null\n}\n\n/**\n * Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any\n * empty parts.\n *\n * @example\n * `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`\n */\nexport function enumPropName(parentName: string | null | undefined, propName: string, enumSuffix: string): string {\n return pascalCase([parentName, propName, enumSuffix].filter(Boolean).join(' '))\n}\n\n/**\n * Merges a ref node with its resolved schema, giving usage-site fields precedence.\n *\n * Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the\n * same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,\n * `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref\n * nodes and refs without a resolved `schema` are returned unchanged.\n *\n * @example\n * ```ts\n * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })\n * const merged = syncSchemaRef(ref) // merges with resolved Pet schema\n * ```\n */\nexport function syncSchemaRef(node: SchemaNode): SchemaNode {\n const ref = narrowSchema(node, 'ref')\n\n if (!ref) return node\n if (!ref.schema) return node\n\n const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref\n\n // Filter out undefined override values so they don't shadow the resolved schema's fields.\n const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== undefined))\n\n return createSchema({ ...ref.schema, ...definedOverrides })\n}\n\n/**\n * Type guard that returns `true` when a schema emits as a plain `string` type.\n *\n * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`\n * types, returns `true` only when `representation` is `'string'` rather than `'date'`.\n */\nexport function isStringType(node: SchemaNode): boolean {\n if (plainStringTypes.has(node.type)) {\n return true\n }\n\n const temporal = narrowSchema(node, 'date') ?? narrowSchema(node, 'time')\n if (temporal) {\n return temporal.representation !== 'date'\n }\n\n return false\n}\n\n/**\n * Derives a {@link ParamGroupType} for a query or header group from the resolver.\n *\n * Returns `null` when there is no resolver, no params, or the group name equals the\n * individual param name (so there is no real group to emit).\n */\nexport function resolveGroupType({\n node,\n params,\n group,\n resolver,\n}: {\n node: OperationNode\n params: Array<ParameterNode>\n group: 'query' | 'header'\n resolver: OperationParamsResolver | undefined\n}): ParamGroupType | null {\n if (!resolver || !params.length) {\n return null\n }\n const firstParam = params[0]!\n const groupMethod = group === 'query' ? resolver.resolveQueryParamsName : resolver.resolveHeaderParamsName\n const groupName = groupMethod.call(resolver, node, firstParam)\n if (groupName === resolver.resolveParamName(node, firstParam)) {\n return null\n }\n return { type: groupName, optional: params.every((p) => !p.required) }\n}\n"],"mappings":";;AAMA,MAAM,mBAAmB,IAAI,IAAgB;CAAC;CAAU;CAAQ;CAAS;CAAO;AAAU,CAAU;;;;;;;AAQpG,SAAgB,eAAe,KAAqB;CAClD,OAAO,IAAI,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK;AAClC;;;;;;;;;;AAWA,SAAgB,eAAe,MAA6C;CAC1E,IAAI,CAAC,QAAQ,KAAK,SAAS,OAAO,OAAO;CACzC,IAAI,KAAK,KAAK,OAAO,eAAe,KAAK,GAAG,KAAK,KAAK,QAAQ,KAAK,QAAQ,QAAQ;CAEnF,OAAO,KAAK,QAAQ,KAAK,QAAQ,QAAQ;AAC3C;;;;;;;;;;;AAYA,SAAgB,UAAU,YAAuC,UAAiC;CAChG,OAAO,aAAaA,gBAAAA,WAAW,CAAC,YAAY,QAAQ,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI;AACrE;;;;;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
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", {
|
|
4
|
+
value,
|
|
5
|
+
configurable: true
|
|
6
|
+
});
|
|
7
|
+
var __exportAll = (all, no_symbols) => {
|
|
8
|
+
let target = {};
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { __name as n, __exportAll as t };
|