@c8y/client
Version:
Client application programming interface to access the Cumulocity IoT-Platform REST services.
97 lines • 4.96 kB
TypeScript
export declare class QueriesUtil {
protected operatorFns: {
__not: (operand: any) => string;
__and: (operand: any) => string;
__or: (operand: any) => string;
__eq: (operand: any, contextKey: any) => string;
__gt: (operand: any, contextKey: any) => string;
__ge: (operand: any, contextKey: any) => string;
__lt: (operand: any, contextKey: any) => string;
__le: (operand: any, contextKey: any) => string;
__in: (operand: any, contextKey: any) => any;
__bygroupid: (operand: any) => string;
__has: (operand: any) => string;
__hasany: (operand: any) => string;
__useFilterQueryString: (queryString: string) => string;
};
/**
* Builds query string from provided query object.
*
* @param query Object containing filters and sort order for querying managed objects. Supported filters are:
* - **__and** - Specifies conditions, e.g. `{__and: [{__has: 'c8y_IsDevice'}, {'count': {__gt: 0}}]}`.
* - **__or** - Specifies alternative conditions, e.g. `{__or: [{__bygroupid: 10300}, {__bygroupid: 10400}]}`.
* - **__eq** - Specified fragment must be equal to given value, e.g. `{'status': 'AVAILABLE'}` (no nested object required).
* - **__lt** - Specified fragment must be less then given value, e.g. `{'count': {__lt: 10}}`.
* - **__gt** - Specified fragment must be greater then given value, e.g. `{'count': {__gt: 0}}`.
* - **__in** - Specified fragment must be equal to one of values in the list, e.g. `{'status': {__in: ['AVAILABLE', 'UNAVAILABLE']}}`.
* - **__not** - Negates condition, e.g. `{__not: {'status': 'AVAILABLE'}}`.
* - **__bygroupid** - True if filtered managed object is assigned to given group, e.g. `{__bygroupid: 10300}`.
* - **__has** - Specified fragment must have a value defined, e.g. `{__has: 'c8y_IsDevice'}`.
* - **__hasany** - Matches objects haing at least one of the fragments defines, e.g. `{__has: ['c8y_IsDevice', 'c8y_Dashboard']}`.
* - **__useFilterQueryString** - Gets rid of the `$filter=()… $orderby=…` parts of a query and keeps only what's between the most
* exterior parentheses of the $filter.
* EXAMPLE: takes a query of the form
* `$filter=(name eq 'RaspPi*') $orderby=name asc`
* and turns it into
* `name eq 'RaspPi*'`
* This is necessary for searching for smart groups, which are identified by their own query
* that needs to be passed through.
*
* Note: if you want to specify the order, you need to wrap your filters within `__filter` property and then add `__orderby` with the array of field paths and sort directions (1 for ascending, -1 for descending), for example:
* - `{ __filter: { ... }, __orderby: [{ 'creationTime': -1 }, { 'name': 1 }] }`
*
* @returns {string} Returns a query string ready to be sent in request params to backend.
*
* **Example**
* ```typescript
* const query = {
* __filter: {
* 'name': 'My Device*',
* 'c8y_Availability.status': {
* __in: ['AVAILABLE', 'UNAVAILABLE']
* },
* 'creationTime': {
* __lt: '2015-11-30T13:28:123Z'
* },
* 'c8y_ActiveAlarmsStatus.critical': {
* __gt: 0
* },
* __or: [
* {__not: {__has: 'c8y_ActiveAlarmsStatus.major'}},
* {
* __or: [
* {__bygroupid: 10300},
* {__bygroupid: 10400}
* ]
* }
* ]
* },
* __orderby: [
* {'name': 1},
* {'creationTime': -1},
* {'c8y_ActiveAlarmsStatus.critical': -1}
* ]
* };
*
* const params = {
* query: queriesUtil.buildQuery(query)
* };
* ```
*/
buildQuery(query: any): string;
buildQueryFilter(queryFilter: any, _queryKey?: any, _glueType?: any): string;
buildQueryOrderby(queryOrderbys: any): string;
addAndFilter(query: any, filter: any): any;
addOrFilter(query: any, filter: any): any;
addFilter(query: any, filter: any, operator: 'and' | 'or'): any;
prependOrderbys(query: any, orderbys: any): any;
appendOrderbys(query: any, orderbys: any): any;
addOrderbys(query: any, orderbys: any, how: 'prepend' | 'append'): any;
extractAndMergeOrderBys(queries: string[]): string;
protected glue(stmts: any[], type: string): any;
protected quoteString(s: any): any;
protected skipEmptyObjects(objs: any[]): any[];
protected isEmptyObject(obj: object): boolean;
private escapeSingleQuote;
}
//# sourceMappingURL=QueriesUtil.d.ts.map