@vite-hub/queue 0.1.0 → 0.4.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 +152 -29
- package/dist/client-B53_G4ky.js +182 -0
- package/dist/{cloudflare-client-COzQ8fHk.js → cloudflare-client-CoISDpIx.js} +28 -21
- package/dist/{cloudflare-resource-name-CCuLDvSP.js → cloudflare-resource-name-BIfBglC2.js} +1 -1
- package/dist/config-B2eaXaT5.js +105 -0
- package/dist/durability.d.ts +13 -0
- package/dist/durability.js +47 -0
- package/dist/duration-tujyhAKt.js +111 -0
- package/dist/error-diagnostics-CQ4BUqRe.js +270 -0
- package/dist/error-diagnostics-mJXBjmQx.js +181 -0
- package/dist/{handler-response-CBwIkmTS.js → handler-response-B6lz9nCn.js} +9 -4
- package/dist/index.d.ts +20 -32
- package/dist/index.js +39 -17
- package/dist/internal/runtime/cloudflare-client.d.ts +2 -2
- package/dist/internal/runtime/cloudflare-client.js +1 -1
- package/dist/internal/runtime/cloudflare-vite.d.ts +30 -2
- package/dist/internal/runtime/cloudflare-vite.js +111 -1
- package/dist/internal/runtime/local-client.d.ts +17 -0
- package/dist/internal/runtime/local-client.js +71 -0
- package/dist/internal/runtime/postgres-client.d.ts +46 -0
- package/dist/internal/runtime/postgres-client.js +570 -0
- package/dist/internal/runtime/state.d.ts +11 -4
- package/dist/internal/runtime/state.js +2 -2
- package/dist/internal/runtime/vercel-client.d.ts +2 -2
- package/dist/internal/runtime/vercel-client.js +66 -28
- package/dist/internal/runtime/worker-client.d.ts +6 -0
- package/dist/internal/runtime/worker-client.js +11 -0
- package/dist/invariant-D8_xBqmZ.js +22 -0
- package/dist/local-CUaWoRUx.d.ts +23 -0
- package/dist/local-Di0FrVUw.js +553 -0
- package/dist/object-D8pRdprI.js +15 -0
- package/dist/{operations-tNUdj3G4.d.ts → operation-definition-nmRu_O3V.d.ts} +42 -15
- package/dist/operations-BVV-9Q0N.js +129 -0
- package/dist/operations.d.ts +47 -9
- package/dist/operations.js +186 -69
- package/dist/runtime/hosted.d.ts +3 -5
- package/dist/runtime/hosted.js +21 -45
- package/dist/{state-G9s378-e.js → state-DLqTqF6V.js} +59 -47
- package/dist/types-CiuSIPR0.d.ts +440 -0
- package/dist/types-Dsbb_Pvp.d.ts +10 -0
- package/dist/vercel-region-B95MAMXN.js +26 -0
- package/dist/virtual.d.ts +4 -0
- package/dist/vite.d.ts +366 -49
- package/dist/vite.js +2071 -2
- package/package.json +39 -46
- package/dist/client-CIc3jsj2.js +0 -114
- package/dist/cloudflare-vite-BCuJOXcT.js +0 -111
- package/dist/cloudflare-vite-CjdP5yBN.d.ts +0 -29
- package/dist/config-BINujLv4.js +0 -74
- package/dist/enqueue-CnQ0QR3O.js +0 -22
- package/dist/error-diagnostics-A_8Kp-48.js +0 -116
- package/dist/error-diagnostics-qzRF6IVB.js +0 -109
- package/dist/errors-DIFaM9tW.js +0 -42
- package/dist/nuxt.d.ts +0 -39
- package/dist/nuxt.js +0 -34
- package/dist/object-B1NW521B.js +0 -7
- package/dist/operations-Cnjbz8kk.js +0 -63
- package/dist/types-1GRMYES1.d.ts +0 -180
- package/dist/vercel-region-cjskrOKl.js +0 -122
- package/dist/vite-ChWLzOVu.js +0 -1512
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
import { t as queueErrorDiagnostics } from "../../error-diagnostics-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t as resolveVercelQueueRegion } from "../../vercel-region-cjskrOKl.js";
|
|
1
|
+
import { t as queueErrorDiagnostics } from "../../error-diagnostics-mJXBjmQx.js";
|
|
2
|
+
import { c as queueRemovedOptionsError, d as normalizeQueueEnqueueInput, l as queueUnsupportedOptionsError, s as queueProviderResult, t as readQueueTimes, u as createQueueMessageId } from "../../duration-tujyhAKt.js";
|
|
3
|
+
import { t as resolveVercelQueueRegion } from "../../vercel-region-B95MAMXN.js";
|
|
5
4
|
//#region src/providers/vercel.ts
|
|
6
5
|
function invalidVercelSendResponse(cause) {
|
|
7
6
|
return [queueErrorDiagnostics.QUEUE_PROVIDER_INVALID_RESPONSE({ cause }), void 0];
|
|
8
7
|
}
|
|
9
|
-
function isRuntimeFunction(value) {
|
|
10
|
-
if (value === null || value === void 0 || Object(value) !== value) return false;
|
|
11
|
-
try {
|
|
12
|
-
Function.prototype.toString.call(value);
|
|
13
|
-
return true;
|
|
14
|
-
} catch {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
8
|
function isVercelQueueSDK(value) {
|
|
19
9
|
if (value === null || typeof value !== "object") return false;
|
|
20
10
|
try {
|
|
@@ -36,14 +26,14 @@ function isVercelQueueSDK(value) {
|
|
|
36
26
|
let constructor;
|
|
37
27
|
try {
|
|
38
28
|
constructor = Object.getOwnPropertyDescriptor(owner, "constructor");
|
|
39
|
-
if (!constructor || !("value" in constructor) ||
|
|
29
|
+
if (!constructor || !("value" in constructor) || typeof constructor.value !== "function" || constructor.value.prototype !== owner) return false;
|
|
40
30
|
} catch {
|
|
41
31
|
return false;
|
|
42
32
|
}
|
|
43
33
|
}
|
|
44
|
-
if ("value" in descriptor) return
|
|
34
|
+
if ("value" in descriptor) return typeof descriptor.value === "function";
|
|
45
35
|
try {
|
|
46
|
-
return
|
|
36
|
+
return typeof Reflect.get(value, name) === "function";
|
|
47
37
|
} catch {
|
|
48
38
|
return false;
|
|
49
39
|
}
|
|
@@ -58,6 +48,27 @@ function isVercelQueueSDK(value) {
|
|
|
58
48
|
};
|
|
59
49
|
return hasCallableMethod("send") && hasCallableMethod("handleCallback");
|
|
60
50
|
}
|
|
51
|
+
/** The cause of `QUEUE_PROVIDER_FAILED` when Vercel rejects jobs of a batch. `results` has each job's result in input order. */
|
|
52
|
+
function batchRejected(results) {
|
|
53
|
+
const failed = results.filter((result) => result.status === "failed").length;
|
|
54
|
+
return Object.assign(queueErrorDiagnostics.QUEUE_VERCEL_BATCH_REJECTED({
|
|
55
|
+
failed,
|
|
56
|
+
total: results.length
|
|
57
|
+
}), { results });
|
|
58
|
+
}
|
|
59
|
+
function parseVercelBatchResults(value, length) {
|
|
60
|
+
if (!Array.isArray(value) || value.length !== length) return invalidVercelSendResponse(value);
|
|
61
|
+
const results = [];
|
|
62
|
+
for (const entry of value) {
|
|
63
|
+
const [error, messageId] = parseVercelMessageId(entry);
|
|
64
|
+
if (error) return [error, void 0];
|
|
65
|
+
results.push({
|
|
66
|
+
status: "queued",
|
|
67
|
+
messageId
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return [void 0, results];
|
|
71
|
+
}
|
|
61
72
|
function parseVercelMessageId(value) {
|
|
62
73
|
if (!value || typeof value !== "object" || Array.isArray(value)) return invalidVercelSendResponse(value);
|
|
63
74
|
let messageId;
|
|
@@ -90,13 +101,14 @@ async function loadVercelQueueClient(region) {
|
|
|
90
101
|
throw queueErrorDiagnostics.QUEUE_VERCEL_SDK_UNAVAILABLE({ cause });
|
|
91
102
|
}
|
|
92
103
|
const { region: resolvedRegion } = resolveVercelQueueRegion(region);
|
|
93
|
-
if (Object.hasOwn(module, "QueueClient") &&
|
|
104
|
+
if (Object.hasOwn(module, "QueueClient") && typeof module.QueueClient === "function") {
|
|
94
105
|
if (!resolvedRegion) throw queueErrorDiagnostics.QUEUE_MISSING_REGION();
|
|
95
106
|
return new module.QueueClient({ region: resolvedRegion });
|
|
96
107
|
}
|
|
97
|
-
if (Object.hasOwn(module, "send") && Object.hasOwn(module, "handleCallback") &&
|
|
108
|
+
if (Object.hasOwn(module, "send") && Object.hasOwn(module, "handleCallback") && typeof module.send === "function" && typeof module.handleCallback === "function") return {
|
|
98
109
|
handleCallback: module.handleCallback,
|
|
99
|
-
send: module.send
|
|
110
|
+
send: module.send,
|
|
111
|
+
...Object.hasOwn(module, "sendBatch") && typeof module.sendBatch === "function" ? { sendBatch: module.sendBatch } : {}
|
|
100
112
|
};
|
|
101
113
|
throw queueErrorDiagnostics.QUEUE_VERCEL_SDK_INVALID();
|
|
102
114
|
}
|
|
@@ -111,15 +123,15 @@ async function createVercelQueueClient(provider) {
|
|
|
111
123
|
topic,
|
|
112
124
|
async send(payload, options) {
|
|
113
125
|
const normalized = normalizeQueueEnqueueInput(payload, options);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
126
|
+
const optionsError = queueUnsupportedOptionsError(normalized.options, "vercel");
|
|
127
|
+
if (optionsError) return [optionsError, void 0];
|
|
128
|
+
const [timeError, times] = readQueueTimes(normalized.options, "ceil");
|
|
129
|
+
if (timeError) return [timeError, void 0];
|
|
118
130
|
const [error, response] = await queueProviderResult("vercel", "send", () => client.send(topic, normalized.payload, {
|
|
119
|
-
delaySeconds:
|
|
131
|
+
delaySeconds: times.delaySeconds,
|
|
120
132
|
idempotencyKey: normalized.options.idempotencyKey || normalized.id,
|
|
121
133
|
region: normalized.options.region ?? provider.region,
|
|
122
|
-
retentionSeconds:
|
|
134
|
+
retentionSeconds: times.retentionSeconds
|
|
123
135
|
}));
|
|
124
136
|
if (error) return [error, void 0];
|
|
125
137
|
const [responseError, messageId] = parseVercelMessageId(response);
|
|
@@ -129,15 +141,41 @@ async function createVercelQueueClient(provider) {
|
|
|
129
141
|
messageId
|
|
130
142
|
}];
|
|
131
143
|
},
|
|
144
|
+
async sendBatch(items, options) {
|
|
145
|
+
const removed = queueRemovedOptionsError("vercel", options, items);
|
|
146
|
+
if (removed) return [removed, void 0];
|
|
147
|
+
const messages = [];
|
|
148
|
+
for (const item of items) {
|
|
149
|
+
const [timeError, times] = readQueueTimes({
|
|
150
|
+
delay: item.delay ?? options?.delay,
|
|
151
|
+
retention: item.retention ?? options?.retention
|
|
152
|
+
}, "ceil");
|
|
153
|
+
if (timeError) return [timeError, void 0];
|
|
154
|
+
messages.push({
|
|
155
|
+
delaySeconds: times.delaySeconds,
|
|
156
|
+
idempotencyKey: item.idempotencyKey || createQueueMessageId(),
|
|
157
|
+
payload: item.body,
|
|
158
|
+
retentionSeconds: times.retentionSeconds
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
const [error, response] = await queueProviderResult("vercel", "send-batch", async () => {
|
|
162
|
+
if (typeof client.sendBatch !== "function") throw queueErrorDiagnostics.QUEUE_VERCEL_SEND_BATCH_UNAVAILABLE();
|
|
163
|
+
const results = await client.sendBatch(topic, messages);
|
|
164
|
+
if (Array.isArray(results) && results.some((result) => result?.status === "failed")) throw batchRejected(results);
|
|
165
|
+
return results;
|
|
166
|
+
});
|
|
167
|
+
if (error) return [error, void 0];
|
|
168
|
+
return parseVercelBatchResults(response, messages.length);
|
|
169
|
+
},
|
|
132
170
|
callback: client.handleCallback.bind(client)
|
|
133
171
|
};
|
|
134
172
|
}
|
|
135
173
|
//#endregion
|
|
136
174
|
//#region src/internal/runtime/vercel-client.ts
|
|
137
175
|
async function createVercelQueueRuntimeClient(options) {
|
|
138
|
-
if (options.
|
|
139
|
-
|
|
140
|
-
|
|
176
|
+
if (options.driver !== "vercel") throw queueErrorDiagnostics.QUEUE_DRIVER_MISMATCH({
|
|
177
|
+
driver: options.driver,
|
|
178
|
+
expected: "vercel"
|
|
141
179
|
});
|
|
142
180
|
return await createVercelQueueClient(options);
|
|
143
181
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { b as QueueClient } from "../../types-CiuSIPR0.js";
|
|
2
|
+
import { t as QueueRuntimeDriverOptions } from "../../types-Dsbb_Pvp.js";
|
|
3
|
+
//#region src/internal/runtime/worker-client.d.ts
|
|
4
|
+
/** Worker package conditions keep the Node driver and its optional peer outside the build graph. */
|
|
5
|
+
export declare function createPostgresQueueRuntimeClient(options: QueueRuntimeDriverOptions): Promise<QueueClient>;
|
|
6
|
+
//#endregion
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { t as queueErrorDiagnostics } from "../../error-diagnostics-mJXBjmQx.js";
|
|
2
|
+
//#region src/internal/runtime/worker-client.ts
|
|
3
|
+
/** Worker package conditions keep the Node driver and its optional peer outside the build graph. */
|
|
4
|
+
async function createPostgresQueueRuntimeClient(options) {
|
|
5
|
+
throw queueErrorDiagnostics.QUEUE_DRIVER_MISMATCH({
|
|
6
|
+
driver: options.driver,
|
|
7
|
+
expected: "cloudflare"
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { createPostgresQueueRuntimeClient };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineDiagnostics } from "nostics";
|
|
2
|
+
//#region ../internal/src/invariant.ts
|
|
3
|
+
const invariantDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
4
|
+
docsBase: "https://vitehub.dev/docs/development/diagnostics",
|
|
5
|
+
codes: { INTERNAL_INVARIANT_FAILED: {
|
|
6
|
+
why: ({ what }) => `ViteHub reached a state that it does not expect: ${what}`,
|
|
7
|
+
fix: "This is a ViteHub bug. Open an issue at https://github.com/vite-hub/vitehub/issues with this error message and its stack trace."
|
|
8
|
+
} }
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* The error for a state that only a ViteHub bug can reach, such as an impossible branch. `what` says which rule broke.
|
|
12
|
+
* Use a code from the package catalog when a developer can cause the error or fix it.
|
|
13
|
+
*/
|
|
14
|
+
function invariantError(what) {
|
|
15
|
+
return invariantDiagnostics.INTERNAL_INVARIANT_FAILED({ what });
|
|
16
|
+
}
|
|
17
|
+
/** Throws `INTERNAL_INVARIANT_FAILED` when `condition` is falsy. */
|
|
18
|
+
function invariant(condition, what) {
|
|
19
|
+
if (!condition) throw invariantError(what);
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { invariant as t };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { A as QueueJobStore } from "./types-CiuSIPR0.js";
|
|
2
|
+
//#region src/providers/local.d.ts
|
|
3
|
+
/** One job for the engine. `vite dev` and the clients read `delay` and `retention` into seconds first. */
|
|
4
|
+
interface LocalQueueEntry {
|
|
5
|
+
delaySeconds?: number;
|
|
6
|
+
id: string;
|
|
7
|
+
idempotencyKey?: string;
|
|
8
|
+
payload: unknown;
|
|
9
|
+
retentionSeconds?: number;
|
|
10
|
+
}
|
|
11
|
+
interface LocalQueueEngine extends QueueJobStore {
|
|
12
|
+
readonly provider: "local";
|
|
13
|
+
close: () => void;
|
|
14
|
+
/**
|
|
15
|
+
* Stores the jobs and returns their message IDs. A pending or running job with the same `idempotencyKey` returns
|
|
16
|
+
* its ID instead. When one file of the batch cannot be written, no job of the batch is stored.
|
|
17
|
+
*/
|
|
18
|
+
enqueue: (queue: string, entries: readonly LocalQueueEntry[]) => Promise<string[]>;
|
|
19
|
+
/** Reads the stored jobs and starts their delivery. Later calls return the same promise. */
|
|
20
|
+
start: () => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { LocalQueueEngine as t };
|