@lunora/runtime 1.0.0-alpha.1 → 1.0.0-alpha.10
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/__assets__/package-og.svg +1 -1
- package/dist/index.d.mts +172 -5
- package/dist/index.d.ts +172 -5
- package/dist/index.mjs +7 -6
- package/dist/packem_shared/{createDynamicShardRegistry-BpCwo_mo.mjs → DEFAULT_REGISTRY_CACHE_TTL_MS-ocax8v0n.mjs} +4 -1
- package/dist/packem_shared/NOOP_EXECUTION_CONTEXT-CCTu0Bf1.mjs +8 -0
- package/dist/packem_shared/applyJurisdiction-BkZtTkct.mjs +20 -0
- package/dist/packem_shared/{composeWorker-BYHiNH_V.mjs → composeWorker-BEv9IBWS.mjs} +165 -41
- package/dist/packem_shared/{createQueryCoordinator-DbxC7iUz.mjs → createQueryCoordinator-Cbds9cUI.mjs} +1 -1
- package/package.json +2 -2
- package/dist/packem_shared/resolveShard-DDkzWtrU.mjs +0 -9
- /package/dist/packem_shared/{consoleSink-DqEvrQs0.mjs → analyticsEngineSink-DqEvrQs0.mjs} +0 -0
- /package/dist/packem_shared/{emitRpcEvent-pEdtqAK8.mjs → emitLogEvent-pEdtqAK8.mjs} +0 -0
package/dist/index.d.mts
CHANGED
|
@@ -110,6 +110,38 @@ declare const toFivetranResponse: (page: ConnectorSyncPage, primaryKey?: Record<
|
|
|
110
110
|
* @param emittedAt epoch-ms stamped on each `RECORD` (default `Date.now()`).
|
|
111
111
|
*/
|
|
112
112
|
declare const toAirbyteMessages: (page: ConnectorSyncPage, emittedAt?: number) => AirbyteMessage[];
|
|
113
|
+
/**
|
|
114
|
+
* The subset of the Cloudflare `ExecutionContext` the Lunora worker entry and
|
|
115
|
+
* the framework mount seams rely on — `waitUntil` for fire-and-forget work that
|
|
116
|
+
* must outlive the response, and `passThroughOnException` for the top-level
|
|
117
|
+
* error posture.
|
|
118
|
+
*
|
|
119
|
+
* It is deliberately **not** a package. `@lunora/runtime` is the leaf server
|
|
120
|
+
* runtime and `@lunora/nuxt` is a framework integration that intentionally does
|
|
121
|
+
* not depend on `@lunora/runtime`'s worker types, yet both need this exact
|
|
122
|
+
* shape: the runtime to build/forward the worker `fetch`, Nuxt to forward an
|
|
123
|
+
* inbound request to the user's composed worker. Each imports this file by
|
|
124
|
+
* relative path and the bundler (packem/rollup) inlines it: no runtime
|
|
125
|
+
* dependency edge is created, the helper is duplicated only in emitted output,
|
|
126
|
+
* never in source. One source of truth, zero deps. See AGENTS.md → "Top-level
|
|
127
|
+
* `shared/` — bundler-inlined source".
|
|
128
|
+
*
|
|
129
|
+
* Both methods are **optional**: a real Cloudflare `ExecutionContext` always
|
|
130
|
+
* supplies them, but a host that mounts Lunora as a sub-handler (Nitro/H3, a
|
|
131
|
+
* non-Cloudflare preview, a unit test) may hand over a partial context or none
|
|
132
|
+
* at all. Callers therefore invoke them defensively (`ctx.waitUntil?.(…)`) or
|
|
133
|
+
* fall back to {@link NOOP_EXECUTION_CONTEXT}.
|
|
134
|
+
*/
|
|
135
|
+
interface ExecutionContextLike {
|
|
136
|
+
passThroughOnException?: () => void;
|
|
137
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* No-op `ExecutionContext` used when the host runtime didn't supply one (a
|
|
141
|
+
* non-Cloudflare preview, or a unit test), so the worker's `fetch` always
|
|
142
|
+
* receives a valid third argument.
|
|
143
|
+
*/
|
|
144
|
+
declare const NOOP_EXECUTION_CONTEXT: ExecutionContextLike;
|
|
113
145
|
/** A timestamp as better-auth stores it: epoch-ms, an ISO string, or absent. */
|
|
114
146
|
type AuthTimestamp = null | number | string;
|
|
115
147
|
/**
|
|
@@ -420,6 +452,14 @@ declare const emitRpcEvent: (sink: ObservabilitySink | undefined, event: Observa
|
|
|
420
452
|
*/
|
|
421
453
|
declare const emitLogEvent: (sink: ObservabilitySink | undefined, event: LogEvent, context?: ObservabilitySinkContext) => void;
|
|
422
454
|
/**
|
|
455
|
+
* Cloudflare Durable Object jurisdictions restrict where a DO runs and persists
|
|
456
|
+
* data, for data-residency / compliance regimes (GDPR, FedRAMP, US data
|
|
457
|
+
* residency). The set is open — Cloudflare adds values over time — so this is a
|
|
458
|
+
* widening union rather than a closed enum.
|
|
459
|
+
* @see https://developers.cloudflare.com/durable-objects/reference/data-location/
|
|
460
|
+
*/
|
|
461
|
+
type DurableObjectJurisdiction = "eu" | "fedramp" | "us";
|
|
462
|
+
/**
|
|
423
463
|
* Structural projection of the bits of `DurableObjectNamespace` the runtime
|
|
424
464
|
* needs. Real workers-types defines a much wider surface; this lets us pass
|
|
425
465
|
* unit-test doubles without coupling to `@cloudflare/workers-types`.
|
|
@@ -437,10 +477,29 @@ interface ShardNamespaceLike {
|
|
|
437
477
|
fetch: (request: Request) => Promise<Response>;
|
|
438
478
|
};
|
|
439
479
|
idFromName: (name: string) => unknown;
|
|
480
|
+
/**
|
|
481
|
+
* Derive a jurisdiction-restricted subnamespace. Every ID and stub created
|
|
482
|
+
* from the returned namespace is pinned to `jurisdiction`. Optional because
|
|
483
|
+
* older workers-types releases (and unit-test doubles) may not expose it;
|
|
484
|
+
* {@link applyJurisdiction} fails closed when a jurisdiction is requested
|
|
485
|
+
* but this method is absent.
|
|
486
|
+
*/
|
|
487
|
+
jurisdiction?: (jurisdiction: DurableObjectJurisdiction) => ShardNamespaceLike;
|
|
440
488
|
}
|
|
441
489
|
interface ResolvedShard {
|
|
442
490
|
fetch: (request: Request) => Promise<Response>;
|
|
443
491
|
}
|
|
492
|
+
/**
|
|
493
|
+
* Return a jurisdiction-restricted view of `namespace`, or `namespace`
|
|
494
|
+
* unchanged when no jurisdiction is configured.
|
|
495
|
+
*
|
|
496
|
+
* Fail-closed: if a jurisdiction is requested but the binding does not expose
|
|
497
|
+
* `.jurisdiction()` (an older workers-types, or a misconfigured test double),
|
|
498
|
+
* this throws rather than silently routing to the un-pinned global namespace —
|
|
499
|
+
* silently dropping a residency constraint would let data land outside the
|
|
500
|
+
* compliance boundary the caller asked for.
|
|
501
|
+
*/
|
|
502
|
+
declare const applyJurisdiction: (namespace: ShardNamespaceLike, jurisdiction?: DurableObjectJurisdiction) => ShardNamespaceLike;
|
|
444
503
|
/** Look up a shard stub by name, preferring `getByName` when present. */
|
|
445
504
|
declare const resolveShard: (namespace: ShardNamespaceLike, shardKey: string) => ResolvedShard;
|
|
446
505
|
/**
|
|
@@ -1130,10 +1189,6 @@ interface RpcEnvelope {
|
|
|
1130
1189
|
functionPath: string;
|
|
1131
1190
|
shardKey?: string;
|
|
1132
1191
|
}
|
|
1133
|
-
interface ExecutionContextLike {
|
|
1134
|
-
passThroughOnException: () => void;
|
|
1135
|
-
waitUntil: (promise: Promise<unknown>) => void;
|
|
1136
|
-
}
|
|
1137
1192
|
type Route = (request: Request, env: unknown, context: ExecutionContextLike) => Promise<Response> | Response;
|
|
1138
1193
|
/**
|
|
1139
1194
|
* Context handed to HTTP-action handlers. Built per request by the worker; its
|
|
@@ -1472,6 +1527,12 @@ interface ScheduledControllerLike {
|
|
|
1472
1527
|
*/
|
|
1473
1528
|
type CronHandler = (controller: ScheduledControllerLike, env: unknown, context: ExecutionContextLike) => Promise<void> | void;
|
|
1474
1529
|
/**
|
|
1530
|
+
* A Cloudflare Queues push-consumer handler — the worker's `queue()` entry
|
|
1531
|
+
* forwards each delivered `MessageBatch` (typed `unknown` here to keep the
|
|
1532
|
+
* runtime decoupled from `@lunora/queue`'s structural batch type).
|
|
1533
|
+
*/
|
|
1534
|
+
type QueueConsumerHandler = (batch: unknown, env: unknown, context: ExecutionContextLike) => Promise<void>;
|
|
1535
|
+
/**
|
|
1475
1536
|
* A single code-defined cron job, shaped like an entry of the generated
|
|
1476
1537
|
* `LUNORA_CRONS` map. `functionPath` is the `"namespace:fn"` to run, `args` its
|
|
1477
1538
|
* bound arguments, and `name` the human label from the `cronJobs()` builder.
|
|
@@ -1553,6 +1614,22 @@ interface BackupManifest {
|
|
|
1553
1614
|
tables?: string;
|
|
1554
1615
|
}
|
|
1555
1616
|
interface WorkerOptions {
|
|
1617
|
+
/**
|
|
1618
|
+
* An additional, async authorization gate for the `/_lunora/admin/*` plane
|
|
1619
|
+
* (the Studio's HTTP + WS endpoints), OR-ed with the static {@link WorkerOptions.adminToken}
|
|
1620
|
+
* bearer. When it resolves `true` for a request, that request is treated as
|
|
1621
|
+
* admin-authorized even without the bearer; when it resolves `false` (or is
|
|
1622
|
+
* unset) the bearer remains the only path. Evaluated once per admin request
|
|
1623
|
+
* and never on the RPC/WebSocket data hot path.
|
|
1624
|
+
*
|
|
1625
|
+
* The intended producer is `@lunora/cloudflare-access`'s `accessAdminGate(...)`,
|
|
1626
|
+
* which verifies the request's `Cf-Access-Jwt-Assertion` JWT and applies an
|
|
1627
|
+
* `isAdmin(claims)` predicate — so the Studio can sit behind Cloudflare Access
|
|
1628
|
+
* instead of (or alongside) a shared admin token. It takes only the request
|
|
1629
|
+
* (verification needs static team-domain/aud config + the remote JWKS, no env
|
|
1630
|
+
* binding), so it composes without threading async through every admin route.
|
|
1631
|
+
*/
|
|
1632
|
+
adminGate?: (request: Request) => boolean | Promise<boolean>;
|
|
1556
1633
|
/**
|
|
1557
1634
|
* Admin bearer token expected by the export/import endpoints. When unset,
|
|
1558
1635
|
* the endpoints respond with `ADMIN_FORBIDDEN` — the same posture the
|
|
@@ -1742,6 +1819,27 @@ interface WorkerOptions {
|
|
|
1742
1819
|
*/
|
|
1743
1820
|
importGlobals?: GlobalImportFunction;
|
|
1744
1821
|
/**
|
|
1822
|
+
* Restrict every Durable Object this worker reaches — shard DOs, the
|
|
1823
|
+
* scheduler DO, the fan-out coordinator, subscriptions — to a Cloudflare
|
|
1824
|
+
* data-residency jurisdiction (`"eu"`, `"us"`, `"fedramp"`). The runtime
|
|
1825
|
+
* derives a jurisdiction-pinned subnamespace from {@link WorkerOptions.shardDO}
|
|
1826
|
+
* and {@link WorkerOptions.schedulerDO} once, so all routing inherits it.
|
|
1827
|
+
*
|
|
1828
|
+
* Fail-closed: if the bound namespace does not expose `.jurisdiction()`
|
|
1829
|
+
* (an older `@cloudflare/workers-types`), the worker throws rather than
|
|
1830
|
+
* silently routing to the un-pinned global namespace. Omit it for the
|
|
1831
|
+
* default, un-pinned behaviour.
|
|
1832
|
+
*
|
|
1833
|
+
* ⚠️ Set once, before the first deploy — changing it strands data. A DO name
|
|
1834
|
+
* maps to a *different* ID per jurisdiction, so toggling this on an existing
|
|
1835
|
+
* deployment makes every shard/scheduler call resolve to a new, empty DO; the
|
|
1836
|
+
* prior data stays in the old jurisdiction and is unreachable (no in-place
|
|
1837
|
+
* migration). Usually set via the schema's `.jurisdiction(...)`, which codegen
|
|
1838
|
+
* threads here.
|
|
1839
|
+
* @see https://developers.cloudflare.com/durable-objects/reference/data-location/
|
|
1840
|
+
*/
|
|
1841
|
+
jurisdiction?: DurableObjectJurisdiction;
|
|
1842
|
+
/**
|
|
1745
1843
|
* Optional telemetry sink. When supplied, the worker emits one
|
|
1746
1844
|
* `onRpc` event per dispatched RPC (single-shard forward or fan-out)
|
|
1747
1845
|
* with duration / ok / error / shardKey or fanOut metadata. Sink
|
|
@@ -1796,6 +1894,14 @@ interface WorkerOptions {
|
|
|
1796
1894
|
*/
|
|
1797
1895
|
queryCoordinator?: QueryCoordinator;
|
|
1798
1896
|
/**
|
|
1897
|
+
* Cloudflare Queues push-consumer handler — the worker's `queue(batch, …)`
|
|
1898
|
+
* entry forwards every delivered `MessageBatch` here. Built by codegen from
|
|
1899
|
+
* `lunora/queues.ts` (via `@lunora/queue`'s `dispatchQueueBatch`, which routes
|
|
1900
|
+
* by `batch.queue` to the matching `defineQueue` handler), so the runtime
|
|
1901
|
+
* stays decoupled from the queue package. Omitted when no push queues exist.
|
|
1902
|
+
*/
|
|
1903
|
+
queue?: QueueConsumerHandler;
|
|
1904
|
+
/**
|
|
1799
1905
|
* Resolve the calling identity from the inbound RPC request. Called once
|
|
1800
1906
|
* per RPC (and per fan-out) before the request is forwarded to the
|
|
1801
1907
|
* shard. The returned `userId` becomes `ctx.auth.userId` on the shard
|
|
@@ -1918,6 +2024,12 @@ interface RpcContext {
|
|
|
1918
2024
|
*/
|
|
1919
2025
|
interface LunoraWorker {
|
|
1920
2026
|
fetch: (request: Request, env: unknown, context: ExecutionContextLike) => Promise<Response>;
|
|
2027
|
+
/**
|
|
2028
|
+
* Cloudflare Queues consumer entry — present only when the app declares push
|
|
2029
|
+
* queues. Forwards each delivered `MessageBatch` to the configured
|
|
2030
|
+
* {@link WorkerOptions.queue} handler; a no-op when none is set.
|
|
2031
|
+
*/
|
|
2032
|
+
queue?: (batch: unknown, env: unknown, context: ExecutionContextLike) => Promise<void>;
|
|
1921
2033
|
scheduled: (controller: ScheduledControllerLike, env: unknown, context: ExecutionContextLike) => Promise<void>;
|
|
1922
2034
|
/**
|
|
1923
2035
|
* In-process query/mutation dispatch for SSR loaders co-located in this
|
|
@@ -2019,6 +2131,55 @@ type FrameworkWorkerOptionsInput = ((env: unknown) => FrameworkWorkerOptions) |
|
|
|
2019
2131
|
* @param optionsInput Lunora options minus `httpRouter`, or an `(env) => options` factory.
|
|
2020
2132
|
*/
|
|
2021
2133
|
declare const withFrameworkWorker: (host: FrameworkHostHandler, optionsInput: FrameworkWorkerOptionsInput) => LunoraWorker;
|
|
2134
|
+
/**
|
|
2135
|
+
* Options for {@link createLunoraHandler}. Either an `(env) => options` factory
|
|
2136
|
+
* (full control — for bindings that only exist at request time), or a partial
|
|
2137
|
+
* {@link FrameworkWorkerOptions} object whose `shardDO` defaults to the
|
|
2138
|
+
* conventional `env.SHARD` binding. Pass nothing for the common case.
|
|
2139
|
+
*/
|
|
2140
|
+
type LunoraHandlerOptions = ((env: unknown) => FrameworkWorkerOptions) | Partial<FrameworkWorkerOptions>;
|
|
2141
|
+
/**
|
|
2142
|
+
* Resolve per-request Lunora worker options. A factory is called with the
|
|
2143
|
+
* request `env`; a partial object has its `shardDO` defaulted to `env.SHARD` so
|
|
2144
|
+
* the common case needs no configuration. Throws a clear error when no shard
|
|
2145
|
+
* namespace can be found — a wiring mistake, not a runtime condition to swallow.
|
|
2146
|
+
*/
|
|
2147
|
+
declare const resolveLunoraOptions: (options: LunoraHandlerOptions, env: unknown) => FrameworkWorkerOptions;
|
|
2148
|
+
/**
|
|
2149
|
+
* Build a framework-neutral request handler for Lunora's realtime plane
|
|
2150
|
+
* (`/_lunora/rpc`, `/_lunora/ws`, `/_lunora/admin/*`). This is the **one shared
|
|
2151
|
+
* seam** every web-standard framework integration mounts — Hono, Nitro/h3,
|
|
2152
|
+
* Elysia, or any WinterCG host running on Cloudflare Workers — so each is a
|
|
2153
|
+
* 1–2 line bridge (`(request, env, ctx) => Response`) rather than a bespoke
|
|
2154
|
+
* adapter package.
|
|
2155
|
+
*
|
|
2156
|
+
* Mount it under `/_lunora/*` (or whatever path you reserve) inside your app's
|
|
2157
|
+
* router; everything else stays your framework's. The host supplies, per
|
|
2158
|
+
* request: a Web `Request`, the Cloudflare `env` (carrying the `SHARD` Durable
|
|
2159
|
+
* Object namespace), and — when available — the `ExecutionContext`. The
|
|
2160
|
+
* `101 Switching Protocols` WebSocket-upgrade `Response` (with its `webSocket`)
|
|
2161
|
+
* is returned verbatim, so the framework streams the socket through unchanged.
|
|
2162
|
+
*
|
|
2163
|
+
* ```ts
|
|
2164
|
+
* // Hono
|
|
2165
|
+
* const lunora = createLunoraHandler();
|
|
2166
|
+
* app.use("/_lunora/*", (c) => lunora(c.req.raw, c.env, c.executionCtx));
|
|
2167
|
+
*
|
|
2168
|
+
* // Nitro / h3
|
|
2169
|
+
* const lunora = createLunoraHandler();
|
|
2170
|
+
* export default defineEventHandler((event) => {
|
|
2171
|
+
* const { ctx, env } = event.context.cloudflare;
|
|
2172
|
+
* return lunora(toWebRequest(event), env, ctx);
|
|
2173
|
+
* });
|
|
2174
|
+
* ```
|
|
2175
|
+
*
|
|
2176
|
+
* `shardDO` defaults to `env.SHARD`; pass `options` (or an `(env) => options`
|
|
2177
|
+
* factory) to add `auth`, `crons`, a `security` posture, or a custom namespace.
|
|
2178
|
+
* A new worker is composed per request because the options (and the `SHARD`
|
|
2179
|
+
* binding they default from) are only known once `env` arrives.
|
|
2180
|
+
* @param options Partial worker options (default `shardDO: env.SHARD`), or an `(env) => options` factory.
|
|
2181
|
+
*/
|
|
2182
|
+
declare const createLunoraHandler: (options?: LunoraHandlerOptions) => ((request: Request, env: unknown, context?: ExecutionContextLike) => Promise<Response>);
|
|
2022
2183
|
/** Re-exported helper so callers can roundtrip envelopes in tests. */
|
|
2023
2184
|
declare const defineRpcEnvelope: (envelope: RpcEnvelope) => RpcEnvelope;
|
|
2024
2185
|
/**
|
|
@@ -2082,6 +2243,12 @@ interface DynamicShardRegistryOptions {
|
|
|
2082
2243
|
* only if you run multiple isolated registries in one environment.
|
|
2083
2244
|
*/
|
|
2084
2245
|
instanceName?: string;
|
|
2246
|
+
/**
|
|
2247
|
+
* Pin the registry DO to a Cloudflare data-residency jurisdiction. Pass the
|
|
2248
|
+
* same value as the worker's `jurisdiction` so the registry co-locates with
|
|
2249
|
+
* the shards it tracks. Omit for the un-pinned global namespace.
|
|
2250
|
+
*/
|
|
2251
|
+
jurisdiction?: DurableObjectJurisdiction;
|
|
2085
2252
|
/** DO namespace binding (`env.SHARD_REGISTRY`). */
|
|
2086
2253
|
namespace: ShardNamespaceLike;
|
|
2087
2254
|
}
|
|
@@ -2256,4 +2423,4 @@ declare const analyticsEngineSink: (options: AnalyticsEngineSinkOptions) => Obse
|
|
|
2256
2423
|
*/
|
|
2257
2424
|
declare const combineSinks: (...sinks: ObservabilitySink[]) => ObservabilitySink;
|
|
2258
2425
|
declare const VERSION: string;
|
|
2259
|
-
export { type AdminTableResolver, type AirbyteMessage, type AnalyticsEngineDataPointLike, type AnalyticsEngineDatasetLike, type AnalyticsEngineSinkOptions, type AuthAdmin, type AuthCapabilities, type AuthImpersonation, type AuthIntrospector, type AuthPage, type AuthSession, type AuthUser, type BackupManifest, type BackupStore, type ConnectorChange, type ConnectorSyncPage, type CorsOptions, type CronHandler, type CronJobDispatch, type CronJobInfo, type CrossShardCounter, type CrossShardReader, type CrossShardRelationCapabilities, type CrossShardRelationOptions, type CsrfOptions, DEFAULT_REGISTRY_CACHE_TTL_MS, type DynamicShardRegistry, type DynamicShardRegistryOptions, type ExecutionContextLike, type ExportFanOutRequest, type ExportFanOutResult, type FanOutRequest, type FanOutResult, type FanOutSpec, type FivetranResponse, type FrameworkHostHandler, type FrameworkWorkerOptions, type FrameworkWorkerOptionsInput, type FunctionDescriptor, type FunctionRegistryEntry, type FunctionRegistryLike, type GlobalExportFunction as GlobalExportFn, type GlobalImportFunction as GlobalImportFn, type GlobalIntrospector, type GlobalTableInfo as GlobalTableInfoMeta, type GlobalTablePage as GlobalTablePageMeta, type HttpActionContext, type HttpActionLike, type HttpRouterLike, type ImportFanOutRequest, type ImportFanOutResult, type ListAuthUsersOptions, type LogEvent, type LogLevel, LunoraError, type LunoraErrorBody, type LunoraWorker, type MergeStrategy, type MigrationFanOutRequest, type MigrationFanOutResult, type ObservabilityEvent, type ObservabilitySink, type ObservabilitySinkContext, type QueryCoordinator, type QueryCoordinatorOptions, type RankFanOutRequest, type RankFanOutResult, type RankPageFanOutRequest, type RankPageFanOutResult, type ResolvedSecurity, type ResolvedShard, type Route, type RpcContext, type RpcEnvelope, SHARD_REGISTRY_DO_NAME, type ScheduledControllerLike, type SecurityHeadersOptions, type SecurityOptions, type SentrySinkOptions, type ShardError, type ShardExportOutcome, type ShardImportOutcome, type ShardMigrationOutcome, type ShardNamespaceLike, type ShardRankOutcome, type ShardRankPageOutcome, type ShardRegistry, type ShardTrafficEntry, type ShardTrafficFanOutRequest, type ShardTrafficFanOutResult, type ShardingInfo, type StorageListFunction as StorageListFn, type StorageObject, VERSION, type VectorIndexSummary, type VectorIntrospector, type VectorQueryMatch, type WebhookSinkOptions, type WorkerOptions, analyticsEngineSink, combineSinks, composeWorker, consoleSink, createCrossShardRelationCapabilities, createDynamicShardRegistry, createQueryCoordinator, createStaticShardRegistry, createWorker, decorateResponse, defineRpcEnvelope, emitLogEvent, emitRpcEvent, enforceOrigin, handleCorsPreflight, mergeStrategyForAggregate, resolveSecurity, resolveShard, sentrySink, toAirbyteMessages, toErrorResponse, toFivetranResponse, webhookSink, withFrameworkWorker };
|
|
2426
|
+
export { type AdminTableResolver, type AirbyteMessage, type AnalyticsEngineDataPointLike, type AnalyticsEngineDatasetLike, type AnalyticsEngineSinkOptions, type AuthAdmin, type AuthCapabilities, type AuthImpersonation, type AuthIntrospector, type AuthPage, type AuthSession, type AuthUser, type BackupManifest, type BackupStore, type ConnectorChange, type ConnectorSyncPage, type CorsOptions, type CronHandler, type CronJobDispatch, type CronJobInfo, type CrossShardCounter, type CrossShardReader, type CrossShardRelationCapabilities, type CrossShardRelationOptions, type CsrfOptions, DEFAULT_REGISTRY_CACHE_TTL_MS, type DurableObjectJurisdiction, type DynamicShardRegistry, type DynamicShardRegistryOptions, type ExecutionContextLike, type ExportFanOutRequest, type ExportFanOutResult, type FanOutRequest, type FanOutResult, type FanOutSpec, type FivetranResponse, type FrameworkHostHandler, type FrameworkWorkerOptions, type FrameworkWorkerOptionsInput, type FunctionDescriptor, type FunctionRegistryEntry, type FunctionRegistryLike, type GlobalExportFunction as GlobalExportFn, type GlobalImportFunction as GlobalImportFn, type GlobalIntrospector, type GlobalTableInfo as GlobalTableInfoMeta, type GlobalTablePage as GlobalTablePageMeta, type HttpActionContext, type HttpActionLike, type HttpRouterLike, type ImportFanOutRequest, type ImportFanOutResult, type ListAuthUsersOptions, type LogEvent, type LogLevel, LunoraError, type LunoraErrorBody, type LunoraHandlerOptions, type LunoraWorker, type MergeStrategy, type MigrationFanOutRequest, type MigrationFanOutResult, NOOP_EXECUTION_CONTEXT, type ObservabilityEvent, type ObservabilitySink, type ObservabilitySinkContext, type QueryCoordinator, type QueryCoordinatorOptions, type RankFanOutRequest, type RankFanOutResult, type RankPageFanOutRequest, type RankPageFanOutResult, type ResolvedSecurity, type ResolvedShard, type Route, type RpcContext, type RpcEnvelope, SHARD_REGISTRY_DO_NAME, type ScheduledControllerLike, type SecurityHeadersOptions, type SecurityOptions, type SentrySinkOptions, type ShardError, type ShardExportOutcome, type ShardImportOutcome, type ShardMigrationOutcome, type ShardNamespaceLike, type ShardRankOutcome, type ShardRankPageOutcome, type ShardRegistry, type ShardTrafficEntry, type ShardTrafficFanOutRequest, type ShardTrafficFanOutResult, type ShardingInfo, type StorageListFunction as StorageListFn, type StorageObject, VERSION, type VectorIndexSummary, type VectorIntrospector, type VectorQueryMatch, type WebhookSinkOptions, type WorkerOptions, analyticsEngineSink, applyJurisdiction, combineSinks, composeWorker, consoleSink, createCrossShardRelationCapabilities, createDynamicShardRegistry, createLunoraHandler, createQueryCoordinator, createStaticShardRegistry, createWorker, decorateResponse, defineRpcEnvelope, emitLogEvent, emitRpcEvent, enforceOrigin, handleCorsPreflight, mergeStrategyForAggregate, resolveLunoraOptions, resolveSecurity, resolveShard, sentrySink, toAirbyteMessages, toErrorResponse, toFivetranResponse, webhookSink, withFrameworkWorker };
|
package/dist/index.d.ts
CHANGED
|
@@ -110,6 +110,38 @@ declare const toFivetranResponse: (page: ConnectorSyncPage, primaryKey?: Record<
|
|
|
110
110
|
* @param emittedAt epoch-ms stamped on each `RECORD` (default `Date.now()`).
|
|
111
111
|
*/
|
|
112
112
|
declare const toAirbyteMessages: (page: ConnectorSyncPage, emittedAt?: number) => AirbyteMessage[];
|
|
113
|
+
/**
|
|
114
|
+
* The subset of the Cloudflare `ExecutionContext` the Lunora worker entry and
|
|
115
|
+
* the framework mount seams rely on — `waitUntil` for fire-and-forget work that
|
|
116
|
+
* must outlive the response, and `passThroughOnException` for the top-level
|
|
117
|
+
* error posture.
|
|
118
|
+
*
|
|
119
|
+
* It is deliberately **not** a package. `@lunora/runtime` is the leaf server
|
|
120
|
+
* runtime and `@lunora/nuxt` is a framework integration that intentionally does
|
|
121
|
+
* not depend on `@lunora/runtime`'s worker types, yet both need this exact
|
|
122
|
+
* shape: the runtime to build/forward the worker `fetch`, Nuxt to forward an
|
|
123
|
+
* inbound request to the user's composed worker. Each imports this file by
|
|
124
|
+
* relative path and the bundler (packem/rollup) inlines it: no runtime
|
|
125
|
+
* dependency edge is created, the helper is duplicated only in emitted output,
|
|
126
|
+
* never in source. One source of truth, zero deps. See AGENTS.md → "Top-level
|
|
127
|
+
* `shared/` — bundler-inlined source".
|
|
128
|
+
*
|
|
129
|
+
* Both methods are **optional**: a real Cloudflare `ExecutionContext` always
|
|
130
|
+
* supplies them, but a host that mounts Lunora as a sub-handler (Nitro/H3, a
|
|
131
|
+
* non-Cloudflare preview, a unit test) may hand over a partial context or none
|
|
132
|
+
* at all. Callers therefore invoke them defensively (`ctx.waitUntil?.(…)`) or
|
|
133
|
+
* fall back to {@link NOOP_EXECUTION_CONTEXT}.
|
|
134
|
+
*/
|
|
135
|
+
interface ExecutionContextLike {
|
|
136
|
+
passThroughOnException?: () => void;
|
|
137
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* No-op `ExecutionContext` used when the host runtime didn't supply one (a
|
|
141
|
+
* non-Cloudflare preview, or a unit test), so the worker's `fetch` always
|
|
142
|
+
* receives a valid third argument.
|
|
143
|
+
*/
|
|
144
|
+
declare const NOOP_EXECUTION_CONTEXT: ExecutionContextLike;
|
|
113
145
|
/** A timestamp as better-auth stores it: epoch-ms, an ISO string, or absent. */
|
|
114
146
|
type AuthTimestamp = null | number | string;
|
|
115
147
|
/**
|
|
@@ -420,6 +452,14 @@ declare const emitRpcEvent: (sink: ObservabilitySink | undefined, event: Observa
|
|
|
420
452
|
*/
|
|
421
453
|
declare const emitLogEvent: (sink: ObservabilitySink | undefined, event: LogEvent, context?: ObservabilitySinkContext) => void;
|
|
422
454
|
/**
|
|
455
|
+
* Cloudflare Durable Object jurisdictions restrict where a DO runs and persists
|
|
456
|
+
* data, for data-residency / compliance regimes (GDPR, FedRAMP, US data
|
|
457
|
+
* residency). The set is open — Cloudflare adds values over time — so this is a
|
|
458
|
+
* widening union rather than a closed enum.
|
|
459
|
+
* @see https://developers.cloudflare.com/durable-objects/reference/data-location/
|
|
460
|
+
*/
|
|
461
|
+
type DurableObjectJurisdiction = "eu" | "fedramp" | "us";
|
|
462
|
+
/**
|
|
423
463
|
* Structural projection of the bits of `DurableObjectNamespace` the runtime
|
|
424
464
|
* needs. Real workers-types defines a much wider surface; this lets us pass
|
|
425
465
|
* unit-test doubles without coupling to `@cloudflare/workers-types`.
|
|
@@ -437,10 +477,29 @@ interface ShardNamespaceLike {
|
|
|
437
477
|
fetch: (request: Request) => Promise<Response>;
|
|
438
478
|
};
|
|
439
479
|
idFromName: (name: string) => unknown;
|
|
480
|
+
/**
|
|
481
|
+
* Derive a jurisdiction-restricted subnamespace. Every ID and stub created
|
|
482
|
+
* from the returned namespace is pinned to `jurisdiction`. Optional because
|
|
483
|
+
* older workers-types releases (and unit-test doubles) may not expose it;
|
|
484
|
+
* {@link applyJurisdiction} fails closed when a jurisdiction is requested
|
|
485
|
+
* but this method is absent.
|
|
486
|
+
*/
|
|
487
|
+
jurisdiction?: (jurisdiction: DurableObjectJurisdiction) => ShardNamespaceLike;
|
|
440
488
|
}
|
|
441
489
|
interface ResolvedShard {
|
|
442
490
|
fetch: (request: Request) => Promise<Response>;
|
|
443
491
|
}
|
|
492
|
+
/**
|
|
493
|
+
* Return a jurisdiction-restricted view of `namespace`, or `namespace`
|
|
494
|
+
* unchanged when no jurisdiction is configured.
|
|
495
|
+
*
|
|
496
|
+
* Fail-closed: if a jurisdiction is requested but the binding does not expose
|
|
497
|
+
* `.jurisdiction()` (an older workers-types, or a misconfigured test double),
|
|
498
|
+
* this throws rather than silently routing to the un-pinned global namespace —
|
|
499
|
+
* silently dropping a residency constraint would let data land outside the
|
|
500
|
+
* compliance boundary the caller asked for.
|
|
501
|
+
*/
|
|
502
|
+
declare const applyJurisdiction: (namespace: ShardNamespaceLike, jurisdiction?: DurableObjectJurisdiction) => ShardNamespaceLike;
|
|
444
503
|
/** Look up a shard stub by name, preferring `getByName` when present. */
|
|
445
504
|
declare const resolveShard: (namespace: ShardNamespaceLike, shardKey: string) => ResolvedShard;
|
|
446
505
|
/**
|
|
@@ -1130,10 +1189,6 @@ interface RpcEnvelope {
|
|
|
1130
1189
|
functionPath: string;
|
|
1131
1190
|
shardKey?: string;
|
|
1132
1191
|
}
|
|
1133
|
-
interface ExecutionContextLike {
|
|
1134
|
-
passThroughOnException: () => void;
|
|
1135
|
-
waitUntil: (promise: Promise<unknown>) => void;
|
|
1136
|
-
}
|
|
1137
1192
|
type Route = (request: Request, env: unknown, context: ExecutionContextLike) => Promise<Response> | Response;
|
|
1138
1193
|
/**
|
|
1139
1194
|
* Context handed to HTTP-action handlers. Built per request by the worker; its
|
|
@@ -1472,6 +1527,12 @@ interface ScheduledControllerLike {
|
|
|
1472
1527
|
*/
|
|
1473
1528
|
type CronHandler = (controller: ScheduledControllerLike, env: unknown, context: ExecutionContextLike) => Promise<void> | void;
|
|
1474
1529
|
/**
|
|
1530
|
+
* A Cloudflare Queues push-consumer handler — the worker's `queue()` entry
|
|
1531
|
+
* forwards each delivered `MessageBatch` (typed `unknown` here to keep the
|
|
1532
|
+
* runtime decoupled from `@lunora/queue`'s structural batch type).
|
|
1533
|
+
*/
|
|
1534
|
+
type QueueConsumerHandler = (batch: unknown, env: unknown, context: ExecutionContextLike) => Promise<void>;
|
|
1535
|
+
/**
|
|
1475
1536
|
* A single code-defined cron job, shaped like an entry of the generated
|
|
1476
1537
|
* `LUNORA_CRONS` map. `functionPath` is the `"namespace:fn"` to run, `args` its
|
|
1477
1538
|
* bound arguments, and `name` the human label from the `cronJobs()` builder.
|
|
@@ -1553,6 +1614,22 @@ interface BackupManifest {
|
|
|
1553
1614
|
tables?: string;
|
|
1554
1615
|
}
|
|
1555
1616
|
interface WorkerOptions {
|
|
1617
|
+
/**
|
|
1618
|
+
* An additional, async authorization gate for the `/_lunora/admin/*` plane
|
|
1619
|
+
* (the Studio's HTTP + WS endpoints), OR-ed with the static {@link WorkerOptions.adminToken}
|
|
1620
|
+
* bearer. When it resolves `true` for a request, that request is treated as
|
|
1621
|
+
* admin-authorized even without the bearer; when it resolves `false` (or is
|
|
1622
|
+
* unset) the bearer remains the only path. Evaluated once per admin request
|
|
1623
|
+
* and never on the RPC/WebSocket data hot path.
|
|
1624
|
+
*
|
|
1625
|
+
* The intended producer is `@lunora/cloudflare-access`'s `accessAdminGate(...)`,
|
|
1626
|
+
* which verifies the request's `Cf-Access-Jwt-Assertion` JWT and applies an
|
|
1627
|
+
* `isAdmin(claims)` predicate — so the Studio can sit behind Cloudflare Access
|
|
1628
|
+
* instead of (or alongside) a shared admin token. It takes only the request
|
|
1629
|
+
* (verification needs static team-domain/aud config + the remote JWKS, no env
|
|
1630
|
+
* binding), so it composes without threading async through every admin route.
|
|
1631
|
+
*/
|
|
1632
|
+
adminGate?: (request: Request) => boolean | Promise<boolean>;
|
|
1556
1633
|
/**
|
|
1557
1634
|
* Admin bearer token expected by the export/import endpoints. When unset,
|
|
1558
1635
|
* the endpoints respond with `ADMIN_FORBIDDEN` — the same posture the
|
|
@@ -1742,6 +1819,27 @@ interface WorkerOptions {
|
|
|
1742
1819
|
*/
|
|
1743
1820
|
importGlobals?: GlobalImportFunction;
|
|
1744
1821
|
/**
|
|
1822
|
+
* Restrict every Durable Object this worker reaches — shard DOs, the
|
|
1823
|
+
* scheduler DO, the fan-out coordinator, subscriptions — to a Cloudflare
|
|
1824
|
+
* data-residency jurisdiction (`"eu"`, `"us"`, `"fedramp"`). The runtime
|
|
1825
|
+
* derives a jurisdiction-pinned subnamespace from {@link WorkerOptions.shardDO}
|
|
1826
|
+
* and {@link WorkerOptions.schedulerDO} once, so all routing inherits it.
|
|
1827
|
+
*
|
|
1828
|
+
* Fail-closed: if the bound namespace does not expose `.jurisdiction()`
|
|
1829
|
+
* (an older `@cloudflare/workers-types`), the worker throws rather than
|
|
1830
|
+
* silently routing to the un-pinned global namespace. Omit it for the
|
|
1831
|
+
* default, un-pinned behaviour.
|
|
1832
|
+
*
|
|
1833
|
+
* ⚠️ Set once, before the first deploy — changing it strands data. A DO name
|
|
1834
|
+
* maps to a *different* ID per jurisdiction, so toggling this on an existing
|
|
1835
|
+
* deployment makes every shard/scheduler call resolve to a new, empty DO; the
|
|
1836
|
+
* prior data stays in the old jurisdiction and is unreachable (no in-place
|
|
1837
|
+
* migration). Usually set via the schema's `.jurisdiction(...)`, which codegen
|
|
1838
|
+
* threads here.
|
|
1839
|
+
* @see https://developers.cloudflare.com/durable-objects/reference/data-location/
|
|
1840
|
+
*/
|
|
1841
|
+
jurisdiction?: DurableObjectJurisdiction;
|
|
1842
|
+
/**
|
|
1745
1843
|
* Optional telemetry sink. When supplied, the worker emits one
|
|
1746
1844
|
* `onRpc` event per dispatched RPC (single-shard forward or fan-out)
|
|
1747
1845
|
* with duration / ok / error / shardKey or fanOut metadata. Sink
|
|
@@ -1796,6 +1894,14 @@ interface WorkerOptions {
|
|
|
1796
1894
|
*/
|
|
1797
1895
|
queryCoordinator?: QueryCoordinator;
|
|
1798
1896
|
/**
|
|
1897
|
+
* Cloudflare Queues push-consumer handler — the worker's `queue(batch, …)`
|
|
1898
|
+
* entry forwards every delivered `MessageBatch` here. Built by codegen from
|
|
1899
|
+
* `lunora/queues.ts` (via `@lunora/queue`'s `dispatchQueueBatch`, which routes
|
|
1900
|
+
* by `batch.queue` to the matching `defineQueue` handler), so the runtime
|
|
1901
|
+
* stays decoupled from the queue package. Omitted when no push queues exist.
|
|
1902
|
+
*/
|
|
1903
|
+
queue?: QueueConsumerHandler;
|
|
1904
|
+
/**
|
|
1799
1905
|
* Resolve the calling identity from the inbound RPC request. Called once
|
|
1800
1906
|
* per RPC (and per fan-out) before the request is forwarded to the
|
|
1801
1907
|
* shard. The returned `userId` becomes `ctx.auth.userId` on the shard
|
|
@@ -1918,6 +2024,12 @@ interface RpcContext {
|
|
|
1918
2024
|
*/
|
|
1919
2025
|
interface LunoraWorker {
|
|
1920
2026
|
fetch: (request: Request, env: unknown, context: ExecutionContextLike) => Promise<Response>;
|
|
2027
|
+
/**
|
|
2028
|
+
* Cloudflare Queues consumer entry — present only when the app declares push
|
|
2029
|
+
* queues. Forwards each delivered `MessageBatch` to the configured
|
|
2030
|
+
* {@link WorkerOptions.queue} handler; a no-op when none is set.
|
|
2031
|
+
*/
|
|
2032
|
+
queue?: (batch: unknown, env: unknown, context: ExecutionContextLike) => Promise<void>;
|
|
1921
2033
|
scheduled: (controller: ScheduledControllerLike, env: unknown, context: ExecutionContextLike) => Promise<void>;
|
|
1922
2034
|
/**
|
|
1923
2035
|
* In-process query/mutation dispatch for SSR loaders co-located in this
|
|
@@ -2019,6 +2131,55 @@ type FrameworkWorkerOptionsInput = ((env: unknown) => FrameworkWorkerOptions) |
|
|
|
2019
2131
|
* @param optionsInput Lunora options minus `httpRouter`, or an `(env) => options` factory.
|
|
2020
2132
|
*/
|
|
2021
2133
|
declare const withFrameworkWorker: (host: FrameworkHostHandler, optionsInput: FrameworkWorkerOptionsInput) => LunoraWorker;
|
|
2134
|
+
/**
|
|
2135
|
+
* Options for {@link createLunoraHandler}. Either an `(env) => options` factory
|
|
2136
|
+
* (full control — for bindings that only exist at request time), or a partial
|
|
2137
|
+
* {@link FrameworkWorkerOptions} object whose `shardDO` defaults to the
|
|
2138
|
+
* conventional `env.SHARD` binding. Pass nothing for the common case.
|
|
2139
|
+
*/
|
|
2140
|
+
type LunoraHandlerOptions = ((env: unknown) => FrameworkWorkerOptions) | Partial<FrameworkWorkerOptions>;
|
|
2141
|
+
/**
|
|
2142
|
+
* Resolve per-request Lunora worker options. A factory is called with the
|
|
2143
|
+
* request `env`; a partial object has its `shardDO` defaulted to `env.SHARD` so
|
|
2144
|
+
* the common case needs no configuration. Throws a clear error when no shard
|
|
2145
|
+
* namespace can be found — a wiring mistake, not a runtime condition to swallow.
|
|
2146
|
+
*/
|
|
2147
|
+
declare const resolveLunoraOptions: (options: LunoraHandlerOptions, env: unknown) => FrameworkWorkerOptions;
|
|
2148
|
+
/**
|
|
2149
|
+
* Build a framework-neutral request handler for Lunora's realtime plane
|
|
2150
|
+
* (`/_lunora/rpc`, `/_lunora/ws`, `/_lunora/admin/*`). This is the **one shared
|
|
2151
|
+
* seam** every web-standard framework integration mounts — Hono, Nitro/h3,
|
|
2152
|
+
* Elysia, or any WinterCG host running on Cloudflare Workers — so each is a
|
|
2153
|
+
* 1–2 line bridge (`(request, env, ctx) => Response`) rather than a bespoke
|
|
2154
|
+
* adapter package.
|
|
2155
|
+
*
|
|
2156
|
+
* Mount it under `/_lunora/*` (or whatever path you reserve) inside your app's
|
|
2157
|
+
* router; everything else stays your framework's. The host supplies, per
|
|
2158
|
+
* request: a Web `Request`, the Cloudflare `env` (carrying the `SHARD` Durable
|
|
2159
|
+
* Object namespace), and — when available — the `ExecutionContext`. The
|
|
2160
|
+
* `101 Switching Protocols` WebSocket-upgrade `Response` (with its `webSocket`)
|
|
2161
|
+
* is returned verbatim, so the framework streams the socket through unchanged.
|
|
2162
|
+
*
|
|
2163
|
+
* ```ts
|
|
2164
|
+
* // Hono
|
|
2165
|
+
* const lunora = createLunoraHandler();
|
|
2166
|
+
* app.use("/_lunora/*", (c) => lunora(c.req.raw, c.env, c.executionCtx));
|
|
2167
|
+
*
|
|
2168
|
+
* // Nitro / h3
|
|
2169
|
+
* const lunora = createLunoraHandler();
|
|
2170
|
+
* export default defineEventHandler((event) => {
|
|
2171
|
+
* const { ctx, env } = event.context.cloudflare;
|
|
2172
|
+
* return lunora(toWebRequest(event), env, ctx);
|
|
2173
|
+
* });
|
|
2174
|
+
* ```
|
|
2175
|
+
*
|
|
2176
|
+
* `shardDO` defaults to `env.SHARD`; pass `options` (or an `(env) => options`
|
|
2177
|
+
* factory) to add `auth`, `crons`, a `security` posture, or a custom namespace.
|
|
2178
|
+
* A new worker is composed per request because the options (and the `SHARD`
|
|
2179
|
+
* binding they default from) are only known once `env` arrives.
|
|
2180
|
+
* @param options Partial worker options (default `shardDO: env.SHARD`), or an `(env) => options` factory.
|
|
2181
|
+
*/
|
|
2182
|
+
declare const createLunoraHandler: (options?: LunoraHandlerOptions) => ((request: Request, env: unknown, context?: ExecutionContextLike) => Promise<Response>);
|
|
2022
2183
|
/** Re-exported helper so callers can roundtrip envelopes in tests. */
|
|
2023
2184
|
declare const defineRpcEnvelope: (envelope: RpcEnvelope) => RpcEnvelope;
|
|
2024
2185
|
/**
|
|
@@ -2082,6 +2243,12 @@ interface DynamicShardRegistryOptions {
|
|
|
2082
2243
|
* only if you run multiple isolated registries in one environment.
|
|
2083
2244
|
*/
|
|
2084
2245
|
instanceName?: string;
|
|
2246
|
+
/**
|
|
2247
|
+
* Pin the registry DO to a Cloudflare data-residency jurisdiction. Pass the
|
|
2248
|
+
* same value as the worker's `jurisdiction` so the registry co-locates with
|
|
2249
|
+
* the shards it tracks. Omit for the un-pinned global namespace.
|
|
2250
|
+
*/
|
|
2251
|
+
jurisdiction?: DurableObjectJurisdiction;
|
|
2085
2252
|
/** DO namespace binding (`env.SHARD_REGISTRY`). */
|
|
2086
2253
|
namespace: ShardNamespaceLike;
|
|
2087
2254
|
}
|
|
@@ -2256,4 +2423,4 @@ declare const analyticsEngineSink: (options: AnalyticsEngineSinkOptions) => Obse
|
|
|
2256
2423
|
*/
|
|
2257
2424
|
declare const combineSinks: (...sinks: ObservabilitySink[]) => ObservabilitySink;
|
|
2258
2425
|
declare const VERSION: string;
|
|
2259
|
-
export { type AdminTableResolver, type AirbyteMessage, type AnalyticsEngineDataPointLike, type AnalyticsEngineDatasetLike, type AnalyticsEngineSinkOptions, type AuthAdmin, type AuthCapabilities, type AuthImpersonation, type AuthIntrospector, type AuthPage, type AuthSession, type AuthUser, type BackupManifest, type BackupStore, type ConnectorChange, type ConnectorSyncPage, type CorsOptions, type CronHandler, type CronJobDispatch, type CronJobInfo, type CrossShardCounter, type CrossShardReader, type CrossShardRelationCapabilities, type CrossShardRelationOptions, type CsrfOptions, DEFAULT_REGISTRY_CACHE_TTL_MS, type DynamicShardRegistry, type DynamicShardRegistryOptions, type ExecutionContextLike, type ExportFanOutRequest, type ExportFanOutResult, type FanOutRequest, type FanOutResult, type FanOutSpec, type FivetranResponse, type FrameworkHostHandler, type FrameworkWorkerOptions, type FrameworkWorkerOptionsInput, type FunctionDescriptor, type FunctionRegistryEntry, type FunctionRegistryLike, type GlobalExportFunction as GlobalExportFn, type GlobalImportFunction as GlobalImportFn, type GlobalIntrospector, type GlobalTableInfo as GlobalTableInfoMeta, type GlobalTablePage as GlobalTablePageMeta, type HttpActionContext, type HttpActionLike, type HttpRouterLike, type ImportFanOutRequest, type ImportFanOutResult, type ListAuthUsersOptions, type LogEvent, type LogLevel, LunoraError, type LunoraErrorBody, type LunoraWorker, type MergeStrategy, type MigrationFanOutRequest, type MigrationFanOutResult, type ObservabilityEvent, type ObservabilitySink, type ObservabilitySinkContext, type QueryCoordinator, type QueryCoordinatorOptions, type RankFanOutRequest, type RankFanOutResult, type RankPageFanOutRequest, type RankPageFanOutResult, type ResolvedSecurity, type ResolvedShard, type Route, type RpcContext, type RpcEnvelope, SHARD_REGISTRY_DO_NAME, type ScheduledControllerLike, type SecurityHeadersOptions, type SecurityOptions, type SentrySinkOptions, type ShardError, type ShardExportOutcome, type ShardImportOutcome, type ShardMigrationOutcome, type ShardNamespaceLike, type ShardRankOutcome, type ShardRankPageOutcome, type ShardRegistry, type ShardTrafficEntry, type ShardTrafficFanOutRequest, type ShardTrafficFanOutResult, type ShardingInfo, type StorageListFunction as StorageListFn, type StorageObject, VERSION, type VectorIndexSummary, type VectorIntrospector, type VectorQueryMatch, type WebhookSinkOptions, type WorkerOptions, analyticsEngineSink, combineSinks, composeWorker, consoleSink, createCrossShardRelationCapabilities, createDynamicShardRegistry, createQueryCoordinator, createStaticShardRegistry, createWorker, decorateResponse, defineRpcEnvelope, emitLogEvent, emitRpcEvent, enforceOrigin, handleCorsPreflight, mergeStrategyForAggregate, resolveSecurity, resolveShard, sentrySink, toAirbyteMessages, toErrorResponse, toFivetranResponse, webhookSink, withFrameworkWorker };
|
|
2426
|
+
export { type AdminTableResolver, type AirbyteMessage, type AnalyticsEngineDataPointLike, type AnalyticsEngineDatasetLike, type AnalyticsEngineSinkOptions, type AuthAdmin, type AuthCapabilities, type AuthImpersonation, type AuthIntrospector, type AuthPage, type AuthSession, type AuthUser, type BackupManifest, type BackupStore, type ConnectorChange, type ConnectorSyncPage, type CorsOptions, type CronHandler, type CronJobDispatch, type CronJobInfo, type CrossShardCounter, type CrossShardReader, type CrossShardRelationCapabilities, type CrossShardRelationOptions, type CsrfOptions, DEFAULT_REGISTRY_CACHE_TTL_MS, type DurableObjectJurisdiction, type DynamicShardRegistry, type DynamicShardRegistryOptions, type ExecutionContextLike, type ExportFanOutRequest, type ExportFanOutResult, type FanOutRequest, type FanOutResult, type FanOutSpec, type FivetranResponse, type FrameworkHostHandler, type FrameworkWorkerOptions, type FrameworkWorkerOptionsInput, type FunctionDescriptor, type FunctionRegistryEntry, type FunctionRegistryLike, type GlobalExportFunction as GlobalExportFn, type GlobalImportFunction as GlobalImportFn, type GlobalIntrospector, type GlobalTableInfo as GlobalTableInfoMeta, type GlobalTablePage as GlobalTablePageMeta, type HttpActionContext, type HttpActionLike, type HttpRouterLike, type ImportFanOutRequest, type ImportFanOutResult, type ListAuthUsersOptions, type LogEvent, type LogLevel, LunoraError, type LunoraErrorBody, type LunoraHandlerOptions, type LunoraWorker, type MergeStrategy, type MigrationFanOutRequest, type MigrationFanOutResult, NOOP_EXECUTION_CONTEXT, type ObservabilityEvent, type ObservabilitySink, type ObservabilitySinkContext, type QueryCoordinator, type QueryCoordinatorOptions, type RankFanOutRequest, type RankFanOutResult, type RankPageFanOutRequest, type RankPageFanOutResult, type ResolvedSecurity, type ResolvedShard, type Route, type RpcContext, type RpcEnvelope, SHARD_REGISTRY_DO_NAME, type ScheduledControllerLike, type SecurityHeadersOptions, type SecurityOptions, type SentrySinkOptions, type ShardError, type ShardExportOutcome, type ShardImportOutcome, type ShardMigrationOutcome, type ShardNamespaceLike, type ShardRankOutcome, type ShardRankPageOutcome, type ShardRegistry, type ShardTrafficEntry, type ShardTrafficFanOutRequest, type ShardTrafficFanOutResult, type ShardingInfo, type StorageListFunction as StorageListFn, type StorageObject, VERSION, type VectorIndexSummary, type VectorIntrospector, type VectorQueryMatch, type WebhookSinkOptions, type WorkerOptions, analyticsEngineSink, applyJurisdiction, combineSinks, composeWorker, consoleSink, createCrossShardRelationCapabilities, createDynamicShardRegistry, createLunoraHandler, createQueryCoordinator, createStaticShardRegistry, createWorker, decorateResponse, defineRpcEnvelope, emitLogEvent, emitRpcEvent, enforceOrigin, handleCorsPreflight, mergeStrategyForAggregate, resolveLunoraOptions, resolveSecurity, resolveShard, sentrySink, toAirbyteMessages, toErrorResponse, toFivetranResponse, webhookSink, withFrameworkWorker };
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
export { toAirbyteMessages, toFivetranResponse } from './packem_shared/toAirbyteMessages-DrHdplb4.mjs';
|
|
2
|
-
export { composeWorker, createWorker, defineRpcEnvelope, withFrameworkWorker } from './packem_shared/composeWorker-
|
|
2
|
+
export { composeWorker, createLunoraHandler, createWorker, defineRpcEnvelope, resolveLunoraOptions, withFrameworkWorker } from './packem_shared/composeWorker-BEv9IBWS.mjs';
|
|
3
3
|
export { createCrossShardRelationCapabilities } from './packem_shared/createCrossShardRelationCapabilities-C0KOf7er.mjs';
|
|
4
|
-
export { DEFAULT_REGISTRY_CACHE_TTL_MS, SHARD_REGISTRY_DO_NAME, createDynamicShardRegistry } from './packem_shared/
|
|
4
|
+
export { DEFAULT_REGISTRY_CACHE_TTL_MS, SHARD_REGISTRY_DO_NAME, createDynamicShardRegistry } from './packem_shared/DEFAULT_REGISTRY_CACHE_TTL_MS-ocax8v0n.mjs';
|
|
5
5
|
export { LunoraError, toErrorResponse } from './packem_shared/LunoraError-CL0aOtpo.mjs';
|
|
6
|
-
export { emitLogEvent, emitRpcEvent } from './packem_shared/
|
|
7
|
-
export { analyticsEngineSink, combineSinks, consoleSink, sentrySink, webhookSink } from './packem_shared/
|
|
8
|
-
export { createQueryCoordinator, createStaticShardRegistry, mergeStrategyForAggregate } from './packem_shared/createQueryCoordinator-
|
|
9
|
-
export { resolveShard } from './packem_shared/
|
|
6
|
+
export { emitLogEvent, emitRpcEvent } from './packem_shared/emitLogEvent-pEdtqAK8.mjs';
|
|
7
|
+
export { analyticsEngineSink, combineSinks, consoleSink, sentrySink, webhookSink } from './packem_shared/analyticsEngineSink-DqEvrQs0.mjs';
|
|
8
|
+
export { createQueryCoordinator, createStaticShardRegistry, mergeStrategyForAggregate } from './packem_shared/createQueryCoordinator-Cbds9cUI.mjs';
|
|
9
|
+
export { applyJurisdiction, resolveShard } from './packem_shared/applyJurisdiction-BkZtTkct.mjs';
|
|
10
10
|
export { decorateResponse, enforceOrigin, handleCorsPreflight, resolveSecurity } from './packem_shared/decorateResponse-DbISh_Wi.mjs';
|
|
11
|
+
export { NOOP_EXECUTION_CONTEXT } from './packem_shared/NOOP_EXECUTION_CONTEXT-CCTu0Bf1.mjs';
|
|
11
12
|
|
|
12
13
|
const VERSION = "0.0.0";
|
|
13
14
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { applyJurisdiction } from './applyJurisdiction-BkZtTkct.mjs';
|
|
2
|
+
|
|
1
3
|
const SHARD_REGISTRY_DO_NAME = "__lunora_shard_registry__";
|
|
2
4
|
const DEFAULT_REGISTRY_CACHE_TTL_MS = 3e4;
|
|
3
5
|
const REGISTRY_BASE_URL = "https://shard-registry.internal";
|
|
@@ -10,9 +12,10 @@ const createDynamicShardRegistry = (options) => {
|
|
|
10
12
|
const instanceName = options.instanceName ?? SHARD_REGISTRY_DO_NAME;
|
|
11
13
|
const cacheTtlMs = options.cacheTtlMs ?? DEFAULT_REGISTRY_CACHE_TTL_MS;
|
|
12
14
|
const cache = /* @__PURE__ */ new Map();
|
|
15
|
+
const namespace = applyJurisdiction(options.namespace, options.jurisdiction);
|
|
13
16
|
let cachedStub;
|
|
14
17
|
const stub = () => {
|
|
15
|
-
cachedStub ??=
|
|
18
|
+
cachedStub ??= namespace.get(namespace.idFromName(instanceName));
|
|
16
19
|
return cachedStub;
|
|
17
20
|
};
|
|
18
21
|
const post = async (path, body) => stub().fetch(
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const applyJurisdiction = (namespace, jurisdiction) => {
|
|
2
|
+
if (jurisdiction === void 0) {
|
|
3
|
+
return namespace;
|
|
4
|
+
}
|
|
5
|
+
if (typeof namespace.jurisdiction !== "function") {
|
|
6
|
+
throw new TypeError(
|
|
7
|
+
`@lunora/runtime: Durable Object namespace does not support jurisdiction("${jurisdiction}") — update @cloudflare/workers-types or remove the jurisdiction option`
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
return namespace.jurisdiction(jurisdiction);
|
|
11
|
+
};
|
|
12
|
+
const resolveShard = (namespace, shardKey) => {
|
|
13
|
+
if (typeof namespace.getByName === "function") {
|
|
14
|
+
return namespace.getByName(shardKey);
|
|
15
|
+
}
|
|
16
|
+
const id = namespace.idFromName(shardKey);
|
|
17
|
+
return namespace.get(id);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { applyJurisdiction, resolveShard };
|