import { t as Id } from "./types-hGBnCpJj.mjs"; import { a as IdVerifiableCodec, i as IdParamFailure, t as IdCodec } from "./adapter-types-B-GLKPOm.mjs"; import { ArgumentMetadata, PipeTransform } from "@nestjs/common"; //#region src/adapters/nestjs.d.ts /** * Options for `ParseIdPipe`. All fields are optional. * * **`onError` constraint:** NestJS `transform()` receives only `value` and `ArgumentMetadata` * — there is no HTTP context object. The `onError` hook must throw (or re-throw); it cannot * write a response inline the way Hono/Express hooks can. * * **Default validation is structural** — `safeParse` checks prefix and base32 form but does not * verify any cryptographic tag. For IDs using a codec that satisfies {@link IdVerifiableCodec} * (the **Signed Timestamp codec** or **Wrapped key codec**), pass `verify: true` via * {@link IdParamVerifyOptions} to also authenticate the tag. */ type IdParamOptions = { /** * Called instead of throwing when provided. The hook **must** throw or re-throw — it cannot * return a response because `PipeTransform.transform` has no HTTP context. */ onError?: (failure: IdParamFailure) => never; /** * Remap the default HTTP status for a failure reason without a full handler. * e.g. `{ brand_mismatch: 400 }` treats both failure kinds as 400. */ status?: { brand_mismatch?: number; malformed?: number; }; }; /** * Extends {@link IdParamOptions} with opt-in HMAC tag verification. * Only accepted when the codec satisfies {@link IdVerifiableCodec} (the **Signed Timestamp codec** or **Wrapped key codec**). * When `verify` is truthy, `ParseIdPipe.transform` returns a `Promise` that awaits * `codec.safeVerify(raw)`; a tag mismatch is treated as a `"malformed"` failure. * NestJS supports async pipes natively — the resolved `Id` reaches the handler. */ type IdParamVerifyOptions = IdParamOptions & { /** When truthy, awaits `codec.safeVerify(raw)` after structural parse and treats a tag failure as `"malformed"`. Accepts any boolean so computed flags (`{ verify: cfg.verifyIds }`) compile without casting. */verify?: boolean; }; /** * 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 * ```ts * 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 * } * } * ``` */ declare class ParseIdPipe implements PipeTransform | Promise>> { private readonly codec; private readonly options; constructor(codec: IdVerifiableCodec, options?: IdParamVerifyOptions); constructor(codec: IdCodec, options?: IdParamOptions); transform(value: unknown, _metadata: ArgumentMetadata): Id | Promise>; } //#endregion export { type IdParamFailure, IdParamOptions, IdParamVerifyOptions, ParseIdPipe }; //# sourceMappingURL=nestjs.d.mts.map