-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from elysiajs/miyu
Release 0.7: Miyu (codename)
- Loading branch information
Showing
91 changed files
with
9,615 additions
and
5,865 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.