├── .babelrc ├── .editorconfig ├── .github ├── contributing.md ├── issue_template.md └── pull_request_template.md ├── .gitignore ├── .istanbul.yml ├── .npmignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── mocha.opts ├── package.json ├── src └── index.js └── test └── index.test.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": ["add-module-exports"], 3 | "presets": [ "es2015" ] 4 | } 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.github/contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to Feathers 2 | 3 | Thank you for contributing to Feathers! :heart: :tada: 4 | 5 | This repo is the main core and where most issues are reported. Feathers embraces modularity and is broken up across many repos. To make this easier to manage we currently use [Zenhub](https://www.zenhub.com/) for issue triage and visibility. They have a free browser plugin you can install so that you can see what is in flight at any time, but of course you also always see current issues in Github. 6 | 7 | ## Report a bug 8 | 9 | Before creating an issue please make sure you have checked out the docs, specifically the [FAQ](https://docs.feathersjs.com/help/faq.html) section. You might want to also try searching Github. It's pretty likely someone has already asked a similar question. 10 | 11 | If you haven't found your answer please feel free to join our [slack channel](http://slack.feathersjs.com), create an issue on Github, or post on [Stackoverflow](http://stackoverflow.com) using the `feathers` or `feathersjs` tag. We try our best to monitor Stackoverflow but you're likely to get more immediate responses in Slack and Github. 12 | 13 | Issues can be reported in the [issue tracker](https://github.com/feathersjs/feathers/issues). Since feathers combines many modules it can be hard for us to assess the root cause without knowing which modules are being used and what your configuration looks like, so **it helps us immensely if you can link to a simple example that reproduces your issue**. 14 | 15 | ## Report a Security Concern 16 | 17 | We take security very seriously at Feathers. We welcome any peer review of our 100% open source code to ensure nobody's Feathers app is ever compromised or hacked. As a web application developer you are responsible for any security breaches. We do our very best to make sure Feathers is as secure as possible by default. 18 | 19 | In order to give the community time to respond and upgrade we strongly urge you report all security issues to us. Send one of the core team members a PM in [Slack](http://slack.feathersjs.com) or email us at hello@feathersjs.com with details and we will respond ASAP. 20 | 21 | For full details refer to our [Security docs](https://docs.feathersjs.com/SECURITY.html). 22 | 23 | ## Pull Requests 24 | 25 | We :heart: pull requests and we're continually working to make it as easy as possible for people to contribute, including a [Plugin Generator](https://github.com/feathersjs/generator-feathers-plugin) and a [common test suite](https://github.com/feathersjs/feathers-service-tests) for database adapters. 26 | 27 | We prefer small pull requests with minimal code changes. The smaller they are the easier they are to review and merge. A core team member will pick up your PR and review it as soon as they can. They may ask for changes or reject your pull request. This is not a reflection of you as an engineer or a person. Please accept feedback graciously as we will also try to be sensitive when providing it. 28 | 29 | Although we generally accept many PRs they can be rejected for many reasons. We will be as transparent as possible but it may simply be that you do not have the same context or information regarding the roadmap that the core team members have. We value the time you take to put together any contributions so we pledge to always be respectful of that time and will try to be as open as possible so that you don't waste it. :smile: 30 | 31 | **All PRs (except documentation) should be accompanied with tests and pass the linting rules.** 32 | 33 | ### Code style 34 | 35 | Before running the tests from the `test/` folder `npm test` will run ESlint. You can check your code changes individually by running `npm run lint`. 36 | 37 | ### ES6 compilation 38 | 39 | Feathers uses [Babel](https://babeljs.io/) to leverage the latest developments of the JavaScript language. All code and samples are currently written in ES2015. To transpile the code in this repository run 40 | 41 | > npm run compile 42 | 43 | __Note:__ `npm test` will run the compilation automatically before the tests. 44 | 45 | ### Tests 46 | 47 | [Mocha](http://mochajs.org/) tests are located in the `test/` folder and can be run using the `npm run mocha` or `npm test` (with ESLint and code coverage) command. 48 | 49 | ### Documentation 50 | 51 | Feathers documentation is contained in Markdown files in the [feathers-docs](https://github.com/feathersjs/feathers-docs) repository. To change the documentation submit a pull request to that repo, referencing any other PR if applicable, and the docs will be updated with the next release. 52 | 53 | ## External Modules 54 | 55 | If you're written something awesome for Feathers, the Feathers ecosystem, or using Feathers please add it to the [showcase](https://docs.feathersjs.com/why/showcase.html). You also might want to check out the [Plugin Generator](https://github.com/feathersjs/generator-feathers-plugin) that can be used to scaffold plugins to be Feathers compliant from the start. 56 | 57 | If you think it would be a good core module then please contact one of the Feathers core team members in [Slack](http://slack.feathersjs.com) and we can discuss whether it belongs in core and how to get it there. :beers: 58 | 59 | ## Contributor Code of Conduct 60 | 61 | As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. 62 | 63 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 64 | 65 | Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. 66 | 67 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team. 68 | 69 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. 70 | 71 | This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/) 72 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | ### Steps to reproduce 2 | 3 | (First please check that this issue is not already solved as [described 4 | here](https://github.com/feathersjs/feathers/blob/master/.github/contributing.md#report-a-bug)) 5 | 6 | - [ ] Tell us what broke. The more detailed the better. 7 | - [ ] If you can, please create a simple example that reproduces the issue and link to a gist, jsbin, repo, etc. 8 | 9 | ### Expected behavior 10 | Tell us what should happen 11 | 12 | ### Actual behavior 13 | Tell us what happens instead 14 | 15 | ### System configuration 16 | 17 | Tell us about the applicable parts of your setup. 18 | 19 | **Module versions** (especially the part that's not working): 20 | 21 | **NodeJS version**: 22 | 23 | **Operating System**: 24 | 25 | **Browser Version**: 26 | 27 | **React Native Version**: 28 | 29 | **Module Loader**: -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ### Summary 2 | 3 | (If you have not already please refer to the contributing guideline as [described 4 | here](https://github.com/feathersjs/feathers/blob/master/.github/contributing.md#pull-requests)) 5 | 6 | - [ ] Tell us about the problem your pull request is solving. 7 | - [ ] Are there any open issues that are related to this? 8 | - [ ] Is this PR dependent on PRs in other repos? 9 | 10 | If so, please mention them to keep the conversations linked together. 11 | 12 | ### Other Information 13 | 14 | If there's anything else that's important and relevant to your pull 15 | request, mention that information here. This could include 16 | benchmarks, or other information. 17 | 18 | Your PR will be reviewed by a core team member and they will work with you to get your changes merged in a timely manner. If merged your PR will automatically be added to the changelog in the next release. 19 | 20 | If your changes involve documentation updates please mention that and link the appropriate PR in [feathers-docs](https://github.com/feathersjs/feathers-docs). 21 | 22 | Thanks for contributing to Feathers! :heart: -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Commenting this out is preferred by some people, see 24 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- 25 | node_modules 26 | 27 | # Users Environment Variables 28 | .lock-wscript 29 | 30 | lib/ -------------------------------------------------------------------------------- /.istanbul.yml: -------------------------------------------------------------------------------- 1 | verbose: false 2 | instrumentation: 3 | root: src/ 4 | excludes: 5 | - lib/ 6 | include-all-sources: true 7 | reporting: 8 | print: summary 9 | reports: 10 | - html 11 | - text 12 | - lcov 13 | watermarks: 14 | statements: [50, 80] 15 | lines: [50, 80] 16 | functions: [50, 80] 17 | branches: [50, 80] -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .babelrc 2 | .istanbul.yml 3 | .travis.yml 4 | .editorconfig 5 | .idea/ 6 | src/ 7 | test/ 8 | !lib/ 9 | .github/ 10 | coverage -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - node 5 | - '6' 6 | - '4' 7 | addons: 8 | code_climate: 9 | repo_token: d91570a5de532850a5c512e5f5f33a459060b8f38d7ab15487e1eb219e2577ee 10 | before_script: 11 | - 'npm install -g codeclimate-test-reporter' 12 | after_script: 13 | - 'codeclimate-test-reporter < coverage/lcov.info' 14 | notifications: 15 | email: false 16 | slack: 17 | rooms: 18 | secure: p7IzsICC96vuahCIZxV0gYn5197RaLLRFvIg9wxt6VoZ9XWMo2jI6aj2oIFDxc+B7NAkPHrOn7WqSi1U752HSxTNISnTzNmUx6gF4wmsQNLGWvp0GzTcT6TFxYSEg+6J4MD/yMmJC3exv06LvbW5tVxBaGG8hGsI3ZW6Z3gUwZRARU9XfgwQxI2sE4/YnLgHqOf7AvxjkDpR9J561kREouKgSVN9Qqpjx2SjLqHr0to8p01ZIeVSQnkJnp1jzt5wB9wvmaVntpiA1fDK/2KBZkkvS7rN+mnHhrzGYx2sgifEiKhwOmm4vIUb6pkEqc4Tu6Kpzdte5yKpXjcJmbz0hijSBbfxxZeXSgPosvpL0nEx/bLCu1O9aoohByyna+JcxzAXFzsqxnST4Ze5ET0cXxcvvx8a62j/5FylxzaJgnNMQlMrfktzkPB7Ei58ojYEpv33yOTAex0Ue+QFwyU2rQXUOorijqNPPBL3y/pMPKtOWtEzVJnELvrg7oBum99ggAU6yVfCfvIqCqsDpmohxvx/BOl3N2pEECJtgB1td0MggHvVmTE8LRkfy0ItwPYvl3sfREatmkmXnKJ3LlIVDI2myO67uFfUcTSSdx/wz6U/f1Q6LGXNoblVCShCp8dZSNKZ+bUkUlQY/eSkMndowmVfBqc5RgOfgh2cIfqrNHA= 19 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [v2.1.1](https://github.com/feathersjs/feathers-query-filters/tree/v2.1.1) (2016-10-14) 4 | [Full Changelog](https://github.com/feathersjs/feathers-query-filters/compare/v2.1.0...v2.1.1) 5 | 6 | **Merged pull requests:** 7 | 8 | - add the posibility to send an object to sort and add the test for that [\#24](https://github.com/feathersjs/feathers-query-filters/pull/24) ([stalinb87](https://github.com/stalinb87)) 9 | 10 | ## [v2.1.0](https://github.com/feathersjs/feathers-query-filters/tree/v2.1.0) (2016-09-28) 11 | [Full Changelog](https://github.com/feathersjs/feathers-query-filters/compare/v2.0.2...v2.1.0) 12 | 13 | **Merged pull requests:** 14 | 15 | - Convert sort parameters to integers [\#21](https://github.com/feathersjs/feathers-query-filters/pull/21) ([daffl](https://github.com/daffl)) 16 | 17 | ## [v2.0.2](https://github.com/feathersjs/feathers-query-filters/tree/v2.0.2) (2016-09-18) 18 | [Full Changelog](https://github.com/feathersjs/feathers-query-filters/compare/v2.0.1...v2.0.2) 19 | 20 | **Closed issues:** 21 | 22 | - Max pagination limit bug [\#19](https://github.com/feathersjs/feathers-query-filters/issues/19) 23 | 24 | **Merged pull requests:** 25 | 26 | - Fix max pagination limit [\#20](https://github.com/feathersjs/feathers-query-filters/pull/20) ([samhunta](https://github.com/samhunta)) 27 | - Update mocha to version 3.0.0 🚀 [\#18](https://github.com/feathersjs/feathers-query-filters/pull/18) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 28 | 29 | ## [v2.0.1](https://github.com/feathersjs/feathers-query-filters/tree/v2.0.1) (2016-07-25) 30 | [Full Changelog](https://github.com/feathersjs/feathers-query-filters/compare/v2.0.0...v2.0.1) 31 | 32 | ## [v2.0.0](https://github.com/feathersjs/feathers-query-filters/tree/v2.0.0) (2016-07-09) 33 | [Full Changelog](https://github.com/feathersjs/feathers-query-filters/compare/v1.5.1...v2.0.0) 34 | 35 | **Fixed bugs:** 36 | 37 | - params.query is empty in an after hook [\#15](https://github.com/feathersjs/feathers-query-filters/issues/15) 38 | 39 | **Closed issues:** 40 | 41 | - Support $search [\#12](https://github.com/feathersjs/feathers-query-filters/issues/12) 42 | 43 | **Merged pull requests:** 44 | 45 | - Make sure to not modify the original query object [\#17](https://github.com/feathersjs/feathers-query-filters/pull/17) ([daffl](https://github.com/daffl)) 46 | - mocha@2.5.0 breaks build 🚨 [\#16](https://github.com/feathersjs/feathers-query-filters/pull/16) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 47 | - Update babel-plugin-add-module-exports to version 0.2.0 🚀 [\#14](https://github.com/feathersjs/feathers-query-filters/pull/14) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 48 | - Update all dependencies 🌴 [\#9](https://github.com/feathersjs/feathers-query-filters/pull/9) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 49 | 50 | ## [v1.5.1](https://github.com/feathersjs/feathers-query-filters/tree/v1.5.1) (2016-01-22) 51 | [Full Changelog](https://github.com/feathersjs/feathers-query-filters/compare/v1.4.1...v1.5.1) 52 | 53 | **Merged pull requests:** 54 | 55 | - Upgrading to Babel 6 and fixing build [\#8](https://github.com/feathersjs/feathers-query-filters/pull/8) ([daffl](https://github.com/daffl)) 56 | 57 | ## [v1.4.1](https://github.com/feathersjs/feathers-query-filters/tree/v1.4.1) (2016-01-22) 58 | [Full Changelog](https://github.com/feathersjs/feathers-query-filters/compare/v1.5.0...v1.4.1) 59 | 60 | **Merged pull requests:** 61 | 62 | - Adding nsp check [\#7](https://github.com/feathersjs/feathers-query-filters/pull/7) ([marshallswain](https://github.com/marshallswain)) 63 | 64 | ## [v1.5.0](https://github.com/feathersjs/feathers-query-filters/tree/v1.5.0) (2016-01-08) 65 | [Full Changelog](https://github.com/feathersjs/feathers-query-filters/compare/v1.4.0...v1.5.0) 66 | 67 | ## [v1.4.0](https://github.com/feathersjs/feathers-query-filters/tree/v1.4.0) (2016-01-08) 68 | [Full Changelog](https://github.com/feathersjs/feathers-query-filters/compare/v1.3.0...v1.4.0) 69 | 70 | **Closed issues:** 71 | 72 | - Support $populate [\#6](https://github.com/feathersjs/feathers-query-filters/issues/6) 73 | 74 | ## [v1.3.0](https://github.com/feathersjs/feathers-query-filters/tree/v1.3.0) (2015-12-03) 75 | [Full Changelog](https://github.com/feathersjs/feathers-query-filters/compare/v1.1.2...v1.3.0) 76 | 77 | ## [v1.1.2](https://github.com/feathersjs/feathers-query-filters/tree/v1.1.2) (2015-12-03) 78 | [Full Changelog](https://github.com/feathersjs/feathers-query-filters/compare/v1.2.0...v1.1.2) 79 | 80 | **Closed issues:** 81 | 82 | - $limit and $skip should be parsed as integers [\#4](https://github.com/feathersjs/feathers-query-filters/issues/4) 83 | - Should have a test suite for CRUD adapters [\#2](https://github.com/feathersjs/feathers-query-filters/issues/2) 84 | - Latest version \(1.1.1\) provided by npm not available on the repo [\#1](https://github.com/feathersjs/feathers-query-filters/issues/1) 85 | 86 | **Merged pull requests:** 87 | 88 | - Parse $skip and $limit as integers [\#5](https://github.com/feathersjs/feathers-query-filters/pull/5) ([daffl](https://github.com/daffl)) 89 | 90 | ## [v1.2.0](https://github.com/feathersjs/feathers-query-filters/tree/v1.2.0) (2015-10-26) 91 | [Full Changelog](https://github.com/feathersjs/feathers-query-filters/compare/v1.1.1...v1.2.0) 92 | 93 | **Merged pull requests:** 94 | 95 | - Updating to new ES6 plugin infrastructure [\#3](https://github.com/feathersjs/feathers-query-filters/pull/3) ([daffl](https://github.com/daffl)) 96 | 97 | ## [v1.1.1](https://github.com/feathersjs/feathers-query-filters/tree/v1.1.1) (2015-07-28) 98 | [Full Changelog](https://github.com/feathersjs/feathers-query-filters/compare/v1.1.0...v1.1.1) 99 | 100 | ## [v1.1.0](https://github.com/feathersjs/feathers-query-filters/tree/v1.1.0) (2015-07-28) 101 | [Full Changelog](https://github.com/feathersjs/feathers-query-filters/compare/v1.0.0...v1.1.0) 102 | 103 | ## [v1.0.0](https://github.com/feathersjs/feathers-query-filters/tree/v1.0.0) (2015-07-27) 104 | 105 | 106 | \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Feathers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # feathers-query-filters 2 | 3 | [![Greenkeeper badge](https://badges.greenkeeper.io/feathersjs/feathers-query-filters.svg)](https://greenkeeper.io/) 4 | 5 | > Adds support for special query string params used for filtering data in [FeatherJS](https://github.com/feathersjs) 6 | 7 | [![Build Status](https://travis-ci.org/feathersjs/feathers-query-filters.png?branch=master)](https://travis-ci.org/feathersjs/feathers-query-filters) 8 | [![Code Climate](https://codeclimate.com/github/feathersjs/feathers-query-filters/badges/gpa.svg)](https://codeclimate.com/github/feathersjs/feathers-query-filters) 9 | [![Test Coverage](https://codeclimate.com/github/feathersjs/feathers-query-filters/badges/coverage.svg)](https://codeclimate.com/github/feathersjs/feathers-query-filters/coverage) 10 | [![Dependency Status](https://img.shields.io/david/feathersjs/feathers-query-filters.svg?style=flat-square)](https://david-dm.org/feathersjs/feathers-query-filters) 11 | [![Download Status](https://img.shields.io/npm/dm/feathers-query-filters.svg?style=flat-square)](https://www.npmjs.com/package/feathers-query-filters) 12 | [![Slack Status](http://slack.feathersjs.com/badge.svg)](http://slack.feathersjs.com) 13 | 14 | > __Important:__ This package has been integrated into [@feathersjs/commons](https://github.com/feathersjs/commons) (`const { filterQuery } = require('@feathersjs/commons')`). 15 | 16 | ## Getting Started 17 | 18 | `feathers-query-filters` is used internally by the [database service adapters](http://docs.feathersjs.com/databases/readme.html) to support [pagination and sorting](http://docs.feathersjs.com/databases/pagination.html). 19 | 20 | ## License 21 | 22 | [MIT](LICENSE) 23 | 24 | ## Author 25 | 26 | [Feathers contributors](https://github.com/feathersjs/feathers-query-filters/graphs/contributors) 27 | -------------------------------------------------------------------------------- /mocha.opts: -------------------------------------------------------------------------------- 1 | --recursive test/ 2 | --compilers js:babel-core/register -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "feathers-query-filters", 3 | "description": "Adds support for special query string params used for filtering data", 4 | "version": "2.1.2", 5 | "license": "MIT", 6 | "homepage": "https://github.com/feathersjs/feathers-query-filters", 7 | "main": "lib/index", 8 | "keywords": [ 9 | "feathers", 10 | "feathers-plugin", 11 | "REST", 12 | "Socket.io", 13 | "realtime", 14 | "nedb", 15 | "service", 16 | "filters", 17 | "sort", 18 | "limit", 19 | "skip", 20 | "select" 21 | ], 22 | "licenses": [ 23 | { 24 | "type": "MIT", 25 | "url": "https://github.com/feathersjs/feathers-query-filters/blob/master/LICENSE" 26 | } 27 | ], 28 | "repository": { 29 | "type": "git", 30 | "url": "git://github.com/feathersjs/feathers-query-filters.git" 31 | }, 32 | "author": { 33 | "name": "Feathers contributors", 34 | "email": "hello@feathersjs.com", 35 | "url": "https://feathersjs.com" 36 | }, 37 | "contributors": [ 38 | "Eric Kryski (http://erickryski.com)", 39 | "David Luecke (http://neyeon.com)", 40 | "Marshall Thompson (https://github.com/marshallswain)" 41 | ], 42 | "bugs": { 43 | "url": "https://github.com/feathersjs/feathers-query-filters/issues" 44 | }, 45 | "engines": { 46 | "node": ">= 4" 47 | }, 48 | "scripts": { 49 | "prepublish": "npm run compile", 50 | "publish": "git push origin && git push origin --tags", 51 | "release:patch": "npm version patch && npm publish", 52 | "release:minor": "npm version minor && npm publish", 53 | "release:major": "npm version major && npm publish", 54 | "compile": "rimraf lib/ && babel -d lib/ src/", 55 | "lint": "eslint-if-supported semistandard --fix", 56 | "mocha": "mocha --opts mocha.opts", 57 | "coverage": "istanbul cover node_modules/mocha/bin/_mocha -- --opts mocha.opts", 58 | "test": "npm run compile && npm run lint && npm run coverage" 59 | }, 60 | "semistandard": { 61 | "env": [ 62 | "mocha" 63 | ], 64 | "ignore": [ 65 | "/lib" 66 | ] 67 | }, 68 | "directories": { 69 | "lib": "lib" 70 | }, 71 | "greenkeeper": { 72 | "ignore": [ 73 | "feathers-commons", 74 | "babel-cli", 75 | "babel-core", 76 | "babel-plugin-add-module-exports", 77 | "babel-preset-es2015", 78 | "chai", 79 | "eslint-if-supported", 80 | "feathers", 81 | "istanbul", 82 | "mocha", 83 | "rimraf", 84 | "semistandard" 85 | ] 86 | }, 87 | "dependencies": { 88 | "feathers-commons": "^0.8.0" 89 | }, 90 | "devDependencies": { 91 | "babel-cli": "^6.4.5", 92 | "babel-core": "^6.4.5", 93 | "babel-plugin-add-module-exports": "^0.2.0", 94 | "babel-preset-es2015": "^6.3.13", 95 | "chai": "^4.0.0", 96 | "eslint-if-supported": "^1.0.1", 97 | "feathers": "^2.0.0", 98 | "istanbul": "^1.1.0-alpha.1", 99 | "mocha": "^4.0.0", 100 | "rimraf": "^2.5.4", 101 | "semistandard": "^12.0.0" 102 | } 103 | } -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import { _ } from 'feathers-commons'; 2 | 3 | const PROPERTIES = ['$sort', '$limit', '$skip', '$select', '$populate']; 4 | 5 | function parse (number) { 6 | if (typeof number !== 'undefined') { 7 | return Math.abs(parseInt(number, 10)); 8 | } 9 | } 10 | 11 | function getLimit (limit, paginate) { 12 | if (paginate && paginate.default) { 13 | const lower = typeof limit === 'number' ? limit : paginate.default; 14 | const upper = typeof paginate.max === 'number' ? paginate.max : Number.MAX_VALUE; 15 | 16 | return Math.min(lower, upper); 17 | } 18 | 19 | return limit; 20 | } 21 | 22 | function convertSort (sort) { 23 | if (typeof sort !== 'object') { 24 | return sort; 25 | } 26 | 27 | const result = {}; 28 | 29 | Object.keys(sort).forEach(key => (result[key] = typeof sort[key] === 'object' ? sort[key] : parseInt(sort[key], 10))); 30 | 31 | return result; 32 | } 33 | 34 | export default function (query, paginate) { 35 | let filters = { 36 | $sort: convertSort(query.$sort), 37 | $limit: getLimit(parse(query.$limit), paginate), 38 | $skip: parse(query.$skip), 39 | $select: query.$select, 40 | $populate: query.$populate 41 | }; 42 | 43 | return { filters, query: _.omit(query, ...PROPERTIES) }; 44 | } 45 | -------------------------------------------------------------------------------- /test/index.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-expressions */ 2 | 3 | import chai from 'chai'; 4 | import filter from '../src/'; 5 | 6 | const expect = chai.expect; 7 | 8 | describe('Feathers Query Filters', function () { 9 | it('is CommonJS compatible', () => { 10 | expect(typeof require('../lib')).to.equal('function'); 11 | }); 12 | 13 | describe('$sort', function () { 14 | it('returns $sort when present in query', function () { 15 | const { filters, query } = filter({ $sort: { name: 1 } }); 16 | expect(filters.$sort.name).to.equal(1); 17 | expect(query).to.deep.equal({}); 18 | }); 19 | 20 | it('returns $sort when present in query as an object', function () { 21 | const { filters, query } = filter({ $sort: { name: {something: 10} } }); 22 | expect(filters.$sort.name.something).to.equal(10); 23 | expect(query).to.deep.equal({}); 24 | }); 25 | 26 | it('converts strings in $sort', function () { 27 | const { filters, query } = filter({ $sort: { test: '-1' } }); 28 | expect(filters.$sort.test).to.equal(-1); 29 | expect(query).to.deep.equal({}); 30 | }); 31 | 32 | it('returns undefined when not present in query', function () { 33 | const query = { $foo: 1 }; 34 | const { filters } = filter(query); 35 | expect(filters.$sort).to.be.undefined; 36 | }); 37 | }); 38 | 39 | describe('$limit', function () { 40 | beforeEach(function () { 41 | this.query = { $limit: 1 }; 42 | }); 43 | 44 | it('returns $limit when present in query', function () { 45 | const { filters, query } = filter(this.query); 46 | expect(filters.$limit).to.equal(1); 47 | expect(query).to.deep.equal({}); 48 | }); 49 | 50 | it('returns undefined when not present in query', function () { 51 | const query = { $foo: 1 }; 52 | const { filters } = filter(query); 53 | expect(filters.$limit).to.be.undefined; 54 | }); 55 | 56 | it('removes $limit from query when present', function () { 57 | expect(filter(this.query).query).to.deep.equal({}); 58 | }); 59 | 60 | it('parses $limit strings into integers (#4)', function () { 61 | const { filters } = filter({ $limit: '2' }); 62 | expect(filters.$limit).to.equal(2); 63 | }); 64 | 65 | it('allows $limit 0', function () { 66 | const { filters } = filter({ $limit: 0 }, { default: 10 }); 67 | expect(filters.$limit).to.equal(0); 68 | }); 69 | 70 | describe('pagination', function () { 71 | it('limits with default pagination', function () { 72 | const { filters } = filter({}, { default: 10 }); 73 | expect(filters.$limit).to.equal(10); 74 | }); 75 | 76 | it('limits with max pagination', function () { 77 | const { filters } = filter({ $limit: 20 }, { default: 5, max: 10 }); 78 | const { filters: filtersNeg } = filter({ $limit: -20 }, { default: 5, max: 10 }); 79 | expect(filters.$limit).to.equal(10); 80 | expect(filtersNeg.$limit).to.equal(10); 81 | }); 82 | }); 83 | }); 84 | 85 | describe('$skip', function () { 86 | beforeEach(function () { 87 | this.query = { $skip: 1 }; 88 | }); 89 | 90 | it('returns $skip when present in query', function () { 91 | const { filters } = filter(this.query); 92 | expect(filters.$skip).to.equal(1); 93 | }); 94 | 95 | it('removes $skip from query when present', function () { 96 | expect(filter(this.query).query).to.deep.equal({}); 97 | }); 98 | 99 | it('returns undefined when not present in query', function () { 100 | const query = { $foo: 1 }; 101 | const { filters } = filter(query); 102 | expect(filters.$skip).to.be.undefined; 103 | }); 104 | 105 | it('parses $skip strings into integers (#4)', function () { 106 | const { filters } = filter({ $skip: '33' }); 107 | expect(filters.$skip).to.equal(33); 108 | }); 109 | }); 110 | 111 | describe('$select', function () { 112 | beforeEach(function () { 113 | this.query = { $select: 1 }; 114 | }); 115 | 116 | it('returns $select when present in query', function () { 117 | const { filters } = filter(this.query); 118 | expect(filters.$select).to.equal(1); 119 | }); 120 | 121 | it('removes $select from query when present', function () { 122 | expect(filter(this.query).query).to.deep.equal({}); 123 | }); 124 | 125 | it('returns undefined when not present in query', function () { 126 | const query = { $foo: 1 }; 127 | const { filters } = filter(query); 128 | expect(filters.$select).to.be.undefined; 129 | }); 130 | }); 131 | 132 | describe('$populate', function () { 133 | beforeEach(function () { 134 | this.query = { $populate: 1 }; 135 | }); 136 | 137 | it('returns $populate when present in query', function () { 138 | const { filters } = filter(this.query); 139 | expect(filters.$populate).to.equal(1); 140 | }); 141 | 142 | it('removes $populate from query when present', function () { 143 | expect(filter(this.query).query).to.deep.equal({}); 144 | }); 145 | 146 | it('returns undefined when not present in query', function () { 147 | const query = { $foo: 1 }; 148 | const { filters } = filter(query); 149 | expect(filters.$populate).to.be.undefined; 150 | }); 151 | }); 152 | }); 153 | --------------------------------------------------------------------------------