@vite-hub/kv 0.3.1 → 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 +14 -12
- package/dist/cli.js +4 -3
- package/dist/{cloudflare-kv-BIEUFzRT.js → cloudflare-kv-C3NO4C21.js} +18 -4
- package/dist/{cloudflare-kv-local-BBw3ZT1K.js → cloudflare-kv-local-C2sbIrFy.js} +2 -2
- package/dist/{config-BXEVoZE3.js → config-LfpUj9hs.js} +25 -23
- package/dist/{create-storage-BGsrQKw3.js → create-storage-BORQm2a8.js} +5 -5
- package/dist/{cursor-history-BqIQePNP.js → cursor-history-DRHh5bO5.js} +1 -1
- package/dist/{database-72Jk3VVk.js → database-oJdy0ZVX.js} +1 -1
- package/dist/{deno-kv-BM9mYdUp.js → deno-kv-D_VtffFv.js} +2 -2
- package/dist/{driver-BwxgaQ-f.d.ts → driver-R4Z5Z5fl.d.ts} +2 -2
- package/dist/{error-diagnostics-BxqvtEIb.js → error-diagnostics-C54QQEhN.js} +10 -2
- package/dist/{errors-DbwufFZp.js → errors-DzD6YNEH.js} +31 -3
- package/dist/errors.d.ts +6 -1
- package/dist/errors.js +2 -2
- package/dist/fs-lite-BAgpmNAF.js +2 -0
- package/dist/{fs-lite-BLZId9_P.js → fs-lite-BaklCLuV.js} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +42 -27
- package/dist/{operation-definition-8gOe-ubD.d.ts → operation-definition-nmRu_O3V.d.ts} +5 -0
- package/dist/{operations-Ch-gKaey.js → operations-CtrWLmPK.js} +3 -9
- package/dist/{operations-B-WZ7P1h.js → operations-D2iI9oN4.js} +238 -226
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +3 -2
- package/dist/{redis-shared-E5mahECF.js → redis-shared-5ogRd3-Y.js} +1 -1
- package/dist/runtime/cloudflare-kv.d.ts +1 -1
- package/dist/runtime/cloudflare-kv.js +1 -1
- package/dist/runtime/nitro-plugin.js +7 -4
- package/dist/runtime/redis-driver.d.ts +2 -2
- package/dist/runtime/redis-driver.js +2 -2
- package/dist/runtime/unstorage-driver.js +6 -2
- package/dist/runtime/upstash-driver.d.ts +2 -2
- package/dist/runtime/upstash-driver.js +2 -2
- package/dist/{types-DEiKew_3.d.ts → types-Dv-OSXZC.d.ts} +33 -20
- package/dist/{upstash-DDlqTttY.js → upstash-B-vaUYqO.js} +2 -2
- package/dist/virtual-module.d.ts +1 -0
- package/dist/vite.d.ts +17 -5
- package/dist/vite.js +601 -334
- package/package.json +5 -5
- package/dist/fs-lite-RAoxu8L0.js +0 -2
- package/dist/main-F3Y22_uV.js +0 -2353
- package/dist/rolldown-runtime-CMFfr-1z.js +0 -26
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { n as GetItemType, r as GetItemTypeMap } from "./types-Bj3EQoRg.js";
|
|
2
|
-
import { Result } from "@vite-hub/runtime";
|
|
2
|
+
import { Duration, Result } from "@vite-hub/runtime";
|
|
3
3
|
//#region src/types.d.ts
|
|
4
4
|
type KVDriver = "cloudflare" | "database" | "deno-kv" | "fs-lite" | "redis" | "upstash";
|
|
5
5
|
/**
|
|
6
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`, `
|
|
7
|
+
* driver does not list. `get`, `set`, `delete`, `has`, `list`, and `clear` work on every driver.
|
|
8
8
|
*/
|
|
9
9
|
interface KVDriverAtomicOperations {
|
|
10
10
|
"cloudflare": never;
|
|
@@ -38,7 +38,7 @@ interface UpstashKVStoreConfig {
|
|
|
38
38
|
token?: string;
|
|
39
39
|
url?: string;
|
|
40
40
|
/**
|
|
41
|
-
* Prefix of every key in Upstash. Default `vitehub:kv:<store>`, as for a Redis store, so `kv.clear()` and `kv.
|
|
41
|
+
* Prefix of every key in Upstash. Default `vitehub:kv:<store>`, as for a Redis store, so `kv.clear()` and `kv.list()`
|
|
42
42
|
* stay inside the store. An empty value uses the default.
|
|
43
43
|
*/
|
|
44
44
|
base?: string;
|
|
@@ -137,14 +137,23 @@ interface ResolvedKVModuleOptions {
|
|
|
137
137
|
store: ResolvedKVStoreConfig;
|
|
138
138
|
stores?: Record<string, ResolvedKVStoreConfig>;
|
|
139
139
|
}
|
|
140
|
-
type KVOperation = "clear" | "delete" | "deleteIfEquals" | "get" | "getAndDelete" | "getMany" | "has" | "increment" | "
|
|
140
|
+
type KVOperation = "clear" | "delete" | "deleteIfEquals" | "get" | "getAndDelete" | "getMany" | "has" | "increment" | "list" | "lock" | "set" | "setIfAbsent" | "setMany";
|
|
141
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";
|
|
142
|
+
type KVErrorCode = "KV_INVALID_CURSOR" | "KV_INVALID_CLEAR_OPTIONS" | "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
143
|
interface KVListOptions {
|
|
144
144
|
/** Opaque continuation cursor returned by a previous page. */
|
|
145
145
|
cursor?: string;
|
|
146
|
-
/** Maximum number of keys to read. Must be a positive integer. */
|
|
146
|
+
/** Maximum number of keys to read. Must be a positive integer. Without it, the page holds every key and no cursor. */
|
|
147
|
+
limit?: number;
|
|
148
|
+
/** Only keys that start with this text, so `"user"` matches `users:1`. `"users:"` matches the keys below `users`. */
|
|
149
|
+
prefix?: string;
|
|
150
|
+
}
|
|
151
|
+
/** One page that a driver reads: `limit` is set. */
|
|
152
|
+
interface KVPageOptions extends KVListOptions {
|
|
147
153
|
limit: number;
|
|
154
|
+
}
|
|
155
|
+
interface KVClearOptions {
|
|
156
|
+
/** Only keys that start with this text, as in `list()`. Without it, `clear()` deletes every key of the store. */
|
|
148
157
|
prefix?: string;
|
|
149
158
|
}
|
|
150
159
|
/** What `kv.get()` converts the stored value to: `text`, `json`, `bytes`, `stream`, or `blob`. */
|
|
@@ -159,16 +168,20 @@ type KVGetOptions<K extends KVGetType | undefined = KVGetType | undefined> = Rec
|
|
|
159
168
|
type KVValue<T, K> = K extends KVGetType ? KVGetTypeMap[K] : T;
|
|
160
169
|
/** Options of `kv.set()`, `kv.setMany()`, and `kv.setIfAbsent()`. Other fields return `KV_INVALID_OPTION`. */
|
|
161
170
|
interface KVSetOptions {
|
|
162
|
-
/**
|
|
163
|
-
|
|
171
|
+
/**
|
|
172
|
+
* How long until the key expires: a number of seconds, or a duration such as `"1h"` or `"7 days"`. Every driver
|
|
173
|
+
* expires the key. Cloudflare KV keeps it at least 60 seconds.
|
|
174
|
+
*/
|
|
175
|
+
ttl?: number | Duration;
|
|
164
176
|
}
|
|
165
177
|
/** Options of `kv.lock()`. */
|
|
166
178
|
interface KVLockOptions {
|
|
167
179
|
/**
|
|
168
|
-
*
|
|
169
|
-
* KV does not renew a lock: when the work runs longer than `ttl`, another
|
|
180
|
+
* How long until the lock expires, so a crashed holder never keeps it: a number of seconds, or a duration such as
|
|
181
|
+
* `"30s"`. Pick a value longer than the work. KV does not renew a lock: when the work runs longer than `ttl`, another
|
|
182
|
+
* runner can take the lock.
|
|
170
183
|
*/
|
|
171
|
-
ttl: number;
|
|
184
|
+
ttl: number | Duration;
|
|
172
185
|
/** Seconds to wait for a held lock, polling with backoff. Default `0`: return `{ acquired: false }` at once. */
|
|
173
186
|
wait?: number;
|
|
174
187
|
}
|
|
@@ -219,7 +232,7 @@ interface KVListPage {
|
|
|
219
232
|
* Config errors, for example an unknown store name, throw.
|
|
220
233
|
*/
|
|
221
234
|
interface KVStorage {
|
|
222
|
-
clear(
|
|
235
|
+
clear(options?: KVClearOptions): Promise<Result<void, "KV_INVALID_CLEAR_OPTIONS" | "KV_OPERATION_FAILED">>;
|
|
223
236
|
delete(key: string, options?: unknown): Promise<Result<void, "KV_KEY_TOO_LONG" | "KV_OPERATION_FAILED">>;
|
|
224
237
|
/**
|
|
225
238
|
* Deletes the key only when its value equals `expected`, in one atomic step. Returns `true` when this call deleted it.
|
|
@@ -249,12 +262,12 @@ interface KVStorage {
|
|
|
249
262
|
}): Promise<Result<KVValue<T, K> | null, "KV_OPERATION_FAILED" | "KV_UNSUPPORTED_OPERATION">>;
|
|
250
263
|
has(key: string, options?: unknown): Promise<Result<boolean, "KV_KEY_TOO_LONG" | "KV_OPERATION_FAILED">>;
|
|
251
264
|
/**
|
|
252
|
-
* Atomically increments a counter. The TTL
|
|
265
|
+
* Atomically increments a counter. The TTL, a number of seconds or a duration such as `"1m"`, is applied only when
|
|
266
|
+
* the counter is created.
|
|
253
267
|
* The drivers in {@link KVDriversWith}`<"increment">` support it. The others return `KV_UNSUPPORTED_OPERATION`.
|
|
254
268
|
*/
|
|
255
|
-
increment(key: string, ttl: number): Promise<Result<number, "KV_INVALID_TTL" | "KV_OPERATION_FAILED" | "KV_UNSUPPORTED_OPERATION">>;
|
|
256
|
-
|
|
257
|
-
list(options: KVListOptions): Promise<Result<KVListPage, "KV_INVALID_CURSOR" | "KV_INVALID_LIMIT" | "KV_OPERATION_FAILED">>;
|
|
269
|
+
increment(key: string, ttl: number | Duration): Promise<Result<number, "KV_INVALID_TTL" | "KV_OPERATION_FAILED" | "KV_UNSUPPORTED_OPERATION">>;
|
|
270
|
+
list(options?: KVListOptions): Promise<Result<KVListPage, "KV_INVALID_CURSOR" | "KV_INVALID_LIMIT" | "KV_OPERATION_FAILED">>;
|
|
258
271
|
/**
|
|
259
272
|
* A lock on `key` that one runner holds at a time, across server processes that share the store. It writes a random
|
|
260
273
|
* owner token with `setIfAbsent()` and a TTL, and frees it with `deleteIfEquals()`, so a runner never deletes a lock
|
|
@@ -263,7 +276,8 @@ interface KVStorage {
|
|
|
263
276
|
*/
|
|
264
277
|
lock(key: string, options: KVLockOptions): KVLock;
|
|
265
278
|
/**
|
|
266
|
-
* Writes a value. `{ ttl }` expires it after
|
|
279
|
+
* Writes a value. `{ ttl }` expires it after a number of seconds or a duration such as `"1h"`; without `ttl`, the
|
|
280
|
+
* value stays until you delete or replace it.
|
|
267
281
|
* Cloudflare KV stores return `KV_KEY_TOO_LONG` and `KV_VALUE_TOO_LARGE` before a write that Cloudflare rejects.
|
|
268
282
|
*/
|
|
269
283
|
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">>;
|
|
@@ -297,7 +311,7 @@ interface KVStoreOptions {
|
|
|
297
311
|
mode?: "read" | "write";
|
|
298
312
|
}
|
|
299
313
|
/**
|
|
300
|
-
* KV handle from `kv.store(name, { mode: "read" })`, with only `get()`, `getMany()`, `has()`,
|
|
314
|
+
* KV handle from `kv.store(name, { mode: "read" })`, with only `get()`, `getMany()`, `has()`, and `list()`.
|
|
301
315
|
* It limits this API, not the host: the KV binding or provider token keeps full access, so it is not a security
|
|
302
316
|
* boundary against code that reads the binding directly.
|
|
303
317
|
*/
|
|
@@ -305,8 +319,7 @@ interface ReadonlyKVStorage {
|
|
|
305
319
|
get: KVStorage["get"];
|
|
306
320
|
getMany: KVStorage["getMany"];
|
|
307
321
|
has: KVStorage["has"];
|
|
308
|
-
keys: KVStorage["keys"];
|
|
309
322
|
list: KVStorage["list"];
|
|
310
323
|
}
|
|
311
324
|
//#endregion
|
|
312
|
-
export {
|
|
325
|
+
export { KVStoreOptions as A, ResolvedUpstashKVStoreConfig as B, KVOperation as C, KVStorage as D, KVSetOptions as E, ResolvedDenoKVStoreConfig as F, ResolvedFsLiteKVStoreConfig as I, ResolvedKVModuleOptions as L, RedisKVStoreConfig as M, ResolvedCloudflareKVStoreConfig as N, KVStoreConfig as O, ResolvedDatabaseKVStoreConfig as P, ResolvedKVStoreConfig as R, KVLockRunResult as S, KVPageOptions as T, UpstashKVStoreConfig as V, KVListPage as _, InferredKVStoreConfig as a, KVLockErrorCode as b, KVDriver as c, KVEntry as d, KVErrorCode as f, KVListOptions as g, KVGetTypeMap as h, FsLiteKVStoreConfig as i, ReadonlyKVStorage as j, KVStoreName as k, KVDriverAtomicOperations as l, KVGetType as m, DatabaseKVStoreConfig as n, KVAtomicOperation as o, KVGetOptions as p, DenoKVStoreConfig as r, KVClearOptions as s, CloudflareKVStoreConfig as t, KVDriversWith as u, KVLock as v, KVOptions as w, KVLockOptions as x, KVLockAcquisition as y, ResolvedRedisKVStoreConfig as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as kvErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
-
import { a as upstashUrlEnvNames, i as upstashTokenEnvNames, s as readEnv } from "./config-
|
|
1
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-C54QQEhN.js";
|
|
2
|
+
import { a as upstashUrlEnvNames, i as upstashTokenEnvNames, s as readEnv } from "./config-LfpUj9hs.js";
|
|
3
3
|
//#region src/runtime/upstash.ts
|
|
4
4
|
function isMaskedValue(value) {
|
|
5
5
|
return !value || /^\*+$/.test(value);
|
package/dist/virtual-module.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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
|
+
export const durabilityReportsStores: boolean
|
|
4
5
|
/** Loads the databases of the app. Set when a store uses the `database` driver. */
|
|
5
6
|
export const loadDatabases: (() => Promise<Record<string, { db: object } | undefined>>) | undefined
|
|
6
7
|
const config: { hosting?: string, kv: typeof kv }
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { L as ResolvedKVModuleOptions, w as KVOptions } from "./types-Dv-OSXZC.js";
|
|
2
2
|
import { r as ViteHubCliPluginMetadata } from "./cli-DpPhz_Ek.js";
|
|
3
|
-
import { n as OperationContributionEntry } from "./operation-definition-
|
|
3
|
+
import { n as OperationContributionEntry } from "./operation-definition-nmRu_O3V.js";
|
|
4
|
+
import "nostics";
|
|
4
5
|
import { Plugin } from "vite";
|
|
5
6
|
//#region src/config.d.ts
|
|
6
7
|
interface KVResolutionInput {
|
|
@@ -9,6 +10,7 @@ interface KVResolutionInput {
|
|
|
9
10
|
* store falls back to `fs-lite` when the runtime has no binding. Builds leave it unset.
|
|
10
11
|
*/
|
|
11
12
|
dev?: boolean;
|
|
13
|
+
prerender?: boolean;
|
|
12
14
|
env?: Record<string, string | undefined>;
|
|
13
15
|
hosting?: string;
|
|
14
16
|
/**
|
|
@@ -157,20 +159,30 @@ export interface KVVitePluginAPI {
|
|
|
157
159
|
/** The variables that the KV stores read on the deployed host. See `kvDeploymentEnv()`. */
|
|
158
160
|
deploymentEnv: DeploymentEnvContribution;
|
|
159
161
|
getConfig: () => KVViteRuntimeConfig;
|
|
162
|
+
getBuildConfig: () => KVViteRuntimeConfig;
|
|
160
163
|
}
|
|
161
164
|
export type KVVitePlugin = Plugin & {
|
|
162
165
|
api: KVVitePluginAPI;
|
|
163
166
|
nitro: {
|
|
164
167
|
name: string;
|
|
165
|
-
setup: (nitro:
|
|
166
|
-
options: NitroCloudflareKVTarget;
|
|
167
|
-
}) => void;
|
|
168
|
+
setup: (nitro: KVNitroBuild) => void;
|
|
168
169
|
};
|
|
169
170
|
vitehub: ViteHubCliPluginMetadata & ViteHubInspectionPluginMetadata & DurabilityPluginMetadata & {
|
|
170
171
|
operations: readonly OperationContributionEntry[];
|
|
171
172
|
};
|
|
172
173
|
};
|
|
173
174
|
export declare function hubKVOptionalPeerResolver(): Plugin;
|
|
175
|
+
/** The part of Nitro's prerender config that KV changes. */
|
|
176
|
+
interface KVPrerenderConfig {
|
|
177
|
+
virtual?: Record<string, string | (() => string)>;
|
|
178
|
+
}
|
|
179
|
+
/** The parts of a Nitro build that KV changes. */
|
|
180
|
+
interface KVNitroBuild {
|
|
181
|
+
hooks?: {
|
|
182
|
+
hook: (name: "prerender:config", callback: (config: KVPrerenderConfig) => void) => unknown;
|
|
183
|
+
};
|
|
184
|
+
options: NitroCloudflareKVTarget;
|
|
185
|
+
}
|
|
174
186
|
interface NitroCloudflareKVTarget {
|
|
175
187
|
handlers?: unknown[];
|
|
176
188
|
kv?: Record<string, unknown>;
|