Skip to content

Filters: reference

  • Allow-list by spec. Clients send public field names; only fields present in the spec (with a matching kind) are emitted — never a client-supplied column. Unknown fields are silently dropped.
  • Server-owned identifiers. Adapter column references (Drizzle/Kysely columns, Knex/sql-tag identifier strings, Mongo paths, Prisma fields, PostgREST columns, Elasticsearch fields) come from your code, not request data. Knex and sql-tag validate identifier strings and throw on anything outside col / table.col; PostgREST columns must be identifiers (optionally with ->/->> steps).
  • Parameterized values. Every value is bound (Drizzle/Kysely SQL params, Knex ?, Bun.sql/postgres.js template parameters, Mongo/Prisma/Elasticsearch object values) — no string interpolation of user input. PostgREST values travel in the query string, quoted/escaped per its grammar so they can’t change the filter’s structure.
  • Validate the request shape (valibot or your validator) before building.
  • Model types: FieldKind, FieldFilter, TextFilter, NumberFilter, EnumFilter, BooleanFilter, DateFilter, DatePreset, DateUnit, ArrayFilter, ColumnFilter, FiltersRequest, FilterNode, Sort, SortItem, SortDirection, FieldKindSpec, ScalarValue.
  • Compiled AST: CompiledWhere, CompiledCond, CompiledOp, TextMatchOp.
  • Compiler: compileFilters, compileFilterNode, DateFilterResolver, SqlDialect, escapeLike, sqlTextOp.
  • Compact URL codec: compactFilterNode, expandFilterNode, compactFilters, expandFilters, createFilterUrlCodec, OPERATOR_CODE, operatorFromCode, UNIT_CODE, unitFromCode, CompactNode, CompactLeaf.
  • Operators: OPERATORS_BY_KIND and the *_OPERATORS constants + *Operator types.
  • Sort: parseSortParam, serializeSort.
  • Describe: describeFieldFilter, describeColumnFilter, DescribeDate.
  • Resource metadata: ResourceMetadata, FieldMetadata, FieldOption, ResourceCrud, PaginationStyle.
  • Pagination re-exports: parsePaginationParams, fromRelayArgs, toRelayConnection, toRestEnvelope, infinitePaginationOptions (+ types).

@xtandard/lib/filters/{valibot,zod,arktype,effect} (each + @js-temporal/polyfill)

Section titled “@xtandard/lib/filters/{valibot,zod,arktype,effect} (each + @js-temporal/polyfill)”

The four ready-made schema subpaths export the same names: FieldFilterSchema, TextFilterSchema, NumberFilterSchema, EnumFilterSchema, BooleanFilterSchema, DateFilterSchema, DatePresetSchema, ArrayFilterSchema, ColumnFilterSchema, FiltersRequestSchema, FilterNodeSchema, SortItemSchema, SortSchema. Peer is the matching validator (valibot / zod / arktype / effect). For effect 4, @xtandard/lib/filters/effect/v4 exports the same names (/effect stays on effect 3). A *.test-d.ts asserts each schema’s inferred output equals the model type.

@xtandard/lib/filters/tanstack-table (zero deps; TanStack Table v8 and v9)

Section titled “@xtandard/lib/filters/tanstack-table (zero deps; TanStack Table v8 and v9)”
  • Bridge: createTableBridge → TableBridge (kinds, toFilters, fromFilters, globalFilterNode, toFilterNode, toSort, fromSort), TableGlobalFilterOptions.
  • Column builders: textColumn, numberColumn, numberRangeColumn, selectColumn, multiSelectColumn, booleanColumn, dateColumn, arrayColumn, filterColumn, customColumn → TableColumnSpec; inference: InferTableFilterValues, InferTableKinds.
  • Sort / pagination: toSort, fromSort, toPagination, fromPagination, tablePaginationOptions, toCursorPagination, rememberCursor, TableCursors.
  • State types: TableColumnFiltersState, TableSortingState, TablePaginationState.
Entry Peer Key exports
/drizzle drizzle-orm (v0.45 ∪ v1) buildWhere, buildFilterNode, toDrizzleWhere, buildOrderBy, createDrizzleKeyset, combineWhere, dateField/…, FieldSpec, FilterSpec, ColumnOf
/drizzle-rqb — v2 (object): buildWhere, buildFilterNode, toDrizzleRqbWhere, DrizzleRqbWhere. v1 (callback): buildRqbV1Where, buildRqbV1FilterNode, toDrizzleRqbV1Callback, RqbV1Operators, RqbV1Sql. Shared dateField/…, DrizzleRqbFilterSpec
/kysely kysely buildWhere, buildFilterNode, buildOrderBy, toKyselyWhere, dateField/…, KyselyFilterSpec, SqlDialect
/knex — buildWhereSql, buildFilterNodeSql, applyFiltersToKnex, toFilterWhereSql, dateField/…, KnexFilterSpec, SqlDialect
/sql-tag — buildWhere, buildFilterNode, buildOrderBy, toSqlTagWhere, dateField/…, SqlTagFilterSpec, SqlTag, SqlTagFragment, SqlDialect
/mongo — buildFilter, buildFilterNode, toMongoFilter, dateField/…, MongoFilterSpec, MongoFilter
/prisma — buildWhere, buildFilterNode, toPrismaWhere, dateField/…, PrismaFilterSpec, PrismaWhere
/memory — buildFilterPredicate, buildFilterNodePredicate, toFilterPredicate, applyFiltersToArray, buildComparator, createMemoryKeyset, createMemoryPaginator, dateField/…, MemoryFilterSpec, MemoryDialect
/postgrest — buildParams, buildFilterNode, toPostgrestParams, applyParamsToPostgrest, applyFiltersToPostgrest, buildOrder, formatOrder, createPostgrestKeyset, dateField/…, PostgrestFilterSpec, PostgrestParams, PostgrestOrderTerm
/elasticsearch — buildQuery, buildFilterNode, toElasticsearchQuery, buildSort, createElasticsearchKeyset, dateField/…, ElasticsearchFilterSpec, ElasticsearchQuery, ElasticsearchSort
  • A date preset throws. Pass resolveDate — the DST-aware date→instant resolution is injected (a bare date isNull/isNotNull needs nothing).

  • between isn’t SQL BETWEEN. It lowers to >= AND <= (and notBetween to < OR >) on purpose — semantically identical, and avoids the inclusive- upper-bound footgun. The model operator is unchanged.

  • Prisma like throws on some patterns. Internal %/_ can’t be expressed in a Prisma where — reduce to contains/startsWith/endsWith, or use $queryRaw.

  • A filter “disappeared”. Its field isn’t in the spec, or its kind doesn’t match the spec’s kind — it was dropped (by design; never trust client fields).

  • Array ops need a dialect outside Postgres. On kysely/knex/sql-tag they default to PG @>/<@/&& (real array column); pass dialect: "mysql" (JSON column, JSON_CONTAINS/JSON_OVERLAPS) or dialect: "sqlite" (JSON1 json_each subqueries) for those engines — see SQL dialects. drizzle is PG-only (its array helpers are Postgres-specific). Mongo/Prisma approximate ($all/$setIsSubset/hasEvery/…); Prisma’s and Elasticsearch’s arrayContained throw.

  • Elasticsearch eq doesn’t match a text field. Point text/enum specs at a keyword field (name.keyword); term compares the indexed term, not the analyzed tokens.

  • Frontend bundle stays lean. Import only @xtandard/lib/filters (types + compile + describe, zero deps) on the client; keep the adapter import on the server.