diff --git a/packages/cli/src/lib/defaults/build-strategies/wasm/javascript/image/Dockerfile.mustache b/packages/cli/src/lib/defaults/build-strategies/wasm/javascript/image/Dockerfile.mustache index 72ad58752..532789563 100644 --- a/packages/cli/src/lib/defaults/build-strategies/wasm/javascript/image/Dockerfile.mustache +++ b/packages/cli/src/lib/defaults/build-strategies/wasm/javascript/image/Dockerfile.mustache @@ -4,11 +4,11 @@ RUN apt-get update && apt-get install -y curl git # Download and install pwrup RUN curl -L https://raw.githubusercontent.com/polywrap/pwr/main/pwrup/install | bash -# Source bash and use pwrup to install pwr -RUN /bin/bash -i -c "source ~/.bashrc; pwrup" +# Use pwrup to install pwr +RUN /root/.pwr/bin/pwrup WORKDIR /project # Copy the script file to build COPY {{#polywrap_module}}{{moduleFilePath}}{{/polywrap_module}} ./wrap.js # Use pwr to build the script -RUN /bin/bash -i -c "pwr js build -f ./wrap.js -o build" \ No newline at end of file +RUN /root/.pwr/bin/pwr js build -f ./wrap.js \ No newline at end of file diff --git a/packages/cli/src/lib/defaults/build-strategies/wasm/javascript/vm/VERSION b/packages/cli/src/lib/defaults/build-strategies/wasm/javascript/vm/VERSION index 6c6aa7cb0..6da28dde7 100644 --- a/packages/cli/src/lib/defaults/build-strategies/wasm/javascript/vm/VERSION +++ b/packages/cli/src/lib/defaults/build-strategies/wasm/javascript/vm/VERSION @@ -1 +1 @@ -0.1.0 \ No newline at end of file +0.1.1 \ No newline at end of file diff --git a/packages/templates/wasm/typescript/polywrap.build.yaml b/packages/templates/wasm/typescript/polywrap.build.yaml deleted file mode 100644 index 4bdc6dc16..000000000 --- a/packages/templates/wasm/typescript/polywrap.build.yaml +++ /dev/null @@ -1,3 +0,0 @@ -format: 0.3.0 -config: - scriptFile: ./bundled/wrap.js \ No newline at end of file diff --git a/packages/templates/wasm/typescript/rollup.config.mjs b/packages/templates/wasm/typescript/rollup.config.mjs index f89156e9a..864500ccb 100644 --- a/packages/templates/wasm/typescript/rollup.config.mjs +++ b/packages/templates/wasm/typescript/rollup.config.mjs @@ -2,7 +2,7 @@ import typescript from "@rollup/plugin-typescript"; import resolve from "@rollup/plugin-node-resolve"; import commonjs from "@rollup/plugin-commonjs"; import terser from "@rollup/plugin-terser"; -import shims from "./shims.js"; +import shims from "./shims/shims.js"; export default { input: "src/wrap/entry.ts", diff --git a/packages/templates/wasm/typescript/shims/msgpack.js b/packages/templates/wasm/typescript/shims/msgpack.js new file mode 100644 index 000000000..2b3513f16 --- /dev/null +++ b/packages/templates/wasm/typescript/shims/msgpack.js @@ -0,0 +1,2356 @@ +module.exports = `function utf8Count(str) { + var strLength = str.length; + var byteLength = 0; + var pos = 0; + while (pos < strLength) { + var value = str.charCodeAt(pos++); + if ((value & 0xffffff80) === 0) { + // 1-byte + byteLength++; + continue; + } else if ((value & 0xfffff800) === 0) { + // 2-bytes + byteLength += 2; + } else { + // handle surrogate pair + if (value >= 0xd800 && value <= 0xdbff) { + // high surrogate + if (pos < strLength) { + var extra = str.charCodeAt(pos); + if ((extra & 0xfc00) === 0xdc00) { + ++pos; + value = ((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000; + } + } + } + if ((value & 0xffff0000) === 0) { + // 3-byte + byteLength += 3; + } else { + // 4-byte + byteLength += 4; + } + } + } + return byteLength; +} +function utf8EncodeJs(str, output, outputOffset) { + var strLength = str.length; + var offset = outputOffset; + var pos = 0; + while (pos < strLength) { + var value = str.charCodeAt(pos++); + if ((value & 0xffffff80) === 0) { + // 1-byte + output[offset++] = value; + continue; + } else if ((value & 0xfffff800) === 0) { + // 2-bytes + output[offset++] = ((value >> 6) & 0x1f) | 0xc0; + } else { + // handle surrogate pair + if (value >= 0xd800 && value <= 0xdbff) { + // high surrogate + if (pos < strLength) { + var extra = str.charCodeAt(pos); + if ((extra & 0xfc00) === 0xdc00) { + ++pos; + value = ((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000; + } + } + } + if ((value & 0xffff0000) === 0) { + // 3-byte + output[offset++] = ((value >> 12) & 0x0f) | 0xe0; + output[offset++] = ((value >> 6) & 0x3f) | 0x80; + } else { + // 4-byte + output[offset++] = ((value >> 18) & 0x07) | 0xf0; + output[offset++] = ((value >> 12) & 0x3f) | 0x80; + output[offset++] = ((value >> 6) & 0x3f) | 0x80; + } + } + output[offset++] = (value & 0x3f) | 0x80; + } +} +// TextEncoder and TextDecoder are standardized in whatwg encoding: +// https://encoding.spec.whatwg.org/ +// and available in all the modern browsers: +// https://caniuse.com/textencoder +// They are available in Node.js since v12 LTS as well: +// https://nodejs.org/api/globals.html#textencoder +var sharedTextEncoder = new TextEncoder(); +// This threshold should be determined by benchmarking, which might vary in engines and input data. +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) { + var offset = inputOffset; + var end = offset + byteLength; + var units = []; + var result = ""; + while (offset < end) { + var byte1 = bytes[offset++]; + if ((byte1 & 0x80) === 0) { + // 1 byte + units.push(byte1); + } else if ((byte1 & 0xe0) === 0xc0) { + // 2 bytes + var byte2 = bytes[offset++] & 0x3f; + units.push(((byte1 & 0x1f) << 6) | byte2); + } else if ((byte1 & 0xf0) === 0xe0) { + // 3 bytes + var byte2 = bytes[offset++] & 0x3f; + var byte3 = bytes[offset++] & 0x3f; + units.push(((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3); + } else if ((byte1 & 0xf8) === 0xf0) { + // 4 bytes + var byte2 = bytes[offset++] & 0x3f; + var byte3 = bytes[offset++] & 0x3f; + var byte4 = bytes[offset++] & 0x3f; + var unit = + ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4; + if (unit > 0xffff) { + unit -= 0x10000; + units.push(((unit >>> 10) & 0x3ff) | 0xd800); + unit = 0xdc00 | (unit & 0x3ff); + } + units.push(unit); + } else { + units.push(byte1); + } + if (units.length >= CHUNK_SIZE) { + result += String.fromCharCode.apply(String, units); + units.length = 0; + } + } + if (units.length > 0) { + result += String.fromCharCode.apply(String, units); + } + return result; +} +var sharedTextDecoder = new TextDecoder(); +// This threshold should be determined by benchmarking, which might vary in engines and input data. + +var TEXT_DECODER_THRESHOLD = 200; +function utf8DecodeTD(bytes, inputOffset, byteLength) { + var 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); + } +} + +/** + * ExtData is used to handle Extension Types that are not registered to ExtensionCodec. + */ +var ExtData = /** @class */ (function () { + function ExtData(type, data) { + this.type = type; + this.data = data; + } + return ExtData; +})(); + +var __extends = + (undefined && undefined.__extends) || + (function () { + var extendStatics = function (d, b) { + extendStatics = + Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && + function (d, b) { + d.__proto__ = b; + }) || + function (d, b) { + for (var p in b) + if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; + }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError( + "Class extends value " + String(b) + " is not a constructor or null" + ); + extendStatics(d, b); + function __() { + this.constructor = d; + } + d.prototype = + b === null + ? Object.create(b) + : ((__.prototype = b.prototype), new __()); + }; + })(); +var DecodeError = /** @class */ (function (_super) { + __extends(DecodeError, _super); + function DecodeError(message) { + var _this = _super.call(this, message) || this; + // fix the prototype chain in a cross-platform way + var proto = Object.create(DecodeError.prototype); + Object.setPrototypeOf(_this, proto); + Object.defineProperty(_this, "name", { + configurable: true, + enumerable: false, + value: DecodeError.name, + }); + return _this; + } + return DecodeError; +})(Error); + +// Integer Utility +var UINT32_MAX = 4294967295; +// DataView extension to handle int64 / uint64, +// where the actual range is 53-bits integer (a.k.a. safe integer) +function setUint64(view, offset, value) { + var high = value / 4294967296; + var low = value; // high bits are truncated by DataView + view.setUint32(offset, high); + view.setUint32(offset + 4, low); +} +function setInt64(view, offset, value) { + var high = Math.floor(value / 4294967296); + var low = value; // high bits are truncated by DataView + view.setUint32(offset, high); + view.setUint32(offset + 4, low); +} +function getInt64(view, offset) { + var high = view.getInt32(offset); + var low = view.getUint32(offset + 4); + return high * 4294967296 + low; +} +function getUint64(view, offset) { + var high = view.getUint32(offset); + var low = view.getUint32(offset + 4); + return high * 4294967296 + low; +} + +// https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type +var EXT_TIMESTAMP = -1; +var TIMESTAMP32_MAX_SEC = 0x100000000 - 1; // 32-bit unsigned int +var TIMESTAMP64_MAX_SEC = 0x400000000 - 1; // 34-bit unsigned int +function encodeTimeSpecToTimestamp(_a) { + var sec = _a.sec, + nsec = _a.nsec; + if (sec >= 0 && nsec >= 0 && sec <= TIMESTAMP64_MAX_SEC) { + // Here sec >= 0 && nsec >= 0 + if (nsec === 0 && sec <= TIMESTAMP32_MAX_SEC) { + // timestamp 32 = { sec32 (unsigned) } + var rv = new Uint8Array(4); + var view = new DataView(rv.buffer); + view.setUint32(0, sec); + return rv; + } else { + // timestamp 64 = { nsec30 (unsigned), sec34 (unsigned) } + var secHigh = sec / 0x100000000; + var secLow = sec & 0xffffffff; + var rv = new Uint8Array(8); + var view = new DataView(rv.buffer); + // nsec30 | secHigh2 + view.setUint32(0, (nsec << 2) | (secHigh & 0x3)); + // secLow32 + view.setUint32(4, secLow); + return rv; + } + } else { + // timestamp 96 = { nsec32 (unsigned), sec64 (signed) } + var rv = new Uint8Array(12); + var view = new DataView(rv.buffer); + view.setUint32(0, nsec); + setInt64(view, 4, sec); + return rv; + } +} +function encodeDateToTimeSpec(date) { + var msec = date.getTime(); + var sec = Math.floor(msec / 1e3); + var nsec = (msec - sec * 1e3) * 1e6; + // Normalizes { sec, nsec } to ensure nsec is unsigned. + var nsecInSec = Math.floor(nsec / 1e9); + return { + sec: sec + nsecInSec, + nsec: nsec - nsecInSec * 1e9, + }; +} +function encodeTimestampExtension(object) { + if (object instanceof Date) { + var timeSpec = encodeDateToTimeSpec(object); + return encodeTimeSpecToTimestamp(timeSpec); + } else { + return null; + } +} +function decodeTimestampToTimeSpec(data) { + var view = new DataView(data.buffer, data.byteOffset, data.byteLength); + // data may be 32, 64, or 96 bits + switch (data.byteLength) { + case 4: { + // timestamp 32 = { sec32 } + var sec = view.getUint32(0); + var nsec = 0; + return { sec: sec, nsec: nsec }; + } + case 8: { + // timestamp 64 = { nsec30, sec34 } + var nsec30AndSecHigh2 = view.getUint32(0); + var secLow32 = view.getUint32(4); + var sec = (nsec30AndSecHigh2 & 0x3) * 0x100000000 + secLow32; + var nsec = nsec30AndSecHigh2 >>> 2; + return { sec: sec, nsec: nsec }; + } + case 12: { + // timestamp 96 = { nsec32 (unsigned), sec64 (signed) } + var sec = getInt64(view, 4); + var nsec = view.getUint32(0); + return { sec: sec, nsec: nsec }; + } + default: + throw new DecodeError( + "Unrecognized data size for timestamp (expected 4, 8, or 12): ".concat( + data.length + ) + ); + } +} +function decodeTimestampExtension(data) { + var timeSpec = decodeTimestampToTimeSpec(data); + return new Date(timeSpec.sec * 1e3 + timeSpec.nsec / 1e6); +} +var timestampExtension = { + type: EXT_TIMESTAMP, + encode: encodeTimestampExtension, + decode: decodeTimestampExtension, +}; + +// ExtensionCodec to handle MessagePack extensions +var ExtensionCodec = /** @class */ (function () { + function ExtensionCodec() { + // built-in extensions + this.builtInEncoders = []; + this.builtInDecoders = []; + // custom extensions + this.encoders = []; + this.decoders = []; + this.register(timestampExtension); + } + ExtensionCodec.prototype.register = function (_a) { + var type = _a.type, + encode = _a.encode, + decode = _a.decode; + if (type >= 0) { + // custom extensions + this.encoders[type] = encode; + this.decoders[type] = decode; + } else { + // built-in extensions + var index = 1 + type; + this.builtInEncoders[index] = encode; + this.builtInDecoders[index] = decode; + } + }; + ExtensionCodec.prototype.tryToEncode = function (object, context) { + // built-in extensions + for (var i = 0; i < this.builtInEncoders.length; i++) { + var encodeExt = this.builtInEncoders[i]; + if (encodeExt != null) { + var data = encodeExt(object, context); + if (data != null) { + var type = -1 - i; + return new ExtData(type, data); + } + } + } + // custom extensions + for (var i = 0; i < this.encoders.length; i++) { + var encodeExt = this.encoders[i]; + if (encodeExt != null) { + var data = encodeExt(object, context); + if (data != null) { + var type = i; + return new ExtData(type, data); + } + } + } + if (object instanceof ExtData) { + // to keep ExtData as is + return object; + } + return null; + }; + ExtensionCodec.prototype.decode = function (data, type, context) { + var decodeExt = + type < 0 ? this.builtInDecoders[-1 - type] : this.decoders[type]; + if (decodeExt) { + return decodeExt(data, type, context); + } else { + // decode() does not fail, returns ExtData instead. + return new ExtData(type, data); + } + }; + ExtensionCodec.defaultCodec = new ExtensionCodec(); + return ExtensionCodec; +})(); + +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 (buffer instanceof ArrayBuffer) { + return new Uint8Array(buffer); + } else { + // ArrayLike + return Uint8Array.from(buffer); + } +} +function createDataView(buffer) { + if (buffer instanceof ArrayBuffer) { + return new DataView(buffer); + } + var bufferView = ensureUint8Array(buffer); + return new DataView( + bufferView.buffer, + bufferView.byteOffset, + bufferView.byteLength + ); +} + +var DEFAULT_MAX_DEPTH = 100; +var DEFAULT_INITIAL_BUFFER_SIZE = 2048; +var Encoder = /** @class */ (function () { + function Encoder(options) { + var _a, _b, _c, _d, _e, _f, _g, _h; + this.extensionCodec = + (_a = + options === null || options === void 0 + ? void 0 + : options.extensionCodec) !== null && _a !== void 0 + ? _a + : ExtensionCodec.defaultCodec; + this.context = + options === null || options === void 0 ? void 0 : options.context; // needs a type assertion because EncoderOptions has no context property when ContextType is undefined + this.useBigInt64 = + (_b = + options === null || options === void 0 + ? void 0 + : options.useBigInt64) !== null && _b !== void 0 + ? _b + : false; + this.maxDepth = + (_c = + options === null || options === void 0 ? void 0 : options.maxDepth) !== + null && _c !== void 0 + ? _c + : DEFAULT_MAX_DEPTH; + this.initialBufferSize = + (_d = + options === null || options === void 0 + ? void 0 + : options.initialBufferSize) !== null && _d !== void 0 + ? _d + : DEFAULT_INITIAL_BUFFER_SIZE; + this.sortKeys = + (_e = + options === null || options === void 0 ? void 0 : options.sortKeys) !== + null && _e !== void 0 + ? _e + : false; + this.forceFloat32 = + (_f = + options === null || options === void 0 + ? void 0 + : options.forceFloat32) !== null && _f !== void 0 + ? _f + : false; + this.ignoreUndefined = + (_g = + options === null || options === void 0 + ? void 0 + : options.ignoreUndefined) !== null && _g !== void 0 + ? _g + : false; + this.forceIntegerToFloat = + (_h = + options === null || options === void 0 + ? void 0 + : options.forceIntegerToFloat) !== null && _h !== void 0 + ? _h + : false; + this.pos = 0; + this.view = new DataView(new ArrayBuffer(this.initialBufferSize)); + this.bytes = new Uint8Array(this.view.buffer); + } + Encoder.prototype.reinitializeState = function () { + 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. + */ + Encoder.prototype.encodeSharedRef = function (object) { + this.reinitializeState(); + this.doEncode(object, 1); + return this.bytes.subarray(0, this.pos); + }; + /** + * @returns Encodes the object and returns a copy of the encoder's internal buffer. + */ + Encoder.prototype.encode = function (object) { + this.reinitializeState(); + this.doEncode(object, 1); + return this.bytes.slice(0, this.pos); + }; + Encoder.prototype.doEncode = function (object, depth) { + if (depth > this.maxDepth) { + throw new Error("Too deep objects in depth ".concat(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); + } + }; + Encoder.prototype.ensureBufferSizeToWrite = function (sizeToWrite) { + var requiredSize = this.pos + sizeToWrite; + if (this.view.byteLength < requiredSize) { + this.resizeBuffer(requiredSize * 2); + } + }; + Encoder.prototype.resizeBuffer = function (newSize) { + var newBuffer = new ArrayBuffer(newSize); + var newBytes = new Uint8Array(newBuffer); + var newView = new DataView(newBuffer); + newBytes.set(this.bytes); + this.view = newView; + this.bytes = newBytes; + }; + Encoder.prototype.encodeNil = function () { + this.writeU8(0xc0); + }; + Encoder.prototype.encodeBoolean = function (object) { + if (object === false) { + this.writeU8(0xc2); + } else { + this.writeU8(0xc3); + } + }; + Encoder.prototype.encodeNumber = function (object) { + if (!this.forceIntegerToFloat && Number.isSafeInteger(object)) { + if (object >= 0) { + if (object < 0x80) { + // positive fixint + this.writeU8(object); + } else if (object < 0x100) { + // uint 8 + this.writeU8(0xcc); + this.writeU8(object); + } else if (object < 0x10000) { + // uint 16 + this.writeU8(0xcd); + this.writeU16(object); + } else if (object < 0x100000000) { + // uint 32 + this.writeU8(0xce); + this.writeU32(object); + } else if (!this.useBigInt64) { + // uint 64 + this.writeU8(0xcf); + this.writeU64(object); + } else { + this.encodeNumberAsFloat(object); + } + } else { + if (object >= -0x20) { + // negative fixint + this.writeU8(0xe0 | (object + 0x20)); + } else if (object >= -0x80) { + // int 8 + this.writeU8(0xd0); + this.writeI8(object); + } else if (object >= -0x8000) { + // int 16 + this.writeU8(0xd1); + this.writeI16(object); + } else if (object >= -0x80000000) { + // int 32 + this.writeU8(0xd2); + this.writeI32(object); + } else if (!this.useBigInt64) { + // int 64 + this.writeU8(0xd3); + this.writeI64(object); + } else { + this.encodeNumberAsFloat(object); + } + } + } else { + this.encodeNumberAsFloat(object); + } + }; + Encoder.prototype.encodeNumberAsFloat = function (object) { + if (this.forceFloat32) { + // float 32 + this.writeU8(0xca); + this.writeF32(object); + } else { + // float 64 + this.writeU8(0xcb); + this.writeF64(object); + } + }; + Encoder.prototype.encodeBigInt64 = function (object) { + if (object >= BigInt(0)) { + // uint 64 + this.writeU8(0xcf); + this.writeBigUint64(object); + } else { + // int 64 + this.writeU8(0xd3); + this.writeBigInt64(object); + } + }; + Encoder.prototype.writeStringHeader = function (byteLength) { + if (byteLength < 32) { + // fixstr + this.writeU8(0xa0 + byteLength); + } else if (byteLength < 0x100) { + // str 8 + this.writeU8(0xd9); + this.writeU8(byteLength); + } else if (byteLength < 0x10000) { + // str 16 + this.writeU8(0xda); + this.writeU16(byteLength); + } else if (byteLength < 0x100000000) { + // str 32 + this.writeU8(0xdb); + this.writeU32(byteLength); + } else { + throw new Error( + "Too long string: ".concat(byteLength, " bytes in UTF-8") + ); + } + }; + Encoder.prototype.encodeString = function (object) { + var maxHeaderSize = 1 + 4; + var byteLength = utf8Count(object); + this.ensureBufferSizeToWrite(maxHeaderSize + byteLength); + this.writeStringHeader(byteLength); + utf8Encode(object, this.bytes, this.pos); + this.pos += byteLength; + }; + Encoder.prototype.encodeObject = function (object, depth) { + // try to encode objects with custom codec first of non-primitives + var 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 { + // symbol, function and other special object come here unless extensionCodec handles them. + throw new Error( + "Unrecognized object: ".concat(Object.prototype.toString.apply(object)) + ); + } + }; + Encoder.prototype.encodeBinary = function (object) { + var size = object.byteLength; + if (size < 0x100) { + // bin 8 + this.writeU8(0xc4); + this.writeU8(size); + } else if (size < 0x10000) { + // bin 16 + this.writeU8(0xc5); + this.writeU16(size); + } else if (size < 0x100000000) { + // bin 32 + this.writeU8(0xc6); + this.writeU32(size); + } else { + throw new Error("Too large binary: ".concat(size)); + } + var bytes = ensureUint8Array(object); + this.writeU8a(bytes); + }; + Encoder.prototype.encodeArray = function (object, depth) { + var size = object.length; + if (size < 16) { + // fixarray + this.writeU8(0x90 + size); + } else if (size < 0x10000) { + // array 16 + this.writeU8(0xdc); + this.writeU16(size); + } else if (size < 0x100000000) { + // array 32 + this.writeU8(0xdd); + this.writeU32(size); + } else { + throw new Error("Too large array: ".concat(size)); + } + for (var _i = 0, object_1 = object; _i < object_1.length; _i++) { + var item = object_1[_i]; + this.doEncode(item, depth + 1); + } + }; + Encoder.prototype.countWithoutUndefined = function (object, keys) { + var count = 0; + for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) { + var key = keys_1[_i]; + if (object[key] !== undefined) { + count++; + } + } + return count; + }; + Encoder.prototype.encodeMap = function (object, depth) { + var keys = Object.keys(object); + if (this.sortKeys) { + keys.sort(); + } + var size = this.ignoreUndefined + ? this.countWithoutUndefined(object, keys) + : keys.length; + if (size < 16) { + // fixmap + this.writeU8(0x80 + size); + } else if (size < 0x10000) { + // map 16 + this.writeU8(0xde); + this.writeU16(size); + } else if (size < 0x100000000) { + // map 32 + this.writeU8(0xdf); + this.writeU32(size); + } else { + throw new Error("Too large map object: ".concat(size)); + } + for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) { + var key = keys_2[_i]; + var value = object[key]; + if (!(this.ignoreUndefined && value === undefined)) { + this.encodeString(key); + this.doEncode(value, depth + 1); + } + } + }; + Encoder.prototype.encodeExtension = function (ext) { + var size = ext.data.length; + if (size === 1) { + // fixext 1 + this.writeU8(0xd4); + } else if (size === 2) { + // fixext 2 + this.writeU8(0xd5); + } else if (size === 4) { + // fixext 4 + this.writeU8(0xd6); + } else if (size === 8) { + // fixext 8 + this.writeU8(0xd7); + } else if (size === 16) { + // fixext 16 + this.writeU8(0xd8); + } else if (size < 0x100) { + // ext 8 + this.writeU8(0xc7); + this.writeU8(size); + } else if (size < 0x10000) { + // ext 16 + this.writeU8(0xc8); + this.writeU16(size); + } else if (size < 0x100000000) { + // ext 32 + this.writeU8(0xc9); + this.writeU32(size); + } else { + throw new Error("Too large extension object: ".concat(size)); + } + this.writeI8(ext.type); + this.writeU8a(ext.data); + }; + Encoder.prototype.writeU8 = function (value) { + this.ensureBufferSizeToWrite(1); + this.view.setUint8(this.pos, value); + this.pos++; + }; + Encoder.prototype.writeU8a = function (values) { + var size = values.length; + this.ensureBufferSizeToWrite(size); + this.bytes.set(values, this.pos); + this.pos += size; + }; + Encoder.prototype.writeI8 = function (value) { + this.ensureBufferSizeToWrite(1); + this.view.setInt8(this.pos, value); + this.pos++; + }; + Encoder.prototype.writeU16 = function (value) { + this.ensureBufferSizeToWrite(2); + this.view.setUint16(this.pos, value); + this.pos += 2; + }; + Encoder.prototype.writeI16 = function (value) { + this.ensureBufferSizeToWrite(2); + this.view.setInt16(this.pos, value); + this.pos += 2; + }; + Encoder.prototype.writeU32 = function (value) { + this.ensureBufferSizeToWrite(4); + this.view.setUint32(this.pos, value); + this.pos += 4; + }; + Encoder.prototype.writeI32 = function (value) { + this.ensureBufferSizeToWrite(4); + this.view.setInt32(this.pos, value); + this.pos += 4; + }; + Encoder.prototype.writeF32 = function (value) { + this.ensureBufferSizeToWrite(4); + this.view.setFloat32(this.pos, value); + this.pos += 4; + }; + Encoder.prototype.writeF64 = function (value) { + this.ensureBufferSizeToWrite(8); + this.view.setFloat64(this.pos, value); + this.pos += 8; + }; + Encoder.prototype.writeU64 = function (value) { + this.ensureBufferSizeToWrite(8); + setUint64(this.view, this.pos, value); + this.pos += 8; + }; + Encoder.prototype.writeI64 = function (value) { + this.ensureBufferSizeToWrite(8); + setInt64(this.view, this.pos, value); + this.pos += 8; + }; + Encoder.prototype.writeBigUint64 = function (value) { + this.ensureBufferSizeToWrite(8); + this.view.setBigUint64(this.pos, value); + this.pos += 8; + }; + Encoder.prototype.writeBigInt64 = function (value) { + this.ensureBufferSizeToWrite(8); + this.view.setBigInt64(this.pos, value); + this.pos += 8; + }; + return Encoder; +})(); + +/** + * @deprecated No longer supported. + */ +var defaultEncodeOptions = undefined; +function encode(value, options) { + var encoder = new Encoder(options); + return encoder.encodeSharedRef(value); +} + +function prettyByte(byte) { + return "" + .concat(byte < 0 ? "-" : "", "0x") + .concat(Math.abs(byte).toString(16).padStart(2, "0")); +} + +var DEFAULT_MAX_KEY_LENGTH = 16; +var DEFAULT_MAX_LENGTH_PER_KEY = 16; +var CachedKeyDecoder = /** @class */ (function () { + function CachedKeyDecoder(maxKeyLength, maxLengthPerKey) { + if (maxKeyLength === void 0) { + maxKeyLength = DEFAULT_MAX_KEY_LENGTH; + } + if (maxLengthPerKey === void 0) { + maxLengthPerKey = DEFAULT_MAX_LENGTH_PER_KEY; + } + this.maxKeyLength = maxKeyLength; + this.maxLengthPerKey = maxLengthPerKey; + this.hit = 0; + this.miss = 0; + // because a sparse array is typically slower than a non-sparse array. + this.caches = []; + for (var i = 0; i < this.maxKeyLength; i++) { + this.caches.push([]); + } + } + CachedKeyDecoder.prototype.canBeCached = function (byteLength) { + return byteLength > 0 && byteLength <= this.maxKeyLength; + }; + CachedKeyDecoder.prototype.find = function (bytes, inputOffset, byteLength) { + var records = this.caches[byteLength - 1]; + FIND_CHUNK: for ( + var _i = 0, records_1 = records; + _i < records_1.length; + _i++ + ) { + var record = records_1[_i]; + var recordBytes = record.bytes; + for (var j = 0; j < byteLength; j++) { + if (recordBytes[j] !== bytes[inputOffset + j]) { + continue FIND_CHUNK; + } + } + return record.str; + } + return null; + }; + CachedKeyDecoder.prototype.store = function (bytes, value) { + var records = this.caches[bytes.length - 1]; + var record = { bytes: bytes, str: value }; + if (records.length >= this.maxLengthPerKey) { + records[(Math.random() * records.length) | 0] = record; + } else { + records.push(record); + } + }; + CachedKeyDecoder.prototype.decode = function ( + bytes, + inputOffset, + byteLength + ) { + var cachedValue = this.find(bytes, inputOffset, byteLength); + if (cachedValue != null) { + this.hit++; + return cachedValue; + } + this.miss++; + var str = utf8DecodeJs(bytes, inputOffset, byteLength); + // Ensure to copy a slice of bytes because the byte may be NodeJS Buffer and Buffer#slice() returns a reference to its internal ArrayBuffer. + var slicedCopyOfBytes = Uint8Array.prototype.slice.call( + bytes, + inputOffset, + inputOffset + byteLength + ); + this.store(slicedCopyOfBytes, str); + return str; + }; + return CachedKeyDecoder; +})(); + +var __awaiter$1 = + (undefined && undefined.__awaiter) || + function (thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P + ? value + : new P(function (resolve) { + resolve(value); + }); + } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done + ? resolve(result.value) + : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); + }; +var __generator$2 = + (undefined && undefined.__generator) || + function (thisArg, body) { + var _ = { + label: 0, + sent: function () { + if (t[0] & 1) throw t[1]; + return t[1]; + }, + trys: [], + ops: [], + }, + f, + y, + t, + g; + return ( + (g = { next: verb(0), throw: verb(1), return: verb(2) }), + typeof Symbol === "function" && + (g[Symbol.iterator] = function () { + return this; + }), + g + ); + function verb(n) { + return function (v) { + return step([n, v]); + }; + } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while ((g && ((g = 0), op[0] && (_ = 0)), _)) + try { + if ( + ((f = 1), + y && + (t = + op[0] & 2 + ? y["return"] + : op[0] + ? y["throw"] || ((t = y["return"]) && t.call(y), 0) + : y.next) && + !(t = t.call(y, op[1])).done) + ) + return t; + if (((y = 0), t)) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: + case 1: + t = op; + break; + case 4: + _.label++; + return { value: op[1], done: false }; + case 5: + _.label++; + y = op[1]; + op = [0]; + continue; + case 7: + op = _.ops.pop(); + _.trys.pop(); + continue; + default: + if ( + !((t = _.trys), (t = t.length > 0 && t[t.length - 1])) && + (op[0] === 6 || op[0] === 2) + ) { + _ = 0; + continue; + } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { + _.label = op[1]; + break; + } + if (op[0] === 6 && _.label < t[1]) { + _.label = t[1]; + t = op; + break; + } + if (t && _.label < t[2]) { + _.label = t[2]; + _.ops.push(op); + break; + } + if (t[2]) _.ops.pop(); + _.trys.pop(); + continue; + } + op = body.call(thisArg, _); + } catch (e) { + op = [6, e]; + y = 0; + } finally { + f = t = 0; + } + if (op[0] & 5) throw op[1]; + return { value: op[0] ? op[1] : void 0, done: true }; + } + }; +var __asyncValues = + (undefined && undefined.__asyncValues) || + function (o) { + if (!Symbol.asyncIterator) + throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator], + i; + return m + ? m.call(o) + : ((o = + typeof __values === "function" ? __values(o) : o[Symbol.iterator]()), + (i = {}), + verb("next"), + verb("throw"), + verb("return"), + (i[Symbol.asyncIterator] = function () { + return this; + }), + i); + function verb(n) { + i[n] = + o[n] && + function (v) { + return new Promise(function (resolve, reject) { + (v = o[n](v)), settle(resolve, reject, v.done, v.value); + }); + }; + } + function settle(resolve, reject, d, v) { + Promise.resolve(v).then(function (v) { + resolve({ value: v, done: d }); + }, reject); + } + }; +var __await$1 = + (undefined && undefined.__await) || + function (v) { + return this instanceof __await$1 ? ((this.v = v), this) : new __await$1(v); + }; +var __asyncGenerator$1 = + (undefined && undefined.__asyncGenerator) || + function (thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) + throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), + i, + q = []; + return ( + (i = {}), + verb("next"), + verb("throw"), + verb("return"), + (i[Symbol.asyncIterator] = function () { + return this; + }), + i + ); + function verb(n) { + if (g[n]) + i[n] = function (v) { + return new Promise(function (a, b) { + q.push([n, v, a, b]) > 1 || resume(n, v); + }); + }; + } + function resume(n, v) { + try { + step(g[n](v)); + } catch (e) { + settle(q[0][3], e); + } + } + function step(r) { + r.value instanceof __await$1 + ? Promise.resolve(r.value.v).then(fulfill, reject) + : settle(q[0][2], r); + } + function fulfill(value) { + resume("next", value); + } + function reject(value) { + resume("throw", value); + } + function settle(f, v) { + if ((f(v), q.shift(), q.length)) resume(q[0][0], q[0][1]); + } + }; +var STATE_ARRAY = "array"; +var STATE_MAP_KEY = "map_key"; +var STATE_MAP_VALUE = "map_value"; +var isValidMapKeyType = function (key) { + return typeof key === "string" || typeof key === "number"; +}; +var HEAD_BYTE_REQUIRED = -1; +var EMPTY_VIEW = new DataView(new ArrayBuffer(0)); +var EMPTY_BYTES = new Uint8Array(EMPTY_VIEW.buffer); +try { + // IE11: The spec says it should throw RangeError, + // IE11: but in IE11 it throws TypeError. + 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 DataViewIndexOutOfBoundsError = RangeError; +var MORE_DATA = new DataViewIndexOutOfBoundsError("Insufficient data"); +var sharedCachedKeyDecoder = new CachedKeyDecoder(); +var Decoder = /** @class */ (function () { + function Decoder(options) { + var _a, _b, _c, _d, _e, _f, _g; + this.totalPos = 0; + this.pos = 0; + this.view = EMPTY_VIEW; + this.bytes = EMPTY_BYTES; + this.headByte = HEAD_BYTE_REQUIRED; + this.stack = []; + this.extensionCodec = + (_a = + options === null || options === void 0 + ? void 0 + : options.extensionCodec) !== null && _a !== void 0 + ? _a + : ExtensionCodec.defaultCodec; + this.context = + options === null || options === void 0 ? void 0 : options.context; // needs a type assertion because EncoderOptions has no context property when ContextType is undefined + this.useBigInt64 = + (_b = + options === null || options === void 0 + ? void 0 + : options.useBigInt64) !== null && _b !== void 0 + ? _b + : false; + this.maxStrLength = + (_c = + options === null || options === void 0 + ? void 0 + : options.maxStrLength) !== null && _c !== void 0 + ? _c + : UINT32_MAX; + this.maxBinLength = + (_d = + options === null || options === void 0 + ? void 0 + : options.maxBinLength) !== null && _d !== void 0 + ? _d + : UINT32_MAX; + this.maxArrayLength = + (_e = + options === null || options === void 0 + ? void 0 + : options.maxArrayLength) !== null && _e !== void 0 + ? _e + : UINT32_MAX; + this.maxMapLength = + (_f = + options === null || options === void 0 + ? void 0 + : options.maxMapLength) !== null && _f !== void 0 + ? _f + : UINT32_MAX; + this.maxExtLength = + (_g = + options === null || options === void 0 + ? void 0 + : options.maxExtLength) !== null && _g !== void 0 + ? _g + : UINT32_MAX; + this.keyDecoder = + (options === null || options === void 0 ? void 0 : options.keyDecoder) !== + undefined + ? options.keyDecoder + : sharedCachedKeyDecoder; + } + Decoder.prototype.reinitializeState = function () { + this.totalPos = 0; + this.headByte = HEAD_BYTE_REQUIRED; + this.stack.length = 0; + // view, bytes, and pos will be re-initialized in setBuffer() + }; + Decoder.prototype.setBuffer = function (buffer) { + this.bytes = ensureUint8Array(buffer); + this.view = createDataView(this.bytes); + this.pos = 0; + }; + Decoder.prototype.appendBuffer = function (buffer) { + if (this.headByte === HEAD_BYTE_REQUIRED && !this.hasRemaining(1)) { + this.setBuffer(buffer); + } else { + var remainingData = this.bytes.subarray(this.pos); + var newData = ensureUint8Array(buffer); + // concat remainingData + newData + var newBuffer = new Uint8Array(remainingData.length + newData.length); + newBuffer.set(remainingData); + newBuffer.set(newData, remainingData.length); + this.setBuffer(newBuffer); + } + }; + Decoder.prototype.hasRemaining = function (size) { + return this.view.byteLength - this.pos >= size; + }; + Decoder.prototype.createExtraByteError = function (posToShow) { + var _a = this, + view = _a.view, + pos = _a.pos; + return new RangeError( + "Extra " + .concat(view.byteLength - pos, " of ") + .concat(view.byteLength, " byte(s) found at buffer[") + .concat(posToShow, "]") + ); + }; + /** + * @throws {@link DecodeError} + * @throws {@link RangeError} + */ + Decoder.prototype.decode = function (buffer) { + this.reinitializeState(); + this.setBuffer(buffer); + var object = this.doDecodeSync(); + if (this.hasRemaining(1)) { + throw this.createExtraByteError(this.pos); + } + return object; + }; + Decoder.prototype.decodeMulti = function (buffer) { + return __generator$2(this, function (_a) { + switch (_a.label) { + case 0: + this.reinitializeState(); + this.setBuffer(buffer); + _a.label = 1; + case 1: + if (!this.hasRemaining(1)) return [3 /*break*/, 3]; + return [4 /*yield*/, this.doDecodeSync()]; + case 2: + _a.sent(); + return [3 /*break*/, 1]; + case 3: + return [2 /*return*/]; + } + }); + }; + Decoder.prototype.decodeAsync = function (stream) { + var _a, stream_1, stream_1_1; + var _b, e_1, _c, _d; + return __awaiter$1(this, void 0, void 0, function () { + var decoded, object, buffer, e_1_1, _e, headByte, pos, totalPos; + return __generator$2(this, function (_f) { + switch (_f.label) { + case 0: + decoded = false; + _f.label = 1; + case 1: + _f.trys.push([1, 6, 7, 12]); + (_a = true), (stream_1 = __asyncValues(stream)); + _f.label = 2; + case 2: + return [4 /*yield*/, stream_1.next()]; + case 3: + if (!((stream_1_1 = _f.sent()), (_b = stream_1_1.done), !_b)) + return [3 /*break*/, 5]; + _d = stream_1_1.value; + _a = false; + try { + buffer = _d; + if (decoded) { + throw this.createExtraByteError(this.totalPos); + } + this.appendBuffer(buffer); + try { + object = this.doDecodeSync(); + decoded = true; + } catch (e) { + if (!(e instanceof DataViewIndexOutOfBoundsError)) { + throw e; // rethrow + } + // fallthrough + } + this.totalPos += this.pos; + } finally { + _a = true; + } + _f.label = 4; + case 4: + return [3 /*break*/, 2]; + case 5: + return [3 /*break*/, 12]; + case 6: + e_1_1 = _f.sent(); + e_1 = { error: e_1_1 }; + return [3 /*break*/, 12]; + case 7: + _f.trys.push([7, , 10, 11]); + if (!(!_a && !_b && (_c = stream_1.return))) + return [3 /*break*/, 9]; + return [4 /*yield*/, _c.call(stream_1)]; + case 8: + _f.sent(); + _f.label = 9; + case 9: + return [3 /*break*/, 11]; + case 10: + if (e_1) throw e_1.error; + return [7 /*endfinally*/]; + case 11: + return [7 /*endfinally*/]; + case 12: + if (decoded) { + if (this.hasRemaining(1)) { + throw this.createExtraByteError(this.totalPos); + } + return [2 /*return*/, object]; + } + (_e = this), + (headByte = _e.headByte), + (pos = _e.pos), + (totalPos = _e.totalPos); + throw new RangeError( + "Insufficient data in parsing " + .concat(prettyByte(headByte), " at ") + .concat(totalPos, " (") + .concat(pos, " in the current buffer)") + ); + } + }); + }); + }; + Decoder.prototype.decodeArrayStream = function (stream) { + return this.decodeMultiAsync(stream, true); + }; + Decoder.prototype.decodeStream = function (stream) { + return this.decodeMultiAsync(stream, false); + }; + Decoder.prototype.decodeMultiAsync = function (stream, isArray) { + return __asyncGenerator$1(this, arguments, function decodeMultiAsync_1() { + var isArrayHeaderRequired, + arrayItemsLeft, + _a, + stream_2, + stream_2_1, + buffer, + e_2, + e_3_1; + var _b, e_3, _c, _d; + return __generator$2(this, function (_e) { + switch (_e.label) { + case 0: + isArrayHeaderRequired = isArray; + arrayItemsLeft = -1; + _e.label = 1; + case 1: + _e.trys.push([1, 15, 16, 21]); + (_a = true), (stream_2 = __asyncValues(stream)); + _e.label = 2; + case 2: + return [4 /*yield*/, __await$1(stream_2.next())]; + case 3: + if (!((stream_2_1 = _e.sent()), (_b = stream_2_1.done), !_b)) + return [3 /*break*/, 14]; + _d = stream_2_1.value; + _a = false; + _e.label = 4; + case 4: + _e.trys.push([4, , 12, 13]); + buffer = _d; + if (isArray && arrayItemsLeft === 0) { + throw this.createExtraByteError(this.totalPos); + } + this.appendBuffer(buffer); + if (isArrayHeaderRequired) { + arrayItemsLeft = this.readArraySize(); + isArrayHeaderRequired = false; + this.complete(); + } + _e.label = 5; + case 5: + _e.trys.push([5, 10, , 11]); + _e.label = 6; + case 6: + if (!true) return [3 /*break*/, 9]; + return [4 /*yield*/, __await$1(this.doDecodeSync())]; + case 7: + return [4 /*yield*/, _e.sent()]; + case 8: + _e.sent(); + if (--arrayItemsLeft === 0) { + return [3 /*break*/, 9]; + } + return [3 /*break*/, 6]; + case 9: + return [3 /*break*/, 11]; + case 10: + e_2 = _e.sent(); + if (!(e_2 instanceof DataViewIndexOutOfBoundsError)) { + throw e_2; // rethrow + } + return [3 /*break*/, 11]; + case 11: + this.totalPos += this.pos; + return [3 /*break*/, 13]; + case 12: + _a = true; + return [7 /*endfinally*/]; + case 13: + return [3 /*break*/, 2]; + case 14: + return [3 /*break*/, 21]; + case 15: + e_3_1 = _e.sent(); + e_3 = { error: e_3_1 }; + return [3 /*break*/, 21]; + case 16: + _e.trys.push([16, , 19, 20]); + if (!(!_a && !_b && (_c = stream_2.return))) + return [3 /*break*/, 18]; + return [4 /*yield*/, __await$1(_c.call(stream_2))]; + case 17: + _e.sent(); + _e.label = 18; + case 18: + return [3 /*break*/, 20]; + case 19: + if (e_3) throw e_3.error; + return [7 /*endfinally*/]; + case 20: + return [7 /*endfinally*/]; + case 21: + return [2 /*return*/]; + } + }); + }); + }; + Decoder.prototype.doDecodeSync = function () { + DECODE: while (true) { + var headByte = this.readHeadByte(); + var object = void 0; + if (headByte >= 0xe0) { + // negative fixint (111x xxxx) 0xe0 - 0xff + object = headByte - 0x100; + } else if (headByte < 0xc0) { + if (headByte < 0x80) { + // positive fixint (0xxx xxxx) 0x00 - 0x7f + object = headByte; + } else if (headByte < 0x90) { + // fixmap (1000 xxxx) 0x80 - 0x8f + var size = headByte - 0x80; + if (size !== 0) { + this.pushMapState(size); + this.complete(); + continue DECODE; + } else { + object = {}; + } + } else if (headByte < 0xa0) { + // fixarray (1001 xxxx) 0x90 - 0x9f + var size = headByte - 0x90; + if (size !== 0) { + this.pushArrayState(size); + this.complete(); + continue DECODE; + } else { + object = []; + } + } else { + // fixstr (101x xxxx) 0xa0 - 0xbf + var byteLength = headByte - 0xa0; + object = this.decodeUtf8String(byteLength, 0); + } + } else if (headByte === 0xc0) { + // nil + object = null; + } else if (headByte === 0xc2) { + // false + object = false; + } else if (headByte === 0xc3) { + // true + object = true; + } else if (headByte === 0xca) { + // float 32 + object = this.readF32(); + } else if (headByte === 0xcb) { + // float 64 + object = this.readF64(); + } else if (headByte === 0xcc) { + // uint 8 + object = this.readU8(); + } else if (headByte === 0xcd) { + // uint 16 + object = this.readU16(); + } else if (headByte === 0xce) { + // uint 32 + object = this.readU32(); + } else if (headByte === 0xcf) { + // uint 64 + if (this.useBigInt64) { + object = this.readU64AsBigInt(); + } else { + object = this.readU64(); + } + } else if (headByte === 0xd0) { + // int 8 + object = this.readI8(); + } else if (headByte === 0xd1) { + // int 16 + object = this.readI16(); + } else if (headByte === 0xd2) { + // int 32 + object = this.readI32(); + } else if (headByte === 0xd3) { + // int 64 + if (this.useBigInt64) { + object = this.readI64AsBigInt(); + } else { + object = this.readI64(); + } + } else if (headByte === 0xd9) { + // str 8 + var byteLength = this.lookU8(); + object = this.decodeUtf8String(byteLength, 1); + } else if (headByte === 0xda) { + // str 16 + var byteLength = this.lookU16(); + object = this.decodeUtf8String(byteLength, 2); + } else if (headByte === 0xdb) { + // str 32 + var byteLength = this.lookU32(); + object = this.decodeUtf8String(byteLength, 4); + } else if (headByte === 0xdc) { + // array 16 + var size = this.readU16(); + if (size !== 0) { + this.pushArrayState(size); + this.complete(); + continue DECODE; + } else { + object = []; + } + } else if (headByte === 0xdd) { + // array 32 + var size = this.readU32(); + if (size !== 0) { + this.pushArrayState(size); + this.complete(); + continue DECODE; + } else { + object = []; + } + } else if (headByte === 0xde) { + // map 16 + var size = this.readU16(); + if (size !== 0) { + this.pushMapState(size); + this.complete(); + continue DECODE; + } else { + object = {}; + } + } else if (headByte === 0xdf) { + // map 32 + var size = this.readU32(); + if (size !== 0) { + this.pushMapState(size); + this.complete(); + continue DECODE; + } else { + object = {}; + } + } else if (headByte === 0xc4) { + // bin 8 + var size = this.lookU8(); + object = this.decodeBinary(size, 1); + } else if (headByte === 0xc5) { + // bin 16 + var size = this.lookU16(); + object = this.decodeBinary(size, 2); + } else if (headByte === 0xc6) { + // bin 32 + var size = this.lookU32(); + object = this.decodeBinary(size, 4); + } else if (headByte === 0xd4) { + // fixext 1 + object = this.decodeExtension(1, 0); + } else if (headByte === 0xd5) { + // fixext 2 + object = this.decodeExtension(2, 0); + } else if (headByte === 0xd6) { + // fixext 4 + object = this.decodeExtension(4, 0); + } else if (headByte === 0xd7) { + // fixext 8 + object = this.decodeExtension(8, 0); + } else if (headByte === 0xd8) { + // fixext 16 + object = this.decodeExtension(16, 0); + } else if (headByte === 0xc7) { + // ext 8 + var size = this.lookU8(); + object = this.decodeExtension(size, 1); + } else if (headByte === 0xc8) { + // ext 16 + var size = this.lookU16(); + object = this.decodeExtension(size, 2); + } else if (headByte === 0xc9) { + // ext 32 + var size = this.lookU32(); + object = this.decodeExtension(size, 4); + } else { + throw new DecodeError( + "Unrecognized type byte: ".concat(prettyByte(headByte)) + ); + } + this.complete(); + var stack = this.stack; + while (stack.length > 0) { + // arrays and maps + var state = stack[stack.length - 1]; + if (state.type === STATE_ARRAY) { + state.array[state.position] = object; + state.position++; + if (state.position === state.size) { + stack.pop(); + object = state.array; + } else { + continue DECODE; + } + } else if (state.type === STATE_MAP_KEY) { + if (!isValidMapKeyType(object)) { + throw new DecodeError( + "The type of key must be string or number but " + typeof object + ); + } + if (object === "__proto__") { + throw new DecodeError("The key __proto__ is not allowed"); + } + state.key = object; + state.type = STATE_MAP_VALUE; + continue DECODE; + } else { + state.map[state.key] = object; + state.readCount++; + if (state.readCount === state.size) { + stack.pop(); + object = state.map; + } else { + state.key = null; + state.type = STATE_MAP_KEY; + continue DECODE; + } + } + } + return object; + } + }; + Decoder.prototype.readHeadByte = function () { + if (this.headByte === HEAD_BYTE_REQUIRED) { + this.headByte = this.readU8(); + // console.log("headByte", prettyByte(this.headByte)); + } + return this.headByte; + }; + Decoder.prototype.complete = function () { + this.headByte = HEAD_BYTE_REQUIRED; + }; + Decoder.prototype.readArraySize = function () { + var headByte = this.readHeadByte(); + switch (headByte) { + case 0xdc: + return this.readU16(); + case 0xdd: + return this.readU32(); + default: { + if (headByte < 0xa0) { + return headByte - 0x90; + } else { + throw new DecodeError( + "Unrecognized array type byte: ".concat(prettyByte(headByte)) + ); + } + } + } + }; + Decoder.prototype.pushMapState = function (size) { + if (size > this.maxMapLength) { + throw new DecodeError( + "Max length exceeded: map length (" + .concat(size, ") > maxMapLengthLength (") + .concat(this.maxMapLength, ")") + ); + } + this.stack.push({ + type: STATE_MAP_KEY, + size: size, + key: null, + readCount: 0, + map: {}, + }); + }; + Decoder.prototype.pushArrayState = function (size) { + if (size > this.maxArrayLength) { + throw new DecodeError( + "Max length exceeded: array length (" + .concat(size, ") > maxArrayLength (") + .concat(this.maxArrayLength, ")") + ); + } + this.stack.push({ + type: STATE_ARRAY, + size: size, + array: new Array(size), + position: 0, + }); + }; + Decoder.prototype.decodeUtf8String = function (byteLength, headerOffset) { + var _a; + if (byteLength > this.maxStrLength) { + throw new DecodeError( + "Max length exceeded: UTF-8 byte length (" + .concat(byteLength, ") > maxStrLength (") + .concat(this.maxStrLength, ")") + ); + } + if (this.bytes.byteLength < this.pos + headerOffset + byteLength) { + throw MORE_DATA; + } + var offset = this.pos + headerOffset; + var object; + if ( + this.stateIsMapKey() && + ((_a = this.keyDecoder) === null || _a === void 0 + ? void 0 + : _a.canBeCached(byteLength)) + ) { + object = this.keyDecoder.decode(this.bytes, offset, byteLength); + } else { + object = utf8Decode(this.bytes, offset, byteLength); + } + this.pos += headerOffset + byteLength; + return object; + }; + Decoder.prototype.stateIsMapKey = function () { + if (this.stack.length > 0) { + var state = this.stack[this.stack.length - 1]; + return state.type === STATE_MAP_KEY; + } + return false; + }; + Decoder.prototype.decodeBinary = function (byteLength, headOffset) { + if (byteLength > this.maxBinLength) { + throw new DecodeError( + "Max length exceeded: bin length (" + .concat(byteLength, ") > maxBinLength (") + .concat(this.maxBinLength, ")") + ); + } + if (!this.hasRemaining(byteLength + headOffset)) { + throw MORE_DATA; + } + var offset = this.pos + headOffset; + var object = this.bytes.subarray(offset, offset + byteLength); + this.pos += headOffset + byteLength; + return object; + }; + Decoder.prototype.decodeExtension = function (size, headOffset) { + if (size > this.maxExtLength) { + throw new DecodeError( + "Max length exceeded: ext length (" + .concat(size, ") > maxExtLength (") + .concat(this.maxExtLength, ")") + ); + } + var extType = this.view.getInt8(this.pos + headOffset); + var data = this.decodeBinary(size, headOffset + 1 /* extType */); + return this.extensionCodec.decode(data, extType, this.context); + }; + Decoder.prototype.lookU8 = function () { + return this.view.getUint8(this.pos); + }; + Decoder.prototype.lookU16 = function () { + return this.view.getUint16(this.pos); + }; + Decoder.prototype.lookU32 = function () { + return this.view.getUint32(this.pos); + }; + Decoder.prototype.readU8 = function () { + var value = this.view.getUint8(this.pos); + this.pos++; + return value; + }; + Decoder.prototype.readI8 = function () { + var value = this.view.getInt8(this.pos); + this.pos++; + return value; + }; + Decoder.prototype.readU16 = function () { + var value = this.view.getUint16(this.pos); + this.pos += 2; + return value; + }; + Decoder.prototype.readI16 = function () { + var value = this.view.getInt16(this.pos); + this.pos += 2; + return value; + }; + Decoder.prototype.readU32 = function () { + var value = this.view.getUint32(this.pos); + this.pos += 4; + return value; + }; + Decoder.prototype.readI32 = function () { + var value = this.view.getInt32(this.pos); + this.pos += 4; + return value; + }; + Decoder.prototype.readU64 = function () { + var value = getUint64(this.view, this.pos); + this.pos += 8; + return value; + }; + Decoder.prototype.readI64 = function () { + var value = getInt64(this.view, this.pos); + this.pos += 8; + return value; + }; + Decoder.prototype.readU64AsBigInt = function () { + var value = this.view.getBigUint64(this.pos); + this.pos += 8; + return value; + }; + Decoder.prototype.readI64AsBigInt = function () { + var value = this.view.getBigInt64(this.pos); + this.pos += 8; + return value; + }; + Decoder.prototype.readF32 = function () { + var value = this.view.getFloat32(this.pos); + this.pos += 4; + return value; + }; + Decoder.prototype.readF64 = function () { + var value = this.view.getFloat64(this.pos); + this.pos += 8; + return value; + }; + return Decoder; +})(); + +/** + * @deprecated No longer supported. + */ +var defaultDecodeOptions = undefined; +/** + * It decodes a single MessagePack object in a buffer. + * + * This is a synchronous decoding function. + * See other variants for asynchronous decoding: {@link decodeAsync()}, {@link decodeStream()}, or {@link decodeArrayStream()}. + * + * @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty. + * @throws {@link DecodeError} if the buffer contains invalid data. + */ +function decode(buffer, options) { + var decoder = new Decoder(options); + return decoder.decode(buffer); +} +/** + * It decodes multiple MessagePack objects in a buffer. + * This is corresponding to {@link decodeMultiStream()}. + * + * @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty. + * @throws {@link DecodeError} if the buffer contains invalid data. + */ +function decodeMulti(buffer, options) { + var decoder = new Decoder(options); + return decoder.decodeMulti(buffer); +} + +// utility for whatwg streams +var __generator$1 = + (undefined && undefined.__generator) || + function (thisArg, body) { + var _ = { + label: 0, + sent: function () { + if (t[0] & 1) throw t[1]; + return t[1]; + }, + trys: [], + ops: [], + }, + f, + y, + t, + g; + return ( + (g = { next: verb(0), throw: verb(1), return: verb(2) }), + typeof Symbol === "function" && + (g[Symbol.iterator] = function () { + return this; + }), + g + ); + function verb(n) { + return function (v) { + return step([n, v]); + }; + } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while ((g && ((g = 0), op[0] && (_ = 0)), _)) + try { + if ( + ((f = 1), + y && + (t = + op[0] & 2 + ? y["return"] + : op[0] + ? y["throw"] || ((t = y["return"]) && t.call(y), 0) + : y.next) && + !(t = t.call(y, op[1])).done) + ) + return t; + if (((y = 0), t)) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: + case 1: + t = op; + break; + case 4: + _.label++; + return { value: op[1], done: false }; + case 5: + _.label++; + y = op[1]; + op = [0]; + continue; + case 7: + op = _.ops.pop(); + _.trys.pop(); + continue; + default: + if ( + !((t = _.trys), (t = t.length > 0 && t[t.length - 1])) && + (op[0] === 6 || op[0] === 2) + ) { + _ = 0; + continue; + } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { + _.label = op[1]; + break; + } + if (op[0] === 6 && _.label < t[1]) { + _.label = t[1]; + t = op; + break; + } + if (t && _.label < t[2]) { + _.label = t[2]; + _.ops.push(op); + break; + } + if (t[2]) _.ops.pop(); + _.trys.pop(); + continue; + } + op = body.call(thisArg, _); + } catch (e) { + op = [6, e]; + y = 0; + } finally { + f = t = 0; + } + if (op[0] & 5) throw op[1]; + return { value: op[0] ? op[1] : void 0, done: true }; + } + }; +var __await = + (undefined && undefined.__await) || + function (v) { + return this instanceof __await ? ((this.v = v), this) : new __await(v); + }; +var __asyncGenerator = + (undefined && undefined.__asyncGenerator) || + function (thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) + throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), + i, + q = []; + return ( + (i = {}), + verb("next"), + verb("throw"), + verb("return"), + (i[Symbol.asyncIterator] = function () { + return this; + }), + i + ); + function verb(n) { + if (g[n]) + i[n] = function (v) { + return new Promise(function (a, b) { + q.push([n, v, a, b]) > 1 || resume(n, v); + }); + }; + } + function resume(n, v) { + try { + step(g[n](v)); + } catch (e) { + settle(q[0][3], e); + } + } + function step(r) { + r.value instanceof __await + ? Promise.resolve(r.value.v).then(fulfill, reject) + : settle(q[0][2], r); + } + function fulfill(value) { + resume("next", value); + } + function reject(value) { + resume("throw", value); + } + function settle(f, v) { + if ((f(v), q.shift(), q.length)) resume(q[0][0], q[0][1]); + } + }; +function isAsyncIterable(object) { + return object[Symbol.asyncIterator] != null; +} +function assertNonNull(value) { + if (value == null) { + throw new Error("Assertion Failure: value must not be null nor undefined"); + } +} +function asyncIterableFromStream(stream) { + return __asyncGenerator( + this, + arguments, + function asyncIterableFromStream_1() { + var reader, _a, done, value; + return __generator$1(this, function (_b) { + switch (_b.label) { + case 0: + reader = stream.getReader(); + _b.label = 1; + case 1: + _b.trys.push([1, , 9, 10]); + _b.label = 2; + case 2: + if (!true) return [3 /*break*/, 8]; + return [4 /*yield*/, __await(reader.read())]; + case 3: + (_a = _b.sent()), (done = _a.done), (value = _a.value); + if (!done) return [3 /*break*/, 5]; + return [4 /*yield*/, __await(void 0)]; + case 4: + return [2 /*return*/, _b.sent()]; + case 5: + assertNonNull(value); + return [4 /*yield*/, __await(value)]; + case 6: + return [4 /*yield*/, _b.sent()]; + case 7: + _b.sent(); + return [3 /*break*/, 2]; + case 8: + return [3 /*break*/, 10]; + case 9: + reader.releaseLock(); + return [7 /*endfinally*/]; + case 10: + return [2 /*return*/]; + } + }); + } + ); +} +function ensureAsyncIterable(streamLike) { + if (isAsyncIterable(streamLike)) { + return streamLike; + } else { + return asyncIterableFromStream(streamLike); + } +} + +var __awaiter = + (undefined && undefined.__awaiter) || + function (thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P + ? value + : new P(function (resolve) { + resolve(value); + }); + } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done + ? resolve(result.value) + : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); + }; +var __generator = + (undefined && undefined.__generator) || + function (thisArg, body) { + var _ = { + label: 0, + sent: function () { + if (t[0] & 1) throw t[1]; + return t[1]; + }, + trys: [], + ops: [], + }, + f, + y, + t, + g; + return ( + (g = { next: verb(0), throw: verb(1), return: verb(2) }), + typeof Symbol === "function" && + (g[Symbol.iterator] = function () { + return this; + }), + g + ); + function verb(n) { + return function (v) { + return step([n, v]); + }; + } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while ((g && ((g = 0), op[0] && (_ = 0)), _)) + try { + if ( + ((f = 1), + y && + (t = + op[0] & 2 + ? y["return"] + : op[0] + ? y["throw"] || ((t = y["return"]) && t.call(y), 0) + : y.next) && + !(t = t.call(y, op[1])).done) + ) + return t; + if (((y = 0), t)) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: + case 1: + t = op; + break; + case 4: + _.label++; + return { value: op[1], done: false }; + case 5: + _.label++; + y = op[1]; + op = [0]; + continue; + case 7: + op = _.ops.pop(); + _.trys.pop(); + continue; + default: + if ( + !((t = _.trys), (t = t.length > 0 && t[t.length - 1])) && + (op[0] === 6 || op[0] === 2) + ) { + _ = 0; + continue; + } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { + _.label = op[1]; + break; + } + if (op[0] === 6 && _.label < t[1]) { + _.label = t[1]; + t = op; + break; + } + if (t && _.label < t[2]) { + _.label = t[2]; + _.ops.push(op); + break; + } + if (t[2]) _.ops.pop(); + _.trys.pop(); + continue; + } + op = body.call(thisArg, _); + } catch (e) { + op = [6, e]; + y = 0; + } finally { + f = t = 0; + } + if (op[0] & 5) throw op[1]; + return { value: op[0] ? op[1] : void 0, done: true }; + } + }; +/** + * @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty. + * @throws {@link DecodeError} if the buffer contains invalid data. + */ +function decodeAsync(streamLike, options) { + return __awaiter(this, void 0, void 0, function () { + var stream, decoder; + return __generator(this, function (_a) { + stream = ensureAsyncIterable(streamLike); + decoder = new Decoder(options); + return [2 /*return*/, decoder.decodeAsync(stream)]; + }); + }); +} +/** + * @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty. + * @throws {@link DecodeError} if the buffer contains invalid data. + */ +function decodeArrayStream(streamLike, options) { + var stream = ensureAsyncIterable(streamLike); + var decoder = new Decoder(options); + return decoder.decodeArrayStream(stream); +} +/** + * @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty. + * @throws {@link DecodeError} if the buffer contains invalid data. + */ +function decodeMultiStream(streamLike, options) { + var stream = ensureAsyncIterable(streamLike); + var decoder = new Decoder(options); + return decoder.decodeStream(stream); +} +/** + * @deprecated Use {@link decodeMultiStream()} instead. + */ +var decodeStream = undefined; +`; diff --git a/packages/templates/wasm/typescript/shims.js b/packages/templates/wasm/typescript/shims/shims.js similarity index 87% rename from packages/templates/wasm/typescript/shims.js rename to packages/templates/wasm/typescript/shims/shims.js index 0e8d008b6..3316d42a0 100644 --- a/packages/templates/wasm/typescript/shims.js +++ b/packages/templates/wasm/typescript/shims/shims.js @@ -1,38 +1,36 @@ -const packagesShim = -` -// HACK: This is a hack because undefined, null, and functions are not supported by the JS Engine -function clean(obj, root = true) { - if (obj === undefined) { - return root ? "undefined" : undefined; - } else if (obj === null) { - return root ? "null" : undefined; - } else if (Array.isArray(obj)) { - return obj.map(x => clean(x, false)).filter(x => x !== undefined); - } else if (obj instanceof Error) { - return { message: obj.message }; - } else if (typeof obj === 'function') { - return root ? "function" : undefined; - } else if (typeof obj !== 'object') { - return obj; - } +const textEncoderShims = require("./textEncoder"); +const msgpackShims = require("./msgpack"); - for (let key in obj) { - let value = clean(obj[key], false); - if (value === undefined) { - delete obj[key]; - } else { - obj[key] = value; - } +const packagesShim = ` +${textEncoderShims} + +${msgpackShims} + +function msgpackEncodeValue(value) { + return { + value: Array.from(encode(value)), + }; +} + +//HACK: remove this once codegen is fixed +const __old_subinvoke = __wrap_subinvoke; +__wrap_subinvoke = function (plugin, method, args) { + if (Array.isArray(args)) { + return __old_subinvoke(plugin, method, args); + } else { + return __old_subinvoke(plugin, method, clean(args)); } - return obj; +}; + +function clean(obj, root = true) { + const x = JSON.stringify(Array.from(encode(obj))); + __wrap_debug_log(x); + return JSON.parse(x); } const console = { - log: function(...args) { - __wrap_subinvoke("plugin/console", "log", { args: clean(args) }); - }, - error: function(...args) { - __wrap_subinvoke("plugin/console", "error", { args: clean(args) }); + log: function(str) { + __wrap_debug_log(str); }, }; @@ -240,14 +238,14 @@ function require(lib) { `; const wrapCode = (code) => { - return `${packagesShim}\nconst __temp = (function () { \n${code}\n return __main(); })();\nclean(__temp)` -} + return `${packagesShim}\nconst __temp = (function () { \n${code}\n return __main(); })();\nclean(__temp)`; +}; module.exports = () => { return { - name: 'wrap-shims', + name: "wrap-shims", renderChunk(code) { return `${wrapCode(code)}`; }, - } -} \ No newline at end of file + }; +}; diff --git a/packages/templates/wasm/typescript/shims/textEncoder.js b/packages/templates/wasm/typescript/shims/textEncoder.js new file mode 100644 index 000000000..9d6df6fcb --- /dev/null +++ b/packages/templates/wasm/typescript/shims/textEncoder.js @@ -0,0 +1,73 @@ +module.exports = `function TextEncoder() {} + +TextEncoder.prototype.encode = function (string) { + var octets = []; + var length = string.length; + var i = 0; + while (i < length) { + var codePoint = string.codePointAt(i); + var c = 0; + var bits = 0; + if (codePoint <= 0x0000007f) { + c = 0; + bits = 0x00; + } else if (codePoint <= 0x000007ff) { + c = 6; + bits = 0xc0; + } else if (codePoint <= 0x0000ffff) { + c = 12; + bits = 0xe0; + } else if (codePoint <= 0x001fffff) { + c = 18; + bits = 0xf0; + } + octets.push(bits | (codePoint >> c)); + c -= 6; + while (c >= 0) { + octets.push(0x80 | ((codePoint >> c) & 0x3f)); + c -= 6; + } + i += codePoint >= 0x10000 ? 2 : 1; + } + return octets; +}; + +function TextDecoder() {} + +TextDecoder.prototype.decode = function (octets) { + var string = ""; + var i = 0; + while (i < octets.length) { + var octet = octets[i]; + var bytesNeeded = 0; + var codePoint = 0; + if (octet <= 0x7f) { + bytesNeeded = 0; + codePoint = octet & 0xff; + } else if (octet <= 0xdf) { + bytesNeeded = 1; + codePoint = octet & 0x1f; + } else if (octet <= 0xef) { + bytesNeeded = 2; + codePoint = octet & 0x0f; + } else if (octet <= 0xf4) { + bytesNeeded = 3; + codePoint = octet & 0x07; + } + if (octets.length - i - bytesNeeded > 0) { + var k = 0; + while (k < bytesNeeded) { + octet = octets[i + k + 1]; + codePoint = (codePoint << 6) | (octet & 0x3f); + k += 1; + } + } else { + codePoint = 0xfffd; + bytesNeeded = octets.length - i; + } + string += String.fromCodePoint(codePoint); + i += bytesNeeded + 1; + } + return string; +}; +`; diff --git a/yarn.lock b/yarn.lock index a387616f3..ce695674a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -120,20 +120,20 @@ integrity sha512-5UamI7xkUcJ3i9qVDS+KFDEK8/7oJ55/sJMB1Ge7IEapr7KfdfV/HErR+koZwOfd+SgtFKOKRhRakdg++DcJpQ== "@babel/core@^7.1.0", "@babel/core@^7.12.3", "@babel/core@^7.7.5": - version "7.22.15" - resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.22.15.tgz#15d4fd03f478a459015a4b94cfbb3bd42c48d2f4" - integrity sha512-PtZqMmgRrvj8ruoEOIwVA3yoF91O+Hgw9o7DAUTNBA6Mo2jpu31clx9a7Nz/9JznqetTR6zwfC4L3LAjKQXUwA== + version "7.22.17" + resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.22.17.tgz#2f9b0b395985967203514b24ee50f9fd0639c866" + integrity sha512-2EENLmhpwplDux5PSsZnSbnSkB3tZ6QTksgO25xwEL7pIDcNOMhF5v/s6RzwjMZzZzw9Ofc30gHv5ChCC8pifQ== dependencies: "@ampproject/remapping" "^2.2.0" "@babel/code-frame" "^7.22.13" "@babel/generator" "^7.22.15" "@babel/helper-compilation-targets" "^7.22.15" - "@babel/helper-module-transforms" "^7.22.15" + "@babel/helper-module-transforms" "^7.22.17" "@babel/helpers" "^7.22.15" - "@babel/parser" "^7.22.15" + "@babel/parser" "^7.22.16" "@babel/template" "^7.22.15" - "@babel/traverse" "^7.22.15" - "@babel/types" "^7.22.15" + "@babel/traverse" "^7.22.17" + "@babel/types" "^7.22.17" convert-source-map "^1.7.0" debug "^4.1.0" gensync "^1.0.0-beta.2" @@ -197,10 +197,10 @@ dependencies: "@babel/types" "^7.22.15" -"@babel/helper-module-transforms@^7.22.15": - version "7.22.15" - resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.22.15.tgz#40ad2f6950f143900e9c1c72363c0b431a606082" - integrity sha512-l1UiX4UyHSFsYt17iQ3Se5pQQZZHa22zyIXURmvkmLCD4t/aU+dvNWHatKac/D9Vm9UES7nvIqHs4jZqKviUmQ== +"@babel/helper-module-transforms@^7.22.17": + version "7.22.17" + resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.22.17.tgz#7edf129097a51ccc12443adbc6320e90eab76693" + integrity sha512-XouDDhQESrLHTpnBtCKExJdyY4gJCdrvH2Pyv8r8kovX2U8G0dRUOT45T9XlbLtuu9CLXP15eusnkprhoPV5iQ== dependencies: "@babel/helper-environment-visitor" "^7.22.5" "@babel/helper-module-imports" "^7.22.15" @@ -265,7 +265,7 @@ resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.18.4.tgz#6774231779dd700e0af29f6ad8d479582d7ce5ef" integrity sha512-FDge0dFazETFcxGw/EXzOkN8uJp0PC7Qbm+Pe9T+av2zlBpOgunFHkQPPn+eRuClU73JF+98D531UgayY89tow== -"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.22.15": +"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.22.15", "@babel/parser@^7.22.16": version "7.22.16" resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.22.16.tgz#180aead7f247305cce6551bea2720934e2fa2c95" integrity sha512-+gPfKv8UWeKKeJTUxe59+OobVcrYHETCsORl61EmSkmgymguYk/X5bp7GuUIXaFsc6y++v8ZxPsLSSuujqDphA== @@ -363,10 +363,10 @@ "@babel/parser" "^7.22.15" "@babel/types" "^7.22.15" -"@babel/traverse@^7.1.0", "@babel/traverse@^7.22.15": - version "7.22.15" - resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.22.15.tgz#75be4d2d6e216e880e93017f4e2389aeb77ef2d9" - integrity sha512-DdHPwvJY0sEeN4xJU5uRLmZjgMMDIvMPniLuYzUVXj/GGzysPl0/fwt44JBkyUIzGJPV8QgHMcQdQ34XFuKTYQ== +"@babel/traverse@^7.1.0", "@babel/traverse@^7.22.15", "@babel/traverse@^7.22.17": + version "7.22.17" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.22.17.tgz#b23c203ab3707e3be816043081b4a994fcacec44" + integrity sha512-xK4Uwm0JnAMvxYZxOVecss85WxTEIbTa7bnGyf/+EgCL5Zt3U7htUpEOWv9detPlamGKuRzCqw74xVglDWpPdg== dependencies: "@babel/code-frame" "^7.22.13" "@babel/generator" "^7.22.15" @@ -374,8 +374,8 @@ "@babel/helper-function-name" "^7.22.5" "@babel/helper-hoist-variables" "^7.22.5" "@babel/helper-split-export-declaration" "^7.22.6" - "@babel/parser" "^7.22.15" - "@babel/types" "^7.22.15" + "@babel/parser" "^7.22.16" + "@babel/types" "^7.22.17" debug "^4.1.0" globals "^11.1.0" @@ -388,10 +388,10 @@ "@babel/helper-validator-identifier" "^7.18.6" to-fast-properties "^2.0.0" -"@babel/types@^7.0.0", "@babel/types@^7.18.2", "@babel/types@^7.20.7", "@babel/types@^7.22.15", "@babel/types@^7.22.5", "@babel/types@^7.3.3": - version "7.22.15" - resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.22.15.tgz#266cb21d2c5fd0b3931e7a91b6dd72d2f617d282" - integrity sha512-X+NLXr0N8XXmN5ZsaQdm9U2SSC3UbIYq/doL++sueHOTisgZHoKaQtZxGuV2cUPQHMfjKEfg/g6oy7Hm6SKFtA== +"@babel/types@^7.0.0", "@babel/types@^7.18.2", "@babel/types@^7.20.7", "@babel/types@^7.22.15", "@babel/types@^7.22.17", "@babel/types@^7.22.5", "@babel/types@^7.3.3": + version "7.22.17" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.22.17.tgz#f753352c4610ffddf9c8bc6823f9ff03e2303eee" + integrity sha512-YSQPHLFtQNE5xN9tHuZnzu8vPr61wVTBZdfv1meex1NBosa4iT05k/Jw06ddJugi4bk7The/oSwQGFcksmEJQg== dependencies: "@babel/helper-string-parser" "^7.22.5" "@babel/helper-validator-identifier" "^7.22.15" @@ -3598,9 +3598,9 @@ camelcase@^6.0.0: integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== caniuse-lite@^1.0.30001517: - version "1.0.30001527" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001527.tgz#813826554828245ccee776c850566dce12bdeaba" - integrity sha512-YkJi7RwPgWtXVSgK4lG9AHH57nSzvvOp9MesgXmw4Q7n0C3H04L0foHqfxcmSAm5AcWb8dW9AYj2tR7/5GnddQ== + version "1.0.30001532" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001532.tgz#c6a4d5d2da6d2b967f0ee5e12e7f680db6ad2fca" + integrity sha512-FbDFnNat3nMnrROzqrsg314zhqN5LGQ1kyyMk2opcrwGbVGpHRhgCWtAgD5YJUqNAiQ+dklreil/c3Qf1dfCTw== capture-exit@^2.0.0: version "2.0.0" @@ -4392,9 +4392,9 @@ ecc-jsbn@~0.1.1: safer-buffer "^2.1.0" electron-to-chromium@^1.4.477: - version "1.4.509" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.509.tgz#9e276f8fcd70e1dfac541390da56a1ed7eea43d1" - integrity sha512-G5KlSWY0zzhANtX15tkikHl4WB7zil2Y65oT52EZUL194abjUXBZym12Ht7Bhuwm/G3LJFEqMADyv2Cks56dmg== + version "1.4.513" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.513.tgz#41a50bf749aa7d8058ffbf7a131fc3327a7b1675" + integrity sha512-cOB0xcInjm+E5qIssHeXJ29BaUyWpMyFKT5RB3bsLENDheCja0wMkHJyiPl0NBE/VzDI7JDuNEQWhe6RitEUcw== elliptic@6.5.4: version "6.5.4" @@ -4468,7 +4468,7 @@ error-ex@^1.2.0, error-ex@^1.3.1: dependencies: is-arrayish "^0.2.1" -es-abstract@^1.20.4, es-abstract@^1.22.1: +es-abstract@^1.22.1: version "1.22.1" resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.22.1.tgz#8b4e5fc5cefd7f1660f0f8e1a52900dfbc9d9ccc" integrity sha512-ioRRcXMO6OFyRpyzV3kE1IIBd4WG5/kltnzdxSCqoP8CMGs/Li+M1uF5o7lOkZVFjDs+NLesthnF66Pg/0q0Lw== @@ -8937,9 +8937,9 @@ rimraf@^2.6.3: glob "^7.1.3" rollup@^3.28.0: - version "3.29.0" - resolved "https://registry.yarnpkg.com/rollup/-/rollup-3.29.0.tgz#1b40e64818afc979c7e5bef93de675829288986b" - integrity sha512-nszM8DINnx1vSS+TpbWKMkxem0CDWk3cSit/WWCBVs9/JZ1I/XLwOsiUglYuYReaeWWSsW9kge5zE5NZtf/a4w== + version "3.29.1" + resolved "https://registry.yarnpkg.com/rollup/-/rollup-3.29.1.tgz#ba53a179d46ac3cd79e162dca6ab70d93cd26f78" + integrity sha512-c+ebvQz0VIH4KhhCpDsI+Bik0eT8ZFEVZEYw0cGMVqIP8zc+gnwl7iXCamTw7vzv2MeuZFZfdx5JJIq+ehzDlg== optionalDependencies: fsevents "~2.3.2" @@ -9435,22 +9435,22 @@ string-width@^1.0.1: strip-ansi "^6.0.1" string.prototype.trim@^1.2.7: - version "1.2.7" - resolved "https://registry.yarnpkg.com/string.prototype.trim/-/string.prototype.trim-1.2.7.tgz#a68352740859f6893f14ce3ef1bb3037f7a90533" - integrity sha512-p6TmeT1T3411M8Cgg9wBTMRtY2q9+PNy9EV1i2lIXUN/btt763oIfxwN3RR8VU6wHX8j/1CFy0L+YuThm6bgOg== + version "1.2.8" + resolved "https://registry.yarnpkg.com/string.prototype.trim/-/string.prototype.trim-1.2.8.tgz#f9ac6f8af4bd55ddfa8895e6aea92a96395393bd" + integrity sha512-lfjY4HcixfQXOfaqCvcBuOIapyaroTXhbkfJN3gcB1OtyupngWK4sEET9Knd0cXd28kTUqu/kHoV4HKSJdnjiQ== dependencies: call-bind "^1.0.2" - define-properties "^1.1.4" - es-abstract "^1.20.4" + define-properties "^1.2.0" + es-abstract "^1.22.1" string.prototype.trimend@^1.0.6: - version "1.0.6" - resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.6.tgz#c4a27fa026d979d79c04f17397f250a462944533" - integrity sha512-JySq+4mrPf9EsDBEDYMOb/lM7XQLulwg5R/m1r0PXEFqrV0qHvl58sdTilSXtKOflCsK2E8jxf+GKC0T07RWwQ== + version "1.0.7" + resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.7.tgz#1bb3afc5008661d73e2dc015cd4853732d6c471e" + integrity sha512-Ni79DqeB72ZFq1uH/L6zJ+DKZTkOtPIHovb3YZHQViE+HDouuU4mBrLOLDn5Dde3RF8qw5qVETEjhu9locMLvA== dependencies: call-bind "^1.0.2" - define-properties "^1.1.4" - es-abstract "^1.20.4" + define-properties "^1.2.0" + es-abstract "^1.22.1" string.prototype.trimstart@^1.0.6: version "1.0.7"