Skip to content

Commit d589e5c

Browse files
committed
🎉 release: 1.2
1 parent 9c6571e commit d589e5c

File tree

5 files changed

+41
-58
lines changed

5 files changed

+41
-58
lines changed

example/a.ts

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,20 @@
11
import { Elysia, t } from '../src'
22

3-
const app = new Elysia()
4-
.onParse('custom', ({ contentType, request }) => {
5-
if (contentType.startsWith('application/x-elysia-1'))
6-
return { name: 'Eden' }
7-
})
8-
.onParse('custom2', ({ contentType, request }) => {
9-
if (contentType.startsWith('application/x-elysia-2'))
10-
return { name: 'Pardofelis' }
11-
})
12-
.post('/json', ({ body }) => body, {
13-
parse: ['custom']
14-
})
3+
export const auth = new Elysia().macro({
4+
isAuth(isAuth: boolean) {
5+
return {
6+
resolve() {
7+
return {
8+
user: 'saltyaom'
9+
}
10+
}
11+
}
12+
},
13+
role(role: 'admin' | 'user') {
14+
return {}
15+
}
16+
})
1517

16-
const response = await Promise.all([
17-
app
18-
.handle(
19-
new Request('http://localhost:3000/json', {
20-
method: 'POST',
21-
headers: {
22-
'content-type': 'application/json'
23-
},
24-
body: JSON.stringify({ name: 'Aru' })
25-
})
26-
)
27-
.then((x) => x.json()),
28-
app
29-
.handle(
30-
new Request('http://localhost:3000/json', {
31-
method: 'POST',
32-
headers: {
33-
'content-type': 'application/x-elysia-1'
34-
},
35-
body: JSON.stringify({ name: 'Aru' })
36-
})
37-
)
38-
.then((x) => x.text()),
39-
app
40-
.handle(
41-
new Request('http://localhost:3000/json', {
42-
method: 'POST',
43-
headers: {
44-
'content-type': 'application/x-elysia-2'
45-
},
46-
body: JSON.stringify({ name: 'Aru' })
47-
})
48-
)
49-
.then((x) => x.text())
50-
])
51-
52-
console.log(response)
18+
new Elysia().ws('/ws', {
19+
ping: (message) => message
20+
})

package.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "elysia",
33
"description": "Ergonomic Framework for Human",
4-
"version": "1.2.0-rc.0",
4+
"version": "1.2.0",
55
"author": {
66
"name": "saltyAom",
77
"url": "https://github.com/SaltyAom",
@@ -118,6 +118,11 @@
118118
"import": "./dist/universal/server.mjs",
119119
"require": "./dist/cjs/universal/server.js"
120120
},
121+
"./universal/env": {
122+
"types": "./dist/universal/env.d.ts",
123+
"import": "./dist/universal/env.mjs",
124+
"require": "./dist/cjs/universal/env.js"
125+
},
121126
"./universal/file": {
122127
"types": "./dist/universal/file.d.ts",
123128
"import": "./dist/universal/file.mjs",
@@ -148,8 +153,8 @@
148153
"release": "npm run build && npm run test && npm publish"
149154
},
150155
"dependencies": {
151-
"@sinclair/typebox": "^0.34.7",
152-
"cookie": "^1.0.1",
156+
"@sinclair/typebox": "^0.34.13",
157+
"cookie": "^1.0.2",
153158
"fast-decode-uri-component": "^1.0.1",
154159
"memoirist": "^0.2.0",
155160
"openapi-types": "^12.1.3"
@@ -166,8 +171,8 @@
166171
"eslint-plugin-sonarjs": "^0.23.0",
167172
"expect-type": "^0.16.0",
168173
"prettier": "^3.3.3",
169-
"tsup": "^8.3.0",
170-
"typescript": "^5.5.2"
174+
"tsup": "^8.3.5",
175+
"typescript": "^5.7.2"
171176
},
172177
"peerDependencies": {
173178
"@sinclair/typebox": ">= 0.34.0",

src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { BunAdapter } from './adapter/bun/index'
1919
import { WebStandardAdapter } from './adapter/web-standard/index'
2020
import type { ElysiaAdapter } from './adapter/types'
2121

22+
import { env } from './universal/env'
2223
import type { ListenCallback, Serve, Server } from './universal/server'
2324

2425
import {
@@ -348,15 +349,15 @@ export default class Elysia<
348349

349350
'~adapter': ElysiaAdapter
350351

351-
env(model: TObject<any>, env = Bun?.env ?? process.env) {
352+
env(model: TObject<any>, _env = env) {
352353
const validator = getSchemaValidator(model, {
353354
dynamic: true,
354355
additionalProperties: true,
355356
coerce: true
356357
})
357358

358-
if (validator.Check(env) === false) {
359-
const error = new ValidationError('env', model, env)
359+
if (validator.Check(_env) === false) {
360+
const error = new ValidationError('env', model, _env)
360361

361362
throw new Error(error.all.map((x) => x.summary).join('\n'))
362363
}
@@ -429,7 +430,7 @@ export default class Elysia<
429430
applyConfig(config: ElysiaConfig<BasePath>) {
430431
this.config = {
431432
prefix: '',
432-
aot: process.env.ELYSIA_AOT !== 'false',
433+
aot: env.ELYSIA_AOT !== 'false',
433434
normalize: true,
434435
...config,
435436
cookie: {
@@ -6168,6 +6169,7 @@ export type {
61686169
CoExist
61696170
} from './types'
61706171

6172+
export { env } from './universal/env'
61716173
export { file, ElysiaFile } from './universal/file'
61726174
export type { ElysiaAdapter } from './adapter'
61736175

src/universal/env.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { isBun } from './utils'
2+
3+
export const env = isBun
4+
? Bun.env
5+
: typeof process !== 'undefined' && process?.env
6+
? process.env
7+
: {}

src/universal/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export { env } from './env'
12
export { file } from './file'
23
export type {
34
ErrorLike,

0 commit comments

Comments
 (0)