@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.
Files changed (50) hide show
  1. package/README.md +19 -13
  2. package/dist/{cli-DpPhz_Ek.d.ts → cli-CLomw9ml.d.ts} +1 -0
  3. package/dist/cli.d.ts +1 -1
  4. package/dist/cli.js +24 -12
  5. package/dist/{cloudflare-env-lOtHHsgP.js → cloudflare-env-Dl349h_9.js} +2 -1
  6. package/dist/{cloudflare-kv-BIEUFzRT.js → cloudflare-kv-DQJhmGof.js} +22 -10
  7. package/dist/{cloudflare-kv-local-BBw3ZT1K.js → cloudflare-kv-local-COjgHweC.js} +3 -7
  8. package/dist/{config-BXEVoZE3.js → config-pfyPiPrI.js} +65 -28
  9. package/dist/{create-storage-BGsrQKw3.js → create-storage-DQ1BbFqH.js} +5 -5
  10. package/dist/{cursor-history-BqIQePNP.js → cursor-history-CAT4mpP1.js} +7 -3
  11. package/dist/{deno-kv-BM9mYdUp.js → deno-kv-Cf0ZveeN.js} +43 -7
  12. package/dist/driver-Du6Eh9p2.d.ts +47 -0
  13. package/dist/{error-diagnostics-BxqvtEIb.js → error-diagnostics-C4VTHInS.js} +16 -4
  14. package/dist/errors-BpiM-Vmh.js +125 -0
  15. package/dist/errors.d.ts +13 -1
  16. package/dist/errors.js +2 -2
  17. package/dist/{fs-lite-BLZId9_P.js → fs-lite-BTcBUP6B.js} +1 -1
  18. package/dist/fs-lite-C8yXCVDM.js +2 -0
  19. package/dist/index.d.ts +2 -2
  20. package/dist/index.js +39 -52
  21. package/dist/{operation-definition-8gOe-ubD.d.ts → operation-definition-CI2PJGqu.d.ts} +13 -2
  22. package/dist/{operations-Ch-gKaey.js → operations-CqKs7Ykc.js} +24 -45
  23. package/dist/{operations-B-WZ7P1h.js → operations-nAaONxzh.js} +273 -231
  24. package/dist/operations.d.ts +2 -2
  25. package/dist/operations.js +4 -3
  26. package/dist/out-BbXG-yVX.js +21755 -0
  27. package/dist/{redis-shared-E5mahECF.js → redis-shared-1M0IaguQ.js} +1 -1
  28. package/dist/request-log-Dj9Vw7qG.js +105 -0
  29. package/dist/{results-p7nPCnaJ.js → results-D6jfPtCk.js} +0 -1
  30. package/dist/runtime/cloudflare-kv.d.ts +1 -1
  31. package/dist/runtime/cloudflare-kv.js +1 -1
  32. package/dist/runtime/cloudflare-request-env.js +1 -1
  33. package/dist/runtime/database.d.ts +2 -0
  34. package/dist/{database-72Jk3VVk.js → runtime/database.js} +68 -37
  35. package/dist/runtime/nitro-plugin.js +12 -5
  36. package/dist/runtime/redis-driver.d.ts +2 -2
  37. package/dist/runtime/redis-driver.js +2 -5
  38. package/dist/runtime/unstorage-driver.js +6 -2
  39. package/dist/runtime/upstash-driver.d.ts +2 -2
  40. package/dist/runtime/upstash-driver.js +2 -6
  41. package/dist/{types-DEiKew_3.d.ts → types-Cp6IBhSN.d.ts} +36 -37
  42. package/dist/{upstash-DDlqTttY.js → upstash-5sTbIR35.js} +2 -2
  43. package/dist/virtual-module.d.ts +1 -0
  44. package/dist/vite.d.ts +21 -6
  45. package/dist/vite.js +2738 -415
  46. package/package.json +10 -5
  47. package/dist/driver-BwxgaQ-f.d.ts +0 -15
  48. package/dist/errors-DbwufFZp.js +0 -60
  49. package/dist/fs-lite-RAoxu8L0.js +0 -2
  50. 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 invariantError } from "./invariant-DolT9EEx.js";
3
- import { n as kvErrorDiagnostics } from "./error-diagnostics-BxqvtEIb.js";
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
- try {
26
- const lengthGetter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype), "length")?.get;
27
- if (!lengthGetter) throw unsupported();
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
- throw invariantError("JSON has no bigint without `toJSON()`");
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)) throw invariantError("JSON has no circular value");
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 = valueType(value);
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 instanceof Uint8Array) {
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 try {
214
+ } else {
236
215
  const result = boundedJSONStringify(value);
237
- rendered = result.value ?? String(value);
238
- truncated = result.truncated;
239
- editable = result.editable;
240
- } catch {
241
- format = "text";
242
- rendered = String(value);
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({