UNPKG

@convergence/convergence

Version:
1,670 lines (1,442 loc) 963 kB
/**! Copyright © 2016-2020 - Convergence Labs, Inc. @version 1.0.0-rc.12 @license Licensed under the terms of the GNU Lesser General Public License version 3 (GPLv3). See https://www.gnu.org/licenses/lgpl-3.0.html */ var Convergence = /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 44); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports) { module.exports = rxjs.operators; /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /** * Various utility functions. * @namespace */ var util = module.exports = __webpack_require__(2); var roots = __webpack_require__(16); var Type, // cyclic Enum; util.codegen = __webpack_require__(41); util.fetch = __webpack_require__(42); util.path = __webpack_require__(43); /** * Node's fs module if available. * @type {Object.<string,*>} */ util.fs = util.inquire("fs"); /** * Converts an object's values to an array. * @param {Object.<string,*>} object Object to convert * @returns {Array.<*>} Converted array */ util.toArray = function toArray(object) { if (object) { var keys = Object.keys(object), array = new Array(keys.length), index = 0; while (index < keys.length) array[index] = object[keys[index++]]; return array; } return []; }; /** * Converts an array of keys immediately followed by their respective value to an object, omitting undefined values. * @param {Array.<*>} array Array to convert * @returns {Object.<string,*>} Converted object */ util.toObject = function toObject(array) { var object = {}, index = 0; while (index < array.length) { var key = array[index++], val = array[index++]; if (val !== undefined) object[key] = val; } return object; }; var safePropBackslashRe = /\\/g, safePropQuoteRe = /"/g; /** * Tests whether the specified name is a reserved word in JS. * @param {string} name Name to test * @returns {boolean} `true` if reserved, otherwise `false` */ util.isReserved = function isReserved(name) { return /^(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$/.test(name); }; /** * Returns a safe property accessor for the specified property name. * @param {string} prop Property name * @returns {string} Safe accessor */ util.safeProp = function safeProp(prop) { if (!/^[$\w_]+$/.test(prop) || util.isReserved(prop)) return "[\"" + prop.replace(safePropBackslashRe, "\\\\").replace(safePropQuoteRe, "\\\"") + "\"]"; return "." + prop; }; /** * Converts the first character of a string to upper case. * @param {string} str String to convert * @returns {string} Converted string */ util.ucFirst = function ucFirst(str) { return str.charAt(0).toUpperCase() + str.substring(1); }; var camelCaseRe = /_([a-z])/g; /** * Converts a string to camel case. * @param {string} str String to convert * @returns {string} Converted string */ util.camelCase = function camelCase(str) { return str.substring(0, 1) + str.substring(1) .replace(camelCaseRe, function($0, $1) { return $1.toUpperCase(); }); }; /** * Compares reflected fields by id. * @param {Field} a First field * @param {Field} b Second field * @returns {number} Comparison value */ util.compareFieldsById = function compareFieldsById(a, b) { return a.id - b.id; }; /** * Decorator helper for types (TypeScript). * @param {Constructor<T>} ctor Constructor function * @param {string} [typeName] Type name, defaults to the constructor's name * @returns {Type} Reflected type * @template T extends Message<T> * @property {Root} root Decorators root */ util.decorateType = function decorateType(ctor, typeName) { /* istanbul ignore if */ if (ctor.$type) { if (typeName && ctor.$type.name !== typeName) { util.decorateRoot.remove(ctor.$type); ctor.$type.name = typeName; util.decorateRoot.add(ctor.$type); } return ctor.$type; } /* istanbul ignore next */ if (!Type) Type = __webpack_require__(18); var type = new Type(typeName || ctor.name); util.decorateRoot.add(type); type.ctor = ctor; // sets up .encode, .decode etc. Object.defineProperty(ctor, "$type", { value: type, enumerable: false }); Object.defineProperty(ctor.prototype, "$type", { value: type, enumerable: false }); return type; }; var decorateEnumIndex = 0; /** * Decorator helper for enums (TypeScript). * @param {Object} object Enum object * @returns {Enum} Reflected enum */ util.decorateEnum = function decorateEnum(object) { /* istanbul ignore if */ if (object.$type) return object.$type; /* istanbul ignore next */ if (!Enum) Enum = __webpack_require__(3); var enm = new Enum("Enum" + decorateEnumIndex++, object); util.decorateRoot.add(enm); Object.defineProperty(object, "$type", { value: enm, enumerable: false }); return enm; }; /** * Sets the value of a property by property path. If a value already exists, it is turned to an array * @param {Object.<string,*>} dst Destination object * @param {string} path dot '.' delimited path of the property to set * @param {Object} value the value to set * @returns {Object.<string,*>} Destination object */ util.setProperty = function setProperty(dst, path, value) { function setProp(dst, path, value) { var part = path.shift(); if (path.length > 0) { dst[part] = setProp(dst[part] || {}, path, value); } else { var prevValue = dst[part]; if (prevValue) value = [].concat(prevValue).concat(value); dst[part] = value; } return dst; } if (typeof dst !== "object") throw TypeError("dst must be an object"); if (!path) throw TypeError("path must be specified"); path = path.split("."); return setProp(dst, path, value); }; /** * Decorator root (TypeScript). * @name util.decorateRoot * @type {Root} * @readonly */ Object.defineProperty(util, "decorateRoot", { get: function() { return roots["decorated"] || (roots["decorated"] = new (__webpack_require__(26))()); } }); /***/ }), /* 2 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /* WEBPACK VAR INJECTION */(function(global) { var util = exports; // used to return a Promise where callback is omitted util.asPromise = __webpack_require__(13); // converts to / from base64 encoded strings util.base64 = __webpack_require__(32); // base class of rpc.Service util.EventEmitter = __webpack_require__(33); // float handling accross browsers util.float = __webpack_require__(34); // requires modules optionally and hides the call from bundlers util.inquire = __webpack_require__(14); // converts to / from utf8 encoded strings util.utf8 = __webpack_require__(35); // provides a node-like buffer pool in the browser util.pool = __webpack_require__(36); // utility to work with the low and high bits of a 64 bit value util.LongBits = __webpack_require__(37); /** * Whether running within node or not. * @memberof util * @type {boolean} */ util.isNode = Boolean(typeof global !== "undefined" && global && global.process && global.process.versions && global.process.versions.node); /** * Global object reference. * @memberof util * @type {Object} */ util.global = util.isNode && global || typeof window !== "undefined" && window || typeof self !== "undefined" && self || this; // eslint-disable-line no-invalid-this /** * An immuable empty array. * @memberof util * @type {Array.<*>} * @const */ util.emptyArray = Object.freeze ? Object.freeze([]) : /* istanbul ignore next */ []; // used on prototypes /** * An immutable empty object. * @type {Object} * @const */ util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next */ {}; // used on prototypes /** * Tests if the specified value is an integer. * @function * @param {*} value Value to test * @returns {boolean} `true` if the value is an integer */ util.isInteger = Number.isInteger || /* istanbul ignore next */ function isInteger(value) { return typeof value === "number" && isFinite(value) && Math.floor(value) === value; }; /** * Tests if the specified value is a string. * @param {*} value Value to test * @returns {boolean} `true` if the value is a string */ util.isString = function isString(value) { return typeof value === "string" || value instanceof String; }; /** * Tests if the specified value is a non-null object. * @param {*} value Value to test * @returns {boolean} `true` if the value is a non-null object */ util.isObject = function isObject(value) { return value && typeof value === "object"; }; /** * Checks if a property on a message is considered to be present. * This is an alias of {@link util.isSet}. * @function * @param {Object} obj Plain object or message instance * @param {string} prop Property name * @returns {boolean} `true` if considered to be present, otherwise `false` */ util.isset = /** * Checks if a property on a message is considered to be present. * @param {Object} obj Plain object or message instance * @param {string} prop Property name * @returns {boolean} `true` if considered to be present, otherwise `false` */ util.isSet = function isSet(obj, prop) { var value = obj[prop]; if (value != null && obj.hasOwnProperty(prop)) // eslint-disable-line eqeqeq, no-prototype-builtins return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0; return false; }; /** * Any compatible Buffer instance. * This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings. * @interface Buffer * @extends Uint8Array */ /** * Node's Buffer class if available. * @type {Constructor<Buffer>} */ util.Buffer = (function() { try { var Buffer = util.inquire("buffer").Buffer; // refuse to use non-node buffers if not explicitly assigned (perf reasons): return Buffer.prototype.utf8Write ? Buffer : /* istanbul ignore next */ null; } catch (e) { /* istanbul ignore next */ return null; } })(); // Internal alias of or polyfull for Buffer.from. util._Buffer_from = null; // Internal alias of or polyfill for Buffer.allocUnsafe. util._Buffer_allocUnsafe = null; /** * Creates a new buffer of whatever type supported by the environment. * @param {number|number[]} [sizeOrArray=0] Buffer size or number array * @returns {Uint8Array|Buffer} Buffer */ util.newBuffer = function newBuffer(sizeOrArray) { /* istanbul ignore next */ return typeof sizeOrArray === "number" ? util.Buffer ? util._Buffer_allocUnsafe(sizeOrArray) : new util.Array(sizeOrArray) : util.Buffer ? util._Buffer_from(sizeOrArray) : typeof Uint8Array === "undefined" ? sizeOrArray : new Uint8Array(sizeOrArray); }; /** * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`. * @type {Constructor<Uint8Array>} */ util.Array = typeof Uint8Array !== "undefined" ? Uint8Array /* istanbul ignore next */ : Array; /** * Any compatible Long instance. * This is a minimal stand-alone definition of a Long instance. The actual type is that exported by long.js. * @interface Long * @property {number} low Low bits * @property {number} high High bits * @property {boolean} unsigned Whether unsigned or not */ /** * Long.js's Long class if available. * @type {Constructor<Long>} */ util.Long = /* istanbul ignore next */ util.global.dcodeIO && /* istanbul ignore next */ util.global.dcodeIO.Long || /* istanbul ignore next */ util.global.Long || util.inquire("long"); /** * Regular expression used to verify 2 bit (`bool`) map keys. * @type {RegExp} * @const */ util.key2Re = /^true|false|0|1$/; /** * Regular expression used to verify 32 bit (`int32` etc.) map keys. * @type {RegExp} * @const */ util.key32Re = /^-?(?:0|[1-9][0-9]*)$/; /** * Regular expression used to verify 64 bit (`int64` etc.) map keys. * @type {RegExp} * @const */ util.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/; /** * Converts a number or long to an 8 characters long hash string. * @param {Long|number} value Value to convert * @returns {string} Hash */ util.longToHash = function longToHash(value) { return value ? util.LongBits.from(value).toHash() : util.LongBits.zeroHash; }; /** * Converts an 8 characters long hash string to a long or number. * @param {string} hash Hash * @param {boolean} [unsigned=false] Whether unsigned or not * @returns {Long|number} Original value */ util.longFromHash = function longFromHash(hash, unsigned) { var bits = util.LongBits.fromHash(hash); if (util.Long) return util.Long.fromBits(bits.lo, bits.hi, unsigned); return bits.toNumber(Boolean(unsigned)); }; /** * Merges the properties of the source object into the destination object. * @memberof util * @param {Object.<string,*>} dst Destination object * @param {Object.<string,*>} src Source object * @param {boolean} [ifNotSet=false] Merges only if the key is not already set * @returns {Object.<string,*>} Destination object */ function merge(dst, src, ifNotSet) { // used by converters for (var keys = Object.keys(src), i = 0; i < keys.length; ++i) if (dst[keys[i]] === undefined || !ifNotSet) dst[keys[i]] = src[keys[i]]; return dst; } util.merge = merge; /** * Converts the first character of a string to lower case. * @param {string} str String to convert * @returns {string} Converted string */ util.lcFirst = function lcFirst(str) { return str.charAt(0).toLowerCase() + str.substring(1); }; /** * Creates a custom error constructor. * @memberof util * @param {string} name Error name * @returns {Constructor<Error>} Custom error constructor */ function newError(name) { function CustomError(message, properties) { if (!(this instanceof CustomError)) return new CustomError(message, properties); // Error.call(this, message); // ^ just returns a new error instance because the ctor can be called as a function Object.defineProperty(this, "message", { get: function() { return message; } }); /* istanbul ignore next */ if (Error.captureStackTrace) // node Error.captureStackTrace(this, CustomError); else Object.defineProperty(this, "stack", { value: new Error().stack || "" }); if (properties) merge(this, properties); } (CustomError.prototype = Object.create(Error.prototype)).constructor = CustomError; Object.defineProperty(CustomError.prototype, "name", { get: function() { return name; } }); CustomError.prototype.toString = function toString() { return this.name + ": " + this.message; }; return CustomError; } util.newError = newError; /** * Constructs a new protocol error. * @classdesc Error subclass indicating a protocol specifc error. * @memberof util * @extends Error * @template T extends Message<T> * @constructor * @param {string} message Error message * @param {Object.<string,*>} [properties] Additional properties * @example * try { * MyMessage.decode(someBuffer); // throws if required fields are missing * } catch (e) { * if (e instanceof ProtocolError && e.instance) * console.log("decoded so far: " + JSON.stringify(e.instance)); * } */ util.ProtocolError = newError("ProtocolError"); /** * So far decoded message instance. * @name util.ProtocolError#instance * @type {Message<T>} */ /** * A OneOf getter as returned by {@link util.oneOfGetter}. * @typedef OneOfGetter * @type {function} * @returns {string|undefined} Set field name, if any */ /** * Builds a getter for a oneof's present field name. * @param {string[]} fieldNames Field names * @returns {OneOfGetter} Unbound getter */ util.oneOfGetter = function getOneOf(fieldNames) { var fieldMap = {}; for (var i = 0; i < fieldNames.length; ++i) fieldMap[fieldNames[i]] = 1; /** * @returns {string|undefined} Set field name, if any * @this Object * @ignore */ return function() { // eslint-disable-line consistent-return for (var keys = Object.keys(this), i = keys.length - 1; i > -1; --i) if (fieldMap[keys[i]] === 1 && this[keys[i]] !== undefined && this[keys[i]] !== null) return keys[i]; }; }; /** * A OneOf setter as returned by {@link util.oneOfSetter}. * @typedef OneOfSetter * @type {function} * @param {string|undefined} value Field name * @returns {undefined} */ /** * Builds a setter for a oneof's present field name. * @param {string[]} fieldNames Field names * @returns {OneOfSetter} Unbound setter */ util.oneOfSetter = function setOneOf(fieldNames) { /** * @param {string} name Field name * @returns {undefined} * @this Object * @ignore */ return function(name) { for (var i = 0; i < fieldNames.length; ++i) if (fieldNames[i] !== name) delete this[fieldNames[i]]; }; }; /** * Default conversion options used for {@link Message#toJSON} implementations. * * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely: * * - Longs become strings * - Enums become string keys * - Bytes become base64 encoded strings * - (Sub-)Messages become plain objects * - Maps become plain objects with all string keys * - Repeated fields become arrays * - NaN and Infinity for float and double fields become strings * * @type {IConversionOptions} * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json */ util.toJSONOptions = { longs: String, enums: String, bytes: String, json: true }; // Sets up buffer utility according to the environment (called in index-minimal) util._configure = function() { var Buffer = util.Buffer; /* istanbul ignore if */ if (!Buffer) { util._Buffer_from = util._Buffer_allocUnsafe = null; return; } // because node 4.x buffers are incompatible & immutable // see: https://github.com/dcodeIO/protobuf.js/pull/665 util._Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from || /* istanbul ignore next */ function Buffer_from(value, encoding) { return new Buffer(value, encoding); }; util._Buffer_allocUnsafe = Buffer.allocUnsafe || /* istanbul ignore next */ function Buffer_allocUnsafe(size) { return new Buffer(size); }; }; /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(31))) /***/ }), /* 3 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; module.exports = Enum; // extends ReflectionObject var ReflectionObject = __webpack_require__(5); ((Enum.prototype = Object.create(ReflectionObject.prototype)).constructor = Enum).className = "Enum"; var Namespace = __webpack_require__(7), util = __webpack_require__(1); /** * Constructs a new enum instance. * @classdesc Reflected enum. * @extends ReflectionObject * @constructor * @param {string} name Unique name within its namespace * @param {Object.<string,number>} [values] Enum values as an object, by name * @param {Object.<string,*>} [options] Declared options * @param {string} [comment] The comment for this enum * @param {Object.<string,string>} [comments] The value comments for this enum */ function Enum(name, values, options, comment, comments) { ReflectionObject.call(this, name, options); if (values && typeof values !== "object") throw TypeError("values must be an object"); /** * Enum values by id. * @type {Object.<number,string>} */ this.valuesById = {}; /** * Enum values by name. * @type {Object.<string,number>} */ this.values = Object.create(this.valuesById); // toJSON, marker /** * Enum comment text. * @type {string|null} */ this.comment = comment; /** * Value comment texts, if any. * @type {Object.<string,string>} */ this.comments = comments || {}; /** * Reserved ranges, if any. * @type {Array.<number[]|string>} */ this.reserved = undefined; // toJSON // Note that values inherit valuesById on their prototype which makes them a TypeScript- // compatible enum. This is used by pbts to write actual enum definitions that work for // static and reflection code alike instead of emitting generic object definitions. if (values) for (var keys = Object.keys(values), i = 0; i < keys.length; ++i) if (typeof values[keys[i]] === "number") // use forward entries only this.valuesById[ this.values[keys[i]] = values[keys[i]] ] = keys[i]; } /** * Enum descriptor. * @interface IEnum * @property {Object.<string,number>} values Enum values * @property {Object.<string,*>} [options] Enum options */ /** * Constructs an enum from an enum descriptor. * @param {string} name Enum name * @param {IEnum} json Enum descriptor * @returns {Enum} Created enum * @throws {TypeError} If arguments are invalid */ Enum.fromJSON = function fromJSON(name, json) { var enm = new Enum(name, json.values, json.options, json.comment, json.comments); enm.reserved = json.reserved; return enm; }; /** * Converts this enum to an enum descriptor. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options * @returns {IEnum} Enum descriptor */ Enum.prototype.toJSON = function toJSON(toJSONOptions) { var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false; return util.toObject([ "options" , this.options, "values" , this.values, "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined, "comment" , keepComments ? this.comment : undefined, "comments" , keepComments ? this.comments : undefined ]); }; /** * Adds a value to this enum. * @param {string} name Value name * @param {number} id Value id * @param {string} [comment] Comment, if any * @returns {Enum} `this` * @throws {TypeError} If arguments are invalid * @throws {Error} If there is already a value with this name or id */ Enum.prototype.add = function add(name, id, comment) { // utilized by the parser but not by .fromJSON if (!util.isString(name)) throw TypeError("name must be a string"); if (!util.isInteger(id)) throw TypeError("id must be an integer"); if (this.values[name] !== undefined) throw Error("duplicate name '" + name + "' in " + this); if (this.isReservedId(id)) throw Error("id " + id + " is reserved in " + this); if (this.isReservedName(name)) throw Error("name '" + name + "' is reserved in " + this); if (this.valuesById[id] !== undefined) { if (!(this.options && this.options.allow_alias)) throw Error("duplicate id " + id + " in " + this); this.values[name] = id; } else this.valuesById[this.values[name] = id] = name; this.comments[name] = comment || null; return this; }; /** * Removes a value from this enum * @param {string} name Value name * @returns {Enum} `this` * @throws {TypeError} If arguments are invalid * @throws {Error} If `name` is not a name of this enum */ Enum.prototype.remove = function remove(name) { if (!util.isString(name)) throw TypeError("name must be a string"); var val = this.values[name]; if (val == null) throw Error("name '" + name + "' does not exist in " + this); delete this.valuesById[val]; delete this.values[name]; delete this.comments[name]; return this; }; /** * Tests if the specified id is reserved. * @param {number} id Id to test * @returns {boolean} `true` if reserved, otherwise `false` */ Enum.prototype.isReservedId = function isReservedId(id) { return Namespace.isReservedId(this.reserved, id); }; /** * Tests if the specified name is reserved. * @param {string} name Name to test * @returns {boolean} `true` if reserved, otherwise `false` */ Enum.prototype.isReservedName = function isReservedName(name) { return Namespace.isReservedName(this.reserved, name); }; /***/ }), /* 4 */ /***/ (function(module, exports) { module.exports = rxjs; /***/ }), /* 5 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; module.exports = ReflectionObject; ReflectionObject.className = "ReflectionObject"; var util = __webpack_require__(1); var Root; // cyclic /** * Constructs a new reflection object instance. * @classdesc Base class of all reflection objects. * @constructor * @param {string} name Object name * @param {Object.<string,*>} [options] Declared options * @abstract */ function ReflectionObject(name, options) { if (!util.isString(name)) throw TypeError("name must be a string"); if (options && !util.isObject(options)) throw TypeError("options must be an object"); /** * Options. * @type {Object.<string,*>|undefined} */ this.options = options; // toJSON /** * Parsed Options. * @type {Array.<Object.<string,*>>|undefined} */ this.parsedOptions = null; /** * Unique name within its namespace. * @type {string} */ this.name = name; /** * Parent namespace. * @type {Namespace|null} */ this.parent = null; /** * Whether already resolved or not. * @type {boolean} */ this.resolved = false; /** * Comment text, if any. * @type {string|null} */ this.comment = null; /** * Defining file name. * @type {string|null} */ this.filename = null; } Object.defineProperties(ReflectionObject.prototype, { /** * Reference to the root namespace. * @name ReflectionObject#root * @type {Root} * @readonly */ root: { get: function() { var ptr = this; while (ptr.parent !== null) ptr = ptr.parent; return ptr; } }, /** * Full name including leading dot. * @name ReflectionObject#fullName * @type {string} * @readonly */ fullName: { get: function() { var path = [ this.name ], ptr = this.parent; while (ptr) { path.unshift(ptr.name); ptr = ptr.parent; } return path.join("."); } } }); /** * Converts this reflection object to its descriptor representation. * @returns {Object.<string,*>} Descriptor * @abstract */ ReflectionObject.prototype.toJSON = /* istanbul ignore next */ function toJSON() { throw Error(); // not implemented, shouldn't happen }; /** * Called when this object is added to a parent. * @param {ReflectionObject} parent Parent added to * @returns {undefined} */ ReflectionObject.prototype.onAdd = function onAdd(parent) { if (this.parent && this.parent !== parent) this.parent.remove(this); this.parent = parent; this.resolved = false; var root = parent.root; if (root instanceof Root) root._handleAdd(this); }; /** * Called when this object is removed from a parent. * @param {ReflectionObject} parent Parent removed from * @returns {undefined} */ ReflectionObject.prototype.onRemove = function onRemove(parent) { var root = parent.root; if (root instanceof Root) root._handleRemove(this); this.parent = null; this.resolved = false; }; /** * Resolves this objects type references. * @returns {ReflectionObject} `this` */ ReflectionObject.prototype.resolve = function resolve() { if (this.resolved) return this; if (this.root instanceof Root) this.resolved = true; // only if part of a root return this; }; /** * Gets an option value. * @param {string} name Option name * @returns {*} Option value or `undefined` if not set */ ReflectionObject.prototype.getOption = function getOption(name) { if (this.options) return this.options[name]; return undefined; }; /** * Sets an option. * @param {string} name Option name * @param {*} value Option value * @param {boolean} [ifNotSet] Sets the option only if it isn't currently set * @returns {ReflectionObject} `this` */ ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet) { if (!ifNotSet || !this.options || this.options[name] === undefined) (this.options || (this.options = {}))[name] = value; return this; }; /** * Sets a parsed option. * @param {string} name parsed Option name * @param {*} value Option value * @param {string} propName dot '.' delimited full path of property within the option to set. if undefined\empty, will add a new option with that value * @returns {ReflectionObject} `this` */ ReflectionObject.prototype.setParsedOption = function setParsedOption(name, value, propName) { if (!this.parsedOptions) { this.parsedOptions = []; } var parsedOptions = this.parsedOptions; if (propName) { // If setting a sub property of an option then try to merge it // with an existing option var opt = parsedOptions.find(function (opt) { return Object.prototype.hasOwnProperty.call(opt, name); }); if (opt) { // If we found an existing option - just merge the property value var newValue = opt[name]; util.setProperty(newValue, propName, value); } else { // otherwise, create a new option, set it's property and add it to the list opt = {}; opt[name] = util.setProperty({}, propName, value); parsedOptions.push(opt); } } else { // Always create a new option when setting the value of the option itself var newOpt = {}; newOpt[name] = value; parsedOptions.push(newOpt); } return this; }; /** * Sets multiple options. * @param {Object.<string,*>} options Options to set * @param {boolean} [ifNotSet] Sets an option only if it isn't currently set * @returns {ReflectionObject} `this` */ ReflectionObject.prototype.setOptions = function setOptions(options, ifNotSet) { if (options) for (var keys = Object.keys(options), i = 0; i < keys.length; ++i) this.setOption(keys[i], options[keys[i]], ifNotSet); return this; }; /** * Converts this instance to its string representation. * @returns {string} Class name[, space, full name] */ ReflectionObject.prototype.toString = function toString() { var className = this.constructor.className, fullName = this.fullName; if (fullName.length) return className + " " + fullName; return className; }; // Sets up cyclic dependencies (called in index-light) ReflectionObject._configure = function(Root_) { Root = Root_; }; /***/ }), /* 6 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; module.exports = Field; // extends ReflectionObject var ReflectionObject = __webpack_require__(5); ((Field.prototype = Object.create(ReflectionObject.prototype)).constructor = Field).className = "Field"; var Enum = __webpack_require__(3), types = __webpack_require__(8), util = __webpack_require__(1); var Type; // cyclic var ruleRe = /^required|optional|repeated$/; /** * Constructs a new message field instance. Note that {@link MapField|map fields} have their own class. * @name Field * @classdesc Reflected message field. * @extends FieldBase * @constructor * @param {string} name Unique name within its namespace * @param {number} id Unique id within its namespace * @param {string} type Value type * @param {string|Object.<string,*>} [rule="optional"] Field rule * @param {string|Object.<string,*>} [extend] Extended type if different from parent * @param {Object.<string,*>} [options] Declared options */ /** * Constructs a field from a field descriptor. * @param {string} name Field name * @param {IField} json Field descriptor * @returns {Field} Created field * @throws {TypeError} If arguments are invalid */ Field.fromJSON = function fromJSON(name, json) { return new Field(name, json.id, json.type, json.rule, json.extend, json.options, json.comment); }; /** * Not an actual constructor. Use {@link Field} instead. * @classdesc Base class of all reflected message fields. This is not an actual class but here for the sake of having consistent type definitions. * @exports FieldBase * @extends ReflectionObject * @constructor * @param {string} name Unique name within its namespace * @param {number} id Unique id within its namespace * @param {string} type Value type * @param {string|Object.<string,*>} [rule="optional"] Field rule * @param {string|Object.<string,*>} [extend] Extended type if different from parent * @param {Object.<string,*>} [options] Declared options * @param {string} [comment] Comment associated with this field */ function Field(name, id, type, rule, extend, options, comment) { if (util.isObject(rule)) { comment = extend; options = rule; rule = extend = undefined; } else if (util.isObject(extend)) { comment = options; options = extend; extend = undefined; } ReflectionObject.call(this, name, options); if (!util.isInteger(id) || id < 0) throw TypeError("id must be a non-negative integer"); if (!util.isString(type)) throw TypeError("type must be a string"); if (rule !== undefined && !ruleRe.test(rule = rule.toString().toLowerCase())) throw TypeError("rule must be a string rule"); if (extend !== undefined && !util.isString(extend)) throw TypeError("extend must be a string"); if (rule === "proto3_optional") { rule = "optional"; } /** * Field rule, if any. * @type {string|undefined} */ this.rule = rule && rule !== "optional" ? rule : undefined; // toJSON /** * Field type. * @type {string} */ this.type = type; // toJSON /** * Unique field id. * @type {number} */ this.id = id; // toJSON, marker /** * Extended type if different from parent. * @type {string|undefined} */ this.extend = extend || undefined; // toJSON /** * Whether this field is required. * @type {boolean} */ this.required = rule === "required"; /** * Whether this field is optional. * @type {boolean} */ this.optional = !this.required; /** * Whether this field is repeated. * @type {boolean} */ this.repeated = rule === "repeated"; /** * Whether this field is a map or not. * @type {boolean} */ this.map = false; /** * Message this field belongs to. * @type {Type|null} */ this.message = null; /** * OneOf this field belongs to, if any, * @type {OneOf|null} */ this.partOf = null; /** * The field type's default value. * @type {*} */ this.typeDefault = null; /** * The field's default value on prototypes. * @type {*} */ this.defaultValue = null; /** * Whether this field's value should be treated as a long. * @type {boolean} */ this.long = util.Long ? types.long[type] !== undefined : /* istanbul ignore next */ false; /** * Whether this field's value is a buffer. * @type {boolean} */ this.bytes = type === "bytes"; /** * Resolved type if not a basic type. * @type {Type|Enum|null} */ this.resolvedType = null; /** * Sister-field within the extended type if a declaring extension field. * @type {Field|null} */ this.extensionField = null; /** * Sister-field within the declaring namespace if an extended field. * @type {Field|null} */ this.declaringField = null; /** * Internally remembers whether this field is packed. * @type {boolean|null} * @private */ this._packed = null; /** * Comment for this field. * @type {string|null} */ this.comment = comment; } /** * Determines whether this field is packed. Only relevant when repeated and working with proto2. * @name Field#packed * @type {boolean} * @readonly */ Object.defineProperty(Field.prototype, "packed", { get: function() { // defaults to packed=true if not explicity set to false if (this._packed === null) this._packed = this.getOption("packed") !== false; return this._packed; } }); /** * @override */ Field.prototype.setOption = function setOption(name, value, ifNotSet) { if (name === "packed") // clear cached before setting this._packed = null; return ReflectionObject.prototype.setOption.call(this, name, value, ifNotSet); }; /** * Field descriptor. * @interface IField * @property {string} [rule="optional"] Field rule * @property {string} type Field type * @property {number} id Field id * @property {Object.<string,*>} [options] Field options */ /** * Extension field descriptor. * @interface IExtensionField * @extends IField * @property {string} extend Extended type */ /** * Converts this field to a field descriptor. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options * @returns {IField} Field descriptor */ Field.prototype.toJSON = function toJSON(toJSONOptions) { var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false; return util.toObject([ "rule" , this.rule !== "optional" && this.rule || undefined, "type" , this.type, "id" , this.id, "extend" , this.extend, "options" , this.options, "comment" , keepComments ? this.comment : undefined ]); }; /** * Resolves this field's type references. * @returns {Field} `this` * @throws {Error} If any reference cannot be resolved */ Field.prototype.resolve = function resolve() { if (this.resolved) return this; if ((this.typeDefault = types.defaults[this.type]) === undefined) { // if not a basic type, resolve it this.resolvedType = (this.declaringField ? this.declaringField.parent : this.parent).lookupTypeOrEnum(this.type); if (this.resolvedType instanceof Type) this.typeDefault = null; else // instanceof Enum this.typeDefault = this.resolvedType.values[Object.keys(this.resolvedType.values)[0]]; // first defined } // use explicitly set default value if present if (this.options && this.options["default"] != null) { this.typeDefault = this.options["default"]; if (this.resolvedType instanceof Enum && typeof this.typeDefault === "string") this.typeDefault = this.resolvedType.values[this.typeDefault]; } // remove unnecessary options if (this.options) { if (this.options.packed === true || this.options.packed !== undefined && this.resolvedType && !(this.resolvedType instanceof Enum)) delete this.options.packed; if (!Object.keys(this.options).length) this.options = undefined; } // convert to internal data type if necesssary if (this.long) { this.typeDefault = util.Long.fromNumber(this.typeDefault, this.type.charAt(0) === "u"); /* istanbul ignore else */ if (Object.freeze) Object.freeze(this.typeDefault); // long instances are meant to be immutable anyway (i.e. use small int cache that even requires it) } else if (this.bytes && typeof this.typeDefault === "string") { var buf; if (util.base64.test(this.typeDefault)) util.base64.decode(this.typeDefault, buf = util.newBuffer(util.base64.length(this.typeDefault)), 0); else util.utf8.write(this.typeDefault, buf = util.newBuffer(util.utf8.length(this.typeDefault)), 0); this.typeDefault = buf; } // take special care of maps and repeated fields if (this.map) this.defaultValue = util.emptyObject; else if (this.repeated) this.defaultValue = util.emptyArray; else this.defaultValue = this.typeDefault; // ensure proper value on prototype if (this.parent instanceof Type) this.parent.ctor.prototype[this.name] = this.defaultValue; return ReflectionObject.prototype.resolve.call(this); }; /** * Decorator function as returned by {@link Field.d} and {@link MapField.d} (TypeScript). * @typedef FieldDecorator * @type {function} * @param {Object} prototype Target prototype * @param {string} fieldName Field name * @returns {undefined} */ /** * Field decorator (TypeScript). * @name Field.d * @function * @param {number} fieldId Field id * @param {"double"|"float"|"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"string"|"bool"|"bytes"|Object} fieldType Field type * @param {"optional"|"required"|"repeated"} [fieldRule="optional"] Field rule * @param {T} [defaultValue] Default value * @returns {FieldDecorator} Decorator function * @template T extends number | number[] | Long | Long[] | string | string[] | boolean | boolean[] | Uint8Array | Uint8Array[] | Buffer | Buffer[] */ Field.d = function decorateField(fieldId, fieldType, fieldRule, defaultValue) { // submessage: decorate the submessage and use its name as the type if (typeof fieldType === "function") fieldType = util.decorateType(fieldType).name; // enum reference: create a reflected copy of the enum and keep reuseing it else if (fieldType && typeof fieldType === "object") fieldType = util.decorateEnum(fieldType).name; return function fieldDecorator(prototype, fieldName) { util.decorateType(prototype.constructor) .add(new Field(fieldName, fieldId, fieldType, fieldRule, { "default": defaultValue })); }; }; /** * Field decorator (TypeScript). * @name Field.d * @function * @param {number} fieldId Field id * @param {Constructor<T>|string} fieldType Field type * @param {"optional"|"required"|"repeated"} [fieldRule="optional"] Field rule * @returns {FieldDecorator} Decorator function * @template T extends Message<T> * @variation 2 */ // like Field.d but without a default value // Sets up cyclic dependencies (called in index-light) Field._configure = function configure(Type_) { Type = Type_; }; /***/ }), /* 7 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; module.exports = Namespace; // extends ReflectionObject var ReflectionObject = __webpack_require__(5); ((Namespace.prototype = Object.create(ReflectionObject.prototype)).constructor = Namespace).className = "Namespace"; var Field = __webpack_require__(6), OneOf = __webpack_require__(9), util = __webpack_require__(1); var Type, // cyclic Service, Enum; /** * Constructs a new namespace instance. * @name Namespace * @classdesc Reflected namespace. * @extends NamespaceBase * @constructor * @param {string} name Namespace name * @param {Object.<string,*>} [options] Declared options */ /** * Constructs a namespace from JSON. * @memberof Namespace * @function * @param {string} name Namespace name * @param {Object.<string,*>} json JSON object * @returns {Namespace} Created namespace * @throws {TypeError} If arguments are invalid */ Namespace.fromJSON = function fromJSON(name, json) { return new Namespace(name, json.options).addJSON(json.nested); }; /** * Converts an array of reflection objects to JSON. * @memberof Namespace * @param {ReflectionObject[]} array Object array * @param {IToJSONOptions} [toJSONOptions] JSON conversion options * @returns {Object.<string,*>|undefined} JSON object or `undefined` when array is empty */ function arrayToJSON(array, toJSONOptions) { if (!(array && array.length)) return undefined; var obj = {}; for (var i = 0; i < array.length; ++i) obj[array[i].name] = array[i].toJSON(toJSONOptions); return obj; } Namespace.arrayToJSON = arrayToJSON; /** * Tests if the specified id is reserved. * @param {Array.<number[]|string>|undefined} reserved Array of reserved ranges and names * @param {number} id Id to test * @returns {boolean} `true` if reserved, otherwise `false` */ Namespace.isReservedId = function isReservedId(reserved, id) { if (reserved) for (var i = 0; i < reserved.length; ++i) if (typeof reserved[i] !== "string" && reserved[i][0] <= id && reserved[i][1] > id) return true; return false; }; /** * Tests if the specified name is reserved. * @param {Array.<number[]|string>|undefined} reserved Array of reserved ranges and names * @param {string} name Name to test * @returns {boolean} `true` if reserved, otherwise `false` */ Namespace.isReservedName = function isReservedName(reserved, name) { if (reserved) for (var i = 0; i < reserved.length; ++i) if (reserved[i] === name) return true; return false; }; /** * Not an actual constructor. Use {@link Namespace} instead. * @classdesc Base class of all reflection objects containing nested objects. This is not an actual class but here for the sake of having consistent type definitions. * @exports NamespaceBase * @extends ReflectionObject * @abstract * @constructor * @param {string} name Namespace name * @param {Object.<string,*>} [options] Declared options * @see {@link Namespace} */ function Namespace(name, options) { ReflectionObject.call(this, name, options