@kubb/plugin-fetch 5.0.0-beta.99 → 5.0.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-fetch",
3
- "version": "5.0.0-beta.99",
3
+ "version": "5.0.0",
4
4
  "description": "Generate a slim, type-safe HTTP client with Kubb based on the native Fetch api.",
5
5
  "keywords": [
6
6
  "api-client",
@@ -49,17 +49,17 @@
49
49
  "registry": "https://registry.npmjs.org/"
50
50
  },
51
51
  "dependencies": {
52
- "@kubb/plugin-ts": "5.0.0-beta.99",
53
- "@kubb/plugin-zod": "5.0.0-beta.99"
52
+ "@kubb/plugin-ts": "^5.0.0",
53
+ "@kubb/plugin-zod": "^5.0.0"
54
54
  },
55
55
  "devDependencies": {
56
- "kubb": "5.0.0-beta.97",
56
+ "kubb": "^5.0.0",
57
57
  "typescript": "^6.0.3",
58
- "@internals/client": "0.0.0",
59
- "@internals/shared": "0.0.0"
58
+ "@internals/shared": "0.0.0",
59
+ "@internals/client": "0.0.0"
60
60
  },
61
61
  "peerDependencies": {
62
- "kubb": "5.0.0-beta.97"
62
+ "kubb": "^5.0.0"
63
63
  },
64
64
  "engines": {
65
65
  "node": ">=22"
@@ -69,9 +69,6 @@
69
69
  "clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
70
70
  "lint": "oxlint .",
71
71
  "lint:fix": "oxlint --fix .",
72
- "release": "pnpm publish --no-git-check",
73
- "release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
74
- "release:stage": "pnpm stage publish --no-git-check",
75
72
  "start": "tsdown --watch",
76
73
  "test": "vitest --passWithNoTests",
77
74
  "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
@@ -1,106 +1,9 @@
1
- import path from 'node:path'
2
- import {
3
- buildZodErrorParse,
4
- getOperationSecurity,
5
- Operation,
6
- resolveRequestValidator,
7
- resolveResponseValidator,
8
- type SecurityDocument,
9
- } from '@internals/client'
10
- import { isEventStream, operationFileEntry } from '@internals/shared'
11
- import { ast, defineGenerator } from 'kubb/kit'
12
- import { pluginTsName } from '@kubb/plugin-ts'
13
- import { pluginZodName } from '@kubb/plugin-zod'
14
- import { File, jsxRenderer } from 'kubb/jsx'
1
+ import { createClientGenerator } from '@internals/client'
15
2
  import type { PluginFetch } from '../types.ts'
16
3
 
17
4
  /**
18
5
  * Built-in operation generator for `@kubb/plugin-fetch`. Emits one async function per OpenAPI
19
- * operation using the shared `Operation` component: a grouped `<Name>Request` type and a function that
20
- * forwards a single `options` object to the bundled `client` and returns the `RequestResult`.
6
+ * operation using the shared `Operation` component: a grouped `<Name>Request` type and a function
7
+ * that forwards a single `options` object to the bundled `client` and returns the `RequestResult`.
21
8
  */
22
- export const clientGenerator = defineGenerator<PluginFetch>({
23
- name: 'fetch',
24
- renderer: jsxRenderer,
25
- operation(node, ctx) {
26
- if (!ast.isHttpOperationNode(node)) return null
27
-
28
- const { config, driver, resolver, root } = ctx
29
- const { output, validator, group } = ctx.options
30
-
31
- const pluginTs = driver.getPlugin(pluginTsName)
32
- if (!pluginTs) return null
33
-
34
- const tsResolver = driver.getResolver(pluginTsName)
35
-
36
- const validatorEnabled = resolveResponseValidator(validator) === 'zod' || resolveRequestValidator(validator) === 'zod'
37
- const pluginZod = validatorEnabled ? driver.getPlugin(pluginZodName) : null
38
- const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null
39
-
40
- const hasRequestBody = Boolean(node.requestBody?.content?.[0]?.schema)
41
- const importedTypeNames = [tsResolver.response.options(node), tsResolver.response.responses(node)]
42
-
43
- const importedZodNames = zodResolver
44
- ? [
45
- resolveResponseValidator(validator) === 'zod' ? zodResolver.response.response?.(node) : null,
46
- resolveResponseValidator(validator) === 'zod' ? (buildZodErrorParse(node, zodResolver)?.expression ?? null) : null,
47
- resolveRequestValidator(validator) === 'zod' && hasRequestBody ? zodResolver.response.body?.(node) : null,
48
- ].filter((name): name is string => Boolean(name))
49
- : []
50
-
51
- const meta = {
52
- name: resolver.name(node.operationId),
53
- file: resolver.file({ ...operationFileEntry(node, node.operationId), root, output, group: group ?? undefined }),
54
- fileTs: tsResolver.file({
55
- ...operationFileEntry(node, node.operationId),
56
- root,
57
- output: pluginTs.options?.output ?? output,
58
- group: pluginTs.options?.group ?? undefined,
59
- }),
60
- fileZod:
61
- zodResolver && pluginZod?.options
62
- ? zodResolver.file({
63
- ...operationFileEntry(node, node.operationId),
64
- root,
65
- output: pluginZod.options.output ?? output,
66
- group: pluginZod.options?.group ?? undefined,
67
- })
68
- : null,
69
- } as const
70
-
71
- const security = getOperationSecurity({
72
- document: ctx.adapter.document as SecurityDocument | null | undefined,
73
- method: node.method,
74
- path: node.path,
75
- })
76
-
77
- const clientPath = path.resolve(root, '.kubb/client.ts')
78
- const eventStream = isEventStream(node)
79
-
80
- return (
81
- <File
82
- baseName={meta.file.baseName}
83
- path={meta.file.path}
84
- meta={meta.file.meta}
85
- banner={resolver.default.banner(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
86
- footer={resolver.default.footer(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
87
- >
88
- <File.Import name={eventStream ? ['client', 'toEventStream'] : ['client']} root={meta.file.path} path={clientPath} />
89
- <File.Import
90
- name={eventStream ? ['Options', 'EventStreamResult', 'SuccessOf'] : ['Options', 'RequestResult']}
91
- root={meta.file.path}
92
- path={clientPath}
93
- isTypeOnly
94
- />
95
-
96
- {meta.fileTs && importedTypeNames.length > 0 && (
97
- <File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
98
- )}
99
-
100
- {meta.fileZod && importedZodNames.length > 0 && <File.Import name={importedZodNames} root={meta.file.path} path={meta.fileZod.path} />}
101
-
102
- <Operation name={meta.name} node={node} tsResolver={tsResolver} zodResolver={zodResolver} validator={validator} security={security} />
103
- </File>
104
- )
105
- },
106
- })
9
+ export const clientGenerator = createClientGenerator<PluginFetch>('fetch')