kontract 0.1.0
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/README.md +435 -0
- package/dist/builder/define-controller.d.ts +115 -0
- package/dist/builder/define-controller.d.ts.map +1 -0
- package/dist/builder/define-controller.js +80 -0
- package/dist/builder/define-controller.js.map +1 -0
- package/dist/builder/define-endpoint.d.ts +157 -0
- package/dist/builder/define-endpoint.d.ts.map +1 -0
- package/dist/builder/define-endpoint.js +103 -0
- package/dist/builder/define-endpoint.js.map +1 -0
- package/dist/builder/define-route.d.ts +191 -0
- package/dist/builder/define-route.d.ts.map +1 -0
- package/dist/builder/define-route.js +124 -0
- package/dist/builder/define-route.js.map +1 -0
- package/dist/builder/index.d.ts +5 -0
- package/dist/builder/index.d.ts.map +1 -0
- package/dist/builder/index.js +7 -0
- package/dist/builder/index.js.map +1 -0
- package/dist/builder/openapi-builder.d.ts +120 -0
- package/dist/builder/openapi-builder.d.ts.map +1 -0
- package/dist/builder/openapi-builder.js +349 -0
- package/dist/builder/openapi-builder.js.map +1 -0
- package/dist/builder/path-params.d.ts +129 -0
- package/dist/builder/path-params.d.ts.map +1 -0
- package/dist/builder/path-params.js +85 -0
- package/dist/builder/path-params.js.map +1 -0
- package/dist/builder/types.d.ts +149 -0
- package/dist/builder/types.d.ts.map +1 -0
- package/dist/builder/types.js +6 -0
- package/dist/builder/types.js.map +1 -0
- package/dist/config/defaults.d.ts +10 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +28 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/define-config.d.ts +50 -0
- package/dist/config/define-config.d.ts.map +1 -0
- package/dist/config/define-config.js +80 -0
- package/dist/config/define-config.js.map +1 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +5 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/types.d.ts +103 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +2 -0
- package/dist/config/types.js.map +1 -0
- package/dist/decorators/api.d.ts +35 -0
- package/dist/decorators/api.d.ts.map +1 -0
- package/dist/decorators/api.js +34 -0
- package/dist/decorators/api.js.map +1 -0
- package/dist/decorators/controller.d.ts +35 -0
- package/dist/decorators/controller.d.ts.map +1 -0
- package/dist/decorators/controller.js +34 -0
- package/dist/decorators/controller.js.map +1 -0
- package/dist/decorators/endpoint.d.ts +93 -0
- package/dist/decorators/endpoint.d.ts.map +1 -0
- package/dist/decorators/endpoint.js +108 -0
- package/dist/decorators/endpoint.js.map +1 -0
- package/dist/decorators/index.d.ts +5 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +6 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/route.d.ts +93 -0
- package/dist/decorators/route.d.ts.map +1 -0
- package/dist/decorators/route.js +108 -0
- package/dist/decorators/route.js.map +1 -0
- package/dist/errors/base.d.ts +8 -0
- package/dist/errors/base.d.ts.map +1 -0
- package/dist/errors/base.js +13 -0
- package/dist/errors/base.js.map +1 -0
- package/dist/errors/configuration.d.ts +22 -0
- package/dist/errors/configuration.d.ts.map +1 -0
- package/dist/errors/configuration.js +33 -0
- package/dist/errors/configuration.js.map +1 -0
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +4 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/validation.d.ts +46 -0
- package/dist/errors/validation.d.ts.map +1 -0
- package/dist/errors/validation.js +52 -0
- package/dist/errors/validation.js.map +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/metadata/index.d.ts +2 -0
- package/dist/metadata/index.d.ts.map +1 -0
- package/dist/metadata/index.js +2 -0
- package/dist/metadata/index.js.map +1 -0
- package/dist/metadata/storage.d.ts +50 -0
- package/dist/metadata/storage.d.ts.map +1 -0
- package/dist/metadata/storage.js +100 -0
- package/dist/metadata/storage.js.map +1 -0
- package/dist/metadata/types.d.ts +142 -0
- package/dist/metadata/types.d.ts.map +1 -0
- package/dist/metadata/types.js +2 -0
- package/dist/metadata/types.js.map +1 -0
- package/dist/response/helpers.d.ts +132 -0
- package/dist/response/helpers.d.ts.map +1 -0
- package/dist/response/helpers.js +197 -0
- package/dist/response/helpers.js.map +1 -0
- package/dist/response/index.d.ts +4 -0
- package/dist/response/index.d.ts.map +1 -0
- package/dist/response/index.js +4 -0
- package/dist/response/index.js.map +1 -0
- package/dist/response/types.d.ts +59 -0
- package/dist/response/types.d.ts.map +1 -0
- package/dist/response/types.js +26 -0
- package/dist/response/types.js.map +1 -0
- package/dist/runtime/adapter-types.d.ts +119 -0
- package/dist/runtime/adapter-types.d.ts.map +1 -0
- package/dist/runtime/adapter-types.js +2 -0
- package/dist/runtime/adapter-types.js.map +1 -0
- package/dist/runtime/index.d.ts +12 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +10 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/response-helpers.d.ts +138 -0
- package/dist/runtime/response-helpers.d.ts.map +1 -0
- package/dist/runtime/response-helpers.js +105 -0
- package/dist/runtime/response-helpers.js.map +1 -0
- package/dist/runtime/route-utils.d.ts +22 -0
- package/dist/runtime/route-utils.d.ts.map +1 -0
- package/dist/runtime/route-utils.js +47 -0
- package/dist/runtime/route-utils.js.map +1 -0
- package/dist/runtime/types.d.ts +125 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +2 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/validation/index.d.ts +3 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +3 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/types.d.ts +55 -0
- package/dist/validation/types.d.ts.map +1 -0
- package/dist/validation/types.js +2 -0
- package/dist/validation/types.js.map +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { TSchema, Static } from '@sinclair/typebox';
|
|
2
|
+
import type { ApiResponse, BinaryResponse, ApiErrorBody } from './types.js';
|
|
3
|
+
import { type ValidationErrorDetail } from '../errors/validation.js';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for response helpers.
|
|
6
|
+
* Set by the framework configuration.
|
|
7
|
+
*/
|
|
8
|
+
export interface ResponseConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Whether to validate responses at runtime.
|
|
11
|
+
* Recommended: true in development, false in production.
|
|
12
|
+
*/
|
|
13
|
+
validateResponses: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Validator function for response data.
|
|
16
|
+
* Should throw or return errors array on failure.
|
|
17
|
+
*/
|
|
18
|
+
validator?: (schema: TSchema, data: unknown) => ValidationErrorDetail[] | void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Configure response helpers.
|
|
22
|
+
* Called by the framework adapter during setup.
|
|
23
|
+
*/
|
|
24
|
+
export declare function configureResponses(newConfig: Partial<ResponseConfig>): void;
|
|
25
|
+
/**
|
|
26
|
+
* Get current response configuration.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getResponseConfig(): ResponseConfig;
|
|
29
|
+
/**
|
|
30
|
+
* Core response builder with optional runtime validation.
|
|
31
|
+
*
|
|
32
|
+
* In development (validateResponses: true), validates that the data matches
|
|
33
|
+
* the schema to catch contract violations early.
|
|
34
|
+
*/
|
|
35
|
+
export declare function respond<TStatus extends number, TResponseSchema extends TSchema>(status: TStatus, schema: TResponseSchema, data: Static<TResponseSchema>): ApiResponse<TStatus, Static<TResponseSchema>>;
|
|
36
|
+
/**
|
|
37
|
+
* Return 200 OK with validated response body.
|
|
38
|
+
*/
|
|
39
|
+
export declare function ok<T extends TSchema>(schema: T, data: Static<T>): ApiResponse<200, Static<T>>;
|
|
40
|
+
/**
|
|
41
|
+
* Return 201 Created with validated response body.
|
|
42
|
+
*/
|
|
43
|
+
export declare function created<T extends TSchema>(schema: T, data: Static<T>): ApiResponse<201, Static<T>>;
|
|
44
|
+
/**
|
|
45
|
+
* Return 202 Accepted with validated response body.
|
|
46
|
+
*/
|
|
47
|
+
export declare function accepted<T extends TSchema>(schema: T, data: Static<T>): ApiResponse<202, Static<T>>;
|
|
48
|
+
/**
|
|
49
|
+
* Return 204 No Content.
|
|
50
|
+
*/
|
|
51
|
+
export declare function noContent(): ApiResponse<204, null>;
|
|
52
|
+
/**
|
|
53
|
+
* Return 400 Bad Request.
|
|
54
|
+
*/
|
|
55
|
+
export declare function badRequest<T extends TSchema>(schema: T, data: Static<T>): ApiResponse<400, Static<T>>;
|
|
56
|
+
/**
|
|
57
|
+
* Return 401 Unauthorized.
|
|
58
|
+
*/
|
|
59
|
+
export declare function unauthorized<T extends TSchema>(schema: T, data: Static<T>): ApiResponse<401, Static<T>>;
|
|
60
|
+
/**
|
|
61
|
+
* Return 403 Forbidden.
|
|
62
|
+
*/
|
|
63
|
+
export declare function forbidden<T extends TSchema>(schema: T, data: Static<T>): ApiResponse<403, Static<T>>;
|
|
64
|
+
/**
|
|
65
|
+
* Return 404 Not Found.
|
|
66
|
+
*/
|
|
67
|
+
export declare function notFound<T extends TSchema>(schema: T, data: Static<T>): ApiResponse<404, Static<T>>;
|
|
68
|
+
/**
|
|
69
|
+
* Return 409 Conflict.
|
|
70
|
+
*/
|
|
71
|
+
export declare function conflict<T extends TSchema>(schema: T, data: Static<T>): ApiResponse<409, Static<T>>;
|
|
72
|
+
/**
|
|
73
|
+
* Return 422 Unprocessable Entity (validation errors).
|
|
74
|
+
*/
|
|
75
|
+
export declare function unprocessableEntity<T extends TSchema>(schema: T, data: Static<T>): ApiResponse<422, Static<T>>;
|
|
76
|
+
/**
|
|
77
|
+
* Return 429 Too Many Requests.
|
|
78
|
+
*/
|
|
79
|
+
export declare function tooManyRequests<T extends TSchema>(schema: T, data: Static<T>): ApiResponse<429, Static<T>>;
|
|
80
|
+
/**
|
|
81
|
+
* Return 500 Internal Server Error.
|
|
82
|
+
*/
|
|
83
|
+
export declare function internalServerError<T extends TSchema>(schema: T, data: Static<T>): ApiResponse<500, Static<T>>;
|
|
84
|
+
/**
|
|
85
|
+
* Return 502 Bad Gateway.
|
|
86
|
+
*/
|
|
87
|
+
export declare function badGateway<T extends TSchema>(schema: T, data: Static<T>): ApiResponse<502, Static<T>>;
|
|
88
|
+
/**
|
|
89
|
+
* Return 503 Service Unavailable.
|
|
90
|
+
*/
|
|
91
|
+
export declare function serviceUnavailable<T extends TSchema>(schema: T, data: Static<T>): ApiResponse<503, Static<T>>;
|
|
92
|
+
/**
|
|
93
|
+
* Return a binary/file response for downloads.
|
|
94
|
+
*/
|
|
95
|
+
export declare function binary<TStatus extends number>(status: TStatus, contentType: string, data: Buffer | string, filename?: string): BinaryResponse<TStatus>;
|
|
96
|
+
/**
|
|
97
|
+
* Unified API error response helpers with sensible defaults.
|
|
98
|
+
* Returns responses matching the standard ApiErrorBody structure.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* // Use defaults
|
|
103
|
+
* return apiError.notFound() // "Resource not found"
|
|
104
|
+
* return apiError.unauthorized() // "Authentication required"
|
|
105
|
+
*
|
|
106
|
+
* // Override message
|
|
107
|
+
* return apiError.notFound('Book not found')
|
|
108
|
+
* return apiError.serviceUnavailable('API is not configured')
|
|
109
|
+
*
|
|
110
|
+
* // Validation errors
|
|
111
|
+
* return apiError.validation([
|
|
112
|
+
* { field: 'email', message: 'Invalid email format' },
|
|
113
|
+
* ])
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
export declare const apiError: {
|
|
117
|
+
badRequest: (message?: string) => ApiResponse<400, ApiErrorBody>;
|
|
118
|
+
unauthorized: (message?: string) => ApiResponse<401, ApiErrorBody>;
|
|
119
|
+
forbidden: (message?: string) => ApiResponse<403, ApiErrorBody>;
|
|
120
|
+
notFound: (message?: string) => ApiResponse<404, ApiErrorBody>;
|
|
121
|
+
validation: (errors: Array<{
|
|
122
|
+
field?: string;
|
|
123
|
+
message: string;
|
|
124
|
+
code?: string;
|
|
125
|
+
}>) => ApiResponse<422, ApiErrorBody>;
|
|
126
|
+
conflict: (message?: string) => ApiResponse<409, ApiErrorBody>;
|
|
127
|
+
rateLimited: (message?: string) => ApiResponse<429, ApiErrorBody>;
|
|
128
|
+
internal: (message?: string) => ApiResponse<500, ApiErrorBody>;
|
|
129
|
+
serviceUnavailable: (message?: string) => ApiResponse<503, ApiErrorBody>;
|
|
130
|
+
externalApi: (message?: string) => ApiResponse<502, ApiErrorBody>;
|
|
131
|
+
};
|
|
132
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/response/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE3E,OAAO,EAA2B,KAAK,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAE7F;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,iBAAiB,EAAE,OAAO,CAAA;IAE1B;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,KAAK,qBAAqB,EAAE,GAAG,IAAI,CAAA;CAC/E;AAMD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI,CAE3E;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CAElD;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,OAAO,SAAS,MAAM,EAAE,eAAe,SAAS,OAAO,EAC7E,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,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wBAAgB,kBAAkB,CAAC,CAAC,SAAS,OAAO,EAClD,MAAM,EAAE,CAAC,EACT,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,GACd,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAE7B;AAID;;GAEG;AACH,wBAAgB,MAAM,CAAC,OAAO,SAAS,MAAM,EAC3C,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,QAAQ,CAAC,EAAE,MAAM,GAChB,cAAc,CAAC,OAAO,CAAC,CAEzB;AAID;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,QAAQ;sCACoB,WAAW,CAAC,GAAG,EAAE,YAAY,CAAC;wCAKhB,WAAW,CAAC,GAAG,EAAE,YAAY,CAAC;qCAK3C,WAAW,CAAC,GAAG,EAAE,YAAY,CAAC;oCAK1B,WAAW,CAAC,GAAG,EAAE,YAAY,CAAC;yBAMhE,KAAK,CAAC;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,KAChE,WAAW,CAAC,GAAG,EAAE,YAAY,CAAC;oCAUU,WAAW,CAAC,GAAG,EAAE,YAAY,CAAC;uCAK3B,WAAW,CAAC,GAAG,EAAE,YAAY,CAAC;oCAK7B,WAAW,CAAC,GAAG,EAAE,YAAY,CAAC;8CAKtB,WAAW,CAAC,GAAG,EAAE,YAAY,CAAC;uCAKtC,WAAW,CAAC,GAAG,EAAE,YAAY,CAAC;CAI9E,CAAA"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { ErrorCodes } from './types.js';
|
|
2
|
+
import { ResponseValidationError } from '../errors/validation.js';
|
|
3
|
+
let config = {
|
|
4
|
+
validateResponses: false,
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Configure response helpers.
|
|
8
|
+
* Called by the framework adapter during setup.
|
|
9
|
+
*/
|
|
10
|
+
export function configureResponses(newConfig) {
|
|
11
|
+
config = { ...config, ...newConfig };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get current response configuration.
|
|
15
|
+
*/
|
|
16
|
+
export function getResponseConfig() {
|
|
17
|
+
return config;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Core response builder with optional runtime validation.
|
|
21
|
+
*
|
|
22
|
+
* In development (validateResponses: true), validates that the data matches
|
|
23
|
+
* the schema to catch contract violations early.
|
|
24
|
+
*/
|
|
25
|
+
export function respond(status, schema, data) {
|
|
26
|
+
if (config.validateResponses && config.validator) {
|
|
27
|
+
// Validate the serialized form (what actually gets sent)
|
|
28
|
+
const serialized = JSON.parse(JSON.stringify(data));
|
|
29
|
+
const errors = config.validator(schema, serialized);
|
|
30
|
+
if (errors && errors.length > 0) {
|
|
31
|
+
throw new ResponseValidationError(schema, data, errors);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return { status, data };
|
|
35
|
+
}
|
|
36
|
+
// ============ Success Helpers ============
|
|
37
|
+
/**
|
|
38
|
+
* Return 200 OK with validated response body.
|
|
39
|
+
*/
|
|
40
|
+
export function ok(schema, data) {
|
|
41
|
+
return respond(200, schema, data);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Return 201 Created with validated response body.
|
|
45
|
+
*/
|
|
46
|
+
export function created(schema, data) {
|
|
47
|
+
return respond(201, schema, data);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Return 202 Accepted with validated response body.
|
|
51
|
+
*/
|
|
52
|
+
export function accepted(schema, data) {
|
|
53
|
+
return respond(202, schema, data);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Return 204 No Content.
|
|
57
|
+
*/
|
|
58
|
+
export function noContent() {
|
|
59
|
+
return { status: 204, data: null };
|
|
60
|
+
}
|
|
61
|
+
// ============ Error Helpers ============
|
|
62
|
+
/**
|
|
63
|
+
* Return 400 Bad Request.
|
|
64
|
+
*/
|
|
65
|
+
export function badRequest(schema, data) {
|
|
66
|
+
return respond(400, schema, data);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Return 401 Unauthorized.
|
|
70
|
+
*/
|
|
71
|
+
export function unauthorized(schema, data) {
|
|
72
|
+
return respond(401, schema, data);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Return 403 Forbidden.
|
|
76
|
+
*/
|
|
77
|
+
export function forbidden(schema, data) {
|
|
78
|
+
return respond(403, schema, data);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Return 404 Not Found.
|
|
82
|
+
*/
|
|
83
|
+
export function notFound(schema, data) {
|
|
84
|
+
return respond(404, schema, data);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Return 409 Conflict.
|
|
88
|
+
*/
|
|
89
|
+
export function conflict(schema, data) {
|
|
90
|
+
return respond(409, schema, data);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Return 422 Unprocessable Entity (validation errors).
|
|
94
|
+
*/
|
|
95
|
+
export function unprocessableEntity(schema, data) {
|
|
96
|
+
return respond(422, schema, data);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Return 429 Too Many Requests.
|
|
100
|
+
*/
|
|
101
|
+
export function tooManyRequests(schema, data) {
|
|
102
|
+
return respond(429, schema, data);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Return 500 Internal Server Error.
|
|
106
|
+
*/
|
|
107
|
+
export function internalServerError(schema, data) {
|
|
108
|
+
return respond(500, schema, data);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Return 502 Bad Gateway.
|
|
112
|
+
*/
|
|
113
|
+
export function badGateway(schema, data) {
|
|
114
|
+
return respond(502, schema, data);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Return 503 Service Unavailable.
|
|
118
|
+
*/
|
|
119
|
+
export function serviceUnavailable(schema, data) {
|
|
120
|
+
return respond(503, schema, data);
|
|
121
|
+
}
|
|
122
|
+
// ============ Binary Response ============
|
|
123
|
+
/**
|
|
124
|
+
* Return a binary/file response for downloads.
|
|
125
|
+
*/
|
|
126
|
+
export function binary(status, contentType, data, filename) {
|
|
127
|
+
return { status, binary: true, contentType, data, filename };
|
|
128
|
+
}
|
|
129
|
+
// ============ Unified apiError Helpers ============
|
|
130
|
+
/**
|
|
131
|
+
* Unified API error response helpers with sensible defaults.
|
|
132
|
+
* Returns responses matching the standard ApiErrorBody structure.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* // Use defaults
|
|
137
|
+
* return apiError.notFound() // "Resource not found"
|
|
138
|
+
* return apiError.unauthorized() // "Authentication required"
|
|
139
|
+
*
|
|
140
|
+
* // Override message
|
|
141
|
+
* return apiError.notFound('Book not found')
|
|
142
|
+
* return apiError.serviceUnavailable('API is not configured')
|
|
143
|
+
*
|
|
144
|
+
* // Validation errors
|
|
145
|
+
* return apiError.validation([
|
|
146
|
+
* { field: 'email', message: 'Invalid email format' },
|
|
147
|
+
* ])
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export const apiError = {
|
|
151
|
+
badRequest: (message = 'Bad request') => ({
|
|
152
|
+
status: 400,
|
|
153
|
+
data: { status: 400, code: ErrorCodes.BAD_REQUEST, message },
|
|
154
|
+
}),
|
|
155
|
+
unauthorized: (message = 'Authentication required') => ({
|
|
156
|
+
status: 401,
|
|
157
|
+
data: { status: 401, code: ErrorCodes.UNAUTHORIZED, message },
|
|
158
|
+
}),
|
|
159
|
+
forbidden: (message = 'Access denied') => ({
|
|
160
|
+
status: 403,
|
|
161
|
+
data: { status: 403, code: ErrorCodes.FORBIDDEN, message },
|
|
162
|
+
}),
|
|
163
|
+
notFound: (message = 'Resource not found') => ({
|
|
164
|
+
status: 404,
|
|
165
|
+
data: { status: 404, code: ErrorCodes.NOT_FOUND, message },
|
|
166
|
+
}),
|
|
167
|
+
validation: (errors) => ({
|
|
168
|
+
status: 422,
|
|
169
|
+
data: {
|
|
170
|
+
status: 422,
|
|
171
|
+
code: ErrorCodes.VALIDATION,
|
|
172
|
+
message: 'Validation failed',
|
|
173
|
+
errors,
|
|
174
|
+
},
|
|
175
|
+
}),
|
|
176
|
+
conflict: (message = 'Resource conflict') => ({
|
|
177
|
+
status: 409,
|
|
178
|
+
data: { status: 409, code: ErrorCodes.CONFLICT, message },
|
|
179
|
+
}),
|
|
180
|
+
rateLimited: (message = 'Too many requests') => ({
|
|
181
|
+
status: 429,
|
|
182
|
+
data: { status: 429, code: ErrorCodes.RATE_LIMITED, message },
|
|
183
|
+
}),
|
|
184
|
+
internal: (message = 'Internal server error') => ({
|
|
185
|
+
status: 500,
|
|
186
|
+
data: { status: 500, code: ErrorCodes.INTERNAL, message },
|
|
187
|
+
}),
|
|
188
|
+
serviceUnavailable: (message = 'Service unavailable') => ({
|
|
189
|
+
status: 503,
|
|
190
|
+
data: { status: 503, code: ErrorCodes.SERVICE_UNAVAILABLE, message },
|
|
191
|
+
}),
|
|
192
|
+
externalApi: (message = 'External API error') => ({
|
|
193
|
+
status: 502,
|
|
194
|
+
data: { status: 502, code: ErrorCodes.EXTERNAL_API, message },
|
|
195
|
+
}),
|
|
196
|
+
};
|
|
197
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/response/helpers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,uBAAuB,EAA8B,MAAM,yBAAyB,CAAA;AAoB7F,IAAI,MAAM,GAAmB;IAC3B,iBAAiB,EAAE,KAAK;CACzB,CAAA;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAAkC;IACnE,MAAM,GAAG,EAAE,GAAG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AAE;KAC9D,CAAC;CACH,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { ApiResponse, BinaryResponse, AnyResponse, ApiErrorBody, ErrorCode, } from './types.js';
|
|
2
|
+
export { isBinaryResponse, ErrorCodes } from './types.js';
|
|
3
|
+
export { configureResponses, getResponseConfig, respond, ok, created, accepted, noContent, badRequest, unauthorized, forbidden, notFound, conflict, unprocessableEntity, tooManyRequests, internalServerError, badGateway, serviceUnavailable, binary, apiError, type ResponseConfig, } from './helpers.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/response/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,WAAW,EACX,cAAc,EACd,WAAW,EACX,YAAY,EACZ,SAAS,GACV,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAGzD,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,OAAO,EACP,EAAE,EACF,OAAO,EACP,QAAQ,EACR,SAAS,EACT,UAAU,EACV,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,UAAU,EACV,kBAAkB,EAClB,MAAM,EACN,QAAQ,EACR,KAAK,cAAc,GACpB,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { isBinaryResponse, ErrorCodes } from './types.js';
|
|
2
|
+
// Response helpers
|
|
3
|
+
export { configureResponses, getResponseConfig, respond, ok, created, accepted, noContent, badRequest, unauthorized, forbidden, notFound, conflict, unprocessableEntity, tooManyRequests, internalServerError, badGateway, serviceUnavailable, binary, apiError, } from './helpers.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/response/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEzD,mBAAmB;AACnB,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,OAAO,EACP,EAAE,EACF,OAAO,EACP,QAAQ,EACR,SAAS,EACT,UAAU,EACV,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,UAAU,EACV,kBAAkB,EAClB,MAAM,EACN,QAAQ,GAET,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard API response wrapper.
|
|
3
|
+
* Used by response helpers to carry status code and data together.
|
|
4
|
+
*/
|
|
5
|
+
export interface ApiResponse<TStatus extends number, TData> {
|
|
6
|
+
status: TStatus;
|
|
7
|
+
data: TData;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Binary response for file downloads.
|
|
11
|
+
* Bypasses JSON serialization and sends raw data.
|
|
12
|
+
*/
|
|
13
|
+
export interface BinaryResponse<TStatus extends number> {
|
|
14
|
+
status: TStatus;
|
|
15
|
+
binary: true;
|
|
16
|
+
contentType: string;
|
|
17
|
+
filename?: string;
|
|
18
|
+
data: Buffer | string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Union of all possible response types.
|
|
22
|
+
*/
|
|
23
|
+
export type AnyResponse = ApiResponse<number, unknown> | BinaryResponse<number>;
|
|
24
|
+
/**
|
|
25
|
+
* Type guard to check if a response is binary.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isBinaryResponse(response: unknown): response is BinaryResponse<number>;
|
|
28
|
+
/**
|
|
29
|
+
* Common error codes for API responses.
|
|
30
|
+
* These can be extended by applications.
|
|
31
|
+
*/
|
|
32
|
+
export declare const ErrorCodes: {
|
|
33
|
+
readonly BAD_REQUEST: "E_BAD_REQUEST";
|
|
34
|
+
readonly UNAUTHORIZED: "E_UNAUTHORIZED";
|
|
35
|
+
readonly FORBIDDEN: "E_FORBIDDEN";
|
|
36
|
+
readonly NOT_FOUND: "E_NOT_FOUND";
|
|
37
|
+
readonly VALIDATION: "E_VALIDATION";
|
|
38
|
+
readonly CONFLICT: "E_CONFLICT";
|
|
39
|
+
readonly RATE_LIMITED: "E_RATE_LIMITED";
|
|
40
|
+
readonly INTERNAL: "E_INTERNAL";
|
|
41
|
+
readonly SERVICE_UNAVAILABLE: "E_SERVICE_UNAVAILABLE";
|
|
42
|
+
readonly EXTERNAL_API: "E_EXTERNAL_API";
|
|
43
|
+
};
|
|
44
|
+
export type ErrorCode = typeof ErrorCodes[keyof typeof ErrorCodes];
|
|
45
|
+
/**
|
|
46
|
+
* Standard error response structure.
|
|
47
|
+
* Applications can extend this with additional fields.
|
|
48
|
+
*/
|
|
49
|
+
export interface ApiErrorBody {
|
|
50
|
+
status: number;
|
|
51
|
+
code: string;
|
|
52
|
+
message: string;
|
|
53
|
+
errors?: Array<{
|
|
54
|
+
field?: string;
|
|
55
|
+
message: string;
|
|
56
|
+
code?: string;
|
|
57
|
+
}>;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/response/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,WAAW,CAAC,OAAO,SAAS,MAAM,EAAE,KAAK;IACxD,MAAM,EAAE,OAAO,CAAA;IACf,IAAI,EAAE,KAAK,CAAA;CACZ;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc,CAAC,OAAO,SAAS,MAAM;IACpD,MAAM,EAAE,OAAO,CAAA;IACf,MAAM,EAAE,IAAI,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,CAAA;AAE/E;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,cAAc,CAAC,MAAM,CAAC,CAOtF;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;CAWb,CAAA;AAEV,MAAM,MAAM,SAAS,GAAG,OAAO,UAAU,CAAC,MAAM,OAAO,UAAU,CAAC,CAAA;AAElE;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,KAAK,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,OAAO,EAAE,MAAM,CAAA;QACf,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAC,CAAA;CACH"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guard to check if a response is binary.
|
|
3
|
+
*/
|
|
4
|
+
export function isBinaryResponse(response) {
|
|
5
|
+
return (response !== null
|
|
6
|
+
&& typeof response === 'object'
|
|
7
|
+
&& 'binary' in response
|
|
8
|
+
&& response.binary === true);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Common error codes for API responses.
|
|
12
|
+
* These can be extended by applications.
|
|
13
|
+
*/
|
|
14
|
+
export const ErrorCodes = {
|
|
15
|
+
BAD_REQUEST: 'E_BAD_REQUEST',
|
|
16
|
+
UNAUTHORIZED: 'E_UNAUTHORIZED',
|
|
17
|
+
FORBIDDEN: 'E_FORBIDDEN',
|
|
18
|
+
NOT_FOUND: 'E_NOT_FOUND',
|
|
19
|
+
VALIDATION: 'E_VALIDATION',
|
|
20
|
+
CONFLICT: 'E_CONFLICT',
|
|
21
|
+
RATE_LIMITED: 'E_RATE_LIMITED',
|
|
22
|
+
INTERNAL: 'E_INTERNAL',
|
|
23
|
+
SERVICE_UNAVAILABLE: 'E_SERVICE_UNAVAILABLE',
|
|
24
|
+
EXTERNAL_API: 'E_EXTERNAL_API',
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/response/types.ts"],"names":[],"mappings":"AA0BA;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAiB;IAChD,OAAO,CACL,QAAQ,KAAK,IAAI;WACd,OAAO,QAAQ,KAAK,QAAQ;WAC5B,QAAQ,IAAI,QAAQ;WACnB,QAAmC,CAAC,MAAM,KAAK,IAAI,CACxD,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,WAAW,EAAE,eAAe;IAC5B,YAAY,EAAE,gBAAgB;IAC9B,SAAS,EAAE,aAAa;IACxB,SAAS,EAAE,aAAa;IACxB,UAAU,EAAE,cAAc;IAC1B,QAAQ,EAAE,YAAY;IACtB,YAAY,EAAE,gBAAgB;IAC9B,QAAQ,EAAE,YAAY;IACtB,mBAAmB,EAAE,uBAAuB;IAC5C,YAAY,EAAE,gBAAgB;CACtB,CAAA"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared type definitions for kontract framework adapters.
|
|
3
|
+
*
|
|
4
|
+
* These types are used across all framework adapters (Hono, Fastify, Express, AdonisJS)
|
|
5
|
+
* to provide consistent typing for response helpers and handler contexts.
|
|
6
|
+
*/
|
|
7
|
+
import type { TSchema, Static } from '@sinclair/typebox';
|
|
8
|
+
import type { ApiResponse } from '../response/types.js';
|
|
9
|
+
import type { ResponseExample, ResponseHeader } from '../metadata/types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Response configuration for routes.
|
|
12
|
+
* Maps HTTP status codes to schemas or response definitions.
|
|
13
|
+
*/
|
|
14
|
+
export type ResponsesConfig = Record<number, TSchema | null | {
|
|
15
|
+
schema: TSchema | null;
|
|
16
|
+
description?: string;
|
|
17
|
+
headers?: Record<string, ResponseHeader>;
|
|
18
|
+
examples?: Record<string, ResponseExample>;
|
|
19
|
+
example?: unknown;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Normalized response entry (internal use).
|
|
23
|
+
*/
|
|
24
|
+
export interface NormalizedResponse {
|
|
25
|
+
schema: TSchema | null;
|
|
26
|
+
description?: string;
|
|
27
|
+
headers?: Record<string, ResponseHeader>;
|
|
28
|
+
examples?: Record<string, ResponseExample>;
|
|
29
|
+
example?: unknown;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Normalized responses map (internal use).
|
|
33
|
+
*/
|
|
34
|
+
export type NormalizedResponses = Record<number, NormalizedResponse>;
|
|
35
|
+
/**
|
|
36
|
+
* Extract the schema from a response definition.
|
|
37
|
+
* Handles both `{ schema: T }` and raw `T` formats.
|
|
38
|
+
*/
|
|
39
|
+
export type ExtractResponseSchema<T> = T extends {
|
|
40
|
+
schema: infer S;
|
|
41
|
+
} ? S extends TSchema ? S : never : T extends TSchema ? T : never;
|
|
42
|
+
/**
|
|
43
|
+
* Get the schema type for a specific status code, or `never` if not defined.
|
|
44
|
+
*/
|
|
45
|
+
export type ResponseSchemaFor<TResponses, Status extends number> = Status extends keyof TResponses ? ExtractResponseSchema<TResponses[Status]> : never;
|
|
46
|
+
/**
|
|
47
|
+
* Helper type to create a typed response function for a specific status code.
|
|
48
|
+
*/
|
|
49
|
+
export type TypedHelper<TResponses, Status extends number> = ResponseSchemaFor<TResponses, Status> extends TSchema ? (data: Static<ResponseSchemaFor<TResponses, Status>>) => ApiResponse<Status, Static<ResponseSchemaFor<TResponses, Status>>> : never;
|
|
50
|
+
/**
|
|
51
|
+
* Error helper that accepts:
|
|
52
|
+
* - No args: use description from response definition as message
|
|
53
|
+
* - A string: use as message, auto-fill status and code
|
|
54
|
+
* - An object: merge with defaults (status, code, description as message)
|
|
55
|
+
*/
|
|
56
|
+
export type TypedErrorHelper<TResponses, Status extends number> = ResponseSchemaFor<TResponses, Status> extends TSchema ? (dataOrMessage?: string | Partial<Static<ResponseSchemaFor<TResponses, Status>>>) => ApiResponse<Status, Static<ResponseSchemaFor<TResponses, Status>>> : never;
|
|
57
|
+
/**
|
|
58
|
+
* Success response helpers namespace (2xx).
|
|
59
|
+
* Only includes methods for status codes that are defined in responses.
|
|
60
|
+
*/
|
|
61
|
+
export type ReplyHelpers<TResponses extends ResponsesConfig> = (200 extends keyof TResponses ? {
|
|
62
|
+
ok: TypedHelper<TResponses, 200>;
|
|
63
|
+
list: TypedHelper<TResponses, 200>;
|
|
64
|
+
} : unknown) & (201 extends keyof TResponses ? {
|
|
65
|
+
created: TypedHelper<TResponses, 201>;
|
|
66
|
+
} : unknown) & (202 extends keyof TResponses ? {
|
|
67
|
+
accepted: TypedHelper<TResponses, 202>;
|
|
68
|
+
} : unknown) & (204 extends keyof TResponses ? {
|
|
69
|
+
noContent: () => ApiResponse<204, null>;
|
|
70
|
+
} : unknown);
|
|
71
|
+
/**
|
|
72
|
+
* Error response helpers namespace (4xx/5xx).
|
|
73
|
+
* Only includes methods for status codes that are defined in responses.
|
|
74
|
+
*
|
|
75
|
+
* Each method accepts:
|
|
76
|
+
* - No args: `error.internal()` - uses response description as message
|
|
77
|
+
* - A string: `error.badRequest('Invalid token')`
|
|
78
|
+
* - An object: `error.badRequest({ message: 'Invalid', details: {...} })`
|
|
79
|
+
*
|
|
80
|
+
* Status, code, and message are auto-filled from sensible defaults.
|
|
81
|
+
*/
|
|
82
|
+
export type ErrorHelpers<TResponses extends ResponsesConfig> = (400 extends keyof TResponses ? {
|
|
83
|
+
badRequest: TypedErrorHelper<TResponses, 400>;
|
|
84
|
+
} : unknown) & (401 extends keyof TResponses ? {
|
|
85
|
+
unauthorized: TypedErrorHelper<TResponses, 401>;
|
|
86
|
+
} : unknown) & (403 extends keyof TResponses ? {
|
|
87
|
+
forbidden: TypedErrorHelper<TResponses, 403>;
|
|
88
|
+
} : unknown) & (404 extends keyof TResponses ? {
|
|
89
|
+
notFound: TypedErrorHelper<TResponses, 404>;
|
|
90
|
+
} : unknown) & (409 extends keyof TResponses ? {
|
|
91
|
+
conflict: TypedErrorHelper<TResponses, 409>;
|
|
92
|
+
} : unknown) & (422 extends keyof TResponses ? {
|
|
93
|
+
validationError: TypedErrorHelper<TResponses, 422>;
|
|
94
|
+
} : unknown) & (429 extends keyof TResponses ? {
|
|
95
|
+
tooManyRequests: TypedErrorHelper<TResponses, 429>;
|
|
96
|
+
} : unknown) & (500 extends keyof TResponses ? {
|
|
97
|
+
internal: TypedErrorHelper<TResponses, 500>;
|
|
98
|
+
} : unknown) & (503 extends keyof TResponses ? {
|
|
99
|
+
serviceUnavailable: TypedErrorHelper<TResponses, 503>;
|
|
100
|
+
} : unknown);
|
|
101
|
+
/**
|
|
102
|
+
* Base handler context interface.
|
|
103
|
+
* Framework adapters extend this with their specific context properties.
|
|
104
|
+
*/
|
|
105
|
+
export interface BaseHandlerContext<TBody = unknown, TQuery = unknown, TParams = unknown, TResponses extends ResponsesConfig = ResponsesConfig> {
|
|
106
|
+
/** Validated request body */
|
|
107
|
+
body: TBody;
|
|
108
|
+
/** Validated query parameters */
|
|
109
|
+
query: TQuery;
|
|
110
|
+
/** Validated path parameters */
|
|
111
|
+
params: TParams;
|
|
112
|
+
/** Authenticated user (available when auth is 'required' or 'optional') */
|
|
113
|
+
user: unknown;
|
|
114
|
+
/** Success response helpers (2xx) - methods typed from responses config */
|
|
115
|
+
reply: ReplyHelpers<TResponses>;
|
|
116
|
+
/** Error response helpers (4xx/5xx) - methods typed from responses config */
|
|
117
|
+
error: ErrorHelpers<TResponses>;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=adapter-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ad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GAAG,OAAO,CAAC,GACjG,CAAC,GAAG,SAAS,MAAM,UAAU,GAAG;IAAE,QAAQ,EAAE,gBAAgB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;CAAE,GAAG,OAAO,CAAC,GAC1F,CAAC,GAAG,SAAS,MAAM,UAAU,GAAG;IAAE,kBAAkB,EAAE,gBAAgB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;CAAE,GAAG,OAAO,CAAC,CAAA;AAM1G;;;GAGG;AACH,MAAM,WAAW,kBAAkB,CACjC,KAAK,GAAG,OAAO,EACf,MAAM,GAAG,OAAO,EAChB,OAAO,GAAG,OAAO,EACjB,UAAU,SAAS,eAAe,GAAG,eAAe;IAEpD,6BAA6B;IAC7B,IAAI,EAAE,KAAK,CAAA;IACX,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,gCAAgC;IAChC,MAAM,EAAE,OAAO,CAAA;IACf,2EAA2E;IAC3E,IAAI,EAAE,OAAO,CAAA;IACb,2EAA2E;IAC3E,KAAK,EAAE,YAAY,CAAC,UAAU,CAAC,CAAA;IAC/B,6EAA6E;IAC7E,KAAK,EAAE,YAAY,CAAC,UAAU,CAAC,CAAA;CAChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-types.js","sourceRoot":"","sources":["../../src/runtime/adapter-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime utilities for kontract adapters.
|
|
3
|
+
*
|
|
4
|
+
* This module exports shared code used by all framework adapters
|
|
5
|
+
* (Hono, Fastify, Express, AdonisJS) to reduce code duplication.
|
|
6
|
+
*/
|
|
7
|
+
export type { RequestContext, AuthUser, AuthResult, AdapterRouteHandler, RouterAdapter, AuthAdapter, ContainerAdapter, ResponseAdapter, LoggerAdapter, FrameworkAdapters, } from './types.js';
|
|
8
|
+
export type { ResponsesConfig, NormalizedResponse, NormalizedResponses, ExtractResponseSchema, ResponseSchemaFor, TypedHelper, TypedErrorHelper, ReplyHelpers, ErrorHelpers, BaseHandlerContext, } from './adapter-types.js';
|
|
9
|
+
export { ERROR_CODES, createSuccessHelper, createErrorHelper, getErrorMessage, createResponseHelpers, } from './response-helpers.js';
|
|
10
|
+
export type { RouteString } from './route-utils.js';
|
|
11
|
+
export { parseRouteString, normalizeResponses, isApiResponse, noContent, } from './route-utils.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,YAAY,EACV,cAAc,EACd,QAAQ,EACR,UAAU,EACV,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,iBAAiB,GAClB,MAAM,YAAY,CAAA;AAGnB,YAAY,EACV,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,kBAAkB,GACnB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,GACtB,MAAM,uBAAuB,CAAA;AAG9B,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,SAAS,GACV,MAAM,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime utilities for kontract adapters.
|
|
3
|
+
*
|
|
4
|
+
* This module exports shared code used by all framework adapters
|
|
5
|
+
* (Hono, Fastify, Express, AdonisJS) to reduce code duplication.
|
|
6
|
+
*/
|
|
7
|
+
// Response helpers
|
|
8
|
+
export { ERROR_CODES, createSuccessHelper, createErrorHelper, getErrorMessage, createResponseHelpers, } from './response-helpers.js';
|
|
9
|
+
export { parseRouteString, normalizeResponses, isApiResponse, noContent, } from './route-utils.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA8BH,mBAAmB;AACnB,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,GACtB,MAAM,uBAAuB,CAAA;AAI9B,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,SAAS,GACV,MAAM,kBAAkB,CAAA"}
|