@mapl/web 0.6.2 → 0.6.4
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/bun/compiler/index.js +1 -1
- package/cloudflare/index.d.ts +1 -1
- package/compilers/call.js +1 -1
- package/package.json +1 -1
- package/response.js +1 -1
package/bun/compiler/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{exportScope,markExported}from"runtime-compiler";import{isHydrating}from"runtime-compiler/config";import{TMP_SCOPE,initScope,setHandlerArgs}from"../../compilers/globals.js";import{wrapScope}from"../../compilers/scope.js";import{initRouter,insertItem,toRoutes}from"./router.js";let PARAM_MAP;let loadToMethodRouter=(router,scope,prefix,content)=>{for(let i=0,layers=router[0];i<layers.length;i++){let self=layers[i];content+=self[0](self,scope)}for(let i=0,routes=router[1];i<routes.length;i++){let route=routes[i];let routeScope=scope.slice();let path=route[1];let routeContent;if(path.includes(`*`)){
|
|
1
|
+
import{exportScope,markExported}from"runtime-compiler";import{isHydrating}from"runtime-compiler/config";import{TMP_SCOPE,initScope,setHandlerArgs}from"../../compilers/globals.js";import{wrapScope}from"../../compilers/scope.js";import{initRouter,insertItem,toRoutes}from"./router.js";let PARAM_MAP;let loadToMethodRouter=(router,scope,prefix,content)=>{for(let i=0,layers=router[0];i<layers.length;i++){let self=layers[i];content+=self[0](self,scope)}for(let i=0,routes=router[1];i<routes.length;i++){let route=routes[i];let routeScope=scope.slice();let path=route[1];let routeContent;if(path.includes(`*`)){let paramCount;if(path.endsWith(`**`)){routeContent=`let{`;paramCount=0;let len=path.length-3,newPath=``,startIdx=0;for(let i=path.indexOf(`*`);i>-1&&i<len;i=path.indexOf(`*`,i+2)){let id=`q`+ paramCount++;routeContent+=id+`,`;newPath+=path.slice(startIdx,i)+`:`+id;startIdx=i+1}startIdx<len&&(newPath+=path.slice(startIdx,len));path=newPath+`/*`;routeContent+=`"*":q`+ paramCount++}else{routeContent=`let{q0`;paramCount=1;let firstStar=path.indexOf(`*`);let newPath=path.slice(0,firstStar)+`:q0`,startIdx=firstStar+1;for(let i=path.indexOf(`*`,firstStar+2);i>-1;i=path.indexOf(`*`,i+2)){let id=`q`+ paramCount++;routeContent+=id+`,`;newPath+=path.slice(startIdx,i)+`:`+id;startIdx=i+1}path=startIdx<path.length?newPath+path.slice(startIdx):newPath}routeContent+=`}=mr.params,mu=mr.url,e=mu.indexOf('?',11);`+content;for(let j=2,params=PARAM_MAP[paramCount];j<route.length;j++){let self=route[j];routeContent+=self[0](self,routeScope,params,paramCount)}}else{routeContent=`let mu=mr.url,e=mu.indexOf('?',11);`+content;for(let j=2;j<route.length;j++){let self=route[j];routeContent+=self[0](self,routeScope,``,0)}}insertItem(route[0],prefix+path,wrapScope(routeScope,routeContent))}for(let i=2;i<router.length;i++){let childRouter=router[i];loadToMethodRouter(childRouter[1],scope.slice(),childRouter[0]===`/`?prefix:prefix+childRouter[0],content)}};export let _load=router=>{initScope();initRouter();PARAM_MAP=[``,`q0`];for(let i=1;i<=8;i++)PARAM_MAP.push(`${PARAM_MAP[i]},q${i}`);loadToMethodRouter(router,[0],``,``)};export let loadToString=toRoutes;export let _hydrate=(router,scope)=>{for(let i=0,layers=router[0];i<layers.length;i++){let self=layers[i];self[0](self,scope)}for(let i=0,routes=router[1];i<routes.length;i++){let route=routes[i];let routeScope=scope.slice();let path=route[1];if(path.includes(`*`)){let paramCount=1;{let i=path.lastIndexOf(`*`);if(i>1){i=path.lastIndexOf(`*`,i-2);while(i>1){paramCount++;i=path.lastIndexOf(`*`,i-2)}i>-1&¶mCount++}}for(let j=2,params=PARAM_MAP[paramCount];j<route.length;j++){let self=route[j];self[0](self,routeScope,params,paramCount)}}else for(let j=2;j<route.length;j++){let self=route[j];self[0](self,routeScope,``,0)}}for(let i=2;i<router.length;i++)_hydrate(router[i][1],scope.slice())};export let build=isHydrating?router=>(_hydrate(router,[0]),markExported()):router=>(setHandlerArgs(`(mr,mi)`),_load(router),exportScope(TMP_SCOPE,loadToString()));
|
package/cloudflare/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/// <
|
|
1
|
+
/// <references types="@cloudflare/workers-types" />
|
|
2
2
|
import type { Request as WorkerRequest, ExecutionContext } from "@cloudflare/workers-types";
|
|
3
3
|
import type { Identifier } from "runtime-compiler";
|
|
4
4
|
export declare const request: Identifier<WorkerRequest>;
|
package/compilers/call.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{declareLocal,injectExternal}from"runtime-compiler";import{isHydrating}from"runtime-compiler/config";import{AsyncFunction}from"runtime-compiler/utils";import{TMP_SCOPE}from"./globals.js";export let buildCall=isHydrating?(scope,fn,_,argsCount)=>{injectExternal(fn);fn instanceof AsyncFunction&&(scope[0]|=1);fn.length>argsCount&&(scope[0]|=2);return``}:(scope,fn,args,argsCount)=>{let str=declareLocal(TMP_SCOPE,injectExternal(fn))+`(`+args;if(fn instanceof AsyncFunction){scope[0]|=1;str=`await `+str}if(fn.length>argsCount){scope[0]|=2;str+=`,mc`}return str+`)`};export let buildRouteCall=isHydrating?(self,scope,_,paramsCount)=>
|
|
1
|
+
import{declareLocal,injectExternal}from"runtime-compiler";import{isHydrating}from"runtime-compiler/config";import{AsyncFunction}from"runtime-compiler/utils";import{TMP_SCOPE}from"./globals.js";export let buildCall=isHydrating?(scope,fn,_,argsCount)=>{injectExternal(fn);fn instanceof AsyncFunction&&(scope[0]|=1);fn.length>argsCount&&(scope[0]|=2);return``}:(scope,fn,args,argsCount)=>{let str=declareLocal(TMP_SCOPE,injectExternal(fn))+`(`+args;if(fn instanceof AsyncFunction){scope[0]|=1;str=`await `+str}if(fn.length>argsCount){scope[0]|=2;str+=`,mc`}return str+`)`};export let buildRouteCall=isHydrating?(self,scope,_,paramsCount)=>buildCall(scope,self[1],``,self[2].length+paramsCount):(self,scope,params,paramsCount)=>{let args=self[2];return args.length>0?paramsCount>0?buildCall(scope,self[1],args.join()+`,`+params,args.length+paramsCount):buildCall(scope,self[1],args.join(),args.length):paramsCount>0?buildCall(scope,self[1],params,paramsCount):buildCall(scope,self[1],``,0)};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@mapl/web","version":"0.6.
|
|
1
|
+
{"name":"@mapl/web","version":"0.6.4","description":"A compiled web framework for all runtimes","keywords":["fast","lightweight","cross-runtime","framework","web","backend"],"repository":{"type":"git","url":"git+https://github.com/mapljs/web.git"},"license":"MIT","type":"module","main":"./index.js","types":"./index.d.ts","dependencies":{"@mapl/router":"^0.8.4","@safe-std/error":"^2.0.4","runtime-compiler":"^3.1.1"},"exports":{"./utils":"./utils.js","./bun":"./bun/index.js","./compilers/globals":"./compilers/globals.js","./constants":"./constants.js","./bun/compiler":"./bun/compiler/index.js","./bun/compiler/router":"./bun/compiler/router.js","./deno/compiler":"./deno/compiler.js","./cloudflare":"./cloudflare/index.js",".":"./index.js","./deno":"./deno/index.js","./router":"./router.js","./compilers/call":"./compilers/call.js","./cloudflare/compiler":"./cloudflare/compiler.js","./layer":"./layer.js","./generic":"./generic/index.js","./response":"./response.js","./generic/compiler":"./generic/compiler.js","./compilers/scope":"./compilers/scope.js"}}
|
package/response.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{buildRouteCall}from"./compilers/call.js";let loadRaw=(self,scope,params,paramsCount)=>`return new Response(`+buildRouteCall(self,scope,params,paramsCount)+((scope[0]&2)===2?`,mc)`:`)`);export let raw=(fn,...args)=>[loadRaw,fn,args];let loadJSON=(self,scope,params,paramsCount)=>`return Response.json(`+buildRouteCall(self,scope,params,paramsCount)+((scope[0]&2)===2?`,mc)`:`)`);export let json=(fn,...args)=>[loadJSON,fn,args];let loadHTML=(self,scope,params,paramsCount)=>{let call=buildRouteCall(self,scope,params,paramsCount);return(scope[0]&2)===2?`mh.push(mhh);return new Response(`+call+`,mc)`:`return new Response(`+call+`,mho)`};export let html=(fn,...args)=>[loadHTML,fn,args];
|
|
1
|
+
import{buildRouteCall}from"./compilers/call.js";import{isHydrating}from"runtime-compiler/config";let loadRaw=isHydrating?buildRouteCall:(self,scope,params,paramsCount)=>`return new Response(`+buildRouteCall(self,scope,params,paramsCount)+((scope[0]&2)===2?`,mc)`:`)`);export let raw=(fn,...args)=>[loadRaw,fn,args];let loadJSON=isHydrating?buildRouteCall:(self,scope,params,paramsCount)=>`return Response.json(`+buildRouteCall(self,scope,params,paramsCount)+((scope[0]&2)===2?`,mc)`:`)`);export let json=(fn,...args)=>[loadJSON,fn,args];let loadHTML=isHydrating?buildRouteCall:(self,scope,params,paramsCount)=>{let call=buildRouteCall(self,scope,params,paramsCount);return(scope[0]&2)===2?`mh.push(mhh);return new Response(`+call+`,mc)`:`return new Response(`+call+`,mho)`};export let html=(fn,...args)=>[loadHTML,fn,args];
|