enqiu 0.1.2 → 0.4.0-beta.0
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/CHANGELOG.md +291 -0
- package/README.md +143 -235
- package/dist/api.d.ts +16 -236
- package/dist/api.js +383 -478
- package/dist/backend.d.ts +25 -0
- package/dist/backend.js +18 -0
- package/dist/definition.d.ts +13 -0
- package/dist/definition.js +51 -0
- package/dist/errors.d.ts +57 -0
- package/dist/errors.js +83 -0
- package/dist/events.d.ts +30 -0
- package/dist/events.js +53 -0
- package/dist/index.d.ts +4 -5
- package/dist/index.js +3 -3
- package/dist/mapping.d.ts +99 -0
- package/dist/mapping.js +167 -0
- package/dist/markers.d.ts +25 -0
- package/dist/markers.js +51 -0
- package/dist/runner.d.ts +20 -0
- package/dist/runner.js +101 -0
- package/dist/serialize.d.ts +15 -0
- package/dist/serialize.js +90 -0
- package/dist/types.d.ts +326 -0
- package/dist/types.js +9 -0
- package/package.json +24 -15
- package/dist/codec.d.ts +0 -8
- package/dist/codec.js +0 -74
- package/dist/cron.d.ts +0 -19
- package/dist/cron.js +0 -217
- package/dist/memory-scheduler.d.ts +0 -24
- package/dist/memory-scheduler.js +0 -163
- package/dist/memory.d.ts +0 -344
- package/dist/memory.js +0 -1201
- package/dist/redis.d.ts +0 -202
- package/dist/redis.js +0 -2180
package/dist/api.d.ts
CHANGED
|
@@ -1,236 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
readonly types?: {
|
|
18
|
-
readonly input: Input;
|
|
19
|
-
readonly output: Output;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
export interface StandardSchemaIssue {
|
|
24
|
-
readonly message: string;
|
|
25
|
-
readonly path?: ReadonlyArray<PropertyKey | {
|
|
26
|
-
readonly key: PropertyKey;
|
|
27
|
-
}>;
|
|
28
|
-
}
|
|
29
|
-
export type InferSchemaInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
30
|
-
export type InferSchemaOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
31
|
-
export interface Progress {
|
|
32
|
-
readonly completed: number;
|
|
33
|
-
readonly total: number;
|
|
34
|
-
readonly message?: string;
|
|
35
|
-
readonly details?: Readonly<Record<string, unknown>>;
|
|
36
|
-
}
|
|
37
|
-
export interface JobLogger {
|
|
38
|
-
debug(message: string, fields?: Readonly<Record<string, unknown>>): void;
|
|
39
|
-
info(message: string, fields?: Readonly<Record<string, unknown>>): void;
|
|
40
|
-
warn(message: string, fields?: Readonly<Record<string, unknown>>): void;
|
|
41
|
-
error(message: string, fields?: Readonly<Record<string, unknown>>): void;
|
|
42
|
-
}
|
|
43
|
-
export interface JobContext<Name extends string = string> {
|
|
44
|
-
readonly id: string;
|
|
45
|
-
readonly name: Name;
|
|
46
|
-
readonly attempt: number;
|
|
47
|
-
readonly signal: AbortSignal;
|
|
48
|
-
reportProgress(progress: Progress): Promise<void>;
|
|
49
|
-
readonly log: JobLogger;
|
|
50
|
-
}
|
|
51
|
-
export type JobHandler<Input = unknown, Output = unknown, Name extends string = string> = (input: Input, context: JobContext<Name>) => MaybePromise<Output>;
|
|
52
|
-
export interface RetryPolicy extends Omit<RetryOptions, "retries"> {
|
|
53
|
-
/** Total number of attempts, including the first. */
|
|
54
|
-
attempts: number;
|
|
55
|
-
}
|
|
56
|
-
export interface ConcurrencyPolicy<Input> {
|
|
57
|
-
limit: number;
|
|
58
|
-
by?: (input: Input) => string;
|
|
59
|
-
}
|
|
60
|
-
export interface ThrottlePolicy<Input> {
|
|
61
|
-
limit: number;
|
|
62
|
-
per: number;
|
|
63
|
-
burst?: number;
|
|
64
|
-
by?: (input: Input) => string;
|
|
65
|
-
}
|
|
66
|
-
export interface DebouncePolicy<Input> {
|
|
67
|
-
wait: number;
|
|
68
|
-
mode: "leading" | "trailing";
|
|
69
|
-
by: (input: Input) => string;
|
|
70
|
-
}
|
|
71
|
-
export interface JobPolicyOptions<Input> {
|
|
72
|
-
retry?: number | RetryPolicy;
|
|
73
|
-
timeout?: number;
|
|
74
|
-
expiresIn?: number;
|
|
75
|
-
concurrency?: number | ConcurrencyPolicy<Input>;
|
|
76
|
-
throttle?: ThrottlePolicy<Input>;
|
|
77
|
-
debounce?: DebouncePolicy<Input>;
|
|
78
|
-
}
|
|
79
|
-
export interface SchemaJobDefinition<Schema extends StandardSchemaV1 = StandardSchemaV1, Output = unknown> extends JobPolicyOptions<InferSchemaOutput<Schema>> {
|
|
80
|
-
readonly [definitionMarker]: true;
|
|
81
|
-
readonly input: Schema;
|
|
82
|
-
readonly run: JobHandler<InferSchemaOutput<Schema>, Output>;
|
|
83
|
-
}
|
|
84
|
-
export type HandlerJobDefinition<Input = unknown, Output = unknown> = JobHandler<Input, Output>;
|
|
85
|
-
export type JobDefinition = SchemaJobDefinition<StandardSchemaV1<unknown, unknown>, unknown> | HandlerJobDefinition<unknown, unknown>;
|
|
86
|
-
export type JobDefinitions = Record<string, JobDefinition>;
|
|
87
|
-
export declare function job<const Schema extends StandardSchemaV1, Output>(definition: Omit<SchemaJobDefinition<Schema, Output>, typeof definitionMarker>): SchemaJobDefinition<Schema, Output>;
|
|
88
|
-
type DefinitionInput<Definition> = Definition extends SchemaJobDefinition<infer Schema, unknown> ? InferSchemaInput<Schema> : Definition extends JobHandler<infer Input, unknown, string> ? Input : never;
|
|
89
|
-
type DefinitionRunInput<Definition> = Definition extends SchemaJobDefinition<infer Schema, unknown> ? InferSchemaOutput<Schema> : Definition extends JobHandler<infer Input, unknown, string> ? Input : never;
|
|
90
|
-
type DefinitionOutput<Definition> = Definition extends SchemaJobDefinition<StandardSchemaV1, infer Output> ? Awaited<Output> : Definition extends JobHandler<unknown, infer Output, string> ? Awaited<Output> : never;
|
|
91
|
-
export interface SubmitOptions {
|
|
92
|
-
id?: string;
|
|
93
|
-
idempotencyKey?: string;
|
|
94
|
-
/** Keep returning the same completed job for this duration. @default 24h */
|
|
95
|
-
idempotencyTtl?: number;
|
|
96
|
-
delay?: number | Date;
|
|
97
|
-
priority?: number | "low" | "normal" | "high";
|
|
98
|
-
retry?: number | RetryPolicy;
|
|
99
|
-
timeout?: number;
|
|
100
|
-
expiresIn?: number;
|
|
101
|
-
signal?: AbortSignal;
|
|
102
|
-
}
|
|
103
|
-
export interface BulkOptions extends Omit<SubmitOptions, "id"> {
|
|
104
|
-
ids?: readonly string[];
|
|
105
|
-
}
|
|
106
|
-
export interface ScheduleOptions<Input> {
|
|
107
|
-
id?: string;
|
|
108
|
-
cron: string;
|
|
109
|
-
timezone?: string;
|
|
110
|
-
input: Input;
|
|
111
|
-
catchUp?: boolean;
|
|
112
|
-
}
|
|
113
|
-
export interface ScheduleHandle {
|
|
114
|
-
readonly id: string;
|
|
115
|
-
readonly nextRunAt: number;
|
|
116
|
-
pause(): Promise<void>;
|
|
117
|
-
resume(): Promise<void>;
|
|
118
|
-
remove(): Promise<void>;
|
|
119
|
-
refresh(): Promise<ScheduleSnapshot>;
|
|
120
|
-
}
|
|
121
|
-
export interface ScheduleSnapshot {
|
|
122
|
-
id: string;
|
|
123
|
-
jobName: string;
|
|
124
|
-
cron: string;
|
|
125
|
-
timezone: string;
|
|
126
|
-
status: "active" | "paused";
|
|
127
|
-
nextRunAt: number;
|
|
128
|
-
input: unknown;
|
|
129
|
-
catchUp: boolean;
|
|
130
|
-
}
|
|
131
|
-
export interface JobHandle<Output = unknown, Input = unknown, Name extends string = string> {
|
|
132
|
-
readonly id: string;
|
|
133
|
-
readonly name: Name;
|
|
134
|
-
readonly input: Input;
|
|
135
|
-
readonly status: JobStatus;
|
|
136
|
-
readonly deduplicated: boolean;
|
|
137
|
-
readonly result: Promise<Output>;
|
|
138
|
-
cancel(reason?: string): Promise<boolean>;
|
|
139
|
-
refresh(): Promise<JobSnapshot<Input, Output, Name>>;
|
|
140
|
-
}
|
|
141
|
-
export interface JobCallable<Input, RunInput, Output, Name extends string, Schema extends StandardSchemaV1 | undefined = undefined> {
|
|
142
|
-
(input: Input, options?: SubmitOptions): Promise<JobHandle<Output, RunInput, Name>>;
|
|
143
|
-
bulk(inputs: readonly Input[], options?: BulkOptions): Promise<Array<JobHandle<Output, RunInput, Name>>>;
|
|
144
|
-
schedule(options: ScheduleOptions<Input>): Promise<ScheduleHandle>;
|
|
145
|
-
readonly input: Schema;
|
|
146
|
-
}
|
|
147
|
-
type DefinitionSchema<Definition> = Definition extends SchemaJobDefinition<infer Schema, unknown> ? Schema : undefined;
|
|
148
|
-
export type JobsApi<Definitions extends JobDefinitions> = {
|
|
149
|
-
readonly [Name in keyof Definitions]: JobCallable<DefinitionInput<Definitions[Name]>, DefinitionRunInput<Definitions[Name]>, DefinitionOutput<Definitions[Name]>, Extract<Name, string>, DefinitionSchema<Definitions[Name]>>;
|
|
150
|
-
} & {
|
|
151
|
-
readonly queue: QueueApi<Definitions>;
|
|
152
|
-
readonly worker: WorkerApi;
|
|
153
|
-
};
|
|
154
|
-
export type AnyJobSnapshot<Definitions extends JobDefinitions> = {
|
|
155
|
-
[Name in keyof Definitions]: JobSnapshot<DefinitionRunInput<Definitions[Name]>, DefinitionOutput<Definitions[Name]>, Extract<Name, string>>;
|
|
156
|
-
}[keyof Definitions];
|
|
157
|
-
export interface JobListQuery {
|
|
158
|
-
status?: JobStatus;
|
|
159
|
-
name?: string;
|
|
160
|
-
before?: number;
|
|
161
|
-
after?: number;
|
|
162
|
-
limit?: number;
|
|
163
|
-
cursor?: string;
|
|
164
|
-
}
|
|
165
|
-
export interface JobListPage<Job = JobSnapshot> {
|
|
166
|
-
jobs: Job[];
|
|
167
|
-
cursor?: string;
|
|
168
|
-
}
|
|
169
|
-
export interface CleanupQuery {
|
|
170
|
-
status?: JobStatus | readonly JobStatus[];
|
|
171
|
-
olderThan?: number;
|
|
172
|
-
limit?: number;
|
|
173
|
-
}
|
|
174
|
-
export interface QueueApi<Definitions extends JobDefinitions> {
|
|
175
|
-
get(id: string): Promise<AnyJobSnapshot<Definitions> | undefined>;
|
|
176
|
-
list(query?: JobListQuery): Promise<JobListPage<AnyJobSnapshot<Definitions>>>;
|
|
177
|
-
stats(): Promise<QueueStats>;
|
|
178
|
-
pause(): Promise<void>;
|
|
179
|
-
resume(): Promise<void>;
|
|
180
|
-
setConcurrency(limit: number): Promise<void>;
|
|
181
|
-
redrive(id: string): Promise<JobHandle>;
|
|
182
|
-
cleanup(query?: CleanupQuery): Promise<string[]>;
|
|
183
|
-
on<Event extends keyof QueueEventMap>(event: Event, listener: (payload: QueueEventMap[Event]) => void): () => void;
|
|
184
|
-
}
|
|
185
|
-
export interface WorkerStartOptions {
|
|
186
|
-
concurrency?: number;
|
|
187
|
-
}
|
|
188
|
-
export interface WorkerApi {
|
|
189
|
-
readonly running: boolean;
|
|
190
|
-
start(options?: WorkerStartOptions): Promise<void>;
|
|
191
|
-
pause(): Promise<void>;
|
|
192
|
-
resume(): Promise<void>;
|
|
193
|
-
onIdle(): Promise<void>;
|
|
194
|
-
close(options?: {
|
|
195
|
-
drain?: boolean;
|
|
196
|
-
}): Promise<void>;
|
|
197
|
-
}
|
|
198
|
-
export interface WorkerOptions {
|
|
199
|
-
concurrency?: number;
|
|
200
|
-
autoStart?: boolean;
|
|
201
|
-
}
|
|
202
|
-
export interface TelemetryEvent {
|
|
203
|
-
readonly type: string;
|
|
204
|
-
readonly queue: string;
|
|
205
|
-
readonly timestamp: number;
|
|
206
|
-
readonly job?: JobSnapshot;
|
|
207
|
-
readonly fields?: Readonly<Record<string, unknown>>;
|
|
208
|
-
}
|
|
209
|
-
export interface Telemetry {
|
|
210
|
-
emit(event: TelemetryEvent): void;
|
|
211
|
-
}
|
|
212
|
-
export interface SharedEnqiuOptions {
|
|
213
|
-
name?: string;
|
|
214
|
-
worker?: false | WorkerOptions;
|
|
215
|
-
retry?: number | RetryPolicy;
|
|
216
|
-
timeout?: number;
|
|
217
|
-
historyLimit?: number;
|
|
218
|
-
logLimit?: number;
|
|
219
|
-
telemetry?: Telemetry;
|
|
220
|
-
}
|
|
221
|
-
export interface MemoryEnqiuOptions extends SharedEnqiuOptions {
|
|
222
|
-
driver?: undefined;
|
|
223
|
-
}
|
|
224
|
-
export interface RedisEnqiuOptions extends SharedEnqiuOptions {
|
|
225
|
-
driver: RedisDriver;
|
|
226
|
-
/** Redis processes must explicitly choose producer-only or worker mode. */
|
|
227
|
-
worker: false | WorkerOptions;
|
|
228
|
-
}
|
|
229
|
-
export type EnqiuOptions = MemoryEnqiuOptions | RedisEnqiuOptions;
|
|
230
|
-
export declare class JobValidationError extends TypeError {
|
|
231
|
-
readonly issues: readonly StandardSchemaIssue[];
|
|
232
|
-
constructor(name: string, issues: readonly StandardSchemaIssue[]);
|
|
233
|
-
}
|
|
234
|
-
export declare function enqiu<const Definitions extends JobDefinitions>(definitions: Definitions, options?: MemoryEnqiuOptions): JobsApi<Definitions>;
|
|
235
|
-
export declare function enqiu<const Definitions extends JobDefinitions>(definitions: Definitions, options: RedisEnqiuOptions): JobsApi<Definitions>;
|
|
236
|
-
export { JobCancelledError, JobExpiredError, JobFailedError, JobSerializationError, JobTimeoutError, QueueClosedError, };
|
|
1
|
+
/**
|
|
2
|
+
* `enqiu()` — a typed layer over BullMQ.
|
|
3
|
+
*
|
|
4
|
+
* Enqiu owns the developer experience: inferred job names, schema-validated
|
|
5
|
+
* input, and one object per job that you call like a function. BullMQ owns
|
|
6
|
+
* storage, scheduling and execution. Anything BullMQ's open-source tier cannot
|
|
7
|
+
* express is absent rather than faked, with two exceptions Enqiu enforces
|
|
8
|
+
* itself around the handler because they cost nothing to add: `timeout` and
|
|
9
|
+
* `expiresIn`.
|
|
10
|
+
*
|
|
11
|
+
* This file composes; the parts it composes live next to it.
|
|
12
|
+
*/
|
|
13
|
+
import type { Enqiu, EnqiuOptions, JobDefinitions } from "./types.js";
|
|
14
|
+
export { job } from "./definition.js";
|
|
15
|
+
/** Build a typed job API backed by a BullMQ queue. */
|
|
16
|
+
export declare function enqiu<const Definitions extends JobDefinitions>(definitions: Definitions, options: EnqiuOptions): Enqiu<Definitions>;
|