rampway 0.3.0 → 0.4.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 (44) hide show
  1. package/README.md +31 -0
  2. package/build/src/velocious/auth.d.ts +17 -0
  3. package/build/src/velocious/auth.d.ts.map +1 -0
  4. package/build/src/velocious/auth.js +30 -0
  5. package/build/src/velocious/auth.js.map +1 -0
  6. package/build/src/velocious/control-plane.d.ts +177 -0
  7. package/build/src/velocious/control-plane.d.ts.map +1 -0
  8. package/build/src/velocious/control-plane.js +290 -0
  9. package/build/src/velocious/control-plane.js.map +1 -0
  10. package/build/src/velocious/controller.d.ts +58 -0
  11. package/build/src/velocious/controller.d.ts.map +1 -0
  12. package/build/src/velocious/controller.js +143 -0
  13. package/build/src/velocious/controller.js.map +1 -0
  14. package/build/src/velocious/executor.d.ts +55 -0
  15. package/build/src/velocious/executor.d.ts.map +1 -0
  16. package/build/src/velocious/executor.js +142 -0
  17. package/build/src/velocious/executor.js.map +1 -0
  18. package/build/src/velocious/index.d.ts +31 -0
  19. package/build/src/velocious/index.d.ts.map +1 -0
  20. package/build/src/velocious/index.js +144 -0
  21. package/build/src/velocious/index.js.map +1 -0
  22. package/build/src/velocious/path-matcher.d.ts +18 -0
  23. package/build/src/velocious/path-matcher.d.ts.map +1 -0
  24. package/build/src/velocious/path-matcher.js +48 -0
  25. package/build/src/velocious/path-matcher.js.map +1 -0
  26. package/build/src/velocious/registry.d.ts +25 -0
  27. package/build/src/velocious/registry.d.ts.map +1 -0
  28. package/build/src/velocious/registry.js +48 -0
  29. package/build/src/velocious/registry.js.map +1 -0
  30. package/build/src/velocious/run-store.d.ts +347 -0
  31. package/build/src/velocious/run-store.d.ts.map +1 -0
  32. package/build/src/velocious/run-store.js +569 -0
  33. package/build/src/velocious/run-store.js.map +1 -0
  34. package/build/src/velocious/sanitize.d.ts +23 -0
  35. package/build/src/velocious/sanitize.d.ts.map +1 -0
  36. package/build/src/velocious/sanitize.js +154 -0
  37. package/build/src/velocious/sanitize.js.map +1 -0
  38. package/build/src/velocious/worker.d.ts +48 -0
  39. package/build/src/velocious/worker.d.ts.map +1 -0
  40. package/build/src/velocious/worker.js +165 -0
  41. package/build/src/velocious/worker.js.map +1 -0
  42. package/docs/docker-development-environment.md +103 -0
  43. package/docs/velocious-deployment-api.md +226 -0
  44. package/package.json +22 -3
@@ -0,0 +1,48 @@
1
+ // @ts-check
2
+ /**
3
+ * @param {string} at - Mount path.
4
+ * @returns {string} Normalized path.
5
+ */
6
+ export function normalizeMountPrefix(at) {
7
+ if (typeof at !== "string" || !at.startsWith("/")) {
8
+ throw new Error(`mount requires an 'at' path starting with '/', got: ${String(at)}`);
9
+ }
10
+ return at.length > 1 && at.endsWith("/") ? at.slice(0, -1) : at;
11
+ }
12
+ /**
13
+ * @param {{prefix: string, path: string}} args - Paths.
14
+ * @returns {string|null} Subpath or null.
15
+ */
16
+ function mountSubPath({ prefix, path }) {
17
+ if (prefix === "/")
18
+ return path;
19
+ if (path === prefix)
20
+ return "/";
21
+ if (path.startsWith(`${prefix}/`))
22
+ return path.slice(prefix.length);
23
+ return null;
24
+ }
25
+ /**
26
+ * @param {{prefix: string, path: string, method: string}} args - Request data.
27
+ * @returns {{action: string, params: Record<string, string>}|null} Match.
28
+ */
29
+ export function matchDeploymentApiPath({ prefix, path, method }) {
30
+ const subPath = mountSubPath({ prefix, path });
31
+ if (subPath === null)
32
+ return null;
33
+ if (method === "POST" && subPath === "/runs")
34
+ return { action: "create", params: {} };
35
+ if (method === "GET") {
36
+ const match = subPath.match(/^\/runs\/([^/]+)$/);
37
+ if (!match)
38
+ return null;
39
+ try {
40
+ return { action: "show", params: { id: decodeURIComponent(match[1]) } };
41
+ }
42
+ catch {
43
+ return null;
44
+ }
45
+ }
46
+ return null;
47
+ }
48
+ //# sourceMappingURL=path-matcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-matcher.js","sourceRoot":"","sources":["../../../src/velocious/path-matcher.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AAC,KAAK,CAAC,mBAAmB,CAAC,CAAA;QAChD,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAA;QAEvB,IAAI,CAAC;YACH,OAAO,EAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAC,EAAE,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAC,EAAC,CAAA;QACrE,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @param {string} at - Normalized mount.
3
+ * @returns {string} Stable scope.
4
+ */
5
+ export function deploymentMountIdentifier(at: string): string;
6
+ /**
7
+ * @param {object} configuration - Configuration.
8
+ * @param {string} at - Mount.
9
+ * @param {Record<string, any>} options - Options.
10
+ * @returns {void}
11
+ */
12
+ export function registerDeploymentMount(configuration: object, at: string, options: Record<string, any>): void;
13
+ /**
14
+ * @param {object} configuration - Configuration.
15
+ * @param {string} at - Mount.
16
+ * @returns {Record<string, any>|undefined} Options.
17
+ */
18
+ export function getDeploymentMount(configuration: object, at: string): Record<string, any> | undefined;
19
+ /**
20
+ * @param {object} configuration - Configuration.
21
+ * @param {string} identifier - Stable mount identifier.
22
+ * @returns {Record<string, any>|undefined} Options.
23
+ */
24
+ export function getDeploymentMountByIdentifier(configuration: object, identifier: string): Record<string, any> | undefined;
25
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/velocious/registry.js"],"names":[],"mappings":"AAOA;;;GAGG;AACH,8CAHW,MAAM,GACJ,MAAM,CAIlB;AAED;;;;;GAKG;AACH,uDALW,MAAM,MACN,MAAM,WACN,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjB,IAAI,CAUhB;AAED;;;;GAIG;AACH,kDAJW,MAAM,MACN,MAAM,GACJ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAC,SAAS,CAIzC;AAED;;;;GAIG;AACH,8DAJW,MAAM,cACN,MAAM,GACJ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAC,SAAS,CAOzC"}
@@ -0,0 +1,48 @@
1
+ // @ts-check
2
+ import { createHash } from "node:crypto";
3
+ /** @type {WeakMap<object, Map<string, Record<string, any>>>} */
4
+ const mounts = new WeakMap();
5
+ /**
6
+ * @param {string} at - Normalized mount.
7
+ * @returns {string} Stable scope.
8
+ */
9
+ export function deploymentMountIdentifier(at) {
10
+ return createHash("sha256").update(at).digest("hex");
11
+ }
12
+ /**
13
+ * @param {object} configuration - Configuration.
14
+ * @param {string} at - Mount.
15
+ * @param {Record<string, any>} options - Options.
16
+ * @returns {void}
17
+ */
18
+ export function registerDeploymentMount(configuration, at, options) {
19
+ let configured = mounts.get(configuration);
20
+ if (!configured) {
21
+ configured = new Map();
22
+ mounts.set(configuration, configured);
23
+ }
24
+ if (configured.has(at))
25
+ throw new Error(`Rampway deployment API is already mounted at ${at}`);
26
+ configured.set(at, options);
27
+ }
28
+ /**
29
+ * @param {object} configuration - Configuration.
30
+ * @param {string} at - Mount.
31
+ * @returns {Record<string, any>|undefined} Options.
32
+ */
33
+ export function getDeploymentMount(configuration, at) {
34
+ return mounts.get(configuration)?.get(at);
35
+ }
36
+ /**
37
+ * @param {object} configuration - Configuration.
38
+ * @param {string} identifier - Stable mount identifier.
39
+ * @returns {Record<string, any>|undefined} Options.
40
+ */
41
+ export function getDeploymentMountByIdentifier(configuration, identifier) {
42
+ for (const options of mounts.get(configuration)?.values() ?? []) {
43
+ if (options.mountIdentifier === identifier)
44
+ return options;
45
+ }
46
+ return undefined;
47
+ }
48
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/velocious/registry.js"],"names":[],"mappings":"AAAA,YAAY;AAEZ,OAAO,EAAC,UAAU,EAAC,MAAM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ns {void}
4
+ */
5
+ export function registerActiveDeploymentRun(id: string): void;
6
+ /**
7
+ * @param {string} id - Run id.
8
+ * @returns {void}
9
+ */
10
+ export function unregisterActiveDeploymentRun(id: string): void;
11
+ /**
12
+ * @param {number} staleRunTimeoutMs - Lease duration.
13
+ * @returns {number} Heartbeat interval strictly below the lease.
14
+ */
15
+ export function heartbeatIntervalMs(staleRunTimeoutMs: number): number;
16
+ /**
17
+ * @param {{activeRunIds: Set<string>, nowMs: number, run: {heartbeatAtMs: number|null, id: string, launchProtectedUntilMs?: number|null, requestedAtMs: number, status?: string}, staleRunTimeoutMs: number}} args - Lease data.
18
+ * @returns {boolean} Whether ownership expired.
19
+ */
20
+ export function isRunLeaseExpired({ activeRunIds: localIds, nowMs, run, staleRunTimeoutMs }: {
21
+ activeRunIds: Set<string>;
22
+ nowMs: number;
23
+ run: {
24
+ heartbeatAtMs: number | null;
25
+ id: string;
26
+ launchProtectedUntilMs?: number | null;
27
+ requestedAtMs: number;
28
+ status?: string;
29
+ };
30
+ staleRunTimeoutMs: number;
31
+ }): boolean;
32
+ /**
33
+ * @param {{id: string, mountIdentifier: string, ownerToken: string}} args - Fence identifiers.
34
+ * @returns {Record<string, unknown>} Update conditions.
35
+ */
36
+ export function terminalTransitionConditions({ id, mountIdentifier, ownerToken }: {
37
+ id: string;
38
+ mountIdentifier: string;
39
+ ownerToken: string;
40
+ }): Record<string, unknown>;
41
+ /**
42
+ * Includes the observed heartbeat so a concurrent renewal defeats stale reconciliation.
43
+ *
44
+ * @param {{mountIdentifier: string, run: Pick<DeploymentRunRow, 'heartbeatAtMs'|'id'|'ownerToken'|'status'>}} args - Fence data.
45
+ * @returns {Record<string, unknown>} Update conditions.
46
+ */
47
+ export function reconciliationConditions({ mountIdentifier, run }: {
48
+ mountIdentifier: string;
49
+ run: Pick<DeploymentRunRow, "heartbeatAtMs" | "id" | "ownerToken" | "status">;
50
+ }): Record<string, unknown>;
51
+ /** Rampway-owned durable deployment state stored through Velocious's database abstraction. */
52
+ export default class DeploymentRunStore {
53
+ /**
54
+ * @param {object} args - Store options.
55
+ * @param {any} args.configuration - Velocious configuration.
56
+ * @param {string} [args.databaseIdentifier] - Database identifier.
57
+ * @param {string} args.mountIdentifier - Authenticated mount scope.
58
+ * @param {number} args.staleRunTimeoutMs - Lease duration.
59
+ */
60
+ constructor({ configuration, databaseIdentifier, mountIdentifier, staleRunTimeoutMs }: {
61
+ configuration: any;
62
+ databaseIdentifier?: string | undefined;
63
+ mountIdentifier: string;
64
+ staleRunTimeoutMs: number;
65
+ });
66
+ configuration: any;
67
+ databaseIdentifier: string;
68
+ mountIdentifier: string;
69
+ staleRunTimeoutMs: number;
70
+ /** @type {Promise<void>|null} */
71
+ readyPromise: Promise<void> | null;
72
+ /** @returns {Promise<void>} */
73
+ ensureReady(): Promise<void>;
74
+ /**
75
+ * Adds the handoff lease to databases created by the previous API schema.
76
+ *
77
+ * @param {any} db - Open Velocious database connection.
78
+ * @returns {Promise<void>}
79
+ */
80
+ _ensureLaunchProtectionColumn(db: any): Promise<void>;
81
+ /**
82
+ * @param {string} id - Run id.
83
+ * @returns {Promise<DeploymentRunRow|null>} Run.
84
+ */
85
+ findRunById(id: string): Promise<DeploymentRunRow | null>;
86
+ /**
87
+ * @param {string} key - Idempotency key.
88
+ * @returns {Promise<DeploymentRunRow|null>} Run.
89
+ */
90
+ findRunByKey(key: string): Promise<DeploymentRunRow | null>;
91
+ /**
92
+ * Serializes admission by target then by mount-global idempotency key.
93
+ *
94
+ * @param {{idempotencyKey: string, project: string, revision: string, stage: string}} args - Run request.
95
+ * @returns {Promise<{outcome: string, run: DeploymentRunRow|null}>} Admission result.
96
+ */
97
+ createRunIfPossible({ idempotencyKey, project, revision, stage }: {
98
+ idempotencyKey: string;
99
+ project: string;
100
+ revision: string;
101
+ stage: string;
102
+ }): Promise<{
103
+ outcome: string;
104
+ run: DeploymentRunRow | null;
105
+ }>;
106
+ /**
107
+ * @param {{id: string, startedAtMs: number}} args - Cross-process worker claim.
108
+ * @returns {Promise<DeploymentRunRow>} Claimed run.
109
+ */
110
+ claimPendingRun({ id, startedAtMs }: {
111
+ id: string;
112
+ startedAtMs: number;
113
+ }): Promise<DeploymentRunRow>;
114
+ /** @param {{id: string, startedAtMs: number}} args - Transition. @returns {Promise<void>} */
115
+ markRunning({ id, startedAtMs }: {
116
+ id: string;
117
+ startedAtMs: number;
118
+ }): Promise<void>;
119
+ /** @param {{id: string, ownerToken: string, finishedAtMs: number, error: any}} args - Launch failure. @returns {Promise<void>} */
120
+ markPendingFailed({ id, ownerToken, finishedAtMs, error }: {
121
+ id: string;
122
+ ownerToken: string;
123
+ finishedAtMs: number;
124
+ error: any;
125
+ }): Promise<void>;
126
+ /** @param {{id: string, finishedAtMs: number, error: any}} args - Pre-claim worker failure. @returns {Promise<void>} */
127
+ failPendingRun({ id, finishedAtMs, error }: {
128
+ id: string;
129
+ finishedAtMs: number;
130
+ error: any;
131
+ }): Promise<void>;
132
+ /** @param {{id: string, heartbeatAtMs: number}} args - Heartbeat. @returns {Promise<void>} */
133
+ heartbeat({ id, heartbeatAtMs }: {
134
+ id: string;
135
+ heartbeatAtMs: number;
136
+ }): Promise<void>;
137
+ /** @param {{id: string, ownerToken: string, finishedAtMs: number, result: any}} args - Transition. @returns {Promise<void>} */
138
+ markSucceeded({ id, ownerToken, finishedAtMs, result }: {
139
+ id: string;
140
+ ownerToken: string;
141
+ finishedAtMs: number;
142
+ result: any;
143
+ }): Promise<void>;
144
+ /** @param {{id: string, ownerToken: string, finishedAtMs: number, error: any}} args - Transition. @returns {Promise<void>} */
145
+ markFailed({ id, ownerToken, finishedAtMs, error }: {
146
+ id: string;
147
+ ownerToken: string;
148
+ finishedAtMs: number;
149
+ error: any;
150
+ }): Promise<void>;
151
+ /** @param {{id: string, ownerToken: string, finishedAtMs: number, error: any}} args - Transition. @returns {Promise<void>} */
152
+ markReconciliationRequired({ id, ownerToken, finishedAtMs, error }: {
153
+ id: string;
154
+ ownerToken: string;
155
+ finishedAtMs: number;
156
+ error: any;
157
+ }): Promise<void>;
158
+ /** @param {{event: string, payload: any, runId: string|null}} args - Audit event. @returns {Promise<void>} */
159
+ addAuditEvent({ event, payload, runId }: {
160
+ event: string;
161
+ payload: any;
162
+ runId: string | null;
163
+ }): Promise<void>;
164
+ /**
165
+ * @param {{runId: string}} args - Query.
166
+ * @returns {Promise<Array<Record<string, any>>>} Events.
167
+ */
168
+ listAuditEvents({ runId }: {
169
+ runId: string;
170
+ }): Promise<Array<Record<string, any>>>;
171
+ /**
172
+ * @param {any} db - Open Velocious database connection.
173
+ * @param {DeploymentRunRow} run - Observed stale run.
174
+ * @returns {Promise<boolean>} Whether this reconciler won.
175
+ */
176
+ _reconcileExpiredRun(db: any, run: DeploymentRunRow): Promise<boolean>;
177
+ /**
178
+ * Reconciles an expired pending/running owner before returning durable state.
179
+ *
180
+ * @param {any} db - Open Velocious database connection.
181
+ * @param {DeploymentRunRow|null} run - Observed run.
182
+ * @returns {Promise<DeploymentRunRow|null>} Current durable run.
183
+ */
184
+ _reconcileExpiredRunIfNeeded(db: any, run: DeploymentRunRow | null): Promise<DeploymentRunRow | null>;
185
+ /** @param {{data: Record<string, any>, id: string, ownerToken: string}} args - Transition. @returns {Promise<void>} */
186
+ _transition({ data, id, ownerToken }: {
187
+ data: Record<string, any>;
188
+ id: string;
189
+ ownerToken: string;
190
+ }): Promise<void>;
191
+ /**
192
+ * @param {string} kind - Lock kind.
193
+ * @param {string} value - Scoped value.
194
+ * @returns {string} Lock name.
195
+ */
196
+ _lockName(kind: string, value: string): string;
197
+ /**
198
+ * @param {any} db - Connection.
199
+ * @param {string} id - Run id.
200
+ * @returns {Promise<DeploymentRunRow|null>} Run.
201
+ */
202
+ _findRunById(db: any, id: string): Promise<DeploymentRunRow | null>;
203
+ /**
204
+ * @param {any} db - Connection.
205
+ * @param {string} key - Idempotency key.
206
+ * @returns {Promise<DeploymentRunRow|null>} Run.
207
+ */
208
+ _findRunByKey(db: any, key: string): Promise<DeploymentRunRow | null>;
209
+ /**
210
+ * @param {any} db - Connection.
211
+ * @param {{project: string, stage: string}} args - Target.
212
+ * @returns {Promise<DeploymentRunRow|null>} Run.
213
+ */
214
+ _findBlockingRun(db: any, { project, stage }: {
215
+ project: string;
216
+ stage: string;
217
+ }): Promise<DeploymentRunRow | null>;
218
+ /**
219
+ * @param {Record<string, any>} row - Database row.
220
+ * @returns {DeploymentRunRow} Run.
221
+ */
222
+ _row(row: Record<string, any>): DeploymentRunRow;
223
+ /**
224
+ * @param {string} context - Context.
225
+ * @param {unknown} error - Failure.
226
+ * @returns {void}
227
+ */
228
+ _emitFrameworkError(context: string, error: unknown): void;
229
+ /**
230
+ * @template T
231
+ * @param {(db: any) => Promise<T>} callback - Work.
232
+ * @returns {Promise<T>} Result.
233
+ */
234
+ _withDb<T>(callback: (db: any) => Promise<T>): Promise<T>;
235
+ }
236
+ export type DeploymentRunRow = {
237
+ id: string;
238
+ mountIdentifier: string;
239
+ project: string;
240
+ stage: string;
241
+ revision: string;
242
+ idempotencyKey: string;
243
+ status: string;
244
+ result: any;
245
+ error: any;
246
+ requestedAtMs: number;
247
+ startedAtMs: number | null;
248
+ finishedAtMs: number | null;
249
+ ownerToken: string | null;
250
+ heartbeatAtMs: number | null;
251
+ launchProtectedUntilMs: number | null;
252
+ };
253
+ export type DeploymentRunStoreContract = {
254
+ findRunById: (id: string) => Promise<DeploymentRunRow | null>;
255
+ findRunByKey: (key: string) => Promise<DeploymentRunRow | null>;
256
+ createRunIfPossible: (args: {
257
+ idempotencyKey: string;
258
+ project: string;
259
+ revision: string;
260
+ stage: string;
261
+ }) => Promise<{
262
+ outcome: string;
263
+ run: DeploymentRunRow | null;
264
+ }>;
265
+ markRunning: (args: {
266
+ id: string;
267
+ startedAtMs: number;
268
+ }) => Promise<void>;
269
+ claimPendingRun: (args: {
270
+ id: string;
271
+ startedAtMs: number;
272
+ }) => Promise<DeploymentRunRow>;
273
+ heartbeat: (args: {
274
+ id: string;
275
+ heartbeatAtMs: number;
276
+ }) => Promise<void>;
277
+ markPendingFailed: (args: {
278
+ id: string;
279
+ ownerToken: string;
280
+ finishedAtMs: number;
281
+ error: any;
282
+ }) => Promise<void>;
283
+ failPendingRun: (args: {
284
+ id: string;
285
+ finishedAtMs: number;
286
+ error: any;
287
+ }) => Promise<void>;
288
+ markSucceeded: (args: {
289
+ id: string;
290
+ ownerToken: string;
291
+ finishedAtMs: number;
292
+ result: any;
293
+ }) => Promise<void>;
294
+ markFailed: (args: {
295
+ id: string;
296
+ ownerToken: string;
297
+ finishedAtMs: number;
298
+ error: any;
299
+ }) => Promise<void>;
300
+ markReconciliationRequired: (args: {
301
+ id: string;
302
+ ownerToken: string;
303
+ finishedAtMs: number;
304
+ error: any;
305
+ }) => Promise<void>;
306
+ addAuditEvent: (args: {
307
+ event: string;
308
+ payload: any;
309
+ runId: string | null;
310
+ }) => Promise<void>;
311
+ };
312
+ export const AUDIT_TABLE: "rampway_deployment_api_audit_events";
313
+ /**
314
+ * @typedef {object} DeploymentRunRow
315
+ * @property {string} id
316
+ * @property {string} mountIdentifier
317
+ * @property {string} project
318
+ * @property {string} stage
319
+ * @property {string} revision
320
+ * @property {string} idempotencyKey
321
+ * @property {string} status
322
+ * @property {any} result
323
+ * @property {any} error
324
+ * @property {number} requestedAtMs
325
+ * @property {number|null} startedAtMs
326
+ * @property {number|null} finishedAtMs
327
+ * @property {string|null} ownerToken
328
+ * @property {number|null} heartbeatAtMs
329
+ * @property {number|null} launchProtectedUntilMs
330
+ */
331
+ /**
332
+ * @typedef {object} DeploymentRunStoreContract
333
+ * @property {(id: string) => Promise<DeploymentRunRow|null>} findRunById
334
+ * @property {(key: string) => Promise<DeploymentRunRow|null>} findRunByKey
335
+ * @property {(args: {idempotencyKey: string, project: string, revision: string, stage: string}) => Promise<{outcome: string, run: DeploymentRunRow|null}>} createRunIfPossible
336
+ * @property {(args: {id: string, startedAtMs: number}) => Promise<void>} markRunning
337
+ * @property {(args: {id: string, startedAtMs: number}) => Promise<DeploymentRunRow>} claimPendingRun
338
+ * @property {(args: {id: string, heartbeatAtMs: number}) => Promise<void>} heartbeat
339
+ * @property {(args: {id: string, ownerToken: string, finishedAtMs: number, error: any}) => Promise<void>} markPendingFailed
340
+ * @property {(args: {id: string, finishedAtMs: number, error: any}) => Promise<void>} failPendingRun
341
+ * @property {(args: {id: string, ownerToken: string, finishedAtMs: number, result: any}) => Promise<void>} markSucceeded
342
+ * @property {(args: {id: string, ownerToken: string, finishedAtMs: number, error: any}) => Promise<void>} markFailed
343
+ * @property {(args: {id: string, ownerToken: string, finishedAtMs: number, error: any}) => Promise<void>} markReconciliationRequired
344
+ * @property {(args: {event: string, payload: any, runId: string|null}) => Promise<void>} addAuditEvent
345
+ */
346
+ export const RUNS_TABLE: "rampway_deployment_runs";
347
+ //# sourceMappingURL=run-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-store.d.ts","sourceRoot":"","sources":["../../../src/velocious/run-store.js"],"names":[],"mappings":"AAkDA;;;GAGG;AACH,gDAHW,MAAM,GACJ,IAAI,CAEuD;AAExE;;;GAGG;AACH,kDAHW,MAAM,GACJ,IAAI,CAE4D;AAE7E;;;GAGG;AACH,uDAHW,MAAM,GACJ,MAAM,CAOlB;AAED;;;GAGG;AACH,6FAHW;IAAC,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE;QAAC,aAAa,EAAE,MAAM,GAAC,IAAI,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,sBAAsB,CAAC,EAAE,MAAM,GAAC,IAAI,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAC,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAC,GAChM,OAAO,CAMnB;AAED;;;GAGG;AACH,kFAHW;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM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