Add TheHive & Cortex nodes (#952)

*  TheHive & Cortex nodes

* 🔨 Make changes mentioned in #887

*  Improvements

*  Improvements

*  Improvements

*  Add descriptions

*  Improvements

*  Improvements

Co-authored-by: MedAliMarz <servfrdali@yahoo.fr>
This commit is contained in:
Ricardo Espinoza
2020-12-02 05:24:25 -05:00
committed by GitHub
parent ea79e80c17
commit ea9f61089b
25 changed files with 7549 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
// Query types
export declare type queryIndexSignature = '_field'|'_gt'|'_value'|'_gte'|'_lt'|'_lte'|'_and'|'_or'|'_not'|'_in'|'_contains'|'_id'|'_between'|'_parent'|'_parent'|'_child'|'_type'|'_string'|'_like'|'_wildcard';
export type IQueryObject = {
[key in queryIndexSignature]?: IQueryObject|IQueryObject[]|string|number|object
};
// Query Functions
export function Eq(field: string, value: any):IQueryObject{
return { '_field': field, '_value': value };
}
export function Gt(field: string, value: any):IQueryObject{
return { '_gt': { field: value } };
}
export function Gte(field: string, value: any):IQueryObject{
return { '_gte': { field: value } };
}
export function Lt(field: string, value: any):IQueryObject{
return { '_lt': { field: value } };
}
export function Lte(field: string, value: any):IQueryObject{
return { '_lte': { field: value } };
}
export function And(...criteria: IQueryObject[]): IQueryObject{
return { '_and': criteria };
}
export function Or(...criteria: IQueryObject[]): IQueryObject{
return { '_or': criteria };
}
export function Not(criteria: IQueryObject[]): IQueryObject{
return { '_not': criteria };
}
export function In(field: string, values: any[]): IQueryObject{
return { '_in': { '_field': field, '_values': values } };
}
export function Contains(field: string): IQueryObject{
return { '_contains': field };
}
export function Id(id: string|number): IQueryObject{
return {'_id': id };
}
export function Between(field:string, from_value: any, to_value: any): IQueryObject{
return {'_between': {'_field': field, '_from': from_value, '_to': to_value } };
}
export function ParentId(tpe:string, id:string):IQueryObject{
return { '_parent': {'_type': tpe, '_id': id } };
}
export function Parent(tpe:string, criterion:IQueryObject):IQueryObject{
return { '_parent': {'_type': tpe, '_query': criterion } };
}
export function Child(tpe:string, criterion:IQueryObject):IQueryObject{
return { '_child': {'_type': tpe, '_query': criterion } };
}
export function Type(tpe:string):IQueryObject{
return { '_type': tpe };
}
export function queryString(query_string:string):IQueryObject{
return { '_string': query_string };
}
export function Like(field:string, value:string):IQueryObject{
return { '_like': { '_field': field, '_value': value } };
}
export function StartsWith(field:string, value:string){
if (!value.startsWith('*')){
value = value + '*';
}
return { '_wildcard': { '_field': field, '_value': value } };
}
export function EndsWith(field:string, value:string){
if (!value.endsWith('*')){
value = '*' + value;
}
return { '_wildcard': { '_field': field, '_value': value } };
}
export function ContainsString(field:string, value:string){
if (!value.endsWith('*')){
value = value + '*';
}
if (!value.startsWith('*')){
value = '*' + value;
}
return { '_wildcard': { '_field': field, '_value': value } };
}