mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-26 21:19:43 -08:00
61e26804ba
* ⚡ enabled array-type * ⚡ await-thenable on * ⚡ ban-types on * ⚡ default-param-last on * ⚡ dot-notation on * ⚡ member-delimiter-style on * ⚡ no-duplicate-imports on * ⚡ no-empty-interface on * ⚡ no-floating-promises on * ⚡ no-for-in-array on * ⚡ no-invalid-void-type on * ⚡ no-loop-func on * ⚡ no-shadow on * ⚡ ban-ts-comment re enabled * ⚡ @typescript-eslint/lines-between-class-members on * address my own comment * @typescript-eslint/return-await on * @typescript-eslint/promise-function-async on * @typescript-eslint/no-unnecessary-boolean-literal-compare on * @typescript-eslint/no-unnecessary-type-assertion on * prefer-const on * @typescript-eslint/prefer-optional-chain on Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
110 lines
2.8 KiB
TypeScript
110 lines
2.8 KiB
TypeScript
// 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, fromValue: any, toValue: any): IQueryObject {
|
|
return { _between: { _field: field, _from: fromValue, _to: toValue } };
|
|
}
|
|
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): IQueryObject {
|
|
return { _string: query };
|
|
}
|
|
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 } };
|
|
}
|