diff --git a/.gitignore b/.gitignore index 6704566..493a824 100644 --- a/.gitignore +++ b/.gitignore @@ -67,6 +67,7 @@ typings/ # Yarn Integrity file .yarn-integrity +yarn.lock # dotenv environment variables file .env diff --git a/README.md b/README.md index 4436f7f..02df363 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # hyperbeedeebee + A MongoDB-like database built on top of Hyperbee with support for indexing Based on [this design](https://gist.github.com/RangerMauve/ae271204054b62d9a649d70b7d218191) @@ -59,6 +60,28 @@ const killbots = await db.collection('example') const eggbert = await db.collection('example').findOne({name: 'Eggbert'}) ``` +### Usage with Autobase + +```JavaScript + const input = new Hypercore(RAM) + const output = new Hypercore(RAM) + const inputs = [input] + + const base = new Autobase({ + inputs, + localOutput: firstOutput, + localInput: firstUser + }) + const autobee = new Autodeebee(base) + + // Create a new DB + const db = new DB(autobee) + // You can then use the DB the same way as you did above. +``` + +You also need to use the [Autodeebee class](./autodeebee.js): +This class redefines the functions of Hyperbee to be compatible with the DB. + ## Data Types HyperbeeDeeBee uses MongoDB's [BSON](https://github.com/mongodb/js-bson) data types for encoding data. @@ -87,6 +110,7 @@ BSONRegExp, BSONSymbol, Timestamp ``` + ## Important Differences From MongoDB - There is a single writer for a hyperbee and multiple readers diff --git a/autodeebee.js b/autodeebee.js new file mode 100644 index 0000000..e77fcf1 --- /dev/null +++ b/autodeebee.js @@ -0,0 +1,86 @@ +const Hyperbee = require('hyperbee') +const b4a = require('b4a') + +module.exports = class Autodeebee { + constructor (autobase, opts) { + this.autobase = autobase + this.opts = opts + if (!opts?.sub) { + this.autobase.start({ + unwrap: true, + apply: applyAutobeeBatch, + view: (core) => + new Hyperbee(core.unwrap(), { + ...this.opts, + extension: false + }) + }) + this.bee = this.autobase.view + } + } + + ready () { + return this.autobase.ready() + } + + feed () { + return this.bee.feed + } + + close () { + return this.bee.close() + } + + sub (name) { + const opts = this.opts ?? {} + opts.sub = true + const auto = new Autodeebee(this.autobase, opts) + auto.bee = this.bee.sub(name) + return auto + } + + batch () { + return this + } + + flush () { } + + async put (key, value, opts = {}) { + const op = b4a.from( + JSON.stringify({ type: 'put', key, value, prefix: this.bee.prefix }) + ) + return await this.autobase.append(op) + } + + async del (key, opts = {}) { + const op = b4a.from( + JSON.stringify({ type: 'del', key, prefix: this.bee.prefix }) + ) + return await this.autobase.append(op) + } + + async get (key) { + return await this.bee.get(key) + } + + createReadStream (opts) { + return this.bee.createReadStream(opts) + } +} + +function getKeyBufferWithPrefix (key, prefix) { + return prefix ? b4a.concat([b4a.from(prefix), b4a.from(key)]) : b4a.from(key) +} +// A real apply function would need to handle conflicts, beyond last-one-wins. +async function applyAutobeeBatch (bee, batch) { + const b = bee.batch({ update: false }) + for (const node of batch) { + const op = JSON.parse(node.value.toString()) + const bufKey = getKeyBufferWithPrefix(op.key, op.prefix) + if (op.type === 'put') { + await b.put(bufKey, b4a.from(op.value)) + } + if (op.type === 'del') await b.del(bufKey) + } + await b.flush() +} diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..5f3e145 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,4450 @@ +/** Declaration file generated by dts-gen */ + +export class NoDocumentSuppliedError extends Error { + constructor(message: string) +} +export class UniqueIntegrityConstraintViolationError extends Error { + constructor(message: string) +} + +export class Collection { + constructor(...args: any[]); + + createIndex(...args: any[]): void; + + find(...args: any[]): Cursor; + + findOne(...args: any[]): Promise; + + delete(...args: any[]): Promise; + + getIndex(...args: any[]): void; + + indexExists(...args: any[]): void; + + insert(...args: T[]): Promise; + + listIndexes(...args: any[]): void; + + reIndex(...args: any[]): void; + + update(...args: any[]): { nMatched: number; nModified: number; nUpserted: number; }; + +} + +export class Cursor { + constructor(...args: any[]); + + count(...args: any[]): number; + + getIndex(...args: any[]): void; + + hint(...args: any[]): Cursor; + + limit(...args: any[]): Cursor; + + skip(...args: any[]): Cursor; + + sort(...args: any[]): Cursor; + + then(onfulfilled?: ((value: any) => TResult1 | Promise) | null | undefined, onrejected?: ((reason: any) => TResult2 | Promise) | null | undefined): Promise; + +} + +export class DB { + constructor(...args: any[]); + + close(...args: any[]): void; + + collection(...args: any[]): Collection; + +} + +export namespace BSON { + class BSONError { + constructor(message: any); + + static captureStackTrace(p0: any, p1: any): any; + + static stackTraceLimit: number; + + } + + class BSONRegExp { + constructor(pattern: any, options: any); + + toExtendedJSON(options: any): any; + + static fromExtendedJSON(doc: any): any; + + static parseOptions(options: any): any; + + } + + class BSONSymbol { + constructor(value: any); + + inspect(): any; + + toExtendedJSON(): any; + + toJSON(): any; + + toString(): any; + + valueOf(): any; + + static fromExtendedJSON(doc: any): any; + + } + + class BSONTypeError { + constructor(message: any); + + static captureStackTrace(p0: any, p1: any): any; + + static stackTraceLimit: number; + + } + + class Binary { + constructor(buffer: any, subType: any); + + inspect(): any; + + length(): any; + + put(byteValue: any): void; + + read(position: any, length: any): any; + + toExtendedJSON(options: any): any; + + toJSON(): any; + + toString(format: any): any; + + toUUID(): any; + + value(asRaw: any): any; + + write(sequence: any, offset: any): void; + + static BSON_BINARY_SUBTYPE_DEFAULT: number; + + static BUFFER_SIZE: number; + + static SUBTYPE_BYTE_ARRAY: number; + + static SUBTYPE_COLUMN: number; + + static SUBTYPE_DEFAULT: number; + + static SUBTYPE_ENCRYPTED: number; + + static SUBTYPE_FUNCTION: number; + + static SUBTYPE_MD5: number; + + static SUBTYPE_USER_DEFINED: number; + + static SUBTYPE_UUID: number; + + static SUBTYPE_UUID_OLD: number; + + static fromExtendedJSON(doc: any, options: any): any; + + } + + class Code { + constructor(code: any, scope: any); + + inspect(): any; + + toExtendedJSON(): any; + + toJSON(): any; + + static fromExtendedJSON(doc: any): any; + + } + + class DBRef { + constructor(collection: any, oid: any, db: any, fields: any); + + inspect(): any; + + toExtendedJSON(options: any): any; + + toJSON(): any; + + static fromExtendedJSON(doc: any): any; + + } + + class Decimal128 { + constructor(bytes: any); + + inspect(): any; + + toExtendedJSON(): any; + + toJSON(): any; + + toString(): any; + + static fromExtendedJSON(doc: any): any; + + static fromString(representation: any): any; + + } + + class Double { + constructor(value: any); + + inspect(): any; + + toExtendedJSON(options: any): any; + + toJSON(): any; + + toString(radix: any): any; + + valueOf(): any; + + static fromExtendedJSON(doc: any, options: any): any; + + } + + class Int32 { + constructor(value: any); + + inspect(): any; + + toExtendedJSON(options: any): any; + + toJSON(): any; + + toString(radix: any): any; + + valueOf(): any; + + static fromExtendedJSON(doc: any, options: any): any; + + } + + class Long { + constructor(low: any, high: any, unsigned: any); + + add(addend: any): any; + + and(other: any): any; + + comp(other: any): any; + + compare(other: any): any; + + div(divisor: any): any; + + divide(divisor: any): any; + + eq(other: any): any; + + equals(other: any): any; + + eqz(): any; + + ge(other: any): any; + + getHighBits(): any; + + getHighBitsUnsigned(): any; + + getLowBits(): any; + + getLowBitsUnsigned(): any; + + getNumBitsAbs(): any; + + greaterThan(other: any): any; + + greaterThanOrEqual(other: any): any; + + gt(other: any): any; + + gte(other: any): any; + + inspect(): any; + + isEven(): any; + + isNegative(): any; + + isOdd(): any; + + isPositive(): any; + + isZero(): any; + + le(other: any): any; + + lessThan(other: any): any; + + lessThanOrEqual(other: any): any; + + lt(other: any): any; + + lte(other: any): any; + + mod(divisor: any): any; + + modulo(divisor: any): any; + + mul(multiplier: any): any; + + multiply(multiplier: any): any; + + ne(other: any): any; + + neg(): any; + + negate(): any; + + neq(other: any): any; + + not(): any; + + notEquals(other: any): any; + + or(other: any): any; + + rem(divisor: any): any; + + shiftLeft(numBits: any): any; + + shiftRight(numBits: any): any; + + shiftRightUnsigned(numBits: any): any; + + shl(numBits: any): any; + + shr(numBits: any): any; + + shr_u(numBits: any): any; + + shru(numBits: any): any; + + sub(subtrahend: any): any; + + subtract(subtrahend: any): any; + + toBigInt(): any; + + toBytes(le: any): any; + + toBytesBE(): any; + + toBytesLE(): any; + + toExtendedJSON(options: any): any; + + toInt(): any; + + toNumber(): any; + + toSigned(): any; + + toString(radix: any): any; + + toUnsigned(): any; + + xor(other: any): any; + + static fromBigInt(value: any, unsigned: any): any; + + static fromBits(lowBits: any, highBits: any, unsigned: any): any; + + static fromBytes(bytes: any, unsigned: any, le: any): any; + + static fromBytesBE(bytes: any, unsigned: any): any; + + static fromBytesLE(bytes: any, unsigned: any): any; + + static fromExtendedJSON(doc: any, options: any): any; + + static fromInt(value: any, unsigned: any): any; + + static fromNumber(value: any, unsigned: any): any; + + static fromString(str: any, unsigned: any, radix: any): any; + + static fromValue(val: any, unsigned: any): any; + + static isLong(value: any): any; + + } + + class LongWithoutOverridesClass { + constructor(low: any, high: any, unsigned: any); + + add(addend: any): any; + + and(other: any): any; + + comp(other: any): any; + + compare(other: any): any; + + div(divisor: any): any; + + divide(divisor: any): any; + + eq(other: any): any; + + equals(other: any): any; + + eqz(): any; + + ge(other: any): any; + + getHighBits(): any; + + getHighBitsUnsigned(): any; + + getLowBits(): any; + + getLowBitsUnsigned(): any; + + getNumBitsAbs(): any; + + greaterThan(other: any): any; + + greaterThanOrEqual(other: any): any; + + gt(other: any): any; + + gte(other: any): any; + + inspect(): any; + + isEven(): any; + + isNegative(): any; + + isOdd(): any; + + isPositive(): any; + + isZero(): any; + + le(other: any): any; + + lessThan(other: any): any; + + lessThanOrEqual(other: any): any; + + lt(other: any): any; + + lte(other: any): any; + + mod(divisor: any): any; + + modulo(divisor: any): any; + + mul(multiplier: any): any; + + multiply(multiplier: any): any; + + ne(other: any): any; + + neg(): any; + + negate(): any; + + neq(other: any): any; + + not(): any; + + notEquals(other: any): any; + + or(other: any): any; + + rem(divisor: any): any; + + shiftLeft(numBits: any): any; + + shiftRight(numBits: any): any; + + shiftRightUnsigned(numBits: any): any; + + shl(numBits: any): any; + + shr(numBits: any): any; + + shr_u(numBits: any): any; + + shru(numBits: any): any; + + sub(subtrahend: any): any; + + subtract(subtrahend: any): any; + + toBigInt(): any; + + toBytes(le: any): any; + + toBytesBE(): any; + + toBytesLE(): any; + + toExtendedJSON(options: any): any; + + toInt(): any; + + toNumber(): any; + + toSigned(): any; + + toString(radix: any): any; + + toUnsigned(): any; + + xor(other: any): any; + + static fromBigInt(value: any, unsigned: any): any; + + static fromBits(lowBits: any, highBits: any, unsigned: any): any; + + static fromBytes(bytes: any, unsigned: any, le: any): any; + + static fromBytesBE(bytes: any, unsigned: any): any; + + static fromBytesLE(bytes: any, unsigned: any): any; + + static fromExtendedJSON(doc: any, options: any): any; + + static fromInt(value: any, unsigned: any): any; + + static fromNumber(value: any, unsigned: any): any; + + static fromString(str: any, unsigned: any, radix: any): any; + + static fromValue(val: any, unsigned: any): any; + + static isLong(value: any): any; + + } + + class Map { + constructor(); + + // Native method; no parameter or return type inference available + clear(): any; + + // Native method; no parameter or return type inference available + delete(p0: any): any; + + // Native method; no parameter or return type inference available + entries(): any; + + // Native method; no parameter or return type inference available + forEach(p0: any): any; + + // Native method; no parameter or return type inference available + get(p0: any): any; + + // Native method; no parameter or return type inference available + has(p0: any): any; + + // Native method; no parameter or return type inference available + keys(): any; + + // Native method; no parameter or return type inference available + set(p0: any, p1: any): any; + + // Native method; no parameter or return type inference available + values(): any; + + } + + class MaxKey { + constructor(); + + inspect(): any; + + toExtendedJSON(): any; + + static fromExtendedJSON(): any; + + } + + class MinKey { + constructor(); + + inspect(): any; + + toExtendedJSON(): any; + + static fromExtendedJSON(): any; + + } + + class ObjectID { + constructor(inputId: any); + + equals(otherId: any): any; + + generate(...args: any[]): any; + + getInc(...args: any[]): any; + + getTimestamp(): any; + + get_inc(...args: any[]): any; + + inspect(): any; + + toExtendedJSON(): any; + + toHexString(): any; + + toJSON(): any; + + toString(format: any): any; + + static createFromHexString(hexString: any): any; + + static createFromTime(time: any): any; + + static createPk(): any; + + static fromExtendedJSON(doc: any): any; + + static generate(time: any): any; + + static getInc(): any; + + static get_inc(...args: any[]): any; + + static index: number; + + static isValid(id: any): any; + + } + + class ObjectId { + constructor(inputId: any); + + equals(otherId: any): any; + + generate(...args: any[]): any; + + getInc(...args: any[]): any; + + getTimestamp(): any; + + get_inc(...args: any[]): any; + + inspect(): any; + + toExtendedJSON(): any; + + toHexString(): any; + + toJSON(): any; + + toString(format: any): any; + + static createFromHexString(hexString: any): any; + + static createFromTime(time: any): any; + + static createPk(): any; + + static fromExtendedJSON(doc: any): any; + + static generate(time: any): any; + + static getInc(): any; + + static get_inc(...args: any[]): any; + + static index: number; + + static isValid(id: any): any; + + } + + class Timestamp { + constructor(low: any, high: any); + + inspect(): any; + + toExtendedJSON(): any; + + toJSON(): any; + + static fromBigInt(value: any, unsigned: any): any; + + static fromBits(lowBits: any, highBits: any): any; + + static fromBytes(bytes: any, unsigned: any, le: any): any; + + static fromBytesBE(bytes: any, unsigned: any): any; + + static fromBytesLE(bytes: any, unsigned: any): any; + + static fromExtendedJSON(doc: any): any; + + static fromInt(value: any): any; + + static fromNumber(value: any): any; + + static fromString(str: any, optRadix: any): any; + + static fromValue(val: any, unsigned: any): any; + + static isLong(value: any): any; + + } + + class UUID { + constructor(input: any); + + equals(otherId: any): any; + + inspect(): any; + + toBinary(): any; + + toHexString(includeDashes: any): any; + + toJSON(): any; + + toString(encoding: any): any; + + static BSON_BINARY_SUBTYPE_DEFAULT: number; + + static BUFFER_SIZE: number; + + static SUBTYPE_BYTE_ARRAY: number; + + static SUBTYPE_COLUMN: number; + + static SUBTYPE_DEFAULT: number; + + static SUBTYPE_ENCRYPTED: number; + + static SUBTYPE_FUNCTION: number; + + static SUBTYPE_MD5: number; + + static SUBTYPE_USER_DEFINED: number; + + static SUBTYPE_UUID: number; + + static SUBTYPE_UUID_OLD: number; + + static createFromHexString(hexString: any): any; + + static fromExtendedJSON(doc: any, options: any): any; + + static generate(): any; + + static isValid(input: any): any; + + } + + const BSON_BINARY_SUBTYPE_BYTE_ARRAY: number; + + const BSON_BINARY_SUBTYPE_COLUMN: number; + + const BSON_BINARY_SUBTYPE_DEFAULT: number; + + const BSON_BINARY_SUBTYPE_ENCRYPTED: number; + + const BSON_BINARY_SUBTYPE_FUNCTION: number; + + const BSON_BINARY_SUBTYPE_MD5: number; + + const BSON_BINARY_SUBTYPE_USER_DEFINED: number; + + const BSON_BINARY_SUBTYPE_UUID: number; + + const BSON_BINARY_SUBTYPE_UUID_NEW: number; + + const BSON_DATA_ARRAY: number; + + const BSON_DATA_BINARY: number; + + const BSON_DATA_BOOLEAN: number; + + const BSON_DATA_CODE: number; + + const BSON_DATA_CODE_W_SCOPE: number; + + const BSON_DATA_DATE: number; + + const BSON_DATA_DBPOINTER: number; + + const BSON_DATA_DECIMAL128: number; + + const BSON_DATA_INT: number; + + const BSON_DATA_LONG: number; + + const BSON_DATA_MAX_KEY: number; + + const BSON_DATA_MIN_KEY: number; + + const BSON_DATA_NULL: number; + + const BSON_DATA_NUMBER: number; + + const BSON_DATA_OBJECT: number; + + const BSON_DATA_OID: number; + + const BSON_DATA_REGEXP: number; + + const BSON_DATA_STRING: number; + + const BSON_DATA_SYMBOL: number; + + const BSON_DATA_TIMESTAMP: number; + + const BSON_DATA_UNDEFINED: number; + + const BSON_INT32_MAX: number; + + const BSON_INT32_MIN: number; + + const BSON_INT64_MAX: number; + + const BSON_INT64_MIN: number; + + function calculateObjectSize(object: any, options: any): any; + + function deserialize(buffer: any, options: any): any; + + function deserializeStream(data: any, startIndex: any, numberOfDocuments: any, documents: any, docStartIndex: any, options: any): any; + + function serialize(object: any, options: any): any; + + function serializeWithBufferAndIndex(object: any, finalBuffer: any, options: any): any; + + function setInternalBufferSize(size: any): void; + + namespace EJSON { + function deserialize(ejson: any, options: any): any; + + function parse(text: any, options: any): any; + + function serialize(value: any, options: any): any; + + function stringify(value: any, replacer: any, space: any, options: any): any; + + } + + namespace Long { + namespace MAX_UNSIGNED_VALUE { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace MAX_VALUE { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace MIN_VALUE { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace NEG_ONE { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace ONE { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace TWO_PWR_24 { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace UONE { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace UZERO { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace ZERO { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + } + + namespace LongWithoutOverridesClass { + namespace MAX_UNSIGNED_VALUE { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace MAX_VALUE { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace MIN_VALUE { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace NEG_ONE { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace ONE { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace TWO_PWR_24 { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace UONE { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace UZERO { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace ZERO { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + } + + namespace Timestamp { + namespace MAX_UNSIGNED_VALUE { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace MAX_VALUE { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace MIN_VALUE { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace NEG_ONE { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace ONE { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace TWO_PWR_24 { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace UONE { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace UZERO { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + namespace ZERO { + const high: number; + + const low: number; + + const unsigned: boolean; + + function add(addend: any): any; + + function and(other: any): any; + + function comp(other: any): any; + + function compare(other: any): any; + + function div(divisor: any): any; + + function divide(divisor: any): any; + + function eq(other: any): any; + + function equals(other: any): any; + + function eqz(): any; + + function ge(other: any): any; + + function getHighBits(): any; + + function getHighBitsUnsigned(): any; + + function getLowBits(): any; + + function getLowBitsUnsigned(): any; + + function getNumBitsAbs(): any; + + function greaterThan(other: any): any; + + function greaterThanOrEqual(other: any): any; + + function gt(other: any): any; + + function gte(other: any): any; + + function inspect(): any; + + function isEven(): any; + + function isNegative(): any; + + function isOdd(): any; + + function isPositive(): any; + + function isZero(): any; + + function le(other: any): any; + + function lessThan(other: any): any; + + function lessThanOrEqual(other: any): any; + + function lt(other: any): any; + + function lte(other: any): any; + + function mod(divisor: any): any; + + function modulo(divisor: any): any; + + function mul(multiplier: any): any; + + function multiply(multiplier: any): any; + + function ne(other: any): any; + + function neg(): any; + + function negate(): any; + + function neq(other: any): any; + + function not(): any; + + function notEquals(other: any): any; + + function or(other: any): any; + + function rem(divisor: any): any; + + function shiftLeft(numBits: any): any; + + function shiftRight(numBits: any): any; + + function shiftRightUnsigned(numBits: any): any; + + function shl(numBits: any): any; + + function shr(numBits: any): any; + + function shr_u(numBits: any): any; + + function shru(numBits: any): any; + + function sub(subtrahend: any): any; + + function subtract(subtrahend: any): any; + + function toBigInt(): any; + + function toBytes(le: any): any; + + function toBytesBE(): any; + + function toBytesLE(): any; + + function toExtendedJSON(options: any): any; + + function toInt(): any; + + function toNumber(): any; + + function toSigned(): any; + + function toString(radix: any): any; + + function toUnsigned(): any; + + function xor(other: any): any; + + } + + } + +} + diff --git a/index.js b/index.js index 707aac0..939eb6a 100644 --- a/index.js +++ b/index.js @@ -20,6 +20,7 @@ const QUERY_TYPES = { $all: compareAll, // Equality + $ne: compareNe, $eq: compareEq, $exists: compareExists } @@ -41,13 +42,26 @@ const UPDATE_TYPES = { $push: updatePush } +class NoDocumentSuppliedError extends Error { + constructor(message) { + super(message) + this.name = this.constructor.name; + } +} +class UniqueIntegrityConstraintViolationError extends Error { + constructor(message) { + super(message) + this.name = this.constructor.name; + } +} + class DB { - constructor (bee) { + constructor(bee) { this.bee = bee this.collections = new Map() } - collection (name) { + collection(name) { if (!this.collections.has(name)) { const sub = this.bee.sub(name) const collection = new Collection(name, sub) @@ -57,14 +71,14 @@ class DB { return this.collections.get(name) } - async close () { + async close() { // TODO: This looks kinda stange. PR a close method on bee? - return this.bee.feed.close() + return this.bee.close() } } class Collection { - constructor (name, bee) { + constructor(name, bee) { this.name = name this.bee = bee this.docs = bee.sub('doc') @@ -72,9 +86,9 @@ class Collection { this.idx = bee.sub('idx') } - async insert (rawDoc) { + async insert(rawDoc) { let doc = rawDoc - if (!doc) throw new TypeError('No Document Supplied') + if (!doc) throw new NoDocumentSuppliedError('No Document Supplied') if (!doc._id) { doc = { ...doc, @@ -87,7 +101,7 @@ class Collection { const exists = await this.docs.get(key) - if (exists) throw new Error('Duplicate Key error, try using .update?') + if (exists) throw new UniqueIntegrityConstraintViolationError('Duplicate Key error, try using .update?') const value = BSON.serialize(doc) @@ -105,12 +119,8 @@ class Collection { return doc } - async update (query = {}, update = {}, options = {}) { - const { - upsert = false, - multi = false, - hint = null - } = options + async update(query = {}, update = {}, options = {}) { + const { upsert = false, multi = false, hint = null } = options let nMatched = 0 let nUpserted = 0 @@ -147,7 +157,9 @@ class Collection { for (const queryField of Object.keys(query)) { const queryValue = query[queryField] if ('$eq' in queryValue) initialDoc[queryField] = queryValue.$eq - else if (!isQueryObject(queryValue)) initialDoc[queryField] = queryValue + else if (!isQueryObject(queryValue)) { + initialDoc[queryField] = queryValue + } } const newDoc = performUpdate(initialDoc, update) @@ -163,8 +175,39 @@ class Collection { } } - async findOne (query = {}) { - const results = await (this.find(query).limit(1)) + async delete(query = {}, options = {}) { + const { multi = false, hint = null } = options + + let nDeleted = 0 + + let cursor = this.find(query) + if (hint) cursor = cursor.hint(hint) + if (!multi) cursor = cursor.limit(1) + + const indexes = await this.listIndexes() + + for await (const doc of cursor) { + nDeleted++ + + const key = doc._id.id + + await this.docs.del(key) + + for (const { fields, name } of indexes) { + // TODO: Cache index subs + const bee = this.idx.sub(name) + + await this._deIndexDocument(bee, fields, doc) + } + } + + return { + nDeleted + } + } + + async findOne(query = {}) { + const results = await this.find(query).limit(1) const [doc] = results @@ -173,11 +216,14 @@ class Collection { return doc } - find (query = {}) { + find(query = {}) { return new Cursor(query, this) } - async createIndex (fields, { rebuild = false, version = INDEX_VERSION, ...opts } = {}) { + async createIndex( + fields, + { rebuild = false, version = INDEX_VERSION, ...opts } = {} + ) { const name = fields.join(',') const exists = await this.indexExists(name) // Don't rebuild index if it's already set @@ -204,18 +250,18 @@ class Collection { return name } - async indexExists (name) { + async indexExists(name) { const exists = await this.idxs.get(name) return exists !== null } - async getIndex (name) { + async getIndex(name) { const data = await this.idxs.get(name) if (!data) throw new Error('Invalid index') return BSON.deserialize(data.value) } - async reIndex (name) { + async reIndex(name) { const { fields } = await this.getIndex(name) // TODO: Cache index subs const bee = this.idx.sub(name) @@ -226,7 +272,7 @@ class Collection { } // This is a private API, don't depend on it - async _indexDocument (bee, fields, doc) { + async _indexDocument(bee, fields, doc) { if (!hasFields(doc, fields)) return const idxValue = doc._id.id @@ -240,7 +286,7 @@ class Collection { await batch.flush() } - async _deIndexDocument (bee, fields, doc) { + async _deIndexDocument(bee, fields, doc) { if (!hasFields(doc, fields)) return const batch = bee.batch() @@ -254,7 +300,7 @@ class Collection { } // TODO: Cache indexes? - async listIndexes () { + async listIndexes() { const stream = this.idxs.createReadStream() const indexes = [] @@ -268,19 +314,23 @@ class Collection { } class Cursor { - constructor (query = {}, collection, opts = { - limit: Infinity, - skip: 0, - sort: null, - hint: null - }) { + constructor( + query = {}, + collection, + opts = { + limit: Infinity, + skip: 0, + sort: null, + hint: null + } + ) { this.query = query this.collection = collection // TODO: Validate opts this.opts = opts } - async count () { + async count() { let count = 0 // Item isn't being used but eslint will complain about it for await (const item of this) { // eslint-disable-line @@ -290,19 +340,19 @@ class Cursor { return count } - hint (hint) { + hint(hint) { return new Cursor(this.query, this.collection, { ...this.opts, hint }) } - limit (limit) { + limit(limit) { return new Cursor(this.query, this.collection, { ...this.opts, limit }) } - skip (skip) { + skip(skip) { return new Cursor(this.query, this.collection, { ...this.opts, skip }) } - sort (field, direction = 1) { + sort(field, direction = 1) { return new Cursor(this.query, this.collection, { ...this.opts, sort: { @@ -312,19 +362,21 @@ class Cursor { }) } - async getIndex () { + async getIndex() { const { sort, hint } = this.opts const query = this.query const queryFields = Object.keys(query) // Filter out fields with `$exists: false` since we can't index non-existance const existingFields = queryFields.filter((field) => { - return isQueryObject(query[field]) ? query[field].$exists !== false : true + return isQueryObject(query[field]) + ? query[field].$exists !== false + : true }) const eqS = existingFields.filter((name) => { const queryValue = query[name] if (!isQueryObject(queryValue)) return true - return ('$eq' in queryValue) + return '$eq' in queryValue }) if (hint) { @@ -332,9 +384,13 @@ class Cursor { const { fields } = hintIndex if (sort) { const sortIndex = fields.indexOf(sort.field) - if (sortIndex === -1) throw new Error("Hinted Index doesn't match required sort") + if (sortIndex === -1) { + throw new Error("Hinted Index doesn't match required sort") + } const consecutive = consecutiveSubset(fields, eqS) - if (consecutive !== sortIndex) throw new Error("Hinted index doesn't match required sort") + if (consecutive !== sortIndex) { + throw new Error("Hinted index doesn't match required sort") + } } const prefixFields = fields.slice(0, consecutiveSubset(fields, eqS)) @@ -367,7 +423,9 @@ class Cursor { }) // Sort by most $eq fields at the beginning .sort(({ fields: fieldsA }, { fields: fieldsB }) => { - return consecutiveSubset(fieldsB, eqS) - consecutiveSubset(fieldsA, eqS) + return ( + consecutiveSubset(fieldsB, eqS) - consecutiveSubset(fieldsA, eqS) + ) }) // The best is the one with the most eqS @@ -388,7 +446,7 @@ class Cursor { } } - async then (resolve, reject) { + async then(resolve, reject) { try { const results = [] for await (const item of this) { @@ -400,8 +458,8 @@ class Cursor { } } - async * [Symbol.asyncIterator] () { - if (this.query._id && (this.query._id instanceof ObjectID)) { + async *[Symbol.asyncIterator]() { + if (this.query._id && this.query._id instanceof ObjectID) { // Doc IDs are unique, so we can query against them without doing a search const key = this.query._id.id @@ -422,11 +480,7 @@ class Cursor { } yield doc } else { - const { - limit = Infinity, - skip = 0, - sort - } = this.opts + const { limit = Infinity, skip = 0, sort } = this.opts const query = this.query const seen = new Set() @@ -436,7 +490,7 @@ class Cursor { const bestIndex = await this.getIndex() - function processDoc (doc) { + function processDoc(doc) { let shouldYield = null let shouldBreak = false @@ -479,10 +533,15 @@ class Cursor { return isQueryObject(query[field]) ? !('$all' in query[field]) : true }) const subQuery = getSubset(query, subQueryFields) - const gt = makeIndexKeyFromQuery(query, prefixFields, index.fields, makeIndexKey) + const gt = makeIndexKeyFromQuery( + query, + prefixFields, + index.fields, + makeIndexKey + ) const opts = { - reverse: (sort?.direction === -1) + reverse: sort?.direction === -1 } if (gt && gt.length) { opts.gt = gt @@ -492,10 +551,12 @@ class Cursor { gt.copy(lt) // Set to MAX byte to only use keys with this prefix - lt[lt.length - 1] = 0xFF + lt[lt.length - 1] = 0xff } - const stream = this.collection.idx.sub(index.name).createReadStream(opts) + const stream = this.collection.idx + .sub(index.name) + .createReadStream(opts) for await (const { key, value: rawId } of stream) { const keyDoc = makeDocFromIndex(key, index.fields) @@ -531,7 +592,7 @@ class Cursor { } } -function performUpdate (doc, update) { +function performUpdate(doc, update) { if (Array.isArray(update)) { return update.reduce(performUpdate, doc) } @@ -546,7 +607,7 @@ function performUpdate (doc, update) { return newDoc } -function matchesQuery (doc, query) { +function matchesQuery(doc, query) { for (const key of Object.keys(query)) { const queryValue = query[key] const docValue = doc[key] @@ -555,7 +616,7 @@ function matchesQuery (doc, query) { return true } -function queryCompare (docValue, queryValue) { +function queryCompare(docValue, queryValue) { if (isQueryObject(queryValue)) { for (const queryType of Object.keys(queryValue)) { const compare = QUERY_TYPES[queryType] @@ -567,51 +628,62 @@ function queryCompare (docValue, queryValue) { } else return compareEq(docValue, queryValue) } -function compareAll (docValue, queryValue) { +function compareAll(docValue, queryValue) { // TODO: Add query validator function to detect this early. - if (!Array.isArray(queryValue)) throw new Error('$all must be set to an array') + if (!Array.isArray(queryValue)) { + throw new Error('$all must be set to an array') + } if (Array.isArray(docValue)) { - return queryValue.every((fromQuery) => docValue.some((fromDoc) => compareEq(fromDoc, fromQuery))) + return queryValue.every((fromQuery) => + docValue.some((fromDoc) => compareEq(fromDoc, fromQuery)) + ) } else { return false } } -function compareIn (docValue, queryValue) { +function compareIn(docValue, queryValue) { // TODO: Add query validator function to detect this early. - if (!Array.isArray(queryValue)) throw new Error('$in must be set to an array') + if (!Array.isArray(queryValue)) { + throw new Error('$in must be set to an array') + } if (Array.isArray(docValue)) { - return docValue.some((fromDoc) => queryValue.some((fromQuery) => compareEq(fromDoc, fromQuery))) + return docValue.some((fromDoc) => + queryValue.some((fromQuery) => compareEq(fromDoc, fromQuery)) + ) } else { return queryValue.some((fromQuery) => compareEq(docValue, fromQuery)) } } -function compareGt (docValue, queryValue) { +function compareGt(docValue, queryValue) { return ensureComparable(docValue) > ensureComparable(queryValue) } -function compareLt (docValue, queryValue) { +function compareLt(docValue, queryValue) { return ensureComparable(docValue) < ensureComparable(queryValue) } -function compareGte (docValue, queryValue) { +function compareGte(docValue, queryValue) { return ensureComparable(docValue) >= ensureComparable(queryValue) } -function compareLte (docValue, queryValue) { +function compareLte(docValue, queryValue) { return ensureComparable(docValue) <= ensureComparable(queryValue) } -function ensureComparable (value) { +function compareNe(docValue, queryValue) { + return ensureComparable(docValue) !== ensureComparable(queryValue) +} + +function ensureComparable(value) { if (value instanceof Date) return value.getTime() return value } -function compareEq (docValue, queryValue) { +function compareEq(docValue, queryValue) { if (Array.isArray(docValue)) { - return docValue - .some((item) => compareEq(item, queryValue)) + return docValue.some((item) => compareEq(item, queryValue)) } else if (typeof docValue?.equals === 'function') { return docValue.equals(queryValue) } else { @@ -619,11 +691,11 @@ function compareEq (docValue, queryValue) { } } -function compareExists (docValue, queryValue) { +function compareExists(docValue, queryValue) { return (docValue !== undefined) === queryValue } -function updatePull (doc, fields) { +function updatePull(doc, fields) { for (const key of Object.keys(fields)) { const value = doc[key] if (!Array.isArray(value)) continue @@ -633,7 +705,7 @@ function updatePull (doc, fields) { } } -function updatePop (doc, fields) { +function updatePop(doc, fields) { for (const key of Object.keys(fields)) { const value = doc[key] if (!Array.isArray(value)) continue @@ -646,7 +718,7 @@ function updatePop (doc, fields) { } } -function updatePush (doc, fields) { +function updatePush(doc, fields) { for (const key of Object.keys(fields)) { const toPush = fields[key] if (!(key in doc)) { @@ -666,7 +738,7 @@ function updatePush (doc, fields) { } } -function updateAddToSet (doc, fields) { +function updateAddToSet(doc, fields) { for (const key of Object.keys(fields)) { if (!(key in doc)) { doc[key] = fields[key] @@ -686,19 +758,19 @@ function updateAddToSet (doc, fields) { } } -function updateUnset (doc, fields) { +function updateUnset(doc, fields) { for (const key of Object.keys(fields)) { delete doc[key] } } -function updateSet (doc, fields) { +function updateSet(doc, fields) { for (const key of Object.keys(fields)) { doc[key] = fields[key] } } -function updateRename (doc, fields) { +function updateRename(doc, fields) { for (const key of Object.keys(fields)) { if (!(key in doc)) continue const name = fields[key] @@ -708,7 +780,7 @@ function updateRename (doc, fields) { } } -function updateInc (doc, fields) { +function updateInc(doc, fields) { for (const key of Object.keys(fields)) { const value = fields[key] if (!(key in doc)) { @@ -719,7 +791,7 @@ function updateInc (doc, fields) { } } -function updateMul (doc, fields) { +function updateMul(doc, fields) { for (const key of Object.keys(fields)) { const value = fields[key] if (!(key in doc)) { @@ -730,17 +802,18 @@ function updateMul (doc, fields) { } } -function hasFields (doc, fields) { - return fields.every((field) => (field in doc) && (field !== undefined)) +function hasFields(doc, fields) { + return fields.every((field) => field in doc && field !== undefined) } -function makeIndexKeyV1 (doc, fields) { +function makeIndexKeyV1(doc, fields) { // TODO: Does BSON array work well for ordering? // TODO: Maybe use a custom encoding? // Serialize the data into a BSON array const buffer = BSON.serialize( // Take all the indexed fields - fields.map((field) => doc[field]) + fields + .map((field) => doc[field]) // Add the document ID .concat(doc._id || []) ) @@ -751,7 +824,7 @@ function makeIndexKeyV1 (doc, fields) { return noPrefix } -function makeDocFromIndexV1 (key, fields) { +function makeDocFromIndexV1(key, fields) { const buffer = Buffer.alloc(key.length + 4) key.copy(buffer, 4) // Write a valid length prefix to the buffer for BSON decoding @@ -769,7 +842,7 @@ function makeDocFromIndexV1 (key, fields) { return doc } -function makeIndexKeyV2 (doc, fields, allFields = fields) { +function makeIndexKeyV2(doc, fields, allFields = fields) { // CBOR encode fields const keyValues = fields.map((field) => { const value = doc[field] @@ -786,7 +859,7 @@ function makeIndexKeyV2 (doc, fields, allFields = fields) { // If the number of fields in the index is greater than what we're generating // We should pad the list with some null bytes // Then we should remove these bytes to get the real prefix - while (keyValues.length < (allFields.length + 1)) { + while (keyValues.length < allFields.length + 1) { keyValues.push(0) toRemove++ } @@ -800,7 +873,7 @@ function makeIndexKeyV2 (doc, fields, allFields = fields) { return key } -function makeDocFromIndexV2 (key, fields) { +function makeDocFromIndexV2(key, fields) { // CBOR decode fields const decoded = cbor.decode(key) const doc = {} @@ -821,7 +894,7 @@ function makeDocFromIndexV2 (key, fields) { return doc } -function getSubset (doc, fields) { +function getSubset(doc, fields) { return fields.reduce((res, field) => { if (field in doc) { res[field] = doc[field] @@ -830,7 +903,7 @@ function getSubset (doc, fields) { }, {}) } -function * flattenDocument (doc, fields) { +function* flattenDocument(doc, fields) { let hadArray = false for (const key of fields) { @@ -853,7 +926,7 @@ function * flattenDocument (doc, fields) { if (!hadArray) yield doc } -function makeIndexKeyFromQuery (query, fields, indexFields, makeIndexKey) { +function makeIndexKeyFromQuery(query, fields, indexFields, makeIndexKey) { // TODO: Account for $eq and $gt fields const doc = fields.reduce((res, field) => { const value = query[field] @@ -874,15 +947,15 @@ function makeIndexKeyFromQuery (query, fields, indexFields, makeIndexKey) { return makeIndexKey(doc, fields, indexFields) } -function isQueryObject (object) { - return (typeof object === 'object') && has$Keys(object) +function isQueryObject(object) { + return typeof object === 'object' && has$Keys(object) } -function has$Keys (object) { +function has$Keys(object) { return Object.keys(object).some((key) => key.startsWith('$')) } -function consecutiveSubset (origin, values) { +function consecutiveSubset(origin, values) { let counter = 0 for (const item of origin) { if (!values.includes(item)) return counter diff --git a/package.json b/package.json index 96d65f9..5c5bc42 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,15 @@ { - "name": "hyperbeedeebee", - "version": "2.0.0", + "name": "hyperdeebee", + "version": "2.0.1", "description": "A MongoDB-like database built on top of Hyperbee with support for indexing", "main": "index.js", "scripts": { "lint": "standard --fix", - "test": "npm run lint && node ./test.js" + "test": "npm run lint && node ./test.js && node ./test_autobee.js" }, "repository": { "type": "git", - "url": "git+https://github.com/RangerMauve/hyperbeedeebee.git" + "url": "git+https://github.com/Jampard/hyperdeebee.git" }, "keywords": [ "hyperbee", @@ -24,14 +24,17 @@ "url": "https://github.com/RangerMauve/hyperbeedeebee/issues" }, "homepage": "https://github.com/RangerMauve/hyperbeedeebee#readme", + "types": "index.d.ts", "dependencies": { "bson": "^4.3.0", "cbor": "^8.1.0" }, "devDependencies": { - "hyperbee": "^1.5.4", - "hypercore": "^9.9.1", - "random-access-memory": "^3.1.2", + "autobase": "https://github.com/hypercore-protocol/autobase", + "b4a": "^1.6.0", + "hyperbee": "^2.0.0", + "hypercore": "^10.2.0", + "random-access-memory": "^5.0.0", "standard": "^16.0.3", "tape": "^5.2.2" } diff --git a/test.js b/test.js index 56ae983..9f8be94 100644 --- a/test.js +++ b/test.js @@ -650,6 +650,34 @@ test('Inserting over a document is an error', async (t) => { } }) +test('.delete a document', async (t) => { + const db = new DB(getBee()) + + try { + const collection = db.collection('example') + + const doc = await collection.insert({ + foo: 'bar', + goodbye: 'world', + something: 'something' + }) + + const { + nDeleted + } = await collection.delete({ foo: 'bar' }) + + t.equal(nDeleted, 1, 'One match') + + try { + await collection.findOne({ _id: doc._id }) + t.fail('Did not throw an error') + } catch (e) { + t.pass('Retrieving deleted doc threw an error') + } + } finally { + await db.close() + } +}) test('Upsert a document', async (t) => { const db = new DB(getBee()) diff --git a/test_autobee.js b/test_autobee.js new file mode 100644 index 0000000..0c3eef9 --- /dev/null +++ b/test_autobee.js @@ -0,0 +1,1074 @@ +const test = require('tape') +const RAM = require('random-access-memory') +const Hypercore = require('hypercore') +const Autobase = require('autobase') +const HyperbeeDeeBee = require('./') +const Autodeebee = require('./autodeebee') +const { DB } = HyperbeeDeeBee + +function getBee () { + const firstUser = new Hypercore(RAM) + const firstOutput = new Hypercore(RAM) + const inputs = [firstUser] + + const base1 = new Autobase({ + inputs, + localOutput: firstOutput, + localInput: firstUser + }) + return new Autodeebee(base1) +} +// eslint-disable-next-line no-unused-vars +function getBees () { + const firstUser = new Hypercore(RAM) + const firstOutput = new Hypercore(RAM) + const secondUser = new Hypercore(RAM) + const secondOutput = new Hypercore(RAM) + + const inputs = [firstUser, secondUser] + + const base1 = new Autobase({ + inputs, + localOutput: firstOutput, + localInput: firstUser + }) + const base2 = new Autobase({ + inputs, + localOutput: secondOutput, + localInput: secondUser + }) + + return [new Autodeebee(base1), new Autodeebee(base2)] +} + +test('Create a document in a collection', async (t) => { + const db = new DB(getBee()) + try { + const collection = db.collection('example') + + t.equal(collection.name, 'example', 'Collection created') + + const doc = await collection.insert({ example: 'Hello World!' }) + + t.ok(doc?._id, 'Doc got created along with _id') + + const otherDoc = await collection.findOne({ _id: doc._id }) + + t.equal(otherDoc.example, doc.example, 'DB property got loaded') + + t.end() + } finally { + await db.close() + } +}) + +test('Create documents with sparse props', async (t) => { + const db = new DB(getBee()) + try { + const collection = db.collection('example') + + await collection.insert({ example: 'World' }) + await collection.insert({ example: 'Hello', color: 'red' }) + + const doc = await collection.findOne({ color: 'red' }) + + t.equal(doc.color, 'red') + + t.end() + } finally { + await db.close() + } +}) + +test('Iterate through all docs in a db', async (t) => { + const db = new DB(getBee()) + + try { + const doc1 = await db.collection('example').insert({ example: 'Hello' }) + const doc2 = await db.collection('example').insert({ example: 'World' }) + + const docs = await db.collection('example').find() + + t.equal(docs.length, 2, 'Found both docs') + + let isFirst = true + for await (const doc of db.collection('example').find()) { + if (isFirst) { + t.ok(doc._id.equals(doc1._id), 'Got same id when iterating (1)') + isFirst = false + } else { + t.ok(doc._id.equals(doc2._id), 'Got same id when iterating (2)') + } + } + + t.end() + } finally { + await db.close() + } +}) +test('Iterate through different collections', async (t) => { + const db = new DB(getBee()) + + try { + await db.collection('example').insert({ example: 'Hello' }) + await db.collection('example').insert({ example: 'World' }) + + const doc1 = await db.collection('patras').insert({ example: 'Hello' }) + const doc2 = await db.collection('patras').insert({ example: 'World' }) + + const docs = await db.collection('patras').find() + + t.equal(docs.length, 2, 'Found both docs') + + let isFirst = true + for await (const doc of db.collection('patras').find()) { + if (isFirst) { + t.ok(doc._id.equals(doc1._id), 'Got same id when iterating (1)') + isFirst = false + } else { + t.ok(doc._id.equals(doc2._id), 'Got same id when iterating (2)') + } + } + + t.end() + } finally { + await db.close() + } +}) + +test('Iterate through different collections of different base', async (t) => { + const [base1, base2] = getBees() + const db = new DB(base1) + const db2 = new DB(base2) + + try { + const doc1 = await db.collection('patras').insert({ example: 'Hello' }) + const doc2 = await db.collection('patras').insert({ example: 'World' }) + + const docs = await db2.collection('patras').find() + + t.equal(docs.length, 2, 'Found both docs') + + let isFirst = true + for await (const doc of db2.collection('patras').find()) { + if (isFirst) { + t.ok(doc._id.equals(doc1._id), 'Got same id when iterating (1)') + isFirst = false + } else { + t.ok(doc._id.equals(doc2._id), 'Got same id when iterating (2)') + } + } + + t.end() + } finally { + await db.close() + } +}) +test('Limit and Skip', async (t) => { + const db = new DB(getBee()) + const NUM_TO_MAKE = 30 + let i = NUM_TO_MAKE + try { + while (i--) { + await db.collection('example').insert({ i }) + } + + const found = await db.collection('example').find().skip(10).limit(10) + + t.equal(found.length, 10, 'Got expected number of items') + + const onlyIs = found.map(({ i }) => i) + + const expected = [19, 18, 17, 16, 15, 14, 13, 12, 11, 10] + + t.deepEqual(onlyIs, expected, 'Got expected subset of Ids') + + t.end() + } finally { + await db.close() + } +}) + +test('Search by field equal', async (t) => { + const db = new DB(getBee()) + + try { + const doc1 = await db.collection('example').insert({ example: 'Hello' }) + const doc2 = await db + .collection('example') + .insert({ example: ['Hello', 'World'] }) + await db.collection('example').insert({ example: 'World' }) + + const found = await db.collection('example').find({ example: 'Hello' }) + + t.equal(found.length, 2, 'Found 2 documents') + t.ok(doc1._id.equals(found[0]._id), 'Got matched field document') + t.ok(doc2._id.equals(found[1]._id), 'Got matched array field document') + + t.end() + } finally { + await db.close() + } +}) + +test('Search by number fields', async (t) => { + const db = new DB(getBee()) + + try { + await db.collection('example').insert({ example: 4 }) + await db.collection('example').insert({ example: 20 }) + await db.collection('example').insert({ example: 666 }) + await db.collection('example').insert({ example: 9001 }) + + const found1 = await db.collection('example').find({ + example: { + $gte: 10, + $lte: 20 + } + }) + + t.equal(found1.length, 1, 'Found 1 document >= 10 and <= 20') + + const found2 = await db.collection('example').find({ + example: { + $gt: 9000 + } + }) + + t.equal(found2.length, 1, 'Found 1 document > 9000') + + const found3 = await db.collection('example').find({ + example: { + $lt: 10 + } + }) + + t.equal(found3.length, 1, 'Found 1 document < 10') + + const found4 = await db.collection('example').find({ + example: { + $ne: 666 + } + }) + + t.equal(found4.length, 3, 'Found 3 document =! 666') + + t.end() + } finally { + await db.close() + } +}) + +test('Search by date fields', async (t) => { + const db = new DB(getBee()) + + try { + await db.collection('example').insert({ example: new Date(2000, 0) }) + await db.collection('example').insert({ example: new Date(2000, 2) }) + await db.collection('example').insert({ example: new Date(2000, 6) }) + await db.collection('example').insert({ example: new Date(2000, 11) }) + + const found1 = await db.collection('example').find({ + example: { + $gte: new Date(2000, 1), + $lte: new Date(2000, 6) + } + }) + + t.equal(found1.length, 2, 'Found 2 document >= Feb and <= July') + + t.end() + } finally { + await db.close() + } +}) + +test('Search using $in and $all', async (t) => { + const db = new DB(getBee()) + + try { + await db.collection('example').insert({ example: [1, 3, 5, 7, 9] }) + await db.collection('example').insert({ example: [2, 3, 6, 8, 10] }) + await db.collection('example').insert({ example: 1 }) + await db.collection('example').insert({ example: 2 }) + + const found1 = await db.collection('example').find({ + example: { + $in: [1, 3, 8] + } + }) + + t.equal(found1.length, 3, 'Found 3 matching documents') + + const found2 = await db.collection('example').find({ + example: { + $all: [2, 6, 8] + } + }) + + t.equal(found2.length, 1, 'Found 1 matching document') + + t.end() + } finally { + await db.close() + } +}) + +test('Search using $exists', async (t) => { + const db = new DB(getBee()) + + try { + await db.collection('example').insert({ example: 'wow' }) + await db.collection('example').insert({ nothing: 'here' }) + + const results1 = await db.collection('example').find({ + example: { $exists: true } + }) + + t.equal(results1.length, 1, 'Found document with field') + + const results2 = await db.collection('example').find({ + example: { $exists: false } + }) + + t.equal(results2.length, 1, 'Found document without field') + + t.end() + } finally { + await db.close() + } +}) + +test('Create indexes and list them', async (t) => { + const db = new DB(getBee()) + try { + await db + .collection('example') + .insert({ example: 1, createdAt: new Date() }) + + await db.collection('example').createIndex(['createdAt', 'example']) + + const indexes = await db.collection('example').listIndexes() + + t.equal(indexes.length, 1, 'Got one index') + t.deepEqual( + indexes[0].fields, + ['createdAt', 'example'], + 'Index containes expected fields' + ) + t.equal( + indexes[0].name, + ['createdAt', 'example'].join(','), + 'Index generated expected name' + ) + + await db + .collection('example') + .insert({ example: 2, createdAt: new Date() }) + + t.ok('Able to insert document with index') + + t.end() + } finally { + await db.close() + } +}) + +test('Sort by index', async (t) => { + const db = new DB(getBee()) + try { + await db.collection('example').createIndex(['createdAt']) + + await db + .collection('example') + .insert({ example: 1, createdAt: new Date(1000) }) + await db + .collection('example') + .insert({ example: 2, createdAt: new Date(2000) }) + await db + .collection('example') + .insert({ example: 3, createdAt: new Date(3000) }) + + let counter = 3 + for await (const { example, createdAt } of db + .collection('example') + .find() + .sort('createdAt', -1)) { + t.equal(example, counter, 'Got doc in expected order') + t.equal(createdAt.getTime(), counter * 1000, 'Got expected timestamp') + counter-- + } + + t.equal(counter, 0, 'Sorted through all 3 documents') + + t.end() + } finally { + await db.close() + } +}) + +test('Cannot sort without index', async (t) => { + const db = new DB(getBee()) + try { + try { + await db.collection('example').find().sort('notfound') + } catch { + t.pass('Threw error when sorting without index') + } + + t.end() + } finally { + await db.close() + } +}) + +test('Limit and skip with index sort', async (t) => { + const db = new DB(getBee()) + const NUM_TO_MAKE = 30 + let i = NUM_TO_MAKE + try { + await db.collection('example').createIndex(['i']) + + while (i--) { + await db.collection('example').insert({ i }) + } + + const query = db + .collection('example') + .find() + .skip(10) + .limit(10) + .sort('i', -1) + + const index = await query.getIndex() + + t.ok(index, 'Using index for search') + + const found = await query + + t.equal(found.length, 10, 'Got expected number of items') + + const onlyIs = found.map(({ i }) => i) + + const expected = [19, 18, 17, 16, 15, 14, 13, 12, 11, 10] + + t.deepEqual(onlyIs, expected, 'Got expected subset of Ids') + + t.end() + } finally { + await db.close() + } +}) + +test('Use $eq for indexes', async (t) => { + const db = new DB(getBee()) + try { + const indexFields = ['color', 'flavor'] + await db.collection('example').createIndex(indexFields) + + await db + .collection('example') + .insert({ example: 1, color: 'red', flavor: 'watermelon' }) + await db + .collection('example') + .insert({ example: 2, color: 'red', flavor: 'raspberry' }) + await db + .collection('example') + .insert({ example: 3, color: 'purple', flavor: 'good' }) + + const query = db.collection('example').find({ + color: 'red' + }) + + const index = await query.getIndex() + + t.ok(index, 'Using an index for the query') + t.deepEqual(index?.index?.fields, indexFields, 'Using the correct index') + + const results = await query + + t.equal(results.length, 2, 'Got expected documents') + + const sortedQuery = query.sort('flavor', -1) + + const sortedIndex = await sortedQuery.getIndex() + + t.ok(sortedIndex, 'Using an index for the sorted query') + + const sorted = await sortedQuery + + t.equal(sorted.length, 2, 'Got expected documents when sorting') + t.equal(sorted[0]?.flavor, 'watermelon', 'Got expected order for sort') + + t.end() + } finally { + await db.close() + } +}) + +test('Arrays get flattened for indexes', async (t) => { + const db = new DB(getBee()) + + try { + await db.collection('example').createIndex(['ingredients', 'name']) + + await db.collection('example').insert({ + name: 'le ghetti du spa', + ingredients: ['noodles', 'corn', 'sauce'] + }) + await db.collection('example').insert({ + name: 'cheeseland', + ingredients: ['corn', 'cheese', 'sauce'] + }) + await db.collection('example').insert({ + name: 'literally corn', + ingredients: ['corn'] + }) + + const query = db + .collection('example') + .find({ + ingredients: 'sauce' + }) + .sort('name') + + const index = await query.getIndex() + + t.ok(index, 'Using an index for the query') + t.deepEqual( + index?.index?.fields, + ['ingredients', 'name'], + 'Using the correct index' + ) + + const results = await query + + t.equal(results.length, 2, 'Found two matching documents') + t.equal(results[0]?.name, 'cheeseland', 'Documents got sorted correctly') + + t.end() + } finally { + await db.close() + } +}) + +test('Indexed Search using $exists', async (t) => { + const db = new DB(getBee()) + + try { + await db.collection('example').createIndex(['example']) + + await db.collection('example').insert({ example: 'wow' }) + await db.collection('example').insert({ nothing: 'here' }) + + const hasIndex = await db + .collection('example') + .find({ + example: { $exists: true } + }) + .getIndex() + + t.ok(hasIndex, 'Using index for search') + + const results1 = await db.collection('example').find({ + example: { $exists: true } + }) + + t.equal(results1.length, 1, 'Found document with field') + + const results2 = await db.collection('example').find({ + example: { $exists: false } + }) + + t.equal(results2.length, 1, 'Found document without field') + + t.end() + } finally { + await db.close() + } +}) + +test('Indexed Search by date fields (with sort)', async (t) => { + const db = new DB(getBee()) + + try { + await db.collection('example').createIndex(['example']) + await db.collection('example').insert({ example: new Date(2000, 0) }) + await db.collection('example').insert({ example: new Date(2000, 2) }) + await db.collection('example').insert({ example: new Date(2000, 6) }) + await db.collection('example').insert({ example: new Date(2000, 11) }) + + const query = db + .collection('example') + .find({ + example: { + $gte: new Date(2000, 1), + $lte: new Date(2000, 6) + } + }) + .sort('example') + + const index = await query.getIndex() + + t.ok(index, 'Using index for date search') + + const found1 = await query + + t.equal(found1.length, 2, 'Found 2 documents >= Feb and <= July') + + t.end() + } finally { + await db.close() + } +}) + +test('Indexed Search using $in and $all with numbers', async (t) => { + const db = new DB(getBee()) + + try { + await db.collection('example').createIndex(['example']) + + // Account for array fields that aren't in the index. + await db + .collection('example') + .insert({ example: [1, 3, 5, 7, 9], fake: [] }) + await db + .collection('example') + .insert({ example: [2, 3, 6, 8, 10], fake: [] }) + await db.collection('example').insert({ example: 1, fake: [] }) + await db.collection('example').insert({ example: 2, fake: [] }) + + const query1 = db.collection('example').find({ + example: { + $in: [1, 3, 8] + } + }) + + const index1 = await query1.getIndex() + + t.ok(index1, 'Using index for $in search') + + const found1 = await query1 + + t.equal(found1.length, 3, 'Found 3 matching documents') + + const query2 = db.collection('example').find({ + example: { + $all: [2, 6, 8] + } + }) + + const index2 = await query2.getIndex() + + t.ok(index2, 'Using index for $all search') + + const found2 = await query2 + + t.equal(found2.length, 1, 'Found 1 matching document') + + t.end() + } finally { + await db.close() + } +}) + +test('Indexed Search using $in and $all with string', async (t) => { + const db = new DB(getBee()) + + try { + await db.collection('example').createIndex(['example']) + + await db + .collection('example') + .insert({ example: ['cats', 'frogs', 'pets', 'spiders', 'furry'] }) + await db + .collection('example') + .insert({ example: ['dogs', 'frogs', 'companions', 'bats'] }) + await db.collection('example').insert({ example: 'cats' }) + await db.collection('example').insert({ example: 'dogs' }) + + const query1 = db.collection('example').find({ + example: { + $in: ['cats', 'frogs', 'bats'] + } + }) + + const index1 = await query1.getIndex() + + t.ok(index1, 'Using index for $in search') + + const found1 = await query1 + + t.equal(found1.length, 3, 'Found 3 matching documents') + + const query2 = db.collection('example').find({ + example: { + $all: ['dogs', 'companions', 'bats'] + } + }) + + const index2 = await query2.getIndex() + + t.ok(index2, 'Using index for $all search') + + const found2 = await query2 + + t.equal(found2.length, 1, 'Found 1 matching document') + + t.end() + } finally { + await db.close() + } +}) + +test('Indexed text search using sort and $all', async (t) => { + const db = new DB(getBee()) + + try { + await db.collection('example').createIndex(['index', 'example']) + + await db + .collection('example') + .insert({ index: 1, example: ['hello', 'world'] }) + await db + .collection('example') + .insert({ index: 2, example: ['goodbye', 'world'] }) + + const results1 = await db.collection('example').find({ + example: { + $all: ['world'] + } + }) + + t.equal(results1.length, 2, 'Matched two documents for $all') + t.end() + } finally { + await db.close() + } +}) + +test('Use hint API to specify the index to use', async (t) => { + const db = new DB(getBee()) + + try { + await db.collection('example').createIndex(['example']) + await db.collection('example').createIndex(['createdAt']) + + await db + .collection('example') + .insert({ example: 'wow', createdAt: new Date() }) + await db + .collection('example') + .insert({ example: 'here', createdAt: new Date() }) + + const chosen1 = await db + .collection('example') + .find({}) + .hint('example') + .getIndex() + + t.equal(chosen1?.index?.name, 'example', 'Hinted index got used') + + const chosen2 = await db + .collection('example') + .find({}) + .sort('createdAt') + .hint('createdAt') + .getIndex() + + t.equal(chosen2?.index?.name, 'createdAt', 'Hinted index got used') + + t.end() + } finally { + await db.close() + } +}) + +test('Inserting over a document is an error', async (t) => { + const db = new DB(getBee()) + + try { + const doc = await db.collection('example').insert({ _hello: 'world' }) + + try { + await db.collection('example').insert(doc) + t.fail('Did not throw an error') + } catch (e) { + t.pass('Inserting threw an error') + } + } finally { + await db.close() + } +}) + +test('.delete a document', async (t) => { + const db = new DB(getBee()) + + try { + const collection = db.collection('example') + + const doc = await collection.insert({ + foo: 'bar', + goodbye: 'world', + something: 'something' + }) + + const { + nDeleted + } = await collection.delete({ foo: 'bar' }) + + t.equal(nDeleted, 1, 'One match') + + try { + await collection.findOne({ _id: doc._id }) + t.fail('Did not throw an error') + } catch (e) { + t.pass('Retrieving deleted doc threw an error') + } + } finally { + await db.close() + } +}) + +test('Upsert a document', async (t) => { + const db = new DB(getBee()) + + try { + const { nUpserted, nModified, nMatched } = await db + .collection('example') + .update( + {}, + { + hello: 'world' + }, + { upsert: true } + ) + + t.equal(nUpserted, 1, 'Upserted a doc') + t.equal(nMatched, 0, 'No existing docs matched') + t.equal(nModified, 0, 'No existing docs modified') + + const doc = await db.collection('example').findOne({ hello: 'world' }) + + t.ok(doc, 'Found doc') + t.equal(doc?.hello, 'world', 'Field got set') + } finally { + await db.close() + } +}) + +test('.update with $set, $unset, $rename', async (t) => { + const db = new DB(getBee()) + + try { + const collection = db.collection('example') + + const doc = await collection.insert({ + foo: 'bar', + goodbye: 'world', + something: 'something' + }) + + const { nUpserted, nModified, nMatched } = await collection.update( + {}, + { + $set: { + foo: 'bazz', + fizz: 'buzz' + }, + // Set with raw fields + hello: 'world', + $unset: { + goodbye: '' + }, + $rename: { + something: 'whatever' + } + } + ) + + t.equal(nUpserted, 0, 'No upserts') + t.equal(nMatched, 1, 'One match') + t.equal(nModified, 1, 'One change') + + const updatedDoc = await collection.findOne({ _id: doc._id }) + + t.ok(updatedDoc, 'Found after updating') + + t.equal(updatedDoc.foo, 'bazz', 'Existing field got updated') + t.equal(updatedDoc.fizz, 'buzz', 'New field got set') + t.equal(updatedDoc.hello, 'world', 'Raw field got set') + t.notOk('goodbye' in updatedDoc, 'Field got unset') + t.notOk('something' in updatedDoc, 'Renamed field got removed') + t.equal(updatedDoc.whatever, 'something', 'Field got renamed') + } finally { + await db.close() + } +}) + +test('.update with $inc, $mult', async (t) => { + const db = new DB(getBee()) + + try { + const collection = db.collection('example') + + const doc = await collection.insert({ + incValue: 4, + multValue: 4 + }) + + const { nUpserted, nModified, nMatched } = await collection.update( + {}, + { + $inc: { + incValue: 20, + incSet: 666 + }, + $mul: { + multValue: 20, + multSet: 666 + } + } + ) + + t.equal(nUpserted, 0, 'No upserts') + t.equal(nMatched, 1, 'One match') + t.equal(nModified, 1, 'One change') + + const updatedDoc = await collection.findOne({ _id: doc._id }) + + t.ok(updatedDoc, 'Found after updating') + t.equal(updatedDoc?.incValue, 4 + 20, 'Value got incremented') + t.equal(updatedDoc?.incSet, 666, 'Unset field got set') + + t.equal(updatedDoc?.multValue, 4 * 20, 'Value got multiplied') + t.equal(updatedDoc?.multSet, 0, 'Unset field got set to 0') + } finally { + await db.close() + } +}) + +test('.update with $push, $addToSet', async (t) => { + const db = new DB(getBee()) + + try { + const collection = db.collection('example') + + const doc = await collection.insert({ + existingSet: ['a', 'b'], + duplicateSet: ['a', 'b'], + eachSet: ['a', 'b'], + existingPush: ['a', 'b'], + duplicatePush: ['a', 'b'], + eachPush: ['a', 'b'] + }) + + const { nUpserted, nModified, nMatched } = await collection.update( + {}, + { + $addToSet: { + existingSet: 'c', + duplicateSet: 'a', + eachSet: { $each: ['b', 'c'] } + }, + $push: { + existingPush: 'c', + duplicatePush: 'a', + eachPush: { $each: ['b', 'c'] } + } + } + ) + + t.equal(nUpserted, 0, 'No upserts') + t.equal(nMatched, 1, 'One match') + t.equal(nModified, 1, 'One change') + + const updatedDoc = await collection.findOne({ _id: doc._id }) + + t.ok(updatedDoc, 'Found after updating') + + t.deepEqual(updatedDoc.existingSet, ['a', 'b', 'c']) + t.deepEqual(updatedDoc.duplicateSet, ['a', 'b']) + t.deepEqual(updatedDoc.eachSet, ['a', 'b', 'c']) + + t.deepEqual(updatedDoc.existingPush, ['a', 'b', 'c']) + t.deepEqual(updatedDoc.duplicatePush, ['a', 'b', 'a']) + t.deepEqual(updatedDoc.eachPush, ['a', 'b', 'b', 'c']) + } finally { + await db.close() + } +}) + +test('.update multiple documents', async (t) => { + const db = new DB(getBee()) + + t.plan(4 + 3) + + try { + const collection = db.collection('example') + + await collection.insert({ value: 0 }) + await collection.insert({ value: 0 }) + await collection.insert({ value: 0 }) + await collection.insert({ value: 0 }) + + const { nUpserted, nModified, nMatched } = await collection.update( + {}, + { + $inc: { + value: 1 + } + }, + { multi: true } + ) + + t.equal(nUpserted, 0, 'No upserts') + t.equal(nMatched, 4, '4 matches') + t.equal(nModified, 4, '4 changes') + + for await (const doc of collection.find()) { + t.equal(doc.value, 1, 'Doc got updated') + } + } finally { + await db.close() + } +}) + +test('.update with array of updates', async (t) => { + const db = new DB(getBee()) + + try { + const collection = db.collection('example') + + await collection.insert({ value: 0 }) + + const { nUpserted, nModified, nMatched } = await collection.update({}, [ + { $inc: { value: 1 } }, + { $rename: { value: 'something' } } + ]) + + t.equal(nUpserted, 0, 'No upserts') + t.equal(nMatched, 1, 'One match') + t.equal(nModified, 1, 'One change') + + const doc = await collection.findOne() + + t.equal(doc?.something, 1, 'field got incremented and renamed') + } finally { + await db.close() + } +}) + +/* Test template + +test('', async (t) => { + const db = new DB(getBee()) + + try { + const collection = db.collection('example') + + } finally { + await db.close() + } +}) +*/