Skip to content

Commit

Permalink
Merge pull request #103 from elysiajs/miyu
Browse files Browse the repository at this point in the history
Release 0.7: Miyu (codename)
  • Loading branch information
SaltyAom authored Sep 20, 2023
2 parents 1fa8a4c + 0f87391 commit 7c51647
Show file tree
Hide file tree
Showing 91 changed files with 9,615 additions and 5,865 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module.exports = {
'@typescript-eslint/no-extra-semi': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-namespace': 'off',
'no-case-declarations': 'off'
'no-case-declarations': 'off',
'no-extra-semi': 'off'
},
ignorePatterns: ['example/*', 'tests/**/*']
}
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
# 0.7.0 - 20 Sep 2023
Feature:
- rewrite type
- rewrite Web Socket
- add mapper method
- add affix, prefix, suffix
- trace
- typeBox.Transfom
- rewrite Type.ElysiaMeta to use TypeBox.Transform
- new type:
- t.Cookie
- t.ObjectString
- t.MaybeEmpty
- t.Nullable
- add `Context` to `onError`
- lifecycle hook now accept array function
- true encapsulation scope

Improvement:
- static Code Analysis now support rest parameter
- breakdown dynamic router into single pipeline instead of inlining to static router to reduce memory usage
- set `t.File` and `t.Files` to `File` instead of `Blob`
- skip class instance merging
- handle `UnknownContextPassToFunction`
- [#157](https://github.com/elysiajs/elysia/pull/179) WebSocket - added unit tests and fixed example & api by @bogeychan
- [#179](https://github.com/elysiajs/elysia/pull/179) add github action to run bun test by @arthurfiorette

Breaking Change:
- remove `ws` plugin, migrate to core
- rename `addError` to `error`

Change:
- using single findDynamicRoute instead of inlining to static map
- remove `mergician`
- remove array routes due to problem with TypeScript

Bug fix:
- strictly validate response by default
- `t.Numeric` not working on headers / query / params
- `t.Optional(t.Object({ [name]: t.Numeric }))` causing error
- add null check before converting `Numeric`
- inherits store to instance plugin
- handle class overlapping
- [#187](https://github.com/elysiajs/elysia/pull/187) InternalServerError message fixed to "INTERNAL_SERVER_ERROR" instead of "NOT_FOUND" by @bogeychan
- [#167](https://github.com/elysiajs/elysia/pull/167) mapEarlyResponse with aot on after handle

# 0.6.24 - 18 Sep 2023
Feature:
- [#149](https://github.com/elysiajs/elysia/pulls/149) support additional status codes in redirects
Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
<img width=480 src=https://user-images.githubusercontent.com/35027979/205498891-b75dc404-3232-4929-b216-823aa7373b71.png alt='Elysia label' />
</p>

<p align=center>Fast and friendly <a href=https://bun.sh>Bun</a> web framework.</p>
<p align=center>Ergonomic Framework for Human</p>

<p align=center>
<a href=https://elysiajs.com>Documentation</a> | <a href=https://discord.gg/eaFJ2KDJck>Discord</a>
</p>

<h6 align=center>
Formerly known as <a href="https://github.com/saltyaom/kingworld">KingWorld</a>
</h6>

## Philosophies
Building on top of 3 philosophies:

Expand Down
Binary file modified bun.lockb
Binary file not shown.
37 changes: 8 additions & 29 deletions example/a.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
import { Elysia, t } from '../src'

import { prisma } from '../../../demo/24/src/auth'
const one = new Elysia({ name: 'one' }).onRequest(() => console.log('Hello, one!'))
const two = new Elysia().use(one)

const setup = new Elysia()
.state({
prisma
})
.decorate({
prisma
})
const three = new Elysia()
.use(one)
.use(two)
.get('/hello', () => 'Hello, world!')
.listen(3000)

const app = new Elysia()
.decorate({
a: 'a'
})
.state({
a: 'a'
})
.use(setup)
.decorate({
b: 'b'
})
.state({
b: 'b'
})
.use(setup)
.get('/', async ({ prisma }) => {
const a = (await prisma.authKey.findFirst()) ?? 'Empty'

return a
})
.listen(8080)
// three.handle(new Request('http://localhost:3000/hello'))
40 changes: 30 additions & 10 deletions example/b.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
import { Elysia } from '../src'
import Elysia from '../src'

const app = new Elysia({
serve: {
// can be string, BunFile, TypedArray, Buffer, or array thereof
key: Bun.file('./key.pem'),
cert: Bun.file('./cert.pem'),
// passphrase, only required if key is encrypted
passphrase: 'super-secret'
}
}).listen(3000)
const app = new Elysia()
.get('/', ({ set }) => {
set.status = "I'm a teapot"

return Bun.file('example/teapot.webp')
})
.trace(async ({ beforeHandle }) => {
try {
console.log('Start BeforeHandle')
const { end } = await beforeHandle

const a = await end
} catch {
console.log("A")
}
})
.get('/trace', () => 'a', {
beforeHandle: [
function setup() {},
function error() {
throw new Error('A')
},
function resume() {}
],
afterHandle() {
console.log('After')
}
})
.listen(3000)
55 changes: 55 additions & 0 deletions example/b/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// setup.ts

import { Elysia } from '../../src'

// database.ts

export const databasePlugin = new Elysia({
name: 'database',
seed: 'database'
}).decorate('database', 'a')

// authentication-plugin.ts

export const authenticationPlugin = new Elysia({
name: 'authentication',
seed: 'authentication'
})
.use(databasePlugin)
.derive(async ({ headers, database }) => {
// logic
})

// setup
export const setup = new Elysia({ name: 'setup', seed: 'setup' }).use(
authenticationPlugin
)

// register.ts

export const register = new Elysia({ prefix: '/register' })
.use(setup)
.get('/', async ({ body, set, database }) => {
// logic
})
// login.ts

export const login = new Elysia({ prefix: '/login' })
.use(setup)
.get('/', async ({ body, set, database }) => {
// logic
})
// authentication.ts
export const authenticationRoute = new Elysia({ prefix: '/authentication' })
.use(login)
.use(register)

export const routes = new Elysia().use(authenticationRoute)

export const v2 = new Elysia({ prefix: '/v2' }).use(routes)

const app = new Elysia()
// .use(cors())
// .use(bearer())
.use(v2)
.listen(8080)
17 changes: 13 additions & 4 deletions example/c.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import type { Elysia } from "../src";
import { Elysia, t } from '../src'

export default function plugin(app: Elysia) {
return app.get('/from-plugin', () => 'hi')
}
const app = new Elysia()
.post('/0.6', ({ body }) => body, {
body: t.Union([
t.Undefined(),
t.Object({
name: t.String(),
job: t.String(),
trait: t.Optional(t.String())
})
])
})
.listen(3000)
43 changes: 43 additions & 0 deletions example/cookie.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Elysia, getSchemaValidator, t } from '../src'

const app = new Elysia()
// .get(
// '/council',
// ({ cookie: { council } }) =>
// (council.value = [
// {
// name: 'Rin',
// affilation: 'Administration'
// }
// ])
// )
// .get('/create', ({ cookie: { name } }) => (name.value = 'Himari'))
.get(
'/update',
({ cookie: { name } }) => {
name.value = 'seminar: Rio'

name.value = 'seminar: Himari'

name.maxAge = 86400

return name.value
},
{
cookie: t.Cookie(
{
name: t.Optional(t.String())
},
{
secrets: 'Fischl von Luftschloss Narfidort',
sign: ['name']
}
)
}
)
// .get('/remove', ({ cookie }) => {
// for (const self of Object.values(cookie)) self.remove()

// return 'Deleted'
// })
.listen(3000)
9 changes: 4 additions & 5 deletions example/lazy-module.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Elysia, SCHEMA } from '../src'
import { Elysia } from '../src'

const plugin = (app: Elysia) => app.get('/plugin', () => 'Plugin')
const asyncPlugin = async (app: Elysia) => app.get('/async', () => 'A')

const app = new Elysia()
.decorate('a', () => 'hello')
// .decorate('a', () => 'hello')
.use(plugin)
.use(asyncPlugin)
.use(import('./lazy'))
.use((app) => app.get('/inline', () => 'inline'))
.get('/', ({ a }) => a())
.use((app) => app.get('/inline', ({ store: { a } }) => 'inline'))
// .get('/', ({ a }) => a())
.listen(3000)

await app.modules
Expand Down
2 changes: 1 addition & 1 deletion example/lazy/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Elysia from "../../src";

export const lazy = (app: Elysia) => app.get('/lazy', () => 'Hi')
export const lazy = (app: Elysia) => app.state('a', 'b').get('/lazy', () => 'Hi')

export default lazy
32 changes: 32 additions & 0 deletions example/rename.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Elysia, t } from '../src'

// ? Elysia#83 | Proposal: Standardized way of renaming third party plugin-scoped stuff
// this would be a plugin provided by a third party
const myPlugin = new Elysia()
.decorate('myProperty', 42)
.model('salt', t.String())

new Elysia()
.use(
myPlugin
// map decorator, rename "myProperty" to "renamedProperty"
.decorate(({ myProperty, ...decorators }) => ({
renamedProperty: myProperty,
...decorators
}))
// map model, rename "salt" to "pepper"
.model(({ salt, ...models }) => ({
...models,
pepper: salt
}))
// Add prefix
.prefix('decorator', 'unstable')
)
.get(
'/mapped',
({ unstableRenamedProperty }) => unstableRenamedProperty
)
.post('/pepper', ({ body }) => body, {
body: 'pepper',
response: t.String()
})
2 changes: 1 addition & 1 deletion example/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Elysia, t, SCHEMA, DEFS } from '../src'
import { Elysia, t } from '../src'

const app = new Elysia()
.model({
Expand Down
14 changes: 10 additions & 4 deletions example/stress/instance.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { Elysia } from '../../src'
import { Elysia, t } from '../../src'

const total = 10_000

const t = performance.now()
const setup = new Elysia({ name: 'setup' })
.decorate('decorate', 'decorate')
.state('state', 'state')
.model('model', t.String())
.error('error', Error)

for (let i = 0; i < total; i++) new Elysia()
const t1 = performance.now()

const took = performance.now() - t
for (let i = 0; i < total; i++) new Elysia().use(setup)

const took = performance.now() - t1

console.log(
Intl.NumberFormat().format(total),
Expand Down
Binary file added example/teapot.webp
Binary file not shown.
23 changes: 23 additions & 0 deletions example/trace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Elysia } from '../src'

const logs = []

const app = new Elysia()
.trace(async ({ beforeHandle, request, response }) => {
const { children, time: start, end } = await beforeHandle
for (const child of children) {
const { time: start, end, name } = await child

console.log(name, 'took', (await end) - start, 'ms')
}
console.log('beforeHandle took', (await end) - start)
})
.get('/', () => 'Hi', {
beforeHandle: [
function setup() {},
async function delay() {
await new Promise((resolve) => setTimeout(resolve, 1000))
}
]
})
.listen(3000)
Loading

0 comments on commit 7c51647

Please sign in to comment.