Skip to content

Commit

Permalink
🎉 release: 1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyAom committed Mar 18, 2024
1 parent bdde62b commit 8b26925
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.4 - 18 Mar 2024
Improvement:
- resolve, derive soundness

# 1.0.3 - 18 Mar 2024
Improvement:
- Reduce instruction for static resource
Expand Down
8 changes: 3 additions & 5 deletions example/a.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Elysia, error, t } from '../src'
import { req } from '../test/utils'

const app = new Elysia({ precompile: true })
.headers({
a: 'hello'
})
.get('/', 'a')
.get('/', 'hi')
.listen(3000)

console.log(app.routes[0].composed?.toString())
console.log(app.fetch.toString())
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.0.3",
"version": "1.0.4",
"author": {
"name": "saltyAom",
"url": "https://github.com/SaltyAom",
Expand Down
11 changes: 10 additions & 1 deletion src/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ export const composeHandler = ({
hooks.type !== 'none' &&
(inference.body || !!validator.body)

// @ts-expect-error private
const defaultHeaders = app.setHeaders
const hasDefaultHeaders =
defaultHeaders && !!Object.keys(defaultHeaders).length

// ? defaultHeaders doesn't imply that user will use headers in handler
const hasHeaders = inference.headers || validator.headers
const hasCookie = inference.cookie || !!validator.cookie
Expand Down Expand Up @@ -556,7 +561,11 @@ export const composeHandler = ({

const hasTraceSet = traceInference.set
const hasSet =
inference.cookie || inference.set || hasTraceSet || hasHeaders
inference.cookie ||
inference.set ||
hasTraceSet ||
hasHeaders ||
(isHandleFn && hasDefaultHeaders)

if (hasTrace) fnLiteral += '\nconst id = c.$$requestId\n'

Expand Down
58 changes: 50 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,13 @@ export default class Elysia<
macro: {}
},
const out Routes extends RouteBase = {},
// ? scoped
const in out Ephemeral extends EphemeralType = {
derive: {}
resolve: {}
schema: {}
},
// ? local
const in out Volatile extends EphemeralType = {
derive: {}
resolve: {}
Expand Down Expand Up @@ -978,10 +980,30 @@ export default class Elysia<
Metadata['schema'] &
Ephemeral['schema'] &
Volatile['schema'],
Singleton & {
derive: Ephemeral['derive'] & Volatile['derive']
resolve: Ephemeral['resolve'] & Volatile['resolve']
},
Singleton &
('global' extends Type
? {
derive: Partial<
Ephemeral['derive'] & Volatile['derive']
>
resolve: Partial<
Ephemeral['resolve'] &
Volatile['resolve']
>
}
: 'scoped' extends Type
? {
derive: Ephemeral['derive'] &
Partial<Volatile['derive']>
resolve: Ephemeral['resolve'] &
Partial<Volatile['resolve']>
}
: {
derive: Ephemeral['derive'] &
Volatile['derive']
resolve: Ephemeral['resolve'] &
Volatile['resolve']
}),
BasePath
>
>
Expand Down Expand Up @@ -4619,10 +4641,30 @@ export default class Elysia<
Metadata['schema'] &
Ephemeral['schema'] &
Volatile['schema'],
Singleton & {
derive: Ephemeral['derive'] & Volatile['derive']
resolve: Ephemeral['resolve'] & Volatile['resolve']
},
Singleton &
('global' extends Type
? {
derive: Partial<
Ephemeral['derive'] & Volatile['derive']
>
resolve: Partial<
Ephemeral['resolve'] &
Volatile['resolve']
>
}
: 'scoped' extends Type
? {
derive: Ephemeral['derive'] &
Partial<Volatile['derive']>
resolve: Ephemeral['resolve'] &
Partial<Volatile['resolve']>
}
: {
derive: Ephemeral['derive'] &
Volatile['derive']
resolve: Ephemeral['resolve'] &
Volatile['resolve']
}),
BasePath
>
>
Expand Down

0 comments on commit 8b26925

Please sign in to comment.