@kubb/plugin-zod 5.0.0-alpha.9 → 5.0.0-beta.4

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.
Files changed (46) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +1 -3
  3. package/dist/index.cjs +1061 -105
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +369 -4
  6. package/dist/index.js +1053 -104
  7. package/dist/index.js.map +1 -1
  8. package/extension.yaml +502 -0
  9. package/package.json +44 -70
  10. package/src/components/Operations.tsx +25 -18
  11. package/src/components/Zod.tsx +21 -121
  12. package/src/constants.ts +5 -0
  13. package/src/generators/zodGenerator.tsx +174 -160
  14. package/src/index.ts +11 -2
  15. package/src/plugin.ts +67 -156
  16. package/src/printers/printerZod.ts +339 -0
  17. package/src/printers/printerZodMini.ts +295 -0
  18. package/src/resolvers/resolverZod.ts +57 -0
  19. package/src/types.ts +130 -115
  20. package/src/utils.ts +222 -0
  21. package/dist/components-B7zUFnAm.cjs +0 -890
  22. package/dist/components-B7zUFnAm.cjs.map +0 -1
  23. package/dist/components-eECfXVou.js +0 -842
  24. package/dist/components-eECfXVou.js.map +0 -1
  25. package/dist/components.cjs +0 -4
  26. package/dist/components.d.ts +0 -56
  27. package/dist/components.js +0 -2
  28. package/dist/generators-BjPDdJUz.cjs +0 -301
  29. package/dist/generators-BjPDdJUz.cjs.map +0 -1
  30. package/dist/generators-lTWPS6oN.js +0 -290
  31. package/dist/generators-lTWPS6oN.js.map +0 -1
  32. package/dist/generators.cjs +0 -4
  33. package/dist/generators.d.ts +0 -508
  34. package/dist/generators.js +0 -2
  35. package/dist/templates/ToZod.source.cjs +0 -7
  36. package/dist/templates/ToZod.source.cjs.map +0 -1
  37. package/dist/templates/ToZod.source.d.ts +0 -7
  38. package/dist/templates/ToZod.source.js +0 -6
  39. package/dist/templates/ToZod.source.js.map +0 -1
  40. package/dist/types-CoCoOc2u.d.ts +0 -172
  41. package/src/components/index.ts +0 -2
  42. package/src/generators/index.ts +0 -2
  43. package/src/generators/operationsGenerator.tsx +0 -50
  44. package/src/parser.ts +0 -909
  45. package/src/templates/ToZod.source.ts +0 -4
  46. package/templates/ToZod.ts +0 -61
@@ -1,508 +0,0 @@
1
- import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { n as PluginZod } from "./types-CoCoOc2u.js";
3
- import { Config, FileMetaBase, Generator, Group, KubbEvents, Output, Plugin, PluginDriver, PluginFactoryOptions, ResolveNameParams } from "@kubb/core";
4
- import { HttpMethod, Oas, Operation, SchemaObject, contentType } from "@kubb/oas";
5
- import { FabricReactNode } from "@kubb/react-fabric/types";
6
- import { Fabric, KubbFile } from "@kubb/fabric-core/types";
7
-
8
- //#region ../../internals/utils/src/asyncEventEmitter.d.ts
9
- /** A function that can be registered as an event listener, synchronous or async. */
10
- type AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>;
11
- /**
12
- * A typed EventEmitter that awaits all async listeners before resolving.
13
- * Wraps Node's `EventEmitter` with full TypeScript event-map inference.
14
- */
15
- declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {
16
- #private;
17
- /**
18
- * `maxListener` controls the maximum number of listeners per event before Node emits a memory-leak warning.
19
- * @default 10
20
- */
21
- constructor(maxListener?: number);
22
- /**
23
- * Emits an event and awaits all registered listeners in parallel.
24
- * Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
25
- */
26
- emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
27
- /** Registers a persistent listener for the given event. */
28
- on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
29
- /** Registers a one-shot listener that removes itself after the first invocation. */
30
- onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
31
- /** Removes a previously registered listener. */
32
- off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
33
- /** Removes all listeners from every event channel. */
34
- removeAll(): void;
35
- }
36
- //#endregion
37
- //#region ../plugin-oas/src/types.d.ts
38
- type GetOasOptions = {
39
- validate?: boolean;
40
- };
41
- type Context$2 = {
42
- getOas(options?: GetOasOptions): Promise<Oas>;
43
- getBaseURL(): Promise<string | undefined>;
44
- };
45
- declare global {
46
- namespace Kubb {
47
- interface PluginContext extends Context$2 {}
48
- }
49
- }
50
- /**
51
- * `propertyName` is the ref name + resolved with the nameResolver
52
- * @example import { Pet } from './Pet'
53
- *
54
- * `originalName` is the original name used(in PascalCase), only used to remove duplicates
55
- *
56
- * `pluginName` can be used to override the current plugin being used, handy when you want to import a type/schema out of another plugin
57
- * @example import a type(plugin-ts) for a mock file(swagger-faker)
58
- */
59
- type Ref = {
60
- propertyName: string;
61
- originalName: string;
62
- path: KubbFile.Path;
63
- pluginName?: string;
64
- };
65
- type Refs = Record<string, Ref>;
66
- type OperationSchema = {
67
- /**
68
- * Converted name, contains already `PathParams`, `QueryParams`, ...
69
- */
70
- name: string;
71
- schema: SchemaObject;
72
- operation?: Operation;
73
- /**
74
- * OperationName in PascalCase, only being used in OperationGenerator
75
- */
76
- operationName: string;
77
- description?: string;
78
- statusCode?: number;
79
- keys?: string[];
80
- keysToOmit?: string[];
81
- withData?: boolean;
82
- };
83
- type OperationSchemas = {
84
- pathParams?: OperationSchema & {
85
- keysToOmit?: never;
86
- };
87
- queryParams?: OperationSchema & {
88
- keysToOmit?: never;
89
- };
90
- headerParams?: OperationSchema & {
91
- keysToOmit?: never;
92
- };
93
- request?: OperationSchema;
94
- response: OperationSchema;
95
- responses: Array<OperationSchema>;
96
- statusCodes?: Array<OperationSchema>;
97
- errors?: Array<OperationSchema>;
98
- };
99
- type ByTag = {
100
- type: 'tag';
101
- pattern: string | RegExp;
102
- };
103
- type ByOperationId = {
104
- type: 'operationId';
105
- pattern: string | RegExp;
106
- };
107
- type ByPath = {
108
- type: 'path';
109
- pattern: string | RegExp;
110
- };
111
- type ByMethod = {
112
- type: 'method';
113
- pattern: HttpMethod | RegExp;
114
- };
115
- type BySchemaName = {
116
- type: 'schemaName';
117
- pattern: string | RegExp;
118
- };
119
- type ByContentType = {
120
- type: 'contentType';
121
- pattern: string | RegExp;
122
- };
123
- type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
124
- type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
125
- type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
126
- options: Partial<TOptions>;
127
- };
128
- //#endregion
129
- //#region ../plugin-oas/src/OperationGenerator.d.ts
130
- type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
131
- fabric: Fabric;
132
- oas: Oas;
133
- exclude: Array<Exclude> | undefined;
134
- include: Array<Include> | undefined;
135
- override: Array<Override<TOptions>> | undefined;
136
- contentType: contentType | undefined;
137
- driver: PluginDriver;
138
- events?: AsyncEventEmitter<KubbEvents>;
139
- /**
140
- * Current plugin
141
- */
142
- plugin: Plugin<TPluginOptions>;
143
- mode: KubbFile.Mode;
144
- UNSTABLE_NAMING?: true;
145
- };
146
- declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> {
147
- #private;
148
- constructor(options: TPluginOptions['resolvedOptions'], context: Context$1<TPluginOptions['resolvedOptions'], TPluginOptions>);
149
- get options(): TPluginOptions['resolvedOptions'];
150
- set options(options: TPluginOptions['resolvedOptions']);
151
- get context(): Context$1<TPluginOptions['resolvedOptions'], TPluginOptions>;
152
- getOptions(operation: Operation, method: HttpMethod): Partial<TPluginOptions['resolvedOptions']>;
153
- getSchemas(operation: Operation, {
154
- resolveName
155
- }?: {
156
- resolveName?: (name: string) => string;
157
- }): OperationSchemas;
158
- getOperations(): Promise<Array<{
159
- path: string;
160
- method: HttpMethod;
161
- operation: Operation;
162
- }>>;
163
- build(...generators: Array<Generator$1<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
164
- }
165
- //#endregion
166
- //#region ../plugin-oas/src/SchemaMapper.d.ts
167
- type SchemaKeywordMapper = {
168
- object: {
169
- keyword: 'object';
170
- args: {
171
- properties: {
172
- [x: string]: Schema[];
173
- };
174
- additionalProperties: Schema[];
175
- patternProperties?: Record<string, Schema[]>;
176
- strict?: boolean;
177
- };
178
- };
179
- url: {
180
- keyword: 'url';
181
- };
182
- readOnly: {
183
- keyword: 'readOnly';
184
- };
185
- writeOnly: {
186
- keyword: 'writeOnly';
187
- };
188
- uuid: {
189
- keyword: 'uuid';
190
- };
191
- email: {
192
- keyword: 'email';
193
- };
194
- firstName: {
195
- keyword: 'firstName';
196
- };
197
- lastName: {
198
- keyword: 'lastName';
199
- };
200
- phone: {
201
- keyword: 'phone';
202
- };
203
- password: {
204
- keyword: 'password';
205
- };
206
- date: {
207
- keyword: 'date';
208
- args: {
209
- type?: 'date' | 'string';
210
- };
211
- };
212
- time: {
213
- keyword: 'time';
214
- args: {
215
- type?: 'date' | 'string';
216
- };
217
- };
218
- datetime: {
219
- keyword: 'datetime';
220
- args: {
221
- offset?: boolean;
222
- local?: boolean;
223
- };
224
- };
225
- tuple: {
226
- keyword: 'tuple';
227
- args: {
228
- items: Schema[];
229
- min?: number;
230
- max?: number;
231
- rest?: Schema;
232
- };
233
- };
234
- array: {
235
- keyword: 'array';
236
- args: {
237
- items: Schema[];
238
- min?: number;
239
- max?: number;
240
- unique?: boolean;
241
- };
242
- };
243
- enum: {
244
- keyword: 'enum';
245
- args: {
246
- name: string;
247
- typeName: string;
248
- asConst: boolean;
249
- items: Array<{
250
- name: string | number;
251
- format: 'string' | 'number' | 'boolean';
252
- value?: string | number | boolean;
253
- }>;
254
- };
255
- };
256
- and: {
257
- keyword: 'and';
258
- args: Schema[];
259
- };
260
- const: {
261
- keyword: 'const';
262
- args: {
263
- name: string | number;
264
- format: 'string' | 'number' | 'boolean';
265
- value?: string | number | boolean;
266
- };
267
- };
268
- union: {
269
- keyword: 'union';
270
- args: Schema[];
271
- };
272
- ref: {
273
- keyword: 'ref';
274
- args: {
275
- name: string;
276
- $ref: string;
277
- /**
278
- * Full qualified path.
279
- */
280
- path: KubbFile.Path;
281
- /**
282
- * When true `File.Import` is used.
283
- * When false a reference is used inside the current file.
284
- */
285
- isImportable: boolean;
286
- };
287
- };
288
- matches: {
289
- keyword: 'matches';
290
- args?: string;
291
- };
292
- boolean: {
293
- keyword: 'boolean';
294
- };
295
- default: {
296
- keyword: 'default';
297
- args: string | number | boolean;
298
- };
299
- string: {
300
- keyword: 'string';
301
- };
302
- integer: {
303
- keyword: 'integer';
304
- };
305
- bigint: {
306
- keyword: 'bigint';
307
- };
308
- number: {
309
- keyword: 'number';
310
- };
311
- max: {
312
- keyword: 'max';
313
- args: number;
314
- };
315
- min: {
316
- keyword: 'min';
317
- args: number;
318
- };
319
- exclusiveMaximum: {
320
- keyword: 'exclusiveMaximum';
321
- args: number;
322
- };
323
- exclusiveMinimum: {
324
- keyword: 'exclusiveMinimum';
325
- args: number;
326
- };
327
- describe: {
328
- keyword: 'describe';
329
- args: string;
330
- };
331
- example: {
332
- keyword: 'example';
333
- args: string;
334
- };
335
- deprecated: {
336
- keyword: 'deprecated';
337
- };
338
- optional: {
339
- keyword: 'optional';
340
- };
341
- undefined: {
342
- keyword: 'undefined';
343
- };
344
- nullish: {
345
- keyword: 'nullish';
346
- };
347
- nullable: {
348
- keyword: 'nullable';
349
- };
350
- null: {
351
- keyword: 'null';
352
- };
353
- any: {
354
- keyword: 'any';
355
- };
356
- unknown: {
357
- keyword: 'unknown';
358
- };
359
- void: {
360
- keyword: 'void';
361
- };
362
- blob: {
363
- keyword: 'blob';
364
- };
365
- schema: {
366
- keyword: 'schema';
367
- args: {
368
- type: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object';
369
- format?: string;
370
- };
371
- };
372
- name: {
373
- keyword: 'name';
374
- args: string;
375
- };
376
- catchall: {
377
- keyword: 'catchall';
378
- };
379
- interface: {
380
- keyword: 'interface';
381
- };
382
- };
383
- type Schema = {
384
- keyword: string;
385
- } | SchemaKeywordMapper[keyof SchemaKeywordMapper];
386
- //#endregion
387
- //#region ../plugin-oas/src/SchemaGenerator.d.ts
388
- type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
389
- fabric: Fabric;
390
- oas: Oas;
391
- driver: PluginDriver;
392
- events?: AsyncEventEmitter<KubbEvents>;
393
- /**
394
- * Current plugin
395
- */
396
- plugin: Plugin<TPluginOptions>;
397
- mode: KubbFile.Mode;
398
- include?: Array<'schemas' | 'responses' | 'requestBodies'>;
399
- override: Array<Override<TOptions>> | undefined;
400
- contentType?: contentType;
401
- output?: string;
402
- };
403
- type SchemaGeneratorOptions = {
404
- dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
405
- integerType?: 'number' | 'bigint';
406
- unknownType: 'any' | 'unknown' | 'void';
407
- emptySchemaType: 'any' | 'unknown' | 'void';
408
- enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal' | 'inlineLiteral';
409
- enumSuffix?: string;
410
- /**
411
- * @deprecated Will be removed in v5. Use `collisionDetection: true` instead to prevent enum name collisions.
412
- * When `collisionDetection` is enabled, the rootName-based approach eliminates the need for numeric suffixes.
413
- * @internal
414
- */
415
- usedEnumNames?: Record<string, number>;
416
- mapper?: Record<string, string>;
417
- typed?: boolean;
418
- transformers: {
419
- /**
420
- * Customize the names based on the type that is provided by the plugin.
421
- */
422
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
423
- /**
424
- * Receive schema and name(propertyName) and return Schema array.
425
- * Return `undefined` to fall through to default schema generation.
426
- * @beta
427
- */
428
- schema?: (schemaProps: SchemaProps$1, defaultSchemas: Schema[]) => Array<Schema> | undefined;
429
- };
430
- };
431
- type SchemaProps$1 = {
432
- schema: SchemaObject | null;
433
- name: string | null;
434
- parentName: string | null;
435
- rootName?: string | null;
436
- };
437
- declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> {
438
- #private;
439
- constructor(options: TOptions, context: Context<TOptions, TPluginOptions>);
440
- get options(): TOptions;
441
- set options(options: TOptions);
442
- get context(): Context<TOptions, TPluginOptions>;
443
- refs: Refs;
444
- /**
445
- * Creates a type node from a given schema.
446
- * Delegates to getBaseTypeFromSchema internally and
447
- * optionally adds a union with null.
448
- */
449
- parse(props: SchemaProps$1): Schema[];
450
- static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
451
- static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
452
- static combineObjects(tree: Schema[] | undefined): Schema[];
453
- build(...generators: Array<Generator$1<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
454
- }
455
- //#endregion
456
- //#region ../plugin-oas/src/generators/createGenerator.d.ts
457
- type CoreGenerator<TOptions extends PluginFactoryOptions> = {
458
- name: string;
459
- type: 'core';
460
- version: '1';
461
- operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
462
- operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
463
- schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
464
- };
465
- //#endregion
466
- //#region ../plugin-oas/src/generators/types.d.ts
467
- type OperationsProps<TOptions extends PluginFactoryOptions> = {
468
- config: Config;
469
- generator: Omit<OperationGenerator<TOptions>, 'build'>;
470
- plugin: Plugin<TOptions>;
471
- operations: Array<Operation>;
472
- };
473
- type OperationProps<TOptions extends PluginFactoryOptions> = {
474
- config: Config;
475
- generator: Omit<OperationGenerator<TOptions>, 'build'>;
476
- plugin: Plugin<TOptions>;
477
- operation: Operation;
478
- };
479
- type SchemaProps<TOptions extends PluginFactoryOptions> = {
480
- config: Config;
481
- generator: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
482
- plugin: Plugin<TOptions>;
483
- schema: {
484
- name: string;
485
- tree: Array<Schema>;
486
- value: SchemaObject;
487
- };
488
- };
489
- type Generator$1<TOptions extends PluginFactoryOptions> = CoreGenerator<TOptions> | ReactGenerator<TOptions> | Generator<TOptions>;
490
- //#endregion
491
- //#region ../plugin-oas/src/generators/createReactGenerator.d.ts
492
- type ReactGenerator<TOptions extends PluginFactoryOptions> = {
493
- name: string;
494
- type: 'react';
495
- version: '1';
496
- Operations: (props: OperationsProps<TOptions>) => FabricReactNode;
497
- Operation: (props: OperationProps<TOptions>) => FabricReactNode;
498
- Schema: (props: SchemaProps<TOptions>) => FabricReactNode;
499
- };
500
- //#endregion
501
- //#region src/generators/operationsGenerator.d.ts
502
- declare const operationsGenerator: ReactGenerator<PluginZod>;
503
- //#endregion
504
- //#region src/generators/zodGenerator.d.ts
505
- declare const zodGenerator: ReactGenerator<PluginZod>;
506
- //#endregion
507
- export { operationsGenerator, zodGenerator };
508
- //# sourceMappingURL=generators.d.ts.map
@@ -1,2 +0,0 @@
1
- import { n as operationsGenerator, t as zodGenerator } from "./generators-lTWPS6oN.js";
2
- export { operationsGenerator, zodGenerator };
@@ -1,7 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/templates/ToZod.source.ts
3
- const source = "/**\n * See https://github.com/colinhacks/tozod/blob/master/src/index.ts\n * Adapted based on https://github.com/colinhacks/zod/issues/372\n */\n\nimport type * as z from 'zod'\n\ntype IsAny<T> = [any extends T ? 'true' : 'false'] extends ['true'] ? true : false\ntype NonOptional<T> = T extends undefined ? never : T\ntype NonNullable<T> = T extends null ? never : T\ntype Equals<X, Y> = [X] extends [Y] ? ([Y] extends [X] ? true : false) : false\n\ntype ZodKey<T> =\n IsAny<T> extends true\n ? 'any'\n : Equals<T, boolean> extends true //[T] extends [booleanUtil.Type]\n ? 'boolean'\n : [undefined] extends [T]\n ? 'optional'\n : [null] extends [T]\n ? 'nullable'\n : T extends any[]\n ? 'array'\n : Equals<T, string> extends true\n ? 'string'\n : Equals<T, bigint> extends true //[T] extends [bigintUtil.Type]\n ? 'bigint'\n : Equals<T, number> extends true //[T] extends [numberUtil.Type]\n ? 'number'\n : Equals<T, Date> extends true //[T] extends [dateUtil.Type]\n ? 'date'\n : T extends { [k: string]: any } //[T] extends [structUtil.Type]\n ? 'object'\n : 'rest'\n\nexport type ToZod<T> = {\n any: z.ZodAny\n optional: z.ZodOptional<ToZod<NonOptional<T>>>\n nullable: z.ZodNullable<ToZod<NonNullable<T>>>\n array: T extends Array<infer U> ? z.ZodArray<ToZod<U>> : never\n string: z.ZodString\n bigint: z.ZodBigInt\n number: z.ZodNumber\n boolean: z.ZodBoolean\n date: z.ZodDate\n object: z.ZodObject<\n // @ts-expect-error cannot convert without Extract but Extract removes the type\n {\n [K in keyof T]: T[K]\n },\n 'passthrough',\n unknown,\n T\n >\n rest: z.ZodType<T>\n}[ZodKey<T>]\n\nexport type ZodShape<T> = {\n // Require all the keys from T\n [key in keyof T]-?: ToZod<T[key]>\n}\n";
4
- //#endregion
5
- exports.source = source;
6
-
7
- //# sourceMappingURL=ToZod.source.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ToZod.source.cjs","names":[],"sources":["../../src/templates/ToZod.source.ts"],"sourcesContent":["// @ts-expect-error - import attributes are handled at build time by importAttributeTextPlugin\nimport content from '../../templates/ToZod.ts' with { type: 'text' }\n\nexport const source = content as string\n"],"mappings":";;AAAA,MAAa,SAAS"}
@@ -1,7 +0,0 @@
1
- import { t as __name } from "../chunk--u3MIqq1.js";
2
-
3
- //#region src/templates/ToZod.source.d.ts
4
- declare const source: string;
5
- //#endregion
6
- export { source };
7
- //# sourceMappingURL=ToZod.source.d.ts.map
@@ -1,6 +0,0 @@
1
- //#region src/templates/ToZod.source.ts
2
- const source = "/**\n * See https://github.com/colinhacks/tozod/blob/master/src/index.ts\n * Adapted based on https://github.com/colinhacks/zod/issues/372\n */\n\nimport type * as z from 'zod'\n\ntype IsAny<T> = [any extends T ? 'true' : 'false'] extends ['true'] ? true : false\ntype NonOptional<T> = T extends undefined ? never : T\ntype NonNullable<T> = T extends null ? never : T\ntype Equals<X, Y> = [X] extends [Y] ? ([Y] extends [X] ? true : false) : false\n\ntype ZodKey<T> =\n IsAny<T> extends true\n ? 'any'\n : Equals<T, boolean> extends true //[T] extends [booleanUtil.Type]\n ? 'boolean'\n : [undefined] extends [T]\n ? 'optional'\n : [null] extends [T]\n ? 'nullable'\n : T extends any[]\n ? 'array'\n : Equals<T, string> extends true\n ? 'string'\n : Equals<T, bigint> extends true //[T] extends [bigintUtil.Type]\n ? 'bigint'\n : Equals<T, number> extends true //[T] extends [numberUtil.Type]\n ? 'number'\n : Equals<T, Date> extends true //[T] extends [dateUtil.Type]\n ? 'date'\n : T extends { [k: string]: any } //[T] extends [structUtil.Type]\n ? 'object'\n : 'rest'\n\nexport type ToZod<T> = {\n any: z.ZodAny\n optional: z.ZodOptional<ToZod<NonOptional<T>>>\n nullable: z.ZodNullable<ToZod<NonNullable<T>>>\n array: T extends Array<infer U> ? z.ZodArray<ToZod<U>> : never\n string: z.ZodString\n bigint: z.ZodBigInt\n number: z.ZodNumber\n boolean: z.ZodBoolean\n date: z.ZodDate\n object: z.ZodObject<\n // @ts-expect-error cannot convert without Extract but Extract removes the type\n {\n [K in keyof T]: T[K]\n },\n 'passthrough',\n unknown,\n T\n >\n rest: z.ZodType<T>\n}[ZodKey<T>]\n\nexport type ZodShape<T> = {\n // Require all the keys from T\n [key in keyof T]-?: ToZod<T[key]>\n}\n";
3
- //#endregion
4
- export { source };
5
-
6
- //# sourceMappingURL=ToZod.source.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ToZod.source.js","names":[],"sources":["../../src/templates/ToZod.source.ts"],"sourcesContent":["// @ts-expect-error - import attributes are handled at build time by importAttributeTextPlugin\nimport content from '../../templates/ToZod.ts' with { type: 'text' }\n\nexport const source = content as string\n"],"mappings":";AAAA,MAAa,SAAS"}