@vite-hub/kv 0.0.4 → 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 +110 -14
- package/dist/batch--v0ri69O.js +40 -0
- package/dist/cli-DpPhz_Ek.d.ts +163 -0
- package/dist/cli.d.ts +17 -0
- package/dist/cli.js +469 -0
- 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/{dist-DDW1iC5f.js → create-storage-BGsrQKw3.js} +266 -115
- package/dist/cursor-history-BqIQePNP.js +165 -0
- package/dist/database-72Jk3VVk.js +250 -0
- package/dist/deno-kv-BM9mYdUp.js +128 -0
- 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 +23 -7
- package/dist/errors.js +2 -20
- package/dist/fs-lite-BLZId9_P.js +386 -0
- package/dist/fs-lite-RAoxu8L0.js +2 -0
- package/dist/index.d.ts +10 -4
- package/dist/index.js +364 -109
- 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/operation-definition-8gOe-ubD.d.ts +234 -0
- package/dist/operations-B-WZ7P1h.js +1351 -0
- package/dist/operations-Ch-gKaey.js +441 -0
- package/dist/operations.d.ts +75 -0
- package/dist/operations.js +318 -0
- package/dist/redis-shared-E5mahECF.js +94 -0
- package/dist/results-p7nPCnaJ.js +6 -0
- package/dist/rolldown-runtime-CMFfr-1z.js +26 -0
- package/dist/runtime/cloudflare-kv.d.ts +3 -4
- package/dist/runtime/cloudflare-kv.js +1 -23
- 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 +4 -6
- package/dist/runtime/upstash-driver.js +60 -110
- package/dist/{driver-BT9WefKi.d.ts → types-Bj3EQoRg.d.ts} +16 -11
- package/dist/types-DEiKew_3.d.ts +312 -0
- package/dist/upstash-DDlqTttY.js +40 -0
- package/dist/utils2-FozcTsmb.js +31 -0
- package/dist/virtual-module.d.ts +2 -0
- package/dist/virtual.d.ts +1 -1
- package/dist/vite.d.ts +159 -14
- package/dist/vite.js +1329 -2898
- package/package.json +68 -19
- package/dist/config-aM9Ae7tH.js +0 -110
- package/dist/deno-kv-cJx3jU10.js +0 -69
- package/dist/fs-lite-BxzdiJSi.js +0 -79
- package/dist/types-CO0DRjJa.d.ts +0 -78
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-BxqvtEIb.js";
|
|
2
|
+
import { link, lstat, mkdir, mkdtemp, opendir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import { basename, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
import createDriver from "unstorage/drivers/fs-lite";
|
|
5
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
6
|
+
import { lock } from "proper-lockfile";
|
|
7
|
+
//#region src/runtime/continuations.ts
|
|
8
|
+
/** Owns process-local cursor retention. Taking a cursor transfers its resource to the caller. */
|
|
9
|
+
function createKVContinuations(options) {
|
|
10
|
+
const entries = /* @__PURE__ */ new Map();
|
|
11
|
+
const releases = /* @__PURE__ */ new Set();
|
|
12
|
+
const failures = [];
|
|
13
|
+
let bytes = 0;
|
|
14
|
+
let disposed = false;
|
|
15
|
+
function take(cursor) {
|
|
16
|
+
const entry = entries.get(cursor);
|
|
17
|
+
if (!entry) return void 0;
|
|
18
|
+
clearTimeout(entry.timeout);
|
|
19
|
+
entries.delete(cursor);
|
|
20
|
+
bytes -= entry.bytes;
|
|
21
|
+
return entry.value;
|
|
22
|
+
}
|
|
23
|
+
function release(value, surfaceFailure = false) {
|
|
24
|
+
const pending = Promise.resolve().then(() => options.release?.(value)).then(() => void 0).catch((error) => {
|
|
25
|
+
if (failures.length === 0) failures.push(error);
|
|
26
|
+
if (surfaceFailure) throw error;
|
|
27
|
+
}).finally(() => {
|
|
28
|
+
releases.delete(pending);
|
|
29
|
+
});
|
|
30
|
+
releases.add(pending);
|
|
31
|
+
return pending;
|
|
32
|
+
}
|
|
33
|
+
function evict(cursor) {
|
|
34
|
+
const value = take(cursor);
|
|
35
|
+
if (value !== void 0) release(value);
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
take,
|
|
39
|
+
async retain(value, size = 0) {
|
|
40
|
+
if (disposed) {
|
|
41
|
+
await release(value, true);
|
|
42
|
+
throw options.expired();
|
|
43
|
+
}
|
|
44
|
+
while (entries.size >= 32 || bytes + size > (options.maximumBytes ?? Number.POSITIVE_INFINITY)) {
|
|
45
|
+
const oldest = entries.keys().next().value;
|
|
46
|
+
if (!oldest) break;
|
|
47
|
+
evict(oldest);
|
|
48
|
+
}
|
|
49
|
+
const cursor = globalThis.crypto.randomUUID();
|
|
50
|
+
const timeout = setTimeout(() => evict(cursor), 9e5);
|
|
51
|
+
timeout.unref?.();
|
|
52
|
+
entries.set(cursor, {
|
|
53
|
+
value,
|
|
54
|
+
bytes: size,
|
|
55
|
+
timeout
|
|
56
|
+
});
|
|
57
|
+
bytes += size;
|
|
58
|
+
return cursor;
|
|
59
|
+
},
|
|
60
|
+
async dispose() {
|
|
61
|
+
disposed = true;
|
|
62
|
+
for (const cursor of entries.keys()) evict(cursor);
|
|
63
|
+
await Promise.all(releases);
|
|
64
|
+
if (failures.length > 0) throw new AggregateError(failures.splice(0), "Failed to release KV listing continuations.");
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/runtime/fs-lite.ts
|
|
70
|
+
const temporaryFile = /^\.unstorage-tmp-[\da-z-]+$/;
|
|
71
|
+
const layoutRecord = /^\.unstorage-tmp-vitehub-layout-v1(?:-\d+)?$/;
|
|
72
|
+
const layoutRecordName = ".unstorage-tmp-vitehub-layout-v1";
|
|
73
|
+
const layoutMarkerName = ".unstorage-tmp-vitehub-record";
|
|
74
|
+
const keyPrefix = "key-";
|
|
75
|
+
function fileName(key) {
|
|
76
|
+
return keyPrefix + key.replace(/[%:]/g, encodeURIComponent);
|
|
77
|
+
}
|
|
78
|
+
function keyOf(name) {
|
|
79
|
+
if (!name.startsWith(keyPrefix)) return;
|
|
80
|
+
const key = name.slice(4).replace(/%(?:25|3A)/g, decodeURIComponent);
|
|
81
|
+
return fileName(key) === name ? key : void 0;
|
|
82
|
+
}
|
|
83
|
+
function hasCode(error, ...codes) {
|
|
84
|
+
return error instanceof Error && "code" in error && typeof error.code === "string" && codes.includes(error.code);
|
|
85
|
+
}
|
|
86
|
+
async function exists(path) {
|
|
87
|
+
try {
|
|
88
|
+
await stat(path);
|
|
89
|
+
return true;
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (hasCode(error, "ENOENT")) return false;
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async function migrateKeys(root) {
|
|
96
|
+
await mkdir(root, { recursive: true });
|
|
97
|
+
let recordPath = "";
|
|
98
|
+
let layout = "";
|
|
99
|
+
const candidates = [];
|
|
100
|
+
while (!layout) {
|
|
101
|
+
const entries = await readdir(root, { withFileTypes: true });
|
|
102
|
+
for (const entry of entries) {
|
|
103
|
+
if (!entry.isFile() || !layoutRecord.test(entry.name)) continue;
|
|
104
|
+
const path = join(root, entry.name);
|
|
105
|
+
const value = await readFile(path, "utf8").catch((error) => {
|
|
106
|
+
if (hasCode(error, "ENOENT")) return "";
|
|
107
|
+
throw error;
|
|
108
|
+
});
|
|
109
|
+
if (!/^\.unstorage-tmp-vitehub-migration-[a-z\d]{6}$/i.test(value)) continue;
|
|
110
|
+
const identity = await Promise.all([lstat(path), lstat(join(root, value, layoutMarkerName))]).catch((error) => {
|
|
111
|
+
if (hasCode(error, "ENOENT", "ENOTDIR")) return void 0;
|
|
112
|
+
throw error;
|
|
113
|
+
});
|
|
114
|
+
if (!identity) continue;
|
|
115
|
+
const [record, marker] = identity;
|
|
116
|
+
if (!record.isFile() || !marker.isFile() || record.dev !== marker.dev || record.ino !== marker.ino) continue;
|
|
117
|
+
recordPath = path;
|
|
118
|
+
layout = join(root, value);
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
if (layout) break;
|
|
122
|
+
let name = layoutRecordName;
|
|
123
|
+
for (let suffix = 1; entries.some((entry) => entry.name === name); suffix++) name = `${layoutRecordName}-${suffix}`;
|
|
124
|
+
const candidate = await mkdtemp(join(root, ".unstorage-tmp-vitehub-migration-"));
|
|
125
|
+
candidates.push(candidate);
|
|
126
|
+
const temporary = join(root, `.unstorage-tmp-${randomUUID()}`);
|
|
127
|
+
try {
|
|
128
|
+
await writeFile(temporary, basename(candidate));
|
|
129
|
+
await link(temporary, join(candidate, layoutMarkerName));
|
|
130
|
+
await link(temporary, join(root, name));
|
|
131
|
+
layout = candidate;
|
|
132
|
+
recordPath = join(root, name);
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (!hasCode(error, "EEXIST", "ENOENT")) throw error;
|
|
135
|
+
} finally {
|
|
136
|
+
await rm(temporary, { force: true });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const release = await lock(layout, {
|
|
140
|
+
lockfilePath: join(layout, "lock"),
|
|
141
|
+
retries: {
|
|
142
|
+
retries: 100,
|
|
143
|
+
minTimeout: 20,
|
|
144
|
+
maxTimeout: 100
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
try {
|
|
148
|
+
for (const candidate of candidates) if (candidate !== layout) await rm(candidate, {
|
|
149
|
+
force: true,
|
|
150
|
+
recursive: true
|
|
151
|
+
});
|
|
152
|
+
const complete = join(layout, "complete");
|
|
153
|
+
if (await exists(complete)) return layout;
|
|
154
|
+
const legacy = join(layout, "legacy");
|
|
155
|
+
await mkdir(legacy, { recursive: true });
|
|
156
|
+
const staged = join(layout, "staged");
|
|
157
|
+
if (!await exists(staged)) {
|
|
158
|
+
for (const entry of await readdir(root, { withFileTypes: true })) {
|
|
159
|
+
if (entry.name === basename(layout) || join(root, entry.name) === recordPath) continue;
|
|
160
|
+
if (!entry.isDirectory() && (!entry.isFile() || temporaryFile.test(entry.name) && !layoutRecord.test(entry.name))) continue;
|
|
161
|
+
await rename(join(root, entry.name), join(legacy, entry.name));
|
|
162
|
+
}
|
|
163
|
+
await writeFile(staged, "");
|
|
164
|
+
}
|
|
165
|
+
for (const file of await readdir(legacy, {
|
|
166
|
+
recursive: true,
|
|
167
|
+
withFileTypes: true
|
|
168
|
+
})) {
|
|
169
|
+
if (!file.isFile() || temporaryFile.test(file.name) && !layoutRecord.test(file.name)) continue;
|
|
170
|
+
const path = join(file.parentPath, file.name);
|
|
171
|
+
const destination = join(root, fileName(relative(legacy, path).split(sep).join(":")));
|
|
172
|
+
try {
|
|
173
|
+
await link(path, destination);
|
|
174
|
+
} catch (error) {
|
|
175
|
+
if (!hasCode(error, "EEXIST")) throw error;
|
|
176
|
+
const source = await lstat(path);
|
|
177
|
+
const target = await lstat(destination);
|
|
178
|
+
if (!target.isFile() || target.dev !== source.dev || target.ino !== source.ino) throw error;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
await writeFile(complete, "");
|
|
182
|
+
await rm(legacy, {
|
|
183
|
+
force: true,
|
|
184
|
+
recursive: true
|
|
185
|
+
});
|
|
186
|
+
return layout;
|
|
187
|
+
} finally {
|
|
188
|
+
await release();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function ttlMilliseconds(ttl) {
|
|
192
|
+
if (!Number.isFinite(ttl) || ttl <= 0) throw kvErrorDiagnostics.KV_INVALID_TTL();
|
|
193
|
+
const ms = Math.ceil(ttl * 1e3);
|
|
194
|
+
if (!Number.isSafeInteger(ms)) throw kvErrorDiagnostics.KV_INVALID_TTL();
|
|
195
|
+
return ms;
|
|
196
|
+
}
|
|
197
|
+
function setExpiry(options) {
|
|
198
|
+
const ttl = options && typeof options === "object" ? Reflect.get(options, "ttl") : void 0;
|
|
199
|
+
if (ttl === void 0 || ttl === null || ttl === 0) return;
|
|
200
|
+
if (typeof ttl !== "number") throw kvErrorDiagnostics.KV_INVALID_TTL();
|
|
201
|
+
return Date.now() + ttlMilliseconds(ttl);
|
|
202
|
+
}
|
|
203
|
+
async function createFsLiteKVDriver(options) {
|
|
204
|
+
const root = resolve(options.base);
|
|
205
|
+
const layout = await migrateKeys(root);
|
|
206
|
+
const expiries = join(layout, "expires");
|
|
207
|
+
const expiryPath = (key) => join(expiries, createHash("sha256").update(key).digest("hex"));
|
|
208
|
+
async function readExpiry(key) {
|
|
209
|
+
const text = await readFile(expiryPath(key), "utf8").catch((error) => {
|
|
210
|
+
if (hasCode(error, "ENOENT", "ENOTDIR")) return void 0;
|
|
211
|
+
throw error;
|
|
212
|
+
});
|
|
213
|
+
const expiresAt = text === void 0 ? NaN : Number(text);
|
|
214
|
+
return Number.isSafeInteger(expiresAt) ? expiresAt : void 0;
|
|
215
|
+
}
|
|
216
|
+
async function synchronized(operation) {
|
|
217
|
+
const release = await lock(layout, {
|
|
218
|
+
lockfilePath: join(layout, "lock"),
|
|
219
|
+
retries: {
|
|
220
|
+
retries: 100,
|
|
221
|
+
minTimeout: 20,
|
|
222
|
+
maxTimeout: 100
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
try {
|
|
226
|
+
return await operation();
|
|
227
|
+
} finally {
|
|
228
|
+
await release();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
async function writeExpiry(key, expiresAt) {
|
|
232
|
+
if (expiresAt === void 0) {
|
|
233
|
+
await rm(expiryPath(key), { force: true });
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
await mkdir(expiries, { recursive: true });
|
|
237
|
+
const temporary = join(expiries, `.tmp-${randomUUID()}`);
|
|
238
|
+
await writeFile(temporary, String(expiresAt));
|
|
239
|
+
await rename(temporary, expiryPath(key));
|
|
240
|
+
}
|
|
241
|
+
async function live(key) {
|
|
242
|
+
const expiresAt = await readExpiry(key);
|
|
243
|
+
if (expiresAt === void 0 || expiresAt > Date.now()) return true;
|
|
244
|
+
await rm(join(root, fileName(key)), { force: true });
|
|
245
|
+
await rm(expiryPath(key), { force: true });
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
const driver = createDriver(options);
|
|
249
|
+
const { getItem, getItemRaw, getMeta, hasItem, removeItem, setItem, setItemRaw } = driver;
|
|
250
|
+
driver.getItem = async (key, operationOptions) => {
|
|
251
|
+
if (!await live(key)) return null;
|
|
252
|
+
const value = await getItem(fileName(key), operationOptions);
|
|
253
|
+
if (value instanceof Error) throw value;
|
|
254
|
+
return value;
|
|
255
|
+
};
|
|
256
|
+
driver.getItemRaw = async (key, operationOptions) => {
|
|
257
|
+
if (!await live(key)) return null;
|
|
258
|
+
const value = await getItemRaw?.(fileName(key), operationOptions);
|
|
259
|
+
if (value instanceof Error) throw value;
|
|
260
|
+
return value;
|
|
261
|
+
};
|
|
262
|
+
driver.getMeta = async (key, operationOptions) => await live(key) ? getMeta?.(fileName(key), operationOptions) ?? null : null;
|
|
263
|
+
driver.setItem = async (key, value, operationOptions) => {
|
|
264
|
+
await writeExpiry(key, setExpiry(operationOptions));
|
|
265
|
+
return setItem?.(fileName(key), value, operationOptions);
|
|
266
|
+
};
|
|
267
|
+
driver.setItemRaw = async (key, value, operationOptions) => {
|
|
268
|
+
await writeExpiry(key, setExpiry(operationOptions));
|
|
269
|
+
return setItemRaw?.(fileName(key), value, operationOptions);
|
|
270
|
+
};
|
|
271
|
+
driver.removeItem = async (key, operationOptions) => {
|
|
272
|
+
await rm(expiryPath(key), { force: true });
|
|
273
|
+
await removeItem?.(fileName(key), operationOptions);
|
|
274
|
+
};
|
|
275
|
+
driver.clear = async (base = "") => {
|
|
276
|
+
const entries = await readdir(root).catch((error) => {
|
|
277
|
+
if (hasCode(error, "ENOENT")) return [];
|
|
278
|
+
throw error;
|
|
279
|
+
});
|
|
280
|
+
for (const entry of entries) {
|
|
281
|
+
const key = keyOf(entry);
|
|
282
|
+
if (key !== void 0 && key.startsWith(base)) {
|
|
283
|
+
await rm(join(root, entry), {
|
|
284
|
+
force: true,
|
|
285
|
+
recursive: true
|
|
286
|
+
});
|
|
287
|
+
await rm(expiryPath(key), { force: true });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
const hasLiveItem = async (key, operationOptions) => {
|
|
292
|
+
if (!await hasItem(fileName(key), operationOptions)) return false;
|
|
293
|
+
if (!await live(key)) return false;
|
|
294
|
+
try {
|
|
295
|
+
return (await stat(join(root, fileName(key)))).isFile();
|
|
296
|
+
} catch (error) {
|
|
297
|
+
if (hasCode(error, "ENOENT")) return false;
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
driver.hasItem = hasLiveItem;
|
|
302
|
+
driver.setIfAbsentItem = async (key, value, ttl) => {
|
|
303
|
+
const expiresAt = ttl === void 0 ? void 0 : Date.now() + ttlMilliseconds(ttl);
|
|
304
|
+
if (await hasLiveItem(key, {})) return false;
|
|
305
|
+
const path = join(root, fileName(key));
|
|
306
|
+
await mkdir(root, { recursive: true });
|
|
307
|
+
const temporary = join(root, `.unstorage-tmp-${randomUUID()}`);
|
|
308
|
+
await writeFile(temporary, value, "utf8");
|
|
309
|
+
try {
|
|
310
|
+
await link(temporary, path);
|
|
311
|
+
await writeExpiry(key, expiresAt);
|
|
312
|
+
return true;
|
|
313
|
+
} catch (error) {
|
|
314
|
+
if (hasCode(error, "EEXIST") && (await stat(path)).isFile()) return false;
|
|
315
|
+
throw error;
|
|
316
|
+
} finally {
|
|
317
|
+
await rm(temporary, { force: true });
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
async function* walk() {
|
|
321
|
+
let entries;
|
|
322
|
+
try {
|
|
323
|
+
entries = await opendir(root);
|
|
324
|
+
} catch (error) {
|
|
325
|
+
if (hasCode(error, "ENOENT")) return;
|
|
326
|
+
throw error;
|
|
327
|
+
}
|
|
328
|
+
for await (const entry of entries) {
|
|
329
|
+
if (entry.name === basename(layout) || layoutRecord.test(entry.name)) continue;
|
|
330
|
+
const key = entry.isFile() ? keyOf(entry.name) : void 0;
|
|
331
|
+
yield key !== void 0 && await synchronized(() => live(key)) ? key : void 0;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
driver.getKeys = async () => {
|
|
335
|
+
const keys = [];
|
|
336
|
+
for await (const key of walk()) if (key !== void 0) keys.push(key);
|
|
337
|
+
return keys;
|
|
338
|
+
};
|
|
339
|
+
const expired = () => kvErrorDiagnostics.KV_INVALID_CURSOR({ problem: "expired" });
|
|
340
|
+
const continuations = createKVContinuations({
|
|
341
|
+
expired,
|
|
342
|
+
release: (iterator) => iterator.return(void 0)
|
|
343
|
+
});
|
|
344
|
+
const dispose = driver.dispose;
|
|
345
|
+
driver.dispose = async () => {
|
|
346
|
+
try {
|
|
347
|
+
await continuations.dispose();
|
|
348
|
+
} finally {
|
|
349
|
+
await dispose?.call(driver);
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
driver.listKeys = async ({ cursor, limit, prefix = "" }) => {
|
|
353
|
+
const keys = [];
|
|
354
|
+
const iterator = cursor ? continuations.take(cursor) : walk();
|
|
355
|
+
if (!iterator) throw expired();
|
|
356
|
+
let scanned = 0;
|
|
357
|
+
while (scanned < limit) {
|
|
358
|
+
const entry = await iterator.next();
|
|
359
|
+
if (entry.done) return { keys };
|
|
360
|
+
scanned++;
|
|
361
|
+
const key = entry.value;
|
|
362
|
+
if (key !== void 0 && key.startsWith(prefix)) keys.push(key);
|
|
363
|
+
}
|
|
364
|
+
return {
|
|
365
|
+
keys,
|
|
366
|
+
cursor: await continuations.retain(iterator)
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
for (const name of [
|
|
370
|
+
"getItem",
|
|
371
|
+
"getItemRaw",
|
|
372
|
+
"getMeta",
|
|
373
|
+
"hasItem",
|
|
374
|
+
"setItem",
|
|
375
|
+
"setItemRaw",
|
|
376
|
+
"removeItem",
|
|
377
|
+
"clear",
|
|
378
|
+
"setIfAbsentItem"
|
|
379
|
+
]) {
|
|
380
|
+
const operation = driver[name];
|
|
381
|
+
if (operation) Reflect.set(driver, name, (...args) => synchronized(async () => Reflect.apply(operation, driver, args)));
|
|
382
|
+
}
|
|
383
|
+
return driver;
|
|
384
|
+
}
|
|
385
|
+
//#endregion
|
|
386
|
+
export { createFsLiteKVDriver as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { A as RedisKVStoreConfig, C as KVOptions, D as KVStoreName, E as KVStoreConfig, F as ResolvedKVModuleOptions, I as ResolvedKVStoreConfig, L as ResolvedRedisKVStoreConfig, M as ResolvedDatabaseKVStoreConfig, N as ResolvedDenoKVStoreConfig, O as KVStoreOptions, P as ResolvedFsLiteKVStoreConfig, R as ResolvedUpstashKVStoreConfig, S as KVOperation, T as KVStorage, _ as KVLock, a as InferredKVStoreConfig, b as KVLockOptions, c as KVDriverAtomicOperations, d as KVErrorCode, f as KVGetOptions, g as KVListPage, h as KVListOptions, i as FsLiteKVStoreConfig, j as ResolvedCloudflareKVStoreConfig, k as ReadonlyKVStorage, l as KVDriversWith, m as KVGetTypeMap, n as DatabaseKVStoreConfig, o as KVAtomicOperation, p as KVGetType, r as DenoKVStoreConfig, s as KVDriver, t as CloudflareKVStoreConfig, u as KVEntry, v as KVLockAcquisition, w as KVSetOptions, x as KVLockRunResult, y as KVLockErrorCode, z as UpstashKVStoreConfig } from "./types-DEiKew_3.js";
|
|
3
2
|
//#region src/runtime/storage.d.ts
|
|
4
|
-
|
|
3
|
+
/** Releases every cached store. Call from the application's shutdown hook after stopping new work. */
|
|
4
|
+
export declare function disposeKVStores(): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* The configured driver that a store uses in this server process. App tests return `fs-lite`.
|
|
7
|
+
* An unknown store throws. Reading the driver does not open a connection to the store.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getKVStoreDriver(name?: KVStoreName): Promise<KVDriver>;
|
|
10
|
+
export declare const kv: KVStorage;
|
|
5
11
|
//#endregion
|
|
6
|
-
export {
|
|
12
|
+
export type { CloudflareKVStoreConfig, DatabaseKVStoreConfig, DenoKVStoreConfig, FsLiteKVStoreConfig, InferredKVStoreConfig, KVAtomicOperation, KVDriver, KVDriverAtomicOperations, KVDriversWith, KVEntry, KVErrorCode, KVGetOptions, KVGetType, KVGetTypeMap, KVListOptions, KVListPage, KVLock, KVLockAcquisition, KVLockErrorCode, KVLockOptions, KVLockRunResult, KVOperation, KVOptions, KVSetOptions, KVStorage, KVStoreConfig, KVStoreOptions, ReadonlyKVStorage, RedisKVStoreConfig, ResolvedCloudflareKVStoreConfig, ResolvedDatabaseKVStoreConfig, ResolvedDenoKVStoreConfig, ResolvedFsLiteKVStoreConfig, ResolvedKVModuleOptions, ResolvedKVStoreConfig, ResolvedRedisKVStoreConfig, ResolvedUpstashKVStoreConfig, UpstashKVStoreConfig };
|