@kubb/plugin-fetch 5.5.7 → 5.5.9
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/OVERVIEW.md +19 -0
- package/dist/index.cjs +63 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +64 -51
- package/dist/index.js.map +1 -1
- package/kubb-extension.json +191 -0
- package/package.json +8 -5
- package/src/plugin.ts +61 -64
package/OVERVIEW.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Fetch
|
|
2
|
+
|
|
3
|
+
Generates a type-safe HTTP client based on the native Fetch API from your OpenAPI spec. Each operation becomes one async function with grouped `path`, `query`, `headers`, and `body` parameters and a result keyed by status code.
|
|
4
|
+
|
|
5
|
+
This plugin provides the client runtime. Query plugins such as `@kubb/plugin-react-query`, `@kubb/plugin-vue-query`, `@kubb/plugin-swr`, and `@kubb/plugin-mcp` call the functions it generates.
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
- Add `@kubb/plugin-ts` for the operation types. Without it, `@kubb/plugin-zod` with `inferred: true` supplies them.
|
|
10
|
+
- Add `@kubb/plugin-zod` when you set `validator`.
|
|
11
|
+
- No HTTP client package is needed.
|
|
12
|
+
|
|
13
|
+
## Options worth knowing
|
|
14
|
+
|
|
15
|
+
- `baseURL` is prepended to every request.
|
|
16
|
+
- `validator: 'zod'` validates request and response bodies with the schemas from `@kubb/plugin-zod`.
|
|
17
|
+
- `sdk` generates a class-based SDK, grouped by tag or flat, instead of standalone functions. Query plugins need the standalone functions, so leave `sdk` unset when you use them.
|
|
18
|
+
- `returnType: 'data'` makes a call resolve to the success body instead of the full result with status, data, and error.
|
|
19
|
+
- `throwOnErrorDefault: false` returns documented error responses as values instead of throwing. A single call can still pass `throwOnError`.
|
package/dist/index.cjs
CHANGED
|
@@ -1480,6 +1480,15 @@ const resolverClient = (0, kubb_kit.createResolver)({
|
|
|
1480
1480
|
*/
|
|
1481
1481
|
const clientGenerator = createClientGenerator("fetch");
|
|
1482
1482
|
//#endregion
|
|
1483
|
+
//#region kubb-extension.json
|
|
1484
|
+
var compatibility = {
|
|
1485
|
+
"kubb": ">=5.8.0",
|
|
1486
|
+
"node": ">=22"
|
|
1487
|
+
};
|
|
1488
|
+
//#endregion
|
|
1489
|
+
//#region package.json
|
|
1490
|
+
var version = "5.5.9";
|
|
1491
|
+
//#endregion
|
|
1483
1492
|
//#region src/templates.ts
|
|
1484
1493
|
/** Absolute path to the fetch client template, copied into `.kubb/client.ts`. */
|
|
1485
1494
|
const fetchClientTemplatePath = (0, node_url.fileURLToPath)(new URL("../templates/fetch.ts", require("url").pathToFileURL(__filename).href));
|
|
@@ -1519,57 +1528,61 @@ const pluginFetchName = "plugin-fetch";
|
|
|
1519
1528
|
* })
|
|
1520
1529
|
* ```
|
|
1521
1530
|
*/
|
|
1522
|
-
const pluginFetch = (0, kubb_kit.definePlugin)(
|
|
1523
|
-
|
|
1524
|
-
path: "clients",
|
|
1525
|
-
barrel: { type: "named" }
|
|
1526
|
-
}, exclude = [], include, override = [], baseURL, throwOnErrorDefault = true, validator = false, returnType = "full", group, sdk, resolver: userResolver } = options;
|
|
1527
|
-
const resolved = {
|
|
1528
|
-
output,
|
|
1529
|
-
exclude,
|
|
1530
|
-
include,
|
|
1531
|
-
override,
|
|
1532
|
-
group: createGroupConfig(group),
|
|
1533
|
-
baseURL,
|
|
1534
|
-
throwOnErrorDefault,
|
|
1535
|
-
validator,
|
|
1536
|
-
returnType,
|
|
1537
|
-
sdk: sdk ? {
|
|
1538
|
-
mode: sdk.mode ?? "tag",
|
|
1539
|
-
name: sdk.name
|
|
1540
|
-
} : void 0,
|
|
1541
|
-
resolver: userResolver ? kubb_kit.Resolver.merge(resolverClient, userResolver) : resolverClient
|
|
1542
|
-
};
|
|
1543
|
-
const selectedGenerators = resolved.sdk ? [createSdkGenerator()] : [clientGenerator];
|
|
1544
|
-
return {
|
|
1531
|
+
const pluginFetch = (0, kubb_kit.definePlugin)({
|
|
1532
|
+
meta: {
|
|
1545
1533
|
name: pluginFetchName,
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1534
|
+
version,
|
|
1535
|
+
compatibility
|
|
1536
|
+
},
|
|
1537
|
+
dependencies: {
|
|
1538
|
+
[_kubb_plugin_ts.pluginTsName]: { optional: true },
|
|
1539
|
+
[_kubb_plugin_zod.pluginZodName]: { optional: true }
|
|
1540
|
+
},
|
|
1541
|
+
setup(options) {
|
|
1542
|
+
const config = (0, kubb_kit.useConfig)();
|
|
1543
|
+
const { output = {
|
|
1544
|
+
path: "clients",
|
|
1545
|
+
barrel: { type: "named" }
|
|
1546
|
+
}, exclude = [], include, override = [], baseURL, throwOnErrorDefault = true, validator = false, returnType = "full", group, sdk, resolver: userResolver } = options;
|
|
1547
|
+
const resolved = {
|
|
1548
|
+
output,
|
|
1549
|
+
exclude,
|
|
1550
|
+
include,
|
|
1551
|
+
override,
|
|
1552
|
+
group: createGroupConfig(group),
|
|
1553
|
+
baseURL,
|
|
1554
|
+
throwOnErrorDefault,
|
|
1555
|
+
validator,
|
|
1556
|
+
returnType,
|
|
1557
|
+
sdk: sdk ? {
|
|
1558
|
+
mode: sdk.mode ?? "tag",
|
|
1559
|
+
name: sdk.name
|
|
1560
|
+
} : void 0,
|
|
1561
|
+
resolver: userResolver ? kubb_kit.Resolver.merge(resolverClient, userResolver) : resolverClient
|
|
1562
|
+
};
|
|
1563
|
+
(0, kubb_kit.setResolver)(resolved.resolver);
|
|
1564
|
+
(0, kubb_kit.setMacros)([...defaultMacros, ...options.macros ?? []]);
|
|
1565
|
+
(0, kubb_kit.addGenerator)(resolved.sdk ? createSdkGenerator() : clientGenerator);
|
|
1566
|
+
const root = node_path.default.resolve(config.root, config.output.path);
|
|
1567
|
+
const baseURLExpression = baseURL ? baseURL.includes("${") ? `\`${baseURL.replaceAll("`", "\\`")}\`` : JSON.stringify(baseURL) : void 0;
|
|
1568
|
+
(0, kubb_kit.injectFile)({
|
|
1569
|
+
baseName: "serializers.ts",
|
|
1570
|
+
path: node_path.default.resolve(root, ".kubb/serializers.ts"),
|
|
1571
|
+
copy: fetchSerializersTemplatePath
|
|
1572
|
+
});
|
|
1573
|
+
(0, kubb_kit.injectFile)({
|
|
1574
|
+
baseName: "client.ts",
|
|
1575
|
+
path: node_path.default.resolve(root, ".kubb/client.ts"),
|
|
1576
|
+
copy: fetchClientTemplatePath,
|
|
1577
|
+
footer: baseURLExpression ? `client.setConfig({ baseURL: ${baseURLExpression} })` : void 0
|
|
1578
|
+
});
|
|
1579
|
+
(0, kubb_kit.injectFile)({
|
|
1580
|
+
baseName: "standardSchema.ts",
|
|
1581
|
+
path: node_path.default.resolve(root, ".kubb/standardSchema.ts"),
|
|
1582
|
+
copy: standardSchemaTemplatePath
|
|
1583
|
+
});
|
|
1584
|
+
return resolved;
|
|
1585
|
+
}
|
|
1573
1586
|
});
|
|
1574
1587
|
//#endregion
|
|
1575
1588
|
exports.clientGenerator = clientGenerator;
|