@vite-hub/kv 0.6.1 → 0.8.0
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 +9 -7
- package/dist/{cli-BvVInMht.d.ts → cli-C-uep33j.d.ts} +15 -0
- package/dist/cli.d.ts +2 -2
- package/dist/cli.js +3 -2
- package/dist/{cloudflare-kv-Cp8HPUlJ.js → cloudflare-kv-hMdZQZz1.js} +3 -3
- package/dist/{cloudflare-kv-local-COoOI34K.js → cloudflare-kv-local-BpPaDG49.js} +2 -2
- package/dist/{config-_1oBDv2R.js → config-x_Nru3R5.js} +4 -4
- package/dist/{create-storage-DbWVAY9l.js → create-storage-DrhV0F4S.js} +1 -1
- package/dist/{cursor-history-CMcEEnTO.js → cursor-history-MzSrXXXX.js} +1 -1
- package/dist/{database-4iAg2GoV.js → database-D0NvYrhk.js} +66 -20
- package/dist/{deno-kv-CatE7zSS.js → deno-kv-DwcTL95B.js} +2 -2
- package/dist/{driver-BruahGvT.d.ts → driver-CZTAQ_07.d.ts} +2 -2
- package/dist/{error-diagnostics-CuVl1nvE.js → error-diagnostics-DAi25E6F.js} +10 -5
- package/dist/{errors-CJoAP4Bu.js → errors-kZRpu7Wa.js} +15 -2
- package/dist/errors.d.ts +6 -1
- package/dist/errors.js +1 -1
- package/dist/{fs-lite-DzTTR6R3.js → fs-lite-1n_Dvy4p.js} +195 -131
- package/dist/fs-lite-Co1NzxYo.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +79 -69
- package/dist/{operation-definition-CqZkx1Rm.d.ts → operations-BAlr2zUj.d.ts} +1 -0
- package/dist/{operations-DSOTGwST.js → operations-Cj_0pSSA.js} +22 -29
- package/dist/{operations-BkVt17cd.js → operations-DP8iWjQK.js} +75 -11
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +2 -2
- package/dist/{redis-shared-CR3ANc_N.js → redis-shared-DEwmedD5.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 +1 -1
- package/dist/runtime/redis-driver.d.ts +2 -2
- package/dist/runtime/redis-driver.js +3 -5
- package/dist/runtime/upstash-driver.d.ts +2 -2
- package/dist/runtime/upstash-driver.js +2 -2
- package/dist/{types-CPDL9enF.d.ts → types-BLxnI_rU.d.ts} +14 -14
- package/dist/{upstash-DeM3_U5H.js → upstash-DINRYhXI.js} +2 -2
- package/dist/vite.d.ts +9 -5
- package/dist/vite.js +211 -75
- package/package.json +8 -4
- package/dist/fs-lite-DwbPkc-C.js +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as invariant } from "../invariant-Dj2R1eMr.js";
|
|
2
2
|
import { o as normalizeKey } from "../utils2-By8eee1x.js";
|
|
3
|
-
import { n as kvErrorDiagnostics } from "../error-diagnostics-
|
|
3
|
+
import { n as kvErrorDiagnostics } from "../error-diagnostics-DAi25E6F.js";
|
|
4
4
|
import { t as chunks } from "../batch-D-ib5_0P.js";
|
|
5
|
-
import { a as redisIncrementScript, i as redisIncrementResult, n as escapeRedisGlob, o as redisTTLSeconds, r as redisDeleteIfEqualsScript, t as createPortableRedisKeyLister } from "../redis-shared-
|
|
5
|
+
import { a as redisIncrementScript, i as redisIncrementResult, n as escapeRedisGlob, o as redisTTLSeconds, r as redisDeleteIfEqualsScript, t as createPortableRedisKeyLister } from "../redis-shared-DEwmedD5.js";
|
|
6
6
|
import { Redis } from "ioredis";
|
|
7
7
|
// src/runtime/redis-driver.ts
|
|
8
8
|
/** The URL of a store: `env:<NAME>` reads the variable now, so a build never holds the URL of its server. */
|
|
@@ -92,9 +92,7 @@ function createRedisKVDriver(options) {
|
|
|
92
92
|
async setIfAbsentItem(key, value, ttl) {
|
|
93
93
|
return (ttl === void 0 ? await client.set(prefixed(key), value, "NX") : await client.set(prefixed(key), value, "PX", ttlMilliseconds(ttl), "NX")) === "OK";
|
|
94
94
|
},
|
|
95
|
-
async
|
|
96
|
-
return await client.getdel(prefixed(key));
|
|
97
|
-
},
|
|
95
|
+
getAndDeleteItem: async (key) => await client.getdel(prefixed(key)),
|
|
98
96
|
incrementItem: async (key, ttl) => redisIncrementResult(await client.eval(redisIncrementScript, 1, prefixed(key), redisTTLSeconds(ttl))),
|
|
99
97
|
deleteIfEqualsItem: async (key, expected) => Number(await client.eval(redisDeleteIfEqualsScript, 1, prefixed(key), expected)) === 1,
|
|
100
98
|
listKeys: createPortableRedisKeyLister("Redis KV", async (cursor, match, count) => {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { B as ResolvedUpstashKVStoreConfig } from "../types-
|
|
2
|
-
import { t as KVRuntimeDriver } from "../driver-
|
|
1
|
+
import { B as ResolvedUpstashKVStoreConfig } from "../types-BLxnI_rU.js";
|
|
2
|
+
import { t as KVRuntimeDriver } from "../driver-CZTAQ_07.js";
|
|
3
3
|
export default function createUpstashKVDriver(options: ResolvedUpstashKVStoreConfig): KVRuntimeDriver;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as invariant } from "../invariant-Dj2R1eMr.js";
|
|
2
2
|
import { o as normalizeKey } from "../utils2-By8eee1x.js";
|
|
3
|
-
import { n as kvErrorDiagnostics } from "../error-diagnostics-
|
|
3
|
+
import { n as kvErrorDiagnostics } from "../error-diagnostics-DAi25E6F.js";
|
|
4
4
|
import { t as chunks } from "../batch-D-ib5_0P.js";
|
|
5
|
-
import { a as redisIncrementScript, i as redisIncrementResult, n as escapeRedisGlob, o as redisTTLSeconds, r as redisDeleteIfEqualsScript, t as createPortableRedisKeyLister } from "../redis-shared-
|
|
5
|
+
import { a as redisIncrementScript, i as redisIncrementResult, n as escapeRedisGlob, o as redisTTLSeconds, r as redisDeleteIfEqualsScript, t as createPortableRedisKeyLister } from "../redis-shared-DEwmedD5.js";
|
|
6
6
|
import createDriver from "unstorage/drivers/upstash";
|
|
7
7
|
// src/runtime/upstash-driver.ts
|
|
8
8
|
const keyBatchSize = 1e3;
|
|
@@ -9,7 +9,7 @@ interface KVDriverAtomicOperations {
|
|
|
9
9
|
"cloudflare": never;
|
|
10
10
|
"database": "deleteIfEquals" | "getAndDelete" | "increment" | "setIfAbsent";
|
|
11
11
|
"deno-kv": "setIfAbsent";
|
|
12
|
-
"fs-lite": "setIfAbsent";
|
|
12
|
+
"fs-lite": "deleteIfEquals" | "getAndDelete" | "increment" | "setIfAbsent";
|
|
13
13
|
"redis": "deleteIfEquals" | "getAndDelete" | "increment" | "setIfAbsent";
|
|
14
14
|
"upstash": "deleteIfEquals" | "getAndDelete" | "increment" | "setIfAbsent";
|
|
15
15
|
}
|
|
@@ -64,7 +64,7 @@ interface DatabaseKVStoreConfig {
|
|
|
64
64
|
driver: "database";
|
|
65
65
|
/**
|
|
66
66
|
* The Database that keeps the keys, in the table `vitehub_kv`. Default `"default"`. The store creates the table when
|
|
67
|
-
* it is missing. Postgres and
|
|
67
|
+
* it is missing. Supports Postgres, libSQL, and native D1 bindings or sessions, not D1 over HTTP.
|
|
68
68
|
*/
|
|
69
69
|
database?: string;
|
|
70
70
|
/** A Database store uses the Database of the app, in `vite dev` too. */
|
|
@@ -138,7 +138,7 @@ interface ResolvedKVModuleOptions {
|
|
|
138
138
|
}
|
|
139
139
|
type KVOperation = "clear" | "delete" | "deleteIfEquals" | "get" | "getAndDelete" | "getMany" | "has" | "increment" | "list" | "lock" | "set" | "setIfAbsent" | "setMany";
|
|
140
140
|
/** Codes that KV operations return in the `[error, data]` tuple. Config errors throw instead. */
|
|
141
|
-
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";
|
|
141
|
+
type KVErrorCode = "KV_INVALID_CURSOR" | "KV_INVALID_CLEAR_OPTIONS" | "KV_INVALID_KEY" | "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
142
|
interface KVListOptions {
|
|
143
143
|
/** Opaque continuation cursor returned by a previous page. */
|
|
144
144
|
cursor?: string;
|
|
@@ -184,7 +184,7 @@ interface KVLockOptions {
|
|
|
184
184
|
wait?: number;
|
|
185
185
|
}
|
|
186
186
|
/** Codes that `kv.lock().run()` and `kv.lock().acquire()` return. */
|
|
187
|
-
type KVLockErrorCode = "KV_INVALID_TTL" | "KV_INVALID_WAIT" | "KV_OPERATION_FAILED" | "KV_UNSUPPORTED_OPERATION";
|
|
187
|
+
type KVLockErrorCode = "KV_INVALID_KEY" | "KV_INVALID_TTL" | "KV_INVALID_WAIT" | "KV_OPERATION_FAILED" | "KV_UNSUPPORTED_OPERATION";
|
|
188
188
|
/** The data of `kv.lock().run()`: the callback's value, or `acquired: false` when another runner held the lock. */
|
|
189
189
|
type KVLockRunResult<T> = {
|
|
190
190
|
acquired: true;
|
|
@@ -232,26 +232,26 @@ interface KVListPage {
|
|
|
232
232
|
*/
|
|
233
233
|
interface KVStorage {
|
|
234
234
|
clear(options?: KVClearOptions): Promise<Result<void, "KV_INVALID_CLEAR_OPTIONS" | "KV_OPERATION_FAILED">>;
|
|
235
|
-
delete(key: string, options?: unknown): Promise<Result<void, "KV_KEY_TOO_LONG" | "KV_OPERATION_FAILED">>;
|
|
235
|
+
delete(key: string, options?: unknown): Promise<Result<void, "KV_INVALID_KEY" | "KV_KEY_TOO_LONG" | "KV_OPERATION_FAILED">>;
|
|
236
236
|
/**
|
|
237
237
|
* Deletes the key only when its value equals `expected`, in one atomic step. Returns `true` when this call deleted it.
|
|
238
238
|
* KV compares the stored text with `expected` serialized as `set()` stores it, so `{ a: 1, b: 2 }` and
|
|
239
239
|
* `{ b: 2, a: 1 }` are different values. Use it to free a token that only its owner may free.
|
|
240
240
|
* The drivers in {@link KVDriversWith}`<"deleteIfEquals">` support it. The others return `KV_UNSUPPORTED_OPERATION`.
|
|
241
241
|
*/
|
|
242
|
-
deleteIfEquals<T = unknown>(key: string, expected: T): Promise<Result<boolean, "KV_INVALID_VALUE" | "KV_OPERATION_FAILED" | "KV_UNSUPPORTED_OPERATION">>;
|
|
243
|
-
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">>;
|
|
244
|
-
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">>;
|
|
242
|
+
deleteIfEquals<T = unknown>(key: string, expected: T): Promise<Result<boolean, "KV_INVALID_KEY" | "KV_INVALID_VALUE" | "KV_OPERATION_FAILED" | "KV_UNSUPPORTED_OPERATION">>;
|
|
243
|
+
get<T = unknown, K extends KVGetType | undefined = undefined>(key: string, options?: KVGetOptions<K>): Promise<Result<KVValue<T, K> | null, "KV_INVALID_KEY" | "KV_KEY_TOO_LONG" | "KV_OPERATION_FAILED">>;
|
|
244
|
+
getMany<T = unknown, K extends KVGetType | undefined = undefined>(keys: readonly string[], options?: KVGetOptions<K>): Promise<Result<Array<KVValue<T, K> | null>, "KV_INVALID_KEY" | "KV_KEY_TOO_LONG" | "KV_OPERATION_FAILED">>;
|
|
245
245
|
getAndDelete<T = unknown, K extends "text" | undefined = undefined>(key: string, options?: {
|
|
246
246
|
type?: K;
|
|
247
|
-
}): Promise<Result<KVValue<T, K> | null, "KV_OPERATION_FAILED" | "KV_UNSUPPORTED_OPERATION">>;
|
|
248
|
-
has(key: string, options?: unknown): Promise<Result<boolean, "KV_KEY_TOO_LONG" | "KV_OPERATION_FAILED">>;
|
|
247
|
+
}): Promise<Result<KVValue<T, K> | null, "KV_INVALID_KEY" | "KV_OPERATION_FAILED" | "KV_UNSUPPORTED_OPERATION">>;
|
|
248
|
+
has(key: string, options?: unknown): Promise<Result<boolean, "KV_INVALID_KEY" | "KV_KEY_TOO_LONG" | "KV_OPERATION_FAILED">>;
|
|
249
249
|
/**
|
|
250
250
|
* Atomically increments a counter. The TTL, a number of seconds or a duration such as `"1m"`, is applied only when
|
|
251
251
|
* the counter is created.
|
|
252
252
|
* The drivers in {@link KVDriversWith}`<"increment">` support it. The others return `KV_UNSUPPORTED_OPERATION`.
|
|
253
253
|
*/
|
|
254
|
-
increment(key: string, ttl: number | Duration): Promise<Result<number, "KV_INVALID_TTL" | "KV_OPERATION_FAILED" | "KV_UNSUPPORTED_OPERATION">>;
|
|
254
|
+
increment(key: string, ttl: number | Duration): Promise<Result<number, "KV_INVALID_KEY" | "KV_INVALID_TTL" | "KV_OPERATION_FAILED" | "KV_UNSUPPORTED_OPERATION">>;
|
|
255
255
|
list(options?: KVListOptions): Promise<Result<KVListPage, "KV_INVALID_CURSOR" | "KV_INVALID_LIMIT" | "KV_OPERATION_FAILED">>;
|
|
256
256
|
/**
|
|
257
257
|
* A lock on `key` that one runner holds at a time, across server processes that share the store. It writes a random
|
|
@@ -265,7 +265,7 @@ interface KVStorage {
|
|
|
265
265
|
* value stays until you delete or replace it.
|
|
266
266
|
* Cloudflare KV stores return `KV_KEY_TOO_LONG` and `KV_VALUE_TOO_LARGE` before a write that Cloudflare rejects.
|
|
267
267
|
*/
|
|
268
|
-
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">>;
|
|
268
|
+
set<T = unknown>(key: string, value: T, options?: KVSetOptions): Promise<Result<void, "KV_INVALID_KEY" | "KV_INVALID_OPTION" | "KV_INVALID_TTL" | "KV_KEY_TOO_LONG" | "KV_OPERATION_FAILED" | "KV_VALUE_TOO_LARGE">>;
|
|
269
269
|
/**
|
|
270
270
|
* Writes many keys in one call. `options` works as in `set()` and applies to every entry. When a key is in `entries`
|
|
271
271
|
* more than once, the last entry wins. A `value` of `undefined` deletes the key, as `set()` does. The writes are not
|
|
@@ -273,14 +273,14 @@ interface KVStorage {
|
|
|
273
273
|
* statement. Other stores write the entries one by one, 16 at a time. A Cloudflare KV store checks every entry against
|
|
274
274
|
* the Workers KV limits before it writes any.
|
|
275
275
|
*/
|
|
276
|
-
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">>;
|
|
276
|
+
setMany<T = unknown>(entries: readonly KVEntry<T>[], options?: KVSetOptions): Promise<Result<void, "KV_INVALID_KEY" | "KV_INVALID_OPTION" | "KV_INVALID_TTL" | "KV_KEY_TOO_LONG" | "KV_OPERATION_FAILED" | "KV_VALUE_TOO_LARGE">>;
|
|
277
277
|
/**
|
|
278
278
|
* Writes the value only when the key has no value, in one atomic step.
|
|
279
279
|
* Returns `true` when this call wrote the value and `false` when the key already had one.
|
|
280
280
|
* The drivers in {@link KVDriversWith}`<"setIfAbsent">` support it. Cloudflare KV is eventually consistent and returns
|
|
281
281
|
* `KV_UNSUPPORTED_OPERATION`.
|
|
282
282
|
*/
|
|
283
|
-
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">>;
|
|
283
|
+
setIfAbsent<T = unknown>(key: string, value: T, options?: KVSetOptions): Promise<Result<boolean, "KV_INVALID_KEY" | "KV_INVALID_OPTION" | "KV_INVALID_TTL" | "KV_INVALID_VALUE" | "KV_OPERATION_FAILED" | "KV_UNSUPPORTED_OPERATION">>;
|
|
284
284
|
/** Selects a named KV store. `{ mode: "read" }` returns a handle without write methods. */
|
|
285
285
|
store(name: KVStoreName, options?: {
|
|
286
286
|
mode?: "write";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as upstashUrlEnvNames, i as upstashTokenEnvNames, s as readEnv } from "./config-
|
|
2
|
-
import { n as kvErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { a as upstashUrlEnvNames, i as upstashTokenEnvNames, s as readEnv } from "./config-x_Nru3R5.js";
|
|
2
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-DAi25E6F.js";
|
|
3
3
|
// src/runtime/upstash.ts
|
|
4
4
|
function isMaskedValue(value) {
|
|
5
5
|
return !value || /^\*+$/.test(value);
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { L as ResolvedKVModuleOptions, w as KVOptions } from "./types-
|
|
2
|
-
import { r as ViteHubCliPluginMetadata } from "./cli-
|
|
3
|
-
import { n as OperationContributionEntry } from "./
|
|
1
|
+
import { L as ResolvedKVModuleOptions, w as KVOptions } from "./types-BLxnI_rU.js";
|
|
2
|
+
import { r as ViteHubCliPluginMetadata } from "./cli-C-uep33j.js";
|
|
3
|
+
import { n as OperationContributionEntry } from "./operations-BAlr2zUj.js";
|
|
4
4
|
import "nostics";
|
|
5
5
|
import { Plugin } from "vite";
|
|
6
6
|
interface KVResolutionInput {
|
|
@@ -149,6 +149,7 @@ export interface KVVitePluginAPI {
|
|
|
149
149
|
deploymentEnv: DeploymentEnvContribution;
|
|
150
150
|
getConfig: () => KVViteRuntimeConfig;
|
|
151
151
|
getBuildConfig: () => KVViteRuntimeConfig;
|
|
152
|
+
whenConfigResolved: () => Promise<void> | undefined;
|
|
152
153
|
}
|
|
153
154
|
export type KVVitePlugin = Plugin & {
|
|
154
155
|
api: KVVitePluginAPI;
|
|
@@ -168,7 +169,10 @@ interface KVNitroBuild {
|
|
|
168
169
|
hooks?: {
|
|
169
170
|
hook: (name: "prerender:config", callback: (config: KVPrerenderConfig) => void) => unknown;
|
|
170
171
|
};
|
|
171
|
-
options: NitroCloudflareKVTarget
|
|
172
|
+
options: NitroCloudflareKVTarget & {
|
|
173
|
+
dev?: boolean;
|
|
174
|
+
preset?: string;
|
|
175
|
+
};
|
|
172
176
|
}
|
|
173
177
|
interface NitroCloudflareKVTarget {
|
|
174
178
|
deps?: {
|
|
@@ -191,6 +195,6 @@ export interface KVViteInput extends Pick<KVResolutionInput, "hosting"> {
|
|
|
191
195
|
/** The module that exports the app's `databases`, for the `database` driver. Default `@vite-hub/database/runtime/registry`. */
|
|
192
196
|
databaseImport?: string;
|
|
193
197
|
}
|
|
194
|
-
/**
|
|
198
|
+
/** KV infers its driver from Nitro's preset, the supplied host, or the host environment. */
|
|
195
199
|
export declare function hubKV(options?: KVOptions, input?: KVViteInput): KVVitePlugin;
|
|
196
200
|
export type { KVViteRuntimeConfig };
|