@cloudhal/cloudflare 0.7.3 → 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.
- package/dist/src/admin-worker.js +4 -4
- package/dist/src/features.d.ts +15 -0
- package/dist/src/features.js +42 -3
- package/dist/src/scheduler.d.ts +23 -0
- package/dist/src/scheduler.js +27 -0
- package/package.json +10 -10
package/dist/src/admin-worker.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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),
|
package/dist/src/features.d.ts
CHANGED
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
* `expiry` until it answers `{ "gates": 2 }` (derived gates, RFC-0042 §3.6).
|
|
7
7
|
*/
|
|
8
8
|
import { type GateSupport } from "@cloudhal/core-ts/availability";
|
|
9
|
+
import { type FieldTypeSupport } from "@cloudhal/core-ts/fields";
|
|
9
10
|
import type { SiteFetch } from "./purge.js";
|
|
10
11
|
/** The features the site Worker reports, or `undefined` when it does not answer (older Workers). */
|
|
11
12
|
export declare function siteFeatures(fetch: SiteFetch, token: string): Promise<{
|
|
12
13
|
gates?: number;
|
|
14
|
+
fields?: number;
|
|
13
15
|
} | undefined>;
|
|
14
16
|
/**
|
|
15
17
|
* The store's gate capability for one admin Worker isolate. A confirmation is remembered as a
|
|
@@ -25,3 +27,16 @@ export declare function siteGateSupport(options: {
|
|
|
25
27
|
readonly remember: (version: number) => void;
|
|
26
28
|
readonly log?: (line: string) => void;
|
|
27
29
|
}): GateSupport;
|
|
30
|
+
/**
|
|
31
|
+
* RFC-0045 §1: the store's reference and repeater capability for one admin Worker isolate, the
|
|
32
|
+
* twin of `siteGateSupport`: yes once the site Worker answers `{ "fields": 2 }` or more (kept as
|
|
33
|
+
* a plain value); a refusal or an error is asked again. Built in rollout step 2; nothing passes it
|
|
34
|
+
* to a store until step 7 enables the types.
|
|
35
|
+
*/
|
|
36
|
+
export declare function siteFieldTypeSupport(options: {
|
|
37
|
+
readonly fetch: SiteFetch | undefined;
|
|
38
|
+
readonly token: string | undefined;
|
|
39
|
+
readonly confirmed: () => boolean;
|
|
40
|
+
readonly remember: () => void;
|
|
41
|
+
readonly log?: (line: string) => void;
|
|
42
|
+
}): FieldTypeSupport;
|
package/dist/src/features.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* `expiry` until it answers `{ "gates": 2 }` (derived gates, RFC-0042 §3.6).
|
|
7
7
|
*/
|
|
8
8
|
import { AVAILABILITY_GATES_VERSION, } from "@cloudhal/core-ts/availability";
|
|
9
|
+
import { FIELDS_FEATURE_VERSION, } from "@cloudhal/core-ts/fields";
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
const FEATURES_URL = "https://site.internal/__cloudhal/features";
|
|
@@ -14,7 +15,7 @@ const FEATURES_URL = "https://site.internal/__cloudhal/features";
|
|
|
14
15
|
export async function siteFeatures(
|
|
15
16
|
fetch ,
|
|
16
17
|
token ,
|
|
17
|
-
)
|
|
18
|
+
) {
|
|
18
19
|
const res = await fetch(FEATURES_URL, {
|
|
19
20
|
method: "GET",
|
|
20
21
|
headers: { authorization: `Bearer ${token}` },
|
|
@@ -23,8 +24,13 @@ export async function siteFeatures(
|
|
|
23
24
|
await res.body?.cancel();
|
|
24
25
|
return undefined;
|
|
25
26
|
}
|
|
26
|
-
const body = (await res.json().catch(() => undefined))
|
|
27
|
-
|
|
27
|
+
const body = (await res.json().catch(() => undefined))
|
|
28
|
+
|
|
29
|
+
;
|
|
30
|
+
return {
|
|
31
|
+
...(typeof body?.gates === "number" ? { gates: body.gates } : {}),
|
|
32
|
+
...(typeof body?.fields === "number" ? { fields: body.fields } : {}),
|
|
33
|
+
};
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
/**
|
|
@@ -68,3 +74,36 @@ export function siteGateSupport(options
|
|
|
68
74
|
},
|
|
69
75
|
};
|
|
70
76
|
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* RFC-0045 §1: the store's reference and repeater capability for one admin Worker isolate, the
|
|
80
|
+
* twin of `siteGateSupport`: yes once the site Worker answers `{ "fields": 2 }` or more (kept as
|
|
81
|
+
* a plain value); a refusal or an error is asked again. Built in rollout step 2; nothing passes it
|
|
82
|
+
* to a store until step 7 enables the types.
|
|
83
|
+
*/
|
|
84
|
+
export function siteFieldTypeSupport(options
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
) {
|
|
91
|
+
return {
|
|
92
|
+
supported: async () => {
|
|
93
|
+
if (options.confirmed()) return true;
|
|
94
|
+
if (!options.fetch || !options.token) return false;
|
|
95
|
+
try {
|
|
96
|
+
const fields = (await siteFeatures(options.fetch, options.token))?.fields ?? 0;
|
|
97
|
+
if (fields < FIELDS_FEATURE_VERSION) {
|
|
98
|
+
options.log?.("site Worker does not read reference and repeater fields yet");
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
options.remember();
|
|
102
|
+
return true;
|
|
103
|
+
} catch (e) {
|
|
104
|
+
options.log?.(`features check failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
package/dist/src/scheduler.d.ts
CHANGED
|
@@ -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
|
/**
|
package/dist/src/scheduler.js
CHANGED
|
@@ -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.
|
|
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.
|
|
52
|
-
"@cloudhal/analytics": "0.
|
|
53
|
-
"@cloudhal/api": "0.
|
|
54
|
-
"@cloudhal/comments": "0.
|
|
55
|
-
"@cloudhal/core-ts": "0.
|
|
56
|
-
"@cloudhal/mcp-server": "0.
|
|
57
|
-
"@cloudhal/schedules": "0.
|
|
58
|
-
"@cloudhal/storage": "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.
|
|
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",
|