@kubb/ast 5.0.0-beta.6 → 5.0.0-beta.61
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 +51 -27
- package/dist/chunk-CNktS9qV.js +17 -0
- package/dist/defineMacro-BLIR6k-j.d.ts +475 -0
- package/dist/defineMacro-BTXvS8nI.js +106 -0
- package/dist/defineMacro-BTXvS8nI.js.map +1 -0
- package/dist/defineMacro-Bv9R_9a2.cjs +123 -0
- package/dist/defineMacro-Bv9R_9a2.cjs.map +1 -0
- package/dist/extractStringsFromNodes-Cja-xxx5.js +29 -0
- package/dist/extractStringsFromNodes-Cja-xxx5.js.map +1 -0
- package/dist/extractStringsFromNodes-DKgDjFO0.cjs +34 -0
- package/dist/extractStringsFromNodes-DKgDjFO0.cjs.map +1 -0
- package/dist/extractStringsFromNodes-p4mX1TQD.d.ts +14 -0
- package/dist/factory-CZNOGI-N.js +283 -0
- package/dist/factory-CZNOGI-N.js.map +1 -0
- package/dist/factory-DG1CVkEb.cjs +300 -0
- package/dist/factory-DG1CVkEb.cjs.map +1 -0
- package/dist/factory.cjs +29 -0
- package/dist/factory.d.ts +62 -0
- package/dist/factory.js +3 -0
- package/dist/index-BzjwdK2M.d.ts +2433 -0
- package/dist/index.cjs +444 -2180
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +94 -3408
- package/dist/index.js +395 -2101
- package/dist/index.js.map +1 -1
- package/dist/macros.cjs +117 -0
- package/dist/macros.cjs.map +1 -0
- package/dist/macros.d.ts +59 -0
- package/dist/macros.js +115 -0
- package/dist/macros.js.map +1 -0
- package/dist/operationParams-BZ07xDm0.d.ts +204 -0
- package/dist/response-KUdWiDWw.js +658 -0
- package/dist/response-KUdWiDWw.js.map +1 -0
- package/dist/response-hnSw2NKE.cjs +1027 -0
- package/dist/response-hnSw2NKE.cjs.map +1 -0
- package/dist/types-DyDzizSf.d.ts +364 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.js +1 -0
- package/dist/utils-BLJwyza-.cjs +912 -0
- package/dist/utils-BLJwyza-.cjs.map +1 -0
- package/dist/utils-CF_-Pn_c.js +770 -0
- package/dist/utils-CF_-Pn_c.js.map +1 -0
- package/dist/utils.cjs +36 -0
- package/dist/utils.d.ts +358 -0
- package/dist/utils.js +4 -0
- package/dist/visitor-DJ6ZEJvq.js +548 -0
- package/dist/visitor-DJ6ZEJvq.js.map +1 -0
- package/dist/visitor-DpKZ9Tk0.cjs +654 -0
- package/dist/visitor-DpKZ9Tk0.cjs.map +1 -0
- package/package.json +21 -6
- package/src/constants.ts +19 -64
- package/src/dedupe.ts +239 -0
- package/src/defineMacro.ts +132 -0
- package/src/dialect.ts +53 -0
- package/src/factory.ts +67 -678
- package/src/guards.ts +10 -92
- package/src/index.ts +13 -44
- package/src/infer.ts +16 -14
- package/src/macros/index.ts +3 -0
- package/src/macros/macroDiscriminatorEnum.ts +44 -0
- package/src/macros/macroEnumName.ts +25 -0
- package/src/macros/macroSimplifyUnion.ts +50 -0
- package/src/mocks.ts +7 -127
- package/src/node.ts +128 -0
- package/src/nodes/base.ts +5 -12
- package/src/nodes/code.ts +165 -74
- package/src/nodes/content.ts +56 -0
- package/src/nodes/file.ts +97 -36
- package/src/nodes/function.ts +216 -156
- package/src/nodes/http.ts +1 -35
- package/src/nodes/index.ts +23 -15
- package/src/nodes/input.ts +140 -0
- package/src/nodes/operation.ts +122 -68
- package/src/nodes/output.ts +23 -0
- package/src/nodes/parameter.ts +33 -3
- package/src/nodes/property.ts +36 -3
- package/src/nodes/requestBody.ts +61 -0
- package/src/nodes/response.ts +58 -13
- package/src/nodes/schema.ts +93 -17
- package/src/printer.ts +48 -42
- package/src/registry.ts +75 -0
- package/src/signature.ts +207 -0
- package/src/types.ts +8 -68
- package/src/utils/codegen.ts +104 -0
- package/src/utils/extractStringsFromNodes.ts +34 -0
- package/src/utils/fileMerge.ts +184 -0
- package/src/utils/index.ts +11 -0
- package/src/utils/operationParams.ts +353 -0
- package/src/utils/refs.ts +138 -0
- package/src/utils/schemaGraph.ts +169 -0
- package/src/utils/schemaMerge.ts +34 -0
- package/src/utils/schemaTraversal.ts +86 -0
- package/src/utils/strings.ts +139 -0
- package/src/visitor.ts +227 -289
- package/dist/chunk--u3MIqq1.js +0 -8
- package/src/nodes/root.ts +0 -64
- package/src/refs.ts +0 -67
- package/src/resolvers.ts +0 -45
- package/src/transformers.ts +0 -159
- package/src/utils.ts +0 -915
package/dist/macros.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import "./chunk-CNktS9qV.js";
|
|
2
|
+
import { _ as isScalarPrimitive, m as narrowSchema, s as enumPropName } from "./visitor-DJ6ZEJvq.js";
|
|
3
|
+
import { X as createSchema, r as createProperty } from "./response-KUdWiDWw.js";
|
|
4
|
+
import { r as defineMacro } from "./defineMacro-BTXvS8nI.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
|
+
* Removes union members a broader scalar primitive already covers, such as a multi-value string enum
|
|
75
|
+
* sitting next to a plain `string`. Single-value enums are kept.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* const next = applyMacros(unionSchema, [macroSimplifyUnion], { depth: 'shallow' })
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
const macroSimplifyUnion = defineMacro({
|
|
83
|
+
name: "simplify-union",
|
|
84
|
+
schema(node) {
|
|
85
|
+
const unionNode = narrowSchema(node, "union");
|
|
86
|
+
if (!unionNode?.members?.length) return void 0;
|
|
87
|
+
const simplified = simplifyUnionMembers(unionNode.members);
|
|
88
|
+
if (simplified.length === unionNode.members.length) return void 0;
|
|
89
|
+
return {
|
|
90
|
+
...unionNode,
|
|
91
|
+
members: simplified
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
/**
|
|
96
|
+
* Filters union members, dropping enum members that a broader scalar primitive already covers.
|
|
97
|
+
*/
|
|
98
|
+
function simplifyUnionMembers(members) {
|
|
99
|
+
const scalarPrimitives = new Set(members.filter((member) => isScalarPrimitive(member.type)).map((m) => m.type));
|
|
100
|
+
if (!scalarPrimitives.size) return members;
|
|
101
|
+
return members.filter((member) => {
|
|
102
|
+
const enumNode = narrowSchema(member, "enum");
|
|
103
|
+
if (!enumNode) return true;
|
|
104
|
+
const primitive = enumNode.primitive;
|
|
105
|
+
if (!primitive) return true;
|
|
106
|
+
if ((enumNode.namedEnumValues?.length ?? enumNode.enumValues?.length ?? 0) <= 1) return true;
|
|
107
|
+
if (scalarPrimitives.has(primitive)) return false;
|
|
108
|
+
if ((primitive === "integer" || primitive === "number") && (scalarPrimitives.has("integer") || scalarPrimitives.has("number"))) return false;
|
|
109
|
+
return true;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
export { macroDiscriminatorEnum, macroEnumName, macroSimplifyUnion };
|
|
114
|
+
|
|
115
|
+
//# 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\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 }: { propertyName: string; values: Array<string>; enumName?: string }) {\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\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 }: { parentName: string | null | undefined; propName: string; enumSuffix: string }) {\n return defineMacro({\n name: 'enum-name',\n schema(node) {\n const enumNode = narrowSchema(node, 'enum')\n if (enumNode?.primitive === 'boolean') return { ...node, name: null }\n if (enumNode) return { ...node, name: enumPropName(parentName, propName, enumSuffix) }\n return undefined\n },\n })\n}\n","import { isScalarPrimitive } from '../constants.ts'\nimport { defineMacro } from '../defineMacro.ts'\nimport { narrowSchema } from '../guards.ts'\nimport type { SchemaNode } from '../nodes/schema.ts'\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\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"],"mappings":";;;;;;;;;;;;;;;AAeA,SAAgB,uBAAuB,EAAE,cAAc,QAAQ,YAAgF;CAC7I,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,cAA+F;CACnJ,OAAO,YAAY;EACjB,MAAM;EACN,OAAO,MAAM;GACX,MAAM,WAAW,aAAa,MAAM,MAAM;GAC1C,IAAI,UAAU,cAAc,WAAW,OAAO;IAAE,GAAG;IAAM,MAAM;GAAK;GACpE,IAAI,UAAU,OAAO;IAAE,GAAG;IAAM,MAAM,aAAa,YAAY,UAAU,UAAU;GAAE;EAEvF;CACF,CAAC;AACH;;;;;;;;;;;;ACVA,MAAa,qBAAqB,YAAY;CAC5C,MAAM;CACN,OAAO,MAAM;EACX,MAAM,YAAY,aAAa,MAAM,OAAO;EAC5C,IAAI,CAAC,WAAW,SAAS,QAAQ,OAAO,KAAA;EAExC,MAAM,aAAa,qBAAqB,UAAU,OAAO;EACzD,IAAI,WAAW,WAAW,UAAU,QAAQ,QAAQ,OAAO,KAAA;EAE3D,OAAO;GAAE,GAAG;GAAW,SAAS;EAAW;CAC7C;AACF,CAAC;;;;AAKD,SAAS,qBAAqB,SAA+C;CAC3E,MAAM,mBAAmB,IAAI,IAAI,QAAQ,QAAQ,WAAW,kBAAkB,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,IAAI,CAAC;CAC9G,IAAI,CAAC,iBAAiB,MAAM,OAAO;CAEnC,OAAO,QAAQ,QAAQ,WAAW;EAChC,MAAM,WAAW,aAAa,QAAQ,MAAM;EAC5C,IAAI,CAAC,UAAU,OAAO;EAEtB,MAAM,YAAY,SAAS;EAC3B,IAAI,CAAC,WAAW,OAAO;EAGvB,KADuB,SAAS,iBAAiB,UAAU,SAAS,YAAY,UAAU,MACpE,GAAG,OAAO;EAEhC,IAAI,iBAAiB,IAAI,SAAS,GAAG,OAAO;EAC5C,KAAK,cAAc,aAAa,cAAc,cAAc,iBAAiB,IAAI,SAAS,KAAK,iBAAiB,IAAI,QAAQ,IAAI,OAAO;EAEvI,OAAO;CACT,CAAC;AACH"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { n as __name } from "./chunk-CNktS9qV.js";
|
|
2
|
+
import { A as FunctionParametersNode, N as TypeExpression, P as TypeLiteralNode, f as OperationNode, k as FunctionParameterNode, w as ParameterNode } from "./index-BzjwdK2M.js";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/operationParams.d.ts
|
|
5
|
+
declare function caseParams(params: Array<ParameterNode>, casing: 'camelcase' | undefined): Array<ParameterNode>;
|
|
6
|
+
/**
|
|
7
|
+
* Named type for a group of parameters (query or header) emitted as a single typed parameter.
|
|
8
|
+
*/
|
|
9
|
+
type ParamGroupType = {
|
|
10
|
+
/**
|
|
11
|
+
* Type expression for the group, a plain group-name reference.
|
|
12
|
+
*/
|
|
13
|
+
type: TypeExpression;
|
|
14
|
+
/**
|
|
15
|
+
* Whether the parameter group is optional.
|
|
16
|
+
*/
|
|
17
|
+
optional: boolean;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Resolver interface for {@link createOperationParams}.
|
|
21
|
+
*
|
|
22
|
+
* `ResolverTs` from `@kubb/plugin-ts` satisfies this interface and can be passed directly.
|
|
23
|
+
*/
|
|
24
|
+
type OperationParamsResolver = {
|
|
25
|
+
/**
|
|
26
|
+
* Resolves the type name for an individual parameter.
|
|
27
|
+
*
|
|
28
|
+
* @example Individual path parameter name
|
|
29
|
+
* `resolver.resolveParamName(node, param) // → 'DeletePetPathPetId'`
|
|
30
|
+
*/
|
|
31
|
+
resolveParamName(node: OperationNode, param: ParameterNode): string;
|
|
32
|
+
/**
|
|
33
|
+
* Resolves the request body type name.
|
|
34
|
+
*
|
|
35
|
+
* @example Request body type name
|
|
36
|
+
* `resolver.resolveDataName(node) // → 'CreatePetData'`
|
|
37
|
+
*/
|
|
38
|
+
resolveDataName(node: OperationNode): string;
|
|
39
|
+
/**
|
|
40
|
+
* Resolves the grouped path parameters type name.
|
|
41
|
+
* When the return value equals `resolveParamName`, no indexed access is emitted.
|
|
42
|
+
*
|
|
43
|
+
* @example Grouped path params type name
|
|
44
|
+
* `resolver.resolvePathParamsName(node, param) // → 'DeletePetPathParams'`
|
|
45
|
+
*/
|
|
46
|
+
resolvePathParamsName(node: OperationNode, param: ParameterNode): string;
|
|
47
|
+
/**
|
|
48
|
+
* Resolves the grouped query parameters type name.
|
|
49
|
+
* When the return value equals `resolveParamName`, an inline struct type is emitted instead.
|
|
50
|
+
*
|
|
51
|
+
* @example Grouped query params type name
|
|
52
|
+
* `resolver.resolveQueryParamsName(node, param) // → 'FindPetsByStatusQueryParams'`
|
|
53
|
+
*/
|
|
54
|
+
resolveQueryParamsName(node: OperationNode, param: ParameterNode): string;
|
|
55
|
+
/**
|
|
56
|
+
* Resolves the grouped header parameters type name.
|
|
57
|
+
* When the return value equals `resolveParamName`, an inline struct type is emitted instead.
|
|
58
|
+
*
|
|
59
|
+
* @example Grouped header params type name
|
|
60
|
+
* `resolver.resolveHeaderParamsName(node, param) // → 'DeletePetHeaderParams'`
|
|
61
|
+
*/
|
|
62
|
+
resolveHeaderParamsName(node: OperationNode, param: ParameterNode): string;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Options for {@link createOperationParams}.
|
|
66
|
+
*/
|
|
67
|
+
type CreateOperationParamsOptions = {
|
|
68
|
+
/**
|
|
69
|
+
* How all operation parameters are grouped in the function signature.
|
|
70
|
+
* - `'object'` wraps all params into a single destructured object `{ petId, data, params }`
|
|
71
|
+
* - `'inline'` emits each param category as a separate top-level parameter
|
|
72
|
+
*/
|
|
73
|
+
paramsType: 'object' | 'inline';
|
|
74
|
+
/**
|
|
75
|
+
* How path parameters are emitted when `paramsType` is `'inline'`.
|
|
76
|
+
* - `'object'` groups them as `{ petId, storeId }: PathParams`
|
|
77
|
+
* - `'inline'` spreads them as individual parameters `petId: string, storeId: string`
|
|
78
|
+
* - `'inlineSpread'` emits a single rest parameter `...pathParams: PathParams`
|
|
79
|
+
*/
|
|
80
|
+
pathParamsType: 'object' | 'inline' | 'inlineSpread';
|
|
81
|
+
/**
|
|
82
|
+
* Converts parameter names to camelCase before output.
|
|
83
|
+
*/
|
|
84
|
+
paramsCasing?: 'camelcase';
|
|
85
|
+
/**
|
|
86
|
+
* Resolver for parameter and request body type names.
|
|
87
|
+
* Pass `ResolverTs` from `@kubb/plugin-ts` directly.
|
|
88
|
+
* When omitted, falls back to the schema primitive or `'unknown'`.
|
|
89
|
+
*/
|
|
90
|
+
resolver?: OperationParamsResolver;
|
|
91
|
+
/**
|
|
92
|
+
* Default value for the path parameters binding when `pathParamsType` is `'object'`.
|
|
93
|
+
* Falls back to `'{}'` when all path params are optional.
|
|
94
|
+
*/
|
|
95
|
+
pathParamsDefault?: string;
|
|
96
|
+
/**
|
|
97
|
+
* Extra parameters appended after the standard operation parameters.
|
|
98
|
+
*
|
|
99
|
+
* @example Plugin-specific trailing parameter
|
|
100
|
+
* ```ts
|
|
101
|
+
* extraParams: [createFunctionParameter({ name: 'options', type: 'Partial<RequestOptions>', default: '{}' })]
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
extraParams?: Array<FunctionParameterNode>;
|
|
105
|
+
/**
|
|
106
|
+
* Override the default parameter names used for body, query, header, and rest-path groups.
|
|
107
|
+
*
|
|
108
|
+
* Useful when targeting languages or frameworks with different naming conventions.
|
|
109
|
+
*
|
|
110
|
+
* @default { data: 'data', params: 'params', headers: 'headers', path: 'pathParams' }
|
|
111
|
+
*/
|
|
112
|
+
paramNames?: {
|
|
113
|
+
/**
|
|
114
|
+
* Name for the request body parameter.
|
|
115
|
+
* @default 'data'
|
|
116
|
+
*/
|
|
117
|
+
data?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Name for the query parameters group parameter.
|
|
120
|
+
* @default 'params'
|
|
121
|
+
*/
|
|
122
|
+
params?: string;
|
|
123
|
+
/**
|
|
124
|
+
* Name for the header parameters group parameter.
|
|
125
|
+
* @default 'headers'
|
|
126
|
+
*/
|
|
127
|
+
headers?: string;
|
|
128
|
+
/**
|
|
129
|
+
* Name for the rest path-parameters parameter when `pathParamsType` is `'inlineSpread'`.
|
|
130
|
+
* @default 'pathParams'
|
|
131
|
+
*/
|
|
132
|
+
path?: string;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Transforms every resolved type name before it lands in a parameter node, for framework-level
|
|
136
|
+
* type wrappers.
|
|
137
|
+
*
|
|
138
|
+
* @example Vue Query, wrap every parameter type with `MaybeRefOrGetter`
|
|
139
|
+
* `typeWrapper: (t) => \`MaybeRefOrGetter<${t}>\``
|
|
140
|
+
*/
|
|
141
|
+
typeWrapper?: (type: string) => string;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Resolves the {@link TypeExpression} for an individual parameter.
|
|
145
|
+
*
|
|
146
|
+
* Without a resolver, it falls back to the schema primitive (a plain type-name string). When the
|
|
147
|
+
* parameter belongs to a named group, it emits an {@link IndexedAccessTypeNode} like
|
|
148
|
+
* `GroupParams['petId']`, otherwise the resolved individual name.
|
|
149
|
+
*/
|
|
150
|
+
declare function resolveParamType({
|
|
151
|
+
node,
|
|
152
|
+
param,
|
|
153
|
+
resolver
|
|
154
|
+
}: {
|
|
155
|
+
node: OperationNode;
|
|
156
|
+
param: ParameterNode;
|
|
157
|
+
resolver: OperationParamsResolver | undefined;
|
|
158
|
+
}): TypeExpression;
|
|
159
|
+
/**
|
|
160
|
+
* Converts an `OperationNode` into function parameters for code generation.
|
|
161
|
+
*
|
|
162
|
+
* Centralizes parameter grouping logic for all plugins. `paramsType` chooses between one
|
|
163
|
+
* destructured object parameter (`object`) and separate top-level parameters (`inline`), while
|
|
164
|
+
* `pathParamsType` controls how path params render in inline mode. Provide a `resolver` for type
|
|
165
|
+
* name resolution and `extraParams` for plugin-specific trailing parameters such as an `options` object.
|
|
166
|
+
*/
|
|
167
|
+
declare function createOperationParams(node: OperationNode, options: CreateOperationParamsOptions): FunctionParametersNode;
|
|
168
|
+
/**
|
|
169
|
+
* Shared arguments for building a query or header parameter group.
|
|
170
|
+
*/
|
|
171
|
+
type BuildGroupArgs = {
|
|
172
|
+
name: string;
|
|
173
|
+
node: OperationNode;
|
|
174
|
+
params: Array<ParameterNode>;
|
|
175
|
+
groupType: ParamGroupType | null;
|
|
176
|
+
resolver: OperationParamsResolver | undefined;
|
|
177
|
+
wrapType: (type: string) => string;
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Builds a single {@link FunctionParameterNode} for a query or header group.
|
|
181
|
+
* Returns an empty array when there are no params to emit.
|
|
182
|
+
*
|
|
183
|
+
* A pre-resolved `groupType` emits `name: GroupType`. Otherwise it builds an inline
|
|
184
|
+
* {@link TypeLiteralNode} from the individual params.
|
|
185
|
+
*/
|
|
186
|
+
declare function buildGroupParam(args: BuildGroupArgs): Array<FunctionParameterNode>;
|
|
187
|
+
/**
|
|
188
|
+
* Builds a {@link TypeLiteralNode} for an inline anonymous type grouping named fields.
|
|
189
|
+
*
|
|
190
|
+
* Used when query or header parameters have no dedicated group type name.
|
|
191
|
+
* Each language printer renders this appropriately (TypeScript: `{ petId: string; name?: string }`).
|
|
192
|
+
*/
|
|
193
|
+
declare function buildTypeLiteral({
|
|
194
|
+
node,
|
|
195
|
+
params,
|
|
196
|
+
resolver
|
|
197
|
+
}: {
|
|
198
|
+
node: OperationNode;
|
|
199
|
+
params: Array<ParameterNode>;
|
|
200
|
+
resolver: OperationParamsResolver | undefined;
|
|
201
|
+
}): TypeLiteralNode;
|
|
202
|
+
//#endregion
|
|
203
|
+
export { buildTypeLiteral as a, resolveParamType as c, buildGroupParam as i, OperationParamsResolver as n, caseParams as o, ParamGroupType as r, createOperationParams as s, BuildGroupArgs as t };
|
|
204
|
+
//# sourceMappingURL=operationParams-BZ07xDm0.d.ts.map
|