@idb-orm/zod-adapter 0.0.1 → 0.0.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.d.ts CHANGED
@@ -1,22 +1,8 @@
1
- import { AbstractProperty, PropertyInputOptions, util } from "@idb-orm/core/dev";
2
- import { z } from "zod";
3
- export declare class Property<Value, HasDefault extends boolean> extends AbstractProperty<Value, HasDefault> {
4
- private schema;
5
- constructor(schema: z.ZodType<Value>, options?: PropertyInputOptions);
6
- array(): Property<Value[], false>;
7
- default(defaultValue: util.NoUndefined<Value>): Property<util.NoUndefined<Value>, true>;
8
- optional(): Property<Value | undefined, false>;
9
- static readonly zodValidators: {
10
- string: z.ZodString;
11
- number: z.ZodNumber;
12
- boolean: z.ZodBoolean;
13
- };
14
- static literal<const T extends util.Literable>(value: T, options?: PropertyInputOptions): Property<T, false>;
15
- static string(options?: PropertyInputOptions): Property<string, false>;
16
- static number(options?: PropertyInputOptions): Property<number, false>;
17
- static boolean(options?: PropertyInputOptions): Property<boolean, false>;
18
- static union<const T extends readonly z.core.SomeType[]>(items: T, options?: PropertyInputOptions): Property<z.output<z.ZodUnion<T>>, false>;
19
- static custom<T>(schema: z.ZodType<T>, options?: PropertyInputOptions): Property<T, false>;
20
- static array<T>(schema: z.ZodType<T>, options?: PropertyInputOptions): Property<T[], false>;
21
- private regenerateValidator;
22
- }
1
+ import { core, Model } from '@idb-orm/core';
2
+ import { default as z } from 'zod';
3
+ type ZodHasDefault<S extends z.ZodType> = S extends z.ZodDefault<any> ? true : false;
4
+ export type ZodTranslation<R extends Record<string, z.ZodType | core.ValidValue>> = {
5
+ [K in keyof R]: R[K] extends z.ZodType ? core.Property<z.output<R[K]>, ZodHasDefault<R[K]>> : R[K] extends core.ValidValue ? R[K] : never;
6
+ };
7
+ export declare function zodModel<Name extends string, ZodFields extends Record<string, core.ValidValue | z.ZodType>>(name: Name, fields: ZodFields): Model<Name, core.Simplify<ZodTranslation<ZodFields>>, core.FindPrimaryKey<core.Simplify<ZodTranslation<ZodFields>>>>;
8
+ export {};