pushq 1.1.0 → 1.2.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/README.md CHANGED
@@ -28,6 +28,7 @@ await pq.createTask("account-42", {
28
28
  delaySeconds: 3600, // or scheduleTime: new Date(...)
29
29
  taskId: "follow_up_abc", // optional: dedup (409 on collision)
30
30
  retry: { maxAttempts: 3 }, // per-task override of the queue config
31
+ // createQueue: { rateLimits: { maxDispatchesPerSecond: 10 } }, // create the queue if missing
31
32
  });
32
33
 
33
34
  // Operate queues at runtime
package/dist/index.cjs CHANGED
@@ -154,7 +154,8 @@ function taskCreateToWire(t) {
154
154
  schedule_time: schedule,
155
155
  delay_seconds: t.delaySeconds,
156
156
  dispatch_deadline_seconds: t.dispatchDeadlineSeconds,
157
- retry: retryToWire(t.retry)
157
+ retry: retryToWire(t.retry),
158
+ create_queue: t.createQueue ? queueConfigToWire(t.createQueue) : void 0
158
159
  }) ?? {};
159
160
  }
160
161
  function taskFromWire(w) {
@@ -264,10 +265,17 @@ var Pushq = class {
264
265
  async createTask(queue, task) {
265
266
  return taskFromWire(await this.request("POST", `/v1/queues/${enc(queue)}/tasks`, taskCreateToWire(task)));
266
267
  }
267
- /** Enqueue up to 500 tasks; non-atomic, per-item results in order. */
268
- async createTasks(queue, tasks) {
268
+ /**
269
+ * Enqueue up to 500 tasks; non-atomic, per-item results in order.
270
+ * `opts.createQueue` creates a missing queue, as on createTask.
271
+ */
272
+ async createTasks(queue, tasks, opts = {}) {
273
+ if (tasks.some((t) => t.createQueue !== void 0)) {
274
+ throw new Error("pushq: pass createQueue in createTasks' options, not on a task");
275
+ }
269
276
  const w = await this.request("POST", `/v1/queues/${enc(queue)}/tasks:batch`, {
270
- tasks: tasks.map(taskCreateToWire)
277
+ tasks: tasks.map(taskCreateToWire),
278
+ ...opts.createQueue ? { create_queue: queueConfigToWire(opts.createQueue) } : {}
271
279
  });
272
280
  return (w.results ?? []).map(batchResultFromWire);
273
281
  }
package/dist/index.d.cts CHANGED
@@ -96,6 +96,18 @@ interface TaskCreate {
96
96
  dispatchDeadlineSeconds?: number;
97
97
  /** Per-task override of the queue retry config (any subset). */
98
98
  retry?: RetryConfig;
99
+ /**
100
+ * Create the queue from this config if it doesn't exist yet. An existing
101
+ * queue is used unchanged: the config is never applied to it. `{}` creates
102
+ * the queue with server defaults. Not allowed on items of createTasks; pass
103
+ * it as createTasks' options instead.
104
+ */
105
+ createQueue?: QueueConfig;
106
+ }
107
+ /** Options for {@link Pushq.createTasks}. */
108
+ interface CreateTasksOptions {
109
+ /** Create the queue from this config if it doesn't exist, as on createTask. */
110
+ createQueue?: QueueConfig;
99
111
  }
100
112
  interface Task {
101
113
  id: string;
@@ -201,8 +213,11 @@ declare class Pushq {
201
213
  idPrefix?: string;
202
214
  }): Promise<QueueStats>;
203
215
  createTask(queue: string, task: TaskCreate): Promise<Task>;
204
- /** Enqueue up to 500 tasks; non-atomic, per-item results in order. */
205
- createTasks(queue: string, tasks: TaskCreate[]): Promise<BatchResult[]>;
216
+ /**
217
+ * Enqueue up to 500 tasks; non-atomic, per-item results in order.
218
+ * `opts.createQueue` creates a missing queue, as on createTask.
219
+ */
220
+ createTasks(queue: string, tasks: TaskCreate[], opts?: CreateTasksOptions): Promise<BatchResult[]>;
206
221
  getTask(queue: string, id: string, opts?: {
207
222
  view?: "basic" | "full";
208
223
  }): Promise<Task>;
@@ -239,4 +254,4 @@ declare function verifySignature(opts: VerifyOptions): Promise<string>;
239
254
  /** Computes a "v1,<base64>" signature (test/tooling helper). */
240
255
  declare function sign(secret: string, msgId: string, timestampSeconds: number, payload: string | Uint8Array): Promise<string>;
241
256
 
242
- export { type Attempt, type BatchResult, DEFAULT_BASE_URL, type ListQueuesParams, type ListTasksParams, type Page, Pushq, PushqError, type PushqOptions, type Queue, type QueueConfig, type QueuePatch, type QueueStats, type RateLimits, type RetryConfig, type Target, type Task, type TaskCreate, type VerifyOptions, WebhookVerificationError, sign, verifySignature };
257
+ export { type Attempt, type BatchResult, type CreateTasksOptions, DEFAULT_BASE_URL, type ListQueuesParams, type ListTasksParams, type Page, Pushq, PushqError, type PushqOptions, type Queue, type QueueConfig, type QueuePatch, type QueueStats, type RateLimits, type RetryConfig, type Target, type Task, type TaskCreate, type VerifyOptions, WebhookVerificationError, sign, verifySignature };
package/dist/index.d.ts CHANGED
@@ -96,6 +96,18 @@ interface TaskCreate {
96
96
  dispatchDeadlineSeconds?: number;
97
97
  /** Per-task override of the queue retry config (any subset). */
98
98
  retry?: RetryConfig;
99
+ /**
100
+ * Create the queue from this config if it doesn't exist yet. An existing
101
+ * queue is used unchanged: the config is never applied to it. `{}` creates
102
+ * the queue with server defaults. Not allowed on items of createTasks; pass
103
+ * it as createTasks' options instead.
104
+ */
105
+ createQueue?: QueueConfig;
106
+ }
107
+ /** Options for {@link Pushq.createTasks}. */
108
+ interface CreateTasksOptions {
109
+ /** Create the queue from this config if it doesn't exist, as on createTask. */
110
+ createQueue?: QueueConfig;
99
111
  }
100
112
  interface Task {
101
113
  id: string;
@@ -201,8 +213,11 @@ declare class Pushq {
201
213
  idPrefix?: string;
202
214
  }): Promise<QueueStats>;
203
215
  createTask(queue: string, task: TaskCreate): Promise<Task>;
204
- /** Enqueue up to 500 tasks; non-atomic, per-item results in order. */
205
- createTasks(queue: string, tasks: TaskCreate[]): Promise<BatchResult[]>;
216
+ /**
217
+ * Enqueue up to 500 tasks; non-atomic, per-item results in order.
218
+ * `opts.createQueue` creates a missing queue, as on createTask.
219
+ */
220
+ createTasks(queue: string, tasks: TaskCreate[], opts?: CreateTasksOptions): Promise<BatchResult[]>;
206
221
  getTask(queue: string, id: string, opts?: {
207
222
  view?: "basic" | "full";
208
223
  }): Promise<Task>;
@@ -239,4 +254,4 @@ declare function verifySignature(opts: VerifyOptions): Promise<string>;
239
254
  /** Computes a "v1,<base64>" signature (test/tooling helper). */
240
255
  declare function sign(secret: string, msgId: string, timestampSeconds: number, payload: string | Uint8Array): Promise<string>;
241
256
 
242
- export { type Attempt, type BatchResult, DEFAULT_BASE_URL, type ListQueuesParams, type ListTasksParams, type Page, Pushq, PushqError, type PushqOptions, type Queue, type QueueConfig, type QueuePatch, type QueueStats, type RateLimits, type RetryConfig, type Target, type Task, type TaskCreate, type VerifyOptions, WebhookVerificationError, sign, verifySignature };
257
+ export { type Attempt, type BatchResult, type CreateTasksOptions, DEFAULT_BASE_URL, type ListQueuesParams, type ListTasksParams, type Page, Pushq, PushqError, type PushqOptions, type Queue, type QueueConfig, type QueuePatch, type QueueStats, type RateLimits, type RetryConfig, type Target, type Task, type TaskCreate, type VerifyOptions, WebhookVerificationError, sign, verifySignature };
package/dist/index.js CHANGED
@@ -123,7 +123,8 @@ function taskCreateToWire(t) {
123
123
  schedule_time: schedule,
124
124
  delay_seconds: t.delaySeconds,
125
125
  dispatch_deadline_seconds: t.dispatchDeadlineSeconds,
126
- retry: retryToWire(t.retry)
126
+ retry: retryToWire(t.retry),
127
+ create_queue: t.createQueue ? queueConfigToWire(t.createQueue) : void 0
127
128
  }) ?? {};
128
129
  }
129
130
  function taskFromWire(w) {
@@ -233,10 +234,17 @@ var Pushq = class {
233
234
  async createTask(queue, task) {
234
235
  return taskFromWire(await this.request("POST", `/v1/queues/${enc(queue)}/tasks`, taskCreateToWire(task)));
235
236
  }
236
- /** Enqueue up to 500 tasks; non-atomic, per-item results in order. */
237
- async createTasks(queue, tasks) {
237
+ /**
238
+ * Enqueue up to 500 tasks; non-atomic, per-item results in order.
239
+ * `opts.createQueue` creates a missing queue, as on createTask.
240
+ */
241
+ async createTasks(queue, tasks, opts = {}) {
242
+ if (tasks.some((t) => t.createQueue !== void 0)) {
243
+ throw new Error("pushq: pass createQueue in createTasks' options, not on a task");
244
+ }
238
245
  const w = await this.request("POST", `/v1/queues/${enc(queue)}/tasks:batch`, {
239
- tasks: tasks.map(taskCreateToWire)
246
+ tasks: tasks.map(taskCreateToWire),
247
+ ...opts.createQueue ? { create_queue: queueConfigToWire(opts.createQueue) } : {}
240
248
  });
241
249
  return (w.results ?? []).map(batchResultFromWire);
242
250
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pushq",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Client for pushq — self-hosted HTTP push task queue (open-source Cloud Tasks alternative)",
5
5
  "license": "MIT",
6
6
  "repository": {