@lunora/server 1.0.0-alpha.70 → 1.0.0-alpha.71

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
@@ -1,6 +1,6 @@
1
1
  import { Validator, Infer, ValidatorMap, InferValidatorMap, ColumnValidator, v } from '@lunora/values';
2
2
  export { type ColumnValidator, type GeoPoint, type Id, type Infer, ValidationError, type Validator, type ValidatorKind, v } from '@lunora/values';
3
- import { ArgsValidator, InferArgs, RegisteredAction, ExposeConfig, X402ProcedureConfig, ActionCtx, MutationCtx, RegisteredMutation, QueryCtx, RegisteredQuery, RegisteredStream, FunctionKind, Secrets, LifecycleEvent, RegisteredLifecycleHook, TableDefinition, RegisteredFunction, VectorIndexDefinition, Schema, AggregateOp, DurableObjectJurisdiction, RelationDefinition, GlobalBackend, OnDeleteAction, SearchLanguage, SearchStrategy, ExternalSourceDefinition, TriggerBuilder, TriggerDefinition, VectorEmbedder, VectorMetric, AggregateIndexDefinition, RankIndexDefinition } from "./types.mjs";
3
+ import { ArgsValidator, InferArgs, RegisteredAction, ExposeConfig, X402ProcedureConfig, ActionCtx, MutationCtx, RegisteredMutation, QueryCtx, RegisteredQuery, DurableStreamOptions, RegisteredStream, FunctionKind, Secrets, LifecycleEvent, RegisteredLifecycleHook, TableDefinition, RegisteredFunction, VectorIndexDefinition, Schema, AggregateOp, DurableObjectJurisdiction, RelationDefinition, GlobalBackend, OnDeleteAction, SearchLanguage, SearchStrategy, ExternalSourceDefinition, TriggerBuilder, TriggerDefinition, VectorEmbedder, VectorMetric, AggregateIndexDefinition, RankIndexDefinition } from "./types.mjs";
4
4
  export { type AnyApi, type AuthState, type CachePurge, type DatabaseReader, type DatabaseWriter, type FunctionVisibility, type GeoBoundingBox, type GeoFilterBuilder, type GeoIndexDefinition, type GeoPointInput, type IndexDefinition, type IndexRangeBuilder, type LifecycleEventKind, type LogFields, type LunoraLogMethod, type LunoraLogger, type LunoraMetrics, type LunoraTracer, type LunoraWideEvent, type PaginationOptions, type PaginationResult, type RankSortKey, type ReadOnlyStorage, type RestCacheConfig, type ScheduledFunctionDoc, type ScheduledJob, type Scheduler, type SearchFilterBuilder, type SearchIndexDefinition, type ShardMode, type SpanEvaluation, type SpanHandle, type SpanKind, type SpanLink, type SpanOptions, type Storage, type StorageMetadata, type SystemDatabaseReader, type SystemDoc, type SystemQuery, type SystemTableName, type TableReader, type TableVectorIndex, type TriggerAggregateOptions, type TriggerCtx, type TriggerDatabase, type TriggerDeleteEvent, type TriggerEvent, type TriggerGroupByEntry, type TriggerGroupByOptions, type TriggerHandler, type TriggerInsertEvent, type TriggerOp, type TriggerQueryArgs, type TriggerQueryPage, type TriggerRankOptions, type TriggerRankPageOptions, type TriggerRankResult, type TriggerRow, type TriggerTiming, type TriggerUpdateEvent, type TtlDefinition, type VectorMatch, type VectorMatches, type VectorQueryInput, type VectorRecord, type VectorSearch, type VectorSearchReader, type VectorUpsertInput, type WorkflowCreateOptions, type WorkflowHandle, type WorkflowInstance, type WorkflowInstanceStatus, type WorkflowStatusResult, type Workflows, anyApi } from "./types.mjs";
5
5
  import { LunoraError as LunoraError$1, LunoraErrorCode } from '@lunora/errors';
6
6
  export type { LunoraErrorCode } from '@lunora/errors';
@@ -27,6 +27,13 @@ export { type CronJob, type CronJobsBuilder, type CronScheduleKind, type DailySc
27
27
  * so the signature is `unknown → unknown`; callers cast the result.
28
28
  */
29
29
  declare const asBucketStorage: (raw: unknown) => unknown;
30
+ /**
31
+ * Options for the `.stream()` terminal. `durable: true` is shorthand for
32
+ * `durable: {}` — the runtime only ever sees the object form.
33
+ */
34
+ interface StreamOptions {
35
+ durable?: boolean | DurableStreamOptions;
36
+ }
30
37
  /** Builder discriminator. Codegen reads this kind. */
31
38
  type TerminalKind = FunctionKind;
32
39
  /** Initial (empty) accumulated args for a fresh builder. */
@@ -98,12 +105,18 @@ interface QueryBuilder<Context, Args extends ArgsValidator, Output = undefined>
98
105
  * tripped when the client cancels — break out of the loop or check
99
106
  * `signal.aborted` between yields. `.output()` does not apply: per-chunk
100
107
  * validation is opt-in via the handler itself.
108
+ *
109
+ * Pass `{ durable: true }` to make the run outlive the socket that opened
110
+ * it: chunks are persisted as they are produced, so a reload resumes the
111
+ * same run from where it left off instead of dropping the work, and a
112
+ * second client with the same arguments attaches to the same transcript.
113
+ * That is what an LLM response wants; a progress ticker does not need it.
101
114
  */
102
115
  stream: <R>(handler: (options: {
103
116
  args: InferArgs<Args>;
104
117
  ctx: Context;
105
118
  signal: AbortSignal;
106
- }) => AsyncGenerator<R, void, void> | AsyncIterable<R>) => RegisteredStream<Args, R>;
119
+ }) => AsyncGenerator<R, void, void> | AsyncIterable<R>, options?: StreamOptions) => RegisteredStream<Args, R>;
107
120
  use: <ContextOut>(middleware: Middleware<Context, ContextOut>) => QueryBuilder<ContextOut, Args, Output>;
108
121
  /**
109
122
  * Mark this query as paid. The origin worker answers an unpaid client RPC
@@ -223,7 +236,7 @@ interface InternalQueryBuilder<Context, Args extends ArgsValidator, Output = und
223
236
  args: InferArgs<Args>;
224
237
  ctx: Context;
225
238
  signal: AbortSignal;
226
- }) => AsyncGenerator<R, void, void> | AsyncIterable<R>) => RegisteredStream<Args, R>;
239
+ }) => AsyncGenerator<R, void, void> | AsyncIterable<R>, options?: StreamOptions) => RegisteredStream<Args, R>;
227
240
  use: <ContextOut>(middleware: Middleware<Context, ContextOut>) => InternalQueryBuilder<ContextOut, Args, Output>;
228
241
  }
229
242
  interface InternalMutationBuilder<Context, Args extends ArgsValidator, Output = undefined> {
@@ -2625,4 +2638,4 @@ interface StorageContextIn {
2625
2638
  }
2626
2639
  declare const storageRules: <Context extends StorageContextIn = StorageContextIn>(rules: ReadonlyArray<StorageRule<Context>>, options?: StorageRulesOptions) => Middleware<Context, Context>;
2627
2640
  declare const VERSION = "0.0.0";
2628
- export { type ActionBuilder, type ActionCtx, type AggregateIndexDefinition, type AggregateIndexOptions, type AggregateOp, type ArgsValidator, type Component, type ComponentFunctions, type CreateOptions, DEFAULT_LIMIT, DEFAULT_MAX_LIMIT, type DataModelInit, type DefineComponentOptions, type DefineIdentityOptions, type DefineListArgsConfig, type DefinePluginOptions, type DefinePolicyInput, type DefinePresenceOptions, type DefineStorageRuleInput, type DurableObjectJurisdiction, 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 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, LunoraError, 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 MiddlewareNext, type MigrationCtx, type MigrationDefinition, type MigrationDocument, type MigrationReader, type MigrationTransform, 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 Plugin, type Policy, type PrefixedTables, type PresenceComponent, type PresenceFunctions, type PresenceMember, type ProtectPublicOptions, type QueryBuilder, type QueryCtx, type RankIndexDefinition, type RankIndexOptions, type RegisteredAction, type RegisteredFunction, type RegisteredLifecycleHook, type RegisteredMigration, type RegisteredMutation, type RegisteredMutator, type RegisteredQuery, type RegisteredShape, type RegisteredStream, type RelationBuilder, type RelationDefinition, type RlsOptions, type RlsReadRegistry, type Role, type Schema, type SchemaExtension, type ShapeDefinition, type ShapeReadWhereRequest, type StorageOperation, type StorageRule, type StorageRuleContext, type StorageRuleDecision, type StorageRulesOptions, 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, allowAll, asBucketStorage, bindOrm, bindTableFacade, buildMaskRegistry, buildRlsReadRegistry, clampLimit, composePluginMiddleware, composeShapeReadWhere, createPolicyDsl, createSecrets, defineAggregateIndex, defineComponent, defineEnv, defineIdentity, defineListArgs, defineMigration, defineMutator, definePermission, definePlugin, definePolicies, definePolicy, definePresence, defineRankIndex, defineRole, defineSchema, defineSchemaExtension, defineShape, defineStorageRule, defineStorageRules, defineTable, defineVectorIndex, deny, httpAction, httpRoute, httpRouter, indexFieldsFromSchema, initLunora, installPlugins, isDeny, isSafeHeaderValue, mask, mergeSchemaExtension, onConnect, onDisconnect, presenceExtension, protectPublic, redactSecrets, rls, serveStorageObject, storageRules, toWhereInput };
2641
+ export { type ActionBuilder, type ActionCtx, type AggregateIndexDefinition, type AggregateIndexOptions, type AggregateOp, type ArgsValidator, type Component, type ComponentFunctions, type CreateOptions, DEFAULT_LIMIT, DEFAULT_MAX_LIMIT, type DataModelInit, type DefineComponentOptions, type DefineIdentityOptions, type DefineListArgsConfig, type DefinePluginOptions, type DefinePolicyInput, type DefinePresenceOptions, type DefineStorageRuleInput, 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 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, LunoraError, 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 MiddlewareNext, type MigrationCtx, type MigrationDefinition, type MigrationDocument, type MigrationReader, type MigrationTransform, 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 Plugin, type Policy, type PrefixedTables, type PresenceComponent, type PresenceFunctions, type PresenceMember, type ProtectPublicOptions, type QueryBuilder, type QueryCtx, type RankIndexDefinition, type RankIndexOptions, type RegisteredAction, type RegisteredFunction, type RegisteredLifecycleHook, type RegisteredMigration, type RegisteredMutation, type RegisteredMutator, type RegisteredQuery, type RegisteredShape, type RegisteredStream, type RelationBuilder, type RelationDefinition, type RlsOptions, type RlsReadRegistry, type Role, type Schema, type SchemaExtension, type ShapeDefinition, type ShapeReadWhereRequest, type StorageOperation, type StorageRule, type StorageRuleContext, type StorageRuleDecision, type StorageRulesOptions, 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, allowAll, asBucketStorage, bindOrm, bindTableFacade, buildMaskRegistry, buildRlsReadRegistry, clampLimit, composePluginMiddleware, composeShapeReadWhere, createPolicyDsl, createSecrets, defineAggregateIndex, defineComponent, defineEnv, defineIdentity, defineListArgs, defineMigration, defineMutator, definePermission, definePlugin, definePolicies, definePolicy, definePresence, defineRankIndex, defineRole, defineSchema, defineSchemaExtension, defineShape, defineStorageRule, defineStorageRules, defineTable, defineVectorIndex, deny, httpAction, httpRoute, httpRouter, indexFieldsFromSchema, initLunora, installPlugins, isDeny, isSafeHeaderValue, mask, mergeSchemaExtension, onConnect, onDisconnect, presenceExtension, protectPublic, redactSecrets, rls, serveStorageObject, storageRules, toWhereInput };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Validator, Infer, ValidatorMap, InferValidatorMap, ColumnValidator, v } from '@lunora/values';
2
2
  export { type ColumnValidator, type GeoPoint, type Id, type Infer, ValidationError, type Validator, type ValidatorKind, v } from '@lunora/values';
3
- import { ArgsValidator, InferArgs, RegisteredAction, ExposeConfig, X402ProcedureConfig, ActionCtx, MutationCtx, RegisteredMutation, QueryCtx, RegisteredQuery, RegisteredStream, FunctionKind, Secrets, LifecycleEvent, RegisteredLifecycleHook, TableDefinition, RegisteredFunction, VectorIndexDefinition, Schema, AggregateOp, DurableObjectJurisdiction, RelationDefinition, GlobalBackend, OnDeleteAction, SearchLanguage, SearchStrategy, ExternalSourceDefinition, TriggerBuilder, TriggerDefinition, VectorEmbedder, VectorMetric, AggregateIndexDefinition, RankIndexDefinition } from "./types.js";
3
+ import { ArgsValidator, InferArgs, RegisteredAction, ExposeConfig, X402ProcedureConfig, ActionCtx, MutationCtx, RegisteredMutation, QueryCtx, RegisteredQuery, DurableStreamOptions, RegisteredStream, FunctionKind, Secrets, LifecycleEvent, RegisteredLifecycleHook, TableDefinition, RegisteredFunction, VectorIndexDefinition, Schema, AggregateOp, DurableObjectJurisdiction, RelationDefinition, GlobalBackend, OnDeleteAction, SearchLanguage, SearchStrategy, ExternalSourceDefinition, TriggerBuilder, TriggerDefinition, VectorEmbedder, VectorMetric, AggregateIndexDefinition, RankIndexDefinition } from "./types.js";
4
4
  export { type AnyApi, type AuthState, type CachePurge, type DatabaseReader, type DatabaseWriter, type FunctionVisibility, type GeoBoundingBox, type GeoFilterBuilder, type GeoIndexDefinition, type GeoPointInput, type IndexDefinition, type IndexRangeBuilder, type LifecycleEventKind, type LogFields, type LunoraLogMethod, type LunoraLogger, type LunoraMetrics, type LunoraTracer, type LunoraWideEvent, type PaginationOptions, type PaginationResult, type RankSortKey, type ReadOnlyStorage, type RestCacheConfig, type ScheduledFunctionDoc, type ScheduledJob, type Scheduler, type SearchFilterBuilder, type SearchIndexDefinition, type ShardMode, type SpanEvaluation, type SpanHandle, type SpanKind, type SpanLink, type SpanOptions, type Storage, type StorageMetadata, type SystemDatabaseReader, type SystemDoc, type SystemQuery, type SystemTableName, type TableReader, type TableVectorIndex, type TriggerAggregateOptions, type TriggerCtx, type TriggerDatabase, type TriggerDeleteEvent, type TriggerEvent, type TriggerGroupByEntry, type TriggerGroupByOptions, type TriggerHandler, type TriggerInsertEvent, type TriggerOp, type TriggerQueryArgs, type TriggerQueryPage, type TriggerRankOptions, type TriggerRankPageOptions, type TriggerRankResult, type TriggerRow, type TriggerTiming, type TriggerUpdateEvent, type TtlDefinition, type VectorMatch, type VectorMatches, type VectorQueryInput, type VectorRecord, type VectorSearch, type VectorSearchReader, type VectorUpsertInput, type WorkflowCreateOptions, type WorkflowHandle, type WorkflowInstance, type WorkflowInstanceStatus, type WorkflowStatusResult, type Workflows, anyApi } from "./types.js";
5
5
  import { LunoraError as LunoraError$1, LunoraErrorCode } from '@lunora/errors';
6
6
  export type { LunoraErrorCode } from '@lunora/errors';
@@ -27,6 +27,13 @@ export { type CronJob, type CronJobsBuilder, type CronScheduleKind, type DailySc
27
27
  * so the signature is `unknown → unknown`; callers cast the result.
28
28
  */
29
29
  declare const asBucketStorage: (raw: unknown) => unknown;
30
+ /**
31
+ * Options for the `.stream()` terminal. `durable: true` is shorthand for
32
+ * `durable: {}` — the runtime only ever sees the object form.
33
+ */
34
+ interface StreamOptions {
35
+ durable?: boolean | DurableStreamOptions;
36
+ }
30
37
  /** Builder discriminator. Codegen reads this kind. */
31
38
  type TerminalKind = FunctionKind;
32
39
  /** Initial (empty) accumulated args for a fresh builder. */
@@ -98,12 +105,18 @@ interface QueryBuilder<Context, Args extends ArgsValidator, Output = undefined>
98
105
  * tripped when the client cancels — break out of the loop or check
99
106
  * `signal.aborted` between yields. `.output()` does not apply: per-chunk
100
107
  * validation is opt-in via the handler itself.
108
+ *
109
+ * Pass `{ durable: true }` to make the run outlive the socket that opened
110
+ * it: chunks are persisted as they are produced, so a reload resumes the
111
+ * same run from where it left off instead of dropping the work, and a
112
+ * second client with the same arguments attaches to the same transcript.
113
+ * That is what an LLM response wants; a progress ticker does not need it.
101
114
  */
102
115
  stream: <R>(handler: (options: {
103
116
  args: InferArgs<Args>;
104
117
  ctx: Context;
105
118
  signal: AbortSignal;
106
- }) => AsyncGenerator<R, void, void> | AsyncIterable<R>) => RegisteredStream<Args, R>;
119
+ }) => AsyncGenerator<R, void, void> | AsyncIterable<R>, options?: StreamOptions) => RegisteredStream<Args, R>;
107
120
  use: <ContextOut>(middleware: Middleware<Context, ContextOut>) => QueryBuilder<ContextOut, Args, Output>;
108
121
  /**
109
122
  * Mark this query as paid. The origin worker answers an unpaid client RPC
@@ -223,7 +236,7 @@ interface InternalQueryBuilder<Context, Args extends ArgsValidator, Output = und
223
236
  args: InferArgs<Args>;
224
237
  ctx: Context;
225
238
  signal: AbortSignal;
226
- }) => AsyncGenerator<R, void, void> | AsyncIterable<R>) => RegisteredStream<Args, R>;
239
+ }) => AsyncGenerator<R, void, void> | AsyncIterable<R>, options?: StreamOptions) => RegisteredStream<Args, R>;
227
240
  use: <ContextOut>(middleware: Middleware<Context, ContextOut>) => InternalQueryBuilder<ContextOut, Args, Output>;
228
241
  }
229
242
  interface InternalMutationBuilder<Context, Args extends ArgsValidator, Output = undefined> {
@@ -2625,4 +2638,4 @@ interface StorageContextIn {
2625
2638
  }
2626
2639
  declare const storageRules: <Context extends StorageContextIn = StorageContextIn>(rules: ReadonlyArray<StorageRule<Context>>, options?: StorageRulesOptions) => Middleware<Context, Context>;
2627
2640
  declare const VERSION = "0.0.0";
2628
- export { type ActionBuilder, type ActionCtx, type AggregateIndexDefinition, type AggregateIndexOptions, type AggregateOp, type ArgsValidator, type Component, type ComponentFunctions, type CreateOptions, DEFAULT_LIMIT, DEFAULT_MAX_LIMIT, type DataModelInit, type DefineComponentOptions, type DefineIdentityOptions, type DefineListArgsConfig, type DefinePluginOptions, type DefinePolicyInput, type DefinePresenceOptions, type DefineStorageRuleInput, type DurableObjectJurisdiction, 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 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, LunoraError, 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 MiddlewareNext, type MigrationCtx, type MigrationDefinition, type MigrationDocument, type MigrationReader, type MigrationTransform, 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 Plugin, type Policy, type PrefixedTables, type PresenceComponent, type PresenceFunctions, type PresenceMember, type ProtectPublicOptions, type QueryBuilder, type QueryCtx, type RankIndexDefinition, type RankIndexOptions, type RegisteredAction, type RegisteredFunction, type RegisteredLifecycleHook, type RegisteredMigration, type RegisteredMutation, type RegisteredMutator, type RegisteredQuery, type RegisteredShape, type RegisteredStream, type RelationBuilder, type RelationDefinition, type RlsOptions, type RlsReadRegistry, type Role, type Schema, type SchemaExtension, type ShapeDefinition, type ShapeReadWhereRequest, type StorageOperation, type StorageRule, type StorageRuleContext, type StorageRuleDecision, type StorageRulesOptions, 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, allowAll, asBucketStorage, bindOrm, bindTableFacade, buildMaskRegistry, buildRlsReadRegistry, clampLimit, composePluginMiddleware, composeShapeReadWhere, createPolicyDsl, createSecrets, defineAggregateIndex, defineComponent, defineEnv, defineIdentity, defineListArgs, defineMigration, defineMutator, definePermission, definePlugin, definePolicies, definePolicy, definePresence, defineRankIndex, defineRole, defineSchema, defineSchemaExtension, defineShape, defineStorageRule, defineStorageRules, defineTable, defineVectorIndex, deny, httpAction, httpRoute, httpRouter, indexFieldsFromSchema, initLunora, installPlugins, isDeny, isSafeHeaderValue, mask, mergeSchemaExtension, onConnect, onDisconnect, presenceExtension, protectPublic, redactSecrets, rls, serveStorageObject, storageRules, toWhereInput };
2641
+ export { type ActionBuilder, type ActionCtx, type AggregateIndexDefinition, type AggregateIndexOptions, type AggregateOp, type ArgsValidator, type Component, type ComponentFunctions, type CreateOptions, DEFAULT_LIMIT, DEFAULT_MAX_LIMIT, type DataModelInit, type DefineComponentOptions, type DefineIdentityOptions, type DefineListArgsConfig, type DefinePluginOptions, type DefinePolicyInput, type DefinePresenceOptions, type DefineStorageRuleInput, 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 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, LunoraError, 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 MiddlewareNext, type MigrationCtx, type MigrationDefinition, type MigrationDocument, type MigrationReader, type MigrationTransform, 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 Plugin, type Policy, type PrefixedTables, type PresenceComponent, type PresenceFunctions, type PresenceMember, type ProtectPublicOptions, type QueryBuilder, type QueryCtx, type RankIndexDefinition, type RankIndexOptions, type RegisteredAction, type RegisteredFunction, type RegisteredLifecycleHook, type RegisteredMigration, type RegisteredMutation, type RegisteredMutator, type RegisteredQuery, type RegisteredShape, type RegisteredStream, type RelationBuilder, type RelationDefinition, type RlsOptions, type RlsReadRegistry, type Role, type Schema, type SchemaExtension, type ShapeDefinition, type ShapeReadWhereRequest, type StorageOperation, type StorageRule, type StorageRuleContext, type StorageRuleDecision, type StorageRulesOptions, 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, allowAll, asBucketStorage, bindOrm, bindTableFacade, buildMaskRegistry, buildRlsReadRegistry, clampLimit, composePluginMiddleware, composeShapeReadWhere, createPolicyDsl, createSecrets, defineAggregateIndex, defineComponent, defineEnv, defineIdentity, defineListArgs, defineMigration, defineMutator, definePermission, definePlugin, definePolicies, definePolicy, definePresence, defineRankIndex, defineRole, defineSchema, defineSchemaExtension, defineShape, defineStorageRule, defineStorageRules, defineTable, defineVectorIndex, deny, httpAction, httpRoute, httpRouter, indexFieldsFromSchema, initLunora, installPlugins, isDeny, isSafeHeaderValue, mask, mergeSchemaExtension, onConnect, onDisconnect, presenceExtension, protectPublic, redactSecrets, rls, serveStorageObject, storageRules, toWhereInput };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{initLunora as t}from"./packem_shared/initLunora-BadfSfpJ.mjs";import{createSecrets as i}from"./packem_shared/createSecrets-CgVPiW2C.mjs";import{LunoraEnvError as f,defineEnv as s,redactSecrets as m}from"./packem_shared/LunoraEnvError-CgpI2Mm_.mjs";import{LunoraError as p}from"./packem_shared/LunoraError-LVhdU0Lo.mjs";import{bindOrm as c,bindTableFacade as l}from"./packem_shared/bindOrm-Bp9hsM2q.mjs";import{httpAction as u,httpRoute as S,httpRouter as g,isSafeHeaderValue as R,serveStorageObject as L}from"./packem_shared/httpAction-BpEJYwzV.mjs";import{defineIdentity as P}from"./packem_shared/defineIdentity-B7gfAgxx.mjs";import{onConnect as A,onDisconnect as I}from"./packem_shared/onConnect-CEtRmUpJ.mjs";import{DEFAULT_LIMIT as y,DEFAULT_MAX_LIMIT as M,clampLimit as _,defineListArgs as D}from"./packem_shared/DEFAULT_LIMIT-yHJ5O96W.mjs";import{defineMigration as k}from"./packem_shared/defineMigration-Bfpwxv2f.mjs";import{defineMutator as C}from"./packem_shared/defineMutator-BgpQ-xUo.mjs";import{c as N,H as O,d as U,a as W,X as w,Z as B,b as H,q as X,K as j,W as q,i as J,m as K}from"./packem_shared/plugin-184MITA3.mjs";import{PRESENCE_DEFAULT_TTL_MS as z,PRESENCE_TABLE as G,definePresence as Q,presenceExtension as Y}from"./packem_shared/PRESENCE_DEFAULT_TTL_MS-Dyb1szd2.mjs";import{protectPublic as ee}from"./packem_shared/protectPublic-BhKewPqm.mjs";import{defineShape as oe}from"./packem_shared/defineShape-Ds8uNqzX.mjs";import{anyApi as ne}from"./types.mjs";import{cronJobs as ae}from"@lunora/scheduler";import{ValidationError as se,v as me}from"@lunora/values";import{allowAll as pe,deny as xe,isDeny as ce,toWhereInput as le}from"./packem_shared/allowAll-BnyNbJZT.mjs";import{asBucketStorage as ue}from"./packem_shared/asBucketStorage-BthCnWop.mjs";import{buildMaskRegistry as ge}from"./packem_shared/buildMaskRegistry-BCIzKxdK.mjs";import{buildRlsReadRegistry as Le,composeShapeReadWhere as he}from"./packem_shared/buildRlsReadRegistry-CE5k6akj.mjs";import{createPolicyDsl as be,definePermission as Ae,definePolicies as Ie,definePolicy as Te,defineRole as ye}from"./packem_shared/createPolicyDsl-sV1swpkD.mjs";import{defineStorageRule as _e,defineStorageRules as De}from"./packem_shared/defineStorageRule-BDu01PUn.mjs";import{mask as ke}from"./packem_shared/mask-CD7SWEvR.mjs";import{c as Ce}from"./packem_shared/middleware-D9_39C5C.mjs";import{storageRules as Ne}from"./packem_shared/storageRules-6_G8JpCv.mjs";const e="0.0.0";export{y as DEFAULT_LIMIT,M as DEFAULT_MAX_LIMIT,f as LunoraEnvError,p as LunoraError,z as PRESENCE_DEFAULT_TTL_MS,G as PRESENCE_TABLE,e as VERSION,se as ValidationError,pe as allowAll,ne as anyApi,ue as asBucketStorage,c as bindOrm,l as bindTableFacade,ge as buildMaskRegistry,Le as buildRlsReadRegistry,_ as clampLimit,N as composePluginMiddleware,he as composeShapeReadWhere,be as createPolicyDsl,i as createSecrets,ae as cronJobs,O as defineAggregateIndex,U as defineComponent,s as defineEnv,P as defineIdentity,D as defineListArgs,k as defineMigration,C as defineMutator,Ae as definePermission,W as definePlugin,Ie as definePolicies,Te as definePolicy,Q as definePresence,w as defineRankIndex,ye as defineRole,B as defineSchema,H as defineSchemaExtension,oe as defineShape,_e as defineStorageRule,De as defineStorageRules,X as defineTable,j as defineVectorIndex,xe as deny,u as httpAction,S as httpRoute,g as httpRouter,q as indexFieldsFromSchema,t as initLunora,J as installPlugins,ce as isDeny,R as isSafeHeaderValue,ke as mask,K as mergeSchemaExtension,A as onConnect,I as onDisconnect,Y as presenceExtension,ee as protectPublic,m as redactSecrets,Ce as rls,L as serveStorageObject,Ne as storageRules,le as toWhereInput,me as v};
1
+ import{initLunora as t}from"./packem_shared/initLunora-BilEHyNs.mjs";import{createSecrets as i}from"./packem_shared/createSecrets-CgVPiW2C.mjs";import{LunoraEnvError as f,defineEnv as s,redactSecrets as m}from"./packem_shared/LunoraEnvError-CgpI2Mm_.mjs";import{LunoraError as p}from"./packem_shared/LunoraError-LVhdU0Lo.mjs";import{bindOrm as c,bindTableFacade as l}from"./packem_shared/bindOrm-Bp9hsM2q.mjs";import{httpAction as u,httpRoute as S,httpRouter as g,isSafeHeaderValue as R,serveStorageObject as L}from"./packem_shared/httpAction-BpEJYwzV.mjs";import{defineIdentity as P}from"./packem_shared/defineIdentity-B7gfAgxx.mjs";import{onConnect as A,onDisconnect as I}from"./packem_shared/onConnect-CEtRmUpJ.mjs";import{DEFAULT_LIMIT as y,DEFAULT_MAX_LIMIT as M,clampLimit as _,defineListArgs as D}from"./packem_shared/DEFAULT_LIMIT-yHJ5O96W.mjs";import{defineMigration as k}from"./packem_shared/defineMigration-Bfpwxv2f.mjs";import{defineMutator as C}from"./packem_shared/defineMutator-BgpQ-xUo.mjs";import{c as N,H as O,d as U,a as W,X as w,Z as B,b as H,q as X,K as j,W as q,i as J,m as K}from"./packem_shared/plugin-184MITA3.mjs";import{PRESENCE_DEFAULT_TTL_MS as z,PRESENCE_TABLE as G,definePresence as Q,presenceExtension as Y}from"./packem_shared/PRESENCE_DEFAULT_TTL_MS-C24x2Cox.mjs";import{protectPublic as ee}from"./packem_shared/protectPublic-BhKewPqm.mjs";import{defineShape as oe}from"./packem_shared/defineShape-Ds8uNqzX.mjs";import{anyApi as ne}from"./types.mjs";import{cronJobs as ae}from"@lunora/scheduler";import{ValidationError as se,v as me}from"@lunora/values";import{allowAll as pe,deny as xe,isDeny as ce,toWhereInput as le}from"./packem_shared/allowAll-BnyNbJZT.mjs";import{asBucketStorage as ue}from"./packem_shared/asBucketStorage-BthCnWop.mjs";import{buildMaskRegistry as ge}from"./packem_shared/buildMaskRegistry-BCIzKxdK.mjs";import{buildRlsReadRegistry as Le,composeShapeReadWhere as he}from"./packem_shared/buildRlsReadRegistry-CE5k6akj.mjs";import{createPolicyDsl as be,definePermission as Ae,definePolicies as Ie,definePolicy as Te,defineRole as ye}from"./packem_shared/createPolicyDsl-sV1swpkD.mjs";import{defineStorageRule as _e,defineStorageRules as De}from"./packem_shared/defineStorageRule-BDu01PUn.mjs";import{mask as ke}from"./packem_shared/mask-CD7SWEvR.mjs";import{c as Ce}from"./packem_shared/middleware-D9_39C5C.mjs";import{storageRules as Ne}from"./packem_shared/storageRules-6_G8JpCv.mjs";const e="0.0.0";export{y as DEFAULT_LIMIT,M as DEFAULT_MAX_LIMIT,f as LunoraEnvError,p as LunoraError,z as PRESENCE_DEFAULT_TTL_MS,G as PRESENCE_TABLE,e as VERSION,se as ValidationError,pe as allowAll,ne as anyApi,ue as asBucketStorage,c as bindOrm,l as bindTableFacade,ge as buildMaskRegistry,Le as buildRlsReadRegistry,_ as clampLimit,N as composePluginMiddleware,he as composeShapeReadWhere,be as createPolicyDsl,i as createSecrets,ae as cronJobs,O as defineAggregateIndex,U as defineComponent,s as defineEnv,P as defineIdentity,D as defineListArgs,k as defineMigration,C as defineMutator,Ae as definePermission,W as definePlugin,Ie as definePolicies,Te as definePolicy,Q as definePresence,w as defineRankIndex,ye as defineRole,B as defineSchema,H as defineSchemaExtension,oe as defineShape,_e as defineStorageRule,De as defineStorageRules,X as defineTable,j as defineVectorIndex,xe as deny,u as httpAction,S as httpRoute,g as httpRouter,q as indexFieldsFromSchema,t as initLunora,J as installPlugins,ce as isDeny,R as isSafeHeaderValue,ke as mask,K as mergeSchemaExtension,A as onConnect,I as onDisconnect,Y as presenceExtension,ee as protectPublic,m as redactSecrets,Ce as rls,L as serveStorageObject,Ne as storageRules,le as toWhereInput,me as v};
@@ -1 +1 @@
1
- import{v as t}from"@lunora/values";import{initLunora as E}from"./initLunora-BadfSfpJ.mjs";import{LunoraError as p}from"./LunoraError-LVhdU0Lo.mjs";import{onDisconnect as q}from"./onConnect-CEtRmUpJ.mjs";import{b as v,q as R,d as _}from"./plugin-184MITA3.mjs";const D=3e4,y=4096,u="presence",h="present",c=`${u}_${h}`,M=v(u,{tables:{[h]:R({data:t.optional(t.record(t.string(),t.any())),lastSeen:t.number(),roomId:t.string(),sessionId:t.string(),userId:t.optional(t.string())}).index("byRoomSession",["roomId","sessionId"]).index("byRoom",["roomId"])}}),{mutation:b,query:L}=E.dataModel().create(),B=(l={})=>{const m=l.ttlMs??D,f=Math.max(0,Math.min(l.disconnectGraceMs??0,m)),w=b.input({data:t.optional(t.record(t.string(),t.any())),roomId:t.string(),sessionId:t.string()}).mutation(async({args:o,ctx:s})=>{const r=Date.now(),i=s.auth.userId??void 0;if(o.data!==void 0&&new TextEncoder().encode(JSON.stringify(o.data)).length>y)throw new p("BAD_REQUEST",`presence data exceeds the ${String(y)}-byte limit`);const e=await s.db.query(c).withIndex("byRoomSession",n=>n.eq("roomId",o.roomId).eq("sessionId",o.sessionId)).first();if(e&&(e.userId??void 0)!==i)throw new p("FORBIDDEN","presence heartbeat denied: this (roomId, sessionId) is held by another identity");const a={lastSeen:r,roomId:o.roomId,sessionId:o.sessionId,...o.data===void 0?{}:{data:o.data},...i===void 0?{}:{userId:i}};return await(e?s.db.patch(e._id,a):s.db.insert(c,a)),{lastSeen:r}}),S=L.input({roomId:t.string()}).query(async({args:o,ctx:s})=>{const r=Date.now()-m,i=(await s.db.query(c).withIndex("byRoom",n=>n.eq("roomId",o.roomId)).collect()).filter(n=>n.lastSeen>r).toSorted((n,d)=>d.lastSeen-n.lastSeen),e=new Set,a=[];for(const n of i){const d=n.userId;if(d!==void 0){if(e.has(d))continue;e.add(d)}const I={lastSeen:n.lastSeen,roomId:n.roomId};d!==void 0&&(I.userId=d),n.data!==void 0&&(I.data=n.data),a.push(I)}return a}),g={...b.input({roomId:t.string()}).mutation(async({args:o,ctx:s})=>{const r=Date.now()-m,i=await s.db.query(c).withIndex("byRoom",e=>e.eq("roomId",o.roomId)).filter(e=>e.lastSeen<=r).collect();return await Promise.all(i.map(e=>s.db.delete(e._id))),{deleted:i.length}}),visibility:"internal"},x=q(async(o,s)=>{const r=s.context?.roomId,i=s.context?.sessionId;if(typeof r!="string"||typeof i!="string")return;const e=await o.db.query(c).withIndex("byRoomSession",d=>d.eq("roomId",r).eq("sessionId",i)).first();if(!e)return;const a=s.userId??void 0;if((e.userId??void 0)!==a)return;if(f===0){await o.db.delete(e._id);return}const n=Math.min(e.lastSeen,Date.now()+f-m);await o.db.patch(e._id,{lastSeen:n})});return _(u,{extension:M,functions:{disconnect:x,heartbeat:w,listPresent:S,sweep:g}})};export{D as PRESENCE_DEFAULT_TTL_MS,c as PRESENCE_TABLE,B as definePresence,M as presenceExtension};
1
+ import{v as t}from"@lunora/values";import{initLunora as E}from"./initLunora-BilEHyNs.mjs";import{LunoraError as p}from"./LunoraError-LVhdU0Lo.mjs";import{onDisconnect as q}from"./onConnect-CEtRmUpJ.mjs";import{b as v,q as R,d as _}from"./plugin-184MITA3.mjs";const D=3e4,y=4096,u="presence",h="present",c=`${u}_${h}`,M=v(u,{tables:{[h]:R({data:t.optional(t.record(t.string(),t.any())),lastSeen:t.number(),roomId:t.string(),sessionId:t.string(),userId:t.optional(t.string())}).index("byRoomSession",["roomId","sessionId"]).index("byRoom",["roomId"])}}),{mutation:b,query:L}=E.dataModel().create(),B=(l={})=>{const m=l.ttlMs??D,f=Math.max(0,Math.min(l.disconnectGraceMs??0,m)),w=b.input({data:t.optional(t.record(t.string(),t.any())),roomId:t.string(),sessionId:t.string()}).mutation(async({args:o,ctx:s})=>{const r=Date.now(),i=s.auth.userId??void 0;if(o.data!==void 0&&new TextEncoder().encode(JSON.stringify(o.data)).length>y)throw new p("BAD_REQUEST",`presence data exceeds the ${String(y)}-byte limit`);const e=await s.db.query(c).withIndex("byRoomSession",n=>n.eq("roomId",o.roomId).eq("sessionId",o.sessionId)).first();if(e&&(e.userId??void 0)!==i)throw new p("FORBIDDEN","presence heartbeat denied: this (roomId, sessionId) is held by another identity");const a={lastSeen:r,roomId:o.roomId,sessionId:o.sessionId,...o.data===void 0?{}:{data:o.data},...i===void 0?{}:{userId:i}};return await(e?s.db.patch(e._id,a):s.db.insert(c,a)),{lastSeen:r}}),S=L.input({roomId:t.string()}).query(async({args:o,ctx:s})=>{const r=Date.now()-m,i=(await s.db.query(c).withIndex("byRoom",n=>n.eq("roomId",o.roomId)).collect()).filter(n=>n.lastSeen>r).toSorted((n,d)=>d.lastSeen-n.lastSeen),e=new Set,a=[];for(const n of i){const d=n.userId;if(d!==void 0){if(e.has(d))continue;e.add(d)}const I={lastSeen:n.lastSeen,roomId:n.roomId};d!==void 0&&(I.userId=d),n.data!==void 0&&(I.data=n.data),a.push(I)}return a}),g={...b.input({roomId:t.string()}).mutation(async({args:o,ctx:s})=>{const r=Date.now()-m,i=await s.db.query(c).withIndex("byRoom",e=>e.eq("roomId",o.roomId)).filter(e=>e.lastSeen<=r).collect();return await Promise.all(i.map(e=>s.db.delete(e._id))),{deleted:i.length}}),visibility:"internal"},x=q(async(o,s)=>{const r=s.context?.roomId,i=s.context?.sessionId;if(typeof r!="string"||typeof i!="string")return;const e=await o.db.query(c).withIndex("byRoomSession",d=>d.eq("roomId",r).eq("sessionId",i)).first();if(!e)return;const a=s.userId??void 0;if((e.userId??void 0)!==a)return;if(f===0){await o.db.delete(e._id);return}const n=Math.min(e.lastSeen,Date.now()+f-m);await o.db.patch(e._id,{lastSeen:n})});return _(u,{extension:M,functions:{disconnect:x,heartbeat:w,listPresent:S,sweep:g}})};export{D as PRESENCE_DEFAULT_TTL_MS,c as PRESENCE_TABLE,B as definePresence,M as presenceExtension};
@@ -0,0 +1 @@
1
+ import{s as g}from"./functions-CDC08CWY.mjs";import{readMaskTag as w}from"./buildMaskRegistry-BCIzKxdK.mjs";import{l as x}from"./policy-tag-Dprt9JWo.mjs";import{l as f}from"./run-middleware-BeEEqmdE.mjs";const y=(a,e)=>e===void 0||typeof a!="object"||a===null?a:Object.assign(Object.create(Object.getPrototypeOf(a)),a,{meta:e}),p=(a,e)=>f(a,e,t=>t),b=(a,e,t,r,i)=>async(s,d)=>{const l=g(a,d),u=await p(e,y(s,i)),m=await t({args:l,ctx:u});return r?r.parse(m):m},v=(a,e,t)=>(r,i,s)=>{const d=g(a,i);return(async function*(){const l=await p(e,r),u=t({args:d,ctx:l,signal:s})[Symbol.asyncIterator]();try{for(;;){if(s.aborted)return;const m=await u.next();if(m.done||s.aborted)return;yield m.value}}finally{await u.return?.()}})()},n=a=>{const e=a.map(t=>x(t)).filter(t=>t!==void 0);return e.length>0?{tags:e}:void 0},c=a=>{const e=new Map;for(const t of a){const r=w(t);if(r)for(const[i,s]of r.columns){const d=e.get(i)??new Set;for(const l of s)d.add(l);e.set(i,d)}}return e.size>0?e:void 0},o=(a,e,t)=>({__lunoraProcedure:a,...t?{__lunoraVisibility:t}:{},input:r=>o(a,{...e,args:{...e.args,...r}},t),[a]:r=>{const i=n(e.middlewares),s=c(e.middlewares);return{args:e.args,...e.expose?{expose:e.expose}:{},handler:b(e.args,e.middlewares,r,e.output,e.meta),kind:a,...s?{maskedTables:s}:{},...e.meta?{meta:e.meta}:{},...i?{rls:i}:{},...t?{visibility:t}:{},...e.x402?{x402:e.x402}:{}}},meta:r=>o(a,{...e,meta:{...e.meta,...r}},t),output:r=>o(a,{...e,output:r},t),...a==="query"?{stream:(r,i)=>{const s=n(e.middlewares),d=c(e.middlewares),l=i?.durable===!0?{}:i?.durable;return{args:e.args,...l?{durable:l}:{},...e.expose?{expose:e.expose}:{},handler:v(e.args,e.middlewares,r),kind:"stream",...d?{maskedTables:d}:{},...s?{rls:s}:{},...t?{visibility:t}:{},...e.x402?{x402:e.x402}:{}}}}:{},use:r=>o(a,{...e,middlewares:[...e.middlewares,r]},t),...t?{}:{expose:r=>o(a,{...e,expose:r},t)},...t?{}:{x402:r=>o(a,{...e,x402:r},t)}}),O={dataModel:()=>({create:a=>({action:o("action",{args:{},middlewares:[]}),internalAction:o("action",{args:{},middlewares:[]},"internal"),internalMutation:o("mutation",{args:{},middlewares:[]},"internal"),internalQuery:o("query",{args:{},middlewares:[]},"internal"),mutation:o("mutation",{args:{},middlewares:[]}),query:o("query",{args:{},middlewares:[]})})})};export{O as initLunora};
package/dist/types.d.mts CHANGED
@@ -646,10 +646,46 @@ type RegisteredLifecycleHook = RegisteredFunction<Record<string, never>, void, "
646
646
  */
647
647
  interface RegisteredStream<A extends ArgsValidator, R> {
648
648
  readonly args: A;
649
+ /**
650
+ * Present when the stream was declared `durable`. Chunks are persisted per
651
+ * run before they reach a socket, the producer outlives the socket that
652
+ * opened it, and a reconnecting (or second) client attaches to the same run
653
+ * and replays what it missed. See {@link DurableStreamOptions}.
654
+ */
655
+ readonly durable?: DurableStreamOptions;
649
656
  readonly handler: (context: unknown, args: InferArgs<A>, signal: AbortSignal) => AsyncIterable<R>;
650
657
  readonly kind: "stream";
651
658
  readonly visibility?: FunctionVisibility;
652
659
  }
660
+ /**
661
+ * Durability settings for a `.stream()` procedure.
662
+ *
663
+ * A run is identified by the socket's verified identity plus the function path
664
+ * and arguments, so two clients of the SAME user calling the same stream with
665
+ * the same arguments observe one producer and one transcript. That identity is
666
+ * the feature: it is what makes a reload resume rather than re-generate, and
667
+ * what lets a second tab watch the same answer. A different identity always gets
668
+ * its own run.
669
+ *
670
+ * Sharing applies to a run still in flight. Once a run finishes, a later caller
671
+ * asking the same question gets a fresh one — a transcript is the record of one
672
+ * execution, not a cached response.
673
+ *
674
+ * **What an attach does not do:** it replays a transcript, it does not re-run the
675
+ * handler — so the procedure's middleware chain (`.use(rls(...))`, rate limits,
676
+ * any custom guard) runs once, for the caller that started the run. That is why
677
+ * the run key is identity-scoped: a guard that has already passed for one user
678
+ * must never be skipped for another.
679
+ */
680
+ interface DurableStreamOptions {
681
+ /**
682
+ * How long a finished transcript is kept before it is trimmed, in
683
+ * milliseconds. Defaults to 24 hours — long enough to survive a reload and
684
+ * a commute, short enough that a chatty shard doesn't accumulate
685
+ * transcripts forever.
686
+ */
687
+ readonly ttlMs?: number;
688
+ }
653
689
  /** The system tables `ctx.db.system` can read. */
654
690
  type SystemTableName = "_scheduled_functions" | "_storage";
655
691
  /**
@@ -2064,4 +2100,4 @@ interface ActionCtx {
2064
2100
  */
2065
2101
  type AnyApi = Record<string, Record<string, RegisteredFunction<ArgsValidator, unknown, FunctionKind>>>;
2066
2102
  declare const anyApi: AnyApi;
2067
- export { type ActionCtx, type AggregateIndexDefinition, type AggregateOp, type AnyApi, type ArgsValidator, type AuthState, type CachePurge, type DatabaseReader, type DatabaseWriter, type DurableObjectJurisdiction, type ExposeConfig, type ExternalSourceCursor, type ExternalSourceDefinition, type ExternalSourceMode, type ExternalSourceRefresh, type FunctionKind, type FunctionVisibility, type GeoBoundingBox, type GeoFilterBuilder, type GeoIndexDefinition, type GeoPointInput, type GlobalBackend, type IndexDefinition, type IndexRangeBuilder, type InferArgs, type LifecycleEvent, type LifecycleEventKind, type LogFields, type LunoraLogMethod, type LunoraLogger, type LunoraMetrics, type LunoraTracer, type LunoraWideEvent, type MutationCtx, type OnDeleteAction, type PaginationOptions, type PaginationResult, type QueryCtx, type RankIndexDefinition, type RankSortKey, type ReadOnlyStorage, type RegisteredAction, type RegisteredFunction, type RegisteredLifecycleHook, type RegisteredMutation, type RegisteredQuery, type RegisteredStream, type RelationDefinition, type RestCacheConfig, type ScheduledFunctionDoc, type ScheduledJob, type Scheduler, type Schema, type SearchFilterBuilder, type SearchIndexDefinition, type SearchLanguage, type SearchStrategy, type Secrets, type SecretsStoreSecretLike, type ShardMode, type SpanEvaluation, type SpanHandle, type SpanKind, type SpanLink, type SpanOptions, type Storage, type StorageMetadata, type SystemDatabaseReader, type SystemDoc, type SystemQuery, type SystemTableName, type TableDefinition, type TableReader, type TableVectorIndex, type TriggerAggregateOptions, type TriggerBuilder, type TriggerCtx, type TriggerDatabase, type TriggerDefinition, type TriggerDeleteEvent, type TriggerEvent, type TriggerGroupByEntry, type TriggerGroupByOptions, type TriggerHandler, type TriggerInsertEvent, type TriggerOp, type TriggerQueryArgs, type TriggerQueryPage, type TriggerRankOptions, type TriggerRankPageOptions, type TriggerRankResult, type TriggerRow, type TriggerTiming, type TriggerUpdateEvent, type TtlDefinition, type VectorEmbedder, type VectorIndexDefinition, type VectorMatch, type VectorMatches, type VectorMetric, type VectorQueryInput, type VectorRecord, type VectorSearch, type VectorSearchReader, type VectorUpsertInput, type WorkflowCreateOptions, type WorkflowHandle, type WorkflowInstance, type WorkflowInstanceStatus, type WorkflowStatusResult, type Workflows, type X402ProcedureConfig, anyApi };
2103
+ export { type ActionCtx, type AggregateIndexDefinition, type AggregateOp, type AnyApi, type ArgsValidator, type AuthState, type CachePurge, type DatabaseReader, type DatabaseWriter, type DurableObjectJurisdiction, type DurableStreamOptions, type ExposeConfig, type ExternalSourceCursor, type ExternalSourceDefinition, type ExternalSourceMode, type ExternalSourceRefresh, type FunctionKind, type FunctionVisibility, type GeoBoundingBox, type GeoFilterBuilder, type GeoIndexDefinition, type GeoPointInput, type GlobalBackend, type IndexDefinition, type IndexRangeBuilder, type InferArgs, type LifecycleEvent, type LifecycleEventKind, type LogFields, type LunoraLogMethod, type LunoraLogger, type LunoraMetrics, type LunoraTracer, type LunoraWideEvent, type MutationCtx, type OnDeleteAction, type PaginationOptions, type PaginationResult, type QueryCtx, type RankIndexDefinition, type RankSortKey, type ReadOnlyStorage, type RegisteredAction, type RegisteredFunction, type RegisteredLifecycleHook, type RegisteredMutation, type RegisteredQuery, type RegisteredStream, type RelationDefinition, type RestCacheConfig, type ScheduledFunctionDoc, type ScheduledJob, type Scheduler, type Schema, type SearchFilterBuilder, type SearchIndexDefinition, type SearchLanguage, type SearchStrategy, type Secrets, type SecretsStoreSecretLike, type ShardMode, type SpanEvaluation, type SpanHandle, type SpanKind, type SpanLink, type SpanOptions, type Storage, type StorageMetadata, type SystemDatabaseReader, type SystemDoc, type SystemQuery, type SystemTableName, type TableDefinition, type TableReader, type TableVectorIndex, type TriggerAggregateOptions, type TriggerBuilder, type TriggerCtx, type TriggerDatabase, type TriggerDefinition, type TriggerDeleteEvent, type TriggerEvent, type TriggerGroupByEntry, type TriggerGroupByOptions, type TriggerHandler, type TriggerInsertEvent, type TriggerOp, type TriggerQueryArgs, type TriggerQueryPage, type TriggerRankOptions, type TriggerRankPageOptions, type TriggerRankResult, type TriggerRow, type TriggerTiming, type TriggerUpdateEvent, type TtlDefinition, type VectorEmbedder, type VectorIndexDefinition, type VectorMatch, type VectorMatches, type VectorMetric, type VectorQueryInput, type VectorRecord, type VectorSearch, type VectorSearchReader, type VectorUpsertInput, type WorkflowCreateOptions, type WorkflowHandle, type WorkflowInstance, type WorkflowInstanceStatus, type WorkflowStatusResult, type Workflows, type X402ProcedureConfig, anyApi };
package/dist/types.d.ts CHANGED
@@ -646,10 +646,46 @@ type RegisteredLifecycleHook = RegisteredFunction<Record<string, never>, void, "
646
646
  */
647
647
  interface RegisteredStream<A extends ArgsValidator, R> {
648
648
  readonly args: A;
649
+ /**
650
+ * Present when the stream was declared `durable`. Chunks are persisted per
651
+ * run before they reach a socket, the producer outlives the socket that
652
+ * opened it, and a reconnecting (or second) client attaches to the same run
653
+ * and replays what it missed. See {@link DurableStreamOptions}.
654
+ */
655
+ readonly durable?: DurableStreamOptions;
649
656
  readonly handler: (context: unknown, args: InferArgs<A>, signal: AbortSignal) => AsyncIterable<R>;
650
657
  readonly kind: "stream";
651
658
  readonly visibility?: FunctionVisibility;
652
659
  }
660
+ /**
661
+ * Durability settings for a `.stream()` procedure.
662
+ *
663
+ * A run is identified by the socket's verified identity plus the function path
664
+ * and arguments, so two clients of the SAME user calling the same stream with
665
+ * the same arguments observe one producer and one transcript. That identity is
666
+ * the feature: it is what makes a reload resume rather than re-generate, and
667
+ * what lets a second tab watch the same answer. A different identity always gets
668
+ * its own run.
669
+ *
670
+ * Sharing applies to a run still in flight. Once a run finishes, a later caller
671
+ * asking the same question gets a fresh one — a transcript is the record of one
672
+ * execution, not a cached response.
673
+ *
674
+ * **What an attach does not do:** it replays a transcript, it does not re-run the
675
+ * handler — so the procedure's middleware chain (`.use(rls(...))`, rate limits,
676
+ * any custom guard) runs once, for the caller that started the run. That is why
677
+ * the run key is identity-scoped: a guard that has already passed for one user
678
+ * must never be skipped for another.
679
+ */
680
+ interface DurableStreamOptions {
681
+ /**
682
+ * How long a finished transcript is kept before it is trimmed, in
683
+ * milliseconds. Defaults to 24 hours — long enough to survive a reload and
684
+ * a commute, short enough that a chatty shard doesn't accumulate
685
+ * transcripts forever.
686
+ */
687
+ readonly ttlMs?: number;
688
+ }
653
689
  /** The system tables `ctx.db.system` can read. */
654
690
  type SystemTableName = "_scheduled_functions" | "_storage";
655
691
  /**
@@ -2064,4 +2100,4 @@ interface ActionCtx {
2064
2100
  */
2065
2101
  type AnyApi = Record<string, Record<string, RegisteredFunction<ArgsValidator, unknown, FunctionKind>>>;
2066
2102
  declare const anyApi: AnyApi;
2067
- export { type ActionCtx, type AggregateIndexDefinition, type AggregateOp, type AnyApi, type ArgsValidator, type AuthState, type CachePurge, type DatabaseReader, type DatabaseWriter, type DurableObjectJurisdiction, type ExposeConfig, type ExternalSourceCursor, type ExternalSourceDefinition, type ExternalSourceMode, type ExternalSourceRefresh, type FunctionKind, type FunctionVisibility, type GeoBoundingBox, type GeoFilterBuilder, type GeoIndexDefinition, type GeoPointInput, type GlobalBackend, type IndexDefinition, type IndexRangeBuilder, type InferArgs, type LifecycleEvent, type LifecycleEventKind, type LogFields, type LunoraLogMethod, type LunoraLogger, type LunoraMetrics, type LunoraTracer, type LunoraWideEvent, type MutationCtx, type OnDeleteAction, type PaginationOptions, type PaginationResult, type QueryCtx, type RankIndexDefinition, type RankSortKey, type ReadOnlyStorage, type RegisteredAction, type RegisteredFunction, type RegisteredLifecycleHook, type RegisteredMutation, type RegisteredQuery, type RegisteredStream, type RelationDefinition, type RestCacheConfig, type ScheduledFunctionDoc, type ScheduledJob, type Scheduler, type Schema, type SearchFilterBuilder, type SearchIndexDefinition, type SearchLanguage, type SearchStrategy, type Secrets, type SecretsStoreSecretLike, type ShardMode, type SpanEvaluation, type SpanHandle, type SpanKind, type SpanLink, type SpanOptions, type Storage, type StorageMetadata, type SystemDatabaseReader, type SystemDoc, type SystemQuery, type SystemTableName, type TableDefinition, type TableReader, type TableVectorIndex, type TriggerAggregateOptions, type TriggerBuilder, type TriggerCtx, type TriggerDatabase, type TriggerDefinition, type TriggerDeleteEvent, type TriggerEvent, type TriggerGroupByEntry, type TriggerGroupByOptions, type TriggerHandler, type TriggerInsertEvent, type TriggerOp, type TriggerQueryArgs, type TriggerQueryPage, type TriggerRankOptions, type TriggerRankPageOptions, type TriggerRankResult, type TriggerRow, type TriggerTiming, type TriggerUpdateEvent, type TtlDefinition, type VectorEmbedder, type VectorIndexDefinition, type VectorMatch, type VectorMatches, type VectorMetric, type VectorQueryInput, type VectorRecord, type VectorSearch, type VectorSearchReader, type VectorUpsertInput, type WorkflowCreateOptions, type WorkflowHandle, type WorkflowInstance, type WorkflowInstanceStatus, type WorkflowStatusResult, type Workflows, type X402ProcedureConfig, anyApi };
2103
+ export { type ActionCtx, type AggregateIndexDefinition, type AggregateOp, type AnyApi, type ArgsValidator, type AuthState, type CachePurge, type DatabaseReader, type DatabaseWriter, type DurableObjectJurisdiction, type DurableStreamOptions, type ExposeConfig, type ExternalSourceCursor, type ExternalSourceDefinition, type ExternalSourceMode, type ExternalSourceRefresh, type FunctionKind, type FunctionVisibility, type GeoBoundingBox, type GeoFilterBuilder, type GeoIndexDefinition, type GeoPointInput, type GlobalBackend, type IndexDefinition, type IndexRangeBuilder, type InferArgs, type LifecycleEvent, type LifecycleEventKind, type LogFields, type LunoraLogMethod, type LunoraLogger, type LunoraMetrics, type LunoraTracer, type LunoraWideEvent, type MutationCtx, type OnDeleteAction, type PaginationOptions, type PaginationResult, type QueryCtx, type RankIndexDefinition, type RankSortKey, type ReadOnlyStorage, type RegisteredAction, type RegisteredFunction, type RegisteredLifecycleHook, type RegisteredMutation, type RegisteredQuery, type RegisteredStream, type RelationDefinition, type RestCacheConfig, type ScheduledFunctionDoc, type ScheduledJob, type Scheduler, type Schema, type SearchFilterBuilder, type SearchIndexDefinition, type SearchLanguage, type SearchStrategy, type Secrets, type SecretsStoreSecretLike, type ShardMode, type SpanEvaluation, type SpanHandle, type SpanKind, type SpanLink, type SpanOptions, type Storage, type StorageMetadata, type SystemDatabaseReader, type SystemDoc, type SystemQuery, type SystemTableName, type TableDefinition, type TableReader, type TableVectorIndex, type TriggerAggregateOptions, type TriggerBuilder, type TriggerCtx, type TriggerDatabase, type TriggerDefinition, type TriggerDeleteEvent, type TriggerEvent, type TriggerGroupByEntry, type TriggerGroupByOptions, type TriggerHandler, type TriggerInsertEvent, type TriggerOp, type TriggerQueryArgs, type TriggerQueryPage, type TriggerRankOptions, type TriggerRankPageOptions, type TriggerRankResult, type TriggerRow, type TriggerTiming, type TriggerUpdateEvent, type TtlDefinition, type VectorEmbedder, type VectorIndexDefinition, type VectorMatch, type VectorMatches, type VectorMetric, type VectorQueryInput, type VectorRecord, type VectorSearch, type VectorSearchReader, type VectorUpsertInput, type WorkflowCreateOptions, type WorkflowHandle, type WorkflowInstance, type WorkflowInstanceStatus, type WorkflowStatusResult, type Workflows, type X402ProcedureConfig, anyApi };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/server",
3
- "version": "1.0.0-alpha.70",
3
+ "version": "1.0.0-alpha.71",
4
4
  "description": "Server primitives for Lunora: defineSchema, defineTable, query, mutation, and action",
5
5
  "keywords": [
6
6
  "backend",
@@ -66,9 +66,9 @@
66
66
  "access": "public"
67
67
  },
68
68
  "dependencies": {
69
- "@lunora/errors": "1.0.0-alpha.20",
70
- "@lunora/scheduler": "1.0.0-alpha.28",
71
- "@lunora/values": "1.0.0-alpha.25",
69
+ "@lunora/errors": "1.0.0-alpha.21",
70
+ "@lunora/scheduler": "1.0.0-alpha.29",
71
+ "@lunora/values": "1.0.0-alpha.26",
72
72
  "drizzle-orm": "^0.45.2",
73
73
  "hono": "^4.12.32"
74
74
  },
@@ -1 +0,0 @@
1
- import{s as g}from"./functions-CDC08CWY.mjs";import{readMaskTag as w}from"./buildMaskRegistry-BCIzKxdK.mjs";import{l as x}from"./policy-tag-Dprt9JWo.mjs";import{l as f}from"./run-middleware-BeEEqmdE.mjs";const y=(t,e)=>e===void 0||typeof t!="object"||t===null?t:Object.assign(Object.create(Object.getPrototypeOf(t)),t,{meta:e}),p=(t,e)=>f(t,e,a=>a),b=(t,e,a,s,i)=>async(r,d)=>{const l=g(t,d),n=await p(e,y(r,i)),m=await a({args:l,ctx:n});return s?s.parse(m):m},v=(t,e,a)=>(s,i,r)=>{const d=g(t,i);return(async function*(){const l=await p(e,s),n=a({args:d,ctx:l,signal:r})[Symbol.asyncIterator]();try{for(;;){if(r.aborted)return;const m=await n.next();if(m.done||r.aborted)return;yield m.value}}finally{await n.return?.()}})()},u=t=>{const e=t.map(a=>x(a)).filter(a=>a!==void 0);return e.length>0?{tags:e}:void 0},c=t=>{const e=new Map;for(const a of t){const s=w(a);if(s)for(const[i,r]of s.columns){const d=e.get(i)??new Set;for(const l of r)d.add(l);e.set(i,d)}}return e.size>0?e:void 0},o=(t,e,a)=>({__lunoraProcedure:t,...a?{__lunoraVisibility:a}:{},input:s=>o(t,{...e,args:{...e.args,...s}},a),[t]:s=>{const i=u(e.middlewares),r=c(e.middlewares);return{args:e.args,...e.expose?{expose:e.expose}:{},handler:b(e.args,e.middlewares,s,e.output,e.meta),kind:t,...r?{maskedTables:r}:{},...e.meta?{meta:e.meta}:{},...i?{rls:i}:{},...a?{visibility:a}:{},...e.x402?{x402:e.x402}:{}}},meta:s=>o(t,{...e,meta:{...e.meta,...s}},a),output:s=>o(t,{...e,output:s},a),...t==="query"?{stream:s=>{const i=u(e.middlewares),r=c(e.middlewares);return{args:e.args,...e.expose?{expose:e.expose}:{},handler:v(e.args,e.middlewares,s),kind:"stream",...r?{maskedTables:r}:{},...i?{rls:i}:{},...a?{visibility:a}:{},...e.x402?{x402:e.x402}:{}}}}:{},use:s=>o(t,{...e,middlewares:[...e.middlewares,s]},a),...a?{}:{expose:s=>o(t,{...e,expose:s},a)},...a?{}:{x402:s=>o(t,{...e,x402:s},a)}}),O={dataModel:()=>({create:t=>({action:o("action",{args:{},middlewares:[]}),internalAction:o("action",{args:{},middlewares:[]},"internal"),internalMutation:o("mutation",{args:{},middlewares:[]},"internal"),internalQuery:o("query",{args:{},middlewares:[]},"internal"),mutation:o("mutation",{args:{},middlewares:[]}),query:o("query",{args:{},middlewares:[]})})})};export{O as initLunora};