@mapl/web 0.2.0-alpha.6 → 0.2.0-alpha.7

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 CHANGED
@@ -107,17 +107,3 @@ import { isHydrating } from 'runtime-compiler/config';
107
107
  // Use this to for minifiedrs to eliminate unused code path in final output
108
108
  isHydrating;
109
109
  ```
110
-
111
- ### Compiling external dependencies
112
- ```ts
113
- import { injectDependency, markDependency, getDependency } from 'runtime-compiler';
114
- import { isHydrating } from 'runtime-compiler/config';
115
-
116
- // Better tree shaking
117
- const hello = isHydrating
118
- ? markDependency<() => void>()
119
- : injectDependency<() => void>(`() => console.log('hello')`);
120
-
121
- // After compiler is executed
122
- getDependency(hello)();
123
- ```
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 urlRouter;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;fnAsync&&(result=`await `+result);let str=typ==null?`return new Response(`+result+(contextCreated?`,c)`:`)`):contextCreated?`hd.push(`+(typ===`json`?`j`:`h`)+`);return new Response(`+(typ===`json`?`JSON.stringify(`+result+`)`:result)+`,c)`:`return new Response(`+(typ===`json`?`JSON.stringify(`+result+`),oj`:result+`,oh`)+`)`;return fnAsync&&!scopeAsync?`return (async()=>{`+str+`})()`:str};let compileToState=router=>{urlRouter={};setHooks({compileHandler:(fn,dat,path,scope)=>{let call=injectExternalDependency(fn)+`(`;let paramCount=countParams(path);paramCount>0&&(call+=paramArgs[paramCount]);if(fn.length>paramCount){call+=paramCount===0?`c`:`,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+`)`)},compileErrorHandler:(fn,dat,scope)=>{let call=injectExternalDependency(fn)+`(t`;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+`)`)},registerCompiled:(method,path,content)=>insertItem(urlRouter,method,path,content)});setContextInit(`let hd=[],c={status:200,req:r,headers:hd};`);compileGroup(router,[false,false,,`return b`,false],``,``)};export let compileToString=router=>{compileToState(router);return`()=>{var t=["text/html","application/json"].map(c=>["Content-Type",c]),[h,j]=t,[oh,oj]=t.map(c=>({headers:[c]})),[n,b]=[404,400].map(s=>new Response(null,{status:s}));return(r)=>{`+compile(urlRouter,`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 n}}`};export let compileToDependency=router=>exportDependency(injectDependency(`(`+compileToString(router)+`)()`));export let compileToHandler=async router=>{let id=compileToDependency(router);await evaluate();return getDependency(id)};export let compileToHandlerSync=router=>{let id=compileToDependency(router);evaluateSync();return getDependency(id)};
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 urlRouter;let paramArgs=createArgSet(new Array(16).fill(0).map((_1,i)=>`q`+i));console.log(paramArgs);let compileReturn=(dat,fnAsync,scopeAsync,contextCreated,result)=>{let typ=dat.type;if(typ===`raw`)return`return `+result;fnAsync&&(result=`await `+result);let str=typ==null?`return new Response(`+result+(contextCreated?`,c)`:`)`):contextCreated?`hd.push(`+(typ===`json`?`j`:`h`)+`);return new Response(`+(typ===`json`?`JSON.stringify(`+result+`)`:result)+`,c)`:`return new Response(`+(typ===`json`?`JSON.stringify(`+result+`),oj`:result+`,oh`)+`)`;return fnAsync&&!scopeAsync?`return (async()=>{`+str+`})()`:str};let compileToState=router=>{urlRouter={};setHooks({compileHandler:(fn,dat,path,scope)=>{let call=injectExternalDependency(fn)+`(`;let paramCount=countParams(path);paramCount>0&&(call+=paramArgs[paramCount]);if(fn.length>paramCount){call+=paramCount===0?`c`:`,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+`)`)},compileErrorHandler:(fn,dat,scope)=>{let call=injectExternalDependency(fn)+`(t`;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+`)`)},registerCompiled:(method,path,content)=>insertItem(urlRouter,method,path,content)});setContextInit(`let hd=[],c={status:200,req:r,headers:hd};`);compileGroup(router,[false,false,,`return b`,false],``,``)};export let compileToString=router=>{compileToState(router);return`()=>{var t=["text/html","application/json"].map(c=>["Content-Type",c]),[h,j]=t,[oh,oj]=t.map(c=>({headers:[c]})),[n,b]=[404,400].map(s=>new Response(null,{status:s}));return(r)=>{`+compile(urlRouter,`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 n}}`};export let compileToDependency=router=>exportDependency(injectDependency(`(`+compileToString(router)+`)()`));export let compileToHandler=async router=>{let id=compileToDependency(router);await evaluate();return getDependency(id)};export let compileToHandlerSync=router=>{let id=compileToDependency(router);evaluateSync();return getDependency(id)};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapl/web",
3
- "version": "0.2.0-alpha.6",
3
+ "version": "0.2.0-alpha.7",
4
4
  "description": "A compiled web framework for all runtimes",
5
5
  "keywords": ["fast", "lightweight", "cross-runtime", "framework", "web", "backend"],
6
6
  "repository": {
@@ -12,7 +12,7 @@
12
12
  "main": "./index.js",
13
13
  "types": "./index.d.ts",
14
14
  "dependencies": {
15
- "@mapl/framework": "^0.4.3",
15
+ "@mapl/framework": "^0.4.4",
16
16
  "@mapl/router": "^0.6.2",
17
17
  "@safe-std/error": "^1.0.1",
18
18
  "runtime-compiler": "^1.0.8"
@@ -22,16 +22,16 @@
22
22
  },
23
23
  "exports": {
24
24
  "./constants": "./constants.js",
25
- "./core": "./core/index.js",
26
- "./core/middleware": "./core/middleware.js",
27
- "./core/handler": "./core/handler.js",
28
- "./core/context": "./core/context.js",
25
+ ".": "./index.js",
26
+ "./utils/static-headers": "./utils/static-headers.js",
29
27
  "./utils/secure-headers": "./utils/secure-headers.js",
30
- "./utils/cors": "./utils/cors.js",
31
28
  "./core/utils": "./core/utils.js",
32
29
  "./compiler/jit": "./compiler/jit.js",
33
- "./utils/static-headers": "./utils/static-headers.js",
34
- ".": "./index.js",
35
- "./compiler/aot": "./compiler/aot.js"
30
+ "./core/middleware": "./core/middleware.js",
31
+ "./core": "./core/index.js",
32
+ "./compiler/aot": "./compiler/aot.js",
33
+ "./core/context": "./core/context.js",
34
+ "./core/handler": "./core/handler.js",
35
+ "./utils/cors": "./utils/cors.js"
36
36
  }
37
37
  }