Skip to content

Commit 55c8ca2

Browse files
committed
🎉 feat: beta.2
1 parent ae9eee4 commit 55c8ca2

File tree

10 files changed

+131
-123
lines changed

10 files changed

+131
-123
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# 0.2.0-beta.2 - 22 Jan 2023
2+
Feature:
3+
- Add support for custom openapi field using `schema.detail`
4+
- Add support for custom code for `response`
5+
6+
Improvement:
7+
- Unioned status type for response
8+
- Optimize TypeScript inference performance
9+
110
# 0.2.0-beta.1 - 22 Jan 2023
211
Breaking Change:
312
- `onParse` now accepts `(context: PreContext, contentType: string)` instead of `(request: Request, contentType: string)`

bun.lockb

376 Bytes
Binary file not shown.

example/a.html

Lines changed: 0 additions & 11 deletions
This file was deleted.

example/a.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

example/body.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Elysia, t } from '../src'
22

33
const app = new Elysia()
44
// Add custom body parser
5-
.onParse(async (request, contentType) => {
5+
.onParse(async ({ request }, contentType) => {
66
switch (contentType) {
77
case 'application/Elysia':
88
return request.text()
@@ -25,7 +25,10 @@ const app = new Elysia()
2525
body: t.Object({
2626
id: t.Number(),
2727
username: t.String()
28-
})
28+
}),
29+
detail: {
30+
summary: 'A'
31+
}
2932
}
3033
})
3134
.post('/mirror', ({ body }) => body)

example/schema.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Elysia, t } from '../src'
1+
import { Elysia, t, SCHEMA } from '../src'
22

33
const app = new Elysia()
44
// Strictly validate response
@@ -16,8 +16,10 @@ const app = new Elysia()
1616
profile: t.Object({
1717
name: t.String()
1818
})
19-
}),
20-
response: t.Number()
19+
})
20+
// response: {
21+
// 200: t.Number()
22+
// }
2123
}
2224
})
2325
// Strictly validate query, params, and body
@@ -28,7 +30,13 @@ const app = new Elysia()
2830
}),
2931
params: t.Object({
3032
id: t.String()
31-
})
33+
}),
34+
response: {
35+
200: t.String(),
36+
300: t.Object({
37+
error: t.String()
38+
})
39+
}
3240
}
3341
})
3442
.guard(
@@ -53,7 +61,7 @@ const app = new Elysia()
5361
schema: {
5462
params: t.Object({
5563
id: t.Number()
56-
}),
64+
})
5765
},
5866
transform: ({ params }) => {
5967
params.id = +params.id
@@ -62,3 +70,5 @@ const app = new Elysia()
6270
)
6371
)
6472
.listen(8080)
73+
74+
type A = typeof app['store'][typeof SCHEMA]['/query/:id']['GET']['query']

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "elysia",
33
"description": "Fast, and friendly Bun web framework",
4-
"version": "0.2.0-beta.1",
4+
"version": "0.2.0-beta.2",
55
"author": {
66
"name": "saltyAom",
77
"url": "https://github.com/SaltyAom",
@@ -35,7 +35,8 @@
3535
"release": "npm run build && npm run test && npm publish"
3636
},
3737
"dependencies": {
38-
"@sinclair/typebox": "0.25.10"
38+
"@sinclair/typebox": "0.25.10",
39+
"openapi-types": "^12.1.0"
3940
},
4041
"devDependencies": {
4142
"@types/node": "^18.11.10",

src/index.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
9494
constructor(config: Partial<ElysiaConfig> = {}) {
9595
this.config = {
9696
strictPath: false,
97-
queryLimit: 48,
9897
...config
9998
}
10099
}
@@ -640,7 +639,7 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
640639
* ```
641640
*/
642641
get<
643-
Schema extends TypedSchema = {},
642+
Schema extends TypedSchema = TypedSchema,
644643
Path extends string = string,
645644
Response = unknown
646645
>(
@@ -1117,7 +1116,9 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
11171116
headers: getSchemaValidator(schema?.headers),
11181117
params: getSchemaValidator(schema?.params),
11191118
query: getSchemaValidator(schema?.query),
1120-
response: getSchemaValidator(schema?.response)
1119+
response: getSchemaValidator(
1120+
schema?.response?.['200'] ?? schema.response
1121+
)
11211122
}
11221123

11231124
return this as unknown as NewInstance
@@ -1422,15 +1423,14 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
14221423
}
14231424
}
14241425

1425-
export { Elysia }
1426+
export { Elysia, Router }
14261427
export { Type as t } from '@sinclair/typebox'
14271428
export {
14281429
SCHEMA,
14291430
getPath,
14301431
createValidationError,
14311432
getSchemaValidator
14321433
} from './utils'
1433-
export { Router } from './router'
14341434

14351435
export type { Context, PreContext } from './context'
14361436
export type {
@@ -1460,5 +1460,14 @@ export type {
14601460
VoidLifeCycle,
14611461
SchemaValidator,
14621462
ElysiaRoute,
1463-
ExtractPath
1463+
ExtractPath,
1464+
IsPathParameter,
1465+
IsAny,
1466+
IsNever,
1467+
UnknownFallback,
1468+
WithArray,
1469+
ObjectValues,
1470+
PickInOrder,
1471+
MaybePromise,
1472+
MergeIfNotNull
14641473
} from './types'

src/schema.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { TSchema } from '@sinclair/typebox'
2+
import type { OpenAPIV2 } from 'openapi-types'
23

34
import type { HTTPMethod, LocalHook } from './types'
45

@@ -23,10 +24,10 @@ export const registerSchemaPath = ({
2324
method,
2425
hook
2526
}: {
26-
schema: Record<string, Object>
27+
schema: OpenAPIV2.PathsObject
2728
path: string
2829
method: HTTPMethod
29-
hook?: LocalHook<any>
30+
hook?: LocalHook
3031
}) => {
3132
path = toOpenAPIPath(path)
3233

@@ -35,6 +36,7 @@ export const registerSchemaPath = ({
3536
const headerSchema = hook?.schema?.headers
3637
const querySchema = hook?.schema?.query
3738
const responseSchema = hook?.schema?.response
39+
const detail = hook?.schema?.detail
3840

3941
const parameters = [
4042
...mapProperties('header', headerSchema),
@@ -66,7 +68,8 @@ export const registerSchemaPath = ({
6668
}
6769
}
6870
}
69-
: {})
71+
: {}),
72+
...detail
7073
}
7174
}
7275
}

0 commit comments

Comments
 (0)