gencow 0.1.299 → 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.
Files changed (149) hide show
  1. package/bin/gencow.mjs +0 -6
  2. package/core/package.json +1 -1
  3. package/docs/packaging.md +14 -4
  4. package/lib/cli-artifact-guard.mjs +53 -3
  5. package/lib/cli-dev-runtime.mjs +1 -0
  6. package/lib/cli-project-runtime.mjs +26 -14
  7. package/lib/codegen-command.mjs +16 -0
  8. package/lib/coding-guardrails.mjs +2 -0
  9. package/lib/dashboard-artifact.mjs +65 -0
  10. package/lib/dashboard-assets.mjs +20 -0
  11. package/lib/db-command.mjs +121 -80
  12. package/lib/db-migration-command-steps.mjs +19 -16
  13. package/lib/db-push-command.mjs +1 -1
  14. package/lib/deploy-codegen-preflight.mjs +1 -0
  15. package/lib/dev-cloud-command.mjs +1 -1
  16. package/lib/dev-local-command.mjs +19 -56
  17. package/lib/document-local-converter.mjs +11 -0
  18. package/lib/local-dashboard-plan.mjs +60 -0
  19. package/lib/local-database-commands.mjs +127 -0
  20. package/lib/local-development-migrations.mjs +157 -0
  21. package/lib/local-drizzle-database.config.mjs +10 -0
  22. package/lib/local-runtime-features.mjs +12 -0
  23. package/lib/rag-selection.mjs +7 -0
  24. package/lib/runtime-local-worker.mjs +116 -0
  25. package/lib/runtime-mode.mjs +3 -0
  26. package/lib/standalone-codegen-adapter.mjs +91 -0
  27. package/lib/ts-codegen-import-extension.mjs +228 -19
  28. package/package.json +16 -9
  29. package/runtime/config.mjs +218 -2
  30. package/runtime/engine/chunk-2HA4CUMS.mjs +90 -0
  31. package/runtime/engine/chunk-2JLO3KMM.mjs +305 -0
  32. package/runtime/engine/chunk-2SR2M7SR.mjs +1045 -0
  33. package/runtime/engine/chunk-3D7MHEUC.mjs +253 -0
  34. package/runtime/engine/chunk-3R7COBWG.mjs +309 -0
  35. package/runtime/engine/chunk-3ZKA54UW.mjs +1560 -0
  36. package/runtime/engine/chunk-45I4YR2J.mjs +9 -0
  37. package/runtime/engine/chunk-4MLRXO7F.mjs +74 -0
  38. package/runtime/engine/chunk-5575APCJ.mjs +215 -0
  39. package/runtime/engine/chunk-5GUJZQF3.mjs +114 -0
  40. package/runtime/engine/chunk-5MXY3T75.mjs +428 -0
  41. package/runtime/engine/chunk-5TACQ2US.mjs +44 -0
  42. package/runtime/engine/chunk-66G4YEDT.mjs +3104 -0
  43. package/runtime/engine/chunk-67YO53WW.mjs +1426 -0
  44. package/runtime/engine/chunk-6GQRM7XY.mjs +87 -0
  45. package/runtime/engine/chunk-6JO72SPP.mjs +68 -0
  46. package/runtime/engine/chunk-6W653LXI.mjs +13 -0
  47. package/runtime/engine/chunk-7ITSMI3S.mjs +69 -0
  48. package/runtime/engine/chunk-7KUJ2H2S.mjs +128 -0
  49. package/runtime/engine/chunk-A5BMQ5IC.mjs +45 -0
  50. package/runtime/engine/chunk-ADF3UR6L.mjs +428 -0
  51. package/runtime/engine/chunk-AEBW7XZJ.mjs +4510 -0
  52. package/runtime/engine/chunk-AGPQ5XIV.mjs +156 -0
  53. package/runtime/engine/chunk-CPU4OZSX.mjs +753 -0
  54. package/runtime/engine/chunk-CSWPPWBL.mjs +50 -0
  55. package/runtime/engine/chunk-DPWXSMWO.mjs +53 -0
  56. package/runtime/engine/chunk-EAIELFKU.mjs +151 -0
  57. package/runtime/engine/chunk-EDU5CBKT.mjs +10 -0
  58. package/runtime/engine/chunk-EQCTAET7.mjs +173 -0
  59. package/runtime/engine/chunk-EQCXDF2Z.mjs +70 -0
  60. package/runtime/engine/chunk-F3G4UGV4.mjs +330 -0
  61. package/runtime/engine/chunk-F62NUNOO.mjs +26 -0
  62. package/runtime/engine/chunk-FKPNIFRP.mjs +2492 -0
  63. package/runtime/engine/chunk-FM23RGVI.mjs +81 -0
  64. package/runtime/engine/chunk-FW5AK4YP.mjs +1041 -0
  65. package/runtime/engine/chunk-GDWYAGWV.mjs +23 -0
  66. package/runtime/engine/chunk-GO5PZUYW.mjs +53 -0
  67. package/runtime/engine/chunk-GOLP7OSG.mjs +340 -0
  68. package/runtime/engine/chunk-GSLM44EF.mjs +242 -0
  69. package/runtime/engine/chunk-GYAJ7OX2.mjs +125 -0
  70. package/runtime/engine/chunk-I3GWR43K.mjs +14 -0
  71. package/runtime/engine/chunk-IFMOTJNU.mjs +106 -0
  72. package/runtime/engine/chunk-IKQKBE2G.mjs +128 -0
  73. package/runtime/engine/chunk-ITH2NEKM.mjs +282 -0
  74. package/runtime/engine/chunk-J6SDRCG4.mjs +96 -0
  75. package/runtime/engine/chunk-JODRNM3S.mjs +29596 -0
  76. package/runtime/engine/chunk-JUDKX53X.mjs +137 -0
  77. package/runtime/engine/chunk-K2YZVPJ4.mjs +827 -0
  78. package/runtime/engine/chunk-KEZJUXEE.mjs +151 -0
  79. package/runtime/engine/chunk-KVLTJFCH.mjs +234 -0
  80. package/runtime/engine/chunk-KX2PRQPS.mjs +126 -0
  81. package/runtime/engine/chunk-LEW5ZMLR.mjs +76 -0
  82. package/runtime/engine/chunk-LINVSJEM.mjs +175 -0
  83. package/runtime/engine/chunk-M7K2ICSM.mjs +11 -0
  84. package/runtime/engine/chunk-MZXDXSDC.mjs +292 -0
  85. package/runtime/engine/chunk-N2TA2IK2.mjs +678 -0
  86. package/runtime/engine/chunk-N4LTCKJP.mjs +695 -0
  87. package/runtime/engine/chunk-N6GCLOUX.mjs +13 -0
  88. package/runtime/engine/chunk-NAG2OXS5.mjs +37 -0
  89. package/runtime/engine/chunk-NNZ2QJUG.mjs +381 -0
  90. package/runtime/engine/chunk-NZPPLDNW.mjs +15 -0
  91. package/runtime/engine/chunk-ODWM57W6.mjs +138 -0
  92. package/runtime/engine/chunk-P5IIXAIE.mjs +23 -0
  93. package/runtime/engine/chunk-PBOXB2BV.mjs +6 -0
  94. package/runtime/engine/chunk-PMOJLN2P.mjs +8 -0
  95. package/runtime/engine/chunk-PZFMKFHO.mjs +180 -0
  96. package/runtime/engine/chunk-QL2TQX2N.mjs +114 -0
  97. package/runtime/engine/chunk-RITT2RSJ.mjs +258 -0
  98. package/runtime/engine/chunk-RODBVJ5M.mjs +135 -0
  99. package/runtime/engine/chunk-RW65MPVY.mjs +261 -0
  100. package/runtime/engine/chunk-S67UYPB6.mjs +25 -0
  101. package/runtime/engine/chunk-SVJCOUI3.mjs +47 -0
  102. package/runtime/engine/chunk-TCN3ZASV.mjs +957 -0
  103. package/runtime/engine/chunk-U2NRG6KC.mjs +32 -0
  104. package/runtime/engine/chunk-UM3F7HUV.mjs +432 -0
  105. package/runtime/engine/chunk-VWU7JJ3P.mjs +146 -0
  106. package/runtime/engine/chunk-WDTKPPMU.mjs +310 -0
  107. package/runtime/engine/chunk-WJOO4XTB.mjs +31 -0
  108. package/runtime/engine/chunk-XNFVL2OY.mjs +63 -0
  109. package/runtime/engine/chunk-XPWJXP2J.mjs +58 -0
  110. package/runtime/engine/chunk-Y3HSBJ3I.mjs +1132 -0
  111. package/runtime/engine/chunk-YMH4RYSX.mjs +317 -0
  112. package/runtime/engine/chunk-YNOMPSGS.mjs +8 -0
  113. package/runtime/engine/chunk-YRBAYTEZ.mjs +251 -0
  114. package/runtime/engine/chunk-YRHM272W.mjs +528 -0
  115. package/runtime/engine/chunk-ZQUZAGIQ.mjs +149 -0
  116. package/runtime/engine/chunk-ZXMM7QFP.mjs +176 -0
  117. package/runtime/engine/chunk-ZZJSIPV2.mjs +262 -0
  118. package/runtime/engine/composition.mjs +325 -0
  119. package/runtime/engine/document-local.mjs +504 -0
  120. package/runtime/engine/graph.json +4134 -0
  121. package/runtime/engine/index.mjs +265 -0
  122. package/runtime/engine/local-postgres-support.mjs +69 -0
  123. package/runtime/engine/local.mjs +3275 -0
  124. package/runtime/engine/pglite-directory-lock.mjs +8 -0
  125. package/runtime/engine/rag.mjs +11 -0
  126. package/runtime/engine/search.mjs +18 -0
  127. package/runtime/framework-migrations/foundation-bootstrap/rag.sql +115 -0
  128. package/runtime/framework-migrations/foundation-bootstrap/workflow.sql +194 -0
  129. package/runtime/framework-migrations/journal-bootstrap/migration.sql +26 -0
  130. package/runtime/framework-migrations/manifest.json +56 -0
  131. package/runtime/framework-migrations/rag/20261006111509_mushy_warhawk/migration.sql +121 -0
  132. package/runtime/framework-migrations/rag/20261013234621_rag_v2_lifecycle_markers/migration.sql +6 -0
  133. package/runtime/framework-migrations/workflow/20261006111508_perpetual_star_brand/migration.sql +31 -0
  134. package/runtime/runtime-metadata.json +27 -0
  135. package/runtime/tooling.mjs +10399 -8951
  136. package/scripts/bundle-runtime-config.mjs +23 -0
  137. package/scripts/bundle-runtime.mjs +100 -0
  138. package/scripts/bundle-runtime.test.mjs +33 -0
  139. package/scripts/bundle-shared.mjs +3 -0
  140. package/scripts/copy-dashboard.mjs +16 -0
  141. package/scripts/pre-publish-check.mjs +23 -11
  142. package/templateFeature/sso/sso-auth-callback.tsx +37 -5
  143. package/templateFeature/tools/manifest.json +2 -1
  144. package/templateFeature/tools/tools.ts +3 -3
  145. package/runtime/server.mjs +0 -14389
  146. package/scripts/bundle-server.mjs +0 -223
  147. package/server/config.js +0 -1
  148. package/server/index.js +0 -1
  149. package/server/package.json +0 -6
@@ -0,0 +1,678 @@
1
+ import {
2
+ isRuntimeLocalJobSourceEvidence,
3
+ schedulerIdentifier,
4
+ snapshotRuntimeBinding,
5
+ snapshotSchedulerArgs,
6
+ timedOutSchedulerWorkFor
7
+ } from "./chunk-WDTKPPMU.mjs";
8
+ import {
9
+ schedulerFailure
10
+ } from "./chunk-NAG2OXS5.mjs";
11
+ import {
12
+ requestContextInputError,
13
+ snapshotRuntimeAuthentication,
14
+ snapshotRuntimeRls
15
+ } from "./chunk-IKQKBE2G.mjs";
16
+ import {
17
+ RuntimeDiagnosticError,
18
+ defaultRlsSessionContext,
19
+ runtimeRequestCorrelation
20
+ } from "./chunk-AEBW7XZJ.mjs";
21
+
22
+ // ../runtime/dist/scheduler/selected-source.js
23
+ import { randomUUID } from "node:crypto";
24
+ var selectedDrivers = /* @__PURE__ */ new WeakMap();
25
+ var selectedIssuers = /* @__PURE__ */ new WeakMap();
26
+ var selectedDriverBindings = /* @__PURE__ */ new WeakSet();
27
+ var issuedInvocations = /* @__PURE__ */ new WeakMap();
28
+ var issuedEvidence = /* @__PURE__ */ new WeakSet();
29
+ function createRuntimeCheckedSelectedSchedulerDriver(driver, binding) {
30
+ if (!driver || typeof driver !== "object" || Object.getPrototypeOf(driver) !== Object.prototype && Object.getPrototypeOf(driver) !== null)
31
+ throw componentFailure();
32
+ const driverIdentity = Object.freeze({});
33
+ const capturedBinding = snapshotRuntimeBinding(binding);
34
+ const descriptors = /* @__PURE__ */ new Map();
35
+ let start;
36
+ for (const key of Reflect.ownKeys(driver)) {
37
+ const descriptor = Object.getOwnPropertyDescriptor(driver, key);
38
+ if (!descriptor || !("value" in descriptor))
39
+ throw componentFailure();
40
+ if (key === "start") {
41
+ if (typeof descriptor.value !== "function")
42
+ throw componentFailure();
43
+ start = descriptor.value;
44
+ continue;
45
+ }
46
+ const value = descriptor.value;
47
+ descriptors.set(key, {
48
+ configurable: false,
49
+ enumerable: descriptor.enumerable,
50
+ writable: false,
51
+ value: typeof value === "function" ? value.bind(driver) : value
52
+ });
53
+ }
54
+ if (!start || !Object.hasOwn(driver, "dispose") || typeof driver.dispose !== "function" || !Object.hasOwn(driver, "enabled") || typeof driver.enabled !== "boolean")
55
+ throw componentFailure();
56
+ const facade = /* @__PURE__ */ Object.create(null);
57
+ descriptors.set("start", {
58
+ configurable: false,
59
+ enumerable: true,
60
+ writable: false,
61
+ value: (dispatch, issuer) => {
62
+ const selection = issuer ? selectedIssuers.get(issuer) : void 0;
63
+ if (!selection || selection.driverIdentity !== driverIdentity || selection.closed || selection.disposed || selection.started)
64
+ throw componentFailure();
65
+ selection.started = true;
66
+ return Reflect.apply(start, driver, [dispatch, issuer]);
67
+ }
68
+ });
69
+ for (const [key, descriptor] of descriptors)
70
+ Object.defineProperty(facade, key, descriptor);
71
+ Object.freeze(facade);
72
+ selectedDrivers.set(facade, Object.freeze({ binding: capturedBinding, identity: driverIdentity }));
73
+ return facade;
74
+ }
75
+ function bindRuntimeSelectedJobSource(input) {
76
+ const registration = selectedDrivers.get(input.driver);
77
+ if (!registration)
78
+ return void 0;
79
+ const binding = snapshotRuntimeBinding(input.binding);
80
+ if (registration.binding.appId !== binding.appId || registration.binding.generationId !== binding.generationId)
81
+ throw componentFailure();
82
+ if (selectedDriverBindings.has(input.driver))
83
+ throw componentFailure();
84
+ selectedDriverBindings.add(input.driver);
85
+ let closed = false;
86
+ let disposed = false;
87
+ const selectionIdentity = Object.freeze({});
88
+ const liveDeliveries = /* @__PURE__ */ new Map();
89
+ const selection = {
90
+ driverIdentity: registration.identity,
91
+ identity: selectionIdentity,
92
+ closed: false,
93
+ disposed: false,
94
+ started: false
95
+ };
96
+ const unhook = input.admission.onStopAdmissions(() => {
97
+ closed = true;
98
+ selection.closed = true;
99
+ });
100
+ function captureTarget(value) {
101
+ try {
102
+ if (!value || typeof value !== "object" || Array.isArray(value))
103
+ throw new Error();
104
+ const prototype = Object.getPrototypeOf(value);
105
+ if (prototype !== Object.prototype && prototype !== null)
106
+ throw new Error();
107
+ const fields = /* @__PURE__ */ new Map();
108
+ for (const key of Reflect.ownKeys(value)) {
109
+ if (typeof key !== "string" || !["kind", "name", "actionToken"].includes(key))
110
+ throw new Error();
111
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
112
+ if (!descriptor || !("value" in descriptor))
113
+ throw new Error();
114
+ fields.set(key, descriptor.value);
115
+ }
116
+ const kind = fields.get("kind");
117
+ const name = schedulerIdentifier(fields.get("name"));
118
+ let target;
119
+ if (kind === "local-action" && !fields.has("actionToken")) {
120
+ target = input.catalog.resolveLocal(name);
121
+ } else if ((kind === "internal" || kind === "procedure-mutation" || kind === "legacy-mutation") && typeof fields.get("actionToken") === "string") {
122
+ target = input.catalog.resolve(name);
123
+ } else {
124
+ throw new Error();
125
+ }
126
+ if (target.kind !== kind || target.name !== name || target.kind !== "local-action" && target.actionToken !== fields.get("actionToken"))
127
+ throw new Error();
128
+ input.catalog.capture(target);
129
+ return target;
130
+ } catch {
131
+ throw schedulerFailure("RUNTIME_SCHEDULER_TARGET_STALE", "Use a target admitted by the current selected generation before scheduling or delivering work.");
132
+ }
133
+ }
134
+ function captureCandidate(value) {
135
+ try {
136
+ if (!value || typeof value !== "object" || Array.isArray(value))
137
+ throw new Error();
138
+ const prototype = Object.getPrototypeOf(value);
139
+ if (prototype !== Object.prototype && prototype !== null)
140
+ throw new Error();
141
+ const fields = /* @__PURE__ */ new Map();
142
+ for (const key of Reflect.ownKeys(value)) {
143
+ if (typeof key !== "string" || ![
144
+ "source",
145
+ "target",
146
+ "args",
147
+ "correlationId",
148
+ "canonicalJobId",
149
+ "deferIfTargetLive",
150
+ "targetWaitMs"
151
+ ].includes(key))
152
+ throw new Error();
153
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
154
+ if (!descriptor || !("value" in descriptor))
155
+ throw new Error();
156
+ fields.set(key, descriptor.value);
157
+ }
158
+ const source = fields.get("source");
159
+ if (source !== "one-shot" && source !== "cron" && source !== "direct")
160
+ throw new Error();
161
+ const correlationId = schedulerIdentifier(fields.get("correlationId"));
162
+ const canonicalJobId = fields.get("canonicalJobId");
163
+ const deferIfTargetLive = fields.get("deferIfTargetLive");
164
+ const targetWaitMs = fields.get("targetWaitMs");
165
+ if (deferIfTargetLive !== void 0 && typeof deferIfTargetLive !== "boolean")
166
+ throw new Error();
167
+ if (targetWaitMs !== void 0 && (!deferIfTargetLive || typeof targetWaitMs !== "number" || !Number.isSafeInteger(targetWaitMs) || targetWaitMs < 0 || targetWaitMs > 2147483647))
168
+ throw new Error();
169
+ if (deferIfTargetLive && source !== "cron" && (source !== "one-shot" || canonicalJobId === void 0))
170
+ throw new Error();
171
+ if (canonicalJobId !== void 0 && (source !== "one-shot" || typeof canonicalJobId !== "string"))
172
+ throw new Error();
173
+ return Object.freeze({
174
+ source,
175
+ deferIfTargetLive: deferIfTargetLive === true,
176
+ targetWaitMs: typeof targetWaitMs === "number" ? targetWaitMs : 0,
177
+ target: captureTarget(fields.get("target")),
178
+ args: snapshotSchedulerArgs(fields.get("args")).args,
179
+ correlationId,
180
+ ...canonicalJobId === void 0 ? {} : { canonicalJobId: schedulerIdentifier(canonicalJobId) }
181
+ });
182
+ } catch (error) {
183
+ if (error && typeof error === "object" && "diagnostic" in error)
184
+ throw error;
185
+ throw schedulerFailure("RUNTIME_SCHEDULER_INPUT_INVALID", "Provide a validated source class, current action target, safe JSON arguments and correlation identifier.");
186
+ }
187
+ }
188
+ const issuer = Object.freeze({
189
+ isDeferred(outcome, invocation) {
190
+ const issued = issuedInvocations.get(invocation);
191
+ return Boolean(!selection.closed && !selection.disposed && issued?.selectionIdentity === selectionIdentity && issued.consumed && !invocation.signal.aborted && issued.evidence.deferIfTargetLive && outcome.dataImpact === "none" && input.run && timedOutSchedulerWorkFor(input.run)?.isDeferred(outcome, invocation));
192
+ },
193
+ issue(candidate) {
194
+ if (closed || disposed || !selection.started || selection.closed || selection.disposed || !input.admission.isReady())
195
+ throw schedulerFailure("RUNTIME_GENERATION_CLOSING", "Use an active selected generation before admitting new scheduler delivery.", "request");
196
+ const captured = captureCandidate(candidate);
197
+ const jobId = captured.canonicalJobId ?? randomUUID();
198
+ const liveKey = JSON.stringify([binding.appId, jobId]);
199
+ if (liveDeliveries.has(liveKey))
200
+ throw executionPendingFailure(captured.correlationId);
201
+ let lease;
202
+ try {
203
+ lease = input.admission.acquireWork();
204
+ } catch {
205
+ throw schedulerFailure("RUNTIME_GENERATION_CLOSING", "Use an active selected generation before admitting new scheduler delivery.", "request", captured.correlationId);
206
+ }
207
+ const origin = Object.freeze({
208
+ appId: binding.appId,
209
+ generationId: binding.generationId,
210
+ deploymentId: binding.generationId,
211
+ artifactId: binding.generationId
212
+ });
213
+ const execution = Object.freeze({ ...origin, assignmentId: binding.generationId });
214
+ const cancellation = new AbortController();
215
+ const signal = AbortSignal.any([lease.signal, cancellation.signal]);
216
+ const invocation = Object.freeze({
217
+ source: captured.source,
218
+ jobId,
219
+ revision: 1,
220
+ occurrenceId: randomUUID(),
221
+ deliveryId: randomUUID(),
222
+ attempt: 1,
223
+ target: captured.target,
224
+ args: captured.args,
225
+ origin,
226
+ execution,
227
+ correlationId: captured.correlationId,
228
+ signal
229
+ });
230
+ let released = false;
231
+ const evidence = Object.freeze({
232
+ kind: "selected",
233
+ deferIfTargetLive: captured.deferIfTargetLive,
234
+ targetWaitMs: captured.targetWaitMs,
235
+ binding,
236
+ invocation,
237
+ source: invocation.source,
238
+ deliveryId: invocation.deliveryId,
239
+ occurrenceId: invocation.occurrenceId,
240
+ attempt: invocation.attempt,
241
+ correlationId: invocation.correlationId,
242
+ assertActive() {
243
+ if (released || selection.disposed || lease.signal.aborted || invocation.signal !== signal || signal.aborted || invocation.origin.appId !== binding.appId || invocation.origin.generationId !== binding.generationId || invocation.execution.appId !== binding.appId || invocation.execution.generationId !== binding.generationId)
244
+ throw schedulerFailure("RUNTIME_GENERATION_CLOSING", "Use the still-active original selected scheduler invocation; an ended delivery cannot authorize new work.", "request", invocation.correlationId);
245
+ }
246
+ });
247
+ issuedEvidence.add(evidence);
248
+ const issued = {
249
+ invocation,
250
+ evidence,
251
+ lease,
252
+ signal,
253
+ selectionIdentity,
254
+ consumed: false,
255
+ released: false
256
+ };
257
+ issuedInvocations.set(invocation, issued);
258
+ liveDeliveries.set(liveKey, issued);
259
+ return Object.freeze({
260
+ invocation,
261
+ cancel() {
262
+ cancellation.abort();
263
+ },
264
+ complete() {
265
+ if (issued.released)
266
+ return;
267
+ issued.released = true;
268
+ released = true;
269
+ if (liveDeliveries.get(liveKey) === issued)
270
+ liveDeliveries.delete(liveKey);
271
+ lease.release();
272
+ }
273
+ });
274
+ }
275
+ });
276
+ selectedIssuers.set(issuer, selection);
277
+ return Object.freeze({
278
+ issuer,
279
+ consume(candidate) {
280
+ if (!candidate || typeof candidate !== "object")
281
+ return void 0;
282
+ const issued = issuedInvocations.get(candidate);
283
+ if (!issued || issued.selectionIdentity !== selectionIdentity || selection.disposed || issued.consumed || issued.released || issued.invocation !== candidate || !issuedEvidence.has(issued.evidence))
284
+ return void 0;
285
+ const invocation = issued.invocation;
286
+ if (invocation.signal !== issued.signal || invocation.origin.appId !== binding.appId || invocation.origin.generationId !== binding.generationId || invocation.execution.appId !== binding.appId || invocation.execution.generationId !== binding.generationId || invocation.source !== issued.evidence.source || invocation.deliveryId !== issued.evidence.deliveryId || invocation.occurrenceId !== issued.evidence.occurrenceId || invocation.attempt !== issued.evidence.attempt || invocation.correlationId !== issued.evidence.correlationId || invocation.signal.aborted)
287
+ return void 0;
288
+ issued.consumed = true;
289
+ return issued.evidence;
290
+ },
291
+ quiesce() {
292
+ closed = true;
293
+ selection.closed = true;
294
+ },
295
+ dispose() {
296
+ if (disposed)
297
+ return;
298
+ closed = true;
299
+ disposed = true;
300
+ selection.closed = true;
301
+ selection.disposed = true;
302
+ unhook();
303
+ }
304
+ });
305
+ }
306
+ function isRuntimeSelectedJobSourceEvidence(value) {
307
+ return Boolean(value && typeof value === "object" && issuedEvidence.has(value));
308
+ }
309
+ function executionPendingFailure(correlationId) {
310
+ return schedulerFailure("RUNTIME_SCHEDULER_EXECUTION_PENDING", "The original delivery of this job is still running. Keep the accepted job and do not enqueue replacement work; retry this delivery only after the original attempt settles.", "request", correlationId);
311
+ }
312
+ function componentFailure() {
313
+ return new RuntimeDiagnosticError({
314
+ code: "RUNTIME_COMPONENT_DEPENDENCY_INVALID",
315
+ stage: "startup",
316
+ capability: "scheduler",
317
+ servingStarted: false,
318
+ dataImpact: "none",
319
+ retryable: false,
320
+ retryPrecondition: "Correct the selected scheduler adapter wiring before restarting.",
321
+ nextAction: "Use the exact frozen scheduler facade created for the selected Runtime generation."
322
+ });
323
+ }
324
+
325
+ // ../runtime/dist/admin/verified-grants.js
326
+ var verifiedGrants = /* @__PURE__ */ new WeakMap();
327
+ function mintVerifiedRuntimeAdministrationScope(binding, request, checked) {
328
+ const scope = Object.freeze({
329
+ binding: Object.freeze({ appId: binding.appId, generationId: binding.generationId }),
330
+ operation: checked.operation,
331
+ target: checked.target
332
+ });
333
+ verifiedGrants.set(scope, {
334
+ request,
335
+ appId: binding.appId,
336
+ generationId: binding.generationId,
337
+ operation: checked.operation,
338
+ target: checked.target
339
+ });
340
+ return scope;
341
+ }
342
+ function assertVerifiedRuntimeAdministrationScope(scope, request, binding) {
343
+ const evidence = scope && typeof scope === "object" ? verifiedGrants.get(scope) : void 0;
344
+ if (!evidence || evidence.request !== request || evidence.appId !== binding.appId || evidence.generationId !== binding.generationId || scope.binding.appId !== evidence.appId || scope.binding.generationId !== evidence.generationId || scope.operation !== evidence.operation || scope.target !== evidence.target)
345
+ throw new Error("RUNTIME_ADMIN_SCOPE_DENIED");
346
+ }
347
+
348
+ // ../runtime/dist/app/checked-scope-domain.js
349
+ function snapshotRuntimeScopeDomain(value) {
350
+ try {
351
+ if (!value || typeof value !== "object")
352
+ return void 0;
353
+ const candidate = value;
354
+ const kind = candidate.kind;
355
+ if (kind === "generation") {
356
+ const binding = candidate.binding;
357
+ if (!binding || typeof binding !== "object")
358
+ return void 0;
359
+ const captured = binding;
360
+ const appId = captured.appId;
361
+ const generationId = captured.generationId;
362
+ if (!validIdentity(appId) || !validIdentity(generationId))
363
+ return void 0;
364
+ return Object.freeze({
365
+ kind: "generation",
366
+ binding: Object.freeze({ appId, generationId })
367
+ });
368
+ }
369
+ if (kind === "embedded-host") {
370
+ const mountId = candidate.mountId;
371
+ if (!validIdentity(mountId))
372
+ return void 0;
373
+ return Object.freeze({ kind: "embedded-host", mountId });
374
+ }
375
+ return void 0;
376
+ } catch {
377
+ return void 0;
378
+ }
379
+ }
380
+ function snapshotRuntimeGenerationScopeDomain(value) {
381
+ const domain = snapshotRuntimeScopeDomain(value);
382
+ return domain?.kind === "generation" ? domain : void 0;
383
+ }
384
+ function sameRuntimeScopeDomain(left, right) {
385
+ const a = snapshotRuntimeScopeDomain(left);
386
+ const b = snapshotRuntimeScopeDomain(right);
387
+ if (!a || !b || a.kind !== b.kind)
388
+ return false;
389
+ return a.kind === "generation" && b.kind === "generation" ? a.binding.appId === b.binding.appId && a.binding.generationId === b.binding.generationId : a.kind === "embedded-host" && b.kind === "embedded-host" && a.mountId === b.mountId;
390
+ }
391
+ function validIdentity(value) {
392
+ return typeof value === "string" && value.trim().length > 0;
393
+ }
394
+
395
+ // ../runtime/dist/app/verified-request.js
396
+ var capturedHostOperations = /* @__PURE__ */ new WeakMap();
397
+ function captureRuntimeHostOperationDescriptor(value) {
398
+ const operation = snapshotHostOperation(value);
399
+ capturedHostOperations.set(operation, operation);
400
+ return operation;
401
+ }
402
+ function snapshotHostOperation(value) {
403
+ if (value && typeof value === "object") {
404
+ const captured = capturedHostOperations.get(value);
405
+ if (captured)
406
+ return captured;
407
+ }
408
+ try {
409
+ if (!value || typeof value !== "object" || Array.isArray(value))
410
+ throw requestContextInputError();
411
+ const fields = /* @__PURE__ */ new Map();
412
+ for (const key of Reflect.ownKeys(value)) {
413
+ if (typeof key !== "string" || !["transport", "kind", "name", "method", "path"].includes(key))
414
+ throw requestContextInputError();
415
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
416
+ if (!descriptor || !("value" in descriptor))
417
+ throw requestContextInputError();
418
+ fields.set(key, descriptor.value);
419
+ }
420
+ const transport = fields.get("transport");
421
+ const kind = fields.get("kind");
422
+ const name = fields.get("name");
423
+ const method = fields.get("method");
424
+ const path = fields.get("path");
425
+ if (transport !== "rpc" && transport !== "http" || kind !== "query" && kind !== "mutation" && kind !== "route" || typeof name !== "string" || !name.trim() || method !== void 0 && typeof method !== "string" || path !== void 0 && typeof path !== "string")
426
+ throw requestContextInputError();
427
+ return Object.freeze({
428
+ transport,
429
+ kind,
430
+ name,
431
+ ...method !== void 0 ? { method } : {},
432
+ ...path !== void 0 ? { path } : {}
433
+ });
434
+ } catch (error) {
435
+ if (error instanceof RuntimeDiagnosticError)
436
+ throw error;
437
+ throw requestContextInputError();
438
+ }
439
+ }
440
+ function createRequestVerifier(input) {
441
+ const binding = snapshotRuntimeBinding(input);
442
+ const verified = /* @__PURE__ */ new WeakSet();
443
+ const retainedSettlements = /* @__PURE__ */ new WeakSet();
444
+ const scopeEnds = /* @__PURE__ */ new WeakMap();
445
+ const sources = /* @__PURE__ */ new WeakMap();
446
+ const hostScopeInputs = /* @__PURE__ */ new WeakMap();
447
+ function register(request, scopeEnd, source) {
448
+ verified.add(request);
449
+ scopeEnds.set(request, scopeEnd);
450
+ sources.set(request, source);
451
+ return request;
452
+ }
453
+ function snapshotAnonymousRls(mapIdentityToRls) {
454
+ return snapshotRuntimeRls(mapIdentityToRls ? mapIdentityToRls({ identity: null }) : defaultRlsSessionContext(""));
455
+ }
456
+ function snapshotWorkflowSourceAuthentication(attempt) {
457
+ const ownerId = attempt.claim.userId;
458
+ if (ownerId === null) {
459
+ if (attempt.identity !== null)
460
+ throw requestContextInputError();
461
+ return Object.freeze({ method: "anonymous", subject: null });
462
+ }
463
+ if (typeof ownerId !== "string" || !ownerId || attempt.identity?.id !== ownerId)
464
+ throw requestContextInputError();
465
+ return Object.freeze({ method: "host", subject: Object.freeze({ id: ownerId }) });
466
+ }
467
+ function assertWorkflowSourceAuthentication(request, source) {
468
+ const current = snapshotWorkflowSourceAuthentication(source.attempt);
469
+ if (current.method !== source.sourceAuthentication.method || current.subject?.id !== source.sourceAuthentication.subject?.id || request.parentDeliveryId !== `workflow:${source.attempt.claim.id}:${source.attempt.claim.epoch}`)
470
+ throw requestContextInputError();
471
+ return source.sourceAuthentication;
472
+ }
473
+ function assertActive(input2, capability = "database") {
474
+ if (!verified.has(input2) || input2.binding !== binding)
475
+ throw requestContextInputError();
476
+ const source = sources.get(input2);
477
+ if (!source)
478
+ throw requestContextInputError();
479
+ if (source.kind === "job")
480
+ source.admission.assertActive();
481
+ if (source.kind === "workflow") {
482
+ if (source.attempt.signal.aborted)
483
+ throw requestContextInputError();
484
+ assertWorkflowSourceAuthentication(input2, source);
485
+ }
486
+ const sourceSignalAborted = source.kind !== "job" && input2.signal.aborted && !retainedSettlements.has(input2);
487
+ if (sourceSignalAborted || scopeEnds.get(input2)?.aborted)
488
+ throw new RuntimeDiagnosticError({
489
+ code: "RUNTIME_GENERATION_CLOSING",
490
+ stage: "request",
491
+ capability,
492
+ servingStarted: "unchanged",
493
+ dataImpact: "none",
494
+ retryable: false,
495
+ retryPrecondition: "Use an active request/job scope.",
496
+ nextAction: "Borrow operations from the active handler; an ended scope cannot authorize later work.",
497
+ correlationId: input2.correlationId
498
+ });
499
+ }
500
+ return {
501
+ async verify(auth, request, signal = request.signal, scopeEnd = signal) {
502
+ const resolved = await auth.resolveAuthentication(request);
503
+ try {
504
+ const authentication = snapshotRuntimeAuthentication(resolved);
505
+ const identity = authentication.identity;
506
+ const mapIdentityToRls = auth.mapIdentityToRls?.bind(auth);
507
+ const rls = snapshotRuntimeRls(mapIdentityToRls ? mapIdentityToRls({ identity }) : defaultRlsSessionContext(identity?.id ?? ""));
508
+ const input2 = Object.freeze({
509
+ binding,
510
+ authentication,
511
+ identity,
512
+ rls,
513
+ signal,
514
+ correlationId: runtimeRequestCorrelation(request)
515
+ });
516
+ return register(input2, scopeEnd, { kind: "request", request, authentication, mapIdentityToRls });
517
+ } catch (error) {
518
+ if (error instanceof RuntimeDiagnosticError)
519
+ throw error;
520
+ throw requestContextInputError();
521
+ }
522
+ },
523
+ /** Private refresh child: same binding, no caller identity or caller RLS. */
524
+ anonymous(original, signal, scopeEnd = signal) {
525
+ const parentSource = verified.has(original) ? sources.get(original) : void 0;
526
+ if (!verified.has(original) || original.binding !== binding || parentSource?.kind !== "request")
527
+ throw requestContextInputError();
528
+ assertActive(original);
529
+ try {
530
+ const child = Object.freeze({
531
+ binding,
532
+ authentication: Object.freeze({ method: "anonymous", identity: null }),
533
+ identity: null,
534
+ rls: snapshotAnonymousRls(parentSource.mapIdentityToRls),
535
+ signal,
536
+ correlationId: original.correlationId
537
+ });
538
+ return register(child, scopeEnd, { kind: "refresh", parent: original });
539
+ } catch {
540
+ throw requestContextInputError();
541
+ }
542
+ },
543
+ verifyJob(auth, admission, signal, scopeEnd = signal) {
544
+ if (!(isRuntimeLocalJobSourceEvidence(admission) || isRuntimeSelectedJobSourceEvidence(admission)) || admission.binding.appId !== binding.appId || admission.binding.generationId !== binding.generationId)
545
+ throw requestContextInputError();
546
+ admission.assertActive();
547
+ const invocation = admission.invocation;
548
+ try {
549
+ const rls = snapshotAnonymousRls(auth.mapIdentityToRls?.bind(auth));
550
+ const input2 = Object.freeze({
551
+ binding,
552
+ authentication: Object.freeze({ method: "anonymous", identity: null }),
553
+ identity: null,
554
+ rls,
555
+ signal,
556
+ correlationId: admission.correlationId,
557
+ parentDeliveryId: admission.deliveryId
558
+ });
559
+ return register(input2, scopeEnd, { kind: "job", admission });
560
+ } catch {
561
+ throw requestContextInputError();
562
+ }
563
+ },
564
+ verifyWorkflowAttempt(auth, attempt, assertAttempt, signal, scopeEnd = signal) {
565
+ try {
566
+ assertAttempt(attempt);
567
+ if (attempt.binding.appId !== binding.appId || attempt.binding.generationId !== binding.generationId || attempt.signal.aborted || attempt.claim.userId !== null && typeof attempt.claim.userId !== "string")
568
+ throw requestContextInputError();
569
+ const sourceAuthentication = snapshotWorkflowSourceAuthentication(attempt);
570
+ const input2 = Object.freeze({
571
+ binding,
572
+ authentication: Object.freeze({ method: "anonymous", identity: null }),
573
+ identity: null,
574
+ rls: snapshotAnonymousRls(auth.mapIdentityToRls?.bind(auth)),
575
+ signal,
576
+ correlationId: attempt.correlationId,
577
+ parentDeliveryId: `workflow:${attempt.claim.id}:${attempt.claim.epoch}`
578
+ });
579
+ return register(input2, scopeEnd, {
580
+ kind: "workflow",
581
+ attempt,
582
+ sourceAuthentication
583
+ });
584
+ } catch {
585
+ throw requestContextInputError();
586
+ }
587
+ },
588
+ verifyAdministration(authority, request, signal, scopeEnd) {
589
+ try {
590
+ assertVerifiedRuntimeAdministrationScope(authority, request, binding);
591
+ } catch {
592
+ throw requestContextInputError();
593
+ }
594
+ const input2 = Object.freeze({
595
+ binding,
596
+ authentication: Object.freeze({ method: "host", identity: null }),
597
+ identity: null,
598
+ rls: snapshotRuntimeRls(defaultRlsSessionContext("")),
599
+ signal,
600
+ correlationId: runtimeRequestCorrelation(request)
601
+ });
602
+ return register(input2, scopeEnd, { kind: "administration", request, authority });
603
+ },
604
+ assertActive(input2, capability = "database") {
605
+ assertActive(input2, capability);
606
+ },
607
+ assertScopeEnd(input2, scopeEnd) {
608
+ if (!verified.has(input2) || input2.binding !== binding || scopeEnds.get(input2) !== scopeEnd)
609
+ throw requestContextInputError();
610
+ },
611
+ retainForSettlement(input2) {
612
+ if (!verified.has(input2) || input2.binding !== binding)
613
+ throw requestContextInputError();
614
+ const source = sources.get(input2);
615
+ if (source?.kind !== "request" && source?.kind !== "refresh" && source?.kind !== "administration")
616
+ return;
617
+ if (scopeEnds.get(input2)?.aborted)
618
+ throw requestContextInputError();
619
+ retainedSettlements.add(input2);
620
+ },
621
+ createHostScopeInput(request, domainInput, operationInput) {
622
+ if (!verified.has(request) || request.binding !== binding || sources.get(request)?.kind !== "request")
623
+ throw requestContextInputError();
624
+ assertActive(request, "auth");
625
+ const domain = snapshotRuntimeScopeDomain(domainInput);
626
+ if (!domain || domain.kind !== "generation" || !sameRuntimeScopeDomain(domain, { kind: "generation", binding }))
627
+ throw requestContextInputError();
628
+ const operation = snapshotHostOperation(operationInput);
629
+ const authentication = request.authentication;
630
+ const hostScopeInput = Object.freeze({
631
+ kind: "request",
632
+ domain,
633
+ identity: authentication.identity,
634
+ ...authentication.method === "session" && authentication.session ? { session: authentication.session } : {},
635
+ correlationId: request.correlationId,
636
+ approvedMetadata: Object.freeze({}),
637
+ operation,
638
+ signal: request.signal,
639
+ assertActive() {
640
+ assertActive(request, "auth");
641
+ }
642
+ });
643
+ hostScopeInputs.set(hostScopeInput, { request, domain, used: false });
644
+ return hostScopeInput;
645
+ },
646
+ consumeHostScopeInput(request, hostScopeInput) {
647
+ const record = hostScopeInput && typeof hostScopeInput === "object" ? hostScopeInputs.get(hostScopeInput) : void 0;
648
+ if (!record || record.request !== request || record.used || !verified.has(request) || request.binding !== binding || !sameRuntimeScopeDomain(record.domain, { kind: "generation", binding }))
649
+ throw requestContextInputError();
650
+ assertActive(request, "auth");
651
+ record.used = true;
652
+ },
653
+ workflowSourceAuthentication(input2) {
654
+ if (!verified.has(input2) || input2.binding !== binding)
655
+ throw requestContextInputError();
656
+ const source = sources.get(input2);
657
+ if (source?.kind !== "workflow")
658
+ throw requestContextInputError();
659
+ return assertWorkflowSourceAuthentication(input2, source);
660
+ },
661
+ assert(input2) {
662
+ if (!verified.has(input2) || input2.binding !== binding || !sources.has(input2))
663
+ throw requestContextInputError();
664
+ }
665
+ };
666
+ }
667
+
668
+ export {
669
+ mintVerifiedRuntimeAdministrationScope,
670
+ createRuntimeCheckedSelectedSchedulerDriver,
671
+ bindRuntimeSelectedJobSource,
672
+ isRuntimeSelectedJobSourceEvidence,
673
+ snapshotRuntimeScopeDomain,
674
+ snapshotRuntimeGenerationScopeDomain,
675
+ sameRuntimeScopeDomain,
676
+ captureRuntimeHostOperationDescriptor,
677
+ createRequestVerifier
678
+ };