UNPKG

react-native-ibm-mobilefirst-jsonstore

Version:

React Native SDK for IBM JSONStore. Works with IBM Mobile First

88 lines (75 loc) 3.4 kB
/* Licensed Materials - Property of IBM * 5725-I43 (C) Copyright IBM Corp. 2018. All Rights Reserved. * US Government Users Restricted Rights - Use, duplication or * disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ /* author - Yash Soni | yashsoni21@in.ibm.com */ import { _checkParamClassType, _checkParamType, _mandatoryParam, ParamTypes } from './Utils'; /** * Options that are used to modify the find operation in JSONStoreCollection. */ class JSONStoreFindOptions { /** * @type {number} */ limit; /** * @type {number} */ offset; /** * @type {Array} */ filters; /** * @type {Array} */ sortAscending; /** * @type {Array} */ sortDescending; /** * * @param {number} [limit] - The maximum number of results to be returned. * @param {number} [offset] - The offset of which results will begin. * @param {Array} [filters] - The search fields to be returned on the results of the find operation. * @param {Array} [sortAscending] - The search fields by which the results will be sorted in ascending order. * @param {Array} [sortDescending] - The search fields by which the results will be sorted in descending order. */ constructor(limit = null, offset = null, filters = [], sortAscending = [], sortDescending = []) { _checkParamClassType(filters, Array); _checkParamClassType(sortAscending, Array); _checkParamClassType(sortDescending, Array); this.limit = limit; this.offset = offset; this.filters = filters; this.sortAscending = sortAscending; this.sortDescending = sortDescending; } /** * Add a search filter to the existing list of search fields. * @param {string} filterField - The search field to Filter */ addFilter(filterField = _mandatoryParam('filterField')) { _checkParamType(filterField, ParamTypes.STRING); this.filters.push(filterField); } /** * Add a new search field by which the results will be sorted. The search field will sort the results in a ascending manner against the search field. Note that it will be sorted in the order that they were added. For example, if you add searchField1 and then searchField2, it will sort according to searchField1, and then any ties will be sorted according to searchField2. * @param {string} sortField - The search field that is used for a ascending sort. */ addSortAscending(sortField = _mandatoryParam('sortField')) { _checkParamType(sortField, ParamTypes.STRING); this.sortAscending.push(sortField); } /** * Add a new search field by which the results will be sorted. The search field will sort the results in a descending manner against the search field. Please note that it will be sorted in the order that they were added. For example, if you add searchField1 and then searchField2, it will sort according to searchField1, and then any ties will be sorted according to searchField2. * @param {string} sortField - The search field that is used for a descending sort. */ addSortDescending(sortField = _mandatoryParam('sortField')) { _checkParamType(sortField, ParamTypes.STRING); this.sortDescending.push(sortField); } } export default JSONStoreFindOptions