@vite-hub/queue 0.4.1 → 0.5.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 +2 -2
- package/dist/{client-B53_G4ky.js → client-CwoCdKct.js} +9 -12
- package/dist/{cloudflare-GosJefIK.js → cloudflare-BMc35cBD.js} +2 -4
- package/dist/{cloudflare-client-CoISDpIx.js → cloudflare-client-xWteD-su.js} +7 -10
- package/dist/{cloudflare-resource-name-BIfBglC2.js → cloudflare-resource-name-Bv8Z7nDU.js} +3 -4
- package/dist/{config-B2eaXaT5.js → config-Bzp1xmdh.js} +4 -9
- package/dist/definition-CIiFfst2.js +26 -0
- package/dist/durability.d.ts +1 -3
- package/dist/durability.js +1 -2
- package/dist/{duration-tujyhAKt.js → duration-C5w_-Rf4.js} +14 -9
- package/dist/{error-diagnostics-mJXBjmQx.js → error-diagnostics-Dv6nKZQW.js} +9 -6
- package/dist/{error-diagnostics-CQ4BUqRe.js → error-diagnostics-kKXseq8d.js} +10 -3
- package/dist/{handler-response-B6lz9nCn.js → handler-response-CchTXVjm.js} +10 -7
- package/dist/index.d.ts +1 -9
- package/dist/index.js +5 -24
- package/dist/{inspect-PeuckaC3.js → inspect-CwdWUhPj.js} +1 -2
- package/dist/internal/runtime/cloudflare-client.d.ts +2 -4
- package/dist/internal/runtime/cloudflare-client.js +1 -2
- package/dist/internal/runtime/cloudflare-vite.d.ts +2 -9
- package/dist/internal/runtime/cloudflare-vite.js +13 -16
- package/dist/internal/runtime/local-client.d.ts +4 -6
- package/dist/internal/runtime/local-client.js +5 -6
- package/dist/internal/runtime/postgres-client.d.ts +6 -8
- package/dist/internal/runtime/postgres-client.js +18 -13
- package/dist/internal/runtime/state.d.ts +3 -5
- package/dist/internal/runtime/state.js +1 -2
- package/dist/internal/runtime/vercel-client.d.ts +2 -4
- package/dist/internal/runtime/vercel-client.js +5 -8
- package/dist/internal/runtime/worker-client.d.ts +3 -5
- package/dist/internal/runtime/worker-client.js +2 -3
- package/dist/{invariant-D8_xBqmZ.js → invariant-CmdvZ3vp.js} +1 -2
- package/dist/{local-CUaWoRUx.d.ts → local-B72WRWkS.d.ts} +1 -3
- package/dist/{local-Di0FrVUw.js → local-RX10a_Sq.js} +26 -21
- package/dist/{object-D8pRdprI.js → object-DRSmpe04.js} +1 -2
- package/dist/{operation-definition-nmRu_O3V.d.ts → operation-definition-CqZkx1Rm.d.ts} +8 -6
- package/dist/{operations-BVV-9Q0N.js → operations-CoEXxfUW.js} +7 -14
- package/dist/operations.d.ts +3 -7
- package/dist/operations.js +10 -16
- package/dist/runtime/hosted.d.ts +2 -4
- package/dist/runtime/hosted.js +4 -5
- package/dist/scan-module-BaqBao0J.js +309 -0
- package/dist/{state-DLqTqF6V.js → state-DqxeV11k.js} +5 -8
- package/dist/{types-Dsbb_Pvp.d.ts → types-BevEYrUV.d.ts} +1 -4
- package/dist/{types-CiuSIPR0.d.ts → types-BzPGPV9z.d.ts} +8 -4
- package/dist/{vercel-region-B95MAMXN.js → vercel-region-DEsR1YJQ.js} +2 -3
- package/dist/{vercel-C_4vqxcl.js → vercel-sUJOxFBB.js} +2 -3
- package/dist/vite.d.ts +8 -30
- package/dist/vite.js +148 -139
- package/package.json +10 -10
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { n as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { t as internalErrorDiagnostics } from "../../error-diagnostics-kKXseq8d.js";
|
|
2
|
+
import { n as normalizeQueueOptions } from "../../config-Bzp1xmdh.js";
|
|
3
|
+
import { n as getCloudflareQueueDefinitionName } from "../../cloudflare-BMc35cBD.js";
|
|
4
|
+
import { t as getCloudflareQueueName } from "../../cloudflare-resource-name-Bv8Z7nDU.js";
|
|
5
|
+
import { n as createCloudflareQueueBatchHandler, t as createCloudflareQueueRuntimeClient } from "../../cloudflare-client-xWteD-su.js";
|
|
6
|
+
import { _ as runWithActiveCloudflareEnv, c as loadQueueDefinition, d as setQueueRuntimeConfig, h as createCloudflareRuntimeEvent, m as setQueueRuntimeRegistry, u as runWithQueueRuntimeEvent } from "../../state-DqxeV11k.js";
|
|
7
|
+
import { t as queueErrorDiagnostics } from "../../error-diagnostics-Dv6nKZQW.js";
|
|
8
8
|
import { runInRunScopes } from "@vite-hub/runtime/internal/run-scope";
|
|
9
|
-
|
|
9
|
+
// ../internal/src/runtime/app.ts
|
|
10
10
|
function resolveAppFetch(label, app) {
|
|
11
11
|
if (!app) return;
|
|
12
12
|
if (typeof app === "function") return app;
|
|
@@ -14,8 +14,7 @@ function resolveAppFetch(label, app) {
|
|
|
14
14
|
if (typeof app.fetch === "function") return app.fetch.bind(app);
|
|
15
15
|
throw internalErrorDiagnostics.INTERNAL_R0011({ message: `Invalid ${label} app. Expected an h3 app or a fetch-compatible handler.` });
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
//#region ../internal/src/runtime/cloudflare-hosted.ts
|
|
17
|
+
// ../internal/src/runtime/cloudflare-hosted.ts
|
|
19
18
|
function createWebRequestHandler(appHandler) {
|
|
20
19
|
return async (request, context) => await Promise.resolve(appHandler ? appHandler(request, context) : new Response(JSON.stringify({
|
|
21
20
|
status: 404,
|
|
@@ -38,8 +37,7 @@ function createCloudflareHostedWorker(adapter) {
|
|
|
38
37
|
return await handle();
|
|
39
38
|
} };
|
|
40
39
|
}
|
|
41
|
-
|
|
42
|
-
//#region src/runtime/cloudflare-shared.ts
|
|
40
|
+
// src/runtime/cloudflare-shared.ts
|
|
43
41
|
function createQueueJob(message, batch) {
|
|
44
42
|
return {
|
|
45
43
|
attempts: typeof message.attempts === "number" ? message.attempts : 1,
|
|
@@ -51,8 +49,7 @@ function createQueueJob(message, batch) {
|
|
|
51
49
|
payload: message.body
|
|
52
50
|
};
|
|
53
51
|
}
|
|
54
|
-
|
|
55
|
-
//#region src/internal/runtime/cloudflare-vite.ts
|
|
52
|
+
// src/internal/runtime/cloudflare-vite.ts
|
|
56
53
|
function createRegistryDefinitionNames(registry, namePrefix) {
|
|
57
54
|
if (!registry) return void 0;
|
|
58
55
|
const definitions = {};
|
|
@@ -102,11 +99,11 @@ function createQueueCloudflareWorker(options = {}) {
|
|
|
102
99
|
await runWithQueueRuntimeEvent(runtimeEvent, async () => {
|
|
103
100
|
await runInRunScopes(() => definition.handler(createQueueJob(message, currentBatch)));
|
|
104
101
|
});
|
|
105
|
-
}
|
|
102
|
+
},
|
|
103
|
+
queue: definitionName
|
|
106
104
|
})(batch);
|
|
107
105
|
});
|
|
108
106
|
}
|
|
109
107
|
};
|
|
110
108
|
}
|
|
111
|
-
//#endregion
|
|
112
109
|
export { createQueueCloudflareWorker };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { n as QueueRuntimeOptions, t as QueueRuntimeDriverOptions } from "../../types-
|
|
4
|
-
//#region src/internal/runtime/local-client.d.ts
|
|
1
|
+
import { t as LocalQueueEngine } from "../../local-B72WRWkS.js";
|
|
2
|
+
import { b as QueueClient, h as LocalQueueStatus } from "../../types-BzPGPV9z.js";
|
|
3
|
+
import { n as QueueRuntimeOptions, t as QueueRuntimeDriverOptions } from "../../types-BevEYrUV.js";
|
|
5
4
|
export declare function createLocalQueueRuntimeClient(options: QueueRuntimeDriverOptions): Promise<QueueClient>;
|
|
6
5
|
/**
|
|
7
6
|
* Starts delivery of the stored jobs when the server starts, so jobs from before a restart run without a new send.
|
|
@@ -13,5 +12,4 @@ export declare function useLocalQueueEngine(config: QueueRuntimeOptions): LocalQ
|
|
|
13
12
|
/** Status of the stored jobs, for `vitehub queue list` and the Console. */
|
|
14
13
|
export declare function getLocalQueueStatus(config: QueueRuntimeOptions): Promise<LocalQueueStatus | undefined>;
|
|
15
14
|
/** Stops the timers of every local engine. The stored jobs stay. */
|
|
16
|
-
export declare function closeLocalQueues(): void;
|
|
17
|
-
//#endregion
|
|
15
|
+
export declare function closeLocalQueues(): void;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { t as defaultLocalQueueBase } from "../../config-Bzp1xmdh.js";
|
|
2
|
+
import { i as localQueueDeliveryRules, n as createLocalQueueEngine, t as createLocalQueueClient } from "../../local-RX10a_Sq.js";
|
|
3
|
+
import { c as loadQueueDefinition, l as missingQueueDefinitionError } from "../../state-DqxeV11k.js";
|
|
4
|
+
import { t as queueErrorDiagnostics } from "../../error-diagnostics-Dv6nKZQW.js";
|
|
5
5
|
import { resolve } from "pathe";
|
|
6
|
-
|
|
6
|
+
// src/internal/runtime/local-client.ts
|
|
7
7
|
const engines = /* @__PURE__ */ new Map();
|
|
8
8
|
function getLocalQueueEngine({ base = defaultLocalQueueBase, development, rules = "local" }) {
|
|
9
9
|
const directory = resolve(base);
|
|
@@ -67,5 +67,4 @@ function closeLocalQueues() {
|
|
|
67
67
|
for (const { engine } of engines.values()) engine.close();
|
|
68
68
|
engines.clear();
|
|
69
69
|
}
|
|
70
|
-
//#endregion
|
|
71
70
|
export { closeLocalQueues, createLocalQueueRuntimeClient, getLocalQueueStatus, startLocalQueue, useLocalQueueEngine };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { b as QueueClient } from "../../types-
|
|
2
|
-
import "../../local-
|
|
3
|
-
import { n as QueueRuntimeOptions, t as QueueRuntimeDriverOptions } from "../../types-
|
|
1
|
+
import { b as QueueClient } from "../../types-BzPGPV9z.js";
|
|
2
|
+
import "../../local-B72WRWkS.js";
|
|
3
|
+
import { n as QueueRuntimeOptions, t as QueueRuntimeDriverOptions } from "../../types-BevEYrUV.js";
|
|
4
4
|
import postgres from "postgres";
|
|
5
|
-
//#region src/providers/postgres.d.ts
|
|
6
5
|
/** A postgres.js client. */
|
|
7
6
|
type PostgresQueueSql = postgres.Sql;
|
|
8
7
|
/**
|
|
@@ -14,8 +13,6 @@ type PostgresQueueConnection = {
|
|
|
14
13
|
} | {
|
|
15
14
|
url: string;
|
|
16
15
|
};
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region src/internal/runtime/postgres-client.d.ts
|
|
19
16
|
/** The Databases of the app, as `@vite-hub/database/drizzle` exports them. */
|
|
20
17
|
export type PostgresQueueDatabases = Readonly<Record<string, {
|
|
21
18
|
db: object;
|
|
@@ -24,12 +21,13 @@ export type PostgresQueueDatabases = Readonly<Record<string, {
|
|
|
24
21
|
export type PostgresQueueDatabasesLoader = () => Promise<PostgresQueueDatabases>;
|
|
25
22
|
interface ResolvedConnection {
|
|
26
23
|
connection: PostgresQueueConnection;
|
|
27
|
-
/** The URL, or the client of the Database. A Database can replace its client when its environment changes. */
|
|
28
24
|
key: object | string;
|
|
29
25
|
}
|
|
30
26
|
/**
|
|
31
27
|
* The connection of the jobs: `QUEUE_POSTGRES_URL` when it is set, else the postgres.js client of the Database that the
|
|
32
28
|
* build found on Postgres. The jobs then use the connection that the Database resolves, whatever variable it reads.
|
|
29
|
+
* Another driver, such as a node-postgres Pool, cannot run the jobs, so they get a postgres.js client on the connection
|
|
30
|
+
* URL of the Database.
|
|
33
31
|
*/
|
|
34
32
|
export declare function resolvePostgresQueueConnection(config: {
|
|
35
33
|
database?: string;
|
|
@@ -43,4 +41,4 @@ export declare function createPostgresQueueRuntimeClient(options: QueueRuntimeDr
|
|
|
43
41
|
export declare function startPostgresQueue(config: false | QueueRuntimeOptions, databases?: PostgresQueueDatabasesLoader): void;
|
|
44
42
|
/** Stops taking jobs, waits for the running jobs up to 10 seconds, and closes the connections it opened. The jobs stay. */
|
|
45
43
|
export declare function closePostgresQueues(): Promise<void>;
|
|
46
|
-
|
|
44
|
+
export {};
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { c as
|
|
4
|
-
import { r as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { r as postgresQueueUrlVariable } from "../../config-Bzp1xmdh.js";
|
|
2
|
+
import { t as invariant } from "../../invariant-CmdvZ3vp.js";
|
|
3
|
+
import { c as queueRemovedOptionsError, d as normalizeQueueEnqueueInput, l as queueUnsupportedOptionsError, s as queueProviderResult, t as readQueueTimes, u as createQueueMessageId } from "../../duration-C5w_-Rf4.js";
|
|
4
|
+
import { i as reportQueueDeliveryError, n as createQueueDeliveryErrorReport, r as isNonRetryableQueueError, t as checkQueueHandlerResponse } from "../../handler-response-CchTXVjm.js";
|
|
5
|
+
import { i as localQueueDeliveryRules, r as delayMs } from "../../local-RX10a_Sq.js";
|
|
6
|
+
import { c as loadQueueDefinition, l as missingQueueDefinitionError, p as setQueueRuntimeJobStore, s as listQueueDefinitionNames } from "../../state-DqxeV11k.js";
|
|
7
|
+
import { t as queueErrorDiagnostics } from "../../error-diagnostics-Dv6nKZQW.js";
|
|
8
8
|
import { hostname } from "node:os";
|
|
9
9
|
import { randomUUID } from "node:crypto";
|
|
10
10
|
import { runInRunScopes } from "@vite-hub/runtime/internal/run-scope";
|
|
11
11
|
import postgres from "postgres";
|
|
12
|
-
/** Jobs that `jobs()` lists at most. */
|
|
13
12
|
const listLimit = 1e3;
|
|
14
13
|
const identifier = /^[a-z_][a-z\d_]{0,62}$/;
|
|
15
14
|
/** Returns `true` for a postgres.js client, such as the `$client` of a Postgres Database. */
|
|
@@ -65,7 +64,6 @@ function createPostgresQueueEngine(options) {
|
|
|
65
64
|
let pumping;
|
|
66
65
|
let pumpAgain = false;
|
|
67
66
|
let closed = false;
|
|
68
|
-
/** Creates the table once per process. Concurrent cold starts wait for one transaction lock, so they do not race. */
|
|
69
67
|
function ensureTable() {
|
|
70
68
|
ready ??= (async () => {
|
|
71
69
|
try {
|
|
@@ -125,7 +123,6 @@ function createPostgresQueueEngine(options) {
|
|
|
125
123
|
concurrency.set(queue, value);
|
|
126
124
|
return value;
|
|
127
125
|
}
|
|
128
|
-
/** Takes due jobs while a Queue Definition has a free slot, and starts them. */
|
|
129
126
|
async function pump() {
|
|
130
127
|
let wait = pollIntervalMs;
|
|
131
128
|
try {
|
|
@@ -439,9 +436,10 @@ function createPostgresQueueClient(engine, queue, resolveEngine) {
|
|
|
439
436
|
}
|
|
440
437
|
};
|
|
441
438
|
}
|
|
442
|
-
|
|
443
|
-
//#region src/internal/runtime/postgres-client.ts
|
|
439
|
+
// src/internal/runtime/postgres-client.ts
|
|
444
440
|
const postgresUrl = /^postgres(?:ql)?:\/\//i;
|
|
441
|
+
/** A Postgres Database answers this key with a function that returns its connection URL. `@vite-hub/database` sets it. */
|
|
442
|
+
const databaseConnectionUrl = Symbol.for("vitehub.database.postgres.connection-url");
|
|
445
443
|
let loadDatabases;
|
|
446
444
|
let closing;
|
|
447
445
|
const engines = /* @__PURE__ */ new Map();
|
|
@@ -469,6 +467,8 @@ function startWorkers(state, engine) {
|
|
|
469
467
|
/**
|
|
470
468
|
* The connection of the jobs: `QUEUE_POSTGRES_URL` when it is set, else the postgres.js client of the Database that the
|
|
471
469
|
* build found on Postgres. The jobs then use the connection that the Database resolves, whatever variable it reads.
|
|
470
|
+
* Another driver, such as a node-postgres Pool, cannot run the jobs, so they get a postgres.js client on the connection
|
|
471
|
+
* URL of the Database.
|
|
472
472
|
*/
|
|
473
473
|
async function resolvePostgresQueueConnection(config, databases = loadDatabases, env = process.env) {
|
|
474
474
|
const url = env[postgresQueueUrlVariable]?.trim();
|
|
@@ -486,6 +486,12 @@ async function resolvePostgresQueueConnection(config, databases = loadDatabases,
|
|
|
486
486
|
connection: { client },
|
|
487
487
|
key: client
|
|
488
488
|
};
|
|
489
|
+
const readUrl = entry ? Reflect.get(entry.db, databaseConnectionUrl) : void 0;
|
|
490
|
+
const databaseUrl = typeof readUrl === "function" ? readUrl() : void 0;
|
|
491
|
+
if (typeof databaseUrl === "string") return {
|
|
492
|
+
connection: { url: databaseUrl },
|
|
493
|
+
key: databaseUrl
|
|
494
|
+
};
|
|
489
495
|
}
|
|
490
496
|
throw queueErrorDiagnostics.QUEUE_POSTGRES_MISSING_CONNECTION({ database: config.database });
|
|
491
497
|
}
|
|
@@ -566,5 +572,4 @@ function closePostgresQueues() {
|
|
|
566
572
|
});
|
|
567
573
|
return closing;
|
|
568
574
|
}
|
|
569
|
-
//#endregion
|
|
570
575
|
export { closePostgresQueues, createPostgresQueueRuntimeClient, resolvePostgresQueueConnection, startPostgresQueue };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { A as QueueJobStore, C as QueueDefinitionRegistry, b as QueueClient, x as QueueDefinition } from "../../types-
|
|
2
|
-
import { n as QueueRuntimeOptions, t as QueueRuntimeDriverOptions } from "../../types-
|
|
3
|
-
//#region src/internal/runtime/state.d.ts
|
|
1
|
+
import { A as QueueJobStore, C as QueueDefinitionRegistry, b as QueueClient, x as QueueDefinition } from "../../types-BzPGPV9z.js";
|
|
2
|
+
import { n as QueueRuntimeOptions, t as QueueRuntimeDriverOptions } from "../../types-BevEYrUV.js";
|
|
4
3
|
export type QueueRuntimeClientFactory = (options: QueueRuntimeDriverOptions) => QueueClient | Promise<QueueClient>;
|
|
5
4
|
export declare function missingQueueDefinitionError(queue: string): Error;
|
|
6
5
|
export declare function setQueueRuntimeConfig(config: false | QueueRuntimeOptions | undefined, createClient?: QueueRuntimeClientFactory): void;
|
|
@@ -20,5 +19,4 @@ export declare function setQueueRuntimeRegistry(registry: QueueDefinitionRegistr
|
|
|
20
19
|
/** The names of the Queue Definitions that this runtime loads, sorted. */
|
|
21
20
|
export declare function listQueueDefinitionNames(): string[];
|
|
22
21
|
export declare function getOrCreateQueueClient(name: string, createClient: () => Promise<QueueClient>): Promise<QueueClient>;
|
|
23
|
-
export declare function loadQueueDefinition(name: string): Promise<QueueDefinition | undefined>;
|
|
24
|
-
//#endregion
|
|
22
|
+
export declare function loadQueueDefinition(name: string): Promise<QueueDefinition | undefined>;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { enterQueueRuntimeEvent, getOrCreateQueueClient, getQueueRuntimeClientFactory, getQueueRuntimeConfig, getQueueRuntimeEvent, getQueueRuntimeJobStore, listQueueDefinitionNames, loadQueueDefinition, missingQueueDefinitionError, runWithQueueRuntimeEvent, setQueueRuntimeConfig, setQueueRuntimeEventDefaults, setQueueRuntimeJobStore, setQueueRuntimeRegistry };
|
|
1
|
+
export { t as enterQueueRuntimeEvent, n as getOrCreateQueueClient, r as getQueueRuntimeClientFactory, i as getQueueRuntimeConfig, a as getQueueRuntimeEvent, o as getQueueRuntimeJobStore, s as listQueueDefinitionNames, c as loadQueueDefinition, l as missingQueueDefinitionError, u as runWithQueueRuntimeEvent, d as setQueueRuntimeConfig, f as setQueueRuntimeEventDefaults, p as setQueueRuntimeJobStore, m as setQueueRuntimeRegistry } from "../../state-DqxeV11k.js";
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
import { T as QueueDriverOptions, b as QueueClient } from "../../types-
|
|
2
|
-
|
|
3
|
-
export declare function createVercelQueueRuntimeClient(options: QueueDriverOptions): Promise<QueueClient>;
|
|
4
|
-
//#endregion
|
|
1
|
+
import { T as QueueDriverOptions, b as QueueClient } from "../../types-BzPGPV9z.js";
|
|
2
|
+
export declare function createVercelQueueRuntimeClient(options: QueueDriverOptions): Promise<QueueClient>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
3
|
-
import { t as resolveVercelQueueRegion } from "../../vercel-region-
|
|
4
|
-
|
|
1
|
+
import { c as queueRemovedOptionsError, d as normalizeQueueEnqueueInput, l as queueUnsupportedOptionsError, s as queueProviderResult, t as readQueueTimes, u as createQueueMessageId } from "../../duration-C5w_-Rf4.js";
|
|
2
|
+
import { t as queueErrorDiagnostics } from "../../error-diagnostics-Dv6nKZQW.js";
|
|
3
|
+
import { t as resolveVercelQueueRegion } from "../../vercel-region-DEsR1YJQ.js";
|
|
4
|
+
// src/providers/vercel.ts
|
|
5
5
|
function invalidVercelSendResponse(cause) {
|
|
6
6
|
return [queueErrorDiagnostics.QUEUE_PROVIDER_INVALID_RESPONSE({ cause }), void 0];
|
|
7
7
|
}
|
|
@@ -48,7 +48,6 @@ function isVercelQueueSDK(value) {
|
|
|
48
48
|
};
|
|
49
49
|
return hasCallableMethod("send") && hasCallableMethod("handleCallback");
|
|
50
50
|
}
|
|
51
|
-
/** The cause of `QUEUE_PROVIDER_FAILED` when Vercel rejects jobs of a batch. `results` has each job's result in input order. */
|
|
52
51
|
function batchRejected(results) {
|
|
53
52
|
const failed = results.filter((result) => result.status === "failed").length;
|
|
54
53
|
return Object.assign(queueErrorDiagnostics.QUEUE_VERCEL_BATCH_REJECTED({
|
|
@@ -170,8 +169,7 @@ async function createVercelQueueClient(provider) {
|
|
|
170
169
|
callback: client.handleCallback.bind(client)
|
|
171
170
|
};
|
|
172
171
|
}
|
|
173
|
-
|
|
174
|
-
//#region src/internal/runtime/vercel-client.ts
|
|
172
|
+
// src/internal/runtime/vercel-client.ts
|
|
175
173
|
async function createVercelQueueRuntimeClient(options) {
|
|
176
174
|
if (options.driver !== "vercel") throw queueErrorDiagnostics.QUEUE_DRIVER_MISMATCH({
|
|
177
175
|
driver: options.driver,
|
|
@@ -179,5 +177,4 @@ async function createVercelQueueRuntimeClient(options) {
|
|
|
179
177
|
});
|
|
180
178
|
return await createVercelQueueClient(options);
|
|
181
179
|
}
|
|
182
|
-
//#endregion
|
|
183
180
|
export { createVercelQueueRuntimeClient };
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { b as QueueClient } from "../../types-
|
|
2
|
-
import { t as QueueRuntimeDriverOptions } from "../../types-
|
|
3
|
-
//#region src/internal/runtime/worker-client.d.ts
|
|
1
|
+
import { b as QueueClient } from "../../types-BzPGPV9z.js";
|
|
2
|
+
import { t as QueueRuntimeDriverOptions } from "../../types-BevEYrUV.js";
|
|
4
3
|
/** Worker package conditions keep the Node driver and its optional peer outside the build graph. */
|
|
5
|
-
export declare function createPostgresQueueRuntimeClient(options: QueueRuntimeDriverOptions): Promise<QueueClient>;
|
|
6
|
-
//#endregion
|
|
4
|
+
export declare function createPostgresQueueRuntimeClient(options: QueueRuntimeDriverOptions): Promise<QueueClient>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as queueErrorDiagnostics } from "../../error-diagnostics-
|
|
2
|
-
|
|
1
|
+
import { t as queueErrorDiagnostics } from "../../error-diagnostics-Dv6nKZQW.js";
|
|
2
|
+
// src/internal/runtime/worker-client.ts
|
|
3
3
|
/** Worker package conditions keep the Node driver and its optional peer outside the build graph. */
|
|
4
4
|
async function createPostgresQueueRuntimeClient(options) {
|
|
5
5
|
throw queueErrorDiagnostics.QUEUE_DRIVER_MISMATCH({
|
|
@@ -7,5 +7,4 @@ async function createPostgresQueueRuntimeClient(options) {
|
|
|
7
7
|
expected: "cloudflare"
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
|
-
//#endregion
|
|
11
10
|
export { createPostgresQueueRuntimeClient };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineDiagnostics } from "nostics";
|
|
2
|
-
|
|
2
|
+
// ../internal/src/invariant.ts
|
|
3
3
|
const invariantDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
4
4
|
docsBase: "https://vitehub.dev/docs/development/diagnostics",
|
|
5
5
|
codes: { INTERNAL_INVARIANT_FAILED: {
|
|
@@ -18,5 +18,4 @@ function invariantError(what) {
|
|
|
18
18
|
function invariant(condition, what) {
|
|
19
19
|
if (!condition) throw invariantError(what);
|
|
20
20
|
}
|
|
21
|
-
//#endregion
|
|
22
21
|
export { invariant as t };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { A as QueueJobStore } from "./types-
|
|
2
|
-
//#region src/providers/local.d.ts
|
|
1
|
+
import { A as QueueJobStore } from "./types-BzPGPV9z.js";
|
|
3
2
|
/** One job for the engine. `vite dev` and the clients read `delay` and `retention` into seconds first. */
|
|
4
3
|
interface LocalQueueEntry {
|
|
5
4
|
delaySeconds?: number;
|
|
@@ -19,5 +18,4 @@ interface LocalQueueEngine extends QueueJobStore {
|
|
|
19
18
|
/** Reads the stored jobs and starts their delivery. Later calls return the same promise. */
|
|
20
19
|
start: () => Promise<void>;
|
|
21
20
|
}
|
|
22
|
-
//#endregion
|
|
23
21
|
export { LocalQueueEngine as t };
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
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-C5w_-Rf4.js";
|
|
2
|
+
import { i as reportQueueDeliveryError, n as createQueueDeliveryErrorReport, r as isNonRetryableQueueError, t as checkQueueHandlerResponse } from "./handler-response-CchTXVjm.js";
|
|
3
|
+
import { t as queueErrorDiagnostics } from "./error-diagnostics-Dv6nKZQW.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
|
}
|
|
@@ -549,5 +555,4 @@ function createLocalQueueClient(engine, queue) {
|
|
|
549
555
|
}
|
|
550
556
|
};
|
|
551
557
|
}
|
|
552
|
-
//#endregion
|
|
553
558
|
export { localQueueDeliveryRules as i, createLocalQueueEngine as n, delayMs as r, createLocalQueueClient as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// ../internal/src/object.ts
|
|
2
2
|
/** A non-null object that is not an array. Functions do not pass. */
|
|
3
3
|
function isRecord(value) {
|
|
4
4
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -11,5 +11,4 @@ function isRecordOrFunction(value) {
|
|
|
11
11
|
function cloneRecord(value) {
|
|
12
12
|
return value && typeof value === "object" && !Array.isArray(value) ? { ...value } : {};
|
|
13
13
|
}
|
|
14
|
-
//#endregion
|
|
15
14
|
export { isRecord as n, isRecordOrFunction as r, cloneRecord as t };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/@standard-schema+spec@1.1.0/node_modules/@standard-schema/spec/dist/index.d.ts
|
|
2
1
|
/** The Standard Typed interface. This is a base type extended by other specs. */
|
|
3
2
|
interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
4
3
|
/** The Standard properties. */
|
|
@@ -74,8 +73,6 @@ declare namespace StandardSchemaV1 {
|
|
|
74
73
|
/** Infers the output type of a Standard. */
|
|
75
74
|
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
76
75
|
}
|
|
77
|
-
//#endregion
|
|
78
|
-
//#region ../internal/src/operation-definition.d.ts
|
|
79
76
|
/** `read` never changes state. `write` changes state. `destructive` deletes or publishes. */
|
|
80
77
|
type OperationKind = "read" | "write" | "destructive";
|
|
81
78
|
/** The signed-in user of a call. */
|
|
@@ -104,6 +101,11 @@ interface OperationAccess {
|
|
|
104
101
|
*/
|
|
105
102
|
readonly sections: "all" | readonly string[];
|
|
106
103
|
readonly user?: OperationUser;
|
|
104
|
+
/**
|
|
105
|
+
* Who signed the call: `"console"` when the ViteHub Console signed it for a person, whose `user` is then a Console
|
|
106
|
+
* account and not an app user, or `"cli"` for a key. Not set for other calls.
|
|
107
|
+
*/
|
|
108
|
+
readonly via?: "console" | "cli";
|
|
107
109
|
}
|
|
108
110
|
interface OperationContext {
|
|
109
111
|
/** The checked Console access of the call. */
|
|
@@ -166,7 +168,8 @@ interface OperationDefinition<Input, Output> {
|
|
|
166
168
|
/** Standard Schema (valibot in this repo). Its Standard JSON Schema builds CLI flags and the MCP input schema. */
|
|
167
169
|
input: StandardSchemaV1<unknown, Input>;
|
|
168
170
|
output?: StandardSchemaV1<unknown, Output>;
|
|
169
|
-
|
|
171
|
+
/** `false`: no `vitehub` command. The Console and MCP still call the operation. */
|
|
172
|
+
cli?: false | {
|
|
170
173
|
/** Defaults: namespace = section, command = verb. */
|
|
171
174
|
namespace?: string;
|
|
172
175
|
/** A space groups commands: `jobs list` and `jobs show` run as `vitehub <namespace> jobs list` and `jobs show`. */
|
|
@@ -207,7 +210,7 @@ interface OperationDefinition<Input, Output> {
|
|
|
207
210
|
/** An operation of any input and output, as a registry holds it. */
|
|
208
211
|
interface AnyOperation extends Omit<OperationDefinition<unknown, unknown>, "cli" | "input" | "mcp" | "output" | "readOnlyWhen" | "run" | "scope" | "section"> {
|
|
209
212
|
readOnlyWhen?: (input: never) => boolean;
|
|
210
|
-
cli?: {
|
|
213
|
+
cli?: false | {
|
|
211
214
|
namespace?: string;
|
|
212
215
|
command?: string;
|
|
213
216
|
default?: boolean;
|
|
@@ -235,5 +238,4 @@ interface OperationContributionEntry {
|
|
|
235
238
|
/** `false`: the app already has these operations at runtime. Only tools such as the CLI and `vitehub inspect` read the entry. */
|
|
236
239
|
runtime?: false;
|
|
237
240
|
}
|
|
238
|
-
//#endregion
|
|
239
241
|
export { OperationContributionEntry as n, AnyOperation as t };
|