@lunora/scheduler 1.0.0-alpha.45 → 1.0.0-alpha.46

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/README.md CHANGED
@@ -83,7 +83,7 @@ import { api } from "@/lunora/_generated/api";
83
83
 
84
84
  const scheduler = createScheduler({ namespace: env.SCHEDULER, originUrl: "https://app.acme.test" });
85
85
 
86
- const { id } = await scheduler.runAfter(5 * 60_000, api.email.sendReminder, { userId: "u-1" });
86
+ const id = await scheduler.runAfter(5 * 60_000, api.email.sendReminder, { userId: "u-1" });
87
87
  await scheduler.cancel(id);
88
88
  ```
89
89
 
package/dist/index.d.mts CHANGED
@@ -172,16 +172,24 @@ interface Scheduler {
172
172
  * `agents.<name>` ref — which starts a fresh instance on fire (args become
173
173
  * its `params`). {@link ScheduleTargetArgs} infers the accepted args from
174
174
  * whichever target was passed.
175
+ *
176
+ * **Resolves the job id, a bare string** — the same value `cancel`/`get`
177
+ * take, and the same value the `ctx.scheduler` surface promises. This object
178
+ * IS `ctx.scheduler` on the shard side (codegen installs it behind
179
+ * `SchedulerLike`, whose `runAfter`/`runAt` are declared `Promise<string>`),
180
+ * so resolving a `{ id, scheduledFor }` record here handed mutations an
181
+ * object where every other gate — `@lunora/server`'s `Scheduler`,
182
+ * `@lunora/shard-engine`'s `SchedulerLike`, `@lunora/runtime`'s httpAction
183
+ * ctx, and the docs — said string. Nothing caught it, because the install is
184
+ * a cast: apps wrote the object into a string column and `cancel(id)`
185
+ * answered `{ cancelled: false }` with no error anywhere.
186
+ *
187
+ * The fire instant is not lost: `runAt` was handed it, and a caller that
188
+ * needs it back reads `scheduledFor` off {@link Scheduler.get}.
175
189
  */
176
- runAfter: <T extends CronTarget>(delayMs: number, target: T, args: ScheduleTargetArgs<T>, options?: RunOptions) => Promise<{
177
- id: string;
178
- scheduledFor: number;
179
- }>;
180
- /** Like {@link Scheduler.runAfter} but fires at an absolute `date`/timestamp. */
181
- runAt: <T extends CronTarget>(date: Date | number, target: T, args: ScheduleTargetArgs<T>, options?: RunOptions) => Promise<{
182
- id: string;
183
- scheduledFor: number;
184
- }>;
190
+ runAfter: <T extends CronTarget>(delayMs: number, target: T, args: ScheduleTargetArgs<T>, options?: RunOptions) => Promise<string>;
191
+ /** Like {@link Scheduler.runAfter} but fires at an absolute `date`/timestamp. Resolves the job id. */
192
+ runAt: <T extends CronTarget>(date: Date | number, target: T, args: ScheduleTargetArgs<T>, options?: RunOptions) => Promise<string>;
185
193
  }
186
194
  /**
187
195
  * Cloudflare Durable Object data-residency jurisdiction. Widening union —
package/dist/index.d.ts CHANGED
@@ -172,16 +172,24 @@ interface Scheduler {
172
172
  * `agents.<name>` ref — which starts a fresh instance on fire (args become
173
173
  * its `params`). {@link ScheduleTargetArgs} infers the accepted args from
174
174
  * whichever target was passed.
175
+ *
176
+ * **Resolves the job id, a bare string** — the same value `cancel`/`get`
177
+ * take, and the same value the `ctx.scheduler` surface promises. This object
178
+ * IS `ctx.scheduler` on the shard side (codegen installs it behind
179
+ * `SchedulerLike`, whose `runAfter`/`runAt` are declared `Promise<string>`),
180
+ * so resolving a `{ id, scheduledFor }` record here handed mutations an
181
+ * object where every other gate — `@lunora/server`'s `Scheduler`,
182
+ * `@lunora/shard-engine`'s `SchedulerLike`, `@lunora/runtime`'s httpAction
183
+ * ctx, and the docs — said string. Nothing caught it, because the install is
184
+ * a cast: apps wrote the object into a string column and `cancel(id)`
185
+ * answered `{ cancelled: false }` with no error anywhere.
186
+ *
187
+ * The fire instant is not lost: `runAt` was handed it, and a caller that
188
+ * needs it back reads `scheduledFor` off {@link Scheduler.get}.
175
189
  */
176
- runAfter: <T extends CronTarget>(delayMs: number, target: T, args: ScheduleTargetArgs<T>, options?: RunOptions) => Promise<{
177
- id: string;
178
- scheduledFor: number;
179
- }>;
180
- /** Like {@link Scheduler.runAfter} but fires at an absolute `date`/timestamp. */
181
- runAt: <T extends CronTarget>(date: Date | number, target: T, args: ScheduleTargetArgs<T>, options?: RunOptions) => Promise<{
182
- id: string;
183
- scheduledFor: number;
184
- }>;
190
+ runAfter: <T extends CronTarget>(delayMs: number, target: T, args: ScheduleTargetArgs<T>, options?: RunOptions) => Promise<string>;
191
+ /** Like {@link Scheduler.runAfter} but fires at an absolute `date`/timestamp. Resolves the job id. */
192
+ runAt: <T extends CronTarget>(date: Date | number, target: T, args: ScheduleTargetArgs<T>, options?: RunOptions) => Promise<string>;
185
193
  }
186
194
  /**
187
195
  * Cloudflare Durable Object data-residency jurisdiction. Widening union —
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{default as o}from"./packem_shared/createScheduler-Bh_lfToR.mjs";import{default as a}from"./packem_shared/createWorkpool-d3THj5gc.mjs";import{createCronTrigger as c}from"./packem_shared/createCronTrigger-DSuDZtqj.mjs";import{CRON_SCHEDULE_KINDS as f,compileCronSchedule as l,cronJobs as n}from"./packem_shared/CRON_SCHEDULE_KINDS-xyFk800s.mjs";import{createQueueConsumer as u,createQueueWorkpool as x,httpDispatcher as d}from"./packem_shared/createQueueConsumer-adiyW-4L.mjs";import{MAX_RETRY_ATTEMPTS as S,RETRY_BASE_DELAY_MS as E,SchedulerDO as C}from"./packem_shared/MAX_RETRY_ATTEMPTS-D24I8zY0.mjs";import{createSchedulerHost as h}from"./packem_shared/createSchedulerHost-BnNZ3raF.mjs";import{isWorkflowReference as T}from"./packem_shared/isWorkflowReference-CT3tdefh.mjs";import{assertValidCronExpression as A,isValidCronExpression as g,warnIfSecondsLeading as k}from"./packem_shared/assertValidCronExpression-DnBtukpq.mjs";export{f as CRON_SCHEDULE_KINDS,S as MAX_RETRY_ATTEMPTS,E as RETRY_BASE_DELAY_MS,C as SchedulerDO,A as assertValidCronExpression,l as compileCronSchedule,c as createCronTrigger,u as createQueueConsumer,x as createQueueWorkpool,o as createScheduler,h as createSchedulerHost,a as createWorkpool,n as cronJobs,d as httpDispatcher,g as isValidCronExpression,T as isWorkflowReference,k as warnIfSecondsLeading};
1
+ import{default as o}from"./packem_shared/createScheduler-CW8pPy0j.mjs";import{default as a}from"./packem_shared/createWorkpool-d3THj5gc.mjs";import{createCronTrigger as c}from"./packem_shared/createCronTrigger-DSuDZtqj.mjs";import{CRON_SCHEDULE_KINDS as f,compileCronSchedule as l,cronJobs as n}from"./packem_shared/CRON_SCHEDULE_KINDS-xyFk800s.mjs";import{createQueueConsumer as u,createQueueWorkpool as x,httpDispatcher as d}from"./packem_shared/createQueueConsumer-adiyW-4L.mjs";import{MAX_RETRY_ATTEMPTS as S,RETRY_BASE_DELAY_MS as E,SchedulerDO as C}from"./packem_shared/MAX_RETRY_ATTEMPTS-D24I8zY0.mjs";import{createSchedulerHost as h}from"./packem_shared/createSchedulerHost-B-5nnRt8.mjs";import{isWorkflowReference as T}from"./packem_shared/isWorkflowReference-CT3tdefh.mjs";import{assertValidCronExpression as A,isValidCronExpression as g,warnIfSecondsLeading as k}from"./packem_shared/assertValidCronExpression-DnBtukpq.mjs";export{f as CRON_SCHEDULE_KINDS,S as MAX_RETRY_ATTEMPTS,E as RETRY_BASE_DELAY_MS,C as SchedulerDO,A as assertValidCronExpression,l as compileCronSchedule,c as createCronTrigger,u as createQueueConsumer,x as createQueueWorkpool,o as createScheduler,h as createSchedulerHost,a as createWorkpool,n as cronJobs,d as httpDispatcher,g as isValidCronExpression,T as isWorkflowReference,k as warnIfSecondsLeading};
@@ -0,0 +1 @@
1
+ import{LunoraError as i}from"@lunora/errors";import{a as y,c as a,g as s}from"./do-client-BKEFA9pM.mjs";import{isWorkflowReference as f}from"./isWorkflowReference-CT3tdefh.mjs";const x=n=>{y(n);const d=async(e,r,t,c={})=>{const u=e instanceof Date?e.getTime():e,o={args:t,instanceName:n.instanceName??"default",maxConcurrency:c.pool===void 0?void 0:c.maxConcurrency,originUrl:n.originUrl,pool:c.pool,retry:c.retry,scheduledFor:u,shardKey:c.shardKey};if(f(r)){if(typeof r.binding!="string"||r.binding.length===0)throw new i("INTERNAL","@lunora/scheduler: workflow/agent schedule target is missing its `binding` — pass the generated `workflows.<name>` / `agents.<name>` reference");return(await a(n,"/schedule",{...o,workflow:r.binding})).id}const l=typeof r=="string"?r:r.__lunoraRef;return(await a(n,"/schedule",{...o,functionPath:l})).id};return{cancel:async e=>a(n,"/cancel",{id:e}),dead:async()=>{const e=await s(n,"/dead");return Array.isArray(e.records)?e.records:[]},deadRetry:async e=>{const{retried:r}=await a(n,"/dead/retry",{id:e});return r===!0},get:async e=>(await s(n,`/get?id=${encodeURIComponent(e)}`)).record??null,list:async()=>{const e=await s(n,"/list");return Array.isArray(e.records)?e.records:[]},runAfter:async(e,r,t,c={})=>{if(!Number.isFinite(e)||e<0)throw new i("INTERNAL","@lunora/scheduler: `delayMs` must be a non-negative finite number");return d(Date.now()+e,r,t,c)},runAt:d}};export{x as default};
@@ -1 +1 @@
1
- import d from"./createScheduler-Bh_lfToR.mjs";const u=t=>t?.at!==void 0?typeof t.at=="number"?t.at:t.at.getTime():Date.now()+(t?.delayMs??0),l=t=>{const a=d({instanceName:t.instanceName,jurisdiction:t.jurisdiction,namespace:t.namespace,originUrl:t.originUrl}),n=e=>({attempts:e.attempts??0,functionPath:e.functionPath??e.workflow??"",id:e.id,scheduledFor:e.scheduledFor});return{cancel:async e=>{const{cancelled:r}=await a.cancel(e);return r},deadLetter:{list:async()=>(await a.dead()).map(r=>n(r)),requeue:async e=>a.deadRetry(e)},list:async()=>(await a.list()).map(r=>n(r)),schedule:async(e,r,c)=>{const s=a.runAt;return s(u(c),e,r,{retry:c?.retry,shardKey:c?.shardKey})}}};export{l as createSchedulerHost};
1
+ import u from"./createScheduler-CW8pPy0j.mjs";const i=t=>t?.at!==void 0?typeof t.at=="number"?t.at:t.at.getTime():Date.now()+(t?.delayMs??0),m=t=>{const a=u({instanceName:t.instanceName,jurisdiction:t.jurisdiction,namespace:t.namespace,originUrl:t.originUrl}),n=e=>({attempts:e.attempts??0,functionPath:e.functionPath??e.workflow??"",id:e.id,scheduledFor:e.scheduledFor});return{cancel:async e=>{const{cancelled:r}=await a.cancel(e);return r},deadLetter:{list:async()=>(await a.dead()).map(r=>n(r)),requeue:async e=>a.deadRetry(e)},list:async()=>(await a.list()).map(r=>n(r)),schedule:async(e,r,c)=>{const d=a.runAt,s=i(c);return{id:await d(s,e,r,{retry:c?.retry,shardKey:c?.shardKey}),scheduledFor:s}}}};export{m as createSchedulerHost};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/scheduler",
3
- "version": "1.0.0-alpha.45",
3
+ "version": "1.0.0-alpha.46",
4
4
  "description": "Scheduling for Lunora: runAfter / runAt and Cron Triggers via SchedulerDO",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -46,8 +46,8 @@
46
46
  "access": "public"
47
47
  },
48
48
  "dependencies": {
49
- "@lunora/errors": "1.0.0-alpha.26",
50
- "@lunora/platform": "1.0.0-alpha.22",
49
+ "@lunora/errors": "1.0.0-alpha.27",
50
+ "@lunora/platform": "1.0.0-alpha.23",
51
51
  "cron-parser": "5.8.1"
52
52
  },
53
53
  "engines": {
@@ -1 +0,0 @@
1
- import{LunoraError as i}from"@lunora/errors";import{a as y,c,g as s}from"./do-client-BKEFA9pM.mjs";import{isWorkflowReference as f}from"./isWorkflowReference-CT3tdefh.mjs";const D=n=>{y(n);const o=async(e,r,t,a={})=>{const u=e instanceof Date?e.getTime():e,d={args:t,instanceName:n.instanceName??"default",maxConcurrency:a.pool===void 0?void 0:a.maxConcurrency,originUrl:n.originUrl,pool:a.pool,retry:a.retry,scheduledFor:u,shardKey:a.shardKey};if(f(r)){if(typeof r.binding!="string"||r.binding.length===0)throw new i("INTERNAL","@lunora/scheduler: workflow/agent schedule target is missing its `binding` — pass the generated `workflows.<name>` / `agents.<name>` reference");return c(n,"/schedule",{...d,workflow:r.binding})}const l=typeof r=="string"?r:r.__lunoraRef;return c(n,"/schedule",{...d,functionPath:l})};return{cancel:async e=>c(n,"/cancel",{id:e}),dead:async()=>{const e=await s(n,"/dead");return Array.isArray(e.records)?e.records:[]},deadRetry:async e=>{const{retried:r}=await c(n,"/dead/retry",{id:e});return r===!0},get:async e=>(await s(n,`/get?id=${encodeURIComponent(e)}`)).record??null,list:async()=>{const e=await s(n,"/list");return Array.isArray(e.records)?e.records:[]},runAfter:async(e,r,t,a={})=>{if(!Number.isFinite(e)||e<0)throw new i("INTERNAL","@lunora/scheduler: `delayMs` must be a non-negative finite number");return o(Date.now()+e,r,t,a)},runAt:o}};export{D as default};