@vite-hub/kv 0.0.0 → 0.0.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/dist/nuxt.js ADDED
@@ -0,0 +1,32 @@
1
+ import { n as assertNoVitePlugin, t as assertNoNitroModule } from "./nitro-B8aUYcjq.js";
2
+ import { defineNuxtModule } from "@nuxt/kit";
3
+ //#region src/nuxt/module.ts
4
+ const NITRO_MODULE_ID = "@vite-hub/kv/nitro";
5
+ const NITRO_MODULE_NAME = "@vite-hub/kv";
6
+ const NUXT_MODULE_ID = "@vite-hub/kv/nuxt";
7
+ const VITE_PLUGIN_NAME = "@vite-hub/kv/vite";
8
+ const installedNitroConfigs = /* @__PURE__ */ new WeakSet();
9
+ function installKVNitroModule(nitro, kv) {
10
+ nitro.modules ||= [];
11
+ if (!nitro.modules.includes(NITRO_MODULE_ID)) nitro.modules.push(NITRO_MODULE_ID);
12
+ if (kv !== void 0) nitro.kv = kv;
13
+ installedNitroConfigs.add(nitro);
14
+ }
15
+ const kvNuxtModule = defineNuxtModule({
16
+ meta: {
17
+ configKey: "kv",
18
+ name: NUXT_MODULE_ID
19
+ },
20
+ async setup(inlineOptions, nuxt) {
21
+ const topLevel = nuxt.options.kv;
22
+ if (topLevel === false) return;
23
+ const kv = topLevel ?? inlineOptions;
24
+ nuxt.options.nitro ||= {};
25
+ await assertNoVitePlugin(nuxt.options.vite, VITE_PLUGIN_NAME, NUXT_MODULE_ID);
26
+ if (!installedNitroConfigs.has(nuxt.options.nitro)) assertNoNitroModule(nuxt.options.nitro, NITRO_MODULE_ID, NITRO_MODULE_NAME, NUXT_MODULE_ID);
27
+ installKVNitroModule(nuxt.options.nitro, kv);
28
+ nuxt.hook("nitro:config", (config) => installKVNitroModule(config, kv));
29
+ }
30
+ });
31
+ //#endregion
32
+ export { kvNuxtModule as default };
@@ -0,0 +1,6 @@
1
+ import { definePlugin } from "nitro";
2
+
3
+ //#region src/runtime/nitro-plugin.d.ts
4
+ declare const kvNitroPlugin: ReturnType<typeof definePlugin>;
5
+ //#endregion
6
+ export { kvNitroPlugin as default };
@@ -0,0 +1,26 @@
1
+ import { t as createLazyKVRuntimeDriver } from "../driver-CPgLtkh4.js";
2
+ import { definePlugin } from "nitro";
3
+ import { useRuntimeConfig } from "nitro/runtime-config";
4
+ import { useStorage } from "nitro/storage";
5
+ //#region src/runtime/nitro-plugin.ts
6
+ const kvNitroPlugin = definePlugin(async () => {
7
+ const runtimeConfig = useRuntimeConfig();
8
+ if (!runtimeConfig.kv) return;
9
+ const storage = useStorage();
10
+ await storage.unmount("kv");
11
+ storage.mount("kv", createLazyKVRuntimeDriver(runtimeConfig.kv));
12
+ const stores = runtimeConfig.kv.stores || { default: runtimeConfig.kv.store };
13
+ for (const [name, store] of Object.entries(stores)) {
14
+ if (name === "default") continue;
15
+ await storage.unmount(`kv:${name}`);
16
+ storage.mount(`kv:${name}`, createLazyKVRuntimeDriver({
17
+ store,
18
+ stores: {
19
+ default: store,
20
+ [name]: store
21
+ }
22
+ }));
23
+ }
24
+ });
25
+ //#endregion
26
+ export { kvNitroPlugin as default };
@@ -0,0 +1,45 @@
1
+ //#region src/types.d.ts
2
+ type KVDriver = "cloudflare-kv-binding" | "upstash" | "fs-lite";
3
+ interface CloudflareKVStoreConfig {
4
+ driver: "cloudflare-kv-binding";
5
+ binding?: string;
6
+ namespaceId?: string;
7
+ }
8
+ interface UpstashKVStoreConfig {
9
+ driver: "upstash";
10
+ token?: string;
11
+ url?: string;
12
+ }
13
+ interface FsLiteKVStoreConfig {
14
+ driver: "fs-lite";
15
+ base?: string;
16
+ }
17
+ type KVStoreConfig = CloudflareKVStoreConfig | UpstashKVStoreConfig | FsLiteKVStoreConfig;
18
+ interface ResolvedCloudflareKVStoreConfig extends CloudflareKVStoreConfig {
19
+ binding: string;
20
+ }
21
+ type ResolvedUpstashKVStoreConfig = Required<UpstashKVStoreConfig>;
22
+ interface ResolvedFsLiteKVStoreConfig extends FsLiteKVStoreConfig {
23
+ base: string;
24
+ }
25
+ type ResolvedKVStoreConfig = ResolvedCloudflareKVStoreConfig | ResolvedUpstashKVStoreConfig | ResolvedFsLiteKVStoreConfig;
26
+ type KVStoreName = "default" | (string & {});
27
+ interface KVStoresConfig {
28
+ stores: Record<string, KVStoreConfig>;
29
+ }
30
+ type KVModuleOptions = KVStoreConfig | KVStoresConfig | false;
31
+ interface ResolvedKVModuleOptions {
32
+ store: ResolvedKVStoreConfig;
33
+ stores?: Record<string, ResolvedKVStoreConfig>;
34
+ }
35
+ interface KVStorage {
36
+ clear(base?: string, options?: unknown): Promise<void>;
37
+ del(key: string, options?: unknown): Promise<void>;
38
+ get<T = unknown>(key: string, options?: unknown): Promise<T | null>;
39
+ has(key: string, options?: unknown): Promise<boolean>;
40
+ keys(base?: string, options?: unknown): Promise<string[]>;
41
+ set<T = unknown>(key: string, value: T, options?: unknown): Promise<void>;
42
+ store(name: KVStoreName): KVStorage;
43
+ }
44
+ //#endregion
45
+ export { KVStorage as a, ResolvedFsLiteKVStoreConfig as c, ResolvedUpstashKVStoreConfig as d, UpstashKVStoreConfig as f, KVModuleOptions as i, ResolvedKVModuleOptions as l, FsLiteKVStoreConfig as n, KVStoreConfig as o, KVDriver as r, ResolvedCloudflareKVStoreConfig as s, CloudflareKVStoreConfig as t, ResolvedKVStoreConfig 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,35 @@
1
+ import { i as KVModuleOptions, l as ResolvedKVModuleOptions } from "./types-27OsNCU6.js";
2
+ import { NitroModule } from "nitro/types";
3
+ import { Plugin } from "vite";
4
+
5
+ //#region src/config.d.ts
6
+ interface KVResolutionInput {
7
+ env?: Record<string, string | undefined>;
8
+ hosting?: string;
9
+ }
10
+ //#endregion
11
+ //#region src/vite-config.d.ts
12
+ declare const KV_VITE_PLUGIN_NAME = "@vite-hub/kv/vite";
13
+ declare const KV_VIRTUAL_CONFIG_ID = "#vitehub/kv/config";
14
+ interface KVViteRuntimeConfig {
15
+ hosting?: string;
16
+ kv: false | ResolvedKVModuleOptions;
17
+ }
18
+ declare function resolveKVViteConfig(kv: KVModuleOptions | undefined, input?: KVResolutionInput): KVViteRuntimeConfig;
19
+ //#endregion
20
+ //#region src/vite.d.ts
21
+ interface KVVitePluginAPI {
22
+ getConfig: () => KVViteRuntimeConfig;
23
+ }
24
+ type KVVitePlugin = Plugin & {
25
+ api: KVVitePluginAPI;
26
+ nitro: NitroModule;
27
+ };
28
+ declare function hubKv(options?: KVModuleOptions): KVVitePlugin;
29
+ declare module "vite" {
30
+ interface UserConfig {
31
+ kv?: KVModuleOptions;
32
+ }
33
+ }
34
+ //#endregion
35
+ export { KVVitePlugin, KVVitePluginAPI, type KVViteRuntimeConfig, KV_VIRTUAL_CONFIG_ID, KV_VITE_PLUGIN_NAME, hubKv, resolveKVViteConfig };
package/dist/vite.js ADDED
@@ -0,0 +1,30 @@
1
+ import { i as resolveKVViteConfig, n as KV_VIRTUAL_CONFIG_ID, r as KV_VITE_PLUGIN_NAME, t as kvNitroModule } from "./module-BrvD5I2y.js";
2
+ //#region src/vite.ts
3
+ const RESOLVED_KV_VIRTUAL_CONFIG_ID = `\0${KV_VIRTUAL_CONFIG_ID}`;
4
+ function serializeVirtualConfig(config) {
5
+ return [
6
+ `export const hosting = ${JSON.stringify(config.hosting)};`,
7
+ `export const kv = ${JSON.stringify(config.kv)};`,
8
+ "export default { hosting, kv };"
9
+ ].join("\n");
10
+ }
11
+ function hubKv(options) {
12
+ let runtimeConfig;
13
+ const getConfig = () => runtimeConfig ??= resolveKVViteConfig(options);
14
+ return {
15
+ name: KV_VITE_PLUGIN_NAME,
16
+ api: { getConfig },
17
+ nitro: kvNitroModule,
18
+ configResolved(config) {
19
+ runtimeConfig = resolveKVViteConfig(config.kv ?? options);
20
+ },
21
+ resolveId(id) {
22
+ if (id === "#vitehub/kv/config") return RESOLVED_KV_VIRTUAL_CONFIG_ID;
23
+ },
24
+ load(id) {
25
+ if (id === RESOLVED_KV_VIRTUAL_CONFIG_ID) return serializeVirtualConfig(getConfig());
26
+ }
27
+ };
28
+ }
29
+ //#endregion
30
+ export { KV_VIRTUAL_CONFIG_ID, KV_VITE_PLUGIN_NAME, hubKv, resolveKVViteConfig };
package/package.json CHANGED
@@ -1,9 +1,80 @@
1
1
  {
2
2
  "name": "@vite-hub/kv",
3
- "version": "0.0.0",
4
- "description": "Reserved package name for ViteHub.",
3
+ "version": "0.0.1",
4
+ "description": "Vite-first key-value storage primitives and Nitro/Nuxt integration for ViteHub.",
5
+ "author": "onmax <maximogarciamtnez@gmail.com>",
5
6
  "license": "Apache-2.0",
6
- "publishConfig": {
7
- "access": "public"
7
+ "homepage": "https://github.com/vite-hub/vitehub#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/vite-hub/vitehub.git",
11
+ "directory": "packages/kv"
12
+ },
13
+ "bugs": "https://github.com/vite-hub/vitehub/issues",
14
+ "keywords": [
15
+ "vitehub",
16
+ "vite",
17
+ "nitro",
18
+ "nuxt",
19
+ "kv",
20
+ "cloudflare",
21
+ "vercel"
22
+ ],
23
+ "sideEffects": false,
24
+ "type": "module",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": "./dist/index.js",
28
+ "./nitro": "./dist/nitro.js",
29
+ "./nuxt": "./dist/nuxt.js",
30
+ "./runtime/nitro-plugin": "./dist/runtime/nitro-plugin.js",
31
+ "./virtual": "./dist/virtual.js",
32
+ "./vite": "./dist/vite.js",
33
+ "./package.json": "./package.json"
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "package.json"
38
+ ],
39
+ "dependencies": {
40
+ "@nuxt/kit": "^4.4.6",
41
+ "defu": "^6.1.4",
42
+ "exsolve": "^1.0.8",
43
+ "unstorage": "^2.0.0-alpha.7"
44
+ },
45
+ "peerDependencies": {
46
+ "@upstash/redis": "^1.37.0",
47
+ "nitro": "^3.0.0-0",
48
+ "vite": ">=6.0.0"
49
+ },
50
+ "peerDependenciesMeta": {
51
+ "@upstash/redis": {
52
+ "optional": true
53
+ },
54
+ "nitro": {
55
+ "optional": true
56
+ },
57
+ "vite": {
58
+ "optional": true
59
+ }
60
+ },
61
+ "devDependencies": {
62
+ "@nuxt/schema": "^4.4.6",
63
+ "nitro": "3.0.260311-beta",
64
+ "ofetch": "^1.5.1",
65
+ "publint": "^0.3.15",
66
+ "tsdown": "^0.21.8",
67
+ "tsx": "^4.21.0",
68
+ "typescript": "^6.0.2",
69
+ "vite": "^8.0.8",
70
+ "vitest": "^4.1.4",
71
+ "@vite-hub/internal": "0.0.1"
72
+ },
73
+ "scripts": {
74
+ "build": "tsdown --tsconfig tsconfig.build.json",
75
+ "dev": "tsdown --watch",
76
+ "typecheck": "tsc --noEmit -p ./tsconfig.json",
77
+ "test": "pnpm --dir ../runtime build && pnpm --dir ../shell build && pnpm --dir ../source build && pnpm --dir ../sandbox build && pnpm --dir ../workspace build && pnpm --dir ../agent build && pnpm --dir ../blob build && pnpm --dir ../database build && pnpm --dir ../env build && pnpm --dir . build && pnpm --dir ../queue build && pnpm --dir ../workflow build && vitest run",
78
+ "test:e2e": "tsx ./test/e2e.ts"
8
79
  }
9
- }
80
+ }