Skip to content

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
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
}
}

Brand extends string

  • PipeTransform<unknown, Id<Brand> | Promise<Id<Brand>>>

new ParseIdPipe<Brand>(codec, options?): ParseIdPipe<Brand>

Defined in: src/adapters/nestjs.ts:92

IdVerifiableCodec<Brand>

IdParamVerifyOptions

ParseIdPipe<Brand>

new ParseIdPipe<Brand>(codec, options?): ParseIdPipe<Brand>

Defined in: src/adapters/nestjs.ts:93

IdCodec<Brand>

IdParamOptions

ParseIdPipe<Brand>

transform(value, _metadata): Id<Brand> | Promise<Id<Brand>>

Defined in: src/adapters/nestjs.ts:99

Method to implement a custom pipe. Called with two parameters

unknown

argument before it is received by route handler method

ArgumentMetadata

Id<Brand> | Promise<Id<Brand>>

PipeTransform.transform