@mapl/web 0.6.3 → 0.6.5
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/compiler.d.ts +1 -0
- package/cloudflare/index.d.ts +1 -1
- package/package.json +1 -1
- package/response.js +1 -1
- package/router.d.ts +41 -2
- package/router.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(`*`)){let paramCount;if(path.endsWith(`**`)){
|
|
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 WILDCARD_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=content;if(path.includes(`*`)){routeContent=`let q=mr.params;`+routeContent;let paramCount=1;if(path.endsWith(`**`)){let newPath=`/*`,endIdx=path.length-3,nextIdx=path.lastIndexOf(`*`,endIdx);while(nextIdx>1){newPath=`:q`+ paramCount+++path.slice(nextIdx+1,endIdx)+newPath;endIdx=nextIdx;nextIdx=path.lastIndexOf(`*`,nextIdx-2)}path=nextIdx>-1?path.slice(0,nextIdx-1)+`:q`+ paramCount+++path.slice(nextIdx+1,endIdx)+newPath:path.slice(0,endIdx)+newPath;for(let j=2,params=WILDCARD_PARAM_MAP[paramCount];j<route.length;j++){let self=route[j];routeContent+=self[0](self,routeScope,params,paramCount)}}else{let nextIdx=path.lastIndexOf(`*`),newPath=`:q0`+path.slice(nextIdx+1),endIdx=nextIdx;nextIdx=path.lastIndexOf(`*`,nextIdx-2);while(nextIdx>1){newPath=`:q`+ paramCount+++path.slice(nextIdx+1,endIdx)+newPath;endIdx=nextIdx;nextIdx=path.lastIndexOf(`*`,nextIdx-2)}path=nextIdx>-1?path.slice(0,nextIdx-1)+`:q`+ paramCount+++path.slice(nextIdx+1,endIdx)+newPath:path.slice(0,endIdx)+newPath;for(let j=2,params=PARAM_MAP[paramCount];j<route.length;j++){let self=route[j];routeContent+=self[0](self,routeScope,params,paramCount)}}}else 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=[``,`q.q0`];WILDCARD_PARAM_MAP=[``,`q['*']`];for(let i=1;i<=8;i++){let newParam=`q.q`+i+`,`;PARAM_MAP.push(newParam+PARAM_MAP[i]);WILDCARD_PARAM_MAP.push(newParam+WILDCARD_PARAM_MAP[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/compiler.d.ts
CHANGED
package/cloudflare/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Request as WorkerRequest, ExecutionContext } from "@cloudflare/workers-types";
|
|
1
|
+
import type { Request as WorkerRequest, ExecutionContext, Cloudflare } from "@cloudflare/workers-types";
|
|
2
2
|
import type { Identifier } from "runtime-compiler";
|
|
3
3
|
export declare const request: Identifier<WorkerRequest>;
|
|
4
4
|
export declare const env: Identifier<Cloudflare.Env>;
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@mapl/web","version":"0.6.
|
|
1
|
+
{"name":"@mapl/web","version":"0.6.5","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","./layer":"./layer.js",".":"./index.js","./constants":"./constants.js","./router":"./router.js","./generic":"./generic/index.js","./cloudflare/compiler":"./cloudflare/compiler.js","./response":"./response.js","./deno":"./deno/index.js","./generic/compiler":"./generic/compiler.js","./compilers/scope":"./compilers/scope.js","./compilers/globals":"./compilers/globals.js","./deno/compiler":"./deno/compiler.js","./bun/compiler":"./bun/compiler/index.js","./compilers/call":"./compilers/call.js","./bun":"./bun/index.js","./cloudflare":"./cloudflare/index.js","./bun/compiler/router":"./bun/compiler/router.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];
|
package/router.d.ts
CHANGED
|
@@ -22,11 +22,50 @@ export type HandleMethod = <Path extends string>(path: Path, ...layers: AnyRoute
|
|
|
22
22
|
* Create a router
|
|
23
23
|
*/
|
|
24
24
|
export declare const init: (...args: Router) => Router;
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Handle custom request method.
|
|
27
|
+
*/
|
|
28
|
+
export declare const handle: <
|
|
29
|
+
Method extends string,
|
|
30
|
+
Path extends string
|
|
31
|
+
>(method: Uppercase<Method>, path: Path, ...layers: AnyRouteLayer<InferParams<Path>>[]) => Route;
|
|
32
|
+
/**
|
|
33
|
+
* Mount a child router.
|
|
34
|
+
*/
|
|
26
35
|
export declare const mount: (...args: ChildRouter) => ChildRouter;
|
|
36
|
+
/**
|
|
37
|
+
* Requests a representation of the specified resource. Requests using GET should only retrieve data and should not contain a request content.
|
|
38
|
+
*/
|
|
27
39
|
export declare const get: HandleMethod;
|
|
40
|
+
/**
|
|
41
|
+
* Asks for a response identical to a GET request, but without a response body.
|
|
42
|
+
*/
|
|
43
|
+
export declare const head: HandleMethod;
|
|
44
|
+
/**
|
|
45
|
+
* Submits an entity to the specified resource, often causing a change in state or side effects on the server.
|
|
46
|
+
*/
|
|
28
47
|
export declare const post: HandleMethod;
|
|
48
|
+
/**
|
|
49
|
+
* Replaces all current representations of the target resource with the request content.
|
|
50
|
+
*/
|
|
29
51
|
export declare const put: HandleMethod;
|
|
52
|
+
/**
|
|
53
|
+
* Deletes the specified resource.
|
|
54
|
+
*/
|
|
30
55
|
export declare const del: HandleMethod;
|
|
31
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Establishes a tunnel to the server identified by the target resource.
|
|
58
|
+
*/
|
|
59
|
+
export declare const connect: HandleMethod;
|
|
60
|
+
/**
|
|
61
|
+
* Describes the communication options for the target resource.
|
|
62
|
+
*/
|
|
32
63
|
export declare const options: HandleMethod;
|
|
64
|
+
/**
|
|
65
|
+
* Performs a message loop-back test along the path to the target resource.
|
|
66
|
+
*/
|
|
67
|
+
export declare const trace: HandleMethod;
|
|
68
|
+
/**
|
|
69
|
+
* Applies partial modifications to a resource.
|
|
70
|
+
*/
|
|
71
|
+
export declare const patch: HandleMethod;
|
package/router.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{argsToArray}from"./utils.js";export let init=argsToArray;export let handle=argsToArray;export let mount=argsToArray;let
|
|
1
|
+
import{argsToArray}from"./utils.js";export let init=argsToArray;export let handle=argsToArray;export let mount=argsToArray;export let get=(...args)=>(args.unshift(`GET`),args);export let head=(...args)=>(args.unshift(`HEAD`),args);export let post=(...args)=>(args.unshift(`POST`),args);export let put=(...args)=>(args.unshift(`PUT`),args);export let del=(...args)=>(args.unshift(`DELETE`),args);export let connect=(...args)=>(args.unshift(`CONNECT`),args);export let options=(...args)=>(args.unshift(`OPTIONS`),args);export let trace=(...args)=>(args.unshift(`TRACE`),args);export let patch=(...args)=>(args.unshift(`PATCH`),args);
|