Skip to content

Commit

Permalink
🎉 feat: exp.35
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyAom committed Nov 15, 2024
1 parent a385ff9 commit d73069a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 14 deletions.
16 changes: 14 additions & 2 deletions example/a.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ const a = new Elysia()
a: t.Ref('a')
}),
})
.get('/', ({ body: { a: { a: { a } } } }) => a, {
body: 'a'
.model((model) => ({
...model,
b: t.Object({
a: model.a,
b: t.Ref('b')
})
}))
.get('/', () => 'a', {
query: t.Object({
a: t.String()
})
})
.listen(3000)

a._routes.index.get.response
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "elysia",
"description": "Ergonomic Framework for Human",
"version": "1.2.0-exp.35",
"version": "1.2.0-exp.36",
"author": {
"name": "saltyAom",
"url": "https://github.com/SaltyAom",
Expand Down
2 changes: 1 addition & 1 deletion src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export class ValidationError extends Error {
{
type: 'validation',
on: type,
summary: errors[0]?.summary,
summary: mapValueError(error).summary,
property: accessor,
message: error?.message,
expected,
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3859,7 +3859,7 @@ export default class Elysia<
query: Schema['query']
headers: Schema['headers']
response: ComposeElysiaResponse<
Schema['response'],
Schema,
Handle
>
}
Expand Down
40 changes: 31 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type { ComposerGeneralHandlerOptions } from './compose'
import type { ElysiaAdapter } from './adapter'
import type { WSLocalHook } from './ws/types'
import type { WebSocketHandler } from './ws/bun'
import { TypeRegistryValidationFunction } from '@sinclair/typebox/build/cjs/type/registry/type'

type PartialServe = Partial<Serve>

Expand Down Expand Up @@ -616,8 +617,8 @@ export type InlineHandler<
>
}
? key
: never]: // @ts-expect-error type is checked in key mapping
ResolveResolutions<
: never]: ResolveResolutions<
// @ts-expect-error type is checked in key mapping
// @ts-expect-error type is checked in key mapping
ReturnType<MacroFn[key]>['resolve']
>[key]
Expand Down Expand Up @@ -1430,18 +1431,39 @@ export type CreateEden<
? _CreateEden<'index', Property>
: _CreateEden<Path, Property>

export type ComposeElysiaResponse<Response, Handle> = Handle extends (
...a: any[]
) => infer A
? _ComposeElysiaResponse<Response, Replace<Awaited<A>, BunFile, File>>
: _ComposeElysiaResponse<Response, Replace<Awaited<Handle>, BunFile, File>>
export type ComposeElysiaResponse<
Schema extends RouteSchema,
Handle
> = Handle extends (...a: any[]) => infer A
? _ComposeElysiaResponse<Schema, Replace<Awaited<A>, BunFile, File>>
: _ComposeElysiaResponse<Schema, Replace<Awaited<Handle>, BunFile, File>>

export type EmptyRouteSchema = {
body: unknown
headers: unknown
query: unknown
params: unknown
cookie: unknown
response: {}
}

type _ComposeElysiaResponse<Response, Handle> = Prettify<
type _ComposeElysiaResponse<Schema extends RouteSchema, Handle> = Prettify<
Prettify<
{
200: Exclude<Handle, ElysiaCustomStatusResponse<any, any, any>>
} & ExtractErrorFromHandle<Handle> &
({} extends Response ? {} : Omit<Response, 200>)
({} extends Schema['response']
? {}
: Omit<Schema['response'], 200>) &
(EmptyRouteSchema extends Schema ? {} : { 422: {
type: 'validation'
on: string
summary?: string
message?: string
found?: unknown
property?: string
expected?: string
} })
>
>

Expand Down

0 comments on commit d73069a

Please sign in to comment.