@kubb/plugin-zod 5.0.0-alpha.3 → 5.0.0-alpha.30
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.cjs +1619 -100
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +418 -4
- package/dist/index.js +1614 -100
- package/dist/index.js.map +1 -1
- package/package.json +6 -34
- package/src/components/Operations.tsx +22 -15
- package/src/components/Zod.tsx +20 -119
- package/src/constants.ts +5 -0
- package/src/generators/zodGenerator.tsx +129 -159
- package/src/generators/zodGeneratorLegacy.tsx +365 -0
- package/src/index.ts +12 -1
- package/src/plugin.ts +102 -148
- package/src/presets.ts +30 -0
- package/src/printers/printerZod.ts +298 -0
- package/src/printers/printerZodMini.ts +273 -0
- package/src/resolvers/resolverZod.ts +61 -0
- package/src/resolvers/resolverZodLegacy.ts +60 -0
- package/src/types.ts +172 -93
- package/src/utils.ts +248 -0
- package/dist/components-B7zUFnAm.cjs +0 -890
- package/dist/components-B7zUFnAm.cjs.map +0 -1
- package/dist/components-eECfXVou.js +0 -842
- package/dist/components-eECfXVou.js.map +0 -1
- package/dist/components.cjs +0 -4
- package/dist/components.d.ts +0 -56
- package/dist/components.js +0 -2
- package/dist/generators-CRKtFRi1.js +0 -290
- package/dist/generators-CRKtFRi1.js.map +0 -1
- package/dist/generators-CzSLRVqQ.cjs +0 -301
- package/dist/generators-CzSLRVqQ.cjs.map +0 -1
- package/dist/generators.cjs +0 -4
- package/dist/generators.d.ts +0 -503
- package/dist/generators.js +0 -2
- package/dist/templates/ToZod.source.cjs +0 -7
- package/dist/templates/ToZod.source.cjs.map +0 -1
- package/dist/templates/ToZod.source.d.ts +0 -7
- package/dist/templates/ToZod.source.js +0 -6
- package/dist/templates/ToZod.source.js.map +0 -1
- package/dist/types-D0wsPC6Y.d.ts +0 -172
- package/src/components/index.ts +0 -2
- package/src/generators/index.ts +0 -2
- package/src/generators/operationsGenerator.tsx +0 -50
- package/src/parser.ts +0 -909
- package/src/templates/ToZod.source.ts +0 -4
- package/templates/ToZod.ts +0 -61
package/templates/ToZod.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* See https://github.com/colinhacks/tozod/blob/master/src/index.ts
|
|
3
|
-
* Adapted based on https://github.com/colinhacks/zod/issues/372
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type * as z from 'zod'
|
|
7
|
-
|
|
8
|
-
type IsAny<T> = [any extends T ? 'true' : 'false'] extends ['true'] ? true : false
|
|
9
|
-
type NonOptional<T> = T extends undefined ? never : T
|
|
10
|
-
type NonNullable<T> = T extends null ? never : T
|
|
11
|
-
type Equals<X, Y> = [X] extends [Y] ? ([Y] extends [X] ? true : false) : false
|
|
12
|
-
|
|
13
|
-
type ZodKey<T> =
|
|
14
|
-
IsAny<T> extends true
|
|
15
|
-
? 'any'
|
|
16
|
-
: Equals<T, boolean> extends true //[T] extends [booleanUtil.Type]
|
|
17
|
-
? 'boolean'
|
|
18
|
-
: [undefined] extends [T]
|
|
19
|
-
? 'optional'
|
|
20
|
-
: [null] extends [T]
|
|
21
|
-
? 'nullable'
|
|
22
|
-
: T extends any[]
|
|
23
|
-
? 'array'
|
|
24
|
-
: Equals<T, string> extends true
|
|
25
|
-
? 'string'
|
|
26
|
-
: Equals<T, bigint> extends true //[T] extends [bigintUtil.Type]
|
|
27
|
-
? 'bigint'
|
|
28
|
-
: Equals<T, number> extends true //[T] extends [numberUtil.Type]
|
|
29
|
-
? 'number'
|
|
30
|
-
: Equals<T, Date> extends true //[T] extends [dateUtil.Type]
|
|
31
|
-
? 'date'
|
|
32
|
-
: T extends { [k: string]: any } //[T] extends [structUtil.Type]
|
|
33
|
-
? 'object'
|
|
34
|
-
: 'rest'
|
|
35
|
-
|
|
36
|
-
export type ToZod<T> = {
|
|
37
|
-
any: z.ZodAny
|
|
38
|
-
optional: z.ZodOptional<ToZod<NonOptional<T>>>
|
|
39
|
-
nullable: z.ZodNullable<ToZod<NonNullable<T>>>
|
|
40
|
-
array: T extends Array<infer U> ? z.ZodArray<ToZod<U>> : never
|
|
41
|
-
string: z.ZodString
|
|
42
|
-
bigint: z.ZodBigInt
|
|
43
|
-
number: z.ZodNumber
|
|
44
|
-
boolean: z.ZodBoolean
|
|
45
|
-
date: z.ZodDate
|
|
46
|
-
object: z.ZodObject<
|
|
47
|
-
// @ts-expect-error cannot convert without Extract but Extract removes the type
|
|
48
|
-
{
|
|
49
|
-
[K in keyof T]: T[K]
|
|
50
|
-
},
|
|
51
|
-
'passthrough',
|
|
52
|
-
unknown,
|
|
53
|
-
T
|
|
54
|
-
>
|
|
55
|
-
rest: z.ZodType<T>
|
|
56
|
-
}[ZodKey<T>]
|
|
57
|
-
|
|
58
|
-
export type ZodShape<T> = {
|
|
59
|
-
// Require all the keys from T
|
|
60
|
-
[key in keyof T]-?: ToZod<T[key]>
|
|
61
|
-
}
|