@facilis.dev/nitro 0.0.0-stage → 0.1.2
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,183 @@
|
|
|
1
|
+
const INTERRUPTED_ERROR = "interrupted (recovered after restart)";
|
|
2
|
+
/** Reads hand out fresh snapshots: callers must never observe a later mutation. */
|
|
3
|
+
function cloneJob(job) {
|
|
4
|
+
return {
|
|
5
|
+
...job,
|
|
6
|
+
runAt: new Date(job.runAt),
|
|
7
|
+
createdAt: new Date(job.createdAt),
|
|
8
|
+
startedAt: job.startedAt === null ? null : new Date(job.startedAt),
|
|
9
|
+
finishedAt: job.finishedAt === null ? null : new Date(job.finishedAt),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function matchesStatus(status, filter) {
|
|
13
|
+
if (filter === undefined)
|
|
14
|
+
return true;
|
|
15
|
+
return typeof filter === "string" ? status === filter : filter.includes(status);
|
|
16
|
+
}
|
|
17
|
+
/** Nothing to release: the map is garbage-collected with the store. */
|
|
18
|
+
async function closeStore() { }
|
|
19
|
+
/**
|
|
20
|
+
* The in-memory queue: used when `jobs.persist` is false, or when the project has not
|
|
21
|
+
* migrated `facilis_jobs` yet. Work is lost across a reload, which is why persistence is
|
|
22
|
+
* the default (docs/JOBS.md §8).
|
|
23
|
+
*/
|
|
24
|
+
export function createMemoryJobStore() {
|
|
25
|
+
const rows = new Map();
|
|
26
|
+
let sequence = 0;
|
|
27
|
+
function replace(id, job) {
|
|
28
|
+
const row = rows.get(id);
|
|
29
|
+
if (row !== undefined)
|
|
30
|
+
rows.set(id, { seq: row.seq, job });
|
|
31
|
+
}
|
|
32
|
+
function byRunAt(a, b) {
|
|
33
|
+
return a.job.runAt.getTime() - b.job.runAt.getTime() || a.seq - b.seq;
|
|
34
|
+
}
|
|
35
|
+
async function insert(job) {
|
|
36
|
+
rows.set(job.id, {
|
|
37
|
+
seq: sequence++,
|
|
38
|
+
job: {
|
|
39
|
+
id: job.id,
|
|
40
|
+
name: job.name,
|
|
41
|
+
status: "queued",
|
|
42
|
+
input: job.input,
|
|
43
|
+
output: null,
|
|
44
|
+
error: null,
|
|
45
|
+
attempts: 0,
|
|
46
|
+
maxAttempts: job.maxAttempts,
|
|
47
|
+
timeoutMs: job.timeoutMs,
|
|
48
|
+
runAt: new Date(job.runAt),
|
|
49
|
+
createdAt: new Date(job.createdAt),
|
|
50
|
+
startedAt: null,
|
|
51
|
+
finishedAt: null,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async function get(id) {
|
|
56
|
+
const row = rows.get(id);
|
|
57
|
+
return row === undefined ? null : cloneJob(row.job);
|
|
58
|
+
}
|
|
59
|
+
async function list(options) {
|
|
60
|
+
const matching = [...rows.values()].filter(({ job }) => matchesStatus(job.status, options.status) &&
|
|
61
|
+
(options.name === undefined || job.name === options.name));
|
|
62
|
+
// Newest-created first; a later insertion wins an identical timestamp.
|
|
63
|
+
matching.sort((a, b) => b.job.createdAt.getTime() - a.job.createdAt.getTime() || b.seq - a.seq);
|
|
64
|
+
return matching.slice(0, Math.max(0, options.limit)).map(({ job }) => cloneJob(job));
|
|
65
|
+
}
|
|
66
|
+
async function queue(limit) {
|
|
67
|
+
const queued = [...rows.values()].filter(({ job }) => job.status === "queued");
|
|
68
|
+
queued.sort(byRunAt);
|
|
69
|
+
const page = limit === undefined ? queued : queued.slice(0, Math.max(0, limit));
|
|
70
|
+
return page.map(({ job }) => cloneJob(job));
|
|
71
|
+
}
|
|
72
|
+
async function running() {
|
|
73
|
+
const active = [...rows.values()].filter(({ job }) => job.status === "running");
|
|
74
|
+
active.sort((a, b) => (a.job.startedAt?.getTime() ?? 0) - (b.job.startedAt?.getTime() ?? 0) || a.seq - b.seq);
|
|
75
|
+
return active.map(({ job }) => cloneJob(job));
|
|
76
|
+
}
|
|
77
|
+
async function claim(now, limit) {
|
|
78
|
+
const due = [...rows.values()].filter(({ job }) => job.status === "queued" && job.runAt.getTime() <= now.getTime());
|
|
79
|
+
due.sort(byRunAt);
|
|
80
|
+
const claimed = [];
|
|
81
|
+
for (const { seq, job } of due.slice(0, Math.max(0, limit))) {
|
|
82
|
+
const next = {
|
|
83
|
+
...job,
|
|
84
|
+
status: "running",
|
|
85
|
+
attempts: job.attempts + 1,
|
|
86
|
+
startedAt: new Date(now),
|
|
87
|
+
};
|
|
88
|
+
rows.set(job.id, { seq, job: next });
|
|
89
|
+
claimed.push(cloneJob(next));
|
|
90
|
+
}
|
|
91
|
+
return claimed;
|
|
92
|
+
}
|
|
93
|
+
async function complete(id, outcome) {
|
|
94
|
+
const row = rows.get(id);
|
|
95
|
+
if (row === undefined)
|
|
96
|
+
return;
|
|
97
|
+
replace(id, {
|
|
98
|
+
...row.job,
|
|
99
|
+
status: outcome.status,
|
|
100
|
+
output: outcome.status === "succeeded" ? outcome.output : null,
|
|
101
|
+
error: outcome.status === "succeeded" ? null : outcome.error,
|
|
102
|
+
finishedAt: new Date(outcome.finishedAt),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
async function requeue(id, options) {
|
|
106
|
+
const row = rows.get(id);
|
|
107
|
+
if (row === undefined)
|
|
108
|
+
return;
|
|
109
|
+
replace(id, {
|
|
110
|
+
...row.job,
|
|
111
|
+
status: "queued",
|
|
112
|
+
output: null,
|
|
113
|
+
error: options.error,
|
|
114
|
+
runAt: new Date(options.runAt),
|
|
115
|
+
startedAt: null,
|
|
116
|
+
finishedAt: null,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async function cancelQueued(id, finishedAt) {
|
|
120
|
+
const row = rows.get(id);
|
|
121
|
+
if (row === undefined || row.job.status !== "queued")
|
|
122
|
+
return false;
|
|
123
|
+
replace(id, {
|
|
124
|
+
...row.job,
|
|
125
|
+
status: "cancelled",
|
|
126
|
+
error: null,
|
|
127
|
+
finishedAt: new Date(finishedAt),
|
|
128
|
+
});
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
async function recoverInterrupted(now) {
|
|
132
|
+
let recovered = 0;
|
|
133
|
+
for (const { job } of rows.values()) {
|
|
134
|
+
if (job.status !== "running")
|
|
135
|
+
continue;
|
|
136
|
+
recovered += 1;
|
|
137
|
+
if (job.attempts >= job.maxAttempts) {
|
|
138
|
+
replace(job.id, {
|
|
139
|
+
...job,
|
|
140
|
+
status: "failed",
|
|
141
|
+
error: INTERRUPTED_ERROR,
|
|
142
|
+
finishedAt: new Date(now),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
replace(job.id, {
|
|
147
|
+
...job,
|
|
148
|
+
status: "queued",
|
|
149
|
+
error: INTERRUPTED_ERROR,
|
|
150
|
+
runAt: new Date(now),
|
|
151
|
+
startedAt: null,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return recovered;
|
|
156
|
+
}
|
|
157
|
+
async function counts() {
|
|
158
|
+
const tally = {
|
|
159
|
+
queued: 0,
|
|
160
|
+
running: 0,
|
|
161
|
+
succeeded: 0,
|
|
162
|
+
failed: 0,
|
|
163
|
+
cancelled: 0,
|
|
164
|
+
};
|
|
165
|
+
for (const { job } of rows.values())
|
|
166
|
+
tally[job.status] += 1;
|
|
167
|
+
return { ...tally };
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
insert,
|
|
171
|
+
get,
|
|
172
|
+
list,
|
|
173
|
+
queue,
|
|
174
|
+
running,
|
|
175
|
+
claim,
|
|
176
|
+
complete,
|
|
177
|
+
requeue,
|
|
178
|
+
cancelQueued,
|
|
179
|
+
recoverInterrupted,
|
|
180
|
+
counts,
|
|
181
|
+
close: closeStore,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { JobJson, JobStatus } from "@facilis.dev/core";
|
|
2
|
+
import type { FacilisJobRow } from "@facilis.dev/db";
|
|
3
|
+
import type { JobOutcome, StoredJob } from "./contracts.js";
|
|
4
|
+
/**
|
|
5
|
+
* Maps a row to the store contract. The JSONB columns read as `unknown` because Drizzle
|
|
6
|
+
* cannot know the app's JSON shape; the engine serialized them through a JSON round-trip,
|
|
7
|
+
* so they are JobJson by construction (JOBS.md §5).
|
|
8
|
+
*/
|
|
9
|
+
export declare function toStoredJob(row: FacilisJobRow): StoredJob;
|
|
10
|
+
/** Column set for `complete`: a terminal status plus the fields that status owns. */
|
|
11
|
+
export declare function completionValues(outcome: JobOutcome): {
|
|
12
|
+
status: "succeeded";
|
|
13
|
+
output: JobJson;
|
|
14
|
+
error: null;
|
|
15
|
+
finishedAt: Date;
|
|
16
|
+
} | {
|
|
17
|
+
status: "failed";
|
|
18
|
+
output: null;
|
|
19
|
+
error: string;
|
|
20
|
+
finishedAt: Date;
|
|
21
|
+
} | {
|
|
22
|
+
status: "cancelled";
|
|
23
|
+
output: null;
|
|
24
|
+
error: string | null;
|
|
25
|
+
finishedAt: Date;
|
|
26
|
+
};
|
|
27
|
+
/** Narrows the text status column; an unknown value is corrupt queue data, not a job. */
|
|
28
|
+
export declare function toJobStatus(value: string): JobStatus;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Row <-> store-contract mapping for the persistent job queue (D-107).
|
|
2
|
+
//
|
|
3
|
+
// Kept apart from db-store.ts so each file stays well under the 300-line limit and the
|
|
4
|
+
// mapping is the single place that knows the text status column and the JSONB columns.
|
|
5
|
+
import { JOB_STATUSES } from "@facilis.dev/core";
|
|
6
|
+
/**
|
|
7
|
+
* Maps a row to the store contract. The JSONB columns read as `unknown` because Drizzle
|
|
8
|
+
* cannot know the app's JSON shape; the engine serialized them through a JSON round-trip,
|
|
9
|
+
* so they are JobJson by construction (JOBS.md §5).
|
|
10
|
+
*/
|
|
11
|
+
export function toStoredJob(row) {
|
|
12
|
+
return {
|
|
13
|
+
id: row.id,
|
|
14
|
+
name: row.name,
|
|
15
|
+
status: toJobStatus(row.status),
|
|
16
|
+
input: row.input,
|
|
17
|
+
output: (row.output ?? null),
|
|
18
|
+
error: row.error,
|
|
19
|
+
attempts: row.attempts,
|
|
20
|
+
maxAttempts: row.maxAttempts,
|
|
21
|
+
timeoutMs: row.timeoutMs,
|
|
22
|
+
runAt: row.runAt,
|
|
23
|
+
createdAt: row.createdAt,
|
|
24
|
+
startedAt: row.startedAt,
|
|
25
|
+
finishedAt: row.finishedAt,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** Column set for `complete`: a terminal status plus the fields that status owns. */
|
|
29
|
+
export function completionValues(outcome) {
|
|
30
|
+
switch (outcome.status) {
|
|
31
|
+
case "succeeded":
|
|
32
|
+
return {
|
|
33
|
+
status: "succeeded",
|
|
34
|
+
output: outcome.output,
|
|
35
|
+
error: null,
|
|
36
|
+
finishedAt: outcome.finishedAt,
|
|
37
|
+
};
|
|
38
|
+
case "failed":
|
|
39
|
+
return {
|
|
40
|
+
status: "failed",
|
|
41
|
+
output: null,
|
|
42
|
+
error: outcome.error,
|
|
43
|
+
finishedAt: outcome.finishedAt,
|
|
44
|
+
};
|
|
45
|
+
case "cancelled":
|
|
46
|
+
return {
|
|
47
|
+
status: "cancelled",
|
|
48
|
+
output: null,
|
|
49
|
+
error: outcome.error,
|
|
50
|
+
finishedAt: outcome.finishedAt,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Narrows the text status column; an unknown value is corrupt queue data, not a job. */
|
|
55
|
+
export function toJobStatus(value) {
|
|
56
|
+
for (const status of JOB_STATUSES) {
|
|
57
|
+
if (status === value)
|
|
58
|
+
return status;
|
|
59
|
+
}
|
|
60
|
+
throw new Error(`facilis_jobs: unknown status "${value}"`);
|
|
61
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type JobDefinition, type JobRecord, type JobsApi } from "@facilis.dev/core";
|
|
2
|
+
import type { JobEngine, StoredJob } from "./contracts.js";
|
|
3
|
+
/** The booted job runtime carried by `BootstrapState` (D-107). */
|
|
4
|
+
export interface JobsRuntime {
|
|
5
|
+
readonly api: JobsApi;
|
|
6
|
+
/** Internal seam for the workflow runner: dispatch step jobs, read and cancel them. */
|
|
7
|
+
readonly engine: JobEngine;
|
|
8
|
+
/** The project's definitions, so workflows can reject a dangling job step at boot. */
|
|
9
|
+
readonly definitions: ReadonlyMap<string, JobDefinition<unknown, unknown>>;
|
|
10
|
+
start(): Promise<void>;
|
|
11
|
+
stop(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The API returns `JobRecord`s: the store's `Date`s are JSON-unfriendly and the queue is
|
|
15
|
+
* persisted/serialized data, so every instant crosses the boundary as ISO-8601 (docs/JOBS.md §6).
|
|
16
|
+
*/
|
|
17
|
+
export declare function toJobRecord(job: StoredJob): JobRecord;
|
|
18
|
+
/**
|
|
19
|
+
* Adapts the engine to the server-only `ctx.jobs` surface (D-107, docs/JOBS.md §6).
|
|
20
|
+
*
|
|
21
|
+
* The relative `delayMs` form is resolved here, not in the engine: the engine only knows
|
|
22
|
+
* absolute instants, which keeps its scheduling deterministic and its tests clock-free.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createJobsApi(engine: JobEngine, maxConcurrent: number): JobsApi;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { JobError, } from "@facilis.dev/core";
|
|
2
|
+
/**
|
|
3
|
+
* The API returns `JobRecord`s: the store's `Date`s are JSON-unfriendly and the queue is
|
|
4
|
+
* persisted/serialized data, so every instant crosses the boundary as ISO-8601 (docs/JOBS.md §6).
|
|
5
|
+
*/
|
|
6
|
+
export function toJobRecord(job) {
|
|
7
|
+
return {
|
|
8
|
+
id: job.id,
|
|
9
|
+
name: job.name,
|
|
10
|
+
status: job.status,
|
|
11
|
+
input: job.input,
|
|
12
|
+
output: job.output,
|
|
13
|
+
error: job.error,
|
|
14
|
+
attempts: job.attempts,
|
|
15
|
+
maxAttempts: job.maxAttempts,
|
|
16
|
+
timeoutMs: job.timeoutMs,
|
|
17
|
+
runAt: job.runAt.toISOString(),
|
|
18
|
+
createdAt: job.createdAt.toISOString(),
|
|
19
|
+
startedAt: job.startedAt === null ? null : job.startedAt.toISOString(),
|
|
20
|
+
finishedAt: job.finishedAt === null ? null : job.finishedAt.toISOString(),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Adapts the engine to the server-only `ctx.jobs` surface (D-107, docs/JOBS.md §6).
|
|
25
|
+
*
|
|
26
|
+
* The relative `delayMs` form is resolved here, not in the engine: the engine only knows
|
|
27
|
+
* absolute instants, which keeps its scheduling deterministic and its tests clock-free.
|
|
28
|
+
*/
|
|
29
|
+
export function createJobsApi(engine, maxConcurrent) {
|
|
30
|
+
return {
|
|
31
|
+
async enqueue(name, data, options) {
|
|
32
|
+
const runAt = resolveRunAt(options);
|
|
33
|
+
const engineOptions = runAt === undefined ? undefined : { runAt };
|
|
34
|
+
return await engine.enqueue(name, data, engineOptions);
|
|
35
|
+
},
|
|
36
|
+
async get(id) {
|
|
37
|
+
const job = await engine.get(id);
|
|
38
|
+
return job === null ? null : toJobRecord(job);
|
|
39
|
+
},
|
|
40
|
+
async list(options) {
|
|
41
|
+
return (await engine.list(options)).map(toJobRecord);
|
|
42
|
+
},
|
|
43
|
+
async queue() {
|
|
44
|
+
return (await engine.queue()).map(toJobRecord);
|
|
45
|
+
},
|
|
46
|
+
async running() {
|
|
47
|
+
return (await engine.running()).map(toJobRecord);
|
|
48
|
+
},
|
|
49
|
+
cancel(id) {
|
|
50
|
+
return engine.cancel(id);
|
|
51
|
+
},
|
|
52
|
+
async stats() {
|
|
53
|
+
const counts = await engine.stats();
|
|
54
|
+
return { ...counts, maxConcurrent };
|
|
55
|
+
},
|
|
56
|
+
// Framework plumbing (D-107, docs/JOBS.md §8): the route wrapper binds the API to the
|
|
57
|
+
// request's policy transaction so queue calls join it instead of opening a nested one.
|
|
58
|
+
bindScope(scope) {
|
|
59
|
+
const scopedEngine = engine.scoped?.(scope) ?? engine;
|
|
60
|
+
return createJobsApi(scopedEngine, maxConcurrent);
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Validates the author-facing schedule options and resolves them to one instant. */
|
|
65
|
+
function resolveRunAt(options) {
|
|
66
|
+
if (options === undefined)
|
|
67
|
+
return undefined;
|
|
68
|
+
const { runAt, delayMs } = options;
|
|
69
|
+
if (runAt !== undefined && delayMs !== undefined) {
|
|
70
|
+
throw new JobError("job_invalid_schedule", '"runAt" and "delayMs" are mutually exclusive.');
|
|
71
|
+
}
|
|
72
|
+
if (runAt !== undefined) {
|
|
73
|
+
const instant = runAt instanceof Date ? runAt : new Date(runAt);
|
|
74
|
+
if (Number.isNaN(instant.getTime())) {
|
|
75
|
+
throw new JobError("job_invalid_schedule", '"runAt" is not a valid ISO-8601 instant.');
|
|
76
|
+
}
|
|
77
|
+
return instant;
|
|
78
|
+
}
|
|
79
|
+
if (delayMs !== undefined) {
|
|
80
|
+
if (!Number.isFinite(delayMs) || delayMs < 0) {
|
|
81
|
+
throw new JobError("job_invalid_schedule", '"delayMs" must be a finite number >= 0.');
|
|
82
|
+
}
|
|
83
|
+
return new Date(Date.now() + delayMs);
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { AuditLogEntry } from "@facilis.dev/core";
|
|
2
|
+
/**
|
|
3
|
+
* Tamper-evident audit chain (D-119, O-014).
|
|
4
|
+
*
|
|
5
|
+
* File-written audit entries carry a sequence number, the previous entry's hash and their own
|
|
6
|
+
* SHA-256 hash over a canonical JSON rendering. The chain is tamper-EVIDENT, not tamper-proof:
|
|
7
|
+
* it has no secret key, so a writer who can rewrite the file can rebuild the chain. WORM or
|
|
8
|
+
* external retention is the deploy's responsibility (stdout/file shipped to a store it cannot
|
|
9
|
+
* rewrite). The chain restarts at seq 1 in a fresh file so a rotated file is still verifiable
|
|
10
|
+
* on its own, from its first entry's `prevHash` onward.
|
|
11
|
+
*/
|
|
12
|
+
export declare const AUDIT_CHAIN_HASH_ALGORITHM = "sha256";
|
|
13
|
+
/** Where the next chained entry starts: the last entry of the active file. */
|
|
14
|
+
export interface AuditChainHead {
|
|
15
|
+
readonly seq: number;
|
|
16
|
+
readonly hash: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ChainedAuditEntry extends AuditLogEntry {
|
|
19
|
+
/** 1-based position in the stream; continues across rotations and restarts. */
|
|
20
|
+
readonly seq: number;
|
|
21
|
+
/** Hash of the previous entry; absent only on the first entry of a fresh chain. */
|
|
22
|
+
readonly prevHash?: string;
|
|
23
|
+
/** SHA-256 of the canonical entry without this field (it covers `seq` and `prevHash`). */
|
|
24
|
+
readonly hash: string;
|
|
25
|
+
}
|
|
26
|
+
/** Everything the hash covers: the entry plus its chain position, minus the hash itself. */
|
|
27
|
+
export type AuditChainPayload = Omit<ChainedAuditEntry, "hash">;
|
|
28
|
+
export interface AuditChainVerification {
|
|
29
|
+
readonly ok: boolean;
|
|
30
|
+
readonly entries: number;
|
|
31
|
+
/** 0-based index of the first broken entry; absent when `ok`. */
|
|
32
|
+
readonly brokenAt?: number;
|
|
33
|
+
/** Stable reason code for the first break, e.g. `hash-mismatch`. */
|
|
34
|
+
readonly reason?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Stable JSON rendering: object keys sorted, no whitespace, `undefined` fields absent.
|
|
38
|
+
* Two entries with the same field values always hash the same, regardless of key order.
|
|
39
|
+
*/
|
|
40
|
+
export declare function canonicalJson(value: unknown): string;
|
|
41
|
+
/** Canonical hash of an entry position; exported so a readback tool can recompute it. */
|
|
42
|
+
export declare function computeAuditHash(payload: AuditChainPayload): string;
|
|
43
|
+
/** Appends one entry to the chain; `head` is null for the first entry of a fresh file. */
|
|
44
|
+
export declare function chainAuditEntry(entry: AuditLogEntry, head: AuditChainHead | null): ChainedAuditEntry;
|
|
45
|
+
/** Structural check used when reading a file back; malformed hashes fail the check. */
|
|
46
|
+
export declare function isChainedAuditEntry(value: unknown): value is ChainedAuditEntry;
|
|
47
|
+
/**
|
|
48
|
+
* Verifies a readback: every entry's hash and every consecutive link.
|
|
49
|
+
*
|
|
50
|
+
* The first entry may start at any `seq` (a rotated file starts mid-stream); when it starts at
|
|
51
|
+
* seq 1 it must not carry a `prevHash`. Only entries given are verified, so verifying
|
|
52
|
+
* `access.1.jsonl` (rotated) checks the links inside that file, not the link to the active one.
|
|
53
|
+
*/
|
|
54
|
+
export declare function verifyAuditChain(entries: readonly unknown[]): AuditChainVerification;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
/**
|
|
3
|
+
* Tamper-evident audit chain (D-119, O-014).
|
|
4
|
+
*
|
|
5
|
+
* File-written audit entries carry a sequence number, the previous entry's hash and their own
|
|
6
|
+
* SHA-256 hash over a canonical JSON rendering. The chain is tamper-EVIDENT, not tamper-proof:
|
|
7
|
+
* it has no secret key, so a writer who can rewrite the file can rebuild the chain. WORM or
|
|
8
|
+
* external retention is the deploy's responsibility (stdout/file shipped to a store it cannot
|
|
9
|
+
* rewrite). The chain restarts at seq 1 in a fresh file so a rotated file is still verifiable
|
|
10
|
+
* on its own, from its first entry's `prevHash` onward.
|
|
11
|
+
*/
|
|
12
|
+
export const AUDIT_CHAIN_HASH_ALGORITHM = "sha256";
|
|
13
|
+
const HASH_PATTERN = /^[a-f0-9]{64}$/;
|
|
14
|
+
/**
|
|
15
|
+
* Stable JSON rendering: object keys sorted, no whitespace, `undefined` fields absent.
|
|
16
|
+
* Two entries with the same field values always hash the same, regardless of key order.
|
|
17
|
+
*/
|
|
18
|
+
export function canonicalJson(value) {
|
|
19
|
+
if (value === null)
|
|
20
|
+
return "null";
|
|
21
|
+
if (typeof value === "bigint")
|
|
22
|
+
return JSON.stringify(value.toString());
|
|
23
|
+
if (typeof value !== "object")
|
|
24
|
+
return JSON.stringify(value) ?? "null";
|
|
25
|
+
if (Array.isArray(value)) {
|
|
26
|
+
return `[${value.map((item) => canonicalJson(item)).join(",")}]`;
|
|
27
|
+
}
|
|
28
|
+
const object = value;
|
|
29
|
+
const parts = [];
|
|
30
|
+
for (const key of Object.keys(object).sort()) {
|
|
31
|
+
const item = object[key];
|
|
32
|
+
if (item === undefined)
|
|
33
|
+
continue;
|
|
34
|
+
parts.push(`${JSON.stringify(key)}:${canonicalJson(item)}`);
|
|
35
|
+
}
|
|
36
|
+
return `{${parts.join(",")}}`;
|
|
37
|
+
}
|
|
38
|
+
/** Canonical hash of an entry position; exported so a readback tool can recompute it. */
|
|
39
|
+
export function computeAuditHash(payload) {
|
|
40
|
+
return createHash(AUDIT_CHAIN_HASH_ALGORITHM)
|
|
41
|
+
.update(canonicalJson(payload), "utf8")
|
|
42
|
+
.digest("hex");
|
|
43
|
+
}
|
|
44
|
+
/** Appends one entry to the chain; `head` is null for the first entry of a fresh file. */
|
|
45
|
+
export function chainAuditEntry(entry, head) {
|
|
46
|
+
const seq = head === null ? 1 : head.seq + 1;
|
|
47
|
+
const payload = {
|
|
48
|
+
...entry,
|
|
49
|
+
seq,
|
|
50
|
+
...(head === null ? {} : { prevHash: head.hash }),
|
|
51
|
+
};
|
|
52
|
+
return { ...payload, hash: computeAuditHash(payload) };
|
|
53
|
+
}
|
|
54
|
+
/** Structural check used when reading a file back; malformed hashes fail the check. */
|
|
55
|
+
export function isChainedAuditEntry(value) {
|
|
56
|
+
if (value === null || typeof value !== "object")
|
|
57
|
+
return false;
|
|
58
|
+
const candidate = value;
|
|
59
|
+
return (candidate["kind"] === "audit" &&
|
|
60
|
+
Number.isSafeInteger(candidate["seq"]) &&
|
|
61
|
+
typeof candidate["hash"] === "string" &&
|
|
62
|
+
HASH_PATTERN.test(candidate["hash"]) &&
|
|
63
|
+
(candidate["prevHash"] === undefined ||
|
|
64
|
+
(typeof candidate["prevHash"] === "string" && HASH_PATTERN.test(candidate["prevHash"]))));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Verifies a readback: every entry's hash and every consecutive link.
|
|
68
|
+
*
|
|
69
|
+
* The first entry may start at any `seq` (a rotated file starts mid-stream); when it starts at
|
|
70
|
+
* seq 1 it must not carry a `prevHash`. Only entries given are verified, so verifying
|
|
71
|
+
* `access.1.jsonl` (rotated) checks the links inside that file, not the link to the active one.
|
|
72
|
+
*/
|
|
73
|
+
export function verifyAuditChain(entries) {
|
|
74
|
+
let previous = null;
|
|
75
|
+
for (const [index, entry] of entries.entries()) {
|
|
76
|
+
if (!isChainedAuditEntry(entry)) {
|
|
77
|
+
return broken(index, "not-a-chained-audit-entry");
|
|
78
|
+
}
|
|
79
|
+
if (index === 0) {
|
|
80
|
+
if (entry.seq === 1 && entry.prevHash !== undefined) {
|
|
81
|
+
return broken(index, "unexpected-prev-hash");
|
|
82
|
+
}
|
|
83
|
+
if (entry.seq > 1 && entry.prevHash === undefined) {
|
|
84
|
+
return broken(index, "missing-prev-hash");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else if (previous !== null) {
|
|
88
|
+
if (entry.seq !== previous.seq + 1)
|
|
89
|
+
return broken(index, "unexpected-sequence");
|
|
90
|
+
if (entry.prevHash !== previous.hash)
|
|
91
|
+
return broken(index, "prev-hash-mismatch");
|
|
92
|
+
}
|
|
93
|
+
const { hash, ...payload } = entry;
|
|
94
|
+
if (computeAuditHash(payload) !== hash)
|
|
95
|
+
return broken(index, "hash-mismatch");
|
|
96
|
+
previous = entry;
|
|
97
|
+
}
|
|
98
|
+
return { ok: true, entries: entries.length };
|
|
99
|
+
}
|
|
100
|
+
function broken(brokenAt, reason) {
|
|
101
|
+
return { ok: false, entries: brokenAt, brokenAt, reason };
|
|
102
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type FacilisLoggingConfig, type LogLevel, type ManifestWarning } from "@facilis.dev/core";
|
|
2
|
+
import { type LoggingRuntime } from "./runtime.js";
|
|
3
|
+
/**
|
|
4
|
+
* Boot-time logging construction (D-119).
|
|
5
|
+
*
|
|
6
|
+
* Logging is built from the project config plus the environment BEFORE the database is opened:
|
|
7
|
+
* a database boot failure must still leave the process with a working access/error stream, and
|
|
8
|
+
* logging itself must never be the reason a project fails to boot. When `facilis.config.ts`
|
|
9
|
+
* did not load, the documented defaults are used.
|
|
10
|
+
*/
|
|
11
|
+
export interface BootstrapLoggingInput {
|
|
12
|
+
/** The project's `logging` section, or null when the project config failed to load. */
|
|
13
|
+
readonly loggingConfig: FacilisLoggingConfig | null;
|
|
14
|
+
readonly env: NodeJS.ProcessEnv;
|
|
15
|
+
readonly projectRoot: string;
|
|
16
|
+
/** Test seam: override the NODE_ENV-derived production detection. */
|
|
17
|
+
readonly production?: boolean;
|
|
18
|
+
/** Test seam: collect stdout lines instead of writing to the process stream. */
|
|
19
|
+
readonly writeStdout?: (line: string) => void;
|
|
20
|
+
}
|
|
21
|
+
export interface BootstrapLogging {
|
|
22
|
+
readonly logging: LoggingRuntime;
|
|
23
|
+
readonly config: FacilisLoggingConfig;
|
|
24
|
+
readonly warnings: readonly ManifestWarning[];
|
|
25
|
+
}
|
|
26
|
+
export declare function createBootstrapLogging(input: BootstrapLoggingInput): BootstrapLogging;
|
|
27
|
+
/** `logging.level` is the one config value the environment may override. */
|
|
28
|
+
export declare function effectiveLoggingConfig(loggingConfig: FacilisLoggingConfig | null, levelOverride: LogLevel | null): FacilisLoggingConfig;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DEFAULT_LOGGING_CONFIG, } from "@facilis.dev/core";
|
|
2
|
+
import { resolveLogSettings } from "./log-settings.js";
|
|
3
|
+
import { createLoggingRuntime } from "./runtime.js";
|
|
4
|
+
export function createBootstrapLogging(input) {
|
|
5
|
+
const resolved = resolveLogSettings({
|
|
6
|
+
env: input.env,
|
|
7
|
+
projectRoot: input.projectRoot,
|
|
8
|
+
...(input.production === undefined ? {} : { production: input.production }),
|
|
9
|
+
});
|
|
10
|
+
const config = effectiveLoggingConfig(input.loggingConfig, resolved.settings.level);
|
|
11
|
+
const runtime = createLoggingRuntime({
|
|
12
|
+
config,
|
|
13
|
+
settings: resolved.settings,
|
|
14
|
+
...(input.writeStdout === undefined ? {} : { writeStdout: input.writeStdout }),
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
logging: runtime,
|
|
18
|
+
config,
|
|
19
|
+
warnings: [...resolved.warnings, ...runtime.warnings],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** `logging.level` is the one config value the environment may override. */
|
|
23
|
+
export function effectiveLoggingConfig(loggingConfig, levelOverride) {
|
|
24
|
+
const base = loggingConfig ?? DEFAULT_LOGGING_CONFIG;
|
|
25
|
+
return levelOverride === null ? base : { ...base, level: levelOverride };
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { LogEntry } from "@facilis.dev/core";
|
|
2
|
+
/**
|
|
3
|
+
* Entry sanitization at the sink boundary (D-119).
|
|
4
|
+
*
|
|
5
|
+
* Core builds the entry shapes; this pass makes them safe to serialize: every free-text field
|
|
6
|
+
* is capped, and the only arbitrary payloads (`data`/`details`) are redacted. Strings are
|
|
7
|
+
* capped rather than truncated with a marker so a hostile value cannot grow a line.
|
|
8
|
+
*/
|
|
9
|
+
export declare const MAX_LOG_MESSAGE = 1000;
|
|
10
|
+
export declare const MAX_LOG_STACK = 4000;
|
|
11
|
+
export declare const MAX_LOG_FIELD = 1000;
|
|
12
|
+
export declare const MAX_LOG_SHORT = 200;
|
|
13
|
+
export declare const MAX_LOG_ARRAY = 50;
|
|
14
|
+
export declare function sanitizeEntry(entry: LogEntry): LogEntry;
|