diff --git a/CHANGELOG.md b/CHANGELOG.md index 3483434..86d74c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ --- +## [v1.1.1](https://github.com/foxifyjs/foxify-restify-odin/releases/tag/v1.1.1) - *(2018-11-29)* + +- :zap: Added `lk` and `nlk` to filter operators + ## [v1.1.0](https://github.com/foxifyjs/foxify-restify-odin/releases/tag/v1.1.0) - *(2018-11-15)* - :zap: Added ability to set `defaults` for decoded params diff --git a/package-lock.json b/package-lock.json index a8b1d66..cb816ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "foxify-restify-odin", - "version": "1.1.0", + "version": "1.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -61,14 +61,11 @@ "tsutils": "^3.1.0" }, "dependencies": { - "tsutils": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.5.0.tgz", - "integrity": "sha512-/FZ+pEJQixWruFejFxNPRSwg+iF6aw7PYZVRqUscJ7EnzV3zieI8byfZziUR7QjCuJFulq8SEe9JcGflO4ze4Q==", - "dev": true, - "requires": { - "tslib": "^1.8.1" - } + "get-caller-file": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.0.tgz", + "integrity": "sha512-cF41L/f/7nXpSwMMHMY0FIurpTPZq/eHwJdeh2+0kKYhL9eD7RqsgMujd3qdqvWdjGIHjwvd/iEMTNECl2EhzA==", + "dev": true } } }, @@ -106,15 +103,15 @@ } }, "@foxify/odin": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/@foxify/odin/-/odin-0.2.2.tgz", - "integrity": "sha512-nAbaVhrJ1uX5ZEygkFQCiYD18hMzhPJJjjoFijr6a7Ax7jC2+VyoV1uge/gc7K1hyrUdLreTSPvTzejYCkC4lA==", + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/@foxify/odin/-/odin-0.4.1.tgz", + "integrity": "sha512-EaKsrec6vcBObo/I5l6WNXEob06i1P6l/R2mefxE9ED0fXqBWMUNRrgrTYNxZwRhBUPqx6LDAAmoWLhghCHtsg==", "dev": true, "requires": { "@types/graphql": "^0.13.4", "@types/graphql-iso-date": "^3.3.1", "@types/mongodb": "^3.1.14", - "@types/node": "^10.12.7", + "@types/node": "^10.12.9", "async": "^2.6.1", "caller-id": "^0.1.0", "deasync": "^0.1.14", @@ -151,15 +148,15 @@ } }, "@types/jest": { - "version": "23.3.9", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-23.3.9.tgz", - "integrity": "sha512-wNMwXSUcwyYajtbayfPp55tSayuDVU6PfY5gzvRSj80UvxdXEJOVPnUVajaOp7NgXLm+1e2ZDLULmpsU9vDvQw==", + "version": "23.3.10", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-23.3.10.tgz", + "integrity": "sha512-DC8xTuW/6TYgvEg3HEXS7cu9OijFqprVDXXiOcdOKZCU/5PJNLZU37VVvmZHdtMiGOa8wAA/We+JzbdxFzQTRQ==", "dev": true }, "@types/mongodb": { - "version": "3.1.14", - "resolved": "https://registry.npmjs.org/@types/mongodb/-/mongodb-3.1.14.tgz", - "integrity": "sha512-Hc9nhu9Z33Gq8SP2CZluNlhwbXBCEGAzLMQPEceZG0wUt/ZTzIGaeo8RXu7FWNXfUd6JHh6KHl0YjQlu6TgncQ==", + "version": "3.1.15", + "resolved": "https://registry.npmjs.org/@types/mongodb/-/mongodb-3.1.15.tgz", + "integrity": "sha512-JSvtmrdrh88WH0Lo8Hq7sB1FkEChkrt6+fAZdFhEsRXcUetnrdU7wd2yar40tPg5wfRI2t31yduQgPiMUvgEEA==", "dev": true, "requires": { "@types/bson": "*", @@ -167,9 +164,9 @@ } }, "@types/node": { - "version": "10.12.7", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.7.tgz", - "integrity": "sha512-Zh5Z4kACfbeE8aAOYh9mqotRxaZMro8MbBQtR8vEXOMiZo2rGEh2LayJijKdlu48YnS6y2EFU/oo2NCe5P6jGw==", + "version": "10.12.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.10.tgz", + "integrity": "sha512-8xZEYckCbUVgK8Eg7lf5Iy4COKJ5uXlnIOnePN0WUwSQggy9tolM+tDJf7wMOnT/JT/W9xDYIaYggt3mRV2O5w==", "dev": true }, "@types/qs": { @@ -1060,14 +1057,6 @@ "base64-js": "0.0.8", "ieee754": "^1.1.4", "isarray": "^1.0.0" - }, - "dependencies": { - "isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", - "dev": true - } } }, "buffer-alloc": { @@ -1732,6 +1721,12 @@ "resolved": "https://registry.npmjs.org/esutils/-/esutils-1.1.6.tgz", "integrity": "sha1-wBzKqa5LiXxtDD4hCuUvPHqEQ3U=", "dev": true + }, + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "dev": true } } }, @@ -2021,9 +2016,9 @@ "dev": true }, "fast-json-stringify": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/fast-json-stringify/-/fast-json-stringify-1.9.1.tgz", - "integrity": "sha512-vBXDKcJtoruWZeoqq/ViqJ3VxZH5LimgBTczIPe3x6m6XAgNr7fpAdPml81K+kb+rVl4hTJa/6iMVB62Fus+1A==", + "version": "1.9.2", + "resolved": "https://registry.npmjs.org/fast-json-stringify/-/fast-json-stringify-1.9.2.tgz", + "integrity": "sha512-V9XELlr0KZ0XHFkcrS85rcRieEc1hyA1xEi5ClZYKgXpCySSsHDwsVg2A7/7ATF48x0WKqbe/glxBifIRTaE+A==", "dev": true, "requires": { "ajv": "^6.5.4", @@ -2202,13 +2197,13 @@ "dev": true }, "foxify": { - "version": "0.10.14", - "resolved": "https://registry.npmjs.org/foxify/-/foxify-0.10.14.tgz", - "integrity": "sha512-r5gLRKohm3fUGlDJBnesKx7ZKVgff5JP7E4YIlYx1nm8OF8W8bkfWtNbChb72IgrUF/iL06BVDpIuYFQcxg86g==", + "version": "0.10.18", + "resolved": "https://registry.npmjs.org/foxify/-/foxify-0.10.18.tgz", + "integrity": "sha512-JAjo84PFuqHm0Ergp+xPgBFzG9TEugaAG3J/SAlSkoQzbs9ngXLvDDXMBVI5d0NxhA/2h8qyojyF8gnAgEc30A==", "dev": true, "requires": { "@foxify/inject": "^1.0.0", - "@types/node": "^10.12.4", + "@types/node": "^10.12.9", "async": "^2.6.1", "content-disposition": "^0.5.2", "content-type": "^1.0.4", @@ -2216,7 +2211,7 @@ "cookie-signature": "^1.1.0", "dotenv": "^6.1.0", "escape-html": "^1.0.3", - "fast-json-stringify": "^1.9.1", + "fast-json-stringify": "^1.9.2", "mime-types": "^2.1.21", "negotiator": "^0.6.1", "on-finished": "^2.3.0", @@ -2792,9 +2787,9 @@ "dev": true }, "get-caller-file": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.0.tgz", - "integrity": "sha512-cF41L/f/7nXpSwMMHMY0FIurpTPZq/eHwJdeh2+0kKYhL9eD7RqsgMujd3qdqvWdjGIHjwvd/iEMTNECl2EhzA==", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", + "integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==", "dev": true }, "get-port": { @@ -2816,23 +2811,12 @@ "dev": true }, "getos": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/getos/-/getos-3.1.0.tgz", - "integrity": "sha512-i9vrxtDu5DlLVFcrbqUqGWYlZN/zZ4pGMICCAcZoYsX3JA54nYp8r5EThw5K+m2q3wszkx4Th746JstspB0H4Q==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/getos/-/getos-3.1.1.tgz", + "integrity": "sha512-oUP1rnEhAr97rkitiszGP9EgDVYnmchgFzfqRzSkgtfv7ai6tEi7Ko8GgjNXts7VLWEqrTWyhsOKLe5C5b/Zkg==", "dev": true, "requires": { - "async": "2.4.0" - }, - "dependencies": { - "async": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/async/-/async-2.4.0.tgz", - "integrity": "sha1-SZAgDxjqW4N8LMT4wDGmmFw4VhE=", - "dev": true, - "requires": { - "lodash": "^4.14.0" - } - } + "async": "2.6.1" } }, "getpass": { @@ -3423,9 +3407,9 @@ "dev": true }, "isarray": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", "dev": true }, "isexe": { @@ -4465,19 +4449,19 @@ } }, "mongodb": { - "version": "3.1.9", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.1.9.tgz", - "integrity": "sha512-f+Og32wK/ovzVlC1S6Ft7yjVTvNsAOs6pBpDrPd2/3wPO9ijNsQrTNntuECjOSxGZpPVl0aRqgHzF1e9e+KvnQ==", + "version": "3.1.10", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.1.10.tgz", + "integrity": "sha512-Uml42GeFxhTGQVml1XQ4cD0o/rp7J2ROy0fdYUcVitoE7vFqEhKH4TYVqRDpQr/bXtCJVxJdNQC1ntRxNREkPQ==", "dev": true, "requires": { - "mongodb-core": "3.1.8", + "mongodb-core": "3.1.9", "safe-buffer": "^5.1.2" } }, "mongodb-core": { - "version": "3.1.8", - "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.1.8.tgz", - "integrity": "sha512-reWCqIRNehyuLaqaz5JMOmh3Xd8JIjNX34o8mnewXLK2Fyt/Ky6BZbU+X0OPzy8qbX+JZrOtnuay7ASCieTYZw==", + "version": "3.1.9", + "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.1.9.tgz", + "integrity": "sha512-MJpciDABXMchrZphh3vMcqu8hkNf/Mi+Gk6btOimVg1XMxLXh87j6FAvRm+KmwD1A9fpu3qRQYcbQe4egj23og==", "dev": true, "requires": { "bson": "^1.1.0", @@ -4487,9 +4471,9 @@ } }, "mongodb-memory-server": { - "version": "2.7.2", - "resolved": "https://registry.npmjs.org/mongodb-memory-server/-/mongodb-memory-server-2.7.2.tgz", - "integrity": "sha512-qT/iSiQf2cpBrz7Bln5Va2+rd2evkTPTO2HbQW5eZwaShPcSxkL9xhUHuemG/9+0ALUjrF9Dq+Mxvur2YRF24Q==", + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/mongodb-memory-server/-/mongodb-memory-server-2.7.3.tgz", + "integrity": "sha512-VZ7jECwVgXacKgUM3OHP2h1UToQpYDkCb9KLTdoC4I/6kDHTRIGEXUBfk4sw0YcDCELxhDPi4TBwHW2M9K5txw==", "dev": true, "requires": { "@babel/runtime": "^7.1.2", @@ -4497,7 +4481,7 @@ "decompress": "^4.2.0", "find-cache-dir": "^2.0.0", "get-port": "^4.0.0", - "getos": "^3.1.0", + "getos": "^3.1.1", "https-proxy-agent": "^2.2.1", "lockfile": "^1.0.4", "md5-file": "^4.0.0", @@ -5085,9 +5069,9 @@ "dev": true }, "qs": { - "version": "6.5.2", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", - "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" + "version": "6.6.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.6.0.tgz", + "integrity": "sha512-KIJqT9jQJDQx5h5uAVPimw6yVg2SekOKu959OCtktD3FjzbpvaPr8i4zzg07DOMz+igA4W/aNM7OV8H37pFYfA==" }, "randomatic": { "version": "3.1.1", @@ -5300,6 +5284,14 @@ "tough-cookie": "~2.4.3", "tunnel-agent": "^0.6.0", "uuid": "^3.3.2" + }, + "dependencies": { + "qs": { + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", + "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==", + "dev": true + } } }, "request-promise-core": { @@ -6401,9 +6393,9 @@ "dev": true }, "ts-jest": { - "version": "23.10.4", - "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-23.10.4.tgz", - "integrity": "sha512-oV/wBwGUS7olSk/9yWMiSIJWbz5xO4zhftnY3gwv6s4SMg6WHF1m8XZNBvQOKQRiTAexZ9754Z13dxBq3Zgssw==", + "version": "23.10.5", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-23.10.5.tgz", + "integrity": "sha512-MRCs9qnGoyKgFc8adDEntAOP64fWK1vZKnOYU1o2HxaqjdJvGqmkLCPCnVq1/If4zkUmEjKPnCiUisTrlX2p2A==", "dev": true, "requires": { "bs-logger": "0.x", @@ -6412,6 +6404,7 @@ "json5": "2.x", "make-error": "1.x", "mkdirp": "0.x", + "resolve": "1.x", "semver": "^5.5", "yargs-parser": "10.x" }, @@ -6480,14 +6473,14 @@ } }, "tslint-config-airbnb": { - "version": "5.11.0", - "resolved": "https://registry.npmjs.org/tslint-config-airbnb/-/tslint-config-airbnb-5.11.0.tgz", - "integrity": "sha512-o2FhaQtxXi6FQ1v0T2n/rACNos6PhuKRmvemMpWxI+9NJn2OOlJ3+OtEmnCdoF7GPXT3Eyk+Q0q4P96flrPl3w==", + "version": "5.11.1", + "resolved": "https://registry.npmjs.org/tslint-config-airbnb/-/tslint-config-airbnb-5.11.1.tgz", + "integrity": "sha512-hkaittm2607vVMe8eotANGN1CimD5tor7uoY3ypg2VTtEcDB/KGWYbJOz58t8LI4cWSyWtgqYQ5F0HwKxxhlkQ==", "dev": true, "requires": { - "tslint-consistent-codestyle": "^1.13.3", + "tslint-consistent-codestyle": "^1.14.1", "tslint-eslint-rules": "^5.4.0", - "tslint-microsoft-contrib": "~5.2.0" + "tslint-microsoft-contrib": "~5.2.1" } }, "tslint-consistent-codestyle": { @@ -6528,15 +6521,6 @@ "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.0.tgz", "integrity": "sha512-f/qGG2tUkrISBlQZEjEqoZ3B2+npJjIf04H1wuAv9iA8i04Icp+61KRXxFdha22670NJopsZCIjhC3SnjPRKrQ==", "dev": true - }, - "tsutils": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.5.0.tgz", - "integrity": "sha512-/FZ+pEJQixWruFejFxNPRSwg+iF6aw7PYZVRqUscJ7EnzV3zieI8byfZziUR7QjCuJFulq8SEe9JcGflO4ze4Q==", - "dev": true, - "requires": { - "tslib": "^1.8.1" - } } } }, @@ -6561,9 +6545,9 @@ } }, "tsutils": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.5.0.tgz", - "integrity": "sha512-/FZ+pEJQixWruFejFxNPRSwg+iF6aw7PYZVRqUscJ7EnzV3zieI8byfZziUR7QjCuJFulq8SEe9JcGflO4ze4Q==", + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.5.1.tgz", + "integrity": "sha512-g9kwRQRpVDhjS3qfrDsnYv7QkBtsNRm1Ln5539hq9Y2ysndnlaWf8+3zTdaa1YB5ko7dpV9XATlP0KmYPsLc+Q==", "dev": true, "requires": { "tslib": "^1.8.1" @@ -6998,14 +6982,6 @@ "which-module": "^2.0.0", "y18n": "^3.2.1", "yargs-parser": "^8.1.0" - }, - "dependencies": { - "get-caller-file": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", - "integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==", - "dev": true - } } }, "yargs-parser": { diff --git a/package.json b/package.json index cca2cf4..ce971d5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "foxify-restify-odin", - "version": "1.1.0", + "version": "1.1.1", "description": "Easily restify odin databases", "author": "Ardalan Amini [https://github.com/ardalanamini]", "license": "MIT", @@ -34,26 +34,26 @@ }, "dependencies": { "prototyped.js": "^0.20.2", - "qs": "^6.5.2" + "qs": "^6.6.0" }, "peerDependencies": { "@foxify/odin": ">=0.2.2", "foxify": ">=0.10.14" }, "devDependencies": { - "@foxify/odin": "^0.2.2", - "@types/jest": "^23.3.9", + "@foxify/odin": "^0.4.1", + "@types/jest": "^23.3.10", "@types/qs": "^6.5.1", "codecov": "^3.1.0", - "foxify": "^0.10.14", + "foxify": "^0.10.18", "jest": "^23.6.0", "jest-environment-node": "^23.4.0", - "mongodb": "^3.1.9", - "mongodb-memory-server": "^2.7.2", - "ts-jest": "^23.10.4", + "mongodb": "^3.1.10", + "mongodb-memory-server": "^2.7.3", + "ts-jest": "^23.10.5", "tslint": "^5.11.0", - "tslint-config-airbnb": "^5.11.0", - "tsutils": "^3.5.0", + "tslint-config-airbnb": "^5.11.1", + "tsutils": "^3.5.1", "typescript": "^3.1.6" }, "jest": { diff --git a/src/builders/filter.ts b/src/builders/filter.ts index 14b90dd..dcb7453 100644 --- a/src/builders/filter.ts +++ b/src/builders/filter.ts @@ -30,6 +30,10 @@ const operate = (query: typeof Odin, field: string, operator: Operator, value: a return query.whereBetween(field, value[0], value[1]); case "nbe": return query.whereNotBetween(field, value[0], value[1]); + case "lk": + return query.whereLike(field, value); + case "nlk": + return query.whereNotLike(field, value); default: throw new TypeError("Unknown operator"); } diff --git a/src/index.ts b/src/index.ts index dafe33b..dc7992f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ import query from "./query"; namespace restify { export type Operator = "lt" | "lte" | "eq" | "ne" | "gte" | "gt" | - "ex" | "in" | "nin" | "bet" | "nbe"; + "ex" | "in" | "nin" | "bet" | "nbe" | "lk" | "nlk"; export interface FilterObject { field: string; @@ -34,7 +34,7 @@ const restify = (model: typeof Odin, defaults: restify.Query = {}) => { } // tslint:disable-next-line:variable-name - const foxify_restify_odin: Foxify.Handler = (req, res, next) => { + const foxifyRestifyOdin: Foxify.Handler = function foxify_restify_odin(req, res, next) { const parsed = parse((req.url as string).replace(/^.*\?/, "")); const decoded = Object.assign({}, defaults, decoder(parsed)); @@ -47,7 +47,7 @@ const restify = (model: typeof Odin, defaults: restify.Query = {}) => { next(); }; - return foxify_restify_odin; + return foxifyRestifyOdin; }; export = restify; diff --git a/test/filter.ts b/test/filter.ts index 3f1d311..abb79e5 100644 --- a/test/filter.ts +++ b/test/filter.ts @@ -300,3 +300,33 @@ it("Should filter (5)", async () => { expect(JSON.parse(result.body)) .toEqual({ users, total: users.length }); }); + +it("Should filter (6)", async () => { + expect.assertions(2); + + const app = new Foxify(); + + app.get("/users", restify(User), async (req, res) => { + expect(req.fro).toBeDefined(); + + res.json({ + users: await req.fro.query.get(), + total: await req.fro.counter.count(), + }); + }); + + const result = await app.inject(`/users?${stringify( + { + filter: { + field: "name.first", + operator: "lk", + value: "arda", + }, + }, + )}`); + + const users = ITEMS.filter(({ name }) => /arda/i.test(name.first)); + + expect(JSON.parse(result.body)) + .toEqual({ users, total: users.length }); +});