alepha 0.10.3 → 0.10.5
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/README.md +10 -22
- package/api/files.cjs +8 -0
- package/api/files.d.ts +201 -0
- package/api/files.js +1 -0
- package/api/jobs.cjs +8 -0
- package/api/jobs.d.ts +274 -0
- package/api/jobs.js +1 -0
- package/api/users.cjs +8 -0
- package/api/users.d.ts +395 -0
- package/api/users.js +1 -0
- package/batch.d.ts +14 -14
- package/bucket.d.ts +81 -4
- package/cache/redis.d.ts +1 -0
- package/cache.d.ts +5 -0
- package/command.d.ts +6 -6
- package/core.d.ts +58 -10
- package/datetime.d.ts +0 -2
- package/devtools.cjs +8 -0
- package/devtools.d.ts +368 -0
- package/devtools.js +1 -0
- package/email.d.ts +15 -15
- package/logger.d.ts +44 -29
- package/package.json +71 -43
- package/postgres.d.ts +134 -320
- package/queue.d.ts +21 -21
- package/react/auth.d.ts +5 -0
- package/react/form.d.ts +2 -2
- package/react.d.ts +27 -27
- package/scheduler.d.ts +22 -2
- package/security.d.ts +12 -4
- package/server/links.d.ts +6 -6
- package/server.d.ts +30 -30
- package/topic.d.ts +26 -161
package/postgres.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as _alepha_core1 from "alepha";
|
|
2
|
-
import { Alepha, AlephaError, Descriptor, KIND, Service, Static, TArray, TBigInt, TBoolean, TInteger,
|
|
3
|
-
import * as
|
|
2
|
+
import { Alepha, AlephaError, Descriptor, KIND, Service, Static, TArray, TBigInt, TBoolean, TInteger, TNull, TNumber, TNumberOptions, TObject, TObjectOptions, TOptional, TOptionalAdd, TRecord, TSchema as TSchema$1, TString, TStringOptions, TUnion } from "alepha";
|
|
3
|
+
import * as drizzle_orm7 from "drizzle-orm";
|
|
4
4
|
import { BuildColumns, BuildExtraConfigColumns, SQL, SQLWrapper, TableConfig, sql } from "drizzle-orm";
|
|
5
5
|
import * as pg$1 from "drizzle-orm/pg-core";
|
|
6
|
-
import { AnyPgColumn, LockConfig, LockStrength, PgColumn, PgColumnBuilderBase, PgDatabase, PgInsertValue, PgSequenceOptions, PgTableExtraConfigValue, PgTableWithColumns, PgTransaction, PgTransactionConfig, SelectedFields, TableConfig as TableConfig$1, UpdateDeleteAction } from "drizzle-orm/pg-core";
|
|
6
|
+
import { AnyPgColumn, AnyPgTable, LockConfig, LockStrength, PgColumn, PgColumnBuilderBase, PgDatabase, PgInsertValue, PgSequenceOptions, PgTableExtraConfigValue, PgTableWithColumns, PgTransaction, PgTransactionConfig, SelectedFields, TableConfig as TableConfig$1, UpdateDeleteAction } from "drizzle-orm/pg-core";
|
|
7
7
|
import { DateTime, DateTimeProvider } from "alepha/datetime";
|
|
8
8
|
import * as _alepha_logger1 from "alepha/logger";
|
|
9
9
|
import * as _alepha_lock0 from "alepha/lock";
|
|
@@ -28,12 +28,16 @@ declare const PG_UPDATED_AT: unique symbol;
|
|
|
28
28
|
declare const PG_DELETED_AT: unique symbol;
|
|
29
29
|
declare const PG_VERSION: unique symbol;
|
|
30
30
|
declare const PG_IDENTITY: unique symbol;
|
|
31
|
+
declare const PG_MANY: unique symbol;
|
|
32
|
+
declare const PG_ONE: unique symbol;
|
|
31
33
|
declare const PG_REF: unique symbol;
|
|
32
34
|
/**
|
|
33
35
|
* @deprecated Use `PG_IDENTITY` instead.
|
|
34
36
|
*/
|
|
35
37
|
declare const PG_SERIAL: unique symbol;
|
|
36
38
|
type PgDefault = typeof PG_DEFAULT;
|
|
39
|
+
type PgMany = typeof PG_MANY;
|
|
40
|
+
type PgOne = typeof PG_ONE;
|
|
37
41
|
type PgRef = typeof PG_REF;
|
|
38
42
|
type PgPrimaryKey = typeof PG_PRIMARY_KEY;
|
|
39
43
|
type PgSymbols = {
|
|
@@ -44,6 +48,8 @@ type PgSymbols = {
|
|
|
44
48
|
[PG_DELETED_AT]: {};
|
|
45
49
|
[PG_VERSION]: {};
|
|
46
50
|
[PG_IDENTITY]: PgIdentityOptions;
|
|
51
|
+
[PG_MANY]: PgManyOptions;
|
|
52
|
+
[PG_ONE]: PgManyOptions;
|
|
47
53
|
[PG_REF]: PgRefOptions;
|
|
48
54
|
/**
|
|
49
55
|
* @deprecated Use `PG_IDENTITY` instead.
|
|
@@ -56,6 +62,11 @@ type PgIdentityOptions = {
|
|
|
56
62
|
} & PgSequenceOptions & {
|
|
57
63
|
name?: string;
|
|
58
64
|
};
|
|
65
|
+
interface PgManyOptions {
|
|
66
|
+
table: AnyPgTable;
|
|
67
|
+
schema: TObject;
|
|
68
|
+
foreignKey: string;
|
|
69
|
+
}
|
|
59
70
|
interface PgRefOptions {
|
|
60
71
|
ref: () => AnyPgColumn;
|
|
61
72
|
actions?: {
|
|
@@ -105,14 +116,14 @@ declare const schemaToPgColumns: <T extends TObject>(schema: T) => FromSchema<T>
|
|
|
105
116
|
* @param value The value of the field.
|
|
106
117
|
* @returns The PG column.
|
|
107
118
|
*/
|
|
108
|
-
declare const mapFieldToColumn: (name: string, value: TSchema$1) => pg$1.PgSerialBuilderInitial<string> | pg$1.PgIntegerBuilderInitial<string> |
|
|
119
|
+
declare const mapFieldToColumn: (name: string, value: TSchema$1) => pg$1.PgSerialBuilderInitial<string> | pg$1.PgIntegerBuilderInitial<string> | drizzle_orm7.IsIdentity<pg$1.PgBigInt64BuilderInitial<"">, "byDefault"> | drizzle_orm7.IsIdentity<pg$1.PgBigInt64BuilderInitial<"">, "always"> | pg$1.PgBigInt53BuilderInitial<string> | pg$1.PgNumericBuilderInitial<string> | pg$1.PgTimestampBuilderInitial<string> | pg$1.PgUUIDBuilderInitial<string> | pg$1.PgCustomColumnBuilder<{
|
|
109
120
|
name: string;
|
|
110
121
|
dataType: "custom";
|
|
111
122
|
columnType: "PgCustomColumn";
|
|
112
123
|
data: Buffer<ArrayBufferLike>;
|
|
113
124
|
driverParam: unknown;
|
|
114
125
|
enumValues: undefined;
|
|
115
|
-
}> | pg$1.PgTimestampStringBuilderInitial<string> | pg$1.PgDateStringBuilderInitial<string> | pg$1.PgTextBuilderInitial<string, [string, ...string[]]> | pg$1.PgBooleanBuilderInitial<string> |
|
|
126
|
+
}> | pg$1.PgTimestampStringBuilderInitial<string> | pg$1.PgDateStringBuilderInitial<string> | pg$1.PgTextBuilderInitial<string, [string, ...string[]]> | pg$1.PgBooleanBuilderInitial<string> | drizzle_orm7.$Type<pg$1.PgCustomColumnBuilder<{
|
|
116
127
|
name: string;
|
|
117
128
|
dataType: "custom";
|
|
118
129
|
columnType: "PgCustomColumn";
|
|
@@ -127,14 +138,14 @@ declare const mapFieldToColumn: (name: string, value: TSchema$1) => pg$1.PgSeria
|
|
|
127
138
|
[x: string]: unknown;
|
|
128
139
|
[x: number]: unknown;
|
|
129
140
|
[x: symbol]: unknown;
|
|
130
|
-
}> |
|
|
141
|
+
}> | drizzle_orm7.$Type<pg$1.PgCustomColumnBuilder<{
|
|
131
142
|
name: string;
|
|
132
143
|
dataType: "custom";
|
|
133
144
|
columnType: "PgCustomColumn";
|
|
134
145
|
data: Record<string, unknown>;
|
|
135
146
|
driverParam: string;
|
|
136
147
|
enumValues: undefined;
|
|
137
|
-
}>, Record<string, unknown>> |
|
|
148
|
+
}>, Record<string, unknown>> | drizzle_orm7.$Type<pg$1.PgCustomColumnBuilder<{
|
|
138
149
|
name: string;
|
|
139
150
|
dataType: "custom";
|
|
140
151
|
columnType: "PgCustomColumn";
|
|
@@ -305,10 +316,10 @@ type PgTableWithColumnsAndSchema<T extends TableConfig, R extends TObject> = PgT
|
|
|
305
316
|
* name: "users",
|
|
306
317
|
* schema: t.object({
|
|
307
318
|
* id: pg.primaryKey(t.uuid()),
|
|
308
|
-
* email: t.
|
|
309
|
-
* username: t.
|
|
310
|
-
* firstName: t.
|
|
311
|
-
* lastName: t.
|
|
319
|
+
* email: t.text({ format: "email" }),
|
|
320
|
+
* username: t.text({ minLength: 3, maxLength: 30 }),
|
|
321
|
+
* firstName: t.text(),
|
|
322
|
+
* lastName: t.text(),
|
|
312
323
|
* isActive: t.boolean({ default: true }),
|
|
313
324
|
* createdAt: pg.createdAt(),
|
|
314
325
|
* updatedAt: pg.updatedAt(),
|
|
@@ -330,15 +341,15 @@ type PgTableWithColumnsAndSchema<T extends TableConfig, R extends TObject> = PgT
|
|
|
330
341
|
* name: "products",
|
|
331
342
|
* schema: t.object({
|
|
332
343
|
* id: pg.primaryKey(t.uuid()),
|
|
333
|
-
* sku: t.
|
|
334
|
-
* name: t.
|
|
335
|
-
* description: t.optional(t.
|
|
344
|
+
* sku: t.text({ minLength: 3 }),
|
|
345
|
+
* name: t.text({ minLength: 1, maxLength: 200 }),
|
|
346
|
+
* description: t.optional(t.text()),
|
|
336
347
|
* price: t.number({ minimum: 0 }),
|
|
337
|
-
* categoryId: t.
|
|
348
|
+
* categoryId: t.text({ format: "uuid" }),
|
|
338
349
|
* inStock: t.boolean({ default: true }),
|
|
339
350
|
* stockQuantity: t.integer({ minimum: 0, default: 0 }),
|
|
340
|
-
* tags: t.optional(t.array(t.
|
|
341
|
-
* metadata: t.optional(t.record(t.
|
|
351
|
+
* tags: t.optional(t.array(t.text())), // PostgreSQL array column
|
|
352
|
+
* metadata: t.optional(t.record(t.text(), t.any())), // JSONB column
|
|
342
353
|
* version: pg.version(),
|
|
343
354
|
* createdAt: pg.createdAt(),
|
|
344
355
|
* updatedAt: pg.updatedAt()
|
|
@@ -367,15 +378,15 @@ type PgTableWithColumnsAndSchema<T extends TableConfig, R extends TObject> = PgT
|
|
|
367
378
|
* name: "audit_logs",
|
|
368
379
|
* schema: t.object({
|
|
369
380
|
* id: pg.primaryKey(t.uuid()),
|
|
370
|
-
* tableName: t.
|
|
371
|
-
* recordId: t.
|
|
381
|
+
* tableName: t.text(),
|
|
382
|
+
* recordId: t.text(),
|
|
372
383
|
* action: t.enum(["CREATE", "UPDATE", "DELETE"]),
|
|
373
|
-
* userId: t.optional(t.
|
|
374
|
-
* oldValues: t.optional(t.record(t.
|
|
375
|
-
* newValues: t.optional(t.record(t.
|
|
384
|
+
* userId: t.optional(t.text({ format: "uuid" })),
|
|
385
|
+
* oldValues: t.optional(t.record(t.text(), t.any())),
|
|
386
|
+
* newValues: t.optional(t.record(t.text(), t.any())),
|
|
376
387
|
* timestamp: pg.createdAt(),
|
|
377
|
-
* ipAddress: t.optional(t.
|
|
378
|
-
* userAgent: t.optional(t.
|
|
388
|
+
* ipAddress: t.optional(t.text()),
|
|
389
|
+
* userAgent: t.optional(t.text())
|
|
379
390
|
* }),
|
|
380
391
|
* indexes: [
|
|
381
392
|
* "tableName",
|
|
@@ -403,9 +414,9 @@ type PgTableWithColumnsAndSchema<T extends TableConfig, R extends TObject> = PgT
|
|
|
403
414
|
* name: "user_roles",
|
|
404
415
|
* schema: t.object({
|
|
405
416
|
* id: pg.primaryKey(t.uuid()),
|
|
406
|
-
* userId: t.
|
|
407
|
-
* roleId: t.
|
|
408
|
-
* assignedBy: t.
|
|
417
|
+
* userId: t.text({ format: "uuid" }),
|
|
418
|
+
* roleId: t.text({ format: "uuid" }),
|
|
419
|
+
* assignedBy: t.text({ format: "uuid" }),
|
|
409
420
|
* assignedAt: pg.createdAt(),
|
|
410
421
|
* expiresAt: t.optional(t.datetime())
|
|
411
422
|
* }),
|
|
@@ -440,12 +451,12 @@ type PgTableWithColumnsAndSchema<T extends TableConfig, R extends TObject> = PgT
|
|
|
440
451
|
* name: "orders",
|
|
441
452
|
* schema: t.object({
|
|
442
453
|
* id: pg.primaryKey(t.uuid()),
|
|
443
|
-
* orderNumber: t.
|
|
444
|
-
* customerId: t.
|
|
454
|
+
* orderNumber: t.text(),
|
|
455
|
+
* customerId: t.text({ format: "uuid" }),
|
|
445
456
|
* status: t.enum(["pending", "processing", "shipped", "delivered"]),
|
|
446
457
|
* totalAmount: t.number({ minimum: 0 }),
|
|
447
|
-
* currency: t.
|
|
448
|
-
* notes: t.optional(t.
|
|
458
|
+
* currency: t.text({ default: "USD" }),
|
|
459
|
+
* notes: t.optional(t.text()),
|
|
449
460
|
* createdAt: pg.createdAt(),
|
|
450
461
|
* updatedAt: pg.updatedAt(),
|
|
451
462
|
* version: pg.version()
|
|
@@ -511,11 +522,11 @@ interface EntityDescriptorOptions<TTableName extends string, T extends TObject,
|
|
|
511
522
|
*
|
|
512
523
|
* **Supported PostgreSQL Types**:
|
|
513
524
|
* - `pg.primaryKey(t.uuid())` - UUID primary key
|
|
514
|
-
* - `t.
|
|
525
|
+
* - `t.text()` - VARCHAR column
|
|
515
526
|
* - `t.integer()`, `t.number()` - Numeric columns
|
|
516
527
|
* - `t.boolean()` - Boolean column
|
|
517
|
-
* - `t.array(t.
|
|
518
|
-
* - `t.record(t.
|
|
528
|
+
* - `t.array(t.text())` - PostgreSQL array column
|
|
529
|
+
* - `t.record(t.text(), t.any())` - JSONB column
|
|
519
530
|
* - `pg.createdAt()`, `pg.updatedAt()`, `pg.deletedAt()` - Audit timestamps
|
|
520
531
|
* - `pg.version()` - Optimistic locking version field
|
|
521
532
|
*
|
|
@@ -530,13 +541,13 @@ interface EntityDescriptorOptions<TTableName extends string, T extends TObject,
|
|
|
530
541
|
* ```ts
|
|
531
542
|
* t.object({
|
|
532
543
|
* id: pg.primaryKey(t.uuid()),
|
|
533
|
-
* email: t.
|
|
534
|
-
* firstName: t.
|
|
535
|
-
* lastName: t.
|
|
544
|
+
* email: t.text({ format: "email" }),
|
|
545
|
+
* firstName: t.text({ minLength: 1, maxLength: 100 }),
|
|
546
|
+
* lastName: t.text({ minLength: 1, maxLength: 100 }),
|
|
536
547
|
* age: t.optional(t.integer({ minimum: 0, maximum: 150 })),
|
|
537
548
|
* isActive: t.boolean({ default: true }),
|
|
538
|
-
* preferences: t.optional(t.record(t.
|
|
539
|
-
* tags: t.optional(t.array(t.
|
|
549
|
+
* preferences: t.optional(t.record(t.text(), t.any())),
|
|
550
|
+
* tags: t.optional(t.array(t.text())),
|
|
540
551
|
* createdAt: pg.createdAt(),
|
|
541
552
|
* updatedAt: pg.updatedAt(),
|
|
542
553
|
* version: pg.version()
|
|
@@ -756,6 +767,26 @@ declare class PgError extends AlephaError {
|
|
|
756
767
|
}
|
|
757
768
|
//#endregion
|
|
758
769
|
//#region src/helpers/pgAttr.d.ts
|
|
770
|
+
/**
|
|
771
|
+
* Decorates a typebox schema with a Postgres attribute.
|
|
772
|
+
*
|
|
773
|
+
* > It's just a fancy way to add Symbols to a field.
|
|
774
|
+
*
|
|
775
|
+
* @example
|
|
776
|
+
* ```ts
|
|
777
|
+
* import { t } from "alepha";
|
|
778
|
+
* import { PG_UPDATED_AT } from "../constants/PG_SYMBOLS";
|
|
779
|
+
*
|
|
780
|
+
* export const updatedAtSchema = pgAttr(
|
|
781
|
+
* t.datetime(), PG_UPDATED_AT,
|
|
782
|
+
* );
|
|
783
|
+
* ```
|
|
784
|
+
*/
|
|
785
|
+
declare const pgAttr: <T extends TSchema$1, Attr extends PgSymbolKeys>(type: T, attr: Attr, value?: PgSymbols[Attr]) => PgAttr<T, Attr>;
|
|
786
|
+
/**
|
|
787
|
+
* Retrieves the fields of a schema that have a specific attribute.
|
|
788
|
+
*/
|
|
789
|
+
declare const getAttrFields: (schema: TObject, name: PgSymbolKeys) => PgAttrField[];
|
|
759
790
|
/**
|
|
760
791
|
* Type representation.
|
|
761
792
|
*/
|
|
@@ -765,6 +796,7 @@ interface PgAttrField {
|
|
|
765
796
|
type: TSchema$1;
|
|
766
797
|
data: any;
|
|
767
798
|
nested?: any[];
|
|
799
|
+
one?: boolean;
|
|
768
800
|
}
|
|
769
801
|
//#endregion
|
|
770
802
|
//#region src/interfaces/FilterOperators.d.ts
|
|
@@ -1124,8 +1156,7 @@ interface FilterOperators<TValue> {
|
|
|
1124
1156
|
}
|
|
1125
1157
|
//#endregion
|
|
1126
1158
|
//#region src/interfaces/PgQueryWhere.d.ts
|
|
1127
|
-
type
|
|
1128
|
-
type PgQueryWhere<T extends object> = { [Key in keyof T]?: FilterOperators<T[Key]> | T[Key] } & {
|
|
1159
|
+
type PgQueryWhere<T extends TObject> = { [Key in keyof Static<T>]?: FilterOperators<Static<T>[Key]> | Static<T>[Key] } & {
|
|
1129
1160
|
/**
|
|
1130
1161
|
* Combine a list of conditions with the `and` operator. Conditions
|
|
1131
1162
|
* that are equal `undefined` are automatically ignored.
|
|
@@ -1194,6 +1225,26 @@ type PgQueryWhere<T extends object> = { [Key in keyof T]?: FilterOperators<T[Key
|
|
|
1194
1225
|
*/
|
|
1195
1226
|
exists?: SQLWrapper;
|
|
1196
1227
|
};
|
|
1228
|
+
type PgQueryWhereOrSQL<T extends TObject> = SQLWrapper | PgQueryWhere<T>;
|
|
1229
|
+
type PgQueryWhereWithManyOrSQL<T extends TObject> = SQLWrapper | PgQueryWhereWithMany<T>;
|
|
1230
|
+
type PgQueryWhereWithMany<T extends TObject> = PgQueryWhere<RemoveManyRelations<T>> & ExtractManyRelations<T>;
|
|
1231
|
+
type RelField = {
|
|
1232
|
+
[PG_MANY]: any;
|
|
1233
|
+
} | {
|
|
1234
|
+
[PG_ONE]: any;
|
|
1235
|
+
};
|
|
1236
|
+
type ExtractManyRelations<T extends TObject> = { [K in keyof T["properties"] as T["properties"][K] extends RelField ? T["properties"][K] extends TArray ? T["properties"][K]["items"] extends TObject ? K : never : never : T["properties"][K] extends TObject ? K : never]?: PgQueryWhere<T["properties"][K] extends TArray ? T["properties"][K]["items"] extends TObject ? T["properties"][K]["items"] : TObject : T["properties"][K] extends TObject ? T["properties"][K] : TObject> };
|
|
1237
|
+
type RemoveManyRelations<T extends TObject> = TObject<{ [K in keyof T["properties"] as T["properties"][K] extends RelField ? never : K]: T["properties"][K] }>;
|
|
1238
|
+
type PgQueryWithMap<T extends TObject> = { [K in keyof T["properties"] as T["properties"][K] extends RelField ? K : never]?: T["properties"][K] extends TArray ? T["properties"][K]["items"] extends TObject ? PgQueryWithMany<T["properties"][K]["items"]> : never : T["properties"][K] extends TObject ? PgQueryWithOne<T["properties"][K]> : T["properties"][K] extends PgAttr<PgAttr<TOptionalAdd<infer U>, PgOne>, PgDefault> ? U extends TObject ? PgQueryWithOne<U> : never : never };
|
|
1239
|
+
type PgQueryWithOne<T extends TObject> = true | {
|
|
1240
|
+
columns?: (keyof Static<T>)[];
|
|
1241
|
+
relations?: PgQueryWithMap<T>;
|
|
1242
|
+
};
|
|
1243
|
+
type PgQueryWithMany<T extends TObject> = true | {
|
|
1244
|
+
limit?: number;
|
|
1245
|
+
columns?: (keyof Static<T>)[];
|
|
1246
|
+
relations?: PgQueryWithMap<T>;
|
|
1247
|
+
};
|
|
1197
1248
|
//#endregion
|
|
1198
1249
|
//#region src/interfaces/PgQuery.d.ts
|
|
1199
1250
|
/**
|
|
@@ -1214,24 +1265,25 @@ interface OrderByClause<T> {
|
|
|
1214
1265
|
* 3. Array: orderBy: [{ column: "name", direction: "asc" }, { column: "age", direction: "desc" }]
|
|
1215
1266
|
*/
|
|
1216
1267
|
type OrderBy<T> = keyof T | OrderByClause<T> | Array<OrderByClause<T>>;
|
|
1217
|
-
interface PgQuery<T extends TObject> {
|
|
1268
|
+
interface PgQuery<T extends TObject = TObject> {
|
|
1218
1269
|
distinct?: boolean;
|
|
1219
|
-
where?:
|
|
1270
|
+
where?: PgQueryWhereWithMany<T> | SQLWrapper;
|
|
1220
1271
|
limit?: number;
|
|
1221
1272
|
offset?: number;
|
|
1222
1273
|
orderBy?: OrderBy<Static<T>>;
|
|
1223
1274
|
groupBy?: (keyof Static<T>)[];
|
|
1275
|
+
relations?: PgQueryWithMap<T>;
|
|
1224
1276
|
}
|
|
1225
|
-
type PgQueryResult<T extends TObject, Select extends (keyof Static<T>)[]> = TPick<T, TKeysToIndexer<Select>>;
|
|
1226
1277
|
//#endregion
|
|
1227
1278
|
//#region src/providers/drivers/PostgresProvider.d.ts
|
|
1228
1279
|
type SQLLike = SQLWrapper | string;
|
|
1229
1280
|
declare abstract class PostgresProvider {
|
|
1230
1281
|
protected readonly alepha: Alepha;
|
|
1231
1282
|
abstract get db(): PgDatabase<any>;
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1283
|
+
readonly dialect: "postgres" | "sqlite";
|
|
1284
|
+
get schema(): string;
|
|
1285
|
+
execute<T extends TObject | undefined>(query: SQLLike, schema?: T): Promise<Array<T extends TObject ? Static<T> : any>>;
|
|
1286
|
+
protected mapResult<T extends TObject = any>(result: Array<any>, schema?: T): Array<T extends TObject ? Static<T> : any>;
|
|
1235
1287
|
}
|
|
1236
1288
|
//#endregion
|
|
1237
1289
|
//#region src/schemas/pageQuerySchema.d.ts
|
|
@@ -1247,7 +1299,7 @@ type PageQuery = Static<typeof pageQuerySchema>;
|
|
|
1247
1299
|
* Create a pagination schema for the given object schema.
|
|
1248
1300
|
*
|
|
1249
1301
|
* @example
|
|
1250
|
-
* const userSchema = t.object({ id: t.int(), name: t.
|
|
1302
|
+
* const userSchema = t.object({ id: t.int(), name: t.text() });
|
|
1251
1303
|
* const pagedUserSchema = pageSchema(userSchema);
|
|
1252
1304
|
*
|
|
1253
1305
|
* @see {@link $repository#paginate}
|
|
@@ -1323,9 +1375,9 @@ type Page<T> = {
|
|
|
1323
1375
|
* name: "users",
|
|
1324
1376
|
* schema: t.object({
|
|
1325
1377
|
* id: pg.primaryKey(t.uuid()),
|
|
1326
|
-
* email: t.
|
|
1327
|
-
* firstName: t.
|
|
1328
|
-
* lastName: t.
|
|
1378
|
+
* email: t.text({ format: "email" }),
|
|
1379
|
+
* firstName: t.text(),
|
|
1380
|
+
* lastName: t.text(),
|
|
1329
1381
|
* isActive: t.boolean({ default: true }),
|
|
1330
1382
|
* createdAt: pg.createdAt(),
|
|
1331
1383
|
* updatedAt: pg.updatedAt()
|
|
@@ -1359,238 +1411,6 @@ type Page<T> = {
|
|
|
1359
1411
|
* }
|
|
1360
1412
|
* }
|
|
1361
1413
|
* ```
|
|
1362
|
-
*
|
|
1363
|
-
* @example
|
|
1364
|
-
* **Advanced querying and filtering:**
|
|
1365
|
-
* ```ts
|
|
1366
|
-
* const Product = $entity({
|
|
1367
|
-
* name: "products",
|
|
1368
|
-
* schema: t.object({
|
|
1369
|
-
* id: pg.primaryKey(t.uuid()),
|
|
1370
|
-
* name: t.string(),
|
|
1371
|
-
* price: t.number({ minimum: 0 }),
|
|
1372
|
-
* categoryId: t.string({ format: "uuid" }),
|
|
1373
|
-
* inStock: t.boolean(),
|
|
1374
|
-
* tags: t.optional(t.array(t.string())),
|
|
1375
|
-
* createdAt: pg.createdAt(),
|
|
1376
|
-
* updatedAt: pg.updatedAt()
|
|
1377
|
-
* }),
|
|
1378
|
-
* indexes: ["categoryId", "inStock", "price"]
|
|
1379
|
-
* });
|
|
1380
|
-
*
|
|
1381
|
-
* class ProductService {
|
|
1382
|
-
* products = $repository({ table: Product });
|
|
1383
|
-
*
|
|
1384
|
-
* async searchProducts(filters: {
|
|
1385
|
-
* categoryId?: string;
|
|
1386
|
-
* minPrice?: number;
|
|
1387
|
-
* maxPrice?: number;
|
|
1388
|
-
* inStock?: boolean;
|
|
1389
|
-
* searchTerm?: string;
|
|
1390
|
-
* }, page: number = 0, size: number = 20) {
|
|
1391
|
-
* const query = this.products.createQuery({
|
|
1392
|
-
* where: {
|
|
1393
|
-
* and: [
|
|
1394
|
-
* filters.categoryId ? { categoryId: filters.categoryId } : {},
|
|
1395
|
-
* filters.inStock !== undefined ? { inStock: filters.inStock } : {},
|
|
1396
|
-
* filters.minPrice ? { price: { gte: filters.minPrice } } : {},
|
|
1397
|
-
* filters.maxPrice ? { price: { lte: filters.maxPrice } } : {},
|
|
1398
|
-
* filters.searchTerm ? { name: { ilike: `%${filters.searchTerm}%` } } : {}
|
|
1399
|
-
* ]
|
|
1400
|
-
* },
|
|
1401
|
-
* orderBy: [{ column: "createdAt", direction: "desc" }]
|
|
1402
|
-
* });
|
|
1403
|
-
*
|
|
1404
|
-
* return await this.products.paginate({ page, size }, query, { count: true });
|
|
1405
|
-
* }
|
|
1406
|
-
*
|
|
1407
|
-
* async getTopSellingProducts(limit: number = 10) {
|
|
1408
|
-
* // Custom SQL query for complex analytics
|
|
1409
|
-
* return await this.products.query(
|
|
1410
|
-
* (table, db) => db
|
|
1411
|
-
* .select({
|
|
1412
|
-
* id: table.id,
|
|
1413
|
-
* name: table.name,
|
|
1414
|
-
* price: table.price,
|
|
1415
|
-
* salesCount: sql<number>`COALESCE(sales.count, 0)`
|
|
1416
|
-
* })
|
|
1417
|
-
* .from(table)
|
|
1418
|
-
* .leftJoin(
|
|
1419
|
-
* sql`(
|
|
1420
|
-
* SELECT product_id, COUNT(*) as count
|
|
1421
|
-
* FROM order_items
|
|
1422
|
-
* WHERE created_at > NOW() - INTERVAL '30 days'
|
|
1423
|
-
* GROUP BY product_id
|
|
1424
|
-
* ) sales`,
|
|
1425
|
-
* sql`sales.product_id = ${table.id}`
|
|
1426
|
-
* )
|
|
1427
|
-
* .orderBy(sql`sales.count DESC NULLS LAST`)
|
|
1428
|
-
* .limit(limit)
|
|
1429
|
-
* );
|
|
1430
|
-
* }
|
|
1431
|
-
* }
|
|
1432
|
-
* ```
|
|
1433
|
-
*
|
|
1434
|
-
* @example
|
|
1435
|
-
* **Transaction handling and data consistency:**
|
|
1436
|
-
* ```ts
|
|
1437
|
-
* class OrderService {
|
|
1438
|
-
* orders = $repository({ table: Order });
|
|
1439
|
-
* orderItems = $repository({ table: OrderItem });
|
|
1440
|
-
* products = $repository({ table: Product });
|
|
1441
|
-
*
|
|
1442
|
-
* async createOrderWithItems(orderData: {
|
|
1443
|
-
* customerId: string;
|
|
1444
|
-
* items: Array<{ productId: string; quantity: number; price: number }>;
|
|
1445
|
-
* }) {
|
|
1446
|
-
* return await this.orders.transaction(async (tx) => {
|
|
1447
|
-
* // Create the order
|
|
1448
|
-
* const order = await this.orders.create({
|
|
1449
|
-
* id: generateUUID(),
|
|
1450
|
-
* customerId: orderData.customerId,
|
|
1451
|
-
* status: 'pending',
|
|
1452
|
-
* totalAmount: orderData.items.reduce((sum, item) => sum + (item.price * item.quantity), 0)
|
|
1453
|
-
* }, { tx });
|
|
1454
|
-
*
|
|
1455
|
-
* // Create order items and update product inventory
|
|
1456
|
-
* for (const itemData of orderData.items) {
|
|
1457
|
-
* await this.orderItems.create({
|
|
1458
|
-
* id: generateUUID(),
|
|
1459
|
-
* orderId: order.id,
|
|
1460
|
-
* productId: itemData.productId,
|
|
1461
|
-
* quantity: itemData.quantity,
|
|
1462
|
-
* unitPrice: itemData.price
|
|
1463
|
-
* }, { tx });
|
|
1464
|
-
*
|
|
1465
|
-
* // Update product inventory using optimistic locking
|
|
1466
|
-
* const product = await this.products.findById(itemData.productId, { tx });
|
|
1467
|
-
* if (product.stockQuantity < itemData.quantity) {
|
|
1468
|
-
* throw new Error(`Insufficient stock for product ${itemData.productId}`);
|
|
1469
|
-
* }
|
|
1470
|
-
*
|
|
1471
|
-
* await this.products.save({
|
|
1472
|
-
* ...product,
|
|
1473
|
-
* stockQuantity: product.stockQuantity - itemData.quantity
|
|
1474
|
-
* }, { tx });
|
|
1475
|
-
* }
|
|
1476
|
-
*
|
|
1477
|
-
* return order;
|
|
1478
|
-
* });
|
|
1479
|
-
* }
|
|
1480
|
-
* }
|
|
1481
|
-
* ```
|
|
1482
|
-
*
|
|
1483
|
-
* @example
|
|
1484
|
-
* **Soft delete and audit trail:**
|
|
1485
|
-
* ```ts
|
|
1486
|
-
* const Document = $entity({
|
|
1487
|
-
* name: "documents",
|
|
1488
|
-
* schema: t.object({
|
|
1489
|
-
* id: pg.primaryKey(t.uuid()),
|
|
1490
|
-
* title: t.string(),
|
|
1491
|
-
* content: t.string(),
|
|
1492
|
-
* authorId: t.string({ format: "uuid" }),
|
|
1493
|
-
* version: pg.version(),
|
|
1494
|
-
* createdAt: pg.createdAt(),
|
|
1495
|
-
* updatedAt: pg.updatedAt(),
|
|
1496
|
-
* deletedAt: pg.deletedAt() // Enables soft delete
|
|
1497
|
-
* })
|
|
1498
|
-
* });
|
|
1499
|
-
*
|
|
1500
|
-
* class DocumentService {
|
|
1501
|
-
* documents = $repository({ table: Document });
|
|
1502
|
-
*
|
|
1503
|
-
* async updateDocument(id: string, updates: { title?: string; content?: string }) {
|
|
1504
|
-
* // This uses optimistic locking via the version field
|
|
1505
|
-
* const document = await this.documents.findById(id);
|
|
1506
|
-
* return await this.documents.save({
|
|
1507
|
-
* ...document,
|
|
1508
|
-
* ...updates // updatedAt will be set automatically
|
|
1509
|
-
* });
|
|
1510
|
-
* }
|
|
1511
|
-
*
|
|
1512
|
-
* async softDeleteDocument(id: string) {
|
|
1513
|
-
* // Soft delete - sets deletedAt timestamp
|
|
1514
|
-
* await this.documents.deleteById(id);
|
|
1515
|
-
* }
|
|
1516
|
-
*
|
|
1517
|
-
* async permanentDeleteDocument(id: string) {
|
|
1518
|
-
* // Hard delete - actually removes from database
|
|
1519
|
-
* await this.documents.deleteById(id, { force: true });
|
|
1520
|
-
* }
|
|
1521
|
-
*
|
|
1522
|
-
* async getActiveDocuments() {
|
|
1523
|
-
* // Automatically excludes soft-deleted records
|
|
1524
|
-
* return await this.documents.find({
|
|
1525
|
-
* where: { authorId: { isNotNull: true } },
|
|
1526
|
-
* orderBy: [{ column: "updatedAt", direction: "desc" }]
|
|
1527
|
-
* });
|
|
1528
|
-
* }
|
|
1529
|
-
*
|
|
1530
|
-
* async getAllDocumentsIncludingDeleted() {
|
|
1531
|
-
* // Include soft-deleted records
|
|
1532
|
-
* return await this.documents.find({}, { force: true });
|
|
1533
|
-
* }
|
|
1534
|
-
* }
|
|
1535
|
-
* ```
|
|
1536
|
-
*
|
|
1537
|
-
* @example
|
|
1538
|
-
* **Complex filtering and aggregation:**
|
|
1539
|
-
* ```ts
|
|
1540
|
-
* class AnalyticsService {
|
|
1541
|
-
* users = $repository({ table: User });
|
|
1542
|
-
* orders = $repository({ table: Order });
|
|
1543
|
-
*
|
|
1544
|
-
* async getUserStatistics(filters: {
|
|
1545
|
-
* startDate?: string;
|
|
1546
|
-
* endDate?: string;
|
|
1547
|
-
* isActive?: boolean;
|
|
1548
|
-
* }) {
|
|
1549
|
-
* const whereConditions = [];
|
|
1550
|
-
*
|
|
1551
|
-
* if (filters.startDate) {
|
|
1552
|
-
* whereConditions.push({ createdAt: { gte: filters.startDate } });
|
|
1553
|
-
* }
|
|
1554
|
-
* if (filters.endDate) {
|
|
1555
|
-
* whereConditions.push({ createdAt: { lte: filters.endDate } });
|
|
1556
|
-
* }
|
|
1557
|
-
* if (filters.isActive !== undefined) {
|
|
1558
|
-
* whereConditions.push({ isActive: filters.isActive });
|
|
1559
|
-
* }
|
|
1560
|
-
*
|
|
1561
|
-
* const totalUsers = await this.users.count({
|
|
1562
|
-
* and: whereConditions
|
|
1563
|
-
* });
|
|
1564
|
-
*
|
|
1565
|
-
* const activeUsers = await this.users.count({
|
|
1566
|
-
* and: [...whereConditions, { isActive: true }]
|
|
1567
|
-
* });
|
|
1568
|
-
*
|
|
1569
|
-
* // Complex aggregation query
|
|
1570
|
-
* const recentActivity = await this.users.query(
|
|
1571
|
-
* sql`
|
|
1572
|
-
* SELECT
|
|
1573
|
-
* DATE_TRUNC('day', created_at) as date,
|
|
1574
|
-
* COUNT(*) as new_users,
|
|
1575
|
-
* COUNT(*) FILTER (WHERE is_active = true) as active_users
|
|
1576
|
-
* FROM users
|
|
1577
|
-
* WHERE created_at >= NOW() - INTERVAL '30 days'
|
|
1578
|
-
* GROUP BY DATE_TRUNC('day', created_at)
|
|
1579
|
-
* ORDER BY date DESC
|
|
1580
|
-
* `
|
|
1581
|
-
* );
|
|
1582
|
-
*
|
|
1583
|
-
* return {
|
|
1584
|
-
* totalUsers,
|
|
1585
|
-
* activeUsers,
|
|
1586
|
-
* inactiveUsers: totalUsers - activeUsers,
|
|
1587
|
-
* recentActivity
|
|
1588
|
-
* };
|
|
1589
|
-
* }
|
|
1590
|
-
* }
|
|
1591
|
-
* ```
|
|
1592
|
-
*
|
|
1593
|
-
* @stability 3
|
|
1594
1414
|
*/
|
|
1595
1415
|
declare const $repository: {
|
|
1596
1416
|
<EntityTableConfig extends TableConfig, EntitySchema extends TObject>(optionsOrTable: RepositoryDescriptorOptions<EntityTableConfig, EntitySchema> | PgTableWithColumnsAndSchema<EntityTableConfig, EntitySchema>): RepositoryDescriptor<EntityTableConfig, EntitySchema>;
|
|
@@ -1623,8 +1443,8 @@ interface RepositoryDescriptorOptions<EntityTableConfig extends TableConfig, Ent
|
|
|
1623
1443
|
* name: "users",
|
|
1624
1444
|
* schema: t.object({
|
|
1625
1445
|
* id: pg.primaryKey(t.uuid()),
|
|
1626
|
-
* email: t.
|
|
1627
|
-
* name: t.
|
|
1446
|
+
* email: t.text({ format: "email" }),
|
|
1447
|
+
* name: t.text()
|
|
1628
1448
|
* })
|
|
1629
1449
|
* });
|
|
1630
1450
|
*
|
|
@@ -1685,7 +1505,7 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
|
|
|
1685
1505
|
/**
|
|
1686
1506
|
* Getter for the database connection from the database provider.
|
|
1687
1507
|
*/
|
|
1688
|
-
protected get db(): PgDatabase<any, Record<string, never>,
|
|
1508
|
+
protected get db(): PgDatabase<any, Record<string, never>, drizzle_orm7.ExtractTablesWithRelations<Record<string, never>>>;
|
|
1689
1509
|
/**
|
|
1690
1510
|
* Execute a SQL query.
|
|
1691
1511
|
*/
|
|
@@ -1710,10 +1530,10 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
|
|
|
1710
1530
|
*
|
|
1711
1531
|
* @returns The SELECT query builder.
|
|
1712
1532
|
*/
|
|
1713
|
-
protected select(opts?: StatementOptions): pg$1.PgSelectBase<string, Record<string, PgColumn<
|
|
1533
|
+
protected select(opts?: StatementOptions): pg$1.PgSelectBase<string, Record<string, PgColumn<drizzle_orm7.ColumnBaseConfig<drizzle_orm7.ColumnDataType, string>, {}, {}>>, "single", Record<string, "not-null">, false, never, {
|
|
1714
1534
|
[x: string]: unknown;
|
|
1715
1535
|
}[], {
|
|
1716
|
-
[x: string]: PgColumn<
|
|
1536
|
+
[x: string]: PgColumn<drizzle_orm7.ColumnBaseConfig<drizzle_orm7.ColumnDataType, string>, {}, {}>;
|
|
1717
1537
|
}>;
|
|
1718
1538
|
protected selectDistinct(opts: StatementOptions | undefined, fields: SelectedFields): pg$1.PgSelectBase<string, SelectedFields, "partial", Record<string, "not-null">, false, never, {
|
|
1719
1539
|
[x: string]: unknown;
|
|
@@ -1753,7 +1573,7 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
|
|
|
1753
1573
|
* @param opts The statement options.
|
|
1754
1574
|
* @returns The found entity.
|
|
1755
1575
|
*/
|
|
1756
|
-
findOne<T extends
|
|
1576
|
+
findOne<T extends EntitySchema = EntitySchema>(where: PgQueryWhereOrSQL<T>, opts?: StatementOptions): Promise<Static<EntitySchema>>;
|
|
1757
1577
|
/**
|
|
1758
1578
|
* Find an entity by ID.
|
|
1759
1579
|
*/
|
|
@@ -1765,7 +1585,7 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
|
|
|
1765
1585
|
count?: boolean;
|
|
1766
1586
|
}): Promise<Page<Static<EntitySchema>>>;
|
|
1767
1587
|
createQuery(query?: PgQuery<EntitySchema>): PgQuery<EntitySchema>;
|
|
1768
|
-
createQueryWhere(where?: PgQueryWhere<
|
|
1588
|
+
createQueryWhere(where?: PgQueryWhere<EntitySchema>): PgQueryWhere<EntitySchema>;
|
|
1769
1589
|
/**
|
|
1770
1590
|
* Create an entity.
|
|
1771
1591
|
*
|
|
@@ -1785,7 +1605,7 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
|
|
|
1785
1605
|
/**
|
|
1786
1606
|
* Find an entity and update it.
|
|
1787
1607
|
*/
|
|
1788
|
-
updateOne(where: PgQueryWhereOrSQL<
|
|
1608
|
+
updateOne(where: PgQueryWhereOrSQL<EntitySchema>, data: Partial<Static<TObjectUpdate<EntitySchema>>>, opts?: StatementOptions): Promise<Static<EntitySchema>>;
|
|
1789
1609
|
/**
|
|
1790
1610
|
* Save a given entity.
|
|
1791
1611
|
*
|
|
@@ -1815,11 +1635,11 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
|
|
|
1815
1635
|
/**
|
|
1816
1636
|
* Find many entities and update all of them.
|
|
1817
1637
|
*/
|
|
1818
|
-
updateMany(where: PgQueryWhereOrSQL<
|
|
1638
|
+
updateMany(where: PgQueryWhereOrSQL<EntitySchema>, data: Partial<Static<TObjectUpdate<EntitySchema>>>, opts?: StatementOptions): Promise<void>;
|
|
1819
1639
|
/**
|
|
1820
1640
|
* Find many and delete all of them.
|
|
1821
1641
|
*/
|
|
1822
|
-
deleteMany(where?:
|
|
1642
|
+
deleteMany(where?: PgQueryWhereOrSQL<EntitySchema>, opts?: StatementOptions): Promise<void>;
|
|
1823
1643
|
/**
|
|
1824
1644
|
* Delete all entities.
|
|
1825
1645
|
*/
|
|
@@ -1833,7 +1653,7 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
|
|
|
1833
1653
|
/**
|
|
1834
1654
|
* Find an entity and delete it.
|
|
1835
1655
|
*/
|
|
1836
|
-
deleteOne(where?:
|
|
1656
|
+
deleteOne(where?: PgQueryWhereOrSQL<EntitySchema>, opts?: StatementOptions): Promise<void>;
|
|
1837
1657
|
/**
|
|
1838
1658
|
* Find an entity by ID and delete it.
|
|
1839
1659
|
*/
|
|
@@ -1841,12 +1661,12 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
|
|
|
1841
1661
|
/**
|
|
1842
1662
|
* Count entities.
|
|
1843
1663
|
*/
|
|
1844
|
-
count(where?: PgQueryWhereOrSQL<
|
|
1664
|
+
count(where?: PgQueryWhereOrSQL<EntitySchema>, opts?: StatementOptions): Promise<number>;
|
|
1845
1665
|
protected conflictMessagePattern: string;
|
|
1846
1666
|
protected handleError(error: unknown, message: string): PgError;
|
|
1847
|
-
protected withDeletedAt(where: PgQueryWhereOrSQL<
|
|
1667
|
+
protected withDeletedAt(where: PgQueryWhereOrSQL<EntitySchema>, opts?: {
|
|
1848
1668
|
force?: boolean;
|
|
1849
|
-
}): PgQueryWhereOrSQL<
|
|
1669
|
+
}): PgQueryWhereOrSQL<EntitySchema>;
|
|
1850
1670
|
protected get organization(): undefined;
|
|
1851
1671
|
protected deletedAt(): PgAttrField | undefined;
|
|
1852
1672
|
/**
|
|
@@ -1856,7 +1676,7 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
|
|
|
1856
1676
|
* @param schema The schema to use.
|
|
1857
1677
|
* @param col The column to use.
|
|
1858
1678
|
*/
|
|
1859
|
-
protected jsonQueryToSql(query: PgQueryWhereOrSQL<
|
|
1679
|
+
protected jsonQueryToSql(query: PgQueryWhereOrSQL<EntitySchema>, schema?: TObject, col?: (key: string) => PgColumn): SQL | undefined;
|
|
1860
1680
|
/**
|
|
1861
1681
|
* Map a filter operator to a SQL query.
|
|
1862
1682
|
*
|
|
@@ -1921,7 +1741,7 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
|
|
|
1921
1741
|
* @param id The ID to get the where clause for.
|
|
1922
1742
|
* @returns The where clause for the ID.
|
|
1923
1743
|
*/
|
|
1924
|
-
protected getWhereId(id: string | number):
|
|
1744
|
+
protected getWhereId(id: string | number): PgQueryWhereOrSQL<EntitySchema>;
|
|
1925
1745
|
/**
|
|
1926
1746
|
* Find a primary key in the schema.
|
|
1927
1747
|
*
|
|
@@ -1930,7 +1750,7 @@ declare class RepositoryDescriptor<EntityTableConfig extends TableConfig, Entity
|
|
|
1930
1750
|
*/
|
|
1931
1751
|
protected getPrimaryKey(schema: TObject): {
|
|
1932
1752
|
key: string;
|
|
1933
|
-
col: PgColumn<
|
|
1753
|
+
col: PgColumn<drizzle_orm7.ColumnBaseConfig<drizzle_orm7.ColumnDataType, string>, {}, {}>;
|
|
1934
1754
|
type: TSchema$1;
|
|
1935
1755
|
};
|
|
1936
1756
|
}
|
|
@@ -2498,7 +2318,9 @@ declare class DrizzleKitProvider {
|
|
|
2498
2318
|
* @returns A promise that resolves once the migrations have been executed.
|
|
2499
2319
|
*/
|
|
2500
2320
|
synchronize(provider: PostgresProvider, schema?: string): Promise<void>;
|
|
2501
|
-
|
|
2321
|
+
/**
|
|
2322
|
+
* Get all tables from the provider's repositories.
|
|
2323
|
+
*/
|
|
2502
2324
|
protected getTables(provider: PostgresProvider, schema?: string): Promise<Record<string, any>>;
|
|
2503
2325
|
protected loadMigrationSnapshot(provider: PostgresProvider): Promise<any>;
|
|
2504
2326
|
protected saveMigrationSnapshot(provider: PostgresProvider, curr: Record<string, any>, entry?: {
|
|
@@ -2511,14 +2333,15 @@ declare class DrizzleKitProvider {
|
|
|
2511
2333
|
* Try to load the official Drizzle Kit API.
|
|
2512
2334
|
* If not available, fallback to the local kit import.
|
|
2513
2335
|
*/
|
|
2514
|
-
protected importDrizzleKit():
|
|
2336
|
+
protected importDrizzleKit(): typeof DrizzleKit;
|
|
2337
|
+
synchronizeSqlite(provider: PostgresProvider): Promise<void>;
|
|
2515
2338
|
}
|
|
2516
2339
|
//#endregion
|
|
2517
2340
|
//#region src/providers/drivers/NodePostgresProvider.d.ts
|
|
2518
2341
|
declare module "alepha" {
|
|
2519
2342
|
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
2520
2343
|
}
|
|
2521
|
-
declare const envSchema: TObject<{
|
|
2344
|
+
declare const envSchema: _alepha_core1.TObject<{
|
|
2522
2345
|
/**
|
|
2523
2346
|
* Main configuration for database connection.
|
|
2524
2347
|
* Accept a string in the format of a Postgres connection URL.
|
|
@@ -2580,18 +2403,11 @@ declare class NodePostgresProvider extends PostgresProvider {
|
|
|
2580
2403
|
*/
|
|
2581
2404
|
get schema(): string;
|
|
2582
2405
|
get db(): PostgresJsDatabase;
|
|
2583
|
-
protected readonly
|
|
2584
|
-
protected readonly
|
|
2585
|
-
execute<T extends TObject | undefined = undefined>(query: SQLLike, schema?: T): Promise<Array<T extends TObject ? Static<T> : any>>;
|
|
2406
|
+
protected readonly onStart: _alepha_core1.HookDescriptor<"start">;
|
|
2407
|
+
protected readonly onStop: _alepha_core1.HookDescriptor<"stop">;
|
|
2586
2408
|
connect(): Promise<void>;
|
|
2587
2409
|
close(): Promise<void>;
|
|
2588
2410
|
protected migrate: _alepha_lock0.LockDescriptor<() => Promise<void>>;
|
|
2589
|
-
protected createClient(): {
|
|
2590
|
-
client: postgres.Sql<{}>;
|
|
2591
|
-
db: PostgresJsDatabase<Record<string, never>> & {
|
|
2592
|
-
$client: postgres.Sql<{}>;
|
|
2593
|
-
};
|
|
2594
|
-
};
|
|
2595
2411
|
/**
|
|
2596
2412
|
* Generate a minimal migration configuration.
|
|
2597
2413
|
*/
|
|
@@ -2605,12 +2421,8 @@ declare class NodePostgresProvider extends PostgresProvider {
|
|
|
2605
2421
|
* For testing purposes, generate a unique schema name.
|
|
2606
2422
|
* The schema name will be generated based on the current date and time.
|
|
2607
2423
|
* It will be in the format of `test_YYYYMMDD_HHMMSS_randomSuffix`.
|
|
2608
|
-
*
|
|
2609
|
-
* TODO: investigate for adding the test file name to the schema name if possible.
|
|
2610
|
-
* TODO: options to skip deletion on failure, in order to inspect the schema?
|
|
2611
2424
|
*/
|
|
2612
2425
|
protected generateTestSchemaName(): string;
|
|
2613
|
-
protected mapResult<T extends TObject = any>(result: Array<any>, schema?: T): Array<T extends TObject ? Static<T> : any>;
|
|
2614
2426
|
}
|
|
2615
2427
|
//#endregion
|
|
2616
2428
|
//#region src/providers/PostgresTypeProvider.d.ts
|
|
@@ -2681,6 +2493,8 @@ declare class PostgresTypeProvider {
|
|
|
2681
2493
|
* It's used by {@link RepositoryDescriptor#paginate} method.
|
|
2682
2494
|
*/
|
|
2683
2495
|
readonly page: <T extends TObject>(resource: T, options?: TObjectOptions) => TPage<T>;
|
|
2496
|
+
readonly many: <T extends TObject, Config extends TableConfig>(table: PgTableWithColumnsAndSchema<Config, T>, foreignKey: keyof T["properties"]) => TOptionalAdd<PgAttr<PgAttr<TArray<T>, PgMany>, PgDefault>>;
|
|
2497
|
+
readonly one: <T extends TObject, Config extends TableConfig>(table: PgTableWithColumnsAndSchema<Config, T>, foreignKey: keyof T["properties"]) => PgAttr<PgAttr<TOptionalAdd<T>, PgOne>, PgDefault>;
|
|
2684
2498
|
}
|
|
2685
2499
|
declare const pg: PostgresTypeProvider;
|
|
2686
2500
|
//#endregion
|
|
@@ -2694,7 +2508,7 @@ declare const legacyIdSchema: PgAttr<PgAttr<PgAttr<typebox1.TInteger, typeof PG_
|
|
|
2694
2508
|
/**
|
|
2695
2509
|
* Postgres schema type.
|
|
2696
2510
|
*/
|
|
2697
|
-
declare const schema: <TDocument extends TSchema$1>(name: string, document: TDocument) =>
|
|
2511
|
+
declare const schema: <TDocument extends TSchema$1>(name: string, document: TDocument) => drizzle_orm7.$Type<pg$1.PgCustomColumnBuilder<{
|
|
2698
2512
|
name: string;
|
|
2699
2513
|
dataType: "custom";
|
|
2700
2514
|
columnType: "PgCustomColumn";
|
|
@@ -2712,8 +2526,8 @@ declare const schema: <TDocument extends TSchema$1>(name: string, document: TDoc
|
|
|
2712
2526
|
* name: "users",
|
|
2713
2527
|
* schema: t.object({
|
|
2714
2528
|
* id: pg.primaryKey(),
|
|
2715
|
-
* name: t.
|
|
2716
|
-
* email: t.
|
|
2529
|
+
* name: t.text(),
|
|
2530
|
+
* email: t.text(),
|
|
2717
2531
|
* }),
|
|
2718
2532
|
* });
|
|
2719
2533
|
*
|
|
@@ -2746,5 +2560,5 @@ declare const schema: <TDocument extends TSchema$1>(name: string, document: TDoc
|
|
|
2746
2560
|
*/
|
|
2747
2561
|
declare const AlephaPostgres: _alepha_core1.Service<_alepha_core1.Module<{}>>;
|
|
2748
2562
|
//#endregion
|
|
2749
|
-
export { $entity, $repository, $sequence, $transaction, AlephaPostgres, DrizzleKitProvider, Entity, EntityDescriptorOptions, FilterOperators, FromSchema, NodePostgresProvider, NodePostgresProviderOptions, OrderBy, OrderByClause, OrderDirection, PG_CREATED_AT, PG_DEFAULT, PG_DELETED_AT, PG_IDENTITY, PG_PRIMARY_KEY, PG_REF, PG_SCHEMA, PG_SERIAL, PG_UPDATED_AT, PG_VERSION, Page, PageQuery, PgDefault, PgEntityNotFoundError, PgIdentityOptions, PgPrimaryKey, PgQuery,
|
|
2563
|
+
export { $entity, $repository, $sequence, $transaction, AlephaPostgres, DrizzleKitProvider, Entity, EntityDescriptorOptions, ExtractManyRelations, FilterOperators, FromSchema, NodePostgresProvider, NodePostgresProviderOptions, OrderBy, OrderByClause, OrderDirection, PG_CREATED_AT, PG_DEFAULT, PG_DELETED_AT, PG_IDENTITY, PG_MANY, PG_ONE, PG_PRIMARY_KEY, PG_REF, PG_SCHEMA, PG_SERIAL, PG_UPDATED_AT, PG_VERSION, Page, PageQuery, PgAttr, PgAttrField, PgDefault, PgEntityNotFoundError, PgIdentityOptions, PgMany, PgManyOptions, PgOne, PgPrimaryKey, PgQuery, PgQueryWhere, PgQueryWhereOrSQL, PgQueryWhereWithMany, PgQueryWhereWithManyOrSQL, PgQueryWithMany, PgQueryWithMap, PgQueryWithOne, PgRef, PgRefOptions, PgSymbolKeys, PgSymbols, PgTableConfig, PgTableWithColumnsAndSchema, PostgresProvider, PostgresTypeProvider, RelField, RemoveManyRelations, RepositoryDescriptor, RepositoryDescriptorOptions, RepositoryProvider, SQLLike, SequenceDescriptor, SequenceDescriptorOptions, StatementOptions, TObjectInsert, TObjectUpdate, TPage, TransactionContext, TransactionDescriptorOptions, camelToSnakeCase, drizzle_orm7 as drizzle, getAttrFields, insertSchema, legacyIdSchema, mapFieldToColumn, mapStringToColumn, pageQuerySchema, pageSchema, pg, pgAttr, schema, schemaToPgColumns, sql, updateSchema };
|
|
2750
2564
|
//# sourceMappingURL=index.d.ts.map
|