@vite-hub/queue 0.6.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -12
- package/dist/{client-CwoCdKct.js → client-mT8TUaag.js} +46 -15
- package/dist/{cloudflare-client-xWteD-su.js → cloudflare-client-DBgvWY0z.js} +14 -42
- package/dist/{cloudflare-resource-name-Bv8Z7nDU.js → cloudflare-resource-name-Coz5CPmn.js} +1 -1
- package/dist/{config-Bzp1xmdh.js → config-ByKUipob.js} +4 -2
- package/dist/{definition-CIiFfst2.js → definition-Dorliu47.js} +9 -2
- package/dist/{duration-C5w_-Rf4.js → duration-BZKArIBP.js} +20 -5
- package/dist/{error-diagnostics-kKXseq8d.js → error-diagnostics-CsiNo_oI.js} +3 -3
- package/dist/{error-diagnostics-Dv6nKZQW.js → error-diagnostics-Yj8XCiya.js} +30 -6
- package/dist/{handler-response-CchTXVjm.js → handler-response-DKhsmxDV.js} +6 -2
- package/dist/index.d.ts +13 -8
- package/dist/index.js +4 -4
- package/dist/internal/runtime/cloudflare-client.d.ts +1 -1
- package/dist/internal/runtime/cloudflare-client.js +1 -1
- package/dist/internal/runtime/cloudflare-vite.d.ts +1 -1
- package/dist/internal/runtime/cloudflare-vite.js +9 -8
- package/dist/internal/runtime/local-client.d.ts +3 -3
- package/dist/internal/runtime/local-client.js +4 -4
- package/dist/internal/runtime/postgres-client.d.ts +8 -6
- package/dist/internal/runtime/postgres-client.js +178 -40
- package/dist/internal/runtime/state.d.ts +5 -3
- package/dist/internal/runtime/state.js +1 -1
- package/dist/internal/runtime/vercel-client.d.ts +1 -1
- package/dist/internal/runtime/vercel-client.js +28 -57
- package/dist/internal/runtime/worker-client.d.ts +2 -2
- package/dist/internal/runtime/worker-client.js +1 -1
- package/dist/{local-RX10a_Sq.js → local-5pcvR1RC.js} +148 -97
- package/dist/{local-B72WRWkS.d.ts → local-DUh8sGn-.d.ts} +1 -1
- package/dist/{operations-CoEXxfUW.js → operations-BSouq47k.js} +11 -6
- package/dist/{operation-definition-CqZkx1Rm.d.ts → operations-DSslh_vK.d.ts} +169 -1
- package/dist/operations.d.ts +13 -4
- package/dist/operations.js +98 -37
- package/dist/retries-BSAZru9n.js +27 -0
- package/dist/run-handler-COXFYL5z.js +61 -0
- package/dist/runtime/hosted.d.ts +1 -1
- package/dist/runtime/hosted.js +32 -20
- package/dist/{scan-module-BaqBao0J.js → scan-module-3HfnrGbT.js} +16 -1
- package/dist/source-files-DrAH1-c8.js +147 -0
- package/dist/{state-DqxeV11k.js → state-C-t99I4Q.js} +9 -3
- package/dist/{types-BevEYrUV.d.ts → types-BPs6OsRv.d.ts} +1 -1
- package/dist/{types-BzPGPV9z.d.ts → types-rZHAtkK0.d.ts} +74 -12
- package/dist/{vercel-region-DEsR1YJQ.js → vercel-region-Bp3hwRBr.js} +1 -1
- package/dist/vite.d.ts +2 -155
- package/dist/vite.js +522 -138
- package/package.json +4 -3
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { resolve } from "pathe";
|
|
3
|
+
// ../internal/src/source-files.ts
|
|
4
|
+
const ignoredDirs = /* @__PURE__ */ new Set([
|
|
5
|
+
"node_modules",
|
|
6
|
+
"dist",
|
|
7
|
+
".output",
|
|
8
|
+
".nuxt",
|
|
9
|
+
".vercel",
|
|
10
|
+
".git",
|
|
11
|
+
".vitehub"
|
|
12
|
+
]);
|
|
13
|
+
const racyWindowNs = 2000000000n;
|
|
14
|
+
const storeKey = Symbol.for("vite-hub.source-files.v1");
|
|
15
|
+
function store() {
|
|
16
|
+
const existing = Reflect.get(globalThis, storeKey);
|
|
17
|
+
if (isStore(existing)) return existing;
|
|
18
|
+
const created = {
|
|
19
|
+
derived: /* @__PURE__ */ new Map(),
|
|
20
|
+
texts: /* @__PURE__ */ new Map(),
|
|
21
|
+
trees: /* @__PURE__ */ new Map()
|
|
22
|
+
};
|
|
23
|
+
Reflect.set(globalThis, storeKey, created);
|
|
24
|
+
return created;
|
|
25
|
+
}
|
|
26
|
+
function isStore(value) {
|
|
27
|
+
return typeof value === "object" && value !== null && "texts" in value && "trees" in value && "derived" in value;
|
|
28
|
+
}
|
|
29
|
+
function errorCode(error) {
|
|
30
|
+
return typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
|
|
31
|
+
}
|
|
32
|
+
function statOrMissing(path) {
|
|
33
|
+
try {
|
|
34
|
+
return statSync(path, { bigint: true });
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (errorCode(error) === "ENOENT" || errorCode(error) === "ENOTDIR") return;
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function signature(stats) {
|
|
41
|
+
return `${stats.ino}:${stats.size}:${stats.mtimeNs}:${stats.ctimeNs}`;
|
|
42
|
+
}
|
|
43
|
+
function isSettled(stats) {
|
|
44
|
+
const changed = stats.mtimeNs > stats.ctimeNs ? stats.mtimeNs : stats.ctimeNs;
|
|
45
|
+
return BigInt(Date.now()) * 1000000n - changed > racyWindowNs;
|
|
46
|
+
}
|
|
47
|
+
function readDirEntries(root) {
|
|
48
|
+
try {
|
|
49
|
+
return readdirSync(root, { withFileTypes: true });
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (errorCode(error) === "ENOENT") return [];
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function walkTree(root, directories, files, nested = false) {
|
|
56
|
+
const before = statOrMissing(root);
|
|
57
|
+
let trusted = before !== void 0 && isSettled(before);
|
|
58
|
+
if (before) directories.set(root, signature(before));
|
|
59
|
+
if (nested && existsSync(resolve(root, ".git"))) return trusted;
|
|
60
|
+
for (const entry of readDirEntries(root)) {
|
|
61
|
+
const path = resolve(root, entry.name);
|
|
62
|
+
if (entry.isDirectory() && !entry.isSymbolicLink()) {
|
|
63
|
+
if (entry.name.startsWith(".") || ignoredDirs.has(entry.name)) continue;
|
|
64
|
+
if (!walkTree(path, directories, files, true)) trusted = false;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (entry.isFile()) files.push({
|
|
68
|
+
hidden: entry.name.startsWith("."),
|
|
69
|
+
name: entry.name,
|
|
70
|
+
path
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return trusted;
|
|
74
|
+
}
|
|
75
|
+
function isCurrent(tree) {
|
|
76
|
+
for (const [directory, stored] of tree.directories) {
|
|
77
|
+
const stats = statOrMissing(directory);
|
|
78
|
+
if (!stats || signature(stats) !== stored) return false;
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
function sourceTree(root) {
|
|
83
|
+
const trees = store().trees;
|
|
84
|
+
const cached = trees.get(root);
|
|
85
|
+
if (cached && isCurrent(cached)) return cached;
|
|
86
|
+
const directories = /* @__PURE__ */ new Map();
|
|
87
|
+
const files = [];
|
|
88
|
+
const trusted = walkTree(root, directories, files);
|
|
89
|
+
files.sort((left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0);
|
|
90
|
+
const tree = {
|
|
91
|
+
directories,
|
|
92
|
+
files
|
|
93
|
+
};
|
|
94
|
+
if (trusted) trees.set(root, tree);
|
|
95
|
+
else trees.delete(root);
|
|
96
|
+
return tree;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The files below `root` whose name matches `predicate`, sorted by path. The walk skips hidden folders, Git
|
|
100
|
+
* repositories, and build output folders such as `node_modules`, `dist`, and `.vitehub`. Hidden files need
|
|
101
|
+
* `includeHidden`. Symbolic links are skipped.
|
|
102
|
+
*/
|
|
103
|
+
function listSourceTreeFiles(root, predicate, options = {}) {
|
|
104
|
+
const files = [];
|
|
105
|
+
for (const file of sourceTree(resolve(root)).files) {
|
|
106
|
+
if (file.hidden && !options.includeHidden) continue;
|
|
107
|
+
if (predicate(file.name)) files.push(file.path);
|
|
108
|
+
}
|
|
109
|
+
return files;
|
|
110
|
+
}
|
|
111
|
+
/** The UTF-8 text of a source file. A file that did not change since the last read is not read again. */
|
|
112
|
+
function readSourceText(file) {
|
|
113
|
+
const path = resolve(file);
|
|
114
|
+
const texts = store().texts;
|
|
115
|
+
const stats = statOrMissing(path);
|
|
116
|
+
if (!stats) return readFileSync(path, "utf8");
|
|
117
|
+
const current = signature(stats);
|
|
118
|
+
const cached = texts.get(path);
|
|
119
|
+
if (cached?.trusted && cached.signature === current) return cached.text;
|
|
120
|
+
const read = readFileSync(path, "utf8");
|
|
121
|
+
const text = cached?.text === read ? cached.text : read;
|
|
122
|
+
texts.set(path, {
|
|
123
|
+
signature: current,
|
|
124
|
+
text,
|
|
125
|
+
trusted: isSettled(stats)
|
|
126
|
+
});
|
|
127
|
+
return text;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* A value that `compute` derives from the text of a source file, such as its syntax tree. The value is computed again
|
|
131
|
+
* only when the text changes. `kind` separates the values of different callers for one file. The last two texts of a
|
|
132
|
+
* file are kept, because some callers read both the file and its transformed code.
|
|
133
|
+
*/
|
|
134
|
+
function deriveFromSource(kind, file, source, compute) {
|
|
135
|
+
const derived = store().derived;
|
|
136
|
+
const key = `${kind}\0${file}`;
|
|
137
|
+
const entries = derived.get(key) ?? [];
|
|
138
|
+
const cached = entries.find((entry) => entry.source === source);
|
|
139
|
+
if (cached) return cached.value;
|
|
140
|
+
const value = compute();
|
|
141
|
+
derived.set(key, [{
|
|
142
|
+
source,
|
|
143
|
+
value
|
|
144
|
+
}, ...entries.slice(0, 1)]);
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
export { listSourceTreeFiles as n, readSourceText as r, deriveFromSource as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as isRecord } from "./object-DRSmpe04.js";
|
|
2
|
-
import { t as queueErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
+
import { t as queueErrorDiagnostics } from "./error-diagnostics-Yj8XCiya.js";
|
|
3
3
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
4
|
// ../internal/src/runtime/cloudflare-env-lookup.ts
|
|
5
5
|
/** The key of the AsyncLocalStorage store on `globalThis`. Every bundled copy of this module shares the store. */
|
|
@@ -117,6 +117,7 @@ let runtimeConfig;
|
|
|
117
117
|
let runtimeClientFactory;
|
|
118
118
|
let registryOverride;
|
|
119
119
|
let jobStore;
|
|
120
|
+
let jobWorkers;
|
|
120
121
|
const queueEventStorage = new AsyncLocalStorage();
|
|
121
122
|
let queueEventDefaults;
|
|
122
123
|
const queueClientCache = /* @__PURE__ */ new Map();
|
|
@@ -133,8 +134,13 @@ function setQueueRuntimeConfig(config, createClient) {
|
|
|
133
134
|
* The stored jobs of a provider that does not keep them in this package's process state. The generated server sets it
|
|
134
135
|
* for the postgres provider, so the Queue operations read jobs without importing the Postgres driver.
|
|
135
136
|
*/
|
|
136
|
-
function setQueueRuntimeJobStore(store) {
|
|
137
|
+
function setQueueRuntimeJobStore(store, workers) {
|
|
137
138
|
jobStore = store;
|
|
139
|
+
jobWorkers = store ? workers : void 0;
|
|
140
|
+
}
|
|
141
|
+
/** Whether this process runs the jobs of the store that `setQueueRuntimeJobStore()` set. `QUEUE_WORKERS=false` turns it off. */
|
|
142
|
+
function getQueueRuntimeJobWorkers() {
|
|
143
|
+
return jobWorkers;
|
|
138
144
|
}
|
|
139
145
|
async function getQueueRuntimeJobStore() {
|
|
140
146
|
return await jobStore?.();
|
|
@@ -190,4 +196,4 @@ async function loadQueueDefinition(name) {
|
|
|
190
196
|
if (isQueueDefinition(loaded)) return loaded;
|
|
191
197
|
if (isRecord(loaded) && Object.hasOwn(loaded, "default") && isQueueDefinition(loaded.default)) return loaded.default;
|
|
192
198
|
}
|
|
193
|
-
export {
|
|
199
|
+
export { resolveWaitUntil as _, getQueueRuntimeEvent as a, listQueueDefinitionNames as c, runWithQueueRuntimeEvent as d, setQueueRuntimeConfig as f, createCloudflareRuntimeEvent as g, setQueueRuntimeRegistry as h, getQueueRuntimeConfig as i, loadQueueDefinition as l, setQueueRuntimeJobStore as m, getOrCreateQueueClient as n, getQueueRuntimeJobStore as o, setQueueRuntimeEventDefaults as p, getQueueRuntimeClientFactory as r, getQueueRuntimeJobWorkers as s, enterQueueRuntimeEvent as t, missingQueueDefinitionError as u, runWithActiveCloudflareEnv as v, getCloudflareEnv as y };
|
|
@@ -16,6 +16,7 @@ interface CloudflareQueueSendBatchMessage<T = unknown> extends CloudflareQueueSe
|
|
|
16
16
|
/** One job in `sendBatch()` of a Cloudflare QueueClient. */
|
|
17
17
|
interface CloudflareQueueSendBatchItem<T = unknown> {
|
|
18
18
|
body: T;
|
|
19
|
+
transaction?: never;
|
|
19
20
|
contentType?: CloudflareQueueContentType;
|
|
20
21
|
/** Time before delivery, such as `"1m"`. */
|
|
21
22
|
delay?: Duration;
|
|
@@ -53,6 +54,8 @@ interface CloudflareQueueBatchHandlerOptions<T = unknown> {
|
|
|
53
54
|
onMessage: (message: CloudflareQueueMessage<T>, batch: CloudflareQueueMessageBatch<T>) => unknown | Promise<unknown>;
|
|
54
55
|
/** The Queue Definition name in delivery error reports. Defaults to the name that `batch.queue` encodes. */
|
|
55
56
|
queue?: string;
|
|
57
|
+
/** The wait before a retry. The attempt limit is the consumer's `max_retries`, which the build sets from `retries.limit`. */
|
|
58
|
+
retries?: QueueRetries;
|
|
56
59
|
}
|
|
57
60
|
type VercelQueueRetryDirective = {
|
|
58
61
|
acknowledge: true;
|
|
@@ -96,6 +99,7 @@ type VercelQueueBatchSendResult = {
|
|
|
96
99
|
*/
|
|
97
100
|
interface VercelQueueSendBatchMessage<T = unknown> {
|
|
98
101
|
body: T;
|
|
102
|
+
transaction?: never;
|
|
99
103
|
/** Time before delivery, such as `"1m"`. */
|
|
100
104
|
delay?: Duration;
|
|
101
105
|
idempotencyKey?: string;
|
|
@@ -104,6 +108,7 @@ interface VercelQueueSendBatchMessage<T = unknown> {
|
|
|
104
108
|
}
|
|
105
109
|
/** Options that apply to every job of a Vercel `sendBatch()` unless the job sets its own. */
|
|
106
110
|
interface VercelQueueSendBatchOptions {
|
|
111
|
+
transaction?: never;
|
|
107
112
|
delay?: Duration;
|
|
108
113
|
retention?: Duration | number;
|
|
109
114
|
}
|
|
@@ -151,8 +156,8 @@ interface LocalQueueDriverOptions extends QueueSharedOptions {
|
|
|
151
156
|
rules?: LocalQueueRules;
|
|
152
157
|
}
|
|
153
158
|
/**
|
|
154
|
-
* The driver whose documented
|
|
155
|
-
*
|
|
159
|
+
* The driver whose documented limits the local driver follows: the largest delay, payload, and batch, and the
|
|
160
|
+
* enqueue options it accepts. Retries follow `retries` of the Queue Definition on every driver. In `vite dev`, a Cloudflare or Vercel app runs its jobs
|
|
156
161
|
* with the local driver and the rules of its hosted driver.
|
|
157
162
|
*/
|
|
158
163
|
type LocalQueueRules = QueueDriver;
|
|
@@ -200,8 +205,23 @@ interface QueueJob<TPayload = unknown> {
|
|
|
200
205
|
/** Delivery metadata of the provider, when it gives some. */
|
|
201
206
|
metadata?: unknown;
|
|
202
207
|
payload: TPayload;
|
|
208
|
+
/** Aborts when ViteHub enforces the attempt's `timeout`. A host can stop the attempt first. Pass it to `fetch()` and other calls. */
|
|
209
|
+
signal: AbortSignal;
|
|
203
210
|
}
|
|
204
211
|
type QueueHandler<TPayload = unknown, TResult = unknown> = (job: QueueJob<TPayload>) => TResult;
|
|
212
|
+
/** How the wait between retries grows: `exponential` doubles it after each retry, `constant` keeps it. */
|
|
213
|
+
type QueueRetryBackoff = "constant" | "exponential";
|
|
214
|
+
/** When a failed job runs again. The defaults are `{ limit: 3, delay: '10 seconds', backoff: 'exponential' }`. */
|
|
215
|
+
interface QueueRetries {
|
|
216
|
+
backoff?: QueueRetryBackoff;
|
|
217
|
+
/** How long to wait before the first retry, such as `"30s"`. A wait is never longer than 12 hours. */
|
|
218
|
+
delay?: Duration;
|
|
219
|
+
/**
|
|
220
|
+
* How many times to run the job again after the first attempt fails, from 0 to 100. `0` runs it once. On Cloudflare,
|
|
221
|
+
* write it as a number literal, because the build reads it from the file to set the consumer's `max_retries`.
|
|
222
|
+
*/
|
|
223
|
+
limit?: number;
|
|
224
|
+
}
|
|
205
225
|
/** Options of `defineQueue()`, next to `handler`. */
|
|
206
226
|
interface QueueDefinitionOptions {
|
|
207
227
|
cache?: boolean;
|
|
@@ -216,6 +236,14 @@ interface QueueDefinitionOptions {
|
|
|
216
236
|
name: string;
|
|
217
237
|
}) => unknown | Promise<unknown>;
|
|
218
238
|
onError?: CloudflareQueueBatchHandlerOptions["onError"];
|
|
239
|
+
/** When a failed job runs again. Every provider uses it. See `QueueRetries` for the defaults. */
|
|
240
|
+
retries?: QueueRetries;
|
|
241
|
+
/**
|
|
242
|
+
* ViteHub's time limit for one attempt, such as `"30s"` or `"5 minutes"`. Default `"15 minutes"`. When enforced,
|
|
243
|
+
* `job.signal` aborts and the attempt fails with `QUEUE_JOB_TIMEOUT`. A host can stop the attempt before either
|
|
244
|
+
* occurs. A handler that ignores the signal keeps running and can overlap its retry.
|
|
245
|
+
*/
|
|
246
|
+
timeout?: Duration;
|
|
219
247
|
}
|
|
220
248
|
/** A Queue Definition: `defineQueue({ handler, ...options })`. */
|
|
221
249
|
interface QueueDefinition<TPayload = unknown, TResult = unknown> extends QueueDefinitionOptions {
|
|
@@ -233,28 +261,46 @@ interface QueueEnqueueOptions {
|
|
|
233
261
|
region?: string;
|
|
234
262
|
/** How long the provider keeps the job: a duration such as `"1h"`, or a number of seconds. */
|
|
235
263
|
retention?: Duration | number;
|
|
264
|
+
/**
|
|
265
|
+
* The postgres provider only: a Drizzle transaction of a Postgres Database, the `tx` of `db.transaction(async tx => ...)`.
|
|
266
|
+
* The job is saved in that transaction, so it exists only when the transaction commits, and it runs after the commit.
|
|
267
|
+
* The jobs table must be in the same database as the transaction, else `send()` returns
|
|
268
|
+
* `QUEUE_TRANSACTION_DATABASE_MISMATCH`. Other providers return `QUEUE_UNSUPPORTED_OPTION`.
|
|
269
|
+
*/
|
|
270
|
+
transaction?: QueueTransaction;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* A live Drizzle transaction of a ViteHub Postgres Database, on postgres.js or node-postgres. A Drizzle Database is not a
|
|
274
|
+
* transaction: it has no `rollback()`.
|
|
275
|
+
*/
|
|
276
|
+
interface QueueTransaction {
|
|
277
|
+
readonly _: {
|
|
278
|
+
readonly session: object;
|
|
279
|
+
};
|
|
280
|
+
rollback: () => never;
|
|
236
281
|
}
|
|
237
282
|
type QueueSendResult = {
|
|
238
283
|
messageId?: string;
|
|
239
284
|
status: "queued";
|
|
240
285
|
};
|
|
241
286
|
/** Codes that Queue operations return in the `[error, data]` tuple. Config errors throw instead. */
|
|
242
|
-
type QueueErrorCode = "QUEUE_PROVIDER_FAILED" | "QUEUE_PROVIDER_INVALID_RESPONSE" | "QUEUE_UNSUPPORTED_OPTION" | "RUNTIME_DURATION_INVALID";
|
|
287
|
+
type QueueErrorCode = "QUEUE_PROVIDER_FAILED" | "QUEUE_PROVIDER_INVALID_RESPONSE" | "QUEUE_TRANSACTION_DATABASE_MISMATCH" | "QUEUE_UNSUPPORTED_OPTION" | "RUNTIME_DURATION_INVALID";
|
|
243
288
|
/** Codes that `send()` and `sendBatch()` of a Cloudflare QueueClient return. */
|
|
244
289
|
type CloudflareQueueErrorCode = "QUEUE_PROVIDER_FAILED" | "QUEUE_UNSUPPORTED_OPTION" | "RUNTIME_DURATION_INVALID";
|
|
245
290
|
/** Codes that `send()` and `sendBatch()` of a local QueueClient return. */
|
|
246
291
|
type LocalQueueErrorCode = "QUEUE_PROVIDER_FAILED" | "QUEUE_UNSUPPORTED_OPTION" | "RUNTIME_DURATION_INVALID";
|
|
247
292
|
/** Codes that `send()` and `sendBatch()` of a postgres QueueClient return. */
|
|
248
|
-
type PostgresQueueErrorCode = "QUEUE_PROVIDER_FAILED" | "QUEUE_UNSUPPORTED_OPTION" | "RUNTIME_DURATION_INVALID";
|
|
293
|
+
type PostgresQueueErrorCode = "QUEUE_PROVIDER_FAILED" | "QUEUE_TRANSACTION_DATABASE_MISMATCH" | "QUEUE_UNSUPPORTED_OPTION" | "RUNTIME_DURATION_INVALID";
|
|
249
294
|
/** One job in `sendBatch()` of a local or postgres QueueClient. */
|
|
250
295
|
interface LocalQueueSendBatchMessage<T = unknown> {
|
|
251
296
|
body: T;
|
|
297
|
+
transaction?: never;
|
|
252
298
|
/** Time before delivery, such as `"1m"`. */
|
|
253
299
|
delay?: Duration;
|
|
254
300
|
idempotencyKey?: string;
|
|
255
301
|
}
|
|
256
302
|
/** Codes that `send()` and `sendBatch()` of a Vercel QueueClient return. */
|
|
257
|
-
type VercelQueueErrorCode = QueueErrorCode
|
|
303
|
+
type VercelQueueErrorCode = Exclude<QueueErrorCode, "QUEUE_TRANSACTION_DATABASE_MISMATCH">;
|
|
258
304
|
interface QueueClientBase<P extends QueueDriver = QueueDriver> {
|
|
259
305
|
readonly native: unknown;
|
|
260
306
|
readonly provider: P;
|
|
@@ -266,7 +312,9 @@ interface CloudflareQueueClient<TPayload = unknown> extends QueueClientBase<"clo
|
|
|
266
312
|
readonly binding: CloudflareQueueBinding;
|
|
267
313
|
createBatchHandler: <TMessage = unknown>(options: CloudflareQueueBatchHandlerOptions<TMessage>) => (batch: CloudflareQueueMessageBatch<TMessage>) => Promise<void>;
|
|
268
314
|
send: (payload: TPayload, options?: QueueEnqueueOptions) => Promise<Result<QueueSendResult, CloudflareQueueErrorCode>>;
|
|
269
|
-
sendBatch: (items: CloudflareQueueSendBatchItem<TPayload>[], options?: QueueEnqueueOptions
|
|
315
|
+
sendBatch: (items: CloudflareQueueSendBatchItem<TPayload>[], options?: Omit<QueueEnqueueOptions, "transaction"> & {
|
|
316
|
+
transaction?: never;
|
|
317
|
+
}) => Promise<Result<QueueSendResult[], CloudflareQueueErrorCode>>;
|
|
270
318
|
}
|
|
271
319
|
/**
|
|
272
320
|
* `send()` and `sendBatch()` return `[error, data]`. `error.code` is one of the codes in the method type.
|
|
@@ -292,6 +340,7 @@ interface LocalQueueClient<TPayload = unknown> extends QueueClientBase<"local">
|
|
|
292
340
|
send: (payload: TPayload, options?: QueueEnqueueOptions) => Promise<Result<QueueSendResult, LocalQueueErrorCode>>;
|
|
293
341
|
sendBatch: (items: LocalQueueSendBatchMessage<TPayload>[], options?: {
|
|
294
342
|
delay?: Duration;
|
|
343
|
+
transaction?: never;
|
|
295
344
|
}) => Promise<Result<QueueSendResult[], LocalQueueErrorCode>>;
|
|
296
345
|
}
|
|
297
346
|
/**
|
|
@@ -304,6 +353,7 @@ interface PostgresQueueClient<TPayload = unknown> extends QueueClientBase<"postg
|
|
|
304
353
|
/** Inserts all jobs in one transaction. When one insert fails, no job of the batch is stored. */
|
|
305
354
|
sendBatch: (items: LocalQueueSendBatchMessage<TPayload>[], options?: {
|
|
306
355
|
delay?: Duration;
|
|
356
|
+
transaction?: never;
|
|
307
357
|
}) => Promise<Result<QueueSendResult[], PostgresQueueErrorCode>>;
|
|
308
358
|
}
|
|
309
359
|
interface QueueClientMap<TPayload> {
|
|
@@ -313,6 +363,11 @@ interface QueueClientMap<TPayload> {
|
|
|
313
363
|
vercel: VercelQueueClient<TPayload>;
|
|
314
364
|
}
|
|
315
365
|
type QueueClient<P extends QueueDriver = QueueDriver, TPayload = unknown> = QueueClientMap<TPayload>[P];
|
|
366
|
+
/**
|
|
367
|
+
* The client that `useQueue()` and `dynamicQueue.use()` return. `send()` and `sendBatch()` load the provider on the
|
|
368
|
+
* first call. `provider` is `local` in `vite dev` and in tests. Use `createQueueClient()` for the provider's `native` object.
|
|
369
|
+
*/
|
|
370
|
+
type NamedQueueClient<P extends QueueDriver = QueueDriver, TPayload = unknown> = P extends QueueDriver ? Pick<QueueClientMap<TPayload>[P], "provider" | "send" | "sendBatch"> : never;
|
|
316
371
|
/** Discovered Queue Definitions. Generated declarations extend this interface. */
|
|
317
372
|
interface QueueRegistry {}
|
|
318
373
|
type QueueName = Extract<keyof QueueRegistry, string>;
|
|
@@ -345,8 +400,6 @@ interface QueueDeliveryErrorDetails {
|
|
|
345
400
|
}
|
|
346
401
|
/** The delivery rules that the local engine applies. */
|
|
347
402
|
interface LocalQueueDeliveryRules {
|
|
348
|
-
/** Deliveries before a failing job becomes a dead job. `Infinity` retries until the job expires. */
|
|
349
|
-
maxAttempts: number;
|
|
350
403
|
/** Largest `delay`, in seconds, that a send accepts. */
|
|
351
404
|
maxDelaySeconds?: number;
|
|
352
405
|
/** Largest number of jobs in one `sendBatch()`. */
|
|
@@ -361,12 +414,10 @@ interface LocalQueueDeliveryRules {
|
|
|
361
414
|
maxSeconds: number;
|
|
362
415
|
minSeconds: number;
|
|
363
416
|
};
|
|
364
|
-
/** Milliseconds before the next delivery after `attempts` failed deliveries. */
|
|
365
|
-
retryDelayMs: (attempts: number) => number;
|
|
366
417
|
/** The provider whose documented rules these are. */
|
|
367
418
|
rules: LocalQueueRules;
|
|
368
419
|
/** Enqueue options that fail with `QUEUE_UNSUPPORTED_OPTION`. */
|
|
369
|
-
unsupportedOptions: readonly ("contentType" | "idempotencyKey" | "region" | "retention")[];
|
|
420
|
+
unsupportedOptions: readonly ("contentType" | "idempotencyKey" | "region" | "retention" | "transaction")[];
|
|
370
421
|
}
|
|
371
422
|
interface LocalQueueStatus {
|
|
372
423
|
/** Absolute directory of the local provider, or the Postgres table and database, without the password. */
|
|
@@ -418,6 +469,12 @@ interface LocalQueueClearFilter {
|
|
|
418
469
|
queue?: string;
|
|
419
470
|
state?: "dead" | "pending";
|
|
420
471
|
}
|
|
472
|
+
/** What `retryDead()` did: how many dead jobs run again, and the message IDs of the dead jobs that it skipped. */
|
|
473
|
+
interface QueueRetryDeadResult {
|
|
474
|
+
retried: number;
|
|
475
|
+
/** Dead jobs whose `idempotencyKey` a live job or a newer dead job holds. They stay dead. */
|
|
476
|
+
skipped: string[];
|
|
477
|
+
}
|
|
421
478
|
/**
|
|
422
479
|
* The stored jobs of a provider that ViteHub can read: the local and the postgres provider. The Queue operations,
|
|
423
480
|
* so `vitehub queue jobs` and the Console, read jobs through it.
|
|
@@ -438,7 +495,12 @@ interface QueueJobStore {
|
|
|
438
495
|
* live job holds the `idempotencyKey` of the dead job.
|
|
439
496
|
*/
|
|
440
497
|
retry: (id: string) => Promise<LocalQueueJob | "duplicate" | "missing" | "running">;
|
|
498
|
+
/**
|
|
499
|
+
* Gives every dead job of the queue a new set of attempts and runs it now, in batches of 500. A dead job is skipped
|
|
500
|
+
* when a live job or a newer dead job holds its `idempotencyKey`.
|
|
501
|
+
*/
|
|
502
|
+
retryDead: (queue: string) => Promise<QueueRetryDeadResult>;
|
|
441
503
|
readonly rules: LocalQueueDeliveryRules;
|
|
442
504
|
status: () => Promise<LocalQueueStatus>;
|
|
443
505
|
}
|
|
444
|
-
export {
|
|
506
|
+
export { QueueJob as A, QueueSendResult as B, QueueDefinitionOptions as C, QueueEnqueueOptions as D, QueueDriverOptions as E, QueuePayload as F, VercelQueueCallbackOptions as G, ResolvedLocalQueueOptions as H, QueueRegistry as I, VercelQueueRetryDirective as J, VercelQueueClient as K, QueueRetries as L, QueueModuleDriverOptions as M, QueueName as N, QueueErrorCode as O, QueueOptions as P, VercelQueueSendResult as Q, QueueRetryBackoff as R, QueueDefinition as S, QueueDriver as T, ResolvedQueueOptions as U, QueueTransaction as V, VercelQueueBatchSendResult as W, VercelQueueSendBatchMessage as X, VercelQueueRetryHandler as Y, VercelQueueSendBatchOptions as Z, NodeQueueDriver as _, CloudflareQueueMessageBatch as a, PostgresQueueErrorCode as b, LocalQueueClient as c, LocalQueueJob as d, LocalQueueJobDetail as f, NamedQueueClient as g, LocalQueueStatus as h, CloudflareQueueMessage as i, QueueJobStore as j, QueueHandler as k, LocalQueueDriverOptions as l, LocalQueueSendBatchMessage as m, CloudflareQueueClient as n, CloudflareQueueSendBatchItem as o, LocalQueueRules as p, VercelQueueErrorCode as q, CloudflareQueueErrorCode as r, DiscoveredQueueDefinition as s, CloudflareQueueBatchHandlerOptions as t, LocalQueueErrorCode as u, PostgresQueueClient as v, QueueDefinitionRegistry as w, QueueClient as x, PostgresQueueDriverOptions as y, QueueRetryDeadResult as z };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as OperationContributionEntry } from "./
|
|
3
|
-
import "nostics";
|
|
1
|
+
import { P as QueueOptions, s as DiscoveredQueueDefinition } from "./types-rZHAtkK0.js";
|
|
2
|
+
import { n as OperationContributionEntry, r as ViteHubCliContributor } from "./operations-DSslh_vK.js";
|
|
4
3
|
import { Plugin, UserConfig } from "vite";
|
|
5
4
|
/** The host that ViteHub builds for: the `host` option of `vitehub()` and the value of `VITEHUB_HOST`. */
|
|
6
5
|
type ViteHubHost = "cloudflare" | "deno" | "netlify" | "node" | "vercel";
|
|
@@ -112,158 +111,6 @@ interface DurabilityPluginMetadata {
|
|
|
112
111
|
/** Called after Vite resolves the config. Return an empty list when the primitive is off. */
|
|
113
112
|
durability?: () => readonly DurabilityContribution[];
|
|
114
113
|
}
|
|
115
|
-
interface HostCliRunResult {
|
|
116
|
-
exitCode: number | null;
|
|
117
|
-
stdout: string;
|
|
118
|
-
stderr?: string;
|
|
119
|
-
}
|
|
120
|
-
/** Runs a host CLI with an argument array and no shell, and returns its stdout. */
|
|
121
|
-
type HostCliRun = (command: string, args: readonly string[], options: {
|
|
122
|
-
cwd?: string;
|
|
123
|
-
env: NodeJS.ProcessEnv;
|
|
124
|
-
signal?: AbortSignal;
|
|
125
|
-
}) => Promise<HostCliRunResult>;
|
|
126
|
-
type ProvisionProvider = "cloudflare" | "vercel";
|
|
127
|
-
interface ProvisionLogger {
|
|
128
|
-
log: (message: string) => void;
|
|
129
|
-
warn: (message: string) => void;
|
|
130
|
-
}
|
|
131
|
-
interface ProvisionContext {
|
|
132
|
-
env: Record<string, string | undefined>;
|
|
133
|
-
fetch: typeof globalThis.fetch;
|
|
134
|
-
logger: ProvisionLogger;
|
|
135
|
-
markPlanUnchecked?: () => void;
|
|
136
|
-
}
|
|
137
|
-
interface ProvisionState {
|
|
138
|
-
cloudflare?: Record<string, Record<string, string>>;
|
|
139
|
-
vercel?: Record<string, Record<string, string>>;
|
|
140
|
-
}
|
|
141
|
-
interface ProvisionResult {
|
|
142
|
-
ids?: ProvisionState;
|
|
143
|
-
}
|
|
144
|
-
interface ProvisionAction {
|
|
145
|
-
kind: string;
|
|
146
|
-
name: string;
|
|
147
|
-
exists: boolean;
|
|
148
|
-
pending?: boolean;
|
|
149
|
-
/** Describes the change that `apply()` makes to an existing resource, for example `read replication: disabled -> auto`. */
|
|
150
|
-
update?: string;
|
|
151
|
-
apply: () => Promise<ProvisionResult>;
|
|
152
|
-
}
|
|
153
|
-
/** One Provision State category that a step records, with the keys that current Definitions use. */
|
|
154
|
-
interface ProvisionStateCategory {
|
|
155
|
-
category: string;
|
|
156
|
-
declared: readonly string[];
|
|
157
|
-
/** Provider resource identity for shared-resource checks. Return undefined when the recorded id lacks enough information. Defaults to the recorded id. */
|
|
158
|
-
resourceIdentity?: (entry: {
|
|
159
|
-
id: string;
|
|
160
|
-
key: string;
|
|
161
|
-
}) => string | undefined;
|
|
162
|
-
/** Identity expected by current config for a declared key. Omit when it cannot be established without provider access. */
|
|
163
|
-
declaredResourceIdentity?: (key: string) => string | undefined;
|
|
164
|
-
/** Tells a developer how to delete the resource of a recorded entry that no Definition declares. ViteHub never runs it. */
|
|
165
|
-
deleteHint: (entry: {
|
|
166
|
-
id: string;
|
|
167
|
-
key: string;
|
|
168
|
-
}) => string;
|
|
169
|
-
}
|
|
170
|
-
interface ProvisionStep {
|
|
171
|
-
id: string;
|
|
172
|
-
provider: ProvisionProvider;
|
|
173
|
-
plan: (context: ProvisionContext) => Promise<ProvisionAction[]>;
|
|
174
|
-
/** Describes the Provision State this step records. Runs without network access, also without credentials. */
|
|
175
|
-
recordedState?: (context: Pick<ProvisionContext, "env">) => ProvisionStateCategory[];
|
|
176
|
-
}
|
|
177
|
-
interface ViteHubCliStreams {
|
|
178
|
-
stderr: {
|
|
179
|
-
write: (chunk: string | Uint8Array, encoding?: BufferEncoding | StdoutWriteCallback, callback?: StdoutWriteCallback) => unknown;
|
|
180
|
-
};
|
|
181
|
-
stdout: {
|
|
182
|
-
write: (chunk: string | Uint8Array) => unknown;
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
interface ViteHubCliSpawnResult {
|
|
186
|
-
exitCode: number | null;
|
|
187
|
-
signal?: NodeJS.Signals | null;
|
|
188
|
-
/** The output of the child when `stdout` is `pipe`. */
|
|
189
|
-
stdout?: string;
|
|
190
|
-
}
|
|
191
|
-
interface ViteHubCliSpawnOptions {
|
|
192
|
-
cwd?: string;
|
|
193
|
-
env?: NodeJS.ProcessEnv;
|
|
194
|
-
stderr?: "inherit" | "pipe";
|
|
195
|
-
/** `ignore` gives the child no terminal input, so a tool that asks questions on a terminal does not ask. */
|
|
196
|
-
stdin?: "ignore" | "inherit";
|
|
197
|
-
/** `stderr` sends the child's stdout to the parent's stderr, so the parent's stdout keeps only its own output. */
|
|
198
|
-
stdout?: "inherit" | "pipe" | "stderr";
|
|
199
|
-
}
|
|
200
|
-
type ViteHubCliSpawn = (command: string, args: string[], options?: ViteHubCliSpawnOptions) => Promise<ViteHubCliSpawnResult>;
|
|
201
|
-
interface ViteHubCliContext extends ViteHubCliStreams {
|
|
202
|
-
cwd: string;
|
|
203
|
-
env: NodeJS.ProcessEnv;
|
|
204
|
-
/** Replaces `fetch` for commands that call a running app, so tests need no server. */
|
|
205
|
-
fetch?: typeof fetch;
|
|
206
|
-
/**
|
|
207
|
-
* Loads the project config for a build on `host` and returns the Provision Steps of its plugins, with the config root
|
|
208
|
-
* that holds `.vitehub/provision.json`. Setup commands, such as `vitehub deploy`, call it only when they need the
|
|
209
|
-
* steps, so they still run on a config that throws.
|
|
210
|
-
*/
|
|
211
|
-
loadProvision?: (host: ProvisionProvider) => Promise<ViteHubCliProvision>;
|
|
212
|
-
/** The deployed app's public origin from `vitehub({ publicUrl })`, when it is one string. */
|
|
213
|
-
publicUrl?: string;
|
|
214
|
-
rootDir: string;
|
|
215
|
-
/** Replaces the host CLI runner, such as for `wrangler auth token`, so tests need no real host CLI. */
|
|
216
|
-
runHostCli?: HostCliRun;
|
|
217
|
-
spawn: ViteHubCliSpawn;
|
|
218
|
-
}
|
|
219
|
-
interface ViteHubCliProvision {
|
|
220
|
-
rootDir: string;
|
|
221
|
-
steps: readonly ProvisionStep[];
|
|
222
|
-
}
|
|
223
|
-
interface ViteHubCliFeature {
|
|
224
|
-
description?: string;
|
|
225
|
-
name: string;
|
|
226
|
-
run: (args: string[], context: ViteHubCliContext) => Promise<number | void> | number | void;
|
|
227
|
-
usage?: string;
|
|
228
|
-
}
|
|
229
|
-
interface ViteHubCliCommandNamespace {
|
|
230
|
-
/** The feature that `vitehub <name>` runs when the next argument names no other feature. It gets every argument after `<name>`. */
|
|
231
|
-
defaultFeature?: string;
|
|
232
|
-
description?: string;
|
|
233
|
-
features: ViteHubCliFeature[];
|
|
234
|
-
name: string;
|
|
235
|
-
}
|
|
236
|
-
/** The flags of `vitehub seed` that every seed gets. */
|
|
237
|
-
interface ViteHubCliSeedOptions {
|
|
238
|
-
/** `--database <name>`: seed only this Database. Only the Database seed runs. */
|
|
239
|
-
database?: string;
|
|
240
|
-
/** The process environment with the env files of `--stage`. */
|
|
241
|
-
env: NodeJS.ProcessEnv;
|
|
242
|
-
/** `--remote`: write the deployed stores. Without it, a seed writes only local data. */
|
|
243
|
-
remote: boolean;
|
|
244
|
-
/** `--timeout <ms>` of each call to the app. */
|
|
245
|
-
timeout?: number;
|
|
246
|
-
/** The deployed app with `--remote`: `--url`, or `vitehub({ publicUrl })`. */
|
|
247
|
-
url?: string;
|
|
248
|
-
}
|
|
249
|
-
/** The seed files of one primitive, which `vitehub seed` writes. */
|
|
250
|
-
interface ViteHubCliSeed {
|
|
251
|
-
/** Where the seed files are, such as `server/seed/kv/`. `vitehub seed` names it when it finds no seed files. */
|
|
252
|
-
files: string;
|
|
253
|
-
/** The primitive, such as `database` or `kv`. `vitehub seed <name>` runs only this seed. */
|
|
254
|
-
name: string;
|
|
255
|
-
/** Writes the seed files and returns the exit code, or `undefined` when the project has no seed files for this primitive. */
|
|
256
|
-
run: (options: ViteHubCliSeedOptions, context: ViteHubCliContext) => Promise<number | undefined>;
|
|
257
|
-
}
|
|
258
|
-
interface ViteHubCliContributor {
|
|
259
|
-
namespaces: ViteHubCliCommandNamespace[];
|
|
260
|
-
provision?: ProvisionStep[];
|
|
261
|
-
/** The seed files that `vitehub seed` writes. */
|
|
262
|
-
seeds?: ViteHubCliSeed[];
|
|
263
|
-
/** The deployed app's public origin. Commands receive it as `context.publicUrl`. */
|
|
264
|
-
publicUrl?: string;
|
|
265
|
-
}
|
|
266
|
-
type StdoutWriteCallback = (error?: Error | null) => void;
|
|
267
114
|
/** Module and export that hold a contributed Definition. */
|
|
268
115
|
interface ContributionDefinition {
|
|
269
116
|
/**
|