@mokup/server 1.1.1 → 1.1.3
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 +9 -0
- package/README.zh-CN.md +9 -0
- package/dist/connect.cjs +25 -0
- package/dist/connect.d.cts +19 -0
- package/dist/connect.d.mts +19 -0
- package/dist/connect.d.ts +19 -0
- package/dist/connect.mjs +23 -0
- package/dist/express.cjs +11 -0
- package/dist/express.d.cts +18 -0
- package/dist/express.d.mts +18 -0
- package/dist/express.d.ts +18 -0
- package/dist/express.mjs +9 -0
- package/dist/fastify.cjs +39 -0
- package/dist/fastify.d.cts +29 -0
- package/dist/fastify.d.mts +29 -0
- package/dist/fastify.d.ts +29 -0
- package/dist/fastify.mjs +37 -0
- package/dist/fetch-server.cjs +1659 -0
- package/dist/fetch-server.d.cts +108 -0
- package/dist/fetch-server.d.mts +108 -0
- package/dist/fetch-server.d.ts +108 -0
- package/dist/fetch-server.mjs +1652 -0
- package/dist/fetch.cjs +26 -0
- package/dist/fetch.d.cts +17 -0
- package/dist/fetch.d.mts +17 -0
- package/dist/fetch.d.ts +17 -0
- package/dist/fetch.mjs +24 -0
- package/dist/hono.cjs +27 -0
- package/dist/hono.d.cts +32 -0
- package/dist/hono.d.mts +32 -0
- package/dist/hono.d.ts +32 -0
- package/dist/hono.mjs +25 -0
- package/dist/index.cjs +29 -1677
- package/dist/index.d.cts +42 -136
- package/dist/index.d.mts +42 -136
- package/dist/index.d.ts +42 -136
- package/dist/index.mjs +28 -1666
- package/dist/koa.cjs +38 -0
- package/dist/koa.d.cts +29 -0
- package/dist/koa.d.mts +29 -0
- package/dist/koa.d.ts +29 -0
- package/dist/koa.mjs +36 -0
- package/dist/node.cjs +26 -0
- package/dist/node.d.cts +13 -0
- package/dist/node.d.mts +13 -0
- package/dist/node.d.ts +13 -0
- package/dist/node.mjs +19 -0
- package/dist/shared/server.CyVIKPsp.d.cts +214 -0
- package/dist/shared/server.CyVIKPsp.d.mts +214 -0
- package/dist/shared/server.CyVIKPsp.d.ts +214 -0
- package/dist/shared/server.D0gAciOr.d.cts +46 -0
- package/dist/shared/server.D0gAciOr.d.mts +46 -0
- package/dist/shared/server.D0gAciOr.d.ts +46 -0
- package/dist/shared/server.DkerfsA-.d.cts +73 -0
- package/dist/shared/server.DkerfsA-.d.mts +73 -0
- package/dist/shared/server.DkerfsA-.d.ts +73 -0
- package/dist/shared/{server.Dje1y79O.mjs → server.LbftO9Jh.mjs} +58 -77
- package/dist/shared/{server.BdTl0qJd.cjs → server.aaygIV2Q.cjs} +59 -77
- package/dist/worker-node.cjs +74 -0
- package/dist/worker-node.d.cts +40 -0
- package/dist/worker-node.d.mts +40 -0
- package/dist/worker-node.d.ts +40 -0
- package/dist/worker-node.mjs +72 -0
- package/dist/worker.cjs +6 -2
- package/dist/worker.d.cts +24 -2
- package/dist/worker.d.mts +24 -2
- package/dist/worker.d.ts +24 -2
- package/dist/worker.mjs +6 -2
- package/package.json +44 -4
- package/dist/shared/server.DNITwCtQ.d.cts +0 -15
- package/dist/shared/server.DNITwCtQ.d.mts +0 -15
- package/dist/shared/server.DNITwCtQ.d.ts +0 -15
package/dist/index.d.cts
CHANGED
|
@@ -1,137 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { a as
|
|
3
|
-
|
|
1
|
+
import { R as RouteDirectoryConfig, M as MiddlewareRegistry } from './shared/server.CyVIKPsp.cjs';
|
|
2
|
+
export { a as MiddlewarePosition, b as ResolvedMiddleware, c as RouteRule } from './shared/server.CyVIKPsp.cjs';
|
|
3
|
+
export { createFetchHandler } from './fetch.cjs';
|
|
4
|
+
export { F as FetchHandler, S as ServerOptions, W as WorkerBundle, a as WorkerInput } from './shared/server.DkerfsA-.cjs';
|
|
5
|
+
export { createMokupWorker } from './worker.cjs';
|
|
4
6
|
export { Manifest, ManifestRoute, ModuleMap, RuntimeOptions } from '@mokup/runtime';
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
declare function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
44
|
-
type RouteStaticResponse = string | number | boolean | bigint | symbol | null | undefined | object;
|
|
45
|
-
type RouteHandlerResult = RouteStaticResponse | Response;
|
|
46
|
-
type RequestHandler = (context: Context) => RouteHandlerResult | Promise<RouteHandlerResult>;
|
|
47
|
-
type RouteResponse = RouteStaticResponse | RequestHandler;
|
|
48
|
-
interface ResolvedMiddleware {
|
|
49
|
-
handle: MiddlewareHandler;
|
|
50
|
-
source: string;
|
|
51
|
-
index: number;
|
|
52
|
-
}
|
|
53
|
-
interface ResolvedRoute {
|
|
54
|
-
file: string;
|
|
55
|
-
template: string;
|
|
56
|
-
method: HttpMethod;
|
|
57
|
-
tokens: RouteToken[];
|
|
58
|
-
score: number[];
|
|
59
|
-
handler: RouteResponse;
|
|
60
|
-
middlewares?: ResolvedMiddleware[];
|
|
61
|
-
status?: number;
|
|
62
|
-
headers?: Record<string, string>;
|
|
63
|
-
delay?: number;
|
|
64
|
-
ruleIndex?: number;
|
|
65
|
-
}
|
|
66
|
-
type RouteTable = ResolvedRoute[];
|
|
67
|
-
|
|
68
|
-
type DirInput = string | string[] | ((root: string) => string | string[]) | undefined;
|
|
69
|
-
|
|
70
|
-
interface FetchServerOptions {
|
|
71
|
-
dir?: DirInput;
|
|
72
|
-
prefix?: string;
|
|
73
|
-
include?: RegExp | RegExp[];
|
|
74
|
-
exclude?: RegExp | RegExp[];
|
|
75
|
-
ignorePrefix?: string | string[];
|
|
76
|
-
watch?: boolean;
|
|
77
|
-
log?: boolean;
|
|
78
|
-
playground?: boolean | {
|
|
79
|
-
path?: string;
|
|
80
|
-
enabled?: boolean;
|
|
81
|
-
};
|
|
82
|
-
host?: string;
|
|
83
|
-
port?: number;
|
|
84
|
-
root?: string;
|
|
85
|
-
}
|
|
86
|
-
type FetchServerOptionsInput = FetchServerOptions | FetchServerOptions[];
|
|
87
|
-
|
|
88
|
-
interface FetchServer {
|
|
89
|
-
fetch: (request: Request) => Promise<Response>;
|
|
90
|
-
refresh: () => Promise<void>;
|
|
91
|
-
getRoutes: () => RouteTable;
|
|
92
|
-
injectWebSocket?: (server: NodeWebSocketServer) => void;
|
|
93
|
-
close?: () => Promise<void>;
|
|
94
|
-
}
|
|
95
|
-
interface NodeWebSocketServer {
|
|
96
|
-
on: (event: string, listener: (...args: unknown[]) => void) => void;
|
|
97
|
-
}
|
|
98
|
-
declare function createFetchServer(options?: FetchServerOptionsInput): Promise<FetchServer>;
|
|
99
|
-
|
|
100
|
-
interface HonoContextLike {
|
|
101
|
-
req: {
|
|
102
|
-
raw: Request;
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
type HonoNext = () => Promise<Response | void>;
|
|
106
|
-
type HonoMiddleware = (context: HonoContextLike, next: HonoNext) => Promise<Response | void>;
|
|
107
|
-
interface HonoRouteLike {
|
|
108
|
-
basePath: string;
|
|
109
|
-
path: string;
|
|
110
|
-
method: string;
|
|
111
|
-
handler: HonoMiddleware;
|
|
112
|
-
}
|
|
113
|
-
declare function createHonoMiddleware(options: ServerOptions): HonoMiddleware & {
|
|
114
|
-
routes: HonoRouteLike[];
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
interface KoaContextLike {
|
|
118
|
-
req: NodeRequestLike;
|
|
119
|
-
request?: {
|
|
120
|
-
body?: unknown;
|
|
121
|
-
headers?: Record<string, string | string[] | undefined>;
|
|
122
|
-
};
|
|
123
|
-
status?: number;
|
|
124
|
-
body?: unknown;
|
|
125
|
-
set: (header: Record<string, string>) => void;
|
|
126
|
-
}
|
|
127
|
-
type KoaNext = () => Promise<unknown>;
|
|
128
|
-
declare function createKoaMiddleware(options: ServerOptions): (ctx: KoaContextLike, next: KoaNext) => Promise<void>;
|
|
129
|
-
|
|
130
|
-
interface FetchWorker {
|
|
131
|
-
fetch: (request: Request) => Promise<Response>;
|
|
132
|
-
}
|
|
133
|
-
declare function createMokupWorker(input: string): Promise<FetchWorker>;
|
|
134
|
-
declare function createMokupWorker(input: Exclude<WorkerInput, string>): FetchWorker;
|
|
135
|
-
|
|
136
|
-
export { FetchHandler, ServerOptions, WorkerInput, createConnectMiddleware, createExpressMiddleware, createFastifyPlugin, createFetchHandler, createFetchServer, createHonoMiddleware, createKoaMiddleware, createMokupWorker };
|
|
137
|
-
export type { FetchServer, FetchServerOptions, FetchServerOptionsInput };
|
|
7
|
+
export { MiddlewareHandler } from '@mokup/shared/hono';
|
|
8
|
+
|
|
9
|
+
type DefineConfigFactory = (context: {
|
|
10
|
+
pre: MiddlewareRegistry;
|
|
11
|
+
normal: MiddlewareRegistry;
|
|
12
|
+
post: MiddlewareRegistry;
|
|
13
|
+
}) => RouteDirectoryConfig | void;
|
|
14
|
+
/**
|
|
15
|
+
* Define a directory config with Hono-style middleware registration.
|
|
16
|
+
*
|
|
17
|
+
* @param input - Config object or factory callback.
|
|
18
|
+
* @returns Route directory config with middleware metadata.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* import { defineConfig } from '@mokup/server'
|
|
22
|
+
*
|
|
23
|
+
* export default defineConfig(({ pre, normal, post }) => {
|
|
24
|
+
* pre.use(async (c, next) => {
|
|
25
|
+
* c.header('x-before', '1')
|
|
26
|
+
* await next()
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* normal.use(async (_c, next) => {
|
|
30
|
+
* await next()
|
|
31
|
+
* })
|
|
32
|
+
*
|
|
33
|
+
* post.use(async (c, next) => {
|
|
34
|
+
* await next()
|
|
35
|
+
* c.header('x-after', '1')
|
|
36
|
+
* })
|
|
37
|
+
*
|
|
38
|
+
* return { delay: 120 }
|
|
39
|
+
* })
|
|
40
|
+
*/
|
|
41
|
+
declare function defineConfig(input: RouteDirectoryConfig | DefineConfigFactory): RouteDirectoryConfig;
|
|
42
|
+
|
|
43
|
+
export { MiddlewareRegistry, RouteDirectoryConfig, defineConfig };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,137 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { a as
|
|
3
|
-
|
|
1
|
+
import { R as RouteDirectoryConfig, M as MiddlewareRegistry } from './shared/server.CyVIKPsp.mjs';
|
|
2
|
+
export { a as MiddlewarePosition, b as ResolvedMiddleware, c as RouteRule } from './shared/server.CyVIKPsp.mjs';
|
|
3
|
+
export { createFetchHandler } from './fetch.mjs';
|
|
4
|
+
export { F as FetchHandler, S as ServerOptions, W as WorkerBundle, a as WorkerInput } from './shared/server.DkerfsA-.mjs';
|
|
5
|
+
export { createMokupWorker } from './worker.mjs';
|
|
4
6
|
export { Manifest, ManifestRoute, ModuleMap, RuntimeOptions } from '@mokup/runtime';
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
declare function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
44
|
-
type RouteStaticResponse = string | number | boolean | bigint | symbol | null | undefined | object;
|
|
45
|
-
type RouteHandlerResult = RouteStaticResponse | Response;
|
|
46
|
-
type RequestHandler = (context: Context) => RouteHandlerResult | Promise<RouteHandlerResult>;
|
|
47
|
-
type RouteResponse = RouteStaticResponse | RequestHandler;
|
|
48
|
-
interface ResolvedMiddleware {
|
|
49
|
-
handle: MiddlewareHandler;
|
|
50
|
-
source: string;
|
|
51
|
-
index: number;
|
|
52
|
-
}
|
|
53
|
-
interface ResolvedRoute {
|
|
54
|
-
file: string;
|
|
55
|
-
template: string;
|
|
56
|
-
method: HttpMethod;
|
|
57
|
-
tokens: RouteToken[];
|
|
58
|
-
score: number[];
|
|
59
|
-
handler: RouteResponse;
|
|
60
|
-
middlewares?: ResolvedMiddleware[];
|
|
61
|
-
status?: number;
|
|
62
|
-
headers?: Record<string, string>;
|
|
63
|
-
delay?: number;
|
|
64
|
-
ruleIndex?: number;
|
|
65
|
-
}
|
|
66
|
-
type RouteTable = ResolvedRoute[];
|
|
67
|
-
|
|
68
|
-
type DirInput = string | string[] | ((root: string) => string | string[]) | undefined;
|
|
69
|
-
|
|
70
|
-
interface FetchServerOptions {
|
|
71
|
-
dir?: DirInput;
|
|
72
|
-
prefix?: string;
|
|
73
|
-
include?: RegExp | RegExp[];
|
|
74
|
-
exclude?: RegExp | RegExp[];
|
|
75
|
-
ignorePrefix?: string | string[];
|
|
76
|
-
watch?: boolean;
|
|
77
|
-
log?: boolean;
|
|
78
|
-
playground?: boolean | {
|
|
79
|
-
path?: string;
|
|
80
|
-
enabled?: boolean;
|
|
81
|
-
};
|
|
82
|
-
host?: string;
|
|
83
|
-
port?: number;
|
|
84
|
-
root?: string;
|
|
85
|
-
}
|
|
86
|
-
type FetchServerOptionsInput = FetchServerOptions | FetchServerOptions[];
|
|
87
|
-
|
|
88
|
-
interface FetchServer {
|
|
89
|
-
fetch: (request: Request) => Promise<Response>;
|
|
90
|
-
refresh: () => Promise<void>;
|
|
91
|
-
getRoutes: () => RouteTable;
|
|
92
|
-
injectWebSocket?: (server: NodeWebSocketServer) => void;
|
|
93
|
-
close?: () => Promise<void>;
|
|
94
|
-
}
|
|
95
|
-
interface NodeWebSocketServer {
|
|
96
|
-
on: (event: string, listener: (...args: unknown[]) => void) => void;
|
|
97
|
-
}
|
|
98
|
-
declare function createFetchServer(options?: FetchServerOptionsInput): Promise<FetchServer>;
|
|
99
|
-
|
|
100
|
-
interface HonoContextLike {
|
|
101
|
-
req: {
|
|
102
|
-
raw: Request;
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
type HonoNext = () => Promise<Response | void>;
|
|
106
|
-
type HonoMiddleware = (context: HonoContextLike, next: HonoNext) => Promise<Response | void>;
|
|
107
|
-
interface HonoRouteLike {
|
|
108
|
-
basePath: string;
|
|
109
|
-
path: string;
|
|
110
|
-
method: string;
|
|
111
|
-
handler: HonoMiddleware;
|
|
112
|
-
}
|
|
113
|
-
declare function createHonoMiddleware(options: ServerOptions): HonoMiddleware & {
|
|
114
|
-
routes: HonoRouteLike[];
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
interface KoaContextLike {
|
|
118
|
-
req: NodeRequestLike;
|
|
119
|
-
request?: {
|
|
120
|
-
body?: unknown;
|
|
121
|
-
headers?: Record<string, string | string[] | undefined>;
|
|
122
|
-
};
|
|
123
|
-
status?: number;
|
|
124
|
-
body?: unknown;
|
|
125
|
-
set: (header: Record<string, string>) => void;
|
|
126
|
-
}
|
|
127
|
-
type KoaNext = () => Promise<unknown>;
|
|
128
|
-
declare function createKoaMiddleware(options: ServerOptions): (ctx: KoaContextLike, next: KoaNext) => Promise<void>;
|
|
129
|
-
|
|
130
|
-
interface FetchWorker {
|
|
131
|
-
fetch: (request: Request) => Promise<Response>;
|
|
132
|
-
}
|
|
133
|
-
declare function createMokupWorker(input: string): Promise<FetchWorker>;
|
|
134
|
-
declare function createMokupWorker(input: Exclude<WorkerInput, string>): FetchWorker;
|
|
135
|
-
|
|
136
|
-
export { FetchHandler, ServerOptions, WorkerInput, createConnectMiddleware, createExpressMiddleware, createFastifyPlugin, createFetchHandler, createFetchServer, createHonoMiddleware, createKoaMiddleware, createMokupWorker };
|
|
137
|
-
export type { FetchServer, FetchServerOptions, FetchServerOptionsInput };
|
|
7
|
+
export { MiddlewareHandler } from '@mokup/shared/hono';
|
|
8
|
+
|
|
9
|
+
type DefineConfigFactory = (context: {
|
|
10
|
+
pre: MiddlewareRegistry;
|
|
11
|
+
normal: MiddlewareRegistry;
|
|
12
|
+
post: MiddlewareRegistry;
|
|
13
|
+
}) => RouteDirectoryConfig | void;
|
|
14
|
+
/**
|
|
15
|
+
* Define a directory config with Hono-style middleware registration.
|
|
16
|
+
*
|
|
17
|
+
* @param input - Config object or factory callback.
|
|
18
|
+
* @returns Route directory config with middleware metadata.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* import { defineConfig } from '@mokup/server'
|
|
22
|
+
*
|
|
23
|
+
* export default defineConfig(({ pre, normal, post }) => {
|
|
24
|
+
* pre.use(async (c, next) => {
|
|
25
|
+
* c.header('x-before', '1')
|
|
26
|
+
* await next()
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* normal.use(async (_c, next) => {
|
|
30
|
+
* await next()
|
|
31
|
+
* })
|
|
32
|
+
*
|
|
33
|
+
* post.use(async (c, next) => {
|
|
34
|
+
* await next()
|
|
35
|
+
* c.header('x-after', '1')
|
|
36
|
+
* })
|
|
37
|
+
*
|
|
38
|
+
* return { delay: 120 }
|
|
39
|
+
* })
|
|
40
|
+
*/
|
|
41
|
+
declare function defineConfig(input: RouteDirectoryConfig | DefineConfigFactory): RouteDirectoryConfig;
|
|
42
|
+
|
|
43
|
+
export { MiddlewareRegistry, RouteDirectoryConfig, defineConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,137 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { a as
|
|
3
|
-
|
|
1
|
+
import { R as RouteDirectoryConfig, M as MiddlewareRegistry } from './shared/server.CyVIKPsp.js';
|
|
2
|
+
export { a as MiddlewarePosition, b as ResolvedMiddleware, c as RouteRule } from './shared/server.CyVIKPsp.js';
|
|
3
|
+
export { createFetchHandler } from './fetch.js';
|
|
4
|
+
export { F as FetchHandler, S as ServerOptions, W as WorkerBundle, a as WorkerInput } from './shared/server.DkerfsA-.js';
|
|
5
|
+
export { createMokupWorker } from './worker.js';
|
|
4
6
|
export { Manifest, ManifestRoute, ModuleMap, RuntimeOptions } from '@mokup/runtime';
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
declare function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
44
|
-
type RouteStaticResponse = string | number | boolean | bigint | symbol | null | undefined | object;
|
|
45
|
-
type RouteHandlerResult = RouteStaticResponse | Response;
|
|
46
|
-
type RequestHandler = (context: Context) => RouteHandlerResult | Promise<RouteHandlerResult>;
|
|
47
|
-
type RouteResponse = RouteStaticResponse | RequestHandler;
|
|
48
|
-
interface ResolvedMiddleware {
|
|
49
|
-
handle: MiddlewareHandler;
|
|
50
|
-
source: string;
|
|
51
|
-
index: number;
|
|
52
|
-
}
|
|
53
|
-
interface ResolvedRoute {
|
|
54
|
-
file: string;
|
|
55
|
-
template: string;
|
|
56
|
-
method: HttpMethod;
|
|
57
|
-
tokens: RouteToken[];
|
|
58
|
-
score: number[];
|
|
59
|
-
handler: RouteResponse;
|
|
60
|
-
middlewares?: ResolvedMiddleware[];
|
|
61
|
-
status?: number;
|
|
62
|
-
headers?: Record<string, string>;
|
|
63
|
-
delay?: number;
|
|
64
|
-
ruleIndex?: number;
|
|
65
|
-
}
|
|
66
|
-
type RouteTable = ResolvedRoute[];
|
|
67
|
-
|
|
68
|
-
type DirInput = string | string[] | ((root: string) => string | string[]) | undefined;
|
|
69
|
-
|
|
70
|
-
interface FetchServerOptions {
|
|
71
|
-
dir?: DirInput;
|
|
72
|
-
prefix?: string;
|
|
73
|
-
include?: RegExp | RegExp[];
|
|
74
|
-
exclude?: RegExp | RegExp[];
|
|
75
|
-
ignorePrefix?: string | string[];
|
|
76
|
-
watch?: boolean;
|
|
77
|
-
log?: boolean;
|
|
78
|
-
playground?: boolean | {
|
|
79
|
-
path?: string;
|
|
80
|
-
enabled?: boolean;
|
|
81
|
-
};
|
|
82
|
-
host?: string;
|
|
83
|
-
port?: number;
|
|
84
|
-
root?: string;
|
|
85
|
-
}
|
|
86
|
-
type FetchServerOptionsInput = FetchServerOptions | FetchServerOptions[];
|
|
87
|
-
|
|
88
|
-
interface FetchServer {
|
|
89
|
-
fetch: (request: Request) => Promise<Response>;
|
|
90
|
-
refresh: () => Promise<void>;
|
|
91
|
-
getRoutes: () => RouteTable;
|
|
92
|
-
injectWebSocket?: (server: NodeWebSocketServer) => void;
|
|
93
|
-
close?: () => Promise<void>;
|
|
94
|
-
}
|
|
95
|
-
interface NodeWebSocketServer {
|
|
96
|
-
on: (event: string, listener: (...args: unknown[]) => void) => void;
|
|
97
|
-
}
|
|
98
|
-
declare function createFetchServer(options?: FetchServerOptionsInput): Promise<FetchServer>;
|
|
99
|
-
|
|
100
|
-
interface HonoContextLike {
|
|
101
|
-
req: {
|
|
102
|
-
raw: Request;
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
type HonoNext = () => Promise<Response | void>;
|
|
106
|
-
type HonoMiddleware = (context: HonoContextLike, next: HonoNext) => Promise<Response | void>;
|
|
107
|
-
interface HonoRouteLike {
|
|
108
|
-
basePath: string;
|
|
109
|
-
path: string;
|
|
110
|
-
method: string;
|
|
111
|
-
handler: HonoMiddleware;
|
|
112
|
-
}
|
|
113
|
-
declare function createHonoMiddleware(options: ServerOptions): HonoMiddleware & {
|
|
114
|
-
routes: HonoRouteLike[];
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
interface KoaContextLike {
|
|
118
|
-
req: NodeRequestLike;
|
|
119
|
-
request?: {
|
|
120
|
-
body?: unknown;
|
|
121
|
-
headers?: Record<string, string | string[] | undefined>;
|
|
122
|
-
};
|
|
123
|
-
status?: number;
|
|
124
|
-
body?: unknown;
|
|
125
|
-
set: (header: Record<string, string>) => void;
|
|
126
|
-
}
|
|
127
|
-
type KoaNext = () => Promise<unknown>;
|
|
128
|
-
declare function createKoaMiddleware(options: ServerOptions): (ctx: KoaContextLike, next: KoaNext) => Promise<void>;
|
|
129
|
-
|
|
130
|
-
interface FetchWorker {
|
|
131
|
-
fetch: (request: Request) => Promise<Response>;
|
|
132
|
-
}
|
|
133
|
-
declare function createMokupWorker(input: string): Promise<FetchWorker>;
|
|
134
|
-
declare function createMokupWorker(input: Exclude<WorkerInput, string>): FetchWorker;
|
|
135
|
-
|
|
136
|
-
export { FetchHandler, ServerOptions, WorkerInput, createConnectMiddleware, createExpressMiddleware, createFastifyPlugin, createFetchHandler, createFetchServer, createHonoMiddleware, createKoaMiddleware, createMokupWorker };
|
|
137
|
-
export type { FetchServer, FetchServerOptions, FetchServerOptionsInput };
|
|
7
|
+
export { MiddlewareHandler } from '@mokup/shared/hono';
|
|
8
|
+
|
|
9
|
+
type DefineConfigFactory = (context: {
|
|
10
|
+
pre: MiddlewareRegistry;
|
|
11
|
+
normal: MiddlewareRegistry;
|
|
12
|
+
post: MiddlewareRegistry;
|
|
13
|
+
}) => RouteDirectoryConfig | void;
|
|
14
|
+
/**
|
|
15
|
+
* Define a directory config with Hono-style middleware registration.
|
|
16
|
+
*
|
|
17
|
+
* @param input - Config object or factory callback.
|
|
18
|
+
* @returns Route directory config with middleware metadata.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* import { defineConfig } from '@mokup/server'
|
|
22
|
+
*
|
|
23
|
+
* export default defineConfig(({ pre, normal, post }) => {
|
|
24
|
+
* pre.use(async (c, next) => {
|
|
25
|
+
* c.header('x-before', '1')
|
|
26
|
+
* await next()
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* normal.use(async (_c, next) => {
|
|
30
|
+
* await next()
|
|
31
|
+
* })
|
|
32
|
+
*
|
|
33
|
+
* post.use(async (c, next) => {
|
|
34
|
+
* await next()
|
|
35
|
+
* c.header('x-after', '1')
|
|
36
|
+
* })
|
|
37
|
+
*
|
|
38
|
+
* return { delay: 120 }
|
|
39
|
+
* })
|
|
40
|
+
*/
|
|
41
|
+
declare function defineConfig(input: RouteDirectoryConfig | DefineConfigFactory): RouteDirectoryConfig;
|
|
42
|
+
|
|
43
|
+
export { MiddlewareRegistry, RouteDirectoryConfig, defineConfig };
|