UNPKG

nkisi

Version:

Command line client for linking to Web Agent lanes over the WARP protocol

1,530 lines (1,502 loc) 1.74 MB
#!/usr/bin/env node (function (factory) { typeof define === 'function' && define.amd ? define(factory) : factory(); }((function () { 'use strict'; var Equals = function (x, y) { if (x === y) { return true; } else if (x !== void 0 && x !== null && typeof x.equals === "function") { return x.equals(y); } return false; }; Equals.is = function (object) { return object !== void 0 && object !== null && typeof object.equals === "function"; }; var HashCode = function (x) { if (x === void 0) { return 0; } else if (x === null) { return 1; } else { return x.hashCode(); } }; HashCode.is = function (object) { return object !== void 0 && object !== null && typeof object.hashCode === "function"; }; var Equivalent = function (x, y, epsilon) { if (x === y) { return true; } else if (x !== void 0 && x !== null && typeof x.equivalentTo === "function") { return x.equivalentTo(y, epsilon); } return false; }; Equivalent.is = function (object) { return object !== void 0 && object !== null && typeof object.equivalentTo === "function"; }; Equivalent.Epsilon = 1.0e-8; var Compare = function (x, y) { if (x === void 0) { if (y === void 0) { return 0; } else { return 1; } } else if (x === null) { if (y === void 0) { return -1; } else if (y === null) { return 0; } else { return 1; } } else if (typeof x.compareTo === "function") { if (y === void 0 || y === null) { return -1; } else { return x.compareTo(y); } } else { return NaN; } }; Compare.is = function (object) { return object !== void 0 && object !== null && typeof object.compareTo === "function"; }; var Lazy = function (target, propertyKey, descriptor) { var writable = descriptor.writable; var enumerable = descriptor.enumerable; var configurable = descriptor.configurable; if (descriptor.get !== void 0) { var get_1 = descriptor.get; descriptor.get = function () { var value = get_1.call(this); Object.defineProperty(target, propertyKey, { value: value, writable: writable, enumerable: enumerable, configurable: configurable, }); return value; }; } else if (descriptor.value !== void 0) { var method_1 = descriptor.value; descriptor.value = function () { var value = method_1.call(this); Object.defineProperty(target, propertyKey, { value: function () { return value; }, writable: writable, enumerable: enumerable, configurable: configurable, }); return value; }; } else { throw new Error("invalid lazy property descriptor"); } }; if (String.prototype.codePointAt === void 0) { String.prototype.codePointAt = function (index) { var size = this.length; index = index ? Number(index) : 0; if (index !== index) { index = 0; } if (index >= 0 && index < size) { var c1 = this.charCodeAt(index); if (c1 <= 0xd7ff || c1 >= 0xe000) { return c1; } else if (c1 <= 0xdbff && index + 1 < size) { var c2 = this.charCodeAt(index + 1); if (c2 >= 0xdc00 && c2 <= 0xdfff) { return ((c1 & 0x03ff) << 10 + c2 & 0x03ff) + 0x10000; } } } return void 0; }; } if (String.prototype.offsetByCodePoints === void 0) { String.prototype.offsetByCodePoints = function (index, count) { if (count > 0) { var size = this.length; while (count > 0 && index < size) { var c1 = this.charCodeAt(index); if (c1 <= 0xd7ff || c1 >= 0xe000) { index += 1; } else if (c1 <= 0xdbff && index + 1 < size) { var c2 = this.charCodeAt(index + 1); if (c2 >= 0xdc00 && c2 <= 0xdfff) { index += 2; } else { index += 1; } } else { index += 1; } count -= 1; } } else if (count < 0) { while (count < 0 && index > 0) { var c2 = this.charCodeAt(index - 1); if (c2 <= 0xd7ff || c2 >= 0xe000) { index -= 1; } else if (c2 >= 0xdc00 && c2 <= 0xdfff && index - 1 > 0) { var c1 = this.charCodeAt(index - 2); if (c1 >= 0xd800 && c1 <= 0xdfff) { index -= 2; } else { index -= 1; } } else { index -= 1; } count -= 1; } } return index; }; } var Random = {}; if (typeof window !== "undefined" && window.crypto !== void 0) { Random.fillBytes = function (array) { window.crypto.getRandomValues(array); }; } else if (typeof window !== "undefined" && window.msCrypto !== void 0) { Random.fillBytes = function (array) { window.msCrypto.getRandomValues(array); }; } else { Random.fillBytes = function (array) { if (array instanceof Int8Array) { for (var i = 0; i < array.length; i += 1) { array[i] = 128 - Math.round(Math.random() * 256); } } else if (array instanceof Uint8Array) { for (var i = 0; i < array.length; i += 1) { array[i] = Math.round(Math.random() * 256); } } else if (array instanceof Int16Array) { for (var i = 0; i < array.length; i += 1) { array[i] = 32768 - Math.round(Math.random() * 65536); } } else if (array instanceof Uint16Array) { for (var i = 0; i < array.length; i += 1) { array[i] = Math.round(Math.random() * 65536); } } else if (array instanceof Int32Array) { for (var i = 0; i < array.length; i += 1) { array[i] = 2147483648 - Math.round(Math.random() * 4294967296); } } else if (array instanceof Uint32Array) { for (var i = 0; i < array.length; i += 1) { array[i] = Math.round(Math.random() * 4294967296); } } else { throw new TypeError("" + array); } }; } var ByteOrder = {}; Object.defineProperty(ByteOrder, "BigEndian", { value: "BE", enumerable: true, }); Object.defineProperty(ByteOrder, "LittleEndian", { value: "LE", enumerable: true, }); Object.defineProperty(ByteOrder, "NativeOrder", { get: function () { var nativeEndian; var bom = new ArrayBuffer(2); new Uint16Array(bom)[0] = 0xfeff; var b = new Uint8Array(bom); if (b[0] === 0xfe && b[1] === 0xff) { nativeEndian = ByteOrder.BigEndian; } else if (b[0] === 0xff && b[1] === 0xfe) { nativeEndian = ByteOrder.LittleEndian; } else { throw new Error(); } Object.defineProperty(ByteOrder, "NativeOrder", { value: nativeEndian, enumerable: true, }); return nativeEndian; }, configurable: true, enumerable: true, }); var Murmur3 = {}; Murmur3.mix = function (code, value) { value = ((value & 0xffff) * 0xcc9e2d51) + (((value >>> 16) * 0xcc9e2d51 & 0xffff) << 16) & 0xffffffff; value = Murmur3.rotl(value, 15); value = ((value & 0xffff) * 0x1b873593) + (((value >>> 16) * 0x1b873593 & 0xffff) << 16) & 0xffffffff; code ^= value; code = Murmur3.rotl(code, 13); code = ((code & 0xffff) * 5) + (((code >>> 16) * 5 & 0xffff) << 16) & 0xffffffff; code = ((code & 0xffff) + 0x6b64) + (((code >>> 16) + 0xe654 & 0xffff) << 16); return code; }; Murmur3.mixUint8Array = function (code, array) { if (ByteOrder.NativeOrder === ByteOrder.BigEndian) { return Murmur3.mixUint8ArrayBE(code, array); } else if (ByteOrder.NativeOrder === ByteOrder.LittleEndian) { return Murmur3.mixUInt8ArrayLE(code, array); } else { throw new Error(); } }; Murmur3.mixUint8ArrayBE = function (code, array) { var offset = 0; var limit = array.length; while (offset + 3 < limit) { var word = (array[offset] & 0xff) << 24 | (array[offset + 1] & 0xff) << 16 | (array[offset + 2] & 0xff) << 8 | array[offset + 3] & 0xff; code = Murmur3.mix(code, word); offset += 4; } if (offset < limit) { var word = (array[offset] & 0xff) << 24; if (offset + 1 < limit) { word |= (array[offset + 1] & 0xff) << 16; if (offset + 2 < limit) { word |= (array[offset + 2] & 0xff) << 8; } } word = ((word & 0xffff) * 0xcc9e2d51) + (((word >>> 16) * 0xcc9e2d51 & 0xffff) << 16) & 0xffffffff; word = Murmur3.rotl(word, 15); word = ((word & 0xffff) * 0x1b873593) + (((word >>> 16) * 0x1b873593 & 0xffff) << 16) & 0xffffffff; code ^= word; } return code ^ limit; }; Murmur3.mixUInt8ArrayLE = function (code, array) { var offset = 0; var limit = array.length; while (offset + 3 < limit) { var word = array[offset] & 0xff | (array[offset + 1] & 0xff) << 8 | (array[offset + 2] & 0xff) << 16 | (array[offset + 3] & 0xff) << 24; code = Murmur3.mix(code, word); offset += 4; } if (offset < limit) { var word = array[offset] & 0xff; if (offset + 1 < limit) { word |= (array[offset + 1] & 0xff) << 8; if (offset + 2 < limit) { word |= (array[offset + 2] & 0xff) << 16; } } word = ((word & 0xffff) * 0xcc9e2d51) + (((word >>> 16) * 0xcc9e2d51 & 0xffff) << 16) & 0xffffffff; word = Murmur3.rotl(word, 15); word = ((word & 0xffff) * 0x1b873593) + (((word >>> 16) * 0x1b873593 & 0xffff) << 16) & 0xffffffff; code ^= word; } return code ^ limit; }; Murmur3.mixString = function (code, string) { if (ByteOrder.NativeOrder === ByteOrder.BigEndian) { return Murmur3.mixStringBE(code, string); } else if (ByteOrder.NativeOrder === ByteOrder.LittleEndian) { return Murmur3.mixStringLE(code, string); } else { throw new Error(); } }; Murmur3.mixStringBE = function (code, string) { var word = 0; var k = 32; var i = 0; var n = string.length; var utf8Length = 0; while (i < n) { var c = string.codePointAt(i); if (c === void 0) { c = string.charCodeAt(i); } if (c >= 0 && c <= 0x7f) { k -= 8; word |= c << k; if (k === 0) { code = Murmur3.mix(code, word); word = 0; k = 32; } utf8Length += 1; } else if (c >= 0x80 && c <= 0x7ff) { k -= 8; word |= (0xc0 | (c >>> 6)) << k; if (k === 0) { code = Murmur3.mix(code, word); word = 0; k = 32; } k -= 8; word |= (0x80 | (c & 0x3f)) << k; if (k === 0) { code = Murmur3.mix(code, word); word = 0; k = 32; } utf8Length += 2; } else if (c >= 0x0800 && c <= 0xffff || c >= 0xe000 && c <= 0xffff) { k -= 8; word |= (0xe0 | (c >>> 12)) << k; if (k === 0) { code = Murmur3.mix(code, word); word = 0; k = 32; } k -= 8; word |= (0x80 | ((c >>> 6) & 0x3f)) << k; if (k === 0) { code = Murmur3.mix(code, word); word = 0; k = 32; } k -= 8; word |= (0x80 | (c & 0x3f)) << k; if (k === 0) { code = Murmur3.mix(code, word); word = 0; k = 32; } utf8Length += 3; } else if (c >= 0x10000 && c <= 0x10ffff) { k -= 8; word |= (0xf0 | (c >>> 18)) << k; if (k === 0) { code = Murmur3.mix(code, word); word = 0; k = 32; } k -= 8; word |= (0x80 | ((c >>> 12) & 0x3f)) << k; if (k === 0) { code = Murmur3.mix(code, word); word = 0; k = 32; } k -= 8; word |= (0x80 | ((c >>> 6) & 0x3f)) << k; if (k === 0) { code = Murmur3.mix(code, word); word = 0; k = 32; } k -= 8; word |= (0x80 | (c & 0x3f)) << k; if (k === 0) { code = Murmur3.mix(code, word); word = 0; k = 32; } utf8Length += 4; } else { k -= 8; word |= 0xef << k; if (k === 0) { code = Murmur3.mix(code, word); word = 0; k = 32; } k -= 8; word |= 0xbf << k; if (k === 0) { code = Murmur3.mix(code, word); word = 0; k = 32; } k -= 8; word |= 0xbd << k; if (k === 0) { code = Murmur3.mix(code, word); word = 0; k = 32; } utf8Length += 3; } i = string.offsetByCodePoints(i, 1); } if (k !== 32) { word = ((word & 0xffff) * 0xcc9e2d51) + (((word >>> 16) * 0xcc9e2d51 & 0xffff) << 16) & 0xffffffff; word = Murmur3.rotl(word, 15); word = ((word & 0xffff) * 0x1b873593) + (((word >>> 16) * 0x1b873593 & 0xffff) << 16) & 0xffffffff; code ^= word; } return code ^ utf8Length; }; Murmur3.mixStringLE = function (code, string) { var word = 0; var k = 0; var i = 0; var n = string.length; var utf8Length = 0; while (i < n) { var c = string.codePointAt(i); if (c === void 0) { c = string.charCodeAt(i); } if (c >= 0 && c <= 0x7f) { word |= c << k; k += 8; if (k === 32) { code = Murmur3.mix(code, word); word = 0; k = 0; } utf8Length += 1; } else if (c >= 0x80 && c <= 0x7ff) { word |= (0xc0 | (c >>> 6)) << k; k += 8; if (k === 32) { code = Murmur3.mix(code, word); word = 0; k = 0; } word |= (0x80 | (c & 0x3f)) << k; k += 8; if (k === 32) { code = Murmur3.mix(code, word); word = 0; k = 0; } utf8Length += 2; } else if (c >= 0x0800 && c <= 0xffff || c >= 0xe000 && c <= 0xffff) { word |= (0xe0 | (c >>> 12)) << k; k += 8; if (k === 32) { code = Murmur3.mix(code, word); word = 0; k = 0; } word |= (0x80 | ((c >>> 6) & 0x3f)) << k; k += 8; if (k === 32) { code = Murmur3.mix(code, word); word = 0; k = 0; } word |= (0x80 | (c & 0x3f)) << k; k += 8; if (k === 32) { code = Murmur3.mix(code, word); word = 0; k = 0; } utf8Length += 3; } else if (c >= 0x10000 && c <= 0x10ffff) { word |= (0xf0 | (c >>> 18)) << k; k += 8; if (k === 32) { code = Murmur3.mix(code, word); word = 0; k = 0; } word |= (0x80 | ((c >>> 12) & 0x3f)) << k; k += 8; if (k === 32) { code = Murmur3.mix(code, word); word = 0; k = 0; } word |= (0x80 | ((c >>> 6) & 0x3f)) << k; k += 8; if (k === 32) { code = Murmur3.mix(code, word); word = 0; k = 0; } word |= (0x80 | (c & 0x3f)) << k; k += 8; if (k === 32) { code = Murmur3.mix(code, word); word = 0; k = 0; } utf8Length += 4; } else { word |= 0xef << k; k += 8; if (k === 32) { code = Murmur3.mix(code, word); word = 0; k = 0; } word |= 0xbf << k; k += 8; if (k === 32) { code = Murmur3.mix(code, word); word = 0; k = 0; } word |= 0xbd << k; k += 8; if (k === 32) { code = Murmur3.mix(code, word); word = 0; k = 0; } utf8Length += 3; } i = string.offsetByCodePoints(i, 1); } if (k !== 32) { word = ((word & 0xffff) * 0xcc9e2d51) + (((word >>> 16) * 0xcc9e2d51 & 0xffff) << 16) & 0xffffffff; word = Murmur3.rotl(word, 15); word = ((word & 0xffff) * 0x1b873593) + (((word >>> 16) * 0x1b873593 & 0xffff) << 16) & 0xffffffff; code ^= word; } return code ^ utf8Length; }; Murmur3.mash = function (code) { code ^= code >>> 16; code = ((code & 0xffff) * 0x85ebca6b) + (((code >>> 16) * 0x85ebca6b & 0xffff) << 16) & 0xffffffff; code ^= code >>> 13; code = ((code & 0xffff) * 0xc2b2ae35) + (((code >>> 16) * 0xc2b2ae35 & 0xffff) << 16) & 0xffffffff; code ^= code >>> 16; return code >>> 0; }; Murmur3.rotl = function (value, distance) { return (value << distance) | (value >>> (32 - distance)); }; var Booleans = {}; Booleans.compare = function (x, y) { if (typeof x === "boolean") { return typeof y === "boolean" ? (x && !y ? -1 : !x && y ? 1 : 0) : -1; } else if (x === null) { return y === void 0 ? -1 : y === null ? 0 : 1; } else if (x === void 0) { return y === void 0 ? 0 : 1; } else { return NaN; } }; Booleans.hash = function (x) { if (x === true) { return 3; } else if (x === false) { return 2; } else if (x === null) { return 1; } else if (x === void 0) { return 0; } else { throw new TypeError("" + x); } }; var Numbers = {}; Numbers.equal = function (x, y) { return x === y || typeof x === "number" && typeof y === "number" && isNaN(x) && isNaN(y); }; Numbers.equivalent = function (x, y, epsilon) { return x === y || typeof x === "number" && typeof y === "number" && (isNaN(x) && isNaN(y) || Math.abs(y - x) < (epsilon !== void 0 ? epsilon : Equivalent.Epsilon)); }; Numbers.compare = function (x, y) { if (typeof x === "number") { return typeof y === "number" ? (x < y ? -1 : x > y ? 1 : isNaN(y) ? (isNaN(x) ? 0 : -1) : isNaN(x) ? 1 : 0) : -1; } else if (x === null) { return y === void 0 ? -1 : y === null ? 0 : 1; } else if (x === void 0) { return y === void 0 ? 0 : 1; } else { return NaN; } }; Numbers.hash = (function () { var hashArrayBuffer = new ArrayBuffer(8); var hashFloat64Array = new Float64Array(hashArrayBuffer); var hashInt32Array = new Int32Array(hashArrayBuffer); return function (x) { if (typeof x === "number") { if (x === ~~x) { return ~~x; } else { hashFloat64Array[0] = x; return hashInt32Array[0] ^ hashInt32Array[1]; } } else if (x === null) { return 1; } else if (x === void 0) { return 0; } else { throw new TypeError("" + x); } }; })(); var Strings = {}; Strings.compare = function (x, y) { if (typeof x === "string") { return typeof y === "string" ? (x < y ? -1 : x > y ? 1 : 0) : -1; } else if (x === null) { return y === void 0 ? -1 : y === null ? 0 : 1; } else if (x === void 0) { return y === void 0 ? 0 : 1; } else { return NaN; } }; Strings.hash = function (x) { if (typeof x === "string") { return Murmur3.mash(Murmur3.mixString(0, x)); } else if (x === null) { return 1; } else if (x === void 0) { return 0; } else { throw new TypeError("" + x); } }; var Functions = {}; Functions.compare = function (x, y) { if (typeof x === "function") { if (typeof y === "function") { var xh = Functions.hash(x); var yh = Functions.hash(y); return xh < yh ? -1 : xh > yh ? 1 : 0; } else { return -1; } } else if (x === null) { return y === void 0 ? -1 : y === null ? 0 : 1; } else if (x === void 0) { return y === void 0 ? 0 : 1; } else { return NaN; } }; Functions.hash = (function () { var nextId = -1; return function (x) { if (typeof x === "function") { var hashCode = x._hashCode; if (hashCode === void 0) { hashCode = ~~nextId; nextId -= 1; Object.defineProperty(x, "_hashCode", { value: hashCode, configurable: true, }); } return hashCode; } else if (x === null) { return 1; } else if (x === void 0) { return 0; } else { throw new TypeError("" + x); } }; })(); var Constructors = {}; Constructors.compare = function (x, y) { if (typeof x === "function") { if (typeof y === "function") { var xh = Constructors.hash(x); var yh = Constructors.hash(y); return xh < yh ? -1 : xh > yh ? 1 : 0; } else { return -1; } } else if (x === null) { return y === void 0 ? -1 : y === null ? 0 : 1; } else if (x === void 0) { return y === void 0 ? 0 : 1; } else { return NaN; } }; Constructors.hash = function (x) { if (typeof x === "function") { var hashCode = x._hashCode; if (hashCode === void 0) { hashCode = Murmur3.mash(Murmur3.mixString(0, x.name)); Object.defineProperty(x, "_hashCode", { value: hashCode, configurable: true, }); } return hashCode; } else if (x === null) { return 1; } else if (x === void 0) { return 0; } else { throw new TypeError("" + x); } }; var Objects = {}; Objects.equal = function (x, y) { if (x === y) { return true; } else if (typeof x === "object" && x !== null && typeof y === "object" && y !== null) { var xKeys = Object.keys(x); var yKeys = Object.keys(y); var n = xKeys.length; if (n !== yKeys.length) { return false; } for (var i = 0; i < n; i += 1) { var key = xKeys[i]; if (key !== yKeys[i] || !Values.equal(x[key], y[key])) { return false; } } return true; } return false; }; Objects.equivalent = function (x, y, epsilon) { if (x === y) { return true; } else if (typeof x === "object" && x !== null && typeof y === "object" && y !== null) { var xKeys = Object.keys(x); var yKeys = Object.keys(y); var n = xKeys.length; if (n !== yKeys.length) { return false; } for (var i = 0; i < n; i += 1) { var key = xKeys[i]; if (key !== yKeys[i] || !Values.equivalent(x[key], y[key], epsilon)) { return false; } } return true; } return false; }; Objects.compare = function (x, y) { if (typeof x === "object" && x !== null) { if (typeof y === "object" && y !== null) { if (x !== y) { var xKeys = Object.keys(x); var yKeys = Object.keys(y); var p = xKeys.length; var q = yKeys.length; var n = Math.min(p, q); var order = 0; for (var i = 0; i < n && order === 0; i += 1) { var xKey = xKeys[i]; var yKey = yKeys[i]; order = Strings.compare(xKey, yKey); if (order === 0) { order = Values.compare(x[xKey], y[yKey]); } } return order !== 0 ? order : p > q ? 1 : p < q ? -1 : 0; } else { return 0; } } else { return -1; } } else if (x === null) { return y === void 0 ? -1 : y === null ? 0 : 1; } else if (x === void 0) { return y === void 0 ? 0 : 1; } else { return NaN; } }; Objects.hash = function (x) { if (typeof x === "object" && x !== null) { var hashValue = 0; var keys = Object.keys(x); for (var i = 0, n = keys.length; i < n; i += 1) { var key = keys[i]; hashValue = Murmur3.mix(Murmur3.mix(hashValue, Strings.hash(key)), Values.hash(x[key])); } return Murmur3.mash(hashValue); } else if (x === null) { return 1; } else if (x === void 0) { return 0; } else { throw new TypeError("" + x); } }; var Values = {}; Values.equal = function (x, y) { if (x instanceof Date) { x = x.getTime(); } if (y instanceof Date) { y = y.getTime(); } if (x === y) { return true; } else if (typeof x === "number") { if (typeof y === "number") { return isNaN(x) && isNaN(y); } } else if (Equals.is(x)) { return x.equals(y); } else if (Array.isArray(x)) { if (Array.isArray(y)) { return Arrays.equal(x, y); } } else if (typeof x === "object" && x !== null) { if (typeof y === "object" && y !== null) { return Objects.equal(x, y); } } return false; }; Values.hash = function (x) { if (x === void 0) { return 0; } else if (x === null) { return 1; } else if (x === false) { return 2; } else if (x === true) { return 3; } else if (typeof x === "number") { return Numbers.hash(x); } else if (typeof x === "string") { return Strings.hash(x); } else if (HashCode.is(x)) { return x.hashCode(); } else if (typeof x === "function") { return Functions.hash(x); } else if (Array.isArray(x)) { return Arrays.hash(x); } else if (typeof x === "object") { return Objects.hash(x); } else { throw new TypeError("" + x); } }; Values.equivalent = function (x, y, epsilon) { if (epsilon === void 0) { epsilon = Equivalent.Epsilon; } if (x instanceof Date) { x = x.getTime(); } if (y instanceof Date) { y = y.getTime(); } if (x === y) { return true; } else if (typeof x === "number") { if (typeof y === "number") { return isNaN(x) && isNaN(y) || Math.abs(y - x) < epsilon; } } else if (Equivalent.is(x)) { return x.equivalentTo(y, epsilon); } else if (Array.isArray(x)) { if (Array.isArray(y)) { return Arrays.equivalent(x, y, epsilon); } } else if (typeof x === "object" && x !== null) { if (typeof y === "object" && y !== null) { return Objects.equivalent(x, y, epsilon); } } return false; }; Values.compare = function (x, y) { if (x instanceof Date) { x = x.getTime(); } if (y instanceof Date) { y = y.getTime(); } if (x === void 0) { if (y === void 0) { return 0; } else { return 1; } } else if (x === null) { if (y === void 0) { return -1; } else if (y === null) { return 0; } else { return 1; } } else if (typeof x === "boolean") { if (y === void 0 || y === null) { return -1; } else if (typeof y === "boolean") { return x && !y ? -1 : !x && y ? 1 : 0; } else { return 1; } } else if (typeof x === "number") { if (y === void 0 || y === null || typeof y === "boolean") { return -1; } else if (typeof y === "number") { return x < y ? -1 : x > y ? 1 : isNaN(y) ? (isNaN(x) ? 0 : -1) : isNaN(x) ? 1 : 0; } else { return 1; } } else if (typeof x === "string") { if (y === void 0 || y === null || typeof y === "boolean" || typeof y === "number") { return -1; } else if (typeof y === "string") { return x < y ? -1 : x > y ? 1 : 0; } else { return 1; } } else if (Compare.is(x)) { return x.compareTo(y); } else if (typeof x === "function") { if (y === void 0 || y === null || typeof y === "boolean" || typeof y === "number" || typeof y === "string") { return -1; } else if (typeof y === "function") { return Functions.compare(x, y); } else { return 1; } } else if (Array.isArray(x)) { if (y === void 0 || y === null || typeof y === "boolean" || typeof y === "number" || typeof y === "string" || typeof y === "function") { return -1; } else if (Array.isArray(y)) { return Arrays.compare(x, y); } else { return 1; } } else if (typeof x === "object") { if (y === void 0 || y === null || typeof y === "boolean" || typeof y === "number" || typeof y === "string" || typeof y === "function" || Array.isArray(y)) { return -1; } else if (typeof y === "object") { return Objects.compare(x, y); } else { return 1; } } else { return NaN; } }; var Arrays = {}; Object.defineProperty(Arrays, "empty", { value: Object.freeze([]), enumerable: true, configurable: true, }); Arrays.inserted = function (newElement, oldArray) { var n = oldArray !== void 0 && oldArray !== null ? oldArray.length : 0; var newArray = new Array(n + 1); for (var i = 0; i < n; i += 1) { var element = oldArray[i]; if (element !== newElement) { newArray[i] = element; } else { return oldArray; } } newArray[n] = newElement; return newArray; }; Arrays.removed = function (oldElement, oldArray) { var n = oldArray !== void 0 && oldArray !== null ? oldArray.length : 0; if (n === 0) { return oldArray !== void 0 && oldArray !== null ? oldArray : Arrays.empty; } else if (n === 1) { return oldArray[0] !== oldElement ? oldArray : Arrays.empty; } else { var newArray = new Array(n - 1); var i = 0; while (i < n) { var element = oldArray[i]; if (element !== oldElement) { newArray[i] = element; i += 1; } else { i += 1; while (i < n) { newArray[i - 1] = oldArray[i]; i += 1; } return newArray; } } return oldArray; } }; Arrays.equal = function (x, y) { if (x === y) { return true; } else if (typeof x === "object" && x !== null && typeof y === "object" && y !== null) { var n = x.length; if (n !== y.length) { return false; } for (var i = 0; i < n; i += 1) { if (!Values.equal(x[i], y[i])) { return false; } } return true; } return false; }; Arrays.equivalent = function (x, y, epsilon) { if (x === y) { return true; } else if (typeof x === "object" && x !== null && typeof y === "object" && y !== null) { var n = x.length; if (n !== y.length) { return false; } for (var i = 0; i < n; i += 1) { if (!Values.equivalent(x[i], y[i], epsilon)) { return false; } } return true; } return false; }; Arrays.compare = function (x, y) { if (typeof x === "object" && x !== null) { if (typeof y === "object" && y !== null) { if (x !== y) { var p = x.length; var q = y.length; var order = 0; for (var i = 0, n = Math.min(p, q); i < n && order === 0; i += 1) { order = Values.compare(x[i], y[i]); } return order !== 0 ? order : p > q ? 1 : p < q ? -1 : 0; } else { return 0; } } else { return -1; } } else if (x === null) { return y === void 0 ? -1 : y === null ? 0 : 1; } else if (x === void 0) { return y === void 0 ? 0 : 1; } else { return NaN; } }; Arrays.hash = function (x) { if (typeof x === "object" && x !== null) { var hashValue = 0; for (var i = 0, n = x.length; i < n; i += 1) { hashValue = Murmur3.mix(hashValue, Values.hash(x[i])); } return Murmur3.mash(hashValue); } else if (x === null) { return 1; } else if (x === void 0) { return 0; } else { throw new TypeError("" + x); } }; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise */ 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); }; function __extends(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 __()); } function __decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } function __spreadArray(to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || from); } var Cursor = (function () { function Cursor() { } Cursor.prototype.set = function (newValue) { throw new Error("immutable"); }; Cursor.prototype.delete = function () { throw new Error("immutable"); }; Cursor.empty = function () { return new CursorEmpty(); }; Cursor.unary = function (value) { return new CursorUnary(value); }; Cursor.array = function (array, index, limit) { if (index === void 0) { index = 0; } if (limit === void 0) { limit = array.length; } return new CursorArray(array, index, limit); }; __decorate([ Lazy ], Cursor, "empty", null); return Cursor; }()); var CursorEmpty = (function (_super) { __extends(CursorEmpty, _super); function CursorEmpty() { return _super !== null && _super.apply(this, arguments) || this; } CursorEmpty.prototype.isEmpty = function () { return true; }; CursorEmpty.prototype.head = function () { throw new Error("empty"); }; CursorEmpty.prototype.step = function () { throw new Error("empty"); }; CursorEmpty.prototype.skip = function (count) { }; CursorEmpty.prototype.hasNext = function () { return false; }; CursorEmpty.prototype.nextIndex = function () { return 0; }; CursorEmpty.prototype.next = function () { return { done: true }; }; CursorEmpty.prototype.hasPrevious = function () { return false; }; CursorEmpty.prototype.previousIndex = function () { return -1; }; CursorEmpty.prototype.previous = function () { return { done: true }; }; return CursorEmpty; }(Cursor)); var CursorUnary = (function (_super) { __extends(CursorUnary, _super); function CursorUnary(value) { var _this = _super.call(this) || this; Object.defineProperty(_this, "value", { value: value, }); Object.defineProperty(_this, "index", { value: 0, configurable: true, }); return _this; } CursorUnary.prototype.isEmpty = function () { return this.index !== 0; }; CursorUnary.prototype.head = function () { if (this.index === 0) { return this.value; } else { throw new Error("empty"); } }; CursorUnary.prototype.step = function () { if (this.index === 0) { Object.defineProperty(this, "index", { value: 1, configurable: true, }); } else { throw new Error("empty"); } }; CursorUnary.prototype.skip = function (count) { this.index = Math.min(Math.max(0, this.index + count), 1); }; CursorUnary.prototype.hasNext = function () { return this.index === 0; }; CursorUnary.prototype.nextIndex = function () { return this.index; }; CursorUnary.prototype.next = function () { if (this.index === 0) { Object.defineProperty(this, "index", { value: 1, configurable: true, }); return { value: this.value, done: true }; } else { return { done: true }; } }; CursorUnary.prototype.hasPrevious = function () { return this.index === 1; }; CursorUnary.prototype.previousIndex = function () { return this.index - 1; }; CursorUnary.prototype.previous = function () { if (this.index === 1) { Object.defineProperty(this, "index", { value: 0, configurable: true, }); return { value: this.value, done: true }; } else { return { done: true }; } }; return CursorUnary; }(Cursor)); var CursorArray = (function (_super) { __extends(CursorArray, _super); function CursorArray(array, index, limit) { var _this = _super.call(this) || this; Object.defineProperty(_this, "array", { value: array, }); Object.defineProperty(_this, "index", { value: index, configurable: true, }); Object.defineProperty(_this, "limit", { value: limit, }); return _this; } CursorArray.prototype.isEmpty = function () { return this.index >= this.limit; }; CursorArray.prototype.head = function () { if (this.index < this.limit) { return this.array[this.index]; } else { throw new Error("empty"); } }; CursorArray.prototype.step = function () { var index = this.index; if (index < this.limit) { Object.defineProperty(this, "index", { value: index + 1, configurable: true, }); } else { throw new Error("empty"); } }; CursorArray.prototype.skip = function (count) { Object.defineProperty(this, "index", { value: Math.min(this.index + count, this.limit), configurable: true, }); }; CursorArray.prototype.hasNext = function () { return this.index < this.limit; }; CursorArray.prototype.nextIndex = function () { return this.index; }; CursorArray.prototype.next = function () { var index = this.index; if (index < this.limit) { Object.defineProperty(this, "index", { value: index + 1, configurable: true, }); return { value: this.array[index], done: this.index === this.limit }; } else { Object.defineProperty(this, "index", { value: this.limit, configurable: true, }); return { done: true }; } }; CursorArray.prototype.hasPrevious = function () { return this.index > 0; }; CursorArray.prototyp