@vite-hub/queue 0.0.4 → 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 +170 -31
- package/dist/client-Cj50hQYp.js +180 -0
- package/dist/cloudflare-client-DYsAjM8B.js +140 -0
- package/dist/{cloudflare-resource-name-R8zYQiZb.js → cloudflare-resource-name-BJHYRCMQ.js} +3 -2
- 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-By0Fpspv.js +61 -0
- package/dist/index.d.ts +29 -83
- package/dist/index.js +24 -11
- package/dist/inspect-PeuckaC3.js +30 -0
- package/dist/internal/runtime/cloudflare-client.d.ts +3 -5
- 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 +23 -15
- package/dist/internal/runtime/state.js +2 -2
- package/dist/internal/runtime/vercel-client.d.ts +3 -5
- package/dist/internal/runtime/vercel-client.js +120 -63
- 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/operation-definition-8gOe-ubD.d.ts +234 -0
- package/dist/operations-Crwjca91.js +124 -0
- package/dist/operations.d.ts +69 -0
- package/dist/operations.js +1344 -0
- package/dist/runtime/hosted.d.ts +5 -9
- package/dist/runtime/hosted.js +21 -23
- package/dist/state-mVA2X_wa.js +196 -0
- 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 +655 -40
- package/dist/vite.js +2071 -2
- package/package.json +66 -30
- package/dist/_app-D29AwUdD.d.ts +0 -11
- package/dist/app-BZpq2cwC.js +0 -10
- package/dist/client-DG9fweET.js +0 -93
- package/dist/cloudflare-client-w5vphoNn.js +0 -99
- package/dist/cloudflare-vite-BlQfDVZD.js +0 -97
- package/dist/cloudflare-vite-nFPor46-.d.ts +0 -24
- package/dist/config-CNgAeIND.js +0 -53
- package/dist/delivery-error-glgYWC9g.js +0 -45
- package/dist/errors-CjuG_qr-.js +0 -108
- package/dist/internal/runtime/vercel-vite.d.ts +0 -20
- package/dist/internal/runtime/vercel-vite.js +0 -49
- package/dist/nuxt.d.ts +0 -19
- package/dist/nuxt.js +0 -30
- package/dist/state-Cno9O7YS.js +0 -110
- package/dist/types-CwvoMATy.d.ts +0 -169
- package/dist/vercel-runtime-package-copy-CEToJtCu.js +0 -116
- package/dist/vite-DOuoen0w.js +0 -4414
package/dist/runtime/hosted.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { b as QueueDefinition } from "../types-BD-8U9zS.js";
|
|
3
2
|
//#region src/runtime/hosted.d.ts
|
|
4
|
-
declare const hostedVercelWaitUntil: (promise: Promise<unknown>) => void | undefined;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}, name: string, definition: QueueDefinition): Promise<unknown>;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { handleHostedVercelQueueCallback, hostedVercelWaitUntil };
|
|
3
|
+
export declare const hostedVercelWaitUntil: (promise: Promise<unknown>) => void | undefined;
|
|
4
|
+
/** Handle one Vercel Queue delivery. The generated consumer route is a Fetchable module that passes its Request here. */
|
|
5
|
+
export declare function handleHostedVercelQueueCallback(request: Request, name: string, definition: QueueDefinition): Promise<Response>;
|
|
6
|
+
//#endregion
|
package/dist/runtime/hosted.js
CHANGED
|
@@ -1,28 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as
|
|
3
|
-
import {
|
|
1
|
+
import { t as queueErrorDiagnostics } from "../error-diagnostics-BRartC1z.js";
|
|
2
|
+
import { n as dynamicQueue } from "../client-Cj50hQYp.js";
|
|
3
|
+
import { i as reportQueueDeliveryError, r as isNonRetryableQueueError, t as checkQueueHandlerResponse } from "../handler-response-By0Fpspv.js";
|
|
4
|
+
import { runInRunScopes } from "@vite-hub/runtime/internal/run-scope";
|
|
4
5
|
import { waitUntil } from "@vercel/functions";
|
|
5
|
-
import { getRequestHeaders, getRequestURL, readRawBody } from "h3";
|
|
6
6
|
//#region src/runtime/hosted.ts
|
|
7
7
|
const hostedVercelWaitUntil = waitUntil;
|
|
8
|
-
async function toRequest(event) {
|
|
9
|
-
if (event.request instanceof Request) return event.request;
|
|
10
|
-
const h3Event = event;
|
|
11
|
-
const body = await readRawBody(h3Event);
|
|
12
|
-
return new Request(getRequestURL(h3Event), {
|
|
13
|
-
body: body || void 0,
|
|
14
|
-
headers: getRequestHeaders(h3Event),
|
|
15
|
-
method: event.method || "POST"
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
8
|
function createVercelJobHandler(definition) {
|
|
19
9
|
return async (payload, metadata) => {
|
|
20
10
|
const meta = metadata;
|
|
21
|
-
await
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
+
}));
|
|
26
18
|
});
|
|
27
19
|
};
|
|
28
20
|
}
|
|
@@ -44,10 +36,16 @@ function createVercelCallbackOptions(name, options) {
|
|
|
44
36
|
}
|
|
45
37
|
};
|
|
46
38
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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"
|
|
45
|
+
});
|
|
46
|
+
const result = await queue.callback(createVercelJobHandler(definition), createVercelCallbackOptions(name, definition.options?.callbackOptions))(request);
|
|
47
|
+
if (result instanceof Response) return result;
|
|
48
|
+
return result === void 0 ? new Response(null, { status: 204 }) : Response.json(result);
|
|
51
49
|
}
|
|
52
50
|
//#endregion
|
|
53
51
|
export { handleHostedVercelQueueCallback, hostedVercelWaitUntil };
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { t as queueErrorDiagnostics } from "./error-diagnostics-BRartC1z.js";
|
|
2
|
+
import { n as isRecord } from "./object-D8pRdprI.js";
|
|
3
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
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. */
|
|
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
|
|
46
|
+
const runtimeGlobal = globalThis;
|
|
47
|
+
const activeEnvStorage = runtimeGlobal[activeEnvStorageKey] ||= new AsyncLocalStorage();
|
|
48
|
+
const globalEnvProbe = Symbol("vitehub.cloudflare.global-env-probe");
|
|
49
|
+
/**
|
|
50
|
+
* Under the Nitro Cloudflare dev server, `cloudflare:workers` exports unenv's env proxy, which reads every key from
|
|
51
|
+
* `globalThis.__env__`. Storing that proxy in `__env__` makes it read itself, and the next read overflows the stack.
|
|
52
|
+
*/
|
|
53
|
+
function readsGlobalEnv(env) {
|
|
54
|
+
const scope = globalThis;
|
|
55
|
+
const owned = Object.hasOwn(scope, "__env__");
|
|
56
|
+
const previous = scope.__env__;
|
|
57
|
+
scope.__env__ = { [globalEnvProbe]: true };
|
|
58
|
+
try {
|
|
59
|
+
return Reflect.get(env, globalEnvProbe) === true;
|
|
60
|
+
} catch {
|
|
61
|
+
return false;
|
|
62
|
+
} finally {
|
|
63
|
+
if (owned) scope.__env__ = previous;
|
|
64
|
+
else delete scope.__env__;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function setActiveCloudflareEnv(env) {
|
|
68
|
+
setInstalledCloudflareEnv(env);
|
|
69
|
+
if (!env || !readsGlobalEnv(env)) globalThis.__env__ = env;
|
|
70
|
+
try {
|
|
71
|
+
activeEnvStorage.enterWith({ env });
|
|
72
|
+
} catch {}
|
|
73
|
+
}
|
|
74
|
+
function runWithActiveCloudflareEnv(env, callback) {
|
|
75
|
+
return activeEnvStorage.run({ env }, callback);
|
|
76
|
+
}
|
|
77
|
+
function resolveWaitUntil(event, options = {}) {
|
|
78
|
+
const target = ownObject(event);
|
|
79
|
+
const context = ownObject(ownValue(target, "context"));
|
|
80
|
+
const cloudflare = ownObject(ownValue(context, "cloudflare"));
|
|
81
|
+
const cloudflareContext = ownObject(ownValue(cloudflare, "context"));
|
|
82
|
+
const platformCloudflare = ownObject(ownValue(ownObject(ownValue(context, "_platform")), "cloudflare"));
|
|
83
|
+
const platformCloudflareContext = ownObject(ownValue(platformCloudflare, "context"));
|
|
84
|
+
const req = ownObject(ownValue(target, "req"));
|
|
85
|
+
const reqCloudflare = ownObject(ownValue(ownObject(ownValue(req, "runtime")), "cloudflare"));
|
|
86
|
+
const hosts = [
|
|
87
|
+
context,
|
|
88
|
+
cloudflare,
|
|
89
|
+
cloudflareContext,
|
|
90
|
+
platformCloudflare,
|
|
91
|
+
platformCloudflareContext,
|
|
92
|
+
req,
|
|
93
|
+
reqCloudflare,
|
|
94
|
+
ownObject(ownValue(reqCloudflare, "context"))
|
|
95
|
+
];
|
|
96
|
+
const owners = options.preferHost ? [...hosts, target] : [target, ...hosts];
|
|
97
|
+
for (const owner of owners) {
|
|
98
|
+
const waitUntil = ownValue(owner, "waitUntil");
|
|
99
|
+
if (typeof waitUntil === "function") return waitUntil.bind(owner);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function createCloudflareRuntimeEvent(env, context) {
|
|
103
|
+
const waitUntil = typeof context?.waitUntil === "function" ? context.waitUntil.bind(context) : void 0;
|
|
104
|
+
return {
|
|
105
|
+
context: {
|
|
106
|
+
cloudflare: {
|
|
107
|
+
env,
|
|
108
|
+
context
|
|
109
|
+
},
|
|
110
|
+
waitUntil
|
|
111
|
+
},
|
|
112
|
+
env,
|
|
113
|
+
waitUntil
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/internal/runtime/state.ts
|
|
118
|
+
let runtimeConfig;
|
|
119
|
+
let runtimeClientFactory;
|
|
120
|
+
let registryOverride;
|
|
121
|
+
let jobStore;
|
|
122
|
+
const queueEventStorage = new AsyncLocalStorage();
|
|
123
|
+
let queueEventDefaults;
|
|
124
|
+
const queueClientCache = /* @__PURE__ */ new Map();
|
|
125
|
+
function missingQueueDefinitionError(queue) {
|
|
126
|
+
return queueErrorDiagnostics.QUEUE_DEFINITION_NOT_FOUND({ queue });
|
|
127
|
+
}
|
|
128
|
+
function setQueueRuntimeConfig(config, createClient) {
|
|
129
|
+
runtimeConfig = config;
|
|
130
|
+
runtimeClientFactory = createClient;
|
|
131
|
+
if (typeof config === "undefined") queueEventDefaults = void 0;
|
|
132
|
+
queueClientCache.clear();
|
|
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
|
+
}
|
|
144
|
+
function getQueueRuntimeConfig() {
|
|
145
|
+
return runtimeConfig;
|
|
146
|
+
}
|
|
147
|
+
function getQueueRuntimeClientFactory() {
|
|
148
|
+
return runtimeClientFactory;
|
|
149
|
+
}
|
|
150
|
+
function runWithQueueRuntimeEvent(event, callback) {
|
|
151
|
+
return queueEventStorage.run(event, callback);
|
|
152
|
+
}
|
|
153
|
+
function enterQueueRuntimeEvent(event) {
|
|
154
|
+
try {
|
|
155
|
+
queueEventStorage.enterWith(event);
|
|
156
|
+
} catch {}
|
|
157
|
+
setActiveCloudflareEnv(event && typeof event === "object" && Object.hasOwn(event, "env") ? event.env : getCloudflareEnv(event));
|
|
158
|
+
}
|
|
159
|
+
function getQueueRuntimeEvent() {
|
|
160
|
+
return queueEventStorage.getStore() ?? queueEventDefaults;
|
|
161
|
+
}
|
|
162
|
+
function setQueueRuntimeEventDefaults(event) {
|
|
163
|
+
queueEventDefaults = event;
|
|
164
|
+
}
|
|
165
|
+
function setQueueRuntimeRegistry(registry) {
|
|
166
|
+
registryOverride = registry;
|
|
167
|
+
queueClientCache.clear();
|
|
168
|
+
}
|
|
169
|
+
/** The names of the Queue Definitions that this runtime loads, sorted. */
|
|
170
|
+
function listQueueDefinitionNames() {
|
|
171
|
+
return registryOverride ? Object.keys(registryOverride).sort() : [];
|
|
172
|
+
}
|
|
173
|
+
function getOrCreateQueueClient(name, createClient) {
|
|
174
|
+
const existing = queueClientCache.get(name);
|
|
175
|
+
if (existing) return existing;
|
|
176
|
+
const pending = createClient().catch((error) => {
|
|
177
|
+
if (queueClientCache.get(name) === pending) queueClientCache.delete(name);
|
|
178
|
+
throw error;
|
|
179
|
+
});
|
|
180
|
+
queueClientCache.set(name, pending);
|
|
181
|
+
return pending;
|
|
182
|
+
}
|
|
183
|
+
function isQueueDefinition(value) {
|
|
184
|
+
return isRecord(value) && Object.hasOwn(value, "handler") && typeof value.handler === "function";
|
|
185
|
+
}
|
|
186
|
+
async function loadQueueDefinition(name) {
|
|
187
|
+
const registry = registryOverride;
|
|
188
|
+
if (!registry || !Object.hasOwn(registry, name)) return void 0;
|
|
189
|
+
const entry = registry[name];
|
|
190
|
+
if (!entry) return;
|
|
191
|
+
const loaded = await entry();
|
|
192
|
+
if (isQueueDefinition(loaded)) return loaded;
|
|
193
|
+
if (isRecord(loaded) && Object.hasOwn(loaded, "default") && isQueueDefinition(loaded.default)) return loaded.default;
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
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 };
|