@lunora/platform-node 1.0.0-alpha.220 → 1.0.0-alpha.222
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/README.md +1 -1
- package/dist/conformance/index.mjs +1 -1
- package/dist/index.d.mts +318 -136
- package/dist/index.d.ts +318 -136
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{NODE_SCHEDULER_DISPATCH_PATH-uDl0zU2t.mjs → NODE_SCHEDULER_DISPATCH_PATH-DmMrAPjT.mjs} +1 -1
- package/dist/packem_shared/bindShardSockets-DjLmRlIA.mjs +1 -0
- package/dist/packem_shared/checkNodeAppHost-Cv5p7igg.mjs +1 -0
- package/dist/packem_shared/createNodeDurableObjectFactory-hAwJt_pN.mjs +1 -0
- package/dist/packem_shared/createNodeMailHost-DrUo8de-.mjs +8 -0
- package/dist/packem_shared/createNodePlatform-De8dIBya.mjs +1 -0
- package/dist/packem_shared/createNodeQueueHost-glQ8GNCA.mjs +17 -0
- package/dist/packem_shared/createNodeShardHost-DZ2cwIKF.mjs +1 -0
- package/dist/packem_shared/createNodeShardRegistry-D1r6M8Rg.mjs +1 -0
- package/dist/packem_shared/node-dispatch-route-B3GAZkHT.mjs +2 -0
- package/package.json +3 -2
- package/dist/packem_shared/bindShardSockets-9GvSocBW.mjs +0 -1
- package/dist/packem_shared/createNodePlatform-C5LvauTf.mjs +0 -1
- package/dist/packem_shared/createNodeQueueHost-szMV0PBN.mjs +0 -17
- package/dist/packem_shared/createNodeShardHost-VU8MPeba.mjs +0 -1
- package/dist/packem_shared/createNodeShardRegistry-BHzxHBx1.mjs +0 -1
- package/dist/packem_shared/node-dispatch-route-ByuCR26s.mjs +0 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { QueueBindingLike, MessageBatchLike, SchedulerHost, ShardHost, SocketHandle, SocketHost, ShardKvStore, DirectShardDirectory, PlatformCapabilities, R2BucketLike } from '@lunora/platform';
|
|
1
2
|
import { SchemaLike } from '@lunora/shard-engine';
|
|
2
3
|
import { SqlCtxDbOptions, SqlCtxExec, createSqlCtxDb } from '@lunora/sql-store';
|
|
3
4
|
import Database from 'better-sqlite3';
|
|
4
|
-
import {
|
|
5
|
+
import { Mailer, QueueLike, MailEnv, MailTransport } from '@lunora/mail';
|
|
5
6
|
import { WorkflowBindingLike } from '@lunora/workflow';
|
|
6
7
|
import { WorkflowRuntime, WorkflowStore } from '@visulima/workflow';
|
|
7
8
|
import { ShardNamespaceLike } from '@lunora/runtime';
|
|
@@ -154,78 +155,79 @@ interface NodeGlobalStore {
|
|
|
154
155
|
* which is the whole point of the dialect seam.
|
|
155
156
|
*/
|
|
156
157
|
declare const createNodeGlobalStore: (options?: NodeGlobalStoreOptions) => NodeGlobalStore;
|
|
157
|
-
/**
|
|
158
|
-
|
|
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;
|
|
158
|
+
/** Options for {@link createNodeMailHost}. */
|
|
159
|
+
interface NodeMailHostOptions {
|
|
165
160
|
/**
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
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.
|
|
161
|
+
* Where `MAIL_FROM`, `RESEND_API_KEY` and the capture switches
|
|
162
|
+
* (`LUNORA_MAIL_CAPTURE`, `WORKER_ENV`, …) are read, once, at construction.
|
|
163
|
+
* `process.env` unless given.
|
|
171
164
|
*/
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
/** A listening server. */
|
|
177
|
-
interface NodeHttpServer {
|
|
178
|
-
/** Stop accepting connections and end every open one, streams included. */
|
|
179
|
-
close: () => Promise<void>;
|
|
165
|
+
env?: MailEnv;
|
|
166
|
+
/** The host clock, shared with the queue host so a retry delay and `poll(now)` agree. Defaults to `Date.now`. */
|
|
167
|
+
now?: () => number;
|
|
180
168
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
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.
|
|
169
|
+
* Deliver through this, an SMTP client, another provider or a test double.
|
|
170
|
+
* It wins over `RESEND_API_KEY`, which is only read without it. Ignored while
|
|
171
|
+
* the env selects capture, as `createMailerFromEnv` ignores a transport then.
|
|
186
172
|
*/
|
|
187
|
-
|
|
188
|
-
/** The `http://host:port` origin the server answers on. */
|
|
189
|
-
origin: string;
|
|
173
|
+
transport?: MailTransport;
|
|
190
174
|
}
|
|
175
|
+
/** Queued mail delivery for one Node process. */
|
|
191
176
|
/**
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
177
|
+
* Why a send sits in `deadLetters`: its retries ran out (`retries_exhausted`); its idempotency key
|
|
178
|
+
* belongs to other content (`idempotency_key_conflict`); an earlier delivery may have been sent
|
|
179
|
+
* and the provider no longer drops a repeat (`outcome_unknown`), so the provider's logs decide;
|
|
180
|
+
* or that may be so and the record of it has expired (`evidence_expired`). `unknown` is a row
|
|
181
|
+
* parked with no reason recorded (by a build before reasons, or a process that stopped first),
|
|
182
|
+
* which may be any of these, so treat it as `outcome_unknown` until the provider's logs say.
|
|
196
183
|
*/
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
184
|
+
type MailParkReason = "evidence_expired" | "idempotency_key_conflict" | "outcome_unknown" | "retries_exhausted" | "unknown";
|
|
185
|
+
interface NodeMailHost {
|
|
186
|
+
/** Sends that failed past the queue's retries, parked by the queue host rather than dropped. */
|
|
187
|
+
deadLetters: {
|
|
188
|
+
/** Each parked send, with why it was parked, so an operator can decide whether to requeue it. */
|
|
189
|
+
list: () => {
|
|
190
|
+
attempts: number;
|
|
191
|
+
body: unknown;
|
|
192
|
+
id: string;
|
|
193
|
+
reason: MailParkReason;
|
|
194
|
+
}[];
|
|
195
|
+
/**
|
|
196
|
+
* Return a parked send to the queue for one more delivery. Its attempt
|
|
197
|
+
* count is kept, so a send an earlier attempt may have delivered is
|
|
198
|
+
* refused once the provider no longer dedupes it. `false` when no mail
|
|
199
|
+
* send with that id is parked. Throws for one queued 15 or more days ago,
|
|
200
|
+
* whose attempt record in the sent ledger has expired.
|
|
201
|
+
*/
|
|
202
|
+
requeue: (id: string) => boolean;
|
|
203
|
+
};
|
|
204
|
+
/** Wait for every `poll()` in flight. `createNodePlatform`'s `drain()` calls it before the database can close. */
|
|
205
|
+
drain: () => Promise<void>;
|
|
206
|
+
/** Whether no `poll()` is in flight: what `createNodePlatform`'s `drain()` checks to end its passes. */
|
|
207
|
+
idle: () => boolean;
|
|
208
|
+
/** `queue()` enqueues onto {@link NodeMailHost.queue}; `send()` delivers now through the same transport. */
|
|
209
|
+
mailer: Mailer;
|
|
210
|
+
/** Deliver the queued sends that are due, and return how many batches went out. Nothing here runs on a timer. */
|
|
211
|
+
poll: (now?: number) => Promise<number>;
|
|
212
|
+
/**
|
|
213
|
+
* The producer: pass it as `createMailerFromEnv(env, { queue })` in your own
|
|
214
|
+
* module. A queued body needs an `idempotencyKey`, which `mailer.queue()` mints.
|
|
215
|
+
*/
|
|
216
|
+
queue: QueueLike;
|
|
204
217
|
}
|
|
205
218
|
/**
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
* the
|
|
210
|
-
*
|
|
219
|
+
* Create queued mail delivery over `database`: a durable `lunora-mail` queue, a
|
|
220
|
+
* mailer whose `queue()` writes to it, and `poll()` to drain it through the given
|
|
221
|
+
* `transport` or, without one, Resend (`RESEND_API_KEY`). In a dev environment
|
|
222
|
+
* the mailer captures instead, exactly as `createMailerFromEnv` decides on
|
|
223
|
+
* Cloudflare. Throws when `MAIL_FROM` is unset or nothing can deliver.
|
|
211
224
|
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
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
|
+
* Give it a connection nothing else opens a transaction on, ideally a file of
|
|
226
|
+
* its own, as `createNodePlatform({ mail: { path } })` does: on a shard host's
|
|
227
|
+
* connection, a poll during `shard.transaction()` writes inside it, and that
|
|
228
|
+
* transaction's rollback would undo the acks and sent records and resend.
|
|
225
229
|
*/
|
|
226
|
-
declare const
|
|
227
|
-
/** Build a `ShardKvStore` over a `better-sqlite3` table in the shard's database. */
|
|
228
|
-
declare const createNodeShardKvStore: (database: Database.Database) => ShardKvStore;
|
|
230
|
+
declare const createNodeMailHost: (database: Database.Database, options?: NodeMailHostOptions) => NodeMailHost;
|
|
229
231
|
/** Options for {@link createNodeQueueHost}. */
|
|
230
232
|
interface NodeQueueHostOptions<Queues extends Record<string, {
|
|
231
233
|
isLunoraQueue: true;
|
|
@@ -279,7 +281,7 @@ interface NodeQueueHost<Queues extends Record<string, {
|
|
|
279
281
|
body: unknown;
|
|
280
282
|
id: string;
|
|
281
283
|
}[];
|
|
282
|
-
/** Return a parked message to its queue with `attempts` reset. `false` when no
|
|
284
|
+
/** Return a parked message to its queue with `attempts` reset. `false` when no message of a queue this host declared is parked under that id. */
|
|
283
285
|
requeue: (id: string) => boolean;
|
|
284
286
|
};
|
|
285
287
|
/** The caller's `env` plus one `QUEUE_<EXPORT>` binding per queue. */
|
|
@@ -479,7 +481,8 @@ interface NodeShardHostOptions {
|
|
|
479
481
|
* rather than closing `database` directly, so the alarm timer and the
|
|
480
482
|
* connection are always retired together.
|
|
481
483
|
*/
|
|
482
|
-
|
|
484
|
+
/** What {@link createNodeShardHost} returns. */
|
|
485
|
+
interface NodeShardHostParts {
|
|
483
486
|
/** Settles once every alarm delivery running now (its handler and any retry write) has; `undefined` when none is. */
|
|
484
487
|
alarmsSettled: () => Promise<unknown> | undefined;
|
|
485
488
|
database: Database.Database;
|
|
@@ -492,7 +495,8 @@ declare const createNodeShardHost: (options?: NodeShardHostOptions) => {
|
|
|
492
495
|
suspendAlarms: () => void;
|
|
493
496
|
/** The failures recorded since the last call, which a drain reports in its result; each is also logged when it happens. */
|
|
494
497
|
takeFailures: () => string[];
|
|
495
|
-
}
|
|
498
|
+
}
|
|
499
|
+
declare const createNodeShardHost: (options?: NodeShardHostOptions) => NodeShardHostParts;
|
|
496
500
|
/** The end a shard accepts. Its `send` and `close` are what the socket host calls through its handle. */
|
|
497
501
|
interface NodeServerEnd {
|
|
498
502
|
close: (code?: number, reason?: string) => void;
|
|
@@ -723,7 +727,7 @@ interface NodePlatform<Queues extends Record<string, {
|
|
|
723
727
|
force?: boolean;
|
|
724
728
|
}) => void;
|
|
725
729
|
/** In-process shard directory (see `createNodeShardRegistry` for what it can and cannot do). */
|
|
726
|
-
directory:
|
|
730
|
+
directory: DirectShardDirectory;
|
|
727
731
|
/**
|
|
728
732
|
* The scheduler dispatch route, served in-process: `Request` in, shard
|
|
729
733
|
* response out, no listener. It answers the path `@lunora/dispatch` and
|
|
@@ -735,10 +739,11 @@ interface NodePlatform<Queues extends Record<string, {
|
|
|
735
739
|
*/
|
|
736
740
|
dispatch: (request: Request) => Promise<Response>;
|
|
737
741
|
/**
|
|
738
|
-
* Wait for every promise handed to `shard.waitUntil` to settle,
|
|
739
|
-
* registry's shards to go idle
|
|
740
|
-
* `onFetch` and `onAlarm` calls,
|
|
741
|
-
* deliveries, and each shard's own
|
|
742
|
+
* Wait for every promise handed to `shard.waitUntil` to settle, for every
|
|
743
|
+
* `mail.poll()` in flight, and for the registry's shards to go idle
|
|
744
|
+
* (`NodeShardRegistry.drain`): in-flight `onFetch` and `onAlarm` calls,
|
|
745
|
+
* including cron and scheduled-job deliveries, and each shard's own
|
|
746
|
+
* `waitUntil` work.
|
|
742
747
|
*
|
|
743
748
|
* Separate from `close()` because the two answer different questions:
|
|
744
749
|
* `close()` releases handles and stays synchronous (it backs
|
|
@@ -778,6 +783,14 @@ interface NodePlatform<Queues extends Record<string, {
|
|
|
778
783
|
idle: () => boolean;
|
|
779
784
|
/** Durable key-value storage backed by the same `better-sqlite3` database as `shard`. */
|
|
780
785
|
kv: ShardKvStore;
|
|
786
|
+
/**
|
|
787
|
+
* Queued mail delivery, or `undefined` when the caller passed no `mail`.
|
|
788
|
+
* Its queue, sent ledger and key records live in `mail.path`, a database file
|
|
789
|
+
* of its own on its own connection, never the shard's: construction refuses a
|
|
790
|
+
* path that is the shard's file, the `globalTablesPath` file, or a `.sqlite3`
|
|
791
|
+
* file in the shard registry's `directory`.
|
|
792
|
+
*/
|
|
793
|
+
mail?: NodeMailHost;
|
|
781
794
|
/** The local-filesystem bucket, or `undefined` when the caller named no bucket directory. */
|
|
782
795
|
objectStorage?: R2BucketLike;
|
|
783
796
|
/** What is running right now (host work, scheduler deliveries, each shard's work), as a timed-out drain would report it. */
|
|
@@ -805,6 +818,18 @@ interface NodePlatform<Queues extends Record<string, {
|
|
|
805
818
|
*/
|
|
806
819
|
workflows?: NodeWorkflowHost<Workflows>;
|
|
807
820
|
}
|
|
821
|
+
/**
|
|
822
|
+
* `createNodePlatform`'s `mail` option: the {@link NodeMailHostOptions} plus the
|
|
823
|
+
* database file the mail host keeps its queue, sent ledger and key records in.
|
|
824
|
+
*
|
|
825
|
+
* Its own file, never the shard's, and there is no default: a shard transaction
|
|
826
|
+
* holds the shard file across awaits, and mail written inside it would be rolled
|
|
827
|
+
* back with it (see `composeMail`). The same reason `globalTablesPath` has none.
|
|
828
|
+
*/
|
|
829
|
+
type NodePlatformMailOptions = NodeMailHostOptions & {
|
|
830
|
+
/** The mail database file, for example `./.lunora/mail.sqlite3`. */
|
|
831
|
+
path: string;
|
|
832
|
+
};
|
|
808
833
|
/**
|
|
809
834
|
* The secrets the dispatch route authenticates with. With neither, the route
|
|
810
835
|
* refuses everything.
|
|
@@ -860,6 +885,15 @@ type NodePlatformOptions<Queues extends Record<string, {
|
|
|
860
885
|
* default, for the same reason the bucket has none.
|
|
861
886
|
*/
|
|
862
887
|
globalTablesPath?: string;
|
|
888
|
+
/**
|
|
889
|
+
* Deliver `@lunora/mail` sends: a durable `lunora-mail` queue drained
|
|
890
|
+
* through the given `transport` or, without one, Resend (`RESEND_API_KEY`), exposed as
|
|
891
|
+
* `platform.mail`. Its queue, sent ledger and key records live in `path`, a
|
|
892
|
+
* database file of their own (see {@link NodePlatformMailOptions}). Omit when
|
|
893
|
+
* the app sends no mail. Throws here, not on the first send, when `MAIL_FROM`
|
|
894
|
+
* is unset or nothing can deliver.
|
|
895
|
+
*/
|
|
896
|
+
mail?: NodePlatformMailOptions;
|
|
863
897
|
/**
|
|
864
898
|
* Directory the object-storage bucket keeps its objects in, one file per
|
|
865
899
|
* key. Omit when the app declares no buckets — there is no default,
|
|
@@ -887,6 +921,142 @@ declare const createNodePlatform: <Queues extends Record<string, {
|
|
|
887
921
|
}> = Record<string, never>, Workflows extends Record<string, {
|
|
888
922
|
isLunoraWorkflow: true;
|
|
889
923
|
}> = Record<string, never>>(options?: NodePlatformOptions<Queues, Workflows>) => NodePlatform<Queues, Workflows>;
|
|
924
|
+
/** One `durable_objects.bindings[]` entry: the `env` key and the exported class behind it. */
|
|
925
|
+
interface NodeAppDurableObjectBinding {
|
|
926
|
+
className: string;
|
|
927
|
+
name: string;
|
|
928
|
+
}
|
|
929
|
+
/** Options for {@link createNodeAppHost}. */
|
|
930
|
+
interface NodeAppHostOptions {
|
|
931
|
+
/**
|
|
932
|
+
* The app's declared crons — the generated `LUNORA_CRONS` map. Armed on the {@link NodeAppHostOptions.shardBinding} platform and
|
|
933
|
+
* delivered to its default shard, as `createNodePlatform`'s `crons` are. The map is the whole declared set, so a host built
|
|
934
|
+
* without a job an earlier one declared deletes it.
|
|
935
|
+
*/
|
|
936
|
+
crons?: Readonly<Record<string, ReadonlyArray<NodeCronJob>>>;
|
|
937
|
+
/**
|
|
938
|
+
* Directory the shard databases live in, one subdirectory per binding. Omit for in-memory shards, which lose every row when the
|
|
939
|
+
* host closes.
|
|
940
|
+
*/
|
|
941
|
+
dataDirectory?: string;
|
|
942
|
+
/** The wrangler config's `durable_objects.bindings`. Each `className` must be a named export of `worker`. */
|
|
943
|
+
durableObjects: ReadonlyArray<NodeAppDurableObjectBinding>;
|
|
944
|
+
/** Plain values for `env`: vars, dev vars, and any binding the caller composes itself. A Durable Object binding of the same name wins. */
|
|
945
|
+
env?: Record<string, unknown>;
|
|
946
|
+
/** The Durable Object binding whose shards run functions, which is where crons fire. Defaults to `SHARD`. */
|
|
947
|
+
shardBinding?: string;
|
|
948
|
+
/** The imported worker module. */
|
|
949
|
+
worker: Record<string, unknown>;
|
|
950
|
+
}
|
|
951
|
+
/** A worker module composed over this host. */
|
|
952
|
+
interface NodeAppHost {
|
|
953
|
+
/**
|
|
954
|
+
* Drain, then close: wait under one deadline (`timeoutMs`, 30 s by default) for the requests `fetch` is still answering, the
|
|
955
|
+
* worker's `waitUntil` work, and every
|
|
956
|
+
* platform to go idle (in-flight shard requests, alarms, cron deliveries and each shard's own `waitUntil` work), then close
|
|
957
|
+
* every platform, cron timers included. The close runs whether or not the drain finished in time, so a reload never opens the
|
|
958
|
+
* databases while this host still holds them. Resolves with what the drain cut off or saw fail. Safe to call more than once.
|
|
959
|
+
*/
|
|
960
|
+
close: (options?: DrainOptions) => Promise<DrainResult>;
|
|
961
|
+
/** The worker's `fetch`, bound to the composed `env`. Hand it to `createNodeHttpServer`. */
|
|
962
|
+
fetch: (request: Request) => Promise<Response>;
|
|
963
|
+
/**
|
|
964
|
+
* Open every stored shard with a persisted alarm, so its alarm fires without waiting for a request to reach it. Call once
|
|
965
|
+
* the host serves; a shard opens its database here, so a caller replacing an older host calls it after closing that one.
|
|
966
|
+
*/
|
|
967
|
+
rearmPersistedAlarms: () => string[];
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Throw what `createNodeAppHost` would refuse for `options`, without opening a database or arming a timer: the default export,
|
|
971
|
+
* every binding's name and class, and the declared crons. `createNodeAppHost` runs it before building anything, so a refused composition
|
|
972
|
+
* changes no stored state (cron rows included); a caller replacing a running host runs it first, so a refused candidate leaves
|
|
973
|
+
* that host serving.
|
|
974
|
+
*/
|
|
975
|
+
declare const checkNodeAppHost: (options: NodeAppHostOptions) => void;
|
|
976
|
+
/** Compose `worker` over one in-process platform per Durable Object binding. */
|
|
977
|
+
declare const createNodeAppHost: (options: NodeAppHostOptions) => NodeAppHost;
|
|
978
|
+
/** What a Durable Object instance must answer on this host. The socket and alarm hooks are optional, as on Cloudflare. */
|
|
979
|
+
interface NodeDurableObjectInstance {
|
|
980
|
+
alarm?: () => Promise<void> | void;
|
|
981
|
+
fetch: (request: Request) => Promise<Response> | Response;
|
|
982
|
+
webSocketClose?: (socket: unknown, code: number, reason: string, wasClean: boolean) => Promise<void> | void;
|
|
983
|
+
webSocketMessage?: (socket: unknown, data: ArrayBuffer | string) => Promise<void> | void;
|
|
984
|
+
}
|
|
985
|
+
type NodeDurableObjectClass = new (state: never, env: Record<string, unknown>) => NodeDurableObjectInstance;
|
|
986
|
+
/** The instance of `DurableObject` for a shard, constructed on first use and once it is ready. */
|
|
987
|
+
declare const createNodeDurableObjectFactory: (DurableObject: NodeDurableObjectClass, env: Record<string, unknown>) => ((shard: NodeShard) => Promise<NodeDurableObjectInstance>);
|
|
988
|
+
/** Serve `options.fetch` over `node:http`. Resolves once the server is listening. */
|
|
989
|
+
declare const createNodeHttpServer: (options: NodeHttpServerOptions) => Promise<NodeHttpServer>;
|
|
990
|
+
/** Options for {@link createNodeHttpServer}. */
|
|
991
|
+
interface NodeHttpServerOptions {
|
|
992
|
+
/** The app worker's `fetch`, already bound to its env and context. */
|
|
993
|
+
fetch: (request: Request) => Promise<Response> | Response;
|
|
994
|
+
/** Host to bind. Defaults to the loopback interface. */
|
|
995
|
+
host?: string;
|
|
996
|
+
/**
|
|
997
|
+
* The public base URL the app is served at, e.g. `https://app.example`. Every request URL uses its origin, so origin-sensitive
|
|
998
|
+
* behaviour (CSRF, WebSocket origin checks, cookie rules) sees the public scheme behind a TLS proxy. The client's `Host` header is
|
|
999
|
+
* never used. Defaults to the bound `http://host:port`, which is only allowed for a loopback `host`: binding a non-loopback address
|
|
1000
|
+
* (e.g. `0.0.0.0` or a LAN IP) without `origin` makes {@link createNodeHttpServer} reject, because browsers would send that address
|
|
1001
|
+
* as `Origin` and fail the CSRF check. Set `origin` to the URL users open.
|
|
1002
|
+
*/
|
|
1003
|
+
origin?: string;
|
|
1004
|
+
/** Port to bind. `0` (the default) picks a free ephemeral port. */
|
|
1005
|
+
port?: number;
|
|
1006
|
+
}
|
|
1007
|
+
/** A listening server. */
|
|
1008
|
+
interface NodeHttpServer {
|
|
1009
|
+
/** Stop accepting connections and end every open one, streams included. */
|
|
1010
|
+
close: () => Promise<void>;
|
|
1011
|
+
/**
|
|
1012
|
+
* Stop accepting connections, then wait until every HTTP response that was in progress when the drain began has been written
|
|
1013
|
+
* to the end or its client has gone, or until the deadline passes (`timeoutMs`, 30 s by default). A request that still
|
|
1014
|
+
* arrives on an open connection is answered with keep-alive off and is not waited for. Event streams (`text/event-stream`)
|
|
1015
|
+
* and WebSockets are endless by design and are not waited for; {@link NodeHttpServer.close} ends them. Resolves with what was
|
|
1016
|
+
* still unfinished when the deadline passed, which it also logs.
|
|
1017
|
+
*/
|
|
1018
|
+
drain: (options?: DrainOptions) => Promise<DrainResult>;
|
|
1019
|
+
/** The `http://host:port` origin the server answers on. */
|
|
1020
|
+
origin: string;
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* The connection fields a Cloudflare `Hyperdrive` binding exposes, and the
|
|
1024
|
+
* `HyperdriveLike` shape `@lunora/hyperdrive`'s `createHyperdrive` reads.
|
|
1025
|
+
* Declared here structurally so this package does not depend on
|
|
1026
|
+
* `@lunora/hyperdrive` for a type.
|
|
1027
|
+
*/
|
|
1028
|
+
interface NodeHyperdriveBinding {
|
|
1029
|
+
connectionString: string;
|
|
1030
|
+
database: string;
|
|
1031
|
+
host: string;
|
|
1032
|
+
password: string;
|
|
1033
|
+
port: number;
|
|
1034
|
+
user: string;
|
|
1035
|
+
}
|
|
1036
|
+
/**
|
|
1037
|
+
* Build the `HYPERDRIVE` binding for a Node host from a database URL, by
|
|
1038
|
+
* default `process.env.DATABASE_URL`. Put it on the `env` the worker and shard
|
|
1039
|
+
* are built over, under the binding name the app reads (`env.HYPERDRIVE`), and
|
|
1040
|
+
* the app's own `.hyperdrive((env) => …)` wiring builds `ctx.sql` from it
|
|
1041
|
+
* unchanged.
|
|
1042
|
+
*
|
|
1043
|
+
* There is no pool or query cache in front of the database here: the driver
|
|
1044
|
+
* the app constructs from `connectionString` connects to it directly, so its own
|
|
1045
|
+
* pool settings are the only ones that apply.
|
|
1046
|
+
* A Postgres URL may name a Unix socket the libpq way: an empty host with the
|
|
1047
|
+
* socket directory in a `host` query parameter (`postgres:///db?host=/var/run/postgresql`),
|
|
1048
|
+
* which becomes the binding's `host`.
|
|
1049
|
+
*
|
|
1050
|
+
* A URL with any TLS option other than an explicit off (`sslmode=prefer` or
|
|
1051
|
+
* `require`, `ssl=true`, `sslrootcert=…`) gets a binding whose discrete fields
|
|
1052
|
+
* throw: they cannot carry it, so a pool built from them would silently connect
|
|
1053
|
+
* without TLS. `sslmode=disable` and `ssl=false` keep them. Build the driver
|
|
1054
|
+
* from `connectionString`, which keeps every query option.
|
|
1055
|
+
* @param url A `postgres://`, `postgresql://`, `mysql://` or `mariadb://` URL; `DATABASE_URL` unless given.
|
|
1056
|
+
*/
|
|
1057
|
+
declare const createNodeHyperdrive: (url?: string | undefined) => NodeHyperdriveBinding;
|
|
1058
|
+
/** Build a `ShardKvStore` over a `better-sqlite3` table in the shard's database. */
|
|
1059
|
+
declare const createNodeShardKvStore: (database: Database.Database) => ShardKvStore;
|
|
890
1060
|
interface NodeProfileHandlerOptions {
|
|
891
1061
|
/** The bearer a caller must present. Required and non-empty: an empty token would make the endpoint open to anyone. */
|
|
892
1062
|
token: string;
|
|
@@ -988,7 +1158,11 @@ interface NodeShardState {
|
|
|
988
1158
|
* one local `wrangler dev` takes — whereas supplying a stub that resolves would
|
|
989
1159
|
* report a point-in-time restore that never happened.
|
|
990
1160
|
*/
|
|
991
|
-
|
|
1161
|
+
/**
|
|
1162
|
+
* `onBlockConcurrency` sees each `blockConcurrencyWhile` promise as it starts, so a caller can tell when the work an object's
|
|
1163
|
+
* constructor gated behind it has finished (see `createNodeDurableObjectFactory`).
|
|
1164
|
+
*/
|
|
1165
|
+
declare const createNodeShardState: (shard: NodeShard, onBlockConcurrency?: (work: Promise<unknown>) => void) => NodeShardState;
|
|
992
1166
|
/** The two socket hooks a `ShardDO` runs on the Cloudflare runtime's behalf. */
|
|
993
1167
|
interface ShardSocketHooks {
|
|
994
1168
|
webSocketClose(ws: unknown, code: number, reason: string, wasClean: boolean): unknown;
|
|
@@ -1035,28 +1209,30 @@ export { DEFAULT_DRAIN_TIMEOUT_MS,
|
|
|
1035
1209
|
* `objectStorageDirectory`) — a capability rated `emulated` with nothing bound
|
|
1036
1210
|
* is the one combination that fails at runtime with no diagnostic before it.
|
|
1037
1211
|
*
|
|
1038
|
-
* **
|
|
1039
|
-
*
|
|
1040
|
-
* `
|
|
1041
|
-
* `
|
|
1042
|
-
*
|
|
1043
|
-
*
|
|
1044
|
-
*
|
|
1045
|
-
*
|
|
1046
|
-
*
|
|
1047
|
-
*
|
|
1048
|
-
*
|
|
1212
|
+
* **Serving an app.** `createNodeAppHost` composes a worker entry module over
|
|
1213
|
+
* one shard registry per Durable Object binding, and `createNodeHttpServer`
|
|
1214
|
+
* serves its `fetch` over `node:http`, streaming the response body. `lunora dev
|
|
1215
|
+
* --target node` runs exactly that pair. Nothing here owns a timer, so queue
|
|
1216
|
+
* delivery is driven by an explicit `poll()`. Absent are the Cloudflare product
|
|
1217
|
+
* bindings with no local equivalent — Vectorize, Workers AI, Browser Rendering,
|
|
1218
|
+
* Containers, Analytics Engine, Pipelines. `ctx.secrets` reads environment
|
|
1219
|
+
* variables through `createNodeSecretBindings` (`./node-secrets`), and the
|
|
1220
|
+
* Hyperdrive binding is built from `DATABASE_URL` by `createNodeHyperdrive`
|
|
1221
|
+
* (`./node-hyperdrive`). Queued `@lunora/mail` sends are delivered by
|
|
1222
|
+
* `createNodeMailHost` (`./node-mail-host`) through Resend or a caller-supplied
|
|
1223
|
+
* transport, for a process that composes it and polls it, as the server
|
|
1224
|
+
* `lunora deploy --target node` writes does. `lunora dev --target node` composes
|
|
1225
|
+
* none: there mail is captured to the Studio inbox, and with capture turned off
|
|
1226
|
+
* a queued send is not delivered.
|
|
1049
1227
|
*
|
|
1050
1228
|
* `lunora deploy --target node` bundles an app into a container build context
|
|
1051
1229
|
* whose generated entry composes this package (crons, `ctx.secrets`,
|
|
1052
1230
|
* Hyperdrive from `DATABASE_URL`) and serves it with `createNodeHttpServer`.
|
|
1053
1231
|
*
|
|
1054
1232
|
* `@lunora/config` ships a `node` **deploy** driver, so `--target node` resolves
|
|
1055
|
-
*
|
|
1056
|
-
*
|
|
1057
|
-
*
|
|
1058
|
-
* server, which is why both statements above hold at once. See
|
|
1059
|
-
* `plans/234-node-host-findings.md`.
|
|
1233
|
+
* and codegen gates against `NODE_CAPABILITIES`. There is no hosted control
|
|
1234
|
+
* plane to deploy to and no `wrangler`-equivalent to shell out to, which is why
|
|
1235
|
+
* the deploy stops at a build context. See `plans/234-node-host-findings.md`.
|
|
1060
1236
|
*/
|
|
1061
1237
|
type DrainOptions,
|
|
1062
1238
|
/**
|
|
@@ -1087,28 +1263,30 @@ type DrainOptions,
|
|
|
1087
1263
|
* `objectStorageDirectory`) — a capability rated `emulated` with nothing bound
|
|
1088
1264
|
* is the one combination that fails at runtime with no diagnostic before it.
|
|
1089
1265
|
*
|
|
1090
|
-
* **
|
|
1091
|
-
*
|
|
1092
|
-
* `
|
|
1093
|
-
* `
|
|
1094
|
-
*
|
|
1095
|
-
*
|
|
1096
|
-
*
|
|
1097
|
-
*
|
|
1098
|
-
*
|
|
1099
|
-
*
|
|
1100
|
-
*
|
|
1266
|
+
* **Serving an app.** `createNodeAppHost` composes a worker entry module over
|
|
1267
|
+
* one shard registry per Durable Object binding, and `createNodeHttpServer`
|
|
1268
|
+
* serves its `fetch` over `node:http`, streaming the response body. `lunora dev
|
|
1269
|
+
* --target node` runs exactly that pair. Nothing here owns a timer, so queue
|
|
1270
|
+
* delivery is driven by an explicit `poll()`. Absent are the Cloudflare product
|
|
1271
|
+
* bindings with no local equivalent — Vectorize, Workers AI, Browser Rendering,
|
|
1272
|
+
* Containers, Analytics Engine, Pipelines. `ctx.secrets` reads environment
|
|
1273
|
+
* variables through `createNodeSecretBindings` (`./node-secrets`), and the
|
|
1274
|
+
* Hyperdrive binding is built from `DATABASE_URL` by `createNodeHyperdrive`
|
|
1275
|
+
* (`./node-hyperdrive`). Queued `@lunora/mail` sends are delivered by
|
|
1276
|
+
* `createNodeMailHost` (`./node-mail-host`) through Resend or a caller-supplied
|
|
1277
|
+
* transport, for a process that composes it and polls it, as the server
|
|
1278
|
+
* `lunora deploy --target node` writes does. `lunora dev --target node` composes
|
|
1279
|
+
* none: there mail is captured to the Studio inbox, and with capture turned off
|
|
1280
|
+
* a queued send is not delivered.
|
|
1101
1281
|
*
|
|
1102
1282
|
* `lunora deploy --target node` bundles an app into a container build context
|
|
1103
1283
|
* whose generated entry composes this package (crons, `ctx.secrets`,
|
|
1104
1284
|
* Hyperdrive from `DATABASE_URL`) and serves it with `createNodeHttpServer`.
|
|
1105
1285
|
*
|
|
1106
1286
|
* `@lunora/config` ships a `node` **deploy** driver, so `--target node` resolves
|
|
1107
|
-
*
|
|
1108
|
-
*
|
|
1109
|
-
*
|
|
1110
|
-
* server, which is why both statements above hold at once. See
|
|
1111
|
-
* `plans/234-node-host-findings.md`.
|
|
1287
|
+
* and codegen gates against `NODE_CAPABILITIES`. There is no hosted control
|
|
1288
|
+
* plane to deploy to and no `wrangler`-equivalent to shell out to, which is why
|
|
1289
|
+
* the deploy stops at a build context. See `plans/234-node-host-findings.md`.
|
|
1112
1290
|
*/
|
|
1113
1291
|
type DrainResult,
|
|
1114
1292
|
/**
|
|
@@ -1139,28 +1317,30 @@ type DrainResult,
|
|
|
1139
1317
|
* `objectStorageDirectory`) — a capability rated `emulated` with nothing bound
|
|
1140
1318
|
* is the one combination that fails at runtime with no diagnostic before it.
|
|
1141
1319
|
*
|
|
1142
|
-
* **
|
|
1143
|
-
*
|
|
1144
|
-
* `
|
|
1145
|
-
* `
|
|
1146
|
-
*
|
|
1147
|
-
*
|
|
1148
|
-
*
|
|
1149
|
-
*
|
|
1150
|
-
*
|
|
1151
|
-
*
|
|
1152
|
-
*
|
|
1320
|
+
* **Serving an app.** `createNodeAppHost` composes a worker entry module over
|
|
1321
|
+
* one shard registry per Durable Object binding, and `createNodeHttpServer`
|
|
1322
|
+
* serves its `fetch` over `node:http`, streaming the response body. `lunora dev
|
|
1323
|
+
* --target node` runs exactly that pair. Nothing here owns a timer, so queue
|
|
1324
|
+
* delivery is driven by an explicit `poll()`. Absent are the Cloudflare product
|
|
1325
|
+
* bindings with no local equivalent — Vectorize, Workers AI, Browser Rendering,
|
|
1326
|
+
* Containers, Analytics Engine, Pipelines. `ctx.secrets` reads environment
|
|
1327
|
+
* variables through `createNodeSecretBindings` (`./node-secrets`), and the
|
|
1328
|
+
* Hyperdrive binding is built from `DATABASE_URL` by `createNodeHyperdrive`
|
|
1329
|
+
* (`./node-hyperdrive`). Queued `@lunora/mail` sends are delivered by
|
|
1330
|
+
* `createNodeMailHost` (`./node-mail-host`) through Resend or a caller-supplied
|
|
1331
|
+
* transport, for a process that composes it and polls it, as the server
|
|
1332
|
+
* `lunora deploy --target node` writes does. `lunora dev --target node` composes
|
|
1333
|
+
* none: there mail is captured to the Studio inbox, and with capture turned off
|
|
1334
|
+
* a queued send is not delivered.
|
|
1153
1335
|
*
|
|
1154
1336
|
* `lunora deploy --target node` bundles an app into a container build context
|
|
1155
1337
|
* whose generated entry composes this package (crons, `ctx.secrets`,
|
|
1156
1338
|
* Hyperdrive from `DATABASE_URL`) and serves it with `createNodeHttpServer`.
|
|
1157
1339
|
*
|
|
1158
1340
|
* `@lunora/config` ships a `node` **deploy** driver, so `--target node` resolves
|
|
1159
|
-
*
|
|
1160
|
-
*
|
|
1161
|
-
*
|
|
1162
|
-
* server, which is why both statements above hold at once. See
|
|
1163
|
-
* `plans/234-node-host-findings.md`.
|
|
1341
|
+
* and codegen gates against `NODE_CAPABILITIES`. There is no hosted control
|
|
1342
|
+
* plane to deploy to and no `wrangler`-equivalent to shell out to, which is why
|
|
1343
|
+
* the deploy stops at a build context. See `plans/234-node-host-findings.md`.
|
|
1164
1344
|
*/
|
|
1165
1345
|
type DrainTimer,
|
|
1166
1346
|
/**
|
|
@@ -1191,27 +1371,29 @@ type DrainTimer,
|
|
|
1191
1371
|
* `objectStorageDirectory`) — a capability rated `emulated` with nothing bound
|
|
1192
1372
|
* is the one combination that fails at runtime with no diagnostic before it.
|
|
1193
1373
|
*
|
|
1194
|
-
* **
|
|
1195
|
-
*
|
|
1196
|
-
* `
|
|
1197
|
-
* `
|
|
1198
|
-
*
|
|
1199
|
-
*
|
|
1200
|
-
*
|
|
1201
|
-
*
|
|
1202
|
-
*
|
|
1203
|
-
*
|
|
1204
|
-
*
|
|
1374
|
+
* **Serving an app.** `createNodeAppHost` composes a worker entry module over
|
|
1375
|
+
* one shard registry per Durable Object binding, and `createNodeHttpServer`
|
|
1376
|
+
* serves its `fetch` over `node:http`, streaming the response body. `lunora dev
|
|
1377
|
+
* --target node` runs exactly that pair. Nothing here owns a timer, so queue
|
|
1378
|
+
* delivery is driven by an explicit `poll()`. Absent are the Cloudflare product
|
|
1379
|
+
* bindings with no local equivalent — Vectorize, Workers AI, Browser Rendering,
|
|
1380
|
+
* Containers, Analytics Engine, Pipelines. `ctx.secrets` reads environment
|
|
1381
|
+
* variables through `createNodeSecretBindings` (`./node-secrets`), and the
|
|
1382
|
+
* Hyperdrive binding is built from `DATABASE_URL` by `createNodeHyperdrive`
|
|
1383
|
+
* (`./node-hyperdrive`). Queued `@lunora/mail` sends are delivered by
|
|
1384
|
+
* `createNodeMailHost` (`./node-mail-host`) through Resend or a caller-supplied
|
|
1385
|
+
* transport, for a process that composes it and polls it, as the server
|
|
1386
|
+
* `lunora deploy --target node` writes does. `lunora dev --target node` composes
|
|
1387
|
+
* none: there mail is captured to the Studio inbox, and with capture turned off
|
|
1388
|
+
* a queued send is not delivered.
|
|
1205
1389
|
*
|
|
1206
1390
|
* `lunora deploy --target node` bundles an app into a container build context
|
|
1207
1391
|
* whose generated entry composes this package (crons, `ctx.secrets`,
|
|
1208
1392
|
* Hyperdrive from `DATABASE_URL`) and serves it with `createNodeHttpServer`.
|
|
1209
1393
|
*
|
|
1210
1394
|
* `@lunora/config` ships a `node` **deploy** driver, so `--target node` resolves
|
|
1211
|
-
*
|
|
1212
|
-
*
|
|
1213
|
-
*
|
|
1214
|
-
* server, which is why both statements above hold at once. See
|
|
1215
|
-
* `plans/234-node-host-findings.md`.
|
|
1395
|
+
* and codegen gates against `NODE_CAPABILITIES`. There is no hosted control
|
|
1396
|
+
* plane to deploy to and no `wrangler`-equivalent to shell out to, which is why
|
|
1397
|
+
* the deploy stops at a build context. See `plans/234-node-host-findings.md`.
|
|
1216
1398
|
*/
|
|
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 };
|
|
1399
|
+
type Drainable, type MailParkReason, NODE_SCHEDULER_DISPATCH_PATH, type NodeAppDurableObjectBinding, type NodeAppHost, type NodeAppHostOptions, type NodeCronJob, type NodeDeclaredCron, type NodeDispatchInvocation, type NodeDispatchRouteOptions, type NodeDurableObjectClass, type NodeDurableObjectInstance, type NodeGlobalContextDatabaseOptions, type NodeGlobalStore, type NodeGlobalStoreOptions, type NodeHttpServer, type NodeHttpServerOptions, type NodeHyperdriveBinding, type NodeMailHost, type NodeMailHostOptions, type NodePlatform, type NodePlatformDispatchOptions, type NodePlatformMailOptions, 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, checkNodeAppHost, createNodeAppHost, createNodeDispatchRoute, createNodeDurableObjectFactory, createNodeGlobalStore, createNodeHttpServer, createNodeHyperdrive, createNodeMailHost, createNodePlatform, createNodeProfileHandler, createNodeQueueHost, createNodeR2Bucket, createNodeSchedulerHost, createNodeSecretBindings, createNodeShardHost, createNodeShardKvStore, createNodeShardNamespace, createNodeShardRegistry, createNodeShardState, createNodeSocketHost, createNodeSqlExec, createNodeWorkflowHost, createNodeWorkflowStore, drainTogether };
|