gencow 0.1.298 → 0.2.0
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 +0 -6
- package/core/index.js +261 -1447
- package/core/package.json +1 -1
- package/dashboard/assets/{index-BnBn8uo4.js → index-DYqUzCmS.js} +3 -3
- package/dashboard/assets/index-OH2xW1ZG.css +2 -0
- package/dashboard/index.html +2 -2
- package/docs/packaging.md +14 -4
- package/lib/cli-artifact-guard.mjs +53 -3
- package/lib/cli-command-runner.d.mts +11 -0
- package/lib/cli-dev-runtime.mjs +1 -0
- package/lib/cli-project-runtime.mjs +26 -14
- package/lib/codegen-command.mjs +16 -0
- package/lib/coding-guardrails.mjs +2 -0
- package/lib/component-readme.mjs +4 -4
- package/lib/dashboard-artifact.mjs +65 -0
- package/lib/dashboard-assets.mjs +20 -0
- package/lib/db-command.mjs +121 -80
- package/lib/db-migration-command-steps.mjs +19 -16
- package/lib/db-push-command.mjs +1 -1
- package/lib/deploy-codegen-preflight.mjs +1 -0
- package/lib/deploy-cron-manifest-diagnostic.mjs +93 -0
- package/lib/deploy-failure-diagnostic.mjs +4 -43
- package/lib/deploy-route-target-rejection-diagnostic.mjs +43 -0
- package/lib/dev-cloud-command.mjs +1 -1
- package/lib/dev-local-command.mjs +19 -56
- package/lib/document-local-converter.mjs +11 -0
- package/lib/jobs-command.mjs +33 -1
- package/lib/local-dashboard-plan.mjs +60 -0
- package/lib/local-database-commands.mjs +127 -0
- package/lib/local-development-migrations.mjs +157 -0
- package/lib/local-drizzle-database.config.mjs +10 -0
- package/lib/local-runtime-features.mjs +12 -0
- package/lib/rag-selection.mjs +7 -0
- package/lib/readme-codegen.mjs +2 -2
- package/lib/runtime-local-worker.mjs +116 -0
- package/lib/runtime-mode.mjs +3 -0
- package/lib/standalone-codegen-adapter.mjs +91 -0
- package/lib/ts-codegen-import-extension.mjs +228 -19
- package/package.json +16 -9
- package/runtime/config.mjs +218 -2
- package/runtime/dependency-lock.mjs +5 -1
- package/runtime/engine/chunk-2HA4CUMS.mjs +90 -0
- package/runtime/engine/chunk-2JLO3KMM.mjs +305 -0
- package/runtime/engine/chunk-2SR2M7SR.mjs +1045 -0
- package/runtime/engine/chunk-3D7MHEUC.mjs +253 -0
- package/runtime/engine/chunk-3R7COBWG.mjs +309 -0
- package/runtime/engine/chunk-3ZKA54UW.mjs +1560 -0
- package/runtime/engine/chunk-45I4YR2J.mjs +9 -0
- package/runtime/engine/chunk-4MLRXO7F.mjs +74 -0
- package/runtime/engine/chunk-5575APCJ.mjs +215 -0
- package/runtime/engine/chunk-5GUJZQF3.mjs +114 -0
- package/runtime/engine/chunk-5MXY3T75.mjs +428 -0
- package/runtime/engine/chunk-5TACQ2US.mjs +44 -0
- package/runtime/engine/chunk-66G4YEDT.mjs +3104 -0
- package/runtime/engine/chunk-67YO53WW.mjs +1426 -0
- package/runtime/engine/chunk-6GQRM7XY.mjs +87 -0
- package/runtime/engine/chunk-6JO72SPP.mjs +68 -0
- package/runtime/engine/chunk-6W653LXI.mjs +13 -0
- package/runtime/engine/chunk-7ITSMI3S.mjs +69 -0
- package/runtime/engine/chunk-7KUJ2H2S.mjs +128 -0
- package/runtime/engine/chunk-A5BMQ5IC.mjs +45 -0
- package/runtime/engine/chunk-ADF3UR6L.mjs +428 -0
- package/runtime/engine/chunk-AEBW7XZJ.mjs +4510 -0
- package/runtime/engine/chunk-AGPQ5XIV.mjs +156 -0
- package/runtime/engine/chunk-CPU4OZSX.mjs +753 -0
- package/runtime/engine/chunk-CSWPPWBL.mjs +50 -0
- package/runtime/engine/chunk-DPWXSMWO.mjs +53 -0
- package/runtime/engine/chunk-EAIELFKU.mjs +151 -0
- package/runtime/engine/chunk-EDU5CBKT.mjs +10 -0
- package/runtime/engine/chunk-EQCTAET7.mjs +173 -0
- package/runtime/engine/chunk-EQCXDF2Z.mjs +70 -0
- package/runtime/engine/chunk-F3G4UGV4.mjs +330 -0
- package/runtime/engine/chunk-F62NUNOO.mjs +26 -0
- package/runtime/engine/chunk-FKPNIFRP.mjs +2492 -0
- package/runtime/engine/chunk-FM23RGVI.mjs +81 -0
- package/runtime/engine/chunk-FW5AK4YP.mjs +1041 -0
- package/runtime/engine/chunk-GDWYAGWV.mjs +23 -0
- package/runtime/engine/chunk-GO5PZUYW.mjs +53 -0
- package/runtime/engine/chunk-GOLP7OSG.mjs +340 -0
- package/runtime/engine/chunk-GSLM44EF.mjs +242 -0
- package/runtime/engine/chunk-GYAJ7OX2.mjs +125 -0
- package/runtime/engine/chunk-I3GWR43K.mjs +14 -0
- package/runtime/engine/chunk-IFMOTJNU.mjs +106 -0
- package/runtime/engine/chunk-IKQKBE2G.mjs +128 -0
- package/runtime/engine/chunk-ITH2NEKM.mjs +282 -0
- package/runtime/engine/chunk-J6SDRCG4.mjs +96 -0
- package/runtime/engine/chunk-JODRNM3S.mjs +29596 -0
- package/runtime/engine/chunk-JUDKX53X.mjs +137 -0
- package/runtime/engine/chunk-K2YZVPJ4.mjs +827 -0
- package/runtime/engine/chunk-KEZJUXEE.mjs +151 -0
- package/runtime/engine/chunk-KVLTJFCH.mjs +234 -0
- package/runtime/engine/chunk-KX2PRQPS.mjs +126 -0
- package/runtime/engine/chunk-LEW5ZMLR.mjs +76 -0
- package/runtime/engine/chunk-LINVSJEM.mjs +175 -0
- package/runtime/engine/chunk-M7K2ICSM.mjs +11 -0
- package/runtime/engine/chunk-MZXDXSDC.mjs +292 -0
- package/runtime/engine/chunk-N2TA2IK2.mjs +678 -0
- package/runtime/engine/chunk-N4LTCKJP.mjs +695 -0
- package/runtime/engine/chunk-N6GCLOUX.mjs +13 -0
- package/runtime/engine/chunk-NAG2OXS5.mjs +37 -0
- package/runtime/engine/chunk-NNZ2QJUG.mjs +381 -0
- package/runtime/engine/chunk-NZPPLDNW.mjs +15 -0
- package/runtime/engine/chunk-ODWM57W6.mjs +138 -0
- package/runtime/engine/chunk-P5IIXAIE.mjs +23 -0
- package/runtime/engine/chunk-PBOXB2BV.mjs +6 -0
- package/runtime/engine/chunk-PMOJLN2P.mjs +8 -0
- package/runtime/engine/chunk-PZFMKFHO.mjs +180 -0
- package/runtime/engine/chunk-QL2TQX2N.mjs +114 -0
- package/runtime/engine/chunk-RITT2RSJ.mjs +258 -0
- package/runtime/engine/chunk-RODBVJ5M.mjs +135 -0
- package/runtime/engine/chunk-RW65MPVY.mjs +261 -0
- package/runtime/engine/chunk-S67UYPB6.mjs +25 -0
- package/runtime/engine/chunk-SVJCOUI3.mjs +47 -0
- package/runtime/engine/chunk-TCN3ZASV.mjs +957 -0
- package/runtime/engine/chunk-U2NRG6KC.mjs +32 -0
- package/runtime/engine/chunk-UM3F7HUV.mjs +432 -0
- package/runtime/engine/chunk-VWU7JJ3P.mjs +146 -0
- package/runtime/engine/chunk-WDTKPPMU.mjs +310 -0
- package/runtime/engine/chunk-WJOO4XTB.mjs +31 -0
- package/runtime/engine/chunk-XNFVL2OY.mjs +63 -0
- package/runtime/engine/chunk-XPWJXP2J.mjs +58 -0
- package/runtime/engine/chunk-Y3HSBJ3I.mjs +1132 -0
- package/runtime/engine/chunk-YMH4RYSX.mjs +317 -0
- package/runtime/engine/chunk-YNOMPSGS.mjs +8 -0
- package/runtime/engine/chunk-YRBAYTEZ.mjs +251 -0
- package/runtime/engine/chunk-YRHM272W.mjs +528 -0
- package/runtime/engine/chunk-ZQUZAGIQ.mjs +149 -0
- package/runtime/engine/chunk-ZXMM7QFP.mjs +176 -0
- package/runtime/engine/chunk-ZZJSIPV2.mjs +262 -0
- package/runtime/engine/composition.mjs +325 -0
- package/runtime/engine/document-local.mjs +504 -0
- package/runtime/engine/graph.json +4134 -0
- package/runtime/engine/index.mjs +265 -0
- package/runtime/engine/local-postgres-support.mjs +69 -0
- package/runtime/engine/local.mjs +3275 -0
- package/runtime/engine/pglite-directory-lock.mjs +8 -0
- package/runtime/engine/rag.mjs +11 -0
- package/runtime/engine/search.mjs +18 -0
- package/runtime/framework-migrations/foundation-bootstrap/rag.sql +115 -0
- package/runtime/framework-migrations/foundation-bootstrap/workflow.sql +194 -0
- package/runtime/framework-migrations/journal-bootstrap/migration.sql +26 -0
- package/runtime/framework-migrations/manifest.json +56 -0
- package/runtime/framework-migrations/rag/20261006111509_mushy_warhawk/migration.sql +121 -0
- package/runtime/framework-migrations/rag/20261013234621_rag_v2_lifecycle_markers/migration.sql +6 -0
- package/runtime/framework-migrations/workflow/20261006111508_perpetual_star_brand/migration.sql +31 -0
- package/runtime/runtime-metadata.json +27 -0
- package/runtime/tooling.mjs +10549 -10543
- package/scripts/bundle-runtime-config.mjs +23 -0
- package/scripts/bundle-runtime.mjs +100 -0
- package/scripts/bundle-runtime.test.mjs +33 -0
- package/scripts/bundle-shared.mjs +3 -0
- package/scripts/copy-dashboard.mjs +16 -0
- package/scripts/pre-publish-check.mjs +23 -11
- package/templateFeature/ai/ai-embedding-result.ts +82 -0
- package/templateFeature/ai/ai-facade.ts +24 -7
- package/templateFeature/ai/ai-provider.ts +17 -1
- package/templateFeature/ai/ai.ts +1 -0
- package/templateFeature/ai/manifest.json +4 -3
- package/templateFeature/reranker/manifest.json +1 -1
- package/templateFeature/reranker/reranker.ts +4 -3
- package/templateFeature/sso/sso-auth-callback.tsx +37 -5
- package/templateFeature/tools/manifest.json +2 -1
- package/templateFeature/tools/tools.ts +3 -3
- package/dashboard/assets/index-C6-BpKKR.css +0 -2
- package/runtime/server.mjs +0 -14320
- package/scripts/bundle-server.mjs +0 -223
- package/server/config.js +0 -1
- package/server/index.js +0 -1
- package/server/package.json +0 -6
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertRuntimeDatabaseSchemaReady,
|
|
3
|
+
createRuntimeDatabaseSchemaCoordinator
|
|
4
|
+
} from "./chunk-KEZJUXEE.mjs";
|
|
5
|
+
import "./chunk-N2TA2IK2.mjs";
|
|
6
|
+
import "./chunk-WDTKPPMU.mjs";
|
|
7
|
+
import "./chunk-NAG2OXS5.mjs";
|
|
8
|
+
import {
|
|
9
|
+
admitRuntimeDatabaseSchemaPlan
|
|
10
|
+
} from "./chunk-3D7MHEUC.mjs";
|
|
11
|
+
import {
|
|
12
|
+
runtimeDatabaseSetupError,
|
|
13
|
+
runtimeDatabaseSetupInterrupted
|
|
14
|
+
} from "./chunk-SVJCOUI3.mjs";
|
|
15
|
+
import "./chunk-IKQKBE2G.mjs";
|
|
16
|
+
import "./chunk-IFMOTJNU.mjs";
|
|
17
|
+
import "./chunk-AEBW7XZJ.mjs";
|
|
18
|
+
|
|
19
|
+
// ../runtime/dist/database-setup/resource-owner.js
|
|
20
|
+
import { isDeepStrictEqual } from "node:util";
|
|
21
|
+
function createRuntimeDatabaseSchemaResourceOwner(input) {
|
|
22
|
+
const database = input.database, binding = Object.freeze({ ...input.binding }), port = input.port;
|
|
23
|
+
let coordinator;
|
|
24
|
+
let closed = false;
|
|
25
|
+
function prepare(components, signal) {
|
|
26
|
+
if (closed)
|
|
27
|
+
return coordinator ? coordinator.ready() : Promise.reject(runtimeDatabaseSetupInterrupted(AbortSignal.abort()));
|
|
28
|
+
if (!coordinator)
|
|
29
|
+
coordinator = createRuntimeDatabaseSchemaCoordinator({ database, binding, port, components, signal });
|
|
30
|
+
else if (!isDeepStrictEqual(coordinator.plan, admitRuntimeDatabaseSchemaPlan(components)))
|
|
31
|
+
return Promise.reject(runtimeDatabaseSetupError("RUNTIME_DATABASE_SETUP_COMPONENT_INVALID"));
|
|
32
|
+
return coordinator.ready();
|
|
33
|
+
}
|
|
34
|
+
return Object.freeze({
|
|
35
|
+
prepare,
|
|
36
|
+
async require(component) {
|
|
37
|
+
const ready = coordinator ? await coordinator.ready() : await prepare([component]);
|
|
38
|
+
assertRuntimeDatabaseSchemaReady(ready, database, binding, [
|
|
39
|
+
{ id: component.id, contractVersion: component.contractVersion }
|
|
40
|
+
]);
|
|
41
|
+
},
|
|
42
|
+
async close() {
|
|
43
|
+
closed = true;
|
|
44
|
+
await coordinator?.close();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
createRuntimeDatabaseSchemaResourceOwner
|
|
50
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RuntimeCompositionError
|
|
3
|
+
} from "./chunk-IFMOTJNU.mjs";
|
|
4
|
+
|
|
5
|
+
// ../runtime/dist/app/host.js
|
|
6
|
+
import { randomUUID } from "node:crypto";
|
|
7
|
+
var RUNTIME_MINIMUM_BUN_VERSION = "1.4.2";
|
|
8
|
+
function assertRuntimeHost() {
|
|
9
|
+
const version = process.versions.bun;
|
|
10
|
+
const supported = typeof Bun !== "undefined" && typeof version === "string";
|
|
11
|
+
const code = supported ? "RUNTIME_HOST_VERSION_UNSUPPORTED" : "RUNTIME_HOST_UNSUPPORTED";
|
|
12
|
+
if (supported) {
|
|
13
|
+
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);
|
|
14
|
+
if (match) {
|
|
15
|
+
const [major, minor, patch] = match.slice(1).map(Number);
|
|
16
|
+
const [minimumMajor, minimumMinor, minimumPatch] = RUNTIME_MINIMUM_BUN_VERSION.split(".").map(Number);
|
|
17
|
+
if (major > minimumMajor || major === minimumMajor && (minor > minimumMinor || minor === minimumMinor && patch >= minimumPatch))
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const nextAction = supported ? `Install Bun ${RUNTIME_MINIMUM_BUN_VERSION} or later, then rerun the same launch.` : `Use Bun ${RUNTIME_MINIMUM_BUN_VERSION} or later; launch generated output with \`bun .gencow/generated/entrypoint.mjs\`.`;
|
|
22
|
+
throw new RuntimeCompositionError({
|
|
23
|
+
code,
|
|
24
|
+
stage: "startup",
|
|
25
|
+
servingStarted: false,
|
|
26
|
+
dataImpact: "none",
|
|
27
|
+
retryable: false,
|
|
28
|
+
retryPrecondition: `Run the same bootstrap using Bun ${RUNTIME_MINIMUM_BUN_VERSION} or later.`,
|
|
29
|
+
nextAction,
|
|
30
|
+
correlationId: randomUUID()
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ../runtime/dist/workflow/completion-transaction.js
|
|
35
|
+
var owners = /* @__PURE__ */ new WeakMap();
|
|
36
|
+
function registerWorkflowCompletionOwner(database, owner) {
|
|
37
|
+
owners.set(database, owner);
|
|
38
|
+
}
|
|
39
|
+
function withWorkflowCompletionTransaction(database, runId, execute) {
|
|
40
|
+
const owner = owners.get(database);
|
|
41
|
+
if (owner)
|
|
42
|
+
return owner.run(runId, (tx) => execute(tx, tx.armDeadline, tx.prepare));
|
|
43
|
+
return database.transaction((tx) => execute(tx, async () => {
|
|
44
|
+
}, async () => {
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
RUNTIME_MINIMUM_BUN_VERSION,
|
|
50
|
+
assertRuntimeHost,
|
|
51
|
+
registerWorkflowCompletionOwner,
|
|
52
|
+
withWorkflowCompletionTransaction
|
|
53
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RuntimeDatabaseRlsError
|
|
3
|
+
} from "./chunk-AEBW7XZJ.mjs";
|
|
4
|
+
|
|
5
|
+
// ../runtime/dist/adapters/database/postgres-driver-config.js
|
|
6
|
+
var MAINTENANCE_POOL_MAX = 4;
|
|
7
|
+
var supported = /* @__PURE__ */ new Set([
|
|
8
|
+
"max",
|
|
9
|
+
"idle_timeout",
|
|
10
|
+
"connect_timeout",
|
|
11
|
+
"sslmode",
|
|
12
|
+
"ssl",
|
|
13
|
+
"sslrootcert",
|
|
14
|
+
"sslnegotiation",
|
|
15
|
+
"application_name",
|
|
16
|
+
"prepare",
|
|
17
|
+
"debug",
|
|
18
|
+
"TimeZone",
|
|
19
|
+
"timezone",
|
|
20
|
+
"DateStyle",
|
|
21
|
+
"datestyle",
|
|
22
|
+
"search_path",
|
|
23
|
+
"statement_timeout",
|
|
24
|
+
"lock_timeout",
|
|
25
|
+
"idle_in_transaction_session_timeout",
|
|
26
|
+
"client_encoding"
|
|
27
|
+
]);
|
|
28
|
+
var retired = /* @__PURE__ */ new Set([
|
|
29
|
+
"max_lifetime",
|
|
30
|
+
"target_session_attrs",
|
|
31
|
+
"keep_alive",
|
|
32
|
+
"backoff",
|
|
33
|
+
"max_pipeline",
|
|
34
|
+
"fetch_types",
|
|
35
|
+
"publications",
|
|
36
|
+
"options"
|
|
37
|
+
]);
|
|
38
|
+
function invalid(option) {
|
|
39
|
+
const name = option && (supported.has(option) || retired.has(option)) ? `PostgreSQL option ${option}` : "unrecognized PostgreSQL option or login binding";
|
|
40
|
+
throw new RuntimeDatabaseRlsError("RUNTIME_DATABASE_RLS_ROLE_CONFIG_INVALID", "startup", `Remove or replace the ${name} using the documented Bun PostgreSQL option mapping, then restart. Neither database client opened; serving and data are unchanged.`);
|
|
41
|
+
}
|
|
42
|
+
function duration(query, key, fallback, positive = false) {
|
|
43
|
+
const raw = query.get(key);
|
|
44
|
+
const value = raw === null ? fallback : raw === "disable" || raw === "false" ? 0 : Number(raw);
|
|
45
|
+
if (raw === "" || !Number.isFinite(value) || value < 0 || value > 2147483 || positive && value === 0)
|
|
46
|
+
invalid(key);
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
function count(query) {
|
|
50
|
+
const value = query.has("max") ? Number(query.get("max")) : 10;
|
|
51
|
+
if (!Number.isSafeInteger(value) || value <= 0 || value > 2147483647)
|
|
52
|
+
invalid("max");
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
function ssl(query) {
|
|
56
|
+
const root = query.get("sslrootcert");
|
|
57
|
+
if (root !== null && root !== "system")
|
|
58
|
+
invalid("sslrootcert");
|
|
59
|
+
if (root === "system")
|
|
60
|
+
return "verify-full";
|
|
61
|
+
const value = query.get("sslmode") ?? query.get("ssl") ?? "disable";
|
|
62
|
+
switch (value) {
|
|
63
|
+
case "disable":
|
|
64
|
+
case "false":
|
|
65
|
+
case "0":
|
|
66
|
+
return "disable";
|
|
67
|
+
case "true":
|
|
68
|
+
case "1":
|
|
69
|
+
case "verify-full":
|
|
70
|
+
return "verify-full";
|
|
71
|
+
case "require":
|
|
72
|
+
case "prefer":
|
|
73
|
+
return value;
|
|
74
|
+
default:
|
|
75
|
+
return invalid(query.has("sslmode") ? "sslmode" : "ssl");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function timeout(value, option) {
|
|
79
|
+
const match = /^\s*(\d+(?:\.\d+)?)\s*(us|ms|s|min|h|d)?\s*$/u.exec(value);
|
|
80
|
+
const units = { us: 1e-3, ms: 1, s: 1e3, min: 6e4, h: 36e5, d: 864e5 };
|
|
81
|
+
if (!match || Number(match[1]) * units[match[2] ?? "ms"] > 2147483647)
|
|
82
|
+
invalid(option);
|
|
83
|
+
}
|
|
84
|
+
function resolveRuntimePostgresDriverConfig(databaseUrl, workload = "application") {
|
|
85
|
+
let url, username, password, database;
|
|
86
|
+
try {
|
|
87
|
+
url = new URL(databaseUrl);
|
|
88
|
+
username = decodeURIComponent(url.username);
|
|
89
|
+
password = decodeURIComponent(url.password);
|
|
90
|
+
database = decodeURIComponent(url.pathname.slice(1));
|
|
91
|
+
} catch {
|
|
92
|
+
return invalid();
|
|
93
|
+
}
|
|
94
|
+
if (!["postgres:", "postgresql:"].includes(url.protocol) || !url.hostname || !username || !database || url.hash || [username, password, database].some((value) => value.includes("\0")))
|
|
95
|
+
invalid();
|
|
96
|
+
const query = url.searchParams;
|
|
97
|
+
const seen = /* @__PURE__ */ new Set();
|
|
98
|
+
for (const [key, value] of query) {
|
|
99
|
+
if (!supported.has(key) || seen.has(key) || value.includes("\0"))
|
|
100
|
+
invalid(key);
|
|
101
|
+
seen.add(key);
|
|
102
|
+
}
|
|
103
|
+
for (const key of ["prepare", "debug"])
|
|
104
|
+
if (query.has(key) && !["false", "0", "disable"].includes(query.get(key)))
|
|
105
|
+
invalid(key);
|
|
106
|
+
if (query.has("sslnegotiation") && query.get("sslnegotiation") !== "postgres")
|
|
107
|
+
invalid("sslnegotiation");
|
|
108
|
+
if (query.has("client_encoding") && !["UTF8", "UTF-8", "utf8", "utf-8"].includes(query.get("client_encoding")))
|
|
109
|
+
invalid("client_encoding");
|
|
110
|
+
if (query.has("TimeZone") && query.has("timezone") || query.has("DateStyle") && query.has("datestyle"))
|
|
111
|
+
invalid();
|
|
112
|
+
for (const key of ["statement_timeout", "lock_timeout", "idle_in_transaction_session_timeout"])
|
|
113
|
+
if (query.has(key))
|
|
114
|
+
timeout(query.get(key), key);
|
|
115
|
+
const mode = ssl(query);
|
|
116
|
+
const requestedMax = count(query);
|
|
117
|
+
const connection = { application_name: query.get("application_name") ?? "postgres.js" };
|
|
118
|
+
for (const key of ["TimeZone", "timezone", "DateStyle", "datestyle", "search_path", "statement_timeout", "lock_timeout", "idle_in_transaction_session_timeout", "client_encoding"])
|
|
119
|
+
if (query.has(key))
|
|
120
|
+
connection[key] = query.get(key);
|
|
121
|
+
const options = {
|
|
122
|
+
adapter: "postgres",
|
|
123
|
+
hostname: url.hostname,
|
|
124
|
+
port: Number(url.port || "5432"),
|
|
125
|
+
username,
|
|
126
|
+
database,
|
|
127
|
+
// A callback avoids Bun's truthy empty-password ambient fallback on every
|
|
128
|
+
// new pooled connection without mutating process environment.
|
|
129
|
+
password: () => password,
|
|
130
|
+
max: workload === "maintenance" ? Math.min(MAINTENANCE_POOL_MAX, requestedMax) : requestedMax,
|
|
131
|
+
// Bun captures bigint decoding during SQL construction; Drizzle's later
|
|
132
|
+
// options mutation cannot change the already-created client.
|
|
133
|
+
bigint: true,
|
|
134
|
+
idleTimeout: duration(query, "idle_timeout", 0),
|
|
135
|
+
connectionTimeout: duration(query, "connect_timeout", 30, true),
|
|
136
|
+
// Bun interrupts active work at maxLifetime, unlike postgres-js idle retirement.
|
|
137
|
+
maxLifetime: 0,
|
|
138
|
+
prepare: false,
|
|
139
|
+
tls: mode === "disable" ? false : Object.freeze({ rejectUnauthorized: mode === "verify-full", serverName: url.hostname }),
|
|
140
|
+
connection: Object.freeze(connection)
|
|
141
|
+
};
|
|
142
|
+
if (!Number.isSafeInteger(options.port) || Number(options.port) < 1 || Number(options.port) > 65535)
|
|
143
|
+
invalid();
|
|
144
|
+
url.search = "";
|
|
145
|
+
url.searchParams.set("sslmode", mode);
|
|
146
|
+
return Object.freeze({ url: url.href, options: Object.freeze(options) });
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export {
|
|
150
|
+
resolveRuntimePostgresDriverConfig
|
|
151
|
+
};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import {
|
|
2
|
+
runtimeDatabaseSetupError
|
|
3
|
+
} from "./chunk-SVJCOUI3.mjs";
|
|
4
|
+
|
|
5
|
+
// ../runtime/dist/adapters/database/postgres-schema-reservation.js
|
|
6
|
+
async function withPostgresSchemaReservation(pool, signal, execute) {
|
|
7
|
+
if (signal.aborted)
|
|
8
|
+
throw runtimeDatabaseSetupError("RUNTIME_DATABASE_SETUP_FAILED");
|
|
9
|
+
const session = await pool.reserve({ signal });
|
|
10
|
+
let closing;
|
|
11
|
+
const abort = () => {
|
|
12
|
+
closing ??= session.close({ timeout: 0 });
|
|
13
|
+
void closing.catch(() => {
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
17
|
+
try {
|
|
18
|
+
if (signal.aborted)
|
|
19
|
+
abort();
|
|
20
|
+
if (closing)
|
|
21
|
+
throw runtimeDatabaseSetupError("RUNTIME_DATABASE_SETUP_FAILED");
|
|
22
|
+
return await execute(session);
|
|
23
|
+
} finally {
|
|
24
|
+
signal.removeEventListener("abort", abort);
|
|
25
|
+
if (closing)
|
|
26
|
+
await closing;
|
|
27
|
+
else
|
|
28
|
+
session.release();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ../runtime/dist/adapters/database/postgres-target-attestation.js
|
|
33
|
+
import { randomBytes } from "node:crypto";
|
|
34
|
+
function challengeKey() {
|
|
35
|
+
return randomBytes(8).readBigInt64BE().toString();
|
|
36
|
+
}
|
|
37
|
+
async function attestPostgresSchemaTarget(setup, operational, signal) {
|
|
38
|
+
const first = challengeKey();
|
|
39
|
+
let second = challengeKey();
|
|
40
|
+
while (first === second)
|
|
41
|
+
second = challengeKey();
|
|
42
|
+
const [identity] = await setup`SELECT current_user AS role, pg_catalog.current_database() AS database`;
|
|
43
|
+
if (!identity?.role || !identity.database || signal.aborted)
|
|
44
|
+
throw runtimeDatabaseSetupError("RUNTIME_DATABASE_SETUP_TARGET_MISMATCH");
|
|
45
|
+
await setup`SELECT pg_catalog.pg_advisory_xact_lock(${first}::bigint), pg_catalog.pg_advisory_xact_lock(${second}::bigint)`;
|
|
46
|
+
const roles = { application: "", maintenance: "" };
|
|
47
|
+
for (const path of ["application", "maintenance"]) {
|
|
48
|
+
await withPostgresSchemaReservation(operational[path], signal, async (probe) => {
|
|
49
|
+
let begun = false;
|
|
50
|
+
try {
|
|
51
|
+
if (probe === setup || signal.aborted)
|
|
52
|
+
throw runtimeDatabaseSetupError("RUNTIME_DATABASE_SETUP_TARGET_MISMATCH");
|
|
53
|
+
await probe.unsafe("BEGIN READ ONLY");
|
|
54
|
+
begun = true;
|
|
55
|
+
const [observation] = await probe`
|
|
56
|
+
SELECT current_user AS role, pg_catalog.current_database() AS database,
|
|
57
|
+
pg_catalog.pg_try_advisory_xact_lock(${first}::bigint) AS first,
|
|
58
|
+
pg_catalog.pg_try_advisory_xact_lock(${second}::bigint) AS second
|
|
59
|
+
`;
|
|
60
|
+
if (!observation?.role || observation.database !== identity.database || observation.first !== false || observation.second !== false || signal.aborted)
|
|
61
|
+
throw runtimeDatabaseSetupError("RUNTIME_DATABASE_SETUP_TARGET_MISMATCH");
|
|
62
|
+
roles[path] = observation.role;
|
|
63
|
+
} finally {
|
|
64
|
+
if (begun)
|
|
65
|
+
await probe.unsafe("ROLLBACK").catch((error) => {
|
|
66
|
+
if (!signal.aborted)
|
|
67
|
+
throw error;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return Object.freeze({
|
|
73
|
+
keys: Object.freeze([first, second]),
|
|
74
|
+
setupRole: identity.role,
|
|
75
|
+
database: identity.database,
|
|
76
|
+
operationalRoles: Object.freeze(roles)
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ../runtime/dist/adapters/database/postgres-schema-cancellation.js
|
|
81
|
+
function lockParts(key) {
|
|
82
|
+
const unsigned = BigInt.asUintN(64, BigInt(key));
|
|
83
|
+
return [(unsigned >> 32n).toString(), (unsigned & 0xffffffffn).toString()];
|
|
84
|
+
}
|
|
85
|
+
async function createPostgresSchemaCancellation(setup, channel, proof) {
|
|
86
|
+
if (setup === channel)
|
|
87
|
+
throw runtimeDatabaseSetupError("RUNTIME_DATABASE_SETUP_COMPONENT_INVALID");
|
|
88
|
+
const [session] = await setup`
|
|
89
|
+
SELECT pg_catalog.pg_backend_pid()::int AS pid, session_user AS actor,
|
|
90
|
+
extract(epoch FROM backend_start)::text AS started
|
|
91
|
+
FROM pg_catalog.pg_stat_activity WHERE pid=pg_catalog.pg_backend_pid()
|
|
92
|
+
`;
|
|
93
|
+
if (!session?.pid || !session.started || session.actor !== proof.setupRole)
|
|
94
|
+
throw runtimeDatabaseSetupError("RUNTIME_DATABASE_SETUP_AUTHORITY_INVALID");
|
|
95
|
+
const first = lockParts(proof.keys[0]);
|
|
96
|
+
const second = lockParts(proof.keys[1]);
|
|
97
|
+
async function guarded(cancel, deadline = null, watcher, observer = channel) {
|
|
98
|
+
const boundary = deadline === null ? "SELECT 0::float8" : "SELECT (extract(epoch FROM ($10::timestamptz-pg_catalog.clock_timestamp()))*1000)::float8 AS milliseconds";
|
|
99
|
+
const waiting = watcher ? "waiting AS MATERIALIZED (SELECT pg_catalog.pg_sleep(GREATEST(0,extract(epoch FROM ($10::timestamptz-pg_catalog.clock_timestamp())))))," : "";
|
|
100
|
+
const values = [
|
|
101
|
+
proof.database,
|
|
102
|
+
session.actor,
|
|
103
|
+
session.pid,
|
|
104
|
+
session.started,
|
|
105
|
+
first[0],
|
|
106
|
+
first[1],
|
|
107
|
+
second[0],
|
|
108
|
+
second[1],
|
|
109
|
+
cancel,
|
|
110
|
+
...deadline === null ? [] : [deadline]
|
|
111
|
+
];
|
|
112
|
+
const [result] = await (watcher ?? observer).unsafe(`
|
|
113
|
+
${watcher ? "/* gencow-completion-deadline-watch */" : ""}
|
|
114
|
+
WITH ${waiting} boundary(milliseconds) AS MATERIALIZED (${boundary}${watcher ? " FROM waiting" : ""}), target AS MATERIALIZED (
|
|
115
|
+
SELECT pg_catalog.current_database()=$1 AND session_user=$2
|
|
116
|
+
AND EXISTS (SELECT 1 FROM pg_catalog.pg_stat_activity activity WHERE activity.pid=$3
|
|
117
|
+
AND activity.usename=$2 AND activity.datname=$1
|
|
118
|
+
AND extract(epoch FROM activity.backend_start)::text=$4)
|
|
119
|
+
AND (SELECT pg_catalog.count(*) FROM pg_catalog.pg_locks held WHERE held.locktype='advisory' AND held.granted
|
|
120
|
+
AND held.pid=$3 AND held.objsubid=1
|
|
121
|
+
AND held.database=(SELECT oid FROM pg_catalog.pg_database WHERE datname=pg_catalog.current_database())
|
|
122
|
+
AND ((held.classid::bigint=$5::bigint AND held.objid::bigint=$6::bigint)
|
|
123
|
+
OR (held.classid::bigint=$7::bigint AND held.objid::bigint=$8::bigint)))=2 AS matched FROM boundary
|
|
124
|
+
) SELECT boundary.milliseconds,target.matched AS matched,
|
|
125
|
+
CASE WHEN target.matched AND $9::boolean AND boundary.milliseconds<=0
|
|
126
|
+
THEN pg_catalog.pg_cancel_backend($3) ELSE false END AS cancelled
|
|
127
|
+
FROM boundary,target
|
|
128
|
+
`, values);
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
return Object.freeze({
|
|
132
|
+
targetPid: session.pid,
|
|
133
|
+
/** Private watcher command. Its owner must attest/reserve the watcher,
|
|
134
|
+
* positively witness server execution before SDK COMMIT and join retirement.
|
|
135
|
+
* A missing/stale main proof never authorizes cancellation of successor SQL. */
|
|
136
|
+
async waitForDeadline(watcher, deadline) {
|
|
137
|
+
const row = await guarded(true, deadline, watcher);
|
|
138
|
+
if (!row || !Number.isFinite(row.milliseconds))
|
|
139
|
+
throw new Error("Owned deadline watcher unavailable");
|
|
140
|
+
return row;
|
|
141
|
+
},
|
|
142
|
+
/** A new cleanup observer must positively re-attest the still-live nonce
|
|
143
|
+
* before observing its eventual absence. Names/absence alone are not proof. */
|
|
144
|
+
matchesTargetOn: async (observer) => (await guarded(false, null, void 0, observer))?.matched === true,
|
|
145
|
+
async sessionExistsOn(observer) {
|
|
146
|
+
const row = (await observer`
|
|
147
|
+
SELECT pg_catalog.current_database()=${proof.database} AND session_user=${session.actor} AS authorized,
|
|
148
|
+
EXISTS(SELECT 1 FROM pg_catalog.pg_stat_activity WHERE pid=${session.pid}
|
|
149
|
+
AND usename=${session.actor} AND datname=${proof.database}
|
|
150
|
+
AND extract(epoch FROM backend_start)::text=${session.started}) AS present`)[0];
|
|
151
|
+
if (!row?.authorized)
|
|
152
|
+
throw new Error("Owned cleanup observer unavailable");
|
|
153
|
+
return row.present;
|
|
154
|
+
},
|
|
155
|
+
cancel: async () => (await guarded(true))?.cancelled === true,
|
|
156
|
+
/** Pin the separate channel to this target before any schema effects. */
|
|
157
|
+
matchesTarget: async () => (await guarded(false))?.matched === true,
|
|
158
|
+
/** Observe the original DB deadline and issue guarded cancellation in the
|
|
159
|
+
* same server command. A withheld clock reply cannot prevent its side effect. */
|
|
160
|
+
async observeDeadline(deadline, targetMayHaveSettled) {
|
|
161
|
+
const row = await guarded(true, deadline);
|
|
162
|
+
if (!row || !row.matched && !targetMayHaveSettled?.() || !Number.isFinite(row.milliseconds))
|
|
163
|
+
throw new Error("Owned deadline target unavailable");
|
|
164
|
+
return row.milliseconds;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export {
|
|
170
|
+
withPostgresSchemaReservation,
|
|
171
|
+
attestPostgresSchemaTarget,
|
|
172
|
+
createPostgresSchemaCancellation
|
|
173
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readRuntimeDatabaseSchemaCatalog
|
|
3
|
+
} from "./chunk-YMH4RYSX.mjs";
|
|
4
|
+
import {
|
|
5
|
+
workflowTerminalGuardSchema
|
|
6
|
+
} from "./chunk-ZXMM7QFP.mjs";
|
|
7
|
+
import {
|
|
8
|
+
workflowSchemaFailure
|
|
9
|
+
} from "./chunk-LINVSJEM.mjs";
|
|
10
|
+
import {
|
|
11
|
+
admitRuntimeDatabaseSchemaPlan
|
|
12
|
+
} from "./chunk-3D7MHEUC.mjs";
|
|
13
|
+
|
|
14
|
+
// ../runtime/dist/adapters/database/postgres-completion-fence.js
|
|
15
|
+
import { randomUUID } from "node:crypto";
|
|
16
|
+
import { sql } from "drizzle-orm";
|
|
17
|
+
var WorkflowTerminalFenceUnavailable = class extends Error {
|
|
18
|
+
cause;
|
|
19
|
+
constructor(cause) {
|
|
20
|
+
super("Owned workflow terminal fence unavailable");
|
|
21
|
+
this.cause = cause;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
async function validatePostgresCompletionFence(database) {
|
|
25
|
+
const result = await database.execute(sql`SELECT current_user::text AS actor`);
|
|
26
|
+
const rows = Array.isArray(result) ? result : result.rows;
|
|
27
|
+
const actor = rows[0]?.actor;
|
|
28
|
+
if (!actor)
|
|
29
|
+
throw workflowSchemaFailure();
|
|
30
|
+
const plan = admitRuntimeDatabaseSchemaPlan([workflowTerminalGuardSchema]);
|
|
31
|
+
const snapshot = await readRuntimeDatabaseSchemaCatalog(database, plan, {
|
|
32
|
+
application: actor,
|
|
33
|
+
maintenance: actor
|
|
34
|
+
});
|
|
35
|
+
const inspected = workflowTerminalGuardSchema.inspect(snapshot);
|
|
36
|
+
if (inspected.state === "incompatible")
|
|
37
|
+
throw workflowSchemaFailure();
|
|
38
|
+
return inspected.state === "ready";
|
|
39
|
+
}
|
|
40
|
+
async function enqueuePostgresCompletionFence(transaction, deadline, xid, pid) {
|
|
41
|
+
try {
|
|
42
|
+
await transaction`SET CONSTRAINTS public._gencow_workflow_terminal_guard_check DEFERRED`;
|
|
43
|
+
const rows = await transaction`INSERT INTO public._gencow_workflow_terminal_guard
|
|
44
|
+
(id,backend_pid,transaction_id,original_deadline)
|
|
45
|
+
SELECT ${randomUUID()}::uuid,${pid}::integer,${xid}::xid8,${deadline}::timestamptz
|
|
46
|
+
WHERE pg_catalog.pg_backend_pid()=${pid} AND pg_catalog.pg_current_xact_id()=${xid}::xid8 RETURNING id`;
|
|
47
|
+
if (rows.length !== 1)
|
|
48
|
+
throw new WorkflowTerminalFenceUnavailable();
|
|
49
|
+
} catch (error) {
|
|
50
|
+
throw new WorkflowTerminalFenceUnavailable(error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function postgresCompletionFenceExpired(error) {
|
|
54
|
+
return error instanceof Error && Reflect.get(error, "errno") === "GCW01" && error.message === "Workflow completion lease expired";
|
|
55
|
+
}
|
|
56
|
+
function postgresCompletionFenceUnavailable(error) {
|
|
57
|
+
return error instanceof Error && Reflect.get(error, "errno") === "GCW02" && [
|
|
58
|
+
"Workflow terminal fence identity unavailable",
|
|
59
|
+
"Workflow terminal fence boundary unavailable",
|
|
60
|
+
"Workflow terminal fence cleanup unavailable"
|
|
61
|
+
].includes(error.message);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export {
|
|
65
|
+
WorkflowTerminalFenceUnavailable,
|
|
66
|
+
validatePostgresCompletionFence,
|
|
67
|
+
enqueuePostgresCompletionFence,
|
|
68
|
+
postgresCompletionFenceExpired,
|
|
69
|
+
postgresCompletionFenceUnavailable
|
|
70
|
+
};
|