@mapl/web 0.3.0-alpha.3 → 0.3.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -3
- package/compiler/bun/router.js +1 -1
- package/core/handler.js +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -13,7 +13,12 @@ const app = router(
|
|
|
13
13
|
[ layer.attach('id', () => performance.now()) ],
|
|
14
14
|
|
|
15
15
|
// Routes
|
|
16
|
-
[
|
|
16
|
+
[
|
|
17
|
+
handle.get('/path', (c) => c.id, {
|
|
18
|
+
// Response wrapper
|
|
19
|
+
type: handle.text
|
|
20
|
+
})
|
|
21
|
+
],
|
|
17
22
|
|
|
18
23
|
// Subrouters
|
|
19
24
|
{ '/api': api }
|
|
@@ -85,7 +90,7 @@ const input = await rolldown({
|
|
|
85
90
|
module: true,
|
|
86
91
|
mangle: false,
|
|
87
92
|
compress: {
|
|
88
|
-
// passes should be at least 2
|
|
93
|
+
// passes should be at least 2, recommend 3 - 5
|
|
89
94
|
passes: 3,
|
|
90
95
|
},
|
|
91
96
|
}),
|
|
@@ -96,4 +101,4 @@ await input.write({
|
|
|
96
101
|
inlineDynamicImports: true,
|
|
97
102
|
});
|
|
98
103
|
```
|
|
99
|
-
As of rn only `terser` can DCE `@mapl/web`
|
|
104
|
+
As of rn only `terser` can DCE `@mapl/web` patterns.
|
package/compiler/bun/router.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{injectDependency}from"runtime-compiler";import{RES404}from"../jit.js";let ROUTES;export let resetRouter=()=>{ROUTES={}};export let insertRoute=(method,path,content)=>{let isWildcard=path.endsWith(`**`);let i=0;let bunPattern=isWildcard?path.slice(-2).replace(/\*/g,()=>`:q`+ i++)+`*`:path.replace(/\*/g,()=>`:q`+ i++);let str=`(r,s)=>{`;if(i>0){str+=`let {q0`;for(let j=1,l=i-(isWildcard?1:0);j<l;j++)str+=`q,`+j;str+=`}=r.params`+(isWildcard?`,q`+i+`=r.params["*"];`:`;`)}(ROUTES[bunPattern]??={})[method]=str+content+`}`;if(method!==`GET`&&method!==`HEAD`&&method!==`OPTIONS`&&method!==`DELETE`&&method!==`PATCH`&&method!==`POST`&&method!==`PUT`)ROUTES[bunPattern][``]??=RES404;if(isWildcard)(ROUTES[bunPattern===`/*`?`/`:bunPattern.slice(0,-3)]??={})[method]??=RES404};export let routerToString=()=>{let str=`{`;for(let pattern in ROUTES){str+=`"`+pattern+`":`;let methods=ROUTES[pattern];
|
|
1
|
+
import{injectDependency}from"runtime-compiler";import{RES404}from"../jit.js";let ROUTES;export let resetRouter=()=>{ROUTES={}};export let insertRoute=(method,path,content)=>{let isWildcard=path.endsWith(`**`);let i=0;let bunPattern=isWildcard?path.slice(-2).replace(/\*/g,()=>`:q`+ i++)+`*`:path.replace(/\*/g,()=>`:q`+ i++);let str=`(r,s)=>{`;if(i>0){str+=`let {q0`;for(let j=1,l=i-(isWildcard?1:0);j<l;j++)str+=`q,`+j;str+=`}=r.params`+(isWildcard?`,q`+i+`=r.params["*"];`:`;`)}(ROUTES[bunPattern]??={})[method]=str+content+`}`;if(method!==``&&method!==`GET`&&method!==`HEAD`&&method!==`OPTIONS`&&method!==`DELETE`&&method!==`PATCH`&&method!==`POST`&&method!==`PUT`)ROUTES[bunPattern][``]??=RES404;if(isWildcard)(ROUTES[bunPattern===`/*`?`/`:bunPattern.slice(0,-3)]??={})[method]??=RES404};export let routerToString=()=>{let str=`{`;for(let pattern in ROUTES){str+=`"`+pattern+`":`;let methods=ROUTES[pattern];let allMethods=methods[``];if(allMethods==null){str+=`{`;for(let method in methods)str+=method+`:`+methods[method]+`,`;str+=`},`}else if(Object.keys(methods).length===1)str+=methods[``]+`,`;else{str+=`(r,s)=>`;for(let method in methods)if(method!==``){let fn=methods[method];str+=`r.method==="`+method+`"?`+(fn.startsWith(`(r,s)=>`)?injectDependency(fn)+`(r,s)`:fn)+`:`}str+=(allMethods.startsWith(`(r,s)=>`)?injectDependency(allMethods)+`(r,s)`:allMethods)+`,`}}return str+`}`};
|
package/core/handler.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{noOp}from"./utils.js";import{isHydrating}from"runtime-compiler/config";import{injectDependency}from"runtime-compiler";
|
|
1
|
+
import{noOp}from"./utils.js";import{isHydrating}from"runtime-compiler/config";import{injectDependency,lazyDependency}from"runtime-compiler";let JSON_HEADER=isHydrating?noOp:lazyDependency(injectDependency,`["content-type","application/json"]`);let JSON_OPTIONS=isHydrating?noOp:lazyDependency(injectDependency,`{headers:[`+JSON_HEADER()+`]}`);export let json=isHydrating?noOp:(res,hasContext)=>hasContext?`h.push(`+JSON_HEADER()+`);return new Response(JSON.stringify(`+res+`),c)`:`return new Response(JSON.stringify(`+res+`),`+JSON_OPTIONS()+`)`;let HTML_HEADER=isHydrating?noOp:lazyDependency(injectDependency,`["content-type","application/json"]`);let HTML_OPTIONS=isHydrating?noOp:lazyDependency(injectDependency,`{headers:[`+JSON_HEADER()+`]}`);export let html=isHydrating?noOp:(res,hasContext)=>hasContext?`h.push(`+HTML_HEADER()+`);return new Response(`+res+`,c)`:`return new Response(`+res+`,`+HTML_OPTIONS()+`)`;export let text=isHydrating?noOp:(res,hasContext)=>`return new Response(`+res+(hasContext?`,c)`:`)`);export let error=(r,f,dat)=>{r[2]=[f,dat];return r};export let route=(method,path,handler,dat)=>[method,path,handler,dat];export let any=(path,handler,dat)=>[``,path,handler,dat];export let get=(path,handler,dat)=>[`GET`,path,handler,dat];export let post=(path,handler,dat)=>[`POST`,path,handler,dat];export let put=(path,handler,dat)=>[`PUT`,path,handler,dat];export let del=(path,handler,dat)=>[`DELETE`,path,handler,dat];export let patch=(path,handler,dat)=>[`PATCH`,path,handler,dat];export let options=(path,handler,dat)=>[`OPTIONS`,path,handler,dat];export let trace=(path,handler,dat)=>[`TRACE`,path,handler,dat];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapl/web",
|
|
3
|
-
"version": "0.3.0-
|
|
3
|
+
"version": "0.3.0-beta.1",
|
|
4
4
|
"description": "A compiled web framework for all runtimes",
|
|
5
5
|
"keywords": ["fast", "lightweight", "cross-runtime", "framework", "web", "backend"],
|
|
6
6
|
"repository": {
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"main": "./index.js",
|
|
13
13
|
"types": "./index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@mapl/framework": "^0.
|
|
15
|
+
"@mapl/framework": "^0.5.2",
|
|
16
16
|
"@mapl/router": "^0.6.2",
|
|
17
17
|
"@safe-std/error": "^1.0.1",
|
|
18
|
-
"runtime-compiler": "^1.
|
|
18
|
+
"runtime-compiler": "^1.2.4"
|
|
19
19
|
},
|
|
20
20
|
"optionalDependencies": {
|
|
21
21
|
"secure-headers": "^0.0.6"
|
|
@@ -25,16 +25,16 @@
|
|
|
25
25
|
".": "./index.js",
|
|
26
26
|
"./core/handler": "./core/handler.js",
|
|
27
27
|
"./core/utils": "./core/utils.js",
|
|
28
|
-
"./core/middleware": "./core/middleware.js",
|
|
29
|
-
"./core/context": "./core/context.js",
|
|
30
28
|
"./core": "./core/index.js",
|
|
29
|
+
"./core/middleware": "./core/middleware.js",
|
|
31
30
|
"./utils/static-headers": "./utils/static-headers.js",
|
|
31
|
+
"./core/context": "./core/context.js",
|
|
32
32
|
"./utils/secure-headers": "./utils/secure-headers.js",
|
|
33
|
-
"./
|
|
34
|
-
"./compiler/jit": "./compiler/jit.js",
|
|
35
|
-
"./compiler/aot": "./compiler/aot.js",
|
|
33
|
+
"./compiler/bun/jit": "./compiler/bun/jit.js",
|
|
36
34
|
"./compiler/bun/aot": "./compiler/bun/aot.js",
|
|
37
35
|
"./compiler/bun/router": "./compiler/bun/router.js",
|
|
38
|
-
"./
|
|
36
|
+
"./utils/cors": "./utils/cors.js",
|
|
37
|
+
"./compiler/aot": "./compiler/aot.js",
|
|
38
|
+
"./compiler/jit": "./compiler/jit.js"
|
|
39
39
|
}
|
|
40
40
|
}
|