@cloudhal/schedules 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +103 -2
  3. package/dist/src/automation.d.ts +82 -0
  4. package/dist/src/automation.js +199 -0
  5. package/dist/src/budget-meter.d.ts +58 -0
  6. package/dist/src/budget-meter.js +130 -0
  7. package/dist/src/budget.d.ts +41 -0
  8. package/dist/src/budget.js +76 -0
  9. package/dist/src/builtins.d.ts +132 -0
  10. package/dist/src/builtins.js +473 -0
  11. package/dist/src/engine.d.ts +16 -0
  12. package/dist/src/engine.js +30 -0
  13. package/dist/src/errors.d.ts +22 -0
  14. package/dist/src/errors.js +56 -0
  15. package/dist/src/feed-check.d.ts +56 -0
  16. package/dist/src/feed-check.js +365 -0
  17. package/dist/src/findings.d.ts +185 -0
  18. package/dist/src/findings.js +287 -0
  19. package/dist/src/ids.d.ts +24 -0
  20. package/dist/src/ids.js +96 -0
  21. package/dist/src/index.d.ts +24 -0
  22. package/dist/src/index.js +24 -0
  23. package/dist/src/instant.d.ts +19 -0
  24. package/dist/src/instant.js +50 -0
  25. package/dist/src/notify.d.ts +50 -0
  26. package/dist/src/notify.js +60 -0
  27. package/dist/src/recurrence.d.ts +155 -0
  28. package/dist/src/recurrence.js +939 -0
  29. package/dist/src/release-when.d.ts +23 -0
  30. package/dist/src/release-when.js +55 -0
  31. package/dist/src/release.d.ts +198 -0
  32. package/dist/src/release.js +552 -0
  33. package/dist/src/scheduler.d.ts +490 -0
  34. package/dist/src/scheduler.js +1343 -0
  35. package/dist/src/sql/finish.d.ts +32 -0
  36. package/dist/src/sql/finish.js +103 -0
  37. package/dist/src/sql/index.d.ts +6 -0
  38. package/dist/src/sql/index.js +15 -0
  39. package/dist/src/sql/rows.d.ts +125 -0
  40. package/dist/src/sql/rows.js +297 -0
  41. package/dist/src/sql/store.d.ts +467 -0
  42. package/dist/src/sql/store.js +2166 -0
  43. package/dist/src/taint.d.ts +65 -0
  44. package/dist/src/taint.js +138 -0
  45. package/dist/src/text.d.ts +6 -0
  46. package/dist/src/text.js +25 -0
  47. package/dist/src/time-entry.d.ts +6 -0
  48. package/dist/src/time-entry.js +6 -0
  49. package/dist/src/time.d.ts +61 -0
  50. package/dist/src/time.js +140 -0
  51. package/package.json +69 -3
@@ -0,0 +1,473 @@
1
+ /**
2
+ * The built-in deterministic automations (RFC-0008 §11.1, rollout step 9): `broken-links`,
3
+ * `stale-content`, `feed-check`, `weekly-digest` and `cleanup`, as the `BuiltinRunner` that
4
+ * `runDue` steps.
5
+ *
6
+ * Every job runs in **bounded, resumable steps**: one step per tick, a fixed number of statements
7
+ * (`BUILTIN_STEP_COST`, checked by `runDue` against the tick's budget before it starts, S17), a page
8
+ * of nodes at most, and a JSON `position` the scheduler keeps in `automations.cursor`, so a large
9
+ * site's sweep spans several ticks and survives a crash between them (the next tick continues the
10
+ * same run from the position). Findings accumulate in the position up to 200 per run; counts stay
11
+ * exact.
12
+ *
13
+ * What a job reads comes through `BuiltinSources` (the live snapshot, analytics' 404 rows, the
14
+ * fetched feed): `@cloudhal/core-ts/automations` implements it over the graph's tables; tests pass
15
+ * fakes. Built-ins run as the system actor and change no content (§11.1): their only writes are
16
+ * the run row, the cursor and, for `cleanup`, the deletion of old schedule rows.
17
+ *
18
+ * Taint (§11.4, D10): a step that reads visitor-supplied text (analytics' 404 paths) or a fetched
19
+ * document (the feed check) returns `taint`, and the run records `{ at, tool }`.
20
+ */
21
+
22
+ import {
23
+ checkRss,
24
+ checkSitemap,
25
+ FEED_NEWEST,
26
+ FEED_PATHS,
27
+
28
+
29
+
30
+ } from "./feed-check.js";
31
+ import {
32
+ addFindings,
33
+
34
+ bump,
35
+ DEFAULT_STALE_AFTER_DAYS,
36
+ DIGEST_ITEMS,
37
+
38
+ digestSummary,
39
+
40
+ MAX_FINDINGS_PER_RUN,
41
+
42
+ STALE_DRAFT_DAYS,
43
+
44
+
45
+
46
+ } from "./findings.js";
47
+ import { canonicalInstant, DAY_MS, instantMs } from "./instant.js";
48
+
49
+
50
+
51
+
52
+
53
+ /**
54
+ * Statements one step of each job may take (the sources' reads and writes), declared up front for
55
+ * the tick's budget check. The core-ts conformance suite measures every step against them on
56
+ * SQLite and D1; the Workers Free tick (40) keeps the claim, the finish, the overview and the
57
+ * heartbeat beside the largest step with room to spare.
58
+ */
59
+ export const BUILTIN_STEP_COST = {
60
+ "broken-links": 6,
61
+ "stale-content": 3,
62
+ "feed-check": 4,
63
+ "weekly-digest": 6,
64
+ cleanup: 10,
65
+ };
66
+
67
+ /** Live nodes one `broken-links` step scans (§11.1: at most 200 nodes per tick on Free). */
68
+ export const LINK_PAGE_SIZE = 50;
69
+ /** Entries one `stale-content` step looks at (only route fields are read, not bodies). */
70
+ export const STALE_PAGE_SIZE = 200;
71
+ /** 404 rows the sweep asks analytics for. */
72
+ export const NOT_FOUND_LIMIT = 20;
73
+ /** Rows `cleanup` deletes per table and step. */
74
+ export const CLEANUP_LIMIT = 200;
75
+
76
+ // ───────────────────────────── what the jobs read ─────────────────────────────
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+ /**
104
+ * Where the built-in jobs read from. Each method's statements count against the step's
105
+ * `BUILTIN_STEP_COST`; `undefined` from a snapshot read means the site has never been published.
106
+ */
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+  
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+ // ───────────────────────────── the runner ─────────────────────────────
151
+
152
+
153
+
154
+
155
+
156
+
157
+ /** The state a job keeps between steps (in `automations.cursor`). */
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+ const fresh = (phase ) => ({ phase, findings: [], counts: {} });
166
+
167
+ function progressOf(position , first ) {
168
+ if (position && typeof position === "object" && "phase" in position) {
169
+ const p = position ;
170
+ return {
171
+ phase: String(p.phase),
172
+ ...(typeof p.after === "string" ? { after: p.after } : {}),
173
+ findings: Array.isArray(p.findings) ? (p.findings ) : [],
174
+ counts: p.counts && typeof p.counts === "object" ? { ...p.counts } : {},
175
+ };
176
+ }
177
+ return fresh(first);
178
+ }
179
+
180
+ const plural = (n , one , many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
181
+
182
+ /** The notification of a finished run with findings (§14), for its owner. */
183
+ function findingsNotice(
184
+ a ,
185
+ run ,
186
+ now ,
187
+ kind ,
188
+ summary ,
189
+ counts ,
190
+ extra = {},
191
+ ) {
192
+ return {
193
+ id: `${kind}:${run}`,
194
+ kind,
195
+ siteId: a.siteId,
196
+ automationId: a.id,
197
+ automationName: a.name,
198
+ runId: run,
199
+ recipients: [a.owner.id],
200
+ at: canonicalInstant(now),
201
+ summary,
202
+ counts,
203
+ ...extra,
204
+ };
205
+ }
206
+
207
+ /** Ends a run that found the site unpublished. */
208
+ const unpublished = () => ({
209
+ done: true,
210
+ outcome: "nothing-to-do",
211
+ summary: "The site has not been published yet; there is nothing live to check.",
212
+ });
213
+
214
+ /** A step that continues from `progress`. */
215
+ const more = (p , extra = {}) => ({
216
+ done: false,
217
+ position: p,
218
+ ...extra,
219
+ });
220
+
221
+ /**
222
+ * The five built-in jobs as one `BuiltinRunner` (`cost` is the largest step; `costOf` the job's).
223
+ * Steps throw only for source errors, which `runDue` records as a failed run.
224
+ */
225
+ export function createBuiltinRunner(
226
+ sources ,
227
+ options = {},
228
+ ) {
229
+ const linkPage = options.linkPageSize ?? LINK_PAGE_SIZE;
230
+ const stalePage = options.stalePageSize ?? STALE_PAGE_SIZE;
231
+
232
+ async function brokenLinks(
233
+ a ,
234
+ run ,
235
+ position ,
236
+ now ,
237
+ ) {
238
+ const p = progressOf(position, "links");
239
+ if (p.phase === "links") {
240
+ const page = await sources.scanLinks({
241
+ siteId: a.siteId,
242
+ ...(p.after ? { after: p.after } : {}),
243
+ limit: linkPage,
244
+ now,
245
+ });
246
+ if (!page) return unpublished();
247
+ bump(p.counts, "nodes-scanned", page.scanned);
248
+ bump(p.counts, "links-checked", page.links);
249
+ for (const f of page.findings) bump(p.counts, f.code);
250
+ addFindings(p.findings, page.findings);
251
+ if (page.next) return more({ ...p, after: page.next });
252
+ if (sources.notFoundPaths) {
253
+ const { after: _done, ...rest } = p;
254
+ return more({ ...rest, phase: "not-found" });
255
+ }
256
+ return finishLinks(a, run, p, now);
257
+ }
258
+ // The 404 paths are visitor-supplied: reading them taints the run (§11.4, `broken_links`).
259
+ const rows = await sources.notFoundPaths?.({ siteId: a.siteId, now, limit: NOT_FOUND_LIMIT });
260
+ const taint = rows ? { at: canonicalInstant(now), tool: "broken_links" } : undefined;
261
+ const found = (rows ?? []).map((r) => ({
262
+ code: "not-found-path",
263
+ severity: r.hits >= 10 ? "warning" : "info",
264
+ ...r,
265
+ untrusted: true,
266
+ }));
267
+ bump(p.counts, "not-found-path", found.length);
268
+ addFindings(p.findings, found);
269
+ return { ...finishLinks(a, run, p, now), ...(taint ? { taint } : {}) };
270
+ }
271
+
272
+ function finishLinks(a , run , p , now ) {
273
+ const broken =
274
+ (p.counts["broken-internal-link"] ?? 0) +
275
+ (p.counts["broken-media-reference"] ?? 0) +
276
+ (p.counts["broken-menu-target"] ?? 0);
277
+ const gated = p.counts["link-to-gated-content"] ?? 0;
278
+ const notFound = p.counts["not-found-path"] ?? 0;
279
+ const counts = { ...p.counts, "broken-links": broken };
280
+ const summary = `Checked ${plural(p.counts["links-checked"] ?? 0, "reference")} in ${plural(p.counts["nodes-scanned"] ?? 0, "live node")}: ${plural(broken, "broken link")}, ${plural(gated, "link")} to gated content, ${plural(notFound, "top 404 path")}.`;
281
+ const total = broken + gated + notFound;
282
+ return {
283
+ done: true,
284
+ outcome: total > 0 ? "did-work" : "nothing-to-do",
285
+ counts,
286
+ summary,
287
+ findings: p.findings,
288
+ ...(total > 0
289
+ ? { notify: [findingsNotice(a, run, now, "automation-findings", summary, counts)] }
290
+ : {}),
291
+ };
292
+ }
293
+
294
+ async function staleContent(
295
+ a ,
296
+ job ,
297
+ run ,
298
+ position ,
299
+ now ,
300
+ ) {
301
+ const p = progressOf(position, "entries");
302
+ const days = job.staleAfterDays ?? DEFAULT_STALE_AFTER_DAYS;
303
+ const cutoff = canonicalInstant(instantMs(now) - days * DAY_MS);
304
+ const page = await sources.staleEntries({
305
+ siteId: a.siteId,
306
+ cutoff,
307
+ ...(p.after ? { after: p.after } : {}),
308
+ limit: stalePage,
309
+ now,
310
+ });
311
+ if (!page) return unpublished();
312
+ bump(p.counts, "entries-scanned", page.scanned);
313
+ bump(p.counts, "stale-entries", page.stale.length);
314
+ // Keep the oldest 200 across pages (a review list starts with what is most out of date).
315
+ p.findings = [...(p.findings ), ...page.stale]
316
+ .sort((x, y) =>
317
+ x.updatedAt < y.updatedAt
318
+ ? -1
319
+ : x.updatedAt > y.updatedAt
320
+ ? 1
321
+ : x.nodeId < y.nodeId
322
+ ? -1
323
+ : 1,
324
+ )
325
+ .slice(0, MAX_FINDINGS_PER_RUN);
326
+ if (page.next) return more({ ...p, after: page.next });
327
+ const n = p.counts["stale-entries"] ?? 0;
328
+ const summary = `${plural(n, "live entry", "live entries")} not updated for ${days} days (of ${p.counts["entries-scanned"] ?? 0}).`;
329
+ return {
330
+ done: true,
331
+ outcome: n > 0 ? "did-work" : "nothing-to-do",
332
+ counts: p.counts,
333
+ summary,
334
+ findings: p.findings,
335
+ ...(n > 0
336
+ ? { notify: [findingsNotice(a, run, now, "automation-findings", summary, p.counts)] }
337
+ : {}),
338
+ };
339
+ }
340
+
341
+ async function feedCheck(
342
+ a ,
343
+ run ,
344
+ position ,
345
+ now ,
346
+ ) {
347
+ const p = progressOf(position, "rss");
348
+ const kind = p.phase ;
349
+ const notServed = {
350
+ done: true,
351
+ outcome: "nothing-to-do",
352
+ counts: { "documents-checked": 0 },
353
+ summary:
354
+ "This site is not served from here (no site Worker or local renderer for it); the feed and sitemap were not checked.",
355
+ };
356
+ if (!sources.fetchDocument) return notServed;
357
+ const exp = await sources.feedExpectations({ siteId: a.siteId, now, newest: FEED_NEWEST });
358
+ if (!exp) return unpublished();
359
+ let doc ;
360
+ try {
361
+ doc = await sources.fetchDocument({ siteId: a.siteId, path: FEED_PATHS[kind] });
362
+ // Not served from here at all (another site of the deployment): nothing to check.
363
+ if (!doc && kind === "rss") return notServed;
364
+ } catch {
365
+ doc = undefined; // a failed fetch is a finding (`feed-unreachable`)
366
+ }
367
+ // Fetched output is untrusted text (§11.4): the run is tainted once it has read a body.
368
+ const taint = doc ? { at: canonicalInstant(now), tool: "feed_check" } : undefined;
369
+ const found = kind === "rss" ? checkRss(doc, exp) : checkSitemap(doc, exp);
370
+ bump(p.counts, "documents-checked");
371
+ for (const f of found) bump(p.counts, f.code);
372
+ addFindings(p.findings, found);
373
+ if (kind === "rss") return more({ ...p, phase: "sitemap" }, taint ? { taint } : {});
374
+ const errors = p.findings.filter((f) => f.severity === "error").length;
375
+ const total = Object.entries(p.counts)
376
+ .filter(([k]) => k.startsWith("feed-"))
377
+ .reduce((n, [, v]) => n + v, 0);
378
+ const leaked = p.counts["feed-gated-node"] ?? 0;
379
+ const summary = `Checked the RSS feed and the sitemap: ${plural(total, "problem")}${leaked > 0 ? `, ${plural(leaked, "gated node")} exposed` : ""}.`;
380
+ return {
381
+ done: true,
382
+ outcome: total > 0 ? "did-work" : "nothing-to-do",
383
+ counts: { ...p.counts, "feed-problems": total, "feed-errors": errors },
384
+ summary,
385
+ findings: p.findings,
386
+ ...(taint ? { taint } : {}),
387
+ ...(total > 0
388
+ ? { notify: [findingsNotice(a, run, now, "automation-findings", summary, p.counts)] }
389
+ : {}),
390
+ };
391
+ }
392
+
393
+ async function weeklyDigest(a , run , now ) {
394
+ const d = await sources.digest({ siteId: a.siteId, automationId: a.id, now });
395
+ const section = (
396
+ code ,
397
+ s ,
398
+ severity ,
399
+ ) => ({ code, severity, count: s.count, items: s.items.slice(0, DIGEST_ITEMS) });
400
+ const findings = [
401
+ section("digest-published", d.published, "info"),
402
+ section("digest-scheduled", d.scheduled, "info"),
403
+ section("digest-attention", d.attention, d.attention.count > 0 ? "warning" : "info"),
404
+ section("digest-open-findings", d.openFindings, "info"),
405
+ ];
406
+ const counts = {
407
+ published: d.published.count,
408
+ scheduled: d.scheduled.count,
409
+ "needs-attention": d.attention.count,
410
+ "open-findings": d.openFindings.count,
411
+ };
412
+ const summary = digestSummary(d);
413
+ return {
414
+ done: true,
415
+ // A digest is work done whatever it says: it was produced and delivered.
416
+ outcome: "did-work",
417
+ counts,
418
+ summary,
419
+ findings,
420
+ notify: [findingsNotice(a, run, now, "automation-digest", summary, counts, { digest: d })],
421
+ };
422
+ }
423
+
424
+ async function cleanup(a , position , now ) {
425
+ const p = progressOf(position, "retention");
426
+ if (p.phase === "retention") {
427
+ const step = await sources.cleanup({ siteId: a.siteId, now, limit: CLEANUP_LIMIT });
428
+ for (const [k, v] of Object.entries(step.counts)) bump(p.counts, k, v);
429
+ if (step.more) return more(p);
430
+ return more({ ...p, phase: "drafts" });
431
+ }
432
+ const drafts = await sources.staleDrafts({
433
+ siteId: a.siteId,
434
+ now,
435
+ days: STALE_DRAFT_DAYS,
436
+ limit: MAX_FINDINGS_PER_RUN,
437
+ });
438
+ bump(p.counts, "stale-drafts", drafts.count);
439
+ addFindings(p.findings, drafts.drafts);
440
+ const deleted = (p.counts["runs-deleted"] ?? 0) + (p.counts["releases-deleted"] ?? 0);
441
+ const tidied =
442
+ deleted +
443
+ (p.counts["findings-trimmed"] ?? 0) +
444
+ (p.counts["leases-cleared"] ?? 0) +
445
+ (p.counts["stale-runs-closed"] ?? 0);
446
+ return {
447
+ done: true,
448
+ outcome: tidied + drafts.count > 0 ? "did-work" : "nothing-to-do",
449
+ counts: p.counts,
450
+ summary: `Deleted ${plural(p.counts["runs-deleted"] ?? 0, "old run")} and ${plural(p.counts["releases-deleted"] ?? 0, "old release")}; trimmed ${plural(p.counts["findings-trimmed"] ?? 0, "finding list")}; cleared ${plural(p.counts["leases-cleared"] ?? 0, "expired lease")}; closed ${plural(p.counts["stale-runs-closed"] ?? 0, "stale run")}; ${plural(drafts.count, "draft")} untouched for ${STALE_DRAFT_DAYS} days.`,
451
+ findings: p.findings,
452
+ };
453
+ }
454
+
455
+ return {
456
+ cost: Math.max(...Object.values(BUILTIN_STEP_COST)),
457
+ costOf: (job) => BUILTIN_STEP_COST[job.builtin],
458
+ async step({ automation, job, run, position, now }) {
459
+ switch (job.builtin) {
460
+ case "broken-links":
461
+ return brokenLinks(automation, run.id, position, now);
462
+ case "stale-content":
463
+ return staleContent(automation, job, run.id, position, now);
464
+ case "feed-check":
465
+ return feedCheck(automation, run.id, position, now);
466
+ case "weekly-digest":
467
+ return weeklyDigest(automation, run.id, now);
468
+ case "cleanup":
469
+ return cleanup(automation, position, now);
470
+ }
471
+ },
472
+ };
473
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @cloudhal/schedules/engine — the Temporal-free part of the release model (RFC-0008 §6, §8.5):
3
+ * pinning, the dependency closure, the `rl1:` hash, composition, conflicts, the state machine, run
4
+ * ids, the instant helpers, the statements that end a release, the `TickMeter`, and the
5
+ * scheduler's types. Nothing here imports `temporal-polyfill`, so `@cloudhal/core-ts` (and with it
6
+ * the site Worker's bundle) can apply releases without the time-zone library. Wall-clock times,
7
+ * recurrence and `runDue` are in the package's main entry.
8
+ */
9
+ export * from "./budget-meter.js";
10
+ export * from "./errors.js";
11
+ export * from "./ids.js";
12
+ export * from "./instant.js";
13
+ export * from "./release.js";
14
+ export type { DueRelease, Heartbeat, RecoverableRelease, ReleaseExecution, ReleaseExecutionInput, ReleaseExecutor, ReleaseFinish, StoredReleaseItem, TickReport, } from "./scheduler.js";
15
+ export { type ReleaseFinishInput, releaseFinishStatements, runStateForRelease, } from "./sql/finish.js";
16
+ export * from "./text.js";
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @cloudhal/schedules/engine — the Temporal-free part of the release model (RFC-0008 §6, §8.5):
3
+ * pinning, the dependency closure, the `rl1:` hash, composition, conflicts, the state machine, run
4
+ * ids, the instant helpers, the statements that end a release, the `TickMeter`, and the
5
+ * scheduler's types. Nothing here imports `temporal-polyfill`, so `@cloudhal/core-ts` (and with it
6
+ * the site Worker's bundle) can apply releases without the time-zone library. Wall-clock times,
7
+ * recurrence and `runDue` are in the package's main entry.
8
+ */
9
+ export * from "./budget-meter.js";
10
+ export * from "./errors.js";
11
+ export * from "./ids.js";
12
+ export * from "./instant.js";
13
+ export * from "./release.js";
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+ export {
26
+
27
+ releaseFinishStatements,
28
+ runStateForRelease,
29
+ } from "./sql/finish.js";
30
+ export * from "./text.js";
@@ -0,0 +1,22 @@
1
+ /** Error codes of `@cloudhal/schedules`; routes map them to HTTP answers (step 7). */
2
+ export type ScheduleErrorCode = "invalid_time_zone" | "invalid_local_time" | "invalid_timestamp" | "invalid_rule" | "unsupported_rule_part" | "rule_too_frequent" | "nothing_to_publish" | "site_node_in_release" | "remove_not_allowed" | "node_not_found" | "duplicate_item" | "too_many_items" | "invalid_transition" | "not_found" | "too_many_releases" | "invalid_settings" | "too_soon" | "too_far";
3
+ /** A refused input or an illegal state change; nothing was written. */
4
+ export declare class ScheduleError extends Error {
5
+ readonly name = "ScheduleError";
6
+ readonly code: ScheduleErrorCode;
7
+ constructor(code: ScheduleErrorCode, message: string);
8
+ }
9
+ /** A compare-and-swap lost: the row changed (or is not in the expected state) since it was read. */
10
+ export declare class ScheduleConflictError extends Error {
11
+ readonly name = "ScheduleConflictError";
12
+ readonly kind: "release" | "automation" | "run" | "settings" | "system_job";
13
+ readonly id: string;
14
+ constructor(kind: ScheduleConflictError["kind"], id: string, message?: string);
15
+ }
16
+ /** A tick tried to execute more statements than its `TickBudget` allows (S17). */
17
+ export declare class TickBudgetExhaustedError extends Error {
18
+ readonly name = "TickBudgetExhaustedError";
19
+ readonly used: number;
20
+ readonly max: number;
21
+ constructor(used: number, max: number);
22
+ }
@@ -0,0 +1,56 @@
1
+ /** Error codes of `@cloudhal/schedules`; routes map them to HTTP answers (step 7). */
2
+
3
+  
4
+
5
+
6
+
7
+
8
+
9
+
10
+  
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+ /** A refused input or an illegal state change; nothing was written. */
25
+ export class ScheduleError extends Error {
26
+ name = "ScheduleError";
27
+ code ;
28
+ constructor(code , message ) {
29
+ super(message);
30
+ this.code = code;
31
+ }
32
+ }
33
+
34
+ /** A compare-and-swap lost: the row changed (or is not in the expected state) since it was read. */
35
+ export class ScheduleConflictError extends Error {
36
+ name = "ScheduleConflictError";
37
+ kind ;
38
+ id ;
39
+ constructor(kind , id , message ) {
40
+ super(message ?? `${kind} ${id} changed since it was read`);
41
+ this.kind = kind;
42
+ this.id = id;
43
+ }
44
+ }
45
+
46
+ /** A tick tried to execute more statements than its `TickBudget` allows (S17). */
47
+ export class TickBudgetExhaustedError extends Error {
48
+ name = "TickBudgetExhaustedError";
49
+ used ;
50
+ max ;
51
+ constructor(used , max ) {
52
+ super(`tick query budget exhausted (${used} of ${max} statements)`);
53
+ this.used = used;
54
+ this.max = max;
55
+ }
56
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The `feed-check` built-in's checks (RFC-0008 §11.1, §7.2), pure over the fetched text. The
3
+ * site's own RSS feed and sitemap are fetched through the `SITE` binding (or the local renderer on
4
+ * Node) and checked for: well-formed XML of the right kind; items with a title and a link; no date
5
+ * in the future; the newest published entries present; media URLs that are live assets; and the
6
+ * **gate self-check** — no embargoed or expired node appears, the time-gate helper verified in
7
+ * production.
8
+ *
9
+ * The fetched text is untrusted (§11.4): it is parsed with bounded scans, never evaluated, and
10
+ * whatever of it a finding quotes is one plain line, marked `untrusted`.
11
+ */
12
+ import type { FeedFinding, GateStateName } from "./findings.js";
13
+ /** Documents larger than this are not parsed (`feed-invalid`). */
14
+ export declare const MAX_DOCUMENT_CHARS = 5000000;
15
+ /** How many of the newest published entries must appear in the feed and the sitemap. */
16
+ export declare const FEED_NEWEST = 5;
17
+ /** Clock skew tolerated before a date counts as "in the future". */
18
+ export declare const FUTURE_TOLERANCE_MS: number;
19
+ export type FeedDocumentKind = "rss" | "sitemap";
20
+ export declare const FEED_PATHS: Readonly<Record<FeedDocumentKind, string>>;
21
+ /** What the live snapshot says the documents must (and must not) contain. */
22
+ export interface FeedExpectations {
23
+ readonly now: string;
24
+ /** The newest published, visible entries (by `publishedAt`), newest first. */
25
+ readonly newest: readonly {
26
+ readonly nodeId: string;
27
+ readonly path: string;
28
+ readonly title: string;
29
+ }[];
30
+ /** Live pages and entries gated right now: they must appear nowhere. */
31
+ readonly gated: readonly {
32
+ readonly nodeId: string;
33
+ readonly path: string;
34
+ readonly state: GateStateName;
35
+ }[];
36
+ /** The media URL prefixes (first 16 hex of the SHA-256) of every live asset. */
37
+ readonly mediaPrefixes: readonly string[];
38
+ }
39
+ export interface FetchedDocument {
40
+ readonly status: number;
41
+ readonly contentType?: string;
42
+ readonly body: string;
43
+ }
44
+ /**
45
+ * Why `text` is not well-formed XML (a bounded, linear scan: elements nest and close, one root,
46
+ * no stray text or `&`), or undefined. Not a validating parser; enough to catch a broken feed.
47
+ */
48
+ export declare function xmlProblem(text: string): string | undefined;
49
+ /** Element text: CDATA unwrapped, the five XML entities and numeric references decoded. */
50
+ export declare function xmlText(raw: string): string;
51
+ /** A URL's path as the site routes it (no query, fragment or trailing slash), or undefined. */
52
+ export declare function urlPath(url: string): string | undefined;
53
+ /** Checks the site's RSS 2.0 feed. */
54
+ export declare function checkRss(doc: FetchedDocument | undefined, exp: FeedExpectations): FeedFinding[];
55
+ /** Checks the site's sitemap. */
56
+ export declare function checkSitemap(doc: FetchedDocument | undefined, exp: FeedExpectations): FeedFinding[];