Skip to content
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

Release 0.7: Miyu #103

Merged
merged 75 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
7ece1af
:tada: feat: miyu type
SaltyAom Aug 29, 2023
29650d3
:tada: feat: stress type
SaltyAom Aug 29, 2023
705c597
:tada: feat: stress type
SaltyAom Aug 29, 2023
f5cc85e
:tada: feat: remove reconciliation
SaltyAom Aug 30, 2023
a1978a5
:tada: feat: near type
SaltyAom Aug 30, 2023
5410431
:tada: feat: merge main
SaltyAom Aug 31, 2023
60263de
:tada: feat: rewrite ws
SaltyAom Aug 31, 2023
1c55e76
:tada: feat: mapper and affix
SaltyAom Aug 31, 2023
3f5a064
:wrench: fix: merge main
SaltyAom Sep 1, 2023
8557b3a
:tada: feat: reporter
SaltyAom Sep 1, 2023
97a1fb3
:tada: feat: reporter
SaltyAom Sep 1, 2023
99fb5a4
:tada: feat: trace
SaltyAom Sep 1, 2023
54b2519
:tada: feat: single findDynamicRoute
SaltyAom Sep 1, 2023
d3da0dc
:tada: feat: reporter
SaltyAom Sep 2, 2023
23ddcea
:tada: feat: trace handle
SaltyAom Sep 2, 2023
a683d35
:tada: feat: trace unit
SaltyAom Sep 4, 2023
0bebf95
:tada: feat: static code analysis on trace
SaltyAom Sep 4, 2023
91c858d
:tada: feat: simplify route registration
SaltyAom Sep 4, 2023
a8a4d5b
:tada: feat: http status string autocompletion
SaltyAom Sep 5, 2023
17dc245
:tada: feat: trace error
SaltyAom Sep 5, 2023
ba650f5
:broom: chore: merge main
SaltyAom Sep 5, 2023
440d6c4
:tada: feat: maybe empty
SaltyAom Sep 5, 2023
d94abc4
:tada: feat: organize test
SaltyAom Sep 6, 2023
d37c17c
:tada: feat: test case for handler
SaltyAom Sep 6, 2023
780d4e2
:tada: feat: parse.unit and error
SaltyAom Sep 7, 2023
e471cf1
:tada: feat: reactive cookie spec
SaltyAom Sep 7, 2023
aac097a
:tada: feat: cookie class
SaltyAom Sep 7, 2023
5238d4d
:tada: feat: basic cookie
SaltyAom Sep 9, 2023
149aca1
:tada: feat: reactive cookie
SaltyAom Sep 9, 2023
3e2ff83
:tada: feat: reactive cookie
SaltyAom Sep 9, 2023
a842a4f
:wrench: fix: remove @types/cookie, using local type instead
SaltyAom Sep 9, 2023
6058d1a
:wrench: fix: rm pnpm-lock
SaltyAom Sep 9, 2023
74fba10
:wrench: fix: remove encode from serialize option
SaltyAom Sep 9, 2023
6e8a374
:tada: feat: cookie validation
SaltyAom Sep 10, 2023
12cb479
:tada: feat: template literal
SaltyAom Sep 11, 2023
8077514
:tada: feat: sign cookie
SaltyAom Sep 11, 2023
67a7c7d
:tada: feat: sign cookie
SaltyAom Sep 12, 2023
02bb298
:tada: feat: TypeBox.Transform
SaltyAom Sep 13, 2023
18e2859
:tada: feat: TypeBox.Transform
SaltyAom Sep 13, 2023
da86045
:tada: feat: cookie test
SaltyAom Sep 13, 2023
d20509d
:tada: feat: merge main
SaltyAom Sep 13, 2023
b39b2b9
:tada: feat: cookie test
SaltyAom Sep 13, 2023
57165d2
:tada: feat: cookie
SaltyAom Sep 13, 2023
c9314b3
:tada: feat: multiple routes
SaltyAom Sep 13, 2023
0dc4b21
:tada: feat: add context to on error
SaltyAom Sep 13, 2023
7c89606
:tada: feat: affix
SaltyAom Sep 13, 2023
0a5fe3d
:tada: feat: affix
SaltyAom Sep 13, 2023
104e22d
:tada: feat: dynamic parser
SaltyAom Sep 13, 2023
1b7bd06
🔧 fix: websocket example
bogeychan Sep 15, 2023
4c2f223
🔧 fix: expected binding of `ServerWebSocket`
bogeychan Sep 15, 2023
1c5deb7
🔧 fix: comply with naming convention `room`
bogeychan Sep 15, 2023
a3ecfa6
🎉 feat: add unit tests for websocket
bogeychan Sep 15, 2023
cf3e6be
:tada: feat: overlapping class
SaltyAom Sep 18, 2023
a76c366
:tada: feat: scope
SaltyAom Sep 18, 2023
b6d499e
Merge pull request #157 from bogeychan/miyu
SaltyAom Sep 18, 2023
adfc06a
:tada: feat: merge main
SaltyAom Sep 18, 2023
7e442c4
:tada: feat: encapsulation
SaltyAom Sep 18, 2023
487e913
:broom: chore: update changelog
SaltyAom Sep 18, 2023
a4f7721
:tada: feat: unknown context
SaltyAom Sep 19, 2023
698c654
:wrench: fix: trace unit test
SaltyAom Sep 19, 2023
206a88d
:feat: feat: remap unit test
SaltyAom Sep 19, 2023
162a35f
:feat: trace: error.unit
SaltyAom Sep 19, 2023
6f8262b
:broom: chore: update changelog
SaltyAom Sep 19, 2023
fefb05d
:broom: chore: update changelog
SaltyAom Sep 19, 2023
758f26a
:tada: feat: remove bind from app.handleError
SaltyAom Sep 19, 2023
d7415f3
:tada: feat: fallback to app.handleError.bind
SaltyAom Sep 20, 2023
ed8dc29
:tada: feat: readonly decorator
SaltyAom Sep 20, 2023
79f8698
:tada: feat: merge main
SaltyAom Sep 20, 2023
59df93e
:tada: feat: dynamic mode cookie
SaltyAom Sep 20, 2023
fd6524d
:broom: chore: chore
SaltyAom Sep 20, 2023
dd56e0a
:broom: chore: remove decode from aot
SaltyAom Sep 20, 2023
55c57ff
:broom: chore: remove array routes
SaltyAom Sep 20, 2023
f7c3927
:wrench: fix: can't declare response twice
SaltyAom Sep 20, 2023
73061f5
:tada: feat: 0.7
SaltyAom Sep 20, 2023
0f87391
:tada: feat: 0.7
SaltyAom Sep 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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