From 20359d8e0f284d1681f62b7345e42361c8a70557 Mon Sep 17 00:00:00 2001 From: Nolan Woods Date: Fri, 10 Jan 2020 09:49:02 -0800 Subject: [PATCH] Merge configs using lodash merge Fixes #97 --- package.json | 8 +++++++- src/api/Request.ts | 18 +++++++++++------- yarn.lock | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 9189aae..d7227be 100644 --- a/package.json +++ b/package.json @@ -44,10 +44,16 @@ "@vuex-orm/core": ">=0.34.0" }, "dependencies": { - "axios": "^0.19.0" + "axios": "^0.19.0", + "lodash.isnil": "latest", + "lodash.merge": "latest", + "lodash.omitby": "latest" }, "devDependencies": { "@types/jest": "^24.0.23", + "@types/lodash.isnil": "^4.0.6", + "@types/lodash.merge": "^4.6.6", + "@types/lodash.omitby": "^4.6.6", "@vuex-orm/core": "^0.34.1", "axios-mock-adapter": "^1.17.0", "codecov": "^3.5.0", diff --git a/src/api/Request.ts b/src/api/Request.ts index 5aca357..1a1e6ce 100644 --- a/src/api/Request.ts +++ b/src/api/Request.ts @@ -1,5 +1,8 @@ import { AxiosInstance, AxiosResponse } from 'axios' import { Model } from '@vuex-orm/core' +import _merge from 'lodash.merge' +import _omitBy from 'lodash.omitby' +import _isNil from 'lodash.isnil' import Config from '../contracts/Config' import Response from './Response' @@ -124,15 +127,16 @@ export default class Request { /** * Create a new config by merging the global config, the model config, - * and the given config. + * and the given config. Any value that is null after the merge will + * have the entire entry removed. */ private createConfig (config: Config): Config { - return { - ...this.config, - ...this.model.globalApiConfig, - ...this.model.apiConfig, - ...config - } + return _omitBy(_merge({}, + this.config, + this.model.globalApiConfig, + this.model.apiConfig, + config + ), _isNil) } /** diff --git a/yarn.lock b/yarn.lock index e1c9e5f..4b84646 100644 --- a/yarn.lock +++ b/yarn.lock @@ -922,6 +922,32 @@ dependencies: jest-diff "^24.3.0" +"@types/lodash.isnil@^4.0.6": + version "4.0.6" + resolved "https://registry.yarnpkg.com/@types/lodash.isnil/-/lodash.isnil-4.0.6.tgz#ff6f07010a69a969c32d5981832cdb4d990ccabf" + integrity sha512-K+9ZVqwWUFKxijX7rPGnrubfTtCQ5VwW0xgPCL5iLBBLg5sUFFXdPG3QxkpGNJil8mgttRqNLSWNweEsUrBXTg== + dependencies: + "@types/lodash" "*" + +"@types/lodash.merge@^4.6.6": + version "4.6.6" + resolved "https://registry.yarnpkg.com/@types/lodash.merge/-/lodash.merge-4.6.6.tgz#b84b403c1d31bc42d51772d1cd5557fa008cd3d6" + integrity sha512-IB90krzMf7YpfgP3u/EvZEdXVvm4e3gJbUvh5ieuI+o+XqiNEt6fCzqNRaiLlPVScLI59RxIGZMQ3+Ko/DJ8vQ== + dependencies: + "@types/lodash" "*" + +"@types/lodash.omitby@^4.6.6": + version "4.6.6" + resolved "https://registry.yarnpkg.com/@types/lodash.omitby/-/lodash.omitby-4.6.6.tgz#d9b392d5f236983d2597b9e977d337faa00af8aa" + integrity sha512-bHkWp4YyTlqPtHgUwEhExcMQNb8V+HjTUzhxgdnw0UhuT0i61aff6RuSlXt4MbQVPJhB/24tb4WBZJQ+LYIQgw== + dependencies: + "@types/lodash" "*" + +"@types/lodash@*": + version "4.14.149" + resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.149.tgz#1342d63d948c6062838fbf961012f74d4e638440" + integrity sha512-ijGqzZt/b7BfzcK9vTrS6MFljQRPn5BFWOx8oE0GYxribu6uV+aA9zZuXI1zc/etK9E8nrgdoF2+LgUw7+9tJQ== + "@types/minimatch@*": version "3.0.3" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" @@ -5305,6 +5331,11 @@ lodash.debounce@^4.0.8: resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af" integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168= +lodash.isnil@latest: + version "4.0.0" + resolved "https://registry.yarnpkg.com/lodash.isnil/-/lodash.isnil-4.0.0.tgz#49e28cd559013458c814c5479d3c663a21bfaa6c" + integrity sha1-SeKM1VkBNFjIFMVHnTxmOiG/qmw= + lodash.kebabcase@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz#8489b1cb0d29ff88195cceca448ff6d6cc295c36" @@ -5315,6 +5346,16 @@ lodash.memoize@4.x, lodash.memoize@^4.1.2: resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe" integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4= +lodash.merge@latest: + version "4.6.2" + resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a" + integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ== + +lodash.omitby@latest: + version "4.6.0" + resolved "https://registry.yarnpkg.com/lodash.omitby/-/lodash.omitby-4.6.0.tgz#5c15ff4754ad555016b53c041311e8f079204791" + integrity sha1-XBX/R1StVVAWtTwEExHo8HkgR5E= + lodash.sortby@^4.7.0: version "4.7.0" resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438" @@ -9064,6 +9105,11 @@ yargs@^13.3.0: y18n "^4.0.0" yargs-parser "^13.1.1" +yarn@^1.21.1: + version "1.21.1" + resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.21.1.tgz#1d5da01a9a03492dc4a5957befc1fd12da83d89c" + integrity sha512-dQgmJv676X/NQczpbiDtc2hsE/pppGDJAzwlRiADMTvFzYbdxPj2WO4PcNyriSt2c4jsCMpt8UFRKHUozt21GQ== + zepto@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/zepto/-/zepto-1.2.0.tgz#e127bd9e66fd846be5eab48c1394882f7c0e4f98"