@kubb/plugin-ts 5.0.0-alpha.22 → 5.0.0-alpha.24
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 +1680 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +529 -4
- package/dist/index.js +1653 -52
- package/dist/index.js.map +1 -1
- package/package.json +3 -42
- package/src/components/Enum.tsx +2 -7
- package/src/components/Type.tsx +11 -5
- package/src/generators/typeGenerator.tsx +36 -24
- package/src/generators/typeGeneratorLegacy.tsx +28 -38
- package/src/index.ts +13 -1
- package/src/plugin.ts +42 -23
- package/src/presets.ts +16 -34
- package/src/printers/functionPrinter.ts +194 -0
- package/src/printers/printerTs.ts +23 -7
- package/src/resolvers/resolverTs.ts +10 -47
- package/src/resolvers/resolverTsLegacy.ts +4 -31
- package/src/types.ts +169 -254
- package/src/utils.ts +103 -0
- package/dist/Type-Bf8raoQX.cjs +0 -124
- package/dist/Type-Bf8raoQX.cjs.map +0 -1
- package/dist/Type-BpXxT4l_.js +0 -113
- package/dist/Type-BpXxT4l_.js.map +0 -1
- package/dist/builderTs-COUg3xtQ.cjs +0 -135
- package/dist/builderTs-COUg3xtQ.cjs.map +0 -1
- package/dist/builderTs-DPpkJKd1.js +0 -131
- package/dist/builderTs-DPpkJKd1.js.map +0 -1
- package/dist/builders.cjs +0 -3
- package/dist/builders.d.ts +0 -23
- package/dist/builders.js +0 -2
- package/dist/casing-BJHFg-zZ.js +0 -84
- package/dist/casing-BJHFg-zZ.js.map +0 -1
- package/dist/casing-DHfdqpLi.cjs +0 -107
- package/dist/casing-DHfdqpLi.cjs.map +0 -1
- package/dist/chunk-ByKO4r7w.cjs +0 -38
- package/dist/components.cjs +0 -4
- package/dist/components.d.ts +0 -71
- package/dist/components.js +0 -2
- package/dist/generators-DFDut8o-.js +0 -555
- package/dist/generators-DFDut8o-.js.map +0 -1
- package/dist/generators-DKd7MYbx.cjs +0 -567
- package/dist/generators-DKd7MYbx.cjs.map +0 -1
- package/dist/generators.cjs +0 -4
- package/dist/generators.d.ts +0 -12
- package/dist/generators.js +0 -2
- package/dist/printerTs-BcHudagv.cjs +0 -594
- package/dist/printerTs-BcHudagv.cjs.map +0 -1
- package/dist/printerTs-CMBCOuqd.js +0 -558
- package/dist/printerTs-CMBCOuqd.js.map +0 -1
- package/dist/printers.cjs +0 -3
- package/dist/printers.d.ts +0 -81
- package/dist/printers.js +0 -2
- package/dist/resolverTsLegacy-CPiqqsO6.js +0 -185
- package/dist/resolverTsLegacy-CPiqqsO6.js.map +0 -1
- package/dist/resolverTsLegacy-CuR9XbKk.cjs +0 -196
- package/dist/resolverTsLegacy-CuR9XbKk.cjs.map +0 -1
- package/dist/resolvers.cjs +0 -4
- package/dist/resolvers.d.ts +0 -52
- package/dist/resolvers.js +0 -2
- package/dist/types-CRtcZOCz.d.ts +0 -374
- package/src/builders/builderTs.ts +0 -107
- package/src/builders/index.ts +0 -1
- package/src/components/index.ts +0 -2
- package/src/generators/index.ts +0 -2
- package/src/printers/index.ts +0 -1
- package/src/resolvers/index.ts +0 -2
package/dist/Type-Bf8raoQX.cjs
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
require("./chunk-ByKO4r7w.cjs");
|
|
2
|
-
const require_casing = require("./casing-DHfdqpLi.cjs");
|
|
3
|
-
const require_printerTs = require("./printerTs-BcHudagv.cjs");
|
|
4
|
-
let _kubb_ast = require("@kubb/ast");
|
|
5
|
-
let _kubb_react_fabric = require("@kubb/react-fabric");
|
|
6
|
-
let _kubb_fabric_core_parsers_typescript = require("@kubb/fabric-core/parsers/typescript");
|
|
7
|
-
let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
|
|
8
|
-
//#region src/components/Enum.tsx
|
|
9
|
-
/**
|
|
10
|
-
* Resolves the runtime identifier name and the TypeScript type name for an enum schema node.
|
|
11
|
-
*
|
|
12
|
-
* The raw `node.name` may be a YAML key such as `"enumNames.Type"` which is not a
|
|
13
|
-
* valid TypeScript identifier. The resolver normalizes it; for inline enum
|
|
14
|
-
* properties the adapter already emits a PascalCase+suffix name so resolution is typically a no-op.
|
|
15
|
-
*/
|
|
16
|
-
function getEnumNames({ node, enumType, enumTypeSuffix, resolver }) {
|
|
17
|
-
const resolved = resolver.default(node.name, "type");
|
|
18
|
-
return {
|
|
19
|
-
enumName: enumType === "asPascalConst" ? resolved : require_casing.camelCase(node.name),
|
|
20
|
-
typeName: require_printerTs.ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) ? resolver.resolveEnumKeyTypedName(node, enumTypeSuffix) : resolved,
|
|
21
|
-
refName: resolved
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Renders the enum declaration(s) for a single named `EnumSchemaNode`.
|
|
26
|
-
*
|
|
27
|
-
* Depending on `enumType` this may emit:
|
|
28
|
-
* - A runtime object (`asConst` / `asPascalConst`) plus a `typeof` type alias
|
|
29
|
-
* - A `const enum` or plain `enum` declaration (`constEnum` / `enum`)
|
|
30
|
-
* - A union literal type alias (`literal`)
|
|
31
|
-
*
|
|
32
|
-
* The emitted `File.Source` nodes carry the resolved names so that the barrel
|
|
33
|
-
* index picks up the correct export identifiers.
|
|
34
|
-
*/
|
|
35
|
-
function Enum({ node, enumType, enumTypeSuffix, enumKeyCasing, resolver }) {
|
|
36
|
-
const { enumName, typeName } = getEnumNames({
|
|
37
|
-
node,
|
|
38
|
-
enumType,
|
|
39
|
-
enumTypeSuffix,
|
|
40
|
-
resolver
|
|
41
|
-
});
|
|
42
|
-
const [nameNode, typeNode] = require_printerTs.createEnumDeclaration({
|
|
43
|
-
name: enumName,
|
|
44
|
-
typeName,
|
|
45
|
-
enums: node.namedEnumValues?.map((v) => [require_printerTs.trimQuotes(v.name.toString()), v.value]) ?? node.enumValues?.filter((v) => v !== null && v !== void 0).map((v) => [require_printerTs.trimQuotes(v.toString()), v]) ?? [],
|
|
46
|
-
type: enumType,
|
|
47
|
-
enumKeyCasing
|
|
48
|
-
});
|
|
49
|
-
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [nameNode && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
50
|
-
name: enumName,
|
|
51
|
-
isExportable: true,
|
|
52
|
-
isIndexable: true,
|
|
53
|
-
isTypeOnly: false,
|
|
54
|
-
children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(nameNode)
|
|
55
|
-
}), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
56
|
-
name: typeName,
|
|
57
|
-
isIndexable: true,
|
|
58
|
-
isExportable: require_printerTs.ENUM_TYPES_WITH_RUNTIME_VALUE.has(enumType),
|
|
59
|
-
isTypeOnly: require_printerTs.ENUM_TYPES_WITH_TYPE_ONLY.has(enumType),
|
|
60
|
-
children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(typeNode)
|
|
61
|
-
})] });
|
|
62
|
-
}
|
|
63
|
-
//#endregion
|
|
64
|
-
//#region src/components/Type.tsx
|
|
65
|
-
function Type({ name, typedName, node, keysToOmit, optionalType, arrayType, syntaxType, enumType, enumTypeSuffix, enumKeyCasing, description, resolver }) {
|
|
66
|
-
const resolvedDescription = description || node?.description;
|
|
67
|
-
const enumSchemaNodes = (0, _kubb_ast.collect)(node, { schema(n) {
|
|
68
|
-
const enumNode = (0, _kubb_ast.narrowSchema)(n, _kubb_ast.schemaTypes.enum);
|
|
69
|
-
if (enumNode?.name) return enumNode;
|
|
70
|
-
} });
|
|
71
|
-
const output = require_printerTs.printerTs({
|
|
72
|
-
optionalType,
|
|
73
|
-
arrayType,
|
|
74
|
-
enumType,
|
|
75
|
-
enumTypeSuffix,
|
|
76
|
-
typeName: name,
|
|
77
|
-
syntaxType,
|
|
78
|
-
description: resolvedDescription,
|
|
79
|
-
keysToOmit,
|
|
80
|
-
resolver
|
|
81
|
-
}).print(node);
|
|
82
|
-
if (!output) return;
|
|
83
|
-
const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {
|
|
84
|
-
return {
|
|
85
|
-
node,
|
|
86
|
-
...getEnumNames({
|
|
87
|
-
node,
|
|
88
|
-
enumType,
|
|
89
|
-
enumTypeSuffix,
|
|
90
|
-
resolver
|
|
91
|
-
})
|
|
92
|
-
};
|
|
93
|
-
});
|
|
94
|
-
const shouldExportEnums = enumType !== "inlineLiteral";
|
|
95
|
-
const shouldExportType = enumType === "inlineLiteral" || enums.every((item) => item.typeName !== name);
|
|
96
|
-
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [shouldExportEnums && enums.map(({ node }) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Enum, {
|
|
97
|
-
node,
|
|
98
|
-
enumType,
|
|
99
|
-
enumTypeSuffix,
|
|
100
|
-
enumKeyCasing,
|
|
101
|
-
resolver
|
|
102
|
-
})), shouldExportType && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
103
|
-
name: typedName,
|
|
104
|
-
isTypeOnly: true,
|
|
105
|
-
isExportable: true,
|
|
106
|
-
isIndexable: true,
|
|
107
|
-
children: output
|
|
108
|
-
})] });
|
|
109
|
-
}
|
|
110
|
-
//#endregion
|
|
111
|
-
Object.defineProperty(exports, "Enum", {
|
|
112
|
-
enumerable: true,
|
|
113
|
-
get: function() {
|
|
114
|
-
return Enum;
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
Object.defineProperty(exports, "Type", {
|
|
118
|
-
enumerable: true,
|
|
119
|
-
get: function() {
|
|
120
|
-
return Type;
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
//# sourceMappingURL=Type-Bf8raoQX.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Type-Bf8raoQX.cjs","names":["camelCase","ENUM_TYPES_WITH_KEY_SUFFIX","trimQuotes","File","ENUM_TYPES_WITH_RUNTIME_VALUE","ENUM_TYPES_WITH_TYPE_ONLY","schemaTypes","printerTs","File"],"sources":["../src/components/Enum.tsx","../src/components/Type.tsx"],"sourcesContent":["import { camelCase, trimQuotes } from '@internals/utils'\nimport type { EnumSchemaNode } from '@kubb/ast/types'\nimport { safePrint } from '@kubb/fabric-core/parsers/typescript'\nimport { File } from '@kubb/react-fabric'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\nimport { ENUM_TYPES_WITH_KEY_SUFFIX, ENUM_TYPES_WITH_RUNTIME_VALUE, ENUM_TYPES_WITH_TYPE_ONLY } from '../constants.ts'\nimport * as factory from '../factory.ts'\nimport type { PluginTs, ResolverTs } from '../types.ts'\n\ntype Props = {\n node: EnumSchemaNode\n enumType: PluginTs['resolvedOptions']['enumType']\n enumTypeSuffix: PluginTs['resolvedOptions']['enumTypeSuffix']\n enumKeyCasing: PluginTs['resolvedOptions']['enumKeyCasing']\n resolver: ResolverTs\n}\n\n/**\n * Resolves the runtime identifier name and the TypeScript type name for an enum schema node.\n *\n * The raw `node.name` may be a YAML key such as `\"enumNames.Type\"` which is not a\n * valid TypeScript identifier. The resolver normalizes it; for inline enum\n * properties the adapter already emits a PascalCase+suffix name so resolution is typically a no-op.\n */\nexport function getEnumNames({\n node,\n enumType,\n enumTypeSuffix,\n resolver,\n}: {\n node: EnumSchemaNode\n enumType: PluginTs['resolvedOptions']['enumType']\n enumTypeSuffix: PluginTs['resolvedOptions']['enumTypeSuffix']\n resolver: ResolverTs\n}): {\n enumName: string\n typeName: string\n /**\n * The PascalCase name that `$ref` importers will use to reference this enum type.\n * For `asConst`/`asPascalConst` this differs from `typeName` (which has a `Key` suffix).\n */\n refName: string\n} {\n const resolved = resolver.default(node.name!, 'type')\n const enumName = enumType === 'asPascalConst' ? resolved : camelCase(node.name!)\n const typeName = ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) ? resolver.resolveEnumKeyTypedName(node, enumTypeSuffix) : resolved\n\n return { enumName, typeName, refName: resolved }\n}\n\n/**\n * Renders the enum declaration(s) for a single named `EnumSchemaNode`.\n *\n * Depending on `enumType` this may emit:\n * - A runtime object (`asConst` / `asPascalConst`) plus a `typeof` type alias\n * - A `const enum` or plain `enum` declaration (`constEnum` / `enum`)\n * - A union literal type alias (`literal`)\n *\n * The emitted `File.Source` nodes carry the resolved names so that the barrel\n * index picks up the correct export identifiers.\n */\nexport function Enum({ node, enumType, enumTypeSuffix, enumKeyCasing, resolver }: Props): FabricReactNode {\n const { enumName, typeName } = getEnumNames({ node, enumType, enumTypeSuffix, resolver })\n\n const [nameNode, typeNode] = factory.createEnumDeclaration({\n name: enumName,\n typeName,\n enums: (node.namedEnumValues?.map((v) => [trimQuotes(v.name.toString()), v.value]) ??\n node.enumValues?.filter((v): v is NonNullable<typeof v> => v !== null && v !== undefined).map((v) => [trimQuotes(v.toString()), v]) ??\n []) as unknown as Array<[string, string]>,\n type: enumType,\n enumKeyCasing,\n })\n\n return (\n <>\n {nameNode && (\n <File.Source name={enumName} isExportable isIndexable isTypeOnly={false}>\n {safePrint(nameNode)}\n </File.Source>\n )}\n <File.Source name={typeName} isIndexable isExportable={ENUM_TYPES_WITH_RUNTIME_VALUE.has(enumType)} isTypeOnly={ENUM_TYPES_WITH_TYPE_ONLY.has(enumType)}>\n {safePrint(typeNode)}\n </File.Source>\n </>\n )\n}\n","import { collect, narrowSchema, schemaTypes } from '@kubb/ast'\nimport type { EnumSchemaNode, SchemaNode } from '@kubb/ast/types'\nimport { File } from '@kubb/react-fabric'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\nimport { printerTs } from '../printers/printerTs.ts'\nimport type { PluginTs } from '../types.ts'\nimport { Enum, getEnumNames } from './Enum.tsx'\n\ntype Props = {\n name: string\n typedName: string\n node: SchemaNode\n optionalType: PluginTs['resolvedOptions']['optionalType']\n arrayType: PluginTs['resolvedOptions']['arrayType']\n enumType: PluginTs['resolvedOptions']['enumType']\n enumTypeSuffix: PluginTs['resolvedOptions']['enumTypeSuffix']\n enumKeyCasing: PluginTs['resolvedOptions']['enumKeyCasing']\n syntaxType: PluginTs['resolvedOptions']['syntaxType']\n resolver: PluginTs['resolvedOptions']['resolver']\n description?: string\n keysToOmit?: string[]\n}\n\nexport function Type({\n name,\n typedName,\n node,\n keysToOmit,\n optionalType,\n arrayType,\n syntaxType,\n enumType,\n enumTypeSuffix,\n enumKeyCasing,\n description,\n resolver,\n}: Props): FabricReactNode {\n const resolvedDescription = description || node?.description\n const enumSchemaNodes = collect<EnumSchemaNode>(node, {\n schema(n): EnumSchemaNode | undefined {\n const enumNode = narrowSchema(n, schemaTypes.enum)\n if (enumNode?.name) return enumNode\n },\n })\n\n const printer = printerTs({\n optionalType,\n arrayType,\n enumType,\n enumTypeSuffix,\n typeName: name,\n syntaxType,\n description: resolvedDescription,\n keysToOmit,\n resolver,\n })\n const output = printer.print(node)\n\n if (!output) {\n return\n }\n\n const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {\n return {\n node,\n ...getEnumNames({ node, enumType, enumTypeSuffix, resolver }),\n }\n })\n\n // Skip enum exports when using inlineLiteral\n const shouldExportEnums = enumType !== 'inlineLiteral'\n const shouldExportType = enumType === 'inlineLiteral' || enums.every((item) => item.typeName !== name)\n\n return (\n <>\n {shouldExportEnums &&\n enums.map(({ node }) => <Enum node={node} enumType={enumType} enumTypeSuffix={enumTypeSuffix} enumKeyCasing={enumKeyCasing} resolver={resolver} />)}\n {shouldExportType && (\n <File.Source name={typedName} isTypeOnly isExportable isIndexable>\n {output}\n </File.Source>\n )}\n </>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;AAwBA,SAAgB,aAAa,EAC3B,MACA,UACA,gBACA,YAcA;CACA,MAAM,WAAW,SAAS,QAAQ,KAAK,MAAO,OAAO;AAIrD,Q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AO,GAA+B;EACpC,MAAM,YAAA,GAAA,UAAA,cAAwB,GAAGC,UAAAA,YAAY,KAAK;AAClD,MAAI,UAAU,KAAM,QAAO;IAE9B,CAAC;CAaF,MAAM,SAXUC,kBAAAA,UAAU;EACxB;EACA;EACA;EACA;EACA,UAAU;EACV;EACA,aAAa;EACb;EACA;EACD,CAAC,CACqB,MAAM,KAAK;AAElC,KAAI,CAAC,OACH;CAGF,MAAM,QAAQ,CAAC,GAAG,IAAI,IAAI,gBAAgB,KAAK,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,SAAS;AACzF,SAAO;GACL;GACA,GAAG,aAAa;IAAE;IAAM;IAAU;IAAgB;IAAU,CAAC;GAC9D;GACD;CAGF,MAAM,oBAAoB,aAAa;CACvC,MAAM,mBAAmB,aAAa,mBAAmB,MAAM,OAAO,SAAS,KAAK,aAAa,KAAK;AAEtG,QACE,iBAAA,GAAA,+BAAA,MAAA,+BAAA,UAAA,EAAA,UAAA,CACG,qBACC,MAAM,KAAK,EAAE,WAAW,iBAAA,GAAA,+BAAA,KAAC,MAAD;EAAY;EAAgB;EAA0B;EAA+B;EAAyB;EAAY,CAAA,CAAC,EACpJ,oBACC,iBAAA,GAAA,+BAAA,KAACC,mBAAAA,KAAK,QAAN;EAAa,MAAM;EAAW,YAAA;EAAW,cAAA;EAAa,aAAA;YACnD;EACW,CAAA,CAEf,EAAA,CAAA"}
|
package/dist/Type-BpXxT4l_.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { t as camelCase } from "./casing-BJHFg-zZ.js";
|
|
3
|
-
import { a as ENUM_TYPES_WITH_TYPE_ONLY, i as ENUM_TYPES_WITH_RUNTIME_VALUE, n as createEnumDeclaration, o as trimQuotes, r as ENUM_TYPES_WITH_KEY_SUFFIX, t as printerTs } from "./printerTs-CMBCOuqd.js";
|
|
4
|
-
import { collect, narrowSchema, schemaTypes } from "@kubb/ast";
|
|
5
|
-
import { File } from "@kubb/react-fabric";
|
|
6
|
-
import { safePrint } from "@kubb/fabric-core/parsers/typescript";
|
|
7
|
-
import { Fragment, jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
|
|
8
|
-
//#region src/components/Enum.tsx
|
|
9
|
-
/**
|
|
10
|
-
* Resolves the runtime identifier name and the TypeScript type name for an enum schema node.
|
|
11
|
-
*
|
|
12
|
-
* The raw `node.name` may be a YAML key such as `"enumNames.Type"` which is not a
|
|
13
|
-
* valid TypeScript identifier. The resolver normalizes it; for inline enum
|
|
14
|
-
* properties the adapter already emits a PascalCase+suffix name so resolution is typically a no-op.
|
|
15
|
-
*/
|
|
16
|
-
function getEnumNames({ node, enumType, enumTypeSuffix, resolver }) {
|
|
17
|
-
const resolved = resolver.default(node.name, "type");
|
|
18
|
-
return {
|
|
19
|
-
enumName: enumType === "asPascalConst" ? resolved : camelCase(node.name),
|
|
20
|
-
typeName: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) ? resolver.resolveEnumKeyTypedName(node, enumTypeSuffix) : resolved,
|
|
21
|
-
refName: resolved
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Renders the enum declaration(s) for a single named `EnumSchemaNode`.
|
|
26
|
-
*
|
|
27
|
-
* Depending on `enumType` this may emit:
|
|
28
|
-
* - A runtime object (`asConst` / `asPascalConst`) plus a `typeof` type alias
|
|
29
|
-
* - A `const enum` or plain `enum` declaration (`constEnum` / `enum`)
|
|
30
|
-
* - A union literal type alias (`literal`)
|
|
31
|
-
*
|
|
32
|
-
* The emitted `File.Source` nodes carry the resolved names so that the barrel
|
|
33
|
-
* index picks up the correct export identifiers.
|
|
34
|
-
*/
|
|
35
|
-
function Enum({ node, enumType, enumTypeSuffix, enumKeyCasing, resolver }) {
|
|
36
|
-
const { enumName, typeName } = getEnumNames({
|
|
37
|
-
node,
|
|
38
|
-
enumType,
|
|
39
|
-
enumTypeSuffix,
|
|
40
|
-
resolver
|
|
41
|
-
});
|
|
42
|
-
const [nameNode, typeNode] = createEnumDeclaration({
|
|
43
|
-
name: enumName,
|
|
44
|
-
typeName,
|
|
45
|
-
enums: node.namedEnumValues?.map((v) => [trimQuotes(v.name.toString()), v.value]) ?? node.enumValues?.filter((v) => v !== null && v !== void 0).map((v) => [trimQuotes(v.toString()), v]) ?? [],
|
|
46
|
-
type: enumType,
|
|
47
|
-
enumKeyCasing
|
|
48
|
-
});
|
|
49
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [nameNode && /* @__PURE__ */ jsx(File.Source, {
|
|
50
|
-
name: enumName,
|
|
51
|
-
isExportable: true,
|
|
52
|
-
isIndexable: true,
|
|
53
|
-
isTypeOnly: false,
|
|
54
|
-
children: safePrint(nameNode)
|
|
55
|
-
}), /* @__PURE__ */ jsx(File.Source, {
|
|
56
|
-
name: typeName,
|
|
57
|
-
isIndexable: true,
|
|
58
|
-
isExportable: ENUM_TYPES_WITH_RUNTIME_VALUE.has(enumType),
|
|
59
|
-
isTypeOnly: ENUM_TYPES_WITH_TYPE_ONLY.has(enumType),
|
|
60
|
-
children: safePrint(typeNode)
|
|
61
|
-
})] });
|
|
62
|
-
}
|
|
63
|
-
//#endregion
|
|
64
|
-
//#region src/components/Type.tsx
|
|
65
|
-
function Type({ name, typedName, node, keysToOmit, optionalType, arrayType, syntaxType, enumType, enumTypeSuffix, enumKeyCasing, description, resolver }) {
|
|
66
|
-
const resolvedDescription = description || node?.description;
|
|
67
|
-
const enumSchemaNodes = collect(node, { schema(n) {
|
|
68
|
-
const enumNode = narrowSchema(n, schemaTypes.enum);
|
|
69
|
-
if (enumNode?.name) return enumNode;
|
|
70
|
-
} });
|
|
71
|
-
const output = printerTs({
|
|
72
|
-
optionalType,
|
|
73
|
-
arrayType,
|
|
74
|
-
enumType,
|
|
75
|
-
enumTypeSuffix,
|
|
76
|
-
typeName: name,
|
|
77
|
-
syntaxType,
|
|
78
|
-
description: resolvedDescription,
|
|
79
|
-
keysToOmit,
|
|
80
|
-
resolver
|
|
81
|
-
}).print(node);
|
|
82
|
-
if (!output) return;
|
|
83
|
-
const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {
|
|
84
|
-
return {
|
|
85
|
-
node,
|
|
86
|
-
...getEnumNames({
|
|
87
|
-
node,
|
|
88
|
-
enumType,
|
|
89
|
-
enumTypeSuffix,
|
|
90
|
-
resolver
|
|
91
|
-
})
|
|
92
|
-
};
|
|
93
|
-
});
|
|
94
|
-
const shouldExportEnums = enumType !== "inlineLiteral";
|
|
95
|
-
const shouldExportType = enumType === "inlineLiteral" || enums.every((item) => item.typeName !== name);
|
|
96
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [shouldExportEnums && enums.map(({ node }) => /* @__PURE__ */ jsx(Enum, {
|
|
97
|
-
node,
|
|
98
|
-
enumType,
|
|
99
|
-
enumTypeSuffix,
|
|
100
|
-
enumKeyCasing,
|
|
101
|
-
resolver
|
|
102
|
-
})), shouldExportType && /* @__PURE__ */ jsx(File.Source, {
|
|
103
|
-
name: typedName,
|
|
104
|
-
isTypeOnly: true,
|
|
105
|
-
isExportable: true,
|
|
106
|
-
isIndexable: true,
|
|
107
|
-
children: output
|
|
108
|
-
})] });
|
|
109
|
-
}
|
|
110
|
-
//#endregion
|
|
111
|
-
export { Enum as n, Type as t };
|
|
112
|
-
|
|
113
|
-
//# sourceMappingURL=Type-BpXxT4l_.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Type-BpXxT4l_.js","names":["factory.createEnumDeclaration"],"sources":["../src/components/Enum.tsx","../src/components/Type.tsx"],"sourcesContent":["import { camelCase, trimQuotes } from '@internals/utils'\nimport type { EnumSchemaNode } from '@kubb/ast/types'\nimport { safePrint } from '@kubb/fabric-core/parsers/typescript'\nimport { File } from '@kubb/react-fabric'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\nimport { ENUM_TYPES_WITH_KEY_SUFFIX, ENUM_TYPES_WITH_RUNTIME_VALUE, ENUM_TYPES_WITH_TYPE_ONLY } from '../constants.ts'\nimport * as factory from '../factory.ts'\nimport type { PluginTs, ResolverTs } from '../types.ts'\n\ntype Props = {\n node: EnumSchemaNode\n enumType: PluginTs['resolvedOptions']['enumType']\n enumTypeSuffix: PluginTs['resolvedOptions']['enumTypeSuffix']\n enumKeyCasing: PluginTs['resolvedOptions']['enumKeyCasing']\n resolver: ResolverTs\n}\n\n/**\n * Resolves the runtime identifier name and the TypeScript type name for an enum schema node.\n *\n * The raw `node.name` may be a YAML key such as `\"enumNames.Type\"` which is not a\n * valid TypeScript identifier. The resolver normalizes it; for inline enum\n * properties the adapter already emits a PascalCase+suffix name so resolution is typically a no-op.\n */\nexport function getEnumNames({\n node,\n enumType,\n enumTypeSuffix,\n resolver,\n}: {\n node: EnumSchemaNode\n enumType: PluginTs['resolvedOptions']['enumType']\n enumTypeSuffix: PluginTs['resolvedOptions']['enumTypeSuffix']\n resolver: ResolverTs\n}): {\n enumName: string\n typeName: string\n /**\n * The PascalCase name that `$ref` importers will use to reference this enum type.\n * For `asConst`/`asPascalConst` this differs from `typeName` (which has a `Key` suffix).\n */\n refName: string\n} {\n const resolved = resolver.default(node.name!, 'type')\n const enumName = enumType === 'asPascalConst' ? resolved : camelCase(node.name!)\n const typeName = ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) ? resolver.resolveEnumKeyTypedName(node, enumTypeSuffix) : resolved\n\n return { enumName, typeName, refName: resolved }\n}\n\n/**\n * Renders the enum declaration(s) for a single named `EnumSchemaNode`.\n *\n * Depending on `enumType` this may emit:\n * - A runtime object (`asConst` / `asPascalConst`) plus a `typeof` type alias\n * - A `const enum` or plain `enum` declaration (`constEnum` / `enum`)\n * - A union literal type alias (`literal`)\n *\n * The emitted `File.Source` nodes carry the resolved names so that the barrel\n * index picks up the correct export identifiers.\n */\nexport function Enum({ node, enumType, enumTypeSuffix, enumKeyCasing, resolver }: Props): FabricReactNode {\n const { enumName, typeName } = getEnumNames({ node, enumType, enumTypeSuffix, resolver })\n\n const [nameNode, typeNode] = factory.createEnumDeclaration({\n name: enumName,\n typeName,\n enums: (node.namedEnumValues?.map((v) => [trimQuotes(v.name.toString()), v.value]) ??\n node.enumValues?.filter((v): v is NonNullable<typeof v> => v !== null && v !== undefined).map((v) => [trimQuotes(v.toString()), v]) ??\n []) as unknown as Array<[string, string]>,\n type: enumType,\n enumKeyCasing,\n })\n\n return (\n <>\n {nameNode && (\n <File.Source name={enumName} isExportable isIndexable isTypeOnly={false}>\n {safePrint(nameNode)}\n </File.Source>\n )}\n <File.Source name={typeName} isIndexable isExportable={ENUM_TYPES_WITH_RUNTIME_VALUE.has(enumType)} isTypeOnly={ENUM_TYPES_WITH_TYPE_ONLY.has(enumType)}>\n {safePrint(typeNode)}\n </File.Source>\n </>\n )\n}\n","import { collect, narrowSchema, schemaTypes } from '@kubb/ast'\nimport type { EnumSchemaNode, SchemaNode } from '@kubb/ast/types'\nimport { File } from '@kubb/react-fabric'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\nimport { printerTs } from '../printers/printerTs.ts'\nimport type { PluginTs } from '../types.ts'\nimport { Enum, getEnumNames } from './Enum.tsx'\n\ntype Props = {\n name: string\n typedName: string\n node: SchemaNode\n optionalType: PluginTs['resolvedOptions']['optionalType']\n arrayType: PluginTs['resolvedOptions']['arrayType']\n enumType: PluginTs['resolvedOptions']['enumType']\n enumTypeSuffix: PluginTs['resolvedOptions']['enumTypeSuffix']\n enumKeyCasing: PluginTs['resolvedOptions']['enumKeyCasing']\n syntaxType: PluginTs['resolvedOptions']['syntaxType']\n resolver: PluginTs['resolvedOptions']['resolver']\n description?: string\n keysToOmit?: string[]\n}\n\nexport function Type({\n name,\n typedName,\n node,\n keysToOmit,\n optionalType,\n arrayType,\n syntaxType,\n enumType,\n enumTypeSuffix,\n enumKeyCasing,\n description,\n resolver,\n}: Props): FabricReactNode {\n const resolvedDescription = description || node?.description\n const enumSchemaNodes = collect<EnumSchemaNode>(node, {\n schema(n): EnumSchemaNode | undefined {\n const enumNode = narrowSchema(n, schemaTypes.enum)\n if (enumNode?.name) return enumNode\n },\n })\n\n const printer = printerTs({\n optionalType,\n arrayType,\n enumType,\n enumTypeSuffix,\n typeName: name,\n syntaxType,\n description: resolvedDescription,\n keysToOmit,\n resolver,\n })\n const output = printer.print(node)\n\n if (!output) {\n return\n }\n\n const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {\n return {\n node,\n ...getEnumNames({ node, enumType, enumTypeSuffix, resolver }),\n }\n })\n\n // Skip enum exports when using inlineLiteral\n const shouldExportEnums = enumType !== 'inlineLiteral'\n const shouldExportType = enumType === 'inlineLiteral' || enums.every((item) => item.typeName !== name)\n\n return (\n <>\n {shouldExportEnums &&\n enums.map(({ node }) => <Enum node={node} enumType={enumType} enumTypeSuffix={enumTypeSuffix} enumKeyCasing={enumKeyCasing} resolver={resolver} />)}\n {shouldExportType && (\n <File.Source name={typedName} isTypeOnly isExportable isIndexable>\n {output}\n </File.Source>\n )}\n </>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;AAwBA,SAAgB,aAAa,EAC3B,MACA,UACA,gBACA,YAcA;CACA,MAAM,WAAW,SAAS,QAAQ,KAAK,MAAO,OAAO;AAIrD,QAAO;EAAE,UAHQ,aAAa,kBAAkB,WAAW,UAAU,KAAK,KAAM;EAG7D,UAFF,2BAA2B,IAAI,SAAS,GAAG,SAAS,wBAAwB,MAAM,eAAe,GAAG;EAExF,SAAS;EAAU;;;;;;;;;;;;;AAclD,SAAgB,KAAK,EAAE,MAAM,UAAU,gBAAgB,eAAe,YAAoC;CACxG,MAAM,EAAE,UAAU,aAAa,aAAa;EAAE;EAAM;EAAU;EAAgB;EAAU,CAAC;CAEzF,MAAM,CAAC,UAAU,YAAYA,sBAA8B;EACzD,MAAM;EACN;EACA,OAAQ,KAAK,iBAAiB,KAAK,MAAM,CAAC,WAAW,EAAE,KAAK,UAA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BAAA,UAAA,EAAA,UAAA,CACG,qBACC,MAAM,KAAK,EAAE,WAAW,oBAAC,MAAD;EAAY;EAAgB;EAA0B;EAA+B;EAAyB;EAAY,CAAA,CAAC,EACpJ,oBACC,oBAAC,KAAK,QAAN;EAAa,MAAM;EAAW,YAAA;EAAW,cAAA;EAAa,aAAA;YACnD;EACW,CAAA,CAEf,EAAA,CAAA"}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
require("./chunk-ByKO4r7w.cjs");
|
|
2
|
-
let _kubb_ast = require("@kubb/ast");
|
|
3
|
-
//#region src/builders/builderTs.ts
|
|
4
|
-
/**
|
|
5
|
-
* Default schema builder for `@kubb/plugin-ts`.
|
|
6
|
-
*
|
|
7
|
-
* Implements the `buildParams`, `buildData`, `buildResponses`, and `buildResponseUnion` helpers
|
|
8
|
-
* used by the TypeScript type generator to construct AST schema nodes for operation parameters,
|
|
9
|
-
* request bodies, and responses.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* import { builderTs } from '@kubb/plugin-ts'
|
|
14
|
-
*
|
|
15
|
-
* builderTs.buildData({ node, resolver })
|
|
16
|
-
* // → object schema with pathParams, queryParams, headerParams, data, url properties
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
const builderTs = (0, require("@kubb/core").defineBuilder)(() => ({
|
|
20
|
-
name: "default",
|
|
21
|
-
buildParams({ params, node, resolver }) {
|
|
22
|
-
return (0, _kubb_ast.createSchema)({
|
|
23
|
-
type: "object",
|
|
24
|
-
properties: params.map((param) => (0, _kubb_ast.createProperty)({
|
|
25
|
-
name: param.name,
|
|
26
|
-
required: param.required,
|
|
27
|
-
schema: (0, _kubb_ast.createSchema)({
|
|
28
|
-
type: "ref",
|
|
29
|
-
name: resolver.resolveParamName(node, param)
|
|
30
|
-
})
|
|
31
|
-
}))
|
|
32
|
-
});
|
|
33
|
-
},
|
|
34
|
-
buildData({ node, resolver }) {
|
|
35
|
-
const pathParams = node.parameters.filter((p) => p.in === "path");
|
|
36
|
-
const queryParams = node.parameters.filter((p) => p.in === "query");
|
|
37
|
-
const headerParams = node.parameters.filter((p) => p.in === "header");
|
|
38
|
-
return (0, _kubb_ast.createSchema)({
|
|
39
|
-
type: "object",
|
|
40
|
-
deprecated: node.deprecated,
|
|
41
|
-
properties: [
|
|
42
|
-
(0, _kubb_ast.createProperty)({
|
|
43
|
-
name: "data",
|
|
44
|
-
schema: node.requestBody?.schema ? (0, _kubb_ast.createSchema)({
|
|
45
|
-
type: "ref",
|
|
46
|
-
name: resolver.resolveDataTypedName(node),
|
|
47
|
-
optional: true
|
|
48
|
-
}) : (0, _kubb_ast.createSchema)({
|
|
49
|
-
type: "never",
|
|
50
|
-
optional: true
|
|
51
|
-
})
|
|
52
|
-
}),
|
|
53
|
-
(0, _kubb_ast.createProperty)({
|
|
54
|
-
name: "pathParams",
|
|
55
|
-
required: pathParams.length > 0,
|
|
56
|
-
schema: pathParams.length > 0 ? this.buildParams({
|
|
57
|
-
params: pathParams,
|
|
58
|
-
node,
|
|
59
|
-
resolver
|
|
60
|
-
}) : (0, _kubb_ast.createSchema)({ type: "never" })
|
|
61
|
-
}),
|
|
62
|
-
(0, _kubb_ast.createProperty)({
|
|
63
|
-
name: "queryParams",
|
|
64
|
-
schema: queryParams.length > 0 ? (0, _kubb_ast.createSchema)({
|
|
65
|
-
...this.buildParams({
|
|
66
|
-
params: queryParams,
|
|
67
|
-
node,
|
|
68
|
-
resolver
|
|
69
|
-
}),
|
|
70
|
-
optional: true
|
|
71
|
-
}) : (0, _kubb_ast.createSchema)({
|
|
72
|
-
type: "never",
|
|
73
|
-
optional: true
|
|
74
|
-
})
|
|
75
|
-
}),
|
|
76
|
-
(0, _kubb_ast.createProperty)({
|
|
77
|
-
name: "headerParams",
|
|
78
|
-
schema: headerParams.length > 0 ? (0, _kubb_ast.createSchema)({
|
|
79
|
-
...this.buildParams({
|
|
80
|
-
params: headerParams,
|
|
81
|
-
node,
|
|
82
|
-
resolver
|
|
83
|
-
}),
|
|
84
|
-
optional: true
|
|
85
|
-
}) : (0, _kubb_ast.createSchema)({
|
|
86
|
-
type: "never",
|
|
87
|
-
optional: true
|
|
88
|
-
})
|
|
89
|
-
}),
|
|
90
|
-
(0, _kubb_ast.createProperty)({
|
|
91
|
-
name: "url",
|
|
92
|
-
required: true,
|
|
93
|
-
schema: (0, _kubb_ast.createSchema)({
|
|
94
|
-
type: "url",
|
|
95
|
-
path: node.path
|
|
96
|
-
})
|
|
97
|
-
})
|
|
98
|
-
]
|
|
99
|
-
});
|
|
100
|
-
},
|
|
101
|
-
buildResponses({ node, resolver }) {
|
|
102
|
-
if (node.responses.length === 0) return null;
|
|
103
|
-
return (0, _kubb_ast.createSchema)({
|
|
104
|
-
type: "object",
|
|
105
|
-
properties: node.responses.map((res) => (0, _kubb_ast.createProperty)({
|
|
106
|
-
name: String(res.statusCode),
|
|
107
|
-
required: true,
|
|
108
|
-
schema: (0, _kubb_ast.createSchema)({
|
|
109
|
-
type: "ref",
|
|
110
|
-
name: resolver.resolveResponseStatusTypedName(node, res.statusCode)
|
|
111
|
-
})
|
|
112
|
-
}))
|
|
113
|
-
});
|
|
114
|
-
},
|
|
115
|
-
buildResponseUnion({ node, resolver }) {
|
|
116
|
-
const responsesWithSchema = node.responses.filter((res) => res.schema);
|
|
117
|
-
if (responsesWithSchema.length === 0) return null;
|
|
118
|
-
return (0, _kubb_ast.createSchema)({
|
|
119
|
-
type: "union",
|
|
120
|
-
members: responsesWithSchema.map((res) => (0, _kubb_ast.createSchema)({
|
|
121
|
-
type: "ref",
|
|
122
|
-
name: resolver.resolveResponseStatusTypedName(node, res.statusCode)
|
|
123
|
-
}))
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}));
|
|
127
|
-
//#endregion
|
|
128
|
-
Object.defineProperty(exports, "builderTs", {
|
|
129
|
-
enumerable: true,
|
|
130
|
-
get: function() {
|
|
131
|
-
return builderTs;
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
//# sourceMappingURL=builderTs-COUg3xtQ.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"builderTs-COUg3xtQ.cjs","names":[],"sources":["../src/builders/builderTs.ts"],"sourcesContent":["import { createProperty, createSchema } from '@kubb/ast'\nimport { defineBuilder } from '@kubb/core'\nimport type { PluginTs } from '../types.ts'\n\n/**\n * Default schema builder for `@kubb/plugin-ts`.\n *\n * Implements the `buildParams`, `buildData`, `buildResponses`, and `buildResponseUnion` helpers\n * used by the TypeScript type generator to construct AST schema nodes for operation parameters,\n * request bodies, and responses.\n *\n * @example\n * ```ts\n * import { builderTs } from '@kubb/plugin-ts'\n *\n * builderTs.buildData({ node, resolver })\n * // → object schema with pathParams, queryParams, headerParams, data, url properties\n * ```\n */\nexport const builderTs = defineBuilder<PluginTs>(() => ({\n name: 'default',\n buildParams({ params, node, resolver }) {\n return createSchema({\n type: 'object',\n properties: params.map((param) =>\n createProperty({\n name: param.name,\n required: param.required,\n schema: createSchema({\n type: 'ref',\n name: resolver.resolveParamName(node, param),\n }),\n }),\n ),\n })\n },\n buildData({ node, resolver }) {\n const pathParams = node.parameters.filter((p) => p.in === 'path')\n const queryParams = node.parameters.filter((p) => p.in === 'query')\n const headerParams = node.parameters.filter((p) => p.in === 'header')\n\n return createSchema({\n type: 'object',\n deprecated: node.deprecated,\n properties: [\n createProperty({\n name: 'data',\n schema: node.requestBody?.schema\n ? createSchema({ type: 'ref', name: resolver.resolveDataTypedName(node), optional: true })\n : createSchema({ type: 'never', optional: true }),\n }),\n createProperty({\n name: 'pathParams',\n required: pathParams.length > 0,\n schema: pathParams.length > 0 ? this.buildParams({ params: pathParams, node, resolver }) : createSchema({ type: 'never' }),\n }),\n createProperty({\n name: 'queryParams',\n schema:\n queryParams.length > 0\n ? createSchema({ ...this.buildParams({ params: queryParams, node, resolver }), optional: true })\n : createSchema({ type: 'never', optional: true }),\n }),\n createProperty({\n name: 'headerParams',\n schema:\n headerParams.length > 0\n ? createSchema({ ...this.buildParams({ params: headerParams, node, resolver }), optional: true })\n : createSchema({ type: 'never', optional: true }),\n }),\n createProperty({\n name: 'url',\n required: true,\n schema: createSchema({ type: 'url', path: node.path }),\n }),\n ],\n })\n },\n buildResponses({ node, resolver }) {\n if (node.responses.length === 0) {\n return null\n }\n\n return createSchema({\n type: 'object',\n properties: node.responses.map((res) =>\n createProperty({\n name: String(res.statusCode),\n required: true,\n schema: createSchema({ type: 'ref', name: resolver.resolveResponseStatusTypedName(node, res.statusCode) }),\n }),\n ),\n })\n },\n buildResponseUnion({ node, resolver }) {\n const responsesWithSchema = node.responses.filter((res) => res.schema)\n\n if (responsesWithSchema.length === 0) {\n return null\n }\n\n return createSchema({\n type: 'union',\n members: responsesWithSchema.map((res) => createSchema({ type: 'ref', name: resolver.resolveResponseStatusTypedName(node, res.statusCode) })),\n })\n },\n}))\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,MAAa,aAAA,yBAAA,sBAA2C;CACtD,MAAM;CACN,YAAY,EAAE,QAAQ,MAAM,YAAY;AACtC,UAAA,GAAA,UAAA,cAAoB;GAClB,MAAM;GACN,YAAY,OAAO,KAAK,WAAA,GAAA,UAAA,gBACP;IACb,MAAM,MAAM;IACZ,UAAU,MAAM;IAChB,SAAA,GAAA,UAAA,cAAqB;KACnB,MAAM;KACN,MAAM,SAAS,iBAAiB,MAAM,MAAM;KAC7C,CAAC;IACH,CAAC,CACH;GACF,CAAC;;CAEJ,UAAU,EAAE,MAAM,YAAY;EAC5B,MAAM,aAAa,KAAK,WAAW,QAAQ,MAAM,EAAE,OAAO,OAAO;EACjE,MAAM,cAAc,KAAK,WAAW,QAAQ,MAAM,EAAE,OAAO,QAAQ;EACnE,MAAM,eAAe,KAAK,WAAW,QAAQ,MAAM,EAAE,OAAO,SAAS;AAErE,UAAA,GAAA,UAAA,cAAoB;GAClB,MAAM;GACN,YAAY,KAAK;GACjB,YAAY;kCACK;KACb,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M,IAAI,WAAW;KAAE,CAAC;IAC3G,CAAC,CACH;GACF,CAAC;;CAEJ,mBAAmB,EAAE,MAAM,YAAY;EACrC,MAAM,sBAAsB,KAAK,UAAU,QAAQ,QAAQ,IAAI,OAAO;AAEtE,MAAI,oBAAoB,WAAW,EACjC,QAAO;AAGT,UAAA,GAAA,UAAA,cAAoB;GAClB,MAAM;GACN,SAAS,oBAAoB,KAAK,SAAA,GAAA,UAAA,cAAqB;IAAE,MAAM;IAAO,MAAM,SAAS,+BAA+B,MAAM,IAAI,WAAW;IAAE,CAAC,CAAC;GAC9I,CAAC;;CAEL,EAAE"}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { createProperty, createSchema } from "@kubb/ast";
|
|
3
|
-
import { defineBuilder } from "@kubb/core";
|
|
4
|
-
//#region src/builders/builderTs.ts
|
|
5
|
-
/**
|
|
6
|
-
* Default schema builder for `@kubb/plugin-ts`.
|
|
7
|
-
*
|
|
8
|
-
* Implements the `buildParams`, `buildData`, `buildResponses`, and `buildResponseUnion` helpers
|
|
9
|
-
* used by the TypeScript type generator to construct AST schema nodes for operation parameters,
|
|
10
|
-
* request bodies, and responses.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { builderTs } from '@kubb/plugin-ts'
|
|
15
|
-
*
|
|
16
|
-
* builderTs.buildData({ node, resolver })
|
|
17
|
-
* // → object schema with pathParams, queryParams, headerParams, data, url properties
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
const builderTs = defineBuilder(() => ({
|
|
21
|
-
name: "default",
|
|
22
|
-
buildParams({ params, node, resolver }) {
|
|
23
|
-
return createSchema({
|
|
24
|
-
type: "object",
|
|
25
|
-
properties: params.map((param) => createProperty({
|
|
26
|
-
name: param.name,
|
|
27
|
-
required: param.required,
|
|
28
|
-
schema: createSchema({
|
|
29
|
-
type: "ref",
|
|
30
|
-
name: resolver.resolveParamName(node, param)
|
|
31
|
-
})
|
|
32
|
-
}))
|
|
33
|
-
});
|
|
34
|
-
},
|
|
35
|
-
buildData({ node, resolver }) {
|
|
36
|
-
const pathParams = node.parameters.filter((p) => p.in === "path");
|
|
37
|
-
const queryParams = node.parameters.filter((p) => p.in === "query");
|
|
38
|
-
const headerParams = node.parameters.filter((p) => p.in === "header");
|
|
39
|
-
return createSchema({
|
|
40
|
-
type: "object",
|
|
41
|
-
deprecated: node.deprecated,
|
|
42
|
-
properties: [
|
|
43
|
-
createProperty({
|
|
44
|
-
name: "data",
|
|
45
|
-
schema: node.requestBody?.schema ? createSchema({
|
|
46
|
-
type: "ref",
|
|
47
|
-
name: resolver.resolveDataTypedName(node),
|
|
48
|
-
optional: true
|
|
49
|
-
}) : createSchema({
|
|
50
|
-
type: "never",
|
|
51
|
-
optional: true
|
|
52
|
-
})
|
|
53
|
-
}),
|
|
54
|
-
createProperty({
|
|
55
|
-
name: "pathParams",
|
|
56
|
-
required: pathParams.length > 0,
|
|
57
|
-
schema: pathParams.length > 0 ? this.buildParams({
|
|
58
|
-
params: pathParams,
|
|
59
|
-
node,
|
|
60
|
-
resolver
|
|
61
|
-
}) : createSchema({ type: "never" })
|
|
62
|
-
}),
|
|
63
|
-
createProperty({
|
|
64
|
-
name: "queryParams",
|
|
65
|
-
schema: queryParams.length > 0 ? createSchema({
|
|
66
|
-
...this.buildParams({
|
|
67
|
-
params: queryParams,
|
|
68
|
-
node,
|
|
69
|
-
resolver
|
|
70
|
-
}),
|
|
71
|
-
optional: true
|
|
72
|
-
}) : createSchema({
|
|
73
|
-
type: "never",
|
|
74
|
-
optional: true
|
|
75
|
-
})
|
|
76
|
-
}),
|
|
77
|
-
createProperty({
|
|
78
|
-
name: "headerParams",
|
|
79
|
-
schema: headerParams.length > 0 ? createSchema({
|
|
80
|
-
...this.buildParams({
|
|
81
|
-
params: headerParams,
|
|
82
|
-
node,
|
|
83
|
-
resolver
|
|
84
|
-
}),
|
|
85
|
-
optional: true
|
|
86
|
-
}) : createSchema({
|
|
87
|
-
type: "never",
|
|
88
|
-
optional: true
|
|
89
|
-
})
|
|
90
|
-
}),
|
|
91
|
-
createProperty({
|
|
92
|
-
name: "url",
|
|
93
|
-
required: true,
|
|
94
|
-
schema: createSchema({
|
|
95
|
-
type: "url",
|
|
96
|
-
path: node.path
|
|
97
|
-
})
|
|
98
|
-
})
|
|
99
|
-
]
|
|
100
|
-
});
|
|
101
|
-
},
|
|
102
|
-
buildResponses({ node, resolver }) {
|
|
103
|
-
if (node.responses.length === 0) return null;
|
|
104
|
-
return createSchema({
|
|
105
|
-
type: "object",
|
|
106
|
-
properties: node.responses.map((res) => createProperty({
|
|
107
|
-
name: String(res.statusCode),
|
|
108
|
-
required: true,
|
|
109
|
-
schema: createSchema({
|
|
110
|
-
type: "ref",
|
|
111
|
-
name: resolver.resolveResponseStatusTypedName(node, res.statusCode)
|
|
112
|
-
})
|
|
113
|
-
}))
|
|
114
|
-
});
|
|
115
|
-
},
|
|
116
|
-
buildResponseUnion({ node, resolver }) {
|
|
117
|
-
const responsesWithSchema = node.responses.filter((res) => res.schema);
|
|
118
|
-
if (responsesWithSchema.length === 0) return null;
|
|
119
|
-
return createSchema({
|
|
120
|
-
type: "union",
|
|
121
|
-
members: responsesWithSchema.map((res) => createSchema({
|
|
122
|
-
type: "ref",
|
|
123
|
-
name: resolver.resolveResponseStatusTypedName(node, res.statusCode)
|
|
124
|
-
}))
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}));
|
|
128
|
-
//#endregion
|
|
129
|
-
export { builderTs as t };
|
|
130
|
-
|
|
131
|
-
//# sourceMappingURL=builderTs-DPpkJKd1.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"builderTs-DPpkJKd1.js","names":[],"sources":["../src/builders/builderTs.ts"],"sourcesContent":["import { createProperty, createSchema } from '@kubb/ast'\nimport { defineBuilder } from '@kubb/core'\nimport type { PluginTs } from '../types.ts'\n\n/**\n * Default schema builder for `@kubb/plugin-ts`.\n *\n * Implements the `buildParams`, `buildData`, `buildResponses`, and `buildResponseUnion` helpers\n * used by the TypeScript type generator to construct AST schema nodes for operation parameters,\n * request bodies, and responses.\n *\n * @example\n * ```ts\n * import { builderTs } from '@kubb/plugin-ts'\n *\n * builderTs.buildData({ node, resolver })\n * // → object schema with pathParams, queryParams, headerParams, data, url properties\n * ```\n */\nexport const builderTs = defineBuilder<PluginTs>(() => ({\n name: 'default',\n buildParams({ params, node, resolver }) {\n return createSchema({\n type: 'object',\n properties: params.map((param) =>\n createProperty({\n name: param.name,\n required: param.required,\n schema: createSchema({\n type: 'ref',\n name: resolver.resolveParamName(node, param),\n }),\n }),\n ),\n })\n },\n buildData({ node, resolver }) {\n const pathParams = node.parameters.filter((p) => p.in === 'path')\n const queryParams = node.parameters.filter((p) => p.in === 'query')\n const headerParams = node.parameters.filter((p) => p.in === 'header')\n\n return createSchema({\n type: 'object',\n deprecated: node.deprecated,\n properties: [\n createProperty({\n name: 'data',\n schema: node.requestBody?.schema\n ? createSchema({ type: 'ref', name: resolver.resolveDataTypedName(node), optional: true })\n : createSchema({ type: 'never', optional: true }),\n }),\n createProperty({\n name: 'pathParams',\n required: pathParams.length > 0,\n schema: pathParams.length > 0 ? this.buildParams({ params: pathParams, node, resolver }) : createSchema({ type: 'never' }),\n }),\n createProperty({\n name: 'queryParams',\n schema:\n queryParams.length > 0\n ? createSchema({ ...this.buildParams({ params: queryParams, node, resolver }), optional: true })\n : createSchema({ type: 'never', optional: true }),\n }),\n createProperty({\n name: 'headerParams',\n schema:\n headerParams.length > 0\n ? createSchema({ ...this.buildParams({ params: headerParams, node, resolver }), optional: true })\n : createSchema({ type: 'never', optional: true }),\n }),\n createProperty({\n name: 'url',\n required: true,\n schema: createSchema({ type: 'url', path: node.path }),\n }),\n ],\n })\n },\n buildResponses({ node, resolver }) {\n if (node.responses.length === 0) {\n return null\n }\n\n return createSchema({\n type: 'object',\n properties: node.responses.map((res) =>\n createProperty({\n name: String(res.statusCode),\n required: true,\n schema: createSchema({ type: 'ref', name: resolver.resolveResponseStatusTypedName(node, res.statusCode) }),\n }),\n ),\n })\n },\n buildResponseUnion({ node, resolver }) {\n const responsesWithSchema = node.responses.filter((res) => res.schema)\n\n if (responsesWithSchema.length === 0) {\n return null\n }\n\n return createSchema({\n type: 'union',\n members: responsesWithSchema.map((res) => createSchema({ type: 'ref', name: resolver.resolveResponseStatusTypedName(node, res.statusCode) })),\n })\n },\n}))\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,MAAa,YAAY,qBAA+B;CACtD,MAAM;CACN,YAAY,EAAE,QAAQ,MAAM,YAAY;AACtC,SAAO,aAAa;GAClB,MAAM;GACN,YAAY,OAAO,KAAK,UACtB,eAAe;IACb,MAAM,MAAM;IACZ,UAAU,MAAM;IAChB,QAAQ,aAAa;KACnB,MAAM;KACN,MAAM,SAAS,iBAAiB,MAAM,MAAM;KAC7C,CAAC;IACH,CAAC,CACH;GACF,CAAC;;CAEJ,UAAU,EAAE,MAAM,YAAY;EAC5B,MAAM,aAAa,KAAK,WAAW,QAAQ,MAAM,EAAE,OAAO,OAAO;EACjE,MAAM,cAAc,KAAK,WAAW,QAAQ,MAAM,EAAE,OAAO,QAAQ;EACnE,MAAM,eAAe,KAAK,WAAW,QAAQ,MAAM,EAAE,OAAO,SAAS;AAErE,SAAO,aAAa;GAClB,MAAM;GACN,YAAY,KAAK;GACjB,YAAY;IACV,eAAe;KACb,MAAM;KACN,QAAQ,KAAK,aAAa,SACtB,aAAa;MAAE,MAAM;MAAO,MAAM,SAAS,qBAAqB,KAAK;MAAE,UAAU;MAAM,CAAC,GACxF,aAAa;MAAE,MAAM;MAAS,UAAU;MAAM,CAAC;KACpD,CAAC;IACF,eAAe;KACb,MAAM;KACN,UAAU,WAAW,SAAS;KAC9B,QAAQ,WAAW,SAAS,IAAI,KAAK,YAAY;MAAE,QAAQ;MAAY;MAAM;MAAU,CAAC,GAAG,aAAa,EAAE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@
|
|
|
1
|
-
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { t as BuilderTs } from "./types-CRtcZOCz.js";
|
|
3
|
-
|
|
4
|
-
//#region src/builders/builderTs.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Default schema builder for `@kubb/plugin-ts`.
|
|
7
|
-
*
|
|
8
|
-
* Implements the `buildParams`, `buildData`, `buildResponses`, and `buildResponseUnion` helpers
|
|
9
|
-
* used by the TypeScript type generator to construct AST schema nodes for operation parameters,
|
|
10
|
-
* request bodies, and responses.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { builderTs } from '@kubb/plugin-ts'
|
|
15
|
-
*
|
|
16
|
-
* builderTs.buildData({ node, resolver })
|
|
17
|
-
* // → object schema with pathParams, queryParams, headerParams, data, url properties
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
declare const builderTs: BuilderTs;
|
|
21
|
-
//#endregion
|
|
22
|
-
export { builderTs };
|
|
23
|
-
//# sourceMappingURL=builders.d.ts.map
|
package/dist/builders.js
DELETED