shokupan 0.11.0 → 0.13.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 +47 -1815
- package/dist/{analyzer-CnKnQ5KV.js → analyzer-B0fMzeIo.js} +2 -2
- package/dist/{analyzer-CnKnQ5KV.js.map → analyzer-B0fMzeIo.js.map} +1 -1
- package/dist/{analyzer-BAhvpNY_.cjs → analyzer-BOtveWL-.cjs} +2 -2
- package/dist/{analyzer-BAhvpNY_.cjs.map → analyzer-BOtveWL-.cjs.map} +1 -1
- package/dist/{analyzer.impl-CfpMu4-g.cjs → analyzer.impl-CUDO6vpn.cjs} +82 -7
- package/dist/analyzer.impl-CUDO6vpn.cjs.map +1 -0
- package/dist/{analyzer.impl-DCiqlXI5.js → analyzer.impl-DmHe92Oi.js} +82 -7
- package/dist/analyzer.impl-DmHe92Oi.js.map +1 -0
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/context.d.ts +40 -8
- package/dist/index.cjs +2876 -506
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -0
- package/dist/index.js +2911 -541
- package/dist/index.js.map +1 -1
- package/dist/plugins/application/api-explorer/static/theme.css +4 -0
- package/dist/plugins/application/auth.d.ts +5 -0
- package/dist/plugins/application/dashboard/fetch-interceptor.d.ts +12 -0
- package/dist/plugins/application/dashboard/plugin.d.ts +9 -0
- package/dist/plugins/application/dashboard/static/requests.js +537 -251
- package/dist/plugins/application/dashboard/static/tabulator.css +23 -3
- package/dist/plugins/application/dashboard/static/theme.css +4 -0
- package/dist/plugins/application/error-view/index.d.ts +14 -0
- package/dist/plugins/application/error-view/monkeypatch.d.ts +9 -0
- package/dist/plugins/application/error-view/util/source-reader.d.ts +10 -0
- package/dist/plugins/application/error-view/views/error.d.ts +2 -0
- package/dist/plugins/application/error-view/views/status.d.ts +2 -0
- package/dist/plugins/application/htmx/index.d.ts +39 -0
- package/dist/plugins/application/mcp-server/plugin.d.ts +38 -0
- package/dist/plugins/application/openapi/analyzer.impl.d.ts +4 -0
- package/dist/plugins/application/openapi/test-setup.d.ts +1 -0
- package/dist/plugins/application/opentelemetry/index.d.ts +33 -0
- package/dist/plugins/middleware/compression.d.ts +12 -2
- package/dist/plugins/middleware/rate-limit.d.ts +5 -0
- package/dist/plugins/middleware/session.d.ts +4 -4
- package/dist/plugins/resilience/decorators.d.ts +23 -0
- package/dist/plugins/resilience/factory.d.ts +5 -0
- package/dist/plugins/resilience/index.d.ts +2 -0
- package/dist/router.d.ts +25 -9
- package/dist/server.d.ts +22 -0
- package/dist/shokupan.d.ts +24 -1
- package/dist/util/adapter/bun.d.ts +8 -0
- package/dist/util/adapter/index.d.ts +4 -0
- package/dist/util/adapter/interface.d.ts +12 -0
- package/dist/util/adapter/node.d.ts +8 -0
- package/dist/util/adapter/wintercg.d.ts +5 -0
- package/dist/util/body-parser.d.ts +30 -0
- package/dist/util/decorators.d.ts +58 -3
- package/dist/util/di.d.ts +3 -8
- package/dist/util/env-loader.d.ts +99 -0
- package/dist/util/mcp-protocol.d.ts +52 -0
- package/dist/util/metadata.d.ts +18 -0
- package/dist/util/promise.d.ts +16 -0
- package/dist/util/request.d.ts +1 -0
- package/dist/util/symbol.d.ts +5 -0
- package/dist/util/types.d.ts +140 -3
- package/package.json +37 -10
- package/dist/analyzer.impl-CfpMu4-g.cjs.map +0 -1
- package/dist/analyzer.impl-DCiqlXI5.js.map +0 -1
- package/dist/plugins/application/dashboard/static/failures.js +0 -85
- package/dist/plugins/application/http-server.d.ts +0 -13
- package/dist/util/adapter/adapters.d.ts +0 -19
- package/dist/util/instrumentation.d.ts +0 -9
|
@@ -5,9 +5,26 @@ import { AsyncAPISpec, GuardAPISpec, MethodAPISpec, Middleware } from './types';
|
|
|
5
5
|
*/
|
|
6
6
|
export declare function Controller(path?: string): (target: any) => void;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Registers this class as a **Singleton** service.
|
|
9
|
+
* A single instance will be created and shared across the process.
|
|
9
10
|
*/
|
|
10
|
-
export declare function
|
|
11
|
+
export declare function Injectable(scope: 'singleton'): ClassDecorator;
|
|
12
|
+
/**
|
|
13
|
+
* Registers this class as an **Instanced** (Transient) service.
|
|
14
|
+
* A new instance will be created every time dependency is resolved.
|
|
15
|
+
*/
|
|
16
|
+
export declare function Injectable(scope: 'instanced'): ClassDecorator;
|
|
17
|
+
/**
|
|
18
|
+
* Property/Parameter Decorator: Injects a service.
|
|
19
|
+
* Used on class properties or constructor parameters.
|
|
20
|
+
*/
|
|
21
|
+
export declare function Inject(token: any): PropertyDecorator & ParameterDecorator;
|
|
22
|
+
/**
|
|
23
|
+
* Decorator: Applies middleware OR injects dependencies.
|
|
24
|
+
* - Class/Method: Middleware
|
|
25
|
+
* - Property/Parameter: Dependency Injection
|
|
26
|
+
*/
|
|
27
|
+
export declare function Use(tokenOrMiddleware?: any | Middleware, ...moreMiddleware: Middleware[]): (target: any, propertyKey?: string, indexOrDescriptor?: PropertyDescriptor | number) => void;
|
|
11
28
|
/**
|
|
12
29
|
* Decorator: Binds a parameter to the request body.
|
|
13
30
|
*/
|
|
@@ -76,4 +93,42 @@ export declare function Event(eventName: string): (target: any, propertyKey: str
|
|
|
76
93
|
/**
|
|
77
94
|
* Decorator: Applies a rate limit to a class or method.
|
|
78
95
|
*/
|
|
79
|
-
export declare function RateLimit(options: RateLimitOptions): (target: any, propertyKey?: string,
|
|
96
|
+
export declare function RateLimit(options: RateLimitOptions): (target: any, propertyKey?: string, indexOrDescriptor?: PropertyDescriptor | number) => void;
|
|
97
|
+
/**
|
|
98
|
+
* Decorator: Registers a method as an MCP Tool.
|
|
99
|
+
* @param name The name of the tool (defaults to method name if not provided)
|
|
100
|
+
* @param description Optional description
|
|
101
|
+
* @param inputSchema Optional JSON Schema for input arguments
|
|
102
|
+
*/
|
|
103
|
+
export declare function Tool(options?: {
|
|
104
|
+
name?: string;
|
|
105
|
+
description?: string;
|
|
106
|
+
inputSchema?: any;
|
|
107
|
+
}): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
108
|
+
/**
|
|
109
|
+
* Decorator: Registers a method as an MCP Prompt.
|
|
110
|
+
* @param name The name of the prompt
|
|
111
|
+
* @param description Optional description
|
|
112
|
+
* @param args Optional list of arguments
|
|
113
|
+
*/
|
|
114
|
+
export declare function Prompt(options?: {
|
|
115
|
+
name?: string;
|
|
116
|
+
description?: string;
|
|
117
|
+
arguments?: {
|
|
118
|
+
name: string;
|
|
119
|
+
description?: string;
|
|
120
|
+
required?: boolean;
|
|
121
|
+
}[];
|
|
122
|
+
}): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
123
|
+
/**
|
|
124
|
+
* Decorator: Registers a method as an MCP Resource handler.
|
|
125
|
+
* @param uri The URI pattern for the resource
|
|
126
|
+
* @param name Optional name
|
|
127
|
+
* @param description Optional description
|
|
128
|
+
* @param mimeType Optional MIME type
|
|
129
|
+
*/
|
|
130
|
+
export declare function Resource(uri: string, options?: {
|
|
131
|
+
name?: string;
|
|
132
|
+
description?: string;
|
|
133
|
+
mimeType?: string;
|
|
134
|
+
}): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
package/dist/util/di.d.ts
CHANGED
|
@@ -6,13 +6,8 @@ export declare class Container {
|
|
|
6
6
|
static register<T>(target: new (...args: any[]) => T, instance: T): void;
|
|
7
7
|
static get<T>(target: new (...args: any[]) => T): T | undefined;
|
|
8
8
|
static has(target: any): boolean;
|
|
9
|
+
private static cache;
|
|
10
|
+
private static resolvingStack;
|
|
9
11
|
static resolve<T>(target: new (...args: any[]) => T): T;
|
|
12
|
+
static teardown(): Promise<void>;
|
|
10
13
|
}
|
|
11
|
-
/**
|
|
12
|
-
* Decorator to mark a class as injectable (Service).
|
|
13
|
-
*/
|
|
14
|
-
export declare function Injectable(): (target: any) => void;
|
|
15
|
-
/**
|
|
16
|
-
* Property Decorator: Injects a service.
|
|
17
|
-
*/
|
|
18
|
-
export declare function Inject(token: any): (target: any, key: string) => void;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export type EnvLoaderOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* If provided, k8s secrets will be loaded from the given paths
|
|
4
|
+
* @default []
|
|
5
|
+
*/
|
|
6
|
+
k8sSecretMountPaths?: string[];
|
|
7
|
+
/**
|
|
8
|
+
* If provided, k8s config maps will be loaded from the given paths
|
|
9
|
+
* @default []
|
|
10
|
+
*/
|
|
11
|
+
k8sConfigMapMountPaths?: string[];
|
|
12
|
+
};
|
|
13
|
+
type Listener<T> = (value: T) => void;
|
|
14
|
+
/**
|
|
15
|
+
* A subject that emits values to listeners.
|
|
16
|
+
*
|
|
17
|
+
* This is used to emit values to listeners when they change.
|
|
18
|
+
*/
|
|
19
|
+
export declare class EmitterSubject<T> {
|
|
20
|
+
private _value;
|
|
21
|
+
private _listeners;
|
|
22
|
+
constructor(initialValue: T);
|
|
23
|
+
get value(): T;
|
|
24
|
+
next(newValue: T): void;
|
|
25
|
+
subscribe(callback: Listener<T>): {
|
|
26
|
+
unsubscribe: () => void;
|
|
27
|
+
};
|
|
28
|
+
toString(): string;
|
|
29
|
+
toJSON(): string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Extend this class with a class of your own. The extended class static properties will then
|
|
33
|
+
* be dynamically loaded from environment variables (additionally .env files).
|
|
34
|
+
* Values will be trimmed then parsed to the type of the property.
|
|
35
|
+
*
|
|
36
|
+
* Secrets should be loaded using the getSecret method -- this prevents them from being logged
|
|
37
|
+
* or otherwise leaked, and enables the use of environment variables to load secrets from
|
|
38
|
+
* k8s secrets, vault, etc.
|
|
39
|
+
*
|
|
40
|
+
* ```typescript
|
|
41
|
+
* class myEnv extends EnvLoader {
|
|
42
|
+
* readonly prop = 123; // loads env variable PROP or PROP (mapped)
|
|
43
|
+
* readonly prop_time = 123; // loads env variable PROP_TIME
|
|
44
|
+
* readonly propTime = 123; // loads env variable PROP_TIME
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare const $secretsCache: unique symbol;
|
|
49
|
+
declare const $secretSubjects: unique symbol;
|
|
50
|
+
declare const $options: unique symbol;
|
|
51
|
+
declare const $watchers: unique symbol;
|
|
52
|
+
declare const $watchersStarted: unique symbol;
|
|
53
|
+
declare const $getSecretValueInternal: unique symbol;
|
|
54
|
+
declare const $getOrCreateSubject: unique symbol;
|
|
55
|
+
declare const $loadSecrets: unique symbol;
|
|
56
|
+
declare const $setupWatchers: unique symbol;
|
|
57
|
+
declare const $updateSubject: unique symbol;
|
|
58
|
+
declare const $updateMappedProperty: unique symbol;
|
|
59
|
+
declare const $mapProperties: unique symbol;
|
|
60
|
+
declare const $assignProperty: unique symbol;
|
|
61
|
+
declare const $toSnakeCase: unique symbol;
|
|
62
|
+
export declare abstract class EnvLoader {
|
|
63
|
+
private [$secretsCache];
|
|
64
|
+
private [$secretSubjects];
|
|
65
|
+
private [$options];
|
|
66
|
+
private [$watchers];
|
|
67
|
+
private [$watchersStarted];
|
|
68
|
+
constructor(options?: EnvLoaderOptions);
|
|
69
|
+
/**
|
|
70
|
+
* Initialize the loader: read secrets.
|
|
71
|
+
* This must be called after the constructor.
|
|
72
|
+
*/
|
|
73
|
+
init(): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Loads a secret from the environment asynchronously.
|
|
76
|
+
*/
|
|
77
|
+
getSecret(key: string): Promise<string | undefined>;
|
|
78
|
+
getSecret(key: string, observer: true): Promise<EmitterSubject<string | undefined>>;
|
|
79
|
+
/**
|
|
80
|
+
* Loads a secret from the environment synchronously.
|
|
81
|
+
*/
|
|
82
|
+
getSecretSync(key: string): string | undefined;
|
|
83
|
+
getSecretSync(key: string, observer: true): EmitterSubject<string | undefined>;
|
|
84
|
+
/**
|
|
85
|
+
* Loads a variable from the environment synchronously.
|
|
86
|
+
*/
|
|
87
|
+
getVar(key: string): string | undefined;
|
|
88
|
+
getVar(key: string, observer: true): EmitterSubject<string | undefined>;
|
|
89
|
+
private [$getSecretValueInternal];
|
|
90
|
+
private [$getOrCreateSubject];
|
|
91
|
+
private [$loadSecrets];
|
|
92
|
+
private [$setupWatchers];
|
|
93
|
+
private [$updateSubject];
|
|
94
|
+
private [$updateMappedProperty];
|
|
95
|
+
private [$mapProperties];
|
|
96
|
+
private [$assignProperty];
|
|
97
|
+
private [$toSnakeCase];
|
|
98
|
+
}
|
|
99
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface JsonRpcRequest {
|
|
2
|
+
jsonrpc: "2.0";
|
|
3
|
+
id?: string | number | null;
|
|
4
|
+
method: string;
|
|
5
|
+
params?: any;
|
|
6
|
+
}
|
|
7
|
+
export interface JsonRpcResponse {
|
|
8
|
+
jsonrpc: "2.0";
|
|
9
|
+
id: string | number | null;
|
|
10
|
+
result?: any;
|
|
11
|
+
error?: {
|
|
12
|
+
code: number;
|
|
13
|
+
message: string;
|
|
14
|
+
data?: any;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export interface McpTool {
|
|
18
|
+
name: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
inputSchema?: any;
|
|
21
|
+
handler: (args: any) => Promise<any> | any;
|
|
22
|
+
}
|
|
23
|
+
export interface McpPrompt {
|
|
24
|
+
name: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
arguments?: {
|
|
27
|
+
name: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
required?: boolean;
|
|
30
|
+
}[];
|
|
31
|
+
handler: (args: any) => Promise<any> | any;
|
|
32
|
+
}
|
|
33
|
+
export interface McpResource {
|
|
34
|
+
uri: string;
|
|
35
|
+
name?: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
mimeType?: string;
|
|
38
|
+
handler: (uri: string, args?: any) => Promise<any> | any;
|
|
39
|
+
}
|
|
40
|
+
export declare class McpProtocol {
|
|
41
|
+
private tools;
|
|
42
|
+
private prompts;
|
|
43
|
+
private resources;
|
|
44
|
+
constructor(tools?: McpTool[], prompts?: McpPrompt[], resources?: McpResource[]);
|
|
45
|
+
addTool(tool: McpTool): void;
|
|
46
|
+
addPrompt(prompt: McpPrompt): void;
|
|
47
|
+
addResource(resource: McpResource): void;
|
|
48
|
+
merge(other: McpProtocol): void;
|
|
49
|
+
handleMessage(message: JsonRpcRequest): Promise<JsonRpcResponse | null>;
|
|
50
|
+
private success;
|
|
51
|
+
private error;
|
|
52
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight Polyfill for Reflect Metadata API.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the need for 'reflect-metadata' package to reduce bundle size
|
|
5
|
+
* while maintaining compatibility with TypeScript's emitDecoratorMetadata.
|
|
6
|
+
*/
|
|
7
|
+
export declare function defineMetadata(key: string | symbol, value: any, target: any, propertyKey?: string | symbol): void;
|
|
8
|
+
export declare function getMetadata(key: string | symbol, target: any, propertyKey?: string | symbol): any;
|
|
9
|
+
declare global {
|
|
10
|
+
namespace Reflect {
|
|
11
|
+
function defineMetadata(metadataKey: any, metadataValue: any, target: Object, propertyKey?: string | symbol): void;
|
|
12
|
+
function getMetadata(metadataKey: any, target: Object, propertyKey?: string | symbol): any;
|
|
13
|
+
function metadata(metadataKey: any, metadataValue: any): {
|
|
14
|
+
(target: Function): void;
|
|
15
|
+
(target: Object, propertyKey: string | symbol): void;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RequestContextStore } from './async-hooks';
|
|
2
|
+
export declare const kContext: unique symbol;
|
|
3
|
+
export interface PatchedPromise extends Promise<any> {
|
|
4
|
+
[kContext]?: {
|
|
5
|
+
store?: RequestContextStore;
|
|
6
|
+
stack: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Monkeypatches the global Promise constructor to attach the current AsyncLocalStorage store
|
|
11
|
+
* and a snapshot of the stack trace to every new Promise instance.
|
|
12
|
+
*
|
|
13
|
+
* This enables the application to trace unhandled rejections back to the original request
|
|
14
|
+
* and see where the dangling promise was created.
|
|
15
|
+
*/
|
|
16
|
+
export declare function enablePromisePatch(): void;
|
package/dist/util/request.d.ts
CHANGED
package/dist/util/symbol.d.ts
CHANGED
|
@@ -29,6 +29,11 @@ export declare const $cachedProtocol: unique symbol;
|
|
|
29
29
|
export declare const $cachedHost: unique symbol;
|
|
30
30
|
export declare const $cachedOrigin: unique symbol;
|
|
31
31
|
export declare const $cachedQuery: unique symbol;
|
|
32
|
+
export declare const $cachedCookies: unique symbol;
|
|
32
33
|
export declare const $ws: unique symbol;
|
|
33
34
|
export declare const $socket: unique symbol;
|
|
34
35
|
export declare const $io: unique symbol;
|
|
36
|
+
export declare const $mcpTools: unique symbol;
|
|
37
|
+
export declare const $mcpPrompts: unique symbol;
|
|
38
|
+
export declare const $mcpResources: unique symbol;
|
|
39
|
+
export declare const $resilienceConfig: unique symbol;
|
package/dist/util/types.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { Server } from 'bun';
|
|
|
3
3
|
import { Server as NodeServer } from 'node:http';
|
|
4
4
|
import { ConnectOptions, Engines } from 'surrealdb';
|
|
5
5
|
import { ShokupanContext } from '../context';
|
|
6
|
+
import { ServerAdapter } from './adapter';
|
|
7
|
+
import { FileSystemAdapter } from './adapter/filesystem';
|
|
6
8
|
import { $isRouter } from './symbol';
|
|
7
9
|
export type HeadersInit = Headers | Record<string, string> | [string, string][];
|
|
8
10
|
export interface ShokupanPluginOptions {
|
|
@@ -118,6 +120,112 @@ export interface CookieOptions {
|
|
|
118
120
|
sameSite?: boolean | 'lax' | 'strict' | 'none' | 'Lax' | 'Strict' | 'None';
|
|
119
121
|
priority?: 'low' | 'medium' | 'high' | 'Low' | 'Medium' | 'High';
|
|
120
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Helper interface for generic streaming operations.
|
|
125
|
+
* Provides methods to write data, pipe streams, and handle abort events.
|
|
126
|
+
*/
|
|
127
|
+
export interface StreamHelper {
|
|
128
|
+
/**
|
|
129
|
+
* Write data to the stream.
|
|
130
|
+
* @param data Data to write (Uint8Array or string, strings are auto-encoded to UTF-8)
|
|
131
|
+
*/
|
|
132
|
+
write(data: Uint8Array | string): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Pipe a ReadableStream to this stream.
|
|
135
|
+
* @param stream ReadableStream to pipe
|
|
136
|
+
*/
|
|
137
|
+
pipe(stream: ReadableStream): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Sleep for a specified duration.
|
|
140
|
+
* @param ms Milliseconds to sleep
|
|
141
|
+
*/
|
|
142
|
+
sleep(ms: number): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Register a callback to be executed when the stream is aborted.
|
|
145
|
+
* @param callback Callback function
|
|
146
|
+
*/
|
|
147
|
+
onAbort(callback: () => void): void;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Helper interface for text streaming operations.
|
|
151
|
+
* Provides methods to write text with or without newlines.
|
|
152
|
+
*/
|
|
153
|
+
export interface TextStreamHelper {
|
|
154
|
+
/**
|
|
155
|
+
* Write text to the stream without a newline.
|
|
156
|
+
* @param text Text to write
|
|
157
|
+
*/
|
|
158
|
+
write(text: string): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* Write text to the stream with a newline.
|
|
161
|
+
* @param text Text to write
|
|
162
|
+
*/
|
|
163
|
+
writeln(text: string): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Sleep for a specified duration.
|
|
166
|
+
* @param ms Milliseconds to sleep
|
|
167
|
+
*/
|
|
168
|
+
sleep(ms: number): Promise<void>;
|
|
169
|
+
/**
|
|
170
|
+
* Register a callback to be executed when the stream is aborted.
|
|
171
|
+
* @param callback Callback function
|
|
172
|
+
*/
|
|
173
|
+
onAbort(callback: () => void): void;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Helper interface for Server-Sent Events (SSE) streaming.
|
|
177
|
+
* Provides methods to write SSE-formatted messages.
|
|
178
|
+
*/
|
|
179
|
+
export interface SSEStreamHelper {
|
|
180
|
+
/**
|
|
181
|
+
* Write a Server-Sent Event message.
|
|
182
|
+
* @param message SSE message with data, event, id, and retry fields
|
|
183
|
+
*/
|
|
184
|
+
writeSSE(message: SSEMessage): Promise<void>;
|
|
185
|
+
/**
|
|
186
|
+
* Sleep for a specified duration.
|
|
187
|
+
* @param ms Milliseconds to sleep
|
|
188
|
+
*/
|
|
189
|
+
sleep(ms: number): Promise<void>;
|
|
190
|
+
/**
|
|
191
|
+
* Register a callback to be executed when the stream is aborted.
|
|
192
|
+
* @param callback Callback function
|
|
193
|
+
*/
|
|
194
|
+
onAbort(callback: () => void): void;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Server-Sent Event message format.
|
|
198
|
+
*/
|
|
199
|
+
export interface SSEMessage {
|
|
200
|
+
/**
|
|
201
|
+
* The data payload of the event.
|
|
202
|
+
*/
|
|
203
|
+
data: string;
|
|
204
|
+
/**
|
|
205
|
+
* Optional event type.
|
|
206
|
+
*/
|
|
207
|
+
event?: string;
|
|
208
|
+
/**
|
|
209
|
+
* Optional event ID.
|
|
210
|
+
*/
|
|
211
|
+
id?: string;
|
|
212
|
+
/**
|
|
213
|
+
* Optional reconnection time in milliseconds.
|
|
214
|
+
*/
|
|
215
|
+
retry?: number;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Error handler for stream operations.
|
|
219
|
+
*/
|
|
220
|
+
export type StreamErrorHandler = (err: Error, stream: StreamHelper) => void | Promise<void>;
|
|
221
|
+
/**
|
|
222
|
+
* Error handler for text stream operations.
|
|
223
|
+
*/
|
|
224
|
+
export type TextStreamErrorHandler = (err: Error, stream: TextStreamHelper) => void | Promise<void>;
|
|
225
|
+
/**
|
|
226
|
+
* Error handler for SSE stream operations.
|
|
227
|
+
*/
|
|
228
|
+
export type SSEStreamErrorHandler = (err: Error, stream: SSEStreamHelper) => void | Promise<void>;
|
|
121
229
|
export type ShokupanHandler<State extends Record<string, any> = Record<string, any>, Params extends Record<string, string> = Record<string, string>> = ((ctx: ShokupanContext<State, Params>, next?: NextFn) => Promise<any> | any) & {
|
|
122
230
|
originalHandler?: ShokupanHandler<State, Params>;
|
|
123
231
|
};
|
|
@@ -129,7 +237,8 @@ export declare enum RouteParamType {
|
|
|
129
237
|
QUERY = "QUERY",
|
|
130
238
|
HEADER = "HEADER",
|
|
131
239
|
REQUEST = "REQUEST",
|
|
132
|
-
CONTEXT = "CONTEXT"
|
|
240
|
+
CONTEXT = "CONTEXT",
|
|
241
|
+
SERVICE = "SERVICE"
|
|
133
242
|
}
|
|
134
243
|
export interface ServerFactory {
|
|
135
244
|
(options: any): Server<any> | Promise<Server<any>> | NodeServer | Promise<NodeServer>;
|
|
@@ -276,6 +385,14 @@ export type ShokupanConfig<T extends Record<string, any> = Record<string, any>>
|
|
|
276
385
|
* @default true
|
|
277
386
|
*/
|
|
278
387
|
enableOpenApiGen: boolean;
|
|
388
|
+
/**
|
|
389
|
+
* Whether to enable monkeypatching of the global Promise constructor.
|
|
390
|
+
* When enabled, Promises created within an async context will carry that context
|
|
391
|
+
* (including `requestId`) and the creation stack trace. This increases memory and
|
|
392
|
+
* cpu usage, but provides richer logging for unhandled rejections.
|
|
393
|
+
* @default false
|
|
394
|
+
*/
|
|
395
|
+
enablePromiseMonkeypatch: boolean;
|
|
279
396
|
/**
|
|
280
397
|
* Whether to block server startup until OpenAPI generation completes.
|
|
281
398
|
* Only applies when enableOpenApiGen is true.
|
|
@@ -310,6 +427,14 @@ export type ShokupanConfig<T extends Record<string, any> = Record<string, any>>
|
|
|
310
427
|
* @default false
|
|
311
428
|
*/
|
|
312
429
|
enableTracing?: boolean;
|
|
430
|
+
/**
|
|
431
|
+
* Query parser mode.
|
|
432
|
+
* - `extended`: Arrays for duplicate keys (default).
|
|
433
|
+
* - `simple`: First value only for duplicate keys.
|
|
434
|
+
* - `strict`: Throws 400 error on duplicate keys.
|
|
435
|
+
* @default 'extended'
|
|
436
|
+
*/
|
|
437
|
+
queryParserMode?: 'extended' | 'simple' | 'strict';
|
|
313
438
|
/**
|
|
314
439
|
* JSON parser to use for parsing request bodies.
|
|
315
440
|
*
|
|
@@ -407,6 +532,12 @@ export type ShokupanConfig<T extends Record<string, any> = Record<string, any>>
|
|
|
407
532
|
* @default 30000
|
|
408
533
|
*/
|
|
409
534
|
readTimeout: number;
|
|
535
|
+
/**
|
|
536
|
+
* Maximum allowed request body size in bytes.
|
|
537
|
+
* Requests larger than this will be rejected with 413 Payload Too Large.
|
|
538
|
+
* @default 10485760 (10MB)
|
|
539
|
+
*/
|
|
540
|
+
maxBodySize?: number;
|
|
410
541
|
/**
|
|
411
542
|
* Timeout for processing the request (milliseconds).
|
|
412
543
|
* Maps to `server.timeout(req, seconds)`.
|
|
@@ -433,11 +564,11 @@ export type ShokupanConfig<T extends Record<string, any> = Record<string, any>>
|
|
|
433
564
|
* The server adapter to use.
|
|
434
565
|
* overrides `serverFactory`.
|
|
435
566
|
*/
|
|
436
|
-
adapter?: 'bun' | 'node' | 'wintercg' |
|
|
567
|
+
adapter?: 'bun' | 'node' | 'wintercg' | ServerAdapter;
|
|
437
568
|
/**
|
|
438
569
|
* The file system adapter to use for `ctx.file`.
|
|
439
570
|
*/
|
|
440
|
-
fileSystem?:
|
|
571
|
+
fileSystem?: FileSystemAdapter;
|
|
441
572
|
/**
|
|
442
573
|
* Lifecycle hooks.
|
|
443
574
|
*/
|
|
@@ -509,6 +640,12 @@ export type ShokupanConfig<T extends Record<string, any> = Record<string, any>>
|
|
|
509
640
|
spec_url: string;
|
|
510
641
|
}>;
|
|
511
642
|
};
|
|
643
|
+
/**
|
|
644
|
+
* Configuration for Security Headers.
|
|
645
|
+
* Can be a boolean to enable/disable defaults, or an object options.
|
|
646
|
+
* @default false
|
|
647
|
+
*/
|
|
648
|
+
defaultSecurityHeaders?: boolean | any;
|
|
512
649
|
/**
|
|
513
650
|
* Any other config options are allowed, but will be ignored.
|
|
514
651
|
* @deprecated
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shokupan",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Shokupan is a low-lift modern web framework for Bun.",
|
|
5
5
|
"author": "Andrew G. Knackstedt",
|
|
6
6
|
"publishConfig": {
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"type": "module",
|
|
24
24
|
"scripts": {
|
|
25
25
|
"dev": "bun --watch --inspect examples/full/main.ts",
|
|
26
|
+
"mcp:inspector": "npx @modelcontextprotocol/inspector http://localhost:8372/mcp",
|
|
26
27
|
"debug:otel": "sh scripts/debug-otel.sh",
|
|
27
28
|
"docs": "cd docs && bun run dev",
|
|
28
29
|
"build": "vite build",
|
|
@@ -58,21 +59,16 @@
|
|
|
58
59
|
},
|
|
59
60
|
"dependencies": {
|
|
60
61
|
"@clack/prompts": "^0.11.0",
|
|
61
|
-
"
|
|
62
|
-
"@opentelemetry/exporter-trace-otlp-proto": "^0.208.0",
|
|
63
|
-
"@opentelemetry/resources": "^2.3.0",
|
|
64
|
-
"@opentelemetry/sdk-trace-base": "^2.3.0",
|
|
65
|
-
"@opentelemetry/sdk-trace-node": "^2.3.0",
|
|
66
|
-
"@opentelemetry/semantic-conventions": "^1.38.0",
|
|
67
|
-
"@scalar/openapi-types": "^0.5.3",
|
|
68
|
-
"js-yaml": "^4.1.1",
|
|
62
|
+
"cockatiel": "^3.2.1",
|
|
69
63
|
"nanoid": "^5.1.6",
|
|
70
|
-
"socket.io": "^4.8.3",
|
|
71
64
|
"tslib": "^2.8.1"
|
|
72
65
|
},
|
|
73
66
|
"peerDependencies": {
|
|
74
67
|
"@apollo/server": "^5.2.0",
|
|
68
|
+
"@modelcontextprotocol/sdk": "^1.25.2",
|
|
69
|
+
"@opentelemetry/api": "^1.9.0",
|
|
75
70
|
"@scalar/api-reference": "^1.0.0",
|
|
71
|
+
"@scalar/openapi-types": "^0.5.3",
|
|
76
72
|
"@surrealdb/node": "^2.4.0",
|
|
77
73
|
"ajv": "^8.0.0",
|
|
78
74
|
"ajv-formats": "^3.0.0",
|
|
@@ -83,9 +79,11 @@
|
|
|
83
79
|
"graphql": "^16.12.0",
|
|
84
80
|
"graphql-yoga": "^5.18.0",
|
|
85
81
|
"jose": "^6.0.0",
|
|
82
|
+
"js-yaml": "^4.1.1",
|
|
86
83
|
"parse-json": "^8.0.0",
|
|
87
84
|
"reflect-metadata": "^0.2.0",
|
|
88
85
|
"secure-json-parse": "^4.0.0",
|
|
86
|
+
"socket.io": "^4.8.3",
|
|
89
87
|
"surrealdb": "^2.0.0-alpha.16"
|
|
90
88
|
},
|
|
91
89
|
"peerDependenciesMeta": {
|
|
@@ -136,11 +134,38 @@
|
|
|
136
134
|
},
|
|
137
135
|
"surrealdb": {
|
|
138
136
|
"optional": true
|
|
137
|
+
},
|
|
138
|
+
"@modelcontextprotocol/sdk": {
|
|
139
|
+
"optional": true
|
|
140
|
+
},
|
|
141
|
+
"@opentelemetry/api": {
|
|
142
|
+
"optional": true
|
|
143
|
+
},
|
|
144
|
+
"@scalar/openapi-types": {
|
|
145
|
+
"optional": true
|
|
146
|
+
},
|
|
147
|
+
"js-yaml": {
|
|
148
|
+
"optional": true
|
|
149
|
+
},
|
|
150
|
+
"socket.io": {
|
|
151
|
+
"optional": true
|
|
152
|
+
},
|
|
153
|
+
"youch": {
|
|
154
|
+
"optional": true
|
|
139
155
|
}
|
|
140
156
|
},
|
|
141
157
|
"devDependencies": {
|
|
142
158
|
"@apollo/server": "^5.2.0",
|
|
159
|
+
"@modelcontextprotocol/sdk": "^1.25.2",
|
|
160
|
+
"@opentelemetry/api": "^1.9.0",
|
|
161
|
+
"@opentelemetry/exporter-trace-otlp-proto": "^0.208.0",
|
|
162
|
+
"@opentelemetry/resources": "^2.3.0",
|
|
163
|
+
"@opentelemetry/sdk-trace-base": "^2.3.0",
|
|
164
|
+
"@opentelemetry/sdk-trace-node": "^2.3.0",
|
|
165
|
+
"@opentelemetry/semantic-conventions": "^1.38.0",
|
|
143
166
|
"@scalar/api-reference": "^1.0.0",
|
|
167
|
+
"@scalar/openapi-types": "^0.5.3",
|
|
168
|
+
"@sentry/node": "^10.36.0",
|
|
144
169
|
"@sinclair/typebox": "^0.34.47",
|
|
145
170
|
"@surrealdb/node": "^2.4.0",
|
|
146
171
|
"@tsconfig/bun": "^1.0.10",
|
|
@@ -161,11 +186,13 @@
|
|
|
161
186
|
"graphql": "^16.12.0",
|
|
162
187
|
"graphql-yoga": "^5.18.0",
|
|
163
188
|
"jose": "^6.0.0",
|
|
189
|
+
"js-yaml": "^4.1.1",
|
|
164
190
|
"parse-json": "^8.0.0",
|
|
165
191
|
"preact": "^10.28.2",
|
|
166
192
|
"preact-render-to-string": "^6.6.5",
|
|
167
193
|
"reflect-metadata": "^0.2.0",
|
|
168
194
|
"secure-json-parse": "^4.0.0",
|
|
195
|
+
"socket.io": "^4.8.3",
|
|
169
196
|
"supertest": "^7.2.2",
|
|
170
197
|
"surrealdb": "^2.0.0-alpha.14",
|
|
171
198
|
"typescript": "~5.9.3",
|