lastlight-core 0.25.9 → 0.26.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.
- package/config/default.yaml +20 -1
- package/dist/admin/chat-session-reader.d.ts +3 -3
- package/dist/admin/chat-session-reader.js +8 -8
- package/dist/admin/chat-session-reader.js.map +1 -1
- package/dist/admin/routes.js +97 -99
- package/dist/admin/routes.js.map +1 -1
- package/dist/admin/sessions.d.ts +7 -7
- package/dist/admin/sessions.js +6 -4
- package/dist/admin/sessions.js.map +1 -1
- package/dist/config/config.d.ts +15 -0
- package/dist/config/config.js +28 -0
- package/dist/config/config.js.map +1 -1
- package/dist/config/repo-config.js +6 -7
- package/dist/config/repo-config.js.map +1 -1
- package/dist/connectors/messaging/base.js +2 -2
- package/dist/connectors/messaging/base.js.map +1 -1
- package/dist/connectors/messaging/session-manager.d.ts +29 -31
- package/dist/connectors/messaging/session-manager.js +156 -189
- package/dist/connectors/messaging/session-manager.js.map +1 -1
- package/dist/connectors/messaging/thread-transcript.d.ts +2 -2
- package/dist/connectors/messaging/thread-transcript.js +14 -8
- package/dist/connectors/messaging/thread-transcript.js.map +1 -1
- package/dist/connectors/slack/connector.js +5 -5
- package/dist/connectors/slack/connector.js.map +1 -1
- package/dist/cron/feedback-poll.js +6 -6
- package/dist/cron/feedback-poll.js.map +1 -1
- package/dist/cron/handlers.js +3 -3
- package/dist/cron/handlers.js.map +1 -1
- package/dist/cron/jobs.d.ts +1 -1
- package/dist/cron/jobs.js +2 -2
- package/dist/cron/jobs.js.map +1 -1
- package/dist/cron/repo-digest.js +4 -4
- package/dist/cron/repo-digest.js.map +1 -1
- package/dist/cron/runner.js +2 -2
- package/dist/cron/runner.js.map +1 -1
- package/dist/cron/scheduler.js +1 -1
- package/dist/cron/scheduler.js.map +1 -1
- package/dist/engine/chat/chat-prompt.d.ts +11 -4
- package/dist/engine/chat/chat-prompt.js.map +1 -1
- package/dist/engine/chat/chat-runner.d.ts +3 -2
- package/dist/engine/chat/chat-runner.js +9 -7
- package/dist/engine/chat/chat-runner.js.map +1 -1
- package/dist/engine/dispatcher.js +29 -25
- package/dist/engine/dispatcher.js.map +1 -1
- package/dist/engine/executors/orchestrator.d.ts +28 -0
- package/dist/engine/executors/orchestrator.js +70 -1
- package/dist/engine/executors/orchestrator.js.map +1 -1
- package/dist/engine/feedback/ingest.d.ts +4 -4
- package/dist/engine/feedback/ingest.js +13 -13
- package/dist/engine/feedback/ingest.js.map +1 -1
- package/dist/engine/feedback/slack.d.ts +2 -2
- package/dist/engine/feedback/slack.js +6 -6
- package/dist/engine/feedback/slack.js.map +1 -1
- package/dist/engine/fix-harvest.d.ts +1 -1
- package/dist/engine/fix-harvest.js +3 -3
- package/dist/engine/fix-harvest.js.map +1 -1
- package/dist/engine/github/team-visibility.js +7 -7
- package/dist/engine/github/team-visibility.js.map +1 -1
- package/dist/engine/pr-escalation.js +7 -7
- package/dist/engine/pr-escalation.js.map +1 -1
- package/dist/engine/pr-state.d.ts +1 -1
- package/dist/engine/pr-state.js +12 -10
- package/dist/engine/pr-state.js.map +1 -1
- package/dist/engine/review-check.d.ts +1 -1
- package/dist/engine/review-check.js +5 -5
- package/dist/engine/review-check.js.map +1 -1
- package/dist/engine/router.js +3 -3
- package/dist/engine/router.js.map +1 -1
- package/dist/index.js +108 -65
- package/dist/index.js.map +1 -1
- package/dist/sandbox/docker.d.ts +33 -1
- package/dist/sandbox/docker.js +95 -1
- package/dist/sandbox/docker.js.map +1 -1
- package/dist/sandbox/k8s/kubernetes-sandbox.d.ts +3 -0
- package/dist/sandbox/k8s/kubernetes-sandbox.js +9 -0
- package/dist/sandbox/k8s/kubernetes-sandbox.js.map +1 -1
- package/dist/sandbox/k8s/pod.d.ts +11 -0
- package/dist/sandbox/k8s/pod.js +11 -6
- package/dist/sandbox/k8s/pod.js.map +1 -1
- package/dist/sandbox/k8s/service-containers.d.ts +43 -0
- package/dist/sandbox/k8s/service-containers.js +87 -0
- package/dist/sandbox/k8s/service-containers.js.map +1 -0
- package/dist/sandbox/reap.d.ts +9 -0
- package/dist/sandbox/reap.js +36 -0
- package/dist/sandbox/reap.js.map +1 -1
- package/dist/sandbox/sandbox.d.ts +14 -0
- package/dist/sandbox/sandbox.js +9 -0
- package/dist/sandbox/sandbox.js.map +1 -1
- package/dist/sandbox/service-containers-docker.d.ts +45 -0
- package/dist/sandbox/service-containers-docker.js +78 -0
- package/dist/sandbox/service-containers-docker.js.map +1 -0
- package/dist/state/approval-store.d.ts +23 -14
- package/dist/state/approval-store.js +137 -86
- package/dist/state/approval-store.js.map +1 -1
- package/dist/state/client.d.ts +105 -0
- package/dist/state/client.js +68 -0
- package/dist/state/client.js.map +1 -0
- package/dist/state/cron-run-store.d.ts +32 -12
- package/dist/state/cron-run-store.js +105 -39
- package/dist/state/cron-run-store.js.map +1 -1
- package/dist/state/db.d.ts +61 -23
- package/dist/state/db.js +171 -105
- package/dist/state/db.js.map +1 -1
- package/dist/state/dialect.d.ts +77 -0
- package/dist/state/dialect.js +129 -0
- package/dist/state/dialect.js.map +1 -0
- package/dist/state/execution-store.d.ts +124 -103
- package/dist/state/execution-store.js +569 -374
- package/dist/state/execution-store.js.map +1 -1
- package/dist/state/feedback-store.d.ts +20 -20
- package/dist/state/feedback-store.js +241 -187
- package/dist/state/feedback-store.js.map +1 -1
- package/dist/state/legacy-sqlite.d.ts +15 -0
- package/dist/state/legacy-sqlite.js +131 -0
- package/dist/state/legacy-sqlite.js.map +1 -0
- package/dist/state/repo-ref.d.ts +9 -4
- package/dist/state/repo-ref.js +12 -6
- package/dist/state/repo-ref.js.map +1 -1
- package/dist/state/schema/pg.d.ts +2788 -0
- package/dist/state/schema/pg.js +301 -0
- package/dist/state/schema/pg.js.map +1 -0
- package/dist/state/schema/sqlite.d.ts +3063 -0
- package/dist/state/schema/sqlite.js +391 -0
- package/dist/state/schema/sqlite.js.map +1 -0
- package/dist/state/team-store.d.ts +26 -13
- package/dist/state/team-store.js +140 -93
- package/dist/state/team-store.js.map +1 -1
- package/dist/state/user-store.d.ts +31 -13
- package/dist/state/user-store.js +180 -80
- package/dist/state/user-store.js.map +1 -1
- package/dist/state/workflow-run-store.d.ts +95 -56
- package/dist/state/workflow-run-store.js +419 -314
- package/dist/state/workflow-run-store.js.map +1 -1
- package/dist/workflows/admission.d.ts +4 -3
- package/dist/workflows/admission.js +34 -10
- package/dist/workflows/admission.js.map +1 -1
- package/dist/workflows/handlers/post-review.js +3 -3
- package/dist/workflows/handlers/post-review.js.map +1 -1
- package/dist/workflows/resume.js +22 -15
- package/dist/workflows/resume.js.map +1 -1
- package/dist/workflows/runner.js +27 -12
- package/dist/workflows/runner.js.map +1 -1
- package/dist/workflows/simple.d.ts +23 -0
- package/dist/workflows/simple.js +40 -16
- package/dist/workflows/simple.js.map +1 -1
- package/drizzle/pg/0000_init.sql +235 -0
- package/drizzle/pg/meta/0000_snapshot.json +1751 -0
- package/drizzle/pg/meta/_journal.json +13 -0
- package/drizzle/sqlite/0000_baseline.sql +257 -0
- package/drizzle/sqlite/0001_backfill_repo_refs.sql +74 -0
- package/drizzle/sqlite/meta/0000_snapshot.json +1593 -0
- package/drizzle/sqlite/meta/0001_snapshot.json +1593 -0
- package/drizzle/sqlite/meta/_journal.json +20 -0
- package/package.json +12 -6
- package/dist/state/migrate.d.ts +0 -15
- package/dist/state/migrate.js +0 -518
- package/dist/state/migrate.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type StateClient, type StateDbc } from "./client.js";
|
|
2
2
|
export interface WorkflowApproval {
|
|
3
3
|
id: string;
|
|
4
4
|
workflowRunId: string;
|
|
@@ -31,14 +31,24 @@ export interface WorkflowApproval {
|
|
|
31
31
|
* status flip (resolve-and-resume, resolve-and-fail, pause-for-approval) live
|
|
32
32
|
* on {@link WorkflowRunStore}, the aggregate root, which is injected with an
|
|
33
33
|
* instance of this store and calls these methods inside a single transaction.
|
|
34
|
+
* That is what the trailing `dbc` parameter on `create` / `respond` /
|
|
35
|
+
* `resolveReplyGate` / `getById` is for: they run against the enclosing
|
|
36
|
+
* transaction when the aggregate passes one, and against the root client
|
|
37
|
+
* otherwise.
|
|
34
38
|
*/
|
|
35
39
|
export declare class ApprovalStore {
|
|
36
|
-
private
|
|
37
|
-
|
|
40
|
+
private client;
|
|
41
|
+
/**
|
|
42
|
+
* Table objects for THIS client's dialect. Every method destructures what it
|
|
43
|
+
* needs off this instead of importing from `schema/sqlite.js` — see
|
|
44
|
+
* `client.ts` → {@link tablesOf} for why the cast alone cannot do it.
|
|
45
|
+
*/
|
|
46
|
+
private readonly t;
|
|
47
|
+
constructor(client: StateClient);
|
|
38
48
|
/** Create a new pending approval request */
|
|
39
49
|
create(approval: Omit<WorkflowApproval, "status" | "respondedBy" | "response" | "respondedAt" | "kind"> & {
|
|
40
50
|
kind?: WorkflowApproval["kind"];
|
|
41
|
-
}): void
|
|
51
|
+
}, dbc?: StateDbc): Promise<void>;
|
|
42
52
|
/**
|
|
43
53
|
* Resolve a reply gate: marks the approval row as approved (reply gates
|
|
44
54
|
* don't have approve/reject semantics — any reply is a "go") and stores
|
|
@@ -51,30 +61,30 @@ export declare class ApprovalStore {
|
|
|
51
61
|
* same thread, the second sees 0 rows and the transaction aborts before a
|
|
52
62
|
* duplicate resume.
|
|
53
63
|
*/
|
|
54
|
-
resolveReplyGate(id: string, replyText: string, responder: string): number
|
|
64
|
+
resolveReplyGate(id: string, replyText: string, responder: string, dbc?: StateDbc): Promise<number>;
|
|
55
65
|
/**
|
|
56
66
|
* Find the most recent pending reply gate for a given trigger id. Used by
|
|
57
67
|
* the router to short-circuit free-form replies on a paused socratic
|
|
58
68
|
* explore loop without re-running classifier logic.
|
|
59
69
|
*/
|
|
60
|
-
getPendingReplyGateByTrigger(triggerId: string): WorkflowApproval | null
|
|
70
|
+
getPendingReplyGateByTrigger(triggerId: string): Promise<WorkflowApproval | null>;
|
|
61
71
|
/** Get a single approval by ID */
|
|
62
|
-
getById(id: string): WorkflowApproval | null
|
|
72
|
+
getById(id: string, dbc?: StateDbc): Promise<WorkflowApproval | null>;
|
|
63
73
|
/** Find the pending approval for a workflow run */
|
|
64
|
-
getPendingForWorkflow(workflowRunId: string): WorkflowApproval | null
|
|
74
|
+
getPendingForWorkflow(workflowRunId: string): Promise<WorkflowApproval | null>;
|
|
65
75
|
/** Find the pending approval by trigger ID (join with workflow_runs) */
|
|
66
|
-
getPendingByTrigger(triggerId: string): WorkflowApproval | null
|
|
76
|
+
getPendingByTrigger(triggerId: string): Promise<WorkflowApproval | null>;
|
|
67
77
|
/**
|
|
68
78
|
* List every approval for a workflow run — all statuses (pending, approved,
|
|
69
79
|
* rejected), oldest first. Powers the dashboard's per-run approval history
|
|
70
80
|
* (who approved/rejected a gate, when, and any comment). Unlike
|
|
71
81
|
* {@link getPendingForWorkflow} this does not filter on status.
|
|
72
82
|
*/
|
|
73
|
-
listForWorkflow(workflowRunId: string): WorkflowApproval[]
|
|
83
|
+
listForWorkflow(workflowRunId: string): Promise<WorkflowApproval[]>;
|
|
74
84
|
/** List all approvals carrying a specific artifact name, newest first */
|
|
75
|
-
listByArtifact(artifact: string): WorkflowApproval[]
|
|
85
|
+
listByArtifact(artifact: string): Promise<WorkflowApproval[]>;
|
|
76
86
|
/** List all pending approvals */
|
|
77
|
-
listPending(): WorkflowApproval[]
|
|
87
|
+
listPending(): Promise<WorkflowApproval[]>;
|
|
78
88
|
/**
|
|
79
89
|
* Record the response to a still-pending approval.
|
|
80
90
|
*
|
|
@@ -83,6 +93,5 @@ export declare class ApprovalStore {
|
|
|
83
93
|
* first pending row update succeeds and the loser must not resume/fail the
|
|
84
94
|
* workflow a second time.
|
|
85
95
|
*/
|
|
86
|
-
respond(id: string, status: 'approved' | 'rejected', respondedBy: string, response?: string): number
|
|
87
|
-
private deserialize;
|
|
96
|
+
respond(id: string, status: 'approved' | 'rejected', respondedBy: string, response?: string, dbc?: StateDbc): Promise<number>;
|
|
88
97
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { and, asc, desc, eq } from "drizzle-orm";
|
|
2
|
+
import { nullsToUndefined, tablesOf, } from "./client.js";
|
|
3
|
+
import { changes } from "./dialect.js";
|
|
1
4
|
/**
|
|
2
5
|
* Owns the `workflow_approvals` table — the human-in-the-loop gates a workflow
|
|
3
6
|
* run can pause on. Carved out of the old `StateDb` god-class (issue #97).
|
|
@@ -7,20 +10,37 @@
|
|
|
7
10
|
* status flip (resolve-and-resume, resolve-and-fail, pause-for-approval) live
|
|
8
11
|
* on {@link WorkflowRunStore}, the aggregate root, which is injected with an
|
|
9
12
|
* instance of this store and calls these methods inside a single transaction.
|
|
13
|
+
* That is what the trailing `dbc` parameter on `create` / `respond` /
|
|
14
|
+
* `resolveReplyGate` / `getById` is for: they run against the enclosing
|
|
15
|
+
* transaction when the aggregate passes one, and against the root client
|
|
16
|
+
* otherwise.
|
|
10
17
|
*/
|
|
11
18
|
export class ApprovalStore {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
client;
|
|
20
|
+
/**
|
|
21
|
+
* Table objects for THIS client's dialect. Every method destructures what it
|
|
22
|
+
* needs off this instead of importing from `schema/sqlite.js` — see
|
|
23
|
+
* `client.ts` → {@link tablesOf} for why the cast alone cannot do it.
|
|
24
|
+
*/
|
|
25
|
+
t;
|
|
26
|
+
constructor(client) {
|
|
27
|
+
this.client = client;
|
|
28
|
+
this.t = tablesOf(client);
|
|
15
29
|
}
|
|
16
30
|
/** Create a new pending approval request */
|
|
17
|
-
create(approval) {
|
|
18
|
-
this.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
async create(approval, dbc = this.client) {
|
|
32
|
+
const { workflowApprovals } = this.t;
|
|
33
|
+
await dbc.insert(workflowApprovals).values({
|
|
34
|
+
id: approval.id,
|
|
35
|
+
workflowRunId: approval.workflowRunId,
|
|
36
|
+
gate: approval.gate,
|
|
37
|
+
summary: approval.summary,
|
|
38
|
+
status: "pending",
|
|
39
|
+
kind: approval.kind ?? "approve",
|
|
40
|
+
artifact: approval.artifact ?? null,
|
|
41
|
+
requestedBy: approval.requestedBy ?? null,
|
|
42
|
+
createdAt: approval.createdAt,
|
|
43
|
+
});
|
|
24
44
|
}
|
|
25
45
|
/**
|
|
26
46
|
* Resolve a reply gate: marks the approval row as approved (reply gates
|
|
@@ -34,55 +54,62 @@ export class ApprovalStore {
|
|
|
34
54
|
* same thread, the second sees 0 rows and the transaction aborts before a
|
|
35
55
|
* duplicate resume.
|
|
36
56
|
*/
|
|
37
|
-
resolveReplyGate(id, replyText, responder) {
|
|
57
|
+
async resolveReplyGate(id, replyText, responder, dbc = this.client) {
|
|
58
|
+
const { workflowApprovals } = this.t;
|
|
38
59
|
const now = new Date().toISOString();
|
|
39
|
-
const result =
|
|
40
|
-
.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
responded_at = ?
|
|
45
|
-
WHERE id = ? AND kind = 'reply' AND status = 'pending'`)
|
|
46
|
-
.run(responder, replyText, now, id);
|
|
47
|
-
return result.changes;
|
|
60
|
+
const result = await dbc
|
|
61
|
+
.update(workflowApprovals)
|
|
62
|
+
.set({ status: "approved", respondedBy: responder, response: replyText, respondedAt: now })
|
|
63
|
+
.where(and(eq(workflowApprovals.id, id), eq(workflowApprovals.kind, "reply"), eq(workflowApprovals.status, "pending")));
|
|
64
|
+
return changes(result);
|
|
48
65
|
}
|
|
49
66
|
/**
|
|
50
67
|
* Find the most recent pending reply gate for a given trigger id. Used by
|
|
51
68
|
* the router to short-circuit free-form replies on a paused socratic
|
|
52
69
|
* explore loop without re-running classifier logic.
|
|
53
70
|
*/
|
|
54
|
-
getPendingReplyGateByTrigger(triggerId) {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
.
|
|
62
|
-
|
|
71
|
+
async getPendingReplyGateByTrigger(triggerId) {
|
|
72
|
+
const { workflowApprovals, workflowRuns } = this.t;
|
|
73
|
+
const [row] = await this.client
|
|
74
|
+
.select(approvalColumns(this.t))
|
|
75
|
+
.from(workflowApprovals)
|
|
76
|
+
.innerJoin(workflowRuns, eq(workflowApprovals.workflowRunId, workflowRuns.id))
|
|
77
|
+
.where(and(eq(workflowRuns.triggerId, triggerId), eq(workflowApprovals.status, "pending"), eq(workflowApprovals.kind, "reply")))
|
|
78
|
+
.orderBy(desc(workflowApprovals.createdAt))
|
|
79
|
+
.limit(1);
|
|
80
|
+
return row ? deserialize(row) : null;
|
|
63
81
|
}
|
|
64
82
|
/** Get a single approval by ID */
|
|
65
|
-
getById(id) {
|
|
66
|
-
const
|
|
67
|
-
|
|
83
|
+
async getById(id, dbc = this.client) {
|
|
84
|
+
const { workflowApprovals } = this.t;
|
|
85
|
+
const [row] = await dbc
|
|
86
|
+
.select()
|
|
87
|
+
.from(workflowApprovals)
|
|
88
|
+
.where(eq(workflowApprovals.id, id))
|
|
89
|
+
.limit(1);
|
|
90
|
+
return row ? deserialize(row) : null;
|
|
68
91
|
}
|
|
69
92
|
/** Find the pending approval for a workflow run */
|
|
70
|
-
getPendingForWorkflow(workflowRunId) {
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
93
|
+
async getPendingForWorkflow(workflowRunId) {
|
|
94
|
+
const { workflowApprovals } = this.t;
|
|
95
|
+
const [row] = await this.client
|
|
96
|
+
.select()
|
|
97
|
+
.from(workflowApprovals)
|
|
98
|
+
.where(and(eq(workflowApprovals.workflowRunId, workflowRunId), eq(workflowApprovals.status, "pending")))
|
|
99
|
+
.limit(1);
|
|
100
|
+
return row ? deserialize(row) : null;
|
|
75
101
|
}
|
|
76
102
|
/** Find the pending approval by trigger ID (join with workflow_runs) */
|
|
77
|
-
getPendingByTrigger(triggerId) {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
103
|
+
async getPendingByTrigger(triggerId) {
|
|
104
|
+
const { workflowApprovals, workflowRuns } = this.t;
|
|
105
|
+
const [row] = await this.client
|
|
106
|
+
.select(approvalColumns(this.t))
|
|
107
|
+
.from(workflowApprovals)
|
|
108
|
+
.innerJoin(workflowRuns, eq(workflowApprovals.workflowRunId, workflowRuns.id))
|
|
109
|
+
.where(and(eq(workflowRuns.triggerId, triggerId), eq(workflowApprovals.status, "pending")))
|
|
110
|
+
.orderBy(desc(workflowApprovals.createdAt))
|
|
111
|
+
.limit(1);
|
|
112
|
+
return row ? deserialize(row) : null;
|
|
86
113
|
}
|
|
87
114
|
/**
|
|
88
115
|
* List every approval for a workflow run — all statuses (pending, approved,
|
|
@@ -90,27 +117,34 @@ export class ApprovalStore {
|
|
|
90
117
|
* (who approved/rejected a gate, when, and any comment). Unlike
|
|
91
118
|
* {@link getPendingForWorkflow} this does not filter on status.
|
|
92
119
|
*/
|
|
93
|
-
listForWorkflow(workflowRunId) {
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
120
|
+
async listForWorkflow(workflowRunId) {
|
|
121
|
+
const { workflowApprovals } = this.t;
|
|
122
|
+
const rows = await this.client
|
|
123
|
+
.select()
|
|
124
|
+
.from(workflowApprovals)
|
|
125
|
+
.where(eq(workflowApprovals.workflowRunId, workflowRunId))
|
|
126
|
+
.orderBy(asc(workflowApprovals.createdAt));
|
|
127
|
+
return rows.map(deserialize);
|
|
98
128
|
}
|
|
99
129
|
/** List all approvals carrying a specific artifact name, newest first */
|
|
100
|
-
listByArtifact(artifact) {
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
130
|
+
async listByArtifact(artifact) {
|
|
131
|
+
const { workflowApprovals } = this.t;
|
|
132
|
+
const rows = await this.client
|
|
133
|
+
.select()
|
|
134
|
+
.from(workflowApprovals)
|
|
135
|
+
.where(eq(workflowApprovals.artifact, artifact))
|
|
136
|
+
.orderBy(desc(workflowApprovals.createdAt));
|
|
137
|
+
return rows.map(deserialize);
|
|
107
138
|
}
|
|
108
139
|
/** List all pending approvals */
|
|
109
|
-
listPending() {
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
140
|
+
async listPending() {
|
|
141
|
+
const { workflowApprovals } = this.t;
|
|
142
|
+
const rows = await this.client
|
|
143
|
+
.select()
|
|
144
|
+
.from(workflowApprovals)
|
|
145
|
+
.where(eq(workflowApprovals.status, "pending"))
|
|
146
|
+
.orderBy(desc(workflowApprovals.createdAt));
|
|
147
|
+
return rows.map(deserialize);
|
|
114
148
|
}
|
|
115
149
|
/**
|
|
116
150
|
* Record the response to a still-pending approval.
|
|
@@ -120,30 +154,47 @@ export class ApprovalStore {
|
|
|
120
154
|
* first pending row update succeeds and the loser must not resume/fail the
|
|
121
155
|
* workflow a second time.
|
|
122
156
|
*/
|
|
123
|
-
respond(id, status, respondedBy, response) {
|
|
157
|
+
async respond(id, status, respondedBy, response, dbc = this.client) {
|
|
158
|
+
const { workflowApprovals } = this.t;
|
|
124
159
|
const now = new Date().toISOString();
|
|
125
|
-
const result =
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return result.changes;
|
|
131
|
-
}
|
|
132
|
-
deserialize(row) {
|
|
133
|
-
return {
|
|
134
|
-
id: row.id,
|
|
135
|
-
workflowRunId: row.workflow_run_id,
|
|
136
|
-
gate: row.gate,
|
|
137
|
-
summary: row.summary,
|
|
138
|
-
status: row.status,
|
|
139
|
-
kind: (row.kind || "approve"),
|
|
140
|
-
artifact: row.artifact || undefined,
|
|
141
|
-
requestedBy: row.requested_by || undefined,
|
|
142
|
-
respondedBy: row.responded_by || undefined,
|
|
143
|
-
response: row.response || undefined,
|
|
144
|
-
respondedAt: row.responded_at || undefined,
|
|
145
|
-
createdAt: row.created_at,
|
|
146
|
-
};
|
|
160
|
+
const result = await dbc
|
|
161
|
+
.update(workflowApprovals)
|
|
162
|
+
.set({ status, respondedBy, response: response ?? null, respondedAt: now })
|
|
163
|
+
.where(and(eq(workflowApprovals.id, id), eq(workflowApprovals.status, "pending")));
|
|
164
|
+
return changes(result);
|
|
147
165
|
}
|
|
148
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Explicit column map for the two joined reads. A bare `.select()` across a
|
|
169
|
+
* join returns `{ workflow_approvals: {...}, workflow_runs: {...} }`; naming
|
|
170
|
+
* the columns keeps those two methods returning a flat approval row like every
|
|
171
|
+
* other read here.
|
|
172
|
+
*/
|
|
173
|
+
const approvalColumns = ({ workflowApprovals }) => ({
|
|
174
|
+
id: workflowApprovals.id,
|
|
175
|
+
workflowRunId: workflowApprovals.workflowRunId,
|
|
176
|
+
gate: workflowApprovals.gate,
|
|
177
|
+
summary: workflowApprovals.summary,
|
|
178
|
+
status: workflowApprovals.status,
|
|
179
|
+
requestedBy: workflowApprovals.requestedBy,
|
|
180
|
+
respondedBy: workflowApprovals.respondedBy,
|
|
181
|
+
response: workflowApprovals.response,
|
|
182
|
+
respondedAt: workflowApprovals.respondedAt,
|
|
183
|
+
createdAt: workflowApprovals.createdAt,
|
|
184
|
+
kind: workflowApprovals.kind,
|
|
185
|
+
artifact: workflowApprovals.artifact,
|
|
186
|
+
});
|
|
187
|
+
/**
|
|
188
|
+
* Builder rows are already camelCase, so this is down to two jobs: turn the
|
|
189
|
+
* nullable columns into absent optionals, and keep the `kind` fallback for
|
|
190
|
+
* rows written before that column existed.
|
|
191
|
+
*/
|
|
192
|
+
function deserialize(row) {
|
|
193
|
+
const r = nullsToUndefined(row);
|
|
194
|
+
return {
|
|
195
|
+
...r,
|
|
196
|
+
status: r.status,
|
|
197
|
+
kind: (r.kind || "approve"),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
149
200
|
//# sourceMappingURL=approval-store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval-store.js","sourceRoot":"","sources":["../../src/state/approval-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AAC;QACrF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,eAAe,GAAG,CAAC,EAAE,iBAAiB,EAAe,EAAE,EAAE,CAAC,CAAC;IAC/D,EAAE,EAAE,iBAAiB,CAAC,EAAE;IACxB,aAAa,EAAE,iBAAiB,CAAC,aAAa;IAC9C,IAAI,EAAE,iBAAiB,CAAC,IAAI;IAC5B,OAAO,EAAE,iBAAiB,CAAC,OAAO;IAClC,MAAM,EAAE,iBAAiB,CAAC,MAAM;IAChC,WAAW,EAAE,iBAAiB,CAAC,WAAW;IAC1C,WAAW,EAAE,iBAAiB,CAAC,WAAW;IAC1C,QAAQ,EAAE,iBAAiB,CAAC,QAAQ;IACpC,WAAW,EAAE,iBAAiB,CAAC,WAAW;IAC1C,SAAS,EAAE,iBAAiB,CAAC,SAAS;IACtC,IAAI,EAAE,iBAAiB,CAAC,IAAI;IAC5B,QAAQ,EAAE,iBAAiB,CAAC,QAAQ;CACrC,CAAC,CAAC;AAEH;;;;GAIG;AACH,SAAS,WAAW,CAAC,GAAgB;IACnC,MAAM,CAAC,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAChC,OAAO;QACL,GAAG,CAAC;QACJ,MAAM,EAAE,CAAC,CAAC,MAAoC;QAC9C,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,SAAS,CAA6B;KACxD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Drizzle client seam.
|
|
3
|
+
*
|
|
4
|
+
* Store code is written ONCE, typed against the sqlite Drizzle instance — the
|
|
5
|
+
* production path. A Postgres instance (Phase 4, PGlite in tests) is adapted
|
|
6
|
+
* through the `asStateClient()` cast below. That is sound because the
|
|
7
|
+
* query-builder surface the stores use (`select` / `insert` / `update` /
|
|
8
|
+
* `delete` / `transaction`) is structurally identical across drivers; the two
|
|
9
|
+
* genuinely divergent surfaces — raw SQL execution and rows-affected shape —
|
|
10
|
+
* are funneled through `rows()` / `run()` / `changes()` in `dialect.ts`.
|
|
11
|
+
*
|
|
12
|
+
* **The cast alone is NOT enough, and this is the one thing to remember here.**
|
|
13
|
+
* The query-builder surface is portable but PER-COLUMN VALUE MAPPING is not: a
|
|
14
|
+
* `sqliteTable` object driven by a PG client sends `1` into a `boolean` column
|
|
15
|
+
* (sqlite's `mapToDriverValue`; `PgBoolean` has none) and runs `JSON.parse`
|
|
16
|
+
* over an already-parsed jsonb object. Booleans break on WRITE, JSON on READ,
|
|
17
|
+
* and `dialect.ts` cannot see either. So no store may import its tables from
|
|
18
|
+
* `./schema/sqlite.js` — they resolve them per dialect through
|
|
19
|
+
* {@link tablesOf}, which hands back `schema/sqlite.ts`'s objects on the sqlite
|
|
20
|
+
* leg and `schema/pg.ts`'s on the Postgres one, from the same code.
|
|
21
|
+
*
|
|
22
|
+
* Backend selection is construction-time injection (`StateDb.open` /
|
|
23
|
+
* `StateDb.fromClient`), never a module-load env global, so both dialects can
|
|
24
|
+
* be constructed in one test process.
|
|
25
|
+
*/
|
|
26
|
+
import type { LibSQLDatabase } from "drizzle-orm/libsql";
|
|
27
|
+
import * as sqliteSchema from "./schema/sqlite.js";
|
|
28
|
+
/** Runtime discriminator carried by StateDb. Branches `dialect.ts` helpers only. */
|
|
29
|
+
export type Dialect = "sqlite" | "postgres";
|
|
30
|
+
export type StateClient = LibSQLDatabase<typeof sqliteSchema>;
|
|
31
|
+
/** The transaction handle `client.transaction()` passes to its callback. */
|
|
32
|
+
export type StateTx = Parameters<Parameters<StateClient["transaction"]>[0]>[0];
|
|
33
|
+
/**
|
|
34
|
+
* Anything a store method can run queries against: the root client, or an
|
|
35
|
+
* enclosing transaction. Methods that participate in a cross-store atomic op
|
|
36
|
+
* take this as a trailing `dbc` parameter defaulting to `this.client`.
|
|
37
|
+
*/
|
|
38
|
+
export type StateDbc = StateClient | StateTx;
|
|
39
|
+
/**
|
|
40
|
+
* The ONE documented cast that lets a non-libsql Drizzle instance (PGlite in
|
|
41
|
+
* Phase 4 tests) drive the sqlite-typed stores. Do not add a second cast site.
|
|
42
|
+
*
|
|
43
|
+
* Two obligations the cast cannot enforce, both on the caller:
|
|
44
|
+
*
|
|
45
|
+
* 1. **Build the instance with its own schema** — `drizzle(pglite, { schema:
|
|
46
|
+
* pgSchema })`. {@link tablesOf} reads the tables back off it, and throws
|
|
47
|
+
* loudly rather than silently mis-mapping if the schema was omitted.
|
|
48
|
+
* 2. **Normalize int8.** Postgres returns `COUNT(*)` / `SUM(...)` as int8,
|
|
49
|
+
* which node-postgres hands back as a STRING. PGlite ≥0.5 parses it to a
|
|
50
|
+
* number by default; a real PG client must be configured to
|
|
51
|
+
* (`types.setTypeParser(20, Number)`), or every aggregate silently arrives
|
|
52
|
+
* stringified.
|
|
53
|
+
*/
|
|
54
|
+
export declare function asStateClient(db: unknown): StateClient;
|
|
55
|
+
/**
|
|
56
|
+
* The dialect-resolved table objects. Typed as the sqlite schema because that
|
|
57
|
+
* is the production path and the two schemas mirror each other export-for-export
|
|
58
|
+
* and property-for-property (`tests/state/schema-parity.test.ts` is the guard).
|
|
59
|
+
*/
|
|
60
|
+
export type StateTables = typeof sqliteSchema;
|
|
61
|
+
/**
|
|
62
|
+
* The table objects belonging to a client — `schema/sqlite.ts`'s on a libsql
|
|
63
|
+
* client, `schema/pg.ts`'s on a Postgres one.
|
|
64
|
+
*
|
|
65
|
+
* Drizzle already carries the schema it was constructed with (`db._.fullSchema`
|
|
66
|
+
* is the object handed to `drizzle(client, { schema })`, and is typed for us),
|
|
67
|
+
* so this needs no extra constructor parameter and no second cast — the PG leg
|
|
68
|
+
* just passes `pgSchema` where production passes `sqliteSchema`. That also
|
|
69
|
+
* keeps `schema/pg.ts` out of the runtime import graph entirely: nothing under
|
|
70
|
+
* `src/` names it.
|
|
71
|
+
*
|
|
72
|
+
* A client built WITHOUT `{ schema }` would leave this empty and every store
|
|
73
|
+
* would then dereference `undefined`, so validate once, here, where the message
|
|
74
|
+
* can say what to fix.
|
|
75
|
+
*/
|
|
76
|
+
export declare function tablesOf(client: StateClient): StateTables;
|
|
77
|
+
/**
|
|
78
|
+
* Serializes the operations that open a transaction (README locked decision 8).
|
|
79
|
+
*
|
|
80
|
+
* ONE per CONNECTION, shared by every store that transacts — not one per store.
|
|
81
|
+
* `WorkflowRunStore` owns five transacting ops and `TeamStore` four, all on the
|
|
82
|
+
* same libsql client; a store-scoped chain would leave run-op-vs-team-op races
|
|
83
|
+
* completely unguarded. Overlapping libsql interactive transactions fail in
|
|
84
|
+
* ways beyond SQLITE_BUSY (nested BEGIN, shared-handle interleaving), and
|
|
85
|
+
* `busy_timeout` cannot help because it is connection-scoped and the client
|
|
86
|
+
* swaps connections after each transaction. So this mutex, not the pragma, is
|
|
87
|
+
* the load-bearing defense — and it is semantically free in a single-writer
|
|
88
|
+
* process.
|
|
89
|
+
*/
|
|
90
|
+
export type OpSerializer = <T>(fn: () => Promise<T>) => Promise<T>;
|
|
91
|
+
export declare function makeOpSerializer(): OpSerializer;
|
|
92
|
+
/** `{ a: string | null }` → `{ a: string | undefined }`, leaving the rest alone. */
|
|
93
|
+
export type NullsToUndefined<T> = {
|
|
94
|
+
[K in keyof T]: null extends T[K] ? Exclude<T[K], null> | undefined : T[K];
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Drizzle returns `null` for a nullable column; the record types spell those
|
|
98
|
+
* fields as optionals (`foo?: string`). Strip the nulls at the store boundary
|
|
99
|
+
* so `record.foo === undefined` behaves as it always has.
|
|
100
|
+
*
|
|
101
|
+
* The return type is transformed too, not just the value — otherwise every
|
|
102
|
+
* caller needs an `as unknown as Record` double cast to hand the result back as
|
|
103
|
+
* its public record type, which would defeat the point of having one helper.
|
|
104
|
+
*/
|
|
105
|
+
export declare function nullsToUndefined<T extends Record<string, unknown>>(row: T): NullsToUndefined<T>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE documented cast that lets a non-libsql Drizzle instance (PGlite in
|
|
3
|
+
* Phase 4 tests) drive the sqlite-typed stores. Do not add a second cast site.
|
|
4
|
+
*
|
|
5
|
+
* Two obligations the cast cannot enforce, both on the caller:
|
|
6
|
+
*
|
|
7
|
+
* 1. **Build the instance with its own schema** — `drizzle(pglite, { schema:
|
|
8
|
+
* pgSchema })`. {@link tablesOf} reads the tables back off it, and throws
|
|
9
|
+
* loudly rather than silently mis-mapping if the schema was omitted.
|
|
10
|
+
* 2. **Normalize int8.** Postgres returns `COUNT(*)` / `SUM(...)` as int8,
|
|
11
|
+
* which node-postgres hands back as a STRING. PGlite ≥0.5 parses it to a
|
|
12
|
+
* number by default; a real PG client must be configured to
|
|
13
|
+
* (`types.setTypeParser(20, Number)`), or every aggregate silently arrives
|
|
14
|
+
* stringified.
|
|
15
|
+
*/
|
|
16
|
+
export function asStateClient(db) {
|
|
17
|
+
return db;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The table objects belonging to a client — `schema/sqlite.ts`'s on a libsql
|
|
21
|
+
* client, `schema/pg.ts`'s on a Postgres one.
|
|
22
|
+
*
|
|
23
|
+
* Drizzle already carries the schema it was constructed with (`db._.fullSchema`
|
|
24
|
+
* is the object handed to `drizzle(client, { schema })`, and is typed for us),
|
|
25
|
+
* so this needs no extra constructor parameter and no second cast — the PG leg
|
|
26
|
+
* just passes `pgSchema` where production passes `sqliteSchema`. That also
|
|
27
|
+
* keeps `schema/pg.ts` out of the runtime import graph entirely: nothing under
|
|
28
|
+
* `src/` names it.
|
|
29
|
+
*
|
|
30
|
+
* A client built WITHOUT `{ schema }` would leave this empty and every store
|
|
31
|
+
* would then dereference `undefined`, so validate once, here, where the message
|
|
32
|
+
* can say what to fix.
|
|
33
|
+
*/
|
|
34
|
+
export function tablesOf(client) {
|
|
35
|
+
const tables = client._?.fullSchema;
|
|
36
|
+
if (!tables?.executions) {
|
|
37
|
+
throw new Error("StateClient was constructed without its schema — call " +
|
|
38
|
+
"drizzle(client, { schema }) with schema/sqlite.js or schema/pg.js. " +
|
|
39
|
+
"Stores resolve their table objects from it (per-dialect value mapping).");
|
|
40
|
+
}
|
|
41
|
+
return tables;
|
|
42
|
+
}
|
|
43
|
+
export function makeOpSerializer() {
|
|
44
|
+
let chain = Promise.resolve();
|
|
45
|
+
return (fn) => {
|
|
46
|
+
// Run regardless of how the previous op settled…
|
|
47
|
+
const next = chain.then(fn, fn);
|
|
48
|
+
// …and never let a rejection poison the chain for everyone behind it.
|
|
49
|
+
chain = next.catch(() => { });
|
|
50
|
+
return next;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Drizzle returns `null` for a nullable column; the record types spell those
|
|
55
|
+
* fields as optionals (`foo?: string`). Strip the nulls at the store boundary
|
|
56
|
+
* so `record.foo === undefined` behaves as it always has.
|
|
57
|
+
*
|
|
58
|
+
* The return type is transformed too, not just the value — otherwise every
|
|
59
|
+
* caller needs an `as unknown as Record` double cast to hand the result back as
|
|
60
|
+
* its public record type, which would defeat the point of having one helper.
|
|
61
|
+
*/
|
|
62
|
+
export function nullsToUndefined(row) {
|
|
63
|
+
const out = {};
|
|
64
|
+
for (const [key, value] of Object.entries(row))
|
|
65
|
+
out[key] = value === null ? undefined : value;
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/state/client.ts"],"names":[],"mappings":"AA2CA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,aAAa,CAAC,EAAW;IACvC,OAAO,EAAiB,CAAC;AAC3B,CAAC;AASD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,QAAQ,CAAC,MAAmB;IAC1C,MAAM,MAAM,GAAI,MAA+C,CAAC,CAAC,EAAE,UAAU,CAAC;IAC9E,IAAI,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,wDAAwD;YACtD,qEAAqE;YACrE,yEAAyE,CAC5E,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAiBD,MAAM,UAAU,gBAAgB;IAC9B,IAAI,KAAK,GAAqB,OAAO,CAAC,OAAO,EAAE,CAAC;IAChD,OAAO,CAAI,EAAoB,EAAc,EAAE;QAC7C,iDAAiD;QACjD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAChC,sEAAsE;QACtE,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC;AAOD;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAoC,GAAM;IACxE,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;IAC9F,OAAO,GAA0B,CAAC;AACpC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type StateClient } from "./client.js";
|
|
2
2
|
/** How a fire was started. */
|
|
3
3
|
export type CronRunSource = "schedule" | "manual";
|
|
4
4
|
/**
|
|
@@ -63,14 +63,32 @@ export interface CronRunFinish {
|
|
|
63
63
|
* and vice versa (issue #327).
|
|
64
64
|
*/
|
|
65
65
|
export declare class CronRunStore {
|
|
66
|
-
private
|
|
67
|
-
|
|
66
|
+
private client;
|
|
67
|
+
/**
|
|
68
|
+
* Table objects for THIS client's dialect. Every method destructures what it
|
|
69
|
+
* needs off this instead of importing from `schema/sqlite.js` — see
|
|
70
|
+
* `client.ts` → {@link tablesOf} for why the cast alone cannot do it.
|
|
71
|
+
*/
|
|
72
|
+
private readonly t;
|
|
73
|
+
constructor(client: StateClient);
|
|
68
74
|
/** Insert a `running` row and return its id. */
|
|
69
|
-
start(meta: CronRunStart): string
|
|
75
|
+
start(meta: CronRunStart): Promise<string>;
|
|
70
76
|
/** Stamp `finished_at` and the terminal fields. */
|
|
71
|
-
finish(id: string, result: CronRunFinish): void
|
|
72
|
-
/**
|
|
73
|
-
|
|
77
|
+
finish(id: string, result: CronRunFinish): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Most recent row per cron name — what the dashboard's crons list reads.
|
|
80
|
+
*
|
|
81
|
+
* A window function, so it stays raw SQL. Two portability notes: the derived
|
|
82
|
+
* table carries an explicit alias (Postgres rejects a `FROM` subquery without
|
|
83
|
+
* one), and `rn` is a `ROW_NUMBER()` rank — `rn = 1` is an integer compare,
|
|
84
|
+
* not a boolean. The tiebreak is `id DESC` — a real recency order, because
|
|
85
|
+
* the ids are minted in creation order ({@link creationOrderedId}); picking
|
|
86
|
+
* the wrong row of a tie here would show the dashboard the wrong outcome.
|
|
87
|
+
*
|
|
88
|
+
* `rows()` results are NOT column-mapped, so {@link mapCronRunRow} reads the
|
|
89
|
+
* raw snake_case column names.
|
|
90
|
+
*/
|
|
91
|
+
latestByCron(): Promise<Map<string, CronRunRecord>>;
|
|
74
92
|
/**
|
|
75
93
|
* Consecutive non-`ok` TERMINAL fires, newest first.
|
|
76
94
|
*
|
|
@@ -79,10 +97,12 @@ export declare class CronRunStore {
|
|
|
79
97
|
* it. Mirrors `ExecutionStore.consecutiveFailures` in shape so the
|
|
80
98
|
* scheduler's call site changes key and table but not logic.
|
|
81
99
|
*
|
|
82
|
-
* `
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
100
|
+
* `id DESC` breaks ties on `started_at`, and the ids are minted in creation
|
|
101
|
+
* order for exactly that purpose — see {@link creationOrderedId}. A merely
|
|
102
|
+
* DETERMINISTIC tiebreak is not sufficient here, which is the trap: this walk
|
|
103
|
+
* stops at the first `ok`, so a tie holding one `ok` and one `failed` returns
|
|
104
|
+
* a different count depending which sorts first. It has to be the RIGHT
|
|
105
|
+
* order, not just a stable one.
|
|
86
106
|
*/
|
|
87
|
-
recentFailures(cronName: string): number
|
|
107
|
+
recentFailures(cronName: string): Promise<number>;
|
|
88
108
|
}
|