Skip to main content
sonamuFilter is a feature for type-safe filtering of Entity fields. Filterable fields and allowed operators are automatically inferred from the Entity definition, preventing invalid filtering attempts at both type level and runtime.
sonamuFilter only filters props marked "toFilter": true in entity.json. Virtual fields are excluded. Relations that create FK (BelongsToOne, OneToOne with hasJoinColumn) can be filtered using the {relation_name}_id format only when the relation prop also has "toFilter": true. Other fields are rejected with 400.

Basic Usage

Filter Types

FilterQuery

FilterQuery<T> type is automatically generated for each Entity:

FilterCondition

Available operators are determined by the field type:

Operators by Type

Usage Examples

Number Filtering

String Filtering

Date Filtering

Enum Filtering

NULL Check

Combined Conditions (AND)

FK (Foreign Key) Filtering

Relations that create FK (BelongsToOne, OneToOne with hasJoinColumn) can be filtered using the {relation_name}_id format when the relation prop has "toFilter": true. Internally converted to a virtual integer type prop, supporting all numeric operators.
FK filtering requires the {relation_name}_id format, not the relation name itself. For example, if you have an employee relation, use employee_id instead of employee for filtering.

URL Query String

Filters can be passed as URL query strings from the frontend:
String values parsed by Fastify are automatically converted to appropriate types:

Validation

sonamuFilter validates the following:

1. Filterable Fields

Only props marked with "toFilter": true in the entity JSON can be filtered. sonamuFilter arrives directly from HTTP requests, so a column without toFilter (for example a password hash hidden by every subset) must never be filterable; otherwise the total of a count query reveals its value one character at a time. Virtual fields are never filterable. Relations that create FK (BelongsToOne, OneToOne with hasJoinColumn) and have "toFilter": true can be filtered using the {relation_name}_id format. A filter that fails validation throws BadRequestException (HTTP 400) before any query runs.

2. Supported Operators

Only operators appropriate for the field type can be used.

3. Enum Values

Enum type fields only allow defined values.

Relationship with Existing Filters

sonamuFilter can be combined with the other ListParams fields, such as the built-in id filter and any custom filters you add to the entity’s ListParams:
If existing filters and sonamuFilter filter the same field, both conditions are applied with AND. Avoid duplicate filtering on the same field to prevent unintended results.

Internal Operation

1. Filter Normalization (normalizeFilterQuery)

Converts string values from URL query strings to appropriate types.

2. Validation (validateSonamuFilters)

Validates the filter query based on the Entity’s filter metadata.

3. Query Application (applySonamuFilters)

Applies validated filter conditions to the Puri query builder.

Next Steps

findMany

List queries and pagination

Puri Query Builder

Write advanced queries