rampway 0.2.6 → 0.3.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.
Files changed (85) hide show
  1. package/README.md +41 -0
  2. package/build/src/cli.d.ts.map +1 -1
  3. package/build/src/cli.js +35 -7
  4. package/build/src/cli.js.map +1 -1
  5. package/build/src/commands/task.d.ts +9 -0
  6. package/build/src/commands/task.d.ts.map +1 -0
  7. package/build/src/commands/task.js +23 -0
  8. package/build/src/commands/task.js.map +1 -0
  9. package/build/src/config/validate-config.d.ts +5 -0
  10. package/build/src/config/validate-config.d.ts.map +1 -1
  11. package/build/src/config/validate-config.js +139 -0
  12. package/build/src/config/validate-config.js.map +1 -1
  13. package/build/src/core/deploy-runner.js +5 -5
  14. package/build/src/core/deploy-runner.js.map +1 -1
  15. package/build/src/core/locks.d.ts +2 -1
  16. package/build/src/core/locks.d.ts.map +1 -1
  17. package/build/src/core/locks.js +28 -9
  18. package/build/src/core/locks.js.map +1 -1
  19. package/build/src/core/operational-task-runner.d.ts +21 -0
  20. package/build/src/core/operational-task-runner.d.ts.map +1 -0
  21. package/build/src/core/operational-task-runner.js +66 -0
  22. package/build/src/core/operational-task-runner.js.map +1 -0
  23. package/build/src/core/redaction.d.ts +31 -3
  24. package/build/src/core/redaction.d.ts.map +1 -1
  25. package/build/src/core/redaction.js +83 -5
  26. package/build/src/core/redaction.js.map +1 -1
  27. package/build/src/core/release-manager.d.ts +11 -0
  28. package/build/src/core/release-manager.d.ts.map +1 -1
  29. package/build/src/core/release-manager.js +22 -0
  30. package/build/src/core/release-manager.js.map +1 -1
  31. package/build/src/core/task-runner.d.ts +4 -2
  32. package/build/src/core/task-runner.d.ts.map +1 -1
  33. package/build/src/core/task-runner.js +34 -8
  34. package/build/src/core/task-runner.js.map +1 -1
  35. package/build/src/transports/local-transport.d.ts +19 -2
  36. package/build/src/transports/local-transport.d.ts.map +1 -1
  37. package/build/src/transports/local-transport.js +97 -9
  38. package/build/src/transports/local-transport.js.map +1 -1
  39. package/build/src/transports/ssh-transport.d.ts +43 -4
  40. package/build/src/transports/ssh-transport.d.ts.map +1 -1
  41. package/build/src/transports/ssh-transport.js +105 -12
  42. package/build/src/transports/ssh-transport.js.map +1 -1
  43. package/build/src/types.d.ts +20 -0
  44. package/build/src/types.d.ts.map +1 -1
  45. package/build/src/velocious/auth.d.ts +17 -0
  46. package/build/src/velocious/auth.d.ts.map +1 -0
  47. package/build/src/velocious/auth.js +30 -0
  48. package/build/src/velocious/auth.js.map +1 -0
  49. package/build/src/velocious/control-plane.d.ts +155 -0
  50. package/build/src/velocious/control-plane.d.ts.map +1 -0
  51. package/build/src/velocious/control-plane.js +275 -0
  52. package/build/src/velocious/control-plane.js.map +1 -0
  53. package/build/src/velocious/controller.d.ts +39 -0
  54. package/build/src/velocious/controller.d.ts.map +1 -0
  55. package/build/src/velocious/controller.js +86 -0
  56. package/build/src/velocious/controller.js.map +1 -0
  57. package/build/src/velocious/executor.d.ts +55 -0
  58. package/build/src/velocious/executor.d.ts.map +1 -0
  59. package/build/src/velocious/executor.js +142 -0
  60. package/build/src/velocious/executor.js.map +1 -0
  61. package/build/src/velocious/index.d.ts +28 -0
  62. package/build/src/velocious/index.d.ts.map +1 -0
  63. package/build/src/velocious/index.js +141 -0
  64. package/build/src/velocious/index.js.map +1 -0
  65. package/build/src/velocious/path-matcher.d.ts +18 -0
  66. package/build/src/velocious/path-matcher.d.ts.map +1 -0
  67. package/build/src/velocious/path-matcher.js +48 -0
  68. package/build/src/velocious/path-matcher.js.map +1 -0
  69. package/build/src/velocious/registry.d.ts +19 -0
  70. package/build/src/velocious/registry.d.ts.map +1 -0
  71. package/build/src/velocious/registry.js +36 -0
  72. package/build/src/velocious/registry.js.map +1 -0
  73. package/build/src/velocious/run-store.d.ts +297 -0
  74. package/build/src/velocious/run-store.d.ts.map +1 -0
  75. package/build/src/velocious/run-store.js +482 -0
  76. package/build/src/velocious/run-store.js.map +1 -0
  77. package/build/src/velocious/sanitize.d.ts +23 -0
  78. package/build/src/velocious/sanitize.d.ts.map +1 -0
  79. package/build/src/velocious/sanitize.js +154 -0
  80. package/build/src/velocious/sanitize.js.map +1 -0
  81. package/docs/config-reference.md +42 -0
  82. package/docs/docker-development-environment.md +103 -0
  83. package/docs/migration-from-capistrano.md +25 -3
  84. package/docs/velocious-deployment-api.md +189 -0
  85. package/package.json +22 -3
@@ -0,0 +1,482 @@
1
+ // @ts-check
2
+ import { createHash, randomUUID } from "node:crypto";
3
+ import TableData from "velocious/build/src/database/table-data/index.js";
4
+ import TableIndex from "velocious/build/src/database/table-data/table-index.js";
5
+ /**
6
+ * @typedef {object} DeploymentRunRow
7
+ * @property {string} id
8
+ * @property {string} mountIdentifier
9
+ * @property {string} project
10
+ * @property {string} stage
11
+ * @property {string} revision
12
+ * @property {string} idempotencyKey
13
+ * @property {string} status
14
+ * @property {any} result
15
+ * @property {any} error
16
+ * @property {number} requestedAtMs
17
+ * @property {number|null} startedAtMs
18
+ * @property {number|null} finishedAtMs
19
+ * @property {string|null} ownerToken
20
+ * @property {number|null} heartbeatAtMs
21
+ */
22
+ /**
23
+ * @typedef {object} DeploymentRunStoreContract
24
+ * @property {(id: string) => Promise<DeploymentRunRow|null>} findRunById
25
+ * @property {(key: string) => Promise<DeploymentRunRow|null>} findRunByKey
26
+ * @property {(args: {idempotencyKey: string, project: string, revision: string, stage: string}) => Promise<{outcome: string, run: DeploymentRunRow|null}>} createRunIfPossible
27
+ * @property {(args: {id: string, startedAtMs: number}) => Promise<void>} markRunning
28
+ * @property {(args: {id: string, heartbeatAtMs: number}) => Promise<void>} heartbeat
29
+ * @property {(args: {id: string, ownerToken: string, finishedAtMs: number, result: any}) => Promise<void>} markSucceeded
30
+ * @property {(args: {id: string, ownerToken: string, finishedAtMs: number, error: any}) => Promise<void>} markFailed
31
+ * @property {(args: {id: string, ownerToken: string, finishedAtMs: number, error: any}) => Promise<void>} markReconciliationRequired
32
+ * @property {(args: {event: string, payload: any, runId: string|null}) => Promise<void>} addAuditEvent
33
+ */
34
+ const RUNS_TABLE = "rampway_deployment_runs";
35
+ const AUDIT_TABLE = "rampway_deployment_api_audit_events";
36
+ const BLOCKING_STATUSES = ["pending", "running", "reconciliation_required"];
37
+ const SCHEMA_LOCK = "rampway-deployment-api:schema-v1";
38
+ const OWNER_TOKEN = randomUUID();
39
+ const activeRunIds = new Set();
40
+ /**
41
+ * @param {string} id - Run id.
42
+ * @returns {void}
43
+ */
44
+ export function registerActiveDeploymentRun(id) { activeRunIds.add(id); }
45
+ /**
46
+ * @param {string} id - Run id.
47
+ * @returns {void}
48
+ */
49
+ export function unregisterActiveDeploymentRun(id) { activeRunIds.delete(id); }
50
+ /**
51
+ * @param {number} staleRunTimeoutMs - Lease duration.
52
+ * @returns {number} Heartbeat interval strictly below the lease.
53
+ */
54
+ export function heartbeatIntervalMs(staleRunTimeoutMs) {
55
+ if (!Number.isSafeInteger(staleRunTimeoutMs) || staleRunTimeoutMs < 4) {
56
+ throw new Error("staleRunTimeoutMs must be an integer of at least 4 milliseconds");
57
+ }
58
+ return Math.max(1, Math.floor(staleRunTimeoutMs / 4));
59
+ }
60
+ /**
61
+ * @param {{activeRunIds: Set<string>, nowMs: number, run: {id: string, heartbeatAtMs: number|null, requestedAtMs: number}, staleRunTimeoutMs: number}} args - Lease data.
62
+ * @returns {boolean} Whether ownership expired.
63
+ */
64
+ export function isRunLeaseExpired({ activeRunIds: localIds, nowMs, run, staleRunTimeoutMs }) {
65
+ if (localIds.has(run.id))
66
+ return false;
67
+ return nowMs - (run.heartbeatAtMs ?? run.requestedAtMs) > staleRunTimeoutMs;
68
+ }
69
+ /**
70
+ * @param {{id: string, mountIdentifier: string, ownerToken: string}} args - Fence identifiers.
71
+ * @returns {Record<string, unknown>} Update conditions.
72
+ */
73
+ export function terminalTransitionConditions({ id, mountIdentifier, ownerToken }) {
74
+ return { id, mount_identifier: mountIdentifier, owner_token: ownerToken, status: "running" };
75
+ }
76
+ /**
77
+ * Includes the observed heartbeat so a concurrent renewal defeats stale reconciliation.
78
+ *
79
+ * @param {{mountIdentifier: string, run: Pick<DeploymentRunRow, 'heartbeatAtMs'|'id'|'ownerToken'|'status'>}} args - Fence data.
80
+ * @returns {Record<string, unknown>} Update conditions.
81
+ */
82
+ export function reconciliationConditions({ mountIdentifier, run }) {
83
+ return {
84
+ heartbeat_at_ms: run.heartbeatAtMs,
85
+ id: run.id,
86
+ mount_identifier: mountIdentifier,
87
+ owner_token: run.ownerToken,
88
+ status: run.status
89
+ };
90
+ }
91
+ /**
92
+ * @param {unknown} value - JSON column.
93
+ * @returns {any} Parsed value.
94
+ */
95
+ function parseJson(value) {
96
+ return typeof value === "string" && value.length > 0 ? JSON.parse(value) : null;
97
+ }
98
+ /** Rampway-owned durable deployment state stored through Velocious's database abstraction. */
99
+ export default class DeploymentRunStore {
100
+ /**
101
+ * @param {object} args - Store options.
102
+ * @param {any} args.configuration - Velocious configuration.
103
+ * @param {string} [args.databaseIdentifier] - Database identifier.
104
+ * @param {string} args.mountIdentifier - Authenticated mount scope.
105
+ * @param {number} args.staleRunTimeoutMs - Lease duration.
106
+ */
107
+ constructor({ configuration, databaseIdentifier = "default", mountIdentifier, staleRunTimeoutMs }) {
108
+ if (!mountIdentifier)
109
+ throw new Error("DeploymentRunStore requires a mountIdentifier");
110
+ heartbeatIntervalMs(staleRunTimeoutMs);
111
+ this.configuration = configuration;
112
+ this.databaseIdentifier = databaseIdentifier;
113
+ this.mountIdentifier = mountIdentifier;
114
+ this.staleRunTimeoutMs = staleRunTimeoutMs;
115
+ /** @type {Promise<void>|null} */
116
+ this.readyPromise = null;
117
+ }
118
+ /** @returns {Promise<void>} */
119
+ async ensureReady() {
120
+ if (this.readyPromise)
121
+ return await this.readyPromise;
122
+ this.readyPromise = this._withDb(async (db) => {
123
+ const acquired = await db.acquireAdvisoryLock(SCHEMA_LOCK);
124
+ if (!acquired)
125
+ throw new Error("Failed to acquire Rampway deployment API schema lock");
126
+ try {
127
+ db.clearSchemaCache();
128
+ if (!await db.tableExists(RUNS_TABLE)) {
129
+ const table = new TableData(RUNS_TABLE, { ifNotExists: true });
130
+ table.string("id", { null: false, primaryKey: true });
131
+ table.string("mount_identifier", { maxLength: 64, null: false });
132
+ table.string("project", { null: false, index: true });
133
+ table.string("stage", { null: false });
134
+ table.string("revision", { null: false });
135
+ table.string("idempotency_key", { null: false });
136
+ table.string("status", { null: false, index: true });
137
+ table.text("result_json", { null: true });
138
+ table.text("error_json", { null: true });
139
+ table.bigint("requested_at_ms", { null: false });
140
+ table.bigint("started_at_ms", { null: true });
141
+ table.bigint("finished_at_ms", { null: true });
142
+ table.string("owner_token", { null: true });
143
+ table.bigint("heartbeat_at_ms", { null: true });
144
+ table.addIndex(new TableIndex(["mount_identifier", "idempotency_key"], {
145
+ name: "index_rampway_runs_on_mount_and_key",
146
+ unique: true
147
+ }));
148
+ await db.createTable(table);
149
+ }
150
+ if (!await db.tableExists(AUDIT_TABLE)) {
151
+ const table = new TableData(AUDIT_TABLE, { ifNotExists: true });
152
+ table.string("id", { null: false, primaryKey: true });
153
+ table.string("mount_identifier", { maxLength: 64, null: false });
154
+ table.string("run_id", { null: true, index: true });
155
+ table.string("event", { null: false, index: true });
156
+ table.text("payload_json", { null: true });
157
+ table.bigint("created_at_ms", { null: false });
158
+ await db.createTable(table);
159
+ }
160
+ }
161
+ finally {
162
+ await db.releaseAdvisoryLock(SCHEMA_LOCK);
163
+ }
164
+ });
165
+ try {
166
+ await this.readyPromise;
167
+ }
168
+ finally {
169
+ this.readyPromise = null;
170
+ }
171
+ }
172
+ /**
173
+ * @param {string} id - Run id.
174
+ * @returns {Promise<DeploymentRunRow|null>} Run.
175
+ */
176
+ async findRunById(id) {
177
+ await this.ensureReady();
178
+ return await this._withDb(async (db) => await this._reconcileExpiredRunIfNeeded(db, await this._findRunById(db, id)));
179
+ }
180
+ /**
181
+ * @param {string} key - Idempotency key.
182
+ * @returns {Promise<DeploymentRunRow|null>} Run.
183
+ */
184
+ async findRunByKey(key) {
185
+ await this.ensureReady();
186
+ return await this._withDb(async (db) => await this._reconcileExpiredRunIfNeeded(db, await this._findRunByKey(db, key)));
187
+ }
188
+ /**
189
+ * Serializes admission by target then by mount-global idempotency key.
190
+ *
191
+ * @param {{idempotencyKey: string, project: string, revision: string, stage: string}} args - Run request.
192
+ * @returns {Promise<{outcome: string, run: DeploymentRunRow|null}>} Admission result.
193
+ */
194
+ async createRunIfPossible({ idempotencyKey, project, revision, stage }) {
195
+ await this.ensureReady();
196
+ return await this._withDb(async (db) => {
197
+ const deploymentLock = this._lockName("target", `${project}:${stage}`);
198
+ if (!await db.tryAcquireAdvisoryLock(deploymentLock)) {
199
+ return { outcome: "in_progress", run: await this._findBlockingRun(db, { project, stage }) };
200
+ }
201
+ try {
202
+ const keyLock = this._lockName("key", idempotencyKey);
203
+ await db.acquireAdvisoryLock(keyLock);
204
+ try {
205
+ const keyed = await this._reconcileExpiredRunIfNeeded(db, await this._findRunByKey(db, idempotencyKey));
206
+ if (keyed) {
207
+ const same = keyed.project === project && keyed.stage === stage && keyed.revision === revision;
208
+ return { outcome: same ? "replay" : "conflict", run: keyed };
209
+ }
210
+ let blocking = await this._findBlockingRun(db, { project, stage });
211
+ if (blocking) {
212
+ if (blocking.status === "reconciliation_required")
213
+ return { outcome: "reconciliation_required", run: blocking };
214
+ if (!isRunLeaseExpired({ activeRunIds, nowMs: Date.now(), run: blocking, staleRunTimeoutMs: this.staleRunTimeoutMs })) {
215
+ return { outcome: "in_progress", run: blocking };
216
+ }
217
+ const reconciled = await this._reconcileExpiredRun(db, blocking);
218
+ if (!reconciled) {
219
+ blocking = await this._findBlockingRun(db, { project, stage });
220
+ return { outcome: blocking?.status === "reconciliation_required" ? "reconciliation_required" : "in_progress", run: blocking };
221
+ }
222
+ if (blocking.status === "running") {
223
+ const run = await this._findRunById(db, blocking.id);
224
+ return { outcome: "reconciliation_required", run };
225
+ }
226
+ }
227
+ const id = randomUUID();
228
+ await db.insert({
229
+ tableName: RUNS_TABLE,
230
+ data: {
231
+ error_json: null,
232
+ finished_at_ms: null,
233
+ heartbeat_at_ms: null,
234
+ id,
235
+ idempotency_key: idempotencyKey,
236
+ mount_identifier: this.mountIdentifier,
237
+ owner_token: OWNER_TOKEN,
238
+ project,
239
+ requested_at_ms: Date.now(),
240
+ result_json: null,
241
+ revision,
242
+ stage,
243
+ started_at_ms: null,
244
+ status: "pending"
245
+ }
246
+ });
247
+ const run = await this._findRunById(db, id);
248
+ if (!run)
249
+ throw new Error(`Rampway deployment run ${id} missing after insertion`);
250
+ return { outcome: "created", run };
251
+ }
252
+ finally {
253
+ await db.releaseAdvisoryLock(keyLock);
254
+ }
255
+ }
256
+ finally {
257
+ await db.releaseAdvisoryLock(deploymentLock);
258
+ }
259
+ });
260
+ }
261
+ /** @param {{id: string, startedAtMs: number}} args - Transition. @returns {Promise<void>} */
262
+ async markRunning({ id, startedAtMs }) {
263
+ await this.ensureReady();
264
+ await this._withDb(async (db) => {
265
+ const affected = await db.affectedRows(db.updateSql({
266
+ tableName: RUNS_TABLE,
267
+ data: { heartbeat_at_ms: startedAtMs, started_at_ms: startedAtMs, status: "running" },
268
+ conditions: { id, mount_identifier: this.mountIdentifier, owner_token: OWNER_TOKEN, status: "pending" }
269
+ }));
270
+ if (affected !== 1)
271
+ throw new Error(`Expected one owner-matching pending Rampway deployment run ${id}, updated ${affected}`);
272
+ });
273
+ }
274
+ /** @param {{id: string, heartbeatAtMs: number}} args - Heartbeat. @returns {Promise<void>} */
275
+ async heartbeat({ id, heartbeatAtMs }) {
276
+ await this.ensureReady();
277
+ await this._withDb(async (db) => {
278
+ await db.affectedRows(db.updateSql({
279
+ tableName: RUNS_TABLE,
280
+ data: { heartbeat_at_ms: heartbeatAtMs },
281
+ conditions: { id, mount_identifier: this.mountIdentifier, owner_token: OWNER_TOKEN, status: "running" }
282
+ }));
283
+ });
284
+ }
285
+ /** @param {{id: string, ownerToken: string, finishedAtMs: number, result: any}} args - Transition. @returns {Promise<void>} */
286
+ async markSucceeded({ id, ownerToken, finishedAtMs, result }) {
287
+ await this._transition({ data: { finished_at_ms: finishedAtMs, result_json: JSON.stringify(result ?? null), status: "succeeded" }, id, ownerToken });
288
+ }
289
+ /** @param {{id: string, ownerToken: string, finishedAtMs: number, error: any}} args - Transition. @returns {Promise<void>} */
290
+ async markFailed({ id, ownerToken, finishedAtMs, error }) {
291
+ await this._transition({ data: { error_json: JSON.stringify(error ?? null), finished_at_ms: finishedAtMs, status: "failed" }, id, ownerToken });
292
+ }
293
+ /** @param {{id: string, ownerToken: string, finishedAtMs: number, error: any}} args - Transition. @returns {Promise<void>} */
294
+ async markReconciliationRequired({ id, ownerToken, finishedAtMs, error }) {
295
+ await this._transition({ data: { error_json: JSON.stringify(error ?? null), finished_at_ms: finishedAtMs, status: "reconciliation_required" }, id, ownerToken });
296
+ }
297
+ /** @param {{event: string, payload: any, runId: string|null}} args - Audit event. @returns {Promise<void>} */
298
+ async addAuditEvent({ event, payload, runId }) {
299
+ await this.ensureReady();
300
+ await this._withDb(async (db) => await db.insert({
301
+ tableName: AUDIT_TABLE,
302
+ data: {
303
+ created_at_ms: Date.now(),
304
+ event,
305
+ id: randomUUID(),
306
+ mount_identifier: this.mountIdentifier,
307
+ payload_json: payload === undefined ? null : JSON.stringify(payload ?? null),
308
+ run_id: runId
309
+ }
310
+ }));
311
+ }
312
+ /**
313
+ * @param {{runId: string}} args - Query.
314
+ * @returns {Promise<Array<Record<string, any>>>} Events.
315
+ */
316
+ async listAuditEvents({ runId }) {
317
+ await this.ensureReady();
318
+ return await this._withDb(async (db) => {
319
+ const rows = await db.newQuery().from(AUDIT_TABLE).where({ mount_identifier: this.mountIdentifier, run_id: runId }).order("created_at_ms ASC").results();
320
+ return rows.map((/** @type {Record<string, any>} */ row) => ({
321
+ createdAtMs: Number(row.created_at_ms),
322
+ event: row.event,
323
+ id: row.id,
324
+ payload: parseJson(row.payload_json),
325
+ runId: row.run_id ?? null
326
+ }));
327
+ });
328
+ }
329
+ /**
330
+ * @param {any} db - Open Velocious database connection.
331
+ * @param {DeploymentRunRow} run - Observed stale run.
332
+ * @returns {Promise<boolean>} Whether this reconciler won.
333
+ */
334
+ async _reconcileExpiredRun(db, run) {
335
+ const running = run.status === "running";
336
+ const status = running ? "reconciliation_required" : "interrupted";
337
+ const event = running ? "run_reconciliation_required" : "run_interrupted";
338
+ const error = running
339
+ ? { message: "Deployment outcome requires operator reconciliation after the execution owner lease expired" }
340
+ : { message: "Deployment run was interrupted before execution began (ownership lease expired)" };
341
+ const affected = await db.affectedRows(db.updateSql({
342
+ tableName: RUNS_TABLE,
343
+ data: { error_json: JSON.stringify(error), finished_at_ms: Date.now(), status },
344
+ conditions: reconciliationConditions({ mountIdentifier: this.mountIdentifier, run })
345
+ }));
346
+ if (affected === 0)
347
+ return false;
348
+ if (affected !== 1)
349
+ throw new Error(`Expected at most one expired Rampway deployment run ${run.id}, updated ${affected}`);
350
+ try {
351
+ await db.insert({
352
+ tableName: AUDIT_TABLE,
353
+ data: {
354
+ created_at_ms: Date.now(),
355
+ event,
356
+ id: randomUUID(),
357
+ mount_identifier: this.mountIdentifier,
358
+ payload_json: JSON.stringify({ project: run.project, revision: run.revision, stage: run.stage }),
359
+ run_id: run.id
360
+ }
361
+ });
362
+ }
363
+ catch (auditError) {
364
+ this._emitFrameworkError("rampway-deployment-api-reconciliation-audit", auditError);
365
+ }
366
+ return true;
367
+ }
368
+ /**
369
+ * Reconciles an expired pending/running owner before returning durable state.
370
+ *
371
+ * @param {any} db - Open Velocious database connection.
372
+ * @param {DeploymentRunRow|null} run - Observed run.
373
+ * @returns {Promise<DeploymentRunRow|null>} Current durable run.
374
+ */
375
+ async _reconcileExpiredRunIfNeeded(db, run) {
376
+ if (!run || !["pending", "running"].includes(run.status))
377
+ return run;
378
+ if (!isRunLeaseExpired({ activeRunIds, nowMs: Date.now(), run, staleRunTimeoutMs: this.staleRunTimeoutMs }))
379
+ return run;
380
+ await this._reconcileExpiredRun(db, run);
381
+ const current = await this._findRunById(db, run.id);
382
+ if (!current)
383
+ throw new Error(`Rampway deployment run ${run.id} missing after lease reconciliation`);
384
+ return current;
385
+ }
386
+ /** @param {{data: Record<string, any>, id: string, ownerToken: string}} args - Transition. @returns {Promise<void>} */
387
+ async _transition({ data, id, ownerToken }) {
388
+ await this.ensureReady();
389
+ await this._withDb(async (db) => {
390
+ const affected = await db.affectedRows(db.updateSql({
391
+ tableName: RUNS_TABLE,
392
+ data,
393
+ conditions: terminalTransitionConditions({ id, mountIdentifier: this.mountIdentifier, ownerToken })
394
+ }));
395
+ if (affected !== 1)
396
+ throw new Error(`Expected one owner-matching running Rampway deployment run ${id}, updated ${affected}`);
397
+ });
398
+ }
399
+ /**
400
+ * @param {string} kind - Lock kind.
401
+ * @param {string} value - Scoped value.
402
+ * @returns {string} Lock name.
403
+ */
404
+ _lockName(kind, value) {
405
+ const hash = createHash("sha256").update(`${this.mountIdentifier}:${value}`).digest("hex").slice(0, 32);
406
+ return `rampway-deployment:${kind}:${hash}`;
407
+ }
408
+ /**
409
+ * @param {any} db - Connection.
410
+ * @param {string} id - Run id.
411
+ * @returns {Promise<DeploymentRunRow|null>} Run.
412
+ */
413
+ async _findRunById(db, id) {
414
+ const rows = await db.newQuery().from(RUNS_TABLE).where({ id, mount_identifier: this.mountIdentifier }).limit(1).results();
415
+ return rows[0] ? this._row(rows[0]) : null;
416
+ }
417
+ /**
418
+ * @param {any} db - Connection.
419
+ * @param {string} key - Idempotency key.
420
+ * @returns {Promise<DeploymentRunRow|null>} Run.
421
+ */
422
+ async _findRunByKey(db, key) {
423
+ const rows = await db.newQuery().from(RUNS_TABLE).where({ idempotency_key: key, mount_identifier: this.mountIdentifier }).limit(1).results();
424
+ return rows[0] ? this._row(rows[0]) : null;
425
+ }
426
+ /**
427
+ * @param {any} db - Connection.
428
+ * @param {{project: string, stage: string}} args - Target.
429
+ * @returns {Promise<DeploymentRunRow|null>} Run.
430
+ */
431
+ async _findBlockingRun(db, { project, stage }) {
432
+ const rows = await db.newQuery().from(RUNS_TABLE).where({ mount_identifier: this.mountIdentifier, project, stage, status: BLOCKING_STATUSES }).order("requested_at_ms ASC").limit(1).results();
433
+ return rows[0] ? this._row(rows[0]) : null;
434
+ }
435
+ /**
436
+ * @param {Record<string, any>} row - Database row.
437
+ * @returns {DeploymentRunRow} Run.
438
+ */
439
+ _row(row) {
440
+ return {
441
+ error: parseJson(row.error_json),
442
+ finishedAtMs: row.finished_at_ms == null ? null : Number(row.finished_at_ms),
443
+ heartbeatAtMs: row.heartbeat_at_ms == null ? null : Number(row.heartbeat_at_ms),
444
+ id: row.id,
445
+ idempotencyKey: row.idempotency_key,
446
+ mountIdentifier: row.mount_identifier,
447
+ ownerToken: row.owner_token ?? null,
448
+ project: row.project,
449
+ requestedAtMs: Number(row.requested_at_ms),
450
+ result: parseJson(row.result_json),
451
+ revision: row.revision,
452
+ stage: row.stage,
453
+ startedAtMs: row.started_at_ms == null ? null : Number(row.started_at_ms),
454
+ status: row.status
455
+ };
456
+ }
457
+ /**
458
+ * @param {string} context - Context.
459
+ * @param {unknown} error - Failure.
460
+ * @returns {void}
461
+ */
462
+ _emitFrameworkError(context, error) {
463
+ const events = this.configuration.getErrorEvents();
464
+ const payload = { context, error };
465
+ events.emit("framework-error", payload);
466
+ events.emit("all-error", { ...payload, errorType: "framework-error" });
467
+ }
468
+ /**
469
+ * @template T
470
+ * @param {(db: any) => Promise<T>} callback - Work.
471
+ * @returns {Promise<T>} Result.
472
+ */
473
+ async _withDb(callback) {
474
+ const pool = this.configuration.getDatabasePool(this.databaseIdentifier);
475
+ /** @type {T|undefined} */
476
+ let result;
477
+ await pool.withConnection({ name: "Rampway deployment run store" }, async (/** @type {any} */ db) => { result = await callback(db); });
478
+ return /** @type {T} */ (result);
479
+ }
480
+ }
481
+ export { AUDIT_TABLE, RUNS_TABLE };
482
+ //# sourceMappingURL=run-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-store.js","sourceRoot":"","sources":["../../../src/velocious/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C,GAAG,CAAC,WAAW,CAAC;YAClC,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,WAAW,EAAE,GAAG,CAAC,aAAa,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC;YACzE,MAAM,EAAE,GAAG,CAAC,MAAM;SACnB,CAAA;IACH,CAAC;IAED;;;;OAIG;IACH,mBAAmB,CAAC,OAAO,EAAE,KAAK;QAChC,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,cAAc,EAAE,CAAA;QAClD,MAAM,OAAO,GAAG,EAAC,OAAO,EAAE,KAAK,EAAC,CAAA;QAChC,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAA;QACvC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,EAAC,GAAG,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAC,CAAC,CAAA;IACtE,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,OAAO,CAAC,QAAQ;QACpB,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;QACxE,0BAA0B;QAC1B,IAAI,MAAM,CAAA;QACV,MAAM,IAAI,CAAC,cAAc,CAAC,EAAC,IAAI,EAAE,8BAA8B,EAAC,EAAE,KAAK,EAAE,kBAAkB,CAAC,EAAE,EAAE,EAAE,GAAG,MAAM,GAAG,MAAM,QAAQ,CAAC,EAAE,CAAC,CAAA,CAAC,CAAC,CAAC,CAAA;QACnI,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAA;IAClC,CAAC;CACF;AAED,OAAO,EAAC,WAAW,EAAE,UAAU,EAAC,CAAA"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Converts an integration value to bounded JSON data while redacting secrets
3
+ * in values and keys. Colliding redacted keys are retained with stable suffixes.
4
+ *
5
+ * @param {unknown} value - Integration value.
6
+ * @param {string[]} secrets - Secrets to remove.
7
+ * @param {number} [depth] - Current depth.
8
+ * @returns {any} JSON-safe value or undefined.
9
+ */
10
+ export function sanitizeAdapterValue(value: unknown, secrets: string[], depth?: number): any;
11
+ /**
12
+ * @param {unknown} error - Deployment failure.
13
+ * @param {string[]} secrets - Secrets to remove.
14
+ * @returns {{message: string, recovery: any}} Safe failure payload.
15
+ */
16
+ export function sanitizeErrorPayload(error: unknown, secrets: string[]): {
17
+ message: string;
18
+ recovery: any;
19
+ };
20
+ export type SanitizerState = {
21
+ visited: number;
22
+ };
23
+ //# sourceMappingURL=sanitize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/velocious/sanitize.js"],"names":[],"mappings":"AA6BA;;;;;;;;GAQG;AACH,4CALW,OAAO,WACP,MAAM,EAAE,UACR,MAAM,GACJ,GAAG,CAef;AAiGD;;;;GAIG;AACH,4CAJW,OAAO,WACP,MAAM,EAAE,GACN;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,GAAG,CAAA;CAAC,CAY5C;6BAvJa;IAAC,OAAO,EAAE,MAAM,CAAA;CAAC"}