@vite-hub/kv 0.0.4 → 0.3.1

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 (63) hide show
  1. package/README.md +110 -14
  2. package/dist/batch--v0ri69O.js +40 -0
  3. package/dist/cli-DpPhz_Ek.d.ts +163 -0
  4. package/dist/cli.d.ts +17 -0
  5. package/dist/cli.js +469 -0
  6. package/dist/cloudflare-env-lOtHHsgP.js +46 -0
  7. package/dist/cloudflare-env-lookup-Bs0VDpU5.js +42 -0
  8. package/dist/cloudflare-kv-BIEUFzRT.js +187 -0
  9. package/dist/cloudflare-kv-local-BBw3ZT1K.js +71 -0
  10. package/dist/config-BXEVoZE3.js +250 -0
  11. package/dist/{dist-DDW1iC5f.js → create-storage-BGsrQKw3.js} +266 -115
  12. package/dist/cursor-history-BqIQePNP.js +165 -0
  13. package/dist/database-72Jk3VVk.js +250 -0
  14. package/dist/deno-kv-BM9mYdUp.js +128 -0
  15. package/dist/dev-peer-CHafxbtj.js +238 -0
  16. package/dist/driver-BwxgaQ-f.d.ts +15 -0
  17. package/dist/durability.d.ts +17 -0
  18. package/dist/durability.js +53 -0
  19. package/dist/error-diagnostics-BxqvtEIb.js +147 -0
  20. package/dist/errors-DbwufFZp.js +60 -0
  21. package/dist/errors.d.ts +23 -7
  22. package/dist/errors.js +2 -20
  23. package/dist/fs-lite-BLZId9_P.js +386 -0
  24. package/dist/fs-lite-RAoxu8L0.js +2 -0
  25. package/dist/index.d.ts +10 -4
  26. package/dist/index.js +364 -109
  27. package/dist/inspect-BIKQsqX4.js +118 -0
  28. package/dist/invariant-DolT9EEx.js +22 -0
  29. package/dist/main-F3Y22_uV.js +2353 -0
  30. package/dist/object-Da1zyPCR.js +11 -0
  31. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  32. package/dist/operations-B-WZ7P1h.js +1351 -0
  33. package/dist/operations-Ch-gKaey.js +441 -0
  34. package/dist/operations.d.ts +75 -0
  35. package/dist/operations.js +318 -0
  36. package/dist/redis-shared-E5mahECF.js +94 -0
  37. package/dist/results-p7nPCnaJ.js +6 -0
  38. package/dist/rolldown-runtime-CMFfr-1z.js +26 -0
  39. package/dist/runtime/cloudflare-kv.d.ts +3 -4
  40. package/dist/runtime/cloudflare-kv.js +1 -23
  41. package/dist/runtime/cloudflare-request-env.d.ts +7 -0
  42. package/dist/runtime/cloudflare-request-env.js +11 -0
  43. package/dist/runtime/nitro-plugin.d.ts +12 -0
  44. package/dist/runtime/nitro-plugin.js +22 -0
  45. package/dist/runtime/redis-driver.d.ts +11 -0
  46. package/dist/runtime/redis-driver.js +113 -0
  47. package/dist/runtime/unstorage-driver.d.ts +14 -0
  48. package/dist/runtime/unstorage-driver.js +33 -0
  49. package/dist/runtime/upstash-driver.d.ts +4 -6
  50. package/dist/runtime/upstash-driver.js +60 -110
  51. package/dist/{driver-BT9WefKi.d.ts → types-Bj3EQoRg.d.ts} +16 -11
  52. package/dist/types-DEiKew_3.d.ts +312 -0
  53. package/dist/upstash-DDlqTttY.js +40 -0
  54. package/dist/utils2-FozcTsmb.js +31 -0
  55. package/dist/virtual-module.d.ts +2 -0
  56. package/dist/virtual.d.ts +1 -1
  57. package/dist/vite.d.ts +159 -14
  58. package/dist/vite.js +1329 -2898
  59. package/package.json +68 -19
  60. package/dist/config-aM9Ae7tH.js +0 -110
  61. package/dist/deno-kv-cJx3jU10.js +0 -69
  62. package/dist/fs-lite-BxzdiJSi.js +0 -79
  63. package/dist/types-CO0DRjJa.d.ts +0 -78
@@ -0,0 +1,441 @@
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";
5
+ import { o as normalizeKey } from "./utils2-FozcTsmb.js";
6
+ import { kv } from "@vite-hub/kv";
7
+ //#region src/runtime/inspect-value.ts
8
+ const unsupported = () => kvErrorDiagnostics.KV_VALUE_UNSUPPORTED();
9
+ function isUint8Array(value) {
10
+ try {
11
+ if (!ArrayBuffer.isView(value)) return false;
12
+ const tagGetter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype), Symbol.toStringTag)?.get;
13
+ return Boolean(tagGetter && Reflect.apply(tagGetter, value, []) === "Uint8Array");
14
+ } catch {
15
+ return false;
16
+ }
17
+ }
18
+ function kvValueType(value) {
19
+ if (value === null) return "null";
20
+ if (Array.isArray(value)) return "array";
21
+ if (isUint8Array(value)) return "bytes";
22
+ return typeof value;
23
+ }
24
+ 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
+ }
47
+ }
48
+ /** JSON inspection accepts JSON values and represents bigint values as decimal strings. */
49
+ function inspectValue(value, seen = /* @__PURE__ */ new WeakSet()) {
50
+ if (typeof value === "bigint") return value.toString();
51
+ if (value === null || typeof value === "string" || typeof value === "boolean") return value;
52
+ if (typeof value === "number" && Number.isFinite(value) && !Object.is(value, -0)) return value;
53
+ if (typeof value !== "object" && typeof value !== "function" || seen.has(value)) throw unsupported();
54
+ seen.add(value);
55
+ try {
56
+ const ownKeys = Reflect.ownKeys(value);
57
+ const dataKeys = Array.isArray(value) ? ownKeys.filter((key) => key !== "length") : ownKeys;
58
+ if (dataKeys.map((key) => Object.getOwnPropertyDescriptor(value, key)).some((descriptor) => !descriptor?.enumerable || !("value" in descriptor))) throw unsupported();
59
+ if (Array.isArray(value)) {
60
+ if (dataKeys.length !== value.length || dataKeys.some((key) => typeof key !== "string" || String(Number(key)) !== key || !Number.isInteger(Number(key)) || Number(key) < 0 || Number(key) >= value.length)) throw unsupported();
61
+ return Array.from({ length: value.length }, (_, index) => inspectValue(Object.getOwnPropertyDescriptor(value, String(index))?.value, seen));
62
+ }
63
+ const prototype = Object.getPrototypeOf(value);
64
+ if (prototype !== Object.prototype && prototype !== null || Object.getOwnPropertySymbols(value).length) throw unsupported();
65
+ return Object.fromEntries(dataKeys.map((key) => [key, inspectValue(Object.getOwnPropertyDescriptor(value, key)?.value, seen)]));
66
+ } finally {
67
+ seen.delete(value);
68
+ }
69
+ }
70
+ /** Encodes one inspection result without running getters or exposing non-JSON object behavior. */
71
+ function inspectKVValue(value) {
72
+ try {
73
+ if (isUint8Array(value)) return {
74
+ encoding: "base64",
75
+ type: "bytes",
76
+ value: encodeBase64(value)
77
+ };
78
+ return {
79
+ type: kvValueType(value),
80
+ value: inspectValue(value)
81
+ };
82
+ } catch (error) {
83
+ if (Reflect.get(Object(error), "code") === "KV_VALUE_UNSUPPORTED") return;
84
+ throw error;
85
+ }
86
+ }
87
+ //#endregion
88
+ //#region src/runtime/preview.ts
89
+ 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
+ function truncateValue(value) {
97
+ const encoder = new TextEncoder();
98
+ let bytes = 0;
99
+ let end = 0;
100
+ for (const character of value) {
101
+ const characterBytes = encoder.encode(character).byteLength;
102
+ if (bytes + characterBytes > maximumValueBytes) return {
103
+ truncated: true,
104
+ value: value.slice(0, end)
105
+ };
106
+ bytes += characterBytes;
107
+ end += character.length;
108
+ }
109
+ return {
110
+ truncated: false,
111
+ value
112
+ };
113
+ }
114
+ function boundedJSONStringify(value) {
115
+ let editable = true;
116
+ let bytes = 0;
117
+ let rendered = "";
118
+ let truncated = false;
119
+ const encoder = new TextEncoder();
120
+ const ancestors = /* @__PURE__ */ new Set();
121
+ const seen = /* @__PURE__ */ new Set();
122
+ function append(fragment) {
123
+ for (const character of fragment) {
124
+ const characterBytes = encoder.encode(character).byteLength;
125
+ if (bytes + characterBytes > maximumValueBytes) {
126
+ truncated = true;
127
+ return false;
128
+ }
129
+ rendered += character;
130
+ bytes += characterBytes;
131
+ }
132
+ return true;
133
+ }
134
+ function appendString(text) {
135
+ if (!append("\"")) return false;
136
+ for (const character of text) if (!append(JSON.stringify(character).slice(1, -1))) return false;
137
+ return append("\"");
138
+ }
139
+ function serialize(input, depth, arrayValue, key, applyToJSON = true) {
140
+ if (typeof input === "string") return appendString(input);
141
+ if (input === null) return append("null");
142
+ if (typeof input === "number") {
143
+ if (!Number.isFinite(input) || Object.is(input, -0)) editable = false;
144
+ return append(Number.isFinite(input) ? String(input) : "null");
145
+ }
146
+ if (typeof input === "boolean") return append(input ? "true" : "false");
147
+ if (typeof input === "undefined" || typeof input === "function" || typeof input === "symbol") {
148
+ editable = false;
149
+ return arrayValue ? append("null") : false;
150
+ }
151
+ if (typeof input === "bigint") {
152
+ editable = false;
153
+ const toJSON = Reflect.get(Object(input), "toJSON");
154
+ if (applyToJSON && typeof toJSON === "function") return serialize(toJSON.call(input, key), depth, arrayValue, key, false);
155
+ throw invariantError("JSON has no bigint without `toJSON()`");
156
+ }
157
+ const object = Object(input);
158
+ const prototype = Object.getPrototypeOf(object);
159
+ if (Array.isArray(object) ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) editable = false;
160
+ const keys = Reflect.ownKeys(object).filter((key) => !Array.isArray(object) || key !== "length");
161
+ if (keys.some((key) => typeof key === "symbol" || !Object.getOwnPropertyDescriptor(object, key)?.enumerable)) editable = false;
162
+ if (Array.isArray(object) && keys.length !== object.length) editable = false;
163
+ const toJSON = Reflect.get(object, "toJSON");
164
+ if (applyToJSON && typeof toJSON === "function") {
165
+ editable = false;
166
+ const replacement = toJSON.call(input, key);
167
+ if (replacement !== input) return serialize(replacement, depth, arrayValue, key, false);
168
+ }
169
+ const boxed = input instanceof Number || input instanceof String || input instanceof Boolean || Object.prototype.toString.call(input) === "[object BigInt]" ? Reflect.apply(object.valueOf, input, []) : input;
170
+ if (boxed !== input) {
171
+ editable = false;
172
+ return serialize(boxed, depth, arrayValue, key);
173
+ }
174
+ if (ancestors.has(object)) throw invariantError("JSON has no circular value");
175
+ if (seen.has(object)) editable = false;
176
+ seen.add(object);
177
+ ancestors.add(object);
178
+ if (Array.isArray(object)) {
179
+ if (!append("[")) return false;
180
+ for (let index = 0; index < object.length; index += 1) {
181
+ if (!append(`${index === 0 ? "" : ","}\n${" ".repeat(depth + 1)}`)) return false;
182
+ if (!serialize(object[index], depth + 1, true, String(index))) return false;
183
+ }
184
+ if (object.length > 0 && !append(`\n${" ".repeat(depth)}`)) return false;
185
+ ancestors.delete(object);
186
+ return append("]");
187
+ }
188
+ if (!append("{")) return false;
189
+ let count = 0;
190
+ for (const key in object) {
191
+ if (!Object.prototype.hasOwnProperty.call(object, key)) continue;
192
+ let item = Reflect.get(object, key);
193
+ if (item !== null && (typeof item === "object" || typeof item === "bigint")) {
194
+ const toJSON = Reflect.get(Object(item), "toJSON");
195
+ if (typeof toJSON === "function") {
196
+ editable = false;
197
+ item = toJSON.call(item, key);
198
+ }
199
+ }
200
+ if (typeof item === "undefined" || typeof item === "function" || typeof item === "symbol") {
201
+ editable = false;
202
+ continue;
203
+ }
204
+ if (!append(`${count === 0 ? "" : ","}\n${" ".repeat(depth + 1)}`)) return false;
205
+ if (!appendString(key) || !append(": ") || !serialize(item, depth + 1, false, key, false)) return false;
206
+ count += 1;
207
+ }
208
+ if (count > 0 && !append(`\n${" ".repeat(depth)}`)) return false;
209
+ ancestors.delete(object);
210
+ return append("}");
211
+ }
212
+ const serialized = serialize(value, 0, false, "");
213
+ return {
214
+ editable,
215
+ truncated,
216
+ value: serialized || truncated ? rendered : void 0
217
+ };
218
+ }
219
+ /** A stored value as text of at most 256 KiB, for a page that shows it. Bytes become hex. */
220
+ function previewKVValue(value) {
221
+ const type = valueType(value);
222
+ let format = "json";
223
+ let rendered;
224
+ let truncated = false;
225
+ let editable = false;
226
+ if (typeof value === "string") {
227
+ editable = true;
228
+ format = "text";
229
+ rendered = value;
230
+ } else if (value instanceof Uint8Array) {
231
+ format = "text";
232
+ const maximumBytes = maximumValueBytes / 2;
233
+ truncated = value.byteLength > maximumBytes;
234
+ rendered = Array.from(value.subarray(0, maximumBytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
235
+ } else try {
236
+ 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);
243
+ }
244
+ const result = truncateValue(rendered);
245
+ const formatted = {
246
+ editable: editable && !truncated && !result.truncated,
247
+ format,
248
+ type,
249
+ value: result.value
250
+ };
251
+ if (truncated || result.truncated) formatted.truncated = true;
252
+ return formatted;
253
+ }
254
+ //#endregion
255
+ //#region src/runtime/operations.ts
256
+ function isMissingKVConfig(error) {
257
+ const code = error instanceof Error && "code" in error ? error.code : void 0;
258
+ const message = error instanceof Error ? error.message : "";
259
+ if (code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") return /^Cannot find (?:package|module) ["']#vitehub\/kv\/config["']/.test(message);
260
+ if (code === "ERR_PACKAGE_IMPORT_NOT_DEFINED") return /^Package import specifier ["']#vitehub\/kv\/config["'] is not defined/.test(message);
261
+ return false;
262
+ }
263
+ let kvConfig = false;
264
+ try {
265
+ kvConfig = (await import("#vitehub/kv/config")).kv;
266
+ } catch (error) {
267
+ if (!isMissingKVConfig(error)) throw error;
268
+ }
269
+ /** The HTTP status that the CLI, the Console, and Agents report for each code of a failed operation. */
270
+ const kvOperationStatus = {
271
+ KV_DISABLED: 409,
272
+ KV_INVALID_CURSOR: 400,
273
+ KV_INVALID_INPUT: 400,
274
+ KV_RESERVED_KEY: 403,
275
+ KV_STORE_NOT_FOUND: 404,
276
+ KV_VALUE_UNSUPPORTED: 422
277
+ };
278
+ const maximumKeyLength = 2048;
279
+ function unwrap(result) {
280
+ const [error, value] = result;
281
+ if (!error) return value;
282
+ throw Object.assign(error, { status: kvOperationStatus[error.code] ?? 502 });
283
+ }
284
+ function resolvedStores(config) {
285
+ if (!config) return [];
286
+ const stores = Object.entries(config.stores ?? { default: config.store }).map(([name, store]) => ({
287
+ driver: store.driver,
288
+ name
289
+ }));
290
+ return [...stores.filter((store) => store.name === "default"), ...stores.filter((store) => store.name !== "default").sort((left, right) => left.name.localeCompare(right.name))];
291
+ }
292
+ /** Returns the KV stores of this runtime. The operations accept only these store names. */
293
+ function listKVDevStores() {
294
+ return resolvedStores(kvConfig);
295
+ }
296
+ function ttlNotice(driver, ttl) {
297
+ if (driver === "upstash" && Math.ceil(ttl) !== ttl) return `Upstash rounds the TTL up to ${Math.ceil(ttl)} seconds.`;
298
+ if (driver === "cloudflare") {
299
+ const effectiveTTL = Math.max(60, Math.ceil(ttl));
300
+ if (ttl < 60) return "Cloudflare KV raises a TTL below 60 seconds to 60 seconds.";
301
+ if (effectiveTTL !== ttl) return `Cloudflare KV rounds the TTL up to ${effectiveTTL} seconds.`;
302
+ }
303
+ }
304
+ function selectStore(stores, name = "default") {
305
+ if (stores.length === 0) throw kvErrorDiagnostics.KV_DISABLED();
306
+ const store = stores.find((entry) => entry.name === name);
307
+ if (!store) throw kvErrorDiagnostics.KV_STORE_NOT_FOUND({
308
+ store: name,
309
+ stores: stores.map((entry) => entry.name).join(", ")
310
+ });
311
+ return {
312
+ driver: store.driver,
313
+ name,
314
+ storage: name === "default" ? kv : kv.store(name)
315
+ };
316
+ }
317
+ /** The keys under `vitehub:` belong to ViteHub, which keeps its own state there. */
318
+ function requireWritableKey(operation, key) {
319
+ if (!normalizeKey(key).toLowerCase().startsWith("vitehub:")) return;
320
+ throw kvErrorDiagnostics.KV_RESERVED_KEY({
321
+ key,
322
+ operation
323
+ });
324
+ }
325
+ function requireKey(operation, input) {
326
+ if (input.key === void 0) throw kvErrorDiagnostics.KV_INVALID_INPUT({
327
+ operation,
328
+ problem: "key"
329
+ });
330
+ if (input.key.length > maximumKeyLength) throw kvErrorDiagnostics.KV_INVALID_INPUT({ problem: "key-length" });
331
+ return input.key;
332
+ }
333
+ /**
334
+ * Runs one `kv.*` operation against the KV stores of this runtime. The Nitro runtime owns the stores and their
335
+ * bindings, so this runs where the app does. There is no operation that clears a store.
336
+ */
337
+ async function runKVOperation(operation, input, stores = listKVDevStores()) {
338
+ try {
339
+ return await runOperation(operation, input, stores);
340
+ } catch (error) {
341
+ const code = Reflect.get(Object(error), "code");
342
+ const status = Reflect.get(Object(error), "status") ?? (typeof code === "string" ? kvOperationStatus[code] : void 0);
343
+ if (typeof status !== "number" || !(error instanceof Error)) throw error;
344
+ const cause = code === "KV_OPERATION_FAILED" && error.cause instanceof Error ? ` ${error.cause.message}` : "";
345
+ throw Object.assign(error, {
346
+ status,
347
+ statusMessage: redactInspectionText(`${error.message}${cause}`)
348
+ });
349
+ }
350
+ }
351
+ async function runOperation(operation, input, stores) {
352
+ const selected = selectStore(stores, input.store);
353
+ switch (operation) {
354
+ case "list": {
355
+ const limit = input.limit ?? 100;
356
+ if (limit > 1e3) throw kvErrorDiagnostics.KV_INVALID_INPUT({
357
+ limit: kvDevMaximumListLimit,
358
+ problem: "limit"
359
+ });
360
+ if ((input.prefix?.length ?? 0) > maximumKeyLength) throw kvErrorDiagnostics.KV_INVALID_INPUT({ problem: "prefix-length" });
361
+ const listOptions = {
362
+ limit,
363
+ prefix: input.prefix ?? ""
364
+ };
365
+ if (input.cursor) listOptions.cursor = input.cursor;
366
+ const page = unwrap(await selected.storage.list(listOptions));
367
+ const result = {
368
+ driver: selected.driver,
369
+ keys: page.keys,
370
+ limit,
371
+ prefix: input.prefix ?? "",
372
+ store: selected.name,
373
+ stores: stores.map((store) => store.name)
374
+ };
375
+ if (page.cursor) result.cursor = page.cursor;
376
+ return result;
377
+ }
378
+ case "get": {
379
+ const key = requireKey(operation, input);
380
+ const value = unwrap(await selected.storage.get(key));
381
+ const found = value !== null || unwrap(await selected.storage.has(key));
382
+ const result = {
383
+ found,
384
+ key,
385
+ store: selected.name
386
+ };
387
+ if (found) result.expiry = "unknown";
388
+ if (!found) return result;
389
+ if (input.preview) return {
390
+ ...result,
391
+ ...previewKVValue(value)
392
+ };
393
+ const inspected = inspectKVValue(value);
394
+ if (!inspected) throw kvErrorDiagnostics.KV_VALUE_UNSUPPORTED();
395
+ return {
396
+ ...result,
397
+ ...inspected
398
+ };
399
+ }
400
+ case "has": {
401
+ const key = requireKey(operation, input);
402
+ return {
403
+ exists: unwrap(await selected.storage.has(key)),
404
+ key,
405
+ store: selected.name
406
+ };
407
+ }
408
+ case "set": {
409
+ const key = requireKey(operation, input);
410
+ requireWritableKey(operation, key);
411
+ if (input.value === void 0) throw kvErrorDiagnostics.KV_INVALID_INPUT({ problem: "value" });
412
+ if (selected.driver === "upstash" && input.ttl !== void 0 && input.ttl < 1) throw kvErrorDiagnostics.KV_INVALID_INPUT({ problem: "ttl" });
413
+ const existed = unwrap(await selected.storage.has(key));
414
+ const ttl = input.ttl === void 0 ? void 0 : selected.driver === "cloudflare" ? Math.max(60, Math.ceil(input.ttl)) : selected.driver === "upstash" ? Math.ceil(input.ttl) : input.ttl;
415
+ unwrap(await selected.storage.set(key, input.value, ttl === void 0 ? void 0 : { ttl }));
416
+ const notice = input.ttl ? ttlNotice(selected.driver, input.ttl) : void 0;
417
+ const result = {
418
+ created: !existed,
419
+ key,
420
+ store: selected.name,
421
+ type: kvValueType(input.value)
422
+ };
423
+ if (notice) result.notice = notice;
424
+ if (ttl) result.ttl = ttl;
425
+ return result;
426
+ }
427
+ case "delete": {
428
+ const key = requireKey(operation, input);
429
+ requireWritableKey(operation, key);
430
+ const existed = unwrap(await selected.storage.has(key));
431
+ unwrap(await selected.storage.delete(key));
432
+ return {
433
+ deleted: existed,
434
+ key,
435
+ store: selected.name
436
+ };
437
+ }
438
+ }
439
+ }
440
+ //#endregion
441
+ export { listKVDevStores, runKVOperation };
@@ -0,0 +1,75 @@
1
+ import { s as KVDriver } from "./types-DEiKew_3.js";
2
+ import { t as AnyOperation } from "./operation-definition-8gOe-ubD.js";
3
+ //#region src/runtime/operations.d.ts
4
+ interface KVDevListResult {
5
+ /** Present when more keys exist. Pass it as `--cursor` to read the next page. */
6
+ cursor?: string;
7
+ /** The build-selected driver that this store uses. */
8
+ driver?: KVDriver;
9
+ keys: string[];
10
+ limit: number;
11
+ prefix: string;
12
+ store: string;
13
+ stores: string[];
14
+ }
15
+ interface KVDevGetResult {
16
+ /** With `preview`: whether text/JSON editing preserves the value. */
17
+ editable?: boolean;
18
+ /** `base64` when the stored value is binary. `value` is then the base64 text. */
19
+ encoding?: "base64";
20
+ found: boolean;
21
+ /** With `preview`: how `value` is written. */
22
+ format?: "json" | "text";
23
+ /**
24
+ * Whether the key can expire. `unknown`: the store can expire keys, but its driver cannot report the time left, so a
25
+ * write that sets no TTL removes the expiry.
26
+ */
27
+ expiry?: "unknown";
28
+ /** With `preview`: the value was cut at 256 KiB. */
29
+ truncated?: true;
30
+ key: string;
31
+ store: string;
32
+ /** JavaScript type of the stored value, for example `string`, `object`, `number`, or `bytes`. */
33
+ type?: string;
34
+ value?: unknown;
35
+ }
36
+ interface KVDevHasResult {
37
+ exists: boolean;
38
+ key: string;
39
+ store: string;
40
+ }
41
+ interface KVDevSetResult {
42
+ /** `true` when the key did not exist before the write. */
43
+ created: boolean;
44
+ key: string;
45
+ /** Limit of the provider that the write is subject to, for example a TTL that the driver ignores. */
46
+ notice?: string;
47
+ store: string;
48
+ /** Effective TTL in seconds passed to the driver. */
49
+ ttl?: number;
50
+ type: string;
51
+ }
52
+ interface KVDevDeleteResult {
53
+ /** `true` when the key was found before the delete. */
54
+ deleted: boolean;
55
+ key: string;
56
+ store: string;
57
+ }
58
+ //#endregion
59
+ //#region ../internal/src/operations-dev.d.ts
60
+ /**
61
+ * Bundled into owner packages and used only by their serve-only generated Nitro route. Operations get the Request as
62
+ * `context.event`, so owner hooks such as `identify` of Comments read its Standard Context.
63
+ */
64
+ export declare function createStandaloneOperationHandler(sources: {
65
+ operations: unknown;
66
+ plugin: string;
67
+ }[], root: string): {
68
+ fetch(request: Request): Promise<Response>;
69
+ };
70
+ //#endregion
71
+ //#region src/operations.d.ts
72
+ /** The `kv.*` operations: list, get, has, set, and delete. The Console, `vitehub kv`, and agents run them. */
73
+ export declare const kvOperations: readonly AnyOperation[];
74
+ //#endregion
75
+ export type { KVDevDeleteResult, KVDevGetResult, KVDevHasResult, KVDevListResult, KVDevSetResult };