@cloudhal/cloudflare 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.
@@ -0,0 +1,24 @@
1
+ /**
2
+ * What the site Worker enforces, asked over the `SITE` binding (RFC-0008 §7.6–§7.7). An older site
3
+ * Worker ignores time gates and would show embargoed content, so the admin Worker lets nobody
4
+ * write `availability` (REST, MCP, bundle import) until the site Worker answers
5
+ * `GET /__cloudhal/features` with `{ "gates": 1 }` or more (invariant S15).
6
+ */
7
+ import { type GateSupport } from "@cloudhal/core-ts/availability";
8
+ import type { SiteFetch } from "./purge.js";
9
+ /** The features the site Worker reports, or `undefined` when it does not answer (older Workers). */
10
+ export declare function siteFeatures(fetch: SiteFetch, token: string): Promise<{
11
+ gates?: number;
12
+ } | undefined>;
13
+ /**
14
+ * The store's gate capability for one admin Worker isolate. A confirmation is remembered as a
15
+ * plain value (`remember`/`confirmed`, nothing awaited across requests, ADR-0012); a refusal or an
16
+ * error is asked again on the next write that sets gates, so deploying the site Worker is enough.
17
+ */
18
+ export declare function siteGateSupport(options: {
19
+ readonly fetch: SiteFetch | undefined;
20
+ readonly token: string | undefined;
21
+ readonly confirmed: () => boolean;
22
+ readonly remember: () => void;
23
+ readonly log?: (line: string) => void;
24
+ }): GateSupport;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * What the site Worker enforces, asked over the `SITE` binding (RFC-0008 §7.6–§7.7). An older site
3
+ * Worker ignores time gates and would show embargoed content, so the admin Worker lets nobody
4
+ * write `availability` (REST, MCP, bundle import) until the site Worker answers
5
+ * `GET /__cloudhal/features` with `{ "gates": 1 }` or more (invariant S15).
6
+ */
7
+ import { GATES_FEATURE_VERSION, } from "@cloudhal/core-ts/availability";
8
+
9
+
10
+ const FEATURES_URL = "https://site.internal/__cloudhal/features";
11
+
12
+ /** The features the site Worker reports, or `undefined` when it does not answer (older Workers). */
13
+ export async function siteFeatures(
14
+ fetch ,
15
+ token ,
16
+ ) {
17
+ const res = await fetch(FEATURES_URL, {
18
+ method: "GET",
19
+ headers: { authorization: `Bearer ${token}` },
20
+ });
21
+ if (!res.ok) {
22
+ await res.body?.cancel();
23
+ return undefined;
24
+ }
25
+ const body = (await res.json().catch(() => undefined)) ;
26
+ return typeof body?.gates === "number" ? { gates: body.gates } : {};
27
+ }
28
+
29
+ /**
30
+ * The store's gate capability for one admin Worker isolate. A confirmation is remembered as a
31
+ * plain value (`remember`/`confirmed`, nothing awaited across requests, ADR-0012); a refusal or an
32
+ * error is asked again on the next write that sets gates, so deploying the site Worker is enough.
33
+ */
34
+ export function siteGateSupport(options
35
+
36
+
37
+
38
+
39
+
40
+ ) {
41
+ return {
42
+ enforced: async () => {
43
+ if (options.confirmed()) return true;
44
+ if (!options.fetch || !options.token) return false;
45
+ try {
46
+ const features = await siteFeatures(options.fetch, options.token);
47
+ if ((features?.gates ?? 0) < GATES_FEATURE_VERSION) {
48
+ options.log?.("site Worker does not enforce time gates yet: availability is refused");
49
+ return false;
50
+ }
51
+ options.remember();
52
+ return true;
53
+ } catch (e) {
54
+ options.log?.(`features check failed: ${e instanceof Error ? e.message : String(e)}`);
55
+ return false;
56
+ }
57
+ },
58
+ };
59
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Email delivery through the Cloudflare Email Service `send_email` binding (RFC-0011, ADR-0025).
3
+ * `cloudhal deploy` binds it as `EMAIL`, locked to one sender (`allowed_sender_addresses`), and sets
4
+ * `CLOUDHAL_MAIL_FROM` / `CLOUDHAL_MAIL_FROM_NAME`. Plain text only; bodies are never logged (they
5
+ * carry one-time links).
6
+ */
7
+ import { type MailSender } from "@cloudhal/api";
8
+ /** The part of the binding's structured `send()` this sender uses. */
9
+ export interface SendEmailBinding {
10
+ send(message: {
11
+ to: string;
12
+ from: {
13
+ email: string;
14
+ name?: string;
15
+ };
16
+ subject: string;
17
+ text: string;
18
+ html?: string;
19
+ headers?: Record<string, string>;
20
+ }): Promise<{
21
+ messageId: string;
22
+ }>;
23
+ }
24
+ export interface MailEnv {
25
+ EMAIL?: SendEmailBinding;
26
+ /** The configured sender address (`mail.from` in cloudhal.json). */
27
+ CLOUDHAL_MAIL_FROM?: string;
28
+ CLOUDHAL_MAIL_FROM_NAME?: string;
29
+ }
30
+ /** A plain `local@domain` address: no display name, no spaces or line breaks. */
31
+ export declare const MAIL_ADDRESS: RegExp;
32
+ export declare function cloudflareEmailSender(binding: SendEmailBinding, from: {
33
+ email: string;
34
+ name?: string;
35
+ }): MailSender;
36
+ /** The deployment's sender, when the binding and a valid `CLOUDHAL_MAIL_FROM` are both there. */
37
+ export declare function adminMail(env: MailEnv): MailSender | undefined;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Email delivery through the Cloudflare Email Service `send_email` binding (RFC-0011, ADR-0025).
3
+ * `cloudhal deploy` binds it as `EMAIL`, locked to one sender (`allowed_sender_addresses`), and sets
4
+ * `CLOUDHAL_MAIL_FROM` / `CLOUDHAL_MAIL_FROM_NAME`. Plain text only; bodies are never logged (they
5
+ * carry one-time links).
6
+ */
7
+ import { MailError, } from "@cloudhal/api";
8
+
9
+ /** The part of the binding's structured `send()` this sender uses. */
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+ /** A plain `local@domain` address: no display name, no spaces or line breaks. */
29
+ export const MAIL_ADDRESS = /^[^\s@<>"]+@[^\s@<>"]+\.[^\s@<>"]+$/;
30
+
31
+ const oneLine = (s ) => s.replace(/[\r\n]+/g, " ").trim();
32
+
33
+ export function cloudflareEmailSender(
34
+ binding ,
35
+ from ,
36
+ ) {
37
+ const sender = {
38
+ email: from.email,
39
+ ...(from.name && oneLine(from.name) ? { name: oneLine(from.name) } : {}),
40
+ };
41
+ return {
42
+ id: "cloudflare-email",
43
+ async send(message ) {
44
+ try {
45
+ await binding.send({
46
+ to: message.to,
47
+ from: sender,
48
+ subject: oneLine(message.subject),
49
+ text: message.text,
50
+ ...(message.html ? { html: message.html } : {}),
51
+ // RFC 3834: auto-responders must not answer.
52
+ headers: { "Auto-Submitted": "auto-generated" },
53
+ });
54
+ } catch (e) {
55
+ throw MailError.from(e);
56
+ }
57
+ },
58
+ };
59
+ }
60
+
61
+ /** The deployment's sender, when the binding and a valid `CLOUDHAL_MAIL_FROM` are both there. */
62
+ export function adminMail(env ) {
63
+ const from = env.CLOUDHAL_MAIL_FROM?.trim();
64
+ if (!env.EMAIL || !from || !MAIL_ADDRESS.test(from)) return undefined;
65
+ return cloudflareEmailSender(env.EMAIL, {
66
+ email: from,
67
+ ...(env.CLOUDHAL_MAIL_FROM_NAME ? { name: env.CLOUDHAL_MAIL_FROM_NAME } : {}),
68
+ });
69
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Purging the site Worker's edge cache after a publish or rollback (ADR-0012, RFC-0002 §7).
3
+ *
4
+ * The admin Worker cannot purge the site Worker's cache itself (purges are scoped to the Worker
5
+ * that cached), so it calls the site Worker's `POST /__cloudhal/purge` over the `SITE` service
6
+ * binding. Which tags: `SiteGraphStore.planCachePurge`, from the diff between the snapshot that was
7
+ * live and the new one — an edited article purges that article and the lists it appears on, not
8
+ * the whole site. Everything is purged when the plan says so (first publish, diff unavailable or
9
+ * too large) or when a tag purge fails.
10
+ */
11
+ import type { CachePurgePlan, PublishChange } from "@cloudhal/core-ts";
12
+ /**
13
+ * Tags per purge request: Cloudflare accepts at most 100 tags in one purge, and Workers Cache
14
+ * always uses the Free-tier purge limits (5 requests per minute, bursts of 25):
15
+ * https://developers.cloudflare.com/cache/how-to/purge-cache/#hostname-tag-prefix-url-and-purge-everything-limits
16
+ * https://developers.cloudflare.com/workers/cache/purge/
17
+ */
18
+ export declare const PURGE_TAGS_PER_REQUEST = 100;
19
+ /**
20
+ * Requests one publish may spend on tag purges. Beyond that one "purge everything" request is
21
+ * cheaper on the rate limit than many tag requests, so the plan falls back to it.
22
+ */
23
+ export declare const PURGE_MAX_REQUESTS = 3;
24
+ /** `fetch` of the site Worker (the `SITE` service binding in production). */
25
+ export type SiteFetch = (url: string, init: RequestInit) => Promise<Response>;
26
+ export interface PurgeSiteCacheOptions {
27
+ readonly fetch: SiteFetch;
28
+ /** The shared `CLOUDHAL_PURGE_TOKEN`. */
29
+ readonly token: string;
30
+ readonly store: {
31
+ planCachePurge(change: PublishChange, options?: {
32
+ maxTags?: number;
33
+ maxReads?: number;
34
+ }): Promise<CachePurgePlan>;
35
+ };
36
+ readonly change: PublishChange;
37
+ /**
38
+ * RFC-0034 §4: the site whose publish this is. A multi-site Worker then purges only that site's
39
+ * tags, even for "everything"; a single-site Worker ignores it.
40
+ */
41
+ readonly siteId?: string;
42
+ readonly log?: (line: string) => void;
43
+ /**
44
+ * Called once per purge request sent, whatever its answer (RFC-0007 §8.4: publishes and comment
45
+ * purges share one budget, recorded in `cache_purge_log`).
46
+ */
47
+ readonly onRequest?: () => Promise<void> | void;
48
+ }
49
+ export interface PurgeSiteCacheResult {
50
+ /** `tags`: only these tags were purged; `everything`: the whole cache; `none`: nothing changed. */
51
+ readonly mode: "tags" | "everything" | "none";
52
+ readonly tags: readonly string[];
53
+ readonly requests: number;
54
+ /** Why everything was purged, when it was. */
55
+ readonly reason?: string;
56
+ }
57
+ /** Purges what a publish changed, in batches the site Worker and Cloudflare accept. */
58
+ export declare function purgeSiteCache(o: PurgeSiteCacheOptions): Promise<PurgeSiteCacheResult>;
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Purging the site Worker's edge cache after a publish or rollback (ADR-0012, RFC-0002 §7).
3
+ *
4
+ * The admin Worker cannot purge the site Worker's cache itself (purges are scoped to the Worker
5
+ * that cached), so it calls the site Worker's `POST /__cloudhal/purge` over the `SITE` service
6
+ * binding. Which tags: `SiteGraphStore.planCachePurge`, from the diff between the snapshot that was
7
+ * live and the new one — an edited article purges that article and the lists it appears on, not
8
+ * the whole site. Everything is purged when the plan says so (first publish, diff unavailable or
9
+ * too large) or when a tag purge fails.
10
+ */
11
+
12
+
13
+ /**
14
+ * Tags per purge request: Cloudflare accepts at most 100 tags in one purge, and Workers Cache
15
+ * always uses the Free-tier purge limits (5 requests per minute, bursts of 25):
16
+ * https://developers.cloudflare.com/cache/how-to/purge-cache/#hostname-tag-prefix-url-and-purge-everything-limits
17
+ * https://developers.cloudflare.com/workers/cache/purge/
18
+ */
19
+ export const PURGE_TAGS_PER_REQUEST = 100;
20
+ /**
21
+ * Requests one publish may spend on tag purges. Beyond that one "purge everything" request is
22
+ * cheaper on the rate limit than many tag requests, so the plan falls back to it.
23
+ */
24
+ export const PURGE_MAX_REQUESTS = 3;
25
+
26
+ /** `fetch` of the site Worker (the `SITE` service binding in production). */
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+  
42
+
43
+
44
+
45
+
46
+
47
+  
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+ const PURGE_URL = "https://site.internal/__cloudhal/purge";
63
+
64
+ const summary = (why ) =>
65
+ why.length > 3 ? `${why.slice(0, 3).join("; ")}; +${why.length - 3} more` : why.join("; ");
66
+
67
+ /** Purges what a publish changed, in batches the site Worker and Cloudflare accept. */
68
+ export async function purgeSiteCache(o ) {
69
+ const log = o.log ?? (() => {});
70
+ const auth = { authorization: `Bearer ${o.token}` };
71
+ let requests = 0;
72
+ const sentOne = async () => {
73
+ requests++;
74
+ await o.onRequest?.();
75
+ };
76
+ const everything = async (reason ) => {
77
+ await sentOne();
78
+ const res = await o.fetch(PURGE_URL, {
79
+ method: "POST",
80
+ headers: o.siteId ? { ...auth, "content-type": "application/json" } : auth,
81
+ ...(o.siteId ? { body: JSON.stringify({ siteId: o.siteId }) } : {}),
82
+ });
83
+ log(`purge everything (${reason}): ${res.status} ${await res.text()}`);
84
+ if (!res.ok) throw new Error(`purge everything failed: ${res.status}`);
85
+ return { mode: "everything", tags: [], requests, reason };
86
+ };
87
+
88
+ const plan = await o.store.planCachePurge(o.change, {
89
+ maxTags: PURGE_TAGS_PER_REQUEST * PURGE_MAX_REQUESTS,
90
+ });
91
+ if (plan.mode === "everything") return everything(plan.reason);
92
+ if (plan.tags.length === 0) {
93
+ log("purge: the new snapshot renders the same site; nothing to purge");
94
+ return { mode: "none", tags: [], requests: 0 };
95
+ }
96
+ for (let i = 0; i < plan.tags.length; i += PURGE_TAGS_PER_REQUEST) {
97
+ const batch = plan.tags.slice(i, i + PURGE_TAGS_PER_REQUEST);
98
+ await sentOne();
99
+ const res = await o.fetch(PURGE_URL, {
100
+ method: "POST",
101
+ headers: { ...auth, "content-type": "application/json" },
102
+ body: JSON.stringify({ tags: batch, ...(o.siteId ? { siteId: o.siteId } : {}) }),
103
+ });
104
+ log(`purge ${batch.length} tag(s) (${summary(plan.why)}): ${res.status} ${await res.text()}`);
105
+ // A partial tag purge would leave stale pages behind: purge everything instead.
106
+ if (!res.ok) return everything(`tag purge failed with ${res.status}`);
107
+ }
108
+ return { mode: "tags", tags: plan.tags, requests };
109
+ }
@@ -0,0 +1,149 @@
1
+ import { type AiSearchEnv } from "@cloudhal/core-ts";
2
+ import { type BuiltinInputs, type NotFoundAnalytics } from "@cloudhal/core-ts/automations";
3
+ import { type ReleasePurger, type SchedulerRuntime } from "@cloudhal/core-ts/releases";
4
+ import { type SystemJobDefinition, type TickBudget, type TickReport, type TickTrigger } from "@cloudhal/schedules";
5
+ import type { SqlDriver } from "@cloudhal/storage";
6
+ /** What the scheduler reads from the admin Worker's environment. */
7
+ export interface SchedulerEnv extends AiSearchEnv {
8
+ DB: D1Database;
9
+ BLOBS: R2Bucket;
10
+ SITE?: Fetcher;
11
+ CLOUDHAL_PURGE_TOKEN?: string;
12
+ /** The `SchedulerClock` Durable Object namespace (declared by every deploy, §8.3). */
13
+ SCHEDULER_CLOCK?: DurableObjectNamespace;
14
+ /** `cron` (default) or `alarm` (`cloudhal deploy` sets it when the cron trigger was refused). */
15
+ CLOUDHAL_SCHEDULER?: string;
16
+ /** `paid` lifts the per-tick budget to Workers Paid's (§8.2); default `free`. */
17
+ CLOUDHAL_TICK_BUDGET?: string;
18
+ /** The site the site Worker serves (the feed check fetches only that site's feed). */
19
+ CLOUDHAL_SITE_ID?: string;
20
+ /** RFC-0034 §4: the sites a multi-site site Worker serves, by hostname. */
21
+ CLOUDHAL_SITE_IDS?: string;
22
+ /** RFC-0034 §4: `{siteId: binding}` for sites served by attached site Workers (`site-routes.ts`). */
23
+ CLOUDHAL_SITE_ROUTES?: string;
24
+ /** `off`: automations stop; releases and gates are unaffected (§11.6). */
25
+ CLOUDHAL_AUTOMATIONS?: string;
26
+ /** Legacy (before RFC-0008): `off` meant "no cron slot", read as `alarm`. */
27
+ CLOUDHAL_ANALYTICS_CRON?: string;
28
+ /** Legacy (before RFC-0008): `off` meant "no cron slot", read as `alarm`. */
29
+ CLOUDHAL_COMMENTS_CRON?: string;
30
+ }
31
+ /** The clock's one instance (`getByName("clock")`, §8.3). */
32
+ export declare const CLOCK_NAME = "clock";
33
+ /** `CLOUDHAL_SCHEDULER`, else the legacy `*_CRON=off` vars as `alarm`, else `cron`. */
34
+ export declare function schedulerMode(env: SchedulerEnv): "cron" | "alarm";
35
+ /** The per-tick budget: Workers Free unless the deployment says it is on Paid. */
36
+ export declare function tickBudget(env: SchedulerEnv): TickBudget;
37
+ /** Moves the clock's alarm to `at` when that is sooner (or arms a lost one). Never throws. */
38
+ export declare function pokeClock(env: SchedulerEnv, at: string | number, log?: (line: string) => void): Promise<void>;
39
+ /** The ticker as the API sees it (`ApiDeps.scheduler`): alarm mode pokes the clock. */
40
+ export declare function schedulerRuntime(env: SchedulerEnv, log?: (line: string) => void): SchedulerRuntime;
41
+ /**
42
+ * Sends a published release's stored purge plan through the site Worker (≤ 3 tag requests, else
43
+ * one "purge everything"), each request logged in `cache_purge_log` (source `schedules`). A failed
44
+ * request (`success: false` is a 502 from the site Worker: the bucket is empty) puts what is left
45
+ * into the purge queue and answers `deferred`; `wake` asks for a flush once the tags are ripe.
46
+ */
47
+ export declare function releasePurger(env: SchedulerEnv, sql: SqlDriver, o?: {
48
+ log?: (line: string) => void;
49
+ wake?: (siteId: string) => void;
50
+ }): ReleasePurger;
51
+ /** What the analytics rollup needs (the admin Worker passes `adminAnalytics`). */
52
+ export type AnalyticsRollup = (sql: SqlDriver, now: Date) => {
53
+ rollup(o: {
54
+ siteIds: string[];
55
+ }): Promise<{
56
+ readonly done: readonly unknown[];
57
+ readonly pending: number;
58
+ readonly saltsDeleted: number;
59
+ readonly retained: number;
60
+ readonly failed: readonly {
61
+ siteId: string;
62
+ day: string;
63
+ error: string;
64
+ }[];
65
+ }>;
66
+ feature(): {
67
+ reader: string;
68
+ enabled?: boolean;
69
+ };
70
+ /** Analytics' `renders` report (the broken-link sweep's 404 rows, RFC-0008 §11.1). */
71
+ query?: NotFoundAnalytics["query"];
72
+ };
73
+ /**
74
+ * The deployment's periodic jobs (§8.2): today's hourly code behind watermarks, with today's log
75
+ * lines; `comments.hourly` only where comments are on.
76
+ */
77
+ export declare function adminSystemJobs(env: SchedulerEnv, sql: SqlDriver, o: {
78
+ analytics: AnalyticsRollup;
79
+ commentsOn: boolean;
80
+ log: (line: string) => void;
81
+ }): SystemJobDefinition[];
82
+ /**
83
+ * Fetches the site's own `/rss.xml` or `/sitemap.xml` through the `SITE` binding, as readers get
84
+ * them (RFC-0008 §11.1 `feed-check`). For a site the site Worker does not serve the answer is
85
+ * undefined (not served from here).
86
+ */
87
+ export declare function siteDocumentFetcher(env: SchedulerEnv): NonNullable<BuiltinInputs["fetchDocument"]> | undefined;
88
+ /** What the admin Worker adds for the built-in jobs: analytics' 404 rows and the feed fetcher. */
89
+ export declare function adminBuiltinInputs(env: SchedulerEnv, analytics: ReturnType<AnalyticsRollup> | undefined): BuiltinInputs;
90
+ export interface AdminTickOptions {
91
+ readonly trigger: TickTrigger;
92
+ readonly now: Date;
93
+ readonly log: (line: string) => void;
94
+ readonly analytics: AnalyticsRollup;
95
+ readonly commentsOn: boolean;
96
+ /** Keeps a deferred purge's flush alive after the tick (the handler's `waitUntil`). */
97
+ readonly waitUntil?: ((p: Promise<unknown>) => void) | undefined;
98
+ }
99
+ /** One tick of the admin Worker (cron, alarm, request backstop or the operator's run-due). */
100
+ export declare function runAdminTick(env: SchedulerEnv, o: AdminTickOptions): Promise<TickReport>;
101
+ /**
102
+ * A cron tick's follow-up (RFC-0008 §8.2): Cloudflare fires `* * * * *` at a fixed second of each
103
+ * minute for a Worker (measured live: :54), so work due a few seconds after a tick would wait for
104
+ * the next one, almost a minute late. When something is due within the next minute, the handler
105
+ * waits until then (no CPU is used while waiting) and runs one more tick, so releases go live at
106
+ * their minute. Returns the wait in ms, or undefined when nothing is due before the next tick.
107
+ */
108
+ export declare function followUpDelay(report: TickReport | undefined, now: number): number | undefined;
109
+ /** Isolate-local state of the request backstop: plain numbers only (ADR-0012). */
110
+ export interface BackstopState {
111
+ lastCheck: number;
112
+ lastRun: number;
113
+ }
114
+ /** How often an isolate reads the heartbeat, and runs at most one backstop tick (§8.6). */
115
+ export declare const BACKSTOP_EVERY_MS = 60000;
116
+ /**
117
+ * The request backstop (§8.6): at most once a minute per isolate, read the heartbeat; if it is
118
+ * more than two minutes behind, run a tick (`request`) — and in alarm mode re-arm the clock.
119
+ * Returns the promise for `waitUntil`, or undefined when nothing is to be done.
120
+ */
121
+ export declare function requestBackstop(env: SchedulerEnv, state: BackstopState, o: Omit<AdminTickOptions, "trigger" | "now"> & {
122
+ now?: () => number;
123
+ }): Promise<void> | undefined;
124
+ /**
125
+ * How the clock re-arms after a tick (§8.3): `now + 1 s` while there is more, else the next wake,
126
+ * at most an hour away (a safety alarm), never in the past.
127
+ */
128
+ export declare function nextAlarm(report: TickReport | undefined, now: number): number;
129
+ /**
130
+ * Builds the `SchedulerClock` Durable Object class (SQLite-backed, one instance named "clock").
131
+ * `tick` runs one admin tick; the admin Worker module passes its own (migrations, analytics,
132
+ * comments). Kept as a factory so the class needs no `cloudflare:workers` import and its logic is
133
+ * testable on Node.
134
+ */
135
+ export declare function schedulerClockClass(tick: (env: SchedulerEnv, o: {
136
+ now: Date;
137
+ waitUntil: (p: Promise<unknown>) => void;
138
+ }) => Promise<TickReport>, log?: (line: string) => void): {
139
+ new (state: DurableObjectState, env: SchedulerEnv): {
140
+ readonly state: DurableObjectState;
141
+ readonly env: SchedulerEnv;
142
+ /** `POST /poke {at}` moves the alarm earlier (or arms it); `GET /alarm` reads it. */
143
+ fetch(request: Request): Promise<Response>;
144
+ /** Moves the alarm to `at` when that is sooner than the armed one (never into the past). */
145
+ poke(at: number): Promise<number>;
146
+ /** Runs a tick and always re-arms; never throws (a thrown alarm is retried only six times). */
147
+ alarm(): Promise<void>;
148
+ };
149
+ };