@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.
- package/README.md +110 -14
- package/dist/batch--v0ri69O.js +40 -0
- package/dist/cli-DpPhz_Ek.d.ts +163 -0
- package/dist/cli.d.ts +17 -0
- package/dist/cli.js +469 -0
- package/dist/cloudflare-env-lOtHHsgP.js +46 -0
- package/dist/cloudflare-env-lookup-Bs0VDpU5.js +42 -0
- package/dist/cloudflare-kv-BIEUFzRT.js +187 -0
- package/dist/cloudflare-kv-local-BBw3ZT1K.js +71 -0
- package/dist/config-BXEVoZE3.js +250 -0
- package/dist/{dist-DDW1iC5f.js → create-storage-BGsrQKw3.js} +266 -115
- package/dist/cursor-history-BqIQePNP.js +165 -0
- package/dist/database-72Jk3VVk.js +250 -0
- package/dist/deno-kv-BM9mYdUp.js +128 -0
- package/dist/dev-peer-CHafxbtj.js +238 -0
- package/dist/driver-BwxgaQ-f.d.ts +15 -0
- package/dist/durability.d.ts +17 -0
- package/dist/durability.js +53 -0
- package/dist/error-diagnostics-BxqvtEIb.js +147 -0
- package/dist/errors-DbwufFZp.js +60 -0
- package/dist/errors.d.ts +23 -7
- package/dist/errors.js +2 -20
- package/dist/fs-lite-BLZId9_P.js +386 -0
- package/dist/fs-lite-RAoxu8L0.js +2 -0
- package/dist/index.d.ts +10 -4
- package/dist/index.js +364 -109
- package/dist/inspect-BIKQsqX4.js +118 -0
- package/dist/invariant-DolT9EEx.js +22 -0
- package/dist/main-F3Y22_uV.js +2353 -0
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
- package/dist/operations-B-WZ7P1h.js +1351 -0
- package/dist/operations-Ch-gKaey.js +441 -0
- package/dist/operations.d.ts +75 -0
- package/dist/operations.js +318 -0
- package/dist/redis-shared-E5mahECF.js +94 -0
- package/dist/results-p7nPCnaJ.js +6 -0
- package/dist/rolldown-runtime-CMFfr-1z.js +26 -0
- package/dist/runtime/cloudflare-kv.d.ts +3 -4
- package/dist/runtime/cloudflare-kv.js +1 -23
- package/dist/runtime/cloudflare-request-env.d.ts +7 -0
- package/dist/runtime/cloudflare-request-env.js +11 -0
- package/dist/runtime/nitro-plugin.d.ts +12 -0
- package/dist/runtime/nitro-plugin.js +22 -0
- package/dist/runtime/redis-driver.d.ts +11 -0
- package/dist/runtime/redis-driver.js +113 -0
- package/dist/runtime/unstorage-driver.d.ts +14 -0
- package/dist/runtime/unstorage-driver.js +33 -0
- package/dist/runtime/upstash-driver.d.ts +4 -6
- package/dist/runtime/upstash-driver.js +60 -110
- package/dist/{driver-BT9WefKi.d.ts → types-Bj3EQoRg.d.ts} +16 -11
- package/dist/types-DEiKew_3.d.ts +312 -0
- package/dist/upstash-DDlqTttY.js +40 -0
- package/dist/utils2-FozcTsmb.js +31 -0
- package/dist/virtual-module.d.ts +2 -0
- package/dist/virtual.d.ts +1 -1
- package/dist/vite.d.ts +159 -14
- package/dist/vite.js +1329 -2898
- package/package.json +68 -19
- package/dist/config-aM9Ae7tH.js +0 -110
- package/dist/deno-kv-cJx3jU10.js +0 -69
- package/dist/fs-lite-BxzdiJSi.js +0 -79
- package/dist/types-CO0DRjJa.d.ts +0 -78
package/package.json
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/kv",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Vite-first key-value storage primitives and integration for ViteHub.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
7
|
+
"key-value",
|
|
7
8
|
"kv",
|
|
9
|
+
"postgres",
|
|
10
|
+
"redis",
|
|
11
|
+
"typescript",
|
|
12
|
+
"upstash",
|
|
8
13
|
"vercel",
|
|
9
14
|
"vite",
|
|
10
15
|
"vitehub"
|
|
11
16
|
],
|
|
12
|
-
"homepage": "https://
|
|
17
|
+
"homepage": "https://vitehub.dev",
|
|
13
18
|
"bugs": "https://github.com/vite-hub/vitehub/issues",
|
|
14
19
|
"license": "Apache-2.0",
|
|
15
20
|
"author": "onmax <maximogarciamtnez@gmail.com>",
|
|
@@ -26,48 +31,92 @@
|
|
|
26
31
|
"sideEffects": false,
|
|
27
32
|
"types": "./dist/index.d.ts",
|
|
28
33
|
"exports": {
|
|
29
|
-
".":
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"./
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"import": "./dist/index.js",
|
|
37
|
+
"default": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./cli": {
|
|
40
|
+
"types": "./dist/cli.d.ts",
|
|
41
|
+
"import": "./dist/cli.js",
|
|
42
|
+
"default": "./dist/cli.js"
|
|
43
|
+
},
|
|
44
|
+
"./durability": {
|
|
45
|
+
"types": "./dist/durability.d.ts",
|
|
46
|
+
"import": "./dist/durability.js",
|
|
47
|
+
"default": "./dist/durability.js"
|
|
48
|
+
},
|
|
49
|
+
"./runtime/redis-driver": {
|
|
50
|
+
"types": "./dist/runtime/redis-driver.d.ts",
|
|
51
|
+
"import": "./dist/runtime/redis-driver.js",
|
|
52
|
+
"default": "./dist/runtime/redis-driver.js"
|
|
53
|
+
},
|
|
54
|
+
"./runtime/upstash-driver": {
|
|
55
|
+
"types": "./dist/runtime/upstash-driver.d.ts",
|
|
56
|
+
"import": "./dist/runtime/upstash-driver.js",
|
|
57
|
+
"default": "./dist/runtime/upstash-driver.js"
|
|
58
|
+
},
|
|
59
|
+
"./virtual": {
|
|
60
|
+
"types": "./dist/virtual.d.ts",
|
|
61
|
+
"import": "./dist/virtual.js",
|
|
62
|
+
"default": "./dist/virtual.js"
|
|
63
|
+
},
|
|
64
|
+
"./vite": {
|
|
65
|
+
"types": "./dist/vite.d.ts",
|
|
66
|
+
"import": "./dist/vite.js",
|
|
67
|
+
"default": "./dist/vite.js"
|
|
68
|
+
},
|
|
35
69
|
"./package.json": "./package.json"
|
|
36
70
|
},
|
|
37
71
|
"dependencies": {
|
|
38
|
-
"@
|
|
72
|
+
"@valibot/to-json-schema": "^1.8.0",
|
|
73
|
+
"@vite-hub/runtime": "0.3.1",
|
|
74
|
+
"birpc": "^4.2.0",
|
|
39
75
|
"defu": "^6.1.7",
|
|
40
76
|
"destr": "^2.0.5",
|
|
41
|
-
"
|
|
77
|
+
"ioredis": "^5.11.1",
|
|
78
|
+
"nostics": "1.4.0",
|
|
79
|
+
"proper-lockfile": "4.1.2",
|
|
80
|
+
"unstorage": "2.0.0-beta.0",
|
|
81
|
+
"valibot": "^1.5.0"
|
|
42
82
|
},
|
|
43
83
|
"devDependencies": {
|
|
84
|
+
"@types/node": "^24.19.1",
|
|
85
|
+
"@libsql/client": "^0.18.0",
|
|
86
|
+
"@vite-hub/database": "0.3.1",
|
|
87
|
+
"@types/proper-lockfile": "4.1.4",
|
|
88
|
+
"@vite-hub/internal": "0.0.1",
|
|
44
89
|
"ofetch": "^1.5.1",
|
|
45
|
-
"
|
|
90
|
+
"postgres": "^3.4.9",
|
|
91
|
+
"publint": "^0.3.25",
|
|
46
92
|
"typescript": "^6.0.3",
|
|
47
|
-
"vite": "^8.
|
|
48
|
-
"vite-plus": "^0.
|
|
49
|
-
"vitest": "^4.1.
|
|
50
|
-
"@vite-hub/internal": "0.0.1"
|
|
93
|
+
"vite": "^8.2.2",
|
|
94
|
+
"vite-plus": "^0.3.3",
|
|
95
|
+
"vitest": "^4.1.11"
|
|
51
96
|
},
|
|
52
97
|
"peerDependencies": {
|
|
53
|
-
"@upstash/redis": "^1.
|
|
98
|
+
"@upstash/redis": "^1.39.0",
|
|
99
|
+
"@vite-hub/database": "0.3.1",
|
|
54
100
|
"vite": ">=8.0.0"
|
|
55
101
|
},
|
|
56
102
|
"peerDependenciesMeta": {
|
|
57
103
|
"@upstash/redis": {
|
|
58
104
|
"optional": true
|
|
59
105
|
},
|
|
106
|
+
"@vite-hub/database": {
|
|
107
|
+
"optional": true
|
|
108
|
+
},
|
|
60
109
|
"vite": {
|
|
61
110
|
"optional": true
|
|
62
111
|
}
|
|
63
112
|
},
|
|
64
113
|
"engines": {
|
|
65
|
-
"node": ">=
|
|
114
|
+
"node": ">=22.18.0"
|
|
66
115
|
},
|
|
67
116
|
"scripts": {
|
|
68
117
|
"build": "vp pack",
|
|
69
118
|
"dev": "vp pack --watch",
|
|
70
|
-
"typecheck": "
|
|
71
|
-
"test": "vp run -t @vite-hub/kv#build && vp test"
|
|
119
|
+
"typecheck": "vp run --cache -t @vite-hub/kv#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
|
|
120
|
+
"test": "vp run --cache -t @vite-hub/kv#build && vp test"
|
|
72
121
|
}
|
|
73
122
|
}
|
package/dist/config-aM9Ae7tH.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { defu } from "defu";
|
|
2
|
-
//#region ../internal/src/env.ts
|
|
3
|
-
function trimmed(value) {
|
|
4
|
-
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
5
|
-
}
|
|
6
|
-
function readEnv(env, ...names) {
|
|
7
|
-
for (const name of names) {
|
|
8
|
-
const value = trimmed(env[name]);
|
|
9
|
-
if (value) return value;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region ../internal/src/hosting.ts
|
|
14
|
-
function normalizeHosting(hosting) {
|
|
15
|
-
const normalized = hosting?.trim().toLowerCase().replaceAll("_", "-") || "";
|
|
16
|
-
if (normalized === "cloudflare") return "cloudflare-module";
|
|
17
|
-
return normalized;
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region ../internal/src/object.ts
|
|
21
|
-
function isPlainObject(value) {
|
|
22
|
-
if (value === null || Object(value) !== value || Array.isArray(value)) return false;
|
|
23
|
-
try {
|
|
24
|
-
Function.prototype.toString.call(value);
|
|
25
|
-
return false;
|
|
26
|
-
} catch {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region src/integrations/upstash.ts
|
|
32
|
-
const maskedUpstashRuntimeValue = "********";
|
|
33
|
-
function hasUpstashEnv(env) {
|
|
34
|
-
const url = readEnv(env, "KV_REST_API_URL");
|
|
35
|
-
const token = readEnv(env, "KV_REST_API_TOKEN");
|
|
36
|
-
return Boolean(url && token);
|
|
37
|
-
}
|
|
38
|
-
function resolveUpstashStore(config = {}) {
|
|
39
|
-
return {
|
|
40
|
-
driver: "upstash",
|
|
41
|
-
token: trimmed(config.token) ?? maskedUpstashRuntimeValue,
|
|
42
|
-
url: trimmed(config.url) ?? maskedUpstashRuntimeValue
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/config.ts
|
|
47
|
-
function resolveFsLiteStore(config = {}) {
|
|
48
|
-
return defu({ base: trimmed(config.base) }, {
|
|
49
|
-
driver: "fs-lite",
|
|
50
|
-
base: ".vitehub/data/kv"
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
function resolveCloudflareStore(config = {}, env = process.env) {
|
|
54
|
-
return defu({
|
|
55
|
-
binding: trimmed(config.binding),
|
|
56
|
-
namespaceId: trimmed(config.namespaceId) ?? readEnv(env, "KV_NAMESPACE_ID")
|
|
57
|
-
}, {
|
|
58
|
-
driver: "cloudflare-kv-binding",
|
|
59
|
-
binding: "KV"
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
function resolveDenoStore(config = {}) {
|
|
63
|
-
const path = trimmed(config.path);
|
|
64
|
-
return path ? {
|
|
65
|
-
driver: "deno-kv",
|
|
66
|
-
path
|
|
67
|
-
} : { driver: "deno-kv" };
|
|
68
|
-
}
|
|
69
|
-
function resolveExplicitStore(store, env) {
|
|
70
|
-
switch (store.driver) {
|
|
71
|
-
case "cloudflare-kv-binding": return resolveCloudflareStore(store, env);
|
|
72
|
-
case "deno-kv": return resolveDenoStore(store);
|
|
73
|
-
case "upstash": return resolveUpstashStore(store);
|
|
74
|
-
case "fs-lite": return resolveFsLiteStore(store);
|
|
75
|
-
default: throw new TypeError(`Unknown \`kv.driver\`: ${JSON.stringify(store.driver)}. Expected "cloudflare-kv-binding", "deno-kv", "upstash", or "fs-lite".`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
function createResolvedConfig(store, stores) {
|
|
79
|
-
return stores ? {
|
|
80
|
-
store,
|
|
81
|
-
stores: {
|
|
82
|
-
default: store,
|
|
83
|
-
...stores
|
|
84
|
-
}
|
|
85
|
-
} : { store };
|
|
86
|
-
}
|
|
87
|
-
function hasStoresConfig(options) {
|
|
88
|
-
return !!options && "stores" in options && isPlainObject(options.stores);
|
|
89
|
-
}
|
|
90
|
-
function normalizeKVOptions(options, input = {}) {
|
|
91
|
-
if (options === false) return;
|
|
92
|
-
if (typeof options !== "undefined" && !isPlainObject(options)) throw new TypeError("`kv` must be a plain object.");
|
|
93
|
-
const env = input.env || process.env;
|
|
94
|
-
const hosting = normalizeHosting(input.hosting);
|
|
95
|
-
const explicit = options;
|
|
96
|
-
if (hasStoresConfig(options)) {
|
|
97
|
-
const resolvedStores = Object.fromEntries(Object.entries(options.stores).map(([name, store]) => [name, resolveExplicitStore(store, env)]));
|
|
98
|
-
const defaultStore = resolvedStores.default;
|
|
99
|
-
if (!defaultStore) throw new TypeError("`kv.stores.default` is required when using named KV stores.");
|
|
100
|
-
return createResolvedConfig(defaultStore, resolvedStores);
|
|
101
|
-
}
|
|
102
|
-
if (explicit?.driver) return createResolvedConfig(resolveExplicitStore(explicit, env));
|
|
103
|
-
if (hosting.includes("deno")) return createResolvedConfig(resolveDenoStore());
|
|
104
|
-
if (hasUpstashEnv(env)) return createResolvedConfig(resolveUpstashStore());
|
|
105
|
-
if (hosting.includes("vercel")) return createResolvedConfig(resolveUpstashStore());
|
|
106
|
-
if (hosting.includes("cloudflare")) return createResolvedConfig(resolveCloudflareStore({}, env));
|
|
107
|
-
return createResolvedConfig(resolveFsLiteStore());
|
|
108
|
-
}
|
|
109
|
-
//#endregion
|
|
110
|
-
export { trimmed as i, isPlainObject as n, readEnv as r, normalizeKVOptions as t };
|
package/dist/deno-kv-cJx3jU10.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
//#region src/runtime/deno-kv.ts
|
|
2
|
-
function getDenoRuntime() {
|
|
3
|
-
return globalThis.Deno;
|
|
4
|
-
}
|
|
5
|
-
function toDenoKey(key) {
|
|
6
|
-
return [key];
|
|
7
|
-
}
|
|
8
|
-
function fromDenoKey(key) {
|
|
9
|
-
return key.length === 1 && typeof key[0] === "string" ? key[0] : void 0;
|
|
10
|
-
}
|
|
11
|
-
function createDenoKVDriver(options = { driver: "deno-kv" }) {
|
|
12
|
-
let kvPromise;
|
|
13
|
-
const open = () => kvPromise ||= (async () => {
|
|
14
|
-
const openKv = getDenoRuntime()?.openKv;
|
|
15
|
-
if (!openKv) throw new Error("[vitehub] Deno KV requires Deno.openKv(). The runtime must be Deno with KV enabled, or the KV Store needs another driver.");
|
|
16
|
-
return openKv(options.path);
|
|
17
|
-
})();
|
|
18
|
-
async function matchingKeys(base = "") {
|
|
19
|
-
const kv = await open();
|
|
20
|
-
const keys = [];
|
|
21
|
-
for await (const entry of kv.list({ prefix: [] })) if (fromDenoKey(entry.key)?.startsWith(base)) keys.push(entry.key);
|
|
22
|
-
return keys;
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
name: "deno-kv",
|
|
26
|
-
options,
|
|
27
|
-
async clear(base = "") {
|
|
28
|
-
const kv = await open();
|
|
29
|
-
for (const key of await matchingKeys(base)) await kv.delete(key);
|
|
30
|
-
},
|
|
31
|
-
async dispose() {
|
|
32
|
-
if (!kvPromise) return;
|
|
33
|
-
(await kvPromise).close?.();
|
|
34
|
-
kvPromise = void 0;
|
|
35
|
-
},
|
|
36
|
-
async getItem(key) {
|
|
37
|
-
return (await (await open()).get(toDenoKey(key))).value ?? null;
|
|
38
|
-
},
|
|
39
|
-
async getKeys(base = "") {
|
|
40
|
-
return (await matchingKeys(base)).flatMap((key) => fromDenoKey(key) ?? []).sort();
|
|
41
|
-
},
|
|
42
|
-
async listKeys({ cursor, limit, prefix = "" }) {
|
|
43
|
-
const iterator = (await open()).list({ prefix: [] }, {
|
|
44
|
-
cursor,
|
|
45
|
-
limit
|
|
46
|
-
});
|
|
47
|
-
const keys = [];
|
|
48
|
-
for await (const entry of iterator) {
|
|
49
|
-
const key = fromDenoKey(entry.key);
|
|
50
|
-
if (key?.startsWith(prefix)) keys.push(key);
|
|
51
|
-
}
|
|
52
|
-
return iterator.cursor ? {
|
|
53
|
-
keys,
|
|
54
|
-
cursor: iterator.cursor
|
|
55
|
-
} : { keys };
|
|
56
|
-
},
|
|
57
|
-
async hasItem(key) {
|
|
58
|
-
return (await (await open()).get(toDenoKey(key))).versionstamp !== null;
|
|
59
|
-
},
|
|
60
|
-
async removeItem(key) {
|
|
61
|
-
await (await open()).delete(toDenoKey(key));
|
|
62
|
-
},
|
|
63
|
-
async setItem(key, value) {
|
|
64
|
-
await (await open()).set(toDenoKey(key), value);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
//#endregion
|
|
69
|
-
export { createDenoKVDriver as default };
|
package/dist/fs-lite-BxzdiJSi.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { opendir } from "node:fs/promises";
|
|
2
|
-
import { join, relative, resolve, sep } from "node:path";
|
|
3
|
-
import createDriver from "unstorage/drivers/fs-lite";
|
|
4
|
-
//#region src/runtime/fs-lite.ts
|
|
5
|
-
function createFsLiteKVDriver(options) {
|
|
6
|
-
const driver = createDriver(options);
|
|
7
|
-
const continuations = /* @__PURE__ */ new Map();
|
|
8
|
-
const maximumContinuations = 32;
|
|
9
|
-
function releaseContinuation(cursor) {
|
|
10
|
-
const continuation = continuations.get(cursor);
|
|
11
|
-
if (!continuation) return;
|
|
12
|
-
clearTimeout(continuation.timeout);
|
|
13
|
-
continuations.delete(cursor);
|
|
14
|
-
continuation.iterator.return(void 0);
|
|
15
|
-
}
|
|
16
|
-
driver.listKeys = async ({ cursor, limit, prefix = "" }) => {
|
|
17
|
-
const root = resolve(options.base);
|
|
18
|
-
const keys = [];
|
|
19
|
-
async function* walk() {
|
|
20
|
-
const pendingDirectories = [root];
|
|
21
|
-
while (pendingDirectories.length > 0) {
|
|
22
|
-
const directory = pendingDirectories.pop();
|
|
23
|
-
let entries;
|
|
24
|
-
try {
|
|
25
|
-
entries = await opendir(directory);
|
|
26
|
-
} catch (error) {
|
|
27
|
-
if (directory === root && error instanceof Error && "code" in error && error.code === "ENOENT") return;
|
|
28
|
-
throw error;
|
|
29
|
-
}
|
|
30
|
-
for await (const entry of entries) {
|
|
31
|
-
const path = join(directory, entry.name);
|
|
32
|
-
if (entry.isDirectory()) {
|
|
33
|
-
pendingDirectories.push(path);
|
|
34
|
-
yield void 0;
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
if (entry.isFile()) yield relative(root, path);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
const continuation = cursor ? continuations.get(cursor) : void 0;
|
|
42
|
-
const iterator = continuation?.iterator ?? (cursor ? void 0 : walk());
|
|
43
|
-
if (!iterator) throw Object.assign(/* @__PURE__ */ new TypeError("Invalid or expired fs-lite KV cursor."), { code: "KV_CURSOR_EXPIRED" });
|
|
44
|
-
if (cursor && continuation) {
|
|
45
|
-
clearTimeout(continuation.timeout);
|
|
46
|
-
continuations.delete(cursor);
|
|
47
|
-
}
|
|
48
|
-
let scanned = 0;
|
|
49
|
-
while (scanned < limit) {
|
|
50
|
-
const entry = await iterator.next();
|
|
51
|
-
if (entry.done) return { keys };
|
|
52
|
-
scanned++;
|
|
53
|
-
const path = entry.value;
|
|
54
|
-
if (path === void 0) continue;
|
|
55
|
-
const key = path.split(sep).join(":");
|
|
56
|
-
if (key.startsWith(prefix)) keys.push(key);
|
|
57
|
-
}
|
|
58
|
-
const nextCursor = crypto.randomUUID();
|
|
59
|
-
const timeout = setTimeout(() => {
|
|
60
|
-
releaseContinuation(nextCursor);
|
|
61
|
-
}, 15 * 6e4);
|
|
62
|
-
timeout.unref();
|
|
63
|
-
continuations.set(nextCursor, {
|
|
64
|
-
iterator,
|
|
65
|
-
timeout
|
|
66
|
-
});
|
|
67
|
-
while (continuations.size > maximumContinuations) {
|
|
68
|
-
const oldestCursor = continuations.keys().next().value;
|
|
69
|
-
if (oldestCursor) releaseContinuation(oldestCursor);
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
keys,
|
|
73
|
-
cursor: nextCursor
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
return driver;
|
|
77
|
-
}
|
|
78
|
-
//#endregion
|
|
79
|
-
export { createFsLiteKVDriver as default };
|
package/dist/types-CO0DRjJa.d.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { ViteHubError, ViteHubErrorDetails } from "@vite-hub/runtime";
|
|
2
|
-
|
|
3
|
-
//#region src/types.d.ts
|
|
4
|
-
type KVDriver = "cloudflare-kv-binding" | "deno-kv" | "upstash" | "fs-lite";
|
|
5
|
-
interface CloudflareKVStoreConfig {
|
|
6
|
-
driver: "cloudflare-kv-binding";
|
|
7
|
-
binding?: string;
|
|
8
|
-
namespaceId?: string;
|
|
9
|
-
}
|
|
10
|
-
interface UpstashKVStoreConfig {
|
|
11
|
-
driver: "upstash";
|
|
12
|
-
token?: string;
|
|
13
|
-
url?: string;
|
|
14
|
-
}
|
|
15
|
-
interface DenoKVStoreConfig {
|
|
16
|
-
driver: "deno-kv";
|
|
17
|
-
path?: string;
|
|
18
|
-
}
|
|
19
|
-
interface FsLiteKVStoreConfig {
|
|
20
|
-
driver: "fs-lite";
|
|
21
|
-
base?: string;
|
|
22
|
-
}
|
|
23
|
-
type KVStoreConfig = CloudflareKVStoreConfig | DenoKVStoreConfig | UpstashKVStoreConfig | FsLiteKVStoreConfig;
|
|
24
|
-
interface ResolvedCloudflareKVStoreConfig extends CloudflareKVStoreConfig {
|
|
25
|
-
binding: string;
|
|
26
|
-
}
|
|
27
|
-
type ResolvedUpstashKVStoreConfig = Required<UpstashKVStoreConfig>;
|
|
28
|
-
interface ResolvedDenoKVStoreConfig extends DenoKVStoreConfig {
|
|
29
|
-
path?: string;
|
|
30
|
-
}
|
|
31
|
-
interface ResolvedFsLiteKVStoreConfig extends FsLiteKVStoreConfig {
|
|
32
|
-
base: string;
|
|
33
|
-
}
|
|
34
|
-
type ResolvedKVStoreConfig = ResolvedCloudflareKVStoreConfig | ResolvedDenoKVStoreConfig | ResolvedUpstashKVStoreConfig | ResolvedFsLiteKVStoreConfig;
|
|
35
|
-
type KVStoreName = "default" | (string & {});
|
|
36
|
-
interface KVStoresConfig {
|
|
37
|
-
stores: Record<string, KVStoreConfig>;
|
|
38
|
-
}
|
|
39
|
-
type KVModuleOptions = KVStoreConfig | KVStoresConfig | false;
|
|
40
|
-
interface ResolvedKVModuleOptions {
|
|
41
|
-
store: ResolvedKVStoreConfig;
|
|
42
|
-
stores?: Record<string, ResolvedKVStoreConfig>;
|
|
43
|
-
}
|
|
44
|
-
type KVOperation = "clear" | "del" | "get" | "getAndDelete" | "has" | "increment" | "keys" | "list" | "set";
|
|
45
|
-
type KVErrorDetails = ViteHubErrorDetails & {
|
|
46
|
-
operation: KVOperation;
|
|
47
|
-
store: string;
|
|
48
|
-
};
|
|
49
|
-
type KVResult<TResult> = [error: null, value: TResult] | [error: ViteHubError<"KV_OPERATION_FAILED", KVErrorDetails>, value: undefined];
|
|
50
|
-
interface KVListOptions {
|
|
51
|
-
/** Opaque continuation cursor returned by a previous page. */
|
|
52
|
-
cursor?: string;
|
|
53
|
-
/** Maximum number of keys to read. Must be a positive integer. */
|
|
54
|
-
limit: number;
|
|
55
|
-
prefix?: string;
|
|
56
|
-
}
|
|
57
|
-
interface KVListPage {
|
|
58
|
-
/** Provider-ordered keys. */
|
|
59
|
-
keys: string[];
|
|
60
|
-
/** Omitted when enumeration is complete. */
|
|
61
|
-
cursor?: string;
|
|
62
|
-
}
|
|
63
|
-
interface KVStorage {
|
|
64
|
-
clear(base?: string, options?: unknown): Promise<KVResult<void>>;
|
|
65
|
-
del(key: string, options?: unknown): Promise<KVResult<void>>;
|
|
66
|
-
get<T = unknown>(key: string, options?: unknown): Promise<KVResult<T | null>>;
|
|
67
|
-
/** Atomically returns and deletes a value when the configured store supports it. */
|
|
68
|
-
getAndDelete<T = unknown>(key: string): Promise<KVResult<T | null>>;
|
|
69
|
-
has(key: string, options?: unknown): Promise<KVResult<boolean>>;
|
|
70
|
-
/** Atomically increments a counter. The TTL is applied only when the counter is created. */
|
|
71
|
-
increment(key: string, ttl: number): Promise<KVResult<number>>;
|
|
72
|
-
keys(base?: string, options?: unknown): Promise<KVResult<string[]>>;
|
|
73
|
-
list(options: KVListOptions): Promise<KVResult<KVListPage>>;
|
|
74
|
-
set<T = unknown>(key: string, value: T, options?: unknown): Promise<KVResult<void>>;
|
|
75
|
-
store(name: KVStoreName): KVStorage;
|
|
76
|
-
}
|
|
77
|
-
//#endregion
|
|
78
|
-
export { ResolvedKVStoreConfig as _, KVErrorDetails as a, KVModuleOptions as c, KVStorage as d, KVStoreConfig as f, ResolvedKVModuleOptions as g, ResolvedFsLiteKVStoreConfig as h, KVDriver as i, KVOperation as l, ResolvedDenoKVStoreConfig as m, DenoKVStoreConfig as n, KVListOptions as o, ResolvedCloudflareKVStoreConfig as p, FsLiteKVStoreConfig as r, KVListPage as s, CloudflareKVStoreConfig as t, KVResult as u, ResolvedUpstashKVStoreConfig as v, UpstashKVStoreConfig as y };
|