@vite-hub/kv 0.0.3 → 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 (39) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +40 -7
  3. package/dist/cli-Cniq99iX.d.ts +85 -0
  4. package/dist/cli.d.ts +15 -0
  5. package/dist/cli.js +448 -0
  6. package/dist/cloudflare-env-C5rM7kUY.js +74 -0
  7. package/dist/{config-C1ofyzSt.js → config-DR6_5ZwI.js} +37 -17
  8. package/dist/continuations-DPyH_vr1.js +63 -0
  9. package/dist/create-storage-29gMzf41.js +442 -0
  10. package/dist/cursor-history-dqYDlsaD.js +148 -0
  11. package/dist/deno-kv-CSYGvRx4.js +120 -0
  12. package/dist/driver-D9fI27jl.d.ts +94 -0
  13. package/dist/error-diagnostics-D_cQeZTi.js +82 -0
  14. package/dist/errors-Dc2oiW-Y.js +38 -0
  15. package/dist/errors.d.ts +12 -7
  16. package/dist/errors.js +2 -20
  17. package/dist/fs-lite-CbLKxLut.js +90 -0
  18. package/dist/index.d.ts +5 -4
  19. package/dist/index.js +119 -49
  20. package/dist/object-B1NW521B.js +7 -0
  21. package/dist/operations-ByuDE12r.js +1442 -0
  22. package/dist/operations-pn8_eGob.js +432 -0
  23. package/dist/operations-tNUdj3G4.d.ts +212 -0
  24. package/dist/operations.d.ts +68 -0
  25. package/dist/operations.js +455 -0
  26. package/dist/results-p7nPCnaJ.js +6 -0
  27. package/dist/runtime/cloudflare-kv.d.ts +6 -0
  28. package/dist/runtime/cloudflare-kv.js +100 -0
  29. package/dist/runtime/upstash-driver.d.ts +5 -2
  30. package/dist/runtime/upstash-driver.js +111 -2
  31. package/dist/types-CMDvN0Wr.d.ts +81 -0
  32. package/dist/utils2-Dsb9P4_2.js +28 -0
  33. package/dist/virtual-module.d.ts +6 -0
  34. package/dist/virtual.d.ts +2 -6
  35. package/dist/vite.d.ts +30 -10
  36. package/dist/vite.js +4910 -213
  37. package/package.json +57 -15
  38. package/dist/deno-kv-JnitV_jG.js +0 -54
  39. package/dist/types-Dg4l318i.d.ts +0 -60
package/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "@vite-hub/kv",
3
- "version": "0.0.3",
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,29 +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/upstash-driver": "./dist/runtime/upstash-driver.js",
32
- "./virtual": "./dist/virtual.js",
33
- "./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
+ },
34
73
  "./package.json": "./package.json"
35
74
  },
36
75
  "dependencies": {
76
+ "@vite-hub/runtime": "0.1.0",
37
77
  "defu": "^6.1.7",
38
- "unstorage": "^2.0.0-alpha.7",
39
- "@vite-hub/runtime": "0.0.3"
78
+ "destr": "^2.0.5",
79
+ "nostics": "1.3.0",
80
+ "unstorage": "2.0.0-alpha.10",
81
+ "valibot": "^1.5.0"
40
82
  },
41
83
  "devDependencies": {
42
84
  "ofetch": "^1.5.1",
43
- "publint": "^0.3.21",
85
+ "publint": "^0.3.25",
44
86
  "typescript": "^6.0.3",
45
- "vite": "^8.0.8",
46
- "vite-plus": "^0.1.24",
47
- "vitest": "^4.1.4",
87
+ "vite": "^8.2.2",
88
+ "vite-plus": "^0.3.3",
89
+ "vitest": "^4.1.11",
48
90
  "@vite-hub/internal": "0.0.1"
49
91
  },
50
92
  "peerDependencies": {
51
- "@upstash/redis": "^1.38.0",
93
+ "@upstash/redis": "^1.39.0",
52
94
  "vite": ">=8.0.0"
53
95
  },
54
96
  "peerDependenciesMeta": {
@@ -65,7 +107,7 @@
65
107
  "scripts": {
66
108
  "build": "vp pack",
67
109
  "dev": "vp pack --watch",
68
- "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",
69
111
  "test": "vp run -t @vite-hub/kv#build && vp test"
70
112
  }
71
113
  }
@@ -1,54 +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 hasItem(key) {
43
- return (await (await open()).get(toDenoKey(key))).value !== null;
44
- },
45
- async removeItem(key) {
46
- await (await open()).delete(toDenoKey(key));
47
- },
48
- async setItem(key, value) {
49
- await (await open()).set(toDenoKey(key), value);
50
- }
51
- };
52
- }
53
- //#endregion
54
- export { createDenoKVDriver as default };
@@ -1,60 +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" | "has" | "keys" | "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 KVStorage {
51
- clear(base?: string, options?: unknown): Promise<KVResult<void>>;
52
- del(key: string, options?: unknown): Promise<KVResult<void>>;
53
- get<T = unknown>(key: string, options?: unknown): Promise<KVResult<T | null>>;
54
- has(key: string, options?: unknown): Promise<KVResult<boolean>>;
55
- keys(base?: string, options?: unknown): Promise<KVResult<string[]>>;
56
- set<T = unknown>(key: string, value: T, options?: unknown): Promise<KVResult<void>>;
57
- store(name: KVStoreName): KVStorage;
58
- }
59
- //#endregion
60
- export { UpstashKVStoreConfig as _, KVErrorDetails as a, KVResult as c, ResolvedCloudflareKVStoreConfig as d, ResolvedDenoKVStoreConfig as f, ResolvedUpstashKVStoreConfig as g, ResolvedKVStoreConfig as h, KVDriver as i, KVStorage as l, ResolvedKVModuleOptions as m, DenoKVStoreConfig as n, KVModuleOptions as o, ResolvedFsLiteKVStoreConfig as p, FsLiteKVStoreConfig as r, KVOperation as s, CloudflareKVStoreConfig as t, KVStoreConfig as u };