gencow 0.1.285 → 0.1.287
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/bin/gencow.mjs +12 -15
- package/core/index.js +120 -24
- package/core/package.json +1 -1
- package/dashboard/assets/{index-CpQz6uv1.js → index-M4J2Ub-u.js} +3 -3
- package/dashboard/assets/index-OH2xW1ZG.css +2 -0
- package/dashboard/index.html +2 -2
- package/docs/api.md +6 -0
- package/docs/commands.md +9 -0
- package/docs/packaging.md +1 -1
- package/docs/troubleshooting.md +11 -0
- package/lib/app-command.mjs +18 -3
- package/lib/app-error-diagnostic.mjs +38 -0
- package/lib/app-response-error.mjs +66 -17
- package/lib/backend-bundle-file-plan.mjs +88 -5
- package/lib/cli-command-runner.mjs +52 -2
- package/lib/codegen-command.mjs +2 -0
- package/lib/coding-guardrails.mjs +8 -0
- package/lib/db-check-deadline.mjs +10 -5
- package/lib/db-command.mjs +14 -4
- package/lib/db-metadata-command.mjs +155 -0
- package/lib/db-migration-command-steps.mjs +104 -10
- package/lib/db-push-command.mjs +49 -45
- package/lib/db-seed-failure-render.mjs +7 -3
- package/lib/deploy-admission-transport-failure.mjs +46 -1
- package/lib/deploy-app-target.mjs +82 -13
- package/lib/deploy-audit-errors.mjs +20 -0
- package/lib/deploy-bundle-staging.mjs +53 -4
- package/lib/deploy-codegen-failure.mjs +36 -4
- package/lib/deploy-codegen-preflight.mjs +22 -1
- package/lib/deploy-failure-diagnostic.mjs +93 -8
- package/lib/deploy-migration-codegen-stage.mjs +65 -0
- package/lib/deploy-package-runtime.mjs +18 -38
- package/lib/deployment-operation-poll.mjs +44 -5
- package/lib/dev-cloud-bundle.mjs +57 -5
- package/lib/dev-cloud-command.mjs +4 -1
- package/lib/dev-cloud-migrations.mjs +3 -0
- package/lib/dev-local-command.mjs +32 -1
- package/lib/doctor-command.mjs +23 -1
- package/lib/drizzle-generate.mjs +28 -6
- package/lib/metadata-conversion.mjs +182 -0
- package/lib/metadata-diagnostic.mjs +121 -0
- package/lib/metadata-publication.mjs +263 -0
- package/lib/metadata-upgrade.mjs +292 -0
- package/lib/migration-bundle-roundtrip.mjs +7 -2
- package/lib/migration-bundle-staging.mjs +13 -1
- package/lib/migration-client-diagnostic.mjs +53 -2
- package/lib/migration-diagnostic.mjs +47 -0
- package/lib/migration-folder-format.mjs +17 -14
- package/lib/migration-operation-client.mjs +3 -1
- package/lib/prod-create-region-diagnostic.mjs +6 -2
- package/lib/project-context.mjs +8 -0
- package/lib/project-migration-manifest.mjs +5 -1
- package/lib/release-client.mjs +59 -18
- package/package.json +15 -15
- package/runtime/dependency-lock.mjs +5 -1
- package/runtime/server.mjs +958 -756
- package/runtime/tooling.mjs +666 -320
- package/scripts/tooling-codegen-runtime.ts +122 -6
- package/templateFeature/ai/ai-facade.ts +3 -2
- package/templateFeature/ai/ai-image-jobs.ts +532 -0
- package/templateFeature/ai/ai-image.ts +2 -2
- package/templateFeature/ai/ai.ts +10 -0
- package/templateFeature/ai/manifest.json +2 -0
- package/templates/ai-chat/README.md +1 -0
- package/templates/ai-chat/prompt.md +1 -1
- package/templates/fullstack/README.md +1 -0
- package/templates/fullstack/prompt.md +1 -1
- package/dashboard/assets/index-C6-BpKKR.css +0 -2
package/bin/gencow.mjs
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* gencow dev — watch, auto-deploy to dev, and stream logs
|
|
11
11
|
* --local — run the local Bun development server
|
|
12
12
|
* gencow db:generate — generate migration SQL from configured schemas
|
|
13
|
+
* gencow db:upgrade-metadata — upgrade migration snapshots without generating SQL
|
|
14
|
+
* gencow db:recover-metadata — finish an interrupted snapshot upgrade
|
|
13
15
|
* gencow db:check — inspect cloud migrations without applying SQL
|
|
14
16
|
* gencow db:push — apply committed migrations to the cloud database
|
|
15
17
|
* gencow db:migrate — apply pending migrations to the running project DB
|
|
@@ -63,6 +65,7 @@ import { updateComponentReadme } from "../lib/component-readme.mjs";
|
|
|
63
65
|
import { createConfigCommand } from "../lib/config-command.mjs";
|
|
64
66
|
import { createCorsCommand } from "../lib/cors-command.mjs";
|
|
65
67
|
import { createDbCommands } from "../lib/db-command.mjs";
|
|
68
|
+
import { createDbMetadataCommands } from "../lib/db-metadata-command.mjs";
|
|
66
69
|
import { createDevCloudCommand } from "../lib/dev-cloud-command.mjs";
|
|
67
70
|
import { createDevLocalCommands } from "../lib/dev-local-command.mjs";
|
|
68
71
|
import { handleDeployReadonlySubcommand, renderDeployHelp, verifyAppReady } from "../lib/deploy-command.mjs";
|
|
@@ -75,7 +78,7 @@ import { createInitCommand } from "../lib/init-command.mjs";
|
|
|
75
78
|
import { createJobsCommand } from "../lib/jobs-command.mjs";
|
|
76
79
|
import { createLogsCommand } from "../lib/logs-command.mjs";
|
|
77
80
|
import { createOriginsCommand } from "../lib/origins-command.mjs";
|
|
78
|
-
import { parseProjectSelectionArgs, setCliInvocationSelection } from "../lib/project-context.mjs";
|
|
81
|
+
import { parseProjectSelectionArgs, resolveCliInvocationSelection, setCliInvocationSelection } from "../lib/project-context.mjs";
|
|
79
82
|
import { createRuntimeCommand } from "../lib/runtime-command.mjs";
|
|
80
83
|
import { createStaticDeployRuntime } from "../lib/static-deploy-command.mjs";
|
|
81
84
|
import { createStaticCommand } from "../lib/static-command.mjs";
|
|
@@ -110,6 +113,9 @@ const CLI_PACKAGE_JSON = JSON.parse(readFileSync(resolve(__dirname, "..", "packa
|
|
|
110
113
|
const CLI_VERSION = CLI_PACKAGE_JSON.version || "0.0.0";
|
|
111
114
|
const CLI_SOURCE_REVISION = resolveCliArtifactSourceRevision(CLI_VERSION);
|
|
112
115
|
const _drizzleKitCmd = (subcmd, options = {}) => buildDrizzleKitCommand(subcmd, options);
|
|
116
|
+
const { dbUpgradeMetadata, dbRecoverMetadata } = createDbMetadataCommands({
|
|
117
|
+
loadConfig, buildEnv, drizzleKitCmdImpl: _drizzleKitCmd, infoImpl: info, logImpl: log,
|
|
118
|
+
});
|
|
113
119
|
const generateApiTs = createApiCodegenRuntime({
|
|
114
120
|
cliVersion: CLI_VERSION,
|
|
115
121
|
sourceRevision: CLI_SOURCE_REVISION,
|
|
@@ -346,32 +352,21 @@ const runTemplatesCommand = createTemplateMarketplaceCommand();
|
|
|
346
352
|
// ─── Commands ─────────────────────────────────────────────
|
|
347
353
|
|
|
348
354
|
const commands = {
|
|
349
|
-
// ── init ─────────────────────────────────────────────
|
|
350
355
|
init: runInitCommand,
|
|
351
|
-
|
|
352
|
-
// ── db:reset ─────────────────────────────────────────
|
|
353
356
|
"db:reset": runDbResetCommand,
|
|
354
|
-
|
|
355
|
-
// ── db:seed ──────────────────────────────────────────
|
|
356
357
|
"db:seed": runDbSeedCommand,
|
|
357
|
-
|
|
358
|
-
// ── db:restore ───────────────────────────────────────
|
|
359
358
|
"db:restore": runDbRestoreCommand,
|
|
360
|
-
|
|
361
|
-
// ── dev ──────────────────────────────────────────────
|
|
362
359
|
dev: runDevCommand,
|
|
363
360
|
|
|
364
|
-
// ── dev:local (로컬 PGlite + hot-reload) ─────────────
|
|
365
361
|
"dev:local": runDevLocalCommand,
|
|
366
362
|
|
|
367
|
-
// ── db:push ──────────────────────────────────────────
|
|
368
363
|
"db:push": runDbPushCommand,
|
|
369
364
|
|
|
370
|
-
// ── db:check ─────────────────────────────────────────
|
|
371
365
|
"db:check": runDbCheckCommand,
|
|
372
366
|
|
|
373
|
-
// ── db:generate ──────────────────────────────────────
|
|
374
367
|
"db:generate": runDbGenerateCommand,
|
|
368
|
+
"db:upgrade-metadata": dbUpgradeMetadata,
|
|
369
|
+
"db:recover-metadata": dbRecoverMetadata,
|
|
375
370
|
|
|
376
371
|
// ── db:migrate ───────────────────────────────────────
|
|
377
372
|
"db:migrate": runDbMigrateCommand,
|
|
@@ -423,6 +418,8 @@ ${BOLD}Commands (login required):${RESET}
|
|
|
423
418
|
${GREEN}db:check${RESET} Audit cloud migrations without applying DDL
|
|
424
419
|
${DIM}--prod Check production DB without mutation${RESET}
|
|
425
420
|
${GREEN}db:generate${RESET} Generate SQL migration files from schema.ts
|
|
421
|
+
${GREEN}db:upgrade-metadata${RESET} Upgrade local migration snapshots
|
|
422
|
+
${GREEN}db:recover-metadata${RESET} Finish an interrupted migration snapshot upgrade
|
|
426
423
|
${GREEN}db:seed${RESET} Run gencow/seed.ts on cloud app
|
|
427
424
|
${DIM}--prod Seed production app (confirmation required)${RESET}
|
|
428
425
|
${GREEN}static [dir]${RESET} Deploy static files only ${DIM}(dist/, out/, build/)${RESET}
|
|
@@ -579,7 +576,7 @@ ${BOLD}Examples:${RESET}
|
|
|
579
576
|
|
|
580
577
|
const [, , rawCmd = "help", ...rawArgs] = process.argv;
|
|
581
578
|
const globalProjectSelection = parseProjectSelectionArgs(rawArgs);
|
|
582
|
-
setCliInvocationSelection(globalProjectSelection);
|
|
579
|
+
setCliInvocationSelection(resolveCliInvocationSelection(globalProjectSelection, process.cwd()));
|
|
583
580
|
const args = [...globalProjectSelection.remainingArgs];
|
|
584
581
|
const cmd =
|
|
585
582
|
rawCmd === "--help" || rawCmd === "-h"
|
package/core/index.js
CHANGED
|
@@ -4030,6 +4030,7 @@ var RESERVED_TENANT_RUNTIME_ENV_KEYS = [
|
|
|
4030
4030
|
"DATABASE_URL",
|
|
4031
4031
|
"GENCOW_DB_URL",
|
|
4032
4032
|
"BETTER_AUTH_SECRET",
|
|
4033
|
+
"GENCOW_PLATFORM_AUTH_SECRET",
|
|
4033
4034
|
"BETTER_AUTH_URL",
|
|
4034
4035
|
"IS_PLATFORM",
|
|
4035
4036
|
"GENCOW_PLATFORM_CONFIG_FILE",
|
|
@@ -4107,6 +4108,7 @@ var RESERVED_TENANT_RUNTIME_ENV_KEYS = [
|
|
|
4107
4108
|
"GENCOW_INTERNAL_TOKEN",
|
|
4108
4109
|
"GENCOW_CRON_TOKEN",
|
|
4109
4110
|
"GENCOW_SCHEDULED_JOB_PUBLIC_KEY",
|
|
4111
|
+
"GENCOW_TRUSTED_CLIENT_ADDRESS_PEERS",
|
|
4110
4112
|
"GENCOW_DEPLOY_ID",
|
|
4111
4113
|
"GENCOW_AI_PROXY_URL",
|
|
4112
4114
|
"GENCOW_AI_PROXY_URL_ALT",
|
|
@@ -4119,6 +4121,7 @@ var RESERVED_TENANT_RUNTIME_ENV_KEYS = [
|
|
|
4119
4121
|
"GENCOW_SHUTDOWN_MARKER_PATH",
|
|
4120
4122
|
"GENCOW_SKIP_MIGRATION",
|
|
4121
4123
|
"GENCOW_DB_MAX_CONNECTIONS",
|
|
4124
|
+
"GENCOW_DB_SYSTEM_MAX_CONNECTIONS",
|
|
4122
4125
|
"GENCOW_DB_POOL_POLICY_VERSION",
|
|
4123
4126
|
"GENCOW_DB_IDLE_TIMEOUT_SECONDS",
|
|
4124
4127
|
"GENCOW_DB_CONNECTION_TIMEOUT_SECONDS",
|
|
@@ -4604,7 +4607,7 @@ var unsupportedByReason = {
|
|
|
4604
4607
|
},
|
|
4605
4608
|
relations: {
|
|
4606
4609
|
message: "This relational builder is not from the verified Drizzle v1 integration.",
|
|
4607
|
-
retryPrecondition: "Check the installed version with `pnpm why drizzle-orm`; use verified drizzle-orm
|
|
4610
|
+
retryPrecondition: "Check the installed version with `pnpm why drizzle-orm`; use verified drizzle-orm 1.0.0-rc.4 or 1.0.0-rc.5 without custom relational builders before retrying."
|
|
4608
4611
|
},
|
|
4609
4612
|
session: {
|
|
4610
4613
|
message: "This Drizzle session cannot be safely bound to the transaction-scoped RLS client.",
|
|
@@ -4639,8 +4642,8 @@ function matchingRlsExecutionClient(scope) {
|
|
|
4639
4642
|
const active = activeRlsExecution.getStore();
|
|
4640
4643
|
return active?.active && active.scope === scope ? active.client : void 0;
|
|
4641
4644
|
}
|
|
4642
|
-
async function runWithRlsScope(scope, client, work) {
|
|
4643
|
-
const active = { scope, client, active: true };
|
|
4645
|
+
async function runWithRlsScope(scope, client, work, holdsQueue = false) {
|
|
4646
|
+
const active = { scope, client, active: true, holdsQueue };
|
|
4644
4647
|
return activeRlsExecution.run(active, async () => {
|
|
4645
4648
|
try {
|
|
4646
4649
|
return await work();
|
|
@@ -4649,6 +4652,48 @@ async function runWithRlsScope(scope, client, work) {
|
|
|
4649
4652
|
}
|
|
4650
4653
|
});
|
|
4651
4654
|
}
|
|
4655
|
+
var contextBoundBuilders = /* @__PURE__ */ new WeakSet();
|
|
4656
|
+
function isNativePromiseOrArray(value) {
|
|
4657
|
+
return value instanceof Promise || Array.isArray(value);
|
|
4658
|
+
}
|
|
4659
|
+
function isThenable(value) {
|
|
4660
|
+
return value !== null && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
4661
|
+
}
|
|
4662
|
+
function isQueryStage(value) {
|
|
4663
|
+
const stage = value;
|
|
4664
|
+
return ["from", "values", "set", "select"].some((key) => typeof stage[key] === "function");
|
|
4665
|
+
}
|
|
4666
|
+
function bindLazyQueryToRlsContext(value) {
|
|
4667
|
+
if (value === null || typeof value !== "object") return value;
|
|
4668
|
+
const store = activeRlsExecution.getStore();
|
|
4669
|
+
if (!store?.active) return value;
|
|
4670
|
+
return bindToStore(value, store);
|
|
4671
|
+
}
|
|
4672
|
+
function bindToStore(value, store) {
|
|
4673
|
+
if (isNativePromiseOrArray(value) || contextBoundBuilders.has(value)) return value;
|
|
4674
|
+
if (!isThenable(value) && !isQueryStage(value)) return value;
|
|
4675
|
+
const proxy = new Proxy(value, {
|
|
4676
|
+
get(target, prop, receiver) {
|
|
4677
|
+
const member = Reflect.get(target, prop, receiver);
|
|
4678
|
+
if (typeof member !== "function" || typeof prop === "symbol" || prop === "constructor") return member;
|
|
4679
|
+
if (prop !== "then" && Function.prototype.toString.call(member).startsWith("class")) return member;
|
|
4680
|
+
if (prop === "then") {
|
|
4681
|
+
return (...args) => {
|
|
4682
|
+
const current = activeRlsExecution.getStore();
|
|
4683
|
+
if (current?.active || !store.active) return Reflect.apply(member, receiver, args);
|
|
4684
|
+
return activeRlsExecution.run(store, () => Reflect.apply(member, receiver, args));
|
|
4685
|
+
};
|
|
4686
|
+
}
|
|
4687
|
+
return (...args) => {
|
|
4688
|
+
const out = Reflect.apply(member, receiver, args);
|
|
4689
|
+
if (out === receiver || out === null || typeof out !== "object") return out;
|
|
4690
|
+
return bindToStore(out, store);
|
|
4691
|
+
};
|
|
4692
|
+
}
|
|
4693
|
+
});
|
|
4694
|
+
contextBoundBuilders.add(proxy);
|
|
4695
|
+
return proxy;
|
|
4696
|
+
}
|
|
4652
4697
|
function runWithRlsTransactionScope(scope, tx, work) {
|
|
4653
4698
|
assertRlsScopeMayEnter(scope);
|
|
4654
4699
|
return runWithRlsScope(scope, tx.session?.client, work);
|
|
@@ -4678,12 +4723,12 @@ function createRlsRelationalQueryRegistry(query2, session, baseSession) {
|
|
|
4678
4723
|
Object.defineProperties(scopedBuilder, {
|
|
4679
4724
|
findMany: {
|
|
4680
4725
|
value: function(config) {
|
|
4681
|
-
return Reflect.apply(trustedFindMany, this, [config]);
|
|
4726
|
+
return bindLazyQueryToRlsContext(Reflect.apply(trustedFindMany, this, [config]));
|
|
4682
4727
|
}
|
|
4683
4728
|
},
|
|
4684
4729
|
findFirst: {
|
|
4685
4730
|
value: function(config) {
|
|
4686
|
-
return Reflect.apply(trustedFindFirst, this, [config]);
|
|
4731
|
+
return bindLazyQueryToRlsContext(Reflect.apply(trustedFindFirst, this, [config]));
|
|
4687
4732
|
}
|
|
4688
4733
|
}
|
|
4689
4734
|
});
|
|
@@ -4812,14 +4857,41 @@ async function withRlsLeasedConnection(leased, rls, fn, scope) {
|
|
|
4812
4857
|
leased.release();
|
|
4813
4858
|
}
|
|
4814
4859
|
}
|
|
4815
|
-
|
|
4860
|
+
var outerConnectionQueues = /* @__PURE__ */ new WeakMap();
|
|
4861
|
+
async function withOuterConnectionExclusive(client, work) {
|
|
4862
|
+
if (!client || typeof client !== "object" && typeof client !== "function") return work();
|
|
4863
|
+
const key = client;
|
|
4864
|
+
const previous = outerConnectionQueues.get(key) ?? Promise.resolve();
|
|
4865
|
+
let release;
|
|
4866
|
+
const mine = new Promise((resolve) => {
|
|
4867
|
+
release = resolve;
|
|
4868
|
+
});
|
|
4869
|
+
const tail = previous.then(() => mine);
|
|
4870
|
+
outerConnectionQueues.set(key, tail);
|
|
4871
|
+
await previous.catch(() => void 0);
|
|
4872
|
+
try {
|
|
4873
|
+
return await work();
|
|
4874
|
+
} finally {
|
|
4875
|
+
release();
|
|
4876
|
+
if (outerConnectionQueues.get(key) === tail) outerConnectionQueues.delete(key);
|
|
4877
|
+
}
|
|
4878
|
+
}
|
|
4879
|
+
async function withRlsConnection(session, rls, reuseOuterConnection, scope, fn, queueKey) {
|
|
4816
4880
|
assertRlsScopeMayEnter(scope);
|
|
4817
4881
|
if (reuseOuterConnection) {
|
|
4818
4882
|
const c2 = session.client;
|
|
4819
|
-
return
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4883
|
+
return withOuterConnectionExclusive(
|
|
4884
|
+
queueKey ?? c2,
|
|
4885
|
+
() => runWithRlsScope(
|
|
4886
|
+
scope,
|
|
4887
|
+
c2,
|
|
4888
|
+
async () => {
|
|
4889
|
+
await applyRlsSessionVars(c2, rls);
|
|
4890
|
+
return fn(c2);
|
|
4891
|
+
},
|
|
4892
|
+
true
|
|
4893
|
+
)
|
|
4894
|
+
);
|
|
4823
4895
|
}
|
|
4824
4896
|
const c = session.client;
|
|
4825
4897
|
const runInner = async (client) => runWithRlsScope(scope, client, async () => {
|
|
@@ -4845,7 +4917,10 @@ function createClientBoundSession(session, client) {
|
|
|
4845
4917
|
return client;
|
|
4846
4918
|
}
|
|
4847
4919
|
const value = Reflect.get(target, prop, receiver);
|
|
4848
|
-
|
|
4920
|
+
if (typeof value !== "function") return value;
|
|
4921
|
+
const bound = value.bind(receiver);
|
|
4922
|
+
if (typeof prop === "symbol" || prop === "constructor") return bound;
|
|
4923
|
+
return (...args) => bindLazyQueryToRlsContext(bound(...args));
|
|
4849
4924
|
}
|
|
4850
4925
|
});
|
|
4851
4926
|
}
|
|
@@ -4875,9 +4950,9 @@ function createPreparedQueryClientExecutors(params) {
|
|
|
4875
4950
|
params.prepareArgs
|
|
4876
4951
|
);
|
|
4877
4952
|
}
|
|
4878
|
-
async function runPreparedQueryWithRls(session, rls, reuseOuterConnection, scope, runOnClient, placeholderValues) {
|
|
4953
|
+
async function runPreparedQueryWithRls(session, rls, reuseOuterConnection, scope, queueKey, runOnClient, placeholderValues) {
|
|
4879
4954
|
const active = currentRlsExecution(scope);
|
|
4880
|
-
if (active) {
|
|
4955
|
+
if (active && (active.holdsQueue || !reuseOuterConnection)) {
|
|
4881
4956
|
return runOnClient(active.client, placeholderValues);
|
|
4882
4957
|
}
|
|
4883
4958
|
return withRlsConnection(
|
|
@@ -4885,10 +4960,11 @@ async function runPreparedQueryWithRls(session, rls, reuseOuterConnection, scope
|
|
|
4885
4960
|
rls,
|
|
4886
4961
|
reuseOuterConnection,
|
|
4887
4962
|
scope,
|
|
4888
|
-
(client) => runOnClient(client, placeholderValues)
|
|
4963
|
+
(client) => runOnClient(client, placeholderValues),
|
|
4964
|
+
queueKey
|
|
4889
4965
|
);
|
|
4890
4966
|
}
|
|
4891
|
-
function wrapPreparedQuery(pq, session, baseSession, prepareQuery, prepareArgs, rls, reuseOuterConnection, scope) {
|
|
4967
|
+
function wrapPreparedQuery(pq, session, baseSession, prepareQuery, prepareArgs, rls, reuseOuterConnection, scope, queueKey) {
|
|
4892
4968
|
const clientExecutors = createPreparedQueryClientExecutors({
|
|
4893
4969
|
pq,
|
|
4894
4970
|
baseSession,
|
|
@@ -4900,6 +4976,7 @@ function wrapPreparedQuery(pq, session, baseSession, prepareQuery, prepareArgs,
|
|
|
4900
4976
|
rls,
|
|
4901
4977
|
reuseOuterConnection,
|
|
4902
4978
|
scope,
|
|
4979
|
+
queueKey,
|
|
4903
4980
|
clientExecutors.execute,
|
|
4904
4981
|
placeholderValues
|
|
4905
4982
|
);
|
|
@@ -4909,12 +4986,13 @@ function wrapPreparedQuery(pq, session, baseSession, prepareQuery, prepareArgs,
|
|
|
4909
4986
|
rls,
|
|
4910
4987
|
reuseOuterConnection,
|
|
4911
4988
|
scope,
|
|
4989
|
+
queueKey,
|
|
4912
4990
|
clientExecutors.all,
|
|
4913
4991
|
placeholderValues
|
|
4914
4992
|
);
|
|
4915
4993
|
}
|
|
4916
4994
|
}
|
|
4917
|
-
function wrapSession(session, rls, reuseOuterConnection, scope) {
|
|
4995
|
+
function wrapSession(session, rls, reuseOuterConnection, scope, queueKey) {
|
|
4918
4996
|
return new Proxy(session, {
|
|
4919
4997
|
get(sTarget, sProp, sRecv) {
|
|
4920
4998
|
if (sProp === "client") {
|
|
@@ -4925,7 +5003,7 @@ function wrapSession(session, rls, reuseOuterConnection, scope) {
|
|
|
4925
5003
|
const prepareQuery = Reflect.get(sTarget, sProp, sRecv);
|
|
4926
5004
|
if (typeof prepareQuery !== "function") throw createRlsUnsupportedError("session");
|
|
4927
5005
|
const pq = Reflect.apply(prepareQuery, sRecv, args);
|
|
4928
|
-
wrapPreparedQuery(pq, sRecv, sTarget, prepareQuery, args, rls, reuseOuterConnection, scope);
|
|
5006
|
+
wrapPreparedQuery(pq, sRecv, sTarget, prepareQuery, args, rls, reuseOuterConnection, scope, queueKey);
|
|
4929
5007
|
return pq;
|
|
4930
5008
|
};
|
|
4931
5009
|
}
|
|
@@ -4935,6 +5013,14 @@ function wrapSession(session, rls, reuseOuterConnection, scope) {
|
|
|
4935
5013
|
});
|
|
4936
5014
|
}
|
|
4937
5015
|
function createRlsDb(db, rls, options = {}) {
|
|
5016
|
+
return createRlsDbInScope(db, rls, options, createRlsScopeToken());
|
|
5017
|
+
}
|
|
5018
|
+
function wrapSharedConnectionCallbackTx(tx, rls, options, scope, queueKey) {
|
|
5019
|
+
const session = tx?.session ?? tx?._?.session;
|
|
5020
|
+
if (!session || typeof session !== "object") return tx;
|
|
5021
|
+
return createRlsDbInScope(tx, rls, options, scope, queueKey);
|
|
5022
|
+
}
|
|
5023
|
+
function createRlsDbInScope(db, rls, options, scope, inheritedQueueKey) {
|
|
4938
5024
|
const reuseOuterConnection = isDrizzleTransactionDb(db);
|
|
4939
5025
|
const database = db;
|
|
4940
5026
|
const baseSession = database.session ?? database._?.session;
|
|
@@ -4944,8 +5030,12 @@ function createRlsDb(db, rls, options = {}) {
|
|
|
4944
5030
|
if (hasUnpartitionedRlsCache(db, baseSession)) {
|
|
4945
5031
|
throw createRlsUnsupportedError("cache");
|
|
4946
5032
|
}
|
|
4947
|
-
const
|
|
4948
|
-
const
|
|
5033
|
+
const queueKey = reuseOuterConnection ? inheritedQueueKey ?? baseSession.client : void 0;
|
|
5034
|
+
const injectScopeOnTx = (tx) => reuseOuterConnection && queueKey ? withOuterConnectionExclusive(
|
|
5035
|
+
queueKey,
|
|
5036
|
+
() => injectRlsVarsOnTx(tx, rls, options.onTransactionContextFailure)
|
|
5037
|
+
) : injectRlsVarsOnTx(tx, rls, options.onTransactionContextFailure);
|
|
5038
|
+
const wrappedSession = wrapSession(baseSession, rls, reuseOuterConnection, scope, queueKey);
|
|
4949
5039
|
const baseQuery = Reflect.get(db, "query", db);
|
|
4950
5040
|
const scopedQuery = baseQuery && typeof baseQuery === "object" ? createRlsRelationalQueryRegistry(baseQuery, wrappedSession, baseSession) : baseQuery;
|
|
4951
5041
|
return new Proxy(db, {
|
|
@@ -4979,9 +5069,10 @@ function createRlsDb(db, rls, options = {}) {
|
|
|
4979
5069
|
return await target.transaction(
|
|
4980
5070
|
async (tx) => {
|
|
4981
5071
|
if (configStatement) await tx.execute(configStatement);
|
|
4982
|
-
await
|
|
5072
|
+
await injectScopeOnTx(tx);
|
|
4983
5073
|
callbackStarted = true;
|
|
4984
|
-
|
|
5074
|
+
const handle = reuseOuterConnection ? wrapSharedConnectionCallbackTx(tx, rls, options, scope, queueKey) : tx;
|
|
5075
|
+
return await runWithRlsTransactionScope(scope, tx, () => callback(handle));
|
|
4985
5076
|
},
|
|
4986
5077
|
...transactionArgs
|
|
4987
5078
|
);
|
|
@@ -5005,13 +5096,17 @@ function createRlsDb(db, rls, options = {}) {
|
|
|
5005
5096
|
...characteristics?.isolationLevel ? { isolationLevel: characteristics.isolationLevel } : {},
|
|
5006
5097
|
...characteristics?.readOnly ? { accessMode: "read only" } : {}
|
|
5007
5098
|
});
|
|
5008
|
-
await
|
|
5009
|
-
|
|
5099
|
+
await injectScopeOnTx(tx);
|
|
5100
|
+
const handle = reuseOuterConnection ? wrapSharedConnectionCallbackTx(tx, rls, options, scope, queueKey) : tx;
|
|
5101
|
+
return runWithRlsTransactionScope(scope, tx, () => callback(handle));
|
|
5010
5102
|
});
|
|
5011
5103
|
};
|
|
5012
5104
|
}
|
|
5013
5105
|
const value = Reflect.get(target, prop, receiver);
|
|
5014
|
-
|
|
5106
|
+
if (typeof value !== "function") return value;
|
|
5107
|
+
const bound = value.bind(receiver);
|
|
5108
|
+
if (typeof prop === "symbol" || prop === "constructor") return bound;
|
|
5109
|
+
return (...args) => bindLazyQueryToRlsContext(bound(...args));
|
|
5015
5110
|
}
|
|
5016
5111
|
});
|
|
5017
5112
|
}
|
|
@@ -6121,6 +6216,7 @@ export {
|
|
|
6121
6216
|
GencowValidationError,
|
|
6122
6217
|
JobAdmissionError,
|
|
6123
6218
|
MAX_FILE_SIZE,
|
|
6219
|
+
RESERVED_TENANT_RUNTIME_ENV_KEYS,
|
|
6124
6220
|
RLS_SESSION_KEY_RE,
|
|
6125
6221
|
RealtimeChannelEventValidationError,
|
|
6126
6222
|
STORAGE_LIST_DEFAULT_LIMIT,
|