@deno/kv
Version:
A Deno KV client library optimized for Node.js.
45 lines (44 loc) • 1.44 kB
JavaScript
;
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports._KvU64 = void 0;
const max = (1n << 64n) - 1n;
class _KvU64 {
constructor(value) {
Object.defineProperty(this, "value", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
if (typeof value !== "bigint") {
throw new TypeError("value must be a bigint");
}
if (value < 0n)
throw new Error("value must be a positive bigint");
if (value > max) {
throw new Error("value must fit in a 64-bit unsigned integer");
}
this.value = value;
}
sum(other) {
checkValueHolder(other);
return new _KvU64((this.value + other.value) % (1n << 64n));
}
min(other) {
checkValueHolder(other);
return other.value < this.value ? new _KvU64(other.value) : this;
}
max(other) {
checkValueHolder(other);
return other.value > this.value ? new _KvU64(other.value) : this;
}
}
exports._KvU64 = _KvU64;
//
function checkValueHolder(obj) {
const valid = typeof obj === "object" && obj !== null &&
!Array.isArray(obj) && "value" in obj && typeof obj.value === "bigint";
if (!valid)
throw new Error(`Expected bigint holder, found: ${obj}`);
}