weifuwu 0.30.1 → 0.30.2
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 +115 -203
- package/dist/core/router.d.ts +21 -58
- package/dist/core/serve.d.ts +0 -4
- package/dist/core/ws.d.ts +28 -0
- package/dist/index.d.ts +2 -24
- package/dist/index.js +396 -1880
- package/dist/queue/index.d.ts +10 -0
- package/dist/queue/types.d.ts +5 -9
- package/package.json +4 -5
- package/dist/core/cookie.d.ts +0 -36
- package/dist/core/env.d.ts +0 -69
- package/dist/core/html.d.ts +0 -34
- package/dist/core/sse.d.ts +0 -47
- package/dist/middleware/csrf.d.ts +0 -31
- package/dist/middleware/flash.d.ts +0 -44
- package/dist/middleware/health.d.ts +0 -24
- package/dist/middleware/i18n.d.ts +0 -39
- package/dist/middleware/request-id.d.ts +0 -40
- package/dist/middleware/theme.d.ts +0 -31
- package/dist/middleware/validate.d.ts +0 -32
- package/dist/test/test-utils.d.ts +0 -193
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import type { Context, Handler, SqlClient } from '../types.ts';
|
|
2
|
-
import { Router } from '../core/router.ts';
|
|
3
|
-
import { WebSocket as WSWebSocket } from 'ws';
|
|
4
|
-
export interface TestResponse {
|
|
5
|
-
readonly status: number;
|
|
6
|
-
readonly headers: Headers;
|
|
7
|
-
json<T = unknown>(): Promise<T>;
|
|
8
|
-
text(): Promise<string>;
|
|
9
|
-
}
|
|
10
|
-
export declare class TestRequest {
|
|
11
|
-
private headers;
|
|
12
|
-
private ctxMixin;
|
|
13
|
-
private bodyData;
|
|
14
|
-
private app;
|
|
15
|
-
private method;
|
|
16
|
-
private path;
|
|
17
|
-
constructor(app: TestApp, method: string, path: string);
|
|
18
|
-
/** Set a request header */
|
|
19
|
-
header(name: string, value: string): this;
|
|
20
|
-
/** Mix properties into ctx (simulating middleware injection) */
|
|
21
|
-
with(mixin: Partial<Context>): this;
|
|
22
|
-
/** Shortcut: set ctx.user */
|
|
23
|
-
withUser(user: unknown): this;
|
|
24
|
-
/** Shortcut: set ctx.tenant */
|
|
25
|
-
withTenant(tenant: {
|
|
26
|
-
id: string;
|
|
27
|
-
name: string;
|
|
28
|
-
role: string;
|
|
29
|
-
}): this;
|
|
30
|
-
/** Set JSON request body */
|
|
31
|
-
body(data: unknown): this;
|
|
32
|
-
/** Set raw text body */
|
|
33
|
-
rawBody(data: string): this;
|
|
34
|
-
/** Send the request and return the response */
|
|
35
|
-
send(): Promise<TestResponse>;
|
|
36
|
-
}
|
|
37
|
-
export declare class TestApp {
|
|
38
|
-
private router;
|
|
39
|
-
private wsServer;
|
|
40
|
-
private wsConnections;
|
|
41
|
-
constructor();
|
|
42
|
-
/**
|
|
43
|
-
* Register a WebSocket handler.
|
|
44
|
-
*/
|
|
45
|
-
ws(path: string, handler: import('../core/router.ts').WebSocketHandler): this;
|
|
46
|
-
/** Get the raw Router (for advanced use). */
|
|
47
|
-
get _router(): Router;
|
|
48
|
-
/** Add global middleware */
|
|
49
|
-
use(mw: any): this;
|
|
50
|
-
/** Register a GET route — supports route-level middleware via spread args. */
|
|
51
|
-
get(path: string, ...args: any[]): this;
|
|
52
|
-
/** Register a POST route. */
|
|
53
|
-
post(path: string, ...args: any[]): this;
|
|
54
|
-
/** Register a PUT route. */
|
|
55
|
-
put(path: string, ...args: any[]): this;
|
|
56
|
-
/** Register a PATCH route. */
|
|
57
|
-
patch(path: string, ...args: any[]): this;
|
|
58
|
-
/** Register a DELETE route. */
|
|
59
|
-
delete(path: string, ...args: any[]): this;
|
|
60
|
-
/** Start building a GET request */
|
|
61
|
-
getReq(path: string): TestRequest;
|
|
62
|
-
/** Start building a POST request */
|
|
63
|
-
postReq(path: string): TestRequest;
|
|
64
|
-
/** Start building a PUT request */
|
|
65
|
-
putReq(path: string): TestRequest;
|
|
66
|
-
/** Start building a PATCH request */
|
|
67
|
-
patchReq(path: string): TestRequest;
|
|
68
|
-
/** Start building a DELETE request */
|
|
69
|
-
deleteReq(path: string): TestRequest;
|
|
70
|
-
/** Get the underlying handler (for advanced usage) */
|
|
71
|
-
handler(): Handler;
|
|
72
|
-
/** Start building a WebSocket connection to the given path. */
|
|
73
|
-
wsReq(path: string): TestWSRequest;
|
|
74
|
-
/**
|
|
75
|
-
* Internal: ensure HTTP server is running for WebSocket connections.
|
|
76
|
-
* Starts on a random port.
|
|
77
|
-
*/
|
|
78
|
-
_ensureServer(): Promise<string>;
|
|
79
|
-
/**
|
|
80
|
-
* Internal: register a WS connection for cleanup.
|
|
81
|
-
*/
|
|
82
|
-
_trackConnection(conn: TestWSConnection): void;
|
|
83
|
-
/**
|
|
84
|
-
* Cleanup all WebSocket connections and stop the server.
|
|
85
|
-
*/
|
|
86
|
-
close(): Promise<void>;
|
|
87
|
-
}
|
|
88
|
-
/** Start building a WebSocket test connection. */
|
|
89
|
-
export declare class TestWSRequest {
|
|
90
|
-
private app;
|
|
91
|
-
private path;
|
|
92
|
-
private _timeout;
|
|
93
|
-
constructor(app: TestApp, path: string);
|
|
94
|
-
/** Set the timeout for operations (default: 5000ms). */
|
|
95
|
-
timeout(ms: number): this;
|
|
96
|
-
/**
|
|
97
|
-
* Connect to the WebSocket endpoint.
|
|
98
|
-
* Starts a real HTTP server (random port) if not already running.
|
|
99
|
-
*/
|
|
100
|
-
connect(): Promise<TestWSConnection>;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* A connected WebSocket for testing.
|
|
104
|
-
*
|
|
105
|
-
* ```ts
|
|
106
|
-
* const conn = await app.wsReq('/echo').connect()
|
|
107
|
-
* conn.send('hello')
|
|
108
|
-
* const msg = await conn.receive()
|
|
109
|
-
* assert.equal(msg, 'hello')
|
|
110
|
-
* conn.close()
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
113
|
-
export declare class TestWSConnection {
|
|
114
|
-
private ws;
|
|
115
|
-
private _timeout;
|
|
116
|
-
private messageQueue;
|
|
117
|
-
private resolveQueue;
|
|
118
|
-
private _closed;
|
|
119
|
-
constructor(ws: WSWebSocket, timeout?: number);
|
|
120
|
-
/** Send a text message. */
|
|
121
|
-
send(data: string): void;
|
|
122
|
-
/** Send a JSON message. */
|
|
123
|
-
json(data: unknown): void;
|
|
124
|
-
/**
|
|
125
|
-
* Wait for the next message. Returns the raw text.
|
|
126
|
-
* Throws on timeout or if the connection is closed.
|
|
127
|
-
*/
|
|
128
|
-
receive(timeout?: number): Promise<string>;
|
|
129
|
-
/** Wait for the next message and parse as JSON. */
|
|
130
|
-
receiveJson<T = unknown>(): Promise<T>;
|
|
131
|
-
/**
|
|
132
|
-
* Assert that no message is received within the given silence period.
|
|
133
|
-
* Useful for verifying that something did NOT happen.
|
|
134
|
-
*/
|
|
135
|
-
expectSilent(ms: number): Promise<void>;
|
|
136
|
-
/** Close the connection. */
|
|
137
|
-
close(): void;
|
|
138
|
-
/** Whether the connection is closed. */
|
|
139
|
-
get closed(): boolean;
|
|
140
|
-
}
|
|
141
|
-
/** Create a new test app */
|
|
142
|
-
export declare function testApp(): TestApp;
|
|
143
|
-
/**
|
|
144
|
-
* Result of createTestDb().
|
|
145
|
-
*/
|
|
146
|
-
export interface TestDb {
|
|
147
|
-
/** Tagged-template SQL client connected to the test database. */
|
|
148
|
-
sql: SqlClient;
|
|
149
|
-
/** Connection URL of the test database. */
|
|
150
|
-
url: string;
|
|
151
|
-
/** Schema name used for this test session. */
|
|
152
|
-
schema: string;
|
|
153
|
-
/** Destroy the test database (drop schema). */
|
|
154
|
-
destroy: () => Promise<void>;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Create an isolated test database schema for integration testing.
|
|
158
|
-
*
|
|
159
|
-
* Uses PostgreSQL schemas for isolation — no separate database needed.
|
|
160
|
-
* Each call creates a unique schema under the same database.
|
|
161
|
-
*
|
|
162
|
-
* ```ts
|
|
163
|
-
* const db = await createTestDb()
|
|
164
|
-
* await db.sql`CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT)`
|
|
165
|
-
* // ... run tests ...
|
|
166
|
-
* await db.destroy() // drops the schema
|
|
167
|
-
* ```
|
|
168
|
-
*
|
|
169
|
-
* Uses `TEST_DATABASE_URL` or `DATABASE_URL` env var.
|
|
170
|
-
*/
|
|
171
|
-
export declare function createTestDb(options?: {
|
|
172
|
-
/** Database URL. Default: TEST_DATABASE_URL or DATABASE_URL. */
|
|
173
|
-
url?: string;
|
|
174
|
-
/** Schema name. Default: auto-generated 'test_<timestamp>_<random>'. */
|
|
175
|
-
schema?: string;
|
|
176
|
-
}): Promise<TestDb>;
|
|
177
|
-
/**
|
|
178
|
-
* Run a test callback within an isolated transaction that is rolled back
|
|
179
|
-
* after completion. This provides the fastest isolation — no cleanup needed.
|
|
180
|
-
*
|
|
181
|
-
* ```ts
|
|
182
|
-
* await withTestDb(async (sql) => {
|
|
183
|
-
* await sql`INSERT INTO users ...`
|
|
184
|
-
* // All changes are rolled back after this callback returns
|
|
185
|
-
* })
|
|
186
|
-
* ```
|
|
187
|
-
*
|
|
188
|
-
* @param optionsOrFn Either a URL string or options object, or the callback directly.
|
|
189
|
-
* @param fn Async callback receiving a tagged-template sql client.
|
|
190
|
-
*/
|
|
191
|
-
export declare function withTestDb(optionsOrFn: string | {
|
|
192
|
-
url?: string;
|
|
193
|
-
} | ((sql: SqlClient) => Promise<void>), fn?: (sql: SqlClient) => Promise<void>): Promise<void>;
|