From 8b269257ca46c5d55cb192765758105064b080f8 Mon Sep 17 00:00:00 2001 From: saltyaom Date: Mon, 18 Mar 2024 21:03:15 +0700 Subject: [PATCH] :tada: release: 1.0.4 --- CHANGELOG.md | 4 ++++ example/a.ts | 8 +++---- package.json | 2 +- src/compose.ts | 11 +++++++++- src/index.ts | 58 +++++++++++++++++++++++++++++++++++++++++++------- 5 files changed, 68 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e56c83e..89cadde8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/example/a.ts b/example/a.ts index 6d0e8f4d..aaa45264 100644 --- a/example/a.ts +++ b/example/a.ts @@ -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()) diff --git a/package.json b/package.json index 74e59612..74c089e1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/compose.ts b/src/compose.ts index 85745594..22881c9c 100644 --- a/src/compose.ts +++ b/src/compose.ts @@ -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 @@ -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' diff --git a/src/index.ts b/src/index.ts index 10d43a38..afdfc675 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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: {} @@ -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 + resolve: Ephemeral['resolve'] & + Partial + } + : { + derive: Ephemeral['derive'] & + Volatile['derive'] + resolve: Ephemeral['resolve'] & + Volatile['resolve'] + }), BasePath > > @@ -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 + resolve: Ephemeral['resolve'] & + Partial + } + : { + derive: Ephemeral['derive'] & + Volatile['derive'] + resolve: Ephemeral['resolve'] & + Volatile['resolve'] + }), BasePath > >