@lunora/server 1.0.0-alpha.214 → 1.0.0-alpha.215

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
@@ -1887,6 +1887,13 @@ type HttpRunners = Pick<ActionCtx, "runAction" | "runMutation" | "runQuery">;
1887
1887
  * the helper even on the branches that never went near storage.
1888
1888
  */
1889
1889
  type HttpActionCtx = {
1890
+ /**
1891
+ * Forward a server-to-server request to a shard Durable Object carrying the
1892
+ * caller's resolved identity headers — the seam the live-stream primitive
1893
+ * (`defineLiveStream`) uses to reach the shard's subscriber registry. See
1894
+ * {@link ShardFetch}.
1895
+ */
1896
+ readonly fetchShard: ShardFetch;
1890
1897
  /**
1891
1898
  * The same `run*` trio bound to `shardKey`, mirroring
1892
1899
  * `createShardClient(...).forShard(key)`:
@@ -1900,6 +1907,8 @@ type HttpActionCtx = {
1900
1907
  * DO — silently, with no way to say otherwise.
1901
1908
  */
1902
1909
  readonly forShard: (shardKey: string) => HttpRunners;
1910
+ /** Publish an arbitrary event to a live topic. See {@link LivePublisher}. */
1911
+ readonly live: LivePublisher;
1903
1912
  readonly scheduler?: ActionCtx["scheduler"];
1904
1913
  readonly storage?: ActionCtx["storage"];
1905
1914
  /**
@@ -1920,6 +1929,59 @@ type HttpActionCtx = {
1920
1929
  } & HttpRunners & Pick<ActionCtx, "auth" | "cache" | "fetch">;
1921
1930
  /** A raw handler wrapped by {@link httpAction}. Receives the raw request, returns the raw response. */
1922
1931
  type HttpActionHandler = (context: HttpActionCtx, request: Request) => Promise<Response> | Response;
1932
+ /** Init for {@link ShardFetch} — the fields the live-stream primitive needs. */
1933
+ interface ShardFetchInit {
1934
+ /** Request body (already serialized). */
1935
+ body?: string;
1936
+ /** Extra headers merged over the forwarded identity headers. */
1937
+ headers?: Record<string, string>;
1938
+ /** HTTP method; defaults to `GET`. */
1939
+ method?: string;
1940
+ }
1941
+ /**
1942
+ * Forward a server-to-server request to a shard Durable Object, carrying the
1943
+ * caller's resolved identity headers. This is the seam the live-stream
1944
+ * primitive uses to reach the shard's subscriber registry: a worker-side
1945
+ * `.stream()` handler cannot itself hold a connection-scoped subscription (the
1946
+ * registry must be the single-actor DO), so the SSE stream is served by the DO
1947
+ * and this is how the route reaches it.
1948
+ *
1949
+ * Not a general-purpose escape hatch: like `ctx.run*` it dispatches as trusted
1950
+ * worker code, so a handler must have already run whatever authorization it
1951
+ * requires before forwarding. An internal call has no client-reachable path of
1952
+ * its own — the DO is never directly addressable.
1953
+ *
1954
+ * `shardKey === undefined` targets the app's default shard.
1955
+ */
1956
+ type ShardFetch = (shardKey: string | undefined, path: string, init?: ShardFetchInit) => Promise<Response>;
1957
+ /** Where a {@link LivePublisher.publish} goes. */
1958
+ interface LivePublishOptions {
1959
+ /** The shard to publish on. Defaults to the ctx's default shard. */
1960
+ shardKey?: string;
1961
+ /**
1962
+ * The `id` of the `defineLiveStream` whose subscribers see the event. A
1963
+ * subscriber follows a topic through the stream that authorized it, so a
1964
+ * publish reaches only that stream's subscribers.
1965
+ */
1966
+ stream: string;
1967
+ }
1968
+ /**
1969
+ * `ctx.live` — publish an arbitrary event to a named topic. The event fans out
1970
+ * to the SSE subscribers of `options.stream` on the shard. WebSocket whisper
1971
+ * members never receive it (see the live-stream docblock).
1972
+ *
1973
+ * Reachable from an HTTP-action ctx; an action (a scheduled job) publishes
1974
+ * through the same surface in-process (see the live-stream docblock).
1975
+ */
1976
+ interface LivePublisher {
1977
+ /**
1978
+ * Publish `payload` to `topic` on `options.stream`. Best-effort — a topic
1979
+ * with no subscribers is a no-op. Rejects when the shard refuses the publish
1980
+ * (an oversized payload, or a room or route topic), so a silent drop is not
1981
+ * possible.
1982
+ */
1983
+ publish: (topic: string, payload: unknown, options: LivePublishOptions) => Promise<void>;
1984
+ }
1923
1985
  /**
1924
1986
  * The hono {@link https://hono.dev | Hono} environment used by {@link httpRouter}.
1925
1987
  * The runtime injects the per-request {@link HttpActionCtx} on the private
@@ -2468,6 +2530,58 @@ declare const clampLimit: (limit: number | undefined, fallback: number, maxLimit
2468
2530
  * the config requires the second call.
2469
2531
  */
2470
2532
  declare const defineListArgs: <TDocument>() => <F extends ListFilterShape<TDocument>, O extends keyof TDocument & string>(config: DefineListArgsConfig<F, O>) => ListArgsSpec<TDocument, F, O>;
2533
+ /**
2534
+ * Verdict handler for a live-topic subscribe. Return `true` to allow; anything
2535
+ * else denies (and a throw denies).
2536
+ */
2537
+ type LiveSubscribeHandler = (options: {
2538
+ ctx: HttpActionCtx;
2539
+ topic: string;
2540
+ }) => boolean | Promise<boolean>;
2541
+ /** Config for {@link defineLiveStream}. */
2542
+ interface LiveStreamConfig {
2543
+ /**
2544
+ * Opt-in for a public stream. It never skips {@link LiveStreamConfig.onSubscribe}:
2545
+ * when a handler is present, the handler decides for every caller and this flag
2546
+ * changes nothing. When `onSubscribe` is omitted, `true` admits an ANONYMOUS
2547
+ * caller (no identity) to any topic, and an authenticated caller is still
2548
+ * denied. Defaults to `false`. See the module docblock for why the default is deny.
2549
+ */
2550
+ allowAnonymousControl?: boolean;
2551
+ /** Stable id, used to derive {@link LiveStream.connectPath} / {@link LiveStream.controlPath}. */
2552
+ id: string;
2553
+ /**
2554
+ * Per-topic authorization, consulted for every subscribe from every caller.
2555
+ * Omitted ⇒ default-deny (unless `allowAnonymousControl` admits anonymous callers).
2556
+ */
2557
+ onSubscribe?: LiveSubscribeHandler;
2558
+ }
2559
+ /** The two route handlers {@link defineLiveStream} produces. */
2560
+ interface LiveStream {
2561
+ /** Mount with `app.get(stream.connectPath, stream.connect)`. Returns the SSE response. */
2562
+ connect: LunoraRouteHandler;
2563
+ /** `GET` path for the SSE connection. */
2564
+ connectPath: string;
2565
+ /** Mount with `app.post(stream.controlPath, stream.control)`. Returns a JSON ack. */
2566
+ control: LunoraRouteHandler;
2567
+ /** `POST` path for subscribe / unsubscribe control. */
2568
+ controlPath: string;
2569
+ id: string;
2570
+ }
2571
+ /**
2572
+ * Define a live topic stream. See the module docblock for the authorization
2573
+ * defaults and the hot-shard ceiling.
2574
+ *
2575
+ * Two limits to know before you ship. First, a subscription is authorized once,
2576
+ * at subscribe, and is not re-checked while the connection stays open: a
2577
+ * credential with an expiry ends the stream at that expiry, and a cookie session
2578
+ * with no expiry keeps receiving until the client closes the connection or
2579
+ * reconnects. Second, live streams are unavailable when delivery authorization is
2580
+ * enabled. Codegen refuses an app that declares a live stream and also calls
2581
+ * `.deliveryAuthorization(...)`, because the shard answers every `/_lunora/live/*`
2582
+ * route with 501 in that mode.
2583
+ */
2584
+ declare const defineLiveStream: (config: LiveStreamConfig) => LiveStream;
2471
2585
  /**
2472
2586
  * Structural mirrors of `@lunora/shard-engine`'s rank-page-row shapes
2473
2587
  * (`RankPageRowKey` / `RankPageRow` / `ShardRankPageResult`) — the return type
@@ -4096,7 +4210,7 @@ type RegisteredWhisperAuthorizer = RegisteredFunction<Record<string, never>, boo
4096
4210
  */
4097
4211
  declare const onWhisper: (handler: WhisperAuthorizeHandler) => RegisteredWhisperAuthorizer;
4098
4212
  declare const VERSION = "0.0.0";
4099
- export { DEFAULT_ACTION_CACHE_TTL_MS as ACTION_CACHE_DEFAULT_TTL_MS, ACTION_CACHE_TABLE, type ActionBuilder, type ActionCacheComponent, type ActionCacheContext, type ActionCacheDatabase, type ActionCacheFunctions, type ActionCtx, type AggregateIndexDefinition, type AggregateIndexOptions, type AggregateOp, type ArgsValidator, type Component, type ComponentFunctions, type CreateOptions, DEFAULT_LIMIT, DEFAULT_MAX_LIMIT, DEFAULT_REDACTED_FIELDS as DOCUMENT_HISTORY_REDACTED_FIELDS, DOCUMENT_HISTORY_TABLE, type DataModelInit, type DeferredDeleteFlushResult, type DefineActionCacheOptions, type DefineComponentOptions, type DefineDocumentHistoryOptions, type DefineIdentityOptions, type DefineListArgsConfig, type DefinePluginOptions, type DefinePolicyInput, type DefinePresenceOptions, type DefineRoomOptions, type DefineStorageRuleInput, type DocumentHistoryComponent, type DocumentHistoryEntry, type DocumentHistoryFunctions, type DurableObjectJurisdiction, type DurableStreamOptions, type EmptyArgs, type EnvAccessor, type EnvKeyFailure, type EnvShape, type ExposeConfig, type ExtendableSchema, type FacadeEntry, type FacadeWriterLike, type FunctionKind, type HttpActionCtx, type HttpActionHandler, type HttpMethod, type HttpRoute, type HttpRouteBuilder, type HttpRouteFactory, type HttpRouteHandlerOptions, type HttpRunners, type HttpStreamHandlerOptions, type IdentityContract, type IdentityRejectMode, type IdentityValidation, type IndexFieldsByTable, type InferArgs, type InferEnv, type InferIdentity, type InlineAggregateIndexOptions, type InlineRankIndexOptions, type InternalActionBuilder, type InternalMutationBuilder, type InternalQueryBuilder, type LifecycleEvent, type LifecycleHandler, type ListArgsSpec, type ListArgsValidators, type ListArgsValue, type ListFilterOperators, type ListOrderByEntry, type ListWhere, type LunoraBuilders, LunoraEnvError, type LunoraHttpApp, type LunoraHttpEnv, type LunoraRouteHandler, type ManyRelation, type MaskColumns, type MaskContext, type MaskFn, type MaskOptions, type MaskPolicies, type MaskRegistry, type MaskStrategy, type Middleware, type MiddlewareContext, type MiddlewareNext, type MigrationCtx, type MigrationDefinition, type MigrationDocument, type MigrationReader, type MigrationTransform, type ModuleConfig, type ModuleDefinition, type MutationBuilder, type MutationCtx, type MutatorDefinition, type OnDeleteAction, type OneRelation, type OrmLike, DEFAULT_TTL_MS as PRESENCE_DEFAULT_TTL_MS, PRESENCE_TABLE, type Permission, type PlatformAdminCheck, type Plugin, type Policy, type PrefixedTables, type PresenceComponent, type PresenceFunctions, type PresenceMember, type ProtectPublicOptions, type QueryBuilder, type QueryCtx, type RankIndexDefinition, type RankIndexOptions, type ReactorHandler, type ReactorOutcome, type ReactorSelect, type RegisteredAction, type RegisteredFunction, type RegisteredLifecycleHook, type RegisteredMigration, type RegisteredMutation, type RegisteredMutator, type RegisteredQuery, type RegisteredReactor, type RegisteredRoom, type RegisteredShape, type RegisteredStream, type RegisteredWhisperAuthorizer, type RelationBuilder, type RelationDefinition, type RelationThrough, type RlsOptions, type RlsReadRegistry, type Role, type RoomJoinHandler, type RoomLeaveHandler, type RoomMessageHandler, type RoomMessageOf, type RoomSocket, type Schema, type SchemaExtension, type ServiceBindingSpec, type ServiceFetcher, type ServiceRpc, type ShapeDefinition, type ShapeGuardDeclaration, type ShapeReadWhereRequest, type ShardInitEvent, type ShardInitHandler, type SseEvent, type StorageOperation, type StorageRule, type StorageRuleContext, type StorageRuleDecision, type StorageRulesOptions, type StorageServeAuthorizer, type StorageServeAuthzContext, type TableBuilder, type TableDefinition, type TerminalKind, type TriggerBuilder, type TriggerDefinition, type TypedDefinePolicyInput, VERSION, type VectorEmbedder, type VectorIndexDefinition, type VectorIndexOptions, type VectorMetric, type VectorizeOptions, type WhereInput, type WhisperAuthorizeHandler, type WhisperEvent, actionCacheExtension, allowAll, asBucketStorage, assertShapesDeclareReadPolicies, beginDeferredDeletes, beginDeferredSchedules, bindOrm, bindTableFacade, buildMaskRegistry, buildRlsReadRegistry, cacheKeyFor, clampLimit, composePluginMiddleware, composeShapeReadWhere, createPolicyDsl, createSecrets, createServices, defineActionCache, defineAggregateIndex, defineComponent, defineDocumentHistory, defineEnv, defineIdentity, defineIdentityGuard, defineListArgs, defineMigration, defineModule, defineMutator, definePermission, definePlugin, definePolicies, definePolicy, definePresence, defineRankIndex, defineRole, defineRoom, defineSchema, defineSchemaExtension, defineShape, defineStorageRule, defineStorageRules, defineTable, defineVectorIndex, deny, documentHistoryExtension, flushDeferredDeletes,
4213
+ export { DEFAULT_ACTION_CACHE_TTL_MS as ACTION_CACHE_DEFAULT_TTL_MS, ACTION_CACHE_TABLE, type ActionBuilder, type ActionCacheComponent, type ActionCacheContext, type ActionCacheDatabase, type ActionCacheFunctions, type ActionCtx, type AggregateIndexDefinition, type AggregateIndexOptions, type AggregateOp, type ArgsValidator, type Component, type ComponentFunctions, type CreateOptions, DEFAULT_LIMIT, DEFAULT_MAX_LIMIT, DEFAULT_REDACTED_FIELDS as DOCUMENT_HISTORY_REDACTED_FIELDS, DOCUMENT_HISTORY_TABLE, type DataModelInit, type DeferredDeleteFlushResult, type DefineActionCacheOptions, type DefineComponentOptions, type DefineDocumentHistoryOptions, type DefineIdentityOptions, type DefineListArgsConfig, type DefinePluginOptions, type DefinePolicyInput, type DefinePresenceOptions, type DefineRoomOptions, type DefineStorageRuleInput, type DocumentHistoryComponent, type DocumentHistoryEntry, type DocumentHistoryFunctions, type DurableObjectJurisdiction, type DurableStreamOptions, type EmptyArgs, type EnvAccessor, type EnvKeyFailure, type EnvShape, type ExposeConfig, type ExtendableSchema, type FacadeEntry, type FacadeWriterLike, type FunctionKind, type HttpActionCtx, type HttpActionHandler, type HttpMethod, type HttpRoute, type HttpRouteBuilder, type HttpRouteFactory, type HttpRouteHandlerOptions, type HttpRunners, type HttpStreamHandlerOptions, type IdentityContract, type IdentityRejectMode, type IdentityValidation, type IndexFieldsByTable, type InferArgs, type InferEnv, type InferIdentity, type InlineAggregateIndexOptions, type InlineRankIndexOptions, type InternalActionBuilder, type InternalMutationBuilder, type InternalQueryBuilder, type LifecycleEvent, type LifecycleHandler, type ListArgsSpec, type ListArgsValidators, type ListArgsValue, type ListFilterOperators, type ListOrderByEntry, type ListWhere, type LivePublishOptions, type LivePublisher, type LiveStream, type LiveStreamConfig, type LiveSubscribeHandler, type LunoraBuilders, LunoraEnvError, type LunoraHttpApp, type LunoraHttpEnv, type LunoraRouteHandler, type ManyRelation, type MaskColumns, type MaskContext, type MaskFn, type MaskOptions, type MaskPolicies, type MaskRegistry, type MaskStrategy, type Middleware, type MiddlewareContext, type MiddlewareNext, type MigrationCtx, type MigrationDefinition, type MigrationDocument, type MigrationReader, type MigrationTransform, type ModuleConfig, type ModuleDefinition, type MutationBuilder, type MutationCtx, type MutatorDefinition, type OnDeleteAction, type OneRelation, type OrmLike, DEFAULT_TTL_MS as PRESENCE_DEFAULT_TTL_MS, PRESENCE_TABLE, type Permission, type PlatformAdminCheck, type Plugin, type Policy, type PrefixedTables, type PresenceComponent, type PresenceFunctions, type PresenceMember, type ProtectPublicOptions, type QueryBuilder, type QueryCtx, type RankIndexDefinition, type RankIndexOptions, type ReactorHandler, type ReactorOutcome, type ReactorSelect, type RegisteredAction, type RegisteredFunction, type RegisteredLifecycleHook, type RegisteredMigration, type RegisteredMutation, type RegisteredMutator, type RegisteredQuery, type RegisteredReactor, type RegisteredRoom, type RegisteredShape, type RegisteredStream, type RegisteredWhisperAuthorizer, type RelationBuilder, type RelationDefinition, type RelationThrough, type RlsOptions, type RlsReadRegistry, type Role, type RoomJoinHandler, type RoomLeaveHandler, type RoomMessageHandler, type RoomMessageOf, type RoomSocket, type Schema, type SchemaExtension, type ServiceBindingSpec, type ServiceFetcher, type ServiceRpc, type ShapeDefinition, type ShapeGuardDeclaration, type ShapeReadWhereRequest, type ShardFetch, type ShardFetchInit, type ShardInitEvent, type ShardInitHandler, type SseEvent, type StorageOperation, type StorageRule, type StorageRuleContext, type StorageRuleDecision, type StorageRulesOptions, type StorageServeAuthorizer, type StorageServeAuthzContext, type TableBuilder, type TableDefinition, type TerminalKind, type TriggerBuilder, type TriggerDefinition, type TypedDefinePolicyInput, VERSION, type VectorEmbedder, type VectorIndexDefinition, type VectorIndexOptions, type VectorMetric, type VectorizeOptions, type WhereInput, type WhisperAuthorizeHandler, type WhisperEvent, actionCacheExtension, allowAll, asBucketStorage, assertShapesDeclareReadPolicies, beginDeferredDeletes, beginDeferredSchedules, bindOrm, bindTableFacade, buildMaskRegistry, buildRlsReadRegistry, cacheKeyFor, clampLimit, composePluginMiddleware, composeShapeReadWhere, createPolicyDsl, createSecrets, createServices, defineActionCache, defineAggregateIndex, defineComponent, defineDocumentHistory, defineEnv, defineIdentity, defineIdentityGuard, defineListArgs, defineLiveStream, defineMigration, defineModule, defineMutator, definePermission, definePlugin, definePolicies, definePolicy, definePresence, defineRankIndex, defineRole, defineRoom, defineSchema, defineSchemaExtension, defineShape, defineStorageRule, defineStorageRules, defineTable, defineVectorIndex, deny, documentHistoryExtension, flushDeferredDeletes,
4100
4214
  /**
4101
4215
  * True when `value` is safe to use as an HTTP header field-value: no CR, LF, or
4102
4216
  * NUL. Guards against response-header injection / `Headers`-construction throws
package/dist/index.d.ts CHANGED
@@ -1887,6 +1887,13 @@ type HttpRunners = Pick<ActionCtx, "runAction" | "runMutation" | "runQuery">;
1887
1887
  * the helper even on the branches that never went near storage.
1888
1888
  */
1889
1889
  type HttpActionCtx = {
1890
+ /**
1891
+ * Forward a server-to-server request to a shard Durable Object carrying the
1892
+ * caller's resolved identity headers — the seam the live-stream primitive
1893
+ * (`defineLiveStream`) uses to reach the shard's subscriber registry. See
1894
+ * {@link ShardFetch}.
1895
+ */
1896
+ readonly fetchShard: ShardFetch;
1890
1897
  /**
1891
1898
  * The same `run*` trio bound to `shardKey`, mirroring
1892
1899
  * `createShardClient(...).forShard(key)`:
@@ -1900,6 +1907,8 @@ type HttpActionCtx = {
1900
1907
  * DO — silently, with no way to say otherwise.
1901
1908
  */
1902
1909
  readonly forShard: (shardKey: string) => HttpRunners;
1910
+ /** Publish an arbitrary event to a live topic. See {@link LivePublisher}. */
1911
+ readonly live: LivePublisher;
1903
1912
  readonly scheduler?: ActionCtx["scheduler"];
1904
1913
  readonly storage?: ActionCtx["storage"];
1905
1914
  /**
@@ -1920,6 +1929,59 @@ type HttpActionCtx = {
1920
1929
  } & HttpRunners & Pick<ActionCtx, "auth" | "cache" | "fetch">;
1921
1930
  /** A raw handler wrapped by {@link httpAction}. Receives the raw request, returns the raw response. */
1922
1931
  type HttpActionHandler = (context: HttpActionCtx, request: Request) => Promise<Response> | Response;
1932
+ /** Init for {@link ShardFetch} — the fields the live-stream primitive needs. */
1933
+ interface ShardFetchInit {
1934
+ /** Request body (already serialized). */
1935
+ body?: string;
1936
+ /** Extra headers merged over the forwarded identity headers. */
1937
+ headers?: Record<string, string>;
1938
+ /** HTTP method; defaults to `GET`. */
1939
+ method?: string;
1940
+ }
1941
+ /**
1942
+ * Forward a server-to-server request to a shard Durable Object, carrying the
1943
+ * caller's resolved identity headers. This is the seam the live-stream
1944
+ * primitive uses to reach the shard's subscriber registry: a worker-side
1945
+ * `.stream()` handler cannot itself hold a connection-scoped subscription (the
1946
+ * registry must be the single-actor DO), so the SSE stream is served by the DO
1947
+ * and this is how the route reaches it.
1948
+ *
1949
+ * Not a general-purpose escape hatch: like `ctx.run*` it dispatches as trusted
1950
+ * worker code, so a handler must have already run whatever authorization it
1951
+ * requires before forwarding. An internal call has no client-reachable path of
1952
+ * its own — the DO is never directly addressable.
1953
+ *
1954
+ * `shardKey === undefined` targets the app's default shard.
1955
+ */
1956
+ type ShardFetch = (shardKey: string | undefined, path: string, init?: ShardFetchInit) => Promise<Response>;
1957
+ /** Where a {@link LivePublisher.publish} goes. */
1958
+ interface LivePublishOptions {
1959
+ /** The shard to publish on. Defaults to the ctx's default shard. */
1960
+ shardKey?: string;
1961
+ /**
1962
+ * The `id` of the `defineLiveStream` whose subscribers see the event. A
1963
+ * subscriber follows a topic through the stream that authorized it, so a
1964
+ * publish reaches only that stream's subscribers.
1965
+ */
1966
+ stream: string;
1967
+ }
1968
+ /**
1969
+ * `ctx.live` — publish an arbitrary event to a named topic. The event fans out
1970
+ * to the SSE subscribers of `options.stream` on the shard. WebSocket whisper
1971
+ * members never receive it (see the live-stream docblock).
1972
+ *
1973
+ * Reachable from an HTTP-action ctx; an action (a scheduled job) publishes
1974
+ * through the same surface in-process (see the live-stream docblock).
1975
+ */
1976
+ interface LivePublisher {
1977
+ /**
1978
+ * Publish `payload` to `topic` on `options.stream`. Best-effort — a topic
1979
+ * with no subscribers is a no-op. Rejects when the shard refuses the publish
1980
+ * (an oversized payload, or a room or route topic), so a silent drop is not
1981
+ * possible.
1982
+ */
1983
+ publish: (topic: string, payload: unknown, options: LivePublishOptions) => Promise<void>;
1984
+ }
1923
1985
  /**
1924
1986
  * The hono {@link https://hono.dev | Hono} environment used by {@link httpRouter}.
1925
1987
  * The runtime injects the per-request {@link HttpActionCtx} on the private
@@ -2468,6 +2530,58 @@ declare const clampLimit: (limit: number | undefined, fallback: number, maxLimit
2468
2530
  * the config requires the second call.
2469
2531
  */
2470
2532
  declare const defineListArgs: <TDocument>() => <F extends ListFilterShape<TDocument>, O extends keyof TDocument & string>(config: DefineListArgsConfig<F, O>) => ListArgsSpec<TDocument, F, O>;
2533
+ /**
2534
+ * Verdict handler for a live-topic subscribe. Return `true` to allow; anything
2535
+ * else denies (and a throw denies).
2536
+ */
2537
+ type LiveSubscribeHandler = (options: {
2538
+ ctx: HttpActionCtx;
2539
+ topic: string;
2540
+ }) => boolean | Promise<boolean>;
2541
+ /** Config for {@link defineLiveStream}. */
2542
+ interface LiveStreamConfig {
2543
+ /**
2544
+ * Opt-in for a public stream. It never skips {@link LiveStreamConfig.onSubscribe}:
2545
+ * when a handler is present, the handler decides for every caller and this flag
2546
+ * changes nothing. When `onSubscribe` is omitted, `true` admits an ANONYMOUS
2547
+ * caller (no identity) to any topic, and an authenticated caller is still
2548
+ * denied. Defaults to `false`. See the module docblock for why the default is deny.
2549
+ */
2550
+ allowAnonymousControl?: boolean;
2551
+ /** Stable id, used to derive {@link LiveStream.connectPath} / {@link LiveStream.controlPath}. */
2552
+ id: string;
2553
+ /**
2554
+ * Per-topic authorization, consulted for every subscribe from every caller.
2555
+ * Omitted ⇒ default-deny (unless `allowAnonymousControl` admits anonymous callers).
2556
+ */
2557
+ onSubscribe?: LiveSubscribeHandler;
2558
+ }
2559
+ /** The two route handlers {@link defineLiveStream} produces. */
2560
+ interface LiveStream {
2561
+ /** Mount with `app.get(stream.connectPath, stream.connect)`. Returns the SSE response. */
2562
+ connect: LunoraRouteHandler;
2563
+ /** `GET` path for the SSE connection. */
2564
+ connectPath: string;
2565
+ /** Mount with `app.post(stream.controlPath, stream.control)`. Returns a JSON ack. */
2566
+ control: LunoraRouteHandler;
2567
+ /** `POST` path for subscribe / unsubscribe control. */
2568
+ controlPath: string;
2569
+ id: string;
2570
+ }
2571
+ /**
2572
+ * Define a live topic stream. See the module docblock for the authorization
2573
+ * defaults and the hot-shard ceiling.
2574
+ *
2575
+ * Two limits to know before you ship. First, a subscription is authorized once,
2576
+ * at subscribe, and is not re-checked while the connection stays open: a
2577
+ * credential with an expiry ends the stream at that expiry, and a cookie session
2578
+ * with no expiry keeps receiving until the client closes the connection or
2579
+ * reconnects. Second, live streams are unavailable when delivery authorization is
2580
+ * enabled. Codegen refuses an app that declares a live stream and also calls
2581
+ * `.deliveryAuthorization(...)`, because the shard answers every `/_lunora/live/*`
2582
+ * route with 501 in that mode.
2583
+ */
2584
+ declare const defineLiveStream: (config: LiveStreamConfig) => LiveStream;
2471
2585
  /**
2472
2586
  * Structural mirrors of `@lunora/shard-engine`'s rank-page-row shapes
2473
2587
  * (`RankPageRowKey` / `RankPageRow` / `ShardRankPageResult`) — the return type
@@ -4096,7 +4210,7 @@ type RegisteredWhisperAuthorizer = RegisteredFunction<Record<string, never>, boo
4096
4210
  */
4097
4211
  declare const onWhisper: (handler: WhisperAuthorizeHandler) => RegisteredWhisperAuthorizer;
4098
4212
  declare const VERSION = "0.0.0";
4099
- export { DEFAULT_ACTION_CACHE_TTL_MS as ACTION_CACHE_DEFAULT_TTL_MS, ACTION_CACHE_TABLE, type ActionBuilder, type ActionCacheComponent, type ActionCacheContext, type ActionCacheDatabase, type ActionCacheFunctions, type ActionCtx, type AggregateIndexDefinition, type AggregateIndexOptions, type AggregateOp, type ArgsValidator, type Component, type ComponentFunctions, type CreateOptions, DEFAULT_LIMIT, DEFAULT_MAX_LIMIT, DEFAULT_REDACTED_FIELDS as DOCUMENT_HISTORY_REDACTED_FIELDS, DOCUMENT_HISTORY_TABLE, type DataModelInit, type DeferredDeleteFlushResult, type DefineActionCacheOptions, type DefineComponentOptions, type DefineDocumentHistoryOptions, type DefineIdentityOptions, type DefineListArgsConfig, type DefinePluginOptions, type DefinePolicyInput, type DefinePresenceOptions, type DefineRoomOptions, type DefineStorageRuleInput, type DocumentHistoryComponent, type DocumentHistoryEntry, type DocumentHistoryFunctions, type DurableObjectJurisdiction, type DurableStreamOptions, type EmptyArgs, type EnvAccessor, type EnvKeyFailure, type EnvShape, type ExposeConfig, type ExtendableSchema, type FacadeEntry, type FacadeWriterLike, type FunctionKind, type HttpActionCtx, type HttpActionHandler, type HttpMethod, type HttpRoute, type HttpRouteBuilder, type HttpRouteFactory, type HttpRouteHandlerOptions, type HttpRunners, type HttpStreamHandlerOptions, type IdentityContract, type IdentityRejectMode, type IdentityValidation, type IndexFieldsByTable, type InferArgs, type InferEnv, type InferIdentity, type InlineAggregateIndexOptions, type InlineRankIndexOptions, type InternalActionBuilder, type InternalMutationBuilder, type InternalQueryBuilder, type LifecycleEvent, type LifecycleHandler, type ListArgsSpec, type ListArgsValidators, type ListArgsValue, type ListFilterOperators, type ListOrderByEntry, type ListWhere, type LunoraBuilders, LunoraEnvError, type LunoraHttpApp, type LunoraHttpEnv, type LunoraRouteHandler, type ManyRelation, type MaskColumns, type MaskContext, type MaskFn, type MaskOptions, type MaskPolicies, type MaskRegistry, type MaskStrategy, type Middleware, type MiddlewareContext, type MiddlewareNext, type MigrationCtx, type MigrationDefinition, type MigrationDocument, type MigrationReader, type MigrationTransform, type ModuleConfig, type ModuleDefinition, type MutationBuilder, type MutationCtx, type MutatorDefinition, type OnDeleteAction, type OneRelation, type OrmLike, DEFAULT_TTL_MS as PRESENCE_DEFAULT_TTL_MS, PRESENCE_TABLE, type Permission, type PlatformAdminCheck, type Plugin, type Policy, type PrefixedTables, type PresenceComponent, type PresenceFunctions, type PresenceMember, type ProtectPublicOptions, type QueryBuilder, type QueryCtx, type RankIndexDefinition, type RankIndexOptions, type ReactorHandler, type ReactorOutcome, type ReactorSelect, type RegisteredAction, type RegisteredFunction, type RegisteredLifecycleHook, type RegisteredMigration, type RegisteredMutation, type RegisteredMutator, type RegisteredQuery, type RegisteredReactor, type RegisteredRoom, type RegisteredShape, type RegisteredStream, type RegisteredWhisperAuthorizer, type RelationBuilder, type RelationDefinition, type RelationThrough, type RlsOptions, type RlsReadRegistry, type Role, type RoomJoinHandler, type RoomLeaveHandler, type RoomMessageHandler, type RoomMessageOf, type RoomSocket, type Schema, type SchemaExtension, type ServiceBindingSpec, type ServiceFetcher, type ServiceRpc, type ShapeDefinition, type ShapeGuardDeclaration, type ShapeReadWhereRequest, type ShardInitEvent, type ShardInitHandler, type SseEvent, type StorageOperation, type StorageRule, type StorageRuleContext, type StorageRuleDecision, type StorageRulesOptions, type StorageServeAuthorizer, type StorageServeAuthzContext, type TableBuilder, type TableDefinition, type TerminalKind, type TriggerBuilder, type TriggerDefinition, type TypedDefinePolicyInput, VERSION, type VectorEmbedder, type VectorIndexDefinition, type VectorIndexOptions, type VectorMetric, type VectorizeOptions, type WhereInput, type WhisperAuthorizeHandler, type WhisperEvent, actionCacheExtension, allowAll, asBucketStorage, assertShapesDeclareReadPolicies, beginDeferredDeletes, beginDeferredSchedules, bindOrm, bindTableFacade, buildMaskRegistry, buildRlsReadRegistry, cacheKeyFor, clampLimit, composePluginMiddleware, composeShapeReadWhere, createPolicyDsl, createSecrets, createServices, defineActionCache, defineAggregateIndex, defineComponent, defineDocumentHistory, defineEnv, defineIdentity, defineIdentityGuard, defineListArgs, defineMigration, defineModule, defineMutator, definePermission, definePlugin, definePolicies, definePolicy, definePresence, defineRankIndex, defineRole, defineRoom, defineSchema, defineSchemaExtension, defineShape, defineStorageRule, defineStorageRules, defineTable, defineVectorIndex, deny, documentHistoryExtension, flushDeferredDeletes,
4213
+ export { DEFAULT_ACTION_CACHE_TTL_MS as ACTION_CACHE_DEFAULT_TTL_MS, ACTION_CACHE_TABLE, type ActionBuilder, type ActionCacheComponent, type ActionCacheContext, type ActionCacheDatabase, type ActionCacheFunctions, type ActionCtx, type AggregateIndexDefinition, type AggregateIndexOptions, type AggregateOp, type ArgsValidator, type Component, type ComponentFunctions, type CreateOptions, DEFAULT_LIMIT, DEFAULT_MAX_LIMIT, DEFAULT_REDACTED_FIELDS as DOCUMENT_HISTORY_REDACTED_FIELDS, DOCUMENT_HISTORY_TABLE, type DataModelInit, type DeferredDeleteFlushResult, type DefineActionCacheOptions, type DefineComponentOptions, type DefineDocumentHistoryOptions, type DefineIdentityOptions, type DefineListArgsConfig, type DefinePluginOptions, type DefinePolicyInput, type DefinePresenceOptions, type DefineRoomOptions, type DefineStorageRuleInput, type DocumentHistoryComponent, type DocumentHistoryEntry, type DocumentHistoryFunctions, type DurableObjectJurisdiction, type DurableStreamOptions, type EmptyArgs, type EnvAccessor, type EnvKeyFailure, type EnvShape, type ExposeConfig, type ExtendableSchema, type FacadeEntry, type FacadeWriterLike, type FunctionKind, type HttpActionCtx, type HttpActionHandler, type HttpMethod, type HttpRoute, type HttpRouteBuilder, type HttpRouteFactory, type HttpRouteHandlerOptions, type HttpRunners, type HttpStreamHandlerOptions, type IdentityContract, type IdentityRejectMode, type IdentityValidation, type IndexFieldsByTable, type InferArgs, type InferEnv, type InferIdentity, type InlineAggregateIndexOptions, type InlineRankIndexOptions, type InternalActionBuilder, type InternalMutationBuilder, type InternalQueryBuilder, type LifecycleEvent, type LifecycleHandler, type ListArgsSpec, type ListArgsValidators, type ListArgsValue, type ListFilterOperators, type ListOrderByEntry, type ListWhere, type LivePublishOptions, type LivePublisher, type LiveStream, type LiveStreamConfig, type LiveSubscribeHandler, type LunoraBuilders, LunoraEnvError, type LunoraHttpApp, type LunoraHttpEnv, type LunoraRouteHandler, type ManyRelation, type MaskColumns, type MaskContext, type MaskFn, type MaskOptions, type MaskPolicies, type MaskRegistry, type MaskStrategy, type Middleware, type MiddlewareContext, type MiddlewareNext, type MigrationCtx, type MigrationDefinition, type MigrationDocument, type MigrationReader, type MigrationTransform, type ModuleConfig, type ModuleDefinition, type MutationBuilder, type MutationCtx, type MutatorDefinition, type OnDeleteAction, type OneRelation, type OrmLike, DEFAULT_TTL_MS as PRESENCE_DEFAULT_TTL_MS, PRESENCE_TABLE, type Permission, type PlatformAdminCheck, type Plugin, type Policy, type PrefixedTables, type PresenceComponent, type PresenceFunctions, type PresenceMember, type ProtectPublicOptions, type QueryBuilder, type QueryCtx, type RankIndexDefinition, type RankIndexOptions, type ReactorHandler, type ReactorOutcome, type ReactorSelect, type RegisteredAction, type RegisteredFunction, type RegisteredLifecycleHook, type RegisteredMigration, type RegisteredMutation, type RegisteredMutator, type RegisteredQuery, type RegisteredReactor, type RegisteredRoom, type RegisteredShape, type RegisteredStream, type RegisteredWhisperAuthorizer, type RelationBuilder, type RelationDefinition, type RelationThrough, type RlsOptions, type RlsReadRegistry, type Role, type RoomJoinHandler, type RoomLeaveHandler, type RoomMessageHandler, type RoomMessageOf, type RoomSocket, type Schema, type SchemaExtension, type ServiceBindingSpec, type ServiceFetcher, type ServiceRpc, type ShapeDefinition, type ShapeGuardDeclaration, type ShapeReadWhereRequest, type ShardFetch, type ShardFetchInit, type ShardInitEvent, type ShardInitHandler, type SseEvent, type StorageOperation, type StorageRule, type StorageRuleContext, type StorageRuleDecision, type StorageRulesOptions, type StorageServeAuthorizer, type StorageServeAuthzContext, type TableBuilder, type TableDefinition, type TerminalKind, type TriggerBuilder, type TriggerDefinition, type TypedDefinePolicyInput, VERSION, type VectorEmbedder, type VectorIndexDefinition, type VectorIndexOptions, type VectorMetric, type VectorizeOptions, type WhereInput, type WhisperAuthorizeHandler, type WhisperEvent, actionCacheExtension, allowAll, asBucketStorage, assertShapesDeclareReadPolicies, beginDeferredDeletes, beginDeferredSchedules, bindOrm, bindTableFacade, buildMaskRegistry, buildRlsReadRegistry, cacheKeyFor, clampLimit, composePluginMiddleware, composeShapeReadWhere, createPolicyDsl, createSecrets, createServices, defineActionCache, defineAggregateIndex, defineComponent, defineDocumentHistory, defineEnv, defineIdentity, defineIdentityGuard, defineListArgs, defineLiveStream, defineMigration, defineModule, defineMutator, definePermission, definePlugin, definePolicies, definePolicy, definePresence, defineRankIndex, defineRole, defineRoom, defineSchema, defineSchemaExtension, defineShape, defineStorageRule, defineStorageRules, defineTable, defineVectorIndex, deny, documentHistoryExtension, flushDeferredDeletes,
4100
4214
  /**
4101
4215
  * True when `value` is safe to use as an HTTP header field-value: no CR, LF, or
4102
4216
  * NUL. Guards against response-header injection / `Headers`-construction throws
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{ACTION_CACHE_DEFAULT_TTL_MS as t,ACTION_CACHE_TABLE as n,actionCacheExtension as i,cacheKeyFor as f,defineActionCache as a}from"./packem_shared/ACTION_CACHE_DEFAULT_TTL_MS-mmP-6BcT.mjs";import{initLunora as d}from"./packem_shared/initLunora-B-7Xs3Qq.mjs";import{isPerDispatchMiddleware as p,tagPerDispatchMiddleware as x}from"./packem_shared/isPerDispatchMiddleware-DDQPatSm.mjs";import{createSecrets as l}from"./packem_shared/createSecrets-D6rLB42U.mjs";import{beginDeferredDeletes as u,flushDeferredDeletes as h,withDeferredDeletes as S}from"./packem_shared/beginDeferredDeletes-DhwFBbvs.mjs";import{beginDeferredSchedules as T,withDeferredSchedules as g}from"./packem_shared/beginDeferredSchedules-C7QLYr6C.mjs";import{DOCUMENT_HISTORY_REDACTED_FIELDS as A,DOCUMENT_HISTORY_TABLE as I,defineDocumentHistory as _,documentHistoryExtension as L}from"./packem_shared/DOCUMENT_HISTORY_REDACTED_FIELDS-B5Zp-7SI.mjs";import{LunoraEnvError as M,defineEnv as P,redactSecrets as b}from"./packem_shared/LunoraEnvError-bkdMu_-N.mjs";import{bindOrm as F,bindTableFacade as O}from"./packem_shared/bindOrm-9fbLRbOb.mjs";import{httpAction as H,httpRoute as N,httpRouter as w,isSafeHeaderValue as U,lastEventId as k,sseEvent as B}from"./packem_shared/httpAction-D2S7bQzl.mjs";import{serveStorageObject as W}from"./packem_shared/serveStorageObject-aqBFrLyo.mjs";import{defineIdentity as Y}from"./packem_shared/defineIdentity-DwkNKwYa.mjs";import{default as J}from"./packem_shared/defineIdentityGuard-Bt8N65Zs.mjs";import{onConnect as Q,onDisconnect as X,onShardInit as q}from"./packem_shared/onConnect-BLRoOpv2.mjs";import{DEFAULT_LIMIT as Z,DEFAULT_MAX_LIMIT as $,clampLimit as ee,defineListArgs as re}from"./packem_shared/DEFAULT_LIMIT-pT_tV8R0.mjs";import{defineMigration as te}from"./packem_shared/defineMigration-CXOS0Bvq.mjs";import{defineModule as ie}from"./packem_shared/defineModule-OecXWM3U.mjs";import{defineMutator as ae}from"./packem_shared/defineMutator-B4ipDtDR.mjs";import{platformAdmin as de}from"./packem_shared/platformAdmin-kczXQme8.mjs";import{c as pe,d as xe,a as ce,b as le,e as Ee,f as ue,g as he,h as Se,i as De,j as Te,k as ge,m as Re}from"./packem_shared/plugin-Bm9wIpiI.mjs";import{PRESENCE_DEFAULT_TTL_MS as Ie,PRESENCE_TABLE as _e,definePresence as Le,presenceExtension as Ce}from"./packem_shared/PRESENCE_DEFAULT_TTL_MS-DFpy5J8G.mjs";import{protectPublic as Pe}from"./packem_shared/protectPublic-Bi5_95aP.mjs";import{onQueryChange as ye}from"./packem_shared/onQueryChange-iuLzmyPs.mjs";import{defineRoom as Oe}from"./packem_shared/defineRoom-CoGi-xwm.mjs";import{createServices as He}from"./packem_shared/createServices-IJvoqi0e.mjs";import{defineShape as we}from"./packem_shared/defineShape-CwKm5KLp.mjs";import{onWhisper as ke}from"./packem_shared/onWhisper-CfDbFLQh.mjs";import{LunoraError as Ve}from"@lunora/errors";import{cronJobs as je}from"@lunora/scheduler";import{ValidationError as Ge,v as Je}from"@lunora/values";import{allowAll as Qe,deny as Xe,isDeny as qe,toWhereInput as ze}from"./packem_shared/allowAll-DkRAgItV.mjs";import{asBucketStorage as $e}from"./packem_shared/asBucketStorage-DoGYOjq3.mjs";import{assertShapesDeclareReadPolicies as rr,buildRlsReadRegistry as or,composeShapeReadWhere as tr}from"./packem_shared/assertShapesDeclareReadPolicies-Bg4Ter7Q.mjs";import{buildMaskRegistry as ir}from"./packem_shared/buildMaskRegistry-DpWMtalG.mjs";import{createPolicyDsl as ar,definePermission as sr,definePolicies as dr,definePolicy as mr,defineRole as pr}from"./packem_shared/createPolicyDsl-BZa6SqLJ.mjs";import{defineStorageRule as cr,defineStorageRules as lr}from"./packem_shared/defineStorageRule-Dv4nJE0H.mjs";import{mask as ur}from"./packem_shared/mask-D-jRCAhy.mjs";import{r as Sr}from"./packem_shared/middleware-3ySZVrpt.mjs";import{storageRules as Tr}from"./packem_shared/storageRules-CBLioxF7.mjs";const e="0.0.0";export{t as ACTION_CACHE_DEFAULT_TTL_MS,n as ACTION_CACHE_TABLE,Z as DEFAULT_LIMIT,$ as DEFAULT_MAX_LIMIT,A as DOCUMENT_HISTORY_REDACTED_FIELDS,I as DOCUMENT_HISTORY_TABLE,M as LunoraEnvError,Ve as LunoraError,Ie as PRESENCE_DEFAULT_TTL_MS,_e as PRESENCE_TABLE,e as VERSION,Ge as ValidationError,i as actionCacheExtension,Qe as allowAll,$e as asBucketStorage,rr as assertShapesDeclareReadPolicies,u as beginDeferredDeletes,T as beginDeferredSchedules,F as bindOrm,O as bindTableFacade,ir as buildMaskRegistry,or as buildRlsReadRegistry,f as cacheKeyFor,ee as clampLimit,pe as composePluginMiddleware,tr as composeShapeReadWhere,ar as createPolicyDsl,l as createSecrets,He as createServices,je as cronJobs,a as defineActionCache,xe as defineAggregateIndex,ce as defineComponent,_ as defineDocumentHistory,P as defineEnv,Y as defineIdentity,J as defineIdentityGuard,re as defineListArgs,te as defineMigration,ie as defineModule,ae as defineMutator,sr as definePermission,le as definePlugin,dr as definePolicies,mr as definePolicy,Le as definePresence,Ee as defineRankIndex,pr as defineRole,Oe as defineRoom,ue as defineSchema,he as defineSchemaExtension,we as defineShape,cr as defineStorageRule,lr as defineStorageRules,Se as defineTable,De as defineVectorIndex,Xe as deny,L as documentHistoryExtension,h as flushDeferredDeletes,H as httpAction,N as httpRoute,w as httpRouter,Te as indexFieldsFromSchema,d as initLunora,ge as installPlugins,qe as isDeny,p as isPerDispatchMiddleware,U as isSafeHeaderValue,k as lastEventId,ur as mask,Re as mergeSchemaExtension,Q as onConnect,X as onDisconnect,ye as onQueryChange,q as onShardInit,ke as onWhisper,de as platformAdmin,Ce as presenceExtension,Pe as protectPublic,b as redactSecrets,Sr as rls,W as serveStorageObject,B as sseEvent,Tr as storageRules,x as tagPerDispatchMiddleware,ze as toWhereInput,Je as v,S as withDeferredDeletes,g as withDeferredSchedules};
1
+ import{ACTION_CACHE_DEFAULT_TTL_MS as t,ACTION_CACHE_TABLE as n,actionCacheExtension as i,cacheKeyFor as f,defineActionCache as a}from"./packem_shared/ACTION_CACHE_DEFAULT_TTL_MS-mmP-6BcT.mjs";import{initLunora as d}from"./packem_shared/initLunora-B-7Xs3Qq.mjs";import{isPerDispatchMiddleware as p,tagPerDispatchMiddleware as x}from"./packem_shared/isPerDispatchMiddleware-DDQPatSm.mjs";import{createSecrets as l}from"./packem_shared/createSecrets-D6rLB42U.mjs";import{beginDeferredDeletes as u,flushDeferredDeletes as S,withDeferredDeletes as h}from"./packem_shared/beginDeferredDeletes-DhwFBbvs.mjs";import{beginDeferredSchedules as T,withDeferredSchedules as g}from"./packem_shared/beginDeferredSchedules-C7QLYr6C.mjs";import{DOCUMENT_HISTORY_REDACTED_FIELDS as A,DOCUMENT_HISTORY_TABLE as I,defineDocumentHistory as L,documentHistoryExtension as _}from"./packem_shared/DOCUMENT_HISTORY_REDACTED_FIELDS-B5Zp-7SI.mjs";import{LunoraEnvError as M,defineEnv as P,redactSecrets as b}from"./packem_shared/LunoraEnvError-bkdMu_-N.mjs";import{bindOrm as F,bindTableFacade as O}from"./packem_shared/bindOrm-9fbLRbOb.mjs";import{httpAction as H,httpRoute as N,httpRouter as w,isSafeHeaderValue as U,lastEventId as k,sseEvent as B}from"./packem_shared/httpAction-D2S7bQzl.mjs";import{serveStorageObject as W}from"./packem_shared/serveStorageObject-aqBFrLyo.mjs";import{defineIdentity as Y}from"./packem_shared/defineIdentity-DwkNKwYa.mjs";import{default as J}from"./packem_shared/defineIdentityGuard-Bt8N65Zs.mjs";import{onConnect as Q,onDisconnect as X,onShardInit as q}from"./packem_shared/onConnect-BLRoOpv2.mjs";import{DEFAULT_LIMIT as Z,DEFAULT_MAX_LIMIT as $,clampLimit as ee,defineListArgs as re}from"./packem_shared/DEFAULT_LIMIT-pT_tV8R0.mjs";import{defineLiveStream as te}from"./packem_shared/defineLiveStream-BKomK5uG.mjs";import{defineMigration as ie}from"./packem_shared/defineMigration-CXOS0Bvq.mjs";import{defineModule as ae}from"./packem_shared/defineModule-OecXWM3U.mjs";import{defineMutator as de}from"./packem_shared/defineMutator-B4ipDtDR.mjs";import{platformAdmin as pe}from"./packem_shared/platformAdmin-kczXQme8.mjs";import{c as ce,d as le,a as Ee,b as ue,e as Se,f as he,g as De,h as Te,i as ge,j as Re,k as Ae,m as Ie}from"./packem_shared/plugin-Bm9wIpiI.mjs";import{PRESENCE_DEFAULT_TTL_MS as _e,PRESENCE_TABLE as Ce,definePresence as Me,presenceExtension as Pe}from"./packem_shared/PRESENCE_DEFAULT_TTL_MS-DFpy5J8G.mjs";import{protectPublic as ye}from"./packem_shared/protectPublic-Bi5_95aP.mjs";import{onQueryChange as Oe}from"./packem_shared/onQueryChange-iuLzmyPs.mjs";import{defineRoom as He}from"./packem_shared/defineRoom-CoGi-xwm.mjs";import{createServices as we}from"./packem_shared/createServices-IJvoqi0e.mjs";import{defineShape as ke}from"./packem_shared/defineShape-CwKm5KLp.mjs";import{onWhisper as Ve}from"./packem_shared/onWhisper-CfDbFLQh.mjs";import{LunoraError as je}from"@lunora/errors";import{cronJobs as Ge}from"@lunora/scheduler";import{ValidationError as Ke,v as Qe}from"@lunora/values";import{allowAll as qe,deny as ze,isDeny as Ze,toWhereInput as $e}from"./packem_shared/allowAll-DkRAgItV.mjs";import{asBucketStorage as rr}from"./packem_shared/asBucketStorage-DoGYOjq3.mjs";import{assertShapesDeclareReadPolicies as tr,buildRlsReadRegistry as nr,composeShapeReadWhere as ir}from"./packem_shared/assertShapesDeclareReadPolicies-Bg4Ter7Q.mjs";import{buildMaskRegistry as ar}from"./packem_shared/buildMaskRegistry-DpWMtalG.mjs";import{createPolicyDsl as dr,definePermission as mr,definePolicies as pr,definePolicy as xr,defineRole as cr}from"./packem_shared/createPolicyDsl-BZa6SqLJ.mjs";import{defineStorageRule as Er,defineStorageRules as ur}from"./packem_shared/defineStorageRule-Dv4nJE0H.mjs";import{mask as hr}from"./packem_shared/mask-D-jRCAhy.mjs";import{r as Tr}from"./packem_shared/middleware-3ySZVrpt.mjs";import{storageRules as Rr}from"./packem_shared/storageRules-CBLioxF7.mjs";const e="0.0.0";export{t as ACTION_CACHE_DEFAULT_TTL_MS,n as ACTION_CACHE_TABLE,Z as DEFAULT_LIMIT,$ as DEFAULT_MAX_LIMIT,A as DOCUMENT_HISTORY_REDACTED_FIELDS,I as DOCUMENT_HISTORY_TABLE,M as LunoraEnvError,je as LunoraError,_e as PRESENCE_DEFAULT_TTL_MS,Ce as PRESENCE_TABLE,e as VERSION,Ke as ValidationError,i as actionCacheExtension,qe as allowAll,rr as asBucketStorage,tr as assertShapesDeclareReadPolicies,u as beginDeferredDeletes,T as beginDeferredSchedules,F as bindOrm,O as bindTableFacade,ar as buildMaskRegistry,nr as buildRlsReadRegistry,f as cacheKeyFor,ee as clampLimit,ce as composePluginMiddleware,ir as composeShapeReadWhere,dr as createPolicyDsl,l as createSecrets,we as createServices,Ge as cronJobs,a as defineActionCache,le as defineAggregateIndex,Ee as defineComponent,L as defineDocumentHistory,P as defineEnv,Y as defineIdentity,J as defineIdentityGuard,re as defineListArgs,te as defineLiveStream,ie as defineMigration,ae as defineModule,de as defineMutator,mr as definePermission,ue as definePlugin,pr as definePolicies,xr as definePolicy,Me as definePresence,Se as defineRankIndex,cr as defineRole,He as defineRoom,he as defineSchema,De as defineSchemaExtension,ke as defineShape,Er as defineStorageRule,ur as defineStorageRules,Te as defineTable,ge as defineVectorIndex,ze as deny,_ as documentHistoryExtension,S as flushDeferredDeletes,H as httpAction,N as httpRoute,w as httpRouter,Re as indexFieldsFromSchema,d as initLunora,Ae as installPlugins,Ze as isDeny,p as isPerDispatchMiddleware,U as isSafeHeaderValue,k as lastEventId,hr as mask,Ie as mergeSchemaExtension,Q as onConnect,X as onDisconnect,Oe as onQueryChange,q as onShardInit,Ve as onWhisper,pe as platformAdmin,Pe as presenceExtension,ye as protectPublic,b as redactSecrets,Tr as rls,W as serveStorageObject,B as sseEvent,Rr as storageRules,x as tagPerDispatchMiddleware,$e as toWhereInput,Qe as v,h as withDeferredDeletes,g as withDeferredSchedules};
@@ -0,0 +1 @@
1
+ import{isLunoraError as m}from"@lunora/errors";import{httpAction as b}from"./httpAction-D2S7bQzl.mjs";const w="/_lunora/live/connect",S="/_lunora/live/control",E=async r=>{try{const e=await r.json();return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:void 0}catch{return}},h=r=>Response.json({code:"FORBIDDEN_TOPIC",error:`subscribe to "${r}" was denied`},{status:403}),u=r=>Response.json({code:"BAD_REQUEST",error:r},{status:400}),_=r=>{const e=`/live/${r.id}/connect`,l=`/live/${r.id}/control`,y=async(o,s)=>{if(!r.onSubscribe)return r.allowAnonymousControl===!0&&o.auth.userId===null;try{return await r.onSubscribe({ctx:o,topic:s})===!0}catch(t){return console.error("[lunora] live subscribe authorization threw; denying:",t),!1}},p=b(async(o,s)=>{const t=new URL(s.url).searchParams.get("shard")??void 0;return o.fetchShard(t,w,{method:"GET"})}),v=b(async(o,s)=>{const t=await E(s);if(!t)return u("Expected a JSON object body");const{action:c}=t,n=typeof t.topic=="string"?t.topic:void 0;if(n===void 0||n.length===0)return u("topic is required");if(c!=="subscribe"&&c!=="unsubscribe")return u("action must be subscribe or unsubscribe");const i=typeof t.shardKey=="string"?t.shardKey:void 0,f=i===void 0?o:{...o,...o.forShard(i)};if(c==="subscribe"&&!await y(f,n))return h(n);const d=o.fetchShard(i,S,{body:JSON.stringify({...t,stream:r.id}),method:"POST"});if(c!=="subscribe")return d;try{return await d}catch(a){if(m(a)&&a.code==="FORBIDDEN_SHARD")return h(n);throw a}});return{connect:p,connectPath:e,control:v,controlPath:l,id:r.id}};export{_ as defineLiveStream};
package/dist/types.d.mts CHANGED
@@ -2819,6 +2819,25 @@ interface ActionCtx {
2819
2819
  * host populates it and why every other one deliberately does not.
2820
2820
  */
2821
2821
  readonly ip?: string;
2822
+ /**
2823
+ * `ctx.live.publish(topic, payload, { stream })` — push an event to the SSE
2824
+ * subscribers of a `defineLiveStream` on THIS shard. Present on the shard
2825
+ * (Cloudflare) target only when the app declares a live stream; absent on a
2826
+ * target that rates `liveStreams` `unsupported`, where codegen reports why.
2827
+ * A scheduled job's action publishes this way too. Absent for a query or
2828
+ * mutation: a publish is a side effect, so only an action may make one.
2829
+ *
2830
+ * Delivery is local to the shard: an omitted `shardKey` means the shard the
2831
+ * action runs on, and a `shardKey` naming another shard rejects rather than
2832
+ * reaching zero subscribers silently. The docblock on `defineLiveStream` has the
2833
+ * full routing rules.
2834
+ */
2835
+ readonly live?: {
2836
+ publish: (topic: string, payload: unknown, options: {
2837
+ shardKey?: string;
2838
+ stream: string;
2839
+ }) => Promise<void>;
2840
+ };
2822
2841
  /** Structured, function-attributed logger; see {@link LunoraLogger}. */
2823
2842
  readonly log: LunoraLogger;
2824
2843
  /**
package/dist/types.d.ts CHANGED
@@ -2819,6 +2819,25 @@ interface ActionCtx {
2819
2819
  * host populates it and why every other one deliberately does not.
2820
2820
  */
2821
2821
  readonly ip?: string;
2822
+ /**
2823
+ * `ctx.live.publish(topic, payload, { stream })` — push an event to the SSE
2824
+ * subscribers of a `defineLiveStream` on THIS shard. Present on the shard
2825
+ * (Cloudflare) target only when the app declares a live stream; absent on a
2826
+ * target that rates `liveStreams` `unsupported`, where codegen reports why.
2827
+ * A scheduled job's action publishes this way too. Absent for a query or
2828
+ * mutation: a publish is a side effect, so only an action may make one.
2829
+ *
2830
+ * Delivery is local to the shard: an omitted `shardKey` means the shard the
2831
+ * action runs on, and a `shardKey` naming another shard rejects rather than
2832
+ * reaching zero subscribers silently. The docblock on `defineLiveStream` has the
2833
+ * full routing rules.
2834
+ */
2835
+ readonly live?: {
2836
+ publish: (topic: string, payload: unknown, options: {
2837
+ shardKey?: string;
2838
+ stream: string;
2839
+ }) => Promise<void>;
2840
+ };
2822
2841
  /** Structured, function-attributed logger; see {@link LunoraLogger}. */
2823
2842
  readonly log: LunoraLogger;
2824
2843
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/server",
3
- "version": "1.0.0-alpha.214",
3
+ "version": "1.0.0-alpha.215",
4
4
  "description": "Server primitives for Lunora: defineSchema, defineTable, query, mutation, and action",
5
5
  "keywords": [
6
6
  "backend",
@@ -71,9 +71,9 @@
71
71
  },
72
72
  "dependencies": {
73
73
  "@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
74
- "@lunora/scheduler": "1.0.0-alpha.134",
75
- "@lunora/shard-engine": "1.0.0-alpha.137",
76
- "@lunora/values": "1.0.0-alpha.69",
74
+ "@lunora/scheduler": "1.0.0-alpha.135",
75
+ "@lunora/shard-engine": "1.0.0-alpha.138",
76
+ "@lunora/values": "1.0.0-alpha.70",
77
77
  "@lunora/wire": "1.0.0-alpha.1",
78
78
  "drizzle-orm": "^0.45.3",
79
79
  "hono": "^4.13.13"