@lunora/runtime 1.0.0-alpha.5 → 1.0.0-alpha.7

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/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
  /**
@@ -1157,10 +1189,6 @@ interface RpcEnvelope {
1157
1189
  functionPath: string;
1158
1190
  shardKey?: string;
1159
1191
  }
1160
- interface ExecutionContextLike {
1161
- passThroughOnException: () => void;
1162
- waitUntil: (promise: Promise<unknown>) => void;
1163
- }
1164
1192
  type Route = (request: Request, env: unknown, context: ExecutionContextLike) => Promise<Response> | Response;
1165
1193
  /**
1166
1194
  * Context handed to HTTP-action handlers. Built per request by the worker; its
@@ -2087,6 +2115,55 @@ type FrameworkWorkerOptionsInput = ((env: unknown) => FrameworkWorkerOptions) |
2087
2115
  * @param optionsInput Lunora options minus `httpRouter`, or an `(env) => options` factory.
2088
2116
  */
2089
2117
  declare const withFrameworkWorker: (host: FrameworkHostHandler, optionsInput: FrameworkWorkerOptionsInput) => LunoraWorker;
2118
+ /**
2119
+ * Options for {@link createLunoraHandler}. Either an `(env) => options` factory
2120
+ * (full control — for bindings that only exist at request time), or a partial
2121
+ * {@link FrameworkWorkerOptions} object whose `shardDO` defaults to the
2122
+ * conventional `env.SHARD` binding. Pass nothing for the common case.
2123
+ */
2124
+ type LunoraHandlerOptions = ((env: unknown) => FrameworkWorkerOptions) | Partial<FrameworkWorkerOptions>;
2125
+ /**
2126
+ * Resolve per-request Lunora worker options. A factory is called with the
2127
+ * request `env`; a partial object has its `shardDO` defaulted to `env.SHARD` so
2128
+ * the common case needs no configuration. Throws a clear error when no shard
2129
+ * namespace can be found — a wiring mistake, not a runtime condition to swallow.
2130
+ */
2131
+ declare const resolveLunoraOptions: (options: LunoraHandlerOptions, env: unknown) => FrameworkWorkerOptions;
2132
+ /**
2133
+ * Build a framework-neutral request handler for Lunora's realtime plane
2134
+ * (`/_lunora/rpc`, `/_lunora/ws`, `/_lunora/admin/*`). This is the **one shared
2135
+ * seam** every web-standard framework integration mounts — Hono, Nitro/h3,
2136
+ * Elysia, or any WinterCG host running on Cloudflare Workers — so each is a
2137
+ * 1–2 line bridge (`(request, env, ctx) => Response`) rather than a bespoke
2138
+ * adapter package.
2139
+ *
2140
+ * Mount it under `/_lunora/*` (or whatever path you reserve) inside your app's
2141
+ * router; everything else stays your framework's. The host supplies, per
2142
+ * request: a Web `Request`, the Cloudflare `env` (carrying the `SHARD` Durable
2143
+ * Object namespace), and — when available — the `ExecutionContext`. The
2144
+ * `101 Switching Protocols` WebSocket-upgrade `Response` (with its `webSocket`)
2145
+ * is returned verbatim, so the framework streams the socket through unchanged.
2146
+ *
2147
+ * ```ts
2148
+ * // Hono
2149
+ * const lunora = createLunoraHandler();
2150
+ * app.use("/_lunora/*", (c) => lunora(c.req.raw, c.env, c.executionCtx));
2151
+ *
2152
+ * // Nitro / h3
2153
+ * const lunora = createLunoraHandler();
2154
+ * export default defineEventHandler((event) => {
2155
+ * const { ctx, env } = event.context.cloudflare;
2156
+ * return lunora(toWebRequest(event), env, ctx);
2157
+ * });
2158
+ * ```
2159
+ *
2160
+ * `shardDO` defaults to `env.SHARD`; pass `options` (or an `(env) => options`
2161
+ * factory) to add `auth`, `crons`, a `security` posture, or a custom namespace.
2162
+ * A new worker is composed per request because the options (and the `SHARD`
2163
+ * binding they default from) are only known once `env` arrives.
2164
+ * @param options Partial worker options (default `shardDO: env.SHARD`), or an `(env) => options` factory.
2165
+ */
2166
+ declare const createLunoraHandler: (options?: LunoraHandlerOptions) => ((request: Request, env: unknown, context?: ExecutionContextLike) => Promise<Response>);
2090
2167
  /** Re-exported helper so callers can roundtrip envelopes in tests. */
2091
2168
  declare const defineRpcEnvelope: (envelope: RpcEnvelope) => RpcEnvelope;
2092
2169
  /**
@@ -2330,4 +2407,4 @@ declare const analyticsEngineSink: (options: AnalyticsEngineSinkOptions) => Obse
2330
2407
  */
2331
2408
  declare const combineSinks: (...sinks: ObservabilitySink[]) => ObservabilitySink;
2332
2409
  declare const VERSION: string;
2333
- 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 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, applyJurisdiction, combineSinks, composeWorker, consoleSink, createCrossShardRelationCapabilities, createDynamicShardRegistry, createQueryCoordinator, createStaticShardRegistry, createWorker, decorateResponse, defineRpcEnvelope, emitLogEvent, emitRpcEvent, enforceOrigin, handleCorsPreflight, mergeStrategyForAggregate, resolveSecurity, resolveShard, sentrySink, toAirbyteMessages, toErrorResponse, toFivetranResponse, webhookSink, withFrameworkWorker };
2410
+ 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
  /**
@@ -1157,10 +1189,6 @@ interface RpcEnvelope {
1157
1189
  functionPath: string;
1158
1190
  shardKey?: string;
1159
1191
  }
1160
- interface ExecutionContextLike {
1161
- passThroughOnException: () => void;
1162
- waitUntil: (promise: Promise<unknown>) => void;
1163
- }
1164
1192
  type Route = (request: Request, env: unknown, context: ExecutionContextLike) => Promise<Response> | Response;
1165
1193
  /**
1166
1194
  * Context handed to HTTP-action handlers. Built per request by the worker; its
@@ -2087,6 +2115,55 @@ type FrameworkWorkerOptionsInput = ((env: unknown) => FrameworkWorkerOptions) |
2087
2115
  * @param optionsInput Lunora options minus `httpRouter`, or an `(env) => options` factory.
2088
2116
  */
2089
2117
  declare const withFrameworkWorker: (host: FrameworkHostHandler, optionsInput: FrameworkWorkerOptionsInput) => LunoraWorker;
2118
+ /**
2119
+ * Options for {@link createLunoraHandler}. Either an `(env) => options` factory
2120
+ * (full control — for bindings that only exist at request time), or a partial
2121
+ * {@link FrameworkWorkerOptions} object whose `shardDO` defaults to the
2122
+ * conventional `env.SHARD` binding. Pass nothing for the common case.
2123
+ */
2124
+ type LunoraHandlerOptions = ((env: unknown) => FrameworkWorkerOptions) | Partial<FrameworkWorkerOptions>;
2125
+ /**
2126
+ * Resolve per-request Lunora worker options. A factory is called with the
2127
+ * request `env`; a partial object has its `shardDO` defaulted to `env.SHARD` so
2128
+ * the common case needs no configuration. Throws a clear error when no shard
2129
+ * namespace can be found — a wiring mistake, not a runtime condition to swallow.
2130
+ */
2131
+ declare const resolveLunoraOptions: (options: LunoraHandlerOptions, env: unknown) => FrameworkWorkerOptions;
2132
+ /**
2133
+ * Build a framework-neutral request handler for Lunora's realtime plane
2134
+ * (`/_lunora/rpc`, `/_lunora/ws`, `/_lunora/admin/*`). This is the **one shared
2135
+ * seam** every web-standard framework integration mounts — Hono, Nitro/h3,
2136
+ * Elysia, or any WinterCG host running on Cloudflare Workers — so each is a
2137
+ * 1–2 line bridge (`(request, env, ctx) => Response`) rather than a bespoke
2138
+ * adapter package.
2139
+ *
2140
+ * Mount it under `/_lunora/*` (or whatever path you reserve) inside your app's
2141
+ * router; everything else stays your framework's. The host supplies, per
2142
+ * request: a Web `Request`, the Cloudflare `env` (carrying the `SHARD` Durable
2143
+ * Object namespace), and — when available — the `ExecutionContext`. The
2144
+ * `101 Switching Protocols` WebSocket-upgrade `Response` (with its `webSocket`)
2145
+ * is returned verbatim, so the framework streams the socket through unchanged.
2146
+ *
2147
+ * ```ts
2148
+ * // Hono
2149
+ * const lunora = createLunoraHandler();
2150
+ * app.use("/_lunora/*", (c) => lunora(c.req.raw, c.env, c.executionCtx));
2151
+ *
2152
+ * // Nitro / h3
2153
+ * const lunora = createLunoraHandler();
2154
+ * export default defineEventHandler((event) => {
2155
+ * const { ctx, env } = event.context.cloudflare;
2156
+ * return lunora(toWebRequest(event), env, ctx);
2157
+ * });
2158
+ * ```
2159
+ *
2160
+ * `shardDO` defaults to `env.SHARD`; pass `options` (or an `(env) => options`
2161
+ * factory) to add `auth`, `crons`, a `security` posture, or a custom namespace.
2162
+ * A new worker is composed per request because the options (and the `SHARD`
2163
+ * binding they default from) are only known once `env` arrives.
2164
+ * @param options Partial worker options (default `shardDO: env.SHARD`), or an `(env) => options` factory.
2165
+ */
2166
+ declare const createLunoraHandler: (options?: LunoraHandlerOptions) => ((request: Request, env: unknown, context?: ExecutionContextLike) => Promise<Response>);
2090
2167
  /** Re-exported helper so callers can roundtrip envelopes in tests. */
2091
2168
  declare const defineRpcEnvelope: (envelope: RpcEnvelope) => RpcEnvelope;
2092
2169
  /**
@@ -2330,4 +2407,4 @@ declare const analyticsEngineSink: (options: AnalyticsEngineSinkOptions) => Obse
2330
2407
  */
2331
2408
  declare const combineSinks: (...sinks: ObservabilitySink[]) => ObservabilitySink;
2332
2409
  declare const VERSION: string;
2333
- 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 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, applyJurisdiction, combineSinks, composeWorker, consoleSink, createCrossShardRelationCapabilities, createDynamicShardRegistry, createQueryCoordinator, createStaticShardRegistry, createWorker, decorateResponse, defineRpcEnvelope, emitLogEvent, emitRpcEvent, enforceOrigin, handleCorsPreflight, mergeStrategyForAggregate, resolveSecurity, resolveShard, sentrySink, toAirbyteMessages, toErrorResponse, toFivetranResponse, webhookSink, withFrameworkWorker };
2410
+ 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,5 +1,5 @@
1
1
  export { toAirbyteMessages, toFivetranResponse } from './packem_shared/toAirbyteMessages-DrHdplb4.mjs';
2
- export { composeWorker, createWorker, defineRpcEnvelope, withFrameworkWorker } from './packem_shared/composeWorker-49Hxp9Ho.mjs';
2
+ export { composeWorker, createLunoraHandler, createWorker, defineRpcEnvelope, resolveLunoraOptions, withFrameworkWorker } from './packem_shared/composeWorker-Bq1WvIOp.mjs';
3
3
  export { createCrossShardRelationCapabilities } from './packem_shared/createCrossShardRelationCapabilities-C0KOf7er.mjs';
4
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';
@@ -8,6 +8,7 @@ export { analyticsEngineSink, combineSinks, consoleSink, sentrySink, webhookSink
8
8
  export { createQueryCoordinator, createStaticShardRegistry, mergeStrategyForAggregate } from './packem_shared/createQueryCoordinator-Cbds9cUI.mjs';
9
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
 
@@ -0,0 +1,8 @@
1
+ const NOOP_EXECUTION_CONTEXT = {
2
+ passThroughOnException: () => {
3
+ },
4
+ waitUntil: () => {
5
+ }
6
+ };
7
+
8
+ export { NOOP_EXECUTION_CONTEXT };
@@ -1,3 +1,4 @@
1
+ import { NOOP_EXECUTION_CONTEXT } from './NOOP_EXECUTION_CONTEXT-CCTu0Bf1.mjs';
1
2
  import { LunoraError, toErrorResponse, isStructuralLunoraError, isStructuralConflictError } from './LunoraError-CL0aOtpo.mjs';
2
3
  import { emitRpcEvent } from './emitLogEvent-pEdtqAK8.mjs';
3
4
  import { resolveShard, applyJurisdiction } from './applyJurisdiction-BkZtTkct.mjs';
@@ -1502,7 +1503,7 @@ const buildWorkflowsAdminRoutes = (deps) => {
1502
1503
  assertAdmin(request);
1503
1504
  const client = resolveWorkflowsClient(env);
1504
1505
  if (!client) {
1505
- return throwNotConfigured();
1506
+ return Response.json({ configured: false, instances: [], page: 1, perPage: 0, totalCount: 0 });
1506
1507
  }
1507
1508
  const workflowName = requireQuery(url, "name");
1508
1509
  const status = toInstanceStatus(url.searchParams.get("status"));
@@ -1662,6 +1663,12 @@ const validateFanOut = (fanOut) => {
1662
1663
  }
1663
1664
  return spec;
1664
1665
  };
1666
+ const logRpcDebug = (env, envelope) => {
1667
+ if (!env?.LUNORA_DEBUG_RPC) {
1668
+ return;
1669
+ }
1670
+ console.warn(`[lunora:rpc] ${envelope.fanOut ? "fan-out" : `shard=${envelope.shardKey ?? "(root)"}`} ${envelope.functionPath}`);
1671
+ };
1665
1672
  const parseEnvelope = async (request) => {
1666
1673
  const text = await readBodyTextWithLimit(request);
1667
1674
  let body;
@@ -2149,6 +2156,7 @@ const createWorker = (options) => {
2149
2156
  throw new LunoraError("RPC endpoint requires POST", { code: "METHOD_NOT_ALLOWED", status: 405 });
2150
2157
  }
2151
2158
  const envelope = await parseEnvelope(request);
2159
+ logRpcDebug(env, envelope);
2152
2160
  if (envelope.fanOut && envelope.shardKey) {
2153
2161
  throw new LunoraError("RPC envelope cannot set both `shardKey` and `fanOut`", { code: "BAD_REQUEST", status: 400 });
2154
2162
  }
@@ -2171,7 +2179,7 @@ const createWorker = (options) => {
2171
2179
  const { observability } = options;
2172
2180
  const sinkContext = context ? {
2173
2181
  waitUntil: (promise) => {
2174
- context.waitUntil(promise);
2182
+ context.waitUntil?.(promise);
2175
2183
  }
2176
2184
  } : void 0;
2177
2185
  if (envelope.fanOut) {
@@ -2375,7 +2383,7 @@ const createWorker = (options) => {
2375
2383
  }
2376
2384
  const basePath = options.authBasePath ?? DEFAULT_AUTH_BASE_PATH;
2377
2385
  if (isAuthAttemptPath(url.pathname, basePath)) {
2378
- context.waitUntil(recordAuthAttempt(env, authResponse.status >= 400 ? "fail" : "ok"));
2386
+ context.waitUntil?.(recordAuthAttempt(env, authResponse.status >= 400 ? "fail" : "ok"));
2379
2387
  }
2380
2388
  return authResponse;
2381
2389
  };
@@ -2448,7 +2456,7 @@ const createWorker = (options) => {
2448
2456
  return {
2449
2457
  async fetch(request, env, context) {
2450
2458
  if (options.passThroughOnException) {
2451
- context.passThroughOnException();
2459
+ context.passThroughOnException?.();
2452
2460
  }
2453
2461
  ensureSecurityResolved(env);
2454
2462
  resolveAdminTokenFromEnv(env);
@@ -2505,6 +2513,19 @@ const withFrameworkWorker = (host, optionsInput) => {
2505
2513
  serverQuery: (request, env, reference, args, options) => build(optionsFactory(env)).serverQuery(request, env, reference, args, options)
2506
2514
  };
2507
2515
  };
2516
+ const resolveLunoraOptions = (options, env) => {
2517
+ if (typeof options === "function") {
2518
+ return options(env);
2519
+ }
2520
+ const shardDO = options.shardDO ?? env?.SHARD;
2521
+ if (!shardDO) {
2522
+ throw new Error(
2523
+ "@lunora/runtime: no shard Durable Object namespace found. Bind `SHARD` in wrangler.jsonc, or pass `createLunoraHandler({ shardDO: env.MY_SHARD })`."
2524
+ );
2525
+ }
2526
+ return { ...options, shardDO };
2527
+ };
2528
+ const createLunoraHandler = (options = {}) => (request, env, context) => createWorker(resolveLunoraOptions(options, env)).fetch(request, env, context ?? NOOP_EXECUTION_CONTEXT);
2508
2529
  const defineRpcEnvelope = (envelope) => envelope;
2509
2530
 
2510
- export { composeWorker, createWorker, defineRpcEnvelope, withFrameworkWorker };
2531
+ export { NOOP_EXECUTION_CONTEXT, composeWorker, createLunoraHandler, createWorker, defineRpcEnvelope, resolveLunoraOptions, withFrameworkWorker };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/runtime",
3
- "version": "1.0.0-alpha.5",
3
+ "version": "1.0.0-alpha.7",
4
4
  "description": "Lunora Worker runtime: the RPC router, shard resolver, and query coordinator",
5
5
  "keywords": [
6
6
  "cloudflare",