@vite-hub/queue 0.1.0 → 0.3.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 +141 -20
- package/dist/client-Cj50hQYp.js +180 -0
- package/dist/{cloudflare-client-COzQ8fHk.js → cloudflare-client-DYsAjM8B.js} +9 -16
- package/dist/{cloudflare-resource-name-CCuLDvSP.js → cloudflare-resource-name-BJHYRCMQ.js} +1 -1
- package/dist/config-BcTDeQIP.js +105 -0
- package/dist/durability.d.ts +13 -0
- package/dist/durability.js +47 -0
- package/dist/error-diagnostics-BRartC1z.js +181 -0
- package/dist/error-diagnostics-DSkCJC_L.js +266 -0
- package/dist/errors-DL3pcNO4.js +77 -0
- package/dist/{handler-response-CBwIkmTS.js → handler-response-By0Fpspv.js} +9 -4
- package/dist/index.d.ts +15 -31
- package/dist/index.js +23 -11
- 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 +560 -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 +52 -26
- 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-CGckW5nr.js +540 -0
- package/dist/local-CVVRVWeR.d.ts +22 -0
- package/dist/object-D8pRdprI.js +15 -0
- package/dist/{operations-tNUdj3G4.d.ts → operation-definition-8gOe-ubD.d.ts} +37 -15
- package/dist/operations-Crwjca91.js +124 -0
- package/dist/operations.d.ts +45 -8
- package/dist/operations.js +173 -24
- package/dist/runtime/hosted.d.ts +3 -5
- package/dist/runtime/hosted.js +21 -45
- package/dist/{state-G9s378-e.js → state-mVA2X_wa.js} +59 -47
- package/dist/types-BD-8U9zS.d.ts +420 -0
- package/dist/types-DS_rqu9l.d.ts +10 -0
- package/dist/vercel-region-D1CivgdA.js +26 -0
- package/dist/virtual.d.ts +4 -0
- package/dist/vite.d.ts +364 -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-BRartC1z.js";
|
|
2
|
+
import { c as createQueueMessageId, l as normalizeQueueEnqueueInput, o as queueProviderResult, s as queueUnsupportedOptionsError } from "../../errors-DL3pcNO4.js";
|
|
3
|
+
import { t as resolveVercelQueueRegion } from "../../vercel-region-D1CivgdA.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,10 +123,8 @@ async function createVercelQueueClient(provider) {
|
|
|
111
123
|
topic,
|
|
112
124
|
async send(payload, options) {
|
|
113
125
|
const normalized = normalizeQueueEnqueueInput(payload, options);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
provider: "vercel"
|
|
117
|
-
}), void 0];
|
|
126
|
+
const optionsError = queueUnsupportedOptionsError(normalized.options, "vercel");
|
|
127
|
+
if (optionsError) return [optionsError, void 0];
|
|
118
128
|
const [error, response] = await queueProviderResult("vercel", "send", () => client.send(topic, normalized.payload, {
|
|
119
129
|
delaySeconds: normalized.options.delaySeconds,
|
|
120
130
|
idempotencyKey: normalized.options.idempotencyKey || normalized.id,
|
|
@@ -129,15 +139,31 @@ async function createVercelQueueClient(provider) {
|
|
|
129
139
|
messageId
|
|
130
140
|
}];
|
|
131
141
|
},
|
|
142
|
+
async sendBatch(items, options) {
|
|
143
|
+
const messages = items.map((item) => ({
|
|
144
|
+
delaySeconds: item.delaySeconds ?? options?.delaySeconds,
|
|
145
|
+
idempotencyKey: item.idempotencyKey || createQueueMessageId(),
|
|
146
|
+
payload: item.body,
|
|
147
|
+
retentionSeconds: item.retentionSeconds ?? options?.retentionSeconds
|
|
148
|
+
}));
|
|
149
|
+
const [error, response] = await queueProviderResult("vercel", "send-batch", async () => {
|
|
150
|
+
if (typeof client.sendBatch !== "function") throw queueErrorDiagnostics.QUEUE_VERCEL_SEND_BATCH_UNAVAILABLE();
|
|
151
|
+
const results = await client.sendBatch(topic, messages);
|
|
152
|
+
if (Array.isArray(results) && results.some((result) => result?.status === "failed")) throw batchRejected(results);
|
|
153
|
+
return results;
|
|
154
|
+
});
|
|
155
|
+
if (error) return [error, void 0];
|
|
156
|
+
return parseVercelBatchResults(response, messages.length);
|
|
157
|
+
},
|
|
132
158
|
callback: client.handleCallback.bind(client)
|
|
133
159
|
};
|
|
134
160
|
}
|
|
135
161
|
//#endregion
|
|
136
162
|
//#region src/internal/runtime/vercel-client.ts
|
|
137
163
|
async function createVercelQueueRuntimeClient(options) {
|
|
138
|
-
if (options.
|
|
139
|
-
|
|
140
|
-
|
|
164
|
+
if (options.driver !== "vercel") throw queueErrorDiagnostics.QUEUE_DRIVER_MISMATCH({
|
|
165
|
+
driver: options.driver,
|
|
166
|
+
expected: "vercel"
|
|
141
167
|
});
|
|
142
168
|
return await createVercelQueueClient(options);
|
|
143
169
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { y as QueueClient } from "../../types-BD-8U9zS.js";
|
|
2
|
+
import { t as QueueRuntimeDriverOptions } from "../../types-DS_rqu9l.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-BRartC1z.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 };
|