@lunora/scheduler 1.0.0-alpha.46 → 1.0.0-alpha.47
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 +58 -22
- package/dist/index.d.ts +58 -22
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,21 +1,46 @@
|
|
|
1
1
|
import { SchedulerHost } from '@lunora/platform';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* direct dependency to keep this package usable from the codegen pipeline
|
|
6
|
-
* itself.
|
|
3
|
+
* The generated function-reference type, shared by every package that needs to
|
|
4
|
+
* infer a call's args or return from `api.<file>.<fn>`.
|
|
7
5
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* This lives in `shared/` rather than in one package because the consumers span
|
|
7
|
+
* a dependency boundary they must not cross: `@lunora/scheduler` and
|
|
8
|
+
* `@lunora/workflow` accept a reference in `runAfter`/`runAt`/`step.run*` but
|
|
9
|
+
* cannot depend on `@lunora/client`, which is a browser package. Each of them
|
|
10
|
+
* previously hand-copied this declaration, and both copies silently rotted when
|
|
11
|
+
* the phantom carrier was renamed — the conditional matched an OPTIONAL property
|
|
12
|
+
* that no longer existed, so `ArgsOf<F>` quietly resolved to `unknown` and every
|
|
13
|
+
* `step.run(ref, args)` in the repo lost its arg checking without a single error.
|
|
14
|
+
*
|
|
15
|
+
* `shared/` is the repo's answer to exactly that shape: bundler-inlined,
|
|
16
|
+
* zero-dependency source imported by relative path, so it creates no runtime
|
|
17
|
+
* edge between the packages that inline it. Being ONE declaration, there is
|
|
18
|
+
* nothing to keep in lockstep and no drift test to write.
|
|
10
19
|
*/
|
|
11
|
-
|
|
20
|
+
/** The registered function kinds a {@link FunctionReference} can describe. `stream` is a query that yields multiple frames over the WS. */
|
|
21
|
+
type FunctionKind = "action" | "mutation" | "query" | "stream";
|
|
22
|
+
/**
|
|
23
|
+
* Opaque reference to a registered function emitted by `@lunora/codegen`.
|
|
24
|
+
*
|
|
25
|
+
* At runtime it carries the `<file>:<function>` identifier in `__lunoraRef`.
|
|
26
|
+
* Generated declarations decorate this with phantom type parameters so callers
|
|
27
|
+
* can infer args / return values per call site.
|
|
28
|
+
*/
|
|
29
|
+
interface FunctionReference<Kind extends FunctionKind = FunctionKind, Args = unknown, Return = unknown> {
|
|
30
|
+
/**
|
|
31
|
+
* Phantom marker carrying the `Kind`/`Args`/`Return` type parameters for
|
|
32
|
+
* inference. Never present at runtime; declared as a covariant (output)
|
|
33
|
+
* position so a concrete reference stays assignable to a widened one.
|
|
34
|
+
*/
|
|
35
|
+
readonly __lunoraPhantom?: {
|
|
36
|
+
args: Args;
|
|
37
|
+
kind: Kind;
|
|
38
|
+
returns: Return;
|
|
39
|
+
};
|
|
12
40
|
readonly __lunoraRef: string;
|
|
13
|
-
/** Marker phantom type — discriminates queries / mutations / actions. */
|
|
14
|
-
readonly _kind?: "query" | "mutation" | "action";
|
|
15
41
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} ? A : Record<string, unknown>;
|
|
42
|
+
/** Extract the args type from a {@link FunctionReference}. */
|
|
43
|
+
type ArgsOf<F> = F extends FunctionReference<infer _K, infer A, infer _R> ? A : never;
|
|
19
44
|
/**
|
|
20
45
|
* Typed reference to a Lunora durable workflow — either the generated
|
|
21
46
|
* `workflows.<name>` reference object (`_generated/api.ts`, which carries the
|
|
@@ -42,19 +67,30 @@ interface WorkflowReference<Params = Record<string, unknown>> {
|
|
|
42
67
|
/** The workflow's export/stable name (present on a generated ref; a `defineWorkflow({ name })` override otherwise). */
|
|
43
68
|
readonly name?: string;
|
|
44
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* A function reference a scheduler or workpool may target.
|
|
72
|
+
*
|
|
73
|
+
* `stream` is excluded deliberately, and the exclusion is load-bearing rather
|
|
74
|
+
* than tidiness: a scheduled job is dispatched as an ordinary `/rpc` call, and
|
|
75
|
+
* the function runner cannot execute a stream function (see
|
|
76
|
+
* `create-worker.ts`'s registry note). Accepting one compiles a job that is
|
|
77
|
+
* guaranteed to fail when its alarm fires, long after the call site that
|
|
78
|
+
* scheduled it.
|
|
79
|
+
*/
|
|
80
|
+
type SchedulableReference<Args = unknown, Return = unknown> = FunctionReference<Exclude<FunctionKind, "stream">, Args, Return>;
|
|
45
81
|
/** A cron job's target: either a one-shot function dispatch or a durable workflow start. */
|
|
46
|
-
type CronTarget =
|
|
82
|
+
type CronTarget = SchedulableReference | WorkflowReference;
|
|
47
83
|
/** The arguments a cron's target accepts: a workflow's inferred `params`, else an open record (function args aren't inferred). */
|
|
48
84
|
type CronTargetArgs<T extends CronTarget> = T extends WorkflowReference<infer Params> ? Params : Record<string, unknown>;
|
|
49
85
|
/**
|
|
50
86
|
* The arguments a one-shot schedule target ({@link Scheduler.runAfter} /
|
|
51
|
-
* {@link Scheduler.runAt}) accepts. Unlike {@link CronTargetArgs} it
|
|
52
|
-
* {@link FunctionReference}'s
|
|
53
|
-
* {@link WorkflowReference}'s
|
|
54
|
-
*
|
|
55
|
-
* `params`.
|
|
87
|
+
* {@link Scheduler.runAt}) accepts. Unlike {@link CronTargetArgs} it resolves a
|
|
88
|
+
* {@link FunctionReference}'s `args` through {@link ArgsOf} as well as a
|
|
89
|
+
* {@link WorkflowReference}'s `params`, so scheduling a generated function
|
|
90
|
+
* reference is arg-checked against that function's validator while scheduling a
|
|
91
|
+
* workflow/agent is checked against its `params`.
|
|
56
92
|
*/
|
|
57
|
-
type ScheduleTargetArgs<T extends CronTarget> = T extends WorkflowReference<infer Params> ? Params : T extends
|
|
93
|
+
type ScheduleTargetArgs<T extends CronTarget> = T extends WorkflowReference<infer Params> ? Params : T extends SchedulableReference ? ArgsOf<T> : Record<string, unknown>;
|
|
58
94
|
/** Narrow a {@link CronTarget} to a {@link WorkflowReference} by its runtime brand. */
|
|
59
95
|
declare const isWorkflowReference: (target: unknown) => target is WorkflowReference;
|
|
60
96
|
/**
|
|
@@ -276,7 +312,7 @@ interface Workpool {
|
|
|
276
312
|
* and the time it was scheduled for (it may not run immediately if the pool
|
|
277
313
|
* is at capacity).
|
|
278
314
|
*/
|
|
279
|
-
enqueue: <F extends
|
|
315
|
+
enqueue: <F extends SchedulableReference>(function_: F, args: ArgsOf<F>, options?: EnqueueOptions) => Promise<{
|
|
280
316
|
id: string;
|
|
281
317
|
scheduledFor: number;
|
|
282
318
|
}>;
|
|
@@ -356,7 +392,7 @@ interface QueueWorkpoolOptions {
|
|
|
356
392
|
*/
|
|
357
393
|
interface QueueWorkpool {
|
|
358
394
|
/** Enqueue a single `fn(args)` dispatch. */
|
|
359
|
-
enqueue: <F extends
|
|
395
|
+
enqueue: <F extends SchedulableReference>(function_: F, args: ArgsOf<F>, options?: QueueEnqueueOptions) => Promise<void>;
|
|
360
396
|
/** Enqueue many dispatches in one `sendBatch`. Each job names its function `ref`. */
|
|
361
397
|
enqueueBatch: (jobs: ReadonlyArray<{
|
|
362
398
|
args?: Record<string, unknown>;
|
|
@@ -1013,4 +1049,4 @@ declare const warnIfSecondsLeading: (schedule: string, context: string) => void;
|
|
|
1013
1049
|
* {@link warnIfSecondsLeading}.
|
|
1014
1050
|
*/
|
|
1015
1051
|
declare const assertValidCronExpression: (schedule: string, context?: string) => void;
|
|
1016
|
-
export { type ArgsOf, CRON_SCHEDULE_KINDS, type CronJob, type CronJobsBuilder, type CronScheduleKind, type CronTarget, type CronTriggerOptions, type CronTriggerSnippet, type DailySchedule, type DurableObjectIdLike, type DurableObjectJurisdiction, type DurableObjectNamespaceLike, type DurableObjectStubLike, type EnqueueOptions, type FunctionReference, type HourlySchedule, type HttpDispatcherOptions, type IntervalSchedule, type LunoraSchedulerOptions, MAX_RETRY_ATTEMPTS, type MessageBatchLike, type MonthlySchedule, type QueueConsumerOptions, type QueueDispatch, type QueueEnqueueOptions, type QueueJob, type QueueLike, type QueueMessageLike, type QueueSendOptionsLike, type QueueSendRequestLike, type QueueWorkpool, type QueueWorkpoolOptions, RETRY_BASE_DELAY_MS, type RetryPolicy, type RunOptions, type ScheduleRecord, type Scheduler, SchedulerDO, type SchedulerDOState, type SchedulerEnv, type SchedulerHostOptions, type SchedulerPoolStatus, type SchedulerStatus, type WeeklySchedule, type WorkflowReference, type Workpool, type WorkpoolOptions, assertValidCronExpression, compileCronSchedule, createCronTrigger, createQueueConsumer, createQueueWorkpool, createScheduler, createSchedulerHost, createWorkpool, cronJobs, httpDispatcher, isValidCronExpression, isWorkflowReference, warnIfSecondsLeading };
|
|
1052
|
+
export { type ArgsOf, CRON_SCHEDULE_KINDS, type CronJob, type CronJobsBuilder, type CronScheduleKind, type CronTarget, type CronTriggerOptions, type CronTriggerSnippet, type DailySchedule, type DurableObjectIdLike, type DurableObjectJurisdiction, type DurableObjectNamespaceLike, type DurableObjectStubLike, type EnqueueOptions, type FunctionKind, type FunctionReference, type HourlySchedule, type HttpDispatcherOptions, type IntervalSchedule, type LunoraSchedulerOptions, MAX_RETRY_ATTEMPTS, type MessageBatchLike, type MonthlySchedule, type QueueConsumerOptions, type QueueDispatch, type QueueEnqueueOptions, type QueueJob, type QueueLike, type QueueMessageLike, type QueueSendOptionsLike, type QueueSendRequestLike, type QueueWorkpool, type QueueWorkpoolOptions, RETRY_BASE_DELAY_MS, type RetryPolicy, type RunOptions, type ScheduleRecord, type Scheduler, SchedulerDO, type SchedulerDOState, type SchedulerEnv, type SchedulerHostOptions, type SchedulerPoolStatus, type SchedulerStatus, type WeeklySchedule, type WorkflowReference, type Workpool, type WorkpoolOptions, assertValidCronExpression, compileCronSchedule, createCronTrigger, createQueueConsumer, createQueueWorkpool, createScheduler, createSchedulerHost, createWorkpool, cronJobs, httpDispatcher, isValidCronExpression, isWorkflowReference, warnIfSecondsLeading };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,46 @@
|
|
|
1
1
|
import { SchedulerHost } from '@lunora/platform';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* direct dependency to keep this package usable from the codegen pipeline
|
|
6
|
-
* itself.
|
|
3
|
+
* The generated function-reference type, shared by every package that needs to
|
|
4
|
+
* infer a call's args or return from `api.<file>.<fn>`.
|
|
7
5
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* This lives in `shared/` rather than in one package because the consumers span
|
|
7
|
+
* a dependency boundary they must not cross: `@lunora/scheduler` and
|
|
8
|
+
* `@lunora/workflow` accept a reference in `runAfter`/`runAt`/`step.run*` but
|
|
9
|
+
* cannot depend on `@lunora/client`, which is a browser package. Each of them
|
|
10
|
+
* previously hand-copied this declaration, and both copies silently rotted when
|
|
11
|
+
* the phantom carrier was renamed — the conditional matched an OPTIONAL property
|
|
12
|
+
* that no longer existed, so `ArgsOf<F>` quietly resolved to `unknown` and every
|
|
13
|
+
* `step.run(ref, args)` in the repo lost its arg checking without a single error.
|
|
14
|
+
*
|
|
15
|
+
* `shared/` is the repo's answer to exactly that shape: bundler-inlined,
|
|
16
|
+
* zero-dependency source imported by relative path, so it creates no runtime
|
|
17
|
+
* edge between the packages that inline it. Being ONE declaration, there is
|
|
18
|
+
* nothing to keep in lockstep and no drift test to write.
|
|
10
19
|
*/
|
|
11
|
-
|
|
20
|
+
/** The registered function kinds a {@link FunctionReference} can describe. `stream` is a query that yields multiple frames over the WS. */
|
|
21
|
+
type FunctionKind = "action" | "mutation" | "query" | "stream";
|
|
22
|
+
/**
|
|
23
|
+
* Opaque reference to a registered function emitted by `@lunora/codegen`.
|
|
24
|
+
*
|
|
25
|
+
* At runtime it carries the `<file>:<function>` identifier in `__lunoraRef`.
|
|
26
|
+
* Generated declarations decorate this with phantom type parameters so callers
|
|
27
|
+
* can infer args / return values per call site.
|
|
28
|
+
*/
|
|
29
|
+
interface FunctionReference<Kind extends FunctionKind = FunctionKind, Args = unknown, Return = unknown> {
|
|
30
|
+
/**
|
|
31
|
+
* Phantom marker carrying the `Kind`/`Args`/`Return` type parameters for
|
|
32
|
+
* inference. Never present at runtime; declared as a covariant (output)
|
|
33
|
+
* position so a concrete reference stays assignable to a widened one.
|
|
34
|
+
*/
|
|
35
|
+
readonly __lunoraPhantom?: {
|
|
36
|
+
args: Args;
|
|
37
|
+
kind: Kind;
|
|
38
|
+
returns: Return;
|
|
39
|
+
};
|
|
12
40
|
readonly __lunoraRef: string;
|
|
13
|
-
/** Marker phantom type — discriminates queries / mutations / actions. */
|
|
14
|
-
readonly _kind?: "query" | "mutation" | "action";
|
|
15
41
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} ? A : Record<string, unknown>;
|
|
42
|
+
/** Extract the args type from a {@link FunctionReference}. */
|
|
43
|
+
type ArgsOf<F> = F extends FunctionReference<infer _K, infer A, infer _R> ? A : never;
|
|
19
44
|
/**
|
|
20
45
|
* Typed reference to a Lunora durable workflow — either the generated
|
|
21
46
|
* `workflows.<name>` reference object (`_generated/api.ts`, which carries the
|
|
@@ -42,19 +67,30 @@ interface WorkflowReference<Params = Record<string, unknown>> {
|
|
|
42
67
|
/** The workflow's export/stable name (present on a generated ref; a `defineWorkflow({ name })` override otherwise). */
|
|
43
68
|
readonly name?: string;
|
|
44
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* A function reference a scheduler or workpool may target.
|
|
72
|
+
*
|
|
73
|
+
* `stream` is excluded deliberately, and the exclusion is load-bearing rather
|
|
74
|
+
* than tidiness: a scheduled job is dispatched as an ordinary `/rpc` call, and
|
|
75
|
+
* the function runner cannot execute a stream function (see
|
|
76
|
+
* `create-worker.ts`'s registry note). Accepting one compiles a job that is
|
|
77
|
+
* guaranteed to fail when its alarm fires, long after the call site that
|
|
78
|
+
* scheduled it.
|
|
79
|
+
*/
|
|
80
|
+
type SchedulableReference<Args = unknown, Return = unknown> = FunctionReference<Exclude<FunctionKind, "stream">, Args, Return>;
|
|
45
81
|
/** A cron job's target: either a one-shot function dispatch or a durable workflow start. */
|
|
46
|
-
type CronTarget =
|
|
82
|
+
type CronTarget = SchedulableReference | WorkflowReference;
|
|
47
83
|
/** The arguments a cron's target accepts: a workflow's inferred `params`, else an open record (function args aren't inferred). */
|
|
48
84
|
type CronTargetArgs<T extends CronTarget> = T extends WorkflowReference<infer Params> ? Params : Record<string, unknown>;
|
|
49
85
|
/**
|
|
50
86
|
* The arguments a one-shot schedule target ({@link Scheduler.runAfter} /
|
|
51
|
-
* {@link Scheduler.runAt}) accepts. Unlike {@link CronTargetArgs} it
|
|
52
|
-
* {@link FunctionReference}'s
|
|
53
|
-
* {@link WorkflowReference}'s
|
|
54
|
-
*
|
|
55
|
-
* `params`.
|
|
87
|
+
* {@link Scheduler.runAt}) accepts. Unlike {@link CronTargetArgs} it resolves a
|
|
88
|
+
* {@link FunctionReference}'s `args` through {@link ArgsOf} as well as a
|
|
89
|
+
* {@link WorkflowReference}'s `params`, so scheduling a generated function
|
|
90
|
+
* reference is arg-checked against that function's validator while scheduling a
|
|
91
|
+
* workflow/agent is checked against its `params`.
|
|
56
92
|
*/
|
|
57
|
-
type ScheduleTargetArgs<T extends CronTarget> = T extends WorkflowReference<infer Params> ? Params : T extends
|
|
93
|
+
type ScheduleTargetArgs<T extends CronTarget> = T extends WorkflowReference<infer Params> ? Params : T extends SchedulableReference ? ArgsOf<T> : Record<string, unknown>;
|
|
58
94
|
/** Narrow a {@link CronTarget} to a {@link WorkflowReference} by its runtime brand. */
|
|
59
95
|
declare const isWorkflowReference: (target: unknown) => target is WorkflowReference;
|
|
60
96
|
/**
|
|
@@ -276,7 +312,7 @@ interface Workpool {
|
|
|
276
312
|
* and the time it was scheduled for (it may not run immediately if the pool
|
|
277
313
|
* is at capacity).
|
|
278
314
|
*/
|
|
279
|
-
enqueue: <F extends
|
|
315
|
+
enqueue: <F extends SchedulableReference>(function_: F, args: ArgsOf<F>, options?: EnqueueOptions) => Promise<{
|
|
280
316
|
id: string;
|
|
281
317
|
scheduledFor: number;
|
|
282
318
|
}>;
|
|
@@ -356,7 +392,7 @@ interface QueueWorkpoolOptions {
|
|
|
356
392
|
*/
|
|
357
393
|
interface QueueWorkpool {
|
|
358
394
|
/** Enqueue a single `fn(args)` dispatch. */
|
|
359
|
-
enqueue: <F extends
|
|
395
|
+
enqueue: <F extends SchedulableReference>(function_: F, args: ArgsOf<F>, options?: QueueEnqueueOptions) => Promise<void>;
|
|
360
396
|
/** Enqueue many dispatches in one `sendBatch`. Each job names its function `ref`. */
|
|
361
397
|
enqueueBatch: (jobs: ReadonlyArray<{
|
|
362
398
|
args?: Record<string, unknown>;
|
|
@@ -1013,4 +1049,4 @@ declare const warnIfSecondsLeading: (schedule: string, context: string) => void;
|
|
|
1013
1049
|
* {@link warnIfSecondsLeading}.
|
|
1014
1050
|
*/
|
|
1015
1051
|
declare const assertValidCronExpression: (schedule: string, context?: string) => void;
|
|
1016
|
-
export { type ArgsOf, CRON_SCHEDULE_KINDS, type CronJob, type CronJobsBuilder, type CronScheduleKind, type CronTarget, type CronTriggerOptions, type CronTriggerSnippet, type DailySchedule, type DurableObjectIdLike, type DurableObjectJurisdiction, type DurableObjectNamespaceLike, type DurableObjectStubLike, type EnqueueOptions, type FunctionReference, type HourlySchedule, type HttpDispatcherOptions, type IntervalSchedule, type LunoraSchedulerOptions, MAX_RETRY_ATTEMPTS, type MessageBatchLike, type MonthlySchedule, type QueueConsumerOptions, type QueueDispatch, type QueueEnqueueOptions, type QueueJob, type QueueLike, type QueueMessageLike, type QueueSendOptionsLike, type QueueSendRequestLike, type QueueWorkpool, type QueueWorkpoolOptions, RETRY_BASE_DELAY_MS, type RetryPolicy, type RunOptions, type ScheduleRecord, type Scheduler, SchedulerDO, type SchedulerDOState, type SchedulerEnv, type SchedulerHostOptions, type SchedulerPoolStatus, type SchedulerStatus, type WeeklySchedule, type WorkflowReference, type Workpool, type WorkpoolOptions, assertValidCronExpression, compileCronSchedule, createCronTrigger, createQueueConsumer, createQueueWorkpool, createScheduler, createSchedulerHost, createWorkpool, cronJobs, httpDispatcher, isValidCronExpression, isWorkflowReference, warnIfSecondsLeading };
|
|
1052
|
+
export { type ArgsOf, CRON_SCHEDULE_KINDS, type CronJob, type CronJobsBuilder, type CronScheduleKind, type CronTarget, type CronTriggerOptions, type CronTriggerSnippet, type DailySchedule, type DurableObjectIdLike, type DurableObjectJurisdiction, type DurableObjectNamespaceLike, type DurableObjectStubLike, type EnqueueOptions, type FunctionKind, type FunctionReference, type HourlySchedule, type HttpDispatcherOptions, type IntervalSchedule, type LunoraSchedulerOptions, MAX_RETRY_ATTEMPTS, type MessageBatchLike, type MonthlySchedule, type QueueConsumerOptions, type QueueDispatch, type QueueEnqueueOptions, type QueueJob, type QueueLike, type QueueMessageLike, type QueueSendOptionsLike, type QueueSendRequestLike, type QueueWorkpool, type QueueWorkpoolOptions, RETRY_BASE_DELAY_MS, type RetryPolicy, type RunOptions, type ScheduleRecord, type Scheduler, SchedulerDO, type SchedulerDOState, type SchedulerEnv, type SchedulerHostOptions, type SchedulerPoolStatus, type SchedulerStatus, type WeeklySchedule, type WorkflowReference, type Workpool, type WorkpoolOptions, assertValidCronExpression, compileCronSchedule, createCronTrigger, createQueueConsumer, createQueueWorkpool, createScheduler, createSchedulerHost, createWorkpool, cronJobs, httpDispatcher, isValidCronExpression, isWorkflowReference, warnIfSecondsLeading };
|