@vite-hub/queue 0.0.4 → 0.1.0

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.
Files changed (51) hide show
  1. package/README.md +41 -23
  2. package/dist/client-CIc3jsj2.js +114 -0
  3. package/dist/cloudflare-client-COzQ8fHk.js +147 -0
  4. package/dist/{cloudflare-resource-name-R8zYQiZb.js → cloudflare-resource-name-CCuLDvSP.js} +3 -2
  5. package/dist/{cloudflare-vite-BlQfDVZD.js → cloudflare-vite-BCuJOXcT.js} +23 -9
  6. package/dist/{cloudflare-vite-nFPor46-.d.ts → cloudflare-vite-CjdP5yBN.d.ts} +9 -4
  7. package/dist/config-BINujLv4.js +74 -0
  8. package/dist/enqueue-CnQ0QR3O.js +22 -0
  9. package/dist/error-diagnostics-A_8Kp-48.js +116 -0
  10. package/dist/error-diagnostics-qzRF6IVB.js +109 -0
  11. package/dist/errors-DIFaM9tW.js +42 -0
  12. package/dist/handler-response-CBwIkmTS.js +56 -0
  13. package/dist/index.d.ts +32 -70
  14. package/dist/index.js +9 -8
  15. package/dist/inspect-PeuckaC3.js +30 -0
  16. package/dist/internal/runtime/cloudflare-client.d.ts +3 -5
  17. package/dist/internal/runtime/cloudflare-client.js +1 -1
  18. package/dist/internal/runtime/cloudflare-vite.d.ts +1 -1
  19. package/dist/internal/runtime/cloudflare-vite.js +1 -1
  20. package/dist/internal/runtime/state.d.ts +16 -15
  21. package/dist/internal/runtime/state.js +2 -2
  22. package/dist/internal/runtime/vercel-client.d.ts +3 -5
  23. package/dist/internal/runtime/vercel-client.js +93 -62
  24. package/dist/nuxt.d.ts +27 -7
  25. package/dist/nuxt.js +6 -2
  26. package/dist/object-B1NW521B.js +7 -0
  27. package/dist/operations-Cnjbz8kk.js +63 -0
  28. package/dist/operations-tNUdj3G4.d.ts +212 -0
  29. package/dist/operations.d.ts +32 -0
  30. package/dist/operations.js +1195 -0
  31. package/dist/runtime/hosted.d.ts +4 -6
  32. package/dist/runtime/hosted.js +30 -8
  33. package/dist/state-G9s378-e.js +184 -0
  34. package/dist/{types-CwvoMATy.d.ts → types-1GRMYES1.d.ts} +35 -24
  35. package/dist/vercel-region-cjskrOKl.js +122 -0
  36. package/dist/vite-ChWLzOVu.js +1512 -0
  37. package/dist/vite.d.ts +334 -34
  38. package/dist/vite.js +2 -2
  39. package/package.json +68 -25
  40. package/dist/_app-D29AwUdD.d.ts +0 -11
  41. package/dist/app-BZpq2cwC.js +0 -10
  42. package/dist/client-DG9fweET.js +0 -93
  43. package/dist/cloudflare-client-w5vphoNn.js +0 -99
  44. package/dist/config-CNgAeIND.js +0 -53
  45. package/dist/delivery-error-glgYWC9g.js +0 -45
  46. package/dist/errors-CjuG_qr-.js +0 -108
  47. package/dist/internal/runtime/vercel-vite.d.ts +0 -20
  48. package/dist/internal/runtime/vercel-vite.js +0 -49
  49. package/dist/state-Cno9O7YS.js +0 -110
  50. package/dist/vercel-runtime-package-copy-CEToJtCu.js +0 -116
  51. package/dist/vite-DOuoen0w.js +0 -4414
@@ -1,10 +1,8 @@
1
- import { s as QueueDefinition } from "../types-CwvoMATy.js";
2
-
1
+ import { c as QueueDefinition } from "../types-1GRMYES1.js";
3
2
  //#region src/runtime/hosted.d.ts
4
- declare const hostedVercelWaitUntil: (promise: Promise<unknown>) => void | undefined;
5
- declare function handleHostedVercelQueueCallback(event: {
3
+ export declare const hostedVercelWaitUntil: (promise: Promise<unknown>) => void | undefined;
4
+ export declare function handleHostedVercelQueueCallback(event: {
6
5
  method?: string;
7
6
  request?: Request;
8
7
  }, name: string, definition: QueueDefinition): Promise<unknown>;
9
- //#endregion
10
- export { handleHostedVercelQueueCallback, hostedVercelWaitUntil };
8
+ //#endregion
@@ -1,12 +1,31 @@
1
- import { n as createQueueError } from "../errors-CjuG_qr-.js";
2
- import { n as reportQueueDeliveryError, t as isNonRetryableQueueError } from "../delivery-error-glgYWC9g.js";
3
- import { n as getQueue } from "../client-DG9fweET.js";
1
+ import { t as queueErrorDiagnostics } from "../error-diagnostics-qzRF6IVB.js";
2
+ import { n as isNonRetryableQueueError, r as reportQueueDeliveryError, t as checkQueueHandlerResponse } from "../handler-response-CBwIkmTS.js";
3
+ import { n as dynamicQueue } from "../client-CIc3jsj2.js";
4
4
  import { waitUntil } from "@vercel/functions";
5
+ import { Request as Request$1 } from "undici";
5
6
  import { getRequestHeaders, getRequestURL, readRawBody } from "h3";
6
7
  //#region src/runtime/hosted.ts
7
8
  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
+ }
8
20
  async function toRequest(event) {
9
- if (event.request instanceof Request) return event.request;
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;
10
29
  const h3Event = event;
11
30
  const body = await readRawBody(h3Event);
12
31
  return new Request(getRequestURL(h3Event), {
@@ -18,12 +37,12 @@ async function toRequest(event) {
18
37
  function createVercelJobHandler(definition) {
19
38
  return async (payload, metadata) => {
20
39
  const meta = metadata;
21
- await definition.handler({
40
+ checkQueueHandlerResponse(await definition.handler({
22
41
  attempts: typeof meta?.deliveryCount === "number" ? meta.deliveryCount : 1,
23
42
  id: typeof meta?.messageId === "string" ? meta.messageId : "vercel-message",
24
43
  metadata,
25
44
  payload
26
- });
45
+ }));
27
46
  };
28
47
  }
29
48
  function createVercelCallbackOptions(name, options) {
@@ -45,8 +64,11 @@ function createVercelCallbackOptions(name, options) {
45
64
  };
46
65
  }
47
66
  async function handleHostedVercelQueueCallback(event, name, definition) {
48
- const queue = await getQueue(name);
49
- if (queue.provider !== "vercel") throw createQueueError("VERCEL_PROVIDER_EXPECTED", { details: { provider: queue.provider } });
67
+ const queue = await dynamicQueue.get(name);
68
+ if (queue.provider !== "vercel") throw queueErrorDiagnostics.QUEUE_PROVIDER_MISMATCH({
69
+ expected: "vercel",
70
+ provider: queue.provider
71
+ });
50
72
  return await queue.callback(createVercelJobHandler(definition), createVercelCallbackOptions(name, definition.options?.callbackOptions))(await toRequest(event));
51
73
  }
52
74
  //#endregion
@@ -0,0 +1,184 @@
1
+ import { t as isPlainObject } from "./object-B1NW521B.js";
2
+ import { t as queueErrorDiagnostics } from "./error-diagnostics-qzRF6IVB.js";
3
+ import { AsyncLocalStorage } from "node:async_hooks";
4
+ import { hasRuntimeType } from "@vite-hub/runtime/internal/runtime-type";
5
+ //#region ../internal/src/runtime/cloudflare-env.ts
6
+ let activeEnv;
7
+ const activeEnvStorageKey = Symbol.for("vitehub.cloudflare.env-storage");
8
+ const runtimeGlobal = globalThis;
9
+ const activeEnvStorage = runtimeGlobal[activeEnvStorageKey] ||= new AsyncLocalStorage();
10
+ const globalEnvProbe = Symbol("vitehub.cloudflare.global-env-probe");
11
+ /**
12
+ * Under the Nitro Cloudflare dev server, `cloudflare:workers` exports unenv's env proxy, which reads every key from
13
+ * `globalThis.__env__`. Storing that proxy in `__env__` makes it read itself, and the next read overflows the stack.
14
+ */
15
+ function readsGlobalEnv(env) {
16
+ const scope = globalThis;
17
+ const owned = Object.hasOwn(scope, "__env__");
18
+ const previous = scope.__env__;
19
+ scope.__env__ = { [globalEnvProbe]: true };
20
+ try {
21
+ return Reflect.get(env, globalEnvProbe) === true;
22
+ } catch {
23
+ return false;
24
+ } finally {
25
+ if (owned) scope.__env__ = previous;
26
+ else delete scope.__env__;
27
+ }
28
+ }
29
+ function setActiveCloudflareEnv(env) {
30
+ activeEnv = env;
31
+ if (!env || !readsGlobalEnv(env)) globalThis.__env__ = env;
32
+ try {
33
+ activeEnvStorage.enterWith({ env });
34
+ } catch {}
35
+ }
36
+ function runWithActiveCloudflareEnv(env, callback) {
37
+ return activeEnvStorage.run({ env }, callback);
38
+ }
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
+ function resolveWaitUntil(event, options = {}) {
71
+ const target = ownObject(event);
72
+ const context = ownObject(ownValue(target, "context"));
73
+ const cloudflare = ownObject(ownValue(context, "cloudflare"));
74
+ const cloudflareContext = ownObject(ownValue(cloudflare, "context"));
75
+ const platformCloudflare = ownObject(ownValue(ownObject(ownValue(context, "_platform")), "cloudflare"));
76
+ const platformCloudflareContext = ownObject(ownValue(platformCloudflare, "context"));
77
+ const req = ownObject(ownValue(target, "req"));
78
+ 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
+ const hosts = [
83
+ context,
84
+ cloudflare,
85
+ cloudflareContext,
86
+ platformCloudflare,
87
+ platformCloudflareContext,
88
+ req,
89
+ reqCloudflare,
90
+ reqCloudflareContext,
91
+ nodeReq,
92
+ nodeCloudflare,
93
+ ownObject(ownValue(nodeCloudflare, "context"))
94
+ ];
95
+ const owners = options.preferHost ? [...hosts, target] : [target, ...hosts];
96
+ for (const owner of owners) {
97
+ const waitUntil = ownValue(owner, "waitUntil");
98
+ if (typeof waitUntil === "function") return waitUntil.bind(owner);
99
+ }
100
+ }
101
+ function createCloudflareRuntimeEvent(env, context) {
102
+ const waitUntil = typeof context?.waitUntil === "function" ? context.waitUntil.bind(context) : void 0;
103
+ return {
104
+ context: {
105
+ cloudflare: {
106
+ env,
107
+ context
108
+ },
109
+ waitUntil
110
+ },
111
+ env,
112
+ waitUntil
113
+ };
114
+ }
115
+ //#endregion
116
+ //#region src/internal/runtime/state.ts
117
+ let runtimeConfig;
118
+ let runtimeClientFactory;
119
+ let registryOverride;
120
+ const queueEventStorage = new AsyncLocalStorage();
121
+ let queueEventDefaults;
122
+ const queueClientCache = /* @__PURE__ */ new Map();
123
+ function missingQueueDefinitionError(queue) {
124
+ return queueErrorDiagnostics.QUEUE_DEFINITION_NOT_FOUND({ queue });
125
+ }
126
+ function setQueueRuntimeConfig(config, createClient) {
127
+ runtimeConfig = config;
128
+ runtimeClientFactory = createClient;
129
+ if (typeof config === "undefined") queueEventDefaults = void 0;
130
+ queueClientCache.clear();
131
+ }
132
+ function getQueueRuntimeConfig() {
133
+ return runtimeConfig;
134
+ }
135
+ function getQueueRuntimeClientFactory() {
136
+ return runtimeClientFactory;
137
+ }
138
+ function runWithQueueRuntimeEvent(event, callback) {
139
+ return queueEventStorage.run(event, callback);
140
+ }
141
+ function enterQueueRuntimeEvent(event) {
142
+ try {
143
+ queueEventStorage.enterWith(event);
144
+ } catch {}
145
+ setActiveCloudflareEnv(event && typeof event === "object" && Object.hasOwn(event, "env") ? event.env : getCloudflareEnv(event));
146
+ }
147
+ function getQueueRuntimeEvent() {
148
+ return queueEventStorage.getStore() ?? queueEventDefaults;
149
+ }
150
+ function setQueueRuntimeEventDefaults(event) {
151
+ queueEventDefaults = event;
152
+ }
153
+ function setQueueRuntimeRegistry(registry) {
154
+ registryOverride = registry;
155
+ queueClientCache.clear();
156
+ }
157
+ /** The names of the Queue Definitions that this runtime loads, sorted. */
158
+ function listQueueDefinitionNames() {
159
+ return registryOverride ? Object.keys(registryOverride).sort() : [];
160
+ }
161
+ function getOrCreateQueueClient(name, createClient) {
162
+ const existing = queueClientCache.get(name);
163
+ if (existing) return existing;
164
+ const pending = createClient().catch((error) => {
165
+ if (queueClientCache.get(name) === pending) queueClientCache.delete(name);
166
+ throw error;
167
+ });
168
+ queueClientCache.set(name, pending);
169
+ return pending;
170
+ }
171
+ function isQueueDefinition(value) {
172
+ return isPlainObject(value) && Object.hasOwn(value, "handler") && hasRuntimeType(value.handler, "function");
173
+ }
174
+ async function loadQueueDefinition(name) {
175
+ const registry = registryOverride;
176
+ if (!registry || !Object.hasOwn(registry, name)) return void 0;
177
+ const entry = registry[name];
178
+ if (!entry) return;
179
+ const loaded = await entry();
180
+ if (isQueueDefinition(loaded)) return loaded;
181
+ if (isPlainObject(loaded) && Object.hasOwn(loaded, "default") && isQueueDefinition(loaded.default)) return loaded.default;
182
+ }
183
+ //#endregion
184
+ export { getQueueRuntimeEvent as a, missingQueueDefinitionError as c, setQueueRuntimeEventDefaults as d, setQueueRuntimeRegistry as f, runWithActiveCloudflareEnv as g, resolveWaitUntil as h, getQueueRuntimeConfig as i, runWithQueueRuntimeEvent as l, getCloudflareEnv as m, getOrCreateQueueClient as n, listQueueDefinitionNames as o, createCloudflareRuntimeEvent as p, getQueueRuntimeClientFactory as r, loadQueueDefinition as s, enterQueueRuntimeEvent as t, setQueueRuntimeConfig as u };
@@ -1,3 +1,4 @@
1
+ import { Result } from "@vite-hub/runtime";
1
2
  //#region src/types.d.ts
2
3
  type QueueProvider = "cloudflare" | "vercel";
3
4
  type CloudflareQueueContentType = "bytes" | "json" | "text" | "v8";
@@ -116,45 +117,55 @@ interface QueueDefinition<TPayload = unknown, TResult = unknown> {
116
117
  options?: QueueDefinitionOptions;
117
118
  }
118
119
  interface QueueEnqueueOptions {
120
+ id?: string;
119
121
  contentType?: CloudflareQueueContentType;
120
122
  delaySeconds?: number;
121
123
  idempotencyKey?: string;
122
124
  region?: string;
123
125
  retentionSeconds?: number;
124
126
  }
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
127
  type QueueSendResult = {
136
128
  messageId?: string;
137
129
  status: "queued";
138
130
  };
131
+ /** Codes that Queue operations return in the `[error, data]` tuple. Config errors throw instead. */
132
+ type QueueErrorCode = "QUEUE_PROVIDER_FAILED" | "QUEUE_PROVIDER_INVALID_RESPONSE" | "QUEUE_UNSUPPORTED_OPTION";
133
+ /** Codes that `send()` and `sendBatch()` of a Cloudflare QueueClient return. */
134
+ type CloudflareQueueErrorCode = "QUEUE_PROVIDER_FAILED" | "QUEUE_UNSUPPORTED_OPTION";
135
+ /** Codes that `send()` of a Vercel QueueClient returns. */
136
+ type VercelQueueErrorCode = QueueErrorCode;
139
137
  interface QueueClientBase<P extends QueueProvider = QueueProvider> {
140
138
  readonly native: unknown;
141
139
  readonly provider: P;
142
- send: <TPayload = unknown>(input: QueueEnqueueInput<TPayload>) => Promise<QueueSendResult>;
143
140
  }
144
- interface CloudflareQueueClient extends QueueClientBase<"cloudflare"> {
141
+ /**
142
+ * `send()` and `sendBatch()` return `[error, data]`. `error.code` is one of the codes in the method type.
143
+ */
144
+ interface CloudflareQueueClient<TPayload = unknown> extends QueueClientBase<"cloudflare"> {
145
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"> {
146
+ createBatchHandler: <TMessage = unknown>(options: CloudflareQueueBatchHandlerOptions<TMessage>) => (batch: CloudflareQueueMessageBatch<TMessage>) => Promise<void>;
147
+ send: (payload: TPayload, options?: QueueEnqueueOptions) => Promise<Result<QueueSendResult, CloudflareQueueErrorCode>>;
148
+ sendBatch: (items: CloudflareQueueSendBatchMessage<TPayload>[], options?: Omit<QueueEnqueueOptions, "id">) => Promise<Result<QueueSendResult[], CloudflareQueueErrorCode>>;
149
+ }
150
+ /**
151
+ * `send()` returns `[error, data]`. `error.code` is one of the codes in the method type.
152
+ */
153
+ interface VercelQueueClient<TPayload = unknown> extends QueueClientBase<"vercel"> {
150
154
  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];
155
+ send: (payload: TPayload, options?: QueueEnqueueOptions) => Promise<Result<QueueSendResult, VercelQueueErrorCode>>;
156
+ callback: <TMessage = unknown>(handler: VercelQueueMessageHandler<TMessage>, options?: VercelQueueCallbackOptions) => VercelQueueCallbackReturn;
157
+ }
158
+ interface QueueClientMap<TPayload> {
159
+ cloudflare: CloudflareQueueClient<TPayload>;
160
+ vercel: VercelQueueClient<TPayload>;
161
+ }
162
+ type QueueClient<P extends QueueProvider = QueueProvider, TPayload = unknown> = QueueClientMap<TPayload>[P];
163
+ /** Discovered Queue Definitions. Generated declarations extend this interface. */
164
+ interface QueueRegistry {}
165
+ type QueueName = Extract<keyof QueueRegistry, string>;
166
+ type QueuePayload<TName extends QueueName> = QueueRegistry[TName] extends {
167
+ handler: (job: infer TJob) => unknown;
168
+ } ? TJob extends QueueJob<infer TPayload> ? TPayload : never : never;
158
169
  interface QueueDefinitionRegistry {
159
170
  [name: string]: () => Promise<{
160
171
  default?: QueueDefinition;
@@ -166,4 +177,4 @@ interface DiscoveredQueueDefinition {
166
177
  source?: "server-queues" | "vite-suffix";
167
178
  }
168
179
  //#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 };
180
+ export { ResolvedQueueOptions as C, VercelQueueRetryDirective as D, VercelQueueErrorCode as E, VercelQueueRetryHandler as O, QueueSendResult as S, VercelQueueClient as T, QueueName as _, CloudflareQueueMessageBatch as a, QueueProviderOptions as b, QueueDefinition as c, QueueEnqueueOptions as d, QueueErrorCode as f, QueueModuleProviderOptions as g, QueueModuleOptions as h, CloudflareQueueMessage as i, VercelQueueSendResult as k, QueueDefinitionOptions as l, QueueJob as m, CloudflareQueueClient as n, DiscoveredQueueDefinition as o, QueueHandler as p, CloudflareQueueErrorCode as r, QueueClient as s, CloudflareQueueBatchHandlerOptions as t, QueueDefinitionRegistry as u, QueuePayload as v, VercelQueueCallbackOptions as w, QueueRegistry as x, QueueProvider as y };
@@ -0,0 +1,122 @@
1
+ import { a as getQueueRuntimeEvent } from "./state-G9s378-e.js";
2
+ //#region src/internal/vercel-region.ts
3
+ function readHeader(headers, name) {
4
+ if (!headers) return;
5
+ if (isHeadersLike(headers)) try {
6
+ const descriptor = getPrototypeDescriptor(headers, "get");
7
+ if (!descriptor) return;
8
+ if (!isBrandedMethod(descriptor.value, headers, descriptor.owner, void 0, "probe").ok) return;
9
+ const value = descriptor.value.call(headers, name);
10
+ if (value !== descriptor.value.call(headers, name)) return;
11
+ return typeof value === "string" && value ? value : void 0;
12
+ } catch {
13
+ return;
14
+ }
15
+ let value;
16
+ try {
17
+ value = headers[name] ?? headers[name.toLowerCase()];
18
+ } catch {
19
+ return;
20
+ }
21
+ if (typeof value === "string") return value;
22
+ if (Array.isArray(value)) return typeof value[0] === "string" ? value[0] : void 0;
23
+ }
24
+ function isHeadersLike(value) {
25
+ if (!value || typeof value !== "object" && typeof value !== "function") return false;
26
+ try {
27
+ if (Object.prototype.hasOwnProperty.call(value, "get")) return false;
28
+ const descriptor = getPrototypeDescriptor(value, "get");
29
+ if (!descriptor) return false;
30
+ return isBrandedMethod(descriptor.value, value, descriptor.owner, void 0, "probe").ok;
31
+ } catch {
32
+ return false;
33
+ }
34
+ }
35
+ function isBrandedMethod(value, receiver, owner, targetName, mode = "accessor") {
36
+ if (typeof value !== "function") return { ok: false };
37
+ try {
38
+ const source = Function.prototype.toString.call(value);
39
+ if (!source.includes("[native code]") && !source.includes("webidl.brandCheck")) return { ok: false };
40
+ if (!owner || Object.getPrototypeOf(owner) === null) return { ok: false };
41
+ const constructor = Object.getOwnPropertyDescriptor(owner, "constructor")?.value;
42
+ if (typeof constructor !== "function" || constructor.prototype !== owner || constructor.name !== "Headers" && constructor.name !== "Request") return { ok: false };
43
+ if (!(receiver instanceof constructor)) return { ok: false };
44
+ if (mode === "accessor") {
45
+ value.call(receiver);
46
+ return { ok: true };
47
+ }
48
+ const probeName = targetName ?? "x-vitehub-brand-probe";
49
+ const probe = value.call(receiver, probeName);
50
+ if (probe !== null && typeof probe !== "string") return { ok: false };
51
+ return {
52
+ ok: true,
53
+ value: typeof probe === "string" && probe ? probe : void 0
54
+ };
55
+ } catch {
56
+ return { ok: false };
57
+ }
58
+ }
59
+ function getRequestHeaders(value) {
60
+ if (!value || typeof value !== "object" && typeof value !== "function") return void 0;
61
+ try {
62
+ const descriptor = getPrototypeDescriptor(value, "headers");
63
+ if (!descriptor?.get || !isBrandedMethod(descriptor.get, value, descriptor.owner, void 0, "accessor").ok) return void 0;
64
+ const headers = descriptor.get.call(value);
65
+ return isHeadersLike(headers) ? headers : void 0;
66
+ } catch {
67
+ return;
68
+ }
69
+ }
70
+ function getPrototypeDescriptor(value, property) {
71
+ let prototype = value;
72
+ const visited = /* @__PURE__ */ new WeakSet();
73
+ const maxDepth = 1024;
74
+ let depth = 0;
75
+ while (prototype && depth++ < maxDepth) {
76
+ if (visited.has(prototype)) return void 0;
77
+ visited.add(prototype);
78
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, property);
79
+ if (descriptor) return {
80
+ ...descriptor,
81
+ owner: prototype
82
+ };
83
+ prototype = Object.getPrototypeOf(prototype);
84
+ }
85
+ }
86
+ function parseRegionFromVercelId(value) {
87
+ if (!value) return;
88
+ return value.match(/^([a-z0-9]+)::/i)?.[1]?.toLowerCase();
89
+ }
90
+ function resolveVercelQueueRegion(explicitRegion) {
91
+ if (explicitRegion) return {
92
+ region: explicitRegion,
93
+ requestScoped: false
94
+ };
95
+ if (process.env.QUEUE_REGION) return {
96
+ region: process.env.QUEUE_REGION,
97
+ requestScoped: false
98
+ };
99
+ if (process.env.VERCEL_REGION) return {
100
+ region: process.env.VERCEL_REGION,
101
+ requestScoped: false
102
+ };
103
+ const event = getQueueRuntimeEvent();
104
+ let requestHeaders;
105
+ try {
106
+ const request = event?.request;
107
+ requestHeaders = getRequestHeaders(request);
108
+ } catch {
109
+ requestHeaders = void 0;
110
+ }
111
+ if (!requestHeaders) try {
112
+ requestHeaders = event?.req?.headers ?? event?.node?.req?.headers;
113
+ } catch {
114
+ requestHeaders = void 0;
115
+ }
116
+ return {
117
+ region: readHeader(requestHeaders, "ce-vqsregion") || parseRegionFromVercelId(readHeader(requestHeaders, "x-vercel-id")),
118
+ requestScoped: event !== void 0
119
+ };
120
+ }
121
+ //#endregion
122
+ export { resolveVercelQueueRegion as t };