@upstash/qstash
Advanced tools
Comparing version 2.4.3 to 2.5.0
@@ -204,2 +204,43 @@ /** | ||
type QueueResponse = { | ||
createdAt: number; | ||
updatedAt: number; | ||
name: string; | ||
parallelism: number; | ||
lag: number; | ||
}; | ||
type UpsertQueueRequest = { | ||
parallelism: number; | ||
}; | ||
type EnqueueRequest = PublishRequest; | ||
declare class Queue { | ||
private readonly http; | ||
private readonly queueName; | ||
constructor(http: Requester, queueName?: string); | ||
/** | ||
* Create or update the queue | ||
*/ | ||
upsert(req: UpsertQueueRequest): Promise<void>; | ||
/** | ||
* Get the queue details | ||
*/ | ||
get(): Promise<QueueResponse>; | ||
/** | ||
* List queues | ||
*/ | ||
list(): Promise<QueueResponse[]>; | ||
/** | ||
* Delete the queue | ||
*/ | ||
delete(): Promise<void>; | ||
/** | ||
* Enqueue a message to a queue. | ||
*/ | ||
enqueue(req: EnqueueRequest): Promise<PublishResponse<PublishRequest>>; | ||
/** | ||
* Enqueue a message to a queue, serializing the body to JSON. | ||
*/ | ||
enqueueJSON<TBody = unknown>(req: PublishRequest<TBody>): Promise<PublishResponse<PublishRequest<TBody>>>; | ||
} | ||
type Schedule = { | ||
@@ -523,3 +564,15 @@ scheduleId: string; | ||
cursor?: number; | ||
filter?: EventsRequestFilter; | ||
}; | ||
type EventsRequestFilter = { | ||
messageId?: string; | ||
state?: State; | ||
url?: string; | ||
topicName?: string; | ||
scheduleId?: string; | ||
queueName?: string; | ||
fromDate?: number; | ||
toDate?: number; | ||
count?: number; | ||
}; | ||
type GetEventsResponse = { | ||
@@ -529,2 +582,5 @@ cursor?: number; | ||
}; | ||
type QueueRequest = { | ||
queueName?: string; | ||
}; | ||
declare class Client { | ||
@@ -557,3 +613,8 @@ http: Requester; | ||
get schedules(): Schedules; | ||
private processHeaders; | ||
/** | ||
* Access the queue API. | ||
* | ||
* Create, read, update or delete queues. | ||
*/ | ||
queue(req?: QueueRequest): Queue; | ||
publish<TRequest extends PublishRequest>(req: TRequest): Promise<PublishResponse<TRequest>>; | ||
@@ -614,2 +675,2 @@ /** | ||
export { AddEndpointsRequest, Client, CreateScheduleRequest, Endpoint, Event, EventsRequest, GetEventsResponse, Message, Messages, PublishJsonRequest, PublishRequest, PublishResponse, PublishToTopicResponse, PublishToUrlResponse, QstashError, QstashRatelimitError, Receiver, ReceiverConfig, RemoveEndpointsRequest, Schedule, Schedules, SignatureError, State, Topic, Topics, VerifyRequest, WithCursor }; | ||
export { AddEndpointsRequest, Client, CreateScheduleRequest, Endpoint, Event, EventsRequest, GetEventsResponse, Message, Messages, PublishJsonRequest, PublishRequest, PublishResponse, PublishToTopicResponse, PublishToUrlResponse, QstashError, QstashRatelimitError, QueueRequest, Receiver, ReceiverConfig, RemoveEndpointsRequest, Schedule, Schedules, SignatureError, State, Topic, Topics, VerifyRequest, WithCursor }; |
@@ -186,3 +186,135 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
} | ||
function processHeaders(req) { | ||
var _a; | ||
const headers = prefixHeaders(new Headers(req.headers)); | ||
headers.set("Upstash-Method", (_a = req.method) != null ? _a : "POST"); | ||
if (typeof req.delay !== "undefined") { | ||
headers.set("Upstash-Delay", `${req.delay.toFixed()}s`); | ||
} | ||
if (typeof req.notBefore !== "undefined") { | ||
headers.set("Upstash-Not-Before", req.notBefore.toFixed()); | ||
} | ||
if (typeof req.deduplicationId !== "undefined") { | ||
headers.set("Upstash-Deduplication-Id", req.deduplicationId); | ||
} | ||
if (typeof req.contentBasedDeduplication !== "undefined") { | ||
headers.set("Upstash-Content-Based-Deduplication", "true"); | ||
} | ||
if (typeof req.retries !== "undefined") { | ||
headers.set("Upstash-Retries", req.retries.toFixed()); | ||
} | ||
if (typeof req.callback !== "undefined") { | ||
headers.set("Upstash-Callback", req.callback); | ||
} | ||
if (typeof req.failureCallback !== "undefined") { | ||
headers.set("Upstash-Failure-Callback", req.failureCallback); | ||
} | ||
return headers; | ||
} | ||
// src/client/queue.ts | ||
var Queue = class { | ||
constructor(http, queueName) { | ||
this.http = http; | ||
this.queueName = queueName; | ||
} | ||
/** | ||
* Create or update the queue | ||
*/ | ||
upsert(req) { | ||
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () { | ||
if (!this.queueName) { | ||
throw new Error("Please provide a queue name to the Queue constructor"); | ||
} | ||
const body = { | ||
queueName: this.queueName, | ||
parallelism: req.parallelism | ||
}; | ||
yield this.http.request({ | ||
method: "POST", | ||
path: ["v2", "queues"], | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify(body), | ||
parseResponseAsJson: false | ||
}); | ||
}); | ||
} | ||
/** | ||
* Get the queue details | ||
*/ | ||
get() { | ||
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () { | ||
if (!this.queueName) { | ||
throw new Error("Please provide a queue name to the Queue constructor"); | ||
} | ||
return yield this.http.request({ | ||
method: "GET", | ||
path: ["v2", "queues", this.queueName] | ||
}); | ||
}); | ||
} | ||
/** | ||
* List queues | ||
*/ | ||
list() { | ||
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () { | ||
return yield this.http.request({ | ||
method: "GET", | ||
path: ["v2", "queues"] | ||
}); | ||
}); | ||
} | ||
/** | ||
* Delete the queue | ||
*/ | ||
delete() { | ||
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () { | ||
if (!this.queueName) { | ||
throw new Error("Please provide a queue name to the Queue constructor"); | ||
} | ||
yield this.http.request({ | ||
method: "DELETE", | ||
path: ["v2", "queues", this.queueName], | ||
parseResponseAsJson: false | ||
}); | ||
}); | ||
} | ||
/** | ||
* Enqueue a message to a queue. | ||
*/ | ||
enqueue(req) { | ||
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () { | ||
var _a; | ||
if (!this.queueName) { | ||
throw new Error("Please provide a queue name to the Queue constructor"); | ||
} | ||
const headers = processHeaders(req); | ||
const destination = (_a = req.url) != null ? _a : req.topic; | ||
const res = yield this.http.request({ | ||
path: ["v2", "enqueue", this.queueName, destination], | ||
body: req.body, | ||
headers, | ||
method: "POST" | ||
}); | ||
return res; | ||
}); | ||
} | ||
/** | ||
* Enqueue a message to a queue, serializing the body to JSON. | ||
*/ | ||
enqueueJSON(req) { | ||
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () { | ||
const headers = prefixHeaders(new Headers(req.headers)); | ||
headers.set("Content-Type", "application/json"); | ||
const res = yield this.enqueue(_chunkEROSIHWEjs.__spreadProps.call(void 0, _chunkEROSIHWEjs.__spreadValues.call(void 0, {}, req), { | ||
body: JSON.stringify(req.body), | ||
headers | ||
})); | ||
return res; | ||
}); | ||
} | ||
}; | ||
// src/client/schedules.ts | ||
@@ -372,28 +504,9 @@ var Schedules = class { | ||
} | ||
processHeaders(req) { | ||
var _a; | ||
const headers = prefixHeaders(new Headers(req.headers)); | ||
headers.set("Upstash-Method", (_a = req.method) != null ? _a : "POST"); | ||
if (typeof req.delay !== "undefined") { | ||
headers.set("Upstash-Delay", `${req.delay.toFixed()}s`); | ||
} | ||
if (typeof req.notBefore !== "undefined") { | ||
headers.set("Upstash-Not-Before", req.notBefore.toFixed()); | ||
} | ||
if (typeof req.deduplicationId !== "undefined") { | ||
headers.set("Upstash-Deduplication-Id", req.deduplicationId); | ||
} | ||
if (typeof req.contentBasedDeduplication !== "undefined") { | ||
headers.set("Upstash-Content-Based-Deduplication", "true"); | ||
} | ||
if (typeof req.retries !== "undefined") { | ||
headers.set("Upstash-Retries", req.retries.toFixed()); | ||
} | ||
if (typeof req.callback !== "undefined") { | ||
headers.set("Upstash-Callback", req.callback); | ||
} | ||
if (typeof req.failureCallback !== "undefined") { | ||
headers.set("Upstash-Failure-Callback", req.failureCallback); | ||
} | ||
return headers; | ||
/** | ||
* Access the queue API. | ||
* | ||
* Create, read, update or delete queues. | ||
*/ | ||
queue(req) { | ||
return new Queue(this.http, req == null ? void 0 : req.queueName); | ||
} | ||
@@ -403,3 +516,3 @@ publish(req) { | ||
var _a; | ||
const headers = this.processHeaders(req); | ||
const headers = processHeaders(req); | ||
const res = yield this.http.request({ | ||
@@ -437,3 +550,3 @@ path: ["v2", "publish", (_a = req.url) != null ? _a : req.topic], | ||
for (const message of req) { | ||
const headers = this.processHeaders(message); | ||
const headers = processHeaders(message); | ||
const headerEntries = Object.fromEntries(headers.entries()); | ||
@@ -494,6 +607,15 @@ messages.push({ | ||
return _chunkEROSIHWEjs.__async.call(void 0, this, null, function* () { | ||
var _a; | ||
const query = {}; | ||
if ((req == null ? void 0 : req.cursor) && req.cursor > 0) { | ||
query.cursor = req.cursor; | ||
query.cursor = req.cursor.toString(); | ||
} | ||
for (const [key, value] of Object.entries((_a = req == null ? void 0 : req.filter) != null ? _a : {})) { | ||
if (typeof value === "number" && value < 0) { | ||
continue; | ||
} | ||
if (typeof value !== "undefined") { | ||
query[key] = value.toString(); | ||
} | ||
} | ||
const res = yield this.http.request({ | ||
@@ -500,0 +622,0 @@ path: ["v2", "events"], |
{ | ||
"name": "@upstash/qstash", | ||
"version": "v2.4.3", | ||
"version": "v2.5.0", | ||
"description": "Official Typescript client for QStash", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
97218
2455