Skip to content

Simple Parser

@rapiq/parser-simple parses plain object/array input — the URL-query-like "simple" dialect. It is the workhorse parser: express-style req.query objects feed straight into it, and the URL codec builds on it.

sh
npm install @rapiq/core @rapiq/parser-simple

Usage

typescript
import { SchemaRegistry, defineSchema } from '@rapiq/core';
import { SimpleParser } from '@rapiq/parser-simple';

const registry = new SchemaRegistry();
registry.add(defineSchema<User>({
    name: 'user',
    fields: { allowed: ['id', 'name', 'age'] },
    filters: { allowed: ['id', 'name', 'age'] },
    relations: { allowed: ['realm'] },
    sort: { allowed: ['id', 'age'] },
    pagination: { maxLimit: 50 },
}));

const parser = new SimpleParser(registry);

const query = parser.parse({
    fields: ['id', 'name'],
    filters: { name: '~jo~', age: '>=18' },
    relations: ['realm'],
    sort: '-age',
    pagination: { limit: 25 },
}, { schema: 'user' });

parse(input, options) returns a Query. Options:

OptionDescription
schemaA Schema instance or the name of a registered schema. Omit to parse without validation.
fields / filters / relations / pagination / sortSet to false to skip a parameter entirely.

Input formats

Per-parameter input shapes and operator syntax are documented on the parameter pages:

  • Fields — arrays, comma strings, +/- modifiers, per-relation records
  • Filters!, <, <=, >, >=, ~…~, comma lists, null
  • Pagination{ limit, offset }
  • Relations — comma strings, arrays, dotted paths
  • Sort- prefix, comma lists, direction objects

Per-parameter parsers

Each parameter also has a standalone parser class — SimpleFieldsParser, SimpleFiltersParser, SimplePaginationParser, SimpleRelationsParser, SimpleSortParser — with the same (input, { schema }) signature, returning that parameter's AST node. Useful when only one parameter comes from user input.

Released under the MIT License.