@kubb/plugin-zod 3.0.0-alpha.5 → 3.0.0-alpha.6

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.
@@ -1,7 +1,7 @@
1
1
  import { ReactNode } from 'react';
2
- export { O as Operations } from './Operations-BlQtRP31.cjs';
2
+ export { O as Operations } from './Operations-BG26e_MW.cjs';
3
3
  import '@kubb/oas';
4
- import '@kubb/react';
4
+ import '@kubb/react/types';
5
5
 
6
6
  type Props$1 = {
7
7
  description?: string;
@@ -1,7 +1,7 @@
1
1
  import { ReactNode } from 'react';
2
- export { O as Operations } from './Operations-BlQtRP31.js';
2
+ export { O as Operations } from './Operations-BG26e_MW.js';
3
3
  import '@kubb/oas';
4
- import '@kubb/react';
4
+ import '@kubb/react/types';
5
5
 
6
6
  type Props$1 = {
7
7
  description?: string;
@@ -1,8 +1,12 @@
1
1
  import {
2
2
  OperationSchema,
3
3
  Operations,
4
- Schema
5
- } from "./chunk-MGSFBU7O.js";
4
+ Schema,
5
+ init_esm_shims
6
+ } from "./chunk-PMYJN6KG.js";
7
+
8
+ // src/components/index.ts
9
+ init_esm_shims();
6
10
  export {
7
11
  OperationSchema,
8
12
  Operations,
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"sources":["../src/components/index.ts"],"sourcesContent":["export { OperationSchema } from './OperationSchema.tsx'\nexport { Operations } from './Operations.tsx'\nexport { Schema } from './Schema.tsx'\n"],"mappings":";;;;;;;;AAAA;","names":[]}
package/dist/index.cjs CHANGED
@@ -1,9 +1,13 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunkRISCJCJNcjs = require('./chunk-RISCJCJN.cjs');
5
4
 
5
+ var _chunkINEB36EJcjs = require('./chunk-INEB36EJ.cjs');
6
6
 
7
+ // src/index.ts
8
+ _chunkINEB36EJcjs.init_cjs_shims.call(void 0, );
7
9
 
8
- exports.pluginZod = _chunkRISCJCJNcjs.pluginZod; exports.pluginZodName = _chunkRISCJCJNcjs.pluginZodName;
10
+
11
+
12
+ exports.pluginZod = _chunkINEB36EJcjs.pluginZod; exports.pluginZodName = _chunkINEB36EJcjs.pluginZodName;
9
13
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-zod/dist/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,yGAAC","file":"/home/runner/work/kubb/kubb/packages/plugin-zod/dist/index.cjs"}
1
+ {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-zod/dist/index.cjs","../src/index.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACNA,8CAAA,CAAA;ADQA;AACE;AACA;AACF,yGAAC","file":"/home/runner/work/kubb/kubb/packages/plugin-zod/dist/index.cjs","sourcesContent":[null,"export { pluginZod, pluginZodName } from './plugin.ts'\nexport type { PluginZod } from './types.ts'\n"]}
package/dist/index.d.cts CHANGED
@@ -3,8 +3,8 @@ import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
3
3
  import * as KubbFile from '@kubb/fs/types';
4
4
  import { SchemaObject } from '@kubb/oas';
5
5
  import { ResolvePathOptions, Exclude, Include, Override, Schema } from '@kubb/plugin-oas';
6
- import { O as Operations } from './Operations-BlQtRP31.cjs';
7
- import '@kubb/react';
6
+ import { O as Operations } from './Operations-BG26e_MW.cjs';
7
+ import '@kubb/react/types';
8
8
  import 'react';
9
9
 
10
10
  type Templates = {
package/dist/index.d.ts CHANGED
@@ -3,8 +3,8 @@ import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
3
3
  import * as KubbFile from '@kubb/fs/types';
4
4
  import { SchemaObject } from '@kubb/oas';
5
5
  import { ResolvePathOptions, Exclude, Include, Override, Schema } from '@kubb/plugin-oas';
6
- import { O as Operations } from './Operations-BlQtRP31.js';
7
- import '@kubb/react';
6
+ import { O as Operations } from './Operations-BG26e_MW.js';
7
+ import '@kubb/react/types';
8
8
  import 'react';
9
9
 
10
10
  type Templates = {
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  import {
2
+ init_esm_shims,
2
3
  pluginZod,
3
4
  pluginZodName
4
- } from "./chunk-MGSFBU7O.js";
5
+ } from "./chunk-PMYJN6KG.js";
6
+
7
+ // src/index.ts
8
+ init_esm_shims();
5
9
  export {
6
10
  pluginZod,
7
11
  pluginZodName
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { pluginZod, pluginZodName } from './plugin.ts'\nexport type { PluginZod } from './types.ts'\n"],"mappings":";;;;;;;AAAA;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-zod",
3
- "version": "3.0.0-alpha.5",
3
+ "version": "3.0.0-alpha.6",
4
4
  "description": "Generator plugin-zod",
5
5
  "keywords": [
6
6
  "typescript",
@@ -56,25 +56,25 @@
56
56
  "!/**/__tests__/**"
57
57
  ],
58
58
  "dependencies": {
59
- "@kubb/core": "3.0.0-alpha.5",
60
- "@kubb/fs": "3.0.0-alpha.5",
61
- "@kubb/oas": "3.0.0-alpha.5",
62
- "@kubb/parser-ts": "3.0.0-alpha.5",
63
- "@kubb/plugin-oas": "3.0.0-alpha.5",
64
- "@kubb/react": "3.0.0-alpha.5",
65
- "@kubb/types": "3.0.0-alpha.5"
59
+ "@kubb/core": "3.0.0-alpha.6",
60
+ "@kubb/fs": "3.0.0-alpha.6",
61
+ "@kubb/oas": "3.0.0-alpha.6",
62
+ "@kubb/parser-ts": "3.0.0-alpha.6",
63
+ "@kubb/plugin-oas": "3.0.0-alpha.6",
64
+ "@kubb/react": "3.0.0-alpha.6",
65
+ "@kubb/types": "3.0.0-alpha.6"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@types/react": "^18.3.4",
69
69
  "prettier": "^3.3.3",
70
70
  "react": "^18.3.1",
71
71
  "tsup": "^8.2.4",
72
- "@kubb/config-biome": "3.0.0-alpha.5",
73
- "@kubb/config-ts": "3.0.0-alpha.5",
74
- "@kubb/config-tsup": "3.0.0-alpha.5"
72
+ "@kubb/config-ts": "3.0.0-alpha.6",
73
+ "@kubb/config-tsup": "3.0.0-alpha.6",
74
+ "@kubb/config-biome": "3.0.0-alpha.6"
75
75
  },
76
76
  "peerDependencies": {
77
- "@kubb/react": "3.0.0-alpha.5"
77
+ "@kubb/react": "3.0.0-alpha.6"
78
78
  },
79
79
  "engines": {
80
80
  "node": ">=20"
@@ -1,7 +1,7 @@
1
1
  import { SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'
2
2
  import { Oas } from '@kubb/plugin-oas/components'
3
3
  import { useOas, useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'
4
- import { File, Parser, useApp } from '@kubb/react'
4
+ import { File, useApp } from '@kubb/react'
5
5
 
6
6
  import type { OperationSchema as OperationSchemaType } from '@kubb/plugin-oas'
7
7
  import type { ReactNode } from 'react'
@@ -45,20 +45,16 @@ OperationSchema.File = function ({}: FileProps): ReactNode {
45
45
 
46
46
  return (
47
47
  <Oas.Schema key={i} name={name} value={schema} tree={[...tree, optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)}>
48
- {mode === 'split' && <Oas.Schema.Imports extName={plugin.options.extName} />}
49
- <File.Source>
50
- <OperationSchema description={description} keysToOmit={keysToOmit} />
51
- </File.Source>
48
+ {mode === 'split' && <Oas.Schema.Imports />}
49
+ <OperationSchema description={description} keysToOmit={keysToOmit} />
52
50
  </Oas.Schema>
53
51
  )
54
52
  }
55
53
 
56
54
  return (
57
- <Parser language="typescript">
58
- <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
59
- <File.Import name={['z']} path={plugin.options.importPath} />
60
- {items.map(mapItem)}
61
- </File>
62
- </Parser>
55
+ <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
56
+ <File.Import name={['z']} path={plugin.options.importPath} />
57
+ {items.map(mapItem)}
58
+ </File>
63
59
  )
64
60
  }
@@ -1,9 +1,9 @@
1
1
  import { useOperationManager, useOperations } from '@kubb/plugin-oas/hooks'
2
- import { Const, File, Parser, useApp } from '@kubb/react'
2
+ import { Const, File, useApp } from '@kubb/react'
3
3
 
4
4
  import transformers from '@kubb/core/transformers'
5
5
  import type { HttpMethod, Operation } from '@kubb/oas'
6
- import type { KubbNode } from '@kubb/react'
6
+ import type { KubbNode } from '@kubb/react/types'
7
7
  import type { ComponentProps, ComponentType } from 'react'
8
8
  import type { FileMeta, PluginZod } from '../types.ts'
9
9
 
@@ -46,12 +46,16 @@ function Template({ operationsName, pathsName, operations }: TemplateProps): Kub
46
46
 
47
47
  return (
48
48
  <>
49
- <Const export name={operationsName} asConst>
50
- {`{${transformers.stringifyObject(operationsJSON)}}`}
51
- </Const>
52
- <Const export name={pathsName} asConst>
53
- {`{${transformers.stringifyObject(pathsJSON)}}`}
54
- </Const>
49
+ <File.Source name={operationsName} isExportable>
50
+ <Const export name={operationsName} asConst>
51
+ {`{${transformers.stringifyObject(operationsJSON)}}`}
52
+ </Const>
53
+ </File.Source>
54
+ <File.Source name={pathsName} isExportable>
55
+ <Const export name={pathsName} asConst>
56
+ {`{${transformers.stringifyObject(pathsJSON)}}`}
57
+ </Const>
58
+ </File.Source>
55
59
  </>
56
60
  )
57
61
  }
@@ -79,17 +83,15 @@ function RootTemplate({ children }: RootTemplateProps) {
79
83
  .map(([_key, { data, operation }], index) => {
80
84
  const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)
81
85
 
82
- return <File.Import key={index} extName={extName} name={names} root={file.path} path={getFile(operation).path} />
86
+ return <File.Import key={index} name={names} root={file.path} path={getFile(operation).path} />
83
87
  })
84
88
  .filter(Boolean)
85
89
 
86
90
  return (
87
- <Parser language="typescript">
88
- <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta} exportable={false}>
89
- {mode === 'split' && imports}
90
- <File.Source>{children}</File.Source>
91
- </File>
92
- </Parser>
91
+ <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
92
+ {mode === 'split' && imports}
93
+ {children}
94
+ </File>
93
95
  )
94
96
  }
95
97
 
@@ -46,15 +46,17 @@ export function Schema(props: Props): ReactNode {
46
46
 
47
47
  if (!tree.length) {
48
48
  return (
49
- <Const
50
- name={resolvedName}
51
- export
52
- JSDoc={{
53
- comments: [description ? `@description ${transformers.jsStringEscape(description)}` : undefined].filter(Boolean),
54
- }}
55
- >
56
- undefined
57
- </Const>
49
+ <File.Source name={resolvedName} isExportable>
50
+ <Const
51
+ name={resolvedName}
52
+ export
53
+ JSDoc={{
54
+ comments: [description ? `@description ${transformers.jsStringEscape(description)}` : undefined].filter(Boolean),
55
+ }}
56
+ >
57
+ undefined
58
+ </Const>
59
+ </File.Source>
58
60
  )
59
61
  }
60
62
 
@@ -77,25 +79,29 @@ export function Schema(props: Props): ReactNode {
77
79
 
78
80
  return (
79
81
  <>
80
- <Const
81
- export
82
- name={resolvedName}
83
- JSDoc={{
84
- comments: [description ? `@description ${transformers.jsStringEscape(description)}` : undefined].filter(Boolean),
85
- }}
86
- >
87
- {[
88
- output,
89
- keysToOmit?.length ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(',')} }))` : undefined,
90
- withTypeAnnotation && typeName ? ` as z.ZodType<${typeName}>` : '',
91
- ]
92
- .filter(Boolean)
93
- .join('') || ''}
94
- </Const>
82
+ <File.Source name={resolvedName} isExportable>
83
+ <Const
84
+ export
85
+ name={resolvedName}
86
+ JSDoc={{
87
+ comments: [description ? `@description ${transformers.jsStringEscape(description)}` : undefined].filter(Boolean),
88
+ }}
89
+ >
90
+ {[
91
+ output,
92
+ keysToOmit?.length ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(',')} }))` : undefined,
93
+ withTypeAnnotation && typeName ? ` as z.ZodType<${typeName}>` : '',
94
+ ]
95
+ .filter(Boolean)
96
+ .join('') || ''}
97
+ </Const>
98
+ </File.Source>
95
99
  {typedSchema && (
96
- <Type export name={resolvedTypeName}>
97
- {`z.infer<typeof ${resolvedName}>`}
98
- </Type>
100
+ <File.Source name={resolvedTypeName} isExportable isTypeOnly>
101
+ <Type export name={resolvedTypeName}>
102
+ {`z.infer<typeof ${resolvedName}>`}
103
+ </Type>
104
+ </File.Source>
99
105
  )}
100
106
  </>
101
107
  )
@@ -117,9 +123,7 @@ Schema.File = function ({}: FileProps): ReactNode {
117
123
  return (
118
124
  <Oas.Schema.File output={pluginManager.config.output.path}>
119
125
  <Schema.Imports />
120
- <File.Source>
121
- <Schema withTypeAnnotation={withTypeAnnotation} description={schema?.description} />
122
- </File.Source>
126
+ <Schema withTypeAnnotation={withTypeAnnotation} description={schema?.description} />
123
127
  </Oas.Schema.File>
124
128
  )
125
129
  }
@@ -1,50 +1,53 @@
1
- export const operations = {
2
- 'get_pets-pet-id': {
3
- request: undefined,
1
+ export const operations = {"get_pets-pet-id": {
2
+ request: undefined,
4
3
  parameters: {
5
- path: undefined,
6
- query: undefined,
7
- header: undefined,
8
- },
4
+ path: undefined,
5
+ query: undefined,
6
+ header: undefined
7
+ },
9
8
  responses: {
10
- 200: GetPetsPetIdQueryResponse,
11
- default: GetPetsPetIdQueryResponse,
12
- },
13
- errors: {},
14
- },
15
- listPets: {
16
- request: undefined,
9
+ 200: GetPetsPetIdQueryResponse,
10
+ default: GetPetsPetIdQueryResponse
11
+ },
12
+ errors: {
13
+
14
+ }
15
+ },
16
+ "listPets": {
17
+ request: undefined,
17
18
  parameters: {
18
- path: undefined,
19
- query: ListPetsQueryParams,
20
- header: undefined,
21
- },
19
+ path: undefined,
20
+ query: ListPetsQueryParams,
21
+ header: undefined
22
+ },
22
23
  responses: {
23
- 200: ListPetsQueryResponse,
24
- default: ListPetsQueryResponse,
25
- },
26
- errors: {},
27
- },
28
- createPets: {
29
- request: CreatePetsMutationRequest,
24
+ 200: ListPetsQueryResponse,
25
+ default: ListPetsQueryResponse
26
+ },
27
+ errors: {
28
+
29
+ }
30
+ },
31
+ "createPets": {
32
+ request: CreatePetsMutationRequest,
30
33
  parameters: {
31
- path: undefined,
32
- query: undefined,
33
- header: undefined,
34
- },
34
+ path: undefined,
35
+ query: undefined,
36
+ header: undefined
37
+ },
35
38
  responses: {
36
- 201: CreatePetsMutationResponse,
37
- default: CreatePetsMutationResponse,
38
- },
39
- errors: {},
40
- },
41
- } as const
42
- export const paths = {
43
- '/pets/{pet_id}': {
44
- get: operations['get_pets-pet-id'],
45
- },
46
- '/pets': {
47
- get: operations['listPets'],
48
- post: operations['createPets'],
49
- },
50
- } as const
39
+ 201: CreatePetsMutationResponse,
40
+ default: CreatePetsMutationResponse
41
+ },
42
+ errors: {
43
+
44
+ }
45
+ }} as const
46
+
47
+ export const paths = {"/pets/{pet_id}": {
48
+ get: operations["get_pets-pet-id"]
49
+ },
50
+ "/pets": {
51
+ get: operations["listPets"],
52
+ post: operations["createPets"]
53
+ }} as const
package/src/plugin.ts CHANGED
@@ -4,7 +4,7 @@ import { FileManager, PluginManager, createPlugin } from '@kubb/core'
4
4
  import { camelCase, pascalCase } from '@kubb/core/transformers'
5
5
  import { renderTemplate } from '@kubb/core/utils'
6
6
  import { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'
7
- import { getGroupedByTagFiles } from '@kubb/plugin-oas/utils'
7
+
8
8
  import { pluginTsName } from '@kubb/plugin-ts'
9
9
 
10
10
  import type { Plugin } from '@kubb/core'
@@ -126,37 +126,17 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
126
126
  const operationFiles = await operationGenerator.build(zodParser)
127
127
  await this.addFile(...operationFiles)
128
128
 
129
- if (this.config.output.write && group?.type === 'tag') {
130
- const rootFiles = await getGroupedByTagFiles({
131
- logger: this.logger,
132
- files: this.fileManager.files,
133
- plugin: this.plugin,
134
- template,
135
- exportAs: group.exportAs || '{{tag}}Schemas',
129
+ if (this.config.output.write) {
130
+ const indexFiles = await this.fileManager.getIndexFiles({
136
131
  root,
137
132
  output,
133
+ files: this.fileManager.files,
134
+ plugin: this.plugin,
135
+ logger: this.logger,
138
136
  })
139
137
 
140
- await this.addFile(...rootFiles)
138
+ await this.addFile(...indexFiles)
141
139
  }
142
140
  },
143
- async buildEnd() {
144
- if (this.config.output.write === false) {
145
- return
146
- }
147
-
148
- const root = path.resolve(this.config.root, this.config.output.path)
149
- const files = await this.fileManager.getIndexFiles({
150
- root,
151
- output,
152
- plugin: this.plugin,
153
- logger: this.logger,
154
- })
155
-
156
- await this.fileManager.processFiles({
157
- logger: this.logger,
158
- files,
159
- })
160
- },
161
141
  }
162
142
  })