-
-
Notifications
You must be signed in to change notification settings - Fork 511
Elysia 1.4: Weirs #1398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Elysia 1.4: Weirs #1398
Changes from all commits
169cbfe
1763ce3
112368a
925a337
2398100
6b683a6
1a29660
c51af45
7b64087
da8119a
d4c2d2d
b94394c
56b8b48
a709a22
761292d
03891e6
a43a607
1fabcd3
96a8b13
7eae435
0ece58a
52aa1c3
36b3417
0cc6c50
2a5b0cc
b869231
5129359
bffe687
990cd32
a1166b7
e87b550
4561eda
ea8ef46
3f51556
7fd26d6
520230b
2baa6b8
249fab1
63da7e8
d28b24a
b3b96c0
50cc8f6
7034649
823015c
5e5106d
834fb2b
6853c28
e331830
a6e7fb3
f828f95
f406bb6
864d91c
aad5fb0
bddfd22
a82b139
617e277
7d9fc87
015e227
ff6cb5a
41f02fe
5706380
0ecf51b
aa1b80f
4002f1a
ac4b961
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,16 @@ | ||
| import { Elysia, t } from '../src' | ||
| import { req } from '../test/utils' | ||
| import { Elysia, t } from 'elysia' | ||
|
|
||
| const app = new Elysia() | ||
| .get('/', () => 'SAFE', { | ||
| query: t.Record(t.String(), t.String()) | ||
| }) | ||
|
|
||
| const response = await app.handle(req('/?x=1')) | ||
|
|
||
| console.log(response.status) | ||
| new Elysia().group( | ||
| '/id/:id', | ||
| { | ||
| params: t.Object({ | ||
| id: t.Number() | ||
| }) | ||
| }, | ||
| (app) => | ||
| app.get('/:name', ({ params }) => params, { | ||
| params: t.Object({ | ||
| name: t.String() | ||
| }) | ||
| }) | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { Elysia, t } from '../src' | ||
| import { openapi as OpenAPI } from '@elysiajs/openapi' | ||
| import { fromTypes } from '@elysiajs/openapi/gen' | ||
|
|
||
| const openapi = (a: any) => | ||
| new Elysia().use((app) => { | ||
| app.use( | ||
| // @ts-ignore | ||
| OpenAPI(a) | ||
| ) | ||
|
|
||
| return app | ||
| }) | ||
|
|
||
| // Elysia 1.4: lifecycle event type soundness | ||
| export const app = new Elysia() | ||
| .use( | ||
| openapi({ | ||
| references: fromTypes('example/openapi.ts') | ||
| }) | ||
| ) | ||
| .macro({ | ||
| auth: { | ||
| response: { | ||
| 409: t.Literal('Conflict') | ||
| }, | ||
| beforeHandle({ status }) { | ||
| if (Math.random() < 0.05) return status(410) | ||
| }, | ||
| resolve: () => ({ a: 'a' }) | ||
| } | ||
| }) | ||
| .onError(({ status }) => { | ||
| if (Math.random() < 0.05) return status(400) | ||
| }) | ||
| .resolve(({ status }) => { | ||
| if (Math.random() < 0.05) return status(401) | ||
| }) | ||
| .onBeforeHandle([ | ||
| ({ status }) => { | ||
| if (Math.random() < 0.05) return status(402) | ||
| }, | ||
| ({ status }) => { | ||
| if (Math.random() < 0.05) return status(403) | ||
| } | ||
| ]) | ||
| .guard({ | ||
| beforeHandle: [ | ||
| ({ status }) => { | ||
| if (Math.random() < 0.05) return status(405) | ||
| }, | ||
| ({ status }) => { | ||
| if (Math.random() < 0.05) return status(406) | ||
| } | ||
| ], | ||
| afterHandle({ status }) { | ||
| if (Math.random() < 0.05) return status(407) | ||
| }, | ||
| error({ status }) { | ||
| if (Math.random() < 0.05) return status(408) | ||
| } | ||
| }) | ||
| .post( | ||
| '/', | ||
| ({ status }) => | ||
| Math.random() < 0.05 ? status(409, 'Conflict') : 'Type Soundness', | ||
| { | ||
| auth: true, | ||
| response: { | ||
| 411: t.Literal('Length Required') | ||
| } | ||
| } | ||
| ) | ||
| .listen(3000) | ||
|
|
||
| // app['~Routes']['post']['response'] | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,7 @@ | ||||||
| { | ||||||
| "name": "elysia", | ||||||
| "description": "Ergonomic Framework for Human", | ||||||
| "version": "1.3.21", | ||||||
| "version": "1.4.0", | ||||||
| "author": { | ||||||
| "name": "saltyAom", | ||||||
| "url": "https://github.com/SaltyAom", | ||||||
|
|
@@ -184,35 +184,38 @@ | |||||
| }, | ||||||
| "dependencies": { | ||||||
| "cookie": "^1.0.2", | ||||||
| "exact-mirror": "0.1.6", | ||||||
| "exact-mirror": "0.2.2", | ||||||
| "fast-decode-uri-component": "^1.0.1" | ||||||
| }, | ||||||
| "devDependencies": { | ||||||
| "@elysiajs/openapi": "^1.3.11", | ||||||
| "@types/bun": "^1.2.16", | ||||||
| "@types/cookie": "^1.0.0", | ||||||
| "@types/fast-decode-uri-component": "^1.0.0", | ||||||
| "@typescript-eslint/eslint-plugin": "^8.30.1", | ||||||
| "@typescript-eslint/parser": "^8.30.1", | ||||||
| "arktype": "^2.1.22", | ||||||
| "eslint": "^9.24.0", | ||||||
| "eslint-plugin-security": "^3.0.1", | ||||||
| "eslint-plugin-sonarjs": "^3.0.2", | ||||||
| "expect-type": "^1.2.1", | ||||||
| "file-type": "^20.4.1", | ||||||
| "memoirist": "^0.4.0", | ||||||
| "mitata": "^1.0.34", | ||||||
| "prettier": "^3.5.3", | ||||||
| "tsup": "^8.4.0", | ||||||
| "typescript": "^5.8.3" | ||||||
| "typescript": "^5.8.3", | ||||||
| "valibot": "^1.1.0", | ||||||
| "zod": "^4.1.5" | ||||||
| }, | ||||||
| "peerDependencies": { | ||||||
| "@sinclair/typebox": ">= 0.34.0", | ||||||
| "@sinclair/typebox": ">= 0.34.0 < 1", | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion TypeBox range too broad for 0.x (minors can be breaking) Widening to - "@sinclair/typebox": ">= 0.34.0 < 1",
+ "@sinclair/typebox": ">= 0.34.0 < 0.35",📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| "exact-mirror": ">= 0.0.9", | ||||||
| "file-type": ">= 20.0.0", | ||||||
| "openapi-types": ">= 12.0.0", | ||||||
| "typescript": ">= 5.0.0" | ||||||
| }, | ||||||
| "optionalDependencies": { | ||||||
| "@sinclair/typebox": "^0.34.33", | ||||||
| "openapi-types": "^12.1.3" | ||||||
| "@sinclair/typebox": ">= 0.34.0 < 1", | ||||||
| "openapi-types": ">= 12.0.0" | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Don’t start a server on import
Top-level
listen(3000)creates side effects (eg, during tooling or type extraction). Gate it behind a main check.📝 Committable suggestion
🤖 Prompt for AI Agents