gencow 0.1.299 → 0.2.1
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/package.json +1 -1
- package/docs/packaging.md +14 -4
- package/lib/cli-artifact-guard.mjs +53 -3
- 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/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/dev-cloud-command.mjs +1 -1
- package/lib/dev-local-command.mjs +19 -56
- package/lib/document-local-converter.mjs +11 -0
- 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/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 +15 -8
- package/runtime/config.mjs +218 -2
- 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 +10399 -8951
- 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-facade.ts +38 -15
- package/templateFeature/ai/manifest.json +1 -0
- package/templateFeature/sso/sso-auth-callback.tsx +37 -5
- package/templateFeature/tools/manifest.json +5 -2
- package/templateFeature/tools/tools.ts +3 -3
- package/runtime/server.mjs +0 -14389
- 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,1041 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertDatabaseGeneration,
|
|
3
|
+
createManagedSchemaPreparation,
|
|
4
|
+
createPostgresGroundingCitationReader,
|
|
5
|
+
createPostgresSearchModes,
|
|
6
|
+
createSearchSessionReads,
|
|
7
|
+
runtimeDatabaseInspection
|
|
8
|
+
} from "./chunk-CPU4OZSX.mjs";
|
|
9
|
+
import {
|
|
10
|
+
loadRuntimePostgresSql
|
|
11
|
+
} from "./chunk-PMOJLN2P.mjs";
|
|
12
|
+
import {
|
|
13
|
+
WorkflowTerminalFenceUnavailable,
|
|
14
|
+
enqueuePostgresCompletionFence,
|
|
15
|
+
postgresCompletionFenceExpired,
|
|
16
|
+
postgresCompletionFenceUnavailable
|
|
17
|
+
} from "./chunk-EQCXDF2Z.mjs";
|
|
18
|
+
import "./chunk-YMH4RYSX.mjs";
|
|
19
|
+
import {
|
|
20
|
+
assertRuntimeHost,
|
|
21
|
+
registerWorkflowCompletionOwner
|
|
22
|
+
} from "./chunk-DPWXSMWO.mjs";
|
|
23
|
+
import {
|
|
24
|
+
borrowRuntimeDrizzle
|
|
25
|
+
} from "./chunk-ADF3UR6L.mjs";
|
|
26
|
+
import {
|
|
27
|
+
createPostgresRecoveryOwner,
|
|
28
|
+
createRuntimeScopedApplicationReads,
|
|
29
|
+
runtimeDatabaseExecutionScope,
|
|
30
|
+
runtimeDatabaseStopAdmissions,
|
|
31
|
+
runtimeGenerationBackedApplicationDatabase,
|
|
32
|
+
runtimeScopedApplicationReads,
|
|
33
|
+
runtimeVettedAuthRead,
|
|
34
|
+
runtimeVettedAuthReadScope
|
|
35
|
+
} from "./chunk-YRHM272W.mjs";
|
|
36
|
+
import "./chunk-P5IIXAIE.mjs";
|
|
37
|
+
import {
|
|
38
|
+
WorkflowLeaseLostError
|
|
39
|
+
} from "./chunk-5GUJZQF3.mjs";
|
|
40
|
+
import "./chunk-XNFVL2OY.mjs";
|
|
41
|
+
import "./chunk-KVLTJFCH.mjs";
|
|
42
|
+
import "./chunk-7KUJ2H2S.mjs";
|
|
43
|
+
import "./chunk-ZXMM7QFP.mjs";
|
|
44
|
+
import "./chunk-PZFMKFHO.mjs";
|
|
45
|
+
import "./chunk-LINVSJEM.mjs";
|
|
46
|
+
import "./chunk-GOLP7OSG.mjs";
|
|
47
|
+
import "./chunk-QL2TQX2N.mjs";
|
|
48
|
+
import "./chunk-LEW5ZMLR.mjs";
|
|
49
|
+
import {
|
|
50
|
+
attestPostgresSchemaTarget,
|
|
51
|
+
createPostgresSchemaCancellation
|
|
52
|
+
} from "./chunk-EQCTAET7.mjs";
|
|
53
|
+
import {
|
|
54
|
+
inspectLocalPostgresReadiness,
|
|
55
|
+
postgresStartupCapacity
|
|
56
|
+
} from "./chunk-5MXY3T75.mjs";
|
|
57
|
+
import {
|
|
58
|
+
assertTrustedLocalDatabaseSecurityPolicyMatches,
|
|
59
|
+
createRuntimeLocalDatabaseWarningSink,
|
|
60
|
+
verifyTrustedLocalDatabaseSecurityPolicy
|
|
61
|
+
} from "./chunk-ZZJSIPV2.mjs";
|
|
62
|
+
import {
|
|
63
|
+
parseRuntimePostgresBinding
|
|
64
|
+
} from "./chunk-FM23RGVI.mjs";
|
|
65
|
+
import "./chunk-ITH2NEKM.mjs";
|
|
66
|
+
import "./chunk-N2TA2IK2.mjs";
|
|
67
|
+
import {
|
|
68
|
+
snapshotRuntimeBinding
|
|
69
|
+
} from "./chunk-WDTKPPMU.mjs";
|
|
70
|
+
import {
|
|
71
|
+
resolveRuntimePostgresDriverConfig
|
|
72
|
+
} from "./chunk-EAIELFKU.mjs";
|
|
73
|
+
import "./chunk-NAG2OXS5.mjs";
|
|
74
|
+
import "./chunk-3D7MHEUC.mjs";
|
|
75
|
+
import "./chunk-SVJCOUI3.mjs";
|
|
76
|
+
import {
|
|
77
|
+
snapshotRuntimeIdentity,
|
|
78
|
+
snapshotRuntimeRls
|
|
79
|
+
} from "./chunk-IKQKBE2G.mjs";
|
|
80
|
+
import "./chunk-IFMOTJNU.mjs";
|
|
81
|
+
import "./chunk-I3GWR43K.mjs";
|
|
82
|
+
import {
|
|
83
|
+
RuntimeDatabaseRlsError,
|
|
84
|
+
RuntimeDiagnosticError,
|
|
85
|
+
createRlsDb
|
|
86
|
+
} from "./chunk-AEBW7XZJ.mjs";
|
|
87
|
+
|
|
88
|
+
// ../runtime/dist/adapters/database/postgres-readiness.js
|
|
89
|
+
import { randomUUID } from "node:crypto";
|
|
90
|
+
function startupError(code, nextAction) {
|
|
91
|
+
return new RuntimeDatabaseRlsError(code, "startup", nextAction, "none", randomUUID());
|
|
92
|
+
}
|
|
93
|
+
async function readRole(client) {
|
|
94
|
+
const rows = await client`
|
|
95
|
+
with recursive inherited_roles(role_id) as (
|
|
96
|
+
select member_role.roleid
|
|
97
|
+
from pg_catalog.pg_auth_members member_role
|
|
98
|
+
where member_role.member = (select oid from pg_catalog.pg_roles where rolname = current_user)
|
|
99
|
+
union
|
|
100
|
+
select parent.roleid
|
|
101
|
+
from pg_catalog.pg_auth_members parent
|
|
102
|
+
join inherited_roles child on parent.member = child.role_id
|
|
103
|
+
)
|
|
104
|
+
select current_user,
|
|
105
|
+
pg_catalog.current_database(),
|
|
106
|
+
roles.rolbypassrls,
|
|
107
|
+
roles.rolsuper,
|
|
108
|
+
exists(
|
|
109
|
+
select 1 from inherited_roles inherited
|
|
110
|
+
join pg_catalog.pg_roles inherited_role on inherited_role.oid = inherited.role_id
|
|
111
|
+
where inherited_role.rolbypassrls or inherited_role.rolsuper
|
|
112
|
+
) as inherited_bypass
|
|
113
|
+
from pg_catalog.pg_roles roles
|
|
114
|
+
where roles.rolname = current_user
|
|
115
|
+
`;
|
|
116
|
+
const role = rows[0];
|
|
117
|
+
if (!role)
|
|
118
|
+
throw new Error("current database role was not found");
|
|
119
|
+
return role;
|
|
120
|
+
}
|
|
121
|
+
async function applicationOwnsRlsRelation(client) {
|
|
122
|
+
const rows = await client`
|
|
123
|
+
-- PostgreSQL is the authority for membership options and transitive paths.
|
|
124
|
+
-- SET to an intermediate role can expose inherited ownership even when the
|
|
125
|
+
-- login cannot SET directly to the owner. ADMIN can grant that access too.
|
|
126
|
+
with recursive reachable_roles(oid) as (
|
|
127
|
+
select oid from pg_catalog.pg_roles where rolname = current_user
|
|
128
|
+
union
|
|
129
|
+
select role.oid from pg_catalog.pg_roles role
|
|
130
|
+
join reachable_roles actor on
|
|
131
|
+
pg_catalog.pg_has_role(actor.oid, role.oid,
|
|
132
|
+
case when pg_catalog.current_setting('server_version_num')::integer >= 160000
|
|
133
|
+
then 'SET' else 'MEMBER' end)
|
|
134
|
+
or pg_catalog.pg_has_role(actor.oid, role.oid, 'MEMBER WITH ADMIN OPTION')
|
|
135
|
+
)
|
|
136
|
+
select exists(
|
|
137
|
+
select 1
|
|
138
|
+
from pg_catalog.pg_class relation
|
|
139
|
+
join pg_catalog.pg_namespace namespace on namespace.oid = relation.relnamespace
|
|
140
|
+
where relation.relrowsecurity
|
|
141
|
+
and exists (
|
|
142
|
+
select 1 from reachable_roles candidate
|
|
143
|
+
where pg_catalog.pg_has_role(candidate.oid, relation.relowner, 'USAGE')
|
|
144
|
+
)
|
|
145
|
+
and namespace.nspname not in ('pg_catalog', 'information_schema')
|
|
146
|
+
) as unsafe
|
|
147
|
+
`;
|
|
148
|
+
return rows[0]?.unsafe === true;
|
|
149
|
+
}
|
|
150
|
+
async function assertPostgresReadiness(application, maintenance, binding, warnings, databaseSecurityPolicy) {
|
|
151
|
+
if (binding.kind === "local")
|
|
152
|
+
return inspectLocalPostgresReadiness(application, maintenance, warnings, databaseSecurityPolicy);
|
|
153
|
+
let applicationRole;
|
|
154
|
+
let maintenanceRole;
|
|
155
|
+
try {
|
|
156
|
+
[applicationRole, maintenanceRole] = await Promise.all([readRole(application), readRole(maintenance)]);
|
|
157
|
+
} catch (error) {
|
|
158
|
+
throw postgresStartupCapacity(error) ?? startupError("RUNTIME_DATABASE_RLS_ROLE_CONFIG_INVALID", "Verify both documented database role bindings can connect, then restart.");
|
|
159
|
+
}
|
|
160
|
+
if (applicationRole.current_database !== maintenanceRole.current_database) {
|
|
161
|
+
throw startupError("RUNTIME_DATABASE_RLS_ROLE_CONFIG_INVALID", "Configure application and maintenance bindings for the same database, then restart.");
|
|
162
|
+
}
|
|
163
|
+
if (applicationRole.current_user === maintenanceRole.current_user) {
|
|
164
|
+
throw startupError("RUNTIME_DATABASE_RLS_ROLE_CONFIG_INVALID", "Configure distinct application and maintenance database role bindings, then restart.");
|
|
165
|
+
}
|
|
166
|
+
if (binding.kind === "hosted" && (applicationRole.current_user !== binding.application.expectedRole || maintenanceRole.current_user !== binding.maintenance.expectedRole || applicationRole.current_database !== binding.expectedDatabase || maintenanceRole.current_database !== binding.expectedDatabase)) {
|
|
167
|
+
throw startupError("RUNTIME_DATABASE_RLS_ROLE_CONFIG_INVALID", "Correct the trusted hosted database role binding, then restart.");
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
const membership = await application`
|
|
171
|
+
with recursive inherited_roles(role_id) as (
|
|
172
|
+
select roleid from pg_catalog.pg_auth_members where member = (select oid from pg_catalog.pg_roles where rolname = current_user)
|
|
173
|
+
union
|
|
174
|
+
select membership.roleid from pg_catalog.pg_auth_members membership join inherited_roles inherited on membership.member = inherited.role_id
|
|
175
|
+
)
|
|
176
|
+
select exists(
|
|
177
|
+
select 1 from inherited_roles where role_id = (select oid from pg_catalog.pg_roles where rolname = ${maintenanceRole.current_user})
|
|
178
|
+
) as unsafe
|
|
179
|
+
`;
|
|
180
|
+
if (membership[0]?.unsafe) {
|
|
181
|
+
throw startupError("RUNTIME_DATABASE_RLS_APPLICATION_ROLE_UNSAFE", "Remove application-role membership in the maintenance role, then restart.");
|
|
182
|
+
}
|
|
183
|
+
} catch (error) {
|
|
184
|
+
if (error instanceof RuntimeDatabaseRlsError)
|
|
185
|
+
throw error;
|
|
186
|
+
throw startupError("RUNTIME_DATABASE_RLS_APPLICATION_ROLE_UNSAFE", "Verify the application role cannot assume the maintenance role, then restart.");
|
|
187
|
+
}
|
|
188
|
+
if (applicationRole.rolbypassrls || applicationRole.rolsuper || applicationRole.inherited_bypass) {
|
|
189
|
+
throw startupError("RUNTIME_DATABASE_RLS_APPLICATION_ROLE_UNSAFE", "Use a non-owner, non-BYPASSRLS application database role and rerun.");
|
|
190
|
+
}
|
|
191
|
+
if (maintenanceRole.rolsuper) {
|
|
192
|
+
throw startupError("RUNTIME_DATABASE_RLS_UNSAFE_ROLE_UNAVAILABLE", "Use a separately scoped maintenance role rather than a database superuser, then restart.");
|
|
193
|
+
}
|
|
194
|
+
const maintenanceBypassAllowed = binding.kind === "hosted" && binding.maintenance.capability === "bypassrls";
|
|
195
|
+
if (maintenanceRole.rolbypassrls && !maintenanceBypassAllowed || maintenanceRole.inherited_bypass) {
|
|
196
|
+
throw startupError("RUNTIME_DATABASE_RLS_UNSAFE_ROLE_UNAVAILABLE", "Configure the maintenance role with only its documented RLS capability, then restart.");
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
if (await applicationOwnsRlsRelation(application)) {
|
|
200
|
+
throw startupError("RUNTIME_DATABASE_RLS_APPLICATION_ROLE_UNSAFE", "Have the trusted database provisioning owner restore a non-owner application binding without inherited or assumable RLS ownership, then restart. Existing data and serving generations were not changed.");
|
|
201
|
+
}
|
|
202
|
+
} catch (error) {
|
|
203
|
+
if (error instanceof RuntimeDatabaseRlsError)
|
|
204
|
+
throw error;
|
|
205
|
+
throw startupError("RUNTIME_DATABASE_RLS_APPLICATION_ROLE_UNSAFE", "Have the trusted database provisioning owner verify application ownership and role-assumption isolation before restarting; existing data and serving generations were not changed.");
|
|
206
|
+
}
|
|
207
|
+
return Object.freeze([applicationRole.current_user, maintenanceRole.current_user]);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// ../runtime/dist/workflow/completion-outcome.js
|
|
211
|
+
var WorkflowCompletionOutcomeError = class extends RuntimeDiagnosticError {
|
|
212
|
+
cause;
|
|
213
|
+
constructor(runId, impact, cause, admission) {
|
|
214
|
+
const closed = impact === "none" && admission === "resource_closed";
|
|
215
|
+
const allocation = impact === "none" && admission === "resource_allocation";
|
|
216
|
+
const rolledBack = impact === "none" && admission === "completion_rolled_back";
|
|
217
|
+
super({
|
|
218
|
+
code: "RUNTIME_WORKFLOW_COMPLETION_OUTCOME_UNAVAILABLE",
|
|
219
|
+
stage: "workflow",
|
|
220
|
+
capability: "database",
|
|
221
|
+
servingStarted: "unchanged",
|
|
222
|
+
dataImpact: impact,
|
|
223
|
+
retryable: false,
|
|
224
|
+
retryPrecondition: closed ? "This generation's database resource is closed; no completion writes started. Use an active generation for same-run inspection before any existing authorized recovery control. Do not retry through the disposed resource." : allocation ? "Completion writes did not start. This generation's database owner must restore completion resource readiness before inspecting this same run and using existing authorized recovery controls." : rolledBack ? "The owned completion transaction rolled back; existing data and completed checkpoints were preserved. The workflow database owner must restore terminal receipt readiness before inspecting this same run and using existing authorized recovery controls." : impact === "committed" ? "The completion transaction committed. The workflow database owner must restore terminal receipt readiness. Inspect this same run's canonical status and prior effects before any existing authorized recovery control; do not repeat completion or prior effects." : impact === "none" ? "Completion writes did not start. Restore maintenance connection/target readiness against the same database as the serving bindings before restarting this generation and inspecting the same run." : "The workflow database owner must restore terminal receipt readiness. Inspect this same run's canonical status and prior effects before any existing authorized recovery control; do not assume a rejected response rolled back.",
|
|
225
|
+
nextAction: `${closed ? "Use the active generation's API, not this disposed resource. " : allocation ? "Completion resource allocation did not finish; serving state and workflow data are unchanged. Wait for this generation's database owner to restore resource readiness; inspect this same run using the active generation's API. " : rolledBack ? "Completion rolled back. Wait for this generation\u2019s database owner to restore terminal receipt readiness, then inspect this same run before any existing recovery controls. " : impact === "none" ? "Verify the configured maintenance binding can authenticate to the same database as the serving bindings. Correct the binding or restore database availability, then restart this generation. " : ""}Inspect workflows.get using POST /api/query with ${JSON.stringify({ json: { name: "workflows.get", args: { id: runId } } })}. Preserve this same run and completed checkpoints. Wait for owner recovery before existing same-run recovery controls; do not edit internal state, repeat individual effects, or start a replacement run.`,
|
|
226
|
+
correlationId: runId
|
|
227
|
+
});
|
|
228
|
+
this.cause = cause;
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
// ../runtime/dist/adapters/database/postgres-completion-channel.js
|
|
233
|
+
function observeStage(observer, stage, operation) {
|
|
234
|
+
return observer ? observer.measure(stage, operation) : operation();
|
|
235
|
+
}
|
|
236
|
+
async function openPostgresCompletionChannel(transaction, pool, operational, signal, stageObserver) {
|
|
237
|
+
const proof = await observeStage(stageObserver, "channelAttest", () => attestPostgresSchemaTarget(transaction, operational, signal));
|
|
238
|
+
const channel = await observeStage(stageObserver, "channelReserve", () => pool.reserve({ signal }));
|
|
239
|
+
try {
|
|
240
|
+
const cancellation = await observeStage(stageObserver, "channelCancelSetup", () => createPostgresSchemaCancellation(transaction, channel, proof));
|
|
241
|
+
if (!await observeStage(stageObserver, "channelTargetMatch", () => cancellation.matchesTarget()))
|
|
242
|
+
throw new Error("Owned completion target unavailable");
|
|
243
|
+
const identity = await observeStage(stageObserver, "channelIdentityRead", () => readIdentity(channel));
|
|
244
|
+
const xid = (await observeStage(stageObserver, "channelXidRead", () => transaction`SELECT pg_catalog.pg_current_xact_id()::text AS xid`))[0].xid;
|
|
245
|
+
async function checked(execute, identityStage) {
|
|
246
|
+
const readCheckedIdentity = () => identityStage ? observeStage(stageObserver, identityStage, () => readIdentity(channel)) : readIdentity(channel);
|
|
247
|
+
if (!sameIdentity(identity, await readCheckedIdentity()))
|
|
248
|
+
throw new Error("Owned completion observation channel unavailable");
|
|
249
|
+
const result = await execute();
|
|
250
|
+
if (!sameIdentity(identity, await readCheckedIdentity()))
|
|
251
|
+
throw new Error("Owned completion observation channel unavailable");
|
|
252
|
+
return result;
|
|
253
|
+
}
|
|
254
|
+
return {
|
|
255
|
+
channel,
|
|
256
|
+
cancellation,
|
|
257
|
+
xid,
|
|
258
|
+
matches: (target) => checked(() => target.matchesTarget()),
|
|
259
|
+
cancel: (target) => checked(() => target.cancel()),
|
|
260
|
+
targetPresent: () => checked(() => cancellation.sessionExistsOn(channel)),
|
|
261
|
+
witnessWatch(target, pid) {
|
|
262
|
+
stageObserver?.count("witnessPoll");
|
|
263
|
+
return checked(async () => {
|
|
264
|
+
if (!await observeStage(stageObserver, "witnessTargetMatch", () => target.matchesTarget()))
|
|
265
|
+
return false;
|
|
266
|
+
const active = (await observeStage(stageObserver, "witnessActiveSql", () => channel`SELECT EXISTS(
|
|
267
|
+
SELECT 1 FROM pg_catalog.pg_stat_activity WHERE pid=${pid} AND state='active'
|
|
268
|
+
AND wait_event='PgSleep'
|
|
269
|
+
AND query LIKE '%/* gencow-completion-deadline-watch */%') AS active`))[0]?.active;
|
|
270
|
+
return active === true && await observeStage(stageObserver, "witnessTargetMatch", () => target.matchesTarget());
|
|
271
|
+
}, "witnessIdentitySql");
|
|
272
|
+
},
|
|
273
|
+
remaining(deadline, targetMayHaveSettled) {
|
|
274
|
+
return checked(() => cancellation.observeDeadline(deadline, targetMayHaveSettled));
|
|
275
|
+
},
|
|
276
|
+
async outcome() {
|
|
277
|
+
if (!sameIdentity(identity, await readIdentity(channel)))
|
|
278
|
+
return "unknown";
|
|
279
|
+
const status = (await channel`
|
|
280
|
+
SELECT pg_catalog.pg_xact_status(${xid}::xid8) AS status`)[0]?.status;
|
|
281
|
+
if (!sameIdentity(identity, await readIdentity(channel)))
|
|
282
|
+
return "unknown";
|
|
283
|
+
return status === "committed" || status === "aborted" ? status : "unknown";
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
} catch (error) {
|
|
287
|
+
channel.release();
|
|
288
|
+
throw error;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
async function readIdentity(channel) {
|
|
292
|
+
const row = (await channel`SELECT pg_catalog.pg_backend_pid()::int AS pid,
|
|
293
|
+
extract(epoch FROM backend_start)::text AS started,session_user AS actor,
|
|
294
|
+
pg_catalog.current_database() AS database FROM pg_catalog.pg_stat_activity WHERE pid=pg_catalog.pg_backend_pid()`)[0];
|
|
295
|
+
if (!row)
|
|
296
|
+
throw new Error("Owned completion channel unavailable");
|
|
297
|
+
return row;
|
|
298
|
+
}
|
|
299
|
+
function sameIdentity(a, b) {
|
|
300
|
+
return a.pid === b.pid && a.started === b.started && a.actor === b.actor && a.database === b.database;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// ../runtime/dist/adapters/database/postgres-completion-watch.js
|
|
304
|
+
function observeStage2(observer, stage, operation) {
|
|
305
|
+
return observer ? observer.measure(stage, operation) : operation();
|
|
306
|
+
}
|
|
307
|
+
function deferred() {
|
|
308
|
+
let resolve;
|
|
309
|
+
let reject;
|
|
310
|
+
const promise = new Promise((done, fail) => {
|
|
311
|
+
resolve = done;
|
|
312
|
+
reject = fail;
|
|
313
|
+
});
|
|
314
|
+
return { promise, resolve, reject };
|
|
315
|
+
}
|
|
316
|
+
function createPostgresCompletionWatch(input) {
|
|
317
|
+
const ready = deferred();
|
|
318
|
+
const activation = deferred();
|
|
319
|
+
let reservation;
|
|
320
|
+
let drainReservation;
|
|
321
|
+
let cancellation;
|
|
322
|
+
let retiring;
|
|
323
|
+
let started = false, finished = false, expired = false;
|
|
324
|
+
let failure;
|
|
325
|
+
let retirementCancelled = false;
|
|
326
|
+
const expectedRetirement = () => retirementCancelled && failure instanceof Error && Reflect.get(failure, "errno") === "57014";
|
|
327
|
+
const abort = () => activation.resolve(null);
|
|
328
|
+
input.signal.addEventListener("abort", abort, { once: true });
|
|
329
|
+
if (input.signal.aborted)
|
|
330
|
+
abort();
|
|
331
|
+
const joined = (async () => {
|
|
332
|
+
reservation = await observeStage2(input.stageObserver, "watchReserve", () => input.pool.reserve({ signal: input.signal }));
|
|
333
|
+
if (input.signal.aborted) {
|
|
334
|
+
await reservation.close({ timeout: 0 });
|
|
335
|
+
throw new Error("Owned completion watcher aborted before initialization");
|
|
336
|
+
}
|
|
337
|
+
await reservation.begin(async (transaction) => {
|
|
338
|
+
const proof = await observeStage2(input.stageObserver, "watchAttest", () => attestPostgresSchemaTarget(transaction, input.operational, input.signal));
|
|
339
|
+
cancellation = await observeStage2(input.stageObserver, "watchCancelSetup", () => createPostgresSchemaCancellation(transaction, input.channel.channel, proof));
|
|
340
|
+
if (!await observeStage2(input.stageObserver, "watchTargetMatch", () => input.channel.matches(cancellation)))
|
|
341
|
+
throw new Error("Owned completion watcher target unavailable");
|
|
342
|
+
await observeStage2(input.stageObserver, "watchConfig", () => transaction`SELECT pg_catalog.set_config('client_connection_check_interval','100ms',true)`);
|
|
343
|
+
const pid = (await observeStage2(input.stageObserver, "watchPidRead", () => transaction`SELECT pg_catalog.pg_backend_pid()::int AS pid`))[0].pid;
|
|
344
|
+
ready.resolve(pid);
|
|
345
|
+
const deadline = await activation.promise;
|
|
346
|
+
if (deadline === null || input.signal.aborted)
|
|
347
|
+
return;
|
|
348
|
+
const row = await input.channel.cancellation.waitForDeadline(transaction, deadline);
|
|
349
|
+
if (row.matched && row.milliseconds <= 0) {
|
|
350
|
+
expired = true;
|
|
351
|
+
input.expired();
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
})().then(() => {
|
|
355
|
+
finished = true;
|
|
356
|
+
}, (error) => {
|
|
357
|
+
finished = true;
|
|
358
|
+
ready.reject(error);
|
|
359
|
+
failure = error;
|
|
360
|
+
if (!retiring)
|
|
361
|
+
input.failed();
|
|
362
|
+
}).finally(() => input.signal.removeEventListener("abort", abort));
|
|
363
|
+
void ready.promise.catch(() => {
|
|
364
|
+
});
|
|
365
|
+
return {
|
|
366
|
+
ready: ready.promise,
|
|
367
|
+
get reservation() {
|
|
368
|
+
return reservation;
|
|
369
|
+
},
|
|
370
|
+
get drainReservation() {
|
|
371
|
+
return drainReservation;
|
|
372
|
+
},
|
|
373
|
+
get expired() {
|
|
374
|
+
return expired;
|
|
375
|
+
},
|
|
376
|
+
get failure() {
|
|
377
|
+
return expectedRetirement() ? void 0 : failure;
|
|
378
|
+
},
|
|
379
|
+
async start(deadline) {
|
|
380
|
+
const pid = await ready.promise;
|
|
381
|
+
if (input.signal.aborted)
|
|
382
|
+
throw new Error("Owned completion watcher unavailable");
|
|
383
|
+
started = true;
|
|
384
|
+
activation.resolve(deadline);
|
|
385
|
+
while (!finished && !input.signal.aborted) {
|
|
386
|
+
if (await input.channel.witnessWatch(cancellation, pid))
|
|
387
|
+
return;
|
|
388
|
+
await new Promise((done) => setTimeout(done, 1));
|
|
389
|
+
}
|
|
390
|
+
throw new Error("Owned completion watcher was not executing before COMMIT");
|
|
391
|
+
},
|
|
392
|
+
retire() {
|
|
393
|
+
return retiring ??= (async () => {
|
|
394
|
+
activation.resolve(null);
|
|
395
|
+
if (started && !finished && cancellation)
|
|
396
|
+
retirementCancelled = await observeStage2(input.stageObserver, "watchRetireCancel", () => input.channel.cancel(cancellation)).catch(() => {
|
|
397
|
+
input.failed();
|
|
398
|
+
return false;
|
|
399
|
+
});
|
|
400
|
+
await observeStage2(input.stageObserver, "watchRetireJoin", () => joined);
|
|
401
|
+
if (failure && !expectedRetirement() && cancellation) {
|
|
402
|
+
const drainCancellation = cancellation;
|
|
403
|
+
input.failed();
|
|
404
|
+
try {
|
|
405
|
+
await observeStage2(input.stageObserver, "watchDrainProof", async () => {
|
|
406
|
+
drainReservation = await input.drainPool.reserve();
|
|
407
|
+
const identity = await readIdentity(drainReservation);
|
|
408
|
+
const matched = await drainCancellation.matchesTargetOn(drainReservation);
|
|
409
|
+
if (!sameIdentity(identity, await readIdentity(drainReservation)))
|
|
410
|
+
throw new Error("Owned watcher cleanup observer changed");
|
|
411
|
+
if (matched) {
|
|
412
|
+
while (await drainCancellation.sessionExistsOn(drainReservation)) {
|
|
413
|
+
if (!sameIdentity(identity, await readIdentity(drainReservation)))
|
|
414
|
+
throw new Error("Owned watcher cleanup observer changed");
|
|
415
|
+
await new Promise((done) => setTimeout(done, 1));
|
|
416
|
+
}
|
|
417
|
+
if (!sameIdentity(identity, await readIdentity(drainReservation)))
|
|
418
|
+
throw new Error("Owned watcher cleanup observer changed");
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
} catch {
|
|
422
|
+
input.failed();
|
|
423
|
+
} finally {
|
|
424
|
+
drainReservation?.release();
|
|
425
|
+
drainReservation = void 0;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
reservation?.release();
|
|
429
|
+
reservation = void 0;
|
|
430
|
+
})();
|
|
431
|
+
},
|
|
432
|
+
join: () => joined
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// ../runtime/dist/adapters/database/postgres-completion-owner.js
|
|
437
|
+
function observeStage3(input, stage, operation) {
|
|
438
|
+
return input.stageObserver ? input.stageObserver.measure(stage, operation) : operation();
|
|
439
|
+
}
|
|
440
|
+
function createPostgresCompletionOwner(input) {
|
|
441
|
+
let closing;
|
|
442
|
+
const live = /* @__PURE__ */ new Map();
|
|
443
|
+
function track(pending, abort) {
|
|
444
|
+
const result = pending.finally(() => live.delete(result));
|
|
445
|
+
live.set(result, abort);
|
|
446
|
+
return result;
|
|
447
|
+
}
|
|
448
|
+
return {
|
|
449
|
+
run(runId, execute) {
|
|
450
|
+
if (closing)
|
|
451
|
+
return Promise.reject(new WorkflowCompletionOutcomeError(runId, "none", void 0, "resource_closed"));
|
|
452
|
+
const allocated = [];
|
|
453
|
+
let state;
|
|
454
|
+
try {
|
|
455
|
+
state = observeStage3(input, "poolAllocate", () => completionState({
|
|
456
|
+
...input,
|
|
457
|
+
createPool(label) {
|
|
458
|
+
const pool = input.createPool(label);
|
|
459
|
+
allocated.push(pool);
|
|
460
|
+
return pool;
|
|
461
|
+
}
|
|
462
|
+
}));
|
|
463
|
+
} catch (error) {
|
|
464
|
+
const failure = Promise.allSettled(allocated.map(async (pool) => pool.close({ timeout: 2 }))).then(() => {
|
|
465
|
+
throw new WorkflowCompletionOutcomeError(runId, "none", error, "resource_allocation");
|
|
466
|
+
});
|
|
467
|
+
return track(failure, () => {
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
return track(runCompletion(input, state, runId, execute), state.abort);
|
|
471
|
+
},
|
|
472
|
+
close() {
|
|
473
|
+
return closing ??= (async () => {
|
|
474
|
+
for (const abort of live.values())
|
|
475
|
+
abort();
|
|
476
|
+
await Promise.allSettled([...live.keys()]);
|
|
477
|
+
})();
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
async function closeOwnedCompletionResource(owned) {
|
|
482
|
+
await owned.close({ timeout: 0 });
|
|
483
|
+
}
|
|
484
|
+
function completionState(input) {
|
|
485
|
+
const pool = input.createPool("gencow-workflow-completion");
|
|
486
|
+
const channelPool = input.createPool("gencow-workflow-completion-cancel");
|
|
487
|
+
const watchPool = input.createPool("gencow-workflow-completion-watch");
|
|
488
|
+
const drainPool = input.createPool("gencow-workflow-completion-watch-drain");
|
|
489
|
+
const controller = new AbortController();
|
|
490
|
+
let channel;
|
|
491
|
+
let transactionReservation;
|
|
492
|
+
let watch;
|
|
493
|
+
let nativeSettled = false, clockObservedExpired = false;
|
|
494
|
+
let wakeAt = Infinity;
|
|
495
|
+
let observeTerminal;
|
|
496
|
+
let originalDeadline;
|
|
497
|
+
let nativeTransaction;
|
|
498
|
+
let preparation;
|
|
499
|
+
let timer;
|
|
500
|
+
let cleanupTimer;
|
|
501
|
+
let expired = false, forced = false, mainRevoked = false, settled = false;
|
|
502
|
+
let cancellation;
|
|
503
|
+
const closures = [];
|
|
504
|
+
const revokeMain = () => {
|
|
505
|
+
if (mainRevoked || !transactionReservation)
|
|
506
|
+
return;
|
|
507
|
+
mainRevoked = true;
|
|
508
|
+
const pending = closeOwnedCompletionResource(transactionReservation);
|
|
509
|
+
closures.push(pending);
|
|
510
|
+
void pending.catch(() => {
|
|
511
|
+
});
|
|
512
|
+
};
|
|
513
|
+
const forceClose = () => {
|
|
514
|
+
if (forced)
|
|
515
|
+
return;
|
|
516
|
+
forced = true;
|
|
517
|
+
controller.abort();
|
|
518
|
+
revokeMain();
|
|
519
|
+
for (const owned of [
|
|
520
|
+
watch?.reservation,
|
|
521
|
+
watch?.drainReservation,
|
|
522
|
+
channel?.channel,
|
|
523
|
+
pool,
|
|
524
|
+
channelPool,
|
|
525
|
+
watchPool,
|
|
526
|
+
drainPool
|
|
527
|
+
]) {
|
|
528
|
+
if (!owned)
|
|
529
|
+
continue;
|
|
530
|
+
const pending = closeOwnedCompletionResource(owned);
|
|
531
|
+
closures.push(pending);
|
|
532
|
+
void pending.catch(() => {
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
const boundCleanup = () => {
|
|
537
|
+
cleanupTimer ??= setTimeout(forceClose, 5e3);
|
|
538
|
+
};
|
|
539
|
+
const expire = () => {
|
|
540
|
+
expired = true;
|
|
541
|
+
boundCleanup();
|
|
542
|
+
revokeMain();
|
|
543
|
+
};
|
|
544
|
+
const abort = () => {
|
|
545
|
+
controller.abort();
|
|
546
|
+
boundCleanup();
|
|
547
|
+
revokeMain();
|
|
548
|
+
if (channel) {
|
|
549
|
+
cancellation ??= channel.cancellation.cancel().catch(() => false);
|
|
550
|
+
} else
|
|
551
|
+
forceClose();
|
|
552
|
+
};
|
|
553
|
+
async function prepare(transaction) {
|
|
554
|
+
if (preparation)
|
|
555
|
+
return preparation;
|
|
556
|
+
if (expired || controller.signal.aborted)
|
|
557
|
+
throw new WorkflowLeaseLostError();
|
|
558
|
+
nativeTransaction = transaction;
|
|
559
|
+
preparation = (async () => {
|
|
560
|
+
cleanupTimer = setTimeout(forceClose, 5e3);
|
|
561
|
+
try {
|
|
562
|
+
channel = await observeStage3(input, "channelSetup", () => openPostgresCompletionChannel(transaction, channelPool, input.operational, controller.signal, input.stageObserver));
|
|
563
|
+
watch = createPostgresCompletionWatch({
|
|
564
|
+
pool: watchPool,
|
|
565
|
+
drainPool,
|
|
566
|
+
channel,
|
|
567
|
+
operational: input.operational,
|
|
568
|
+
signal: controller.signal,
|
|
569
|
+
failed: abort,
|
|
570
|
+
expired: expire,
|
|
571
|
+
stageObserver: input.stageObserver
|
|
572
|
+
});
|
|
573
|
+
await observeStage3(input, "watchReady", () => watch.ready);
|
|
574
|
+
} finally {
|
|
575
|
+
clearTimeout(cleanupTimer);
|
|
576
|
+
cleanupTimer = void 0;
|
|
577
|
+
}
|
|
578
|
+
})();
|
|
579
|
+
return preparation;
|
|
580
|
+
}
|
|
581
|
+
async function arm(transaction, deadline) {
|
|
582
|
+
if (originalDeadline || expired || controller.signal.aborted)
|
|
583
|
+
throw new WorkflowLeaseLostError();
|
|
584
|
+
await prepare(transaction);
|
|
585
|
+
if (expired || controller.signal.aborted)
|
|
586
|
+
throw new WorkflowLeaseLostError();
|
|
587
|
+
originalDeadline = deadline;
|
|
588
|
+
}
|
|
589
|
+
async function startCommit() {
|
|
590
|
+
if (!channel || !originalDeadline)
|
|
591
|
+
throw new Error("Owned completion deadline unavailable");
|
|
592
|
+
const deadline = originalDeadline;
|
|
593
|
+
async function tick() {
|
|
594
|
+
if (settled)
|
|
595
|
+
return;
|
|
596
|
+
boundCleanup();
|
|
597
|
+
const observedAt = performance.now();
|
|
598
|
+
const remaining = await channel.remaining(deadline, () => nativeSettled || watch?.expired === true);
|
|
599
|
+
if (settled)
|
|
600
|
+
return;
|
|
601
|
+
if (remaining > 0) {
|
|
602
|
+
wakeAt = observedAt + remaining;
|
|
603
|
+
clearTimeout(cleanupTimer);
|
|
604
|
+
cleanupTimer = void 0;
|
|
605
|
+
timer = setTimeout(() => {
|
|
606
|
+
void observe();
|
|
607
|
+
}, Math.min(Math.ceil(remaining), 2147483647));
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
clockObservedExpired = true;
|
|
611
|
+
expire();
|
|
612
|
+
await channel.cancellation.cancel();
|
|
613
|
+
}
|
|
614
|
+
let observing;
|
|
615
|
+
const observe = () => {
|
|
616
|
+
if (observing)
|
|
617
|
+
return observing;
|
|
618
|
+
const pending = tick().catch(() => {
|
|
619
|
+
boundCleanup();
|
|
620
|
+
forceClose();
|
|
621
|
+
});
|
|
622
|
+
observing = pending;
|
|
623
|
+
cancellation = pending;
|
|
624
|
+
void pending.then(() => {
|
|
625
|
+
if (observing === pending)
|
|
626
|
+
observing = void 0;
|
|
627
|
+
});
|
|
628
|
+
return pending;
|
|
629
|
+
};
|
|
630
|
+
observeTerminal = observe;
|
|
631
|
+
boundCleanup();
|
|
632
|
+
try {
|
|
633
|
+
await tick();
|
|
634
|
+
if (!expired && watch) {
|
|
635
|
+
boundCleanup();
|
|
636
|
+
await observeStage3(input, "watchWitness", () => watch.start(deadline));
|
|
637
|
+
await enqueuePostgresCompletionFence(nativeTransaction, deadline, channel.xid, channel.cancellation.targetPid);
|
|
638
|
+
}
|
|
639
|
+
} finally {
|
|
640
|
+
if (!expired && !controller.signal.aborted) {
|
|
641
|
+
clearTimeout(cleanupTimer);
|
|
642
|
+
cleanupTimer = void 0;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
if (expired)
|
|
646
|
+
throw new WorkflowLeaseLostError();
|
|
647
|
+
}
|
|
648
|
+
return {
|
|
649
|
+
async open() {
|
|
650
|
+
boundCleanup();
|
|
651
|
+
try {
|
|
652
|
+
transactionReservation = await observeStage3(input, "mainReserve", () => pool.reserve({ signal: controller.signal }));
|
|
653
|
+
if (controller.signal.aborted) {
|
|
654
|
+
mainRevoked = true;
|
|
655
|
+
const closingReservation = closeOwnedCompletionResource(transactionReservation);
|
|
656
|
+
closures.push(closingReservation);
|
|
657
|
+
await closingReservation;
|
|
658
|
+
throw new WorkflowLeaseLostError();
|
|
659
|
+
}
|
|
660
|
+
return transactionReservation;
|
|
661
|
+
} finally {
|
|
662
|
+
clearTimeout(cleanupTimer);
|
|
663
|
+
cleanupTimer = void 0;
|
|
664
|
+
}
|
|
665
|
+
},
|
|
666
|
+
abort,
|
|
667
|
+
fenceExpired: expire,
|
|
668
|
+
prepare,
|
|
669
|
+
arm,
|
|
670
|
+
startCommit,
|
|
671
|
+
get expired() {
|
|
672
|
+
return expired;
|
|
673
|
+
},
|
|
674
|
+
get unavailable() {
|
|
675
|
+
return controller.signal.aborted || forced || watch?.failure !== void 0;
|
|
676
|
+
},
|
|
677
|
+
async settleDeadline() {
|
|
678
|
+
nativeSettled = true;
|
|
679
|
+
if (performance.now() >= wakeAt && !clockObservedExpired && !forced) {
|
|
680
|
+
clearTimeout(timer);
|
|
681
|
+
await observeTerminal?.();
|
|
682
|
+
}
|
|
683
|
+
if (watch) {
|
|
684
|
+
boundCleanup();
|
|
685
|
+
await observeStage3(input, "watchRetire", () => watch.retire());
|
|
686
|
+
}
|
|
687
|
+
if (mainRevoked && channel && !forced) {
|
|
688
|
+
boundCleanup();
|
|
689
|
+
try {
|
|
690
|
+
while (await channel.targetPresent())
|
|
691
|
+
await new Promise((done) => setTimeout(done, 1));
|
|
692
|
+
} catch {
|
|
693
|
+
forceClose();
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
},
|
|
697
|
+
async outcome() {
|
|
698
|
+
boundCleanup();
|
|
699
|
+
return channel && !forced ? channel.outcome().catch(() => "unknown") : "unknown";
|
|
700
|
+
},
|
|
701
|
+
async finish() {
|
|
702
|
+
settled = true;
|
|
703
|
+
clearTimeout(timer);
|
|
704
|
+
const failures = [];
|
|
705
|
+
try {
|
|
706
|
+
await cancellation?.catch(() => void 0);
|
|
707
|
+
if (watch) {
|
|
708
|
+
boundCleanup();
|
|
709
|
+
try {
|
|
710
|
+
await observeStage3(input, "watchRetire", () => watch.retire());
|
|
711
|
+
} catch (error) {
|
|
712
|
+
failures.push(error);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
if (!forced) {
|
|
716
|
+
for (const reservation of [mainRevoked ? void 0 : transactionReservation, channel?.channel]) {
|
|
717
|
+
try {
|
|
718
|
+
reservation?.release();
|
|
719
|
+
} catch (error) {
|
|
720
|
+
failures.push(error);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
const results = await observeStage3(input, "poolClose", () => Promise.allSettled([
|
|
725
|
+
...[pool, channelPool, watchPool, drainPool].map(async (owned) => owned.close({ timeout: 2 })),
|
|
726
|
+
...closures
|
|
727
|
+
]));
|
|
728
|
+
for (const result of results)
|
|
729
|
+
if (result.status === "rejected")
|
|
730
|
+
failures.push(result.reason);
|
|
731
|
+
if (failures.length)
|
|
732
|
+
throw new AggregateError(failures, "Owned completion cleanup unavailable");
|
|
733
|
+
} finally {
|
|
734
|
+
clearTimeout(cleanupTimer);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
async function runCompletion(input, state, runId, execute) {
|
|
740
|
+
const outcome = await runCompletionTransaction(input, state, runId, execute).then((value) => ({ status: "fulfilled", value }), (reason) => ({ status: "rejected", reason }));
|
|
741
|
+
try {
|
|
742
|
+
await state.finish();
|
|
743
|
+
} catch (cleanupError) {
|
|
744
|
+
if (outcome.status === "fulfilled")
|
|
745
|
+
throw new WorkflowCompletionOutcomeError(runId, "committed", cleanupError);
|
|
746
|
+
}
|
|
747
|
+
if (outcome.status === "rejected")
|
|
748
|
+
throw outcome.reason;
|
|
749
|
+
return outcome.value;
|
|
750
|
+
}
|
|
751
|
+
async function runCompletionTransaction(input, state, runId, execute) {
|
|
752
|
+
let callbackReturned = false, armed = false, commitAcknowledged = false;
|
|
753
|
+
let value;
|
|
754
|
+
let finishCommitSpan;
|
|
755
|
+
try {
|
|
756
|
+
const transaction = input.createDatabase(await state.open()).transaction(async (tx) => {
|
|
757
|
+
const native = Reflect.get(Reflect.get(tx, "session"), "client");
|
|
758
|
+
const operations = {
|
|
759
|
+
execute: (statement) => observeStage3(input, "callbackSql", () => tx.execute(statement)),
|
|
760
|
+
prepare: () => state.prepare(native),
|
|
761
|
+
async armDeadline(deadline) {
|
|
762
|
+
await state.arm(native, deadline);
|
|
763
|
+
armed = true;
|
|
764
|
+
}
|
|
765
|
+
};
|
|
766
|
+
value = await execute(operations);
|
|
767
|
+
await observeStage3(input, "commitAdmission", () => state.startCommit());
|
|
768
|
+
callbackReturned = true;
|
|
769
|
+
finishCommitSpan = input.stageObserver?.start("nativeCommit");
|
|
770
|
+
return value;
|
|
771
|
+
});
|
|
772
|
+
const result = await (input.stageObserver ? transaction.finally(() => finishCommitSpan?.()) : transaction);
|
|
773
|
+
commitAcknowledged = true;
|
|
774
|
+
await observeStage3(input, "deadlineSettle", () => state.settleDeadline());
|
|
775
|
+
if (state.expired || state.unavailable) {
|
|
776
|
+
throw new WorkflowCompletionOutcomeError(runId, "committed", void 0);
|
|
777
|
+
}
|
|
778
|
+
return result;
|
|
779
|
+
} catch (error) {
|
|
780
|
+
const fenced = !commitAcknowledged && postgresCompletionFenceExpired(error);
|
|
781
|
+
if (fenced)
|
|
782
|
+
state.fenceExpired();
|
|
783
|
+
await observeStage3(input, "deadlineSettle", () => state.settleDeadline());
|
|
784
|
+
if (error instanceof WorkflowCompletionOutcomeError)
|
|
785
|
+
throw error;
|
|
786
|
+
if (commitAcknowledged)
|
|
787
|
+
throw new WorkflowCompletionOutcomeError(runId, "committed", error);
|
|
788
|
+
if (fenced)
|
|
789
|
+
throw new WorkflowLeaseLostError();
|
|
790
|
+
if (!armed) {
|
|
791
|
+
if (error instanceof WorkflowLeaseLostError)
|
|
792
|
+
throw error;
|
|
793
|
+
throw new WorkflowCompletionOutcomeError(runId, "none", error);
|
|
794
|
+
}
|
|
795
|
+
const outcome = await state.outcome();
|
|
796
|
+
if (outcome === "aborted") {
|
|
797
|
+
if (state.expired)
|
|
798
|
+
throw new WorkflowLeaseLostError();
|
|
799
|
+
if (
|
|
800
|
+
// Callback/guard admission succeeded, but actual SDK COMMIT failed.
|
|
801
|
+
// Original-XID readback proves rollback even when a post-readiness
|
|
802
|
+
// permission failure has no private guard SQLSTATE. Keep its cause and
|
|
803
|
+
// public terminal diagnosis; early callback SQL retains its old error.
|
|
804
|
+
callbackReturned || state.unavailable || error instanceof WorkflowTerminalFenceUnavailable || postgresCompletionFenceUnavailable(error)
|
|
805
|
+
)
|
|
806
|
+
throw new WorkflowCompletionOutcomeError(runId, "none", error, "completion_rolled_back");
|
|
807
|
+
throw error;
|
|
808
|
+
}
|
|
809
|
+
if (outcome === "committed" && callbackReturned && !state.expired && !state.unavailable)
|
|
810
|
+
return value;
|
|
811
|
+
throw new WorkflowCompletionOutcomeError(runId, outcome === "committed" ? "committed" : "unknown", error);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
// ../runtime/dist/adapters/database/postgres.js
|
|
816
|
+
var SYSTEM_RLS_CONTEXT = Object.freeze({
|
|
817
|
+
userId: "",
|
|
818
|
+
currentUserId: "",
|
|
819
|
+
role: "system",
|
|
820
|
+
internalSystem: "true"
|
|
821
|
+
});
|
|
822
|
+
async function createPostgresDatabaseAdapter(input, generation, warnings = createRuntimeLocalDatabaseWarningSink(), retainGenerationWork, selectedDatabaseSecurityPolicy, frameworkTargetPlan, relations, completionStageObserver) {
|
|
823
|
+
assertRuntimeHost();
|
|
824
|
+
const generationBinding = snapshotRuntimeBinding(generation);
|
|
825
|
+
const binding = parseRuntimePostgresBinding(input);
|
|
826
|
+
const databaseSecurityPolicy = binding.kind !== "local" ? void 0 : frameworkTargetPlan ? selectedDatabaseSecurityPolicy ? assertTrustedLocalDatabaseSecurityPolicyMatches(selectedDatabaseSecurityPolicy, frameworkTargetPlan.policy) : verifyTrustedLocalDatabaseSecurityPolicy(frameworkTargetPlan.policy) : selectedDatabaseSecurityPolicy ? verifyTrustedLocalDatabaseSecurityPolicy(selectedDatabaseSecurityPolicy) : void 0;
|
|
827
|
+
const recoveryOwner = createPostgresRecoveryOwner(void 0, retainGenerationWork);
|
|
828
|
+
const applicationConfig = resolveRuntimePostgresDriverConfig(binding.application.databaseUrl);
|
|
829
|
+
const maintenanceConfig = resolveRuntimePostgresDriverConfig(binding.maintenance.databaseUrl, "maintenance");
|
|
830
|
+
const [SQL, { drizzle }, { runtimePostgresClient, runtimePostgresCodecs }, { bunSqlPgCodecs }] = await Promise.all([
|
|
831
|
+
loadRuntimePostgresSql(),
|
|
832
|
+
import("drizzle-orm/bun-sql"),
|
|
833
|
+
import("./chunk-45I4YR2J.mjs"),
|
|
834
|
+
import("drizzle-orm/bun-sql/postgres/codecs")
|
|
835
|
+
]);
|
|
836
|
+
let openedApplication;
|
|
837
|
+
let openedMaintenance;
|
|
838
|
+
try {
|
|
839
|
+
const applicationClient = runtimePostgresClient(openedApplication = new SQL(applicationConfig.url, applicationConfig.options), { owner: recoveryOwner });
|
|
840
|
+
const maintenanceClient = runtimePostgresClient(openedMaintenance = new SQL(maintenanceConfig.url, maintenanceConfig.options), { owner: recoveryOwner });
|
|
841
|
+
const operationalRoles = await assertPostgresReadiness(applicationClient, maintenanceClient, binding, warnings, databaseSecurityPolicy);
|
|
842
|
+
const codecs = runtimePostgresCodecs(bunSqlPgCodecs);
|
|
843
|
+
const applicationDatabase = drizzle({
|
|
844
|
+
client: applicationClient,
|
|
845
|
+
codecs,
|
|
846
|
+
...relations ? { relations } : {}
|
|
847
|
+
});
|
|
848
|
+
const maintenanceDatabase = drizzle({ client: maintenanceClient, codecs });
|
|
849
|
+
const authDatabase = createRlsDb(maintenanceDatabase, SYSTEM_RLS_CONTEXT);
|
|
850
|
+
const authView = Object.freeze({
|
|
851
|
+
[runtimeDatabaseExecutionScope]: (_assertActive, operation) => recoveryOwner.withNeutralExecutionFence(operation),
|
|
852
|
+
drizzle: borrowRuntimeDrizzle(authDatabase, () => {
|
|
853
|
+
}, (_assertActive, operation) => recoveryOwner.withNeutralExecutionFence(operation)),
|
|
854
|
+
[runtimeVettedAuthRead]: recoveryOwner.runVettedRead,
|
|
855
|
+
[runtimeVettedAuthReadScope]: recoveryOwner.withVettedReadScope
|
|
856
|
+
});
|
|
857
|
+
const completionOwner = createPostgresCompletionOwner({
|
|
858
|
+
createPool(label) {
|
|
859
|
+
return new SQL(maintenanceConfig.url, {
|
|
860
|
+
...maintenanceConfig.options,
|
|
861
|
+
max: 1,
|
|
862
|
+
connectionTimeout: Math.min(Number(maintenanceConfig.options.connectionTimeout ?? 5), 5),
|
|
863
|
+
connection: { ...maintenanceConfig.options.connection, application_name: label }
|
|
864
|
+
});
|
|
865
|
+
},
|
|
866
|
+
createDatabase(pool) {
|
|
867
|
+
return createRlsDb(drizzle({ client: runtimePostgresClient(pool), codecs }), SYSTEM_RLS_CONTEXT);
|
|
868
|
+
},
|
|
869
|
+
operational: { application: openedApplication, maintenance: openedMaintenance },
|
|
870
|
+
...completionStageObserver ? { stageObserver: completionStageObserver } : {}
|
|
871
|
+
});
|
|
872
|
+
registerWorkflowCompletionOwner(authView.drizzle, completionOwner);
|
|
873
|
+
const requestDrizzle = (database, request, assertScopeActive) => {
|
|
874
|
+
const assertActive = () => {
|
|
875
|
+
assertDatabaseGeneration(generationBinding, request);
|
|
876
|
+
if (assertScopeActive) {
|
|
877
|
+
assertScopeActive();
|
|
878
|
+
} else if (request.signal.aborted)
|
|
879
|
+
throw new RuntimeDiagnosticError({
|
|
880
|
+
code: "RUNTIME_GENERATION_CLOSING",
|
|
881
|
+
stage: "request",
|
|
882
|
+
servingStarted: "unchanged",
|
|
883
|
+
dataImpact: "none",
|
|
884
|
+
retryable: false,
|
|
885
|
+
retryPrecondition: "Use an active request or workflow scope.",
|
|
886
|
+
nextAction: "Borrow database operations only while the verified request scope is active.",
|
|
887
|
+
capability: "database",
|
|
888
|
+
correlationId: request.correlationId
|
|
889
|
+
});
|
|
890
|
+
};
|
|
891
|
+
return borrowRuntimeDrizzle(database, assertActive, recoveryOwner.withExecutionFence);
|
|
892
|
+
};
|
|
893
|
+
let disposal;
|
|
894
|
+
let groundingCitationReader;
|
|
895
|
+
const resourceIdentity = {};
|
|
896
|
+
const schema = binding.kind === "local" && binding.setup && !frameworkTargetPlan ? await (async () => {
|
|
897
|
+
const [{ createPostgresSchemaProviderPort }, { createRuntimeDatabaseSchemaResourceOwner }, { runtimeWorkflowSchemaComponent }] = await Promise.all([
|
|
898
|
+
import("./chunk-3ZKA54UW.mjs"),
|
|
899
|
+
import("./chunk-CSWPPWBL.mjs"),
|
|
900
|
+
import("./chunk-M7K2ICSM.mjs")
|
|
901
|
+
]);
|
|
902
|
+
const owner = createRuntimeDatabaseSchemaResourceOwner({
|
|
903
|
+
database: resourceIdentity,
|
|
904
|
+
binding: generationBinding,
|
|
905
|
+
port: createPostgresSchemaProviderPort({
|
|
906
|
+
binding,
|
|
907
|
+
operational: { application: openedApplication, maintenance: openedMaintenance },
|
|
908
|
+
warnings
|
|
909
|
+
})
|
|
910
|
+
});
|
|
911
|
+
return { owner, prepareWorkflow: () => owner.require(runtimeWorkflowSchemaComponent) };
|
|
912
|
+
})() : void 0;
|
|
913
|
+
const frameworkSchema = binding.kind === "local" && frameworkTargetPlan ? await (async () => {
|
|
914
|
+
const [{ createPostgresSchemaProviderPort }, { createFrameworkSchemaResourceOwner }] = await Promise.all([
|
|
915
|
+
import("./chunk-3ZKA54UW.mjs"),
|
|
916
|
+
import("./chunk-F62NUNOO.mjs")
|
|
917
|
+
]);
|
|
918
|
+
return createFrameworkSchemaResourceOwner({
|
|
919
|
+
database: resourceIdentity,
|
|
920
|
+
binding: generationBinding,
|
|
921
|
+
plan: frameworkTargetPlan,
|
|
922
|
+
port: createPostgresSchemaProviderPort({
|
|
923
|
+
binding,
|
|
924
|
+
operational: { application: openedApplication, maintenance: openedMaintenance },
|
|
925
|
+
warnings,
|
|
926
|
+
frameworkTargetPlan
|
|
927
|
+
}).framework,
|
|
928
|
+
borrow: async () => authView.drizzle
|
|
929
|
+
});
|
|
930
|
+
})() : void 0;
|
|
931
|
+
const prepareRag = frameworkSchema ? async () => {
|
|
932
|
+
const proof = await frameworkSchema.prepare();
|
|
933
|
+
await frameworkSchema.borrow("rag", proof);
|
|
934
|
+
} : binding.kind === "local" && binding.setup && "expectedRole" in binding.setup && "expectedDatabase" in binding.setup ? (await import("./chunk-ODWM57W6.mjs")).createPostgresRagSetup(binding.setup, maintenanceClient, operationalRoles) : void 0;
|
|
935
|
+
const managed = createManagedSchemaPreparation({
|
|
936
|
+
engine: "postgres",
|
|
937
|
+
operationalRoles,
|
|
938
|
+
prepareRag,
|
|
939
|
+
prepareWorkflow: frameworkSchema ? async () => {
|
|
940
|
+
const proof = await frameworkSchema.prepare();
|
|
941
|
+
await frameworkSchema.borrow("workflow", proof);
|
|
942
|
+
} : schema?.prepareWorkflow
|
|
943
|
+
}, authView.drizzle);
|
|
944
|
+
const resource = {
|
|
945
|
+
[runtimeDatabaseExecutionScope]: recoveryOwner.withExecutionFence,
|
|
946
|
+
[runtimeDatabaseStopAdmissions]: recoveryOwner.fenceRecovery,
|
|
947
|
+
administrationInspection: runtimeDatabaseInspection,
|
|
948
|
+
borrowSearchModes(options) {
|
|
949
|
+
const search = (scope, assertCurrent) => createSearchSessionReads(applicationDatabase, scope, assertCurrent);
|
|
950
|
+
return createPostgresSearchModes({
|
|
951
|
+
binding: generationBinding,
|
|
952
|
+
application: search,
|
|
953
|
+
...options?.managed ? { managed: search } : {},
|
|
954
|
+
config: options?.config,
|
|
955
|
+
withExecutionFence: recoveryOwner.withExecutionFence,
|
|
956
|
+
assertOpen() {
|
|
957
|
+
if (disposal)
|
|
958
|
+
throw new Error("Search resource ended");
|
|
959
|
+
}
|
|
960
|
+
});
|
|
961
|
+
},
|
|
962
|
+
borrowGroundingCitationReader() {
|
|
963
|
+
return groundingCitationReader ??= createPostgresGroundingCitationReader({
|
|
964
|
+
binding: generationBinding,
|
|
965
|
+
application: (scope, assertCurrent) => createSearchSessionReads(applicationDatabase, { ...scope, ownership: "managed" }, assertCurrent),
|
|
966
|
+
withExecutionFence: recoveryOwner.withExecutionFence,
|
|
967
|
+
assertOpen() {
|
|
968
|
+
if (disposal)
|
|
969
|
+
throw new Error("Grounding resource ended");
|
|
970
|
+
}
|
|
971
|
+
});
|
|
972
|
+
},
|
|
973
|
+
createRequestContext(request, assertScopeActive, assertApplicationActive = assertScopeActive) {
|
|
974
|
+
assertDatabaseGeneration(generationBinding, request);
|
|
975
|
+
const ownerBinding = snapshotRuntimeBinding(request.binding);
|
|
976
|
+
const identity = snapshotRuntimeIdentity(request.identity);
|
|
977
|
+
const rls = snapshotRuntimeRls(request.rls);
|
|
978
|
+
const scopedApplicationDatabase = createRlsDb(applicationDatabase, rls);
|
|
979
|
+
const bindApplicationReads = (assertCurrent, assertLive, assertTransactionActive) => createRuntimeScopedApplicationReads(scopedApplicationDatabase, ownerBinding, identity, rls, assertCurrent, assertLive, assertTransactionActive);
|
|
980
|
+
return Object.freeze({
|
|
981
|
+
[runtimeGenerationBackedApplicationDatabase]: true,
|
|
982
|
+
[runtimeScopedApplicationReads]: bindApplicationReads,
|
|
983
|
+
db: requestDrizzle(scopedApplicationDatabase, request, assertApplicationActive),
|
|
984
|
+
unsafeDb: requestDrizzle(createRlsDb(maintenanceDatabase, SYSTEM_RLS_CONTEXT), request, assertScopeActive)
|
|
985
|
+
});
|
|
986
|
+
},
|
|
987
|
+
createWorkflowContext(attempt) {
|
|
988
|
+
assertDatabaseGeneration(generationBinding, attempt);
|
|
989
|
+
const ownerBinding = snapshotRuntimeBinding(attempt.binding);
|
|
990
|
+
const identity = snapshotRuntimeIdentity(attempt.identity);
|
|
991
|
+
const rls = snapshotRuntimeRls(attempt.rls);
|
|
992
|
+
const scopedApplicationDatabase = createRlsDb(applicationDatabase, rls);
|
|
993
|
+
const bindApplicationReads = (assertCurrent, assertLive) => createRuntimeScopedApplicationReads(scopedApplicationDatabase, ownerBinding, identity, rls, assertCurrent, assertLive);
|
|
994
|
+
return Object.freeze({
|
|
995
|
+
[runtimeScopedApplicationReads]: bindApplicationReads,
|
|
996
|
+
db: requestDrizzle(scopedApplicationDatabase, attempt),
|
|
997
|
+
unsafeDb: requestDrizzle(createRlsDb(maintenanceDatabase, SYSTEM_RLS_CONTEXT), attempt)
|
|
998
|
+
});
|
|
999
|
+
},
|
|
1000
|
+
borrowAuthDatabase() {
|
|
1001
|
+
return authView;
|
|
1002
|
+
},
|
|
1003
|
+
managedSchema: managed.preparation,
|
|
1004
|
+
...schema && !frameworkSchema ? { prepareDatabaseSchema: schema.owner.prepare } : {},
|
|
1005
|
+
...frameworkSchema ? {
|
|
1006
|
+
prepareFrameworkSchema: frameworkSchema.prepare,
|
|
1007
|
+
borrowFrameworkSchema: async (componentId, proof) => await frameworkSchema.borrow(componentId, proof)
|
|
1008
|
+
} : {},
|
|
1009
|
+
prepareWorkflowDatabase: () => managed.preparation.prepare("workflow"),
|
|
1010
|
+
dispose() {
|
|
1011
|
+
return disposal ??= (async () => {
|
|
1012
|
+
recoveryOwner.fenceRecovery();
|
|
1013
|
+
await completionOwner.close();
|
|
1014
|
+
await schema?.owner.close();
|
|
1015
|
+
await frameworkSchema?.close();
|
|
1016
|
+
await managed.close();
|
|
1017
|
+
await recoveryOwner.close();
|
|
1018
|
+
await Promise.all([
|
|
1019
|
+
applicationClient.close({ timeout: 5 }),
|
|
1020
|
+
maintenanceClient.close({ timeout: 5 })
|
|
1021
|
+
]);
|
|
1022
|
+
})();
|
|
1023
|
+
}
|
|
1024
|
+
};
|
|
1025
|
+
return Object.assign(resourceIdentity, resource);
|
|
1026
|
+
} catch (error) {
|
|
1027
|
+
recoveryOwner.fenceRecovery();
|
|
1028
|
+
await recoveryOwner.close().catch(() => {
|
|
1029
|
+
});
|
|
1030
|
+
await Promise.all([
|
|
1031
|
+
openedApplication?.close({ timeout: 1 }).catch(() => {
|
|
1032
|
+
}),
|
|
1033
|
+
openedMaintenance?.close({ timeout: 1 }).catch(() => {
|
|
1034
|
+
})
|
|
1035
|
+
]);
|
|
1036
|
+
throw error;
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
export {
|
|
1040
|
+
createPostgresDatabaseAdapter
|
|
1041
|
+
};
|