@vite-hub/queue 0.1.0 → 0.4.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 +152 -29
- package/dist/client-B53_G4ky.js +182 -0
- package/dist/{cloudflare-client-COzQ8fHk.js → cloudflare-client-CoISDpIx.js} +28 -21
- package/dist/{cloudflare-resource-name-CCuLDvSP.js → cloudflare-resource-name-BIfBglC2.js} +1 -1
- package/dist/config-B2eaXaT5.js +105 -0
- package/dist/durability.d.ts +13 -0
- package/dist/durability.js +47 -0
- package/dist/duration-tujyhAKt.js +111 -0
- package/dist/error-diagnostics-CQ4BUqRe.js +270 -0
- package/dist/error-diagnostics-mJXBjmQx.js +181 -0
- package/dist/{handler-response-CBwIkmTS.js → handler-response-B6lz9nCn.js} +9 -4
- package/dist/index.d.ts +20 -32
- package/dist/index.js +39 -17
- package/dist/internal/runtime/cloudflare-client.d.ts +2 -2
- package/dist/internal/runtime/cloudflare-client.js +1 -1
- package/dist/internal/runtime/cloudflare-vite.d.ts +30 -2
- package/dist/internal/runtime/cloudflare-vite.js +111 -1
- package/dist/internal/runtime/local-client.d.ts +17 -0
- package/dist/internal/runtime/local-client.js +71 -0
- package/dist/internal/runtime/postgres-client.d.ts +46 -0
- package/dist/internal/runtime/postgres-client.js +570 -0
- package/dist/internal/runtime/state.d.ts +11 -4
- package/dist/internal/runtime/state.js +2 -2
- package/dist/internal/runtime/vercel-client.d.ts +2 -2
- package/dist/internal/runtime/vercel-client.js +66 -28
- package/dist/internal/runtime/worker-client.d.ts +6 -0
- package/dist/internal/runtime/worker-client.js +11 -0
- package/dist/invariant-D8_xBqmZ.js +22 -0
- package/dist/local-CUaWoRUx.d.ts +23 -0
- package/dist/local-Di0FrVUw.js +553 -0
- package/dist/object-D8pRdprI.js +15 -0
- package/dist/{operations-tNUdj3G4.d.ts → operation-definition-nmRu_O3V.d.ts} +42 -15
- package/dist/operations-BVV-9Q0N.js +129 -0
- package/dist/operations.d.ts +47 -9
- package/dist/operations.js +186 -69
- package/dist/runtime/hosted.d.ts +3 -5
- package/dist/runtime/hosted.js +21 -45
- package/dist/{state-G9s378-e.js → state-DLqTqF6V.js} +59 -47
- package/dist/types-CiuSIPR0.d.ts +440 -0
- package/dist/types-Dsbb_Pvp.d.ts +10 -0
- package/dist/vercel-region-B95MAMXN.js +26 -0
- package/dist/virtual.d.ts +4 -0
- package/dist/vite.d.ts +366 -49
- package/dist/vite.js +2071 -2
- package/package.json +39 -46
- package/dist/client-CIc3jsj2.js +0 -114
- package/dist/cloudflare-vite-BCuJOXcT.js +0 -111
- package/dist/cloudflare-vite-CjdP5yBN.d.ts +0 -29
- package/dist/config-BINujLv4.js +0 -74
- package/dist/enqueue-CnQ0QR3O.js +0 -22
- package/dist/error-diagnostics-A_8Kp-48.js +0 -116
- package/dist/error-diagnostics-qzRF6IVB.js +0 -109
- package/dist/errors-DIFaM9tW.js +0 -42
- package/dist/nuxt.d.ts +0 -39
- package/dist/nuxt.js +0 -34
- package/dist/object-B1NW521B.js +0 -7
- package/dist/operations-Cnjbz8kk.js +0 -63
- package/dist/types-1GRMYES1.d.ts +0 -180
- package/dist/vercel-region-cjskrOKl.js +0 -122
- package/dist/vite-ChWLzOVu.js +0 -1512
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { t as queueErrorDiagnostics } from "./error-diagnostics-mJXBjmQx.js";
|
|
2
|
+
import { a as normalizePublicQueueIdentifier, r as isQueueError } from "./duration-tujyhAKt.js";
|
|
3
|
+
import { i as getQueueRuntimeConfig, o as getQueueRuntimeJobStore, s as listQueueDefinitionNames } from "./state-DLqTqF6V.js";
|
|
4
|
+
import { n as dynamicQueue } from "./client-B53_G4ky.js";
|
|
5
|
+
import { t as redactInspectionText } from "./inspect-PeuckaC3.js";
|
|
6
|
+
import { runtimeErrorDiagnostics } from "@vite-hub/runtime";
|
|
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
|
+
const statuses = {
|
|
10
|
+
QUEUE_DEFINITION_NAME_INVALID: 400,
|
|
11
|
+
QUEUE_DEFINITION_NOT_FOUND: 404,
|
|
12
|
+
QUEUE_DISABLED: 409,
|
|
13
|
+
QUEUE_JOB_DUPLICATE: 409,
|
|
14
|
+
QUEUE_JOBS_UNAVAILABLE: 409,
|
|
15
|
+
QUEUE_JOB_NOT_FOUND: 404,
|
|
16
|
+
QUEUE_JOB_RUNNING: 409,
|
|
17
|
+
QUEUE_PROVIDER_FAILED: 502,
|
|
18
|
+
QUEUE_PROVIDER_INVALID_RESPONSE: 502,
|
|
19
|
+
QUEUE_UNSUPPORTED_OPTION: 400
|
|
20
|
+
};
|
|
21
|
+
/** Gives a Queue catalog error the status and the redacted message that the CLI and the Console report. */
|
|
22
|
+
function failure(error) {
|
|
23
|
+
if (runtimeErrorDiagnostics.RUNTIME_DURATION_INVALID.is(error)) return Object.assign(error, {
|
|
24
|
+
status: 400,
|
|
25
|
+
statusMessage: redactInspectionText(error.message)
|
|
26
|
+
});
|
|
27
|
+
if (!isQueueError(error)) return error;
|
|
28
|
+
return Object.assign(error, {
|
|
29
|
+
status: statuses[error.code] ?? 500,
|
|
30
|
+
statusMessage: redactInspectionText(error.message)
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async function listQueues() {
|
|
34
|
+
const config = getQueueRuntimeConfig();
|
|
35
|
+
if (config === false) throw failure(queueErrorDiagnostics.QUEUE_DISABLED());
|
|
36
|
+
const names = listQueueDefinitionNames();
|
|
37
|
+
if (config?.driver === "local" || config?.driver === "postgres") {
|
|
38
|
+
const status = config.driver === "postgres" ? await (await getQueueRuntimeJobStore())?.status() : await (await import("./internal/runtime/local-client.js")).getLocalQueueStatus(config);
|
|
39
|
+
if (status) {
|
|
40
|
+
const empty = {
|
|
41
|
+
dead: 0,
|
|
42
|
+
pending: 0,
|
|
43
|
+
running: 0
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
provider: config.driver,
|
|
47
|
+
...config.driver === "local" && config.rules && config.rules !== "local" ? { rules: config.rules } : {},
|
|
48
|
+
queues: names.map((name) => ({
|
|
49
|
+
name,
|
|
50
|
+
...empty,
|
|
51
|
+
...status.queues[name]
|
|
52
|
+
})),
|
|
53
|
+
storage: {
|
|
54
|
+
base: status.base,
|
|
55
|
+
deadLimit: status.deadLimit,
|
|
56
|
+
durability: status.durability
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
...config ? { provider: config.driver } : {},
|
|
63
|
+
queues: names.map((name) => ({ name }))
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
async function sendToQueue(input) {
|
|
67
|
+
const queue = normalizePublicQueueIdentifier(input.queue);
|
|
68
|
+
if (!queue) throw failure(queueErrorDiagnostics.QUEUE_DEFINITION_NAME_INVALID());
|
|
69
|
+
const options = {
|
|
70
|
+
...input.delay === void 0 ? {} : { delay: input.delay },
|
|
71
|
+
...input.idempotencyKey === void 0 ? {} : { idempotencyKey: input.idempotencyKey }
|
|
72
|
+
};
|
|
73
|
+
let result;
|
|
74
|
+
try {
|
|
75
|
+
result = await dynamicQueue.send(queue, input.payload, options);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
throw failure(error);
|
|
78
|
+
}
|
|
79
|
+
const [error, sent] = result;
|
|
80
|
+
if (error) throw failure(error);
|
|
81
|
+
const config = getQueueRuntimeConfig();
|
|
82
|
+
return {
|
|
83
|
+
...sent?.messageId ? { messageId: sent.messageId } : {},
|
|
84
|
+
...config ? { provider: config.driver } : {},
|
|
85
|
+
queue,
|
|
86
|
+
status: "queued"
|
|
87
|
+
};
|
|
88
|
+
}
|
|
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
|
+
async function localJobs() {
|
|
94
|
+
const config = getQueueRuntimeConfig();
|
|
95
|
+
if (config === false) throw failure(queueErrorDiagnostics.QUEUE_DISABLED());
|
|
96
|
+
const store = config?.driver === "postgres" ? await getQueueRuntimeJobStore() : config ? (await import("./internal/runtime/local-client.js")).useLocalQueueEngine(config) : void 0;
|
|
97
|
+
if (!store) throw failure(queueErrorDiagnostics.QUEUE_JOBS_UNAVAILABLE({ driver: config?.driver ?? "configured" }));
|
|
98
|
+
return store;
|
|
99
|
+
}
|
|
100
|
+
function jobNotFound() {
|
|
101
|
+
return failure(queueErrorDiagnostics.QUEUE_JOB_NOT_FOUND());
|
|
102
|
+
}
|
|
103
|
+
async function listQueueJobs(input) {
|
|
104
|
+
const engine = await localJobs();
|
|
105
|
+
const jobs = (await engine.jobs(input)).filter((job) => (input.queue === void 0 || job.queue === input.queue) && (input.state === void 0 || job.state === input.state));
|
|
106
|
+
return {
|
|
107
|
+
base: engine.base,
|
|
108
|
+
jobs,
|
|
109
|
+
provider: engine.provider,
|
|
110
|
+
rules: engine.rules.rules
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
async function showQueueJob(id) {
|
|
114
|
+
const job = await (await localJobs()).job(id);
|
|
115
|
+
if (!job) throw jobNotFound();
|
|
116
|
+
return { job };
|
|
117
|
+
}
|
|
118
|
+
async function retryQueueJob(id) {
|
|
119
|
+
const result = await (await localJobs()).retry(id);
|
|
120
|
+
if (result === "missing") throw jobNotFound();
|
|
121
|
+
if (result === "running") throw failure(queueErrorDiagnostics.QUEUE_JOB_RUNNING());
|
|
122
|
+
if (result === "duplicate") throw failure(queueErrorDiagnostics.QUEUE_JOB_DUPLICATE());
|
|
123
|
+
return { job: result };
|
|
124
|
+
}
|
|
125
|
+
async function clearQueueJobs(input) {
|
|
126
|
+
return { cleared: await (await localJobs()).clear(input) };
|
|
127
|
+
}
|
|
128
|
+
//#endregion
|
|
129
|
+
export { clearQueueJobs, listQueueJobs, listQueues, retryQueueJob, sendToQueue, showQueueJob };
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,22 +1,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { A as QueueJobStore, d as LocalQueueJob, f as LocalQueueJobDetail, h as LocalQueueStatus, p as LocalQueueRules, w as QueueDriver } from "./types-CiuSIPR0.js";
|
|
2
|
+
import "./local-CUaWoRUx.js";
|
|
3
|
+
import { t as AnyOperation } from "./operation-definition-nmRu_O3V.js";
|
|
3
4
|
//#region src/runtime/operations.d.ts
|
|
4
5
|
interface QueueListResult {
|
|
5
6
|
/** `undefined` when the runtime has not installed a Queue configuration. */
|
|
6
|
-
provider?:
|
|
7
|
+
provider?: QueueDriver;
|
|
8
|
+
/** The local provider only: the provider whose delivery rules the jobs follow. In `vite dev`, the provider of the build. */
|
|
9
|
+
rules?: LocalQueueRules;
|
|
10
|
+
/**
|
|
11
|
+
* The local and postgres providers only: where the jobs are and what survives. `single-host` jobs survive a restart
|
|
12
|
+
* on this host, but not a move to another host or a new container. `shared` jobs are in Postgres, and every
|
|
13
|
+
* instance of the app runs them.
|
|
14
|
+
*/
|
|
15
|
+
storage?: {
|
|
16
|
+
base: string;
|
|
17
|
+
deadLimit: number;
|
|
18
|
+
durability: LocalQueueStatus["durability"];
|
|
19
|
+
};
|
|
20
|
+
/** `dead`, `pending`, and `running` are job counts of the local and postgres providers. Hosted providers do not report a backlog. */
|
|
7
21
|
queues: Array<{
|
|
22
|
+
dead?: number;
|
|
8
23
|
name: string;
|
|
24
|
+
pending?: number;
|
|
25
|
+
running?: number;
|
|
9
26
|
}>;
|
|
10
27
|
}
|
|
28
|
+
interface QueueJobsListInput {
|
|
29
|
+
queue?: string;
|
|
30
|
+
state?: LocalQueueJob["state"];
|
|
31
|
+
}
|
|
32
|
+
interface QueueJobsListResult {
|
|
33
|
+
/** Absolute directory of the local provider, or the Postgres table and database, without the password. */
|
|
34
|
+
base: string;
|
|
35
|
+
/**
|
|
36
|
+
* Stored jobs, newest first. Completed jobs are deleted, so the list has pending, running, and dead jobs. The
|
|
37
|
+
* postgres provider lists at most 1,000 jobs.
|
|
38
|
+
*/
|
|
39
|
+
jobs: LocalQueueJob[];
|
|
40
|
+
provider: QueueJobStore["provider"];
|
|
41
|
+
/** The provider whose delivery rules the jobs follow. */
|
|
42
|
+
rules: LocalQueueRules;
|
|
43
|
+
}
|
|
44
|
+
interface QueueJobsClearInput {
|
|
45
|
+
queue?: string;
|
|
46
|
+
state?: "dead" | "pending";
|
|
47
|
+
}
|
|
11
48
|
interface QueueSendOperationResult {
|
|
12
49
|
messageId?: string;
|
|
13
|
-
provider?:
|
|
50
|
+
provider?: QueueDriver;
|
|
14
51
|
queue: string;
|
|
15
52
|
status: "queued";
|
|
16
53
|
}
|
|
17
54
|
interface QueueSendOperationInput {
|
|
18
|
-
|
|
19
|
-
|
|
55
|
+
/** Time before delivery, such as `"1m"`. The send reads it, and a wrong one fails with `RUNTIME_DURATION_INVALID`. */
|
|
56
|
+
delay?: string;
|
|
20
57
|
idempotencyKey?: string;
|
|
21
58
|
payload: unknown;
|
|
22
59
|
queue: string;
|
|
@@ -24,9 +61,10 @@ interface QueueSendOperationInput {
|
|
|
24
61
|
//#endregion
|
|
25
62
|
//#region src/operations.d.ts
|
|
26
63
|
/**
|
|
27
|
-
* The `queue.*` operations: list and send
|
|
28
|
-
*
|
|
64
|
+
* The `queue.*` operations: list and send, and the stored jobs of the local and postgres providers. `vite dev` runs
|
|
65
|
+
* every job with the local provider. Cloudflare and Vercel do not let a producer read their queue, so the job
|
|
66
|
+
* operations fail there.
|
|
29
67
|
*/
|
|
30
68
|
export declare const queueOperations: readonly AnyOperation[];
|
|
31
69
|
//#endregion
|
|
32
|
-
export type { QueueListResult, QueueSendOperationInput, QueueSendOperationResult };
|
|
70
|
+
export type { LocalQueueJob, LocalQueueJobDetail, QueueJobsClearInput, QueueJobsListInput, QueueJobsListResult, QueueListResult, QueueSendOperationInput, QueueSendOperationResult };
|
package/dist/operations.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as isRecordOrFunction } from "./object-D8pRdprI.js";
|
|
2
|
+
import { t as internalErrorDiagnostics } from "./error-diagnostics-CQ4BUqRe.js";
|
|
2
3
|
//#region ../internal/src/standard-schema.ts
|
|
3
4
|
function readOwn(value, key) {
|
|
4
5
|
if (value === null || Object(value) !== value) return;
|
|
@@ -8,9 +9,6 @@ function readOwn(value, key) {
|
|
|
8
9
|
return;
|
|
9
10
|
}
|
|
10
11
|
}
|
|
11
|
-
function isRecord(value) {
|
|
12
|
-
return value !== null && Object(value) === value && !Array.isArray(value);
|
|
13
|
-
}
|
|
14
12
|
/**
|
|
15
13
|
* Read a Standard JSON Schema projection without throwing.
|
|
16
14
|
*
|
|
@@ -26,7 +24,7 @@ function standardJsonSchema(schema, direction, target = "draft-2020-12", library
|
|
|
26
24
|
target,
|
|
27
25
|
libraryOptions
|
|
28
26
|
} : { target });
|
|
29
|
-
return
|
|
27
|
+
return isRecordOrFunction(result) ? result : void 0;
|
|
30
28
|
} catch {
|
|
31
29
|
return;
|
|
32
30
|
}
|
|
@@ -738,7 +736,7 @@ function withValibotJsonSchema(schema, options = {}) {
|
|
|
738
736
|
if (Object.hasOwn(standard, "jsonSchema") && standard.jsonSchema) return schema;
|
|
739
737
|
const convert = (typeMode) => (request) => {
|
|
740
738
|
const target = options.target ?? request.target;
|
|
741
|
-
if (!isValibotTarget(target)) throw
|
|
739
|
+
if (!isValibotTarget(target)) throw internalErrorDiagnostics.INTERNAL_VALIBOT_JSON_SCHEMA_TARGET_UNSUPPORTED({ target: String(target) });
|
|
742
740
|
return toJsonSchema(schema, {
|
|
743
741
|
target,
|
|
744
742
|
typeMode,
|
|
@@ -757,33 +755,33 @@ function withValibotJsonSchema(schema, options = {}) {
|
|
|
757
755
|
};
|
|
758
756
|
}
|
|
759
757
|
//#endregion
|
|
760
|
-
//#region ../internal/src/
|
|
758
|
+
//#region ../internal/src/operation-definition.ts
|
|
761
759
|
const nameFormat = /^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*$/;
|
|
762
760
|
const kinds = /* @__PURE__ */ new Set([
|
|
763
761
|
"read",
|
|
764
762
|
"write",
|
|
765
763
|
"destructive"
|
|
766
764
|
]);
|
|
767
|
-
function isObject(value) {
|
|
768
|
-
return value !== null && Object(value) === value && !Array.isArray(value);
|
|
769
|
-
}
|
|
770
765
|
function invalidDefinition(name, reason) {
|
|
771
766
|
return internalErrorDiagnostics.INTERNAL_R0020({ message: `[vitehub] Operation ${JSON.stringify(name)} is invalid: ${reason}` });
|
|
772
767
|
}
|
|
773
768
|
function checkDefinition(definition) {
|
|
774
|
-
if (!
|
|
769
|
+
if (!isRecordOrFunction(definition)) throw invalidDefinition(void 0, "defineOperation() takes an object.");
|
|
775
770
|
const { name } = definition;
|
|
776
771
|
if (String(name) !== name || !nameFormat.test(name)) throw invalidDefinition(name, "the name must look like `section.verb`, in lower case.");
|
|
777
772
|
if (String(definition.description) !== definition.description || !definition.description) throw invalidDefinition(name, "add a one sentence description.");
|
|
778
773
|
const { section } = definition;
|
|
779
|
-
if (section !== false && !(section instanceof Function) && (
|
|
774
|
+
if (section !== false && !(section instanceof Function) && !isSectionId(section)) throw invalidDefinition(name, "section must be a Console section id, a function, or false; section ids cannot contain ':'.");
|
|
775
|
+
if (definition.scope !== void 0 && (!(definition.scope instanceof Function) || String(section) !== section)) throw invalidDefinition(name, "scope must be a function, and it needs a section id.");
|
|
780
776
|
if (!kinds.has(String(definition.kind))) throw invalidDefinition(name, "kind must be \"read\", \"write\", or \"destructive\".");
|
|
781
777
|
const input = definition.input;
|
|
782
|
-
if (!
|
|
778
|
+
if (!isRecordOrFunction(input) || !isRecordOrFunction(input["~standard"]) || !(input["~standard"].validate instanceof Function)) throw invalidDefinition(name, "input must be a Standard Schema, such as a valibot object.");
|
|
783
779
|
if (!(definition.run instanceof Function)) throw invalidDefinition(name, "run must be a function.");
|
|
784
780
|
const { maxRequestBytes } = definition;
|
|
785
781
|
if (maxRequestBytes !== void 0 && (!Number.isInteger(maxRequestBytes) || Number(maxRequestBytes) < 65536)) throw invalidDefinition(name, `maxRequestBytes can only raise the limit above ${defaultRequestBytes} bytes (64 KiB).`);
|
|
786
782
|
if (definition.readOnlyWhen !== void 0 && !(definition.readOnlyWhen instanceof Function)) throw invalidDefinition(name, "readOnlyWhen must be a function.");
|
|
783
|
+
const { mcp } = definition;
|
|
784
|
+
if (mcp !== void 0 && mcp !== false && (!isRecordOrFunction(mcp) || mcp.title !== void 0 && (String(mcp.title) !== mcp.title || !mcp.title) || mcp.format !== void 0 && !(mcp.format instanceof Function))) throw invalidDefinition(name, "mcp must be false, or an object with a title string and a format function.");
|
|
787
785
|
}
|
|
788
786
|
/** The default limit of a call, in bytes. */
|
|
789
787
|
const defaultRequestBytes = 65536;
|
|
@@ -806,14 +804,24 @@ function defineOperation(definition) {
|
|
|
806
804
|
input: withValibotJsonSchema(definition.input)
|
|
807
805
|
};
|
|
808
806
|
const properties = operationInputJsonSchema(defined).properties;
|
|
809
|
-
const clashes =
|
|
807
|
+
const clashes = isRecordOrFunction(properties) ? Object.keys(properties).filter((key) => reservedOperationFlags.includes(key)) : [];
|
|
810
808
|
if (clashes.length) throw invalidDefinition(definition.name, `the input key ${clashes.map((key) => JSON.stringify(key)).join(", ")} is a CLI flag of every command (${reservedOperationFlags.join(", ")}). Rename it.`);
|
|
811
809
|
return defined;
|
|
812
810
|
}
|
|
811
|
+
function isSectionId(section) {
|
|
812
|
+
return typeof section === "string" && section !== "" && !section.includes(":");
|
|
813
|
+
}
|
|
813
814
|
/** JSON Schema of the input, for CLI flags and MCP tool schemas. Falls back to an open object. */
|
|
814
815
|
function operationInputJsonSchema(operation) {
|
|
815
816
|
return standardJsonSchema(operation.input, "input") ?? { type: "object" };
|
|
816
817
|
}
|
|
818
|
+
//#endregion
|
|
819
|
+
//#region ../internal/src/operations.ts
|
|
820
|
+
/** Align rows of text cells in columns for CLI output. The last column is not padded. */
|
|
821
|
+
function table(rows) {
|
|
822
|
+
const widths = rows[0].map((_, column) => Math.max(...rows.map((row) => row[column].length)));
|
|
823
|
+
return rows.map((row) => row.map((cell, column) => column === row.length - 1 ? cell : cell.padEnd(widths[column])).join(" ")).join("\n");
|
|
824
|
+
}
|
|
817
825
|
const DEFAULT_CONFIG = {
|
|
818
826
|
lang: void 0,
|
|
819
827
|
message: void 0,
|
|
@@ -891,6 +899,22 @@ function _addIssue(context, label, dataset, config$1, other) {
|
|
|
891
899
|
else dataset.issues = [issue];
|
|
892
900
|
}
|
|
893
901
|
/**
|
|
902
|
+
* Joins multiple `expects` values with the given separator.
|
|
903
|
+
*
|
|
904
|
+
* @param values The `expects` values.
|
|
905
|
+
* @param separator The separator.
|
|
906
|
+
*
|
|
907
|
+
* @returns The joined `expects` property.
|
|
908
|
+
*
|
|
909
|
+
* @internal
|
|
910
|
+
*/
|
|
911
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
912
|
+
function _joinExpects(values$1, separator) {
|
|
913
|
+
const list = [...new Set(values$1)];
|
|
914
|
+
if (list.length > 1) return `(${list.join(` ${separator} `)})`;
|
|
915
|
+
return list[0] ?? "never";
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
894
918
|
* Eagerly creates and attaches the Standard Schema properties of a schema.
|
|
895
919
|
*
|
|
896
920
|
* Hint: The contextual `this` type includes the standard properties that are
|
|
@@ -910,20 +934,20 @@ function _standardSchema(schema) {
|
|
|
910
934
|
};
|
|
911
935
|
return schema;
|
|
912
936
|
}
|
|
937
|
+
/**
|
|
938
|
+
* Creates a description metadata action.
|
|
939
|
+
*
|
|
940
|
+
* @param description_ The description text.
|
|
941
|
+
*
|
|
942
|
+
* @returns A description action.
|
|
943
|
+
*/
|
|
913
944
|
/* @__NO_SIDE_EFFECTS__ */
|
|
914
|
-
function
|
|
945
|
+
function description(description_) {
|
|
915
946
|
return {
|
|
916
|
-
kind: "
|
|
917
|
-
type: "
|
|
918
|
-
reference:
|
|
919
|
-
|
|
920
|
-
expects: null,
|
|
921
|
-
requirement: Number.isInteger,
|
|
922
|
-
message: message$1,
|
|
923
|
-
"~run"(dataset, config$1) {
|
|
924
|
-
if (dataset.typed && !this.requirement(dataset.value)) _addIssue(this, "integer", dataset, config$1);
|
|
925
|
-
return dataset;
|
|
926
|
-
}
|
|
947
|
+
kind: "metadata",
|
|
948
|
+
type: "description",
|
|
949
|
+
reference: description,
|
|
950
|
+
description: description_
|
|
927
951
|
};
|
|
928
952
|
}
|
|
929
953
|
/* @__NO_SIDE_EFFECTS__ */
|
|
@@ -942,22 +966,6 @@ function minLength(requirement, message$1) {
|
|
|
942
966
|
}
|
|
943
967
|
};
|
|
944
968
|
}
|
|
945
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
946
|
-
function minValue(requirement, message$1) {
|
|
947
|
-
return {
|
|
948
|
-
kind: "validation",
|
|
949
|
-
type: "min_value",
|
|
950
|
-
reference: minValue,
|
|
951
|
-
async: false,
|
|
952
|
-
expects: `>=${requirement instanceof Date ? requirement.toJSON() : /* @__PURE__ */ _stringify(requirement)}`,
|
|
953
|
-
requirement,
|
|
954
|
-
message: message$1,
|
|
955
|
-
"~run"(dataset, config$1) {
|
|
956
|
-
if (dataset.typed && !(dataset.value >= this.requirement)) _addIssue(this, "value", dataset, config$1, { received: dataset.value instanceof Date ? dataset.value.toJSON() : /* @__PURE__ */ _stringify(dataset.value) });
|
|
957
|
-
return dataset;
|
|
958
|
-
}
|
|
959
|
-
};
|
|
960
|
-
}
|
|
961
969
|
/**
|
|
962
970
|
* Returns the fallback value of the schema.
|
|
963
971
|
*
|
|
@@ -985,22 +993,6 @@ function getDefault(schema, dataset, config$1) {
|
|
|
985
993
|
return typeof schema.default === "function" ? schema.default(dataset, config$1) : schema.default;
|
|
986
994
|
}
|
|
987
995
|
/* @__NO_SIDE_EFFECTS__ */
|
|
988
|
-
function number(message$1) {
|
|
989
|
-
return _standardSchema({
|
|
990
|
-
kind: "schema",
|
|
991
|
-
type: "number",
|
|
992
|
-
reference: number,
|
|
993
|
-
expects: "number",
|
|
994
|
-
async: false,
|
|
995
|
-
message: message$1,
|
|
996
|
-
"~run"(dataset, config$1) {
|
|
997
|
-
if (typeof dataset.value === "number" && !isNaN(dataset.value)) dataset.typed = true;
|
|
998
|
-
else _addIssue(this, "type", dataset, config$1);
|
|
999
|
-
return dataset;
|
|
1000
|
-
}
|
|
1001
|
-
});
|
|
1002
|
-
}
|
|
1003
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
1004
996
|
function optional(wrapped, default_) {
|
|
1005
997
|
return _standardSchema({
|
|
1006
998
|
kind: "schema",
|
|
@@ -1023,6 +1015,23 @@ function optional(wrapped, default_) {
|
|
|
1023
1015
|
});
|
|
1024
1016
|
}
|
|
1025
1017
|
/* @__NO_SIDE_EFFECTS__ */
|
|
1018
|
+
function picklist(options, message$1) {
|
|
1019
|
+
return _standardSchema({
|
|
1020
|
+
kind: "schema",
|
|
1021
|
+
type: "picklist",
|
|
1022
|
+
reference: picklist,
|
|
1023
|
+
expects: /* @__PURE__ */ _joinExpects(options.map(_stringify), "|"),
|
|
1024
|
+
async: false,
|
|
1025
|
+
options,
|
|
1026
|
+
message: message$1,
|
|
1027
|
+
"~run"(dataset, config$1) {
|
|
1028
|
+
if (this.options.includes(dataset.value)) dataset.typed = true;
|
|
1029
|
+
else _addIssue(this, "type", dataset, config$1);
|
|
1030
|
+
return dataset;
|
|
1031
|
+
}
|
|
1032
|
+
});
|
|
1033
|
+
}
|
|
1034
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1026
1035
|
function strictObject(entries$1, message$1) {
|
|
1027
1036
|
return _standardSchema({
|
|
1028
1037
|
kind: "schema",
|
|
@@ -1154,7 +1163,7 @@ function pipe(...pipe$1) {
|
|
|
1154
1163
|
}
|
|
1155
1164
|
//#endregion
|
|
1156
1165
|
//#region src/operations.ts
|
|
1157
|
-
const runtime = () => import("./operations-
|
|
1166
|
+
const runtime = () => import("./operations-BVV-9Q0N.js");
|
|
1158
1167
|
function defineQueueOperation(definition) {
|
|
1159
1168
|
return defineOperation({
|
|
1160
1169
|
...definition,
|
|
@@ -1162,26 +1171,22 @@ function defineQueueOperation(definition) {
|
|
|
1162
1171
|
user: false
|
|
1163
1172
|
});
|
|
1164
1173
|
}
|
|
1165
|
-
|
|
1166
|
-
* The `queue.*` operations: list and send. The provider-independent Queue contract has no way to read a backlog, so
|
|
1167
|
-
* there is no peek.
|
|
1168
|
-
*/
|
|
1169
|
-
const queueOperations = [defineQueueOperation({
|
|
1174
|
+
const list = defineQueueOperation({
|
|
1170
1175
|
cli: { namespace: "queue" },
|
|
1171
|
-
description: "List the Queue Definitions of the app and the provider that sends their jobs.",
|
|
1176
|
+
description: "List the Queue Definitions of the app and the provider that sends their jobs. The local and postgres providers also report where they store jobs and the job counts.",
|
|
1172
1177
|
input: /* @__PURE__ */ strictObject({}),
|
|
1173
1178
|
kind: "read",
|
|
1174
1179
|
name: "queue.list",
|
|
1175
1180
|
run: async () => (await runtime()).listQueues()
|
|
1176
|
-
})
|
|
1181
|
+
});
|
|
1182
|
+
const send = defineQueueOperation({
|
|
1177
1183
|
cli: {
|
|
1178
1184
|
namespace: "queue",
|
|
1179
1185
|
positional: ["queue", "payload"]
|
|
1180
1186
|
},
|
|
1181
1187
|
description: "Send one job to a Queue Definition. The payload is a JSON value.",
|
|
1182
1188
|
input: /* @__PURE__ */ strictObject({
|
|
1183
|
-
|
|
1184
|
-
id: /* @__PURE__ */ optional(/* @__PURE__ */ pipe(/* @__PURE__ */ string(), /* @__PURE__ */ minLength(1))),
|
|
1189
|
+
delay: /* @__PURE__ */ optional(/* @__PURE__ */ pipe(/* @__PURE__ */ string(), /* @__PURE__ */ minLength(1), /* @__PURE__ */ description("Time before delivery, such as 1m or 30s."))),
|
|
1185
1190
|
idempotencyKey: /* @__PURE__ */ optional(/* @__PURE__ */ pipe(/* @__PURE__ */ string(), /* @__PURE__ */ minLength(1))),
|
|
1186
1191
|
payload: /* @__PURE__ */ unknown(),
|
|
1187
1192
|
queue: /* @__PURE__ */ pipe(/* @__PURE__ */ string(), /* @__PURE__ */ minLength(1))
|
|
@@ -1190,6 +1195,118 @@ const queueOperations = [defineQueueOperation({
|
|
|
1190
1195
|
kind: "write",
|
|
1191
1196
|
name: "queue.send",
|
|
1192
1197
|
run: async (input) => (await runtime()).sendToQueue(input)
|
|
1193
|
-
})
|
|
1198
|
+
});
|
|
1199
|
+
const queueName = /* @__PURE__ */ pipe(/* @__PURE__ */ string(), /* @__PURE__ */ minLength(1));
|
|
1200
|
+
const jobId = /* @__PURE__ */ pipe(/* @__PURE__ */ string(), /* @__PURE__ */ minLength(1));
|
|
1201
|
+
function nextTime(job) {
|
|
1202
|
+
if (job.state === "dead") return job.failedAt ?? "-";
|
|
1203
|
+
return job.state === "running" ? "now" : job.availableAt;
|
|
1204
|
+
}
|
|
1205
|
+
function formatJobs(result) {
|
|
1206
|
+
const header = `Jobs in ${result.base} (${result.rules} rules)\n`;
|
|
1207
|
+
if (result.jobs.length === 0) return `${header}No jobs.\n`;
|
|
1208
|
+
return `${header}${table([[
|
|
1209
|
+
"JOB",
|
|
1210
|
+
"QUEUE",
|
|
1211
|
+
"STATE",
|
|
1212
|
+
"ATTEMPTS",
|
|
1213
|
+
"NEXT OR FAILED AT",
|
|
1214
|
+
"ERROR"
|
|
1215
|
+
], ...result.jobs.map((job) => [
|
|
1216
|
+
job.id,
|
|
1217
|
+
job.queue,
|
|
1218
|
+
job.state,
|
|
1219
|
+
String(job.attempts),
|
|
1220
|
+
nextTime(job),
|
|
1221
|
+
job.error?.message ?? "-"
|
|
1222
|
+
])])}\n`;
|
|
1223
|
+
}
|
|
1224
|
+
function formatJob({ job }) {
|
|
1225
|
+
return [
|
|
1226
|
+
`Job: ${job.id}`,
|
|
1227
|
+
`Queue: ${job.queue}`,
|
|
1228
|
+
`State: ${job.state}`,
|
|
1229
|
+
`Attempts: ${job.attempts}`,
|
|
1230
|
+
`Enqueued at: ${job.enqueuedAt}`,
|
|
1231
|
+
`${job.state === "dead" ? "Failed at" : "Next delivery"}: ${nextTime(job)}`,
|
|
1232
|
+
...job.expiresAt ? [`Expires at: ${job.expiresAt}`] : [],
|
|
1233
|
+
...job.idempotencyKey ? [`Idempotency key: ${job.idempotencyKey}`] : [],
|
|
1234
|
+
...job.error ? [`Error: ${job.error.code ? `${job.error.code} ` : ""}${job.error.message}`] : [],
|
|
1235
|
+
...job.error?.stack ? ["Stack:", job.error.stack] : [],
|
|
1236
|
+
...job.file ? [`File: ${job.file}`] : [],
|
|
1237
|
+
"Payload:",
|
|
1238
|
+
JSON.stringify(job.payload ?? null, null, 2),
|
|
1239
|
+
""
|
|
1240
|
+
].join("\n");
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* The `queue.*` operations: list and send, and the stored jobs of the local and postgres providers. `vite dev` runs
|
|
1244
|
+
* every job with the local provider. Cloudflare and Vercel do not let a producer read their queue, so the job
|
|
1245
|
+
* operations fail there.
|
|
1246
|
+
*/
|
|
1247
|
+
const queueOperations = [
|
|
1248
|
+
list,
|
|
1249
|
+
send,
|
|
1250
|
+
defineQueueOperation({
|
|
1251
|
+
cli: {
|
|
1252
|
+
command: "jobs list",
|
|
1253
|
+
format: formatJobs,
|
|
1254
|
+
namespace: "queue"
|
|
1255
|
+
},
|
|
1256
|
+
description: "List the stored Queue jobs, newest first: pending, running, and dead jobs, from the local or postgres provider. In `vite dev` every job runs in the dev server, so this lists them for any provider.",
|
|
1257
|
+
input: /* @__PURE__ */ strictObject({
|
|
1258
|
+
queue: /* @__PURE__ */ optional(queueName),
|
|
1259
|
+
state: /* @__PURE__ */ optional(/* @__PURE__ */ picklist([
|
|
1260
|
+
"dead",
|
|
1261
|
+
"pending",
|
|
1262
|
+
"running"
|
|
1263
|
+
]))
|
|
1264
|
+
}),
|
|
1265
|
+
kind: "read",
|
|
1266
|
+
name: "queue.jobs-list",
|
|
1267
|
+
run: async (input) => (await runtime()).listQueueJobs(input)
|
|
1268
|
+
}),
|
|
1269
|
+
defineQueueOperation({
|
|
1270
|
+
cli: {
|
|
1271
|
+
command: "jobs show",
|
|
1272
|
+
format: formatJob,
|
|
1273
|
+
namespace: "queue",
|
|
1274
|
+
positional: ["id"]
|
|
1275
|
+
},
|
|
1276
|
+
description: "Show one stored Queue job by message ID, with its payload, attempts, and last error.",
|
|
1277
|
+
input: /* @__PURE__ */ strictObject({ id: jobId }),
|
|
1278
|
+
kind: "read",
|
|
1279
|
+
name: "queue.jobs-show",
|
|
1280
|
+
run: async (input) => (await runtime()).showQueueJob(input.id)
|
|
1281
|
+
}),
|
|
1282
|
+
defineQueueOperation({
|
|
1283
|
+
cli: {
|
|
1284
|
+
command: "jobs retry",
|
|
1285
|
+
namespace: "queue",
|
|
1286
|
+
positional: ["id"]
|
|
1287
|
+
},
|
|
1288
|
+
description: "Run a stored Queue job now. A dead job gets a new set of attempts. The call returns before the handler ends.",
|
|
1289
|
+
input: /* @__PURE__ */ strictObject({ id: jobId }),
|
|
1290
|
+
invoke: true,
|
|
1291
|
+
kind: "write",
|
|
1292
|
+
name: "queue.jobs-retry",
|
|
1293
|
+
run: async (input) => (await runtime()).retryQueueJob(input.id)
|
|
1294
|
+
}),
|
|
1295
|
+
defineQueueOperation({
|
|
1296
|
+
cli: {
|
|
1297
|
+
command: "jobs clear",
|
|
1298
|
+
format: ({ cleared }) => `Removed ${cleared} job${cleared === 1 ? "" : "s"}.\n`,
|
|
1299
|
+
namespace: "queue"
|
|
1300
|
+
},
|
|
1301
|
+
description: "Remove the stored Queue jobs that match, pending and dead. Running jobs stay.",
|
|
1302
|
+
input: /* @__PURE__ */ strictObject({
|
|
1303
|
+
queue: /* @__PURE__ */ optional(queueName),
|
|
1304
|
+
state: /* @__PURE__ */ optional(/* @__PURE__ */ picklist(["dead", "pending"]))
|
|
1305
|
+
}),
|
|
1306
|
+
kind: "destructive",
|
|
1307
|
+
name: "queue.jobs-clear",
|
|
1308
|
+
run: async (input) => (await runtime()).clearQueueJobs(input)
|
|
1309
|
+
})
|
|
1310
|
+
];
|
|
1194
1311
|
//#endregion
|
|
1195
1312
|
export { queueOperations };
|
package/dist/runtime/hosted.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { x as QueueDefinition } from "../types-CiuSIPR0.js";
|
|
2
2
|
//#region src/runtime/hosted.d.ts
|
|
3
3
|
export declare const hostedVercelWaitUntil: (promise: Promise<unknown>) => void | undefined;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
request?: Request;
|
|
7
|
-
}, name: string, definition: QueueDefinition): Promise<unknown>;
|
|
4
|
+
/** Handle one Vercel Queue delivery. The generated consumer route is a Fetchable module that passes its Request here. */
|
|
5
|
+
export declare function handleHostedVercelQueueCallback(request: Request, name: string, definition: QueueDefinition): Promise<Response>;
|
|
8
6
|
//#endregion
|