alepha 0.6.7 → 0.6.8

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/postgres.d.ts CHANGED
@@ -1 +1,1452 @@
1
- export * from '@alepha/postgres';
1
+ import * as _alepha_core from '@alepha/core';
2
+ import { TObject as TObject$1, Static as Static$1, Alepha, KIND, OPTIONS } from '@alepha/core';
3
+ import * as _sinclair_typebox from '@sinclair/typebox';
4
+ import { TObject, Static, TSchema, ObjectOptions, Kind, TProperties, Evaluate, TReadonly, TOptional, TAdditionalProperties, OptionalKind, TArray, TIntersect, TBoolean, TInteger, IntegerOptions, StringOptions, TOptionalWithFlag } from '@sinclair/typebox';
5
+ import * as drizzle_orm from 'drizzle-orm';
6
+ import { TableConfig, SQLWrapper, SQL, BuildColumns } from 'drizzle-orm';
7
+ export { sql } from 'drizzle-orm';
8
+ import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
9
+ import { PgSequenceOptions, AnyPgTable, AnyPgColumn, UpdateDeleteAction, PgTableExtraConfigValue, PgTableWithColumns, PgColumnBuilderBase, PgDatabase, TableConfig as TableConfig$1, PgColumn, PgTransaction, PgTransactionConfig, LockStrength, LockConfig, PgInsertValue, PgSelectJoinFn } from 'drizzle-orm/pg-core';
10
+ export * from 'drizzle-orm/pg-core';
11
+ import { PgTransactionConfig as PgTransactionConfig$1 } from 'drizzle-orm/pg-core/session';
12
+ import { BuildExtraConfigColumns } from 'drizzle-orm/column-builder';
13
+ import { PgTableExtraConfigValue as PgTableExtraConfigValue$1 } from 'drizzle-orm/pg-core/table';
14
+ import * as _alepha_lock from '@alepha/lock';
15
+ import { MigrationConfig } from 'drizzle-orm/migrator';
16
+ import { NodePgDatabase } from 'drizzle-orm/node-postgres';
17
+ import pg$1, { ClientConfig } from 'pg';
18
+ import { UpdateDeleteAction as UpdateDeleteAction$1 } from 'drizzle-orm/pg-core/foreign-keys';
19
+
20
+ /**
21
+ *
22
+ */
23
+ declare const PG_SCHEMA: unique symbol;
24
+
25
+ declare const PG_DEFAULT: unique symbol;
26
+ declare const PG_PRIMARY_KEY: unique symbol;
27
+ declare const PG_CREATED_AT: unique symbol;
28
+ declare const PG_UPDATED_AT: unique symbol;
29
+ declare const PG_VERSION: unique symbol;
30
+ declare const PG_IDENTITY: unique symbol;
31
+ declare const PG_SERIAL: unique symbol;
32
+ declare const PG_MANY: unique symbol;
33
+ declare const PG_ONE: unique symbol;
34
+ declare const PG_REF: unique symbol;
35
+ type PgDefault = typeof PG_DEFAULT;
36
+ type PgMany = typeof PG_MANY;
37
+ type PgRef = typeof PG_REF;
38
+ type PgPrimaryKey = typeof PG_PRIMARY_KEY;
39
+ type PgSymbols = {
40
+ [PG_DEFAULT]: {};
41
+ [PG_PRIMARY_KEY]: {};
42
+ [PG_CREATED_AT]: {};
43
+ [PG_UPDATED_AT]: {};
44
+ [PG_VERSION]: {};
45
+ [PG_IDENTITY]: PgIdentityOptions;
46
+ [PG_SERIAL]: {};
47
+ [PG_MANY]: PgManyOptions;
48
+ [PG_ONE]: PgManyOptions;
49
+ [PG_REF]: PgRefOptions;
50
+ };
51
+ type PgSymbolKeys = keyof PgSymbols;
52
+ type PgIdentityOptions = {
53
+ mode: "always" | "byDefault";
54
+ } & PgSequenceOptions & {
55
+ name?: string;
56
+ };
57
+ interface PgManyOptions {
58
+ table: AnyPgTable;
59
+ schema: TObject;
60
+ foreignKey: string;
61
+ }
62
+ interface PgRefOptions {
63
+ ref: () => AnyPgColumn;
64
+ actions?: {
65
+ onUpdate?: UpdateDeleteAction;
66
+ onDelete?: UpdateDeleteAction;
67
+ };
68
+ }
69
+
70
+ interface EntityDescriptorOptions<T extends TObject, Keys = keyof Static<T>> {
71
+ name: string;
72
+ schema: T;
73
+ indexes?: (Keys | {
74
+ column: Keys;
75
+ unique?: boolean;
76
+ name?: string;
77
+ })[];
78
+ foreignKeys?: {
79
+ columns: Keys[];
80
+ foreignTable: string;
81
+ foreignColumns: Keys[];
82
+ onUpdate?: "cascade" | "restrict" | "no action" | "set null" | "set default";
83
+ onDelete?: "cascade" | "restrict" | "no action" | "set null" | "set default";
84
+ }[];
85
+ config?: PgTableExtraConfigValue[];
86
+ }
87
+ /**
88
+ * Creates a table descriptor for drizzle-orm.
89
+ */
90
+ declare const $entity: <T extends TObject>(options: EntityDescriptorOptions<T>) => PgTableWithColumnsAndSchema<PgTableConfig<string, T, FromSchema<T>>, T>;
91
+
92
+ /**
93
+ * Convert a schema to columns.
94
+ *
95
+ * @param schema
96
+ */
97
+ declare const schemaToColumns: <T extends TObject$1>(schema: T) => FromSchema<T>;
98
+ declare const fromSchema: <T extends TObject$1>(schema: T) => FromSchema<T>;
99
+ /**
100
+ * Convert a schema to columns.
101
+ */
102
+ type FromSchema<T extends TObject$1> = {
103
+ [key in keyof T["properties"]]: PgColumnBuilderBase;
104
+ };
105
+ /**
106
+ * The symbol for the schema.
107
+ */
108
+ /**
109
+ * A table with columns and schema.
110
+ */
111
+ type PgTableWithColumnsAndSchema<T extends TableConfig, R extends TObject$1> = PgTableWithColumns<T> & {
112
+ [PG_SCHEMA]: R;
113
+ };
114
+
115
+ type SQLLike = SQLWrapper | string;
116
+ declare class PostgresProvider {
117
+ /**
118
+ * Get the database instance
119
+ */
120
+ get db(): PgDatabase<any>;
121
+ get schema(): string;
122
+ get dialect(): string;
123
+ execute(query: SQLLike): Promise<any[]>;
124
+ }
125
+
126
+ /**
127
+ * Fork of the original typebox schema "TObject".
128
+ *
129
+ * Expect some breaking changes in the future...
130
+ */
131
+ interface TInsertObject<T extends TObject> extends TSchema, ObjectOptions {
132
+ [Kind]: "Object";
133
+ static: ObjectStatic<T["properties"], this["params"]>;
134
+ additionalProperties?: TAdditionalProperties;
135
+ type: "object";
136
+ required?: string[];
137
+ properties: {
138
+ [K in keyof T["properties"] as T["properties"][K] extends {
139
+ [PG_DEFAULT]: any;
140
+ } ? never : K]: T["properties"][K];
141
+ };
142
+ }
143
+ type ReadonlyOptionalPropertyKeys<T extends TProperties> = {
144
+ [K in keyof T]: T[K] extends TReadonly<TSchema> ? T[K] extends TOptional<T[K]> ? K : never : never;
145
+ }[keyof T];
146
+ type ReadonlyPropertyKeys<T extends TProperties> = {
147
+ [K in keyof T]: T[K] extends TReadonly<TSchema> ? T[K] extends TOptional<T[K]> ? never : K : never;
148
+ }[keyof T];
149
+ type OptionalPropertyKeys<T extends TProperties> = {
150
+ [K in keyof T]: T[K] extends TOptional<TSchema> ? T[K] extends TReadonly<T[K]> ? never : K : never;
151
+ }[keyof T];
152
+ type RequiredPropertyKeys<T extends TProperties> = keyof Omit<T, ReadonlyOptionalPropertyKeys<T> | ReadonlyPropertyKeys<T> | OptionalPropertyKeys<T>>;
153
+ type ObjectStaticProperties<T extends TProperties, R extends Record<keyof any, unknown>> = Evaluate<Readonly<Partial<Pick<R, ReadonlyOptionalPropertyKeys<T>>>> & Readonly<Pick<R, ReadonlyPropertyKeys<T>>> & Partial<Pick<R, OptionalPropertyKeys<T>>> & Required<Pick<R, RequiredPropertyKeys<T>>>>;
154
+ type ObjectStatic<T extends TProperties, P extends unknown[]> = ObjectStaticProperties<T, {
155
+ [K in keyof T]: Static<T[K], P>;
156
+ }>;
157
+
158
+ /**
159
+ * Replaces all null values in an object with undefined.
160
+ *
161
+ * @param value - The object to be processed.
162
+ * @return A new object with all null values replaced with undefined.
163
+ */
164
+ declare const nullToUndefined: <T extends object>(value: T) => NullToUndefined<T>;
165
+ /**
166
+ * Replaces all null values in an object with undefined.
167
+ */
168
+ type NullToUndefined<T> = T extends null ? undefined : T extends null | undefined | string | number | boolean | symbol | bigint | Function | Date | RegExp ? T : T extends Array<infer U> ? Array<NullToUndefined<U>> : T extends Map<infer K, infer V> ? Map<K, NullToUndefined<V>> : T extends Set<infer U> ? Set<NullToUndefined<U>> : T extends object ? {
169
+ [K in keyof T]: NullToUndefined<T[K]>;
170
+ } : unknown;
171
+ /**
172
+ *
173
+ */
174
+ type NullifyIfOptional<T> = {
175
+ [K in keyof T]: undefined extends T[K] ? T[K] | null : T[K];
176
+ };
177
+
178
+ interface FilterOperators<TValue> {
179
+ /**
180
+ * Test that two values are equal.
181
+ *
182
+ * Remember that the SQL standard dictates that
183
+ * two NULL values are not equal, so if you want to test
184
+ * whether a value is null, you may want to use
185
+ * `isNull` instead.
186
+ *
187
+ * ## Examples
188
+ *
189
+ * ```ts
190
+ * // Select cars made by Ford
191
+ * db.select().from(cars)
192
+ * .where(eq(cars.make, 'Ford'))
193
+ * ```
194
+ *
195
+ * @see isNull for a way to test equality to NULL.
196
+ */
197
+ eq?: TValue;
198
+ /**
199
+ * Test that two values are not equal.
200
+ *
201
+ * Remember that the SQL standard dictates that
202
+ * two NULL values are not equal, so if you want to test
203
+ * whether a value is not null, you may want to use
204
+ * `isNotNull` instead.
205
+ *
206
+ * ## Examples
207
+ *
208
+ * ```ts
209
+ * // Select cars not made by Ford
210
+ * db.select().from(cars)
211
+ * .where(ne(cars.make, 'Ford'))
212
+ * ```
213
+ *
214
+ * @see isNotNull for a way to test whether a value is not null.
215
+ */
216
+ ne?: TValue;
217
+ /**
218
+ * Test that the first expression passed is greater than
219
+ * the second expression.
220
+ *
221
+ * ## Examples
222
+ *
223
+ * ```ts
224
+ * // Select cars made after 2000.
225
+ * db.select().from(cars)
226
+ * .where(gt(cars.year, 2000))
227
+ * ```
228
+ *
229
+ * @see gte for greater-than-or-equal
230
+ */
231
+ gt?: TValue;
232
+ /**
233
+ * Test that the first expression passed is greater than
234
+ * or equal to the second expression. Use `gt` to
235
+ * test whether an expression is strictly greater
236
+ * than another.
237
+ *
238
+ * ## Examples
239
+ *
240
+ * ```ts
241
+ * // Select cars made on or after 2000.
242
+ * db.select().from(cars)
243
+ * .where(gte(cars.year, 2000))
244
+ * ```
245
+ *
246
+ * @see gt for a strictly greater-than condition
247
+ */
248
+ gte?: TValue;
249
+ /**
250
+ * Test that the first expression passed is less than
251
+ * the second expression.
252
+ *
253
+ * ## Examples
254
+ *
255
+ * ```ts
256
+ * // Select cars made before 2000.
257
+ * db.select().from(cars)
258
+ * .where(lt(cars.year, 2000))
259
+ * ```
260
+ *
261
+ * @see lte for greater-than-or-equal
262
+ */
263
+ lt?: TValue;
264
+ /**
265
+ * Test that the first expression passed is less than
266
+ * or equal to the second expression.
267
+ *
268
+ * ## Examples
269
+ *
270
+ * ```ts
271
+ * // Select cars made before 2000.
272
+ * db.select().from(cars)
273
+ * .where(lte(cars.year, 2000))
274
+ * ```
275
+ *
276
+ * @see lt for a strictly less-than condition
277
+ */
278
+ lte?: TValue;
279
+ /**
280
+ * Test whether the first parameter, a column or expression,
281
+ * has a value from a list passed as the second argument.
282
+ *
283
+ * ## Throws
284
+ *
285
+ * The argument passed in the second array can't be empty:
286
+ * if an empty is provided, this method will throw.
287
+ *
288
+ * ## Examples
289
+ *
290
+ * ```ts
291
+ * // Select cars made by Ford or GM.
292
+ * db.select().from(cars)
293
+ * .where(inArray(cars.make, ['Ford', 'GM']))
294
+ * ```
295
+ *
296
+ * @see notInArray for the inverse of this test
297
+ */
298
+ inArray?: TValue[];
299
+ /**
300
+ * Test whether the first parameter, a column or expression,
301
+ * has a value that is not present in a list passed as the
302
+ * second argument.
303
+ *
304
+ * ## Throws
305
+ *
306
+ * The argument passed in the second array can't be empty:
307
+ * if an empty is provided, this method will throw.
308
+ *
309
+ * ## Examples
310
+ *
311
+ * ```ts
312
+ * // Select cars made by any company except Ford or GM.
313
+ * db.select().from(cars)
314
+ * .where(notInArray(cars.make, ['Ford', 'GM']))
315
+ * ```
316
+ *
317
+ * @see inArray for the inverse of this test
318
+ */
319
+ notInArray?: TValue[];
320
+ /**
321
+ * Test whether an expression is not NULL. By the SQL standard,
322
+ * NULL is neither equal nor not equal to itself, so
323
+ * it's recommended to use `isNull` and `notIsNull` for
324
+ * comparisons to NULL.
325
+ *
326
+ * ## Examples
327
+ *
328
+ * ```ts
329
+ * // Select cars that have been discontinued.
330
+ * db.select().from(cars)
331
+ * .where(isNotNull(cars.discontinuedAt))
332
+ * ```
333
+ *
334
+ * @see isNull for the inverse of this test
335
+ */
336
+ isNotNull?: true;
337
+ /**
338
+ * Test whether an expression is NULL. By the SQL standard,
339
+ * NULL is neither equal nor not equal to itself, so
340
+ * it's recommended to use `isNull` and `notIsNull` for
341
+ * comparisons to NULL.
342
+ *
343
+ * ## Examples
344
+ *
345
+ * ```ts
346
+ * // Select cars that have no discontinuedAt date.
347
+ * db.select().from(cars)
348
+ * .where(isNull(cars.discontinuedAt))
349
+ * ```
350
+ *
351
+ * @see isNotNull for the inverse of this test
352
+ */
353
+ isNull?: true;
354
+ /**
355
+ * Test whether an expression is between two values. This
356
+ * is an easier way to express range tests, which would be
357
+ * expressed mathematically as `x <= a <= y` but in SQL
358
+ * would have to be like `a >= x AND a <= y`.
359
+ *
360
+ * Between is inclusive of the endpoints: if `column`
361
+ * is equal to `min` or `max`, it will be TRUE.
362
+ *
363
+ * ## Examples
364
+ *
365
+ * ```ts
366
+ * // Select cars made between 1990 and 2000
367
+ * db.select().from(cars)
368
+ * .where(between(cars.year, 1990, 2000))
369
+ * ```
370
+ *
371
+ * @see notBetween for the inverse of this test
372
+ */
373
+ between?: [number, number];
374
+ /**
375
+ * Test whether an expression is not between two values.
376
+ *
377
+ * This, like `between`, includes its endpoints, so if
378
+ * the `column` is equal to `min` or `max`, in this case
379
+ * it will evaluate to FALSE.
380
+ *
381
+ * ## Examples
382
+ *
383
+ * ```ts
384
+ * // Exclude cars made in the 1970s
385
+ * db.select().from(cars)
386
+ * .where(notBetween(cars.year, 1970, 1979))
387
+ * ```
388
+ *
389
+ * @see between for the inverse of this test
390
+ */
391
+ notBetween?: [number, number];
392
+ /**
393
+ * Compare a column to a pattern, which can include `%` and `_`
394
+ * characters to match multiple variations. Including `%`
395
+ * in the pattern matches zero or more characters, and including
396
+ * `_` will match a single character.
397
+ *
398
+ * ## Examples
399
+ *
400
+ * ```ts
401
+ * // Select all cars with 'Turbo' in their names.
402
+ * db.select().from(cars)
403
+ * .where(like(cars.name, '%Turbo%'))
404
+ * ```
405
+ *
406
+ * @see ilike for a case-insensitive version of this condition
407
+ */
408
+ like?: string;
409
+ /**
410
+ * The inverse of like - this tests that a given column
411
+ * does not match a pattern, which can include `%` and `_`
412
+ * characters to match multiple variations. Including `%`
413
+ * in the pattern matches zero or more characters, and including
414
+ * `_` will match a single character.
415
+ *
416
+ * ## Examples
417
+ *
418
+ * ```ts
419
+ * // Select all cars that don't have "ROver" in their name.
420
+ * db.select().from(cars)
421
+ * .where(notLike(cars.name, '%Rover%'))
422
+ * ```
423
+ *
424
+ * @see like for the inverse condition
425
+ * @see notIlike for a case-insensitive version of this condition
426
+ */
427
+ notLike?: string;
428
+ /**
429
+ * Case-insensitively compare a column to a pattern,
430
+ * which can include `%` and `_`
431
+ * characters to match multiple variations. Including `%`
432
+ * in the pattern matches zero or more characters, and including
433
+ * `_` will match a single character.
434
+ *
435
+ * Unlike like, this performs a case-insensitive comparison.
436
+ *
437
+ * ## Examples
438
+ *
439
+ * ```ts
440
+ * // Select all cars with 'Turbo' in their names.
441
+ * db.select().from(cars)
442
+ * .where(ilike(cars.name, '%Turbo%'))
443
+ * ```
444
+ *
445
+ * @see like for a case-sensitive version of this condition
446
+ */
447
+ ilike?: string;
448
+ /**
449
+ * The inverse of ilike - this case-insensitively tests that a given column
450
+ * does not match a pattern, which can include `%` and `_`
451
+ * characters to match multiple variations. Including `%`
452
+ * in the pattern matches zero or more characters, and including
453
+ * `_` will match a single character.
454
+ *
455
+ * ## Examples
456
+ *
457
+ * ```ts
458
+ * // Select all cars that don't have "Rover" in their name.
459
+ * db.select().from(cars)
460
+ * .where(notLike(cars.name, '%Rover%'))
461
+ * ```
462
+ *
463
+ * @see ilike for the inverse condition
464
+ * @see notLike for a case-sensitive version of this condition
465
+ */
466
+ notIlike?: string;
467
+ /**
468
+ * Test that a column or expression contains all elements of
469
+ * the list passed as the second argument.
470
+ *
471
+ * ## Throws
472
+ *
473
+ * The argument passed in the second array can't be empty:
474
+ * if an empty is provided, this method will throw.
475
+ *
476
+ * ## Examples
477
+ *
478
+ * ```ts
479
+ * // Select posts where its tags contain "Typescript" and "ORM".
480
+ * db.select().from(posts)
481
+ * .where(arrayContains(posts.tags, ['Typescript', 'ORM']))
482
+ * ```
483
+ *
484
+ * @see arrayContained to find if an array contains all elements of a column or expression
485
+ * @see arrayOverlaps to find if a column or expression contains any elements of an array
486
+ */
487
+ arrayContains?: TValue;
488
+ /**
489
+ * Test that the list passed as the second argument contains
490
+ * all elements of a column or expression.
491
+ *
492
+ * ## Throws
493
+ *
494
+ * The argument passed in the second array can't be empty:
495
+ * if an empty is provided, this method will throw.
496
+ *
497
+ * ## Examples
498
+ *
499
+ * ```ts
500
+ * // Select posts where its tags contain "Typescript", "ORM" or both,
501
+ * // but filtering posts that have additional tags.
502
+ * db.select().from(posts)
503
+ * .where(arrayContained(posts.tags, ['Typescript', 'ORM']))
504
+ * ```
505
+ *
506
+ * @see arrayContains to find if a column or expression contains all elements of an array
507
+ * @see arrayOverlaps to find if a column or expression contains any elements of an array
508
+ */
509
+ arrayContained?: TValue;
510
+ /**
511
+ * Test that a column or expression contains any elements of
512
+ * the list passed as the second argument.
513
+ *
514
+ * ## Throws
515
+ *
516
+ * The argument passed in the second array can't be empty:
517
+ * if an empty is provided, this method will throw.
518
+ *
519
+ * ## Examples
520
+ *
521
+ * ```ts
522
+ * // Select posts where its tags contain "Typescript", "ORM" or both.
523
+ * db.select().from(posts)
524
+ * .where(arrayOverlaps(posts.tags, ['Typescript', 'ORM']))
525
+ * ```
526
+ *
527
+ * @see arrayContains to find if a column or expression contains all elements of an array
528
+ * @see arrayContained to find if an array contains all elements of a column or expression
529
+ */
530
+ arrayOverlaps?: TValue;
531
+ }
532
+
533
+ type InferInsert<T extends TObject> = StaticEntry<T> & StaticDefaultEntry<T>;
534
+ type StaticDefaultEntry<T extends TObject> = {
535
+ [K in keyof T["properties"] as T["properties"][K] extends {
536
+ [PG_DEFAULT]: any;
537
+ } | {
538
+ [OptionalKind]: "Optional";
539
+ } ? K : never]?: Static<T["properties"][K]>;
540
+ };
541
+ type StaticEntry<T extends TObject> = {
542
+ [K in keyof T["properties"] as T["properties"][K] extends {
543
+ [PG_DEFAULT]: any;
544
+ } | {
545
+ [OptionalKind]: "Optional";
546
+ } ? never : K]: Static<T["properties"][K]>;
547
+ };
548
+
549
+ type PgQueryWhere<T extends object> = {
550
+ [Key in keyof T]?: FilterOperators<T[Key]>;
551
+ } & {
552
+ /**
553
+ * Combine a list of conditions with the `and` operator. Conditions
554
+ * that are equal `undefined` are automatically ignored.
555
+ *
556
+ * ## Examples
557
+ *
558
+ * ```ts
559
+ * db.select().from(cars)
560
+ * .where(
561
+ * and(
562
+ * eq(cars.make, 'Volvo'),
563
+ * eq(cars.year, 1950),
564
+ * )
565
+ * )
566
+ * ```
567
+ */
568
+ and?: Array<PgQueryWhere<T> | SQL>;
569
+ /**
570
+ * Combine a list of conditions with the `or` operator. Conditions
571
+ * that are equal `undefined` are automatically ignored.
572
+ *
573
+ * ## Examples
574
+ *
575
+ * ```ts
576
+ * db.select().from(cars)
577
+ * .where(
578
+ * or(
579
+ * eq(cars.make, 'GM'),
580
+ * eq(cars.make, 'Ford'),
581
+ * )
582
+ * )
583
+ * ```
584
+ */
585
+ or?: Array<PgQueryWhere<T> | SQL>;
586
+ /**
587
+ * Negate the meaning of an expression using the `not` keyword.
588
+ *
589
+ * ## Examples
590
+ *
591
+ * ```ts
592
+ * // Select cars _not_ made by GM or Ford.
593
+ * db.select().from(cars)
594
+ * .where(not(inArray(cars.make, ['GM', 'Ford'])))
595
+ * ```
596
+ */
597
+ not?: PgQueryWhere<T>;
598
+ /**
599
+ * Test whether a subquery evaluates to have any rows.
600
+ *
601
+ * ## Examples
602
+ *
603
+ * ```ts
604
+ * // Users whose `homeCity` column has a match in a cities
605
+ * // table.
606
+ * db
607
+ * .select()
608
+ * .from(users)
609
+ * .where(
610
+ * exists(db.select()
611
+ * .from(cities)
612
+ * .where(eq(users.homeCity, cities.id))),
613
+ * );
614
+ * ```
615
+ *
616
+ * @see notExists for the inverse of this test
617
+ */
618
+ exists?: SQLWrapper;
619
+ };
620
+
621
+ interface PgQuery<T extends TObject> {
622
+ where?: PgQueryWhereWithMany<T> | SQLWrapper;
623
+ limit?: number;
624
+ offset?: number;
625
+ sort?: {
626
+ [key in keyof Static<T>]?: "asc" | "desc";
627
+ };
628
+ relations?: PgQueryWithMap<T>;
629
+ }
630
+ type PgQueryWhereWithMany<T extends TObject> = PgQueryWhere<Static<RemoveManyRelations<T>>> & ExtractManyRelations<T>;
631
+ type ExtractManyRelations<T extends TObject> = {
632
+ [K in keyof T["properties"] as T["properties"][K] extends {
633
+ [PG_MANY]: any;
634
+ } ? T["properties"][K] extends TArray ? T["properties"][K]["items"] extends TObject ? K : never : never : never]?: PgQueryWhere<Static<T["properties"][K]["items"]>>;
635
+ };
636
+ type RemoveManyRelations<T extends TObject> = TObject<{
637
+ [K in keyof T["properties"] as T["properties"][K] extends {
638
+ [PG_MANY]: any;
639
+ } ? never : K]: T["properties"][K];
640
+ }>;
641
+ type PgQueryWithMap<T extends TObject> = {
642
+ [K in keyof T["properties"] as T["properties"][K] extends {
643
+ [PG_MANY]: any;
644
+ } ? K : never]?: T["properties"][K] extends TObject ? PgQueryWith<T["properties"][K]> : T["properties"][K] extends TArray ? PgQueryWith<T["properties"][K]> : never;
645
+ };
646
+ type PgQueryWith<T extends TObject | TArray> = true | {
647
+ relations?: {
648
+ [key: string]: PgQueryWith<T>;
649
+ };
650
+ };
651
+
652
+ declare const pageQuerySchema: _sinclair_typebox.TObject<{
653
+ page: _sinclair_typebox.TOptional<_sinclair_typebox.TInteger>;
654
+ size: _sinclair_typebox.TOptional<_sinclair_typebox.TNumber>;
655
+ sort: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
656
+ }>;
657
+ type PageQuery = Static$1<typeof pageQuerySchema>;
658
+
659
+ /**
660
+ * Page Schema
661
+ *
662
+ * @param objectSchema
663
+ * @param options
664
+ */
665
+ declare const pageSchema: <T extends TObject | TIntersect>(objectSchema: T, options?: ObjectOptions) => TPage<T>;
666
+ /**
667
+ *
668
+ */
669
+ type TPage<T extends TObject | TIntersect> = TObject<{
670
+ content: TArray<T>;
671
+ can: TObject<{
672
+ next: TBoolean;
673
+ previous: TBoolean;
674
+ }>;
675
+ page: TObject<{
676
+ number: TInteger;
677
+ size: TInteger;
678
+ }>;
679
+ }>;
680
+ /**
681
+ *
682
+ */
683
+ type Page<T> = {
684
+ content: T[];
685
+ can: {
686
+ next: boolean;
687
+ previous: boolean;
688
+ };
689
+ page: {
690
+ number: number;
691
+ size: number;
692
+ };
693
+ };
694
+
695
+ /**
696
+ *
697
+ */
698
+ declare class Repository<TTable extends PgTableWithColumns<TableConfig$1>, TTableSchema extends TObject> {
699
+ readonly options: {
700
+ table: TTable;
701
+ schema: TTableSchema;
702
+ };
703
+ readonly provider: PostgresProvider;
704
+ protected readonly alepha: Alepha;
705
+ static of: <TEntity extends TableConfig$1, TSchema extends TObject>(table: PgTableWithColumnsAndSchema<TEntity, TSchema>) => (new () => Repository<PgTableWithColumnsAndSchema<TEntity, TSchema>, TSchema>);
706
+ /**
707
+ * Register Repository as a valid descriptor.
708
+ * - Required for $repository to work.
709
+ */
710
+ [KIND]: string;
711
+ /**
712
+ * Represents the primary key of the table.
713
+ * - Key is the name of the primary key column.
714
+ * - Type is the type (TypeBox) of the primary key column.
715
+ *
716
+ * ID is mandatory. If the table does not have a primary key, it will throw an error.
717
+ */
718
+ readonly id: {
719
+ type: TSchema;
720
+ key: keyof TTableSchema["properties"];
721
+ col: PgColumn;
722
+ };
723
+ [OPTIONS]: {
724
+ table: TTable;
725
+ schema: TTableSchema;
726
+ };
727
+ constructor(options: {
728
+ table: TTable;
729
+ schema: TTableSchema;
730
+ });
731
+ /**
732
+ * Get the table schema.
733
+ */
734
+ get schema(): TTableSchema;
735
+ /**
736
+ * Get the insert schema.
737
+ */
738
+ get insertSchema(): TInsertObject<TTableSchema>;
739
+ /**
740
+ * Get Drizzle table object.
741
+ */
742
+ get table(): TTable;
743
+ /**
744
+ * Get SQL table name. (from Drizzle table object)
745
+ */
746
+ get tableName(): string;
747
+ /**
748
+ * Getter for the database connection from the database provider.
749
+ */
750
+ get db(): PgDatabase<any, Record<string, never>, drizzle_orm.ExtractTablesWithRelations<Record<string, never>>>;
751
+ /**
752
+ *
753
+ */
754
+ organization(): PgColumn;
755
+ /**
756
+ * Execute a SQL query.
757
+ *
758
+ * @param query
759
+ * @param schema
760
+ */
761
+ execute<T extends TObject = TTableSchema>(query: SQLLike | ((table: TTable, db: PgDatabase<any>) => SQLLike), schema?: T): Promise<Static<T>[]>;
762
+ /**
763
+ * Get a Drizzle column from the table by his name.
764
+ *
765
+ * @param name - The name of the column to get.
766
+ * @returns The column from the table.
767
+ */
768
+ protected col(name: keyof TTable["_"]["columns"]): PgColumn;
769
+ /**
770
+ * Run a transaction.
771
+ *
772
+ * @param transaction
773
+ * @param config
774
+ */
775
+ transaction<T>(transaction: (tx: PgTransaction<any, Record<string, any>, any>) => Promise<T>, config?: PgTransactionConfig): Promise<T>;
776
+ /**
777
+ * Start a SELECT query on the table.
778
+ *
779
+ * @returns The SELECT query builder.
780
+ */
781
+ protected select(opts?: StatementOptions): drizzle_orm_pg_core.PgSelectBase<string, Record<string, PgColumn<drizzle_orm.ColumnBaseConfig<drizzle_orm.ColumnDataType, string>, {}, {}>>, "single", Record<string, "not-null">, false, never, {
782
+ [x: string]: unknown;
783
+ }[], {
784
+ [x: string]: PgColumn<drizzle_orm.ColumnBaseConfig<drizzle_orm.ColumnDataType, string>, {}, {}>;
785
+ }>;
786
+ /**
787
+ * Start an INSERT query on the table.
788
+ *
789
+ * @returns The INSERT query builder.
790
+ */
791
+ protected insert(opts?: StatementOptions): drizzle_orm_pg_core.PgInsertBuilder<TTable, any, false>;
792
+ /**
793
+ * Start an UPDATE query on the table.
794
+ *
795
+ * @returns The UPDATE query builder.
796
+ */
797
+ protected update(opts?: StatementOptions): drizzle_orm_pg_core.PgUpdateBuilder<TTable, any>;
798
+ /**
799
+ * Start a DELETE query on the table.
800
+ *
801
+ * @returns The DELETE query builder.
802
+ */
803
+ protected delete(opts?: StatementOptions): drizzle_orm_pg_core.PgDeleteBase<TTable, any, undefined, undefined, false, never>;
804
+ /**
805
+ * Find entities.
806
+ *
807
+ * @param query The find query.
808
+ * @param opts The statement options.
809
+ * @returns The found entities.
810
+ */
811
+ find(query?: PgQuery<TTableSchema>, opts?: StatementOptions): Promise<Static<TTableSchema>[]>;
812
+ /**
813
+ * Find a single entity.
814
+ *
815
+ * @param where The where clause.
816
+ * @param opts The statement options.
817
+ * @returns The found entity.
818
+ */
819
+ findOne<T extends Static<TTableSchema> = Static<TTableSchema>>(where: PgQueryWhere<T>, opts?: StatementOptions): Promise<Static<TTableSchema>>;
820
+ /**
821
+ * Find an entity by ID.
822
+ *
823
+ * @param id
824
+ * @param opts
825
+ */
826
+ findById(id: string | number, opts?: StatementOptions): Promise<Static<TTableSchema>>;
827
+ /**
828
+ * Paginate entities.
829
+ *
830
+ * @param pageQuery The pagination query.
831
+ * @param findQuery The find query.
832
+ * @param opts The statement options.
833
+ * @returns The paginated entities.
834
+ */
835
+ paginate(pageQuery?: PageQuery, findQuery?: PgQuery<TTableSchema>, opts?: StatementOptions): Promise<Page<Static<TTableSchema>>>;
836
+ /**
837
+ *
838
+ */
839
+ createQuery(query?: PgQuery<TTableSchema>): PgQuery<TTableSchema>;
840
+ /**
841
+ *
842
+ */
843
+ createQueryWhere(where?: PgQueryWhere<Static<TTableSchema>>): PgQueryWhere<Static<TTableSchema>>;
844
+ /**
845
+ * Create an entity.
846
+ *
847
+ * @param data The entity to create.
848
+ * @param opts The options for creating the entity.
849
+ * @returns The ID of the created entity.
850
+ */
851
+ create(data: InferInsert<TTableSchema>, opts?: StatementOptions): Promise<Static<TTableSchema>>;
852
+ /**
853
+ * Create many entities.
854
+ *
855
+ * @param values The entities to create.
856
+ * @param opts The statement options.
857
+ * @returns The created entities.
858
+ */
859
+ createMany(values: Array<InferInsert<TTableSchema>>, opts?: StatementOptions): Promise<Static<TTableSchema>[]>;
860
+ /**
861
+ * Update an entity.
862
+ *
863
+ * @param query The where clause.
864
+ * @param data The data to update.
865
+ * @param opts The statement options.
866
+ * @returns The updated entity.
867
+ */
868
+ updateOne(query: PgQueryWhere<Static<TTableSchema>>, data: Partial<NullifyIfOptional<Static<TTableSchema>>> | {
869
+ $append: Partial<NullifyIfOptional<Static<TTableSchema>>>;
870
+ }, opts?: StatementOptions): Promise<Static<TTableSchema>>;
871
+ save(data: InferInsert<TTableSchema>, opts?: StatementOptions): Promise<Static<TTableSchema>>;
872
+ /**
873
+ * Update an entity by ID.
874
+ *
875
+ * @param id
876
+ * @param data
877
+ * @param opts
878
+ */
879
+ updateById(id: string | number, data: Partial<NullifyIfOptional<Static<TTableSchema>>>, opts?: StatementOptions): Promise<Static<TTableSchema>>;
880
+ /**
881
+ * Update entities.
882
+ *
883
+ * @param where The where clause.
884
+ * @param data The data to update.
885
+ * @param opts The statement options.
886
+ * @returns The updated entities.
887
+ */
888
+ updateMany(where: PgQueryWhere<Static<TTableSchema>>, data: Partial<NullifyIfOptional<Static<TTableSchema>>>, opts?: StatementOptions): Promise<Static<TTableSchema>[]>;
889
+ /**
890
+ * Delete entities.
891
+ *
892
+ * @param where Query.
893
+ * @param opts The statement options.
894
+ */
895
+ deleteMany(where?: PgQueryWhere<Static<TTableSchema>>, opts?: StatementOptions): Promise<void>;
896
+ /**
897
+ * Delete all entities.
898
+ * @param opts
899
+ */
900
+ clear(opts?: StatementOptions): Promise<void>;
901
+ /**
902
+ * Delete an entity by ID.
903
+ *
904
+ * @param id
905
+ * @param opts
906
+ */
907
+ deleteById(id: string | number, opts?: StatementOptions): Promise<void>;
908
+ /**
909
+ * Count entities.
910
+ *
911
+ * @param where The where clause.
912
+ * @param opts The statement options.
913
+ * @returns The count of entities.
914
+ */
915
+ count(where?: PgQueryWhere<Static<TTableSchema>>, opts?: StatementOptions): Promise<number>;
916
+ /**
917
+ * Convert a query object to a SQL query.
918
+ *
919
+ * @param query The query object.
920
+ * @param schema The schema to use.
921
+ * @param col The column to use.
922
+ */
923
+ jsonQueryToSql(query: PgQueryWhere<Static<TTableSchema>>, schema?: TObject, col?: (key: string) => PgColumn): SQL | undefined;
924
+ /**
925
+ * Map a filter operator to a SQL query.
926
+ *
927
+ * @param operator
928
+ * @param column
929
+ * @protected
930
+ */
931
+ protected mapOperatorToSql(operator: FilterOperators<any>, column: PgColumn): SQL | undefined;
932
+ /**
933
+ * Create a pagination object.
934
+ *
935
+ * @param entities The entities to paginate.
936
+ * @param limit The limit of the pagination.
937
+ * @param offset The offset of the pagination.
938
+ */
939
+ protected createPagination(entities: Static<TTableSchema>[], limit?: number, offset?: number): Page<Static<TTableSchema>>;
940
+ /**
941
+ * Convert something to valid Pg Insert Value.
942
+ */
943
+ protected cast(data: any, insert: boolean): PgInsertValue<TTable>;
944
+ /**
945
+ * Clean a row. Remove all null values.
946
+ *
947
+ * @param row The row to clean.
948
+ * @param schema The schema to use.
949
+ * @returns The cleaned row.
950
+ */
951
+ protected clean<T extends TObject = TTableSchema>(row: any, schema?: T): Static<T>;
952
+ /**
953
+ * Get the where clause for an ID.
954
+ *
955
+ * @param id The ID to get the where clause for.
956
+ * @returns The where clause for the ID.
957
+ */
958
+ protected getWhereId(id: string | number): PgQueryWhere<Static<TTableSchema>>;
959
+ /**
960
+ * Get all fields with a specific attribute.
961
+ *
962
+ * @param schema
963
+ * @param name
964
+ * @protected
965
+ */
966
+ protected getAttrFields(schema: TObject, name: PgSymbolKeys): PgAttrField[];
967
+ /**
968
+ * Find a primary key in the schema.
969
+ *
970
+ * @param schema
971
+ * @protected
972
+ */
973
+ protected getPrimaryKey(schema: TObject): {
974
+ key: string;
975
+ col: PgColumn<drizzle_orm.ColumnBaseConfig<drizzle_orm.ColumnDataType, string>, {}, {}>;
976
+ type: TSchema;
977
+ };
978
+ /**
979
+ * Try to aggregate the rows after a select JOIN.
980
+ *
981
+ * @param rows
982
+ * @param pgManyFields
983
+ * @param query
984
+ * @protected
985
+ */
986
+ protected aggregateRows(rows: any[], pgManyFields: PgAttrField[], query: PgQuery<any>): any[];
987
+ /**
988
+ * Populate the JOINs in the query.
989
+ *
990
+ * @param builder
991
+ * @param query
992
+ * @param schema
993
+ * @param id
994
+ * @protected
995
+ */
996
+ protected withJoins(builder: {
997
+ leftJoin: PgSelectJoinFn<any, any, "left", true>;
998
+ innerJoin: PgSelectJoinFn<any, any, "inner", true>;
999
+ }, query: PgQuery<any>, schema: TObject, id: PgColumn): PgAttrField[];
1000
+ }
1001
+ /**
1002
+ * The options for a statement.
1003
+ */
1004
+ interface StatementOptions {
1005
+ /**
1006
+ * Transaction to use.
1007
+ */
1008
+ tx?: PgTransaction<any, Record<string, any>>;
1009
+ /**
1010
+ * Lock strength.
1011
+ */
1012
+ for?: LockStrength | {
1013
+ config: LockConfig;
1014
+ strength: LockStrength;
1015
+ };
1016
+ /**
1017
+ * Organization ID.
1018
+ *
1019
+ * Multi-tenant support.
1020
+ *
1021
+ * If set, it will be used to filter the results by organization.
1022
+ */
1023
+ organization?: string;
1024
+ }
1025
+ interface PgAttrField {
1026
+ key: string;
1027
+ type: TSchema;
1028
+ data: any;
1029
+ nested?: any[];
1030
+ }
1031
+
1032
+ interface RepositoryDescriptorOptions<TEntity extends TableConfig, TSchema extends TObject$1> {
1033
+ /**
1034
+ * The table to create the repository for.
1035
+ */
1036
+ table: PgTableWithColumnsAndSchema<TEntity, TSchema>;
1037
+ /**
1038
+ * Override default provider.
1039
+ */
1040
+ provider?: () => PostgresProvider;
1041
+ }
1042
+ /**
1043
+ * @param optionsOrTable
1044
+ */
1045
+ declare const $repository: {
1046
+ <TEntity extends TableConfig, TSchema extends TObject$1>(optionsOrTable: RepositoryDescriptorOptions<TEntity, TSchema> | PgTableWithColumnsAndSchema<TEntity, TSchema>): Repository<PgTableWithColumnsAndSchema<TEntity, TSchema>, TSchema>;
1047
+ [KIND]: string;
1048
+ };
1049
+
1050
+ declare const KEY = "SEQUENCE";
1051
+ interface SequenceDescriptorOptions {
1052
+ /**
1053
+ *
1054
+ */
1055
+ name?: string;
1056
+ /**
1057
+ *
1058
+ */
1059
+ start?: number;
1060
+ /**
1061
+ *
1062
+ */
1063
+ increment?: number;
1064
+ /**
1065
+ *
1066
+ */
1067
+ min?: number;
1068
+ /**
1069
+ *
1070
+ */
1071
+ max?: number;
1072
+ /**
1073
+ *
1074
+ */
1075
+ cycle?: boolean;
1076
+ }
1077
+ interface SequenceDescriptor {
1078
+ [KIND]: typeof KEY;
1079
+ [OPTIONS]: SequenceDescriptorOptions;
1080
+ /**
1081
+ *
1082
+ */
1083
+ (): Promise<number>;
1084
+ /**
1085
+ *
1086
+ */
1087
+ next(): Promise<number>;
1088
+ /**
1089
+ *
1090
+ */
1091
+ current(): Promise<number>;
1092
+ }
1093
+ /**
1094
+ *
1095
+ * @param options
1096
+ */
1097
+ declare const $sequence: {
1098
+ (options?: SequenceDescriptorOptions): SequenceDescriptor;
1099
+ [KIND]: string;
1100
+ };
1101
+
1102
+ interface TransactionDescriptorOptions<T extends any[], R> {
1103
+ /**
1104
+ *
1105
+ * @param tx
1106
+ * @param args
1107
+ */
1108
+ handler: (tx: PgTransaction<any, any, any>, ...args: T) => Promise<R>;
1109
+ /**
1110
+ *
1111
+ */
1112
+ config?: PgTransactionConfig$1;
1113
+ }
1114
+ type TransactionContext = PgTransaction<any, any, any>;
1115
+ /**
1116
+ * Creates a transaction descriptor.
1117
+ */
1118
+ declare const $transaction: <T extends any[], R>(opts: TransactionDescriptorOptions<T, R>) => (...parameters: T) => Promise<Promise<R>>;
1119
+
1120
+ declare class EntityNotFoundError extends Error {
1121
+ readonly code = "ERR_RESOURCE_NOTFOUND";
1122
+ readonly status = 404;
1123
+ constructor(entityName: string);
1124
+ }
1125
+
1126
+ /**
1127
+ * Create a table with a json schema.
1128
+ *
1129
+ * @param name The name of the table.
1130
+ * @param schema The json schema of the table.
1131
+ * @param extraConfig Extra configuration for the table.
1132
+ */
1133
+ declare const pgTableSchema: <TTableName extends string, TSchema extends TObject, TColumnsMap extends FromSchema<TSchema>>(name: TTableName, schema: TSchema, extraConfig?: (self: BuildExtraConfigColumns<TTableName, TColumnsMap, "pg">) => PgTableExtraConfigValue$1[]) => PgTableWithColumnsAndSchema<PgTableConfig<TTableName, TSchema, TColumnsMap>, TSchema>;
1134
+ /**
1135
+ * @alias pgTableSchema
1136
+ */
1137
+ declare const table: <TTableName extends string, TSchema extends TObject, TColumnsMap extends FromSchema<TSchema>>(name: TTableName, schema: TSchema, extraConfig?: (self: BuildExtraConfigColumns<TTableName, TColumnsMap, "pg">) => PgTableExtraConfigValue$1[]) => PgTableWithColumnsAndSchema<PgTableConfig<TTableName, TSchema, TColumnsMap>, TSchema>;
1138
+ declare const $table: <TTableName extends string, TSchema extends TObject, TColumnsMap extends FromSchema<TSchema>>(name: TTableName, schema: TSchema, extraConfig?: (self: BuildExtraConfigColumns<TTableName, TColumnsMap, "pg">) => PgTableExtraConfigValue$1[]) => PgTableWithColumnsAndSchema<PgTableConfig<TTableName, TSchema, TColumnsMap>, TSchema>;
1139
+ declare const table2: <TTableName extends string, TSchema extends TObject, TColumnsMap extends FromSchema<TSchema>>(name: TTableName, schema: TSchema, extraConfig?: (self: BuildExtraConfigColumns<TTableName, TColumnsMap, "pg">) => PgTableExtraConfigValue$1[]) => PgTableWithColumnsAndSchema<PgTableConfig<TTableName, TSchema, TColumnsMap>, TSchema>;
1140
+ /**
1141
+ *
1142
+ */
1143
+ type PgTableConfig<TTableName extends string, TSchema extends TObject, TColumnsMap extends FromSchema<TSchema>> = {
1144
+ name: TTableName;
1145
+ schema: any;
1146
+ columns: BuildColumns<TTableName, TColumnsMap, "pg">;
1147
+ dialect: "pg";
1148
+ };
1149
+
1150
+ declare class RepositoryDescriptorProvider {
1151
+ protected readonly log: _alepha_core.Logger;
1152
+ protected readonly alepha: Alepha;
1153
+ protected readonly repositories: Array<Repository<any, TObject>>;
1154
+ constructor();
1155
+ protected readonly configure: _alepha_core.HookDescriptor<"configure">;
1156
+ /**
1157
+ * Get all repositories.
1158
+ *
1159
+ * @param provider - Filter by provider.
1160
+ */
1161
+ getRepositories(provider?: PostgresProvider): Repository<PgTableWithColumns<TableConfig$1>, TObject>[];
1162
+ /**
1163
+ * Get all tables from the repositories.
1164
+ *
1165
+ * @param provider
1166
+ */
1167
+ getTables(provider?: PostgresProvider): PgTableWithColumns<TableConfig$1>[];
1168
+ /**
1169
+ * Get all providers from the repositories.
1170
+ */
1171
+ getProviders(): PostgresProvider[];
1172
+ /**
1173
+ * Process all descriptors.
1174
+ *
1175
+ * @protected
1176
+ */
1177
+ protected processDescriptors(): Promise<void>;
1178
+ /**
1179
+ * Get all models from the repository descriptors.
1180
+ *
1181
+ * By models, we mean the tables.
1182
+ */
1183
+ protected processRepositoryDescriptors(): Promise<void>;
1184
+ }
1185
+
1186
+ declare class DrizzleKitProvider {
1187
+ protected readonly log: _alepha_core.Logger;
1188
+ protected readonly alepha: Alepha;
1189
+ protected readonly repositoryDescriptorProvider: RepositoryDescriptorProvider;
1190
+ /**
1191
+ * Try to generate migrations from scratch based on the models.
1192
+ * Then, execute the migrations.
1193
+ *
1194
+ * This is useful for testing or development purposes.
1195
+ *
1196
+ * Do not use in production.
1197
+ *
1198
+ * @param provider - The Postgres provider to use.
1199
+ * @param schema - The schema to use.
1200
+ * @returns A promise that resolves once the migrations have been executed.
1201
+ */
1202
+ synchronize(provider: PostgresProvider, schema?: string): Promise<void>;
1203
+ /**
1204
+ * Get the Drizzle Kit API.
1205
+ *
1206
+ * @protected
1207
+ */
1208
+ protected importDrizzleKit(): any;
1209
+ }
1210
+
1211
+ declare module "alepha" {
1212
+ interface Env extends Partial<Static$1<typeof envSchema$1>> {
1213
+ }
1214
+ }
1215
+ declare const envSchema$1: _alepha_core.TObject<{
1216
+ PG_HOST: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
1217
+ PG_USERNAME: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
1218
+ PG_DATABASE: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
1219
+ PG_PASSWORD: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
1220
+ /**
1221
+ *
1222
+ */
1223
+ DATABASE_URL: _sinclair_typebox.TString;
1224
+ /**
1225
+ *
1226
+ */
1227
+ DATABASE_MIGRATIONS_FOLDER: _sinclair_typebox.TString;
1228
+ /**
1229
+ *
1230
+ */
1231
+ DATABASE_MIGRATIONS_SCHEMA: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
1232
+ /**
1233
+ *
1234
+ */
1235
+ DATABASE_MIGRATIONS_TABLE: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
1236
+ /**
1237
+ * The schema to use.
1238
+ * Accept a string.
1239
+ */
1240
+ POSTGRES_SCHEMA: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
1241
+ /**
1242
+ * Synchronize the database schema with the models.
1243
+ * Accept a boolean or a postgres schema name.
1244
+ *
1245
+ * @default false
1246
+ */
1247
+ POSTGRES_SYNCHRONIZE: _sinclair_typebox.TOptional<_sinclair_typebox.TBoolean>;
1248
+ /**
1249
+ *
1250
+ */
1251
+ POSTGRES_REJECT_UNAUTHORIZED: _sinclair_typebox.TBoolean;
1252
+ }>;
1253
+ interface NodePostgresProviderState {
1254
+ client: pg$1.Client;
1255
+ db: NodePgDatabase;
1256
+ }
1257
+ declare class NodePostgresProvider implements PostgresProvider {
1258
+ readonly dialect = "postgres";
1259
+ protected readonly log: _alepha_core.Logger;
1260
+ protected readonly env: {
1261
+ PG_HOST?: string | undefined;
1262
+ PG_USERNAME?: string | undefined;
1263
+ PG_DATABASE?: string | undefined;
1264
+ PG_PASSWORD?: string | undefined;
1265
+ DATABASE_MIGRATIONS_SCHEMA?: string | undefined;
1266
+ DATABASE_MIGRATIONS_TABLE?: string | undefined;
1267
+ POSTGRES_SCHEMA?: string | undefined;
1268
+ POSTGRES_SYNCHRONIZE?: boolean | undefined;
1269
+ DATABASE_URL: string;
1270
+ DATABASE_MIGRATIONS_FOLDER: string;
1271
+ POSTGRES_REJECT_UNAUTHORIZED: boolean;
1272
+ };
1273
+ protected readonly alepha: Alepha;
1274
+ protected readonly kit: DrizzleKitProvider;
1275
+ protected state?: NodePostgresProviderState;
1276
+ /**
1277
+ * In testing mode, the schema name will be generated and deleted after the test.
1278
+ */
1279
+ protected testingSchemaName?: string;
1280
+ get db(): NodePgDatabase;
1281
+ protected readonly configure: _alepha_core.HookDescriptor<"start">;
1282
+ protected readonly stop: _alepha_core.HookDescriptor<"stop">;
1283
+ /**
1284
+ * Get Postgres schema.
1285
+ */
1286
+ get schema(): string;
1287
+ execute(query: SQLLike): Promise<any[]>;
1288
+ connect(): Promise<void>;
1289
+ close(): Promise<void>;
1290
+ /**
1291
+ *
1292
+ * @protected
1293
+ */
1294
+ protected migrate: _alepha_lock.LockDescriptor<() => Promise<void>>;
1295
+ protected createClient(): NodePostgresProviderState;
1296
+ protected getMigrationOptions(): MigrationConfig;
1297
+ protected getClientOptions(): ClientConfig;
1298
+ }
1299
+
1300
+ /**
1301
+ * Type representation.
1302
+ */
1303
+ type PgAttr<T extends TSchema, TAttr extends PgSymbolKeys> = T & {
1304
+ [K in TAttr]: PgSymbols[K];
1305
+ };
1306
+
1307
+ declare const createdAtSchema: PgAttr<PgAttr<_sinclair_typebox.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
1308
+
1309
+ declare const legacyIdSchema: PgAttr<PgAttr<PgAttr<_sinclair_typebox.TInteger, typeof PG_PRIMARY_KEY>, typeof PG_SERIAL>, typeof PG_DEFAULT>;
1310
+
1311
+ /**
1312
+ *
1313
+ */
1314
+ declare const updatedAtSchema: PgAttr<PgAttr<_sinclair_typebox.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
1315
+
1316
+ /**
1317
+ * Entity Schema.
1318
+ *
1319
+ * Add some common SQL properties to an object.
1320
+ */
1321
+ declare const entitySchema: TObject<{
1322
+ id: PgAttr<PgAttr<PgAttr<_sinclair_typebox.TInteger, typeof PG_PRIMARY_KEY>, typeof PG_SERIAL>, typeof PG_DEFAULT>;
1323
+ createdAt: PgAttr<PgAttr<_sinclair_typebox.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
1324
+ updatedAt: PgAttr<PgAttr<_sinclair_typebox.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
1325
+ }>;
1326
+ /**
1327
+ * TypeBox Entity Type.
1328
+ */
1329
+ type TEntity<T extends TProperties> = TObject<T & {
1330
+ id: typeof legacyIdSchema;
1331
+ createdAt: typeof createdAtSchema;
1332
+ updatedAt: typeof updatedAtSchema;
1333
+ }>;
1334
+ /**
1335
+ * The base entity.
1336
+ */
1337
+ type BaseEntity = Static$1<typeof entitySchema>;
1338
+ /**
1339
+ * The keys of the base entity.
1340
+ */
1341
+ type BaseEntityKeys = keyof BaseEntity;
1342
+ /**
1343
+ * The keys of the base entity.
1344
+ */
1345
+ declare const entityKeys: readonly ["id", "createdAt", "updatedAt"];
1346
+
1347
+ declare module "alepha/core" {
1348
+ interface TypeProvider {
1349
+ pg: PostgresTypeProvider;
1350
+ }
1351
+ }
1352
+ declare class PostgresTypeProvider {
1353
+ readonly attr: <T extends TSchema, Attr extends PgSymbolKeys>(type: T, attr: Attr, value?: PgSymbols[Attr]) => PgAttr<T, Attr>;
1354
+ readonly serial: () => PgAttr<_sinclair_typebox.TInteger, typeof PG_SERIAL>;
1355
+ readonly identity: (options?: IntegerOptions) => PgAttr<_sinclair_typebox.TInteger, typeof PG_IDENTITY>;
1356
+ readonly id: (options?: IntegerOptions) => PgAttr<PgAttr<PgAttr<_sinclair_typebox.TInteger, typeof PG_IDENTITY>, typeof PG_DEFAULT>, typeof PG_PRIMARY_KEY>;
1357
+ readonly identityPrimaryKey: (options?: IntegerOptions) => PgAttr<PgAttr<PgAttr<_sinclair_typebox.TInteger, typeof PG_PRIMARY_KEY>, typeof PG_IDENTITY>, typeof PG_DEFAULT>;
1358
+ readonly primaryKey: <T extends TSchema>(type: T) => PgAttr<PgAttr<T, PgDefault>, PgPrimaryKey>;
1359
+ /**
1360
+ *
1361
+ * @param type
1362
+ * @param value
1363
+ */
1364
+ readonly default: <T extends TSchema>(type: T, value?: Static$1<T>) => PgAttr<T, PgDefault>;
1365
+ /**
1366
+ *
1367
+ * @param options
1368
+ */
1369
+ readonly version: (options?: IntegerOptions) => PgAttr<PgAttr<_sinclair_typebox.TInteger, typeof PG_VERSION>, typeof PG_DEFAULT>;
1370
+ /**
1371
+ *
1372
+ * @param options
1373
+ */
1374
+ readonly createdAt: (options?: StringOptions) => PgAttr<PgAttr<_sinclair_typebox.TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
1375
+ /**
1376
+ *
1377
+ * @param options
1378
+ */
1379
+ readonly updatedAt: (options?: StringOptions) => PgAttr<PgAttr<_sinclair_typebox.TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
1380
+ /**
1381
+ *
1382
+ * @param properties
1383
+ * @param options
1384
+ */
1385
+ readonly entity: <T extends TProperties>(properties: T, options?: ObjectOptions) => TEntity<T>;
1386
+ /**
1387
+ *
1388
+ * @param obj
1389
+ */
1390
+ readonly insert: <T extends TObject>(obj: T) => TInsertObject<T>;
1391
+ /**
1392
+ * @alias insert
1393
+ */
1394
+ readonly input: <T extends TObject>(obj: T) => TInsertObject<T>;
1395
+ /**
1396
+ *
1397
+ * @param resource
1398
+ * @param options
1399
+ */
1400
+ readonly page: <T extends TObject>(resource: T, options?: ObjectOptions) => TPage<T>;
1401
+ /**
1402
+ *
1403
+ * @param type
1404
+ * @param ref
1405
+ * @param actions
1406
+ */
1407
+ readonly ref: <T extends TSchema>(type: T, ref: () => any, actions?: {
1408
+ onUpdate?: UpdateDeleteAction$1;
1409
+ onDelete?: UpdateDeleteAction$1;
1410
+ }) => PgAttr<T, PgRef>;
1411
+ /**
1412
+ *
1413
+ * @param table
1414
+ * @param foreignKey
1415
+ */
1416
+ readonly many: <T extends TObject, Config extends TableConfig$1>(table: PgTableWithColumnsAndSchema<Config, T>, foreignKey: keyof T["properties"]) => TOptionalWithFlag<PgAttr<PgAttr<TArray<T>, PgMany>, PgDefault>, true>;
1417
+ }
1418
+ declare const pg: PostgresTypeProvider;
1419
+
1420
+ /**
1421
+ * Postgres schema type.
1422
+ */
1423
+ declare const schema: <TDocument extends TSchema>(name: string, document: TDocument) => drizzle_orm.$Type<drizzle_orm_pg_core.PgCustomColumnBuilder<{
1424
+ name: string;
1425
+ dataType: "custom";
1426
+ columnType: "PgCustomColumn";
1427
+ data: (TDocument & {
1428
+ params: [];
1429
+ })["static"];
1430
+ driverParam: string;
1431
+ enumValues: undefined;
1432
+ }>, (TDocument & {
1433
+ params: [];
1434
+ })["static"]>;
1435
+
1436
+ declare const envSchema: _alepha_core.TObject<{
1437
+ POSTGRES_PROVIDER: _sinclair_typebox.TOptional<_sinclair_typebox.TUnsafe<"pg">>;
1438
+ }>;
1439
+ declare module "@alepha/core" {
1440
+ interface Env extends Partial<Static$1<typeof envSchema>> {
1441
+ }
1442
+ }
1443
+ declare class PostgresModule {
1444
+ protected readonly alepha: Alepha;
1445
+ protected readonly env: {
1446
+ POSTGRES_PROVIDER?: "pg" | undefined;
1447
+ };
1448
+ constructor();
1449
+ protected getDefaultProviderName(): "pg";
1450
+ }
1451
+
1452
+ export { $entity, $repository, $sequence, $table, $transaction, type BaseEntity, type BaseEntityKeys, type EntityDescriptorOptions, EntityNotFoundError, type ExtractManyRelations, type FilterOperators, type FromSchema, NodePostgresProvider, type NodePostgresProviderState, type NullToUndefined, type NullifyIfOptional, PG_CREATED_AT, PG_DEFAULT, PG_IDENTITY, PG_MANY, PG_ONE, PG_PRIMARY_KEY, PG_REF, PG_SCHEMA, PG_SERIAL, PG_UPDATED_AT, PG_VERSION, type Page, type PageQuery, type PgAttrField, type PgDefault, type PgIdentityOptions, type PgMany, type PgManyOptions, type PgPrimaryKey, type PgQuery, type PgQueryWhere, type PgQueryWhereWithMany, type PgQueryWith, type PgQueryWithMap, type PgRef, type PgRefOptions, type PgSymbolKeys, type PgSymbols, type PgTableConfig, type PgTableWithColumnsAndSchema, PostgresModule, PostgresProvider, PostgresTypeProvider, type RemoveManyRelations, Repository, type RepositoryDescriptorOptions, RepositoryDescriptorProvider, type SQLLike, type SequenceDescriptor, type SequenceDescriptorOptions, type StatementOptions, type TEntity, type TPage, type TransactionContext, type TransactionDescriptorOptions, entityKeys, entitySchema, fromSchema, nullToUndefined, pageQuerySchema, pageSchema, pg, pgTableSchema, schema, schemaToColumns, table, table2 };