@vite-hub/kv 0.5.1 → 0.6.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 +1 -1
- package/dist/cli.js +2 -2
- package/dist/{cloudflare-env-Bm6huR35.js → cloudflare-env-Cpy3Bqdn.js} +1 -2
- package/dist/{cloudflare-kv-K2MzfP6D.js → cloudflare-kv-Cp8HPUlJ.js} +4 -4
- package/dist/{cloudflare-kv-local-lov9LLhU.js → cloudflare-kv-local-COoOI34K.js} +3 -3
- package/dist/{config-B8FRGmX_.js → config-_1oBDv2R.js} +1 -1
- package/dist/{create-storage-BMvkkYdM.js → create-storage-DbWVAY9l.js} +1 -1
- package/dist/{cursor-history-C6oG12QO.js → cursor-history-CMcEEnTO.js} +1 -1
- package/dist/{runtime/database.js → database-4iAg2GoV.js} +24 -50
- package/dist/{deno-kv-MnqlNH1e.js → deno-kv-CatE7zSS.js} +2 -2
- package/dist/driver-BruahGvT.d.ts +13 -0
- package/dist/{error-diagnostics-DUIp6FhO.js → error-diagnostics-CuVl1nvE.js} +2 -2
- package/dist/{errors-IaVOqzAs.js → errors-CJoAP4Bu.js} +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -1
- package/dist/fs-lite-DwbPkc-C.js +1 -0
- package/dist/{fs-lite-fvNdBEr9.js → fs-lite-DzTTR6R3.js} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -9
- package/dist/{operations-CGAX5ASA.js → operations-BkVt17cd.js} +9 -5
- package/dist/{operations-FgS_sJ3M.js → operations-DSOTGwST.js} +1 -1
- package/dist/operations.d.ts +1 -1
- package/dist/operations.js +2 -2
- package/dist/{redis-shared-DO7Ib1Sz.js → redis-shared-CR3ANc_N.js} +1 -1
- package/dist/runtime/cloudflare-kv.d.ts +1 -1
- package/dist/runtime/cloudflare-kv.js +1 -1
- package/dist/runtime/cloudflare-request-env.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 +2 -2
- package/dist/runtime/upstash-driver.d.ts +2 -2
- package/dist/runtime/upstash-driver.js +2 -2
- package/dist/{types-C397WKyf.d.ts → types-CPDL9enF.d.ts} +1 -1
- package/dist/{upstash-DQVo1zbz.js → upstash-DeM3_U5H.js} +2 -2
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +19 -14
- package/package.json +4 -9
- package/dist/driver-bLMl-wMO.d.ts +0 -43
- package/dist/fs-lite-DhXLUL-H.js +0 -1
- package/dist/runtime/database.d.ts +0 -2
package/README.md
CHANGED
|
@@ -66,7 +66,7 @@ Several Node processes share keys only through a shared store. Without a `driver
|
|
|
66
66
|
|
|
67
67
|
`{ driver: "upstash", url?, token?, base? }` uses the same `base` rule as `redis`: every key gets the prefix `vitehub:kv:<store>` unless `base` sets another one, so `kv.clear()` and `kv.list()` stay inside the store. Upstash takes whole seconds, so `set()` rounds a TTL up. Its listing cursor also holds its whole state, so the next page works in another serverless invocation.
|
|
68
68
|
|
|
69
|
-
`{ driver: "database", database? }` keeps keys in the table `vitehub_kv` of the Database `database` (default `"default"`), with one `namespace` per store. The store creates the table when it is missing; on Postgres, an advisory lock lets several servers start at once. Every atomic operation is one SQL statement, and expiry uses the clock of the Database. Writes start background cleanup of at most 1000 expired rows in their namespace. A full batch lets the next write start another batch; once a batch is not full, cleanup waits a minute. Postgres sweeps skip rows locked by another process. It works on Postgres
|
|
69
|
+
`{ driver: "database", database? }` keeps keys in the table `vitehub_kv` of the Database `database` (default `"default"`), with one `namespace` per store. The store creates the table when it is missing; on Postgres, an advisory lock lets several servers start at once. Every atomic operation is one SQL statement, and expiry uses the clock of the Database. Writes start background cleanup of at most 1000 expired rows in their namespace. A full batch lets the next write start another batch; once a batch is not full, cleanup waits a minute. Postgres sweeps skip rows locked by another process. It works on Postgres and libSQL, not on D1.
|
|
70
70
|
|
|
71
71
|
The driver is selected at build time. Redis requires `kv: { driver: "redis" }`; every process must supply its URL, and a missing URL fails. An unrelated `REDIS_URL` never changes the selected driver. A build without a `driver` that has `REDIS_URL`, or a `KV_URL` that starts with `rediss://`, reports the hint `KV_REDIS_URL_UNUSED` in the build output and in `.vitehub/hints.json`, with the fix `kv: { driver: "redis" }`. On Vercel without Upstash variables, the same hint says that the inferred Upstash store fails at runtime. The `kv.list` operation (`vitehub kv list`, the Console) reports that driver.
|
|
72
72
|
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { A as readViteHubDevTargetOption, D as parseCliPositiveInteger, E as listSeedFiles, M as writeCliFailure, O as readCliOptionValue, T as askOnTerminal, n as callOperationFromCli } from "./operations-
|
|
1
|
+
import { A as readViteHubDevTargetOption, D as parseCliPositiveInteger, E as listSeedFiles, M as writeCliFailure, O as readCliOptionValue, T as askOnTerminal, n as callOperationFromCli } from "./operations-BkVt17cd.js";
|
|
2
2
|
import { t as isRecord } from "./object-CAK6UYR5.js";
|
|
3
|
-
import { n as kvErrorDiagnostics } from "./error-diagnostics-
|
|
3
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-CuVl1nvE.js";
|
|
4
4
|
import { t as kvDevMaximumListLimit } from "./results-emgN7uDS.js";
|
|
5
5
|
import { readFile } from "node:fs/promises";
|
|
6
6
|
import { extname, join, relative, resolve } from "node:path";
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { i as setInstalledCloudflareEnv, n as getActiveCloudflareEnv, r as getCloudflareEnv, t as activeEnvStorageKey } from "./cloudflare-env-lookup-Dgq5n1Aq.js";
|
|
2
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
3
|
// ../internal/src/runtime/cloudflare-env.ts
|
|
4
|
-
const d1PrimaryClient = Symbol.for("vitehub.database.d1-primary-client");
|
|
5
4
|
const runtimeGlobal = globalThis;
|
|
6
5
|
const activeEnvStorage = runtimeGlobal[activeEnvStorageKey] ||= new AsyncLocalStorage();
|
|
7
6
|
const globalEnvProbe = Symbol("vitehub.cloudflare.global-env-probe");
|
|
@@ -43,4 +42,4 @@ function installCloudflareRequestEnv(event, fallback) {
|
|
|
43
42
|
const env = getCloudflareEnv(event, { fallback: false }) ?? fallback;
|
|
44
43
|
if (env) setActiveCloudflareEnv(env);
|
|
45
44
|
}
|
|
46
|
-
export {
|
|
45
|
+
export { installCloudflareRequestEnv as n, getActiveCloudflareBinding as t };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as invariant } from "./invariant-Dj2R1eMr.js";
|
|
2
|
-
import {
|
|
3
|
-
import { n as normalizeKVListPrefix, t as createKVStorage } from "./create-storage-
|
|
4
|
-
import { n as kvErrorDiagnostics } from "./error-diagnostics-
|
|
5
|
-
import { n as recordCursor, t as createCursorHistory } from "./cursor-history-
|
|
2
|
+
import { t as getActiveCloudflareBinding } from "./cloudflare-env-Cpy3Bqdn.js";
|
|
3
|
+
import { n as normalizeKVListPrefix, t as createKVStorage } from "./create-storage-DbWVAY9l.js";
|
|
4
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-CuVl1nvE.js";
|
|
5
|
+
import { n as recordCursor, t as createCursorHistory } from "./cursor-history-CMcEEnTO.js";
|
|
6
6
|
import { i as setItemsOneByOne, t as chunks } from "./batch-D-ib5_0P.js";
|
|
7
7
|
import createDriver from "unstorage/drivers/cloudflare-kv-binding";
|
|
8
8
|
// src/runtime/cloudflare-kv-limits.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as validateCloudflareKVBatch, i as installCloudflareKVLimits, r as assertCloudflareKVWrite, t as createCloudflareDriver } from "./cloudflare-kv-
|
|
3
|
-
import { t as createFsLiteKVDriver } from "./fs-lite-
|
|
1
|
+
import { t as getActiveCloudflareBinding } from "./cloudflare-env-Cpy3Bqdn.js";
|
|
2
|
+
import { a as validateCloudflareKVBatch, i as installCloudflareKVLimits, r as assertCloudflareKVWrite, t as createCloudflareDriver } from "./cloudflare-kv-Cp8HPUlJ.js";
|
|
3
|
+
import { t as createFsLiteKVDriver } from "./fs-lite-DzTTR6R3.js";
|
|
4
4
|
import { i as setItemsOneByOne, n as getItemsOneByOne } from "./batch-D-ib5_0P.js";
|
|
5
5
|
// src/runtime/cloudflare-kv-local.ts
|
|
6
6
|
function cloudflareExpirationSeconds(options) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { o as normalizeKey } from "./utils2-By8eee1x.js";
|
|
2
2
|
import { t as isRecord } from "./object-CAK6UYR5.js";
|
|
3
|
-
import { n as kvErrorDiagnostics } from "./error-diagnostics-
|
|
3
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-CuVl1nvE.js";
|
|
4
4
|
import { defu } from "defu";
|
|
5
5
|
// ../internal/src/env.ts
|
|
6
6
|
function trimmed(value) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as normalizeBaseKey, i as joinKeys, n as filterKeyByDepth, o as normalizeKey, r as hasDotSegment, t as filterKeyByBase } from "./utils2-By8eee1x.js";
|
|
2
|
-
import { n as kvErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-CuVl1nvE.js";
|
|
3
3
|
import { r as mapWithLimit } from "./batch-D-ib5_0P.js";
|
|
4
4
|
// ../../node_modules/.pnpm/unstorage@2.0.0-beta.0/node_modules/unstorage/dist/_chunks/libs/destr.mjs
|
|
5
5
|
const suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as invariant } from "./invariant-Dj2R1eMr.js";
|
|
2
|
-
import { n as kvErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-CuVl1nvE.js";
|
|
3
3
|
// src/runtime/cursor-history.ts
|
|
4
4
|
const MAX_CURSOR_HISTORIES = 1024;
|
|
5
5
|
const MAX_CURSORS_PER_HISTORY = 1024;
|
|
@@ -1,57 +1,35 @@
|
|
|
1
|
-
import { t as logFailure } from "
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t as chunks } from "../batch-D-ib5_0P.js";
|
|
1
|
+
import { t as logFailure } from "./request-log-DllKQXj7.js";
|
|
2
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-CuVl1nvE.js";
|
|
3
|
+
import { t as chunks } from "./batch-D-ib5_0P.js";
|
|
5
4
|
// src/runtime/database.ts
|
|
6
5
|
/** The table that keeps the keys of every `database` store. Each store has its rows under its own `namespace`. */
|
|
7
6
|
const kvTable = "vitehub_kv";
|
|
8
|
-
function isD1HttpClient(value) {
|
|
9
|
-
return typeof value === "object" && value !== null && Reflect.get(value, "protocol") === "d1-http" && hasMethod(value, "query");
|
|
10
|
-
}
|
|
11
|
-
function isRow(value) {
|
|
12
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13
|
-
}
|
|
14
|
-
function objectRows(rows) {
|
|
15
|
-
if (rows.every(isRow)) return rows;
|
|
16
|
-
throw kvErrorDiagnostics.KV_PROVIDER_INVALID_RESPONSE({ problem: "Cloudflare D1 returned rows without column names." });
|
|
17
|
-
}
|
|
18
|
-
const d1MaxParameters = 100;
|
|
19
7
|
function hasMethod(value, name) {
|
|
20
8
|
if ((typeof value !== "object" || value === null) && typeof value !== "function") return false;
|
|
21
9
|
return typeof Reflect.get(value, name) === "function";
|
|
22
10
|
}
|
|
23
11
|
/**
|
|
24
|
-
* A SQL client over the Drizzle database of the app
|
|
25
|
-
*
|
|
12
|
+
* A SQL client over the Drizzle database of the app. It reads `$client` on each query, because a Postgres Database on
|
|
13
|
+
* Cloudflare has a client per request.
|
|
26
14
|
*/
|
|
27
15
|
function kvSqlClientFromDatabase(db, database) {
|
|
28
|
-
const client = () => Reflect.get(db,
|
|
16
|
+
const client = () => Reflect.get(db, "$client");
|
|
29
17
|
const first = client();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
query: async (sql, params) => await client().unsafe(sql, params)
|
|
33
|
-
};
|
|
34
|
-
if (hasMethod(first, "execute")) return {
|
|
35
|
-
dialect: "sqlite",
|
|
36
|
-
query: async (sql, params) => (await client().execute({
|
|
37
|
-
sql,
|
|
38
|
-
args: params
|
|
39
|
-
})).rows
|
|
40
|
-
};
|
|
41
|
-
if (hasMethod(first, "prepare") && hasMethod(first, "batch")) return {
|
|
42
|
-
dialect: "sqlite",
|
|
43
|
-
maxParameters: d1MaxParameters,
|
|
44
|
-
query: async (sql, params) => (await client().prepare(sql).bind(...params).all()).results
|
|
45
|
-
};
|
|
46
|
-
if (isD1HttpClient(first)) return {
|
|
47
|
-
dialect: "sqlite",
|
|
48
|
-
maxParameters: d1MaxParameters,
|
|
49
|
-
query: async (sql, params) => objectRows(await client().query(sql, params, "write"))
|
|
50
|
-
};
|
|
51
|
-
throw kvErrorDiagnostics.KV_DATABASE_UNAVAILABLE({
|
|
18
|
+
const dialect = hasMethod(first, "unsafe") ? "postgresql" : hasMethod(first, "execute") ? "sqlite" : void 0;
|
|
19
|
+
if (!dialect) throw kvErrorDiagnostics.KV_DATABASE_UNAVAILABLE({
|
|
52
20
|
database,
|
|
53
21
|
problem: "unsupported"
|
|
54
22
|
});
|
|
23
|
+
return {
|
|
24
|
+
dialect,
|
|
25
|
+
async query(sql, params) {
|
|
26
|
+
if (dialect === "postgresql") return await client().unsafe(sql, params);
|
|
27
|
+
return (await client().execute({
|
|
28
|
+
sql,
|
|
29
|
+
args: params
|
|
30
|
+
})).rows;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
55
33
|
}
|
|
56
34
|
const sweepIntervalMs = 6e4;
|
|
57
35
|
const sweepBatchSize = 1e3;
|
|
@@ -74,10 +52,10 @@ function decodeCursor(cursor) {
|
|
|
74
52
|
/**
|
|
75
53
|
* KV in a table of the app's Database. Each atomic operation is one statement, so two servers that write one key at
|
|
76
54
|
* the same time get one winner. Expiry uses the clock of the Database. Works on Postgres and on SQLite 3.35 or later,
|
|
77
|
-
* such as libSQL
|
|
78
|
-
* out of reach of every KV store.
|
|
55
|
+
* such as libSQL.
|
|
79
56
|
*/
|
|
80
|
-
function createDatabaseKVDriver(options, connect
|
|
57
|
+
function createDatabaseKVDriver(options, connect) {
|
|
58
|
+
const table = kvTable;
|
|
81
59
|
const namespace = options.namespace;
|
|
82
60
|
let pending;
|
|
83
61
|
let sweptAt = 0;
|
|
@@ -149,17 +127,13 @@ function createDatabaseKVDriver(options, connect, table = kvTable) {
|
|
|
149
127
|
const [filter, params] = prefixFilter(prefix);
|
|
150
128
|
return (await query(`select "key" from ${table} where namespace = ? and ${live}${filter} order by "key"`, [namespace, ...params])).map((row) => String(row.key));
|
|
151
129
|
}
|
|
152
|
-
async function rowsPerStatement(parametersPerRow, fixedParameters = 0) {
|
|
153
|
-
const { maxParameters } = await ready();
|
|
154
|
-
return maxParameters === void 0 ? batchRows : Math.min(batchRows, Math.floor((maxParameters - fixedParameters) / parametersPerRow));
|
|
155
|
-
}
|
|
156
130
|
async function upsert(items, setOptions) {
|
|
157
131
|
sweep();
|
|
158
132
|
const ttl = setOptions?.ttl;
|
|
159
133
|
if (ttl !== void 0 && ttl !== null && ttl !== 0 && typeof ttl !== "number") throw kvErrorDiagnostics.KV_INVALID_TTL();
|
|
160
134
|
const ms = typeof ttl === "number" && ttl !== 0 ? ttlMilliseconds(ttl) : void 0;
|
|
161
135
|
const row = `(?, ?, ?, ${ms === void 0 ? "null" : "{now} + cast(? as bigint)"})`;
|
|
162
|
-
for (const batch of chunks(items,
|
|
136
|
+
for (const batch of chunks(items, batchRows)) await query(`insert into ${table} (namespace, "key", value, expires_at) values ${batch.map(() => row).join(", ")}
|
|
163
137
|
on conflict (namespace, "key") do update set value = excluded.value, expires_at = excluded.expires_at`, batch.flatMap((item) => ms === void 0 ? [
|
|
164
138
|
namespace,
|
|
165
139
|
item.key,
|
|
@@ -183,7 +157,7 @@ function createDatabaseKVDriver(options, connect, table = kvTable) {
|
|
|
183
157
|
},
|
|
184
158
|
async getItems(items) {
|
|
185
159
|
const values = /* @__PURE__ */ new Map();
|
|
186
|
-
for (const batch of chunks([...new Set(items.map((item) => item.key))],
|
|
160
|
+
for (const batch of chunks([...new Set(items.map((item) => item.key))], batchRows)) {
|
|
187
161
|
const rows = await query(`select "key", value from ${table} where namespace = ? and "key" in (${batch.map(() => "?").join(", ")}) and ${live}`, [namespace, ...batch]);
|
|
188
162
|
for (const row of rows) values.set(String(row.key), String(row.value));
|
|
189
163
|
}
|
|
@@ -277,4 +251,4 @@ function createDatabaseKVDriver(options, connect, table = kvTable) {
|
|
|
277
251
|
}
|
|
278
252
|
};
|
|
279
253
|
}
|
|
280
|
-
export { createDatabaseKVDriver as default, kvSqlClientFromDatabase
|
|
254
|
+
export { createDatabaseKVDriver as default, kvSqlClientFromDatabase };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as invariant } from "./invariant-Dj2R1eMr.js";
|
|
2
|
-
import { n as kvErrorDiagnostics } from "./error-diagnostics-
|
|
3
|
-
import { n as recordCursor, t as createCursorHistory } from "./cursor-history-
|
|
2
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-CuVl1nvE.js";
|
|
3
|
+
import { n as recordCursor, t as createCursorHistory } from "./cursor-history-CMcEEnTO.js";
|
|
4
4
|
// src/runtime/deno-kv.ts
|
|
5
5
|
const MAX_DENO_KEY_BYTES = 2048;
|
|
6
6
|
function getDenoRuntime() {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { i as TransactionOptions, t as Driver } from "./types-BUb0FcjM.js";
|
|
2
|
+
import { T as KVPageOptions, _ as KVListPage } from "./types-CPDL9enF.js";
|
|
3
|
+
type KVRuntimeDriver = Driver & Record<string, unknown> & {
|
|
4
|
+
validateBatch?: (items: Parameters<NonNullable<Driver["setItems"]>>[0], removals: string[], options?: TransactionOptions) => void | Promise<void>;
|
|
5
|
+
/** Deletes the key when it holds the serialized `expected` value. Resolves `true` when this call deleted it. */
|
|
6
|
+
deleteIfEqualsItem?: (key: string, expected: string) => Promise<boolean>;
|
|
7
|
+
getAndDeleteItem?: <T = unknown>(key: string) => Promise<T | null>;
|
|
8
|
+
incrementItem?: (key: string, ttl: number) => Promise<number>;
|
|
9
|
+
listKeys: (options: KVPageOptions) => Promise<KVListPage>;
|
|
10
|
+
/** Writes the serialized value only when the key is missing. Resolves `true` when this call wrote it. */
|
|
11
|
+
setIfAbsentItem?: (key: string, value: string, ttl?: number) => Promise<boolean>;
|
|
12
|
+
};
|
|
13
|
+
export { KVRuntimeDriver as t };
|
|
@@ -73,8 +73,8 @@ const kvErrorDiagnostics = /*#__PURE__*/ defineErrors({
|
|
|
73
73
|
fix: "Read the value in the app with `kv.get()`. The `kv.get` operation shows JSON values, bigint values, and bytes, without getters, symbols, or class instances."
|
|
74
74
|
},
|
|
75
75
|
KV_DATABASE_UNAVAILABLE: {
|
|
76
|
-
why: ({ database, problem }) => problem === "missing" ? `The KV \`database\` driver keeps keys in the Database "${database}", and the app has no Database with that name.` : `The KV \`database\` driver needs the Database "${database}" on
|
|
77
|
-
fix: ({ problem }) => problem === "missing" ? "Add a Database Definition, for example `server/database.ts` with `defineDatabase({ dialect: 'postgresql', schema: {} })`, or select another KV driver." : "
|
|
76
|
+
why: ({ database, problem }) => problem === "missing" ? `The KV \`database\` driver keeps keys in the Database "${database}", and the app has no Database with that name.` : `The KV \`database\` driver needs the Database "${database}" on Postgres or libSQL. It does not support D1.`,
|
|
77
|
+
fix: ({ problem }) => problem === "missing" ? "Add a Database Definition, for example `server/database.ts` with `defineDatabase({ dialect: 'postgresql', schema: {} })`, or select another KV driver." : "On Cloudflare, use the `cloudflare` driver. Elsewhere, point the Database at Postgres or libSQL."
|
|
78
78
|
},
|
|
79
79
|
KV_DENO_KV_UNAVAILABLE: {
|
|
80
80
|
why: "The `deno-kv` driver needs `Deno.openKv()`, and this runtime does not have it.",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as kvErrorDiagnostics, t as kvConfigErrorCodes } from "./error-diagnostics-
|
|
1
|
+
import { n as kvErrorDiagnostics, t as kvConfigErrorCodes } from "./error-diagnostics-CuVl1nvE.js";
|
|
2
2
|
import { isRuntimeDiagnostic, parseDuration, toResultError } from "@vite-hub/runtime";
|
|
3
3
|
// src/runtime/ttl.ts
|
|
4
4
|
/**
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as KVStoreOptions, C as KVOperation, D as KVStorage, E as KVSetOptions, T as KVPageOptions, _ as KVListPage, f as KVErrorCode, g as KVListOptions, j as ReadonlyKVStorage } from "./types-
|
|
1
|
+
import { A as KVStoreOptions, C as KVOperation, D as KVStorage, E as KVSetOptions, T as KVPageOptions, _ as KVListPage, f as KVErrorCode, g as KVListOptions, j as ReadonlyKVStorage } from "./types-CPDL9enF.js";
|
|
2
2
|
import { Result, ResultError } from "@vite-hub/runtime";
|
|
3
3
|
/**
|
|
4
4
|
* Returns the handle that `kv.store(name, options)` gives. An unknown mode throws, so a typo never gives a writable handle.
|
package/dist/errors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as kvClearOptionsError, n as kvInvalidLimitError, r as kvKeyLimitCodes, i as kvListLimitInvalid, a as kvResult, o as kvSetCodes, s as kvSetTTL, c as kvStoreNotFoundError, f as kvStoreWithMode, l as kvUnsupportedOperationError, u as kvWriteLimitCodes, d as listKVKeys } from "./errors-
|
|
1
|
+
export { t as kvClearOptionsError, n as kvInvalidLimitError, r as kvKeyLimitCodes, i as kvListLimitInvalid, a as kvResult, o as kvSetCodes, s as kvSetTTL, c as kvStoreNotFoundError, f as kvStoreWithMode, l as kvUnsupportedOperationError, u as kvWriteLimitCodes, d as listKVKeys } from "./errors-CJoAP4Bu.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as default } from "./fs-lite-DzTTR6R3.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as kvErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-CuVl1nvE.js";
|
|
2
2
|
import { link, lstat, mkdir, mkdtemp, opendir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
3
3
|
import { basename, join, relative, resolve, sep } from "node:path";
|
|
4
4
|
import createDriver from "unstorage/drivers/fs-lite";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as KVStoreOptions, B as ResolvedUpstashKVStoreConfig, C as KVOperation, D as KVStorage, E as KVSetOptions, F as ResolvedDenoKVStoreConfig, I as ResolvedFsLiteKVStoreConfig, L as ResolvedKVModuleOptions, M as RedisKVStoreConfig, N as ResolvedCloudflareKVStoreConfig, O as KVStoreConfig, P as ResolvedDatabaseKVStoreConfig, R as ResolvedKVStoreConfig, S as KVLockRunResult, V as UpstashKVStoreConfig, _ as KVListPage, a as InferredKVStoreConfig, b as KVLockErrorCode, c as KVDriver, d as KVEntry, f as KVErrorCode, g as KVListOptions, h as KVGetTypeMap, i as FsLiteKVStoreConfig, j as ReadonlyKVStorage, k as KVStoreName, l as KVDriverAtomicOperations, m as KVGetType, n as DatabaseKVStoreConfig, o as KVAtomicOperation, p as KVGetOptions, r as DenoKVStoreConfig, s as KVClearOptions, t as CloudflareKVStoreConfig, u as KVDriversWith, v as KVLock, w as KVOptions, x as KVLockOptions, y as KVLockAcquisition, z as ResolvedRedisKVStoreConfig } from "./types-
|
|
1
|
+
import { A as KVStoreOptions, B as ResolvedUpstashKVStoreConfig, C as KVOperation, D as KVStorage, E as KVSetOptions, F as ResolvedDenoKVStoreConfig, I as ResolvedFsLiteKVStoreConfig, L as ResolvedKVModuleOptions, M as RedisKVStoreConfig, N as ResolvedCloudflareKVStoreConfig, O as KVStoreConfig, P as ResolvedDatabaseKVStoreConfig, R as ResolvedKVStoreConfig, S as KVLockRunResult, V as UpstashKVStoreConfig, _ as KVListPage, a as InferredKVStoreConfig, b as KVLockErrorCode, c as KVDriver, d as KVEntry, f as KVErrorCode, g as KVListOptions, h as KVGetTypeMap, i as FsLiteKVStoreConfig, j as ReadonlyKVStorage, k as KVStoreName, l as KVDriverAtomicOperations, m as KVGetType, n as DatabaseKVStoreConfig, o as KVAtomicOperation, p as KVGetOptions, r as DenoKVStoreConfig, s as KVClearOptions, t as CloudflareKVStoreConfig, u as KVDriversWith, v as KVLock, w as KVOptions, x as KVLockOptions, y as KVLockAcquisition, z as ResolvedRedisKVStoreConfig } from "./types-CPDL9enF.js";
|
|
2
2
|
/** Releases every cached store. Call from the application's shutdown hook after stopping new work. */
|
|
3
3
|
export declare function disposeKVStores(): Promise<void>;
|
|
4
4
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { r as normalizeKVOptions, s as readEnv } from "./config-
|
|
1
|
+
import { r as normalizeKVOptions, s as readEnv } from "./config-_1oBDv2R.js";
|
|
2
2
|
import { n as getActiveCloudflareEnv } from "./cloudflare-env-lookup-Dgq5n1Aq.js";
|
|
3
|
-
import { a as kvResult, d as listKVKeys, f as kvStoreWithMode, i as kvListLimitInvalid, o as kvSetCodes, p as ttlSeconds, r as kvKeyLimitCodes, s as kvSetTTL, t as kvClearOptionsError } from "./errors-
|
|
3
|
+
import { a as kvResult, d as listKVKeys, f as kvStoreWithMode, i as kvListLimitInvalid, o as kvSetCodes, p as ttlSeconds, r as kvKeyLimitCodes, s as kvSetTTL, t as kvClearOptionsError } from "./errors-CJoAP4Bu.js";
|
|
4
4
|
import { o as normalizeKey } from "./utils2-By8eee1x.js";
|
|
5
|
-
import { n as kvErrorDiagnostics } from "./error-diagnostics-
|
|
6
|
-
import { t as resolveRuntimeKVOptions } from "./upstash-
|
|
5
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-CuVl1nvE.js";
|
|
6
|
+
import { t as resolveRuntimeKVOptions } from "./upstash-DeM3_U5H.js";
|
|
7
7
|
import { i as setItemsOneByOne, n as getItemsOneByOne } from "./batch-D-ib5_0P.js";
|
|
8
|
-
import { n as normalizeKVListPrefix, t as createKVStorage$1 } from "./create-storage-
|
|
8
|
+
import { n as normalizeKVListPrefix, t as createKVStorage$1 } from "./create-storage-DbWVAY9l.js";
|
|
9
9
|
import { t as logFailure } from "./request-log-DllKQXj7.js";
|
|
10
10
|
import { getViteHubTestMode } from "@vite-hub/runtime/internal/test-mode";
|
|
11
11
|
import { destr } from "destr";
|
|
@@ -59,7 +59,7 @@ const otherOptionalDriverMethods = {
|
|
|
59
59
|
const batchDriverMethods = /* @__PURE__ */ new Set(["getItems", "setItems"]);
|
|
60
60
|
const lazyOptionalDriverMethods = Object.fromEntries(Object.entries(driverAtomicOperations).map(([driver, operations]) => [driver, /* @__PURE__ */ new Set([...Object.keys(operations).map((operation) => atomicDriverMethods[operation]), ...otherOptionalDriverMethods[driver] ?? []])]));
|
|
61
61
|
async function createDatabaseDriver(store, loadDatabases) {
|
|
62
|
-
const { default: factory, kvSqlClientFromDatabase } = await import("./
|
|
62
|
+
const { default: factory, kvSqlClientFromDatabase } = await import("./database-4iAg2GoV.js");
|
|
63
63
|
return factory(store, async () => {
|
|
64
64
|
const entry = loadDatabases ? (await loadDatabases())[store.database] : void 0;
|
|
65
65
|
if (!entry) throw kvErrorDiagnostics.KV_DATABASE_UNAVAILABLE({
|
|
@@ -74,7 +74,7 @@ async function createRuntimeDriver(store, loadDatabases) {
|
|
|
74
74
|
case "cloudflare": {
|
|
75
75
|
const { localBase } = store;
|
|
76
76
|
if (localBase) {
|
|
77
|
-
const { default: factory } = await import("./cloudflare-kv-local-
|
|
77
|
+
const { default: factory } = await import("./cloudflare-kv-local-COoOI34K.js");
|
|
78
78
|
return factory({
|
|
79
79
|
...store,
|
|
80
80
|
localBase
|
|
@@ -85,11 +85,11 @@ async function createRuntimeDriver(store, loadDatabases) {
|
|
|
85
85
|
}
|
|
86
86
|
case "database": return createDatabaseDriver(store, loadDatabases);
|
|
87
87
|
case "deno-kv": {
|
|
88
|
-
const { default: factory } = await import("./deno-kv-
|
|
88
|
+
const { default: factory } = await import("./deno-kv-CatE7zSS.js");
|
|
89
89
|
return factory(store);
|
|
90
90
|
}
|
|
91
91
|
case "fs-lite": {
|
|
92
|
-
const { default: factory } = await import("./fs-lite-
|
|
92
|
+
const { default: factory } = await import("./fs-lite-DwbPkc-C.js");
|
|
93
93
|
return factory(store);
|
|
94
94
|
}
|
|
95
95
|
case "redis": {
|
|
@@ -922,7 +922,8 @@ const reservedOperationNamespaces = [
|
|
|
922
922
|
"login",
|
|
923
923
|
"logout",
|
|
924
924
|
"update",
|
|
925
|
-
"whoami"
|
|
925
|
+
"whoami",
|
|
926
|
+
"apps"
|
|
926
927
|
]
|
|
927
928
|
];
|
|
928
929
|
/** Input keys that the generated CLI commands read themselves. */
|
|
@@ -1294,7 +1295,7 @@ async function callOperation(target, name, input) {
|
|
|
1294
1295
|
const url = new URL(operationRpcPath.slice(1), base);
|
|
1295
1296
|
origin = url.origin;
|
|
1296
1297
|
const env = target.roots?.length ? {} : target.env;
|
|
1297
|
-
try {
|
|
1298
|
+
if (!target.authorization) try {
|
|
1298
1299
|
readConsoleSigningKey(env);
|
|
1299
1300
|
} catch (error) {
|
|
1300
1301
|
return {
|
|
@@ -1306,15 +1307,18 @@ async function callOperation(target, name, input) {
|
|
|
1306
1307
|
};
|
|
1307
1308
|
}
|
|
1308
1309
|
const outcome = await callOperationRpc(name, input ?? {}, async (body) => {
|
|
1309
|
-
const
|
|
1310
|
+
const signal = target.signal ?? AbortSignal.timeout(target.timeout ?? 3e4);
|
|
1311
|
+
const headers = target.authorization ? operationHeaders() : await signedOperationHeaders(env, url, body);
|
|
1312
|
+
if (target.authorization) headers.set("authorization", target.authorization);
|
|
1310
1313
|
if (target.confirmed !== void 0) headers.set(operationConfirmationHeader, target.confirmed ? "confirmed" : "required");
|
|
1311
1314
|
if (target.roots?.length) headers.set(operationExpectedRootsHeader, target.roots.map(projectRootHash).join(","));
|
|
1315
|
+
signal.throwIfAborted();
|
|
1312
1316
|
const response = await (target.fetch ?? fetch)(url.href, {
|
|
1313
1317
|
body,
|
|
1314
1318
|
headers,
|
|
1315
1319
|
method: "POST",
|
|
1316
1320
|
redirect: "manual",
|
|
1317
|
-
signal
|
|
1321
|
+
signal
|
|
1318
1322
|
});
|
|
1319
1323
|
const text = await response.text();
|
|
1320
1324
|
let json;
|
|
@@ -1351,7 +1355,7 @@ async function callOperation(target, name, input) {
|
|
|
1351
1355
|
} : void 0);
|
|
1352
1356
|
if (failure) {
|
|
1353
1357
|
if (target.roots?.length && failure.status === 401) failure.fix = `Pass --url ${base.href.slice(0, -1)} to send credentials. A command sends none to the dev server that it finds. ${failure.fix ?? "Set VITEHUB_CONSOLE_PRIVATE_KEY_<NAME> to a private key that `vitehub secret console-key` printed, and its public key in VITEHUB_CONSOLE_KEY_<NAME> on the app."}`;
|
|
1354
|
-
if ((failure.status === 401 || failure.status === 403) && !hasCredentials(env) && !failure.fix) failure.fix = target.roots?.length ? `Pass --url <origin> to send deployment credentials. ${operationCredentialHint}` : operationCredentialHint;
|
|
1358
|
+
if ((failure.status === 401 || failure.status === 403) && !target.authorization && !hasCredentials(env) && !failure.fix) failure.fix = target.roots?.length ? `Pass --url <origin> to send deployment credentials. ${operationCredentialHint}` : operationCredentialHint;
|
|
1355
1359
|
return {
|
|
1356
1360
|
ok: false,
|
|
1357
1361
|
...failure
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { o as normalizeKey } from "./utils2-By8eee1x.js";
|
|
2
2
|
import { t as redactInspectionText } from "./inspect-BWMcVWD8.js";
|
|
3
|
-
import { n as kvErrorDiagnostics } from "./error-diagnostics-
|
|
3
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-CuVl1nvE.js";
|
|
4
4
|
import { t as kvDevMaximumListLimit } from "./results-emgN7uDS.js";
|
|
5
5
|
import { kv } from "@vite-hub/kv";
|
|
6
6
|
// src/runtime/inspect-value.ts
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as AnyOperation } from "./operation-definition-CqZkx1Rm.js";
|
|
2
|
-
import { c as KVDriver } from "./types-
|
|
2
|
+
import { c as KVDriver } from "./types-CPDL9enF.js";
|
|
3
3
|
interface KVDevListResult {
|
|
4
4
|
/** Present when more keys exist. Pass it as `--cursor` to read the next page. */
|
|
5
5
|
cursor?: string;
|
package/dist/operations.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as internalErrorDiagnostics, a as operationRootHeader, c as projectRootHash, d as defineOperation, f as answerOperationRpc, h as readOperationRpcCall, i as createOperationRegistry, l as runOperation, m as operationRpcRefusal, o as operationRpcHeader, s as operationsOf, t as assertOperationProject, u as toOperationFailure } from "./operations-
|
|
1
|
+
import { P as internalErrorDiagnostics, a as operationRootHeader, c as projectRootHash, d as defineOperation, f as answerOperationRpc, h as readOperationRpcCall, i as createOperationRegistry, l as runOperation, m as operationRpcRefusal, o as operationRpcHeader, s as operationsOf, t as assertOperationProject, u as toOperationFailure } from "./operations-BkVt17cd.js";
|
|
2
2
|
import { t as kvDevMaximumListLimit } from "./results-emgN7uDS.js";
|
|
3
3
|
import { n as isViteHubLoopbackPeer } from "./dev-peer-D0vOxmrD.js";
|
|
4
4
|
import * as v from "valibot";
|
|
@@ -235,7 +235,7 @@ function createStandaloneOperationHandler(sources, root) {
|
|
|
235
235
|
} };
|
|
236
236
|
}
|
|
237
237
|
// src/operations.ts
|
|
238
|
-
const runtime = () => import("./operations-
|
|
238
|
+
const runtime = () => import("./operations-DSOTGwST.js");
|
|
239
239
|
const store = v.optional(v.pipe(v.string(), v.check((name) => name.trim() !== "", "Name a store.")));
|
|
240
240
|
const key = v.string();
|
|
241
241
|
function defineKVOperation(definition) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as KVRuntimeDriver } from "../driver-
|
|
1
|
+
import { t as KVRuntimeDriver } from "../driver-BruahGvT.js";
|
|
2
2
|
declare function createCloudflareDriver(options: Record<string, unknown>): KVRuntimeDriver;
|
|
3
3
|
export declare function createCloudflareKVStorage(options: Record<string, unknown>): unknown;
|
|
4
4
|
export { createCloudflareDriver as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { n as createCloudflareKVStorage, t as default } from "../cloudflare-kv-
|
|
1
|
+
export { n as createCloudflareKVStorage, t as default } from "../cloudflare-kv-Cp8HPUlJ.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as installCloudflareRequestEnv } from "../cloudflare-env-Cpy3Bqdn.js";
|
|
2
2
|
// src/runtime/cloudflare-request-env.ts
|
|
3
3
|
/**
|
|
4
4
|
* Nitro middleware for Cloudflare KV. A Cloudflare KV store reads its binding from the active env, and only the request
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as logFailure } from "../request-log-DllKQXj7.js";
|
|
2
|
-
import { t as kvInferredStoreNotice } from "../config-
|
|
2
|
+
import { t as kvInferredStoreNotice } from "../config-_1oBDv2R.js";
|
|
3
3
|
import { disposeKVStores } from "@vite-hub/kv";
|
|
4
4
|
// src/runtime/nitro-plugin.ts
|
|
5
5
|
async function logInferredStores() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { z as ResolvedRedisKVStoreConfig } from "../types-
|
|
2
|
-
import { t as KVRuntimeDriver } from "../driver-
|
|
1
|
+
import { z as ResolvedRedisKVStoreConfig } from "../types-CPDL9enF.js";
|
|
2
|
+
import { t as KVRuntimeDriver } from "../driver-BruahGvT.js";
|
|
3
3
|
/** The URL of a store: `env:<NAME>` reads the variable now, so a build never holds the URL of its server. */
|
|
4
4
|
export declare function resolveRedisUrl(url: string, env?: Record<string, string | undefined>): string;
|
|
5
5
|
/**
|
|
@@ -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-CuVl1nvE.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-CR3ANc_N.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. */
|
|
@@ -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-CPDL9enF.js";
|
|
2
|
+
import { t as KVRuntimeDriver } from "../driver-BruahGvT.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-CuVl1nvE.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-CR3ANc_N.js";
|
|
6
6
|
import createDriver from "unstorage/drivers/upstash";
|
|
7
7
|
// src/runtime/upstash-driver.ts
|
|
8
8
|
const keyBatchSize = 1e3;
|
|
@@ -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
|
|
67
|
+
* it is missing. Postgres and libSQL work. D1 does not.
|
|
68
68
|
*/
|
|
69
69
|
database?: string;
|
|
70
70
|
/** A Database store uses the Database of the app, in `vite dev` too. */
|
|
@@ -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-_1oBDv2R.js";
|
|
2
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-CuVl1nvE.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,4 +1,4 @@
|
|
|
1
|
-
import { L as ResolvedKVModuleOptions, w as KVOptions } from "./types-
|
|
1
|
+
import { L as ResolvedKVModuleOptions, w as KVOptions } from "./types-CPDL9enF.js";
|
|
2
2
|
import { r as ViteHubCliPluginMetadata } from "./cli-BvVInMht.js";
|
|
3
3
|
import { n as OperationContributionEntry } from "./operation-definition-CqZkx1Rm.js";
|
|
4
4
|
import "nostics";
|
package/dist/vite.js
CHANGED
|
@@ -3,10 +3,10 @@ import { n as invariantError, t as invariant } from "./invariant-Dj2R1eMr.js";
|
|
|
3
3
|
import { a as resolve$1, i as relative$1, n as relativeDefinitionFile, r as dirname$1 } from "./inspect-BWMcVWD8.js";
|
|
4
4
|
import { t as addViteHubDevPeerDevHandler } from "./dev-peer-D0vOxmrD.js";
|
|
5
5
|
import { n as isRecordOrFunction, t as isRecord } from "./object-CAK6UYR5.js";
|
|
6
|
-
import { C as resolveViteHubProjectRoot, N as writeViteHubDevServerFile, P as internalErrorDiagnostics, S as markViteConfigPlugin, b as hasNitroConfigContext, j as removeViteHubDevServerFile, k as readViteHubDevServerFile, p as operationRpcPath, r as collectOperationContributions, v as VITEHUB_PROJECT_ROOT, w as shouldSkipViteProviderBuild, x as isServerEnvironment, y as createNoExternalAddition } from "./operations-
|
|
7
|
-
import { a as upstashUrlEnvNames, i as upstashTokenEnvNames, n as kvRedisEnvHint, o as resolveHostPreset, r as normalizeKVOptions } from "./config-
|
|
8
|
-
import { n as kvErrorDiagnostics } from "./error-diagnostics-
|
|
9
|
-
import { n as resolveUpstashRuntimeValues } from "./upstash-
|
|
6
|
+
import { C as resolveViteHubProjectRoot, N as writeViteHubDevServerFile, P as internalErrorDiagnostics, S as markViteConfigPlugin, b as hasNitroConfigContext, j as removeViteHubDevServerFile, k as readViteHubDevServerFile, p as operationRpcPath, r as collectOperationContributions, v as VITEHUB_PROJECT_ROOT, w as shouldSkipViteProviderBuild, x as isServerEnvironment, y as createNoExternalAddition } from "./operations-BkVt17cd.js";
|
|
7
|
+
import { a as upstashUrlEnvNames, i as upstashTokenEnvNames, n as kvRedisEnvHint, o as resolveHostPreset, r as normalizeKVOptions } from "./config-_1oBDv2R.js";
|
|
8
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-CuVl1nvE.js";
|
|
9
|
+
import { n as resolveUpstashRuntimeValues } from "./upstash-DeM3_U5H.js";
|
|
10
10
|
import { createRequire, isBuiltin } from "node:module";
|
|
11
11
|
import { access, copyFile, cp, mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
|
|
12
12
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
@@ -405,7 +405,11 @@ const encodedAliasExactMarker = "\0vitehub-exact:";
|
|
|
405
405
|
/** Select the runtime constants from one resolved Vite configuration. */
|
|
406
406
|
function resolveViteHubBundleDefines(config) {
|
|
407
407
|
const defines = {};
|
|
408
|
-
for (const name of [
|
|
408
|
+
for (const name of [
|
|
409
|
+
"__VITEHUB_PUBLIC_URL__",
|
|
410
|
+
"__VITEHUB_APP_BASE_URL__",
|
|
411
|
+
"__VITEHUB_CONSOLE_URL__"
|
|
412
|
+
]) {
|
|
409
413
|
const value = config.define?.[name];
|
|
410
414
|
if (typeof value === "string") defines[name] = value;
|
|
411
415
|
}
|
|
@@ -800,20 +804,20 @@ function createFileUrlPlugin() {
|
|
|
800
804
|
}
|
|
801
805
|
};
|
|
802
806
|
}
|
|
803
|
-
/**
|
|
804
|
-
* Copies a `.wasm?module` import next to the bundle and keeps it as a relative `.wasm` import. Wrangler and Nitro load
|
|
805
|
-
* such an import as a compiled WebAssembly module, which Workers need because they can't compile WebAssembly bytes.
|
|
806
|
-
* Node.js compiles WebAssembly bytes, so there the import becomes the bytes of the file.
|
|
807
|
-
*/
|
|
808
807
|
function createWasmModulePlugin(outdir, workingDir, copy) {
|
|
809
808
|
return {
|
|
810
809
|
name: "vitehub-wasm-module",
|
|
811
810
|
async resolveId(source, importer, extra) {
|
|
812
|
-
|
|
813
|
-
|
|
811
|
+
const explicitModule = source.endsWith(".wasm?module");
|
|
812
|
+
if (!explicitModule && (!copy || !source.endsWith(".wasm") || extra.custom?.[skipMarkdownTemplateResolve])) return;
|
|
813
|
+
const path = explicitModule ? source.slice(0, -7) : source;
|
|
814
|
+
const resolved = await this.resolve(path, importerFor(importer, workingDir), {
|
|
814
815
|
custom: extra.custom,
|
|
815
|
-
|
|
816
|
+
isEntry: extra.isEntry,
|
|
817
|
+
kind: extra.kind,
|
|
818
|
+
skipSelf: true
|
|
816
819
|
});
|
|
820
|
+
if (!explicitModule && (!isFileResolution(resolved) || !resolved.id.endsWith(".wasm"))) return resolved ?? void 0;
|
|
817
821
|
if (!isFileResolution(resolved)) this.error(`[vitehub] Could not resolve ${JSON.stringify(source)}.`);
|
|
818
822
|
if (!copy) return resolved.id;
|
|
819
823
|
const bytes = await readFile(resolved.id);
|
|
@@ -5585,7 +5589,8 @@ function configureNitroCloudflareRequestEnv(nitro, kv) {
|
|
|
5585
5589
|
const handlers = Array.isArray(nitro.handlers) ? nitro.handlers.filter((handler) => !(isRecord(handler) && handler.handler === KV_CLOUDFLARE_REQUEST_ENV_MIDDLEWARE)) : [];
|
|
5586
5590
|
if (hasCloudflareKVStore(kv)) handlers.unshift({
|
|
5587
5591
|
handler: KV_CLOUDFLARE_REQUEST_ENV_MIDDLEWARE,
|
|
5588
|
-
middleware: true
|
|
5592
|
+
middleware: true,
|
|
5593
|
+
route: "/**"
|
|
5589
5594
|
});
|
|
5590
5595
|
if (handlers.length || Array.isArray(nitro.handlers)) nitro.handlers = handlers;
|
|
5591
5596
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/kv",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Vite-first key-value storage primitives and integration for ViteHub.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -46,11 +46,6 @@
|
|
|
46
46
|
"import": "./dist/durability.js",
|
|
47
47
|
"default": "./dist/durability.js"
|
|
48
48
|
},
|
|
49
|
-
"./runtime/database": {
|
|
50
|
-
"types": "./dist/runtime/database.d.ts",
|
|
51
|
-
"import": "./dist/runtime/database.js",
|
|
52
|
-
"default": "./dist/runtime/database.js"
|
|
53
|
-
},
|
|
54
49
|
"./runtime/redis-driver": {
|
|
55
50
|
"types": "./dist/runtime/redis-driver.d.ts",
|
|
56
51
|
"import": "./dist/runtime/redis-driver.js",
|
|
@@ -75,7 +70,7 @@
|
|
|
75
70
|
},
|
|
76
71
|
"dependencies": {
|
|
77
72
|
"@valibot/to-json-schema": "^1.8.0",
|
|
78
|
-
"@vite-hub/runtime": "0.
|
|
73
|
+
"@vite-hub/runtime": "0.6.1",
|
|
79
74
|
"birpc": "^4.2.0",
|
|
80
75
|
"defu": "^6.1.7",
|
|
81
76
|
"destr": "^2.0.5",
|
|
@@ -88,7 +83,7 @@
|
|
|
88
83
|
"devDependencies": {
|
|
89
84
|
"@types/node": "^24.19.2",
|
|
90
85
|
"@libsql/client": "^0.18.0",
|
|
91
|
-
"@vite-hub/database": "0.
|
|
86
|
+
"@vite-hub/database": "0.6.1",
|
|
92
87
|
"@types/proper-lockfile": "4.1.4",
|
|
93
88
|
"@vite-hub/internal": "0.0.1",
|
|
94
89
|
"ofetch": "^1.5.1",
|
|
@@ -101,7 +96,7 @@
|
|
|
101
96
|
},
|
|
102
97
|
"peerDependencies": {
|
|
103
98
|
"@upstash/redis": "^1.41.0",
|
|
104
|
-
"@vite-hub/database": "0.
|
|
99
|
+
"@vite-hub/database": "0.6.1",
|
|
105
100
|
"vite": ">=8.0.0"
|
|
106
101
|
},
|
|
107
102
|
"peerDependenciesMeta": {
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { i as TransactionOptions, t as Driver } from "./types-BUb0FcjM.js";
|
|
2
|
-
import { P as ResolvedDatabaseKVStoreConfig, T as KVPageOptions, _ as KVListPage } from "./types-C397WKyf.js";
|
|
3
|
-
/** The table that keeps the keys of every `database` store. Each store has its rows under its own `namespace`. */
|
|
4
|
-
declare const kvTable = "vitehub_kv";
|
|
5
|
-
type KVSqlParam = string | number | null;
|
|
6
|
-
/**
|
|
7
|
-
* Runs one statement and resolves its rows as objects keyed by column name. `postgresql` SQL uses `$1`, `$2`, ... and
|
|
8
|
-
* `sqlite` SQL uses `?`.
|
|
9
|
-
*/
|
|
10
|
-
interface KVSqlClient {
|
|
11
|
-
dialect: "postgresql" | "sqlite";
|
|
12
|
-
/** The most values that one statement may bind, such as 100 on Cloudflare D1. */
|
|
13
|
-
maxParameters?: number;
|
|
14
|
-
query(sql: string, params: KVSqlParam[]): Promise<readonly Record<string, unknown>[]>;
|
|
15
|
-
}
|
|
16
|
-
/** The databases of the app, as `@vite-hub/database/runtime/registry` exports them. */
|
|
17
|
-
type KVDatabases = Record<string, {
|
|
18
|
-
db: object;
|
|
19
|
-
} | undefined>;
|
|
20
|
-
/**
|
|
21
|
-
* A SQL client over the Drizzle database of the app: postgres.js, libSQL, primary Cloudflare D1, or D1 over HTTP. It resolves
|
|
22
|
-
* the client on each query because the Database connection can belong to the request.
|
|
23
|
-
*/
|
|
24
|
-
declare function kvSqlClientFromDatabase(db: object, database: string): KVSqlClient;
|
|
25
|
-
type DatabaseKVDriver = KVRuntimeDriver & Required<Pick<KVRuntimeDriver, "getItems">>;
|
|
26
|
-
/**
|
|
27
|
-
* KV in a table of the app's Database. Each atomic operation is one statement, so two servers that write one key at
|
|
28
|
-
* the same time get one winner. Expiry uses the clock of the Database. Works on Postgres and on SQLite 3.35 or later,
|
|
29
|
-
* such as libSQL and Cloudflare D1. `table` defaults to `vitehub_kv`. A caller that passes another table keeps its rows
|
|
30
|
-
* out of reach of every KV store.
|
|
31
|
-
*/
|
|
32
|
-
declare function createDatabaseKVDriver(options: ResolvedDatabaseKVStoreConfig, connect: () => Promise<KVSqlClient>, table?: string): DatabaseKVDriver;
|
|
33
|
-
type KVRuntimeDriver = Driver & Record<string, unknown> & {
|
|
34
|
-
validateBatch?: (items: Parameters<NonNullable<Driver["setItems"]>>[0], removals: string[], options?: TransactionOptions) => void | Promise<void>;
|
|
35
|
-
/** Deletes the key when it holds the serialized `expected` value. Resolves `true` when this call deleted it. */
|
|
36
|
-
deleteIfEqualsItem?: (key: string, expected: string) => Promise<boolean>;
|
|
37
|
-
getAndDeleteItem?: <T = unknown>(key: string) => Promise<T | null>;
|
|
38
|
-
incrementItem?: (key: string, ttl: number) => Promise<number>;
|
|
39
|
-
listKeys: (options: KVPageOptions) => Promise<KVListPage>;
|
|
40
|
-
/** Writes the serialized value only when the key is missing. Resolves `true` when this call wrote it. */
|
|
41
|
-
setIfAbsentItem?: (key: string, value: string, ttl?: number) => Promise<boolean>;
|
|
42
|
-
};
|
|
43
|
-
export { createDatabaseKVDriver as a, KVSqlParam as i, KVDatabases as n, kvSqlClientFromDatabase as o, KVSqlClient as r, kvTable as s, KVRuntimeDriver as t };
|
package/dist/fs-lite-DhXLUL-H.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { t as default } from "./fs-lite-fvNdBEr9.js";
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { a as createDatabaseKVDriver, i as KVSqlParam, n as KVDatabases, o as kvSqlClientFromDatabase, r as KVSqlClient, s as kvTable } from "../driver-bLMl-wMO.js";
|
|
2
|
-
export { KVDatabases, KVSqlClient, KVSqlParam, createDatabaseKVDriver as default, kvSqlClientFromDatabase, kvTable };
|