Skip to main content
An example use case for these helpers would be to write a QueryService that wraps a store that does not support the query options natively (e.g. An in memory collection of objects such as a static array of objects). All examples will be based on the following DTO definition.

applyFilter

The applyFilter helper applies a Filter to a single object or an array of objects.

Arguments

  • dto: DTO|DTO[]
    • If a single object a function that will test the dto against the filter, returning true when if it matches the filter.
    • If an array of objects is provided the array will be filtered returning a new array with all elements that match the filter.
  • filter: Filter<DTO> - The filter to check the object[s] against. See Filtering

Example

applySort

The applySort will sort an array of dtos.
Because applySort uses the native Array#sort method it may not exactly match the ordering you would expect from a database.
It is expected that your data types all match. For example if you have a number field that also has some numbers represented as strings the applySort method may not work as expected.

Arguments

  • dto: DTO[] - The array of DTOs to sort.
  • sortFields: SortField<DTO>[] - The sorting criteria. See Sorting

Example

The resulting sorted array would be.

applyPaging

The applyPaging method will apply a limit and/or offset to an array of dtos.

Arguments

  • dto: DTO[] - The array of DTOs to page.
  • paging: Paging - The paging arguments to apply. See Paging

Example

The resulting paged dtos would be.

applyQuery

The applyQuery uses the applyFilter, applySorting, and applyPaging methods to apply a Query to an array of DTOs.

Arguments

  • dto: DTO[] - The array of DTOs to page.
  • query: Query<DTO> - The query to apply to the array of dtos. See Queries

Example

The resulting array of dtos would be.

transformFilter

The transformFilter is used to remap fields in a Filter. This method is commonly used when defining a custom Assembler.

Arguments

  • filter: Filter<From> - The filter you want to transform.
  • fieldMap: QueryFieldMap<From, To> - A map of fields where the key is a key in the From type, and the value is a key in the to type.

Example

The new filter would be

transformSort

The transformSort is used to remap fields in an array of SortField<DTO>[]. This method is commonly used when defining a custom Assembler.

Arguments

  • sortFields: SortField<From>[] - The array of sorting criteria to transform.
  • fieldMap: QueryFieldMap<From, To> - A map of fields where the key is a key in the From type, and the value is a key in the to type.

Example

transformQuery

The transformQuery method uses the transformFilter and transformSort methods to remap a Query. This method is commonly used when defining a custom Assembler.

Arguments

  • sortFields: Query<From> - The query to transform.
  • fieldMap: QueryFieldMap<From, To> - A map of fields where the key is a key in the From type, and the value is a key in the to type.

Example

The resulting query would be.

getFilterComparisons

Used to search a filter get a list of comparison objects for a given key.

Arguments

  • filter: Filter<DTO> - The filter to search.
  • key: keyof DTO - The key in the DTO object to search for in the filter object.

Example

The resulting array would be

getFilterOmitting

Used to get a filter with a given key removed.

Arguments

  • filter: Filter<DTO> - The filter containing the unwanted key.
  • key: keyof DTO - The key in the DTO object to remove in the filter object.

Example

The resulting filter would be
Edit this page