@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/queue",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Queue primitives and Vite deployment integration for ViteHub.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"background-jobs",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"h3",
|
|
9
9
|
"job-queue",
|
|
10
10
|
"nuxt",
|
|
11
|
-
"
|
|
11
|
+
"postgres",
|
|
12
12
|
"queue",
|
|
13
13
|
"typescript",
|
|
14
14
|
"vercel",
|
|
@@ -31,41 +31,25 @@
|
|
|
31
31
|
"type": "module",
|
|
32
32
|
"sideEffects": false,
|
|
33
33
|
"types": "./dist/index.d.ts",
|
|
34
|
+
"imports": {
|
|
35
|
+
"#vitehub/queue/node-client": {
|
|
36
|
+
"types": "./dist/internal/runtime/postgres-client.d.ts",
|
|
37
|
+
"workerd": "./dist/internal/runtime/worker-client.js",
|
|
38
|
+
"worker": "./dist/internal/runtime/worker-client.js",
|
|
39
|
+
"browser": "./dist/internal/runtime/worker-client.js",
|
|
40
|
+
"default": "./dist/internal/runtime/postgres-client.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
34
43
|
"exports": {
|
|
35
44
|
".": {
|
|
36
45
|
"types": "./dist/index.d.ts",
|
|
37
46
|
"import": "./dist/index.js",
|
|
38
47
|
"default": "./dist/index.js"
|
|
39
48
|
},
|
|
40
|
-
"./
|
|
41
|
-
"types": "./dist/
|
|
42
|
-
"import": "./dist/
|
|
43
|
-
"default": "./dist/
|
|
44
|
-
},
|
|
45
|
-
"./internal/runtime/cloudflare-vite": {
|
|
46
|
-
"types": "./dist/internal/runtime/cloudflare-vite.d.ts",
|
|
47
|
-
"import": "./dist/internal/runtime/cloudflare-vite.js",
|
|
48
|
-
"default": "./dist/internal/runtime/cloudflare-vite.js"
|
|
49
|
-
},
|
|
50
|
-
"./internal/runtime/state": {
|
|
51
|
-
"types": "./dist/internal/runtime/state.d.ts",
|
|
52
|
-
"import": "./dist/internal/runtime/state.js",
|
|
53
|
-
"default": "./dist/internal/runtime/state.js"
|
|
54
|
-
},
|
|
55
|
-
"./internal/runtime/vercel-client": {
|
|
56
|
-
"types": "./dist/internal/runtime/vercel-client.d.ts",
|
|
57
|
-
"import": "./dist/internal/runtime/vercel-client.js",
|
|
58
|
-
"default": "./dist/internal/runtime/vercel-client.js"
|
|
59
|
-
},
|
|
60
|
-
"./nuxt": {
|
|
61
|
-
"types": "./dist/nuxt.d.ts",
|
|
62
|
-
"import": "./dist/nuxt.js",
|
|
63
|
-
"default": "./dist/nuxt.js"
|
|
64
|
-
},
|
|
65
|
-
"./operations": {
|
|
66
|
-
"types": "./dist/operations.d.ts",
|
|
67
|
-
"import": "./dist/operations.js",
|
|
68
|
-
"default": "./dist/operations.js"
|
|
49
|
+
"./durability": {
|
|
50
|
+
"types": "./dist/durability.d.ts",
|
|
51
|
+
"import": "./dist/durability.js",
|
|
52
|
+
"default": "./dist/durability.js"
|
|
69
53
|
},
|
|
70
54
|
"./runtime/hosted": {
|
|
71
55
|
"types": "./dist/runtime/hosted.d.ts",
|
|
@@ -80,44 +64,53 @@
|
|
|
80
64
|
"./package.json": "./package.json"
|
|
81
65
|
},
|
|
82
66
|
"dependencies": {
|
|
83
|
-
"@
|
|
84
|
-
"@vercel/functions": "^3.9.11",
|
|
85
|
-
"@vercel/queue": "^0.5.1",
|
|
86
|
-
"@vite-hub/runtime": "0.1.0",
|
|
67
|
+
"@vite-hub/runtime": "0.3.1",
|
|
87
68
|
"defu": "^6.1.7",
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"nostics": "1.3.0",
|
|
91
|
-
"pathe": "^2.0.3",
|
|
92
|
-
"ws": "^8.22.0",
|
|
93
|
-
"undici": "8.12.2"
|
|
69
|
+
"nostics": "1.4.0",
|
|
70
|
+
"pathe": "^2.0.3"
|
|
94
71
|
},
|
|
95
72
|
"devDependencies": {
|
|
96
73
|
"@types/node": "^24.19.1",
|
|
97
|
-
"
|
|
74
|
+
"@vercel/functions": "^3.9.11",
|
|
75
|
+
"@vercel/queue": "^0.11.0",
|
|
76
|
+
"@vite-hub/database": "0.3.1",
|
|
77
|
+
"@vite-hub/internal": "0.0.1",
|
|
78
|
+
"postgres": "^3.4.9",
|
|
98
79
|
"publint": "^0.3.25",
|
|
99
80
|
"typescript": "^6.0.3",
|
|
81
|
+
"undici": "8.12.2",
|
|
100
82
|
"valibot": "^1.5.0",
|
|
101
83
|
"vite": "^8.2.2",
|
|
102
84
|
"vite-plus": "^0.3.3",
|
|
103
|
-
"vitest": "^4.1.11"
|
|
104
|
-
"@vite-hub/internal": "0.0.1"
|
|
85
|
+
"vitest": "^4.1.11"
|
|
105
86
|
},
|
|
106
87
|
"peerDependencies": {
|
|
88
|
+
"@vercel/functions": "^3.9.11",
|
|
89
|
+
"@vercel/queue": "^0.11.0",
|
|
90
|
+
"postgres": "^3.4.9",
|
|
107
91
|
"vite": ">=8.0.0"
|
|
108
92
|
},
|
|
109
93
|
"peerDependenciesMeta": {
|
|
94
|
+
"@vercel/functions": {
|
|
95
|
+
"optional": true
|
|
96
|
+
},
|
|
97
|
+
"@vercel/queue": {
|
|
98
|
+
"optional": true
|
|
99
|
+
},
|
|
100
|
+
"postgres": {
|
|
101
|
+
"optional": true
|
|
102
|
+
},
|
|
110
103
|
"vite": {
|
|
111
104
|
"optional": true
|
|
112
105
|
}
|
|
113
106
|
},
|
|
114
107
|
"engines": {
|
|
115
|
-
"node": ">=
|
|
108
|
+
"node": ">=22.19.0"
|
|
116
109
|
},
|
|
117
110
|
"scripts": {
|
|
118
111
|
"build": "vp pack",
|
|
119
112
|
"dev": "vp pack --watch",
|
|
120
113
|
"typecheck": "vp run --cache -t @vite-hub/queue#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
|
|
121
|
-
"test": "vp run -t @vite-hub/queue#build && vp test"
|
|
114
|
+
"test": "vp run --cache -t @vite-hub/queue#build && vp test"
|
|
122
115
|
}
|
|
123
116
|
}
|
package/dist/client-CIc3jsj2.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { t as normalizeQueueOptions } from "./config-BINujLv4.js";
|
|
2
|
-
import { t as queueErrorDiagnostics } from "./error-diagnostics-qzRF6IVB.js";
|
|
3
|
-
import { i as normalizePublicQueueIdentifier, r as isQueueError } from "./errors-DIFaM9tW.js";
|
|
4
|
-
import { t as getCloudflareQueueBindingName } from "./cloudflare-GosJefIK.js";
|
|
5
|
-
import { t as getVercelQueueTopicName } from "./vercel-C_4vqxcl.js";
|
|
6
|
-
import { a as getQueueRuntimeEvent, h as resolveWaitUntil, i as getQueueRuntimeConfig, l as runWithQueueRuntimeEvent, m as getCloudflareEnv, n as getOrCreateQueueClient, r as getQueueRuntimeClientFactory, s as loadQueueDefinition } from "./state-G9s378-e.js";
|
|
7
|
-
import { t as resolveVercelQueueRegion } from "./vercel-region-cjskrOKl.js";
|
|
8
|
-
//#region src/runtime/client.ts
|
|
9
|
-
async function loadNamedQueueDefinition(name) {
|
|
10
|
-
try {
|
|
11
|
-
return await loadQueueDefinition(name);
|
|
12
|
-
} catch (cause) {
|
|
13
|
-
throw queueErrorDiagnostics.QUEUE_DEFINITION_LOAD_FAILED({
|
|
14
|
-
cause,
|
|
15
|
-
queue: normalizePublicQueueIdentifier(name)
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
function resolveCloudflareBinding(binding, name) {
|
|
20
|
-
if (binding && typeof binding !== "string") return binding;
|
|
21
|
-
const bindingName = binding || getCloudflareQueueBindingName(name);
|
|
22
|
-
return getCloudflareEnv(getQueueRuntimeEvent())?.[bindingName] || bindingName;
|
|
23
|
-
}
|
|
24
|
-
function toProviderOptions(name, config) {
|
|
25
|
-
if (config.provider === "cloudflare") return {
|
|
26
|
-
...config,
|
|
27
|
-
binding: resolveCloudflareBinding(config.binding, name)
|
|
28
|
-
};
|
|
29
|
-
return {
|
|
30
|
-
...config,
|
|
31
|
-
topic: getVercelQueueTopicName(name)
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
function getActiveQueueConfig() {
|
|
35
|
-
const config = getQueueRuntimeConfig();
|
|
36
|
-
if (config === false) return false;
|
|
37
|
-
return config || normalizeQueueOptions(void 0, { hosting: "vercel" });
|
|
38
|
-
}
|
|
39
|
-
async function createNamedQueueClient(name) {
|
|
40
|
-
const config = getActiveQueueConfig();
|
|
41
|
-
if (config === false) throw queueErrorDiagnostics.QUEUE_DISABLED();
|
|
42
|
-
const provider = toProviderOptions(name, config);
|
|
43
|
-
const createClient = getQueueRuntimeClientFactory();
|
|
44
|
-
if (!createClient) throw queueErrorDiagnostics.QUEUE_RUNTIME_NOT_INSTALLED();
|
|
45
|
-
try {
|
|
46
|
-
return await createClient(provider);
|
|
47
|
-
} catch (cause) {
|
|
48
|
-
if (isQueueError(cause)) throw cause;
|
|
49
|
-
throw queueErrorDiagnostics.QUEUE_PROVIDER_FAILED({
|
|
50
|
-
cause,
|
|
51
|
-
operation: "create-client",
|
|
52
|
-
provider: provider.provider
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
async function getDynamicQueue(name) {
|
|
57
|
-
const definition = await loadNamedQueueDefinition(name);
|
|
58
|
-
if (!definition) throw queueErrorDiagnostics.QUEUE_DEFINITION_NOT_FOUND({ queue: normalizePublicQueueIdentifier(name) });
|
|
59
|
-
const config = getActiveQueueConfig();
|
|
60
|
-
if (definition.options?.cache === false || config === false || config.cache === false || config.provider === "cloudflare" || config.provider === "vercel" && resolveVercelQueueRegion(config.region).requestScoped) return await createNamedQueueClient(name);
|
|
61
|
-
return await getOrCreateQueueClient(name, () => createNamedQueueClient(name));
|
|
62
|
-
}
|
|
63
|
-
async function runDynamicQueue(name, payload, options) {
|
|
64
|
-
let queue;
|
|
65
|
-
try {
|
|
66
|
-
queue = await getDynamicQueue(name);
|
|
67
|
-
} catch (error) {
|
|
68
|
-
if (isQueueError(error, ["QUEUE_PROVIDER_FAILED"])) return [error, void 0];
|
|
69
|
-
throw error;
|
|
70
|
-
}
|
|
71
|
-
return await queue.send(payload, options);
|
|
72
|
-
}
|
|
73
|
-
function deferDynamicQueue(name, payload, options) {
|
|
74
|
-
const request = getQueueRuntimeEvent();
|
|
75
|
-
const task = async () => {
|
|
76
|
-
const [error] = await runWithQueueRuntimeEvent(request, () => runDynamicQueue(name, payload, options));
|
|
77
|
-
if (error) throw error;
|
|
78
|
-
};
|
|
79
|
-
const handleError = async (error) => {
|
|
80
|
-
console.error(`[vitehub] Deferred queue dispatch failed for "${name}"`, error);
|
|
81
|
-
try {
|
|
82
|
-
await (await loadNamedQueueDefinition(name))?.options?.onDispatchError?.(error, { name });
|
|
83
|
-
} catch (hookError) {
|
|
84
|
-
console.error(`[vitehub] onDispatchError hook failed for "${name}"`, hookError);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
const promise = task().catch(handleError);
|
|
88
|
-
const waitUntil = resolveWaitUntil(request);
|
|
89
|
-
if (typeof waitUntil === "function") waitUntil(promise);
|
|
90
|
-
}
|
|
91
|
-
/** Dispatch externally supplied names and payloads after application validation. */
|
|
92
|
-
const dynamicQueue = {
|
|
93
|
-
defer: deferDynamicQueue,
|
|
94
|
-
get: getDynamicQueue,
|
|
95
|
-
run: runDynamicQueue
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* Returns the QueueClient of a discovered Queue Definition. Config errors, for example an unknown name, throw.
|
|
99
|
-
*/
|
|
100
|
-
async function getQueue(name) {
|
|
101
|
-
return await getDynamicQueue(name);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Enqueues one job and returns `[error, result]`. `error.code` is a `QueueErrorCode`.
|
|
105
|
-
* Config errors, for example an unknown Queue name, throw.
|
|
106
|
-
*/
|
|
107
|
-
function runQueue(name, payload, options) {
|
|
108
|
-
return runDynamicQueue(name, payload, options);
|
|
109
|
-
}
|
|
110
|
-
function deferQueue(name, payload, options) {
|
|
111
|
-
deferDynamicQueue(name, payload, options);
|
|
112
|
-
}
|
|
113
|
-
//#endregion
|
|
114
|
-
export { runQueue as i, dynamicQueue as n, getQueue as r, deferQueue as t };
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { t as internalErrorDiagnostics } from "./error-diagnostics-A_8Kp-48.js";
|
|
2
|
-
import { t as normalizeQueueOptions } from "./config-BINujLv4.js";
|
|
3
|
-
import { t as queueErrorDiagnostics } from "./error-diagnostics-qzRF6IVB.js";
|
|
4
|
-
import { n as getCloudflareQueueDefinitionName } from "./cloudflare-GosJefIK.js";
|
|
5
|
-
import { n as createCloudflareQueueBatchHandler, t as createCloudflareQueueRuntimeClient } from "./cloudflare-client-COzQ8fHk.js";
|
|
6
|
-
import { t as getCloudflareQueueName } from "./cloudflare-resource-name-CCuLDvSP.js";
|
|
7
|
-
import { f as setQueueRuntimeRegistry, g as runWithActiveCloudflareEnv, l as runWithQueueRuntimeEvent, p as createCloudflareRuntimeEvent, s as loadQueueDefinition, u as setQueueRuntimeConfig } from "./state-G9s378-e.js";
|
|
8
|
-
//#region ../internal/src/runtime/app.ts
|
|
9
|
-
function resolveAppFetch(label, app) {
|
|
10
|
-
if (!app) return;
|
|
11
|
-
if (typeof app === "function") return app;
|
|
12
|
-
if (typeof app.request === "function") return (request, context) => app.request(request, void 0, context);
|
|
13
|
-
if (typeof app.fetch === "function") return app.fetch.bind(app);
|
|
14
|
-
throw internalErrorDiagnostics.INTERNAL_R0011({ message: `Invalid ${label} app. Expected an h3 app or a fetch-compatible handler.` });
|
|
15
|
-
}
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region ../internal/src/runtime/cloudflare-hosted.ts
|
|
18
|
-
function createWebRequestHandler(appHandler) {
|
|
19
|
-
return async (request, context) => await Promise.resolve(appHandler ? appHandler(request, context) : new Response(JSON.stringify({
|
|
20
|
-
status: 404,
|
|
21
|
-
message: `Cannot find any route matching [${request.method}] ${request.url}`
|
|
22
|
-
}), {
|
|
23
|
-
headers: { "content-type": "application/json;charset=UTF-8" },
|
|
24
|
-
status: 404,
|
|
25
|
-
statusText: "Not Found"
|
|
26
|
-
}));
|
|
27
|
-
}
|
|
28
|
-
function createCloudflareHostedWorker(adapter) {
|
|
29
|
-
const requestHandler = createWebRequestHandler(resolveAppFetch(adapter.label, adapter.app));
|
|
30
|
-
return { async fetch(request, env, context) {
|
|
31
|
-
const handle = async (handlerContext) => await Promise.resolve(requestHandler(request, handlerContext));
|
|
32
|
-
if (adapter.onRequest) return await adapter.onRequest({
|
|
33
|
-
env,
|
|
34
|
-
executionContext: context,
|
|
35
|
-
handle
|
|
36
|
-
});
|
|
37
|
-
return await handle();
|
|
38
|
-
} };
|
|
39
|
-
}
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/runtime/cloudflare-shared.ts
|
|
42
|
-
function createQueueJob(message, batch) {
|
|
43
|
-
return {
|
|
44
|
-
attempts: typeof message.attempts === "number" ? message.attempts : 1,
|
|
45
|
-
id: message.id,
|
|
46
|
-
metadata: {
|
|
47
|
-
batch,
|
|
48
|
-
message
|
|
49
|
-
},
|
|
50
|
-
payload: message.body
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/internal/runtime/cloudflare-vite.ts
|
|
55
|
-
function createRegistryDefinitionNames(registry, namePrefix) {
|
|
56
|
-
if (!registry) return void 0;
|
|
57
|
-
const definitions = {};
|
|
58
|
-
for (const name of Object.keys(registry)) {
|
|
59
|
-
const physicalName = getCloudflareQueueName(name, namePrefix);
|
|
60
|
-
if (definitions[physicalName]) throw queueErrorDiagnostics.QUEUE_NAME_COLLISION({
|
|
61
|
-
first: definitions[physicalName],
|
|
62
|
-
resolved: physicalName,
|
|
63
|
-
second: name
|
|
64
|
-
});
|
|
65
|
-
definitions[physicalName] = name;
|
|
66
|
-
}
|
|
67
|
-
return definitions;
|
|
68
|
-
}
|
|
69
|
-
function createQueueCloudflareWorker(options = {}) {
|
|
70
|
-
const queueConfig = options.queue === false ? false : normalizeQueueOptions(options.queue, { hosting: "cloudflare" });
|
|
71
|
-
const registry = options.registry;
|
|
72
|
-
const definitions = options.definitions;
|
|
73
|
-
const registryDefinitions = !definitions && queueConfig !== false && queueConfig.provider === "cloudflare" ? createRegistryDefinitionNames(registry, queueConfig.namePrefix ?? "") : void 0;
|
|
74
|
-
const applyRuntimeState = () => {
|
|
75
|
-
setQueueRuntimeConfig(queueConfig, createCloudflareQueueRuntimeClient);
|
|
76
|
-
setQueueRuntimeRegistry(registry);
|
|
77
|
-
};
|
|
78
|
-
return {
|
|
79
|
-
...createCloudflareHostedWorker({
|
|
80
|
-
app: options.app,
|
|
81
|
-
label: "queue",
|
|
82
|
-
async onRequest({ env, executionContext, handle }) {
|
|
83
|
-
applyRuntimeState();
|
|
84
|
-
const runtimeEvent = createCloudflareRuntimeEvent(env, executionContext);
|
|
85
|
-
return await runWithActiveCloudflareEnv(env, () => runWithQueueRuntimeEvent(runtimeEvent, () => handle(runtimeEvent.context)));
|
|
86
|
-
}
|
|
87
|
-
}),
|
|
88
|
-
async queue(batch, env, context) {
|
|
89
|
-
applyRuntimeState();
|
|
90
|
-
if (queueConfig === false || queueConfig?.provider !== "cloudflare") return;
|
|
91
|
-
const runtimeEvent = createCloudflareRuntimeEvent(env, context);
|
|
92
|
-
await runWithActiveCloudflareEnv(env, async () => {
|
|
93
|
-
const definitionName = definitions ? Object.hasOwn(definitions, batch.queue) ? definitions[batch.queue] : void 0 : registryDefinitions?.[batch.queue] ?? (/-[0-9a-f]{32}$/.test(batch.queue) && !/(?:^|-)queue--(?:[0-9a-f]{2})+$/i.test(batch.queue) || queueConfig.namePrefix && !batch.queue.startsWith(queueConfig.namePrefix) ? void 0 : getCloudflareQueueDefinitionName(batch.queue, queueConfig.namePrefix));
|
|
94
|
-
if (!definitionName) throw queueErrorDiagnostics.QUEUE_DEFINITION_NOT_FOUND({ queue: batch.queue });
|
|
95
|
-
const definition = await loadQueueDefinition(definitionName);
|
|
96
|
-
if (!definition) throw queueErrorDiagnostics.QUEUE_DEFINITION_NOT_FOUND({ queue: definitionName });
|
|
97
|
-
await createCloudflareQueueBatchHandler({
|
|
98
|
-
concurrency: definition.options?.concurrency,
|
|
99
|
-
onError: definition.options?.onError,
|
|
100
|
-
onMessage: async (message, currentBatch) => {
|
|
101
|
-
await runWithQueueRuntimeEvent(runtimeEvent, async () => {
|
|
102
|
-
await definition.handler(createQueueJob(message, currentBatch));
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
})(batch);
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
//#endregion
|
|
111
|
-
export { createQueueCloudflareWorker as t };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { C as ResolvedQueueOptions, a as CloudflareQueueMessageBatch, u as QueueDefinitionRegistry } from "./types-1GRMYES1.js";
|
|
2
|
-
//#region ../internal/src/runtime/cloudflare-env.d.ts
|
|
3
|
-
type CloudflareWorkerEnv = Record<string, unknown>;
|
|
4
|
-
interface CloudflareWorkerExecutionContext {
|
|
5
|
-
waitUntil?: (promise: Promise<unknown>) => void;
|
|
6
|
-
}
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region ../internal/src/runtime/app.d.ts
|
|
9
|
-
type AppHandler = (request: Request, context?: Record<string, unknown>) => Response | Promise<Response>;
|
|
10
|
-
type VitehubApp = AppHandler | {
|
|
11
|
-
fetch?: AppHandler;
|
|
12
|
-
request?: (request: Request, options?: RequestInit, context?: Record<string, unknown>) => Response | Promise<Response>;
|
|
13
|
-
};
|
|
14
|
-
//#endregion
|
|
15
|
-
//#region src/internal/runtime/cloudflare-vite.d.ts
|
|
16
|
-
type CloudflareWorkerApp = VitehubApp;
|
|
17
|
-
interface QueueCloudflareWorkerOptions {
|
|
18
|
-
app?: CloudflareWorkerApp;
|
|
19
|
-
definitions?: Record<string, string>;
|
|
20
|
-
queue?: false | ResolvedQueueOptions;
|
|
21
|
-
registry?: QueueDefinitionRegistry;
|
|
22
|
-
}
|
|
23
|
-
interface QueueCloudflareWorker {
|
|
24
|
-
fetch: (request: Request, env: CloudflareWorkerEnv, context: CloudflareWorkerExecutionContext) => Promise<Response>;
|
|
25
|
-
queue: (batch: CloudflareQueueMessageBatch, env: CloudflareWorkerEnv, context: CloudflareWorkerExecutionContext) => Promise<void>;
|
|
26
|
-
}
|
|
27
|
-
declare function createQueueCloudflareWorker(options?: QueueCloudflareWorkerOptions): QueueCloudflareWorker;
|
|
28
|
-
//#endregion
|
|
29
|
-
export { createQueueCloudflareWorker as i, QueueCloudflareWorker as n, QueueCloudflareWorkerOptions as r, CloudflareWorkerApp as t };
|
package/dist/config-BINujLv4.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { t as isPlainObject } from "./object-B1NW521B.js";
|
|
2
|
-
import { t as queueErrorDiagnostics } from "./error-diagnostics-qzRF6IVB.js";
|
|
3
|
-
import { defu } from "defu";
|
|
4
|
-
function deploymentPresetFromNitro(value) {
|
|
5
|
-
const normalized = value?.trim().toLowerCase().replaceAll("_", "-");
|
|
6
|
-
if (!normalized) return;
|
|
7
|
-
if (normalized.startsWith("cloudflare")) return "cloudflare";
|
|
8
|
-
if (normalized.startsWith("deno")) return "deno";
|
|
9
|
-
if (normalized.startsWith("netlify")) return "netlify";
|
|
10
|
-
if (normalized === "node" || normalized.startsWith("node-")) return "node";
|
|
11
|
-
if (normalized.startsWith("vercel")) return "vercel";
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region ../internal/src/hosting.ts
|
|
15
|
-
/**
|
|
16
|
-
* Returns the Nitro preset name that this build targets, as the developer wrote it.
|
|
17
|
-
* The order is `nitro.preset`, `hosting`, `NITRO_PRESET`, `SERVER_PRESET`, then `VITEHUB_HOSTING`.
|
|
18
|
-
* Empty values are skipped.
|
|
19
|
-
*/
|
|
20
|
-
function resolveHostPreset(input = {}) {
|
|
21
|
-
const env = input.env ?? (typeof process === "undefined" ? {} : process.env);
|
|
22
|
-
const nitroPreset = input.nitro && typeof input.nitro === "object" ? Reflect.get(input.nitro, "preset") : void 0;
|
|
23
|
-
for (const value of [
|
|
24
|
-
nitroPreset,
|
|
25
|
-
input.hosting,
|
|
26
|
-
env.NITRO_PRESET,
|
|
27
|
-
env.SERVER_PRESET,
|
|
28
|
-
env.VITEHUB_HOSTING
|
|
29
|
-
]) if (typeof value === "string" && value.trim()) return value.trim();
|
|
30
|
-
}
|
|
31
|
-
/** Returns the host that this build targets: `cloudflare`, `deno`, `netlify`, `node`, or `vercel`. */
|
|
32
|
-
function resolveHost(input = {}) {
|
|
33
|
-
return deploymentPresetFromNitro(resolveHostPreset(input));
|
|
34
|
-
}
|
|
35
|
-
function normalizeHosting(hosting) {
|
|
36
|
-
const normalized = hosting?.trim().toLowerCase().replaceAll("_", "-") || "";
|
|
37
|
-
if (normalized === "cloudflare") return "cloudflare-module";
|
|
38
|
-
return normalized;
|
|
39
|
-
}
|
|
40
|
-
/** Narrows a preset or host name to the hosts that have a native provider: Cloudflare, Netlify, or Vercel. */
|
|
41
|
-
function getHostingProvider(hosting) {
|
|
42
|
-
const preset = deploymentPresetFromNitro(hosting);
|
|
43
|
-
if (preset === "cloudflare" || preset === "netlify" || preset === "vercel") return preset;
|
|
44
|
-
}
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/config.ts
|
|
47
|
-
const knownProviders = /* @__PURE__ */ new Set(["cloudflare", "vercel"]);
|
|
48
|
-
function readOwnOption(options, key) {
|
|
49
|
-
return Object.hasOwn(options, key) ? options[key] : void 0;
|
|
50
|
-
}
|
|
51
|
-
function resolveProvider(options, hosting) {
|
|
52
|
-
const cache = readOwnOption(options, "cache");
|
|
53
|
-
const shared = typeof cache === "boolean" ? { cache } : {};
|
|
54
|
-
const provider = readOwnOption(options, "provider");
|
|
55
|
-
if (typeof provider === "string" && !knownProviders.has(provider)) throw queueErrorDiagnostics.QUEUE_INVALID_PROVIDER({ provider });
|
|
56
|
-
if (typeof provider === "undefined" && hosting && !hosting.includes("cloudflare") && !hosting.includes("vercel")) throw queueErrorDiagnostics.QUEUE_MISSING_PROVIDER({ hosting });
|
|
57
|
-
if ((provider || (hosting.includes("cloudflare") ? "cloudflare" : "vercel")) === "cloudflare") {
|
|
58
|
-
const binding = readOwnOption(options, "binding");
|
|
59
|
-
const namePrefix = readOwnOption(options, "namePrefix");
|
|
60
|
-
return defu({
|
|
61
|
-
...typeof binding === "string" ? { binding } : {},
|
|
62
|
-
...typeof namePrefix === "string" ? { namePrefix } : {}
|
|
63
|
-
}, shared, { provider: "cloudflare" });
|
|
64
|
-
}
|
|
65
|
-
const region = readOwnOption(options, "region");
|
|
66
|
-
return defu(typeof region === "string" ? { region } : {}, shared, { provider: "vercel" });
|
|
67
|
-
}
|
|
68
|
-
function normalizeQueueOptions(options, input = {}) {
|
|
69
|
-
if (options === false) return void 0;
|
|
70
|
-
if (typeof options !== "undefined" && !isPlainObject(options)) throw queueErrorDiagnostics.QUEUE_INVALID_CONFIG();
|
|
71
|
-
return resolveProvider(options || {}, normalizeHosting(input.hosting));
|
|
72
|
-
}
|
|
73
|
-
//#endregion
|
|
74
|
-
export { resolveHostPreset as i, getHostingProvider as n, resolveHost as r, normalizeQueueOptions as t };
|
package/dist/enqueue-CnQ0QR3O.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//#region src/enqueue.ts
|
|
2
|
-
let fallbackCounter = 0;
|
|
3
|
-
function createQueueMessageId(prefix = "queue") {
|
|
4
|
-
const uuid = globalThis.crypto?.randomUUID?.();
|
|
5
|
-
if (uuid) return `${prefix}_${uuid}`;
|
|
6
|
-
fallbackCounter = fallbackCounter + 1 >>> 0;
|
|
7
|
-
return `${prefix}_${Date.now().toString(36)}_${fallbackCounter.toString(36)}`;
|
|
8
|
-
}
|
|
9
|
-
/** Payload properties never select enqueue options. */
|
|
10
|
-
function normalizeQueueEnqueueInput(payload, options = {}) {
|
|
11
|
-
const hasOwnId = Object.hasOwn(options, "id");
|
|
12
|
-
const providerOptions = { ...options };
|
|
13
|
-
const id = hasOwnId ? Object.hasOwn(providerOptions, "id") ? providerOptions.id : options.id : void 0;
|
|
14
|
-
delete providerOptions.id;
|
|
15
|
-
return {
|
|
16
|
-
id: typeof id === "string" && id.length > 0 ? id : createQueueMessageId(),
|
|
17
|
-
options: providerOptions,
|
|
18
|
-
payload
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
//#endregion
|
|
22
|
-
export { normalizeQueueEnqueueInput as n, createQueueMessageId as t };
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { defineDiagnostics } from "nostics";
|
|
2
|
-
//#region ../internal/src/error-diagnostics.ts
|
|
3
|
-
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
4
|
-
const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
5
|
-
docsBase: () => "https://vitehub.dev/docs/reference/diagnostics",
|
|
6
|
-
codes: {
|
|
7
|
-
INTERNAL_R0012: dynamicError,
|
|
8
|
-
INTERNAL_R0013: dynamicError,
|
|
9
|
-
INTERNAL_R0014: {
|
|
10
|
-
why: ({ path }) => `Cannot read Provision State from "${path}".`,
|
|
11
|
-
fix: "Check file access and restore valid JSON while preserving existing resource IDs."
|
|
12
|
-
},
|
|
13
|
-
INTERNAL_R0020: {
|
|
14
|
-
fix: "Give the operation a name like `content.publish`, a description, a section, a kind, an input schema, and a run function.",
|
|
15
|
-
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
16
|
-
},
|
|
17
|
-
INTERNAL_R0021: {
|
|
18
|
-
fix: "Run `vitehub inspect definitions --kind operation` to list the operations of this app.",
|
|
19
|
-
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
20
|
-
},
|
|
21
|
-
INTERNAL_R0022: {
|
|
22
|
-
fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
|
|
23
|
-
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
24
|
-
},
|
|
25
|
-
INTERNAL_R0024: {
|
|
26
|
-
fix: "Start the dev server with `vite dev`, or pass `--url <origin>` of a deployed app with credentials in VITEHUB_CONSOLE_AUTHORIZATION, VITEHUB_CONSOLE_COOKIE, or CF_ACCESS_CLIENT_ID and CF_ACCESS_CLIENT_SECRET.",
|
|
27
|
-
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
28
|
-
},
|
|
29
|
-
INTERNAL_R0023: {
|
|
30
|
-
fix: "Ask for access to the section of this operation.",
|
|
31
|
-
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
32
|
-
},
|
|
33
|
-
INTERNAL_B0001: dynamicError,
|
|
34
|
-
INTERNAL_B0002: dynamicError,
|
|
35
|
-
INTERNAL_B0003: dynamicError,
|
|
36
|
-
INTERNAL_B0004: dynamicError,
|
|
37
|
-
INTERNAL_B0005: dynamicError,
|
|
38
|
-
INTERNAL_B0006: dynamicError,
|
|
39
|
-
INTERNAL_B0007: dynamicError,
|
|
40
|
-
INTERNAL_B0008: dynamicError,
|
|
41
|
-
INTERNAL_B0009: dynamicError,
|
|
42
|
-
INTERNAL_B0010: dynamicError,
|
|
43
|
-
INTERNAL_B0011: dynamicError,
|
|
44
|
-
INTERNAL_B0012: dynamicError,
|
|
45
|
-
INTERNAL_B0013: dynamicError,
|
|
46
|
-
INTERNAL_B0014: dynamicError,
|
|
47
|
-
INTERNAL_B0015: dynamicError,
|
|
48
|
-
INTERNAL_B0016: dynamicError,
|
|
49
|
-
INTERNAL_B0017: dynamicError,
|
|
50
|
-
INTERNAL_B0018: dynamicError,
|
|
51
|
-
INTERNAL_B0019: dynamicError,
|
|
52
|
-
INTERNAL_B0020: dynamicError,
|
|
53
|
-
INTERNAL_B0021: dynamicError,
|
|
54
|
-
INTERNAL_B0022: dynamicError,
|
|
55
|
-
INTERNAL_B0023: dynamicError,
|
|
56
|
-
INTERNAL_B0024: dynamicError,
|
|
57
|
-
INTERNAL_B0025: dynamicError,
|
|
58
|
-
INTERNAL_B0026: dynamicError,
|
|
59
|
-
INTERNAL_B0027: dynamicError,
|
|
60
|
-
INTERNAL_B0028: dynamicError,
|
|
61
|
-
INTERNAL_B0029: dynamicError,
|
|
62
|
-
INTERNAL_B0030: dynamicError,
|
|
63
|
-
INTERNAL_B0031: dynamicError,
|
|
64
|
-
INTERNAL_B0032: dynamicError,
|
|
65
|
-
INTERNAL_B0033: dynamicError,
|
|
66
|
-
INTERNAL_B0034: dynamicError,
|
|
67
|
-
INTERNAL_B0035: dynamicError,
|
|
68
|
-
INTERNAL_B0036: dynamicError,
|
|
69
|
-
INTERNAL_B0037: dynamicError,
|
|
70
|
-
INTERNAL_B0038: dynamicError,
|
|
71
|
-
INTERNAL_B0039: dynamicError,
|
|
72
|
-
INTERNAL_B0040: dynamicError,
|
|
73
|
-
INTERNAL_B0041: dynamicError,
|
|
74
|
-
INTERNAL_B0042: dynamicError,
|
|
75
|
-
INTERNAL_B0043: dynamicError,
|
|
76
|
-
INTERNAL_B0044: dynamicError,
|
|
77
|
-
INTERNAL_B0045: dynamicError,
|
|
78
|
-
INTERNAL_B0046: dynamicError,
|
|
79
|
-
INTERNAL_B0047: dynamicError,
|
|
80
|
-
INTERNAL_B0048: {
|
|
81
|
-
fix: "Rename one of the two operations. A name is `<section>.<verb>` and is unique in the app.",
|
|
82
|
-
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
83
|
-
},
|
|
84
|
-
INTERNAL_B0049: {
|
|
85
|
-
fix: "Set `cli: { namespace, command }` on one of the two operations.",
|
|
86
|
-
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
87
|
-
},
|
|
88
|
-
INTERNAL_B0050: {
|
|
89
|
-
fix: "Rename one of the two operations, or set `mcp: false` on it. MCP tool names replace every character outside letters, digits, `_`, and `-` with `_`.",
|
|
90
|
-
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
91
|
-
},
|
|
92
|
-
INTERNAL_R0025: {
|
|
93
|
-
fix: "Start `vite dev` in the project that you run the command from, or pass `--url` of that server.",
|
|
94
|
-
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
95
|
-
},
|
|
96
|
-
INTERNAL_R0026: {
|
|
97
|
-
why: "The server parsed a destructive operation that the CLI did not confirm.",
|
|
98
|
-
fix: "Review the operation, then run it again with --yes to confirm the change."
|
|
99
|
-
},
|
|
100
|
-
INTERNAL_C0001: dynamicError,
|
|
101
|
-
INTERNAL_C0002: dynamicError,
|
|
102
|
-
INTERNAL_R0001: dynamicError,
|
|
103
|
-
INTERNAL_R0002: dynamicError,
|
|
104
|
-
INTERNAL_R0003: dynamicError,
|
|
105
|
-
INTERNAL_R0004: dynamicError,
|
|
106
|
-
INTERNAL_R0005: dynamicError,
|
|
107
|
-
INTERNAL_R0006: dynamicError,
|
|
108
|
-
INTERNAL_R0007: dynamicError,
|
|
109
|
-
INTERNAL_R0008: dynamicError,
|
|
110
|
-
INTERNAL_R0009: dynamicError,
|
|
111
|
-
INTERNAL_R0010: dynamicError,
|
|
112
|
-
INTERNAL_R0011: dynamicError
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
//#endregion
|
|
116
|
-
export { internalErrorDiagnostics as t };
|