@mpen/routekit 0.1.0 → 0.1.2

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.
Files changed (133) hide show
  1. package/dist/bin.d.mts +4 -0
  2. package/dist/client/react.d.mts +178 -0
  3. package/dist/client/react.mjs +142 -0
  4. package/dist/client.d.mts +433 -0
  5. package/dist/client.mjs +264 -0
  6. package/dist/content-BuDOmhH_.mjs +102 -0
  7. package/dist/core-CzUCxvGk.d.mts +140 -0
  8. package/dist/core-DbmQauwS.mjs +81 -0
  9. package/dist/handlers.d.mts +72 -0
  10. package/dist/handlers.mjs +153 -0
  11. package/dist/index.d.mts +3 -0
  12. package/dist/index.mjs +1152 -0
  13. package/dist/middleware.d.mts +388 -0
  14. package/dist/middleware.mjs +1222 -0
  15. package/dist/request-Dn0zc-xm.mjs +1025 -0
  16. package/dist/response/content.d.mts +79 -0
  17. package/dist/response/content.mjs +2 -0
  18. package/dist/response/json-rpc.d.mts +1 -0
  19. package/dist/response/json-rpc.mjs +1 -0
  20. package/dist/response/problem/valibot.d.mts +230 -0
  21. package/dist/response/problem/valibot.mjs +258 -0
  22. package/dist/response/problem.d.mts +415 -0
  23. package/dist/response/problem.mjs +183 -0
  24. package/dist/response/status.d.mts +45 -0
  25. package/dist/response/status.mjs +2 -0
  26. package/dist/responses-B379Ep9Y.d.mts +296 -0
  27. package/dist/responses-BpVrgeYi.mjs +101 -0
  28. package/dist/router-Cwb7ak0J.d.mts +1819 -0
  29. package/dist/routes.d.mts +282 -0
  30. package/dist/routes.mjs +311 -0
  31. package/dist/status-C-8mw-FB.mjs +59 -0
  32. package/dist/valibot-D7liFYyB.d.mts +290 -0
  33. package/dist/valibot-Du97X-TS.mjs +326 -0
  34. package/package.json +8 -2
  35. package/src/bin/gen-api-client.test.ts +0 -70
  36. package/src/bin/gen-api-client.ts +0 -986
  37. package/src/client/headers.ts +0 -31
  38. package/src/client/index.ts +0 -8
  39. package/src/client/promise.ts +0 -11
  40. package/src/client/react/index.test.tsx +0 -266
  41. package/src/client/react/index.ts +0 -431
  42. package/src/client/responses.test.ts +0 -151
  43. package/src/client/responses.ts +0 -278
  44. package/src/client/transport.ts +0 -74
  45. package/src/client/transports/body-codec.ts +0 -61
  46. package/src/client/transports/fetch.ts +0 -113
  47. package/src/client/tsconfig.json +0 -9
  48. package/src/client/types.ts +0 -15
  49. package/src/client/url.ts +0 -31
  50. package/src/index.ts +0 -63
  51. package/src/router/fetch-types.ts +0 -13
  52. package/src/router/handlers/index.ts +0 -2
  53. package/src/router/handlers/openapi/index.ts +0 -2
  54. package/src/router/handlers/openapi/openapi.ts +0 -293
  55. package/src/router/integration/zod-openapi.test.ts +0 -74
  56. package/src/router/lib/charset.test.ts +0 -22
  57. package/src/router/lib/charset.ts +0 -133
  58. package/src/router/lib/collections.ts +0 -3
  59. package/src/router/lib/format.test.ts +0 -67
  60. package/src/router/lib/format.ts +0 -35
  61. package/src/router/lib/host.ts +0 -4
  62. package/src/router/lib/json-schema.ts +0 -6
  63. package/src/router/lib/media-type.test.ts +0 -122
  64. package/src/router/lib/media-type.ts +0 -289
  65. package/src/router/lib/pathname.test.ts +0 -18
  66. package/src/router/lib/pathname.ts +0 -19
  67. package/src/router/lib/route-names.ts +0 -70
  68. package/src/router/lib/route-normalize.test.ts +0 -36
  69. package/src/router/lib/route-normalize.ts +0 -67
  70. package/src/router/lib/schema-merge.ts +0 -56
  71. package/src/router/middleware/accept-ctx.test.ts +0 -33
  72. package/src/router/middleware/accept-ctx.ts +0 -12
  73. package/src/router/middleware/body-limit.test.ts +0 -112
  74. package/src/router/middleware/body-limit.ts +0 -121
  75. package/src/router/middleware/content-type-context.ts +0 -0
  76. package/src/router/middleware/cors.test.ts +0 -269
  77. package/src/router/middleware/cors.ts +0 -490
  78. package/src/router/middleware/csrf.test.ts +0 -106
  79. package/src/router/middleware/csrf.ts +0 -192
  80. package/src/router/middleware/define.ts +0 -249
  81. package/src/router/middleware/index.ts +0 -34
  82. package/src/router/middleware/jsxhtml-response.ts +0 -0
  83. package/src/router/middleware/oas-swagger.ts +0 -0
  84. package/src/router/middleware/rate-limit.test.ts +0 -886
  85. package/src/router/middleware/rate-limit.ts +0 -920
  86. package/src/router/middleware/request-id-ctx.test.ts +0 -183
  87. package/src/router/middleware/request-id-ctx.ts +0 -135
  88. package/src/router/middleware/request-logger-format.test.ts +0 -16
  89. package/src/router/middleware/request-logger-format.ts +0 -269
  90. package/src/router/middleware/request-logger.test.ts +0 -267
  91. package/src/router/middleware/request-logger.ts +0 -131
  92. package/src/router/middleware/start-time-ctx.ts +0 -5
  93. package/src/router/request.ts +0 -611
  94. package/src/router/response/core.ts +0 -181
  95. package/src/router/response/directives.ts +0 -233
  96. package/src/router/response/formats/content/bodyless.ts +0 -54
  97. package/src/router/response/formats/content/content.ts +0 -79
  98. package/src/router/response/formats/content/index.ts +0 -2
  99. package/src/router/response/formats/json-rpc/index.ts +0 -2
  100. package/src/router/response/formats/problem/badRequest.ts +0 -90
  101. package/src/router/response/formats/problem/conflict.ts +0 -90
  102. package/src/router/response/formats/problem/created.ts +0 -40
  103. package/src/router/response/formats/problem/index.ts +0 -27
  104. package/src/router/response/formats/problem/notFound.ts +0 -90
  105. package/src/router/response/formats/problem/permissionDenied.ts +0 -90
  106. package/src/router/response/formats/problem/problem.test.ts +0 -888
  107. package/src/router/response/formats/problem/rateLimited.ts +0 -90
  108. package/src/router/response/formats/problem/responses.ts +0 -219
  109. package/src/router/response/formats/problem/root-errors.ts +0 -48
  110. package/src/router/response/formats/problem/sessionExpired.ts +0 -90
  111. package/src/router/response/formats/problem/types.ts +0 -170
  112. package/src/router/response/formats/problem/unauthenticated.ts +0 -90
  113. package/src/router/response/formats/problem/valibot.ts +0 -410
  114. package/src/router/response/formats/status/index.ts +0 -1
  115. package/src/router/response/formats/status/responses.ts +0 -59
  116. package/src/router/response/formats/status/status.test.ts +0 -21
  117. package/src/router/response/framers.ts +0 -85
  118. package/src/router/response/index.ts +0 -28
  119. package/src/router/response/openapi.test.ts +0 -96
  120. package/src/router/response/openapi.ts +0 -1
  121. package/src/router/response/serializers.ts +0 -66
  122. package/src/router/response/stream.ts +0 -35
  123. package/src/router/router.test.ts +0 -1571
  124. package/src/router/router.ts +0 -1965
  125. package/src/router/routes/index.ts +0 -46
  126. package/src/router/routes/valibot/index.ts +0 -18
  127. package/src/router/routes/valibot/valibot.ts +0 -1393
  128. package/src/router/routes/valibot.test.ts +0 -286
  129. package/src/router/routes/zod/index.ts +0 -18
  130. package/src/router/routes/zod/zod.ts +0 -1318
  131. package/src/router/routes/zod.test.ts +0 -280
  132. package/src/router/server-interface.ts +0 -31
  133. package/src/router/types.ts +0 -657
@@ -0,0 +1,415 @@
1
+ import { u as AnyContext, z as RouterExtension } from "../router-Cwb7ak0J.mjs";
2
+ import { n as RoutekitResponse } from "../core-CzUCxvGk.mjs";
3
+ import { a as ok, c as ProblemError, d as ProblemResponse, f as StandardResponse, i as ValidationProblemInit, l as ProblemIssue, n as SuccessResponseInit, o as problem, p as SuccessResponse, r as VALIDATION_PROBLEM_CODE, s as validationProblem, t as ProblemResponseInit, u as ProblemIssuePathSegment } from "../responses-B379Ep9Y.mjs";
4
+ import { HttpStatus } from "@mpen/http";
5
+
6
+ //#region src/router/response/formats/problem/created.d.ts
7
+ /**
8
+ * Create a `201 Created` standard response envelope.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * router.post('/users', () => created({ id: 'user_123' }))
13
+ * ```
14
+ *
15
+ * @param data - Successful response payload.
16
+ * @param init - Response headers and optional metadata.
17
+ * @returns Routekit logical response with an [`SuccessResponse`]{@link SuccessResponse} body.
18
+ * @typeParam Data - Successful response payload type.
19
+ * @typeParam Meta - Optional metadata payload type.
20
+ */
21
+ declare function created<const Data, const Meta = unknown>(data: Data, init?: SuccessResponseInit<Meta>): RoutekitResponse<SuccessResponse<Data, Meta>, HttpStatus.CREATED>;
22
+ //#endregion
23
+ //#region src/router/response/formats/problem/notFound.d.ts
24
+ /**
25
+ * Options accepted by [`notFound`]{@link notFound}.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * notFound({
30
+ * message: 'No user exists for the provided id.',
31
+ * })
32
+ * ```
33
+ *
34
+ * @typeParam Code - Machine-readable primary error code.
35
+ */
36
+ interface NotFoundInit<Code extends string = 'not_found'> extends Omit<ProblemResponseInit<Code>, 'code' | 'status' | 'message'> {
37
+ /**
38
+ * Machine-readable error code. Defaults to `'not_found'`.
39
+ */
40
+ code?: Code;
41
+ /**
42
+ * Human-readable problem message.
43
+ */
44
+ message?: string;
45
+ /**
46
+ * HTTP status code for this response. Defaults to `404`.
47
+ */
48
+ status?: number | HttpStatus;
49
+ }
50
+ /**
51
+ * Create a standard 404 Not Found problem response envelope.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * return notFound('Todo not found.')
56
+ * ```
57
+ *
58
+ * @param message - Human-readable problem message.
59
+ * @param init - Optional extra problem response options.
60
+ * @returns Routekit logical response with a `'not_found'` [`ProblemResponse`]{@link ProblemResponse}.
61
+ */
62
+ declare function notFound(message: string, init?: Omit<NotFoundInit<'not_found'>, 'message'>): RoutekitResponse<ProblemResponse<'not_found'>>;
63
+ /**
64
+ * Create a standard 404 Not Found problem response envelope.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * return notFound({ message: 'Todo not found.' })
69
+ * ```
70
+ *
71
+ * @param init - Optional problem response options.
72
+ * @returns Routekit logical response with a [`ProblemResponse`]{@link ProblemResponse}.
73
+ * @typeParam Code - Machine-readable primary error code.
74
+ */
75
+ declare function notFound<const Code extends string = 'not_found'>(init?: NotFoundInit<Code>): RoutekitResponse<ProblemResponse<Code>>;
76
+ //#endregion
77
+ //#region src/router/response/formats/problem/permissionDenied.d.ts
78
+ /**
79
+ * Options accepted by [`permissionDenied`]{@link permissionDenied}.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * permissionDenied({
84
+ * message: 'You do not have permission to perform this action.',
85
+ * })
86
+ * ```
87
+ *
88
+ * @typeParam Code - Machine-readable primary error code.
89
+ */
90
+ interface PermissionDeniedInit<Code extends string = 'permission_denied'> extends Omit<ProblemResponseInit<Code>, 'code' | 'status' | 'message'> {
91
+ /**
92
+ * Machine-readable error code. Defaults to `'permission_denied'`.
93
+ */
94
+ code?: Code;
95
+ /**
96
+ * Human-readable problem message.
97
+ */
98
+ message?: string;
99
+ /**
100
+ * HTTP status code for this response. Defaults to `403`.
101
+ */
102
+ status?: number | HttpStatus;
103
+ }
104
+ /**
105
+ * Create a standard 403 Permission Denied problem response envelope.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * return permissionDenied('You are not authorized to edit this profile.')
110
+ * ```
111
+ *
112
+ * @param message - Human-readable problem message.
113
+ * @param init - Optional extra problem response options.
114
+ * @returns Routekit logical response with a `'permission_denied'` [`ProblemResponse`]{@link ProblemResponse}.
115
+ */
116
+ declare function permissionDenied(message: string, init?: Omit<PermissionDeniedInit<'permission_denied'>, 'message'>): RoutekitResponse<ProblemResponse<'permission_denied'>>;
117
+ /**
118
+ * Create a standard 403 Permission Denied problem response envelope.
119
+ *
120
+ * @example
121
+ * ```ts
122
+ * return permissionDenied({ message: 'Insufficient scope.' })
123
+ * ```
124
+ *
125
+ * @param init - Optional problem response options.
126
+ * @returns Routekit logical response with a [`ProblemResponse`]{@link ProblemResponse}.
127
+ * @typeParam Code - Machine-readable primary error code.
128
+ */
129
+ declare function permissionDenied<const Code extends string = 'permission_denied'>(init?: PermissionDeniedInit<Code>): RoutekitResponse<ProblemResponse<Code>>;
130
+ //#endregion
131
+ //#region src/router/response/formats/problem/unauthenticated.d.ts
132
+ /**
133
+ * Options accepted by [`unauthenticated`]{@link unauthenticated}.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * unauthenticated({
138
+ * message: 'You must be logged in to access this resource.',
139
+ * })
140
+ * ```
141
+ *
142
+ * @typeParam Code - Machine-readable primary error code.
143
+ */
144
+ interface UnauthenticatedInit<Code extends string = 'unauthenticated'> extends Omit<ProblemResponseInit<Code>, 'code' | 'status' | 'message'> {
145
+ /**
146
+ * Machine-readable error code. Defaults to `'unauthenticated'`.
147
+ */
148
+ code?: Code;
149
+ /**
150
+ * Human-readable problem message.
151
+ */
152
+ message?: string;
153
+ /**
154
+ * HTTP status code for this response. Defaults to `401`.
155
+ */
156
+ status?: number | HttpStatus;
157
+ }
158
+ /**
159
+ * Create a standard 401 Unauthenticated problem response envelope.
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * return unauthenticated('Missing authorization token.')
164
+ * ```
165
+ *
166
+ * @param message - Human-readable problem message.
167
+ * @param init - Optional extra problem response options.
168
+ * @returns Routekit logical response with a `'unauthenticated'` [`ProblemResponse`]{@link ProblemResponse}.
169
+ */
170
+ declare function unauthenticated(message: string, init?: Omit<UnauthenticatedInit<'unauthenticated'>, 'message'>): RoutekitResponse<ProblemResponse<'unauthenticated'>>;
171
+ /**
172
+ * Create a standard 401 Unauthenticated problem response envelope.
173
+ *
174
+ * @example
175
+ * ```ts
176
+ * return unauthenticated({ message: 'Invalid credentials.' })
177
+ * ```
178
+ *
179
+ * @param init - Optional problem response options.
180
+ * @returns Routekit logical response with a [`ProblemResponse`]{@link ProblemResponse}.
181
+ * @typeParam Code - Machine-readable primary error code.
182
+ */
183
+ declare function unauthenticated<const Code extends string = 'unauthenticated'>(init?: UnauthenticatedInit<Code>): RoutekitResponse<ProblemResponse<Code>>;
184
+ //#endregion
185
+ //#region src/router/response/formats/problem/sessionExpired.d.ts
186
+ /**
187
+ * Options accepted by [`sessionExpired`]{@link sessionExpired}.
188
+ *
189
+ * @example
190
+ * ```ts
191
+ * sessionExpired({
192
+ * message: 'Your login session has expired. Please log in again.',
193
+ * })
194
+ * ```
195
+ *
196
+ * @typeParam Code - Machine-readable primary error code.
197
+ */
198
+ interface SessionExpiredInit<Code extends string = 'session_expired'> extends Omit<ProblemResponseInit<Code>, 'code' | 'status' | 'message'> {
199
+ /**
200
+ * Machine-readable error code. Defaults to `'session_expired'`.
201
+ */
202
+ code?: Code;
203
+ /**
204
+ * Human-readable problem message.
205
+ */
206
+ message?: string;
207
+ /**
208
+ * HTTP status code for this response. Defaults to `401`.
209
+ */
210
+ status?: number | HttpStatus;
211
+ }
212
+ /**
213
+ * Create a standard 401 Session Expired problem response envelope.
214
+ *
215
+ * @example
216
+ * ```ts
217
+ * return sessionExpired('Session has timed out.')
218
+ * ```
219
+ *
220
+ * @param message - Human-readable problem message.
221
+ * @param init - Optional extra problem response options.
222
+ * @returns Routekit logical response with a `'session_expired'` [`ProblemResponse`]{@link ProblemResponse}.
223
+ */
224
+ declare function sessionExpired(message: string, init?: Omit<SessionExpiredInit<'session_expired'>, 'message'>): RoutekitResponse<ProblemResponse<'session_expired'>>;
225
+ /**
226
+ * Create a standard 401 Session Expired problem response envelope.
227
+ *
228
+ * @example
229
+ * ```ts
230
+ * return sessionExpired({ message: 'Session expired.' })
231
+ * ```
232
+ *
233
+ * @param init - Optional problem response options.
234
+ * @returns Routekit logical response with a [`ProblemResponse`]{@link ProblemResponse}.
235
+ * @typeParam Code - Machine-readable primary error code.
236
+ */
237
+ declare function sessionExpired<const Code extends string = 'session_expired'>(init?: SessionExpiredInit<Code>): RoutekitResponse<ProblemResponse<Code>>;
238
+ //#endregion
239
+ //#region src/router/response/formats/problem/badRequest.d.ts
240
+ /**
241
+ * Options accepted by [`badRequest`]{@link badRequest}.
242
+ *
243
+ * @example
244
+ * ```ts
245
+ * badRequest({
246
+ * message: 'The request is malformed.',
247
+ * })
248
+ * ```
249
+ *
250
+ * @typeParam Code - Machine-readable primary error code.
251
+ */
252
+ interface BadRequestInit<Code extends string = 'bad_request'> extends Omit<ProblemResponseInit<Code>, 'code' | 'status' | 'message'> {
253
+ /**
254
+ * Machine-readable error code. Defaults to `'bad_request'`.
255
+ */
256
+ code?: Code;
257
+ /**
258
+ * Human-readable problem message.
259
+ */
260
+ message?: string;
261
+ /**
262
+ * HTTP status code for this response. Defaults to `400`.
263
+ */
264
+ status?: number | HttpStatus;
265
+ }
266
+ /**
267
+ * Create a standard 400 Bad Request problem response envelope.
268
+ *
269
+ * @example
270
+ * ```ts
271
+ * return badRequest('Invalid query parameter format.')
272
+ * ```
273
+ *
274
+ * @param message - Human-readable problem message.
275
+ * @param init - Optional extra problem response options.
276
+ * @returns Routekit logical response with a `'bad_request'` [`ProblemResponse`]{@link ProblemResponse}.
277
+ */
278
+ declare function badRequest(message: string, init?: Omit<BadRequestInit<'bad_request'>, 'message'>): RoutekitResponse<ProblemResponse<'bad_request'>>;
279
+ /**
280
+ * Create a standard 400 Bad Request problem response envelope.
281
+ *
282
+ * @example
283
+ * ```ts
284
+ * return badRequest({ message: 'Malformed payload.' })
285
+ * ```
286
+ *
287
+ * @param init - Optional problem response options.
288
+ * @returns Routekit logical response with a [`ProblemResponse`]{@link ProblemResponse}.
289
+ * @typeParam Code - Machine-readable primary error code.
290
+ */
291
+ declare function badRequest<const Code extends string = 'bad_request'>(init?: BadRequestInit<Code>): RoutekitResponse<ProblemResponse<Code>>;
292
+ //#endregion
293
+ //#region src/router/response/formats/problem/conflict.d.ts
294
+ /**
295
+ * Options accepted by [`conflict`]{@link conflict}.
296
+ *
297
+ * @example
298
+ * ```ts
299
+ * conflict({
300
+ * message: 'The resource already exists.',
301
+ * })
302
+ * ```
303
+ *
304
+ * @typeParam Code - Machine-readable primary error code.
305
+ */
306
+ interface ConflictInit<Code extends string = 'conflict'> extends Omit<ProblemResponseInit<Code>, 'code' | 'status' | 'message'> {
307
+ /**
308
+ * Machine-readable error code. Defaults to `'conflict'`.
309
+ */
310
+ code?: Code;
311
+ /**
312
+ * Human-readable problem message.
313
+ */
314
+ message?: string;
315
+ /**
316
+ * HTTP status code for this response. Defaults to `409`.
317
+ */
318
+ status?: number | HttpStatus;
319
+ }
320
+ /**
321
+ * Create a standard 409 Conflict problem response envelope.
322
+ *
323
+ * @example
324
+ * ```ts
325
+ * return conflict('A user with this email address already exists.')
326
+ * ```
327
+ *
328
+ * @param message - Human-readable problem message.
329
+ * @param init - Optional extra problem response options.
330
+ * @returns Routekit logical response with a `'conflict'` [`ProblemResponse`]{@link ProblemResponse}.
331
+ */
332
+ declare function conflict(message: string, init?: Omit<ConflictInit<'conflict'>, 'message'>): RoutekitResponse<ProblemResponse<'conflict'>>;
333
+ /**
334
+ * Create a standard 409 Conflict problem response envelope.
335
+ *
336
+ * @example
337
+ * ```ts
338
+ * return conflict({ message: 'State conflict.' })
339
+ * ```
340
+ *
341
+ * @param init - Optional problem response options.
342
+ * @returns Routekit logical response with a [`ProblemResponse`]{@link ProblemResponse}.
343
+ * @typeParam Code - Machine-readable primary error code.
344
+ */
345
+ declare function conflict<const Code extends string = 'conflict'>(init?: ConflictInit<Code>): RoutekitResponse<ProblemResponse<Code>>;
346
+ //#endregion
347
+ //#region src/router/response/formats/problem/rateLimited.d.ts
348
+ /**
349
+ * Options accepted by [`rateLimited`]{@link rateLimited}.
350
+ *
351
+ * @example
352
+ * ```ts
353
+ * rateLimited({
354
+ * message: 'Too many requests. Please try again later.',
355
+ * })
356
+ * ```
357
+ *
358
+ * @typeParam Code - Machine-readable primary error code.
359
+ */
360
+ interface RateLimitedInit<Code extends string = 'rate_limited'> extends Omit<ProblemResponseInit<Code>, 'code' | 'status' | 'message'> {
361
+ /**
362
+ * Machine-readable error code. Defaults to `'rate_limited'`.
363
+ */
364
+ code?: Code;
365
+ /**
366
+ * Human-readable problem message.
367
+ */
368
+ message?: string;
369
+ /**
370
+ * HTTP status code for this response. Defaults to `429`.
371
+ */
372
+ status?: number | HttpStatus;
373
+ }
374
+ /**
375
+ * Create a standard 429 Too Many Requests problem response envelope.
376
+ *
377
+ * @example
378
+ * ```ts
379
+ * return rateLimited('Rate limit exceeded. Please wait 60 seconds.')
380
+ * ```
381
+ *
382
+ * @param message - Human-readable problem message.
383
+ * @param init - Optional extra problem response options.
384
+ * @returns Routekit logical response with a `'rate_limited'` [`ProblemResponse`]{@link ProblemResponse}.
385
+ */
386
+ declare function rateLimited(message: string, init?: Omit<RateLimitedInit<'rate_limited'>, 'message'>): RoutekitResponse<ProblemResponse<'rate_limited'>>;
387
+ /**
388
+ * Create a standard 429 Too Many Requests problem response envelope.
389
+ *
390
+ * @example
391
+ * ```ts
392
+ * return rateLimited({ message: 'Rate limit exceeded.' })
393
+ * ```
394
+ *
395
+ * @param init - Optional problem response options.
396
+ * @returns Routekit logical response with a [`ProblemResponse`]{@link ProblemResponse}.
397
+ * @typeParam Code - Machine-readable primary error code.
398
+ */
399
+ declare function rateLimited<const Code extends string = 'rate_limited'>(init?: RateLimitedInit<Code>): RoutekitResponse<ProblemResponse<Code>>;
400
+ //#endregion
401
+ //#region src/router/response/formats/problem/root-errors.d.ts
402
+ /**
403
+ * Install standard problem-envelope handlers for router-level errors.
404
+ *
405
+ * @example
406
+ * ```ts
407
+ * const router = new Router().install(problemRootErrors())
408
+ * ```
409
+ *
410
+ * @returns Router extension that registers not-found, method, media-type, and internal-error handlers.
411
+ * @typeParam Ctx - Context carried by the router being configured.
412
+ */
413
+ declare function problemRootErrors<Ctx extends object = AnyContext>(): RouterExtension<Ctx>;
414
+ //#endregion
415
+ export { type BadRequestInit, type ConflictInit, type NotFoundInit, type PermissionDeniedInit, type ProblemError, type ProblemIssue, type ProblemIssuePathSegment, type ProblemResponse, type ProblemResponseInit, type RateLimitedInit, type SessionExpiredInit, type StandardResponse, type SuccessResponse, type SuccessResponseInit, type UnauthenticatedInit, VALIDATION_PROBLEM_CODE, type ValidationProblemInit, badRequest, conflict, created, notFound, ok, permissionDenied, problem, problemRootErrors, rateLimited, sessionExpired, unauthenticated, validationProblem };
@@ -0,0 +1,183 @@
1
+ import { a as response } from "../core-DbmQauwS.mjs";
2
+ import { i as validationProblem, n as ok, r as problem, t as VALIDATION_PROBLEM_CODE } from "../responses-BpVrgeYi.mjs";
3
+ import { HttpStatus } from "@mpen/http";
4
+ //#region src/router/response/formats/problem/created.ts
5
+ function withDefinedOptional(value, key, field) {
6
+ if (field === void 0) return value;
7
+ return {
8
+ ...value,
9
+ [key]: field
10
+ };
11
+ }
12
+ /**
13
+ * Create a `201 Created` standard response envelope.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * router.post('/users', () => created({ id: 'user_123' }))
18
+ * ```
19
+ *
20
+ * @param data - Successful response payload.
21
+ * @param init - Response headers and optional metadata.
22
+ * @returns Routekit logical response with an [`SuccessResponse`]{@link SuccessResponse} body.
23
+ * @typeParam Data - Successful response payload type.
24
+ * @typeParam Meta - Optional metadata payload type.
25
+ */
26
+ function created(data, init = {}) {
27
+ const { meta, ...responseInit } = init;
28
+ return response(withDefinedOptional({
29
+ success: true,
30
+ data
31
+ }, "meta", meta), {
32
+ ...responseInit,
33
+ status: HttpStatus.CREATED
34
+ });
35
+ }
36
+ //#endregion
37
+ //#region src/router/response/formats/problem/notFound.ts
38
+ function notFound(messageOrInit, init) {
39
+ if (typeof messageOrInit === "string") return problem({
40
+ ...init,
41
+ code: init?.code ?? "not_found",
42
+ message: messageOrInit,
43
+ status: init?.status ?? HttpStatus.NOT_FOUND
44
+ });
45
+ return problem({
46
+ ...messageOrInit,
47
+ code: messageOrInit?.code ?? "not_found",
48
+ message: messageOrInit?.message ?? "Not found",
49
+ status: messageOrInit?.status ?? HttpStatus.NOT_FOUND
50
+ });
51
+ }
52
+ //#endregion
53
+ //#region src/router/response/formats/problem/permissionDenied.ts
54
+ function permissionDenied(messageOrInit, init) {
55
+ if (typeof messageOrInit === "string") return problem({
56
+ ...init,
57
+ code: init?.code ?? "permission_denied",
58
+ message: messageOrInit,
59
+ status: init?.status ?? HttpStatus.FORBIDDEN
60
+ });
61
+ return problem({
62
+ ...messageOrInit,
63
+ code: messageOrInit?.code ?? "permission_denied",
64
+ message: messageOrInit?.message ?? "Permission denied",
65
+ status: messageOrInit?.status ?? HttpStatus.FORBIDDEN
66
+ });
67
+ }
68
+ //#endregion
69
+ //#region src/router/response/formats/problem/unauthenticated.ts
70
+ function unauthenticated(messageOrInit, init) {
71
+ if (typeof messageOrInit === "string") return problem({
72
+ ...init,
73
+ code: init?.code ?? "unauthenticated",
74
+ message: messageOrInit,
75
+ status: init?.status ?? HttpStatus.UNAUTHORIZED
76
+ });
77
+ return problem({
78
+ ...messageOrInit,
79
+ code: messageOrInit?.code ?? "unauthenticated",
80
+ message: messageOrInit?.message ?? "Unauthenticated",
81
+ status: messageOrInit?.status ?? HttpStatus.UNAUTHORIZED
82
+ });
83
+ }
84
+ //#endregion
85
+ //#region src/router/response/formats/problem/sessionExpired.ts
86
+ function sessionExpired(messageOrInit, init) {
87
+ if (typeof messageOrInit === "string") return problem({
88
+ ...init,
89
+ code: init?.code ?? "session_expired",
90
+ message: messageOrInit,
91
+ status: init?.status ?? HttpStatus.UNAUTHORIZED
92
+ });
93
+ return problem({
94
+ ...messageOrInit,
95
+ code: messageOrInit?.code ?? "session_expired",
96
+ message: messageOrInit?.message ?? "Session expired",
97
+ status: messageOrInit?.status ?? HttpStatus.UNAUTHORIZED
98
+ });
99
+ }
100
+ //#endregion
101
+ //#region src/router/response/formats/problem/badRequest.ts
102
+ function badRequest(messageOrInit, init) {
103
+ if (typeof messageOrInit === "string") return problem({
104
+ ...init,
105
+ code: init?.code ?? "bad_request",
106
+ message: messageOrInit,
107
+ status: init?.status ?? HttpStatus.BAD_REQUEST
108
+ });
109
+ return problem({
110
+ ...messageOrInit,
111
+ code: messageOrInit?.code ?? "bad_request",
112
+ message: messageOrInit?.message ?? "Bad request",
113
+ status: messageOrInit?.status ?? HttpStatus.BAD_REQUEST
114
+ });
115
+ }
116
+ //#endregion
117
+ //#region src/router/response/formats/problem/conflict.ts
118
+ function conflict(messageOrInit, init) {
119
+ if (typeof messageOrInit === "string") return problem({
120
+ ...init,
121
+ code: init?.code ?? "conflict",
122
+ message: messageOrInit,
123
+ status: init?.status ?? HttpStatus.CONFLICT
124
+ });
125
+ return problem({
126
+ ...messageOrInit,
127
+ code: messageOrInit?.code ?? "conflict",
128
+ message: messageOrInit?.message ?? "Conflict",
129
+ status: messageOrInit?.status ?? HttpStatus.CONFLICT
130
+ });
131
+ }
132
+ //#endregion
133
+ //#region src/router/response/formats/problem/rateLimited.ts
134
+ function rateLimited(messageOrInit, init) {
135
+ if (typeof messageOrInit === "string") return problem({
136
+ ...init,
137
+ code: init?.code ?? "rate_limited",
138
+ message: messageOrInit,
139
+ status: init?.status ?? HttpStatus.TOO_MANY_REQUESTS
140
+ });
141
+ return problem({
142
+ ...messageOrInit,
143
+ code: messageOrInit?.code ?? "rate_limited",
144
+ message: messageOrInit?.message ?? "Rate limited",
145
+ status: messageOrInit?.status ?? HttpStatus.TOO_MANY_REQUESTS
146
+ });
147
+ }
148
+ //#endregion
149
+ //#region src/router/response/formats/problem/root-errors.ts
150
+ /**
151
+ * Install standard problem-envelope handlers for router-level errors.
152
+ *
153
+ * @example
154
+ * ```ts
155
+ * const router = new Router().install(problemRootErrors())
156
+ * ```
157
+ *
158
+ * @returns Router extension that registers not-found, method, media-type, and internal-error handlers.
159
+ * @typeParam Ctx - Context carried by the router being configured.
160
+ */
161
+ function problemRootErrors() {
162
+ return (router) => {
163
+ router.onNotFound(() => problem({
164
+ code: "not_found",
165
+ message: "Not found",
166
+ status: HttpStatus.NOT_FOUND
167
+ })).onMethodNotAllowed(() => problem({
168
+ code: "method_not_allowed",
169
+ message: "Method not allowed",
170
+ status: HttpStatus.METHOD_NOT_ALLOWED
171
+ })).onUnsupportedMediaType(() => problem({
172
+ code: "unsupported_media_type",
173
+ message: "Unsupported media type",
174
+ status: HttpStatus.UNSUPPORTED_MEDIA_TYPE
175
+ })).onInternalError(() => problem({
176
+ code: "internal_server_error",
177
+ message: "Internal server error",
178
+ status: HttpStatus.INTERNAL_SERVER_ERROR
179
+ }));
180
+ };
181
+ }
182
+ //#endregion
183
+ export { VALIDATION_PROBLEM_CODE, badRequest, conflict, created, notFound, ok, permissionDenied, problem, problemRootErrors, rateLimited, sessionExpired, unauthenticated, validationProblem };
@@ -0,0 +1,45 @@
1
+ import { n as RoutekitResponse, r as RoutekitResponseInit } from "../core-CzUCxvGk.mjs";
2
+ import { HttpStatus } from "@mpen/http";
3
+
4
+ //#region src/router/response/formats/status/responses.d.ts
5
+ /**
6
+ * Create a `200 OK` logical response.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * return ok({payload: 'ready'})
11
+ * ```
12
+ *
13
+ * @param responseBody - Logical response body.
14
+ * @param init - Response headers.
15
+ * @returns Routekit logical response.
16
+ */
17
+ declare function ok<const T>(responseBody: T, init?: Omit<RoutekitResponseInit, 'status'>): RoutekitResponse<T, HttpStatus.OK>;
18
+ /**
19
+ * Create a `400 Bad Request` logical response.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * return badRequest({message: 'Invalid request'})
24
+ * ```
25
+ *
26
+ * @param responseBody - Logical response body.
27
+ * @param init - Response headers.
28
+ * @returns Routekit logical response.
29
+ */
30
+ declare function badRequest<const T>(responseBody: T, init?: Omit<RoutekitResponseInit, 'status'>): RoutekitResponse<T, HttpStatus.BAD_REQUEST>;
31
+ /**
32
+ * Create a `422 Unprocessable Content` logical response.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * return unprocessableContent({message: 'Email is already taken'})
37
+ * ```
38
+ *
39
+ * @param responseBody - Logical response body.
40
+ * @param init - Response headers.
41
+ * @returns Routekit logical response.
42
+ */
43
+ declare function unprocessableContent<const T>(responseBody: T, init?: Omit<RoutekitResponseInit, 'status'>): RoutekitResponse<T, HttpStatus.UNPROCESSABLE_ENTITY>;
44
+ //#endregion
45
+ export { badRequest, ok, unprocessableContent };
@@ -0,0 +1,2 @@
1
+ import { n as ok, r as unprocessableContent, t as badRequest } from "../status-C-8mw-FB.mjs";
2
+ export { badRequest, ok, unprocessableContent };