Skip to content

Commit

Permalink
🧹 chore: remove decode from aot
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyAom committed Sep 20, 2023
1 parent fd6524d commit dd56e0a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 52 deletions.
27 changes: 5 additions & 22 deletions example/a.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,9 @@ import { post } from '../test/utils'
const app = new Elysia({
aot: false
})
.get(
'/update',
({ cookie: { name } }) => {
name.value = 'Himari'

return name.value
},
{
cookie: t.Cookie(
{
name: t.Optional(t.String())
},
{
secrets: 'Fischl',
sign: ['name']
}
),
error() {
console.log("A")
}
}
)
.get('/id/:id', ({ params: { id } }) => typeof id, {
params: t.Object({
id: t.Numeric()
})
})
.listen(3000)
32 changes: 2 additions & 30 deletions src/dynamic-handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import { mapEarlyResponse, mapResponse } from './handler'
import { ElysiaErrors, NotFoundError, ValidationError } from './error'

import type { Context } from './context'
import type { Handler, LifeCycleStore, SchemaValidator } from './types'

import { parse as parseQuery } from 'fast-querystring'
import { TypeCheck } from '@sinclair/typebox/compiler'
import { TObject } from '@sinclair/typebox'

import { sign as signCookie } from 'cookie-signature'
import { parseCookie } from './cookie'

import type { Handler, LifeCycleStore, SchemaValidator } from './types'

// JIT Handler
export type DynamicHandler = {
handle: Handler<any, any>
Expand Down Expand Up @@ -205,33 +204,6 @@ export const createDynamicHandler =
: undefined
)

if (body && validator?.body?.Decode)
context.body = (validator.body as TypeCheck<TObject>).Decode(
body
) as any

if (context.query && validator?.query?.Decode)
context.query = (validator.query as TypeCheck<TObject>).Decode(
context.query
) as any

if (context.params && validator?.params?.Decode)
// @ts-ignore
context.params = (
validator.params as TypeCheck<TObject>
).Decode(context.params) as any

if (context.cookie && validator?.cookie?.Decode)
// @ts-ignore
context.cookie = (
validator.cookie as TypeCheck<TObject>
).Decode(context.cookie) as any

if (context.headers && validator?.headers?.Decode)
context.headers = (
validator.headers as TypeCheck<TObject>
).Decode(context.headers) as any

for (let i = 0; i < hooks.transform.length; i++) {
const operation = hooks.transform[i](context)

Expand Down

0 comments on commit dd56e0a

Please sign in to comment.