alepha 0.12.1 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-notifications/index.d.ts +111 -111
- package/dist/api-users/index.d.ts +1240 -1240
- package/dist/api-verifications/index.d.ts +94 -94
- package/dist/cli/{dist-Sz2EXvQX.cjs → dist-Dl9Vl7Ur.js} +17 -13
- package/dist/cli/{dist-BBPjuQ56.js.map → dist-Dl9Vl7Ur.js.map} +1 -1
- package/dist/cli/index.d.ts +3 -11
- package/dist/cli/index.js +106 -74
- package/dist/cli/index.js.map +1 -1
- package/dist/email/index.js +71 -73
- package/dist/email/index.js.map +1 -1
- package/dist/orm/index.d.ts +1 -1
- package/dist/orm/index.js.map +1 -1
- package/dist/queue/index.d.ts +4 -4
- package/dist/redis/index.d.ts +10 -10
- package/dist/retry/index.d.ts +1 -1
- package/dist/retry/index.js +2 -2
- package/dist/retry/index.js.map +1 -1
- package/dist/scheduler/index.d.ts +6 -6
- package/dist/server/index.js +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server-auth/index.d.ts +193 -193
- package/dist/server-health/index.d.ts +17 -17
- package/dist/server-links/index.d.ts +34 -34
- package/dist/server-metrics/index.js +170 -174
- package/dist/server-metrics/index.js.map +1 -1
- package/dist/server-security/index.d.ts +9 -9
- package/dist/vite/index.js +4 -5
- package/dist/vite/index.js.map +1 -1
- package/dist/websocket/index.d.ts +7 -7
- package/package.json +52 -103
- package/src/cli/apps/AlephaPackageBuilderCli.ts +7 -2
- package/src/cli/assets/appRouterTs.ts +9 -0
- package/src/cli/assets/indexHtml.ts +2 -1
- package/src/cli/assets/mainBrowserTs.ts +10 -0
- package/src/cli/commands/CoreCommands.ts +6 -5
- package/src/cli/commands/DrizzleCommands.ts +65 -57
- package/src/cli/commands/VerifyCommands.ts +1 -1
- package/src/cli/services/ProjectUtils.ts +44 -38
- package/src/orm/providers/DrizzleKitProvider.ts +1 -1
- package/src/retry/descriptors/$retry.ts +5 -3
- package/src/server/providers/NodeHttpServerProvider.ts +1 -1
- package/src/vite/helpers/boot.ts +3 -3
- package/dist/api-files/index.cjs +0 -1293
- package/dist/api-files/index.cjs.map +0 -1
- package/dist/api-files/index.d.cts +0 -829
- package/dist/api-jobs/index.cjs +0 -274
- package/dist/api-jobs/index.cjs.map +0 -1
- package/dist/api-jobs/index.d.cts +0 -654
- package/dist/api-notifications/index.cjs +0 -380
- package/dist/api-notifications/index.cjs.map +0 -1
- package/dist/api-notifications/index.d.cts +0 -289
- package/dist/api-parameters/index.cjs +0 -66
- package/dist/api-parameters/index.cjs.map +0 -1
- package/dist/api-parameters/index.d.cts +0 -84
- package/dist/api-users/index.cjs +0 -6009
- package/dist/api-users/index.cjs.map +0 -1
- package/dist/api-users/index.d.cts +0 -4740
- package/dist/api-verifications/index.cjs +0 -407
- package/dist/api-verifications/index.cjs.map +0 -1
- package/dist/api-verifications/index.d.cts +0 -207
- package/dist/batch/index.cjs +0 -408
- package/dist/batch/index.cjs.map +0 -1
- package/dist/batch/index.d.cts +0 -330
- package/dist/bin/index.cjs +0 -17
- package/dist/bin/index.cjs.map +0 -1
- package/dist/bin/index.d.cts +0 -1
- package/dist/bucket/index.cjs +0 -303
- package/dist/bucket/index.cjs.map +0 -1
- package/dist/bucket/index.d.cts +0 -355
- package/dist/cache/index.cjs +0 -241
- package/dist/cache/index.cjs.map +0 -1
- package/dist/cache/index.d.cts +0 -202
- package/dist/cache-redis/index.cjs +0 -84
- package/dist/cache-redis/index.cjs.map +0 -1
- package/dist/cache-redis/index.d.cts +0 -40
- package/dist/cli/chunk-DSlc6foC.cjs +0 -43
- package/dist/cli/dist-BBPjuQ56.js +0 -2778
- package/dist/cli/dist-Sz2EXvQX.cjs.map +0 -1
- package/dist/cli/index.cjs +0 -1241
- package/dist/cli/index.cjs.map +0 -1
- package/dist/cli/index.d.cts +0 -422
- package/dist/command/index.cjs +0 -693
- package/dist/command/index.cjs.map +0 -1
- package/dist/command/index.d.cts +0 -340
- package/dist/core/index.cjs +0 -2264
- package/dist/core/index.cjs.map +0 -1
- package/dist/core/index.d.cts +0 -1927
- package/dist/datetime/index.cjs +0 -318
- package/dist/datetime/index.cjs.map +0 -1
- package/dist/datetime/index.d.cts +0 -145
- package/dist/email/index.cjs +0 -10874
- package/dist/email/index.cjs.map +0 -1
- package/dist/email/index.d.cts +0 -186
- package/dist/fake/index.cjs +0 -34641
- package/dist/fake/index.cjs.map +0 -1
- package/dist/fake/index.d.cts +0 -74
- package/dist/file/index.cjs +0 -1212
- package/dist/file/index.cjs.map +0 -1
- package/dist/file/index.d.cts +0 -698
- package/dist/lock/index.cjs +0 -226
- package/dist/lock/index.cjs.map +0 -1
- package/dist/lock/index.d.cts +0 -361
- package/dist/lock-redis/index.cjs +0 -113
- package/dist/lock-redis/index.cjs.map +0 -1
- package/dist/lock-redis/index.d.cts +0 -24
- package/dist/logger/index.cjs +0 -521
- package/dist/logger/index.cjs.map +0 -1
- package/dist/logger/index.d.cts +0 -281
- package/dist/orm/index.cjs +0 -2986
- package/dist/orm/index.cjs.map +0 -1
- package/dist/orm/index.d.cts +0 -2213
- package/dist/queue/index.cjs +0 -1044
- package/dist/queue/index.cjs.map +0 -1
- package/dist/queue/index.d.cts +0 -1265
- package/dist/queue-redis/index.cjs +0 -873
- package/dist/queue-redis/index.cjs.map +0 -1
- package/dist/queue-redis/index.d.cts +0 -82
- package/dist/redis/index.cjs +0 -153
- package/dist/redis/index.cjs.map +0 -1
- package/dist/redis/index.d.cts +0 -82
- package/dist/retry/index.cjs +0 -146
- package/dist/retry/index.cjs.map +0 -1
- package/dist/retry/index.d.cts +0 -172
- package/dist/router/index.cjs +0 -111
- package/dist/router/index.cjs.map +0 -1
- package/dist/router/index.d.cts +0 -46
- package/dist/scheduler/index.cjs +0 -576
- package/dist/scheduler/index.cjs.map +0 -1
- package/dist/scheduler/index.d.cts +0 -145
- package/dist/security/index.cjs +0 -2402
- package/dist/security/index.cjs.map +0 -1
- package/dist/security/index.d.cts +0 -598
- package/dist/server/index.cjs +0 -1680
- package/dist/server/index.cjs.map +0 -1
- package/dist/server/index.d.cts +0 -810
- package/dist/server-auth/index.cjs +0 -3146
- package/dist/server-auth/index.cjs.map +0 -1
- package/dist/server-auth/index.d.cts +0 -1164
- package/dist/server-cache/index.cjs +0 -252
- package/dist/server-cache/index.cjs.map +0 -1
- package/dist/server-cache/index.d.cts +0 -164
- package/dist/server-compress/index.cjs +0 -141
- package/dist/server-compress/index.cjs.map +0 -1
- package/dist/server-compress/index.d.cts +0 -38
- package/dist/server-cookies/index.cjs +0 -234
- package/dist/server-cookies/index.cjs.map +0 -1
- package/dist/server-cookies/index.d.cts +0 -144
- package/dist/server-cors/index.cjs +0 -201
- package/dist/server-cors/index.cjs.map +0 -1
- package/dist/server-cors/index.d.cts +0 -140
- package/dist/server-health/index.cjs +0 -62
- package/dist/server-health/index.cjs.map +0 -1
- package/dist/server-health/index.d.cts +0 -58
- package/dist/server-helmet/index.cjs +0 -131
- package/dist/server-helmet/index.cjs.map +0 -1
- package/dist/server-helmet/index.d.cts +0 -97
- package/dist/server-links/index.cjs +0 -992
- package/dist/server-links/index.cjs.map +0 -1
- package/dist/server-links/index.d.cts +0 -513
- package/dist/server-metrics/index.cjs +0 -4535
- package/dist/server-metrics/index.cjs.map +0 -1
- package/dist/server-metrics/index.d.cts +0 -35
- package/dist/server-multipart/index.cjs +0 -237
- package/dist/server-multipart/index.cjs.map +0 -1
- package/dist/server-multipart/index.d.cts +0 -50
- package/dist/server-proxy/index.cjs +0 -186
- package/dist/server-proxy/index.cjs.map +0 -1
- package/dist/server-proxy/index.d.cts +0 -234
- package/dist/server-rate-limit/index.cjs +0 -241
- package/dist/server-rate-limit/index.cjs.map +0 -1
- package/dist/server-rate-limit/index.d.cts +0 -183
- package/dist/server-security/index.cjs +0 -316
- package/dist/server-security/index.cjs.map +0 -1
- package/dist/server-security/index.d.cts +0 -173
- package/dist/server-static/index.cjs +0 -170
- package/dist/server-static/index.cjs.map +0 -1
- package/dist/server-static/index.d.cts +0 -121
- package/dist/server-swagger/index.cjs +0 -1021
- package/dist/server-swagger/index.cjs.map +0 -1
- package/dist/server-swagger/index.d.cts +0 -382
- package/dist/sms/index.cjs +0 -221
- package/dist/sms/index.cjs.map +0 -1
- package/dist/sms/index.d.cts +0 -130
- package/dist/thread/index.cjs +0 -350
- package/dist/thread/index.cjs.map +0 -1
- package/dist/thread/index.d.cts +0 -260
- package/dist/topic/index.cjs +0 -282
- package/dist/topic/index.cjs.map +0 -1
- package/dist/topic/index.d.cts +0 -523
- package/dist/topic-redis/index.cjs +0 -71
- package/dist/topic-redis/index.cjs.map +0 -1
- package/dist/topic-redis/index.d.cts +0 -42
- package/dist/vite/index.cjs +0 -1077
- package/dist/vite/index.cjs.map +0 -1
- package/dist/vite/index.d.cts +0 -542
- package/dist/websocket/index.cjs +0 -1117
- package/dist/websocket/index.cjs.map +0 -1
- package/dist/websocket/index.d.cts +0 -861
package/dist/orm/index.d.cts
DELETED
|
@@ -1,2213 +0,0 @@
|
|
|
1
|
-
import * as alepha1 from "alepha";
|
|
2
|
-
import { Alepha, AlephaError, Descriptor, KIND, Page, Page as Page$1, PageQuery, PageQuery as PageQuery$1, Service, Static, StaticEncode, TBigInt, TInteger, TNull, TNumber, TNumberOptions, TObject, TObjectOptions, TOptional, TPage, TSchema, TString, TStringOptions, TUnion, TUnsafe, pageQuerySchema, pageSchema } from "alepha";
|
|
3
|
-
import * as drizzle_orm0 from "drizzle-orm";
|
|
4
|
-
import { BuildColumns, BuildExtraConfigColumns, SQL, SQLWrapper, sql } from "drizzle-orm";
|
|
5
|
-
import * as drizzle_orm_pg_core0 from "drizzle-orm/pg-core";
|
|
6
|
-
import { LockConfig, LockStrength, PgColumn, PgColumnBuilderBase, PgDatabase, PgInsertValue, PgSchema, PgSelectBase, PgSequenceOptions, PgTableExtraConfigValue, PgTableWithColumns, PgTransaction, UpdateDeleteAction } from "drizzle-orm/pg-core";
|
|
7
|
-
import { DateTime, DateTimeProvider } from "alepha/datetime";
|
|
8
|
-
import { PgTransactionConfig } from "drizzle-orm/pg-core/session";
|
|
9
|
-
import * as alepha_logger0 from "alepha/logger";
|
|
10
|
-
import * as DrizzleKit from "drizzle-kit/api";
|
|
11
|
-
import * as alepha_retry0 from "alepha/retry";
|
|
12
|
-
import * as alepha_lock0 from "alepha/lock";
|
|
13
|
-
import { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
14
|
-
import postgres from "postgres";
|
|
15
|
-
import { DatabaseSync } from "node:sqlite";
|
|
16
|
-
import * as typebox1 from "typebox";
|
|
17
|
-
import * as pg$1 from "drizzle-orm/sqlite-core";
|
|
18
|
-
import { SQLiteColumnBuilderBase } from "drizzle-orm/sqlite-core";
|
|
19
|
-
import { UpdateDeleteAction as UpdateDeleteAction$1 } from "drizzle-orm/pg-core/foreign-keys";
|
|
20
|
-
export * from "drizzle-orm/pg-core";
|
|
21
|
-
|
|
22
|
-
//#region src/orm/schemas/insertSchema.d.ts
|
|
23
|
-
/**
|
|
24
|
-
* Transforms a TObject schema for insert operations.
|
|
25
|
-
* All default properties at the root level are made optional.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* Before: { name: string; age: number(default=0); }
|
|
29
|
-
* After: { name: string; age?: number; }
|
|
30
|
-
*/
|
|
31
|
-
type TObjectInsert<T extends TObject> = TObject<{ [K in keyof T["properties"]]: T["properties"][K] extends {
|
|
32
|
-
[PG_DEFAULT]: any;
|
|
33
|
-
} | {
|
|
34
|
-
"~optional": true;
|
|
35
|
-
} ? TOptional<T["properties"][K]> : T["properties"][K] }>;
|
|
36
|
-
declare const insertSchema: <T extends TObject>(obj: T) => TObjectInsert<T>;
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region src/orm/schemas/updateSchema.d.ts
|
|
39
|
-
/**
|
|
40
|
-
* Transforms a TObject schema for update operations.
|
|
41
|
-
* All optional properties at the root level are made nullable (i.e., `T | null`).
|
|
42
|
-
* This allows an API endpoint to explicitly accept `null` to clear an optional field in the database.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* Before: { name?: string; age: number; }
|
|
46
|
-
* After: { name?: string | null; age: number; }
|
|
47
|
-
*/
|
|
48
|
-
type TObjectUpdate<T extends TObject> = TObject<{ [K in keyof T["properties"]]: T["properties"][K] extends TOptional<infer U> ? TOptional<TUnion<[U, TNull]>> : T["properties"][K] }>;
|
|
49
|
-
declare const updateSchema: <T extends TObject>(schema: T) => TObjectUpdate<T>;
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region src/orm/descriptors/$entity.d.ts
|
|
52
|
-
/**
|
|
53
|
-
* Creates a database entity descriptor that defines table structure using TypeBox schemas.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```ts
|
|
57
|
-
* import { t } from "alepha";
|
|
58
|
-
* import { $entity } from "alepha/orm";
|
|
59
|
-
*
|
|
60
|
-
* const userEntity = $entity({
|
|
61
|
-
* name: "users",
|
|
62
|
-
* schema: t.object({
|
|
63
|
-
* id: pg.primaryKey(),
|
|
64
|
-
* name: t.text(),
|
|
65
|
-
* email: t.email(),
|
|
66
|
-
* }),
|
|
67
|
-
* });
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
declare const $entity: {
|
|
71
|
-
<TSchema$1 extends TObject>(options: EntityDescriptorOptions<TSchema$1>): EntityDescriptor<TSchema$1>;
|
|
72
|
-
[KIND]: typeof EntityDescriptor;
|
|
73
|
-
};
|
|
74
|
-
interface EntityDescriptorOptions<T extends TObject, Keys = keyof Static<T>> {
|
|
75
|
-
/**
|
|
76
|
-
* The database table name that will be created for this entity.
|
|
77
|
-
* If not provided, name will be inferred from the $repository variable name.
|
|
78
|
-
*/
|
|
79
|
-
name: string;
|
|
80
|
-
/**
|
|
81
|
-
* TypeBox schema defining the table structure and column types.
|
|
82
|
-
*/
|
|
83
|
-
schema: T;
|
|
84
|
-
/**
|
|
85
|
-
* Database indexes to create for query optimization.
|
|
86
|
-
*/
|
|
87
|
-
indexes?: (Keys | {
|
|
88
|
-
/**
|
|
89
|
-
* Single column to index.
|
|
90
|
-
*/
|
|
91
|
-
column: Keys;
|
|
92
|
-
/**
|
|
93
|
-
* Whether this should be a unique index (enforces uniqueness constraint).
|
|
94
|
-
*/
|
|
95
|
-
unique?: boolean;
|
|
96
|
-
/**
|
|
97
|
-
* Custom name for the index. If not provided, generates name automatically.
|
|
98
|
-
*/
|
|
99
|
-
name?: string;
|
|
100
|
-
} | {
|
|
101
|
-
/**
|
|
102
|
-
* Multiple columns for composite index (order matters for query optimization).
|
|
103
|
-
*/
|
|
104
|
-
columns: Keys[];
|
|
105
|
-
/**
|
|
106
|
-
* Whether this should be a unique index (enforces uniqueness constraint).
|
|
107
|
-
*/
|
|
108
|
-
unique?: boolean;
|
|
109
|
-
/**
|
|
110
|
-
* Custom name for the index. If not provided, generates name automatically.
|
|
111
|
-
*/
|
|
112
|
-
name?: string;
|
|
113
|
-
})[];
|
|
114
|
-
/**
|
|
115
|
-
* Foreign key constraints to maintain referential integrity.
|
|
116
|
-
*/
|
|
117
|
-
foreignKeys?: Array<{
|
|
118
|
-
/**
|
|
119
|
-
* Optional name for the foreign key constraint.
|
|
120
|
-
*/
|
|
121
|
-
name?: string;
|
|
122
|
-
/**
|
|
123
|
-
* Local columns that reference the foreign table.
|
|
124
|
-
*/
|
|
125
|
-
columns: Array<keyof Static<T>>;
|
|
126
|
-
/**
|
|
127
|
-
* Referenced columns in the foreign table.
|
|
128
|
-
* Must be EntityColumn references from other entities.
|
|
129
|
-
*/
|
|
130
|
-
foreignColumns: Array<() => EntityColumn<any>>;
|
|
131
|
-
}>;
|
|
132
|
-
/**
|
|
133
|
-
* Additional table constraints for data validation.
|
|
134
|
-
*
|
|
135
|
-
* Constraints enforce business rules at the database level, providing
|
|
136
|
-
* an additional layer of data integrity beyond application validation.
|
|
137
|
-
*
|
|
138
|
-
* **Constraint Types**:
|
|
139
|
-
* - **Unique constraints**: Prevent duplicate values across columns
|
|
140
|
-
* - **Check constraints**: Enforce custom validation rules with SQL expressions
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* ```ts
|
|
144
|
-
* constraints: [
|
|
145
|
-
* {
|
|
146
|
-
* name: "unique_user_email",
|
|
147
|
-
* columns: ["email"],
|
|
148
|
-
* unique: true
|
|
149
|
-
* },
|
|
150
|
-
* {
|
|
151
|
-
* name: "valid_age_range",
|
|
152
|
-
* columns: ["age"],
|
|
153
|
-
* check: sql`age >= 0 AND age <= 150`
|
|
154
|
-
* },
|
|
155
|
-
* {
|
|
156
|
-
* name: "unique_user_username_per_tenant",
|
|
157
|
-
* columns: ["tenantId", "username"],
|
|
158
|
-
* unique: true
|
|
159
|
-
* }
|
|
160
|
-
* ]
|
|
161
|
-
* ```
|
|
162
|
-
*/
|
|
163
|
-
constraints?: Array<{
|
|
164
|
-
/**
|
|
165
|
-
* Columns involved in this constraint.
|
|
166
|
-
*/
|
|
167
|
-
columns: Array<keyof Static<T>>;
|
|
168
|
-
/**
|
|
169
|
-
* Optional name for the constraint.
|
|
170
|
-
*/
|
|
171
|
-
name?: string;
|
|
172
|
-
/**
|
|
173
|
-
* Whether this is a unique constraint.
|
|
174
|
-
*/
|
|
175
|
-
unique?: boolean | {};
|
|
176
|
-
/**
|
|
177
|
-
* SQL expression for check constraint validation.
|
|
178
|
-
*/
|
|
179
|
-
check?: SQL;
|
|
180
|
-
}>;
|
|
181
|
-
/**
|
|
182
|
-
* Advanced Drizzle ORM configuration for complex table setups.
|
|
183
|
-
*/
|
|
184
|
-
config?: (self: BuildExtraConfigColumns<string, FromSchema<T>, "pg">) => PgTableExtraConfigValue[];
|
|
185
|
-
}
|
|
186
|
-
declare class EntityDescriptor<T extends TObject = TObject> {
|
|
187
|
-
readonly options: EntityDescriptorOptions<T>;
|
|
188
|
-
constructor(options: EntityDescriptorOptions<T>);
|
|
189
|
-
alias(alias: string): this;
|
|
190
|
-
get cols(): EntityColumns<T>;
|
|
191
|
-
get name(): string;
|
|
192
|
-
get schema(): T;
|
|
193
|
-
get insertSchema(): TObjectInsert<T>;
|
|
194
|
-
get updateSchema(): TObjectUpdate<T>;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Convert a schema to columns.
|
|
198
|
-
*/
|
|
199
|
-
type FromSchema<T extends TObject> = { [key in keyof T["properties"]]: PgColumnBuilderBase };
|
|
200
|
-
type SchemaToTableConfig<T extends TObject> = {
|
|
201
|
-
name: string;
|
|
202
|
-
schema: string | undefined;
|
|
203
|
-
columns: { [key in keyof T["properties"]]: PgColumn };
|
|
204
|
-
dialect: string;
|
|
205
|
-
};
|
|
206
|
-
type EntityColumn<T extends TObject> = {
|
|
207
|
-
name: string;
|
|
208
|
-
entity: EntityDescriptor<T>;
|
|
209
|
-
};
|
|
210
|
-
type EntityColumns<T extends TObject> = { [key in keyof T["properties"]]: EntityColumn<T> };
|
|
211
|
-
//#endregion
|
|
212
|
-
//#region src/orm/constants/PG_SYMBOLS.d.ts
|
|
213
|
-
declare const PG_DEFAULT: unique symbol;
|
|
214
|
-
declare const PG_PRIMARY_KEY: unique symbol;
|
|
215
|
-
declare const PG_CREATED_AT: unique symbol;
|
|
216
|
-
declare const PG_UPDATED_AT: unique symbol;
|
|
217
|
-
declare const PG_DELETED_AT: unique symbol;
|
|
218
|
-
declare const PG_VERSION: unique symbol;
|
|
219
|
-
declare const PG_IDENTITY: unique symbol;
|
|
220
|
-
declare const PG_ENUM: unique symbol;
|
|
221
|
-
declare const PG_REF: unique symbol;
|
|
222
|
-
/**
|
|
223
|
-
* @deprecated Use `PG_IDENTITY` instead.
|
|
224
|
-
*/
|
|
225
|
-
declare const PG_SERIAL: unique symbol;
|
|
226
|
-
type PgDefault = typeof PG_DEFAULT;
|
|
227
|
-
type PgRef = typeof PG_REF;
|
|
228
|
-
type PgPrimaryKey = typeof PG_PRIMARY_KEY;
|
|
229
|
-
type PgSymbols = {
|
|
230
|
-
[PG_DEFAULT]: {};
|
|
231
|
-
[PG_PRIMARY_KEY]: {};
|
|
232
|
-
[PG_CREATED_AT]: {};
|
|
233
|
-
[PG_UPDATED_AT]: {};
|
|
234
|
-
[PG_DELETED_AT]: {};
|
|
235
|
-
[PG_VERSION]: {};
|
|
236
|
-
[PG_IDENTITY]: PgIdentityOptions;
|
|
237
|
-
[PG_REF]: PgRefOptions;
|
|
238
|
-
[PG_ENUM]: PgEnumOptions;
|
|
239
|
-
/**
|
|
240
|
-
* @deprecated Use `PG_IDENTITY` instead.
|
|
241
|
-
*/
|
|
242
|
-
[PG_SERIAL]: {};
|
|
243
|
-
};
|
|
244
|
-
type PgSymbolKeys = keyof PgSymbols;
|
|
245
|
-
type PgIdentityOptions = {
|
|
246
|
-
mode: "always" | "byDefault";
|
|
247
|
-
} & PgSequenceOptions & {
|
|
248
|
-
name?: string;
|
|
249
|
-
};
|
|
250
|
-
interface PgEnumOptions {
|
|
251
|
-
name?: string;
|
|
252
|
-
description?: string;
|
|
253
|
-
}
|
|
254
|
-
interface PgRefOptions {
|
|
255
|
-
ref: () => {
|
|
256
|
-
name: string;
|
|
257
|
-
entity: EntityDescriptor;
|
|
258
|
-
};
|
|
259
|
-
actions?: {
|
|
260
|
-
onUpdate?: UpdateDeleteAction;
|
|
261
|
-
onDelete?: UpdateDeleteAction;
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
//#endregion
|
|
265
|
-
//#region src/orm/errors/DbError.d.ts
|
|
266
|
-
declare class DbError extends AlephaError {
|
|
267
|
-
name: string;
|
|
268
|
-
constructor(message: string, cause?: unknown);
|
|
269
|
-
}
|
|
270
|
-
//#endregion
|
|
271
|
-
//#region src/orm/helpers/pgAttr.d.ts
|
|
272
|
-
/**
|
|
273
|
-
* Decorates a typebox schema with a Postgres attribute.
|
|
274
|
-
*
|
|
275
|
-
* > It's just a fancy way to add Symbols to a field.
|
|
276
|
-
*
|
|
277
|
-
* @example
|
|
278
|
-
* ```ts
|
|
279
|
-
* import { t } from "alepha";
|
|
280
|
-
* import { PG_UPDATED_AT } from "../constants/PG_SYMBOLS";
|
|
281
|
-
*
|
|
282
|
-
* export const updatedAtSchema = pgAttr(
|
|
283
|
-
* t.datetime(), PG_UPDATED_AT,
|
|
284
|
-
* );
|
|
285
|
-
* ```
|
|
286
|
-
*/
|
|
287
|
-
declare const pgAttr: <T extends TSchema, Attr extends PgSymbolKeys>(type: T, attr: Attr, value?: PgSymbols[Attr]) => PgAttr<T, Attr>;
|
|
288
|
-
/**
|
|
289
|
-
* Retrieves the fields of a schema that have a specific attribute.
|
|
290
|
-
*/
|
|
291
|
-
declare const getAttrFields: (schema: TObject, name: PgSymbolKeys) => PgAttrField[];
|
|
292
|
-
/**
|
|
293
|
-
* Type representation.
|
|
294
|
-
*/
|
|
295
|
-
type PgAttr<T extends TSchema, TAttr extends PgSymbolKeys> = T & { [K in TAttr]: PgSymbols[K] };
|
|
296
|
-
interface PgAttrField {
|
|
297
|
-
key: string;
|
|
298
|
-
type: TSchema;
|
|
299
|
-
data: any;
|
|
300
|
-
nested?: any[];
|
|
301
|
-
one?: boolean;
|
|
302
|
-
}
|
|
303
|
-
//#endregion
|
|
304
|
-
//#region src/orm/interfaces/FilterOperators.d.ts
|
|
305
|
-
interface FilterOperators<TValue> {
|
|
306
|
-
/**
|
|
307
|
-
* Test that two values are equal.
|
|
308
|
-
*
|
|
309
|
-
* Remember that the SQL standard dictates that
|
|
310
|
-
* two NULL values are not equal, so if you want to test
|
|
311
|
-
* whether a value is null, you may want to use
|
|
312
|
-
* `isNull` instead.
|
|
313
|
-
*
|
|
314
|
-
* ## Examples
|
|
315
|
-
*
|
|
316
|
-
* ```ts
|
|
317
|
-
* // Select cars made by Ford
|
|
318
|
-
* db.select().from(cars)
|
|
319
|
-
* .where(eq(cars.make, 'Ford'))
|
|
320
|
-
* ```
|
|
321
|
-
*
|
|
322
|
-
* @see isNull for a way to test equality to NULL.
|
|
323
|
-
*/
|
|
324
|
-
eq?: TValue;
|
|
325
|
-
/**
|
|
326
|
-
* Test that two values are not equal.
|
|
327
|
-
*
|
|
328
|
-
* Remember that the SQL standard dictates that
|
|
329
|
-
* two NULL values are not equal, so if you want to test
|
|
330
|
-
* whether a value is not null, you may want to use
|
|
331
|
-
* `isNotNull` instead.
|
|
332
|
-
*
|
|
333
|
-
* ## Examples
|
|
334
|
-
*
|
|
335
|
-
* ```ts
|
|
336
|
-
* // Select cars not made by Ford
|
|
337
|
-
* db.select().from(cars)
|
|
338
|
-
* .where(ne(cars.make, 'Ford'))
|
|
339
|
-
* ```
|
|
340
|
-
*
|
|
341
|
-
* @see isNotNull for a way to test whether a value is not null.
|
|
342
|
-
*/
|
|
343
|
-
ne?: TValue;
|
|
344
|
-
/**
|
|
345
|
-
* Test that the first expression passed is greater than
|
|
346
|
-
* the second expression.
|
|
347
|
-
*
|
|
348
|
-
* ## Examples
|
|
349
|
-
*
|
|
350
|
-
* ```ts
|
|
351
|
-
* // Select cars made after 2000.
|
|
352
|
-
* db.select().from(cars)
|
|
353
|
-
* .where(gt(cars.year, 2000))
|
|
354
|
-
* ```
|
|
355
|
-
*
|
|
356
|
-
* @see gte for greater-than-or-equal
|
|
357
|
-
*/
|
|
358
|
-
gt?: TValue;
|
|
359
|
-
/**
|
|
360
|
-
* Test that the first expression passed is greater than
|
|
361
|
-
* or equal to the second expression. Use `gt` to
|
|
362
|
-
* test whether an expression is strictly greater
|
|
363
|
-
* than another.
|
|
364
|
-
*
|
|
365
|
-
* ## Examples
|
|
366
|
-
*
|
|
367
|
-
* ```ts
|
|
368
|
-
* // Select cars made on or after 2000.
|
|
369
|
-
* db.select().from(cars)
|
|
370
|
-
* .where(gte(cars.year, 2000))
|
|
371
|
-
* ```
|
|
372
|
-
*
|
|
373
|
-
* @see gt for a strictly greater-than condition
|
|
374
|
-
*/
|
|
375
|
-
gte?: TValue;
|
|
376
|
-
/**
|
|
377
|
-
* Test that the first expression passed is less than
|
|
378
|
-
* the second expression.
|
|
379
|
-
*
|
|
380
|
-
* ## Examples
|
|
381
|
-
*
|
|
382
|
-
* ```ts
|
|
383
|
-
* // Select cars made before 2000.
|
|
384
|
-
* db.select().from(cars)
|
|
385
|
-
* .where(lt(cars.year, 2000))
|
|
386
|
-
* ```
|
|
387
|
-
*
|
|
388
|
-
* @see lte for greater-than-or-equal
|
|
389
|
-
*/
|
|
390
|
-
lt?: TValue;
|
|
391
|
-
/**
|
|
392
|
-
* Test that the first expression passed is less than
|
|
393
|
-
* or equal to the second expression.
|
|
394
|
-
*
|
|
395
|
-
* ## Examples
|
|
396
|
-
*
|
|
397
|
-
* ```ts
|
|
398
|
-
* // Select cars made before 2000.
|
|
399
|
-
* db.select().from(cars)
|
|
400
|
-
* .where(lte(cars.year, 2000))
|
|
401
|
-
* ```
|
|
402
|
-
*
|
|
403
|
-
* @see lt for a strictly less-than condition
|
|
404
|
-
*/
|
|
405
|
-
lte?: TValue;
|
|
406
|
-
/**
|
|
407
|
-
* Test whether the first parameter, a column or expression,
|
|
408
|
-
* has a value from a list passed as the second argument.
|
|
409
|
-
*
|
|
410
|
-
* ## Throws
|
|
411
|
-
*
|
|
412
|
-
* The argument passed in the second array can't be empty:
|
|
413
|
-
* if an empty is provided, this method will throw.
|
|
414
|
-
*
|
|
415
|
-
* ## Examples
|
|
416
|
-
*
|
|
417
|
-
* ```ts
|
|
418
|
-
* // Select cars made by Ford or GM.
|
|
419
|
-
* db.select().from(cars)
|
|
420
|
-
* .where(inArray(cars.make, ['Ford', 'GM']))
|
|
421
|
-
* ```
|
|
422
|
-
*
|
|
423
|
-
* @see notInArray for the inverse of this test
|
|
424
|
-
*/
|
|
425
|
-
inArray?: TValue[];
|
|
426
|
-
/**
|
|
427
|
-
* Test whether the first parameter, a column or expression,
|
|
428
|
-
* has a value that is not present in a list passed as the
|
|
429
|
-
* second argument.
|
|
430
|
-
*
|
|
431
|
-
* ## Throws
|
|
432
|
-
*
|
|
433
|
-
* The argument passed in the second array can't be empty:
|
|
434
|
-
* if an empty is provided, this method will throw.
|
|
435
|
-
*
|
|
436
|
-
* ## Examples
|
|
437
|
-
*
|
|
438
|
-
* ```ts
|
|
439
|
-
* // Select cars made by any company except Ford or GM.
|
|
440
|
-
* db.select().from(cars)
|
|
441
|
-
* .where(notInArray(cars.make, ['Ford', 'GM']))
|
|
442
|
-
* ```
|
|
443
|
-
*
|
|
444
|
-
* @see inArray for the inverse of this test
|
|
445
|
-
*/
|
|
446
|
-
notInArray?: TValue[];
|
|
447
|
-
/**
|
|
448
|
-
* Test whether an expression is not NULL. By the SQL standard,
|
|
449
|
-
* NULL is neither equal nor not equal to itself, so
|
|
450
|
-
* it's recommended to use `isNull` and `notIsNull` for
|
|
451
|
-
* comparisons to NULL.
|
|
452
|
-
*
|
|
453
|
-
* ## Examples
|
|
454
|
-
*
|
|
455
|
-
* ```ts
|
|
456
|
-
* // Select cars that have been discontinued.
|
|
457
|
-
* db.select().from(cars)
|
|
458
|
-
* .where(isNotNull(cars.discontinuedAt))
|
|
459
|
-
* ```
|
|
460
|
-
*
|
|
461
|
-
* @see isNull for the inverse of this test
|
|
462
|
-
*/
|
|
463
|
-
isNotNull?: true;
|
|
464
|
-
/**
|
|
465
|
-
* Test whether an expression is NULL. By the SQL standard,
|
|
466
|
-
* NULL is neither equal nor not equal to itself, so
|
|
467
|
-
* it's recommended to use `isNull` and `notIsNull` for
|
|
468
|
-
* comparisons to NULL.
|
|
469
|
-
*
|
|
470
|
-
* ## Examples
|
|
471
|
-
*
|
|
472
|
-
* ```ts
|
|
473
|
-
* // Select cars that have no discontinuedAt date.
|
|
474
|
-
* db.select().from(cars)
|
|
475
|
-
* .where(isNull(cars.discontinuedAt))
|
|
476
|
-
* ```
|
|
477
|
-
*
|
|
478
|
-
* @see isNotNull for the inverse of this test
|
|
479
|
-
*/
|
|
480
|
-
isNull?: true;
|
|
481
|
-
/**
|
|
482
|
-
* Test whether an expression is between two values. This
|
|
483
|
-
* is an easier way to express range tests, which would be
|
|
484
|
-
* expressed mathematically as `x <= a <= y` but in SQL
|
|
485
|
-
* would have to be like `a >= x AND a <= y`.
|
|
486
|
-
*
|
|
487
|
-
* Between is inclusive of the endpoints: if `column`
|
|
488
|
-
* is equal to `min` or `max`, it will be TRUE.
|
|
489
|
-
*
|
|
490
|
-
* ## Examples
|
|
491
|
-
*
|
|
492
|
-
* ```ts
|
|
493
|
-
* // Select cars made between 1990 and 2000
|
|
494
|
-
* db.select().from(cars)
|
|
495
|
-
* .where(between(cars.year, 1990, 2000))
|
|
496
|
-
* ```
|
|
497
|
-
*
|
|
498
|
-
* @see notBetween for the inverse of this test
|
|
499
|
-
*/
|
|
500
|
-
between?: [number, number];
|
|
501
|
-
/**
|
|
502
|
-
* Test whether an expression is not between two values.
|
|
503
|
-
*
|
|
504
|
-
* This, like `between`, includes its endpoints, so if
|
|
505
|
-
* the `column` is equal to `min` or `max`, in this case
|
|
506
|
-
* it will evaluate to FALSE.
|
|
507
|
-
*
|
|
508
|
-
* ## Examples
|
|
509
|
-
*
|
|
510
|
-
* ```ts
|
|
511
|
-
* // Exclude cars made in the 1970s
|
|
512
|
-
* db.select().from(cars)
|
|
513
|
-
* .where(notBetween(cars.year, 1970, 1979))
|
|
514
|
-
* ```
|
|
515
|
-
*
|
|
516
|
-
* @see between for the inverse of this test
|
|
517
|
-
*/
|
|
518
|
-
notBetween?: [number, number];
|
|
519
|
-
/**
|
|
520
|
-
* Compare a column to a pattern, which can include `%` and `_`
|
|
521
|
-
* characters to match multiple variations. Including `%`
|
|
522
|
-
* in the pattern matches zero or more characters, and including
|
|
523
|
-
* `_` will match a single character.
|
|
524
|
-
*
|
|
525
|
-
* ## Examples
|
|
526
|
-
*
|
|
527
|
-
* ```ts
|
|
528
|
-
* // Select all cars with 'Turbo' in their names.
|
|
529
|
-
* db.select().from(cars)
|
|
530
|
-
* .where(like(cars.name, '%Turbo%'))
|
|
531
|
-
* ```
|
|
532
|
-
*
|
|
533
|
-
* @see ilike for a case-insensitive version of this condition
|
|
534
|
-
*/
|
|
535
|
-
like?: string;
|
|
536
|
-
/**
|
|
537
|
-
* The inverse of like - this tests that a given column
|
|
538
|
-
* does not match a pattern, which can include `%` and `_`
|
|
539
|
-
* characters to match multiple variations. Including `%`
|
|
540
|
-
* in the pattern matches zero or more characters, and including
|
|
541
|
-
* `_` will match a single character.
|
|
542
|
-
*
|
|
543
|
-
* ## Examples
|
|
544
|
-
*
|
|
545
|
-
* ```ts
|
|
546
|
-
* // Select all cars that don't have "ROver" in their name.
|
|
547
|
-
* db.select().from(cars)
|
|
548
|
-
* .where(notLike(cars.name, '%Rover%'))
|
|
549
|
-
* ```
|
|
550
|
-
*
|
|
551
|
-
* @see like for the inverse condition
|
|
552
|
-
* @see notIlike for a case-insensitive version of this condition
|
|
553
|
-
*/
|
|
554
|
-
notLike?: string;
|
|
555
|
-
/**
|
|
556
|
-
* Case-insensitively compare a column to a pattern,
|
|
557
|
-
* which can include `%` and `_`
|
|
558
|
-
* characters to match multiple variations. Including `%`
|
|
559
|
-
* in the pattern matches zero or more characters, and including
|
|
560
|
-
* `_` will match a single character.
|
|
561
|
-
*
|
|
562
|
-
* Unlike like, this performs a case-insensitive comparison.
|
|
563
|
-
*
|
|
564
|
-
* ## Examples
|
|
565
|
-
*
|
|
566
|
-
* ```ts
|
|
567
|
-
* // Select all cars with 'Turbo' in their names.
|
|
568
|
-
* db.select().from(cars)
|
|
569
|
-
* .where(ilike(cars.name, '%Turbo%'))
|
|
570
|
-
* ```
|
|
571
|
-
*
|
|
572
|
-
* @see like for a case-sensitive version of this condition
|
|
573
|
-
*/
|
|
574
|
-
ilike?: string;
|
|
575
|
-
/**
|
|
576
|
-
* The inverse of ilike - this case-insensitively tests that a given column
|
|
577
|
-
* does not match a pattern, which can include `%` and `_`
|
|
578
|
-
* characters to match multiple variations. Including `%`
|
|
579
|
-
* in the pattern matches zero or more characters, and including
|
|
580
|
-
* `_` will match a single character.
|
|
581
|
-
*
|
|
582
|
-
* ## Examples
|
|
583
|
-
*
|
|
584
|
-
* ```ts
|
|
585
|
-
* // Select all cars that don't have "Rover" in their name.
|
|
586
|
-
* db.select().from(cars)
|
|
587
|
-
* .where(notLike(cars.name, '%Rover%'))
|
|
588
|
-
* ```
|
|
589
|
-
*
|
|
590
|
-
* @see ilike for the inverse condition
|
|
591
|
-
* @see notLike for a case-sensitive version of this condition
|
|
592
|
-
*/
|
|
593
|
-
notIlike?: string;
|
|
594
|
-
/**
|
|
595
|
-
* Syntactic sugar for case-insensitive substring matching.
|
|
596
|
-
* Automatically wraps the value with `%` wildcards on both sides.
|
|
597
|
-
*
|
|
598
|
-
* Equivalent to: `ilike: '%value%'`
|
|
599
|
-
*
|
|
600
|
-
* ## Examples
|
|
601
|
-
*
|
|
602
|
-
* ```ts
|
|
603
|
-
* // Select all cars with "Turbo" anywhere in their name.
|
|
604
|
-
* db.select().from(cars)
|
|
605
|
-
* .where({ name: { contains: 'Turbo' } })
|
|
606
|
-
* // Same as: .where(ilike(cars.name, '%Turbo%'))
|
|
607
|
-
* ```
|
|
608
|
-
*
|
|
609
|
-
* @see ilike for manual pattern matching
|
|
610
|
-
* @see startsWith for prefix matching
|
|
611
|
-
* @see endsWith for suffix matching
|
|
612
|
-
*/
|
|
613
|
-
contains?: string;
|
|
614
|
-
/**
|
|
615
|
-
* Syntactic sugar for case-insensitive prefix matching.
|
|
616
|
-
* Automatically appends a `%` wildcard to the end of the value.
|
|
617
|
-
*
|
|
618
|
-
* Equivalent to: `ilike: 'value%'`
|
|
619
|
-
*
|
|
620
|
-
* ## Examples
|
|
621
|
-
*
|
|
622
|
-
* ```ts
|
|
623
|
-
* // Select all cars whose names start with "Ford".
|
|
624
|
-
* db.select().from(cars)
|
|
625
|
-
* .where({ name: { startsWith: 'Ford' } })
|
|
626
|
-
* // Same as: .where(ilike(cars.name, 'Ford%'))
|
|
627
|
-
* ```
|
|
628
|
-
*
|
|
629
|
-
* @see ilike for manual pattern matching
|
|
630
|
-
* @see contains for substring matching
|
|
631
|
-
* @see endsWith for suffix matching
|
|
632
|
-
*/
|
|
633
|
-
startsWith?: string;
|
|
634
|
-
/**
|
|
635
|
-
* Syntactic sugar for case-insensitive suffix matching.
|
|
636
|
-
* Automatically prepends a `%` wildcard to the beginning of the value.
|
|
637
|
-
*
|
|
638
|
-
* Equivalent to: `ilike: '%value'`
|
|
639
|
-
*
|
|
640
|
-
* ## Examples
|
|
641
|
-
*
|
|
642
|
-
* ```ts
|
|
643
|
-
* // Select all cars whose names end with "Turbo".
|
|
644
|
-
* db.select().from(cars)
|
|
645
|
-
* .where({ name: { endsWith: 'Turbo' } })
|
|
646
|
-
* // Same as: .where(ilike(cars.name, '%Turbo'))
|
|
647
|
-
* ```
|
|
648
|
-
*
|
|
649
|
-
* @see ilike for manual pattern matching
|
|
650
|
-
* @see contains for substring matching
|
|
651
|
-
* @see startsWith for prefix matching
|
|
652
|
-
*/
|
|
653
|
-
endsWith?: string;
|
|
654
|
-
/**
|
|
655
|
-
* Test that a column or expression contains all elements of
|
|
656
|
-
* the list passed as the second argument.
|
|
657
|
-
*
|
|
658
|
-
* ## Throws
|
|
659
|
-
*
|
|
660
|
-
* The argument passed in the second array can't be empty:
|
|
661
|
-
* if an empty is provided, this method will throw.
|
|
662
|
-
*
|
|
663
|
-
* ## Examples
|
|
664
|
-
*
|
|
665
|
-
* ```ts
|
|
666
|
-
* // Select posts where its tags contain "Typescript" and "ORM".
|
|
667
|
-
* db.select().from(posts)
|
|
668
|
-
* .where(arrayContains(posts.tags, ['Typescript', 'ORM']))
|
|
669
|
-
* ```
|
|
670
|
-
*
|
|
671
|
-
* @see arrayContained to find if an array contains all elements of a column or expression
|
|
672
|
-
* @see arrayOverlaps to find if a column or expression contains any elements of an array
|
|
673
|
-
*/
|
|
674
|
-
arrayContains?: TValue;
|
|
675
|
-
/**
|
|
676
|
-
* Test that the list passed as the second argument contains
|
|
677
|
-
* all elements of a column or expression.
|
|
678
|
-
*
|
|
679
|
-
* ## Throws
|
|
680
|
-
*
|
|
681
|
-
* The argument passed in the second array can't be empty:
|
|
682
|
-
* if an empty is provided, this method will throw.
|
|
683
|
-
*
|
|
684
|
-
* ## Examples
|
|
685
|
-
*
|
|
686
|
-
* ```ts
|
|
687
|
-
* // Select posts where its tags contain "Typescript", "ORM" or both,
|
|
688
|
-
* // but filtering posts that have additional tags.
|
|
689
|
-
* db.select().from(posts)
|
|
690
|
-
* .where(arrayContained(posts.tags, ['Typescript', 'ORM']))
|
|
691
|
-
* ```
|
|
692
|
-
*
|
|
693
|
-
* @see arrayContains to find if a column or expression contains all elements of an array
|
|
694
|
-
* @see arrayOverlaps to find if a column or expression contains any elements of an array
|
|
695
|
-
*/
|
|
696
|
-
arrayContained?: TValue;
|
|
697
|
-
/**
|
|
698
|
-
* Test that a column or expression contains any elements of
|
|
699
|
-
* the list passed as the second argument.
|
|
700
|
-
*
|
|
701
|
-
* ## Throws
|
|
702
|
-
*
|
|
703
|
-
* The argument passed in the second array can't be empty:
|
|
704
|
-
* if an empty is provided, this method will throw.
|
|
705
|
-
*
|
|
706
|
-
* ## Examples
|
|
707
|
-
*
|
|
708
|
-
* ```ts
|
|
709
|
-
* // Select posts where its tags contain "Typescript", "ORM" or both.
|
|
710
|
-
* db.select().from(posts)
|
|
711
|
-
* .where(arrayOverlaps(posts.tags, ['Typescript', 'ORM']))
|
|
712
|
-
* ```
|
|
713
|
-
*
|
|
714
|
-
* @see arrayContains to find if a column or expression contains all elements of an array
|
|
715
|
-
* @see arrayContained to find if an array contains all elements of a column or expression
|
|
716
|
-
*/
|
|
717
|
-
arrayOverlaps?: TValue;
|
|
718
|
-
}
|
|
719
|
-
//#endregion
|
|
720
|
-
//#region src/orm/interfaces/PgQueryWhere.d.ts
|
|
721
|
-
type PgQueryWhere<T extends TObject, Relations extends PgRelationMap<TObject> | undefined = undefined> = (PgQueryWhereOperators<T> & PgQueryWhereConditions<T>) | (PgQueryWhereRelations<Relations> & PgQueryWhereOperators<T> & PgQueryWhereConditions<T, Relations>);
|
|
722
|
-
type PgQueryWhereOrSQL<T extends TObject, Relations extends PgRelationMap<TObject> | undefined = undefined> = SQLWrapper | PgQueryWhere<T, Relations>;
|
|
723
|
-
type PgQueryWhereOperators<T extends TObject> = { [Key in keyof Static<T>]?: FilterOperators<Static<T>[Key]> | Static<T>[Key] | (Static<T>[Key] extends object ? NestedJsonbQuery<Static<T>[Key]> : never) };
|
|
724
|
-
type PgQueryWhereConditions<T extends TObject, Relations extends PgRelationMap<TObject> | undefined = undefined> = {
|
|
725
|
-
/**
|
|
726
|
-
* Combine a list of conditions with the `and` operator. Conditions
|
|
727
|
-
* that are equal `undefined` are automatically ignored.
|
|
728
|
-
*
|
|
729
|
-
* ## Examples
|
|
730
|
-
*
|
|
731
|
-
* ```ts
|
|
732
|
-
* db.select().from(cars)
|
|
733
|
-
* .where(
|
|
734
|
-
* and(
|
|
735
|
-
* eq(cars.make, 'Volvo'),
|
|
736
|
-
* eq(cars.year, 1950),
|
|
737
|
-
* )
|
|
738
|
-
* )
|
|
739
|
-
* ```
|
|
740
|
-
*/
|
|
741
|
-
and?: Array<PgQueryWhereOrSQL<T, Relations>>;
|
|
742
|
-
/**
|
|
743
|
-
* Combine a list of conditions with the `or` operator. Conditions
|
|
744
|
-
* that are equal `undefined` are automatically ignored.
|
|
745
|
-
*
|
|
746
|
-
* ## Examples
|
|
747
|
-
*
|
|
748
|
-
* ```ts
|
|
749
|
-
* db.select().from(cars)
|
|
750
|
-
* .where(
|
|
751
|
-
* or(
|
|
752
|
-
* eq(cars.make, 'GM'),
|
|
753
|
-
* eq(cars.make, 'Ford'),
|
|
754
|
-
* )
|
|
755
|
-
* )
|
|
756
|
-
* ```
|
|
757
|
-
*/
|
|
758
|
-
or?: Array<PgQueryWhereOrSQL<T, Relations>>;
|
|
759
|
-
/**
|
|
760
|
-
* Negate the meaning of an expression using the `not` keyword.
|
|
761
|
-
*
|
|
762
|
-
* ## Examples
|
|
763
|
-
*
|
|
764
|
-
* ```ts
|
|
765
|
-
* // Select cars _not_ made by GM or Ford.
|
|
766
|
-
* db.select().from(cars)
|
|
767
|
-
* .where(not(inArray(cars.make, ['GM', 'Ford'])))
|
|
768
|
-
* ```
|
|
769
|
-
*/
|
|
770
|
-
not?: PgQueryWhereOrSQL<T, Relations>;
|
|
771
|
-
/**
|
|
772
|
-
* Test whether a subquery evaluates to have any rows.
|
|
773
|
-
*
|
|
774
|
-
* ## Examples
|
|
775
|
-
*
|
|
776
|
-
* ```ts
|
|
777
|
-
* // Users whose `homeCity` column has a match in a cities
|
|
778
|
-
* // table.
|
|
779
|
-
* db
|
|
780
|
-
* .select()
|
|
781
|
-
* .from(users)
|
|
782
|
-
* .where(
|
|
783
|
-
* exists(db.select()
|
|
784
|
-
* .from(cities)
|
|
785
|
-
* .where(eq(users.homeCity, cities.id))),
|
|
786
|
-
* );
|
|
787
|
-
* ```
|
|
788
|
-
*
|
|
789
|
-
* @see notExists for the inverse of this test
|
|
790
|
-
*/
|
|
791
|
-
exists?: SQLWrapper;
|
|
792
|
-
};
|
|
793
|
-
type PgQueryWhereRelations<Relations extends PgRelationMap<TObject> | undefined = undefined> = Relations extends PgRelationMap<TObject> ? { [K in keyof Relations]?: PgQueryWhere<Relations[K]["join"]["schema"], Relations[K]["with"]> } : {};
|
|
794
|
-
/**
|
|
795
|
-
* Recursively allow nested queries for JSONB object/array types
|
|
796
|
-
*/
|
|
797
|
-
type NestedJsonbQuery<T> = T extends object ? T extends Array<infer U> ? U extends object ? { [K in keyof U]?: FilterOperators<U[K]> | U[K] } : FilterOperators<U> | U : { [K in keyof T]?: FilterOperators<T[K]> | T[K] | (T[K] extends object ? NestedJsonbQuery<T[K]> : never) } : FilterOperators<T> | T;
|
|
798
|
-
//#endregion
|
|
799
|
-
//#region src/orm/interfaces/PgQuery.d.ts
|
|
800
|
-
/**
|
|
801
|
-
* Order direction for sorting
|
|
802
|
-
*/
|
|
803
|
-
type OrderDirection = "asc" | "desc";
|
|
804
|
-
/**
|
|
805
|
-
* Single order by clause with column and direction
|
|
806
|
-
*/
|
|
807
|
-
interface OrderByClause<T> {
|
|
808
|
-
column: keyof T;
|
|
809
|
-
direction?: OrderDirection;
|
|
810
|
-
}
|
|
811
|
-
/**
|
|
812
|
-
* Order by parameter - supports 3 modes:
|
|
813
|
-
* 1. String: orderBy: "name" (defaults to ASC)
|
|
814
|
-
* 2. Single object: orderBy: { column: "name", direction: "desc" }
|
|
815
|
-
* 3. Array: orderBy: [{ column: "name", direction: "asc" }, { column: "age", direction: "desc" }]
|
|
816
|
-
*/
|
|
817
|
-
type OrderBy<T> = keyof T | OrderByClause<T> | Array<OrderByClause<T>>;
|
|
818
|
-
/**
|
|
819
|
-
* Generic query interface for PostgreSQL entities
|
|
820
|
-
*/
|
|
821
|
-
interface PgQuery<T extends TObject = TObject> {
|
|
822
|
-
distinct?: (keyof Static<T>)[];
|
|
823
|
-
columns?: (keyof Static<T>)[];
|
|
824
|
-
where?: PgQueryWhereOrSQL<T>;
|
|
825
|
-
limit?: number;
|
|
826
|
-
offset?: number;
|
|
827
|
-
orderBy?: OrderBy<Static<T>>;
|
|
828
|
-
groupBy?: (keyof Static<T>)[];
|
|
829
|
-
}
|
|
830
|
-
type PgStatic<T extends TObject, Relations extends PgRelationMap<T>> = Static<T> & { [K in keyof Relations]: Static<Relations[K]["join"]["schema"]> & (Relations[K]["with"] extends PgRelationMap<TObject> ? PgStatic<Relations[K]["join"]["schema"], Relations[K]["with"]> : {}) };
|
|
831
|
-
interface PgQueryRelations<T extends TObject = TObject, Relations extends PgRelationMap<T> | undefined = undefined> extends PgQuery<T> {
|
|
832
|
-
with?: Relations;
|
|
833
|
-
where?: PgQueryWhereOrSQL<T, Relations>;
|
|
834
|
-
}
|
|
835
|
-
type PgRelationMap<Base extends TObject> = Record<string, PgRelation<Base>>;
|
|
836
|
-
type PgRelation<Base extends TObject> = {
|
|
837
|
-
type?: "left" | "inner" | "right";
|
|
838
|
-
join: {
|
|
839
|
-
schema: TObject;
|
|
840
|
-
name: string;
|
|
841
|
-
};
|
|
842
|
-
on: SQLWrapper | [keyof Static<Base>, {
|
|
843
|
-
name: string;
|
|
844
|
-
}];
|
|
845
|
-
with?: PgRelationMap<TObject>;
|
|
846
|
-
};
|
|
847
|
-
//#endregion
|
|
848
|
-
//#region src/orm/descriptors/$sequence.d.ts
|
|
849
|
-
/**
|
|
850
|
-
* Creates a PostgreSQL sequence descriptor for generating unique numeric values.
|
|
851
|
-
*/
|
|
852
|
-
declare const $sequence: {
|
|
853
|
-
(options?: SequenceDescriptorOptions): SequenceDescriptor;
|
|
854
|
-
[KIND]: typeof SequenceDescriptor;
|
|
855
|
-
};
|
|
856
|
-
interface SequenceDescriptorOptions extends PgSequenceOptions {
|
|
857
|
-
/**
|
|
858
|
-
* The name of the sequence. If not provided, the property key will be used.
|
|
859
|
-
*/
|
|
860
|
-
name?: string;
|
|
861
|
-
provider?: DatabaseProvider;
|
|
862
|
-
}
|
|
863
|
-
declare class SequenceDescriptor extends Descriptor<SequenceDescriptorOptions> {
|
|
864
|
-
readonly provider: DatabaseProvider;
|
|
865
|
-
onInit(): void;
|
|
866
|
-
get name(): string;
|
|
867
|
-
next(): Promise<number>;
|
|
868
|
-
current(): Promise<number>;
|
|
869
|
-
protected $provider(): DatabaseProvider;
|
|
870
|
-
}
|
|
871
|
-
//#endregion
|
|
872
|
-
//#region src/orm/services/ModelBuilder.d.ts
|
|
873
|
-
/**
|
|
874
|
-
* Database-specific table configuration functions
|
|
875
|
-
*/
|
|
876
|
-
interface TableConfigBuilders<TConfig> {
|
|
877
|
-
index: (name: string) => {
|
|
878
|
-
on: (...columns: any[]) => TConfig;
|
|
879
|
-
};
|
|
880
|
-
uniqueIndex: (name: string) => {
|
|
881
|
-
on: (...columns: any[]) => TConfig;
|
|
882
|
-
};
|
|
883
|
-
unique: (name: string) => {
|
|
884
|
-
on: (...columns: any[]) => TConfig;
|
|
885
|
-
};
|
|
886
|
-
check: (name: string, sql: SQL) => TConfig;
|
|
887
|
-
foreignKey: (config: {
|
|
888
|
-
name: string;
|
|
889
|
-
columns: any[];
|
|
890
|
-
foreignColumns: any[];
|
|
891
|
-
}) => TConfig;
|
|
892
|
-
}
|
|
893
|
-
/**
|
|
894
|
-
* Abstract base class for transforming Alepha Descriptors (Entity, Sequence, etc...)
|
|
895
|
-
* into drizzle models (tables, enums, sequences, etc...).
|
|
896
|
-
*/
|
|
897
|
-
declare abstract class ModelBuilder {
|
|
898
|
-
/**
|
|
899
|
-
* Build a table from an entity descriptor.
|
|
900
|
-
*/
|
|
901
|
-
abstract buildTable(entity: EntityDescriptor, options: {
|
|
902
|
-
tables: Map<string, unknown>;
|
|
903
|
-
enums: Map<string, unknown>;
|
|
904
|
-
schema: string;
|
|
905
|
-
}): void;
|
|
906
|
-
/**
|
|
907
|
-
* Build a sequence from a sequence descriptor.
|
|
908
|
-
*/
|
|
909
|
-
abstract buildSequence(sequence: SequenceDescriptor, options: {
|
|
910
|
-
sequences: Map<string, unknown>;
|
|
911
|
-
schema: string;
|
|
912
|
-
}): void;
|
|
913
|
-
/**
|
|
914
|
-
* Convert camelCase to snake_case for column names.
|
|
915
|
-
*/
|
|
916
|
-
protected toColumnName(str: string): string;
|
|
917
|
-
/**
|
|
918
|
-
* Build the table configuration function for any database.
|
|
919
|
-
* This includes indexes, foreign keys, constraints, and custom config.
|
|
920
|
-
*
|
|
921
|
-
* @param entity - The entity descriptor
|
|
922
|
-
* @param builders - Database-specific builder functions
|
|
923
|
-
* @param tableResolver - Function to resolve entity references to table columns
|
|
924
|
-
* @param customConfigHandler - Optional handler for custom config
|
|
925
|
-
*/
|
|
926
|
-
protected buildTableConfig<TConfig, TSelf>(entity: EntityDescriptor, builders: TableConfigBuilders<TConfig>, tableResolver?: (entityName: string) => any, customConfigHandler?: (config: any, self: TSelf) => TConfig[]): ((self: TSelf) => TConfig[]) | undefined;
|
|
927
|
-
}
|
|
928
|
-
//#endregion
|
|
929
|
-
//#region src/orm/providers/DrizzleKitProvider.d.ts
|
|
930
|
-
declare class DrizzleKitProvider {
|
|
931
|
-
protected readonly log: alepha_logger0.Logger;
|
|
932
|
-
protected readonly alepha: Alepha;
|
|
933
|
-
/**
|
|
934
|
-
* Synchronize database with current schema definitions.
|
|
935
|
-
*
|
|
936
|
-
* In development mode, it will generate and execute migrations based on the current state.
|
|
937
|
-
* In testing mode, it will generate migrations from scratch without applying them.
|
|
938
|
-
*
|
|
939
|
-
* Does nothing in production mode, you must handle migrations manually.
|
|
940
|
-
*/
|
|
941
|
-
synchronize(provider: DatabaseProvider): Promise<void>;
|
|
942
|
-
/**
|
|
943
|
-
* Mostly used for testing purposes. You can generate SQL migration statements without executing them.
|
|
944
|
-
*/
|
|
945
|
-
generateMigration(provider: DatabaseProvider, prevSnapshot?: any): Promise<{
|
|
946
|
-
statements: string[];
|
|
947
|
-
models: Record<string, unknown>;
|
|
948
|
-
snapshot?: any;
|
|
949
|
-
}>;
|
|
950
|
-
/**
|
|
951
|
-
* Load all tables, enums, sequences, etc. from the provider's repositories.
|
|
952
|
-
*/
|
|
953
|
-
getModels(provider: DatabaseProvider): Record<string, unknown>;
|
|
954
|
-
/**
|
|
955
|
-
* Load the migration snapshot from the database.
|
|
956
|
-
*/
|
|
957
|
-
protected loadDevMigrations(provider: DatabaseProvider): Promise<DevMigrations | undefined>;
|
|
958
|
-
protected saveDevMigrations(provider: DatabaseProvider, curr: Record<string, any>, devMigrations?: DevMigrations): Promise<void>;
|
|
959
|
-
protected executeStatements(statements: string[], provider: DatabaseProvider, catchErrors?: boolean): Promise<void>;
|
|
960
|
-
protected createSchemaIfNotExists(provider: DatabaseProvider, schemaName: string): Promise<void>;
|
|
961
|
-
/**
|
|
962
|
-
* Try to load the official Drizzle Kit API.
|
|
963
|
-
* If not available, fallback to the local kit import.
|
|
964
|
-
*/
|
|
965
|
-
protected importDrizzleKit(): typeof DrizzleKit;
|
|
966
|
-
}
|
|
967
|
-
declare const devMigrationsSchema: alepha1.TObject<{
|
|
968
|
-
id: alepha1.TNumber;
|
|
969
|
-
name: alepha1.TString;
|
|
970
|
-
snapshot: alepha1.TString;
|
|
971
|
-
created_at: alepha1.TString;
|
|
972
|
-
}>;
|
|
973
|
-
type DevMigrations = Static<typeof devMigrationsSchema>;
|
|
974
|
-
//#endregion
|
|
975
|
-
//#region src/orm/providers/drivers/DatabaseProvider.d.ts
|
|
976
|
-
type SQLLike = SQLWrapper | string;
|
|
977
|
-
declare abstract class DatabaseProvider {
|
|
978
|
-
protected readonly alepha: Alepha;
|
|
979
|
-
protected readonly log: alepha_logger0.Logger;
|
|
980
|
-
protected abstract readonly builder: ModelBuilder;
|
|
981
|
-
protected abstract readonly kit: DrizzleKitProvider;
|
|
982
|
-
abstract readonly db: PgDatabase<any>;
|
|
983
|
-
abstract readonly dialect: "postgresql" | "sqlite";
|
|
984
|
-
abstract readonly url: string;
|
|
985
|
-
readonly enums: Map<string, unknown>;
|
|
986
|
-
readonly tables: Map<string, unknown>;
|
|
987
|
-
readonly sequences: Map<string, unknown>;
|
|
988
|
-
get name(): string;
|
|
989
|
-
get schema(): string;
|
|
990
|
-
table<T extends TObject>(entity: EntityDescriptor<T>): PgTableWithColumns<SchemaToTableConfig<T>>;
|
|
991
|
-
registerEntity(entity: EntityDescriptor): void;
|
|
992
|
-
registerSequence(sequence: SequenceDescriptor): void;
|
|
993
|
-
abstract execute(statement: SQLLike): Promise<Record<string, unknown>[]>;
|
|
994
|
-
run<T extends TObject>(statement: SQLLike, schema: T): Promise<Array<Static<T>>>;
|
|
995
|
-
/**
|
|
996
|
-
* Get migrations folder path - can be overridden
|
|
997
|
-
*/
|
|
998
|
-
protected getMigrationsFolder(): string;
|
|
999
|
-
/**
|
|
1000
|
-
* Base migration orchestration - handles environment logic
|
|
1001
|
-
*/
|
|
1002
|
-
protected migrateDatabase(): Promise<void>;
|
|
1003
|
-
/**
|
|
1004
|
-
* Production: run migrations from folder
|
|
1005
|
-
*/
|
|
1006
|
-
protected runProductionMigration(migrationsFolder: string): Promise<void>;
|
|
1007
|
-
/**
|
|
1008
|
-
* Test: always synchronize
|
|
1009
|
-
*/
|
|
1010
|
-
protected runTestMigration(): Promise<void>;
|
|
1011
|
-
/**
|
|
1012
|
-
* Development: default to synchronize (can be overridden)
|
|
1013
|
-
*/
|
|
1014
|
-
protected runDevelopmentMigration(migrationsFolder: string): Promise<void>;
|
|
1015
|
-
/**
|
|
1016
|
-
* Common synchronization with error handling
|
|
1017
|
-
*/
|
|
1018
|
-
protected synchronizeSchema(): Promise<void>;
|
|
1019
|
-
/**
|
|
1020
|
-
* Provider-specific migration execution
|
|
1021
|
-
* MUST be implemented by each provider
|
|
1022
|
-
*/
|
|
1023
|
-
protected abstract executeMigrations(migrationsFolder: string): Promise<void>;
|
|
1024
|
-
}
|
|
1025
|
-
//#endregion
|
|
1026
|
-
//#region src/orm/services/PgJsonQueryManager.d.ts
|
|
1027
|
-
/**
|
|
1028
|
-
* Manages JSONB query generation for nested object and array queries in PostgreSQL.
|
|
1029
|
-
* This class handles complex nested queries using PostgreSQL's JSONB operators.
|
|
1030
|
-
*/
|
|
1031
|
-
declare class PgJsonQueryManager {
|
|
1032
|
-
/**
|
|
1033
|
-
* Check if a query contains nested JSONB queries.
|
|
1034
|
-
* A nested query is when the value is an object with operator keys.
|
|
1035
|
-
*/
|
|
1036
|
-
hasNestedQuery(where: PgQueryWhere<TObject>): boolean;
|
|
1037
|
-
/**
|
|
1038
|
-
* Build a JSONB query condition for nested object queries.
|
|
1039
|
-
* Supports deep nesting like: { profile: { contact: { email: { eq: "test@example.com" } } } }
|
|
1040
|
-
*
|
|
1041
|
-
* @param column The JSONB column
|
|
1042
|
-
* @param path The path to the nested property (e.g., ['profile', 'contact', 'email'])
|
|
1043
|
-
* @param operator The filter operator (e.g., { eq: "test@example.com" })
|
|
1044
|
-
* @param dialect Database dialect (postgresql or sqlite)
|
|
1045
|
-
* @param columnSchema Optional schema of the JSON column for type inference
|
|
1046
|
-
* @returns SQL condition
|
|
1047
|
-
*/
|
|
1048
|
-
buildJsonbCondition(column: PgColumn, path: string[], operator: FilterOperators<any>, dialect: "postgresql" | "sqlite", columnSchema?: any): SQL | undefined;
|
|
1049
|
-
/**
|
|
1050
|
-
* Build JSONB array query conditions.
|
|
1051
|
-
* Supports queries like: { addresses: { city: { eq: "Wonderland" } } }
|
|
1052
|
-
* which translates to: EXISTS (SELECT 1 FROM jsonb_array_elements(addresses) elem WHERE elem->>'city' = 'Wonderland')
|
|
1053
|
-
*
|
|
1054
|
-
* @param dialect Database dialect (postgresql or sqlite)
|
|
1055
|
-
* Note: SQLite array queries are not yet supported
|
|
1056
|
-
*/
|
|
1057
|
-
buildJsonbArrayCondition(column: PgColumn, path: string[], arrayPath: string, operator: FilterOperators<any>, dialect: "postgresql" | "sqlite"): SQL | undefined;
|
|
1058
|
-
/**
|
|
1059
|
-
* Apply a filter operator to a JSONB value.
|
|
1060
|
-
* @param dialect Database dialect for appropriate casting syntax
|
|
1061
|
-
* @param fieldType Optional field type from schema for smart casting
|
|
1062
|
-
*/
|
|
1063
|
-
private applyOperatorToJsonValue;
|
|
1064
|
-
/**
|
|
1065
|
-
* Parse a nested query object and extract the path and operator.
|
|
1066
|
-
* For example: { profile: { contact: { email: { eq: "test@example.com" } } } }
|
|
1067
|
-
* Returns: { path: ['profile', 'contact', 'email'], operator: { eq: "test@example.com" } }
|
|
1068
|
-
*/
|
|
1069
|
-
parseNestedQuery(nestedQuery: any, currentPath?: string[]): Array<{
|
|
1070
|
-
path: string[];
|
|
1071
|
-
operator: FilterOperators<any>;
|
|
1072
|
-
}>;
|
|
1073
|
-
/**
|
|
1074
|
-
* Determine if a property is a JSONB column based on the schema.
|
|
1075
|
-
* A column is JSONB if it's defined as an object or array in the TypeBox schema.
|
|
1076
|
-
*/
|
|
1077
|
-
isJsonbColumn(schema: TObject, columnName: string): boolean;
|
|
1078
|
-
/**
|
|
1079
|
-
* Check if an array property contains primitive types (string, number, boolean, etc.)
|
|
1080
|
-
* rather than objects. Primitive arrays should use native Drizzle operators.
|
|
1081
|
-
* @returns true if the array contains primitives, false if it contains objects
|
|
1082
|
-
*/
|
|
1083
|
-
isPrimitiveArray(schema: TObject, columnName: string): boolean;
|
|
1084
|
-
/**
|
|
1085
|
-
* Get the type of a field by navigating through a schema path.
|
|
1086
|
-
* Used for smart type casting in SQL queries.
|
|
1087
|
-
*
|
|
1088
|
-
* @param columnSchema The schema of the JSON column (e.g., t.object({ age: t.integer() }))
|
|
1089
|
-
* @param path The path to navigate (e.g., ['contact', 'email'])
|
|
1090
|
-
* @returns The type string (e.g., 'integer', 'number', 'string') or undefined if not found
|
|
1091
|
-
*/
|
|
1092
|
-
private getFieldType;
|
|
1093
|
-
/**
|
|
1094
|
-
* Check if a nested path points to an array property.
|
|
1095
|
-
*/
|
|
1096
|
-
isArrayProperty(schema: TObject, path: string[]): boolean;
|
|
1097
|
-
}
|
|
1098
|
-
//#endregion
|
|
1099
|
-
//#region src/orm/services/QueryManager.d.ts
|
|
1100
|
-
declare class QueryManager {
|
|
1101
|
-
protected readonly jsonQueryManager: PgJsonQueryManager;
|
|
1102
|
-
protected readonly alepha: Alepha;
|
|
1103
|
-
/**
|
|
1104
|
-
* Convert a query object to a SQL query.
|
|
1105
|
-
*/
|
|
1106
|
-
toSQL(query: PgQueryWhereOrSQL<TObject>, options: {
|
|
1107
|
-
schema: TObject;
|
|
1108
|
-
col: (key: string) => PgColumn;
|
|
1109
|
-
joins?: PgJoin[];
|
|
1110
|
-
dialect: "postgresql" | "sqlite";
|
|
1111
|
-
}): SQL | undefined;
|
|
1112
|
-
/**
|
|
1113
|
-
* Build a JSONB query for nested object/array queries.
|
|
1114
|
-
*/
|
|
1115
|
-
protected buildJsonbQuery(column: PgColumn, nestedQuery: any, schema: TObject, columnName: string, dialect: "postgresql" | "sqlite"): SQL | undefined;
|
|
1116
|
-
/**
|
|
1117
|
-
* Check if an object has any filter operator properties.
|
|
1118
|
-
*/
|
|
1119
|
-
protected hasFilterOperatorProperties(obj: any): boolean;
|
|
1120
|
-
/**
|
|
1121
|
-
* Map a filter operator to a SQL query.
|
|
1122
|
-
*/
|
|
1123
|
-
mapOperatorToSql(operator: FilterOperators<any> | any, column: PgColumn, columnSchema?: TObject, columnName?: string, dialect?: "postgresql" | "sqlite"): SQL | undefined;
|
|
1124
|
-
/**
|
|
1125
|
-
* Parse pagination sort string to orderBy format.
|
|
1126
|
-
* Format: "firstName,-lastName" -> [{ column: "firstName", direction: "asc" }, { column: "lastName", direction: "desc" }]
|
|
1127
|
-
* - Columns separated by comma
|
|
1128
|
-
* - Prefix with '-' for DESC direction
|
|
1129
|
-
*
|
|
1130
|
-
* @param sort Pagination sort string
|
|
1131
|
-
* @returns OrderBy array or single object
|
|
1132
|
-
*/
|
|
1133
|
-
parsePaginationSort(sort: string): Array<{
|
|
1134
|
-
column: string;
|
|
1135
|
-
direction: "asc" | "desc";
|
|
1136
|
-
}> | {
|
|
1137
|
-
column: string;
|
|
1138
|
-
direction: "asc" | "desc";
|
|
1139
|
-
};
|
|
1140
|
-
/**
|
|
1141
|
-
* Normalize orderBy parameter to array format.
|
|
1142
|
-
* Supports 3 modes:
|
|
1143
|
-
* 1. String: "name" -> [{ column: "name", direction: "asc" }]
|
|
1144
|
-
* 2. Object: { column: "name", direction: "desc" } -> [{ column: "name", direction: "desc" }]
|
|
1145
|
-
* 3. Array: [{ column: "name" }, { column: "age", direction: "desc" }] -> normalized array
|
|
1146
|
-
*
|
|
1147
|
-
* @param orderBy The orderBy parameter
|
|
1148
|
-
* @returns Normalized array of order by clauses
|
|
1149
|
-
*/
|
|
1150
|
-
normalizeOrderBy(orderBy: any): Array<{
|
|
1151
|
-
column: string;
|
|
1152
|
-
direction: "asc" | "desc";
|
|
1153
|
-
}>;
|
|
1154
|
-
/**
|
|
1155
|
-
* Create a pagination object.
|
|
1156
|
-
*
|
|
1157
|
-
* @deprecated Use `createPagination` from alepha instead.
|
|
1158
|
-
* This method now delegates to the framework-level helper.
|
|
1159
|
-
*
|
|
1160
|
-
* @param entities The entities to paginate.
|
|
1161
|
-
* @param limit The limit of the pagination.
|
|
1162
|
-
* @param offset The offset of the pagination.
|
|
1163
|
-
* @param sort Optional sort metadata to include in response.
|
|
1164
|
-
*/
|
|
1165
|
-
createPagination<T>(entities: T[], limit?: number, offset?: number, sort?: Array<{
|
|
1166
|
-
column: string;
|
|
1167
|
-
direction: "asc" | "desc";
|
|
1168
|
-
}>): alepha1.Page<T>;
|
|
1169
|
-
}
|
|
1170
|
-
interface PgJoin {
|
|
1171
|
-
table: string;
|
|
1172
|
-
schema: TObject;
|
|
1173
|
-
key: string;
|
|
1174
|
-
col: (key: string) => PgColumn;
|
|
1175
|
-
parent?: string;
|
|
1176
|
-
}
|
|
1177
|
-
//#endregion
|
|
1178
|
-
//#region src/orm/services/PgRelationManager.d.ts
|
|
1179
|
-
declare class PgRelationManager {
|
|
1180
|
-
/**
|
|
1181
|
-
* Recursively build joins for the query builder based on the relations map
|
|
1182
|
-
*/
|
|
1183
|
-
buildJoins(provider: DatabaseProvider, builder: PgSelectBase<any, any, any>, joins: Array<PgJoin>, withRelations: PgRelationMap<TObject>, table: PgTableWithColumns<any>, parentKey?: string): void;
|
|
1184
|
-
/**
|
|
1185
|
-
* Map a row with its joined relations based on the joins definition
|
|
1186
|
-
*/
|
|
1187
|
-
mapRowWithJoins(record: Record<string, unknown>, row: Record<string, unknown>, schema: TObject, joins: PgJoin[], parentKey?: string): Record<string, unknown>;
|
|
1188
|
-
/**
|
|
1189
|
-
* Check if all values in an object are null (indicates a left join with no match)
|
|
1190
|
-
*/
|
|
1191
|
-
private isAllNull;
|
|
1192
|
-
/**
|
|
1193
|
-
* Build a schema that includes all join properties recursively
|
|
1194
|
-
*/
|
|
1195
|
-
buildSchemaWithJoins(baseSchema: TObject, joins: PgJoin[], parentPath?: string): TObject;
|
|
1196
|
-
}
|
|
1197
|
-
//#endregion
|
|
1198
|
-
//#region src/orm/services/Repository.d.ts
|
|
1199
|
-
declare abstract class Repository<T extends TObject> {
|
|
1200
|
-
readonly entity: EntityDescriptor<T>;
|
|
1201
|
-
readonly provider: DatabaseProvider;
|
|
1202
|
-
protected readonly relationManager: PgRelationManager;
|
|
1203
|
-
protected readonly queryManager: QueryManager;
|
|
1204
|
-
protected readonly dateTimeProvider: DateTimeProvider;
|
|
1205
|
-
protected readonly alepha: Alepha;
|
|
1206
|
-
constructor(entity: EntityDescriptor<T>, provider?: typeof DatabaseProvider);
|
|
1207
|
-
/**
|
|
1208
|
-
* Represents the primary key of the table.
|
|
1209
|
-
* - Key is the name of the primary key column.
|
|
1210
|
-
* - Type is the type (TypeBox) of the primary key column.
|
|
1211
|
-
*
|
|
1212
|
-
* ID is mandatory. If the table does not have a primary key, it will throw an error.
|
|
1213
|
-
*/
|
|
1214
|
-
get id(): {
|
|
1215
|
-
type: TSchema;
|
|
1216
|
-
key: keyof T["properties"];
|
|
1217
|
-
col: PgColumn;
|
|
1218
|
-
};
|
|
1219
|
-
/**
|
|
1220
|
-
* Get Drizzle table object.
|
|
1221
|
-
*/
|
|
1222
|
-
get table(): PgTableWithColumns<SchemaToTableConfig<T>>;
|
|
1223
|
-
/**
|
|
1224
|
-
* Get SQL table name. (from Drizzle table object)
|
|
1225
|
-
*/
|
|
1226
|
-
get tableName(): string;
|
|
1227
|
-
/**
|
|
1228
|
-
* Getter for the database connection from the database provider.
|
|
1229
|
-
*/
|
|
1230
|
-
protected get db(): PgDatabase<any>;
|
|
1231
|
-
/**
|
|
1232
|
-
* Execute a SQL query.
|
|
1233
|
-
*
|
|
1234
|
-
* This method allows executing raw SQL queries against the database.
|
|
1235
|
-
* This is by far the easiest way to run custom queries that are not covered by the repository's built-in methods!
|
|
1236
|
-
*
|
|
1237
|
-
* You must use the `sql` tagged template function from Drizzle ORM to create the query. https://orm.drizzle.team/docs/sql
|
|
1238
|
-
*
|
|
1239
|
-
* @example
|
|
1240
|
-
* ```ts
|
|
1241
|
-
* class App {
|
|
1242
|
-
* repository = $repository({ ... });
|
|
1243
|
-
* async getAdults() {
|
|
1244
|
-
* const users = repository.table; // Drizzle table object
|
|
1245
|
-
* await repository.query(sql`SELECT * FROM ${users} WHERE ${users.age} > ${18}`);
|
|
1246
|
-
* // or better
|
|
1247
|
-
* await repository.query((users) => sql`SELECT * FROM ${users} WHERE ${users.age} > ${18}`);
|
|
1248
|
-
* }
|
|
1249
|
-
* }
|
|
1250
|
-
* ```
|
|
1251
|
-
*/
|
|
1252
|
-
query<R extends TObject = T>(query: SQLLike | ((table: PgTableWithColumns<SchemaToTableConfig<T>>, db: PgDatabase<any>) => SQLLike), schema?: R): Promise<Static<R>[]>;
|
|
1253
|
-
/**
|
|
1254
|
-
* Map raw database fields to entity fields. (handles column name differences)
|
|
1255
|
-
*/
|
|
1256
|
-
protected mapRawFieldsToEntity(row: Record<string, unknown>): any;
|
|
1257
|
-
/**
|
|
1258
|
-
* Get a Drizzle column from the table by his name.
|
|
1259
|
-
*/
|
|
1260
|
-
protected col(name: keyof StaticEncode<T>): PgColumn;
|
|
1261
|
-
/**
|
|
1262
|
-
* Run a transaction.
|
|
1263
|
-
*/
|
|
1264
|
-
transaction<T>(transaction: (tx: PgTransaction<any, Record<string, any>, any>) => Promise<T>, config?: PgTransactionConfig): Promise<T>;
|
|
1265
|
-
/**
|
|
1266
|
-
* Start a SELECT query on the table.
|
|
1267
|
-
*/
|
|
1268
|
-
protected rawSelect(opts?: StatementOptions): drizzle_orm_pg_core0.PgSelectBase<string, Record<string, PgColumn<drizzle_orm0.ColumnBaseConfig<drizzle_orm0.ColumnDataType, string>, {}, {}>>, "single", Record<string, "not-null">, false, never, {
|
|
1269
|
-
[x: string]: unknown;
|
|
1270
|
-
}[], {
|
|
1271
|
-
[x: string]: PgColumn<drizzle_orm0.ColumnBaseConfig<drizzle_orm0.ColumnDataType, string>, {}, {}>;
|
|
1272
|
-
}>;
|
|
1273
|
-
/**
|
|
1274
|
-
* Start a SELECT DISTINCT query on the table.
|
|
1275
|
-
*/
|
|
1276
|
-
protected rawSelectDistinct(opts?: StatementOptions, columns?: (keyof Static<T>)[]): drizzle_orm_pg_core0.PgSelectBase<string, Record<string, any>, "partial", Record<string, "not-null">, false, never, {
|
|
1277
|
-
[x: string]: any;
|
|
1278
|
-
}[], {
|
|
1279
|
-
[x: string]: any;
|
|
1280
|
-
}>;
|
|
1281
|
-
/**
|
|
1282
|
-
* Start an INSERT query on the table.
|
|
1283
|
-
*/
|
|
1284
|
-
protected rawInsert(opts?: StatementOptions): drizzle_orm_pg_core0.PgInsertBuilder<PgTableWithColumns<SchemaToTableConfig<T>>, any, false>;
|
|
1285
|
-
/**
|
|
1286
|
-
* Start an UPDATE query on the table.
|
|
1287
|
-
*/
|
|
1288
|
-
protected rawUpdate(opts?: StatementOptions): drizzle_orm_pg_core0.PgUpdateBuilder<PgTableWithColumns<SchemaToTableConfig<T>>, any>;
|
|
1289
|
-
/**
|
|
1290
|
-
* Start a DELETE query on the table.
|
|
1291
|
-
*/
|
|
1292
|
-
protected rawDelete(opts?: StatementOptions): drizzle_orm_pg_core0.PgDeleteBase<PgTableWithColumns<SchemaToTableConfig<T>>, any, undefined, undefined, false, never>;
|
|
1293
|
-
/**
|
|
1294
|
-
* Create a Drizzle `select` query based on a JSON query object.
|
|
1295
|
-
*
|
|
1296
|
-
* > This method is the base for `find`, `findOne`, `findById`, and `paginate`.
|
|
1297
|
-
*/
|
|
1298
|
-
findMany<R extends PgRelationMap<T>>(query?: PgQueryRelations<T, R>, opts?: StatementOptions): Promise<PgStatic<T, R>[]>;
|
|
1299
|
-
/**
|
|
1300
|
-
* Find a single entity.
|
|
1301
|
-
*/
|
|
1302
|
-
findOne<R extends PgRelationMap<T>>(query: Pick<PgQueryRelations<T, R>, "with" | "where">, opts?: StatementOptions): Promise<PgStatic<T, R>>;
|
|
1303
|
-
/**
|
|
1304
|
-
* Find entities with pagination.
|
|
1305
|
-
*
|
|
1306
|
-
* It uses the same parameters as `find()`, but adds pagination metadata to the response.
|
|
1307
|
-
*
|
|
1308
|
-
* > Pagination CAN also do a count query to get the total number of elements.
|
|
1309
|
-
*/
|
|
1310
|
-
paginate<R extends PgRelationMap<T>>(pagination?: PageQuery$1, query?: PgQueryRelations<T, R>, opts?: StatementOptions & {
|
|
1311
|
-
count?: boolean;
|
|
1312
|
-
}): Promise<Page$1<PgStatic<T, R>>>;
|
|
1313
|
-
/**
|
|
1314
|
-
* Find an entity by ID.
|
|
1315
|
-
*
|
|
1316
|
-
* This is a convenience method for `findOne` with a where clause on the primary key.
|
|
1317
|
-
* If you need more complex queries, use `findOne` instead.
|
|
1318
|
-
*/
|
|
1319
|
-
findById(id: string | number, opts?: StatementOptions): Promise<Static<T>>;
|
|
1320
|
-
/**
|
|
1321
|
-
* Helper to create a type-safe query object.
|
|
1322
|
-
*/
|
|
1323
|
-
createQuery(): PgQuery<T>;
|
|
1324
|
-
/**
|
|
1325
|
-
* Helper to create a type-safe where clause.
|
|
1326
|
-
*/
|
|
1327
|
-
createQueryWhere(): PgQueryWhere<T>;
|
|
1328
|
-
/**
|
|
1329
|
-
* Create an entity.
|
|
1330
|
-
*
|
|
1331
|
-
* @param data The entity to create.
|
|
1332
|
-
* @param opts The options for creating the entity.
|
|
1333
|
-
* @returns The ID of the created entity.
|
|
1334
|
-
*/
|
|
1335
|
-
create(data: Static<TObjectInsert<T>>, opts?: StatementOptions): Promise<Static<T>>;
|
|
1336
|
-
/**
|
|
1337
|
-
* Create many entities.
|
|
1338
|
-
*
|
|
1339
|
-
* @param values The entities to create.
|
|
1340
|
-
* @param opts The statement options.
|
|
1341
|
-
* @returns The created entities.
|
|
1342
|
-
*/
|
|
1343
|
-
createMany(values: Array<Static<TObjectInsert<T>>>, opts?: StatementOptions): Promise<Static<T>[]>;
|
|
1344
|
-
/**
|
|
1345
|
-
* Find an entity and update it.
|
|
1346
|
-
*/
|
|
1347
|
-
updateOne(where: PgQueryWhereOrSQL<T>, data: Partial<Static<TObjectUpdate<T>>>, opts?: StatementOptions): Promise<Static<T>>;
|
|
1348
|
-
/**
|
|
1349
|
-
* Save a given entity.
|
|
1350
|
-
*
|
|
1351
|
-
* @example
|
|
1352
|
-
* ```ts
|
|
1353
|
-
* const entity = await repository.findById(1);
|
|
1354
|
-
* entity.name = "New Name"; // update a field
|
|
1355
|
-
* delete entity.description; // delete a field
|
|
1356
|
-
* await repository.save(entity);
|
|
1357
|
-
* ```
|
|
1358
|
-
*
|
|
1359
|
-
* Difference with `updateById/updateOne`:
|
|
1360
|
-
*
|
|
1361
|
-
* - requires the entity to be fetched first (whole object is expected)
|
|
1362
|
-
* - check pg.version() if present -> optimistic locking
|
|
1363
|
-
* - validate entity against schema
|
|
1364
|
-
* - undefined values will be set to null, not ignored!
|
|
1365
|
-
*
|
|
1366
|
-
* @see {@link DbVersionMismatchError}
|
|
1367
|
-
*/
|
|
1368
|
-
save(entity: Static<T>, opts?: StatementOptions): Promise<void>;
|
|
1369
|
-
/**
|
|
1370
|
-
* Find an entity by ID and update it.
|
|
1371
|
-
*/
|
|
1372
|
-
updateById(id: string | number, data: Partial<Static<TObjectUpdate<T>>>, opts?: StatementOptions): Promise<Static<T>>;
|
|
1373
|
-
/**
|
|
1374
|
-
* Find many entities and update all of them.
|
|
1375
|
-
*/
|
|
1376
|
-
updateMany(where: PgQueryWhereOrSQL<T>, data: Partial<Static<TObjectUpdate<T>>>, opts?: StatementOptions): Promise<Array<number | string>>;
|
|
1377
|
-
/**
|
|
1378
|
-
* Find many and delete all of them.
|
|
1379
|
-
* @returns Array of deleted entity IDs
|
|
1380
|
-
*/
|
|
1381
|
-
deleteMany(where?: PgQueryWhereOrSQL<T>, opts?: StatementOptions): Promise<Array<number | string>>;
|
|
1382
|
-
/**
|
|
1383
|
-
* Delete all entities.
|
|
1384
|
-
* @returns Array of deleted entity IDs
|
|
1385
|
-
*/
|
|
1386
|
-
clear(opts?: StatementOptions): Promise<Array<number | string>>;
|
|
1387
|
-
/**
|
|
1388
|
-
* Delete the given entity.
|
|
1389
|
-
*
|
|
1390
|
-
* You must fetch the entity first in order to delete it.
|
|
1391
|
-
* @returns Array containing the deleted entity ID
|
|
1392
|
-
*/
|
|
1393
|
-
destroy(entity: Static<T>, opts?: StatementOptions): Promise<Array<number | string>>;
|
|
1394
|
-
/**
|
|
1395
|
-
* Find an entity and delete it.
|
|
1396
|
-
* @returns Array of deleted entity IDs (should contain at most one ID)
|
|
1397
|
-
*/
|
|
1398
|
-
deleteOne(where?: PgQueryWhereOrSQL<T>, opts?: StatementOptions): Promise<Array<number | string>>;
|
|
1399
|
-
/**
|
|
1400
|
-
* Find an entity by ID and delete it.
|
|
1401
|
-
* @returns Array containing the deleted entity ID
|
|
1402
|
-
* @throws DbEntityNotFoundError if the entity is not found
|
|
1403
|
-
*/
|
|
1404
|
-
deleteById(id: string | number, opts?: StatementOptions): Promise<Array<number | string>>;
|
|
1405
|
-
/**
|
|
1406
|
-
* Count entities.
|
|
1407
|
-
*/
|
|
1408
|
-
count(where?: PgQueryWhereOrSQL<T>, opts?: StatementOptions): Promise<number>;
|
|
1409
|
-
protected conflictMessagePattern: string;
|
|
1410
|
-
protected handleError(error: unknown, message: string): DbError;
|
|
1411
|
-
protected withDeletedAt(where: PgQueryWhereOrSQL<T>, opts?: {
|
|
1412
|
-
force?: boolean;
|
|
1413
|
-
}): PgQueryWhereOrSQL<T>;
|
|
1414
|
-
protected deletedAt(): PgAttrField | undefined;
|
|
1415
|
-
/**
|
|
1416
|
-
* Convert something to valid Pg Insert Value.
|
|
1417
|
-
*/
|
|
1418
|
-
protected cast(data: any, insert: boolean): PgInsertValue<PgTableWithColumns<SchemaToTableConfig<T>>>;
|
|
1419
|
-
/**
|
|
1420
|
-
* Transform a row from the database into a clean entity.
|
|
1421
|
-
*/
|
|
1422
|
-
protected clean<T extends TObject>(row: Record<string, unknown>, schema: T): Static<T>;
|
|
1423
|
-
/**
|
|
1424
|
-
* Clean a row with joins recursively
|
|
1425
|
-
*/
|
|
1426
|
-
protected cleanWithJoins<T extends TObject>(row: Record<string, unknown>, schema: T, joins: PgJoin[], parentPath?: string): Static<T>;
|
|
1427
|
-
/**
|
|
1428
|
-
* Convert a where clause to SQL.
|
|
1429
|
-
*/
|
|
1430
|
-
protected toSQL(where: PgQueryWhereOrSQL<T>, joins?: PgJoin[]): SQL | undefined;
|
|
1431
|
-
/**
|
|
1432
|
-
* Get the where clause for an ID.
|
|
1433
|
-
*
|
|
1434
|
-
* @param id The ID to get the where clause for.
|
|
1435
|
-
* @returns The where clause for the ID.
|
|
1436
|
-
*/
|
|
1437
|
-
protected getWhereId(id: string | number): PgQueryWhere<T>;
|
|
1438
|
-
/**
|
|
1439
|
-
* Find a primary key in the schema.
|
|
1440
|
-
*/
|
|
1441
|
-
protected getPrimaryKey(schema: TObject): {
|
|
1442
|
-
key: string;
|
|
1443
|
-
col: PgColumn<drizzle_orm0.ColumnBaseConfig<drizzle_orm0.ColumnDataType, string>, {}, {}>;
|
|
1444
|
-
type: TSchema;
|
|
1445
|
-
};
|
|
1446
|
-
}
|
|
1447
|
-
/**
|
|
1448
|
-
* The options for a statement.
|
|
1449
|
-
*/
|
|
1450
|
-
interface StatementOptions {
|
|
1451
|
-
/**
|
|
1452
|
-
* Transaction to use.
|
|
1453
|
-
*/
|
|
1454
|
-
tx?: PgTransaction<any, Record<string, any>>;
|
|
1455
|
-
/**
|
|
1456
|
-
* Lock strength.
|
|
1457
|
-
*/
|
|
1458
|
-
for?: LockStrength | {
|
|
1459
|
-
config: LockConfig;
|
|
1460
|
-
strength: LockStrength;
|
|
1461
|
-
};
|
|
1462
|
-
/**
|
|
1463
|
-
* If true, ignore soft delete.
|
|
1464
|
-
*/
|
|
1465
|
-
force?: boolean;
|
|
1466
|
-
/**
|
|
1467
|
-
* Force the current time.
|
|
1468
|
-
*/
|
|
1469
|
-
now?: DateTime | string;
|
|
1470
|
-
}
|
|
1471
|
-
//#endregion
|
|
1472
|
-
//#region src/orm/descriptors/$repository.d.ts
|
|
1473
|
-
/**
|
|
1474
|
-
* Get the repository for the given entity.
|
|
1475
|
-
*/
|
|
1476
|
-
declare const $repository: <T extends TObject>(entity: EntityDescriptor<T>) => Repository<T>;
|
|
1477
|
-
//#endregion
|
|
1478
|
-
//#region src/orm/descriptors/$transaction.d.ts
|
|
1479
|
-
/**
|
|
1480
|
-
* Creates a transaction descriptor for database operations requiring atomicity and consistency.
|
|
1481
|
-
*
|
|
1482
|
-
* This descriptor provides a convenient way to wrap database operations in PostgreSQL
|
|
1483
|
-
* transactions, ensuring ACID properties and automatic retry logic for version conflicts.
|
|
1484
|
-
* It integrates seamlessly with the repository pattern and provides built-in handling
|
|
1485
|
-
* for optimistic locking scenarios with automatic retry on version mismatches.
|
|
1486
|
-
*
|
|
1487
|
-
* **Important Notes**:
|
|
1488
|
-
* - All operations within the transaction handler are atomic
|
|
1489
|
-
* - Automatic retry on `PgVersionMismatchError` for optimistic locking
|
|
1490
|
-
* - Pass `{ tx }` option to all repository operations within the transaction
|
|
1491
|
-
* - Transactions are automatically rolled back on any unhandled error
|
|
1492
|
-
* - Use appropriate isolation levels based on your consistency requirements
|
|
1493
|
-
*/
|
|
1494
|
-
declare const $transaction: <T extends any[], R>(opts: TransactionDescriptorOptions<T, R>) => alepha_retry0.RetryDescriptorFn<(...args: T) => Promise<R>>;
|
|
1495
|
-
interface TransactionDescriptorOptions<T extends any[], R> {
|
|
1496
|
-
/**
|
|
1497
|
-
* Transaction handler function that contains all database operations to be executed atomically.
|
|
1498
|
-
*
|
|
1499
|
-
* This function:
|
|
1500
|
-
* - Receives a transaction object as the first parameter
|
|
1501
|
-
* - Should pass the transaction to all repository operations via `{ tx }` option
|
|
1502
|
-
* - All operations within are automatically rolled back if any error occurs
|
|
1503
|
-
* - Has access to the full Alepha dependency injection container
|
|
1504
|
-
* - Will be automatically retried if a `PgVersionMismatchError` occurs
|
|
1505
|
-
*
|
|
1506
|
-
* **Transaction Guidelines**:
|
|
1507
|
-
* - Keep transactions as short as possible to minimize lock contention
|
|
1508
|
-
* - Always pass the `tx` parameter to repository operations
|
|
1509
|
-
* - Handle expected business errors gracefully
|
|
1510
|
-
* - Log important operations for debugging and audit trails
|
|
1511
|
-
* - Consider the impact of long-running transactions on performance
|
|
1512
|
-
*
|
|
1513
|
-
* **Error Handling**:
|
|
1514
|
-
* - Throwing any error will automatically roll back the transaction
|
|
1515
|
-
* - `PgVersionMismatchError` triggers automatic retry logic
|
|
1516
|
-
* - Other database errors will be propagated after rollback
|
|
1517
|
-
* - Use try-catch within the handler for business-specific error handling
|
|
1518
|
-
*
|
|
1519
|
-
* @param tx - The PostgreSQL transaction object to use for all database operations
|
|
1520
|
-
* @param ...args - Additional arguments passed to the transaction function
|
|
1521
|
-
* @returns Promise resolving to the transaction result
|
|
1522
|
-
*
|
|
1523
|
-
* @example
|
|
1524
|
-
* ```ts
|
|
1525
|
-
* handler: async (tx, orderId: string, newStatus: string) => {
|
|
1526
|
-
* // Get the current order (with transaction)
|
|
1527
|
-
* const order = await this.orders.findById(orderId, { tx });
|
|
1528
|
-
*
|
|
1529
|
-
* // Validate business rules
|
|
1530
|
-
* if (!this.isValidStatusTransition(order.status, newStatus)) {
|
|
1531
|
-
* throw new Error(`Invalid status transition: ${order.status} -> ${newStatus}`);
|
|
1532
|
-
* }
|
|
1533
|
-
*
|
|
1534
|
-
* // Update order status (with transaction)
|
|
1535
|
-
* const updatedOrder = await this.orders.updateById(
|
|
1536
|
-
* orderId,
|
|
1537
|
-
* { status: newStatus },
|
|
1538
|
-
* { tx }
|
|
1539
|
-
* );
|
|
1540
|
-
*
|
|
1541
|
-
* // Create audit log (with transaction)
|
|
1542
|
-
* await this.auditLogs.create({
|
|
1543
|
-
* id: generateUUID(),
|
|
1544
|
-
* entityId: orderId,
|
|
1545
|
-
* action: 'status_change',
|
|
1546
|
-
* oldValue: order.status,
|
|
1547
|
-
* newValue: newStatus,
|
|
1548
|
-
* timestamp: new Date().toISOString()
|
|
1549
|
-
* }, { tx });
|
|
1550
|
-
*
|
|
1551
|
-
* return updatedOrder;
|
|
1552
|
-
* }
|
|
1553
|
-
* ```
|
|
1554
|
-
*/
|
|
1555
|
-
handler: (tx: PgTransaction<any, any, any>, ...args: T) => Promise<R>;
|
|
1556
|
-
/**
|
|
1557
|
-
* PostgreSQL transaction configuration options.
|
|
1558
|
-
*
|
|
1559
|
-
* This allows you to customize transaction behavior including:
|
|
1560
|
-
* - **Isolation Level**: Controls visibility of concurrent transaction changes
|
|
1561
|
-
* - **Access Mode**: Whether the transaction is read-only or read-write
|
|
1562
|
-
* - **Deferrable**: For serializable transactions, allows deferring to avoid conflicts
|
|
1563
|
-
*
|
|
1564
|
-
* **Isolation Levels**:
|
|
1565
|
-
* - **read_uncommitted**: Lowest isolation, allows dirty reads (rarely used)
|
|
1566
|
-
* - **read_committed**: Default level, prevents dirty reads
|
|
1567
|
-
* - **repeatable_read**: Prevents dirty and non-repeatable reads
|
|
1568
|
-
* - **serializable**: Highest isolation, full ACID compliance
|
|
1569
|
-
*
|
|
1570
|
-
* **Access Modes**:
|
|
1571
|
-
* - **read_write**: Default, allows both read and write operations
|
|
1572
|
-
* - **read_only**: Only allows read operations, can provide performance benefits
|
|
1573
|
-
*
|
|
1574
|
-
* **When to Use Different Isolation Levels**:
|
|
1575
|
-
* - **read_committed**: Most common operations, good balance of consistency and performance
|
|
1576
|
-
* - **repeatable_read**: When you need consistent reads throughout the transaction
|
|
1577
|
-
* - **serializable**: Critical financial operations, when absolute consistency is required
|
|
1578
|
-
*
|
|
1579
|
-
* @example
|
|
1580
|
-
* ```ts
|
|
1581
|
-
* config: {
|
|
1582
|
-
* isolationLevel: 'serializable', // Highest consistency for financial operations
|
|
1583
|
-
* accessMode: 'read_write'
|
|
1584
|
-
* }
|
|
1585
|
-
* ```
|
|
1586
|
-
*
|
|
1587
|
-
* @example
|
|
1588
|
-
* ```ts
|
|
1589
|
-
* config: {
|
|
1590
|
-
* isolationLevel: 'read_committed', // Default level for most operations
|
|
1591
|
-
* accessMode: 'read_only' // Performance optimization for read-only operations
|
|
1592
|
-
* }
|
|
1593
|
-
* ```
|
|
1594
|
-
*/
|
|
1595
|
-
config?: PgTransactionConfig;
|
|
1596
|
-
}
|
|
1597
|
-
type TransactionContext = PgTransaction<any, any, any>;
|
|
1598
|
-
//#endregion
|
|
1599
|
-
//#region src/orm/errors/DbConflictError.d.ts
|
|
1600
|
-
declare class DbConflictError extends DbError {
|
|
1601
|
-
readonly name = "DbConflictError";
|
|
1602
|
-
readonly status = 409;
|
|
1603
|
-
}
|
|
1604
|
-
//#endregion
|
|
1605
|
-
//#region src/orm/errors/DbEntityNotFoundError.d.ts
|
|
1606
|
-
declare class DbEntityNotFoundError extends DbError {
|
|
1607
|
-
readonly name = "DbEntityNotFoundError";
|
|
1608
|
-
readonly status = 404;
|
|
1609
|
-
constructor(entityName: string);
|
|
1610
|
-
}
|
|
1611
|
-
//#endregion
|
|
1612
|
-
//#region src/orm/errors/DbMigrationError.d.ts
|
|
1613
|
-
declare class DbMigrationError extends DbError {
|
|
1614
|
-
readonly name = "DbMigrationError";
|
|
1615
|
-
constructor(cause?: unknown);
|
|
1616
|
-
}
|
|
1617
|
-
//#endregion
|
|
1618
|
-
//#region src/orm/errors/DbVersionMismatchError.d.ts
|
|
1619
|
-
/**
|
|
1620
|
-
* Error thrown when there is a version mismatch.
|
|
1621
|
-
* It's thrown by {@link Repository#save} when the updated entity version does not match the one in the database.
|
|
1622
|
-
* This is used for optimistic concurrency control.
|
|
1623
|
-
*/
|
|
1624
|
-
declare class DbVersionMismatchError extends DbError {
|
|
1625
|
-
readonly name = "DbVersionMismatchError";
|
|
1626
|
-
constructor(table: string, id: any);
|
|
1627
|
-
}
|
|
1628
|
-
//#endregion
|
|
1629
|
-
//#region src/orm/helpers/parseQueryString.d.ts
|
|
1630
|
-
/**
|
|
1631
|
-
* Parse a string query into a PgQueryWhere object.
|
|
1632
|
-
*
|
|
1633
|
-
* Supported syntax:
|
|
1634
|
-
* - Simple equality: "name=John"
|
|
1635
|
-
* - Wildcard patterns: "name=John*" (startsWith), "name=*John" (endsWith), "name=*John*" (contains)
|
|
1636
|
-
* - Operators: "age>18", "age>=18", "age<65", "age<=65", "status!=active"
|
|
1637
|
-
* - NULL checks: "deletedAt=null", "email!=null"
|
|
1638
|
-
* - IN arrays: "status=[pending,active]"
|
|
1639
|
-
* - AND conditions: "name=John&age>18"
|
|
1640
|
-
* - OR conditions: "name=John|email=john@example.com"
|
|
1641
|
-
* - Nested AND/OR: "(name=John|name=Jane)&age>18"
|
|
1642
|
-
* - JSONB nested: "profile.city=Paris"
|
|
1643
|
-
*
|
|
1644
|
-
* @example
|
|
1645
|
-
* ```ts
|
|
1646
|
-
* // Simple equality
|
|
1647
|
-
* parseQueryString("name=John")
|
|
1648
|
-
* // => { name: { eq: "John" } }
|
|
1649
|
-
*
|
|
1650
|
-
* // Wildcard patterns
|
|
1651
|
-
* parseQueryString("name=John*") // startsWith
|
|
1652
|
-
* // => { name: { startsWith: "John" } }
|
|
1653
|
-
* parseQueryString("name=*Smith") // endsWith
|
|
1654
|
-
* // => { name: { endsWith: "Smith" } }
|
|
1655
|
-
* parseQueryString("name=*oh*") // contains
|
|
1656
|
-
* // => { name: { contains: "oh" } }
|
|
1657
|
-
*
|
|
1658
|
-
* // Multiple conditions
|
|
1659
|
-
* parseQueryString("name=John&age>18")
|
|
1660
|
-
* // => { and: [{ name: { eq: "John" } }, { age: { gt: 18 } }] }
|
|
1661
|
-
*
|
|
1662
|
-
* // OR conditions
|
|
1663
|
-
* parseQueryString("status=active|status=pending")
|
|
1664
|
-
* // => { or: [{ status: { eq: "active" } }, { status: { eq: "pending" } }] }
|
|
1665
|
-
*
|
|
1666
|
-
* // Complex nested
|
|
1667
|
-
* parseQueryString("(name=John|name=Jane)&age>18&status!=archived")
|
|
1668
|
-
* // => { and: [
|
|
1669
|
-
* // { or: [{ name: { eq: "John" } }, { name: { eq: "Jane" } }] },
|
|
1670
|
-
* // { age: { gt: 18 } },
|
|
1671
|
-
* // { status: { ne: "archived" } }
|
|
1672
|
-
* // ] }
|
|
1673
|
-
*
|
|
1674
|
-
* // JSONB nested query
|
|
1675
|
-
* parseQueryString("profile.city=Paris&profile.age>25")
|
|
1676
|
-
* // => { profile: { city: { eq: "Paris" }, age: { gt: 25 } } }
|
|
1677
|
-
* ```
|
|
1678
|
-
*/
|
|
1679
|
-
declare function parseQueryString<T extends TObject>(query: string): PgQueryWhere<T>;
|
|
1680
|
-
/**
|
|
1681
|
-
* Helper function to build query strings programmatically
|
|
1682
|
-
*
|
|
1683
|
-
* @example
|
|
1684
|
-
* ```ts
|
|
1685
|
-
* buildQueryString({
|
|
1686
|
-
* and: [
|
|
1687
|
-
* { name: "eq:John" },
|
|
1688
|
-
* { age: "gt:18" }
|
|
1689
|
-
* ]
|
|
1690
|
-
* })
|
|
1691
|
-
* // => "name=John&age>18"
|
|
1692
|
-
* ```
|
|
1693
|
-
*/
|
|
1694
|
-
declare function buildQueryString(where: any): string;
|
|
1695
|
-
//#endregion
|
|
1696
|
-
//#region src/orm/services/PostgresModelBuilder.d.ts
|
|
1697
|
-
declare class PostgresModelBuilder extends ModelBuilder {
|
|
1698
|
-
protected schemas: Map<string, drizzle_orm_pg_core0.PgSchema<string>>;
|
|
1699
|
-
protected getPgSchema(name: string): any;
|
|
1700
|
-
buildTable(entity: EntityDescriptor<any>, options: {
|
|
1701
|
-
tables: Map<string, unknown>;
|
|
1702
|
-
enums: Map<string, unknown>;
|
|
1703
|
-
schema: string;
|
|
1704
|
-
}): void;
|
|
1705
|
-
buildSequence(sequence: SequenceDescriptor, options: {
|
|
1706
|
-
sequences: Map<string, unknown>;
|
|
1707
|
-
schema: string;
|
|
1708
|
-
}): void;
|
|
1709
|
-
/**
|
|
1710
|
-
* Get PostgreSQL-specific config builder for the table.
|
|
1711
|
-
*/
|
|
1712
|
-
protected getTableConfig(entity: EntityDescriptor, tables: Map<string, unknown>): ((self: BuildExtraConfigColumns<string, any, "pg">) => PgTableExtraConfigValue[]) | undefined;
|
|
1713
|
-
schemaToPgColumns: <T extends TObject>(tableName: string, schema: T, nsp: PgSchema, enums: Map<string, unknown>, tables: Map<string, unknown>) => FromSchema<T>;
|
|
1714
|
-
mapFieldToColumn: (tableName: string, fieldName: string, value: TSchema, nsp: PgSchema, enums: Map<string, any>) => any;
|
|
1715
|
-
/**
|
|
1716
|
-
* Map a string to a PG column.
|
|
1717
|
-
*
|
|
1718
|
-
* @param key The key of the field.
|
|
1719
|
-
* @param value The value of the field.
|
|
1720
|
-
*/
|
|
1721
|
-
mapStringToColumn: (key: string, value: TSchema) => drizzle_orm_pg_core0.PgUUIDBuilderInitial<string> | drizzle_orm_pg_core0.PgCustomColumnBuilder<{
|
|
1722
|
-
name: string;
|
|
1723
|
-
dataType: "custom";
|
|
1724
|
-
columnType: "PgCustomColumn";
|
|
1725
|
-
data: Buffer<ArrayBufferLike>;
|
|
1726
|
-
driverParam: unknown;
|
|
1727
|
-
enumValues: undefined;
|
|
1728
|
-
}> | drizzle_orm_pg_core0.PgTimestampStringBuilderInitial<string> | drizzle_orm_pg_core0.PgDateStringBuilderInitial<string> | drizzle_orm_pg_core0.PgTextBuilderInitial<string, [string, ...string[]]>;
|
|
1729
|
-
}
|
|
1730
|
-
//#endregion
|
|
1731
|
-
//#region src/orm/providers/drivers/NodePostgresProvider.d.ts
|
|
1732
|
-
declare module "alepha" {
|
|
1733
|
-
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
1734
|
-
}
|
|
1735
|
-
declare const envSchema: alepha1.TObject<{
|
|
1736
|
-
/**
|
|
1737
|
-
* Main configuration for database connection.
|
|
1738
|
-
* Accept a string in the format of a Postgres connection URL.
|
|
1739
|
-
* Example: postgres://user:password@localhost:5432/database
|
|
1740
|
-
* or
|
|
1741
|
-
* Example: postgres://user:password@localhost:5432/database?sslmode=require
|
|
1742
|
-
*/
|
|
1743
|
-
DATABASE_URL: alepha1.TOptional<alepha1.TString>;
|
|
1744
|
-
/**
|
|
1745
|
-
* In addition to the DATABASE_URL, you can specify the postgres schema name.
|
|
1746
|
-
*
|
|
1747
|
-
* It will monkey patch drizzle tables.
|
|
1748
|
-
*/
|
|
1749
|
-
POSTGRES_SCHEMA: alepha1.TOptional<alepha1.TString>;
|
|
1750
|
-
}>;
|
|
1751
|
-
declare class NodePostgresProvider extends DatabaseProvider {
|
|
1752
|
-
static readonly SSL_MODES: readonly ["require", "allow", "prefer", "verify-full"];
|
|
1753
|
-
protected readonly log: alepha_logger0.Logger;
|
|
1754
|
-
protected readonly env: {
|
|
1755
|
-
DATABASE_URL?: string | undefined;
|
|
1756
|
-
POSTGRES_SCHEMA?: string | undefined;
|
|
1757
|
-
};
|
|
1758
|
-
protected readonly kit: DrizzleKitProvider;
|
|
1759
|
-
protected readonly builder: PostgresModelBuilder;
|
|
1760
|
-
protected client?: postgres.Sql;
|
|
1761
|
-
protected pg?: PostgresJsDatabase;
|
|
1762
|
-
readonly dialect = "postgresql";
|
|
1763
|
-
get name(): string;
|
|
1764
|
-
/**
|
|
1765
|
-
* In testing mode, the schema name will be generated and deleted after the test.
|
|
1766
|
-
*/
|
|
1767
|
-
protected schemaForTesting: string | undefined;
|
|
1768
|
-
get url(): string;
|
|
1769
|
-
/**
|
|
1770
|
-
* Execute a SQL statement.
|
|
1771
|
-
*/
|
|
1772
|
-
execute(statement: SQLLike): Promise<Array<Record<string, unknown>>>;
|
|
1773
|
-
/**
|
|
1774
|
-
* Get Postgres schema used by this provider.
|
|
1775
|
-
*/
|
|
1776
|
-
get schema(): string;
|
|
1777
|
-
/**
|
|
1778
|
-
* Get the Drizzle Postgres database instance.
|
|
1779
|
-
*/
|
|
1780
|
-
get db(): PostgresJsDatabase;
|
|
1781
|
-
protected executeMigrations(migrationsFolder: string): Promise<void>;
|
|
1782
|
-
protected readonly onStart: alepha1.HookDescriptor<"start">;
|
|
1783
|
-
protected readonly onStop: alepha1.HookDescriptor<"stop">;
|
|
1784
|
-
connect(): Promise<void>;
|
|
1785
|
-
close(): Promise<void>;
|
|
1786
|
-
protected migrate: alepha_lock0.LockDescriptor<() => Promise<void>>;
|
|
1787
|
-
/**
|
|
1788
|
-
* Map the DATABASE_URL to postgres client options.
|
|
1789
|
-
*/
|
|
1790
|
-
protected getClientOptions(): postgres.Options<any>;
|
|
1791
|
-
protected ssl(url: URL): "require" | "allow" | "prefer" | "verify-full" | undefined;
|
|
1792
|
-
/**
|
|
1793
|
-
* For testing purposes, generate a unique schema name.
|
|
1794
|
-
* The schema name will be generated based on the current date and time.
|
|
1795
|
-
* It will be in the format of `test_YYYYMMDD_HHMMSS_randomSuffix`.
|
|
1796
|
-
*/
|
|
1797
|
-
protected generateTestSchemaName(): string;
|
|
1798
|
-
}
|
|
1799
|
-
//#endregion
|
|
1800
|
-
//#region src/orm/services/SqliteModelBuilder.d.ts
|
|
1801
|
-
declare class SqliteModelBuilder extends ModelBuilder {
|
|
1802
|
-
buildTable(entity: EntityDescriptor<any>, options: {
|
|
1803
|
-
tables: Map<string, unknown>;
|
|
1804
|
-
enums: Map<string, unknown>;
|
|
1805
|
-
schema: string;
|
|
1806
|
-
}): void;
|
|
1807
|
-
buildSequence(sequence: SequenceDescriptor, options: {
|
|
1808
|
-
sequences: Map<string, unknown>;
|
|
1809
|
-
schema: string;
|
|
1810
|
-
}): void;
|
|
1811
|
-
/**
|
|
1812
|
-
* Get SQLite-specific config builder for the table.
|
|
1813
|
-
*/
|
|
1814
|
-
protected getTableConfig(entity: EntityDescriptor, tables: Map<string, unknown>): ((self: BuildColumns<string, any, "sqlite">) => any) | undefined;
|
|
1815
|
-
schemaToSqliteColumns: <T extends TObject>(tableName: string, schema: T, enums: Map<string, unknown>, tables: Map<string, unknown>) => SchemaToSqliteBuilder<T>;
|
|
1816
|
-
mapFieldToSqliteColumn: (tableName: string, fieldName: string, value: TSchema, enums: Map<string, any>) => pg$1.SQLiteIntegerBuilderInitial<string> | pg$1.SQLiteNumericBuilderInitial<string> | pg$1.SQLiteTextBuilderInitial<string, [string, ...string[]], number | undefined> | drizzle_orm0.$Type<pg$1.SQLiteCustomColumnBuilder<{
|
|
1817
|
-
name: string;
|
|
1818
|
-
dataType: "custom";
|
|
1819
|
-
columnType: "SQLiteCustomColumn";
|
|
1820
|
-
data: string;
|
|
1821
|
-
driverParam: string;
|
|
1822
|
-
enumValues: undefined;
|
|
1823
|
-
}>, string> | pg$1.SQLiteCustomColumnBuilder<{
|
|
1824
|
-
name: string;
|
|
1825
|
-
dataType: "custom";
|
|
1826
|
-
columnType: "SQLiteCustomColumn";
|
|
1827
|
-
data: string;
|
|
1828
|
-
driverParam: number;
|
|
1829
|
-
enumValues: undefined;
|
|
1830
|
-
}> | pg$1.SQLiteCustomColumnBuilder<{
|
|
1831
|
-
name: string;
|
|
1832
|
-
dataType: "custom";
|
|
1833
|
-
columnType: "SQLiteCustomColumn";
|
|
1834
|
-
data: boolean;
|
|
1835
|
-
driverParam: number;
|
|
1836
|
-
enumValues: undefined;
|
|
1837
|
-
}> | drizzle_orm0.$Type<pg$1.SQLiteCustomColumnBuilder<{
|
|
1838
|
-
name: string;
|
|
1839
|
-
dataType: "custom";
|
|
1840
|
-
columnType: "SQLiteCustomColumn";
|
|
1841
|
-
data: {
|
|
1842
|
-
[x: string]: unknown;
|
|
1843
|
-
[x: number]: unknown;
|
|
1844
|
-
[x: symbol]: unknown;
|
|
1845
|
-
};
|
|
1846
|
-
driverParam: string;
|
|
1847
|
-
enumValues: undefined;
|
|
1848
|
-
}>, {
|
|
1849
|
-
[x: string]: unknown;
|
|
1850
|
-
[x: number]: unknown;
|
|
1851
|
-
[x: symbol]: unknown;
|
|
1852
|
-
}> | drizzle_orm0.$Type<pg$1.SQLiteCustomColumnBuilder<{
|
|
1853
|
-
name: string;
|
|
1854
|
-
dataType: "custom";
|
|
1855
|
-
columnType: "SQLiteCustomColumn";
|
|
1856
|
-
data: Record<string, unknown>;
|
|
1857
|
-
driverParam: string;
|
|
1858
|
-
enumValues: undefined;
|
|
1859
|
-
}>, Record<string, unknown>> | drizzle_orm0.$Type<pg$1.SQLiteCustomColumnBuilder<{
|
|
1860
|
-
name: string;
|
|
1861
|
-
dataType: "custom";
|
|
1862
|
-
columnType: "SQLiteCustomColumn";
|
|
1863
|
-
data: any;
|
|
1864
|
-
driverParam: string;
|
|
1865
|
-
enumValues: undefined;
|
|
1866
|
-
}>, any> | drizzle_orm0.$Type<pg$1.SQLiteCustomColumnBuilder<{
|
|
1867
|
-
name: string;
|
|
1868
|
-
dataType: "custom";
|
|
1869
|
-
columnType: "SQLiteCustomColumn";
|
|
1870
|
-
data: unknown[];
|
|
1871
|
-
driverParam: string;
|
|
1872
|
-
enumValues: undefined;
|
|
1873
|
-
}>, unknown[]>;
|
|
1874
|
-
mapStringToSqliteColumn: (key: string, value: TString) => pg$1.SQLiteTextBuilderInitial<string, [string, ...string[]], number | undefined> | drizzle_orm0.$Type<pg$1.SQLiteCustomColumnBuilder<{
|
|
1875
|
-
name: string;
|
|
1876
|
-
dataType: "custom";
|
|
1877
|
-
columnType: "SQLiteCustomColumn";
|
|
1878
|
-
data: string;
|
|
1879
|
-
driverParam: string;
|
|
1880
|
-
enumValues: undefined;
|
|
1881
|
-
}>, string> | pg$1.SQLiteCustomColumnBuilder<{
|
|
1882
|
-
name: string;
|
|
1883
|
-
dataType: "custom";
|
|
1884
|
-
columnType: "SQLiteCustomColumn";
|
|
1885
|
-
data: string;
|
|
1886
|
-
driverParam: number;
|
|
1887
|
-
enumValues: undefined;
|
|
1888
|
-
}>;
|
|
1889
|
-
sqliteJson: <TDocument extends TSchema>(name: string, document: TDocument) => drizzle_orm0.$Type<pg$1.SQLiteCustomColumnBuilder<{
|
|
1890
|
-
name: string;
|
|
1891
|
-
dataType: "custom";
|
|
1892
|
-
columnType: "SQLiteCustomColumn";
|
|
1893
|
-
data: typebox1.StaticType<[], "Decode", {}, {}, TDocument>;
|
|
1894
|
-
driverParam: string;
|
|
1895
|
-
enumValues: undefined;
|
|
1896
|
-
}>, typebox1.StaticType<[], "Decode", {}, {}, TDocument>>;
|
|
1897
|
-
sqliteDateTime: {
|
|
1898
|
-
<TConfig extends Record<string, any>>(fieldConfig: TConfig): pg$1.SQLiteCustomColumnBuilder<{
|
|
1899
|
-
name: "";
|
|
1900
|
-
dataType: "custom";
|
|
1901
|
-
columnType: "SQLiteCustomColumn";
|
|
1902
|
-
data: string;
|
|
1903
|
-
driverParam: number;
|
|
1904
|
-
enumValues: undefined;
|
|
1905
|
-
}>;
|
|
1906
|
-
<TName extends string>(dbName: TName, fieldConfig: unknown): pg$1.SQLiteCustomColumnBuilder<{
|
|
1907
|
-
name: TName;
|
|
1908
|
-
dataType: "custom";
|
|
1909
|
-
columnType: "SQLiteCustomColumn";
|
|
1910
|
-
data: string;
|
|
1911
|
-
driverParam: number;
|
|
1912
|
-
enumValues: undefined;
|
|
1913
|
-
}>;
|
|
1914
|
-
};
|
|
1915
|
-
sqliteBool: {
|
|
1916
|
-
<TConfig extends Record<string, any>>(fieldConfig: TConfig): pg$1.SQLiteCustomColumnBuilder<{
|
|
1917
|
-
name: "";
|
|
1918
|
-
dataType: "custom";
|
|
1919
|
-
columnType: "SQLiteCustomColumn";
|
|
1920
|
-
data: boolean;
|
|
1921
|
-
driverParam: number;
|
|
1922
|
-
enumValues: undefined;
|
|
1923
|
-
}>;
|
|
1924
|
-
<TName extends string>(dbName: TName, fieldConfig: unknown): pg$1.SQLiteCustomColumnBuilder<{
|
|
1925
|
-
name: TName;
|
|
1926
|
-
dataType: "custom";
|
|
1927
|
-
columnType: "SQLiteCustomColumn";
|
|
1928
|
-
data: boolean;
|
|
1929
|
-
driverParam: number;
|
|
1930
|
-
enumValues: undefined;
|
|
1931
|
-
}>;
|
|
1932
|
-
};
|
|
1933
|
-
sqliteDate: {
|
|
1934
|
-
<TConfig extends Record<string, any>>(fieldConfig: TConfig): pg$1.SQLiteCustomColumnBuilder<{
|
|
1935
|
-
name: "";
|
|
1936
|
-
dataType: "custom";
|
|
1937
|
-
columnType: "SQLiteCustomColumn";
|
|
1938
|
-
data: string;
|
|
1939
|
-
driverParam: number;
|
|
1940
|
-
enumValues: undefined;
|
|
1941
|
-
}>;
|
|
1942
|
-
<TName extends string>(dbName: TName, fieldConfig: unknown): pg$1.SQLiteCustomColumnBuilder<{
|
|
1943
|
-
name: TName;
|
|
1944
|
-
dataType: "custom";
|
|
1945
|
-
columnType: "SQLiteCustomColumn";
|
|
1946
|
-
data: string;
|
|
1947
|
-
driverParam: number;
|
|
1948
|
-
enumValues: undefined;
|
|
1949
|
-
}>;
|
|
1950
|
-
};
|
|
1951
|
-
}
|
|
1952
|
-
type SchemaToSqliteBuilder<T extends TObject> = { [key in keyof T["properties"]]: SQLiteColumnBuilderBase };
|
|
1953
|
-
//#endregion
|
|
1954
|
-
//#region src/orm/providers/drivers/NodeSqliteProvider.d.ts
|
|
1955
|
-
/**
|
|
1956
|
-
* Configuration options for the Node.js SQLite database provider.
|
|
1957
|
-
*/
|
|
1958
|
-
declare const nodeSqliteOptions: alepha1.Atom<alepha1.TObject<{
|
|
1959
|
-
path: alepha1.TOptional<alepha1.TString>;
|
|
1960
|
-
}>, "alepha.postgres.node-sqlite.options">;
|
|
1961
|
-
type NodeSqliteProviderOptions = Static<typeof nodeSqliteOptions.schema>;
|
|
1962
|
-
declare module "alepha" {
|
|
1963
|
-
interface State {
|
|
1964
|
-
[nodeSqliteOptions.key]: NodeSqliteProviderOptions;
|
|
1965
|
-
}
|
|
1966
|
-
}
|
|
1967
|
-
/**
|
|
1968
|
-
* Add a fake support for SQLite in Node.js based on Postgres interfaces.
|
|
1969
|
-
*
|
|
1970
|
-
* This is NOT a real SQLite provider, it's a workaround to use SQLite with Drizzle ORM.
|
|
1971
|
-
* This is NOT recommended for production use.
|
|
1972
|
-
*/
|
|
1973
|
-
declare class NodeSqliteProvider extends DatabaseProvider {
|
|
1974
|
-
protected readonly kit: DrizzleKitProvider;
|
|
1975
|
-
protected readonly log: alepha_logger0.Logger;
|
|
1976
|
-
protected readonly env: {
|
|
1977
|
-
DATABASE_URL?: string | undefined;
|
|
1978
|
-
};
|
|
1979
|
-
protected readonly builder: SqliteModelBuilder;
|
|
1980
|
-
protected readonly options: Readonly<{
|
|
1981
|
-
path?: string | undefined;
|
|
1982
|
-
}>;
|
|
1983
|
-
protected sqlite: DatabaseSync;
|
|
1984
|
-
get name(): string;
|
|
1985
|
-
readonly dialect = "sqlite";
|
|
1986
|
-
get url(): string;
|
|
1987
|
-
execute(query: SQLLike): Promise<Array<Record<string, unknown>>>;
|
|
1988
|
-
readonly db: PgDatabase<any>;
|
|
1989
|
-
protected readonly onStart: alepha1.HookDescriptor<"start">;
|
|
1990
|
-
protected executeMigrations(migrationsFolder: string): Promise<void>;
|
|
1991
|
-
}
|
|
1992
|
-
//#endregion
|
|
1993
|
-
//#region src/orm/providers/PostgresTypeProvider.d.ts
|
|
1994
|
-
declare class PostgresTypeProvider {
|
|
1995
|
-
readonly attr: <T extends TSchema, Attr extends PgSymbolKeys>(type: T, attr: Attr, value?: PgSymbols[Attr]) => PgAttr<T, Attr>;
|
|
1996
|
-
/**
|
|
1997
|
-
* Creates a primary key with an identity column.
|
|
1998
|
-
*/
|
|
1999
|
-
readonly identityPrimaryKey: (identity?: PgIdentityOptions, options?: TNumberOptions) => PgAttr<PgAttr<PgAttr<TInteger, typeof PG_PRIMARY_KEY>, typeof PG_IDENTITY>, typeof PG_DEFAULT>;
|
|
2000
|
-
/**
|
|
2001
|
-
* Creates a primary key with a big identity column. (default)
|
|
2002
|
-
*/
|
|
2003
|
-
readonly bigIdentityPrimaryKey: (identity?: PgIdentityOptions, options?: TNumberOptions) => PgAttr<PgAttr<PgAttr<TNumber, typeof PG_PRIMARY_KEY>, typeof PG_IDENTITY>, typeof PG_DEFAULT>;
|
|
2004
|
-
/**
|
|
2005
|
-
* Creates a primary key with a UUID column.
|
|
2006
|
-
*/
|
|
2007
|
-
readonly uuidPrimaryKey: () => PgAttr<PgAttr<TString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
|
|
2008
|
-
/**
|
|
2009
|
-
* Creates a primary key for a given type. Supports:
|
|
2010
|
-
* - `t.integer()` -> PG INT (default)
|
|
2011
|
-
* - `t.bigint()` -> PG BIGINT
|
|
2012
|
-
* - `t.uuid()` -> PG UUID
|
|
2013
|
-
*/
|
|
2014
|
-
primaryKey(): PgAttr<PgAttr<TInteger, PgPrimaryKey>, PgDefault>;
|
|
2015
|
-
primaryKey(type: TString, options?: TStringOptions): PgAttr<PgAttr<TString, PgPrimaryKey>, PgDefault>;
|
|
2016
|
-
primaryKey(type: TInteger, options?: TNumberOptions, identity?: PgIdentityOptions): PgAttr<PgAttr<TInteger, PgPrimaryKey>, PgDefault>;
|
|
2017
|
-
primaryKey(type: TNumber, options?: TNumberOptions, identity?: PgIdentityOptions): PgAttr<PgAttr<TNumber, PgPrimaryKey>, PgDefault>;
|
|
2018
|
-
primaryKey(type: TBigInt, options?: TNumberOptions, identity?: PgIdentityOptions): PgAttr<PgAttr<TBigInt, PgPrimaryKey>, PgDefault>;
|
|
2019
|
-
/**
|
|
2020
|
-
* Wrap a schema with "default" attribute.
|
|
2021
|
-
* This is used to set a default value for a column in the database.
|
|
2022
|
-
*/
|
|
2023
|
-
readonly default: <T extends TSchema>(type: T, value?: Static<T>) => PgAttr<T, PgDefault>;
|
|
2024
|
-
/**
|
|
2025
|
-
* Creates a column 'version'.
|
|
2026
|
-
*
|
|
2027
|
-
* This is used to track the version of a row in the database.
|
|
2028
|
-
*
|
|
2029
|
-
* You can use it for optimistic concurrency control (OCC) with {@link RepositoryDescriptor#save}.
|
|
2030
|
-
*
|
|
2031
|
-
* @see {@link RepositoryDescriptor#save}
|
|
2032
|
-
* @see {@link PgVersionMismatchError}
|
|
2033
|
-
*/
|
|
2034
|
-
readonly version: (options?: TNumberOptions) => PgAttr<PgAttr<TInteger, typeof PG_VERSION>, typeof PG_DEFAULT>;
|
|
2035
|
-
/**
|
|
2036
|
-
* Creates a column Created At. So just a datetime column with a default value of the current timestamp.
|
|
2037
|
-
*/
|
|
2038
|
-
readonly createdAt: (options?: TStringOptions) => PgAttr<PgAttr<TString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
|
|
2039
|
-
/**
|
|
2040
|
-
* Creates a column Updated At. Like createdAt, but it is updated on every update of the row.
|
|
2041
|
-
*/
|
|
2042
|
-
readonly updatedAt: (options?: TStringOptions) => PgAttr<PgAttr<TString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
|
|
2043
|
-
/**
|
|
2044
|
-
* Creates a column Deleted At for soft delete functionality.
|
|
2045
|
-
* This is used to mark rows as deleted without actually removing them from the database.
|
|
2046
|
-
* The column is nullable - NULL means not deleted, timestamp means deleted.
|
|
2047
|
-
*/
|
|
2048
|
-
readonly deletedAt: (options?: TStringOptions) => PgAttr<alepha1.TOptional<TString>, typeof PG_DELETED_AT>;
|
|
2049
|
-
/**
|
|
2050
|
-
* Creates a Postgres ENUM type.
|
|
2051
|
-
*
|
|
2052
|
-
* > By default, `t.enum()` is mapped to a TEXT column in Postgres.
|
|
2053
|
-
* > Using this method, you can create a real ENUM type in the database.
|
|
2054
|
-
*
|
|
2055
|
-
* @example
|
|
2056
|
-
* ```ts
|
|
2057
|
-
* const statusEnum = pg.enum(["pending", "active", "archived"], { name: "status_enum" });
|
|
2058
|
-
* ```
|
|
2059
|
-
*/
|
|
2060
|
-
readonly enum: <T extends string[]>(values: [...T], pgEnumOptions?: PgEnumOptions, typeOptions?: TStringOptions) => PgAttr<TUnsafe<T[number]>, typeof PG_ENUM>;
|
|
2061
|
-
/**
|
|
2062
|
-
* Creates a reference to another table or schema. Basically a foreign key.
|
|
2063
|
-
*/
|
|
2064
|
-
readonly ref: <T extends TSchema>(type: T, ref: () => any, actions?: {
|
|
2065
|
-
onUpdate?: UpdateDeleteAction$1;
|
|
2066
|
-
onDelete?: UpdateDeleteAction$1;
|
|
2067
|
-
}) => PgAttr<T, PgRef>;
|
|
2068
|
-
/**
|
|
2069
|
-
* Creates a page schema for a given object schema.
|
|
2070
|
-
* It's used by {@link RepositoryDescriptor#paginate} method.
|
|
2071
|
-
*/
|
|
2072
|
-
readonly page: <T extends TObject>(resource: T, options?: TObjectOptions) => TPage<T>;
|
|
2073
|
-
}
|
|
2074
|
-
declare const pg: PostgresTypeProvider;
|
|
2075
|
-
//#endregion
|
|
2076
|
-
//#region src/orm/providers/RepositoryProvider.d.ts
|
|
2077
|
-
declare class RepositoryProvider {
|
|
2078
|
-
protected readonly alepha: Alepha;
|
|
2079
|
-
protected readonly registry: Map<EntityDescriptor<any>, Service<Repository<any>>>;
|
|
2080
|
-
getRepositories(provider?: DatabaseProvider): Repository<TObject<alepha1.TProperties>>[];
|
|
2081
|
-
getRepository<T extends TObject>(entity: EntityDescriptor<T>): Repository<T>;
|
|
2082
|
-
createClassRepository<T extends TObject>(entity: EntityDescriptor<T>): Service<Repository<T>>;
|
|
2083
|
-
}
|
|
2084
|
-
//#endregion
|
|
2085
|
-
//#region src/orm/schemas/legacyIdSchema.d.ts
|
|
2086
|
-
/**
|
|
2087
|
-
* @deprecated Use `pg.primaryKey()` instead.
|
|
2088
|
-
*/
|
|
2089
|
-
declare const legacyIdSchema: PgAttr<PgAttr<PgAttr<alepha1.TInteger, typeof PG_PRIMARY_KEY>, typeof PG_SERIAL>, typeof PG_DEFAULT>;
|
|
2090
|
-
//#endregion
|
|
2091
|
-
//#region src/orm/types/schema.d.ts
|
|
2092
|
-
/**
|
|
2093
|
-
* Postgres schema type.
|
|
2094
|
-
*/
|
|
2095
|
-
declare const schema: <TDocument extends TSchema>(name: string, document: TDocument) => drizzle_orm0.$Type<drizzle_orm_pg_core0.PgCustomColumnBuilder<{
|
|
2096
|
-
name: string;
|
|
2097
|
-
dataType: "custom";
|
|
2098
|
-
columnType: "PgCustomColumn";
|
|
2099
|
-
data: typebox1.StaticType<[], "Decode", {}, {}, TDocument>;
|
|
2100
|
-
driverParam: string;
|
|
2101
|
-
enumValues: undefined;
|
|
2102
|
-
}>, typebox1.StaticType<[], "Decode", {}, {}, TDocument>>;
|
|
2103
|
-
//#endregion
|
|
2104
|
-
//#region src/orm/index.d.ts
|
|
2105
|
-
declare module "alepha" {
|
|
2106
|
-
interface Hooks {
|
|
2107
|
-
/**
|
|
2108
|
-
* Fires before creating an entity in the repository.
|
|
2109
|
-
*/
|
|
2110
|
-
"repository:create:before": {
|
|
2111
|
-
tableName: string;
|
|
2112
|
-
data: any;
|
|
2113
|
-
};
|
|
2114
|
-
/**
|
|
2115
|
-
* Fires after creating an entity in the repository.
|
|
2116
|
-
*/
|
|
2117
|
-
"repository:create:after": {
|
|
2118
|
-
tableName: string;
|
|
2119
|
-
data: any;
|
|
2120
|
-
entity: any;
|
|
2121
|
-
};
|
|
2122
|
-
/**
|
|
2123
|
-
* Fires before updating entities in the repository.
|
|
2124
|
-
*/
|
|
2125
|
-
"repository:update:before": {
|
|
2126
|
-
tableName: string;
|
|
2127
|
-
where: any;
|
|
2128
|
-
data: any;
|
|
2129
|
-
};
|
|
2130
|
-
/**
|
|
2131
|
-
* Fires after updating entities in the repository.
|
|
2132
|
-
*/
|
|
2133
|
-
"repository:update:after": {
|
|
2134
|
-
tableName: string;
|
|
2135
|
-
where: any;
|
|
2136
|
-
data: any;
|
|
2137
|
-
entities: any[];
|
|
2138
|
-
};
|
|
2139
|
-
/**
|
|
2140
|
-
* Fires before deleting entities from the repository.
|
|
2141
|
-
*/
|
|
2142
|
-
"repository:delete:before": {
|
|
2143
|
-
tableName: string;
|
|
2144
|
-
where: any;
|
|
2145
|
-
};
|
|
2146
|
-
/**
|
|
2147
|
-
* Fires after deleting entities from the repository.
|
|
2148
|
-
*/
|
|
2149
|
-
"repository:delete:after": {
|
|
2150
|
-
tableName: string;
|
|
2151
|
-
where: any;
|
|
2152
|
-
ids: Array<string | number>;
|
|
2153
|
-
};
|
|
2154
|
-
/**
|
|
2155
|
-
* Fires before reading entities from the repository.
|
|
2156
|
-
*/
|
|
2157
|
-
"repository:read:before": {
|
|
2158
|
-
tableName: string;
|
|
2159
|
-
query: any;
|
|
2160
|
-
};
|
|
2161
|
-
/**
|
|
2162
|
-
* Fires after reading entities from the repository.
|
|
2163
|
-
*/
|
|
2164
|
-
"repository:read:after": {
|
|
2165
|
-
tableName: string;
|
|
2166
|
-
query: any;
|
|
2167
|
-
entities: any[];
|
|
2168
|
-
};
|
|
2169
|
-
}
|
|
2170
|
-
}
|
|
2171
|
-
/**
|
|
2172
|
-
* Postgres client based on Drizzle ORM, Alepha type-safe friendly.
|
|
2173
|
-
*
|
|
2174
|
-
* ```ts
|
|
2175
|
-
* const users = $entity({
|
|
2176
|
-
* name: "users",
|
|
2177
|
-
* schema: t.object({
|
|
2178
|
-
* id: pg.primaryKey(),
|
|
2179
|
-
* name: t.text(),
|
|
2180
|
-
* email: t.text(),
|
|
2181
|
-
* }),
|
|
2182
|
-
* });
|
|
2183
|
-
*
|
|
2184
|
-
* class Db {
|
|
2185
|
-
* users = $repository(users);
|
|
2186
|
-
* }
|
|
2187
|
-
*
|
|
2188
|
-
* const db = alepha.inject(Db);
|
|
2189
|
-
* const user = await db.users.one({ name: { eq: "John Doe" } });
|
|
2190
|
-
* ```
|
|
2191
|
-
*
|
|
2192
|
-
* This is not a full ORM, but rather a set of tools to work with Postgres databases in a type-safe way.
|
|
2193
|
-
*
|
|
2194
|
-
* It provides:
|
|
2195
|
-
* - A type-safe way to define entities and repositories. (via `$entity` and `$repository`)
|
|
2196
|
-
* - Custom query builders and filters.
|
|
2197
|
-
* - Built-in special columns like `createdAt`, `updatedAt`, `deletedAt`, `version`.
|
|
2198
|
-
* - Automatic JSONB support.
|
|
2199
|
-
* - Automatic synchronization of entities with the database schema (for testing and development).
|
|
2200
|
-
* - Fallback to raw SQL via Drizzle ORM `sql` function.
|
|
2201
|
-
*
|
|
2202
|
-
* Migrations are supported via Drizzle ORM, you need to use the `drizzle-kit` CLI tool to generate and run migrations.
|
|
2203
|
-
*
|
|
2204
|
-
* @see {@link $entity}
|
|
2205
|
-
* @see {@link $sequence}
|
|
2206
|
-
* @see {@link $repository}
|
|
2207
|
-
* @see {@link $transaction}
|
|
2208
|
-
* @module alepha.postgres
|
|
2209
|
-
*/
|
|
2210
|
-
declare const AlephaPostgres: alepha1.Service<alepha1.Module>;
|
|
2211
|
-
//#endregion
|
|
2212
|
-
export { $entity, $repository, $sequence, $transaction, AlephaPostgres, DatabaseProvider, DbConflictError, DbEntityNotFoundError, DbError, DbMigrationError, DbVersionMismatchError, DrizzleKitProvider, EntityColumn, EntityColumns, EntityDescriptor, EntityDescriptorOptions, FilterOperators, FromSchema, NodePostgresProvider, NodeSqliteProvider, NodeSqliteProviderOptions, OrderBy, OrderByClause, OrderDirection, PG_CREATED_AT, PG_DEFAULT, PG_DELETED_AT, PG_ENUM, PG_IDENTITY, PG_PRIMARY_KEY, PG_REF, PG_SERIAL, PG_UPDATED_AT, PG_VERSION, type Page, type PageQuery, PgAttr, PgAttrField, PgDefault, PgEnumOptions, PgIdentityOptions, PgPrimaryKey, PgQuery, PgQueryRelations, PgQueryWhere, PgQueryWhereOrSQL, PgRef, PgRefOptions, PgRelation, PgRelationMap, PgStatic, PgSymbolKeys, PgSymbols, PostgresTypeProvider, Repository, RepositoryProvider, SQLLike, SchemaToTableConfig, SequenceDescriptor, SequenceDescriptorOptions, StatementOptions, TObjectInsert, TObjectUpdate, TransactionContext, TransactionDescriptorOptions, buildQueryString, drizzle_orm0 as drizzle, getAttrFields, insertSchema, legacyIdSchema, nodeSqliteOptions, pageQuerySchema, pageSchema, parseQueryString, pg, pgAttr, schema, sql, updateSchema };
|
|
2213
|
-
//# sourceMappingURL=index.d.cts.map
|