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 is automatically generated based on the Entityβs props. Virtual fields are excluded
from filtering targets. Relations that create FK (BelongsToOne, OneToOne with
hasJoinColumn) can be filtered using the {relation_name}_id format.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. 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:Validation
sonamuFilter validates the following:
1. Filterable Fields
Only fields defined in the Entityβs props can be filtered. Virtual fields are excluded from filtering targets. However, relations that create FK (BelongsToOne, OneToOne with hasJoinColumn) can be filtered using the {relation_name}_id format.
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 used together with custom filters in ListParams:
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