@mapl/web 0.3.0-beta.1 → 0.3.0
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/compiler/bun/jit.js +1 -1
- package/core/handler.d.ts +16 -5
- package/core/handler.js +1 -1
- package/core/middleware.d.ts +1 -1
- package/core/middleware.js +1 -1
- package/core/utils.d.ts +0 -1
- package/core/utils.js +1 -1
- package/package.json +10 -10
package/compiler/bun/jit.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{compileGroup,AsyncFunction,contextInit,setContextInit,setCompileErrorHandlerHook,setCompileHandlerHook}from"@mapl/framework";import{countParams}from"@mapl/router/path";import{exportDependency,getDependency,injectDependency,injectExternalDependency}from"runtime-compiler";import{evaluate,evaluateSync}from"runtime-compiler/jit";import{compileErrorHandler,compileReturn,paramArgs,RES400}from"../jit.js";import{insertRoute,resetRouter,routerToString}from"./router.js";let compileToState=router=>{resetRouter();setCompileHandlerHook((handler,prevContent,path,scope)=>{let fn=handler[2];let call=injectExternalDependency(fn)+`(`;let paramCount=countParams(handler[1]);paramCount>0&&(call+=paramArgs[paramCount]);if(fn.length>paramCount){call+=paramCount===0?`c`:`,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]?`})()`:``))});setCompileErrorHandlerHook(compileErrorHandler);setContextInit(`let h=[],c={status:200,req:r,server:s
|
|
1
|
+
import{compileGroup,AsyncFunction,contextInit,setContextInit,setCompileErrorHandlerHook,setCompileHandlerHook}from"@mapl/framework";import{countParams}from"@mapl/router/path";import{exportDependency,getDependency,injectDependency,injectExternalDependency}from"runtime-compiler";import{evaluate,evaluateSync}from"runtime-compiler/jit";import{compileErrorHandler,compileReturn,paramArgs,RES400}from"../jit.js";import{insertRoute,resetRouter,routerToString}from"./router.js";let compileToState=router=>{resetRouter();setCompileHandlerHook((handler,prevContent,path,scope)=>{let fn=handler[2];let call=injectExternalDependency(fn)+`(`;let paramCount=countParams(handler[1]);paramCount>0&&(call+=paramArgs[paramCount]);if(fn.length>paramCount){call+=paramCount===0?`c`:`,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]?`})()`:``))});setCompileErrorHandlerHook(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/core/handler.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { Err } from "@safe-std/error";
|
|
2
2
|
import type { Context } from "./context.js";
|
|
3
3
|
import type { RouterTag } from "./index.js";
|
|
4
|
-
import {
|
|
5
|
-
export
|
|
4
|
+
import type { RequestMethod } from "./utils.js";
|
|
5
|
+
export interface HandlerResponse<I = any> {
|
|
6
|
+
(response: string, hasContext: boolean): string;
|
|
7
|
+
(response: string, hasContext: boolean, _: I): string;
|
|
8
|
+
}
|
|
6
9
|
export interface HandlerData extends Record<symbol, any> {
|
|
7
10
|
type?: HandlerResponse;
|
|
8
11
|
}
|
|
@@ -21,18 +24,26 @@ export type InferHandler<
|
|
|
21
24
|
export interface DefineHandler {
|
|
22
25
|
<
|
|
23
26
|
P extends string,
|
|
24
|
-
const D extends HandlerData
|
|
25
|
-
C
|
|
26
|
-
>(path: P, handler: NoInfer<InferHandler<P, D, C>>, dat
|
|
27
|
+
const D extends HandlerData,
|
|
28
|
+
C
|
|
29
|
+
>(path: P, handler: NoInfer<InferHandler<P, D, C>>, dat: D): HandlerTag<C>;
|
|
30
|
+
<
|
|
31
|
+
P extends string,
|
|
32
|
+
C
|
|
33
|
+
>(path: P, handler: NoInfer<InferHandler<P, undefined, C>>): HandlerTag<C>;
|
|
27
34
|
}
|
|
28
35
|
declare const handlerTag: unique symbol;
|
|
29
36
|
export interface HandlerTag<T> {
|
|
30
37
|
[handlerTag]: T;
|
|
31
38
|
}
|
|
39
|
+
export declare const JSON_HEADER: () => string;
|
|
40
|
+
export declare const JSON_OPTIONS: () => string;
|
|
32
41
|
/**
|
|
33
42
|
* Return JSON
|
|
34
43
|
*/
|
|
35
44
|
export declare const json: HandlerResponse;
|
|
45
|
+
export declare const HTML_HEADER: () => string;
|
|
46
|
+
export declare const HTML_OPTIONS: () => string;
|
|
36
47
|
/**
|
|
37
48
|
* Return HTML
|
|
38
49
|
*/
|
package/core/handler.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{isHydrating}from"runtime-compiler/config";import{injectDependency,lazyDependency,noOp}from"runtime-compiler";export let JSON_HEADER=isHydrating?noOp:lazyDependency(injectDependency,`["content-type","application/json"]`);export let JSON_OPTIONS=isHydrating?noOp:lazyDependency(injectDependency,`{headers:[`+JSON_HEADER()+`]}`);export let json=isHydrating?noOp:(res,hasContext)=>hasContext?`h.push(`+JSON_HEADER()+`);return new Response(JSON.stringify(`+res+`),c)`:`return new Response(JSON.stringify(`+res+`),`+JSON_OPTIONS()+`)`;export let HTML_HEADER=isHydrating?noOp:lazyDependency(injectDependency,`["content-type","application/json"]`);export let HTML_OPTIONS=isHydrating?noOp:lazyDependency(injectDependency,`{headers:[`+JSON_HEADER()+`]}`);export let html=isHydrating?noOp:(res,hasContext)=>hasContext?`h.push(`+HTML_HEADER()+`);return new Response(`+res+`,c)`:`return new Response(`+res+`,`+HTML_OPTIONS()+`)`;export let text=isHydrating?noOp:(res,hasContext)=>`return new Response(`+res+(hasContext?`,c)`:`)`);export let error=(r,f,dat)=>{r[2]=[f,dat];return r};export let route=(method,path,handler,dat)=>[method,path,handler,dat];export let any=(path,handler,dat)=>[``,path,handler,dat];export let get=(path,handler,dat)=>[`GET`,path,handler,dat];export let post=(path,handler,dat)=>[`POST`,path,handler,dat];export let put=(path,handler,dat)=>[`PUT`,path,handler,dat];export let del=(path,handler,dat)=>[`DELETE`,path,handler,dat];export let patch=(path,handler,dat)=>[`PATCH`,path,handler,dat];export let options=(path,handler,dat)=>[`OPTIONS`,path,handler,dat];export let trace=(path,handler,dat)=>[`TRACE`,path,handler,dat];
|
package/core/middleware.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ScopeState } from "@mapl/framework";
|
|
2
2
|
import type { InferErr, InferResult } from "@safe-std/error";
|
|
3
|
-
import {
|
|
3
|
+
import type { AwaitedReturn } from "./utils.js";
|
|
4
4
|
import type { Context } from "./context.js";
|
|
5
5
|
export type MiddlewareHandler = (c: Context) => any;
|
|
6
6
|
export type MiddlewareTypes<
|
package/core/middleware.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{noOp}from"
|
|
1
|
+
import{noOp}from"runtime-compiler";export let macro=f=>[-1,f];export let noOpMacro=macro(noOp);export let tap=f=>[0,f];export let attach=(prop,f)=>[1,f,prop];export let validate=f=>[2,f];export let parse=(prop,f)=>[3,f,prop];
|
package/core/utils.d.ts
CHANGED
|
@@ -2,4 +2,3 @@ export type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) ex
|
|
|
2
2
|
export type AwaitedReturn<U extends (...a: any[]) => any> = Awaited<ReturnType<U>>;
|
|
3
3
|
export type RequestMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | "TRACE" | (string & {});
|
|
4
4
|
export type FetchFn = (req: Request) => any;
|
|
5
|
-
export declare const noOp: () => string;
|
package/core/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export{};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapl/web",
|
|
3
|
-
"version": "0.3.0
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A compiled web framework for all runtimes",
|
|
5
5
|
"keywords": ["fast", "lightweight", "cross-runtime", "framework", "web", "backend"],
|
|
6
6
|
"repository": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"@mapl/framework": "^0.5.2",
|
|
16
16
|
"@mapl/router": "^0.6.2",
|
|
17
17
|
"@safe-std/error": "^1.0.1",
|
|
18
|
-
"runtime-compiler": "^1.2.
|
|
18
|
+
"runtime-compiler": "^1.2.5"
|
|
19
19
|
},
|
|
20
20
|
"optionalDependencies": {
|
|
21
21
|
"secure-headers": "^0.0.6"
|
|
@@ -23,18 +23,18 @@
|
|
|
23
23
|
"exports": {
|
|
24
24
|
"./constants": "./constants.js",
|
|
25
25
|
".": "./index.js",
|
|
26
|
-
"./core/handler": "./core/handler.js",
|
|
27
|
-
"./core/utils": "./core/utils.js",
|
|
28
|
-
"./core": "./core/index.js",
|
|
29
26
|
"./core/middleware": "./core/middleware.js",
|
|
27
|
+
"./core/utils": "./core/utils.js",
|
|
30
28
|
"./utils/static-headers": "./utils/static-headers.js",
|
|
31
|
-
"./
|
|
29
|
+
"./utils/cors": "./utils/cors.js",
|
|
30
|
+
"./compiler/aot": "./compiler/aot.js",
|
|
31
|
+
"./core/handler": "./core/handler.js",
|
|
32
32
|
"./utils/secure-headers": "./utils/secure-headers.js",
|
|
33
33
|
"./compiler/bun/jit": "./compiler/bun/jit.js",
|
|
34
|
-
"./compiler/
|
|
34
|
+
"./compiler/jit": "./compiler/jit.js",
|
|
35
35
|
"./compiler/bun/router": "./compiler/bun/router.js",
|
|
36
|
-
"./
|
|
37
|
-
"./compiler/aot": "./compiler/aot.js",
|
|
38
|
-
"./
|
|
36
|
+
"./core": "./core/index.js",
|
|
37
|
+
"./compiler/bun/aot": "./compiler/bun/aot.js",
|
|
38
|
+
"./core/context": "./core/context.js"
|
|
39
39
|
}
|
|
40
40
|
}
|