fixup! diigo-cache: the caches take their clock as a constructor argument

Past the transitional idiom: the cache logic (DiigoCacheLogic,
PublicCacheLogic in cache.ts) requires its Clock, with no default, so
cache.ts reaches no ambient time. The worker's entry module is the
edge: it makes the live clock and exports the runtime-constructed
DiigoCache/PublicCache as (ctx, env) subclasses that supply it (the
Cloudflare constraint: the runtime constructs DOs with ctx and env
only). Binding class names are unchanged, so stored state is too. The
tests' FixedClockCache extends the logic class.

Generated-by: Claude Opus 5.5
This commit is contained in:
dckc committed 2026-10-07 04:39:29 -05:00
1 parent cf901ded5f
commit 961515d8db
6 files changed
+53 -31

No files matched your search

+28 -5
View File
@@ -17,16 +17,39 @@ import { newWorkersRpcResponse } from "capnweb";
import { CacheApi } from "./api.js";
import { CAPNWEB_BROWSER_JS } from "./capnweb-browser.js";
import { CACHE_PAGE_HTML } from "./cache-page.js";
import { DiigoCache, PublicCache } from "./cache.js";
import type { FillStatus } from "./cache.js";
import { DiigoCacheLogic, PublicCacheLogic } from "./cache.js";
import type { CacheEnv, Clock, FillStatus } from "./cache.js";
import type { Item } from "./cache.js";
import { updatedISO, usernameOf } from "./items.js";
import { toWebkey, idFromWebkey, isWebkey, shashKey } from "./webkeys.js";
import { pmSave } from "./pm-save.js";
// the DO classes must be entrypoint exports (the exports/ binding targets
// the main module)
export { DiigoCache, PublicCache };
/**
* the live clock. This module is the worker's edge — the runtime's entry,
* like a program script — so ambient time is reached here and delegated
* down; the cache logic only uses the clock it is given.
*/
function liveClock(): Clock {
return { now: () => Date.now(), sleep: (ms) => new Promise((r) => setTimeout(r, ms)) };
}
// The DO classes must be exports of the main module, and the runtime
// constructs them with (ctx, env) only: a Cloudflare API constraint, met
// here at the edge by subclasses that supply the live clock.
/** the private cache, as the runtime constructs it */
export class DiigoCache extends DiigoCacheLogic {
constructor(ctx: DurableObjectState, env: CacheEnv) {
super(ctx, env, liveClock());
}
}
/** the public cache, as the runtime constructs it */
export class PublicCache extends PublicCacheLogic {
constructor(ctx: DurableObjectState, env: CacheEnv) {
super(ctx, env, liveClock());
}
}
/** worker bindings (structural until wrangler types regenerates) */
type Env = {