@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.cjs
CHANGED
|
@@ -365,7 +365,7 @@ function buildOperationComments(node, options = {}) {
|
|
|
365
365
|
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
366
366
|
}
|
|
367
367
|
function getOperationParameters(node, options = {}) {
|
|
368
|
-
const params =
|
|
368
|
+
const params = (0, _kubb_ast_utils.caseParams)(node.parameters, options.paramsCasing);
|
|
369
369
|
return {
|
|
370
370
|
path: params.filter((param) => param.in === "path"),
|
|
371
371
|
query: params.filter((param) => param.in === "query"),
|
|
@@ -498,43 +498,52 @@ const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
|
498
498
|
function isGroup(spec) {
|
|
499
499
|
return "children" in spec;
|
|
500
500
|
}
|
|
501
|
-
function
|
|
502
|
-
return
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
501
|
+
function groupEntries(group) {
|
|
502
|
+
return Object.entries(group.children).filter(([, child]) => child != null);
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Assembles a destructured group parameter from a binding pattern and an optional
|
|
506
|
+
* type literal. Built directly because `createFunctionParameter({ properties })`
|
|
507
|
+
* requires every member to carry a type, while these groups also hold untyped,
|
|
508
|
+
* value-only call entries.
|
|
509
|
+
*/
|
|
510
|
+
function createGroupParam(elements, members, default_) {
|
|
511
|
+
return {
|
|
512
|
+
kind: "FunctionParameter",
|
|
513
|
+
name: _kubb_core.ast.factory.createObjectBindingPattern({ elements }),
|
|
514
|
+
type: members.length ? _kubb_core.ast.factory.createTypeLiteral({ members }) : void 0,
|
|
515
|
+
default: default_,
|
|
516
|
+
optional: false
|
|
517
|
+
};
|
|
506
518
|
}
|
|
507
519
|
function createDeclarationLeaf(name, spec) {
|
|
508
|
-
if (spec.default !== void 0) return _kubb_core.ast.createFunctionParameter({
|
|
520
|
+
if (spec.default !== void 0) return _kubb_core.ast.factory.createFunctionParameter({
|
|
509
521
|
name,
|
|
510
|
-
type:
|
|
522
|
+
type: spec.type,
|
|
511
523
|
default: spec.default,
|
|
512
524
|
rest: spec.mode === "inlineSpread"
|
|
513
525
|
});
|
|
514
|
-
return _kubb_core.ast.createFunctionParameter({
|
|
526
|
+
return _kubb_core.ast.factory.createFunctionParameter({
|
|
515
527
|
name,
|
|
516
|
-
type:
|
|
528
|
+
type: spec.type,
|
|
517
529
|
optional: !!spec.optional,
|
|
518
530
|
rest: spec.mode === "inlineSpread"
|
|
519
531
|
});
|
|
520
532
|
}
|
|
521
533
|
function createDeclarationParam(name, spec) {
|
|
522
|
-
if (isGroup(spec))
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
534
|
+
if (isGroup(spec)) {
|
|
535
|
+
const entries = groupEntries(spec);
|
|
536
|
+
return createGroupParam(entries.map(([childName]) => ({ name: childName })), entries.filter(([, child]) => child.type).map(([childName, child]) => ({
|
|
537
|
+
name: childName,
|
|
538
|
+
type: child.type,
|
|
539
|
+
optional: !!child.optional || child.default !== void 0
|
|
540
|
+
})), spec.default);
|
|
541
|
+
}
|
|
527
542
|
return createDeclarationLeaf(name, spec);
|
|
528
543
|
}
|
|
529
544
|
function createCallParam(name, spec) {
|
|
530
|
-
if (isGroup(spec)) return
|
|
531
|
-
|
|
532
|
-
properties: Object.entries(spec.children).filter(([, child]) => child != null).map(([childName, child]) => _kubb_core.ast.createFunctionParameter({
|
|
533
|
-
name: child?.mode === "inlineSpread" ? spec.mode === "inlineSpread" ? child.value ?? childName : `...${child.value ?? childName}` : child?.value ? `${childName}: ${child.value}` : childName,
|
|
534
|
-
rest: spec.mode === "inlineSpread" && child?.mode === "inlineSpread"
|
|
535
|
-
}))
|
|
536
|
-
});
|
|
537
|
-
return _kubb_core.ast.createFunctionParameter({
|
|
545
|
+
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 })), []);
|
|
546
|
+
return _kubb_core.ast.factory.createFunctionParameter({
|
|
538
547
|
name: spec.value ?? name,
|
|
539
548
|
rest: spec.mode === "inlineSpread"
|
|
540
549
|
});
|
|
@@ -547,10 +556,10 @@ function createFunctionParams(params) {
|
|
|
547
556
|
const entries = Object.entries(params).filter(([, spec]) => spec != null);
|
|
548
557
|
return {
|
|
549
558
|
toConstructor() {
|
|
550
|
-
return declarationPrinter$4.print(_kubb_core.ast.createFunctionParameters({ params: entries.map(([name, spec]) => createDeclarationParam(name, spec)) })) ?? "";
|
|
559
|
+
return declarationPrinter$4.print(_kubb_core.ast.factory.createFunctionParameters({ params: entries.map(([name, spec]) => createDeclarationParam(name, spec)) })) ?? "";
|
|
551
560
|
},
|
|
552
561
|
toCall() {
|
|
553
|
-
return callPrinter.print(_kubb_core.ast.createFunctionParameters({ params: entries.map(([name, spec]) => createCallParam(name, spec)) })) ?? "";
|
|
562
|
+
return callPrinter.print(_kubb_core.ast.factory.createFunctionParameters({ params: entries.map(([name, spec]) => createCallParam(name, spec)) })) ?? "";
|
|
554
563
|
}
|
|
555
564
|
};
|
|
556
565
|
}
|
|
@@ -695,12 +704,11 @@ function buildReturnStatement({ dataReturnType, parser, node, zodResolver, tsRes
|
|
|
695
704
|
//#region src/components/Url.tsx
|
|
696
705
|
const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
697
706
|
function buildUrlParamsNode({ paramsType, paramsCasing, pathParamsType, node, tsResolver }) {
|
|
698
|
-
|
|
707
|
+
return (0, _kubb_ast_utils.createOperationParams)({
|
|
699
708
|
...node,
|
|
700
709
|
parameters: node.parameters.filter((p) => p.in === "path"),
|
|
701
710
|
requestBody: void 0
|
|
702
|
-
}
|
|
703
|
-
return _kubb_core.ast.createOperationParams(urlNode, {
|
|
711
|
+
}, {
|
|
704
712
|
paramsType: paramsType === "object" ? "object" : "inline",
|
|
705
713
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
706
714
|
paramsCasing,
|
|
@@ -745,17 +753,14 @@ function Url({ name, isExportable = true, isIndexable = true, baseURL, paramsTyp
|
|
|
745
753
|
//#region src/components/Client.tsx
|
|
746
754
|
const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
747
755
|
function buildClientParamsNode({ paramsType, paramsCasing, pathParamsType, node, tsResolver, isConfigurable }) {
|
|
748
|
-
return
|
|
756
|
+
return (0, _kubb_ast_utils.createOperationParams)(node, {
|
|
749
757
|
paramsType,
|
|
750
758
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
751
759
|
paramsCasing,
|
|
752
760
|
resolver: tsResolver,
|
|
753
|
-
extraParams: [...isConfigurable ? [_kubb_core.ast.createFunctionParameter({
|
|
761
|
+
extraParams: [...isConfigurable ? [_kubb_core.ast.factory.createFunctionParameter({
|
|
754
762
|
name: "config",
|
|
755
|
-
type:
|
|
756
|
-
variant: "reference",
|
|
757
|
-
name: buildRequestConfigType(node, tsResolver)
|
|
758
|
-
}),
|
|
763
|
+
type: buildRequestConfigType(node, tsResolver),
|
|
759
764
|
default: "{}"
|
|
760
765
|
})] : []]
|
|
761
766
|
});
|
|
@@ -1552,7 +1557,7 @@ const operationsGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1552
1557
|
method: node.method.toLowerCase()
|
|
1553
1558
|
};
|
|
1554
1559
|
}
|
|
1555
|
-
return [_kubb_core.ast.createFile({
|
|
1560
|
+
return [_kubb_core.ast.factory.createFile({
|
|
1556
1561
|
baseName: file.baseName,
|
|
1557
1562
|
path: file.path,
|
|
1558
1563
|
meta: file.meta,
|
|
@@ -1572,14 +1577,14 @@ const operationsGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1572
1577
|
baseName: file.baseName
|
|
1573
1578
|
}
|
|
1574
1579
|
}),
|
|
1575
|
-
sources: [_kubb_core.ast.createSource({
|
|
1580
|
+
sources: [_kubb_core.ast.factory.createSource({
|
|
1576
1581
|
name,
|
|
1577
1582
|
isExportable: true,
|
|
1578
1583
|
isIndexable: true,
|
|
1579
|
-
nodes: [_kubb_core.ast.createConst({
|
|
1584
|
+
nodes: [_kubb_core.ast.factory.createConst({
|
|
1580
1585
|
name,
|
|
1581
1586
|
export: true,
|
|
1582
|
-
nodes: [_kubb_core.ast.createText(JSON.stringify(operationsObject, void 0, 2))]
|
|
1587
|
+
nodes: [_kubb_core.ast.factory.createText(JSON.stringify(operationsObject, void 0, 2))]
|
|
1583
1588
|
})]
|
|
1584
1589
|
})]
|
|
1585
1590
|
})];
|
|
@@ -2004,7 +2009,7 @@ const pluginClient = (0, _kubb_core.definePlugin)((options) => {
|
|
|
2004
2009
|
const { output = {
|
|
2005
2010
|
path: "clients",
|
|
2006
2011
|
barrel: { type: "named" }
|
|
2007
|
-
}, 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,
|
|
2012
|
+
}, 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;
|
|
2008
2013
|
const resolvedImportPath = importPath ?? (!bundle ? `@kubb/plugin-client/clients/${client}` : void 0);
|
|
2009
2014
|
const selectedGenerators = options.generators ?? [
|
|
2010
2015
|
clientType === "staticClass" ? staticClassClientGenerator : clientType === "class" ? classClientGenerator : clientGenerator,
|
|
@@ -2042,7 +2047,7 @@ const pluginClient = (0, _kubb_core.definePlugin)((options) => {
|
|
|
2042
2047
|
resolver
|
|
2043
2048
|
});
|
|
2044
2049
|
ctx.setResolver(resolver);
|
|
2045
|
-
if (
|
|
2050
|
+
if (userMacros?.length) ctx.setMacros(userMacros);
|
|
2046
2051
|
for (const gen of selectedGenerators) ctx.addGenerator(gen);
|
|
2047
2052
|
const root = node_path$1.default.resolve(ctx.config.root, ctx.config.output.path);
|
|
2048
2053
|
if (!resolvedImportPath?.startsWith(".")) {
|
|
@@ -2050,21 +2055,21 @@ const pluginClient = (0, _kubb_core.definePlugin)((options) => {
|
|
|
2050
2055
|
ctx.injectFile({
|
|
2051
2056
|
baseName: "client.ts",
|
|
2052
2057
|
path: node_path$1.default.resolve(root, ".kubb/client.ts"),
|
|
2053
|
-
sources: [_kubb_core.ast.createSource({
|
|
2058
|
+
sources: [_kubb_core.ast.factory.createSource({
|
|
2054
2059
|
name: "client",
|
|
2055
|
-
nodes: isInlineSource ? [_kubb_core.ast.createText(client === "fetch" ? require_templates_clients_fetch_source.source : require_templates_clients_axios_source.source)] : [],
|
|
2060
|
+
nodes: isInlineSource ? [_kubb_core.ast.factory.createText(client === "fetch" ? require_templates_clients_fetch_source.source : require_templates_clients_axios_source.source)] : [],
|
|
2056
2061
|
isExportable: true,
|
|
2057
2062
|
isIndexable: true
|
|
2058
2063
|
})],
|
|
2059
|
-
exports: !isInlineSource && resolvedImportPath ? [_kubb_core.ast.createExport({ path: resolvedImportPath })] : []
|
|
2064
|
+
exports: !isInlineSource && resolvedImportPath ? [_kubb_core.ast.factory.createExport({ path: resolvedImportPath })] : []
|
|
2060
2065
|
});
|
|
2061
2066
|
}
|
|
2062
2067
|
ctx.injectFile({
|
|
2063
2068
|
baseName: "config.ts",
|
|
2064
2069
|
path: node_path$1.default.resolve(root, ".kubb/config.ts"),
|
|
2065
|
-
sources: [_kubb_core.ast.createSource({
|
|
2070
|
+
sources: [_kubb_core.ast.factory.createSource({
|
|
2066
2071
|
name: "config",
|
|
2067
|
-
nodes: [_kubb_core.ast.createText(require_templates_config_source.source)],
|
|
2072
|
+
nodes: [_kubb_core.ast.factory.createText(require_templates_config_source.source)],
|
|
2068
2073
|
isExportable: false,
|
|
2069
2074
|
isIndexable: false
|
|
2070
2075
|
})]
|