@elysiumjs/mnemosyne-drizzle 0.1.3 → 0.1.4
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/.turbo/turbo-build.log +9 -0
- package/.turbo/turbo-typecheck.log +1 -0
- package/coverage/.lcov.info.01ffde0d9f956dce.tmp +14 -0
- package/coverage/.lcov.info.2f80a4def3a82099.tmp +343 -0
- package/coverage/.lcov.info.560a2daaba0934cd.tmp +366 -0
- package/coverage/.lcov.info.7162c9b788dc0bc6.tmp +366 -0
- package/coverage/.lcov.info.b57c0b452c3901e5.tmp +17 -0
- package/coverage/.lcov.info.c47de8626f331696.tmp +17 -0
- package/coverage/.lcov.info.c710a42b25b08349.tmp +343 -0
- package/coverage/.lcov.info.dbc8f065467fc8a2.tmp +287 -0
- package/coverage/.lcov.info.de180a43301f82c0.tmp +35 -0
- package/coverage/.lcov.info.df18163ab929ab1b.tmp +357 -0
- package/coverage/.lcov.info.febf711c192f5c0c.tmp +17 -0
- package/coverage/lcov.info +357 -0
- package/dist/database.d.ts +71 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +2 -0
- package/dist/model.d.ts +61 -0
- package/dist/repository.d.ts +35 -0
- package/dist/table.d.ts +145 -0
- package/dist/tenancy.d.ts +88 -0
- package/package.json +5 -5
- package/src/index.ts +8 -0
- package/bunfig.toml +0 -11
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
TN:
|
|
2
|
+
SF:../core/dist/index.js
|
|
3
|
+
FNF:225
|
|
4
|
+
FNH:28
|
|
5
|
+
DA:1,0
|
|
6
|
+
DA:2,0
|
|
7
|
+
DA:3,0
|
|
8
|
+
DA:4,0
|
|
9
|
+
DA:5,0
|
|
10
|
+
DA:6,0
|
|
11
|
+
DA:7,0
|
|
12
|
+
DA:8,0
|
|
13
|
+
DA:9,0
|
|
14
|
+
DA:10,0
|
|
15
|
+
DA:11,0
|
|
16
|
+
DA:12,0
|
|
17
|
+
DA:13,0
|
|
18
|
+
DA:14,0
|
|
19
|
+
DA:15,0
|
|
20
|
+
DA:16,0
|
|
21
|
+
DA:17,0
|
|
22
|
+
DA:18,0
|
|
23
|
+
DA:19,1221
|
|
24
|
+
LF:19
|
|
25
|
+
LH:1
|
|
26
|
+
end_of_record
|
|
27
|
+
TN:
|
|
28
|
+
SF:src/database.ts
|
|
29
|
+
FNF:9
|
|
30
|
+
FNH:1
|
|
31
|
+
DA:20,130
|
|
32
|
+
DA:21,108
|
|
33
|
+
DA:22,92
|
|
34
|
+
DA:23,126
|
|
35
|
+
DA:63,114
|
|
36
|
+
DA:64,18
|
|
37
|
+
DA:65,47
|
|
38
|
+
DA:67,0
|
|
39
|
+
DA:68,0
|
|
40
|
+
DA:69,0
|
|
41
|
+
DA:70,0
|
|
42
|
+
DA:71,0
|
|
43
|
+
DA:72,0
|
|
44
|
+
DA:73,75
|
|
45
|
+
DA:76,0
|
|
46
|
+
DA:77,0
|
|
47
|
+
DA:78,0
|
|
48
|
+
DA:79,0
|
|
49
|
+
DA:80,0
|
|
50
|
+
DA:81,0
|
|
51
|
+
DA:82,0
|
|
52
|
+
DA:83,0
|
|
53
|
+
DA:84,0
|
|
54
|
+
DA:85,0
|
|
55
|
+
DA:86,0
|
|
56
|
+
DA:87,0
|
|
57
|
+
DA:88,0
|
|
58
|
+
DA:89,0
|
|
59
|
+
DA:90,0
|
|
60
|
+
DA:91,0
|
|
61
|
+
DA:92,0
|
|
62
|
+
DA:93,0
|
|
63
|
+
DA:94,0
|
|
64
|
+
DA:95,0
|
|
65
|
+
DA:96,0
|
|
66
|
+
DA:97,0
|
|
67
|
+
DA:98,0
|
|
68
|
+
DA:99,0
|
|
69
|
+
DA:100,0
|
|
70
|
+
DA:101,0
|
|
71
|
+
DA:102,0
|
|
72
|
+
DA:103,0
|
|
73
|
+
DA:104,0
|
|
74
|
+
DA:105,0
|
|
75
|
+
DA:106,0
|
|
76
|
+
DA:107,0
|
|
77
|
+
DA:108,0
|
|
78
|
+
DA:109,0
|
|
79
|
+
DA:110,0
|
|
80
|
+
DA:111,0
|
|
81
|
+
DA:112,0
|
|
82
|
+
DA:113,0
|
|
83
|
+
DA:114,0
|
|
84
|
+
DA:115,0
|
|
85
|
+
DA:116,0
|
|
86
|
+
DA:117,0
|
|
87
|
+
DA:118,0
|
|
88
|
+
DA:119,0
|
|
89
|
+
DA:120,0
|
|
90
|
+
DA:121,0
|
|
91
|
+
DA:122,0
|
|
92
|
+
DA:123,0
|
|
93
|
+
DA:124,0
|
|
94
|
+
DA:125,0
|
|
95
|
+
DA:126,0
|
|
96
|
+
DA:127,6
|
|
97
|
+
DA:129,2
|
|
98
|
+
DA:143,98
|
|
99
|
+
DA:144,27
|
|
100
|
+
DA:145,48
|
|
101
|
+
DA:146,28
|
|
102
|
+
DA:147,57
|
|
103
|
+
DA:148,21
|
|
104
|
+
DA:149,24
|
|
105
|
+
DA:150,27
|
|
106
|
+
DA:151,33
|
|
107
|
+
DA:152,25
|
|
108
|
+
DA:153,23
|
|
109
|
+
DA:154,18
|
|
110
|
+
DA:155,20
|
|
111
|
+
DA:156,4
|
|
112
|
+
DA:157,22
|
|
113
|
+
DA:158,87
|
|
114
|
+
DA:161,0
|
|
115
|
+
DA:162,66
|
|
116
|
+
DA:165,0
|
|
117
|
+
DA:166,35
|
|
118
|
+
DA:168,6
|
|
119
|
+
DA:169,2
|
|
120
|
+
DA:175,87
|
|
121
|
+
LF:90
|
|
122
|
+
LH:31
|
|
123
|
+
end_of_record
|
|
124
|
+
TN:
|
|
125
|
+
SF:src/model.ts
|
|
126
|
+
FNF:8
|
|
127
|
+
FNH:7
|
|
128
|
+
DA:18,76
|
|
129
|
+
DA:19,53
|
|
130
|
+
DA:21,43
|
|
131
|
+
DA:22,45
|
|
132
|
+
DA:33,37
|
|
133
|
+
DA:34,50
|
|
134
|
+
DA:35,31
|
|
135
|
+
DA:36,15
|
|
136
|
+
DA:37,20
|
|
137
|
+
DA:38,15
|
|
138
|
+
DA:39,20
|
|
139
|
+
DA:40,16
|
|
140
|
+
DA:41,16
|
|
141
|
+
DA:42,0
|
|
142
|
+
DA:43,0
|
|
143
|
+
DA:44,0
|
|
144
|
+
DA:45,0
|
|
145
|
+
DA:46,0
|
|
146
|
+
DA:47,0
|
|
147
|
+
DA:48,0
|
|
148
|
+
DA:49,0
|
|
149
|
+
DA:50,0
|
|
150
|
+
DA:51,0
|
|
151
|
+
DA:53,2
|
|
152
|
+
DA:69,31
|
|
153
|
+
DA:70,13
|
|
154
|
+
DA:71,35
|
|
155
|
+
DA:74,13
|
|
156
|
+
DA:75,41
|
|
157
|
+
DA:76,42
|
|
158
|
+
DA:77,21
|
|
159
|
+
DA:78,40
|
|
160
|
+
DA:79,29
|
|
161
|
+
DA:80,33
|
|
162
|
+
DA:81,14
|
|
163
|
+
DA:82,43
|
|
164
|
+
DA:83,4
|
|
165
|
+
DA:86,21
|
|
166
|
+
DA:87,45
|
|
167
|
+
DA:88,21
|
|
168
|
+
DA:89,16
|
|
169
|
+
DA:90,112
|
|
170
|
+
DA:92,1
|
|
171
|
+
DA:93,4
|
|
172
|
+
DA:94,41
|
|
173
|
+
DA:95,55
|
|
174
|
+
DA:97,2
|
|
175
|
+
DA:114,38
|
|
176
|
+
DA:115,7
|
|
177
|
+
DA:116,9
|
|
178
|
+
DA:117,3
|
|
179
|
+
DA:118,70
|
|
180
|
+
DA:148,27
|
|
181
|
+
DA:149,7
|
|
182
|
+
DA:150,12
|
|
183
|
+
DA:151,3
|
|
184
|
+
DA:152,39
|
|
185
|
+
DA:153,43
|
|
186
|
+
DA:158,81
|
|
187
|
+
DA:161,47
|
|
188
|
+
DA:162,47
|
|
189
|
+
DA:163,2
|
|
190
|
+
DA:165,12
|
|
191
|
+
LF:63
|
|
192
|
+
LH:53
|
|
193
|
+
end_of_record
|
|
194
|
+
TN:
|
|
195
|
+
SF:src/table.ts
|
|
196
|
+
FNF:2
|
|
197
|
+
FNH:2
|
|
198
|
+
DA:17,64
|
|
199
|
+
DA:30,34
|
|
200
|
+
DA:37,31
|
|
201
|
+
DA:38,10
|
|
202
|
+
DA:39,3
|
|
203
|
+
DA:40,33
|
|
204
|
+
DA:59,22
|
|
205
|
+
DA:63,11
|
|
206
|
+
DA:64,9
|
|
207
|
+
DA:65,16
|
|
208
|
+
DA:66,3
|
|
209
|
+
DA:67,64
|
|
210
|
+
DA:68,36
|
|
211
|
+
DA:69,13
|
|
212
|
+
LF:14
|
|
213
|
+
LH:14
|
|
214
|
+
end_of_record
|
|
215
|
+
TN:
|
|
216
|
+
SF:src/tenancy.ts
|
|
217
|
+
FNF:14
|
|
218
|
+
FNH:10
|
|
219
|
+
DA:19,112
|
|
220
|
+
DA:20,68
|
|
221
|
+
DA:21,164
|
|
222
|
+
DA:23,76
|
|
223
|
+
DA:24,86
|
|
224
|
+
DA:30,60
|
|
225
|
+
DA:31,62
|
|
226
|
+
DA:43,89
|
|
227
|
+
DA:44,136
|
|
228
|
+
DA:53,99
|
|
229
|
+
DA:54,73
|
|
230
|
+
DA:55,69
|
|
231
|
+
DA:56,5
|
|
232
|
+
DA:57,80
|
|
233
|
+
DA:58,86
|
|
234
|
+
DA:59,44
|
|
235
|
+
DA:74,63
|
|
236
|
+
DA:78,16
|
|
237
|
+
DA:79,22
|
|
238
|
+
DA:80,24
|
|
239
|
+
DA:81,6
|
|
240
|
+
DA:82,59
|
|
241
|
+
DA:83,71
|
|
242
|
+
DA:84,5
|
|
243
|
+
DA:86,98
|
|
244
|
+
DA:87,85
|
|
245
|
+
DA:88,81
|
|
246
|
+
DA:89,5
|
|
247
|
+
DA:91,94
|
|
248
|
+
DA:92,122
|
|
249
|
+
DA:93,96
|
|
250
|
+
DA:95,42
|
|
251
|
+
DA:110,0
|
|
252
|
+
DA:111,0
|
|
253
|
+
DA:112,0
|
|
254
|
+
DA:113,0
|
|
255
|
+
DA:114,0
|
|
256
|
+
DA:115,0
|
|
257
|
+
DA:116,0
|
|
258
|
+
DA:117,0
|
|
259
|
+
DA:118,0
|
|
260
|
+
DA:119,0
|
|
261
|
+
DA:120,0
|
|
262
|
+
DA:121,0
|
|
263
|
+
DA:122,0
|
|
264
|
+
DA:123,7
|
|
265
|
+
DA:132,0
|
|
266
|
+
DA:133,0
|
|
267
|
+
DA:134,0
|
|
268
|
+
DA:135,0
|
|
269
|
+
DA:136,0
|
|
270
|
+
DA:137,0
|
|
271
|
+
DA:138,0
|
|
272
|
+
DA:139,0
|
|
273
|
+
DA:140,0
|
|
274
|
+
DA:141,75
|
|
275
|
+
DA:150,0
|
|
276
|
+
DA:151,0
|
|
277
|
+
DA:152,0
|
|
278
|
+
DA:153,0
|
|
279
|
+
DA:154,0
|
|
280
|
+
DA:155,0
|
|
281
|
+
DA:156,0
|
|
282
|
+
DA:157,0
|
|
283
|
+
DA:158,46
|
|
284
|
+
DA:169,143
|
|
285
|
+
DA:170,72
|
|
286
|
+
DA:171,140
|
|
287
|
+
DA:172,144
|
|
288
|
+
DA:173,122
|
|
289
|
+
DA:175,54
|
|
290
|
+
DA:176,30
|
|
291
|
+
DA:177,34
|
|
292
|
+
DA:178,168
|
|
293
|
+
DA:179,170
|
|
294
|
+
DA:180,9
|
|
295
|
+
DA:195,57
|
|
296
|
+
DA:196,35
|
|
297
|
+
DA:198,54
|
|
298
|
+
DA:199,90
|
|
299
|
+
DA:200,36
|
|
300
|
+
DA:201,16
|
|
301
|
+
DA:202,112
|
|
302
|
+
DA:204,6
|
|
303
|
+
DA:205,9
|
|
304
|
+
DA:206,82
|
|
305
|
+
DA:207,120
|
|
306
|
+
DA:210,16
|
|
307
|
+
DA:211,26
|
|
308
|
+
DA:212,18
|
|
309
|
+
DA:213,20
|
|
310
|
+
DA:214,10
|
|
311
|
+
DA:216,40
|
|
312
|
+
DA:218,2
|
|
313
|
+
DA:228,66
|
|
314
|
+
DA:229,29
|
|
315
|
+
DA:231,56
|
|
316
|
+
DA:233,36
|
|
317
|
+
DA:236,16
|
|
318
|
+
DA:237,24
|
|
319
|
+
DA:238,16
|
|
320
|
+
DA:239,20
|
|
321
|
+
DA:240,10
|
|
322
|
+
DA:241,76
|
|
323
|
+
DA:242,144
|
|
324
|
+
DA:244,94
|
|
325
|
+
DA:245,152
|
|
326
|
+
DA:246,41
|
|
327
|
+
DA:247,8
|
|
328
|
+
DA:249,2
|
|
329
|
+
LF:110
|
|
330
|
+
LH:80
|
|
331
|
+
end_of_record
|
|
332
|
+
TN:
|
|
333
|
+
SF:tests/setup.ts
|
|
334
|
+
FNF:3
|
|
335
|
+
FNH:1
|
|
336
|
+
DA:1,0
|
|
337
|
+
DA:2,0
|
|
338
|
+
DA:3,0
|
|
339
|
+
DA:4,0
|
|
340
|
+
DA:5,0
|
|
341
|
+
DA:6,30
|
|
342
|
+
DA:7,47
|
|
343
|
+
DA:8,19
|
|
344
|
+
DA:9,2
|
|
345
|
+
DA:10,2
|
|
346
|
+
LF:10
|
|
347
|
+
LH:5
|
|
348
|
+
end_of_record
|
|
349
|
+
TN:
|
|
350
|
+
SF:../mnemosyne/dist/index.js
|
|
351
|
+
FNF:52
|
|
352
|
+
FNH:12
|
|
353
|
+
DA:1,0
|
|
354
|
+
DA:2,3199
|
|
355
|
+
LF:2
|
|
356
|
+
LH:1
|
|
357
|
+
end_of_record
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { DatabaseCacheConfig, DatabaseDriver } from '@elysiumjs/mnemosyne';
|
|
2
|
+
import type { DrizzleConfig } from 'drizzle-orm';
|
|
3
|
+
import type { BunSQLDatabase } from 'drizzle-orm/bun-sql';
|
|
4
|
+
import type { CacheConfig } from 'drizzle-orm/cache/core/types';
|
|
5
|
+
import { AbstractDatabase } from '@elysiumjs/mnemosyne';
|
|
6
|
+
import { Table } from 'drizzle-orm';
|
|
7
|
+
import { Cache as DrizzleCache } from 'drizzle-orm/cache/core';
|
|
8
|
+
/**
|
|
9
|
+
* Connection configuration for Drizzle ORM.
|
|
10
|
+
*
|
|
11
|
+
* Extends `DrizzleConfig` with connection details and optional caching.
|
|
12
|
+
*
|
|
13
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
14
|
+
* @template TSchema The Drizzle schema type.
|
|
15
|
+
*/
|
|
16
|
+
export type DrizzleConnectionProps<TSchema extends Record<string, unknown> = Record<string, never>> = Omit<DrizzleConfig<TSchema>, 'cache'> & ({
|
|
17
|
+
connection: string | ({
|
|
18
|
+
url?: string;
|
|
19
|
+
} & Bun.SQLOptions);
|
|
20
|
+
} | {
|
|
21
|
+
client: Bun.SQL;
|
|
22
|
+
}) & {
|
|
23
|
+
cache?: true | DatabaseCacheConfig;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* A Drizzle database connection backed by Bun's SQL driver.
|
|
27
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
28
|
+
*/
|
|
29
|
+
export type DrizzleConnection = BunSQLDatabase<Record<string, never>> & {
|
|
30
|
+
$client: Bun.SQL;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Drizzle query cache backed by the framework's cache storage.
|
|
34
|
+
*
|
|
35
|
+
* Extends the Drizzle `Cache` base class and implements the
|
|
36
|
+
* framework's `DatabaseCacheStrategy` interface so that query
|
|
37
|
+
* results can be transparently cached and invalidated.
|
|
38
|
+
*
|
|
39
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
40
|
+
*/
|
|
41
|
+
export declare class DrizzleDatabaseCache extends DrizzleCache {
|
|
42
|
+
#private;
|
|
43
|
+
private readonly cacheStrategy;
|
|
44
|
+
private readonly globalTtl;
|
|
45
|
+
private usedTablesPerKey;
|
|
46
|
+
constructor(cacheStrategy?: 'explicit' | 'all', globalTtl?: number, storageEngine?: 'redis' | 'memory');
|
|
47
|
+
strategy(): 'explicit' | 'all';
|
|
48
|
+
get(key: string): Promise<any[] | undefined>;
|
|
49
|
+
put(key: string, response: any, tables: string[], _isTag: boolean, config?: CacheConfig): Promise<void>;
|
|
50
|
+
onMutate(params: {
|
|
51
|
+
tags?: string | string[];
|
|
52
|
+
tables?: string | string[] | Table<any> | Table<any>[];
|
|
53
|
+
}): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Drizzle-specific database manager.
|
|
57
|
+
*
|
|
58
|
+
* Implements the abstract database class with a driver that creates
|
|
59
|
+
* Drizzle connections using Bun's built-in SQL client.
|
|
60
|
+
*
|
|
61
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
62
|
+
*/
|
|
63
|
+
declare class DrizzleDatabase extends AbstractDatabase<DrizzleConnection, DrizzleConnectionProps> {
|
|
64
|
+
protected driver: DatabaseDriver<DrizzleConnection, DrizzleConnectionProps>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Singleton Drizzle database manager.
|
|
68
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
69
|
+
*/
|
|
70
|
+
export declare const Database: DrizzleDatabase;
|
|
71
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from 'drizzle-orm';
|
|
2
|
+
export * from 'drizzle-orm/pg-core';
|
|
3
|
+
export type { ColumnsWithTable, SelectedFields, SelectedFieldsFlat, SelectedFieldsOrdered, TableConfig } from 'drizzle-orm/pg-core';
|
|
4
|
+
export { pgTable, getTableBuilders } from './table';
|
|
5
|
+
export { Database, DrizzleDatabaseCache } from './database';
|
|
6
|
+
export type { DrizzleConnectionProps, DrizzleConnection } from './database';
|
|
7
|
+
export { DrizzleModel, createSchemaFromDrizzle, drizzleAdapter, type DrizzleModelOptions } from './model';
|
|
8
|
+
export { DrizzleRepository } from './repository';
|
|
9
|
+
export { DrizzleSchemaTenancy, DrizzleRLSTenancy, wrapTenantSchema, registerTenantSchema, getTenantSchema, withRLS, setConnectionTenant, getSessionTenant, createRLSPolicy } from './tenancy';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{Application as T,Event as d}from"@elysiumjs/core";import{registerTenancyStrategy as N}from"@elysiumjs/mnemosyne";import{AbstractDatabase as j,createDatabaseCacheStorage as w}from"@elysiumjs/mnemosyne";import{getTableName as $,is as B,Table as I}from"drizzle-orm";import{drizzle as L}from"drizzle-orm/bun-sql";import{Cache as P}from"drizzle-orm/cache/core";class X extends P{cacheStrategy;globalTtl;#F;usedTablesPerKey={};constructor(F="explicit",G=1,H="redis"){super();this.cacheStrategy=F;this.globalTtl=G;this.#F=w({storage:H})}strategy(){return this.cacheStrategy}async get(F){return await this.#F.get(F)??void 0}async put(F,G,H,J,K){await this.#F.set(F,G,(K?.ex??this.globalTtl)*1000);for(let M of H){let U=this.usedTablesPerKey[M];if(U===void 0)this.usedTablesPerKey[M]=[F];else U.push(F)}}async onMutate(F){let G=F.tags?Array.isArray(F.tags)?F.tags:[F.tags]:[],H=F.tables?Array.isArray(F.tables)?F.tables:[F.tables]:[],J=new Set;for(let K of H){let M=B(K,I)?$(K):K,U=this.usedTablesPerKey[M]??[];for(let E of U)J.add(E)}if(J.size>0||G.length>0){await this.#F.mdel(G),await this.#F.mdel([...J]);for(let K of H){let M=B(K,I)?$(K):K;this.usedTablesPerKey[M]=[]}}}}class O extends j{driver={createConnection(F){let G=F.cache===void 0?void 0:F.cache===!0?new X:F.cache.enabled!==!1?new X(F.cache.strategy,F.cache.ttl,F.cache.storage):void 0;return L({...F,cache:G})},withTransaction(F,G){return F.transaction((H)=>G(H))},getRawClient(F){return F.$client}}}var V=new O;import{getTenancyConfig as q}from"@elysiumjs/mnemosyne";import{sql as A}from"drizzle-orm";import{getTableConfig as v,pgPolicy as s,pgSchema as x,pgTable as C}from"drizzle-orm/pg-core";import{pgTable as g}from"drizzle-orm/pg-core";var R=new WeakMap,Q=(F)=>{return R.get(F)};var Y=new Map,W=new Map,S=(F)=>{return W.get(F)??k(F)},k=(F)=>{if(W.has(F))return W.get(F);let G=x(F);return W.set(F,G),G},D=(F,G,H)=>{if(F==="public")return C(G,H);let J=`${F}.${G}`;if(Y.has(J))return Y.get(J);let M=S(F).table(G,H);return Y.set(J,M),M};class Z{mode="schema";resolveTable(F,G){let H=Q(F);if(!H)throw Error("No column builders registered for table. Use pgTable() from '@elysiumjs/mnemosyne-drizzle' for tenant support.");let J=v(F);return D(G,J.name,H)}async withIsolation(F,G,H){return H()}}class _{mode="rls";resolveTable(F,G){return F}async withIsolation(F,G,H){let K=q().rls?.sessionVariable??"app.current_tenant";return F.transaction(async(M)=>{return await M.execute(A`SELECT set_config(${K}, ${G}, true)`),H()})}}export*from"drizzle-orm";export*from"drizzle-orm/pg-core";d.once("elysium:app:launched",()=>{let G=T.instance.getConfig("elysium:mnemosyne");if(G?.database){for(let[H,J]of Object.entries(G.database.connections))V.registerConnection(H,J);if(V.connectionExists(G.database.default))V.setDefaultConnection(G.database.default)}if(G?.tenancy){let H=G.tenancy.mode==="rls"?new _:new Z;N(H)}});export{QF as wrapTenantSchema,wF as withRLS,LF as setConnectionTenant,EF as registerTenantSchema,JF as pgTable,jF as getTenantSchema,KF as getTableBuilders,PF as getSessionTenant,ZF as drizzleAdapter,YF as createSchemaFromDrizzle,RF as createRLSPolicy,IF as DrizzleSchemaTenancy,$F as DrizzleRepository,OF as DrizzleRLSTenancy,XF as DrizzleModel,VF as DrizzleDatabaseCache,UF as Database};
|
package/dist/model.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ModelAdapter } from '@elysiumjs/mnemosyne';
|
|
2
|
+
import type { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
3
|
+
/**
|
|
4
|
+
* Drizzle-specific model adapter.
|
|
5
|
+
*
|
|
6
|
+
* Bridges Drizzle's `PgTableWithColumns` to the framework's
|
|
7
|
+
* normalized model metadata.
|
|
8
|
+
*
|
|
9
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
10
|
+
*/
|
|
11
|
+
export declare const drizzleAdapter: ModelAdapter<PgTableWithColumns<any>>;
|
|
12
|
+
/**
|
|
13
|
+
* Creates Elysia validation schemas from a Drizzle table.
|
|
14
|
+
*
|
|
15
|
+
* This is a convenience wrapper around `createSchemaFromModel` that
|
|
16
|
+
* automatically extracts column metadata via the `drizzleAdapter`.
|
|
17
|
+
*
|
|
18
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
19
|
+
* @param table The Drizzle table to generate schemas for.
|
|
20
|
+
* @param opts Schema generation options.
|
|
21
|
+
* @returns An Elysia validation schema.
|
|
22
|
+
*/
|
|
23
|
+
export declare const createSchemaFromDrizzle: (table: PgTableWithColumns<any>, opts?: {
|
|
24
|
+
mode?: "create" | "update" | "select";
|
|
25
|
+
}) => import("@sinclair/typebox").TObject<{}>;
|
|
26
|
+
/**
|
|
27
|
+
* Options for creating a DrizzleModel.
|
|
28
|
+
*/
|
|
29
|
+
export interface DrizzleModelOptions {
|
|
30
|
+
/**
|
|
31
|
+
* Enable tenant schema support for this model.
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
supportTenancy?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Creates a model class backed by a Drizzle pgTable.
|
|
38
|
+
*
|
|
39
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
40
|
+
* @param table The Drizzle table (created with enhanced pgTable).
|
|
41
|
+
* @param options Model configuration options.
|
|
42
|
+
* @returns A model class with Drizzle-backed static metadata.
|
|
43
|
+
*/
|
|
44
|
+
export declare const DrizzleModel: <TTable extends PgTableWithColumns<any>>(table: TTable, options?: DrizzleModelOptions) => {
|
|
45
|
+
new (): {};
|
|
46
|
+
readonly $inferSelect: unknown;
|
|
47
|
+
readonly $inferInsert: unknown;
|
|
48
|
+
readonly $inferUpdate: unknown;
|
|
49
|
+
readonly table: PgTableWithColumns<any>;
|
|
50
|
+
readonly tableName: string;
|
|
51
|
+
readonly columns: Record<string, import("drizzle-orm/pg-core").PgColumnBuilderBase<import("drizzle-orm").ColumnBuilderBaseConfig<import("drizzle-orm").ColumnDataType, string>, object>>;
|
|
52
|
+
readonly insertSchema: import("@sinclair/typebox").TObject<{}>;
|
|
53
|
+
readonly updateSchema: import("@sinclair/typebox").TObject<{}>;
|
|
54
|
+
readonly selectSchema: import("@sinclair/typebox").TObject<{}>;
|
|
55
|
+
readonly supportTenancy: boolean;
|
|
56
|
+
} & {
|
|
57
|
+
readonly $inferSelect: TTable["$inferSelect"];
|
|
58
|
+
readonly $inferInsert: TTable["$inferInsert"];
|
|
59
|
+
readonly $inferUpdate: Partial<TTable["$inferInsert"]>;
|
|
60
|
+
readonly table: TTable;
|
|
61
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { IdType, ModelClass } from '@elysiumjs/mnemosyne';
|
|
2
|
+
import type { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
3
|
+
import type { DrizzleConnection } from './database';
|
|
4
|
+
/**
|
|
5
|
+
* Drizzle-specific repository mixin with concrete CRUD operations.
|
|
6
|
+
*
|
|
7
|
+
* Extends the abstract repository with Drizzle query builder calls
|
|
8
|
+
* for all standard CRUD methods.
|
|
9
|
+
*
|
|
10
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
11
|
+
* @template TModel The model class type.
|
|
12
|
+
* @param model The model class to create the repository for.
|
|
13
|
+
* @returns A concrete repository class with CRUD methods.
|
|
14
|
+
*/
|
|
15
|
+
export declare const DrizzleRepository: <TModel extends ModelClass<any, any, any, PgTableWithColumns<any>>>(model: TModel) => {
|
|
16
|
+
new (): {
|
|
17
|
+
all(): Promise<TModel["$inferSelect"][]>;
|
|
18
|
+
paginate(count: number, page?: number): Promise<{
|
|
19
|
+
page: number;
|
|
20
|
+
data: TModel["$inferSelect"][];
|
|
21
|
+
total: number;
|
|
22
|
+
}>;
|
|
23
|
+
find(id: IdType): Promise<TModel["$inferSelect"] | null>;
|
|
24
|
+
findBy<TKey extends keyof TModel["$inferSelect"]>(column: TKey, value: TModel["$inferSelect"][TKey]): Promise<TModel["$inferSelect"] | null>;
|
|
25
|
+
insert(data: TModel["$inferInsert"]): Promise<TModel["$inferSelect"]>;
|
|
26
|
+
update(id: IdType, data: TModel["$inferUpdate"]): Promise<TModel["$inferSelect"]>;
|
|
27
|
+
updateAll(data: TModel["$inferUpdate"]): Promise<TModel["$inferSelect"][]>;
|
|
28
|
+
delete(id: IdType): Promise<TModel["$inferSelect"]>;
|
|
29
|
+
deleteAll(): Promise<TModel["$inferSelect"][]>;
|
|
30
|
+
exists(id: IdType): Promise<boolean>;
|
|
31
|
+
readonly db: DrizzleConnection;
|
|
32
|
+
};
|
|
33
|
+
readonly Model: TModel;
|
|
34
|
+
readonly connection: string;
|
|
35
|
+
};
|
package/dist/table.d.ts
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { PgColumnBuilderBase, PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves the original column builders for a table.
|
|
4
|
+
* @param table The table created with enhanced pgTable.
|
|
5
|
+
* @returns The original column builder definitions, or `undefined`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getTableBuilders: (table: PgTableWithColumns<any>) => Record<string, PgColumnBuilderBase> | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a PostgreSQL table with automatic column builder registration.
|
|
10
|
+
*
|
|
11
|
+
* This is an enhanced version of Drizzle's `pgTable` that automatically
|
|
12
|
+
* registers column builders for tenancy support. It has the exact same
|
|
13
|
+
* signature and behavior as the original.
|
|
14
|
+
*
|
|
15
|
+
* @param tableName The name of the database table.
|
|
16
|
+
* @param columns The column definitions.
|
|
17
|
+
* @param extraConfig Optional extra Drizzle table configuration.
|
|
18
|
+
* @returns A Drizzle PostgreSQL table with registered column builders.
|
|
19
|
+
*/
|
|
20
|
+
export declare const pgTable: <TTableName extends string, TColumns extends Record<string, PgColumnBuilderBase>>(tableName: TTableName, columns: TColumns, extraConfig?: (table: any) => any) => PgTableWithColumns<{
|
|
21
|
+
name: TTableName;
|
|
22
|
+
schema: undefined;
|
|
23
|
+
columns: { [Key in keyof TColumns]: import("drizzle-orm/pg-core").PgColumn<{
|
|
24
|
+
name: (Omit<TColumns[Key]["_"], "name"> & {
|
|
25
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
26
|
+
})["name"];
|
|
27
|
+
tableName: TTableName;
|
|
28
|
+
dataType: (Omit<TColumns[Key]["_"], "name"> & {
|
|
29
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
30
|
+
})["dataType"];
|
|
31
|
+
columnType: (Omit<TColumns[Key]["_"], "name"> & {
|
|
32
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
33
|
+
})["columnType"];
|
|
34
|
+
data: Omit<TColumns[Key]["_"], "name"> & {
|
|
35
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
36
|
+
} extends infer T ? T extends Omit<TColumns[Key]["_"], "name"> & {
|
|
37
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
38
|
+
} ? T extends {
|
|
39
|
+
$type: infer U;
|
|
40
|
+
} ? U : T["data"] : never : never;
|
|
41
|
+
driverParam: (Omit<TColumns[Key]["_"], "name"> & {
|
|
42
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
43
|
+
})["driverParam"];
|
|
44
|
+
notNull: Omit<TColumns[Key]["_"], "name"> & {
|
|
45
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
46
|
+
} extends infer T_1 ? T_1 extends Omit<TColumns[Key]["_"], "name"> & {
|
|
47
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
48
|
+
} ? T_1 extends {
|
|
49
|
+
notNull: true;
|
|
50
|
+
} ? true : false : never : never;
|
|
51
|
+
hasDefault: Omit<TColumns[Key]["_"], "name"> & {
|
|
52
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
53
|
+
} extends infer T_2 ? T_2 extends Omit<TColumns[Key]["_"], "name"> & {
|
|
54
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
55
|
+
} ? T_2 extends {
|
|
56
|
+
hasDefault: true;
|
|
57
|
+
} ? true : false : never : never;
|
|
58
|
+
isPrimaryKey: Omit<TColumns[Key]["_"], "name"> & {
|
|
59
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
60
|
+
} extends infer T_3 ? T_3 extends Omit<TColumns[Key]["_"], "name"> & {
|
|
61
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
62
|
+
} ? T_3 extends {
|
|
63
|
+
isPrimaryKey: true;
|
|
64
|
+
} ? true : false : never : never;
|
|
65
|
+
isAutoincrement: Omit<TColumns[Key]["_"], "name"> & {
|
|
66
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
67
|
+
} extends infer T_4 ? T_4 extends Omit<TColumns[Key]["_"], "name"> & {
|
|
68
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
69
|
+
} ? T_4 extends {
|
|
70
|
+
isAutoincrement: true;
|
|
71
|
+
} ? true : false : never : never;
|
|
72
|
+
hasRuntimeDefault: Omit<TColumns[Key]["_"], "name"> & {
|
|
73
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
74
|
+
} extends infer T_5 ? T_5 extends Omit<TColumns[Key]["_"], "name"> & {
|
|
75
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
76
|
+
} ? T_5 extends {
|
|
77
|
+
hasRuntimeDefault: true;
|
|
78
|
+
} ? true : false : never : never;
|
|
79
|
+
enumValues: (Omit<TColumns[Key]["_"], "name"> & {
|
|
80
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
81
|
+
})["enumValues"];
|
|
82
|
+
baseColumn: Omit<TColumns[Key]["_"], "name"> & {
|
|
83
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
84
|
+
} extends infer T_6 ? T_6 extends Omit<TColumns[Key]["_"], "name"> & {
|
|
85
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
86
|
+
} ? T_6 extends {
|
|
87
|
+
baseBuilder: infer U_1 extends import("drizzle-orm").ColumnBuilderBase;
|
|
88
|
+
} ? import("drizzle-orm").Column<{
|
|
89
|
+
name: U_1["_"]["name"];
|
|
90
|
+
tableName: TTableName;
|
|
91
|
+
dataType: U_1["_"]["dataType"];
|
|
92
|
+
columnType: U_1["_"]["columnType"];
|
|
93
|
+
data: U_1["_"] extends infer T_7 ? T_7 extends U_1["_"] ? T_7 extends {
|
|
94
|
+
$type: infer U;
|
|
95
|
+
} ? U : T_7["data"] : never : never;
|
|
96
|
+
driverParam: U_1["_"]["driverParam"];
|
|
97
|
+
notNull: U_1["_"] extends infer T_8 ? T_8 extends U_1["_"] ? T_8 extends {
|
|
98
|
+
notNull: true;
|
|
99
|
+
} ? true : false : never : never;
|
|
100
|
+
hasDefault: U_1["_"] extends infer T_9 ? T_9 extends U_1["_"] ? T_9 extends {
|
|
101
|
+
hasDefault: true;
|
|
102
|
+
} ? true : false : never : never;
|
|
103
|
+
isPrimaryKey: U_1["_"] extends infer T_10 ? T_10 extends U_1["_"] ? T_10 extends {
|
|
104
|
+
isPrimaryKey: true;
|
|
105
|
+
} ? true : false : never : never;
|
|
106
|
+
isAutoincrement: U_1["_"] extends infer T_11 ? T_11 extends U_1["_"] ? T_11 extends {
|
|
107
|
+
isAutoincrement: true;
|
|
108
|
+
} ? true : false : never : never;
|
|
109
|
+
hasRuntimeDefault: U_1["_"] extends infer T_12 ? T_12 extends U_1["_"] ? T_12 extends {
|
|
110
|
+
hasRuntimeDefault: true;
|
|
111
|
+
} ? true : false : never : never;
|
|
112
|
+
enumValues: U_1["_"]["enumValues"];
|
|
113
|
+
baseColumn: U_1["_"] extends infer T_13 ? T_13 extends U_1["_"] ? T_13 extends {
|
|
114
|
+
baseBuilder: infer U_1 extends import("drizzle-orm").ColumnBuilderBase;
|
|
115
|
+
} ? import("drizzle-orm").Column</*elided*/ any, {}, Omit<U_1["_"], "name" | "data" | "driverParam" | "tableName" | "notNull" | "hasDefault" | "isPrimaryKey" | "isAutoincrement" | "hasRuntimeDefault" | "dataType" | "columnType" | "enumValues" | "identity" | "dialect" | "baseColumn" | "generated" | "brand"> extends infer T_14 ? { [K in keyof T_14]: T_14[K]; } : never> : never : never : never;
|
|
116
|
+
identity: U_1["_"] extends infer T_15 ? T_15 extends U_1["_"] ? T_15 extends {
|
|
117
|
+
identity: "always";
|
|
118
|
+
} ? "always" : T_15 extends {
|
|
119
|
+
identity: "byDefault";
|
|
120
|
+
} ? "byDefault" : undefined : never : never;
|
|
121
|
+
generated: U_1["_"] extends infer T_16 ? T_16 extends U_1["_"] ? T_16 extends {
|
|
122
|
+
generated: infer G;
|
|
123
|
+
} ? unknown extends G ? undefined : G extends undefined ? undefined : G : undefined : never : never;
|
|
124
|
+
}, {}, Omit<U_1["_"], "name" | "data" | "driverParam" | "tableName" | "notNull" | "hasDefault" | "isPrimaryKey" | "isAutoincrement" | "hasRuntimeDefault" | "dataType" | "columnType" | "enumValues" | "identity" | "dialect" | "baseColumn" | "generated" | "brand"> extends infer T_17 ? { [K in keyof T_17]: T_17[K]; } : never> : never : never : never;
|
|
125
|
+
identity: Omit<TColumns[Key]["_"], "name"> & {
|
|
126
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
127
|
+
} extends infer T_18 ? T_18 extends Omit<TColumns[Key]["_"], "name"> & {
|
|
128
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
129
|
+
} ? T_18 extends {
|
|
130
|
+
identity: "always";
|
|
131
|
+
} ? "always" : T_18 extends {
|
|
132
|
+
identity: "byDefault";
|
|
133
|
+
} ? "byDefault" : undefined : never : never;
|
|
134
|
+
generated: Omit<TColumns[Key]["_"], "name"> & {
|
|
135
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
136
|
+
} extends infer T_19 ? T_19 extends Omit<TColumns[Key]["_"], "name"> & {
|
|
137
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
138
|
+
} ? T_19 extends {
|
|
139
|
+
generated: infer G;
|
|
140
|
+
} ? unknown extends G ? undefined : G extends undefined ? undefined : G : undefined : never : never;
|
|
141
|
+
}, {}, Omit<Omit<TColumns[Key]["_"], "name"> & {
|
|
142
|
+
name: TColumns[Key]["_"]["name"] extends "" ? import("drizzle-orm").Assume<Key, string> : TColumns[Key]["_"]["name"];
|
|
143
|
+
}, "name" | "data" | "driverParam" | "tableName" | "notNull" | "hasDefault" | "isPrimaryKey" | "isAutoincrement" | "hasRuntimeDefault" | "dataType" | "columnType" | "enumValues" | "identity" | "dialect" | "baseColumn" | "generated" | "brand"> extends infer T_20 ? { [K_1 in keyof T_20]: T_20[K_1]; } : never>; };
|
|
144
|
+
dialect: "pg";
|
|
145
|
+
}>;
|