@rwillians/exto 0.1.0 → 0.1.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/cjs/bun-postgres.js +75 -0
- package/dist/cjs/bun-sqlite.js +94 -0
- package/dist/cjs/index.js +453 -0
- package/dist/cjs/standard-schema.js +240 -0
- package/dist/cjs/utils.js +17 -0
- package/dist/esm/bun-postgres.js +71 -0
- package/dist/esm/bun-sqlite.js +90 -0
- package/dist/esm/index.js +408 -0
- package/dist/esm/standard-schema.js +229 -0
- package/dist/esm/utils.js +10 -0
- package/dist/types/bun-postgres.d.ts +16 -0
- package/dist/types/bun-sqlite.d.ts +16 -0
- package/dist/types/index.d.ts +315 -0
- package/dist/types/standard-schema.d.ts +174 -0
- package/dist/types/utils.d.ts +11 -0
- package/package.json +6 -6
- package/dist/.gitignore +0 -2
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import * as std from './standard-schema';
|
|
2
|
+
import { ValidationError } from './standard-schema';
|
|
3
|
+
import { type CamelCase, type Expand } from './utils';
|
|
4
|
+
type Primitive = 'BIGINT' | 'BINARY' | 'BOOLEAN' | 'CITEXT' | 'DATE' | 'DATETIME' | 'DECIMAL' | 'FLOAT' | 'INTEGER' | 'JSON' | 'SEQUENCE' | 'STRING' | 'TEXT' | 'UUID';
|
|
5
|
+
type ColumnProps<S extends std.Schema = std.Schema> = {
|
|
6
|
+
type: Primitive;
|
|
7
|
+
schema: S;
|
|
8
|
+
default?: unknown;
|
|
9
|
+
generated?: true;
|
|
10
|
+
length?: number;
|
|
11
|
+
precision?: number;
|
|
12
|
+
scale?: number;
|
|
13
|
+
nullable?: true;
|
|
14
|
+
primaryKey?: true;
|
|
15
|
+
unique?: true;
|
|
16
|
+
};
|
|
17
|
+
type Column<K extends string = string, P extends ColumnProps = ColumnProps> = P & {
|
|
18
|
+
key: K;
|
|
19
|
+
name: string;
|
|
20
|
+
input: std.input<P['schema']>;
|
|
21
|
+
output: std.output<P['schema']>;
|
|
22
|
+
};
|
|
23
|
+
declare class ColumnBuilder<P extends ColumnProps> {
|
|
24
|
+
readonly props: P;
|
|
25
|
+
constructor(props: P);
|
|
26
|
+
default(value: std.output<P['schema']> | (() => std.output<P['schema']>)): ColumnBuilder<Expand<P & {
|
|
27
|
+
default: typeof value;
|
|
28
|
+
}>>;
|
|
29
|
+
generated(): ColumnBuilder<Expand<P & {
|
|
30
|
+
generated: true;
|
|
31
|
+
}>>;
|
|
32
|
+
nullable(): ColumnBuilder<Expand<Omit<P, "schema"> & {
|
|
33
|
+
nullable: true;
|
|
34
|
+
schema: std.Schema<std.input<P['schema']> | null, std.output<P['schema']> | null>;
|
|
35
|
+
}>>;
|
|
36
|
+
primaryKey(): ColumnBuilder<Expand<P & {
|
|
37
|
+
primaryKey: true;
|
|
38
|
+
}>>;
|
|
39
|
+
unique(): ColumnBuilder<Expand<P & {
|
|
40
|
+
unique: true;
|
|
41
|
+
}>>;
|
|
42
|
+
}
|
|
43
|
+
declare const column: <P extends ColumnProps>(props: P) => ColumnBuilder<P>;
|
|
44
|
+
declare const types: {
|
|
45
|
+
bigint: () => ColumnBuilder<{
|
|
46
|
+
type: "BIGINT";
|
|
47
|
+
schema: std.Schema<bigint, bigint>;
|
|
48
|
+
}>;
|
|
49
|
+
binary: () => ColumnBuilder<{
|
|
50
|
+
type: "BINARY";
|
|
51
|
+
schema: std.Schema<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
52
|
+
}>;
|
|
53
|
+
boolean: () => ColumnBuilder<{
|
|
54
|
+
type: "BOOLEAN";
|
|
55
|
+
schema: std.Schema<boolean, boolean>;
|
|
56
|
+
}>;
|
|
57
|
+
citext: () => ColumnBuilder<{
|
|
58
|
+
type: "CITEXT";
|
|
59
|
+
schema: std.Schema<string, string>;
|
|
60
|
+
}>;
|
|
61
|
+
date: () => ColumnBuilder<{
|
|
62
|
+
type: "DATE";
|
|
63
|
+
schema: std.Schema<string, string>;
|
|
64
|
+
}>;
|
|
65
|
+
datetime: () => ColumnBuilder<{
|
|
66
|
+
type: "DATETIME";
|
|
67
|
+
schema: std.Schema<string | number | Date, Date>;
|
|
68
|
+
}>;
|
|
69
|
+
decimal: (options?: {
|
|
70
|
+
precision: number;
|
|
71
|
+
scale: number;
|
|
72
|
+
}) => ColumnBuilder<{
|
|
73
|
+
precision?: number | undefined;
|
|
74
|
+
scale?: number | undefined;
|
|
75
|
+
type: "DECIMAL";
|
|
76
|
+
schema: std.Schema<number, number>;
|
|
77
|
+
}>;
|
|
78
|
+
enum: <const T extends readonly [string, ...string[]]>(values: T) => ColumnBuilder<{
|
|
79
|
+
type: "STRING";
|
|
80
|
+
schema: std.Schema<T[number], T[number]>;
|
|
81
|
+
length: number;
|
|
82
|
+
}>;
|
|
83
|
+
float: () => ColumnBuilder<{
|
|
84
|
+
type: "FLOAT";
|
|
85
|
+
schema: std.Schema<number, number>;
|
|
86
|
+
}>;
|
|
87
|
+
integer: () => ColumnBuilder<{
|
|
88
|
+
type: "INTEGER";
|
|
89
|
+
schema: std.Schema<number, number>;
|
|
90
|
+
}>;
|
|
91
|
+
json: <S extends std.Schema>(schema: S) => ColumnBuilder<{
|
|
92
|
+
type: "JSON";
|
|
93
|
+
schema: S;
|
|
94
|
+
}>;
|
|
95
|
+
sequence: () => ColumnBuilder<{
|
|
96
|
+
type: "SEQUENCE";
|
|
97
|
+
schema: std.Schema<number, number>;
|
|
98
|
+
generated: true;
|
|
99
|
+
}>;
|
|
100
|
+
string: ({ size }?: {
|
|
101
|
+
size?: number;
|
|
102
|
+
}) => ColumnBuilder<{
|
|
103
|
+
type: "STRING";
|
|
104
|
+
schema: std.Schema<string, string>;
|
|
105
|
+
length: number;
|
|
106
|
+
}>;
|
|
107
|
+
text: () => ColumnBuilder<{
|
|
108
|
+
type: "TEXT";
|
|
109
|
+
schema: std.Schema<string, string>;
|
|
110
|
+
}>;
|
|
111
|
+
uuid: () => ColumnBuilder<{
|
|
112
|
+
type: "UUID";
|
|
113
|
+
schema: std.Schema<string, string>;
|
|
114
|
+
}>;
|
|
115
|
+
};
|
|
116
|
+
type Columns = Record<string, Column>;
|
|
117
|
+
type Table<N extends string = string, C extends Columns = Columns> = {
|
|
118
|
+
name: N;
|
|
119
|
+
alias: string;
|
|
120
|
+
columns: C;
|
|
121
|
+
};
|
|
122
|
+
type OmitOnInsert = {
|
|
123
|
+
generated: true;
|
|
124
|
+
};
|
|
125
|
+
type OptionalOnInsert = {
|
|
126
|
+
default: unknown;
|
|
127
|
+
} | {
|
|
128
|
+
nullable: true;
|
|
129
|
+
};
|
|
130
|
+
type OmitOnUpdate = {
|
|
131
|
+
generated: true;
|
|
132
|
+
} | {
|
|
133
|
+
primaryKey: true;
|
|
134
|
+
};
|
|
135
|
+
type NumericType = 'BIGINT' | 'DECIMAL' | 'FLOAT' | 'INTEGER';
|
|
136
|
+
type Infer<C extends Columns> = Expand<{
|
|
137
|
+
[K in keyof C]: C[K]['output'];
|
|
138
|
+
}>;
|
|
139
|
+
type InferForInsert<C extends Columns> = Expand<{
|
|
140
|
+
[K in keyof C as C[K] extends OmitOnInsert | OptionalOnInsert ? never : K]: C[K]['input'];
|
|
141
|
+
} & {
|
|
142
|
+
[K in keyof C as C[K] extends OmitOnInsert ? never : C[K] extends OptionalOnInsert ? K : never]?: C[K]['input'];
|
|
143
|
+
}>;
|
|
144
|
+
type InferForUpdate<C extends Columns> = Expand<{
|
|
145
|
+
[K in keyof C as C[K] extends OmitOnUpdate ? never : K]?: C[K]['input'];
|
|
146
|
+
}>;
|
|
147
|
+
type NumericKeys<C extends Columns> = {
|
|
148
|
+
[K in keyof C]: C[K] extends OmitOnUpdate ? never : C[K]['type'] extends NumericType ? K : never;
|
|
149
|
+
}[keyof C];
|
|
150
|
+
type DefinedTable<N extends string, C extends Columns> = Table<N, C> & {
|
|
151
|
+
as: (alias: string) => DefinedTable<N, C>;
|
|
152
|
+
infer: Infer<C>;
|
|
153
|
+
inferForInsert: InferForInsert<C>;
|
|
154
|
+
inferForUpdate: InferForUpdate<C>;
|
|
155
|
+
};
|
|
156
|
+
declare const defineTable: <N extends string, S extends Record<string, ColumnBuilder<ColumnProps>>>(name: N, shapeFn: (t: typeof types) => S) => DefinedTable<N, { [K in keyof S & string as CamelCase<K>]: Column<CamelCase<K>, S[K]['props']>; }>;
|
|
157
|
+
type Codec = {
|
|
158
|
+
encode: (value: any) => unknown;
|
|
159
|
+
decode: (value: any) => unknown;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Everything that differs between database engines. SQL generation, param
|
|
163
|
+
* collection, validation and encoding/decoding all live in the core.
|
|
164
|
+
*
|
|
165
|
+
* `generated` returns the DDL that makes the database generate the column's
|
|
166
|
+
* value, or `undefined` when the database can't natively, in which case the
|
|
167
|
+
* value is generated client-side on insert.
|
|
168
|
+
*/
|
|
169
|
+
type DialectName = 'postgres' | 'sqlite' | (string & {});
|
|
170
|
+
interface Dialect {
|
|
171
|
+
name: DialectName;
|
|
172
|
+
placeholder(index: number): string;
|
|
173
|
+
type(column: Column): string;
|
|
174
|
+
generated(column: Column): string | undefined;
|
|
175
|
+
codecs: Record<Primitive, Codec>;
|
|
176
|
+
}
|
|
177
|
+
interface ILogger {
|
|
178
|
+
debug(sql: string, params: unknown[]): void;
|
|
179
|
+
error(sql: string, params: unknown[], error: unknown): void;
|
|
180
|
+
}
|
|
181
|
+
type Row = Record<string, unknown>;
|
|
182
|
+
interface IDatabase {
|
|
183
|
+
readonly dialect: Dialect;
|
|
184
|
+
readonly loggers: ILogger[];
|
|
185
|
+
execute(sql: string, params: unknown[]): Promise<Row[]>;
|
|
186
|
+
transaction<T>(fn: (tx: IDatabase) => Promise<T>): Promise<T>;
|
|
187
|
+
}
|
|
188
|
+
declare const exec: (db: IDatabase, sql: string, params?: unknown[]) => Promise<void>;
|
|
189
|
+
type Op = '=' | '!=' | '<' | '<=' | '>' | '>=' | 'like' | 'not like' | 'in' | 'not in' | 'is' | 'is not';
|
|
190
|
+
type ValueFor<V, O extends Op> = O extends 'is' | 'is not' ? null : O extends 'in' | 'not in' ? NonNullable<V>[] : O extends 'like' | 'not like' ? string : NonNullable<V>;
|
|
191
|
+
type ExprNode = {
|
|
192
|
+
key: string;
|
|
193
|
+
op: Op;
|
|
194
|
+
value: unknown;
|
|
195
|
+
} | {
|
|
196
|
+
group: 'AND' | 'OR';
|
|
197
|
+
exprs: ExprNode[];
|
|
198
|
+
};
|
|
199
|
+
declare const COLUMNS: unique symbol;
|
|
200
|
+
type Expr<C extends Columns> = ExprNode & {
|
|
201
|
+
readonly [COLUMNS]?: (columns: C) => C;
|
|
202
|
+
};
|
|
203
|
+
declare const expr: (<C extends Columns, K extends keyof C & string, O extends Op>(key: K, op: O, value: ValueFor<C[K]['output'], O>) => Expr<C>) & {
|
|
204
|
+
and: <C extends Columns>(exprs: Expr<C>[]) => Expr<C>;
|
|
205
|
+
or: <C extends Columns>(exprs: Expr<C>[]) => Expr<C>;
|
|
206
|
+
};
|
|
207
|
+
type Condition = {
|
|
208
|
+
col: Column;
|
|
209
|
+
op: Op;
|
|
210
|
+
value: unknown;
|
|
211
|
+
} | {
|
|
212
|
+
group: 'AND' | 'OR';
|
|
213
|
+
conditions: Condition[];
|
|
214
|
+
};
|
|
215
|
+
type Changes<C extends Columns> = {
|
|
216
|
+
set?: InferForUpdate<C>;
|
|
217
|
+
inc?: {
|
|
218
|
+
[K in NumericKeys<C>]?: number;
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
type Conflict<C extends Columns> = {
|
|
222
|
+
on: (keyof C & string)[];
|
|
223
|
+
do: 'nothing' | 'throw' | (Changes<C> & {
|
|
224
|
+
replace?: (keyof InferForUpdate<C> & string)[];
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
type InsertOptions<C extends Columns> = {
|
|
228
|
+
conflict?: Conflict<C>;
|
|
229
|
+
};
|
|
230
|
+
declare class InsertBuilder<T extends Table> {
|
|
231
|
+
private readonly table;
|
|
232
|
+
private readonly rows;
|
|
233
|
+
constructor(table: T, rows?: InferForInsert<T['columns']>[]);
|
|
234
|
+
values(rows: InferForInsert<T['columns']> | InferForInsert<T['columns']>[]): InsertBuilder<T>;
|
|
235
|
+
insert(db: IDatabase, options?: InsertOptions<T['columns']> & {
|
|
236
|
+
returning?: true;
|
|
237
|
+
}): Promise<Infer<T['columns']>[]>;
|
|
238
|
+
insert(db: IDatabase, options: InsertOptions<T['columns']> & {
|
|
239
|
+
returning: false;
|
|
240
|
+
}): Promise<undefined>;
|
|
241
|
+
insert<K extends keyof T['columns'] & string>(db: IDatabase, options: InsertOptions<T['columns']> & {
|
|
242
|
+
returning: K[];
|
|
243
|
+
}): Promise<Expand<Pick<Infer<T['columns']>, K>>[]>;
|
|
244
|
+
private renderConflict;
|
|
245
|
+
}
|
|
246
|
+
declare const into: <T extends Table>(table: T) => InsertBuilder<T>;
|
|
247
|
+
type Direction = 'ASC' | 'DESC';
|
|
248
|
+
type Query<T extends Table> = {
|
|
249
|
+
table: T;
|
|
250
|
+
select?: string[];
|
|
251
|
+
where: Condition[];
|
|
252
|
+
orderBy: [Column, Direction][];
|
|
253
|
+
limit?: number;
|
|
254
|
+
offset?: number;
|
|
255
|
+
};
|
|
256
|
+
type Keys<T extends Table> = keyof T['columns'] & string;
|
|
257
|
+
declare class QueryBuilder<T extends Table, S extends Keys<T> = Keys<T>> {
|
|
258
|
+
private readonly query;
|
|
259
|
+
constructor(query: Query<T>);
|
|
260
|
+
select<K extends Keys<T>>(keys: K[]): QueryBuilder<T, K>;
|
|
261
|
+
where<K extends Keys<T>, O extends Op>(key: K, op: O, value: ValueFor<T['columns'][K]['output'], O>): QueryBuilder<T, S>;
|
|
262
|
+
where(expr: Expr<T['columns']>): QueryBuilder<T, S>;
|
|
263
|
+
orderBy(keys: (Keys<T> | [Keys<T>, Direction])[]): QueryBuilder<T, S>;
|
|
264
|
+
limit(n: number): QueryBuilder<T, S>;
|
|
265
|
+
offset(n: number): QueryBuilder<T, S>;
|
|
266
|
+
all(db: IDatabase): Promise<Expand<Pick<Expand<T["columns"] extends infer T_1 extends Columns ? { [K in keyof T_1]: T_1[K]["output"]; } : never>, S>>[]>;
|
|
267
|
+
one(db: IDatabase): Promise<Expand<Pick<Expand<T["columns"] extends infer T_1 extends Columns ? { [K in keyof T_1]: T_1[K]["output"]; } : never>, S>>>;
|
|
268
|
+
exists(db: IDatabase): Promise<boolean>;
|
|
269
|
+
count(db: IDatabase): Promise<number>;
|
|
270
|
+
update(db: IDatabase, changes: Changes<T['columns']> & {
|
|
271
|
+
returning: false;
|
|
272
|
+
}): Promise<undefined>;
|
|
273
|
+
update<K extends keyof T['columns'] & string>(db: IDatabase, changes: Changes<T['columns']> & {
|
|
274
|
+
returning: K[];
|
|
275
|
+
}): Promise<Expand<Pick<Infer<T['columns']>, K>>[]>;
|
|
276
|
+
update(db: IDatabase, changes: Changes<T['columns']> & {
|
|
277
|
+
returning?: true;
|
|
278
|
+
}): Promise<Infer<T['columns']>[]>;
|
|
279
|
+
delete(db: IDatabase, options: {
|
|
280
|
+
returning: true;
|
|
281
|
+
}): Promise<Infer<T['columns']>[]>;
|
|
282
|
+
delete<K extends keyof T['columns'] & string>(db: IDatabase, options: {
|
|
283
|
+
returning: K[];
|
|
284
|
+
}): Promise<Expand<Pick<Infer<T['columns']>, K>>[]>;
|
|
285
|
+
delete(db: IDatabase, options?: {
|
|
286
|
+
returning?: false;
|
|
287
|
+
}): Promise<undefined>;
|
|
288
|
+
private renderSelect;
|
|
289
|
+
private top;
|
|
290
|
+
private assertUnbounded;
|
|
291
|
+
}
|
|
292
|
+
declare const from: <T extends Table>(table: T) => QueryBuilder<T, Keys<T>>;
|
|
293
|
+
type IndexOptions = {
|
|
294
|
+
ifNotExists?: boolean;
|
|
295
|
+
name?: string;
|
|
296
|
+
};
|
|
297
|
+
declare const createIndex: <T extends Table>(table: T, keys: (keyof T['columns'] & string)[], { ifNotExists, name, unique, }?: IndexOptions & {
|
|
298
|
+
unique?: boolean;
|
|
299
|
+
}) => {
|
|
300
|
+
onto: (db: IDatabase) => Promise<void>;
|
|
301
|
+
};
|
|
302
|
+
declare const create: {
|
|
303
|
+
table: (table: Table, { ifNotExists }?: {
|
|
304
|
+
ifNotExists?: boolean;
|
|
305
|
+
}) => {
|
|
306
|
+
onto: (db: IDatabase) => Promise<void>;
|
|
307
|
+
};
|
|
308
|
+
index: typeof createIndex;
|
|
309
|
+
uniqueIndex: <T extends Table>(table: T, keys: (keyof T['columns'] & string)[], options?: IndexOptions) => {
|
|
310
|
+
onto: (db: IDatabase) => Promise<void>;
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
type Migration = (db: IDatabase) => Promise<void>;
|
|
314
|
+
declare const defineMigrations: (migrations: Record<string, Migration>) => (db: IDatabase) => Promise<void>;
|
|
315
|
+
export { type Codec, type Column, type ColumnProps, type Dialect, type DialectName, type Expr, type IDatabase, type ILogger, type Migration, type Primitive, type Row, type Table, ValidationError, column, create, defineMigrations, defineTable as table, exec, expr, from, into, types as t, };
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
2
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
3
|
+
}
|
|
4
|
+
declare namespace StandardSchemaV1 {
|
|
5
|
+
export interface Props<Input = unknown, Output = Input> {
|
|
6
|
+
readonly version: 1;
|
|
7
|
+
readonly vendor: string;
|
|
8
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
9
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
10
|
+
}
|
|
11
|
+
export type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
12
|
+
export interface SuccessResult<Output> {
|
|
13
|
+
readonly value: Output;
|
|
14
|
+
readonly issues?: undefined;
|
|
15
|
+
}
|
|
16
|
+
export interface FailureResult {
|
|
17
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
18
|
+
}
|
|
19
|
+
export interface Issue {
|
|
20
|
+
readonly message: string;
|
|
21
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
22
|
+
}
|
|
23
|
+
export interface PathSegment {
|
|
24
|
+
readonly key: PropertyKey;
|
|
25
|
+
}
|
|
26
|
+
export interface Types<Input = unknown, Output = Input> {
|
|
27
|
+
readonly input: Input;
|
|
28
|
+
readonly output: Output;
|
|
29
|
+
}
|
|
30
|
+
export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
31
|
+
export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
32
|
+
export {};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @public The Standard Schema interface.
|
|
36
|
+
* @since 0.1.0
|
|
37
|
+
* @version 1
|
|
38
|
+
*/
|
|
39
|
+
export { type StandardSchemaV1 as Schema };
|
|
40
|
+
/**
|
|
41
|
+
* @public Infers the input type of a Standard Schema.
|
|
42
|
+
* @since 0.1.0
|
|
43
|
+
* @version 1
|
|
44
|
+
*/
|
|
45
|
+
export type input<T extends StandardSchemaV1> = StandardSchemaV1.InferInput<T>;
|
|
46
|
+
/**
|
|
47
|
+
* @public Infers the output type of a Standard Schema.
|
|
48
|
+
* @since 0.1.0
|
|
49
|
+
* @version 1
|
|
50
|
+
*/
|
|
51
|
+
export type output<T extends StandardSchemaV1> = StandardSchemaV1.InferOutput<T>;
|
|
52
|
+
/**
|
|
53
|
+
* @public Thrown when a value fails validation, carrying every issue found.
|
|
54
|
+
* @since 0.1.0
|
|
55
|
+
* @version 1
|
|
56
|
+
*/
|
|
57
|
+
export declare class ValidationError extends Error {
|
|
58
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
59
|
+
constructor(issues: ReadonlyArray<StandardSchemaV1.Issue>);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @public Use any standard schema to parse a value.
|
|
63
|
+
* @since 0.1.0
|
|
64
|
+
* @version 1
|
|
65
|
+
*/
|
|
66
|
+
export declare const parse: <T extends StandardSchemaV1>(schema: T, value: unknown) => StandardSchemaV1.Result<output<T>>;
|
|
67
|
+
/**
|
|
68
|
+
* @public Like {@link parse}, but returns the value or throws a
|
|
69
|
+
* {@link ValidationError}.
|
|
70
|
+
* @since 0.1.0
|
|
71
|
+
* @version 1
|
|
72
|
+
*/
|
|
73
|
+
export declare const parseOrThrow: <T extends StandardSchemaV1>(schema: T, value: unknown) => output<T>;
|
|
74
|
+
/**
|
|
75
|
+
* @public Defines an array of a given standard schema.
|
|
76
|
+
* @since 0.1.0
|
|
77
|
+
* @version 1
|
|
78
|
+
*/
|
|
79
|
+
export declare const array: <T extends StandardSchemaV1>(schema: T) => StandardSchemaV1<input<T>[], output<T>[]>;
|
|
80
|
+
/**
|
|
81
|
+
* @public Defines a standard schema for bigints.
|
|
82
|
+
* @since 0.1.0
|
|
83
|
+
* @version 1
|
|
84
|
+
*/
|
|
85
|
+
export declare const bigint: () => StandardSchemaV1<bigint, bigint>;
|
|
86
|
+
/**
|
|
87
|
+
* @public Defines a standard schema for boolean values.
|
|
88
|
+
* @since 0.1.0
|
|
89
|
+
* @version 1
|
|
90
|
+
*/
|
|
91
|
+
export declare const boolean: () => StandardSchemaV1<boolean, boolean>;
|
|
92
|
+
/**
|
|
93
|
+
* @public Defines a standard schema for dates, coercing ISO 8601 strings
|
|
94
|
+
* and epoch timestamps (in milliseconds) into `Date`.
|
|
95
|
+
* @since 0.1.0
|
|
96
|
+
* @version 1
|
|
97
|
+
*/
|
|
98
|
+
export declare const date: () => StandardSchemaV1<string | number | Date, Date>;
|
|
99
|
+
/**
|
|
100
|
+
* @public Defines a standard schema for one of the given string values.
|
|
101
|
+
* @since 0.1.0
|
|
102
|
+
* @version 1
|
|
103
|
+
*/
|
|
104
|
+
export declare const enumOf: <const T extends readonly string[]>(values: T) => StandardSchemaV1<T[number], T[number]>;
|
|
105
|
+
/**
|
|
106
|
+
* @public Defines a standard schema for instances of a given class.
|
|
107
|
+
* @since 0.1.0
|
|
108
|
+
* @version 1
|
|
109
|
+
*/
|
|
110
|
+
export declare const instanceOf: <T>(ctor: new (...args: any[]) => T) => StandardSchemaV1<T, T>;
|
|
111
|
+
/**
|
|
112
|
+
* @public Defines a standard schema for integers, within the safe integer
|
|
113
|
+
* range by default.
|
|
114
|
+
* @since 0.1.0
|
|
115
|
+
* @version 1
|
|
116
|
+
*/
|
|
117
|
+
export declare const integer: ({ min, max }?: {
|
|
118
|
+
max?: number | undefined;
|
|
119
|
+
min?: number | undefined;
|
|
120
|
+
}) => StandardSchemaV1<number, number>;
|
|
121
|
+
/**
|
|
122
|
+
* @public Defines a standard schema for calendar dates as `YYYY-MM-DD`
|
|
123
|
+
* strings.
|
|
124
|
+
* @since 0.1.0
|
|
125
|
+
* @version 1
|
|
126
|
+
*/
|
|
127
|
+
export declare const isoDate: () => StandardSchemaV1<string, string>;
|
|
128
|
+
/**
|
|
129
|
+
* @public Makes a given standard schema accept `null`.
|
|
130
|
+
* @since 0.1.0
|
|
131
|
+
* @version 1
|
|
132
|
+
*/
|
|
133
|
+
export declare const nullable: <T extends StandardSchemaV1>(schema: T) => StandardSchemaV1<input<T> | null, output<T> | null>;
|
|
134
|
+
/**
|
|
135
|
+
* @public Defines a standard schema for finite numbers.
|
|
136
|
+
* @since 0.1.0
|
|
137
|
+
* @version 1
|
|
138
|
+
*/
|
|
139
|
+
export declare const number: () => StandardSchemaV1<number, number>;
|
|
140
|
+
/**
|
|
141
|
+
* @public Makes a given standard schema accept `undefined`.
|
|
142
|
+
* @since 0.1.0
|
|
143
|
+
* @version 1
|
|
144
|
+
*/
|
|
145
|
+
export declare const optional: <T extends StandardSchemaV1>(schema: T) => StandardSchemaV1<input<T> | undefined, output<T> | undefined>;
|
|
146
|
+
/**
|
|
147
|
+
* @public Defines a standard schema for strings, optionally limited in
|
|
148
|
+
* length.
|
|
149
|
+
* @since 0.1.0
|
|
150
|
+
* @version 1
|
|
151
|
+
*/
|
|
152
|
+
export declare const string: ({ max }?: {
|
|
153
|
+
max?: number;
|
|
154
|
+
}) => StandardSchemaV1<string, string>;
|
|
155
|
+
/**
|
|
156
|
+
* @public Defines a standard schema for objects of a given shape. Keys
|
|
157
|
+
* missing from the shape are rejected, keys missing from the input
|
|
158
|
+
* are validated as `undefined`.
|
|
159
|
+
* @since 0.1.0
|
|
160
|
+
* @version 1
|
|
161
|
+
*/
|
|
162
|
+
type Expand<T> = T extends object ? {
|
|
163
|
+
[K in keyof T]: T[K];
|
|
164
|
+
} : never;
|
|
165
|
+
type OptionalKeys<T extends Record<string, StandardSchemaV1>> = {
|
|
166
|
+
[K in keyof T]: undefined extends input<T[K]> ? K : never;
|
|
167
|
+
}[keyof T];
|
|
168
|
+
export declare const strictObject: <T extends Record<string, StandardSchemaV1>>(shape: T) => StandardSchemaV1<Expand<{ [K in Exclude<keyof T, OptionalKeys<T>>]: input<T[K]>; } & { [K in OptionalKeys<T>]?: input<T[K]> | undefined; }>, Expand<{ [K in Exclude<keyof T, OptionalKeys<T>>]: output<T[K]>; } & { [K in OptionalKeys<T>]?: output<T[K]> | undefined; }>>;
|
|
169
|
+
/**
|
|
170
|
+
* @public Defines a standard schema for UUID strings (any version).
|
|
171
|
+
* @since 0.1.0
|
|
172
|
+
* @version 1
|
|
173
|
+
*/
|
|
174
|
+
export declare const uuid: () => StandardSchemaV1<string, string>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type Ctor<T> = new (...args: any[]) => T;
|
|
2
|
+
export type Expand<T> = T extends object ? {
|
|
3
|
+
[K in keyof T]: T[K];
|
|
4
|
+
} : never;
|
|
5
|
+
export type CamelCase<S extends string> = S extends `${infer T}_${infer U}` ? `${T}${Capitalize<CamelCase<U>>}` : S;
|
|
6
|
+
export declare const camelCase: <T extends string>(str: T) => CamelCase<T>;
|
|
7
|
+
export declare const snakeCase: (str: string) => string;
|
|
8
|
+
export declare const wrap: <T>(value: T | T[]) => T[];
|
|
9
|
+
export declare function raise(message: string, cause?: Error): never;
|
|
10
|
+
export declare function raise(ctor: Ctor<Error>, message: string, cause?: Error): never;
|
|
11
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rwillians/exto",
|
|
3
3
|
"description": "A zero-dependencies teeny tiny ORM for SQL databases.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"author": "Rafael Willians <me@rwillians.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"publishConfig": {
|
|
@@ -12,17 +12,17 @@
|
|
|
12
12
|
"url": "git://github.com/rwillians/exto.git"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
|
-
"query",
|
|
16
15
|
"builder",
|
|
17
|
-
"
|
|
16
|
+
"bun",
|
|
17
|
+
"orm",
|
|
18
18
|
"postgres",
|
|
19
|
+
"query builder",
|
|
20
|
+
"query",
|
|
19
21
|
"sql",
|
|
20
22
|
"sqlite",
|
|
21
|
-
"typescript",
|
|
22
23
|
"type-safe",
|
|
23
24
|
"type-safety",
|
|
24
|
-
"
|
|
25
|
-
"bun"
|
|
25
|
+
"typescript"
|
|
26
26
|
],
|
|
27
27
|
"type": "module",
|
|
28
28
|
"module": "dist/esm/index.js",
|
package/dist/.gitignore
DELETED