@vite-hub/kv 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 +9 -7
- package/dist/{cli-BvVInMht.d.ts → cli-C-uep33j.d.ts} +15 -0
- package/dist/cli.d.ts +2 -2
- package/dist/cli.js +3 -2
- package/dist/{cloudflare-kv-Cp8HPUlJ.js → cloudflare-kv-hMdZQZz1.js} +3 -3
- package/dist/{cloudflare-kv-local-COoOI34K.js → cloudflare-kv-local-BpPaDG49.js} +2 -2
- package/dist/{config-_1oBDv2R.js → config-x_Nru3R5.js} +4 -4
- package/dist/{create-storage-DbWVAY9l.js → create-storage-DrhV0F4S.js} +1 -1
- package/dist/{cursor-history-CMcEEnTO.js → cursor-history-MzSrXXXX.js} +1 -1
- package/dist/{database-4iAg2GoV.js → database-D0NvYrhk.js} +66 -20
- package/dist/{deno-kv-CatE7zSS.js → deno-kv-DwcTL95B.js} +2 -2
- package/dist/{driver-BruahGvT.d.ts → driver-CZTAQ_07.d.ts} +2 -2
- package/dist/{error-diagnostics-CuVl1nvE.js → error-diagnostics-DAi25E6F.js} +10 -5
- package/dist/{errors-CJoAP4Bu.js → errors-kZRpu7Wa.js} +15 -2
- package/dist/errors.d.ts +6 -1
- package/dist/errors.js +1 -1
- package/dist/{fs-lite-DzTTR6R3.js → fs-lite-1n_Dvy4p.js} +195 -131
- package/dist/fs-lite-Co1NzxYo.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +79 -69
- package/dist/{operation-definition-CqZkx1Rm.d.ts → operations-BAlr2zUj.d.ts} +1 -0
- package/dist/{operations-DSOTGwST.js → operations-Cj_0pSSA.js} +22 -29
- package/dist/{operations-BkVt17cd.js → operations-DP8iWjQK.js} +75 -11
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +2 -2
- package/dist/{redis-shared-CR3ANc_N.js → redis-shared-DEwmedD5.js} +1 -1
- package/dist/runtime/cloudflare-kv.d.ts +1 -1
- package/dist/runtime/cloudflare-kv.js +1 -1
- package/dist/runtime/nitro-plugin.js +1 -1
- package/dist/runtime/redis-driver.d.ts +2 -2
- package/dist/runtime/redis-driver.js +3 -5
- package/dist/runtime/upstash-driver.d.ts +2 -2
- package/dist/runtime/upstash-driver.js +2 -2
- package/dist/{types-CPDL9enF.d.ts → types-BLxnI_rU.d.ts} +14 -14
- package/dist/{upstash-DeM3_U5H.js → upstash-DINRYhXI.js} +2 -2
- package/dist/vite.d.ts +9 -5
- package/dist/vite.js +211 -75
- package/package.json +8 -4
- package/dist/fs-lite-DwbPkc-C.js +0 -1
package/dist/index.js
CHANGED
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
import { r as normalizeKVOptions, s as readEnv } from "./config-
|
|
1
|
+
import { r as normalizeKVOptions, s as readEnv } from "./config-x_Nru3R5.js";
|
|
2
2
|
import { n as getActiveCloudflareEnv } from "./cloudflare-env-lookup-Dgq5n1Aq.js";
|
|
3
|
-
import { a as
|
|
3
|
+
import { a as kvListLimitInvalid, c as kvSetTTL, f as listKVKeys, i as kvKeyLimitCodes, m as ttlSeconds, n as kvInvalidKeyError, o as kvResult, p as kvStoreWithMode, s as kvSetCodes, t as kvClearOptionsError } from "./errors-kZRpu7Wa.js";
|
|
4
4
|
import { o as normalizeKey } from "./utils2-By8eee1x.js";
|
|
5
|
-
import { n as kvErrorDiagnostics } from "./error-diagnostics-
|
|
6
|
-
import { t as resolveRuntimeKVOptions } from "./upstash-
|
|
5
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-DAi25E6F.js";
|
|
6
|
+
import { t as resolveRuntimeKVOptions } from "./upstash-DINRYhXI.js";
|
|
7
7
|
import { i as setItemsOneByOne, n as getItemsOneByOne } from "./batch-D-ib5_0P.js";
|
|
8
|
-
import { n as normalizeKVListPrefix, t as createKVStorage$1 } from "./create-storage-
|
|
8
|
+
import { n as normalizeKVListPrefix, t as createKVStorage$1 } from "./create-storage-DrhV0F4S.js";
|
|
9
9
|
import { t as logFailure } from "./request-log-DllKQXj7.js";
|
|
10
10
|
import { getViteHubTestMode } from "@vite-hub/runtime/internal/test-mode";
|
|
11
11
|
import { destr } from "destr";
|
|
12
12
|
// src/runtime/driver.ts
|
|
13
|
-
const lazyDriverMethods = /* @__PURE__ */ new Set([
|
|
14
|
-
"clear",
|
|
15
|
-
"getItem",
|
|
16
|
-
"getKeys",
|
|
17
|
-
"hasItem",
|
|
18
|
-
"listKeys",
|
|
19
|
-
"removeItem",
|
|
20
|
-
"setItem"
|
|
21
|
-
]);
|
|
22
13
|
const atomicDriverMethods = {
|
|
23
14
|
deleteIfEquals: "deleteIfEqualsItem",
|
|
24
15
|
getAndDelete: "getAndDeleteItem",
|
|
@@ -34,7 +25,12 @@ const driverAtomicOperations = {
|
|
|
34
25
|
setIfAbsent: true
|
|
35
26
|
},
|
|
36
27
|
"deno-kv": { setIfAbsent: true },
|
|
37
|
-
"fs-lite": {
|
|
28
|
+
"fs-lite": {
|
|
29
|
+
deleteIfEquals: true,
|
|
30
|
+
getAndDelete: true,
|
|
31
|
+
increment: true,
|
|
32
|
+
setIfAbsent: true
|
|
33
|
+
},
|
|
38
34
|
"redis": {
|
|
39
35
|
deleteIfEquals: true,
|
|
40
36
|
getAndDelete: true,
|
|
@@ -56,10 +52,9 @@ const otherOptionalDriverMethods = {
|
|
|
56
52
|
"setItemRaw"
|
|
57
53
|
]
|
|
58
54
|
};
|
|
59
|
-
const batchDriverMethods = /* @__PURE__ */ new Set(["getItems", "setItems"]);
|
|
60
55
|
const lazyOptionalDriverMethods = Object.fromEntries(Object.entries(driverAtomicOperations).map(([driver, operations]) => [driver, /* @__PURE__ */ new Set([...Object.keys(operations).map((operation) => atomicDriverMethods[operation]), ...otherOptionalDriverMethods[driver] ?? []])]));
|
|
61
56
|
async function createDatabaseDriver(store, loadDatabases) {
|
|
62
|
-
const { default: factory, kvSqlClientFromDatabase } = await import("./database-
|
|
57
|
+
const { default: factory, kvSqlClientFromDatabase } = await import("./database-D0NvYrhk.js");
|
|
63
58
|
return factory(store, async () => {
|
|
64
59
|
const entry = loadDatabases ? (await loadDatabases())[store.database] : void 0;
|
|
65
60
|
if (!entry) throw kvErrorDiagnostics.KV_DATABASE_UNAVAILABLE({
|
|
@@ -74,7 +69,7 @@ async function createRuntimeDriver(store, loadDatabases) {
|
|
|
74
69
|
case "cloudflare": {
|
|
75
70
|
const { localBase } = store;
|
|
76
71
|
if (localBase) {
|
|
77
|
-
const { default: factory } = await import("./cloudflare-kv-local-
|
|
72
|
+
const { default: factory } = await import("./cloudflare-kv-local-BpPaDG49.js");
|
|
78
73
|
return factory({
|
|
79
74
|
...store,
|
|
80
75
|
localBase
|
|
@@ -85,11 +80,11 @@ async function createRuntimeDriver(store, loadDatabases) {
|
|
|
85
80
|
}
|
|
86
81
|
case "database": return createDatabaseDriver(store, loadDatabases);
|
|
87
82
|
case "deno-kv": {
|
|
88
|
-
const { default: factory } = await import("./deno-kv-
|
|
83
|
+
const { default: factory } = await import("./deno-kv-DwcTL95B.js");
|
|
89
84
|
return factory(store);
|
|
90
85
|
}
|
|
91
86
|
case "fs-lite": {
|
|
92
|
-
const { default: factory } = await import("./fs-lite-
|
|
87
|
+
const { default: factory } = await import("./fs-lite-Co1NzxYo.js");
|
|
93
88
|
return factory(store);
|
|
94
89
|
}
|
|
95
90
|
case "redis": {
|
|
@@ -119,30 +114,38 @@ function createLazyKVRuntimeDriver(config, loadDatabases) {
|
|
|
119
114
|
});
|
|
120
115
|
return pending;
|
|
121
116
|
}
|
|
122
|
-
const
|
|
117
|
+
const optionalMethods = lazyOptionalDriverMethods[config.store.driver];
|
|
118
|
+
return {
|
|
123
119
|
name: `lazy:${config.store.driver}`,
|
|
124
|
-
options: config.store
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
120
|
+
options: config.store,
|
|
121
|
+
clear: async (base, options) => (await resolve()).clear?.(base, options),
|
|
122
|
+
getItem: async (key, options) => (await resolve()).getItem(key, options),
|
|
123
|
+
getItems: async (items, options) => {
|
|
124
|
+
const resolved = await resolve();
|
|
125
|
+
return (resolved.getItems ?? getItemsOneByOne(resolved))(items, options);
|
|
126
|
+
},
|
|
127
|
+
getKeys: async (base, options) => (await resolve()).getKeys(base, options),
|
|
128
|
+
hasItem: async (key, options) => (await resolve()).hasItem(key, options),
|
|
129
|
+
listKeys: async (options) => (await resolve()).listKeys(options),
|
|
130
|
+
removeItem: async (key, options) => (await resolve()).removeItem?.(key, options),
|
|
131
|
+
setItem: async (key, value, options) => (await resolve()).setItem?.(key, value, options),
|
|
132
|
+
setItems: async (items, options) => {
|
|
133
|
+
const resolved = await resolve();
|
|
134
|
+
return (resolved.setItems ?? setItemsOneByOne(resolved))(items, options);
|
|
135
|
+
},
|
|
136
|
+
dispose: async () => {
|
|
130
137
|
disposed = true;
|
|
131
|
-
if (
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const driver = await resolve();
|
|
143
|
-
return driver[prop]?.apply(driver, args);
|
|
144
|
-
};
|
|
145
|
-
} });
|
|
138
|
+
if (driverPromise) await (await driverPromise).dispose?.();
|
|
139
|
+
},
|
|
140
|
+
getItemRaw: optionalMethods.has("getItemRaw") ? async (key, options) => (await resolve()).getItemRaw?.(key, options) : void 0,
|
|
141
|
+
getMeta: optionalMethods.has("getMeta") ? async (key, options) => (await resolve()).getMeta?.(key, options) ?? null : void 0,
|
|
142
|
+
setItemRaw: optionalMethods.has("setItemRaw") ? async (key, value, options) => (await resolve()).setItemRaw?.(key, value, options) : void 0,
|
|
143
|
+
validateBatch: optionalMethods.has("validateBatch") ? async (items, removals, options) => (await resolve()).validateBatch(items, removals, options) : void 0,
|
|
144
|
+
deleteIfEqualsItem: optionalMethods.has("deleteIfEqualsItem") ? async (key, expected) => (await resolve()).deleteIfEqualsItem(key, expected) : void 0,
|
|
145
|
+
getAndDeleteItem: optionalMethods.has("getAndDeleteItem") ? async (key) => (await resolve()).getAndDeleteItem(key) : void 0,
|
|
146
|
+
incrementItem: optionalMethods.has("incrementItem") ? async (key, ttl) => (await resolve()).incrementItem(key, ttl) : void 0,
|
|
147
|
+
setIfAbsentItem: optionalMethods.has("setIfAbsentItem") ? async (key, value, ttl) => (await resolve()).setIfAbsentItem(key, value, ttl) : void 0
|
|
148
|
+
};
|
|
146
149
|
}
|
|
147
150
|
// src/runtime/hosted-storage.ts
|
|
148
151
|
function assertHostedConfig(config) {
|
|
@@ -166,7 +169,7 @@ function serializeValue(value, operation = "setIfAbsent") {
|
|
|
166
169
|
if (value && typeof value === "object") {
|
|
167
170
|
const prototype = Object.getPrototypeOf(value);
|
|
168
171
|
if (prototype === null || prototype === Object.prototype) return serializeJSONValue(value, operation);
|
|
169
|
-
const toJSON =
|
|
172
|
+
const toJSON = "toJSON" in value ? value.toJSON : void 0;
|
|
170
173
|
if (typeof toJSON === "function") return serializeValue(toJSON.call(value), operation);
|
|
171
174
|
}
|
|
172
175
|
throw kvErrorDiagnostics.KV_INVALID_VALUE({
|
|
@@ -213,23 +216,23 @@ function createHostedKVStorage(config, name = "default", loadDatabases) {
|
|
|
213
216
|
[name]: store
|
|
214
217
|
}
|
|
215
218
|
}, loadDatabases);
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
219
|
+
const base = createKVStorage$1(driver);
|
|
220
|
+
const { getAndDeleteItem, incrementItem, setIfAbsentItem, deleteIfEqualsItem } = driver;
|
|
221
|
+
return {
|
|
222
|
+
...base,
|
|
223
|
+
getMany: base.getMany,
|
|
224
|
+
listKeys: (options) => driver.listKeys({
|
|
225
|
+
...options,
|
|
226
|
+
prefix: normalizeKVListPrefix(options.prefix)
|
|
227
|
+
}),
|
|
228
|
+
getAndDeleteItem: getAndDeleteItem && (async (key, options) => {
|
|
229
|
+
const value = await getAndDeleteItem(normalizeKey(key));
|
|
230
|
+
return options?.type === "text" ? value : deserializeValue(value);
|
|
231
|
+
}),
|
|
232
|
+
incrementItem: incrementItem && ((key, ttl) => incrementItem(normalizeKey(key), ttl)),
|
|
233
|
+
setIfAbsentItem: setIfAbsentItem && (async (key, value, ttl) => setIfAbsentItem(normalizeKey(key), serializeValue(value), ttl)),
|
|
234
|
+
deleteIfEqualsItem: deleteIfEqualsItem && (async (key, expected) => deleteIfEqualsItem(normalizeKey(key), serializeValue(expected, "deleteIfEquals")))
|
|
226
235
|
};
|
|
227
|
-
if (incrementItem) storage.incrementItem = (key, ttl) => incrementItem(normalizeKey(key), ttl);
|
|
228
|
-
const setIfAbsentItem = driver.setIfAbsentItem;
|
|
229
|
-
if (setIfAbsentItem) storage.setIfAbsentItem = async (key, value, ttl) => setIfAbsentItem(normalizeKey(key), serializeValue(value), ttl);
|
|
230
|
-
const deleteIfEqualsItem = driver.deleteIfEqualsItem;
|
|
231
|
-
if (deleteIfEqualsItem) storage.deleteIfEqualsItem = async (key, expected) => deleteIfEqualsItem(normalizeKey(key), serializeValue(expected, "deleteIfEquals"));
|
|
232
|
-
return storage;
|
|
233
236
|
}
|
|
234
237
|
// src/runtime/lock.ts
|
|
235
238
|
const firstRetryMs = 25;
|
|
@@ -243,6 +246,8 @@ function createKVLock(store, resolveStorage, key, options) {
|
|
|
243
246
|
async function acquire() {
|
|
244
247
|
const ttl = ttlSeconds(options.ttl);
|
|
245
248
|
const wait = options.wait ?? 0;
|
|
249
|
+
const keyError = kvInvalidKeyError([key]);
|
|
250
|
+
if (keyError) return [keyError, void 0];
|
|
246
251
|
if (ttl === void 0) return [kvErrorDiagnostics.KV_INVALID_TTL(), void 0];
|
|
247
252
|
if (!Number.isFinite(wait) || wait < 0) return [kvErrorDiagnostics.KV_INVALID_WAIT(), void 0];
|
|
248
253
|
const storage = await resolveStorage();
|
|
@@ -385,6 +390,11 @@ async function runKVOperation(operation, name, run, codes = []) {
|
|
|
385
390
|
const storage = await resolveStorage(name);
|
|
386
391
|
return kvResult(operation, name, () => run(storage), codes);
|
|
387
392
|
}
|
|
393
|
+
async function runKeyedKVOperation(operation, name, keys, run, codes = []) {
|
|
394
|
+
const error = kvInvalidKeyError(keys);
|
|
395
|
+
if (error) return [error, void 0];
|
|
396
|
+
return runKVOperation(operation, name, run, codes);
|
|
397
|
+
}
|
|
388
398
|
function createKVStorage(name = "default") {
|
|
389
399
|
return {
|
|
390
400
|
async clear(options) {
|
|
@@ -393,10 +403,10 @@ function createKVStorage(name = "default") {
|
|
|
393
403
|
return runKVOperation("clear", name, async (storage) => storage.clear(options?.prefix));
|
|
394
404
|
},
|
|
395
405
|
async delete(key, options) {
|
|
396
|
-
return
|
|
406
|
+
return runKeyedKVOperation("delete", name, [key], async (storage) => storage.removeItem(key, options), kvKeyLimitCodes);
|
|
397
407
|
},
|
|
398
408
|
async deleteIfEquals(key, expected) {
|
|
399
|
-
return
|
|
409
|
+
return runKeyedKVOperation("deleteIfEquals", name, [key], async (storage) => {
|
|
400
410
|
if (!storage.deleteIfEqualsItem) throw kvErrorDiagnostics.KV_UNSUPPORTED_OPERATION({
|
|
401
411
|
operation: "deleteIfEquals",
|
|
402
412
|
store: name
|
|
@@ -405,10 +415,10 @@ function createKVStorage(name = "default") {
|
|
|
405
415
|
}, ["KV_INVALID_VALUE", "KV_UNSUPPORTED_OPERATION"]);
|
|
406
416
|
},
|
|
407
417
|
async get(key, options) {
|
|
408
|
-
return
|
|
418
|
+
return runKeyedKVOperation("get", name, [key], (storage) => storage.getItem(key, options), kvKeyLimitCodes);
|
|
409
419
|
},
|
|
410
420
|
async getAndDelete(key, options) {
|
|
411
|
-
return
|
|
421
|
+
return runKeyedKVOperation("getAndDelete", name, [key], async (storage) => {
|
|
412
422
|
if (!storage.getAndDeleteItem) throw kvErrorDiagnostics.KV_UNSUPPORTED_OPERATION({
|
|
413
423
|
operation: "getAndDelete",
|
|
414
424
|
store: name
|
|
@@ -417,13 +427,13 @@ function createKVStorage(name = "default") {
|
|
|
417
427
|
}, ["KV_UNSUPPORTED_OPERATION"]);
|
|
418
428
|
},
|
|
419
429
|
async getMany(keys, options) {
|
|
420
|
-
return
|
|
430
|
+
return runKeyedKVOperation("getMany", name, keys, (storage) => storage.getMany(keys, options), kvKeyLimitCodes);
|
|
421
431
|
},
|
|
422
432
|
async has(key, options) {
|
|
423
|
-
return
|
|
433
|
+
return runKeyedKVOperation("has", name, [key], (storage) => storage.hasItem(key, options), kvKeyLimitCodes);
|
|
424
434
|
},
|
|
425
435
|
async increment(key, ttl) {
|
|
426
|
-
return
|
|
436
|
+
return runKeyedKVOperation("increment", name, [key], async (storage) => {
|
|
427
437
|
if (!storage.incrementItem) throw kvErrorDiagnostics.KV_UNSUPPORTED_OPERATION({
|
|
428
438
|
operation: "increment",
|
|
429
439
|
store: name
|
|
@@ -441,19 +451,19 @@ function createKVStorage(name = "default") {
|
|
|
441
451
|
return runKVOperation("list", name, (storage) => listKVKeys((page) => storage.listKeys(page), options), ["KV_INVALID_CURSOR"]);
|
|
442
452
|
},
|
|
443
453
|
async set(key, value, options) {
|
|
444
|
-
return
|
|
454
|
+
return runKeyedKVOperation("set", name, [key], async (storage) => {
|
|
445
455
|
const ttl = kvSetTTL("set", options);
|
|
446
456
|
return storage.setItem(key, value, ttl === void 0 ? void 0 : { ttl });
|
|
447
457
|
}, kvSetCodes);
|
|
448
458
|
},
|
|
449
459
|
async setMany(entries, options) {
|
|
450
|
-
return
|
|
460
|
+
return runKeyedKVOperation("setMany", name, Array.isArray(entries) ? entries.map((entry) => Reflect.get(Object(entry), "key")) : entries, async (storage) => {
|
|
451
461
|
const ttl = kvSetTTL("setMany", options);
|
|
452
462
|
return storage.setMany(entries, ttl === void 0 ? void 0 : { ttl });
|
|
453
463
|
}, kvSetCodes);
|
|
454
464
|
},
|
|
455
465
|
async setIfAbsent(key, value, options) {
|
|
456
|
-
return
|
|
466
|
+
return runKeyedKVOperation("setIfAbsent", name, [key], async (storage) => {
|
|
457
467
|
if (!storage.setIfAbsentItem) throw kvErrorDiagnostics.KV_UNSUPPORTED_OPERATION({
|
|
458
468
|
operation: "setIfAbsent",
|
|
459
469
|
store: name
|
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
import { o as normalizeKey } from "./utils2-By8eee1x.js";
|
|
2
2
|
import { t as redactInspectionText } from "./inspect-BWMcVWD8.js";
|
|
3
|
-
import { n as kvErrorDiagnostics } from "./error-diagnostics-
|
|
3
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-DAi25E6F.js";
|
|
4
4
|
import { t as kvDevMaximumListLimit } from "./results-emgN7uDS.js";
|
|
5
5
|
import { kv } from "@vite-hub/kv";
|
|
6
6
|
// src/runtime/inspect-value.ts
|
|
7
7
|
const unsupported = () => kvErrorDiagnostics.KV_VALUE_UNSUPPORTED();
|
|
8
8
|
function isUint8Array(value) {
|
|
9
|
-
|
|
10
|
-
if (!ArrayBuffer.isView(value)) return false;
|
|
11
|
-
const tagGetter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype), Symbol.toStringTag)?.get;
|
|
12
|
-
return Boolean(tagGetter && Reflect.apply(tagGetter, value, []) === "Uint8Array");
|
|
13
|
-
} catch {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
9
|
+
return ArrayBuffer.isView(value) && Object.prototype.toString.call(value) === "[object Uint8Array]";
|
|
16
10
|
}
|
|
17
11
|
function kvValueType(value) {
|
|
18
12
|
if (value === null) return "null";
|
|
@@ -32,21 +26,20 @@ function inspectValue(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
32
26
|
if (typeof value !== "object" && typeof value !== "function" || seen.has(value)) throw unsupported();
|
|
33
27
|
seen.add(value);
|
|
34
28
|
try {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
if (dataKeys.map((key) => Object.getOwnPropertyDescriptor(value, key)).some((descriptor) => !descriptor?.enumerable || !("value" in descriptor))) throw unsupported();
|
|
29
|
+
const keys = Object.keys(value);
|
|
30
|
+
if (Object.getOwnPropertyNames(value).length - keys.length - (Array.isArray(value) ? 1 : 0) !== 0 || Object.getOwnPropertySymbols(value).length) throw unsupported();
|
|
38
31
|
if (Array.isArray(value)) {
|
|
39
|
-
if (
|
|
40
|
-
return
|
|
32
|
+
if (keys.length !== value.length || keys.some((key, index) => key !== String(index))) throw unsupported();
|
|
33
|
+
return value.map((item) => inspectValue(item, seen));
|
|
41
34
|
}
|
|
42
35
|
const prototype = Object.getPrototypeOf(value);
|
|
43
|
-
if (prototype !== Object.prototype && prototype !== null
|
|
44
|
-
return Object.fromEntries(
|
|
36
|
+
if (prototype !== Object.prototype && prototype !== null) throw unsupported();
|
|
37
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, inspectValue(item, seen)]));
|
|
45
38
|
} finally {
|
|
46
39
|
seen.delete(value);
|
|
47
40
|
}
|
|
48
41
|
}
|
|
49
|
-
/** Encodes
|
|
42
|
+
/** Encodes a stored value as JSON data or Base64 bytes for inspection. */
|
|
50
43
|
function inspectKVValue(value) {
|
|
51
44
|
try {
|
|
52
45
|
if (isUint8Array(value)) return {
|
|
@@ -59,7 +52,7 @@ function inspectKVValue(value) {
|
|
|
59
52
|
value: inspectValue(value)
|
|
60
53
|
};
|
|
61
54
|
} catch (error) {
|
|
62
|
-
if (
|
|
55
|
+
if (error instanceof Error && "code" in error && error.code === "KV_VALUE_UNSUPPORTED") return;
|
|
63
56
|
throw error;
|
|
64
57
|
}
|
|
65
58
|
}
|
|
@@ -123,7 +116,7 @@ function boundedJSONStringify(value) {
|
|
|
123
116
|
}
|
|
124
117
|
if (typeof input === "bigint") {
|
|
125
118
|
editable = false;
|
|
126
|
-
const toJSON =
|
|
119
|
+
const toJSON = Object(input).toJSON;
|
|
127
120
|
if (applyToJSON && typeof toJSON === "function") return serialize(toJSON.call(input, key), depth, arrayValue, key, false);
|
|
128
121
|
unsupported = true;
|
|
129
122
|
return false;
|
|
@@ -131,16 +124,16 @@ function boundedJSONStringify(value) {
|
|
|
131
124
|
const object = Object(input);
|
|
132
125
|
const prototype = Object.getPrototypeOf(object);
|
|
133
126
|
if (Array.isArray(object) ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) editable = false;
|
|
134
|
-
const keys =
|
|
135
|
-
if (
|
|
127
|
+
const keys = Object.keys(object);
|
|
128
|
+
if (Object.getOwnPropertySymbols(object).length || Object.getOwnPropertyNames(object).length !== keys.length + (Array.isArray(object) ? 1 : 0)) editable = false;
|
|
136
129
|
if (Array.isArray(object) && keys.length !== object.length) editable = false;
|
|
137
|
-
const toJSON =
|
|
130
|
+
const toJSON = object.toJSON;
|
|
138
131
|
if (applyToJSON && typeof toJSON === "function") {
|
|
139
132
|
editable = false;
|
|
140
133
|
const replacement = toJSON.call(input, key);
|
|
141
134
|
if (replacement !== input) return serialize(replacement, depth, arrayValue, key, false);
|
|
142
135
|
}
|
|
143
|
-
const boxed = input instanceof Number || input instanceof String || input instanceof Boolean || Object.prototype.toString.call(input) === "[object BigInt]" ?
|
|
136
|
+
const boxed = input instanceof Number || input instanceof String || input instanceof Boolean || Object.prototype.toString.call(input) === "[object BigInt]" ? object.valueOf() : input;
|
|
144
137
|
if (boxed !== input) {
|
|
145
138
|
editable = false;
|
|
146
139
|
return serialize(boxed, depth, arrayValue, key);
|
|
@@ -166,9 +159,9 @@ function boundedJSONStringify(value) {
|
|
|
166
159
|
let count = 0;
|
|
167
160
|
for (const key in object) {
|
|
168
161
|
if (!Object.prototype.hasOwnProperty.call(object, key)) continue;
|
|
169
|
-
let item =
|
|
162
|
+
let item = object[key];
|
|
170
163
|
if (item !== null && (typeof item === "object" || typeof item === "bigint")) {
|
|
171
|
-
const toJSON =
|
|
164
|
+
const toJSON = Object(item).toJSON;
|
|
172
165
|
if (typeof toJSON === "function") {
|
|
173
166
|
editable = false;
|
|
174
167
|
item = toJSON.call(item, key);
|
|
@@ -257,6 +250,7 @@ const maximumKeyLength = 2048;
|
|
|
257
250
|
function unwrap(result) {
|
|
258
251
|
const [error, value] = result;
|
|
259
252
|
if (!error) return value;
|
|
253
|
+
if (error.status !== void 0) throw error;
|
|
260
254
|
throw Object.assign(error, { status: kvOperationStatus[error.code] ?? 502 });
|
|
261
255
|
}
|
|
262
256
|
function resolvedStores(config) {
|
|
@@ -316,13 +310,12 @@ async function runKVOperation(operation, input, stores = listKVDevStores()) {
|
|
|
316
310
|
return await runOperation(operation, input, stores);
|
|
317
311
|
} catch (error) {
|
|
318
312
|
const code = Reflect.get(Object(error), "code");
|
|
319
|
-
const
|
|
313
|
+
const existingStatus = Reflect.get(Object(error), "status");
|
|
314
|
+
const status = existingStatus ?? (typeof code === "string" ? kvOperationStatus[code] : void 0);
|
|
320
315
|
if (typeof status !== "number" || !(error instanceof Error)) throw error;
|
|
321
316
|
const cause = code === "KV_OPERATION_FAILED" && error.cause instanceof Error ? ` ${error.cause.message}` : "";
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
statusMessage: redactInspectionText(`${error.message}${cause}`)
|
|
325
|
-
});
|
|
317
|
+
if (existingStatus === void 0 || existingStatus === null) Object.assign(error, { status });
|
|
318
|
+
throw Object.assign(error, { statusMessage: redactInspectionText(`${error.message}${cause}`) });
|
|
326
319
|
}
|
|
327
320
|
}
|
|
328
321
|
async function runOperation(operation, input, stores) {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { n as isRecordOrFunction, t as isRecord } from "./object-CAK6UYR5.js";
|
|
2
2
|
import { t as invariant } from "./invariant-Dj2R1eMr.js";
|
|
3
|
+
import "node:module";
|
|
3
4
|
import { readdir } from "node:fs/promises";
|
|
4
5
|
import { basename, dirname, join, parse, relative, resolve } from "node:path";
|
|
5
6
|
import { mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
6
7
|
import { createInterface } from "node:readline/promises";
|
|
8
|
+
import "node:url";
|
|
7
9
|
import { defineDiagnostics } from "nostics";
|
|
8
10
|
import { tmpdir } from "node:os";
|
|
9
|
-
import "node:url";
|
|
10
11
|
import { createBirpc } from "birpc";
|
|
11
12
|
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
12
13
|
// ../internal/src/error-diagnostics.ts
|
|
@@ -39,7 +40,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
39
40
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
40
41
|
},
|
|
41
42
|
INTERNAL_R0024: {
|
|
42
|
-
fix: "Start the dev server
|
|
43
|
+
fix: "Start the dev server (`nuxt dev` or `vite dev`), or pass `--url <origin>` of a deployed app and set VITEHUB_CONSOLE_PRIVATE_KEY_<NAME> to a private key whose public key the app has in VITEHUB_CONSOLE_KEY_<NAME>.",
|
|
43
44
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
44
45
|
},
|
|
45
46
|
INTERNAL_R0023: {
|
|
@@ -155,7 +156,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
155
156
|
fix: "Give a switch column `format: \"switch\"` and `switch: { operation, input }` with a registered operation name, or remove both."
|
|
156
157
|
},
|
|
157
158
|
INTERNAL_R0025: {
|
|
158
|
-
fix: "Start `vite dev` in the project that you run the command from, or pass `--url` of that server.",
|
|
159
|
+
fix: "Start the dev server (`nuxt dev` or `vite dev`) in the project that you run the command from, or pass `--url` of that server.",
|
|
159
160
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
160
161
|
},
|
|
161
162
|
INTERNAL_R0026: {
|
|
@@ -176,7 +177,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
176
177
|
},
|
|
177
178
|
INTERNAL_R0002: {
|
|
178
179
|
...dynamicError,
|
|
179
|
-
fix:
|
|
180
|
+
fix: ({ fix }) => fix ?? "Build for a host that provides this capability, or set the option named in the message to `false`."
|
|
180
181
|
},
|
|
181
182
|
INTERNAL_R0004: {
|
|
182
183
|
...dynamicError,
|
|
@@ -456,6 +457,56 @@ function isServerEnvironment(name, config) {
|
|
|
456
457
|
const VITEHUB_NITRO_CONFIG_CONTEXT = "__vitehubNitroConfigContext";
|
|
457
458
|
const VITEHUB_PROJECT_ROOT = "__vitehubProjectRoot";
|
|
458
459
|
/**
|
|
460
|
+
* Server Env declarations that ViteHub features add before `hubEnv()` builds the registry, such as the Server Env of
|
|
461
|
+
* discovered Channels. The application's `env.server` wins field by field.
|
|
462
|
+
*/
|
|
463
|
+
const VITEHUB_ENV_SERVER = "__vitehubEnvServer";
|
|
464
|
+
function isPackageServerEnvField(value) {
|
|
465
|
+
return Array.isArray(value.names);
|
|
466
|
+
}
|
|
467
|
+
/** The kind of a contributed field. `hubEnv()` declares it as an optional `env()` with a non-canonical source. */
|
|
468
|
+
const PACKAGE_SERVER_ENV_FIELD = "vitehub-package-env-field";
|
|
469
|
+
function packageServerEnvDeclarations(fields) {
|
|
470
|
+
return Object.fromEntries(Object.entries(fields).flatMap(([key, field]) => {
|
|
471
|
+
if (!isPackageServerEnvField(field)) {
|
|
472
|
+
const group = packageServerEnvDeclarations(field);
|
|
473
|
+
return Object.keys(group).length ? [[key, group]] : [];
|
|
474
|
+
}
|
|
475
|
+
return [[key, {
|
|
476
|
+
kind: PACKAGE_SERVER_ENV_FIELD,
|
|
477
|
+
names: [...field.names],
|
|
478
|
+
description: field.description,
|
|
479
|
+
secret: field.secret,
|
|
480
|
+
sourcePatterns: field.sourcePatterns
|
|
481
|
+
}]];
|
|
482
|
+
}));
|
|
483
|
+
}
|
|
484
|
+
function isServerEnvGroup(value) {
|
|
485
|
+
return isRecord(value) && value.kind !== "env-variable" && value.kind !== "vitehub-package-env-field";
|
|
486
|
+
}
|
|
487
|
+
function mergeServerEnvGroups(base, added) {
|
|
488
|
+
const merged = { ...base };
|
|
489
|
+
for (const [key, value] of Object.entries(added)) {
|
|
490
|
+
const current = merged[key];
|
|
491
|
+
merged[key] = isServerEnvGroup(current) && isServerEnvGroup(value) ? mergeServerEnvGroups(current, value) : current ?? value;
|
|
492
|
+
}
|
|
493
|
+
return merged;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Declare in Server Env the host variables that a package reads for its configured provider, under
|
|
497
|
+
* `env.server.<group>`, so `inspectServerEnv()` and Setup pages list them with a description. Each value is optional:
|
|
498
|
+
* the package reports a missing value when it uses the provider, and `deployment.json` keeps the deploy rule. The
|
|
499
|
+
* source claims no canonical name, so the application can also read the variable under its own key. Declarations
|
|
500
|
+
* that another feature already added at the same path stay, and the application's `env.server` wins field by field.
|
|
501
|
+
*/
|
|
502
|
+
function contributeServerEnv(config, group, fields) {
|
|
503
|
+
const declarations = packageServerEnvDeclarations(fields);
|
|
504
|
+
if (!Object.keys(declarations).length) return;
|
|
505
|
+
const contributed = Reflect.get(config, VITEHUB_ENV_SERVER);
|
|
506
|
+
const server = isRecord(contributed) ? contributed : {};
|
|
507
|
+
Reflect.set(config, VITEHUB_ENV_SERVER, mergeServerEnvGroups(server, { [group]: declarations }));
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
459
510
|
* Set by `vite-hub/nuxt` when it replays Vite config hooks for `nuxt prepare`. Prepare uses `command: "build"` to write
|
|
460
511
|
* the same types as the build, but it builds nothing.
|
|
461
512
|
*/
|
|
@@ -1130,7 +1181,6 @@ function operationSection(operation, input) {
|
|
|
1130
1181
|
function isSectionScope(scope) {
|
|
1131
1182
|
return isSectionId(scope) && scope !== "read";
|
|
1132
1183
|
}
|
|
1133
|
-
/** `"blob:media"` → `["blob:media", "blob"]`: a grant of the section covers each of its scopes. */
|
|
1134
1184
|
function grantsFor(section) {
|
|
1135
1185
|
const separator = section.indexOf(":");
|
|
1136
1186
|
return separator === -1 ? [section] : [section, section.slice(0, separator)];
|
|
@@ -1362,14 +1412,15 @@ async function callOperation(target, name, input) {
|
|
|
1362
1412
|
};
|
|
1363
1413
|
}
|
|
1364
1414
|
if (response.status === 401 || response.status >= 300 && response.status < 400) return unreachable(`${url.origin} asked for authentication (HTTP ${response.status}).`, 401);
|
|
1365
|
-
return unreachable(`${url.origin} did not answer as a ViteHub app (HTTP ${response.status}). Pass the origin of an app that runs ViteHub
|
|
1415
|
+
return unreachable(`${url.origin} did not answer as a ViteHub app (HTTP ${response.status}). ${response.status === 404 && !target.roots?.length ? "A production build answers ViteHub operations only when `vitehub()` sets `console`. Set it, deploy again, and pass the origin of that app." : "Pass the origin of an app that runs ViteHub."}`, response.status);
|
|
1366
1416
|
} catch (error) {
|
|
1367
1417
|
return unreachable(`The request to ${origin} failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1368
1418
|
}
|
|
1369
1419
|
}
|
|
1370
1420
|
/**
|
|
1371
1421
|
* Call one operation from a `vitehub` command: on `--url` when it is set, else on the dev server that the project
|
|
1372
|
-
* started.
|
|
1422
|
+
* started. A call on `--url` goes through the Console when `consoleRoute` finds the app there. Never throws. Without a
|
|
1423
|
+
* dev server the result is an `INTERNAL_R0024` failure that says to start one.
|
|
1373
1424
|
*/
|
|
1374
1425
|
async function callOperationFromCli(call, name, input) {
|
|
1375
1426
|
let roots;
|
|
@@ -1378,15 +1429,28 @@ async function callOperationFromCli(call, name, input) {
|
|
|
1378
1429
|
} catch {
|
|
1379
1430
|
roots = [call.rootDir];
|
|
1380
1431
|
}
|
|
1432
|
+
const target = {
|
|
1433
|
+
...call.confirmed !== void 0 ? { confirmed: call.confirmed } : {},
|
|
1434
|
+
env: call.env,
|
|
1435
|
+
...call.fetch ? { fetch: call.fetch } : {}
|
|
1436
|
+
};
|
|
1437
|
+
if (call.url && call.consoleRoute && !hasCredentials(call.env)) {
|
|
1438
|
+
const signal = AbortSignal.timeout(call.timeout ?? 3e4);
|
|
1439
|
+
const route = await call.consoleRoute(call.url, signal);
|
|
1440
|
+
return await callOperation({
|
|
1441
|
+
...target,
|
|
1442
|
+
...route ? { authorization: route.authorization } : {},
|
|
1443
|
+
signal,
|
|
1444
|
+
url: route?.target ?? call.url
|
|
1445
|
+
}, name, input);
|
|
1446
|
+
}
|
|
1381
1447
|
const url = call.url ?? findViteHubDevServerUrl(roots, call.env);
|
|
1382
1448
|
if (!url) return unreachable(`No dev server is running for ${roots.at(-1)}.`);
|
|
1383
1449
|
return await callOperation({
|
|
1384
|
-
...
|
|
1385
|
-
env: call.env,
|
|
1386
|
-
...call.fetch ? { fetch: call.fetch } : {},
|
|
1450
|
+
...target,
|
|
1387
1451
|
...call.url ? {} : { roots },
|
|
1388
1452
|
...call.timeout ? { timeout: call.timeout } : {},
|
|
1389
1453
|
url
|
|
1390
1454
|
}, name, input);
|
|
1391
1455
|
}
|
|
1392
|
-
export {
|
|
1456
|
+
export { readViteHubDevServerFile as A, markViteConfigPlugin as C, listSeedFiles as D, askOnTerminal as E, internalErrorDiagnostics as F, removeViteHubDevServerFile as M, writeCliFailure as N, parseCliPositiveInteger as O, writeViteHubDevServerFile as P, isServerEnvironment as S, shouldSkipViteProviderBuild as T, VITEHUB_PREPARE as _, operationRootHeader as a, createNoExternalAddition as b, projectRootHash as c, defineOperation as d, answerOperationRpc as f, VITEHUB_NITRO_CONFIG_CONTEXT as g, readOperationRpcCall as h, createOperationRegistry as i, readViteHubDevTargetOption as j, readCliOptionValue 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, resolveViteHubProjectRoot as w, hasNitroConfigContext as x, contributeServerEnv as y };
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as AnyOperation } from "./
|
|
2
|
-
import { c as KVDriver } from "./types-
|
|
1
|
+
import { t as AnyOperation } from "./operations-BAlr2zUj.js";
|
|
2
|
+
import { c as KVDriver } from "./types-BLxnI_rU.js";
|
|
3
3
|
interface KVDevListResult {
|
|
4
4
|
/** Present when more keys exist. Pass it as `--cursor` to read the next page. */
|
|
5
5
|
cursor?: string;
|
package/dist/operations.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { F 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-DP8iWjQK.js";
|
|
2
2
|
import { t as kvDevMaximumListLimit } from "./results-emgN7uDS.js";
|
|
3
3
|
import { n as isViteHubLoopbackPeer } from "./dev-peer-D0vOxmrD.js";
|
|
4
4
|
import * as v from "valibot";
|
|
@@ -235,7 +235,7 @@ function createStandaloneOperationHandler(sources, root) {
|
|
|
235
235
|
} };
|
|
236
236
|
}
|
|
237
237
|
// src/operations.ts
|
|
238
|
-
const runtime = () => import("./operations-
|
|
238
|
+
const runtime = () => import("./operations-Cj_0pSSA.js");
|
|
239
239
|
const store = v.optional(v.pipe(v.string(), v.check((name) => name.trim() !== "", "Name a store.")));
|
|
240
240
|
const key = v.string();
|
|
241
241
|
function defineKVOperation(definition) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as KVRuntimeDriver } from "../driver-
|
|
1
|
+
import { t as KVRuntimeDriver } from "../driver-CZTAQ_07.js";
|
|
2
2
|
declare function createCloudflareDriver(options: Record<string, unknown>): KVRuntimeDriver;
|
|
3
3
|
export declare function createCloudflareKVStorage(options: Record<string, unknown>): unknown;
|
|
4
4
|
export { createCloudflareDriver as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { n as createCloudflareKVStorage, t as default } from "../cloudflare-kv-
|
|
1
|
+
export { n as createCloudflareKVStorage, t as default } from "../cloudflare-kv-hMdZQZz1.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as logFailure } from "../request-log-DllKQXj7.js";
|
|
2
|
-
import { t as kvInferredStoreNotice } from "../config-
|
|
2
|
+
import { t as kvInferredStoreNotice } from "../config-x_Nru3R5.js";
|
|
3
3
|
import { disposeKVStores } from "@vite-hub/kv";
|
|
4
4
|
// src/runtime/nitro-plugin.ts
|
|
5
5
|
async function logInferredStores() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { z as ResolvedRedisKVStoreConfig } from "../types-
|
|
2
|
-
import { t as KVRuntimeDriver } from "../driver-
|
|
1
|
+
import { z as ResolvedRedisKVStoreConfig } from "../types-BLxnI_rU.js";
|
|
2
|
+
import { t as KVRuntimeDriver } from "../driver-CZTAQ_07.js";
|
|
3
3
|
/** The URL of a store: `env:<NAME>` reads the variable now, so a build never holds the URL of its server. */
|
|
4
4
|
export declare function resolveRedisUrl(url: string, env?: Record<string, string | undefined>): string;
|
|
5
5
|
/**
|