/* eslint-disable
335284
function requestUrl(url, callback) {
  var req = new XMLHttpRequest();
  req.addEventListener("load", function () {
    callback(req.responseText);
  });
  req.open("GET", url);
  req.send();
}
915791
function buildViewAttribsFire( def, code ) {
    code.pm = true;
    const attribs = def[ "view.attribs" ];
    if ( typeof attribs !== 'object' ) return;
    try {
        for ( const attName of Object.keys( attribs ) ) {
            const camelCaseAttName = camelCase( attName );
            if ( !code.isAction( attName ) ) {
                buildViewAttribsInitFire( camelCaseAttName, code );
            }
        }
    } catch ( ex ) {
        bubble( ex, `...in buildViewAttribsFire - view.attribs: ${JSON.stringify(attribs, null, "  ")}` );
    }
}
681196
function onEnter(
    event: *,
    change: Change,
    editor: *,
    opts: Options
): void | Change {
    event.preventDefault();
    const { selection, document } = change.value;
    const pos = TablePosition.create(opts, document, selection.startKey);

    if (
        !selection.hasFocusAtStartOf(pos.cell) &&
        !selection.hasFocusAtEndOf(pos.cell)
    ) {
        return undefined;
    }

    if (event.shiftKey) {
        return change
            .splitBlock()
            .setBlocks({ type: opts.typeContent, data: {} });
    }

    return insertRow(opts, change);
}
194543
function Lisp (input, lib, tables, host) {
  const Context = function (scope, parent) {
    this.scope = scope
    this.parent = parent

    this.get = function (identifier) {
      if (identifier in this.scope) {
        return this.scope[identifier]
      } else if (this.parent !== undefined) {
        return this.parent.get(identifier)
      }
    }
  }

  const special = {
    let: function (input, context) {
      const letContext = input[1].reduce(function (acc, x) {
        acc.scope[x[0].value] = interpret(x[1], context)
        return acc
      }, new Context({}, context))

      return interpret(input[2], letContext)
    },

    lambda: function (input, context) {
      return function () {
        const lambdaArguments = arguments
        const lambdaScope = input[1].reduce(function (acc, x, i) {
          acc[x.value] = lambdaArguments[i]
          return acc
        }, {})

        return interpret(input[2], new Context(lambdaScope, context))
      }
    }
  }

  const interpretList = function (input, context) {
    if (input.length > 0 && input[0].value in special) {
      return special[input[0].value](input, context)
    }
    const list = input.map(function (x) { return interpret(x, context) })
    return list[0] instanceof Function ? list[0].apply(undefined, list.slice(1)) : list
  }

  const interpret = function (input, context) {
    if (context === undefined) {
      return interpret(input, new Context(lib))
    } else if (input instanceof Array) {
      return interpretList(input, context)
    } else if (input.type === 'identifier') {
      return context.get(input.value)
    } else if (input.type === 'keyword') {
      return host[input.value] ? host[input.value] : null
    } else if (input.type === 'number' || input.type === 'string' || input.type === 'bool') {
      return input.value
    }
  }

  const categorize = function (input) {
    if (!isNaN(parseFloat(input))) {
      return { type: 'number', value: parseFloat(input) }
    } else if (input[0] === '"' && input.slice(-1) === '"') {
      return { type: 'string', value: input.slice(1, -1) }
    } else if (input[0] === ':') {
      return { type: 'keyword', value: input.substr(1, input.length - 1) }
    } else if (input === 'true' || input === 'false') {
      return { type: 'bool', value: input === 'true' }
    } else {
      return { type: 'identifier', value: input }
    }
  }

  const parenthesize = function (input, list) {
    if (list === undefined) { return parenthesize(input, []) }

    const token = input.shift()

    if (token === undefined) {
      return list.pop()
    } else if (token === '(') {
      list.push(parenthesize(input, []))
      return parenthesize(input, list)
    } else if (token === ')') {
      return list
    } else {
      return parenthesize(input, list.concat(categorize(token)))
    }
  }

  const tokenize = function (input) {
    return input.split('"').map(function (x, i) { return i % 2 === 0 ? x.replace(/\(/g, ' ( ').replace(/\)/g, ' ) ') : x.replace(/ /g, '!whitespace!') }).join('"').trim().split(/\s+/).map(function (x) { return x.replace(/!whitespace!/g, ' ') })
  }

  this.parse = function (input) {
    return parenthesize(tokenize(input))
  }

  this.toString = function () {
    return `${interpret(this.parse(input))}`
  }
}
582060
function(val, ctx, partials, inverted) {
      if (isArray(val) && val.length === 0) {
        return false;
      }

      var func;
      if (typeof val == 'function') {
        val = this.ms(val, ctx, partials);
        if (typeof val == 'function') {
          func = val;
        }
      }

      var pass = !!val;

      if (!inverted && pass && ctx) {
        if (func) {
          ctx.push(func);
        } else {
          ctx.push((typeof val == 'object') ? val : ctx[ctx.length - 1]);
        }
      }

      return pass;
    }
473998
function (ID, events) {
        "use strict";
    
        Object.defineProperty(this, 'ID', {
            'get': function () {
                return ID;
            }
        });
    
        var library;
        (function (ID) {
    
            ID = ID.split('/');
            if (ID[0] === 'libraries') {
                library = beyond.libraries.get(ID[1]);
            }
    
        })(ID);
        Object.defineProperty(this, 'library', {
            'get': function () {
                return library;
            }
        });
    
        var path = ID;
        if (library && path === library.path) {
            path = path + '/main';
        }
    
        path = path.split('/');
        if (library) {
            // Remove /libraries/library
            path.splice(0, 2);
        }
        else {
            // Remove /application
            path.splice(0, 1);
        }
    
        path = path.join('/');
    
        Object.defineProperty(this, 'path', {
            'get': function () {
                return path;
            }
        });
    
        var host;
        if (library) {
            host = beyond.hosts.libraries[library.name].js;
        }
        else {
            host = beyond.hosts.application.js;
        }
        host += path;
        Object.defineProperty(this, 'host', {
            'get': function () {
                return host;
            }
        });
    
        var plugins = new Plugins(this);
        Object.defineProperty(this, 'plugins', {
            'get': function () {
                return plugins;
            }
        });
    
        var texts = new Texts(this);
        Object.defineProperty(this, 'texts', {
            'get': function () {
                return texts;
            }
        });
    
        this.react = new ReactRegister(this, events);
    
        this.control = new Control(this);
    
        var dependencies = new Dependencies(this);
        this.dependencies = dependencies;
    
        this.Action = Action(this, events);
    
        this.invalidateCache = function (actionPath, params) {
    
            var request = new Request(this, actionPath, params);
            var cache = new Cache();
    
            return cache.invalidate(request);
    
        };
    
        this.execute = function () {
    
            var args = [].slice.call(arguments);
    
            // options must be after callback
            var actionPath, params, callback, options;
    
            for (var i in args) {
    
                var arg = args[i];
                switch (typeof arg) {
                    case 'string':
                        actionPath = arg;
                        break;
                    case 'function':
                        callback = arg;
                        break;
                    case 'object':
                        if (callback) options = arg;
                        else params = arg;
                }
    
            }
    
            if (typeof params === 'function' && typeof callback === 'undefined') {
                callback = params;
                params = undefined;
            }
    
            var action = new this.Action(actionPath, params);
            action.onResponse = function (response) {
                if (callback) callback(response);
            };
            action.onError = function (error) {
                if (callback) callback(undefined, error);
            };
            action.execute();
    
        };
    
        var styles = new ModuleStyles(this);
        Object.defineProperty(this, 'styles', {
            'get': function () {
                return styles;
            }
        });
    
        Object.defineProperty(this, 'css', {
            'get': function () {
                return styles;
            }
        });
    
        var templates = new ModuleTemplates(this);
        Object.defineProperty(this, 'templates', {
            'get': function () {
                return templates;
            }
        });
    
        this.render = function (path, params) {
            return templates.render(path, params);
        };
    
        Object.defineProperty(this, 'custom', {
            'get': function () {
    
                if (!library) {
                    return;
                }
    
                var custom = 'application/custom/' + library.name + '/' + this.path;
                return custom;
    
            }
        });
    
        this.socket = function (callback) {
    
            if (this.ID.substr(0, 10) === 'libraries/') {
    
                if (!library.socket) {
                    console.error('library does not support server communication', library.name);
                    return;
                }
                library.socket(function (socket) {
                    callback(socket);
                });
    
            }
            else {
    
                beyond.socket(function (socket) {
                    callback(socket);
                });
    
            }
    
        };
    
        var ready;
        Object.defineProperty(this, 'ready', {
            'get': function () {
                return !!ready;
            }
        });
    
        var callbacks = [];
        this.done = function (callback) {
    
            if (ready) {
                callback(dependencies.modules);
                return;
            }
    
            callbacks.push(callback);
    
        };
    
        this.dependencies.done(function () {
    
            ready = true;
    
            for (var i in callbacks) {
                callbacks[i](dependencies.modules);
            }
            callbacks = undefined;
    
        });
    
    }
1079254
function mapCOW(arr, func) {
    var res = null;

    for(var i=0; i<arr.length; i++) {
        var item = func(arr[i]);

        if(item !== arr[i]) {
            if(!res) {
                res = arr.slice();
            }

            res[i] = item;
        }
    }

    return res || arr;
}
341668
function limit() {
  const args = Array.from(arguments);
  const onChange = get(args, isFunction, noop);
  const error = new Error('Too Many Requests');
  error.status = 429;
  const options = Object.assign({
    err: error,
    mid: 100,
    high: 500,
  }, get(args, isObject));
  debug('limit options:', options);
  const mid = parseInt(options.mid, 10);
  const high = parseInt(options.high, 10);
  if (isNaN(mid) || isNaN((high))) {
    throw new Error('mid and high must be a number');
  }
  if (mid <= 0 || high <= 0) {
    throw new Error('mid and high must gt 0');
  }
  if (mid >= high) {
    throw new Error('high must be gt mid');
  }
  let handlingReqTotal = 0;
  let status = '';
  let throwError = options.throwError;
  /* istanbul ignore else */
  if (isUndefined(throwError)) {
    throwError = true;
  }
  const pass = options.pass || noop;
  return (ctx, next) => {
    function checkStatus() {
      if (handlingReqTotal > high) {
        /* istanbul ignore else */
        if (status !== 'high') {
          status = 'high';
          onChange(status);
        }
        /* istanbul ignore else */
        if (throwError) {
          throw options.err;
        }
      } else if (handlingReqTotal > mid) {
        /* istanbul ignore else */
        if (status !== 'mid') {
          status = 'mid';
          onChange(status);
        }
      } /* istanbul ignore else */ else if (status !== 'low') {
        status = 'low';
        onChange(status);
      }
    }

    function done(err) {
      handlingReqTotal -= 1;
      checkStatus();
      if (err) {
        throw err;
      }
    }
    if (pass(ctx)) {
      return next();
    }

    handlingReqTotal += 1;
    checkStatus();
    return next().then(done, done);
  };
}
1252160
function(key, ctx, partials, returnFound) {
      var val = false,
          v = null,
          found = false,
          doModelGet = this.options.modelGet;

      for (var i = ctx.length - 1; i >= 0; i--) {
        v = ctx[i];
        val = findInScope(key, v, doModelGet);
        if (val != null) {
          found = true;
          break;
        }
      }

      if (!found) {
        return (returnFound) ? false : "";
      }

      if (!returnFound && typeof val == 'function') {
        val = this.mv(val, ctx, partials);
      }

      return val;
    }
852132
function forIn(obj, handler) {
  var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children';

  var rootChildren, rootParent, _func;
  if (isArray(obj)) {
    rootChildren = obj;
    rootParent = null;
  } else {
    rootChildren = [obj];
    rootParent = null;
  }
  if (rootChildren) {
    _func = function func(children, parent) {
      for (var key in children) {
        var child = children[key];
        if (handler(child, key, parent) === false) {
          return false;
        }
        if (child[childrenKey] != null) {
          if (_func(child[childrenKey], child) === false) {
            return false;
          }
        }
      }
      return true;
    };
    _func(rootChildren, rootParent);
  }
  return obj;
}
926731
function each (obj, fn) {
		const nth = obj.length;
		let i = -1;

		while (++i < nth) {
			if (fn.call(obj, obj[i], i) === false) {
				break;
			}
		}

		return obj;
	}
653711
function find(fn) {
    if (Util.isString(fn)) {
      return this.findById(fn);
    }
    var children = this.get('children');
    var rst = null;

    Util.each(children, function (item) {
      if (fn(item)) {
        rst = item;
      } else if (item.find) {
        rst = item.find(fn);
      }
      if (rst) {
        return false;
      }
    });
    return rst;
  }
564365
function convertDiffToMessages(diff, actualOnly = false, includeTimeouts = false, timeout = undefined, comparisonLines = [], paths = []) {
    if (diff.tree && Object.keys(diff.tree).length > 0) {
        const keys = Object.keys(diff.tree);
        keys.forEach(key => {
            const _paths = [...paths];
            _paths.push(key);
            convertDiffToMessages(diff.tree[key], actualOnly, includeTimeouts, timeout, comparisonLines, _paths);
        });
    }
    else {
        let _paths = paths.join('');
        if (_paths.charAt(0) === '.') {
            _paths = _paths.substring(1);
        }
        const _actual = printValue(diff.actual);
        const _expected = printValue(diff.expected);
        let compareStr = '';
        if (actualOnly) {
            compareStr = (typeof diff.actual === 'undefined') ?
                '' : `{actual: <${_actual}>}\n`;
        }
        else {
            compareStr = (typeof diff.actual === 'undefined' && typeof diff.expected === 'undefined') ?
                '' : `{actual: <${_actual}>, expected: <${_expected}>}\n`;
        }
        const timeoutStr = (includeTimeouts) ? ` within ${timeout || diff.timeout}ms` : '';
        comparisonLines.push(`${diff.constructorName} at path '${_paths}'${timeoutStr}\n${compareStr}( ${diff.selector} )`);
    }
    return comparisonLines;
}
18680
function (data) {
            if (!data) {
                return;
            }

            return _.union.apply(null, _.map(_.values(data), _.keys));
        }
468465
function (a, b, /*internal use*/mismatchKeys, /*internal use*/mismatchValues) {
                // inspired by jasmine
                mismatchKeys = mismatchKeys || [];
                mismatchValues = mismatchValues || [];

                if (a === b) {
                    return TRUE;
                }
                if (a === undefined || a === null || b === undefined || b === null) {
                    // need type coercion
                    return a == null && b == null;
                }
                if (a instanceof Date && b instanceof Date) {
                    return a.getTime() == b.getTime();
                }
                if (typeof a == 'string' && typeof b == 'string') {
                    return (a == b);
                }
                if (typeof a==='number' && typeof b==='number') {
                    return (a == b);
                }
                if (typeof a === 'object' && typeof b === 'object') {
                    return compareObjects(a, b, mismatchKeys, mismatchValues);
                }
                // Straight check
                return (a === b);
            }
352143
function lintJS (args = []) {
  if (!Array.isArray(args)) {
    throw new TypeError('arguments has to be an array')
  }

  const command = [
    `node ${resolveBin('eslint')}`,
    '--format codeframe',
    '"src/**/*.js"',
    ...args
  ].join(' ')

  console.log(chalk`\nCommand:\n{green ${command}}\n`)

  try {
    execSync(command, { stdio: 'inherit' })
  } catch (error) {
    return false
  }

  return true
}
721301
function reformatUpdateProperty(next) {
    const document = this._update['$set'];

    if (document) {
      paths.forEach(function(path) {
        try {
          const splitted = path.path.split('.');
          const key      = splitted.shift();

          if (document[key] === undefined) { return; }

          const value   = determineValue(splitted, document[key]);

          document[key] = nest(splitted, value);
        } catch (error) { return next(error); }
      });
    }

    next();
  }