@facilis.dev/nitro 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +18 -2
- package/dist/config.d.ts +30 -0
- package/dist/config.js +112 -0
- package/dist/constants.d.ts +24 -0
- package/dist/constants.js +24 -0
- package/dist/facade.d.ts +37 -0
- package/dist/facade.js +121 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +14 -0
- package/dist/middleware/context.d.ts +5 -0
- package/dist/middleware/context.js +86 -0
- package/dist/middleware/cors.d.ts +10 -0
- package/dist/middleware/cors.js +34 -0
- package/dist/middleware/session.d.ts +9 -0
- package/dist/middleware/session.js +18 -0
- package/dist/module.d.ts +7 -0
- package/dist/module.js +234 -0
- package/dist/rolldown-parser.d.ts +3 -0
- package/dist/rolldown-parser.js +66 -0
- package/dist/route-metadata.d.ts +22 -0
- package/dist/route-metadata.js +161 -0
- package/dist/routes/dev-query.post.d.ts +10 -0
- package/dist/routes/dev-query.post.js +49 -0
- package/dist/routes/dev-schema.get.d.ts +9 -0
- package/dist/routes/dev-schema.get.js +34 -0
- package/dist/routes/dev-view.post.d.ts +11 -0
- package/dist/routes/dev-view.post.js +61 -0
- package/dist/routes/health.get.d.ts +8 -0
- package/dist/routes/health.get.js +18 -0
- package/dist/routes/manifest-revision.get.d.ts +8 -0
- package/dist/routes/manifest-revision.get.js +26 -0
- package/dist/routes/manifest.get.d.ts +8 -0
- package/dist/routes/manifest.get.js +68 -0
- package/dist/routes/openapi.get.d.ts +8 -0
- package/dist/routes/openapi.get.js +29 -0
- package/dist/routes/sso.d.ts +2 -0
- package/dist/routes/sso.js +216 -0
- package/dist/routes/token.post.d.ts +10 -0
- package/dist/routes/token.post.js +75 -0
- package/dist/runtime/boot-runtimes.d.ts +21 -0
- package/dist/runtime/boot-runtimes.js +38 -0
- package/dist/runtime/bootstrap.d.ts +47 -0
- package/dist/runtime/bootstrap.js +214 -0
- package/dist/runtime/config.d.ts +27 -0
- package/dist/runtime/config.js +44 -0
- package/dist/runtime/cors-policy.d.ts +16 -0
- package/dist/runtime/cors-policy.js +88 -0
- package/dist/runtime/db-bootstrap.d.ts +9 -0
- package/dist/runtime/db-bootstrap.js +87 -0
- package/dist/runtime/db-target.d.ts +21 -0
- package/dist/runtime/db-target.js +52 -0
- package/dist/runtime/dev-db-persistence.d.ts +39 -0
- package/dist/runtime/dev-db-persistence.js +124 -0
- package/dist/runtime/dev-query.d.ts +38 -0
- package/dist/runtime/dev-query.js +87 -0
- package/dist/runtime/env.d.ts +9 -0
- package/dist/runtime/env.js +14 -0
- package/dist/runtime/http-guard.d.ts +16 -0
- package/dist/runtime/http-guard.js +42 -0
- package/dist/runtime/http.d.ts +11 -0
- package/dist/runtime/http.js +18 -0
- package/dist/runtime/jobs/boot.d.ts +20 -0
- package/dist/runtime/jobs/boot.js +77 -0
- package/dist/runtime/jobs/contracts.d.ts +161 -0
- package/dist/runtime/jobs/contracts.js +1 -0
- package/dist/runtime/jobs/db-store.d.ts +21 -0
- package/dist/runtime/jobs/db-store.js +210 -0
- package/dist/runtime/jobs/definitions.d.ts +14 -0
- package/dist/runtime/jobs/definitions.js +31 -0
- package/dist/runtime/jobs/engine-support.d.ts +22 -0
- package/dist/runtime/jobs/engine-support.js +32 -0
- package/dist/runtime/jobs/engine.d.ts +6 -0
- package/dist/runtime/jobs/engine.js +261 -0
- package/dist/runtime/jobs/executor.d.ts +11 -0
- package/dist/runtime/jobs/executor.js +27 -0
- package/dist/runtime/jobs/memory-store.d.ts +7 -0
- package/dist/runtime/jobs/memory-store.js +183 -0
- package/dist/runtime/jobs/row-mapping.d.ts +28 -0
- package/dist/runtime/jobs/row-mapping.js +61 -0
- package/dist/runtime/jobs/runtime.d.ts +24 -0
- package/dist/runtime/jobs/runtime.js +86 -0
- package/dist/runtime/logging/audit-chain.d.ts +54 -0
- package/dist/runtime/logging/audit-chain.js +102 -0
- package/dist/runtime/logging/bootstrap-logging.d.ts +28 -0
- package/dist/runtime/logging/bootstrap-logging.js +26 -0
- package/dist/runtime/logging/entry.d.ts +14 -0
- package/dist/runtime/logging/entry.js +85 -0
- package/dist/runtime/logging/file-sink.d.ts +24 -0
- package/dist/runtime/logging/file-sink.js +128 -0
- package/dist/runtime/logging/log-settings.d.ts +52 -0
- package/dist/runtime/logging/log-settings.js +93 -0
- package/dist/runtime/logging/log-sink.d.ts +18 -0
- package/dist/runtime/logging/log-sink.js +22 -0
- package/dist/runtime/logging/redact.d.ts +31 -0
- package/dist/runtime/logging/redact.js +106 -0
- package/dist/runtime/logging/runtime.d.ts +25 -0
- package/dist/runtime/logging/runtime.js +114 -0
- package/dist/runtime/logging/sudo-bridge.d.ts +13 -0
- package/dist/runtime/logging/sudo-bridge.js +38 -0
- package/dist/runtime/manifest-data.d.ts +28 -0
- package/dist/runtime/manifest-data.js +70 -0
- package/dist/runtime/manifest-response.d.ts +45 -0
- package/dist/runtime/manifest-response.js +50 -0
- package/dist/runtime/manifest-sections.d.ts +20 -0
- package/dist/runtime/manifest-sections.js +59 -0
- package/dist/runtime/manifest-service.d.ts +16 -0
- package/dist/runtime/manifest-service.js +66 -0
- package/dist/runtime/project-config.d.ts +8 -0
- package/dist/runtime/project-config.js +22 -0
- package/dist/runtime/project-files.d.ts +12 -0
- package/dist/runtime/project-files.js +99 -0
- package/dist/runtime/rate-limit.d.ts +6 -0
- package/dist/runtime/rate-limit.js +6 -0
- package/dist/runtime/revision-service.d.ts +15 -0
- package/dist/runtime/revision-service.js +26 -0
- package/dist/runtime/sql.d.ts +8 -0
- package/dist/runtime/sql.js +23 -0
- package/dist/runtime/sso.d.ts +40 -0
- package/dist/runtime/sso.js +98 -0
- package/dist/runtime/state.d.ts +7 -0
- package/dist/runtime/state.js +7 -0
- package/dist/runtime/storage-keys.d.ts +9 -0
- package/dist/runtime/storage-keys.js +82 -0
- package/dist/runtime/storage-target.d.ts +25 -0
- package/dist/runtime/storage-target.js +155 -0
- package/dist/runtime/system-role.d.ts +9 -0
- package/dist/runtime/system-role.js +21 -0
- package/dist/runtime/tasks/boot.d.ts +20 -0
- package/dist/runtime/tasks/boot.js +32 -0
- package/dist/runtime/tasks/contracts.d.ts +70 -0
- package/dist/runtime/tasks/contracts.js +1 -0
- package/dist/runtime/tasks/db-store.d.ts +18 -0
- package/dist/runtime/tasks/db-store.js +139 -0
- package/dist/runtime/tasks/row-mapping.d.ts +11 -0
- package/dist/runtime/tasks/row-mapping.js +69 -0
- package/dist/runtime/tasks/runtime.d.ts +7 -0
- package/dist/runtime/tasks/runtime.js +162 -0
- package/dist/runtime/tasks/tasks-test-harness.d.ts +16 -0
- package/dist/runtime/tasks/tasks-test-harness.js +70 -0
- package/dist/runtime/tenant.d.ts +10 -0
- package/dist/runtime/tenant.js +13 -0
- package/dist/runtime/workflows/boot.d.ts +25 -0
- package/dist/runtime/workflows/boot.js +75 -0
- package/dist/runtime/workflows/contracts.d.ts +96 -0
- package/dist/runtime/workflows/contracts.js +1 -0
- package/dist/runtime/workflows/db-store.d.ts +18 -0
- package/dist/runtime/workflows/db-store.js +128 -0
- package/dist/runtime/workflows/definitions.d.ts +14 -0
- package/dist/runtime/workflows/definitions.js +50 -0
- package/dist/runtime/workflows/dispatch.d.ts +4 -0
- package/dist/runtime/workflows/dispatch.js +119 -0
- package/dist/runtime/workflows/row-mapping.d.ts +5 -0
- package/dist/runtime/workflows/row-mapping.js +38 -0
- package/dist/runtime/workflows/runner.d.ts +15 -0
- package/dist/runtime/workflows/runner.js +89 -0
- package/dist/runtime/workflows/runtime.d.ts +14 -0
- package/dist/runtime/workflows/runtime.js +129 -0
- package/dist/runtime/workflows/steps.d.ts +14 -0
- package/dist/runtime/workflows/steps.js +49 -0
- package/dist/runtime/workflows/support.d.ts +20 -0
- package/dist/runtime/workflows/support.js +36 -0
- package/dist/runtime/workflows/transitions.d.ts +8 -0
- package/dist/runtime/workflows/transitions.js +184 -0
- package/dist/runtime/workflows/workflows-test-harness.d.ts +62 -0
- package/dist/runtime/workflows/workflows-test-harness.js +178 -0
- package/dist/session-cookie.d.ts +13 -0
- package/dist/session-cookie.js +48 -0
- package/dist/storage.d.ts +50 -0
- package/dist/storage.js +118 -0
- package/dist/types.d.ts +44 -0
- package/dist/types.js +1 -0
- package/dist/virtual-ids.d.ts +17 -0
- package/dist/virtual-ids.js +17 -0
- package/dist/vite.d.ts +22 -0
- package/dist/vite.js +135 -0
- package/package.json +61 -4
- package/src/config.ts +120 -0
- package/src/constants.ts +24 -0
- package/src/facade.ts +153 -0
- package/src/index.ts +44 -0
- package/src/middleware/context.ts +106 -0
- package/src/middleware/cors.ts +42 -0
- package/src/middleware/session.ts +23 -0
- package/src/module.ts +278 -0
- package/src/rolldown-parser.ts +79 -0
- package/src/route-metadata-test-harness.ts +62 -0
- package/src/route-metadata.ts +194 -0
- package/src/routes/dev-query.post.ts +53 -0
- package/src/routes/dev-schema.get.ts +43 -0
- package/src/routes/dev-view.post.ts +66 -0
- package/src/routes/health.get.ts +26 -0
- package/src/routes/manifest-revision.get.ts +38 -0
- package/src/routes/manifest.get.ts +111 -0
- package/src/routes/openapi.get.ts +34 -0
- package/src/routes/sso.ts +247 -0
- package/src/routes/token.post.ts +89 -0
- package/src/runtime/boot-runtimes.ts +69 -0
- package/src/runtime/bootstrap.ts +300 -0
- package/src/runtime/config.ts +60 -0
- package/src/runtime/cors-policy.ts +107 -0
- package/src/runtime/db-bootstrap.ts +99 -0
- package/src/runtime/db-target.ts +87 -0
- package/src/runtime/dev-db-persistence.ts +146 -0
- package/src/runtime/dev-query.ts +124 -0
- package/src/runtime/env.ts +18 -0
- package/src/runtime/http-guard.ts +50 -0
- package/src/runtime/http.ts +30 -0
- package/src/runtime/jobs/boot.ts +97 -0
- package/src/runtime/jobs/contracts.ts +165 -0
- package/src/runtime/jobs/db-store-test-harness.ts +98 -0
- package/src/runtime/jobs/db-store.ts +273 -0
- package/src/runtime/jobs/definitions.ts +42 -0
- package/src/runtime/jobs/engine-support.ts +44 -0
- package/src/runtime/jobs/engine.ts +296 -0
- package/src/runtime/jobs/executor.ts +37 -0
- package/src/runtime/jobs/memory-store.ts +222 -0
- package/src/runtime/jobs/row-mapping.ts +67 -0
- package/src/runtime/jobs/runtime.ts +110 -0
- package/src/runtime/logging/audit-chain.ts +135 -0
- package/src/runtime/logging/bootstrap-logging.ts +62 -0
- package/src/runtime/logging/entry.ts +99 -0
- package/src/runtime/logging/file-sink.ts +157 -0
- package/src/runtime/logging/log-settings.ts +166 -0
- package/src/runtime/logging/log-sink.ts +31 -0
- package/src/runtime/logging/redact.ts +108 -0
- package/src/runtime/logging/runtime.ts +163 -0
- package/src/runtime/logging/sudo-bridge.ts +41 -0
- package/src/runtime/manifest-data.ts +103 -0
- package/src/runtime/manifest-response.ts +95 -0
- package/src/runtime/manifest-sections.ts +79 -0
- package/src/runtime/manifest-service.ts +83 -0
- package/src/runtime/project-config.ts +25 -0
- package/src/runtime/project-files.ts +103 -0
- package/src/runtime/rate-limit.ts +12 -0
- package/src/runtime/revision-service.ts +38 -0
- package/src/runtime/sql.ts +24 -0
- package/src/runtime/sso.ts +153 -0
- package/src/runtime/state.ts +7 -0
- package/src/runtime/storage-keys.ts +95 -0
- package/src/runtime/storage-target.ts +238 -0
- package/src/runtime/system-role.ts +26 -0
- package/src/runtime/tasks/boot.ts +49 -0
- package/src/runtime/tasks/contracts.ts +77 -0
- package/src/runtime/tasks/db-store.ts +191 -0
- package/src/runtime/tasks/row-mapping.ts +75 -0
- package/src/runtime/tasks/runtime.ts +192 -0
- package/src/runtime/tasks/tasks-test-harness.ts +92 -0
- package/src/runtime/tenant.ts +15 -0
- package/src/runtime/workflows/boot.ts +97 -0
- package/src/runtime/workflows/contracts.ts +114 -0
- package/src/runtime/workflows/db-store.ts +156 -0
- package/src/runtime/workflows/definitions.ts +75 -0
- package/src/runtime/workflows/dispatch.ts +148 -0
- package/src/runtime/workflows/row-mapping.ts +54 -0
- package/src/runtime/workflows/runner.ts +105 -0
- package/src/runtime/workflows/runtime.ts +161 -0
- package/src/runtime/workflows/steps.ts +74 -0
- package/src/runtime/workflows/support.ts +60 -0
- package/src/runtime/workflows/transitions.ts +259 -0
- package/src/runtime/workflows/workflows-test-harness.ts +238 -0
- package/src/session-cookie.ts +69 -0
- package/src/storage.ts +173 -0
- package/src/types.ts +51 -0
- package/src/virtual-ids.ts +18 -0
- package/src/virtual-modules.d.ts +53 -0
- package/src/vite.ts +175 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Row <-> store-contract mapping for manual tasks (D-135).
|
|
2
|
+
//
|
|
3
|
+
// Kept apart from db-store.ts so each file stays well under the 300-line limit and the text
|
|
4
|
+
// status/decision columns are decoded in exactly one place.
|
|
5
|
+
import { TASK_DECISIONS, TASK_KINDS, TASK_STATUSES } from "@facilis.dev/core";
|
|
6
|
+
import type { JobJson, TaskDecision, TaskKind, TaskRecord, TaskStatus } from "@facilis.dev/core";
|
|
7
|
+
import type { FacilisTaskRow } from "@facilis.dev/db";
|
|
8
|
+
|
|
9
|
+
import type { StoredTask } from "./contracts.ts";
|
|
10
|
+
|
|
11
|
+
/** Maps a row to the store contract; JSONB columns are TaskJson by construction. */
|
|
12
|
+
export function toStoredTask(row: FacilisTaskRow): StoredTask {
|
|
13
|
+
return {
|
|
14
|
+
id: row.id,
|
|
15
|
+
workflowId: row.workflowId,
|
|
16
|
+
stepIndex: row.stepIndex,
|
|
17
|
+
kind: toTaskKind(row.kind),
|
|
18
|
+
status: toTaskStatus(row.status),
|
|
19
|
+
decision: row.decision === null ? null : toTaskDecision(row.decision),
|
|
20
|
+
titleKey: row.titleKey,
|
|
21
|
+
titleParams: row.titleParams as JobJson,
|
|
22
|
+
payload: (row.payload ?? null) as JobJson | null,
|
|
23
|
+
requestedBy: row.requestedBy,
|
|
24
|
+
assignedPermission: row.assignedPermission,
|
|
25
|
+
expiresAt: row.expiresAt,
|
|
26
|
+
decidedBy: row.decidedBy,
|
|
27
|
+
decidedAt: row.decidedAt,
|
|
28
|
+
comment: row.comment,
|
|
29
|
+
createdAt: row.createdAt,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The API record: JSON-friendly timestamps, JSON data. */
|
|
34
|
+
export function toTaskRecord(task: StoredTask): TaskRecord {
|
|
35
|
+
return {
|
|
36
|
+
id: task.id,
|
|
37
|
+
workflowId: task.workflowId,
|
|
38
|
+
stepIndex: task.stepIndex,
|
|
39
|
+
kind: task.kind,
|
|
40
|
+
status: task.status,
|
|
41
|
+
decision: task.decision,
|
|
42
|
+
titleKey: task.titleKey,
|
|
43
|
+
titleParams: task.titleParams,
|
|
44
|
+
payload: task.payload,
|
|
45
|
+
requestedBy: task.requestedBy,
|
|
46
|
+
assignedPermission: task.assignedPermission,
|
|
47
|
+
expiresAt: task.expiresAt === null ? null : task.expiresAt.toISOString(),
|
|
48
|
+
decidedBy: task.decidedBy,
|
|
49
|
+
decidedAt: task.decidedAt === null ? null : task.decidedAt.toISOString(),
|
|
50
|
+
comment: task.comment,
|
|
51
|
+
createdAt: task.createdAt.toISOString(),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Narrows the text status column; an unknown value is corrupt row data, not a task. */
|
|
56
|
+
export function toTaskStatus(value: string): TaskStatus {
|
|
57
|
+
for (const status of TASK_STATUSES) {
|
|
58
|
+
if (status === value) return status;
|
|
59
|
+
}
|
|
60
|
+
throw new Error('facilis_tasks: unknown status "' + value + '"');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function toTaskKind(value: string): TaskKind {
|
|
64
|
+
for (const kind of TASK_KINDS) {
|
|
65
|
+
if (kind === value) return kind;
|
|
66
|
+
}
|
|
67
|
+
throw new Error('facilis_tasks: unknown kind "' + value + '"');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function toTaskDecision(value: string): TaskDecision {
|
|
71
|
+
for (const decision of TASK_DECISIONS) {
|
|
72
|
+
if (decision === value) return decision;
|
|
73
|
+
}
|
|
74
|
+
throw new Error('facilis_tasks: unknown decision "' + value + '"');
|
|
75
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// The server-only task API (D-135, docs/WORKFLOWS.md §7).
|
|
2
|
+
//
|
|
3
|
+
// Validation, JSON serialization and error classification live here; the store only knows
|
|
4
|
+
// rows. A decision is a compare-and-set on the task row: who decided, when and with what
|
|
5
|
+
// comment are recorded in one atomic write, and the decider's identity comes from the
|
|
6
|
+
// request context bound by the route wrapper, never from the request body.
|
|
7
|
+
import { randomUUID } from "node:crypto";
|
|
8
|
+
|
|
9
|
+
import { TaskError, serializeTaskData } from "@facilis.dev/core";
|
|
10
|
+
import type {
|
|
11
|
+
RequestTaskInput,
|
|
12
|
+
TaskActorContext,
|
|
13
|
+
TaskDecisionInput,
|
|
14
|
+
TaskJson,
|
|
15
|
+
TaskListOptions,
|
|
16
|
+
TaskRecord,
|
|
17
|
+
TasksApi,
|
|
18
|
+
} from "@facilis.dev/core";
|
|
19
|
+
import type { PolicyScopedDatabase } from "@facilis.dev/db";
|
|
20
|
+
|
|
21
|
+
import type { NewStoredTask, TaskListFilters, TaskStore } from "./contracts.ts";
|
|
22
|
+
import { toTaskRecord } from "./row-mapping.ts";
|
|
23
|
+
|
|
24
|
+
const DEFAULT_LIMIT = 50;
|
|
25
|
+
const MAX_LIMIT = 200;
|
|
26
|
+
const MAX_TITLE_KEY_LENGTH = 200;
|
|
27
|
+
const MAX_COMMENT_LENGTH = 1000;
|
|
28
|
+
const TITLE_KEY_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
29
|
+
const PERMISSION_PATTERN = /^[A-Za-z0-9][A-Za-z0-9:_-]*$/;
|
|
30
|
+
const MAX_PERMISSION_LENGTH = 100;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Adapts a TaskStore to the handler-facing API. The actor is the session user id (or null
|
|
34
|
+
* for a system-created task); bindScope re-binds both the transaction and the actor.
|
|
35
|
+
*/
|
|
36
|
+
export function createTasksApi(
|
|
37
|
+
store: TaskStore,
|
|
38
|
+
context: TaskActorContext = { actor: null },
|
|
39
|
+
): TasksApi {
|
|
40
|
+
const api: TasksApi = {
|
|
41
|
+
async request(input: RequestTaskInput): Promise<TaskRecord> {
|
|
42
|
+
const task = normalizeTask(input, context.actor);
|
|
43
|
+
await store.insert(task);
|
|
44
|
+
const stored = await store.get(task.id);
|
|
45
|
+
if (stored === null) throw new TaskError("task_not_found", "The task was not persisted.");
|
|
46
|
+
return toTaskRecord(stored);
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
async get(id: string): Promise<TaskRecord | null> {
|
|
50
|
+
const task = await store.get(id);
|
|
51
|
+
return task === null ? null : toTaskRecord(task);
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
async list(options: TaskListOptions = {}): Promise<TaskRecord[]> {
|
|
55
|
+
return (await store.list(normalizeFilters(options))).map(toTaskRecord);
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
async decide(id: string, decision: TaskDecisionInput): Promise<TaskRecord> {
|
|
59
|
+
const kind = decision?.kind;
|
|
60
|
+
if (kind !== "approve" && kind !== "reject") {
|
|
61
|
+
throw invalid('decision.kind must be "approve" or "reject".');
|
|
62
|
+
}
|
|
63
|
+
const comment = normalizeComment(decision.comment);
|
|
64
|
+
const now = new Date();
|
|
65
|
+
const updated = await store.decide(id, {
|
|
66
|
+
decision: kind,
|
|
67
|
+
decidedBy: context.actor,
|
|
68
|
+
comment,
|
|
69
|
+
now,
|
|
70
|
+
});
|
|
71
|
+
if (updated !== null) return toTaskRecord(updated);
|
|
72
|
+
// The CAS matched nothing: classify why, lazily expiring the row when its instant passed.
|
|
73
|
+
const row = await store.get(id);
|
|
74
|
+
if (row === null) throw new TaskError("task_not_found", "Task " + id + " does not exist.");
|
|
75
|
+
if (row.status === "pending") {
|
|
76
|
+
if (row.expiresAt !== null && row.expiresAt.getTime() <= now.getTime()) {
|
|
77
|
+
await store.expire(id, now);
|
|
78
|
+
throw new TaskError("task_expired", "Task " + id + " expired before it was decided.");
|
|
79
|
+
}
|
|
80
|
+
// Another decider won the CAS between the read and the update.
|
|
81
|
+
throw new TaskError("task_already_decided", "Task " + id + " has already been decided.");
|
|
82
|
+
}
|
|
83
|
+
if (row.status === "expired") {
|
|
84
|
+
throw new TaskError("task_expired", "Task " + id + " expired before it was decided.");
|
|
85
|
+
}
|
|
86
|
+
throw new TaskError("task_already_decided", "Task " + id + " is no longer pending.");
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
cancel(id: string): Promise<boolean> {
|
|
90
|
+
return store.cancel(id, new Date());
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Framework plumbing: the handler's calls join its policy transaction and carry its actor.
|
|
95
|
+
api.bindScope = (scope: PolicyScopedDatabase, next: TaskActorContext): TasksApi =>
|
|
96
|
+
createTasksApi(store.scoped?.(scope) ?? store, next);
|
|
97
|
+
return api;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function normalizeTask(input: RequestTaskInput, actor: string | null): NewStoredTask {
|
|
101
|
+
if (typeof input !== "object" || input === null) {
|
|
102
|
+
throw invalid("A task request must be an object.");
|
|
103
|
+
}
|
|
104
|
+
const titleKey = input.titleKey;
|
|
105
|
+
if (
|
|
106
|
+
typeof titleKey !== "string" ||
|
|
107
|
+
titleKey.length === 0 ||
|
|
108
|
+
titleKey.length > MAX_TITLE_KEY_LENGTH ||
|
|
109
|
+
!TITLE_KEY_PATTERN.test(titleKey)
|
|
110
|
+
) {
|
|
111
|
+
throw invalid("titleKey must be a flat i18n key (letters, digits, dot, dash, underscore).");
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
id: randomUUID(),
|
|
115
|
+
workflowId: null,
|
|
116
|
+
stepIndex: null,
|
|
117
|
+
kind: "approval",
|
|
118
|
+
titleKey,
|
|
119
|
+
titleParams: normalizeTitleParams(input.titleParams),
|
|
120
|
+
payload: input.payload === undefined ? null : serializeTaskData(input.payload),
|
|
121
|
+
requestedBy: actor,
|
|
122
|
+
assignedPermission: normalizePermission(input.assignedPermission),
|
|
123
|
+
expiresAt: normalizeExpiresAt(input.expiresAt),
|
|
124
|
+
createdAt: new Date(),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function normalizeTitleParams(value: RequestTaskInput["titleParams"]): TaskJson {
|
|
129
|
+
if (value === undefined) return {};
|
|
130
|
+
const parsed = serializeTaskData(value);
|
|
131
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
132
|
+
throw invalid("titleParams must be a JSON object.");
|
|
133
|
+
}
|
|
134
|
+
return parsed;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function normalizePermission(value: string | undefined): string | null {
|
|
138
|
+
if (value === undefined) return null;
|
|
139
|
+
if (
|
|
140
|
+
typeof value !== "string" ||
|
|
141
|
+
value.length === 0 ||
|
|
142
|
+
value.length > MAX_PERMISSION_LENGTH ||
|
|
143
|
+
!PERMISSION_PATTERN.test(value)
|
|
144
|
+
) {
|
|
145
|
+
throw invalid(
|
|
146
|
+
"assignedPermission must be a permission name (letters, digits, colon, dash, underscore).",
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
return value;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function normalizeExpiresAt(value: string | Date | undefined): Date | null {
|
|
153
|
+
if (value === undefined) return null;
|
|
154
|
+
const instant = value instanceof Date ? value : new Date(value);
|
|
155
|
+
if (Number.isNaN(instant.getTime())) {
|
|
156
|
+
throw invalid("expiresAt is not a valid ISO-8601 instant.");
|
|
157
|
+
}
|
|
158
|
+
return instant;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function normalizeComment(value: string | undefined): string | null {
|
|
162
|
+
if (value === undefined) return null;
|
|
163
|
+
if (typeof value !== "string" || value.length > MAX_COMMENT_LENGTH) {
|
|
164
|
+
throw invalid("comment must be a string of at most 1000 characters.");
|
|
165
|
+
}
|
|
166
|
+
const trimmed = value.trim();
|
|
167
|
+
return trimmed.length === 0 ? null : trimmed;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function normalizeFilters(options: TaskListOptions): TaskListFilters {
|
|
171
|
+
const status = options.status;
|
|
172
|
+
const workflowId = options.workflowId;
|
|
173
|
+
const assignedPermission = options.assignedPermission;
|
|
174
|
+
return {
|
|
175
|
+
...(status === undefined ? {} : { status }),
|
|
176
|
+
...(workflowId === undefined ? {} : { workflowId }),
|
|
177
|
+
...(assignedPermission === undefined ? {} : { assignedPermission }),
|
|
178
|
+
limit: normalizeLimit(options.limit),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function normalizeLimit(value: number | undefined): number {
|
|
183
|
+
if (value === undefined) return DEFAULT_LIMIT;
|
|
184
|
+
if (!Number.isInteger(value) || value < 1) {
|
|
185
|
+
throw invalid("limit must be a positive integer.");
|
|
186
|
+
}
|
|
187
|
+
return Math.min(value, MAX_LIMIT);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function invalid(message: string): TaskError {
|
|
191
|
+
return new TaskError("task_invalid_input", message);
|
|
192
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Shared PGlite fixture for the manual-task store suite (D-135). It creates the real
|
|
2
|
+
// drizzle table definition, its policies and the tenant-column default, so the store is
|
|
3
|
+
// exercised through the same RLS boundary the runtime uses in dev.
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
|
|
6
|
+
import { sql } from "drizzle-orm";
|
|
7
|
+
import { getTableConfig, PgDialect } from "drizzle-orm/pg-core";
|
|
8
|
+
|
|
9
|
+
import type { FacilisDb } from "@facilis.dev/db";
|
|
10
|
+
import {
|
|
11
|
+
createDb,
|
|
12
|
+
ensureAppRole,
|
|
13
|
+
facilisTasks,
|
|
14
|
+
policyCreateSql,
|
|
15
|
+
tenantDefaultSql,
|
|
16
|
+
} from "@facilis.dev/db";
|
|
17
|
+
|
|
18
|
+
import type { NewStoredTask } from "./contracts.ts";
|
|
19
|
+
import { createDbTaskStore } from "./db-store.ts";
|
|
20
|
+
|
|
21
|
+
/** Deployment tenant; a second tenant proves the RLS boundary cannot be crossed. */
|
|
22
|
+
export const TENANT_ID = "eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee";
|
|
23
|
+
export const OTHER_TENANT = "ffffffff-ffff-ffff-ffff-ffffffffffff";
|
|
24
|
+
export const BASE = new Date("2026-11-10T12:00:00.000Z");
|
|
25
|
+
export const LATER = new Date("2026-11-10T12:30:00.000Z");
|
|
26
|
+
|
|
27
|
+
export interface TasksTestContext {
|
|
28
|
+
readonly db: FacilisDb;
|
|
29
|
+
readonly store: ReturnType<typeof createDbTaskStore>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function createTasksTestContext(): Promise<TasksTestContext> {
|
|
33
|
+
const db = await createDb();
|
|
34
|
+
const tenantDefault = new PgDialect().sqlToQuery(tenantDefaultSql()).sql;
|
|
35
|
+
const statements = [
|
|
36
|
+
`CREATE TABLE facilis_tasks (
|
|
37
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
38
|
+
workflow_id uuid,
|
|
39
|
+
step_index integer,
|
|
40
|
+
kind text NOT NULL,
|
|
41
|
+
status text NOT NULL,
|
|
42
|
+
decision text,
|
|
43
|
+
title_key text NOT NULL,
|
|
44
|
+
title_params jsonb NOT NULL DEFAULT '{}'::jsonb,
|
|
45
|
+
payload jsonb,
|
|
46
|
+
requested_by text,
|
|
47
|
+
assigned_permission text,
|
|
48
|
+
expires_at timestamptz,
|
|
49
|
+
decided_by text,
|
|
50
|
+
decided_at timestamptz,
|
|
51
|
+
comment text,
|
|
52
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
53
|
+
tenant_id uuid NOT NULL DEFAULT ` +
|
|
54
|
+
tenantDefault +
|
|
55
|
+
`
|
|
56
|
+
)`,
|
|
57
|
+
"ALTER TABLE facilis_tasks ENABLE ROW LEVEL SECURITY",
|
|
58
|
+
...getTableConfig(facilisTasks).policies.map((policy) =>
|
|
59
|
+
policyCreateSql("facilis_tasks", policy),
|
|
60
|
+
),
|
|
61
|
+
];
|
|
62
|
+
await db.db.transaction(async (tx) => {
|
|
63
|
+
for (const statement of statements) await tx.execute(sql.raw(statement));
|
|
64
|
+
});
|
|
65
|
+
await ensureAppRole(db);
|
|
66
|
+
return { db, store: createDbTaskStore({ db, tenantId: TENANT_ID }) };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Empties the table as the connecting superuser, so each test starts from a clean slate. */
|
|
70
|
+
export async function clearTasks(db: FacilisDb): Promise<void> {
|
|
71
|
+
await db.db.execute(sql.raw("delete from facilis_tasks"));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let sequence = 0;
|
|
75
|
+
|
|
76
|
+
export function newTask(overrides: Partial<NewStoredTask> = {}): NewStoredTask {
|
|
77
|
+
sequence += 1;
|
|
78
|
+
return {
|
|
79
|
+
id: randomUUID(),
|
|
80
|
+
workflowId: null,
|
|
81
|
+
stepIndex: null,
|
|
82
|
+
kind: "approval",
|
|
83
|
+
titleKey: "todos.approval",
|
|
84
|
+
titleParams: { title: "Buy milk" },
|
|
85
|
+
payload: { todoId: "todo-1" },
|
|
86
|
+
requestedBy: "system:test",
|
|
87
|
+
assignedPermission: null,
|
|
88
|
+
expiresAt: null,
|
|
89
|
+
createdAt: new Date(BASE.getTime() + sequence),
|
|
90
|
+
...overrides,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DEFAULT_TENANT_ID } from "@facilis.dev/core";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Single-tenant fallback tenant id (DECISIONS O-003).
|
|
5
|
+
*
|
|
6
|
+
* The constant lives in @facilis.dev/core so the middleware, the handler scoping and generated
|
|
7
|
+
* apps cannot drift apart (a mismatch makes RLS reject every insert). It is also the value the
|
|
8
|
+
* session middleware requires a session's user row to carry (D-040).
|
|
9
|
+
*/
|
|
10
|
+
export { DEFAULT_TENANT_ID };
|
|
11
|
+
|
|
12
|
+
export function readDefaultTenantId(environment: NodeJS.ProcessEnv = process.env): string {
|
|
13
|
+
const configured = environment["FACILIS_TENANT_ID"]?.trim();
|
|
14
|
+
return configured !== undefined && configured.length > 0 ? configured : DEFAULT_TENANT_ID;
|
|
15
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { FacilisJobsConfig, FacilisWorkflowsConfig, ManifestWarning } from "@facilis.dev/core";
|
|
2
|
+
import type { FacilisDb } from "@facilis.dev/db";
|
|
3
|
+
|
|
4
|
+
import type { JobsRuntime } from "../jobs/runtime.ts";
|
|
5
|
+
import type { TaskStore } from "../tasks/contracts.ts";
|
|
6
|
+
import { createDbTaskStore, isTasksTableAvailable } from "../tasks/db-store.ts";
|
|
7
|
+
import type { WorkflowModule } from "./contracts.ts";
|
|
8
|
+
import { createDbWorkflowStore, isWorkflowsTableAvailable } from "./db-store.ts";
|
|
9
|
+
import { buildWorkflowRegistry } from "./definitions.ts";
|
|
10
|
+
import { createWorkflowRunner, type WorkflowsRuntime } from "./runner.ts";
|
|
11
|
+
|
|
12
|
+
export interface BootWorkflowsOptions {
|
|
13
|
+
readonly db: FacilisDb;
|
|
14
|
+
readonly tenantId: string;
|
|
15
|
+
readonly modules: readonly WorkflowModule[];
|
|
16
|
+
/** The booted job queue; null disables workflows, because a step cannot run without it. */
|
|
17
|
+
readonly jobs: JobsRuntime | null;
|
|
18
|
+
readonly jobsConfig: FacilisJobsConfig;
|
|
19
|
+
readonly workflowsConfig: FacilisWorkflowsConfig;
|
|
20
|
+
/** Session-wide manifest warnings; boot pushes into it instead of throwing. */
|
|
21
|
+
readonly warnings: ManifestWarning[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Boots the workflow runtime (D-135, docs/WORKFLOWS.md §8).
|
|
26
|
+
*
|
|
27
|
+
* Never throws: without both tables (or without the job queue) the API is unavailable with a
|
|
28
|
+
* manifest warning, because a suspended chain needs durable rows and jobs (there is
|
|
29
|
+
* deliberately no in-memory mode). The returned runtime is carried by BootstrapState and
|
|
30
|
+
* exposed as ctx.workflows.
|
|
31
|
+
*/
|
|
32
|
+
export async function bootWorkflows(
|
|
33
|
+
options: BootWorkflowsOptions,
|
|
34
|
+
): Promise<WorkflowsRuntime | null> {
|
|
35
|
+
const { db, tenantId, modules, jobs, jobsConfig, workflowsConfig, warnings } = options;
|
|
36
|
+
if (!workflowsConfig.persist) {
|
|
37
|
+
warnings.push({
|
|
38
|
+
code: "workflows_disabled",
|
|
39
|
+
message: "workflows.persist is false; workflows are disabled (rows are the contract).",
|
|
40
|
+
});
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
if (jobs === null) {
|
|
44
|
+
warnings.push({
|
|
45
|
+
code: "workflows_disabled",
|
|
46
|
+
message: "Background jobs are unavailable; workflows are disabled.",
|
|
47
|
+
});
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
if (!(await isWorkflowsTableAvailable(db)) || !(await isTasksTableAvailable(db))) {
|
|
52
|
+
warnings.push({
|
|
53
|
+
code: "workflows_table_missing",
|
|
54
|
+
message:
|
|
55
|
+
"facilis_workflows or facilis_tasks is missing; workflows are disabled. Re-export the tables from db/schema.ts and apply the framework migration.",
|
|
56
|
+
});
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const registry = buildWorkflowRegistry(modules, jobs.definitions);
|
|
60
|
+
warnings.push(...registry.warnings);
|
|
61
|
+
|
|
62
|
+
// One warning per failing context is enough: a broken store would otherwise flood the
|
|
63
|
+
// manifest on every tick.
|
|
64
|
+
const reportedErrors = new Set<string>();
|
|
65
|
+
const taskStore: TaskStore = createDbTaskStore({ db, tenantId });
|
|
66
|
+
const runner = createWorkflowRunner({
|
|
67
|
+
db,
|
|
68
|
+
tenantId,
|
|
69
|
+
definitions: registry.definitions,
|
|
70
|
+
store: createDbWorkflowStore({ db, tenantId }),
|
|
71
|
+
tasks: taskStore,
|
|
72
|
+
jobs: jobs.engine,
|
|
73
|
+
config: workflowsConfig,
|
|
74
|
+
maxStepAttempts: jobsConfig.maxAttempts,
|
|
75
|
+
onError: (error, context) => {
|
|
76
|
+
if (reportedErrors.has(context)) return;
|
|
77
|
+
reportedErrors.add(context);
|
|
78
|
+
warnings.push({
|
|
79
|
+
code: "workflow_runtime_error",
|
|
80
|
+
message: "Workflow runner error (" + context + "): " + describe(error),
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
await runner.start();
|
|
85
|
+
return runner;
|
|
86
|
+
} catch (error) {
|
|
87
|
+
warnings.push({
|
|
88
|
+
code: "workflows_boot_failed",
|
|
89
|
+
message: "Workflows are disabled: " + describe(error),
|
|
90
|
+
});
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function describe(error: unknown): string {
|
|
96
|
+
return error instanceof Error ? error.message : String(error);
|
|
97
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Internal contracts of the workflow runtime (D-135, docs/WORKFLOWS.md §5-§8). The public
|
|
2
|
+
// API lives in @facilis.dev/core; this module only knows rows, statuses and the store seams.
|
|
3
|
+
import type { FacilisDb, PolicyScopedDatabase } from "@facilis.dev/db";
|
|
4
|
+
import type {
|
|
5
|
+
FacilisWorkflowsConfig,
|
|
6
|
+
JobJson,
|
|
7
|
+
WorkflowDefinition,
|
|
8
|
+
WorkflowProgressEntry,
|
|
9
|
+
WorkflowStatus,
|
|
10
|
+
WorkflowStepIdentity,
|
|
11
|
+
} from "@facilis.dev/core";
|
|
12
|
+
|
|
13
|
+
import type { JobEngine, JobTimers } from "../jobs/contracts.ts";
|
|
14
|
+
import type { TaskStore } from "../tasks/contracts.ts";
|
|
15
|
+
|
|
16
|
+
/** One workflow row as the store knows it: JSON data plus real Dates (the API ISO-izes them). */
|
|
17
|
+
export interface StoredWorkflow {
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly status: WorkflowStatus;
|
|
21
|
+
readonly input: JobJson;
|
|
22
|
+
readonly progress: readonly WorkflowProgressEntry[];
|
|
23
|
+
readonly plan: readonly WorkflowStepIdentity[];
|
|
24
|
+
readonly currentStep: number;
|
|
25
|
+
readonly currentJobId: string | null;
|
|
26
|
+
readonly waitingTaskId: string | null;
|
|
27
|
+
readonly attempts: number;
|
|
28
|
+
readonly output: JobJson | null;
|
|
29
|
+
readonly error: string | null;
|
|
30
|
+
readonly startedAt: Date;
|
|
31
|
+
readonly finishedAt: Date | null;
|
|
32
|
+
readonly createdAt: Date;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** What `start` writes; status/attempts belong to the runtime, not the caller. */
|
|
36
|
+
export interface NewStoredWorkflow {
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly name: string;
|
|
39
|
+
readonly input: JobJson;
|
|
40
|
+
readonly plan: readonly WorkflowStepIdentity[];
|
|
41
|
+
readonly startedAt: Date;
|
|
42
|
+
readonly createdAt: Date;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface WorkflowListFilters {
|
|
46
|
+
readonly status?: WorkflowStatus | readonly WorkflowStatus[];
|
|
47
|
+
readonly name?: string;
|
|
48
|
+
/** Already normalised by the API (default 50, max 200). */
|
|
49
|
+
readonly limit: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Expected current values for one compare-and-set write. Every present field is an AND
|
|
54
|
+
* condition on the UPDATE, so a transition that lost a race changes nothing.
|
|
55
|
+
*/
|
|
56
|
+
export interface WorkflowGuard {
|
|
57
|
+
readonly status: WorkflowStatus;
|
|
58
|
+
readonly currentStep?: number;
|
|
59
|
+
readonly currentJobId?: string | null;
|
|
60
|
+
readonly waitingTaskId?: string | null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The fields a transition may change; absent fields keep their row value. */
|
|
64
|
+
export interface WorkflowPatch {
|
|
65
|
+
readonly status?: WorkflowStatus;
|
|
66
|
+
readonly progress?: readonly WorkflowProgressEntry[];
|
|
67
|
+
readonly currentStep?: number;
|
|
68
|
+
readonly currentJobId?: string | null;
|
|
69
|
+
readonly waitingTaskId?: string | null;
|
|
70
|
+
readonly attempts?: number;
|
|
71
|
+
readonly output?: JobJson | null;
|
|
72
|
+
readonly error?: string | null;
|
|
73
|
+
readonly finishedAt?: Date | null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface WorkflowStore {
|
|
77
|
+
insert(workflow: NewStoredWorkflow): Promise<void>;
|
|
78
|
+
get(id: string): Promise<StoredWorkflow | null>;
|
|
79
|
+
list(filters: WorkflowListFilters): Promise<StoredWorkflow[]>;
|
|
80
|
+
/** CAS update; null when the current row no longer matches the guard. */
|
|
81
|
+
update(id: string, guard: WorkflowGuard, patch: WorkflowPatch): Promise<StoredWorkflow | null>;
|
|
82
|
+
/**
|
|
83
|
+
* Optional view whose operations join the request's policy transaction instead of opening
|
|
84
|
+
* a new one: PGlite is single-connection, so a nested BEGIN would deadlock (JOBS §8).
|
|
85
|
+
*/
|
|
86
|
+
scoped?(scope: PolicyScopedDatabase): WorkflowStore;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** One scanned definition module: virtual module entry, useful for warning messages. */
|
|
90
|
+
export interface WorkflowModule {
|
|
91
|
+
readonly file: string;
|
|
92
|
+
readonly definition: unknown;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Everything the API and the runner share; the runner is the only writer of transitions. */
|
|
96
|
+
export interface WorkflowRuntimeDeps {
|
|
97
|
+
readonly db: FacilisDb;
|
|
98
|
+
readonly tenantId: string;
|
|
99
|
+
readonly definitions: ReadonlyMap<string, WorkflowDefinition<unknown, unknown>>;
|
|
100
|
+
/** Base store; a bound API view swaps in `store.scoped(scope)`. */
|
|
101
|
+
readonly store: WorkflowStore;
|
|
102
|
+
readonly tasks: TaskStore;
|
|
103
|
+
/** The job engine: step dispatch enqueues through it, possibly inside the runner's transaction. */
|
|
104
|
+
readonly jobs: JobEngine;
|
|
105
|
+
readonly config: FacilisWorkflowsConfig;
|
|
106
|
+
/** Step dispatches of one step allowed before the chain fails (`jobs.maxAttempts`). */
|
|
107
|
+
readonly maxStepAttempts: number;
|
|
108
|
+
/** Defaults to the process clock. */
|
|
109
|
+
readonly now?: () => Date;
|
|
110
|
+
/** Defaults to the process timers; tests inject a deterministic ticker. */
|
|
111
|
+
readonly timers?: JobTimers;
|
|
112
|
+
/** Receives unexpected runner failures (a store write failing in the tick). */
|
|
113
|
+
readonly onError?: (error: unknown, context: string) => void;
|
|
114
|
+
}
|