@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
|
@@ -0,0 +1,105 @@
|
|
|
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 runWithActiveCloudflareEnv(env, callback) {
|
|
13
|
+
return activeEnvStorage.run({ env }, callback);
|
|
14
|
+
}
|
|
15
|
+
function getActiveCloudflareEnv() {
|
|
16
|
+
const scoped = activeEnvStorage.getStore();
|
|
17
|
+
return scoped ? scoped.env : activeEnv ?? globalThis.__env__;
|
|
18
|
+
}
|
|
19
|
+
function getCloudflareEnv(event) {
|
|
20
|
+
const target = event;
|
|
21
|
+
return target?.env || target?.context?.cloudflare?.env || target?.context?._platform?.cloudflare?.env || target?.req?.runtime?.cloudflare?.env || getActiveCloudflareEnv();
|
|
22
|
+
}
|
|
23
|
+
function resolveWaitUntil(event) {
|
|
24
|
+
const target = event;
|
|
25
|
+
const owners = [
|
|
26
|
+
target,
|
|
27
|
+
target?.context,
|
|
28
|
+
target?.context?.cloudflare,
|
|
29
|
+
target?.context?.cloudflare?.context,
|
|
30
|
+
target?.context?._platform?.cloudflare,
|
|
31
|
+
target?.context?._platform?.cloudflare?.context,
|
|
32
|
+
target?.req,
|
|
33
|
+
target?.req?.runtime?.cloudflare,
|
|
34
|
+
target?.req?.runtime?.cloudflare?.context
|
|
35
|
+
];
|
|
36
|
+
for (const owner of owners) if (typeof owner?.waitUntil === "function") return owner.waitUntil.bind(owner);
|
|
37
|
+
}
|
|
38
|
+
function createCloudflareRuntimeEvent(env, context) {
|
|
39
|
+
const waitUntil = typeof context?.waitUntil === "function" ? context.waitUntil.bind(context) : void 0;
|
|
40
|
+
return {
|
|
41
|
+
context: {
|
|
42
|
+
cloudflare: {
|
|
43
|
+
env,
|
|
44
|
+
context
|
|
45
|
+
},
|
|
46
|
+
waitUntil
|
|
47
|
+
},
|
|
48
|
+
env,
|
|
49
|
+
waitUntil
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/internal/runtime/state.ts
|
|
54
|
+
let runtimeConfig;
|
|
55
|
+
let runtimeClientFactory;
|
|
56
|
+
let registryOverride;
|
|
57
|
+
const queueEventStorage = new AsyncLocalStorage();
|
|
58
|
+
let queueEventDefaults;
|
|
59
|
+
const queueClientCache = /* @__PURE__ */ new Map();
|
|
60
|
+
function setQueueRuntimeConfig(config, createClient) {
|
|
61
|
+
runtimeConfig = config;
|
|
62
|
+
runtimeClientFactory = createClient;
|
|
63
|
+
if (typeof config === "undefined") queueEventDefaults = void 0;
|
|
64
|
+
queueClientCache.clear();
|
|
65
|
+
}
|
|
66
|
+
function getQueueRuntimeConfig() {
|
|
67
|
+
return runtimeConfig;
|
|
68
|
+
}
|
|
69
|
+
function getQueueRuntimeClientFactory() {
|
|
70
|
+
return runtimeClientFactory;
|
|
71
|
+
}
|
|
72
|
+
function runWithQueueRuntimeEvent(event, callback) {
|
|
73
|
+
return queueEventStorage.run(event, callback);
|
|
74
|
+
}
|
|
75
|
+
function enterQueueRuntimeEvent(event) {
|
|
76
|
+
try {
|
|
77
|
+
queueEventStorage.enterWith(event);
|
|
78
|
+
} catch {}
|
|
79
|
+
setActiveCloudflareEnv(getCloudflareEnv(event));
|
|
80
|
+
}
|
|
81
|
+
function getQueueRuntimeEvent() {
|
|
82
|
+
return queueEventStorage.getStore() ?? queueEventDefaults;
|
|
83
|
+
}
|
|
84
|
+
function setQueueRuntimeEventDefaults(event) {
|
|
85
|
+
queueEventDefaults = event;
|
|
86
|
+
}
|
|
87
|
+
function setQueueRuntimeRegistry(registry) {
|
|
88
|
+
registryOverride = registry;
|
|
89
|
+
queueClientCache.clear();
|
|
90
|
+
}
|
|
91
|
+
function getQueueClientCache() {
|
|
92
|
+
return queueClientCache;
|
|
93
|
+
}
|
|
94
|
+
function isQueueDefinition(value) {
|
|
95
|
+
return Boolean(value) && typeof value === "object" && typeof value.handler === "function";
|
|
96
|
+
}
|
|
97
|
+
async function loadQueueDefinition(name) {
|
|
98
|
+
const entry = registryOverride?.[name];
|
|
99
|
+
if (!entry) return;
|
|
100
|
+
const loaded = await entry();
|
|
101
|
+
if (isQueueDefinition(loaded)) return loaded;
|
|
102
|
+
if (loaded && typeof loaded === "object" && "default" in loaded && isQueueDefinition(loaded.default)) return loaded.default;
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
export { getQueueRuntimeEvent as a, setQueueRuntimeConfig as c, createCloudflareRuntimeEvent as d, getCloudflareEnv as f, getQueueRuntimeConfig as i, setQueueRuntimeEventDefaults as l, runWithActiveCloudflareEnv as m, getQueueClientCache as n, loadQueueDefinition as o, resolveWaitUntil as p, getQueueRuntimeClientFactory as r, runWithQueueRuntimeEvent as s, enterQueueRuntimeEvent as t, setQueueRuntimeRegistry as u };
|
|
@@ -75,6 +75,7 @@ interface CloudflareQueueProviderOptions extends QueueSharedOptions {
|
|
|
75
75
|
}
|
|
76
76
|
interface CloudflareQueueModuleProviderOptions extends QueueSharedOptions {
|
|
77
77
|
binding?: string;
|
|
78
|
+
namePrefix?: string;
|
|
78
79
|
provider: "cloudflare";
|
|
79
80
|
}
|
|
80
81
|
interface VercelQueueProviderOptions extends QueueSharedOptions {
|
|
@@ -90,6 +91,7 @@ interface VercelQueueModuleProviderOptions extends QueueSharedOptions {
|
|
|
90
91
|
type QueueProviderOptions = CloudflareQueueProviderOptions | VercelQueueProviderOptions;
|
|
91
92
|
type QueueModuleProviderOptions = CloudflareQueueModuleProviderOptions | VercelQueueModuleProviderOptions;
|
|
92
93
|
type QueueModuleOptions = false | (QueueSharedOptions & {
|
|
94
|
+
namePrefix?: string;
|
|
93
95
|
provider?: undefined;
|
|
94
96
|
}) | QueueModuleProviderOptions;
|
|
95
97
|
type ResolvedQueueOptions = QueueModuleProviderOptions;
|
|
@@ -161,7 +163,7 @@ interface QueueDefinitionRegistry {
|
|
|
161
163
|
interface DiscoveredQueueDefinition {
|
|
162
164
|
handler: string;
|
|
163
165
|
name: string;
|
|
164
|
-
source?: "
|
|
166
|
+
source?: "server-queues" | "vite-suffix";
|
|
165
167
|
}
|
|
166
168
|
//#endregion
|
|
167
169
|
export { VercelQueueRetryHandler as C, VercelQueueRetryDirective as S, QueueProviderOptions as _, DiscoveredQueueDefinition as a, VercelQueueCallbackOptions as b, QueueDefinitionOptions as c, QueueEnqueueOptions as d, QueueHandler as f, QueueProvider as g, QueueModuleProviderOptions as h, CloudflareQueueMessageBatch as i, QueueDefinitionRegistry as l, QueueModuleOptions as m, CloudflareQueueClient as n, QueueClient as o, QueueJob as p, CloudflareQueueMessage as r, QueueDefinition as s, CloudflareQueueBatchHandlerOptions as t, QueueEnqueueInput as u, QueueSendResult as v, VercelQueueSendResult as w, VercelQueueClient as x, ResolvedQueueOptions as y };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { i as createDefaultVercelOutputRoot } from "./vite-BcMpQk_n.js";
|
|
2
|
+
import { access, cp, mkdir, readFile, realpath, rm } from "node:fs/promises";
|
|
3
|
+
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
//#region ../internal/src/build/vercel-runtime-package-copy.ts
|
|
5
|
+
async function copyVercelFunctionRuntimePackageDirectories(options) {
|
|
6
|
+
if (!options.packages.length) return;
|
|
7
|
+
const outputNodeModules = resolve(resolve(options.outputRoot ?? createDefaultVercelOutputRoot(options.rootDir), "functions", options.serverFunctionName ?? "__server.func"), "node_modules");
|
|
8
|
+
const copied = /* @__PURE__ */ new Map();
|
|
9
|
+
const selected = /* @__PURE__ */ new Map();
|
|
10
|
+
for (const runtimePackage of options.packages) try {
|
|
11
|
+
selected.set(runtimePackage.name, await realpath(await resolvePackageJson(runtimePackage.name, dirname(runtimePackage.resolveFrom ?? join(options.rootDir, "package.json")))));
|
|
12
|
+
} catch (error) {
|
|
13
|
+
if (!runtimePackage.optional || error.code !== "ENOENT") throw error;
|
|
14
|
+
}
|
|
15
|
+
for (const runtimePackage of options.packages) await copyPackageDirectory(runtimePackage.name, runtimePackage.resolveFrom ?? join(options.rootDir, "package.json"), outputNodeModules, copied, selected, runtimePackage.optional);
|
|
16
|
+
}
|
|
17
|
+
async function copyPackageDirectory(name, resolveFrom, outputNodeModules, copied, selected, optional = false, conflictNodeModules) {
|
|
18
|
+
let resolvedPackageJsonPath;
|
|
19
|
+
try {
|
|
20
|
+
resolvedPackageJsonPath = await resolvePackageJson(name, dirname(resolveFrom));
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (optional && error.code === "ENOENT") return;
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
const packageJsonPath = await realpath(resolvedPackageJsonPath);
|
|
26
|
+
const packageDir = dirname(packageJsonPath);
|
|
27
|
+
let targetDir = join(outputNodeModules, ...name.split("/"));
|
|
28
|
+
const selectedPackage = selected.get(name);
|
|
29
|
+
const existingPackage = copied.get(targetDir);
|
|
30
|
+
if (selectedPackage && selectedPackage !== packageJsonPath || existingPackage && existingPackage !== packageJsonPath) {
|
|
31
|
+
if (!conflictNodeModules) return;
|
|
32
|
+
targetDir = join(conflictNodeModules, ...name.split("/"));
|
|
33
|
+
}
|
|
34
|
+
if (copied.get(targetDir) === packageJsonPath) return;
|
|
35
|
+
copied.set(targetDir, packageJsonPath);
|
|
36
|
+
await rm(targetDir, {
|
|
37
|
+
force: true,
|
|
38
|
+
recursive: true
|
|
39
|
+
});
|
|
40
|
+
await mkdir(dirname(targetDir), { recursive: true });
|
|
41
|
+
await cp(packageDir, targetDir, {
|
|
42
|
+
dereference: true,
|
|
43
|
+
filter: (source) => !relative(packageDir, source).split(sep).includes("node_modules"),
|
|
44
|
+
recursive: true
|
|
45
|
+
});
|
|
46
|
+
const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
|
|
47
|
+
for (const dependency of Object.keys(packageJson.dependencies ?? {})) await copyPackageDirectory(dependency, packageJsonPath, outputNodeModules, copied, selected, false, join(targetDir, "node_modules"));
|
|
48
|
+
}
|
|
49
|
+
async function resolvePackageJson(name, fromDir) {
|
|
50
|
+
let current = await realpath(fromDir).catch(() => fromDir);
|
|
51
|
+
while (current !== dirname(current)) {
|
|
52
|
+
const candidate = join(current, "node_modules", ...name.split("/"), "package.json");
|
|
53
|
+
try {
|
|
54
|
+
await access(candidate);
|
|
55
|
+
return candidate;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (error.code !== "ENOENT") throw error;
|
|
58
|
+
}
|
|
59
|
+
current = dirname(current);
|
|
60
|
+
}
|
|
61
|
+
const error = /* @__PURE__ */ new Error(`Could not resolve package.json for ${name}.`);
|
|
62
|
+
error.code = "ENOENT";
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { copyVercelFunctionRuntimePackageDirectories };
|