@sdk-it/hono 0.45.0 → 0.46.1
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 +95 -194
- package/dist/index.js.map +2 -2
- package/dist/lib/constant-value.d.ts.map +1 -1
- package/dist/lib/response-analyzer.d.ts.map +1 -1
- package/dist/lib/runtime/index.js.map +1 -1
- package/dist/lib/runtime/output.d.ts +26 -26
- package/dist/lib/runtime/validator.d.ts +1 -1
- package/dist/lib/runtime/validator.d.ts.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,134 +1,99 @@
|
|
|
1
1
|
# @sdk-it/hono
|
|
2
2
|
|
|
3
|
-
Hono
|
|
3
|
+
Hono runtime middleware and response analysis for SDK-IT.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
See [`@sdk-it/typescript`](../typescript/README.md) for OpenAPI-to-TypeScript
|
|
6
|
+
client generation.
|
|
6
7
|
|
|
7
8
|
## Installation
|
|
8
9
|
|
|
9
10
|
```bash
|
|
10
|
-
npm install @sdk-it/
|
|
11
|
+
npm install @sdk-it/hono hono zod
|
|
12
|
+
npm install --save-dev @sdk-it/generic @sdk-it/typescript typescript@^6.0.3
|
|
11
13
|
```
|
|
12
14
|
|
|
13
|
-
## Runtime
|
|
15
|
+
## Runtime primitives
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
The runtime exports work without generating an SDK.
|
|
16
18
|
|
|
17
|
-
###
|
|
19
|
+
### Validate requests
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
> [!IMPORTANT]
|
|
22
|
-
> For openapi generation to work correctly, you must use the `validate` middleware for each route.
|
|
23
|
-
|
|
24
|
-
> [!TIP]
|
|
25
|
-
> You can copy paste the middleware to your project if you want customize it further.
|
|
26
|
-
|
|
27
|
-
**Basic Usage:**
|
|
21
|
+
Every route included in OpenAPI generation must use `validate`. The middleware
|
|
22
|
+
validates the selected values and exposes the parsed result as `c.var.input`.
|
|
28
23
|
|
|
29
24
|
```typescript
|
|
25
|
+
import { Hono } from 'hono';
|
|
30
26
|
import { z } from 'zod';
|
|
31
27
|
|
|
32
28
|
import { validate } from '@sdk-it/hono/runtime';
|
|
33
29
|
|
|
30
|
+
const app = new Hono();
|
|
31
|
+
|
|
34
32
|
app.post(
|
|
35
|
-
'/books',
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
'/users/:userId/books',
|
|
34
|
+
validate('application/json', (payload) => ({
|
|
35
|
+
userId: {
|
|
36
|
+
select: payload.params.userId,
|
|
37
|
+
against: z.uuid(),
|
|
38
|
+
},
|
|
39
39
|
page: {
|
|
40
40
|
select: payload.query.page,
|
|
41
|
-
against: z.number().min(1).default(1),
|
|
41
|
+
against: z.coerce.number().int().min(1).default(1),
|
|
42
42
|
},
|
|
43
|
-
|
|
44
|
-
// Multiple query parameters (array)
|
|
45
43
|
categories: {
|
|
46
44
|
select: payload.queries.category,
|
|
47
45
|
against: z.array(z.string()),
|
|
48
46
|
},
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
apiKey: {
|
|
48
|
+
select: payload.headers['x-api-key'],
|
|
49
|
+
against: z.string().min(32),
|
|
50
|
+
},
|
|
51
51
|
title: {
|
|
52
52
|
select: payload.body.title,
|
|
53
53
|
against: z.string().min(1),
|
|
54
54
|
},
|
|
55
|
-
|
|
56
|
-
author: {
|
|
57
|
-
select: payload.body.author,
|
|
58
|
-
against: z.string().min(1),
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
// For nested objects in body
|
|
62
55
|
metadata: {
|
|
63
56
|
select: payload.body.metadata,
|
|
64
57
|
against: z.object({
|
|
65
58
|
isbn: z.string(),
|
|
66
|
-
publishedYear: z.number(),
|
|
59
|
+
publishedYear: z.number().int(),
|
|
67
60
|
}),
|
|
68
61
|
},
|
|
69
|
-
|
|
70
|
-
// URL parameter validation
|
|
71
|
-
userId: {
|
|
72
|
-
select: payload.params.userId,
|
|
73
|
-
against: z.uuid(),
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
// Header validation
|
|
77
|
-
apiKey: {
|
|
78
|
-
select: payload.headers['x-api-key'],
|
|
79
|
-
against: z.string().min(32),
|
|
80
|
-
},
|
|
81
62
|
})),
|
|
82
63
|
(c) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
c.var.input;
|
|
86
|
-
return c.json({ success: true });
|
|
64
|
+
const { userId, page, categories, apiKey, title, metadata } = c.var.input;
|
|
65
|
+
return c.json({ userId, page, categories, apiKey, title, metadata }, 201);
|
|
87
66
|
},
|
|
88
67
|
);
|
|
89
68
|
```
|
|
90
69
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
Pass a content type as the first argument to enforce it before validation:
|
|
70
|
+
The optional first argument enforces the request content type before
|
|
71
|
+
validation:
|
|
94
72
|
|
|
95
73
|
```typescript
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
app.post(
|
|
101
|
-
'/users',
|
|
102
|
-
validate('application/json', (payload) => ({
|
|
103
|
-
// <-- Enforces 'application/json'
|
|
104
|
-
name: {
|
|
105
|
-
select: payload.body.name,
|
|
106
|
-
against: z.string(),
|
|
107
|
-
},
|
|
108
|
-
})),
|
|
109
|
-
(c) => {
|
|
110
|
-
// Handle request with guaranteed JSON content
|
|
111
|
-
const { name } = c.var.input;
|
|
112
|
-
return c.json({ success: true });
|
|
74
|
+
validate('application/json', (payload) => ({
|
|
75
|
+
name: {
|
|
76
|
+
select: payload.body.name,
|
|
77
|
+
against: z.string(),
|
|
113
78
|
},
|
|
114
|
-
);
|
|
79
|
+
}));
|
|
115
80
|
```
|
|
116
81
|
|
|
117
|
-
|
|
82
|
+
Supported enforced content types are:
|
|
118
83
|
|
|
119
|
-
|
|
84
|
+
- `application/json`
|
|
85
|
+
- `application/x-www-form-urlencoded`
|
|
86
|
+
- `multipart/form-data`
|
|
87
|
+
- `text/plain`
|
|
120
88
|
|
|
121
|
-
|
|
122
|
-
|
|
89
|
+
Query and path values arrive as strings. Use Zod coercion when the parsed value
|
|
90
|
+
should be a number, boolean, or another non-string type.
|
|
123
91
|
|
|
124
|
-
|
|
92
|
+
### Validate file uploads
|
|
125
93
|
|
|
126
|
-
|
|
94
|
+
Use `z.instanceof(File)` with `multipart/form-data`:
|
|
127
95
|
|
|
128
|
-
|
|
129
|
-
* @openapi uploadProfilePicture
|
|
130
|
-
* @tags users
|
|
131
|
-
*/
|
|
96
|
+
```typescript
|
|
132
97
|
app.post(
|
|
133
98
|
'/users/:userId/avatar',
|
|
134
99
|
validate('multipart/form-data', (payload) => ({
|
|
@@ -136,104 +101,71 @@ app.post(
|
|
|
136
101
|
select: payload.params.userId,
|
|
137
102
|
against: z.uuid(),
|
|
138
103
|
},
|
|
139
|
-
// File validation
|
|
140
104
|
avatar: {
|
|
141
|
-
select: payload.body.avatar,
|
|
142
|
-
against: z.instanceof(File),
|
|
105
|
+
select: payload.body.avatar,
|
|
106
|
+
against: z.instanceof(File),
|
|
143
107
|
},
|
|
144
|
-
// Other form fields can also be validated
|
|
145
108
|
caption: {
|
|
146
109
|
select: payload.body.caption,
|
|
147
|
-
against: z.string().optional(),
|
|
110
|
+
against: z.string().optional(),
|
|
148
111
|
},
|
|
149
112
|
})),
|
|
150
|
-
|
|
113
|
+
(c) => {
|
|
151
114
|
const { userId, avatar, caption } = c.var.input;
|
|
152
|
-
|
|
153
|
-
// Example: Process the uploaded file
|
|
154
|
-
// const fileBuffer = Buffer.from(await avatar.arrayBuffer());
|
|
155
|
-
// await writeFile(`./uploads/${userId}_${avatar.name}`, fileBuffer);
|
|
156
|
-
|
|
157
|
-
console.log(
|
|
158
|
-
`Received avatar for user ${userId}: ${avatar.name}, size: ${avatar.size}`,
|
|
159
|
-
);
|
|
160
|
-
if (caption) {
|
|
161
|
-
console.log(`Caption: ${caption}`);
|
|
162
|
-
}
|
|
163
115
|
return c.json({
|
|
164
|
-
|
|
116
|
+
userId,
|
|
117
|
+
filename: avatar.name,
|
|
118
|
+
size: avatar.size,
|
|
119
|
+
caption,
|
|
165
120
|
});
|
|
166
121
|
},
|
|
167
122
|
);
|
|
168
123
|
```
|
|
169
124
|
|
|
170
|
-
###
|
|
125
|
+
### Enforce a content type without validation
|
|
171
126
|
|
|
172
|
-
|
|
127
|
+
Use `consume` when a route only needs content-type enforcement:
|
|
173
128
|
|
|
174
129
|
```typescript
|
|
175
130
|
import { consume } from '@sdk-it/hono/runtime';
|
|
176
131
|
|
|
177
|
-
app.post(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const body = await c.req.parseBody();
|
|
183
|
-
const file = body['file']; // Access file data
|
|
184
|
-
// ... process file ...
|
|
185
|
-
return c.json({ success: true });
|
|
186
|
-
},
|
|
187
|
-
);
|
|
132
|
+
app.post('/upload', consume('multipart/form-data'), async (c) => {
|
|
133
|
+
const body = await c.req.parseBody();
|
|
134
|
+
const file = body.file;
|
|
135
|
+
return c.json({ uploaded: file instanceof File });
|
|
136
|
+
});
|
|
188
137
|
```
|
|
189
138
|
|
|
190
|
-
###
|
|
191
|
-
|
|
192
|
-
The output function sends HTTP responses with typed status codes and content types.
|
|
193
|
-
|
|
194
|
-
The `output` utility builds on hono's `context.body`.
|
|
139
|
+
### Send semantic responses
|
|
195
140
|
|
|
196
|
-
|
|
197
|
-
> You don't necessarily need to use this function for OpenAPI generation, but it provides a clean and consistent way to send responses.
|
|
141
|
+
`createOutput` wraps Hono's response methods:
|
|
198
142
|
|
|
199
143
|
```typescript
|
|
200
144
|
import { createOutput } from '@sdk-it/hono/runtime';
|
|
201
145
|
|
|
202
146
|
app.post('/users', (c) => {
|
|
203
147
|
const output = createOutput(() => c);
|
|
204
|
-
|
|
205
|
-
// Success responses
|
|
206
|
-
return output.ok({ data: 'success' });
|
|
207
|
-
return output.accepted({ status: 'processing' });
|
|
208
|
-
|
|
209
|
-
// Error responses
|
|
210
|
-
return output.badRequest({ error: 'Invalid input' });
|
|
211
|
-
return output.unauthorized({ error: 'Not authenticated' });
|
|
212
|
-
return output.forbidden({ error: 'Not authorized' });
|
|
213
|
-
return output.notImplemented({ error: 'Coming soon' });
|
|
214
|
-
|
|
215
|
-
// Redirects
|
|
216
|
-
return output.redirect('/new-location');
|
|
217
|
-
|
|
218
|
-
// Custom headers
|
|
219
|
-
return output.ok({ data: 'success' }, { 'Cache-Control': 'max-age=3600' });
|
|
148
|
+
return output.created('/users/123', { id: '123' });
|
|
220
149
|
});
|
|
221
150
|
```
|
|
222
151
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
152
|
+
The helper provides methods for common success and error statuses, redirects,
|
|
153
|
+
attachments, and custom headers. It is a runtime utility; use Hono response
|
|
154
|
+
methods such as `c.json` on analyzed routes so `responseAnalyzer` can infer
|
|
155
|
+
their response bodies and status codes.
|
|
226
156
|
|
|
227
|
-
|
|
157
|
+
## Generate OpenAPI and a client
|
|
228
158
|
|
|
229
|
-
|
|
159
|
+
Create an analyzed route:
|
|
230
160
|
|
|
231
161
|
```typescript
|
|
162
|
+
// src/app.ts
|
|
163
|
+
import { Hono } from 'hono';
|
|
232
164
|
import { z } from 'zod';
|
|
233
165
|
|
|
234
166
|
import { validate } from '@sdk-it/hono/runtime';
|
|
235
167
|
|
|
236
|
-
const app = new Hono();
|
|
168
|
+
export const app = new Hono();
|
|
237
169
|
|
|
238
170
|
/**
|
|
239
171
|
* @openapi listBooks
|
|
@@ -247,90 +179,59 @@ app.get(
|
|
|
247
179
|
against: z.string(),
|
|
248
180
|
},
|
|
249
181
|
})),
|
|
250
|
-
|
|
251
|
-
const { author } = c.var.input;
|
|
252
|
-
|
|
253
|
-
return c.json(books);
|
|
182
|
+
(c) => {
|
|
183
|
+
const { author } = c.var.input;
|
|
184
|
+
return c.json([{ title: 'Example', author }]);
|
|
254
185
|
},
|
|
255
186
|
);
|
|
256
187
|
```
|
|
257
188
|
|
|
258
|
-
|
|
259
|
-
> Instead of using `createOutput` fn, you can use [context-storage](https://hono.dev/docs/middleware/builtin/context-storage) middleware and then import the global `output` object from `@sdk-it/hono/runtime`.
|
|
260
|
-
|
|
261
|
-
- Use the generate fn to create an OpenAPI spec from your routes.
|
|
262
|
-
|
|
263
|
-
<b><small>filename: openapi.ts</small></b>
|
|
189
|
+
Analyze the backend and generate the client:
|
|
264
190
|
|
|
265
191
|
```typescript
|
|
192
|
+
// openapi.ts
|
|
266
193
|
import { writeFile } from 'node:fs/promises';
|
|
267
|
-
import {
|
|
194
|
+
import { resolve } from 'node:path';
|
|
268
195
|
|
|
269
196
|
import { analyze } from '@sdk-it/generic';
|
|
270
|
-
// Use responseAnalyzer from `@sdk-it/hono`
|
|
271
|
-
// only if you use hono context object to send response
|
|
272
|
-
// e.g. c.json({ data: 'success' });
|
|
273
197
|
import { responseAnalyzer } from '@sdk-it/hono';
|
|
274
|
-
// Use responseAnalyzer from `@sdk-it/generic`
|
|
275
|
-
// only if you use the output function to send response
|
|
276
|
-
// e.g. output.ok({ data: 'success' });
|
|
277
|
-
// import { responseAnalyzer } from '@sdk-it/generic';
|
|
278
|
-
|
|
279
198
|
import { generate } from '@sdk-it/typescript';
|
|
280
199
|
|
|
281
|
-
const { paths, components } = await analyze(
|
|
282
|
-
|
|
283
|
-
|
|
200
|
+
const { paths, components, tags } = await analyze(
|
|
201
|
+
'./apps/backend/tsconfig.app.json',
|
|
202
|
+
{
|
|
203
|
+
responseAnalyzer,
|
|
204
|
+
},
|
|
205
|
+
);
|
|
284
206
|
|
|
285
|
-
// Now you can use the generated specification to create an SDK or save it to a file
|
|
286
207
|
const spec = {
|
|
208
|
+
openapi: '3.1.0' as const,
|
|
287
209
|
info: {
|
|
288
210
|
title: 'My API',
|
|
289
211
|
version: '1.0.0',
|
|
290
212
|
},
|
|
291
213
|
paths,
|
|
292
214
|
components,
|
|
215
|
+
tags: tags.map((name) => ({ name })),
|
|
293
216
|
};
|
|
294
217
|
|
|
295
|
-
// Save the spec to a file
|
|
296
218
|
await writeFile('openapi.json', JSON.stringify(spec, null, 2));
|
|
297
|
-
// OR
|
|
298
|
-
|
|
299
|
-
// Continue to generate an SDK
|
|
300
219
|
await generate(spec, {
|
|
301
|
-
output:
|
|
220
|
+
output: resolve('client'),
|
|
221
|
+
name: 'Client',
|
|
302
222
|
});
|
|
303
223
|
```
|
|
304
224
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
```bash
|
|
308
|
-
# using recent versions of node
|
|
309
|
-
node ./openapi.ts
|
|
310
|
-
|
|
311
|
-
# using node < 22
|
|
312
|
-
npx tsx ./openapi.ts
|
|
313
|
-
|
|
314
|
-
# using bun
|
|
315
|
-
bun ./openapi.ts
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
<details>
|
|
319
|
-
<summary> Run in watch mode </summary>
|
|
225
|
+
Run the script with Node.js 24 or newer:
|
|
320
226
|
|
|
321
227
|
```bash
|
|
322
|
-
node
|
|
228
|
+
node openapi.ts
|
|
323
229
|
```
|
|
324
230
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
> [!TIP]
|
|
328
|
-
> See [the typescript package](../typescript/README.md) for more info.
|
|
329
|
-
|
|
330
|
-
- Use the client
|
|
231
|
+
The generated client returns response data and throws typed errors:
|
|
331
232
|
|
|
332
233
|
```typescript
|
|
333
|
-
import { Client,
|
|
234
|
+
import { Client, Unauthorized } from './client/index.ts';
|
|
334
235
|
|
|
335
236
|
const client = new Client({
|
|
336
237
|
baseUrl: 'http://localhost:3000',
|
|
@@ -340,12 +241,12 @@ try {
|
|
|
340
241
|
const books = await client.request('GET /books', {
|
|
341
242
|
author: 'John Doe',
|
|
342
243
|
});
|
|
343
|
-
console.log(
|
|
244
|
+
console.log(books);
|
|
344
245
|
} catch (error) {
|
|
345
|
-
if (error instanceof
|
|
346
|
-
console.error('
|
|
246
|
+
if (error instanceof Unauthorized) {
|
|
247
|
+
console.error('Authentication is required', error.data);
|
|
347
248
|
} else {
|
|
348
|
-
|
|
249
|
+
throw error;
|
|
349
250
|
}
|
|
350
251
|
}
|
|
351
252
|
```
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/lib/response-analyzer.ts", "../src/lib/constant-value.ts"],
|
|
4
|
-
"sourcesContent": ["import ts from 'typescript';\n\nimport {\n $types,\n type NaunceResponseAnalyzerFn,\n type ResponseItem,\n type TypeDeriver,\n} from '@sdk-it/core';\nimport { getConstantValue } from './constant-value.js';\n\nconst handlerVisitor: (\n on: (\n node: ts.Node | undefined,\n statusCode: ts.Node | undefined,\n headers: ts.Node | undefined,\n contentType: string,\n ) => void,\n contextVarName: string,\n) => ts.Visitor = (callback, contextVarName) => {\n return (node: ts.Node) => {\n if (ts.isReturnStatement(node) && node.expression) {\n if (ts.isCallExpression(node.expression)) {\n if (ts.isPropertyAccessExpression(node.expression.expression)) {\n const propAccess = node.expression.expression;\n if (\n ts.isIdentifier(propAccess.expression) &&\n propAccess.expression.text === contextVarName\n ) {\n const [body, statusCode, headers] = node.expression.arguments;\n let contentType = 'application/json';\n const callerMethod = propAccess.name.text;\n if (callerMethod === 'body') {\n contentType = 'application/octet-stream';\n }\n if (!body) {\n contentType = 'empty';\n }\n callback(body, statusCode, headers, contentType);\n }\n }\n // if (ts.isIdentifier(node.expression.expression)) {\n // console.log('streamText');\n // if (node.expression.expression.text === 'streamText') {\n // callback(undefined, undefined, undefined, 'text/plain');\n // }\n // }\n }\n }\n return ts.forEachChild(node, handlerVisitor(callback, contextVarName));\n };\n};\n\nfunction resolveStatusCode(node: ts.Node) {\n if (ts.isNumericLiteral(node)) {\n return node.text;\n }\n throw new Error(`Could not resolve status code`);\n}\n\nfunction normalizeContentType(value: string | undefined) {\n if (!value) {\n return undefined;\n }\n return value.split(';')[0]?.trim();\n}\n\nfunction getPropertyNameText(\n name: ts.PropertyName,\n checker: ts.TypeChecker,\n): string | undefined {\n if (ts.isIdentifier(name)) {\n return name.text;\n }\n if (ts.isStringLiteral(name) || ts.isNumericLiteral(name)) {\n return name.text;\n }\n if (ts.isComputedPropertyName(name)) {\n const expression = name.expression;\n if (ts.isStringLiteral(expression) || ts.isNumericLiteral(expression)) {\n return expression.text;\n }\n const value = getConstantValue(checker, expression);\n if (typeof value === 'string' || typeof value === 'number') {\n return String(value);\n }\n }\n return undefined;\n}\n\nfunction resolveHeadersObject(\n headersNode: ts.Node | undefined,\n checker: ts.TypeChecker,\n): ts.ObjectLiteralExpression | undefined {\n if (!headersNode) {\n return undefined;\n }\n const unwrapObjectLiteral = (\n expression: ts.Expression,\n ): ts.ObjectLiteralExpression | undefined => {\n if (ts.isObjectLiteralExpression(expression)) {\n return expression;\n }\n if (\n ts.isParenthesizedExpression(expression) &&\n ts.isObjectLiteralExpression(expression.expression)\n ) {\n return expression.expression;\n }\n return undefined;\n };\n if (ts.isObjectLiteralExpression(headersNode)) {\n return headersNode;\n }\n if (ts.isAsExpression(headersNode)) {\n return resolveHeadersObject(headersNode.expression, checker);\n }\n if (ts.isTypeAssertionExpression(headersNode)) {\n return resolveHeadersObject(headersNode.expression, checker);\n }\n if (ts.isParenthesizedExpression(headersNode)) {\n return resolveHeadersObject(headersNode.expression, checker);\n }\n if (ts.isNewExpression(headersNode)) {\n const exprName = headersNode.expression.getText();\n if (exprName === 'Headers') {\n const [init] = headersNode.arguments ?? [];\n return init ? resolveHeadersObject(init, checker) : undefined;\n }\n }\n if (ts.isCallExpression(headersNode)) {\n let callee: ts.Expression = headersNode.expression;\n if (ts.isParenthesizedExpression(callee)) {\n callee = callee.expression;\n }\n if (ts.isArrowFunction(callee) || ts.isFunctionExpression(callee)) {\n if (ts.isExpression(callee.body)) {\n const bodyLiteral = unwrapObjectLiteral(callee.body);\n if (bodyLiteral) {\n return bodyLiteral;\n }\n }\n if (ts.isBlock(callee.body)) {\n for (const statement of callee.body.statements) {\n if (\n ts.isReturnStatement(statement) &&\n statement.expression &&\n unwrapObjectLiteral(statement.expression)\n ) {\n return unwrapObjectLiteral(statement.expression);\n }\n }\n }\n }\n }\n if (ts.isShorthandPropertyAssignment(headersNode)) {\n const symbol = checker.getShorthandAssignmentValueSymbol(headersNode);\n const decl = symbol?.valueDeclaration ?? symbol?.declarations?.[0];\n if (decl && ts.isVariableDeclaration(decl) && decl.initializer) {\n return resolveHeadersObject(decl.initializer, checker);\n }\n }\n if (ts.isIdentifier(headersNode)) {\n const symbol = checker.getSymbolAtLocation(headersNode);\n const decl = symbol?.valueDeclaration ?? symbol?.declarations?.[0];\n if (decl && ts.isVariableDeclaration(decl) && decl.initializer) {\n return resolveHeadersObject(decl.initializer, checker);\n }\n }\n return undefined;\n}\n\nfunction getHeaderValue(\n headersNode: ts.Node | undefined,\n headerName: string,\n checker: ts.TypeChecker,\n) {\n const headersObject = resolveHeadersObject(headersNode, checker);\n if (!headersObject) {\n return undefined;\n }\n for (const prop of headersObject.properties) {\n if (!ts.isPropertyAssignment(prop)) {\n continue;\n }\n const key = getPropertyNameText(prop.name, checker);\n if (!key || key.toLowerCase() !== headerName.toLowerCase()) {\n continue;\n }\n const value = getConstantValue(checker, prop.initializer);\n return typeof value === 'string' ? value : undefined;\n }\n return undefined;\n}\n\nfunction hasHeaderKey(\n headersNode: ts.Node | undefined,\n headerName: string,\n checker: ts.TypeChecker,\n) {\n const headersObject = resolveHeadersObject(headersNode, checker);\n if (!headersObject) {\n return false;\n }\n for (const prop of headersObject.properties) {\n if (!ts.isPropertyAssignment(prop)) {\n continue;\n }\n const key = getPropertyNameText(prop.name, checker);\n if (key && key.toLowerCase() === headerName.toLowerCase()) {\n return true;\n }\n }\n return false;\n}\n\nfunction isJsonContentType(contentType: string) {\n return contentType.endsWith('/json') || contentType.endsWith('+json');\n}\n\nfunction isTextContentTypeValue(contentType: string) {\n return contentType.startsWith('text/');\n}\n\nfunction inferContentType(\n body: ts.Node | undefined,\n headers: ts.Node | undefined,\n defaultContentType: string,\n checker: ts.TypeChecker,\n) {\n if (!body) {\n return 'empty';\n }\n const headerContentType = normalizeContentType(\n getHeaderValue(headers, 'Content-Type', checker),\n );\n if (headerContentType) {\n return headerContentType;\n }\n if (hasHeaderKey(headers, 'Content-Disposition', checker)) {\n return 'application/octet-stream';\n }\n return defaultContentType;\n}\n\nfunction getHeaderKeys(headersNode: ts.Node | undefined, deriver: TypeDeriver) {\n if (!headersNode) {\n return [];\n }\n const resolved = resolveHeadersObject(headersNode, deriver.checker);\n if (resolved) {\n return Object.keys(deriver.serializeNode(resolved));\n }\n const type = deriver.checker.getTypeAtLocation(headersNode);\n const names = deriver.checker\n .getPropertiesOfType(type)\n .map((prop) => prop.name);\n if (!names.length) {\n return [];\n }\n const sorted = [...names].sort((a, b) => a.localeCompare(b));\n return sorted.flatMap((name) =>\n name.includes('-') ? [`'${name}'`, name] : [name],\n );\n}\n\nexport const newResponse: NaunceResponseAnalyzerFn = (\n _handler,\n deriver,\n node,\n) => {\n if (!ts.isNewExpression(node)) {\n return [];\n }\n const exprName = node.expression.getText();\n if (exprName !== 'Response') {\n return [];\n }\n const [body, init] = node.arguments ?? [];\n let statusNode: ts.Node | undefined;\n let headersNode: ts.Node | undefined;\n if (init && ts.isObjectLiteralExpression(init)) {\n for (const prop of init.properties) {\n if (!ts.isPropertyAssignment(prop)) {\n if (ts.isShorthandPropertyAssignment(prop)) {\n const key = prop.name.text;\n if (key === 'headers') {\n headersNode = prop;\n }\n }\n continue;\n }\n const key = getPropertyNameText(prop.name, deriver.checker);\n if (!key) {\n continue;\n }\n if (key === 'status') {\n statusNode = prop.initializer;\n } else if (key === 'headers') {\n headersNode = prop.initializer;\n }\n }\n }\n\n const contentType = inferContentType(\n body,\n headersNode,\n 'application/octet-stream',\n deriver.checker,\n );\n\n const normalized = contentType.toLowerCase();\n const shouldSerialize =\n !!body &&\n (isJsonContentType(normalized) || isTextContentTypeValue(normalized));\n\n return [\n {\n headers: getHeaderKeys(headersNode, deriver),\n contentType,\n statusCode: statusNode ? resolveStatusCode(statusNode) : '200',\n response: shouldSerialize ? deriver.serializeNode(body) : undefined,\n },\n ];\n};\n\nexport function defaultResponseAnalyzer(\n handler: ts.ArrowFunction | ts.FunctionExpression,\n deriver: TypeDeriver,\n) {\n const responsesList: ResponseItem[] = [];\n if (!handler.parameters.length) {\n return responsesList;\n }\n const contextVarName = handler.parameters[0].name.getText();\n const visit = handlerVisitor((node, statusCode, headers, contentType) => {\n const resolvedContentType = inferContentType(\n node,\n headers,\n contentType,\n deriver.checker,\n );\n responsesList.push({\n headers: getHeaderKeys(headers, deriver),\n contentType: resolvedContentType,\n statusCode: statusCode ? resolveStatusCode(statusCode) : '200',\n response: node ? deriver.serializeNode(node) : undefined,\n });\n }, contextVarName);\n visit(handler.body);\n return responsesList;\n}\n\nexport function streamText(\n _handler: ts.ArrowFunction | ts.FunctionExpression,\n _deriver: TypeDeriver,\n): ResponseItem[] {\n return [\n {\n contentType: 'text/plain',\n headers: [{ 'Transfer-Encoding': ['chunked'] }],\n statusCode: '200',\n response: {\n optional: false,\n kind: 'primitive',\n [$types]: ['string'],\n },\n },\n ];\n}\n\nexport function stream(\n _handler: ts.ArrowFunction | ts.FunctionExpression,\n _deriver: TypeDeriver,\n): ResponseItem[] {\n return [\n {\n contentType: 'application/octet-stream',\n headers: [],\n statusCode: '200',\n response: {\n optional: false,\n kind: 'primitive',\n [$types]: ['string'],\n },\n },\n ];\n}\n\nexport function streamSSE(\n _handler: ts.ArrowFunction | ts.FunctionExpression,\n _deriver: TypeDeriver,\n): ResponseItem[] {\n return [\n {\n contentType: 'text/event-stream',\n headers: [],\n statusCode: '200',\n response: {\n optional: false,\n kind: 'primitive',\n [$types]: ['string'],\n },\n },\n ];\n}\n\nexport const httpException: NaunceResponseAnalyzerFn = (\n _handler,\n deriver,\n node,\n) => {\n if (ts.isNewExpression(node)) {\n const [status, options] = node.arguments ?? [];\n // if (!ts.isObjectLiteralExpression(options)) {\n // return [];\n // }\n // const properties = options.properties.reduce<Record<string, string>>(\n // (acc, prop) => {\n // if (ts.isPropertyAssignment(prop)) {\n // const key = prop.name.getText();\n // if (ts.isLiteralExpression(prop.initializer)) {\n // acc[key] = prop.initializer.text;\n // } else {\n // acc[key] = prop.initializer.getText();\n // }\n // }\n // return acc;\n // },\n // {},\n // );\n return [\n {\n contentType: 'application/json',\n headers: [],\n statusCode: resolveStatusCode(status),\n response: options ? deriver.serializeNode(options) : undefined,\n },\n ];\n }\n return [];\n};\n\nexport const responseAnalyzer = {\n default: defaultResponseAnalyzer,\n streamText,\n stream,\n streamSSE,\n 'new.Response': newResponse,\n 'throw.new.HTTPException': httpException,\n};\n\nexport default responseAnalyzer;\n", "import ts from 'typescript';\n\nfunction unwrapExpression(node: ts.Expression): ts.Expression {\n let current = node;\n while (true) {\n if (ts.isAsExpression(current)) {\n current = current.expression;\n continue;\n }\n if (ts.isTypeAssertionExpression(current)) {\n current = current.expression;\n continue;\n }\n if (ts.isParenthesizedExpression(current)) {\n current = current.expression;\n continue;\n }\n return current;\n }\n}\n\nfunction literalValueFromType(\n type: ts.Type,\n checker: ts.TypeChecker,\n): string | number | boolean | undefined {\n if (type.isStringLiteral()) {\n return type.value;\n }\n if (type.isNumberLiteral()) {\n return type.value;\n }\n if (type.flags & ts.TypeFlags.BooleanLiteral) {\n return checker.typeToString(type) === 'true';\n }\n return undefined;\n}\n\nexport function getConstantValue(\n checker: ts.TypeChecker,\n expression: ts.Expression,\n): string | number | boolean | undefined {\n const unwrapped = unwrapExpression(expression);\n\n const constant = checker.getConstantValue(\n unwrapped as\n | ts.EnumMember\n | ts.PropertyAccessExpression\n | ts.ElementAccessExpression,\n );\n if (constant !== undefined) {\n return constant;\n }\n\n if (\n ts.isStringLiteral(unwrapped) ||\n ts.isNoSubstitutionTemplateLiteral(unwrapped)\n ) {\n return unwrapped.text;\n }\n if (ts.isNumericLiteral(unwrapped)) {\n return Number(unwrapped.text);\n }\n if (unwrapped.kind === ts.SyntaxKind.TrueKeyword) {\n return true;\n }\n if (unwrapped.kind === ts.SyntaxKind.FalseKeyword) {\n return false;\n }\n\n const type = checker.getTypeAtLocation(unwrapped);\n const literal = literalValueFromType(type, checker);\n if (literal !== undefined) {\n return literal;\n }\n if (type.isUnion()) {\n let resolved: string | number | boolean | undefined = undefined;\n for (const entry of type.types) {\n const value = literalValueFromType(entry, checker);\n if (value === undefined) {\n return undefined;\n }\n if (resolved === undefined) {\n resolved = value;\n } else if (resolved !== value) {\n return undefined;\n }\n }\n return resolved;\n }\n return undefined;\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,OAAOA,SAAQ;AAEf;AAAA,EACE;AAAA,OAIK;;;ACPP,OAAO,QAAQ;AAEf,SAAS,iBAAiB,MAAoC;AAC5D,MAAI,UAAU;AACd,SAAO,MAAM;AACX,QAAI,GAAG,eAAe,OAAO,GAAG;AAC9B,gBAAU,QAAQ;AAClB;AAAA,IACF;AACA,QAAI,GAAG,0BAA0B,OAAO,GAAG;AACzC,gBAAU,QAAQ;AAClB;AAAA,IACF;AACA,QAAI,GAAG,0BAA0B,OAAO,GAAG;AACzC,gBAAU,QAAQ;AAClB;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;AAEA,SAAS,qBACP,MACA,SACuC;AACvC,MAAI,KAAK,gBAAgB,GAAG;AAC1B,WAAO,KAAK;AAAA,EACd;AACA,MAAI,KAAK,gBAAgB,GAAG;AAC1B,WAAO,KAAK;AAAA,EACd;AACA,MAAI,KAAK,QAAQ,GAAG,UAAU,gBAAgB;AAC5C,WAAO,QAAQ,aAAa,IAAI,MAAM;AAAA,EACxC;AACA,SAAO;AACT;AAEO,SAAS,iBACd,SACA,YACuC;AACvC,QAAM,YAAY,iBAAiB,UAAU;AAE7C,QAAM,WAAW,QAAQ;AAAA,IACvB;AAAA,
|
|
4
|
+
"sourcesContent": ["import ts from 'typescript';\n\nimport {\n $types,\n type NaunceResponseAnalyzerFn,\n type ResponseItem,\n type TypeDeriver,\n} from '@sdk-it/core';\n\nimport { getConstantValue } from './constant-value.js';\n\nconst handlerVisitor: (\n on: (\n node: ts.Node | undefined,\n statusCode: ts.Node | undefined,\n headers: ts.Node | undefined,\n contentType: string,\n ) => void,\n contextVarName: string,\n) => ts.Visitor = (callback, contextVarName) => {\n return (node: ts.Node) => {\n if (ts.isReturnStatement(node) && node.expression) {\n if (ts.isCallExpression(node.expression)) {\n if (ts.isPropertyAccessExpression(node.expression.expression)) {\n const propAccess = node.expression.expression;\n if (\n ts.isIdentifier(propAccess.expression) &&\n propAccess.expression.text === contextVarName\n ) {\n const [body, statusCode, headers] = node.expression.arguments;\n let contentType = 'application/json';\n const callerMethod = propAccess.name.text;\n if (callerMethod === 'body') {\n contentType = 'application/octet-stream';\n }\n if (!body) {\n contentType = 'empty';\n }\n callback(body, statusCode, headers, contentType);\n }\n }\n // if (ts.isIdentifier(node.expression.expression)) {\n // console.log('streamText');\n // if (node.expression.expression.text === 'streamText') {\n // callback(undefined, undefined, undefined, 'text/plain');\n // }\n // }\n }\n }\n return ts.forEachChild(node, handlerVisitor(callback, contextVarName));\n };\n};\n\nfunction resolveStatusCode(node: ts.Node) {\n if (ts.isNumericLiteral(node)) {\n return node.text;\n }\n throw new Error(`Could not resolve status code`);\n}\n\nfunction normalizeContentType(value: string | undefined) {\n if (!value) {\n return undefined;\n }\n return value.split(';')[0]?.trim();\n}\n\nfunction getPropertyNameText(\n name: ts.PropertyName,\n checker: ts.TypeChecker,\n): string | undefined {\n if (ts.isIdentifier(name)) {\n return name.text;\n }\n if (ts.isStringLiteral(name) || ts.isNumericLiteral(name)) {\n return name.text;\n }\n if (ts.isComputedPropertyName(name)) {\n const expression = name.expression;\n if (ts.isStringLiteral(expression) || ts.isNumericLiteral(expression)) {\n return expression.text;\n }\n const value = getConstantValue(checker, expression);\n if (typeof value === 'string' || typeof value === 'number') {\n return String(value);\n }\n }\n return undefined;\n}\n\nfunction resolveHeadersObject(\n headersNode: ts.Node | undefined,\n checker: ts.TypeChecker,\n): ts.ObjectLiteralExpression | undefined {\n if (!headersNode) {\n return undefined;\n }\n const unwrapObjectLiteral = (\n expression: ts.Expression,\n ): ts.ObjectLiteralExpression | undefined => {\n if (ts.isObjectLiteralExpression(expression)) {\n return expression;\n }\n if (\n ts.isParenthesizedExpression(expression) &&\n ts.isObjectLiteralExpression(expression.expression)\n ) {\n return expression.expression;\n }\n return undefined;\n };\n if (ts.isObjectLiteralExpression(headersNode)) {\n return headersNode;\n }\n if (ts.isAsExpression(headersNode)) {\n return resolveHeadersObject(headersNode.expression, checker);\n }\n if (ts.isTypeAssertionExpression(headersNode)) {\n return resolveHeadersObject(headersNode.expression, checker);\n }\n if (ts.isParenthesizedExpression(headersNode)) {\n return resolveHeadersObject(headersNode.expression, checker);\n }\n if (ts.isNewExpression(headersNode)) {\n const exprName = headersNode.expression.getText();\n if (exprName === 'Headers') {\n const [init] = headersNode.arguments ?? [];\n return init ? resolveHeadersObject(init, checker) : undefined;\n }\n }\n if (ts.isCallExpression(headersNode)) {\n let callee: ts.Expression = headersNode.expression;\n if (ts.isParenthesizedExpression(callee)) {\n callee = callee.expression;\n }\n if (ts.isArrowFunction(callee) || ts.isFunctionExpression(callee)) {\n if (ts.isExpression(callee.body)) {\n const bodyLiteral = unwrapObjectLiteral(callee.body);\n if (bodyLiteral) {\n return bodyLiteral;\n }\n }\n if (ts.isBlock(callee.body)) {\n for (const statement of callee.body.statements) {\n if (\n ts.isReturnStatement(statement) &&\n statement.expression &&\n unwrapObjectLiteral(statement.expression)\n ) {\n return unwrapObjectLiteral(statement.expression);\n }\n }\n }\n }\n }\n if (ts.isShorthandPropertyAssignment(headersNode)) {\n const symbol = checker.getShorthandAssignmentValueSymbol(headersNode);\n const decl = symbol?.valueDeclaration ?? symbol?.declarations?.[0];\n if (decl && ts.isVariableDeclaration(decl) && decl.initializer) {\n return resolveHeadersObject(decl.initializer, checker);\n }\n }\n if (ts.isIdentifier(headersNode)) {\n const symbol = checker.getSymbolAtLocation(headersNode);\n const decl = symbol?.valueDeclaration ?? symbol?.declarations?.[0];\n if (decl && ts.isVariableDeclaration(decl) && decl.initializer) {\n return resolveHeadersObject(decl.initializer, checker);\n }\n }\n return undefined;\n}\n\nfunction getHeaderValue(\n headersNode: ts.Node | undefined,\n headerName: string,\n checker: ts.TypeChecker,\n) {\n const headersObject = resolveHeadersObject(headersNode, checker);\n if (!headersObject) {\n return undefined;\n }\n for (const prop of headersObject.properties) {\n if (!ts.isPropertyAssignment(prop)) {\n continue;\n }\n const key = getPropertyNameText(prop.name, checker);\n if (!key || key.toLowerCase() !== headerName.toLowerCase()) {\n continue;\n }\n const value = getConstantValue(checker, prop.initializer);\n return typeof value === 'string' ? value : undefined;\n }\n return undefined;\n}\n\nfunction hasHeaderKey(\n headersNode: ts.Node | undefined,\n headerName: string,\n checker: ts.TypeChecker,\n) {\n const headersObject = resolveHeadersObject(headersNode, checker);\n if (!headersObject) {\n return false;\n }\n for (const prop of headersObject.properties) {\n if (!ts.isPropertyAssignment(prop)) {\n continue;\n }\n const key = getPropertyNameText(prop.name, checker);\n if (key && key.toLowerCase() === headerName.toLowerCase()) {\n return true;\n }\n }\n return false;\n}\n\nfunction isJsonContentType(contentType: string) {\n return contentType.endsWith('/json') || contentType.endsWith('+json');\n}\n\nfunction isTextContentTypeValue(contentType: string) {\n return contentType.startsWith('text/');\n}\n\nfunction inferContentType(\n body: ts.Node | undefined,\n headers: ts.Node | undefined,\n defaultContentType: string,\n checker: ts.TypeChecker,\n) {\n if (!body) {\n return 'empty';\n }\n const headerContentType = normalizeContentType(\n getHeaderValue(headers, 'Content-Type', checker),\n );\n if (headerContentType) {\n return headerContentType;\n }\n if (hasHeaderKey(headers, 'Content-Disposition', checker)) {\n return 'application/octet-stream';\n }\n return defaultContentType;\n}\n\nfunction getHeaderKeys(headersNode: ts.Node | undefined, deriver: TypeDeriver) {\n if (!headersNode) {\n return [];\n }\n const resolved = resolveHeadersObject(headersNode, deriver.checker);\n if (resolved) {\n return Object.keys(deriver.serializeNode(resolved));\n }\n const type = deriver.checker.getTypeAtLocation(headersNode);\n const names = deriver.checker\n .getPropertiesOfType(type)\n .map((prop) => prop.name);\n if (!names.length) {\n return [];\n }\n const sorted = [...names].sort((a, b) => a.localeCompare(b));\n return sorted.flatMap((name) =>\n name.includes('-') ? [`'${name}'`, name] : [name],\n );\n}\n\nexport const newResponse: NaunceResponseAnalyzerFn = (\n _handler,\n deriver,\n node,\n) => {\n if (!ts.isNewExpression(node)) {\n return [];\n }\n const exprName = node.expression.getText();\n if (exprName !== 'Response') {\n return [];\n }\n const [body, init] = node.arguments ?? [];\n let statusNode: ts.Node | undefined;\n let headersNode: ts.Node | undefined;\n if (init && ts.isObjectLiteralExpression(init)) {\n for (const prop of init.properties) {\n if (!ts.isPropertyAssignment(prop)) {\n if (ts.isShorthandPropertyAssignment(prop)) {\n const key = prop.name.text;\n if (key === 'headers') {\n headersNode = prop;\n }\n }\n continue;\n }\n const key = getPropertyNameText(prop.name, deriver.checker);\n if (!key) {\n continue;\n }\n if (key === 'status') {\n statusNode = prop.initializer;\n } else if (key === 'headers') {\n headersNode = prop.initializer;\n }\n }\n }\n\n const contentType = inferContentType(\n body,\n headersNode,\n 'application/octet-stream',\n deriver.checker,\n );\n\n const normalized = contentType.toLowerCase();\n const shouldSerialize =\n !!body &&\n (isJsonContentType(normalized) || isTextContentTypeValue(normalized));\n\n return [\n {\n headers: getHeaderKeys(headersNode, deriver),\n contentType,\n statusCode: statusNode ? resolveStatusCode(statusNode) : '200',\n response: shouldSerialize ? deriver.serializeNode(body) : undefined,\n },\n ];\n};\n\nexport function defaultResponseAnalyzer(\n handler: ts.ArrowFunction | ts.FunctionExpression,\n deriver: TypeDeriver,\n) {\n const responsesList: ResponseItem[] = [];\n if (!handler.parameters.length) {\n return responsesList;\n }\n const contextVarName = handler.parameters[0].name.getText();\n const visit = handlerVisitor((node, statusCode, headers, contentType) => {\n const resolvedContentType = inferContentType(\n node,\n headers,\n contentType,\n deriver.checker,\n );\n responsesList.push({\n headers: getHeaderKeys(headers, deriver),\n contentType: resolvedContentType,\n statusCode: statusCode ? resolveStatusCode(statusCode) : '200',\n response: node ? deriver.serializeNode(node) : undefined,\n });\n }, contextVarName);\n visit(handler.body);\n return responsesList;\n}\n\nexport function streamText(\n _handler: ts.ArrowFunction | ts.FunctionExpression,\n _deriver: TypeDeriver,\n): ResponseItem[] {\n return [\n {\n contentType: 'text/plain',\n headers: [{ 'Transfer-Encoding': ['chunked'] }],\n statusCode: '200',\n response: {\n optional: false,\n kind: 'primitive',\n [$types]: ['string'],\n },\n },\n ];\n}\n\nexport function stream(\n _handler: ts.ArrowFunction | ts.FunctionExpression,\n _deriver: TypeDeriver,\n): ResponseItem[] {\n return [\n {\n contentType: 'application/octet-stream',\n headers: [],\n statusCode: '200',\n response: {\n optional: false,\n kind: 'primitive',\n [$types]: ['string'],\n },\n },\n ];\n}\n\nexport function streamSSE(\n _handler: ts.ArrowFunction | ts.FunctionExpression,\n _deriver: TypeDeriver,\n): ResponseItem[] {\n return [\n {\n contentType: 'text/event-stream',\n headers: [],\n statusCode: '200',\n response: {\n optional: false,\n kind: 'primitive',\n [$types]: ['string'],\n },\n },\n ];\n}\n\nexport const httpException: NaunceResponseAnalyzerFn = (\n _handler,\n deriver,\n node,\n) => {\n if (ts.isNewExpression(node)) {\n const [status, options] = node.arguments ?? [];\n // if (!ts.isObjectLiteralExpression(options)) {\n // return [];\n // }\n // const properties = options.properties.reduce<Record<string, string>>(\n // (acc, prop) => {\n // if (ts.isPropertyAssignment(prop)) {\n // const key = prop.name.getText();\n // if (ts.isLiteralExpression(prop.initializer)) {\n // acc[key] = prop.initializer.text;\n // } else {\n // acc[key] = prop.initializer.getText();\n // }\n // }\n // return acc;\n // },\n // {},\n // );\n return [\n {\n contentType: 'application/json',\n headers: [],\n statusCode: resolveStatusCode(status),\n response: options ? deriver.serializeNode(options) : undefined,\n },\n ];\n }\n return [];\n};\n\nexport const responseAnalyzer = {\n default: defaultResponseAnalyzer,\n streamText,\n stream,\n streamSSE,\n 'new.Response': newResponse,\n 'throw.new.HTTPException': httpException,\n};\n\nexport default responseAnalyzer;\n", "import ts from 'typescript';\n\nfunction unwrapExpression(node: ts.Expression): ts.Expression {\n let current = node;\n while (true) {\n if (ts.isAsExpression(current)) {\n current = current.expression;\n continue;\n }\n if (ts.isTypeAssertionExpression(current)) {\n current = current.expression;\n continue;\n }\n if (ts.isParenthesizedExpression(current)) {\n current = current.expression;\n continue;\n }\n return current;\n }\n}\n\nfunction literalValueFromType(\n type: ts.Type,\n checker: ts.TypeChecker,\n): string | number | boolean | undefined {\n if (type.isStringLiteral()) {\n return type.value;\n }\n if (type.isNumberLiteral()) {\n return type.value;\n }\n if (type.flags & ts.TypeFlags.BooleanLiteral) {\n return checker.typeToString(type) === 'true';\n }\n return undefined;\n}\n\nexport function getConstantValue(\n checker: ts.TypeChecker,\n expression: ts.Expression,\n): string | number | boolean | undefined {\n const unwrapped = unwrapExpression(expression);\n\n const constant = checker.getConstantValue(\n unwrapped as\n ts.EnumMember | ts.PropertyAccessExpression | ts.ElementAccessExpression,\n );\n if (constant !== undefined) {\n return constant;\n }\n\n if (\n ts.isStringLiteral(unwrapped) ||\n ts.isNoSubstitutionTemplateLiteral(unwrapped)\n ) {\n return unwrapped.text;\n }\n if (ts.isNumericLiteral(unwrapped)) {\n return Number(unwrapped.text);\n }\n if (unwrapped.kind === ts.SyntaxKind.TrueKeyword) {\n return true;\n }\n if (unwrapped.kind === ts.SyntaxKind.FalseKeyword) {\n return false;\n }\n\n const type = checker.getTypeAtLocation(unwrapped);\n const literal = literalValueFromType(type, checker);\n if (literal !== undefined) {\n return literal;\n }\n if (type.isUnion()) {\n let resolved: string | number | boolean | undefined = undefined;\n for (const entry of type.types) {\n const value = literalValueFromType(entry, checker);\n if (value === undefined) {\n return undefined;\n }\n if (resolved === undefined) {\n resolved = value;\n } else if (resolved !== value) {\n return undefined;\n }\n }\n return resolved;\n }\n return undefined;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAOA,SAAQ;AAEf;AAAA,EACE;AAAA,OAIK;;;ACPP,OAAO,QAAQ;AAEf,SAAS,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AA,QACN,CAAC,MAAM,GAAG,CAAC,QAAQ;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,OACd,UACA,UACgB;AAChB,SAAO;AAAA,IACL;AAAA,MACE,aAAa;AAAA,MACb,SAAS,CAAC;AAAA,MACV,YAAY;AAAA,MACZ,UAAU;AAAA,QACR,UAAU;AAAA,QACV,MAAM;AAAA,QACN,CAAC,MAAM,GAAG,CAAC,QAAQ;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,UACd,UACA,UACgB;AAChB,SAAO;AAAA,IACL;AAAA,MACE,aAAa;AAAA,MACb,SAAS,CAAC;AAAA,MACV,YAAY;AAAA,MACZ,UAAU;AAAA,QACR,UAAU;AAAA,QACV,MAAM;AAAA,QACN,CAAC,MAAM,GAAG,CAAC,QAAQ;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AACF;AAEO,IAAM,gBAA0C,CACrD,UACA,SACA,SACG;AACH,MAAID,IAAG,gBAAgB,IAAI,GAAG;AAC5B,UAAM,CAAC,QAAQ,OAAO,IAAI,KAAK,aAAa,CAAC;AAkB7C,WAAO;AAAA,MACL;AAAA,QACE,aAAa;AAAA,QACb,SAAS,CAAC;AAAA,QACV,YAAY,kBAAkB,MAAM;AAAA,QACpC,UAAU,UAAU,QAAQ,cAAc,OAAO,IAAI;AAAA,MACvD;AAAA,IACF;AAAA,EACF;AACA,SAAO,CAAC;AACV;AAEO,IAAM,mBAAmB;AAAA,EAC9B,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EACA,gBAAgB;AAAA,EAChB,2BAA2B;AAC7B;",
|
|
6
6
|
"names": ["ts", "ts", "key"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constant-value.d.ts","sourceRoot":"","sources":["../../src/lib/constant-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAqC5B,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,UAAU,EAAE,EAAE,CAAC,UAAU,GACxB,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"constant-value.d.ts","sourceRoot":"","sources":["../../src/lib/constant-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAqC5B,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,UAAU,EAAE,EAAE,CAAC,UAAU,GACxB,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAgDvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-analyzer.d.ts","sourceRoot":"","sources":["../../src/lib/response-analyzer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAEL,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EACjB,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"response-analyzer.d.ts","sourceRoot":"","sources":["../../src/lib/response-analyzer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAEL,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EACjB,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AAmQtB,eAAO,MAAM,WAAW,EAAE,wBA0DzB,CAAC;AAEF,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,EAAE,CAAC,aAAa,GAAG,EAAE,CAAC,kBAAkB,EACjD,OAAO,EAAE,WAAW,kBAuBrB;AAED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,EAAE,CAAC,aAAa,GAAG,EAAE,CAAC,kBAAkB,EAClD,QAAQ,EAAE,WAAW,GACpB,YAAY,EAAE,CAahB;AAED,wBAAgB,MAAM,CACpB,QAAQ,EAAE,EAAE,CAAC,aAAa,GAAG,EAAE,CAAC,kBAAkB,EAClD,QAAQ,EAAE,WAAW,GACpB,YAAY,EAAE,CAahB;AAED,wBAAgB,SAAS,CACvB,QAAQ,EAAE,EAAE,CAAC,aAAa,GAAG,EAAE,CAAC,kBAAkB,EAClD,QAAQ,EAAE,WAAW,GACpB,YAAY,EAAE,CAahB;AAED,eAAO,MAAM,aAAa,EAAE,wBAkC3B,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;;;;CAO5B,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/runtime/output.ts", "../../../src/lib/runtime/validator.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Context } from 'hono';\nimport { getContext } from 'hono/context-storage';\nimport type {\n ContentfulStatusCode,\n RedirectStatusCode,\n} from 'hono/utils/http-status';\n\ntype Data = any;\nfunction send(\n context: Context,\n value: Data | undefined | null,\n status: ContentfulStatusCode,\n headers?: Readonly<Record<string, string>>,\n) {\n if (value === undefined || value === null) {\n return context.body(null, status, headers);\n }\n const responseHeaders = { ...headers };\n responseHeaders['Content-Type'] ??= 'application/json';\n if (responseHeaders['Content-Type'].includes('application/json')) {\n return context.body(JSON.stringify(value), status, responseHeaders);\n }\n return context.body(value, status, responseHeaders);\n}\n\nexport function createOutput(contextFn: () => Context) {\n return {\n nocontent() {\n const context = contextFn();\n return context.body(null, 204, {});\n },\n ok(value: Data | undefined | null, headers?: Record<string, string>) {\n return send(contextFn(), value, 200, headers);\n },\n created(\n valueOrUri: string | Data,\n value: Data | undefined | null,\n headers?: Record<string, string>,\n ) {\n if (typeof valueOrUri === 'string') {\n // If no content is provided, we send null\n return send(contextFn(), value, 201, {\n Location: valueOrUri,\n ...(headers || {}),\n });\n } else {\n // valueOrUri is the data\n return send(contextFn(), valueOrUri, 201, headers);\n }\n },\n redirect(uri: string | URL, statusCode?: unknown) {\n const context = contextFn();\n return context.redirect(\n uri.toString(),\n (statusCode as RedirectStatusCode) ?? undefined,\n );\n },\n attachment(buffer: Buffer, filename: string, mimeType: string) {\n const context = contextFn();\n // https://github.com/honojs/hono/issues/3720\n return context.body(buffer as never, 200, {\n 'Content-Type': mimeType,\n 'Content-Disposition': `attachment; filename=\"${filename}\"`,\n 'Content-Length': buffer.length.toString(),\n });\n },\n badRequest(\n value: Data | undefined | null,\n headers?: Record<string, string>,\n ) {\n return send(contextFn(), value, 400, headers);\n },\n unauthorized(\n value: Data | undefined | null,\n headers?: Record<string, string>,\n ) {\n return send(contextFn(), value, 401, headers);\n },\n forbidden(\n value: Data | undefined | null,\n headers?: Record<string, string>,\n ) {\n return send(contextFn(), value, 403, headers);\n },\n notFound(value: Data | undefined | null, headers?: Record<string, string>) {\n return send(contextFn(), value, 404, headers);\n },\n notImplemented(\n value: Data | undefined | null,\n headers?: Record<string, string>,\n ) {\n return send(contextFn(), value, 501, headers);\n },\n accepted(value: Data | undefined | null, headers?: Record<string, string>) {\n return send(contextFn(), value, 202, headers);\n },\n conflict(value: Data | undefined | null, headers?: Record<string, string>) {\n return send(contextFn(), value, 409, headers);\n },\n unprocessableEntity(\n value: Data | undefined | null,\n headers?: Record<string, string>,\n ) {\n return send(contextFn(), value, 422, headers);\n },\n internalServerError(\n value: Data | undefined | null,\n headers?: Record<string, string>,\n ) {\n return send(contextFn(), value, 500, headers);\n },\n serviceUnavailable(\n value: Data | undefined | null,\n headers?: Record<string, string>,\n ) {\n return send(contextFn(), value, 503, headers);\n },\n };\n}\n\nexport const output = createOutput(() => getContext());\n", "import { parse as parseContentType } from 'fast-content-type-parse';\nimport type { MiddlewareHandler, ValidationTargets } from 'hono';\nimport { createMiddleware } from 'hono/factory';\nimport { HTTPException } from 'hono/http-exception';\nimport z from 'zod';\n\ntype ContentType =\n | 'application/json'\n | 'application/x-www-form-urlencoded'\n | 'multipart/form-data'\n | 'text/plain';\n\n// z.ZodType<any> mirrors zod v3's ZodTypeAny: with the default `unknown`\n// output, concrete middlewares stop being assignable to\n// ValidateMiddleware<ValidatorConfig>.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ValidatorConfig = Record<\n string,\n { select: unknown; against: z.ZodType<any> }\n>;\n\ntype ExtractInput<T extends ValidatorConfig> = {\n [K in keyof T]: z.infer<T[K]['against']>;\n};\n\ntype HasUndefined<T> = undefined extends T ? true : false;\n\ntype InferTarget<\n T extends ValidatorConfig,\n S,\n Target extends keyof ValidationTargets,\n> = {\n [K in keyof T as T[K]['select'] extends S ? K : never]: HasUndefined<\n z.infer<T[K]['against']>\n > extends true\n ? z.infer<T[K]['against']> | undefined\n : z.infer<T[K]['against']> extends ValidationTargets[Target]\n ? z.infer<T[K]['against']>\n : z.infer<T[K]['against']>;\n};\n\ntype InferIn<T extends ValidatorConfig> = (keyof InferTarget<\n T,\n QuerySelect | QueriesSelect,\n 'query'\n> extends never\n ? never\n : { query: InferTarget<T, QuerySelect | QueriesSelect, 'query'> }) &\n (keyof InferTarget<T, BodySelect, 'json'> extends never\n ? never\n : { json: InferTarget<T, BodySelect, 'json'> }) &\n (keyof InferTarget<T, ParamsSelect, 'param'> extends never\n ? never\n : { param: InferTarget<T, ParamsSelect, 'param'> }) &\n (keyof InferTarget<T, HeadersSelect, 'header'> extends never\n ? never\n : { header: InferTarget<T, HeadersSelect, 'header'> }) &\n (keyof InferTarget<T, CookieSelect, 'cookie'> extends never\n ? never\n : { cookie: InferTarget<T, CookieSelect, 'cookie'> });\n\n// Marker classes\nclass BodySelect {\n #private = 0;\n}\nclass QuerySelect {\n #private = 0;\n}\nclass QueriesSelect {\n #private = 0;\n}\nclass ParamsSelect {\n #private = 0;\n}\nclass HeadersSelect {\n #private = 0;\n}\nclass CookieSelect {\n #private = 0;\n}\n\ntype SelectorFn<T> = (payload: {\n body: Record<string, BodySelect>;\n query: Record<string, QuerySelect>;\n queries: Record<string, QueriesSelect>;\n params: Record<string, ParamsSelect>;\n headers: Record<string, HeadersSelect>;\n}) => T;\ntype ValidateMiddleware<T extends ValidatorConfig> = MiddlewareHandler<\n {\n Variables: {\n input: ExtractInput<T>;\n };\n },\n string,\n { in: InferIn<T> }\n>;\n\nexport function validate<T extends ValidatorConfig>(\n selector: SelectorFn<T>,\n): ValidateMiddleware<T>;\nexport function validate<T extends ValidatorConfig>(\n expectedContentTypeOrSelector: ContentType,\n selector: SelectorFn<T>,\n): ValidateMiddleware<T>;\nexport function validate<T extends ValidatorConfig>(\n expectedContentTypeOrSelector: ContentType | SelectorFn<T>,\n selector?: SelectorFn<T>,\n): ValidateMiddleware<T> {\n const expectedContentType =\n typeof expectedContentTypeOrSelector === 'string'\n ? expectedContentTypeOrSelector\n : undefined;\n const _selector =\n typeof expectedContentTypeOrSelector === 'function'\n ? expectedContentTypeOrSelector\n : selector;\n if (!_selector) {\n throw new Error('Selector function is required');\n }\n\n return createMiddleware(async (c, next) => {\n const ct = c.req.header('content-type');\n if (c.req.method === 'GET' && ct) {\n throw new HTTPException(415, {\n message: 'Unsupported Media Type',\n cause: {\n code: 'api/unsupported-media-type',\n details: `GET requests cannot have a content type header`,\n },\n });\n }\n if (expectedContentType) {\n verifyContentType(ct, expectedContentType);\n }\n\n const contentType = ct ? parseContentType(ct) : null;\n let body: unknown = null;\n\n switch (contentType?.type) {\n case 'application/json':\n body = await c.req.json();\n break;\n case 'application/x-www-form-urlencoded':\n case 'multipart/form-data':\n body = await c.req.parseBody();\n break;\n default:\n body = {};\n }\n\n const payload = {\n body,\n query: c.req.query(),\n queries: c.req.queries(),\n params: c.req.param(),\n headers: Object.fromEntries(\n Object.entries(c.req.header()).map(([k, v]) => [k, v ?? '']),\n ),\n };\n\n const config = _selector(payload as never);\n const schema = z.object(\n Object.entries(config).reduce(\n (acc, [key, value]) => {\n acc[key] = value.against;\n return acc;\n },\n {} as Record<string, z.ZodType>,\n ),\n );\n\n const input = Object.entries(config).reduce(\n (acc, [key, value]) => {\n acc[key] = value.select;\n return acc;\n },\n {} as Record<string, unknown>,\n );\n\n const parsed = await parse(schema, input);\n c.set('input', parsed as ExtractInput<T>);\n await next();\n });\n}\n\nexport async function parse<T extends z.ZodRawShape>(\n schema: z.ZodObject<T>,\n input: unknown,\n) {\n const result = await schema.safeParseAsync(input);\n if (!result.success) {\n const error = new HTTPException(400, {\n message: 'Validation failed',\n cause: {\n code: 'api/validation-failed',\n detail: 'The input data is invalid',\n errors: z.flattenError(result.error, (issue) => ({\n message: issue.message,\n code: issue.code,\n path: issue.path.join('.'),\n })).fieldErrors,\n },\n });\n throw error;\n }\n return result.data;\n}\n\nexport const openapi = validate;\n\nexport const consume = (contentType: ContentType) => {\n return createMiddleware(async (context, next) => {\n verifyContentType(context.req.header('content-type'), contentType);\n await next();\n });\n};\n\nexport function verifyContentType(\n actual: string | undefined,\n expected: ContentType,\n): asserts actual is ContentType {\n if (!actual) {\n throw new HTTPException(415, {\n message: 'Unsupported Media Type',\n cause: {\n code: 'api/unsupported-media-type',\n details: 'Missing content type header',\n },\n });\n }\n const { type: incomingContentType } = parseContentType(actual);\n if (incomingContentType !== expected) {\n throw new HTTPException(415, {\n message: 'Unsupported Media Type',\n cause: {\n code: 'api/unsupported-media-type',\n details: `Expected content type: ${expected}, but got: ${incomingContentType}`,\n },\n });\n }\n}\n"],
|
|
4
|
+
"sourcesContent": ["import type { Context } from 'hono';\nimport { getContext } from 'hono/context-storage';\nimport type {\n ContentfulStatusCode,\n RedirectStatusCode,\n} from 'hono/utils/http-status';\n\ntype Data = any;\nfunction send(\n context: Context,\n value: Data | undefined | null,\n status: ContentfulStatusCode,\n headers?: Readonly<Record<string, string>>,\n) {\n if (value === undefined || value === null) {\n return context.body(null, status, headers);\n }\n const responseHeaders = { ...headers };\n responseHeaders['Content-Type'] ??= 'application/json';\n if (responseHeaders['Content-Type'].includes('application/json')) {\n return context.body(JSON.stringify(value), status, responseHeaders);\n }\n return context.body(value, status, responseHeaders);\n}\n\nexport function createOutput(contextFn: () => Context) {\n return {\n nocontent() {\n const context = contextFn();\n return context.body(null, 204, {});\n },\n ok(value: Data | undefined | null, headers?: Record<string, string>) {\n return send(contextFn(), value, 200, headers);\n },\n created(\n valueOrUri: string | Data,\n value: Data | undefined | null,\n headers?: Record<string, string>,\n ) {\n if (typeof valueOrUri === 'string') {\n // If no content is provided, we send null\n return send(contextFn(), value, 201, {\n Location: valueOrUri,\n ...(headers || {}),\n });\n } else {\n // valueOrUri is the data\n return send(contextFn(), valueOrUri, 201, headers);\n }\n },\n redirect(uri: string | URL, statusCode?: unknown) {\n const context = contextFn();\n return context.redirect(\n uri.toString(),\n (statusCode as RedirectStatusCode) ?? undefined,\n );\n },\n attachment(buffer: Buffer, filename: string, mimeType: string) {\n const context = contextFn();\n // https://github.com/honojs/hono/issues/3720\n return context.body(buffer as never, 200, {\n 'Content-Type': mimeType,\n 'Content-Disposition': `attachment; filename=\"${filename}\"`,\n 'Content-Length': buffer.length.toString(),\n });\n },\n badRequest(\n value: Data | undefined | null,\n headers?: Record<string, string>,\n ) {\n return send(contextFn(), value, 400, headers);\n },\n unauthorized(\n value: Data | undefined | null,\n headers?: Record<string, string>,\n ) {\n return send(contextFn(), value, 401, headers);\n },\n forbidden(\n value: Data | undefined | null,\n headers?: Record<string, string>,\n ) {\n return send(contextFn(), value, 403, headers);\n },\n notFound(value: Data | undefined | null, headers?: Record<string, string>) {\n return send(contextFn(), value, 404, headers);\n },\n notImplemented(\n value: Data | undefined | null,\n headers?: Record<string, string>,\n ) {\n return send(contextFn(), value, 501, headers);\n },\n accepted(value: Data | undefined | null, headers?: Record<string, string>) {\n return send(contextFn(), value, 202, headers);\n },\n conflict(value: Data | undefined | null, headers?: Record<string, string>) {\n return send(contextFn(), value, 409, headers);\n },\n unprocessableEntity(\n value: Data | undefined | null,\n headers?: Record<string, string>,\n ) {\n return send(contextFn(), value, 422, headers);\n },\n internalServerError(\n value: Data | undefined | null,\n headers?: Record<string, string>,\n ) {\n return send(contextFn(), value, 500, headers);\n },\n serviceUnavailable(\n value: Data | undefined | null,\n headers?: Record<string, string>,\n ) {\n return send(contextFn(), value, 503, headers);\n },\n };\n}\n\nexport const output = createOutput(() => getContext());\n", "import { parse as parseContentType } from 'fast-content-type-parse';\nimport type { MiddlewareHandler, ValidationTargets } from 'hono';\nimport { createMiddleware } from 'hono/factory';\nimport { HTTPException } from 'hono/http-exception';\nimport z from 'zod';\n\ntype ContentType =\n | 'application/json'\n | 'application/x-www-form-urlencoded'\n | 'multipart/form-data'\n | 'text/plain';\n\n// z.ZodType<any> mirrors zod v3's ZodTypeAny: with the default `unknown`\n// output, concrete middlewares stop being assignable to\n// ValidateMiddleware<ValidatorConfig>.\n\ntype ValidatorConfig = Record<\n string,\n { select: unknown; against: z.ZodType<any> }\n>;\n\ntype ExtractInput<T extends ValidatorConfig> = {\n [K in keyof T]: z.infer<T[K]['against']>;\n};\n\ntype HasUndefined<T> = undefined extends T ? true : false;\n\ntype InferTarget<\n T extends ValidatorConfig,\n S,\n Target extends keyof ValidationTargets,\n> = {\n [K in keyof T as T[K]['select'] extends S ? K : never]: HasUndefined<\n z.infer<T[K]['against']>\n > extends true\n ? z.infer<T[K]['against']> | undefined\n : z.infer<T[K]['against']> extends ValidationTargets[Target]\n ? z.infer<T[K]['against']>\n : z.infer<T[K]['against']>;\n};\n\ntype InferIn<T extends ValidatorConfig> = (keyof InferTarget<\n T,\n QuerySelect | QueriesSelect,\n 'query'\n> extends never\n ? never\n : { query: InferTarget<T, QuerySelect | QueriesSelect, 'query'> }) &\n (keyof InferTarget<T, BodySelect, 'json'> extends never\n ? never\n : { json: InferTarget<T, BodySelect, 'json'> }) &\n (keyof InferTarget<T, ParamsSelect, 'param'> extends never\n ? never\n : { param: InferTarget<T, ParamsSelect, 'param'> }) &\n (keyof InferTarget<T, HeadersSelect, 'header'> extends never\n ? never\n : { header: InferTarget<T, HeadersSelect, 'header'> }) &\n (keyof InferTarget<T, CookieSelect, 'cookie'> extends never\n ? never\n : { cookie: InferTarget<T, CookieSelect, 'cookie'> });\n\n// Marker classes\nclass BodySelect {\n #private = 0;\n}\nclass QuerySelect {\n #private = 0;\n}\nclass QueriesSelect {\n #private = 0;\n}\nclass ParamsSelect {\n #private = 0;\n}\nclass HeadersSelect {\n #private = 0;\n}\nclass CookieSelect {\n #private = 0;\n}\n\ntype SelectorFn<T> = (payload: {\n body: Record<string, BodySelect>;\n query: Record<string, QuerySelect>;\n queries: Record<string, QueriesSelect>;\n params: Record<string, ParamsSelect>;\n headers: Record<string, HeadersSelect>;\n}) => T;\ntype ValidateMiddleware<T extends ValidatorConfig> = MiddlewareHandler<\n {\n Variables: {\n input: ExtractInput<T>;\n };\n },\n string,\n { in: InferIn<T> }\n>;\n\nexport function validate<T extends ValidatorConfig>(\n selector: SelectorFn<T>,\n): ValidateMiddleware<T>;\nexport function validate<T extends ValidatorConfig>(\n expectedContentTypeOrSelector: ContentType,\n selector: SelectorFn<T>,\n): ValidateMiddleware<T>;\nexport function validate<T extends ValidatorConfig>(\n expectedContentTypeOrSelector: ContentType | SelectorFn<T>,\n selector?: SelectorFn<T>,\n): ValidateMiddleware<T> {\n const expectedContentType =\n typeof expectedContentTypeOrSelector === 'string'\n ? expectedContentTypeOrSelector\n : undefined;\n const _selector =\n typeof expectedContentTypeOrSelector === 'function'\n ? expectedContentTypeOrSelector\n : selector;\n if (!_selector) {\n throw new Error('Selector function is required');\n }\n\n return createMiddleware(async (c, next) => {\n const ct = c.req.header('content-type');\n if (c.req.method === 'GET' && ct) {\n throw new HTTPException(415, {\n message: 'Unsupported Media Type',\n cause: {\n code: 'api/unsupported-media-type',\n details: `GET requests cannot have a content type header`,\n },\n });\n }\n if (expectedContentType) {\n verifyContentType(ct, expectedContentType);\n }\n\n const contentType = ct ? parseContentType(ct) : null;\n let body: unknown = null;\n\n switch (contentType?.type) {\n case 'application/json':\n body = await c.req.json();\n break;\n case 'application/x-www-form-urlencoded':\n case 'multipart/form-data':\n body = await c.req.parseBody();\n break;\n default:\n body = {};\n }\n\n const payload = {\n body,\n query: c.req.query(),\n queries: c.req.queries(),\n params: c.req.param(),\n headers: Object.fromEntries(\n Object.entries(c.req.header()).map(([k, v]) => [k, v ?? '']),\n ),\n };\n\n const config = _selector(payload as never);\n const schema = z.object(\n Object.entries(config).reduce(\n (acc, [key, value]) => {\n acc[key] = value.against;\n return acc;\n },\n {} as Record<string, z.ZodType>,\n ),\n );\n\n const input = Object.entries(config).reduce(\n (acc, [key, value]) => {\n acc[key] = value.select;\n return acc;\n },\n {} as Record<string, unknown>,\n );\n\n const parsed = await parse(schema, input);\n c.set('input', parsed as ExtractInput<T>);\n await next();\n });\n}\n\nexport async function parse<T extends z.ZodRawShape>(\n schema: z.ZodObject<T>,\n input: unknown,\n) {\n const result = await schema.safeParseAsync(input);\n if (!result.success) {\n const error = new HTTPException(400, {\n message: 'Validation failed',\n cause: {\n code: 'api/validation-failed',\n detail: 'The input data is invalid',\n errors: z.flattenError(result.error, (issue) => ({\n message: issue.message,\n code: issue.code,\n path: issue.path.join('.'),\n })).fieldErrors,\n },\n });\n throw error;\n }\n return result.data;\n}\n\nexport const openapi = validate;\n\nexport const consume = (contentType: ContentType) => {\n return createMiddleware(async (context, next) => {\n verifyContentType(context.req.header('content-type'), contentType);\n await next();\n });\n};\n\nexport function verifyContentType(\n actual: string | undefined,\n expected: ContentType,\n): asserts actual is ContentType {\n if (!actual) {\n throw new HTTPException(415, {\n message: 'Unsupported Media Type',\n cause: {\n code: 'api/unsupported-media-type',\n details: 'Missing content type header',\n },\n });\n }\n const { type: incomingContentType } = parseContentType(actual);\n if (incomingContentType !== expected) {\n throw new HTTPException(415, {\n message: 'Unsupported Media Type',\n cause: {\n code: 'api/unsupported-media-type',\n details: `Expected content type: ${expected}, but got: ${incomingContentType}`,\n },\n });\n }\n}\n"],
|
|
5
5
|
"mappings": ";AACA,SAAS,kBAAkB;AAO3B,SAAS,KACP,SACA,OACA,QACA,SACA;AACA,MAAI,UAAU,UAAa,UAAU,MAAM;AACzC,WAAO,QAAQ,KAAK,MAAM,QAAQ,OAAO;AAAA,EAC3C;AACA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AAK;AAAA,EACb,CAAC;AACH;AAEA,eAAsB,MACpB,QACA,OACA;AACA,QAAM,SAAS,MAAM,OAAO,eAAe,KAAK;AAChD,MAAI,CAAC,OAAO,SAAS;AACnB,UAAM,QAAQ,IAAI,cAAc,KAAK;AAAA,MACnC,SAAS;AAAA,MACT,OAAO;AAAA,QACL,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,QAAQ,EAAE,aAAa,OAAO,OAAO,CAAC,WAAW;AAAA,UAC/C,SAAS,MAAM;AAAA,UACf,MAAM,MAAM;AAAA,UACZ,MAAM,MAAM,KAAK,KAAK,GAAG;AAAA,QAC3B,EAAE,EAAE;AAAA,MACN;AAAA,IACF,CAAC;AACD,UAAM;AAAA,EACR;AACA,SAAO,OAAO;AAChB;AAEO,IAAM,UAAU;AAEhB,IAAM,UAAU,CAAC,gBAA6B;AACnD,SAAO,iBAAiB,OAAO,SAAS,SAAS;AAC/C,sBAAkB,QAAQ,IAAI,OAAO,cAAc,GAAG,WAAW;AACjE,UAAM,KAAK;AAAA,EACb,CAAC;AACH;AAEO,SAAS,kBACd,QACA,UAC+B;AAC/B,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,cAAc,KAAK;AAAA,MAC3B,SAAS;AAAA,MACT,OAAO;AAAA,QACL,MAAM;AAAA,QACN,SAAS;AAAA,MACX;AAAA,IACF,CAAC;AAAA,EACH;AACA,QAAM,EAAE,MAAM,oBAAoB,IAAI,iBAAiB,MAAM;AAC7D,MAAI,wBAAwB,UAAU;AACpC,UAAM,IAAI,cAAc,KAAK;AAAA,MAC3B,SAAS;AAAA,MACT,OAAO;AAAA,QACL,MAAM;AAAA,QACN,SAAS,0BAA0B,QAAQ,cAAc,mBAAmB;AAAA,MAC9E;AAAA,IACF,CAAC;AAAA,EACH;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,37 +2,37 @@ import type { Context } from 'hono';
|
|
|
2
2
|
type Data = any;
|
|
3
3
|
export declare function createOutput(contextFn: () => Context): {
|
|
4
4
|
nocontent(): Response & import("hono").TypedResponse<null, 204, "body">;
|
|
5
|
-
ok(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
6
|
-
created(valueOrUri: string | Data, value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
5
|
+
ok(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
6
|
+
created(valueOrUri: string | Data, value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
7
7
|
redirect(uri: string | URL, statusCode?: unknown): Response & import("hono").TypedResponse<undefined, 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308, "redirect">;
|
|
8
|
-
attachment(buffer: Buffer, filename: string, mimeType: string): Response & import("hono").TypedResponse<
|
|
9
|
-
badRequest(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
10
|
-
unauthorized(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
11
|
-
forbidden(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
12
|
-
notFound(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
13
|
-
notImplemented(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
14
|
-
accepted(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
15
|
-
conflict(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
16
|
-
unprocessableEntity(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
17
|
-
internalServerError(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
18
|
-
serviceUnavailable(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
8
|
+
attachment(buffer: Buffer, filename: string, mimeType: string): Response & import("hono").TypedResponse<never, 200, "body">;
|
|
9
|
+
badRequest(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
10
|
+
unauthorized(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
11
|
+
forbidden(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
12
|
+
notFound(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
13
|
+
notImplemented(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
14
|
+
accepted(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
15
|
+
conflict(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
16
|
+
unprocessableEntity(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
17
|
+
internalServerError(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
18
|
+
serviceUnavailable(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
19
19
|
};
|
|
20
20
|
export declare const output: {
|
|
21
21
|
nocontent(): Response & import("hono").TypedResponse<null, 204, "body">;
|
|
22
|
-
ok(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
23
|
-
created(valueOrUri: string | Data, value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
22
|
+
ok(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
23
|
+
created(valueOrUri: string | Data, value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
24
24
|
redirect(uri: string | URL, statusCode?: unknown): Response & import("hono").TypedResponse<undefined, 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308, "redirect">;
|
|
25
|
-
attachment(buffer: Buffer, filename: string, mimeType: string): Response & import("hono").TypedResponse<
|
|
26
|
-
badRequest(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
27
|
-
unauthorized(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
28
|
-
forbidden(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
29
|
-
notFound(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
30
|
-
notImplemented(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
31
|
-
accepted(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
32
|
-
conflict(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
33
|
-
unprocessableEntity(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
34
|
-
internalServerError(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
35
|
-
serviceUnavailable(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<
|
|
25
|
+
attachment(buffer: Buffer, filename: string, mimeType: string): Response & import("hono").TypedResponse<never, 200, "body">;
|
|
26
|
+
badRequest(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
27
|
+
unauthorized(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
28
|
+
forbidden(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
29
|
+
notFound(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
30
|
+
notImplemented(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
31
|
+
accepted(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
32
|
+
conflict(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
33
|
+
unprocessableEntity(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
34
|
+
internalServerError(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
35
|
+
serviceUnavailable(value: Data | undefined | null, headers?: Record<string, string>): Response & import("hono").TypedResponse<any, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "body">;
|
|
36
36
|
};
|
|
37
37
|
export {};
|
|
38
38
|
//# sourceMappingURL=output.d.ts.map
|
|
@@ -59,7 +59,7 @@ export declare function validate<T extends ValidatorConfig>(selector: SelectorFn
|
|
|
59
59
|
export declare function validate<T extends ValidatorConfig>(expectedContentTypeOrSelector: ContentType, selector: SelectorFn<T>): ValidateMiddleware<T>;
|
|
60
60
|
export declare function parse<T extends z.ZodRawShape>(schema: z.ZodObject<T>, input: unknown): Promise<z.core.$InferObjectOutput<T, {}>>;
|
|
61
61
|
export declare const openapi: typeof validate;
|
|
62
|
-
export declare const consume: (contentType: ContentType) => MiddlewareHandler<any, string, {}>;
|
|
62
|
+
export declare const consume: (contentType: ContentType) => MiddlewareHandler<any, string, {}, Response>;
|
|
63
63
|
export declare function verifyContentType(actual: string | undefined, expected: ContentType): asserts actual is ContentType;
|
|
64
64
|
export {};
|
|
65
65
|
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../../src/lib/runtime/validator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAGjE,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,KAAK,WAAW,GACZ,kBAAkB,GAClB,mCAAmC,GACnC,qBAAqB,GACrB,YAAY,CAAC;AAMjB,KAAK,eAAe,GAAG,MAAM,CAC3B,MAAM,EACN;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;CAAE,CAC7C,CAAC;AAEF,KAAK,YAAY,CAAC,CAAC,SAAS,eAAe,IAAI;KAC5C,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;CACzC,CAAC;AAEF,KAAK,YAAY,CAAC,CAAC,IAAI,SAAS,SAAS,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AAE1D,KAAK,WAAW,CACd,CAAC,SAAS,eAAe,EACzB,CAAC,EACD,MAAM,SAAS,MAAM,iBAAiB,IACpC;KACD,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC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C;AAkFzB,wBAAsB,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,WAAW,EACjD,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EACtB,KAAK,EAAE,OAAO,6CAmBf;AAED,eAAO,MAAM,OAAO,iBAAW,CAAC;AAEhC,eAAO,MAAM,OAAO,GAAI,aAAa,WAAW,iDAK/C,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,QAAQ,EAAE,WAAW,GACpB,OAAO,CAAC,MAAM,IAAI,WAAW,CAoB/B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdk-it/hono",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
"!**/*.test.*"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@sdk-it/core": "0.
|
|
30
|
+
"@sdk-it/core": "0.46.1",
|
|
31
31
|
"hono": "^4.7.4",
|
|
32
32
|
"zod": "^4.3.0",
|
|
33
33
|
"fast-content-type-parse": "^3.0.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"typescript": "^
|
|
36
|
+
"typescript": "^6.0.3"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/debug": "^4.1.12"
|