gencow 0.1.154 → 0.1.155
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/core/index.js +74 -30
- package/lib/codegen/index.mjs +74 -30
- package/package.json +1 -1
- package/server/index.js +74 -30
- package/server/index.js.map +3 -3
package/core/index.js
CHANGED
|
@@ -3229,6 +3229,10 @@ async function forEachSetConfig(rls, setOne) {
|
|
|
3229
3229
|
}
|
|
3230
3230
|
}
|
|
3231
3231
|
var rlsExecClient = new AsyncLocalStorage();
|
|
3232
|
+
function isBunSqlSession(session) {
|
|
3233
|
+
const name = session?.constructor?.name;
|
|
3234
|
+
return typeof name === "string" && name.includes("BunSQLSession");
|
|
3235
|
+
}
|
|
3232
3236
|
function isDrizzleTransactionDb(db) {
|
|
3233
3237
|
const d = db;
|
|
3234
3238
|
if (typeof d?.rollback === "function") {
|
|
@@ -3296,40 +3300,80 @@ async function withRlsConnection(session, rls, reuseOuterConnection, fn) {
|
|
|
3296
3300
|
}
|
|
3297
3301
|
return runInner(c);
|
|
3298
3302
|
}
|
|
3299
|
-
function
|
|
3303
|
+
function createClientBoundSession(session, client) {
|
|
3304
|
+
return new Proxy(session, {
|
|
3305
|
+
get(target, prop, receiver) {
|
|
3306
|
+
if (prop === "client") {
|
|
3307
|
+
return client;
|
|
3308
|
+
}
|
|
3309
|
+
const value = Reflect.get(target, prop, receiver);
|
|
3310
|
+
return typeof value === "function" ? value.bind(receiver) : value;
|
|
3311
|
+
}
|
|
3312
|
+
});
|
|
3313
|
+
}
|
|
3314
|
+
async function withPreparedQueryClient(pq, client, fn) {
|
|
3315
|
+
if (!("client" in pq)) {
|
|
3316
|
+
return await fn();
|
|
3317
|
+
}
|
|
3318
|
+
const prevPq = pq.client;
|
|
3319
|
+
pq.client = client;
|
|
3320
|
+
try {
|
|
3321
|
+
return await fn();
|
|
3322
|
+
} finally {
|
|
3323
|
+
pq.client = prevPq;
|
|
3324
|
+
}
|
|
3325
|
+
}
|
|
3326
|
+
function createGenericPreparedQueryClientExecutors(pq) {
|
|
3300
3327
|
const origExecute = pq.execute.bind(pq);
|
|
3301
3328
|
const origAll = typeof pq.all === "function" ? pq.all.bind(pq) : null;
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
return
|
|
3305
|
-
}
|
|
3306
|
-
|
|
3307
|
-
pq.client = client;
|
|
3308
|
-
try {
|
|
3309
|
-
return await fn();
|
|
3310
|
-
} finally {
|
|
3311
|
-
pq.client = prevPq;
|
|
3312
|
-
}
|
|
3329
|
+
return {
|
|
3330
|
+
execute(client, placeholderValues) {
|
|
3331
|
+
return withPreparedQueryClient(pq, client, () => origExecute(placeholderValues));
|
|
3332
|
+
},
|
|
3333
|
+
all: origAll ? (client, placeholderValues) => withPreparedQueryClient(pq, client, () => origAll(placeholderValues)) : void 0
|
|
3313
3334
|
};
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
return withRlsConnection(session, rls, reuseOuterConnection, async (client) => {
|
|
3320
|
-
return withPreparedQueryClient(client, () => origExecute(placeholderValues));
|
|
3321
|
-
});
|
|
3335
|
+
}
|
|
3336
|
+
function createBunSqlPreparedQueryClientExecutors(baseSession, prepareQuery, prepareArgs) {
|
|
3337
|
+
const reprepareOnClient = (client) => {
|
|
3338
|
+
const clientBoundSession = createClientBoundSession(baseSession, client);
|
|
3339
|
+
return Reflect.apply(prepareQuery, clientBoundSession, prepareArgs);
|
|
3322
3340
|
};
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3341
|
+
return {
|
|
3342
|
+
execute(client, placeholderValues) {
|
|
3343
|
+
return reprepareOnClient(client).execute(placeholderValues);
|
|
3344
|
+
},
|
|
3345
|
+
all(client, placeholderValues) {
|
|
3346
|
+
const txPreparedQuery = reprepareOnClient(client);
|
|
3347
|
+
if (typeof txPreparedQuery.all === "function") {
|
|
3348
|
+
return txPreparedQuery.all(placeholderValues);
|
|
3328
3349
|
}
|
|
3329
|
-
return
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3350
|
+
return txPreparedQuery.execute(placeholderValues);
|
|
3351
|
+
}
|
|
3352
|
+
};
|
|
3353
|
+
}
|
|
3354
|
+
function createPreparedQueryClientExecutors(params) {
|
|
3355
|
+
if (isBunSqlSession(params.baseSession)) {
|
|
3356
|
+
return createBunSqlPreparedQueryClientExecutors(params.baseSession, params.prepareQuery, params.prepareArgs);
|
|
3357
|
+
}
|
|
3358
|
+
return createGenericPreparedQueryClientExecutors(params.pq);
|
|
3359
|
+
}
|
|
3360
|
+
async function runPreparedQueryWithRls(session, rls, reuseOuterConnection, runOnClient, placeholderValues) {
|
|
3361
|
+
const active = rlsExecClient.getStore();
|
|
3362
|
+
if (active) {
|
|
3363
|
+
return runOnClient(active, placeholderValues);
|
|
3364
|
+
}
|
|
3365
|
+
return withRlsConnection(session, rls, reuseOuterConnection, (client) => runOnClient(client, placeholderValues));
|
|
3366
|
+
}
|
|
3367
|
+
function wrapPreparedQuery(pq, session, baseSession, prepareQuery, prepareArgs, rls, reuseOuterConnection) {
|
|
3368
|
+
const clientExecutors = createPreparedQueryClientExecutors({
|
|
3369
|
+
pq,
|
|
3370
|
+
baseSession,
|
|
3371
|
+
prepareQuery,
|
|
3372
|
+
prepareArgs
|
|
3373
|
+
});
|
|
3374
|
+
pq.execute = (placeholderValues) => runPreparedQueryWithRls(session, rls, reuseOuterConnection, clientExecutors.execute, placeholderValues);
|
|
3375
|
+
if (clientExecutors.all) {
|
|
3376
|
+
pq.all = (placeholderValues) => runPreparedQueryWithRls(session, rls, reuseOuterConnection, clientExecutors.all, placeholderValues);
|
|
3333
3377
|
}
|
|
3334
3378
|
}
|
|
3335
3379
|
function wrapSession(session, rls, reuseOuterConnection) {
|
|
@@ -3342,7 +3386,7 @@ function wrapSession(session, rls, reuseOuterConnection) {
|
|
|
3342
3386
|
return (...args) => {
|
|
3343
3387
|
const prepareQuery = Reflect.get(sTarget, sProp, sRecv);
|
|
3344
3388
|
const pq = Reflect.apply(prepareQuery, sRecv, args);
|
|
3345
|
-
wrapPreparedQuery(pq, sRecv, rls, reuseOuterConnection);
|
|
3389
|
+
wrapPreparedQuery(pq, sRecv, sTarget, prepareQuery, args, rls, reuseOuterConnection);
|
|
3346
3390
|
return pq;
|
|
3347
3391
|
};
|
|
3348
3392
|
}
|
package/lib/codegen/index.mjs
CHANGED
|
@@ -6997,6 +6997,10 @@ async function forEachSetConfig(rls, setOne) {
|
|
|
6997
6997
|
await setOne(name2, value);
|
|
6998
6998
|
}
|
|
6999
6999
|
}
|
|
7000
|
+
function isBunSqlSession(session) {
|
|
7001
|
+
const name2 = session?.constructor?.name;
|
|
7002
|
+
return typeof name2 === "string" && name2.includes("BunSQLSession");
|
|
7003
|
+
}
|
|
7000
7004
|
function isDrizzleTransactionDb(db) {
|
|
7001
7005
|
const d = db;
|
|
7002
7006
|
if (typeof d?.rollback === "function") {
|
|
@@ -7064,40 +7068,80 @@ async function withRlsConnection(session, rls, reuseOuterConnection, fn) {
|
|
|
7064
7068
|
}
|
|
7065
7069
|
return runInner(c);
|
|
7066
7070
|
}
|
|
7067
|
-
function
|
|
7071
|
+
function createClientBoundSession(session, client) {
|
|
7072
|
+
return new Proxy(session, {
|
|
7073
|
+
get(target, prop, receiver) {
|
|
7074
|
+
if (prop === "client") {
|
|
7075
|
+
return client;
|
|
7076
|
+
}
|
|
7077
|
+
const value = Reflect.get(target, prop, receiver);
|
|
7078
|
+
return typeof value === "function" ? value.bind(receiver) : value;
|
|
7079
|
+
}
|
|
7080
|
+
});
|
|
7081
|
+
}
|
|
7082
|
+
async function withPreparedQueryClient(pq, client, fn) {
|
|
7083
|
+
if (!("client" in pq)) {
|
|
7084
|
+
return await fn();
|
|
7085
|
+
}
|
|
7086
|
+
const prevPq = pq.client;
|
|
7087
|
+
pq.client = client;
|
|
7088
|
+
try {
|
|
7089
|
+
return await fn();
|
|
7090
|
+
} finally {
|
|
7091
|
+
pq.client = prevPq;
|
|
7092
|
+
}
|
|
7093
|
+
}
|
|
7094
|
+
function createGenericPreparedQueryClientExecutors(pq) {
|
|
7068
7095
|
const origExecute = pq.execute.bind(pq);
|
|
7069
7096
|
const origAll = typeof pq.all === "function" ? pq.all.bind(pq) : null;
|
|
7070
|
-
|
|
7071
|
-
|
|
7072
|
-
return
|
|
7073
|
-
}
|
|
7074
|
-
|
|
7075
|
-
|
|
7076
|
-
|
|
7077
|
-
|
|
7078
|
-
|
|
7079
|
-
|
|
7080
|
-
|
|
7097
|
+
return {
|
|
7098
|
+
execute(client, placeholderValues) {
|
|
7099
|
+
return withPreparedQueryClient(pq, client, () => origExecute(placeholderValues));
|
|
7100
|
+
},
|
|
7101
|
+
all: origAll ? (client, placeholderValues) => withPreparedQueryClient(pq, client, () => origAll(placeholderValues)) : void 0
|
|
7102
|
+
};
|
|
7103
|
+
}
|
|
7104
|
+
function createBunSqlPreparedQueryClientExecutors(baseSession, prepareQuery, prepareArgs) {
|
|
7105
|
+
const reprepareOnClient = (client) => {
|
|
7106
|
+
const clientBoundSession = createClientBoundSession(baseSession, client);
|
|
7107
|
+
return Reflect.apply(prepareQuery, clientBoundSession, prepareArgs);
|
|
7081
7108
|
};
|
|
7082
|
-
|
|
7083
|
-
|
|
7084
|
-
|
|
7085
|
-
|
|
7109
|
+
return {
|
|
7110
|
+
execute(client, placeholderValues) {
|
|
7111
|
+
return reprepareOnClient(client).execute(placeholderValues);
|
|
7112
|
+
},
|
|
7113
|
+
all(client, placeholderValues) {
|
|
7114
|
+
const txPreparedQuery = reprepareOnClient(client);
|
|
7115
|
+
if (typeof txPreparedQuery.all === "function") {
|
|
7116
|
+
return txPreparedQuery.all(placeholderValues);
|
|
7117
|
+
}
|
|
7118
|
+
return txPreparedQuery.execute(placeholderValues);
|
|
7086
7119
|
}
|
|
7087
|
-
return withRlsConnection(session, rls, reuseOuterConnection, async (client) => {
|
|
7088
|
-
return withPreparedQueryClient(client, () => origExecute(placeholderValues));
|
|
7089
|
-
});
|
|
7090
7120
|
};
|
|
7091
|
-
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
7100
|
-
|
|
7121
|
+
}
|
|
7122
|
+
function createPreparedQueryClientExecutors(params) {
|
|
7123
|
+
if (isBunSqlSession(params.baseSession)) {
|
|
7124
|
+
return createBunSqlPreparedQueryClientExecutors(params.baseSession, params.prepareQuery, params.prepareArgs);
|
|
7125
|
+
}
|
|
7126
|
+
return createGenericPreparedQueryClientExecutors(params.pq);
|
|
7127
|
+
}
|
|
7128
|
+
async function runPreparedQueryWithRls(session, rls, reuseOuterConnection, runOnClient, placeholderValues) {
|
|
7129
|
+
const active = rlsExecClient.getStore();
|
|
7130
|
+
if (active) {
|
|
7131
|
+
return runOnClient(active, placeholderValues);
|
|
7132
|
+
}
|
|
7133
|
+
return withRlsConnection(session, rls, reuseOuterConnection, (client) => runOnClient(client, placeholderValues));
|
|
7134
|
+
}
|
|
7135
|
+
function wrapPreparedQuery(pq, session, baseSession, prepareQuery, prepareArgs, rls, reuseOuterConnection) {
|
|
7136
|
+
const clientExecutors = createPreparedQueryClientExecutors({
|
|
7137
|
+
pq,
|
|
7138
|
+
baseSession,
|
|
7139
|
+
prepareQuery,
|
|
7140
|
+
prepareArgs
|
|
7141
|
+
});
|
|
7142
|
+
pq.execute = (placeholderValues) => runPreparedQueryWithRls(session, rls, reuseOuterConnection, clientExecutors.execute, placeholderValues);
|
|
7143
|
+
if (clientExecutors.all) {
|
|
7144
|
+
pq.all = (placeholderValues) => runPreparedQueryWithRls(session, rls, reuseOuterConnection, clientExecutors.all, placeholderValues);
|
|
7101
7145
|
}
|
|
7102
7146
|
}
|
|
7103
7147
|
function wrapSession(session, rls, reuseOuterConnection) {
|
|
@@ -7110,7 +7154,7 @@ function wrapSession(session, rls, reuseOuterConnection) {
|
|
|
7110
7154
|
return (...args) => {
|
|
7111
7155
|
const prepareQuery = Reflect.get(sTarget, sProp, sRecv);
|
|
7112
7156
|
const pq = Reflect.apply(prepareQuery, sRecv, args);
|
|
7113
|
-
wrapPreparedQuery(pq, sRecv, rls, reuseOuterConnection);
|
|
7157
|
+
wrapPreparedQuery(pq, sRecv, sTarget, prepareQuery, args, rls, reuseOuterConnection);
|
|
7114
7158
|
return pq;
|
|
7115
7159
|
};
|
|
7116
7160
|
}
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -87259,6 +87259,10 @@ async function forEachSetConfig(rls, setOne) {
|
|
|
87259
87259
|
}
|
|
87260
87260
|
}
|
|
87261
87261
|
var rlsExecClient = new AsyncLocalStorage();
|
|
87262
|
+
function isBunSqlSession(session2) {
|
|
87263
|
+
const name = session2?.constructor?.name;
|
|
87264
|
+
return typeof name === "string" && name.includes("BunSQLSession");
|
|
87265
|
+
}
|
|
87262
87266
|
function isDrizzleTransactionDb(db) {
|
|
87263
87267
|
const d = db;
|
|
87264
87268
|
if (typeof d?.rollback === "function") {
|
|
@@ -87326,40 +87330,80 @@ async function withRlsConnection(session2, rls, reuseOuterConnection, fn) {
|
|
|
87326
87330
|
}
|
|
87327
87331
|
return runInner(c);
|
|
87328
87332
|
}
|
|
87329
|
-
function
|
|
87333
|
+
function createClientBoundSession(session2, client) {
|
|
87334
|
+
return new Proxy(session2, {
|
|
87335
|
+
get(target, prop, receiver) {
|
|
87336
|
+
if (prop === "client") {
|
|
87337
|
+
return client;
|
|
87338
|
+
}
|
|
87339
|
+
const value = Reflect.get(target, prop, receiver);
|
|
87340
|
+
return typeof value === "function" ? value.bind(receiver) : value;
|
|
87341
|
+
}
|
|
87342
|
+
});
|
|
87343
|
+
}
|
|
87344
|
+
async function withPreparedQueryClient(pq, client, fn) {
|
|
87345
|
+
if (!("client" in pq)) {
|
|
87346
|
+
return await fn();
|
|
87347
|
+
}
|
|
87348
|
+
const prevPq = pq.client;
|
|
87349
|
+
pq.client = client;
|
|
87350
|
+
try {
|
|
87351
|
+
return await fn();
|
|
87352
|
+
} finally {
|
|
87353
|
+
pq.client = prevPq;
|
|
87354
|
+
}
|
|
87355
|
+
}
|
|
87356
|
+
function createGenericPreparedQueryClientExecutors(pq) {
|
|
87330
87357
|
const origExecute = pq.execute.bind(pq);
|
|
87331
87358
|
const origAll = typeof pq.all === "function" ? pq.all.bind(pq) : null;
|
|
87332
|
-
|
|
87333
|
-
|
|
87334
|
-
return
|
|
87335
|
-
}
|
|
87336
|
-
|
|
87337
|
-
|
|
87338
|
-
|
|
87339
|
-
|
|
87340
|
-
|
|
87341
|
-
|
|
87342
|
-
|
|
87359
|
+
return {
|
|
87360
|
+
execute(client, placeholderValues) {
|
|
87361
|
+
return withPreparedQueryClient(pq, client, () => origExecute(placeholderValues));
|
|
87362
|
+
},
|
|
87363
|
+
all: origAll ? (client, placeholderValues) => withPreparedQueryClient(pq, client, () => origAll(placeholderValues)) : void 0
|
|
87364
|
+
};
|
|
87365
|
+
}
|
|
87366
|
+
function createBunSqlPreparedQueryClientExecutors(baseSession, prepareQuery, prepareArgs) {
|
|
87367
|
+
const reprepareOnClient = (client) => {
|
|
87368
|
+
const clientBoundSession = createClientBoundSession(baseSession, client);
|
|
87369
|
+
return Reflect.apply(prepareQuery, clientBoundSession, prepareArgs);
|
|
87343
87370
|
};
|
|
87344
|
-
|
|
87345
|
-
|
|
87346
|
-
|
|
87347
|
-
|
|
87371
|
+
return {
|
|
87372
|
+
execute(client, placeholderValues) {
|
|
87373
|
+
return reprepareOnClient(client).execute(placeholderValues);
|
|
87374
|
+
},
|
|
87375
|
+
all(client, placeholderValues) {
|
|
87376
|
+
const txPreparedQuery = reprepareOnClient(client);
|
|
87377
|
+
if (typeof txPreparedQuery.all === "function") {
|
|
87378
|
+
return txPreparedQuery.all(placeholderValues);
|
|
87379
|
+
}
|
|
87380
|
+
return txPreparedQuery.execute(placeholderValues);
|
|
87348
87381
|
}
|
|
87349
|
-
return withRlsConnection(session2, rls, reuseOuterConnection, async (client) => {
|
|
87350
|
-
return withPreparedQueryClient(client, () => origExecute(placeholderValues));
|
|
87351
|
-
});
|
|
87352
87382
|
};
|
|
87353
|
-
|
|
87354
|
-
|
|
87355
|
-
|
|
87356
|
-
|
|
87357
|
-
|
|
87358
|
-
|
|
87359
|
-
|
|
87360
|
-
|
|
87361
|
-
|
|
87362
|
-
|
|
87383
|
+
}
|
|
87384
|
+
function createPreparedQueryClientExecutors(params) {
|
|
87385
|
+
if (isBunSqlSession(params.baseSession)) {
|
|
87386
|
+
return createBunSqlPreparedQueryClientExecutors(params.baseSession, params.prepareQuery, params.prepareArgs);
|
|
87387
|
+
}
|
|
87388
|
+
return createGenericPreparedQueryClientExecutors(params.pq);
|
|
87389
|
+
}
|
|
87390
|
+
async function runPreparedQueryWithRls(session2, rls, reuseOuterConnection, runOnClient, placeholderValues) {
|
|
87391
|
+
const active = rlsExecClient.getStore();
|
|
87392
|
+
if (active) {
|
|
87393
|
+
return runOnClient(active, placeholderValues);
|
|
87394
|
+
}
|
|
87395
|
+
return withRlsConnection(session2, rls, reuseOuterConnection, (client) => runOnClient(client, placeholderValues));
|
|
87396
|
+
}
|
|
87397
|
+
function wrapPreparedQuery(pq, session2, baseSession, prepareQuery, prepareArgs, rls, reuseOuterConnection) {
|
|
87398
|
+
const clientExecutors = createPreparedQueryClientExecutors({
|
|
87399
|
+
pq,
|
|
87400
|
+
baseSession,
|
|
87401
|
+
prepareQuery,
|
|
87402
|
+
prepareArgs
|
|
87403
|
+
});
|
|
87404
|
+
pq.execute = (placeholderValues) => runPreparedQueryWithRls(session2, rls, reuseOuterConnection, clientExecutors.execute, placeholderValues);
|
|
87405
|
+
if (clientExecutors.all) {
|
|
87406
|
+
pq.all = (placeholderValues) => runPreparedQueryWithRls(session2, rls, reuseOuterConnection, clientExecutors.all, placeholderValues);
|
|
87363
87407
|
}
|
|
87364
87408
|
}
|
|
87365
87409
|
function wrapSession(session2, rls, reuseOuterConnection) {
|
|
@@ -87372,7 +87416,7 @@ function wrapSession(session2, rls, reuseOuterConnection) {
|
|
|
87372
87416
|
return (...args) => {
|
|
87373
87417
|
const prepareQuery = Reflect.get(sTarget, sProp, sRecv);
|
|
87374
87418
|
const pq = Reflect.apply(prepareQuery, sRecv, args);
|
|
87375
|
-
wrapPreparedQuery(pq, sRecv, rls, reuseOuterConnection);
|
|
87419
|
+
wrapPreparedQuery(pq, sRecv, sTarget, prepareQuery, args, rls, reuseOuterConnection);
|
|
87376
87420
|
return pq;
|
|
87377
87421
|
};
|
|
87378
87422
|
}
|