@cloudhal/cloudflare 0.6.1 → 0.6.3

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.
@@ -0,0 +1,8 @@
1
+ import type { SystemJobDefinition } from "@cloudhal/schedules";
2
+ import type { SqlDriver } from "@cloudhal/storage";
3
+ /** The next five-minute mark strictly after `after` (UTC). */
4
+ export declare const everyFiveMinutes: (after: Date) => Date;
5
+ export declare function listValuesJob(sql: SqlDriver, o: {
6
+ paid: boolean;
7
+ log: (line: string) => void;
8
+ }): SystemJobDefinition;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * RFC-0042 §4, #110: the admin Worker's `lists.backfill` system job. Every five minutes it makes
3
+ * listed collections' `entry_list_values` ready again where a settings change, a field
4
+ * operation, an import, a race or a deployment from before migration 0029 left them not ready
5
+ * (`rebuildListValues`, resumable and guarded, so a run cut short loses nothing), within a budget
6
+ * that fits the tick plan. On the paid plan it also removes rows of collections that list no
7
+ * fields any more. Until a collection is ready, its listings scan as before.
8
+ *
9
+ * The declared `cost` is the run's statement budget, which `rebuildListValues` enforces on every
10
+ * statement it issues (discovery, chunks and tidy alike), so the tick's meter never sees more.
11
+ * Each run starts at another not-ready collection, so a busy one cannot hold the rest back.
12
+ */
13
+ import { rebuildListValues } from "@cloudhal/core-ts";
14
+
15
+
16
+
17
+ const EVERY_MS = 5 * 60_000;
18
+
19
+ /** The next five-minute mark strictly after `after` (UTC). */
20
+ export const everyFiveMinutes = (after ) =>
21
+ new Date((Math.floor(after.getTime() / EVERY_MS) + 1) * EVERY_MS);
22
+
23
+ export function listValuesJob(
24
+ sql ,
25
+ o ,
26
+ ) {
27
+ // Discovery is two statements, a chunk of 100 entries about five; the free tick allows 40 in all.
28
+ const budget = o.paid
29
+ ? { entries: 2000, ms: 20_000, statements: 150 }
30
+ : { entries: 200, ms: 5_000, statements: 16 };
31
+ return {
32
+ name: "lists.backfill",
33
+ cost: budget.statements,
34
+ next: everyFiveMinutes,
35
+ async run({ now }) {
36
+ const start = Math.floor(now.getTime() / EVERY_MS);
37
+ const r = await rebuildListValues(sql, { budget, tidy: o.paid, start });
38
+ const written = r.collections.reduce((n, c) => n + c.written, 0);
39
+ const waiting = r.collections.filter((c) => !c.ready).length;
40
+ if (written + r.tidied > 0 || r.exhausted)
41
+ o.log(
42
+ `lists backfill: ${written} entr${written === 1 ? "y" : "ies"} indexed, ${r.tidied} row(s) tidied, ${waiting} collection(s) not ready${r.exhausted ? " (more next run)" : ""}`,
43
+ );
44
+ },
45
+ };
46
+ }
@@ -63,6 +63,7 @@ import { SqlScheduleStore } from "@cloudhal/schedules/sql";
63
63
  import { D1Driver } from "@cloudhal/storage/d1";
64
64
  import { R2BlobStore } from "@cloudhal/storage/r2";
65
65
  import { flushCommentPurges, runCommentsHourly } from "./comments.js";
66
+ import { listValuesJob } from "./list-values-job.js";
66
67
  import { PURGE_MAX_REQUESTS, PURGE_TAGS_PER_REQUEST } from "./purge.js";
67
68
  import { attachedSite, bindingFor, routedSite } from "./site-routes.js";
68
69
 
@@ -270,6 +271,7 @@ export function adminSystemJobs(
270
271
  log(`schedules retention: ${r.runs} run(s), ${r.releases} release(s) deleted`);
271
272
  },
272
273
  },
274
+ listValuesJob(sql, { paid: env.CLOUDHAL_TICK_BUDGET === "paid", log }),
273
275
  ];
274
276
  if (o.commentsOn)
275
277
  jobs.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudhal/cloudflare",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Cloudhal on Cloudflare: the admin Worker (API, auth, MCP, Studio) over D1 + R2",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://cloudhal.dev",
@@ -48,23 +48,23 @@
48
48
  "README.md"
49
49
  ],
50
50
  "dependencies": {
51
- "@cloudhal/agent-runtime": "0.6.1",
52
- "@cloudhal/analytics": "0.6.1",
53
- "@cloudhal/api": "0.6.1",
54
- "@cloudhal/comments": "0.6.1",
55
- "@cloudhal/core-ts": "0.6.1",
56
- "@cloudhal/mcp-server": "0.6.1",
57
- "@cloudhal/schedules": "0.6.1",
58
- "@cloudhal/storage": "0.6.1",
59
- "zod": "^4.6.5"
51
+ "@cloudhal/agent-runtime": "0.6.3",
52
+ "@cloudhal/analytics": "0.6.3",
53
+ "@cloudhal/api": "0.6.3",
54
+ "@cloudhal/comments": "0.6.3",
55
+ "@cloudhal/core-ts": "0.6.3",
56
+ "@cloudhal/mcp-server": "0.6.3",
57
+ "@cloudhal/schedules": "0.6.3",
58
+ "@cloudhal/storage": "0.6.3",
59
+ "zod": "^4.6.7"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@cloudflare/workers-types": "^5.20261007.1",
63
- "@cloudhal/astro-renderer": "0.6.1",
63
+ "@cloudhal/astro-renderer": "0.6.3",
64
64
  "@types/node": "^26.6.5",
65
65
  "typescript": "7.0.2",
66
- "vitest": "5.0.3",
67
- "wrangler": "4.148.0"
66
+ "vitest": "5.0.5",
67
+ "wrangler": "4.158.0"
68
68
  },
69
69
  "engines": {
70
70
  "node": ">=24"