@vite-hub/queue 0.1.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +152 -29
- package/dist/client-B53_G4ky.js +182 -0
- package/dist/{cloudflare-client-COzQ8fHk.js → cloudflare-client-CoISDpIx.js} +28 -21
- package/dist/{cloudflare-resource-name-CCuLDvSP.js → cloudflare-resource-name-BIfBglC2.js} +1 -1
- package/dist/config-B2eaXaT5.js +105 -0
- package/dist/durability.d.ts +13 -0
- package/dist/durability.js +47 -0
- package/dist/duration-tujyhAKt.js +111 -0
- package/dist/error-diagnostics-CQ4BUqRe.js +270 -0
- package/dist/error-diagnostics-mJXBjmQx.js +181 -0
- package/dist/{handler-response-CBwIkmTS.js → handler-response-B6lz9nCn.js} +9 -4
- package/dist/index.d.ts +20 -32
- package/dist/index.js +39 -17
- package/dist/internal/runtime/cloudflare-client.d.ts +2 -2
- package/dist/internal/runtime/cloudflare-client.js +1 -1
- package/dist/internal/runtime/cloudflare-vite.d.ts +30 -2
- package/dist/internal/runtime/cloudflare-vite.js +111 -1
- package/dist/internal/runtime/local-client.d.ts +17 -0
- package/dist/internal/runtime/local-client.js +71 -0
- package/dist/internal/runtime/postgres-client.d.ts +46 -0
- package/dist/internal/runtime/postgres-client.js +570 -0
- package/dist/internal/runtime/state.d.ts +11 -4
- package/dist/internal/runtime/state.js +2 -2
- package/dist/internal/runtime/vercel-client.d.ts +2 -2
- package/dist/internal/runtime/vercel-client.js +66 -28
- package/dist/internal/runtime/worker-client.d.ts +6 -0
- package/dist/internal/runtime/worker-client.js +11 -0
- package/dist/invariant-D8_xBqmZ.js +22 -0
- package/dist/local-CUaWoRUx.d.ts +23 -0
- package/dist/local-Di0FrVUw.js +553 -0
- package/dist/object-D8pRdprI.js +15 -0
- package/dist/{operations-tNUdj3G4.d.ts → operation-definition-nmRu_O3V.d.ts} +42 -15
- package/dist/operations-BVV-9Q0N.js +129 -0
- package/dist/operations.d.ts +47 -9
- package/dist/operations.js +186 -69
- package/dist/runtime/hosted.d.ts +3 -5
- package/dist/runtime/hosted.js +21 -45
- package/dist/{state-G9s378-e.js → state-DLqTqF6V.js} +59 -47
- package/dist/types-CiuSIPR0.d.ts +440 -0
- package/dist/types-Dsbb_Pvp.d.ts +10 -0
- package/dist/vercel-region-B95MAMXN.js +26 -0
- package/dist/virtual.d.ts +4 -0
- package/dist/vite.d.ts +366 -49
- package/dist/vite.js +2071 -2
- package/package.json +39 -46
- package/dist/client-CIc3jsj2.js +0 -114
- package/dist/cloudflare-vite-BCuJOXcT.js +0 -111
- package/dist/cloudflare-vite-CjdP5yBN.d.ts +0 -29
- package/dist/config-BINujLv4.js +0 -74
- package/dist/enqueue-CnQ0QR3O.js +0 -22
- package/dist/error-diagnostics-A_8Kp-48.js +0 -116
- package/dist/error-diagnostics-qzRF6IVB.js +0 -109
- package/dist/errors-DIFaM9tW.js +0 -42
- package/dist/nuxt.d.ts +0 -39
- package/dist/nuxt.js +0 -34
- package/dist/object-B1NW521B.js +0 -7
- package/dist/operations-Cnjbz8kk.js +0 -63
- package/dist/types-1GRMYES1.d.ts +0 -180
- package/dist/vercel-region-cjskrOKl.js +0 -122
- package/dist/vite-ChWLzOVu.js +0 -1512
package/dist/runtime/hosted.js
CHANGED
|
@@ -1,48 +1,21 @@
|
|
|
1
|
-
import { t as queueErrorDiagnostics } from "../error-diagnostics-
|
|
2
|
-
import { n as
|
|
3
|
-
import {
|
|
1
|
+
import { t as queueErrorDiagnostics } from "../error-diagnostics-mJXBjmQx.js";
|
|
2
|
+
import { n as dynamicQueue } from "../client-B53_G4ky.js";
|
|
3
|
+
import { i as reportQueueDeliveryError, r as isNonRetryableQueueError, t as checkQueueHandlerResponse } from "../handler-response-B6lz9nCn.js";
|
|
4
|
+
import { runInRunScopes } from "@vite-hub/runtime/internal/run-scope";
|
|
4
5
|
import { waitUntil } from "@vercel/functions";
|
|
5
|
-
import { Request as Request$1 } from "undici";
|
|
6
|
-
import { getRequestHeaders, getRequestURL, readRawBody } from "h3";
|
|
7
6
|
//#region src/runtime/hosted.ts
|
|
8
7
|
const hostedVercelWaitUntil = waitUntil;
|
|
9
|
-
function isRequestLike(value) {
|
|
10
|
-
if (value === null || typeof value !== "object") return false;
|
|
11
|
-
return [Object.getOwnPropertyDescriptor(Request.prototype, "url")?.get, Object.getOwnPropertyDescriptor(Request$1.prototype, "url")?.get].filter((getter) => typeof getter === "function").some((getter) => {
|
|
12
|
-
try {
|
|
13
|
-
getter.call(value);
|
|
14
|
-
return true;
|
|
15
|
-
} catch {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
async function toRequest(event) {
|
|
21
|
-
let sameRealmRequest = false;
|
|
22
|
-
try {
|
|
23
|
-
sameRealmRequest = event.request instanceof Request;
|
|
24
|
-
} catch {
|
|
25
|
-
sameRealmRequest = false;
|
|
26
|
-
}
|
|
27
|
-
if (sameRealmRequest) return event.request;
|
|
28
|
-
if (isRequestLike(event.request)) return event.request;
|
|
29
|
-
const h3Event = event;
|
|
30
|
-
const body = await readRawBody(h3Event);
|
|
31
|
-
return new Request(getRequestURL(h3Event), {
|
|
32
|
-
body: body || void 0,
|
|
33
|
-
headers: getRequestHeaders(h3Event),
|
|
34
|
-
method: event.method || "POST"
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
8
|
function createVercelJobHandler(definition) {
|
|
38
9
|
return async (payload, metadata) => {
|
|
39
10
|
const meta = metadata;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
11
|
+
await runInRunScopes(async () => {
|
|
12
|
+
checkQueueHandlerResponse(await definition.handler({
|
|
13
|
+
attempts: typeof meta?.deliveryCount === "number" ? meta.deliveryCount : 1,
|
|
14
|
+
id: typeof meta?.messageId === "string" ? meta.messageId : "vercel-message",
|
|
15
|
+
metadata,
|
|
16
|
+
payload
|
|
17
|
+
}));
|
|
18
|
+
});
|
|
46
19
|
};
|
|
47
20
|
}
|
|
48
21
|
function createVercelCallbackOptions(name, options) {
|
|
@@ -63,13 +36,16 @@ function createVercelCallbackOptions(name, options) {
|
|
|
63
36
|
}
|
|
64
37
|
};
|
|
65
38
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
39
|
+
/** Handle one Vercel Queue delivery. The generated consumer route is a Fetchable module that passes its Request here. */
|
|
40
|
+
async function handleHostedVercelQueueCallback(request, name, definition) {
|
|
41
|
+
const queue = await dynamicQueue.use(name);
|
|
42
|
+
if (queue.provider !== "vercel") throw queueErrorDiagnostics.QUEUE_DRIVER_MISMATCH({
|
|
43
|
+
driver: queue.provider,
|
|
44
|
+
expected: "vercel"
|
|
71
45
|
});
|
|
72
|
-
|
|
46
|
+
const result = await queue.callback(createVercelJobHandler(definition), createVercelCallbackOptions(name, definition.callbackOptions))(request);
|
|
47
|
+
if (result instanceof Response) return result;
|
|
48
|
+
return result === void 0 ? new Response(null, { status: 204 }) : Response.json(result);
|
|
73
49
|
}
|
|
74
50
|
//#endregion
|
|
75
51
|
export { handleHostedVercelQueueCallback, hostedVercelWaitUntil };
|
|
@@ -1,10 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as queueErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { n as isRecord } from "./object-D8pRdprI.js";
|
|
2
|
+
import { t as queueErrorDiagnostics } from "./error-diagnostics-mJXBjmQx.js";
|
|
3
3
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let activeEnv;
|
|
4
|
+
//#region ../internal/src/runtime/cloudflare-env-lookup.ts
|
|
5
|
+
/** The key of the AsyncLocalStorage store on `globalThis`. Every bundled copy of this module shares the store. */
|
|
7
6
|
const activeEnvStorageKey = Symbol.for("vitehub.cloudflare.env-storage");
|
|
7
|
+
let activeEnv;
|
|
8
|
+
function setInstalledCloudflareEnv(env) {
|
|
9
|
+
activeEnv = env;
|
|
10
|
+
}
|
|
11
|
+
/** The store of the current `runWithActiveCloudflareEnv()` call, or undefined outside one. */
|
|
12
|
+
function getScopedCloudflareEnv() {
|
|
13
|
+
return globalThis[activeEnvStorageKey]?.getStore();
|
|
14
|
+
}
|
|
15
|
+
function getActiveCloudflareEnv() {
|
|
16
|
+
const scoped = getScopedCloudflareEnv();
|
|
17
|
+
if (scoped) return scoped.env;
|
|
18
|
+
const host = globalThis;
|
|
19
|
+
return Object.hasOwn(host, "__env__") && host.__env__ !== void 0 ? host.__env__ : activeEnv;
|
|
20
|
+
}
|
|
21
|
+
function ownValue(value, key) {
|
|
22
|
+
if (value === null || typeof value !== "object" && typeof value !== "function" || !Object.hasOwn(value, key)) return void 0;
|
|
23
|
+
return Reflect.get(value, key);
|
|
24
|
+
}
|
|
25
|
+
function ownObject(value) {
|
|
26
|
+
return value !== null && (typeof value === "object" || typeof value === "function") ? value : void 0;
|
|
27
|
+
}
|
|
28
|
+
/** The objects where H3 and Nitro hosts put Cloudflare `env` and `context`, in lookup order. */
|
|
29
|
+
function cloudflareOwners(target) {
|
|
30
|
+
const context = ownObject(ownValue(target, "context"));
|
|
31
|
+
const platform = ownObject(ownValue(context, "_platform"));
|
|
32
|
+
const req = ownObject(ownValue(target, "req"));
|
|
33
|
+
return [
|
|
34
|
+
ownObject(ownValue(context, "cloudflare")),
|
|
35
|
+
ownObject(ownValue(platform, "cloudflare")),
|
|
36
|
+
ownObject(ownValue(ownObject(ownValue(req, "runtime")), "cloudflare"))
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
function getCloudflareEnv(event, options = {}) {
|
|
40
|
+
const target = ownObject(event);
|
|
41
|
+
for (const candidate of [ownValue(target, "env"), ...cloudflareOwners(target).map((owner) => ownValue(owner, "env"))]) if (candidate) return candidate;
|
|
42
|
+
return options.fallback === false ? void 0 : getActiveCloudflareEnv();
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region ../internal/src/runtime/cloudflare-env.ts
|
|
8
46
|
const runtimeGlobal = globalThis;
|
|
9
47
|
const activeEnvStorage = runtimeGlobal[activeEnvStorageKey] ||= new AsyncLocalStorage();
|
|
10
48
|
const globalEnvProbe = Symbol("vitehub.cloudflare.global-env-probe");
|
|
@@ -27,7 +65,7 @@ function readsGlobalEnv(env) {
|
|
|
27
65
|
}
|
|
28
66
|
}
|
|
29
67
|
function setActiveCloudflareEnv(env) {
|
|
30
|
-
|
|
68
|
+
setInstalledCloudflareEnv(env);
|
|
31
69
|
if (!env || !readsGlobalEnv(env)) globalThis.__env__ = env;
|
|
32
70
|
try {
|
|
33
71
|
activeEnvStorage.enterWith({ env });
|
|
@@ -36,37 +74,6 @@ function setActiveCloudflareEnv(env) {
|
|
|
36
74
|
function runWithActiveCloudflareEnv(env, callback) {
|
|
37
75
|
return activeEnvStorage.run({ env }, callback);
|
|
38
76
|
}
|
|
39
|
-
function getActiveCloudflareEnv() {
|
|
40
|
-
const scoped = activeEnvStorage.getStore();
|
|
41
|
-
if (scoped) return scoped.env;
|
|
42
|
-
const host = globalThis;
|
|
43
|
-
return Object.hasOwn(host, "__env__") && host.__env__ !== void 0 ? host.__env__ : activeEnv;
|
|
44
|
-
}
|
|
45
|
-
function ownValue(value, key) {
|
|
46
|
-
if (value === null || typeof value !== "object" && typeof value !== "function" || !Object.hasOwn(value, key)) return void 0;
|
|
47
|
-
return Reflect.get(value, key);
|
|
48
|
-
}
|
|
49
|
-
function ownObject(value) {
|
|
50
|
-
return value !== null && (typeof value === "object" || typeof value === "function") ? value : void 0;
|
|
51
|
-
}
|
|
52
|
-
/** The objects where H3 1, H3 2, and Nitro hosts put Cloudflare `env` and `context`, in lookup order. */
|
|
53
|
-
function cloudflareOwners(target) {
|
|
54
|
-
const context = ownObject(ownValue(target, "context"));
|
|
55
|
-
const platform = ownObject(ownValue(context, "_platform"));
|
|
56
|
-
const req = ownObject(ownValue(target, "req"));
|
|
57
|
-
const nodeReq = ownObject(ownValue(ownObject(ownValue(target, "node")), "req"));
|
|
58
|
-
return [
|
|
59
|
-
ownObject(ownValue(context, "cloudflare")),
|
|
60
|
-
ownObject(ownValue(platform, "cloudflare")),
|
|
61
|
-
ownObject(ownValue(ownObject(ownValue(req, "runtime")), "cloudflare")),
|
|
62
|
-
ownObject(ownValue(ownObject(ownValue(nodeReq, "runtime")), "cloudflare"))
|
|
63
|
-
];
|
|
64
|
-
}
|
|
65
|
-
function getCloudflareEnv(event, options = {}) {
|
|
66
|
-
const target = ownObject(event);
|
|
67
|
-
for (const candidate of [ownValue(target, "env"), ...cloudflareOwners(target).map((owner) => ownValue(owner, "env"))]) if (candidate) return candidate;
|
|
68
|
-
return options.fallback === false ? void 0 : getActiveCloudflareEnv();
|
|
69
|
-
}
|
|
70
77
|
function resolveWaitUntil(event, options = {}) {
|
|
71
78
|
const target = ownObject(event);
|
|
72
79
|
const context = ownObject(ownValue(target, "context"));
|
|
@@ -76,9 +83,6 @@ function resolveWaitUntil(event, options = {}) {
|
|
|
76
83
|
const platformCloudflareContext = ownObject(ownValue(platformCloudflare, "context"));
|
|
77
84
|
const req = ownObject(ownValue(target, "req"));
|
|
78
85
|
const reqCloudflare = ownObject(ownValue(ownObject(ownValue(req, "runtime")), "cloudflare"));
|
|
79
|
-
const reqCloudflareContext = ownObject(ownValue(reqCloudflare, "context"));
|
|
80
|
-
const nodeReq = ownObject(ownValue(ownObject(ownValue(target, "node")), "req"));
|
|
81
|
-
const nodeCloudflare = ownObject(ownValue(ownObject(ownValue(nodeReq, "runtime")), "cloudflare"));
|
|
82
86
|
const hosts = [
|
|
83
87
|
context,
|
|
84
88
|
cloudflare,
|
|
@@ -87,10 +91,7 @@ function resolveWaitUntil(event, options = {}) {
|
|
|
87
91
|
platformCloudflareContext,
|
|
88
92
|
req,
|
|
89
93
|
reqCloudflare,
|
|
90
|
-
|
|
91
|
-
nodeReq,
|
|
92
|
-
nodeCloudflare,
|
|
93
|
-
ownObject(ownValue(nodeCloudflare, "context"))
|
|
94
|
+
ownObject(ownValue(reqCloudflare, "context"))
|
|
94
95
|
];
|
|
95
96
|
const owners = options.preferHost ? [...hosts, target] : [target, ...hosts];
|
|
96
97
|
for (const owner of owners) {
|
|
@@ -117,6 +118,7 @@ function createCloudflareRuntimeEvent(env, context) {
|
|
|
117
118
|
let runtimeConfig;
|
|
118
119
|
let runtimeClientFactory;
|
|
119
120
|
let registryOverride;
|
|
121
|
+
let jobStore;
|
|
120
122
|
const queueEventStorage = new AsyncLocalStorage();
|
|
121
123
|
let queueEventDefaults;
|
|
122
124
|
const queueClientCache = /* @__PURE__ */ new Map();
|
|
@@ -129,6 +131,16 @@ function setQueueRuntimeConfig(config, createClient) {
|
|
|
129
131
|
if (typeof config === "undefined") queueEventDefaults = void 0;
|
|
130
132
|
queueClientCache.clear();
|
|
131
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* The stored jobs of a provider that does not keep them in this package's process state. The generated server sets it
|
|
136
|
+
* for the postgres provider, so the Queue operations read jobs without importing the Postgres driver.
|
|
137
|
+
*/
|
|
138
|
+
function setQueueRuntimeJobStore(store) {
|
|
139
|
+
jobStore = store;
|
|
140
|
+
}
|
|
141
|
+
async function getQueueRuntimeJobStore() {
|
|
142
|
+
return await jobStore?.();
|
|
143
|
+
}
|
|
132
144
|
function getQueueRuntimeConfig() {
|
|
133
145
|
return runtimeConfig;
|
|
134
146
|
}
|
|
@@ -169,7 +181,7 @@ function getOrCreateQueueClient(name, createClient) {
|
|
|
169
181
|
return pending;
|
|
170
182
|
}
|
|
171
183
|
function isQueueDefinition(value) {
|
|
172
|
-
return
|
|
184
|
+
return isRecord(value) && Object.hasOwn(value, "handler") && typeof value.handler === "function";
|
|
173
185
|
}
|
|
174
186
|
async function loadQueueDefinition(name) {
|
|
175
187
|
const registry = registryOverride;
|
|
@@ -178,7 +190,7 @@ async function loadQueueDefinition(name) {
|
|
|
178
190
|
if (!entry) return;
|
|
179
191
|
const loaded = await entry();
|
|
180
192
|
if (isQueueDefinition(loaded)) return loaded;
|
|
181
|
-
if (
|
|
193
|
+
if (isRecord(loaded) && Object.hasOwn(loaded, "default") && isQueueDefinition(loaded.default)) return loaded.default;
|
|
182
194
|
}
|
|
183
195
|
//#endregion
|
|
184
|
-
export { getQueueRuntimeEvent as a,
|
|
196
|
+
export { runWithActiveCloudflareEnv as _, getQueueRuntimeEvent as a, loadQueueDefinition as c, setQueueRuntimeConfig as d, setQueueRuntimeEventDefaults as f, resolveWaitUntil as g, createCloudflareRuntimeEvent as h, getQueueRuntimeConfig as i, missingQueueDefinitionError as l, setQueueRuntimeRegistry as m, getOrCreateQueueClient as n, getQueueRuntimeJobStore as o, setQueueRuntimeJobStore as p, getQueueRuntimeClientFactory as r, listQueueDefinitionNames as s, enterQueueRuntimeEvent as t, runWithQueueRuntimeEvent as u, getCloudflareEnv as v };
|