-
-
Notifications
You must be signed in to change notification settings - Fork 250
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 #911 from elysiajs/seele
Release 1.2: Seele
- Loading branch information
Showing
59 changed files
with
6,702 additions
and
3,456 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
import { Elysia, t } from '../src' | ||
import { req } from '../test/utils' | ||
|
||
const api = new Elysia().get('/', ({ query }) => query, { | ||
query: t.Object({ | ||
date: t.Date() | ||
}) | ||
export const auth = new Elysia().macro({ | ||
isAuth(isAuth: boolean) { | ||
return { | ||
resolve() { | ||
return { | ||
user: 'saltyaom' | ||
} | ||
} | ||
} | ||
}, | ||
role(role: 'admin' | 'user') { | ||
return {} | ||
} | ||
}) | ||
|
||
api.handle(req(`/?date=${Date.now()}`)).then(x => x.json()).then(console.log) | ||
|
||
// const app = new Elysia() | ||
// .get('/', () => 'ok', { | ||
// query: t.Object({ | ||
// key1: t.Union([t.Array(t.String()), t.String()]) | ||
// }) | ||
// }) | ||
|
||
// app.handle(req('/?key1=ab&key1=cd&z=が')) | ||
// .then((x) => x.status) | ||
// .then(console.log) | ||
new Elysia().ws('/ws', { | ||
ping: (message) => message | ||
}) |
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,10 @@ | ||
import { createServer } from 'http' | ||
|
||
createServer((req, res) => { | ||
res.statusCode = 201 | ||
res. | ||
res.writeHead(200, { | ||
'content-type': 'application/json' | ||
}) | ||
res.end('a') | ||
}).listen(3000) |
Empty file.
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,71 @@ | ||
interface Node<T = unknown, Nodes extends Node<any, any>[] = []> { | ||
value: T | ||
neighbors: Nodes | ||
} | ||
|
||
type A = Node<1, [B, C]> // Node<1, [Node<2>, Node<3>]> | ||
type B = Node<2, [A, D]> // Node<2, [Node<1>, Node<3>]> | ||
type C = Node<3, [A, B]> // Node<3, [Node<1>, Node<2>]> | ||
type D = Node<4, [B, C]> // Node<4, [Node<2>, Node<3>]> | ||
|
||
type FilterOut<Arr extends any[], Target> = | ||
Arr extends [ | ||
infer Head, | ||
...infer Tail | ||
] | ||
? Head extends Target | ||
? FilterOut<Tail, Target> | ||
: [Head, ...FilterOut<Tail, Target>] | ||
: [] | ||
|
||
type BFS< | ||
Root extends Node<any, any[]>, | ||
ToFind, | ||
Searched extends Node<any, any>[] = [] | ||
> = Root extends (Searched['length'] extends 0 ? never : Searched[number]) | ||
? FilterOut<Root['neighbors'], Searched[number]> extends [ | ||
infer Current extends Node<any, any> | ||
] | ||
? BFS<Current, ToFind, [...Searched, Root]> | ||
: never | ||
: Root['value'] extends ToFind | ||
? Root & { __order: Searched } | ||
: Root['neighbors'] extends [ | ||
infer Current extends Node<any, any>, | ||
...infer Rest extends Node<any, any>[] | ||
] | ||
? Current['value'] extends ToFind | ||
? Current | ||
: Rest extends [infer Next extends Node<any, any>] | ||
? BFS<Next, ToFind, [...Searched, Root]> | ||
: never | ||
: never | ||
|
||
|
||
type Result = BFS<A, 4> // Node<4, [Node<2>, Node<3>]> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
function breadthFirstSearch<T>( | ||
root: Node<unknown, Node<any, any>[]>, | ||
toFind: T, | ||
searched: Node<any, any>[] = [] | ||
): Node<T> | null { | ||
if (searched.includes(root)) return null | ||
if (root.value === toFind) return root as Node<T> | ||
|
||
for (const current of root.neighbors) { | ||
if (current.value === toFind) return current | ||
|
||
const a = breadthFirstSearch(current, toFind, [...searched, root]) | ||
} | ||
|
||
return null | ||
} |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { Context } from '../../context' | ||
import type { AnyLocalHook } from '../../types' | ||
|
||
import { | ||
mapResponse, | ||
mapEarlyResponse, | ||
mapCompactResponse, | ||
createStaticHandler | ||
} from '../web-standard/handler' | ||
|
||
export const createNativeStaticHandler = ( | ||
handle: unknown, | ||
hooks: AnyLocalHook, | ||
setHeaders: Context['set']['headers'] = {} | ||
): (() => Response) | undefined => { | ||
if (typeof handle === 'function' || handle instanceof Blob) return | ||
|
||
const response = mapResponse(handle, { | ||
headers: setHeaders | ||
}) | ||
|
||
if ( | ||
hooks.parse.length === 0 && | ||
hooks.transform.length === 0 && | ||
hooks.beforeHandle.length === 0 && | ||
hooks.afterHandle.length === 0 | ||
) { | ||
if (!response.headers.has('content-type')) | ||
response.headers.append('content-type', 'text/plain;charset=utf-8') | ||
|
||
return response.clone.bind(response) | ||
} | ||
} | ||
|
||
export { | ||
mapResponse, | ||
mapEarlyResponse, | ||
mapCompactResponse, | ||
createStaticHandler | ||
} |
Oops, something went wrong.