@zizq-labs/zizq 0.3.0 → 0.3.1

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
@@ -50,11 +50,11 @@ yarn add @zizq-labs/zizq
50
50
  Enqueueing a job.
51
51
 
52
52
  ```ts
53
- import { Client, enqueue } from "@zizq-labs/zizq";
53
+ import { Client } from "@zizq-labs/zizq";
54
54
 
55
55
  const client = new Client({ url: "http://localhost:7890" });
56
56
 
57
- await enqueue(client, {
57
+ await client.enqueue({
58
58
  type: "send_email",
59
59
  queue: "emails",
60
60
  payload: { to: "user@example.com" },
package/dist/client.d.ts CHANGED
@@ -34,8 +34,8 @@ import { type Dispatcher } from "undici";
34
34
  import { Job, JobPage, ErrorRecord, ErrorPage, CronGroup, CronEntry } from "./resources.ts";
35
35
  import { JobQuery, type JobQueryOptions } from "./query.ts";
36
36
  import { CronHandle } from "./cron.ts";
37
- export type { JobStatus, SortDirection, UniqueScope, BackoffConfig, RetentionConfig, EnqueueOptions, FailureOptions, UpdateJobOptions, Format, TakeOptions, ListJobsOptions, ListErrorsOptions, UpdateAllJobsOptions, JobFilter, DeleteAllJobsOptions, CronEntryInput, ReplaceCronGroupOptions, } from "./types.ts";
38
- import type { EnqueueOptions, FailureOptions, UpdateJobOptions, Format, TakeOptions, ListJobsOptions, ListErrorsOptions, UpdateAllJobsOptions, JobFilter, DeleteAllJobsOptions, CronEntryInput, ReplaceCronGroupOptions } from "./types.ts";
37
+ export type { JobStatus, SortDirection, UniqueScope, BackoffConfig, RetentionConfig, EnqueueOptions, EnqueueInput, FailureOptions, UpdateJobOptions, Format, TakeOptions, ListJobsOptions, ListErrorsOptions, UpdateAllJobsOptions, JobFilter, DeleteAllJobsOptions, CronEntryInput, ReplaceCronGroupOptions, } from "./types.ts";
38
+ import type { EnqueueOptions, EnqueueInput, FailureOptions, UpdateJobOptions, Format, TakeOptions, ListJobsOptions, ListErrorsOptions, UpdateAllJobsOptions, JobFilter, DeleteAllJobsOptions, CronEntryInput, ReplaceCronGroupOptions } from "./types.ts";
39
39
  export { Job, JobPage, ErrorRecord, ErrorPage, CronGroup, CronEntry, type JobData, type ErrorRecordData, type CronGroupData, type CronEntryData, } from "./resources.ts";
40
40
  /** Response shape for `GET /health`. */
41
41
  interface HealthResponse {
@@ -164,10 +164,14 @@ export declare class Client {
164
164
  /**
165
165
  * Enqueue a single job.
166
166
  *
167
+ * The `type` field accepts either a string job type name or a function
168
+ * reference with attached `zizqOptions`. When a function is provided,
169
+ * its `zizqOptions` supplies defaults for `queue`, `priority`, etc.
170
+ *
167
171
  * @returns The created job, including its server-assigned `id` and `status`.
168
172
  * @throws {ZizqError} If the server rejects the request (e.g. invalid queue name).
169
173
  *
170
- * @example
174
+ * @example String type
171
175
  * ```ts
172
176
  * const job = await client.enqueue({
173
177
  * type: "send_email",
@@ -175,22 +179,51 @@ export declare class Client {
175
179
  * payload: { to: "user@example.com" },
176
180
  * });
177
181
  * ```
182
+ *
183
+ * @example Function reference
184
+ * ```ts
185
+ * const job = await client.enqueue({
186
+ * type: sendEmail,
187
+ * payload: { to: "user@example.com" },
188
+ * });
189
+ * ```
178
190
  */
179
- enqueue(options: EnqueueOptions): Promise<Job>;
191
+ enqueue(input: EnqueueInput): Promise<Job>;
180
192
  /**
181
193
  * Enqueue multiple jobs in a single request.
182
194
  *
195
+ * Accepts the same input format as {@link enqueue}, including function
196
+ * references for the `type` field.
197
+ *
183
198
  * @returns An array of created jobs in the same order as the input.
184
199
  *
185
200
  * @example
186
201
  * ```ts
187
202
  * const jobs = await client.enqueueBulk([
188
- * { type: "send_email", queue: "emails", payload: { to: "a@b.com" } },
189
- * { type: "send_email", queue: "emails", payload: { to: "c@d.com" } },
203
+ * { type: sendEmail, payload: { to: "a@b.com" } },
204
+ * { type: "manual_job", queue: "ops", payload: {} },
190
205
  * ]);
191
206
  * ```
192
207
  */
193
- enqueueBulk(jobs: EnqueueOptions[]): Promise<Job[]>;
208
+ enqueueBulk(inputs: EnqueueInput[]): Promise<Job[]>;
209
+ /**
210
+ * Enqueue a single job using raw, fully-resolved options.
211
+ *
212
+ * Prefer {@link enqueue} for most use cases. This method is useful when
213
+ * you have already resolved function references or need direct control
214
+ * over the options object.
215
+ *
216
+ * @returns The created job, including its server-assigned `id` and `status`.
217
+ */
218
+ enqueueRaw(options: EnqueueOptions): Promise<Job>;
219
+ /**
220
+ * Enqueue multiple jobs using raw, fully-resolved options.
221
+ *
222
+ * Prefer {@link enqueueBulk} for most use cases.
223
+ *
224
+ * @returns An array of created jobs in the same order as the input.
225
+ */
226
+ enqueueBulkRaw(jobs: EnqueueOptions[]): Promise<Job[]>;
194
227
  /**
195
228
  * Acknowledge a job as successfully completed.
196
229
  *
package/dist/client.js CHANGED
@@ -37,6 +37,7 @@ import { encode as msgpackEncode, decode as msgpackDecode } from "@msgpack/msgpa
37
37
  import { Job, JobPage, ErrorRecord, ErrorPage, CronGroup, CronEntry, } from "./resources.js";
38
38
  import { JobQuery } from "./query.js";
39
39
  import { CronHandle } from "./cron.js";
40
+ import { resolveInput } from "./enqueue.js";
40
41
  // Re-export resource types so consumers can import from client.ts.
41
42
  export { Job, JobPage, ErrorRecord, ErrorPage, CronGroup, CronEntry, } from "./resources.js";
42
43
  /** Base error class for all Zizq errors. */
@@ -179,10 +180,14 @@ export class Client {
179
180
  /**
180
181
  * Enqueue a single job.
181
182
  *
183
+ * The `type` field accepts either a string job type name or a function
184
+ * reference with attached `zizqOptions`. When a function is provided,
185
+ * its `zizqOptions` supplies defaults for `queue`, `priority`, etc.
186
+ *
182
187
  * @returns The created job, including its server-assigned `id` and `status`.
183
188
  * @throws {ZizqError} If the server rejects the request (e.g. invalid queue name).
184
189
  *
185
- * @example
190
+ * @example String type
186
191
  * ```ts
187
192
  * const job = await client.enqueue({
188
193
  * type: "send_email",
@@ -190,25 +195,58 @@ export class Client {
190
195
  * payload: { to: "user@example.com" },
191
196
  * });
192
197
  * ```
198
+ *
199
+ * @example Function reference
200
+ * ```ts
201
+ * const job = await client.enqueue({
202
+ * type: sendEmail,
203
+ * payload: { to: "user@example.com" },
204
+ * });
205
+ * ```
193
206
  */
194
- async enqueue(options) {
195
- const api = enqueueToApi(options);
196
- return this.wrapJob(await this.handleResponse(await this.post("/jobs", api)));
207
+ async enqueue(input) {
208
+ return this.enqueueRaw(resolveInput(input));
197
209
  }
198
210
  /**
199
211
  * Enqueue multiple jobs in a single request.
200
212
  *
213
+ * Accepts the same input format as {@link enqueue}, including function
214
+ * references for the `type` field.
215
+ *
201
216
  * @returns An array of created jobs in the same order as the input.
202
217
  *
203
218
  * @example
204
219
  * ```ts
205
220
  * const jobs = await client.enqueueBulk([
206
- * { type: "send_email", queue: "emails", payload: { to: "a@b.com" } },
207
- * { type: "send_email", queue: "emails", payload: { to: "c@d.com" } },
221
+ * { type: sendEmail, payload: { to: "a@b.com" } },
222
+ * { type: "manual_job", queue: "ops", payload: {} },
208
223
  * ]);
209
224
  * ```
210
225
  */
211
- async enqueueBulk(jobs) {
226
+ async enqueueBulk(inputs) {
227
+ return this.enqueueBulkRaw(inputs.map(resolveInput));
228
+ }
229
+ /**
230
+ * Enqueue a single job using raw, fully-resolved options.
231
+ *
232
+ * Prefer {@link enqueue} for most use cases. This method is useful when
233
+ * you have already resolved function references or need direct control
234
+ * over the options object.
235
+ *
236
+ * @returns The created job, including its server-assigned `id` and `status`.
237
+ */
238
+ async enqueueRaw(options) {
239
+ const api = enqueueToApi(options);
240
+ return this.wrapJob(await this.handleResponse(await this.post("/jobs", api)));
241
+ }
242
+ /**
243
+ * Enqueue multiple jobs using raw, fully-resolved options.
244
+ *
245
+ * Prefer {@link enqueueBulk} for most use cases.
246
+ *
247
+ * @returns An array of created jobs in the same order as the input.
248
+ */
249
+ async enqueueBulkRaw(jobs) {
212
250
  const api = { jobs: jobs.map(enqueueToApi) };
213
251
  const data = await this.handleResponse(await this.post("/jobs/bulk", api));
214
252
  return data.jobs.map((j) => this.wrapJob(j));
package/dist/cron.d.ts CHANGED
@@ -8,8 +8,7 @@
8
8
  */
9
9
  import type { Client } from "./client.ts";
10
10
  import type { CronGroup, CronEntry } from "./resources.ts";
11
- import type { EnqueueOptions } from "./types.ts";
12
- import { type EnqueueInput } from "./enqueue.ts";
11
+ import type { EnqueueOptions, EnqueueInput } from "./types.ts";
13
12
  /**
14
13
  * A cron entry definition that accepts function references for the job type.
15
14
  *
package/dist/enqueue.d.ts CHANGED
@@ -1,120 +1,25 @@
1
- import { Client, type BackoffConfig, type EnqueueOptions, Job, type RetentionConfig, type UniqueScope } from "./client.ts";
2
- import type { JobFunction } from "./handler.ts";
3
- /**
4
- * Input for enqueueing a job.
5
- *
6
- * The `type` field accepts either a string job type name or a function
7
- * reference with optional attached `zizqOptions`. When a function is provided,
8
- * its `zizqOptions` supplies defaults for `queue`, `priority`, etc. These
9
- * defaults can be overridden by inputs specified at enqueue-time.
10
- *
11
- * When `type` is a string, `queue` is required in the inputs.
12
- *
13
- * @example Function reference
14
- * ```ts
15
- * await enqueue(client, { type: sendEmail, payload: { to: "a@b.com" } });
16
- * ```
17
- *
18
- * @example String type with explicit config
19
- * ```ts
20
- * await enqueue(client, {
21
- * type: "send_email",
22
- * queue: "emails",
23
- * payload: { to: "a@b.com" },
24
- * priority: 100,
25
- * });
26
- * ```
27
- */
28
- export interface EnqueueInput {
29
- /** Job type — a function reference or a string type name. */
30
- type: JobFunction | string;
31
- /** Arbitrary payload delivered to the worker. */
32
- payload: unknown;
33
- /**
34
- * Target queue name.
35
- *
36
- * Required when `type` is a string and no `zizqOptions.queue` default
37
- * is available.
38
- */
39
- queue?: string;
40
- /**
41
- * Priority (lower = higher priority).
42
- *
43
- * Valid range is 0 to 65536. Default: 32768.
44
- */
45
- priority?: number;
46
- /**
47
- * Timestamp (ms since epoch) when the job becomes eligible.
48
- *
49
- * When set to a future timestamp the job is created in the "scheduled"
50
- * status. Otherwise the job is created in the "ready" status.
51
- */
52
- readyAt?: number;
53
- /**
54
- * Per-job retry limit.
55
- *
56
- * When not set the server default value applies.
57
- */
58
- retryLimit?: number;
59
- /** Per-job backoff configuration. */
60
- backoff?: BackoffConfig;
61
- /** Per-job retention configuration. */
62
- retention?: RetentionConfig;
63
- /**
64
- * Unique key for enqueue-time deduplication.
65
- *
66
- * Requires a pro license on the server.
67
- *
68
- * The key is global across all queues and job types. Prefix with the job
69
- * type to make it unique per job type.
70
- */
71
- uniqueKey?: string;
72
- /** Uniqueness scope. Only valid when `uniqueKey` is set. */
73
- uniqueWhile?: UniqueScope;
74
- }
1
+ import type { EnqueueOptions, EnqueueInput } from "./types.ts";
2
+ import type { Client } from "./client.ts";
3
+ import type { Job } from "./resources.ts";
4
+ export type { EnqueueInput } from "./types.ts";
75
5
  /**
76
6
  * Enqueue a single job.
77
7
  *
8
+ * @deprecated Use `client.enqueue()` instead.
9
+ *
78
10
  * @param client - The Zizq client to use for the HTTP request.
79
11
  * @param input - Job type, payload, and optional configuration.
80
12
  * @returns The created job, including its server-assigned `id` and `status`.
81
- *
82
- * @example Function reference
83
- * ```ts
84
- * async function sendEmail(payload) { ... }
85
- * sendEmail.zizqOptions = { queue: "emails", priority: 100 };
86
- *
87
- * const job = await enqueue(client, {
88
- * type: sendEmail,
89
- * payload: { to: "user@example.com" },
90
- * });
91
- * ```
92
- *
93
- * @example String type
94
- * ```ts
95
- * const job = await enqueue(client, {
96
- * type: "send_email",
97
- * queue: "emails",
98
- * payload: { to: "user@example.com" },
99
- * });
100
- * ```
101
13
  */
102
14
  export declare function enqueue(client: Client, input: EnqueueInput): Promise<Job>;
103
15
  /**
104
16
  * Enqueue multiple jobs in a single request.
105
17
  *
18
+ * @deprecated Use `client.enqueueBulk()` instead.
19
+ *
106
20
  * @param client - The Zizq client to use for the HTTP request.
107
21
  * @param inputs - Array of job inputs.
108
22
  * @returns An array of created jobs in the same order as the input.
109
- *
110
- * @example
111
- * ```ts
112
- * const jobs = await enqueueBulk(client, [
113
- * { type: sendEmail, payload: { to: "a@b.com" } },
114
- * { type: sendEmail, payload: { to: "c@d.com" }, priority: 1 },
115
- * { type: "manual_job", queue: "ops", payload: {} },
116
- * ]);
117
- * ```
118
23
  */
119
24
  export declare function enqueueBulk(client: Client, inputs: EnqueueInput[]): Promise<Job[]>;
120
25
  /**
package/dist/enqueue.js CHANGED
@@ -3,51 +3,26 @@
3
3
  /**
4
4
  * Enqueue a single job.
5
5
  *
6
+ * @deprecated Use `client.enqueue()` instead.
7
+ *
6
8
  * @param client - The Zizq client to use for the HTTP request.
7
9
  * @param input - Job type, payload, and optional configuration.
8
10
  * @returns The created job, including its server-assigned `id` and `status`.
9
- *
10
- * @example Function reference
11
- * ```ts
12
- * async function sendEmail(payload) { ... }
13
- * sendEmail.zizqOptions = { queue: "emails", priority: 100 };
14
- *
15
- * const job = await enqueue(client, {
16
- * type: sendEmail,
17
- * payload: { to: "user@example.com" },
18
- * });
19
- * ```
20
- *
21
- * @example String type
22
- * ```ts
23
- * const job = await enqueue(client, {
24
- * type: "send_email",
25
- * queue: "emails",
26
- * payload: { to: "user@example.com" },
27
- * });
28
- * ```
29
11
  */
30
12
  export async function enqueue(client, input) {
31
- return client.enqueue(resolveInput(input));
13
+ return client.enqueue(input);
32
14
  }
33
15
  /**
34
16
  * Enqueue multiple jobs in a single request.
35
17
  *
18
+ * @deprecated Use `client.enqueueBulk()` instead.
19
+ *
36
20
  * @param client - The Zizq client to use for the HTTP request.
37
21
  * @param inputs - Array of job inputs.
38
22
  * @returns An array of created jobs in the same order as the input.
39
- *
40
- * @example
41
- * ```ts
42
- * const jobs = await enqueueBulk(client, [
43
- * { type: sendEmail, payload: { to: "a@b.com" } },
44
- * { type: sendEmail, payload: { to: "c@d.com" }, priority: 1 },
45
- * { type: "manual_job", queue: "ops", payload: {} },
46
- * ]);
47
- * ```
48
23
  */
49
24
  export async function enqueueBulk(client, inputs) {
50
- return client.enqueueBulk(inputs.map(resolveInput));
25
+ return client.enqueueBulk(inputs);
51
26
  }
52
27
  // --- Internal ---
53
28
  // Compute the unique key from a job function's ZizqOptions + payload.
package/dist/handler.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * @module
10
10
  */
11
- import type { BackoffConfig, EnqueueOptions, RetentionConfig, UniqueScope } from "./client.ts";
11
+ import type { BackoffConfig, EnqueueOptions, RetentionConfig, UniqueScope } from "./types.ts";
12
12
  import type { Job } from "./resources.ts";
13
13
  /**
14
14
  * Configuration that can be attached to a job function via `fn.zizqOptions`.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { Client, Job, JobPage, ErrorRecord, ErrorPage, CronGroup, CronEntry, ZizqError, ConnectionError, ResponseError, ClientError, NotFoundError, ServerError, } from "./client.ts";
2
2
  export type { ClientOptions, TlsOptions, } from "./client.ts";
3
- export type { JobStatus, SortDirection, UniqueScope, Format, BackoffConfig, RetentionConfig, EnqueueOptions, FailureOptions, UpdateJobOptions, TakeOptions, ListJobsOptions, ListErrorsOptions, UpdateAllJobsOptions, JobFilter, DeleteAllJobsOptions, CronEntryInput, ReplaceCronGroupOptions, } from "./types.ts";
3
+ export type { JobStatus, SortDirection, UniqueScope, Format, BackoffConfig, RetentionConfig, EnqueueOptions, EnqueueInput, FailureOptions, UpdateJobOptions, TakeOptions, ListJobsOptions, ListErrorsOptions, UpdateAllJobsOptions, JobFilter, DeleteAllJobsOptions, CronEntryInput, ReplaceCronGroupOptions, } from "./types.ts";
4
4
  export type { JobData, ErrorRecordData, CronEntryData, CronGroupData, } from "./resources.ts";
5
5
  export { Worker } from "./worker.ts";
6
6
  export type { WorkerOptions, Logger, RequestRetryOptions } from "./worker.ts";
@@ -11,5 +11,4 @@ export type { ErrorQueryOptions, JobQueryOptions } from "./query.ts";
11
11
  export { enqueue, enqueueBulk } from "./enqueue.ts";
12
12
  export { CronHandle, CronEntryHandle } from "./cron.ts";
13
13
  export type { CronEntryDefinition, RegisterCronOptions } from "./cron.ts";
14
- export type { EnqueueInput } from "./enqueue.ts";
15
14
  export { uniqueKey } from "./unique-key.ts";
package/dist/types.d.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @module
8
8
  */
9
+ import type { JobFunction } from "./handler.ts";
9
10
  /** Lifecycle status of a job. */
10
11
  export type JobStatus = "ready" | "in_flight" | "scheduled" | "completed" | "dead";
11
12
  /** Sort direction for paginated listings. */
@@ -242,3 +243,75 @@ export interface ReplaceCronGroupOptions {
242
243
  /** Named collection of entries present in this group. */
243
244
  entries: CronEntryInput[];
244
245
  }
246
+ /**
247
+ * Input for enqueueing a job.
248
+ *
249
+ * The `type` field accepts either a string job type name or a function
250
+ * reference with optional attached `zizqOptions`. When a function is provided,
251
+ * its `zizqOptions` supplies defaults for `queue`, `priority`, etc. These
252
+ * defaults can be overridden by inputs specified at enqueue-time.
253
+ *
254
+ * When `type` is a string, `queue` is required in the inputs.
255
+ *
256
+ * @example Function reference
257
+ * ```ts
258
+ * await client.enqueue({ type: sendEmail, payload: { to: "a@b.com" } });
259
+ * ```
260
+ *
261
+ * @example String type with explicit config
262
+ * ```ts
263
+ * await client.enqueue({
264
+ * type: "send_email",
265
+ * queue: "emails",
266
+ * payload: { to: "a@b.com" },
267
+ * priority: 100,
268
+ * });
269
+ * ```
270
+ */
271
+ export interface EnqueueInput {
272
+ /** Job type — a function reference or a string type name. */
273
+ type: JobFunction | string;
274
+ /** Arbitrary payload delivered to the worker. */
275
+ payload: unknown;
276
+ /**
277
+ * Target queue name.
278
+ *
279
+ * Required when `type` is a string and no `zizqOptions.queue` default
280
+ * is available.
281
+ */
282
+ queue?: string;
283
+ /**
284
+ * Priority (lower = higher priority).
285
+ *
286
+ * Valid range is 0 to 65536. Default: 32768.
287
+ */
288
+ priority?: number;
289
+ /**
290
+ * Timestamp (ms since epoch) when the job becomes eligible.
291
+ *
292
+ * When set to a future timestamp the job is created in the "scheduled"
293
+ * status. Otherwise the job is created in the "ready" status.
294
+ */
295
+ readyAt?: number;
296
+ /**
297
+ * Per-job retry limit.
298
+ *
299
+ * When not set the server default value applies.
300
+ */
301
+ retryLimit?: number;
302
+ /** Per-job backoff configuration. */
303
+ backoff?: BackoffConfig;
304
+ /** Per-job retention configuration. */
305
+ retention?: RetentionConfig;
306
+ /**
307
+ * Unique key for enqueue-time deduplication.
308
+ *
309
+ * Requires a pro license on the server.
310
+ *
311
+ * The key is global across all queues and job types. Prefix with the job
312
+ * type to make it unique per job type.
313
+ */
314
+ uniqueKey?: string;
315
+ /** Uniqueness scope. Only valid when `uniqueKey` is set. */
316
+ uniqueWhile?: UniqueScope;
317
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zizq-labs/zizq",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Node.js client for the Zizq job queue server",
5
5
  "homepage": "https://zizq.io",
6
6
  "repository": {