@mapl/web 0.1.9 → 0.1.10
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/core/compile.js +1 -1
- package/core/index.js +1 -1
- package/package.json +7 -7
package/core/compile.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{compileGroup,createArgSet,AsyncFunction,compilerState as state}from"@mapl/framework";import compile from"@mapl/router/method/compiler";import{countParams}from"@mapl/router/path";import{isErr}from"@safe-std/error";import createContext from"./context.js";let paramArgs=createArgSet(new Array(16).fill(0).map((_1,i)=>`q`+i));let compileReturn=(dat,fnAsync,scopeAsync,contextCreated,result)=>{let typ=dat.type;if(typ===`raw`)return`return `+result;if(fnAsync)result=`await `+result;let str=typ==null?`return new Response(`+result+(contextCreated?`,c)`:`)`):contextCreated?`mh.push(`+(typ===`json`?`mwj`:`mwh`)+`);return new Response(`+(typ===`json`?`JSON.stringify(`+result+`)`:result)+`,c)`:`return new Response(`+(typ===`json`?`JSON.stringify(`+result+`),mwoj`:result+`,mwoh`)+`)`;return fnAsync&&!scopeAsync?`return (async()=>{`+str+`})()`:str};let compileHandler=(fn,dat,path,scope)=>{let call=`f`+state[1].push(fn)+`(`;let paramCount=countParams(path);if(paramCount>0)call+=paramArgs[paramCount];if(fn.length>paramCount){call+=paramCount===0?`c`:`,c`;if(!scope[1])return state[2]+compileReturn(dat,fn instanceof AsyncFunction,scope[0],true,call+`)`)}return compileReturn(dat,fn instanceof AsyncFunction,scope[0],scope[1],call+`)`)};let compileErrorHandler=(fn,dat,scope)=>{let call=`f`+state[1].push(fn)+`(t`;if(fn.length>1){call+=`,c`;if(!scope[1])return state[2]+compileReturn(dat,fn instanceof AsyncFunction,scope[0],true,call+`)`)}return compileReturn(dat,fn instanceof AsyncFunction,scope[0],scope[1],call+`)`)};export let compileToState=router=>{state[0]={};state[1]=[];state[2]=`let c=mwc(r);`;state[3]=compileHandler;state[4]=compileErrorHandler;compileGroup(router,[false,false
|
|
1
|
+
import{compileGroup,createArgSet,AsyncFunction,compilerState as state}from"@mapl/framework";import compile from"@mapl/router/method/compiler";import{countParams}from"@mapl/router/path";import{isErr}from"@safe-std/error";import createContext from"./context.js";let paramArgs=createArgSet(new Array(16).fill(0).map((_1,i)=>`q`+i));let compileReturn=(dat,fnAsync,scopeAsync,contextCreated,result)=>{let typ=dat.type;if(typ===`raw`)return`return `+result;if(fnAsync)result=`await `+result;let str=typ==null?`return new Response(`+result+(contextCreated?`,c)`:`)`):contextCreated?`mh.push(`+(typ===`json`?`mwj`:`mwh`)+`);return new Response(`+(typ===`json`?`JSON.stringify(`+result+`)`:result)+`,c)`:`return new Response(`+(typ===`json`?`JSON.stringify(`+result+`),mwoj`:result+`,mwoh`)+`)`;return fnAsync&&!scopeAsync?`return (async()=>{`+str+`})()`:str};let compileHandler=(fn,dat,path,scope)=>{let call=`f`+state[1].push(fn)+`(`;let paramCount=countParams(path);if(paramCount>0)call+=paramArgs[paramCount];if(fn.length>paramCount){call+=paramCount===0?`c`:`,c`;if(!scope[1])return state[2]+compileReturn(dat,fn instanceof AsyncFunction,scope[0],true,call+`)`)}return compileReturn(dat,fn instanceof AsyncFunction,scope[0],scope[1],call+`)`)};let compileErrorHandler=(fn,dat,scope)=>{let call=`f`+state[1].push(fn)+`(t`;if(fn.length>1){call+=`,c`;if(!scope[1])return state[2]+compileReturn(dat,fn instanceof AsyncFunction,scope[0],true,call+`)`)}return compileReturn(dat,fn instanceof AsyncFunction,scope[0],scope[1],call+`)`)};export let compileToState=router=>{state[0]={};state[1]=[];state[2]=`let c=mwc(r);`;state[3]=compileHandler;state[4]=compileErrorHandler;compileGroup(router,[false,false,,`return mwb`,false],``,``)};export let stateToString=()=>`"use strict";var t=["text/html","application/json"].map(c=>["Content-Type",c]),[mwh,mwj]=t,[mwoh,mwoj]=t.map(c=>({headers:[c]})),[mwn,mwb]=[404,400].map(s=>new Response(null,{status:s}));return(r)=>{`+compile(state[0],`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 mwn}`;export let stateToArgs=()=>{let depsString=`me,mwc`;let deps=state[1];for(let i=0;i<deps.length;i++)depsString+=`,f`+(i+1);return depsString};export default router=>{compileToState(router);return Function(stateToArgs(),stateToString())(isErr,createContext,...state[1])};
|
package/core/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default (middlewares,handlers,children)=>[middlewares,handlers
|
|
1
|
+
export default (middlewares,handlers,children)=>[middlewares,handlers,,children];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapl/web",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "A compiled web framework for all runtimes",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"repository": {
|
|
@@ -12,19 +12,19 @@
|
|
|
12
12
|
"main": "./index.js",
|
|
13
13
|
"types": "./index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@mapl/framework": "^0.2.
|
|
15
|
+
"@mapl/framework": "^0.2.6",
|
|
16
16
|
"@mapl/router": "^0.6.0",
|
|
17
17
|
"@safe-std/error": "^1.0.0"
|
|
18
18
|
},
|
|
19
19
|
"exports": {
|
|
20
20
|
"./constants": "./constants.js",
|
|
21
|
-
"
|
|
22
|
-
"./core/
|
|
21
|
+
"./utils/cors": "./utils/cors.js",
|
|
22
|
+
"./core/context": "./core/context.js",
|
|
23
|
+
"./core/middleware": "./core/middleware.js",
|
|
23
24
|
"./core": "./core/index.js",
|
|
24
25
|
"./core/compile": "./core/compile.js",
|
|
26
|
+
".": "./index.js",
|
|
25
27
|
"./core/utils": "./core/utils.js",
|
|
26
|
-
"./core/
|
|
27
|
-
"./utils/cors": "./utils/cors.js",
|
|
28
|
-
"./core/middleware": "./core/middleware.js"
|
|
28
|
+
"./core/handler": "./core/handler.js"
|
|
29
29
|
}
|
|
30
30
|
}
|