Skip to content

Commit

Permalink
Merge pull request #911 from elysiajs/seele
Browse files Browse the repository at this point in the history
Release 1.2: Seele
  • Loading branch information
SaltyAom authored Dec 23, 2024
2 parents 4ed9465 + dbd3142 commit 18d3dce
Show file tree
Hide file tree
Showing 59 changed files with 6,702 additions and 3,456 deletions.
39 changes: 37 additions & 2 deletions build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const tsupConfig: Options = {
splitting: false,
sourcemap: false,
clean: true,
bundle: true
bundle: false,
minify: false
// outExtension() {
// return {
// js: '.js'
Expand All @@ -33,6 +34,35 @@ await Promise.all([
})
])

// ? Fix mjs import
const glob = new Bun.Glob('./dist/**/*.mjs')

for await (const entry of glob.scan('.')) {
const content = await Bun.file(entry).text()

await Bun.write(
entry,
content
.replace(
// Named import
/(import|export)\s*\{([a-zA-Z0-9_,\s$]*)\}\s*from\s*['"]([a-zA-Z0-9./-]*[./][a-zA-Z0-9./-]*)['"]/g,
'$1{$2}from"$3.mjs"'
)
.replace(
// Default import
/(import|export) ([a-zA-Z0-9_$]+) from\s*['"]([a-zA-Z0-9./-]*[./][a-zA-Z0-9./-]*)['"]/g,
'$1 $2 from"$3.mjs"'
)
)

// await fs.writeFile(
// entry,
// (await fs.readFile(entry))
// .toString()
// .replaceAll(/require\("(.+)\.js"\);/g, 'require("$1.cjs");'),
// );
}

await $`tsc --project tsconfig.dts.json`

await Bun.build({
Expand All @@ -45,7 +75,12 @@ await Bun.build({
},
target: 'bun',
sourcemap: 'external',
external: ['@sinclair/typebox']
external: [
'@sinclair/typebox',
'cookie',
'fast-decode-uri-component',
'memoirist'
]
})

await Promise.all([
Expand Down
Binary file modified bun.lockb
Binary file not shown.
33 changes: 16 additions & 17 deletions example/a.ts
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
})
10 changes: 10 additions & 0 deletions example/ab.ts
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 added example/app.ts
Empty file.
71 changes: 71 additions & 0 deletions example/d.ts
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
}
74 changes: 62 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "elysia",
"description": "Ergonomic Framework for Human",
"version": "1.1.27",
"version": "1.2.0",
"author": {
"name": "saltyAom",
"url": "https://github.com/SaltyAom",
Expand All @@ -23,6 +23,16 @@
"import": "./dist/ws/index.mjs",
"require": "./dist/cjs/ws/index.js"
},
"./ws/types": {
"types": "./dist/ws/types.d.ts",
"import": "./dist/ws/types.mjs",
"require": "./dist/cjs/ws/types.js"
},
"./ws/bun": {
"types": "./dist/ws/bun.d.ts",
"import": "./dist/ws/bun.mjs",
"require": "./dist/cjs/ws/bun.js"
},
"./compose": {
"types": "./dist/compose.d.ts",
"import": "./dist/compose.mjs",
Expand All @@ -43,11 +53,6 @@
"import": "./dist/error.mjs",
"require": "./dist/cjs/error.js"
},
"./handler": {
"types": "./dist/handler.d.ts",
"import": "./dist/handler.mjs",
"require": "./dist/cjs/handler.js"
},
"./sucrose": {
"types": "./dist/sucrose.d.ts",
"import": "./dist/sucrose.mjs",
Expand Down Expand Up @@ -77,6 +82,51 @@
"types": "./dist/fast-querystring.d.ts",
"import": "./dist/fast-querystring.mjs",
"require": "./dist/cjs/fast-querystring.js"
},
"./adapter": {
"types": "./dist/adapter/index.d.ts",
"import": "./dist/adapter/index.mjs",
"require": "./dist/cjs/adapter/index.js"
},
"./adapter/bun": {
"types": "./dist/adapter/bun/index.d.ts",
"import": "./dist/adapter/bun/index.mjs",
"require": "./dist/cjs/adapter/bun/index.js"
},
"./adapter/bun/handler": {
"types": "./dist/adapter/bun/handler.d.ts",
"import": "./dist/adapter/bun/handler.mjs",
"require": "./dist/cjs/adapter/bun/handler.js"
},
"./adapter/web-standard": {
"types": "./dist/adapter/web-standard/index.d.ts",
"import": "./dist/adapter/web-standard/index.mjs",
"require": "./dist/cjs/adapter/web-standard/index.js"
},
"./adapter/web-standard/handler": {
"types": "./dist/adapter/web-standard/handler.d.ts",
"import": "./dist/adapter/web-standard/handler.mjs",
"require": "./dist/cjs/adapter/web-standard/handler.js"
},
"./universal": {
"types": "./dist/universal/index.d.ts",
"import": "./dist/universal/index.mjs",
"require": "./dist/cjs/universal/index.js"
},
"./universal/server": {
"types": "./dist/universal/server.d.ts",
"import": "./dist/universal/server.mjs",
"require": "./dist/cjs/universal/server.js"
},
"./universal/env": {
"types": "./dist/universal/env.d.ts",
"import": "./dist/universal/env.mjs",
"require": "./dist/cjs/universal/env.js"
},
"./universal/file": {
"types": "./dist/universal/file.d.ts",
"import": "./dist/universal/file.mjs",
"require": "./dist/cjs/universal/file.js"
}
},
"repository": {
Expand All @@ -103,9 +153,10 @@
"release": "npm run build && npm run test && npm publish"
},
"dependencies": {
"@sinclair/typebox": "0.32.34",
"cookie": "^1.0.1",
"@sinclair/typebox": "^0.34.13",
"cookie": "^1.0.2",
"fast-decode-uri-component": "^1.0.1",
"memoirist": "^0.2.0",
"openapi-types": "^12.1.3"
},
"devDependencies": {
Expand All @@ -119,13 +170,12 @@
"eslint-plugin-security": "^2.1.0",
"eslint-plugin-sonarjs": "^0.23.0",
"expect-type": "^0.16.0",
"memoirist": "^0.2.0",
"prettier": "^3.3.3",
"tsup": "^8.0.2",
"typescript": "^5.5.2"
"tsup": "^8.3.5",
"typescript": "^5.7.2"
},
"peerDependencies": {
"@sinclair/typebox": ">= 0.32.0",
"@sinclair/typebox": ">= 0.34.0",
"openapi-types": ">= 12.0.0",
"typescript": ">= 5.0.0"
},
Expand Down
40 changes: 40 additions & 0 deletions src/adapter/bun/handler.ts
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
}
Loading

0 comments on commit 18d3dce

Please sign in to comment.