@vite-hub/kv 0.0.4 → 0.1.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 (37) hide show
  1. package/README.md +33 -8
  2. package/dist/cli-Cniq99iX.d.ts +85 -0
  3. package/dist/cli.d.ts +15 -0
  4. package/dist/cli.js +448 -0
  5. package/dist/cloudflare-env-C5rM7kUY.js +74 -0
  6. package/dist/{config-aM9Ae7tH.js → config-DR6_5ZwI.js} +36 -22
  7. package/dist/continuations-DPyH_vr1.js +63 -0
  8. package/dist/{dist-DDW1iC5f.js → create-storage-29gMzf41.js} +70 -75
  9. package/dist/cursor-history-dqYDlsaD.js +148 -0
  10. package/dist/deno-kv-CSYGvRx4.js +120 -0
  11. package/dist/{driver-BT9WefKi.d.ts → driver-D9fI27jl.d.ts} +33 -3
  12. package/dist/error-diagnostics-D_cQeZTi.js +82 -0
  13. package/dist/errors-Dc2oiW-Y.js +38 -0
  14. package/dist/errors.d.ts +12 -7
  15. package/dist/errors.js +2 -20
  16. package/dist/fs-lite-CbLKxLut.js +90 -0
  17. package/dist/index.d.ts +5 -4
  18. package/dist/index.js +92 -64
  19. package/dist/object-B1NW521B.js +7 -0
  20. package/dist/operations-ByuDE12r.js +1442 -0
  21. package/dist/operations-pn8_eGob.js +432 -0
  22. package/dist/operations-tNUdj3G4.d.ts +212 -0
  23. package/dist/operations.d.ts +68 -0
  24. package/dist/operations.js +455 -0
  25. package/dist/results-p7nPCnaJ.js +6 -0
  26. package/dist/runtime/cloudflare-kv.d.ts +3 -4
  27. package/dist/runtime/cloudflare-kv.js +84 -8
  28. package/dist/runtime/upstash-driver.d.ts +4 -6
  29. package/dist/runtime/upstash-driver.js +34 -44
  30. package/dist/{types-CO0DRjJa.d.ts → types-CMDvN0Wr.d.ts} +20 -17
  31. package/dist/utils2-Dsb9P4_2.js +28 -0
  32. package/dist/virtual.d.ts +1 -1
  33. package/dist/vite.d.ts +14 -10
  34. package/dist/vite.js +603 -224
  35. package/package.json +56 -16
  36. package/dist/deno-kv-cJx3jU10.js +0 -69
  37. package/dist/fs-lite-BxzdiJSi.js +0 -79
package/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "@vite-hub/kv",
3
- "version": "0.0.4",
3
+ "version": "0.1.0",
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
+ "redis",
10
+ "typescript",
11
+ "upstash",
8
12
  "vercel",
9
13
  "vite",
10
14
  "vitehub"
11
15
  ],
12
- "homepage": "https://github.com/vite-hub/vitehub#readme",
16
+ "homepage": "https://vitehub.dev",
13
17
  "bugs": "https://github.com/vite-hub/vitehub/issues",
14
18
  "license": "Apache-2.0",
15
19
  "author": "onmax <maximogarciamtnez@gmail.com>",
@@ -26,31 +30,67 @@
26
30
  "sideEffects": false,
27
31
  "types": "./dist/index.d.ts",
28
32
  "exports": {
29
- ".": "./dist/index.js",
30
- "./errors": "./dist/errors.js",
31
- "./runtime/cloudflare-kv": "./dist/runtime/cloudflare-kv.js",
32
- "./runtime/upstash-driver": "./dist/runtime/upstash-driver.js",
33
- "./virtual": "./dist/virtual.js",
34
- "./vite": "./dist/vite.js",
33
+ ".": {
34
+ "types": "./dist/index.d.ts",
35
+ "import": "./dist/index.js",
36
+ "default": "./dist/index.js"
37
+ },
38
+ "./cli": {
39
+ "types": "./dist/cli.d.ts",
40
+ "import": "./dist/cli.js",
41
+ "default": "./dist/cli.js"
42
+ },
43
+ "./errors": {
44
+ "types": "./dist/errors.d.ts",
45
+ "import": "./dist/errors.js",
46
+ "default": "./dist/errors.js"
47
+ },
48
+ "./operations": {
49
+ "types": "./dist/operations.d.ts",
50
+ "import": "./dist/operations.js",
51
+ "default": "./dist/operations.js"
52
+ },
53
+ "./runtime/cloudflare-kv": {
54
+ "types": "./dist/runtime/cloudflare-kv.d.ts",
55
+ "import": "./dist/runtime/cloudflare-kv.js",
56
+ "default": "./dist/runtime/cloudflare-kv.js"
57
+ },
58
+ "./runtime/upstash-driver": {
59
+ "types": "./dist/runtime/upstash-driver.d.ts",
60
+ "import": "./dist/runtime/upstash-driver.js",
61
+ "default": "./dist/runtime/upstash-driver.js"
62
+ },
63
+ "./virtual": {
64
+ "types": "./dist/virtual.d.ts",
65
+ "import": "./dist/virtual.js",
66
+ "default": "./dist/virtual.js"
67
+ },
68
+ "./vite": {
69
+ "types": "./dist/vite.d.ts",
70
+ "import": "./dist/vite.js",
71
+ "default": "./dist/vite.js"
72
+ },
35
73
  "./package.json": "./package.json"
36
74
  },
37
75
  "dependencies": {
38
- "@vite-hub/runtime": "0.0.4",
76
+ "@vite-hub/runtime": "0.1.0",
39
77
  "defu": "^6.1.7",
40
78
  "destr": "^2.0.5",
41
- "unstorage": "2.0.0-alpha.7"
79
+ "nostics": "1.3.0",
80
+ "unstorage": "2.0.0-alpha.10",
81
+ "valibot": "^1.5.0"
42
82
  },
43
83
  "devDependencies": {
44
84
  "ofetch": "^1.5.1",
45
- "publint": "^0.3.21",
85
+ "publint": "^0.3.25",
46
86
  "typescript": "^6.0.3",
47
- "vite": "^8.0.8",
48
- "vite-plus": "^0.1.24",
49
- "vitest": "^4.1.4",
87
+ "vite": "^8.2.2",
88
+ "vite-plus": "^0.3.3",
89
+ "vitest": "^4.1.11",
50
90
  "@vite-hub/internal": "0.0.1"
51
91
  },
52
92
  "peerDependencies": {
53
- "@upstash/redis": "^1.38.0",
93
+ "@upstash/redis": "^1.39.0",
54
94
  "vite": ">=8.0.0"
55
95
  },
56
96
  "peerDependenciesMeta": {
@@ -67,7 +107,7 @@
67
107
  "scripts": {
68
108
  "build": "vp pack",
69
109
  "dev": "vp pack --watch",
70
- "typecheck": "tsc --noEmit -p ./tsconfig.json",
110
+ "typecheck": "vp run --cache -t @vite-hub/kv#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
71
111
  "test": "vp run -t @vite-hub/kv#build && vp test"
72
112
  }
73
113
  }
@@ -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 };
@@ -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 };