UNPKG

@codesandbox/sdk

Version:
1,430 lines (1,418 loc) 273 kB
import { createRequire } from 'module'; const require = createRequire(import.meta.url); 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 __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) { if (typeof require !== "undefined") return require.apply(this, arguments); throw Error('Dynamic require of "' + x + '" is not supported'); }); var __commonJS = (cb, mod) => function __require2() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, 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 )); // node_modules/@msgpack/msgpack/dist.cjs/utils/utf8.cjs var require_utf8 = __commonJS({ "node_modules/@msgpack/msgpack/dist.cjs/utils/utf8.cjs"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.utf8Count = utf8Count; exports.utf8EncodeJs = utf8EncodeJs; exports.utf8EncodeTE = utf8EncodeTE; exports.utf8Encode = utf8Encode; exports.utf8DecodeJs = utf8DecodeJs; exports.utf8DecodeTD = utf8DecodeTD; exports.utf8Decode = utf8Decode; function utf8Count(str) { const strLength = str.length; let byteLength = 0; let pos = 0; while (pos < strLength) { let value = str.charCodeAt(pos++); if ((value & 4294967168) === 0) { byteLength++; continue; } else if ((value & 4294965248) === 0) { byteLength += 2; } else { if (value >= 55296 && value <= 56319) { if (pos < strLength) { const extra = str.charCodeAt(pos); if ((extra & 64512) === 56320) { ++pos; value = ((value & 1023) << 10) + (extra & 1023) + 65536; } } } if ((value & 4294901760) === 0) { byteLength += 3; } else { byteLength += 4; } } } return byteLength; } function utf8EncodeJs(str, output, outputOffset) { const strLength = str.length; let offset = outputOffset; let pos = 0; while (pos < strLength) { let value = str.charCodeAt(pos++); if ((value & 4294967168) === 0) { output[offset++] = value; continue; } else if ((value & 4294965248) === 0) { output[offset++] = value >> 6 & 31 | 192; } else { if (value >= 55296 && value <= 56319) { if (pos < strLength) { const extra = str.charCodeAt(pos); if ((extra & 64512) === 56320) { ++pos; value = ((value & 1023) << 10) + (extra & 1023) + 65536; } } } if ((value & 4294901760) === 0) { output[offset++] = value >> 12 & 15 | 224; output[offset++] = value >> 6 & 63 | 128; } else { output[offset++] = value >> 18 & 7 | 240; output[offset++] = value >> 12 & 63 | 128; output[offset++] = value >> 6 & 63 | 128; } } output[offset++] = value & 63 | 128; } } var sharedTextEncoder = new TextEncoder(); var TEXT_ENCODER_THRESHOLD = 50; function utf8EncodeTE(str, output, outputOffset) { sharedTextEncoder.encodeInto(str, output.subarray(outputOffset)); } function utf8Encode(str, output, outputOffset) { if (str.length > TEXT_ENCODER_THRESHOLD) { utf8EncodeTE(str, output, outputOffset); } else { utf8EncodeJs(str, output, outputOffset); } } var CHUNK_SIZE = 4096; function utf8DecodeJs(bytes, inputOffset, byteLength) { let offset = inputOffset; const end = offset + byteLength; const units = []; let result = ""; while (offset < end) { const byte1 = bytes[offset++]; if ((byte1 & 128) === 0) { units.push(byte1); } else if ((byte1 & 224) === 192) { const byte2 = bytes[offset++] & 63; units.push((byte1 & 31) << 6 | byte2); } else if ((byte1 & 240) === 224) { const byte2 = bytes[offset++] & 63; const byte3 = bytes[offset++] & 63; units.push((byte1 & 31) << 12 | byte2 << 6 | byte3); } else if ((byte1 & 248) === 240) { const byte2 = bytes[offset++] & 63; const byte3 = bytes[offset++] & 63; const byte4 = bytes[offset++] & 63; let unit = (byte1 & 7) << 18 | byte2 << 12 | byte3 << 6 | byte4; if (unit > 65535) { unit -= 65536; units.push(unit >>> 10 & 1023 | 55296); unit = 56320 | unit & 1023; } units.push(unit); } else { units.push(byte1); } if (units.length >= CHUNK_SIZE) { result += String.fromCharCode(...units); units.length = 0; } } if (units.length > 0) { result += String.fromCharCode(...units); } return result; } var sharedTextDecoder = new TextDecoder(); var TEXT_DECODER_THRESHOLD = 200; function utf8DecodeTD(bytes, inputOffset, byteLength) { const stringBytes = bytes.subarray(inputOffset, inputOffset + byteLength); return sharedTextDecoder.decode(stringBytes); } function utf8Decode(bytes, inputOffset, byteLength) { if (byteLength > TEXT_DECODER_THRESHOLD) { return utf8DecodeTD(bytes, inputOffset, byteLength); } else { return utf8DecodeJs(bytes, inputOffset, byteLength); } } } }); // node_modules/@msgpack/msgpack/dist.cjs/ExtData.cjs var require_ExtData = __commonJS({ "node_modules/@msgpack/msgpack/dist.cjs/ExtData.cjs"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExtData = void 0; var ExtData = class { constructor(type, data) { this.type = type; this.data = data; } }; exports.ExtData = ExtData; } }); // node_modules/@msgpack/msgpack/dist.cjs/DecodeError.cjs var require_DecodeError = __commonJS({ "node_modules/@msgpack/msgpack/dist.cjs/DecodeError.cjs"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DecodeError = void 0; var DecodeError = class _DecodeError extends Error { constructor(message) { super(message); const proto = Object.create(_DecodeError.prototype); Object.setPrototypeOf(this, proto); Object.defineProperty(this, "name", { configurable: true, enumerable: false, value: _DecodeError.name }); } }; exports.DecodeError = DecodeError; } }); // node_modules/@msgpack/msgpack/dist.cjs/utils/int.cjs var require_int = __commonJS({ "node_modules/@msgpack/msgpack/dist.cjs/utils/int.cjs"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UINT32_MAX = void 0; exports.setUint64 = setUint64; exports.setInt64 = setInt64; exports.getInt64 = getInt64; exports.getUint64 = getUint64; exports.UINT32_MAX = 4294967295; function setUint64(view, offset, value) { const high = value / 4294967296; const low = value; view.setUint32(offset, high); view.setUint32(offset + 4, low); } function setInt64(view, offset, value) { const high = Math.floor(value / 4294967296); const low = value; view.setUint32(offset, high); view.setUint32(offset + 4, low); } function getInt64(view, offset) { const high = view.getInt32(offset); const low = view.getUint32(offset + 4); return high * 4294967296 + low; } function getUint64(view, offset) { const high = view.getUint32(offset); const low = view.getUint32(offset + 4); return high * 4294967296 + low; } } }); // node_modules/@msgpack/msgpack/dist.cjs/timestamp.cjs var require_timestamp = __commonJS({ "node_modules/@msgpack/msgpack/dist.cjs/timestamp.cjs"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.timestampExtension = exports.EXT_TIMESTAMP = void 0; exports.encodeTimeSpecToTimestamp = encodeTimeSpecToTimestamp; exports.encodeDateToTimeSpec = encodeDateToTimeSpec; exports.encodeTimestampExtension = encodeTimestampExtension; exports.decodeTimestampToTimeSpec = decodeTimestampToTimeSpec; exports.decodeTimestampExtension = decodeTimestampExtension; var DecodeError_ts_1 = require_DecodeError(); var int_ts_1 = require_int(); exports.EXT_TIMESTAMP = -1; var TIMESTAMP32_MAX_SEC = 4294967296 - 1; var TIMESTAMP64_MAX_SEC = 17179869184 - 1; function encodeTimeSpecToTimestamp({ sec, nsec }) { if (sec >= 0 && nsec >= 0 && sec <= TIMESTAMP64_MAX_SEC) { if (nsec === 0 && sec <= TIMESTAMP32_MAX_SEC) { const rv = new Uint8Array(4); const view = new DataView(rv.buffer); view.setUint32(0, sec); return rv; } else { const secHigh = sec / 4294967296; const secLow = sec & 4294967295; const rv = new Uint8Array(8); const view = new DataView(rv.buffer); view.setUint32(0, nsec << 2 | secHigh & 3); view.setUint32(4, secLow); return rv; } } else { const rv = new Uint8Array(12); const view = new DataView(rv.buffer); view.setUint32(0, nsec); (0, int_ts_1.setInt64)(view, 4, sec); return rv; } } function encodeDateToTimeSpec(date) { const msec = date.getTime(); const sec = Math.floor(msec / 1e3); const nsec = (msec - sec * 1e3) * 1e6; const nsecInSec = Math.floor(nsec / 1e9); return { sec: sec + nsecInSec, nsec: nsec - nsecInSec * 1e9 }; } function encodeTimestampExtension(object) { if (object instanceof Date) { const timeSpec = encodeDateToTimeSpec(object); return encodeTimeSpecToTimestamp(timeSpec); } else { return null; } } function decodeTimestampToTimeSpec(data) { const view = new DataView(data.buffer, data.byteOffset, data.byteLength); switch (data.byteLength) { case 4: { const sec = view.getUint32(0); const nsec = 0; return { sec, nsec }; } case 8: { const nsec30AndSecHigh2 = view.getUint32(0); const secLow32 = view.getUint32(4); const sec = (nsec30AndSecHigh2 & 3) * 4294967296 + secLow32; const nsec = nsec30AndSecHigh2 >>> 2; return { sec, nsec }; } case 12: { const sec = (0, int_ts_1.getInt64)(view, 4); const nsec = view.getUint32(0); return { sec, nsec }; } default: throw new DecodeError_ts_1.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${data.length}`); } } function decodeTimestampExtension(data) { const timeSpec = decodeTimestampToTimeSpec(data); return new Date(timeSpec.sec * 1e3 + timeSpec.nsec / 1e6); } exports.timestampExtension = { type: exports.EXT_TIMESTAMP, encode: encodeTimestampExtension, decode: decodeTimestampExtension }; } }); // node_modules/@msgpack/msgpack/dist.cjs/ExtensionCodec.cjs var require_ExtensionCodec = __commonJS({ "node_modules/@msgpack/msgpack/dist.cjs/ExtensionCodec.cjs"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExtensionCodec = void 0; var ExtData_ts_1 = require_ExtData(); var timestamp_ts_1 = require_timestamp(); var ExtensionCodec = class { constructor() { this.builtInEncoders = []; this.builtInDecoders = []; this.encoders = []; this.decoders = []; this.register(timestamp_ts_1.timestampExtension); } register({ type, encode, decode }) { if (type >= 0) { this.encoders[type] = encode; this.decoders[type] = decode; } else { const index = -1 - type; this.builtInEncoders[index] = encode; this.builtInDecoders[index] = decode; } } tryToEncode(object, context) { for (let i = 0; i < this.builtInEncoders.length; i++) { const encodeExt = this.builtInEncoders[i]; if (encodeExt != null) { const data = encodeExt(object, context); if (data != null) { const type = -1 - i; return new ExtData_ts_1.ExtData(type, data); } } } for (let i = 0; i < this.encoders.length; i++) { const encodeExt = this.encoders[i]; if (encodeExt != null) { const data = encodeExt(object, context); if (data != null) { const type = i; return new ExtData_ts_1.ExtData(type, data); } } } if (object instanceof ExtData_ts_1.ExtData) { return object; } return null; } decode(data, type, context) { const decodeExt = type < 0 ? this.builtInDecoders[-1 - type] : this.decoders[type]; if (decodeExt) { return decodeExt(data, type, context); } else { return new ExtData_ts_1.ExtData(type, data); } } }; exports.ExtensionCodec = ExtensionCodec; ExtensionCodec.defaultCodec = new ExtensionCodec(); } }); // node_modules/@msgpack/msgpack/dist.cjs/utils/typedArrays.cjs var require_typedArrays = __commonJS({ "node_modules/@msgpack/msgpack/dist.cjs/utils/typedArrays.cjs"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ensureUint8Array = ensureUint8Array; function isArrayBufferLike(buffer) { return buffer instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && buffer instanceof SharedArrayBuffer; } function ensureUint8Array(buffer) { if (buffer instanceof Uint8Array) { return buffer; } else if (ArrayBuffer.isView(buffer)) { return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength); } else if (isArrayBufferLike(buffer)) { return new Uint8Array(buffer); } else { return Uint8Array.from(buffer); } } } }); // node_modules/@msgpack/msgpack/dist.cjs/Encoder.cjs var require_Encoder = __commonJS({ "node_modules/@msgpack/msgpack/dist.cjs/Encoder.cjs"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Encoder = exports.DEFAULT_INITIAL_BUFFER_SIZE = exports.DEFAULT_MAX_DEPTH = void 0; var utf8_ts_1 = require_utf8(); var ExtensionCodec_ts_1 = require_ExtensionCodec(); var int_ts_1 = require_int(); var typedArrays_ts_1 = require_typedArrays(); exports.DEFAULT_MAX_DEPTH = 100; exports.DEFAULT_INITIAL_BUFFER_SIZE = 2048; var Encoder = class _Encoder { constructor(options) { this.entered = false; this.extensionCodec = options?.extensionCodec ?? ExtensionCodec_ts_1.ExtensionCodec.defaultCodec; this.context = options?.context; this.useBigInt64 = options?.useBigInt64 ?? false; this.maxDepth = options?.maxDepth ?? exports.DEFAULT_MAX_DEPTH; this.initialBufferSize = options?.initialBufferSize ?? exports.DEFAULT_INITIAL_BUFFER_SIZE; this.sortKeys = options?.sortKeys ?? false; this.forceFloat32 = options?.forceFloat32 ?? false; this.ignoreUndefined = options?.ignoreUndefined ?? false; this.forceIntegerToFloat = options?.forceIntegerToFloat ?? false; this.pos = 0; this.view = new DataView(new ArrayBuffer(this.initialBufferSize)); this.bytes = new Uint8Array(this.view.buffer); } clone() { return new _Encoder({ extensionCodec: this.extensionCodec, context: this.context, useBigInt64: this.useBigInt64, maxDepth: this.maxDepth, initialBufferSize: this.initialBufferSize, sortKeys: this.sortKeys, forceFloat32: this.forceFloat32, ignoreUndefined: this.ignoreUndefined, forceIntegerToFloat: this.forceIntegerToFloat }); } reinitializeState() { this.pos = 0; } /** * This is almost equivalent to {@link Encoder#encode}, but it returns an reference of the encoder's internal buffer and thus much faster than {@link Encoder#encode}. * * @returns Encodes the object and returns a shared reference the encoder's internal buffer. */ encodeSharedRef(object) { if (this.entered) { const instance = this.clone(); return instance.encodeSharedRef(object); } try { this.entered = true; this.reinitializeState(); this.doEncode(object, 1); return this.bytes.subarray(0, this.pos); } finally { this.entered = false; } } /** * @returns Encodes the object and returns a copy of the encoder's internal buffer. */ encode(object) { if (this.entered) { const instance = this.clone(); return instance.encode(object); } try { this.entered = true; this.reinitializeState(); this.doEncode(object, 1); return this.bytes.slice(0, this.pos); } finally { this.entered = false; } } doEncode(object, depth) { if (depth > this.maxDepth) { throw new Error(`Too deep objects in depth ${depth}`); } if (object == null) { this.encodeNil(); } else if (typeof object === "boolean") { this.encodeBoolean(object); } else if (typeof object === "number") { if (!this.forceIntegerToFloat) { this.encodeNumber(object); } else { this.encodeNumberAsFloat(object); } } else if (typeof object === "string") { this.encodeString(object); } else if (this.useBigInt64 && typeof object === "bigint") { this.encodeBigInt64(object); } else { this.encodeObject(object, depth); } } ensureBufferSizeToWrite(sizeToWrite) { const requiredSize = this.pos + sizeToWrite; if (this.view.byteLength < requiredSize) { this.resizeBuffer(requiredSize * 2); } } resizeBuffer(newSize) { const newBuffer = new ArrayBuffer(newSize); const newBytes = new Uint8Array(newBuffer); const newView = new DataView(newBuffer); newBytes.set(this.bytes); this.view = newView; this.bytes = newBytes; } encodeNil() { this.writeU8(192); } encodeBoolean(object) { if (object === false) { this.writeU8(194); } else { this.writeU8(195); } } encodeNumber(object) { if (!this.forceIntegerToFloat && Number.isSafeInteger(object)) { if (object >= 0) { if (object < 128) { this.writeU8(object); } else if (object < 256) { this.writeU8(204); this.writeU8(object); } else if (object < 65536) { this.writeU8(205); this.writeU16(object); } else if (object < 4294967296) { this.writeU8(206); this.writeU32(object); } else if (!this.useBigInt64) { this.writeU8(207); this.writeU64(object); } else { this.encodeNumberAsFloat(object); } } else { if (object >= -32) { this.writeU8(224 | object + 32); } else if (object >= -128) { this.writeU8(208); this.writeI8(object); } else if (object >= -32768) { this.writeU8(209); this.writeI16(object); } else if (object >= -2147483648) { this.writeU8(210); this.writeI32(object); } else if (!this.useBigInt64) { this.writeU8(211); this.writeI64(object); } else { this.encodeNumberAsFloat(object); } } } else { this.encodeNumberAsFloat(object); } } encodeNumberAsFloat(object) { if (this.forceFloat32) { this.writeU8(202); this.writeF32(object); } else { this.writeU8(203); this.writeF64(object); } } encodeBigInt64(object) { if (object >= BigInt(0)) { this.writeU8(207); this.writeBigUint64(object); } else { this.writeU8(211); this.writeBigInt64(object); } } writeStringHeader(byteLength) { if (byteLength < 32) { this.writeU8(160 + byteLength); } else if (byteLength < 256) { this.writeU8(217); this.writeU8(byteLength); } else if (byteLength < 65536) { this.writeU8(218); this.writeU16(byteLength); } else if (byteLength < 4294967296) { this.writeU8(219); this.writeU32(byteLength); } else { throw new Error(`Too long string: ${byteLength} bytes in UTF-8`); } } encodeString(object) { const maxHeaderSize = 1 + 4; const byteLength = (0, utf8_ts_1.utf8Count)(object); this.ensureBufferSizeToWrite(maxHeaderSize + byteLength); this.writeStringHeader(byteLength); (0, utf8_ts_1.utf8Encode)(object, this.bytes, this.pos); this.pos += byteLength; } encodeObject(object, depth) { const ext = this.extensionCodec.tryToEncode(object, this.context); if (ext != null) { this.encodeExtension(ext); } else if (Array.isArray(object)) { this.encodeArray(object, depth); } else if (ArrayBuffer.isView(object)) { this.encodeBinary(object); } else if (typeof object === "object") { this.encodeMap(object, depth); } else { throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(object)}`); } } encodeBinary(object) { const size = object.byteLength; if (size < 256) { this.writeU8(196); this.writeU8(size); } else if (size < 65536) { this.writeU8(197); this.writeU16(size); } else if (size < 4294967296) { this.writeU8(198); this.writeU32(size); } else { throw new Error(`Too large binary: ${size}`); } const bytes = (0, typedArrays_ts_1.ensureUint8Array)(object); this.writeU8a(bytes); } encodeArray(object, depth) { const size = object.length; if (size < 16) { this.writeU8(144 + size); } else if (size < 65536) { this.writeU8(220); this.writeU16(size); } else if (size < 4294967296) { this.writeU8(221); this.writeU32(size); } else { throw new Error(`Too large array: ${size}`); } for (const item of object) { this.doEncode(item, depth + 1); } } countWithoutUndefined(object, keys) { let count = 0; for (const key of keys) { if (object[key] !== void 0) { count++; } } return count; } encodeMap(object, depth) { const keys = Object.keys(object); if (this.sortKeys) { keys.sort(); } const size = this.ignoreUndefined ? this.countWithoutUndefined(object, keys) : keys.length; if (size < 16) { this.writeU8(128 + size); } else if (size < 65536) { this.writeU8(222); this.writeU16(size); } else if (size < 4294967296) { this.writeU8(223); this.writeU32(size); } else { throw new Error(`Too large map object: ${size}`); } for (const key of keys) { const value = object[key]; if (!(this.ignoreUndefined && value === void 0)) { this.encodeString(key); this.doEncode(value, depth + 1); } } } encodeExtension(ext) { if (typeof ext.data === "function") { const data = ext.data(this.pos + 6); const size2 = data.length; if (size2 >= 4294967296) { throw new Error(`Too large extension object: ${size2}`); } this.writeU8(201); this.writeU32(size2); this.writeI8(ext.type); this.writeU8a(data); return; } const size = ext.data.length; if (size === 1) { this.writeU8(212); } else if (size === 2) { this.writeU8(213); } else if (size === 4) { this.writeU8(214); } else if (size === 8) { this.writeU8(215); } else if (size === 16) { this.writeU8(216); } else if (size < 256) { this.writeU8(199); this.writeU8(size); } else if (size < 65536) { this.writeU8(200); this.writeU16(size); } else if (size < 4294967296) { this.writeU8(201); this.writeU32(size); } else { throw new Error(`Too large extension object: ${size}`); } this.writeI8(ext.type); this.writeU8a(ext.data); } writeU8(value) { this.ensureBufferSizeToWrite(1); this.view.setUint8(this.pos, value); this.pos++; } writeU8a(values) { const size = values.length; this.ensureBufferSizeToWrite(size); this.bytes.set(values, this.pos); this.pos += size; } writeI8(value) { this.ensureBufferSizeToWrite(1); this.view.setInt8(this.pos, value); this.pos++; } writeU16(value) { this.ensureBufferSizeToWrite(2); this.view.setUint16(this.pos, value); this.pos += 2; } writeI16(value) { this.ensureBufferSizeToWrite(2); this.view.setInt16(this.pos, value); this.pos += 2; } writeU32(value) { this.ensureBufferSizeToWrite(4); this.view.setUint32(this.pos, value); this.pos += 4; } writeI32(value) { this.ensureBufferSizeToWrite(4); this.view.setInt32(this.pos, value); this.pos += 4; } writeF32(value) { this.ensureBufferSizeToWrite(4); this.view.setFloat32(this.pos, value); this.pos += 4; } writeF64(value) { this.ensureBufferSizeToWrite(8); this.view.setFloat64(this.pos, value); this.pos += 8; } writeU64(value) { this.ensureBufferSizeToWrite(8); (0, int_ts_1.setUint64)(this.view, this.pos, value); this.pos += 8; } writeI64(value) { this.ensureBufferSizeToWrite(8); (0, int_ts_1.setInt64)(this.view, this.pos, value); this.pos += 8; } writeBigUint64(value) { this.ensureBufferSizeToWrite(8); this.view.setBigUint64(this.pos, value); this.pos += 8; } writeBigInt64(value) { this.ensureBufferSizeToWrite(8); this.view.setBigInt64(this.pos, value); this.pos += 8; } }; exports.Encoder = Encoder; } }); // node_modules/@msgpack/msgpack/dist.cjs/encode.cjs var require_encode = __commonJS({ "node_modules/@msgpack/msgpack/dist.cjs/encode.cjs"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.encode = encode; var Encoder_ts_1 = require_Encoder(); function encode(value, options) { const encoder = new Encoder_ts_1.Encoder(options); return encoder.encodeSharedRef(value); } } }); // node_modules/@msgpack/msgpack/dist.cjs/utils/prettyByte.cjs var require_prettyByte = __commonJS({ "node_modules/@msgpack/msgpack/dist.cjs/utils/prettyByte.cjs"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.prettyByte = prettyByte; function prettyByte(byte) { return `${byte < 0 ? "-" : ""}0x${Math.abs(byte).toString(16).padStart(2, "0")}`; } } }); // node_modules/@msgpack/msgpack/dist.cjs/CachedKeyDecoder.cjs var require_CachedKeyDecoder = __commonJS({ "node_modules/@msgpack/msgpack/dist.cjs/CachedKeyDecoder.cjs"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CachedKeyDecoder = void 0; var utf8_ts_1 = require_utf8(); var DEFAULT_MAX_KEY_LENGTH = 16; var DEFAULT_MAX_LENGTH_PER_KEY = 16; var CachedKeyDecoder = class { constructor(maxKeyLength = DEFAULT_MAX_KEY_LENGTH, maxLengthPerKey = DEFAULT_MAX_LENGTH_PER_KEY) { this.hit = 0; this.miss = 0; this.maxKeyLength = maxKeyLength; this.maxLengthPerKey = maxLengthPerKey; this.caches = []; for (let i = 0; i < this.maxKeyLength; i++) { this.caches.push([]); } } canBeCached(byteLength) { return byteLength > 0 && byteLength <= this.maxKeyLength; } find(bytes, inputOffset, byteLength) { const records = this.caches[byteLength - 1]; FIND_CHUNK: for (const record of records) { const recordBytes = record.bytes; for (let j = 0; j < byteLength; j++) { if (recordBytes[j] !== bytes[inputOffset + j]) { continue FIND_CHUNK; } } return record.str; } return null; } store(bytes, value) { const records = this.caches[bytes.length - 1]; const record = { bytes, str: value }; if (records.length >= this.maxLengthPerKey) { records[Math.random() * records.length | 0] = record; } else { records.push(record); } } decode(bytes, inputOffset, byteLength) { const cachedValue = this.find(bytes, inputOffset, byteLength); if (cachedValue != null) { this.hit++; return cachedValue; } this.miss++; const str = (0, utf8_ts_1.utf8DecodeJs)(bytes, inputOffset, byteLength); const slicedCopyOfBytes = Uint8Array.prototype.slice.call(bytes, inputOffset, inputOffset + byteLength); this.store(slicedCopyOfBytes, str); return str; } }; exports.CachedKeyDecoder = CachedKeyDecoder; } }); // node_modules/@msgpack/msgpack/dist.cjs/Decoder.cjs var require_Decoder = __commonJS({ "node_modules/@msgpack/msgpack/dist.cjs/Decoder.cjs"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Decoder = void 0; var prettyByte_ts_1 = require_prettyByte(); var ExtensionCodec_ts_1 = require_ExtensionCodec(); var int_ts_1 = require_int(); var utf8_ts_1 = require_utf8(); var typedArrays_ts_1 = require_typedArrays(); var CachedKeyDecoder_ts_1 = require_CachedKeyDecoder(); var DecodeError_ts_1 = require_DecodeError(); var STATE_ARRAY = "array"; var STATE_MAP_KEY = "map_key"; var STATE_MAP_VALUE = "map_value"; var mapKeyConverter = (key) => { if (typeof key === "string" || typeof key === "number") { return key; } throw new DecodeError_ts_1.DecodeError("The type of key must be string or number but " + typeof key); }; var StackPool = class { constructor() { this.stack = []; this.stackHeadPosition = -1; } get length() { return this.stackHeadPosition + 1; } top() { return this.stack[this.stackHeadPosition]; } pushArrayState(size) { const state = this.getUninitializedStateFromPool(); state.type = STATE_ARRAY; state.position = 0; state.size = size; state.array = new Array(size); } pushMapState(size) { const state = this.getUninitializedStateFromPool(); state.type = STATE_MAP_KEY; state.readCount = 0; state.size = size; state.map = {}; } getUninitializedStateFromPool() { this.stackHeadPosition++; if (this.stackHeadPosition === this.stack.length) { const partialState = { type: void 0, size: 0, array: void 0, position: 0, readCount: 0, map: void 0, key: null }; this.stack.push(partialState); } return this.stack[this.stackHeadPosition]; } release(state) { const topStackState = this.stack[this.stackHeadPosition]; if (topStackState !== state) { throw new Error("Invalid stack state. Released state is not on top of the stack."); } if (state.type === STATE_ARRAY) { const partialState = state; partialState.size = 0; partialState.array = void 0; partialState.position = 0; partialState.type = void 0; } if (state.type === STATE_MAP_KEY || state.type === STATE_MAP_VALUE) { const partialState = state; partialState.size = 0; partialState.map = void 0; partialState.readCount = 0; partialState.type = void 0; } this.stackHeadPosition--; } reset() { this.stack.length = 0; this.stackHeadPosition = -1; } }; var HEAD_BYTE_REQUIRED = -1; var EMPTY_VIEW = new DataView(new ArrayBuffer(0)); var EMPTY_BYTES = new Uint8Array(EMPTY_VIEW.buffer); try { EMPTY_VIEW.getInt8(0); } catch (e) { if (!(e instanceof RangeError)) { throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access"); } } var MORE_DATA = new RangeError("Insufficient data"); var sharedCachedKeyDecoder = new CachedKeyDecoder_ts_1.CachedKeyDecoder(); var Decoder = class _Decoder { constructor(options) { this.totalPos = 0; this.pos = 0; this.view = EMPTY_VIEW; this.bytes = EMPTY_BYTES; this.headByte = HEAD_BYTE_REQUIRED; this.stack = new StackPool(); this.entered = false; this.extensionCodec = options?.extensionCodec ?? ExtensionCodec_ts_1.ExtensionCodec.defaultCodec; this.context = options?.context; this.useBigInt64 = options?.useBigInt64 ?? false; this.rawStrings = options?.rawStrings ?? false; this.maxStrLength = options?.maxStrLength ?? int_ts_1.UINT32_MAX; this.maxBinLength = options?.maxBinLength ?? int_ts_1.UINT32_MAX; this.maxArrayLength = options?.maxArrayLength ?? int_ts_1.UINT32_MAX; this.maxMapLength = options?.maxMapLength ?? int_ts_1.UINT32_MAX; this.maxExtLength = options?.maxExtLength ?? int_ts_1.UINT32_MAX; this.keyDecoder = options?.keyDecoder !== void 0 ? options.keyDecoder : sharedCachedKeyDecoder; this.mapKeyConverter = options?.mapKeyConverter ?? mapKeyConverter; } clone() { return new _Decoder({ extensionCodec: this.extensionCodec, context: this.context, useBigInt64: this.useBigInt64, rawStrings: this.rawStrings, maxStrLength: this.maxStrLength, maxBinLength: this.maxBinLength, maxArrayLength: this.maxArrayLength, maxMapLength: this.maxMapLength, maxExtLength: this.maxExtLength, keyDecoder: this.keyDecoder }); } reinitializeState() { this.totalPos = 0; this.headByte = HEAD_BYTE_REQUIRED; this.stack.reset(); } setBuffer(buffer) { const bytes = (0, typedArrays_ts_1.ensureUint8Array)(buffer); this.bytes = bytes; this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength); this.pos = 0; } appendBuffer(buffer) { if (this.headByte === HEAD_BYTE_REQUIRED && !this.hasRemaining(1)) { this.setBuffer(buffer); } else { const remainingData = this.bytes.subarray(this.pos); const newData = (0, typedArrays_ts_1.ensureUint8Array)(buffer); const newBuffer = new Uint8Array(remainingData.length + newData.length); newBuffer.set(remainingData); newBuffer.set(newData, remainingData.length); this.setBuffer(newBuffer); } } hasRemaining(size) { return this.view.byteLength - this.pos >= size; } createExtraByteError(posToShow) { const { view, pos } = this; return new RangeError(`Extra ${view.byteLength - pos} of ${view.byteLength} byte(s) found at buffer[${posToShow}]`); } /** * @throws {@link DecodeError} * @throws {@link RangeError} */ decode(buffer) { if (this.entered) { const instance = this.clone(); return instance.decode(buffer); } try { this.entered = true; this.reinitializeState(); this.setBuffer(buffer); const object = this.doDecodeSync(); if (this.hasRemaining(1)) { throw this.createExtraByteError(this.pos); } return object; } finally { this.entered = false; } } *decodeMulti(buffer) { if (this.entered) { const instance = this.clone(); yield* instance.decodeMulti(buffer); return; } try { this.entered = true; this.reinitializeState(); this.setBuffer(buffer); while (this.hasRemaining(1)) { yield this.doDecodeSync(); } } finally { this.entered = false; } } async decodeAsync(stream) { if (this.entered) { const instance = this.clone(); return instance.decodeAsync(stream); } try { this.entered = true; let decoded = false; let object; for await (const buffer of stream) { if (decoded) { this.entered = false; throw this.createExtraByteError(this.totalPos); } this.appendBuffer(buffer); try { object = this.doDecodeSync(); decoded = true; } catch (e) { if (!(e instanceof RangeError)) { throw e; } } this.totalPos += this.pos; } if (decoded) { if (this.hasRemaining(1)) { throw this.createExtraByteError(this.totalPos); } return object; } const { headByte, pos, totalPos } = this; throw new RangeError(`Insufficient data in parsing ${(0, prettyByte_ts_1.prettyByte)(headByte)} at ${totalPos} (${pos} in the current buffer)`); } finally { this.entered = false; } } decodeArrayStream(stream) { return this.decodeMultiAsync(stream, true); } decodeStream(stream) { return this.decodeMultiAsync(stream, false); } async *decodeMultiAsync(stream, isArray) { if (this.entered) { const instance = this.clone(); yield* instance.decodeMultiAsync(stream, isArray); return; } try { this.entered = true; let isArrayHeaderRequired = isArray; let arrayItemsLeft = -1; for await (const buffer of stream) { if (isArray && arrayItemsLeft === 0) { throw this.createExtraByteError(this.totalPos); } this.appendBuffer(buffer); if (isArrayHeaderRequired) { arrayItemsLeft = this.readArraySize(); isArrayHeaderRequired = false; this.complete(); } try { while (true) { yield this.doDecodeSync(); if (--arrayItemsLeft === 0) { break; } } } catch (e) { if (!(e instanceof RangeError)) { throw e; } } this.totalPos += this.pos; } } finally { this.entered = false; } } doDecodeSync() { DECODE: while (true) { const headByte = this.readHeadByte(); let object; if (headByte >= 224) { object = headByte - 256; } else if (headByte < 192) { if (headByte < 128) { object = headByte; } else if (headByte < 144) { const size = headByte - 128; if (size !== 0) { this.pushMapState(size); this.complete(); continue DECODE; } else { object = {}; } } else if (headByte < 160) { const size = headByte - 144; if (size !== 0) { this.pushArrayState(size); this.complete(); continue DECODE; } else { object = []; } } else { const byteLength = headByte - 160; object = this.decodeString(byteLength, 0); } } else if (headByte === 192) { object = null; } else if (headByte === 194) { object = false; } else if (headByte === 195) { object = true; } else if (headByte === 202) { object = this.readF32(); } else if (headByte === 203) { object = this.readF64(); } else if (headByte === 204) { object = this.readU8(); } else if (headByte === 205) { object = this.readU16(); } else if (headByte === 206) { object = this.readU32(); } else if (headByte === 207) { if (this.useBigInt64) { object = this.readU64AsBigInt(); } else { object = this.readU64(); } } else if (headByte === 208) { object = this.readI8(); } else if (headByte === 209) { object = this.readI16(); } else if (headByte === 210) { object = this.readI32(); } else if (headByte === 211) { if (this.useBigInt64) { object = this.readI64AsBigInt(); } else { object = this.readI64(); } } else if (headByte === 217) { const byteLength = this.lookU8(); object = this.decodeString(byteLength, 1); } else if (headByte === 218) { const byteLength = this.lookU16(); object = this.decodeString(byteLength, 2); } else if (headByte === 219) { const byteLength = this.lookU32(); object = this.decodeString(byteLength, 4); } else if (headByte === 220) { const size = this.readU16(); if (size !== 0) { this.pushArrayState(size); this.complete(); continue DECODE; } else { object = []; } } else if (headByte === 221) { const size = this.readU32(); if (size !== 0) { this.pushArrayState(size); this.complete(); continue DECODE; } else { object = []; } } else if (headByte === 222) { const size = this.readU16(); if (size !== 0) { this.pushMapState(size); this.complete(); continue DECODE; } else { object = {}; } } else if (headByte === 223) { const size = this.readU32(); if (size !== 0) { this.pushMapState(size); this.complete(); continue DECODE; } else { object = {}; } } else if (headByte === 196) { const size = this.lookU8(); object = this.decodeBinary(size, 1); } else if (headByte === 197) { const size = this.lookU16(); object = this.decodeBinary(size, 2); } else if (headByte === 198) { const size = this.lookU32(); object = this.decodeBinary(size, 4); } else if (headByte === 212) { object = this.decodeExtension(1, 0); } else if (headByte === 213) { object = this.decodeExtension(2, 0); } else if (headByte === 214) { object = this.decodeExtension(4, 0); } else if (headByte === 215) { object = this.decodeExtension(8, 0); } else if (headByte === 216) { object = this.decodeExtension(16, 0); } else if (headByte === 199) { const size = this.lookU8(); object = this.decodeExtension(size, 1); } else if (headByte === 200) { const size = this.lookU16(); object = this.decodeExtension(size, 2); } else if (headByte === 201) { const size = this.lookU32(); object = this.decodeExtension(size, 4); } else { throw new DecodeError_ts_1.DecodeError(`Unrecognized type byte: ${(0, prettyByte_ts_1.prettyByte)(headByte)}`); } this.complete(); const stack = this.stack; while (stack.length > 0) { const state = stack.top(); if (state.type === STATE_ARRAY) { state.array[state.position] = object; state.position++; if (state.position === state.size) { object = state.array; stack.release(state); } else { continue DECODE; } } else if (state.type === STATE_MAP_KEY) { if (object === "__proto__") { throw new DecodeError_ts_1.DecodeError("The key __proto__ is not allowed"); } state.key = this.mapKeyConverter(object); state.type = STATE_MAP_VALUE; continue DECODE; } else { state.map[state.key] = object; state.readCount++; if (state.readCount === state.size) { object = state.map; stack.release(state); } else { state.key = null; state.type = STATE_MAP_KEY; continue DECODE; } } } return object; } } readHeadByte() { if (this.headByte === HEAD_BYTE_REQUIRED) { this.headByte = this.readU8(); } return this.headByte; } complete() { this.headByte = HEAD_BYTE_REQUIRED; } readArraySize() { const headByte = this.readHeadByte(); switch (headByte) { case 220: return this.readU16(); case 221: return this.readU32(); default: { if (headByte < 160) { return headByte - 144; } else { throw new DecodeError_ts_1.DecodeError(`Unrecognized array type byte: ${(0, prettyByte_ts_1.prettyByte)(headByte)}`); } } } } pushMapState(size) { if (size > this.maxMapLength) { throw new DecodeError_ts_1.DecodeError(`Max length exceeded: map length (${size}) > maxMapLengthLength (${this.maxMapLength})`); } this.stack.pushMapState(size); } pushArrayState(size) { if (size > this.maxArrayLength) { throw new DecodeError_ts_1.DecodeError(`Max length exceeded: array length (${size}) > maxArrayLength (${this.maxArrayLength})`); } this.stack.pushArrayState(size); } decodeString(byteLength, headerOffset) { if (!this.rawStrings || this.stateIsMapKey()) { return this.decodeUtf8String(byteLength, headerOffset); } return this.decodeBinary(byteL