
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
github.com/guillaumeblaquiere/jsonFilter
Advanced tools
This library allows you to apply post processing filters to the Datastore/Firestore results.
The filter format is API oriented and designed to be provided by an API consumer in param to your its request.
Firestore and datastore have several query limitation for Firestore and for Datastore
array-contains-any or IN is allowed per queryIN or array-contains-any clauseThe library allows you to unlock these limitation:
IN on the set of dataIN conditionNOT IN on set of data> and < operatorsThere is the known limitation of this library. These can be implemented -> Open a feature request!
The filters should be applied only on a small array of results and the filtering overhead is very small
Indeed, the documents have to be read for being filter. If you read thousand of document, you will pay a lot for nothing
In addition, your API response time will take more time because of the high number of documents to recover and the filtering duration.
This library work with Go app and use reflection. It performs 3 things
See example for a practical implementation.
The default filter format is the following
key1=val1,val2:key2.subkey=val3
Where:
Behavior:
The filters are applied on an array of struct. Each element of the struct are evaluate against the filters
Each filter element must return OK for keeping the entry value. The behavior of the 4 operators are different:
=!=><The default filter format use these character
=,!=,<,> by default: by default, by default. by defaultYou can set an Options structure on filter to customize your filter like this
o := &jsonFilter.Options{
MaxDepth: 4,
EqualKeyValueSeparator: "=",
GreaterThanKeyValueSeparator: ">",
LowerThanKeyValueSeparator: "<",
NotEqualKeyValueSeparator: "!=",
ValueSeparator: ",",
KeysSeparator: ":",
ComposedKeySeparator: "->",
}
filter.SetOptions(o)
If you don't define a part of the option, the default value is used for this part (a log message display this)
You can also define the max depth of composed key. By default, this value is set to 0, which means infinite. You can override this value in the option structure.
You can filter on these simple types
Complex type are supported
In JSON, the map representation is the following
{
"mapsSimple":{
"entryMap1":"value1",
"entryMap2":"value2"
},
"mapsStruct":{
"entryMap1": {
"fieldName":"value1"
},
"entryMap2":{
"fieldName":"value2"
},
},
"mapsArray":{
"entryMap1": [
{
"fieldName":"value1"
}
],
"entryMap2":[
{
"fieldName":"value2"
},
]
},
}
The filter key will be the following
mapsSimple.entryMap1 if it's a simple mapmapsStruct.entryMap1.fieldName if it's a map of structuremapsArray.entryMap1.fieldName if it's a map of Array. The array is invisible in the processingThis library is licensed under Apache 2.0. Full license text is available in LICENSE.
FAQs
Unknown package
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.