UNPKG

@fireproof/database

Version:
1,539 lines (1,520 loc) 713 kB
console.log('cjs/node build'); "use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __esm = (fn, res) => function __init() { return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; }; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (target, all) => { for (var name4 in all) __defProp(target, name4, { get: all[name4], enumerable: true }); }; var __copyProps = (to, from5, except, desc) => { if (from5 && typeof from5 === "object" || typeof from5 === "function") { for (let key of __getOwnPropNames(from5)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from5[key], enumerable: !(desc = __getOwnPropDesc(from5, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // ../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/is.js function is(value) { if (value === null) { return "null"; } if (value === void 0) { return "undefined"; } if (value === true || value === false) { return "boolean"; } const typeOf = typeof value; if (typeofs.includes(typeOf)) { return typeOf; } if (typeOf === "function") { return "Function"; } if (Array.isArray(value)) { return "Array"; } if (isBuffer(value)) { return "Buffer"; } const objectType = getObjectType(value); if (objectType) { return objectType; } return "Object"; } function isBuffer(value) { return value && value.constructor && value.constructor.isBuffer && value.constructor.isBuffer.call(null, value); } function getObjectType(value) { const objectTypeName = Object.prototype.toString.call(value).slice(8, -1); if (objectTypeNames.includes(objectTypeName)) { return objectTypeName; } return void 0; } var typeofs, objectTypeNames; var init_is = __esm({ "../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/is.js"() { typeofs = [ "string", "number", "bigint", "symbol" ]; objectTypeNames = [ "Function", "Generator", "AsyncGenerator", "GeneratorFunction", "AsyncGeneratorFunction", "AsyncFunction", "Observable", "Array", "Buffer", "Object", "RegExp", "Date", "Error", "Map", "Set", "WeakMap", "WeakSet", "ArrayBuffer", "SharedArrayBuffer", "DataView", "Promise", "URL", "HTMLElement", "Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "BigInt64Array", "BigUint64Array" ]; } }); // ../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/token.js var Type, Token; var init_token = __esm({ "../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/token.js"() { Type = class { constructor(major, name4, terminal) { this.major = major; this.majorEncoded = major << 5; this.name = name4; this.terminal = terminal; } toString() { return `Type[${this.major}].${this.name}`; } compare(typ) { return this.major < typ.major ? -1 : this.major > typ.major ? 1 : 0; } }; Type.uint = new Type(0, "uint", true); Type.negint = new Type(1, "negint", true); Type.bytes = new Type(2, "bytes", true); Type.string = new Type(3, "string", true); Type.array = new Type(4, "array", false); Type.map = new Type(5, "map", false); Type.tag = new Type(6, "tag", false); Type.float = new Type(7, "float", true); Type.false = new Type(7, "false", true); Type.true = new Type(7, "true", true); Type.null = new Type(7, "null", true); Type.undefined = new Type(7, "undefined", true); Type.break = new Type(7, "break", true); Token = class { constructor(type, value, encodedLength) { this.type = type; this.value = value; this.encodedLength = encodedLength; this.encodedBytes = void 0; this.byteValue = void 0; } toString() { return `Token[${this.type}].${this.value}`; } }; } }); // ../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/byte-utils.js function isBuffer2(buf3) { return useBuffer && globalThis.Buffer.isBuffer(buf3); } function asU8A(buf3) { if (!(buf3 instanceof Uint8Array)) { return Uint8Array.from(buf3); } return isBuffer2(buf3) ? new Uint8Array(buf3.buffer, buf3.byteOffset, buf3.byteLength) : buf3; } function compare(b1, b2) { if (isBuffer2(b1) && isBuffer2(b2)) { return b1.compare(b2); } for (let i = 0; i < b1.length; i++) { if (b1[i] === b2[i]) { continue; } return b1[i] < b2[i] ? -1 : 1; } return 0; } function utf8ToBytes(string, units = Infinity) { let codePoint; const length3 = string.length; let leadSurrogate = null; const bytes = []; for (let i = 0; i < length3; ++i) { codePoint = string.charCodeAt(i); if (codePoint > 55295 && codePoint < 57344) { if (!leadSurrogate) { if (codePoint > 56319) { if ((units -= 3) > -1) bytes.push(239, 191, 189); continue; } else if (i + 1 === length3) { if ((units -= 3) > -1) bytes.push(239, 191, 189); continue; } leadSurrogate = codePoint; continue; } if (codePoint < 56320) { if ((units -= 3) > -1) bytes.push(239, 191, 189); leadSurrogate = codePoint; continue; } codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536; } else if (leadSurrogate) { if ((units -= 3) > -1) bytes.push(239, 191, 189); } leadSurrogate = null; if (codePoint < 128) { if ((units -= 1) < 0) break; bytes.push(codePoint); } else if (codePoint < 2048) { if ((units -= 2) < 0) break; bytes.push(codePoint >> 6 | 192, codePoint & 63 | 128); } else if (codePoint < 65536) { if ((units -= 3) < 0) break; bytes.push(codePoint >> 12 | 224, codePoint >> 6 & 63 | 128, codePoint & 63 | 128); } else if (codePoint < 1114112) { if ((units -= 4) < 0) break; bytes.push(codePoint >> 18 | 240, codePoint >> 12 & 63 | 128, codePoint >> 6 & 63 | 128, codePoint & 63 | 128); } else { throw new Error("Invalid code point"); } } return bytes; } function utf8Slice(buf3, offset, end) { const res = []; while (offset < end) { const firstByte = buf3[offset]; let codePoint = null; let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1; if (offset + bytesPerSequence <= end) { let secondByte, thirdByte, fourthByte, tempCodePoint; switch (bytesPerSequence) { case 1: if (firstByte < 128) { codePoint = firstByte; } break; case 2: secondByte = buf3[offset + 1]; if ((secondByte & 192) === 128) { tempCodePoint = (firstByte & 31) << 6 | secondByte & 63; if (tempCodePoint > 127) { codePoint = tempCodePoint; } } break; case 3: secondByte = buf3[offset + 1]; thirdByte = buf3[offset + 2]; if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) { tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63; if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) { codePoint = tempCodePoint; } } break; case 4: secondByte = buf3[offset + 1]; thirdByte = buf3[offset + 2]; fourthByte = buf3[offset + 3]; if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) { tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63; if (tempCodePoint > 65535 && tempCodePoint < 1114112) { codePoint = tempCodePoint; } } } } if (codePoint === null) { codePoint = 65533; bytesPerSequence = 1; } else if (codePoint > 65535) { codePoint -= 65536; res.push(codePoint >>> 10 & 1023 | 55296); codePoint = 56320 | codePoint & 1023; } res.push(codePoint); offset += bytesPerSequence; } return decodeCodePointsArray(res); } function decodeCodePointsArray(codePoints) { const len = codePoints.length; if (len <= MAX_ARGUMENTS_LENGTH) { return String.fromCharCode.apply(String, codePoints); } let res = ""; let i = 0; while (i < len) { res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)); } return res; } var useBuffer, textDecoder, textEncoder, toString, fromString, fromArray, slice, concat, alloc, MAX_ARGUMENTS_LENGTH; var init_byte_utils = __esm({ "../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/byte-utils.js"() { useBuffer = globalThis.process && !globalThis.process.browser && globalThis.Buffer && typeof globalThis.Buffer.isBuffer === "function"; textDecoder = new TextDecoder(); textEncoder = new TextEncoder(); toString = useBuffer ? (bytes, start, end) => { return end - start > 64 ? globalThis.Buffer.from(bytes.subarray(start, end)).toString("utf8") : utf8Slice(bytes, start, end); } : (bytes, start, end) => { return end - start > 64 ? textDecoder.decode(bytes.subarray(start, end)) : utf8Slice(bytes, start, end); }; fromString = useBuffer ? (string) => { return string.length > 64 ? globalThis.Buffer.from(string) : utf8ToBytes(string); } : (string) => { return string.length > 64 ? textEncoder.encode(string) : utf8ToBytes(string); }; fromArray = (arr) => { return Uint8Array.from(arr); }; slice = useBuffer ? (bytes, start, end) => { if (isBuffer2(bytes)) { return new Uint8Array(bytes.subarray(start, end)); } return bytes.slice(start, end); } : (bytes, start, end) => { return bytes.slice(start, end); }; concat = useBuffer ? (chunks, length3) => { chunks = chunks.map((c) => c instanceof Uint8Array ? c : globalThis.Buffer.from(c)); return asU8A(globalThis.Buffer.concat(chunks, length3)); } : (chunks, length3) => { const out = new Uint8Array(length3); let off = 0; for (let b of chunks) { if (off + b.length > out.length) { b = b.subarray(0, out.length - off); } out.set(b, off); off += b.length; } return out; }; alloc = useBuffer ? (size) => { return globalThis.Buffer.allocUnsafe(size); } : (size) => { return new Uint8Array(size); }; MAX_ARGUMENTS_LENGTH = 4096; } }); // ../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/bl.js var defaultChunkSize, Bl; var init_bl = __esm({ "../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/bl.js"() { init_byte_utils(); defaultChunkSize = 256; Bl = class { constructor(chunkSize = defaultChunkSize) { this.chunkSize = chunkSize; this.cursor = 0; this.maxCursor = -1; this.chunks = []; this._initReuseChunk = null; } reset() { this.cursor = 0; this.maxCursor = -1; if (this.chunks.length) { this.chunks = []; } if (this._initReuseChunk !== null) { this.chunks.push(this._initReuseChunk); this.maxCursor = this._initReuseChunk.length - 1; } } push(bytes) { let topChunk = this.chunks[this.chunks.length - 1]; const newMax = this.cursor + bytes.length; if (newMax <= this.maxCursor + 1) { const chunkPos = topChunk.length - (this.maxCursor - this.cursor) - 1; topChunk.set(bytes, chunkPos); } else { if (topChunk) { const chunkPos = topChunk.length - (this.maxCursor - this.cursor) - 1; if (chunkPos < topChunk.length) { this.chunks[this.chunks.length - 1] = topChunk.subarray(0, chunkPos); this.maxCursor = this.cursor - 1; } } if (bytes.length < 64 && bytes.length < this.chunkSize) { topChunk = alloc(this.chunkSize); this.chunks.push(topChunk); this.maxCursor += topChunk.length; if (this._initReuseChunk === null) { this._initReuseChunk = topChunk; } topChunk.set(bytes, 0); } else { this.chunks.push(bytes); this.maxCursor += bytes.length; } } this.cursor += bytes.length; } toBytes(reset = false) { let byts; if (this.chunks.length === 1) { const chunk = this.chunks[0]; if (reset && this.cursor > chunk.length / 2) { byts = this.cursor === chunk.length ? chunk : chunk.subarray(0, this.cursor); this._initReuseChunk = null; this.chunks = []; } else { byts = slice(chunk, 0, this.cursor); } } else { byts = concat(this.chunks, this.cursor); } if (reset) { this.reset(); } return byts; } }; } }); // ../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/common.js function assertEnoughData(data, pos, need) { if (data.length - pos < need) { throw new Error(`${decodeErrPrefix} not enough data for type`); } } var decodeErrPrefix, encodeErrPrefix, uintMinorPrefixBytes; var init_common = __esm({ "../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/common.js"() { decodeErrPrefix = "CBOR decode error:"; encodeErrPrefix = "CBOR encode error:"; uintMinorPrefixBytes = []; uintMinorPrefixBytes[23] = 1; uintMinorPrefixBytes[24] = 2; uintMinorPrefixBytes[25] = 3; uintMinorPrefixBytes[26] = 5; uintMinorPrefixBytes[27] = 9; } }); // ../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/0uint.js function readUint8(data, offset, options) { assertEnoughData(data, offset, 1); const value = data[offset]; if (options.strict === true && value < uintBoundaries[0]) { throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`); } return value; } function readUint16(data, offset, options) { assertEnoughData(data, offset, 2); const value = data[offset] << 8 | data[offset + 1]; if (options.strict === true && value < uintBoundaries[1]) { throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`); } return value; } function readUint32(data, offset, options) { assertEnoughData(data, offset, 4); const value = data[offset] * 16777216 + (data[offset + 1] << 16) + (data[offset + 2] << 8) + data[offset + 3]; if (options.strict === true && value < uintBoundaries[2]) { throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`); } return value; } function readUint64(data, offset, options) { assertEnoughData(data, offset, 8); const hi = data[offset] * 16777216 + (data[offset + 1] << 16) + (data[offset + 2] << 8) + data[offset + 3]; const lo = data[offset + 4] * 16777216 + (data[offset + 5] << 16) + (data[offset + 6] << 8) + data[offset + 7]; const value = (BigInt(hi) << BigInt(32)) + BigInt(lo); if (options.strict === true && value < uintBoundaries[3]) { throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`); } if (value <= Number.MAX_SAFE_INTEGER) { return Number(value); } if (options.allowBigInt === true) { return value; } throw new Error(`${decodeErrPrefix} integers outside of the safe integer range are not supported`); } function decodeUint8(data, pos, _minor, options) { return new Token(Type.uint, readUint8(data, pos + 1, options), 2); } function decodeUint16(data, pos, _minor, options) { return new Token(Type.uint, readUint16(data, pos + 1, options), 3); } function decodeUint32(data, pos, _minor, options) { return new Token(Type.uint, readUint32(data, pos + 1, options), 5); } function decodeUint64(data, pos, _minor, options) { return new Token(Type.uint, readUint64(data, pos + 1, options), 9); } function encodeUint(buf3, token) { return encodeUintValue(buf3, 0, token.value); } function encodeUintValue(buf3, major, uint) { if (uint < uintBoundaries[0]) { const nuint = Number(uint); buf3.push([major | nuint]); } else if (uint < uintBoundaries[1]) { const nuint = Number(uint); buf3.push([ major | 24, nuint ]); } else if (uint < uintBoundaries[2]) { const nuint = Number(uint); buf3.push([ major | 25, nuint >>> 8, nuint & 255 ]); } else if (uint < uintBoundaries[3]) { const nuint = Number(uint); buf3.push([ major | 26, nuint >>> 24 & 255, nuint >>> 16 & 255, nuint >>> 8 & 255, nuint & 255 ]); } else { const buint = BigInt(uint); if (buint < uintBoundaries[4]) { const set = [ major | 27, 0, 0, 0, 0, 0, 0, 0 ]; let lo = Number(buint & BigInt(4294967295)); let hi = Number(buint >> BigInt(32) & BigInt(4294967295)); set[8] = lo & 255; lo = lo >> 8; set[7] = lo & 255; lo = lo >> 8; set[6] = lo & 255; lo = lo >> 8; set[5] = lo & 255; set[4] = hi & 255; hi = hi >> 8; set[3] = hi & 255; hi = hi >> 8; set[2] = hi & 255; hi = hi >> 8; set[1] = hi & 255; buf3.push(set); } else { throw new Error(`${decodeErrPrefix} encountered BigInt larger than allowable range`); } } } var uintBoundaries; var init_uint = __esm({ "../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/0uint.js"() { init_token(); init_common(); uintBoundaries = [ 24, 256, 65536, 4294967296, BigInt("18446744073709551616") ]; encodeUint.encodedSize = function encodedSize(token) { return encodeUintValue.encodedSize(token.value); }; encodeUintValue.encodedSize = function encodedSize2(uint) { if (uint < uintBoundaries[0]) { return 1; } if (uint < uintBoundaries[1]) { return 2; } if (uint < uintBoundaries[2]) { return 3; } if (uint < uintBoundaries[3]) { return 5; } return 9; }; encodeUint.compareTokens = function compareTokens(tok1, tok2) { return tok1.value < tok2.value ? -1 : tok1.value > tok2.value ? 1 : 0; }; } }); // ../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/1negint.js function decodeNegint8(data, pos, _minor, options) { return new Token(Type.negint, -1 - readUint8(data, pos + 1, options), 2); } function decodeNegint16(data, pos, _minor, options) { return new Token(Type.negint, -1 - readUint16(data, pos + 1, options), 3); } function decodeNegint32(data, pos, _minor, options) { return new Token(Type.negint, -1 - readUint32(data, pos + 1, options), 5); } function decodeNegint64(data, pos, _minor, options) { const int = readUint64(data, pos + 1, options); if (typeof int !== "bigint") { const value = -1 - int; if (value >= Number.MIN_SAFE_INTEGER) { return new Token(Type.negint, value, 9); } } if (options.allowBigInt !== true) { throw new Error(`${decodeErrPrefix} integers outside of the safe integer range are not supported`); } return new Token(Type.negint, neg1b - BigInt(int), 9); } function encodeNegint(buf3, token) { const negint = token.value; const unsigned = typeof negint === "bigint" ? negint * neg1b - pos1b : negint * -1 - 1; encodeUintValue(buf3, token.type.majorEncoded, unsigned); } var neg1b, pos1b; var init_negint = __esm({ "../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/1negint.js"() { init_token(); init_uint(); init_common(); neg1b = BigInt(-1); pos1b = BigInt(1); encodeNegint.encodedSize = function encodedSize3(token) { const negint = token.value; const unsigned = typeof negint === "bigint" ? negint * neg1b - pos1b : negint * -1 - 1; if (unsigned < uintBoundaries[0]) { return 1; } if (unsigned < uintBoundaries[1]) { return 2; } if (unsigned < uintBoundaries[2]) { return 3; } if (unsigned < uintBoundaries[3]) { return 5; } return 9; }; encodeNegint.compareTokens = function compareTokens2(tok1, tok2) { return tok1.value < tok2.value ? 1 : tok1.value > tok2.value ? -1 : 0; }; } }); // ../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/2bytes.js function toToken(data, pos, prefix, length3) { assertEnoughData(data, pos, prefix + length3); const buf3 = slice(data, pos + prefix, pos + prefix + length3); return new Token(Type.bytes, buf3, prefix + length3); } function decodeBytesCompact(data, pos, minor, _options) { return toToken(data, pos, 1, minor); } function decodeBytes8(data, pos, _minor, options) { return toToken(data, pos, 2, readUint8(data, pos + 1, options)); } function decodeBytes16(data, pos, _minor, options) { return toToken(data, pos, 3, readUint16(data, pos + 1, options)); } function decodeBytes32(data, pos, _minor, options) { return toToken(data, pos, 5, readUint32(data, pos + 1, options)); } function decodeBytes64(data, pos, _minor, options) { const l = readUint64(data, pos + 1, options); if (typeof l === "bigint") { throw new Error(`${decodeErrPrefix} 64-bit integer bytes lengths not supported`); } return toToken(data, pos, 9, l); } function tokenBytes(token) { if (token.encodedBytes === void 0) { token.encodedBytes = token.type === Type.string ? fromString(token.value) : token.value; } return token.encodedBytes; } function encodeBytes(buf3, token) { const bytes = tokenBytes(token); encodeUintValue(buf3, token.type.majorEncoded, bytes.length); buf3.push(bytes); } function compareBytes(b1, b2) { return b1.length < b2.length ? -1 : b1.length > b2.length ? 1 : compare(b1, b2); } var init_bytes = __esm({ "../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/2bytes.js"() { init_token(); init_common(); init_uint(); init_byte_utils(); encodeBytes.encodedSize = function encodedSize4(token) { const bytes = tokenBytes(token); return encodeUintValue.encodedSize(bytes.length) + bytes.length; }; encodeBytes.compareTokens = function compareTokens3(tok1, tok2) { return compareBytes(tokenBytes(tok1), tokenBytes(tok2)); }; } }); // ../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/3string.js function toToken2(data, pos, prefix, length3, options) { const totLength = prefix + length3; assertEnoughData(data, pos, totLength); const tok = new Token(Type.string, toString(data, pos + prefix, pos + totLength), totLength); if (options.retainStringBytes === true) { tok.byteValue = slice(data, pos + prefix, pos + totLength); } return tok; } function decodeStringCompact(data, pos, minor, options) { return toToken2(data, pos, 1, minor, options); } function decodeString8(data, pos, _minor, options) { return toToken2(data, pos, 2, readUint8(data, pos + 1, options), options); } function decodeString16(data, pos, _minor, options) { return toToken2(data, pos, 3, readUint16(data, pos + 1, options), options); } function decodeString32(data, pos, _minor, options) { return toToken2(data, pos, 5, readUint32(data, pos + 1, options), options); } function decodeString64(data, pos, _minor, options) { const l = readUint64(data, pos + 1, options); if (typeof l === "bigint") { throw new Error(`${decodeErrPrefix} 64-bit integer string lengths not supported`); } return toToken2(data, pos, 9, l, options); } var encodeString; var init_string = __esm({ "../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/3string.js"() { init_token(); init_common(); init_uint(); init_bytes(); init_byte_utils(); encodeString = encodeBytes; } }); // ../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/4array.js function toToken3(_data, _pos, prefix, length3) { return new Token(Type.array, length3, prefix); } function decodeArrayCompact(data, pos, minor, _options) { return toToken3(data, pos, 1, minor); } function decodeArray8(data, pos, _minor, options) { return toToken3(data, pos, 2, readUint8(data, pos + 1, options)); } function decodeArray16(data, pos, _minor, options) { return toToken3(data, pos, 3, readUint16(data, pos + 1, options)); } function decodeArray32(data, pos, _minor, options) { return toToken3(data, pos, 5, readUint32(data, pos + 1, options)); } function decodeArray64(data, pos, _minor, options) { const l = readUint64(data, pos + 1, options); if (typeof l === "bigint") { throw new Error(`${decodeErrPrefix} 64-bit integer array lengths not supported`); } return toToken3(data, pos, 9, l); } function decodeArrayIndefinite(data, pos, _minor, options) { if (options.allowIndefinite === false) { throw new Error(`${decodeErrPrefix} indefinite length items not allowed`); } return toToken3(data, pos, 1, Infinity); } function encodeArray(buf3, token) { encodeUintValue(buf3, Type.array.majorEncoded, token.value); } var init_array = __esm({ "../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/4array.js"() { init_token(); init_uint(); init_common(); encodeArray.compareTokens = encodeUint.compareTokens; encodeArray.encodedSize = function encodedSize5(token) { return encodeUintValue.encodedSize(token.value); }; } }); // ../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/5map.js function toToken4(_data, _pos, prefix, length3) { return new Token(Type.map, length3, prefix); } function decodeMapCompact(data, pos, minor, _options) { return toToken4(data, pos, 1, minor); } function decodeMap8(data, pos, _minor, options) { return toToken4(data, pos, 2, readUint8(data, pos + 1, options)); } function decodeMap16(data, pos, _minor, options) { return toToken4(data, pos, 3, readUint16(data, pos + 1, options)); } function decodeMap32(data, pos, _minor, options) { return toToken4(data, pos, 5, readUint32(data, pos + 1, options)); } function decodeMap64(data, pos, _minor, options) { const l = readUint64(data, pos + 1, options); if (typeof l === "bigint") { throw new Error(`${decodeErrPrefix} 64-bit integer map lengths not supported`); } return toToken4(data, pos, 9, l); } function decodeMapIndefinite(data, pos, _minor, options) { if (options.allowIndefinite === false) { throw new Error(`${decodeErrPrefix} indefinite length items not allowed`); } return toToken4(data, pos, 1, Infinity); } function encodeMap(buf3, token) { encodeUintValue(buf3, Type.map.majorEncoded, token.value); } var init_map = __esm({ "../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/5map.js"() { init_token(); init_uint(); init_common(); encodeMap.compareTokens = encodeUint.compareTokens; encodeMap.encodedSize = function encodedSize6(token) { return encodeUintValue.encodedSize(token.value); }; } }); // ../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/6tag.js function decodeTagCompact(_data, _pos, minor, _options) { return new Token(Type.tag, minor, 1); } function decodeTag8(data, pos, _minor, options) { return new Token(Type.tag, readUint8(data, pos + 1, options), 2); } function decodeTag16(data, pos, _minor, options) { return new Token(Type.tag, readUint16(data, pos + 1, options), 3); } function decodeTag32(data, pos, _minor, options) { return new Token(Type.tag, readUint32(data, pos + 1, options), 5); } function decodeTag64(data, pos, _minor, options) { return new Token(Type.tag, readUint64(data, pos + 1, options), 9); } function encodeTag(buf3, token) { encodeUintValue(buf3, Type.tag.majorEncoded, token.value); } var init_tag = __esm({ "../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/6tag.js"() { init_token(); init_uint(); encodeTag.compareTokens = encodeUint.compareTokens; encodeTag.encodedSize = function encodedSize7(token) { return encodeUintValue.encodedSize(token.value); }; } }); // ../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/7float.js function decodeUndefined(_data, _pos, _minor, options) { if (options.allowUndefined === false) { throw new Error(`${decodeErrPrefix} undefined values are not supported`); } else if (options.coerceUndefinedToNull === true) { return new Token(Type.null, null, 1); } return new Token(Type.undefined, void 0, 1); } function decodeBreak(_data, _pos, _minor, options) { if (options.allowIndefinite === false) { throw new Error(`${decodeErrPrefix} indefinite length items not allowed`); } return new Token(Type.break, void 0, 1); } function createToken(value, bytes, options) { if (options) { if (options.allowNaN === false && Number.isNaN(value)) { throw new Error(`${decodeErrPrefix} NaN values are not supported`); } if (options.allowInfinity === false && (value === Infinity || value === -Infinity)) { throw new Error(`${decodeErrPrefix} Infinity values are not supported`); } } return new Token(Type.float, value, bytes); } function decodeFloat16(data, pos, _minor, options) { return createToken(readFloat16(data, pos + 1), 3, options); } function decodeFloat32(data, pos, _minor, options) { return createToken(readFloat32(data, pos + 1), 5, options); } function decodeFloat64(data, pos, _minor, options) { return createToken(readFloat64(data, pos + 1), 9, options); } function encodeFloat(buf3, token, options) { const float = token.value; if (float === false) { buf3.push([Type.float.majorEncoded | MINOR_FALSE]); } else if (float === true) { buf3.push([Type.float.majorEncoded | MINOR_TRUE]); } else if (float === null) { buf3.push([Type.float.majorEncoded | MINOR_NULL]); } else if (float === void 0) { buf3.push([Type.float.majorEncoded | MINOR_UNDEFINED]); } else { let decoded; let success = false; if (!options || options.float64 !== true) { encodeFloat16(float); decoded = readFloat16(ui8a, 1); if (float === decoded || Number.isNaN(float)) { ui8a[0] = 249; buf3.push(ui8a.slice(0, 3)); success = true; } else { encodeFloat32(float); decoded = readFloat32(ui8a, 1); if (float === decoded) { ui8a[0] = 250; buf3.push(ui8a.slice(0, 5)); success = true; } } } if (!success) { encodeFloat64(float); decoded = readFloat64(ui8a, 1); ui8a[0] = 251; buf3.push(ui8a.slice(0, 9)); } } } function encodeFloat16(inp) { if (inp === Infinity) { dataView.setUint16(0, 31744, false); } else if (inp === -Infinity) { dataView.setUint16(0, 64512, false); } else if (Number.isNaN(inp)) { dataView.setUint16(0, 32256, false); } else { dataView.setFloat32(0, inp); const valu32 = dataView.getUint32(0); const exponent = (valu32 & 2139095040) >> 23; const mantissa = valu32 & 8388607; if (exponent === 255) { dataView.setUint16(0, 31744, false); } else if (exponent === 0) { dataView.setUint16(0, (inp & 2147483648) >> 16 | mantissa >> 13, false); } else { const logicalExponent = exponent - 127; if (logicalExponent < -24) { dataView.setUint16(0, 0); } else if (logicalExponent < -14) { dataView.setUint16(0, (valu32 & 2147483648) >> 16 | 1 << 24 + logicalExponent, false); } else { dataView.setUint16(0, (valu32 & 2147483648) >> 16 | logicalExponent + 15 << 10 | mantissa >> 13, false); } } } } function readFloat16(ui8a3, pos) { if (ui8a3.length - pos < 2) { throw new Error(`${decodeErrPrefix} not enough data for float16`); } const half = (ui8a3[pos] << 8) + ui8a3[pos + 1]; if (half === 31744) { return Infinity; } if (half === 64512) { return -Infinity; } if (half === 32256) { return NaN; } const exp = half >> 10 & 31; const mant = half & 1023; let val; if (exp === 0) { val = mant * 2 ** -24; } else if (exp !== 31) { val = (mant + 1024) * 2 ** (exp - 25); } else { val = mant === 0 ? Infinity : NaN; } return half & 32768 ? -val : val; } function encodeFloat32(inp) { dataView.setFloat32(0, inp, false); } function readFloat32(ui8a3, pos) { if (ui8a3.length - pos < 4) { throw new Error(`${decodeErrPrefix} not enough data for float32`); } const offset = (ui8a3.byteOffset || 0) + pos; return new DataView(ui8a3.buffer, offset, 4).getFloat32(0, false); } function encodeFloat64(inp) { dataView.setFloat64(0, inp, false); } function readFloat64(ui8a3, pos) { if (ui8a3.length - pos < 8) { throw new Error(`${decodeErrPrefix} not enough data for float64`); } const offset = (ui8a3.byteOffset || 0) + pos; return new DataView(ui8a3.buffer, offset, 8).getFloat64(0, false); } var MINOR_FALSE, MINOR_TRUE, MINOR_NULL, MINOR_UNDEFINED, buffer, dataView, ui8a; var init_float = __esm({ "../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/7float.js"() { init_token(); init_common(); init_uint(); MINOR_FALSE = 20; MINOR_TRUE = 21; MINOR_NULL = 22; MINOR_UNDEFINED = 23; encodeFloat.encodedSize = function encodedSize8(token, options) { const float = token.value; if (float === false || float === true || float === null || float === void 0) { return 1; } if (!options || options.float64 !== true) { encodeFloat16(float); let decoded = readFloat16(ui8a, 1); if (float === decoded || Number.isNaN(float)) { return 3; } encodeFloat32(float); decoded = readFloat32(ui8a, 1); if (float === decoded) { return 5; } } return 9; }; buffer = new ArrayBuffer(9); dataView = new DataView(buffer, 1); ui8a = new Uint8Array(buffer, 0); encodeFloat.compareTokens = encodeUint.compareTokens; } }); // ../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/jump.js function invalidMinor(data, pos, minor) { throw new Error(`${decodeErrPrefix} encountered invalid minor (${minor}) for major ${data[pos] >>> 5}`); } function errorer(msg) { return () => { throw new Error(`${decodeErrPrefix} ${msg}`); }; } function quickEncodeToken(token) { switch (token.type) { case Type.false: return fromArray([244]); case Type.true: return fromArray([245]); case Type.null: return fromArray([246]); case Type.bytes: if (!token.value.length) { return fromArray([64]); } return; case Type.string: if (token.value === "") { return fromArray([96]); } return; case Type.array: if (token.value === 0) { return fromArray([128]); } return; case Type.map: if (token.value === 0) { return fromArray([160]); } return; case Type.uint: if (token.value < 24) { return fromArray([Number(token.value)]); } return; case Type.negint: if (token.value >= -24) { return fromArray([31 - Number(token.value)]); } } } var jump, quick; var init_jump = __esm({ "../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/jump.js"() { init_token(); init_uint(); init_negint(); init_bytes(); init_string(); init_array(); init_map(); init_tag(); init_float(); init_common(); init_byte_utils(); jump = []; for (let i = 0; i <= 23; i++) { jump[i] = invalidMinor; } jump[24] = decodeUint8; jump[25] = decodeUint16; jump[26] = decodeUint32; jump[27] = decodeUint64; jump[28] = invalidMinor; jump[29] = invalidMinor; jump[30] = invalidMinor; jump[31] = invalidMinor; for (let i = 32; i <= 55; i++) { jump[i] = invalidMinor; } jump[56] = decodeNegint8; jump[57] = decodeNegint16; jump[58] = decodeNegint32; jump[59] = decodeNegint64; jump[60] = invalidMinor; jump[61] = invalidMinor; jump[62] = invalidMinor; jump[63] = invalidMinor; for (let i = 64; i <= 87; i++) { jump[i] = decodeBytesCompact; } jump[88] = decodeBytes8; jump[89] = decodeBytes16; jump[90] = decodeBytes32; jump[91] = decodeBytes64; jump[92] = invalidMinor; jump[93] = invalidMinor; jump[94] = invalidMinor; jump[95] = errorer("indefinite length bytes/strings are not supported"); for (let i = 96; i <= 119; i++) { jump[i] = decodeStringCompact; } jump[120] = decodeString8; jump[121] = decodeString16; jump[122] = decodeString32; jump[123] = decodeString64; jump[124] = invalidMinor; jump[125] = invalidMinor; jump[126] = invalidMinor; jump[127] = errorer("indefinite length bytes/strings are not supported"); for (let i = 128; i <= 151; i++) { jump[i] = decodeArrayCompact; } jump[152] = decodeArray8; jump[153] = decodeArray16; jump[154] = decodeArray32; jump[155] = decodeArray64; jump[156] = invalidMinor; jump[157] = invalidMinor; jump[158] = invalidMinor; jump[159] = decodeArrayIndefinite; for (let i = 160; i <= 183; i++) { jump[i] = decodeMapCompact; } jump[184] = decodeMap8; jump[185] = decodeMap16; jump[186] = decodeMap32; jump[187] = decodeMap64; jump[188] = invalidMinor; jump[189] = invalidMinor; jump[190] = invalidMinor; jump[191] = decodeMapIndefinite; for (let i = 192; i <= 215; i++) { jump[i] = decodeTagCompact; } jump[216] = decodeTag8; jump[217] = decodeTag16; jump[218] = decodeTag32; jump[219] = decodeTag64; jump[220] = invalidMinor; jump[221] = invalidMinor; jump[222] = invalidMinor; jump[223] = invalidMinor; for (let i = 224; i <= 243; i++) { jump[i] = errorer("simple values are not supported"); } jump[244] = invalidMinor; jump[245] = invalidMinor; jump[246] = invalidMinor; jump[247] = decodeUndefined; jump[248] = errorer("simple values are not supported"); jump[249] = decodeFloat16; jump[250] = decodeFloat32; jump[251] = decodeFloat64; jump[252] = invalidMinor; jump[253] = invalidMinor; jump[254] = invalidMinor; jump[255] = decodeBreak; quick = []; for (let i = 0; i < 24; i++) { quick[i] = new Token(Type.uint, i, 1); } for (let i = -1; i >= -24; i--) { quick[31 - i] = new Token(Type.negint, i, 1); } quick[64] = new Token(Type.bytes, new Uint8Array(0), 1); quick[96] = new Token(Type.string, "", 1); quick[128] = new Token(Type.array, 0, 1); quick[160] = new Token(Type.map, 0, 1); quick[244] = new Token(Type.false, false, 1); quick[245] = new Token(Type.true, true, 1); quick[246] = new Token(Type.null, null, 1); } }); // ../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/encode.js function makeCborEncoders() { const encoders = []; encoders[Type.uint.major] = encodeUint; encoders[Type.negint.major] = encodeNegint; encoders[Type.bytes.major] = encodeBytes; encoders[Type.string.major] = encodeString; encoders[Type.array.major] = encodeArray; encoders[Type.map.major] = encodeMap; encoders[Type.tag.major] = encodeTag; encoders[Type.float.major] = encodeFloat; return encoders; } function objectToTokens(obj, options = {}, refStack) { const typ = is(obj); const customTypeEncoder = options && options.typeEncoders && options.typeEncoders[typ] || typeEncoders[typ]; if (typeof customTypeEncoder === "function") { const tokens = customTypeEncoder(obj, typ, options, refStack); if (tokens != null) { return tokens; } } const typeEncoder = typeEncoders[typ]; if (!typeEncoder) { throw new Error(`${encodeErrPrefix} unsupported type: ${typ}`); } return typeEncoder(obj, typ, options, refStack); } function sortMapEntries(entries3, options) { if (options.mapSorter) { entries3.sort(options.mapSorter); } } function mapSorter(e1, e2) { const keyToken1 = Array.isArray(e1[0]) ? e1[0][0] : e1[0]; const keyToken2 = Array.isArray(e2[0]) ? e2[0][0] : e2[0]; if (keyToken1.type !== keyToken2.type) { return keyToken1.type.compare(keyToken2.type); } const major = keyToken1.type.major; const tcmp = cborEncoders[major].compareTokens(keyToken1, keyToken2); if (tcmp === 0) { console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"); } return tcmp; } function tokensToEncoded(buf3, tokens, encoders, options) { if (Array.isArray(tokens)) { for (const token of tokens) { tokensToEncoded(buf3, token, encoders, options); } } else { encoders[tokens.type.major](buf3, tokens, options); } } function encodeCustom(data, encoders, options) { const tokens = objectToTokens(data, options); if (!Array.isArray(tokens) && options.quickEncodeToken) { const quickBytes = options.quickEncodeToken(tokens); if (quickBytes) { return quickBytes; } const encoder = encoders[tokens.type.major]; if (encoder.encodedSize) { const size = encoder.encodedSize(tokens, options); const buf3 = new Bl(size); encoder(buf3, tokens, options); if (buf3.chunks.length !== 1) { throw new Error(`Unexpected error: pre-calculated length for ${tokens} was wrong`); } return asU8A(buf3.chunks[0]); } } buf.reset(); tokensToEncoded(buf, tokens, encoders, options); return buf.toBytes(true); } function encode3(data, options) { options = Object.assign({}, defaultEncodeOptions, options); return encodeCustom(data, cborEncoders, options); } var defaultEncodeOptions, cborEncoders, buf, Ref, simpleTokens, typeEncoders; var init_encode = __esm({ "../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/encode.js"() { init_is(); init_token(); init_bl(); init_common(); init_jump(); init_byte_utils(); init_uint(); init_negint(); init_bytes(); init_string(); init_array(); init_map(); init_tag(); init_float(); defaultEncodeOptions = { float64: false, mapSorter, quickEncodeToken }; cborEncoders = makeCborEncoders(); buf = new Bl(); Ref = class _Ref { constructor(obj, parent) { this.obj = obj; this.parent = parent; } includes(obj) { let p = this; do { if (p.obj === obj) { return true; } } while (p = p.parent); return false; } static createCheck(stack, obj) { if (stack && stack.includes(obj)) { throw new Error(`${encodeErrPrefix} object contains circular references`); } return new _Ref(obj, stack); } }; simpleTokens = { null: new Token(Type.null, null), undefined: new Token(Type.undefined, void 0), true: new Token(Type.true, true), false: new Token(Type.false, false), emptyArray: new Token(Type.array, 0), emptyMap: new Token(Type.map, 0) }; typeEncoders = { number(obj, _typ, _options, _refStack) { if (!Number.isInteger(obj) || !Number.isSafeInteger(obj)) { return new Token(Type.float, obj); } else if (obj >= 0) { return new Token(Type.uint, obj); } else { return new Token(Type.negint, obj); } }, bigint(obj, _typ, _options, _refStack) { if (obj >= BigInt(0)) { return new Token(Type.uint, obj); } else { return new Token(Type.negint, obj); } }, Uint8Array(obj, _typ, _options, _refStack) { return new Token(Type.bytes, obj); }, string(obj, _typ, _options, _refStack) { return new Token(Type.string, obj); }, boolean(obj, _typ, _options, _refStack) { return obj ? simpleTokens.true : simpleTokens.false; }, null(_obj, _typ, _options, _refStack) { return simpleTokens.null; }, undefined(_obj, _typ, _options, _refStack) { return simpleTokens.undefined; }, ArrayBuffer(obj, _typ, _options, _refStack) { return new Token(Type.bytes, new Uint8Array(obj)); }, DataView(obj, _typ, _options, _refStack) { return new Token(Type.bytes, new Uint8Array(obj.buffer, obj.byteOffset, obj.byteLength)); }, Array(obj, _typ, options, refStack) { if (!obj.length) { if (options.addBreakTokens === true) { return [ simpleTokens.emptyArray, new Token(Type.break) ]; } return simpleTokens.emptyArray; } refStack = Ref.createCheck(refStack, obj); const entries3 = []; let i = 0; for (const e of obj) { entries3[i++] = objectToTokens(e, options, refStack); } if (options.addBreakTokens) { return [ new Token(Type.array, obj.length), entries3, new Token(Type.break) ]; } return [ new Token(Type.array, obj.length), entries3 ]; }, Object(obj, typ, options, refStack) { const isMap = typ !== "Object"; const keys = isMap ? obj.keys() : Object.keys(obj); const length3 = isMap ? obj.size : keys.length; if (!length3) { if (options.addBreakTokens === true) { return [ simpleTokens.emptyMap, new Token(Type.break) ]; } return simpleTokens.emptyMap; } refStack = Ref.createCheck(refStack, obj); const entries3 = []; let i = 0; for (const key of keys) { entries3[i++] = [ objectToTokens(key, options, refStack), objectToTokens(isMap ? obj.get(key) : obj[key], options, refStack) ]; } sortMapEntries(entries3, options); if (options.addBreakTokens) { return [ new Token(Type.map, length3), entries3, new Token(Type.break) ]; } return [ new Token(Type.map, length3), entries3 ]; } }; typeEncoders.Map = typeEncoders.Object; typeEncoders.Buffer = typeEncoders.Uint8Array; for (const typ of "Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" ")) { typeEncoders[`${typ}Array`] = typeEncoders.DataView; } } }); // ../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/decode.js function tokenToArray(token, tokeniser, options) { const arr = []; for (let i = 0; i < token.value; i++) { const value = tokensToObject(tokeniser, options); if (value === BREAK) { if (token.value === Infinity) { break; } throw new Error(`${decodeErrPrefix} got unexpected break to lengthed array`); } if (value === DONE) { throw new Error(`${decodeErrPrefix} found array but not enough entries (got ${i}, expected ${token.value})`); } arr[i] = value; } return arr; } function tokenToMap(token, tokeniser, options) { const useMaps = options.useMaps === true; const obj = useMaps ? void 0 : {}; const m = useMaps ? /* @__PURE__ */ new Map() : void 0; for (let i = 0; i < token.value; i++) { const key = tokensToObject(tokeniser, options); if (key === BREAK) { if (token.value === Infinity) { break; } throw new Error(`${decodeErrPrefix} got unexpected break to lengthed map`); } if (key === DONE) { throw new Error(`${decodeErrPrefix} found map but not enough entries (got ${i} [no key], expected ${token.value})`); } if (useMaps !== true && typeof key !== "string") { throw new Error(`${decodeErrPrefix} non-string keys not supported (got ${typeof key})`); } if (options.rejectDuplicateMapKeys === true) { if (useMaps && m.has(key) || !useMaps && key in obj) { throw new Error(`${decodeErrPrefix} found repeat map key "${key}"`); } } const value = tokensToObject(tokeniser, options); if (value === DONE) { throw new Error(`${decodeErrPrefix} found map but not enough entries (got ${i} [no value], expected ${token.value})`); } if (useMaps) {