@kubb/plugin-client 5.0.0-beta.56 → 5.0.0-beta.64
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 +50 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +51 -46
- package/dist/index.js.map +1 -1
- package/package.json +7 -8
- package/src/clients/axios.ts +0 -113
- package/src/clients/fetch.ts +0 -201
- package/src/components/ClassClient.tsx +0 -161
- package/src/components/Client.tsx +0 -281
- package/src/components/StaticClassClient.tsx +0 -153
- package/src/components/Url.tsx +0 -90
- package/src/components/WrapperClient.tsx +0 -33
- package/src/functionParams.ts +0 -118
- package/src/generators/classClientGenerator.tsx +0 -261
- package/src/generators/clientGenerator.tsx +0 -135
- package/src/generators/groupedClientGenerator.tsx +0 -82
- package/src/generators/operationsGenerator.ts +0 -47
- package/src/generators/staticClassClientGenerator.tsx +0 -240
- package/src/index.ts +0 -10
- package/src/plugin.ts +0 -161
- package/src/resolvers/resolverClient.ts +0 -46
- package/src/templates/clients/axios.source.ts +0 -4
- package/src/templates/clients/fetch.source.ts +0 -4
- package/src/templates/config.source.ts +0 -4
- package/src/types.ts +0 -276
- package/src/utils.ts +0 -259
package/dist/index.d.ts
CHANGED
|
@@ -234,10 +234,10 @@ type Options = OutputOptions & {
|
|
|
234
234
|
*/
|
|
235
235
|
resolver?: Partial<ResolverClient> & ThisType<ResolverClient>;
|
|
236
236
|
/**
|
|
237
|
-
*
|
|
238
|
-
* Return `null` or `undefined` to leave the node unchanged.
|
|
237
|
+
* Macros applied to each operation node before code is printed.
|
|
238
|
+
* Return `null` or `undefined` from a callback to leave the node unchanged.
|
|
239
239
|
*/
|
|
240
|
-
|
|
240
|
+
macros?: Array<ast.Macro>;
|
|
241
241
|
/**
|
|
242
242
|
* Custom generators that run alongside the built-in client generators.
|
|
243
243
|
*/
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { source as source$1 } from "./templates/clients/fetch.source.js";
|
|
|
4
4
|
import { source as source$2 } from "./templates/config.source.js";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { ast, defineGenerator, definePlugin, defineResolver } from "@kubb/core";
|
|
7
|
-
import { buildJSDoc, stringify } from "@kubb/ast/utils";
|
|
7
|
+
import { buildJSDoc, caseParams, createOperationParams, stringify } from "@kubb/ast/utils";
|
|
8
8
|
import { functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
9
9
|
import { Const, File, Function, jsxRenderer } from "@kubb/renderer-jsx";
|
|
10
10
|
import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
|
|
@@ -359,7 +359,7 @@ function buildOperationComments(node, options = {}) {
|
|
|
359
359
|
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
360
360
|
}
|
|
361
361
|
function getOperationParameters(node, options = {}) {
|
|
362
|
-
const params =
|
|
362
|
+
const params = caseParams(node.parameters, options.paramsCasing);
|
|
363
363
|
return {
|
|
364
364
|
path: params.filter((param) => param.in === "path"),
|
|
365
365
|
query: params.filter((param) => param.in === "query"),
|
|
@@ -492,43 +492,52 @@ const callPrinter = functionPrinter({ mode: "call" });
|
|
|
492
492
|
function isGroup(spec) {
|
|
493
493
|
return "children" in spec;
|
|
494
494
|
}
|
|
495
|
-
function
|
|
496
|
-
return
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
495
|
+
function groupEntries(group) {
|
|
496
|
+
return Object.entries(group.children).filter(([, child]) => child != null);
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Assembles a destructured group parameter from a binding pattern and an optional
|
|
500
|
+
* type literal. Built directly because `createFunctionParameter({ properties })`
|
|
501
|
+
* requires every member to carry a type, while these groups also hold untyped,
|
|
502
|
+
* value-only call entries.
|
|
503
|
+
*/
|
|
504
|
+
function createGroupParam(elements, members, default_) {
|
|
505
|
+
return {
|
|
506
|
+
kind: "FunctionParameter",
|
|
507
|
+
name: ast.factory.createObjectBindingPattern({ elements }),
|
|
508
|
+
type: members.length ? ast.factory.createTypeLiteral({ members }) : void 0,
|
|
509
|
+
default: default_,
|
|
510
|
+
optional: false
|
|
511
|
+
};
|
|
500
512
|
}
|
|
501
513
|
function createDeclarationLeaf(name, spec) {
|
|
502
|
-
if (spec.default !== void 0) return ast.createFunctionParameter({
|
|
514
|
+
if (spec.default !== void 0) return ast.factory.createFunctionParameter({
|
|
503
515
|
name,
|
|
504
|
-
type:
|
|
516
|
+
type: spec.type,
|
|
505
517
|
default: spec.default,
|
|
506
518
|
rest: spec.mode === "inlineSpread"
|
|
507
519
|
});
|
|
508
|
-
return ast.createFunctionParameter({
|
|
520
|
+
return ast.factory.createFunctionParameter({
|
|
509
521
|
name,
|
|
510
|
-
type:
|
|
522
|
+
type: spec.type,
|
|
511
523
|
optional: !!spec.optional,
|
|
512
524
|
rest: spec.mode === "inlineSpread"
|
|
513
525
|
});
|
|
514
526
|
}
|
|
515
527
|
function createDeclarationParam(name, spec) {
|
|
516
|
-
if (isGroup(spec))
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
528
|
+
if (isGroup(spec)) {
|
|
529
|
+
const entries = groupEntries(spec);
|
|
530
|
+
return createGroupParam(entries.map(([childName]) => ({ name: childName })), entries.filter(([, child]) => child.type).map(([childName, child]) => ({
|
|
531
|
+
name: childName,
|
|
532
|
+
type: child.type,
|
|
533
|
+
optional: !!child.optional || child.default !== void 0
|
|
534
|
+
})), spec.default);
|
|
535
|
+
}
|
|
521
536
|
return createDeclarationLeaf(name, spec);
|
|
522
537
|
}
|
|
523
538
|
function createCallParam(name, spec) {
|
|
524
|
-
if (isGroup(spec)) return
|
|
525
|
-
|
|
526
|
-
properties: Object.entries(spec.children).filter(([, child]) => child != null).map(([childName, child]) => ast.createFunctionParameter({
|
|
527
|
-
name: child?.mode === "inlineSpread" ? spec.mode === "inlineSpread" ? child.value ?? childName : `...${child.value ?? childName}` : child?.value ? `${childName}: ${child.value}` : childName,
|
|
528
|
-
rest: spec.mode === "inlineSpread" && child?.mode === "inlineSpread"
|
|
529
|
-
}))
|
|
530
|
-
});
|
|
531
|
-
return ast.createFunctionParameter({
|
|
539
|
+
if (isGroup(spec)) return createGroupParam(groupEntries(spec).map(([childName, child]) => ({ name: child.mode === "inlineSpread" ? spec.mode === "inlineSpread" ? child.value ?? childName : `...${child.value ?? childName}` : child.value ? `${childName}: ${child.value}` : childName })), []);
|
|
540
|
+
return ast.factory.createFunctionParameter({
|
|
532
541
|
name: spec.value ?? name,
|
|
533
542
|
rest: spec.mode === "inlineSpread"
|
|
534
543
|
});
|
|
@@ -541,10 +550,10 @@ function createFunctionParams(params) {
|
|
|
541
550
|
const entries = Object.entries(params).filter(([, spec]) => spec != null);
|
|
542
551
|
return {
|
|
543
552
|
toConstructor() {
|
|
544
|
-
return declarationPrinter$4.print(ast.createFunctionParameters({ params: entries.map(([name, spec]) => createDeclarationParam(name, spec)) })) ?? "";
|
|
553
|
+
return declarationPrinter$4.print(ast.factory.createFunctionParameters({ params: entries.map(([name, spec]) => createDeclarationParam(name, spec)) })) ?? "";
|
|
545
554
|
},
|
|
546
555
|
toCall() {
|
|
547
|
-
return callPrinter.print(ast.createFunctionParameters({ params: entries.map(([name, spec]) => createCallParam(name, spec)) })) ?? "";
|
|
556
|
+
return callPrinter.print(ast.factory.createFunctionParameters({ params: entries.map(([name, spec]) => createCallParam(name, spec)) })) ?? "";
|
|
548
557
|
}
|
|
549
558
|
};
|
|
550
559
|
}
|
|
@@ -689,12 +698,11 @@ function buildReturnStatement({ dataReturnType, parser, node, zodResolver, tsRes
|
|
|
689
698
|
//#region src/components/Url.tsx
|
|
690
699
|
const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
|
|
691
700
|
function buildUrlParamsNode({ paramsType, paramsCasing, pathParamsType, node, tsResolver }) {
|
|
692
|
-
|
|
701
|
+
return createOperationParams({
|
|
693
702
|
...node,
|
|
694
703
|
parameters: node.parameters.filter((p) => p.in === "path"),
|
|
695
704
|
requestBody: void 0
|
|
696
|
-
}
|
|
697
|
-
return ast.createOperationParams(urlNode, {
|
|
705
|
+
}, {
|
|
698
706
|
paramsType: paramsType === "object" ? "object" : "inline",
|
|
699
707
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
700
708
|
paramsCasing,
|
|
@@ -739,17 +747,14 @@ function Url({ name, isExportable = true, isIndexable = true, baseURL, paramsTyp
|
|
|
739
747
|
//#region src/components/Client.tsx
|
|
740
748
|
const declarationPrinter$2 = functionPrinter({ mode: "declaration" });
|
|
741
749
|
function buildClientParamsNode({ paramsType, paramsCasing, pathParamsType, node, tsResolver, isConfigurable }) {
|
|
742
|
-
return
|
|
750
|
+
return createOperationParams(node, {
|
|
743
751
|
paramsType,
|
|
744
752
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
745
753
|
paramsCasing,
|
|
746
754
|
resolver: tsResolver,
|
|
747
|
-
extraParams: [...isConfigurable ? [ast.createFunctionParameter({
|
|
755
|
+
extraParams: [...isConfigurable ? [ast.factory.createFunctionParameter({
|
|
748
756
|
name: "config",
|
|
749
|
-
type:
|
|
750
|
-
variant: "reference",
|
|
751
|
-
name: buildRequestConfigType(node, tsResolver)
|
|
752
|
-
}),
|
|
757
|
+
type: buildRequestConfigType(node, tsResolver),
|
|
753
758
|
default: "{}"
|
|
754
759
|
})] : []]
|
|
755
760
|
});
|
|
@@ -1546,7 +1551,7 @@ const operationsGenerator = defineGenerator({
|
|
|
1546
1551
|
method: node.method.toLowerCase()
|
|
1547
1552
|
};
|
|
1548
1553
|
}
|
|
1549
|
-
return [ast.createFile({
|
|
1554
|
+
return [ast.factory.createFile({
|
|
1550
1555
|
baseName: file.baseName,
|
|
1551
1556
|
path: file.path,
|
|
1552
1557
|
meta: file.meta,
|
|
@@ -1566,14 +1571,14 @@ const operationsGenerator = defineGenerator({
|
|
|
1566
1571
|
baseName: file.baseName
|
|
1567
1572
|
}
|
|
1568
1573
|
}),
|
|
1569
|
-
sources: [ast.createSource({
|
|
1574
|
+
sources: [ast.factory.createSource({
|
|
1570
1575
|
name,
|
|
1571
1576
|
isExportable: true,
|
|
1572
1577
|
isIndexable: true,
|
|
1573
|
-
nodes: [ast.createConst({
|
|
1578
|
+
nodes: [ast.factory.createConst({
|
|
1574
1579
|
name,
|
|
1575
1580
|
export: true,
|
|
1576
|
-
nodes: [ast.createText(JSON.stringify(operationsObject, void 0, 2))]
|
|
1581
|
+
nodes: [ast.factory.createText(JSON.stringify(operationsObject, void 0, 2))]
|
|
1577
1582
|
})]
|
|
1578
1583
|
})]
|
|
1579
1584
|
})];
|
|
@@ -1998,7 +2003,7 @@ const pluginClient = definePlugin((options) => {
|
|
|
1998
2003
|
const { output = {
|
|
1999
2004
|
path: "clients",
|
|
2000
2005
|
barrel: { type: "named" }
|
|
2001
|
-
}, group, exclude = [], include, override = [], urlType = false, dataReturnType = "data", paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", operations = false, paramsCasing, clientType = options.sdk ? "class" : "function", parser = false, client = "axios", importPath, bundle = false, sdk, baseURL, resolver: userResolver,
|
|
2006
|
+
}, group, exclude = [], include, override = [], urlType = false, dataReturnType = "data", paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", operations = false, paramsCasing, clientType = options.sdk ? "class" : "function", parser = false, client = "axios", importPath, bundle = false, sdk, baseURL, resolver: userResolver, macros: userMacros } = options;
|
|
2002
2007
|
const resolvedImportPath = importPath ?? (!bundle ? `@kubb/plugin-client/clients/${client}` : void 0);
|
|
2003
2008
|
const selectedGenerators = options.generators ?? [
|
|
2004
2009
|
clientType === "staticClass" ? staticClassClientGenerator : clientType === "class" ? classClientGenerator : clientGenerator,
|
|
@@ -2036,7 +2041,7 @@ const pluginClient = definePlugin((options) => {
|
|
|
2036
2041
|
resolver
|
|
2037
2042
|
});
|
|
2038
2043
|
ctx.setResolver(resolver);
|
|
2039
|
-
if (
|
|
2044
|
+
if (userMacros?.length) ctx.setMacros(userMacros);
|
|
2040
2045
|
for (const gen of selectedGenerators) ctx.addGenerator(gen);
|
|
2041
2046
|
const root = path.resolve(ctx.config.root, ctx.config.output.path);
|
|
2042
2047
|
if (!resolvedImportPath?.startsWith(".")) {
|
|
@@ -2044,21 +2049,21 @@ const pluginClient = definePlugin((options) => {
|
|
|
2044
2049
|
ctx.injectFile({
|
|
2045
2050
|
baseName: "client.ts",
|
|
2046
2051
|
path: path.resolve(root, ".kubb/client.ts"),
|
|
2047
|
-
sources: [ast.createSource({
|
|
2052
|
+
sources: [ast.factory.createSource({
|
|
2048
2053
|
name: "client",
|
|
2049
|
-
nodes: isInlineSource ? [ast.createText(client === "fetch" ? source$1 : source)] : [],
|
|
2054
|
+
nodes: isInlineSource ? [ast.factory.createText(client === "fetch" ? source$1 : source)] : [],
|
|
2050
2055
|
isExportable: true,
|
|
2051
2056
|
isIndexable: true
|
|
2052
2057
|
})],
|
|
2053
|
-
exports: !isInlineSource && resolvedImportPath ? [ast.createExport({ path: resolvedImportPath })] : []
|
|
2058
|
+
exports: !isInlineSource && resolvedImportPath ? [ast.factory.createExport({ path: resolvedImportPath })] : []
|
|
2054
2059
|
});
|
|
2055
2060
|
}
|
|
2056
2061
|
ctx.injectFile({
|
|
2057
2062
|
baseName: "config.ts",
|
|
2058
2063
|
path: path.resolve(root, ".kubb/config.ts"),
|
|
2059
|
-
sources: [ast.createSource({
|
|
2064
|
+
sources: [ast.factory.createSource({
|
|
2060
2065
|
name: "config",
|
|
2061
|
-
nodes: [ast.createText(source$2)],
|
|
2066
|
+
nodes: [ast.factory.createText(source$2)],
|
|
2062
2067
|
isExportable: false,
|
|
2063
2068
|
isIndexable: false
|
|
2064
2069
|
})]
|