@lunora/server 1.0.0-alpha.282 → 1.0.0-alpha.283

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.
@@ -1,5 +1,5 @@
1
1
  import { TransactionHeadroomTracker, SqlExec } from '@lunora/shard-engine';
2
- import { D as DatabaseWriter, S as Schema } from "./packem_shared/types.d-CJnJltzy.mjs";
2
+ import { D as DatabaseWriter, S as Schema } from "./packem_shared/types.d--zaGh3rX.mjs";
3
3
  import '@lunora/values';
4
4
  /** Where the current dispatch's tracker lives: an `AsyncLocalStorage` fits, and so does any stand-in. */
5
5
  interface HeadroomScope {
@@ -1,5 +1,5 @@
1
1
  import { TransactionHeadroomTracker, SqlExec } from '@lunora/shard-engine';
2
- import { D as DatabaseWriter, S as Schema } from "./packem_shared/types.d-CJnJltzy.js";
2
+ import { D as DatabaseWriter, S as Schema } from "./packem_shared/types.d--zaGh3rX.js";
3
3
  import '@lunora/values';
4
4
  /** Where the current dispatch's tracker lives: an `AsyncLocalStorage` fits, and so does any stand-in. */
5
5
  interface HeadroomScope {
@@ -1 +1 @@
1
- import{LunoraError as R}from"@lunora/errors";import{TransactionHeadroomTracker as l,runShardMigrations as p,createShardCtxDb as w,RLS_UNWRAP_SYMBOL as T}from"@lunora/shard-engine";import{beginDeferredSchedules as g}from"./packem_shared/beginDeferredSchedules-BTwq-NUO.mjs";import{bindTableFacade as S}from"./packem_shared/bindOrm-D5mVDvbi.mjs";class y extends l{fallback=new l;scope;constructor(r){super(),this.scope=r}run(r){return this.scope===void 0?(this.fallback=new l,r()):this.scope.run(new l,r)}headroom(){return this.current().headroom()}recordRead(r){this.current().recordRead(r)}recordReadBytes(r){this.current().recordReadBytes(r)}recordDocumentRead(r,n){this.current().recordDocumentRead(r,n)}recordWrite(r){this.current().recordWrite(r)}current(){return this.scope?.getStore()??this.fallback}}const C=e=>{if(e===null||typeof e.userId!="string"||e.userId.length===0)return{claims:null,userId:null};const{userId:r,...n}=e;return{claims:Object.keys(n).length>0?n:null,userId:r}},O=(e,r)=>{const{scheduler:n,sql:a}=r,i=e;p(a,i);const c=new y(r.headroomScope),m=t=>{const o=t;for(const s of Object.keys(i.tables))o[s]=S(t,s);return t};let u=!1;const I=t=>{const o=w({auth:{identity:t.claims,userId:t.userId},enforceRls:r.enforceRls??!0,headroom:c,inTransaction:()=>u,schema:i,sql:a}),s=o[T]??o;return{database:m(o),rawDatabase:m(s)}},d=t=>{a.exec.call(a,t)};let f=Promise.resolve();return{createWriters:I,runWithBudget:t=>c.run(t),runInTransaction:t=>{const o=async()=>{const b=g({scheduler:n});d("BEGIN"),u=!0;try{const h=await t();return d("COMMIT"),u=!1,await b(!0),h}catch(h){u=!1;try{d("ROLLBACK")}catch{}throw await b(!1),h}},s=f.then(()=>c.run(o));return f=s.then(()=>{},()=>{}),s}}},k=e=>{if(typeof e!="object"||e===null)return;const{kind:r}=e;if(r==="query"||r==="mutation"||r==="action")return r},P=(e,r,n,a,i)=>{const c=k(r);if(c!==e)throw new R("INTERNAL",`expected a registered ${e}, received a ${c??"non-function"} reference`);if(!i&&r.visibility==="internal")throw new R("INTERNAL",`This ${e} is an internal function — it is unreachable from the external RPC boundary in production. Call it through ctx.run${e.charAt(0).toUpperCase()}${e.slice(1)} from another function instead.`);return Promise.resolve(r.handler(n,a??{}))};export{O as createInProcessRuntime,k as registeredFunctionKind,C as resolveInProcessIdentity,P as runRegisteredFunction};
1
+ import{LunoraError as R}from"@lunora/errors";import{TransactionHeadroomTracker as l,runShardMigrations as p,createShardCtxDb as w,RLS_UNWRAP_SYMBOL as T}from"@lunora/shard-engine";import{beginDeferredSchedules as g}from"./packem_shared/beginDeferredSchedules-BOsY07vZ.mjs";import{bindTableFacade as S}from"./packem_shared/bindOrm-D5mVDvbi.mjs";class y extends l{fallback=new l;scope;constructor(r){super(),this.scope=r}run(r){return this.scope===void 0?(this.fallback=new l,r()):this.scope.run(new l,r)}headroom(){return this.current().headroom()}recordRead(r){this.current().recordRead(r)}recordReadBytes(r){this.current().recordReadBytes(r)}recordDocumentRead(r,n){this.current().recordDocumentRead(r,n)}recordWrite(r){this.current().recordWrite(r)}current(){return this.scope?.getStore()??this.fallback}}const C=e=>{if(e===null||typeof e.userId!="string"||e.userId.length===0)return{claims:null,userId:null};const{userId:r,...n}=e;return{claims:Object.keys(n).length>0?n:null,userId:r}},O=(e,r)=>{const{scheduler:n,sql:a}=r,i=e;p(a,i);const c=new y(r.headroomScope),m=t=>{const o=t;for(const s of Object.keys(i.tables))o[s]=S(t,s);return t};let u=!1;const I=t=>{const o=w({auth:{identity:t.claims,userId:t.userId},enforceRls:r.enforceRls??!0,headroom:c,inTransaction:()=>u,schema:i,sql:a}),s=o[T]??o;return{database:m(o),rawDatabase:m(s)}},d=t=>{a.exec.call(a,t)};let f=Promise.resolve();return{createWriters:I,runWithBudget:t=>c.run(t),runInTransaction:t=>{const o=async()=>{const b=g({scheduler:n});d("BEGIN"),u=!0;try{const h=await t();return d("COMMIT"),u=!1,await b(!0),h}catch(h){u=!1;try{d("ROLLBACK")}catch{}throw await b(!1),h}},s=f.then(()=>c.run(o));return f=s.then(()=>{},()=>{}),s}}},k=e=>{if(typeof e!="object"||e===null)return;const{kind:r}=e;if(r==="query"||r==="mutation"||r==="action")return r},P=(e,r,n,a,i)=>{const c=k(r);if(c!==e)throw new R("INTERNAL",`expected a registered ${e}, received a ${c??"non-function"} reference`);if(!i&&r.visibility==="internal")throw new R("INTERNAL",`This ${e} is an internal function — it is unreachable from the external RPC boundary in production. Call it through ctx.run${e.charAt(0).toUpperCase()}${e.slice(1)} from another function instead.`);return Promise.resolve(r.handler(n,a??{}))};export{O as createInProcessRuntime,k as registeredFunctionKind,C as resolveInProcessIdentity,P as runRegisteredFunction};
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Validator, Infer, ColumnValidator, Id, StringColumnValidator, ValidatorMap, InferValidatorMap } 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 { A as ArgsValidator, I as InferArgs, R as RegisteredAction, E as ExposeConfig, X as X402ProcedureConfig, b as ActionCtx, c as RegisteredInternalAction, M as MutationCtx, d as RegisteredInternalMutation, Q as QueryCtx, e as RegisteredInternalQuery, f as DurableStreamOptions, g as RegisteredInternalStream, h as RegisteredMutation, i as RegisteredQuery, j as RegisteredStream, F as FunctionKind, T as TableDefinition, k as RegisteredFunction, V as VectorIndexDefinition, S as Schema, l as AggregateOp, G as GlobalBackend, K as KeyedRelationDefinition, m as RelationThrough, n as ThroughRelationDefinition, O as OnDeleteAction, o as RelationDefinition, p as SearchLanguage, q as SearchStrategy, r as ExternalSourceDefinition, s as TriggerBuilder, t as TriggerDefinition, u as VectorEmbedder, v as VectorMetric, w as DurableObjectJurisdiction, x as AggregateIndexDefinition, y as RankIndexDefinition, z as Secrets, B as LiveTopicRef, C as LifecycleEvent, H as ShardInitEvent, J as RegisteredLifecycleHook, W as WhisperEvent } from "./packem_shared/types.d-CJnJltzy.mjs";
4
- export type { N as AuthState, P as CachePurge, U as DatabaseReader, D as DatabaseWriter, Y as FunctionVisibility, Z as GeoBoundingBox, _ as GeoFilterBuilder, $ as GeoIndexDefinition, a0 as GeoPointInput, a1 as IndexDefinition, a2 as IndexRangeBuilder, a3 as LifecycleEventKind, a4 as LogFields, a5 as LunoraLogMethod, a6 as LunoraLogger, a7 as LunoraMetrics, L as LunoraTracer, a8 as LunoraWideEvent, a9 as MutationStorage, aa as PaginationOptions, ab as PaginationResult, ac as PatchIfResult, ad as RankSortKey, ae as ReadOnlyStorage, af as RelatedDirection, ag as RelatedNode, ah as RelatedOptions, ai as RelatedPage, aj as RelatedStart, ak as RelatedStartReference, al as RestCacheConfig, am as RetryPolicy, an as RunQueryOptions, ao as ScheduleRunOptions, ap as ScheduledFunctionDoc, aq as ScheduledJob, ar as ScheduledJobState, as as ScheduledJobView, at as Scheduler, au as SearchFilterBuilder, av as SearchIndexDefinition, aw as ShardMode, ax as SpanContextIds, ay as SpanEvaluation, a as SpanHandle, az as SpanIdentity, aA as SpanKind, aB as SpanLink, aC as SpanOptions, aD as Storage, aE as StorageListOptions, aF as StorageListResult, aG as StorageMetadata, aH as StorageMultipartUpload, aI as StorageMultipartUploadOptions, aJ as StorageObjectBody, aK as StorageObjectHead, aL as StorageRange, aM as StorageUploadBody, aN as StorageUploadOptions, aO as StorageUploadResult, aP as StorageUploadedPart, aQ as SystemDatabaseReader, aR as SystemDoc, aS as SystemQuery, aT as SystemTableName, aU as TableReader, aV as TableVectorIndex, aW as TriggerAggregateOptions, aX as TriggerCtx, aY as TriggerDatabase, aZ as TriggerDeleteEvent, a_ as TriggerEvent, a$ as TriggerGroupByEntry, b0 as TriggerGroupByOptions, b1 as TriggerHandler, b2 as TriggerInsertEvent, b3 as TriggerOp, b4 as TriggerQueryArgs, b5 as TriggerQueryPage, b6 as TriggerRankOptions, b7 as TriggerRankPageOptions, b8 as TriggerRankResult, b9 as TriggerRow, ba as TriggerTiming, bb as TriggerUpdateEvent, bc as TtlDefinition, bd as VectorMatch, be as VectorMatches, bf as VectorQueryInput, bg as VectorRecord, bh as VectorSearch, bi as VectorSearchReader, bj as VectorUpsertInput, bk as WorkflowCreateOptions, bl as WorkflowEventDefinition, bm as WorkflowHandle, bn as WorkflowInstance, bo as WorkflowInstanceEvent, bp as WorkflowInstanceStatus, bq as WorkflowStatusResult, br as Workflows } from "./packem_shared/types.d-CJnJltzy.mjs";
3
+ import { A as ArgsValidator, I as InferArgs, R as RegisteredAction, E as ExposeConfig, X as X402ProcedureConfig, b as ActionCtx, c as RegisteredInternalAction, M as MutationCtx, d as RegisteredInternalMutation, Q as QueryCtx, e as RegisteredInternalQuery, f as DurableStreamOptions, g as RegisteredInternalStream, h as RegisteredMutation, i as RegisteredQuery, j as RegisteredStream, F as FunctionKind, T as TableDefinition, k as RegisteredFunction, V as VectorIndexDefinition, S as Schema, l as AggregateOp, G as GlobalBackend, K as KeyedRelationDefinition, m as RelationThrough, n as ThroughRelationDefinition, O as OnDeleteAction, o as RelationDefinition, p as SearchLanguage, q as SearchStrategy, r as ExternalSourceDefinition, s as TriggerBuilder, t as TriggerDefinition, u as VectorEmbedder, v as VectorMetric, w as DurableObjectJurisdiction, x as AggregateIndexDefinition, y as RankIndexDefinition, z as Secrets, B as LiveTopicRef, C as LifecycleEvent, H as ShardInitEvent, J as RegisteredLifecycleHook, W as WhisperEvent } from "./packem_shared/types.d--zaGh3rX.mjs";
4
+ export type { N as AuthState, P as CachePurge, U as DatabaseReader, D as DatabaseWriter, Y as FunctionVisibility, Z as GeoBoundingBox, _ as GeoFilterBuilder, $ as GeoIndexDefinition, a0 as GeoPointInput, a1 as IndexDefinition, a2 as IndexRangeBuilder, a3 as LifecycleEventKind, a4 as LogFields, a5 as LunoraLogMethod, a6 as LunoraLogger, a7 as LunoraMetrics, L as LunoraTracer, a8 as LunoraWideEvent, a9 as MutationStorage, aa as PaginationOptions, ab as PaginationResult, ac as PatchIfResult, ad as RankSortKey, ae as ReadOnlyStorage, af as RelatedDirection, ag as RelatedNode, ah as RelatedOptions, ai as RelatedPage, aj as RelatedStart, ak as RelatedStartReference, al as RestCacheConfig, am as RetryPolicy, an as RunQueryOptions, ao as ScheduleRunOptions, ap as ScheduledFunctionDoc, aq as ScheduledJob, ar as ScheduledJobState, as as ScheduledJobView, at as Scheduler, au as SearchFilterBuilder, av as SearchIndexDefinition, aw as ShardMode, ax as SpanContextIds, ay as SpanEvaluation, a as SpanHandle, az as SpanIdentity, aA as SpanKind, aB as SpanLink, aC as SpanOptions, aD as Storage, aE as StorageListOptions, aF as StorageListResult, aG as StorageMetadata, aH as StorageMultipartUpload, aI as StorageMultipartUploadOptions, aJ as StorageObjectBody, aK as StorageObjectHead, aL as StorageRange, aM as StorageUploadBody, aN as StorageUploadOptions, aO as StorageUploadResult, aP as StorageUploadedPart, aQ as SystemDatabaseReader, aR as SystemDoc, aS as SystemQuery, aT as SystemTableName, aU as TableReader, aV as TableVectorIndex, aW as TriggerAggregateOptions, aX as TriggerCtx, aY as TriggerDatabase, aZ as TriggerDeleteEvent, a_ as TriggerEvent, a$ as TriggerGroupByEntry, b0 as TriggerGroupByOptions, b1 as TriggerHandler, b2 as TriggerInsertEvent, b3 as TriggerOp, b4 as TriggerQueryArgs, b5 as TriggerQueryPage, b6 as TriggerRankOptions, b7 as TriggerRankPageOptions, b8 as TriggerRankResult, b9 as TriggerRow, ba as TriggerTiming, bb as TriggerUpdateEvent, bc as TtlDefinition, bd as VectorMatch, be as VectorMatches, bf as VectorQueryInput, bg as VectorRecord, bh as VectorSearch, bi as VectorSearchReader, bj as VectorUpsertInput, bk as WorkflowCreateOptions, bl as WorkflowEventDefinition, bm as WorkflowHandle, bn as WorkflowInstance, bo as WorkflowInstanceEvent, bp as WorkflowInstanceStatus, bq as WorkflowStatusResult, br as Workflows } from "./packem_shared/types.d--zaGh3rX.mjs";
5
5
  import { LunoraError } from '@lunora/errors';
6
6
  export { LunoraError, type LunoraErrorCode } from '@lunora/errors';
7
7
  import { Context, Hono, ExecutionContext } from 'hono';
@@ -1451,8 +1451,11 @@ interface SchedulerLike {
1451
1451
  * that had to widen to `unknown` and cast back — the generated shard among them
1452
1452
  * — could not be type-checked against the contract this docblock describes.
1453
1453
  * @param scheduler the `ctx.scheduler` implementation to wrap
1454
+ * @param outbox durable custody for buffered calls; absent on a harness with no store
1455
+ * @param userId reads the user the call is scheduled for, at each call; the raw id is fixed in
1456
+ * the custody record, so a replay with no identity still lands in the same dedup scope
1454
1457
  */
1455
- declare const withDeferredSchedules: <S extends SchedulerLike>(scheduler: S, outbox?: ScheduleOutbox) => S;
1458
+ declare const withDeferredSchedules: <S extends SchedulerLike>(scheduler: S, outbox?: ScheduleOutbox, userId?: () => string | undefined) => S;
1456
1459
  /**
1457
1460
  * Open a deferral window on `context.scheduler` and return its settle function.
1458
1461
  *
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Validator, Infer, ColumnValidator, Id, StringColumnValidator, ValidatorMap, InferValidatorMap } 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 { A as ArgsValidator, I as InferArgs, R as RegisteredAction, E as ExposeConfig, X as X402ProcedureConfig, b as ActionCtx, c as RegisteredInternalAction, M as MutationCtx, d as RegisteredInternalMutation, Q as QueryCtx, e as RegisteredInternalQuery, f as DurableStreamOptions, g as RegisteredInternalStream, h as RegisteredMutation, i as RegisteredQuery, j as RegisteredStream, F as FunctionKind, T as TableDefinition, k as RegisteredFunction, V as VectorIndexDefinition, S as Schema, l as AggregateOp, G as GlobalBackend, K as KeyedRelationDefinition, m as RelationThrough, n as ThroughRelationDefinition, O as OnDeleteAction, o as RelationDefinition, p as SearchLanguage, q as SearchStrategy, r as ExternalSourceDefinition, s as TriggerBuilder, t as TriggerDefinition, u as VectorEmbedder, v as VectorMetric, w as DurableObjectJurisdiction, x as AggregateIndexDefinition, y as RankIndexDefinition, z as Secrets, B as LiveTopicRef, C as LifecycleEvent, H as ShardInitEvent, J as RegisteredLifecycleHook, W as WhisperEvent } from "./packem_shared/types.d-CJnJltzy.js";
4
- export type { N as AuthState, P as CachePurge, U as DatabaseReader, D as DatabaseWriter, Y as FunctionVisibility, Z as GeoBoundingBox, _ as GeoFilterBuilder, $ as GeoIndexDefinition, a0 as GeoPointInput, a1 as IndexDefinition, a2 as IndexRangeBuilder, a3 as LifecycleEventKind, a4 as LogFields, a5 as LunoraLogMethod, a6 as LunoraLogger, a7 as LunoraMetrics, L as LunoraTracer, a8 as LunoraWideEvent, a9 as MutationStorage, aa as PaginationOptions, ab as PaginationResult, ac as PatchIfResult, ad as RankSortKey, ae as ReadOnlyStorage, af as RelatedDirection, ag as RelatedNode, ah as RelatedOptions, ai as RelatedPage, aj as RelatedStart, ak as RelatedStartReference, al as RestCacheConfig, am as RetryPolicy, an as RunQueryOptions, ao as ScheduleRunOptions, ap as ScheduledFunctionDoc, aq as ScheduledJob, ar as ScheduledJobState, as as ScheduledJobView, at as Scheduler, au as SearchFilterBuilder, av as SearchIndexDefinition, aw as ShardMode, ax as SpanContextIds, ay as SpanEvaluation, a as SpanHandle, az as SpanIdentity, aA as SpanKind, aB as SpanLink, aC as SpanOptions, aD as Storage, aE as StorageListOptions, aF as StorageListResult, aG as StorageMetadata, aH as StorageMultipartUpload, aI as StorageMultipartUploadOptions, aJ as StorageObjectBody, aK as StorageObjectHead, aL as StorageRange, aM as StorageUploadBody, aN as StorageUploadOptions, aO as StorageUploadResult, aP as StorageUploadedPart, aQ as SystemDatabaseReader, aR as SystemDoc, aS as SystemQuery, aT as SystemTableName, aU as TableReader, aV as TableVectorIndex, aW as TriggerAggregateOptions, aX as TriggerCtx, aY as TriggerDatabase, aZ as TriggerDeleteEvent, a_ as TriggerEvent, a$ as TriggerGroupByEntry, b0 as TriggerGroupByOptions, b1 as TriggerHandler, b2 as TriggerInsertEvent, b3 as TriggerOp, b4 as TriggerQueryArgs, b5 as TriggerQueryPage, b6 as TriggerRankOptions, b7 as TriggerRankPageOptions, b8 as TriggerRankResult, b9 as TriggerRow, ba as TriggerTiming, bb as TriggerUpdateEvent, bc as TtlDefinition, bd as VectorMatch, be as VectorMatches, bf as VectorQueryInput, bg as VectorRecord, bh as VectorSearch, bi as VectorSearchReader, bj as VectorUpsertInput, bk as WorkflowCreateOptions, bl as WorkflowEventDefinition, bm as WorkflowHandle, bn as WorkflowInstance, bo as WorkflowInstanceEvent, bp as WorkflowInstanceStatus, bq as WorkflowStatusResult, br as Workflows } from "./packem_shared/types.d-CJnJltzy.js";
3
+ import { A as ArgsValidator, I as InferArgs, R as RegisteredAction, E as ExposeConfig, X as X402ProcedureConfig, b as ActionCtx, c as RegisteredInternalAction, M as MutationCtx, d as RegisteredInternalMutation, Q as QueryCtx, e as RegisteredInternalQuery, f as DurableStreamOptions, g as RegisteredInternalStream, h as RegisteredMutation, i as RegisteredQuery, j as RegisteredStream, F as FunctionKind, T as TableDefinition, k as RegisteredFunction, V as VectorIndexDefinition, S as Schema, l as AggregateOp, G as GlobalBackend, K as KeyedRelationDefinition, m as RelationThrough, n as ThroughRelationDefinition, O as OnDeleteAction, o as RelationDefinition, p as SearchLanguage, q as SearchStrategy, r as ExternalSourceDefinition, s as TriggerBuilder, t as TriggerDefinition, u as VectorEmbedder, v as VectorMetric, w as DurableObjectJurisdiction, x as AggregateIndexDefinition, y as RankIndexDefinition, z as Secrets, B as LiveTopicRef, C as LifecycleEvent, H as ShardInitEvent, J as RegisteredLifecycleHook, W as WhisperEvent } from "./packem_shared/types.d--zaGh3rX.js";
4
+ export type { N as AuthState, P as CachePurge, U as DatabaseReader, D as DatabaseWriter, Y as FunctionVisibility, Z as GeoBoundingBox, _ as GeoFilterBuilder, $ as GeoIndexDefinition, a0 as GeoPointInput, a1 as IndexDefinition, a2 as IndexRangeBuilder, a3 as LifecycleEventKind, a4 as LogFields, a5 as LunoraLogMethod, a6 as LunoraLogger, a7 as LunoraMetrics, L as LunoraTracer, a8 as LunoraWideEvent, a9 as MutationStorage, aa as PaginationOptions, ab as PaginationResult, ac as PatchIfResult, ad as RankSortKey, ae as ReadOnlyStorage, af as RelatedDirection, ag as RelatedNode, ah as RelatedOptions, ai as RelatedPage, aj as RelatedStart, ak as RelatedStartReference, al as RestCacheConfig, am as RetryPolicy, an as RunQueryOptions, ao as ScheduleRunOptions, ap as ScheduledFunctionDoc, aq as ScheduledJob, ar as ScheduledJobState, as as ScheduledJobView, at as Scheduler, au as SearchFilterBuilder, av as SearchIndexDefinition, aw as ShardMode, ax as SpanContextIds, ay as SpanEvaluation, a as SpanHandle, az as SpanIdentity, aA as SpanKind, aB as SpanLink, aC as SpanOptions, aD as Storage, aE as StorageListOptions, aF as StorageListResult, aG as StorageMetadata, aH as StorageMultipartUpload, aI as StorageMultipartUploadOptions, aJ as StorageObjectBody, aK as StorageObjectHead, aL as StorageRange, aM as StorageUploadBody, aN as StorageUploadOptions, aO as StorageUploadResult, aP as StorageUploadedPart, aQ as SystemDatabaseReader, aR as SystemDoc, aS as SystemQuery, aT as SystemTableName, aU as TableReader, aV as TableVectorIndex, aW as TriggerAggregateOptions, aX as TriggerCtx, aY as TriggerDatabase, aZ as TriggerDeleteEvent, a_ as TriggerEvent, a$ as TriggerGroupByEntry, b0 as TriggerGroupByOptions, b1 as TriggerHandler, b2 as TriggerInsertEvent, b3 as TriggerOp, b4 as TriggerQueryArgs, b5 as TriggerQueryPage, b6 as TriggerRankOptions, b7 as TriggerRankPageOptions, b8 as TriggerRankResult, b9 as TriggerRow, ba as TriggerTiming, bb as TriggerUpdateEvent, bc as TtlDefinition, bd as VectorMatch, be as VectorMatches, bf as VectorQueryInput, bg as VectorRecord, bh as VectorSearch, bi as VectorSearchReader, bj as VectorUpsertInput, bk as WorkflowCreateOptions, bl as WorkflowEventDefinition, bm as WorkflowHandle, bn as WorkflowInstance, bo as WorkflowInstanceEvent, bp as WorkflowInstanceStatus, bq as WorkflowStatusResult, br as Workflows } from "./packem_shared/types.d--zaGh3rX.js";
5
5
  import { LunoraError } from '@lunora/errors';
6
6
  export { LunoraError, type LunoraErrorCode } from '@lunora/errors';
7
7
  import { Context, Hono, ExecutionContext } from 'hono';
@@ -1451,8 +1451,11 @@ interface SchedulerLike {
1451
1451
  * that had to widen to `unknown` and cast back — the generated shard among them
1452
1452
  * — could not be type-checked against the contract this docblock describes.
1453
1453
  * @param scheduler the `ctx.scheduler` implementation to wrap
1454
+ * @param outbox durable custody for buffered calls; absent on a harness with no store
1455
+ * @param userId reads the user the call is scheduled for, at each call; the raw id is fixed in
1456
+ * the custody record, so a replay with no identity still lands in the same dedup scope
1454
1457
  */
1455
- declare const withDeferredSchedules: <S extends SchedulerLike>(scheduler: S, outbox?: ScheduleOutbox) => S;
1458
+ declare const withDeferredSchedules: <S extends SchedulerLike>(scheduler: S, outbox?: ScheduleOutbox, userId?: () => string | undefined) => S;
1456
1459
  /**
1457
1460
  * Open a deferral window on `context.scheduler` and return its settle function.
1458
1461
  *
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{ACTION_CACHE_DEFAULT_TTL_MS as t,ACTION_CACHE_TABLE as i,actionCacheExtension as n,cacheKeyFor as f,defineActionCache as a}from"./packem_shared/ACTION_CACHE_DEFAULT_TTL_MS-Dv4DKrj0.mjs";import{authorize as s}from"./packem_shared/authorize-CVLZJxf_.mjs";import{initLunora as p}from"./packem_shared/initLunora-DcvCGLL_.mjs";import{isPerDispatchMiddleware as c,tagPerDispatchMiddleware as l}from"./packem_shared/isPerDispatchMiddleware-DDQPatSm.mjs";import{createSecrets as u}from"./packem_shared/createSecrets-D6rLB42U.mjs";import{beginDeferredDeletes as h,flushDeferredDeletes as D,withDeferredDeletes as T}from"./packem_shared/beginDeferredDeletes-DhwFBbvs.mjs";import{beginDeferredSchedules as A,withDeferredSchedules as g}from"./packem_shared/beginDeferredSchedules-BTwq-NUO.mjs";import{DOCUMENT_HISTORY_REDACTED_FIELDS as _,DOCUMENT_HISTORY_TABLE as I,defineDocumentHistory as C,documentHistoryExtension as M}from"./packem_shared/DOCUMENT_HISTORY_REDACTED_FIELDS-BCa6sLSJ.mjs";import{LunoraEnvError as b,defineEnv as y}from"./packem_shared/LunoraEnvError-06_Zc4yc.mjs";import{bindOrm as F,bindTableFacade as v,defineLazyFacade as N}from"./packem_shared/bindOrm-D5mVDvbi.mjs";import{httpAction as H,httpRoute as k,httpRouter as w,lastEventId as B,sseEvent as V}from"./packem_shared/httpAction-Bfw3qwLG.mjs";import{serveStorageObject as j}from"./packem_shared/serveStorageObject-CLz3qhNI.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 $,DEFAULT_MAX_LIMIT as ee,clampLimit as re,defineListArgs as oe}from"./packem_shared/DEFAULT_LIMIT-z7HB19s7.mjs";import{defineLiveStream as ie,liveStreamRouter as ne}from"./packem_shared/defineLiveStream-q9yO3wl6.mjs";import{defineMigration as ae}from"./packem_shared/defineMigration-CXOS0Bvq.mjs";import{defineModule as se}from"./packem_shared/defineModule-OecXWM3U.mjs";import{defineMutator as pe}from"./packem_shared/defineMutator-DlLFSWbO.mjs";import{platformAdmin as ce}from"./packem_shared/platformAdmin-kczXQme8.mjs";import{c as Ee,d as ue,a as Se,b as he,e as De,f as Te,g as Re,h as Ae,i as ge,j as Le,k as _e,m as Ie}from"./packem_shared/plugin-CyLqvCB9.mjs";import{PRESENCE_DEFAULT_TTL_MS as Me,PRESENCE_TABLE as Pe,definePresence as be,presenceExtension as ye}from"./packem_shared/PRESENCE_DEFAULT_TTL_MS-aj9Ec70J.mjs";import{PROCEDURE_META as Fe,UNLOADED_META as ve,procedureMeta as Ne}from"./packem_shared/PROCEDURE_META-DVzrXpfa.mjs";import{protectPublic as He}from"./packem_shared/protectPublic-Bi5_95aP.mjs";import{onQueryChange as we}from"./packem_shared/onQueryChange-iuLzmyPs.mjs";import{defineRoom as Ve}from"./packem_shared/defineRoom-CoGi-xwm.mjs";import{createServices as je}from"./packem_shared/createServices-IJvoqi0e.mjs";import{defineShape as Ye}from"./packem_shared/defineShape-H-0IbZlb.mjs";import{defineWebSocket as Je}from"./packem_shared/defineWebSocket-BHoy6_ox.mjs";import{onWhisper as Qe}from"./packem_shared/onWhisper-CfDbFLQh.mjs";import{LunoraError as qe}from"@lunora/errors";import{cronJobs as $e}from"@lunora/scheduler";import{ValidationError as rr,v as or}from"@lunora/values";import{allowAll as ir,deny as nr,isDeny as fr,toWhereInput as ar}from"./packem_shared/allowAll-DkRAgItV.mjs";import{asBucketStorage as sr}from"./packem_shared/asBucketStorage-DoGYOjq3.mjs";import{assertShapesDeclareReadPolicies as pr,buildRlsReadRegistry as xr,composeShapeReadWhere as cr}from"./packem_shared/assertShapesDeclareReadPolicies-C09SMvM4.mjs";import{buildMaskRegistry as Er}from"./packem_shared/buildMaskRegistry-DpWMtalG.mjs";import{createPolicyDsl as Sr,definePermission as hr,definePolicies as Dr,definePolicy as Tr,defineRole as Rr}from"./packem_shared/createPolicyDsl-BZa6SqLJ.mjs";import{defineStorageRule as gr,defineStorageRules as Lr}from"./packem_shared/defineStorageRule-Dv4nJE0H.mjs";import{isSafeHeaderValue as Ir}from"./packem_shared/isSafeHeaderValue-DswDADFy.mjs";import{mask as Mr}from"./packem_shared/mask-DHJtsP7t.mjs";import{r as br}from"./packem_shared/redact-secrets-BpatNz48.mjs";import{r as Or}from"./packem_shared/middleware-CHYtnvZP.mjs";import{storageRules as vr}from"./packem_shared/storageRules-BVIXkoRg.mjs";const e="0.0.0";export{t as ACTION_CACHE_DEFAULT_TTL_MS,i as ACTION_CACHE_TABLE,$ as DEFAULT_LIMIT,ee as DEFAULT_MAX_LIMIT,_ as DOCUMENT_HISTORY_REDACTED_FIELDS,I as DOCUMENT_HISTORY_TABLE,b as LunoraEnvError,qe as LunoraError,Me as PRESENCE_DEFAULT_TTL_MS,Pe as PRESENCE_TABLE,Fe as PROCEDURE_META,ve as UNLOADED_META,e as VERSION,rr as ValidationError,n as actionCacheExtension,ir as allowAll,sr as asBucketStorage,pr as assertShapesDeclareReadPolicies,s as authorize,h as beginDeferredDeletes,A as beginDeferredSchedules,F as bindOrm,v as bindTableFacade,Er as buildMaskRegistry,xr as buildRlsReadRegistry,f as cacheKeyFor,re as clampLimit,Ee as composePluginMiddleware,cr as composeShapeReadWhere,Sr as createPolicyDsl,u as createSecrets,je as createServices,$e as cronJobs,a as defineActionCache,ue as defineAggregateIndex,Se as defineComponent,C as defineDocumentHistory,y as defineEnv,Y as defineIdentity,J as defineIdentityGuard,N as defineLazyFacade,oe as defineListArgs,ie as defineLiveStream,ae as defineMigration,se as defineModule,pe as defineMutator,hr as definePermission,he as definePlugin,Dr as definePolicies,Tr as definePolicy,be as definePresence,De as defineRankIndex,Rr as defineRole,Ve as defineRoom,Te as defineSchema,Re as defineSchemaExtension,Ye as defineShape,gr as defineStorageRule,Lr as defineStorageRules,Ae as defineTable,ge as defineVectorIndex,Je as defineWebSocket,nr as deny,M as documentHistoryExtension,D as flushDeferredDeletes,H as httpAction,k as httpRoute,w as httpRouter,Le as indexFieldsFromSchema,p as initLunora,_e as installPlugins,fr as isDeny,c as isPerDispatchMiddleware,Ir as isSafeHeaderValue,B as lastEventId,ne as liveStreamRouter,Mr as mask,Ie as mergeSchemaExtension,Q as onConnect,X as onDisconnect,we as onQueryChange,q as onShardInit,Qe as onWhisper,ce as platformAdmin,ye as presenceExtension,Ne as procedureMeta,He as protectPublic,br as redactSecrets,Or as rls,j as serveStorageObject,V as sseEvent,vr as storageRules,l as tagPerDispatchMiddleware,ar as toWhereInput,or as v,T as withDeferredDeletes,g as withDeferredSchedules};
1
+ import{ACTION_CACHE_DEFAULT_TTL_MS as t,ACTION_CACHE_TABLE as i,actionCacheExtension as n,cacheKeyFor as f,defineActionCache as a}from"./packem_shared/ACTION_CACHE_DEFAULT_TTL_MS-Dv4DKrj0.mjs";import{authorize as s}from"./packem_shared/authorize-CVLZJxf_.mjs";import{initLunora as p}from"./packem_shared/initLunora-DcvCGLL_.mjs";import{isPerDispatchMiddleware as c,tagPerDispatchMiddleware as l}from"./packem_shared/isPerDispatchMiddleware-DDQPatSm.mjs";import{createSecrets as u}from"./packem_shared/createSecrets-D6rLB42U.mjs";import{beginDeferredDeletes as h,flushDeferredDeletes as D,withDeferredDeletes as T}from"./packem_shared/beginDeferredDeletes-DhwFBbvs.mjs";import{beginDeferredSchedules as A,withDeferredSchedules as g}from"./packem_shared/beginDeferredSchedules-BOsY07vZ.mjs";import{DOCUMENT_HISTORY_REDACTED_FIELDS as _,DOCUMENT_HISTORY_TABLE as I,defineDocumentHistory as C,documentHistoryExtension as M}from"./packem_shared/DOCUMENT_HISTORY_REDACTED_FIELDS-BCa6sLSJ.mjs";import{LunoraEnvError as b,defineEnv as y}from"./packem_shared/LunoraEnvError-06_Zc4yc.mjs";import{bindOrm as F,bindTableFacade as v,defineLazyFacade as N}from"./packem_shared/bindOrm-D5mVDvbi.mjs";import{httpAction as H,httpRoute as k,httpRouter as w,lastEventId as B,sseEvent as V}from"./packem_shared/httpAction-Bfw3qwLG.mjs";import{serveStorageObject as j}from"./packem_shared/serveStorageObject-CLz3qhNI.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 $,DEFAULT_MAX_LIMIT as ee,clampLimit as re,defineListArgs as oe}from"./packem_shared/DEFAULT_LIMIT-z7HB19s7.mjs";import{defineLiveStream as ie,liveStreamRouter as ne}from"./packem_shared/defineLiveStream-q9yO3wl6.mjs";import{defineMigration as ae}from"./packem_shared/defineMigration-CXOS0Bvq.mjs";import{defineModule as se}from"./packem_shared/defineModule-OecXWM3U.mjs";import{defineMutator as pe}from"./packem_shared/defineMutator-DlLFSWbO.mjs";import{platformAdmin as ce}from"./packem_shared/platformAdmin-kczXQme8.mjs";import{c as Ee,d as ue,a as Se,b as he,e as De,f as Te,g as Re,h as Ae,i as ge,j as Le,k as _e,m as Ie}from"./packem_shared/plugin-CyLqvCB9.mjs";import{PRESENCE_DEFAULT_TTL_MS as Me,PRESENCE_TABLE as Pe,definePresence as be,presenceExtension as ye}from"./packem_shared/PRESENCE_DEFAULT_TTL_MS-aj9Ec70J.mjs";import{PROCEDURE_META as Fe,UNLOADED_META as ve,procedureMeta as Ne}from"./packem_shared/PROCEDURE_META-DVzrXpfa.mjs";import{protectPublic as He}from"./packem_shared/protectPublic-Bi5_95aP.mjs";import{onQueryChange as we}from"./packem_shared/onQueryChange-iuLzmyPs.mjs";import{defineRoom as Ve}from"./packem_shared/defineRoom-CoGi-xwm.mjs";import{createServices as je}from"./packem_shared/createServices-IJvoqi0e.mjs";import{defineShape as Ye}from"./packem_shared/defineShape-H-0IbZlb.mjs";import{defineWebSocket as Je}from"./packem_shared/defineWebSocket-BHoy6_ox.mjs";import{onWhisper as Qe}from"./packem_shared/onWhisper-CfDbFLQh.mjs";import{LunoraError as qe}from"@lunora/errors";import{cronJobs as $e}from"@lunora/scheduler";import{ValidationError as rr,v as or}from"@lunora/values";import{allowAll as ir,deny as nr,isDeny as fr,toWhereInput as ar}from"./packem_shared/allowAll-DkRAgItV.mjs";import{asBucketStorage as sr}from"./packem_shared/asBucketStorage-DoGYOjq3.mjs";import{assertShapesDeclareReadPolicies as pr,buildRlsReadRegistry as xr,composeShapeReadWhere as cr}from"./packem_shared/assertShapesDeclareReadPolicies-C09SMvM4.mjs";import{buildMaskRegistry as Er}from"./packem_shared/buildMaskRegistry-DpWMtalG.mjs";import{createPolicyDsl as Sr,definePermission as hr,definePolicies as Dr,definePolicy as Tr,defineRole as Rr}from"./packem_shared/createPolicyDsl-BZa6SqLJ.mjs";import{defineStorageRule as gr,defineStorageRules as Lr}from"./packem_shared/defineStorageRule-Dv4nJE0H.mjs";import{isSafeHeaderValue as Ir}from"./packem_shared/isSafeHeaderValue-DswDADFy.mjs";import{mask as Mr}from"./packem_shared/mask-DHJtsP7t.mjs";import{r as br}from"./packem_shared/redact-secrets-BpatNz48.mjs";import{r as Or}from"./packem_shared/middleware-CHYtnvZP.mjs";import{storageRules as vr}from"./packem_shared/storageRules-BVIXkoRg.mjs";const e="0.0.0";export{t as ACTION_CACHE_DEFAULT_TTL_MS,i as ACTION_CACHE_TABLE,$ as DEFAULT_LIMIT,ee as DEFAULT_MAX_LIMIT,_ as DOCUMENT_HISTORY_REDACTED_FIELDS,I as DOCUMENT_HISTORY_TABLE,b as LunoraEnvError,qe as LunoraError,Me as PRESENCE_DEFAULT_TTL_MS,Pe as PRESENCE_TABLE,Fe as PROCEDURE_META,ve as UNLOADED_META,e as VERSION,rr as ValidationError,n as actionCacheExtension,ir as allowAll,sr as asBucketStorage,pr as assertShapesDeclareReadPolicies,s as authorize,h as beginDeferredDeletes,A as beginDeferredSchedules,F as bindOrm,v as bindTableFacade,Er as buildMaskRegistry,xr as buildRlsReadRegistry,f as cacheKeyFor,re as clampLimit,Ee as composePluginMiddleware,cr as composeShapeReadWhere,Sr as createPolicyDsl,u as createSecrets,je as createServices,$e as cronJobs,a as defineActionCache,ue as defineAggregateIndex,Se as defineComponent,C as defineDocumentHistory,y as defineEnv,Y as defineIdentity,J as defineIdentityGuard,N as defineLazyFacade,oe as defineListArgs,ie as defineLiveStream,ae as defineMigration,se as defineModule,pe as defineMutator,hr as definePermission,he as definePlugin,Dr as definePolicies,Tr as definePolicy,be as definePresence,De as defineRankIndex,Rr as defineRole,Ve as defineRoom,Te as defineSchema,Re as defineSchemaExtension,Ye as defineShape,gr as defineStorageRule,Lr as defineStorageRules,Ae as defineTable,ge as defineVectorIndex,Je as defineWebSocket,nr as deny,M as documentHistoryExtension,D as flushDeferredDeletes,H as httpAction,k as httpRoute,w as httpRouter,Le as indexFieldsFromSchema,p as initLunora,_e as installPlugins,fr as isDeny,c as isPerDispatchMiddleware,Ir as isSafeHeaderValue,B as lastEventId,ne as liveStreamRouter,Mr as mask,Ie as mergeSchemaExtension,Q as onConnect,X as onDisconnect,we as onQueryChange,q as onShardInit,Qe as onWhisper,ce as platformAdmin,ye as presenceExtension,Ne as procedureMeta,He as protectPublic,br as redactSecrets,Or as rls,j as serveStorageObject,V as sseEvent,vr as storageRules,l as tagPerDispatchMiddleware,ar as toWhereInput,or as v,T as withDeferredDeletes,g as withDeferredSchedules};
package/dist/otel.d.mts CHANGED
@@ -41,7 +41,7 @@
41
41
  * `@opentelemetry/api` is a PEER dependency: it keeps a module-global registry,
42
42
  * so a second copy in the tree would silently split it.
43
43
  */
44
- import { a as SpanHandle, L as LunoraTracer } from "./packem_shared/types.d-CJnJltzy.mjs";
44
+ import { a as SpanHandle, L as LunoraTracer } from "./packem_shared/types.d--zaGh3rX.mjs";
45
45
  import '@lunora/values';
46
46
  /**
47
47
  * @since 1.0.0
package/dist/otel.d.ts CHANGED
@@ -41,7 +41,7 @@
41
41
  * `@opentelemetry/api` is a PEER dependency: it keeps a module-global registry,
42
42
  * so a second copy in the tree would silently split it.
43
43
  */
44
- import { a as SpanHandle, L as LunoraTracer } from "./packem_shared/types.d-CJnJltzy.js";
44
+ import { a as SpanHandle, L as LunoraTracer } from "./packem_shared/types.d--zaGh3rX.js";
45
45
  import '@lunora/values';
46
46
  /**
47
47
  * @since 1.0.0
@@ -0,0 +1 @@
1
+ import{assertScheduleInstant as O,assertScheduleDelay as S,resolveScheduleId as j,assertDedupKey as I}from"@lunora/scheduler";import{encodeArgsOrThrow as U}from"@lunora/wire";const x=new WeakMap,v=r=>{if(typeof r=="string")return r;const n=r??{},e=n.__lunoraRef??n.binding;return typeof e=="string"?e:"<unknown>"},A=r=>{let n=r;for(;n!==void 0&&!n.open;)n=n.parent;return n},$=(r,n,e)=>r==="runAfter"?Math.max(n,e-Date.now()):Math.max(n,e),k=async(r,{id:n,run:e,token:t})=>{if(r?.handOff!==void 0){await r.handOff(n,e,t);return}await e(),r?.forget(n)},q=(r,n)=>{const e=n?.();return e!==void 0&&e.length>0?{...r,dedupUserId:e}:r===void 0||!("dedupUserId"in r)?r:Object.fromEntries(Object.entries(r).filter(([t])=>t!=="dedupUserId"))},P=(r,n,e)=>{const t=r,d={decisions:new Map,innermost:void 0,outbox:n},u=(o,i,s,c,w)=>t[o].call(t,i,s,c,w),a=(o,i,s,c,w)=>{const p=q(w,e),h=v(s);d.decisions.has(h)||d.decisions.set(h,d.outbox?.admit(h));const y=d.decisions.get(h),g=y===void 0?i:$(o,i,y),b=d.innermost;if(b===void 0)return u(o,g,s,c,p);const l=j(p?.id),m={...p,dedupKey:I(p?.dedupKey)??`${l}-${crypto.randomUUID().replaceAll("-","")}`},D=d.outbox?.record(l,{args:U(`ctx.scheduler.${o}`,v(s),c),options:m,target:s,when:Math.ceil(o==="runAfter"?Date.now()+g:g)});return b.pending.push({id:l,run:async()=>u(o,g,s,c,{...m,id:l}),token:D}),Promise.resolve(l)},f={...t,runAfter:(o,i,s,c)=>(S(o,"ctx.scheduler.runAfter"),a("runAfter",o,i,s,c)),runAt:(o,i,s,c)=>(O(o,Date.now(),"ctx.scheduler.runAt"),a("runAt",o,i,s,c))};return Object.setPrototypeOf(f,Object.getPrototypeOf(t)),x.set(f,d),f},W=r=>{const{scheduler:n}=r,e=typeof n=="object"&&n!==null?x.get(n):void 0;if(!e)return async()=>{};const t={open:!0,parent:e.innermost,pending:[]};return e.innermost=t,async d=>{if(!t.open)return;t.open=!1,e.innermost===t&&(e.innermost=A(t.parent));const u=t.pending.splice(0);if(u.length===0)return;if(!d){for(const{id:s}of u)e.outbox?.forget(s);return}const a=A(t.parent);if(a!==void 0){a.pending.push(...u);return}const f=[];for(const s of u)try{await k(e.outbox,s)}catch(c){f.push(c)}const[o,...i]=f;if(o!==void 0)throw e.outbox?.wake(),i.length===0?o:new AggregateError(f,`ctx.scheduler: ${String(f.length)} of ${String(u.length)} deferred jobs failed to reach the scheduler after the commit`)}};export{W as beginDeferredSchedules,P as withDeferredSchedules};
@@ -1968,9 +1968,9 @@ interface ScheduleRunOptions {
1968
1968
  * The key the job's receiver dedups a re-delivery on. Defaults to one minted per scheduling;
1969
1969
  * set it when the same logical job may be scheduled more than once and must run once. Must
1970
1970
  * match `^[A-Za-z0-9_][A-Za-z0-9_-]{0,99}$`; inside a mutation a key that does not is refused
1971
- * there and then, rolling the mutation back. A function target remembers the key for 24 hours,
1972
- * a workflow target for as long as its instance exists, and the key is shared by every job
1973
- * reaching the same shard: scope a fixed key yourself when callers could collide.
1971
+ * there and then, rolling the mutation back. A function target dedups per scheduling user and
1972
+ * target function (jobs with no user share one scope per function) and remembers the key for
1973
+ * 24 hours; a workflow target uses the bare key as its instance id, for as long as it exists.
1974
1974
  */
1975
1975
  dedupKey?: string;
1976
1976
  /** Retry policy for this job; the scheduler's defaults apply when omitted. */
@@ -1968,9 +1968,9 @@ interface ScheduleRunOptions {
1968
1968
  * The key the job's receiver dedups a re-delivery on. Defaults to one minted per scheduling;
1969
1969
  * set it when the same logical job may be scheduled more than once and must run once. Must
1970
1970
  * match `^[A-Za-z0-9_][A-Za-z0-9_-]{0,99}$`; inside a mutation a key that does not is refused
1971
- * there and then, rolling the mutation back. A function target remembers the key for 24 hours,
1972
- * a workflow target for as long as its instance exists, and the key is shared by every job
1973
- * reaching the same shard: scope a fixed key yourself when callers could collide.
1971
+ * there and then, rolling the mutation back. A function target dedups per scheduling user and
1972
+ * target function (jobs with no user share one scope per function) and remembers the key for
1973
+ * 24 hours; a workflow target uses the bare key as its instance id, for as long as it exists.
1974
1974
  */
1975
1975
  dedupKey?: string;
1976
1976
  /** Retry policy for this job; the scheduler's defaults apply when omitted. */
package/dist/types.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export type { b as ActionCtx, x as AggregateIndexDefinition, l as AggregateOp, A as ArgsValidator, N as AuthState, P as CachePurge, U as DatabaseReader, D as DatabaseWriter, w as DurableObjectJurisdiction, f as DurableStreamOptions, E as ExposeConfig, bs as ExternalSourceCursor, r as ExternalSourceDefinition, bt as ExternalSourceMode, bu as ExternalSourceRefresh, F as FunctionKind, Y as FunctionVisibility, Z as GeoBoundingBox, _ as GeoFilterBuilder, $ as GeoIndexDefinition, a0 as GeoPointInput, G as GlobalBackend, a1 as IndexDefinition, a2 as IndexRangeBuilder, I as InferArgs, K as KeyedRelationDefinition, C as LifecycleEvent, a3 as LifecycleEventKind, a4 as LogFields, a5 as LunoraLogMethod, a6 as LunoraLogger, a7 as LunoraMetrics, L as LunoraTracer, a8 as LunoraWideEvent, M as MutationCtx, a9 as MutationStorage, O as OnDeleteAction, aa as PaginationOptions, ab as PaginationResult, ac as PatchIfResult, Q as QueryCtx, y as RankIndexDefinition, ad as RankSortKey, ae as ReadOnlyStorage, R as RegisteredAction, k as RegisteredFunction, c as RegisteredInternalAction, d as RegisteredInternalMutation, e as RegisteredInternalQuery, g as RegisteredInternalStream, J as RegisteredLifecycleHook, h as RegisteredMutation, i as RegisteredQuery, j as RegisteredStream, af as RelatedDirection, ag as RelatedNode, ah as RelatedOptions, ai as RelatedPage, aj as RelatedStart, ak as RelatedStartReference, o as RelationDefinition, m as RelationThrough, al as RestCacheConfig, am as RetryPolicy, an as RunQueryOptions, ao as ScheduleRunOptions, ap as ScheduledFunctionDoc, aq as ScheduledJob, ar as ScheduledJobState, as as ScheduledJobView, at as Scheduler, S as Schema, au as SearchFilterBuilder, av as SearchIndexDefinition, p as SearchLanguage, q as SearchStrategy, z as Secrets, bv as SecretsStoreSecretLike, H as ShardInitEvent, aw as ShardMode, ax as SpanContextIds, ay as SpanEvaluation, a as SpanHandle, az as SpanIdentity, aA as SpanKind, aB as SpanLink, aC as SpanOptions, aD as Storage, aE as StorageListOptions, aF as StorageListResult, aG as StorageMetadata, aH as StorageMultipartUpload, aI as StorageMultipartUploadOptions, aJ as StorageObjectBody, aK as StorageObjectHead, aL as StorageRange, aM as StorageUploadBody, aN as StorageUploadOptions, aO as StorageUploadResult, aP as StorageUploadedPart, aQ as SystemDatabaseReader, aR as SystemDoc, aS as SystemQuery, aT as SystemTableName, T as TableDefinition, aU as TableReader, aV as TableVectorIndex, n as ThroughRelationDefinition, aW as TriggerAggregateOptions, s as TriggerBuilder, aX as TriggerCtx, aY as TriggerDatabase, t as TriggerDefinition, aZ as TriggerDeleteEvent, a_ as TriggerEvent, a$ as TriggerGroupByEntry, b0 as TriggerGroupByOptions, b1 as TriggerHandler, b2 as TriggerInsertEvent, b3 as TriggerOp, b4 as TriggerQueryArgs, b5 as TriggerQueryPage, b6 as TriggerRankOptions, b7 as TriggerRankPageOptions, b8 as TriggerRankResult, b9 as TriggerRow, ba as TriggerTiming, bb as TriggerUpdateEvent, bc as TtlDefinition, u as VectorEmbedder, V as VectorIndexDefinition, bd as VectorMatch, be as VectorMatches, v as VectorMetric, bf as VectorQueryInput, bg as VectorRecord, bh as VectorSearch, bi as VectorSearchReader, bj as VectorUpsertInput, W as WhisperEvent, bk as WorkflowCreateOptions, bl as WorkflowEventDefinition, bm as WorkflowHandle, bn as WorkflowInstance, bo as WorkflowInstanceEvent, bp as WorkflowInstanceStatus, bq as WorkflowStatusResult, br as Workflows, X as X402ProcedureConfig } from "./packem_shared/types.d-CJnJltzy.mjs";
1
+ export type { b as ActionCtx, x as AggregateIndexDefinition, l as AggregateOp, A as ArgsValidator, N as AuthState, P as CachePurge, U as DatabaseReader, D as DatabaseWriter, w as DurableObjectJurisdiction, f as DurableStreamOptions, E as ExposeConfig, bs as ExternalSourceCursor, r as ExternalSourceDefinition, bt as ExternalSourceMode, bu as ExternalSourceRefresh, F as FunctionKind, Y as FunctionVisibility, Z as GeoBoundingBox, _ as GeoFilterBuilder, $ as GeoIndexDefinition, a0 as GeoPointInput, G as GlobalBackend, a1 as IndexDefinition, a2 as IndexRangeBuilder, I as InferArgs, K as KeyedRelationDefinition, C as LifecycleEvent, a3 as LifecycleEventKind, a4 as LogFields, a5 as LunoraLogMethod, a6 as LunoraLogger, a7 as LunoraMetrics, L as LunoraTracer, a8 as LunoraWideEvent, M as MutationCtx, a9 as MutationStorage, O as OnDeleteAction, aa as PaginationOptions, ab as PaginationResult, ac as PatchIfResult, Q as QueryCtx, y as RankIndexDefinition, ad as RankSortKey, ae as ReadOnlyStorage, R as RegisteredAction, k as RegisteredFunction, c as RegisteredInternalAction, d as RegisteredInternalMutation, e as RegisteredInternalQuery, g as RegisteredInternalStream, J as RegisteredLifecycleHook, h as RegisteredMutation, i as RegisteredQuery, j as RegisteredStream, af as RelatedDirection, ag as RelatedNode, ah as RelatedOptions, ai as RelatedPage, aj as RelatedStart, ak as RelatedStartReference, o as RelationDefinition, m as RelationThrough, al as RestCacheConfig, am as RetryPolicy, an as RunQueryOptions, ao as ScheduleRunOptions, ap as ScheduledFunctionDoc, aq as ScheduledJob, ar as ScheduledJobState, as as ScheduledJobView, at as Scheduler, S as Schema, au as SearchFilterBuilder, av as SearchIndexDefinition, p as SearchLanguage, q as SearchStrategy, z as Secrets, bv as SecretsStoreSecretLike, H as ShardInitEvent, aw as ShardMode, ax as SpanContextIds, ay as SpanEvaluation, a as SpanHandle, az as SpanIdentity, aA as SpanKind, aB as SpanLink, aC as SpanOptions, aD as Storage, aE as StorageListOptions, aF as StorageListResult, aG as StorageMetadata, aH as StorageMultipartUpload, aI as StorageMultipartUploadOptions, aJ as StorageObjectBody, aK as StorageObjectHead, aL as StorageRange, aM as StorageUploadBody, aN as StorageUploadOptions, aO as StorageUploadResult, aP as StorageUploadedPart, aQ as SystemDatabaseReader, aR as SystemDoc, aS as SystemQuery, aT as SystemTableName, T as TableDefinition, aU as TableReader, aV as TableVectorIndex, n as ThroughRelationDefinition, aW as TriggerAggregateOptions, s as TriggerBuilder, aX as TriggerCtx, aY as TriggerDatabase, t as TriggerDefinition, aZ as TriggerDeleteEvent, a_ as TriggerEvent, a$ as TriggerGroupByEntry, b0 as TriggerGroupByOptions, b1 as TriggerHandler, b2 as TriggerInsertEvent, b3 as TriggerOp, b4 as TriggerQueryArgs, b5 as TriggerQueryPage, b6 as TriggerRankOptions, b7 as TriggerRankPageOptions, b8 as TriggerRankResult, b9 as TriggerRow, ba as TriggerTiming, bb as TriggerUpdateEvent, bc as TtlDefinition, u as VectorEmbedder, V as VectorIndexDefinition, bd as VectorMatch, be as VectorMatches, v as VectorMetric, bf as VectorQueryInput, bg as VectorRecord, bh as VectorSearch, bi as VectorSearchReader, bj as VectorUpsertInput, W as WhisperEvent, bk as WorkflowCreateOptions, bl as WorkflowEventDefinition, bm as WorkflowHandle, bn as WorkflowInstance, bo as WorkflowInstanceEvent, bp as WorkflowInstanceStatus, bq as WorkflowStatusResult, br as Workflows, X as X402ProcedureConfig } from "./packem_shared/types.d--zaGh3rX.mjs";
2
2
  import '@lunora/values';
package/dist/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export type { b as ActionCtx, x as AggregateIndexDefinition, l as AggregateOp, A as ArgsValidator, N as AuthState, P as CachePurge, U as DatabaseReader, D as DatabaseWriter, w as DurableObjectJurisdiction, f as DurableStreamOptions, E as ExposeConfig, bs as ExternalSourceCursor, r as ExternalSourceDefinition, bt as ExternalSourceMode, bu as ExternalSourceRefresh, F as FunctionKind, Y as FunctionVisibility, Z as GeoBoundingBox, _ as GeoFilterBuilder, $ as GeoIndexDefinition, a0 as GeoPointInput, G as GlobalBackend, a1 as IndexDefinition, a2 as IndexRangeBuilder, I as InferArgs, K as KeyedRelationDefinition, C as LifecycleEvent, a3 as LifecycleEventKind, a4 as LogFields, a5 as LunoraLogMethod, a6 as LunoraLogger, a7 as LunoraMetrics, L as LunoraTracer, a8 as LunoraWideEvent, M as MutationCtx, a9 as MutationStorage, O as OnDeleteAction, aa as PaginationOptions, ab as PaginationResult, ac as PatchIfResult, Q as QueryCtx, y as RankIndexDefinition, ad as RankSortKey, ae as ReadOnlyStorage, R as RegisteredAction, k as RegisteredFunction, c as RegisteredInternalAction, d as RegisteredInternalMutation, e as RegisteredInternalQuery, g as RegisteredInternalStream, J as RegisteredLifecycleHook, h as RegisteredMutation, i as RegisteredQuery, j as RegisteredStream, af as RelatedDirection, ag as RelatedNode, ah as RelatedOptions, ai as RelatedPage, aj as RelatedStart, ak as RelatedStartReference, o as RelationDefinition, m as RelationThrough, al as RestCacheConfig, am as RetryPolicy, an as RunQueryOptions, ao as ScheduleRunOptions, ap as ScheduledFunctionDoc, aq as ScheduledJob, ar as ScheduledJobState, as as ScheduledJobView, at as Scheduler, S as Schema, au as SearchFilterBuilder, av as SearchIndexDefinition, p as SearchLanguage, q as SearchStrategy, z as Secrets, bv as SecretsStoreSecretLike, H as ShardInitEvent, aw as ShardMode, ax as SpanContextIds, ay as SpanEvaluation, a as SpanHandle, az as SpanIdentity, aA as SpanKind, aB as SpanLink, aC as SpanOptions, aD as Storage, aE as StorageListOptions, aF as StorageListResult, aG as StorageMetadata, aH as StorageMultipartUpload, aI as StorageMultipartUploadOptions, aJ as StorageObjectBody, aK as StorageObjectHead, aL as StorageRange, aM as StorageUploadBody, aN as StorageUploadOptions, aO as StorageUploadResult, aP as StorageUploadedPart, aQ as SystemDatabaseReader, aR as SystemDoc, aS as SystemQuery, aT as SystemTableName, T as TableDefinition, aU as TableReader, aV as TableVectorIndex, n as ThroughRelationDefinition, aW as TriggerAggregateOptions, s as TriggerBuilder, aX as TriggerCtx, aY as TriggerDatabase, t as TriggerDefinition, aZ as TriggerDeleteEvent, a_ as TriggerEvent, a$ as TriggerGroupByEntry, b0 as TriggerGroupByOptions, b1 as TriggerHandler, b2 as TriggerInsertEvent, b3 as TriggerOp, b4 as TriggerQueryArgs, b5 as TriggerQueryPage, b6 as TriggerRankOptions, b7 as TriggerRankPageOptions, b8 as TriggerRankResult, b9 as TriggerRow, ba as TriggerTiming, bb as TriggerUpdateEvent, bc as TtlDefinition, u as VectorEmbedder, V as VectorIndexDefinition, bd as VectorMatch, be as VectorMatches, v as VectorMetric, bf as VectorQueryInput, bg as VectorRecord, bh as VectorSearch, bi as VectorSearchReader, bj as VectorUpsertInput, W as WhisperEvent, bk as WorkflowCreateOptions, bl as WorkflowEventDefinition, bm as WorkflowHandle, bn as WorkflowInstance, bo as WorkflowInstanceEvent, bp as WorkflowInstanceStatus, bq as WorkflowStatusResult, br as Workflows, X as X402ProcedureConfig } from "./packem_shared/types.d-CJnJltzy.js";
1
+ export type { b as ActionCtx, x as AggregateIndexDefinition, l as AggregateOp, A as ArgsValidator, N as AuthState, P as CachePurge, U as DatabaseReader, D as DatabaseWriter, w as DurableObjectJurisdiction, f as DurableStreamOptions, E as ExposeConfig, bs as ExternalSourceCursor, r as ExternalSourceDefinition, bt as ExternalSourceMode, bu as ExternalSourceRefresh, F as FunctionKind, Y as FunctionVisibility, Z as GeoBoundingBox, _ as GeoFilterBuilder, $ as GeoIndexDefinition, a0 as GeoPointInput, G as GlobalBackend, a1 as IndexDefinition, a2 as IndexRangeBuilder, I as InferArgs, K as KeyedRelationDefinition, C as LifecycleEvent, a3 as LifecycleEventKind, a4 as LogFields, a5 as LunoraLogMethod, a6 as LunoraLogger, a7 as LunoraMetrics, L as LunoraTracer, a8 as LunoraWideEvent, M as MutationCtx, a9 as MutationStorage, O as OnDeleteAction, aa as PaginationOptions, ab as PaginationResult, ac as PatchIfResult, Q as QueryCtx, y as RankIndexDefinition, ad as RankSortKey, ae as ReadOnlyStorage, R as RegisteredAction, k as RegisteredFunction, c as RegisteredInternalAction, d as RegisteredInternalMutation, e as RegisteredInternalQuery, g as RegisteredInternalStream, J as RegisteredLifecycleHook, h as RegisteredMutation, i as RegisteredQuery, j as RegisteredStream, af as RelatedDirection, ag as RelatedNode, ah as RelatedOptions, ai as RelatedPage, aj as RelatedStart, ak as RelatedStartReference, o as RelationDefinition, m as RelationThrough, al as RestCacheConfig, am as RetryPolicy, an as RunQueryOptions, ao as ScheduleRunOptions, ap as ScheduledFunctionDoc, aq as ScheduledJob, ar as ScheduledJobState, as as ScheduledJobView, at as Scheduler, S as Schema, au as SearchFilterBuilder, av as SearchIndexDefinition, p as SearchLanguage, q as SearchStrategy, z as Secrets, bv as SecretsStoreSecretLike, H as ShardInitEvent, aw as ShardMode, ax as SpanContextIds, ay as SpanEvaluation, a as SpanHandle, az as SpanIdentity, aA as SpanKind, aB as SpanLink, aC as SpanOptions, aD as Storage, aE as StorageListOptions, aF as StorageListResult, aG as StorageMetadata, aH as StorageMultipartUpload, aI as StorageMultipartUploadOptions, aJ as StorageObjectBody, aK as StorageObjectHead, aL as StorageRange, aM as StorageUploadBody, aN as StorageUploadOptions, aO as StorageUploadResult, aP as StorageUploadedPart, aQ as SystemDatabaseReader, aR as SystemDoc, aS as SystemQuery, aT as SystemTableName, T as TableDefinition, aU as TableReader, aV as TableVectorIndex, n as ThroughRelationDefinition, aW as TriggerAggregateOptions, s as TriggerBuilder, aX as TriggerCtx, aY as TriggerDatabase, t as TriggerDefinition, aZ as TriggerDeleteEvent, a_ as TriggerEvent, a$ as TriggerGroupByEntry, b0 as TriggerGroupByOptions, b1 as TriggerHandler, b2 as TriggerInsertEvent, b3 as TriggerOp, b4 as TriggerQueryArgs, b5 as TriggerQueryPage, b6 as TriggerRankOptions, b7 as TriggerRankPageOptions, b8 as TriggerRankResult, b9 as TriggerRow, ba as TriggerTiming, bb as TriggerUpdateEvent, bc as TtlDefinition, u as VectorEmbedder, V as VectorIndexDefinition, bd as VectorMatch, be as VectorMatches, v as VectorMetric, bf as VectorQueryInput, bg as VectorRecord, bh as VectorSearch, bi as VectorSearchReader, bj as VectorUpsertInput, W as WhisperEvent, bk as WorkflowCreateOptions, bl as WorkflowEventDefinition, bm as WorkflowHandle, bn as WorkflowInstance, bo as WorkflowInstanceEvent, bp as WorkflowInstanceStatus, bq as WorkflowStatusResult, br as Workflows, X as X402ProcedureConfig } from "./packem_shared/types.d--zaGh3rX.js";
2
2
  import '@lunora/values';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/server",
3
- "version": "1.0.0-alpha.282",
3
+ "version": "1.0.0-alpha.283",
4
4
  "description": "Server primitives for Lunora: defineSchema, defineTable, query, mutation, and action",
5
5
  "keywords": [
6
6
  "backend",
@@ -73,7 +73,7 @@
73
73
  },
74
74
  "dependencies": {
75
75
  "@lunora/errors": ">=1.0.0-alpha.77 <2.0.0-0",
76
- "@lunora/scheduler": "^1.0.0-alpha.173",
76
+ "@lunora/scheduler": "^1.0.0-alpha.175",
77
77
  "@lunora/shard-engine": "^1.0.0-alpha.210",
78
78
  "@lunora/values": "^1.0.0-alpha.95",
79
79
  "@lunora/wire": "1.0.0-alpha.6",
@@ -1 +0,0 @@
1
- import{assertScheduleInstant as x,assertScheduleDelay as D,resolveScheduleId as O,assertDedupKey as S}from"@lunora/scheduler";import{encodeArgsOrThrow as $}from"@lunora/wire";const A=new WeakMap,m=o=>{if(typeof o=="string")return o;const n=o??{},e=n.__lunoraRef??n.binding;return typeof e=="string"?e:"<unknown>"},b=o=>{let n=o;for(;n!==void 0&&!n.open;)n=n.parent;return n},j=(o,n,e)=>o==="runAfter"?Math.max(n,e-Date.now()):Math.max(n,e),k=async(o,{id:n,run:e,token:r})=>{if(o?.handOff!==void 0){await o.handOff(n,e,r);return}await e(),o?.forget(n)},K=(o,n)=>{const e=o,r={decisions:new Map,innermost:void 0,outbox:n},l=(t,i,s,c,u)=>e[t].call(e,i,s,c,u),d=(t,i,s,c,u)=>{const h=m(s);r.decisions.has(h)||r.decisions.set(h,r.outbox?.admit(h));const g=r.decisions.get(h),p=g===void 0?i:j(t,i,g),w=r.innermost;if(w===void 0)return l(t,p,s,c,u);const a=O(u?.id),y={...u,dedupKey:S(u?.dedupKey)??`${a}-${crypto.randomUUID().replaceAll("-","")}`},v=r.outbox?.record(a,{args:$(`ctx.scheduler.${t}`,m(s),c),options:y,target:s,when:Math.ceil(t==="runAfter"?Date.now()+p:p)});return w.pending.push({id:a,run:async()=>l(t,p,s,c,{...y,id:a}),token:v}),Promise.resolve(a)},f={...e,runAfter:(t,i,s,c)=>(D(t,"ctx.scheduler.runAfter"),d("runAfter",t,i,s,c)),runAt:(t,i,s,c)=>(x(t,Date.now(),"ctx.scheduler.runAt"),d("runAt",t,i,s,c))};return Object.setPrototypeOf(f,Object.getPrototypeOf(e)),A.set(f,r),f},M=o=>{const{scheduler:n}=o,e=typeof n=="object"&&n!==null?A.get(n):void 0;if(!e)return async()=>{};const r={open:!0,parent:e.innermost,pending:[]};return e.innermost=r,async l=>{if(!r.open)return;r.open=!1,e.innermost===r&&(e.innermost=b(r.parent));const d=r.pending.splice(0);if(d.length===0)return;if(!l){for(const{id:c}of d)e.outbox?.forget(c);return}const f=b(r.parent);if(f!==void 0){f.pending.push(...d);return}const t=[];for(const c of d)try{await k(e.outbox,c)}catch(u){t.push(u)}const[i,...s]=t;if(i!==void 0)throw e.outbox?.wake(),s.length===0?i:new AggregateError(t,`ctx.scheduler: ${String(t.length)} of ${String(d.length)} deferred jobs failed to reach the scheduler after the commit`)}};export{M as beginDeferredSchedules,K as withDeferredSchedules};