@mapl/web 0.3.18 → 0.4.1
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 +0 -29
- package/build/rolldown.d.ts +1 -0
- package/build/utils.d.ts +1 -0
- package/bun/compiler/jit.d.ts +4 -5
- package/bun/compiler/jit.js +1 -1
- package/bun/compiler/router.js +1 -1
- package/bun/index.d.ts +1 -1
- package/compiler/aot.d.ts +2 -3
- package/compiler/aot.js +1 -1
- package/compiler/jit.d.ts +0 -1
- package/compiler/jit.js +1 -1
- package/constants.js +1 -1
- package/core/handler.d.ts +14 -4
- package/core/index.d.ts +2 -2
- package/core/middleware.d.ts +3 -3
- package/core/utils.d.ts +1 -0
- package/package.json +18 -18
- package/utils/basic-auth.d.ts +2 -2
- package/utils/body-limit.js +1 -1
- package/utils/cors.d.ts +3 -2
- package/utils/cors.js +1 -1
- package/utils/static-headers.js +1 -1
package/README.md
CHANGED
|
@@ -1,34 +1,5 @@
|
|
|
1
1
|
A compiled web framework for all runtimes.
|
|
2
2
|
|
|
3
|
-
```ts
|
|
4
|
-
import { router, handle, layer } from '@mapl/web';
|
|
5
|
-
import { compileToHandler } from '@mapl/web/compiler/jit';
|
|
6
|
-
|
|
7
|
-
const api = router([], [
|
|
8
|
-
handle.get('/', () => 'Hi')
|
|
9
|
-
]);
|
|
10
|
-
|
|
11
|
-
const app = router(
|
|
12
|
-
// Middlewares
|
|
13
|
-
[ layer.attach('id', () => performance.now()) ],
|
|
14
|
-
|
|
15
|
-
// Routes
|
|
16
|
-
[
|
|
17
|
-
handle.get('/path', (c) => '' + c.id, {
|
|
18
|
-
// Response wrapper
|
|
19
|
-
type: handle.text
|
|
20
|
-
})
|
|
21
|
-
],
|
|
22
|
-
|
|
23
|
-
// Subrouters
|
|
24
|
-
{ '/api': api }
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
export default {
|
|
28
|
-
fetch: await compileToHandler(app)
|
|
29
|
-
};
|
|
30
|
-
```
|
|
31
|
-
|
|
32
3
|
## AOT compilation (experimental)
|
|
33
4
|
Build `@mapl/web` to improve startup time.
|
|
34
5
|
|
package/build/rolldown.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export interface MaplOptions {
|
|
|
28
28
|
*/
|
|
29
29
|
hydrate?: MaplBuildOptions;
|
|
30
30
|
}
|
|
31
|
+
// Plugins to manipulate imports
|
|
31
32
|
export declare const hydrateImportsPlugin: RolldownPluginOption;
|
|
32
33
|
export declare const SERVER_ENTRY = "index.js";
|
|
33
34
|
export declare const hydrate: (options: MaplOptions) => Promise<void>;
|
package/build/utils.d.ts
CHANGED
package/bun/compiler/jit.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { RouterTag } from "../../core/index.js";
|
|
2
2
|
import { type CompiledDependency } from "runtime-compiler";
|
|
3
3
|
import type { BunContext } from "../index.js";
|
|
4
|
-
import type {
|
|
5
|
-
export type BunRoutes<T extends string = string> = Record<T, RouterTypes.RouteValue<T>>;
|
|
4
|
+
import type { Serve } from "bun";
|
|
6
5
|
export declare const compileToString: (router: RouterTag<BunContext>) => string;
|
|
7
|
-
export declare const compileToExportedDependency: (router: RouterTag<BunContext>) => CompiledDependency<
|
|
8
|
-
export declare const compileToHandler: (router: RouterTag<BunContext>) => Promise<
|
|
9
|
-
export declare const compileToHandlerSync: (router: RouterTag<BunContext>) =>
|
|
6
|
+
export declare const compileToExportedDependency: (router: RouterTag<BunContext>) => CompiledDependency<Serve.Routes<any, any>>;
|
|
7
|
+
export declare const compileToHandler: (router: RouterTag<BunContext>) => Promise<Serve.Routes<any, any>>;
|
|
8
|
+
export declare const compileToHandlerSync: (router: RouterTag<BunContext>) => Serve.Routes<any, any>;
|
package/bun/compiler/jit.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{compileGroup,
|
|
1
|
+
import{compileGroup,contextInit,setContextInit,hooks,getParamArgs}from"@mapl/framework";import{countParams}from"@mapl/router/path";import{AsyncFunction,exportDependency,getDependency,injectDependency,injectExternalDependency}from"runtime-compiler";import{evaluate,evaluateSync}from"runtime-compiler/jit";import{compileErrorHandler,compileReturn,RES400}from"../../compiler/jit.js";import{insertRoute,resetRouter,routerToString}from"./router.js";let compileToState=router=>{resetRouter();hooks.compileHandler=(handler,prevContent,path,scope)=>{let fn=handler[2];let paramCount=countParams(handler[1]);let call=injectExternalDependency(fn)+`(`+getParamArgs(paramCount);if(fn.length>paramCount){call+=`c`;if(!scope[1]){insertRoute(handler[0],path,prevContent+contextInit+compileReturn(handler[3],fn instanceof AsyncFunction,scope[0],true,call+`)`)+(scope[0]?`})()`:``));return}}insertRoute(handler[0],path,prevContent+compileReturn(handler[3],fn instanceof AsyncFunction,scope[0],scope[1],call+`)`)+(scope[0]?`})()`:``))};hooks.compileErrorHandler=compileErrorHandler;setContextInit(`let h=[],c={status:200,req:r,headers:h,server:s};`);compileGroup(router,[false,false,,`return `+RES400(),false],``,``)};export let compileToString=router=>{compileToState(router);return routerToString()};export let compileToExportedDependency=router=>exportDependency(injectDependency(compileToString(router)));export let compileToHandler=async router=>{let id=compileToExportedDependency(router);await evaluate();return getDependency(id)};export let compileToHandlerSync=router=>{let id=compileToExportedDependency(router);evaluateSync();return getDependency(id)};
|
package/bun/compiler/router.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{injectDependency}from"runtime-compiler";import{RES404}from"../../compiler/jit.js";let ROUTES;export let resetRouter=()=>{ROUTES={}};export let insertRoute=(method,path,content)=>{let isWildcard=path.endsWith(`**`);let i=0;let bunPattern=isWildcard?path.slice(-2).replace(/\*/g,()=>`:q`+ i++)+`*`:path.replace(/\*/g,()=>`:q`+ i++);let str=`(r,s)=>{`;if(i>0){str+=`let {q0`;for(let j=1,l=i-(isWildcard?1:0);j<l;j++)str+=`q,`+j;str+=`}=r.params`+(isWildcard?`,q`+i+`=r.params["*"];`:`;`)}(ROUTES[bunPattern]??={})[method]=str+content+`}`;if(method!==``&&method!==`GET`&&method!==`HEAD`&&method!==`OPTIONS`&&method!==`DELETE`&&method!==`PATCH`&&method!==`POST`&&method!==`PUT`)ROUTES[bunPattern][``]??=RES404;if(isWildcard)(ROUTES[bunPattern===`/*`?`/`:bunPattern.slice(0,-3)]??={})[method]??=RES404};export let routerToString=()=>{let str=`{`;for(let pattern in ROUTES){str+=`"`+pattern+`":`;let methods=ROUTES[pattern];let allMethods=methods[``];if(allMethods==null){str+=`{`;for(let method in methods)str+=method+`:`+methods[method]+`,`;str+=`},`}else if(Object.keys(methods).length===1)str+=methods[``]+`,`;else{str+=`(r,s)=>`;for(let method in methods)if(method!==``){let fn=methods[method];str+=`r.method==="`+method+`"?`+(fn.startsWith(`(r,s)=>`)?injectDependency(fn)+`(r,s)`:fn)+`:`}str+=(allMethods.startsWith(`(r,s)=>`)?injectDependency(allMethods)+`(r,s)`:allMethods)+`,`}}return str+`}`};
|
|
1
|
+
import{injectDependency}from"runtime-compiler";import{RES404}from"../../compiler/jit.js";let ROUTES;export let resetRouter=()=>{ROUTES={}};export let insertRoute=(method,path,content)=>{let isWildcard=path.endsWith(`**`);let i=0;let bunPattern=isWildcard?path.slice(-2).replace(/\*/g,()=>`:q`+ i++)+`*`:path.replace(/\*/g,()=>`:q`+ i++);let str=`(r,s)=>{`;if(i>0){str+=`let {q0`;for(let j=1,l=i-(isWildcard?1:0);j<l;j++)str+=`q,`+j;str+=`}=r.params`+(isWildcard?`,q`+i+`=r.params["*"];`:`;`)}(ROUTES[bunPattern]??={})[method]=str+content+`}`;if(method!==``&&method!==`GET`&&method!==`HEAD`&&method!==`OPTIONS`&&method!==`DELETE`&&method!==`PATCH`&&method!==`POST`&&method!==`PUT`)ROUTES[bunPattern][``]??=RES404();if(isWildcard)(ROUTES[bunPattern===`/*`?`/`:bunPattern.slice(0,-3)]??={})[method]??=RES404()};export let routerToString=()=>{let str=`{`;for(let pattern in ROUTES){str+=`"`+pattern+`":`;let methods=ROUTES[pattern];let allMethods=methods[``];if(allMethods==null){str+=`{`;for(let method in methods)str+=method+`:`+methods[method]+`,`;str+=`},`}else if(Object.keys(methods).length===1)str+=methods[``]+`,`;else{str+=`(r,s)=>`;for(let method in methods)if(method!==``){let fn=methods[method];str+=`r.method==="`+method+`"?`+(fn.startsWith(`(r,s)=>`)?injectDependency(fn)+`(r,s)`:fn)+`:`}str+=(allMethods.startsWith(`(r,s)=>`)?injectDependency(allMethods)+`(r,s)`:allMethods)+`,`}}return str+`}`};
|
package/bun/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type ChildRouters, type InferHandlers, type InferRouter } from "../core
|
|
|
3
3
|
import type { MiddlewareTypes } from "../core/middleware.js";
|
|
4
4
|
export interface BunContext {
|
|
5
5
|
readonly req: BunRequest;
|
|
6
|
-
readonly server: Server
|
|
6
|
+
readonly server: Server<any>;
|
|
7
7
|
}
|
|
8
8
|
export declare const router: <
|
|
9
9
|
const T extends MiddlewareTypes<BunContext, any, any>[],
|
package/compiler/aot.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { RouterTag } from "../core/index.js";
|
|
2
2
|
import "../core/context.js";
|
|
3
3
|
import type { GenericContext } from "../index.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
declare const _default: (router: RouterTag<GenericContext> | RouterTag<BunContext>) => void;
|
|
4
|
+
export declare const hydrateRouter: (router: RouterTag<GenericContext>) => void;
|
|
5
|
+
declare const _default: (router: RouterTag<GenericContext>) => void;
|
|
7
6
|
export default _default;
|
package/compiler/aot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{hydrateDependency,hooks}from"@mapl/framework";import{injectExternalDependency,markExported}from"runtime-compiler";import"../core/context.js";
|
|
1
|
+
import{hydrateDependency,hooks}from"@mapl/framework";import{countParams}from"@mapl/router/path";import{injectExternalDependency,markExported}from"runtime-compiler";import"../core/context.js";export let hydrateRouter=router=>{hooks.compileHandler=(handler,_,_1,scope)=>{let fn=handler[2];injectExternalDependency(fn);handler[3]?.handler?.(``,scope[1]||fn.length>countParams(handler[1]))};hooks.compileErrorHandler=(_,fn,dat,scope)=>{injectExternalDependency(fn);dat?.handler?.(``,scope[1]||fn.length>1);return``};hydrateDependency(router,[false,false,,``,false],``)};export default router=>{hydrateRouter(router);markExported()};
|
package/compiler/jit.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ import type { FetchFn } from "../core/utils.js";
|
|
|
4
4
|
import type { GenericContext } from "../index.js";
|
|
5
5
|
export declare const RES404: () => string;
|
|
6
6
|
export declare const RES400: () => string;
|
|
7
|
-
export declare const paramArgs: string[];
|
|
8
7
|
export declare const compileToString: (router: RouterTag<GenericContext>) => string;
|
|
9
8
|
export declare const compileToExportedDependency: (router: RouterTag<GenericContext>) => CompiledDependency<FetchFn>;
|
|
10
9
|
export declare const compileToHandler: (router: RouterTag<GenericContext>) => Promise<FetchFn>;
|
package/compiler/jit.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{compileGroup,
|
|
1
|
+
import{compileGroup,contextInit,setContextInit,hooks,getParamArgs}from"@mapl/framework";import compile from"@mapl/router/method/compiler";import{countParams}from"@mapl/router/path";import{insertItem}from"@mapl/router/method";import{AsyncFunction,exportDependency,getDependency,injectDependency,injectExternalDependency,lazyDependency,noOp}from"runtime-compiler";import{evaluate,evaluateSync}from"runtime-compiler/jit";import{isHydrating}from"runtime-compiler/config";let URL_ROUTER;export let RES404=isHydrating?noOp:lazyDependency(injectDependency,`new Response(null,{status:404})`);export let RES400=isHydrating?noOp:lazyDependency(injectDependency,`new Response(null,{status:400})`);export let compileReturn=(dat,fnAsync,scopeAsync,contextCreated,result)=>{let res=dat?.handler;if(res==null)return`return `+result;let str=res(fnAsync?`await `+result:result,contextCreated);return fnAsync&&!scopeAsync?`return (async()=>{`+str+`})()`:str};export let compileErrorHandler=(input,fn,dat,scope)=>{let call=injectExternalDependency(fn)+`(`+input;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+`)`)};let compileToState=router=>{URL_ROUTER={};hooks.compileHandler=(handler,prevContent,path,scope)=>{let fn=handler[2];let paramCount=countParams(handler[1]);let call=injectExternalDependency(fn)+`(`+getParamArgs(paramCount);if(fn.length>paramCount){call+=`c`;if(!scope[1]){insertItem(URL_ROUTER,handler[0],path,prevContent+contextInit+compileReturn(handler[3],fn instanceof AsyncFunction,scope[0],true,call+`)`)+(scope[0]?`})()`:``));return}}insertItem(URL_ROUTER,handler[0],path,prevContent+compileReturn(handler[3],fn instanceof AsyncFunction,scope[0],scope[1],call+`)`)+(scope[0]?`})()`:``))};hooks.compileErrorHandler=compileErrorHandler;setContextInit(`let h=[],c={status:200,req:r,headers:h};`);compileGroup(router,[false,false,,`return `+RES400(),false],``,``)};export let compileToString=router=>{compileToState(router);return`(r)=>{`+compile(URL_ROUTER,`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 `+RES404()+`}`};export let compileToExportedDependency=router=>exportDependency(injectDependency(compileToString(router)));export let compileToHandler=async router=>{let id=compileToExportedDependency(router);await evaluate();return getDependency(id)};export let compileToHandlerSync=router=>{let id=compileToExportedDependency(router);evaluateSync();return getDependency(id)};
|
package/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{PATH,REQ,URL,PATH_START,PATH_END}from"@mapl/framework/constants";export*from"@mapl/framework/constants";export let HEADERS=`h`;export let SERVER_INFO=`s`;export let BUN_FN_ARGS=`(`+REQ
|
|
1
|
+
import{PATH,REQ,URL,PATH_START,PATH_END}from"@mapl/framework/constants";export*from"@mapl/framework/constants";export let HEADERS=`h`;export let SERVER_INFO=`s`;export let BUN_FN_ARGS=`(`+REQ+`,s)`;export let BUN_FN_START=BUN_FN_ARGS+`=>`;export let PARSE_PATH=`let `+URL+`=`+REQ+`.url,`+PATH_START+`=`+URL+`.indexOf("/",12)+1,`+PATH_END+`=`+URL+`.indexOf("?",`+PATH_START+`),`+PATH+`=`+PATH_END+`===-1?`+URL+`.slice(`+PATH_START+`):`+URL+`.slice(`+PATH_START+`,`+PATH_END+`);`;
|
package/core/handler.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { AnyErr } from "@safe-std/error";
|
|
2
2
|
import type { Context } from "./context.js";
|
|
3
3
|
import type { RouterTag } from "./index.js";
|
|
4
|
-
import type { RequestMethod } from "./utils.js";
|
|
4
|
+
import type { MaybePromise, RequestMethod } from "./utils.js";
|
|
5
5
|
export interface HandlerResponse<I = any> {
|
|
6
6
|
(response: string, hasContext: boolean): string;
|
|
7
7
|
(response: string, hasContext: boolean, _: I): string;
|
|
8
8
|
}
|
|
9
9
|
export interface HandlerData extends Record<symbol, any> {
|
|
10
|
-
|
|
10
|
+
handler?: HandlerResponse;
|
|
11
11
|
}
|
|
12
12
|
export type Handler<
|
|
13
13
|
Params extends string[] = string[],
|
|
@@ -15,7 +15,8 @@ export type Handler<
|
|
|
15
15
|
R = any
|
|
16
16
|
> = (...args: [...params: Params, c: Context & T]) => R;
|
|
17
17
|
export type InferPath<T extends string> = T extends `${string}*${infer Next}` ? Next extends "*" ? [string] : [string, ...InferPath<Next>] : [];
|
|
18
|
-
|
|
18
|
+
// toResponse macro
|
|
19
|
+
export type InferReturn<D extends HandlerData | undefined> = MaybePromise<D extends HandlerData ? D["handler"] extends HandlerResponse<infer I> ? I : Response : Response>;
|
|
19
20
|
export type InferHandler<
|
|
20
21
|
P extends string,
|
|
21
22
|
D extends HandlerData | undefined,
|
|
@@ -32,8 +33,9 @@ export interface DefineHandler {
|
|
|
32
33
|
C
|
|
33
34
|
>(path: P, handler: NoInfer<InferHandler<P, undefined, C>>): HandlerTag<C>;
|
|
34
35
|
}
|
|
36
|
+
// Unique tags
|
|
35
37
|
declare const handlerTag: unique symbol;
|
|
36
|
-
export interface HandlerTag<T> {
|
|
38
|
+
export interface HandlerTag<out T> {
|
|
37
39
|
[handlerTag]: T;
|
|
38
40
|
}
|
|
39
41
|
export declare const JSON_HEADER: () => string;
|
|
@@ -73,12 +75,20 @@ export declare const route: <
|
|
|
73
75
|
const D extends HandlerData | undefined = undefined,
|
|
74
76
|
C = {}
|
|
75
77
|
>(method: RequestMethod, path: P, handler: NoInfer<InferHandler<P, D, C>>, dat?: D) => HandlerTag<C>;
|
|
78
|
+
// @ts-ignore
|
|
76
79
|
export declare const any: DefineHandler;
|
|
80
|
+
// @ts-ignore
|
|
77
81
|
export declare const get: DefineHandler;
|
|
82
|
+
// @ts-ignore
|
|
78
83
|
export declare const post: DefineHandler;
|
|
84
|
+
// @ts-ignore
|
|
79
85
|
export declare const put: DefineHandler;
|
|
86
|
+
// @ts-ignore
|
|
80
87
|
export declare const del: DefineHandler;
|
|
88
|
+
// @ts-ignore
|
|
81
89
|
export declare const patch: DefineHandler;
|
|
90
|
+
// @ts-ignore
|
|
82
91
|
export declare const options: DefineHandler;
|
|
92
|
+
// @ts-ignore
|
|
83
93
|
export declare const trace: DefineHandler;
|
|
84
94
|
export {};
|
package/core/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import type { AnyMiddlewareTypes, InferMiddlewareState, InferMiddlewareErr } fro
|
|
|
3
3
|
import type { UnionToIntersection } from "./utils.js";
|
|
4
4
|
declare const _: unique symbol;
|
|
5
5
|
export interface RouterTag<
|
|
6
|
-
C,
|
|
7
|
-
E = any
|
|
6
|
+
out C,
|
|
7
|
+
out E = any
|
|
8
8
|
> {
|
|
9
9
|
[_]: [E, C];
|
|
10
10
|
}
|
package/core/middleware.d.ts
CHANGED
|
@@ -4,9 +4,9 @@ import type { Context } from "./context.js";
|
|
|
4
4
|
import type { InferErr, InferResult } from "@safe-std/error";
|
|
5
5
|
declare const _: unique symbol;
|
|
6
6
|
export interface MiddlewareTypes<
|
|
7
|
-
Context,
|
|
8
|
-
Err,
|
|
9
|
-
State
|
|
7
|
+
out Context,
|
|
8
|
+
out Err,
|
|
9
|
+
in out State
|
|
10
10
|
> {
|
|
11
11
|
[_]: [Context, Err, State];
|
|
12
12
|
}
|
package/core/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
2
2
|
export type AwaitedReturn<U extends (...a: any[]) => any> = Awaited<ReturnType<U>>;
|
|
3
|
+
export type MaybePromise<T> = Promise<T> | T;
|
|
3
4
|
export type RequestMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | "TRACE" | (string & {});
|
|
4
5
|
export type FetchFn = (req: Request) => any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapl/web",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "A compiled web framework for all runtimes",
|
|
5
5
|
"keywords": ["fast", "lightweight", "cross-runtime", "framework", "web", "backend"],
|
|
6
6
|
"repository": {
|
|
@@ -12,32 +12,32 @@
|
|
|
12
12
|
"main": "./index.js",
|
|
13
13
|
"types": "./index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@mapl/framework": "^0.6.
|
|
15
|
+
"@mapl/framework": "^0.6.3",
|
|
16
16
|
"@mapl/router": "^0.6.4",
|
|
17
17
|
"@safe-std/error": "^2.0.4",
|
|
18
|
-
"runtime-compiler": "^1.2.
|
|
18
|
+
"runtime-compiler": "^1.2.7"
|
|
19
19
|
},
|
|
20
20
|
"exports": {
|
|
21
|
+
".": "./index.js",
|
|
21
22
|
"./constants": "./constants.js",
|
|
22
|
-
"./utils
|
|
23
|
-
"./
|
|
24
|
-
"./
|
|
25
|
-
"./utils/
|
|
26
|
-
"./
|
|
23
|
+
"./core/utils": "./core/utils.js",
|
|
24
|
+
"./core/middleware": "./core/middleware.js",
|
|
25
|
+
"./core/context": "./core/context.js",
|
|
26
|
+
"./utils/cors": "./utils/cors.js",
|
|
27
|
+
"./core/handler": "./core/handler.js",
|
|
27
28
|
"./utils/redirect": "./utils/redirect.js",
|
|
28
|
-
"./
|
|
29
|
-
"./
|
|
29
|
+
"./utils/body-limit": "./utils/body-limit.js",
|
|
30
|
+
"./utils/bearer-auth": "./utils/bearer-auth.js",
|
|
31
|
+
"./utils/static-headers": "./utils/static-headers.js",
|
|
32
|
+
"./utils/basic-auth": "./utils/basic-auth.js",
|
|
30
33
|
"./bun/compiler/router": "./bun/compiler/router.js",
|
|
31
|
-
"./
|
|
32
|
-
"./core/context": "./core/context.js",
|
|
34
|
+
"./compiler/aot": "./compiler/aot.js",
|
|
33
35
|
"./bun/compiler/aot": "./bun/compiler/aot.js",
|
|
34
|
-
"./
|
|
36
|
+
"./compiler/jit": "./compiler/jit.js",
|
|
37
|
+
"./bun": "./bun/index.js",
|
|
35
38
|
"./bun/compiler/jit": "./bun/compiler/jit.js",
|
|
39
|
+
"./build/rolldown": "./build/rolldown.js",
|
|
36
40
|
"./core": "./core/index.js",
|
|
37
|
-
"./
|
|
38
|
-
"./bun": "./bun/index.js",
|
|
39
|
-
"./core/utils": "./core/utils.js",
|
|
40
|
-
".": "./index.js",
|
|
41
|
-
"./utils/basic-auth": "./utils/basic-auth.js"
|
|
41
|
+
"./build/utils": "./build/utils.js"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/utils/basic-auth.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Header } from "../core/context.js";
|
|
2
2
|
export declare const extract: (req: Request) => {
|
|
3
|
-
name: string
|
|
4
|
-
pwd: string
|
|
3
|
+
name: string;
|
|
4
|
+
pwd: string;
|
|
5
5
|
} | undefined;
|
|
6
6
|
export declare const realm: (val: string) => Header;
|
|
7
7
|
export declare const error: (val: string) => Header;
|
package/utils/body-limit.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{macro}from"../core/middleware.js";import{isHydrating}from"runtime-compiler/config";import{createAsyncScope}from"@mapl/framework";
|
|
1
|
+
import{macro}from"../core/middleware.js";import{injectDependency,lazyDependency,noOp}from"runtime-compiler";import{isHydrating}from"runtime-compiler/config";import{createAsyncScope}from"@mapl/framework";export let RES413=isHydrating?noOp:lazyDependency(injectDependency,`new Response(null,{status:413})`);export let size=isHydrating?()=>macro(createAsyncScope):bytes=>macro(scope=>createAsyncScope(scope)+`if(await `+injectDependency(`async(r)=>{if(r.body!==null){let l=r.headers.get("content-length");if(l===null||r.headers.has("transfer-encoding")){let g=r.clone().body.getReader(),i=await g.read(),s=0;while(!i.done){s+=i.value.byteLength;if(s>`+bytes+`)return true;i=await g.read()}}else if(+l>`+bytes+`)return true}return false}`)+`(r))return `+RES413()+`;`);
|
package/utils/cors.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { type MiddlewareTypes } from "../core/middleware.js";
|
|
2
2
|
import type { RequestMethod } from "../core/utils.js";
|
|
3
3
|
import type { Header } from "../core/context.js";
|
|
4
|
+
// Ensure people don't make mistake categorizing headers
|
|
4
5
|
declare const _: unique symbol;
|
|
5
6
|
export type CORSHeader = Header & {
|
|
6
|
-
[_]: 0
|
|
7
|
+
[_]: 0;
|
|
7
8
|
};
|
|
8
9
|
export type CORSPreflightHeader = Header & {
|
|
9
|
-
[_]: 1
|
|
10
|
+
[_]: 1;
|
|
10
11
|
};
|
|
11
12
|
export declare const allowMethods: (v: [RequestMethod, RequestMethod, ...RequestMethod[]] | RequestMethod | "*") => CORSPreflightHeader;
|
|
12
13
|
export declare const allowHeaders: (v: string[] | string) => CORSPreflightHeader;
|
package/utils/cors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{injectDependency}from"runtime-compiler";import{isHydrating}from"runtime-compiler/config";import{createContext}from"@mapl/framework";import{macro}from"../core/middleware.js";import{injectList}from"./static-headers.js";export let allowMethods=v=>[`access-control-allow-methods`,``+v];export let allowHeaders=v=>[`access-control-allow-headers`,``+v];export let maxAge=v=>[`access-control-max-age`,``+v];export let allowCredentials=[`access-control-allow-credentials`,`true`];export let exposeHeaders=v=>[`access-control-expose-headers`,``+v];let createContextMacro=macro(createContext);export let init=isHydrating?()=>createContextMacro:(origins,preflightHeaders=[],headers=[])=>{if(origins!==`*`){headers.push([`vary`,`origin`]);if(Array.isArray(origins))return macro(scope=>{let
|
|
1
|
+
import{injectDependency}from"runtime-compiler";import{isHydrating}from"runtime-compiler/config";import{createContext}from"@mapl/framework";import{macro}from"../core/middleware.js";import{injectList}from"./static-headers.js";export let allowMethods=v=>[`access-control-allow-methods`,``+v];export let allowHeaders=v=>[`access-control-allow-headers`,``+v];export let maxAge=v=>[`access-control-max-age`,``+v];export let allowCredentials=[`access-control-allow-credentials`,`true`];export let exposeHeaders=v=>[`access-control-expose-headers`,``+v];let createContextMacro=macro(createContext);export let init=isHydrating?()=>createContextMacro:(origins,preflightHeaders=[],headers=[])=>{if(origins!==`*`){headers.push([`vary`,`origin`]);if(Array.isArray(origins))return macro(scope=>{let str=`(r,h)=>{let o=r.headers.get("origin");h.push(["access-control-allow-origin",typeof o==="string"&&o===`+JSON.stringify(origins[1]);for(let i=2;i<origins.length;i++)str+=`||o===`+JSON.stringify(origins[i]);return createContext(scope)+(injectDependency(str+`?o:`+JSON.stringify(origins[0])+`]);`+(headers.length>0?`h.push(`+injectList(headers)+`);`:``)+(preflightHeaders.length>0?`r.method==="OPTIONS"&&h.push(`+injectList(preflightHeaders)+`)}`:`}`))+`(r,h);`)})}headers.push([`access-control-allow-origin`,origins]);return macro(scope=>{let pushHeaders=headers.length>0?`h.push(`+injectList(headers)+`);`:``;return createContext(scope)+(preflightHeaders.length>0?injectDependency(`(r,h)=>{`+pushHeaders+`r.method==="OPTIONS"&&h.push(`+injectList(preflightHeaders)+`)}`)+`(r,h);`:pushHeaders)})};
|
package/utils/static-headers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isHydrating}from"runtime-compiler/config";import{macro,noOpMacro}from"../core/middleware.js";
|
|
1
|
+
import{isHydrating}from"runtime-compiler/config";import{injectDependency}from"runtime-compiler";import{macro,noOpMacro}from"../core/middleware.js";export let injectList=list=>list.length!==1?`...`+injectDependency(JSON.stringify(list)):injectDependency(JSON.stringify(list[0]));export default isHydrating?()=>noOpMacro:headers=>macro(()=>`h.push(`+injectList(Array.isArray(headers)?headers:headers instanceof Headers?headers.entries().toArray():Object.entries(headers))+`);`);
|