@vite-hub/kv 0.3.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 +19 -13
- package/dist/{cli-DpPhz_Ek.d.ts → cli-CLomw9ml.d.ts} +1 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +24 -12
- package/dist/{cloudflare-env-lOtHHsgP.js → cloudflare-env-Dl349h_9.js} +2 -1
- package/dist/{cloudflare-kv-BIEUFzRT.js → cloudflare-kv-DQJhmGof.js} +22 -10
- package/dist/{cloudflare-kv-local-BBw3ZT1K.js → cloudflare-kv-local-COjgHweC.js} +3 -7
- package/dist/{config-BXEVoZE3.js → config-pfyPiPrI.js} +65 -28
- package/dist/{create-storage-BGsrQKw3.js → create-storage-DQ1BbFqH.js} +5 -5
- package/dist/{cursor-history-BqIQePNP.js → cursor-history-CAT4mpP1.js} +7 -3
- package/dist/{deno-kv-BM9mYdUp.js → deno-kv-Cf0ZveeN.js} +43 -7
- package/dist/driver-Du6Eh9p2.d.ts +47 -0
- package/dist/{error-diagnostics-BxqvtEIb.js → error-diagnostics-C4VTHInS.js} +16 -4
- package/dist/errors-BpiM-Vmh.js +125 -0
- package/dist/errors.d.ts +13 -1
- package/dist/errors.js +2 -2
- package/dist/{fs-lite-BLZId9_P.js → fs-lite-BTcBUP6B.js} +1 -1
- package/dist/fs-lite-C8yXCVDM.js +2 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +39 -52
- package/dist/{operation-definition-8gOe-ubD.d.ts → operation-definition-CI2PJGqu.d.ts} +13 -2
- package/dist/{operations-Ch-gKaey.js → operations-CqKs7Ykc.js} +24 -45
- package/dist/{operations-B-WZ7P1h.js → operations-nAaONxzh.js} +273 -231
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +4 -3
- package/dist/out-BbXG-yVX.js +21755 -0
- package/dist/{redis-shared-E5mahECF.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/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-72Jk3VVk.js → runtime/database.js} +68 -37
- package/dist/runtime/nitro-plugin.js +12 -5
- package/dist/runtime/redis-driver.d.ts +2 -2
- package/dist/runtime/redis-driver.js +2 -5
- package/dist/runtime/unstorage-driver.js +6 -2
- package/dist/runtime/upstash-driver.d.ts +2 -2
- package/dist/runtime/upstash-driver.js +2 -6
- package/dist/{types-DEiKew_3.d.ts → types-Cp6IBhSN.d.ts} +36 -37
- package/dist/{upstash-DDlqTttY.js → upstash-5sTbIR35.js} +2 -2
- package/dist/virtual-module.d.ts +1 -0
- package/dist/vite.d.ts +21 -6
- package/dist/vite.js +2738 -415
- package/package.json +10 -5
- package/dist/driver-BwxgaQ-f.d.ts +0 -15
- package/dist/errors-DbwufFZp.js +0 -60
- package/dist/fs-lite-RAoxu8L0.js +0 -2
- package/dist/main-F3Y22_uV.js +0 -2353
|
@@ -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;
|
|
@@ -87,12 +66,6 @@ function inspectKVValue(value) {
|
|
|
87
66
|
//#endregion
|
|
88
67
|
//#region src/runtime/preview.ts
|
|
89
68
|
const maximumValueBytes = 262144;
|
|
90
|
-
function valueType(value) {
|
|
91
|
-
if (value === null) return "null";
|
|
92
|
-
if (Array.isArray(value)) return "array";
|
|
93
|
-
if (value instanceof Uint8Array) return "bytes";
|
|
94
|
-
return typeof value;
|
|
95
|
-
}
|
|
96
69
|
function truncateValue(value) {
|
|
97
70
|
const encoder = new TextEncoder();
|
|
98
71
|
let bytes = 0;
|
|
@@ -113,6 +86,7 @@ function truncateValue(value) {
|
|
|
113
86
|
}
|
|
114
87
|
function boundedJSONStringify(value) {
|
|
115
88
|
let editable = true;
|
|
89
|
+
let unsupported = false;
|
|
116
90
|
let bytes = 0;
|
|
117
91
|
let rendered = "";
|
|
118
92
|
let truncated = false;
|
|
@@ -152,7 +126,8 @@ function boundedJSONStringify(value) {
|
|
|
152
126
|
editable = false;
|
|
153
127
|
const toJSON = Reflect.get(Object(input), "toJSON");
|
|
154
128
|
if (applyToJSON && typeof toJSON === "function") return serialize(toJSON.call(input, key), depth, arrayValue, key, false);
|
|
155
|
-
|
|
129
|
+
unsupported = true;
|
|
130
|
+
return false;
|
|
156
131
|
}
|
|
157
132
|
const object = Object(input);
|
|
158
133
|
const prototype = Object.getPrototypeOf(object);
|
|
@@ -171,7 +146,10 @@ function boundedJSONStringify(value) {
|
|
|
171
146
|
editable = false;
|
|
172
147
|
return serialize(boxed, depth, arrayValue, key);
|
|
173
148
|
}
|
|
174
|
-
if (ancestors.has(object))
|
|
149
|
+
if (ancestors.has(object)) {
|
|
150
|
+
unsupported = true;
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
175
153
|
if (seen.has(object)) editable = false;
|
|
176
154
|
seen.add(object);
|
|
177
155
|
ancestors.add(object);
|
|
@@ -210,6 +188,7 @@ function boundedJSONStringify(value) {
|
|
|
210
188
|
return append("}");
|
|
211
189
|
}
|
|
212
190
|
const serialized = serialize(value, 0, false, "");
|
|
191
|
+
if (unsupported) return void 0;
|
|
213
192
|
return {
|
|
214
193
|
editable,
|
|
215
194
|
truncated,
|
|
@@ -218,7 +197,7 @@ function boundedJSONStringify(value) {
|
|
|
218
197
|
}
|
|
219
198
|
/** A stored value as text of at most 256 KiB, for a page that shows it. Bytes become hex. */
|
|
220
199
|
function previewKVValue(value) {
|
|
221
|
-
const type =
|
|
200
|
+
const type = kvValueType(value);
|
|
222
201
|
let format = "json";
|
|
223
202
|
let rendered;
|
|
224
203
|
let truncated = false;
|
|
@@ -227,19 +206,21 @@ function previewKVValue(value) {
|
|
|
227
206
|
editable = true;
|
|
228
207
|
format = "text";
|
|
229
208
|
rendered = value;
|
|
230
|
-
} else if (value
|
|
209
|
+
} else if (isUint8Array(value)) {
|
|
231
210
|
format = "text";
|
|
232
211
|
const maximumBytes = maximumValueBytes / 2;
|
|
233
212
|
truncated = value.byteLength > maximumBytes;
|
|
234
213
|
rendered = Array.from(value.subarray(0, maximumBytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
235
|
-
} else
|
|
214
|
+
} else {
|
|
236
215
|
const result = boundedJSONStringify(value);
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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
|
+
}
|
|
243
224
|
}
|
|
244
225
|
const result = truncateValue(rendered);
|
|
245
226
|
const formatted = {
|
|
@@ -266,7 +247,6 @@ try {
|
|
|
266
247
|
} catch (error) {
|
|
267
248
|
if (!isMissingKVConfig(error)) throw error;
|
|
268
249
|
}
|
|
269
|
-
/** The HTTP status that the CLI, the Console, and Agents report for each code of a failed operation. */
|
|
270
250
|
const kvOperationStatus = {
|
|
271
251
|
KV_DISABLED: 409,
|
|
272
252
|
KV_INVALID_CURSOR: 400,
|
|
@@ -314,7 +294,6 @@ function selectStore(stores, name = "default") {
|
|
|
314
294
|
storage: name === "default" ? kv : kv.store(name)
|
|
315
295
|
};
|
|
316
296
|
}
|
|
317
|
-
/** The keys under `vitehub:` belong to ViteHub, which keeps its own state there. */
|
|
318
297
|
function requireWritableKey(operation, key) {
|
|
319
298
|
if (!normalizeKey(key).toLowerCase().startsWith("vitehub:")) return;
|
|
320
299
|
throw kvErrorDiagnostics.KV_RESERVED_KEY({
|