@mapl/web 0.3.0-alpha.1 → 0.3.0-alpha.2
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/compiler/jit.js +1 -1
- package/package.json +7 -7
package/compiler/jit.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{compileGroup,createArgSet,AsyncFunction,setHooks,contextInit,setContextInit}from"@mapl/framework";import compile from"@mapl/router/method/compiler";import{countParams}from"@mapl/router/path";import{insertItem}from"@mapl/router/method";import{exportDependency,getDependency,injectDependency,injectExternalDependency}from"runtime-compiler";import{evaluate,evaluateSync}from"runtime-compiler/jit";let URL_ROUTER;export let RES404=injectDependency(`new Response(null,{status:404})`);export let RES400=injectDependency(`new Response(null,{status:400})`);let paramArgs=createArgSet(new Array(16).fill(0).map((_1,i)=>`q`+i));let compileReturn=(dat,fnAsync,scopeAsync,contextCreated,result)=>{let res=dat?.type;if(res==null)return`return `+result;let str=res(fnAsync?`await `+result:result,contextCreated);return fnAsync&&!scopeAsync?`return (async()=>{`+str+`})()`:str};let compileToState=router=>{URL_ROUTER={};setHooks({compileHandler:(handler,prevContent,path,scope)=>{let fn=handler[2];let call=injectExternalDependency(fn)+`(`;let paramCount=countParams(handler[1]);paramCount>0&&(call+=paramArgs[paramCount]);if(fn.length>paramCount){call+=paramCount===0?`c`:`,c`;if(!scope[1]){insertItem(URL_ROUTER,handler[0],path,prevContent+contextInit+compileReturn(handler[3],fn instanceof AsyncFunction,scope[0],true,call+`)`)+(scope[0]?`})()`:``));return}}insertItem(URL_ROUTER,handler[0],path,prevContent+compileReturn(handler[3],fn instanceof AsyncFunction,scope[0],scope[1],call+`)`)+(scope[0]?`})()`:``))},compileErrorHandler:(input,fn,dat,scope)=>{let call=injectExternalDependency(fn)+`(`+input;if(fn.length>1){call+=`,c`;if(!scope[1])return contextInit+compileReturn(dat,fn instanceof AsyncFunction,scope[0],true,call+`)`)}return compileReturn(dat,fn instanceof AsyncFunction,scope[0],scope[1],call+`)`)}});setContextInit(`let h=[],c={status:200,req:r,headers:h};`);compileGroup(router,[false,false,,`return `+RES400,false],``,``)};export let compileToString=router=>{compileToState(router);return`(r)=>{`+compile(URL_ROUTER,`r.method`,`let u=r.url,s=u.indexOf("/",12)+1,e=u.indexOf("?",s),p=e===-1?u.slice(s):u.slice(s,e);`,1)+`return `+RES404+`}`};export let compileToExportedDependency=router=>exportDependency(injectDependency(
|
|
1
|
+
import{compileGroup,createArgSet,AsyncFunction,setHooks,contextInit,setContextInit}from"@mapl/framework";import compile from"@mapl/router/method/compiler";import{countParams}from"@mapl/router/path";import{insertItem}from"@mapl/router/method";import{exportDependency,getDependency,injectDependency,injectExternalDependency}from"runtime-compiler";import{evaluate,evaluateSync}from"runtime-compiler/jit";let URL_ROUTER;export let RES404=injectDependency(`new Response(null,{status:404})`);export let RES400=injectDependency(`new Response(null,{status:400})`);let paramArgs=createArgSet(new Array(16).fill(0).map((_1,i)=>`q`+i));let compileReturn=(dat,fnAsync,scopeAsync,contextCreated,result)=>{let res=dat?.type;if(res==null)return`return `+result;let str=res(fnAsync?`await `+result:result,contextCreated);return fnAsync&&!scopeAsync?`return (async()=>{`+str+`})()`:str};let compileToState=router=>{URL_ROUTER={};setHooks({compileHandler:(handler,prevContent,path,scope)=>{let fn=handler[2];let call=injectExternalDependency(fn)+`(`;let paramCount=countParams(handler[1]);paramCount>0&&(call+=paramArgs[paramCount]);if(fn.length>paramCount){call+=paramCount===0?`c`:`,c`;if(!scope[1]){insertItem(URL_ROUTER,handler[0],path,prevContent+contextInit+compileReturn(handler[3],fn instanceof AsyncFunction,scope[0],true,call+`)`)+(scope[0]?`})()`:``));return}}insertItem(URL_ROUTER,handler[0],path,prevContent+compileReturn(handler[3],fn instanceof AsyncFunction,scope[0],scope[1],call+`)`)+(scope[0]?`})()`:``))},compileErrorHandler:(input,fn,dat,scope)=>{let call=injectExternalDependency(fn)+`(`+input;if(fn.length>1){call+=`,c`;if(!scope[1])return contextInit+compileReturn(dat,fn instanceof AsyncFunction,scope[0],true,call+`)`)}return compileReturn(dat,fn instanceof AsyncFunction,scope[0],scope[1],call+`)`)}});setContextInit(`let h=[],c={status:200,req:r,headers:h};`);compileGroup(router,[false,false,,`return `+RES400,false],``,``)};export let compileToString=router=>{compileToState(router);return`(r)=>{`+compile(URL_ROUTER,`r.method`,`let u=r.url,s=u.indexOf("/",12)+1,e=u.indexOf("?",s),p=e===-1?u.slice(s):u.slice(s,e);`,1)+`return `+RES404+`}`};export let compileToExportedDependency=router=>exportDependency(injectDependency(compileToString(router)));export let compileToHandler=async router=>{let id=compileToExportedDependency(router);await evaluate();return getDependency(id)};export let compileToHandlerSync=router=>{let id=compileToExportedDependency(router);evaluateSync();return getDependency(id)};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapl/web",
|
|
3
|
-
"version": "0.3.0-alpha.
|
|
3
|
+
"version": "0.3.0-alpha.2",
|
|
4
4
|
"description": "A compiled web framework for all runtimes",
|
|
5
5
|
"keywords": ["fast", "lightweight", "cross-runtime", "framework", "web", "backend"],
|
|
6
6
|
"repository": {
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
},
|
|
23
23
|
"exports": {
|
|
24
24
|
"./constants": "./constants.js",
|
|
25
|
+
"./core/utils": "./core/utils.js",
|
|
25
26
|
".": "./index.js",
|
|
26
|
-
"./utils/secure-headers": "./utils/secure-headers.js",
|
|
27
27
|
"./core/context": "./core/context.js",
|
|
28
|
-
"./
|
|
28
|
+
"./compiler/aot": "./compiler/aot.js",
|
|
29
29
|
"./core/middleware": "./core/middleware.js",
|
|
30
|
-
"./
|
|
30
|
+
"./utils/cors": "./utils/cors.js",
|
|
31
31
|
"./core": "./core/index.js",
|
|
32
|
-
"./utils/static-headers": "./utils/static-headers.js",
|
|
33
|
-
"./compiler/aot": "./compiler/aot.js",
|
|
34
32
|
"./core/handler": "./core/handler.js",
|
|
35
|
-
"./
|
|
33
|
+
"./compiler/jit": "./compiler/jit.js",
|
|
34
|
+
"./utils/static-headers": "./utils/static-headers.js",
|
|
35
|
+
"./utils/secure-headers": "./utils/secure-headers.js"
|
|
36
36
|
}
|
|
37
37
|
}
|