pushq 1.0.1 → 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 +2 -1
- package/dist/index.cjs +12 -4
- package/dist/index.d.cts +24 -4
- package/dist/index.d.ts +24 -4
- package/dist/index.js +12 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,10 +24,11 @@ await pq.upsertQueue("account-42", {
|
|
|
24
24
|
|
|
25
25
|
await pq.createTask("account-42", {
|
|
26
26
|
path: "/hooks/send-message", // resolved against the queue's baseUrl
|
|
27
|
-
jsonBody: { userId: 1 },
|
|
27
|
+
jsonBody: { userId: 1 }, // any JSON.stringify-able value: class instances, toJSON(), Zod output
|
|
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
|
-
/**
|
|
268
|
-
|
|
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
|
@@ -82,7 +82,12 @@ interface TaskCreate {
|
|
|
82
82
|
headers?: Record<string, string>;
|
|
83
83
|
/** Raw body bytes or string. Exclusive with jsonBody. POST/PUT/PATCH only. */
|
|
84
84
|
body?: Uint8Array | string;
|
|
85
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Request body as JSON, sent with Content-Type: application/json. Any value
|
|
87
|
+
* JSON.stringify accepts: plain objects, class instances (own enumerable
|
|
88
|
+
* fields), objects with toJSON(), values parsed by Zod/Valibot, etc.
|
|
89
|
+
* Exclusive with body.
|
|
90
|
+
*/
|
|
86
91
|
jsonBody?: unknown;
|
|
87
92
|
/** Exclusive with delaySeconds. */
|
|
88
93
|
scheduleTime?: Date | string;
|
|
@@ -91,6 +96,18 @@ interface TaskCreate {
|
|
|
91
96
|
dispatchDeadlineSeconds?: number;
|
|
92
97
|
/** Per-task override of the queue retry config (any subset). */
|
|
93
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;
|
|
94
111
|
}
|
|
95
112
|
interface Task {
|
|
96
113
|
id: string;
|
|
@@ -196,8 +213,11 @@ declare class Pushq {
|
|
|
196
213
|
idPrefix?: string;
|
|
197
214
|
}): Promise<QueueStats>;
|
|
198
215
|
createTask(queue: string, task: TaskCreate): Promise<Task>;
|
|
199
|
-
/**
|
|
200
|
-
|
|
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[]>;
|
|
201
221
|
getTask(queue: string, id: string, opts?: {
|
|
202
222
|
view?: "basic" | "full";
|
|
203
223
|
}): Promise<Task>;
|
|
@@ -234,4 +254,4 @@ declare function verifySignature(opts: VerifyOptions): Promise<string>;
|
|
|
234
254
|
/** Computes a "v1,<base64>" signature (test/tooling helper). */
|
|
235
255
|
declare function sign(secret: string, msgId: string, timestampSeconds: number, payload: string | Uint8Array): Promise<string>;
|
|
236
256
|
|
|
237
|
-
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
|
@@ -82,7 +82,12 @@ interface TaskCreate {
|
|
|
82
82
|
headers?: Record<string, string>;
|
|
83
83
|
/** Raw body bytes or string. Exclusive with jsonBody. POST/PUT/PATCH only. */
|
|
84
84
|
body?: Uint8Array | string;
|
|
85
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Request body as JSON, sent with Content-Type: application/json. Any value
|
|
87
|
+
* JSON.stringify accepts: plain objects, class instances (own enumerable
|
|
88
|
+
* fields), objects with toJSON(), values parsed by Zod/Valibot, etc.
|
|
89
|
+
* Exclusive with body.
|
|
90
|
+
*/
|
|
86
91
|
jsonBody?: unknown;
|
|
87
92
|
/** Exclusive with delaySeconds. */
|
|
88
93
|
scheduleTime?: Date | string;
|
|
@@ -91,6 +96,18 @@ interface TaskCreate {
|
|
|
91
96
|
dispatchDeadlineSeconds?: number;
|
|
92
97
|
/** Per-task override of the queue retry config (any subset). */
|
|
93
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;
|
|
94
111
|
}
|
|
95
112
|
interface Task {
|
|
96
113
|
id: string;
|
|
@@ -196,8 +213,11 @@ declare class Pushq {
|
|
|
196
213
|
idPrefix?: string;
|
|
197
214
|
}): Promise<QueueStats>;
|
|
198
215
|
createTask(queue: string, task: TaskCreate): Promise<Task>;
|
|
199
|
-
/**
|
|
200
|
-
|
|
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[]>;
|
|
201
221
|
getTask(queue: string, id: string, opts?: {
|
|
202
222
|
view?: "basic" | "full";
|
|
203
223
|
}): Promise<Task>;
|
|
@@ -234,4 +254,4 @@ declare function verifySignature(opts: VerifyOptions): Promise<string>;
|
|
|
234
254
|
/** Computes a "v1,<base64>" signature (test/tooling helper). */
|
|
235
255
|
declare function sign(secret: string, msgId: string, timestampSeconds: number, payload: string | Uint8Array): Promise<string>;
|
|
236
256
|
|
|
237
|
-
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
|
-
/**
|
|
237
|
-
|
|
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
|
}
|