orchid-orm-schema-to-zod 0.4.44 → 0.5.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/dist/index.d.ts +122 -88
- package/dist/index.js +357 -378
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +358 -377
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,93 +1,127 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
import { Buffer } from 'node:buffer';
|
|
1
|
+
import { ParseColumn, EncodeColumn, AsTypeArg, ColumnTypeBase, ErrorMessage, NullableColumn, StringTypeData, ColumnSchemaGetterTableClass, ErrorMessages, ColumnSchemaGetterColumns, Code } from 'orchid-core';
|
|
2
|
+
import { EnumColumn, ArrayColumnValue, DateBaseColumn, ColumnType, OperatorsJson, ColumnData, ArrayColumn } from 'pqb';
|
|
3
|
+
import { ZodTypeAny, ZodEnum, ZodNullable, ZodUnknown, ZodBoolean, ZodType, ZodNever, ZodString, ZodNumber, ZodDate, ZodObject, ZodOptional, ZodArray } from 'zod';
|
|
6
4
|
|
|
7
|
-
type
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type FullTextSearchType = 'tsvector' | 'tsquery';
|
|
16
|
-
type UUIDType = 'uuid';
|
|
17
|
-
type ByteaType = 'bytea';
|
|
18
|
-
type SchemaToZod<T extends ColumnTypeBase, D = T['dataType']> = T['data']['isNullable'] extends true ? z.ZodNullable<SchemaToZod<Omit<T, 'data'> & {
|
|
19
|
-
data: Omit<T['data'], 'isNullable'> & {
|
|
20
|
-
isNullable: false;
|
|
21
|
-
};
|
|
22
|
-
}>> : D extends NumberType ? z.ZodNumber : D extends BigIntType | StringType | TimeType | GeometryType | NetworkType | BitStringType | FullTextSearchType | UUIDType ? z.ZodString : D extends ByteaType ? z.ZodType<Buffer> : D extends DateTimeType ? z.ZodDate : D extends 'interval' ? typeof interval : D extends 'boolean' ? z.ZodBoolean : T extends EnumColumn<any, any> ? z.ZodEnum<T['options']> : T extends ArrayColumn<any> ? z.ZodArray<SchemaToZod<T['data']['item']>> : T extends JSONColumn<JSONType> ? JsonToZod<T['data']['schema']> : T extends VirtualColumn ? z.ZodNever : never;
|
|
23
|
-
declare module 'orchid-core' {
|
|
24
|
-
interface JSONType {
|
|
25
|
-
zod: z.ZodTypeAny;
|
|
26
|
-
}
|
|
27
|
-
interface JSONUnknown {
|
|
28
|
-
zod: z.ZodUnknown;
|
|
29
|
-
}
|
|
30
|
-
interface JSONBoolean {
|
|
31
|
-
zod: z.ZodBoolean;
|
|
32
|
-
}
|
|
33
|
-
interface JSONNull {
|
|
34
|
-
zod: z.ZodNull;
|
|
35
|
-
}
|
|
36
|
-
interface JSONNumber {
|
|
37
|
-
zod: z.ZodNumber;
|
|
38
|
-
}
|
|
39
|
-
interface JSONString {
|
|
40
|
-
zod: z.ZodString;
|
|
41
|
-
}
|
|
5
|
+
type ParseDateToNumber = ParseColumn<DateBaseColumn<ZodSchemaConfig>, ZodNumber, number>;
|
|
6
|
+
type ParseDateToDate = ParseColumn<DateBaseColumn<ZodSchemaConfig>, ZodDate, Date>;
|
|
7
|
+
declare class ZodJSONColumn<ZodSchema extends ZodTypeAny> extends ColumnType<ZodSchemaConfig, ZodSchema['_output'], ZodSchema, OperatorsJson> {
|
|
8
|
+
dataType: "jsonb";
|
|
9
|
+
operators: OperatorsJson;
|
|
10
|
+
data: ColumnData;
|
|
11
|
+
constructor(schema: ZodSchema);
|
|
12
|
+
toCode(t: string): Code;
|
|
42
13
|
}
|
|
43
|
-
type
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
type MapDiscriminatedUnion<T extends JSONDiscriminatedUnion<string, any>, Options = MapJsonTuple<T['data']['types']>> = z.ZodDiscriminatedUnion<T['data']['discriminator'], Options extends z.ZodDiscriminatedUnionOption<T['data']['discriminator']>[] ? Options : never>;
|
|
49
|
-
type MapUnionArgs<T extends unknown[]> = T extends [
|
|
50
|
-
infer F extends JSONType,
|
|
51
|
-
infer S extends JSONType,
|
|
52
|
-
...infer Tail
|
|
53
|
-
] ? [JsonToZod<F>, JsonToZod<S>, ...MapJsonTuple<Tail>] : never;
|
|
54
|
-
type MapJsonTuple<T extends unknown[]> = T extends [infer Head, ...infer Tail] ? [Head extends JSONType ? JsonToZod<Head> : never, ...MapJsonTuple<Tail>] : [];
|
|
55
|
-
type Columns = {
|
|
56
|
-
shape: ColumnsShapeBase;
|
|
57
|
-
};
|
|
58
|
-
type Table = {
|
|
59
|
-
columns: ColumnsShapeBase;
|
|
14
|
+
type ArrayMethods<Value> = {
|
|
15
|
+
min<T extends ColumnTypeBase>(this: T, value: Value, params?: ErrorMessage): T;
|
|
16
|
+
max<T extends ColumnTypeBase>(this: T, value: Value, params?: ErrorMessage): T;
|
|
17
|
+
length<T extends ColumnTypeBase>(this: T, value: Value, params?: ErrorMessage): T;
|
|
18
|
+
nonEmpty<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
60
19
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
20
|
+
interface ZodArrayColumn<Item extends ArrayColumnValue> extends ArrayColumn<ZodSchemaConfig, Item, ZodArray<Item['inputSchema']>, ZodArray<Item['outputSchema']>, ZodArray<Item['querySchema']>>, ArrayMethods<number> {
|
|
21
|
+
}
|
|
22
|
+
declare class ZodArrayColumn<Item extends ArrayColumnValue> extends ArrayColumn<ZodSchemaConfig, Item, ZodArray<Item['inputSchema']>, ZodArray<Item['outputSchema']>, ZodArray<Item['querySchema']>> {
|
|
23
|
+
constructor(item: Item);
|
|
24
|
+
}
|
|
25
|
+
type ZodSchemaConfig = {
|
|
26
|
+
type: ZodTypeAny;
|
|
27
|
+
parse<T extends {
|
|
28
|
+
type: unknown;
|
|
29
|
+
}, OutputSchema extends ZodTypeAny, Output = OutputSchema['_output']>(this: T, _schema: OutputSchema, fn: (input: T['type']) => Output): ParseColumn<T, OutputSchema, Output>;
|
|
30
|
+
encode<T extends {
|
|
31
|
+
type: unknown;
|
|
32
|
+
}, InputSchema extends ZodTypeAny, Input = InputSchema['_output']>(this: T, _schema: InputSchema, fn: (input: Input) => unknown): EncodeColumn<T, InputSchema, Input>;
|
|
33
|
+
asType<T, Types extends AsTypeArg<ZodTypeAny>, TypeSchema extends ZodTypeAny = Types extends {
|
|
34
|
+
type: ZodTypeAny;
|
|
35
|
+
} ? Types['type'] : never, Type = TypeSchema['_output']>(this: T, types: Types): Omit<T, 'type' | 'inputType' | 'inputSchema' | 'outputType' | 'outputSchema' | 'queryType' | 'querySchema'> & {
|
|
36
|
+
type: Type;
|
|
37
|
+
inputType: Types['input'] extends ZodTypeAny ? Types['input']['_output'] : Type;
|
|
38
|
+
inputSchema: Types['input'] extends ZodTypeAny ? Types['input'] : TypeSchema;
|
|
39
|
+
outputType: Types['output'] extends ZodTypeAny ? Types['output']['_output'] : Type;
|
|
40
|
+
outputSchema: Types['output'] extends ZodTypeAny ? Types['output'] : TypeSchema;
|
|
41
|
+
queryType: Types['query'] extends ZodTypeAny ? Types['query']['_output'] : Type;
|
|
42
|
+
querySchema: Types['query'] extends ZodTypeAny ? Types['query'] : TypeSchema;
|
|
43
|
+
};
|
|
44
|
+
dateAsNumber(): ParseDateToNumber;
|
|
45
|
+
dateAsDate(): ParseDateToDate;
|
|
46
|
+
dateMethods: {
|
|
47
|
+
min<T extends ColumnTypeBase>(this: T, value: Date, params?: ErrorMessage): T;
|
|
48
|
+
max<T extends ColumnTypeBase>(this: T, value: Date, params?: ErrorMessage): T;
|
|
49
|
+
};
|
|
50
|
+
enum<U extends string, T extends [U, ...U[]]>(dataType: string, type: T): EnumColumn<ZodSchemaConfig, ZodEnum<T>, U, T>;
|
|
51
|
+
array<Item extends ArrayColumnValue>(item: Item): ZodArrayColumn<Item>;
|
|
52
|
+
nullable<T extends ColumnTypeBase>(this: T): NullableColumn<T, ZodNullable<T['inputSchema']>, ZodNullable<T['outputSchema']>, ZodNullable<T['querySchema']>>;
|
|
53
|
+
json<ZodSchema extends ZodTypeAny = ZodUnknown>(schema?: ZodSchema): ZodJSONColumn<ZodSchema>;
|
|
54
|
+
boolean: ZodBoolean;
|
|
55
|
+
buffer: ZodType<Buffer>;
|
|
56
|
+
unknown: ZodUnknown;
|
|
57
|
+
never: ZodNever;
|
|
58
|
+
string: ZodString;
|
|
59
|
+
stringMin(max: number): ZodString;
|
|
60
|
+
stringMax(max: number): ZodString;
|
|
61
|
+
stringMinMax(min: number, max: number): ZodString;
|
|
62
|
+
stringMethods: ArrayMethods<number> & {
|
|
63
|
+
email<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
64
|
+
url<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
65
|
+
emoji<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
66
|
+
uuid<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
67
|
+
cuid<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
68
|
+
cuid2<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
69
|
+
ulid<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
70
|
+
regex<T extends ColumnTypeBase>(this: T, value: RegExp, params?: ErrorMessage): T;
|
|
71
|
+
includes<T extends ColumnTypeBase, Value extends string>(this: T, value: Value, params?: ErrorMessage): T;
|
|
72
|
+
startsWith<T extends ColumnTypeBase, Value extends string>(this: T, value: Value, params?: ErrorMessage): T;
|
|
73
|
+
endsWith<T extends ColumnTypeBase, Value extends string>(this: T, value: Value, params?: ErrorMessage): T;
|
|
74
|
+
datetime<T extends ColumnTypeBase>(this: T, params?: StringTypeData['datetime'] & Exclude<ErrorMessage, string>): T;
|
|
75
|
+
ip<T extends ColumnTypeBase>(this: T, params?: StringTypeData['ip'] & Exclude<ErrorMessage, string>): T;
|
|
76
|
+
trim<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
77
|
+
toLowerCase<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
78
|
+
toUpperCase<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
79
|
+
};
|
|
80
|
+
number: ZodNumber;
|
|
81
|
+
numberMethods: {
|
|
82
|
+
lt<T extends ColumnTypeBase>(this: T, value: number, params?: ErrorMessage): T;
|
|
83
|
+
lte<T extends ColumnTypeBase>(this: T, value: number, params?: ErrorMessage): T;
|
|
84
|
+
max<T extends ColumnTypeBase>(this: T, value: number, params?: ErrorMessage): T;
|
|
85
|
+
gt<T extends ColumnTypeBase>(this: T, value: number, params?: ErrorMessage): T;
|
|
86
|
+
gte<T extends ColumnTypeBase>(this: T, value: number, params?: ErrorMessage): T;
|
|
87
|
+
min<T extends ColumnTypeBase>(this: T, value: number, params?: ErrorMessage): T;
|
|
88
|
+
positive<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
89
|
+
nonNegative<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
90
|
+
negative<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
91
|
+
nonPositive<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
92
|
+
step<T extends ColumnTypeBase>(this: T, value: number, params?: ErrorMessage): T;
|
|
93
|
+
int<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
94
|
+
finite<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
95
|
+
safe<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
96
|
+
};
|
|
97
|
+
int: ZodNumber;
|
|
98
|
+
stringNumberDate: ZodDate;
|
|
99
|
+
timeInterval: ZodObject<{
|
|
100
|
+
years: ZodOptional<ZodNumber>;
|
|
101
|
+
months: ZodOptional<ZodNumber>;
|
|
102
|
+
days: ZodOptional<ZodNumber>;
|
|
103
|
+
hours: ZodOptional<ZodNumber>;
|
|
104
|
+
minutes: ZodOptional<ZodNumber>;
|
|
105
|
+
seconds: ZodOptional<ZodNumber>;
|
|
106
|
+
}>;
|
|
107
|
+
bit(max: number): ZodString;
|
|
108
|
+
uuid: ZodString;
|
|
109
|
+
inputSchema<T extends ColumnSchemaGetterTableClass>(this: T): MapSchema<T, 'inputSchema'>;
|
|
110
|
+
outputSchema<T extends ColumnSchemaGetterTableClass>(this: T): MapSchema<T, 'outputSchema'>;
|
|
111
|
+
querySchema<T extends ColumnSchemaGetterTableClass>(this: T): MapSchema<T, 'querySchema'>;
|
|
112
|
+
updateSchema<T extends ColumnSchemaGetterTableClass>(this: T): UpdateSchema<T>;
|
|
113
|
+
pkeySchema<T extends ColumnSchemaGetterTableClass>(this: T): PkeySchema<T>;
|
|
114
|
+
errors<T extends ColumnTypeBase>(this: T, errors: ErrorMessages): T;
|
|
64
115
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}>;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
months: z.ZodOptional<z.ZodNumber>;
|
|
76
|
-
days: z.ZodOptional<z.ZodNumber>;
|
|
77
|
-
hours: z.ZodOptional<z.ZodNumber>;
|
|
78
|
-
seconds: z.ZodOptional<z.ZodNumber>;
|
|
79
|
-
}, "strict", z.ZodTypeAny, {
|
|
80
|
-
years?: number | undefined;
|
|
81
|
-
months?: number | undefined;
|
|
82
|
-
days?: number | undefined;
|
|
83
|
-
hours?: number | undefined;
|
|
84
|
-
seconds?: number | undefined;
|
|
85
|
-
}, {
|
|
86
|
-
years?: number | undefined;
|
|
87
|
-
months?: number | undefined;
|
|
88
|
-
days?: number | undefined;
|
|
89
|
-
hours?: number | undefined;
|
|
90
|
-
seconds?: number | undefined;
|
|
91
|
-
}>;
|
|
116
|
+
declare const zodSchemaConfig: ZodSchemaConfig;
|
|
117
|
+
type MapSchema<T extends ColumnSchemaGetterTableClass, Key extends 'inputSchema' | 'outputSchema' | 'querySchema'> = ZodObject<{
|
|
118
|
+
[K in keyof ColumnSchemaGetterColumns<T>]: ColumnSchemaGetterColumns<T>[K][Key];
|
|
119
|
+
}, 'strip'>;
|
|
120
|
+
type UpdateSchema<T extends ColumnSchemaGetterTableClass> = ZodObject<{
|
|
121
|
+
[K in keyof ColumnSchemaGetterColumns<T>]: ZodOptional<ColumnSchemaGetterColumns<T>[K]['inputSchema']>;
|
|
122
|
+
}, 'strip'>;
|
|
123
|
+
type PkeySchema<T extends ColumnSchemaGetterTableClass> = ZodObject<{
|
|
124
|
+
[K in keyof ColumnSchemaGetterColumns<T> as ColumnSchemaGetterColumns<T>[K]['data']['isPrimaryKey'] extends true ? K : never]: ColumnSchemaGetterColumns<T>[K]['inputSchema'];
|
|
125
|
+
}, 'strip'>;
|
|
92
126
|
|
|
93
|
-
export {
|
|
127
|
+
export { ZodSchemaConfig, zodSchemaConfig };
|