balda 0.0.38 → 0.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cli.js +32 -32
- package/lib/cli.js.map +1 -1
- package/lib/index.cjs +58 -58
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +90 -119
- package/lib/index.d.ts +90 -119
- package/lib/index.js +58 -58
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { schedule, TaskContext } from 'node-cron';
|
|
2
2
|
import { TSchema, Static } from '@sinclair/typebox';
|
|
3
|
-
import {
|
|
3
|
+
import { ZodType, z } from 'zod';
|
|
4
4
|
import { Ajv } from 'ajv';
|
|
5
5
|
import { IncomingMessage, ServerResponse, Server as Server$2 } from 'node:http';
|
|
6
6
|
import { Http2Server } from 'node:http2';
|
|
@@ -114,8 +114,8 @@ declare const flag: {
|
|
|
114
114
|
type AjvInstance = InstanceType<typeof Ajv>;
|
|
115
115
|
type AjvCompileParams = Parameters<AjvInstance["compile"]>;
|
|
116
116
|
|
|
117
|
-
type RequestSchema =
|
|
118
|
-
type ValidatedData<T extends RequestSchema> = T extends
|
|
117
|
+
type RequestSchema = ZodType | TSchema | AjvCompileParams[0];
|
|
118
|
+
type ValidatedData<T extends RequestSchema> = T extends ZodType ? z.infer<T> : T extends TSchema ? Static<T> : T extends AjvCompileParams[0] ? any : any;
|
|
119
119
|
interface CustomValidationError {
|
|
120
120
|
status?: number;
|
|
121
121
|
message?: string;
|
|
@@ -246,7 +246,7 @@ type SwaggerRouteOptions = {
|
|
|
246
246
|
service?: string;
|
|
247
247
|
/** Name of the route */
|
|
248
248
|
name?: string;
|
|
249
|
-
/** Responses for this route */
|
|
249
|
+
/** Responses for this route (used by decorators) */
|
|
250
250
|
responses?: Record<number, RequestSchema>;
|
|
251
251
|
/** Errors for this route */
|
|
252
252
|
errors?: Record<number, RequestSchema>;
|
|
@@ -748,13 +748,41 @@ type CookieMiddlewareOptions = {
|
|
|
748
748
|
};
|
|
749
749
|
|
|
750
750
|
/**
|
|
751
|
-
*
|
|
752
|
-
*
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
751
|
+
* Extracts parameter names from a path string and creates a typed object
|
|
752
|
+
* @example ExtractParams<"/users/:id/posts/:postId"> → { id: string; postId: string }
|
|
753
|
+
*/
|
|
754
|
+
type ExtractParams<T extends string> = T extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
|
|
755
|
+
[K in Param | keyof ExtractParams<Rest>]: string;
|
|
756
|
+
} : T extends `${infer _Start}:${infer Param}` ? {
|
|
757
|
+
[K in Param]: string;
|
|
758
|
+
} : Record<string, never>;
|
|
759
|
+
/**
|
|
760
|
+
* Helper type to infer the output type from a Zod schema, TypeBox schema, or any schema with _output
|
|
756
761
|
*/
|
|
757
|
-
|
|
762
|
+
type InferSchemaType<T> = T extends ZodType ? z.infer<T> : T extends TSchema ? Static<T> : any;
|
|
763
|
+
/**
|
|
764
|
+
* Maps a responses object (e.g. { 200: ZodSchema, 404: TypeBoxSchema }) to
|
|
765
|
+
* an inferred type map (e.g. { 200: InferredType200, 404: InferredType404 }).
|
|
766
|
+
*/
|
|
767
|
+
type InferResponseMap<T extends Record<number, RequestSchema>> = {
|
|
768
|
+
[K in keyof T]: InferSchemaType<T[K]>;
|
|
769
|
+
};
|
|
770
|
+
/**
|
|
771
|
+
* Extracts the body type for a specific HTTP status code from a response map.
|
|
772
|
+
* When the status code has a schema defined, enforces exact type matching.
|
|
773
|
+
* Defaults to `any` when the status code is not present in the map.
|
|
774
|
+
*/
|
|
775
|
+
type ResponseBodyForStatus<TMap, TStatus extends number> = TStatus extends keyof TMap ? 0 extends 1 & TMap[TStatus] ? any : {
|
|
776
|
+
[K in keyof TMap[TStatus]]: TMap[TStatus][K];
|
|
777
|
+
} : any;
|
|
778
|
+
|
|
779
|
+
/**
|
|
780
|
+
* The response object with per-status-code type-safe response bodies.
|
|
781
|
+
* When response schemas are provided (e.g. via the `responses` route option), each shorthand
|
|
782
|
+
* method (ok, created, notFound, etc.) is typed to its corresponding status code schema.
|
|
783
|
+
* @template TResponseMap - Maps HTTP status codes to their inferred body types (defaults to Record<number, any>)
|
|
784
|
+
*/
|
|
785
|
+
declare class Response$1<TResponseMap extends Record<number, any> = Record<number, any>> {
|
|
758
786
|
#private;
|
|
759
787
|
static toWebResponse(response: Response$1): globalThis.Response;
|
|
760
788
|
/**
|
|
@@ -792,7 +820,7 @@ declare class Response$1<TBody = any> {
|
|
|
792
820
|
* Send a response with the given body, tries to determine the content type based on the body type, status defaults to 200
|
|
793
821
|
* @warning If cannot determine the content type, it will be sent as is
|
|
794
822
|
*/
|
|
795
|
-
send(body:
|
|
823
|
+
send(body: TResponseMap[keyof TResponseMap]): void;
|
|
796
824
|
/**
|
|
797
825
|
* Send a response with the given body without any content type or encoding (as is), status defaults to 200
|
|
798
826
|
*/
|
|
@@ -806,13 +834,7 @@ declare class Response$1<TBody = any> {
|
|
|
806
834
|
* @param body - The response body to serialize
|
|
807
835
|
* @param schema - Optional schema for fast-json-stringify. When provided, enables fast serialization
|
|
808
836
|
*/
|
|
809
|
-
json(body:
|
|
810
|
-
/**
|
|
811
|
-
* Converts any schema type to JSON Schema format with appropriate prefix.
|
|
812
|
-
* @param schema - The schema to convert
|
|
813
|
-
* @returns Object with JSON Schema and prefix
|
|
814
|
-
*/
|
|
815
|
-
private getJsonSchemaWithPrefix;
|
|
837
|
+
json(body: TResponseMap[keyof TResponseMap], schema?: RequestSchema): void;
|
|
816
838
|
/**
|
|
817
839
|
* Send a response with the given HTML, status defaults to 200
|
|
818
840
|
*/
|
|
@@ -839,15 +861,15 @@ declare class Response$1<TBody = any> {
|
|
|
839
861
|
/**
|
|
840
862
|
* 200 OK
|
|
841
863
|
*/
|
|
842
|
-
ok(body?:
|
|
864
|
+
ok(body?: ResponseBodyForStatus<TResponseMap, 200>): void;
|
|
843
865
|
/**
|
|
844
866
|
* 201 Created
|
|
845
867
|
*/
|
|
846
|
-
created(body?:
|
|
868
|
+
created(body?: ResponseBodyForStatus<TResponseMap, 201>): void;
|
|
847
869
|
/**
|
|
848
870
|
* 202 Accepted
|
|
849
871
|
*/
|
|
850
|
-
accepted(body?:
|
|
872
|
+
accepted(body?: ResponseBodyForStatus<TResponseMap, 202>): void;
|
|
851
873
|
/**
|
|
852
874
|
* 204 No Content
|
|
853
875
|
*/
|
|
@@ -855,7 +877,7 @@ declare class Response$1<TBody = any> {
|
|
|
855
877
|
/**
|
|
856
878
|
* 206 Partial Content
|
|
857
879
|
*/
|
|
858
|
-
partialContent(body?:
|
|
880
|
+
partialContent(body?: ResponseBodyForStatus<TResponseMap, 206>): void;
|
|
859
881
|
/**
|
|
860
882
|
* 3XX Redirection
|
|
861
883
|
*/
|
|
@@ -894,75 +916,75 @@ declare class Response$1<TBody = any> {
|
|
|
894
916
|
/**
|
|
895
917
|
* 400 Bad Request
|
|
896
918
|
*/
|
|
897
|
-
badRequest(body?:
|
|
919
|
+
badRequest(body?: ResponseBodyForStatus<TResponseMap, 400>): void;
|
|
898
920
|
/**
|
|
899
921
|
* 401 Unauthorized
|
|
900
922
|
*/
|
|
901
|
-
unauthorized(body?:
|
|
923
|
+
unauthorized(body?: ResponseBodyForStatus<TResponseMap, 401>): void;
|
|
902
924
|
/**
|
|
903
925
|
* 403 Forbidden
|
|
904
926
|
*/
|
|
905
|
-
forbidden(body?:
|
|
927
|
+
forbidden(body?: ResponseBodyForStatus<TResponseMap, 403>): void;
|
|
906
928
|
/**
|
|
907
929
|
* 404 Not Found
|
|
908
930
|
*/
|
|
909
|
-
notFound(body?:
|
|
931
|
+
notFound(body?: ResponseBodyForStatus<TResponseMap, 404>): void;
|
|
910
932
|
/**
|
|
911
933
|
* 405 Method Not Allowed
|
|
912
934
|
*/
|
|
913
|
-
methodNotAllowed(body?:
|
|
935
|
+
methodNotAllowed(body?: ResponseBodyForStatus<TResponseMap, 405>): void;
|
|
914
936
|
/**
|
|
915
937
|
* 406 Not Acceptable
|
|
916
938
|
*/
|
|
917
|
-
notAcceptable(body?:
|
|
939
|
+
notAcceptable(body?: ResponseBodyForStatus<TResponseMap, 406>): void;
|
|
918
940
|
/**
|
|
919
941
|
* 409 Conflict
|
|
920
942
|
*/
|
|
921
|
-
conflict(body?:
|
|
943
|
+
conflict(body?: ResponseBodyForStatus<TResponseMap, 409>): void;
|
|
922
944
|
/**
|
|
923
945
|
* 410 Gone
|
|
924
946
|
*/
|
|
925
|
-
gone(body?:
|
|
947
|
+
gone(body?: ResponseBodyForStatus<TResponseMap, 410>): void;
|
|
926
948
|
/**
|
|
927
949
|
* 413 Payload Too Large
|
|
928
950
|
*/
|
|
929
|
-
payloadTooLarge(body?:
|
|
951
|
+
payloadTooLarge(body?: ResponseBodyForStatus<TResponseMap, 413>): void;
|
|
930
952
|
/**
|
|
931
953
|
* 415 Unsupported Media Type
|
|
932
954
|
*/
|
|
933
|
-
unsupportedMediaType(body?:
|
|
955
|
+
unsupportedMediaType(body?: ResponseBodyForStatus<TResponseMap, 415>): void;
|
|
934
956
|
/**
|
|
935
957
|
* 422 Unprocessable Entity
|
|
936
958
|
*/
|
|
937
|
-
unprocessableEntity(body?:
|
|
959
|
+
unprocessableEntity(body?: ResponseBodyForStatus<TResponseMap, 422>): void;
|
|
938
960
|
/**
|
|
939
961
|
* 429 Too Many Requests
|
|
940
962
|
*/
|
|
941
|
-
tooManyRequests(body?:
|
|
963
|
+
tooManyRequests(body?: ResponseBodyForStatus<TResponseMap, 429>): void;
|
|
942
964
|
/**
|
|
943
965
|
* 5XX Server Errors
|
|
944
966
|
*/
|
|
945
|
-
internalServerError(body?:
|
|
967
|
+
internalServerError(body?: ResponseBodyForStatus<TResponseMap, 500>): void;
|
|
946
968
|
/**
|
|
947
969
|
* 501 Not Implemented
|
|
948
970
|
*/
|
|
949
|
-
notImplemented(body?:
|
|
971
|
+
notImplemented(body?: ResponseBodyForStatus<TResponseMap, 501>): void;
|
|
950
972
|
/**
|
|
951
973
|
* 502 Bad Gateway
|
|
952
974
|
*/
|
|
953
|
-
badGateway(body?:
|
|
975
|
+
badGateway(body?: ResponseBodyForStatus<TResponseMap, 502>): void;
|
|
954
976
|
/**
|
|
955
977
|
* 503 Service Unavailable
|
|
956
978
|
*/
|
|
957
|
-
serviceUnavailable(body?:
|
|
979
|
+
serviceUnavailable(body?: ResponseBodyForStatus<TResponseMap, 503>): void;
|
|
958
980
|
/**
|
|
959
981
|
* 504 Gateway Timeout
|
|
960
982
|
*/
|
|
961
|
-
gatewayTimeout(body?:
|
|
983
|
+
gatewayTimeout(body?: ResponseBodyForStatus<TResponseMap, 504>): void;
|
|
962
984
|
/**
|
|
963
985
|
* 505 HTTP Version Not Supported
|
|
964
986
|
*/
|
|
965
|
-
httpVersionNotSupported(body?:
|
|
987
|
+
httpVersionNotSupported(body?: ResponseBodyForStatus<TResponseMap, 505>): void;
|
|
966
988
|
/**
|
|
967
989
|
* Set a cookie for the response, cookie middleware must be registered in order to use this function
|
|
968
990
|
*/
|
|
@@ -983,22 +1005,14 @@ declare class Response$1<TBody = any> {
|
|
|
983
1005
|
* If a fast serializer is available and the body is an object, it will be serialized lazily.
|
|
984
1006
|
*/
|
|
985
1007
|
getBody(): any;
|
|
1008
|
+
/**
|
|
1009
|
+
* Converts any schema type to JSON Schema format with appropriate prefix.
|
|
1010
|
+
* @param schema - The schema to convert
|
|
1011
|
+
* @returns Object with JSON Schema and prefix
|
|
1012
|
+
*/
|
|
1013
|
+
private getJsonSchemaWithPrefix;
|
|
986
1014
|
}
|
|
987
1015
|
|
|
988
|
-
/**
|
|
989
|
-
* Extracts parameter names from a path string and creates a typed object
|
|
990
|
-
* @example ExtractParams<"/users/:id/posts/:postId"> → { id: string; postId: string }
|
|
991
|
-
*/
|
|
992
|
-
type ExtractParams<T extends string> = T extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
|
|
993
|
-
[K in Param | keyof ExtractParams<Rest>]: string;
|
|
994
|
-
} : T extends `${infer _Start}:${infer Param}` ? {
|
|
995
|
-
[K in Param]: string;
|
|
996
|
-
} : Record<string, never>;
|
|
997
|
-
/**
|
|
998
|
-
* Helper type to infer the output type from a Zod schema, TypeBox schema, or any schema with _output
|
|
999
|
-
*/
|
|
1000
|
-
type InferSchemaType<T> = T extends ZodAny ? z.infer<T> : T extends TSchema ? Static<T> : T;
|
|
1001
|
-
|
|
1002
1016
|
/**
|
|
1003
1017
|
* Decorator to mark a handler for a DELETE request with type-safe path parameters and response body
|
|
1004
1018
|
* DELETE requests cannot have a request body (by HTTP spec)
|
|
@@ -1161,10 +1175,10 @@ declare const put: <TPath extends string = string>(path: TPath, options?: Swagge
|
|
|
1161
1175
|
* Type-safe handler for routes with typed path parameters and response
|
|
1162
1176
|
* Body and query are validated first and passed as separate typed arguments
|
|
1163
1177
|
* @example
|
|
1164
|
-
* TypedHandler<"/users/:id", CreateUserSchema, SearchQuerySchema, UserResponse>
|
|
1165
|
-
* → (req: Request<{ id: string }>, res: Response<UserResponse>, body: CreateUserInput, query: SearchQuery) => void | Promise<void>
|
|
1178
|
+
* TypedHandler<"/users/:id", CreateUserSchema, SearchQuerySchema, { 200: UserResponse }>
|
|
1179
|
+
* → (req: Request<{ id: string }>, res: Response<{ 200: UserResponse }>, body: CreateUserInput, query: SearchQuery) => void | Promise<void>
|
|
1166
1180
|
*/
|
|
1167
|
-
type TypedHandler<TPath extends string, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined,
|
|
1181
|
+
type TypedHandler<TPath extends string, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, TResponseMap extends Record<number, any> = Record<number, any>> = (req: Request<ExtractParams<TPath>>, res: Response$1<TResponseMap>, ...args: [
|
|
1168
1182
|
...(TBody extends RequestSchema ? [body: InferSchemaType<TBody>] : []),
|
|
1169
1183
|
...(TQuery extends RequestSchema ? [query: InferSchemaType<TQuery>] : [])
|
|
1170
1184
|
]) => void | Promise<void>;
|
|
@@ -1280,7 +1294,7 @@ declare class Router {
|
|
|
1280
1294
|
body?: RequestSchema;
|
|
1281
1295
|
query?: RequestSchema;
|
|
1282
1296
|
all?: RequestSchema;
|
|
1283
|
-
}, swaggerOptions?: SwaggerRouteOptions): void;
|
|
1297
|
+
}, swaggerOptions?: SwaggerRouteOptions, responses?: Record<number, RequestSchema>): void;
|
|
1284
1298
|
/**
|
|
1285
1299
|
* Find the matching route for the given HTTP method and path.
|
|
1286
1300
|
* Returns the resolved middleware chain, handler, extracted params, and response schemas; or null if not found.
|
|
@@ -1302,37 +1316,37 @@ declare class Router {
|
|
|
1302
1316
|
* Register a GET route under this router's base path with type-safe path parameters.
|
|
1303
1317
|
*/
|
|
1304
1318
|
get<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1305
|
-
get<TPath extends string = string>(path: TPath, options: StandardMethodOptions
|
|
1319
|
+
get<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>>(path: TPath, options: StandardMethodOptions<TResponses>, handler: ControllerHandler<TPath, TResponses>): void;
|
|
1306
1320
|
/**
|
|
1307
1321
|
* Register a POST route under this router's base path with type-safe path parameters.
|
|
1308
1322
|
*/
|
|
1309
1323
|
post<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1310
|
-
post<TPath extends string = string>(path: TPath, options: StandardMethodOptions
|
|
1324
|
+
post<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>>(path: TPath, options: StandardMethodOptions<TResponses>, handler: ControllerHandler<TPath, TResponses>): void;
|
|
1311
1325
|
/**
|
|
1312
1326
|
* Register a PATCH route under this router's base path with type-safe path parameters.
|
|
1313
1327
|
*/
|
|
1314
1328
|
patch<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1315
|
-
patch<TPath extends string = string>(path: TPath, options: StandardMethodOptions
|
|
1329
|
+
patch<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>>(path: TPath, options: StandardMethodOptions<TResponses>, handler: ControllerHandler<TPath, TResponses>): void;
|
|
1316
1330
|
/**
|
|
1317
1331
|
* Register a PUT route under this router's base path with type-safe path parameters.
|
|
1318
1332
|
*/
|
|
1319
1333
|
put<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1320
|
-
put<TPath extends string = string>(path: TPath, options: StandardMethodOptions
|
|
1334
|
+
put<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>>(path: TPath, options: StandardMethodOptions<TResponses>, handler: ControllerHandler<TPath, TResponses>): void;
|
|
1321
1335
|
/**
|
|
1322
1336
|
* Register a DELETE route under this router's base path with type-safe path parameters.
|
|
1323
1337
|
*/
|
|
1324
1338
|
delete<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1325
|
-
delete<TPath extends string = string>(path: TPath, options: StandardMethodOptions
|
|
1339
|
+
delete<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>>(path: TPath, options: StandardMethodOptions<TResponses>, handler: ControllerHandler<TPath, TResponses>): void;
|
|
1326
1340
|
/**
|
|
1327
1341
|
* Register an OPTIONS route under this router's base path with type-safe path parameters.
|
|
1328
1342
|
*/
|
|
1329
1343
|
options<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1330
|
-
options<TPath extends string = string>(path: TPath, options: StandardMethodOptions
|
|
1344
|
+
options<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>>(path: TPath, options: StandardMethodOptions<TResponses>, handler: ControllerHandler<TPath, TResponses>): void;
|
|
1331
1345
|
/**
|
|
1332
1346
|
* Register an HEAD route under this router's base path with type-safe path parameters.
|
|
1333
1347
|
*/
|
|
1334
|
-
head<TPath extends string = string>(path: TPath, handler:
|
|
1335
|
-
head<TPath extends string = string>(path: TPath, options: StandardMethodOptions
|
|
1348
|
+
head<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1349
|
+
head<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>>(path: TPath, options: StandardMethodOptions<TResponses>, handler: ControllerHandler<TPath, TResponses>): void;
|
|
1336
1350
|
/**
|
|
1337
1351
|
* Create a grouped router that shares a base path and middlewares.
|
|
1338
1352
|
* The callback receives a child router where routes are defined; routes
|
|
@@ -1368,7 +1382,12 @@ interface Route {
|
|
|
1368
1382
|
handler: ServerRouteHandler;
|
|
1369
1383
|
swaggerOptions?: SwaggerRouteOptions;
|
|
1370
1384
|
/**
|
|
1371
|
-
*
|
|
1385
|
+
* Response schemas from route options, indexed by status code.
|
|
1386
|
+
* Used by swagger plugin for documentation and fast JSON serialization.
|
|
1387
|
+
*/
|
|
1388
|
+
responses?: RouteResponseSchemas;
|
|
1389
|
+
/**
|
|
1390
|
+
* Compiled response schemas, indexed by status code.
|
|
1372
1391
|
* Used for automatic fast JSON serialization in Response.json()
|
|
1373
1392
|
*/
|
|
1374
1393
|
responseSchemas?: RouteResponseSchemas;
|
|
@@ -1422,22 +1441,6 @@ declare class Server<H extends NodeHttpClient = NodeHttpClient> implements Serve
|
|
|
1422
1441
|
compareHash(hash: string, data: string): Promise<boolean>;
|
|
1423
1442
|
getEnvironment(): Record<string, string>;
|
|
1424
1443
|
tmpDir(...append: string[]): string;
|
|
1425
|
-
get<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1426
|
-
get<TPath extends string = string>(path: TPath, options: StandardMethodOptions, handler: ControllerHandler<TPath>): void;
|
|
1427
|
-
post<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1428
|
-
post<TPath extends string = string>(path: TPath, options: StandardMethodOptions, handler: ControllerHandler<TPath>): void;
|
|
1429
|
-
patch<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1430
|
-
patch<TPath extends string = string>(path: TPath, options: StandardMethodOptions, handler: ControllerHandler<TPath>): void;
|
|
1431
|
-
put<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1432
|
-
put<TPath extends string = string>(path: TPath, options: StandardMethodOptions, handler: ControllerHandler<TPath>): void;
|
|
1433
|
-
delete<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1434
|
-
delete<TPath extends string = string>(path: TPath, options: StandardMethodOptions, handler: ControllerHandler<TPath>): void;
|
|
1435
|
-
options<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1436
|
-
options<TPath extends string = string>(path: TPath, options: StandardMethodOptions, handler: ControllerHandler<TPath>): void;
|
|
1437
|
-
head<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1438
|
-
head<TPath extends string = string>(path: TPath, options: StandardMethodOptions, handler: ControllerHandler<TPath>): void;
|
|
1439
|
-
group(path: string, middleware: ServerRouteMiddleware[] | ServerRouteMiddleware, cb: (router: ClientRouter) => void): void;
|
|
1440
|
-
group(path: string, cb: (router: ClientRouter) => void): void;
|
|
1441
1444
|
getNodeServer(): RuntimeServerMap<"node", H>;
|
|
1442
1445
|
getBunServer(): RuntimeServerMap<"bun">;
|
|
1443
1446
|
getDenoServer(): RuntimeServerMap<"deno">;
|
|
@@ -1476,7 +1479,6 @@ declare class Server<H extends NodeHttpClient = NodeHttpClient> implements Serve
|
|
|
1476
1479
|
}): void;
|
|
1477
1480
|
getMockServer(options?: Pick<ServerOptions, "controllerPatterns">): Promise<MockServer>;
|
|
1478
1481
|
private importControllers;
|
|
1479
|
-
private extractOptionsAndHandlerFromRouteRegistration;
|
|
1480
1482
|
private applyPlugins;
|
|
1481
1483
|
/**
|
|
1482
1484
|
* Initializes the server by importing the controllers and applying the plugins, it's idempotent, it will not re-import the controllers or apply the plugins if the server was already initialized (e.g. mockServer init)
|
|
@@ -2171,38 +2173,6 @@ interface ServerInterface {
|
|
|
2171
2173
|
* @param expressRouter - The Express router to mount
|
|
2172
2174
|
*/
|
|
2173
2175
|
mountExpressRouter: (basePath: string, expressRouter: ExpressRouter) => void;
|
|
2174
|
-
/**
|
|
2175
|
-
* Shorthand for the router.get method
|
|
2176
|
-
*/
|
|
2177
|
-
get: (...args: any[]) => void;
|
|
2178
|
-
/**
|
|
2179
|
-
* Shorthand for the router.post method
|
|
2180
|
-
*/
|
|
2181
|
-
post: (...args: any[]) => void;
|
|
2182
|
-
/**
|
|
2183
|
-
* Shorthand for the router.put method
|
|
2184
|
-
*/
|
|
2185
|
-
put: (...args: any[]) => void;
|
|
2186
|
-
/**
|
|
2187
|
-
* Shorthand for the router.patch method
|
|
2188
|
-
*/
|
|
2189
|
-
patch: (...args: any[]) => void;
|
|
2190
|
-
/**
|
|
2191
|
-
* Shorthand for the router.delete method
|
|
2192
|
-
*/
|
|
2193
|
-
delete: (...args: any[]) => void;
|
|
2194
|
-
/**
|
|
2195
|
-
* Shorthand for the router.options method
|
|
2196
|
-
*/
|
|
2197
|
-
options: (...args: any[]) => void;
|
|
2198
|
-
/**
|
|
2199
|
-
* Shorthand for the router.head method
|
|
2200
|
-
*/
|
|
2201
|
-
head: (...args: any[]) => void;
|
|
2202
|
-
/**
|
|
2203
|
-
* Shorthand for the router.group method
|
|
2204
|
-
*/
|
|
2205
|
-
group: (...args: any[]) => void;
|
|
2206
2176
|
/**
|
|
2207
2177
|
* Get the node server instance, you must be using node runtime to use this method based on the nodeHttpClient option passed to the server constructor (defaults to http)
|
|
2208
2178
|
* @throws if the runtime is not node
|
|
@@ -2338,16 +2308,17 @@ interface ServerInterface {
|
|
|
2338
2308
|
*/
|
|
2339
2309
|
exit: (code?: number) => void;
|
|
2340
2310
|
}
|
|
2341
|
-
type StandardMethodOptions = {
|
|
2311
|
+
type StandardMethodOptions<TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>> = {
|
|
2342
2312
|
middlewares?: ServerRouteMiddleware[] | ServerRouteMiddleware;
|
|
2343
2313
|
body?: RequestSchema;
|
|
2344
2314
|
query?: RequestSchema;
|
|
2345
2315
|
all?: RequestSchema;
|
|
2316
|
+
responses?: TResponses;
|
|
2346
2317
|
swagger?: SwaggerRouteOptions;
|
|
2347
2318
|
};
|
|
2348
2319
|
type ServerHook = () => SyncOrAsync;
|
|
2349
2320
|
type SignalEvent = Deno.Signal | NodeJS.Signals;
|
|
2350
|
-
type ControllerHandler<TPath extends string = string> = (req: Request<ExtractParams<TPath>>, res: Response$1
|
|
2321
|
+
type ControllerHandler<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>> = (req: Request<ExtractParams<TPath>>, res: Response$1<InferResponseMap<TResponses>>, ...args: any[]) => ServerHandlerReturnType;
|
|
2351
2322
|
|
|
2352
2323
|
type RunTimeType = "bun" | "node" | "deno";
|
|
2353
2324
|
|
|
@@ -4074,4 +4045,4 @@ declare const createPolicyDecorator: <T extends Record<string, PolicyProvider>>(
|
|
|
4074
4045
|
*/
|
|
4075
4046
|
declare const router: ClientRouter;
|
|
4076
4047
|
|
|
4077
|
-
export { type AsyncLocalStorageContextSetters, AzureBlobStorageProvider, BaseCron, BasePlugin, type BaseStorageProviderOptions, type BlobStorageProviderOptions, BullMQConfiguration, type BullMQConfigurationOptions, BullMQPubSub, Command, type CommandOptions, CommandRegistry, type CompressionOptions, type CookieMiddlewareOptions, type CorsOptions, type CronSchedule, type CronScheduleParams, CronService, type CronUIOptions, CustomAdapter, type CustomQueueConfiguration, type CustomStorageProviderOptions, CustomTypedQueue, type CustomValidationError, EdgeAdapter, EjsAdapter, type ExtractParams, GraphQL, type GraphQLContext, type GraphQLOptions, type GraphQLResolverFunction, type GraphQLResolverMap, type GraphQLResolverType, type GraphQLResolvers, type GraphQLSchemaInput, type GraphQLTypeDef, HandlebarsAdapter, type HelmetOptions, type HttpMethod, type HttpsOptions, type InferSchemaType, LocalStorageProvider, type LocalStorageProviderOptions, type LogOptions, type LoggerOptions, type MailOptions, MailOptionsBuilder, MailProvider, type MailProviderInterface, Mailer, type MailerInterface, type MailerOptions, type MailerProviderOptions, MemoryPubSub, type MethodOverrideOptions, MockResponse, MockServer, type MockServerOptions, type MqttConnectionOptions, type MqttHandler, type MqttPublishOptions, MqttService, type MqttSubscribeOptions, type MqttSubscription, type MqttTopics, MustacheAdapter, type NextFunction, type NodeHttpClient, type NodeServer as NodeHttpServerClient, PGBossConfiguration, type PGBossConfigurationOptions, PGBossPubSub, type PolicyDecorator, PolicyManager, type PolicyProvider, type PublishTopic, QueueManager, QueueService, type RateLimiterKeyOptions, Request, type RequestSchema, Response$1 as Response, type RuntimeServer, S3StorageProvider, type S3StorageProviderOptions, SQSConfiguration, type SQSConfigurationOptions, SQSPubSub, type CacheMetrics as SchemaCacheMetrics, type SerializeOptions, Server, type ServerConnectInput, type ServerErrorHandler, type ServerHook, type ServerInterface, type ServerListenCallback, type ServerOptions, type ServerRouteHandler, type ServerRouteMiddleware, type ServerTapOptions, type SessionOptions, type SignalEvent, type StaticPluginOptions, Storage, type StorageInterface, type StorageOptions, type StorageProviderOptions, type TemplateMailOptions, type TimeoutOptions, type TrustProxyOptions, type TypedHandler, TypedQueue, type TypedRouteMetadata, type ValidatedData, type ValidationOptions, arg, asyncLocalStorage, asyncStorage, bullmqQueue, clearAllCaches as clearAllSchemaCaches, commandRegistry, compression, controller, cookie, cors, createExpressAdapter, createPolicyDecorator, createQueue, cron, Server as default, defineQueueConfiguration, del, expressHandler, expressMiddleware, flag, get, getCacheMetrics as getSchemaCacheMetrics, hash, helmet, log, logCacheMetrics as logSchemaCacheMetrics, logger, memoryQueue, methodOverride, middleware, mountExpressRouter, mqtt, patch, pgbossQueue, post, put, rateLimiter, router, serialize, serveStatic, session, setCronGlobalErrorHandler, setMqttGlobalErrorHandler, sqsQueue, timeout as timeoutMw, trustProxy, validate };
|
|
4048
|
+
export { type AsyncLocalStorageContextSetters, AzureBlobStorageProvider, BaseCron, BasePlugin, type BaseStorageProviderOptions, type BlobStorageProviderOptions, BullMQConfiguration, type BullMQConfigurationOptions, BullMQPubSub, Command, type CommandOptions, CommandRegistry, type CompressionOptions, type CookieMiddlewareOptions, type CorsOptions, type CronSchedule, type CronScheduleParams, CronService, type CronUIOptions, CustomAdapter, type CustomQueueConfiguration, type CustomStorageProviderOptions, CustomTypedQueue, type CustomValidationError, EdgeAdapter, EjsAdapter, type ExtractParams, GraphQL, type GraphQLContext, type GraphQLOptions, type GraphQLResolverFunction, type GraphQLResolverMap, type GraphQLResolverType, type GraphQLResolvers, type GraphQLSchemaInput, type GraphQLTypeDef, HandlebarsAdapter, type HelmetOptions, type HttpMethod, type HttpsOptions, type InferResponseMap, type InferSchemaType, LocalStorageProvider, type LocalStorageProviderOptions, type LogOptions, type LoggerOptions, type MailOptions, MailOptionsBuilder, MailProvider, type MailProviderInterface, Mailer, type MailerInterface, type MailerOptions, type MailerProviderOptions, MemoryPubSub, type MethodOverrideOptions, MockResponse, MockServer, type MockServerOptions, type MqttConnectionOptions, type MqttHandler, type MqttPublishOptions, MqttService, type MqttSubscribeOptions, type MqttSubscription, type MqttTopics, MustacheAdapter, type NextFunction, type NodeHttpClient, type NodeServer as NodeHttpServerClient, PGBossConfiguration, type PGBossConfigurationOptions, PGBossPubSub, type PolicyDecorator, PolicyManager, type PolicyProvider, type PublishTopic, QueueManager, QueueService, type RateLimiterKeyOptions, Request, type RequestSchema, Response$1 as Response, type ResponseBodyForStatus, type RuntimeServer, S3StorageProvider, type S3StorageProviderOptions, SQSConfiguration, type SQSConfigurationOptions, SQSPubSub, type CacheMetrics as SchemaCacheMetrics, type SerializeOptions, Server, type ServerConnectInput, type ServerErrorHandler, type ServerHook, type ServerInterface, type ServerListenCallback, type ServerOptions, type ServerRouteHandler, type ServerRouteMiddleware, type ServerTapOptions, type SessionOptions, type SignalEvent, type StaticPluginOptions, Storage, type StorageInterface, type StorageOptions, type StorageProviderOptions, type TemplateMailOptions, type TimeoutOptions, type TrustProxyOptions, type TypedHandler, TypedQueue, type TypedRouteMetadata, type ValidatedData, type ValidationOptions, arg, asyncLocalStorage, asyncStorage, bullmqQueue, clearAllCaches as clearAllSchemaCaches, commandRegistry, compression, controller, cookie, cors, createExpressAdapter, createPolicyDecorator, createQueue, cron, Server as default, defineQueueConfiguration, del, expressHandler, expressMiddleware, flag, get, getCacheMetrics as getSchemaCacheMetrics, hash, helmet, log, logCacheMetrics as logSchemaCacheMetrics, logger, memoryQueue, methodOverride, middleware, mountExpressRouter, mqtt, patch, pgbossQueue, post, put, rateLimiter, router, serialize, serveStatic, session, setCronGlobalErrorHandler, setMqttGlobalErrorHandler, sqsQueue, timeout as timeoutMw, trustProxy, validate };
|