@rtorcato/api-response v1.0.0
Interfaces
SuccessResponse
Defined in: index.ts:4
Standard success envelope returned by API handlers.
Type Parameters
T
T
Properties
success
success:
true
Defined in: index.ts:5
data
data:
T
Defined in: index.ts:6
message?
optionalmessage?:string
Defined in: index.ts:7
Type Aliases
ErrorResponse
ErrorResponse =
any
Functions
ok()
ok<
T>(data,message?):SuccessResponse<T>
Defined in: index.ts:16
Build a SuccessResponse envelope.
Pairs with the error shape thrown by @rtorcato/api-errors: success bodies
carry success: true + data, error bodies carry status/code/message.
Type Parameters
T
T
Parameters
data
T
message?
string
Returns
successSchema()
successSchema<
T>(dataSchema):ZodObject<{success:ZodLiteral<true>;data:T;message:ZodOptional<ZodString>; },$strip>
Defined in: index.ts:24
Build a zod schema for a success envelope wrapping dataSchema — for
documenting or validating responses (e.g. in OpenAPI contracts).
Type Parameters
T
T extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
Parameters
dataSchema
T
Returns
ZodObject<{ success: ZodLiteral<true>; data: T; message: ZodOptional<ZodString>; }, $strip>
errorSchema()
errorSchema():
ZodObject<{error:ZodString;code:ZodString;message:ZodString;stack:ZodOptional<ZodString>; },$strip>
Defined in: index.ts:38
Zod schema for the error envelope — for OpenAPI contracts and response validation.
Returns
ZodObject<{ error: ZodString; code: ZodString; message: ZodString; stack: ZodOptional<ZodString>; }, $strip>