{"size": 1592, "ext": "js", "max_stars_repo_path": "node_modules/loopback-datasource-juggler/lib/kvao/keys.js", "max_stars_repo_name": "Shapes/letsgo", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "node_modules/loopback-datasource-juggler/lib/kvao/keys.js", "max_issues_repo_name": "Shapes/letsgo", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "node_modules/loopback-datasource-juggler/lib/kvao/keys.js", "max_forks_repo_name": "Shapes/letsgo", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.0983606557, "max_line_length": 75, "alphanum_fraction": 0.6425879397}
'use strict';

var assert = require('assert');
var utils = require('../utils');

/**
 * Get all keys.
 *
 * **NOTE**
 * Building an in-memory array of all keys may be expensive.
 * Consider using `iterateKeys` instead.
 *
 * @param {Object} filter An optional filter object with the following
 * properties:
 *  - `match` - glob string to use to filter returned keys, e.g. 'userid.*'
 *    All connectors are required to support `*` and `?`.
 *    They may also support additional special characters that are specific
 *    to the backing store.
 * @param {Object} options
 * @callback callback
 * @param {Error=} err
 * @param {[String]} keys The list of keys.
 *
 * @promise
 *
 * @header KVAO.keys(filter, callback)
 */
module.exports = function keyValueKeys(filter, options, callback) {
  if (callback === undefined) {
    if (typeof options === 'function') {
      callback = options;
      options = undefined;
    } else if (options === undefined && typeof filter === 'function') {
      callback = filter;
      filter = undefined;
    }
  }

  filter = filter || {};
  options = options || {};

  assert(typeof filter === 'object', 'filter must be an object');
  assert(typeof options === 'object', 'options must be an object');

  callback = callback || utils.createPromiseCallback();

  var iter = this.iterateKeys(filter, options);
  var keys = [];
  iter.next(onNextKey);

  function onNextKey(err, key) {
    if (err) return callback(err);
    if (key === undefined) return callback(null, keys);
    keys.push(key);
    iter.next(onNextKey);
  }

  return callback.promise;
};

