@kubb/plugin-ts 5.0.0-alpha.2 → 5.0.0-alpha.21
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/Type-B6fo0gSk.js +120 -0
- package/dist/Type-B6fo0gSk.js.map +1 -0
- package/dist/Type-oFwUfkZv.cjs +131 -0
- package/dist/Type-oFwUfkZv.cjs.map +1 -0
- package/dist/builderTs-Cd3juc2G.cjs +120 -0
- package/dist/builderTs-Cd3juc2G.cjs.map +1 -0
- package/dist/builderTs-DausqHpc.js +116 -0
- package/dist/builderTs-DausqHpc.js.map +1 -0
- package/dist/builders.cjs +3 -0
- package/dist/builders.d.ts +8 -0
- package/dist/builders.js +2 -0
- package/dist/casing-BJHFg-zZ.js +84 -0
- package/dist/casing-BJHFg-zZ.js.map +1 -0
- package/dist/casing-DHfdqpLi.cjs +107 -0
- package/dist/casing-DHfdqpLi.cjs.map +1 -0
- package/dist/chunk-ByKO4r7w.cjs +38 -0
- package/dist/components.cjs +3 -2
- package/dist/components.d.ts +40 -11
- package/dist/components.js +2 -2
- package/dist/generators-ByK18qUn.js +551 -0
- package/dist/generators-ByK18qUn.js.map +1 -0
- package/dist/generators-aSsiTfUO.cjs +563 -0
- package/dist/generators-aSsiTfUO.cjs.map +1 -0
- package/dist/generators.cjs +3 -2
- package/dist/generators.d.ts +7 -492
- package/dist/generators.js +2 -2
- package/dist/index.cjs +148 -3
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +146 -1
- package/dist/index.js.map +1 -0
- package/dist/printerTs-BgZucv4T.js +559 -0
- package/dist/printerTs-BgZucv4T.js.map +1 -0
- package/dist/printerTs-CFXc_LpP.cjs +595 -0
- package/dist/printerTs-CFXc_LpP.cjs.map +1 -0
- package/dist/printers.cjs +3 -0
- package/dist/printers.d.ts +75 -0
- package/dist/printers.js +2 -0
- package/dist/resolverTsLegacy-DLl854-P.js +185 -0
- package/dist/resolverTsLegacy-DLl854-P.js.map +1 -0
- package/dist/resolverTsLegacy-sJ16Iqrl.cjs +196 -0
- package/dist/resolverTsLegacy-sJ16Iqrl.cjs.map +1 -0
- package/dist/resolvers.cjs +4 -0
- package/dist/resolvers.d.ts +52 -0
- package/dist/resolvers.js +2 -0
- package/dist/types-BcyuFDn9.d.ts +344 -0
- package/package.json +27 -8
- package/src/builders/builderTs.ts +92 -0
- package/src/builders/index.ts +1 -0
- package/src/components/Enum.tsx +83 -0
- package/src/components/Type.tsx +24 -145
- package/src/components/index.ts +1 -0
- package/src/constants.ts +29 -0
- package/src/factory.ts +14 -48
- package/src/generators/index.ts +1 -0
- package/src/generators/typeGenerator.tsx +119 -403
- package/src/generators/typeGeneratorLegacy.tsx +345 -0
- package/src/plugin.ts +80 -122
- package/src/presets.ts +26 -0
- package/src/printers/index.ts +1 -0
- package/src/printers/printerTs.ts +389 -0
- package/src/resolvers/index.ts +2 -0
- package/src/resolvers/resolverTs.ts +107 -0
- package/src/resolvers/resolverTsLegacy.ts +87 -0
- package/src/types.ts +261 -72
- package/dist/components-9wydyqUx.cjs +0 -848
- package/dist/components-9wydyqUx.cjs.map +0 -1
- package/dist/components-LmqJfxMv.js +0 -721
- package/dist/components-LmqJfxMv.js.map +0 -1
- package/dist/plugin-CNkzbtpl.cjs +0 -508
- package/dist/plugin-CNkzbtpl.cjs.map +0 -1
- package/dist/plugin-DoLrDl9P.js +0 -476
- package/dist/plugin-DoLrDl9P.js.map +0 -1
- package/dist/types-BpeKGgCn.d.ts +0 -170
- package/src/parser.ts +0 -396
- package/src/printer.ts +0 -221
|
@@ -0,0 +1,120 @@
|
|
|
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-BgZucv4T.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, 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) ? `${resolved}Key` : 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, enumKeyCasing, resolver }) {
|
|
36
|
+
const { enumName, typeName, refName } = getEnumNames({
|
|
37
|
+
node,
|
|
38
|
+
enumType,
|
|
39
|
+
resolver
|
|
40
|
+
});
|
|
41
|
+
const [nameNode, typeNode] = createEnumDeclaration({
|
|
42
|
+
name: enumName,
|
|
43
|
+
typeName,
|
|
44
|
+
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]) ?? [],
|
|
45
|
+
type: enumType,
|
|
46
|
+
enumKeyCasing
|
|
47
|
+
});
|
|
48
|
+
const needsRefAlias = ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && refName !== typeName;
|
|
49
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
50
|
+
nameNode && /* @__PURE__ */ jsx(File.Source, {
|
|
51
|
+
name: enumName,
|
|
52
|
+
isExportable: true,
|
|
53
|
+
isIndexable: true,
|
|
54
|
+
isTypeOnly: false,
|
|
55
|
+
children: safePrint(nameNode)
|
|
56
|
+
}),
|
|
57
|
+
/* @__PURE__ */ jsx(File.Source, {
|
|
58
|
+
name: typeName,
|
|
59
|
+
isIndexable: true,
|
|
60
|
+
isExportable: ENUM_TYPES_WITH_RUNTIME_VALUE.has(enumType),
|
|
61
|
+
isTypeOnly: ENUM_TYPES_WITH_TYPE_ONLY.has(enumType),
|
|
62
|
+
children: safePrint(typeNode)
|
|
63
|
+
}),
|
|
64
|
+
needsRefAlias && /* @__PURE__ */ jsx(File.Source, {
|
|
65
|
+
name: refName,
|
|
66
|
+
isExportable: true,
|
|
67
|
+
isIndexable: true,
|
|
68
|
+
isTypeOnly: true,
|
|
69
|
+
children: `export type ${refName} = ${typeName}`
|
|
70
|
+
})
|
|
71
|
+
] });
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/components/Type.tsx
|
|
75
|
+
function Type({ name, typedName, node, keysToOmit, optionalType, arrayType, syntaxType, enumType, enumKeyCasing, description, resolver }) {
|
|
76
|
+
const resolvedDescription = description || node?.description;
|
|
77
|
+
const enumSchemaNodes = collect(node, { schema(n) {
|
|
78
|
+
const enumNode = narrowSchema(n, schemaTypes.enum);
|
|
79
|
+
if (enumNode?.name) return enumNode;
|
|
80
|
+
} });
|
|
81
|
+
const output = printerTs({
|
|
82
|
+
optionalType,
|
|
83
|
+
arrayType,
|
|
84
|
+
enumType,
|
|
85
|
+
typeName: name,
|
|
86
|
+
syntaxType,
|
|
87
|
+
description: resolvedDescription,
|
|
88
|
+
keysToOmit,
|
|
89
|
+
resolver
|
|
90
|
+
}).print(node);
|
|
91
|
+
if (!output) return;
|
|
92
|
+
const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {
|
|
93
|
+
return {
|
|
94
|
+
node,
|
|
95
|
+
...getEnumNames({
|
|
96
|
+
node,
|
|
97
|
+
enumType,
|
|
98
|
+
resolver
|
|
99
|
+
})
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
const shouldExportEnums = enumType !== "inlineLiteral";
|
|
103
|
+
const shouldExportType = enumType === "inlineLiteral" || enums.every((item) => item.typeName !== name);
|
|
104
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [shouldExportEnums && enums.map(({ node }) => /* @__PURE__ */ jsx(Enum, {
|
|
105
|
+
node,
|
|
106
|
+
enumType,
|
|
107
|
+
enumKeyCasing,
|
|
108
|
+
resolver
|
|
109
|
+
})), shouldExportType && /* @__PURE__ */ jsx(File.Source, {
|
|
110
|
+
name: typedName,
|
|
111
|
+
isTypeOnly: true,
|
|
112
|
+
isExportable: true,
|
|
113
|
+
isIndexable: true,
|
|
114
|
+
children: output
|
|
115
|
+
})] });
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
export { Enum as n, Type as t };
|
|
119
|
+
|
|
120
|
+
//# sourceMappingURL=Type-B6fo0gSk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Type-B6fo0gSk.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 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({ node, enumType, resolver }: { node: EnumSchemaNode; enumType: PluginTs['resolvedOptions']['enumType']; resolver: ResolverTs }): {\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) ? `${resolved}Key` : 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, enumKeyCasing, resolver }: Props): FabricReactNode {\n const { enumName, typeName, refName } = getEnumNames({ node, enumType, 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 const needsRefAlias = ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && refName !== typeName\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 {needsRefAlias && (\n <File.Source name={refName} isExportable isIndexable isTypeOnly>\n {`export type ${refName} = ${typeName}`}\n </File.Source>\n )}\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 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 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({ optionalType, arrayType, enumType, typeName: name, syntaxType, description: resolvedDescription, keysToOmit, resolver })\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, 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 && enums.map(({ node }) => <Enum node={node} enumType={enumType} 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":";;;;;;;;;;;;;;;AAuBA,SAAgB,aAAa,EAAE,MAAM,UAAU,YAQ7C;CACA,MAAM,WAAW,SAAS,QAAQ,KAAK,MAAO,OAAO;AAIrD,QAAO;EAAE,UAHQ,aAAa,kBAAkB,WAAW,UAAU,KAAK,KAAM;EAG7D,UAFF,2BAA2B,IAAI,SAAS,GAAG,GAAG,SAAS,OAAO;EAElD,SAAS;EAAU;;;;;;;;;;;;;AAclD,SAAgB,KAAK,EAAE,MAAM,UAAU,eAAe,YAAoC;CACxF,MAAM,EAAE,UAAU,UAAU,YAAY,aAAa;EAAE;EAAM;EAAU;EAAU,CAAC;CAElF,MAAM,CAAC,UAAU,YAAYA,sBAA8B;EACzD,MAAM;EACN;EACA,OAAQ,KAAK,iBAAiB,KAAK,MAAM,CAAC,WAAW,EAAE,KA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;GACA,GAAG,aAAa;IAAE;IAAM;IAAU;IAAU,CAAC;GAC9C;GACD;CAGF,MAAM,oBAAoB,aAAa;CACvC,MAAM,mBAAmB,aAAa,mBAAmB,MAAM,OAAO,SAAS,KAAK,aAAa,KAAK;AAEtG,QACE,qBAAA,UAAA,EAAA,UAAA,CACG,qBAAqB,MAAM,KAAK,EAAE,WAAW,oBAAC,MAAD;EAAY;EAAgB;EAAyB;EAAyB;EAAY,CAAA,CAAC,EACxI,oBACC,oBAAC,KAAK,QAAN;EAAa,MAAM;EAAW,YAAA;EAAW,cAAA;EAAa,aAAA;YACnD;EACW,CAAA,CAEf,EAAA,CAAA"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
require("./chunk-ByKO4r7w.cjs");
|
|
2
|
+
const require_casing = require("./casing-DHfdqpLi.cjs");
|
|
3
|
+
const require_printerTs = require("./printerTs-CFXc_LpP.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, 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) ? `${resolved}Key` : 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, enumKeyCasing, resolver }) {
|
|
36
|
+
const { enumName, typeName, refName } = getEnumNames({
|
|
37
|
+
node,
|
|
38
|
+
enumType,
|
|
39
|
+
resolver
|
|
40
|
+
});
|
|
41
|
+
const [nameNode, typeNode] = require_printerTs.createEnumDeclaration({
|
|
42
|
+
name: enumName,
|
|
43
|
+
typeName,
|
|
44
|
+
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]) ?? [],
|
|
45
|
+
type: enumType,
|
|
46
|
+
enumKeyCasing
|
|
47
|
+
});
|
|
48
|
+
const needsRefAlias = require_printerTs.ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && refName !== typeName;
|
|
49
|
+
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
|
|
50
|
+
nameNode && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
51
|
+
name: enumName,
|
|
52
|
+
isExportable: true,
|
|
53
|
+
isIndexable: true,
|
|
54
|
+
isTypeOnly: false,
|
|
55
|
+
children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(nameNode)
|
|
56
|
+
}),
|
|
57
|
+
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
58
|
+
name: typeName,
|
|
59
|
+
isIndexable: true,
|
|
60
|
+
isExportable: require_printerTs.ENUM_TYPES_WITH_RUNTIME_VALUE.has(enumType),
|
|
61
|
+
isTypeOnly: require_printerTs.ENUM_TYPES_WITH_TYPE_ONLY.has(enumType),
|
|
62
|
+
children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(typeNode)
|
|
63
|
+
}),
|
|
64
|
+
needsRefAlias && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
65
|
+
name: refName,
|
|
66
|
+
isExportable: true,
|
|
67
|
+
isIndexable: true,
|
|
68
|
+
isTypeOnly: true,
|
|
69
|
+
children: `export type ${refName} = ${typeName}`
|
|
70
|
+
})
|
|
71
|
+
] });
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/components/Type.tsx
|
|
75
|
+
function Type({ name, typedName, node, keysToOmit, optionalType, arrayType, syntaxType, enumType, enumKeyCasing, description, resolver }) {
|
|
76
|
+
const resolvedDescription = description || node?.description;
|
|
77
|
+
const enumSchemaNodes = (0, _kubb_ast.collect)(node, { schema(n) {
|
|
78
|
+
const enumNode = (0, _kubb_ast.narrowSchema)(n, _kubb_ast.schemaTypes.enum);
|
|
79
|
+
if (enumNode?.name) return enumNode;
|
|
80
|
+
} });
|
|
81
|
+
const output = require_printerTs.printerTs({
|
|
82
|
+
optionalType,
|
|
83
|
+
arrayType,
|
|
84
|
+
enumType,
|
|
85
|
+
typeName: name,
|
|
86
|
+
syntaxType,
|
|
87
|
+
description: resolvedDescription,
|
|
88
|
+
keysToOmit,
|
|
89
|
+
resolver
|
|
90
|
+
}).print(node);
|
|
91
|
+
if (!output) return;
|
|
92
|
+
const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {
|
|
93
|
+
return {
|
|
94
|
+
node,
|
|
95
|
+
...getEnumNames({
|
|
96
|
+
node,
|
|
97
|
+
enumType,
|
|
98
|
+
resolver
|
|
99
|
+
})
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
const shouldExportEnums = enumType !== "inlineLiteral";
|
|
103
|
+
const shouldExportType = enumType === "inlineLiteral" || enums.every((item) => item.typeName !== name);
|
|
104
|
+
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, {
|
|
105
|
+
node,
|
|
106
|
+
enumType,
|
|
107
|
+
enumKeyCasing,
|
|
108
|
+
resolver
|
|
109
|
+
})), shouldExportType && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
110
|
+
name: typedName,
|
|
111
|
+
isTypeOnly: true,
|
|
112
|
+
isExportable: true,
|
|
113
|
+
isIndexable: true,
|
|
114
|
+
children: output
|
|
115
|
+
})] });
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
Object.defineProperty(exports, "Enum", {
|
|
119
|
+
enumerable: true,
|
|
120
|
+
get: function() {
|
|
121
|
+
return Enum;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
Object.defineProperty(exports, "Type", {
|
|
125
|
+
enumerable: true,
|
|
126
|
+
get: function() {
|
|
127
|
+
return Type;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
//# sourceMappingURL=Type-oFwUfkZv.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Type-oFwUfkZv.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 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({ node, enumType, resolver }: { node: EnumSchemaNode; enumType: PluginTs['resolvedOptions']['enumType']; resolver: ResolverTs }): {\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) ? `${resolved}Key` : 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, enumKeyCasing, resolver }: Props): FabricReactNode {\n const { enumName, typeName, refName } = getEnumNames({ node, enumType, 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 const needsRefAlias = ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && refName !== typeName\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 {needsRefAlias && (\n <File.Source name={refName} isExportable isIndexable isTypeOnly>\n {`export type ${refName} = ${typeName}`}\n </File.Source>\n )}\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 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 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({ optionalType, arrayType, enumType, typeName: name, syntaxType, description: resolvedDescription, keysToOmit, resolver })\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, 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 && enums.map(({ node }) => <Enum node={node} enumType={enumType} 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":";;;;;;;;;;;;;;;AAuBA,SAAgB,aAAa,EAAE,MAAM,UAAU,YAQ7C;CACA,MAAM,WAAW,SAAS,QAAQ,KAAK,MAAO,OAAO;AAIrD,QAAO;EAAE,UAHQ,aAAa,kBAAkB,WAAWA,eAAAA,UAAU,KAAK,KAAM;EAG7D,UAFFC,kBAAAA,2BAA2B,IAAI,SAAS,GAAG,GAAG,SAAS,OAAO;EAElD,SAAS;EAAU;;;;;;;;;;;;;AAclD,SAAgB,KAAK,EAAE,MAAM,UAAU,eAAe,YAAoC;CACxF,MAAM,EAAE,UAAU,UAAU,YAAY,aAAa;EAAE;EAAM;E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AAM,QAAO;IAE9B,CAAC;CAGF,MAAM,SADUC,kBAAAA,UAAU;EAAE;EAAc;EAAW;EAAU,UAAU;EAAM;EAAY,aAAa;EAAqB;EAAY;EAAU,CAAC,CAC7H,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;IAAU,CAAC;GAC9C;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,qBAAqB,MAAM,KAAK,EAAE,WAAW,iBAAA,GAAA,+BAAA,KAAC,MAAD;EAAY;EAAgB;EAAyB;EAAyB;EAAY,CAAA,CAAC,EACxI,oBACC,iBAAA,GAAA,+BAAA,KAACC,mBAAAA,KAAK,QAAN;EAAa,MAAM;EAAW,YAAA;EAAW,cAAA;EAAa,aAAA;YACnD;EACW,CAAA,CAEf,EAAA,CAAA"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
require("./chunk-ByKO4r7w.cjs");
|
|
2
|
+
let _kubb_ast = require("@kubb/ast");
|
|
3
|
+
//#region src/builders/builderTs.ts
|
|
4
|
+
const builderTs = (0, require("@kubb/core").defineBuilder)(() => ({
|
|
5
|
+
name: "default",
|
|
6
|
+
buildParams({ params, node, resolver }) {
|
|
7
|
+
return (0, _kubb_ast.createSchema)({
|
|
8
|
+
type: "object",
|
|
9
|
+
properties: params.map((param) => (0, _kubb_ast.createProperty)({
|
|
10
|
+
name: param.name,
|
|
11
|
+
required: param.required,
|
|
12
|
+
schema: (0, _kubb_ast.createSchema)({
|
|
13
|
+
type: "ref",
|
|
14
|
+
name: resolver.resolveParamName(node, param)
|
|
15
|
+
})
|
|
16
|
+
}))
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
buildData({ node, resolver }) {
|
|
20
|
+
const pathParams = node.parameters.filter((p) => p.in === "path");
|
|
21
|
+
const queryParams = node.parameters.filter((p) => p.in === "query");
|
|
22
|
+
const headerParams = node.parameters.filter((p) => p.in === "header");
|
|
23
|
+
return (0, _kubb_ast.createSchema)({
|
|
24
|
+
type: "object",
|
|
25
|
+
deprecated: node.deprecated,
|
|
26
|
+
properties: [
|
|
27
|
+
(0, _kubb_ast.createProperty)({
|
|
28
|
+
name: "data",
|
|
29
|
+
schema: node.requestBody?.schema ? (0, _kubb_ast.createSchema)({
|
|
30
|
+
type: "ref",
|
|
31
|
+
name: resolver.resolveDataTypedName(node),
|
|
32
|
+
optional: true
|
|
33
|
+
}) : (0, _kubb_ast.createSchema)({
|
|
34
|
+
type: "never",
|
|
35
|
+
optional: true
|
|
36
|
+
})
|
|
37
|
+
}),
|
|
38
|
+
(0, _kubb_ast.createProperty)({
|
|
39
|
+
name: "pathParams",
|
|
40
|
+
required: pathParams.length > 0,
|
|
41
|
+
schema: pathParams.length > 0 ? this.buildParams({
|
|
42
|
+
params: pathParams,
|
|
43
|
+
node,
|
|
44
|
+
resolver
|
|
45
|
+
}) : (0, _kubb_ast.createSchema)({ type: "never" })
|
|
46
|
+
}),
|
|
47
|
+
(0, _kubb_ast.createProperty)({
|
|
48
|
+
name: "queryParams",
|
|
49
|
+
schema: queryParams.length > 0 ? (0, _kubb_ast.createSchema)({
|
|
50
|
+
...this.buildParams({
|
|
51
|
+
params: queryParams,
|
|
52
|
+
node,
|
|
53
|
+
resolver
|
|
54
|
+
}),
|
|
55
|
+
optional: true
|
|
56
|
+
}) : (0, _kubb_ast.createSchema)({
|
|
57
|
+
type: "never",
|
|
58
|
+
optional: true
|
|
59
|
+
})
|
|
60
|
+
}),
|
|
61
|
+
(0, _kubb_ast.createProperty)({
|
|
62
|
+
name: "headerParams",
|
|
63
|
+
schema: headerParams.length > 0 ? (0, _kubb_ast.createSchema)({
|
|
64
|
+
...this.buildParams({
|
|
65
|
+
params: headerParams,
|
|
66
|
+
node,
|
|
67
|
+
resolver
|
|
68
|
+
}),
|
|
69
|
+
optional: true
|
|
70
|
+
}) : (0, _kubb_ast.createSchema)({
|
|
71
|
+
type: "never",
|
|
72
|
+
optional: true
|
|
73
|
+
})
|
|
74
|
+
}),
|
|
75
|
+
(0, _kubb_ast.createProperty)({
|
|
76
|
+
name: "url",
|
|
77
|
+
required: true,
|
|
78
|
+
schema: (0, _kubb_ast.createSchema)({
|
|
79
|
+
type: "url",
|
|
80
|
+
path: node.path
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
]
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
buildResponses({ node, resolver }) {
|
|
87
|
+
if (node.responses.length === 0) return null;
|
|
88
|
+
return (0, _kubb_ast.createSchema)({
|
|
89
|
+
type: "object",
|
|
90
|
+
properties: node.responses.map((res) => (0, _kubb_ast.createProperty)({
|
|
91
|
+
name: String(res.statusCode),
|
|
92
|
+
required: true,
|
|
93
|
+
schema: (0, _kubb_ast.createSchema)({
|
|
94
|
+
type: "ref",
|
|
95
|
+
name: resolver.resolveResponseStatusTypedName(node, res.statusCode)
|
|
96
|
+
})
|
|
97
|
+
}))
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
buildResponseUnion({ node, resolver }) {
|
|
101
|
+
const responsesWithSchema = node.responses.filter((res) => res.schema);
|
|
102
|
+
if (responsesWithSchema.length === 0) return null;
|
|
103
|
+
return (0, _kubb_ast.createSchema)({
|
|
104
|
+
type: "union",
|
|
105
|
+
members: responsesWithSchema.map((res) => (0, _kubb_ast.createSchema)({
|
|
106
|
+
type: "ref",
|
|
107
|
+
name: resolver.resolveResponseStatusTypedName(node, res.statusCode)
|
|
108
|
+
}))
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}));
|
|
112
|
+
//#endregion
|
|
113
|
+
Object.defineProperty(exports, "builderTs", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
get: function() {
|
|
116
|
+
return builderTs;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
//# sourceMappingURL=builderTs-Cd3juc2G.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builderTs-Cd3juc2G.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\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":";;;AAIA,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,MAAM;KACN,QAAQ,KAAK,aAAa,UAAA,GAAA,UAAA,cACT;MAAE,MAAM;MAAO,MAAM,SAAS,qBAAqB,KAAK;MAAE,UAAU;MAAM,CAAC,IAAA,GAAA,U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,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"}
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
const builderTs = defineBuilder(() => ({
|
|
6
|
+
name: "default",
|
|
7
|
+
buildParams({ params, node, resolver }) {
|
|
8
|
+
return createSchema({
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: params.map((param) => createProperty({
|
|
11
|
+
name: param.name,
|
|
12
|
+
required: param.required,
|
|
13
|
+
schema: createSchema({
|
|
14
|
+
type: "ref",
|
|
15
|
+
name: resolver.resolveParamName(node, param)
|
|
16
|
+
})
|
|
17
|
+
}))
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
buildData({ node, resolver }) {
|
|
21
|
+
const pathParams = node.parameters.filter((p) => p.in === "path");
|
|
22
|
+
const queryParams = node.parameters.filter((p) => p.in === "query");
|
|
23
|
+
const headerParams = node.parameters.filter((p) => p.in === "header");
|
|
24
|
+
return createSchema({
|
|
25
|
+
type: "object",
|
|
26
|
+
deprecated: node.deprecated,
|
|
27
|
+
properties: [
|
|
28
|
+
createProperty({
|
|
29
|
+
name: "data",
|
|
30
|
+
schema: node.requestBody?.schema ? createSchema({
|
|
31
|
+
type: "ref",
|
|
32
|
+
name: resolver.resolveDataTypedName(node),
|
|
33
|
+
optional: true
|
|
34
|
+
}) : createSchema({
|
|
35
|
+
type: "never",
|
|
36
|
+
optional: true
|
|
37
|
+
})
|
|
38
|
+
}),
|
|
39
|
+
createProperty({
|
|
40
|
+
name: "pathParams",
|
|
41
|
+
required: pathParams.length > 0,
|
|
42
|
+
schema: pathParams.length > 0 ? this.buildParams({
|
|
43
|
+
params: pathParams,
|
|
44
|
+
node,
|
|
45
|
+
resolver
|
|
46
|
+
}) : createSchema({ type: "never" })
|
|
47
|
+
}),
|
|
48
|
+
createProperty({
|
|
49
|
+
name: "queryParams",
|
|
50
|
+
schema: queryParams.length > 0 ? createSchema({
|
|
51
|
+
...this.buildParams({
|
|
52
|
+
params: queryParams,
|
|
53
|
+
node,
|
|
54
|
+
resolver
|
|
55
|
+
}),
|
|
56
|
+
optional: true
|
|
57
|
+
}) : createSchema({
|
|
58
|
+
type: "never",
|
|
59
|
+
optional: true
|
|
60
|
+
})
|
|
61
|
+
}),
|
|
62
|
+
createProperty({
|
|
63
|
+
name: "headerParams",
|
|
64
|
+
schema: headerParams.length > 0 ? createSchema({
|
|
65
|
+
...this.buildParams({
|
|
66
|
+
params: headerParams,
|
|
67
|
+
node,
|
|
68
|
+
resolver
|
|
69
|
+
}),
|
|
70
|
+
optional: true
|
|
71
|
+
}) : createSchema({
|
|
72
|
+
type: "never",
|
|
73
|
+
optional: true
|
|
74
|
+
})
|
|
75
|
+
}),
|
|
76
|
+
createProperty({
|
|
77
|
+
name: "url",
|
|
78
|
+
required: true,
|
|
79
|
+
schema: createSchema({
|
|
80
|
+
type: "url",
|
|
81
|
+
path: node.path
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
]
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
buildResponses({ node, resolver }) {
|
|
88
|
+
if (node.responses.length === 0) return null;
|
|
89
|
+
return createSchema({
|
|
90
|
+
type: "object",
|
|
91
|
+
properties: node.responses.map((res) => createProperty({
|
|
92
|
+
name: String(res.statusCode),
|
|
93
|
+
required: true,
|
|
94
|
+
schema: createSchema({
|
|
95
|
+
type: "ref",
|
|
96
|
+
name: resolver.resolveResponseStatusTypedName(node, res.statusCode)
|
|
97
|
+
})
|
|
98
|
+
}))
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
buildResponseUnion({ node, resolver }) {
|
|
102
|
+
const responsesWithSchema = node.responses.filter((res) => res.schema);
|
|
103
|
+
if (responsesWithSchema.length === 0) return null;
|
|
104
|
+
return createSchema({
|
|
105
|
+
type: "union",
|
|
106
|
+
members: responsesWithSchema.map((res) => createSchema({
|
|
107
|
+
type: "ref",
|
|
108
|
+
name: resolver.resolveResponseStatusTypedName(node, res.statusCode)
|
|
109
|
+
}))
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}));
|
|
113
|
+
//#endregion
|
|
114
|
+
export { builderTs as t };
|
|
115
|
+
|
|
116
|
+
//# sourceMappingURL=builderTs-DausqHpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builderTs-DausqHpc.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\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":";;;;AAIA,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,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3G,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,SAAO,aAAa;GAClB,MAAM;GACN,SAAS,oBAAoB,KAAK,QAAQ,aAAa;IAAE,MAAM;IAAO,MAAM,SAAS,+BAA+B,MAAM,IAAI,WAAW;IAAE,CAAC,CAAC;GAC9I,CAAC;;CAEL,EAAE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
+
import { t as BuilderTs } from "./types-BcyuFDn9.js";
|
|
3
|
+
|
|
4
|
+
//#region src/builders/builderTs.d.ts
|
|
5
|
+
declare const builderTs: BuilderTs;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { builderTs };
|
|
8
|
+
//# sourceMappingURL=builders.d.ts.map
|
package/dist/builders.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import "./chunk--u3MIqq1.js";
|
|
2
|
+
//#region ../../internals/utils/src/casing.ts
|
|
3
|
+
/**
|
|
4
|
+
* Shared implementation for camelCase and PascalCase conversion.
|
|
5
|
+
* Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
|
|
6
|
+
* and capitalizes each word according to `pascal`.
|
|
7
|
+
*
|
|
8
|
+
* When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
|
|
9
|
+
*/
|
|
10
|
+
function toCamelOrPascal(text, pascal) {
|
|
11
|
+
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
12
|
+
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
13
|
+
if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
|
|
14
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
15
|
+
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Splits `text` on `.` and applies `transformPart` to each segment.
|
|
19
|
+
* The last segment receives `isLast = true`, all earlier segments receive `false`.
|
|
20
|
+
* Segments are joined with `/` to form a file path.
|
|
21
|
+
*
|
|
22
|
+
* Only splits on dots followed by a letter so that version numbers
|
|
23
|
+
* embedded in operationIds (e.g. `v2025.0`) are kept intact.
|
|
24
|
+
*/
|
|
25
|
+
function applyToFileParts(text, transformPart) {
|
|
26
|
+
const parts = text.split(/\.(?=[a-zA-Z])/);
|
|
27
|
+
return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Converts `text` to camelCase.
|
|
31
|
+
* When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* camelCase('hello-world') // 'helloWorld'
|
|
35
|
+
* camelCase('pet.petId', { isFile: true }) // 'pet/petId'
|
|
36
|
+
*/
|
|
37
|
+
function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
38
|
+
if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
|
|
39
|
+
prefix,
|
|
40
|
+
suffix
|
|
41
|
+
} : {}));
|
|
42
|
+
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Converts `text` to PascalCase.
|
|
46
|
+
* When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* pascalCase('hello-world') // 'HelloWorld'
|
|
50
|
+
* pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'
|
|
51
|
+
*/
|
|
52
|
+
function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
53
|
+
if (isFile) return applyToFileParts(text, (part, isLast) => isLast ? pascalCase(part, {
|
|
54
|
+
prefix,
|
|
55
|
+
suffix
|
|
56
|
+
}) : camelCase(part));
|
|
57
|
+
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Converts `text` to snake_case.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* snakeCase('helloWorld') // 'hello_world'
|
|
64
|
+
* snakeCase('Hello-World') // 'hello_world'
|
|
65
|
+
*/
|
|
66
|
+
function snakeCase(text, { prefix = "", suffix = "" } = {}) {
|
|
67
|
+
return `${prefix} ${text} ${suffix}`.trim().replace(/([a-z])([A-Z])/g, "$1_$2").replace(/[\s\-.]+/g, "_").replace(/[^a-zA-Z0-9_]/g, "").toLowerCase().split("_").filter(Boolean).join("_");
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Converts `text` to SCREAMING_SNAKE_CASE.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* screamingSnakeCase('helloWorld') // 'HELLO_WORLD'
|
|
74
|
+
*/
|
|
75
|
+
function screamingSnakeCase(text, { prefix = "", suffix = "" } = {}) {
|
|
76
|
+
return snakeCase(text, {
|
|
77
|
+
prefix,
|
|
78
|
+
suffix
|
|
79
|
+
}).toUpperCase();
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
export { snakeCase as i, pascalCase as n, screamingSnakeCase as r, camelCase as t };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=casing-BJHFg-zZ.js.map
|