*

@param {srv.core.Context} context
@param {Function} callback - function(err, resource)
322963
function (context, callback) {

            var path = context.request.urlInfo.pathname,
                relativePath = this.$restHandler.$.path;

            if (path.indexOf(relativePath) !== 0) {
                callback(new Error("Handler path '" + relativePath + "' not at start of " + path));
                return;
            }

            // remove relative handler path from path
            path = path.substring(relativePath.length);

            var pathElements = path.split('/');

            // remove first empty path
            pathElements.shift();

            try {
                callback(null, this._getResourceForPath(pathElements));
            } catch (e) {
                callback(e);
            }
        }
462736
function ContextKarma (callParentKarmaMethod) {
  // Define local variables
  var hasError = false
  var self = this
  var isLoaded = false

  // Define our loggers
  // DEV: These are intentionally repeated in client and context
  this.log = function (type, args) {
    var values = []

    for (var i = 0; i < args.length; i++) {
      values.push(this.stringify(args[i], 3))
    }

    this.info({log: values.join(', '), type: type})
  }

  this.stringify = stringify

  // Define our proxy error handler
  // DEV: We require one in our context to track `hasError`
  this.error = function () {
    hasError = true
    callParentKarmaMethod('error', [].slice.call(arguments))
    return false
  }

  // Define our start handler
  function UNIMPLEMENTED_START () {
    this.error('You need to include some adapter that implements __karma__.start method!')
  }
  // all files loaded, let's start the execution
  this.loaded = function () {
    // has error -> cancel
    if (!hasError && !isLoaded) {
      isLoaded = true
      try {
        this.start(this.config)
      } catch (error) {
        this.error(error.stack || error.toString())
      }
    }

    // remove reference to child iframe
    this.start = UNIMPLEMENTED_START
  }
  // supposed to be overriden by the context
  // TODO(vojta): support multiple callbacks (queue)
  this.start = UNIMPLEMENTED_START

  // Define proxy methods
  // DEV: This is a closured `for` loop (same as a `forEach`) for IE support
  var proxyMethods = ['complete', 'info', 'result']
  for (var i = 0; i < proxyMethods.length; i++) {
    (function bindProxyMethod (methodName) {
      self[methodName] = function boundProxyMethod () {
        callParentKarmaMethod(methodName, [].slice.call(arguments))
      }
    }(proxyMethods[i]))
  }

  // Define bindings for context window
  this.setupContext = function (contextWindow) {
    // If we clear the context after every run and we already had an error
    //   then stop now. Otherwise, carry on.
    if (self.config.clearContext && hasError) {
      return
    }

    // Perform window level bindings
    // DEV: We return `self.error` since we want to `return false` to ignore errors
    contextWindow.onerror = function () {
      return self.error.apply(self, arguments)
    }
    // DEV: We must defined a function since we don't want to pass the event object
    contextWindow.onbeforeunload = function (e, b) {
      callParentKarmaMethod('onbeforeunload', [])
    }

    contextWindow.dump = function () {
      self.log('dump', arguments)
    }

    var _confirm = contextWindow.confirm
    var _prompt = contextWindow.prompt

    contextWindow.alert = function (msg) {
      self.log('alert', [msg])
    }

    contextWindow.confirm = function (msg) {
      self.log('confirm', [msg])
      return _confirm(msg)
    }

    contextWindow.prompt = function (msg, defaultVal) {
      self.log('prompt', [msg, defaultVal])
      return _prompt(msg, defaultVal)
    }

    // If we want to overload our console, then do it
    function getConsole (currentWindow) {
      return currentWindow.console || {
        log: function () {},
        info: function () {},
        warn: function () {},
        error: function () {},
        debug: function () {}
      }
    }
    if (self.config.captureConsole) {
      // patch the console
      var localConsole = contextWindow.console = getConsole(contextWindow)
      var logMethods = ['log', 'info', 'warn', 'error', 'debug']
      var patchConsoleMethod = function (method) {
        var orig = localConsole[method]
        if (!orig) {
          return
        }
        localConsole[method] = function () {
          self.log(method, arguments)
          try {
            return Function.prototype.apply.call(orig, localConsole, arguments)
          } catch (error) {
            self.log('warn', ['Console method ' + method + ' threw: ' + error])
          }
        }
      }
      for (var i = 0; i < logMethods.length; i++) {
        patchConsoleMethod(logMethods[i])
      }
    }
  }
}
395205
function once (callback, context) {
  var done = false
  var rest = null
  var args = arraySlice(arguments, 2)
  context = context || this
  return function () {
    if (done) {
      return rest
    }
    rest = callback.apply(context, arraySlice(arguments).concat(args))
    done = true
    return rest
  }
}
1026186
function (context, path, callback) {
  path = normalize(path);
  var name = basename(path);
  var parentPath = dirname(path);

  var directoryNode;
  var directoryData;
  var parentDirectoryNode;
  var parentDirectoryData;

  function read_parent_directory_data(error, result) {
    if(error) {
      callback(error);
    } else {
      parentDirectoryNode = result;
      context.getObject(parentDirectoryNode.data, check_if_node_exists);
    }
  }

  function check_if_node_exists(error, result) {
    if(error) {
      callback(error);
    } else if(ROOT_DIRECTORY_NAME === name) {
      callback(new Errors.EBUSY(null, path));
    } else if(!result.hasOwnProperty(name)) {
      callback(new Errors.ENOENT(null, path));
    } else {
      parentDirectoryData = result;
      directoryNode = parentDirectoryData[name].id;
      context.getObject(directoryNode, check_if_node_is_directory);
    }
  }

  function check_if_node_is_directory(error, result) {
    if(error) {
      callback(error);
    } else if(result.type !== NODE_TYPE_DIRECTORY) {
      callback(new Errors.ENOTDIR(null, path));
    } else {
      directoryNode = result;
      context.getObject(directoryNode.data, check_if_directory_is_empty);
    }
  }

  function check_if_directory_is_empty(error, result) {
    if(error) {
      callback(error);
    } else {
      directoryData = result;
      if(Object.keys(directoryData).length > 0) {
        callback(new Errors.ENOTEMPTY(null, path));
      } else {
        _entry_from_parent_directory_node();
      }
    }
  }

  function update_time(error) {
    if(error) {
      callback(error);
    } else {
      var now = Date.now();
      update_node_times(context, parentPath, parentDirectoryNode, { mtime: now, ctime: now }, _node);
    }
  }

  function _entry_from_parent_directory_node() {
    delete parentDirectoryData[name];
    context.putObject(parentDirectoryNode.data, parentDirectoryData, update_time);
  }

  function _node(error) {
    if(error) {
      callback(error);
    } else {
      context.delete(directoryNode.id, _data);
    }
  }

  function _data(error) {
    if(error) {
      callback(error);
    } else {
      context.delete(directoryNode.data, callback);
    }
  }

  find_node(context, parentPath, read_parent_directory_data);
}
1152228
function (context, callback) {
            var model,
                self = this;

            flow()
                .seq("collection", function (cb) {
                    self._findCollection(context, cb);
                })
                .seq(function () {
                    model = this.vars.collection.createItem(self.$resourceId);
                })
                .seq(function (cb) {
                    self._beforeModelRemove(model, context, cb);
                })
                // remove model
                .seq(function (cb) {
                    model.remove(null, cb);
                })
                .seq(function (cb) {
                    self._afterModelRemove(model, context, cb);
                })
                .exec(function (err, results) {
                    if (!err) {
                        // TODO: do correct invalidation
                        results.collection.invalidatePageCache();
                        // TODO: generate the location header
                        var body = "";

                        var response = context.response;
                        response.writeHead(200, "", {
                            'Content-Type': 'application/json'
                        });

                        response.write(body);
                        response.end();

                        callback(null);
                    } else {
                        if (!(err instanceof HttpError)) {
                            var statusCode = 500;
                            if (err === DataSource.ERROR.NOT_FOUND) {
                                statusCode = 404;
                            }
                            err = new HttpError(err, statusCode);
                        }
                        callback(err);
                    }
                });
        }
688674
async function compileContext(target, contextOptions) {
	const context = await getContext(target, contextOptions)

	return async function (data/** @param {object} */) {
		return context.map(data)
	}
}
663072
function (context, authenticationRequest, callback) {
            //
            var authProvider = this.getAuthenticationProviderForRequest(authenticationRequest);

            if (authProvider) {
                flow()
                    .seq("authentication", function (cb) {
                        // authenticate
                        authProvider.authenticate(authenticationRequest, cb);
                    })
                    .seq(function (cb) {
                        // init authentication
                        this.vars.authentication.init(cb);
                    })
                    .exec(function (err, results) {
                        var authentication = results.authentication;
                        if (!err && authentication) {
                            context.user.addAuthentication(authentication);
                        }
                        // return authentication with user id
                        callback(err, authentication);
                    })
            } else {
                callback(AuthenticationError.NO_PROVIDER_FOUND, null);
            }
        }
156579
function(selector, context) {
  this.selector = selector;
  if (typeof context == 'function') {
    this.context = null;
    this.asyncExecute(null, null, context);
  }
  else {
    this.context = context;
  }

  this.instance = -1;
  this.index = -1;
  this.length = -1;
}
880967
function callHandler(callback, context, args) {
  switch (args.length) {
    case 0: return callback.call(context);
    case 1: return callback.call(context, args[0]);
    case 2: return callback.call(context, args[0], args[1]);
    case 3: return callback.call(context, args[0], args[1], args[2]);
    default: return callback.apply(context, args);
  }
}
880004
function(callback, context)
  {
    var db = this;
    var promise = new Promise();
    var success = this.handleRefreshSuccess( promise );
    var failure = this.handleRefreshFailure( promise );

    promise.complete( callback, context || db );

    batchExecute(function()
    {
      db.executeRefresh( success, failure );
    });

    return promise;
  }
1189344
function() {
    var callbacks = this._callbacks;
    var contexts = this._contexts;
    if (callbacks) {
      ("production" !== "development" ? invariant(
        callbacks.length === contexts.length,
        'Mismatched list of contexts in callback queue'
      ) : invariant(callbacks.length === contexts.length));
      this._callbacks = null;
      this._contexts = null;
      for (var i = 0, l = callbacks.length; i < l; i++) {
        callbacks[i].call(contexts[i]);
      }
      callbacks.length = 0;
      contexts.length = 0;
    }
  }
303283
function callback(fn, context, event) {
        //window.setTimeout(function(){
        event.target = context;
        (typeof context[fn] === "function") && context[fn].apply(context, [event]);
        //}, 1);
    }
487609
function(evname, callback, context) {
    this._events = this._events || {};
    var a = this._events[evname] = this._events[evname] || [];
    a.push({
      cb: callback,
      ctxt: context || this
    });
    return this;
  }
839810
function(callbacks, context){
      // avoid warnings on trying to remove handler for destroyed instance
      // since it droped all handlers
      if (this.destroy === warnOnDestroy)
        return;

      var cursor = this;
      var prev;

      context = context || this;

      // search for handler and remove it
      while (prev = cursor, cursor = cursor.handler)
        if (cursor.callbacks === callbacks && cursor.context === context)
        {
          // make it non-callable
          cursor.callbacks = NULL_HANDLER;

          // remove from list
          prev.handler = cursor.handler;

          return;
        }

      // handler not found
      /** @cut */ basis.dev.warn(namespace + '.Emitter#removeHandler: no handler removed');
    }
53457
function callbackOnce(err, arg) {
            var cb = callback;
            callback = null;
            if (cb) { cb(err, arg); }
        }
988733
function bind (callback, context) {
  var args = arraySlice(arguments, 2)
  context = context || this
  return function () {
    return callback.apply(context, arraySlice(arguments).concat(args))
  }
}
355907
function on(event, callback, context) {
        var events = eventsplitter.test(event)
            ? event.split(eventsplitter)
            : [event];

        this.events = this.events || (this.events = {});

        while (event = events.shift()) {
          if (!event) continue;

          (this.events[event] = this.events[event] || []).push({
              context: context
            , callback: callback
          });
        }

        return this;
      }