mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
Revert "refactor: rename Deno.openKv() to Deno.kv() (#18349)"
This reverts commit 50b793c9ed
.
This commit is contained in:
parent
df614ff6e5
commit
81563365d0
6 changed files with 22 additions and 18 deletions
|
@ -8,25 +8,25 @@ import {
|
||||||
} from "./test_util.ts";
|
} from "./test_util.ts";
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "kv :memory: no permissions",
|
name: "openKv :memory: no permissions",
|
||||||
permissions: {},
|
permissions: {},
|
||||||
async fn() {
|
async fn() {
|
||||||
const db = await Deno.kv(":memory:");
|
const db = await Deno.openKv(":memory:");
|
||||||
await db.close();
|
await db.close();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "kv invalid filenames",
|
name: "openKv invalid filenames",
|
||||||
permissions: {},
|
permissions: {},
|
||||||
async fn() {
|
async fn() {
|
||||||
await assertRejects(
|
await assertRejects(
|
||||||
async () => await Deno.kv(""),
|
async () => await Deno.openKv(""),
|
||||||
TypeError,
|
TypeError,
|
||||||
"Filename cannot be empty",
|
"Filename cannot be empty",
|
||||||
);
|
);
|
||||||
await assertRejects(
|
await assertRejects(
|
||||||
async () => await Deno.kv(":foo"),
|
async () => await Deno.openKv(":foo"),
|
||||||
TypeError,
|
TypeError,
|
||||||
"Filename cannot start with ':' unless prefixed with './'",
|
"Filename cannot start with ':' unless prefixed with './'",
|
||||||
);
|
);
|
||||||
|
@ -37,7 +37,9 @@ function dbTest(name: string, fn: (db: Deno.Kv) => Promise<void>) {
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name,
|
name,
|
||||||
async fn() {
|
async fn() {
|
||||||
const db: Deno.Kv = await Deno.kv(":memory:");
|
const db: Deno.Kv = await Deno.openKv(
|
||||||
|
":memory:",
|
||||||
|
);
|
||||||
try {
|
try {
|
||||||
await fn(db);
|
await fn(db);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
12
cli/tsc/dts/lib.deno.unstable.d.ts
vendored
12
cli/tsc/dts/lib.deno.unstable.d.ts
vendored
|
@ -1535,7 +1535,7 @@ declare namespace Deno {
|
||||||
* @tags allow-read, allow-write
|
* @tags allow-read, allow-write
|
||||||
* @category KV
|
* @category KV
|
||||||
*/
|
*/
|
||||||
export function kv(path?: string): Promise<Deno.Kv>;
|
export function openKv(path?: string): Promise<Deno.Kv>;
|
||||||
|
|
||||||
/** **UNSTABLE**: New API, yet to be vetted.
|
/** **UNSTABLE**: New API, yet to be vetted.
|
||||||
*
|
*
|
||||||
|
@ -1876,7 +1876,7 @@ declare namespace Deno {
|
||||||
* the returned entry will have a `null` value and versionstamp.
|
* the returned entry will have a `null` value and versionstamp.
|
||||||
*
|
*
|
||||||
* ```ts
|
* ```ts
|
||||||
* const db = await Deno.kv();
|
* const db = await Deno.openKv();
|
||||||
* const result = await db.get(["foo"]);
|
* const result = await db.get(["foo"]);
|
||||||
* result.key; // ["foo"]
|
* result.key; // ["foo"]
|
||||||
* result.value; // "bar"
|
* result.value; // "bar"
|
||||||
|
@ -1902,7 +1902,7 @@ declare namespace Deno {
|
||||||
* entry will have a `null` value and versionstamp.
|
* entry will have a `null` value and versionstamp.
|
||||||
*
|
*
|
||||||
* ```ts
|
* ```ts
|
||||||
* const db = await Deno.kv();
|
* const db = await Deno.openKv();
|
||||||
* const result = await db.getMany([["foo"], ["baz"]]);
|
* const result = await db.getMany([["foo"], ["baz"]]);
|
||||||
* result[0].key; // ["foo"]
|
* result[0].key; // ["foo"]
|
||||||
* result[0].value; // "bar"
|
* result[0].value; // "bar"
|
||||||
|
@ -1928,7 +1928,7 @@ declare namespace Deno {
|
||||||
* exists for the key, it will be overwritten.
|
* exists for the key, it will be overwritten.
|
||||||
*
|
*
|
||||||
* ```ts
|
* ```ts
|
||||||
* const db = await Deno.kv();
|
* const db = await Deno.openKv();
|
||||||
* await db.set(["foo"], "bar");
|
* await db.set(["foo"], "bar");
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
@ -1939,7 +1939,7 @@ declare namespace Deno {
|
||||||
* for the key, this operation is a no-op.
|
* for the key, this operation is a no-op.
|
||||||
*
|
*
|
||||||
* ```ts
|
* ```ts
|
||||||
* const db = await Deno.kv();
|
* const db = await Deno.openKv();
|
||||||
* await db.delete(["foo"]);
|
* await db.delete(["foo"]);
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
@ -1971,7 +1971,7 @@ declare namespace Deno {
|
||||||
* not `["users", "noa"]` or `["users", "zoe"]`.
|
* not `["users", "noa"]` or `["users", "zoe"]`.
|
||||||
*
|
*
|
||||||
* ```ts
|
* ```ts
|
||||||
* const db = await Deno.kv();
|
* const db = await Deno.openKv();
|
||||||
* const entries = db.list({ prefix: ["users"] });
|
* const entries = db.list({ prefix: ["users"] });
|
||||||
* for await (const entry of entries) {
|
* for await (const entry of entries) {
|
||||||
* entry.key; // ["users", "alice"]
|
* entry.key; // ["users", "alice"]
|
||||||
|
|
|
@ -14,7 +14,7 @@ const encodeCursor: (
|
||||||
) => string = (selector, boundaryKey) =>
|
) => string = (selector, boundaryKey) =>
|
||||||
ops.op_kv_encode_cursor(selector, boundaryKey);
|
ops.op_kv_encode_cursor(selector, boundaryKey);
|
||||||
|
|
||||||
async function kv(path: string) {
|
async function openKv(path: string) {
|
||||||
const rid = await core.opAsync("op_kv_database_open", path);
|
const rid = await core.opAsync("op_kv_database_open", path);
|
||||||
return new Kv(rid);
|
return new Kv(rid);
|
||||||
}
|
}
|
||||||
|
@ -466,4 +466,4 @@ class KvListIterator extends AsyncIterator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Kv, kv, KvListIterator, KvU64 };
|
export { Kv, KvListIterator, KvU64, openKv };
|
||||||
|
|
|
@ -84,7 +84,9 @@ where
|
||||||
{
|
{
|
||||||
let handler = {
|
let handler = {
|
||||||
let state = state.borrow();
|
let state = state.borrow();
|
||||||
state.borrow::<UnstableChecker>().check_unstable("Deno.kv");
|
state
|
||||||
|
.borrow::<UnstableChecker>()
|
||||||
|
.check_unstable("Deno.openKv");
|
||||||
state.borrow::<Rc<DBH>>().clone()
|
state.borrow::<Rc<DBH>>().clone()
|
||||||
};
|
};
|
||||||
let db = handler.open(state.clone(), path).await?;
|
let db = handler.open(state.clone(), path).await?;
|
||||||
|
|
|
@ -128,8 +128,8 @@ impl<P: SqliteDbHandlerPermissions> DatabaseHandler for SqliteDbHandler<P> {
|
||||||
{
|
{
|
||||||
let mut state = state.borrow_mut();
|
let mut state = state.borrow_mut();
|
||||||
let permissions = state.borrow_mut::<P>();
|
let permissions = state.borrow_mut::<P>();
|
||||||
permissions.check_read(path, "Deno.kv")?;
|
permissions.check_read(path, "Deno.openKv")?;
|
||||||
permissions.check_write(path, "Deno.kv")?;
|
permissions.check_write(path, "Deno.openKv")?;
|
||||||
}
|
}
|
||||||
let flags = OpenFlags::default().difference(OpenFlags::SQLITE_OPEN_URI);
|
let flags = OpenFlags::default().difference(OpenFlags::SQLITE_OPEN_URI);
|
||||||
rusqlite::Connection::open_with_flags(path, flags)?
|
rusqlite::Connection::open_with_flags(path, flags)?
|
||||||
|
|
|
@ -170,7 +170,7 @@ const denoNsUnstable = {
|
||||||
funlockSync: fs.funlockSync,
|
funlockSync: fs.funlockSync,
|
||||||
upgradeHttp: http.upgradeHttp,
|
upgradeHttp: http.upgradeHttp,
|
||||||
upgradeHttpRaw: flash.upgradeHttpRaw,
|
upgradeHttpRaw: flash.upgradeHttpRaw,
|
||||||
kv: kv.kv,
|
openKv: kv.openKv,
|
||||||
Kv: kv.Kv,
|
Kv: kv.Kv,
|
||||||
KvU64: kv.KvU64,
|
KvU64: kv.KvU64,
|
||||||
KvListIterator: kv.KvListIterator,
|
KvListIterator: kv.KvListIterator,
|
||||||
|
|
Loading…
Reference in a new issue