@vite-hub/kv 0.0.1 → 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 +14 -8
- package/dist/{config-Bu0hVhEv.js → config-C1ofyzSt.js} +23 -21
- package/dist/deno-kv-JnitV_jG.js +54 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +20 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +116 -36
- package/dist/runtime/upstash-driver.d.ts +2 -0
- package/dist/runtime/upstash-driver.js +2 -0
- package/dist/types-Dg4l318i.d.ts +60 -0
- package/dist/vite.d.ts +3 -4
- package/dist/vite.js +383 -4
- package/package.json +37 -46
- package/dist/driver-CPgLtkh4.js +0 -81
- package/dist/env-Cs7n_E1y.js +0 -12
- package/dist/module-BrvD5I2y.js +0 -256
- package/dist/nitro-B8aUYcjq.js +0 -40
- package/dist/nitro.d.ts +0 -27
- package/dist/nitro.js +0 -2
- package/dist/nuxt.d.ts +0 -58077
- package/dist/nuxt.js +0 -32
- package/dist/runtime/nitro-plugin.d.ts +0 -6
- package/dist/runtime/nitro-plugin.js +0 -26
- package/dist/types-27OsNCU6.d.ts +0 -45
package/dist/module-BrvD5I2y.js
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import { n as trimmed, t as readEnv } from "./env-Cs7n_E1y.js";
|
|
2
|
-
import { i as detectHosting, n as warnVercelKVFallback, r as isPlainObject, t as normalizeKVOptions } from "./config-Bu0hVhEv.js";
|
|
3
|
-
import { i as resolveRuntimeEntry$1, r as assertNoVitePluginInNitro } from "./nitro-B8aUYcjq.js";
|
|
4
|
-
import { readFile } from "node:fs/promises";
|
|
5
|
-
//#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
|
|
6
|
-
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
7
|
-
function normalizeWindowsPath(input = "") {
|
|
8
|
-
if (!input) return input;
|
|
9
|
-
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
10
|
-
}
|
|
11
|
-
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
12
|
-
function cwd() {
|
|
13
|
-
if (typeof process !== "undefined" && typeof process.cwd === "function") return process.cwd().replace(/\\/g, "/");
|
|
14
|
-
return "/";
|
|
15
|
-
}
|
|
16
|
-
const resolve = function(...arguments_) {
|
|
17
|
-
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
18
|
-
let resolvedPath = "";
|
|
19
|
-
let resolvedAbsolute = false;
|
|
20
|
-
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
21
|
-
const path = index >= 0 ? arguments_[index] : cwd();
|
|
22
|
-
if (!path || path.length === 0) continue;
|
|
23
|
-
resolvedPath = `${path}/${resolvedPath}`;
|
|
24
|
-
resolvedAbsolute = isAbsolute(path);
|
|
25
|
-
}
|
|
26
|
-
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
27
|
-
if (resolvedAbsolute && !isAbsolute(resolvedPath)) return `/${resolvedPath}`;
|
|
28
|
-
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
29
|
-
};
|
|
30
|
-
function normalizeString(path, allowAboveRoot) {
|
|
31
|
-
let res = "";
|
|
32
|
-
let lastSegmentLength = 0;
|
|
33
|
-
let lastSlash = -1;
|
|
34
|
-
let dots = 0;
|
|
35
|
-
let char = null;
|
|
36
|
-
for (let index = 0; index <= path.length; ++index) {
|
|
37
|
-
if (index < path.length) char = path[index];
|
|
38
|
-
else if (char === "/") break;
|
|
39
|
-
else char = "/";
|
|
40
|
-
if (char === "/") {
|
|
41
|
-
if (lastSlash === index - 1 || dots === 1);
|
|
42
|
-
else if (dots === 2) {
|
|
43
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
44
|
-
if (res.length > 2) {
|
|
45
|
-
const lastSlashIndex = res.lastIndexOf("/");
|
|
46
|
-
if (lastSlashIndex === -1) {
|
|
47
|
-
res = "";
|
|
48
|
-
lastSegmentLength = 0;
|
|
49
|
-
} else {
|
|
50
|
-
res = res.slice(0, lastSlashIndex);
|
|
51
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
52
|
-
}
|
|
53
|
-
lastSlash = index;
|
|
54
|
-
dots = 0;
|
|
55
|
-
continue;
|
|
56
|
-
} else if (res.length > 0) {
|
|
57
|
-
res = "";
|
|
58
|
-
lastSegmentLength = 0;
|
|
59
|
-
lastSlash = index;
|
|
60
|
-
dots = 0;
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (allowAboveRoot) {
|
|
65
|
-
res += res.length > 0 ? "/.." : "..";
|
|
66
|
-
lastSegmentLength = 2;
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
|
|
70
|
-
else res = path.slice(lastSlash + 1, index);
|
|
71
|
-
lastSegmentLength = index - lastSlash - 1;
|
|
72
|
-
}
|
|
73
|
-
lastSlash = index;
|
|
74
|
-
dots = 0;
|
|
75
|
-
} else if (char === "." && dots !== -1) ++dots;
|
|
76
|
-
else dots = -1;
|
|
77
|
-
}
|
|
78
|
-
return res;
|
|
79
|
-
}
|
|
80
|
-
const isAbsolute = function(p) {
|
|
81
|
-
return _IS_ABSOLUTE_RE.test(p);
|
|
82
|
-
};
|
|
83
|
-
//#endregion
|
|
84
|
-
//#region ../internal/src/feature-bridge/feature-options.ts
|
|
85
|
-
function cloneFeatureOptions(feature, options) {
|
|
86
|
-
if (!isPlainObject(options)) throw new TypeError(`[vitehub] \`${feature}\` must be a plain object.`);
|
|
87
|
-
return { ...options };
|
|
88
|
-
}
|
|
89
|
-
function normalizeFeatureOptions(feature, options) {
|
|
90
|
-
if (options === false || typeof options === "undefined") return void 0;
|
|
91
|
-
return cloneFeatureOptions(feature, options);
|
|
92
|
-
}
|
|
93
|
-
//#endregion
|
|
94
|
-
//#region ../internal/src/feature-bridge/feature-engine.ts
|
|
95
|
-
function createFeatureEngine(options) {
|
|
96
|
-
return options;
|
|
97
|
-
}
|
|
98
|
-
function normalizeFeaturePublicOptions(feature, options) {
|
|
99
|
-
return normalizeFeatureOptions(feature, options);
|
|
100
|
-
}
|
|
101
|
-
function readFeaturePublicOptions(source, key) {
|
|
102
|
-
if (source.kind === "vite") return source.userConfig[key];
|
|
103
|
-
return source.nitro.options[key];
|
|
104
|
-
}
|
|
105
|
-
function resolveDefaultOptions(defaultOptions) {
|
|
106
|
-
return typeof defaultOptions === "function" ? defaultOptions() : defaultOptions;
|
|
107
|
-
}
|
|
108
|
-
function applyRuntimeConfig(runtimeConfig, key, config) {
|
|
109
|
-
runtimeConfig[key] = config;
|
|
110
|
-
}
|
|
111
|
-
async function readWorkspaceDeps(rootDir) {
|
|
112
|
-
const packageJson = JSON.parse(await readFile(resolve(rootDir, "package.json"), "utf8"));
|
|
113
|
-
return {
|
|
114
|
-
...packageJson.dependencies,
|
|
115
|
-
...packageJson.devDependencies
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
function resolveViteRoot(config) {
|
|
119
|
-
return resolve(process.cwd(), typeof config.root === "string" ? config.root : ".");
|
|
120
|
-
}
|
|
121
|
-
function resolveRawOptions(engine, source) {
|
|
122
|
-
const rawOptions = engine.readPublicOptions(source);
|
|
123
|
-
return typeof rawOptions === "undefined" && typeof engine.defaultOptions !== "undefined" ? resolveDefaultOptions(engine.defaultOptions) : rawOptions;
|
|
124
|
-
}
|
|
125
|
-
function resolveNormalizedConfig(engine, source) {
|
|
126
|
-
const rawOptions = resolveRawOptions(engine, source);
|
|
127
|
-
const hosting = source.kind === "vite" ? detectHosting({ options: source.userConfig }) : detectHosting(source.nitro);
|
|
128
|
-
if (rawOptions === false) return {
|
|
129
|
-
config: false,
|
|
130
|
-
hosting: hosting || void 0
|
|
131
|
-
};
|
|
132
|
-
const normalizedOptions = engine.normalizeOptions(rawOptions);
|
|
133
|
-
if (!normalizedOptions) return void 0;
|
|
134
|
-
return {
|
|
135
|
-
config: engine.resolveConfig ? engine.resolveConfig(normalizedOptions, hosting) : normalizedOptions,
|
|
136
|
-
hosting: hosting || void 0
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
async function buildFeatureResolvedState(engine, source) {
|
|
140
|
-
const resolved = resolveNormalizedConfig(engine, source);
|
|
141
|
-
if (!resolved) return void 0;
|
|
142
|
-
const rootDir = source.kind === "vite" ? resolveViteRoot(source.userConfig) : source.nitro.options.rootDir;
|
|
143
|
-
const runtimeConfig = source.kind === "nitro" ? source.nitro.options.runtimeConfig ||= {} : {};
|
|
144
|
-
if (resolved.hosting) runtimeConfig.hosting ||= resolved.hosting;
|
|
145
|
-
if (engine.assignRuntimeConfig) engine.assignRuntimeConfig(runtimeConfig, resolved.config);
|
|
146
|
-
else applyRuntimeConfig(runtimeConfig, engine.configKey, resolved.config);
|
|
147
|
-
const deps = engine.loadDeps ? await readWorkspaceDeps(rootDir) : {};
|
|
148
|
-
return {
|
|
149
|
-
rootDir,
|
|
150
|
-
config: resolved.config,
|
|
151
|
-
deps,
|
|
152
|
-
runtimeConfig,
|
|
153
|
-
hosting: resolved.hosting
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
async function buildFeatureNitroContext(engine, nitro) {
|
|
157
|
-
return await buildFeatureResolvedState(engine, {
|
|
158
|
-
kind: "nitro",
|
|
159
|
-
nitro
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
function createFeatureNitroBridge(engine) {
|
|
163
|
-
return {
|
|
164
|
-
name: engine.name,
|
|
165
|
-
async setup(nitro) {
|
|
166
|
-
await assertNoVitePluginInNitro(nitro, `${engine.name}/vite`, `${engine.name}/nitro`);
|
|
167
|
-
const context = await buildFeatureNitroContext(engine, nitro);
|
|
168
|
-
if (!context) return;
|
|
169
|
-
await engine.setupNitro?.(nitro, context);
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
//#endregion
|
|
174
|
-
//#region ../internal/src/arrays.ts
|
|
175
|
-
function pushUnique(arr, item, key = (value) => value) {
|
|
176
|
-
const id = key(item);
|
|
177
|
-
if (arr.some((entry) => key(entry) === id)) return;
|
|
178
|
-
arr.push(item);
|
|
179
|
-
}
|
|
180
|
-
//#endregion
|
|
181
|
-
//#region src/integrations/cloudflare.ts
|
|
182
|
-
function configureCloudflareKV(target, config) {
|
|
183
|
-
for (const store of Object.values(config.stores || { default: config.store })) {
|
|
184
|
-
if (store.driver !== "cloudflare-kv-binding" || !store.namespaceId) continue;
|
|
185
|
-
const { binding, namespaceId } = store;
|
|
186
|
-
target.cloudflare ||= {};
|
|
187
|
-
target.cloudflare.wrangler ||= {};
|
|
188
|
-
target.cloudflare.wrangler.kv_namespaces ||= [];
|
|
189
|
-
pushUnique(target.cloudflare.wrangler.kv_namespaces, {
|
|
190
|
-
binding,
|
|
191
|
-
id: namespaceId
|
|
192
|
-
}, (entry) => entry.binding);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
//#endregion
|
|
196
|
-
//#region src/vite-config.ts
|
|
197
|
-
const KV_VITE_PLUGIN_NAME = "@vite-hub/kv/vite";
|
|
198
|
-
const KV_VIRTUAL_CONFIG_ID = "#vitehub/kv/config";
|
|
199
|
-
function resolveHosting(input) {
|
|
200
|
-
const env = input.env || process.env;
|
|
201
|
-
return trimmed(input.hosting) ?? readEnv(env, "NITRO_PRESET", "VITEHUB_HOSTING");
|
|
202
|
-
}
|
|
203
|
-
function resolveKVViteConfig(kv, input = {}) {
|
|
204
|
-
const env = input.env || process.env;
|
|
205
|
-
const hosting = resolveHosting(input);
|
|
206
|
-
return {
|
|
207
|
-
hosting,
|
|
208
|
-
kv: normalizeKVOptions(kv, {
|
|
209
|
-
env,
|
|
210
|
-
hosting
|
|
211
|
-
}) ?? false
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
//#endregion
|
|
215
|
-
//#region src/feature.ts
|
|
216
|
-
function resolveRuntimeEntry(srcRelative, packageSubpath) {
|
|
217
|
-
return resolveRuntimeEntry$1(srcRelative, packageSubpath, import.meta.url);
|
|
218
|
-
}
|
|
219
|
-
function normalizeKVPublicOptions(options) {
|
|
220
|
-
return normalizeFeaturePublicOptions("kv", options);
|
|
221
|
-
}
|
|
222
|
-
function readKVPublicOptions(source) {
|
|
223
|
-
const options = readFeaturePublicOptions(source, "kv");
|
|
224
|
-
return typeof options === "undefined" ? {} : options;
|
|
225
|
-
}
|
|
226
|
-
//#endregion
|
|
227
|
-
//#region src/nitro/module.ts
|
|
228
|
-
const kvNitroModule = createFeatureNitroBridge(createFeatureEngine({
|
|
229
|
-
name: "@vite-hub/kv",
|
|
230
|
-
feature: "kv",
|
|
231
|
-
configKey: "kv",
|
|
232
|
-
normalizeOptions: normalizeKVPublicOptions,
|
|
233
|
-
resolveConfig(options, hosting) {
|
|
234
|
-
return resolveKVViteConfig(options, {
|
|
235
|
-
env: process.env,
|
|
236
|
-
hosting
|
|
237
|
-
}).kv;
|
|
238
|
-
},
|
|
239
|
-
readPublicOptions: readKVPublicOptions,
|
|
240
|
-
setupNitro(nitro, context) {
|
|
241
|
-
if (!context.config) return;
|
|
242
|
-
const target = nitro;
|
|
243
|
-
const resolved = context.config;
|
|
244
|
-
target.options.alias ||= {};
|
|
245
|
-
target.options.alias["@vite-hub/kv"] = resolveRuntimeEntry("./index", "@vite-hub/kv");
|
|
246
|
-
target.options.plugins ||= [];
|
|
247
|
-
const plugin = resolveRuntimeEntry("./runtime/nitro-plugin", "@vite-hub/kv/runtime/nitro-plugin");
|
|
248
|
-
if (!target.options.plugins.includes(plugin)) target.options.plugins.push(plugin);
|
|
249
|
-
target.options.storage ||= {};
|
|
250
|
-
target.options.storage.kv = resolved.store;
|
|
251
|
-
configureCloudflareKV(target.options, resolved);
|
|
252
|
-
warnVercelKVFallback(target, resolved, context.hosting);
|
|
253
|
-
}
|
|
254
|
-
}));
|
|
255
|
-
//#endregion
|
|
256
|
-
export { resolveKVViteConfig as i, KV_VIRTUAL_CONFIG_ID as n, KV_VITE_PLUGIN_NAME as r, kvNitroModule as t };
|
package/dist/nitro-B8aUYcjq.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { resolveModulePath } from "exsolve";
|
|
2
|
-
//#region ../internal/src/nitro.ts
|
|
3
|
-
function resolveRuntimeEntry(srcRelative, packageSubpath, importMetaUrl) {
|
|
4
|
-
return resolveModulePath(srcRelative, {
|
|
5
|
-
extensions: [".ts", ".mts"],
|
|
6
|
-
from: importMetaUrl,
|
|
7
|
-
try: true
|
|
8
|
-
}) ?? resolveModulePath(packageSubpath, {
|
|
9
|
-
extensions: [".js", ".mjs"],
|
|
10
|
-
from: importMetaUrl
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
function isPromiseLike(value) {
|
|
14
|
-
return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
|
|
15
|
-
}
|
|
16
|
-
async function hasNamedVitePlugin(plugin, name) {
|
|
17
|
-
if (isPromiseLike(plugin)) return hasNamedVitePlugin(await plugin, name);
|
|
18
|
-
if (Array.isArray(plugin)) {
|
|
19
|
-
for (const entry of plugin) if (await hasNamedVitePlugin(entry, name)) return true;
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
return typeof plugin === "object" && plugin !== null && "name" in plugin && plugin.name === name;
|
|
23
|
-
}
|
|
24
|
-
function hasNitroModule(entry, moduleId, moduleName) {
|
|
25
|
-
if (entry === moduleId) return true;
|
|
26
|
-
if (typeof entry !== "object" || entry === null) return false;
|
|
27
|
-
const module = "nitro" in entry ? entry.nitro : entry;
|
|
28
|
-
return typeof module === "object" && module !== null && "name" in module && module.name === moduleName;
|
|
29
|
-
}
|
|
30
|
-
async function assertNoVitePlugin(vite, vitePluginName, integrationName) {
|
|
31
|
-
if (await hasNamedVitePlugin(vite?.plugins, vitePluginName)) throw new Error(`[vitehub] Do not configure ${vitePluginName} when using ${integrationName}.`);
|
|
32
|
-
}
|
|
33
|
-
async function assertNoVitePluginInNitro(nitro, vitePluginName, integrationName) {
|
|
34
|
-
await assertNoVitePlugin(nitro.options.vite, vitePluginName, integrationName);
|
|
35
|
-
}
|
|
36
|
-
function assertNoNitroModule(nitro, moduleId, moduleName, integrationName) {
|
|
37
|
-
if (nitro.modules?.some((entry) => hasNitroModule(entry, moduleId, moduleName))) throw new Error(`[vitehub] Do not configure ${moduleId} when using ${integrationName}.`);
|
|
38
|
-
}
|
|
39
|
-
//#endregion
|
|
40
|
-
export { resolveRuntimeEntry as i, assertNoVitePlugin as n, assertNoVitePluginInNitro as r, assertNoNitroModule as t };
|
package/dist/nitro.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { i as KVModuleOptions, l as ResolvedKVModuleOptions } from "./types-27OsNCU6.js";
|
|
2
|
-
import { NitroModule } from "nitro/types";
|
|
3
|
-
|
|
4
|
-
//#region src/nitro/module.d.ts
|
|
5
|
-
declare const kvNitroModule: NitroModule;
|
|
6
|
-
declare module "nitro/types" {
|
|
7
|
-
interface NitroOptions {
|
|
8
|
-
cloudflare?: {
|
|
9
|
-
wrangler?: {
|
|
10
|
-
kv_namespaces?: {
|
|
11
|
-
binding: string;
|
|
12
|
-
id: string;
|
|
13
|
-
}[];
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
kv?: KVModuleOptions;
|
|
17
|
-
}
|
|
18
|
-
interface NitroConfig {
|
|
19
|
-
kv?: KVModuleOptions;
|
|
20
|
-
}
|
|
21
|
-
interface NitroRuntimeConfig {
|
|
22
|
-
hosting?: string;
|
|
23
|
-
kv?: false | ResolvedKVModuleOptions;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
//#endregion
|
|
27
|
-
export { kvNitroModule as default };
|
package/dist/nitro.js
DELETED