@vite-hub/queue 0.0.1 → 0.0.3
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 +42 -6
- package/dist/client-CPQ-iyXS.js +93 -0
- package/dist/{cloudflare-D5dVqiNw.js → cloudflare-GosJefIK.js} +5 -8
- package/dist/{cloudflare-CTdH2u_E.js → cloudflare-client-w5vphoNn.js} +34 -42
- package/dist/cloudflare-resource-name-R8zYQiZb.js +34 -0
- package/dist/cloudflare-vite-bA1eLf46.js +92 -0
- package/dist/{cloudflare-vite-CRx2CsH9.d.ts → cloudflare-vite-nFPor46-.d.ts} +4 -3
- package/dist/{config-CIDUZkmH.js → config-B7xkD1v0.js} +21 -3
- package/dist/delivery-error-glgYWC9g.js +45 -0
- package/dist/errors-CjuG_qr-.js +108 -0
- package/dist/index.d.ts +62 -24
- package/dist/index.js +19 -8
- package/dist/internal/runtime/cloudflare-client.d.ts +6 -0
- package/dist/internal/runtime/cloudflare-client.js +2 -0
- package/dist/{runtime → internal/runtime}/cloudflare-vite.d.ts +1 -1
- package/dist/internal/runtime/cloudflare-vite.js +2 -0
- package/dist/internal/runtime/state.d.ts +16 -0
- package/dist/internal/runtime/state.js +2 -0
- package/dist/internal/runtime/vercel-client.d.ts +6 -0
- package/dist/{vercel-D31zfxiW.js → internal/runtime/vercel-client.js} +46 -30
- package/dist/internal/runtime/vercel-vite.d.ts +20 -0
- package/dist/{runtime → internal/runtime}/vercel-vite.js +6 -5
- package/dist/nuxt.d.ts +19 -0
- package/dist/nuxt.js +29 -0
- package/dist/runtime/hosted.d.ts +1 -1
- package/dist/runtime/hosted.js +52 -1
- package/dist/state-Bo8CLZ_k.js +105 -0
- package/dist/{types-CBsyjWye.d.ts → types-CwvoMATy.d.ts} +3 -1
- package/dist/{vercel-BGm0G00p.js → vercel-C_4vqxcl.js} +1 -1
- package/dist/vercel-runtime-package-copy-CKimoFJ5.js +66 -0
- package/dist/vite-BcMpQk_n.js +1842 -0
- package/dist/vite.d.ts +90 -6
- package/dist/vite.js +2 -492
- package/package.json +45 -49
- package/dist/cloudflare-env-CJ6g1-Qb.js +0 -49
- package/dist/cloudflare-shared-Ce61GXcn.js +0 -14
- package/dist/cloudflare-vite-Bs67_E_Y.js +0 -66
- package/dist/errors-xRt0BFZK.js +0 -57
- package/dist/hosted-Dw9WiPNH.js +0 -136
- package/dist/module-Cr8pH2J_.js +0 -610
- package/dist/nitro.d.ts +0 -32
- package/dist/nitro.js +0 -2
- package/dist/runtime/cloudflare-vite.js +0 -2
- package/dist/runtime/nitro-plugin.d.ts +0 -6
- package/dist/runtime/nitro-plugin.js +0 -40
- package/dist/runtime/state.d.ts +0 -13
- package/dist/runtime/state.js +0 -41
- package/dist/runtime/vercel-vite.d.ts +0 -13
- /package/dist/{_app-Bx4e5L33.d.ts → _app-D29AwUdD.d.ts} +0 -0
- /package/dist/{app-BFpA3j89.js → app-BZpq2cwC.js} +0 -0
package/package.json
CHANGED
|
@@ -1,81 +1,77 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/queue",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Queue primitives and Vite
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "Queue primitives and Vite deployment integration for ViteHub.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cloudflare",
|
|
7
|
+
"h3",
|
|
8
|
+
"queue",
|
|
9
|
+
"vercel",
|
|
10
|
+
"vite",
|
|
11
|
+
"vitehub"
|
|
12
|
+
],
|
|
7
13
|
"homepage": "https://github.com/vite-hub/vitehub#readme",
|
|
14
|
+
"bugs": "https://github.com/vite-hub/vitehub/issues",
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"author": "onmax <maximogarciamtnez@gmail.com>",
|
|
8
17
|
"repository": {
|
|
9
18
|
"type": "git",
|
|
10
19
|
"url": "git+https://github.com/vite-hub/vitehub.git",
|
|
11
20
|
"directory": "packages/queue"
|
|
12
21
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
"vite",
|
|
17
|
-
"nitro",
|
|
18
|
-
"h3",
|
|
19
|
-
"queue",
|
|
20
|
-
"cloudflare",
|
|
21
|
-
"vercel"
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"package.json"
|
|
22
25
|
],
|
|
23
|
-
"sideEffects": false,
|
|
24
26
|
"type": "module",
|
|
27
|
+
"sideEffects": false,
|
|
25
28
|
"types": "./dist/index.d.ts",
|
|
26
29
|
"exports": {
|
|
27
30
|
".": "./dist/index.js",
|
|
28
|
-
"./
|
|
29
|
-
"./runtime/cloudflare-vite": "./dist/runtime/cloudflare-vite.js",
|
|
31
|
+
"./internal/runtime/cloudflare-client": "./dist/internal/runtime/cloudflare-client.js",
|
|
32
|
+
"./internal/runtime/cloudflare-vite": "./dist/internal/runtime/cloudflare-vite.js",
|
|
33
|
+
"./internal/runtime/state": "./dist/internal/runtime/state.js",
|
|
34
|
+
"./internal/runtime/vercel-client": "./dist/internal/runtime/vercel-client.js",
|
|
35
|
+
"./internal/runtime/vercel-vite": "./dist/internal/runtime/vercel-vite.js",
|
|
36
|
+
"./nuxt": "./dist/nuxt.js",
|
|
30
37
|
"./runtime/hosted": "./dist/runtime/hosted.js",
|
|
31
|
-
"./runtime/nitro-plugin": "./dist/runtime/nitro-plugin.js",
|
|
32
|
-
"./runtime/state": "./dist/runtime/state.js",
|
|
33
|
-
"./runtime/vercel-vite": "./dist/runtime/vercel-vite.js",
|
|
34
38
|
"./vite": "./dist/vite.js",
|
|
35
39
|
"./package.json": "./package.json"
|
|
36
40
|
},
|
|
37
|
-
"files": [
|
|
38
|
-
"dist",
|
|
39
|
-
"package.json"
|
|
40
|
-
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@vercel/functions": "^3.
|
|
43
|
-
"
|
|
42
|
+
"@vercel/functions": "^3.7.5",
|
|
43
|
+
"@vercel/queue": "^0.0.0-alpha.40",
|
|
44
|
+
"defu": "^6.1.7",
|
|
44
45
|
"esbuild": "^0.27.7",
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
46
|
+
"h3": "2.0.1-rc.25",
|
|
47
|
+
"pathe": "^2.0.3",
|
|
48
|
+
"@vite-hub/runtime": "0.0.3"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/node": "^24.13.3",
|
|
52
|
+
"nuxt": "^4.4.8",
|
|
53
|
+
"publint": "^0.3.21",
|
|
54
|
+
"typescript": "^6.0.3",
|
|
55
|
+
"vite": "^8.0.8",
|
|
56
|
+
"vite-plus": "^0.1.24",
|
|
57
|
+
"vitest": "^4.1.4",
|
|
58
|
+
"@vite-hub/internal": "0.0.1"
|
|
48
59
|
},
|
|
49
60
|
"peerDependencies": {
|
|
50
|
-
"
|
|
51
|
-
"nitro": "^3.0.0-0",
|
|
52
|
-
"vite": "^8.0.0"
|
|
61
|
+
"vite": ">=8.0.0"
|
|
53
62
|
},
|
|
54
63
|
"peerDependenciesMeta": {
|
|
55
|
-
"@vercel/queue": {
|
|
56
|
-
"optional": true
|
|
57
|
-
},
|
|
58
|
-
"nitro": {
|
|
59
|
-
"optional": true
|
|
60
|
-
},
|
|
61
64
|
"vite": {
|
|
62
65
|
"optional": true
|
|
63
66
|
}
|
|
64
67
|
},
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"publint": "^0.3.15",
|
|
68
|
-
"tsdown": "^0.21.8",
|
|
69
|
-
"typescript": "^6.0.2",
|
|
70
|
-
"nitro": "3.0.260311-beta",
|
|
71
|
-
"vite": "^8.0.8",
|
|
72
|
-
"vitest": "^4.1.4",
|
|
73
|
-
"@vite-hub/internal": "0.0.1"
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=24.0.0"
|
|
74
70
|
},
|
|
75
71
|
"scripts": {
|
|
76
|
-
"build": "
|
|
77
|
-
"dev": "
|
|
72
|
+
"build": "vp pack",
|
|
73
|
+
"dev": "vp pack --watch",
|
|
78
74
|
"typecheck": "tsc --noEmit -p ./tsconfig.json",
|
|
79
|
-
"test": "
|
|
75
|
+
"test": "vp run -t @vite-hub/queue#build && vp test"
|
|
80
76
|
}
|
|
81
77
|
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
//#region ../internal/src/runtime/cloudflare-env.ts
|
|
3
|
-
let activeEnv;
|
|
4
|
-
const activeEnvStorage = new AsyncLocalStorage();
|
|
5
|
-
function setActiveCloudflareEnv(env) {
|
|
6
|
-
activeEnv = env;
|
|
7
|
-
globalThis.__env__ = env;
|
|
8
|
-
try {
|
|
9
|
-
activeEnvStorage.enterWith(env);
|
|
10
|
-
} catch {}
|
|
11
|
-
}
|
|
12
|
-
function getActiveCloudflareEnv() {
|
|
13
|
-
return activeEnvStorage.getStore() ?? activeEnv ?? globalThis.__env__;
|
|
14
|
-
}
|
|
15
|
-
function getCloudflareEnv(event) {
|
|
16
|
-
const target = event;
|
|
17
|
-
return target?.env || target?.context?.cloudflare?.env || target?.context?._platform?.cloudflare?.env || target?.req?.runtime?.cloudflare?.env || getActiveCloudflareEnv();
|
|
18
|
-
}
|
|
19
|
-
function resolveWaitUntil(event) {
|
|
20
|
-
const target = event;
|
|
21
|
-
const owners = [
|
|
22
|
-
target,
|
|
23
|
-
target?.context,
|
|
24
|
-
target?.context?.cloudflare,
|
|
25
|
-
target?.context?.cloudflare?.context,
|
|
26
|
-
target?.context?._platform?.cloudflare,
|
|
27
|
-
target?.context?._platform?.cloudflare?.context,
|
|
28
|
-
target?.req,
|
|
29
|
-
target?.req?.runtime?.cloudflare,
|
|
30
|
-
target?.req?.runtime?.cloudflare?.context
|
|
31
|
-
];
|
|
32
|
-
for (const owner of owners) if (typeof owner?.waitUntil === "function") return owner.waitUntil.bind(owner);
|
|
33
|
-
}
|
|
34
|
-
function createCloudflareRuntimeEvent(env, context) {
|
|
35
|
-
const waitUntil = typeof context?.waitUntil === "function" ? context.waitUntil.bind(context) : void 0;
|
|
36
|
-
return {
|
|
37
|
-
context: {
|
|
38
|
-
cloudflare: {
|
|
39
|
-
env,
|
|
40
|
-
context
|
|
41
|
-
},
|
|
42
|
-
waitUntil
|
|
43
|
-
},
|
|
44
|
-
env,
|
|
45
|
-
waitUntil
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
//#endregion
|
|
49
|
-
export { setActiveCloudflareEnv as i, getCloudflareEnv as n, resolveWaitUntil as r, createCloudflareRuntimeEvent as t };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
//#region src/runtime/cloudflare-shared.ts
|
|
2
|
-
function createQueueJob(message, batch) {
|
|
3
|
-
return {
|
|
4
|
-
attempts: typeof message.attempts === "number" ? message.attempts : 1,
|
|
5
|
-
id: message.id,
|
|
6
|
-
metadata: {
|
|
7
|
-
batch,
|
|
8
|
-
message
|
|
9
|
-
},
|
|
10
|
-
payload: message.body
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
export { createQueueJob as t };
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { n as createCloudflareQueueBatchHandler } from "./cloudflare-CTdH2u_E.js";
|
|
2
|
-
import { t as normalizeQueueOptions } from "./config-CIDUZkmH.js";
|
|
3
|
-
import { n as getCloudflareQueueDefinitionName } from "./cloudflare-D5dVqiNw.js";
|
|
4
|
-
import { i as setActiveCloudflareEnv, t as createCloudflareRuntimeEvent } from "./cloudflare-env-CJ6g1-Qb.js";
|
|
5
|
-
import { loadQueueDefinition, runWithQueueRuntimeEvent, setQueueRuntimeConfig, setQueueRuntimeRegistry } from "./runtime/state.js";
|
|
6
|
-
import { t as resolveAppFetch } from "./app-BFpA3j89.js";
|
|
7
|
-
import { t as createQueueJob } from "./cloudflare-shared-Ce61GXcn.js";
|
|
8
|
-
import { H3, toWebHandler } from "h3/cloudflare";
|
|
9
|
-
//#region ../internal/src/runtime/cloudflare-hosted.ts
|
|
10
|
-
function createWebRequestHandler(appHandler) {
|
|
11
|
-
const defaultHandler = toWebHandler(new H3());
|
|
12
|
-
return async (request, context) => await Promise.resolve(appHandler ? appHandler(request, context) : defaultHandler(request, context));
|
|
13
|
-
}
|
|
14
|
-
function createCloudflareHostedWorker(adapter) {
|
|
15
|
-
const requestHandler = createWebRequestHandler(resolveAppFetch(adapter.label, adapter.app));
|
|
16
|
-
return { async fetch(request, env, context) {
|
|
17
|
-
const handle = async (handlerContext) => await Promise.resolve(requestHandler(request, handlerContext));
|
|
18
|
-
if (adapter.onRequest) return await adapter.onRequest({
|
|
19
|
-
env,
|
|
20
|
-
executionContext: context,
|
|
21
|
-
handle
|
|
22
|
-
});
|
|
23
|
-
return await handle();
|
|
24
|
-
} };
|
|
25
|
-
}
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/runtime/cloudflare-vite.ts
|
|
28
|
-
function createQueueCloudflareWorker(options = {}) {
|
|
29
|
-
const queueConfig = options.queue === false ? false : normalizeQueueOptions(options.queue, { hosting: "cloudflare" });
|
|
30
|
-
const registry = options.registry;
|
|
31
|
-
const applyRuntimeState = () => {
|
|
32
|
-
setQueueRuntimeConfig(queueConfig);
|
|
33
|
-
setQueueRuntimeRegistry(registry);
|
|
34
|
-
};
|
|
35
|
-
return {
|
|
36
|
-
...createCloudflareHostedWorker({
|
|
37
|
-
app: options.app,
|
|
38
|
-
label: "queue",
|
|
39
|
-
async onRequest({ env, executionContext, handle }) {
|
|
40
|
-
applyRuntimeState();
|
|
41
|
-
setActiveCloudflareEnv(env);
|
|
42
|
-
const runtimeEvent = createCloudflareRuntimeEvent(env, executionContext);
|
|
43
|
-
return await runWithQueueRuntimeEvent(runtimeEvent, () => handle(runtimeEvent.context));
|
|
44
|
-
}
|
|
45
|
-
}),
|
|
46
|
-
async queue(batch, env, context) {
|
|
47
|
-
applyRuntimeState();
|
|
48
|
-
setActiveCloudflareEnv(env);
|
|
49
|
-
if (queueConfig === false || queueConfig?.provider !== "cloudflare") return;
|
|
50
|
-
const definition = await loadQueueDefinition(getCloudflareQueueDefinitionName(batch.queue));
|
|
51
|
-
if (!definition) return;
|
|
52
|
-
const runtimeEvent = createCloudflareRuntimeEvent(env, context);
|
|
53
|
-
await createCloudflareQueueBatchHandler({
|
|
54
|
-
concurrency: definition.options?.concurrency,
|
|
55
|
-
onError: definition.options?.onError,
|
|
56
|
-
onMessage: async (message, currentBatch) => {
|
|
57
|
-
await runWithQueueRuntimeEvent(runtimeEvent, async () => {
|
|
58
|
-
await definition.handler(createQueueJob(message, currentBatch));
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
})(batch);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
//#endregion
|
|
66
|
-
export { createQueueCloudflareWorker as t };
|
package/dist/errors-xRt0BFZK.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
//#region src/enqueue.ts
|
|
2
|
-
const envelopeKeys = new Set([
|
|
3
|
-
"contentType",
|
|
4
|
-
"delaySeconds",
|
|
5
|
-
"id",
|
|
6
|
-
"idempotencyKey",
|
|
7
|
-
"region",
|
|
8
|
-
"retentionSeconds"
|
|
9
|
-
]);
|
|
10
|
-
let fallbackCounter = 0;
|
|
11
|
-
function createQueueMessageId(prefix = "queue") {
|
|
12
|
-
const uuid = globalThis.crypto?.randomUUID?.();
|
|
13
|
-
if (uuid) return `${prefix}_${uuid}`;
|
|
14
|
-
fallbackCounter = fallbackCounter + 1 >>> 0;
|
|
15
|
-
return `${prefix}_${Date.now().toString(36)}_${fallbackCounter.toString(36)}`;
|
|
16
|
-
}
|
|
17
|
-
function isQueueEnvelope(input) {
|
|
18
|
-
if (typeof input !== "object" || input === null || Array.isArray(input) || !("payload" in input)) return false;
|
|
19
|
-
return Object.keys(input).every((key) => key === "payload" || envelopeKeys.has(key));
|
|
20
|
-
}
|
|
21
|
-
function normalizeQueueEnqueueInput(input) {
|
|
22
|
-
if (!isQueueEnvelope(input)) return {
|
|
23
|
-
id: createQueueMessageId(),
|
|
24
|
-
options: {},
|
|
25
|
-
payload: input
|
|
26
|
-
};
|
|
27
|
-
const { contentType, delaySeconds, id, idempotencyKey, payload, region, retentionSeconds } = input;
|
|
28
|
-
const options = {
|
|
29
|
-
...contentType !== void 0 ? { contentType } : {},
|
|
30
|
-
...delaySeconds !== void 0 ? { delaySeconds } : {},
|
|
31
|
-
...idempotencyKey !== void 0 ? { idempotencyKey } : {},
|
|
32
|
-
...region !== void 0 ? { region } : {},
|
|
33
|
-
...retentionSeconds !== void 0 ? { retentionSeconds } : {}
|
|
34
|
-
};
|
|
35
|
-
return {
|
|
36
|
-
id: typeof id === "string" && id.length > 0 ? id : createQueueMessageId(),
|
|
37
|
-
options,
|
|
38
|
-
payload
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region src/errors.ts
|
|
43
|
-
var QueueError = class extends Error {
|
|
44
|
-
code;
|
|
45
|
-
details;
|
|
46
|
-
httpStatus;
|
|
47
|
-
method;
|
|
48
|
-
provider;
|
|
49
|
-
cause;
|
|
50
|
-
constructor(message, metadata = {}) {
|
|
51
|
-
super(message);
|
|
52
|
-
this.name = "QueueError";
|
|
53
|
-
Object.assign(this, metadata);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
//#endregion
|
|
57
|
-
export { createQueueMessageId as n, normalizeQueueEnqueueInput as r, QueueError as t };
|
package/dist/hosted-Dw9WiPNH.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { t as normalizeQueueOptions } from "./config-CIDUZkmH.js";
|
|
2
|
-
import { r as normalizeQueueEnqueueInput, t as QueueError } from "./errors-xRt0BFZK.js";
|
|
3
|
-
import { t as getCloudflareQueueBindingName } from "./cloudflare-D5dVqiNw.js";
|
|
4
|
-
import { t as getVercelQueueTopicName } from "./vercel-BGm0G00p.js";
|
|
5
|
-
import { n as getCloudflareEnv, r as resolveWaitUntil } from "./cloudflare-env-CJ6g1-Qb.js";
|
|
6
|
-
import { getQueueClientCache, getQueueRuntimeConfig, getQueueRuntimeEvent, loadQueueDefinition, runWithQueueRuntimeEvent } from "./runtime/state.js";
|
|
7
|
-
import { waitUntil } from "@vercel/functions";
|
|
8
|
-
import { getRequestHeaders, getRequestURL, readRawBody } from "h3";
|
|
9
|
-
//#region src/runtime/client.ts
|
|
10
|
-
function resolveCloudflareBinding(binding, name) {
|
|
11
|
-
if (binding && typeof binding !== "string") return binding;
|
|
12
|
-
const bindingName = binding || getCloudflareQueueBindingName(name);
|
|
13
|
-
return getCloudflareEnv(getQueueRuntimeEvent())?.[bindingName] || bindingName;
|
|
14
|
-
}
|
|
15
|
-
function toProviderOptions(name, config) {
|
|
16
|
-
if (config.provider === "cloudflare") return {
|
|
17
|
-
...config,
|
|
18
|
-
binding: resolveCloudflareBinding(config.binding, name)
|
|
19
|
-
};
|
|
20
|
-
return {
|
|
21
|
-
...config,
|
|
22
|
-
topic: getVercelQueueTopicName(name)
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
async function createQueueClient(options) {
|
|
26
|
-
if (options.provider === "cloudflare") {
|
|
27
|
-
const { createCloudflareQueueClient } = await import("./cloudflare-CTdH2u_E.js").then((n) => n.t);
|
|
28
|
-
return createCloudflareQueueClient(options);
|
|
29
|
-
}
|
|
30
|
-
const { createVercelQueueClient } = await import("./vercel-D31zfxiW.js");
|
|
31
|
-
return await createVercelQueueClient(options);
|
|
32
|
-
}
|
|
33
|
-
function getActiveQueueConfig() {
|
|
34
|
-
const config = getQueueRuntimeConfig();
|
|
35
|
-
if (config === false) return false;
|
|
36
|
-
return config || normalizeQueueOptions(void 0, { hosting: "vercel" });
|
|
37
|
-
}
|
|
38
|
-
async function createNamedQueueClient(name) {
|
|
39
|
-
const config = getActiveQueueConfig();
|
|
40
|
-
if (config === false) throw new QueueError("Queue is disabled.", {
|
|
41
|
-
code: "QUEUE_DISABLED",
|
|
42
|
-
httpStatus: 400
|
|
43
|
-
});
|
|
44
|
-
const provider = toProviderOptions(name, config);
|
|
45
|
-
try {
|
|
46
|
-
return await createQueueClient(provider);
|
|
47
|
-
} catch (error) {
|
|
48
|
-
if (error instanceof QueueError) throw error;
|
|
49
|
-
throw new QueueError(error instanceof Error ? error.message : String(error), {
|
|
50
|
-
cause: error,
|
|
51
|
-
provider: provider.provider
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
async function getQueue(name) {
|
|
56
|
-
const definition = await loadQueueDefinition(name);
|
|
57
|
-
if (!definition) throw new QueueError(`Unknown queue definition: ${name}`, {
|
|
58
|
-
code: "QUEUE_DEFINITION_NOT_FOUND",
|
|
59
|
-
details: { name },
|
|
60
|
-
httpStatus: 404
|
|
61
|
-
});
|
|
62
|
-
const config = getActiveQueueConfig();
|
|
63
|
-
if (definition.options?.cache === false || config === false || config.cache === false || config.provider === "cloudflare") return await createNamedQueueClient(name);
|
|
64
|
-
const cache = getQueueClientCache();
|
|
65
|
-
const existing = cache.get(name);
|
|
66
|
-
if (existing) return await existing;
|
|
67
|
-
const pending = createNamedQueueClient(name).catch((error) => {
|
|
68
|
-
cache.delete(name);
|
|
69
|
-
throw error;
|
|
70
|
-
});
|
|
71
|
-
cache.set(name, pending);
|
|
72
|
-
return await pending;
|
|
73
|
-
}
|
|
74
|
-
async function runQueue(name, input) {
|
|
75
|
-
if (!await loadQueueDefinition(name)) throw new QueueError(`Unknown queue definition: ${name}`, {
|
|
76
|
-
code: "QUEUE_DEFINITION_NOT_FOUND",
|
|
77
|
-
details: { name },
|
|
78
|
-
httpStatus: 404
|
|
79
|
-
});
|
|
80
|
-
const normalized = normalizeQueueEnqueueInput(input);
|
|
81
|
-
return await (await getQueue(name)).send({
|
|
82
|
-
...normalized.options,
|
|
83
|
-
id: normalized.id,
|
|
84
|
-
payload: normalized.payload
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
function deferQueue(name, input) {
|
|
88
|
-
const request = getQueueRuntimeEvent();
|
|
89
|
-
const task = () => runWithQueueRuntimeEvent(request, () => runQueue(name, input));
|
|
90
|
-
const handleError = async (error) => {
|
|
91
|
-
console.error(`[vitehub] Deferred queue dispatch failed for "${name}"`, error);
|
|
92
|
-
try {
|
|
93
|
-
await (await loadQueueDefinition(name))?.options?.onDispatchError?.(error, { name });
|
|
94
|
-
} catch (hookError) {
|
|
95
|
-
console.error(`[vitehub] onDispatchError hook failed for "${name}"`, hookError);
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
const promise = task().catch(handleError);
|
|
99
|
-
const waitUntil = resolveWaitUntil(request);
|
|
100
|
-
if (typeof waitUntil === "function") waitUntil(promise);
|
|
101
|
-
}
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/runtime/hosted.ts
|
|
104
|
-
const hostedVercelWaitUntil = waitUntil;
|
|
105
|
-
async function toRequest(event) {
|
|
106
|
-
if (event.request instanceof Request) return event.request;
|
|
107
|
-
const h3Event = event;
|
|
108
|
-
const body = await readRawBody(h3Event);
|
|
109
|
-
return new Request(getRequestURL(h3Event), {
|
|
110
|
-
body: body || void 0,
|
|
111
|
-
headers: getRequestHeaders(h3Event),
|
|
112
|
-
method: event.method || "POST"
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
function createVercelJobHandler(definition) {
|
|
116
|
-
return async (payload, metadata) => {
|
|
117
|
-
const meta = metadata;
|
|
118
|
-
await definition.handler({
|
|
119
|
-
attempts: typeof meta?.deliveryCount === "number" ? meta.deliveryCount : 1,
|
|
120
|
-
id: typeof meta?.messageId === "string" ? meta.messageId : "vercel-message",
|
|
121
|
-
metadata,
|
|
122
|
-
payload
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
async function handleHostedVercelQueueCallback(event, name, definition) {
|
|
127
|
-
const queue = await getQueue(name);
|
|
128
|
-
if (queue.provider !== "vercel") throw new QueueError(`Queue "${name}" resolved to provider "${queue.provider}", expected "vercel".`, {
|
|
129
|
-
code: "VERCEL_PROVIDER_EXPECTED",
|
|
130
|
-
httpStatus: 400,
|
|
131
|
-
provider: queue.provider
|
|
132
|
-
});
|
|
133
|
-
return await queue.callback(createVercelJobHandler(definition), definition.options?.callbackOptions)(await toRequest(event));
|
|
134
|
-
}
|
|
135
|
-
//#endregion
|
|
136
|
-
export { getQueue as a, deferQueue as i, hostedVercelWaitUntil as n, runQueue as o, createQueueClient as r, handleHostedVercelQueueCallback as t };
|