@vite-hub/kv 0.1.0 → 0.4.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/README.md +94 -21
- package/dist/batch--v0ri69O.js +40 -0
- package/dist/cli-DpPhz_Ek.d.ts +163 -0
- package/dist/cli.d.ts +4 -2
- package/dist/cli.js +99 -77
- package/dist/cloudflare-env-lOtHHsgP.js +46 -0
- package/dist/cloudflare-env-lookup-Bs0VDpU5.js +42 -0
- package/dist/cloudflare-kv-C3NO4C21.js +201 -0
- package/dist/cloudflare-kv-local-C2sbIrFy.js +71 -0
- package/dist/config-LfpUj9hs.js +252 -0
- package/dist/{create-storage-29gMzf41.js → create-storage-BORQm2a8.js} +206 -50
- package/dist/{cursor-history-dqYDlsaD.js → cursor-history-DRHh5bO5.js} +31 -14
- package/dist/database-oJdy0ZVX.js +250 -0
- package/dist/{deno-kv-CSYGvRx4.js → deno-kv-D_VtffFv.js} +12 -4
- package/dist/dev-peer-CHafxbtj.js +238 -0
- package/dist/driver-R4Z5Z5fl.d.ts +15 -0
- package/dist/durability.d.ts +17 -0
- package/dist/durability.js +53 -0
- package/dist/error-diagnostics-C54QQEhN.js +155 -0
- package/dist/errors-DzD6YNEH.js +88 -0
- package/dist/errors.d.ts +17 -1
- package/dist/errors.js +2 -2
- package/dist/fs-lite-BAgpmNAF.js +2 -0
- package/dist/fs-lite-BaklCLuV.js +386 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +326 -84
- package/dist/inspect-BIKQsqX4.js +118 -0
- package/dist/invariant-DolT9EEx.js +22 -0
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/{operations-tNUdj3G4.d.ts → operation-definition-nmRu_O3V.d.ts} +42 -15
- package/dist/{operations-pn8_eGob.js → operations-CtrWLmPK.js} +69 -66
- package/dist/operations-D2iI9oN4.js +1363 -0
- package/dist/operations.d.ts +15 -8
- package/dist/operations.js +56 -192
- package/dist/redis-shared-5ogRd3-Y.js +94 -0
- package/dist/runtime/cloudflare-kv.d.ts +1 -1
- package/dist/runtime/cloudflare-kv.js +1 -99
- package/dist/runtime/cloudflare-request-env.d.ts +7 -0
- package/dist/runtime/cloudflare-request-env.js +11 -0
- package/dist/runtime/nitro-plugin.d.ts +12 -0
- package/dist/runtime/nitro-plugin.js +25 -0
- package/dist/runtime/redis-driver.d.ts +11 -0
- package/dist/runtime/redis-driver.js +113 -0
- package/dist/runtime/unstorage-driver.d.ts +14 -0
- package/dist/runtime/unstorage-driver.js +37 -0
- package/dist/runtime/upstash-driver.d.ts +2 -2
- package/dist/runtime/upstash-driver.js +58 -98
- package/dist/{driver-D9fI27jl.d.ts → types-Bj3EQoRg.d.ts} +16 -41
- package/dist/types-Dv-OSXZC.d.ts +325 -0
- package/dist/upstash-B-vaUYqO.js +40 -0
- package/dist/{utils2-Dsb9P4_2.js → utils2-FozcTsmb.js} +5 -2
- package/dist/virtual-module.d.ts +3 -0
- package/dist/vite.d.ts +167 -14
- package/dist/vite.js +1195 -2876
- package/package.json +30 -21
- package/dist/cli-Cniq99iX.d.ts +0 -85
- package/dist/cloudflare-env-C5rM7kUY.js +0 -74
- package/dist/config-DR6_5ZwI.js +0 -124
- package/dist/continuations-DPyH_vr1.js +0 -63
- package/dist/error-diagnostics-D_cQeZTi.js +0 -82
- package/dist/errors-Dc2oiW-Y.js +0 -38
- package/dist/fs-lite-CbLKxLut.js +0 -90
- package/dist/object-B1NW521B.js +0 -7
- package/dist/operations-ByuDE12r.js +0 -1442
- package/dist/types-CMDvN0Wr.d.ts +0 -81
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/kv",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Vite-first key-value storage primitives and integration for ViteHub.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
7
7
|
"key-value",
|
|
8
8
|
"kv",
|
|
9
|
+
"postgres",
|
|
9
10
|
"redis",
|
|
10
11
|
"typescript",
|
|
11
12
|
"upstash",
|
|
@@ -40,20 +41,15 @@
|
|
|
40
41
|
"import": "./dist/cli.js",
|
|
41
42
|
"default": "./dist/cli.js"
|
|
42
43
|
},
|
|
43
|
-
"./
|
|
44
|
-
"types": "./dist/
|
|
45
|
-
"import": "./dist/
|
|
46
|
-
"default": "./dist/
|
|
44
|
+
"./durability": {
|
|
45
|
+
"types": "./dist/durability.d.ts",
|
|
46
|
+
"import": "./dist/durability.js",
|
|
47
|
+
"default": "./dist/durability.js"
|
|
47
48
|
},
|
|
48
|
-
"./
|
|
49
|
-
"types": "./dist/
|
|
50
|
-
"import": "./dist/
|
|
51
|
-
"default": "./dist/
|
|
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"
|
|
49
|
+
"./runtime/redis-driver": {
|
|
50
|
+
"types": "./dist/runtime/redis-driver.d.ts",
|
|
51
|
+
"import": "./dist/runtime/redis-driver.js",
|
|
52
|
+
"default": "./dist/runtime/redis-driver.js"
|
|
57
53
|
},
|
|
58
54
|
"./runtime/upstash-driver": {
|
|
59
55
|
"types": "./dist/runtime/upstash-driver.d.ts",
|
|
@@ -73,41 +69,54 @@
|
|
|
73
69
|
"./package.json": "./package.json"
|
|
74
70
|
},
|
|
75
71
|
"dependencies": {
|
|
76
|
-
"@
|
|
72
|
+
"@valibot/to-json-schema": "^1.8.0",
|
|
73
|
+
"@vite-hub/runtime": "0.4.1",
|
|
74
|
+
"birpc": "^4.2.0",
|
|
77
75
|
"defu": "^6.1.7",
|
|
78
76
|
"destr": "^2.0.5",
|
|
79
|
-
"
|
|
80
|
-
"
|
|
77
|
+
"ioredis": "^5.11.1",
|
|
78
|
+
"nostics": "1.4.0",
|
|
79
|
+
"proper-lockfile": "4.1.2",
|
|
80
|
+
"unstorage": "2.0.0-beta.0",
|
|
81
81
|
"valibot": "^1.5.0"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
|
+
"@types/node": "^24.19.1",
|
|
85
|
+
"@libsql/client": "^0.18.0",
|
|
86
|
+
"@vite-hub/database": "0.4.1",
|
|
87
|
+
"@types/proper-lockfile": "4.1.4",
|
|
88
|
+
"@vite-hub/internal": "0.0.1",
|
|
84
89
|
"ofetch": "^1.5.1",
|
|
90
|
+
"postgres": "^3.4.9",
|
|
85
91
|
"publint": "^0.3.25",
|
|
86
92
|
"typescript": "^6.0.3",
|
|
87
93
|
"vite": "^8.2.2",
|
|
88
94
|
"vite-plus": "^0.3.3",
|
|
89
|
-
"vitest": "^4.1.11"
|
|
90
|
-
"@vite-hub/internal": "0.0.1"
|
|
95
|
+
"vitest": "^4.1.11"
|
|
91
96
|
},
|
|
92
97
|
"peerDependencies": {
|
|
93
98
|
"@upstash/redis": "^1.39.0",
|
|
99
|
+
"@vite-hub/database": "0.4.1",
|
|
94
100
|
"vite": ">=8.0.0"
|
|
95
101
|
},
|
|
96
102
|
"peerDependenciesMeta": {
|
|
97
103
|
"@upstash/redis": {
|
|
98
104
|
"optional": true
|
|
99
105
|
},
|
|
106
|
+
"@vite-hub/database": {
|
|
107
|
+
"optional": true
|
|
108
|
+
},
|
|
100
109
|
"vite": {
|
|
101
110
|
"optional": true
|
|
102
111
|
}
|
|
103
112
|
},
|
|
104
113
|
"engines": {
|
|
105
|
-
"node": ">=24.
|
|
114
|
+
"node": ">=24.15.0"
|
|
106
115
|
},
|
|
107
116
|
"scripts": {
|
|
108
117
|
"build": "vp pack",
|
|
109
118
|
"dev": "vp pack --watch",
|
|
110
119
|
"typecheck": "vp run --cache -t @vite-hub/kv#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
|
|
111
|
-
"test": "vp run -t @vite-hub/kv#build && vp test"
|
|
120
|
+
"test": "vp run --cache -t @vite-hub/kv#build && vp test"
|
|
112
121
|
}
|
|
113
122
|
}
|
package/dist/cli-Cniq99iX.d.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { Diagnostic } from "nostics";
|
|
2
|
-
//#region ../internal/src/provision.d.ts
|
|
3
|
-
type ProvisionProvider = "cloudflare" | "vercel";
|
|
4
|
-
interface ProvisionLogger {
|
|
5
|
-
log: (message: string) => void;
|
|
6
|
-
warn: (message: string) => void;
|
|
7
|
-
}
|
|
8
|
-
interface ProvisionContext {
|
|
9
|
-
env: Record<string, string | undefined>;
|
|
10
|
-
fetch: typeof globalThis.fetch;
|
|
11
|
-
logger: ProvisionLogger;
|
|
12
|
-
markPlanUnchecked?: () => void;
|
|
13
|
-
}
|
|
14
|
-
interface ProvisionState {
|
|
15
|
-
cloudflare?: Record<string, Record<string, string>>;
|
|
16
|
-
vercel?: Record<string, Record<string, string>>;
|
|
17
|
-
}
|
|
18
|
-
interface ProvisionResult {
|
|
19
|
-
ids?: ProvisionState;
|
|
20
|
-
}
|
|
21
|
-
interface ProvisionAction {
|
|
22
|
-
kind: string;
|
|
23
|
-
name: string;
|
|
24
|
-
exists: boolean;
|
|
25
|
-
pending?: boolean;
|
|
26
|
-
apply: () => Promise<ProvisionResult>;
|
|
27
|
-
}
|
|
28
|
-
interface ProvisionStep {
|
|
29
|
-
id: string;
|
|
30
|
-
provider: ProvisionProvider;
|
|
31
|
-
plan: (context: ProvisionContext) => Promise<ProvisionAction[]>;
|
|
32
|
-
}
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region ../internal/src/cli.d.ts
|
|
35
|
-
interface ViteHubCliStreams {
|
|
36
|
-
stderr: {
|
|
37
|
-
write: (chunk: string | Uint8Array, encoding?: BufferEncoding | StdoutWriteCallback, callback?: StdoutWriteCallback) => unknown;
|
|
38
|
-
};
|
|
39
|
-
stdout: {
|
|
40
|
-
write: (chunk: string | Uint8Array) => unknown;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
interface ViteHubCliSpawnResult {
|
|
44
|
-
exitCode: number | null;
|
|
45
|
-
signal?: NodeJS.Signals | null;
|
|
46
|
-
}
|
|
47
|
-
interface ViteHubCliSpawnOptions {
|
|
48
|
-
cwd?: string;
|
|
49
|
-
env?: NodeJS.ProcessEnv;
|
|
50
|
-
stderr?: "inherit" | "pipe";
|
|
51
|
-
stdout?: "inherit" | "pipe";
|
|
52
|
-
}
|
|
53
|
-
type ViteHubCliSpawn = (command: string, args: string[], options?: ViteHubCliSpawnOptions) => Promise<ViteHubCliSpawnResult>;
|
|
54
|
-
interface ViteHubCliContext extends ViteHubCliStreams {
|
|
55
|
-
cwd: string;
|
|
56
|
-
env: NodeJS.ProcessEnv;
|
|
57
|
-
/** Replaces `fetch` for commands that call a running app, so tests need no server. */
|
|
58
|
-
fetch?: typeof fetch;
|
|
59
|
-
rootDir: string;
|
|
60
|
-
spawn: ViteHubCliSpawn;
|
|
61
|
-
}
|
|
62
|
-
interface ViteHubCliFeature {
|
|
63
|
-
description?: string;
|
|
64
|
-
name: string;
|
|
65
|
-
run: (args: string[], context: ViteHubCliContext) => Promise<number | void> | number | void;
|
|
66
|
-
usage?: string;
|
|
67
|
-
}
|
|
68
|
-
interface ViteHubCliCommandNamespace {
|
|
69
|
-
/** The feature that `vitehub <name>` runs when no feature is named. */
|
|
70
|
-
defaultFeature?: string;
|
|
71
|
-
description?: string;
|
|
72
|
-
features: ViteHubCliFeature[];
|
|
73
|
-
name: string;
|
|
74
|
-
}
|
|
75
|
-
interface ViteHubCliContributor {
|
|
76
|
-
namespaces: ViteHubCliCommandNamespace[];
|
|
77
|
-
provision?: ProvisionStep[];
|
|
78
|
-
}
|
|
79
|
-
type ViteHubCliContributorFactory = () => ViteHubCliContributor | undefined | Promise<ViteHubCliContributor | undefined>;
|
|
80
|
-
interface ViteHubCliPluginMetadata {
|
|
81
|
-
cli?: ViteHubCliContributor | ViteHubCliContributorFactory;
|
|
82
|
-
}
|
|
83
|
-
type StdoutWriteCallback = (error?: Error | null) => void;
|
|
84
|
-
//#endregion
|
|
85
|
-
export { ViteHubCliStreams as i, ViteHubCliContributor as n, ViteHubCliPluginMetadata as r, ViteHubCliContext as t };
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
//#region ../internal/src/runtime/cloudflare-env.ts
|
|
3
|
-
let activeEnv;
|
|
4
|
-
const activeEnvStorageKey = Symbol.for("vitehub.cloudflare.env-storage");
|
|
5
|
-
const runtimeGlobal = globalThis;
|
|
6
|
-
const activeEnvStorage = runtimeGlobal[activeEnvStorageKey] ||= new AsyncLocalStorage();
|
|
7
|
-
function getActiveCloudflareEnv() {
|
|
8
|
-
const scoped = activeEnvStorage.getStore();
|
|
9
|
-
if (scoped) return scoped.env;
|
|
10
|
-
const host = globalThis;
|
|
11
|
-
return Object.hasOwn(host, "__env__") && host.__env__ !== void 0 ? host.__env__ : activeEnv;
|
|
12
|
-
}
|
|
13
|
-
function getActiveCloudflareBinding(name) {
|
|
14
|
-
const env = getActiveCloudflareEnv();
|
|
15
|
-
return env && Object.hasOwn(env, name) ? env[name] : void 0;
|
|
16
|
-
}
|
|
17
|
-
function ownValue(value, key) {
|
|
18
|
-
if (value === null || typeof value !== "object" && typeof value !== "function" || !Object.hasOwn(value, key)) return void 0;
|
|
19
|
-
return Reflect.get(value, key);
|
|
20
|
-
}
|
|
21
|
-
function ownObject(value) {
|
|
22
|
-
return value !== null && (typeof value === "object" || typeof value === "function") ? value : void 0;
|
|
23
|
-
}
|
|
24
|
-
/** The objects where H3 1, H3 2, and Nitro hosts put Cloudflare `env` and `context`, in lookup order. */
|
|
25
|
-
function cloudflareOwners(target) {
|
|
26
|
-
const context = ownObject(ownValue(target, "context"));
|
|
27
|
-
const platform = ownObject(ownValue(context, "_platform"));
|
|
28
|
-
const req = ownObject(ownValue(target, "req"));
|
|
29
|
-
const nodeReq = ownObject(ownValue(ownObject(ownValue(target, "node")), "req"));
|
|
30
|
-
return [
|
|
31
|
-
ownObject(ownValue(context, "cloudflare")),
|
|
32
|
-
ownObject(ownValue(platform, "cloudflare")),
|
|
33
|
-
ownObject(ownValue(ownObject(ownValue(req, "runtime")), "cloudflare")),
|
|
34
|
-
ownObject(ownValue(ownObject(ownValue(nodeReq, "runtime")), "cloudflare"))
|
|
35
|
-
];
|
|
36
|
-
}
|
|
37
|
-
function getCloudflareEnv(event, options = {}) {
|
|
38
|
-
const target = ownObject(event);
|
|
39
|
-
for (const candidate of [ownValue(target, "env"), ...cloudflareOwners(target).map((owner) => ownValue(owner, "env"))]) if (candidate) return candidate;
|
|
40
|
-
return options.fallback === false ? void 0 : getActiveCloudflareEnv();
|
|
41
|
-
}
|
|
42
|
-
function resolveWaitUntil(event, options = {}) {
|
|
43
|
-
const target = ownObject(event);
|
|
44
|
-
const context = ownObject(ownValue(target, "context"));
|
|
45
|
-
const cloudflare = ownObject(ownValue(context, "cloudflare"));
|
|
46
|
-
const cloudflareContext = ownObject(ownValue(cloudflare, "context"));
|
|
47
|
-
const platformCloudflare = ownObject(ownValue(ownObject(ownValue(context, "_platform")), "cloudflare"));
|
|
48
|
-
const platformCloudflareContext = ownObject(ownValue(platformCloudflare, "context"));
|
|
49
|
-
const req = ownObject(ownValue(target, "req"));
|
|
50
|
-
const reqCloudflare = ownObject(ownValue(ownObject(ownValue(req, "runtime")), "cloudflare"));
|
|
51
|
-
const reqCloudflareContext = ownObject(ownValue(reqCloudflare, "context"));
|
|
52
|
-
const nodeReq = ownObject(ownValue(ownObject(ownValue(target, "node")), "req"));
|
|
53
|
-
const nodeCloudflare = ownObject(ownValue(ownObject(ownValue(nodeReq, "runtime")), "cloudflare"));
|
|
54
|
-
const hosts = [
|
|
55
|
-
context,
|
|
56
|
-
cloudflare,
|
|
57
|
-
cloudflareContext,
|
|
58
|
-
platformCloudflare,
|
|
59
|
-
platformCloudflareContext,
|
|
60
|
-
req,
|
|
61
|
-
reqCloudflare,
|
|
62
|
-
reqCloudflareContext,
|
|
63
|
-
nodeReq,
|
|
64
|
-
nodeCloudflare,
|
|
65
|
-
ownObject(ownValue(nodeCloudflare, "context"))
|
|
66
|
-
];
|
|
67
|
-
const owners = options.preferHost ? [...hosts, target] : [target, ...hosts];
|
|
68
|
-
for (const owner of owners) {
|
|
69
|
-
const waitUntil = ownValue(owner, "waitUntil");
|
|
70
|
-
if (typeof waitUntil === "function") return waitUntil.bind(owner);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
//#endregion
|
|
74
|
-
export { resolveWaitUntil as i, getActiveCloudflareEnv as n, getCloudflareEnv as r, getActiveCloudflareBinding as t };
|
package/dist/config-DR6_5ZwI.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { t as isPlainObject } from "./object-B1NW521B.js";
|
|
2
|
-
import { n as kvErrorDiagnostics } from "./error-diagnostics-D_cQeZTi.js";
|
|
3
|
-
import { defu } from "defu";
|
|
4
|
-
//#region ../internal/src/env.ts
|
|
5
|
-
function trimmed(value) {
|
|
6
|
-
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
7
|
-
}
|
|
8
|
-
function readEnv(env, ...names) {
|
|
9
|
-
for (const name of names) {
|
|
10
|
-
const value = trimmed(env[name]);
|
|
11
|
-
if (value) return value;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
//#endregion
|
|
15
|
-
//#region ../internal/src/hosting.ts
|
|
16
|
-
/**
|
|
17
|
-
* Returns the Nitro preset name that this build targets, as the developer wrote it.
|
|
18
|
-
* The order is `nitro.preset`, `hosting`, `NITRO_PRESET`, `SERVER_PRESET`, then `VITEHUB_HOSTING`.
|
|
19
|
-
* Empty values are skipped.
|
|
20
|
-
*/
|
|
21
|
-
function resolveHostPreset(input = {}) {
|
|
22
|
-
const env = input.env ?? (typeof process === "undefined" ? {} : process.env);
|
|
23
|
-
const nitroPreset = input.nitro && typeof input.nitro === "object" ? Reflect.get(input.nitro, "preset") : void 0;
|
|
24
|
-
for (const value of [
|
|
25
|
-
nitroPreset,
|
|
26
|
-
input.hosting,
|
|
27
|
-
env.NITRO_PRESET,
|
|
28
|
-
env.SERVER_PRESET,
|
|
29
|
-
env.VITEHUB_HOSTING
|
|
30
|
-
]) if (typeof value === "string" && value.trim()) return value.trim();
|
|
31
|
-
}
|
|
32
|
-
function normalizeHosting(hosting) {
|
|
33
|
-
const normalized = hosting?.trim().toLowerCase().replaceAll("_", "-") || "";
|
|
34
|
-
if (normalized === "cloudflare") return "cloudflare-module";
|
|
35
|
-
return normalized;
|
|
36
|
-
}
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region src/integrations/upstash.ts
|
|
39
|
-
const maskedUpstashRuntimeValue = "********";
|
|
40
|
-
/** Vercel names first, then the names that the Upstash console and NuxtHub use. */
|
|
41
|
-
const upstashUrlEnvNames = ["KV_REST_API_URL", "UPSTASH_REDIS_REST_URL"];
|
|
42
|
-
const upstashTokenEnvNames = ["KV_REST_API_TOKEN", "UPSTASH_REDIS_REST_TOKEN"];
|
|
43
|
-
function hasUpstashEnv(env) {
|
|
44
|
-
const url = readEnv(env, ...upstashUrlEnvNames);
|
|
45
|
-
const token = readEnv(env, ...upstashTokenEnvNames);
|
|
46
|
-
return Boolean(url && token);
|
|
47
|
-
}
|
|
48
|
-
function resolveUpstashStore(config = {}) {
|
|
49
|
-
return {
|
|
50
|
-
driver: "upstash",
|
|
51
|
-
token: trimmed(config.token) ?? maskedUpstashRuntimeValue,
|
|
52
|
-
url: trimmed(config.url) ?? maskedUpstashRuntimeValue
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
//#endregion
|
|
56
|
-
//#region src/config.ts
|
|
57
|
-
function resolveFsLiteStore(config = {}) {
|
|
58
|
-
return defu({ base: trimmed(config.base) }, {
|
|
59
|
-
driver: "fs-lite",
|
|
60
|
-
base: ".vitehub/data/kv"
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
function resolveCloudflareStore(config = {}, env = process.env) {
|
|
64
|
-
return defu({
|
|
65
|
-
binding: trimmed(config.binding),
|
|
66
|
-
namespaceId: trimmed(config.namespaceId) ?? readEnv(env, "KV_NAMESPACE_ID"),
|
|
67
|
-
namespaceName: trimmed(config.namespaceName)
|
|
68
|
-
}, {
|
|
69
|
-
driver: "cloudflare-kv-binding",
|
|
70
|
-
binding: "KV"
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
function resolveDenoStore(config = {}) {
|
|
74
|
-
const path = trimmed(config.path);
|
|
75
|
-
return path ? {
|
|
76
|
-
driver: "deno-kv",
|
|
77
|
-
path
|
|
78
|
-
} : { driver: "deno-kv" };
|
|
79
|
-
}
|
|
80
|
-
function resolveExplicitStore(store, env) {
|
|
81
|
-
switch (store.driver) {
|
|
82
|
-
case "cloudflare-kv-binding": return resolveCloudflareStore(store, env);
|
|
83
|
-
case "deno-kv": return resolveDenoStore(store);
|
|
84
|
-
case "upstash": return resolveUpstashStore(store);
|
|
85
|
-
case "fs-lite": return resolveFsLiteStore(store);
|
|
86
|
-
default: throw kvErrorDiagnostics.KV_INVALID_DRIVER({ driver: JSON.stringify(store.driver) });
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
function createResolvedConfig(store, stores) {
|
|
90
|
-
return stores ? {
|
|
91
|
-
store,
|
|
92
|
-
stores: {
|
|
93
|
-
default: store,
|
|
94
|
-
...stores
|
|
95
|
-
}
|
|
96
|
-
} : { store };
|
|
97
|
-
}
|
|
98
|
-
function hasStoresConfig(options, stores) {
|
|
99
|
-
return !!options && Object.hasOwn(options, "stores") && isPlainObject(stores);
|
|
100
|
-
}
|
|
101
|
-
function normalizeKVOptions(options, input = {}) {
|
|
102
|
-
if (options === false) return;
|
|
103
|
-
if (typeof options !== "undefined" && !isPlainObject(options)) throw kvErrorDiagnostics.KV_INVALID_CONFIG({ path: "kv" });
|
|
104
|
-
const env = input.env || process.env;
|
|
105
|
-
const hosting = normalizeHosting(input.hosting);
|
|
106
|
-
const explicit = options;
|
|
107
|
-
const hasOwnStores = options !== void 0 && Object.hasOwn(options, "stores");
|
|
108
|
-
const stores = hasOwnStores ? Reflect.get(options, "stores", options) : void 0;
|
|
109
|
-
if (hasOwnStores && !isPlainObject(stores)) throw kvErrorDiagnostics.KV_INVALID_CONFIG({ path: "kv.stores" });
|
|
110
|
-
if (hasStoresConfig(options, stores)) {
|
|
111
|
-
const resolvedStores = Object.fromEntries(Object.entries(stores).map(([name, store]) => [name, resolveExplicitStore(store, env)]));
|
|
112
|
-
const defaultStore = resolvedStores.default;
|
|
113
|
-
if (!defaultStore) throw kvErrorDiagnostics.KV_MISSING_DEFAULT_STORE();
|
|
114
|
-
return createResolvedConfig(defaultStore, resolvedStores);
|
|
115
|
-
}
|
|
116
|
-
if (explicit?.driver) return createResolvedConfig(resolveExplicitStore(explicit, env));
|
|
117
|
-
if (hosting.includes("deno")) return createResolvedConfig(resolveDenoStore());
|
|
118
|
-
if (hasUpstashEnv(env)) return createResolvedConfig(resolveUpstashStore());
|
|
119
|
-
if (hosting.includes("vercel")) return createResolvedConfig(resolveUpstashStore());
|
|
120
|
-
if (hosting.includes("cloudflare")) return createResolvedConfig(resolveCloudflareStore({}, env));
|
|
121
|
-
return createResolvedConfig(resolveFsLiteStore());
|
|
122
|
-
}
|
|
123
|
-
//#endregion
|
|
124
|
-
export { readEnv as a, resolveHostPreset as i, upstashTokenEnvNames as n, upstashUrlEnvNames as r, normalizeKVOptions as t };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
//#region src/runtime/continuations.ts
|
|
2
|
-
/** Owns process-local cursor retention. Taking a cursor transfers its resource to the caller. */
|
|
3
|
-
function createKVContinuations(options) {
|
|
4
|
-
const entries = /* @__PURE__ */ new Map();
|
|
5
|
-
const releases = /* @__PURE__ */ new Set();
|
|
6
|
-
const failures = [];
|
|
7
|
-
let bytes = 0;
|
|
8
|
-
let disposed = false;
|
|
9
|
-
function take(cursor) {
|
|
10
|
-
const entry = entries.get(cursor);
|
|
11
|
-
if (!entry) return void 0;
|
|
12
|
-
clearTimeout(entry.timeout);
|
|
13
|
-
entries.delete(cursor);
|
|
14
|
-
bytes -= entry.bytes;
|
|
15
|
-
return entry.value;
|
|
16
|
-
}
|
|
17
|
-
function release(value, surfaceFailure = false) {
|
|
18
|
-
const pending = Promise.resolve().then(() => options.release?.(value)).then(() => void 0).catch((error) => {
|
|
19
|
-
if (failures.length === 0) failures.push(error);
|
|
20
|
-
if (surfaceFailure) throw error;
|
|
21
|
-
}).finally(() => {
|
|
22
|
-
releases.delete(pending);
|
|
23
|
-
});
|
|
24
|
-
releases.add(pending);
|
|
25
|
-
return pending;
|
|
26
|
-
}
|
|
27
|
-
function evict(cursor) {
|
|
28
|
-
const value = take(cursor);
|
|
29
|
-
if (value !== void 0) release(value);
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
take,
|
|
33
|
-
async retain(value, size = 0) {
|
|
34
|
-
if (disposed) {
|
|
35
|
-
await release(value, true);
|
|
36
|
-
throw options.expired();
|
|
37
|
-
}
|
|
38
|
-
while (entries.size >= 32 || bytes + size > (options.maximumBytes ?? Number.POSITIVE_INFINITY)) {
|
|
39
|
-
const oldest = entries.keys().next().value;
|
|
40
|
-
if (!oldest) break;
|
|
41
|
-
evict(oldest);
|
|
42
|
-
}
|
|
43
|
-
const cursor = globalThis.crypto.randomUUID();
|
|
44
|
-
const timeout = setTimeout(() => evict(cursor), 9e5);
|
|
45
|
-
timeout.unref?.();
|
|
46
|
-
entries.set(cursor, {
|
|
47
|
-
value,
|
|
48
|
-
bytes: size,
|
|
49
|
-
timeout
|
|
50
|
-
});
|
|
51
|
-
bytes += size;
|
|
52
|
-
return cursor;
|
|
53
|
-
},
|
|
54
|
-
async dispose() {
|
|
55
|
-
disposed = true;
|
|
56
|
-
for (const cursor of entries.keys()) evict(cursor);
|
|
57
|
-
await Promise.all(releases);
|
|
58
|
-
if (failures.length > 0) throw new AggregateError(failures.splice(0), "Failed to release KV listing continuations.");
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
//#endregion
|
|
63
|
-
export { createKVContinuations as t };
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { defineErrors } from "@vite-hub/runtime";
|
|
2
|
-
//#region src/error-diagnostics.ts
|
|
3
|
-
const cursorProblems = {
|
|
4
|
-
"expired": "The list cursor has expired.",
|
|
5
|
-
"foreign": "The list cursor belongs to a different storage backend.",
|
|
6
|
-
"in-use": "The list cursor is already in use.",
|
|
7
|
-
"invalid": "The list cursor is invalid or exceeds the maximum size."
|
|
8
|
-
};
|
|
9
|
-
const kvErrorDiagnostics = /*#__PURE__*/ defineErrors({
|
|
10
|
-
docs: "https://vitehub.dev/docs/kv/limits-and-errors",
|
|
11
|
-
codes: {
|
|
12
|
-
KV_INVALID_CURSOR: {
|
|
13
|
-
why: ({ problem }) => cursorProblems[problem],
|
|
14
|
-
fix: "Pass the `cursor` of the previous page once, to the same store. If it fails, start again without `cursor`."
|
|
15
|
-
},
|
|
16
|
-
KV_INVALID_LIMIT: {
|
|
17
|
-
why: "`limit` must be a positive integer.",
|
|
18
|
-
fix: "Pass a positive integer, for example `kv.list({ limit: 100 })`."
|
|
19
|
-
},
|
|
20
|
-
KV_INVALID_TTL: {
|
|
21
|
-
why: "`ttl` must be a positive number of seconds within the safe integer range.",
|
|
22
|
-
fix: "Pass the TTL in seconds, for example `kv.increment('attempts', 60)`."
|
|
23
|
-
},
|
|
24
|
-
KV_OPERATION_FAILED: {
|
|
25
|
-
why: ({ operation, store }) => `kv.${operation}() failed on the "${store}" store.`,
|
|
26
|
-
fix: "Read `error.cause` for the provider error. Retry when the provider is available again."
|
|
27
|
-
},
|
|
28
|
-
KV_UNSUPPORTED_OPERATION: {
|
|
29
|
-
why: ({ operation, store }) => `kv.${operation}() needs atomic operations, and the "${store}" store does not support them.`,
|
|
30
|
-
fix: "Use the `upstash` driver for this store. For request budgets, use the Rate Limit primitive."
|
|
31
|
-
},
|
|
32
|
-
KV_DENO_KV_UNAVAILABLE: {
|
|
33
|
-
why: "The `deno-kv` driver needs `Deno.openKv()`, and this runtime does not have it.",
|
|
34
|
-
fix: "Run on Deno with KV enabled, or select another KV driver."
|
|
35
|
-
},
|
|
36
|
-
KV_DISABLED: {
|
|
37
|
-
why: "KV is not configured in this runtime.",
|
|
38
|
-
fix: "Add `hubKv()` to the Vite config and do not set `kv: false`."
|
|
39
|
-
},
|
|
40
|
-
KV_INVALID_CONFIG: {
|
|
41
|
-
why: ({ path }) => `\`${path}\` must be a plain object.`,
|
|
42
|
-
fix: "Pass an object, for example `kv: { driver: 'fs-lite' }`."
|
|
43
|
-
},
|
|
44
|
-
KV_INVALID_DRIVER: {
|
|
45
|
-
why: ({ driver }) => `\`kv.driver\` ${driver} is not a KV driver.`,
|
|
46
|
-
fix: "Set `kv.driver` to \"cloudflare-kv-binding\", \"deno-kv\", \"upstash\", or \"fs-lite\"."
|
|
47
|
-
},
|
|
48
|
-
KV_MISSING_DEFAULT_STORE: {
|
|
49
|
-
why: "`kv.stores.default` is missing.",
|
|
50
|
-
fix: "Add a `default` store when you configure named KV stores."
|
|
51
|
-
},
|
|
52
|
-
KV_MISSING_ENV: {
|
|
53
|
-
why: ({ names }) => `Upstash KV needs the runtime environment variable ${names}.`,
|
|
54
|
-
fix: "Set the variable in the host environment, or set `url` and `token` in the KV config."
|
|
55
|
-
},
|
|
56
|
-
KV_STORE_NOT_FOUND: {
|
|
57
|
-
why: ({ store }) => `The KV store "${store}" is not configured.`,
|
|
58
|
-
fix: "Add the store under `kv.stores`, or use the name of a configured store."
|
|
59
|
-
},
|
|
60
|
-
KV_CLI_USAGE: {
|
|
61
|
-
why: ({ problem }) => problem,
|
|
62
|
-
fix: "Run `vitehub kv --help` to see the commands and options."
|
|
63
|
-
},
|
|
64
|
-
KV_PROVIDER_INVALID_RESPONSE: {
|
|
65
|
-
why: ({ problem }) => `The KV provider returned a response that ViteHub cannot use. ${problem}`,
|
|
66
|
-
fix: "Retry the operation. If it fails again, open a ViteHub issue with the driver name."
|
|
67
|
-
},
|
|
68
|
-
KV_PROVISION_FAILED: {
|
|
69
|
-
why: ({ problem }) => `Cloudflare KV provisioning failed. ${problem}`,
|
|
70
|
-
fix: "Run `vitehub provision run --provider cloudflare --dry-run` and check the Cloudflare token permissions."
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
/** Codes that a KV operation throws because the code or the deployment must change. */
|
|
75
|
-
const kvConfigErrorCodes = /* @__PURE__ */ new Set([
|
|
76
|
-
"KV_DENO_KV_UNAVAILABLE",
|
|
77
|
-
"KV_DISABLED",
|
|
78
|
-
"KV_MISSING_ENV",
|
|
79
|
-
"KV_STORE_NOT_FOUND"
|
|
80
|
-
]);
|
|
81
|
-
//#endregion
|
|
82
|
-
export { kvErrorDiagnostics as n, kvConfigErrorCodes as t };
|
package/dist/errors-Dc2oiW-Y.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { n as kvErrorDiagnostics, t as kvConfigErrorCodes } from "./error-diagnostics-D_cQeZTi.js";
|
|
2
|
-
import { isRuntimeDiagnostic, toResultError } from "@vite-hub/runtime";
|
|
3
|
-
//#region src/errors.ts
|
|
4
|
-
function hasCode(error, codes) {
|
|
5
|
-
return codes.some((code) => code === error.code);
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Runs one KV operation and returns `[error, data]`.
|
|
9
|
-
* A KV error with one of `codes` is returned with Runtime's public serializer. A config error is thrown.
|
|
10
|
-
* Any other failure becomes `KV_OPERATION_FAILED` with the failure in `cause`.
|
|
11
|
-
*/
|
|
12
|
-
async function kvResult(operation, store, run, codes = []) {
|
|
13
|
-
try {
|
|
14
|
-
return [void 0, await run()];
|
|
15
|
-
} catch (cause) {
|
|
16
|
-
if (isRuntimeDiagnostic(cause) && kvConfigErrorCodes.has(cause.code)) throw cause;
|
|
17
|
-
if (isRuntimeDiagnostic(cause) && hasCode(cause, codes)) return [toResultError(cause), void 0];
|
|
18
|
-
return [kvErrorDiagnostics.KV_OPERATION_FAILED({
|
|
19
|
-
cause,
|
|
20
|
-
operation,
|
|
21
|
-
store
|
|
22
|
-
}), void 0];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function kvStoreNotFoundError(store) {
|
|
26
|
-
return kvErrorDiagnostics.KV_STORE_NOT_FOUND({ store });
|
|
27
|
-
}
|
|
28
|
-
function kvUnsupportedOperationError(operation, store) {
|
|
29
|
-
return kvErrorDiagnostics.KV_UNSUPPORTED_OPERATION({
|
|
30
|
-
operation,
|
|
31
|
-
store
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
function kvInvalidLimitError() {
|
|
35
|
-
return kvErrorDiagnostics.KV_INVALID_LIMIT();
|
|
36
|
-
}
|
|
37
|
-
//#endregion
|
|
38
|
-
export { kvUnsupportedOperationError as i, kvResult as n, kvStoreNotFoundError as r, kvInvalidLimitError as t };
|
package/dist/fs-lite-CbLKxLut.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { n as kvErrorDiagnostics } from "./error-diagnostics-D_cQeZTi.js";
|
|
2
|
-
import { t as createKVContinuations } from "./continuations-DPyH_vr1.js";
|
|
3
|
-
import { opendir, stat } from "node:fs/promises";
|
|
4
|
-
import { join, relative, resolve, sep } from "node:path";
|
|
5
|
-
import createDriver from "unstorage/drivers/fs-lite";
|
|
6
|
-
//#region src/runtime/fs-lite.ts
|
|
7
|
-
function createFsLiteKVDriver(options) {
|
|
8
|
-
const root = resolve(options.base);
|
|
9
|
-
const driver = createDriver(options);
|
|
10
|
-
const getItem = driver.getItem;
|
|
11
|
-
driver.getItem = async (key, operationOptions) => {
|
|
12
|
-
const value = await getItem(key, operationOptions);
|
|
13
|
-
if (value instanceof Error) {
|
|
14
|
-
if ("code" in value && value.code === "ENOTDIR") return null;
|
|
15
|
-
throw value;
|
|
16
|
-
}
|
|
17
|
-
return value;
|
|
18
|
-
};
|
|
19
|
-
const hasItem = driver.hasItem;
|
|
20
|
-
driver.hasItem = async (key, operationOptions) => {
|
|
21
|
-
if (!await hasItem(key, operationOptions)) return false;
|
|
22
|
-
try {
|
|
23
|
-
return (await stat(join(root, key.replace(/:/g, "/")))).isFile();
|
|
24
|
-
} catch (error) {
|
|
25
|
-
if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) return false;
|
|
26
|
-
throw error;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
const expired = () => kvErrorDiagnostics.KV_INVALID_CURSOR({ problem: "expired" });
|
|
30
|
-
const continuations = createKVContinuations({
|
|
31
|
-
expired,
|
|
32
|
-
release: (iterator) => iterator.return(void 0)
|
|
33
|
-
});
|
|
34
|
-
const dispose = driver.dispose;
|
|
35
|
-
driver.dispose = async () => {
|
|
36
|
-
try {
|
|
37
|
-
await continuations.dispose();
|
|
38
|
-
} finally {
|
|
39
|
-
await dispose?.call(driver);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
driver.listKeys = async ({ cursor, limit, prefix = "" }) => {
|
|
43
|
-
const keys = [];
|
|
44
|
-
async function* walk() {
|
|
45
|
-
const pendingDirectories = [root];
|
|
46
|
-
while (pendingDirectories.length > 0) {
|
|
47
|
-
const directory = pendingDirectories.pop();
|
|
48
|
-
let entries;
|
|
49
|
-
try {
|
|
50
|
-
entries = await opendir(directory);
|
|
51
|
-
} catch (error) {
|
|
52
|
-
if (directory === root && error instanceof Error && "code" in error && error.code === "ENOENT") return;
|
|
53
|
-
if (directory !== root && error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
|
|
54
|
-
yield void 0;
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
throw error;
|
|
58
|
-
}
|
|
59
|
-
for await (const entry of entries) {
|
|
60
|
-
const path = join(directory, entry.name);
|
|
61
|
-
if (entry.isDirectory()) {
|
|
62
|
-
pendingDirectories.push(path);
|
|
63
|
-
yield void 0;
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
yield entry.isFile() ? relative(root, path) : void 0;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
const iterator = cursor ? continuations.take(cursor) : walk();
|
|
71
|
-
if (!iterator) throw expired();
|
|
72
|
-
let scanned = 0;
|
|
73
|
-
while (scanned < limit) {
|
|
74
|
-
const entry = await iterator.next();
|
|
75
|
-
if (entry.done) return { keys };
|
|
76
|
-
scanned++;
|
|
77
|
-
const path = entry.value;
|
|
78
|
-
if (path === void 0) continue;
|
|
79
|
-
const key = path.split(sep).join(":");
|
|
80
|
-
if (key.startsWith(prefix)) keys.push(key);
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
keys,
|
|
84
|
-
cursor: await continuations.retain(iterator)
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
return driver;
|
|
88
|
-
}
|
|
89
|
-
//#endregion
|
|
90
|
-
export { createFsLiteKVDriver as default };
|
package/dist/object-B1NW521B.js
DELETED