diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/kv/01_db.ts | 45 | ||||
-rw-r--r-- | ext/kv/lib.rs | 3 |
2 files changed, 37 insertions, 11 deletions
diff --git a/ext/kv/01_db.ts b/ext/kv/01_db.ts index 72d358005..ca37aa840 100644 --- a/ext/kv/01_db.ts +++ b/ext/kv/01_db.ts @@ -2,8 +2,15 @@ // @ts-ignore internal api const { - ObjectGetPrototypeOf, AsyncGeneratorPrototype, + BigIntPrototypeToString, + ObjectFreeze, + ObjectGetPrototypeOf, + ObjectPrototypeIsPrototypeOf, + StringPrototypeReplace, + SymbolFor, + SymbolToStringTag, + Uint8ArrayPrototype, } = globalThis.__bootstrap.primordials; const core = Deno.core; const ops = core.ops; @@ -289,7 +296,7 @@ const MIN_U64 = BigInt("0"); const MAX_U64 = BigInt("0xffffffffffffffff"); class KvU64 { - readonly value: bigint; + value: bigint; constructor(value: bigint) { if (typeof value !== "bigint") { @@ -299,11 +306,31 @@ class KvU64 { throw new RangeError("value must be a positive bigint"); } if (value > MAX_U64) { - throw new RangeError("value must be a 64-bit unsigned integer"); + throw new RangeError("value must fit in a 64-bit unsigned integer"); } this.value = value; Object.freeze(this); } + + valueOf() { + return this.value; + } + + toString() { + return BigIntPrototypeToString(this.value); + } + + get [SymbolToStringTag]() { + return "Deno.KvU64"; + } + + [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) { + return StringPrototypeReplace( + inspect(Object(this.value), inspectOptions), + "BigInt", + "Deno.KvU64", + ); + } } function deserializeValue(entry: RawKvEntry): Deno.KvEntry<unknown> { @@ -330,15 +357,15 @@ function deserializeValue(entry: RawKvEntry): Deno.KvEntry<unknown> { } function serializeValue(value: unknown): RawValue { - if (value instanceof Uint8Array) { + if (ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, value)) { return { kind: "bytes", value, }; - } else if (value instanceof KvU64) { + } else if (ObjectPrototypeIsPrototypeOf(KvU64.prototype, value)) { return { kind: "u64", - value: value.value, + value: value.valueOf(), }; } else { return { @@ -398,13 +425,13 @@ class KvListIterator extends AsyncIterator let start: Deno.KvKey | undefined; let end: Deno.KvKey | undefined; if ("prefix" in selector && selector.prefix !== undefined) { - prefix = Object.freeze([...selector.prefix]); + prefix = ObjectFreeze([...selector.prefix]); } if ("start" in selector && selector.start !== undefined) { - start = Object.freeze([...selector.start]); + start = ObjectFreeze([...selector.start]); } if ("end" in selector && selector.end !== undefined) { - end = Object.freeze([...selector.end]); + end = ObjectFreeze([...selector.end]); } if (prefix) { if (start && end) { diff --git a/ext/kv/lib.rs b/ext/kv/lib.rs index f17ed55e3..dbc626225 100644 --- a/ext/kv/lib.rs +++ b/ext/kv/lib.rs @@ -53,8 +53,7 @@ impl UnstableChecker { } deno_core::extension!(deno_kv, - // TODO(bartlomieju): specify deps - deps = [ ], + deps = [ deno_console ], parameters = [ DBH: DatabaseHandler ], ops = [ op_kv_database_open<DBH>, |