Skip to content

Commit f95e277

Browse files
Export a makeNativeService to access native version.
1 parent c57c67d commit f95e277

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

client.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ export function makeRemoteService(opts: RemoteServiceOptions): KvService {
5353
}
5454
}
5555

56+
/**
57+
* Creates a new KvService instance that can be used to access Deno's native implementation (only works in the Deno runtime!)
58+
*
59+
* Requires the --unstable flag to `deno run` and any applicable --allow-read/allow-write/allow-net flags
60+
*/
61+
export function makeNativeService(): KvService {
62+
if ('Deno' in globalThis) {
63+
const { openKv, KvU64 } = globalThis.Deno;
64+
if (typeof openKv === 'function' && typeof KvU64 === 'function') {
65+
return {
66+
// deno-lint-ignore no-explicit-any
67+
openKv: openKv as any,
68+
newU64: value => new KvU64(value),
69+
}
70+
}
71+
}
72+
throw new Error(`Global 'Deno.openKv' or 'Deno.KvU64' not found`);
73+
}
74+
5675
//
5776

5877
type Cursor = { lastYieldedKeyBytes: Uint8Array }

scripts/build_npm.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ await build({
2020
// package.json properties
2121
name: 'kv-connect-kit',
2222
version: Deno.args[0],
23-
description: 'Minimal Typescript client implementing the KV Connect protocol. Connect to Deno KV remotely from Node, Cloudflare Workers, Bun, and Deno.',
23+
description: 'Minimal Typescript client implementing the KV Connect protocol. Connect to Deno KV remotely from Node, Cloudflare Workers, Bun, Deno, and the browser.',
2424
license: 'MIT',
2525
repository: {
2626
type: 'git',
@@ -29,6 +29,7 @@ await build({
2929
bugs: {
3030
url: 'https://github.com/skymethod/kv-connect-kit/issues',
3131
},
32+
homepage: 'https://github.com/skymethod/kv-connect-kit',
3233

3334
},
3435
postBuild() {

0 commit comments

Comments
 (0)