@vite-hub/kv 0.1.0 → 0.4.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 (65) hide show
  1. package/README.md +94 -21
  2. package/dist/batch--v0ri69O.js +40 -0
  3. package/dist/cli-DpPhz_Ek.d.ts +163 -0
  4. package/dist/cli.d.ts +4 -2
  5. package/dist/cli.js +99 -77
  6. package/dist/cloudflare-env-lOtHHsgP.js +46 -0
  7. package/dist/cloudflare-env-lookup-Bs0VDpU5.js +42 -0
  8. package/dist/cloudflare-kv-C3NO4C21.js +201 -0
  9. package/dist/cloudflare-kv-local-C2sbIrFy.js +71 -0
  10. package/dist/config-LfpUj9hs.js +252 -0
  11. package/dist/{create-storage-29gMzf41.js → create-storage-BORQm2a8.js} +206 -50
  12. package/dist/{cursor-history-dqYDlsaD.js → cursor-history-DRHh5bO5.js} +31 -14
  13. package/dist/database-oJdy0ZVX.js +250 -0
  14. package/dist/{deno-kv-CSYGvRx4.js → deno-kv-D_VtffFv.js} +12 -4
  15. package/dist/dev-peer-CHafxbtj.js +238 -0
  16. package/dist/driver-R4Z5Z5fl.d.ts +15 -0
  17. package/dist/durability.d.ts +17 -0
  18. package/dist/durability.js +53 -0
  19. package/dist/error-diagnostics-C54QQEhN.js +155 -0
  20. package/dist/errors-DzD6YNEH.js +88 -0
  21. package/dist/errors.d.ts +17 -1
  22. package/dist/errors.js +2 -2
  23. package/dist/fs-lite-BAgpmNAF.js +2 -0
  24. package/dist/fs-lite-BaklCLuV.js +386 -0
  25. package/dist/index.d.ts +7 -2
  26. package/dist/index.js +326 -84
  27. package/dist/inspect-BIKQsqX4.js +118 -0
  28. package/dist/invariant-DolT9EEx.js +22 -0
  29. package/dist/object-Da1zyPCR.js +11 -0
  30. package/dist/{operations-tNUdj3G4.d.ts → operation-definition-nmRu_O3V.d.ts} +42 -15
  31. package/dist/{operations-pn8_eGob.js → operations-CtrWLmPK.js} +69 -66
  32. package/dist/operations-D2iI9oN4.js +1363 -0
  33. package/dist/operations.d.ts +15 -8
  34. package/dist/operations.js +56 -192
  35. package/dist/redis-shared-5ogRd3-Y.js +94 -0
  36. package/dist/runtime/cloudflare-kv.d.ts +1 -1
  37. package/dist/runtime/cloudflare-kv.js +1 -99
  38. package/dist/runtime/cloudflare-request-env.d.ts +7 -0
  39. package/dist/runtime/cloudflare-request-env.js +11 -0
  40. package/dist/runtime/nitro-plugin.d.ts +12 -0
  41. package/dist/runtime/nitro-plugin.js +25 -0
  42. package/dist/runtime/redis-driver.d.ts +11 -0
  43. package/dist/runtime/redis-driver.js +113 -0
  44. package/dist/runtime/unstorage-driver.d.ts +14 -0
  45. package/dist/runtime/unstorage-driver.js +37 -0
  46. package/dist/runtime/upstash-driver.d.ts +2 -2
  47. package/dist/runtime/upstash-driver.js +58 -98
  48. package/dist/{driver-D9fI27jl.d.ts → types-Bj3EQoRg.d.ts} +16 -41
  49. package/dist/types-Dv-OSXZC.d.ts +325 -0
  50. package/dist/upstash-B-vaUYqO.js +40 -0
  51. package/dist/{utils2-Dsb9P4_2.js → utils2-FozcTsmb.js} +5 -2
  52. package/dist/virtual-module.d.ts +3 -0
  53. package/dist/vite.d.ts +167 -14
  54. package/dist/vite.js +1195 -2876
  55. package/package.json +30 -21
  56. package/dist/cli-Cniq99iX.d.ts +0 -85
  57. package/dist/cloudflare-env-C5rM7kUY.js +0 -74
  58. package/dist/config-DR6_5ZwI.js +0 -124
  59. package/dist/continuations-DPyH_vr1.js +0 -63
  60. package/dist/error-diagnostics-D_cQeZTi.js +0 -82
  61. package/dist/errors-Dc2oiW-Y.js +0 -38
  62. package/dist/fs-lite-CbLKxLut.js +0 -90
  63. package/dist/object-B1NW521B.js +0 -7
  64. package/dist/operations-ByuDE12r.js +0 -1442
  65. package/dist/types-CMDvN0Wr.d.ts +0 -81
@@ -0,0 +1,113 @@
1
+ import { t as invariant } from "../invariant-DolT9EEx.js";
2
+ import { n as kvErrorDiagnostics } from "../error-diagnostics-C54QQEhN.js";
3
+ import { o as normalizeKey } from "../utils2-FozcTsmb.js";
4
+ import { t as chunks } from "../batch--v0ri69O.js";
5
+ import { a as redisIncrementScript, i as redisIncrementResult, n as escapeRedisGlob, o as redisTTLSeconds, r as redisDeleteIfEqualsScript, t as createPortableRedisKeyLister } from "../redis-shared-5ogRd3-Y.js";
6
+ import { Redis } from "ioredis";
7
+ //#region src/runtime/redis-driver.ts
8
+ /** The URL of a store: `env:<NAME>` reads the variable now, so a build never holds the URL of its server. */
9
+ function resolveRedisUrl(url, env = globalThis.process?.env ?? {}) {
10
+ if (!url.startsWith("env:")) return url;
11
+ const name = url.slice(4);
12
+ const value = env[name]?.trim();
13
+ if (!value) throw kvErrorDiagnostics.KV_MISSING_ENV({
14
+ driver: "redis",
15
+ names: `\`${name}\``
16
+ });
17
+ return value;
18
+ }
19
+ /** Milliseconds for `SET PX`, which keeps fractional TTLs, as the other drivers do. */
20
+ function ttlMilliseconds(ttl) {
21
+ redisTTLSeconds(ttl);
22
+ return Math.ceil(ttl * 1e3);
23
+ }
24
+ /** The `PX` milliseconds of a write. Like other unstorage drivers, no TTL or 0 keeps the key. */
25
+ function writeTTL(options) {
26
+ const ttl = options?.ttl;
27
+ if (ttl === void 0 || ttl === null || ttl === 0) return;
28
+ if (typeof ttl === "number") return ttlMilliseconds(ttl);
29
+ throw kvErrorDiagnostics.KV_INVALID_TTL();
30
+ }
31
+ /** Keys per `MGET`, so one reply stays a moderate size. */
32
+ const mgetBatchSize = 1e3;
33
+ /**
34
+ * KV over a Redis server through TCP, with `ioredis`. Each atomic operation is one command or one script. This module
35
+ * loads only for a Redis store, so other stores do not load `ioredis`.
36
+ */
37
+ function createRedisKVDriver(options) {
38
+ const base = normalizeKey(options.base);
39
+ invariant(base, "resolveRedisStore() gives a Redis KV store a non-empty `base`, which keeps clear() inside the store");
40
+ const client = new Redis(resolveRedisUrl(options.url), {
41
+ lazyConnect: true,
42
+ maxRetriesPerRequest: 3
43
+ });
44
+ const prefixed = (key) => `${base}:${key}`;
45
+ const unprefixed = (key) => key.startsWith(`${base}:`) ? key.slice(base.length + 1) : key;
46
+ const pattern = (match) => `${escapeRedisGlob(base)}:${match}`;
47
+ async function scanAll(prefix) {
48
+ const keys = [];
49
+ let cursor = "0";
50
+ do {
51
+ const [next, page] = await client.scan(cursor, "MATCH", pattern(`${escapeRedisGlob(prefix ?? "")}*`), "COUNT", 1e3);
52
+ cursor = next;
53
+ for (const key of page) keys.push(key);
54
+ } while (cursor !== "0");
55
+ return keys;
56
+ }
57
+ return {
58
+ name: "vitehub-kv-redis",
59
+ options,
60
+ hasItem: async (key) => await client.exists(prefixed(key)) > 0,
61
+ getItem: async (key) => await client.get(prefixed(key)),
62
+ async getItems(items) {
63
+ const values = [];
64
+ for (const batch of chunks(items, mgetBatchSize)) values.push(...await client.mget(...batch.map((item) => prefixed(item.key))));
65
+ return items.map((item, index) => ({
66
+ key: item.key,
67
+ value: values[index] ?? null
68
+ }));
69
+ },
70
+ async setItem(key, value, setOptions) {
71
+ const ttl = writeTTL(setOptions);
72
+ if (ttl === void 0) await client.set(prefixed(key), value);
73
+ else await client.set(prefixed(key), value, "PX", ttl);
74
+ },
75
+ async setItems(items, setOptions) {
76
+ const pipeline = client.pipeline();
77
+ for (const item of items) {
78
+ const ttl = writeTTL({
79
+ ...setOptions,
80
+ ...item.options
81
+ });
82
+ if (ttl === void 0) pipeline.set(prefixed(item.key), item.value);
83
+ else pipeline.set(prefixed(item.key), item.value, "PX", ttl);
84
+ }
85
+ for (const [error] of await pipeline.exec() ?? []) if (error) throw error;
86
+ },
87
+ async removeItem(key) {
88
+ await client.unlink(prefixed(key));
89
+ },
90
+ getKeys: async (base) => (await scanAll(base)).map(unprefixed),
91
+ async clear(base) {
92
+ const keys = await scanAll(base);
93
+ for (let offset = 0; offset < keys.length; offset += 1e3) await client.unlink(...keys.slice(offset, offset + 1e3));
94
+ },
95
+ async setIfAbsentItem(key, value, ttl) {
96
+ return (ttl === void 0 ? await client.set(prefixed(key), value, "NX") : await client.set(prefixed(key), value, "PX", ttlMilliseconds(ttl), "NX")) === "OK";
97
+ },
98
+ async getAndDeleteItem(key) {
99
+ return await client.getdel(prefixed(key));
100
+ },
101
+ incrementItem: async (key, ttl) => redisIncrementResult(await client.eval(redisIncrementScript, 1, prefixed(key), redisTTLSeconds(ttl))),
102
+ deleteIfEqualsItem: async (key, expected) => Number(await client.eval(redisDeleteIfEqualsScript, 1, prefixed(key), expected)) === 1,
103
+ listKeys: createPortableRedisKeyLister("Redis KV", async (cursor, match, count) => {
104
+ const [next, keys] = await client.scan(cursor, "MATCH", pattern(match), "COUNT", count);
105
+ return [next, keys.map(unprefixed)];
106
+ }),
107
+ async dispose() {
108
+ client.disconnect();
109
+ }
110
+ };
111
+ }
112
+ //#endregion
113
+ export { createRedisKVDriver as default, resolveRedisUrl };
@@ -0,0 +1,14 @@
1
+ import { t as Driver } from "../types-Bj3EQoRg.js";
2
+ //#region src/runtime/unstorage-driver.d.ts
3
+ export interface KVStorageDriverOptions {
4
+ /** The named KV store. Default: the default store. */
5
+ store?: string;
6
+ /** Key prefix inside the store, so the mount's keys stay apart from the app's other keys. Default: no prefix. */
7
+ base?: string;
8
+ }
9
+ /**
10
+ * Unstorage driver over one KV store, for Nitro storage mounts such as `kv` and `cache`.
11
+ * It resolves the store on each call, so a Cloudflare store uses the binding of the current request.
12
+ */
13
+ export default function createKVStorageDriver(options?: KVStorageDriverOptions): Driver<KVStorageDriverOptions>;
14
+ //#endregion
@@ -0,0 +1,37 @@
1
+ import { o as normalizeKey } from "../utils2-FozcTsmb.js";
2
+ import { kv } from "@vite-hub/kv";
3
+ //#region src/runtime/unstorage-driver.ts
4
+ async function unwrap(pending) {
5
+ const [error, value] = await pending;
6
+ if (error) throw error;
7
+ return value;
8
+ }
9
+ /**
10
+ * Unstorage driver over one KV store, for Nitro storage mounts such as `kv` and `cache`.
11
+ * It resolves the store on each call, so a Cloudflare store uses the binding of the current request.
12
+ */
13
+ function createKVStorageDriver(options = {}) {
14
+ const base = normalizeKey(options.base);
15
+ const prefix = base ? `${base}:` : "";
16
+ const key = (name) => prefix + normalizeKey(name);
17
+ const below = (name) => {
18
+ const value = key(name);
19
+ return value && !value.endsWith(":") ? `${value}:` : value;
20
+ };
21
+ const store = () => options.store === void 0 ? kv : kv.store(options.store);
22
+ return {
23
+ name: "vitehub-kv",
24
+ options,
25
+ hasItem: (name) => unwrap(store().has(key(name))),
26
+ getItem: (name) => unwrap(store().get(key(name), { type: "text" })),
27
+ getItemRaw: (name) => unwrap(store().get(key(name), { type: "bytes" })),
28
+ setItem: (name, value, opts) => unwrap(store().set(key(name), value, typeof opts?.ttl === "number" ? { ttl: opts.ttl } : void 0)),
29
+ removeItem: (name) => unwrap(store().delete(key(name))),
30
+ async getKeys(keyBase) {
31
+ return (await unwrap(store().list({ prefix: below(keyBase) }))).keys.map((name) => name.slice(prefix.length));
32
+ },
33
+ clear: (keyBase) => unwrap(store().clear({ prefix: below(keyBase) }))
34
+ };
35
+ }
36
+ //#endregion
37
+ export { createKVStorageDriver as default };
@@ -1,5 +1,5 @@
1
- import { _ as ResolvedUpstashKVStoreConfig } from "../types-CMDvN0Wr.js";
2
- import { t as KVRuntimeDriver } from "../driver-D9fI27jl.js";
1
+ import { B as ResolvedUpstashKVStoreConfig } from "../types-Dv-OSXZC.js";
2
+ import { t as KVRuntimeDriver } from "../driver-R4Z5Z5fl.js";
3
3
  //#region src/runtime/upstash-driver.d.ts
4
4
  export default function createUpstashKVDriver(options: ResolvedUpstashKVStoreConfig): KVRuntimeDriver;
5
5
  //#endregion
@@ -1,109 +1,69 @@
1
- import { n as kvErrorDiagnostics } from "../error-diagnostics-D_cQeZTi.js";
2
- import { t as createKVContinuations } from "../continuations-DPyH_vr1.js";
1
+ import { t as invariant } from "../invariant-DolT9EEx.js";
2
+ import { n as kvErrorDiagnostics } from "../error-diagnostics-C54QQEhN.js";
3
+ import { o as normalizeKey } from "../utils2-FozcTsmb.js";
4
+ import { t as chunks } from "../batch--v0ri69O.js";
5
+ import { a as redisIncrementScript, i as redisIncrementResult, n as escapeRedisGlob, o as redisTTLSeconds, r as redisDeleteIfEqualsScript, t as createPortableRedisKeyLister } from "../redis-shared-5ogRd3-Y.js";
3
6
  import createDriver from "unstorage/drivers/upstash";
4
7
  //#region src/runtime/upstash-driver.ts
5
- const incrementScript = `
6
- local existed = redis.call('EXISTS', KEYS[1])
7
- local current = redis.call('GET', KEYS[1])
8
- if current then
9
- local negative = string.sub(current, 1, 1) == '-'
10
- local digits = negative and string.sub(current, 2) or current
11
- local boundary = negative and '9007199254740992' or '9007199254740991'
12
- local beyond = #digits > #boundary or (#digits == #boundary and digits > boundary)
13
- local at_positive_boundary = not negative and digits == boundary
14
- if beyond or at_positive_boundary then
15
- return redis.error_reply('Atomic KV increment exceeds the JavaScript safe integer range.')
16
- end
17
- end
18
- local value = redis.call('INCR', KEYS[1])
19
- if existed == 0 then
20
- redis.call('EXPIRE', KEYS[1], ARGV[1])
21
- end
22
- return value
23
- `;
24
- function normalizeTTL(ttl) {
25
- if (!Number.isFinite(ttl) || ttl <= 0) throw kvErrorDiagnostics.KV_INVALID_TTL();
26
- const seconds = Math.ceil(ttl);
27
- if (!Number.isSafeInteger(seconds)) throw kvErrorDiagnostics.KV_INVALID_TTL();
28
- return seconds;
29
- }
30
- function decodeCursor(cursor) {
31
- if (!cursor) return { cursor: "0" };
32
- try {
33
- const value = JSON.parse(decodeURIComponent(cursor));
34
- if (typeof value.cursor !== "string" || value.cursor.length === 0) throw kvErrorDiagnostics.KV_INVALID_CURSOR({ problem: "invalid" });
35
- return value;
36
- } catch {
37
- throw kvErrorDiagnostics.KV_INVALID_CURSOR({ problem: "invalid" });
38
- }
39
- }
40
- function encodeCursor(cursor) {
41
- return encodeURIComponent(JSON.stringify(cursor));
42
- }
43
- function escapeRedisGlob(value) {
44
- return value.replaceAll(/([*?[\\\]])/g, "\\$1");
45
- }
8
+ const keyBatchSize = 1e3;
46
9
  function createUpstashKVDriver(options) {
47
- const driver = createDriver(options);
48
- const maximumContinuationBytes = 1048576;
49
- const expired = () => kvErrorDiagnostics.KV_INVALID_CURSOR({ problem: "expired" });
50
- const continuations = createKVContinuations({
51
- expired,
52
- maximumBytes: maximumContinuationBytes
10
+ const base = normalizeKey(options.base);
11
+ invariant(base, "resolveUpstashStore() gives an Upstash KV store a non-empty `base`, which keeps clear() inside the store");
12
+ const driver = createDriver({
13
+ lib: () => import("@upstash/redis"),
14
+ ...options,
15
+ base,
16
+ automaticDeserialization: false
53
17
  });
54
- const dispose = driver.dispose;
55
- driver.dispose = async () => {
56
- try {
57
- await continuations.dispose();
58
- } finally {
59
- await dispose?.call(driver);
60
- }
18
+ const client = () => driver.getInstance();
19
+ const prefixed = (key) => `${base}:${key}`;
20
+ const unprefixed = (key) => key.startsWith(`${base}:`) ? key.slice(base.length + 1) : key;
21
+ driver.setItem = async (key, value, setOptions) => {
22
+ const ttl = setOptions?.ttl;
23
+ if (ttl !== void 0 && ttl !== null && ttl !== 0 && typeof ttl !== "number") throw kvErrorDiagnostics.KV_INVALID_TTL();
24
+ await (await client()).set(prefixed(key), value, typeof ttl === "number" && ttl !== 0 ? { ex: redisTTLSeconds(ttl) } : void 0);
61
25
  };
62
- driver.getAndDeleteItem = async (key) => (await driver.getInstance()).getdel(key);
63
- driver.incrementItem = async (key, ttl) => {
64
- const value = Number(await (await driver.getInstance()).eval(incrementScript, [key], [String(normalizeTTL(ttl))]));
65
- if (!Number.isSafeInteger(value)) throw kvErrorDiagnostics.KV_PROVIDER_INVALID_RESPONSE({ problem: "The counter exceeds the JavaScript safe integer range." });
66
- return value;
26
+ driver.getItems = async (items) => {
27
+ const values = [];
28
+ for (const batch of chunks(items, keyBatchSize)) values.push(...await (await client()).mget(...batch.map((item) => prefixed(item.key))));
29
+ return items.map((item, index) => ({
30
+ key: item.key,
31
+ value: values[index] ?? null
32
+ }));
67
33
  };
68
- function retainContinuation(keys, providerCursor) {
69
- const encoder = new TextEncoder();
70
- const bytes = keys.reduce((total, key) => total + encoder.encode(key).byteLength, 0);
71
- if (bytes > maximumContinuationBytes) throw kvErrorDiagnostics.KV_PROVIDER_INVALID_RESPONSE({ problem: "Upstash KV scan overflow exceeds the continuation size limit." });
72
- return continuations.retain({
73
- cursor: providerCursor,
74
- keys
75
- }, bytes);
76
- }
77
- driver.listKeys = async ({ cursor, limit, prefix = "" }) => {
78
- const retained = cursor ? continuations.take(cursor) : void 0;
79
- if (cursor && !retained && /^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/i.test(cursor)) throw expired();
80
- let providerCursor;
81
- let keys;
82
- if (retained) {
83
- providerCursor = retained.cursor;
84
- keys = retained.keys;
85
- } else {
86
- const state = decodeCursor(cursor);
87
- providerCursor = state.cursor;
88
- const scanned = await (await driver.getInstance()).scan(providerCursor, {
89
- count: limit,
90
- match: `${escapeRedisGlob(prefix)}*`
34
+ driver.clear = async (prefix) => {
35
+ const keys = [];
36
+ let cursor = "0";
37
+ do {
38
+ const [next, page] = await (await client()).scan(cursor, {
39
+ count: keyBatchSize,
40
+ match: `${escapeRedisGlob(prefixed(prefix ?? ""))}*`
91
41
  });
92
- providerCursor = String(scanned[0]);
93
- if (providerCursor === state.cursor && providerCursor !== "0") throw kvErrorDiagnostics.KV_PROVIDER_INVALID_RESPONSE({ problem: "Upstash KV scan returned a repeated pagination cursor." });
94
- keys = [...new Set(scanned[1])];
95
- }
96
- const pageKeys = keys.slice(0, limit);
97
- const overflow = keys.slice(limit);
98
- if (overflow.length > 0) return {
99
- keys: pageKeys,
100
- cursor: await retainContinuation(overflow, providerCursor)
101
- };
102
- if (providerCursor === "0") return { keys: pageKeys };
103
- return {
104
- keys: pageKeys,
105
- cursor: encodeCursor({ cursor: providerCursor })
42
+ cursor = String(next);
43
+ keys.push(...page);
44
+ } while (cursor !== "0");
45
+ for (const batch of chunks(keys, keyBatchSize)) await (await client()).del(...batch);
46
+ };
47
+ driver.getAndDeleteItem = async (key) => (await client()).getdel(prefixed(key));
48
+ driver.incrementItem = async (key, ttl) => redisIncrementResult(await (await client()).eval(redisIncrementScript, [prefixed(key)], [String(redisTTLSeconds(ttl))]));
49
+ driver.deleteIfEqualsItem = async (key, expected) => Number(await (await client()).eval(redisDeleteIfEqualsScript, [prefixed(key)], [expected])) === 1;
50
+ driver.setIfAbsentItem = async (key, value, ttl) => {
51
+ const setOptions = ttl === void 0 ? { nx: true } : {
52
+ ex: redisTTLSeconds(ttl),
53
+ nx: true
106
54
  };
55
+ return await (await client()).set(prefixed(key), value, setOptions) === "OK";
56
+ };
57
+ driver.listKeys = createPortableRedisKeyLister("Upstash KV", async (cursor, match, count) => {
58
+ const [next, keys] = await (await client()).scan(cursor, {
59
+ count,
60
+ match: `${escapeRedisGlob(base)}:${match}`
61
+ });
62
+ return [String(next), keys.map(unprefixed)];
63
+ });
64
+ const dispose = driver.dispose;
65
+ driver.dispose = async () => {
66
+ await dispose?.call(driver);
107
67
  };
108
68
  return driver;
109
69
  }
@@ -1,40 +1,22 @@
1
- import { o as KVListOptions, s as KVListPage } from "./types-CMDvN0Wr.js";
2
- import "unstorage/drivers/cloudflare-kv-binding";
3
- import "unstorage/drivers/upstash";
4
- import "unstorage/drivers/fs-lite";
5
- import "unstorage/drivers/azure-app-configuration";
6
- import "unstorage/drivers/azure-cosmos";
7
- import "unstorage/drivers/azure-key-vault";
8
- import "unstorage/drivers/azure-storage-blob";
9
- import "unstorage/drivers/azure-storage-table";
10
- import "unstorage/drivers/capacitor-preferences";
11
- import "unstorage/drivers/cloudflare-cache-binding";
12
- import "unstorage/drivers/cloudflare-kv-http";
13
- import "unstorage/drivers/cloudflare-r2-binding";
14
- import "unstorage/drivers/db0";
15
- import "unstorage/drivers/deno-kv-node";
16
- import "unstorage/drivers/deno-kv";
17
- import "unstorage/drivers/fs";
18
- import "unstorage/drivers/github";
19
- import "unstorage/drivers/http";
20
- import "unstorage/drivers/indexedb";
21
- import "unstorage/drivers/localstorage";
22
- import "unstorage/drivers/lru-cache";
23
- import "unstorage/drivers/mongodb";
24
- import "unstorage/drivers/netlify-blobs";
25
- import "unstorage/drivers/overlay";
26
- import "unstorage/drivers/planetscale";
27
- import "unstorage/drivers/redis";
28
- import "unstorage/drivers/s3";
29
- import "unstorage/drivers/session-storage";
30
- import "unstorage/drivers/uploadthing";
31
- import "unstorage/drivers/vercel-blob";
32
- import "unstorage/drivers/vercel-runtime-cache";
33
- //#region ../../node_modules/.pnpm/unstorage@2.0.0-alpha.10/node_modules/unstorage/dist/_chunks/types.d.mts
1
+ //#region ../../node_modules/.pnpm/unstorage@2.0.0-beta.0/node_modules/unstorage/dist/_chunks/types.d.mts
34
2
  type StorageValue = null | string | number | boolean | object;
35
3
  type WatchEvent = "update" | "remove";
36
4
  type WatchCallback = (event: WatchEvent, key: string) => any;
37
5
  type MaybePromise<T> = T | Promise<T>;
6
+ /** Types that {@link Storage.getItem} can convert the stored value to. */
7
+ type GetItemType = keyof GetItemTypeMap;
8
+ interface GetItemTypeMap {
9
+ text: string;
10
+ json: JSONValue;
11
+ bytes: Uint8Array;
12
+ stream: ReadableStream<Uint8Array>;
13
+ blob: Blob;
14
+ }
15
+ type JSONValue = string | number | boolean | null | JSONObject | JSONArray;
16
+ interface JSONObject {
17
+ [key: string]: JSONValue;
18
+ }
19
+ type JSONArray = JSONValue[];
38
20
  type Unwatch = () => MaybePromise<void>;
39
21
  interface StorageMeta {
40
22
  atime?: Date;
@@ -84,11 +66,4 @@ interface Driver<OptionsT = any, InstanceT = any> {
84
66
  watch?: (callback: WatchCallback) => MaybePromise<Unwatch>;
85
67
  }
86
68
  //#endregion
87
- //#region src/runtime/driver.d.ts
88
- type KVRuntimeDriver = Driver & Record<string, unknown> & {
89
- getAndDeleteItem?: <T = unknown>(key: string) => Promise<T | null>;
90
- incrementItem?: (key: string, ttl: number) => Promise<number>;
91
- listKeys: (options: KVListOptions) => Promise<KVListPage>;
92
- };
93
- //#endregion
94
- export { KVRuntimeDriver as t };
69
+ export { TransactionOptions as i, GetItemType as n, GetItemTypeMap as r, Driver as t };