@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/dist/index.d.ts CHANGED
@@ -233,7 +233,7 @@ export declare const pluginFetchName = "plugin-fetch";
233
233
  * })
234
234
  * ```
235
235
  */
236
- export declare const pluginFetch: (options?: Options | undefined) => import("kubb/kit").Plugin<PluginFetch>;
236
+ export declare const pluginFetch: import("kubb/kit").PluginFactory<PluginFetch>;
237
237
  //#endregion
238
238
  export { type Options, type PluginFetch, type ResolvedOptions, type ResolverClient, pluginFetch as default };
239
239
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./rolldown-runtime-C0LytTxp.js";
2
- import { Diagnostics, Resolver, Url, ast, createResolver, defineGenerator, definePlugin, macroSimplifyUnion } from "kubb/kit";
2
+ import { Diagnostics, Resolver, Url, addGenerator, ast, createResolver, defineGenerator, definePlugin, injectFile, macroSimplifyUnion, setMacros, setResolver, useConfig } from "kubb/kit";
3
3
  import path from "node:path";
4
4
  import { createFunctionParameter, createFunctionParameters, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
5
5
  import { File, Function, jsxRenderer } from "kubb/jsx";
@@ -1454,6 +1454,15 @@ const resolverClient = createResolver({
1454
1454
  */
1455
1455
  const clientGenerator = createClientGenerator("fetch");
1456
1456
  //#endregion
1457
+ //#region kubb-extension.json
1458
+ var compatibility = {
1459
+ "kubb": ">=5.8.0",
1460
+ "node": ">=22"
1461
+ };
1462
+ //#endregion
1463
+ //#region package.json
1464
+ var version = "5.5.9";
1465
+ //#endregion
1457
1466
  //#region src/templates.ts
1458
1467
  /** Absolute path to the fetch client template, copied into `.kubb/client.ts`. */
1459
1468
  const fetchClientTemplatePath = fileURLToPath(new URL("../templates/fetch.ts", import.meta.url));
@@ -1493,57 +1502,61 @@ const pluginFetchName = "plugin-fetch";
1493
1502
  * })
1494
1503
  * ```
1495
1504
  */
1496
- const pluginFetch = definePlugin((options) => {
1497
- const { output = {
1498
- path: "clients",
1499
- barrel: { type: "named" }
1500
- }, exclude = [], include, override = [], baseURL, throwOnErrorDefault = true, validator = false, returnType = "full", group, sdk, resolver: userResolver } = options;
1501
- const resolved = {
1502
- output,
1503
- exclude,
1504
- include,
1505
- override,
1506
- group: createGroupConfig(group),
1507
- baseURL,
1508
- throwOnErrorDefault,
1509
- validator,
1510
- returnType,
1511
- sdk: sdk ? {
1512
- mode: sdk.mode ?? "tag",
1513
- name: sdk.name
1514
- } : void 0,
1515
- resolver: userResolver ? Resolver.merge(resolverClient, userResolver) : resolverClient
1516
- };
1517
- const selectedGenerators = resolved.sdk ? [createSdkGenerator()] : [clientGenerator];
1518
- return {
1505
+ const pluginFetch = definePlugin({
1506
+ meta: {
1519
1507
  name: pluginFetchName,
1520
- options,
1521
- dependencies: [pluginTsName, pluginZodName],
1522
- hooks: { "kubb:plugin:setup"(ctx) {
1523
- ctx.setOptions(resolved);
1524
- ctx.setResolver(resolved.resolver);
1525
- ctx.setMacros([...defaultMacros, ...options.macros ?? []]);
1526
- ctx.addGenerator(...selectedGenerators);
1527
- const root = path.resolve(ctx.config.root, ctx.config.output.path);
1528
- const baseURLExpression = baseURL ? baseURL.includes("${") ? `\`${baseURL.replaceAll("`", "\\`")}\`` : JSON.stringify(baseURL) : void 0;
1529
- ctx.injectFile({
1530
- baseName: "serializers.ts",
1531
- path: path.resolve(root, ".kubb/serializers.ts"),
1532
- copy: fetchSerializersTemplatePath
1533
- });
1534
- ctx.injectFile({
1535
- baseName: "client.ts",
1536
- path: path.resolve(root, ".kubb/client.ts"),
1537
- copy: fetchClientTemplatePath,
1538
- footer: baseURLExpression ? `client.setConfig({ baseURL: ${baseURLExpression} })` : void 0
1539
- });
1540
- ctx.injectFile({
1541
- baseName: "standardSchema.ts",
1542
- path: path.resolve(root, ".kubb/standardSchema.ts"),
1543
- copy: standardSchemaTemplatePath
1544
- });
1545
- } }
1546
- };
1508
+ version,
1509
+ compatibility
1510
+ },
1511
+ dependencies: {
1512
+ [pluginTsName]: { optional: true },
1513
+ [pluginZodName]: { optional: true }
1514
+ },
1515
+ setup(options) {
1516
+ const config = useConfig();
1517
+ const { output = {
1518
+ path: "clients",
1519
+ barrel: { type: "named" }
1520
+ }, exclude = [], include, override = [], baseURL, throwOnErrorDefault = true, validator = false, returnType = "full", group, sdk, resolver: userResolver } = options;
1521
+ const resolved = {
1522
+ output,
1523
+ exclude,
1524
+ include,
1525
+ override,
1526
+ group: createGroupConfig(group),
1527
+ baseURL,
1528
+ throwOnErrorDefault,
1529
+ validator,
1530
+ returnType,
1531
+ sdk: sdk ? {
1532
+ mode: sdk.mode ?? "tag",
1533
+ name: sdk.name
1534
+ } : void 0,
1535
+ resolver: userResolver ? Resolver.merge(resolverClient, userResolver) : resolverClient
1536
+ };
1537
+ setResolver(resolved.resolver);
1538
+ setMacros([...defaultMacros, ...options.macros ?? []]);
1539
+ addGenerator(resolved.sdk ? createSdkGenerator() : clientGenerator);
1540
+ const root = path.resolve(config.root, config.output.path);
1541
+ const baseURLExpression = baseURL ? baseURL.includes("${") ? `\`${baseURL.replaceAll("`", "\\`")}\`` : JSON.stringify(baseURL) : void 0;
1542
+ injectFile({
1543
+ baseName: "serializers.ts",
1544
+ path: path.resolve(root, ".kubb/serializers.ts"),
1545
+ copy: fetchSerializersTemplatePath
1546
+ });
1547
+ injectFile({
1548
+ baseName: "client.ts",
1549
+ path: path.resolve(root, ".kubb/client.ts"),
1550
+ copy: fetchClientTemplatePath,
1551
+ footer: baseURLExpression ? `client.setConfig({ baseURL: ${baseURLExpression} })` : void 0
1552
+ });
1553
+ injectFile({
1554
+ baseName: "standardSchema.ts",
1555
+ path: path.resolve(root, ".kubb/standardSchema.ts"),
1556
+ copy: standardSchemaTemplatePath
1557
+ });
1558
+ return resolved;
1559
+ }
1547
1560
  });
1548
1561
  //#endregion
1549
1562
  export { clientGenerator, pluginFetch as default, pluginFetch, pluginFetchName };