Registry / database / qast
library2.1.3jsnpmunverified

QAST v2.1.3 is a zero-dependency, ORM-agnostic library that parses human-readable query strings (e.g., 'age gt 25 and name eq "John"') into an AST and converts it into filters for Prisma, TypeORM, Sequelize, Mongoose, Knex, and Drizzle. Actively maintained; ships TypeScript types. Key differentiators: zero runtime dependencies, optional whitelists and field constraints for safety, OpenAPI helpers, and support for multiple ORMs via optional peer dependencies.

npm install qast
INSTALL
IMPORT
SIG · QAST
Q
qast
databasejavascriptv2.1.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parseQuery
import { parseQuery } from 'qast'
const qast = require('qast'); const parseQuery = qast.parseQuery;
ESM-only since v2; CommonJS require with destructuring is not supported. Use ESM imports.
toPrismaFilter
import { toPrismaFilter } from 'qast'
Available since v1. Ensure @prisma/client is installed as a peer dependency.
toSequelizeFilter
import { toSequelizeFilter } from 'qast'
Works with Sequelize v6+. Uses Op symbols internally.
parseQueryFull
import { parseQueryFull } from 'qast'
import { parseFull } from 'qast'
The correct name is 'parseQueryFull', not 'parseFull' or 'parseQueryFull' misspelled.
openApiFilterParameter
import { openApiFilterParameter } from 'qast'
Generates OpenAPI 3.x query parameter spec. Only for filter strings, not full query.

Parse a filter query string into an AST and apply it as a Prisma where clause.

import { parseQuery, toPrismaFilter } from 'qast'; import { PrismaClient } from '@prisma/client'; const prisma = new PrismaClient(); const raw = "age gt 25 and (name eq 'John' or city eq 'Paris')"; const ast = parseQuery(raw, { allowedFields: ['age', 'name', 'city'], validate: true, }); const filter = toPrismaFilter(ast); // filter: { AND: [ { age: { gt: 25 } }, { OR: [ { name: { equals: 'John' } }, { city: { equals: 'Paris' } } ] } ] } const users = await prisma.user.findMany({ where: filter }); console.log(users); // String literals must be quoted: 'single quotes' or "double quotes" are both valid. // Numeric values are parsed as numbers. // Booleans: true/false (unquoted).
Debug
Known issues
breakingIn v2.0.0, the package switched from CommonJS to ESM-only. require() will throw ERR_REQUIRE_ESM.
fix
Use import syntax or migrate to dynamic import().
affects: >=2.0.0
gotchaString literals in queries must be quoted. Unquoted strings will be parsed as field names or cause errors.
fix
Always wrap string values in single or double quotes, e.g., name eq 'John'.
affects: >=1.0.0
gotchaField names are case-sensitive and must match exactly with your database schema. The adapter does not transform case.
fix
Ensure allowedFields and query field names match your ORM column/property names.
affects: >=1.0.0
deprecatedThe 'toKnexFilter' adapter uses Knex's deprecated 'whereRaw' syntax in some complex queries. It will be updated in v3.
fix
Use Knex's native query builder or migrate to a different adapter if Knex support is critical.
affects: >=2.0.0 <3.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Using require('qast') in a CommonJS file with Node.js >=16.
fix
Use import { parseQuery } from 'qast' in an ESM module, or use dynamic import: const qast = await import('qast').
TypeError: (0 , qast.toPrismaFilter) is not a function
Incorrect import or destructuring of a CommonJS default export.
fix
Use import { toPrismaFilter } from 'qast' instead of const qast = require('qast'); qast.toPrismaFilter().
Error: Unknown operator 'gt'
The operator 'gt' is not in the allowedOperators list.
fix
Add 'gt' to allowedOperators in parseQuery options, or use a different operator.
Upgrade
Version history
2.1.3latest on npm
Audit
Dependencies
@prisma/clientoptionalOptional peer dependency needed for Prisma adapter
drizzle-ormoptionalOptional peer dependency needed for Drizzle adapter
knexoptionalOptional peer dependency needed for Knex adapter
mongooseoptionalOptional peer dependency needed for Mongoose adapter
sequelizeoptionalOptional peer dependency needed for Sequelize adapter
typeormoptionalOptional peer dependency needed for TypeORM adapter
Agent activity
11 hits · last 30 days
node
8
Resources
packageqast
qast — npm install qast · libregistry