@kubb/plugin-fetch 5.4.0 → 5.4.2

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.js CHANGED
@@ -5,6 +5,7 @@ import { createFunctionParameter, createFunctionParameters, functionPrinter, plu
5
5
  import { File, Function, jsxRenderer } from "kubb/jsx";
6
6
  import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
7
7
  import { pluginZodName } from "@kubb/plugin-zod";
8
+ import { readFileSync } from "node:fs";
8
9
  import { fileURLToPath } from "node:url";
9
10
  //#region ../../internals/shared/src/params.ts
10
11
  /**
@@ -1467,10 +1468,52 @@ const pluginFetch = definePlugin((options) => {
1467
1468
  path: path.resolve(root, ".kubb/serializers.ts"),
1468
1469
  copy: fetchSerializersTemplatePath
1469
1470
  });
1471
+ const clientPath = path.resolve(root, ".kubb/client.ts");
1472
+ const clientSource = readFileSync(fetchClientTemplatePath, "utf8");
1473
+ const clientBody = clientSource.slice(clientSource.indexOf("\n\n") + 2);
1474
+ const runtimeRoot = path.dirname(clientPath);
1470
1475
  ctx.injectFile({
1471
1476
  baseName: "client.ts",
1472
- path: path.resolve(root, ".kubb/client.ts"),
1473
- copy: fetchClientTemplatePath,
1477
+ path: clientPath,
1478
+ imports: [
1479
+ ast.factory.createImport({
1480
+ name: [
1481
+ "applyHeaderStyles",
1482
+ "defaultBodySerializer",
1483
+ "defaultPathSerializer",
1484
+ "defaultQuerySerializer",
1485
+ "isDefaultJsonBody",
1486
+ "serializeCookies"
1487
+ ],
1488
+ path: path.resolve(root, ".kubb/serializers.ts"),
1489
+ root: runtimeRoot
1490
+ }),
1491
+ ast.factory.createImport({
1492
+ name: [
1493
+ "HeadersInit",
1494
+ "PathParamStyle",
1495
+ "PathSerializer",
1496
+ "RequestBody",
1497
+ "Serializers",
1498
+ "Styles"
1499
+ ],
1500
+ path: path.resolve(root, ".kubb/serializers.ts"),
1501
+ root: runtimeRoot,
1502
+ isTypeOnly: true
1503
+ }),
1504
+ ast.factory.createImport({
1505
+ name: ["ParseError", "validateStandardSchema"],
1506
+ path: path.resolve(root, ".kubb/standardSchema.ts"),
1507
+ root: runtimeRoot
1508
+ }),
1509
+ ast.factory.createImport({
1510
+ name: ["StandardSchemaValidator"],
1511
+ path: path.resolve(root, ".kubb/standardSchema.ts"),
1512
+ root: runtimeRoot,
1513
+ isTypeOnly: true
1514
+ })
1515
+ ],
1516
+ sources: [ast.factory.createSource({ nodes: [ast.factory.createText(clientBody)] })],
1474
1517
  footer: baseURLExpression ? `client.setConfig({ baseURL: ${baseURLExpression} })` : void 0
1475
1518
  });
1476
1519
  ctx.injectFile({