@orthograph/host-cloudflare 0.0.0-stage → 0.1.0-next.2
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/LICENSE +202 -0
- package/README.md +2 -2
- package/dist/index.d.ts +21 -0
- package/dist/index.js +12 -0
- package/dist/modules/actors/internal/tables.d.ts +1 -0
- package/dist/modules/actors/internal/tables.js +5 -0
- package/dist/modules/actors/service.d.ts +18 -0
- package/dist/modules/actors/service.js +51 -0
- package/dist/modules/actors/types.d.ts +35 -0
- package/dist/modules/actors/types.js +1 -0
- package/dist/modules/auth/internal/instance.d.ts +4462 -0
- package/dist/modules/auth/internal/instance.js +36 -0
- package/dist/modules/auth/internal/oauth.d.ts +20 -0
- package/dist/modules/auth/internal/oauth.js +70 -0
- package/dist/modules/auth/internal/options.d.ts +4886 -0
- package/dist/modules/auth/internal/options.js +75 -0
- package/dist/modules/auth/internal/schema.d.ts +2 -0
- package/dist/modules/auth/internal/schema.js +41 -0
- package/dist/modules/auth/internal/world-token.d.ts +15 -0
- package/dist/modules/auth/internal/world-token.js +40 -0
- package/dist/modules/auth/service.d.ts +9 -0
- package/dist/modules/auth/service.js +96 -0
- package/dist/modules/auth/types.d.ts +75 -0
- package/dist/modules/auth/types.js +1 -0
- package/dist/modules/clock/internal/date.d.ts +17 -0
- package/dist/modules/clock/internal/date.js +45 -0
- package/dist/modules/clock/internal/door.d.ts +2 -0
- package/dist/modules/clock/internal/door.js +49 -0
- package/dist/modules/clock/internal/state.d.ts +5 -0
- package/dist/modules/clock/internal/state.js +78 -0
- package/dist/modules/clock/service.d.ts +2 -0
- package/dist/modules/clock/service.js +36 -0
- package/dist/modules/clock/types.d.ts +152 -0
- package/dist/modules/clock/types.js +1 -0
- package/dist/modules/database/service.d.ts +2 -0
- package/dist/modules/database/service.js +6 -0
- package/dist/modules/database/types.d.ts +7 -0
- package/dist/modules/database/types.js +1 -0
- package/dist/modules/follower/internal/entries.d.ts +9 -0
- package/dist/modules/follower/internal/entries.js +20 -0
- package/dist/modules/follower/internal/health.d.ts +18 -0
- package/dist/modules/follower/internal/health.js +27 -0
- package/dist/modules/follower/internal/outbox.d.ts +26 -0
- package/dist/modules/follower/internal/outbox.js +35 -0
- package/dist/modules/follower/internal/poll.d.ts +21 -0
- package/dist/modules/follower/internal/poll.js +23 -0
- package/dist/modules/follower/service.d.ts +31 -0
- package/dist/modules/follower/service.js +87 -0
- package/dist/modules/follower/types.d.ts +71 -0
- package/dist/modules/follower/types.js +4 -0
- package/dist/modules/inbound/internal/accept.d.ts +26 -0
- package/dist/modules/inbound/internal/accept.js +10 -0
- package/dist/modules/inbound/internal/read.d.ts +10 -0
- package/dist/modules/inbound/internal/read.js +26 -0
- package/dist/modules/inbound/internal/same.d.ts +1 -0
- package/dist/modules/inbound/internal/same.js +12 -0
- package/dist/modules/inbound/internal/verify.d.ts +6 -0
- package/dist/modules/inbound/internal/verify.js +57 -0
- package/dist/modules/inbound/service.d.ts +2 -0
- package/dist/modules/inbound/service.js +110 -0
- package/dist/modules/inbound/types.d.ts +28 -0
- package/dist/modules/inbound/types.js +1 -0
- package/dist/modules/journal/service.d.ts +2 -0
- package/dist/modules/journal/service.js +23 -0
- package/dist/modules/journal/types.d.ts +8 -0
- package/dist/modules/journal/types.js +1 -0
- package/dist/modules/relayer/internal/adopt.d.ts +19 -0
- package/dist/modules/relayer/internal/adopt.js +34 -0
- package/dist/modules/relayer/internal/check.d.ts +16 -0
- package/dist/modules/relayer/internal/check.js +141 -0
- package/dist/modules/relayer/internal/health.d.ts +5 -0
- package/dist/modules/relayer/internal/health.js +7 -0
- package/dist/modules/relayer/internal/live.d.ts +26 -0
- package/dist/modules/relayer/internal/live.js +25 -0
- package/dist/modules/relayer/internal/relay.d.ts +22 -0
- package/dist/modules/relayer/internal/relay.js +44 -0
- package/dist/modules/relayer/internal/store.d.ts +41 -0
- package/dist/modules/relayer/internal/store.js +44 -0
- package/dist/modules/relayer/service.d.ts +58 -0
- package/dist/modules/relayer/service.js +124 -0
- package/dist/modules/relayer/types.d.ts +75 -0
- package/dist/modules/relayer/types.js +1 -0
- package/dist/modules/store/internal/actors.d.ts +6 -0
- package/dist/modules/store/internal/actors.js +24 -0
- package/dist/modules/store/internal/commit.d.ts +10 -0
- package/dist/modules/store/internal/commit.js +57 -0
- package/dist/modules/store/internal/list.d.ts +10 -0
- package/dist/modules/store/internal/list.js +28 -0
- package/dist/modules/store/internal/rows.d.ts +14 -0
- package/dist/modules/store/internal/rows.js +29 -0
- package/dist/modules/store/internal/unique.d.ts +3 -0
- package/dist/modules/store/internal/unique.js +17 -0
- package/dist/modules/store/service.d.ts +2 -0
- package/dist/modules/store/service.js +71 -0
- package/dist/modules/store/types.d.ts +36 -0
- package/dist/modules/store/types.js +1 -0
- package/dist/modules/telemetry/internal/exporters.d.ts +21 -0
- package/dist/modules/telemetry/internal/exporters.js +66 -0
- package/dist/modules/telemetry/service.d.ts +2 -0
- package/dist/modules/telemetry/service.js +52 -0
- package/dist/modules/telemetry/types.d.ts +36 -0
- package/dist/modules/telemetry/types.js +1 -0
- package/dist/modules/timers/internal/controller.d.ts +13 -0
- package/dist/modules/timers/internal/controller.js +63 -0
- package/dist/modules/timers/internal/count.d.ts +39 -0
- package/dist/modules/timers/internal/count.js +105 -0
- package/dist/modules/timers/internal/limits.d.ts +4 -0
- package/dist/modules/timers/internal/limits.js +8 -0
- package/dist/modules/timers/internal/table.d.ts +52 -0
- package/dist/modules/timers/internal/table.js +181 -0
- package/dist/modules/timers/service.d.ts +12 -0
- package/dist/modules/timers/service.js +136 -0
- package/dist/modules/timers/types.d.ts +82 -0
- package/dist/modules/timers/types.js +1 -0
- package/dist/modules/world/internal/entry.d.ts +34 -0
- package/dist/modules/world/internal/entry.js +69 -0
- package/dist/modules/world/internal/facts.d.ts +5 -0
- package/dist/modules/world/internal/facts.js +31 -0
- package/dist/modules/world/internal/fence.d.ts +9 -0
- package/dist/modules/world/internal/fence.js +90 -0
- package/dist/modules/world/internal/front-door.d.ts +5 -0
- package/dist/modules/world/internal/front-door.js +50 -0
- package/dist/modules/world/internal/leases.d.ts +33 -0
- package/dist/modules/world/internal/leases.js +79 -0
- package/dist/modules/world/internal/reset.d.ts +6 -0
- package/dist/modules/world/internal/reset.js +24 -0
- package/dist/modules/world/internal/work.d.ts +11 -0
- package/dist/modules/world/internal/work.js +73 -0
- package/dist/modules/world/internal/worlds.d.ts +7 -0
- package/dist/modules/world/internal/worlds.js +48 -0
- package/dist/modules/world/service.d.ts +80 -0
- package/dist/modules/world/service.js +209 -0
- package/dist/modules/world/types.d.ts +47 -0
- package/dist/modules/world/types.js +1 -0
- package/package.json +46 -3
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { DurableObject } from "cloudflare:workers";
|
|
2
|
+
import { Clock, Effect } from "effect";
|
|
3
|
+
import { frontDoor, RESET_HEADER } from "./internal/front-door.js";
|
|
4
|
+
import { AuthD1 } from "#modules/auth/service.js";
|
|
5
|
+
import { WorldClock } from "#modules/clock/service.js";
|
|
6
|
+
import { WorldTimers } from "#modules/timers/service.js";
|
|
7
|
+
import { entry, within, withinNow } from "./internal/entry.js";
|
|
8
|
+
import { facts } from "./internal/facts.js";
|
|
9
|
+
import { end, live } from "./internal/leases.js";
|
|
10
|
+
import { resetDatabases } from "./internal/reset.js";
|
|
11
|
+
import { worldsDoor } from "./internal/worlds.js";
|
|
12
|
+
import { fenced, section } from "./internal/fence.js";
|
|
13
|
+
import { work } from "./internal/work.js";
|
|
14
|
+
const json = (body, status = 200) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
15
|
+
/**
|
|
16
|
+
* The world's Durable Object. Export it from the Worker's entry; bind it as `WORLD`. In a long-lived environment each
|
|
17
|
+
* world is its own instance, named by the world's id: it holds the cast, and an alarm at the world's expiry that
|
|
18
|
+
* destroys it (D3 #7, #50). Under `ortho dev` and a local prove there is the one, named `world`, and no alarm.
|
|
19
|
+
*/
|
|
20
|
+
export class World extends DurableObject {
|
|
21
|
+
auth;
|
|
22
|
+
/** The world's instant (M8.06): the wall clock, or the one it keeps in its own storage. */
|
|
23
|
+
clock;
|
|
24
|
+
/** The world's timer table and count of work in flight (M8.07). */
|
|
25
|
+
timers;
|
|
26
|
+
constructor(ctx, env) {
|
|
27
|
+
super(ctx, env);
|
|
28
|
+
this.clock = WorldClock.state(ctx.storage.sql, WorldClock.declared(env));
|
|
29
|
+
const kinds = this.wakeKinds();
|
|
30
|
+
// A due durable row is woken by its kind's code, here in the world's own isolate and in the world's time (fresh source).
|
|
31
|
+
const wakes = kinds === undefined ? undefined : WorldTimers.route(kinds);
|
|
32
|
+
this.timers = WorldTimers.state({
|
|
33
|
+
sql: ctx.storage.sql, clock: this.clock, env, changed: () => { if (this.clock.kind === "real")
|
|
34
|
+
void this.schedule(); },
|
|
35
|
+
// The wake runs in a runtime of its own (`runPromise`), so the abort must cross: interrupting this fiber (a reset, the bound) aborts
|
|
36
|
+
// `signal`, which interrupts the inner one, and a wake that was ended performs no write afterwards.
|
|
37
|
+
...(wakes === undefined ? {} : { wakes: (timer) => Effect.promise((signal) => this.inTime(() => Effect.runPromise(wakes(timer), { signal }))) }),
|
|
38
|
+
});
|
|
39
|
+
// A wake the world died in the middle of is pending again (the table recovers it); a real world sets its alarm for it.
|
|
40
|
+
if (this.clock.kind === "real")
|
|
41
|
+
void this.schedule();
|
|
42
|
+
ctx.storage.sql.exec("CREATE TABLE IF NOT EXISTS cast (name TEXT PRIMARY KEY, person TEXT, email TEXT NOT NULL, password TEXT NOT NULL)");
|
|
43
|
+
this.auth = AuthD1.make({ db: env.DB, secret: env.AUTH_SECRET, worlds: true });
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Which code wakes each kind of durable timer (M8.07). The generated Worker for a blueprint with a stepped or scaled clock
|
|
47
|
+
* extends this class and answers its wake map, empty until a feature registers a kind; no map, no route, and a due row fails.
|
|
48
|
+
*/
|
|
49
|
+
wakeKinds() {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
fetch(request) {
|
|
53
|
+
const { pathname } = new URL(request.url);
|
|
54
|
+
if (pathname === "/_world/arm" || pathname === "/_world/end") {
|
|
55
|
+
return request.json().then((body) => (pathname === "/_world/arm" ? this.arm(body) : this.finish(body)));
|
|
56
|
+
}
|
|
57
|
+
const clock = WorldClock.door(this.clock, request, this.timers.controller);
|
|
58
|
+
if (clock)
|
|
59
|
+
return clock;
|
|
60
|
+
// The wipe of the databases is over: the world admits requests again.
|
|
61
|
+
// It names its world as the reset did: a request that does not (a page, another world) cannot open it early.
|
|
62
|
+
const nonce = this.env.ORTHO_WORLD_NONCE;
|
|
63
|
+
const named = !nonce || request.headers.get(RESET_HEADER) === nonce;
|
|
64
|
+
if (pathname === "/_world/reset/done" && request.method === "POST") {
|
|
65
|
+
if (!named)
|
|
66
|
+
return Promise.resolve(json({ error: "not this world's reset" }, 403));
|
|
67
|
+
this.timers.admit();
|
|
68
|
+
return Promise.resolve(json({ admitted: true }));
|
|
69
|
+
}
|
|
70
|
+
// The cast signs up and in through Better Auth, which reads `Date`: at the world's instant, not the machine's.
|
|
71
|
+
// The cast, the credentials and the other front-door routes run Better Auth, which reads `Date`: each is counted work for its whole life,
|
|
72
|
+
// so a move does not pass one that is in flight (a real world counts nothing).
|
|
73
|
+
const resetting = pathname === "/_world/reset" && request.method === "POST";
|
|
74
|
+
// A reset that does not name this world closes nothing.
|
|
75
|
+
if (resetting && !named)
|
|
76
|
+
return Promise.resolve(json({ error: "not this world's reset" }, 403));
|
|
77
|
+
// One reset at a time: while the world is closed for one, another is a conflict, so the first one's `done` cannot reopen the world under
|
|
78
|
+
// the second one's wipe.
|
|
79
|
+
if (resetting && this.clock.kind !== "real" && this.timers.closed())
|
|
80
|
+
return Promise.resolve(json({ error: "a reset is already in progress" }, 409));
|
|
81
|
+
// While the world is closed for a reset, a read (health, clock, facts) answers as always, and a write is refused as a conflict, not a crash.
|
|
82
|
+
if (this.clock.kind !== "real" && this.timers.closed() && !resetting) {
|
|
83
|
+
if (request.method !== "GET" && request.method !== "HEAD")
|
|
84
|
+
return Promise.resolve(json({ error: "the world is being reset" }, 409));
|
|
85
|
+
return this.inTime(() => Effect.runPromise(frontDoor(this.ctx.storage.sql, this.auth, request, nonce)));
|
|
86
|
+
}
|
|
87
|
+
const token = this.clock.kind === "real" || this.timers.closed() ? undefined : this.timers.rpc.countEnter(`world:${pathname.replace("/_world/", "")}`);
|
|
88
|
+
// A reset first closes the world to new tokens and to writes and lets the writes in progress end; the databases are wiped next, by
|
|
89
|
+
// `toWorld`, and only then (`/_world/reset/done`) does the world admit requests again. A write still open at the bound fails the reset,
|
|
90
|
+
// naming it: the world opens again and nothing is wiped.
|
|
91
|
+
const refused = resetting
|
|
92
|
+
? Effect.runPromise(Effect.result(this.timers.close())).then((done) => (done._tag === "Success" ? undefined : done.failure.busy))
|
|
93
|
+
: Promise.resolve(undefined);
|
|
94
|
+
const answered = refused
|
|
95
|
+
.then((busy) => {
|
|
96
|
+
if (busy === undefined)
|
|
97
|
+
return this.inTime(() => Effect.runPromise(frontDoor(this.ctx.storage.sql, this.auth, request, nonce)));
|
|
98
|
+
this.timers.admit();
|
|
99
|
+
return json({ error: "NeverQuiet", busy }, 409);
|
|
100
|
+
})
|
|
101
|
+
.finally(() => { if (token !== undefined)
|
|
102
|
+
this.timers.rpc.countLeave(token); });
|
|
103
|
+
// The warm reset between runs (ST1.24) is the one way back: the clock returns to its declared start, a scaled one re-anchored now.
|
|
104
|
+
// Only the reset the world itself accepted (its nonce matched) does it.
|
|
105
|
+
return resetting ? answered.then((response) => { if (response.ok) {
|
|
106
|
+
this.clock.reset();
|
|
107
|
+
this.timers.reset();
|
|
108
|
+
}
|
|
109
|
+
else
|
|
110
|
+
this.timers.admit(); return response; }) : answered;
|
|
111
|
+
}
|
|
112
|
+
/** The world's instant now. */
|
|
113
|
+
now() {
|
|
114
|
+
return this.clock.now();
|
|
115
|
+
}
|
|
116
|
+
/** An entry begins (M8.07): the world takes a token for it under `owner` (`entry:<path>`) and answers it with the source its request reads time from. */
|
|
117
|
+
begin(owner) {
|
|
118
|
+
return { source: this.clock.source(), token: this.clock.kind === "real" ? undefined : this.timers.rpc.countEnter(owner) };
|
|
119
|
+
}
|
|
120
|
+
/** What to read the world's time from. Every other entry (the Worker, the actors) asks this over RPC, once, to run in this world's time. */
|
|
121
|
+
source() {
|
|
122
|
+
return this.clock.source();
|
|
123
|
+
}
|
|
124
|
+
inTime(f) {
|
|
125
|
+
const source = this.clock.source();
|
|
126
|
+
return source === undefined ? f() : WorldClock.within(source, f);
|
|
127
|
+
}
|
|
128
|
+
/** Remember the world's id and wake at its expiry. */
|
|
129
|
+
arm({ id, expires }) {
|
|
130
|
+
return this.ctx.storage.put({ world: id, expires }).then(() => this.schedule()).then(() => json({ armed: id }));
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The one alarm a Durable Object has: the world's lifetime, or in a real world the earliest timer, whichever is first.
|
|
134
|
+
* A stepped or scaled world sets no alarm for timers: its controller fires them (M8.07).
|
|
135
|
+
*/
|
|
136
|
+
schedule() {
|
|
137
|
+
return this.ctx.storage.get("expires").then((expires) => {
|
|
138
|
+
const next = [expires, this.timers.nextAlarm()].filter((at) => at !== undefined);
|
|
139
|
+
return next.length === 0 ? undefined : this.ctx.storage.setAlarm(Math.min(...next));
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/** Delete what the world made, then everything the world itself holds, alarm included. */
|
|
143
|
+
finish({ id, reason }) {
|
|
144
|
+
return Effect.runPromise(Clock.currentTimeMillis.pipe(Effect.flatMap((now) => end(this.env.DB, id, reason, now)))).then((ended) => this.ctx.storage.deleteAlarm().then(() => this.ctx.storage.deleteAll()).then(() => json({ ended })));
|
|
145
|
+
}
|
|
146
|
+
/** The world's own lifetime: real time, never the world's (K23 section 1), so it is the one entry that is not wrapped. */
|
|
147
|
+
alarm() {
|
|
148
|
+
return this.ctx.storage.get(["world", "expires"]).then((kept) => {
|
|
149
|
+
const id = kept.get("world");
|
|
150
|
+
const expires = kept.get("expires");
|
|
151
|
+
// A world armed before the expiry was kept ends at its alarm, as it always did; otherwise the alarm is a timer's.
|
|
152
|
+
if (id !== undefined && (expires === undefined || WorldClock.wall() >= expires))
|
|
153
|
+
return this.finish({ id, reason: "expired" }).then(() => undefined);
|
|
154
|
+
// The timer alarm runs app code, so it wraps itself in its world's time (a real world's `inTime` is a plain call).
|
|
155
|
+
return this.inTime(() => Effect.runPromise(this.timers.fireDue())).then(() => this.schedule());
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
// What the Worker and every other process call on the world (M8.07): the count of work in flight and the timer table.
|
|
159
|
+
countEnter(owner) { return this.timers.rpc.countEnter(owner); }
|
|
160
|
+
countLeave(id) { return this.timers.rpc.countLeave(id); }
|
|
161
|
+
countName(id, owner) { return this.timers.rpc.countName(id, owner); }
|
|
162
|
+
countHas(id) { return this.timers.rpc.countHas(id); }
|
|
163
|
+
countSection(id) { return this.timers.rpc.countSection(id); }
|
|
164
|
+
countSectionEnd(id) { return this.timers.rpc.countSectionEnd(id); }
|
|
165
|
+
timerAdd(...args) { return this.timers.rpc.timerAdd(...args); }
|
|
166
|
+
timerWait(id) { return this.timers.rpc.timerWait(id); }
|
|
167
|
+
timerCancel(id) { return this.timers.rpc.timerCancel(id); }
|
|
168
|
+
timerSet(...args) { return this.timers.rpc.timerSet(...args); }
|
|
169
|
+
timerClear(...args) { return this.timers.rpc.timerClear(...args); }
|
|
170
|
+
timersSleeping() { return this.timers.rpc.timersSleeping(); }
|
|
171
|
+
timersDurable() { return this.timers.rpc.timersDurable(); }
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Every entry that runs app code wraps itself in its world's time (M8.06). `entry` wraps a Worker's `fetch`, `scheduled`
|
|
175
|
+
* and `queue`; `within` wraps any other promise-returning entry (a Workflows step), and `withinNow` an RPC method that
|
|
176
|
+
* answers at once. A real world runs each as it is.
|
|
177
|
+
*/
|
|
178
|
+
export const WorldEntry = { entry, within, withinNow, work, fenced, section };
|
|
179
|
+
/**
|
|
180
|
+
* A `/_world/*` request. Facts come straight from the database. `/_world/worlds` is the environment's registry of worlds,
|
|
181
|
+
* which only an environment that hosts worlds (`leases`) has. Anything else goes to the live world's own Durable Object
|
|
182
|
+
* in such an environment, and otherwise to the one world of this deployment.
|
|
183
|
+
*/
|
|
184
|
+
export const toWorld = (world, request) => {
|
|
185
|
+
const { pathname } = new URL(request.url);
|
|
186
|
+
if (pathname.startsWith("/_world/facts/"))
|
|
187
|
+
return Effect.runPromise(facts(world, request));
|
|
188
|
+
// A warm world is emptied between runs (ST1.24); a world with leases ends by its own lease instead. The header makes the
|
|
189
|
+
// request one a browser page cannot send cross-origin without a preflight; the world checks its value against its own.
|
|
190
|
+
if (pathname === "/_world/reset" && request.method === "POST") {
|
|
191
|
+
if (world.leases)
|
|
192
|
+
return Promise.resolve(json({ error: "a world with leases is ended, not reset" }, 404));
|
|
193
|
+
if (!request.headers.get(RESET_HEADER))
|
|
194
|
+
return Promise.resolve(json({ error: `a reset names its world in ${RESET_HEADER}` }, 400));
|
|
195
|
+
const keeper = world.worlds.get(world.worlds.idFromName("world"));
|
|
196
|
+
const admit = () => keeper.fetch(new Request("http://world/_world/reset/done", { method: "POST", headers: { [RESET_HEADER]: request.headers.get(RESET_HEADER) ?? "" } }));
|
|
197
|
+
return keeper.fetch(request).then((cast) => cast.ok
|
|
198
|
+
// The world is closed from the reset until the wipe is over, however the wipe ends.
|
|
199
|
+
? cast.json().then(({ people }) => Effect.runPromise(resetDatabases(world, people)))
|
|
200
|
+
.then(() => admit(), (failure) => admit().then(() => Promise.reject(failure)))
|
|
201
|
+
.then(() => json({ reset: true }))
|
|
202
|
+
: cast);
|
|
203
|
+
}
|
|
204
|
+
if (!world.leases)
|
|
205
|
+
return world.worlds.get(world.worlds.idFromName("world")).fetch(request);
|
|
206
|
+
if (pathname.startsWith("/_world/worlds"))
|
|
207
|
+
return Effect.runPromise(worldsDoor({ worlds: world.worlds, db: world.db }, request));
|
|
208
|
+
return Effect.runPromise(live(world.db)).then((held) => world.worlds.get(world.worlds.idFromName(held[0]?.id ?? "world")).fetch(request));
|
|
209
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { CastMember } from "#modules/auth/types.js";
|
|
2
|
+
export interface WorldEnv {
|
|
3
|
+
readonly DB: D1Database;
|
|
4
|
+
/** Better Auth's secret. Made fresh by `ortho dev` for each run; never written to a file. */
|
|
5
|
+
readonly AUTH_SECRET: string;
|
|
6
|
+
/** Made fresh by `ortho dev`: its health answer says it, and a reset must present it (a record of dev is no one else's world). */
|
|
7
|
+
readonly ORTHO_WORLD_NONCE?: string;
|
|
8
|
+
/** How worlds tell time (M8.06): each environment's clock as JSON. Absent, or no entry for this environment: real. */
|
|
9
|
+
readonly ORTHO_CLOCKS?: string;
|
|
10
|
+
readonly ORTHO_ENVIRONMENT?: string;
|
|
11
|
+
/** How long a move waits for the world to be quiet, in real milliseconds, before it fails as `NeverQuiet` (M8.07). Five seconds when unset. */
|
|
12
|
+
readonly ORTHO_QUIET_MS?: string;
|
|
13
|
+
/** The most timers one move may fire at one instant before it fails as `NeverQuiet`, naming who keeps registering them. 10 000 when unset. */
|
|
14
|
+
readonly ORTHO_FIRE_LIMIT?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* `POST /_world/cast` with `{ names, anonymous? }`: each name signed up once (kept for the world's life) and signed in
|
|
18
|
+
* afresh. A name in `anonymous` only gets an email and a password, so a script can sign them up itself.
|
|
19
|
+
*/
|
|
20
|
+
export interface Cast {
|
|
21
|
+
readonly [name: string]: CastMember;
|
|
22
|
+
}
|
|
23
|
+
/** What an entry needs from its bindings to find its world and its clock (M8.06). */
|
|
24
|
+
export interface EntryEnv {
|
|
25
|
+
readonly WORLD: DurableObjectNamespace;
|
|
26
|
+
readonly DB: D1Database;
|
|
27
|
+
/** `1` in an environment that hosts worlds with lifetimes: the live world is its own instance, named by its id. */
|
|
28
|
+
readonly ORTHO_WORLDS?: string;
|
|
29
|
+
readonly ORTHO_CLOCKS?: string;
|
|
30
|
+
readonly ORTHO_ENVIRONMENT?: string;
|
|
31
|
+
}
|
|
32
|
+
/** What `toWorld` needs from the Worker's bindings. */
|
|
33
|
+
export interface WorldHost {
|
|
34
|
+
readonly worlds: DurableObjectNamespace;
|
|
35
|
+
readonly db: D1Database;
|
|
36
|
+
readonly tables: ReadonlyArray<string>;
|
|
37
|
+
/** The declared database stores (K3): each its own binding, with the tables of the things that live in it. */
|
|
38
|
+
readonly stores?: ReadonlyArray<{
|
|
39
|
+
readonly db: D1Database;
|
|
40
|
+
readonly tables: ReadonlyArray<string>;
|
|
41
|
+
}>;
|
|
42
|
+
/** The Durable Objects things that live as actors are kept in, and the tables they go by: their facts are read from the actor, never from D1. */
|
|
43
|
+
readonly actors?: DurableObjectNamespace;
|
|
44
|
+
readonly actorTables?: ReadonlyArray<string>;
|
|
45
|
+
/** This environment hosts worlds with lifetimes (a test environment): `/_world/worlds` is open, and each world is its own Durable Object. */
|
|
46
|
+
readonly leases?: boolean;
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orthograph/host-cloudflare",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-next.2",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"default": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@better-auth/api-key": "1.7.15",
|
|
14
|
+
"@better-auth/core": "1.7.15",
|
|
15
|
+
"@better-auth/oauth-provider": "1.7.15",
|
|
16
|
+
"@better-auth/utils": "0.5.1",
|
|
17
|
+
"@better-fetch/fetch": "1.3.3",
|
|
18
|
+
"@effect/sql-d1": "4.1.4",
|
|
19
|
+
"better-auth": "1.7.15",
|
|
20
|
+
"better-call": "1.4.4",
|
|
21
|
+
"effect": "4.1.4",
|
|
22
|
+
"jose": "6.2.15",
|
|
23
|
+
"zod": "4.6.7",
|
|
24
|
+
"@orthograph/chain-evm": "0.1.0-next.2",
|
|
25
|
+
"orthograph": "0.1.0-next.2",
|
|
26
|
+
"@orthograph/language-effect": "0.1.0-next.2"
|
|
27
|
+
},
|
|
28
|
+
"imports": {
|
|
29
|
+
"#modules/*.js": "./dist/modules/*.js"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@cloudflare/vitest-pool-workers": "0.23.0",
|
|
33
|
+
"@cloudflare/workers-types": "5.20261101.1",
|
|
34
|
+
"kysely": "0.29.7",
|
|
35
|
+
"wrangler": "4.156.1"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public",
|
|
42
|
+
"tag": "next"
|
|
43
|
+
},
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/Open-Harness/orthograph.git",
|
|
47
|
+
"directory": "packages/host-cloudflare"
|
|
48
|
+
}
|
|
6
49
|
}
|