@vite-hub/kv 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/dist/{cli-DpPhz_Ek.d.ts → cli-CLomw9ml.d.ts} +1 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +22 -11
- package/dist/{cloudflare-env-lOtHHsgP.js → cloudflare-env-Dl349h_9.js} +2 -1
- package/dist/{cloudflare-kv-C3NO4C21.js → cloudflare-kv-DQJhmGof.js} +8 -10
- package/dist/{cloudflare-kv-local-C2sbIrFy.js → cloudflare-kv-local-COjgHweC.js} +3 -7
- package/dist/{config-LfpUj9hs.js → config-pfyPiPrI.js} +47 -12
- package/dist/{create-storage-BORQm2a8.js → create-storage-DQ1BbFqH.js} +1 -1
- package/dist/{cursor-history-DRHh5bO5.js → cursor-history-CAT4mpP1.js} +7 -3
- package/dist/{deno-kv-D_VtffFv.js → deno-kv-Cf0ZveeN.js} +43 -7
- package/dist/driver-Du6Eh9p2.d.ts +47 -0
- package/dist/{error-diagnostics-C54QQEhN.js → error-diagnostics-C4VTHInS.js} +6 -2
- package/dist/{errors-DzD6YNEH.js → errors-BpiM-Vmh.js} +41 -4
- package/dist/errors.d.ts +8 -1
- package/dist/errors.js +2 -2
- package/dist/{fs-lite-BaklCLuV.js → fs-lite-BTcBUP6B.js} +1 -1
- package/dist/fs-lite-C8yXCVDM.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +27 -55
- package/dist/{operation-definition-nmRu_O3V.d.ts → operation-definition-CI2PJGqu.d.ts} +8 -2
- package/dist/{operations-CtrWLmPK.js → operations-CqKs7Ykc.js} +22 -37
- package/dist/{operations-D2iI9oN4.js → operations-nAaONxzh.js} +38 -8
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +3 -3
- package/dist/out-BbXG-yVX.js +21755 -0
- package/dist/{redis-shared-5ogRd3-Y.js → redis-shared-1M0IaguQ.js} +1 -1
- package/dist/request-log-Dj9Vw7qG.js +105 -0
- package/dist/{results-p7nPCnaJ.js → results-D6jfPtCk.js} +0 -1
- package/dist/rolldown-runtime-CMFfr-1z.js +26 -0
- package/dist/runtime/cloudflare-kv.d.ts +1 -1
- package/dist/runtime/cloudflare-kv.js +1 -1
- package/dist/runtime/cloudflare-request-env.js +1 -1
- package/dist/runtime/database.d.ts +2 -0
- package/dist/{database-oJdy0ZVX.js → runtime/database.js} +68 -37
- package/dist/runtime/nitro-plugin.js +10 -6
- package/dist/runtime/redis-driver.d.ts +2 -2
- package/dist/runtime/redis-driver.js +2 -5
- package/dist/runtime/upstash-driver.d.ts +2 -2
- package/dist/runtime/upstash-driver.js +2 -6
- package/dist/{types-Dv-OSXZC.d.ts → types-Cp6IBhSN.d.ts} +3 -17
- package/dist/{upstash-B-vaUYqO.js → upstash-5sTbIR35.js} +2 -2
- package/dist/vite.d.ts +8 -5
- package/dist/vite.js +2102 -46
- package/package.json +9 -4
- package/dist/driver-R4Z5Z5fl.d.ts +0 -15
- package/dist/fs-lite-BAgpmNAF.js +0 -2
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { n as kvErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
-
import { a as kvResult,
|
|
3
|
-
import { r as normalizeKVOptions, s as readEnv } from "./config-
|
|
1
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-C4VTHInS.js";
|
|
2
|
+
import { a as kvResult, d as listKVKeys, f as kvStoreWithMode, i as kvListLimitInvalid, o as kvSetCodes, p as ttlSeconds, r as kvKeyLimitCodes, s as kvSetTTL, t as kvClearOptionsError } from "./errors-BpiM-Vmh.js";
|
|
3
|
+
import { r as normalizeKVOptions, s as readEnv } from "./config-pfyPiPrI.js";
|
|
4
4
|
import { n as getActiveCloudflareEnv } from "./cloudflare-env-lookup-Bs0VDpU5.js";
|
|
5
|
-
import { n as normalizeKVListPrefix, t as createKVStorage$1 } from "./create-storage-
|
|
5
|
+
import { n as normalizeKVListPrefix, t as createKVStorage$1 } from "./create-storage-DQ1BbFqH.js";
|
|
6
6
|
import { o as normalizeKey } from "./utils2-FozcTsmb.js";
|
|
7
|
-
import { t as resolveRuntimeKVOptions } from "./upstash-
|
|
7
|
+
import { t as resolveRuntimeKVOptions } from "./upstash-5sTbIR35.js";
|
|
8
8
|
import { i as setItemsOneByOne, n as getItemsOneByOne } from "./batch--v0ri69O.js";
|
|
9
|
-
import {
|
|
9
|
+
import { t as logFailure } from "./request-log-Dj9Vw7qG.js";
|
|
10
10
|
import { getViteHubTestMode } from "@vite-hub/runtime/internal/test-mode";
|
|
11
11
|
import { destr } from "destr";
|
|
12
12
|
//#region src/runtime/driver.ts
|
|
@@ -19,7 +19,6 @@ const lazyDriverMethods = /* @__PURE__ */ new Set([
|
|
|
19
19
|
"removeItem",
|
|
20
20
|
"setItem"
|
|
21
21
|
]);
|
|
22
|
-
/** The driver method behind each atomic KV operation. */
|
|
23
22
|
const atomicDriverMethods = {
|
|
24
23
|
deleteIfEquals: "deleteIfEqualsItem",
|
|
25
24
|
getAndDelete: "getAndDeleteItem",
|
|
@@ -49,7 +48,6 @@ const driverAtomicOperations = {
|
|
|
49
48
|
setIfAbsent: true
|
|
50
49
|
}
|
|
51
50
|
};
|
|
52
|
-
/** Other optional unstorage methods that a driver has. */
|
|
53
51
|
const otherOptionalDriverMethods = {
|
|
54
52
|
"cloudflare": ["validateBatch"],
|
|
55
53
|
"fs-lite": [
|
|
@@ -58,11 +56,10 @@ const otherOptionalDriverMethods = {
|
|
|
58
56
|
"setItemRaw"
|
|
59
57
|
]
|
|
60
58
|
};
|
|
61
|
-
/** Batch methods. A driver without one gets a version that calls the single-key method for each key. */
|
|
62
59
|
const batchDriverMethods = /* @__PURE__ */ new Set(["getItems", "setItems"]);
|
|
63
60
|
const lazyOptionalDriverMethods = Object.fromEntries(Object.entries(driverAtomicOperations).map(([driver, operations]) => [driver, /* @__PURE__ */ new Set([...Object.keys(operations).map((operation) => atomicDriverMethods[operation]), ...otherOptionalDriverMethods[driver] ?? []])]));
|
|
64
61
|
async function createDatabaseDriver(store, loadDatabases) {
|
|
65
|
-
const { default: factory, kvSqlClientFromDatabase } = await import("./database
|
|
62
|
+
const { default: factory, kvSqlClientFromDatabase } = await import("./runtime/database.js");
|
|
66
63
|
return factory(store, async () => {
|
|
67
64
|
const entry = loadDatabases ? (await loadDatabases())[store.database] : void 0;
|
|
68
65
|
if (!entry) throw kvErrorDiagnostics.KV_DATABASE_UNAVAILABLE({
|
|
@@ -77,7 +74,7 @@ async function createRuntimeDriver(store, loadDatabases) {
|
|
|
77
74
|
case "cloudflare": {
|
|
78
75
|
const { localBase } = store;
|
|
79
76
|
if (localBase) {
|
|
80
|
-
const { default: factory } = await import("./cloudflare-kv-local-
|
|
77
|
+
const { default: factory } = await import("./cloudflare-kv-local-COjgHweC.js");
|
|
81
78
|
return factory({
|
|
82
79
|
...store,
|
|
83
80
|
localBase
|
|
@@ -88,11 +85,11 @@ async function createRuntimeDriver(store, loadDatabases) {
|
|
|
88
85
|
}
|
|
89
86
|
case "database": return createDatabaseDriver(store, loadDatabases);
|
|
90
87
|
case "deno-kv": {
|
|
91
|
-
const { default: factory } = await import("./deno-kv-
|
|
88
|
+
const { default: factory } = await import("./deno-kv-Cf0ZveeN.js");
|
|
92
89
|
return factory(store);
|
|
93
90
|
}
|
|
94
91
|
case "fs-lite": {
|
|
95
|
-
const { default: factory } = await import("./fs-lite-
|
|
92
|
+
const { default: factory } = await import("./fs-lite-C8yXCVDM.js");
|
|
96
93
|
return factory(store);
|
|
97
94
|
}
|
|
98
95
|
case "redis": {
|
|
@@ -236,23 +233,6 @@ function createHostedKVStorage(config, name = "default", loadDatabases) {
|
|
|
236
233
|
return storage;
|
|
237
234
|
}
|
|
238
235
|
//#endregion
|
|
239
|
-
//#region src/runtime/ttl.ts
|
|
240
|
-
/**
|
|
241
|
-
* The seconds of a KV `ttl`: a number of seconds, or a duration such as `"1h"`. `undefined` when it is not a positive
|
|
242
|
-
* time, so the caller returns `KV_INVALID_TTL`.
|
|
243
|
-
*/
|
|
244
|
-
function ttlSeconds(ttl) {
|
|
245
|
-
let seconds;
|
|
246
|
-
if (typeof ttl === "number") seconds = ttl;
|
|
247
|
-
else if (typeof ttl !== "string") return;
|
|
248
|
-
else try {
|
|
249
|
-
seconds = parseDuration(ttl) / 1e3;
|
|
250
|
-
} catch {
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
return Number.isFinite(seconds) && seconds > 0 && Number.isSafeInteger(Math.ceil(seconds * 1e3)) ? seconds : void 0;
|
|
254
|
-
}
|
|
255
|
-
//#endregion
|
|
256
236
|
//#region src/runtime/lock.ts
|
|
257
237
|
const firstRetryMs = 25;
|
|
258
238
|
const maxRetryMs = 500;
|
|
@@ -305,7 +285,18 @@ function createKVLock(store, resolveStorage, key, options) {
|
|
|
305
285
|
try {
|
|
306
286
|
value = await fn();
|
|
307
287
|
} catch (cause) {
|
|
308
|
-
await lock.release();
|
|
288
|
+
const [releaseError] = await lock.release();
|
|
289
|
+
if (releaseError) logFailure({
|
|
290
|
+
field: "kv",
|
|
291
|
+
fields: {
|
|
292
|
+
op: "lock-release",
|
|
293
|
+
store
|
|
294
|
+
},
|
|
295
|
+
message: "KV could not release a lock after its callback threw",
|
|
296
|
+
error: releaseError.cause
|
|
297
|
+
}, () => {
|
|
298
|
+
console.warn(`[vitehub] KV could not release the lock "${key}" after its callback threw. The lock expires after its ttl.`, releaseError);
|
|
299
|
+
});
|
|
309
300
|
throw cause;
|
|
310
301
|
}
|
|
311
302
|
const [releaseError] = await lock.release();
|
|
@@ -397,17 +388,6 @@ async function runKVOperation(operation, name, run, codes = []) {
|
|
|
397
388
|
const storage = await resolveStorage(name);
|
|
398
389
|
return kvResult(operation, name, () => run(storage), codes);
|
|
399
390
|
}
|
|
400
|
-
function readSetTTL(operation, options) {
|
|
401
|
-
if (options === void 0) return;
|
|
402
|
-
for (const option of Object.keys(options)) if (option !== "ttl") throw kvErrorDiagnostics.KV_INVALID_OPTION({
|
|
403
|
-
operation,
|
|
404
|
-
option
|
|
405
|
-
});
|
|
406
|
-
if (options.ttl === void 0) return;
|
|
407
|
-
const ttl = ttlSeconds(options.ttl);
|
|
408
|
-
if (ttl === void 0) throw kvErrorDiagnostics.KV_INVALID_TTL();
|
|
409
|
-
return ttl;
|
|
410
|
-
}
|
|
411
391
|
function createKVStorage(name = "default") {
|
|
412
392
|
return {
|
|
413
393
|
async clear(options) {
|
|
@@ -465,23 +445,15 @@ function createKVStorage(name = "default") {
|
|
|
465
445
|
},
|
|
466
446
|
async set(key, value, options) {
|
|
467
447
|
return runKVOperation("set", name, async (storage) => {
|
|
468
|
-
const ttl =
|
|
448
|
+
const ttl = kvSetTTL("set", options);
|
|
469
449
|
return storage.setItem(key, value, ttl === void 0 ? void 0 : { ttl });
|
|
470
|
-
},
|
|
471
|
-
...kvWriteLimitCodes,
|
|
472
|
-
"KV_INVALID_OPTION",
|
|
473
|
-
"KV_INVALID_TTL"
|
|
474
|
-
]);
|
|
450
|
+
}, kvSetCodes);
|
|
475
451
|
},
|
|
476
452
|
async setMany(entries, options) {
|
|
477
453
|
return runKVOperation("setMany", name, async (storage) => {
|
|
478
|
-
const ttl =
|
|
454
|
+
const ttl = kvSetTTL("setMany", options);
|
|
479
455
|
return storage.setMany(entries, ttl === void 0 ? void 0 : { ttl });
|
|
480
|
-
},
|
|
481
|
-
...kvWriteLimitCodes,
|
|
482
|
-
"KV_INVALID_OPTION",
|
|
483
|
-
"KV_INVALID_TTL"
|
|
484
|
-
]);
|
|
456
|
+
}, kvSetCodes);
|
|
485
457
|
},
|
|
486
458
|
async setIfAbsent(key, value, options) {
|
|
487
459
|
return runKVOperation("setIfAbsent", name, async (storage) => {
|
|
@@ -489,7 +461,7 @@ function createKVStorage(name = "default") {
|
|
|
489
461
|
operation: "setIfAbsent",
|
|
490
462
|
store: name
|
|
491
463
|
});
|
|
492
|
-
return storage.setIfAbsentItem(key, value,
|
|
464
|
+
return storage.setIfAbsentItem(key, value, kvSetTTL("setIfAbsent", options));
|
|
493
465
|
}, [
|
|
494
466
|
"KV_INVALID_OPTION",
|
|
495
467
|
"KV_INVALID_TTL",
|
|
@@ -104,6 +104,11 @@ interface OperationAccess {
|
|
|
104
104
|
*/
|
|
105
105
|
readonly sections: "all" | readonly string[];
|
|
106
106
|
readonly user?: OperationUser;
|
|
107
|
+
/**
|
|
108
|
+
* Who signed the call: `"console"` when the ViteHub Console signed it for a person, whose `user` is then a Console
|
|
109
|
+
* account and not an app user, or `"cli"` for a key. Not set for other calls.
|
|
110
|
+
*/
|
|
111
|
+
readonly via?: "console" | "cli";
|
|
107
112
|
}
|
|
108
113
|
interface OperationContext {
|
|
109
114
|
/** The checked Console access of the call. */
|
|
@@ -166,7 +171,8 @@ interface OperationDefinition<Input, Output> {
|
|
|
166
171
|
/** Standard Schema (valibot in this repo). Its Standard JSON Schema builds CLI flags and the MCP input schema. */
|
|
167
172
|
input: StandardSchemaV1<unknown, Input>;
|
|
168
173
|
output?: StandardSchemaV1<unknown, Output>;
|
|
169
|
-
|
|
174
|
+
/** `false`: no `vitehub` command. The Console and MCP still call the operation. */
|
|
175
|
+
cli?: false | {
|
|
170
176
|
/** Defaults: namespace = section, command = verb. */
|
|
171
177
|
namespace?: string;
|
|
172
178
|
/** A space groups commands: `jobs list` and `jobs show` run as `vitehub <namespace> jobs list` and `jobs show`. */
|
|
@@ -207,7 +213,7 @@ interface OperationDefinition<Input, Output> {
|
|
|
207
213
|
/** An operation of any input and output, as a registry holds it. */
|
|
208
214
|
interface AnyOperation extends Omit<OperationDefinition<unknown, unknown>, "cli" | "input" | "mcp" | "output" | "readOnlyWhen" | "run" | "scope" | "section"> {
|
|
209
215
|
readOnlyWhen?: (input: never) => boolean;
|
|
210
|
-
cli?: {
|
|
216
|
+
cli?: false | {
|
|
211
217
|
namespace?: string;
|
|
212
218
|
command?: string;
|
|
213
219
|
default?: boolean;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { t as redactInspectionText } from "./inspect-BIKQsqX4.js";
|
|
2
|
-
import { n as
|
|
3
|
-
import {
|
|
4
|
-
import { t as kvDevMaximumListLimit } from "./results-p7nPCnaJ.js";
|
|
2
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-C4VTHInS.js";
|
|
3
|
+
import { t as kvDevMaximumListLimit } from "./results-D6jfPtCk.js";
|
|
5
4
|
import { o as normalizeKey } from "./utils2-FozcTsmb.js";
|
|
6
5
|
import { kv } from "@vite-hub/kv";
|
|
7
6
|
//#region src/runtime/inspect-value.ts
|
|
@@ -22,30 +21,10 @@ function kvValueType(value) {
|
|
|
22
21
|
return typeof value;
|
|
23
22
|
}
|
|
24
23
|
function encodeBase64(bytes) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const length = Reflect.apply(lengthGetter, bytes, []);
|
|
29
|
-
for (const key of ["byteLength", "length"]) {
|
|
30
|
-
const descriptor = Object.getOwnPropertyDescriptor(bytes, key);
|
|
31
|
-
if (descriptor && (!("value" in descriptor) || descriptor.value !== length)) throw unsupported();
|
|
32
|
-
}
|
|
33
|
-
const encoded = [];
|
|
34
|
-
let chunk = [];
|
|
35
|
-
for (const byte of Reflect.apply(Uint8Array.prototype.values, bytes, [])) {
|
|
36
|
-
chunk.push(byte);
|
|
37
|
-
if (chunk.length === 12288) {
|
|
38
|
-
encoded.push(btoa(String.fromCharCode(...chunk)));
|
|
39
|
-
chunk = [];
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (chunk.length) encoded.push(btoa(String.fromCharCode(...chunk)));
|
|
43
|
-
return encoded.join("");
|
|
44
|
-
} catch {
|
|
45
|
-
throw unsupported();
|
|
46
|
-
}
|
|
24
|
+
const encoded = [];
|
|
25
|
+
for (let offset = 0; offset < bytes.byteLength; offset += 12288) encoded.push(btoa(String.fromCharCode(...bytes.subarray(offset, offset + 12288))));
|
|
26
|
+
return encoded.join("");
|
|
47
27
|
}
|
|
48
|
-
/** JSON inspection accepts JSON values and represents bigint values as decimal strings. */
|
|
49
28
|
function inspectValue(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
50
29
|
if (typeof value === "bigint") return value.toString();
|
|
51
30
|
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
@@ -107,6 +86,7 @@ function truncateValue(value) {
|
|
|
107
86
|
}
|
|
108
87
|
function boundedJSONStringify(value) {
|
|
109
88
|
let editable = true;
|
|
89
|
+
let unsupported = false;
|
|
110
90
|
let bytes = 0;
|
|
111
91
|
let rendered = "";
|
|
112
92
|
let truncated = false;
|
|
@@ -146,7 +126,8 @@ function boundedJSONStringify(value) {
|
|
|
146
126
|
editable = false;
|
|
147
127
|
const toJSON = Reflect.get(Object(input), "toJSON");
|
|
148
128
|
if (applyToJSON && typeof toJSON === "function") return serialize(toJSON.call(input, key), depth, arrayValue, key, false);
|
|
149
|
-
|
|
129
|
+
unsupported = true;
|
|
130
|
+
return false;
|
|
150
131
|
}
|
|
151
132
|
const object = Object(input);
|
|
152
133
|
const prototype = Object.getPrototypeOf(object);
|
|
@@ -165,7 +146,10 @@ function boundedJSONStringify(value) {
|
|
|
165
146
|
editable = false;
|
|
166
147
|
return serialize(boxed, depth, arrayValue, key);
|
|
167
148
|
}
|
|
168
|
-
if (ancestors.has(object))
|
|
149
|
+
if (ancestors.has(object)) {
|
|
150
|
+
unsupported = true;
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
169
153
|
if (seen.has(object)) editable = false;
|
|
170
154
|
seen.add(object);
|
|
171
155
|
ancestors.add(object);
|
|
@@ -204,6 +188,7 @@ function boundedJSONStringify(value) {
|
|
|
204
188
|
return append("}");
|
|
205
189
|
}
|
|
206
190
|
const serialized = serialize(value, 0, false, "");
|
|
191
|
+
if (unsupported) return void 0;
|
|
207
192
|
return {
|
|
208
193
|
editable,
|
|
209
194
|
truncated,
|
|
@@ -226,14 +211,16 @@ function previewKVValue(value) {
|
|
|
226
211
|
const maximumBytes = maximumValueBytes / 2;
|
|
227
212
|
truncated = value.byteLength > maximumBytes;
|
|
228
213
|
rendered = Array.from(value.subarray(0, maximumBytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
229
|
-
} else
|
|
214
|
+
} else {
|
|
230
215
|
const result = boundedJSONStringify(value);
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
216
|
+
if (result) {
|
|
217
|
+
rendered = result.value ?? String(value);
|
|
218
|
+
truncated = result.truncated;
|
|
219
|
+
editable = result.editable;
|
|
220
|
+
} else {
|
|
221
|
+
format = "text";
|
|
222
|
+
rendered = String(value);
|
|
223
|
+
}
|
|
237
224
|
}
|
|
238
225
|
const result = truncateValue(rendered);
|
|
239
226
|
const formatted = {
|
|
@@ -260,7 +247,6 @@ try {
|
|
|
260
247
|
} catch (error) {
|
|
261
248
|
if (!isMissingKVConfig(error)) throw error;
|
|
262
249
|
}
|
|
263
|
-
/** The HTTP status that the CLI, the Console, and Agents report for each code of a failed operation. */
|
|
264
250
|
const kvOperationStatus = {
|
|
265
251
|
KV_DISABLED: 409,
|
|
266
252
|
KV_INVALID_CURSOR: 400,
|
|
@@ -308,7 +294,6 @@ function selectStore(stores, name = "default") {
|
|
|
308
294
|
storage: name === "default" ? kv : kv.store(name)
|
|
309
295
|
};
|
|
310
296
|
}
|
|
311
|
-
/** The keys under `vitehub:` belong to ViteHub, which keeps its own state there. */
|
|
312
297
|
function requireWritableKey(operation, key) {
|
|
313
298
|
if (!normalizeKey(key).toLowerCase().startsWith("vitehub:")) return;
|
|
314
299
|
throw kvErrorDiagnostics.KV_RESERVED_KEY({
|
|
@@ -35,7 +35,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
35
35
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
36
36
|
},
|
|
37
37
|
INTERNAL_R0022: {
|
|
38
|
-
fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
|
|
38
|
+
fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields, and the list_operations tool of the ViteHub MCP gives the input schema of each operation.",
|
|
39
39
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
40
40
|
},
|
|
41
41
|
INTERNAL_R0024: {
|
|
@@ -254,6 +254,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
254
254
|
why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
|
|
255
255
|
fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
|
|
256
256
|
},
|
|
257
|
+
INTERNAL_RUNTIME_PACKAGE_VERSION_CONFLICT: {
|
|
258
|
+
why: ({ first, name, second }) => `[vitehub] One server function needs ${name} from two installations: ${first} and ${second}.`,
|
|
259
|
+
fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`, then build again."
|
|
260
|
+
},
|
|
257
261
|
INTERNAL_SECRET_PURPOSE_MISSING: {
|
|
258
262
|
why: "[vitehub] A derived secret requires a purpose.",
|
|
259
263
|
fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
|
|
@@ -432,6 +436,10 @@ const projectRootFileMarkers = [
|
|
|
432
436
|
["nuxt.config.js"],
|
|
433
437
|
["nuxt.config.mjs"]
|
|
434
438
|
];
|
|
439
|
+
/** Record a selected plugin in its pre config hook, before other plugins consume the selection. */
|
|
440
|
+
function markViteConfigPlugin(env, name) {
|
|
441
|
+
Reflect.set(env, Symbol.for(`vitehub.config-plugin:${name}`), true);
|
|
442
|
+
}
|
|
435
443
|
function createNoExternalAddition(...packageNames) {
|
|
436
444
|
return (current) => {
|
|
437
445
|
if (current === true) return;
|
|
@@ -443,6 +451,7 @@ function createNoExternalAddition(...packageNames) {
|
|
|
443
451
|
function isServerEnvironment(name, config) {
|
|
444
452
|
return name === "ssr" || config.consumer === "server";
|
|
445
453
|
}
|
|
454
|
+
const VITEHUB_NITRO_CONFIG_CONTEXT = "__vitehubNitroConfigContext";
|
|
446
455
|
const VITEHUB_PROJECT_ROOT = "__vitehubProjectRoot";
|
|
447
456
|
/**
|
|
448
457
|
* Set by `vite-hub/nuxt` when it replays Vite config hooks for `nuxt prepare`. Prepare uses `command: "build"` to write
|
|
@@ -487,7 +496,7 @@ function hasProjectRootDirectoryMarker(root) {
|
|
|
487
496
|
for (const marker of projectRootDirectoryMarkers) try {
|
|
488
497
|
if (statSync(resolve(root, ...marker)).isDirectory()) return true;
|
|
489
498
|
} catch (error) {
|
|
490
|
-
if (error
|
|
499
|
+
if (!isMissingProjectMarker(error)) throw error;
|
|
491
500
|
}
|
|
492
501
|
return false;
|
|
493
502
|
}
|
|
@@ -501,11 +510,15 @@ function hasProjectRootFileMarker(root, markers) {
|
|
|
501
510
|
try {
|
|
502
511
|
if (statSync(resolve(root, ...path)).isFile()) return true;
|
|
503
512
|
} catch (error) {
|
|
504
|
-
if (error
|
|
513
|
+
if (!isMissingProjectMarker(error)) throw error;
|
|
505
514
|
}
|
|
506
515
|
}
|
|
507
516
|
return false;
|
|
508
517
|
}
|
|
518
|
+
function isMissingProjectMarker(error) {
|
|
519
|
+
const code = error.code;
|
|
520
|
+
return code === "ENOENT" || code === "ENOTDIR";
|
|
521
|
+
}
|
|
509
522
|
//#endregion
|
|
510
523
|
//#region ../internal/src/operation-rpc.ts
|
|
511
524
|
/** Path of the operation RPC under the app. Dev servers and deployed apps serve it the same way, one birpc call per POST. */
|
|
@@ -1021,11 +1034,16 @@ function operationsOf(value) {
|
|
|
1021
1034
|
/** The CLI namespace and command of an operation. Defaults: the section (or the name prefix) and the verb. */
|
|
1022
1035
|
function operationCliPath(operation) {
|
|
1023
1036
|
const dot = operation.name.indexOf(".");
|
|
1037
|
+
const cli = operationCliOptions(operation);
|
|
1024
1038
|
return {
|
|
1025
|
-
command:
|
|
1026
|
-
namespace:
|
|
1039
|
+
command: cli?.command ?? operation.name.slice(dot + 1),
|
|
1040
|
+
namespace: cli?.namespace ?? (typeof operation.section === "string" ? operation.section : operation.name.slice(0, dot))
|
|
1027
1041
|
};
|
|
1028
1042
|
}
|
|
1043
|
+
/** The CLI options of an operation, or undefined for an operation without options or with `cli: false`. */
|
|
1044
|
+
function operationCliOptions(operation) {
|
|
1045
|
+
return operation.cli || void 0;
|
|
1046
|
+
}
|
|
1029
1047
|
/**
|
|
1030
1048
|
* The MCP tool name of an operation: every character outside `[a-zA-Z0-9_-]` becomes `_`, since clients such as
|
|
1031
1049
|
* Claude reject a dot in a tool name. `content.publish` is `content_publish`.
|
|
@@ -1050,6 +1068,7 @@ function createOperationRegistry(sources) {
|
|
|
1050
1068
|
const operations = [...byName.values()].map((entry) => entry.operation).sort((left, right) => left.name.localeCompare(right.name));
|
|
1051
1069
|
const commands = /* @__PURE__ */ new Map();
|
|
1052
1070
|
for (const operation of operations) {
|
|
1071
|
+
if (operation.cli === false) continue;
|
|
1053
1072
|
const { command, namespace } = operationCliPath(operation);
|
|
1054
1073
|
if (reservedOperationNamespaces.includes(namespace)) throw invalidDefinition(operation.name, `the CLI namespace ${JSON.stringify(namespace)} is reserved for built-in commands. Set cli.namespace to another name.`);
|
|
1055
1074
|
const key = `${namespace} ${command}`;
|
|
@@ -1077,12 +1096,23 @@ function describeInputIssues(issues) {
|
|
|
1077
1096
|
return path ? `${path}: ${issue.message}` : issue.message;
|
|
1078
1097
|
}).join(" ");
|
|
1079
1098
|
}
|
|
1099
|
+
function describeInputFields(schema) {
|
|
1100
|
+
const shapes = (Array.isArray(schema.anyOf) ? schema.anyOf : [schema]).map((shape) => {
|
|
1101
|
+
if (!isRecordOrFunction(shape) || !isRecordOrFunction(shape.properties)) return void 0;
|
|
1102
|
+
const required = Array.isArray(shape.required) ? shape.required : [];
|
|
1103
|
+
const fields = Object.keys(shape.properties).map((field) => required.includes(field) ? field : `${field}?`);
|
|
1104
|
+
return fields.length ? `{ ${fields.join(", ")} }` : "{}";
|
|
1105
|
+
});
|
|
1106
|
+
return shapes.every((shape) => shape !== void 0) ? shapes.join(" or ") : void 0;
|
|
1107
|
+
}
|
|
1080
1108
|
/** Validate `input` with the schema of the operation. Throws `INTERNAL_R0022` with `status: 400`. */
|
|
1081
1109
|
async function parseOperationInput(operation, input) {
|
|
1082
1110
|
const result = await operation.input["~standard"].validate(input ?? {});
|
|
1083
1111
|
if (!result.issues) return result.value;
|
|
1084
|
-
const
|
|
1085
|
-
|
|
1112
|
+
const fields = describeInputFields(operationInputJsonSchema(operation));
|
|
1113
|
+
const issues = describeInputIssues(result.issues);
|
|
1114
|
+
const message = `Invalid input for ${operation.name}. ${issues}${fields ? `${/[.!?]$/.test(issues) ? "" : "."} ${operation.name} takes ${fields}.` : ""}`;
|
|
1115
|
+
throw Object.assign(internalErrorDiagnostics.INTERNAL_R0022({ message }), { status: 400 });
|
|
1086
1116
|
}
|
|
1087
1117
|
/**
|
|
1088
1118
|
* The section that grants a call, or `false` for any Console user. `undefined` means the input names no valid section.
|
|
@@ -1360,4 +1390,4 @@ async function callOperationFromCli(call, name, input) {
|
|
|
1360
1390
|
}, name, input);
|
|
1361
1391
|
}
|
|
1362
1392
|
//#endregion
|
|
1363
|
-
export {
|
|
1393
|
+
export { readViteHubDevTargetOption as A, resolveViteHubProjectRoot as C, parseCliPositiveInteger as D, listSeedFiles as E, writeCliFailure as M, writeViteHubDevServerFile as N, readCliOptionValue as O, internalErrorDiagnostics as P, markViteConfigPlugin as S, askOnTerminal as T, VITEHUB_PREPARE as _, operationRootHeader as a, hasNitroConfigContext as b, projectRootHash as c, defineOperation as d, answerOperationRpc as f, VITEHUB_NITRO_CONFIG_CONTEXT as g, readOperationRpcCall as h, createOperationRegistry as i, removeViteHubDevServerFile as j, readViteHubDevServerFile as k, runOperation as l, operationRpcRefusal as m, callOperationFromCli as n, operationRpcHeader as o, operationRpcPath as p, collectOperationContributions as r, operationsOf as s, assertOperationProject as t, toOperationFailure as u, VITEHUB_PROJECT_ROOT as v, shouldSkipViteProviderBuild as w, isServerEnvironment as x, createNoExternalAddition as y };
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as KVDriver } from "./types-
|
|
2
|
-
import { t as AnyOperation } from "./operation-definition-
|
|
1
|
+
import { c as KVDriver } from "./types-Cp6IBhSN.js";
|
|
2
|
+
import { t as AnyOperation } from "./operation-definition-CI2PJGqu.js";
|
|
3
3
|
//#region src/runtime/operations.d.ts
|
|
4
4
|
interface KVDevListResult {
|
|
5
5
|
/** Present when more keys exist. Pass it as `--cursor` to read the next page. */
|
package/dist/operations.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as kvDevMaximumListLimit } from "./results-
|
|
1
|
+
import { P as internalErrorDiagnostics, a as operationRootHeader, c as projectRootHash, d as defineOperation, f as answerOperationRpc, h as readOperationRpcCall, i as createOperationRegistry, l as runOperation, m as operationRpcRefusal, o as operationRpcHeader, s as operationsOf, t as assertOperationProject, u as toOperationFailure } from "./operations-nAaONxzh.js";
|
|
2
|
+
import { t as kvDevMaximumListLimit } from "./results-D6jfPtCk.js";
|
|
3
3
|
import { n as isViteHubLoopbackPeer } from "./dev-peer-CHafxbtj.js";
|
|
4
4
|
import * as v from "valibot";
|
|
5
5
|
//#region ../internal/src/secret.ts
|
|
@@ -238,7 +238,7 @@ function createStandaloneOperationHandler(sources, root) {
|
|
|
238
238
|
}
|
|
239
239
|
//#endregion
|
|
240
240
|
//#region src/operations.ts
|
|
241
|
-
const runtime = () => import("./operations-
|
|
241
|
+
const runtime = () => import("./operations-CqKs7Ykc.js");
|
|
242
242
|
const store = v.optional(v.pipe(v.string(), v.check((name) => name.trim() !== "", "Name a store.")));
|
|
243
243
|
const key = v.string();
|
|
244
244
|
function defineKVOperation(definition) {
|