{"size": 1820, "ext": "js", "max_stars_repo_path": "test/index.js", "max_stars_repo_name": "rledford/qproc-mongo", "max_stars_repo_stars_event_min_datetime": "2018-11-06T08:19:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-05T15:56:03.000Z", "max_issues_repo_path": "test/index.js", "max_issues_repo_name": "rledford/qproc-mongo", "max_issues_repo_issues_event_min_datetime": "2019-09-03T15:04:08.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-05T15:36:38.000Z", "max_forks_repo_path": "test/index.js", "max_forks_repo_name": "rledford/qproc-mongo", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": 6, "max_forks_count": null, "avg_line_length": 21.1627906977, "max_line_length": 63, "alphanum_fraction": 0.5576923077}
function separator() {
  console.log(Array(50).fill('*').join(''));
}

const qproc = require('../lib/qproc-mongo');
let options = {
  fields: {
    _id: {
      type: qproc.ObjectId,
      alias: 'id'
    },
    v: {
      type: qproc.Date,
      default: () => {
        return {
          $lt: new Date()
        };
      }
    },
    category: qproc.String,
    name: qproc.String,
    date: {
      type: qproc.Date
    },
    description: {
      type: qproc.String,
      alias: ['info', 'desc']
    },
    sponsors: qproc.String,
    count: qproc.Int,
    cost: qproc.Float,
    confirmed: qproc.Boolean,
    'nested.*': qproc.Int,
    'multiple.*.wildcards.*': qproc.Float,
    'adjacent.wildcard.*.*': qproc.String
  },
  meta: {
    calculateTotals: {
      type: 'boolean',
      alias: 'ct'
    }
  },
  projections: ['other']
};

const test = qproc.createMiddleware(options);

const req = {
  query: {
    id: 'alias for _id',
    category: 'in:music,sports,null',
    date: 'gt:2018-01-01,lt:2019-01-01',
    desc: 'regex:/^mastodon/gi',
    sponsors: 'all:Gibson,Fender',
    count: 'lt:1000',
    cost: 'gte:299.99',
    sort: 'desc:date,asc:count',
    limit: '100',
    skip: '-25',
    confirmed: 'true',
    'nested.integer': 'gt:1000',
    'multiple.nested.wildcards.integer': 'gt:50',
    'adjacent.wildcard.test.test': 'test',
    ct: 'false',
    proj: '+cost,other'
  }
};
const res = {};
const next = function (err) {
  if (err) {
    console.log(err);
  }
};

separator();
console.log('TEST: process query parameters in the request');
console.log('EXPECTED RESULT: valid MongoDB query parameters');

console.log('****** REQUEST QUERY INPUT *******\n', req.query);
test(req, res, next);
console.log(
  '********* QPROC OUTPUT **********\n',
  JSON.stringify(req.qproc, null, 2)
);
separator();
