Skip to content

Commit

Permalink
Merge pull request #25 from elysiajs/next
Browse files Browse the repository at this point in the history
feat: 0.3 - 大地の閾を探して [Looking for Edge of Ground]
  • Loading branch information
SaltyAom authored Mar 17, 2023
2 parents 5ea9288 + 36c7fb9 commit 34fa583
Show file tree
Hide file tree
Showing 40 changed files with 3,098 additions and 977 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = {
'no-mixed-spaces-and-tabs': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-extra-semi': 'off',
'@typescript-eslint/ban-ts-comment': 'off'
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-namespace': 'off'
},
ignorePatterns: ['example/*', 'tests/**/*']
}
13 changes: 8 additions & 5 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
.git
.gitignore
.prettierrc
.eslintrc.js
.cjs.swcrc
.es.swcrc
.esm.swcrc
.swcrc
bun.lockb
.husky
.github

bun.lockb
node_modules
tsconfig.json
CHANGELOG.md

example
tests
docs
src
# src
.DS_Store
test
CHANGELOG.md
.eslintrc.js
tsconfig.cjs.json
tsconfig.esm.json

CONTRIBUTING.md
CODE_OF_CONDUCT.md
162 changes: 161 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,163 @@
# 0.3.0 - 17 Mar 2023
Feature:
- Elysia Fn
- Suport `multipart/form-data`
- `t.File` and `t.Files` for file validation
- `schema.content` for specifying content type

Improvement:
- Add string format: 'email', 'uuid', 'date', 'date-time'
- Update @sinclair/typebox to 0.25.24
- Update Raikiri to 0.2.0-beta.0 (ei)
- Add file upload test thanks to #21 (@amirrezamahyari)
- Pre compile lowercase method for Eden
- Reduce complex instruction for most Elysia types
- Change store type to `unknown`
- Compile `ElysiaRoute` type to literal
- Optimize type compliation, type inference and auto-completion
- Improve type compilation speed
- Improve TypeScript inference between plugin registration
- Optimize TypeScript inference size
- Context creation optimization
- Use Raikiri router by default
- Remove unused function
- Refactor `registerSchemaPath` to support OpenAPI 3.0.3
- Add `error` inference for Eden
- Mark `@sinclair/typebox` as optional `peerDenpendencies`

Fix:
- Raikiri 0.2 thrown error on not found
- Union response with `t.File` is not working
- Definitions isn't defined on Swagger
- details are missing on group plugin
- group plugin, isn't unable to compile schema
- group is not exportable because EXPOSED is a private property
- Multiple cookies doesn't set `content-type` to `application/json`
- `EXPOSED` is not export when using `fn.permission`
- Missing merged return type for `.ws`
- Missing nanoid
- context side-effects
- `t.Files` in swagger is referring to single file
- Eden response type is unknown
- Unable to type `setModel` inference definition via Eden
- Handle error thrown in non permission function
- Exported variable has or is using name 'SCHEMA' from external module
- Exported variable has or is using name 'DEFS' from external module
- Possible errors for building Elysia app with `declaration: true` in `tsconfig.json`

Breaking Change:
- Rename `inject` to `derive`
- Depreacate `ElysiaRoute`, changed to inline
- Remove `derive`
- Update from OpenAPI 2.x to OpenAPI 3.0.3
- Move context.store[SYMBOL] to meta[SYMBOL]

# 0.3.0-rc.9 - 16 Mar 2023
Improvement:
- Add string format: 'email', 'uuid', 'date', 'date-time'

# 0.3.0-rc.8 - 16 Mar 2023
Fix:
- Raikiri 0.2 thrown error on not found

# 0.3.0-rc.7 - 16 Mar 2023
Improvement:
- Update @sinclair/typebox to 0.25.24
- Update Raikiri to 0.2.0-beta.0 (ei)
- Add file upload test thanks to #21 (@amirrezamahyari)

# 0.3.0-rc.6 - 10 Mar 2023
Fix:
- Union response with `t.File` is not working

# 0.3.0-rc.5 - 10 Mar 2023
Fix:
- Definitions isn't defined on Swagger
- details are missing on group plugin
- group plugin, isn't unable to compile schema
- group is not exportable because EXPOSED is a private property

# 0.3.0-rc.4 - 9 Mar 2023
Fix:
- console.log while using cookie

# 0.3.0-rc.3 - 9 Mar 2023
Breaking Change:
- Rename `inject` to `derive`

Fix:
- Multiple cookies doesn't set `content-type` to `application/json`
- `EXPOSED` is not export when using `fn.permission`

# 0.3.0-rc.2 - 7 Mar 2023
Fix:
- Missing merged return type for `.ws`

# 0.3.0-rc.1 - 7 Mar 2023
Fix:
- Missing nanoid

# 0.3.0-beta.6 - 4 Mar 2023
Fix:
- context side-effects

# 0.3.0-beta.5 - 1 Mar 2023
Improvement:
- Pre compile lowercase method for Eden

# 0.3.0-beta.3 - 27 Feb 2023
Improvement:
- ~33% faster for compiling type inference
- Reduce complex instruction for most Elysia types
- Change store type to `unknown`

Fix:
- `t.Files` in swagger is referring to single file
- Eden response type is unknown

# 0.3.0-beta.2 - 27 Feb 2023
Improvement:
- Compile `ElysiaRoute` type to literal
- Optimize type compliation, type inference and auto-completion
- Improve type compilation speed by ~3x

Fix:
- Unable to type `setModel` inference definition via Eden

Breaking Change:
- Depreacate `ElysiaRoute`, changed to inline

# 0.3.0-beta.1 - 25 Feb 2023
Fix:
- Handle error thrown in non permission function

# 0.3.0-beta.0 - 25 Feb 2023
Feature:
- Elysia Fn
- Suport `multipart/form-data`
- `t.File` and `t.Files` for file validation
- `schema.content` for specifying content type

Improvement:
- Improve TypeScript inference between plugin registration
- Optimize TypeScript inference size
- Context creation optimization
- Use Raikiri router by default
- Remove unused function
- Refactor `registerSchemaPath` to support OpenAPI 3.0.3
- Add `error` inference for Eden
- Mark `@sinclair/typebox` as optional `peerDenpendencies`

Fix:
- Exported variable has or is using name 'SCHEMA' from external module
- Exported variable has or is using name 'DEFS' from external module
- Possible errors for building Elysia app with `declaration: true` in `tsconfig.json`

Breaking Change:
- Remove `derive`
- Update from OpenAPI 2.x to OpenAPI 3.0.3
- Move context.store[SYMBOL] to meta[SYMBOL]

# 0.2.9 - 20 Feb 2023
Bug fix:
- `group` doesn't inherits `onError`
Expand Down Expand Up @@ -100,7 +260,7 @@ Happy Christmas, wishing you happy tonight as we release the first stable releas
With this API is now stabilized, and Elysia will focus on growing its ecosystem and plugins for common patterns.

## Eden
Introducing [Eden](https://elysiajs.com/collections/eden.html), a fully type-safe client for Elysia server like tRPC.
Introducing [Eden](https://elysiajs.com/plugins/eden.html), a fully type-safe client for Elysia server like tRPC.

A 600 bytes client for Elysia server, no code generation need, creating a fully type-safe, and auto-complete for both client and server.

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

const authenticate = (app: Elysia) =>
app.group('/authenticate', (group) =>
group
export const plugin = (app: Elysia) =>
app.group('/a', (app) =>
app
.setModel({
sign: t.Object({
username: t.String()
})
})
.post(
'/login',
({ body: { username, password }, set }) => {
throw new Error('A')
},
'/json/:id',
({ body, params: { id }, query: { name } }) => 'h',
{
beforeHandle: ({ body: { username, password }, set }) => {},
schema: {
body: t.Object({
username: t.String(),
password: t.String()
})
headers: 'sign',
params: t.Object({
id: t.Number()
}),
response: {
200: t.String(),
400: t.String()
},
detail: {
summary: 'Transform path parameter'
}
}
}
)
.onError(({ code, error, set }) => {
console.log("A")
)

return {
status: 400,
body: {
error: 'Bad request'
}
}
const app = new Elysia({
serve: {
// Max payload in byte
maxRequestBodySize: 1024
}
})
.use(plugin)
.derive((context) => {
return {
a: 'b'
}
})
.decorate('A', 'b')
.post('/sign', ({ body }) => body, {
schema: {
body: t.Object({
email: t.String({
format: 'email'
}),
time: t.String({
format: 'date-time'
})
})
)
}
})
.post(
'/file',
({ set, a, A }) => {
const file = Bun.file('')
if (file.size === 0) {
set.status = 404
return 2
}

const app = new Elysia().use(authenticate).listen(8080)
return file
},
{
error({ set }) {},
schema: {
response: t.Object({
200: t.File(),
404: t.Number()
})
}
}
)
.listen(8080)
12 changes: 6 additions & 6 deletions example/derive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Elysia } from '../src'

new Elysia()
.state('counter', 0)
.inject(({ store }) => ({
.derive(({ store }) => ({
increase() {
store.counter++
}
}))
.derive((store) => ({
doubled: () => store().counter * 2,
tripled: () => store().counter * 3
.derive(({ store }) => ({
doubled: store.counter * 2,
tripled: store.counter * 3
}))
.get('/', ({ increase, store }) => {
increase()
Expand All @@ -18,8 +18,8 @@ new Elysia()

return {
counter,
doubled: doubled(),
tripled: tripled()
doubled,
tripled
}
})
.listen(3000, ({ hostname, port }) => {
Expand Down
2 changes: 1 addition & 1 deletion example/error.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Elysia, t } from '../src'

new Elysia()
.onError((code, error) => {
.onError(({ code, error }) => {
if (code === 'NOT_FOUND')
return new Response('Not Found :(', {
status: 404
Expand Down
12 changes: 12 additions & 0 deletions example/expose.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Elysia } from '../src'

const app = new Elysia()
.get('/', () => 'Hello Elysia')
.fn({
mirror: async <T extends string>(value: T) => {
if (value === 'false') throw new Error("Value can't be false")

return value
}
})
.listen(8080)
4 changes: 2 additions & 2 deletions example/nested-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ new Elysia()
.guard(
{
schema: {
header: t.Object({
a: t.Number()
headers: t.Object({
a: t.String()
})
}
},
Expand Down
5 changes: 1 addition & 4 deletions example/router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Elysia, type SCHEMA } from '../src'
import { Elysia } from '../src'

const prefix =
<Prefix extends string = string>(prefix: Prefix) =>
Expand All @@ -19,6 +19,3 @@ const a = new Elysia()
.use(prefix('prefixed'))
.listen(8080)

type Router = typeof a['store'][typeof SCHEMA]

type Path = Router['/a']['GET']['response']
Loading

0 comments on commit 34fa583

Please sign in to comment.