@sdk-it/hono 0.46.10 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +114 -159
- package/dist/index.js.map +3 -3
- package/dist/lib/constant-value.d.ts +3 -2
- package/dist/lib/constant-value.d.ts.map +1 -1
- package/dist/lib/evlog.d.ts +28 -0
- package/dist/lib/evlog.d.ts.map +1 -0
- package/dist/lib/evlog.js +152 -0
- package/dist/lib/evlog.js.map +7 -0
- package/dist/lib/response-analyzer.d.ts +8 -6
- package/dist/lib/response-analyzer.d.ts.map +1 -1
- package/dist/lib/runtime/index.d.ts.map +1 -1
- package/dist/lib/runtime/index.js +48 -23
- package/dist/lib/runtime/index.js.map +2 -2
- package/dist/lib/runtime/output.d.ts +5 -4
- package/dist/lib/runtime/output.d.ts.map +1 -1
- package/dist/lib/runtime/validator.d.ts.map +1 -1
- package/package.json +23 -8
- package/src/lib/runtime/output.ts +8 -8
- package/src/lib/runtime/validator.ts +72 -29
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ client generation.
|
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
npm install @sdk-it/hono hono zod
|
|
17
|
-
npm install --save-dev @sdk-it/generic @sdk-it/typescript
|
|
17
|
+
npm install --save-dev @sdk-it/core @sdk-it/generic @sdk-it/typescript
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
## Runtime primitives
|
|
@@ -235,16 +235,15 @@ Analyze the backend and generate the client:
|
|
|
235
235
|
import { writeFile } from 'node:fs/promises';
|
|
236
236
|
import { resolve } from 'node:path';
|
|
237
237
|
|
|
238
|
+
import { openAnalysisProject } from '@sdk-it/core/program.js';
|
|
238
239
|
import { analyze } from '@sdk-it/generic';
|
|
239
240
|
import { responseAnalyzer } from '@sdk-it/hono';
|
|
240
241
|
import { generate } from '@sdk-it/typescript';
|
|
241
242
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
},
|
|
247
|
-
);
|
|
243
|
+
using project = openAnalysisProject('./apps/backend/tsconfig.app.json');
|
|
244
|
+
const { paths, components, tags } = await analyze(project, {
|
|
245
|
+
responseAnalyzer,
|
|
246
|
+
});
|
|
248
247
|
|
|
249
248
|
const spec = {
|
|
250
249
|
openapi: '3.1.0' as const,
|
|
@@ -260,7 +259,8 @@ const spec = {
|
|
|
260
259
|
await writeFile('openapi.json', JSON.stringify(spec, null, 2));
|
|
261
260
|
await generate(spec, {
|
|
262
261
|
output: resolve('client'),
|
|
263
|
-
name: '
|
|
262
|
+
name: 'MyApi',
|
|
263
|
+
packageName: '@acme/my-api',
|
|
264
264
|
});
|
|
265
265
|
```
|
|
266
266
|
|
|
@@ -273,9 +273,9 @@ node openapi.ts
|
|
|
273
273
|
The generated client returns response data and throws typed errors:
|
|
274
274
|
|
|
275
275
|
```typescript
|
|
276
|
-
import {
|
|
276
|
+
import { Unauthorized, createMyApi } from './client/index.ts';
|
|
277
277
|
|
|
278
|
-
const client =
|
|
278
|
+
const client = createMyApi({
|
|
279
279
|
baseUrl: 'http://localhost:3000',
|
|
280
280
|
});
|
|
281
281
|
|
|
@@ -292,3 +292,58 @@ try {
|
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
```
|
|
295
|
+
|
|
296
|
+
## Document evlog error catalogs
|
|
297
|
+
|
|
298
|
+
A route can throw an [evlog](https://www.npmjs.com/package/evlog) catalog error instead of an `HTTPException`:
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
import { defineErrorCatalog } from 'evlog';
|
|
302
|
+
|
|
303
|
+
export const billingErrors = defineErrorCatalog('billing', {
|
|
304
|
+
PAYMENT_DECLINED: { status: 402, message: 'Card declined' },
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
// in a handler
|
|
308
|
+
throw billingErrors.PAYMENT_DECLINED();
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
If your error handler returns the error as it is (`c.json(error, error.status)`), add `evlogErrors` to the analyzers. Each catalog throw is then documented at its status, with evlog's JSON body and the literal `code`:
|
|
312
|
+
|
|
313
|
+
```typescript
|
|
314
|
+
import { responseAnalyzer } from '@sdk-it/hono';
|
|
315
|
+
import { evlogErrors } from '@sdk-it/hono/evlog';
|
|
316
|
+
|
|
317
|
+
const { paths, components } = await analyze(project, {
|
|
318
|
+
responseAnalyzer: { ...responseAnalyzer, ...evlogErrors },
|
|
319
|
+
});
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
If your error handler writes a different body, write your own `throw.call.EvlogError` analyzer. `catalogError` gives the entry's `code`, `status`, `message`, `why`, `fix` and `link`, and `schema` is the OpenAPI schema of your body:
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
import { catalogError } from '@sdk-it/hono/evlog';
|
|
326
|
+
|
|
327
|
+
const myErrors = {
|
|
328
|
+
'throw.call.EvlogError': (handler, deriver, node) => {
|
|
329
|
+
const error = catalogError(deriver, node);
|
|
330
|
+
if (!error) return [];
|
|
331
|
+
return [
|
|
332
|
+
{
|
|
333
|
+
statusCode: String(error.status),
|
|
334
|
+
contentType: 'application/json',
|
|
335
|
+
headers: [],
|
|
336
|
+
schema: {
|
|
337
|
+
type: 'object',
|
|
338
|
+
properties: {
|
|
339
|
+
error: { type: 'string' },
|
|
340
|
+
code: { type: 'string', enum: [error.code] },
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
];
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
A thrown call that no analyzer claims is not documented.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","
|
|
1
|
+
{"version":3,"file":"index.d.ts","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,70 +1,64 @@
|
|
|
1
1
|
// packages/hono/src/lib/response-analyzer.ts
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
isArrowFunction,
|
|
4
|
+
isAsExpression as isAsExpression2,
|
|
5
|
+
isBlock,
|
|
6
|
+
isCallExpression,
|
|
7
|
+
isComputedPropertyName,
|
|
8
|
+
isExpression,
|
|
9
|
+
isFunctionExpression,
|
|
10
|
+
isIdentifier,
|
|
11
|
+
isNewExpression,
|
|
12
|
+
isNullLiteral,
|
|
13
|
+
isNumericLiteral,
|
|
14
|
+
isObjectLiteralExpression,
|
|
15
|
+
isParenthesizedExpression as isParenthesizedExpression2,
|
|
16
|
+
isPropertyAccessExpression,
|
|
17
|
+
isPropertyAssignment,
|
|
18
|
+
isReturnStatement,
|
|
19
|
+
isShorthandPropertyAssignment,
|
|
20
|
+
isStringLiteral,
|
|
21
|
+
isTypeAssertion as isTypeAssertion2,
|
|
22
|
+
isVariableDeclaration
|
|
23
|
+
} from "@typescript/native/ast/is";
|
|
3
24
|
import {
|
|
4
25
|
$types
|
|
5
26
|
} from "@sdk-it/core";
|
|
6
27
|
|
|
7
28
|
// packages/hono/src/lib/constant-value.ts
|
|
8
|
-
import
|
|
29
|
+
import {
|
|
30
|
+
isAsExpression,
|
|
31
|
+
isParenthesizedExpression,
|
|
32
|
+
isTypeAssertion
|
|
33
|
+
} from "@typescript/native/ast/is";
|
|
9
34
|
function unwrapExpression(node) {
|
|
10
35
|
let current = node;
|
|
11
|
-
while (
|
|
12
|
-
|
|
13
|
-
current = current.expression;
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
if (ts.isTypeAssertionExpression(current)) {
|
|
17
|
-
current = current.expression;
|
|
18
|
-
continue;
|
|
19
|
-
}
|
|
20
|
-
if (ts.isParenthesizedExpression(current)) {
|
|
21
|
-
current = current.expression;
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
return current;
|
|
36
|
+
while (isAsExpression(current) || isTypeAssertion(current) || isParenthesizedExpression(current)) {
|
|
37
|
+
current = current.expression;
|
|
25
38
|
}
|
|
39
|
+
return current;
|
|
26
40
|
}
|
|
27
|
-
function
|
|
28
|
-
if (type.
|
|
41
|
+
function literalValue(type) {
|
|
42
|
+
if (type.isStringLiteralType() || type.isNumberLiteralType() || type.isBooleanLiteralType()) {
|
|
29
43
|
return type.value;
|
|
30
44
|
}
|
|
31
|
-
if (type.isNumberLiteral()) {
|
|
32
|
-
return type.value;
|
|
33
|
-
}
|
|
34
|
-
if (type.flags & ts.TypeFlags.BooleanLiteral) {
|
|
35
|
-
return checker.typeToString(type) === "true";
|
|
36
|
-
}
|
|
37
45
|
return void 0;
|
|
38
46
|
}
|
|
39
47
|
function getConstantValue(checker, expression) {
|
|
40
48
|
const unwrapped = unwrapExpression(expression);
|
|
41
|
-
const constant = checker.getConstantValue(
|
|
42
|
-
unwrapped
|
|
43
|
-
);
|
|
49
|
+
const constant = checker.getConstantValue(unwrapped);
|
|
44
50
|
if (constant !== void 0) {
|
|
45
51
|
return constant;
|
|
46
52
|
}
|
|
47
|
-
if (ts.isStringLiteral(unwrapped) || ts.isNoSubstitutionTemplateLiteral(unwrapped)) {
|
|
48
|
-
return unwrapped.text;
|
|
49
|
-
}
|
|
50
|
-
if (ts.isNumericLiteral(unwrapped)) {
|
|
51
|
-
return Number(unwrapped.text);
|
|
52
|
-
}
|
|
53
|
-
if (unwrapped.kind === ts.SyntaxKind.TrueKeyword) {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
if (unwrapped.kind === ts.SyntaxKind.FalseKeyword) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
53
|
const type = checker.getTypeAtLocation(unwrapped);
|
|
60
|
-
const literal =
|
|
54
|
+
const literal = literalValue(type);
|
|
61
55
|
if (literal !== void 0) {
|
|
62
56
|
return literal;
|
|
63
57
|
}
|
|
64
|
-
if (type.
|
|
58
|
+
if (type.isUnionType()) {
|
|
65
59
|
let resolved = void 0;
|
|
66
|
-
for (const entry of type.
|
|
67
|
-
const value =
|
|
60
|
+
for (const entry of type.getTypes()) {
|
|
61
|
+
const value = literalValue(entry);
|
|
68
62
|
if (value === void 0) {
|
|
69
63
|
return void 0;
|
|
70
64
|
}
|
|
@@ -80,32 +74,8 @@ function getConstantValue(checker, expression) {
|
|
|
80
74
|
}
|
|
81
75
|
|
|
82
76
|
// packages/hono/src/lib/response-analyzer.ts
|
|
83
|
-
var handlerVisitor = (callback, contextVarName) => {
|
|
84
|
-
return (node) => {
|
|
85
|
-
if (ts2.isReturnStatement(node) && node.expression) {
|
|
86
|
-
if (ts2.isCallExpression(node.expression)) {
|
|
87
|
-
if (ts2.isPropertyAccessExpression(node.expression.expression)) {
|
|
88
|
-
const propAccess = node.expression.expression;
|
|
89
|
-
if (ts2.isIdentifier(propAccess.expression) && propAccess.expression.text === contextVarName) {
|
|
90
|
-
const [body, statusCode, headers] = node.expression.arguments;
|
|
91
|
-
let contentType = "application/json";
|
|
92
|
-
const callerMethod = propAccess.name.text;
|
|
93
|
-
if (callerMethod === "body") {
|
|
94
|
-
contentType = "application/octet-stream";
|
|
95
|
-
}
|
|
96
|
-
if (!body) {
|
|
97
|
-
contentType = "empty";
|
|
98
|
-
}
|
|
99
|
-
callback(body, statusCode, headers, contentType);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return ts2.forEachChild(node, handlerVisitor(callback, contextVarName));
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
77
|
function resolveStatusCode(node) {
|
|
108
|
-
if (
|
|
78
|
+
if (isNumericLiteral(node)) {
|
|
109
79
|
return node.text;
|
|
110
80
|
}
|
|
111
81
|
throw new Error(`Could not resolve status code`);
|
|
@@ -117,15 +87,12 @@ function normalizeContentType(value) {
|
|
|
117
87
|
return value.split(";")[0]?.trim();
|
|
118
88
|
}
|
|
119
89
|
function getPropertyNameText(name, checker) {
|
|
120
|
-
if (
|
|
90
|
+
if (isIdentifier(name) || isStringLiteral(name) || isNumericLiteral(name)) {
|
|
121
91
|
return name.text;
|
|
122
92
|
}
|
|
123
|
-
if (
|
|
124
|
-
return name.text;
|
|
125
|
-
}
|
|
126
|
-
if (ts2.isComputedPropertyName(name)) {
|
|
93
|
+
if (isComputedPropertyName(name)) {
|
|
127
94
|
const expression = name.expression;
|
|
128
|
-
if (
|
|
95
|
+
if (isStringLiteral(expression) || isNumericLiteral(expression)) {
|
|
129
96
|
return expression.text;
|
|
130
97
|
}
|
|
131
98
|
const value = getConstantValue(checker, expression);
|
|
@@ -140,65 +107,60 @@ function resolveHeadersObject(headersNode, checker) {
|
|
|
140
107
|
return void 0;
|
|
141
108
|
}
|
|
142
109
|
const unwrapObjectLiteral = (expression) => {
|
|
143
|
-
if (
|
|
110
|
+
if (isObjectLiteralExpression(expression)) {
|
|
144
111
|
return expression;
|
|
145
112
|
}
|
|
146
|
-
if (
|
|
113
|
+
if (isParenthesizedExpression2(expression) && isObjectLiteralExpression(expression.expression)) {
|
|
147
114
|
return expression.expression;
|
|
148
115
|
}
|
|
149
116
|
return void 0;
|
|
150
117
|
};
|
|
151
|
-
if (
|
|
118
|
+
if (isObjectLiteralExpression(headersNode)) {
|
|
152
119
|
return headersNode;
|
|
153
120
|
}
|
|
154
|
-
if (
|
|
155
|
-
return resolveHeadersObject(headersNode.expression, checker);
|
|
156
|
-
}
|
|
157
|
-
if (ts2.isTypeAssertionExpression(headersNode)) {
|
|
121
|
+
if (isAsExpression2(headersNode) || isTypeAssertion2(headersNode) || isParenthesizedExpression2(headersNode)) {
|
|
158
122
|
return resolveHeadersObject(headersNode.expression, checker);
|
|
159
123
|
}
|
|
160
|
-
if (
|
|
161
|
-
return resolveHeadersObject(headersNode.expression, checker);
|
|
162
|
-
}
|
|
163
|
-
if (ts2.isNewExpression(headersNode)) {
|
|
124
|
+
if (isNewExpression(headersNode)) {
|
|
164
125
|
const exprName = headersNode.expression.getText();
|
|
165
126
|
if (exprName === "Headers") {
|
|
166
127
|
const [init] = headersNode.arguments ?? [];
|
|
167
128
|
return init ? resolveHeadersObject(init, checker) : void 0;
|
|
168
129
|
}
|
|
169
130
|
}
|
|
170
|
-
if (
|
|
131
|
+
if (isCallExpression(headersNode)) {
|
|
171
132
|
let callee = headersNode.expression;
|
|
172
|
-
if (
|
|
133
|
+
if (isParenthesizedExpression2(callee)) {
|
|
173
134
|
callee = callee.expression;
|
|
174
135
|
}
|
|
175
|
-
if (
|
|
176
|
-
if (
|
|
136
|
+
if (isArrowFunction(callee) || isFunctionExpression(callee)) {
|
|
137
|
+
if (isExpression(callee.body)) {
|
|
177
138
|
const bodyLiteral = unwrapObjectLiteral(callee.body);
|
|
178
139
|
if (bodyLiteral) {
|
|
179
140
|
return bodyLiteral;
|
|
180
141
|
}
|
|
181
142
|
}
|
|
182
|
-
if (
|
|
143
|
+
if (isBlock(callee.body)) {
|
|
183
144
|
for (const statement of callee.body.statements) {
|
|
184
|
-
|
|
185
|
-
|
|
145
|
+
const returned = isReturnStatement(statement) && statement.expression ? unwrapObjectLiteral(statement.expression) : void 0;
|
|
146
|
+
if (returned) {
|
|
147
|
+
return returned;
|
|
186
148
|
}
|
|
187
149
|
}
|
|
188
150
|
}
|
|
189
151
|
}
|
|
190
152
|
}
|
|
191
|
-
if (
|
|
153
|
+
if (isShorthandPropertyAssignment(headersNode)) {
|
|
192
154
|
const symbol = checker.getShorthandAssignmentValueSymbol(headersNode);
|
|
193
|
-
const decl = symbol?.valueDeclaration ?? symbol?.declarations
|
|
194
|
-
if (decl &&
|
|
155
|
+
const decl = (symbol?.valueDeclaration ?? symbol?.declarations[0])?.resolve();
|
|
156
|
+
if (decl && isVariableDeclaration(decl) && decl.initializer) {
|
|
195
157
|
return resolveHeadersObject(decl.initializer, checker);
|
|
196
158
|
}
|
|
197
159
|
}
|
|
198
|
-
if (
|
|
160
|
+
if (isIdentifier(headersNode)) {
|
|
199
161
|
const symbol = checker.getSymbolAtLocation(headersNode);
|
|
200
|
-
const decl = symbol?.valueDeclaration ?? symbol?.declarations
|
|
201
|
-
if (decl &&
|
|
162
|
+
const decl = (symbol?.valueDeclaration ?? symbol?.declarations[0])?.resolve();
|
|
163
|
+
if (decl && isVariableDeclaration(decl) && decl.initializer) {
|
|
202
164
|
return resolveHeadersObject(decl.initializer, checker);
|
|
203
165
|
}
|
|
204
166
|
}
|
|
@@ -210,7 +172,7 @@ function getHeaderValue(headersNode, headerName, checker) {
|
|
|
210
172
|
return void 0;
|
|
211
173
|
}
|
|
212
174
|
for (const prop of headersObject.properties) {
|
|
213
|
-
if (!
|
|
175
|
+
if (!isPropertyAssignment(prop)) {
|
|
214
176
|
continue;
|
|
215
177
|
}
|
|
216
178
|
const key = getPropertyNameText(prop.name, checker);
|
|
@@ -222,22 +184,6 @@ function getHeaderValue(headersNode, headerName, checker) {
|
|
|
222
184
|
}
|
|
223
185
|
return void 0;
|
|
224
186
|
}
|
|
225
|
-
function hasHeaderKey(headersNode, headerName, checker) {
|
|
226
|
-
const headersObject = resolveHeadersObject(headersNode, checker);
|
|
227
|
-
if (!headersObject) {
|
|
228
|
-
return false;
|
|
229
|
-
}
|
|
230
|
-
for (const prop of headersObject.properties) {
|
|
231
|
-
if (!ts2.isPropertyAssignment(prop)) {
|
|
232
|
-
continue;
|
|
233
|
-
}
|
|
234
|
-
const key = getPropertyNameText(prop.name, checker);
|
|
235
|
-
if (key && key.toLowerCase() === headerName.toLowerCase()) {
|
|
236
|
-
return true;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
187
|
function isJsonContentType(contentType) {
|
|
242
188
|
return contentType.endsWith("/json") || contentType.endsWith("+json");
|
|
243
189
|
}
|
|
@@ -254,45 +200,34 @@ function inferContentType(body, headers, defaultContentType, checker) {
|
|
|
254
200
|
if (headerContentType) {
|
|
255
201
|
return headerContentType;
|
|
256
202
|
}
|
|
257
|
-
if (hasHeaderKey(headers, "Content-Disposition", checker)) {
|
|
258
|
-
return "application/octet-stream";
|
|
259
|
-
}
|
|
260
203
|
return defaultContentType;
|
|
261
204
|
}
|
|
262
|
-
function getHeaderKeys(headersNode,
|
|
205
|
+
function getHeaderKeys(headersNode, checker) {
|
|
263
206
|
if (!headersNode) {
|
|
264
207
|
return [];
|
|
265
208
|
}
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
return Object.keys(deriver.serializeNode(resolved));
|
|
269
|
-
}
|
|
270
|
-
const type = deriver.checker.getTypeAtLocation(headersNode);
|
|
271
|
-
const names = deriver.checker.getPropertiesOfType(type).map((prop) => prop.name);
|
|
272
|
-
if (!names.length) {
|
|
273
|
-
return [];
|
|
274
|
-
}
|
|
275
|
-
const sorted = [...names].sort((a, b) => a.localeCompare(b));
|
|
276
|
-
return sorted.flatMap(
|
|
277
|
-
(name) => name.includes("-") ? [`'${name}'`, name] : [name]
|
|
209
|
+
const type = checker.getTypeAtLocation(
|
|
210
|
+
resolveHeadersObject(headersNode, checker) ?? headersNode
|
|
278
211
|
);
|
|
212
|
+
return checker.getPropertiesOfType(type).map((prop) => prop.name);
|
|
279
213
|
}
|
|
280
214
|
var newResponse = (_handler, deriver, node) => {
|
|
281
|
-
if (!
|
|
215
|
+
if (!isNewExpression(node)) {
|
|
282
216
|
return [];
|
|
283
217
|
}
|
|
284
218
|
const exprName = node.expression.getText();
|
|
285
219
|
if (exprName !== "Response") {
|
|
286
220
|
return [];
|
|
287
221
|
}
|
|
288
|
-
const [
|
|
222
|
+
const [argument, init] = node.arguments ?? [];
|
|
223
|
+
const body = argument && isNullLiteral(argument) ? void 0 : argument;
|
|
289
224
|
let statusNode;
|
|
290
225
|
let headersNode;
|
|
291
|
-
if (init &&
|
|
226
|
+
if (init && isObjectLiteralExpression(init)) {
|
|
292
227
|
for (const prop of init.properties) {
|
|
293
|
-
if (!
|
|
294
|
-
if (
|
|
295
|
-
const key2 = prop.name.
|
|
228
|
+
if (!isPropertyAssignment(prop)) {
|
|
229
|
+
if (isShorthandPropertyAssignment(prop)) {
|
|
230
|
+
const key2 = prop.name.getText();
|
|
296
231
|
if (key2 === "headers") {
|
|
297
232
|
headersNode = prop;
|
|
298
233
|
}
|
|
@@ -320,35 +255,55 @@ var newResponse = (_handler, deriver, node) => {
|
|
|
320
255
|
const shouldSerialize = !!body && (isJsonContentType(normalized) || isTextContentTypeValue(normalized));
|
|
321
256
|
return [
|
|
322
257
|
{
|
|
323
|
-
headers: getHeaderKeys(headersNode, deriver),
|
|
258
|
+
headers: getHeaderKeys(headersNode, deriver.checker),
|
|
324
259
|
contentType,
|
|
325
260
|
statusCode: statusNode ? resolveStatusCode(statusNode) : "200",
|
|
326
261
|
response: shouldSerialize ? deriver.serializeNode(body) : void 0
|
|
327
262
|
}
|
|
328
263
|
];
|
|
329
264
|
};
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
265
|
+
var rawBodyMethods = /* @__PURE__ */ new Set(["body", "newResponse"]);
|
|
266
|
+
var defaultMediaTypes = /* @__PURE__ */ new Map([
|
|
267
|
+
["json", "application/json"],
|
|
268
|
+
["text", "text/plain"],
|
|
269
|
+
["html", "text/html"]
|
|
270
|
+
]);
|
|
271
|
+
function defaultResponseAnalyzer(handler, deriver, returned) {
|
|
272
|
+
const [context] = handler.parameters;
|
|
273
|
+
if (!context || !isCallExpression(returned) || !isPropertyAccessExpression(returned.expression)) {
|
|
274
|
+
return [];
|
|
334
275
|
}
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
276
|
+
const method = returned.expression;
|
|
277
|
+
if (!isIdentifier(method.expression) || method.expression.text !== context.name.getText()) {
|
|
278
|
+
return [];
|
|
279
|
+
}
|
|
280
|
+
const [argument, statusCode, headers] = returned.arguments;
|
|
281
|
+
if (method.name.text === "redirect") {
|
|
282
|
+
return [
|
|
283
|
+
{
|
|
284
|
+
headers: ["Location"],
|
|
285
|
+
contentType: "empty",
|
|
286
|
+
statusCode: statusCode ? resolveStatusCode(statusCode) : "302",
|
|
287
|
+
response: void 0
|
|
288
|
+
}
|
|
289
|
+
];
|
|
290
|
+
}
|
|
291
|
+
const rawBody = rawBodyMethods.has(method.name.text);
|
|
292
|
+
const body = rawBody && argument && isNullLiteral(argument) ? void 0 : argument;
|
|
293
|
+
let sentAs = defaultMediaTypes.get(method.name.text) ?? "application/json";
|
|
294
|
+
if (!body) {
|
|
295
|
+
sentAs = "empty";
|
|
296
|
+
} else if (rawBody) {
|
|
297
|
+
sentAs = "application/octet-stream";
|
|
298
|
+
}
|
|
299
|
+
return [
|
|
300
|
+
{
|
|
301
|
+
headers: getHeaderKeys(headers, deriver.checker),
|
|
302
|
+
contentType: inferContentType(body, headers, sentAs, deriver.checker),
|
|
346
303
|
statusCode: statusCode ? resolveStatusCode(statusCode) : "200",
|
|
347
|
-
response:
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
visit(handler.body);
|
|
351
|
-
return responsesList;
|
|
304
|
+
response: body ? deriver.serializeNode(body) : void 0
|
|
305
|
+
}
|
|
306
|
+
];
|
|
352
307
|
}
|
|
353
308
|
function streamText(_handler, _deriver) {
|
|
354
309
|
return [
|
|
@@ -393,7 +348,7 @@ function streamSSE(_handler, _deriver) {
|
|
|
393
348
|
];
|
|
394
349
|
}
|
|
395
350
|
var httpException = (_handler, deriver, node) => {
|
|
396
|
-
if (
|
|
351
|
+
if (isNewExpression(node)) {
|
|
397
352
|
const [status, options] = node.arguments ?? [];
|
|
398
353
|
return [
|
|
399
354
|
{
|
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';\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": ";
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import type {\n Expression,\n Node,\n ObjectLiteralExpression,\n PropertyName,\n} from '@typescript/native/ast';\nimport {\n isArrowFunction,\n isAsExpression,\n isBlock,\n isCallExpression,\n isComputedPropertyName,\n isExpression,\n isFunctionExpression,\n isIdentifier,\n isNewExpression,\n isNullLiteral,\n isNumericLiteral,\n isObjectLiteralExpression,\n isParenthesizedExpression,\n isPropertyAccessExpression,\n isPropertyAssignment,\n isReturnStatement,\n isShorthandPropertyAssignment,\n isStringLiteral,\n isTypeAssertion,\n isVariableDeclaration,\n} from '@typescript/native/ast/is';\nimport type { Checker } from '@typescript/native/sync';\n\nimport {\n $types,\n type FunctionWithBody,\n type NaunceResponseAnalyzerFn,\n type ResponseItem,\n} from '@sdk-it/core';\nimport type { TypeDeriver } from '@sdk-it/core/deriver.js';\n\nimport { getConstantValue } from './constant-value.js';\n\nfunction resolveStatusCode(node: Node) {\n if (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: PropertyName,\n checker: Checker,\n): string | undefined {\n if (isIdentifier(name) || isStringLiteral(name) || isNumericLiteral(name)) {\n return name.text;\n }\n if (isComputedPropertyName(name)) {\n const expression = name.expression;\n if (isStringLiteral(expression) || 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: Node | undefined,\n checker: Checker,\n): ObjectLiteralExpression | undefined {\n if (!headersNode) {\n return undefined;\n }\n const unwrapObjectLiteral = (\n expression: Expression,\n ): ObjectLiteralExpression | undefined => {\n if (isObjectLiteralExpression(expression)) {\n return expression;\n }\n if (\n isParenthesizedExpression(expression) &&\n isObjectLiteralExpression(expression.expression)\n ) {\n return expression.expression;\n }\n return undefined;\n };\n if (isObjectLiteralExpression(headersNode)) {\n return headersNode;\n }\n if (\n isAsExpression(headersNode) ||\n isTypeAssertion(headersNode) ||\n isParenthesizedExpression(headersNode)\n ) {\n return resolveHeadersObject(headersNode.expression, checker);\n }\n if (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 (isCallExpression(headersNode)) {\n let callee: Expression = headersNode.expression;\n if (isParenthesizedExpression(callee)) {\n callee = callee.expression;\n }\n if (isArrowFunction(callee) || isFunctionExpression(callee)) {\n if (isExpression(callee.body)) {\n const bodyLiteral = unwrapObjectLiteral(callee.body);\n if (bodyLiteral) {\n return bodyLiteral;\n }\n }\n if (isBlock(callee.body)) {\n for (const statement of callee.body.statements) {\n const returned =\n isReturnStatement(statement) && statement.expression\n ? unwrapObjectLiteral(statement.expression)\n : undefined;\n if (returned) {\n return returned;\n }\n }\n }\n }\n }\n if (isShorthandPropertyAssignment(headersNode)) {\n const symbol = checker.getShorthandAssignmentValueSymbol(headersNode);\n const decl = (\n symbol?.valueDeclaration ?? symbol?.declarations[0]\n )?.resolve();\n if (decl && isVariableDeclaration(decl) && decl.initializer) {\n return resolveHeadersObject(decl.initializer, checker);\n }\n }\n if (isIdentifier(headersNode)) {\n const symbol = checker.getSymbolAtLocation(headersNode);\n const decl = (\n symbol?.valueDeclaration ?? symbol?.declarations[0]\n )?.resolve();\n if (decl && isVariableDeclaration(decl) && decl.initializer) {\n return resolveHeadersObject(decl.initializer, checker);\n }\n }\n return undefined;\n}\n\nfunction getHeaderValue(\n headersNode: Node | undefined,\n headerName: string,\n checker: Checker,\n) {\n const headersObject = resolveHeadersObject(headersNode, checker);\n if (!headersObject) {\n return undefined;\n }\n for (const prop of headersObject.properties) {\n if (!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 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: Node | undefined,\n headers: Node | undefined,\n defaultContentType: string,\n checker: Checker,\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 return defaultContentType;\n}\n\nfunction getHeaderKeys(headersNode: Node | undefined, checker: Checker) {\n if (!headersNode) {\n return [];\n }\n const type = checker.getTypeAtLocation(\n resolveHeadersObject(headersNode, checker) ?? headersNode,\n );\n return checker.getPropertiesOfType(type).map((prop) => prop.name);\n}\n\nexport const newResponse: NaunceResponseAnalyzerFn = (\n _handler,\n deriver,\n node,\n) => {\n if (!isNewExpression(node)) {\n return [];\n }\n const exprName = node.expression.getText();\n if (exprName !== 'Response') {\n return [];\n }\n const [argument, init] = node.arguments ?? [];\n // A body of null sends nothing, as for c.body(null) in defaultResponseAnalyzer.\n const body = argument && isNullLiteral(argument) ? undefined : argument;\n let statusNode: Node | undefined;\n let headersNode: Node | undefined;\n if (init && isObjectLiteralExpression(init)) {\n for (const prop of init.properties) {\n if (!isPropertyAssignment(prop)) {\n if (isShorthandPropertyAssignment(prop)) {\n const key = prop.name.getText();\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.checker),\n contentType,\n statusCode: statusNode ? resolveStatusCode(statusNode) : '200',\n response: shouldSerialize ? deriver.serializeNode(body) : undefined,\n },\n ];\n};\n\n/** The context methods that send their first argument as the raw body. */\nconst rawBodyMethods = new Set(['body', 'newResponse']);\n\n/** The media type each Hono context method sends when no Content-Type header is passed (hono/dist/context.js). */\nconst defaultMediaTypes = new Map([\n ['json', 'application/json'],\n ['text', 'text/plain'],\n ['html', 'text/html'],\n]);\n\n/** The response `returned`, a value the handler returns, sends when it is a call on the handler's context, such as `c.json(body, 201)`. */\nexport function defaultResponseAnalyzer(\n handler: FunctionWithBody,\n deriver: TypeDeriver,\n returned: Node,\n): ResponseItem[] {\n const [context] = handler.parameters;\n if (\n !context ||\n !isCallExpression(returned) ||\n !isPropertyAccessExpression(returned.expression)\n ) {\n return [];\n }\n const method = returned.expression;\n if (\n !isIdentifier(method.expression) ||\n method.expression.text !== context.name.getText()\n ) {\n return [];\n }\n const [argument, statusCode, headers] = returned.arguments;\n if (method.name.text === 'redirect') {\n // Hono's c.redirect(location, status = 302) sets Location and sends no body.\n return [\n {\n headers: ['Location'],\n contentType: 'empty',\n statusCode: statusCode ? resolveStatusCode(statusCode) : '302',\n response: undefined,\n },\n ];\n }\n const rawBody = rawBodyMethods.has(method.name.text);\n // A raw body of null sends nothing; c.json(null) still sends the JSON text null.\n // newResponse repeats this rule for new Response(null).\n const body =\n rawBody && argument && isNullLiteral(argument) ? undefined : argument;\n let sentAs = defaultMediaTypes.get(method.name.text) ?? 'application/json';\n if (!body) {\n sentAs = 'empty';\n } else if (rawBody) {\n sentAs = 'application/octet-stream';\n }\n return [\n {\n headers: getHeaderKeys(headers, deriver.checker),\n contentType: inferContentType(body, headers, sentAs, deriver.checker),\n statusCode: statusCode ? resolveStatusCode(statusCode) : '200',\n response: body ? deriver.serializeNode(body) : undefined,\n },\n ];\n}\n\nexport function streamText(\n _handler: FunctionWithBody,\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: FunctionWithBody,\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: FunctionWithBody,\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 (isNewExpression(node)) {\n const [status, options] = node.arguments ?? [];\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 type { Expression } from '@typescript/native/ast';\nimport {\n isAsExpression,\n isParenthesizedExpression,\n isTypeAssertion,\n} from '@typescript/native/ast/is';\nimport type { Checker, Type } from '@typescript/native/sync';\n\nfunction unwrapExpression(node: Expression): Expression {\n let current = node;\n while (\n isAsExpression(current) ||\n isTypeAssertion(current) ||\n isParenthesizedExpression(current)\n ) {\n current = current.expression;\n }\n return current;\n}\n\nfunction literalValue(type: Type): string | number | boolean | undefined {\n if (\n type.isStringLiteralType() ||\n type.isNumberLiteralType() ||\n type.isBooleanLiteralType()\n ) {\n return type.value;\n }\n return undefined;\n}\n\nexport function getConstantValue(\n checker: Checker,\n expression: Expression,\n): string | number | boolean | undefined {\n const unwrapped = unwrapExpression(expression);\n\n const constant = checker.getConstantValue(unwrapped);\n if (constant !== undefined) {\n return constant;\n }\n\n const type = checker.getTypeAtLocation(unwrapped);\n const literal = literalValue(type);\n if (literal !== undefined) {\n return literal;\n }\n if (type.isUnionType()) {\n let resolved: string | number | boolean | undefined = undefined;\n for (const entry of type.getTypes()) {\n const value = literalValue(entry);\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": ";AAMA;AAAA,EACE;AAAA,EACA,kBAAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,6BAAAC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,mBAAAC;AAAA,EACA;AAAA,OACK;AAGP;AAAA,EACE;AAAA,OAIK;;;AClCP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,iBAAiB,MAA8B;AACtD,MAAI,UAAU;AACd,SACE,eAAe,OAAO,KACtB,gBAAgB,OAAO,KACvB,0BAA0B,OAAO,GACjC;AACA,cAAU,QAAQ;AAAA,EACpB;AACA,SAAO;AACT;AAEA,SAAS,aAAa,MAAmD;AACvE,MACE,KAAK,oBAAoB,KACzB,KAAK,oBAAoB,KACzB,KAAK,qBAAqB,GAC1B;AACA,WAAO,KAAK;AAAA,EACd;AACA,SAAO;AACT;AAEO,SAAS,iBACd,SACA,YACuC;AACvC,QAAM,YAAY,iBAAiB,UAAU;AAE7C,QAAM,WAAW,QAAQ,iBAAiB,SAAS;AACnD,MAAI,aAAa,QAAW;AAC1B,WAAO;AAAA,EACT;AAEA,QAA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AAM,mBAAmB;AAAA,EAC9B,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EACA,gBAAgB;AAAA,EAChB,2BAA2B;AAC7B;",
|
|
6
|
+
"names": ["isAsExpression", "isParenthesizedExpression", "isTypeAssertion", "isParenthesizedExpression", "isAsExpression", "isTypeAssertion", "key"]
|
|
7
7
|
}
|