@vite-hub/kv 0.0.0 → 0.0.2

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 CHANGED
@@ -1,3 +1,59 @@
1
1
  # @vite-hub/kv
2
2
 
3
- Reserved package name for ViteHub.
3
+ <p>
4
+ <a href="https://vitehub.dev"><img alt="ViteHub" src="https://img.shields.io/badge/ViteHub-vitehub.dev-646cff?style=flat-square"></a>
5
+ <img alt="TypeScript" src="https://img.shields.io/badge/TypeScript-ready-3178c6?style=flat-square">
6
+ <img alt="Vite" src="https://img.shields.io/badge/Vite-config-646cff?style=flat-square">
7
+ <img alt="KV" src="https://img.shields.io/badge/KV-stores-0f766e?style=flat-square">
8
+ </p>
9
+
10
+ `@vite-hub/kv` gives server code one small-state API for settings, flags, cache entries, and JSON-like records.
11
+
12
+ ## Install
13
+
14
+ ```sh
15
+ pnpm add @vite-hub/kv
16
+ ```
17
+
18
+ Add `@upstash/redis` when you use the Upstash driver.
19
+
20
+ ## Minimal API
21
+
22
+ ```ts
23
+ // server/api/settings.put.ts
24
+ import { kv } from "@vite-hub/kv"
25
+ import { defineEventHandler, readBody } from "h3"
26
+
27
+ export default defineEventHandler(async (event) => {
28
+ const [writeError] = await kv.set("settings", await readBody(event))
29
+ if (writeError) throw writeError
30
+
31
+ const [readError, settings] = await kv.get("settings")
32
+ if (readError) throw readError
33
+ return settings
34
+ })
35
+ ```
36
+
37
+ ```ts
38
+ // vite.config.ts
39
+ import { hubKv } from "@vite-hub/kv/vite"
40
+ import { defineConfig } from "vite"
41
+
42
+ export default defineConfig({
43
+ kv: {
44
+ driver: "fs-lite",
45
+ base: ".data/kv",
46
+ },
47
+ plugins: [hubKv()],
48
+ })
49
+ ```
50
+
51
+ ## Vite Integration
52
+
53
+ Use `hubKv()` in Vite to resolve KV config and expose the `kv` runtime helper to server code.
54
+
55
+ Providers include local `fs-lite`, [Cloudflare Workers KV](https://developers.cloudflare.com/kv/), and [Upstash Redis](https://upstash.com/docs/redis/overall/getstarted). The storage layer is built on [unstorage](https://unstorage.unjs.io/guide).
56
+
57
+ KV operations return `[error, value]`. Provider failures use `ViteHubError` with code `KV_OPERATION_FAILED`, operation/store details, and the provider failure in `cause`. Invalid configuration and unknown named stores still throw before provider execution.
58
+
59
+ Learn more at [vitehub.dev](https://vitehub.dev).
@@ -0,0 +1,104 @@
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
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
23
+ }
24
+ //#endregion
25
+ //#region src/integrations/upstash.ts
26
+ const maskedUpstashRuntimeValue = "********";
27
+ function hasUpstashEnv(env) {
28
+ const url = readEnv(env, "KV_REST_API_URL");
29
+ const token = readEnv(env, "KV_REST_API_TOKEN");
30
+ return Boolean(url && token);
31
+ }
32
+ function resolveUpstashStore(config = {}) {
33
+ return {
34
+ driver: "upstash",
35
+ token: trimmed(config.token) ?? maskedUpstashRuntimeValue,
36
+ url: trimmed(config.url) ?? maskedUpstashRuntimeValue
37
+ };
38
+ }
39
+ //#endregion
40
+ //#region src/config.ts
41
+ function resolveFsLiteStore(config = {}) {
42
+ return defu({ base: trimmed(config.base) }, {
43
+ driver: "fs-lite",
44
+ base: ".data/kv"
45
+ });
46
+ }
47
+ function resolveCloudflareStore(config = {}, env = process.env) {
48
+ return defu({
49
+ binding: trimmed(config.binding),
50
+ namespaceId: trimmed(config.namespaceId) ?? readEnv(env, "KV_NAMESPACE_ID")
51
+ }, {
52
+ driver: "cloudflare-kv-binding",
53
+ binding: "KV"
54
+ });
55
+ }
56
+ function resolveDenoStore(config = {}) {
57
+ const path = trimmed(config.path);
58
+ return path ? {
59
+ driver: "deno-kv",
60
+ path
61
+ } : { driver: "deno-kv" };
62
+ }
63
+ function resolveExplicitStore(store, env) {
64
+ switch (store.driver) {
65
+ case "cloudflare-kv-binding": return resolveCloudflareStore(store, env);
66
+ case "deno-kv": return resolveDenoStore(store);
67
+ case "upstash": return resolveUpstashStore(store);
68
+ case "fs-lite": return resolveFsLiteStore(store);
69
+ default: throw new TypeError(`Unknown \`kv.driver\`: ${JSON.stringify(store.driver)}. Expected "cloudflare-kv-binding", "deno-kv", "upstash", or "fs-lite".`);
70
+ }
71
+ }
72
+ function createResolvedConfig(store, stores) {
73
+ return stores ? {
74
+ store,
75
+ stores: {
76
+ default: store,
77
+ ...stores
78
+ }
79
+ } : { store };
80
+ }
81
+ function hasStoresConfig(options) {
82
+ return !!options && "stores" in options && isPlainObject(options.stores);
83
+ }
84
+ function normalizeKVOptions(options, input = {}) {
85
+ if (options === false) return;
86
+ if (typeof options !== "undefined" && !isPlainObject(options)) throw new TypeError("`kv` must be a plain object.");
87
+ const env = input.env || process.env;
88
+ const hosting = normalizeHosting(input.hosting);
89
+ const explicit = options;
90
+ if (hasStoresConfig(options)) {
91
+ const resolvedStores = Object.fromEntries(Object.entries(options.stores).map(([name, store]) => [name, resolveExplicitStore(store, env)]));
92
+ const defaultStore = resolvedStores.default;
93
+ if (!defaultStore) throw new TypeError("`kv.stores.default` is required when using named KV stores.");
94
+ return createResolvedConfig(defaultStore, resolvedStores);
95
+ }
96
+ if (explicit?.driver) return createResolvedConfig(resolveExplicitStore(explicit, env));
97
+ if (hosting.includes("deno")) return createResolvedConfig(resolveDenoStore());
98
+ if (hasUpstashEnv(env)) return createResolvedConfig(resolveUpstashStore());
99
+ if (hosting.includes("vercel")) return createResolvedConfig(resolveUpstashStore());
100
+ if (hosting.includes("cloudflare")) return createResolvedConfig(resolveCloudflareStore({}, env));
101
+ return createResolvedConfig(resolveFsLiteStore());
102
+ }
103
+ //#endregion
104
+ export { readEnv as n, trimmed as r, normalizeKVOptions as t };
@@ -0,0 +1,54 @@
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 };
@@ -0,0 +1,8 @@
1
+ import { a as KVErrorDetails, c as KVResult, s as KVOperation } from "./types-Dg4l318i.js";
2
+ import { ViteHubError } from "@vite-hub/runtime";
3
+
4
+ //#region src/errors.d.ts
5
+ declare function kvError(operation: KVOperation, store: string, cause: unknown): ViteHubError<"KV_OPERATION_FAILED", KVErrorDetails>;
6
+ declare function kvResult<TResult>(operation: KVOperation, store: string, run: () => Promise<TResult>): Promise<KVResult<TResult>>;
7
+ //#endregion
8
+ export { kvError, kvResult };
package/dist/errors.js ADDED
@@ -0,0 +1,20 @@
1
+ import { ViteHubError } from "@vite-hub/runtime";
2
+ //#region src/errors.ts
3
+ function kvError(operation, store, cause) {
4
+ return new ViteHubError("KV_OPERATION_FAILED", "KV storage operation failed.", {
5
+ cause,
6
+ details: {
7
+ operation,
8
+ store
9
+ }
10
+ });
11
+ }
12
+ async function kvResult(operation, store, run) {
13
+ try {
14
+ return [null, await run()];
15
+ } catch (cause) {
16
+ return [kvError(operation, store, cause), void 0];
17
+ }
18
+ }
19
+ //#endregion
20
+ export { kvError, kvResult };
@@ -0,0 +1,6 @@
1
+ import { _ as UpstashKVStoreConfig, a as KVErrorDetails, c as KVResult, d as ResolvedCloudflareKVStoreConfig, f as ResolvedDenoKVStoreConfig, g as ResolvedUpstashKVStoreConfig, h as ResolvedKVStoreConfig, i as KVDriver, l as KVStorage, m as ResolvedKVModuleOptions, n as DenoKVStoreConfig, o as KVModuleOptions, p as ResolvedFsLiteKVStoreConfig, r as FsLiteKVStoreConfig, s as KVOperation, t as CloudflareKVStoreConfig, u as KVStoreConfig } from "./types-Dg4l318i.js";
2
+
3
+ //#region src/runtime/storage.d.ts
4
+ declare const kv: KVStorage;
5
+ //#endregion
6
+ export { type CloudflareKVStoreConfig, type DenoKVStoreConfig, type FsLiteKVStoreConfig, type KVDriver, type KVErrorDetails, type KVModuleOptions, type KVOperation, type KVResult, type KVStorage, type KVStoreConfig, type ResolvedCloudflareKVStoreConfig, type ResolvedDenoKVStoreConfig, type ResolvedFsLiteKVStoreConfig, type ResolvedKVModuleOptions, type ResolvedKVStoreConfig, type ResolvedUpstashKVStoreConfig, type UpstashKVStoreConfig, kv };
package/dist/index.js ADDED
@@ -0,0 +1,196 @@
1
+ import { kvResult } from "./errors.js";
2
+ import { n as readEnv, t as normalizeKVOptions } from "./config-C1ofyzSt.js";
3
+ import { AsyncLocalStorage } from "node:async_hooks";
4
+ import { createStorage } from "unstorage";
5
+ const activeEnvStorage = new AsyncLocalStorage();
6
+ function getActiveCloudflareEnv() {
7
+ const scoped = activeEnvStorage.getStore();
8
+ return scoped ? scoped.env : globalThis.__env__;
9
+ }
10
+ //#endregion
11
+ //#region src/runtime/upstash.ts
12
+ function isMaskedValue(value) {
13
+ return !value || /^\*+$/.test(value);
14
+ }
15
+ function assertRuntimeValue(value, envName) {
16
+ if (isMaskedValue(value)) throw new Error(`Missing runtime environment variable \`${envName}\` for Upstash KV.`);
17
+ }
18
+ function resolveRuntimeUpstashStore(config, env) {
19
+ const envUrl = readEnv(env, "KV_REST_API_URL");
20
+ const envToken = readEnv(env, "KV_REST_API_TOKEN");
21
+ const resolved = {
22
+ ...config,
23
+ token: isMaskedValue(config.token) ? envToken || config.token : config.token,
24
+ url: isMaskedValue(config.url) ? envUrl || config.url : config.url
25
+ };
26
+ assertRuntimeValue(resolved.url, "KV_REST_API_URL");
27
+ assertRuntimeValue(resolved.token, "KV_REST_API_TOKEN");
28
+ return resolved;
29
+ }
30
+ function resolveRuntimeKVOptions(config, env = process.env) {
31
+ if (!config || config.store.driver !== "upstash") return config;
32
+ return {
33
+ ...config,
34
+ store: resolveRuntimeUpstashStore(config.store, env)
35
+ };
36
+ }
37
+ //#endregion
38
+ //#region src/runtime/driver.ts
39
+ const lazyDriverMethods = new Set([
40
+ "clear",
41
+ "getItem",
42
+ "getKeys",
43
+ "hasItem",
44
+ "removeItem",
45
+ "setItem"
46
+ ]);
47
+ const lazyOptionalDriverMethods = {
48
+ "cloudflare-kv-binding": /* @__PURE__ */ new Set(),
49
+ "deno-kv": /* @__PURE__ */ new Set(),
50
+ "fs-lite": new Set([
51
+ "getItemRaw",
52
+ "getMeta",
53
+ "setItemRaw"
54
+ ]),
55
+ "upstash": new Set(["getItems"])
56
+ };
57
+ async function createRuntimeDriver(store) {
58
+ switch (store.driver) {
59
+ case "cloudflare-kv-binding": {
60
+ const { default: factory } = await import("unstorage/drivers/cloudflare-kv-binding");
61
+ return factory(store);
62
+ }
63
+ case "deno-kv": {
64
+ const { default: factory } = await import("./deno-kv-JnitV_jG.js");
65
+ return factory(store);
66
+ }
67
+ case "fs-lite": {
68
+ const { default: factory } = await import("unstorage/drivers/fs-lite");
69
+ return factory(store);
70
+ }
71
+ case "upstash": {
72
+ const { default: factory } = await import("@vite-hub/kv/runtime/upstash-driver");
73
+ return factory(store);
74
+ }
75
+ }
76
+ }
77
+ function createLazyKVRuntimeDriver(config) {
78
+ let driverPromise;
79
+ const resolve = () => driverPromise ||= (async () => {
80
+ const runtime = resolveRuntimeKVOptions(config);
81
+ if (!runtime) throw new Error("KV runtime is disabled.");
82
+ return createRuntimeDriver(runtime.store);
83
+ })();
84
+ const target = {
85
+ name: `lazy:${config.store.driver}`,
86
+ options: config.store
87
+ };
88
+ return new Proxy(target, { get(t, prop) {
89
+ const own = t[prop];
90
+ if (own !== void 0) return own;
91
+ if (prop === "dispose") return async () => {
92
+ if (!driverPromise) return;
93
+ const driver = await driverPromise;
94
+ return driver.dispose?.call(driver);
95
+ };
96
+ const optionalMethods = lazyOptionalDriverMethods[config.store.driver];
97
+ if (!lazyDriverMethods.has(prop) && !optionalMethods.has(prop)) return void 0;
98
+ return async (...args) => {
99
+ const driver = await resolve();
100
+ return driver[prop]?.apply(driver, args);
101
+ };
102
+ } });
103
+ }
104
+ //#endregion
105
+ //#region src/runtime/hosted-storage.ts
106
+ var KVStoreConfigurationError = class extends Error {};
107
+ function assertHostedConfig(config) {
108
+ if (!config) throw new KVStoreConfigurationError("[vitehub] `@vite-hub/kv` requires `hubKv()` and `kv !== false`.");
109
+ return config;
110
+ }
111
+ function createHostedKVStorage(config) {
112
+ return createNamedHostedKVStorage(config, "default");
113
+ }
114
+ function createNamedHostedKVStorage(config, name) {
115
+ const resolved = assertHostedConfig(config);
116
+ const store = (resolved.stores || { default: resolved.store })[name];
117
+ if (!store) throw new KVStoreConfigurationError(`[vitehub] Unknown KV store "${name}".`);
118
+ return createStorage({ driver: createLazyKVRuntimeDriver({
119
+ store,
120
+ stores: {
121
+ default: store,
122
+ [name]: store
123
+ }
124
+ }) });
125
+ }
126
+ //#endregion
127
+ //#region src/runtime/storage.ts
128
+ const storagePromises = /* @__PURE__ */ new Map();
129
+ function inferHosting(env) {
130
+ if (getActiveCloudflareEnv()) return "cloudflare";
131
+ const explicit = readEnv(env, "VITEHUB_HOSTING");
132
+ if (explicit) return explicit;
133
+ if (typeof globalThis.Deno?.openKv === "function") return "deno";
134
+ return readEnv(env, "KV_REST_API_URL") ? "vercel" : void 0;
135
+ }
136
+ function shouldFallbackHostedConfigImport(error) {
137
+ const code = error?.code;
138
+ return code === "MODULE_NOT_FOUND" || code === "ERR_MODULE_NOT_FOUND" || code === "ERR_PACKAGE_IMPORT_NOT_DEFINED" || code === "ERR_UNSUPPORTED_ESM_URL_SCHEME";
139
+ }
140
+ async function resolveHostedConfig() {
141
+ try {
142
+ return (await import("#vitehub/kv/config")).kv;
143
+ } catch (error) {
144
+ if (!shouldFallbackHostedConfigImport(error)) throw error;
145
+ const env = typeof process !== "undefined" ? process.env : {};
146
+ return normalizeKVOptions(void 0, {
147
+ env,
148
+ hosting: inferHosting(env)
149
+ }) || false;
150
+ }
151
+ }
152
+ async function resolveStorage(name = "default") {
153
+ const existing = storagePromises.get(name);
154
+ if (existing) return existing;
155
+ if (inferHosting(typeof process !== "undefined" ? process.env : {}) === "vercel") {
156
+ const promise = resolveHostedConfig().then((config) => name === "default" ? createHostedKVStorage(config) : createNamedHostedKVStorage(config, name));
157
+ storagePromises.set(name, promise);
158
+ return promise;
159
+ }
160
+ const promise = resolveHostedConfig().then((config) => name === "default" ? createHostedKVStorage(config) : createNamedHostedKVStorage(config, name));
161
+ storagePromises.set(name, promise);
162
+ return promise;
163
+ }
164
+ async function runKVOperation(operation, name, run) {
165
+ const result = await kvResult(operation, name, async () => run(await resolveStorage(name)));
166
+ if (result[0]?.cause instanceof KVStoreConfigurationError) throw result[0].cause;
167
+ return result;
168
+ }
169
+ function createKVStorage(name = "default") {
170
+ return {
171
+ async clear(base, options) {
172
+ return runKVOperation("clear", name, async (storage) => storage.clear(base, options));
173
+ },
174
+ async del(key, options) {
175
+ return runKVOperation("del", name, async (storage) => storage.removeItem(key, options));
176
+ },
177
+ async get(key, options) {
178
+ return runKVOperation("get", name, (storage) => storage.getItem(key, options));
179
+ },
180
+ async has(key, options) {
181
+ return runKVOperation("has", name, (storage) => storage.hasItem(key, options));
182
+ },
183
+ async keys(base, options) {
184
+ return runKVOperation("keys", name, (storage) => storage.getKeys(base, options));
185
+ },
186
+ async set(key, value, options) {
187
+ return runKVOperation("set", name, async (storage) => storage.setItem(key, value, options));
188
+ },
189
+ store(storeName) {
190
+ return createKVStorage(storeName);
191
+ }
192
+ };
193
+ }
194
+ const kv = createKVStorage();
195
+ //#endregion
196
+ export { kv };
@@ -0,0 +1,2 @@
1
+ import upstash_default from "unstorage/drivers/upstash";
2
+ export { upstash_default as default };
@@ -0,0 +1,2 @@
1
+ import upstash_default from "unstorage/drivers/upstash";
2
+ export { upstash_default as default };
@@ -0,0 +1,60 @@
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 };
@@ -0,0 +1,6 @@
1
+ declare module "#vitehub/kv/config" {
2
+ export const hosting: string | undefined
3
+ export const kv: false | import("./index.js").ResolvedKVModuleOptions
4
+ const config: { hosting?: string, kv: typeof kv }
5
+ export default config
6
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/vite.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ import { m as ResolvedKVModuleOptions, o as KVModuleOptions } from "./types-Dg4l318i.js";
2
+ import { Plugin } from "vite";
3
+
4
+ //#region src/config.d.ts
5
+ interface KVResolutionInput {
6
+ env?: Record<string, string | undefined>;
7
+ hosting?: string;
8
+ }
9
+ //#endregion
10
+ //#region src/vite-config.d.ts
11
+ declare const KV_VITE_PLUGIN_NAME = "@vite-hub/kv/vite";
12
+ declare const KV_VIRTUAL_CONFIG_ID = "#vitehub/kv/config";
13
+ interface KVViteRuntimeConfig {
14
+ hosting?: string;
15
+ kv: false | ResolvedKVModuleOptions;
16
+ }
17
+ declare function resolveKVViteConfig(kv: KVModuleOptions | undefined, input?: KVResolutionInput): KVViteRuntimeConfig;
18
+ //#endregion
19
+ //#region src/vite.d.ts
20
+ interface KVVitePluginAPI {
21
+ getConfig: () => KVViteRuntimeConfig;
22
+ }
23
+ type KVVitePlugin = Plugin & {
24
+ api: KVVitePluginAPI;
25
+ };
26
+ declare function hubKvOptionalPeerResolver(): Plugin;
27
+ declare function hubKv(options?: KVModuleOptions): KVVitePlugin;
28
+ declare module "vite" {
29
+ interface UserConfig {
30
+ kv?: KVModuleOptions;
31
+ }
32
+ }
33
+ //#endregion
34
+ export { KVVitePlugin, KVVitePluginAPI, type KVViteRuntimeConfig, KV_VIRTUAL_CONFIG_ID, KV_VITE_PLUGIN_NAME, hubKv, hubKvOptionalPeerResolver, resolveKVViteConfig };
package/dist/vite.js ADDED
@@ -0,0 +1,409 @@
1
+ import { n as readEnv, r as trimmed, t as normalizeKVOptions } from "./config-C1ofyzSt.js";
2
+ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
3
+ import { basename, join, resolve } from "node:path";
4
+ //#region src/vite-config.ts
5
+ const KV_VITE_PLUGIN_NAME = "@vite-hub/kv/vite";
6
+ const KV_VIRTUAL_CONFIG_ID = "#vitehub/kv/config";
7
+ function resolveHosting(input) {
8
+ const env = input.env || process.env;
9
+ return trimmed(input.hosting) ?? readEnv(env, "VITEHUB_HOSTING");
10
+ }
11
+ function resolveKVViteConfig(kv, input = {}) {
12
+ const env = input.env || process.env;
13
+ const hosting = resolveHosting(input);
14
+ return {
15
+ hosting,
16
+ kv: normalizeKVOptions(kv, {
17
+ env,
18
+ hosting
19
+ }) ?? false
20
+ };
21
+ }
22
+ //#endregion
23
+ //#region ../internal/src/build/provider-output-config.ts
24
+ function isProviderJsonArray(value, ancestors) {
25
+ if (Object.getPrototypeOf(value) !== Array.prototype || ancestors.has(value)) return false;
26
+ if (Reflect.ownKeys(value).length !== value.length + 1) return false;
27
+ ancestors.add(value);
28
+ try {
29
+ for (let index = 0; index < value.length; index++) {
30
+ const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
31
+ if (!descriptor?.enumerable || !("value" in descriptor) || !isProviderJsonValue(descriptor.value, ancestors)) return false;
32
+ }
33
+ return true;
34
+ } finally {
35
+ ancestors.delete(value);
36
+ }
37
+ }
38
+ function isProviderJsonRecordValue(value, ancestors) {
39
+ const prototype = Object.getPrototypeOf(value);
40
+ if (prototype !== Object.prototype && prototype !== null || ancestors.has(value)) return false;
41
+ ancestors.add(value);
42
+ try {
43
+ return Reflect.ownKeys(value).every((key) => {
44
+ if (typeof key !== "string") return false;
45
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
46
+ return descriptor?.enumerable === true && "value" in descriptor && isProviderJsonValue(descriptor.value, ancestors);
47
+ });
48
+ } finally {
49
+ ancestors.delete(value);
50
+ }
51
+ }
52
+ function isProviderJsonValue(value, ancestors) {
53
+ if (value === null || typeof value === "boolean" || typeof value === "string") return true;
54
+ if (typeof value === "number") return Number.isFinite(value);
55
+ if (Array.isArray(value)) return isProviderJsonArray(value, ancestors);
56
+ return typeof value === "object" && isProviderJsonRecordValue(value, ancestors);
57
+ }
58
+ function isProviderJsonRecord(value) {
59
+ try {
60
+ return typeof value === "object" && value !== null && !Array.isArray(value) && isProviderJsonRecordValue(value, /* @__PURE__ */ new Set());
61
+ } catch {
62
+ return false;
63
+ }
64
+ }
65
+ function assertProviderJsonRecord(value) {
66
+ if (!isProviderJsonRecord(value)) throw new TypeError("[vitehub] Provider output config must be a JSON object.");
67
+ }
68
+ function isFileNotFoundError(error) {
69
+ return error instanceof Error && "code" in error && error.code === "ENOENT";
70
+ }
71
+ async function readProviderJsonRecord(file) {
72
+ try {
73
+ const parsed = JSON.parse(await readFile(file, "utf8"));
74
+ assertProviderJsonRecord(parsed);
75
+ return parsed;
76
+ } catch (error) {
77
+ if (isFileNotFoundError(error)) return;
78
+ throw error;
79
+ }
80
+ }
81
+ function deleteOwnedFields(value, ownership) {
82
+ const next = { ...value };
83
+ for (const key of ownership.keys ?? []) delete next[key];
84
+ for (const field of Object.keys(ownership.arrays ?? {})) delete next[field];
85
+ return next;
86
+ }
87
+ function getKeyedArrayEntryValue(value, key) {
88
+ if (!isProviderJsonRecord(value)) return;
89
+ const entryValue = value[key];
90
+ return entryValue === null || typeof entryValue === "boolean" || typeof entryValue === "number" || typeof entryValue === "string" ? entryValue : void 0;
91
+ }
92
+ function preserveUnownedKeyedArrayEntries(value, ownership, replacements = []) {
93
+ const current = Array.isArray(value) ? value : [];
94
+ const replacementKeys = replacements.flatMap((entry) => {
95
+ const key = getKeyedArrayEntryValue(entry, ownership.key);
96
+ return key === void 0 ? [] : [key];
97
+ });
98
+ const ownedKeys = new Set([...ownership.values ?? [], ...replacementKeys]);
99
+ return current.filter((entry) => {
100
+ const key = getKeyedArrayEntryValue(entry, ownership.key);
101
+ return key === void 0 || !ownedKeys.has(key);
102
+ });
103
+ }
104
+ function mergeOwnedArrays(existing, value, arrays) {
105
+ const next = { ...value };
106
+ for (const [field, ownership] of Object.entries(arrays ?? {})) {
107
+ const incoming = Array.isArray(value[field]) ? value[field] : [];
108
+ const merged = [...preserveUnownedKeyedArrayEntries(existing[field], ownership, incoming), ...incoming];
109
+ if (merged.length) next[field] = merged;
110
+ else delete next[field];
111
+ }
112
+ return next;
113
+ }
114
+ async function persistProviderJsonRecord(file, value, removeIfEmpty) {
115
+ if (removeIfEmpty && !Object.keys(value).length) {
116
+ await rm(file, { force: true });
117
+ return;
118
+ }
119
+ await writeFile(file, `${JSON.stringify(value, null, 2)}\n`, "utf8");
120
+ }
121
+ async function writeProviderOutputConfig(file, value, ownership = {}, options = {}) {
122
+ await persistProviderJsonRecord(file, mergeProviderOutputConfig(await readProviderJsonRecord(file) ?? {}, value, ownership), options.removeIfEmpty === true);
123
+ }
124
+ function mergeProviderOutputConfig(existing, value, ownership = {}) {
125
+ assertProviderJsonRecord(existing);
126
+ assertProviderJsonRecord(value);
127
+ return {
128
+ ...deleteOwnedFields(existing, ownership),
129
+ ...mergeOwnedArrays(existing, value, ownership.arrays)
130
+ };
131
+ }
132
+ async function cleanProviderOutputConfig(file, ownership) {
133
+ if (!ownership.keys?.length && !Object.keys(ownership.arrays ?? {}).length) return;
134
+ const existing = await readProviderJsonRecord(file);
135
+ if (!existing) return;
136
+ const next = deleteOwnedFields(existing, ownership);
137
+ let changed = (ownership.keys ?? []).some((key) => key in existing);
138
+ for (const [field, arrayOwnership] of Object.entries(ownership.arrays ?? {})) {
139
+ if (!(field in existing)) continue;
140
+ const current = existing[field];
141
+ const preserved = preserveUnownedKeyedArrayEntries(current, arrayOwnership);
142
+ changed ||= !Array.isArray(current) || preserved.length !== current.length || preserved.length === 0;
143
+ if (preserved.length) next[field] = preserved;
144
+ }
145
+ if (!changed) return;
146
+ await persistProviderJsonRecord(file, next, true);
147
+ }
148
+ //#endregion
149
+ //#region ../internal/src/build/user-entry.ts
150
+ function toSafeAppName(rootDir) {
151
+ return basename(rootDir).replace(/[^a-z0-9-]+/gi, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").toLowerCase();
152
+ }
153
+ //#endregion
154
+ //#region ../internal/src/build/cloudflare.ts
155
+ function createDefaultCloudflareOutputRoot(rootDir) {
156
+ return resolve(rootDir, "dist", toSafeAppName(rootDir));
157
+ }
158
+ async function writeCloudflareWranglerConfig(options) {
159
+ const outputRoot = options.outputRoot ?? createDefaultCloudflareOutputRoot(options.rootDir);
160
+ const configFile = resolve(outputRoot, "wrangler.json");
161
+ if (!options.wranglerConfig) {
162
+ await cleanProviderOutputConfig(configFile, options.wranglerConfigOwnership ?? {});
163
+ return;
164
+ }
165
+ await mkdir(outputRoot, { recursive: true });
166
+ await writeProviderOutputConfig(configFile, options.wranglerConfig, options.wranglerConfigOwnership, { removeIfEmpty: true });
167
+ }
168
+ const VITEHUB_MODES = {
169
+ e2e: "e2e",
170
+ blob: "blob",
171
+ chat: "chat",
172
+ db: "db",
173
+ env: "env",
174
+ kv: "kv",
175
+ queue: "queue",
176
+ schedule: "schedule",
177
+ sandbox: "sandbox",
178
+ workspace: "workspace",
179
+ workflow: "workflow"
180
+ };
181
+ function isViteCli(argv) {
182
+ return argv.some((arg) => /(?:^|[/\\])vite(?:\.[cm]?js)?$/.test(arg) || arg === "vite");
183
+ }
184
+ function getViteCliMode(argv = process.argv) {
185
+ if (!isViteCli(argv)) return;
186
+ const modes = new Set(Object.values(VITEHUB_MODES));
187
+ for (let index = 0; index < argv.length; index += 1) {
188
+ const arg = argv[index];
189
+ const mode = arg === "--mode" || arg === "-m" ? argv[index + 1] : arg.startsWith("--mode=") ? arg.slice(7) : void 0;
190
+ if (mode && modes.has(mode)) return mode;
191
+ }
192
+ }
193
+ function getViteMode(env = process.env) {
194
+ return env["VITEHUB_VITE_MODE"] ?? getViteCliMode();
195
+ }
196
+ [
197
+ ".ts",
198
+ ".mts",
199
+ ".cts",
200
+ ".js",
201
+ ".mjs",
202
+ ".cjs"
203
+ ].flatMap((extension) => [["server", `email${extension}`], [`server.email${extension}`]]);
204
+ function createNoExternalMerger(packageName) {
205
+ return (current) => {
206
+ if (current === true) return true;
207
+ if (!current) return [packageName];
208
+ const values = Array.isArray(current) ? current : [current];
209
+ return values.includes(packageName) ? values : [...values, packageName];
210
+ };
211
+ }
212
+ function isServerEnvironment(name, config) {
213
+ return name === "ssr" || config.consumer === "server";
214
+ }
215
+ function shouldSkipViteProviderBuild(command, mode) {
216
+ return command === "serve" || mode === "e2e";
217
+ }
218
+ //#endregion
219
+ //#region ../internal/src/arrays.ts
220
+ function pushUnique(arr, item, key = (value) => value) {
221
+ const id = key(item);
222
+ if (arr.some((entry) => key(entry) === id)) return;
223
+ arr.push(item);
224
+ }
225
+ //#endregion
226
+ //#region src/integrations/cloudflare.ts
227
+ function configureCloudflareKV(target, config) {
228
+ for (const store of Object.values(config.stores || { default: config.store })) {
229
+ if (store.driver !== "cloudflare-kv-binding" || !store.namespaceId) continue;
230
+ const { binding, namespaceId } = store;
231
+ target.cloudflare ||= {};
232
+ target.cloudflare.wrangler ||= {};
233
+ target.cloudflare.wrangler.kv_namespaces ||= [];
234
+ pushUnique(target.cloudflare.wrangler.kv_namespaces, {
235
+ binding,
236
+ id: namespaceId
237
+ }, (entry) => entry.binding);
238
+ }
239
+ }
240
+ //#endregion
241
+ //#region src/vite.ts
242
+ const RESOLVED_KV_VIRTUAL_CONFIG_ID = `\0${KV_VIRTUAL_CONFIG_ID}`;
243
+ const RESOLVED_KV_RUNTIME_ID = `\0#vitehub/kv/runtime`;
244
+ const KV_ERRORS_IMPORT_ID = new URL(import.meta.url.endsWith(".ts") ? "./errors.ts" : "./errors.js", import.meta.url).href;
245
+ const UPSTASH_DRIVER_IMPORT_ID = "@vite-hub/kv/runtime/upstash-driver";
246
+ const UNSTORAGE_IMPORT_ID = import.meta.resolve("unstorage");
247
+ const CLOUDFLARE_KV_DRIVER_IMPORT_ID = import.meta.resolve("unstorage/drivers/cloudflare-kv-binding");
248
+ const mergeNoExternal = createNoExternalMerger("@vite-hub/kv");
249
+ const KV_CLOUDFLARE_BINDINGS_FILE = ".vitehub-kv-bindings.json";
250
+ function hubKvOptionalPeerResolver() {
251
+ return {
252
+ name: "@vite-hub/kv/optional-peers",
253
+ enforce: "pre",
254
+ resolveId(id, importer, resolveOptions) {
255
+ if (!resolveOptions?.ssr || !isKVOptionalUpstashImport(id, importer)) return;
256
+ return {
257
+ external: true,
258
+ id
259
+ };
260
+ }
261
+ };
262
+ }
263
+ function serializeVirtualConfig(config) {
264
+ return [
265
+ `export const hosting = ${JSON.stringify(config.hosting)};`,
266
+ `export const kv = ${JSON.stringify(config.kv)};`,
267
+ "export default { hosting, kv };"
268
+ ].join("\n");
269
+ }
270
+ function isCloudflareKVConfig(kv) {
271
+ return Boolean(kv) && Object.values(kv.stores || { default: kv.store }).every((store) => store.driver === "cloudflare-kv-binding");
272
+ }
273
+ function hasUpstashStore(kv) {
274
+ if (!kv) return false;
275
+ return Object.values(kv.stores || { default: kv.store }).some((store) => store.driver === "upstash");
276
+ }
277
+ function isKVOptionalUpstashImport(id, importer) {
278
+ if (id !== UPSTASH_DRIVER_IMPORT_ID || !importer) return false;
279
+ const normalizedImporter = importer.replace(/\\/g, "/").split("?", 1)[0];
280
+ return normalizedImporter.endsWith("/packages/kv/src/runtime/driver.ts") || normalizedImporter.endsWith("/packages/kv/dist/index.js") || normalizedImporter.includes("/@vite-hub/kv/dist/index.js");
281
+ }
282
+ function createCloudflareKVWranglerConfig(kv) {
283
+ if (!kv) return;
284
+ const target = {};
285
+ configureCloudflareKV(target, kv);
286
+ return target.cloudflare?.wrangler?.kv_namespaces?.length ? target.cloudflare.wrangler : void 0;
287
+ }
288
+ function cloudflareBindingsFile(rootDir) {
289
+ return join(createDefaultCloudflareOutputRoot(rootDir), KV_CLOUDFLARE_BINDINGS_FILE);
290
+ }
291
+ async function readOwnedCloudflareKVBindings(rootDir) {
292
+ try {
293
+ const parsed = JSON.parse(await readFile(cloudflareBindingsFile(rootDir), "utf8"));
294
+ return Array.isArray(parsed) ? parsed.filter((value) => typeof value === "string") : [];
295
+ } catch (error) {
296
+ if (error.code === "ENOENT") return [];
297
+ throw error;
298
+ }
299
+ }
300
+ async function writeOwnedCloudflareKVBindings(rootDir, bindings) {
301
+ const file = cloudflareBindingsFile(rootDir);
302
+ if (!bindings.length) {
303
+ await rm(file, { force: true });
304
+ return;
305
+ }
306
+ await mkdir(createDefaultCloudflareOutputRoot(rootDir), { recursive: true });
307
+ await writeFile(file, `${JSON.stringify([...new Set(bindings)], null, 2)}\n`, "utf8");
308
+ }
309
+ function serializeCloudflareRuntime(config) {
310
+ return [
311
+ `import { createStorage } from ${JSON.stringify(UNSTORAGE_IMPORT_ID)};`,
312
+ `import createDriver from ${JSON.stringify(CLOUDFLARE_KV_DRIVER_IMPORT_ID)};`,
313
+ `import { kvResult } from ${JSON.stringify(KV_ERRORS_IMPORT_ID)};`,
314
+ "",
315
+ `const kvConfig = ${JSON.stringify(config, null, 2)}`,
316
+ "const storages = new Map();",
317
+ "",
318
+ "function resolveStoreConfig(name) {",
319
+ " const stores = kvConfig.stores || { default: kvConfig.store };",
320
+ " const store = stores[name];",
321
+ " if (!store) throw new Error(`[vitehub] Unknown KV store \"${name}\".`);",
322
+ " return store;",
323
+ "}",
324
+ "",
325
+ "function resolveStorage(name = \"default\") {",
326
+ " const store = resolveStoreConfig(name);",
327
+ " const existing = storages.get(name);",
328
+ " if (existing) return existing;",
329
+ " const storage = createStorage({ driver: createDriver(store) });",
330
+ " storages.set(name, storage);",
331
+ " return storage;",
332
+ "}",
333
+ "",
334
+ "async function resolveStorageResult(name, operation) {",
335
+ " resolveStoreConfig(name);",
336
+ " return kvResult(operation, name, async () => resolveStorage(name));",
337
+ "}",
338
+ "",
339
+ "function createKVStorage(name = \"default\") {",
340
+ " return {",
341
+ " async clear(base, options) { const [error, storage] = await resolveStorageResult(name, \"clear\"); return error ? [error, undefined] : kvResult(\"clear\", name, async () => { await storage.clear(base, options); }); },",
342
+ " async del(key, options) { const [error, storage] = await resolveStorageResult(name, \"del\"); return error ? [error, undefined] : kvResult(\"del\", name, async () => { await storage.removeItem(key, options); }); },",
343
+ " async get(key, options) { const [error, storage] = await resolveStorageResult(name, \"get\"); return error ? [error, undefined] : kvResult(\"get\", name, () => storage.getItem(key, options)); },",
344
+ " async has(key, options) { const [error, storage] = await resolveStorageResult(name, \"has\"); return error ? [error, undefined] : kvResult(\"has\", name, () => storage.hasItem(key, options)); },",
345
+ " async keys(base, options) { const [error, storage] = await resolveStorageResult(name, \"keys\"); return error ? [error, undefined] : kvResult(\"keys\", name, () => storage.getKeys(base, options)); },",
346
+ " async set(key, value, options) { const [error, storage] = await resolveStorageResult(name, \"set\"); return error ? [error, undefined] : kvResult(\"set\", name, async () => { await storage.setItem(key, value, options); }); },",
347
+ " store(storeName) { return createKVStorage(storeName); },",
348
+ " };",
349
+ "}",
350
+ "",
351
+ "export const kv = createKVStorage();",
352
+ ""
353
+ ].join("\n");
354
+ }
355
+ function hubKv(options) {
356
+ let resolved;
357
+ let runtimeConfig;
358
+ const getConfig = () => runtimeConfig ??= resolveKVViteConfig(options);
359
+ return {
360
+ name: KV_VITE_PLUGIN_NAME,
361
+ enforce: "pre",
362
+ api: { getConfig },
363
+ configResolved(config) {
364
+ resolved = config;
365
+ runtimeConfig = resolveKVViteConfig(config.kv ?? options);
366
+ },
367
+ configEnvironment(name, config) {
368
+ if (!isServerEnvironment(name, config)) return;
369
+ return { resolve: { noExternal: mergeNoExternal(config.resolve?.noExternal) } };
370
+ },
371
+ resolveId(id, importer, resolveOptions) {
372
+ if (id === UPSTASH_DRIVER_IMPORT_ID && resolveOptions?.ssr && !hasUpstashStore(getConfig().kv) && isKVOptionalUpstashImport(id, importer)) return {
373
+ external: true,
374
+ id
375
+ };
376
+ if (id === "@vite-hub/kv" && isCloudflareKVConfig(getConfig().kv)) return RESOLVED_KV_RUNTIME_ID;
377
+ if (id === "#vitehub/kv/config") return RESOLVED_KV_VIRTUAL_CONFIG_ID;
378
+ },
379
+ load(id) {
380
+ if (id === RESOLVED_KV_RUNTIME_ID) {
381
+ const kv = getConfig().kv;
382
+ if (isCloudflareKVConfig(kv)) return serializeCloudflareRuntime(kv);
383
+ }
384
+ if (id === RESOLVED_KV_VIRTUAL_CONFIG_ID) return serializeVirtualConfig(getConfig());
385
+ },
386
+ closeBundle: {
387
+ order: "post",
388
+ sequential: true,
389
+ async handler() {
390
+ if (!resolved || shouldSkipViteProviderBuild(resolved.command, getViteMode())) return;
391
+ const wranglerConfig = createCloudflareKVWranglerConfig(getConfig().kv);
392
+ const nextBindings = wranglerConfig?.kv_namespaces?.map((binding) => binding.binding) ?? [];
393
+ const previousBindings = await readOwnedCloudflareKVBindings(resolved.root);
394
+ if (!wranglerConfig && !previousBindings.length) return;
395
+ await writeCloudflareWranglerConfig({
396
+ rootDir: resolved.root,
397
+ wranglerConfigOwnership: { arrays: { kv_namespaces: {
398
+ key: "binding",
399
+ values: [...previousBindings, ...nextBindings]
400
+ } } },
401
+ ...wranglerConfig ? { wranglerConfig } : {}
402
+ });
403
+ await writeOwnedCloudflareKVBindings(resolved.root, nextBindings);
404
+ }
405
+ }
406
+ };
407
+ }
408
+ //#endregion
409
+ export { KV_VIRTUAL_CONFIG_ID, KV_VITE_PLUGIN_NAME, hubKv, hubKvOptionalPeerResolver, resolveKVViteConfig };
package/package.json CHANGED
@@ -1,9 +1,71 @@
1
1
  {
2
2
  "name": "@vite-hub/kv",
3
- "version": "0.0.0",
4
- "description": "Reserved package name for ViteHub.",
3
+ "version": "0.0.2",
4
+ "description": "Vite-first key-value storage primitives and integration for ViteHub.",
5
+ "keywords": [
6
+ "cloudflare",
7
+ "kv",
8
+ "vercel",
9
+ "vite",
10
+ "vitehub"
11
+ ],
12
+ "homepage": "https://github.com/vite-hub/vitehub#readme",
13
+ "bugs": "https://github.com/vite-hub/vitehub/issues",
5
14
  "license": "Apache-2.0",
6
- "publishConfig": {
7
- "access": "public"
15
+ "author": "onmax <maximogarciamtnez@gmail.com>",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/vite-hub/vitehub.git",
19
+ "directory": "packages/kv"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "package.json"
24
+ ],
25
+ "type": "module",
26
+ "sideEffects": false,
27
+ "types": "./dist/index.d.ts",
28
+ "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",
34
+ "./package.json": "./package.json"
35
+ },
36
+ "dependencies": {
37
+ "defu": "^6.1.7",
38
+ "unstorage": "^2.0.0-alpha.7",
39
+ "@vite-hub/runtime": "0.0.2"
40
+ },
41
+ "devDependencies": {
42
+ "ofetch": "^1.5.1",
43
+ "publint": "^0.3.21",
44
+ "typescript": "^6.0.3",
45
+ "vite": "^8.0.8",
46
+ "vite-plus": "^0.1.24",
47
+ "vitest": "^4.1.4",
48
+ "@vite-hub/internal": "0.0.1"
49
+ },
50
+ "peerDependencies": {
51
+ "@upstash/redis": "^1.38.0",
52
+ "vite": ">=8.0.0"
53
+ },
54
+ "peerDependenciesMeta": {
55
+ "@upstash/redis": {
56
+ "optional": true
57
+ },
58
+ "vite": {
59
+ "optional": true
60
+ }
61
+ },
62
+ "engines": {
63
+ "node": ">=24.0.0"
64
+ },
65
+ "scripts": {
66
+ "build": "vp pack",
67
+ "dev": "vp pack --watch",
68
+ "typecheck": "tsc --noEmit -p ./tsconfig.json",
69
+ "test": "vp run -t @vite-hub/kv#build && vp test"
8
70
  }
9
- }
71
+ }