@vite-hub/kv 0.1.0 → 0.3.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 +86 -15
- 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 +98 -77
- package/dist/cloudflare-env-lOtHHsgP.js +46 -0
- package/dist/cloudflare-env-lookup-Bs0VDpU5.js +42 -0
- package/dist/cloudflare-kv-BIEUFzRT.js +187 -0
- package/dist/cloudflare-kv-local-BBw3ZT1K.js +71 -0
- package/dist/config-BXEVoZE3.js +250 -0
- package/dist/{create-storage-29gMzf41.js → create-storage-BGsrQKw3.js} +206 -50
- package/dist/{cursor-history-dqYDlsaD.js → cursor-history-BqIQePNP.js} +31 -14
- package/dist/database-72Jk3VVk.js +250 -0
- package/dist/{deno-kv-CSYGvRx4.js → deno-kv-BM9mYdUp.js} +12 -4
- package/dist/dev-peer-CHafxbtj.js +238 -0
- package/dist/driver-BwxgaQ-f.d.ts +15 -0
- package/dist/durability.d.ts +17 -0
- package/dist/durability.js +53 -0
- package/dist/error-diagnostics-BxqvtEIb.js +147 -0
- package/dist/errors-DbwufFZp.js +60 -0
- package/dist/errors.d.ts +12 -1
- package/dist/errors.js +2 -2
- package/dist/fs-lite-BLZId9_P.js +386 -0
- package/dist/fs-lite-RAoxu8L0.js +2 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +302 -75
- package/dist/inspect-BIKQsqX4.js +118 -0
- package/dist/invariant-DolT9EEx.js +22 -0
- package/dist/main-F3Y22_uV.js +2353 -0
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/{operations-tNUdj3G4.d.ts → operation-definition-8gOe-ubD.d.ts} +37 -15
- package/dist/operations-B-WZ7P1h.js +1351 -0
- package/dist/{operations-pn8_eGob.js → operations-Ch-gKaey.js} +67 -58
- package/dist/operations.d.ts +15 -8
- package/dist/operations.js +55 -192
- package/dist/redis-shared-E5mahECF.js +94 -0
- package/dist/rolldown-runtime-CMFfr-1z.js +26 -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 +22 -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 +33 -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-DEiKew_3.d.ts +312 -0
- package/dist/upstash-DDlqTttY.js +40 -0
- package/dist/{utils2-Dsb9P4_2.js → utils2-FozcTsmb.js} +5 -2
- package/dist/virtual-module.d.ts +2 -0
- package/dist/vite.d.ts +152 -11
- package/dist/vite.js +888 -2836
- 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
|
@@ -1,40 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
import "unstorage/drivers/cloudflare-kv-binding";
|
|
3
|
-
import "unstorage/drivers/upstash";
|
|
4
|
-
import "unstorage/drivers/fs-lite";
|
|
5
|
-
import "unstorage/drivers/azure-app-configuration";
|
|
6
|
-
import "unstorage/drivers/azure-cosmos";
|
|
7
|
-
import "unstorage/drivers/azure-key-vault";
|
|
8
|
-
import "unstorage/drivers/azure-storage-blob";
|
|
9
|
-
import "unstorage/drivers/azure-storage-table";
|
|
10
|
-
import "unstorage/drivers/capacitor-preferences";
|
|
11
|
-
import "unstorage/drivers/cloudflare-cache-binding";
|
|
12
|
-
import "unstorage/drivers/cloudflare-kv-http";
|
|
13
|
-
import "unstorage/drivers/cloudflare-r2-binding";
|
|
14
|
-
import "unstorage/drivers/db0";
|
|
15
|
-
import "unstorage/drivers/deno-kv-node";
|
|
16
|
-
import "unstorage/drivers/deno-kv";
|
|
17
|
-
import "unstorage/drivers/fs";
|
|
18
|
-
import "unstorage/drivers/github";
|
|
19
|
-
import "unstorage/drivers/http";
|
|
20
|
-
import "unstorage/drivers/indexedb";
|
|
21
|
-
import "unstorage/drivers/localstorage";
|
|
22
|
-
import "unstorage/drivers/lru-cache";
|
|
23
|
-
import "unstorage/drivers/mongodb";
|
|
24
|
-
import "unstorage/drivers/netlify-blobs";
|
|
25
|
-
import "unstorage/drivers/overlay";
|
|
26
|
-
import "unstorage/drivers/planetscale";
|
|
27
|
-
import "unstorage/drivers/redis";
|
|
28
|
-
import "unstorage/drivers/s3";
|
|
29
|
-
import "unstorage/drivers/session-storage";
|
|
30
|
-
import "unstorage/drivers/uploadthing";
|
|
31
|
-
import "unstorage/drivers/vercel-blob";
|
|
32
|
-
import "unstorage/drivers/vercel-runtime-cache";
|
|
33
|
-
//#region ../../node_modules/.pnpm/unstorage@2.0.0-alpha.10/node_modules/unstorage/dist/_chunks/types.d.mts
|
|
1
|
+
//#region ../../node_modules/.pnpm/unstorage@2.0.0-beta.0/node_modules/unstorage/dist/_chunks/types.d.mts
|
|
34
2
|
type StorageValue = null | string | number | boolean | object;
|
|
35
3
|
type WatchEvent = "update" | "remove";
|
|
36
4
|
type WatchCallback = (event: WatchEvent, key: string) => any;
|
|
37
5
|
type MaybePromise<T> = T | Promise<T>;
|
|
6
|
+
/** Types that {@link Storage.getItem} can convert the stored value to. */
|
|
7
|
+
type GetItemType = keyof GetItemTypeMap;
|
|
8
|
+
interface GetItemTypeMap {
|
|
9
|
+
text: string;
|
|
10
|
+
json: JSONValue;
|
|
11
|
+
bytes: Uint8Array;
|
|
12
|
+
stream: ReadableStream<Uint8Array>;
|
|
13
|
+
blob: Blob;
|
|
14
|
+
}
|
|
15
|
+
type JSONValue = string | number | boolean | null | JSONObject | JSONArray;
|
|
16
|
+
interface JSONObject {
|
|
17
|
+
[key: string]: JSONValue;
|
|
18
|
+
}
|
|
19
|
+
type JSONArray = JSONValue[];
|
|
38
20
|
type Unwatch = () => MaybePromise<void>;
|
|
39
21
|
interface StorageMeta {
|
|
40
22
|
atime?: Date;
|
|
@@ -84,11 +66,4 @@ interface Driver<OptionsT = any, InstanceT = any> {
|
|
|
84
66
|
watch?: (callback: WatchCallback) => MaybePromise<Unwatch>;
|
|
85
67
|
}
|
|
86
68
|
//#endregion
|
|
87
|
-
|
|
88
|
-
type KVRuntimeDriver = Driver & Record<string, unknown> & {
|
|
89
|
-
getAndDeleteItem?: <T = unknown>(key: string) => Promise<T | null>;
|
|
90
|
-
incrementItem?: (key: string, ttl: number) => Promise<number>;
|
|
91
|
-
listKeys: (options: KVListOptions) => Promise<KVListPage>;
|
|
92
|
-
};
|
|
93
|
-
//#endregion
|
|
94
|
-
export { KVRuntimeDriver as t };
|
|
69
|
+
export { TransactionOptions as i, GetItemType as n, GetItemTypeMap as r, Driver as t };
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { n as GetItemType, r as GetItemTypeMap } from "./types-Bj3EQoRg.js";
|
|
2
|
+
import { Result } from "@vite-hub/runtime";
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
type KVDriver = "cloudflare" | "database" | "deno-kv" | "fs-lite" | "redis" | "upstash";
|
|
5
|
+
/**
|
|
6
|
+
* The atomic operations of each driver. A store returns `KV_UNSUPPORTED_OPERATION` for an atomic operation that its
|
|
7
|
+
* driver does not list. `get`, `set`, `delete`, `has`, `keys`, `list`, and `clear` work on every driver.
|
|
8
|
+
*/
|
|
9
|
+
interface KVDriverAtomicOperations {
|
|
10
|
+
"cloudflare": never;
|
|
11
|
+
"database": "deleteIfEquals" | "getAndDelete" | "increment" | "setIfAbsent";
|
|
12
|
+
"deno-kv": "setIfAbsent";
|
|
13
|
+
"fs-lite": "setIfAbsent";
|
|
14
|
+
"redis": "deleteIfEquals" | "getAndDelete" | "increment" | "setIfAbsent";
|
|
15
|
+
"upstash": "deleteIfEquals" | "getAndDelete" | "increment" | "setIfAbsent";
|
|
16
|
+
}
|
|
17
|
+
/** The drivers that run `operation` atomically, for example `KVDriversWith<"deleteIfEquals">`. */
|
|
18
|
+
type KVDriversWith<TOperation extends KVAtomicOperation> = { [Driver in KVDriver]: TOperation extends KVDriverAtomicOperations[Driver] ? Driver : never; }[KVDriver];
|
|
19
|
+
/** The KV operations that need an atomic provider operation. */
|
|
20
|
+
type KVAtomicOperation = "deleteIfEquals" | "getAndDelete" | "increment" | "setIfAbsent";
|
|
21
|
+
interface CloudflareKVStoreConfig {
|
|
22
|
+
driver: "cloudflare";
|
|
23
|
+
binding?: string;
|
|
24
|
+
/**
|
|
25
|
+
* In `vite dev`, use the real namespace: ViteHub writes `remote: true` on the Wrangler binding and does not fall back
|
|
26
|
+
* to the local `fs-lite` store. Writes change real data. Builds ignore it.
|
|
27
|
+
*/
|
|
28
|
+
remote?: boolean;
|
|
29
|
+
/** Cloudflare KV namespace id. When omitted, the build reads the id recorded by `vitehub provision run`. */
|
|
30
|
+
namespaceId?: string;
|
|
31
|
+
/** Cloudflare KV namespace title that `vitehub provision run` finds or creates when `namespaceId` is not set. */
|
|
32
|
+
namespaceName?: string;
|
|
33
|
+
}
|
|
34
|
+
interface UpstashKVStoreConfig {
|
|
35
|
+
driver: "upstash";
|
|
36
|
+
/** An Upstash store is always remote, in `vite dev` too. */
|
|
37
|
+
remote?: true;
|
|
38
|
+
token?: string;
|
|
39
|
+
url?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Prefix of every key in Upstash. Default `vitehub:kv:<store>`, as for a Redis store, so `kv.clear()` and `kv.keys()`
|
|
42
|
+
* stay inside the store. An empty value uses the default.
|
|
43
|
+
*/
|
|
44
|
+
base?: string;
|
|
45
|
+
}
|
|
46
|
+
interface RedisKVStoreConfig {
|
|
47
|
+
driver: "redis";
|
|
48
|
+
/**
|
|
49
|
+
* The Redis URL, such as `redis://user:password@host:6379`. Default `env:REDIS_URL`: the server reads `REDIS_URL`
|
|
50
|
+
* when the store starts, not at build time. `env:<NAME>` reads another variable. A literal URL goes into the build
|
|
51
|
+
* output, so keep passwords in a variable.
|
|
52
|
+
*/
|
|
53
|
+
url?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Prefix of every key in Redis. Default `vitehub:kv:<store>`, which keeps keys that are not ViteHub's apart.
|
|
56
|
+
* The generated store segment escapes `%`, `:`, `/`, `\`, and `?`; an empty store name uses `%`.
|
|
57
|
+
* Two ViteHub apps on one Redis database share this default, so give each app its own database or `base`.
|
|
58
|
+
* An empty value uses the default.
|
|
59
|
+
*/
|
|
60
|
+
base?: string;
|
|
61
|
+
/** A Redis store uses the server that `url` points to, in `vite dev` too. */
|
|
62
|
+
remote?: never;
|
|
63
|
+
}
|
|
64
|
+
interface DatabaseKVStoreConfig {
|
|
65
|
+
driver: "database";
|
|
66
|
+
/**
|
|
67
|
+
* The Database that keeps the keys, in the table `vitehub_kv`. Default `"default"`. The store creates the table when
|
|
68
|
+
* it is missing. Postgres and libSQL work. D1 does not.
|
|
69
|
+
*/
|
|
70
|
+
database?: string;
|
|
71
|
+
/** A Database store uses the Database of the app, in `vite dev` too. */
|
|
72
|
+
remote?: never;
|
|
73
|
+
}
|
|
74
|
+
interface DenoKVStoreConfig {
|
|
75
|
+
driver: "deno-kv";
|
|
76
|
+
path?: string;
|
|
77
|
+
/** A Deno KV store is local. */
|
|
78
|
+
remote?: false;
|
|
79
|
+
}
|
|
80
|
+
interface FsLiteKVStoreConfig {
|
|
81
|
+
driver: "fs-lite";
|
|
82
|
+
base?: string;
|
|
83
|
+
/** An `fs-lite` store is local. */
|
|
84
|
+
remote?: false;
|
|
85
|
+
}
|
|
86
|
+
/** A store without `driver`. ViteHub infers the driver from the host and the env. */
|
|
87
|
+
interface InferredKVStoreConfig {
|
|
88
|
+
driver?: undefined;
|
|
89
|
+
/**
|
|
90
|
+
* In `vite dev`, the inferred store is local unless this is `true`: Upstash env and the Vercel host do not select
|
|
91
|
+
* Upstash, and the Cloudflare host uses the local `fs-lite` store when the dev runtime has no KV binding. With
|
|
92
|
+
* `true`, `vite dev` uses the real store, so writes change real data. Builds ignore it.
|
|
93
|
+
*/
|
|
94
|
+
remote?: boolean;
|
|
95
|
+
}
|
|
96
|
+
type KVStoreConfig = CloudflareKVStoreConfig | DatabaseKVStoreConfig | DenoKVStoreConfig | FsLiteKVStoreConfig | RedisKVStoreConfig | UpstashKVStoreConfig;
|
|
97
|
+
interface ResolvedCloudflareKVStoreConfig extends CloudflareKVStoreConfig {
|
|
98
|
+
binding: string;
|
|
99
|
+
/** Only in `vite dev`: the `fs-lite` directory that the store uses when the runtime has no binding. */
|
|
100
|
+
localBase?: string;
|
|
101
|
+
/** Only in `vite dev`. */
|
|
102
|
+
remote?: true;
|
|
103
|
+
}
|
|
104
|
+
interface ResolvedUpstashKVStoreConfig extends UpstashKVStoreConfig {
|
|
105
|
+
base: string;
|
|
106
|
+
token: string;
|
|
107
|
+
url: string;
|
|
108
|
+
}
|
|
109
|
+
interface ResolvedDenoKVStoreConfig extends DenoKVStoreConfig {
|
|
110
|
+
path?: string;
|
|
111
|
+
}
|
|
112
|
+
interface ResolvedFsLiteKVStoreConfig extends FsLiteKVStoreConfig {
|
|
113
|
+
base: string;
|
|
114
|
+
/** {@link ResolvedDatabaseKVStoreConfig.inferred} */
|
|
115
|
+
inferred?: true;
|
|
116
|
+
}
|
|
117
|
+
interface ResolvedRedisKVStoreConfig extends RedisKVStoreConfig {
|
|
118
|
+
base: string;
|
|
119
|
+
url: string;
|
|
120
|
+
}
|
|
121
|
+
interface ResolvedDatabaseKVStoreConfig extends DatabaseKVStoreConfig {
|
|
122
|
+
database: string;
|
|
123
|
+
/** The value of the `namespace` column for the keys of this store: the store name. */
|
|
124
|
+
namespace: string;
|
|
125
|
+
/**
|
|
126
|
+
* The build inferred this store on Node. The server keeps this driver regardless of `REDIS_URL`.
|
|
127
|
+
*/
|
|
128
|
+
inferred?: true;
|
|
129
|
+
}
|
|
130
|
+
type ResolvedKVStoreConfig = ResolvedCloudflareKVStoreConfig | ResolvedDatabaseKVStoreConfig | ResolvedDenoKVStoreConfig | ResolvedFsLiteKVStoreConfig | ResolvedRedisKVStoreConfig | ResolvedUpstashKVStoreConfig;
|
|
131
|
+
type KVStoreName = "default" | (string & {});
|
|
132
|
+
interface KVStoresConfig {
|
|
133
|
+
stores: Record<string, KVStoreConfig>;
|
|
134
|
+
}
|
|
135
|
+
type KVOptions = KVStoreConfig | InferredKVStoreConfig | KVStoresConfig | false;
|
|
136
|
+
interface ResolvedKVModuleOptions {
|
|
137
|
+
store: ResolvedKVStoreConfig;
|
|
138
|
+
stores?: Record<string, ResolvedKVStoreConfig>;
|
|
139
|
+
}
|
|
140
|
+
type KVOperation = "clear" | "delete" | "deleteIfEquals" | "get" | "getAndDelete" | "getMany" | "has" | "increment" | "keys" | "list" | "lock" | "set" | "setIfAbsent" | "setMany";
|
|
141
|
+
/** Codes that KV operations return in the `[error, data]` tuple. Config errors throw instead. */
|
|
142
|
+
type KVErrorCode = "KV_INVALID_CURSOR" | "KV_INVALID_LIMIT" | "KV_INVALID_OPTION" | "KV_INVALID_TTL" | "KV_INVALID_VALUE" | "KV_INVALID_WAIT" | "KV_KEY_TOO_LONG" | "KV_OPERATION_FAILED" | "KV_UNSUPPORTED_OPERATION" | "KV_VALUE_TOO_LARGE";
|
|
143
|
+
interface KVListOptions {
|
|
144
|
+
/** Opaque continuation cursor returned by a previous page. */
|
|
145
|
+
cursor?: string;
|
|
146
|
+
/** Maximum number of keys to read. Must be a positive integer. */
|
|
147
|
+
limit: number;
|
|
148
|
+
prefix?: string;
|
|
149
|
+
}
|
|
150
|
+
/** What `kv.get()` converts the stored value to: `text`, `json`, `bytes`, `stream`, or `blob`. */
|
|
151
|
+
type KVGetType = GetItemType;
|
|
152
|
+
/** The value type `kv.get()` returns for each {@link KVGetType}. */
|
|
153
|
+
type KVGetTypeMap = GetItemTypeMap;
|
|
154
|
+
/** Options of `kv.get()`. Other fields go to the driver. */
|
|
155
|
+
type KVGetOptions<K extends KVGetType | undefined = KVGetType | undefined> = Record<string, unknown> & {
|
|
156
|
+
type?: K;
|
|
157
|
+
};
|
|
158
|
+
/** A read value: the caller's `T` without a `type`, the converted type with one. */
|
|
159
|
+
type KVValue<T, K> = K extends KVGetType ? KVGetTypeMap[K] : T;
|
|
160
|
+
/** Options of `kv.set()`, `kv.setMany()`, and `kv.setIfAbsent()`. Other fields return `KV_INVALID_OPTION`. */
|
|
161
|
+
interface KVSetOptions {
|
|
162
|
+
/** Seconds until the key expires, a positive number. Every driver expires the key. Cloudflare KV keeps it at least 60 seconds. */
|
|
163
|
+
ttl?: number;
|
|
164
|
+
}
|
|
165
|
+
/** Options of `kv.lock()`. */
|
|
166
|
+
interface KVLockOptions {
|
|
167
|
+
/**
|
|
168
|
+
* Seconds until the lock expires, so a crashed holder never keeps it. Pick a value longer than the work.
|
|
169
|
+
* KV does not renew a lock: when the work runs longer than `ttl`, another runner can take the lock.
|
|
170
|
+
*/
|
|
171
|
+
ttl: number;
|
|
172
|
+
/** Seconds to wait for a held lock, polling with backoff. Default `0`: return `{ acquired: false }` at once. */
|
|
173
|
+
wait?: number;
|
|
174
|
+
}
|
|
175
|
+
/** Codes that `kv.lock().run()` and `kv.lock().acquire()` return. */
|
|
176
|
+
type KVLockErrorCode = "KV_INVALID_TTL" | "KV_INVALID_WAIT" | "KV_OPERATION_FAILED" | "KV_UNSUPPORTED_OPERATION";
|
|
177
|
+
/** The data of `kv.lock().run()`: the callback's value, or `acquired: false` when another runner held the lock. */
|
|
178
|
+
type KVLockRunResult<T> = {
|
|
179
|
+
acquired: true;
|
|
180
|
+
value: T;
|
|
181
|
+
} | {
|
|
182
|
+
acquired: false;
|
|
183
|
+
};
|
|
184
|
+
/** The data of `kv.lock().acquire()`. */
|
|
185
|
+
type KVLockAcquisition = {
|
|
186
|
+
acquired: true;
|
|
187
|
+
/**
|
|
188
|
+
* Deletes the lock only when this runner still holds it. Returns `true` when it deleted the lock and `false` when
|
|
189
|
+
* the lock had expired, so another runner can hold it now.
|
|
190
|
+
*/
|
|
191
|
+
release(): Promise<Result<boolean, "KV_OPERATION_FAILED">>;
|
|
192
|
+
} | {
|
|
193
|
+
acquired: false;
|
|
194
|
+
};
|
|
195
|
+
/** A lock on one key. Create it with `kv.lock(key, options)`. */
|
|
196
|
+
interface KVLock {
|
|
197
|
+
/**
|
|
198
|
+
* Takes the lock, runs `fn`, and releases the lock, also when `fn` throws. An error from `fn` is thrown again after
|
|
199
|
+
* the release. Returns `{ acquired: false }` without calling `fn` when another runner holds the lock after `wait`.
|
|
200
|
+
* A release that fails returns `KV_OPERATION_FAILED` after `fn` ran; the lock then expires after `ttl`.
|
|
201
|
+
*/
|
|
202
|
+
run<T>(fn: () => T): Promise<Result<KVLockRunResult<Awaited<T>>, KVLockErrorCode>>;
|
|
203
|
+
/** Takes the lock and returns a `release()` function. Prefer `run()`, which always releases. */
|
|
204
|
+
acquire(): Promise<Result<KVLockAcquisition, KVLockErrorCode>>;
|
|
205
|
+
}
|
|
206
|
+
/** One entry of `kv.setMany()`. */
|
|
207
|
+
interface KVEntry<T = unknown> {
|
|
208
|
+
key: string;
|
|
209
|
+
value: T;
|
|
210
|
+
}
|
|
211
|
+
interface KVListPage {
|
|
212
|
+
/** Provider-ordered keys. */
|
|
213
|
+
keys: string[];
|
|
214
|
+
/** Omitted when enumeration is complete. */
|
|
215
|
+
cursor?: string;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Each method returns `[error, data]`. `error.code` is one of the codes in the method type.
|
|
219
|
+
* Config errors, for example an unknown store name, throw.
|
|
220
|
+
*/
|
|
221
|
+
interface KVStorage {
|
|
222
|
+
clear(base?: string, options?: unknown): Promise<Result<void, "KV_OPERATION_FAILED">>;
|
|
223
|
+
delete(key: string, options?: unknown): Promise<Result<void, "KV_KEY_TOO_LONG" | "KV_OPERATION_FAILED">>;
|
|
224
|
+
/**
|
|
225
|
+
* Deletes the key only when its value equals `expected`, in one atomic step. Returns `true` when this call deleted it.
|
|
226
|
+
* KV compares the stored text with `expected` serialized as `set()` stores it, so `{ a: 1, b: 2 }` and
|
|
227
|
+
* `{ b: 2, a: 1 }` are different values. Use it to free a token that only its owner may free.
|
|
228
|
+
* The drivers in {@link KVDriversWith}`<"deleteIfEquals">` support it. The others return `KV_UNSUPPORTED_OPERATION`.
|
|
229
|
+
*/
|
|
230
|
+
deleteIfEquals<T = unknown>(key: string, expected: T): Promise<Result<boolean, "KV_INVALID_VALUE" | "KV_OPERATION_FAILED" | "KV_UNSUPPORTED_OPERATION">>;
|
|
231
|
+
/**
|
|
232
|
+
* Reads a value or returns `null`. Without `options.type`, a string value is parsed as JSON, so `"123"` reads back as `123`.
|
|
233
|
+
* `{ type: "text" }` returns the stored text, and `json`, `bytes`, `stream`, and `blob` convert it to that type.
|
|
234
|
+
*/
|
|
235
|
+
get<T = unknown, K extends KVGetType | undefined = undefined>(key: string, options?: KVGetOptions<K>): Promise<Result<KVValue<T, K> | null, "KV_KEY_TOO_LONG" | "KV_OPERATION_FAILED">>;
|
|
236
|
+
/**
|
|
237
|
+
* Reads many keys in one call. Returns one value per key, in the order of `keys`, with `null` for a missing key.
|
|
238
|
+
* `options` works as in `get()` and applies to every key. Stores with a batch read use it: Cloudflare KV reads 100
|
|
239
|
+
* keys per call, Redis and Upstash use `MGET`, and the `database` driver runs one query. Other stores read the keys
|
|
240
|
+
* one by one, 16 at a time.
|
|
241
|
+
*/
|
|
242
|
+
getMany<T = unknown, K extends KVGetType | undefined = undefined>(keys: readonly string[], options?: KVGetOptions<K>): Promise<Result<Array<KVValue<T, K> | null>, "KV_KEY_TOO_LONG" | "KV_OPERATION_FAILED">>;
|
|
243
|
+
/**
|
|
244
|
+
* Atomically returns and deletes a value. `{ type: "text" }` returns the stored text.
|
|
245
|
+
* The drivers in {@link KVDriversWith}`<"getAndDelete">` support it. The others return `KV_UNSUPPORTED_OPERATION`.
|
|
246
|
+
*/
|
|
247
|
+
getAndDelete<T = unknown, K extends "text" | undefined = undefined>(key: string, options?: {
|
|
248
|
+
type?: K;
|
|
249
|
+
}): Promise<Result<KVValue<T, K> | null, "KV_OPERATION_FAILED" | "KV_UNSUPPORTED_OPERATION">>;
|
|
250
|
+
has(key: string, options?: unknown): Promise<Result<boolean, "KV_KEY_TOO_LONG" | "KV_OPERATION_FAILED">>;
|
|
251
|
+
/**
|
|
252
|
+
* Atomically increments a counter. The TTL is applied only when the counter is created.
|
|
253
|
+
* The drivers in {@link KVDriversWith}`<"increment">` support it. The others return `KV_UNSUPPORTED_OPERATION`.
|
|
254
|
+
*/
|
|
255
|
+
increment(key: string, ttl: number): Promise<Result<number, "KV_INVALID_TTL" | "KV_OPERATION_FAILED" | "KV_UNSUPPORTED_OPERATION">>;
|
|
256
|
+
keys(base?: string, options?: unknown): Promise<Result<string[], "KV_OPERATION_FAILED">>;
|
|
257
|
+
list(options: KVListOptions): Promise<Result<KVListPage, "KV_INVALID_CURSOR" | "KV_INVALID_LIMIT" | "KV_OPERATION_FAILED">>;
|
|
258
|
+
/**
|
|
259
|
+
* A lock on `key` that one runner holds at a time, across server processes that share the store. It writes a random
|
|
260
|
+
* owner token with `setIfAbsent()` and a TTL, and frees it with `deleteIfEquals()`, so a runner never deletes a lock
|
|
261
|
+
* that another runner took after it expired. Nothing renews a lock.
|
|
262
|
+
* The drivers in {@link KVDriversWith}`<"deleteIfEquals">` support it. The others return `KV_UNSUPPORTED_OPERATION`.
|
|
263
|
+
*/
|
|
264
|
+
lock(key: string, options: KVLockOptions): KVLock;
|
|
265
|
+
/**
|
|
266
|
+
* Writes a value. `{ ttl }` expires it after that many seconds; without `ttl`, the value stays until you delete or replace it.
|
|
267
|
+
* Cloudflare KV stores return `KV_KEY_TOO_LONG` and `KV_VALUE_TOO_LARGE` before a write that Cloudflare rejects.
|
|
268
|
+
*/
|
|
269
|
+
set<T = unknown>(key: string, value: T, options?: KVSetOptions): Promise<Result<void, "KV_INVALID_OPTION" | "KV_INVALID_TTL" | "KV_KEY_TOO_LONG" | "KV_OPERATION_FAILED" | "KV_VALUE_TOO_LARGE">>;
|
|
270
|
+
/**
|
|
271
|
+
* Writes many keys in one call. `options` works as in `set()` and applies to every entry. When a key is in `entries`
|
|
272
|
+
* more than once, the last entry wins. A `value` of `undefined` deletes the key, as `set()` does. The writes are not
|
|
273
|
+
* atomic: when the call fails, some entries can be written. Redis sends one pipeline and the `database` driver runs one
|
|
274
|
+
* statement. Other stores write the entries one by one, 16 at a time. A Cloudflare KV store checks every entry against
|
|
275
|
+
* the Workers KV limits before it writes any.
|
|
276
|
+
*/
|
|
277
|
+
setMany<T = unknown>(entries: readonly KVEntry<T>[], options?: KVSetOptions): Promise<Result<void, "KV_INVALID_OPTION" | "KV_INVALID_TTL" | "KV_KEY_TOO_LONG" | "KV_OPERATION_FAILED" | "KV_VALUE_TOO_LARGE">>;
|
|
278
|
+
/**
|
|
279
|
+
* Writes the value only when the key has no value, in one atomic step.
|
|
280
|
+
* Returns `true` when this call wrote the value and `false` when the key already had one.
|
|
281
|
+
* The drivers in {@link KVDriversWith}`<"setIfAbsent">` support it. Cloudflare KV is eventually consistent and returns
|
|
282
|
+
* `KV_UNSUPPORTED_OPERATION`.
|
|
283
|
+
*/
|
|
284
|
+
setIfAbsent<T = unknown>(key: string, value: T, options?: KVSetOptions): Promise<Result<boolean, "KV_INVALID_OPTION" | "KV_INVALID_TTL" | "KV_INVALID_VALUE" | "KV_OPERATION_FAILED" | "KV_UNSUPPORTED_OPERATION">>;
|
|
285
|
+
/** Selects a named KV store. `{ mode: "read" }` returns a handle without write methods. */
|
|
286
|
+
store(name: KVStoreName, options?: {
|
|
287
|
+
mode?: "write";
|
|
288
|
+
}): KVStorage;
|
|
289
|
+
store(name: KVStoreName, options: {
|
|
290
|
+
mode: "read";
|
|
291
|
+
}): ReadonlyKVStorage;
|
|
292
|
+
store(name: KVStoreName, options?: KVStoreOptions): KVStorage | ReadonlyKVStorage;
|
|
293
|
+
}
|
|
294
|
+
/** Options of `kv.store()`. */
|
|
295
|
+
interface KVStoreOptions {
|
|
296
|
+
/** `"read"` returns a handle without write methods. Defaults to `"write"`. */
|
|
297
|
+
mode?: "read" | "write";
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* KV handle from `kv.store(name, { mode: "read" })`, with only `get()`, `getMany()`, `has()`, `keys()`, and `list()`.
|
|
301
|
+
* It limits this API, not the host: the KV binding or provider token keeps full access, so it is not a security
|
|
302
|
+
* boundary against code that reads the binding directly.
|
|
303
|
+
*/
|
|
304
|
+
interface ReadonlyKVStorage {
|
|
305
|
+
get: KVStorage["get"];
|
|
306
|
+
getMany: KVStorage["getMany"];
|
|
307
|
+
has: KVStorage["has"];
|
|
308
|
+
keys: KVStorage["keys"];
|
|
309
|
+
list: KVStorage["list"];
|
|
310
|
+
}
|
|
311
|
+
//#endregion
|
|
312
|
+
export { RedisKVStoreConfig as A, KVOptions as C, KVStoreName as D, KVStoreConfig as E, ResolvedKVModuleOptions as F, ResolvedKVStoreConfig as I, ResolvedRedisKVStoreConfig as L, ResolvedDatabaseKVStoreConfig as M, ResolvedDenoKVStoreConfig as N, KVStoreOptions as O, ResolvedFsLiteKVStoreConfig as P, ResolvedUpstashKVStoreConfig as R, KVOperation as S, KVStorage as T, KVLock as _, InferredKVStoreConfig as a, KVLockOptions as b, KVDriverAtomicOperations as c, KVErrorCode as d, KVGetOptions as f, KVListPage as g, KVListOptions as h, FsLiteKVStoreConfig as i, ResolvedCloudflareKVStoreConfig as j, ReadonlyKVStorage as k, KVDriversWith as l, KVGetTypeMap as m, DatabaseKVStoreConfig as n, KVAtomicOperation as o, KVGetType as p, DenoKVStoreConfig as r, KVDriver as s, CloudflareKVStoreConfig as t, KVEntry as u, KVLockAcquisition as v, KVSetOptions as w, KVLockRunResult as x, KVLockErrorCode as y, UpstashKVStoreConfig as z };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-BxqvtEIb.js";
|
|
2
|
+
import { a as upstashUrlEnvNames, i as upstashTokenEnvNames, s as readEnv } from "./config-BXEVoZE3.js";
|
|
3
|
+
//#region src/runtime/upstash.ts
|
|
4
|
+
function isMaskedValue(value) {
|
|
5
|
+
return !value || /^\*+$/.test(value);
|
|
6
|
+
}
|
|
7
|
+
function assertRuntimeValue(value, envNames) {
|
|
8
|
+
if (isMaskedValue(value)) {
|
|
9
|
+
const names = envNames.map((name) => `\`${name}\``).join(" or ");
|
|
10
|
+
throw kvErrorDiagnostics.KV_MISSING_ENV({
|
|
11
|
+
driver: "upstash",
|
|
12
|
+
names
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** Fills credentials without validating them, so development still reports missing env on the first operation. */
|
|
17
|
+
function resolveUpstashRuntimeValues(config, env) {
|
|
18
|
+
const completeEnvPair = upstashUrlEnvNames.map((urlName, index) => [readEnv(env, urlName), readEnv(env, upstashTokenEnvNames[index])]).find(([url, token]) => url && token);
|
|
19
|
+
const envUrl = readEnv(env, ...upstashUrlEnvNames);
|
|
20
|
+
const envToken = readEnv(env, ...upstashTokenEnvNames);
|
|
21
|
+
const hasMaskedPair = isMaskedValue(config.url) && isMaskedValue(config.token);
|
|
22
|
+
const resolveMaskedValue = (value, pairValue, fallback) => isMaskedValue(value) ? pairValue || fallback || value || "********" : value ?? "********";
|
|
23
|
+
return {
|
|
24
|
+
...config,
|
|
25
|
+
token: resolveMaskedValue(config.token, completeEnvPair?.[1], hasMaskedPair ? void 0 : envToken),
|
|
26
|
+
url: resolveMaskedValue(config.url, completeEnvPair?.[0], hasMaskedPair ? void 0 : envUrl)
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function resolveRuntimeKVOptions(config, env = process.env) {
|
|
30
|
+
if (!config || config.store.driver !== "upstash") return config;
|
|
31
|
+
const store = resolveUpstashRuntimeValues(config.store, env);
|
|
32
|
+
assertRuntimeValue(store.url, upstashUrlEnvNames);
|
|
33
|
+
assertRuntimeValue(store.token, upstashTokenEnvNames);
|
|
34
|
+
return {
|
|
35
|
+
...config,
|
|
36
|
+
store
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { resolveUpstashRuntimeValues as n, resolveRuntimeKVOptions as t };
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/unstorage@2.0.0-
|
|
1
|
+
//#region ../../node_modules/.pnpm/unstorage@2.0.0-beta.0/node_modules/unstorage/dist/_chunks/utils2.mjs
|
|
2
2
|
function normalizeKey(key) {
|
|
3
3
|
if (!key) return "";
|
|
4
4
|
return key.split("?")[0]?.replace(/[/\\]/g, ":").replace(/:+/g, ":").replace(/^:|:$/g, "") || "";
|
|
5
5
|
}
|
|
6
|
+
function hasDotSegment(key) {
|
|
7
|
+
return key.split(":").some((segment) => segment === "." || segment === "..");
|
|
8
|
+
}
|
|
6
9
|
function joinKeys(...keys) {
|
|
7
10
|
return normalizeKey(keys.join(":"));
|
|
8
11
|
}
|
|
@@ -25,4 +28,4 @@ function filterKeyByBase(key, base) {
|
|
|
25
28
|
return key[key.length - 1] !== "$";
|
|
26
29
|
}
|
|
27
30
|
//#endregion
|
|
28
|
-
export {
|
|
31
|
+
export { normalizeBaseKey as a, joinKeys as i, filterKeyByDepth as n, normalizeKey as o, hasDotSegment as r, filterKeyByBase as t };
|
package/dist/virtual-module.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
declare module "#vitehub/kv/config" {
|
|
2
2
|
export const hosting: string | undefined
|
|
3
3
|
export const kv: false | import("./index.js").ResolvedKVModuleOptions
|
|
4
|
+
/** Loads the databases of the app. Set when a store uses the `database` driver. */
|
|
5
|
+
export const loadDatabases: (() => Promise<Record<string, { db: object } | undefined>>) | undefined
|
|
4
6
|
const config: { hosting?: string, kv: typeof kv }
|
|
5
7
|
export default config
|
|
6
8
|
}
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as ViteHubCliPluginMetadata } from "./cli-
|
|
3
|
-
import { n as OperationContributionEntry } from "./
|
|
1
|
+
import { C as KVOptions, F as ResolvedKVModuleOptions } from "./types-DEiKew_3.js";
|
|
2
|
+
import { r as ViteHubCliPluginMetadata } from "./cli-DpPhz_Ek.js";
|
|
3
|
+
import { n as OperationContributionEntry } from "./operation-definition-8gOe-ubD.js";
|
|
4
4
|
import { Plugin } from "vite";
|
|
5
5
|
//#region src/config.d.ts
|
|
6
6
|
interface KVResolutionInput {
|
|
7
|
+
/**
|
|
8
|
+
* `vite dev`. A store is then local unless it sets `remote: true`: inference never selects Upstash, and a Cloudflare
|
|
9
|
+
* store falls back to `fs-lite` when the runtime has no binding. Builds leave it unset.
|
|
10
|
+
*/
|
|
11
|
+
dev?: boolean;
|
|
7
12
|
env?: Record<string, string | undefined>;
|
|
8
13
|
hosting?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The app has a Default Database on Postgres. A build without a KV driver then infers the `database` driver on Node.
|
|
16
|
+
* The KV Vite plugin finds it in the Database Definitions.
|
|
17
|
+
*/
|
|
18
|
+
postgresDatabase?: boolean;
|
|
9
19
|
}
|
|
10
20
|
//#endregion
|
|
11
21
|
//#region src/vite-config.d.ts
|
|
@@ -15,10 +25,137 @@ interface KVViteRuntimeConfig {
|
|
|
15
25
|
hosting?: string;
|
|
16
26
|
kv: false | ResolvedKVModuleOptions;
|
|
17
27
|
}
|
|
18
|
-
export declare function resolveKVViteConfig(kv:
|
|
28
|
+
export declare function resolveKVViteConfig(kv: KVOptions | undefined, input?: KVResolutionInput): KVViteRuntimeConfig;
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region ../internal/src/deployment.d.ts
|
|
31
|
+
/** The host that ViteHub builds for: the `host` option of `vitehub()` and the value of `VITEHUB_HOST`. */
|
|
32
|
+
type ViteHubHost = "cloudflare" | "deno" | "netlify" | "node" | "vercel";
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region ../internal/src/inspect.d.ts
|
|
35
|
+
interface ViteHubDefinitionField {
|
|
36
|
+
label: string;
|
|
37
|
+
value: string;
|
|
38
|
+
}
|
|
39
|
+
/** Serializable summary of one discovered Definition. Files are relative to the project root. */
|
|
40
|
+
interface ViteHubDefinitionSummary {
|
|
41
|
+
fields: readonly ViteHubDefinitionField[];
|
|
42
|
+
file: string;
|
|
43
|
+
name: string;
|
|
44
|
+
source: string;
|
|
45
|
+
}
|
|
46
|
+
/** Lists the Definitions that one owner package discovered for the resolved Vite config. */
|
|
47
|
+
interface ViteHubDefinitionInspector {
|
|
48
|
+
/** Stable singular kind, for example `queue` or `rate-limit`. */
|
|
49
|
+
kind: string;
|
|
50
|
+
label: string;
|
|
51
|
+
list: () => Promise<readonly ViteHubDefinitionSummary[]> | readonly ViteHubDefinitionSummary[];
|
|
52
|
+
}
|
|
53
|
+
/** One generated Provider Output file or directory that an owner package can write. */
|
|
54
|
+
interface ViteHubProviderOutputEntry {
|
|
55
|
+
description: string;
|
|
56
|
+
owner: string;
|
|
57
|
+
/** Absolute path. */
|
|
58
|
+
path: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Where an inspected resource id came from. `name` means the host binds the resource by its name and needs no id.
|
|
62
|
+
* The CLI sets `provider-output` when only a generated Wrangler config names the id.
|
|
63
|
+
*/
|
|
64
|
+
type ViteHubResourceIdSource = "config" | "env" | "name" | "provider-output" | "provision-state";
|
|
65
|
+
/** One host resource that a Definition or store maps to. Owner packages read only local config and Provision State. */
|
|
66
|
+
interface ViteHubResourceSummary {
|
|
67
|
+
/** Cloudflare binding name, so the CLI can find the id in generated Wrangler config. */
|
|
68
|
+
binding?: string;
|
|
69
|
+
/** Definition or store name. */
|
|
70
|
+
definition: string;
|
|
71
|
+
/** Env variable that supplied the id when `source` is `env`. */
|
|
72
|
+
env?: string;
|
|
73
|
+
host: "cloudflare" | "vercel";
|
|
74
|
+
id?: string;
|
|
75
|
+
/** Same resource kind names as Provision actions, for example `cloudflare-d1`. */
|
|
76
|
+
kind: string;
|
|
77
|
+
/** Resource name on the host, when the config names it. */
|
|
78
|
+
name?: string;
|
|
79
|
+
/** Explains how the host finds the resource when no id or name is known locally. */
|
|
80
|
+
note?: string;
|
|
81
|
+
owner: string;
|
|
82
|
+
/** Absent when no id is known yet. */
|
|
83
|
+
source?: ViteHubResourceIdSource;
|
|
84
|
+
}
|
|
85
|
+
interface ViteHubInspectionContributor {
|
|
86
|
+
definitions?: readonly ViteHubDefinitionInspector[];
|
|
87
|
+
providerOutput?: readonly ViteHubProviderOutputEntry[];
|
|
88
|
+
resources?: () => readonly ViteHubResourceSummary[] | Promise<readonly ViteHubResourceSummary[]>;
|
|
89
|
+
}
|
|
90
|
+
type ViteHubInspectionContributorFactory = () => ViteHubInspectionContributor | undefined | Promise<ViteHubInspectionContributor | undefined>;
|
|
91
|
+
interface ViteHubInspectionPluginMetadata {
|
|
92
|
+
inspect?: ViteHubInspectionContributor | ViteHubInspectionContributorFactory;
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region ../internal/src/build/deployment-plan-output.d.ts
|
|
96
|
+
/**
|
|
97
|
+
* One set of host variables that the deployed app reads, as `deployment.json` lists it: a Server Env declaration, or
|
|
98
|
+
* a variable that a primitive reads itself, such as `VITEHUB_SECRET` or `BLOB_READ_WRITE_TOKEN`.
|
|
99
|
+
* It holds names only, so `vitehub deploy` can check the host without booting Vite. It never holds a value.
|
|
100
|
+
*/
|
|
101
|
+
interface DeploymentEnvEntry {
|
|
102
|
+
/** The declaration path, such as `env.server.github.token`, when it is safe to show. Primitive entries have none. */
|
|
103
|
+
path?: string;
|
|
104
|
+
/** The host variable names, in read order. The first name that is set supplies the value. */
|
|
105
|
+
names: readonly string[];
|
|
106
|
+
/** Any variable whose name starts with this prefix supplies the value, such as `VITEHUB_CONSOLE_KEY_`. */
|
|
107
|
+
prefix?: string;
|
|
108
|
+
required: boolean;
|
|
109
|
+
secret: boolean;
|
|
110
|
+
/** A default supplies the value when no name is set. */
|
|
111
|
+
hasDefault: boolean;
|
|
112
|
+
/** The primitives that read these names, such as `blob`. Server Env declarations have none. */
|
|
113
|
+
owners?: readonly string[];
|
|
114
|
+
}
|
|
115
|
+
/** What a primitive needs to know to name the variables it reads in the deployed app. */
|
|
116
|
+
interface DeploymentEnvContext {
|
|
117
|
+
host: ViteHubHost;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The host variables that a primitive reads itself, outside the Server Env registry, for one host and its resolved
|
|
121
|
+
* config. A Vite plugin exposes it as `api.deploymentEnv`, and the build writes the result to `deployment.json`.
|
|
122
|
+
* Return names only, never values.
|
|
123
|
+
*/
|
|
124
|
+
type DeploymentEnvContribution = (context: DeploymentEnvContext) => readonly DeploymentEnvEntry[];
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region ../internal/src/durability.d.ts
|
|
127
|
+
/**
|
|
128
|
+
* One durability reporter that a primitive's Vite plugin contributes through `vitehub.durability`. The Node server
|
|
129
|
+
* imports `export` from `module` at boot and calls it with `input` and the server environment. It returns the
|
|
130
|
+
* `Durability` lines of `@vite-hub/runtime/durability`.
|
|
131
|
+
*/
|
|
132
|
+
interface DurabilityContribution {
|
|
133
|
+
/** The primitive that the reporter describes, such as `kv`. Other reporters find its result by this id. */
|
|
134
|
+
primitive: string;
|
|
135
|
+
/** The absolute file of the reporter module. */
|
|
136
|
+
module: string;
|
|
137
|
+
export: string;
|
|
138
|
+
/**
|
|
139
|
+
* The resolved configuration of the primitive, as plain JSON data. The build writes it into the server with
|
|
140
|
+
* `JSON.stringify`, so do not put credentials here.
|
|
141
|
+
*/
|
|
142
|
+
input: unknown;
|
|
143
|
+
}
|
|
144
|
+
/** The `vitehub.durability` field of a primitive's Vite plugin. */
|
|
145
|
+
interface DurabilityPluginMetadata {
|
|
146
|
+
/** Called after Vite resolves the config. Return an empty list when the primitive is off. */
|
|
147
|
+
durability?: () => readonly DurabilityContribution[];
|
|
148
|
+
}
|
|
19
149
|
//#endregion
|
|
20
150
|
//#region src/vite.d.ts
|
|
151
|
+
/**
|
|
152
|
+
* File path of the unstorage driver over a KV store. Options: `store` (default: the default store) and `base` (a key prefix).
|
|
153
|
+
* ViteHub mounts it at `kv`, `kv-<store>`, and, with `cache: { driver: "kv" }`, at `cache`.
|
|
154
|
+
*/
|
|
155
|
+
export declare const kvStorageDriver: string;
|
|
21
156
|
export interface KVVitePluginAPI {
|
|
157
|
+
/** The variables that the KV stores read on the deployed host. See `kvDeploymentEnv()`. */
|
|
158
|
+
deploymentEnv: DeploymentEnvContribution;
|
|
22
159
|
getConfig: () => KVViteRuntimeConfig;
|
|
23
160
|
}
|
|
24
161
|
export type KVVitePlugin = Plugin & {
|
|
@@ -29,12 +166,16 @@ export type KVVitePlugin = Plugin & {
|
|
|
29
166
|
options: NitroCloudflareKVTarget;
|
|
30
167
|
}) => void;
|
|
31
168
|
};
|
|
32
|
-
vitehub: ViteHubCliPluginMetadata & {
|
|
169
|
+
vitehub: ViteHubCliPluginMetadata & ViteHubInspectionPluginMetadata & DurabilityPluginMetadata & {
|
|
33
170
|
operations: readonly OperationContributionEntry[];
|
|
34
171
|
};
|
|
35
172
|
};
|
|
36
|
-
export declare function
|
|
173
|
+
export declare function hubKVOptionalPeerResolver(): Plugin;
|
|
37
174
|
interface NitroCloudflareKVTarget {
|
|
175
|
+
handlers?: unknown[];
|
|
176
|
+
kv?: Record<string, unknown>;
|
|
177
|
+
storage?: Record<string, unknown>;
|
|
178
|
+
plugins?: string[];
|
|
38
179
|
cloudflare?: {
|
|
39
180
|
wrangler?: {
|
|
40
181
|
kv_namespaces?: Array<{
|
|
@@ -44,11 +185,11 @@ interface NitroCloudflareKVTarget {
|
|
|
44
185
|
};
|
|
45
186
|
};
|
|
46
187
|
}
|
|
47
|
-
export
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
kv?: KVModuleOptions;
|
|
51
|
-
}
|
|
188
|
+
export interface KVViteInput extends Pick<KVResolutionInput, "hosting"> {
|
|
189
|
+
/** The module that exports the app's `databases`, for the `database` driver. Default `@vite-hub/database/runtime/registry`. */
|
|
190
|
+
databaseImport?: string;
|
|
52
191
|
}
|
|
192
|
+
/** `input.hosting` names the host preset for driver inference, as `vitehub()` passes it. Without it, KV reads the host from env. */
|
|
193
|
+
export declare function hubKV(options?: KVOptions, input?: KVViteInput): KVVitePlugin;
|
|
53
194
|
//#endregion
|
|
54
195
|
export type { KVViteRuntimeConfig };
|