Skip to content

Commit

Permalink
🎉 release: 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyAom committed Dec 23, 2024
1 parent 9c6571e commit d589e5c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 58 deletions.
66 changes: 17 additions & 49 deletions example/a.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,20 @@
import { Elysia, t } from '../src'

const app = new Elysia()
.onParse('custom', ({ contentType, request }) => {
if (contentType.startsWith('application/x-elysia-1'))
return { name: 'Eden' }
})
.onParse('custom2', ({ contentType, request }) => {
if (contentType.startsWith('application/x-elysia-2'))
return { name: 'Pardofelis' }
})
.post('/json', ({ body }) => body, {
parse: ['custom']
})
export const auth = new Elysia().macro({
isAuth(isAuth: boolean) {
return {
resolve() {
return {
user: 'saltyaom'
}
}
}
},
role(role: 'admin' | 'user') {
return {}
}
})

const response = await Promise.all([
app
.handle(
new Request('http://localhost:3000/json', {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({ name: 'Aru' })
})
)
.then((x) => x.json()),
app
.handle(
new Request('http://localhost:3000/json', {
method: 'POST',
headers: {
'content-type': 'application/x-elysia-1'
},
body: JSON.stringify({ name: 'Aru' })
})
)
.then((x) => x.text()),
app
.handle(
new Request('http://localhost:3000/json', {
method: 'POST',
headers: {
'content-type': 'application/x-elysia-2'
},
body: JSON.stringify({ name: 'Aru' })
})
)
.then((x) => x.text())
])

console.log(response)
new Elysia().ws('/ws', {
ping: (message) => message
})
15 changes: 10 additions & 5 deletions 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.2.0-rc.0",
"version": "1.2.0",
"author": {
"name": "saltyAom",
"url": "https://github.com/SaltyAom",
Expand Down Expand Up @@ -118,6 +118,11 @@
"import": "./dist/universal/server.mjs",
"require": "./dist/cjs/universal/server.js"
},
"./universal/env": {
"types": "./dist/universal/env.d.ts",
"import": "./dist/universal/env.mjs",
"require": "./dist/cjs/universal/env.js"
},
"./universal/file": {
"types": "./dist/universal/file.d.ts",
"import": "./dist/universal/file.mjs",
Expand Down Expand Up @@ -148,8 +153,8 @@
"release": "npm run build && npm run test && npm publish"
},
"dependencies": {
"@sinclair/typebox": "^0.34.7",
"cookie": "^1.0.1",
"@sinclair/typebox": "^0.34.13",
"cookie": "^1.0.2",
"fast-decode-uri-component": "^1.0.1",
"memoirist": "^0.2.0",
"openapi-types": "^12.1.3"
Expand All @@ -166,8 +171,8 @@
"eslint-plugin-sonarjs": "^0.23.0",
"expect-type": "^0.16.0",
"prettier": "^3.3.3",
"tsup": "^8.3.0",
"typescript": "^5.5.2"
"tsup": "^8.3.5",
"typescript": "^5.7.2"
},
"peerDependencies": {
"@sinclair/typebox": ">= 0.34.0",
Expand Down
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { BunAdapter } from './adapter/bun/index'
import { WebStandardAdapter } from './adapter/web-standard/index'
import type { ElysiaAdapter } from './adapter/types'

import { env } from './universal/env'
import type { ListenCallback, Serve, Server } from './universal/server'

import {
Expand Down Expand Up @@ -348,15 +349,15 @@ export default class Elysia<

'~adapter': ElysiaAdapter

env(model: TObject<any>, env = Bun?.env ?? process.env) {
env(model: TObject<any>, _env = env) {
const validator = getSchemaValidator(model, {
dynamic: true,
additionalProperties: true,
coerce: true
})

if (validator.Check(env) === false) {
const error = new ValidationError('env', model, env)
if (validator.Check(_env) === false) {
const error = new ValidationError('env', model, _env)

throw new Error(error.all.map((x) => x.summary).join('\n'))
}
Expand Down Expand Up @@ -429,7 +430,7 @@ export default class Elysia<
applyConfig(config: ElysiaConfig<BasePath>) {
this.config = {
prefix: '',
aot: process.env.ELYSIA_AOT !== 'false',
aot: env.ELYSIA_AOT !== 'false',
normalize: true,
...config,
cookie: {
Expand Down Expand Up @@ -6168,6 +6169,7 @@ export type {
CoExist
} from './types'

export { env } from './universal/env'
export { file, ElysiaFile } from './universal/file'
export type { ElysiaAdapter } from './adapter'

Expand Down
7 changes: 7 additions & 0 deletions src/universal/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { isBun } from './utils'

export const env = isBun
? Bun.env
: typeof process !== 'undefined' && process?.env
? process.env
: {}
1 change: 1 addition & 0 deletions src/universal/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { env } from './env'
export { file } from './file'
export type {
ErrorLike,
Expand Down

0 comments on commit d589e5c

Please sign in to comment.