@vite-hub/queue 0.1.0 → 0.3.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 +141 -20
- package/dist/client-Cj50hQYp.js +180 -0
- package/dist/{cloudflare-client-COzQ8fHk.js → cloudflare-client-DYsAjM8B.js} +9 -16
- package/dist/{cloudflare-resource-name-CCuLDvSP.js → cloudflare-resource-name-BJHYRCMQ.js} +1 -1
- package/dist/config-BcTDeQIP.js +105 -0
- package/dist/durability.d.ts +13 -0
- package/dist/durability.js +47 -0
- package/dist/error-diagnostics-BRartC1z.js +181 -0
- package/dist/error-diagnostics-DSkCJC_L.js +266 -0
- package/dist/errors-DL3pcNO4.js +77 -0
- package/dist/{handler-response-CBwIkmTS.js → handler-response-By0Fpspv.js} +9 -4
- package/dist/index.d.ts +15 -31
- package/dist/index.js +23 -11
- 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 +560 -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 +52 -26
- 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-CGckW5nr.js +540 -0
- package/dist/local-CVVRVWeR.d.ts +22 -0
- package/dist/object-D8pRdprI.js +15 -0
- package/dist/{operations-tNUdj3G4.d.ts → operation-definition-8gOe-ubD.d.ts} +37 -15
- package/dist/operations-Crwjca91.js +124 -0
- package/dist/operations.d.ts +45 -8
- package/dist/operations.js +173 -24
- package/dist/runtime/hosted.d.ts +3 -5
- package/dist/runtime/hosted.js +21 -45
- package/dist/{state-G9s378-e.js → state-mVA2X_wa.js} +59 -47
- package/dist/types-BD-8U9zS.d.ts +420 -0
- package/dist/types-DS_rqu9l.d.ts +10 -0
- package/dist/vercel-region-D1CivgdA.js +26 -0
- package/dist/virtual.d.ts +4 -0
- package/dist/vite.d.ts +364 -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
|
@@ -75,7 +75,7 @@ declare namespace StandardSchemaV1 {
|
|
|
75
75
|
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
76
76
|
}
|
|
77
77
|
//#endregion
|
|
78
|
-
//#region ../internal/src/
|
|
78
|
+
//#region ../internal/src/operation-definition.d.ts
|
|
79
79
|
/** `read` never changes state. `write` changes state. `destructive` deletes or publishes. */
|
|
80
80
|
type OperationKind = "read" | "write" | "destructive";
|
|
81
81
|
/** The signed-in user of a call. */
|
|
@@ -98,7 +98,9 @@ interface OperationAccess {
|
|
|
98
98
|
readonly mode: string;
|
|
99
99
|
/**
|
|
100
100
|
* The sections that the call may use. `"all"` when no section filter applies. An entry is a section id (`"kv"`, every
|
|
101
|
-
* operation of the section)
|
|
101
|
+
* operation of the section), `"<section>:read"` (only the operations that read), or `"<section>:<scope>"` (only the
|
|
102
|
+
* calls of a scoped operation for that scope, such as `"blob:media"` for one Blob store). `"<section>:<scope>:read"`
|
|
103
|
+
* allows only the reads of that scope.
|
|
102
104
|
*/
|
|
103
105
|
readonly sections: "all" | readonly string[];
|
|
104
106
|
readonly user?: OperationUser;
|
|
@@ -116,6 +118,12 @@ interface OperationContext {
|
|
|
116
118
|
env?: Record<string, unknown>;
|
|
117
119
|
waitUntil?: (task: Promise<unknown>) => void;
|
|
118
120
|
request?: Request;
|
|
121
|
+
/**
|
|
122
|
+
* The request event of the HTTP request that carries the call, when there is one: the Request of the Console route,
|
|
123
|
+
* with its Standard Context. Operations hand it to app hooks that read the request's own session, such as `identify`
|
|
124
|
+
* of Comments.
|
|
125
|
+
*/
|
|
126
|
+
event?: unknown;
|
|
119
127
|
/** Operations set a success status here, such as 202 for an accepted call. */
|
|
120
128
|
response?: {
|
|
121
129
|
status?: number;
|
|
@@ -138,9 +146,16 @@ interface OperationDefinition<Input, Output> {
|
|
|
138
146
|
description: string;
|
|
139
147
|
/**
|
|
140
148
|
* Console section that grants access, such as `content`. `false`: any Console user. A function reads the section
|
|
141
|
-
* from the input, for operations that serve several sections.
|
|
149
|
+
* from the input, for operations that serve several sections. Section ids cannot contain `:`; it is reserved for
|
|
150
|
+
* scope and read-only grants. A function that returns an invalid id denies the call.
|
|
142
151
|
*/
|
|
143
152
|
section: string | false | ((input: Input) => string | undefined);
|
|
153
|
+
/**
|
|
154
|
+
* The part of a string `section` that one call uses, such as the Blob store that the input names. The call then needs
|
|
155
|
+
* the section (every scope) or `"<section>:<scope>"` (only this scope). A scope that is empty, is `read`, or has a
|
|
156
|
+
* `:` needs the whole section.
|
|
157
|
+
*/
|
|
158
|
+
scope?: (input: Input) => string | undefined;
|
|
144
159
|
/** `read` never changes state. `write` changes state. `destructive` deletes or publishes; the CLI asks for `--yes`, MCP marks `destructiveHint`, agents require approval by default. */
|
|
145
160
|
kind: OperationKind;
|
|
146
161
|
/** Standard Schema (valibot in this repo). Its Standard JSON Schema builds CLI flags and the MCP input schema. */
|
|
@@ -149,19 +164,14 @@ interface OperationDefinition<Input, Output> {
|
|
|
149
164
|
cli?: {
|
|
150
165
|
/** Defaults: namespace = section, command = verb. */
|
|
151
166
|
namespace?: string;
|
|
167
|
+
/** A space groups commands: `jobs list` and `jobs show` run as `vitehub <namespace> jobs list` and `jobs show`. */
|
|
152
168
|
command?: string;
|
|
153
169
|
/** Input keys read from positional arguments, in order. */
|
|
154
170
|
positional?: string[];
|
|
155
171
|
/** Human output, written verbatim. Without it the CLI prints JSON. `--json` always prints JSON. */
|
|
156
172
|
format?: (output: Output) => string;
|
|
157
|
-
/** `vitehub <namespace>` runs this command when no command is named
|
|
173
|
+
/** `vitehub <namespace>` runs this command when no command is named. */
|
|
158
174
|
default?: boolean;
|
|
159
|
-
/**
|
|
160
|
-
* Route of the app that takes a signed dispatch of this operation, such as `/_vitehub/schedules/run`. With `--url`
|
|
161
|
-
* and a dispatch key in the environment (`VITEHUB_DISPATCH_KEY`), the command signs the input and posts it there, so
|
|
162
|
-
* a CI job needs no Console credentials. Without a key it calls the RPC.
|
|
163
|
-
*/
|
|
164
|
-
dispatch?: string;
|
|
165
175
|
};
|
|
166
176
|
/** Largest request body in bytes. It can raise the 64 KiB default but not lower it. */
|
|
167
177
|
maxRequestBytes?: number;
|
|
@@ -170,8 +180,16 @@ interface OperationDefinition<Input, Output> {
|
|
|
170
180
|
* confirmation, and agents run it without approval. Without it, every call of a `destructive` operation asks.
|
|
171
181
|
*/
|
|
172
182
|
readOnlyWhen?: (input: Input) => boolean;
|
|
173
|
-
/**
|
|
174
|
-
|
|
183
|
+
/**
|
|
184
|
+
* How MCP offers the operation as a tool. `false`: MCP does not offer it, such as an editor transport that only the
|
|
185
|
+
* Console uses. `title`: the short title that clients show, instead of the name in words. `format`: the text of a
|
|
186
|
+
* result for the Agent, such as a list of lines. The result stays the structured content. Without `format`, the text
|
|
187
|
+
* is the result as JSON.
|
|
188
|
+
*/
|
|
189
|
+
mcp?: false | {
|
|
190
|
+
title?: string;
|
|
191
|
+
format?: (output: NoInfer<Output>) => string;
|
|
192
|
+
};
|
|
175
193
|
/** `false`: the operation never reads `context.user`, so the Console skips the session lookup for it. */
|
|
176
194
|
user?: false;
|
|
177
195
|
/**
|
|
@@ -182,24 +200,28 @@ interface OperationDefinition<Input, Output> {
|
|
|
182
200
|
run: (input: Input, context: OperationContext) => Output | Promise<Output>;
|
|
183
201
|
}
|
|
184
202
|
/** An operation of any input and output, as a registry holds it. */
|
|
185
|
-
interface AnyOperation extends Omit<OperationDefinition<unknown, unknown>, "cli" | "input" | "output" | "readOnlyWhen" | "run" | "section"> {
|
|
203
|
+
interface AnyOperation extends Omit<OperationDefinition<unknown, unknown>, "cli" | "input" | "mcp" | "output" | "readOnlyWhen" | "run" | "scope" | "section"> {
|
|
186
204
|
readOnlyWhen?: (input: never) => boolean;
|
|
187
205
|
cli?: {
|
|
188
206
|
namespace?: string;
|
|
189
207
|
command?: string;
|
|
190
208
|
default?: boolean;
|
|
191
|
-
dispatch?: string;
|
|
192
209
|
positional?: string[];
|
|
193
210
|
format?: (output: never) => string;
|
|
194
211
|
};
|
|
212
|
+
mcp?: false | {
|
|
213
|
+
title?: string;
|
|
214
|
+
format?: (output: never) => string;
|
|
215
|
+
};
|
|
195
216
|
input: StandardSchemaV1;
|
|
196
217
|
output?: StandardSchemaV1;
|
|
197
218
|
run: (input: never, context: OperationContext) => unknown;
|
|
219
|
+
scope?: (input: never) => string | undefined;
|
|
198
220
|
section: string | false | ((input: never) => string | undefined);
|
|
199
221
|
}
|
|
200
222
|
/** The contribution of one plugin: operations, or a module that exports them. */
|
|
201
223
|
interface OperationContributionEntry {
|
|
202
|
-
/**
|
|
224
|
+
/** The absolute path of the module that generated code imports, such as `ownModule(import.meta.url, "operations")`. */
|
|
203
225
|
module: string;
|
|
204
226
|
/** Named export that holds an operation or an array of operations. Defaults to `default`. */
|
|
205
227
|
export?: string;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { t as queueErrorDiagnostics } from "./error-diagnostics-BRartC1z.js";
|
|
2
|
+
import { i as normalizePublicQueueIdentifier, n as isQueueError } from "./errors-DL3pcNO4.js";
|
|
3
|
+
import { i as getQueueRuntimeConfig, o as getQueueRuntimeJobStore, s as listQueueDefinitionNames } from "./state-mVA2X_wa.js";
|
|
4
|
+
import { n as dynamicQueue } from "./client-Cj50hQYp.js";
|
|
5
|
+
import { t as redactInspectionText } from "./inspect-PeuckaC3.js";
|
|
6
|
+
//#region src/runtime/operations.ts
|
|
7
|
+
/** The HTTP status that the CLI, the Console, and Agents report for each code of a failed operation. */
|
|
8
|
+
const statuses = {
|
|
9
|
+
QUEUE_DEFINITION_NAME_INVALID: 400,
|
|
10
|
+
QUEUE_DEFINITION_NOT_FOUND: 404,
|
|
11
|
+
QUEUE_DISABLED: 409,
|
|
12
|
+
QUEUE_JOB_DUPLICATE: 409,
|
|
13
|
+
QUEUE_JOBS_UNAVAILABLE: 409,
|
|
14
|
+
QUEUE_JOB_NOT_FOUND: 404,
|
|
15
|
+
QUEUE_JOB_RUNNING: 409,
|
|
16
|
+
QUEUE_PROVIDER_FAILED: 502,
|
|
17
|
+
QUEUE_PROVIDER_INVALID_RESPONSE: 502,
|
|
18
|
+
QUEUE_UNSUPPORTED_OPTION: 400
|
|
19
|
+
};
|
|
20
|
+
/** Gives a Queue catalog error the status and the redacted message that the CLI and the Console report. */
|
|
21
|
+
function failure(error) {
|
|
22
|
+
if (!isQueueError(error)) return error;
|
|
23
|
+
return Object.assign(error, {
|
|
24
|
+
status: statuses[error.code] ?? 500,
|
|
25
|
+
statusMessage: redactInspectionText(error.message)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async function listQueues() {
|
|
29
|
+
const config = getQueueRuntimeConfig();
|
|
30
|
+
if (config === false) throw failure(queueErrorDiagnostics.QUEUE_DISABLED());
|
|
31
|
+
const names = listQueueDefinitionNames();
|
|
32
|
+
if (config?.driver === "local" || config?.driver === "postgres") {
|
|
33
|
+
const status = config.driver === "postgres" ? await (await getQueueRuntimeJobStore())?.status() : await (await import("./internal/runtime/local-client.js")).getLocalQueueStatus(config);
|
|
34
|
+
if (status) {
|
|
35
|
+
const empty = {
|
|
36
|
+
dead: 0,
|
|
37
|
+
pending: 0,
|
|
38
|
+
running: 0
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
provider: config.driver,
|
|
42
|
+
...config.driver === "local" && config.rules && config.rules !== "local" ? { rules: config.rules } : {},
|
|
43
|
+
queues: names.map((name) => ({
|
|
44
|
+
name,
|
|
45
|
+
...empty,
|
|
46
|
+
...status.queues[name]
|
|
47
|
+
})),
|
|
48
|
+
storage: {
|
|
49
|
+
base: status.base,
|
|
50
|
+
deadLimit: status.deadLimit,
|
|
51
|
+
durability: status.durability
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
...config ? { provider: config.driver } : {},
|
|
58
|
+
queues: names.map((name) => ({ name }))
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
async function sendToQueue(input) {
|
|
62
|
+
const queue = normalizePublicQueueIdentifier(input.queue);
|
|
63
|
+
if (!queue) throw failure(queueErrorDiagnostics.QUEUE_DEFINITION_NAME_INVALID());
|
|
64
|
+
const options = {
|
|
65
|
+
...input.delaySeconds === void 0 ? {} : { delaySeconds: input.delaySeconds },
|
|
66
|
+
...input.idempotencyKey === void 0 ? {} : { idempotencyKey: input.idempotencyKey }
|
|
67
|
+
};
|
|
68
|
+
let result;
|
|
69
|
+
try {
|
|
70
|
+
result = await dynamicQueue.send(queue, input.payload, options);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
throw failure(error);
|
|
73
|
+
}
|
|
74
|
+
const [error, sent] = result;
|
|
75
|
+
if (error) throw failure(error);
|
|
76
|
+
const config = getQueueRuntimeConfig();
|
|
77
|
+
return {
|
|
78
|
+
...sent?.messageId ? { messageId: sent.messageId } : {},
|
|
79
|
+
...config ? { provider: config.driver } : {},
|
|
80
|
+
queue,
|
|
81
|
+
status: "queued"
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The stored jobs of the local or postgres provider. Cloudflare and Vercel do not let a producer read their queue, so
|
|
86
|
+
* their jobs do not list.
|
|
87
|
+
*/
|
|
88
|
+
async function localJobs() {
|
|
89
|
+
const config = getQueueRuntimeConfig();
|
|
90
|
+
if (config === false) throw failure(queueErrorDiagnostics.QUEUE_DISABLED());
|
|
91
|
+
const store = config?.driver === "postgres" ? await getQueueRuntimeJobStore() : config ? (await import("./internal/runtime/local-client.js")).useLocalQueueEngine(config) : void 0;
|
|
92
|
+
if (!store) throw failure(queueErrorDiagnostics.QUEUE_JOBS_UNAVAILABLE({ driver: config?.driver ?? "configured" }));
|
|
93
|
+
return store;
|
|
94
|
+
}
|
|
95
|
+
function jobNotFound() {
|
|
96
|
+
return failure(queueErrorDiagnostics.QUEUE_JOB_NOT_FOUND());
|
|
97
|
+
}
|
|
98
|
+
async function listQueueJobs(input) {
|
|
99
|
+
const engine = await localJobs();
|
|
100
|
+
const jobs = (await engine.jobs(input)).filter((job) => (input.queue === void 0 || job.queue === input.queue) && (input.state === void 0 || job.state === input.state));
|
|
101
|
+
return {
|
|
102
|
+
base: engine.base,
|
|
103
|
+
jobs,
|
|
104
|
+
provider: engine.provider,
|
|
105
|
+
rules: engine.rules.rules
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
async function showQueueJob(id) {
|
|
109
|
+
const job = await (await localJobs()).job(id);
|
|
110
|
+
if (!job) throw jobNotFound();
|
|
111
|
+
return { job };
|
|
112
|
+
}
|
|
113
|
+
async function retryQueueJob(id) {
|
|
114
|
+
const result = await (await localJobs()).retry(id);
|
|
115
|
+
if (result === "missing") throw jobNotFound();
|
|
116
|
+
if (result === "running") throw failure(queueErrorDiagnostics.QUEUE_JOB_RUNNING());
|
|
117
|
+
if (result === "duplicate") throw failure(queueErrorDiagnostics.QUEUE_JOB_DUPLICATE());
|
|
118
|
+
return { job: result };
|
|
119
|
+
}
|
|
120
|
+
async function clearQueueJobs(input) {
|
|
121
|
+
return { cleared: await (await localJobs()).clear(input) };
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
export { clearQueueJobs, listQueueJobs, listQueues, retryQueueJob, sendToQueue, showQueueJob };
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,22 +1,58 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { C as QueueDriver, d as LocalQueueJobDetail, f as LocalQueueRules, k as QueueJobStore, m as LocalQueueStatus, u as LocalQueueJob } from "./types-BD-8U9zS.js";
|
|
2
|
+
import "./local-CVVRVWeR.js";
|
|
3
|
+
import { t as AnyOperation } from "./operation-definition-8gOe-ubD.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
55
|
delaySeconds?: number;
|
|
19
|
-
id?: string;
|
|
20
56
|
idempotencyKey?: string;
|
|
21
57
|
payload: unknown;
|
|
22
58
|
queue: string;
|
|
@@ -24,9 +60,10 @@ interface QueueSendOperationInput {
|
|
|
24
60
|
//#endregion
|
|
25
61
|
//#region src/operations.d.ts
|
|
26
62
|
/**
|
|
27
|
-
* The `queue.*` operations: list and send
|
|
28
|
-
*
|
|
63
|
+
* The `queue.*` operations: list and send, and the stored jobs of the local and postgres providers. `vite dev` runs
|
|
64
|
+
* every job with the local provider. Cloudflare and Vercel do not let a producer read their queue, so the job
|
|
65
|
+
* operations fail there.
|
|
29
66
|
*/
|
|
30
67
|
export declare const queueOperations: readonly AnyOperation[];
|
|
31
68
|
//#endregion
|
|
32
|
-
export type { QueueListResult, QueueSendOperationInput, QueueSendOperationResult };
|
|
69
|
+
export type { LocalQueueJob, LocalQueueJobDetail, QueueJobsClearInput, QueueJobsListInput, QueueJobsListResult, QueueListResult, QueueSendOperationInput, QueueSendOperationResult };
|
package/dist/operations.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { t as internalErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { t as internalErrorDiagnostics } from "./error-diagnostics-DSkCJC_L.js";
|
|
2
|
+
import { r as isRecordOrFunction } from "./object-D8pRdprI.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
|
|
@@ -1023,6 +1047,23 @@ function optional(wrapped, default_) {
|
|
|
1023
1047
|
});
|
|
1024
1048
|
}
|
|
1025
1049
|
/* @__NO_SIDE_EFFECTS__ */
|
|
1050
|
+
function picklist(options, message$1) {
|
|
1051
|
+
return _standardSchema({
|
|
1052
|
+
kind: "schema",
|
|
1053
|
+
type: "picklist",
|
|
1054
|
+
reference: picklist,
|
|
1055
|
+
expects: /* @__PURE__ */ _joinExpects(options.map(_stringify), "|"),
|
|
1056
|
+
async: false,
|
|
1057
|
+
options,
|
|
1058
|
+
message: message$1,
|
|
1059
|
+
"~run"(dataset, config$1) {
|
|
1060
|
+
if (this.options.includes(dataset.value)) dataset.typed = true;
|
|
1061
|
+
else _addIssue(this, "type", dataset, config$1);
|
|
1062
|
+
return dataset;
|
|
1063
|
+
}
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1026
1067
|
function strictObject(entries$1, message$1) {
|
|
1027
1068
|
return _standardSchema({
|
|
1028
1069
|
kind: "schema",
|
|
@@ -1154,7 +1195,7 @@ function pipe(...pipe$1) {
|
|
|
1154
1195
|
}
|
|
1155
1196
|
//#endregion
|
|
1156
1197
|
//#region src/operations.ts
|
|
1157
|
-
const runtime = () => import("./operations-
|
|
1198
|
+
const runtime = () => import("./operations-Crwjca91.js");
|
|
1158
1199
|
function defineQueueOperation(definition) {
|
|
1159
1200
|
return defineOperation({
|
|
1160
1201
|
...definition,
|
|
@@ -1162,18 +1203,15 @@ function defineQueueOperation(definition) {
|
|
|
1162
1203
|
user: false
|
|
1163
1204
|
});
|
|
1164
1205
|
}
|
|
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({
|
|
1206
|
+
const list = defineQueueOperation({
|
|
1170
1207
|
cli: { namespace: "queue" },
|
|
1171
|
-
description: "List the Queue Definitions of the app and the provider that sends their jobs.",
|
|
1208
|
+
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
1209
|
input: /* @__PURE__ */ strictObject({}),
|
|
1173
1210
|
kind: "read",
|
|
1174
1211
|
name: "queue.list",
|
|
1175
1212
|
run: async () => (await runtime()).listQueues()
|
|
1176
|
-
})
|
|
1213
|
+
});
|
|
1214
|
+
const send = defineQueueOperation({
|
|
1177
1215
|
cli: {
|
|
1178
1216
|
namespace: "queue",
|
|
1179
1217
|
positional: ["queue", "payload"]
|
|
@@ -1181,7 +1219,6 @@ const queueOperations = [defineQueueOperation({
|
|
|
1181
1219
|
description: "Send one job to a Queue Definition. The payload is a JSON value.",
|
|
1182
1220
|
input: /* @__PURE__ */ strictObject({
|
|
1183
1221
|
delaySeconds: /* @__PURE__ */ optional(/* @__PURE__ */ pipe(/* @__PURE__ */ number(), /* @__PURE__ */ integer(), /* @__PURE__ */ minValue(0))),
|
|
1184
|
-
id: /* @__PURE__ */ optional(/* @__PURE__ */ pipe(/* @__PURE__ */ string(), /* @__PURE__ */ minLength(1))),
|
|
1185
1222
|
idempotencyKey: /* @__PURE__ */ optional(/* @__PURE__ */ pipe(/* @__PURE__ */ string(), /* @__PURE__ */ minLength(1))),
|
|
1186
1223
|
payload: /* @__PURE__ */ unknown(),
|
|
1187
1224
|
queue: /* @__PURE__ */ pipe(/* @__PURE__ */ string(), /* @__PURE__ */ minLength(1))
|
|
@@ -1190,6 +1227,118 @@ const queueOperations = [defineQueueOperation({
|
|
|
1190
1227
|
kind: "write",
|
|
1191
1228
|
name: "queue.send",
|
|
1192
1229
|
run: async (input) => (await runtime()).sendToQueue(input)
|
|
1193
|
-
})
|
|
1230
|
+
});
|
|
1231
|
+
const queueName = /* @__PURE__ */ pipe(/* @__PURE__ */ string(), /* @__PURE__ */ minLength(1));
|
|
1232
|
+
const jobId = /* @__PURE__ */ pipe(/* @__PURE__ */ string(), /* @__PURE__ */ minLength(1));
|
|
1233
|
+
function nextTime(job) {
|
|
1234
|
+
if (job.state === "dead") return job.failedAt ?? "-";
|
|
1235
|
+
return job.state === "running" ? "now" : job.availableAt;
|
|
1236
|
+
}
|
|
1237
|
+
function formatJobs(result) {
|
|
1238
|
+
const header = `Jobs in ${result.base} (${result.rules} rules)\n`;
|
|
1239
|
+
if (result.jobs.length === 0) return `${header}No jobs.\n`;
|
|
1240
|
+
return `${header}${table([[
|
|
1241
|
+
"JOB",
|
|
1242
|
+
"QUEUE",
|
|
1243
|
+
"STATE",
|
|
1244
|
+
"ATTEMPTS",
|
|
1245
|
+
"NEXT OR FAILED AT",
|
|
1246
|
+
"ERROR"
|
|
1247
|
+
], ...result.jobs.map((job) => [
|
|
1248
|
+
job.id,
|
|
1249
|
+
job.queue,
|
|
1250
|
+
job.state,
|
|
1251
|
+
String(job.attempts),
|
|
1252
|
+
nextTime(job),
|
|
1253
|
+
job.error?.message ?? "-"
|
|
1254
|
+
])])}\n`;
|
|
1255
|
+
}
|
|
1256
|
+
function formatJob({ job }) {
|
|
1257
|
+
return [
|
|
1258
|
+
`Job: ${job.id}`,
|
|
1259
|
+
`Queue: ${job.queue}`,
|
|
1260
|
+
`State: ${job.state}`,
|
|
1261
|
+
`Attempts: ${job.attempts}`,
|
|
1262
|
+
`Enqueued at: ${job.enqueuedAt}`,
|
|
1263
|
+
`${job.state === "dead" ? "Failed at" : "Next delivery"}: ${nextTime(job)}`,
|
|
1264
|
+
...job.expiresAt ? [`Expires at: ${job.expiresAt}`] : [],
|
|
1265
|
+
...job.idempotencyKey ? [`Idempotency key: ${job.idempotencyKey}`] : [],
|
|
1266
|
+
...job.error ? [`Error: ${job.error.code ? `${job.error.code} ` : ""}${job.error.message}`] : [],
|
|
1267
|
+
...job.error?.stack ? ["Stack:", job.error.stack] : [],
|
|
1268
|
+
...job.file ? [`File: ${job.file}`] : [],
|
|
1269
|
+
"Payload:",
|
|
1270
|
+
JSON.stringify(job.payload ?? null, null, 2),
|
|
1271
|
+
""
|
|
1272
|
+
].join("\n");
|
|
1273
|
+
}
|
|
1274
|
+
/**
|
|
1275
|
+
* The `queue.*` operations: list and send, and the stored jobs of the local and postgres providers. `vite dev` runs
|
|
1276
|
+
* every job with the local provider. Cloudflare and Vercel do not let a producer read their queue, so the job
|
|
1277
|
+
* operations fail there.
|
|
1278
|
+
*/
|
|
1279
|
+
const queueOperations = [
|
|
1280
|
+
list,
|
|
1281
|
+
send,
|
|
1282
|
+
defineQueueOperation({
|
|
1283
|
+
cli: {
|
|
1284
|
+
command: "jobs list",
|
|
1285
|
+
format: formatJobs,
|
|
1286
|
+
namespace: "queue"
|
|
1287
|
+
},
|
|
1288
|
+
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.",
|
|
1289
|
+
input: /* @__PURE__ */ strictObject({
|
|
1290
|
+
queue: /* @__PURE__ */ optional(queueName),
|
|
1291
|
+
state: /* @__PURE__ */ optional(/* @__PURE__ */ picklist([
|
|
1292
|
+
"dead",
|
|
1293
|
+
"pending",
|
|
1294
|
+
"running"
|
|
1295
|
+
]))
|
|
1296
|
+
}),
|
|
1297
|
+
kind: "read",
|
|
1298
|
+
name: "queue.jobs-list",
|
|
1299
|
+
run: async (input) => (await runtime()).listQueueJobs(input)
|
|
1300
|
+
}),
|
|
1301
|
+
defineQueueOperation({
|
|
1302
|
+
cli: {
|
|
1303
|
+
command: "jobs show",
|
|
1304
|
+
format: formatJob,
|
|
1305
|
+
namespace: "queue",
|
|
1306
|
+
positional: ["id"]
|
|
1307
|
+
},
|
|
1308
|
+
description: "Show one stored Queue job by message ID, with its payload, attempts, and last error.",
|
|
1309
|
+
input: /* @__PURE__ */ strictObject({ id: jobId }),
|
|
1310
|
+
kind: "read",
|
|
1311
|
+
name: "queue.jobs-show",
|
|
1312
|
+
run: async (input) => (await runtime()).showQueueJob(input.id)
|
|
1313
|
+
}),
|
|
1314
|
+
defineQueueOperation({
|
|
1315
|
+
cli: {
|
|
1316
|
+
command: "jobs retry",
|
|
1317
|
+
namespace: "queue",
|
|
1318
|
+
positional: ["id"]
|
|
1319
|
+
},
|
|
1320
|
+
description: "Run a stored Queue job now. A dead job gets a new set of attempts. The call returns before the handler ends.",
|
|
1321
|
+
input: /* @__PURE__ */ strictObject({ id: jobId }),
|
|
1322
|
+
invoke: true,
|
|
1323
|
+
kind: "write",
|
|
1324
|
+
name: "queue.jobs-retry",
|
|
1325
|
+
run: async (input) => (await runtime()).retryQueueJob(input.id)
|
|
1326
|
+
}),
|
|
1327
|
+
defineQueueOperation({
|
|
1328
|
+
cli: {
|
|
1329
|
+
command: "jobs clear",
|
|
1330
|
+
format: ({ cleared }) => `Removed ${cleared} job${cleared === 1 ? "" : "s"}.\n`,
|
|
1331
|
+
namespace: "queue"
|
|
1332
|
+
},
|
|
1333
|
+
description: "Remove the stored Queue jobs that match, pending and dead. Running jobs stay.",
|
|
1334
|
+
input: /* @__PURE__ */ strictObject({
|
|
1335
|
+
queue: /* @__PURE__ */ optional(queueName),
|
|
1336
|
+
state: /* @__PURE__ */ optional(/* @__PURE__ */ picklist(["dead", "pending"]))
|
|
1337
|
+
}),
|
|
1338
|
+
kind: "destructive",
|
|
1339
|
+
name: "queue.jobs-clear",
|
|
1340
|
+
run: async (input) => (await runtime()).clearQueueJobs(input)
|
|
1341
|
+
})
|
|
1342
|
+
];
|
|
1194
1343
|
//#endregion
|
|
1195
1344
|
export { queueOperations };
|
package/dist/runtime/hosted.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as QueueDefinition } from "../types-BD-8U9zS.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
|