orchid-orm-valibot 0.0.1
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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/index.d.ts +243 -0
- package/dist/index.js +450 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +445 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Roman Kushyn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { ParseColumn, EncodeColumn, AsTypeArg, ColumnTypeBase, NullableColumn, ColumnSchemaGetterTableClass, ColumnSchemaGetterColumns, Code, ErrorMessage, StringTypeData } from 'orchid-core';
|
|
2
|
+
import { EnumColumn, ArrayColumnValue, ColumnType, OperatorsJson, ColumnData, ArrayColumn, SmallIntColumn, IntegerColumn, RealColumn, SmallSerialColumn, SerialColumn, BigIntColumn, DecimalColumn, DoublePrecisionColumn, BigSerialColumn, MoneyColumn, VarCharColumn, CharColumn, TextColumn, StringColumn, CitextColumn, DateColumn, TimestampColumn, TimestampTZColumn } from 'pqb';
|
|
3
|
+
import { BaseValidation, BaseSchema, Output, PicklistSchema, NullableSchema, UnknownSchema, BooleanSchema, InstanceSchema, NeverSchema, StringSchema, NumberSchema, DateSchema, ObjectSchema, OptionalSchema, ArraySchema } from 'valibot';
|
|
4
|
+
|
|
5
|
+
type ParseDateToNumber = ParseColumn<DateColumnValibot, NumberSchema, number>;
|
|
6
|
+
type ParseDateToDate = ParseColumn<DateColumnValibot, DateSchema, Date>;
|
|
7
|
+
declare class ValibotJSONColumn<Schema extends BaseSchema> extends ColumnType<ValibotSchemaConfig, Output<Schema>, Schema, OperatorsJson> {
|
|
8
|
+
dataType: "jsonb";
|
|
9
|
+
operators: OperatorsJson;
|
|
10
|
+
data: ColumnData;
|
|
11
|
+
constructor(schema: Schema);
|
|
12
|
+
toCode(t: string): Code;
|
|
13
|
+
}
|
|
14
|
+
interface 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;
|
|
19
|
+
}
|
|
20
|
+
interface ValibotArrayColumn<Item extends ArrayColumnValue> extends ArrayColumn<ValibotSchemaConfig, Item, ArraySchema<Item['inputSchema']>, ArraySchema<Item['outputSchema']>, ArraySchema<Item['querySchema']>>, ArrayMethods<number> {
|
|
21
|
+
}
|
|
22
|
+
declare class ValibotArrayColumn<Item extends ArrayColumnValue> extends ArrayColumn<ValibotSchemaConfig, Item, ArraySchema<Item['inputSchema']>, ArraySchema<Item['outputSchema']>, ArraySchema<Item['querySchema']>> {
|
|
23
|
+
constructor(item: Item);
|
|
24
|
+
}
|
|
25
|
+
interface NumberMethods {
|
|
26
|
+
lt<T extends ColumnTypeBase>(this: T, value: number, params?: ErrorMessage): T;
|
|
27
|
+
lte<T extends ColumnTypeBase>(this: T, value: number, params?: ErrorMessage): T;
|
|
28
|
+
max<T extends ColumnTypeBase>(this: T, value: number, params?: ErrorMessage): T;
|
|
29
|
+
gt<T extends ColumnTypeBase>(this: T, value: number, params?: ErrorMessage): T;
|
|
30
|
+
gte<T extends ColumnTypeBase>(this: T, value: number, params?: ErrorMessage): T;
|
|
31
|
+
min<T extends ColumnTypeBase>(this: T, value: number, params?: ErrorMessage): T;
|
|
32
|
+
positive<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
33
|
+
nonNegative<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
34
|
+
negative<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
35
|
+
nonPositive<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
36
|
+
step<T extends ColumnTypeBase>(this: T, value: number, params?: ErrorMessage): T;
|
|
37
|
+
int<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
38
|
+
finite<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
39
|
+
safe<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
40
|
+
}
|
|
41
|
+
type GtValidation<TInput extends string | number | bigint | boolean | Date, TRequirement extends TInput> = BaseValidation<TInput> & {
|
|
42
|
+
/**
|
|
43
|
+
* The validation type.
|
|
44
|
+
*/
|
|
45
|
+
type: 'gt';
|
|
46
|
+
/**
|
|
47
|
+
* The maximum value.
|
|
48
|
+
*/
|
|
49
|
+
requirement: TRequirement;
|
|
50
|
+
};
|
|
51
|
+
declare function gt<TInput extends string | number | bigint | Date, TRequirement extends TInput>(requirement: TRequirement, message?: string): GtValidation<TInput, TRequirement>;
|
|
52
|
+
type LtValidation<TInput extends string | number | bigint | boolean | Date, TRequirement extends TInput> = BaseValidation<TInput> & {
|
|
53
|
+
/**
|
|
54
|
+
* The validation type.
|
|
55
|
+
*/
|
|
56
|
+
type: 'lt';
|
|
57
|
+
/**
|
|
58
|
+
* The maximum value.
|
|
59
|
+
*/
|
|
60
|
+
requirement: TRequirement;
|
|
61
|
+
};
|
|
62
|
+
declare function lt<TInput extends string | number | bigint | Date, TRequirement extends TInput>(requirement: TRequirement, message?: string): LtValidation<TInput, TRequirement>;
|
|
63
|
+
type StepValidation<TInput extends number, TRequirement extends TInput> = BaseValidation<TInput> & {
|
|
64
|
+
/**
|
|
65
|
+
* The validation type.
|
|
66
|
+
*/
|
|
67
|
+
type: 'step';
|
|
68
|
+
/**
|
|
69
|
+
* The maximum value.
|
|
70
|
+
*/
|
|
71
|
+
requirement: TRequirement;
|
|
72
|
+
};
|
|
73
|
+
declare function step<TInput extends number, TRequirement extends TInput>(requirement: TRequirement, message?: string): StepValidation<TInput, TRequirement>;
|
|
74
|
+
interface SmallIntColumnValibot extends SmallIntColumn<ValibotSchemaConfig>, NumberMethods {
|
|
75
|
+
}
|
|
76
|
+
declare class SmallIntColumnValibot extends SmallIntColumn<ValibotSchemaConfig> {
|
|
77
|
+
}
|
|
78
|
+
interface IntegerColumnValibot extends IntegerColumn<ValibotSchemaConfig>, NumberMethods {
|
|
79
|
+
}
|
|
80
|
+
declare class IntegerColumnValibot extends IntegerColumn<ValibotSchemaConfig> {
|
|
81
|
+
}
|
|
82
|
+
interface RealColumnValibot extends RealColumn<ValibotSchemaConfig>, NumberMethods {
|
|
83
|
+
}
|
|
84
|
+
declare class RealColumnValibot extends RealColumn<ValibotSchemaConfig> {
|
|
85
|
+
}
|
|
86
|
+
interface SmallSerialColumnValibot extends SmallSerialColumn<ValibotSchemaConfig>, NumberMethods {
|
|
87
|
+
}
|
|
88
|
+
declare class SmallSerialColumnValibot extends SmallSerialColumn<ValibotSchemaConfig> {
|
|
89
|
+
}
|
|
90
|
+
interface SerialColumnValibot extends SerialColumn<ValibotSchemaConfig>, NumberMethods {
|
|
91
|
+
}
|
|
92
|
+
declare class SerialColumnValibot extends SerialColumn<ValibotSchemaConfig> {
|
|
93
|
+
}
|
|
94
|
+
interface StringMethods extends ArrayMethods<number> {
|
|
95
|
+
email<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
96
|
+
url<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
97
|
+
emoji<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
98
|
+
uuid<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
99
|
+
cuid2<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
100
|
+
ulid<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
101
|
+
regex<T extends ColumnTypeBase>(this: T, value: RegExp, params?: ErrorMessage): T;
|
|
102
|
+
includes<T extends ColumnTypeBase, Value extends string>(this: T, value: Value, params?: ErrorMessage): T;
|
|
103
|
+
startsWith<T extends ColumnTypeBase, Value extends string>(this: T, value: Value, params?: ErrorMessage): T;
|
|
104
|
+
endsWith<T extends ColumnTypeBase, Value extends string>(this: T, value: Value, params?: ErrorMessage): T;
|
|
105
|
+
datetime<T extends ColumnTypeBase>(this: T, params?: StringTypeData['datetime'] & Exclude<ErrorMessage, string>): T;
|
|
106
|
+
ip<T extends ColumnTypeBase>(this: T, params?: StringTypeData['ip'] & Exclude<ErrorMessage, string>): T;
|
|
107
|
+
trim<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
108
|
+
toLowerCase<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
109
|
+
toUpperCase<T extends ColumnTypeBase>(this: T, params?: ErrorMessage): T;
|
|
110
|
+
}
|
|
111
|
+
interface BigIntColumnValibot extends BigIntColumn<ValibotSchemaConfig>, StringMethods {
|
|
112
|
+
}
|
|
113
|
+
declare class BigIntColumnValibot extends BigIntColumn<ValibotSchemaConfig> {
|
|
114
|
+
}
|
|
115
|
+
interface DecimalColumnValibot extends DecimalColumn<ValibotSchemaConfig>, StringMethods {
|
|
116
|
+
}
|
|
117
|
+
declare class DecimalColumnValibot extends DecimalColumn<ValibotSchemaConfig> {
|
|
118
|
+
}
|
|
119
|
+
interface DoublePrecisionColumnValibot extends DoublePrecisionColumn<ValibotSchemaConfig>, StringMethods {
|
|
120
|
+
}
|
|
121
|
+
declare class DoublePrecisionColumnValibot extends DoublePrecisionColumn<ValibotSchemaConfig> {
|
|
122
|
+
}
|
|
123
|
+
interface BigSerialColumnValibot extends BigSerialColumn<ValibotSchemaConfig>, StringMethods {
|
|
124
|
+
}
|
|
125
|
+
declare class BigSerialColumnValibot extends BigSerialColumn<ValibotSchemaConfig> {
|
|
126
|
+
}
|
|
127
|
+
interface MoneyColumnValibot extends MoneyColumn<ValibotSchemaConfig>, StringMethods {
|
|
128
|
+
}
|
|
129
|
+
declare class MoneyColumnValibot extends MoneyColumn<ValibotSchemaConfig> {
|
|
130
|
+
}
|
|
131
|
+
interface VarCharColumnValibot extends VarCharColumn<ValibotSchemaConfig>, StringMethods {
|
|
132
|
+
}
|
|
133
|
+
declare class VarCharColumnValibot extends VarCharColumn<ValibotSchemaConfig> {
|
|
134
|
+
}
|
|
135
|
+
interface CharColumnValibot extends CharColumn<ValibotSchemaConfig>, StringMethods {
|
|
136
|
+
}
|
|
137
|
+
declare class CharColumnValibot extends CharColumn<ValibotSchemaConfig> {
|
|
138
|
+
}
|
|
139
|
+
interface TextColumnValibot extends TextColumn<ValibotSchemaConfig>, StringMethods {
|
|
140
|
+
}
|
|
141
|
+
declare class TextColumnValibot extends TextColumn<ValibotSchemaConfig> {
|
|
142
|
+
}
|
|
143
|
+
interface StringColumnValibot extends StringColumn<ValibotSchemaConfig>, StringMethods {
|
|
144
|
+
}
|
|
145
|
+
declare class StringColumnValibot extends StringColumn<ValibotSchemaConfig> {
|
|
146
|
+
}
|
|
147
|
+
interface CitextColumnValibot extends CitextColumn<ValibotSchemaConfig>, StringMethods {
|
|
148
|
+
}
|
|
149
|
+
declare class CitextColumnValibot extends CitextColumn<ValibotSchemaConfig> {
|
|
150
|
+
}
|
|
151
|
+
interface DateMethods {
|
|
152
|
+
min<T extends ColumnTypeBase>(this: T, value: Date, params?: ErrorMessage): T;
|
|
153
|
+
max<T extends ColumnTypeBase>(this: T, value: Date, params?: ErrorMessage): T;
|
|
154
|
+
}
|
|
155
|
+
interface DateColumnValibot extends DateColumn<ValibotSchemaConfig>, DateMethods {
|
|
156
|
+
}
|
|
157
|
+
declare class DateColumnValibot extends DateColumn<ValibotSchemaConfig> {
|
|
158
|
+
}
|
|
159
|
+
interface TimestampNoTzColumnValibot extends TimestampColumn<ValibotSchemaConfig>, DateMethods {
|
|
160
|
+
}
|
|
161
|
+
declare class TimestampNoTzColumnValibot extends TimestampColumn<ValibotSchemaConfig> {
|
|
162
|
+
}
|
|
163
|
+
interface TimestampColumnValibot extends TimestampTZColumn<ValibotSchemaConfig>, DateMethods {
|
|
164
|
+
}
|
|
165
|
+
declare class TimestampColumnValibot extends TimestampTZColumn<ValibotSchemaConfig> {
|
|
166
|
+
}
|
|
167
|
+
interface ValibotSchemaConfig {
|
|
168
|
+
type: BaseSchema;
|
|
169
|
+
parse<T extends {
|
|
170
|
+
type: unknown;
|
|
171
|
+
}, OutputSchema extends BaseSchema, Out = Output<OutputSchema>>(this: T, _schema: OutputSchema, fn: (input: T['type']) => Out): ParseColumn<T, OutputSchema, Out>;
|
|
172
|
+
encode<T extends {
|
|
173
|
+
type: unknown;
|
|
174
|
+
}, InputSchema extends BaseSchema, In = Output<InputSchema>>(this: T, _schema: InputSchema, fn: (input: In) => unknown): EncodeColumn<T, InputSchema, In>;
|
|
175
|
+
asType<T, Types extends AsTypeArg<BaseSchema>, TypeSchema extends BaseSchema = Types extends {
|
|
176
|
+
type: BaseSchema;
|
|
177
|
+
} ? Types['type'] : never, Type = Output<TypeSchema>>(this: T, types: Types): {
|
|
178
|
+
[K in keyof T]: K extends 'type' ? Type : K extends 'inputType' ? Types['input'] extends BaseSchema ? Output<Types['input']> : Type : K extends 'inputSchema' ? Types['input'] extends BaseSchema ? Types['input'] : TypeSchema : K extends 'outputType' ? Types['output'] extends BaseSchema ? Output<Types['output']> : Type : K extends 'outputSchema' ? Types['output'] extends BaseSchema ? Types['output'] : TypeSchema : K extends 'queryType' ? Types['query'] extends BaseSchema ? Output<Types['query']> : Type : K extends 'querySchema' ? Types['query'] extends BaseSchema ? Types['query'] : TypeSchema : T[K];
|
|
179
|
+
};
|
|
180
|
+
dateAsNumber(): ParseDateToNumber;
|
|
181
|
+
dateAsDate(): ParseDateToDate;
|
|
182
|
+
enum<U extends string, T extends [U, ...U[]]>(dataType: string, type: T): EnumColumn<ValibotSchemaConfig, PicklistSchema<T>, U, T>;
|
|
183
|
+
array<Item extends ArrayColumnValue>(item: Item): ValibotArrayColumn<Item>;
|
|
184
|
+
nullable<T extends ColumnTypeBase>(this: T): NullableColumn<T, NullableSchema<T['inputSchema']>, NullableSchema<T['outputSchema']>, NullableSchema<T['querySchema']>>;
|
|
185
|
+
json<Schema extends BaseSchema = UnknownSchema>(schema?: Schema): ValibotJSONColumn<Schema>;
|
|
186
|
+
boolean(): BooleanSchema;
|
|
187
|
+
buffer(): InstanceSchema<typeof Buffer>;
|
|
188
|
+
unknown(): UnknownSchema;
|
|
189
|
+
never(): NeverSchema;
|
|
190
|
+
stringSchema(): StringSchema;
|
|
191
|
+
stringMin(max: number): StringSchema;
|
|
192
|
+
stringMax(max: number): StringSchema;
|
|
193
|
+
stringMinMax(min: number, max: number): StringSchema;
|
|
194
|
+
number(): NumberSchema;
|
|
195
|
+
int(): NumberSchema;
|
|
196
|
+
stringNumberDate(): DateSchema;
|
|
197
|
+
timeInterval(): ObjectSchema<{
|
|
198
|
+
years: OptionalSchema<NumberSchema>;
|
|
199
|
+
months: OptionalSchema<NumberSchema>;
|
|
200
|
+
days: OptionalSchema<NumberSchema>;
|
|
201
|
+
hours: OptionalSchema<NumberSchema>;
|
|
202
|
+
minutes: OptionalSchema<NumberSchema>;
|
|
203
|
+
seconds: OptionalSchema<NumberSchema>;
|
|
204
|
+
}>;
|
|
205
|
+
bit(max: number): StringSchema;
|
|
206
|
+
uuid(): StringSchema;
|
|
207
|
+
inputSchema<T extends ColumnSchemaGetterTableClass>(this: T): MapSchema<T, 'inputSchema'>;
|
|
208
|
+
outputSchema<T extends ColumnSchemaGetterTableClass>(this: T): MapSchema<T, 'outputSchema'>;
|
|
209
|
+
querySchema<T extends ColumnSchemaGetterTableClass>(this: T): MapSchema<T, 'querySchema'>;
|
|
210
|
+
updateSchema<T extends ColumnSchemaGetterTableClass>(this: T): UpdateSchema<T>;
|
|
211
|
+
pkeySchema<T extends ColumnSchemaGetterTableClass>(this: T): PkeySchema<T>;
|
|
212
|
+
error<T extends ColumnTypeBase<ValibotSchemaConfig>>(this: T, message: string): T;
|
|
213
|
+
smallint(): SmallIntColumnValibot;
|
|
214
|
+
integer(): IntegerColumnValibot;
|
|
215
|
+
real(): RealColumnValibot;
|
|
216
|
+
smallSerial(): SmallSerialColumnValibot;
|
|
217
|
+
serial(): SerialColumnValibot;
|
|
218
|
+
bigint(): BigIntColumnValibot;
|
|
219
|
+
decimal(precision?: number, scale?: number): DecimalColumnValibot;
|
|
220
|
+
doublePrecision(): DoublePrecisionColumnValibot;
|
|
221
|
+
bigSerial(): BigSerialColumnValibot;
|
|
222
|
+
money(): MoneyColumnValibot;
|
|
223
|
+
varchar(limit?: number): VarCharColumnValibot;
|
|
224
|
+
char(limit?: number): CharColumnValibot;
|
|
225
|
+
text(min: number, max: number): TextColumnValibot;
|
|
226
|
+
string(limit?: number): StringColumnValibot;
|
|
227
|
+
citext(min: number, max: number): CitextColumnValibot;
|
|
228
|
+
date(): DateColumnValibot;
|
|
229
|
+
timestampNoTZ(precision?: number): TimestampNoTzColumnValibot;
|
|
230
|
+
timestamp(precision?: number): TimestampColumnValibot;
|
|
231
|
+
}
|
|
232
|
+
declare const valibotSchemaConfig: ValibotSchemaConfig;
|
|
233
|
+
type MapSchema<T extends ColumnSchemaGetterTableClass, Key extends 'inputSchema' | 'outputSchema' | 'querySchema'> = ObjectSchema<{
|
|
234
|
+
[K in keyof ColumnSchemaGetterColumns<T>]: ColumnSchemaGetterColumns<T>[K][Key];
|
|
235
|
+
}>;
|
|
236
|
+
type UpdateSchema<T extends ColumnSchemaGetterTableClass> = ObjectSchema<{
|
|
237
|
+
[K in keyof ColumnSchemaGetterColumns<T>]: OptionalSchema<ColumnSchemaGetterColumns<T>[K]['inputSchema']>;
|
|
238
|
+
}>;
|
|
239
|
+
type PkeySchema<T extends ColumnSchemaGetterTableClass> = ObjectSchema<{
|
|
240
|
+
[K in keyof ColumnSchemaGetterColumns<T> as ColumnSchemaGetterColumns<T>[K]['data']['isPrimaryKey'] extends true ? K : never]: ColumnSchemaGetterColumns<T>[K]['inputSchema'];
|
|
241
|
+
}>;
|
|
242
|
+
|
|
243
|
+
export { GtValidation, LtValidation, StepValidation, ValibotSchemaConfig, gt, lt, step, valibotSchemaConfig };
|