@stacksjs/bun-router 0.0.2 → 0.0.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/dist/{chunk-r15a48wc.js → chunk-cjdekj87.js} +536 -98
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +454 -119
- package/package.json +6 -8
- package/dist/auth.d.ts +0 -77
- package/dist/cache/lru-cache.d.ts +0 -88
- package/dist/cache/middleware-memoization.d.ts +0 -101
- package/dist/cache/route-cache-warmer.d.ts +0 -125
- package/dist/cache/sqlite-cache.d.ts +0 -114
- package/dist/cache/streaming-cache.d.ts +0 -86
- package/dist/cli/colors.d.ts +0 -12
- package/dist/cli/index.d.ts +0 -10
- package/dist/cli/middleware.d.ts +0 -31
- package/dist/cli/openapi.d.ts +0 -17
- package/dist/cli/router.d.ts +0 -15
- package/dist/cli/routes.d.ts +0 -30
- package/dist/cli/utils.d.ts +0 -68
- package/dist/config.d.ts +0 -274
- package/dist/container/container.d.ts +0 -141
- package/dist/container/contextual-binding.d.ts +0 -112
- package/dist/container/decorators.d.ts +0 -114
- package/dist/container/service-provider.d.ts +0 -221
- package/dist/development/hot-reload.d.ts +0 -129
- package/dist/development/index.d.ts +0 -144
- package/dist/development/performance-profiler.d.ts +0 -152
- package/dist/development/route-debugger.d.ts +0 -102
- package/dist/development/route-inspector.d.ts +0 -142
- package/dist/development/typescript-utilities.d.ts +0 -116
- package/dist/docs.d.ts +0 -10
- package/dist/errors/circuit-breaker.d.ts +0 -138
- package/dist/errors/error-handler.d.ts +0 -57
- package/dist/errors/error-reporting.d.ts +0 -135
- package/dist/errors/exceptions.d.ts +0 -178
- package/dist/errors/graceful-degradation.d.ts +0 -130
- package/dist/errors/index.d.ts +0 -6
- package/dist/errors/router-errors.d.ts +0 -97
- package/dist/file-serving/static-files.d.ts +0 -98
- package/dist/middleware/auth.d.ts +0 -34
- package/dist/middleware/content_security_policy.d.ts +0 -54
- package/dist/middleware/cors.d.ts +0 -5
- package/dist/middleware/csrf.d.ts +0 -7
- package/dist/middleware/ddos_protection.d.ts +0 -47
- package/dist/middleware/file_security.d.ts +0 -23
- package/dist/middleware/file_upload.d.ts +0 -41
- package/dist/middleware/helmet.d.ts +0 -54
- package/dist/middleware/index.d.ts +0 -55
- package/dist/middleware/input_validation.d.ts +0 -46
- package/dist/middleware/json_body.d.ts +0 -4
- package/dist/middleware/performance_alerting.d.ts +0 -88
- package/dist/middleware/performance_dashboard.d.ts +0 -97
- package/dist/middleware/performance_monitor.d.ts +0 -236
- package/dist/middleware/pipeline.d.ts +0 -90
- package/dist/middleware/rate_limit.d.ts +0 -33
- package/dist/middleware/request_id.d.ts +0 -4
- package/dist/middleware/request_signing.d.ts +0 -96
- package/dist/middleware/request_tracer.d.ts +0 -76
- package/dist/middleware/response_cache.d.ts +0 -90
- package/dist/middleware/security.d.ts +0 -70
- package/dist/middleware/security_suite.d.ts +0 -46
- package/dist/middleware/session.d.ts +0 -7
- package/dist/model-binding/index.d.ts +0 -17
- package/dist/model-binding/model-middleware.d.ts +0 -80
- package/dist/model-binding/model-registry.d.ts +0 -125
- package/dist/model-binding.d.ts +0 -123
- package/dist/model-resolver-factory.d.ts +0 -31
- package/dist/observability/correlation.d.ts +0 -131
- package/dist/observability/health-checks.d.ts +0 -129
- package/dist/observability/index.d.ts +0 -92
- package/dist/observability/integration.d.ts +0 -112
- package/dist/observability/metrics.d.ts +0 -135
- package/dist/observability/tracing.d.ts +0 -112
- package/dist/optimization/bun-utilities.d.ts +0 -106
- package/dist/query-builder-integration.d.ts +0 -24
- package/dist/request/enhanced-request.d.ts +0 -143
- package/dist/request/macros.d.ts +0 -267
- package/dist/response/macros.d.ts +0 -207
- package/dist/response/response-factory.d.ts +0 -93
- package/dist/router/file-based-routing.d.ts +0 -40
- package/dist/router/file-streaming.d.ts +0 -6
- package/dist/router/fluent-router.d.ts +0 -179
- package/dist/router/fluent-routing.d.ts +0 -198
- package/dist/router/group-organization.d.ts +0 -5
- package/dist/router/handler-resolver.d.ts +0 -13
- package/dist/router/http-methods.d.ts +0 -10
- package/dist/router/index.d.ts +0 -114
- package/dist/router/middleware-integration.d.ts +0 -86
- package/dist/router/middleware.d.ts +0 -5
- package/dist/router/model-binding.d.ts +0 -7
- package/dist/router/optimized-route-matching.d.ts +0 -6
- package/dist/router/route-building.d.ts +0 -5
- package/dist/router/route-compiler.d.ts +0 -67
- package/dist/router/route-matching.d.ts +0 -5
- package/dist/router/route-trie.d.ts +0 -69
- package/dist/router/router.d.ts +0 -133
- package/dist/router/server.d.ts +0 -5
- package/dist/router/validation-integration.d.ts +0 -116
- package/dist/router/view-rendering.d.ts +0 -5
- package/dist/router/websocket.d.ts +0 -5
- package/dist/routing/route-caching.d.ts +0 -105
- package/dist/routing/route-throttling.d.ts +0 -112
- package/dist/routing/subdomain-routing.d.ts +0 -159
- package/dist/streaming/index.d.ts +0 -15
- package/dist/streaming/sse-handler.d.ts +0 -81
- package/dist/streaming/stream-handler.d.ts +0 -81
- package/dist/testing/auth-testing.d.ts +0 -107
- package/dist/testing/file-upload-testing.d.ts +0 -139
- package/dist/testing/index.d.ts +0 -10
- package/dist/testing/middleware-testing.d.ts +0 -99
- package/dist/testing/model-binding-testing.d.ts +0 -132
- package/dist/testing/performance-testing.d.ts +0 -202
- package/dist/testing/test-client.d.ts +0 -58
- package/dist/testing/test-request.d.ts +0 -43
- package/dist/testing/test-response.d.ts +0 -45
- package/dist/testing/types.d.ts +0 -206
- package/dist/testing/websocket-testing.d.ts +0 -170
- package/dist/types/controller-types.d.ts +0 -303
- package/dist/types/core.d.ts +0 -526
- package/dist/types/middleware-types.d.ts +0 -315
- package/dist/types/request-response-augmentation.d.ts +0 -373
- package/dist/types/route-inference.d.ts +0 -287
- package/dist/types.d.ts +0 -1620
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/query-preservation.d.ts +0 -31
- package/dist/utils.d.ts +0 -69
- package/dist/validation/validator.d.ts +0 -169
- package/dist/websocket/clustering.d.ts +0 -114
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import type { EnhancedRequest } from '../types';
|
|
2
|
-
import type { ModelBindingTestOptions } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Factory functions
|
|
5
|
-
*/
|
|
6
|
-
export declare function createModelBindingTester(options?: ModelBindingTestOptions): ModelBindingTester;
|
|
7
|
-
export declare function createModelResolverTester(): ModelResolverTester;
|
|
8
|
-
/**
|
|
9
|
-
* Mock model factories
|
|
10
|
-
*/
|
|
11
|
-
export declare const modelMocks: {
|
|
12
|
-
/**
|
|
13
|
-
* Create a mock model class
|
|
14
|
-
*/
|
|
15
|
-
createModel: (name: string, attributes: Record<string, any> = {}) => any;
|
|
16
|
-
/**
|
|
17
|
-
* Create a User model mock
|
|
18
|
-
*/
|
|
19
|
-
User: () => unknown;
|
|
20
|
-
/**
|
|
21
|
-
* Create a Post model mock
|
|
22
|
-
*/
|
|
23
|
-
Post: () => unknown
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Model binding constraint helpers
|
|
27
|
-
*/
|
|
28
|
-
export declare const constraintHelpers: {
|
|
29
|
-
belongsTo: (userIdField?: string) => ModelConstraintFn
|
|
30
|
-
belongsToUser: () => ModelConstraintFn
|
|
31
|
-
published: () => SimpleModelConstraintFn
|
|
32
|
-
visible: () => SimpleModelConstraintFn
|
|
33
|
-
custom: (constraintFn: ModelConstraintFn) => ModelConstraintFn
|
|
34
|
-
combine: (...constraints: ModelConstraintFn[]) => ModelConstraintFn
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Route model binding test helpers
|
|
38
|
-
*/
|
|
39
|
-
export declare const routeModelHelpers: {
|
|
40
|
-
testRoute: (path: string, params: Record<string, string>, modelBindings: Record<string, any>) => Promise<EnhancedRequest>
|
|
41
|
-
createHandler: (expectedModels: string[]) => RouteHandlerFn
|
|
42
|
-
testBindingMiddleware: (bindings: Record<string, any>) => BindingMiddlewareFn
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Test utilities for scoped model binding
|
|
46
|
-
*/
|
|
47
|
-
export declare const scopedBindingHelpers: {
|
|
48
|
-
testUserScoped: (model: any, user: any, constraint?: UserScopeConstraint) => Promise<boolean>
|
|
49
|
-
testRoleAccess: (model: any, user: any, requiredRoles: string[]) => Promise<boolean>
|
|
50
|
-
testPermissionAccess: (model: any, user: any, requiredPermissions: string[]) => Promise<boolean>
|
|
51
|
-
};
|
|
52
|
-
/** Model constraint function type */
|
|
53
|
-
export type ModelConstraintFn = (model: any, request: EnhancedRequest) => Promise<boolean>
|
|
54
|
-
/** Simple model constraint function type (no request) */
|
|
55
|
-
export type SimpleModelConstraintFn = (model: any) => Promise<boolean>
|
|
56
|
-
/** Route handler function type */
|
|
57
|
-
export type RouteHandlerFn = (request: EnhancedRequest) => Promise<Response>
|
|
58
|
-
/** Binding middleware function type */
|
|
59
|
-
export type BindingMiddlewareFn = (request: EnhancedRequest, next: () => Promise<Response>) => Promise<Response>
|
|
60
|
-
/** User scope constraint function */
|
|
61
|
-
export type UserScopeConstraint = (model: any, user: any) => Promise<boolean>
|
|
62
|
-
/**
|
|
63
|
-
* Generic mock model base class for type annotations
|
|
64
|
-
*/
|
|
65
|
-
export declare class GenericMockModel {
|
|
66
|
-
id: any;
|
|
67
|
-
attributes: Record<string, any>;
|
|
68
|
-
constructor(data?: Record<string, any>);
|
|
69
|
-
static modelName: string;
|
|
70
|
-
static find(_id: any): Promise<GenericMockModel | null>;
|
|
71
|
-
static findOrFail(_id: any): Promise<GenericMockModel>;
|
|
72
|
-
static where(_conditions: Record<string, any>): Promise<GenericMockModel[]>;
|
|
73
|
-
static create(_data: Record<string, any>): Promise<GenericMockModel>;
|
|
74
|
-
save(): Promise<GenericMockModel>;
|
|
75
|
-
delete(): Promise<void>;
|
|
76
|
-
toJSON(): Record<string, any>;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Mock User class for type annotations
|
|
80
|
-
*/
|
|
81
|
-
export declare class MockUserClass {
|
|
82
|
-
id: number;
|
|
83
|
-
email: string;
|
|
84
|
-
name: string;
|
|
85
|
-
constructor(data?: { id: number, email?: string, name?: string });
|
|
86
|
-
static find(_id: any): Promise<MockUserClass | null>;
|
|
87
|
-
static findOrFail(_id: any): Promise<MockUserClass>;
|
|
88
|
-
toJSON(): Record<string, any>;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Mock Post class for type annotations
|
|
92
|
-
*/
|
|
93
|
-
export declare class MockPostClass {
|
|
94
|
-
id: number;
|
|
95
|
-
title: string;
|
|
96
|
-
content: string;
|
|
97
|
-
userId: number;
|
|
98
|
-
constructor(data?: { id: number, title?: string, content?: string, userId?: number });
|
|
99
|
-
static find(_id: any): Promise<MockPostClass | null>;
|
|
100
|
-
static findOrFail(_id: any): Promise<MockPostClass>;
|
|
101
|
-
belongsTo(_userId: number): Promise<boolean>;
|
|
102
|
-
toJSON(): Record<string, any>;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Model binding testing utilities
|
|
106
|
-
*/
|
|
107
|
-
export declare class ModelBindingTester {
|
|
108
|
-
private request: EnhancedRequest;
|
|
109
|
-
private options: ModelBindingTestOptions;
|
|
110
|
-
constructor(options?: ModelBindingTestOptions);
|
|
111
|
-
withRequest(request: EnhancedRequest): ModelBindingTester;
|
|
112
|
-
withParams(params: Record<string, string>): ModelBindingTester;
|
|
113
|
-
withModel(modelClass: any): ModelBindingTester;
|
|
114
|
-
withRouteKey(routeKey: string): ModelBindingTester;
|
|
115
|
-
withConstraints(constraints: Record<string, any>): ModelBindingTester;
|
|
116
|
-
withResolver(resolver: (value: string) => Promise<any>): ModelBindingTester;
|
|
117
|
-
testResolution(paramValue: string): Promise<any>;
|
|
118
|
-
testNotFound(paramValue: string): Promise<void>;
|
|
119
|
-
getRequest(): EnhancedRequest;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Model resolver factory for testing
|
|
123
|
-
*/
|
|
124
|
-
export declare class ModelResolverTester {
|
|
125
|
-
private resolvers: Map<string, (value: string) => Promise<any>>;
|
|
126
|
-
register(key: string, resolver: (value: string) => Promise<any>): ModelResolverTester;
|
|
127
|
-
registerModel(key: string, modelClass: any): ModelResolverTester;
|
|
128
|
-
resolve(key: string, value: string): Promise<any>;
|
|
129
|
-
testAll(testValue?: string): Promise<Record<string, any>>;
|
|
130
|
-
getKeys(): string[];
|
|
131
|
-
clear(): ModelResolverTester;
|
|
132
|
-
}
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import type { EnhancedRequest } from '../types';
|
|
2
|
-
import type { LoadTestConfig, PerformanceMetrics } from './types';
|
|
3
|
-
import type { TestClient } from './test-client';
|
|
4
|
-
/**
|
|
5
|
-
* Factory functions
|
|
6
|
-
*/
|
|
7
|
-
export declare function createPerformanceTester(): PerformanceTester;
|
|
8
|
-
export declare function createLoadTester(client: TestClient, config: LoadTestConfig): LoadTester;
|
|
9
|
-
/**
|
|
10
|
-
* Benchmark testing utilities
|
|
11
|
-
*/
|
|
12
|
-
export declare const benchmarkTests: {
|
|
13
|
-
routeHandler: (handler: (req: EnhancedRequest) => Promise<Response>, iterations?: number) => Promise<RouteHandlerBenchmarkResult>
|
|
14
|
-
middleware: (middleware: (req: EnhancedRequest, next: () => Promise<Response | null>) => Promise<Response | null>, iterations?: number) => Promise<MiddlewareBenchmarkResult>
|
|
15
|
-
jsonSerialization: (data: any, iterations?: number) => Promise<JsonBenchmarkResult>
|
|
16
|
-
routeMatching: (routes: Array<{ path: string, handler: any }>, testPaths: string[], iterations?: number) => Promise<RouteMatchingBenchmarkResult>
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Memory testing utilities
|
|
20
|
-
*/
|
|
21
|
-
export declare const memoryTests: {
|
|
22
|
-
measureMemoryUsage: <T>(fn: () => Promise<T> | T, iterations?: number) => Promise<MemoryUsageResult<T>>
|
|
23
|
-
testRouteHandlerMemoryLeaks: (handler: (req: EnhancedRequest) => Promise<Response>, iterations?: number) => Promise<RouteHandlerMemoryLeakResult>
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Stress testing utilities
|
|
27
|
-
*/
|
|
28
|
-
export declare const stressTests: {
|
|
29
|
-
rampUpTest: (client: TestClient, path: string, options: RampUpTestOptions) => Promise<RampUpTestResult[]>
|
|
30
|
-
spikeTest: (client: TestClient, path: string, options: SpikeTestOptions) => Promise<SpikeTestResult>
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Performance assertion helpers
|
|
34
|
-
*/
|
|
35
|
-
export declare const performanceAssertions: {
|
|
36
|
-
/**
|
|
37
|
-
* Assert response time is within acceptable range
|
|
38
|
-
*/
|
|
39
|
-
responseTimeWithin: (actualTime: number, maxTime: number) => any;
|
|
40
|
-
/**
|
|
41
|
-
* Assert throughput meets minimum requirements
|
|
42
|
-
*/
|
|
43
|
-
throughputAtLeast: (actualThroughput: number, minThroughput: number) => any;
|
|
44
|
-
/**
|
|
45
|
-
* Assert error rate is acceptable
|
|
46
|
-
*/
|
|
47
|
-
errorRateBelow: (errorRate: number, maxErrorRate: number) => any;
|
|
48
|
-
/**
|
|
49
|
-
* Assert memory usage is within limits
|
|
50
|
-
*/
|
|
51
|
-
memoryUsageWithin: (actualUsage: number, maxUsage: number) => any;
|
|
52
|
-
/**
|
|
53
|
-
* Assert no memory leaks detected
|
|
54
|
-
*/
|
|
55
|
-
noMemoryLeaks: (memoryGrowth: number, threshold: number?) => any
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Performance test utilities
|
|
59
|
-
*/
|
|
60
|
-
export declare const performanceUtils: {
|
|
61
|
-
/**
|
|
62
|
-
* Get current memory usage
|
|
63
|
-
*/
|
|
64
|
-
getCurrentMemoryUsage: () => any;
|
|
65
|
-
/**
|
|
66
|
-
* Get CPU usage
|
|
67
|
-
*/
|
|
68
|
-
getCPUUsage: () => any;
|
|
69
|
-
/**
|
|
70
|
-
* Create performance metric snapshot
|
|
71
|
-
*/
|
|
72
|
-
createMetricSnapshot: (responseTime: number) => any;
|
|
73
|
-
/**
|
|
74
|
-
* Format performance results for display
|
|
75
|
-
*/
|
|
76
|
-
formatResults: (results: any) => any
|
|
77
|
-
};
|
|
78
|
-
/** Route handler benchmark result */
|
|
79
|
-
export declare interface RouteHandlerBenchmarkResult {
|
|
80
|
-
averageTime: number
|
|
81
|
-
minTime: number
|
|
82
|
-
maxTime: number
|
|
83
|
-
totalTime: number
|
|
84
|
-
throughput: number
|
|
85
|
-
}
|
|
86
|
-
/** Middleware benchmark result */
|
|
87
|
-
export declare interface MiddlewareBenchmarkResult {
|
|
88
|
-
averageTime: number
|
|
89
|
-
minTime: number
|
|
90
|
-
maxTime: number
|
|
91
|
-
totalTime: number
|
|
92
|
-
}
|
|
93
|
-
/** JSON serialization benchmark result */
|
|
94
|
-
export declare interface JsonBenchmarkResult {
|
|
95
|
-
averageTime: number
|
|
96
|
-
minTime: number
|
|
97
|
-
maxTime: number
|
|
98
|
-
totalTime: number
|
|
99
|
-
dataSize: number
|
|
100
|
-
}
|
|
101
|
-
/** URL parsing benchmark result */
|
|
102
|
-
export declare interface UrlParsingBenchmarkResult {
|
|
103
|
-
averageTime: number
|
|
104
|
-
minTime: number
|
|
105
|
-
maxTime: number
|
|
106
|
-
totalTime: number
|
|
107
|
-
}
|
|
108
|
-
/** Memory test result */
|
|
109
|
-
export declare interface MemoryTestResult {
|
|
110
|
-
heapUsedBefore: number
|
|
111
|
-
heapUsedAfter: number
|
|
112
|
-
heapUsedDelta: number
|
|
113
|
-
rssBefore: number
|
|
114
|
-
rssAfter: number
|
|
115
|
-
rssDelta: number
|
|
116
|
-
}
|
|
117
|
-
/** Memory usage result */
|
|
118
|
-
export declare interface MemoryUsageResult<T> {
|
|
119
|
-
averageHeapUsed: number
|
|
120
|
-
maxHeapUsed: number
|
|
121
|
-
memoryLeakDetected: boolean
|
|
122
|
-
results: T[]
|
|
123
|
-
}
|
|
124
|
-
/** Route handler memory leak result */
|
|
125
|
-
export declare interface RouteHandlerMemoryLeakResult {
|
|
126
|
-
memoryLeakDetected: boolean
|
|
127
|
-
initialMemory: number
|
|
128
|
-
finalMemory: number
|
|
129
|
-
memoryGrowth: number
|
|
130
|
-
}
|
|
131
|
-
/** Ramp up test options */
|
|
132
|
-
export declare interface RampUpTestOptions {
|
|
133
|
-
startConcurrency: number
|
|
134
|
-
endConcurrency: number
|
|
135
|
-
rampUpTime: number
|
|
136
|
-
testDuration: number
|
|
137
|
-
}
|
|
138
|
-
/** Ramp up test result */
|
|
139
|
-
export declare interface RampUpTestResult {
|
|
140
|
-
concurrency: number
|
|
141
|
-
requestsPerSecond: number
|
|
142
|
-
averageResponseTime: number
|
|
143
|
-
errorRate: number
|
|
144
|
-
}
|
|
145
|
-
/** Spike test options */
|
|
146
|
-
export declare interface SpikeTestOptions {
|
|
147
|
-
normalLoad: number
|
|
148
|
-
spikeLoad: number
|
|
149
|
-
spikeDuration: number
|
|
150
|
-
}
|
|
151
|
-
/** Spike test result */
|
|
152
|
-
export declare interface SpikeTestResult {
|
|
153
|
-
normalPhase: any
|
|
154
|
-
spikePhase: any
|
|
155
|
-
recoveryPhase: any
|
|
156
|
-
}
|
|
157
|
-
/** Route matching benchmark result */
|
|
158
|
-
export declare interface RouteMatchingBenchmarkResult {
|
|
159
|
-
averageTime: number
|
|
160
|
-
minTime: number
|
|
161
|
-
maxTime: number
|
|
162
|
-
totalTime: number
|
|
163
|
-
matchRate: number
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Performance testing utilities
|
|
167
|
-
*/
|
|
168
|
-
export declare class PerformanceTester {
|
|
169
|
-
private metrics: PerformanceMetrics[];
|
|
170
|
-
private startTime: number;
|
|
171
|
-
private endTime: number;
|
|
172
|
-
start(): PerformanceTester;
|
|
173
|
-
end(): PerformanceTester;
|
|
174
|
-
recordMetric(metric: PerformanceMetrics): PerformanceTester;
|
|
175
|
-
getElapsedTime(): number;
|
|
176
|
-
getMetrics(): PerformanceMetrics[];
|
|
177
|
-
getAverageResponseTime(): number;
|
|
178
|
-
getMemoryStats(): {
|
|
179
|
-
averageHeapUsed: number
|
|
180
|
-
maxHeapUsed: number
|
|
181
|
-
averageRSS: number
|
|
182
|
-
maxRSS: number
|
|
183
|
-
};
|
|
184
|
-
clear(): PerformanceTester;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Load testing utilities
|
|
188
|
-
*/
|
|
189
|
-
export declare class LoadTester {
|
|
190
|
-
private client: TestClient;
|
|
191
|
-
private config: LoadTestConfig;
|
|
192
|
-
constructor(client: TestClient, config: LoadTestConfig);
|
|
193
|
-
run(path: string, method?: 'GET' | 'POST' | 'PUT' | 'DELETE', requestOptions?: any): Promise<{
|
|
194
|
-
totalRequests: number
|
|
195
|
-
successfulRequests: number
|
|
196
|
-
failedRequests: number
|
|
197
|
-
averageResponseTime: number
|
|
198
|
-
requestsPerSecond: number
|
|
199
|
-
errors: Array<{ error: string, count: number }>
|
|
200
|
-
}>;
|
|
201
|
-
private makeRequest(path: string, method: 'GET' | 'POST' | 'PUT' | 'DELETE', options: any): Promise<number>;
|
|
202
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { EnhancedRequest } from '../types';
|
|
2
|
-
import type { Router } from '../router/router';
|
|
3
|
-
import type { TestClientConfig, TestRequestOptions } from './types';
|
|
4
|
-
import type { TestResponseWrapper } from './test-response';
|
|
5
|
-
/**
|
|
6
|
-
* Create a test client for a router
|
|
7
|
-
*/
|
|
8
|
-
export declare function createTestClient(router: Router, config?: TestClientConfig): TestClient;
|
|
9
|
-
/**
|
|
10
|
-
* Test client factory with fluent API
|
|
11
|
-
*/
|
|
12
|
-
export declare const testClient: {
|
|
13
|
-
/**
|
|
14
|
-
* Create a test client for a router
|
|
15
|
-
*/
|
|
16
|
-
for: (router: Router, config?: TestClientConfig) => any;
|
|
17
|
-
/**
|
|
18
|
-
* Create a test client with specific configuration
|
|
19
|
-
*/
|
|
20
|
-
withConfig: (config: TestClientConfig) => (router: Router) => any;
|
|
21
|
-
/**
|
|
22
|
-
* Create a test client with authentication
|
|
23
|
-
*/
|
|
24
|
-
withAuth: (token: string, type: 'Bearer' | 'Basic' = 'Bearer') => (router: Router) => any;
|
|
25
|
-
/**
|
|
26
|
-
* Create a test client with custom headers
|
|
27
|
-
*/
|
|
28
|
-
withHeaders: (headers: Record<string, string>) => (router: Router) => any
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Test client for making HTTP requests to router instances
|
|
32
|
-
*/
|
|
33
|
-
export declare class TestClient {
|
|
34
|
-
private router: Router;
|
|
35
|
-
private config: TestClientConfig;
|
|
36
|
-
private defaultHeaders: Record<string, string>;
|
|
37
|
-
constructor(router: Router, config?: TestClientConfig);
|
|
38
|
-
get(path: string, options?: TestRequestOptions): Promise<TestResponseWrapper>;
|
|
39
|
-
post(path: string, options?: TestRequestOptions): Promise<TestResponseWrapper>;
|
|
40
|
-
put(path: string, options?: TestRequestOptions): Promise<TestResponseWrapper>;
|
|
41
|
-
patch(path: string, options?: TestRequestOptions): Promise<TestResponseWrapper>;
|
|
42
|
-
delete(path: string, options?: TestRequestOptions): Promise<TestResponseWrapper>;
|
|
43
|
-
options(path: string, options?: TestRequestOptions): Promise<TestResponseWrapper>;
|
|
44
|
-
head(path: string, options?: TestRequestOptions): Promise<TestResponseWrapper>;
|
|
45
|
-
request(method: string, path: string, options?: TestRequestOptions): Promise<TestResponseWrapper>;
|
|
46
|
-
private handleRequest(request: EnhancedRequest): Promise<Response>;
|
|
47
|
-
private findMatchingRoute(method: string, pathname: string): { route: any, params: Record<string, string> } | null;
|
|
48
|
-
private matchPath(pattern: string, pathname: string): Record<string, string> | null;
|
|
49
|
-
private executeMiddlewareChain(request: EnhancedRequest, route: any): Promise<Response>;
|
|
50
|
-
private executeHandler(handler: any, request: EnhancedRequest): Promise<Response>;
|
|
51
|
-
setDefaultHeaders(headers: Record<string, string>): TestClient;
|
|
52
|
-
auth(token: string, type?: 'Bearer' | 'Basic'): TestClient;
|
|
53
|
-
userAgent(userAgent: string): TestClient;
|
|
54
|
-
withConfig(config: Partial<TestClientConfig>): TestClient;
|
|
55
|
-
withHeaders(headers: Record<string, string>): TestClient;
|
|
56
|
-
getRouter(): Router;
|
|
57
|
-
getConfig(): TestClientConfig;
|
|
58
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { EnhancedRequest, UploadedFile } from '../types';
|
|
2
|
-
import type { TestFile, TestRequestOptions } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Create a mock request with minimal setup
|
|
5
|
-
*/
|
|
6
|
-
export declare function createMockRequest(method?: string, path?: string, options?: TestRequestOptions): EnhancedRequest;
|
|
7
|
-
/**
|
|
8
|
-
* Helper functions for creating test requests
|
|
9
|
-
*/
|
|
10
|
-
export declare const testRequest: {
|
|
11
|
-
get: (path: string, options?: TestRequestOptions) => any;
|
|
12
|
-
post: (path: string, options?: TestRequestOptions) => any;
|
|
13
|
-
put: (path: string, options?: TestRequestOptions) => any;
|
|
14
|
-
patch: (path: string, options?: TestRequestOptions) => any;
|
|
15
|
-
delete: (path: string, options?: TestRequestOptions) => any;
|
|
16
|
-
options: (path: string, options?: TestRequestOptions) => any;
|
|
17
|
-
head: (path: string, options?: TestRequestOptions) => any
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Creates a mock EnhancedRequest for testing
|
|
21
|
-
*/
|
|
22
|
-
export declare class TestRequestBuilder {
|
|
23
|
-
private request: Partial<EnhancedRequest>;
|
|
24
|
-
private url: URL;
|
|
25
|
-
constructor(method: string, path: string, options?: TestRequestOptions);
|
|
26
|
-
private parseQuery(searchParams: URLSearchParams): Record<string, string | string[]>;
|
|
27
|
-
private convertTestFiles(testFiles: TestFile[]): UploadedFile[];
|
|
28
|
-
private handleBody(body: any): void;
|
|
29
|
-
params(params: Record<string, string>): TestRequestBuilder;
|
|
30
|
-
headers(headers: Record<string, string>): TestRequestBuilder;
|
|
31
|
-
auth(token: string, type?: 'Bearer' | 'Basic'): TestRequestBuilder;
|
|
32
|
-
user(user: any): TestRequestBuilder;
|
|
33
|
-
session(session: any): TestRequestBuilder;
|
|
34
|
-
cookies(cookies: Record<string, string>): TestRequestBuilder;
|
|
35
|
-
context(context: Record<string, any>): TestRequestBuilder;
|
|
36
|
-
json(data: any): TestRequestBuilder;
|
|
37
|
-
form(data: Record<string, any>): TestRequestBuilder;
|
|
38
|
-
files(files: TestFile[]): TestRequestBuilder;
|
|
39
|
-
ip(ip: string): TestRequestBuilder;
|
|
40
|
-
userAgent(userAgent: string): TestRequestBuilder;
|
|
41
|
-
csrf(token: string): TestRequestBuilder;
|
|
42
|
-
build(): EnhancedRequest;
|
|
43
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { TestResponse } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Create a test response from a Response object
|
|
4
|
-
*/
|
|
5
|
-
export declare function createTestResponse(response: Response): Promise<TestResponseWrapper>;
|
|
6
|
-
/**
|
|
7
|
-
* Create a mock response for testing
|
|
8
|
-
*/
|
|
9
|
-
export declare function createMockResponse(status?: number, body?: any, headers?: Record<string, string>): TestResponseWrapper;
|
|
10
|
-
/**
|
|
11
|
-
* Test response wrapper with assertion helpers
|
|
12
|
-
*/
|
|
13
|
-
export declare class TestResponseWrapper implements TestResponse {
|
|
14
|
-
status: number;
|
|
15
|
-
statusText: string;
|
|
16
|
-
headers: Record<string, string>;
|
|
17
|
-
body: any;
|
|
18
|
-
text: string;
|
|
19
|
-
json: any;
|
|
20
|
-
cookies: Record<string, string>;
|
|
21
|
-
redirected: boolean;
|
|
22
|
-
url: string;
|
|
23
|
-
ok: boolean;
|
|
24
|
-
type: string;
|
|
25
|
-
private originalResponse: Response;
|
|
26
|
-
constructor(response: Response, body?: any);
|
|
27
|
-
private parseHeaders(headers: Headers): Record<string, string>;
|
|
28
|
-
private parseCookies(cookieHeader: string | null): Record<string, string>;
|
|
29
|
-
expectStatus(status: number): TestResponseWrapper;
|
|
30
|
-
expectSuccess(): TestResponseWrapper;
|
|
31
|
-
expectHeader(name: string, value?: string): TestResponseWrapper;
|
|
32
|
-
expectBody(expectedBody: any): TestResponseWrapper;
|
|
33
|
-
expectJson(expectedJson: any): TestResponseWrapper;
|
|
34
|
-
expectJsonContains(properties: Record<string, any>): TestResponseWrapper;
|
|
35
|
-
expectCookie(name: string, value?: string): TestResponseWrapper;
|
|
36
|
-
expectRedirect(url?: string): TestResponseWrapper;
|
|
37
|
-
expectValidationError(field?: string, message?: string): TestResponseWrapper;
|
|
38
|
-
expectContentType(contentType: string): TestResponseWrapper;
|
|
39
|
-
expectBodyContains(text: string): TestResponseWrapper;
|
|
40
|
-
expectBodyMatches(pattern: RegExp): TestResponseWrapper;
|
|
41
|
-
expectJsonStructure(structure: any): TestResponseWrapper;
|
|
42
|
-
private validateStructure(data: any, structure: any, path: string): void;
|
|
43
|
-
getOriginalResponse(): Response;
|
|
44
|
-
toJSON(): any;
|
|
45
|
-
}
|
package/dist/testing/types.d.ts
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import type { EnhancedRequest, MiddlewareHandler } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Test client configuration options
|
|
4
|
-
*/
|
|
5
|
-
export declare interface TestClientConfig {
|
|
6
|
-
baseUrl?: string
|
|
7
|
-
defaultHeaders?: Record<string, string>
|
|
8
|
-
timeout?: number
|
|
9
|
-
followRedirects?: boolean
|
|
10
|
-
validateStatus?: (status: number) => boolean
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Test request options
|
|
14
|
-
*/
|
|
15
|
-
export declare interface TestRequestOptions {
|
|
16
|
-
headers?: Record<string, string>
|
|
17
|
-
query?: Record<string, string | string[]>
|
|
18
|
-
body?: any
|
|
19
|
-
files?: TestFile[]
|
|
20
|
-
cookies?: Record<string, string>
|
|
21
|
-
session?: any
|
|
22
|
-
user?: any
|
|
23
|
-
context?: Record<string, any>
|
|
24
|
-
timeout?: number
|
|
25
|
-
followRedirects?: boolean
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Test file for upload testing
|
|
29
|
-
*/
|
|
30
|
-
export declare interface TestFile {
|
|
31
|
-
fieldName: string
|
|
32
|
-
filename: string
|
|
33
|
-
content: string | ArrayBuffer | Uint8Array
|
|
34
|
-
mimetype?: string
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Test response interface
|
|
38
|
-
*/
|
|
39
|
-
export declare interface TestResponse {
|
|
40
|
-
status: number
|
|
41
|
-
statusText: string
|
|
42
|
-
headers: Record<string, string>
|
|
43
|
-
body: any
|
|
44
|
-
text: string
|
|
45
|
-
json: any
|
|
46
|
-
cookies: Record<string, string>
|
|
47
|
-
redirected: boolean
|
|
48
|
-
url: string
|
|
49
|
-
ok: boolean
|
|
50
|
-
type: string
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Middleware test context
|
|
54
|
-
*/
|
|
55
|
-
export declare interface MiddlewareTestContext {
|
|
56
|
-
request: EnhancedRequest
|
|
57
|
-
response?: Response
|
|
58
|
-
next: ReturnType<typeof import('bun:test').mock<() => Promise<Response | null>>>
|
|
59
|
-
error?: Error
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Authentication test user
|
|
63
|
-
*/
|
|
64
|
-
export declare interface TestUser {
|
|
65
|
-
id: string | number
|
|
66
|
-
email?: string
|
|
67
|
-
username?: string
|
|
68
|
-
roles?: string[]
|
|
69
|
-
permissions?: string[]
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* JWT test options
|
|
73
|
-
*/
|
|
74
|
-
export declare interface JWTTestOptions {
|
|
75
|
-
secret?: string
|
|
76
|
-
expiresIn?: string
|
|
77
|
-
algorithm?: 'HS256' | 'HS384' | 'HS512' | 'RS256'
|
|
78
|
-
payload?: Record<string, any>
|
|
79
|
-
headers?: Record<string, any>
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Session test options
|
|
83
|
-
*/
|
|
84
|
-
export declare interface SessionTestOptions {
|
|
85
|
-
sessionId?: string
|
|
86
|
-
data?: Record<string, any>
|
|
87
|
-
maxAge?: number
|
|
88
|
-
secure?: boolean
|
|
89
|
-
httpOnly?: boolean
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Model binding test options
|
|
93
|
-
*/
|
|
94
|
-
export declare interface ModelBindingTestOptions {
|
|
95
|
-
modelClass?: any
|
|
96
|
-
routeKey?: string
|
|
97
|
-
constraints?: Record<string, any>
|
|
98
|
-
customResolver?: (value: string) => Promise<any>
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Performance test metrics
|
|
102
|
-
*/
|
|
103
|
-
export declare interface PerformanceMetrics {
|
|
104
|
-
responseTime: number
|
|
105
|
-
memoryUsage: {
|
|
106
|
-
heapUsed: number
|
|
107
|
-
heapTotal: number
|
|
108
|
-
external: number
|
|
109
|
-
rss: number
|
|
110
|
-
}
|
|
111
|
-
cpuUsage: {
|
|
112
|
-
user: number
|
|
113
|
-
system: number
|
|
114
|
-
}
|
|
115
|
-
requestsPerSecond?: number
|
|
116
|
-
concurrentRequests?: number
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Load test configuration
|
|
120
|
-
*/
|
|
121
|
-
export declare interface LoadTestConfig {
|
|
122
|
-
duration: number
|
|
123
|
-
concurrency: number
|
|
124
|
-
rampUp?: number
|
|
125
|
-
rampDown?: number
|
|
126
|
-
requestsPerSecond?: number
|
|
127
|
-
maxRequests?: number
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* WebSocket test message
|
|
131
|
-
*/
|
|
132
|
-
export declare interface WSTestMessage {
|
|
133
|
-
type: 'text' | 'binary'
|
|
134
|
-
data: string | ArrayBuffer | Uint8Array
|
|
135
|
-
timestamp?: number
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* WebSocket test client
|
|
139
|
-
*/
|
|
140
|
-
export declare interface WSTestClient {
|
|
141
|
-
send: (message: string | ArrayBuffer | Uint8Array) => void
|
|
142
|
-
close: (code?: number, reason?: string) => void
|
|
143
|
-
ping: (data?: Uint8Array) => void
|
|
144
|
-
pong: (data?: Uint8Array) => void
|
|
145
|
-
messages: WSTestMessage[]
|
|
146
|
-
isConnected: boolean
|
|
147
|
-
readyState: number
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Test assertion helpers
|
|
151
|
-
*/
|
|
152
|
-
export declare interface TestAssertions {
|
|
153
|
-
toHaveStatus: (status: number) => void
|
|
154
|
-
toHaveHeader: (name: string, value?: string) => void
|
|
155
|
-
toHaveBody: (body: any) => void
|
|
156
|
-
toHaveJson: (json: any) => void
|
|
157
|
-
toHaveCookie: (name: string, value?: string) => void
|
|
158
|
-
toBeRedirected: (url?: string) => void
|
|
159
|
-
toHaveValidationError: (field?: string, message?: string) => void
|
|
160
|
-
toBeAuthenticated: (user?: any) => void
|
|
161
|
-
toBeUnauthenticated: () => void
|
|
162
|
-
toHaveMiddleware: (middleware: string | MiddlewareHandler) => void
|
|
163
|
-
toHaveModel: (model: any) => void
|
|
164
|
-
toHaveUploadedFile: (fieldName: string, filename?: string) => void
|
|
165
|
-
toRespondWithin: (milliseconds: number) => void
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Mock factory options
|
|
169
|
-
*/
|
|
170
|
-
export declare interface MockFactoryOptions {
|
|
171
|
-
count?: number
|
|
172
|
-
overrides?: Record<string, any>
|
|
173
|
-
relations?: Record<string, any>
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Database test helpers
|
|
177
|
-
*/
|
|
178
|
-
export declare interface DatabaseTestHelpers {
|
|
179
|
-
seed: (data: any[]) => Promise<void>
|
|
180
|
-
truncate: (tables?: string[]) => Promise<void>
|
|
181
|
-
factory: <T>(model: string, options?: MockFactoryOptions) => T[]
|
|
182
|
-
create: <T>(model: string, data?: Partial<T>) => Promise<T>
|
|
183
|
-
transaction: <T>(callback: () => Promise<T>) => Promise<T>
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Test environment configuration
|
|
187
|
-
*/
|
|
188
|
-
export declare interface TestEnvironment {
|
|
189
|
-
database?: DatabaseTestHelpers
|
|
190
|
-
cache?: {
|
|
191
|
-
clear: () => Promise<void>
|
|
192
|
-
get: (key: string) => Promise<any>
|
|
193
|
-
set: (key: string, value: any, ttl?: number) => Promise<void>
|
|
194
|
-
}
|
|
195
|
-
storage?: {
|
|
196
|
-
clear: () => Promise<void>
|
|
197
|
-
put: (path: string, content: string | ArrayBuffer) => Promise<void>
|
|
198
|
-
get: (path: string) => Promise<string | ArrayBuffer | null>
|
|
199
|
-
delete: (path: string) => Promise<void>
|
|
200
|
-
}
|
|
201
|
-
queue?: {
|
|
202
|
-
clear: () => Promise<void>
|
|
203
|
-
push: (job: any) => Promise<void>
|
|
204
|
-
process: () => Promise<void>
|
|
205
|
-
}
|
|
206
|
-
}
|