@vite-hub/queue 0.7.0 → 0.8.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/dist/{client-B8QVg1mA.js → client-mT8TUaag.js} +1 -1
- package/dist/{cloudflare-client-BoaOlFzD.js → cloudflare-client-DBgvWY0z.js} +3 -36
- package/dist/{duration-CcLSF94z.js → duration-BZKArIBP.js} +1 -1
- package/dist/{handler-response-GFXYd6mF.js → handler-response-DKhsmxDV.js} +1 -1
- package/dist/index.js +2 -2
- package/dist/internal/runtime/cloudflare-client.js +1 -1
- package/dist/internal/runtime/cloudflare-vite.js +2 -2
- package/dist/internal/runtime/local-client.js +1 -1
- package/dist/internal/runtime/postgres-client.js +11 -11
- package/dist/internal/runtime/vercel-client.js +5 -53
- package/dist/{local-BR4W57HU.js → local-5pcvR1RC.js} +5 -3
- package/dist/{operations-COCpSoua.js → operations-BSouq47k.js} +2 -2
- package/dist/operations.js +1 -1
- package/dist/{run-handler-B_RVXMs5.js → run-handler-COXFYL5z.js} +1 -1
- package/dist/runtime/hosted.js +3 -3
- package/dist/{scan-module-BaqBao0J.js → scan-module-3HfnrGbT.js} +16 -1
- package/dist/source-files-DrAH1-c8.js +147 -0
- package/dist/vite.js +63 -71
- package/package.json +4 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _ as resolveWaitUntil, a as getQueueRuntimeEvent, d as runWithQueueRuntimeEvent, i as getQueueRuntimeConfig, l as loadQueueDefinition, n as getOrCreateQueueClient, r as getQueueRuntimeClientFactory, y as getCloudflareEnv } from "./state-C-t99I4Q.js";
|
|
2
2
|
import { n as normalizeQueueOptions } from "./config-ByKUipob.js";
|
|
3
|
-
import { c as queueBatchOptionsError, d as queueUnsupportedOptionsError, i as isQueueError, m as normalizeQueueEnqueueInput, o as normalizePublicQueueIdentifier, r as formatQueueOptionNames, t as readQueueTimes } from "./duration-
|
|
3
|
+
import { c as queueBatchOptionsError, d as queueUnsupportedOptionsError, i as isQueueError, m as normalizeQueueEnqueueInput, o as normalizePublicQueueIdentifier, r as formatQueueOptionNames, t as readQueueTimes } from "./duration-BZKArIBP.js";
|
|
4
4
|
import { t as resolveVercelQueueRegion } from "./vercel-region-Bp3hwRBr.js";
|
|
5
5
|
import { t as getCloudflareQueueBindingName } from "./cloudflare-BMc35cBD.js";
|
|
6
6
|
import { t as getVercelQueueTopicName } from "./vercel-sUJOxFBB.js";
|
|
@@ -1,44 +1,11 @@
|
|
|
1
|
-
import { c as queueBatchOptionsError, d as queueUnsupportedOptionsError, l as queueProviderResult, m as normalizeQueueEnqueueInput, o as normalizePublicQueueIdentifier, t as readQueueTimes, u as queueRemovedOptionsError } from "./duration-
|
|
1
|
+
import { c as queueBatchOptionsError, d as queueUnsupportedOptionsError, l as queueProviderResult, m as normalizeQueueEnqueueInput, o as normalizePublicQueueIdentifier, t as readQueueTimes, u as queueRemovedOptionsError } from "./duration-BZKArIBP.js";
|
|
2
2
|
import { t as queueErrorDiagnostics } from "./error-diagnostics-Yj8XCiya.js";
|
|
3
3
|
import { n as getCloudflareQueueDefinitionName } from "./cloudflare-BMc35cBD.js";
|
|
4
|
-
import { i as reportQueueDeliveryError, r as isNonRetryableQueueError, t as checkQueueHandlerResponse } from "./handler-response-
|
|
4
|
+
import { i as reportQueueDeliveryError, r as isNonRetryableQueueError, t as checkQueueHandlerResponse } from "./handler-response-DKhsmxDV.js";
|
|
5
5
|
import { n as queueRetryPolicy } from "./retries-BSAZru9n.js";
|
|
6
6
|
import { parseDuration } from "@vite-hub/runtime";
|
|
7
7
|
// src/providers/cloudflare.ts
|
|
8
8
|
const cloudflareBindingName = /^[A-Z_]\w{0,127}$/i;
|
|
9
|
-
function isCloudflareQueueBinding(binding) {
|
|
10
|
-
if (binding === null || typeof binding !== "object" || Array.isArray(binding)) return false;
|
|
11
|
-
const hasCallableMethod = (name) => {
|
|
12
|
-
let owner = binding;
|
|
13
|
-
while (owner && owner !== Object.prototype) {
|
|
14
|
-
let descriptor;
|
|
15
|
-
try {
|
|
16
|
-
descriptor = Object.getOwnPropertyDescriptor(owner, name);
|
|
17
|
-
} catch {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
if (descriptor) {
|
|
21
|
-
if (owner !== binding) {
|
|
22
|
-
const constructor = Object.getOwnPropertyDescriptor(owner, "constructor");
|
|
23
|
-
if (!constructor || !("value" in constructor) || typeof constructor.value !== "function" || constructor.value.prototype !== owner) return false;
|
|
24
|
-
}
|
|
25
|
-
if ("value" in descriptor) return typeof descriptor.value === "function";
|
|
26
|
-
try {
|
|
27
|
-
return typeof Reflect.get(binding, name) === "function";
|
|
28
|
-
} catch {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
owner = Object.getPrototypeOf(owner);
|
|
34
|
-
} catch {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return false;
|
|
39
|
-
};
|
|
40
|
-
return hasCallableMethod("send") && hasCallableMethod("sendBatch");
|
|
41
|
-
}
|
|
42
9
|
function toSendOptions(options = {}) {
|
|
43
10
|
const error = queueUnsupportedOptionsError(options, "cloudflare");
|
|
44
11
|
if (error) return [error, void 0];
|
|
@@ -108,8 +75,8 @@ function createCloudflareQueueClient(provider) {
|
|
|
108
75
|
const binding = typeof provider.binding === "string" && cloudflareBindingName.test(provider.binding) ? provider.binding : void 0;
|
|
109
76
|
throw queueErrorDiagnostics.QUEUE_BINDING_NOT_FOUND({ binding });
|
|
110
77
|
}
|
|
111
|
-
if (!isCloudflareQueueBinding(provider.binding)) throw queueErrorDiagnostics.QUEUE_INVALID_BINDING();
|
|
112
78
|
const binding = provider.binding;
|
|
79
|
+
if (typeof binding?.send !== "function" || typeof binding.sendBatch !== "function") throw queueErrorDiagnostics.QUEUE_INVALID_BINDING();
|
|
113
80
|
return {
|
|
114
81
|
provider: "cloudflare",
|
|
115
82
|
native: binding,
|
|
@@ -57,7 +57,7 @@ function queueRemovedOptionsError(provider, options, items = []) {
|
|
|
57
57
|
function queueBatchOptionsError(provider, options, items) {
|
|
58
58
|
const removed = queueRemovedOptionsError(provider, options, items);
|
|
59
59
|
if (removed) return removed;
|
|
60
|
-
if (options
|
|
60
|
+
if (options?.transaction !== void 0 || items.some((item) => item.transaction !== void 0)) return queueErrorDiagnostics.QUEUE_UNSUPPORTED_OPTION({
|
|
61
61
|
options: "`transaction`",
|
|
62
62
|
provider
|
|
63
63
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as isQueueError, o as normalizePublicQueueIdentifier } from "./duration-
|
|
1
|
+
import { i as isQueueError, o as normalizePublicQueueIdentifier } from "./duration-BZKArIBP.js";
|
|
2
2
|
import { getViteHubErrorShape } from "@vite-hub/runtime";
|
|
3
3
|
import { toResponse } from "@vite-hub/runtime/internal/response";
|
|
4
4
|
// src/internal/delivery-error.ts
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as defineQueue } from "./definition-Dorliu47.js";
|
|
2
|
-
import { p as createQueueMessageId } from "./duration-
|
|
3
|
-
import { a as useQueue, i as sendQueue, n as dynamicQueue, t as deferQueue } from "./client-
|
|
2
|
+
import { p as createQueueMessageId } from "./duration-BZKArIBP.js";
|
|
3
|
+
import { a as useQueue, i as sendQueue, n as dynamicQueue, t as deferQueue } from "./client-mT8TUaag.js";
|
|
4
4
|
import { t as queueErrorDiagnostics } from "./error-diagnostics-Yj8XCiya.js";
|
|
5
5
|
// src/runtime/create-client.ts
|
|
6
6
|
async function createQueueClient(options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as createCloudflareQueueRuntimeClient } from "../../cloudflare-client-
|
|
1
|
+
export { t as createCloudflareQueueRuntimeClient } from "../../cloudflare-client-DBgvWY0z.js";
|
|
@@ -2,8 +2,8 @@ import { t as internalErrorDiagnostics } from "../../error-diagnostics-CsiNo_oI.
|
|
|
2
2
|
import { n as normalizeQueueOptions } from "../../config-ByKUipob.js";
|
|
3
3
|
import { n as getCloudflareQueueDefinitionName } from "../../cloudflare-BMc35cBD.js";
|
|
4
4
|
import { t as getCloudflareQueueName } from "../../cloudflare-resource-name-Coz5CPmn.js";
|
|
5
|
-
import { n as createCloudflareQueueBatchHandler, t as createCloudflareQueueRuntimeClient } from "../../cloudflare-client-
|
|
6
|
-
import { t as runQueueHandler } from "../../run-handler-
|
|
5
|
+
import { n as createCloudflareQueueBatchHandler, t as createCloudflareQueueRuntimeClient } from "../../cloudflare-client-DBgvWY0z.js";
|
|
6
|
+
import { t as runQueueHandler } from "../../run-handler-COXFYL5z.js";
|
|
7
7
|
import { d as runWithQueueRuntimeEvent, f as setQueueRuntimeConfig, g as createCloudflareRuntimeEvent, h as setQueueRuntimeRegistry, l as loadQueueDefinition, v as runWithActiveCloudflareEnv } from "../../state-C-t99I4Q.js";
|
|
8
8
|
import { t as queueErrorDiagnostics } from "../../error-diagnostics-Yj8XCiya.js";
|
|
9
9
|
// ../internal/src/runtime/app.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as defaultLocalQueueBase } from "../../config-ByKUipob.js";
|
|
2
|
-
import { i as localQueueDeliveryRules, n as createLocalQueueEngine, t as createLocalQueueClient } from "../../local-
|
|
2
|
+
import { i as localQueueDeliveryRules, n as createLocalQueueEngine, t as createLocalQueueClient } from "../../local-5pcvR1RC.js";
|
|
3
3
|
import { l as loadQueueDefinition, u as missingQueueDefinitionError } from "../../state-C-t99I4Q.js";
|
|
4
4
|
import { t as queueErrorDiagnostics } from "../../error-diagnostics-Yj8XCiya.js";
|
|
5
5
|
import { resolve } from "pathe";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { i as queueWorkersVariable, r as postgresQueueUrlVariable } from "../../config-ByKUipob.js";
|
|
2
2
|
import { t as invariant } from "../../invariant-CmdvZ3vp.js";
|
|
3
|
-
import { c as queueBatchOptionsError, d as queueUnsupportedOptionsError, i as isQueueError, l as queueProviderResult, m as normalizeQueueEnqueueInput, p as createQueueMessageId, s as postgresUnsupportedEnqueueOptions, t as readQueueTimes } from "../../duration-
|
|
3
|
+
import { c as queueBatchOptionsError, d as queueUnsupportedOptionsError, i as isQueueError, l as queueProviderResult, m as normalizeQueueEnqueueInput, p as createQueueMessageId, s as postgresUnsupportedEnqueueOptions, t as readQueueTimes } from "../../duration-BZKArIBP.js";
|
|
4
4
|
import { t as queueErrorDiagnostics } from "../../error-diagnostics-Yj8XCiya.js";
|
|
5
|
-
import { i as reportQueueDeliveryError, n as createQueueDeliveryErrorReport, r as isNonRetryableQueueError } from "../../handler-response-
|
|
6
|
-
import { n as isRecord } from "../../object-DRSmpe04.js";
|
|
5
|
+
import { i as reportQueueDeliveryError, n as createQueueDeliveryErrorReport, r as isNonRetryableQueueError } from "../../handler-response-DKhsmxDV.js";
|
|
6
|
+
import { n as isRecord, r as isRecordOrFunction } from "../../object-DRSmpe04.js";
|
|
7
7
|
import { n as queueRetryPolicy } from "../../retries-BSAZru9n.js";
|
|
8
|
-
import { n as runQueueJob } from "../../run-handler-
|
|
9
|
-
import { i as localQueueDeliveryRules, r as delayMs } from "../../local-
|
|
8
|
+
import { n as runQueueJob } from "../../run-handler-COXFYL5z.js";
|
|
9
|
+
import { i as localQueueDeliveryRules, r as delayMs } from "../../local-5pcvR1RC.js";
|
|
10
10
|
import { c as listQueueDefinitionNames, l as loadQueueDefinition, m as setQueueRuntimeJobStore, u as missingQueueDefinitionError } from "../../state-C-t99I4Q.js";
|
|
11
11
|
import { hostname } from "node:os";
|
|
12
12
|
import { randomUUID } from "node:crypto";
|
|
@@ -20,7 +20,7 @@ function readRows(value) {
|
|
|
20
20
|
function postgresTransactionQuery(transaction) {
|
|
21
21
|
const session = isRecord(transaction) && typeof transaction.rollback === "function" && isRecord(transaction._) ? transaction._.session : void 0;
|
|
22
22
|
const client = isRecord(session) ? session.client : void 0;
|
|
23
|
-
const query =
|
|
23
|
+
const query = isRecord(client) ? client.query : isRecordOrFunction(client) ? client.unsafe : void 0;
|
|
24
24
|
if (typeof query !== "function") throw queueErrorDiagnostics.QUEUE_TRANSACTION_DATABASE_MISMATCH({ reason: "driver" });
|
|
25
25
|
const active = Reflect.get(transaction, transactionActive);
|
|
26
26
|
if (typeof active !== "function") throw queueErrorDiagnostics.QUEUE_TRANSACTION_DATABASE_MISMATCH({ reason: "driver" });
|
|
@@ -30,7 +30,7 @@ function postgresTransactionQuery(transaction) {
|
|
|
30
30
|
assertActive();
|
|
31
31
|
return (text, params) => {
|
|
32
32
|
assertActive();
|
|
33
|
-
const pending =
|
|
33
|
+
const pending = query.call(client, text, params);
|
|
34
34
|
return new Promise((resolve, reject) => pending.then(resolve, reject)).then(readRows);
|
|
35
35
|
};
|
|
36
36
|
}
|
|
@@ -564,8 +564,8 @@ function createPostgresQueueClient(engine, queue, resolveEngine) {
|
|
|
564
564
|
};
|
|
565
565
|
}
|
|
566
566
|
// src/internal/runtime/postgres-client.ts
|
|
567
|
-
const postgresUrl = /^postgres(?:ql)?:\/\//i;
|
|
568
567
|
const databaseConnectionUrl = Symbol.for("vitehub.database.postgres.connection-url");
|
|
568
|
+
const postgresUrl = /^postgres(?:ql)?:\/\//i;
|
|
569
569
|
let loadDatabases;
|
|
570
570
|
let closing;
|
|
571
571
|
const engines = /* @__PURE__ */ new Map();
|
|
@@ -610,13 +610,13 @@ async function resolvePostgresQueueConnection(config, databases = loadDatabases,
|
|
|
610
610
|
};
|
|
611
611
|
}
|
|
612
612
|
if (config.database && databases) {
|
|
613
|
-
const
|
|
614
|
-
const client =
|
|
613
|
+
const database = (await databases())[config.database]?.db;
|
|
614
|
+
const client = database?.$client;
|
|
615
615
|
if (isPostgresQueueSql(client)) return {
|
|
616
616
|
connection: { client },
|
|
617
617
|
key: client
|
|
618
618
|
};
|
|
619
|
-
const readUrl =
|
|
619
|
+
const readUrl = database?.[databaseConnectionUrl];
|
|
620
620
|
const databaseUrl = typeof readUrl === "function" ? readUrl() : void 0;
|
|
621
621
|
if (typeof databaseUrl === "string") return {
|
|
622
622
|
connection: { url: databaseUrl },
|
|
@@ -1,53 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as isRecord } from "../../object-DRSmpe04.js";
|
|
2
|
+
import { c as queueBatchOptionsError, d as queueUnsupportedOptionsError, l as queueProviderResult, m as normalizeQueueEnqueueInput, p as createQueueMessageId, t as readQueueTimes } from "../../duration-BZKArIBP.js";
|
|
2
3
|
import { t as queueErrorDiagnostics } from "../../error-diagnostics-Yj8XCiya.js";
|
|
3
4
|
import { t as resolveVercelQueueRegion } from "../../vercel-region-Bp3hwRBr.js";
|
|
4
5
|
// src/providers/vercel.ts
|
|
5
6
|
function invalidVercelSendResponse(cause) {
|
|
6
7
|
return [queueErrorDiagnostics.QUEUE_PROVIDER_INVALID_RESPONSE({ cause }), void 0];
|
|
7
8
|
}
|
|
8
|
-
function isVercelQueueSDK(value) {
|
|
9
|
-
if (value === null || typeof value !== "object") return false;
|
|
10
|
-
try {
|
|
11
|
-
if (Array.isArray(value)) return false;
|
|
12
|
-
} catch {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
const hasCallableMethod = (name) => {
|
|
16
|
-
let owner = value;
|
|
17
|
-
while (owner && owner !== Object.prototype) {
|
|
18
|
-
let descriptor;
|
|
19
|
-
try {
|
|
20
|
-
descriptor = Object.getOwnPropertyDescriptor(owner, name);
|
|
21
|
-
} catch {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
if (descriptor) {
|
|
25
|
-
if (owner !== value) {
|
|
26
|
-
let constructor;
|
|
27
|
-
try {
|
|
28
|
-
constructor = Object.getOwnPropertyDescriptor(owner, "constructor");
|
|
29
|
-
if (!constructor || !("value" in constructor) || typeof constructor.value !== "function" || constructor.value.prototype !== owner) return false;
|
|
30
|
-
} catch {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
if ("value" in descriptor) return typeof descriptor.value === "function";
|
|
35
|
-
try {
|
|
36
|
-
return typeof Reflect.get(value, name) === "function";
|
|
37
|
-
} catch {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
owner = Object.getPrototypeOf(owner);
|
|
43
|
-
} catch {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return false;
|
|
48
|
-
};
|
|
49
|
-
return hasCallableMethod("send") && hasCallableMethod("handleCallback");
|
|
50
|
-
}
|
|
51
9
|
function batchRejected(results) {
|
|
52
10
|
const failed = results.filter((result) => result.status === "failed").length;
|
|
53
11
|
return Object.assign(queueErrorDiagnostics.QUEUE_VERCEL_BATCH_REJECTED({
|
|
@@ -69,14 +27,8 @@ function parseVercelBatchResults(value, length) {
|
|
|
69
27
|
return [void 0, results];
|
|
70
28
|
}
|
|
71
29
|
function parseVercelMessageId(value) {
|
|
72
|
-
if (!value ||
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
if (!Object.prototype.hasOwnProperty.call(value, "messageId")) return invalidVercelSendResponse(value);
|
|
76
|
-
messageId = Reflect.get(value, "messageId");
|
|
77
|
-
} catch (cause) {
|
|
78
|
-
return invalidVercelSendResponse(cause);
|
|
79
|
-
}
|
|
30
|
+
if (!isRecord(value) || !Object.hasOwn(value, "messageId")) return invalidVercelSendResponse(value);
|
|
31
|
+
const messageId = value.messageId;
|
|
80
32
|
if (messageId === null) return [void 0, void 0];
|
|
81
33
|
if (typeof messageId !== "string" || !messageId || messageId.length > 128 || messageId.trim() !== messageId) return invalidVercelSendResponse(value);
|
|
82
34
|
return [void 0, messageId];
|
|
@@ -134,7 +86,7 @@ async function createVercelQueueClient(provider) {
|
|
|
134
86
|
const topic = provider.topic;
|
|
135
87
|
if (!topic) throw queueErrorDiagnostics.QUEUE_MISSING_TOPIC();
|
|
136
88
|
const client = provider.client === void 0 ? await loadVercelQueueClient(provider.region) : provider.client;
|
|
137
|
-
if (
|
|
89
|
+
if (typeof client?.send !== "function" || typeof client.handleCallback !== "function") throw queueErrorDiagnostics.QUEUE_VERCEL_SDK_INVALID();
|
|
138
90
|
return {
|
|
139
91
|
provider: "vercel",
|
|
140
92
|
native: client,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as localUnsupportedEnqueueOptions, c as queueBatchOptionsError, d as queueUnsupportedOptionsError, f as vercelUnsupportedEnqueueOptions, l as queueProviderResult, m as normalizeQueueEnqueueInput, n as cloudflareUnsupportedEnqueueOptions, p as createQueueMessageId, s as postgresUnsupportedEnqueueOptions, t as readQueueTimes } from "./duration-
|
|
2
|
-
import { i as reportQueueDeliveryError, n as createQueueDeliveryErrorReport, r as isNonRetryableQueueError } from "./handler-response-
|
|
1
|
+
import { a as localUnsupportedEnqueueOptions, c as queueBatchOptionsError, d as queueUnsupportedOptionsError, f as vercelUnsupportedEnqueueOptions, l as queueProviderResult, m as normalizeQueueEnqueueInput, n as cloudflareUnsupportedEnqueueOptions, p as createQueueMessageId, s as postgresUnsupportedEnqueueOptions, t as readQueueTimes } from "./duration-BZKArIBP.js";
|
|
2
|
+
import { i as reportQueueDeliveryError, n as createQueueDeliveryErrorReport, r as isNonRetryableQueueError } from "./handler-response-DKhsmxDV.js";
|
|
3
3
|
import { n as queueRetryPolicy } from "./retries-BSAZru9n.js";
|
|
4
|
-
import { n as runQueueJob } from "./run-handler-
|
|
4
|
+
import { n as runQueueJob } from "./run-handler-COXFYL5z.js";
|
|
5
5
|
import { t as queueErrorDiagnostics } from "./error-diagnostics-Yj8XCiya.js";
|
|
6
6
|
import { mkdir, readFile, readdir, rename, rm, writeFile } from "node:fs/promises";
|
|
7
7
|
import { join, resolve } from "pathe";
|
|
@@ -154,6 +154,7 @@ function createLocalQueueEngine(options) {
|
|
|
154
154
|
let closed = false;
|
|
155
155
|
const file = (job) => join(base, `${job.key}.json`);
|
|
156
156
|
const attemptInFlight = (job) => runningKeys.has(job.key) || expiringKeys.has(job.key);
|
|
157
|
+
const keyHeld = (job) => job.idempotencyKey !== void 0 && [...jobs.values()].some((other) => other.key !== job.key && other.queue === job.queue && other.idempotencyKey === job.idempotencyKey && (other.state === "pending" || attemptInFlight(other)));
|
|
157
158
|
function mutate(run) {
|
|
158
159
|
const result = mutationTail.then(run);
|
|
159
160
|
mutationTail = result.then(() => void 0, () => void 0);
|
|
@@ -465,6 +466,7 @@ function createLocalQueueEngine(options) {
|
|
|
465
466
|
const job = findJob(id);
|
|
466
467
|
if (!job) return "missing";
|
|
467
468
|
if (attemptInFlight(job)) return "running";
|
|
469
|
+
if (job.state === "dead" && keyHeld(job)) return "duplicate";
|
|
468
470
|
writingKeys.add(job.key);
|
|
469
471
|
let retry;
|
|
470
472
|
try {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as redactInspectionText } from "./inspect-CwdWUhPj.js";
|
|
2
2
|
import { t as queueErrorDiagnostics } from "./error-diagnostics-Yj8XCiya.js";
|
|
3
|
-
import { i as isQueueError, o as normalizePublicQueueIdentifier } from "./duration-
|
|
3
|
+
import { i as isQueueError, o as normalizePublicQueueIdentifier } from "./duration-BZKArIBP.js";
|
|
4
4
|
import { c as listQueueDefinitionNames, i as getQueueRuntimeConfig, o as getQueueRuntimeJobStore, s as getQueueRuntimeJobWorkers } from "./state-C-t99I4Q.js";
|
|
5
|
-
import { n as dynamicQueue } from "./client-
|
|
5
|
+
import { n as dynamicQueue } from "./client-mT8TUaag.js";
|
|
6
6
|
import { runtimeErrorDiagnostics } from "@vite-hub/runtime/internal/error-diagnostics";
|
|
7
7
|
// src/runtime/operations.ts
|
|
8
8
|
const statuses = {
|
package/dist/operations.js
CHANGED
|
@@ -525,7 +525,7 @@ function pipe(...pipe$1) {
|
|
|
525
525
|
});
|
|
526
526
|
}
|
|
527
527
|
// src/operations.ts
|
|
528
|
-
const runtime = () => import("./operations-
|
|
528
|
+
const runtime = () => import("./operations-BSouq47k.js");
|
|
529
529
|
function defineQueueOperation(definition) {
|
|
530
530
|
return defineOperation({
|
|
531
531
|
...definition,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as queueErrorDiagnostics } from "./error-diagnostics-Yj8XCiya.js";
|
|
2
|
-
import { t as checkQueueHandlerResponse } from "./handler-response-
|
|
2
|
+
import { t as checkQueueHandlerResponse } from "./handler-response-DKhsmxDV.js";
|
|
3
3
|
import { parseDuration } from "@vite-hub/runtime";
|
|
4
4
|
import { runInRunScopes } from "@vite-hub/runtime/internal/run-scope";
|
|
5
5
|
// src/internal/run-handler.ts
|
package/dist/runtime/hosted.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as queueErrorDiagnostics } from "../error-diagnostics-Yj8XCiya.js";
|
|
2
|
-
import { i as reportQueueDeliveryError, r as isNonRetryableQueueError } from "../handler-response-
|
|
2
|
+
import { i as reportQueueDeliveryError, r as isNonRetryableQueueError } from "../handler-response-DKhsmxDV.js";
|
|
3
3
|
import { n as queueRetryPolicy } from "../retries-BSAZru9n.js";
|
|
4
|
-
import { n as runQueueJob } from "../run-handler-
|
|
5
|
-
import { r as loadQueueClient } from "../client-
|
|
4
|
+
import { n as runQueueJob } from "../run-handler-COXFYL5z.js";
|
|
5
|
+
import { r as loadQueueClient } from "../client-mT8TUaag.js";
|
|
6
6
|
import { waitUntil } from "@vercel/functions";
|
|
7
7
|
// src/runtime/hosted.ts
|
|
8
8
|
const hostedVercelWaitUntil = waitUntil;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { r as readSourceText, t as deriveFromSource } from "./source-files-DrAH1-c8.js";
|
|
1
2
|
import { parseSync } from "vite";
|
|
2
3
|
// ../internal/src/build/ast-walk.ts
|
|
3
4
|
/** The oxc parser grammar for a file, from its extension. Defaults to TypeScript. */
|
|
@@ -45,8 +46,22 @@ function scanModule(source, file = "module.ts") {
|
|
|
45
46
|
source
|
|
46
47
|
};
|
|
47
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Reads and parses a source file once for each change of its text. Callers share the result, so they must not change
|
|
51
|
+
* the syntax tree.
|
|
52
|
+
*/
|
|
53
|
+
function scanSourceFile(file) {
|
|
54
|
+
return scanModuleText(readSourceText(file), file);
|
|
55
|
+
}
|
|
56
|
+
/** `scanModule` with a result that is shared while `source` stays the same for `file`. */
|
|
57
|
+
function scanModuleText(source, file) {
|
|
58
|
+
return deriveFromSource("scan-module", file, source, () => scanModule(source, file));
|
|
59
|
+
}
|
|
48
60
|
/** Lists the names that a module exports. A default export reads as `default`. Type-only exports are left out. */
|
|
49
61
|
function exportNames(source, file = "module.ts") {
|
|
62
|
+
return [...deriveFromSource("export-names", file, source, () => readExportNames(source, file))];
|
|
63
|
+
}
|
|
64
|
+
function readExportNames(source, file) {
|
|
50
65
|
const { module } = parseSync(file, source, {
|
|
51
66
|
lang: moduleLanguage(file),
|
|
52
67
|
sourceType: "module"
|
|
@@ -306,4 +321,4 @@ function templateExpressionSources(template) {
|
|
|
306
321
|
if (literal.type !== "TemplateLiteral") return [];
|
|
307
322
|
return literal.expressions.map((_node, index) => module.source.slice(literal.quasis[index]?.end ?? 0, literal.quasis[index + 1]?.start ?? 0));
|
|
308
323
|
}
|
|
309
|
-
export { argumentExpression, defaultExportExpression, dynamic, exportNames, findCalls, findDefaultExportCall, findProperty, maskLiterals, moduleTokens, nodeText, objectProperties, scanModule, staticString, staticValue, templateExpressionSources, unwrapExpression, walk };
|
|
324
|
+
export { argumentExpression, defaultExportExpression, dynamic, exportNames, findCalls, findDefaultExportCall, findProperty, maskLiterals, moduleTokens, nodeText, objectProperties, scanModule, scanModuleText, scanSourceFile, staticString, staticValue, templateExpressionSources, unwrapExpression, walk };
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { resolve } from "pathe";
|
|
3
|
+
// ../internal/src/source-files.ts
|
|
4
|
+
const ignoredDirs = /* @__PURE__ */ new Set([
|
|
5
|
+
"node_modules",
|
|
6
|
+
"dist",
|
|
7
|
+
".output",
|
|
8
|
+
".nuxt",
|
|
9
|
+
".vercel",
|
|
10
|
+
".git",
|
|
11
|
+
".vitehub"
|
|
12
|
+
]);
|
|
13
|
+
const racyWindowNs = 2000000000n;
|
|
14
|
+
const storeKey = Symbol.for("vite-hub.source-files.v1");
|
|
15
|
+
function store() {
|
|
16
|
+
const existing = Reflect.get(globalThis, storeKey);
|
|
17
|
+
if (isStore(existing)) return existing;
|
|
18
|
+
const created = {
|
|
19
|
+
derived: /* @__PURE__ */ new Map(),
|
|
20
|
+
texts: /* @__PURE__ */ new Map(),
|
|
21
|
+
trees: /* @__PURE__ */ new Map()
|
|
22
|
+
};
|
|
23
|
+
Reflect.set(globalThis, storeKey, created);
|
|
24
|
+
return created;
|
|
25
|
+
}
|
|
26
|
+
function isStore(value) {
|
|
27
|
+
return typeof value === "object" && value !== null && "texts" in value && "trees" in value && "derived" in value;
|
|
28
|
+
}
|
|
29
|
+
function errorCode(error) {
|
|
30
|
+
return typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
|
|
31
|
+
}
|
|
32
|
+
function statOrMissing(path) {
|
|
33
|
+
try {
|
|
34
|
+
return statSync(path, { bigint: true });
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (errorCode(error) === "ENOENT" || errorCode(error) === "ENOTDIR") return;
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function signature(stats) {
|
|
41
|
+
return `${stats.ino}:${stats.size}:${stats.mtimeNs}:${stats.ctimeNs}`;
|
|
42
|
+
}
|
|
43
|
+
function isSettled(stats) {
|
|
44
|
+
const changed = stats.mtimeNs > stats.ctimeNs ? stats.mtimeNs : stats.ctimeNs;
|
|
45
|
+
return BigInt(Date.now()) * 1000000n - changed > racyWindowNs;
|
|
46
|
+
}
|
|
47
|
+
function readDirEntries(root) {
|
|
48
|
+
try {
|
|
49
|
+
return readdirSync(root, { withFileTypes: true });
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (errorCode(error) === "ENOENT") return [];
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function walkTree(root, directories, files, nested = false) {
|
|
56
|
+
const before = statOrMissing(root);
|
|
57
|
+
let trusted = before !== void 0 && isSettled(before);
|
|
58
|
+
if (before) directories.set(root, signature(before));
|
|
59
|
+
if (nested && existsSync(resolve(root, ".git"))) return trusted;
|
|
60
|
+
for (const entry of readDirEntries(root)) {
|
|
61
|
+
const path = resolve(root, entry.name);
|
|
62
|
+
if (entry.isDirectory() && !entry.isSymbolicLink()) {
|
|
63
|
+
if (entry.name.startsWith(".") || ignoredDirs.has(entry.name)) continue;
|
|
64
|
+
if (!walkTree(path, directories, files, true)) trusted = false;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (entry.isFile()) files.push({
|
|
68
|
+
hidden: entry.name.startsWith("."),
|
|
69
|
+
name: entry.name,
|
|
70
|
+
path
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return trusted;
|
|
74
|
+
}
|
|
75
|
+
function isCurrent(tree) {
|
|
76
|
+
for (const [directory, stored] of tree.directories) {
|
|
77
|
+
const stats = statOrMissing(directory);
|
|
78
|
+
if (!stats || signature(stats) !== stored) return false;
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
function sourceTree(root) {
|
|
83
|
+
const trees = store().trees;
|
|
84
|
+
const cached = trees.get(root);
|
|
85
|
+
if (cached && isCurrent(cached)) return cached;
|
|
86
|
+
const directories = /* @__PURE__ */ new Map();
|
|
87
|
+
const files = [];
|
|
88
|
+
const trusted = walkTree(root, directories, files);
|
|
89
|
+
files.sort((left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0);
|
|
90
|
+
const tree = {
|
|
91
|
+
directories,
|
|
92
|
+
files
|
|
93
|
+
};
|
|
94
|
+
if (trusted) trees.set(root, tree);
|
|
95
|
+
else trees.delete(root);
|
|
96
|
+
return tree;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The files below `root` whose name matches `predicate`, sorted by path. The walk skips hidden folders, Git
|
|
100
|
+
* repositories, and build output folders such as `node_modules`, `dist`, and `.vitehub`. Hidden files need
|
|
101
|
+
* `includeHidden`. Symbolic links are skipped.
|
|
102
|
+
*/
|
|
103
|
+
function listSourceTreeFiles(root, predicate, options = {}) {
|
|
104
|
+
const files = [];
|
|
105
|
+
for (const file of sourceTree(resolve(root)).files) {
|
|
106
|
+
if (file.hidden && !options.includeHidden) continue;
|
|
107
|
+
if (predicate(file.name)) files.push(file.path);
|
|
108
|
+
}
|
|
109
|
+
return files;
|
|
110
|
+
}
|
|
111
|
+
/** The UTF-8 text of a source file. A file that did not change since the last read is not read again. */
|
|
112
|
+
function readSourceText(file) {
|
|
113
|
+
const path = resolve(file);
|
|
114
|
+
const texts = store().texts;
|
|
115
|
+
const stats = statOrMissing(path);
|
|
116
|
+
if (!stats) return readFileSync(path, "utf8");
|
|
117
|
+
const current = signature(stats);
|
|
118
|
+
const cached = texts.get(path);
|
|
119
|
+
if (cached?.trusted && cached.signature === current) return cached.text;
|
|
120
|
+
const read = readFileSync(path, "utf8");
|
|
121
|
+
const text = cached?.text === read ? cached.text : read;
|
|
122
|
+
texts.set(path, {
|
|
123
|
+
signature: current,
|
|
124
|
+
text,
|
|
125
|
+
trusted: isSettled(stats)
|
|
126
|
+
});
|
|
127
|
+
return text;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* A value that `compute` derives from the text of a source file, such as its syntax tree. The value is computed again
|
|
131
|
+
* only when the text changes. `kind` separates the values of different callers for one file. The last two texts of a
|
|
132
|
+
* file are kept, because some callers read both the file and its transformed code.
|
|
133
|
+
*/
|
|
134
|
+
function deriveFromSource(kind, file, source, compute) {
|
|
135
|
+
const derived = store().derived;
|
|
136
|
+
const key = `${kind}\0${file}`;
|
|
137
|
+
const entries = derived.get(key) ?? [];
|
|
138
|
+
const cached = entries.find((entry) => entry.source === source);
|
|
139
|
+
if (cached) return cached.value;
|
|
140
|
+
const value = compute();
|
|
141
|
+
derived.set(key, [{
|
|
142
|
+
source,
|
|
143
|
+
value
|
|
144
|
+
}, ...entries.slice(0, 1)]);
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
export { listSourceTreeFiles as n, readSourceText as r, deriveFromSource as t };
|
package/dist/vite.js
CHANGED
|
@@ -3,13 +3,14 @@ import { t as internalErrorDiagnostics } from "./error-diagnostics-CsiNo_oI.js";
|
|
|
3
3
|
import { n as isRecord, r as isRecordOrFunction, t as cloneRecord } from "./object-DRSmpe04.js";
|
|
4
4
|
import { a as getHostingProvider, i as queueWorkersVariable, n as normalizeQueueOptions, o as resolveHost, r as postgresQueueUrlVariable, s as resolveHostPreset, t as defaultLocalQueueBase } from "./config-ByKUipob.js";
|
|
5
5
|
import { t as queueErrorDiagnostics } from "./error-diagnostics-Yj8XCiya.js";
|
|
6
|
+
import { n as listSourceTreeFiles } from "./source-files-DrAH1-c8.js";
|
|
6
7
|
import { n as isQueueMaxBatchSize } from "./definition-Dorliu47.js";
|
|
7
8
|
import { t as getCloudflareQueueBindingName } from "./cloudflare-BMc35cBD.js";
|
|
8
9
|
import { t as getVercelQueueTopicName } from "./vercel-sUJOxFBB.js";
|
|
9
10
|
import { t as getCloudflareQueueName } from "./cloudflare-resource-name-Coz5CPmn.js";
|
|
10
11
|
import { n as summarizeDefinitions } from "./inspect-CwdWUhPj.js";
|
|
11
12
|
import { createRequire } from "node:module";
|
|
12
|
-
import { existsSync, readFileSync,
|
|
13
|
+
import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
13
14
|
import { tmpdir } from "node:os";
|
|
14
15
|
import { basename, dirname, isAbsolute, parse, resolve } from "node:path";
|
|
15
16
|
import { fileURLToPath } from "node:url";
|
|
@@ -124,18 +125,26 @@ function isMissingProjectMarker(error) {
|
|
|
124
125
|
const code = error.code;
|
|
125
126
|
return code === "ENOENT" || code === "ENOTDIR";
|
|
126
127
|
}
|
|
128
|
+
/** The owner of the generated code that a Vite or Nuxt config writes, from the CLI discovery and Node test markers. */
|
|
129
|
+
function viteHubGeneratedOwner(config) {
|
|
130
|
+
if (Reflect.get(config, "vitehubNodeTest") === true) return "node-test";
|
|
131
|
+
return Reflect.get(config, "vitehubCliDiscovery") === true ? "cli" : "app";
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The generated-code folder of an owner, relative to the project root: `.vitehub` for the app, `.vitehub/cli` and
|
|
135
|
+
* `.vitehub/node-test` for the others. State that the processes share, such as the Email outbox or the Env secret,
|
|
136
|
+
* stays in `.vitehub`, and so do the declaration files that TypeScript reads, because their contents follow only the
|
|
137
|
+
* Definitions.
|
|
138
|
+
*/
|
|
139
|
+
function viteHubGeneratedCodeDir(owner = "app") {
|
|
140
|
+
return owner === "app" ? ".vitehub" : `.vitehub/${owner}`;
|
|
141
|
+
}
|
|
127
142
|
// ../internal/src/durability.ts
|
|
128
143
|
/** The `durability` module next to the Vite plugin module at `importMetaUrl`, in source and in `dist`. */
|
|
129
144
|
function durabilityModuleFile(importMetaUrl) {
|
|
130
145
|
return fileURLToPath(new URL(importMetaUrl.endsWith(".ts") ? "./durability.ts" : "./durability.js", importMetaUrl));
|
|
131
146
|
}
|
|
132
147
|
// ../internal/src/build/paths.ts
|
|
133
|
-
function generatedDirSegments(productName) {
|
|
134
|
-
return [".vitehub", productName];
|
|
135
|
-
}
|
|
136
|
-
function ensureGeneratedDir(rootDir, productName) {
|
|
137
|
-
return resolve$1(rootDir, ...generatedDirSegments(productName));
|
|
138
|
-
}
|
|
139
148
|
function computePackageDir(importMetaUrl) {
|
|
140
149
|
const currentFileDir = dirname$1(fileURLToPath(importMetaUrl));
|
|
141
150
|
return resolve$1(currentFileDir, basename$1(currentFileDir) === "internal" ? "../.." : "..");
|
|
@@ -1207,15 +1216,6 @@ function queueDeploymentEnv(queue) {
|
|
|
1207
1216
|
const sourceFilePattern = /\.(?:c|m)?[jt]sx?$/i;
|
|
1208
1217
|
const declarationFilePattern = /\.d\.(?:c|m)?[jt]sx?$/i;
|
|
1209
1218
|
const testFilePattern = /\.(?:test|spec)\.(?:c|m)?[jt]sx?$/i;
|
|
1210
|
-
const ignoredDirs = /* @__PURE__ */ new Set([
|
|
1211
|
-
"node_modules",
|
|
1212
|
-
"dist",
|
|
1213
|
-
".output",
|
|
1214
|
-
".nuxt",
|
|
1215
|
-
".vercel",
|
|
1216
|
-
".git",
|
|
1217
|
-
".vitehub"
|
|
1218
|
-
]);
|
|
1219
1219
|
function resolveDefinitionScanRoots(rootDir, scanDirs = []) {
|
|
1220
1220
|
return [...new Set([rootDir, ...scanDirs].filter(Boolean))];
|
|
1221
1221
|
}
|
|
@@ -1238,32 +1238,8 @@ function createSuffixDefinitionSource(source, roots, pattern, normalizeName, opt
|
|
|
1238
1238
|
source
|
|
1239
1239
|
};
|
|
1240
1240
|
}
|
|
1241
|
-
function readDirEntries(root) {
|
|
1242
|
-
try {
|
|
1243
|
-
return readdirSync(root, { withFileTypes: true });
|
|
1244
|
-
} catch (error) {
|
|
1245
|
-
if (error.code === "ENOENT") return [];
|
|
1246
|
-
throw error;
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
function isGitRepositoryDirectory(directory) {
|
|
1250
|
-
return existsSync(resolve$1(directory, ".git"));
|
|
1251
|
-
}
|
|
1252
1241
|
function listMatchingFiles(root, predicate, options = {}) {
|
|
1253
|
-
|
|
1254
|
-
for (const entry of readDirEntries(root)) {
|
|
1255
|
-
const absolute = resolve$1(root, entry.name);
|
|
1256
|
-
if (entry.isDirectory() && !entry.isSymbolicLink()) {
|
|
1257
|
-
if (isGitRepositoryDirectory(absolute)) continue;
|
|
1258
|
-
if (entry.name.startsWith(".")) continue;
|
|
1259
|
-
if (ignoredDirs.has(entry.name)) continue;
|
|
1260
|
-
files.push(...listMatchingFiles(absolute, predicate, options));
|
|
1261
|
-
continue;
|
|
1262
|
-
}
|
|
1263
|
-
if (entry.name.startsWith(".") && !options.includeHidden) continue;
|
|
1264
|
-
if (entry.isFile() && predicate(entry.name)) files.push(absolute);
|
|
1265
|
-
}
|
|
1266
|
-
return files.sort();
|
|
1242
|
+
return listSourceTreeFiles(root, predicate, options);
|
|
1267
1243
|
}
|
|
1268
1244
|
/** A module that a Definitions folder can hold: JavaScript or TypeScript, and not a declaration, test, or spec file. */
|
|
1269
1245
|
function isDefinitionSourceFile(name) {
|
|
@@ -1414,10 +1390,17 @@ async function writeQueueTypes(root, definitions, importBase = "@vite-hub/queue"
|
|
|
1414
1390
|
const queuePackageName = "@vite-hub/queue";
|
|
1415
1391
|
const productName = "queue";
|
|
1416
1392
|
const generatedRegistryFileName = "registry.mjs";
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
const
|
|
1420
|
-
|
|
1393
|
+
/** The generated Queue files of an owner, relative to the project root. */
|
|
1394
|
+
function queueGeneratedPaths(owner = "app") {
|
|
1395
|
+
const dir = viteHubGeneratedCodeDir(owner);
|
|
1396
|
+
return {
|
|
1397
|
+
middleware: `${dir}/nitro/queue/middleware.ts`,
|
|
1398
|
+
plugin: `${dir}/nitro/queue/plugin.ts`,
|
|
1399
|
+
registryDir: `${dir}/${productName}`,
|
|
1400
|
+
testSetup: `${dir}/${productName}/test-setup.mjs`,
|
|
1401
|
+
vercelConsumerDir: `${dir}/nitro/queue/vercel`
|
|
1402
|
+
};
|
|
1403
|
+
}
|
|
1421
1404
|
const vercelQueueFunctionEnv = "VITEHUB_VERCEL_QUEUE_FUNCTION";
|
|
1422
1405
|
const vercelQueueConsumerRoutePrefix = "/api/vitehub/queues/vercel";
|
|
1423
1406
|
const packageDir = computePackageDir(import.meta.url);
|
|
@@ -1523,7 +1506,7 @@ function readQueueConsumerOptions(file, { argumentExpression, defaultExportExpre
|
|
|
1523
1506
|
async function createCloudflareQueueBindings(definitions, namePrefix = "") {
|
|
1524
1507
|
if (!definitions.length) return;
|
|
1525
1508
|
createCloudflareQueueDefinitionNames(definitions, namePrefix);
|
|
1526
|
-
const scanner = await import("./scan-module-
|
|
1509
|
+
const scanner = await import("./scan-module-3HfnrGbT.js");
|
|
1527
1510
|
return {
|
|
1528
1511
|
consumers: definitions.map((definition) => {
|
|
1529
1512
|
return {
|
|
@@ -1596,18 +1579,19 @@ function renderNitroMiddleware(middlewareFile, queueConfig, hasDefinitions, deve
|
|
|
1596
1579
|
].join("\n");
|
|
1597
1580
|
}
|
|
1598
1581
|
/** Writes the generated Queue integration and returns the Queue config that its Nitro plugin uses. */
|
|
1599
|
-
async function writeQueueNitroIntegration(rootDir, queue, hosting, cloudflareQueues = true, definitions = discoverQueueDefinitions({ rootDir }), development = false, importBase = queuePackageName, database = {}) {
|
|
1582
|
+
async function writeQueueNitroIntegration(rootDir, queue, hosting, cloudflareQueues = true, definitions = discoverQueueDefinitions({ rootDir }), development = false, importBase = queuePackageName, database = {}, owner = "app") {
|
|
1583
|
+
const paths = queueGeneratedPaths(owner);
|
|
1600
1584
|
await writeQueueTypes(rootDir, definitions, importBase);
|
|
1601
|
-
const generatedDir =
|
|
1585
|
+
const generatedDir = resolve(rootDir, paths.registryDir);
|
|
1602
1586
|
const registryFile = resolve(generatedDir, generatedRegistryFileName);
|
|
1603
|
-
const pluginFile = resolve(rootDir,
|
|
1604
|
-
const middlewareFile = resolve(rootDir,
|
|
1587
|
+
const pluginFile = resolve(rootDir, paths.plugin);
|
|
1588
|
+
const middlewareFile = resolve(rootDir, paths.middleware);
|
|
1605
1589
|
const queueConfig = resolveOutputQueueConfig(typeof queue === "undefined" ? {} : queue, hosting, database.postgres === true);
|
|
1606
1590
|
const queueDefinitions = cloudflareQueues && queueConfig !== false && queueConfig.driver === "cloudflare" ? createCloudflareQueueDefinitionNames(definitions, queueConfig.namePrefix) : {};
|
|
1607
1591
|
const runtimeConfig = resolveRuntimeQueueConfig(queueConfig, development, rootDir);
|
|
1608
1592
|
await Promise.all([mkdir(dirname(pluginFile), { recursive: true }), mkdir(generatedDir, { recursive: true })]);
|
|
1609
|
-
const vercelConsumerDir = resolve(rootDir,
|
|
1610
|
-
const vercelConsumers = queueConfig !== false && queueConfig.driver === "vercel" ? createVercelQueueConsumerRoutes(definitions) : [];
|
|
1593
|
+
const vercelConsumerDir = resolve(rootDir, paths.vercelConsumerDir);
|
|
1594
|
+
const vercelConsumers = queueConfig !== false && queueConfig.driver === "vercel" ? createVercelQueueConsumerRoutes(definitions, owner) : [];
|
|
1611
1595
|
const vercelConsumerFiles = new Set(vercelConsumers.map((consumer) => resolve(rootDir, consumer.handler)));
|
|
1612
1596
|
const staleVercelConsumerFiles = (await readdir(vercelConsumerDir).catch(() => [])).map((name) => resolve(vercelConsumerDir, name)).filter((file) => !vercelConsumerFiles.has(file));
|
|
1613
1597
|
await Promise.all(staleVercelConsumerFiles.map((file) => rm(file, {
|
|
@@ -1622,8 +1606,8 @@ async function writeQueueNitroIntegration(rootDir, queue, hosting, cloudflareQue
|
|
|
1622
1606
|
const file = resolve(rootDir, consumer.handler);
|
|
1623
1607
|
await writeFileIfChanged(file, renderVercelQueueConsumerHandler(file, consumer));
|
|
1624
1608
|
}),
|
|
1625
|
-
...process.env.VITEST ? [writeFileIfChanged(resolve(rootDir,
|
|
1626
|
-
`import { setQueueRuntimeConfig, setQueueRuntimeRegistry } from ${JSON.stringify(createImportPath(resolve(rootDir,
|
|
1609
|
+
...process.env.VITEST ? [writeFileIfChanged(resolve(rootDir, paths.testSetup), [
|
|
1610
|
+
`import { setQueueRuntimeConfig, setQueueRuntimeRegistry } from ${JSON.stringify(createImportPath(resolve(rootDir, paths.testSetup), resolveRuntimeModule("internal/runtime/state")))}`,
|
|
1627
1611
|
`import registry from "./${generatedRegistryFileName}"`,
|
|
1628
1612
|
`setQueueRuntimeConfig(${JSON.stringify(queueConfig)})`,
|
|
1629
1613
|
"setQueueRuntimeRegistry(registry)",
|
|
@@ -1645,7 +1629,8 @@ function sanitizeVercelConsumerName(functionPath) {
|
|
|
1645
1629
|
* Maps each Queue Definition to a Nitro route with a Vercel queue trigger.
|
|
1646
1630
|
* The consumer name keeps the function path of earlier ViteHub releases, so a redeploy keeps the Vercel consumer group.
|
|
1647
1631
|
*/
|
|
1648
|
-
function createVercelQueueConsumerRoutes(definitions) {
|
|
1632
|
+
function createVercelQueueConsumerRoutes(definitions, owner = "app") {
|
|
1633
|
+
const { vercelConsumerDir } = queueGeneratedPaths(owner);
|
|
1649
1634
|
const routes = /* @__PURE__ */ new Map();
|
|
1650
1635
|
return definitions.map((definition) => {
|
|
1651
1636
|
const segments = definition.name.replace(/[^a-z0-9/_-]+/gi, "_").split("/");
|
|
@@ -1660,7 +1645,7 @@ function createVercelQueueConsumerRoutes(definitions) {
|
|
|
1660
1645
|
const consumer = sanitizeVercelConsumerName(`${route.slice(1)}.func`);
|
|
1661
1646
|
return {
|
|
1662
1647
|
consumer,
|
|
1663
|
-
handler: `${
|
|
1648
|
+
handler: `${vercelConsumerDir}/${consumer}.mjs`,
|
|
1664
1649
|
name: definition.name,
|
|
1665
1650
|
route,
|
|
1666
1651
|
topic: getVercelQueueTopicName(definition.name)
|
|
@@ -2096,17 +2081,17 @@ function supportsCloudflareQueues(nitro) {
|
|
|
2096
2081
|
function isGeneratedNitroRegistration(value, generatedPath) {
|
|
2097
2082
|
return typeof value === "string" && (value === generatedPath || value.replaceAll("\\", "/").endsWith(`/${generatedPath}`));
|
|
2098
2083
|
}
|
|
2099
|
-
function isGeneratedVercelConsumer(value) {
|
|
2100
|
-
return typeof value === "string" && value.replaceAll("\\", "/").includes(
|
|
2084
|
+
function isGeneratedVercelConsumer(value, vercelConsumerDir) {
|
|
2085
|
+
return typeof value === "string" && value.replaceAll("\\", "/").includes(`${vercelConsumerDir}/`);
|
|
2101
2086
|
}
|
|
2102
2087
|
function hostsVercelQueueConsumers(nitro) {
|
|
2103
2088
|
const hosting = getHostingProvider(resolveHost({ nitro }));
|
|
2104
2089
|
return hosting === "vercel" || hosting === void 0 && Boolean(process.env.VERCEL);
|
|
2105
2090
|
}
|
|
2106
|
-
function addVercelQueueConsumers(kit, definitions, root) {
|
|
2091
|
+
function addVercelQueueConsumers(kit, definitions, root, owner) {
|
|
2107
2092
|
const vercel = cloneRecord(kit.config.vercel);
|
|
2108
2093
|
const functionRules = cloneRecord(vercel.functionRules);
|
|
2109
|
-
for (const consumer of createVercelQueueConsumerRoutes(definitions)) {
|
|
2094
|
+
for (const consumer of createVercelQueueConsumerRoutes(definitions, owner)) {
|
|
2110
2095
|
const rule = cloneRecord(functionRules[consumer.route]);
|
|
2111
2096
|
kit.addHandler({
|
|
2112
2097
|
handler: root ? resolve$1(root, consumer.handler) : consumer.handler,
|
|
@@ -2151,10 +2136,12 @@ async function mergeNitroConfig(config, value, queue, root, definitions) {
|
|
|
2151
2136
|
const normalizedQueue = normalizeQueueForHosting(queue, nitroHosting);
|
|
2152
2137
|
const runtimeEnabled = queue !== false && !(queue !== false && nitroHosting && queue && normalizedQueue === void 0);
|
|
2153
2138
|
const nitroOwnsPaths = hasNitroConfigContext(config);
|
|
2154
|
-
const
|
|
2155
|
-
const
|
|
2156
|
-
|
|
2157
|
-
|
|
2139
|
+
const owner = viteHubGeneratedOwner(config);
|
|
2140
|
+
const paths = queueGeneratedPaths(owner);
|
|
2141
|
+
const plugin = nitroOwnsPaths ? resolve$1(root, paths.plugin) : paths.plugin;
|
|
2142
|
+
const middleware = nitroOwnsPaths ? resolve$1(root, paths.middleware) : paths.middleware;
|
|
2143
|
+
nitro.plugins = Array.isArray(nitro.plugins) ? nitro.plugins.filter((entry) => !isGeneratedNitroRegistration(entry, paths.plugin)) : [];
|
|
2144
|
+
nitro.handlers = Array.isArray(nitro.handlers) ? nitro.handlers.filter((handler) => !isGeneratedNitroRegistration(handler?.handler, paths.middleware) && !isGeneratedVercelConsumer(handler?.handler, paths.vercelConsumerDir)) : [];
|
|
2158
2145
|
const kit = createNitroServerKit(nitro);
|
|
2159
2146
|
if (!runtimeEnabled) {
|
|
2160
2147
|
contributeCloudflareProviderOutput(providerOutput, { owner: "queue" });
|
|
@@ -2168,7 +2155,7 @@ async function mergeNitroConfig(config, value, queue, root, definitions) {
|
|
|
2168
2155
|
}, "start");
|
|
2169
2156
|
const queueHosting = resolveQueueHosting(queue, resolveQueueHost(config, nitro));
|
|
2170
2157
|
const resolvedVercelQueue = queueHosting === "vercel" ? normalizeQueueOptions(queue, { hosting: queueHosting }) : void 0;
|
|
2171
|
-
if (resolvedVercelQueue && resolvedVercelQueue.driver === "vercel" && hostsVercelQueueConsumers(nitro)) addVercelQueueConsumers(kit, definitions, nitroOwnsPaths ? root : void 0);
|
|
2158
|
+
if (resolvedVercelQueue && resolvedVercelQueue.driver === "vercel" && hostsVercelQueueConsumers(nitro)) addVercelQueueConsumers(kit, definitions, nitroOwnsPaths ? root : void 0, owner);
|
|
2172
2159
|
if (queueHosting !== "cloudflare") {
|
|
2173
2160
|
contributeCloudflareProviderOutput(providerOutput, { owner: "queue" });
|
|
2174
2161
|
return composeNitroCloudflareProviderOutput(providerOutput, kit.config, value);
|
|
@@ -2252,7 +2239,7 @@ function hubQueue(options, internalOptions = {}) {
|
|
|
2252
2239
|
});
|
|
2253
2240
|
}
|
|
2254
2241
|
function discoverViteQueueDefinitions(viteRoot, outputRoot, found) {
|
|
2255
|
-
return resolve$1(viteRoot) === outputRoot ? discoverQueueDefinitions({
|
|
2242
|
+
return resolve$1(viteRoot) === outputRoot && !serverDirs ? discoverQueueDefinitions({
|
|
2256
2243
|
contributions: found,
|
|
2257
2244
|
rootDir: viteRoot
|
|
2258
2245
|
}) : discoverQueueDefinitions({
|
|
@@ -2273,6 +2260,7 @@ function hubQueue(options, internalOptions = {}) {
|
|
|
2273
2260
|
import: internalOptions.databaseImport,
|
|
2274
2261
|
postgres: postgresDatabase
|
|
2275
2262
|
});
|
|
2263
|
+
let generatedOwner = "app";
|
|
2276
2264
|
const nodeWrites = /* @__PURE__ */ new Map();
|
|
2277
2265
|
function recordNodeWrite(rootDir, queue, host, definitions) {
|
|
2278
2266
|
if (host !== "node") return;
|
|
@@ -2281,6 +2269,7 @@ function hubQueue(options, internalOptions = {}) {
|
|
|
2281
2269
|
definitions,
|
|
2282
2270
|
development: localDevelopment,
|
|
2283
2271
|
nitroQueue,
|
|
2272
|
+
owner: generatedOwner,
|
|
2284
2273
|
postgres: postgresDatabase,
|
|
2285
2274
|
queue
|
|
2286
2275
|
});
|
|
@@ -2349,6 +2338,7 @@ function hubQueue(options, internalOptions = {}) {
|
|
|
2349
2338
|
["__vitehubNitroConfigContext"]: true,
|
|
2350
2339
|
nitro
|
|
2351
2340
|
};
|
|
2341
|
+
if (viteConfig) generatedOwner = viteHubGeneratedOwner(viteConfig);
|
|
2352
2342
|
const resolvedConfig = resolvedConfigs.get(root);
|
|
2353
2343
|
const state = resolvedConfig ? buildStates.get(resolvedConfig) : void 0;
|
|
2354
2344
|
const projectQueue = viteConfig ? getResolvedFeatureOptions(viteConfig, "queue") ?? options : state ? state.queue : queueOptions.has(root) ? queueOptions.get(root) : options;
|
|
@@ -2381,13 +2371,14 @@ function hubQueue(options, internalOptions = {}) {
|
|
|
2381
2371
|
};
|
|
2382
2372
|
nuxtStates.set(root, nuxtState);
|
|
2383
2373
|
if (state) Object.assign(state, nuxtState);
|
|
2384
|
-
writtenQueue = await writeQueueNitroIntegration(projectRoot, nitroQueue, hosting, cloudflareQueues, definitions, localDevelopment, internalOptions.importBase, database());
|
|
2374
|
+
writtenQueue = await writeQueueNitroIntegration(projectRoot, nitroQueue, hosting, cloudflareQueues, definitions, localDevelopment, internalOptions.importBase, database(), generatedOwner);
|
|
2385
2375
|
recordNodeWrite(projectRoot, projectQueue, host, definitions);
|
|
2386
2376
|
return configuredNitro;
|
|
2387
2377
|
} }
|
|
2388
2378
|
},
|
|
2389
2379
|
async config(config, env) {
|
|
2390
2380
|
preview = env?.isPreview === true;
|
|
2381
|
+
generatedOwner = viteHubGeneratedOwner(config);
|
|
2391
2382
|
queue = getResolvedFeatureOptions(config, "queue") ?? options;
|
|
2392
2383
|
queueOptions.set(resolve$1(config.root || process.cwd()), queue);
|
|
2393
2384
|
serverDirs = config["__vitehubServerDirs"] ?? serverDirs;
|
|
@@ -2397,10 +2388,11 @@ function hubQueue(options, internalOptions = {}) {
|
|
|
2397
2388
|
contributions = await collectPluginQueueContributions(config.plugins, root, configuredRoot);
|
|
2398
2389
|
const nitro = config.nitro;
|
|
2399
2390
|
config.nitro = await mergeNitroConfig(config, nitro, queue, outputRoot, discoverViteQueueDefinitions(root, outputRoot, contributions));
|
|
2400
|
-
if (process.env.VITEST) return { test: { setupFiles: [resolve$1(outputRoot,
|
|
2391
|
+
if (process.env.VITEST) return { test: { setupFiles: [resolve$1(outputRoot, queueGeneratedPaths(generatedOwner).testSetup)] } };
|
|
2401
2392
|
},
|
|
2402
2393
|
async configResolved(config) {
|
|
2403
2394
|
resolved = config;
|
|
2395
|
+
generatedOwner = viteHubGeneratedOwner(config);
|
|
2404
2396
|
const configuredRoot = frameworkProjectRoot(config);
|
|
2405
2397
|
const nuxtState = nuxtStates.get(config.root) ?? (configuredRoot ? nuxtStates.get(configuredRoot) : void 0);
|
|
2406
2398
|
nuxtConfiguredDefinitions = nuxtState?.nuxtConfiguredDefinitions;
|
|
@@ -2427,7 +2419,7 @@ function hubQueue(options, internalOptions = {}) {
|
|
|
2427
2419
|
nitroQueue = resolvedQueue?.driver && nitroHosting && resolvedQueue.driver !== nitroHosting ? false : queue;
|
|
2428
2420
|
validatesNitroDefinitions = hasNitroConfigContext(config) && nitroQueue !== false;
|
|
2429
2421
|
localDevelopment = config.command === "serve" && !preview;
|
|
2430
|
-
writtenQueue = await writeQueueNitroIntegration(outputRoot, nitroQueue, hosting, cloudflareQueues, configuredDefinitions, localDevelopment, internalOptions.importBase, database());
|
|
2422
|
+
writtenQueue = await writeQueueNitroIntegration(outputRoot, nitroQueue, hosting, cloudflareQueues, configuredDefinitions, localDevelopment, internalOptions.importBase, database(), generatedOwner);
|
|
2431
2423
|
recordNodeWrite(outputRoot, queue, host, configuredDefinitions);
|
|
2432
2424
|
buildStates.set(config, {
|
|
2433
2425
|
configuredDefinitions,
|
|
@@ -2451,7 +2443,7 @@ function hubQueue(options, internalOptions = {}) {
|
|
|
2451
2443
|
resolved = context.server.config;
|
|
2452
2444
|
const outputRoot = nuxtProjectRoot || frameworkProjectRoot(resolved) || resolve$1(resolved.root);
|
|
2453
2445
|
const definitions = resolveNuxtDefinitions?.() ?? discoverViteQueueDefinitions(resolved.root, outputRoot, contributions);
|
|
2454
|
-
writtenQueue = await writeQueueNitroIntegration(outputRoot, nitroQueue, hosting, cloudflareQueues, definitions, localDevelopment, internalOptions.importBase, database());
|
|
2446
|
+
writtenQueue = await writeQueueNitroIntegration(outputRoot, nitroQueue, hosting, cloudflareQueues, definitions, localDevelopment, internalOptions.importBase, database(), generatedOwner);
|
|
2455
2447
|
},
|
|
2456
2448
|
async buildStart() {
|
|
2457
2449
|
const databaseConfig = databasePlugin?.api?.getConfig?.();
|
|
@@ -2461,7 +2453,7 @@ function hubQueue(options, internalOptions = {}) {
|
|
|
2461
2453
|
if (write.postgres === postgresDatabase) continue;
|
|
2462
2454
|
write.postgres = postgresDatabase;
|
|
2463
2455
|
hosting = resolveQueueHosting(write.queue, "node", postgresDatabase);
|
|
2464
|
-
writtenQueue = await writeQueueNitroIntegration(rootDir, write.nitroQueue, hosting, write.cloudflareQueues, write.definitions, write.development, internalOptions.importBase, database());
|
|
2456
|
+
writtenQueue = await writeQueueNitroIntegration(rootDir, write.nitroQueue, hosting, write.cloudflareQueues, write.definitions, write.development, internalOptions.importBase, database(), write.owner);
|
|
2465
2457
|
}
|
|
2466
2458
|
},
|
|
2467
2459
|
buildEnd(error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/queue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Queue primitives and Vite deployment integration for ViteHub.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"background-jobs",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@valibot/to-json-schema": "^1.8.0",
|
|
68
|
-
"@vite-hub/runtime": "0.
|
|
68
|
+
"@vite-hub/runtime": "0.8.0",
|
|
69
69
|
"defu": "^6.1.7",
|
|
70
70
|
"nostics": "1.4.0",
|
|
71
71
|
"pathe": "^2.0.3"
|
|
@@ -74,8 +74,9 @@
|
|
|
74
74
|
"@types/node": "^24.19.2",
|
|
75
75
|
"@vercel/functions": "^3.11.3",
|
|
76
76
|
"@vercel/queue": "^0.11.0",
|
|
77
|
-
"@vite-hub/database": "0.
|
|
77
|
+
"@vite-hub/database": "0.8.0",
|
|
78
78
|
"@vite-hub/internal": "0.0.1",
|
|
79
|
+
"fast-check": "^4.11.0",
|
|
79
80
|
"postgres": "^3.4.9",
|
|
80
81
|
"publint": "^0.3.25",
|
|
81
82
|
"typescript": "^6.0.3",
|