@vite-hub/queue 0.4.1 → 0.5.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.
- package/README.md +2 -2
- package/dist/{client-B53_G4ky.js → client-DYE_ZV8c.js} +5 -6
- package/dist/{cloudflare-client-CoISDpIx.js → cloudflare-client-BasaJ68s.js} +4 -5
- package/dist/{cloudflare-resource-name-BIfBglC2.js → cloudflare-resource-name-BUNNqgkg.js} +1 -1
- package/dist/{config-B2eaXaT5.js → config-YEuaeQVq.js} +1 -3
- package/dist/definition-BL_3WHNu.js +27 -0
- package/dist/{duration-tujyhAKt.js → duration-CshzgSSx.js} +11 -3
- package/dist/{error-diagnostics-CQ4BUqRe.js → error-diagnostics-C0KyI408.js} +5 -1
- package/dist/{error-diagnostics-mJXBjmQx.js → error-diagnostics-DukggGP6.js} +8 -4
- package/dist/{handler-response-B6lz9nCn.js → handler-response-ChtAjPNo.js} +8 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -22
- package/dist/internal/runtime/cloudflare-client.d.ts +1 -1
- package/dist/internal/runtime/cloudflare-client.js +1 -1
- package/dist/internal/runtime/cloudflare-vite.d.ts +1 -1
- package/dist/internal/runtime/cloudflare-vite.js +8 -7
- package/dist/internal/runtime/local-client.d.ts +3 -3
- package/dist/internal/runtime/local-client.js +4 -4
- package/dist/internal/runtime/postgres-client.d.ts +5 -4
- package/dist/internal/runtime/postgres-client.js +16 -9
- package/dist/internal/runtime/state.d.ts +2 -2
- package/dist/internal/runtime/state.js +1 -1
- package/dist/internal/runtime/vercel-client.d.ts +1 -1
- package/dist/internal/runtime/vercel-client.js +3 -4
- package/dist/internal/runtime/worker-client.d.ts +2 -2
- package/dist/internal/runtime/worker-client.js +1 -1
- package/dist/{local-Di0FrVUw.js → local-CnBd5jdm.js} +26 -20
- package/dist/{local-CUaWoRUx.d.ts → local-DAL5ZgDg.d.ts} +1 -1
- package/dist/{operation-definition-nmRu_O3V.d.ts → operation-definition-CI2PJGqu.d.ts} +8 -2
- package/dist/{operations-BVV-9Q0N.js → operations-BL0b9pte.js} +5 -11
- package/dist/operations.d.ts +3 -3
- package/dist/operations.js +3 -3
- package/dist/runtime/hosted.d.ts +1 -1
- package/dist/runtime/hosted.js +3 -3
- package/dist/scan-module-BbqyaLl6.js +311 -0
- package/dist/{state-DLqTqF6V.js → state-ER1YdCBF.js} +1 -1
- package/dist/{types-Dsbb_Pvp.d.ts → types-D6hDNcMY.d.ts} +1 -2
- package/dist/{types-CiuSIPR0.d.ts → types-klaR79hV.d.ts} +8 -2
- package/dist/{vercel-region-B95MAMXN.js → vercel-region-DOciq2kx.js} +1 -1
- package/dist/vite.d.ts +8 -4
- package/dist/vite.js +123 -94
- package/package.json +3 -3
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { t as queueErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
-
import { c as queueRemovedOptionsError, d as normalizeQueueEnqueueInput, i as localUnsupportedEnqueueOptions, l as queueUnsupportedOptionsError, n as cloudflareUnsupportedEnqueueOptions, o as postgresUnsupportedEnqueueOptions, s as queueProviderResult, t as readQueueTimes, u as createQueueMessageId } from "./duration-
|
|
3
|
-
import { i as reportQueueDeliveryError, n as createQueueDeliveryErrorReport, r as isNonRetryableQueueError, t as checkQueueHandlerResponse } from "./handler-response-
|
|
1
|
+
import { t as queueErrorDiagnostics } from "./error-diagnostics-DukggGP6.js";
|
|
2
|
+
import { c as queueRemovedOptionsError, d as normalizeQueueEnqueueInput, i as localUnsupportedEnqueueOptions, l as queueUnsupportedOptionsError, n as cloudflareUnsupportedEnqueueOptions, o as postgresUnsupportedEnqueueOptions, s as queueProviderResult, t as readQueueTimes, u as createQueueMessageId } from "./duration-CshzgSSx.js";
|
|
3
|
+
import { i as reportQueueDeliveryError, n as createQueueDeliveryErrorReport, r as isNonRetryableQueueError, t as checkQueueHandlerResponse } from "./handler-response-ChtAjPNo.js";
|
|
4
4
|
import { mkdir, readFile, readdir, rename, rm, writeFile } from "node:fs/promises";
|
|
5
5
|
import { join, resolve } from "pathe";
|
|
6
6
|
import { randomUUID } from "node:crypto";
|
|
7
7
|
import { runInRunScopes } from "@vite-hub/runtime/internal/run-scope";
|
|
8
8
|
const maxTimerDelay = 2 ** 31 - 1;
|
|
9
|
+
const storeRetryMaxMs = 3e4;
|
|
10
|
+
function storeRetryDelayMs(failures) {
|
|
11
|
+
return Math.min(10 * 2 ** (failures - 1), storeRetryMaxMs);
|
|
12
|
+
}
|
|
9
13
|
/** Retries after 1, 2, and 4 seconds, up to 60 seconds. The local and postgres providers use it. */
|
|
10
14
|
function defaultRetryDelayMs(attempts) {
|
|
11
15
|
return Math.min(2 ** (attempts - 1), 60) * 1e3;
|
|
@@ -64,7 +68,6 @@ const providerNames = {
|
|
|
64
68
|
postgres: "The postgres provider",
|
|
65
69
|
vercel: "Vercel"
|
|
66
70
|
};
|
|
67
|
-
/** The JSON copy of the payload and its size in bytes. */
|
|
68
71
|
function toStoredPayload(payload) {
|
|
69
72
|
const text = JSON.stringify(payload);
|
|
70
73
|
return text === void 0 ? {
|
|
@@ -142,7 +145,7 @@ function toJobSummary(job, running) {
|
|
|
142
145
|
...job.failedAt === void 0 ? {} : { failedAt: isoTime(job.failedAt) },
|
|
143
146
|
id: job.id,
|
|
144
147
|
queue: job.queue,
|
|
145
|
-
state: job.state === "dead" ? "dead" :
|
|
148
|
+
state: running ? "running" : job.state === "dead" ? "dead" : "pending"
|
|
146
149
|
};
|
|
147
150
|
}
|
|
148
151
|
function createLocalQueueEngine(options) {
|
|
@@ -155,11 +158,13 @@ function createLocalQueueEngine(options) {
|
|
|
155
158
|
const writingKeys = /* @__PURE__ */ new Set();
|
|
156
159
|
const expiringKeys = /* @__PURE__ */ new Set();
|
|
157
160
|
const concurrency = /* @__PURE__ */ new Map();
|
|
161
|
+
const storeFailures = /* @__PURE__ */ new WeakMap();
|
|
158
162
|
let enqueueTail = Promise.resolve();
|
|
159
163
|
let started;
|
|
160
164
|
let timer;
|
|
161
165
|
let closed = false;
|
|
162
166
|
const file = (job) => join(base, `${job.key}.json`);
|
|
167
|
+
const attemptInFlight = (job) => runningKeys.has(job.key) || expiringKeys.has(job.key);
|
|
163
168
|
async function persist(job) {
|
|
164
169
|
const target = file(job);
|
|
165
170
|
await writeFile(`${target}.tmp`, JSON.stringify(job), "utf8");
|
|
@@ -194,7 +199,6 @@ function createLocalQueueEngine(options) {
|
|
|
194
199
|
}
|
|
195
200
|
arm(next);
|
|
196
201
|
}
|
|
197
|
-
/** Deletes the oldest dead jobs of `queue` above `localQueueDeadLimit`. */
|
|
198
202
|
async function pruneDead(queue) {
|
|
199
203
|
const dead = [...jobs.values()].filter((job) => job.queue === queue && job.state === "dead").sort((a, b) => (a.failedAt ?? 0) - (b.failedAt ?? 0));
|
|
200
204
|
for (const job of dead.slice(0, Math.max(0, dead.length - 100))) {
|
|
@@ -205,6 +209,7 @@ function createLocalQueueEngine(options) {
|
|
|
205
209
|
}
|
|
206
210
|
}
|
|
207
211
|
async function markDead(job, error, reason = `after ${job.attempts} attempts`) {
|
|
212
|
+
storeFailures.delete(job);
|
|
208
213
|
job.state = "dead";
|
|
209
214
|
job.error = error;
|
|
210
215
|
job.failedAt = Date.now();
|
|
@@ -213,7 +218,6 @@ function createLocalQueueEngine(options) {
|
|
|
213
218
|
delete job.payload;
|
|
214
219
|
await pruneDead(job.queue);
|
|
215
220
|
}
|
|
216
|
-
/** A job with a retention is not delivered after it expires, as on Vercel. */
|
|
217
221
|
async function expire(job) {
|
|
218
222
|
expiringKeys.add(job.key);
|
|
219
223
|
try {
|
|
@@ -234,7 +238,7 @@ function createLocalQueueEngine(options) {
|
|
|
234
238
|
jobs.delete(job.key);
|
|
235
239
|
} catch (error) {
|
|
236
240
|
console.error(`[vitehub:queue] The local provider ran a job, but cannot delete ${file(job)}.`, error);
|
|
237
|
-
await persist(job).catch(() => {});
|
|
241
|
+
await persist(job).catch((persistError) => console.error(`[vitehub:queue] The local provider cannot mark ${file(job)} done either. The job runs again after a restart.`, persistError));
|
|
238
242
|
}
|
|
239
243
|
}
|
|
240
244
|
async function deliver(job) {
|
|
@@ -253,6 +257,7 @@ function createLocalQueueEngine(options) {
|
|
|
253
257
|
...job,
|
|
254
258
|
attempts
|
|
255
259
|
});
|
|
260
|
+
storeFailures.delete(job);
|
|
256
261
|
job.attempts = attempts;
|
|
257
262
|
let handled = false;
|
|
258
263
|
try {
|
|
@@ -287,7 +292,11 @@ function createLocalQueueEngine(options) {
|
|
|
287
292
|
}
|
|
288
293
|
if (handled) await complete(job);
|
|
289
294
|
} catch (storeError) {
|
|
290
|
-
job.
|
|
295
|
+
if (job.state === "pending") {
|
|
296
|
+
const failures = (storeFailures.get(job) ?? 0) + 1;
|
|
297
|
+
storeFailures.set(job, failures);
|
|
298
|
+
job.availableAt = Date.now() + Math.max(retryDelayMs(Math.max(1, job.attempts)), storeRetryDelayMs(failures));
|
|
299
|
+
}
|
|
291
300
|
console.error(`[vitehub:queue] The local provider cannot update the job file in ${base}.`, storeError);
|
|
292
301
|
} finally {
|
|
293
302
|
runningKeys.delete(job.key);
|
|
@@ -327,7 +336,6 @@ function createLocalQueueEngine(options) {
|
|
|
327
336
|
for (const queue of new Set(recovered.map((job) => job.queue))) await pruneDead(queue);
|
|
328
337
|
schedule();
|
|
329
338
|
}
|
|
330
|
-
/** The newest job with this message ID. Message IDs from the caller can repeat. */
|
|
331
339
|
function findJob(id) {
|
|
332
340
|
let found;
|
|
333
341
|
for (const job of jobs.values()) {
|
|
@@ -336,7 +344,6 @@ function createLocalQueueEngine(options) {
|
|
|
336
344
|
}
|
|
337
345
|
return found;
|
|
338
346
|
}
|
|
339
|
-
/** Memory drops the payload of a dead job. Its file keeps it. */
|
|
340
347
|
async function readPayload(job) {
|
|
341
348
|
if (job.state !== "dead") return Object.hasOwn(job, "payload") ? { payload: job.payload } : {};
|
|
342
349
|
const stored = JSON.parse(await readFile(file(job), "utf8"));
|
|
@@ -381,7 +388,7 @@ function createLocalQueueEngine(options) {
|
|
|
381
388
|
});
|
|
382
389
|
checkBatch(entries, prepared.reduce((total, item) => total + item.bytes, 0), rules);
|
|
383
390
|
for (const { availableAt, entry, expiresAt, stored } of prepared) {
|
|
384
|
-
const duplicate = entry.idempotencyKey === void 0 ? void 0 : [...jobs.values(), ...created].find((job) => job.queue === queue && job.state === "pending"
|
|
391
|
+
const duplicate = entry.idempotencyKey === void 0 ? void 0 : [...jobs.values(), ...created].find((job) => job.queue === queue && job.idempotencyKey === entry.idempotencyKey && (job.state === "pending" || job.state === "dead" && attemptInFlight(job)));
|
|
385
392
|
if (duplicate) {
|
|
386
393
|
ids.push(duplicate.id);
|
|
387
394
|
continue;
|
|
@@ -424,7 +431,7 @@ function createLocalQueueEngine(options) {
|
|
|
424
431
|
const job = findJob(id);
|
|
425
432
|
if (!job) return void 0;
|
|
426
433
|
return {
|
|
427
|
-
...toJobSummary(job,
|
|
434
|
+
...toJobSummary(job, attemptInFlight(job)),
|
|
428
435
|
file: file(job),
|
|
429
436
|
...job.idempotencyKey === void 0 ? {} : { idempotencyKey: job.idempotencyKey },
|
|
430
437
|
...await readPayload(job)
|
|
@@ -432,13 +439,13 @@ function createLocalQueueEngine(options) {
|
|
|
432
439
|
},
|
|
433
440
|
async jobs() {
|
|
434
441
|
await this.start();
|
|
435
|
-
return [...jobs.values()].filter((job) => job.state !== "done" && !writingKeys.has(job.key)).sort((a, b) => b.enqueuedAt - a.enqueuedAt).map((job) => toJobSummary(job,
|
|
442
|
+
return [...jobs.values()].filter((job) => job.state !== "done" && !writingKeys.has(job.key)).sort((a, b) => b.enqueuedAt - a.enqueuedAt).map((job) => toJobSummary(job, attemptInFlight(job)));
|
|
436
443
|
},
|
|
437
444
|
async retry(id) {
|
|
438
445
|
await this.start();
|
|
439
446
|
const job = findJob(id);
|
|
440
447
|
if (!job) return "missing";
|
|
441
|
-
if (
|
|
448
|
+
if (attemptInFlight(job)) return "running";
|
|
442
449
|
const now = Date.now();
|
|
443
450
|
if (job.state === "dead") {
|
|
444
451
|
const { payload } = await readPayload(job);
|
|
@@ -458,12 +465,12 @@ function createLocalQueueEngine(options) {
|
|
|
458
465
|
await persist(retry);
|
|
459
466
|
jobs.set(job.key, retry);
|
|
460
467
|
schedule();
|
|
461
|
-
return toJobSummary(retry,
|
|
468
|
+
return toJobSummary(retry, attemptInFlight(retry));
|
|
462
469
|
}
|
|
463
470
|
job.availableAt = now;
|
|
464
471
|
await persist(job);
|
|
465
472
|
schedule();
|
|
466
|
-
return toJobSummary(job,
|
|
473
|
+
return toJobSummary(job, attemptInFlight(job));
|
|
467
474
|
},
|
|
468
475
|
provider: "local",
|
|
469
476
|
rules,
|
|
@@ -481,8 +488,8 @@ function createLocalQueueEngine(options) {
|
|
|
481
488
|
pending: 0,
|
|
482
489
|
running: 0
|
|
483
490
|
};
|
|
484
|
-
if (job
|
|
485
|
-
else if (
|
|
491
|
+
if (attemptInFlight(job)) entry.running++;
|
|
492
|
+
else if (job.state === "dead") entry.dead++;
|
|
486
493
|
else entry.pending++;
|
|
487
494
|
}
|
|
488
495
|
return {
|
|
@@ -494,7 +501,6 @@ function createLocalQueueEngine(options) {
|
|
|
494
501
|
}
|
|
495
502
|
};
|
|
496
503
|
}
|
|
497
|
-
/** The provider of the rules rejects the option, so `vite dev` fails as the host does. */
|
|
498
504
|
function unsupportedOptions(options, rules) {
|
|
499
505
|
return queueUnsupportedOptionsError(options, rules.rules, rules.unsupportedOptions);
|
|
500
506
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as QueueJobStore } from "./types-
|
|
1
|
+
import { A as QueueJobStore } from "./types-klaR79hV.js";
|
|
2
2
|
//#region src/providers/local.d.ts
|
|
3
3
|
/** One job for the engine. `vite dev` and the clients read `delay` and `retention` into seconds first. */
|
|
4
4
|
interface LocalQueueEntry {
|
|
@@ -104,6 +104,11 @@ interface OperationAccess {
|
|
|
104
104
|
*/
|
|
105
105
|
readonly sections: "all" | readonly string[];
|
|
106
106
|
readonly user?: OperationUser;
|
|
107
|
+
/**
|
|
108
|
+
* Who signed the call: `"console"` when the ViteHub Console signed it for a person, whose `user` is then a Console
|
|
109
|
+
* account and not an app user, or `"cli"` for a key. Not set for other calls.
|
|
110
|
+
*/
|
|
111
|
+
readonly via?: "console" | "cli";
|
|
107
112
|
}
|
|
108
113
|
interface OperationContext {
|
|
109
114
|
/** The checked Console access of the call. */
|
|
@@ -166,7 +171,8 @@ interface OperationDefinition<Input, Output> {
|
|
|
166
171
|
/** Standard Schema (valibot in this repo). Its Standard JSON Schema builds CLI flags and the MCP input schema. */
|
|
167
172
|
input: StandardSchemaV1<unknown, Input>;
|
|
168
173
|
output?: StandardSchemaV1<unknown, Output>;
|
|
169
|
-
|
|
174
|
+
/** `false`: no `vitehub` command. The Console and MCP still call the operation. */
|
|
175
|
+
cli?: false | {
|
|
170
176
|
/** Defaults: namespace = section, command = verb. */
|
|
171
177
|
namespace?: string;
|
|
172
178
|
/** A space groups commands: `jobs list` and `jobs show` run as `vitehub <namespace> jobs list` and `jobs show`. */
|
|
@@ -207,7 +213,7 @@ interface OperationDefinition<Input, Output> {
|
|
|
207
213
|
/** An operation of any input and output, as a registry holds it. */
|
|
208
214
|
interface AnyOperation extends Omit<OperationDefinition<unknown, unknown>, "cli" | "input" | "mcp" | "output" | "readOnlyWhen" | "run" | "scope" | "section"> {
|
|
209
215
|
readOnlyWhen?: (input: never) => boolean;
|
|
210
|
-
cli?: {
|
|
216
|
+
cli?: false | {
|
|
211
217
|
namespace?: string;
|
|
212
218
|
command?: string;
|
|
213
219
|
default?: boolean;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { t as queueErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
-
import { a as normalizePublicQueueIdentifier, r as isQueueError } from "./duration-
|
|
3
|
-
import { i as getQueueRuntimeConfig, o as getQueueRuntimeJobStore, s as listQueueDefinitionNames } from "./state-
|
|
4
|
-
import { n as dynamicQueue } from "./client-
|
|
1
|
+
import { t as queueErrorDiagnostics } from "./error-diagnostics-DukggGP6.js";
|
|
2
|
+
import { a as normalizePublicQueueIdentifier, r as isQueueError } from "./duration-CshzgSSx.js";
|
|
3
|
+
import { i as getQueueRuntimeConfig, o as getQueueRuntimeJobStore, s as listQueueDefinitionNames } from "./state-ER1YdCBF.js";
|
|
4
|
+
import { n as dynamicQueue } from "./client-DYE_ZV8c.js";
|
|
5
5
|
import { t as redactInspectionText } from "./inspect-PeuckaC3.js";
|
|
6
|
-
import { runtimeErrorDiagnostics } from "@vite-hub/runtime";
|
|
6
|
+
import { runtimeErrorDiagnostics } from "@vite-hub/runtime/internal/error-diagnostics";
|
|
7
7
|
//#region src/runtime/operations.ts
|
|
8
|
-
/** The HTTP status that the CLI, the Console, and Agents report for each code of a failed operation. */
|
|
9
8
|
const statuses = {
|
|
10
9
|
QUEUE_DEFINITION_NAME_INVALID: 400,
|
|
11
10
|
QUEUE_DEFINITION_NOT_FOUND: 404,
|
|
@@ -18,7 +17,6 @@ const statuses = {
|
|
|
18
17
|
QUEUE_PROVIDER_INVALID_RESPONSE: 502,
|
|
19
18
|
QUEUE_UNSUPPORTED_OPTION: 400
|
|
20
19
|
};
|
|
21
|
-
/** Gives a Queue catalog error the status and the redacted message that the CLI and the Console report. */
|
|
22
20
|
function failure(error) {
|
|
23
21
|
if (runtimeErrorDiagnostics.RUNTIME_DURATION_INVALID.is(error)) return Object.assign(error, {
|
|
24
22
|
status: 400,
|
|
@@ -86,10 +84,6 @@ async function sendToQueue(input) {
|
|
|
86
84
|
status: "queued"
|
|
87
85
|
};
|
|
88
86
|
}
|
|
89
|
-
/**
|
|
90
|
-
* The stored jobs of the local or postgres provider. Cloudflare and Vercel do not let a producer read their queue, so
|
|
91
|
-
* their jobs do not list.
|
|
92
|
-
*/
|
|
93
87
|
async function localJobs() {
|
|
94
88
|
const config = getQueueRuntimeConfig();
|
|
95
89
|
if (config === false) throw failure(queueErrorDiagnostics.QUEUE_DISABLED());
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { A as QueueJobStore, d as LocalQueueJob, f as LocalQueueJobDetail, h as LocalQueueStatus, p as LocalQueueRules, w as QueueDriver } from "./types-
|
|
2
|
-
import "./local-
|
|
3
|
-
import { t as AnyOperation } from "./operation-definition-
|
|
1
|
+
import { A as QueueJobStore, d as LocalQueueJob, f as LocalQueueJobDetail, h as LocalQueueStatus, p as LocalQueueRules, w as QueueDriver } from "./types-klaR79hV.js";
|
|
2
|
+
import "./local-DAL5ZgDg.js";
|
|
3
|
+
import { t as AnyOperation } from "./operation-definition-CI2PJGqu.js";
|
|
4
4
|
//#region src/runtime/operations.d.ts
|
|
5
5
|
interface QueueListResult {
|
|
6
6
|
/** `undefined` when the runtime has not installed a Queue configuration. */
|
package/dist/operations.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as isRecordOrFunction } from "./object-D8pRdprI.js";
|
|
2
|
-
import { t as internalErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
+
import { t as internalErrorDiagnostics } from "./error-diagnostics-C0KyI408.js";
|
|
3
3
|
//#region ../internal/src/standard-schema.ts
|
|
4
4
|
function readOwn(value, key) {
|
|
5
5
|
if (value === null || Object(value) !== value) return;
|
|
@@ -1163,7 +1163,7 @@ function pipe(...pipe$1) {
|
|
|
1163
1163
|
}
|
|
1164
1164
|
//#endregion
|
|
1165
1165
|
//#region src/operations.ts
|
|
1166
|
-
const runtime = () => import("./operations-
|
|
1166
|
+
const runtime = () => import("./operations-BL0b9pte.js");
|
|
1167
1167
|
function defineQueueOperation(definition) {
|
|
1168
1168
|
return defineOperation({
|
|
1169
1169
|
...definition,
|
|
@@ -1268,7 +1268,7 @@ const queueOperations = [
|
|
|
1268
1268
|
}),
|
|
1269
1269
|
defineQueueOperation({
|
|
1270
1270
|
cli: {
|
|
1271
|
-
command: "jobs
|
|
1271
|
+
command: "jobs get",
|
|
1272
1272
|
format: formatJob,
|
|
1273
1273
|
namespace: "queue",
|
|
1274
1274
|
positional: ["id"]
|
package/dist/runtime/hosted.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { x as QueueDefinition } from "../types-
|
|
1
|
+
import { x as QueueDefinition } from "../types-klaR79hV.js";
|
|
2
2
|
//#region src/runtime/hosted.d.ts
|
|
3
3
|
export declare const hostedVercelWaitUntil: (promise: Promise<unknown>) => void | undefined;
|
|
4
4
|
/** Handle one Vercel Queue delivery. The generated consumer route is a Fetchable module that passes its Request here. */
|
package/dist/runtime/hosted.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as queueErrorDiagnostics } from "../error-diagnostics-
|
|
2
|
-
import { n as dynamicQueue } from "../client-
|
|
3
|
-
import { i as reportQueueDeliveryError, r as isNonRetryableQueueError, t as checkQueueHandlerResponse } from "../handler-response-
|
|
1
|
+
import { t as queueErrorDiagnostics } from "../error-diagnostics-DukggGP6.js";
|
|
2
|
+
import { n as dynamicQueue } from "../client-DYE_ZV8c.js";
|
|
3
|
+
import { i as reportQueueDeliveryError, r as isNonRetryableQueueError, t as checkQueueHandlerResponse } from "../handler-response-ChtAjPNo.js";
|
|
4
4
|
import { runInRunScopes } from "@vite-hub/runtime/internal/run-scope";
|
|
5
5
|
import { waitUntil } from "@vercel/functions";
|
|
6
6
|
//#region src/runtime/hosted.ts
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { parseSync } from "vite";
|
|
2
|
+
//#region ../internal/src/build/ast-walk.ts
|
|
3
|
+
/** The oxc parser grammar for a file, from its extension. Defaults to TypeScript. */
|
|
4
|
+
function moduleLanguage(file) {
|
|
5
|
+
if (/\.(?:c|m)?tsx$/i.test(file)) return "tsx";
|
|
6
|
+
if (/\.(?:c|m)?jsx$/i.test(file)) return "jsx";
|
|
7
|
+
if (/\.(?:c|m)?js$/i.test(file)) return "js";
|
|
8
|
+
return "ts";
|
|
9
|
+
}
|
|
10
|
+
function isNode(value) {
|
|
11
|
+
return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
|
|
12
|
+
}
|
|
13
|
+
/** Visits `node` and its descendants. Return `false` from `visit` to skip the children of a node. */
|
|
14
|
+
function walk(node, visit, parent) {
|
|
15
|
+
if (visit(node, parent) === false) return;
|
|
16
|
+
const fields = node;
|
|
17
|
+
for (const key in fields) {
|
|
18
|
+
const child = fields[key];
|
|
19
|
+
if (typeof child !== "object" || child === null || key === "parent") continue;
|
|
20
|
+
if (Array.isArray(child)) {
|
|
21
|
+
for (const item of child) if (isNode(item)) walk(item, visit, node);
|
|
22
|
+
} else if (isNode(child)) walk(child, visit, node);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region ../internal/src/build/scan-module.ts
|
|
27
|
+
/**
|
|
28
|
+
* Reads facts from JavaScript and TypeScript modules at build and dev time. The scanner parses each module once with
|
|
29
|
+
* the oxc parser that Vite ships through Rolldown, and never runs it. Values that are not static literals read as
|
|
30
|
+
* `dynamic`, so callers can report their own diagnostics.
|
|
31
|
+
*/
|
|
32
|
+
/** The value of an expression that the scanner cannot read without running the module. */
|
|
33
|
+
const dynamic = Symbol("dynamic");
|
|
34
|
+
/** Parses a module once. `file` selects the grammar from its extension and defaults to TypeScript. */
|
|
35
|
+
function scanModule(source, file = "module.ts") {
|
|
36
|
+
const result = parseSync(file, source, {
|
|
37
|
+
lang: moduleLanguage(file),
|
|
38
|
+
preserveParens: false,
|
|
39
|
+
sourceType: "module"
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
comments: result.comments,
|
|
43
|
+
errors: result.errors,
|
|
44
|
+
file,
|
|
45
|
+
program: result.program,
|
|
46
|
+
source
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** Lists the names that a module exports. A default export reads as `default`. Type-only exports are left out. */
|
|
50
|
+
function exportNames(source, file = "module.ts") {
|
|
51
|
+
const { module } = parseSync(file, source, {
|
|
52
|
+
lang: moduleLanguage(file),
|
|
53
|
+
sourceType: "module"
|
|
54
|
+
});
|
|
55
|
+
return module.staticExports.flatMap((statement) => statement.entries).flatMap((entry) => {
|
|
56
|
+
if (entry.isType) return [];
|
|
57
|
+
if (entry.exportName.kind === "Default") return ["default"];
|
|
58
|
+
return entry.exportName.name === null ? [] : [entry.exportName.name];
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/** The source text of a node. */
|
|
62
|
+
function nodeText(module, node) {
|
|
63
|
+
return module.source.slice(node.start, node.end);
|
|
64
|
+
}
|
|
65
|
+
/** Removes parentheses, `as`, `satisfies`, `!`, and `<T>` assertions around an expression. */
|
|
66
|
+
function unwrapExpression(node) {
|
|
67
|
+
while (node.type === "ParenthesizedExpression" || node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression" || node.type === "TSNonNullExpression" || node.type === "TSTypeAssertion") node = node.expression;
|
|
68
|
+
return node;
|
|
69
|
+
}
|
|
70
|
+
/** A call argument without assertions, or undefined for a spread or missing argument. */
|
|
71
|
+
function argumentExpression(argument) {
|
|
72
|
+
return argument === void 0 || argument.type === "SpreadElement" ? void 0 : unwrapExpression(argument);
|
|
73
|
+
}
|
|
74
|
+
/** Calls whose callee is a plain identifier in `names`, such as `defineCollection(...)`, in source order. */
|
|
75
|
+
function findCalls(module, names) {
|
|
76
|
+
const wanted = new Set(names);
|
|
77
|
+
const calls = [];
|
|
78
|
+
walk(module.program, (node) => {
|
|
79
|
+
if (node.type === "CallExpression" && node.callee.type === "Identifier" && wanted.has(node.callee.name)) calls.push(node);
|
|
80
|
+
});
|
|
81
|
+
return calls.sort((left, right) => left.start - right.start);
|
|
82
|
+
}
|
|
83
|
+
/** The expression of `export default <expression>`, without assertions. Declarations return undefined. */
|
|
84
|
+
function defaultExportExpression(module) {
|
|
85
|
+
for (const statement of module.program.body) {
|
|
86
|
+
if (statement.type !== "ExportDefaultDeclaration") continue;
|
|
87
|
+
const declaration = statement.declaration;
|
|
88
|
+
if (declaration.type === "FunctionDeclaration" || declaration.type === "ClassDeclaration" || declaration.type === "TSInterfaceDeclaration") return;
|
|
89
|
+
return unwrapExpression(declaration);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Finds `export default defineX({ ... })` for one of `names`. With `positionalOptionsIndex`, a call whose first
|
|
94
|
+
* argument is not an object and that has more than one argument reads its options from that argument. Returns
|
|
95
|
+
* undefined when the options are not an object literal.
|
|
96
|
+
*/
|
|
97
|
+
function findDefaultExportCall(module, names, options = {}) {
|
|
98
|
+
const call = defaultExportExpression(module);
|
|
99
|
+
if (call?.type !== "CallExpression" || call.callee.type !== "Identifier" || !names.includes(call.callee.name)) return;
|
|
100
|
+
const name = call.callee.name;
|
|
101
|
+
const first = argumentExpression(call.arguments[0]);
|
|
102
|
+
if (first?.type === "ObjectExpression") return {
|
|
103
|
+
call,
|
|
104
|
+
name,
|
|
105
|
+
options: first
|
|
106
|
+
};
|
|
107
|
+
if (options.positionalOptionsIndex === void 0 || first === void 0 || call.arguments.length < 2) return;
|
|
108
|
+
const positional = call.arguments[options.positionalOptionsIndex];
|
|
109
|
+
if (positional === void 0) return {
|
|
110
|
+
call,
|
|
111
|
+
name
|
|
112
|
+
};
|
|
113
|
+
const object = argumentExpression(positional);
|
|
114
|
+
return object?.type === "ObjectExpression" ? {
|
|
115
|
+
call,
|
|
116
|
+
name,
|
|
117
|
+
options: object
|
|
118
|
+
} : void 0;
|
|
119
|
+
}
|
|
120
|
+
function staticKey(property) {
|
|
121
|
+
const key = property.key;
|
|
122
|
+
if (key.type === "Identifier" && !property.computed) return key.name;
|
|
123
|
+
if (key.type === "PrivateIdentifier") return;
|
|
124
|
+
const value = staticValue(key);
|
|
125
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "bigint" ? String(value) : void 0;
|
|
126
|
+
}
|
|
127
|
+
/** The members of an object literal in source order. */
|
|
128
|
+
function objectProperties(object) {
|
|
129
|
+
return object.properties.map((node) => node.type === "SpreadElement" ? {
|
|
130
|
+
computed: false,
|
|
131
|
+
key: void 0,
|
|
132
|
+
node,
|
|
133
|
+
value: void 0
|
|
134
|
+
} : {
|
|
135
|
+
computed: node.computed,
|
|
136
|
+
key: staticKey(node),
|
|
137
|
+
node,
|
|
138
|
+
value: unwrapExpression(node.value)
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/** The last member named `name`, which is the one that the object keeps at runtime. */
|
|
142
|
+
function findProperty(object, name) {
|
|
143
|
+
return objectProperties(object).findLast((property) => property.key === name);
|
|
144
|
+
}
|
|
145
|
+
/** The value of a template literal without substitutions. */
|
|
146
|
+
function staticTemplate(node) {
|
|
147
|
+
if (node.expressions.length) return dynamic;
|
|
148
|
+
return node.quasis[0]?.value.cooked ?? dynamic;
|
|
149
|
+
}
|
|
150
|
+
const escapePattern = /\\(u\{[^}]*\}?|u[\s\S]{0,4}|x[\s\S]{0,2}|0\d|[\s\S])/g;
|
|
151
|
+
/**
|
|
152
|
+
* True when a string literal has an escape that strict mode code rejects. The parser recovers from some bad escapes
|
|
153
|
+
* and accepts legacy octal escapes, so the scanner checks them again.
|
|
154
|
+
*/
|
|
155
|
+
function hasInvalidEscape(raw) {
|
|
156
|
+
for (const [, escape = ""] of raw.matchAll(escapePattern)) if (escape.startsWith("u{")) {
|
|
157
|
+
const code = escape.slice(2, -1);
|
|
158
|
+
if (!escape.endsWith("}") || !/^[\da-fA-F]+$/.test(code) || Number.parseInt(code, 16) > 1114111) return true;
|
|
159
|
+
} else if (escape.startsWith("u")) {
|
|
160
|
+
if (!/^u[\da-fA-F]{4}$/.test(escape)) return true;
|
|
161
|
+
} else if (escape.startsWith("x")) {
|
|
162
|
+
if (!/^x[\da-fA-F]{2}$/.test(escape)) return true;
|
|
163
|
+
} else if (/^(?:[1-9]|0\d)$/.test(escape)) return true;
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Reads a literal value: strings, numbers, booleans, `null`, `undefined`, template literals without substitutions,
|
|
168
|
+
* and arrays and objects of these. Any other expression gives `dynamic`.
|
|
169
|
+
*/
|
|
170
|
+
function staticValue(node) {
|
|
171
|
+
node = unwrapExpression(node);
|
|
172
|
+
switch (node.type) {
|
|
173
|
+
case "Literal":
|
|
174
|
+
if ("regex" in node) return dynamic;
|
|
175
|
+
return typeof node.value === "string" && hasInvalidEscape(node.raw ?? "") ? dynamic : node.value;
|
|
176
|
+
case "TemplateLiteral": return staticTemplate(node);
|
|
177
|
+
case "Identifier": return node.name === "undefined" ? void 0 : dynamic;
|
|
178
|
+
case "UnaryExpression": {
|
|
179
|
+
if (node.operator === "void") return staticValue(node.argument) === dynamic ? dynamic : void 0;
|
|
180
|
+
const value = staticValue(node.argument);
|
|
181
|
+
if (node.operator === "-" && (typeof value === "number" || typeof value === "bigint")) return -value;
|
|
182
|
+
return dynamic;
|
|
183
|
+
}
|
|
184
|
+
case "ArrayExpression": {
|
|
185
|
+
const values = [];
|
|
186
|
+
for (const element of node.elements) {
|
|
187
|
+
if (element === null || element.type === "SpreadElement") return dynamic;
|
|
188
|
+
const value = staticValue(element);
|
|
189
|
+
if (value === dynamic) return dynamic;
|
|
190
|
+
values.push(value);
|
|
191
|
+
}
|
|
192
|
+
return values;
|
|
193
|
+
}
|
|
194
|
+
case "ObjectExpression": {
|
|
195
|
+
const values = {};
|
|
196
|
+
for (const property of objectProperties(node)) {
|
|
197
|
+
if (property.key === void 0 || property.node.type !== "Property" || property.node.kind !== "init" || property.node.method || property.value === void 0) return dynamic;
|
|
198
|
+
const value = staticValue(property.value);
|
|
199
|
+
if (value === dynamic) return dynamic;
|
|
200
|
+
Object.defineProperty(values, property.key, {
|
|
201
|
+
configurable: true,
|
|
202
|
+
enumerable: true,
|
|
203
|
+
value,
|
|
204
|
+
writable: true
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
return values;
|
|
208
|
+
}
|
|
209
|
+
default: return dynamic;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/** The static string value of an expression, or undefined when it is not a string literal. */
|
|
213
|
+
function staticString(node) {
|
|
214
|
+
if (node === void 0) return;
|
|
215
|
+
const value = staticValue(node);
|
|
216
|
+
return typeof value === "string" ? value : void 0;
|
|
217
|
+
}
|
|
218
|
+
function isLineTerminator(char) {
|
|
219
|
+
return char === "\n" || char === "\r" || char === "\u2028" || char === "\u2029";
|
|
220
|
+
}
|
|
221
|
+
/** Comments, JSX text, and string, template, and regular expression literals, sorted by position. Templates are not split. */
|
|
222
|
+
function literalSpans(module) {
|
|
223
|
+
const spans = module.comments.map((comment) => ({
|
|
224
|
+
end: comment.end,
|
|
225
|
+
inert: true,
|
|
226
|
+
start: comment.start
|
|
227
|
+
}));
|
|
228
|
+
walk(module.program, (node) => {
|
|
229
|
+
if (node.type === "TemplateLiteral" || node.type === "JSXText") {
|
|
230
|
+
spans.push({
|
|
231
|
+
end: node.end,
|
|
232
|
+
inert: node.type === "JSXText",
|
|
233
|
+
start: node.start
|
|
234
|
+
});
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
if (node.type === "Literal" && (typeof node.value === "string" || "regex" in node)) spans.push({
|
|
238
|
+
end: node.end,
|
|
239
|
+
inert: false,
|
|
240
|
+
start: node.start
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
return spans.sort((left, right) => left.start - right.start);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* The module source with comments, strings, templates, regular expressions, and JSX text replaced by spaces. Line
|
|
247
|
+
* terminators and all positions stay the same, so text matches map back to the source.
|
|
248
|
+
*/
|
|
249
|
+
function maskLiterals(module) {
|
|
250
|
+
const output = module.source.split("");
|
|
251
|
+
for (const span of literalSpans(module)) for (let index = span.start; index < span.end; index++) if (!isLineTerminator(output[index] ?? "")) output[index] = " ";
|
|
252
|
+
return output.join("");
|
|
253
|
+
}
|
|
254
|
+
const codeTokenPattern = /(?:0[xX][\da-fA-F_]+|0[bB][01_]+|0[oO][0-7_]+|(?:\d[\d_]*(?:\.[\d_]*)?|\.\d[\d_]*)(?:[eE][+-]?[\d_]+)?)n?|(?:[\p{ID_Start}$_]|\\u\{[\da-fA-F]+\}|\\u[\da-fA-F]{4})(?:[\p{ID_Continue}$]|\\u\{[\da-fA-F]+\}|\\u[\da-fA-F]{4})*|\S/gu;
|
|
255
|
+
function decodeIdentifier(token) {
|
|
256
|
+
return token.replace(/\\u(?:\{([\da-fA-F]+)\}|([\da-fA-F]{4}))/g, (_escape, point, unit) => String.fromCodePoint(Number.parseInt(point ?? unit ?? "0", 16)));
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Splits a module into tokens. The parser finds literals and comments, so a `/` is never confused between division
|
|
260
|
+
* and a regular expression. Identifier escapes are decoded.
|
|
261
|
+
*/
|
|
262
|
+
function moduleTokens(module) {
|
|
263
|
+
const { source } = module;
|
|
264
|
+
const tokens = [];
|
|
265
|
+
const starts = [];
|
|
266
|
+
const lineBreaks = /* @__PURE__ */ new Set();
|
|
267
|
+
let previousEnd = 0;
|
|
268
|
+
const push = (token, start) => {
|
|
269
|
+
for (let index = previousEnd; index < start; index++) if (isLineTerminator(source[index] ?? "")) {
|
|
270
|
+
lineBreaks.add(tokens.length);
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
tokens.push(token);
|
|
274
|
+
starts.push(start);
|
|
275
|
+
previousEnd = start + token.length;
|
|
276
|
+
};
|
|
277
|
+
const scanCode = (start, end) => {
|
|
278
|
+
const pattern = new RegExp(codeTokenPattern.source, codeTokenPattern.flags);
|
|
279
|
+
const code = source.slice(start, end);
|
|
280
|
+
for (const match of code.matchAll(pattern)) {
|
|
281
|
+
const token = match[0];
|
|
282
|
+
push(/^[\p{ID_Start}$_\\]/u.test(token) ? decodeIdentifier(token) : token, start + match.index);
|
|
283
|
+
previousEnd = start + match.index + token.length;
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
let cursor = 0;
|
|
287
|
+
for (const span of literalSpans(module)) {
|
|
288
|
+
if (span.start < cursor) continue;
|
|
289
|
+
scanCode(cursor, span.start);
|
|
290
|
+
if (!span.inert) push(source.slice(span.start, span.end), span.start);
|
|
291
|
+
cursor = span.end;
|
|
292
|
+
}
|
|
293
|
+
scanCode(cursor, source.length);
|
|
294
|
+
return {
|
|
295
|
+
lineBreaks,
|
|
296
|
+
starts,
|
|
297
|
+
tokens
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
/** The source of each `${...}` substitution in a template literal, such as the source of one template token. */
|
|
301
|
+
function templateExpressionSources(template) {
|
|
302
|
+
const module = scanModule(`(${template})`);
|
|
303
|
+
const statement = module.program.body[0];
|
|
304
|
+
if (statement?.type !== "ExpressionStatement") return [];
|
|
305
|
+
const expression = unwrapExpression(statement.expression);
|
|
306
|
+
const literal = expression.type === "TaggedTemplateExpression" ? expression.quasi : expression;
|
|
307
|
+
if (literal.type !== "TemplateLiteral") return [];
|
|
308
|
+
return literal.expressions.map((_node, index) => module.source.slice(literal.quasis[index]?.end ?? 0, literal.quasis[index + 1]?.start ?? 0));
|
|
309
|
+
}
|
|
310
|
+
//#endregion
|
|
311
|
+
export { argumentExpression, defaultExportExpression, dynamic, exportNames, findCalls, findDefaultExportCall, findProperty, maskLiterals, moduleTokens, nodeText, objectProperties, scanModule, staticString, staticValue, templateExpressionSources, unwrapExpression, walk };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as isRecord } from "./object-D8pRdprI.js";
|
|
2
|
-
import { t as queueErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
+
import { t as queueErrorDiagnostics } from "./error-diagnostics-DukggGP6.js";
|
|
3
3
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
4
|
//#region ../internal/src/runtime/cloudflare-env-lookup.ts
|
|
5
5
|
/** The key of the AsyncLocalStorage store on `globalThis`. Every bundled copy of this module shares the store. */
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { R as ResolvedQueueOptions, T as QueueDriverOptions } from "./types-
|
|
1
|
+
import { R as ResolvedQueueOptions, T as QueueDriverOptions } from "./types-klaR79hV.js";
|
|
2
2
|
//#region src/internal/runtime/types.d.ts
|
|
3
|
-
/** Only the generated development integration enables handler error details. */
|
|
4
3
|
interface QueueDevelopmentOptions {
|
|
5
4
|
development?: boolean;
|
|
6
5
|
}
|