shokupan 0.0.1 → 0.2.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/README.md +13 -12
- package/dist/analysis/openapi-analyzer.d.ts +142 -0
- package/dist/cli.cjs +62 -2
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +62 -2
- package/dist/cli.js.map +1 -1
- package/dist/context.d.ts +59 -5
- package/dist/decorators.d.ts +5 -1
- package/dist/index.cjs +1799 -737
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1799 -737
- package/dist/index.js.map +1 -1
- package/dist/middleware.d.ts +2 -0
- package/dist/openapi-analyzer-BN0wFCML.cjs +772 -0
- package/dist/openapi-analyzer-BN0wFCML.cjs.map +1 -0
- package/dist/openapi-analyzer-BTExMLX4.js +772 -0
- package/dist/openapi-analyzer-BTExMLX4.js.map +1 -0
- package/dist/plugins/debugview/plugin.d.ts +34 -0
- package/dist/plugins/openapi-validator.d.ts +2 -0
- package/dist/plugins/openapi.d.ts +10 -0
- package/dist/plugins/proxy.d.ts +9 -0
- package/dist/plugins/scalar.d.ts +3 -1
- package/dist/plugins/serve-static.d.ts +3 -0
- package/dist/plugins/server-adapter.d.ts +13 -0
- package/dist/response.d.ts +4 -0
- package/dist/router.d.ts +43 -15
- package/dist/server-adapter-BD6oKEto.cjs +81 -0
- package/dist/server-adapter-BD6oKEto.cjs.map +1 -0
- package/dist/server-adapter-CnQFr4P7.js +64 -0
- package/dist/server-adapter-CnQFr4P7.js.map +1 -0
- package/dist/shokupan.d.ts +16 -7
- package/dist/symbol.d.ts +2 -0
- package/dist/types.d.ts +120 -1
- package/package.json +9 -3
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { OpenAPI } from '@scalar/openapi-types';
|
|
2
|
+
import { Server } from 'bun';
|
|
2
3
|
import { ShokupanContext } from './context';
|
|
3
4
|
import { $isRouter } from './symbol';
|
|
4
|
-
export type DeepPartial<T> = T extends object ? {
|
|
5
|
+
export type DeepPartial<T> = T extends Function ? T : T extends object ? {
|
|
5
6
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
6
7
|
} : T;
|
|
7
8
|
export type MethodAPISpec = OpenAPI.Operation;
|
|
@@ -18,6 +19,18 @@ export interface OpenAPIOptions {
|
|
|
18
19
|
defaultTagGroup?: string;
|
|
19
20
|
defaultTag?: string;
|
|
20
21
|
}
|
|
22
|
+
export interface ShokupanHooks<T = any> {
|
|
23
|
+
onError?: (error: unknown, ctx: ShokupanContext<T>) => void | Promise<void>;
|
|
24
|
+
onRequestStart?: (ctx: ShokupanContext<T>) => void | Promise<void>;
|
|
25
|
+
onRequestEnd?: (ctx: ShokupanContext<T>) => void | Promise<void>;
|
|
26
|
+
onResponseStart?: (ctx: ShokupanContext<T>, response: Response) => void | Promise<void>;
|
|
27
|
+
onResponseEnd?: (ctx: ShokupanContext<T>, response: Response) => void | Promise<void>;
|
|
28
|
+
beforeValidate?: (ctx: ShokupanContext<T>, data: any) => void | Promise<void>;
|
|
29
|
+
afterValidate?: (ctx: ShokupanContext<T>, data: any) => void | Promise<void>;
|
|
30
|
+
onReadTimeout?: (ctx: ShokupanContext<T>) => void | Promise<void>;
|
|
31
|
+
onWriteTimeout?: (ctx: ShokupanContext<T>) => void | Promise<void>;
|
|
32
|
+
onRequestTimeout?: (ctx: ShokupanContext<T>) => void | Promise<void>;
|
|
33
|
+
}
|
|
21
34
|
export interface CookieOptions {
|
|
22
35
|
maxAge?: number;
|
|
23
36
|
expires?: Date;
|
|
@@ -39,12 +52,32 @@ export declare enum RouteParamType {
|
|
|
39
52
|
REQUEST = "REQUEST",
|
|
40
53
|
CONTEXT = "CONTEXT"
|
|
41
54
|
}
|
|
55
|
+
export interface ServerFactory {
|
|
56
|
+
(options: any): Server | Promise<Server>;
|
|
57
|
+
}
|
|
42
58
|
export type NextFn = () => Promise<any>;
|
|
43
59
|
export type Middleware = (ctx: ShokupanContext<unknown>, next: NextFn) => Promise<any> | any;
|
|
60
|
+
export type JSXRenderer = (element: any, args?: unknown) => string | Promise<string>;
|
|
44
61
|
export type ShokupanRouteConfig = DeepPartial<{
|
|
45
62
|
name: string;
|
|
46
63
|
group: string;
|
|
64
|
+
/**
|
|
65
|
+
* Timeout for this specific route (milliseconds).
|
|
66
|
+
*/
|
|
67
|
+
requestTimeout: number;
|
|
47
68
|
openapi: DeepPartial<OpenAPI.Operation>;
|
|
69
|
+
/**
|
|
70
|
+
* Custom renderer for this route.
|
|
71
|
+
*/
|
|
72
|
+
renderer: JSXRenderer;
|
|
73
|
+
/**
|
|
74
|
+
* Hooks for this route/router.
|
|
75
|
+
*/
|
|
76
|
+
hooks: ShokupanHooks;
|
|
77
|
+
/**
|
|
78
|
+
* Whether to enforce that only controller classes (constructors) are accepted by the router.
|
|
79
|
+
*/
|
|
80
|
+
controllersOnly: boolean;
|
|
48
81
|
}>;
|
|
49
82
|
export type ShokupanRoute = {
|
|
50
83
|
method: Method;
|
|
@@ -58,13 +91,69 @@ export type ShokupanRoute = {
|
|
|
58
91
|
handler: ShokupanHandler;
|
|
59
92
|
spec?: GuardAPISpec;
|
|
60
93
|
}[];
|
|
94
|
+
requestTimeout?: number;
|
|
95
|
+
renderer?: JSXRenderer;
|
|
96
|
+
/**
|
|
97
|
+
* Hooks from the router/route definition
|
|
98
|
+
*/
|
|
99
|
+
hooks?: ShokupanHooks;
|
|
61
100
|
};
|
|
62
101
|
export type ShokupanConfig<T extends Record<string, any> = Record<string, any>> = DeepPartial<{
|
|
102
|
+
/**
|
|
103
|
+
* The port to be used for the server.
|
|
104
|
+
* @default 3000
|
|
105
|
+
*/
|
|
63
106
|
port: number;
|
|
107
|
+
/**
|
|
108
|
+
* The hostname to be used for the server.
|
|
109
|
+
* @default "localhost"
|
|
110
|
+
*/
|
|
64
111
|
hostname: string;
|
|
112
|
+
/**
|
|
113
|
+
* Whether to run in development mode.
|
|
114
|
+
* @default process.env.NODE_ENV !== "production"
|
|
115
|
+
*/
|
|
65
116
|
development: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Whether to enable AsyncLocalStorage.
|
|
119
|
+
* (Request local storage)
|
|
120
|
+
* @default false
|
|
121
|
+
*/
|
|
66
122
|
enableAsyncLocalStorage: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Whether to enable OpenAPI generation.
|
|
125
|
+
* @default true
|
|
126
|
+
*/
|
|
127
|
+
enableOpenApiGen: boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Whether to reuse the port.
|
|
130
|
+
* @default false
|
|
131
|
+
*/
|
|
132
|
+
reusePort: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Whether to enforce that only controller classes (constructors) are accepted by the router.
|
|
135
|
+
* @default false
|
|
136
|
+
*/
|
|
137
|
+
controllersOnly: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Whether to enable OpenTelemetry tracing.
|
|
140
|
+
* @default false
|
|
141
|
+
*/
|
|
142
|
+
enableTracing?: boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Whether to enable middleware and handler tracking.
|
|
145
|
+
* When enabled, `ctx.handlerStack` will be populated with the handlers the request has passed through.
|
|
146
|
+
* Also, `ctx.state` will be a Proxy that tracks changes made by each handler.
|
|
147
|
+
* @default false
|
|
148
|
+
*/
|
|
149
|
+
enableMiddlewareTracking: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* HTTP logger function.
|
|
152
|
+
*/
|
|
67
153
|
httpLogger: (ctx: ShokupanContext<T>) => void;
|
|
154
|
+
/**
|
|
155
|
+
* Logger object.
|
|
156
|
+
*/
|
|
68
157
|
logger: {
|
|
69
158
|
verbose: boolean;
|
|
70
159
|
info: (msg: string, props: Record<string, any>) => void;
|
|
@@ -76,6 +165,36 @@ export type ShokupanConfig<T extends Record<string, any> = Record<string, any>>
|
|
|
76
165
|
*/
|
|
77
166
|
fatal: (msg: string, props: Record<string, any>) => void;
|
|
78
167
|
};
|
|
168
|
+
/**
|
|
169
|
+
* Timeout for reading the request body (milliseconds).
|
|
170
|
+
* Maps to Bun's `idleTimeout`.
|
|
171
|
+
* @default 30000
|
|
172
|
+
*/
|
|
173
|
+
readTimeout: number;
|
|
174
|
+
/**
|
|
175
|
+
* Timeout for processing the request (milliseconds).
|
|
176
|
+
* Maps to `server.timeout(req, seconds)`.
|
|
177
|
+
* @default 0 (disabled)
|
|
178
|
+
*/
|
|
179
|
+
requestTimeout: number;
|
|
180
|
+
/**
|
|
181
|
+
* Timeout for writing the response (milliseconds).
|
|
182
|
+
* Not currently supported by Bun.serve natively.
|
|
183
|
+
*/
|
|
184
|
+
writeTimeout: number;
|
|
185
|
+
/**
|
|
186
|
+
* JSX Rendering function.
|
|
187
|
+
*/
|
|
188
|
+
renderer: JSXRenderer;
|
|
189
|
+
/**
|
|
190
|
+
* Factory function to create the server instance.
|
|
191
|
+
* Defaults to Bun.serve.
|
|
192
|
+
*/
|
|
193
|
+
serverFactory: ServerFactory;
|
|
194
|
+
/**
|
|
195
|
+
* Lifecycle hooks.
|
|
196
|
+
*/
|
|
197
|
+
hooks: ShokupanHooks<T>;
|
|
79
198
|
[key: string]: any;
|
|
80
199
|
}>;
|
|
81
200
|
export interface RequestOptions {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shokupan",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Shokupan is a low-lift modern web framework for Bun.",
|
|
5
5
|
"author": "Andrew G. Knackstedt",
|
|
6
6
|
"repository": {
|
|
@@ -58,9 +58,16 @@
|
|
|
58
58
|
"@opentelemetry/semantic-conventions": "^1.38.0",
|
|
59
59
|
"@scalar/api-reference": "^1.40.9",
|
|
60
60
|
"@scalar/openapi-types": "^0.5.3",
|
|
61
|
+
"@surrealdb/node": "^2.4.0",
|
|
62
|
+
"ajv": "^8.17.1",
|
|
63
|
+
"ajv-formats": "^3.0.1",
|
|
61
64
|
"arctic": "^3.7.0",
|
|
65
|
+
"class-transformer": "^0.5.1",
|
|
66
|
+
"class-validator": "^0.14.3",
|
|
62
67
|
"eta": "^4.5.0",
|
|
63
68
|
"jose": "^6.1.3",
|
|
69
|
+
"reflect-metadata": "^0.2.2",
|
|
70
|
+
"surrealdb": "^2.0.0-alpha.14",
|
|
64
71
|
"tslib": "^2.8.1"
|
|
65
72
|
},
|
|
66
73
|
"devDependencies": {
|
|
@@ -69,7 +76,6 @@
|
|
|
69
76
|
"@types/axios": "^0.9.36",
|
|
70
77
|
"@types/bun": "^1.2.23",
|
|
71
78
|
"@types/supertest": "^6.0.3",
|
|
72
|
-
"ajv": "^8.17.1",
|
|
73
79
|
"axios": "^1.13.2",
|
|
74
80
|
"get-port": "^7.1.0",
|
|
75
81
|
"supertest": "^7.1.4",
|
|
@@ -79,4 +85,4 @@
|
|
|
79
85
|
"vite-plugin-dts": "^4.5.4",
|
|
80
86
|
"zod": "^4.2.1"
|
|
81
87
|
}
|
|
82
|
-
}
|
|
88
|
+
}
|