@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/errors-CjuG_qr-.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { ViteHubError, getViteHubErrorShape } from "@vite-hub/runtime";
|
|
2
|
-
//#region src/enqueue.ts
|
|
3
|
-
const envelopeKeys = new Set([
|
|
4
|
-
"contentType",
|
|
5
|
-
"delaySeconds",
|
|
6
|
-
"id",
|
|
7
|
-
"idempotencyKey",
|
|
8
|
-
"region",
|
|
9
|
-
"retentionSeconds"
|
|
10
|
-
]);
|
|
11
|
-
let fallbackCounter = 0;
|
|
12
|
-
function createQueueMessageId(prefix = "queue") {
|
|
13
|
-
const uuid = globalThis.crypto?.randomUUID?.();
|
|
14
|
-
if (uuid) return `${prefix}_${uuid}`;
|
|
15
|
-
fallbackCounter = fallbackCounter + 1 >>> 0;
|
|
16
|
-
return `${prefix}_${Date.now().toString(36)}_${fallbackCounter.toString(36)}`;
|
|
17
|
-
}
|
|
18
|
-
function isQueueEnvelope(input) {
|
|
19
|
-
if (typeof input !== "object" || input === null || Array.isArray(input) || !("payload" in input)) return false;
|
|
20
|
-
return Object.keys(input).every((key) => key === "payload" || envelopeKeys.has(key));
|
|
21
|
-
}
|
|
22
|
-
function normalizeQueueEnqueueInput(input) {
|
|
23
|
-
if (!isQueueEnvelope(input)) return {
|
|
24
|
-
id: createQueueMessageId(),
|
|
25
|
-
options: {},
|
|
26
|
-
payload: input
|
|
27
|
-
};
|
|
28
|
-
const { contentType, delaySeconds, id, idempotencyKey, payload, region, retentionSeconds } = input;
|
|
29
|
-
const options = {
|
|
30
|
-
...contentType !== void 0 ? { contentType } : {},
|
|
31
|
-
...delaySeconds !== void 0 ? { delaySeconds } : {},
|
|
32
|
-
...idempotencyKey !== void 0 ? { idempotencyKey } : {},
|
|
33
|
-
...region !== void 0 ? { region } : {},
|
|
34
|
-
...retentionSeconds !== void 0 ? { retentionSeconds } : {}
|
|
35
|
-
};
|
|
36
|
-
return {
|
|
37
|
-
id: typeof id === "string" && id.length > 0 ? id : createQueueMessageId(),
|
|
38
|
-
options,
|
|
39
|
-
payload
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
//#endregion
|
|
43
|
-
//#region src/errors.ts
|
|
44
|
-
const cloudflareUnsupportedEnqueueOptions = [
|
|
45
|
-
"idempotencyKey",
|
|
46
|
-
"region",
|
|
47
|
-
"retentionSeconds"
|
|
48
|
-
];
|
|
49
|
-
const queueErrorMessages = {
|
|
50
|
-
CLOUDFLARE_BINDING_INVALID: "[vitehub] Cloudflare queue binding is invalid.",
|
|
51
|
-
CLOUDFLARE_BINDING_RESOLUTION_REQUIRED: "[vitehub] Cloudflare queue requires a concrete request-scoped binding.",
|
|
52
|
-
CLOUDFLARE_UNSUPPORTED_ENQUEUE_OPTIONS: "[vitehub] Cloudflare queue does not support one or more enqueue options.",
|
|
53
|
-
QUEUE_DEFINITION_LOAD_FAILED: "[vitehub] Queue Definition could not be loaded.",
|
|
54
|
-
QUEUE_DEFINITION_NOT_FOUND: "[vitehub] Queue Definition is not registered. Queue Runtime Registry is installed by generated Provider Output.",
|
|
55
|
-
QUEUE_DISABLED: "[vitehub] Queue runtime is disabled.",
|
|
56
|
-
QUEUE_PROVIDER_OPERATION_FAILED: "[vitehub] Queue provider operation failed.",
|
|
57
|
-
QUEUE_PROVIDER_RESPONSE_INVALID: "[vitehub] Vercel queue provider returned an invalid send response.",
|
|
58
|
-
VERCEL_PROVIDER_EXPECTED: "[vitehub] Hosted Vercel Queue Delivery requires the Vercel provider.",
|
|
59
|
-
VERCEL_QUEUE_REGION_REQUIRED: "[vitehub] Vercel queue region could not be resolved.",
|
|
60
|
-
VERCEL_QUEUE_SDK_INVALID: "[vitehub] Vercel queue SDK does not expose the expected client API.",
|
|
61
|
-
VERCEL_QUEUE_SDK_LOAD_FAILED: "[vitehub] Vercel queue SDK could not be loaded.",
|
|
62
|
-
VERCEL_TOPIC_RESOLUTION_REQUIRED: "[vitehub] Vercel queue requires a concrete topic.",
|
|
63
|
-
VERCEL_UNSUPPORTED_ENQUEUE_OPTIONS: "[vitehub] Vercel queue does not support one or more enqueue options."
|
|
64
|
-
};
|
|
65
|
-
const queueOwnedErrors = /* @__PURE__ */ new WeakSet();
|
|
66
|
-
function createQueueError(code, options = {}) {
|
|
67
|
-
const details = options.details;
|
|
68
|
-
const error = new ViteHubError(code, code === "QUEUE_PROVIDER_OPERATION_FAILED" && details && "provider" in details && "operation" in details ? `[vitehub] ${details.provider} queue provider failed during ${details.operation}.` : queueErrorMessages[code], options);
|
|
69
|
-
queueOwnedErrors.add(error);
|
|
70
|
-
return error;
|
|
71
|
-
}
|
|
72
|
-
function isQueueOwnedError(error) {
|
|
73
|
-
return typeof error === "object" && error !== null && queueOwnedErrors.has(error);
|
|
74
|
-
}
|
|
75
|
-
function getQueueErrorPublicShape(error) {
|
|
76
|
-
return getViteHubErrorShape(error);
|
|
77
|
-
}
|
|
78
|
-
function normalizePublicQueueIdentifier(value) {
|
|
79
|
-
if (typeof value !== "string" || !value || value.length > 128 || value.trim() !== value) return;
|
|
80
|
-
if (!/^[a-z\d][a-z\d._/-]*$/i.test(value)) return;
|
|
81
|
-
if (/^[a-z][a-z\d+.-]*:\/\//i.test(value) || /^[a-z]:\//i.test(value)) return;
|
|
82
|
-
if (value.split("/").some((part) => part === "." || part === "..")) return;
|
|
83
|
-
return value;
|
|
84
|
-
}
|
|
85
|
-
function isQueueBoundaryIdentity(error) {
|
|
86
|
-
if (getViteHubErrorShape(error)) return true;
|
|
87
|
-
try {
|
|
88
|
-
return error instanceof Error && error.name === "AbortError";
|
|
89
|
-
} catch {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
async function runQueueProviderOperation(provider, operation, run) {
|
|
94
|
-
try {
|
|
95
|
-
return await run();
|
|
96
|
-
} catch (cause) {
|
|
97
|
-
if (isQueueBoundaryIdentity(cause)) throw cause;
|
|
98
|
-
throw createQueueError("QUEUE_PROVIDER_OPERATION_FAILED", {
|
|
99
|
-
cause,
|
|
100
|
-
details: {
|
|
101
|
-
operation,
|
|
102
|
-
provider
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
//#endregion
|
|
108
|
-
export { isQueueOwnedError as a, createQueueMessageId as c, isQueueBoundaryIdentity as i, normalizeQueueEnqueueInput as l, createQueueError as n, normalizePublicQueueIdentifier as o, getQueueErrorPublicShape as r, runQueueProviderOperation as s, cloudflareUnsupportedEnqueueOptions as t };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { l as QueueDefinitionRegistry, y as ResolvedQueueOptions } from "../../types-CwvoMATy.js";
|
|
2
|
-
import { t as QueueApp } from "../../_app-D29AwUdD.js";
|
|
3
|
-
import { QueueRuntimeClientFactory } from "./state.js";
|
|
4
|
-
|
|
5
|
-
//#region src/internal/runtime/vercel-vite.d.ts
|
|
6
|
-
interface QueueVercelServerBaseOptions {
|
|
7
|
-
app?: QueueApp;
|
|
8
|
-
registry?: QueueDefinitionRegistry;
|
|
9
|
-
}
|
|
10
|
-
type QueueVercelServerOptions = QueueVercelServerBaseOptions & ({
|
|
11
|
-
createClient: QueueRuntimeClientFactory;
|
|
12
|
-
queue?: ResolvedQueueOptions;
|
|
13
|
-
} | {
|
|
14
|
-
createClient?: never;
|
|
15
|
-
queue: false;
|
|
16
|
-
});
|
|
17
|
-
type QueueVercelServer = (req: unknown, res: unknown) => unknown;
|
|
18
|
-
declare function createQueueVercelServer(options: QueueVercelServerOptions): QueueVercelServer;
|
|
19
|
-
//#endregion
|
|
20
|
-
export { QueueVercelServer, createQueueVercelServer };
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { c as setQueueRuntimeConfig, s as runWithQueueRuntimeEvent, u as setQueueRuntimeRegistry } from "../../state-Cno9O7YS.js";
|
|
2
|
-
import { t as resolveAppFetch } from "../../app-BZpq2cwC.js";
|
|
3
|
-
import { waitUntil } from "@vercel/functions";
|
|
4
|
-
import { H3 } from "h3";
|
|
5
|
-
//#region ../internal/src/runtime/vercel-hosted.ts
|
|
6
|
-
function createVercelHostedServer(adapter) {
|
|
7
|
-
const app = new H3();
|
|
8
|
-
const appHandler = resolveAppFetch(adapter.label, adapter.app);
|
|
9
|
-
let nodeHandlerPromise;
|
|
10
|
-
return function hostedVercelServer(req, res) {
|
|
11
|
-
const handle = async () => {
|
|
12
|
-
nodeHandlerPromise ||= (async () => {
|
|
13
|
-
if (appHandler) {
|
|
14
|
-
const { fromWebHandler } = await import("h3");
|
|
15
|
-
app.use(fromWebHandler(async (request, context) => await appHandler(request, context)));
|
|
16
|
-
}
|
|
17
|
-
const { toNodeHandler } = await import("h3/node");
|
|
18
|
-
return toNodeHandler(app);
|
|
19
|
-
})();
|
|
20
|
-
return (await nodeHandlerPromise)(req, res);
|
|
21
|
-
};
|
|
22
|
-
if (adapter.onRequest) return adapter.onRequest({
|
|
23
|
-
handle,
|
|
24
|
-
req,
|
|
25
|
-
res
|
|
26
|
-
});
|
|
27
|
-
return handle();
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region src/internal/runtime/vercel-vite.ts
|
|
32
|
-
function createQueueVercelServer(options) {
|
|
33
|
-
if (options.queue !== false && !options.createClient) throw new TypeError("[vitehub] Enabled Vercel Queue output requires its generated client factory.");
|
|
34
|
-
return createVercelHostedServer({
|
|
35
|
-
app: options.app,
|
|
36
|
-
label: "queue",
|
|
37
|
-
onRequest({ handle, req, res }) {
|
|
38
|
-
setQueueRuntimeConfig(options.queue, options.createClient);
|
|
39
|
-
setQueueRuntimeRegistry(options.registry);
|
|
40
|
-
return runWithQueueRuntimeEvent({
|
|
41
|
-
req,
|
|
42
|
-
res,
|
|
43
|
-
waitUntil
|
|
44
|
-
}, handle);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
//#endregion
|
|
49
|
-
export { createQueueVercelServer };
|
package/dist/nuxt.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { m as QueueModuleOptions } from "./types-CwvoMATy.js";
|
|
2
|
-
|
|
3
|
-
//#region src/nuxt.d.ts
|
|
4
|
-
type QueueNuxtModuleOptions = QueueModuleOptions;
|
|
5
|
-
type NuxtLike = {
|
|
6
|
-
hook?: (name: "nitro:config", handler: (nitroConfig: Record<string, unknown>) => void | Promise<void>) => void;
|
|
7
|
-
options: {
|
|
8
|
-
dev?: boolean;
|
|
9
|
-
rootDir?: string;
|
|
10
|
-
serverDir?: string;
|
|
11
|
-
srcDir?: string;
|
|
12
|
-
vite?: {
|
|
13
|
-
plugins?: unknown[];
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
declare function viteHubQueueNuxtModule(options?: QueueNuxtModuleOptions, nuxt?: NuxtLike): void;
|
|
18
|
-
//#endregion
|
|
19
|
-
export { QueueNuxtModuleOptions, viteHubQueueNuxtModule as default };
|
package/dist/nuxt.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { n as hubQueue, t as createQueueNitroConfig } from "./vite-DOuoen0w.js";
|
|
2
|
-
//#region src/nuxt.ts
|
|
3
|
-
function isQueueVitePlugin(value) {
|
|
4
|
-
return Boolean(value && typeof value === "object" && value.name === "@vite-hub/queue/vite");
|
|
5
|
-
}
|
|
6
|
-
function findQueueVitePlugin(plugins) {
|
|
7
|
-
return plugins.flat(Infinity).find(isQueueVitePlugin);
|
|
8
|
-
}
|
|
9
|
-
function viteHubQueueNuxtModule(options = {}, nuxt) {
|
|
10
|
-
if (!nuxt) return;
|
|
11
|
-
nuxt.options.vite ??= {};
|
|
12
|
-
const plugins = Array.isArray(nuxt.options.vite.plugins) ? nuxt.options.vite.plugins : [];
|
|
13
|
-
const existingPlugin = findQueueVitePlugin(plugins);
|
|
14
|
-
const plugin = existingPlugin || hubQueue(options);
|
|
15
|
-
if (!existingPlugin) plugins.push(plugin);
|
|
16
|
-
nuxt.options.vite.plugins = plugins;
|
|
17
|
-
nuxt.hook?.("nitro:config", async (nitroConfig) => {
|
|
18
|
-
const projectRoot = nuxt.options.rootDir || process.cwd();
|
|
19
|
-
const nitro = await createQueueNitroConfig(plugin, {
|
|
20
|
-
development: nuxt.options.dev,
|
|
21
|
-
nitro: nitroConfig,
|
|
22
|
-
projectRoot,
|
|
23
|
-
root: nuxt.options.srcDir || projectRoot,
|
|
24
|
-
serverDirs: nuxt.options.serverDir ? [nuxt.options.serverDir] : void 0
|
|
25
|
-
});
|
|
26
|
-
Object.assign(nitroConfig, nitro);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
//#endregion
|
|
30
|
-
export { viteHubQueueNuxtModule as default };
|
package/dist/state-Cno9O7YS.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
//#region ../internal/src/runtime/cloudflare-env.ts
|
|
3
|
-
let activeEnv;
|
|
4
|
-
const activeEnvStorageKey = Symbol.for("vitehub.cloudflare.env-storage");
|
|
5
|
-
const runtimeGlobal = globalThis;
|
|
6
|
-
const activeEnvStorage = runtimeGlobal[activeEnvStorageKey] ||= new AsyncLocalStorage();
|
|
7
|
-
function setActiveCloudflareEnv(env) {
|
|
8
|
-
activeEnv = env;
|
|
9
|
-
globalThis.__env__ = env;
|
|
10
|
-
try {
|
|
11
|
-
activeEnvStorage.enterWith({ env });
|
|
12
|
-
} catch {}
|
|
13
|
-
}
|
|
14
|
-
function runWithActiveCloudflareEnv(env, callback) {
|
|
15
|
-
return activeEnvStorage.run({ env }, callback);
|
|
16
|
-
}
|
|
17
|
-
function getActiveCloudflareEnv() {
|
|
18
|
-
const scoped = activeEnvStorage.getStore();
|
|
19
|
-
return scoped ? scoped.env : activeEnv ?? globalThis.__env__;
|
|
20
|
-
}
|
|
21
|
-
function getCloudflareEnv(event) {
|
|
22
|
-
const target = event;
|
|
23
|
-
return target?.env || target?.context?.cloudflare?.env || target?.context?._platform?.cloudflare?.env || target?.req?.runtime?.cloudflare?.env || target?.node?.req?.runtime?.cloudflare?.env || getActiveCloudflareEnv();
|
|
24
|
-
}
|
|
25
|
-
function resolveWaitUntil(event) {
|
|
26
|
-
const target = event;
|
|
27
|
-
const owners = [
|
|
28
|
-
target,
|
|
29
|
-
target?.context,
|
|
30
|
-
target?.context?.cloudflare,
|
|
31
|
-
target?.context?.cloudflare?.context,
|
|
32
|
-
target?.context?._platform?.cloudflare,
|
|
33
|
-
target?.context?._platform?.cloudflare?.context,
|
|
34
|
-
target?.req,
|
|
35
|
-
target?.req?.runtime?.cloudflare,
|
|
36
|
-
target?.req?.runtime?.cloudflare?.context,
|
|
37
|
-
target?.node?.req,
|
|
38
|
-
target?.node?.req?.runtime?.cloudflare,
|
|
39
|
-
target?.node?.req?.runtime?.cloudflare?.context
|
|
40
|
-
];
|
|
41
|
-
for (const owner of owners) if (typeof owner?.waitUntil === "function") return owner.waitUntil.bind(owner);
|
|
42
|
-
}
|
|
43
|
-
function createCloudflareRuntimeEvent(env, context) {
|
|
44
|
-
const waitUntil = typeof context?.waitUntil === "function" ? context.waitUntil.bind(context) : void 0;
|
|
45
|
-
return {
|
|
46
|
-
context: {
|
|
47
|
-
cloudflare: {
|
|
48
|
-
env,
|
|
49
|
-
context
|
|
50
|
-
},
|
|
51
|
-
waitUntil
|
|
52
|
-
},
|
|
53
|
-
env,
|
|
54
|
-
waitUntil
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region src/internal/runtime/state.ts
|
|
59
|
-
let runtimeConfig;
|
|
60
|
-
let runtimeClientFactory;
|
|
61
|
-
let registryOverride;
|
|
62
|
-
const queueEventStorage = new AsyncLocalStorage();
|
|
63
|
-
let queueEventDefaults;
|
|
64
|
-
const queueClientCache = /* @__PURE__ */ new Map();
|
|
65
|
-
function setQueueRuntimeConfig(config, createClient) {
|
|
66
|
-
runtimeConfig = config;
|
|
67
|
-
runtimeClientFactory = createClient;
|
|
68
|
-
if (typeof config === "undefined") queueEventDefaults = void 0;
|
|
69
|
-
queueClientCache.clear();
|
|
70
|
-
}
|
|
71
|
-
function getQueueRuntimeConfig() {
|
|
72
|
-
return runtimeConfig;
|
|
73
|
-
}
|
|
74
|
-
function getQueueRuntimeClientFactory() {
|
|
75
|
-
return runtimeClientFactory;
|
|
76
|
-
}
|
|
77
|
-
function runWithQueueRuntimeEvent(event, callback) {
|
|
78
|
-
return queueEventStorage.run(event, callback);
|
|
79
|
-
}
|
|
80
|
-
function enterQueueRuntimeEvent(event) {
|
|
81
|
-
try {
|
|
82
|
-
queueEventStorage.enterWith(event);
|
|
83
|
-
} catch {}
|
|
84
|
-
setActiveCloudflareEnv(event && typeof event === "object" && Object.hasOwn(event, "env") ? event.env : getCloudflareEnv(event));
|
|
85
|
-
}
|
|
86
|
-
function getQueueRuntimeEvent() {
|
|
87
|
-
return queueEventStorage.getStore() ?? queueEventDefaults;
|
|
88
|
-
}
|
|
89
|
-
function setQueueRuntimeEventDefaults(event) {
|
|
90
|
-
queueEventDefaults = event;
|
|
91
|
-
}
|
|
92
|
-
function setQueueRuntimeRegistry(registry) {
|
|
93
|
-
registryOverride = registry;
|
|
94
|
-
queueClientCache.clear();
|
|
95
|
-
}
|
|
96
|
-
function getQueueClientCache() {
|
|
97
|
-
return queueClientCache;
|
|
98
|
-
}
|
|
99
|
-
function isQueueDefinition(value) {
|
|
100
|
-
return Boolean(value) && typeof value === "object" && typeof value.handler === "function";
|
|
101
|
-
}
|
|
102
|
-
async function loadQueueDefinition(name) {
|
|
103
|
-
const entry = registryOverride?.[name];
|
|
104
|
-
if (!entry) return;
|
|
105
|
-
const loaded = await entry();
|
|
106
|
-
if (isQueueDefinition(loaded)) return loaded;
|
|
107
|
-
if (loaded && typeof loaded === "object" && "default" in loaded && isQueueDefinition(loaded.default)) return loaded.default;
|
|
108
|
-
}
|
|
109
|
-
//#endregion
|
|
110
|
-
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 };
|
package/dist/types-CwvoMATy.d.ts
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
//#region src/types.d.ts
|
|
2
|
-
type QueueProvider = "cloudflare" | "vercel";
|
|
3
|
-
type CloudflareQueueContentType = "bytes" | "json" | "text" | "v8";
|
|
4
|
-
interface CloudflareQueueSendOptions {
|
|
5
|
-
contentType?: CloudflareQueueContentType;
|
|
6
|
-
delaySeconds?: number;
|
|
7
|
-
}
|
|
8
|
-
interface CloudflareQueueSendBatchOptions {
|
|
9
|
-
delaySeconds?: number;
|
|
10
|
-
}
|
|
11
|
-
interface CloudflareQueueSendBatchMessage<T = unknown> extends CloudflareQueueSendOptions {
|
|
12
|
-
body: T;
|
|
13
|
-
}
|
|
14
|
-
interface CloudflareQueueRetryOptions {
|
|
15
|
-
delaySeconds?: number;
|
|
16
|
-
}
|
|
17
|
-
interface CloudflareQueueBinding {
|
|
18
|
-
send: <T = unknown>(body: T, options?: CloudflareQueueSendOptions) => Promise<unknown>;
|
|
19
|
-
sendBatch: <T = unknown>(messages: Iterable<CloudflareQueueSendBatchMessage<T>>, options?: CloudflareQueueSendBatchOptions) => Promise<unknown>;
|
|
20
|
-
}
|
|
21
|
-
interface CloudflareQueueMessage<T = unknown> {
|
|
22
|
-
ack: () => void;
|
|
23
|
-
attempts: number;
|
|
24
|
-
body: T;
|
|
25
|
-
id: string;
|
|
26
|
-
retry: (options?: CloudflareQueueRetryOptions) => void;
|
|
27
|
-
timestamp?: Date;
|
|
28
|
-
}
|
|
29
|
-
interface CloudflareQueueMessageBatch<T = unknown> {
|
|
30
|
-
ackAll: () => void;
|
|
31
|
-
messages: CloudflareQueueMessage<T>[];
|
|
32
|
-
queue: string;
|
|
33
|
-
retryAll: (options?: CloudflareQueueRetryOptions) => void;
|
|
34
|
-
}
|
|
35
|
-
type CloudflareQueueBatchErrorAction = "ack" | "retry" | {
|
|
36
|
-
retry: CloudflareQueueRetryOptions;
|
|
37
|
-
};
|
|
38
|
-
interface CloudflareQueueBatchHandlerOptions<T = unknown> {
|
|
39
|
-
concurrency?: number;
|
|
40
|
-
onError?: (error: unknown, message: CloudflareQueueMessage<T>, batch: CloudflareQueueMessageBatch<T>) => CloudflareQueueBatchErrorAction | void | Promise<CloudflareQueueBatchErrorAction | void>;
|
|
41
|
-
onMessage: (message: CloudflareQueueMessage<T>, batch: CloudflareQueueMessageBatch<T>) => unknown | Promise<unknown>;
|
|
42
|
-
}
|
|
43
|
-
type VercelQueueRetryDirective = {
|
|
44
|
-
acknowledge: true;
|
|
45
|
-
} | {
|
|
46
|
-
afterSeconds: number;
|
|
47
|
-
};
|
|
48
|
-
type VercelQueueRetryHandler = (error: unknown, metadata: unknown) => VercelQueueRetryDirective | void;
|
|
49
|
-
interface VercelQueueCallbackOptions {
|
|
50
|
-
retry?: VercelQueueRetryHandler;
|
|
51
|
-
visibilityTimeoutSeconds?: number;
|
|
52
|
-
}
|
|
53
|
-
interface VercelQueueSendOptions {
|
|
54
|
-
delaySeconds?: number;
|
|
55
|
-
headers?: Record<string, string>;
|
|
56
|
-
idempotencyKey?: string;
|
|
57
|
-
region?: string;
|
|
58
|
-
retentionSeconds?: number;
|
|
59
|
-
}
|
|
60
|
-
interface VercelQueueSendResult {
|
|
61
|
-
messageId?: string | null;
|
|
62
|
-
}
|
|
63
|
-
type VercelQueueMessageHandler<T = unknown> = (payload: T, metadata?: unknown) => unknown | Promise<unknown>;
|
|
64
|
-
type VercelQueueCallbackReturn = (request: Request) => Promise<unknown> | unknown;
|
|
65
|
-
interface VercelQueueSDK {
|
|
66
|
-
handleCallback: <TPayload = unknown>(handler: VercelQueueMessageHandler<TPayload>, options?: VercelQueueCallbackOptions) => VercelQueueCallbackReturn;
|
|
67
|
-
send: (topic: string, payload: unknown, options?: VercelQueueSendOptions) => Promise<VercelQueueSendResult>;
|
|
68
|
-
}
|
|
69
|
-
interface QueueSharedOptions {
|
|
70
|
-
cache?: boolean;
|
|
71
|
-
}
|
|
72
|
-
interface CloudflareQueueProviderOptions extends QueueSharedOptions {
|
|
73
|
-
binding?: string | CloudflareQueueBinding;
|
|
74
|
-
provider: "cloudflare";
|
|
75
|
-
}
|
|
76
|
-
interface CloudflareQueueModuleProviderOptions extends QueueSharedOptions {
|
|
77
|
-
binding?: string;
|
|
78
|
-
namePrefix?: string;
|
|
79
|
-
provider: "cloudflare";
|
|
80
|
-
}
|
|
81
|
-
interface VercelQueueProviderOptions extends QueueSharedOptions {
|
|
82
|
-
client?: VercelQueueSDK;
|
|
83
|
-
provider: "vercel";
|
|
84
|
-
region?: string;
|
|
85
|
-
topic?: string;
|
|
86
|
-
}
|
|
87
|
-
interface VercelQueueModuleProviderOptions extends QueueSharedOptions {
|
|
88
|
-
provider: "vercel";
|
|
89
|
-
region?: string;
|
|
90
|
-
}
|
|
91
|
-
type QueueProviderOptions = CloudflareQueueProviderOptions | VercelQueueProviderOptions;
|
|
92
|
-
type QueueModuleProviderOptions = CloudflareQueueModuleProviderOptions | VercelQueueModuleProviderOptions;
|
|
93
|
-
type QueueModuleOptions = false | (QueueSharedOptions & {
|
|
94
|
-
namePrefix?: string;
|
|
95
|
-
provider?: undefined;
|
|
96
|
-
}) | QueueModuleProviderOptions;
|
|
97
|
-
type ResolvedQueueOptions = QueueModuleProviderOptions;
|
|
98
|
-
interface QueueJob<TPayload = unknown> {
|
|
99
|
-
attempts: number;
|
|
100
|
-
id: string;
|
|
101
|
-
metadata?: unknown;
|
|
102
|
-
payload: TPayload;
|
|
103
|
-
}
|
|
104
|
-
type QueueHandler<TPayload = unknown, TResult = unknown> = (job: QueueJob<TPayload>) => TResult;
|
|
105
|
-
interface QueueDefinitionOptions {
|
|
106
|
-
cache?: boolean;
|
|
107
|
-
callbackOptions?: VercelQueueCallbackOptions;
|
|
108
|
-
concurrency?: number;
|
|
109
|
-
onDispatchError?: (error: unknown, context: {
|
|
110
|
-
name: string;
|
|
111
|
-
}) => unknown | Promise<unknown>;
|
|
112
|
-
onError?: CloudflareQueueBatchHandlerOptions["onError"];
|
|
113
|
-
}
|
|
114
|
-
interface QueueDefinition<TPayload = unknown, TResult = unknown> {
|
|
115
|
-
handler: QueueHandler<TPayload, TResult>;
|
|
116
|
-
options?: QueueDefinitionOptions;
|
|
117
|
-
}
|
|
118
|
-
interface QueueEnqueueOptions {
|
|
119
|
-
contentType?: CloudflareQueueContentType;
|
|
120
|
-
delaySeconds?: number;
|
|
121
|
-
idempotencyKey?: string;
|
|
122
|
-
region?: string;
|
|
123
|
-
retentionSeconds?: number;
|
|
124
|
-
}
|
|
125
|
-
type QueueEnqueueEnvelope<TPayload = unknown> = {
|
|
126
|
-
payload: TPayload;
|
|
127
|
-
contentType?: CloudflareQueueContentType;
|
|
128
|
-
delaySeconds?: number;
|
|
129
|
-
id?: string;
|
|
130
|
-
idempotencyKey?: string;
|
|
131
|
-
region?: string;
|
|
132
|
-
retentionSeconds?: number;
|
|
133
|
-
};
|
|
134
|
-
type QueueEnqueueInput<TPayload = unknown> = TPayload | QueueEnqueueEnvelope<TPayload>;
|
|
135
|
-
type QueueSendResult = {
|
|
136
|
-
messageId?: string;
|
|
137
|
-
status: "queued";
|
|
138
|
-
};
|
|
139
|
-
interface QueueClientBase<P extends QueueProvider = QueueProvider> {
|
|
140
|
-
readonly native: unknown;
|
|
141
|
-
readonly provider: P;
|
|
142
|
-
send: <TPayload = unknown>(input: QueueEnqueueInput<TPayload>) => Promise<QueueSendResult>;
|
|
143
|
-
}
|
|
144
|
-
interface CloudflareQueueClient extends QueueClientBase<"cloudflare"> {
|
|
145
|
-
readonly binding: CloudflareQueueBinding;
|
|
146
|
-
createBatchHandler: <TPayload = unknown>(options: CloudflareQueueBatchHandlerOptions<TPayload>) => (batch: CloudflareQueueMessageBatch<TPayload>) => Promise<void>;
|
|
147
|
-
sendBatch: (items: CloudflareQueueSendBatchMessage[], options?: QueueEnqueueOptions) => Promise<QueueSendResult[]>;
|
|
148
|
-
}
|
|
149
|
-
interface VercelQueueClient extends QueueClientBase<"vercel"> {
|
|
150
|
-
readonly topic: string;
|
|
151
|
-
callback: <TPayload = unknown>(handler: VercelQueueMessageHandler<TPayload>, options?: VercelQueueCallbackOptions) => VercelQueueCallbackReturn;
|
|
152
|
-
}
|
|
153
|
-
interface QueueClientMap {
|
|
154
|
-
cloudflare: CloudflareQueueClient;
|
|
155
|
-
vercel: VercelQueueClient;
|
|
156
|
-
}
|
|
157
|
-
type QueueClient<P extends QueueProvider = QueueProvider> = QueueClientMap[P];
|
|
158
|
-
interface QueueDefinitionRegistry {
|
|
159
|
-
[name: string]: () => Promise<{
|
|
160
|
-
default?: QueueDefinition;
|
|
161
|
-
} | QueueDefinition>;
|
|
162
|
-
}
|
|
163
|
-
interface DiscoveredQueueDefinition {
|
|
164
|
-
handler: string;
|
|
165
|
-
name: string;
|
|
166
|
-
source?: "server-queues" | "vite-suffix";
|
|
167
|
-
}
|
|
168
|
-
//#endregion
|
|
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 };
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { a as createDefaultVercelOutputRoot } from "./vite-DOuoen0w.js";
|
|
2
|
-
import { access, cp, mkdir, mkdtemp, readFile, realpath, rename, 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 functionDir = resolve(options.outputRoot ?? createDefaultVercelOutputRoot(options.rootDir), "functions", options.serverFunctionName ?? "__server.func");
|
|
8
|
-
const outputNodeModules = resolve(functionDir, "node_modules");
|
|
9
|
-
const stagingRoot = await mkdtemp(resolve(functionDir, ".vitehub-runtime-package-directories-"));
|
|
10
|
-
const stagedNodeModules = resolve(stagingRoot, "node_modules");
|
|
11
|
-
const previousNodeModules = resolve(stagingRoot, "previous-node_modules");
|
|
12
|
-
let movedPreviousOutput = false;
|
|
13
|
-
let installedReplacement = false;
|
|
14
|
-
let publicationSucceeded = false;
|
|
15
|
-
let restorationSucceeded = false;
|
|
16
|
-
try {
|
|
17
|
-
try {
|
|
18
|
-
await cp(outputNodeModules, stagedNodeModules, { recursive: true });
|
|
19
|
-
} catch (error) {
|
|
20
|
-
if (error.code !== "ENOENT") throw error;
|
|
21
|
-
}
|
|
22
|
-
await mkdir(stagedNodeModules, { recursive: true });
|
|
23
|
-
const copied = /* @__PURE__ */ new Map();
|
|
24
|
-
const selected = /* @__PURE__ */ new Map();
|
|
25
|
-
for (const runtimePackage of options.packages) try {
|
|
26
|
-
selected.set(runtimePackage.name, await realpath(await resolvePackageJson(runtimePackage.name, dirname(runtimePackage.resolveFrom ?? join(options.rootDir, "package.json")))));
|
|
27
|
-
} catch (error) {
|
|
28
|
-
if (!runtimePackage.optional || error.code !== "ENOENT") throw error;
|
|
29
|
-
}
|
|
30
|
-
for (const runtimePackage of options.packages) await copyPackageDirectory(runtimePackage.name, runtimePackage.resolveFrom ?? join(options.rootDir, "package.json"), stagedNodeModules, copied, selected, runtimePackage.optional);
|
|
31
|
-
options.signal?.throwIfAborted();
|
|
32
|
-
try {
|
|
33
|
-
await rename(outputNodeModules, previousNodeModules);
|
|
34
|
-
movedPreviousOutput = true;
|
|
35
|
-
} catch (error) {
|
|
36
|
-
if (error.code !== "ENOENT") throw error;
|
|
37
|
-
}
|
|
38
|
-
try {
|
|
39
|
-
options.signal?.throwIfAborted();
|
|
40
|
-
await rename(stagedNodeModules, outputNodeModules);
|
|
41
|
-
installedReplacement = true;
|
|
42
|
-
options.signal?.throwIfAborted();
|
|
43
|
-
publicationSucceeded = true;
|
|
44
|
-
} catch (error) {
|
|
45
|
-
if (installedReplacement) await rm(outputNodeModules, {
|
|
46
|
-
force: true,
|
|
47
|
-
recursive: true
|
|
48
|
-
});
|
|
49
|
-
if (movedPreviousOutput) {
|
|
50
|
-
await rename(previousNodeModules, outputNodeModules);
|
|
51
|
-
restorationSucceeded = true;
|
|
52
|
-
}
|
|
53
|
-
throw error;
|
|
54
|
-
}
|
|
55
|
-
} finally {
|
|
56
|
-
if (!movedPreviousOutput || publicationSucceeded || restorationSucceeded) await rm(stagingRoot, {
|
|
57
|
-
force: true,
|
|
58
|
-
recursive: true
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
async function copyPackageDirectory(name, resolveFrom, outputNodeModules, copied, selected, optional = false, conflictNodeModules) {
|
|
63
|
-
let resolvedPackageJsonPath;
|
|
64
|
-
try {
|
|
65
|
-
resolvedPackageJsonPath = await resolvePackageJson(name, dirname(resolveFrom));
|
|
66
|
-
} catch (error) {
|
|
67
|
-
if (optional && error.code === "ENOENT") return;
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
70
|
-
const packageJsonPath = await realpath(resolvedPackageJsonPath);
|
|
71
|
-
const packageDir = dirname(packageJsonPath);
|
|
72
|
-
let targetDir = join(outputNodeModules, ...name.split("/"));
|
|
73
|
-
const selectedPackage = selected.get(name);
|
|
74
|
-
const existingPackage = copied.get(targetDir);
|
|
75
|
-
if (selectedPackage && selectedPackage !== packageJsonPath || existingPackage && existingPackage !== packageJsonPath) {
|
|
76
|
-
if (!conflictNodeModules) return;
|
|
77
|
-
targetDir = join(conflictNodeModules, ...name.split("/"));
|
|
78
|
-
}
|
|
79
|
-
if (copied.get(targetDir) === packageJsonPath) return;
|
|
80
|
-
copied.set(targetDir, packageJsonPath);
|
|
81
|
-
await rm(targetDir, {
|
|
82
|
-
force: true,
|
|
83
|
-
recursive: true
|
|
84
|
-
});
|
|
85
|
-
await mkdir(dirname(targetDir), { recursive: true });
|
|
86
|
-
await cp(packageDir, targetDir, {
|
|
87
|
-
dereference: true,
|
|
88
|
-
filter: (source) => !relative(packageDir, source).split(sep).includes("node_modules"),
|
|
89
|
-
recursive: true
|
|
90
|
-
});
|
|
91
|
-
const packageJson = parsePackageJson(JSON.parse(await readFile(packageJsonPath, "utf8")), packageJsonPath);
|
|
92
|
-
const dependencies = packageJson.dependencies === void 0 ? {} : parsePackageJson(packageJson.dependencies, `${packageJsonPath} dependencies`);
|
|
93
|
-
for (const dependency of Object.keys(dependencies)) await copyPackageDirectory(dependency, packageJsonPath, outputNodeModules, copied, selected, false, join(targetDir, "node_modules"));
|
|
94
|
-
}
|
|
95
|
-
async function resolvePackageJson(name, fromDir) {
|
|
96
|
-
let current = await realpath(fromDir).catch(() => fromDir);
|
|
97
|
-
while (current !== dirname(current)) {
|
|
98
|
-
const candidate = join(current, "node_modules", ...name.split("/"), "package.json");
|
|
99
|
-
try {
|
|
100
|
-
await access(candidate);
|
|
101
|
-
return candidate;
|
|
102
|
-
} catch (error) {
|
|
103
|
-
if (error.code !== "ENOENT") throw error;
|
|
104
|
-
}
|
|
105
|
-
current = dirname(current);
|
|
106
|
-
}
|
|
107
|
-
const error = /* @__PURE__ */ new Error(`Could not resolve package.json for ${name}.`);
|
|
108
|
-
error.code = "ENOENT";
|
|
109
|
-
throw error;
|
|
110
|
-
}
|
|
111
|
-
function parsePackageJson(value, path) {
|
|
112
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error(`Expected ${path} to contain a JSON object.`);
|
|
113
|
-
return value;
|
|
114
|
-
}
|
|
115
|
-
//#endregion
|
|
116
|
-
export { copyVercelFunctionRuntimePackageDirectories };
|