@mapl/web 0.6.6 → 0.7.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 +1 -0
- package/cloudflare/compiler.d.ts +7 -19
- package/cloudflare/compiler.js +1 -1
- package/cloudflare/index.d.ts +2 -6
- package/cloudflare/index.js +1 -1
- package/cloudflare/vars.d.ts +5 -0
- package/cloudflare/vars.js +1 -0
- package/compiler/utils.d.ts +4 -0
- package/compiler/utils.js +1 -0
- package/constants.d.ts +3 -2
- package/constants.js +1 -1
- package/deno/compiler.d.ts +2 -9
- package/deno/compiler.js +1 -1
- package/deno/index.d.ts +2 -4
- package/deno/index.js +1 -1
- package/deno/vars.d.ts +3 -0
- package/deno/vars.js +1 -0
- package/generic/compiler.d.ts +3 -26
- package/generic/compiler.js +1 -1
- package/generic/index.d.ts +2 -3
- package/generic/index.js +1 -1
- package/generic/vars.d.ts +2 -0
- package/generic/vars.js +1 -0
- package/index.d.ts +1 -2
- package/index.js +1 -1
- package/package.json +1 -1
- package/router.d.ts +75 -68
- package/router.js +1 -1
- package/send.d.ts +95 -0
- package/send.js +1 -0
- package/bun/compiler/index.d.ts +0 -27
- package/bun/compiler/index.js +0 -1
- package/bun/compiler/router.d.ts +0 -9
- package/bun/compiler/router.js +0 -1
- package/bun/index.d.ts +0 -5
- package/bun/index.js +0 -1
- package/compilers/call.d.ts +0 -9
- package/compilers/call.js +0 -1
- package/compilers/globals.d.ts +0 -21
- package/compilers/globals.js +0 -1
- package/compilers/scope.d.ts +0 -14
- package/compilers/scope.js +0 -1
- package/layer.d.ts +0 -45
- package/layer.js +0 -1
- package/response.d.ts +0 -41
- package/response.js +0 -1
- package/utils.d.ts +0 -1
- package/utils.js +0 -1
package/README.md
CHANGED
package/cloudflare/compiler.d.ts
CHANGED
|
@@ -1,20 +1,8 @@
|
|
|
1
|
-
import { type ExportedDependency
|
|
2
|
-
import type { ExportedHandlerFetchHandler, Cloudflare } from "@cloudflare/workers-types";
|
|
1
|
+
import { type ExportedDependency } from "runtime-compiler";
|
|
3
2
|
import type { Router } from "../router.ts";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @example
|
|
11
|
-
* const createFetch = getDependency(build(app));
|
|
12
|
-
*
|
|
13
|
-
* export default {
|
|
14
|
-
* fetch(...args) {
|
|
15
|
-
* // Set up stuff...
|
|
16
|
-
* return (this.fetch = createFetch())(...args);
|
|
17
|
-
* }
|
|
18
|
-
* } satisfies ExportedHandler<Env>;
|
|
19
|
-
*/
|
|
20
|
-
export declare const build: (router: Router) => ExportedDependency<CompiledResult>;
|
|
3
|
+
import type { ExportedHandlerFetchHandler, Cloudflare } from "@cloudflare/workers-types";
|
|
4
|
+
declare const _default: <
|
|
5
|
+
Env = Cloudflare.Env,
|
|
6
|
+
CfHostMetadata = unknown
|
|
7
|
+
>(router: Router<[]>) => ExportedDependency<() => ExportedHandlerFetchHandler<Env, CfHostMetadata>>;
|
|
8
|
+
export default _default;
|
package/cloudflare/compiler.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{exportExpr,markExported}from"runtime-compiler";import{isHydrating}from"runtime-compiler/config";import{
|
|
1
|
+
import{declareLocal,exportExpr,markExported}from"runtime-compiler";import{isHydrating}from"runtime-compiler/config";import{createRouter,insertItem}from"@mapl/router/method";import compileRouter from"@mapl/router/method/compiler";export default isHydrating?markExported:router=>{let urlRouter=createRouter();for(let i=0,routes=router[7];i<routes.length;i++){let route=routes[i];let content=route[0]+route[2];let flags=route[3];insertItem(urlRouter,route[7],route[4],(flags&1)===1?`return `+declareLocal(route[6],`async(mr,mi,mec)=>{${content}}`)+`(mr,mi,mec)`:content)}let scope=router[6];return exportExpr(`()=>{${scope[0]+scope[2]}return (mr,mi,mec)=>{let mu=mr.url,s=mu.indexOf('/',10)+1,e=mu.indexOf('?',s),p=e===-1?mu.slice(s):mu.slice(s,e);${compileRouter(urlRouter,`mr.method`,0)}return mnf}}`)};
|
package/cloudflare/index.d.ts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare const request: Identifier<WorkerRequest>;
|
|
4
|
-
export declare const env: Identifier<Cloudflare.Env>;
|
|
5
|
-
export declare const ctx: Identifier<ExecutionContext>;
|
|
6
|
-
export { build } from "./compiler.ts";
|
|
1
|
+
export { default as compile } from "./compiler.ts";
|
|
2
|
+
export * as vars from "./vars.ts";
|
package/cloudflare/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export{default as compile}from"./compiler.js";export*as vars from"./vars.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Request as WorkerRequest, ExecutionContext, Cloudflare } from "@cloudflare/workers-types";
|
|
2
|
+
import type { Identifier } from "runtime-compiler";
|
|
3
|
+
export declare const request: Identifier<WorkerRequest>;
|
|
4
|
+
export declare const env: Identifier<Cloudflare.Env>;
|
|
5
|
+
export declare const ctx: Identifier<ExecutionContext>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export let request=`mr`;export let env=`mi`;export let ctx=`mec`;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type Identifier } from "runtime-compiler";
|
|
2
|
+
import type { BaseScope } from "../router.ts";
|
|
3
|
+
export type InferDependencies<T extends Identifier<any>[]> = { [K in keyof T] : T[K]["~type"] };
|
|
4
|
+
export declare const injectValue: <T>(v: T, scope: BaseScope) => Identifier<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{declareLocal,injectExternal}from"runtime-compiler";export let injectValue=(v,scope)=>declareLocal(scope[6],injectExternal(v));
|
package/constants.d.ts
CHANGED
|
@@ -12,9 +12,10 @@ export declare const EXEC_CTX = "mec";
|
|
|
12
12
|
export declare const FULL_URL = "mu";
|
|
13
13
|
export declare const GENERIC_ARGS: string;
|
|
14
14
|
export declare const BUN_DENO_ARGS: string;
|
|
15
|
-
export declare const
|
|
15
|
+
export declare const CF_ARGS: string;
|
|
16
16
|
export declare const RES_404 = "mnf";
|
|
17
|
+
export declare const RES_200 = "mok";
|
|
18
|
+
export declare const RES = "mrs";
|
|
17
19
|
export declare const HTML_HEADER = "mhh";
|
|
18
|
-
export declare const HTML_OPTION = "mho";
|
|
19
20
|
// Fast path for injecting mapl symbols
|
|
20
21
|
export declare const DECL_GLOBALS: string;
|
package/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"@mapl/framework/constants";export*from"@mapl/router/constants";export let CTX=`mc`;export let HEADERS=`mh`;export let PARSED_RESULT=`mt`;export let CREATE_CTX=`let ${HEADERS}=[],${CTX}={status:200,headers:${HEADERS}};`;export let REQ=`mr`;export let INFO=`mi`;export let EXEC_CTX=`mec`;export let FULL_URL=`mu`;export let GENERIC_ARGS=`(${REQ})`;export let BUN_DENO_ARGS=`(${REQ},${INFO})`;export let
|
|
1
|
+
export*from"@mapl/framework/constants";export*from"@mapl/router/constants";export let CTX=`mc`;export let HEADERS=`mh`;export let PARSED_RESULT=`mt`;export let CREATE_CTX=`let ${HEADERS}=[],${CTX}={status:200,headers:${HEADERS}};`;export let REQ=`mr`;export let INFO=`mi`;export let EXEC_CTX=`mec`;export let FULL_URL=`mu`;export let GENERIC_ARGS=`(${REQ})`;export let BUN_DENO_ARGS=`(${REQ},${INFO})`;export let CF_ARGS=`(${REQ},${INFO},${EXEC_CTX})`;export let RES_404=`mnf`;export let RES_200=`mok`;export let RES=`mrs`;export let HTML_HEADER=`mhh`;export let DECL_GLOBALS=`let ${HTML_HEADER}=['content-type','text/html'],${RES_404}=new Response(null,{status:404}),${RES_200}=new Response();`;
|
package/deno/compiler.d.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import { type ExportedDependency } from "runtime-compiler";
|
|
2
2
|
import type { Router } from "../router.ts";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/
|
|
6
|
-
export type CompiledResult = (req: Request) => Response | Promise<Response>;
|
|
7
|
-
/**
|
|
8
|
-
* @example
|
|
9
|
-
* Deno.serve(getDependency(build(app)));
|
|
10
|
-
*/
|
|
11
|
-
export declare const build: (router: Router) => ExportedDependency<CompiledResult>;
|
|
3
|
+
declare const _default: <Addr extends Deno.Addr = Deno.Addr>(router: Router<[]>) => ExportedDependency<Deno.ServeHandlerInfo<Addr>>;
|
|
4
|
+
export default _default;
|
package/deno/compiler.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{declareLocal,exportScope,markExported}from"runtime-compiler";import{isHydrating}from"runtime-compiler/config";import{createRouter,insertItem}from"@mapl/router/method";import compileRouter from"@mapl/router/method/compiler";export default isHydrating?markExported:router=>{let urlRouter=createRouter();for(let i=0,routes=router[7];i<routes.length;i++){let route=routes[i];let content=route[0]+route[2];let flags=route[3];insertItem(urlRouter,route[7],route[4],(flags&1)===1?`return `+declareLocal(route[6],`async(mr,mi)=>{${content}}`)+`(mr,mi)`:content)}return exportScope(router[6],`(mr,mi)=>{let mu=mr.url,s=mu.indexOf('/',10)+1,e=mu.indexOf('?',s),p=e===-1?mu.slice(s):mu.slice(s,e);${compileRouter(urlRouter,`mr.method`,0)}return mnf}`)};
|
package/deno/index.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export declare const info: Identifier<Deno.ServeHandlerInfo<Deno.Addr>>;
|
|
4
|
-
export { build } from "./compiler.ts";
|
|
1
|
+
export { default as compile } from "./compiler.ts";
|
|
2
|
+
export * as vars from "./vars.ts";
|
package/deno/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{
|
|
1
|
+
export{default as compile}from"./compiler.js";export*as vars from"./vars.js";
|
package/deno/vars.d.ts
ADDED
package/deno/vars.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"../generic/vars.js";export let info=`mi`;
|
package/generic/compiler.d.ts
CHANGED
|
@@ -1,27 +1,4 @@
|
|
|
1
|
-
import { type ExportedDependency
|
|
2
|
-
import { type HandlerScope } from "../compilers/scope.ts";
|
|
1
|
+
import { type ExportedDependency } from "runtime-compiler";
|
|
3
2
|
import type { Router } from "../router.ts";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
export type CompiledResult = (req: Request) => Response | Promise<Response>;
|
|
8
|
-
/**
|
|
9
|
-
* Load all global state for a router
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* setHandlerArgs(constants.GENERIC_ARGS);
|
|
13
|
-
* _load(router);
|
|
14
|
-
*/
|
|
15
|
-
export declare const _load: (router: Router) => void;
|
|
16
|
-
export declare const loadToString: () => Value<CompiledResult>;
|
|
17
|
-
/**
|
|
18
|
-
* Hydrate router data
|
|
19
|
-
*/
|
|
20
|
-
export declare const _hydrate: (router: Router, scope: HandlerScope) => void;
|
|
21
|
-
/**
|
|
22
|
-
* @example
|
|
23
|
-
* export default {
|
|
24
|
-
* fetch: getDependency(build(app))
|
|
25
|
-
* };
|
|
26
|
-
*/
|
|
27
|
-
export declare const build: (router: Router) => ExportedDependency<CompiledResult>;
|
|
3
|
+
declare const _default: (router: Router<[]>) => ExportedDependency<(req: Request) => Response | Promise<Response>>;
|
|
4
|
+
export default _default;
|
package/generic/compiler.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{declareLocal,exportScope,markExported}from"runtime-compiler";import{isHydrating}from"runtime-compiler/config";import{createRouter,insertItem}from"@mapl/router/method";import compileRouter from"@mapl/router/method/compiler";export default isHydrating?markExported:router=>{let urlRouter=createRouter();for(let i=0,routes=router[7];i<routes.length;i++){let route=routes[i];let content=route[0]+route[2];let flags=route[3];insertItem(urlRouter,route[7],route[4],(flags&1)===1?`return `+declareLocal(route[6],`async(mr)=>{${content}}`)+`(mr)`:content)}return exportScope(router[6],`(mr)=>{let mu=mr.url,s=mu.indexOf('/',10)+1,e=mu.indexOf('?',s),p=e===-1?mu.slice(s):mu.slice(s,e);${compileRouter(urlRouter,`mr.method`,0)}return mnf}`)};
|
package/generic/index.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export { build } from "./compiler.ts";
|
|
1
|
+
export { default as compile } from "./compiler.ts";
|
|
2
|
+
export * as vars from "./vars.ts";
|
package/generic/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export{default as compile}from"./compiler.js";export*as vars from"./vars.js";
|
package/generic/vars.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export let request=`mr`;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*as
|
|
1
|
+
export*as router from"./router.js";export*as send from"./send.js";
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@mapl/web","version":"0.
|
|
1
|
+
{"name":"@mapl/web","version":"0.7.1","description":"A compiled web framework for all runtimes","keywords":["backend","cross-runtime","fast","framework","lightweight","web"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/mapljs/web.git"},"type":"module","main":"./index.js","types":"./index.d.ts","dependencies":{"@mapl/router":"^0.10.2","runtime-compiler":"^3.1.7"},"exports":{"./generic/compiler":"./generic/compiler.js","./deno":"./deno/index.js","./deno/vars":"./deno/vars.js","./constants":"./constants.js","./deno/compiler":"./deno/compiler.js","./cloudflare":"./cloudflare/index.js","./cloudflare/vars":"./cloudflare/vars.js","./cloudflare/compiler":"./cloudflare/compiler.js","./compiler/utils":"./compiler/utils.js","./send":"./send.js","./generic":"./generic/index.js","./generic/vars":"./generic/vars.js",".":"./index.js","./router":"./router.js"}}
|
package/router.d.ts
CHANGED
|
@@ -1,71 +1,78 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
import type { Scope } from "runtime-compiler";
|
|
2
|
+
export interface BaseScope extends Scope {
|
|
3
|
+
/**
|
|
4
|
+
* Scope flags.
|
|
5
|
+
*
|
|
6
|
+
* Bit positions:
|
|
7
|
+
* - `0`: whether scope requires async.
|
|
8
|
+
*/
|
|
9
|
+
3: number;
|
|
10
|
+
/**
|
|
11
|
+
* Base path.
|
|
12
|
+
*/
|
|
13
|
+
4: string;
|
|
14
|
+
/**
|
|
15
|
+
* Parameter count of the base path.
|
|
16
|
+
*/
|
|
17
|
+
5: number;
|
|
18
|
+
/**
|
|
19
|
+
* Parent scope.
|
|
20
|
+
*/
|
|
21
|
+
6: Scope;
|
|
22
|
+
}
|
|
23
|
+
declare const _params: unique symbol;
|
|
24
|
+
type _params = typeof _params;
|
|
25
|
+
export interface Router<out Params extends any[] = any[]> extends BaseScope {
|
|
26
|
+
[_params]?: Params;
|
|
27
|
+
/**
|
|
28
|
+
* Route list.
|
|
29
|
+
*/
|
|
30
|
+
7: Route[];
|
|
31
|
+
}
|
|
32
|
+
export interface Route<out Params extends any[] = any[]> extends BaseScope {
|
|
33
|
+
[_params]?: Params;
|
|
34
|
+
/**
|
|
35
|
+
* Route method.
|
|
36
|
+
*/
|
|
37
|
+
7: string;
|
|
38
|
+
}
|
|
39
|
+
export type InferParams<
|
|
40
|
+
Path extends string,
|
|
41
|
+
Prev extends any[] = []
|
|
42
|
+
> = Path extends `${string}*${infer Rest}` ? Rest extends "*" ? [...Prev, string] : InferParams<Rest, [...Prev, string]> : Prev;
|
|
43
|
+
/**
|
|
44
|
+
* Create a root router.
|
|
45
|
+
*/
|
|
46
|
+
export declare const init: () => Router<[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Create a subrouter.
|
|
49
|
+
* @param router Parent router
|
|
50
|
+
* @param path Subpath. Must not be `/`.
|
|
51
|
+
*/
|
|
52
|
+
export declare const branch: <
|
|
53
|
+
Params extends any[],
|
|
30
54
|
Path extends string
|
|
31
|
-
>(
|
|
32
|
-
/**
|
|
33
|
-
* Mount a child router.
|
|
34
|
-
*/
|
|
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
|
-
*/
|
|
39
|
-
export declare const get: HandleMethod;
|
|
55
|
+
>(router: Router<Params>, path: Path) => Router<InferParams<Path, Params>>;
|
|
40
56
|
/**
|
|
41
|
-
*
|
|
57
|
+
* Create a new route.
|
|
58
|
+
* @param router
|
|
59
|
+
* @param method
|
|
60
|
+
* @param path
|
|
42
61
|
*/
|
|
43
|
-
export declare const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
export
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
export declare const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
export declare const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
export
|
|
60
|
-
/**
|
|
61
|
-
* Describes the communication options for the target resource.
|
|
62
|
-
*/
|
|
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;
|
|
62
|
+
export declare const route: <
|
|
63
|
+
Params extends any[],
|
|
64
|
+
Path extends string
|
|
65
|
+
>(router: Router<Params>, method: string, path: Path) => Route<InferParams<Path, Params>>;
|
|
66
|
+
export type RouteFn = <
|
|
67
|
+
Params extends any[],
|
|
68
|
+
Path extends string
|
|
69
|
+
>(router: Router<Params>, path: Path) => Route<InferParams<Path, Params>>;
|
|
70
|
+
export declare const get: RouteFn;
|
|
71
|
+
export declare const post: RouteFn;
|
|
72
|
+
export declare const put: RouteFn;
|
|
73
|
+
export declare const del: RouteFn;
|
|
74
|
+
export declare const patch: RouteFn;
|
|
75
|
+
export declare const options: RouteFn;
|
|
76
|
+
export declare const trace: RouteFn;
|
|
77
|
+
export declare const any: RouteFn;
|
|
78
|
+
export {};
|
package/router.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{countParams}from"@mapl/router/utils";import{isHydrating}from"runtime-compiler/config";export let init=isHydrating?()=>[``,0,``,0,``,0,[``,0,``],[]]:()=>[`let mh=[],mc={status:200,headers:mh};`,0,``,0,``,0,[`let mhh=['content-type','text/html'],mnf=new Response(null,{status:404}),mok=new Response();`,0,``],[]];export let branch=(router,path)=>{router=router.slice();router[4]+=path;router[5]+=countParams(path);return router};export let route=(router,method,path)=>{let route=router.slice();route[4]=route[4]===``?path:path===`/`?route[4]:route[4]+path;route[5]+=countParams(path);route[7]=method;router[7].push(route);return route};export let get=(router,path)=>route(router,`GET`,path);export let post=(router,path)=>route(router,`POST`,path);export let put=(router,path)=>route(router,`PUT`,path);export let del=(router,path)=>route(router,`DELETE`,path);export let patch=(router,path)=>route(router,`PATCH`,path);export let options=(router,path)=>route(router,`OPTIONS`,path);export let trace=(router,path)=>route(router,`TRACE`,path);export let any=(router,path)=>route(router,``,path);
|
package/send.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { Identifier } from "runtime-compiler";
|
|
2
|
+
import { type InferDependencies } from "./compiler/utils.ts";
|
|
3
|
+
import type { Route } from "./router.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Describe a header pair
|
|
6
|
+
*/
|
|
7
|
+
export type ResponseHeader = [string, string] | readonly [string, string];
|
|
8
|
+
/**
|
|
9
|
+
* Response state
|
|
10
|
+
*/
|
|
11
|
+
export interface ResponseState {
|
|
12
|
+
status: number;
|
|
13
|
+
headers: ResponseHeader[];
|
|
14
|
+
statusText: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const PARAMS_MAP: string[];
|
|
17
|
+
export declare const _call: (route: Route, f: (...args: any[]) => any, deps: Identifier<any>[]) => string;
|
|
18
|
+
export declare const _hydrateCall: (route: Route, f: (...args: any[]) => any, ...args: any[]) => void;
|
|
19
|
+
export declare const _setResponse: (route: Route, f: (...args: any[]) => any, deps: Identifier<any>[]) => void;
|
|
20
|
+
export declare const _setAwaitedResponse: (route: Route, f: (...args: any[]) => any, deps: Identifier<any>[]) => void;
|
|
21
|
+
export declare const _returnRaw: (route: Route) => void;
|
|
22
|
+
export declare const _returnHTML: (route: Route) => void;
|
|
23
|
+
export declare const _returnJSON: (route: Route) => void;
|
|
24
|
+
/**
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const route = router.get(root, '/');
|
|
28
|
+
* send.body(route, (c) => {
|
|
29
|
+
* c.status = 418;
|
|
30
|
+
* return 'I\'m a teapot';
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare const body: <
|
|
35
|
+
Params extends any[],
|
|
36
|
+
const Deps extends Identifier<any>[]
|
|
37
|
+
>(route: Route<Params>, f: (...args: [...InferDependencies<Deps>, ...Params, res: ResponseState]) => BodyInit, ...args: Deps) => void;
|
|
38
|
+
/**
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const route = router.post(root, '/');
|
|
42
|
+
* send.bodyAsync(route, (req) => req.text(), vars.request);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const bodyAsync: <
|
|
46
|
+
Params extends any[],
|
|
47
|
+
const Deps extends Identifier<any>[]
|
|
48
|
+
>(route: Route<Params>, f: (...args: [...InferDependencies<Deps>, ...Params, res: ResponseState]) => BodyInit | Promise<BodyInit>, ...args: Deps) => void;
|
|
49
|
+
/**
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const route = router.get(root, '/json');
|
|
53
|
+
* send.json(route, (c) => {
|
|
54
|
+
* c.status = 418;
|
|
55
|
+
* return { msg: 'I\'m a teapot' };
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare const json: <
|
|
60
|
+
Params extends any[],
|
|
61
|
+
const Deps extends Identifier<any>[]
|
|
62
|
+
>(route: Route<Params>, f: (...args: [...InferDependencies<Deps>, ...Params, res: ResponseState]) => any, ...args: Deps) => void;
|
|
63
|
+
/**
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* const route = router.post(root, '/json');
|
|
67
|
+
* send.jsonAsync(route, (req) => req.json(), vars.request);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare const jsonAsync: <
|
|
71
|
+
Params extends any[],
|
|
72
|
+
const Deps extends Identifier<any>[]
|
|
73
|
+
>(route: Route<Params>, f: (...args: [...InferDependencies<Deps>, ...Params, res: ResponseState]) => Promise<any>, ...args: Deps) => void;
|
|
74
|
+
/**
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* const route = router.get(root, '/home');
|
|
78
|
+
* send.html(route, (req) => `<a>${req.url}</a>`, vars.request);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare const html: <
|
|
82
|
+
Params extends any[],
|
|
83
|
+
const Deps extends Identifier<any>[]
|
|
84
|
+
>(route: Route<Params>, f: (...args: [...InferDependencies<Deps>, ...Params, res: ResponseState]) => BodyInit, ...args: Deps) => void;
|
|
85
|
+
/**
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const route = router.get(root, '/home');
|
|
89
|
+
* send.htmlAsync(route, async (req) => `<p>${await req.text()}</p>`, vars.request);
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare const htmlAsync: <
|
|
93
|
+
Params extends any[],
|
|
94
|
+
const Deps extends Identifier<any>[]
|
|
95
|
+
>(route: Route<Params>, f: (...args: [...InferDependencies<Deps>, ...Params, res: ResponseState]) => Promise<BodyInit>, ...args: Deps) => void;
|
package/send.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{injectValue}from"./compiler/utils.js";import{isHydrating}from"runtime-compiler/config";export let PARAMS_MAP=[``,`q0,`];for(let i=1;i<=16;i++)PARAMS_MAP.push(`${PARAMS_MAP[i]}q${i},`);export let _call=(route,f,deps)=>injectValue(f,route)+(deps.length>0?`(${deps.join()},`:`(`)+PARAMS_MAP[route[5]]+(f.length>deps.length+route[5]?`mc);`:`);`);export let _hydrateCall=(route,f)=>{injectValue(f,route)};export let _setResponse=(route,f,deps)=>{route[0]+=`let mrs=`+_call(route,f,deps)};export let _setAwaitedResponse=(route,f,deps)=>{route[0]+=`let mrs=await `+_call(route,f,deps);route[3]|=1};export let _returnRaw=route=>{route[2]+=`return new Response(mrs,mc)`};export let _returnHTML=route=>{route[2]+=`mh.push(mhh);return new Response(mrs,mc)`};export let _returnJSON=route=>{route[2]+=`return Response.json(mrs,mc)`};export let body=isHydrating?_hydrateCall:(route,f,...deps)=>{_setResponse(route,f,deps);_returnRaw(route)};export let bodyAsync=isHydrating?_hydrateCall:(route,f,...deps)=>{_setAwaitedResponse(route,f,deps);_returnRaw(route)};export let json=isHydrating?_hydrateCall:(route,f,...deps)=>{_setResponse(route,f,deps);_returnJSON(route)};export let jsonAsync=isHydrating?_hydrateCall:(route,f,...deps)=>{_setAwaitedResponse(route,f,deps);_returnJSON(route)};export let html=isHydrating?_hydrateCall:(route,f,...deps)=>{_setResponse(route,f,deps);_returnHTML(route)};export let htmlAsync=isHydrating?_hydrateCall:(route,f,...deps)=>{_setAwaitedResponse(route,f,deps);_returnHTML(route)};
|
package/bun/compiler/index.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { type ExportedDependency, type Value } from "runtime-compiler";
|
|
2
|
-
import { type HandlerScope } from "../../compilers/scope.ts";
|
|
3
|
-
import type { Router } from "../../router.ts";
|
|
4
|
-
/**
|
|
5
|
-
* Describe compiler compiled result
|
|
6
|
-
*/
|
|
7
|
-
export type CompiledResult = Bun.Serve.Routes<any, string>;
|
|
8
|
-
/**
|
|
9
|
-
* Load all global state for a router
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* setHandlerArgs(constants.GENERIC_ARGS);
|
|
13
|
-
* _load(router);
|
|
14
|
-
*/
|
|
15
|
-
export declare const _load: (router: Router) => void;
|
|
16
|
-
export declare const loadToString: () => Value<CompiledResult>;
|
|
17
|
-
/**
|
|
18
|
-
* Hydrate router data
|
|
19
|
-
*/
|
|
20
|
-
export declare const _hydrate: (router: Router, scope: HandlerScope) => void;
|
|
21
|
-
/**
|
|
22
|
-
* @example
|
|
23
|
-
* export default {
|
|
24
|
-
* fetch: getDependency(build(app))
|
|
25
|
-
* };
|
|
26
|
-
*/
|
|
27
|
-
export declare const build: (router: Router) => ExportedDependency<CompiledResult>;
|
package/bun/compiler/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;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()));
|
package/bun/compiler/router.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare const initRouter: () => void;
|
|
2
|
-
/**
|
|
3
|
-
* Path and content must be processed before inserting
|
|
4
|
-
* @param method
|
|
5
|
-
* @param path
|
|
6
|
-
* @param content
|
|
7
|
-
*/
|
|
8
|
-
export declare const insertItem: (method: string, path: string, content: string) => void;
|
|
9
|
-
export declare const toRoutes: () => string;
|
package/bun/compiler/router.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
let METHOD_ROUTER;let DEOPT_PATHS;export let initRouter=()=>{METHOD_ROUTER={};DEOPT_PATHS=[]};export let insertItem=(method,path,content)=>{let methods=METHOD_ROUTER[path];if(methods!=null)methods[``]??DEOPT_PATHS.push(path);else methods=METHOD_ROUTER[path]={};method!==`GET`&&method!==`POST`&&method!==`PUT`&&method!==`DELETE`&&method!==`PATCH`&&method!==`OPTIONS`&&DEOPT_PATHS.push(path);methods[method]=content};export let toRoutes=()=>{let str=`{`;for(let i=0;i<DEOPT_PATHS.length;i++){let back=`return mnf},`;let path=DEOPT_PATHS[i];str+=`"`+path+`":(mr,mi)=>{`;let methods=METHOD_ROUTER[path];delete METHOD_ROUTER[path];let first=true;for(let method in methods)if(method===``)back=methods[``]+`},`;else{if(first){first=false;str+=`if(`}else str+=`else if(`;str+=`mr.method==="`+method+`"){`+methods[method]+`}`}str+=back}for(const path in METHOD_ROUTER){str+=`"`+path;let methods=METHOD_ROUTER[path];if(methods[``]==null){str+=`":{`;for(const method in methods)str+=method+`:(mr,mi)=>{`+methods[method]+`},`;str+=`},`}else str+=`":(mr,mi)=>{`+methods[``]+`},`}return str+`}`};
|
package/bun/index.d.ts
DELETED
package/bun/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export let request=`mr`;export let server=`mi`;export{build}from"./compiler/index.js";
|
package/compilers/call.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type Identifier } from "runtime-compiler";
|
|
2
|
-
import type { HandlerScope } from "./scope.ts";
|
|
3
|
-
import type { SendLayer } from "../response.ts";
|
|
4
|
-
export interface Call<T extends (...args: any[]) => any> {
|
|
5
|
-
0: T;
|
|
6
|
-
1: Identifier<any>[];
|
|
7
|
-
}
|
|
8
|
-
export declare const buildCall: (scope: HandlerScope, fn: (...args: any[]) => any, args: string, argsCount: number) => string;
|
|
9
|
-
export declare const buildRouteCall: SendLayer<any>[0];
|
package/compilers/call.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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/compilers/globals.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { type Identifier, type Scope } from "runtime-compiler";
|
|
2
|
-
import { isErr } from "@safe-std/error";
|
|
3
|
-
/**
|
|
4
|
-
* @example
|
|
5
|
-
* '(req,env,ctx)'
|
|
6
|
-
*/
|
|
7
|
-
export declare let HANDLER_ARGS: string;
|
|
8
|
-
/**
|
|
9
|
-
* @example
|
|
10
|
-
* setHandlerArgs('(req,env,ctx)');
|
|
11
|
-
*/
|
|
12
|
-
export declare const setHandlerArgs: (str: string) => void;
|
|
13
|
-
/**
|
|
14
|
-
* Store local variables
|
|
15
|
-
*/
|
|
16
|
-
export declare let TMP_SCOPE: Scope;
|
|
17
|
-
/**
|
|
18
|
-
* Check whether value is an error
|
|
19
|
-
*/
|
|
20
|
-
export declare let IS_ERR: Identifier<typeof isErr>;
|
|
21
|
-
export declare const initScope: () => void;
|
package/compilers/globals.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{declareLocal,injectExternal}from"runtime-compiler";import{isErr}from"@safe-std/error";export let HANDLER_ARGS;export let setHandlerArgs=str=>{HANDLER_ARGS=str};export let TMP_SCOPE;export let IS_ERR;export let initScope=()=>{TMP_SCOPE=[`let mhh=['content-type','text/html'],mho={headers:mhh},mnf=new Response(null,{status:404});`,0];IS_ERR=declareLocal(TMP_SCOPE,injectExternal(isErr))};
|
package/compilers/scope.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Handler scope state.
|
|
3
|
-
*/
|
|
4
|
-
export interface HandlerScope {
|
|
5
|
-
/**
|
|
6
|
-
* Scope flags.
|
|
7
|
-
*
|
|
8
|
-
* bit 0: scope requires async or not
|
|
9
|
-
* bit 1: scope requires context or not
|
|
10
|
-
*/
|
|
11
|
-
0: number;
|
|
12
|
-
slice: () => this;
|
|
13
|
-
}
|
|
14
|
-
export declare const wrapScope: (scope: HandlerScope, content: string) => string;
|
package/compilers/scope.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{declareLocal}from"runtime-compiler";import{HANDLER_ARGS,TMP_SCOPE}from"./globals.js";export let wrapScope=(scope,content)=>{let flags=scope[0];(flags&2)===2&&(content=`let mh=[],mc={status:200,headers:mh};`+content);return(flags&1)===1?`return `+declareLocal(TMP_SCOPE,`async`+HANDLER_ARGS+`=>{`+content+`}`)+HANDLER_ARGS:content};
|
package/layer.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { Identifier } from "runtime-compiler";
|
|
2
|
-
import type { ResponseState } from "./response.ts";
|
|
3
|
-
import type { HandlerScope } from "./compilers/scope.ts";
|
|
4
|
-
/**
|
|
5
|
-
* @example
|
|
6
|
-
* f[0](f, scope);
|
|
7
|
-
*/
|
|
8
|
-
export interface AnyLayer {
|
|
9
|
-
0: (self: any, scope: HandlerScope) => string;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* @example
|
|
13
|
-
* f[0](f, scope);
|
|
14
|
-
*/
|
|
15
|
-
export interface Layer {
|
|
16
|
-
0: (self: this, scope: HandlerScope) => string;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* @example
|
|
20
|
-
* f[0](f, scope, 'p0,p1,');
|
|
21
|
-
*/
|
|
22
|
-
export interface AnyRouteLayer<Params extends any[]> {
|
|
23
|
-
0: (self: any, scope: HandlerScope, params: string, paramsCount: number) => string;
|
|
24
|
-
"~"?: Params;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* @example
|
|
28
|
-
* f[0](f, scope, 'p0,p1,');
|
|
29
|
-
*/
|
|
30
|
-
export interface RouteLayer<Params extends any[]> {
|
|
31
|
-
0: (self: this, scope: HandlerScope, params: string, paramsCount: number) => string;
|
|
32
|
-
"~"?: Params;
|
|
33
|
-
}
|
|
34
|
-
///
|
|
35
|
-
/// Impls
|
|
36
|
-
///
|
|
37
|
-
interface TapLayer extends Layer {
|
|
38
|
-
1: (...args: any[]) => any;
|
|
39
|
-
2: Identifier<any>[];
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Tap a function to request lifecycle.
|
|
43
|
-
*/
|
|
44
|
-
export declare const tap: <Args extends Identifier<any>[]>(fn: (...args: [...{ [K in keyof Args] : Args[K]["~type"] }, res: ResponseState]) => void | Promise<void>, ...args: Args) => TapLayer;
|
|
45
|
-
export {};
|
package/layer.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{buildCall}from"./compilers/call.js";let loadTap=(self,scope)=>{let args=self[2];return buildCall(scope,self[1],args.join(),args.length)+`;`};export let tap=(fn,...args)=>[loadTap,fn,args];
|
package/response.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { Identifier } from "runtime-compiler";
|
|
2
|
-
import type { RouteLayer } from "./layer.ts";
|
|
3
|
-
/**
|
|
4
|
-
* Describe a header pair
|
|
5
|
-
*/
|
|
6
|
-
export type ResponseHeader = [string, string] | readonly [string, string];
|
|
7
|
-
/**
|
|
8
|
-
* Response state
|
|
9
|
-
*/
|
|
10
|
-
export interface ResponseState {
|
|
11
|
-
status: number;
|
|
12
|
-
headers: ResponseHeader[];
|
|
13
|
-
}
|
|
14
|
-
export interface SendLayer<Params extends any[]> extends RouteLayer<Params> {
|
|
15
|
-
1: (...args: any[]) => any;
|
|
16
|
-
2: Identifier<any>[];
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* @example
|
|
20
|
-
* router.get('/', send.raw(() => 'Hi'))
|
|
21
|
-
*/
|
|
22
|
-
export declare const raw: <
|
|
23
|
-
const Args extends Identifier<any>[],
|
|
24
|
-
Params extends any[] = []
|
|
25
|
-
>(fn: (...args: [...{ [K in keyof Args] : Args[K]["~type"] }, ...Params, res: ResponseState]) => BodyInit | Promise<BodyInit>, ...args: Args) => SendLayer<Params>;
|
|
26
|
-
/**
|
|
27
|
-
* @example
|
|
28
|
-
* router.post('/', send.json(() => ({ hello: 'world' })))
|
|
29
|
-
*/
|
|
30
|
-
export declare const json: <
|
|
31
|
-
const Args extends Identifier<any>[],
|
|
32
|
-
Params extends any[] = []
|
|
33
|
-
>(fn: (...args: [...{ [K in keyof Args] : Args[K]["~type"] }, ...Params, res: ResponseState]) => any, ...args: Args) => SendLayer<Params>;
|
|
34
|
-
/**
|
|
35
|
-
* @example
|
|
36
|
-
* router.get('/', send.html(() => '<p>Hi</p>'))
|
|
37
|
-
*/
|
|
38
|
-
export declare const html: <
|
|
39
|
-
const Args extends Identifier<any>[],
|
|
40
|
-
Params extends any[] = []
|
|
41
|
-
>(fn: (...args: [...{ [K in keyof Args] : Args[K]["~type"] }, ...Params, res: ResponseState]) => BodyInit | Promise<BodyInit>, ...args: Args) => SendLayer<Params>;
|
package/response.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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/utils.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const argsToArray: <T extends any[]>(...args: T) => T;
|
package/utils.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export let argsToArray=(...args)=>args;
|