diff --git a/package-lock.json b/package-lock.json index e4fd57a1..daaaa26d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "feathers-vuex", - "version": "3.16.0", + "version": "3.17.1-0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "3.16.0", + "version": "3.17.1-0", "license": "MIT", "dependencies": { "@feathersjs/adapter-commons": "^4.5.2", diff --git a/package.json b/package.json index f1c12a76..b4aaac2a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "feathers-vuex", "description": "FeathersJS, Vue, and Nuxt for the artisan developer", - "version": "3.16.0", + "version": "3.17.1-0", "homepage": "https:feathers-vuex.feathersjs-ecosystem.com", "main": "dist/", "module": "dist/", diff --git a/src/service-module/service-module.getters.ts b/src/service-module/service-module.getters.ts index a1e3a469..779c1f4d 100644 --- a/src/service-module/service-module.getters.ts +++ b/src/service-module/service-module.getters.ts @@ -42,7 +42,32 @@ export default function makeServiceGetters() { idField, tempsById } = state - const q = _omit(params.query || {}, paramsForServer) + + const paramsForServerByValue = paramsForServer.filter(el => + Array.isArray(el) + ) + + const q = paramsForServerByValue.reduce( + (acc, [key, valueOrPredicate]) => { + if (!acc[key] || (acc[key] && !valueOrPredicate)) return acc + + if ( + ((typeof valueOrPredicate === 'string' || + typeof valueOrPredicate === 'number') && + acc[key] === valueOrPredicate) || + (typeof valueOrPredicate === 'function' && + valueOrPredicate(acc[key])) + ) { + return _omit(acc, key) + } + + return acc + }, + _omit( + params.query || {}, + paramsForServer.filter(el => typeof el === 'string') + ) + ) const { query, filters } = filterQuery(q, { operators: additionalOperators.concat(whitelist) @@ -114,14 +139,22 @@ export default function makeServiceGetters() { return copiesById[id] }, - isCreatePendingById: ({ isIdCreatePending }: ServiceState) => (id: Id) => - isIdCreatePending.includes(id), - isUpdatePendingById: ({ isIdUpdatePending }: ServiceState) => (id: Id) => - isIdUpdatePending.includes(id), - isPatchPendingById: ({ isIdPatchPending }: ServiceState) => (id: Id) => - isIdPatchPending.includes(id), - isRemovePendingById: ({ isIdRemovePending }: ServiceState) => (id: Id) => - isIdRemovePending.includes(id), + isCreatePendingById: + ({ isIdCreatePending }: ServiceState) => + (id: Id) => + isIdCreatePending.includes(id), + isUpdatePendingById: + ({ isIdUpdatePending }: ServiceState) => + (id: Id) => + isIdUpdatePending.includes(id), + isPatchPendingById: + ({ isIdPatchPending }: ServiceState) => + (id: Id) => + isIdPatchPending.includes(id), + isRemovePendingById: + ({ isIdRemovePending }: ServiceState) => + (id: Id) => + isIdRemovePending.includes(id), isSavePendingById: (state: ServiceState, getters) => (id: Id) => getters.isCreatePendingById(id) || getters.isUpdatePendingById(id) || diff --git a/test/service-module/service-module.getters.test.ts b/test/service-module/service-module.getters.test.ts index 83e4c0b1..ea897f13 100644 --- a/test/service-module/service-module.getters.test.ts +++ b/test/service-module/service-module.getters.test.ts @@ -351,6 +351,45 @@ describe('Service Module - Getters', function () { assert(results.total === 1, 'total was correct') }) + it('find with paramsForServer option with specific value as string', function () { + const { state } = this + state.paramsForServer = [['_$client', '1']] + const params = { query: { test: false, _$client: '1' } } + const results = find(state)(params) + + assert(results.data.length === 1, 'the length was correct') + assert(results.data[0]._id === 3, 'the correct record was returned') + assert(results.limit === 0, 'limit was correct') + assert(results.skip === 0, 'skip was correct') + assert(results.total === 1, 'total was correct') + }) + + it('find with paramsForServer option with specific value as number', function () { + const { state } = this + state.paramsForServer = [['_$client', -1]] + const params = { query: { test: false, _$client: -1 } } + const results = find(state)(params) + + assert(results.data.length === 1, 'the length was correct') + assert(results.data[0]._id === 3, 'the correct record was returned') + assert(results.limit === 0, 'limit was correct') + assert(results.skip === 0, 'skip was correct') + assert(results.total === 1, 'total was correct') + }) + + it('find with paramsForServer option with specific value as function', function () { + const { state } = this + state.paramsForServer = [['_$client', value => value === 1]] + const params = { query: { test: false, _$client: 1 } } + const results = find(state)(params) + + assert(results.data.length === 1, 'the length was correct') + assert(results.data[0]._id === 3, 'the correct record was returned') + assert(results.limit === 0, 'limit was correct') + assert(results.skip === 0, 'skip was correct') + assert(results.total === 1, 'total was correct') + }) + it('find with non-whitelisted custom operator fails', function () { const { state } = this const params = { query: { $client: 'test' } }