Skip to content

QueryTransformPipe

NestJS pipe for query parameter normalization.

ts
import { QueryTransformPipe } from '@querry-kit/nest-util';

Constructor

QueryTransformPipe does not require constructor arguments.

ts
const pipe = new QueryTransformPipe();

transform(value, metadata)

Transforms value when both conditions are true:

  • metadata.type === 'query'
  • typeof value === 'object'

Otherwise, the original value is returned unchanged.

ts
const pipe = new QueryTransformPipe();

pipe.transform({ page: '1', 'where.name': 'Ada' }, { type: 'query' } as never);

// { page: 1, where: { name: 'Ada' } }

NestJS Usage

Global registration:

ts
app.useGlobalPipes(new QueryTransformPipe());

Route-level registration:

ts
@UsePipes(new QueryTransformPipe())
@Get()
findMany(@Query() query: unknown) {
  return query;
}

Notes

  • The pipe is decorated as injectable for NestJS compatibility.
  • The parsing behavior is implemented by the parseObject object utility function.
  • Validation is intentionally outside the pipe's responsibility.

Released under the MIT License.