@cloudhal/cloudflare 0.8.0 → 0.9.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.
@@ -71,8 +71,9 @@ import { adminMail, } from "./mail.js";
71
71
  import { purgeSiteCache } from "./purge.js";
72
72
  import {
73
73
 
74
+ cronTick,
74
75
  followUpDelay,
75
- releasePurger,
76
+ publishNowPurge,
76
77
  requestBackstop,
77
78
  runAdminTick,
78
79
 
@@ -537,7 +538,7 @@ export function createAdminWorker(options = {}) {
537
538
  // RFC-0008 §12–§13: the schedule routes and tools; "Publish now" purges like a tick.
538
539
  schedules: {
539
540
  store: new SqlScheduleStore(sql),
540
- purge: releasePurger(env, sql, { log }),
541
+ ...publishNowPurge(env, sql, log),
541
542
  automationsEnabled: env.CLOUDHAL_AUTOMATIONS !== "off",
542
543
  },
543
544
  scheduler: {
@@ -571,8 +572,7 @@ export function createAdminWorker(options = {}) {
571
572
  await ensureMigrated(sql);
572
573
  const tick = (now ) =>
573
574
  runAdminTick(env, {
574
- trigger: "cron",
575
- now,
575
+ ...cronTick(controller, env, now),
576
576
  log,
577
577
  analytics: (s, at) => adminAnalytics(env, s, { now: () => at, log }),
578
578
  commentsOn: commentsOn(env),
@@ -95,7 +95,30 @@ export interface AdminTickOptions {
95
95
  readonly commentsOn: boolean;
96
96
  /** Keeps a deferred purge's flush alive after the tick (the handler's `waitUntil`). */
97
97
  readonly waitUntil?: ((p: Promise<unknown>) => void) | undefined;
98
+ /**
99
+ * RFC-0045: the R2 calls release purges may still make in this invocation, shared by every tick
100
+ * it runs (the cron's follow-up); absent: one allowance per tick.
101
+ */
102
+ readonly releaseBlobs?: {
103
+ left: number;
104
+ } | undefined;
98
105
  }
106
+ /** "Publish now"'s purge, and the deployment's tick budget that sizes its blob calls (RFC-0045). */
107
+ export declare function publishNowPurge(env: SchedulerEnv, sql: SqlDriver, log: (line: string) => void): {
108
+ purge: ReleasePurger;
109
+ tickBudget: TickBudget;
110
+ };
111
+ /**
112
+ * A cron tick's trigger and clock, with RFC-0045's R2 allowance for release purges: one per
113
+ * invocation (`controller`), so the cron's follow-up tick shares it (the cap is per invocation).
114
+ */
115
+ export declare function cronTick(controller: object, env: SchedulerEnv, now: Date): {
116
+ trigger: "cron";
117
+ now: Date;
118
+ releaseBlobs: {
119
+ left: number;
120
+ };
121
+ };
99
122
  /** One tick of the admin Worker (cron, alarm, request backstop or the operator's run-due). */
100
123
  export declare function runAdminTick(env: SchedulerEnv, o: AdminTickOptions): Promise<TickReport>;
101
124
  /**
@@ -30,6 +30,7 @@ import { SqlCommentStore } from "@cloudhal/comments/sql";
30
30
  import {
31
31
 
32
32
 
33
+ releaseBlobAllowance,
33
34
  SiteGraphStore,
34
35
  searchProviderFromEnv,
35
36
  siteCacheTag,
@@ -380,10 +381,35 @@ export function adminBuiltinInputs(
380
381
 
381
382
 
382
383
 
384
+
385
+
386
+
387
+
388
+
383
389
 
384
390
 
385
391
  const sleep = (ms ) => new Promise((resolve) => setTimeout(resolve, ms));
386
392
 
393
+ /** "Publish now"'s purge, and the deployment's tick budget that sizes its blob calls (RFC-0045). */
394
+ export function publishNowPurge(env , sql , log ) {
395
+ return { purge: releasePurger(env, sql, { log }), tickBudget: tickBudget(env) };
396
+ }
397
+
398
+ const invocationBlobs = new WeakMap ();
399
+
400
+ /**
401
+ * A cron tick's trigger and clock, with RFC-0045's R2 allowance for release purges: one per
402
+ * invocation (`controller`), so the cron's follow-up tick shares it (the cap is per invocation).
403
+ */
404
+ export function cronTick(controller , env , now ) {
405
+ let releaseBlobs = invocationBlobs.get(controller);
406
+ if (!releaseBlobs) {
407
+ releaseBlobs = { left: releaseBlobAllowance(tickBudget(env)) };
408
+ invocationBlobs.set(controller, releaseBlobs);
409
+ }
410
+ return { trigger: "cron" , now, releaseBlobs };
411
+ }
412
+
387
413
  /** One tick of the admin Worker (cron, alarm, request backstop or the operator's run-due). */
388
414
  export function runAdminTick(env , o ) {
389
415
  const sql = new D1Driver(env.DB);
@@ -425,6 +451,7 @@ export function runAdminTick(env , o )
425
451
  log: o.log,
426
452
  }),
427
453
  purge: ({ counted }) => releasePurger(env, counted, { log: o.log, wake: flush }),
454
+ ...(o.releaseBlobs ? { releaseBlobs: o.releaseBlobs } : {}),
428
455
  automationsEnabled: env.CLOUDHAL_AUTOMATIONS !== "off",
429
456
  // RFC-0008 §11.1: the built-in jobs read analytics' 404 rows and the site's own feed.
430
457
  builtinInputs: ({ counted }) => adminBuiltinInputs(env, o.analytics(counted, o.now)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudhal/cloudflare",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
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,19 +48,19 @@
48
48
  "README.md"
49
49
  ],
50
50
  "dependencies": {
51
- "@cloudhal/agent-runtime": "0.8.0",
52
- "@cloudhal/analytics": "0.8.0",
53
- "@cloudhal/api": "0.8.0",
54
- "@cloudhal/comments": "0.8.0",
55
- "@cloudhal/core-ts": "0.8.0",
56
- "@cloudhal/mcp-server": "0.8.0",
57
- "@cloudhal/schedules": "0.8.0",
58
- "@cloudhal/storage": "0.8.0",
51
+ "@cloudhal/agent-runtime": "0.9.0",
52
+ "@cloudhal/analytics": "0.9.0",
53
+ "@cloudhal/api": "0.9.0",
54
+ "@cloudhal/comments": "0.9.0",
55
+ "@cloudhal/core-ts": "0.9.0",
56
+ "@cloudhal/mcp-server": "0.9.0",
57
+ "@cloudhal/schedules": "0.9.0",
58
+ "@cloudhal/storage": "0.9.0",
59
59
  "zod": "^4.6.7"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@cloudflare/workers-types": "^5.20261007.1",
63
- "@cloudhal/astro-renderer": "0.8.0",
63
+ "@cloudhal/astro-renderer": "0.9.0",
64
64
  "@types/node": "^26.6.5",
65
65
  "typescript": "7.0.2",
66
66
  "vitest": "5.1.0",