@mapl/web 0.6.4 → 0.6.6

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.
@@ -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(`**`)){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&&paramCount++}}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()));
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&&paramCount++}}for(let j=2;j<route.length;j++){let self=route[j];self[0](self,routeScope,``,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()));
@@ -1,4 +1,5 @@
1
1
  import { type ExportedDependency, type Value } from "runtime-compiler";
2
+ import type { ExportedHandlerFetchHandler, Cloudflare } from "@cloudflare/workers-types";
2
3
  import type { Router } from "../router.ts";
3
4
  /**
4
5
  * Describe compiler compiled result
@@ -1,5 +1,4 @@
1
- /// <references types="@cloudflare/workers-types" />
2
- import type { Request as WorkerRequest, ExecutionContext } from "@cloudflare/workers-types";
1
+ import type { Request as WorkerRequest, ExecutionContext, Cloudflare } from "@cloudflare/workers-types";
3
2
  import type { Identifier } from "runtime-compiler";
4
3
  export declare const request: Identifier<WorkerRequest>;
5
4
  export declare const env: Identifier<Cloudflare.Env>;
package/package.json CHANGED
@@ -1 +1 @@
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"}}
1
+ {"name":"@mapl/web","version":"0.6.6","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","./router":"./router.js","./constants":"./constants.js",".":"./index.js","./response":"./response.js","./bun/compiler/router":"./bun/compiler/router.js","./cloudflare/compiler":"./cloudflare/compiler.js","./cloudflare":"./cloudflare/index.js","./bun":"./bun/index.js","./compilers/call":"./compilers/call.js","./bun/compiler":"./bun/compiler/index.js","./deno/compiler":"./deno/compiler.js","./compilers/scope":"./compilers/scope.js","./generic":"./generic/index.js","./deno":"./deno/index.js","./compilers/globals":"./compilers/globals.js","./generic/compiler":"./generic/compiler.js"}}
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
- export declare const handle: <Path extends string>(method: string, path: Path, ...layers: AnyRouteLayer<InferParams<Path>>[]) => Route;
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
- export declare const patch: HandleMethod;
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 GET=[`GET`];export let get=(...args)=>GET.concat(args);let POST=[`POST`];export let post=(...args)=>POST.concat(args);let PUT=[`PUT`];export let put=(...args)=>PUT.concat(args);let DELETE=[`DELETE`];export let del=(...args)=>DELETE.concat(args);let PATCH=[`PATCH`];export let patch=(...args)=>PATCH.concat(args);let OPTIONS=[`OPTIONS`];export let options=(...args)=>OPTIONS.concat(args);
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);