@lunora/platform-node 1.0.0-alpha.22 → 1.0.0-alpha.220
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.md +201 -104
- package/README.md +8 -1
- package/dist/conformance/index.mjs +1 -1
- package/dist/index.d.mts +740 -135
- package/dist/index.d.ts +740 -135
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/DEFAULT_DRAIN_TIMEOUT_MS-JyFyF0D9.mjs +1 -0
- package/dist/packem_shared/NODE_SCHEDULER_DISPATCH_PATH-uDl0zU2t.mjs +1 -0
- package/dist/packem_shared/bindShardSockets-9GvSocBW.mjs +1 -0
- package/dist/packem_shared/createNodeGlobalStore-CD4DiqeS.mjs +1 -0
- package/dist/packem_shared/createNodeHttpServer-cUx4J9Z9.mjs +4 -0
- package/dist/packem_shared/createNodeHyperdrive-C4Z_s0hY.mjs +1 -0
- package/dist/packem_shared/createNodePlatform-C5LvauTf.mjs +1 -0
- package/dist/packem_shared/createNodeProfileHandler-MX5xKPg0.mjs +1 -0
- package/dist/packem_shared/createNodeQueueHost-szMV0PBN.mjs +17 -0
- package/dist/packem_shared/createNodeR2Bucket-D_jsnenX.mjs +1 -0
- package/dist/packem_shared/createNodeSchedulerHost-BQPmMWJ7.mjs +15 -0
- package/dist/packem_shared/createNodeSecretBindings-C7wh0fOm.mjs +1 -0
- package/dist/packem_shared/createNodeShardHost-VU8MPeba.mjs +1 -0
- package/dist/packem_shared/createNodeShardNamespace-BgQjDv7V.mjs +1 -0
- package/dist/packem_shared/createNodeShardRegistry-BHzxHBx1.mjs +1 -0
- package/dist/packem_shared/createNodeSocketHost-ByOmEGFe.mjs +2 -0
- package/dist/packem_shared/createNodeWorkflowHost-B76TKiw_.mjs +1 -0
- package/dist/packem_shared/hmac-url-Bogwm7I6.mjs +1 -0
- package/dist/packem_shared/node-dispatch-route-ByuCR26s.mjs +2 -0
- package/dist/packem_shared/node-socket-pair-0baNnoFw.mjs +1 -0
- package/dist/packem_shared/prepared-statement-3XBQZXtC.mjs +1 -0
- package/package.json +17 -10
- package/dist/packem_shared/createNodeGlobalStore-Cwi33XOk.mjs +0 -1
- package/dist/packem_shared/createNodePlatform-1fAQ_biu.mjs +0 -1
- package/dist/packem_shared/createNodeQueueHost--mBLGSxF.mjs +0 -17
- package/dist/packem_shared/createNodeR2Bucket-CmHYlIni.mjs +0 -1
- package/dist/packem_shared/createNodeSchedulerHost-vZgv1CEo.mjs +0 -15
- package/dist/packem_shared/createNodeShardHost-C0j8nvSU.mjs +0 -1
- package/dist/packem_shared/createNodeShardRegistry-DKdc0pV8.mjs +0 -1
- package/dist/packem_shared/createNodeShardState-CpUzvWwd.mjs +0 -1
- package/dist/packem_shared/createNodeSocketHost-DK3X5PlQ.mjs +0 -2
- package/dist/packem_shared/createNodeWorkflowHost-CTVBYiuj.mjs +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,92 @@
|
|
|
1
1
|
import { SchemaLike } from '@lunora/shard-engine';
|
|
2
2
|
import { SqlCtxDbOptions, SqlCtxExec, createSqlCtxDb } from '@lunora/sql-store';
|
|
3
3
|
import Database from 'better-sqlite3';
|
|
4
|
-
import { ShardKvStore, QueueBindingLike, MessageBatchLike, SchedulerHost, ShardHost, SocketHost, DirectShardDirectory, PlatformCapabilities, ShardDirectory, R2BucketLike
|
|
4
|
+
import { ShardKvStore, QueueBindingLike, MessageBatchLike, SchedulerHost, ShardHost, SocketHandle, SocketHost, DirectShardDirectory, PlatformCapabilities, ShardDirectory, R2BucketLike } from '@lunora/platform';
|
|
5
5
|
import { WorkflowBindingLike } from '@lunora/workflow';
|
|
6
6
|
import { WorkflowRuntime, WorkflowStore } from '@visulima/workflow';
|
|
7
|
+
import { ShardNamespaceLike } from '@lunora/runtime';
|
|
8
|
+
/**
|
|
9
|
+
* The deadline every `drain()` in this package runs under. A shutdown that waits for work without a bound is held open by the
|
|
10
|
+
* one request or background task that never settles, until the supervisor's kill skips the database close the drain exists to
|
|
11
|
+
* reach. Each drain returns what was still pending when its deadline passed, so the caller can log it and close anyway.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Arms `onExpire` to run after `ms` and returns a function that disarms it. Injectable so a test drives the deadline by hand
|
|
15
|
+
* rather than waiting for a clock.
|
|
16
|
+
*/
|
|
17
|
+
type DrainTimer = (ms: number, onExpire: () => void) => () => void;
|
|
18
|
+
/** Options every `drain()` accepts. */
|
|
19
|
+
interface DrainOptions {
|
|
20
|
+
/** Stop waiting after this many milliseconds. Defaults to {@link DEFAULT_DRAIN_TIMEOUT_MS}. */
|
|
21
|
+
timeoutMs?: number;
|
|
22
|
+
/** The clock the deadline runs on. Defaults to `setTimeout`, which keeps the process alive until the drain settles or expires. */
|
|
23
|
+
timer?: DrainTimer;
|
|
24
|
+
}
|
|
25
|
+
/** How a `drain()` ended. */
|
|
26
|
+
interface DrainResult {
|
|
27
|
+
/**
|
|
28
|
+
* Work that failed while the drain waited for it (an alarm retry that could not be written), one readable entry each. Each
|
|
29
|
+
* was also logged with its cause when it happened. A failure never stops the drain waiting for the rest.
|
|
30
|
+
*/
|
|
31
|
+
failed: string[];
|
|
32
|
+
/** What was still running when the deadline passed, one human-readable entry each. Empty when the drain completed. */
|
|
33
|
+
pending: string[];
|
|
34
|
+
/** `true` when the deadline passed before the work settled. */
|
|
35
|
+
timedOut: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** Long enough for an ordinary request or background write to finish; short enough that a stuck one cannot stall a shutdown. */
|
|
38
|
+
declare const DEFAULT_DRAIN_TIMEOUT_MS = 3e4;
|
|
39
|
+
/** Something that drains and can say, synchronously, whether it is idle: a registry, a platform. */
|
|
40
|
+
interface Drainable {
|
|
41
|
+
drain: (options?: DrainOptions) => Promise<DrainResult>;
|
|
42
|
+
idle: () => boolean;
|
|
43
|
+
/** What is running right now, re-read when the deadline passes: a part that drained early can have gained work since. */
|
|
44
|
+
pending: () => string[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Drain several parts under one deadline until a pass that began with every part idle also ends with every part idle. Work
|
|
48
|
+
* on one part can start work on another after that one finished draining (a request handed between registries), and a
|
|
49
|
+
* failure can be recorded after a part's own drain returned; the pass that begins idle collects it, and is held to the same
|
|
50
|
+
* deadline as any other.
|
|
51
|
+
*/
|
|
52
|
+
declare const drainTogether: (parts: ReadonlyArray<Drainable>, options?: DrainOptions) => Promise<DrainResult>;
|
|
53
|
+
/** One function call the route has authenticated and parsed. */
|
|
54
|
+
interface NodeDispatchInvocation {
|
|
55
|
+
args: Record<string, unknown>;
|
|
56
|
+
functionPath: string;
|
|
57
|
+
/** The scheduler record or delivery id, used as the shard's idempotency key. */
|
|
58
|
+
id: string | undefined;
|
|
59
|
+
/** Identity the trusted caller forwarded, if any. */
|
|
60
|
+
identity: {
|
|
61
|
+
identity?: string;
|
|
62
|
+
userId?: string;
|
|
63
|
+
} | undefined;
|
|
64
|
+
/** The job's due time in epoch-ms, when the sender stamped one. */
|
|
65
|
+
scheduledFor?: number;
|
|
66
|
+
shardKey: string;
|
|
67
|
+
traceparent: string | undefined;
|
|
68
|
+
}
|
|
69
|
+
interface NodeDispatchRouteOptions {
|
|
70
|
+
/** `LUNORA_ADMIN_TOKEN`. Used as the bearer when no HMAC signature is presented. */
|
|
71
|
+
adminToken?: string;
|
|
72
|
+
/** The shard a body without `shardKey` is sent to. */
|
|
73
|
+
defaultShardKey: string;
|
|
74
|
+
/** Runs the call in-process and returns the shard's response, unchanged. */
|
|
75
|
+
invoke: (call: NodeDispatchInvocation) => Promise<Response>;
|
|
76
|
+
/** Epoch-ms clock for the signature window. Defaults to `Date.now`; tests inject one. */
|
|
77
|
+
now?: () => number;
|
|
78
|
+
/** `LUNORA_SCHEDULER_SECRET`. When set, a signed request is verified against it. */
|
|
79
|
+
schedulerSecret?: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Build the dispatch route. The returned function answers any request it is
|
|
83
|
+
* handed; mounting it at {@link NODE_SCHEDULER_DISPATCH_PATH} is the caller's job.
|
|
84
|
+
* With neither secret configured every request is refused, so an unconfigured
|
|
85
|
+
* route fails closed.
|
|
86
|
+
*/
|
|
87
|
+
declare const createNodeDispatchRoute: (options: NodeDispatchRouteOptions) => ((request: Request) => Promise<Response>);
|
|
88
|
+
/** The path `@lunora/dispatch` and `@lunora/scheduler` POST to. */
|
|
89
|
+
declare const NODE_SCHEDULER_DISPATCH_PATH: "/_lunora/scheduler/dispatch";
|
|
7
90
|
/**
|
|
8
91
|
* The Node store options — the shared store options minus the two this binding
|
|
9
92
|
* owns. `dialect` is fixed (SQLite) and `exec` is the store's own connection;
|
|
@@ -14,13 +97,21 @@ type NodeGlobalContextDatabaseOptions = Omit<SqlCtxDbOptions, "dialect" | "exec"
|
|
|
14
97
|
/**
|
|
15
98
|
* Wrap a `better-sqlite3` connection as the async exec the store core consumes.
|
|
16
99
|
*
|
|
17
|
-
* `batch`
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
100
|
+
* `batch` runs the statements in order inside one `better-sqlite3`
|
|
101
|
+
* transaction, which is synchronous, so nothing else runs between them. There is
|
|
102
|
+
* no round trip to save; atomicity is the point. The store core's FTS5 search
|
|
103
|
+
* companion writes each document as an ordered list of statements, and without
|
|
104
|
+
* this two async writers interleaved at every `await` between them: one could
|
|
105
|
+
* move a document's mapping while the other's entry was mid-write, leaving an
|
|
106
|
+
* entry no later write or purge could reach. The `sqlite` dialect's contract
|
|
107
|
+
* requires an ordered, atomic `batch` for exactly that reason.
|
|
108
|
+
*
|
|
109
|
+
* `transaction` holds `BEGIN IMMEDIATE` … `COMMIT` open across the awaits of
|
|
110
|
+
* an async `work`, which `better-sqlite3`'s own synchronous `transaction()`
|
|
111
|
+
* cannot. The connection is shared, so while one is open every other statement
|
|
112
|
+
* waits for it to settle: run in between, another writer's statement would land
|
|
113
|
+
* inside it and be rolled back with it. The wait and the statement (or the
|
|
114
|
+
* `BEGIN`) run with no `await` between them, so nothing slips in after the check.
|
|
24
115
|
*/
|
|
25
116
|
declare const createNodeSqlExec: (database: Database.Database) => SqlCtxExec;
|
|
26
117
|
/** Options for {@link createNodeGlobalStore}. */
|
|
@@ -63,6 +154,76 @@ interface NodeGlobalStore {
|
|
|
63
154
|
* which is the whole point of the dialect seam.
|
|
64
155
|
*/
|
|
65
156
|
declare const createNodeGlobalStore: (options?: NodeGlobalStoreOptions) => NodeGlobalStore;
|
|
157
|
+
/** Serve `options.fetch` over `node:http`. Resolves once the server is listening. */
|
|
158
|
+
declare const createNodeHttpServer: (options: NodeHttpServerOptions) => Promise<NodeHttpServer>;
|
|
159
|
+
/** Options for {@link createNodeHttpServer}. */
|
|
160
|
+
interface NodeHttpServerOptions {
|
|
161
|
+
/** The app worker's `fetch`, already bound to its env and context. */
|
|
162
|
+
fetch: (request: Request) => Promise<Response> | Response;
|
|
163
|
+
/** Host to bind. Defaults to the loopback interface. */
|
|
164
|
+
host?: string;
|
|
165
|
+
/**
|
|
166
|
+
* The public base URL the app is served at, e.g. `https://app.example`. Every request URL uses its origin, so origin-sensitive
|
|
167
|
+
* behaviour (CSRF, WebSocket origin checks, cookie rules) sees the public scheme behind a TLS proxy. The client's `Host` header is
|
|
168
|
+
* never used. Defaults to the bound `http://host:port`, which is only allowed for a loopback `host`: binding a non-loopback address
|
|
169
|
+
* (e.g. `0.0.0.0` or a LAN IP) without `origin` makes {@link createNodeHttpServer} reject, because browsers would send that address
|
|
170
|
+
* as `Origin` and fail the CSRF check. Set `origin` to the URL users open.
|
|
171
|
+
*/
|
|
172
|
+
origin?: string;
|
|
173
|
+
/** Port to bind. `0` (the default) picks a free ephemeral port. */
|
|
174
|
+
port?: number;
|
|
175
|
+
}
|
|
176
|
+
/** A listening server. */
|
|
177
|
+
interface NodeHttpServer {
|
|
178
|
+
/** Stop accepting connections and end every open one, streams included. */
|
|
179
|
+
close: () => Promise<void>;
|
|
180
|
+
/**
|
|
181
|
+
* Stop accepting connections, then wait until every HTTP response that was in progress when the drain began has been written
|
|
182
|
+
* to the end or its client has gone, or until the deadline passes (`timeoutMs`, 30 s by default). A request that still
|
|
183
|
+
* arrives on an open connection is answered with keep-alive off and is not waited for. Event streams (`text/event-stream`)
|
|
184
|
+
* and WebSockets are endless by design and are not waited for; {@link NodeHttpServer.close} ends them. Resolves with what was
|
|
185
|
+
* still unfinished when the deadline passed, which it also logs.
|
|
186
|
+
*/
|
|
187
|
+
drain: (options?: DrainOptions) => Promise<DrainResult>;
|
|
188
|
+
/** The `http://host:port` origin the server answers on. */
|
|
189
|
+
origin: string;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The connection fields a Cloudflare `Hyperdrive` binding exposes, and the
|
|
193
|
+
* `HyperdriveLike` shape `@lunora/hyperdrive`'s `createHyperdrive` reads.
|
|
194
|
+
* Declared here structurally so this package does not depend on
|
|
195
|
+
* `@lunora/hyperdrive` for a type.
|
|
196
|
+
*/
|
|
197
|
+
interface NodeHyperdriveBinding {
|
|
198
|
+
connectionString: string;
|
|
199
|
+
database: string;
|
|
200
|
+
host: string;
|
|
201
|
+
password: string;
|
|
202
|
+
port: number;
|
|
203
|
+
user: string;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Build the `HYPERDRIVE` binding for a Node host from a database URL, by
|
|
207
|
+
* default `process.env.DATABASE_URL`. Put it on the `env` the worker and shard
|
|
208
|
+
* are built over, under the binding name the app reads (`env.HYPERDRIVE`), and
|
|
209
|
+
* the app's own `.hyperdrive((env) => …)` wiring builds `ctx.sql` from it
|
|
210
|
+
* unchanged.
|
|
211
|
+
*
|
|
212
|
+
* There is no pool or query cache in front of the database here: the driver
|
|
213
|
+
* the app constructs from `connectionString` connects to it directly, so its own
|
|
214
|
+
* pool settings are the only ones that apply.
|
|
215
|
+
* A Postgres URL may name a Unix socket the libpq way: an empty host with the
|
|
216
|
+
* socket directory in a `host` query parameter (`postgres:///db?host=/var/run/postgresql`),
|
|
217
|
+
* which becomes the binding's `host`.
|
|
218
|
+
*
|
|
219
|
+
* A URL with any TLS option other than an explicit off (`sslmode=prefer` or
|
|
220
|
+
* `require`, `ssl=true`, `sslrootcert=…`) gets a binding whose discrete fields
|
|
221
|
+
* throw: they cannot carry it, so a pool built from them would silently connect
|
|
222
|
+
* without TLS. `sslmode=disable` and `ssl=false` keep them. Build the driver
|
|
223
|
+
* from `connectionString`, which keeps every query option.
|
|
224
|
+
* @param url A `postgres://`, `postgresql://`, `mysql://` or `mariadb://` URL; `DATABASE_URL` unless given.
|
|
225
|
+
*/
|
|
226
|
+
declare const createNodeHyperdrive: (url?: string | undefined) => NodeHyperdriveBinding;
|
|
66
227
|
/** Build a `ShardKvStore` over a `better-sqlite3` table in the shard's database. */
|
|
67
228
|
declare const createNodeShardKvStore: (database: Database.Database) => ShardKvStore;
|
|
68
229
|
/** Options for {@link createNodeQueueHost}. */
|
|
@@ -137,6 +298,14 @@ interface NodeQueueHost<Queues extends Record<string, {
|
|
|
137
298
|
declare const createNodeQueueHost: <Queues extends Record<string, {
|
|
138
299
|
isLunoraQueue: true;
|
|
139
300
|
}>>(database: Database.Database, options: NodeQueueHostOptions<Queues>) => NodeQueueHost<Queues>;
|
|
301
|
+
/** One declared cron job, as {@link NodeSchedulerHost.declareCrons} takes it. */
|
|
302
|
+
interface NodeDeclaredCron {
|
|
303
|
+
args: Record<string, unknown>;
|
|
304
|
+
expression: string;
|
|
305
|
+
functionPath: string;
|
|
306
|
+
/** The job's `cronJobs()` name, unique across the app. Keys its row. */
|
|
307
|
+
name: string;
|
|
308
|
+
}
|
|
140
309
|
/** Options for {@link createNodeSchedulerHost}. */
|
|
141
310
|
interface NodeSchedulerHostOptions {
|
|
142
311
|
/**
|
|
@@ -146,17 +315,22 @@ interface NodeSchedulerHostOptions {
|
|
|
146
315
|
* A handler that **throws** marks the delivery failed, which is what drives
|
|
147
316
|
* the retry/dead-letter machinery: the job's `attempts` increments and it is
|
|
148
317
|
* either re-armed with backoff or parked. A handler that resolves marks the
|
|
149
|
-
* job
|
|
318
|
+
* job `succeeded`.
|
|
150
319
|
*
|
|
151
320
|
* Omitting it makes every delivery trivially succeed, which means a caller
|
|
152
321
|
* who forgets to pass one gets a scheduler that quietly drops work — the
|
|
153
322
|
* precise failure plan 267 caught. Supply one in anything real; the
|
|
154
323
|
* conformance host supplies one purely so the TCK can tell a delivery apart
|
|
155
324
|
* from an expired timer.
|
|
325
|
+
*
|
|
326
|
+
* `job.scheduledFor` is the due time (a cron tick's planned fire time).
|
|
327
|
+
* Forwarding it as the dispatch body's `scheduledFor` is what lets the shard
|
|
328
|
+
* record the `scheduler.lag_ms` metric, as the Worker dispatch path does.
|
|
156
329
|
*/
|
|
157
330
|
onDispatch?: (functionPath: string, args: Record<string, unknown>, job: {
|
|
158
331
|
attempts: number;
|
|
159
332
|
id: string;
|
|
333
|
+
scheduledFor: number;
|
|
160
334
|
}) => Promise<void> | void;
|
|
161
335
|
}
|
|
162
336
|
/**
|
|
@@ -164,6 +338,14 @@ interface NodeSchedulerHostOptions {
|
|
|
164
338
|
* TCK's dead-letter legs need.
|
|
165
339
|
*/
|
|
166
340
|
interface NodeSchedulerHost {
|
|
341
|
+
/**
|
|
342
|
+
* Make `crons` the app's declared cron set: upsert each one, arm it, and
|
|
343
|
+
* delete and disarm any declared row not in the list (a job the app removed
|
|
344
|
+
* or renamed). Every expression is parsed before anything is written, so an
|
|
345
|
+
* invalid one throws and leaves the previous set in place. Throws after
|
|
346
|
+
* `dispose()`.
|
|
347
|
+
*/
|
|
348
|
+
declareCrons: (crons: ReadonlyArray<NodeDeclaredCron>) => void;
|
|
167
349
|
/**
|
|
168
350
|
* Clear every armed `setTimeout` (one-shot jobs and cron ticks alike) and
|
|
169
351
|
* put the host into a terminal, closed state: afterwards `schedule()` and
|
|
@@ -177,6 +359,14 @@ interface NodeSchedulerHost {
|
|
|
177
359
|
* left uncleared.
|
|
178
360
|
*/
|
|
179
361
|
dispose: () => void;
|
|
362
|
+
/**
|
|
363
|
+
* Deliveries running now, one-shot jobs and cron ticks alike, each from its timer firing until the scheduler has
|
|
364
|
+
* recorded the outcome, labelled by job. A drain waits for these before the database the scheduler writes to is closed.
|
|
365
|
+
*/
|
|
366
|
+
pendingDispatches: () => {
|
|
367
|
+
labels: string[];
|
|
368
|
+
waits: Promise<unknown>[];
|
|
369
|
+
};
|
|
180
370
|
scheduler: SchedulerHost;
|
|
181
371
|
/**
|
|
182
372
|
* Drive a pending job straight to its dead-letter state without waiting out
|
|
@@ -185,6 +375,12 @@ interface NodeSchedulerHost {
|
|
|
185
375
|
* while how many failures it takes to get there is host policy.
|
|
186
376
|
*/
|
|
187
377
|
simulateDeadLetter: (id: string) => Promise<boolean>;
|
|
378
|
+
/**
|
|
379
|
+
* Stop firing: clear every armed timer and arm none from then on, while rows are still written and kept. A shutdown calls
|
|
380
|
+
* it before draining, so no job or cron tick starts after the drain checked for running work; each then re-arms from its
|
|
381
|
+
* row after a restart. A delivery already running finishes. One-way; `dispose()` still ends the host.
|
|
382
|
+
*/
|
|
383
|
+
suspend: () => void;
|
|
188
384
|
}
|
|
189
385
|
/** Build a durable, SQLite-backed scheduler over `database`. */
|
|
190
386
|
declare const createNodeSchedulerHost: (database: Database.Database, options?: NodeSchedulerHostOptions) => NodeSchedulerHost;
|
|
@@ -197,9 +393,12 @@ interface NodeShardHostOptions {
|
|
|
197
393
|
* `_lunora_alarm` when the host is constructed over an existing database,
|
|
198
394
|
* including an alarm whose time elapsed while nothing was running.
|
|
199
395
|
*
|
|
200
|
-
* A handler that throws is isolated to its own delivery
|
|
396
|
+
* A handler that throws is isolated to its own delivery — it never reaches
|
|
201
397
|
* the caller that set the alarm, because by then that call has long
|
|
202
|
-
* returned
|
|
398
|
+
* returned — and the wakeup is then re-delivered with backoff up to
|
|
399
|
+
* {@link ALARM_RETRY_LIMIT} times, the way workerd retries a throwing
|
|
400
|
+
* `alarm()`. Delivery is at-least-once, so the handler must tolerate
|
|
401
|
+
* running twice for one scheduled timestamp.
|
|
203
402
|
*/
|
|
204
403
|
onAlarm?: () => Promise<void> | void;
|
|
205
404
|
/**
|
|
@@ -218,25 +417,59 @@ interface NodeShardHostOptions {
|
|
|
218
417
|
/**
|
|
219
418
|
* Build a `ShardHost` over a real `better-sqlite3` database.
|
|
220
419
|
*
|
|
221
|
-
* `runSerialized`
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
* `
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
* `runSerialized
|
|
239
|
-
*
|
|
420
|
+
* `runSerialized` and `transaction` share **one** boundary lock, because they
|
|
421
|
+
* write **one** `better-sqlite3` connection. `transaction` issues raw
|
|
422
|
+
* `BEGIN`/`COMMIT`/`ROLLBACK` — legal here (unlike inside a Cloudflare Durable
|
|
423
|
+
* Object, where the runtime forbids it and callers must use
|
|
424
|
+
* `storage.transaction`) because better-sqlite3 is a plain embedded database
|
|
425
|
+
* with no platform-level transaction primitive layered over it.
|
|
426
|
+
*
|
|
427
|
+
* ## Why one lane and not two
|
|
428
|
+
*
|
|
429
|
+
* This host shipped with two private tail chains, one per entry point, so each
|
|
430
|
+
* serialized against itself and neither against the other. `runSerialized`
|
|
431
|
+
* issues no `BEGIN` of its own, so one of its closures overlapping a bare
|
|
432
|
+
* `transaction()` wrote straight into that transaction's span. `assertOwnTurn`
|
|
433
|
+
* below catches the write — it is the only reason this host never silently lost
|
|
434
|
+
* one the way an unguarded connection would — but catching it is not the same
|
|
435
|
+
* as preventing it, and the refusal lands in the wrong place:
|
|
436
|
+
*
|
|
437
|
+
* 1. A `runSerialized` closure writes a row. Nothing is open, so it commits.
|
|
438
|
+
* 2. It awaits (a scheduler hop, an `onShardInit` read, any real I/O).
|
|
439
|
+
* 3. A bare `transaction()` runs `BEGIN` while it is parked. `transaction` is
|
|
440
|
+
* a public contract surface, and `./node-shard-state` re-exports it as the
|
|
441
|
+
* `storage.transaction` member `ShardDO` documents as "the platform
|
|
442
|
+
* primitive", so a subclass reaches one without going through the engine.
|
|
443
|
+
* 4. The closure resumes and its next write is refused with
|
|
444
|
+
* `SHARD_UNAVAILABLE`, so `runSerialized` **rejects** — with step 1 already
|
|
445
|
+
* durable.
|
|
446
|
+
*
|
|
447
|
+
* The boundary the contract promises is atomic-or-nothing to its caller tore in
|
|
448
|
+
* half: a rejection the caller will retry, on top of a write the retry now
|
|
449
|
+
* re-applies. That is `runSerialized`'s "no two closures interleave" guarantee
|
|
450
|
+
* broken by a `transaction` it was never serialized against.
|
|
451
|
+
*
|
|
452
|
+
* ## Why the lock is re-entrant, and why `AsyncLocalStorage` is what makes it so
|
|
453
|
+
*
|
|
454
|
+
* The engine composes the two, and stacks them: `ShardRunner.runInTransaction`
|
|
455
|
+
* is `runSerialized(() => transaction(work))` (`@lunora/shard-engine`), and
|
|
456
|
+
* `ShardDO.fetch` widens a mutation dispatch carrying `x-lunora-mutation-id`
|
|
457
|
+
* into a *further* `runSerialized` span around it (`@lunora/do`). Under two
|
|
458
|
+
* plain FIFO chains that outer span is already fatal on this host — the inner
|
|
459
|
+
* `runSerialized` waits on a `tail` that only settles when the outer closure it
|
|
460
|
+
* is running inside resolves, and because nothing ever resets that `tail`, the
|
|
461
|
+
* shard's write lane is wedged for the life of the process rather than for the
|
|
462
|
+
* life of the request.
|
|
463
|
+
*
|
|
464
|
+
* So the lock is skipped for a boundary opened from inside a boundary, and
|
|
465
|
+
* `AsyncLocalStorage` is the only thing that can tell that case from the one
|
|
466
|
+
* that must queue: its store follows a single call's own await chain without
|
|
467
|
+
* leaking into a sibling chain. A held boolean cannot — it reads `true` for an
|
|
468
|
+
* unrelated *second top-level* `transaction()` too, which would then nest a raw
|
|
469
|
+
* `BEGIN` on a connection already inside one. This is the same distinction
|
|
470
|
+
* workerd's `blockConcurrencyWhile` draws natively with "does not queue events
|
|
471
|
+
* initiated as part of the callback itself", which is what
|
|
472
|
+
* `@lunora/platform-cloudflare` leans on for the identical composition.
|
|
240
473
|
*
|
|
241
474
|
* The returned `dispose()` is this host's lifecycle owner: it clears the
|
|
242
475
|
* pending alarm `setTimeout` (so it can never fire against a connection this
|
|
@@ -247,13 +480,68 @@ interface NodeShardHostOptions {
|
|
|
247
480
|
* connection are always retired together.
|
|
248
481
|
*/
|
|
249
482
|
declare const createNodeShardHost: (options?: NodeShardHostOptions) => {
|
|
483
|
+
/** Settles once every alarm delivery running now (its handler and any retry write) has; `undefined` when none is. */
|
|
484
|
+
alarmsSettled: () => Promise<unknown> | undefined;
|
|
250
485
|
database: Database.Database;
|
|
251
486
|
dispose: () => void;
|
|
252
487
|
drain: () => Promise<void>;
|
|
253
488
|
host: ShardHost;
|
|
489
|
+
pendingAlarms: () => number;
|
|
490
|
+
pendingBackground: () => number;
|
|
491
|
+
/** Stop arming and claiming alarms, leaving the durable row for a restart. One-way: a closing registry calls it. */
|
|
492
|
+
suspendAlarms: () => void;
|
|
493
|
+
/** The failures recorded since the last call, which a drain reports in its result; each is also logged when it happens. */
|
|
494
|
+
takeFailures: () => string[];
|
|
254
495
|
};
|
|
496
|
+
/** The end a shard accepts. Its `send` and `close` are what the socket host calls through its handle. */
|
|
497
|
+
interface NodeServerEnd {
|
|
498
|
+
close: (code?: number, reason?: string) => void;
|
|
499
|
+
send: (data: string | ArrayBuffer) => void;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* The socket-host half of a Node platform instance, plus the test-only hooks
|
|
503
|
+
* `@lunora/platform/conformance`'s `ConformanceHost` needs to drive a recycle
|
|
504
|
+
* from inside a test.
|
|
505
|
+
*/
|
|
506
|
+
interface NodeSocketHost {
|
|
507
|
+
/**
|
|
508
|
+
* Wait for every close handler still running, including ones they start. `undefined` when none are,
|
|
509
|
+
* so a caller can dispose synchronously.
|
|
510
|
+
*/
|
|
511
|
+
drain: () => Promise<void> | undefined;
|
|
512
|
+
/** Deliver a connection's close to `handler`, which calls `webSocketClose`. One handler per host. */
|
|
513
|
+
onClose: (handler: (socket: NodeServerEnd, code: number, reason: string, wasClean: boolean) => void | Promise<void>) => void;
|
|
514
|
+
/**
|
|
515
|
+
* Deliver a connection's inbound frames to `handler`. The handler is the
|
|
516
|
+
* shard that accepted the connection, so it calls `webSocketMessage`. One
|
|
517
|
+
* handler per host: a later call replaces the earlier one.
|
|
518
|
+
*/
|
|
519
|
+
onMessage: (handler: (socket: NodeServerEnd, data: string | ArrayBuffer) => void) => void;
|
|
520
|
+
/** Read back the frames sent to a socket, oldest first, text frames only. */
|
|
521
|
+
readFrames: (handle: SocketHandle) => string[];
|
|
522
|
+
/**
|
|
523
|
+
* Re-create a runtime socket from durable state.
|
|
524
|
+
*
|
|
525
|
+
* `attachment` is a fallback only: this host restores what it persisted,
|
|
526
|
+
* because that is what a real wake looks like. The argument covers an id
|
|
527
|
+
* this host never durably tracked (a synthetic id a test constructs).
|
|
528
|
+
*/
|
|
529
|
+
restoreSocket: (id: string, attachment: unknown) => SocketHandle;
|
|
530
|
+
/** Drop the runtime socket map while keeping durable attachments/tags. */
|
|
531
|
+
simulateRecycle: () => void;
|
|
532
|
+
/** The `SocketHost` contract implementation. */
|
|
533
|
+
socket: SocketHost;
|
|
534
|
+
}
|
|
535
|
+
/** Build the socket registry, persisting attachments and tags to `database`. */
|
|
536
|
+
declare const createNodeSocketHost: (database: Database.Database) => NodeSocketHost;
|
|
255
537
|
/** The contracts scoped to one shard key. */
|
|
256
538
|
interface NodeShard {
|
|
539
|
+
/**
|
|
540
|
+
* Inbound socket events for this shard's registry. Bind the shard that owns
|
|
541
|
+
* the sockets here, so a frame or close reaches its `webSocketMessage` and
|
|
542
|
+
* `webSocketClose`. See `bindShardSockets`.
|
|
543
|
+
*/
|
|
544
|
+
inbound: Pick<NodeSocketHost, "onClose" | "onMessage">;
|
|
257
545
|
/** Durable key-value storage on this shard's database. */
|
|
258
546
|
kv: ShardKvStore;
|
|
259
547
|
/** Single-writer execution, local SQL, transactions, durable alarms. */
|
|
@@ -289,10 +577,32 @@ interface NodeShardRegistryOptions {
|
|
|
289
577
|
}
|
|
290
578
|
/** An in-process shard registry: placement, hosting, and the fan-out key set. */
|
|
291
579
|
interface NodeShardRegistry {
|
|
292
|
-
/**
|
|
293
|
-
|
|
580
|
+
/**
|
|
581
|
+
* Dispose every live shard, and refuse new work from then on: `shardFor`, a stub's `fetch` and `rearmPersistedAlarms`
|
|
582
|
+
* throw once this is called, so nothing reopens a shard. Safe to call more than once. A shard that a request or a socket
|
|
583
|
+
* close handler is still using is disposed once that work settles, unless `force` is set: then it is disposed now and
|
|
584
|
+
* named in a log line. A shard whose dispose fails stays live; a failure after close() returned is logged and reported by
|
|
585
|
+
* the next `drain()`, and the next `close()` retries it. A shutdown passes `force` after its drain has finished or
|
|
586
|
+
* reached its deadline, so work that never settles cannot keep a database open at exit.
|
|
587
|
+
*/
|
|
588
|
+
close: (options?: {
|
|
589
|
+
force?: boolean;
|
|
590
|
+
}) => void;
|
|
294
591
|
/** The `ShardDirectory` to hand the runtime. */
|
|
295
592
|
directory: DirectShardDirectory;
|
|
593
|
+
/**
|
|
594
|
+
* Wait until every shard is idle: no `onFetch` or `onAlarm` call in flight (a cron or scheduled job's delivery is one), no
|
|
595
|
+
* promise handed to a shard's `waitUntil` pending, and no socket close handler still running, across every live shard,
|
|
596
|
+
* including one opened while draining. Work that starts more work is waited for too. Bounded by `timeoutMs` (30 s by
|
|
597
|
+
* default); resolves with what was still running when it passed, which it also logs. A graceful shutdown awaits this, then
|
|
598
|
+
* calls {@link NodeShardRegistry.close}; `close()` alone does not wait for any of it.
|
|
599
|
+
*/
|
|
600
|
+
drain: (options?: DrainOptions) => Promise<DrainResult>;
|
|
601
|
+
/**
|
|
602
|
+
* Whether every shard is idle right now (nothing a {@link NodeShardRegistry.drain} would wait for). Synchronous, so a caller
|
|
603
|
+
* that drained several things can confirm all of them are still idle at one instant before it closes anything.
|
|
604
|
+
*/
|
|
605
|
+
idle: () => boolean;
|
|
296
606
|
/**
|
|
297
607
|
* Every shard key this registry knows about — the set `@lunora/runtime`'s
|
|
298
608
|
* query coordinator fans out over.
|
|
@@ -305,27 +615,91 @@ interface NodeShardRegistry {
|
|
|
305
615
|
* cost of visiting shards that had nothing to say.
|
|
306
616
|
*/
|
|
307
617
|
listShardKeys: (table?: string) => ReadonlyArray<string>;
|
|
618
|
+
/** What is running right now, one label per shard with its counts, as a drain that timed out would report it. */
|
|
619
|
+
pending: () => string[];
|
|
620
|
+
/**
|
|
621
|
+
* Open every stored shard that has a persisted alarm, so the alarm is re-armed now rather than when something next sends
|
|
622
|
+
* that shard a request: after a restart an alarm would otherwise never fire on a shard nobody calls. Shards without one stay
|
|
623
|
+
* closed. Returns the keys it opened. A process serving the registry calls this once, before it takes traffic.
|
|
624
|
+
*/
|
|
625
|
+
rearmPersistedAlarms: () => string[];
|
|
308
626
|
/** Materialize (or reuse) the shard serving `key`. */
|
|
309
627
|
shardFor: (key: string) => NodeShard;
|
|
628
|
+
/**
|
|
629
|
+
* Stop arming and claiming alarms on every shard, including one opened afterwards, leaving each durable row to re-arm after
|
|
630
|
+
* a restart. A shutdown calls it before draining, so no alarm starts after the drain checked for running work. One-way;
|
|
631
|
+
* `close()` does it too.
|
|
632
|
+
*/
|
|
633
|
+
suspendAlarms: () => void;
|
|
310
634
|
}
|
|
311
635
|
/** Build the in-process shard registry. */
|
|
312
636
|
declare const createNodeShardRegistry: (options?: NodeShardRegistryOptions) => NodeShardRegistry;
|
|
637
|
+
/** Options for {@link createNodeWorkflowHost}. */
|
|
638
|
+
interface NodeWorkflowHostOptions<Workflows extends Record<string, {
|
|
639
|
+
isLunoraWorkflow: true;
|
|
640
|
+
}>> {
|
|
641
|
+
/** Base env merged under the derived workflow bindings — surfaced to workflow bodies as `ctx.env` and used to resolve spawned children. */
|
|
642
|
+
env?: Record<string, unknown>;
|
|
643
|
+
/** How long (ms) the engine holds a cross-process lease while an activation runs, for stores that implement `acquire`. Defaults to 30000. */
|
|
644
|
+
leaseTtlMs?: number;
|
|
645
|
+
/** Where runs are persisted. Required — see the header for why there is no default. `createNodeWorkflowStore(database)` is the durable one. */
|
|
646
|
+
store: WorkflowStore;
|
|
647
|
+
/** The declared workflows keyed by their `lunora/workflows.ts` export name (e.g. `{ orderPipeline: orderPipeline }`). Values must be `defineWorkflow` results. */
|
|
648
|
+
workflows: Workflows;
|
|
649
|
+
}
|
|
650
|
+
/** A fully-wired Node workflow host. */
|
|
651
|
+
interface NodeWorkflowHost<Workflows extends Record<string, {
|
|
652
|
+
isLunoraWorkflow: true;
|
|
653
|
+
}>> {
|
|
654
|
+
/** Per-export-name `WorkflowBindingLike` — the map `ctx.workflows` consumes. */
|
|
655
|
+
readonly bindings: { [K in keyof Workflows]: WorkflowBindingLike; };
|
|
656
|
+
/**
|
|
657
|
+
* The caller's `env` plus one binding per workflow under its class name
|
|
658
|
+
* (`OrderPipelineWorkflow`), the key `ctx.exports` would carry on Cloudflare —
|
|
659
|
+
* merge this into a worker env so `ctx.spawn`/`ctx.parallel` resolve
|
|
660
|
+
* children through the same runtime.
|
|
661
|
+
*/
|
|
662
|
+
readonly env: Record<string, unknown>;
|
|
663
|
+
/** The underlying visulima runtime — `sweep`/`signal` for a dev loop or tests. */
|
|
664
|
+
readonly runtime: WorkflowRuntime;
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Create a Node workflow host: compile every declared Lunora workflow onto the
|
|
668
|
+
* visulima engine, derive the workflow env, and expose the per-workflow
|
|
669
|
+
* `WorkflowBindingLike` handles.
|
|
670
|
+
*/
|
|
671
|
+
declare const createNodeWorkflowHost: <Workflows extends Record<string, {
|
|
672
|
+
isLunoraWorkflow: true;
|
|
673
|
+
}>>(options: NodeWorkflowHostOptions<Workflows>) => NodeWorkflowHost<Workflows>;
|
|
674
|
+
/** One entry of the generated `LUNORA_CRONS` map (`_generated/crons.ts`). */
|
|
675
|
+
interface NodeCronJob {
|
|
676
|
+
args?: Record<string, unknown>;
|
|
677
|
+
functionPath?: string;
|
|
678
|
+
name: string;
|
|
679
|
+
workflow?: string;
|
|
680
|
+
}
|
|
313
681
|
/** Every contract this package provides, composed for one Node process. */
|
|
314
682
|
interface NodePlatform<Queues extends Record<string, {
|
|
315
683
|
isLunoraQueue: true;
|
|
684
|
+
}> = Record<string, never>, Workflows extends Record<string, {
|
|
685
|
+
isLunoraWorkflow: true;
|
|
316
686
|
}> = Record<string, never>> {
|
|
317
687
|
/** `using platform = createNodePlatform(...)` support — delegates to `close()`. */
|
|
318
688
|
[Symbol.dispose]: () => void;
|
|
319
689
|
/** What this target supports — see `NODE_CAPABILITIES` in `@lunora/platform`. */
|
|
320
690
|
capabilities: PlatformCapabilities;
|
|
321
691
|
/**
|
|
322
|
-
* Tear this platform instance down:
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
692
|
+
* Tear this platform instance down: every resource this root built, in
|
|
693
|
+
* reverse construction order — the global store's own connection, every
|
|
694
|
+
* armed scheduler job timer, the registry's live shards, and last the shard
|
|
695
|
+
* host's pending alarm timer and its `better-sqlite3` database (and, with
|
|
696
|
+
* it, `kv`'s table — both live on the same connection). Nothing in this
|
|
697
|
+
* package closes these resources on its own — a `NodePlatform` a caller
|
|
698
|
+
* stops using without calling `close()` leaks the open file handles (plus
|
|
699
|
+
* their WAL/SHM sidecar files) and keeps the process alive on outstanding
|
|
700
|
+
* timers. Safe to call more than once. A `createNodePlatform` that throws
|
|
701
|
+
* unwinds the same list itself, so a failed construction leaks nothing and
|
|
702
|
+
* leaves nothing to call this on.
|
|
329
703
|
*
|
|
330
704
|
* **`close()` is a terminal state, not merely a cleanup step.** After it
|
|
331
705
|
* runs: `scheduler.schedule()` throws instead of arming a fresh timer
|
|
@@ -340,21 +714,74 @@ interface NodePlatform<Queues extends Record<string, {
|
|
|
340
714
|
* any runtime socket map or durable row. A no-op instead of a throw would
|
|
341
715
|
* be indistinguishable from a working call — exactly the silent-vanishing
|
|
342
716
|
* this lifecycle exists to end.
|
|
717
|
+
*
|
|
718
|
+
* `force` is for a shutdown whose drain has finished or reached its deadline:
|
|
719
|
+
* a shard whose socket close handler is still running is disposed now (and
|
|
720
|
+
* logged) instead of once the handler settles. See `NodeShardRegistry.close`.
|
|
343
721
|
*/
|
|
344
|
-
close: (
|
|
722
|
+
close: (options?: {
|
|
723
|
+
force?: boolean;
|
|
724
|
+
}) => void;
|
|
345
725
|
/** In-process shard directory (see `createNodeShardRegistry` for what it can and cannot do). */
|
|
346
726
|
directory: ShardDirectory;
|
|
347
727
|
/**
|
|
348
|
-
*
|
|
728
|
+
* The scheduler dispatch route, served in-process: `Request` in, shard
|
|
729
|
+
* response out, no listener. It answers the path `@lunora/dispatch` and
|
|
730
|
+
* `@lunora/scheduler` POST to. Pass it to `dispatchQueueBatch` as
|
|
731
|
+
* `queueFetchImpl` on `createWorker` so a queue handler's `message.run` /
|
|
732
|
+
* `ctx.run` reaches the shard; the env you pass there must carry `LUNORA_ORIGIN_URL` and the same
|
|
733
|
+
* `LUNORA_ADMIN_TOKEN` as `dispatch.adminToken`. Every request is refused
|
|
734
|
+
* unless `dispatch` supplies a secret.
|
|
735
|
+
*/
|
|
736
|
+
dispatch: (request: Request) => Promise<Response>;
|
|
737
|
+
/**
|
|
738
|
+
* Wait for every promise handed to `shard.waitUntil` to settle, and for the
|
|
739
|
+
* registry's shards to go idle (`NodeShardRegistry.drain`): in-flight
|
|
740
|
+
* `onFetch` and `onAlarm` calls, including cron and scheduled-job
|
|
741
|
+
* deliveries, and each shard's own `waitUntil` work.
|
|
349
742
|
*
|
|
350
743
|
* Separate from `close()` because the two answer different questions:
|
|
351
744
|
* `close()` releases handles and stays synchronous (it backs
|
|
352
745
|
* `Symbol.dispose`), while draining is inherently awaitable. A graceful
|
|
353
|
-
* shutdown is `await platform.drain()` then `platform.close()`.
|
|
746
|
+
* shutdown is `await platform.drain()` then `platform.close()`. Bounded by
|
|
747
|
+
* `timeoutMs` (30 s by default); resolves with what was still running when
|
|
748
|
+
* it passed.
|
|
749
|
+
*
|
|
750
|
+
* Draining is the start of shutdown: it first stops the scheduler's job and
|
|
751
|
+
* cron timers and every alarm timer, so nothing new starts once the drain
|
|
752
|
+
* has found the platform idle. Their rows are kept and re-armed after a
|
|
753
|
+
* restart.
|
|
354
754
|
*/
|
|
355
|
-
drain: () => Promise<
|
|
755
|
+
drain: (options?: DrainOptions) => Promise<DrainResult>;
|
|
756
|
+
/**
|
|
757
|
+
* The `.global()` backend, or `undefined` when the caller named no database
|
|
758
|
+
* file for it. There is no default path, because a global store silently
|
|
759
|
+
* rooted at `:memory:` loses every row when the process exits.
|
|
760
|
+
*
|
|
761
|
+
* **A building block, not a wiring.** Unlike its three siblings, nothing
|
|
762
|
+
* downstream of this composition root reads it: a `.global()` read or write
|
|
763
|
+
* reaches its backend through exactly one seam, `createShardCtxDb({ globalDb
|
|
764
|
+
* })`, and the only thing that passes `globalDb` is the generated `shard.ts`,
|
|
765
|
+
* from its `d1` / `hyperdriveGlobal` config thunks. `createNodePlatform`
|
|
766
|
+
* constructs no shard DO, so it cannot make that hop itself. A caller that
|
|
767
|
+
* wants `.global()` on this host makes it: after `migrate(schema)` has
|
|
768
|
+
* provisioned the tables, give the generated `createShardDO` a `d1` thunk
|
|
769
|
+
* returning `platform.globalTables.writer({ schema, … })` — `writer` builds
|
|
770
|
+
* the `createSqlCtxDb` facade that seam expects, and `node-platform.test.ts`
|
|
771
|
+
* round-trips a row through exactly that object.
|
|
772
|
+
*/
|
|
773
|
+
globalTables?: NodeGlobalStore;
|
|
774
|
+
/**
|
|
775
|
+
* Whether nothing a {@link NodePlatform.drain} would wait for is running right now. Synchronous, so a caller draining
|
|
776
|
+
* several platforms or registries together can confirm they are all idle at one instant.
|
|
777
|
+
*/
|
|
778
|
+
idle: () => boolean;
|
|
356
779
|
/** Durable key-value storage backed by the same `better-sqlite3` database as `shard`. */
|
|
357
780
|
kv: ShardKvStore;
|
|
781
|
+
/** The local-filesystem bucket, or `undefined` when the caller named no bucket directory. */
|
|
782
|
+
objectStorage?: R2BucketLike;
|
|
783
|
+
/** What is running right now (host work, scheduler deliveries, each shard's work), as a timed-out drain would report it. */
|
|
784
|
+
pending: () => string[];
|
|
358
785
|
/**
|
|
359
786
|
* The declared queues, or `undefined` when the caller declared none.
|
|
360
787
|
*
|
|
@@ -363,12 +790,36 @@ interface NodePlatform<Queues extends Record<string, {
|
|
|
363
790
|
* works when no queue exists to send to.
|
|
364
791
|
*/
|
|
365
792
|
queues?: NodeQueueHost<Queues>;
|
|
793
|
+
/** Open every stored shard with a persisted alarm, so it is re-armed before traffic arrives. See `NodeShardRegistry.rearmPersistedAlarms`. */
|
|
794
|
+
rearmPersistedAlarms: () => string[];
|
|
366
795
|
/** Delayed jobs and crons, persisted to the same database and re-armed on construction. */
|
|
367
796
|
scheduler: SchedulerHost;
|
|
368
797
|
/** Single-writer execution, local SQL, transactions, durable alarms. */
|
|
369
798
|
shard: ShardHost;
|
|
370
799
|
/** Socket registry with mutable tags and SQLite-persisted attachments. */
|
|
371
800
|
sockets: SocketHost;
|
|
801
|
+
/**
|
|
802
|
+
* The declared workflows, or `undefined` when the caller declared none.
|
|
803
|
+
* Runs are persisted to the same `better-sqlite3` database as the shard, so
|
|
804
|
+
* they survive a restart without a second store to configure.
|
|
805
|
+
*/
|
|
806
|
+
workflows?: NodeWorkflowHost<Workflows>;
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* The secrets the dispatch route authenticates with. With neither, the route
|
|
810
|
+
* refuses everything.
|
|
811
|
+
*
|
|
812
|
+
* Queue and topic delivery authenticates with `adminToken` alone:
|
|
813
|
+
* `@lunora/dispatch` always sends `Bearer <LUNORA_ADMIN_TOKEN>` and never signs,
|
|
814
|
+
* so the value here must match the token the caller puts on the env it passes
|
|
815
|
+
* `dispatchQueueBatch`. `schedulerSecret` only verifies a signed body, which the
|
|
816
|
+
* scheduler's own delivery sends; queue delivery never does.
|
|
817
|
+
*/
|
|
818
|
+
interface NodePlatformDispatchOptions {
|
|
819
|
+
/** `LUNORA_ADMIN_TOKEN`. The bearer queue and topic delivery sends, so it must match the caller's env. */
|
|
820
|
+
adminToken?: string;
|
|
821
|
+
/** `LUNORA_SCHEDULER_SECRET`. When set, a signed body is verified against it. Queue delivery does not sign. */
|
|
822
|
+
schedulerSecret?: string;
|
|
372
823
|
}
|
|
373
824
|
/**
|
|
374
825
|
* Options for {@link createNodePlatform} — the shard host's (`path`,
|
|
@@ -378,23 +829,71 @@ interface NodePlatform<Queues extends Record<string, {
|
|
|
378
829
|
* or job with nowhere to land is bookkeeping. `directory` makes the shards the
|
|
379
830
|
* directory resolves for fan-out file-backed too, and `onAlarm` gives their
|
|
380
831
|
* durable alarms somewhere to land.
|
|
832
|
+
*
|
|
833
|
+
* `queues`, `workflows`, `objectStorageDirectory` and `globalTablesPath` are the
|
|
834
|
+
* four declarations — each is absent from the returned platform when omitted.
|
|
381
835
|
*/
|
|
382
836
|
type NodePlatformOptions<Queues extends Record<string, {
|
|
383
837
|
isLunoraQueue: true;
|
|
838
|
+
}> = Record<string, never>, Workflows extends Record<string, {
|
|
839
|
+
isLunoraWorkflow: true;
|
|
384
840
|
}> = Record<string, never>> = {
|
|
385
841
|
/**
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
842
|
+
* The app's declared crons — pass the generated `LUNORA_CRONS` map
|
|
843
|
+
* (`_generated/crons.ts`). Each job is armed on the scheduler and delivered
|
|
844
|
+
* through the same `onDispatch` a scheduled job uses, so it needs `onFetch`
|
|
845
|
+
* (or your own `onDispatch`) to reach a shard; a non-empty map with neither
|
|
846
|
+
* throws. Job names must be unique, every schedule must have a next
|
|
847
|
+
* occurrence, and schedules are read as UTC. The map is the whole declared
|
|
848
|
+
* set: a job declared by an earlier run and absent here is deleted. Omit
|
|
849
|
+
* the option and this process neither fires nor deletes declared jobs, so
|
|
850
|
+
* a script opening the same file leaves a running server's crons alone.
|
|
851
|
+
* Crons registered through `scheduler.cron()` are re-armed either way.
|
|
852
|
+
*/
|
|
853
|
+
crons?: Readonly<Record<string, ReadonlyArray<NodeCronJob>>>;
|
|
854
|
+
/** Secrets for the dispatch route. Omit to leave the route refusing every request. */
|
|
855
|
+
dispatch?: NodePlatformDispatchOptions;
|
|
856
|
+
/**
|
|
857
|
+
* Database file the `.global()` tables live in — its own file, never a
|
|
858
|
+
* shard's, because a table every shard reads must not be inside any one of
|
|
859
|
+
* them. Omit when the app declares no `.global()` table; there is no
|
|
860
|
+
* default, for the same reason the bucket has none.
|
|
861
|
+
*/
|
|
862
|
+
globalTablesPath?: string;
|
|
863
|
+
/**
|
|
864
|
+
* Directory the object-storage bucket keeps its objects in, one file per
|
|
865
|
+
* key. Omit when the app declares no buckets — there is no default,
|
|
866
|
+
* because a bucket silently rooted at the process's working directory is
|
|
867
|
+
* worse than an absent one.
|
|
868
|
+
*/
|
|
869
|
+
objectStorageDirectory?: string;
|
|
870
|
+
/**
|
|
871
|
+
* Deliver one assembled queue batch — wire this to the app worker's `queue`
|
|
872
|
+
* export from `createWorker`, not to bare `dispatchQueueBatch`. That export
|
|
873
|
+
* is the only path that hands the consumer `ctx.live`, and it takes
|
|
874
|
+
* `queueFetchImpl` (this platform's `dispatch`, wrapped as a `fetch`) so
|
|
875
|
+
* `ctx.run` reaches the shard here rather than `LUNORA_ORIGIN_URL`. Required
|
|
876
|
+
* alongside `queues`; without it the messages would be stored and never consumed.
|
|
389
877
|
*/
|
|
390
878
|
onQueueBatch?: NodeQueueHostOptions<Queues>["onBatch"];
|
|
391
879
|
/** The app's `defineQueue` results, keyed by export name. Omit when the app declares no queues. */
|
|
392
880
|
queues?: Queues;
|
|
881
|
+
/** The app's `defineWorkflow` results, keyed by export name. Omit when the app declares no workflows. */
|
|
882
|
+
workflows?: Workflows;
|
|
393
883
|
} & NodeSchedulerHostOptions & NodeShardHostOptions & NodeShardRegistryOptions;
|
|
394
884
|
/** Compose every contract this package provides over one `better-sqlite3` database. */
|
|
395
885
|
declare const createNodePlatform: <Queues extends Record<string, {
|
|
396
886
|
isLunoraQueue: true;
|
|
397
|
-
}> = Record<string, never
|
|
887
|
+
}> = Record<string, never>, Workflows extends Record<string, {
|
|
888
|
+
isLunoraWorkflow: true;
|
|
889
|
+
}> = Record<string, never>>(options?: NodePlatformOptions<Queues, Workflows>) => NodePlatform<Queues, Workflows>;
|
|
890
|
+
interface NodeProfileHandlerOptions {
|
|
891
|
+
/** The bearer a caller must present. Required and non-empty: an empty token would make the endpoint open to anyone. */
|
|
892
|
+
token: string;
|
|
893
|
+
}
|
|
894
|
+
type NodeProfileHandler = (request: Request) => Promise<Response>;
|
|
895
|
+
/** The public handler: the real profiler, guarded by `token`. */
|
|
896
|
+
declare const createNodeProfileHandler: ({ token }: NodeProfileHandlerOptions) => NodeProfileHandler;
|
|
398
897
|
/** Options for {@link createNodeR2Bucket}. */
|
|
399
898
|
interface NodeR2BucketOptions {
|
|
400
899
|
/** The bucket directory — created on first write. Objects live here, one file per key. */
|
|
@@ -402,10 +901,41 @@ interface NodeR2BucketOptions {
|
|
|
402
901
|
}
|
|
403
902
|
/**
|
|
404
903
|
* Create an `R2BucketLike` over the local filesystem. Any object shape
|
|
405
|
-
* `createStorage({ bucket })` accepts — `put`/`get`/`head`/`delete`/`list` —
|
|
904
|
+
* `createStorage({ bucket, bucketName })` accepts — `put`/`get`/`head`/`delete`/`list` —
|
|
406
905
|
* maps directly onto a file operation.
|
|
407
906
|
*/
|
|
408
907
|
declare const createNodeR2Bucket: (options: NodeR2BucketOptions) => R2BucketLike;
|
|
908
|
+
/** The shape `ctx.secrets` reads off `env[name]`: a Cloudflare Secrets Store secret binding. */
|
|
909
|
+
interface NodeSecretBinding {
|
|
910
|
+
get: () => Promise<string>;
|
|
911
|
+
}
|
|
912
|
+
/**
|
|
913
|
+
* Build the `ctx.secrets` bindings for a Node host from environment variables:
|
|
914
|
+
* one binding per name, spread into the `env` the worker and shard are built
|
|
915
|
+
* over. `ctx.secrets.get(name)` then reads `source[name]`.
|
|
916
|
+
*
|
|
917
|
+
* Names are listed rather than every variable in `source` being bound, for the
|
|
918
|
+
* same reason a wrangler config lists `secrets_store_secrets[]`: `ctx.secrets`
|
|
919
|
+
* reaches only what was granted to it. It also keeps the bindings off names the
|
|
920
|
+
* env already carries as plain strings (`LUNORA_ADMIN_TOKEN` and the like),
|
|
921
|
+
* which the runtime reads as strings and a binding object would break; a
|
|
922
|
+
* `LUNORA_*` name is refused for that reason.
|
|
923
|
+
*
|
|
924
|
+
* The value is read when `get()` is called, so an unused secret never has to be
|
|
925
|
+
* set. An unset or empty variable rejects the call.
|
|
926
|
+
* @param names The secret names the app reads through `ctx.secrets`.
|
|
927
|
+
* @param source Where values come from; `process.env` unless given.
|
|
928
|
+
*/
|
|
929
|
+
declare const createNodeSecretBindings: (names: ReadonlyArray<string>, source?: Readonly<Record<string, string | undefined>>) => Record<string, NodeSecretBinding>;
|
|
930
|
+
/**
|
|
931
|
+
* Present the node shard registry as the `ShardNamespaceLike` a worker is built
|
|
932
|
+
* over (`createWorker({ shardDO })`).
|
|
933
|
+
*
|
|
934
|
+
* The registry names its id derivation `idForName`, which is the
|
|
935
|
+
* `ShardDirectory` spelling; the worker reads Cloudflare's `idFromName`. Both
|
|
936
|
+
* return the key itself here, so a stub from either route reaches the same shard.
|
|
937
|
+
*/
|
|
938
|
+
declare const createNodeShardNamespace: (directory: DirectShardDirectory) => ShardNamespaceLike;
|
|
409
939
|
/**
|
|
410
940
|
* The `DurableObjectState` subset `ShardDO` consumes.
|
|
411
941
|
*
|
|
@@ -422,6 +952,11 @@ interface NodeShardState {
|
|
|
422
952
|
id: {
|
|
423
953
|
name?: string;
|
|
424
954
|
};
|
|
955
|
+
/** Open a connection pair. Read by `@lunora/platform-cloudflare`'s socket host, which has no `WebSocketPair` here. */
|
|
956
|
+
openSocketPair: () => {
|
|
957
|
+
client: unknown;
|
|
958
|
+
server: unknown;
|
|
959
|
+
};
|
|
425
960
|
storage: {
|
|
426
961
|
delete: (key: string) => Promise<boolean>;
|
|
427
962
|
deleteAlarm: () => Promise<void>;
|
|
@@ -438,6 +973,8 @@ interface NodeShardState {
|
|
|
438
973
|
};
|
|
439
974
|
transaction: <T>(closure: () => Promise<T>) => Promise<T>;
|
|
440
975
|
};
|
|
976
|
+
/** Build the upgrade response for a pair's client end. A Node `Response` cannot carry status 101, so this is a marker. */
|
|
977
|
+
upgradeResponse: (client: unknown) => Response;
|
|
441
978
|
waitUntil: (promise: Promise<unknown>) => void;
|
|
442
979
|
}
|
|
443
980
|
/**
|
|
@@ -452,71 +989,76 @@ interface NodeShardState {
|
|
|
452
989
|
* report a point-in-time restore that never happened.
|
|
453
990
|
*/
|
|
454
991
|
declare const createNodeShardState: (shard: NodeShard) => NodeShardState;
|
|
455
|
-
/**
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
*/
|
|
460
|
-
interface NodeSocketHost {
|
|
461
|
-
/** Read back the frames sent to a socket, oldest first, text frames only. */
|
|
462
|
-
readFrames: (handle: SocketHandle) => string[];
|
|
463
|
-
/**
|
|
464
|
-
* Re-create a runtime socket from durable state.
|
|
465
|
-
*
|
|
466
|
-
* `attachment` is a fallback only: this host restores what it persisted,
|
|
467
|
-
* because that is what a real wake looks like. The argument covers an id
|
|
468
|
-
* this host never durably tracked (a synthetic id a test constructs).
|
|
469
|
-
*/
|
|
470
|
-
restoreSocket: (id: string, attachment: unknown) => SocketHandle;
|
|
471
|
-
/** Drop the runtime socket map while keeping durable attachments/tags. */
|
|
472
|
-
simulateRecycle: () => void;
|
|
473
|
-
/** The `SocketHost` contract implementation. */
|
|
474
|
-
socket: SocketHost;
|
|
475
|
-
}
|
|
476
|
-
/** Build the socket registry, persisting attachments and tags to `database`. */
|
|
477
|
-
declare const createNodeSocketHost: (database: Database.Database) => NodeSocketHost;
|
|
478
|
-
/** Options for {@link createNodeWorkflowHost}. */
|
|
479
|
-
interface NodeWorkflowHostOptions<Workflows extends Record<string, {
|
|
480
|
-
isLunoraWorkflow: true;
|
|
481
|
-
}>> {
|
|
482
|
-
/** Base env merged under the derived `WORKFLOW_*` bindings — surfaced to workflow bodies as `ctx.env` and used to resolve spawned children. */
|
|
483
|
-
env?: Record<string, unknown>;
|
|
484
|
-
/** How long (ms) the engine holds a cross-process lease while an activation runs, for stores that implement `acquire`. Defaults to 30000. */
|
|
485
|
-
leaseTtlMs?: number;
|
|
486
|
-
/** Where runs are persisted. Required — see the header for why there is no default. `createNodeWorkflowStore(database)` is the durable one. */
|
|
487
|
-
store: WorkflowStore;
|
|
488
|
-
/** The declared workflows keyed by their `lunora/workflows.ts` export name (e.g. `{ orderPipeline: orderPipeline }`). Values must be `defineWorkflow` results. */
|
|
489
|
-
workflows: Workflows;
|
|
490
|
-
}
|
|
491
|
-
/** A fully-wired Node workflow host. */
|
|
492
|
-
interface NodeWorkflowHost<Workflows extends Record<string, {
|
|
493
|
-
isLunoraWorkflow: true;
|
|
494
|
-
}>> {
|
|
495
|
-
/** Per-export-name `WorkflowBindingLike` — the map `ctx.workflows` consumes. */
|
|
496
|
-
readonly bindings: { [K in keyof Workflows]: WorkflowBindingLike; };
|
|
497
|
-
/**
|
|
498
|
-
* The caller's `env` plus one `WORKFLOW_<EXPORT>` binding per workflow —
|
|
499
|
-
* merge this into a worker env so `ctx.spawn`/`ctx.parallel` resolve
|
|
500
|
-
* children through the same runtime.
|
|
501
|
-
*/
|
|
502
|
-
readonly env: Record<string, unknown>;
|
|
503
|
-
/** The underlying visulima runtime — `sweep`/`signal` for a dev loop or tests. */
|
|
504
|
-
readonly runtime: WorkflowRuntime;
|
|
992
|
+
/** The two socket hooks a `ShardDO` runs on the Cloudflare runtime's behalf. */
|
|
993
|
+
interface ShardSocketHooks {
|
|
994
|
+
webSocketClose(ws: unknown, code: number, reason: string, wasClean: boolean): unknown;
|
|
995
|
+
webSocketMessage(ws: unknown, message: string | ArrayBuffer): unknown;
|
|
505
996
|
}
|
|
506
997
|
/**
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
998
|
+
* Deliver a shard's inbound socket events. The Cloudflare runtime calls
|
|
999
|
+
* `webSocketMessage` and `webSocketClose` on the Durable Object for a hibernated
|
|
1000
|
+
* socket. On Node nothing does, so the embedder calls this once per shard
|
|
1001
|
+
* instance, at the same point it builds the shard.
|
|
510
1002
|
*/
|
|
511
|
-
declare const
|
|
512
|
-
isLunoraWorkflow: true;
|
|
513
|
-
}>>(options: NodeWorkflowHostOptions<Workflows>) => NodeWorkflowHost<Workflows>;
|
|
1003
|
+
declare const bindShardSockets: (shard: ShardSocketHooks, inbound: Pick<NodeShard["inbound"], "onClose" | "onMessage">) => void;
|
|
514
1004
|
/**
|
|
515
1005
|
* Build a durable {@link WorkflowStore} over a `better-sqlite3` connection.
|
|
516
1006
|
* Pass the result as `createNodeWorkflowHost({ store })`.
|
|
517
1007
|
*/
|
|
518
1008
|
declare const createNodeWorkflowStore: (database: Database.Database) => WorkflowStore;
|
|
519
|
-
export {
|
|
1009
|
+
export { DEFAULT_DRAIN_TIMEOUT_MS,
|
|
1010
|
+
/**
|
|
1011
|
+
* `@lunora/platform-node` — a Node implementation of the `@lunora/platform`
|
|
1012
|
+
* host contracts (`ShardHost`, `SocketHost`, `ShardDirectory`, `ShardKvStore`,
|
|
1013
|
+
* `SchedulerHost`) over `better-sqlite3` and an in-process socket/directory/
|
|
1014
|
+
* scheduler registry.
|
|
1015
|
+
*
|
|
1016
|
+
* Promoted from `@lunora/platform`'s `node:sqlite` reference host
|
|
1017
|
+
* (`src/conformance/reference-host.ts`) under plan 234, then hardened until the
|
|
1018
|
+
* durability half of each contract actually holds: alarms and scheduler jobs
|
|
1019
|
+
* are persisted **and re-armed on construction**, socket attachments and tags
|
|
1020
|
+
* live in SQLite rather than a `Map`, and `.global()` tables run the real
|
|
1021
|
+
* `@lunora/sql-store` core (`./node-global-store`). Each of those is pinned by
|
|
1022
|
+
* a restart test — a second host over the same database file — not only by the
|
|
1023
|
+
* TCK's simulated recycle.
|
|
1024
|
+
*
|
|
1025
|
+
* Three suites run against this package: `@lunora/platform/conformance`'s host
|
|
1026
|
+
* TCK, `@lunora/shard-engine/conformance`'s engine suite, and its own
|
|
1027
|
+
* lifecycle/global-store tests.
|
|
1028
|
+
*
|
|
1029
|
+
* **Emulated here**, and rated accordingly in `NODE_CAPABILITIES`
|
|
1030
|
+
* (`@lunora/platform`): queues over a durable table (`./node-queue-host`), R2
|
|
1031
|
+
* buckets over the local filesystem (`./node-r2-bucket`), workflows over the
|
|
1032
|
+
* `@visulima/workflow` engine (`./node-workflow-host`), and cross-shard fan-out
|
|
1033
|
+
* via `@lunora/runtime`'s query coordinator over the in-process shard registry.
|
|
1034
|
+
* `createNodePlatform` binds all three declarations (`queues`, `workflows`,
|
|
1035
|
+
* `objectStorageDirectory`) — a capability rated `emulated` with nothing bound
|
|
1036
|
+
* is the one combination that fails at runtime with no diagnostic before it.
|
|
1037
|
+
*
|
|
1038
|
+
* **Still missing:** a dev server. There is no `lunora dev --target node`, and
|
|
1039
|
+
* nothing here owns a timer, so queue delivery is driven by an explicit
|
|
1040
|
+
* `poll()`. What exists is the listener a dev server would sit on:
|
|
1041
|
+
* `createNodeHttpServer` serves an app worker's `fetch` over `node:http`,
|
|
1042
|
+
* streaming the response body, and `createNodeShardNamespace` presents the
|
|
1043
|
+
* registry as the `shardDO` namespace that worker routes to. Also absent are
|
|
1044
|
+
* the Cloudflare product bindings with no local
|
|
1045
|
+
* equivalent — Vectorize, Workers AI, Browser Rendering, Containers, Analytics
|
|
1046
|
+
* Engine, Pipelines. `ctx.secrets` reads environment variables through
|
|
1047
|
+
* `createNodeSecretBindings` (`./node-secrets`), and the Hyperdrive binding is
|
|
1048
|
+
* built from `DATABASE_URL` by `createNodeHyperdrive` (`./node-hyperdrive`).
|
|
1049
|
+
*
|
|
1050
|
+
* `lunora deploy --target node` bundles an app into a container build context
|
|
1051
|
+
* whose generated entry composes this package (crons, `ctx.secrets`,
|
|
1052
|
+
* Hyperdrive from `DATABASE_URL`) and serves it with `createNodeHttpServer`.
|
|
1053
|
+
*
|
|
1054
|
+
* `@lunora/config` ships a `node` **deploy** driver, so `--target node` resolves
|
|
1055
|
+
* for `provision` — which reports, once, which declared features this target
|
|
1056
|
+
* cannot serve, and writes nothing: there is no hosted control plane to deploy
|
|
1057
|
+
* to and no `wrangler`-equivalent to shell out to. A deploy driver is not a dev
|
|
1058
|
+
* server, which is why both statements above hold at once. See
|
|
1059
|
+
* `plans/234-node-host-findings.md`.
|
|
1060
|
+
*/
|
|
1061
|
+
type DrainOptions,
|
|
520
1062
|
/**
|
|
521
1063
|
* `@lunora/platform-node` — a Node implementation of the `@lunora/platform`
|
|
522
1064
|
* host contracts (`ShardHost`, `SocketHost`, `ShardDirectory`, `ShardKvStore`,
|
|
@@ -536,18 +1078,39 @@ export {
|
|
|
536
1078
|
* TCK, `@lunora/shard-engine/conformance`'s engine suite, and its own
|
|
537
1079
|
* lifecycle/global-store tests.
|
|
538
1080
|
*
|
|
539
|
-
* **
|
|
540
|
-
* (`@lunora/platform`):
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
*
|
|
1081
|
+
* **Emulated here**, and rated accordingly in `NODE_CAPABILITIES`
|
|
1082
|
+
* (`@lunora/platform`): queues over a durable table (`./node-queue-host`), R2
|
|
1083
|
+
* buckets over the local filesystem (`./node-r2-bucket`), workflows over the
|
|
1084
|
+
* `@visulima/workflow` engine (`./node-workflow-host`), and cross-shard fan-out
|
|
1085
|
+
* via `@lunora/runtime`'s query coordinator over the in-process shard registry.
|
|
1086
|
+
* `createNodePlatform` binds all three declarations (`queues`, `workflows`,
|
|
1087
|
+
* `objectStorageDirectory`) — a capability rated `emulated` with nothing bound
|
|
1088
|
+
* is the one combination that fails at runtime with no diagnostic before it.
|
|
1089
|
+
*
|
|
1090
|
+
* **Still missing:** a dev server. There is no `lunora dev --target node`, and
|
|
1091
|
+
* nothing here owns a timer, so queue delivery is driven by an explicit
|
|
1092
|
+
* `poll()`. What exists is the listener a dev server would sit on:
|
|
1093
|
+
* `createNodeHttpServer` serves an app worker's `fetch` over `node:http`,
|
|
1094
|
+
* streaming the response body, and `createNodeShardNamespace` presents the
|
|
1095
|
+
* registry as the `shardDO` namespace that worker routes to. Also absent are
|
|
1096
|
+
* the Cloudflare product bindings with no local
|
|
1097
|
+
* equivalent — Vectorize, Workers AI, Browser Rendering, Containers, Analytics
|
|
1098
|
+
* Engine, Pipelines. `ctx.secrets` reads environment variables through
|
|
1099
|
+
* `createNodeSecretBindings` (`./node-secrets`), and the Hyperdrive binding is
|
|
1100
|
+
* built from `DATABASE_URL` by `createNodeHyperdrive` (`./node-hyperdrive`).
|
|
1101
|
+
*
|
|
1102
|
+
* `lunora deploy --target node` bundles an app into a container build context
|
|
1103
|
+
* whose generated entry composes this package (crons, `ctx.secrets`,
|
|
1104
|
+
* Hyperdrive from `DATABASE_URL`) and serves it with `createNodeHttpServer`.
|
|
1105
|
+
*
|
|
1106
|
+
* `@lunora/config` ships a `node` **deploy** driver, so `--target node` resolves
|
|
1107
|
+
* for `provision` — which reports, once, which declared features this target
|
|
1108
|
+
* cannot serve, and writes nothing: there is no hosted control plane to deploy
|
|
1109
|
+
* to and no `wrangler`-equivalent to shell out to. A deploy driver is not a dev
|
|
1110
|
+
* server, which is why both statements above hold at once. See
|
|
548
1111
|
* `plans/234-node-host-findings.md`.
|
|
549
1112
|
*/
|
|
550
|
-
type
|
|
1113
|
+
type DrainResult,
|
|
551
1114
|
/**
|
|
552
1115
|
* `@lunora/platform-node` — a Node implementation of the `@lunora/platform`
|
|
553
1116
|
* host contracts (`ShardHost`, `SocketHost`, `ShardDirectory`, `ShardKvStore`,
|
|
@@ -567,18 +1130,39 @@ type NodeGlobalContextDatabaseOptions,
|
|
|
567
1130
|
* TCK, `@lunora/shard-engine/conformance`'s engine suite, and its own
|
|
568
1131
|
* lifecycle/global-store tests.
|
|
569
1132
|
*
|
|
570
|
-
* **
|
|
571
|
-
* (`@lunora/platform`):
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
*
|
|
1133
|
+
* **Emulated here**, and rated accordingly in `NODE_CAPABILITIES`
|
|
1134
|
+
* (`@lunora/platform`): queues over a durable table (`./node-queue-host`), R2
|
|
1135
|
+
* buckets over the local filesystem (`./node-r2-bucket`), workflows over the
|
|
1136
|
+
* `@visulima/workflow` engine (`./node-workflow-host`), and cross-shard fan-out
|
|
1137
|
+
* via `@lunora/runtime`'s query coordinator over the in-process shard registry.
|
|
1138
|
+
* `createNodePlatform` binds all three declarations (`queues`, `workflows`,
|
|
1139
|
+
* `objectStorageDirectory`) — a capability rated `emulated` with nothing bound
|
|
1140
|
+
* is the one combination that fails at runtime with no diagnostic before it.
|
|
1141
|
+
*
|
|
1142
|
+
* **Still missing:** a dev server. There is no `lunora dev --target node`, and
|
|
1143
|
+
* nothing here owns a timer, so queue delivery is driven by an explicit
|
|
1144
|
+
* `poll()`. What exists is the listener a dev server would sit on:
|
|
1145
|
+
* `createNodeHttpServer` serves an app worker's `fetch` over `node:http`,
|
|
1146
|
+
* streaming the response body, and `createNodeShardNamespace` presents the
|
|
1147
|
+
* registry as the `shardDO` namespace that worker routes to. Also absent are
|
|
1148
|
+
* the Cloudflare product bindings with no local
|
|
1149
|
+
* equivalent — Vectorize, Workers AI, Browser Rendering, Containers, Analytics
|
|
1150
|
+
* Engine, Pipelines. `ctx.secrets` reads environment variables through
|
|
1151
|
+
* `createNodeSecretBindings` (`./node-secrets`), and the Hyperdrive binding is
|
|
1152
|
+
* built from `DATABASE_URL` by `createNodeHyperdrive` (`./node-hyperdrive`).
|
|
1153
|
+
*
|
|
1154
|
+
* `lunora deploy --target node` bundles an app into a container build context
|
|
1155
|
+
* whose generated entry composes this package (crons, `ctx.secrets`,
|
|
1156
|
+
* Hyperdrive from `DATABASE_URL`) and serves it with `createNodeHttpServer`.
|
|
1157
|
+
*
|
|
1158
|
+
* `@lunora/config` ships a `node` **deploy** driver, so `--target node` resolves
|
|
1159
|
+
* for `provision` — which reports, once, which declared features this target
|
|
1160
|
+
* cannot serve, and writes nothing: there is no hosted control plane to deploy
|
|
1161
|
+
* to and no `wrangler`-equivalent to shell out to. A deploy driver is not a dev
|
|
1162
|
+
* server, which is why both statements above hold at once. See
|
|
579
1163
|
* `plans/234-node-host-findings.md`.
|
|
580
1164
|
*/
|
|
581
|
-
type
|
|
1165
|
+
type DrainTimer,
|
|
582
1166
|
/**
|
|
583
1167
|
* `@lunora/platform-node` — a Node implementation of the `@lunora/platform`
|
|
584
1168
|
* host contracts (`ShardHost`, `SocketHost`, `ShardDirectory`, `ShardKvStore`,
|
|
@@ -598,15 +1182,36 @@ type NodeGlobalStore,
|
|
|
598
1182
|
* TCK, `@lunora/shard-engine/conformance`'s engine suite, and its own
|
|
599
1183
|
* lifecycle/global-store tests.
|
|
600
1184
|
*
|
|
601
|
-
* **
|
|
602
|
-
* (`@lunora/platform`):
|
|
603
|
-
*
|
|
604
|
-
*
|
|
605
|
-
*
|
|
606
|
-
*
|
|
607
|
-
*
|
|
608
|
-
*
|
|
609
|
-
*
|
|
1185
|
+
* **Emulated here**, and rated accordingly in `NODE_CAPABILITIES`
|
|
1186
|
+
* (`@lunora/platform`): queues over a durable table (`./node-queue-host`), R2
|
|
1187
|
+
* buckets over the local filesystem (`./node-r2-bucket`), workflows over the
|
|
1188
|
+
* `@visulima/workflow` engine (`./node-workflow-host`), and cross-shard fan-out
|
|
1189
|
+
* via `@lunora/runtime`'s query coordinator over the in-process shard registry.
|
|
1190
|
+
* `createNodePlatform` binds all three declarations (`queues`, `workflows`,
|
|
1191
|
+
* `objectStorageDirectory`) — a capability rated `emulated` with nothing bound
|
|
1192
|
+
* is the one combination that fails at runtime with no diagnostic before it.
|
|
1193
|
+
*
|
|
1194
|
+
* **Still missing:** a dev server. There is no `lunora dev --target node`, and
|
|
1195
|
+
* nothing here owns a timer, so queue delivery is driven by an explicit
|
|
1196
|
+
* `poll()`. What exists is the listener a dev server would sit on:
|
|
1197
|
+
* `createNodeHttpServer` serves an app worker's `fetch` over `node:http`,
|
|
1198
|
+
* streaming the response body, and `createNodeShardNamespace` presents the
|
|
1199
|
+
* registry as the `shardDO` namespace that worker routes to. Also absent are
|
|
1200
|
+
* the Cloudflare product bindings with no local
|
|
1201
|
+
* equivalent — Vectorize, Workers AI, Browser Rendering, Containers, Analytics
|
|
1202
|
+
* Engine, Pipelines. `ctx.secrets` reads environment variables through
|
|
1203
|
+
* `createNodeSecretBindings` (`./node-secrets`), and the Hyperdrive binding is
|
|
1204
|
+
* built from `DATABASE_URL` by `createNodeHyperdrive` (`./node-hyperdrive`).
|
|
1205
|
+
*
|
|
1206
|
+
* `lunora deploy --target node` bundles an app into a container build context
|
|
1207
|
+
* whose generated entry composes this package (crons, `ctx.secrets`,
|
|
1208
|
+
* Hyperdrive from `DATABASE_URL`) and serves it with `createNodeHttpServer`.
|
|
1209
|
+
*
|
|
1210
|
+
* `@lunora/config` ships a `node` **deploy** driver, so `--target node` resolves
|
|
1211
|
+
* for `provision` — which reports, once, which declared features this target
|
|
1212
|
+
* cannot serve, and writes nothing: there is no hosted control plane to deploy
|
|
1213
|
+
* to and no `wrangler`-equivalent to shell out to. A deploy driver is not a dev
|
|
1214
|
+
* server, which is why both statements above hold at once. See
|
|
610
1215
|
* `plans/234-node-host-findings.md`.
|
|
611
1216
|
*/
|
|
612
|
-
type NodeGlobalStoreOptions, type NodePlatform, type NodePlatformOptions, type NodeQueueHost, type NodeQueueHostOptions, type NodeR2BucketOptions, type NodeSchedulerHost, type NodeSchedulerHostOptions, type NodeShard, type NodeShardHostOptions, type NodeShardRegistry, type NodeShardRegistryOptions, type NodeShardState, type NodeSocketHost, type NodeWorkflowHost, type NodeWorkflowHostOptions, createNodeGlobalStore, createNodePlatform, createNodeQueueHost, createNodeR2Bucket, createNodeSchedulerHost, createNodeShardHost, createNodeShardKvStore, createNodeShardRegistry, createNodeShardState, createNodeSocketHost, createNodeSqlExec, createNodeWorkflowHost, createNodeWorkflowStore };
|
|
1217
|
+
type Drainable, NODE_SCHEDULER_DISPATCH_PATH, type NodeCronJob, type NodeDeclaredCron, type NodeDispatchInvocation, type NodeDispatchRouteOptions, type NodeGlobalContextDatabaseOptions, type NodeGlobalStore, type NodeGlobalStoreOptions, type NodeHttpServer, type NodeHttpServerOptions, type NodeHyperdriveBinding, type NodePlatform, type NodePlatformDispatchOptions, type NodePlatformOptions, type NodeProfileHandler, type NodeProfileHandlerOptions, type NodeQueueHost, type NodeQueueHostOptions, type NodeR2BucketOptions, type NodeSchedulerHost, type NodeSchedulerHostOptions, type NodeSecretBinding, type NodeShard, type NodeShardHostOptions, type NodeShardRegistry, type NodeShardRegistryOptions, type NodeShardState, type NodeSocketHost, type NodeWorkflowHost, type NodeWorkflowHostOptions, type ShardSocketHooks, bindShardSockets, createNodeDispatchRoute, createNodeGlobalStore, createNodeHttpServer, createNodeHyperdrive, createNodePlatform, createNodeProfileHandler, createNodeQueueHost, createNodeR2Bucket, createNodeSchedulerHost, createNodeSecretBindings, createNodeShardHost, createNodeShardKvStore, createNodeShardNamespace, createNodeShardRegistry, createNodeShardState, createNodeSocketHost, createNodeSqlExec, createNodeWorkflowHost, createNodeWorkflowStore, drainTogether };
|