Skip to content

Filters

Filter the resources according to specific criteria.

  • URL parameter: filter
  • AST nodes: Filters (compound and/or) / Filter { operator, field, value }

Input format

The simple dialect takes an object — keys are field names (or relation.field paths), values encode the operator:

typescript
{
    filters: {
        id: 1,                  // equal
        name: '~jo~',           // contains
        age: '>=18',            // greater than or equal
        'realm.name': 'master', // nested field (relation must be allowed)
    },
}

Multiple keys combine with and.

Operator syntax

ValueOperatorAST operator
1, 'admin'equalEQUAL
'!admin'not equalNOT_EQUAL
'<18'less thanLESS_THAN
'<=18'less than or equalLESS_THAN_EQUAL
'>18'greater thanGREATER_THAN
'>=18'greater than or equalGREATER_THAN_EQUAL
'1,2,3' or [1, 2, 3]in listIN
'!1,2,3'not in listNOT_IN
'jo~'starts withSTARTS_WITH
'!jo~'not starts withNOT_STARTS_WITH
'~jo'ends withENDS_WITH
'!~jo'not ends withNOT_ENDS_WITH
'~jo~'containsCONTAINS
'!~jo~'not containsNOT_CONTAINS
'null' / nullequal nullEQUAL
'!null'not equal nullNOT_EQUAL

Value coercion: numeric strings become numbers ('18'18), 'true'/'false' become booleans, 'null' becomes null.

OR conditions

The simple object dialect combines keys with and. For or combinations, build the Filters tree by hand or use the expression language.

Nested fields

relation.field keys filter on related records. The relation must be permitted by the relations schema, and the field validates against the related schema via schemaMapping.

Schema options

typescript
defineSchema<User>({
    filters: {
        allowed: ['id', 'name', 'age'],
        mapping: { aliasId: 'id' },
        default: new Filter(FilterFieldOperator.EQUAL, 'status', 'active'),
    },
});
OptionDescription
allowedFilterable field names. Omit to allow all; [] blocks the parameter.
defaultCondition applied when the client sends no filters.
mappingAlias → field translation applied before validation.
validatePer-filter hook — inspect/replace a parsed Filter, or reject it.

On violation: dropped silently, or FiltersParseError with throwOnFailure.

Released under the MIT License.