ParseIdPipe
Defined in: src/adapters/nestjs.ts:85
NestJS pipe that validates an untrusted route param against a codec via safeParse.
Marked @Injectable() via Injectable()(ParseIdPipe) at module load time, making it
available for NestJS DI.
Default (no options): throws NotFoundException (404) for brand mismatches and
BadRequestException (400) for malformed IDs.
options.status: remaps the default HTTP status for a reason; when the resolved status
differs from the default, the pipe throws HttpException(reason, status).
options.onError: escape hatch for custom error handling. The hook must throw — it
cannot return a response because PipeTransform.transform has no HTTP context.
- Brand mismatch (
invalid_prefix) →reason: "brand_mismatch", default 404 - Malformed or missing ID →
reason: "malformed", default 400
Example
Section titled “Example”import { ParseIdPipe } from "@smonn/ids/nestjs";import { createTimestampId } from "@smonn/ids";
const usr = createTimestampId("usr");
@Controller("users")class UsersController { @Get(":id") findOne(@Param("id", new ParseIdPipe(usr)) id: Id<"usr">) { return { id }; // Id<"usr">, canonical }}Type Parameters
Section titled “Type Parameters”Brand extends string
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ParseIdPipe<
Brand>(codec,options?):ParseIdPipe<Brand>
Defined in: src/adapters/nestjs.ts:92
Parameters
Section titled “Parameters”IdVerifiableCodec<Brand>
options?
Section titled “options?”Returns
Section titled “Returns”ParseIdPipe<Brand>
Constructor
Section titled “Constructor”new ParseIdPipe<
Brand>(codec,options?):ParseIdPipe<Brand>
Defined in: src/adapters/nestjs.ts:93
Parameters
Section titled “Parameters”IdCodec<Brand>
options?
Section titled “options?”Returns
Section titled “Returns”ParseIdPipe<Brand>
Methods
Section titled “Methods”transform()
Section titled “transform()”Defined in: src/adapters/nestjs.ts:99
Method to implement a custom pipe. Called with two parameters
Parameters
Section titled “Parameters”unknown
argument before it is received by route handler method
_metadata
Section titled “_metadata”ArgumentMetadata
Returns
Section titled “Returns”Id<Brand> | Promise<Id<Brand>>
Implementation of
Section titled “Implementation of”PipeTransform.transform