@vite-hub/queue 0.0.0 → 0.0.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 +53 -1
- package/dist/_app-Bx4e5L33.d.ts +11 -0
- package/dist/app-BFpA3j89.js +10 -0
- package/dist/cloudflare-CTdH2u_E.js +107 -0
- package/dist/cloudflare-D5dVqiNw.js +29 -0
- package/dist/cloudflare-env-CJ6g1-Qb.js +49 -0
- package/dist/cloudflare-shared-Ce61GXcn.js +14 -0
- package/dist/cloudflare-vite-Bs67_E_Y.js +66 -0
- package/dist/cloudflare-vite-CRx2CsH9.d.ts +23 -0
- package/dist/config-CIDUZkmH.js +29 -0
- package/dist/errors-xRt0BFZK.js +57 -0
- package/dist/hosted-Dw9WiPNH.js +136 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +17 -0
- package/dist/module-Cr8pH2J_.js +610 -0
- package/dist/nitro.d.ts +32 -0
- package/dist/nitro.js +2 -0
- package/dist/runtime/cloudflare-vite.d.ts +2 -0
- package/dist/runtime/cloudflare-vite.js +2 -0
- package/dist/runtime/hosted.d.ts +11 -0
- package/dist/runtime/hosted.js +2 -0
- package/dist/runtime/nitro-plugin.d.ts +6 -0
- package/dist/runtime/nitro-plugin.js +40 -0
- package/dist/runtime/state.d.ts +13 -0
- package/dist/runtime/state.js +41 -0
- package/dist/runtime/vercel-vite.d.ts +13 -0
- package/dist/runtime/vercel-vite.js +48 -0
- package/dist/types-CBsyjWye.d.ts +167 -0
- package/dist/vercel-BGm0G00p.js +8 -0
- package/dist/vercel-D31zfxiW.js +98 -0
- package/dist/virtual.d.ts +4 -0
- package/dist/vite.d.ts +45 -0
- package/dist/vite.js +492 -0
- package/package.json +77 -5
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { n as createCloudflareQueueBatchHandler } from "../cloudflare-CTdH2u_E.js";
|
|
2
|
+
import { n as getCloudflareQueueDefinitionName } from "../cloudflare-D5dVqiNw.js";
|
|
3
|
+
import { i as setActiveCloudflareEnv, t as createCloudflareRuntimeEvent } from "../cloudflare-env-CJ6g1-Qb.js";
|
|
4
|
+
import { enterQueueRuntimeEvent, loadQueueDefinition, runWithQueueRuntimeEvent, setQueueRuntimeConfig, setQueueRuntimeRegistry } from "./state.js";
|
|
5
|
+
import { t as createQueueJob } from "../cloudflare-shared-Ce61GXcn.js";
|
|
6
|
+
import { definePlugin } from "nitro";
|
|
7
|
+
import { useRuntimeConfig } from "nitro/runtime-config";
|
|
8
|
+
import queueRegistry from "#vitehub/queue/registry";
|
|
9
|
+
//#region src/runtime/nitro-plugin.ts
|
|
10
|
+
const queueNitroPlugin = definePlugin((nitroApp) => {
|
|
11
|
+
const runtimeConfig = useRuntimeConfig();
|
|
12
|
+
const applyRuntimeState = () => {
|
|
13
|
+
setQueueRuntimeConfig(runtimeConfig.queue);
|
|
14
|
+
setQueueRuntimeRegistry(queueRegistry);
|
|
15
|
+
};
|
|
16
|
+
applyRuntimeState();
|
|
17
|
+
nitroApp.hooks.hook("request", (event) => {
|
|
18
|
+
applyRuntimeState();
|
|
19
|
+
enterQueueRuntimeEvent(event);
|
|
20
|
+
});
|
|
21
|
+
nitroApp.hooks.hook("cloudflare:queue", async ({ batch, env, context }) => {
|
|
22
|
+
applyRuntimeState();
|
|
23
|
+
if (runtimeConfig.queue === false || runtimeConfig.queue?.provider !== "cloudflare") return;
|
|
24
|
+
setActiveCloudflareEnv(env);
|
|
25
|
+
const definition = await loadQueueDefinition(getCloudflareQueueDefinitionName(batch.queue));
|
|
26
|
+
if (!definition) return;
|
|
27
|
+
const runtimeEvent = createCloudflareRuntimeEvent(env, context);
|
|
28
|
+
await createCloudflareQueueBatchHandler({
|
|
29
|
+
concurrency: definition.options?.concurrency,
|
|
30
|
+
onError: definition.options?.onError,
|
|
31
|
+
onMessage: async (message, currentBatch) => {
|
|
32
|
+
await runWithQueueRuntimeEvent(runtimeEvent, async () => {
|
|
33
|
+
await definition.handler(createQueueJob(message, currentBatch));
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
})(batch);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
//#endregion
|
|
40
|
+
export { queueNitroPlugin as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { l as QueueDefinitionRegistry, s as QueueDefinition, y as ResolvedQueueOptions } from "../types-CBsyjWye.js";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/state.d.ts
|
|
4
|
+
declare function setQueueRuntimeConfig(config: false | ResolvedQueueOptions | undefined): void;
|
|
5
|
+
declare function getQueueRuntimeConfig(): false | ResolvedQueueOptions | undefined;
|
|
6
|
+
declare function runWithQueueRuntimeEvent<T>(event: unknown, callback: () => T): T;
|
|
7
|
+
declare function enterQueueRuntimeEvent(event: unknown): void;
|
|
8
|
+
declare function getQueueRuntimeEvent(): unknown;
|
|
9
|
+
declare function setQueueRuntimeRegistry(registry: QueueDefinitionRegistry | undefined): void;
|
|
10
|
+
declare function getQueueClientCache(): Map<string, Promise<unknown>>;
|
|
11
|
+
declare function loadQueueDefinition(name: string): Promise<QueueDefinition | undefined>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { enterQueueRuntimeEvent, getQueueClientCache, getQueueRuntimeConfig, getQueueRuntimeEvent, loadQueueDefinition, runWithQueueRuntimeEvent, setQueueRuntimeConfig, setQueueRuntimeRegistry };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
//#region src/runtime/state.ts
|
|
3
|
+
let runtimeConfig;
|
|
4
|
+
let registryOverride;
|
|
5
|
+
const queueEventStorage = new AsyncLocalStorage();
|
|
6
|
+
const queueClientCache = /* @__PURE__ */ new Map();
|
|
7
|
+
function setQueueRuntimeConfig(config) {
|
|
8
|
+
runtimeConfig = config;
|
|
9
|
+
queueClientCache.clear();
|
|
10
|
+
}
|
|
11
|
+
function getQueueRuntimeConfig() {
|
|
12
|
+
return runtimeConfig;
|
|
13
|
+
}
|
|
14
|
+
function runWithQueueRuntimeEvent(event, callback) {
|
|
15
|
+
return queueEventStorage.run(event, callback);
|
|
16
|
+
}
|
|
17
|
+
function enterQueueRuntimeEvent(event) {
|
|
18
|
+
queueEventStorage.enterWith(event);
|
|
19
|
+
}
|
|
20
|
+
function getQueueRuntimeEvent() {
|
|
21
|
+
return queueEventStorage.getStore();
|
|
22
|
+
}
|
|
23
|
+
function setQueueRuntimeRegistry(registry) {
|
|
24
|
+
registryOverride = registry;
|
|
25
|
+
queueClientCache.clear();
|
|
26
|
+
}
|
|
27
|
+
function getQueueClientCache() {
|
|
28
|
+
return queueClientCache;
|
|
29
|
+
}
|
|
30
|
+
function isQueueDefinition(value) {
|
|
31
|
+
return Boolean(value) && typeof value === "object" && typeof value.handler === "function";
|
|
32
|
+
}
|
|
33
|
+
async function loadQueueDefinition(name) {
|
|
34
|
+
const entry = registryOverride?.[name];
|
|
35
|
+
if (!entry) return;
|
|
36
|
+
const loaded = await entry();
|
|
37
|
+
if (isQueueDefinition(loaded)) return loaded;
|
|
38
|
+
if (loaded && typeof loaded === "object" && "default" in loaded && isQueueDefinition(loaded.default)) return loaded.default;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { enterQueueRuntimeEvent, getQueueClientCache, getQueueRuntimeConfig, getQueueRuntimeEvent, loadQueueDefinition, runWithQueueRuntimeEvent, setQueueRuntimeConfig, setQueueRuntimeRegistry };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { l as QueueDefinitionRegistry, y as ResolvedQueueOptions } from "../types-CBsyjWye.js";
|
|
2
|
+
import { t as QueueApp } from "../_app-Bx4e5L33.js";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/vercel-vite.d.ts
|
|
5
|
+
interface QueueVercelServerOptions {
|
|
6
|
+
app?: QueueApp;
|
|
7
|
+
queue?: false | ResolvedQueueOptions;
|
|
8
|
+
registry?: QueueDefinitionRegistry;
|
|
9
|
+
}
|
|
10
|
+
type QueueVercelServer = (req: unknown, res: unknown) => unknown;
|
|
11
|
+
declare function createQueueVercelServer(options?: QueueVercelServerOptions): QueueVercelServer;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { QueueVercelServer, createQueueVercelServer };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { runWithQueueRuntimeEvent, setQueueRuntimeConfig, setQueueRuntimeRegistry } from "./state.js";
|
|
2
|
+
import { t as resolveAppFetch } from "../app-BFpA3j89.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/runtime/vercel-vite.ts
|
|
32
|
+
function createQueueVercelServer(options = {}) {
|
|
33
|
+
return createVercelHostedServer({
|
|
34
|
+
app: options.app,
|
|
35
|
+
label: "queue",
|
|
36
|
+
onRequest({ handle, req, res }) {
|
|
37
|
+
setQueueRuntimeConfig(options.queue);
|
|
38
|
+
setQueueRuntimeRegistry(options.registry);
|
|
39
|
+
return runWithQueueRuntimeEvent({
|
|
40
|
+
req,
|
|
41
|
+
res,
|
|
42
|
+
waitUntil
|
|
43
|
+
}, handle);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { createQueueVercelServer };
|
|
@@ -0,0 +1,167 @@
|
|
|
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
|
+
provider: "cloudflare";
|
|
79
|
+
}
|
|
80
|
+
interface VercelQueueProviderOptions extends QueueSharedOptions {
|
|
81
|
+
client?: VercelQueueSDK;
|
|
82
|
+
provider: "vercel";
|
|
83
|
+
region?: string;
|
|
84
|
+
topic?: string;
|
|
85
|
+
}
|
|
86
|
+
interface VercelQueueModuleProviderOptions extends QueueSharedOptions {
|
|
87
|
+
provider: "vercel";
|
|
88
|
+
region?: string;
|
|
89
|
+
}
|
|
90
|
+
type QueueProviderOptions = CloudflareQueueProviderOptions | VercelQueueProviderOptions;
|
|
91
|
+
type QueueModuleProviderOptions = CloudflareQueueModuleProviderOptions | VercelQueueModuleProviderOptions;
|
|
92
|
+
type QueueModuleOptions = false | (QueueSharedOptions & {
|
|
93
|
+
provider?: undefined;
|
|
94
|
+
}) | QueueModuleProviderOptions;
|
|
95
|
+
type ResolvedQueueOptions = QueueModuleProviderOptions;
|
|
96
|
+
interface QueueJob<TPayload = unknown> {
|
|
97
|
+
attempts: number;
|
|
98
|
+
id: string;
|
|
99
|
+
metadata?: unknown;
|
|
100
|
+
payload: TPayload;
|
|
101
|
+
}
|
|
102
|
+
type QueueHandler<TPayload = unknown, TResult = unknown> = (job: QueueJob<TPayload>) => TResult;
|
|
103
|
+
interface QueueDefinitionOptions {
|
|
104
|
+
cache?: boolean;
|
|
105
|
+
callbackOptions?: VercelQueueCallbackOptions;
|
|
106
|
+
concurrency?: number;
|
|
107
|
+
onDispatchError?: (error: unknown, context: {
|
|
108
|
+
name: string;
|
|
109
|
+
}) => unknown | Promise<unknown>;
|
|
110
|
+
onError?: CloudflareQueueBatchHandlerOptions["onError"];
|
|
111
|
+
}
|
|
112
|
+
interface QueueDefinition<TPayload = unknown, TResult = unknown> {
|
|
113
|
+
handler: QueueHandler<TPayload, TResult>;
|
|
114
|
+
options?: QueueDefinitionOptions;
|
|
115
|
+
}
|
|
116
|
+
interface QueueEnqueueOptions {
|
|
117
|
+
contentType?: CloudflareQueueContentType;
|
|
118
|
+
delaySeconds?: number;
|
|
119
|
+
idempotencyKey?: string;
|
|
120
|
+
region?: string;
|
|
121
|
+
retentionSeconds?: number;
|
|
122
|
+
}
|
|
123
|
+
type QueueEnqueueEnvelope<TPayload = unknown> = {
|
|
124
|
+
payload: TPayload;
|
|
125
|
+
contentType?: CloudflareQueueContentType;
|
|
126
|
+
delaySeconds?: number;
|
|
127
|
+
id?: string;
|
|
128
|
+
idempotencyKey?: string;
|
|
129
|
+
region?: string;
|
|
130
|
+
retentionSeconds?: number;
|
|
131
|
+
};
|
|
132
|
+
type QueueEnqueueInput<TPayload = unknown> = TPayload | QueueEnqueueEnvelope<TPayload>;
|
|
133
|
+
type QueueSendResult = {
|
|
134
|
+
messageId?: string;
|
|
135
|
+
status: "queued";
|
|
136
|
+
};
|
|
137
|
+
interface QueueClientBase<P extends QueueProvider = QueueProvider> {
|
|
138
|
+
readonly native: unknown;
|
|
139
|
+
readonly provider: P;
|
|
140
|
+
send: <TPayload = unknown>(input: QueueEnqueueInput<TPayload>) => Promise<QueueSendResult>;
|
|
141
|
+
}
|
|
142
|
+
interface CloudflareQueueClient extends QueueClientBase<"cloudflare"> {
|
|
143
|
+
readonly binding: CloudflareQueueBinding;
|
|
144
|
+
createBatchHandler: <TPayload = unknown>(options: CloudflareQueueBatchHandlerOptions<TPayload>) => (batch: CloudflareQueueMessageBatch<TPayload>) => Promise<void>;
|
|
145
|
+
sendBatch: (items: CloudflareQueueSendBatchMessage[], options?: QueueEnqueueOptions) => Promise<QueueSendResult[]>;
|
|
146
|
+
}
|
|
147
|
+
interface VercelQueueClient extends QueueClientBase<"vercel"> {
|
|
148
|
+
readonly topic: string;
|
|
149
|
+
callback: <TPayload = unknown>(handler: VercelQueueMessageHandler<TPayload>, options?: VercelQueueCallbackOptions) => VercelQueueCallbackReturn;
|
|
150
|
+
}
|
|
151
|
+
interface QueueClientMap {
|
|
152
|
+
cloudflare: CloudflareQueueClient;
|
|
153
|
+
vercel: VercelQueueClient;
|
|
154
|
+
}
|
|
155
|
+
type QueueClient<P extends QueueProvider = QueueProvider> = QueueClientMap[P];
|
|
156
|
+
interface QueueDefinitionRegistry {
|
|
157
|
+
[name: string]: () => Promise<{
|
|
158
|
+
default?: QueueDefinition;
|
|
159
|
+
} | QueueDefinition>;
|
|
160
|
+
}
|
|
161
|
+
interface DiscoveredQueueDefinition {
|
|
162
|
+
handler: string;
|
|
163
|
+
name: string;
|
|
164
|
+
source?: "nitro-server-queues" | "vite-suffix";
|
|
165
|
+
}
|
|
166
|
+
//#endregion
|
|
167
|
+
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,8 @@
|
|
|
1
|
+
import { i as encodeNameHex } from "./cloudflare-D5dVqiNw.js";
|
|
2
|
+
//#region src/integrations/vercel.ts
|
|
3
|
+
const vercelQueueTopicPrefix = "topic--";
|
|
4
|
+
function getVercelQueueTopicName(name) {
|
|
5
|
+
return `${vercelQueueTopicPrefix}${encodeNameHex(name)}`;
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { getVercelQueueTopicName as t };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { r as normalizeQueueEnqueueInput, t as QueueError } from "./errors-xRt0BFZK.js";
|
|
2
|
+
import { getQueueRuntimeEvent } from "./runtime/state.js";
|
|
3
|
+
//#region src/providers/vercel.ts
|
|
4
|
+
function readHeader(headers, name) {
|
|
5
|
+
if (!headers) return;
|
|
6
|
+
if (headers instanceof Headers) return headers.get(name) || void 0;
|
|
7
|
+
const value = headers[name] ?? headers[name.toLowerCase()];
|
|
8
|
+
if (typeof value === "string") return value;
|
|
9
|
+
if (Array.isArray(value)) return typeof value[0] === "string" ? value[0] : void 0;
|
|
10
|
+
}
|
|
11
|
+
function parseRegionFromVercelId(value) {
|
|
12
|
+
if (!value) return;
|
|
13
|
+
return value.match(/^([a-z0-9]+)::/i)?.[1]?.toLowerCase();
|
|
14
|
+
}
|
|
15
|
+
function resolveVercelRegion(explicitRegion) {
|
|
16
|
+
if (explicitRegion) return explicitRegion;
|
|
17
|
+
if (typeof process.env.QUEUE_REGION === "string" && process.env.QUEUE_REGION) return process.env.QUEUE_REGION;
|
|
18
|
+
if (typeof process.env.VERCEL_REGION === "string" && process.env.VERCEL_REGION) return process.env.VERCEL_REGION;
|
|
19
|
+
const event = getQueueRuntimeEvent();
|
|
20
|
+
const requestHeaders = event?.request instanceof Request ? event.request.headers : event?.req?.headers;
|
|
21
|
+
return readHeader(requestHeaders, "ce-vqsregion") || parseRegionFromVercelId(readHeader(requestHeaders, "x-vercel-id"));
|
|
22
|
+
}
|
|
23
|
+
async function loadVercelQueueClient(region) {
|
|
24
|
+
let module;
|
|
25
|
+
try {
|
|
26
|
+
const loaded = globalThis.__vitehubVercelQueue;
|
|
27
|
+
if (loaded && typeof loaded === "object") module = loaded;
|
|
28
|
+
else {
|
|
29
|
+
const importVercelQueue = new Function("specifier", "return import(specifier)");
|
|
30
|
+
const specifier = "@vercel/queue";
|
|
31
|
+
try {
|
|
32
|
+
module = await importVercelQueue(specifier);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (!(error instanceof TypeError) || !/dynamic import callback/i.test(error.message)) throw error;
|
|
35
|
+
module = await import(specifier);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} catch (error) {
|
|
39
|
+
throw new QueueError(`@vercel/queue load failed. Install it to use the Vercel provider. Original error: ${error instanceof Error ? error.message : error}`, {
|
|
40
|
+
cause: error,
|
|
41
|
+
code: "VERCEL_QUEUE_SDK_LOAD_FAILED",
|
|
42
|
+
provider: "vercel"
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const resolvedRegion = resolveVercelRegion(region);
|
|
46
|
+
if ("QueueClient" in module && typeof module.QueueClient === "function") {
|
|
47
|
+
if (!resolvedRegion) throw new QueueError("Vercel queue region could not be resolved. Set `queue.region`, `QUEUE_REGION`, or run inside a Vercel request context.", {
|
|
48
|
+
code: "VERCEL_QUEUE_REGION_REQUIRED",
|
|
49
|
+
httpStatus: 500,
|
|
50
|
+
provider: "vercel"
|
|
51
|
+
});
|
|
52
|
+
return new module.QueueClient({ region: resolvedRegion });
|
|
53
|
+
}
|
|
54
|
+
if (typeof module.send === "function" && typeof module.handleCallback === "function") return {
|
|
55
|
+
handleCallback: module.handleCallback,
|
|
56
|
+
send: module.send
|
|
57
|
+
};
|
|
58
|
+
throw new QueueError("@vercel/queue does not expose the expected queue client API.", {
|
|
59
|
+
code: "VERCEL_QUEUE_SDK_INVALID",
|
|
60
|
+
provider: "vercel"
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async function createVercelQueueClient(provider) {
|
|
64
|
+
const topic = provider.topic;
|
|
65
|
+
if (!topic) throw new QueueError("Vercel queue topics are derived from discovered queue names. Direct clients require a topic.", {
|
|
66
|
+
code: "VERCEL_TOPIC_RESOLUTION_REQUIRED",
|
|
67
|
+
httpStatus: 400,
|
|
68
|
+
provider: "vercel"
|
|
69
|
+
});
|
|
70
|
+
const client = provider.client || await loadVercelQueueClient(provider.region);
|
|
71
|
+
return {
|
|
72
|
+
provider: "vercel",
|
|
73
|
+
native: client,
|
|
74
|
+
topic,
|
|
75
|
+
async send(input) {
|
|
76
|
+
const normalized = normalizeQueueEnqueueInput(input);
|
|
77
|
+
if (normalized.options.contentType !== void 0) throw new QueueError("Vercel queue does not support enqueue options: contentType.", {
|
|
78
|
+
code: "VERCEL_UNSUPPORTED_ENQUEUE_OPTIONS",
|
|
79
|
+
details: { unsupported: ["contentType"] },
|
|
80
|
+
httpStatus: 400,
|
|
81
|
+
method: "send",
|
|
82
|
+
provider: "vercel"
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
status: "queued",
|
|
86
|
+
messageId: (await client.send(topic, normalized.payload, {
|
|
87
|
+
delaySeconds: normalized.options.delaySeconds,
|
|
88
|
+
idempotencyKey: normalized.options.idempotencyKey || normalized.id,
|
|
89
|
+
region: normalized.options.region ?? provider.region,
|
|
90
|
+
retentionSeconds: normalized.options.retentionSeconds
|
|
91
|
+
})).messageId ?? void 0
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
callback: client.handleCallback.bind(client)
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
export { createVercelQueueClient };
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { m as QueueModuleOptions } from "./types-CBsyjWye.js";
|
|
2
|
+
import { NitroModule } from "nitro/types";
|
|
3
|
+
import { Plugin } from "vite";
|
|
4
|
+
|
|
5
|
+
//#region src/internal/vite-build.d.ts
|
|
6
|
+
interface CloudflareQueueConfigOptions {
|
|
7
|
+
compatibilityDate?: string;
|
|
8
|
+
rootDir?: string;
|
|
9
|
+
}
|
|
10
|
+
interface CloudflareQueueConfig {
|
|
11
|
+
assets?: {
|
|
12
|
+
directory?: string;
|
|
13
|
+
run_worker_first: string[];
|
|
14
|
+
};
|
|
15
|
+
compatibility_date: string;
|
|
16
|
+
compatibility_flags: string[];
|
|
17
|
+
main: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
observability: {
|
|
20
|
+
enabled: true;
|
|
21
|
+
};
|
|
22
|
+
queues?: {
|
|
23
|
+
consumers: Array<{
|
|
24
|
+
queue: string;
|
|
25
|
+
}>;
|
|
26
|
+
producers: Array<{
|
|
27
|
+
binding: string;
|
|
28
|
+
queue: string;
|
|
29
|
+
}>;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
declare function createCloudflareQueueConfig(options?: CloudflareQueueConfigOptions): Promise<CloudflareQueueConfig>;
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/vite.d.ts
|
|
35
|
+
type QueueVitePlugin = Plugin & {
|
|
36
|
+
nitro: NitroModule;
|
|
37
|
+
};
|
|
38
|
+
declare function hubQueue(options?: QueueModuleOptions): QueueVitePlugin;
|
|
39
|
+
declare module "vite" {
|
|
40
|
+
interface UserConfig {
|
|
41
|
+
queue?: QueueModuleOptions;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { type CloudflareQueueConfig, type CloudflareQueueConfigOptions, QueueVitePlugin, createCloudflareQueueConfig, hubQueue };
|