deepline 0.3.519 → 0.3.521

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 (186) hide show
  1. package/dist/bundling-sources/sdk/src/plays/client-core.ts +16 -45
  2. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  3. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +0 -18
  4. package/dist/bundling-sources/shared_libs/play-data-plane/r2.ts +0 -155
  5. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +160 -2
  6. package/dist/bundling-sources/shared_libs/play-runtime/execute-server-timing.ts +22 -0
  7. package/dist/bundling-sources/shared_libs/play-runtime/fixture-behavior.ts +24 -0
  8. package/dist/bundling-sources/shared_libs/play-runtime/internal-bootstrap-token.ts +1 -54
  9. package/dist/bundling-sources/shared_libs/play-runtime/launch-identity.ts +2 -7
  10. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +0 -13
  11. package/dist/bundling-sources/shared_libs/play-runtime/run-identity.ts +0 -56
  12. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +10 -21
  13. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-heartbeat.ts +1 -1
  14. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-progress-push.ts +2 -1
  15. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-terminal-push.ts +1 -1
  16. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +2 -37
  17. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-payload-transport.ts +3 -74
  18. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-runtime-watchdog.ts +2 -226
  19. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +3 -36
  20. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api-paths.ts +0 -26
  21. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +1 -9
  22. package/dist/bundling-sources/shared_libs/play-runtime/runtime-authority.ts +0 -5
  23. package/dist/bundling-sources/shared_libs/play-runtime/runtime-environment.ts +9 -49
  24. package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-oidc.ts +11 -447
  25. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +5 -4
  26. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +12 -207
  27. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-shared.ts +3 -17
  28. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/gateway-progress-registry.ts +0 -9
  29. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +2 -18
  30. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +15 -175
  31. package/dist/bundling-sources/shared_libs/play-runtime/workflow-executor-auth.ts +0 -4
  32. package/dist/cli/{artifacts-YRKH7KNC.js → artifacts-JGH464N2.js} +20 -20
  33. package/dist/cli/{artifacts-ZZULJ6X5.mjs → artifacts-TYPU37IU.mjs} +8 -8
  34. package/dist/cli/auth-JWR3VSNT.js +43 -0
  35. package/dist/cli/{auth-WU2BDO3T.mjs → auth-XPQT6NUB.mjs} +5 -5
  36. package/dist/cli/{billing-DG62VVXW.mjs → billing-47AMHOMP.mjs} +8 -8
  37. package/dist/cli/{billing-MUMMBMQK.js → billing-6D4KXBFJ.js} +81 -81
  38. package/dist/cli/{chunk-R3OAKFHJ.mjs → chunk-2DQPB5HT.mjs} +5 -5
  39. package/dist/cli/{chunk-6Y3DDRRN.js → chunk-2KHUFWTK.js} +3 -3
  40. package/dist/cli/{chunk-XUCAH3LN.js → chunk-3Q7HEEH2.js} +10 -10
  41. package/dist/cli/{chunk-MI5DKOBD.mjs → chunk-4DB6JV7X.mjs} +2 -2
  42. package/dist/cli/{chunk-J4X4RNSP.mjs → chunk-4GGXAYKI.mjs} +3 -3
  43. package/dist/cli/{chunk-AXA5DFY5.mjs → chunk-4I7I5CGB.mjs} +1 -1
  44. package/dist/cli/{chunk-I3ICKVYH.js → chunk-4MN65FRF.js} +53 -53
  45. package/dist/cli/{chunk-Y7D6L4M7.mjs → chunk-4MONKWYE.mjs} +5 -5
  46. package/dist/cli/{chunk-3CUIIVGR.mjs → chunk-5T7QKHQL.mjs} +1 -1
  47. package/dist/cli/{chunk-UMPHUAGZ.js → chunk-6DCBTJZP.js} +3 -3
  48. package/dist/cli/{chunk-LKYLIZ5X.js → chunk-6N72GHAV.js} +2 -2
  49. package/dist/cli/{chunk-RHQKDHCX.mjs → chunk-6UHYXNCP.mjs} +2 -2
  50. package/dist/cli/{chunk-RU5JRQKJ.mjs → chunk-6V2RI3AL.mjs} +3 -3
  51. package/dist/cli/{chunk-NIJE62ZD.mjs → chunk-7AUXX6M5.mjs} +1 -1
  52. package/dist/cli/{chunk-NH22WUUG.mjs → chunk-7IYDCHTG.mjs} +2 -2
  53. package/dist/cli/{chunk-FEJKDR67.mjs → chunk-7LRALARF.mjs} +1 -1
  54. package/dist/cli/{chunk-N3LUYBOB.mjs → chunk-A2B5AAU3.mjs} +11 -11
  55. package/dist/cli/{chunk-CRE3OGHH.mjs → chunk-A6USUS4L.mjs} +2 -2
  56. package/dist/cli/{chunk-ZQ23WQP3.js → chunk-AMVKLEPH.js} +2 -2
  57. package/dist/cli/{chunk-RQ2BHYUM.mjs → chunk-CBBCUYIN.mjs} +2 -2
  58. package/dist/cli/{chunk-CBMTBMIJ.mjs → chunk-DQURY3WH.mjs} +1 -1
  59. package/dist/cli/{chunk-EMV6EHK2.js → chunk-DY6634MN.js} +14 -14
  60. package/dist/cli/{chunk-5A2SIIPH.mjs → chunk-E4ZS2B2J.mjs} +1 -1
  61. package/dist/cli/{chunk-BQYXIAJM.js → chunk-EILHJRPW.js} +3 -3
  62. package/dist/cli/{chunk-RQDD2VV3.js → chunk-EW3EAEWZ.js} +5 -5
  63. package/dist/cli/{chunk-A7W3CCU5.mjs → chunk-EZNZDOAG.mjs} +5 -5
  64. package/dist/cli/{chunk-HT675XNR.mjs → chunk-FKD3KL5Q.mjs} +1 -1
  65. package/dist/cli/{chunk-FJAGGBDR.mjs → chunk-FQJFONFT.mjs} +59 -90
  66. package/dist/cli/{chunk-C7ZD4LXZ.js → chunk-FTZX4QZN.js} +2 -2
  67. package/dist/cli/{chunk-F6XD4CRW.js → chunk-GNYSODBR.js} +1 -1
  68. package/dist/cli/{chunk-4PWBHYH4.js → chunk-HD3KYCDC.js} +7 -7
  69. package/dist/cli/{chunk-IMIHYCJ5.mjs → chunk-HHBJJYKL.mjs} +5 -5
  70. package/dist/cli/{chunk-YRU46P7H.mjs → chunk-HRWVEIAX.mjs} +1 -1
  71. package/dist/cli/{chunk-TT2XB433.js → chunk-HSFLMTED.js} +4 -4
  72. package/dist/cli/{chunk-E6YWCXII.js → chunk-JFQJNYTB.js} +16 -16
  73. package/dist/cli/{chunk-XBS4RDKU.js → chunk-LGU2NIOT.js} +98 -98
  74. package/dist/cli/{chunk-SBF4K3QF.mjs → chunk-LNBMEFOI.mjs} +4 -4
  75. package/dist/cli/{chunk-G2QD575P.js → chunk-MD43YAL6.js} +6 -6
  76. package/dist/cli/{chunk-S7R4O62I.js → chunk-MRU4N33M.js} +6 -6
  77. package/dist/cli/{chunk-UB2REJPL.mjs → chunk-NNDAVVBG.mjs} +2 -2
  78. package/dist/cli/{chunk-ORNLTNBN.js → chunk-PUKWFJXW.js} +44 -44
  79. package/dist/cli/{chunk-O655PVT4.js → chunk-QGTWGHYD.js} +88 -119
  80. package/dist/cli/{chunk-AL7FDMD6.mjs → chunk-TBIWR7M2.mjs} +1 -1
  81. package/dist/cli/{chunk-PK6VYYEY.js → chunk-UAZKOH3J.js} +5 -5
  82. package/dist/cli/{chunk-BMCRTI6Z.mjs → chunk-UBKA33KY.mjs} +1 -22
  83. package/dist/cli/{chunk-4ECU5DI3.js → chunk-ULW2KBKL.js} +26 -26
  84. package/dist/cli/{chunk-52DFTRVC.js → chunk-VSH3AE5E.js} +16 -16
  85. package/dist/cli/{chunk-P62S3ZMS.js → chunk-VYY5V4M5.js} +11 -11
  86. package/dist/cli/{chunk-HXPHRSNM.js → chunk-WL6WPW6X.js} +14 -14
  87. package/dist/cli/{chunk-WSGXBROE.js → chunk-XDVT3GOM.js} +1 -22
  88. package/dist/cli/{chunk-GO467AXG.js → chunk-Y23TOHNV.js} +41 -41
  89. package/dist/cli/{chunk-FTJ2D3XD.mjs → chunk-Y7IR4LBU.mjs} +3 -3
  90. package/dist/cli/{chunk-25WXWSFS.js → chunk-YROP3H6T.js} +22 -22
  91. package/dist/cli/{chunk-HKKC7J6K.mjs → chunk-ZO2XJVFH.mjs} +6 -6
  92. package/dist/cli/{csv-BKWIYPMK.js → csv-5TM2OSYP.js} +13 -13
  93. package/dist/cli/{csv-3TUJHAOW.mjs → csv-PM3WDXDF.mjs} +4 -4
  94. package/dist/cli/{db-EJMJDKDA.js → db-3LJ32FZM.js} +29 -29
  95. package/dist/cli/{db-I75IQ7XI.mjs → db-5P72NPRL.mjs} +8 -8
  96. package/dist/cli/describe-GRS3IRSX.js +50 -0
  97. package/dist/cli/{describe-RUFLLRIN.mjs → describe-ZLCMBGHG.mjs} +20 -20
  98. package/dist/cli/describe-core.d.mts +2 -2
  99. package/dist/cli/describe-core.d.ts +2 -2
  100. package/dist/cli/{executions-TQJCMUUG.js → executions-4AJ5TQVY.js} +10 -10
  101. package/dist/cli/{executions-VW3MYJEE.mjs → executions-JMFL6AV7.mjs} +8 -8
  102. package/dist/cli/{feedback-76342G7E.mjs → feedback-DKMG2QB7.mjs} +5 -5
  103. package/dist/cli/{feedback-UFAEXH5B.js → feedback-I2BLXMGH.js} +10 -10
  104. package/dist/cli/git-2LNT43A2.js +25 -0
  105. package/dist/cli/{git-L5XKAODI.mjs → git-ARG223MY.mjs} +5 -5
  106. package/dist/cli/index.js +141 -141
  107. package/dist/cli/index.mjs +43 -43
  108. package/dist/cli/{legacy-noops-DKAZ7JG3.mjs → legacy-noops-24LOAOZN.mjs} +6 -6
  109. package/dist/cli/{legacy-noops-DM66YISP.js → legacy-noops-N7SVA7PL.js} +9 -9
  110. package/dist/cli/{monitors-QXEJI54B.mjs → monitors-RYQFWM2T.mjs} +9 -9
  111. package/dist/cli/{monitors-NKDIH4TY.js → monitors-XNCYLOJM.js} +102 -102
  112. package/dist/cli/{org-NKIIBUNO.js → org-I33TKZXF.js} +74 -74
  113. package/dist/cli/{org-KZQCVREB.mjs → org-ORIH56E5.mjs} +8 -8
  114. package/dist/cli/{pages-UJUFCJEL.js → pages-2UXXGIMF.js} +20 -20
  115. package/dist/cli/{pages-E7IT5SWT.mjs → pages-ME43HSBL.mjs} +8 -8
  116. package/dist/cli/{play-SPI5MO67.js → play-F4QOFU37.js} +338 -338
  117. package/dist/cli/{play-AKL5E2DF.mjs → play-XEKNY46M.mjs} +21 -21
  118. package/dist/cli/{providers-4NVQ3FSC.js → providers-E7DPCBNX.js} +11 -11
  119. package/dist/cli/{providers-6HSSVI74.mjs → providers-XKU44G74.mjs} +8 -8
  120. package/dist/cli/{quickstart-FEQD7S4Z.js → quickstart-ICLF2F6A.js} +6 -6
  121. package/dist/cli/{quickstart-EHLEHSMI.mjs → quickstart-J7NVEXV5.mjs} +4 -4
  122. package/dist/cli/{run-GH6ECTJF.js → run-HJMHUQBN.js} +43 -43
  123. package/dist/cli/{run-IWVM7BD6.mjs → run-MQ5ZONGL.mjs} +25 -25
  124. package/dist/cli/run-identity-G257GQED.js +25 -0
  125. package/dist/cli/{run-identity-MNRZS2N3.mjs → run-identity-MRNCEGV2.mjs} +3 -9
  126. package/dist/cli/{search-X4CDMN7J.mjs → search-GGRC77CV.mjs} +10 -10
  127. package/dist/cli/search-V6IBJ4TX.js +33 -0
  128. package/dist/cli/{search-output-IIYMGZTQ.js → search-output-MXZTZI2P.js} +6 -6
  129. package/dist/cli/{search-output-PJ7N5WUQ.mjs → search-output-NY4GDBRU.mjs} +4 -4
  130. package/dist/cli/{secrets-4YPMC7XZ.mjs → secrets-FA37G4Q2.mjs} +8 -8
  131. package/dist/cli/{secrets-QPP2FXID.js → secrets-PFESG72B.js} +17 -17
  132. package/dist/cli/{sessions-BEOI47VZ.mjs → sessions-BLLXPETU.mjs} +6 -6
  133. package/dist/cli/sessions-DNFTQOQH.js +18 -0
  134. package/dist/cli/{settings-FZDONKPW.js → settings-32VPG4Z2.js} +88 -88
  135. package/dist/cli/{settings-VHULXNY3.mjs → settings-U26S7MPH.mjs} +15 -15
  136. package/dist/cli/{setup-5IV3NHGD.mjs → setup-4AXBCX7C.mjs} +10 -10
  137. package/dist/cli/{setup-LZ6IN5JS.js → setup-R6NSENH7.js} +50 -50
  138. package/dist/cli/skills-G4ZE3OS5.js +37 -0
  139. package/dist/cli/{skills-FZAFBW5J.mjs → skills-JUH7AVUL.mjs} +8 -8
  140. package/dist/cli/tools-27LHZFJD.js +57 -0
  141. package/dist/cli/{tools-TLBH3RFK.mjs → tools-FOYLU3FH.mjs} +19 -19
  142. package/dist/cli/{update-KPLIZYOV.mjs → update-FUVX22VM.mjs} +10 -10
  143. package/dist/cli/update-KNZ7N242.js +35 -0
  144. package/dist/cli/{workflow-ACHPT3DD.js → workflow-JACZW4GJ.js} +19 -19
  145. package/dist/cli/{workflow-GYJOYYWK.mjs → workflow-QLT22BLT.mjs} +9 -9
  146. package/dist/{client-CswZYCGj.d.ts → client-B-2Am2y6.d.ts} +1 -1
  147. package/dist/{client-CpSiHSti.d.mts → client-DA71-2_u.d.mts} +1 -1
  148. package/dist/{client-core-C1xVOg8Y.d.mts → client-core-BXbds1cb.d.mts} +1 -20
  149. package/dist/{client-core-D2pLt36Q.d.ts → client-core-C0IzDKMJ.d.ts} +1 -20
  150. package/dist/index.d.mts +3 -3
  151. package/dist/index.d.ts +3 -3
  152. package/dist/index.js +19 -19
  153. package/dist/index.mjs +8 -8
  154. package/dist/install-integrity.json +114 -122
  155. package/dist/plays/play-description.d.mts +1 -1
  156. package/dist/plays/play-description.d.ts +1 -1
  157. package/dist/plays/run-request.d.mts +1 -1
  158. package/dist/plays/run-request.d.ts +1 -1
  159. package/dist/plays/run-request.js +3 -3
  160. package/dist/plays/run-request.mjs +2 -2
  161. package/dist/release.d.mts +1 -1
  162. package/dist/release.d.ts +1 -1
  163. package/dist/release.js +2 -2
  164. package/dist/release.mjs +1 -1
  165. package/dist/server.d.mts +2 -2
  166. package/dist/server.d.ts +2 -2
  167. package/dist/server.js +7 -7
  168. package/dist/server.mjs +5 -5
  169. package/package.json +1 -1
  170. package/dist/bundling-sources/shared_libs/play-runtime/runtime-app-transport.ts +0 -374
  171. package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-egress.ts +0 -55
  172. package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-profile.ts +0 -329
  173. package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-sandbox-credential.ts +0 -338
  174. package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-staging.ts +0 -417
  175. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-gateway-attempt.ts +0 -81
  176. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-gateway-staging-journal.ts +0 -708
  177. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-gateway-staging-teardown.ts +0 -160
  178. package/dist/cli/auth-DF6WJLN2.js +0 -43
  179. package/dist/cli/describe-EAK3MPTG.js +0 -50
  180. package/dist/cli/git-OOCPCIGZ.js +0 -25
  181. package/dist/cli/run-identity-HFYABUJS.js +0 -31
  182. package/dist/cli/search-NIRYA3VL.js +0 -33
  183. package/dist/cli/sessions-5I2IFTW7.js +0 -18
  184. package/dist/cli/skills-WJWLFSHI.js +0 -37
  185. package/dist/cli/tools-SH35NRGU.js +0 -57
  186. package/dist/cli/update-MA46YSGR.js +0 -35
@@ -1,708 +0,0 @@
1
- import { randomUUID } from 'node:crypto';
2
- import {
3
- assertRuntimeGatewayStagingScope,
4
- isRuntimeGatewayStagingSha256,
5
- isRuntimeGatewayStagingUploadId,
6
- RUNTIME_GATEWAY_STAGING_ERROR_CODES,
7
- RUNTIME_GATEWAY_STAGING_GRANT_MAX_TTL_SECONDS,
8
- RUNTIME_GATEWAY_STAGING_RETIRE_GRACE_SECONDS,
9
- runtimeGatewayStagingObjectKey,
10
- type RuntimeGatewayStagingDirection,
11
- type RuntimeGatewayStagingScope,
12
- } from '../runtime-gateway-staging';
13
-
14
- /**
15
- * Custody journal for app-hosted Runtime gateway staged bodies.
16
- *
17
- * Schema contract: one new table, two partial indexes, and one additive
18
- * nullable column, created with `IF NOT EXISTS` by the deployment migration
19
- * on every run (the common
20
- * migration path, the shared online expansion, and the cold bootstrap). It is
21
- * not a scheduler-shape requirement and not behind the schema marker:
22
- * readiness, admission, and every other runtime path never read it. When it
23
- * is absent, only a staging operation of a pinned run fails, with
24
- * `runtime_gateway_staging_journal_missing`.
25
- *
26
- * Row lifecycle: `reserved` (custody persisted before any upload authority is
27
- * minted) -> `accepting` -> `accepted` | `rejected` -> `deleted`. Every row,
28
- * whatever its state, is retired only after `retire_after` (grant expiry plus
29
- * the gateway invocation ceiling), and is marked deleted only after the
30
- * object store confirms the key absent.
31
- *
32
- * `bucket_fingerprint` records which bucket the reserving process addressed
33
- * (`getR2BucketFingerprint`: SHA-256 of bucket name and endpoint host).
34
- * Teardown refuses to delete or mark deleted a row whose fingerprint differs
35
- * from its own store's, because an absence readback from another bucket
36
- * proves nothing. The column is part of the table's creation: the table has
37
- * never shipped without it, so no migration ever alters a current table.
38
- */
39
-
40
- type QueryClient = {
41
- query<Row extends Record<string, unknown> = Record<string, unknown>>(
42
- sql: string,
43
- params?: unknown[],
44
- ): Promise<{ rows: Row[] }>;
45
- };
46
-
47
- export const RUNTIME_GATEWAY_STAGING_TABLE = 'runtime_gateway_staged_bodies';
48
-
49
- const quote = (value: string) => `"${value.replace(/"/g, '""')}"`;
50
- const relation = (schema: string) =>
51
- `${quote(schema)}.${quote(RUNTIME_GATEWAY_STAGING_TABLE)}`;
52
-
53
- /**
54
- * Index names are schema-local, so they carry no schema prefix: a prefixed
55
- * name longer than Postgres' 63-byte identifier limit is truncated, and for a
56
- * long schema name both indexes truncated to the same name, so `IF NOT
57
- * EXISTS` silently skipped the second one.
58
- */
59
- export const RUNTIME_GATEWAY_STAGING_RETIRE_INDEX =
60
- 'runtime_gateway_staged_bodies_retire_idx';
61
- export const RUNTIME_GATEWAY_STAGING_DELETED_INDEX =
62
- 'runtime_gateway_staged_bodies_deleted_idx';
63
-
64
- /** Deployment-owned additive DDL. Request paths never run it. */
65
- export function runtimeGatewayStagingSchemaStatements(
66
- schema: string,
67
- ): string[] {
68
- return [
69
- `CREATE TABLE IF NOT EXISTS ${relation(schema)} (
70
- upload_id text PRIMARY KEY,
71
- org_id text NOT NULL,
72
- run_id text NOT NULL,
73
- attempt integer NOT NULL CHECK (attempt >= 0),
74
- direction text NOT NULL CHECK (direction IN ('request', 'response')),
75
- object_key text NOT NULL UNIQUE,
76
- sha256 text NOT NULL CHECK (sha256 ~ '^[0-9a-f]{64}$'),
77
- byte_length integer NOT NULL CHECK (byte_length > 0),
78
- state text NOT NULL CHECK (state IN ('reserved', 'accepting', 'accepted', 'rejected', 'deleted')),
79
- bucket_fingerprint text,
80
- grant_expires_at timestamptz NOT NULL,
81
- retire_after timestamptz NOT NULL,
82
- retire_claim_token text,
83
- retire_claimed_at timestamptz,
84
- consumed_at timestamptz,
85
- deleted_at timestamptz,
86
- created_at timestamptz NOT NULL DEFAULT now(),
87
- updated_at timestamptz NOT NULL DEFAULT now(),
88
- CHECK (retire_after > grant_expires_at),
89
- CHECK ((retire_claim_token IS NULL) = (retire_claimed_at IS NULL)),
90
- CHECK ((state = 'deleted') = (deleted_at IS NOT NULL))
91
- )`,
92
- `CREATE INDEX IF NOT EXISTS ${quote(RUNTIME_GATEWAY_STAGING_RETIRE_INDEX)}
93
- ON ${relation(schema)} (retire_after) WHERE state <> 'deleted'`,
94
- `CREATE INDEX IF NOT EXISTS ${quote(RUNTIME_GATEWAY_STAGING_DELETED_INDEX)}
95
- ON ${relation(schema)} (deleted_at) WHERE state = 'deleted'`,
96
- ];
97
- }
98
-
99
- /** Install the journal. Idempotent; never touches an existing table. */
100
- export async function ensureRuntimeGatewayStagingSchema(
101
- client: QueryClient,
102
- options: { schema: string },
103
- ): Promise<void> {
104
- for (const statement of runtimeGatewayStagingSchemaStatements(
105
- options.schema,
106
- )) {
107
- await client.query(statement);
108
- }
109
- }
110
-
111
- /** Upper bound on schemas probed by one discovery statement. */
112
- export const RUNTIME_GATEWAY_STAGING_DISCOVERY_MAX_PAGE_SIZE = 512;
113
-
114
- export type RuntimeGatewayStagingActionableSchema = Readonly<{
115
- schema: string;
116
- /** When this schema's oldest actionable row became due. */
117
- dueAt: Date;
118
- }>;
119
-
120
- export type RuntimeGatewayStagingDiscoveryPage = Readonly<{
121
- /** Schemas in this page with a due retirement or a prunable deleted row. */
122
- actionable: readonly RuntimeGatewayStagingActionableSchema[];
123
- /** Keyset cursor for the next page; null after the last page. */
124
- nextAfterSchema: string | null;
125
- }>;
126
-
127
- /** Due-time probe for one schema: one ordered seek per partial index. */
128
- function stagingDueProbeSql(
129
- table: string,
130
- schemaParam: string,
131
- retentionParam: string,
132
- ) {
133
- return `(SELECT ${schemaParam}::text AS schema, LEAST(
134
- (SELECT retire_after FROM ${table}
135
- WHERE state <> 'deleted' AND retire_after < now()
136
- ORDER BY retire_after LIMIT 1),
137
- (SELECT deleted_at + make_interval(secs => ${retentionParam}::double precision)
138
- FROM ${table}
139
- WHERE state = 'deleted'
140
- AND deleted_at < now() - make_interval(secs => ${retentionParam}::double precision)
141
- ORDER BY deleted_at LIMIT 1)
142
- ) AS due_at)`;
143
- }
144
-
145
- function decodeDueRows(
146
- rows: Array<{ schema: string; due_at: Date | string | null }>,
147
- ): RuntimeGatewayStagingActionableSchema[] {
148
- return rows
149
- .filter((row) => row.due_at != null)
150
- .map((row) =>
151
- Object.freeze({ schema: row.schema, dueAt: new Date(row.due_at!) }),
152
- );
153
- }
154
-
155
- async function probeStagingSchemas(
156
- client: QueryClient,
157
- schemas: readonly string[],
158
- prunableOlderThanSeconds: number,
159
- ): Promise<RuntimeGatewayStagingActionableSchema[]> {
160
- const probes = schemas.map((schema, index) =>
161
- stagingDueProbeSql(relation(schema), `$${index + 2}`, '$1'),
162
- );
163
- const result = await client.query<{
164
- schema: string;
165
- due_at: Date | string | null;
166
- }>(probes.join('\n UNION ALL \n'), [prunableOlderThanSeconds, ...schemas]);
167
- return decodeDueRows(result.rows);
168
- }
169
-
170
- /**
171
- * One keyset page of the scheduler schemas on this database that carry the
172
- * journal (byte order, strictly after `afterSchema`), narrowed to those with
173
- * actionable work: a non-deleted row past `retire_after`, or a deleted row
174
- * past its retention. Every schema in the page costs one ordered seek on each
175
- * partial index, all in one statement, so a caller pages the whole catalog
176
- * without ever planning a claim on an idle schema. A schema dropped while the
177
- * page was probed is skipped, not fatal.
178
- */
179
- export async function listActionableRuntimeGatewayStagingSchemas(
180
- client: QueryClient,
181
- input: {
182
- afterSchema: string | null;
183
- pageSize: number;
184
- prunableOlderThanSeconds: number;
185
- },
186
- ): Promise<RuntimeGatewayStagingDiscoveryPage> {
187
- if (
188
- !Number.isSafeInteger(input.pageSize) ||
189
- input.pageSize < 1 ||
190
- input.pageSize > RUNTIME_GATEWAY_STAGING_DISCOVERY_MAX_PAGE_SIZE
191
- ) {
192
- throw new Error('Runtime gateway staging discovery page size is invalid.');
193
- }
194
- if (
195
- !Number.isFinite(input.prunableOlderThanSeconds) ||
196
- input.prunableOlderThanSeconds < 0
197
- ) {
198
- throw new Error('Runtime gateway staging retention is invalid.');
199
- }
200
- const catalog = await client.query<{ schema: string }>(
201
- `SELECT namespace.nspname::text AS schema
202
- FROM pg_catalog.pg_class AS relation
203
- JOIN pg_catalog.pg_namespace AS namespace
204
- ON namespace.oid = relation.relnamespace
205
- WHERE relation.relname = $1 AND relation.relkind IN ('r', 'p')
206
- AND ($2::text IS NULL
207
- OR namespace.nspname::text COLLATE "C" > $2::text COLLATE "C")
208
- ORDER BY namespace.nspname::text COLLATE "C"
209
- LIMIT $3`,
210
- [RUNTIME_GATEWAY_STAGING_TABLE, input.afterSchema, input.pageSize],
211
- );
212
- const schemas = catalog.rows.map((row) => row.schema);
213
- const nextAfterSchema =
214
- schemas.length === input.pageSize ? schemas[schemas.length - 1]! : null;
215
- if (schemas.length === 0) return { actionable: [], nextAfterSchema };
216
- let actionable: RuntimeGatewayStagingActionableSchema[];
217
- try {
218
- actionable = await probeStagingSchemas(
219
- client,
220
- schemas,
221
- input.prunableOlderThanSeconds,
222
- );
223
- } catch (error) {
224
- if (!isUndefinedTable(error)) throw error;
225
- // A Preview estate was dropped between the catalog read and the probe.
226
- // Probe the page one schema at a time and skip the ones that are gone.
227
- actionable = [];
228
- for (const schema of schemas) {
229
- try {
230
- actionable.push(
231
- ...(await probeStagingSchemas(
232
- client,
233
- [schema],
234
- input.prunableOlderThanSeconds,
235
- )),
236
- );
237
- } catch (probeError) {
238
- if (!isUndefinedTable(probeError)) throw probeError;
239
- }
240
- }
241
- }
242
- return { actionable, nextAfterSchema };
243
- }
244
-
245
- /** The pinned run cannot stage: the deployment has not installed the journal. */
246
- export class RuntimeGatewayStagingJournalMissingError extends Error {
247
- readonly code = RUNTIME_GATEWAY_STAGING_ERROR_CODES.journalMissing;
248
- constructor(schema: string) {
249
- super(
250
- `${RUNTIME_GATEWAY_STAGING_ERROR_CODES.journalMissing}: scheduler schema ${schema} has no ${RUNTIME_GATEWAY_STAGING_TABLE} table; run the runtime scheduler migration.`,
251
- );
252
- this.name = 'RuntimeGatewayStagingJournalMissingError';
253
- }
254
- }
255
-
256
- function isUndefinedTable(error: unknown): boolean {
257
- return (
258
- !!error &&
259
- typeof error === 'object' &&
260
- (error as { code?: unknown }).code === '42P01'
261
- );
262
- }
263
-
264
- export type RuntimeGatewayStagedBody = Readonly<{
265
- uploadId: string;
266
- scope: RuntimeGatewayStagingScope;
267
- direction: RuntimeGatewayStagingDirection;
268
- objectKey: string;
269
- sha256: string;
270
- byteLength: number;
271
- state: 'reserved' | 'accepting' | 'accepted' | 'rejected' | 'deleted';
272
- grantExpiresAt: Date;
273
- retireAfter: Date;
274
- retireClaimToken: string | null;
275
- /** Null only for rows reserved before the column existed. */
276
- bucketFingerprint: string | null;
277
- }>;
278
-
279
- type Row = {
280
- upload_id: string;
281
- org_id: string;
282
- run_id: string;
283
- attempt: number;
284
- direction: RuntimeGatewayStagingDirection;
285
- object_key: string;
286
- sha256: string;
287
- byte_length: number | string;
288
- state: RuntimeGatewayStagedBody['state'];
289
- grant_expires_at: Date | string;
290
- retire_after: Date | string;
291
- retire_claim_token: string | null;
292
- bucket_fingerprint?: string | null;
293
- };
294
-
295
- function decode(row: Row): RuntimeGatewayStagedBody {
296
- return Object.freeze({
297
- uploadId: row.upload_id,
298
- scope: Object.freeze({
299
- orgId: row.org_id,
300
- runId: row.run_id,
301
- attempt: Number(row.attempt),
302
- }),
303
- direction: row.direction,
304
- objectKey: row.object_key,
305
- sha256: row.sha256,
306
- byteLength: Number(row.byte_length),
307
- state: row.state,
308
- grantExpiresAt: new Date(row.grant_expires_at),
309
- retireAfter: new Date(row.retire_after),
310
- retireClaimToken: row.retire_claim_token,
311
- bucketFingerprint: row.bucket_fingerprint ?? null,
312
- });
313
- }
314
-
315
- const SCOPE_WHERE = `upload_id = $1 AND org_id = $2 AND run_id = $3 AND attempt = $4`;
316
-
317
- /**
318
- * Row operations only: no method performs object-storage I/O. Callers
319
- * authenticate the scope (executor token claims) before any call.
320
- */
321
- export class RuntimeGatewayStagingJournal {
322
- private readonly table: string;
323
-
324
- constructor(
325
- private readonly client: QueryClient,
326
- private readonly schema: string,
327
- ) {
328
- this.table = relation(schema);
329
- }
330
-
331
- /**
332
- * True when this schema's journal is current (table and every column this
333
- * build writes). One catalog read; request paths call it before handing a
334
- * staging-capable request to the gateway, never DDL.
335
- */
336
- async isInstalled(): Promise<boolean> {
337
- const result = await this.client.query<{ installed: boolean }>(
338
- `SELECT EXISTS (
339
- SELECT 1 FROM pg_catalog.pg_attribute AS attribute
340
- JOIN pg_catalog.pg_class AS relation ON relation.oid = attribute.attrelid
341
- JOIN pg_catalog.pg_namespace AS namespace
342
- ON namespace.oid = relation.relnamespace
343
- WHERE namespace.nspname = $1 AND relation.relname = $2
344
- AND attribute.attname = 'bucket_fingerprint'
345
- AND NOT attribute.attisdropped
346
- ) AS installed`,
347
- [this.schema, RUNTIME_GATEWAY_STAGING_TABLE],
348
- );
349
- return result.rows[0]?.installed === true;
350
- }
351
-
352
- private async run<T extends Record<string, unknown>>(
353
- sql: string,
354
- params: unknown[],
355
- ): Promise<{ rows: T[] }> {
356
- try {
357
- return await this.client.query<T>(sql, params);
358
- } catch (error) {
359
- if (isUndefinedTable(error)) {
360
- throw new RuntimeGatewayStagingJournalMissingError(this.schema);
361
- }
362
- throw error;
363
- }
364
- }
365
-
366
- /**
367
- * Persist custody, including the grant's exact expiry, before any upload
368
- * authority exists. A caller mints its presigned URL only after this
369
- * returns, with a lifetime no later than `grantExpiresAt`.
370
- */
371
- async reserve(input: {
372
- scope: RuntimeGatewayStagingScope;
373
- direction: RuntimeGatewayStagingDirection;
374
- sha256: string;
375
- byteLength: number;
376
- maxBytes: number;
377
- grantTtlSeconds: number;
378
- /** The store's `getR2BucketFingerprint`, persisted with custody. */
379
- bucketFingerprint: string;
380
- }): Promise<RuntimeGatewayStagedBody> {
381
- assertRuntimeGatewayStagingScope(input.scope);
382
- if (!isRuntimeGatewayStagingSha256(input.sha256)) {
383
- throw new Error('Runtime gateway staging digest is invalid.');
384
- }
385
- if (
386
- !Number.isSafeInteger(input.byteLength) ||
387
- input.byteLength < 1 ||
388
- input.byteLength > input.maxBytes
389
- ) {
390
- throw new Error('Runtime gateway staging size is outside its bound.');
391
- }
392
- if (
393
- !Number.isSafeInteger(input.grantTtlSeconds) ||
394
- input.grantTtlSeconds < 1 ||
395
- input.grantTtlSeconds > RUNTIME_GATEWAY_STAGING_GRANT_MAX_TTL_SECONDS
396
- ) {
397
- throw new Error('Runtime gateway staging grant lifetime is invalid.');
398
- }
399
- if (!/^[0-9a-f]{64}$/.test(input.bucketFingerprint)) {
400
- throw new Error('Runtime gateway staging bucket fingerprint is invalid.');
401
- }
402
- const uploadId = randomUUID();
403
- const objectKey = runtimeGatewayStagingObjectKey(
404
- input.scope,
405
- input.direction,
406
- uploadId,
407
- );
408
- const result = await this.run<Row>(
409
- `INSERT INTO ${this.table}
410
- (upload_id, org_id, run_id, attempt, direction, object_key, sha256,
411
- byte_length, state, grant_expires_at, retire_after,
412
- bucket_fingerprint)
413
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, 'reserved',
414
- now() + make_interval(secs => $9::double precision),
415
- now() + make_interval(secs => $10::double precision), $11)
416
- RETURNING *`,
417
- [
418
- uploadId,
419
- input.scope.orgId,
420
- input.scope.runId,
421
- input.scope.attempt,
422
- input.direction,
423
- objectKey,
424
- input.sha256,
425
- input.byteLength,
426
- input.grantTtlSeconds,
427
- input.grantTtlSeconds + RUNTIME_GATEWAY_STAGING_RETIRE_GRACE_SECONDS,
428
- input.bucketFingerprint,
429
- ],
430
- );
431
- return decode(result.rows[0]!);
432
- }
433
-
434
- /**
435
- * Take the one consumption of a reserved request upload in this exact run
436
- * attempt while its grant is live. Null when unknown, out of scope,
437
- * already consumed, or expired (retirement may already be deleting it).
438
- */
439
- async claimAccept(input: {
440
- scope: RuntimeGatewayStagingScope;
441
- uploadId: string;
442
- }): Promise<RuntimeGatewayStagedBody | null> {
443
- if (!isRuntimeGatewayStagingUploadId(input.uploadId)) return null;
444
- const result = await this.run<Row>(
445
- `UPDATE ${this.table} SET state = 'accepting', updated_at = now()
446
- WHERE ${SCOPE_WHERE} AND direction = 'request' AND state = 'reserved'
447
- AND grant_expires_at > now()
448
- RETURNING *`,
449
- [
450
- input.uploadId,
451
- input.scope.orgId,
452
- input.scope.runId,
453
- input.scope.attempt,
454
- ],
455
- );
456
- return result.rows[0] ? decode(result.rows[0]) : null;
457
- }
458
-
459
- /** Verified bytes were handed to the gateway, or a response was stored. */
460
- async markAccepted(body: RuntimeGatewayStagedBody): Promise<boolean> {
461
- const result = await this.run<Row>(
462
- `UPDATE ${this.table}
463
- SET state = 'accepted', consumed_at = now(), updated_at = now()
464
- WHERE ${SCOPE_WHERE} AND state IN ('reserved', 'accepting')
465
- RETURNING upload_id`,
466
- [body.uploadId, body.scope.orgId, body.scope.runId, body.scope.attempt],
467
- );
468
- return result.rows.length === 1;
469
- }
470
-
471
- /** Stored bytes failed their integrity check; never consumable again. */
472
- async markRejected(body: RuntimeGatewayStagedBody): Promise<boolean> {
473
- const result = await this.run<Row>(
474
- `UPDATE ${this.table} SET state = 'rejected', updated_at = now()
475
- WHERE ${SCOPE_WHERE} AND state = 'accepting'
476
- RETURNING upload_id`,
477
- [body.uploadId, body.scope.orgId, body.scope.runId, body.scope.attempt],
478
- );
479
- return result.rows.length === 1;
480
- }
481
-
482
- /**
483
- * An ambiguous read: hand the upload back so nothing is lost. The client
484
- * retries with a fresh upload; retirement covers this row either way.
485
- */
486
- async releaseAccept(body: RuntimeGatewayStagedBody): Promise<boolean> {
487
- const result = await this.run<Row>(
488
- `UPDATE ${this.table} SET state = 'reserved', updated_at = now()
489
- WHERE ${SCOPE_WHERE} AND state = 'accepting'
490
- RETURNING upload_id`,
491
- [body.uploadId, body.scope.orgId, body.scope.runId, body.scope.attempt],
492
- );
493
- return result.rows.length === 1;
494
- }
495
-
496
- /**
497
- * Idle probe for `claimRetirements`: true when a non-deleted row is past
498
- * `retire_after`. A superset of the claim's predicates, served by the same
499
- * partial index as an ordered seek (a scalar subquery, never `EXISTS`), so
500
- * an idle pass never plans the claim statement.
501
- */
502
- async hasDueRetirement(): Promise<boolean> {
503
- const result = await this.run<{ due: Date | string | null }>(
504
- `SELECT (
505
- SELECT retire_after FROM ${this.table}
506
- WHERE state <> 'deleted' AND retire_after < now()
507
- ORDER BY retire_after
508
- LIMIT 1
509
- ) AS due`,
510
- [],
511
- );
512
- return result.rows[0]?.due != null;
513
- }
514
-
515
- /** Idle probe for `pruneDeleted`, on the deleted-rows partial index. */
516
- async hasPrunableDeleted(olderThanSeconds: number): Promise<boolean> {
517
- const result = await this.run<{ due: Date | string | null }>(
518
- `SELECT (
519
- SELECT deleted_at FROM ${this.table}
520
- WHERE state = 'deleted'
521
- AND deleted_at < now() - make_interval(secs => $1::double precision)
522
- ORDER BY deleted_at
523
- LIMIT 1
524
- ) AS due`,
525
- [olderThanSeconds],
526
- );
527
- return result.rows[0]?.due != null;
528
- }
529
-
530
- /**
531
- * Claim actionable retirements only: rows past `retire_after` that are not
532
- * deleted and not held by a live claim. Bounded and skip-locked, so
533
- * concurrent sweepers split the work.
534
- */
535
- async claimRetirements(limit: number): Promise<RuntimeGatewayStagedBody[]> {
536
- if (!Number.isSafeInteger(limit) || limit < 1 || limit > 64) {
537
- throw new Error('Runtime gateway staging retirement limit is invalid.');
538
- }
539
- const result = await this.run<Row>(
540
- `WITH due AS (
541
- SELECT upload_id FROM ${this.table}
542
- WHERE state <> 'deleted' AND retire_after < now()
543
- AND (retire_claim_token IS NULL
544
- OR retire_claimed_at < now() - interval '5 minutes')
545
- ORDER BY retire_after
546
- LIMIT $1
547
- FOR UPDATE SKIP LOCKED
548
- )
549
- UPDATE ${this.table} AS staged
550
- SET retire_claim_token = $2, retire_claimed_at = now(), updated_at = now()
551
- FROM due WHERE staged.upload_id = due.upload_id
552
- RETURNING staged.*`,
553
- [limit, randomUUID()],
554
- );
555
- return result.rows.map(decode);
556
- }
557
-
558
- /** Call only after the object store confirmed this exact key absent. */
559
- async confirmDeleted(body: RuntimeGatewayStagedBody): Promise<boolean> {
560
- if (!body.retireClaimToken) return false;
561
- const result = await this.run<Row>(
562
- `UPDATE ${this.table}
563
- SET state = 'deleted', deleted_at = now(), retire_claim_token = NULL,
564
- retire_claimed_at = NULL, updated_at = now()
565
- WHERE upload_id = $1 AND retire_claim_token = $2 AND state <> 'deleted'
566
- AND retire_after < now()
567
- RETURNING upload_id`,
568
- [body.uploadId, body.retireClaimToken],
569
- );
570
- return result.rows.length === 1;
571
- }
572
-
573
- /** A failed or ambiguous delete keeps the row for the next sweep. */
574
- async releaseRetirement(body: RuntimeGatewayStagedBody): Promise<boolean> {
575
- if (!body.retireClaimToken) return false;
576
- const result = await this.run<Row>(
577
- `UPDATE ${this.table}
578
- SET retire_claim_token = NULL, retire_claimed_at = NULL, updated_at = now()
579
- WHERE upload_id = $1 AND retire_claim_token = $2
580
- RETURNING upload_id`,
581
- [body.uploadId, body.retireClaimToken],
582
- );
583
- return result.rows.length === 1;
584
- }
585
-
586
- /**
587
- * Hand back claims a pass will not process (its deadline arrived), in one
588
- * statement, so they are claimable by the next pass at once rather than
589
- * after the stale-claim window.
590
- */
591
- async releaseRetirements(
592
- bodies: readonly RuntimeGatewayStagedBody[],
593
- ): Promise<number> {
594
- const held = bodies.filter((body) => body.retireClaimToken);
595
- if (held.length === 0) return 0;
596
- const result = await this.run<Row>(
597
- `UPDATE ${this.table} AS staged
598
- SET retire_claim_token = NULL, retire_claimed_at = NULL, updated_at = now()
599
- FROM unnest($1::text[], $2::text[]) AS released(upload_id, token)
600
- WHERE staged.upload_id = released.upload_id
601
- AND staged.retire_claim_token = released.token
602
- RETURNING staged.upload_id`,
603
- [
604
- held.map((body) => body.uploadId),
605
- held.map((body) => body.retireClaimToken),
606
- ],
607
- );
608
- return result.rows.length;
609
- }
610
-
611
- /** Drop bounded batches of long-deleted custody rows. */
612
- async pruneDeleted(input: {
613
- olderThanSeconds: number;
614
- limit: number;
615
- }): Promise<number> {
616
- const result = await this.run<Row>(
617
- `DELETE FROM ${this.table} WHERE upload_id IN (
618
- SELECT upload_id FROM ${this.table}
619
- WHERE state = 'deleted'
620
- AND deleted_at < now() - make_interval(secs => $1::double precision)
621
- ORDER BY deleted_at LIMIT $2
622
- ) RETURNING upload_id`,
623
- [input.olderThanSeconds, input.limit],
624
- );
625
- return result.rows.length;
626
- }
627
-
628
- /**
629
- * Teardown only: the number of rows whose object is not yet confirmed
630
- * absent, or null when the journal table does not exist.
631
- */
632
- async countUnconfirmedCustody(): Promise<number | null> {
633
- try {
634
- const result = await this.client.query<{ count: string | number }>(
635
- `SELECT count(*) AS count FROM ${this.table} WHERE state <> 'deleted'`,
636
- [],
637
- );
638
- return Number(result.rows[0]?.count ?? 0);
639
- } catch (error) {
640
- if (isUndefinedTable(error)) return null;
641
- throw error;
642
- }
643
- }
644
-
645
- /**
646
- * Teardown only: claim undeleted rows whose upload grant has expired,
647
- * regardless of `retire_after`. The caller has quiesced every writer of
648
- * this schema and is about to drop it. A row whose grant is still live is
649
- * never claimed: its presigned PUT could recreate the key after a delete,
650
- * so it stays unconfirmed and the teardown refuses the drop until it
651
- * expires.
652
- */
653
- async claimForcedRetirements(
654
- limit: number,
655
- excludeUploadIds: readonly string[] = [],
656
- ): Promise<RuntimeGatewayStagedBody[]> {
657
- if (!Number.isSafeInteger(limit) || limit < 1 || limit > 64) {
658
- throw new Error('Runtime gateway staging retirement limit is invalid.');
659
- }
660
- const result = await this.run<Row>(
661
- `WITH held AS (
662
- SELECT upload_id FROM ${this.table}
663
- WHERE state <> 'deleted' AND grant_expires_at <= now()
664
- AND NOT (upload_id = ANY($3::text[]))
665
- ORDER BY created_at
666
- LIMIT $1
667
- FOR UPDATE SKIP LOCKED
668
- )
669
- UPDATE ${this.table} AS staged
670
- SET retire_claim_token = $2, retire_claimed_at = now(), updated_at = now()
671
- FROM held WHERE staged.upload_id = held.upload_id
672
- RETURNING staged.*`,
673
- [limit, randomUUID(), [...excludeUploadIds]],
674
- );
675
- return result.rows.map(decode);
676
- }
677
-
678
- /**
679
- * Teardown only: after confirmed absence in the bucket `bucketFingerprint`
680
- * names, whatever `retire_after` says. A row reserved against another
681
- * bucket is never marked deleted.
682
- */
683
- async confirmForcedDeleted(
684
- body: RuntimeGatewayStagedBody,
685
- bucketFingerprint: string,
686
- ): Promise<boolean> {
687
- if (!body.retireClaimToken) return false;
688
- const result = await this.run<Row>(
689
- `UPDATE ${this.table}
690
- SET state = 'deleted', deleted_at = now(), retire_claim_token = NULL,
691
- retire_claimed_at = NULL, updated_at = now()
692
- WHERE upload_id = $1 AND retire_claim_token = $2 AND state <> 'deleted'
693
- AND grant_expires_at <= now()
694
- AND (bucket_fingerprint IS NULL OR bucket_fingerprint = $3)
695
- RETURNING upload_id`,
696
- [body.uploadId, body.retireClaimToken, bucketFingerprint],
697
- );
698
- return result.rows.length === 1;
699
- }
700
-
701
- async get(uploadId: string): Promise<RuntimeGatewayStagedBody | null> {
702
- const result = await this.run<Row>(
703
- `SELECT * FROM ${this.table} WHERE upload_id = $1`,
704
- [uploadId],
705
- );
706
- return result.rows[0] ? decode(result.rows[0]) : null;
707
- }
708
- }