@upstash/qstash 2.4.0 → 2.4.2
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 +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +73 -25
- package/dist/index.mjs +73 -25
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -550,12 +550,21 @@ declare class Client {
|
|
|
550
550
|
* Create, read or delete schedules.
|
|
551
551
|
*/
|
|
552
552
|
get schedules(): Schedules;
|
|
553
|
+
private processHeaders;
|
|
553
554
|
publish<TRequest extends PublishRequest>(req: TRequest): Promise<PublishResponse<TRequest>>;
|
|
554
555
|
/**
|
|
555
556
|
* publishJSON is a utility wrapper around `publish` that automatically serializes the body
|
|
556
557
|
* and sets the `Content-Type` header to `application/json`.
|
|
557
558
|
*/
|
|
558
559
|
publishJSON<TBody = unknown, TRequest extends PublishRequest<TBody> = PublishRequest<TBody>>(req: TRequest): Promise<PublishResponse<TRequest>>;
|
|
560
|
+
/**
|
|
561
|
+
* Batch publish messages to QStash.
|
|
562
|
+
*/
|
|
563
|
+
batch(req: PublishRequest[]): Promise<(PublishToUrlResponse | PublishToTopicResponse)[]>;
|
|
564
|
+
/**
|
|
565
|
+
* Batch publish messages to QStash, serializing each body to JSON.
|
|
566
|
+
*/
|
|
567
|
+
batchJSON<TBody = unknown, TRequest extends PublishRequest<TBody> = PublishRequest<TBody>>(req: TRequest[]): Promise<(PublishToUrlResponse | PublishToTopicResponse)[]>;
|
|
559
568
|
/**
|
|
560
569
|
* Retrieve your logs.
|
|
561
570
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -550,12 +550,21 @@ declare class Client {
|
|
|
550
550
|
* Create, read or delete schedules.
|
|
551
551
|
*/
|
|
552
552
|
get schedules(): Schedules;
|
|
553
|
+
private processHeaders;
|
|
553
554
|
publish<TRequest extends PublishRequest>(req: TRequest): Promise<PublishResponse<TRequest>>;
|
|
554
555
|
/**
|
|
555
556
|
* publishJSON is a utility wrapper around `publish` that automatically serializes the body
|
|
556
557
|
* and sets the `Content-Type` header to `application/json`.
|
|
557
558
|
*/
|
|
558
559
|
publishJSON<TBody = unknown, TRequest extends PublishRequest<TBody> = PublishRequest<TBody>>(req: TRequest): Promise<PublishResponse<TRequest>>;
|
|
560
|
+
/**
|
|
561
|
+
* Batch publish messages to QStash.
|
|
562
|
+
*/
|
|
563
|
+
batch(req: PublishRequest[]): Promise<(PublishToUrlResponse | PublishToTopicResponse)[]>;
|
|
564
|
+
/**
|
|
565
|
+
* Batch publish messages to QStash, serializing each body to JSON.
|
|
566
|
+
*/
|
|
567
|
+
batchJSON<TBody = unknown, TRequest extends PublishRequest<TBody> = PublishRequest<TBody>>(req: TRequest[]): Promise<(PublishToUrlResponse | PublishToTopicResponse)[]>;
|
|
559
568
|
/**
|
|
560
569
|
* Retrieve your logs.
|
|
561
570
|
*
|
package/dist/index.js
CHANGED
|
@@ -368,34 +368,39 @@ var Client = class {
|
|
|
368
368
|
get schedules() {
|
|
369
369
|
return new Schedules(this.http);
|
|
370
370
|
}
|
|
371
|
+
processHeaders(req) {
|
|
372
|
+
var _a;
|
|
373
|
+
const headers = prefixHeaders(new Headers(req.headers));
|
|
374
|
+
headers.set("Upstash-Method", (_a = req.method) != null ? _a : "POST");
|
|
375
|
+
if (typeof req.delay !== "undefined") {
|
|
376
|
+
headers.set("Upstash-Delay", `${req.delay.toFixed()}s`);
|
|
377
|
+
}
|
|
378
|
+
if (typeof req.notBefore !== "undefined") {
|
|
379
|
+
headers.set("Upstash-Not-Before", req.notBefore.toFixed());
|
|
380
|
+
}
|
|
381
|
+
if (typeof req.deduplicationId !== "undefined") {
|
|
382
|
+
headers.set("Upstash-Deduplication-Id", req.deduplicationId);
|
|
383
|
+
}
|
|
384
|
+
if (typeof req.contentBasedDeduplication !== "undefined") {
|
|
385
|
+
headers.set("Upstash-Content-Based-Deduplication", "true");
|
|
386
|
+
}
|
|
387
|
+
if (typeof req.retries !== "undefined") {
|
|
388
|
+
headers.set("Upstash-Retries", req.retries.toFixed());
|
|
389
|
+
}
|
|
390
|
+
if (typeof req.callback !== "undefined") {
|
|
391
|
+
headers.set("Upstash-Callback", req.callback);
|
|
392
|
+
}
|
|
393
|
+
if (typeof req.failureCallback !== "undefined") {
|
|
394
|
+
headers.set("Upstash-Failure-Callback", req.failureCallback);
|
|
395
|
+
}
|
|
396
|
+
return headers;
|
|
397
|
+
}
|
|
371
398
|
publish(req) {
|
|
372
399
|
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
373
|
-
var _a
|
|
374
|
-
const headers =
|
|
375
|
-
headers.set("Upstash-Method", (_a = req.method) != null ? _a : "POST");
|
|
376
|
-
if (typeof req.delay !== "undefined") {
|
|
377
|
-
headers.set("Upstash-Delay", `${req.delay.toFixed()}s`);
|
|
378
|
-
}
|
|
379
|
-
if (typeof req.notBefore !== "undefined") {
|
|
380
|
-
headers.set("Upstash-Not-Before", req.notBefore.toFixed());
|
|
381
|
-
}
|
|
382
|
-
if (typeof req.deduplicationId !== "undefined") {
|
|
383
|
-
headers.set("Upstash-Deduplication-Id", req.deduplicationId);
|
|
384
|
-
}
|
|
385
|
-
if (typeof req.contentBasedDeduplication !== "undefined") {
|
|
386
|
-
headers.set("Upstash-Content-Based-Deduplication", "true");
|
|
387
|
-
}
|
|
388
|
-
if (typeof req.retries !== "undefined") {
|
|
389
|
-
headers.set("Upstash-Retries", req.retries.toFixed());
|
|
390
|
-
}
|
|
391
|
-
if (typeof req.callback !== "undefined") {
|
|
392
|
-
headers.set("Upstash-Callback", req.callback);
|
|
393
|
-
}
|
|
394
|
-
if (typeof req.failureCallback !== "undefined") {
|
|
395
|
-
headers.set("Upstash-Failure-Callback", req.failureCallback);
|
|
396
|
-
}
|
|
400
|
+
var _a;
|
|
401
|
+
const headers = this.processHeaders(req);
|
|
397
402
|
const res = yield this.http.request({
|
|
398
|
-
path: ["v2", "publish", (
|
|
403
|
+
path: ["v2", "publish", (_a = req.url) != null ? _a : req.topic],
|
|
399
404
|
body: req.body,
|
|
400
405
|
headers,
|
|
401
406
|
method: "POST"
|
|
@@ -418,6 +423,49 @@ var Client = class {
|
|
|
418
423
|
return res;
|
|
419
424
|
});
|
|
420
425
|
}
|
|
426
|
+
/**
|
|
427
|
+
* Batch publish messages to QStash.
|
|
428
|
+
*/
|
|
429
|
+
batch(req) {
|
|
430
|
+
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
431
|
+
var _a;
|
|
432
|
+
const messages = [];
|
|
433
|
+
for (const message of req) {
|
|
434
|
+
const headers = this.processHeaders(message);
|
|
435
|
+
const headerEntries = Object.fromEntries(headers.entries());
|
|
436
|
+
messages.push({
|
|
437
|
+
destination: (_a = message.url) != null ? _a : message.topic,
|
|
438
|
+
headers: headerEntries,
|
|
439
|
+
body: message.body
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
const res = yield this.http.request({
|
|
443
|
+
path: ["v2", "batch"],
|
|
444
|
+
body: JSON.stringify(messages),
|
|
445
|
+
headers: {
|
|
446
|
+
"Content-Type": "application/json"
|
|
447
|
+
},
|
|
448
|
+
method: "POST"
|
|
449
|
+
});
|
|
450
|
+
return res;
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Batch publish messages to QStash, serializing each body to JSON.
|
|
455
|
+
*/
|
|
456
|
+
batchJSON(req) {
|
|
457
|
+
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () {
|
|
458
|
+
for (const message of req) {
|
|
459
|
+
if ("body" in message) {
|
|
460
|
+
message.body = JSON.stringify(message.body);
|
|
461
|
+
}
|
|
462
|
+
message.headers = new Headers(message.headers);
|
|
463
|
+
message.headers.set("Content-Type", "application/json");
|
|
464
|
+
}
|
|
465
|
+
const res = yield this.batch(req);
|
|
466
|
+
return res;
|
|
467
|
+
});
|
|
468
|
+
}
|
|
421
469
|
/**
|
|
422
470
|
* Retrieve your logs.
|
|
423
471
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -368,34 +368,39 @@ var Client = class {
|
|
|
368
368
|
get schedules() {
|
|
369
369
|
return new Schedules(this.http);
|
|
370
370
|
}
|
|
371
|
+
processHeaders(req) {
|
|
372
|
+
var _a;
|
|
373
|
+
const headers = prefixHeaders(new Headers(req.headers));
|
|
374
|
+
headers.set("Upstash-Method", (_a = req.method) != null ? _a : "POST");
|
|
375
|
+
if (typeof req.delay !== "undefined") {
|
|
376
|
+
headers.set("Upstash-Delay", `${req.delay.toFixed()}s`);
|
|
377
|
+
}
|
|
378
|
+
if (typeof req.notBefore !== "undefined") {
|
|
379
|
+
headers.set("Upstash-Not-Before", req.notBefore.toFixed());
|
|
380
|
+
}
|
|
381
|
+
if (typeof req.deduplicationId !== "undefined") {
|
|
382
|
+
headers.set("Upstash-Deduplication-Id", req.deduplicationId);
|
|
383
|
+
}
|
|
384
|
+
if (typeof req.contentBasedDeduplication !== "undefined") {
|
|
385
|
+
headers.set("Upstash-Content-Based-Deduplication", "true");
|
|
386
|
+
}
|
|
387
|
+
if (typeof req.retries !== "undefined") {
|
|
388
|
+
headers.set("Upstash-Retries", req.retries.toFixed());
|
|
389
|
+
}
|
|
390
|
+
if (typeof req.callback !== "undefined") {
|
|
391
|
+
headers.set("Upstash-Callback", req.callback);
|
|
392
|
+
}
|
|
393
|
+
if (typeof req.failureCallback !== "undefined") {
|
|
394
|
+
headers.set("Upstash-Failure-Callback", req.failureCallback);
|
|
395
|
+
}
|
|
396
|
+
return headers;
|
|
397
|
+
}
|
|
371
398
|
publish(req) {
|
|
372
399
|
return __async(this, null, function* () {
|
|
373
|
-
var _a
|
|
374
|
-
const headers =
|
|
375
|
-
headers.set("Upstash-Method", (_a = req.method) != null ? _a : "POST");
|
|
376
|
-
if (typeof req.delay !== "undefined") {
|
|
377
|
-
headers.set("Upstash-Delay", `${req.delay.toFixed()}s`);
|
|
378
|
-
}
|
|
379
|
-
if (typeof req.notBefore !== "undefined") {
|
|
380
|
-
headers.set("Upstash-Not-Before", req.notBefore.toFixed());
|
|
381
|
-
}
|
|
382
|
-
if (typeof req.deduplicationId !== "undefined") {
|
|
383
|
-
headers.set("Upstash-Deduplication-Id", req.deduplicationId);
|
|
384
|
-
}
|
|
385
|
-
if (typeof req.contentBasedDeduplication !== "undefined") {
|
|
386
|
-
headers.set("Upstash-Content-Based-Deduplication", "true");
|
|
387
|
-
}
|
|
388
|
-
if (typeof req.retries !== "undefined") {
|
|
389
|
-
headers.set("Upstash-Retries", req.retries.toFixed());
|
|
390
|
-
}
|
|
391
|
-
if (typeof req.callback !== "undefined") {
|
|
392
|
-
headers.set("Upstash-Callback", req.callback);
|
|
393
|
-
}
|
|
394
|
-
if (typeof req.failureCallback !== "undefined") {
|
|
395
|
-
headers.set("Upstash-Failure-Callback", req.failureCallback);
|
|
396
|
-
}
|
|
400
|
+
var _a;
|
|
401
|
+
const headers = this.processHeaders(req);
|
|
397
402
|
const res = yield this.http.request({
|
|
398
|
-
path: ["v2", "publish", (
|
|
403
|
+
path: ["v2", "publish", (_a = req.url) != null ? _a : req.topic],
|
|
399
404
|
body: req.body,
|
|
400
405
|
headers,
|
|
401
406
|
method: "POST"
|
|
@@ -418,6 +423,49 @@ var Client = class {
|
|
|
418
423
|
return res;
|
|
419
424
|
});
|
|
420
425
|
}
|
|
426
|
+
/**
|
|
427
|
+
* Batch publish messages to QStash.
|
|
428
|
+
*/
|
|
429
|
+
batch(req) {
|
|
430
|
+
return __async(this, null, function* () {
|
|
431
|
+
var _a;
|
|
432
|
+
const messages = [];
|
|
433
|
+
for (const message of req) {
|
|
434
|
+
const headers = this.processHeaders(message);
|
|
435
|
+
const headerEntries = Object.fromEntries(headers.entries());
|
|
436
|
+
messages.push({
|
|
437
|
+
destination: (_a = message.url) != null ? _a : message.topic,
|
|
438
|
+
headers: headerEntries,
|
|
439
|
+
body: message.body
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
const res = yield this.http.request({
|
|
443
|
+
path: ["v2", "batch"],
|
|
444
|
+
body: JSON.stringify(messages),
|
|
445
|
+
headers: {
|
|
446
|
+
"Content-Type": "application/json"
|
|
447
|
+
},
|
|
448
|
+
method: "POST"
|
|
449
|
+
});
|
|
450
|
+
return res;
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Batch publish messages to QStash, serializing each body to JSON.
|
|
455
|
+
*/
|
|
456
|
+
batchJSON(req) {
|
|
457
|
+
return __async(this, null, function* () {
|
|
458
|
+
for (const message of req) {
|
|
459
|
+
if ("body" in message) {
|
|
460
|
+
message.body = JSON.stringify(message.body);
|
|
461
|
+
}
|
|
462
|
+
message.headers = new Headers(message.headers);
|
|
463
|
+
message.headers.set("Content-Type", "application/json");
|
|
464
|
+
}
|
|
465
|
+
const res = yield this.batch(req);
|
|
466
|
+
return res;
|
|
467
|
+
});
|
|
468
|
+
}
|
|
421
469
|
/**
|
|
422
470
|
* Retrieve your logs.
|
|
423
471
|
*
|