hapipal / confidence

Dynamic, declarative configurations
Other
263 stars 43 forks source link

Possible way to merge criteria? #49

Closed jhyland87 closed 3 years ago

jhyland87 commented 8 years ago

I was wondering if there was a way to provide an array for the criteria to filter for? I know the $base and whatever is filtered for via store.get() is merged, but can you merge more than just that by providing an array or something like?

Example...

'use strict';

import * as Confidence from 'confidence';

const store = new Confidence.Store({
    "package-groups": {
        $filter: 'groups',
        $base: [ 'base thingy' ],
        $default: [ 'default' ],
        foo: [ 'baz' ],
        bar: [ 'qux' ]
    }
} );

console.log( store.get('/', { groups: 'foo' }) );
// Result: { 'package-groups': [ 'base thingy', 'baz' ] }

console.log( store.get('/', { groups: ['foo','bar'] }) );
// Result:         { 'package-groups': [ 'base thingy', 'default' ] }
// Desired result: { 'package-groups': [ 'base thingy', 'baz', 'qux' ] }

I realize this is meant for HapiJS, and thats what I use it for mostly, but some of the packages made for HapiJS are pretty useful with just about anything else, such as Joi, as well as Confidence. Im trying to get Confidence working on another (non HapiJS) project, but I need to be able to filter for more than just one thing in the Confidence json object.

I know I could just store.get() multiple times with different filters, and merge the results... But thats pretty messy, id like to avoid that if possible.

Thanks

patrickkettner commented 8 years ago

not currently - but it sounds like a great idea for a PR. Would you be interested in making one? Should just be a type check and iteration if isArray()

devinivy commented 3 years ago

It's been a few years and no PRs have come through, so I am going to close this one out.