Skip to content

Commit

Permalink
🎉 feat: 0.2 release
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyAom committed Jan 27, 2023
1 parent ee4f7ee commit cb89dcc
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
21 changes: 15 additions & 6 deletions example/a.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,29 @@ const app = new Elysia()
query: t.Object({
n: t.String()
}),
body: t.Object({
username: t.String(),
password: t.String()
})
body: t.Object(
{
username: t.String(),
password: t.String()
},
{
description: 'An expected body'
}
),
detail: {
summary: 'Sign in the user',
tags: ['authentication']
}
}
})
.get('/sign-in', ({ body }) => 'ok')
.get('/products/nendoroid/skadi', ({ body }) => 1)
.get('/id2/:id', ({ params }) => 1, {
schema: {
detail: {
'summary': 'a',
summary: 'a'
}
}
})

type App = typeof app['store'][typeof SCHEMA]['/mirror']['POST']['body']
type App = typeof app['store'][typeof SCHEMA]['/mirror']['POST']['body']
14 changes: 5 additions & 9 deletions example/schema.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { Elysia, t, SCHEMA, DEFS } from '../src'

const app = new Elysia()
.setModel(
'a',
t.Object({
.setModel({
a: t.Object({
response: t.String()
})
)
.setModel(
'b',
t.Object({
}),
b: t.Object({
response: t.Number()
})
)
})
// Strictly validate response
.get('/', () => 'hi')
// Strictly validate body and response
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "elysia",
"description": "Fast, and friendly Bun web framework",
"version": "0.2.0-rc.1",
"version": "0.2.0",
"author": {
"name": "saltyAom",
"url": "https://github.com/SaltyAom",
Expand Down
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,9 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
schema: Instance['schema']
}>
>(name: Key, value: Value): NewInstance {
;(this.store as Record<Key, Value>)[name] = value
if (!(name in this.store)) {
;(this.store as Record<Key, Value>)[name] = value
}

return this as unknown as NewInstance
}
Expand All @@ -1080,7 +1082,7 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
}>
>(name: Name, value: Value): NewInstance {
if (!this.decorators) this.decorators = {}
this.decorators[name] = value
if (!(name in this.decorators)) this.decorators[name] = value

return this as unknown as NewInstance
}
Expand Down Expand Up @@ -1492,7 +1494,10 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {
request: Instance['request']
schema: Instance['schema']
}> {
Object.assign(this.store[DEFS], record)
Object.entries(record).forEach(([key, value]) => {
// @ts-ignore
if (!(key in this.store[DEFS])) this.store[DEFS][key] = value
})

return this as unknown as any
}
Expand Down
2 changes: 2 additions & 0 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const registerSchemaPath = ({
Object.entries(responseSchema as Record<string, TSchema>).forEach(
([key, value]) => {
if (typeof value === 'string') {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { type, properties, required, ...rest } = models[
value
] as TSchema & {
Expand Down Expand Up @@ -113,6 +114,7 @@ export const registerSchemaPath = ({
)
}
} else if (typeof responseSchema === 'string') {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { type, properties, required, ...rest } = models[
responseSchema
] as TSchema & {
Expand Down

0 comments on commit cb89dcc

Please sign in to comment.