@elysiumjs/mnemosyne-drizzle 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,8 +2,8 @@
2
2
  $ bun run clean && bun run build:js && bun run build:ts
3
3
  $ rimraf dist
4
4
  $ bun build ./src/index.ts --outdir ./dist --target bun --packages external --root ./src --minify
5
- Bundled 6 modules in 10ms
5
+ Bundled 4 modules in 9ms
6
6
 
7
- index.js 6.28 KB (entry point)
7
+ index.js 3.30 KB (entry point)
8
8
 
9
9
  $ tsc
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { eq, gt, gte, lt, lte, ne } from 'drizzle-orm';
1
2
  export * from 'drizzle-orm/pg-core';
2
3
  export { pgTable, getTableBuilders } from './table';
3
4
  export { Database, DrizzleDatabaseCache } from './database';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{Application as n,Event as l}from"@elysiumjs/core";import{registerTenancyStrategy as t}from"@elysiumjs/mnemosyne";import{AbstractDatabase as S,createDatabaseCacheStorage as C}from"@elysiumjs/mnemosyne";import{getTableName as j,is as v,Table as w}from"drizzle-orm";import{drizzle as k}from"drizzle-orm/bun-sql";import{Cache as N}from"drizzle-orm/cache/core";class O extends N{cacheStrategy;globalTtl;#G;usedTablesPerKey={};constructor(G="explicit",J=1,H="redis"){super();this.cacheStrategy=G;this.globalTtl=J;this.#G=C({storage:H})}strategy(){return this.cacheStrategy}async get(G){return await this.#G.get(G)??void 0}async put(G,J,H,K,V){await this.#G.set(G,J,(V?.ex??this.globalTtl)*1000);for(let W of H){let Y=this.usedTablesPerKey[W];if(Y===void 0)this.usedTablesPerKey[W]=[G];else Y.push(G)}}async onMutate(G){let J=G.tags?Array.isArray(G.tags)?G.tags:[G.tags]:[],H=G.tables?Array.isArray(G.tables)?G.tables:[G.tables]:[],K=new Set;for(let V of H){let W=v(V,w)?j(V):V,Y=this.usedTablesPerKey[W]??[];for(let I of Y)K.add(I)}if(K.size>0||J.length>0){await this.#G.mdel(J),await this.#G.mdel([...K]);for(let V of H){let W=v(V,w)?j(V):V;this.usedTablesPerKey[W]=[]}}}}class R extends S{driver={createConnection(G){let J=G.cache===void 0?void 0:G.cache===!0?new O:G.cache.enabled!==!1?new O(G.cache.strategy,G.cache.ttl,G.cache.storage):void 0;return k({...G,cache:J})},withTransaction(G,J){return G.transaction((H)=>J(H))},getRawClient(G){return G.$client}}}var X=new R;import{getTenancyConfig as $}from"@elysiumjs/mnemosyne";import{sql as Z}from"drizzle-orm";import{getTableConfig as h,pgPolicy as f,pgSchema as z,pgTable as u}from"drizzle-orm/pg-core";import{pgTable as D}from"drizzle-orm/pg-core";var q=new WeakMap,_=(G)=>{return q.get(G)},T=(G,J,H)=>{let K=D(G,J,H);return q.set(K,J),K};var P=new Map,Q=new Map,A=(G)=>{return Q.get(G)??x(G)},x=(G)=>{if(Q.has(G))return Q.get(G);let J=z(G);return Q.set(G,J),J},M=(G,J,H)=>{if(G==="public")return u(J,H);let K=`${G}.${J}`;if(P.has(K))return P.get(K);let W=A(G).table(J,H);return P.set(K,W),W},y=async(G,J,H="default")=>{let K=X.getConnection(H),W=$().rls?.sessionVariable??"app.current_tenant",Y=G??"public";return K.transaction(async(I)=>{return await I.execute(Z`SELECT set_config(${W}, ${Y}, true)`),J(I)})},p=async(G,J="default")=>{let H=X.getConnection(J),V=$().rls?.sessionVariable??"app.current_tenant",W=G??"public";await H.execute(Z`SELECT set_config(${V}, ${W}, false)`)},g=async(G="default")=>{let J=X.getConnection(G),K=$().rls?.sessionVariable??"app.current_tenant";return(await J.execute(Z`SELECT current_setting(${K}, true) as tenant`))?.rows?.[0]?.tenant??null},d=(G,J,H)=>{let K=$(),V=K.rls?.sessionVariable??"app.current_tenant",W=J??K.rls?.defaultColumn??"tenant_id",Y=H??`${G}_tenant_isolation`;return f(Y,{for:"all",to:"public",using:Z`${Z.identifier(W)} = current_setting(${V}, true)::text`,withCheck:Z`${Z.identifier(W)} = current_setting(${V}, true)::text`})};class U{mode="schema";resolveTable(G,J){let H=_(G);if(!H)throw Error("No column builders registered for table. Use pgTable() from '@elysiumjs/mnemosyne-drizzle' for tenant support.");let K=h(G);return M(J,K.name,H)}async withIsolation(G,J,H){return H()}}class E{mode="rls";resolveTable(G,J){return G}async withIsolation(G,J,H){let V=$().rls?.sessionVariable??"app.current_tenant";return G.transaction(async(W)=>{return await W.execute(Z`SELECT set_config(${V}, ${J}, true)`),H()})}}export*from"drizzle-orm/pg-core";import{AbstractModel as b,createSchemaFromModel as m}from"@elysiumjs/mnemosyne";import{getTableConfig as L}from"drizzle-orm/pg-core";var r=(G)=>{if(G.columnType==="PgUUID")return"uuid";switch(G.dataType){case"string":return"string";case"number":return"number";case"boolean":return"boolean";case"array":return"array";case"json":return"json";case"date":return"date";case"bigint":return"bigint";case"buffer":return"buffer";default:return"string"}},B={getTableName(G){return L(G).name},getColumns(G){let J=L(G);return J.columns.map((H)=>({name:H.name,dataType:r(H),nullable:!H.notNull,hasDefault:H.hasDefault,isPrimaryKey:H.primary||J.primaryKeys.some((K)=>K.columns.some((V)=>V.name===H.name))}))},createTenantTable(G,J){let H=_(G);if(!H)throw Error("No column builders registered for table. Use pgTable() from '@elysiumjs/mnemosyne-drizzle' for tenant support.");let K=L(G);return M(J,K.name,H)}},s=(G,J)=>{return m(B.getColumns(G),J)},i=(G,J)=>{let H=L(G),K=_(G),V=b(H.name,K??{},B,G);if(J?.supportTenancy!==void 0)V.supportTenancy=J.supportTenancy;return V};import{AbstractRepository as c}from"@elysiumjs/mnemosyne";import{eq as F}from"drizzle-orm";var o=(G)=>{class J extends c(G,X){async all(){return await this.db.select().from(G.table)}async paginate(H,K=1){let V=await this.db.$count(G.table),W=Math.max(K-1,0)*H;return{page:K,total:V,data:await this.db.select().from(G.table).offset(W).limit(H)}}async find(H){let[K]=await this.db.select().from(G.table).where(F(G.table.id,H));return K??null}async findBy(H,K){let[V]=await this.db.select().from(G.table).where(F(G.table[H],K));return V??null}async insert(H){let[K]=await this.db.insert(G.table).values(H).returning();return K}async update(H,K){let[V]=await this.db.update(G.table).set(K).where(F(G.table.id,H)).returning();return V}async updateAll(H){return await this.db.update(G.table).set(H).returning()}async delete(H){let[K]=await this.db.delete(G.table).where(F(G.table.id,H)).returning();return K}async deleteAll(){return await this.db.delete(G.table).returning()}async exists(H){return await this.db.$count(G.table,F(G.table.id,H))>0}}return J};l.once("elysium:app:launched",()=>{let J=n.instance.getConfig("elysium:mnemosyne");if(J?.database){for(let[H,K]of Object.entries(J.database.connections))X.registerConnection(H,K);if(X.connectionExists(J.database.default))X.setDefaultConnection(J.database.default)}if(J?.tenancy){let H=J.tenancy.mode==="rls"?new E:new U;t(H)}});export{M as wrapTenantSchema,y as withRLS,p as setConnectionTenant,x as registerTenantSchema,T as pgTable,A as getTenantSchema,_ as getTableBuilders,g as getSessionTenant,B as drizzleAdapter,s as createSchemaFromDrizzle,d as createRLSPolicy,U as DrizzleSchemaTenancy,o as DrizzleRepository,E as DrizzleRLSTenancy,i as DrizzleModel,O as DrizzleDatabaseCache,X as Database};
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/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{RF as wrapTenantSchema,vF as withRLS,xF as setConnectionTenant,qF as registerTenantSchema,XF as pgTable,UF as ne,MF as lte,KF as lt,JF as gte,HF as gt,AF as getTenantSchema,YF as getTableBuilders,CF as getSessionTenant,GF as eq,QF as drizzleAdapter,OF as createSchemaFromDrizzle,SF as createRLSPolicy,LF as DrizzleSchemaTenancy,jF as DrizzleRepository,PF as DrizzleRLSTenancy,IF as DrizzleModel,$F as DrizzleDatabaseCache,_F as Database};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elysiumjs/mnemosyne-drizzle",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Drizzle ORM driver for @elysiumjs/mnemosyne",
6
6
  "private": false,
@@ -19,7 +19,13 @@
19
19
  "typecheck": "tsc --noEmit",
20
20
  "prepublishOnly": "bun run build"
21
21
  },
22
- "keywords": ["elysium", "database", "orm", "drizzle", "postgresql"],
22
+ "keywords": [
23
+ "elysium",
24
+ "database",
25
+ "orm",
26
+ "drizzle",
27
+ "postgresql"
28
+ ],
23
29
  "module": "dist/index.js",
24
30
  "type": "module",
25
31
  "types": "dist/index.d.ts",
@@ -29,7 +35,7 @@
29
35
  "@elysiumjs/mnemosyne": "^0.1.0"
30
36
  },
31
37
  "dependencies": {
32
- "drizzle-orm": "^0.44.6"
38
+ "drizzle-orm": "^0.45.1"
33
39
  },
34
40
  "devDependencies": {
35
41
  "@elysiumjs/core": "0.7.0",
package/src/index.ts CHANGED
@@ -22,6 +22,7 @@ import { Database } from './database';
22
22
  import { DrizzleRLSTenancy, DrizzleSchemaTenancy } from './tenancy';
23
23
 
24
24
  // Re-export drizzle-orm/pg-core with enhanced pgTable
25
+ export { eq, gt, gte, lt, lte, ne } from 'drizzle-orm';
25
26
  export * from 'drizzle-orm/pg-core';
26
27
  export { pgTable, getTableBuilders } from './table';
27
28
 
@@ -1 +0,0 @@
1
- $ tsc --noEmit
@@ -1,14 +0,0 @@
1
- TN:
2
- SF:tests/setup.ts
3
- FNF:1
4
- FNH:0
5
- DA:1,25
6
- DA:3,32
7
- DA:5,0
8
- DA:6,0
9
- DA:7,0
10
- DA:8,0
11
- DA:10,2
12
- LF:7
13
- LH:3
14
- end_of_record
@@ -1,343 +0,0 @@
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:10
127
- FNH:9
128
- DA:18,76
129
- DA:19,62
130
- DA:21,45
131
- DA:35,42
132
- DA:42,42
133
- DA:43,7
134
- DA:44,12
135
- DA:45,3
136
- DA:46,45
137
- DA:54,37
138
- DA:55,10
139
- DA:56,3
140
- DA:57,41
141
- DA:69,37
142
- DA:70,50
143
- DA:71,31
144
- DA:72,15
145
- DA:73,20
146
- DA:74,15
147
- DA:75,20
148
- DA:76,16
149
- DA:77,16
150
- DA:78,0
151
- DA:79,0
152
- DA:80,0
153
- DA:81,0
154
- DA:82,0
155
- DA:83,0
156
- DA:84,0
157
- DA:85,0
158
- DA:86,0
159
- DA:87,0
160
- DA:89,2
161
- DA:105,31
162
- DA:106,13
163
- DA:107,35
164
- DA:110,13
165
- DA:111,41
166
- DA:112,42
167
- DA:113,21
168
- DA:114,40
169
- DA:115,29
170
- DA:116,33
171
- DA:117,14
172
- DA:118,43
173
- DA:119,4
174
- DA:122,21
175
- DA:123,51
176
- DA:124,21
177
- DA:125,16
178
- DA:126,99
179
- DA:128,1
180
- DA:129,4
181
- DA:130,41
182
- DA:131,55
183
- DA:133,2
184
- DA:150,38
185
- DA:151,7
186
- DA:152,9
187
- DA:153,3
188
- DA:154,70
189
- DA:173,27
190
- DA:174,11
191
- DA:175,9
192
- DA:176,16
193
- DA:177,3
194
- DA:178,61
195
- DA:180,50
196
- DA:186,76
197
- DA:187,12
198
- LF:70
199
- LH:60
200
- end_of_record
201
- TN:
202
- SF:src/tenancy.ts
203
- FNF:14
204
- FNH:10
205
- DA:19,112
206
- DA:20,68
207
- DA:21,164
208
- DA:23,76
209
- DA:24,98
210
- DA:30,60
211
- DA:31,62
212
- DA:43,89
213
- DA:44,136
214
- DA:53,99
215
- DA:54,73
216
- DA:55,69
217
- DA:56,5
218
- DA:57,80
219
- DA:58,86
220
- DA:59,44
221
- DA:74,63
222
- DA:78,16
223
- DA:79,22
224
- DA:80,24
225
- DA:81,6
226
- DA:82,59
227
- DA:83,71
228
- DA:84,5
229
- DA:86,98
230
- DA:87,85
231
- DA:88,81
232
- DA:89,5
233
- DA:91,94
234
- DA:92,122
235
- DA:93,96
236
- DA:95,42
237
- DA:110,0
238
- DA:111,0
239
- DA:112,0
240
- DA:113,0
241
- DA:114,0
242
- DA:115,0
243
- DA:116,0
244
- DA:117,0
245
- DA:118,0
246
- DA:119,0
247
- DA:120,0
248
- DA:121,0
249
- DA:122,0
250
- DA:123,7
251
- DA:132,0
252
- DA:133,0
253
- DA:134,0
254
- DA:135,0
255
- DA:136,0
256
- DA:137,0
257
- DA:138,0
258
- DA:139,0
259
- DA:140,0
260
- DA:141,75
261
- DA:150,0
262
- DA:151,0
263
- DA:152,0
264
- DA:153,0
265
- DA:154,0
266
- DA:155,0
267
- DA:156,0
268
- DA:157,0
269
- DA:158,46
270
- DA:169,143
271
- DA:170,72
272
- DA:171,140
273
- DA:172,144
274
- DA:173,122
275
- DA:175,54
276
- DA:176,30
277
- DA:177,34
278
- DA:178,168
279
- DA:179,170
280
- DA:180,9
281
- DA:195,57
282
- DA:196,35
283
- DA:198,54
284
- DA:199,102
285
- DA:200,36
286
- DA:201,16
287
- DA:202,99
288
- DA:204,6
289
- DA:205,9
290
- DA:206,82
291
- DA:207,120
292
- DA:210,16
293
- DA:211,26
294
- DA:212,18
295
- DA:213,20
296
- DA:214,10
297
- DA:216,40
298
- DA:218,2
299
- DA:228,66
300
- DA:229,29
301
- DA:231,56
302
- DA:233,36
303
- DA:236,16
304
- DA:237,24
305
- DA:238,16
306
- DA:239,20
307
- DA:240,10
308
- DA:241,76
309
- DA:242,144
310
- DA:244,94
311
- DA:245,152
312
- DA:246,41
313
- DA:247,8
314
- DA:249,2
315
- LF:110
316
- LH:80
317
- end_of_record
318
- TN:
319
- SF:tests/setup.ts
320
- FNF:3
321
- FNH:1
322
- DA:1,0
323
- DA:2,0
324
- DA:3,0
325
- DA:4,0
326
- DA:5,0
327
- DA:6,30
328
- DA:7,47
329
- DA:8,19
330
- DA:9,2
331
- DA:10,2
332
- LF:10
333
- LH:5
334
- end_of_record
335
- TN:
336
- SF:../mnemosyne/dist/index.js
337
- FNF:53
338
- FNH:12
339
- DA:1,0
340
- DA:2,3197
341
- LF:2
342
- LH:1
343
- end_of_record