@stacksjs/bun-router 0.0.2 → 0.0.4
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 +7 -9
- 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,46 +0,0 @@
|
|
|
1
|
-
import type { EnhancedRequest, MiddlewareHandler, NextFunction } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Factory function to create a security suite middleware
|
|
4
|
-
*/
|
|
5
|
-
export declare function securitySuite(options?: SecuritySuiteOptions): MiddlewareHandler;
|
|
6
|
-
/**
|
|
7
|
-
* Preset configurations for different security levels
|
|
8
|
-
*/
|
|
9
|
-
export declare const securityPresets: {
|
|
10
|
-
/**
|
|
11
|
-
* Basic security - minimal performance impact
|
|
12
|
-
*/
|
|
13
|
-
basic: () => any;
|
|
14
|
-
/**
|
|
15
|
-
* Standard security - balanced security and performance
|
|
16
|
-
*/
|
|
17
|
-
standard: () => any;
|
|
18
|
-
/**
|
|
19
|
-
* High security - maximum protection
|
|
20
|
-
*/
|
|
21
|
-
high: () => any;
|
|
22
|
-
/**
|
|
23
|
-
* API security - optimized for API endpoints
|
|
24
|
-
*/
|
|
25
|
-
api: () => any;
|
|
26
|
-
/**
|
|
27
|
-
* Development security - minimal restrictions for development
|
|
28
|
-
*/
|
|
29
|
-
development: () => any
|
|
30
|
-
};
|
|
31
|
-
export declare interface SecuritySuiteOptions {
|
|
32
|
-
helmet?: boolean | object
|
|
33
|
-
security?: boolean | object
|
|
34
|
-
ddosProtection?: boolean | object
|
|
35
|
-
inputValidation?: boolean | object
|
|
36
|
-
contentSecurityPolicy?: boolean | object
|
|
37
|
-
order?: string[]
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Comprehensive security middleware suite that combines multiple security layers
|
|
41
|
-
*/
|
|
42
|
-
export declare class SecuritySuite {
|
|
43
|
-
private middlewares: MiddlewareHandler[];
|
|
44
|
-
constructor(options?: SecuritySuiteOptions);
|
|
45
|
-
handle(req: EnhancedRequest, next: NextFunction): Promise<Response | null>;
|
|
46
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { EnhancedRequest, NextFunction } from '../types';
|
|
2
|
-
export declare class Session {
|
|
3
|
-
static private sessions: Map<string, any>;
|
|
4
|
-
handle(req: EnhancedRequest, next: NextFunction): Promise<Response>;
|
|
5
|
-
private parseCookies(req: Request): Record<string, string>;
|
|
6
|
-
private generateSessionId(): string;
|
|
7
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
bindModel,
|
|
3
|
-
createModelBindingMiddleware,
|
|
4
|
-
ModelBindingFactory,
|
|
5
|
-
type ModelBindingMiddlewareOptions,
|
|
6
|
-
ModelBindingUtils,
|
|
7
|
-
TypedModelBinding,
|
|
8
|
-
withModelBinding,
|
|
9
|
-
} from './model-middleware';
|
|
10
|
-
export {
|
|
11
|
-
type ModelBindingConfig,
|
|
12
|
-
ModelFactory,
|
|
13
|
-
ModelRegistry,
|
|
14
|
-
modelRegistry,
|
|
15
|
-
type ModelResolutionResult,
|
|
16
|
-
ModelUtils,
|
|
17
|
-
} from './model-registry';
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import type { EnhancedRequest, } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Create model binding middleware
|
|
4
|
-
*/
|
|
5
|
-
export declare function createModelBindingMiddleware(bindings: ModelBindingRef[], options?: ModelBindingMiddlewareOptions): void;
|
|
6
|
-
/**
|
|
7
|
-
* Single model binding middleware
|
|
8
|
-
*/
|
|
9
|
-
export declare function bindModel(modelName: string, parameterName: string, options?: {
|
|
10
|
-
required?: boolean
|
|
11
|
-
as?: string
|
|
12
|
-
failOnError?: boolean
|
|
13
|
-
}): (req: EnhancedRequest, next: () => Promise<Response>) => Promise<Response>;
|
|
14
|
-
/**
|
|
15
|
-
* Route parameter model binding decorator
|
|
16
|
-
*/
|
|
17
|
-
export declare function withModelBinding<TPath extends string>(bindings: ModelBindingRef[]): void;
|
|
18
|
-
/**
|
|
19
|
-
* Model binding utilities for middleware
|
|
20
|
-
*/
|
|
21
|
-
export declare const ModelBindingUtils: {
|
|
22
|
-
/**
|
|
23
|
-
* Create middleware that binds multiple models
|
|
24
|
-
*/
|
|
25
|
-
multiple(bindings: Array<{ model: string, param: string, required?: boolean }>): (req: EnhancedRequest, next: () => Promise<Response>) => unknown
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Type-safe model binding helpers
|
|
29
|
-
*/
|
|
30
|
-
export declare const TypedModelBinding: {
|
|
31
|
-
/**
|
|
32
|
-
* Create a typed model binding that preserves route parameter types
|
|
33
|
-
*/
|
|
34
|
-
create<TPath extends string>(
|
|
35
|
-
bindings: Array<{
|
|
36
|
-
model: string
|
|
37
|
-
param: keyof ExtractRouteParams<TPath>
|
|
38
|
-
required?: boolean
|
|
39
|
-
as?: string
|
|
40
|
-
}>,
|
|
41
|
-
): (req: EnhancedRequest, next: () => Promise<Response>) => unknown;
|
|
42
|
-
/**
|
|
43
|
-
* Create a single typed model binding
|
|
44
|
-
*/
|
|
45
|
-
single<TPath extends string>(
|
|
46
|
-
modelName: string,
|
|
47
|
-
param: keyof ExtractRouteParams<TPath>,
|
|
48
|
-
options: {
|
|
49
|
-
required?: boolean
|
|
50
|
-
as?: string
|
|
51
|
-
} = {},
|
|
52
|
-
): (req: EnhancedRequest, next: () => Promise<Response>) => unknown
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* Model binding middleware options
|
|
56
|
-
*/
|
|
57
|
-
export declare interface ModelBindingMiddlewareOptions {
|
|
58
|
-
failOnError?: boolean
|
|
59
|
-
attachToRequest?: boolean
|
|
60
|
-
paramMapping?: Record<string, string>
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Simplified model binding configuration for middleware
|
|
64
|
-
*/
|
|
65
|
-
export declare interface ModelBindingRef {
|
|
66
|
-
model: string
|
|
67
|
-
parameter: string
|
|
68
|
-
required?: boolean
|
|
69
|
-
as?: string
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Model binding middleware factory
|
|
73
|
-
*/
|
|
74
|
-
export declare class ModelBindingFactory {
|
|
75
|
-
static user(paramName?: string, as?: string): (req: EnhancedRequest, next: () => Promise<Response>) => Promise<Response>;
|
|
76
|
-
static post(paramName?: string, as?: string): (req: EnhancedRequest, next: () => Promise<Response>) => Promise<Response>;
|
|
77
|
-
static category(paramName?: string, as?: string): (req: EnhancedRequest, next: () => Promise<Response>) => Promise<Response>;
|
|
78
|
-
static ownedResource(modelName: string, paramName: string, userIdField?: string): Array<(req: EnhancedRequest, next: () => Promise<Response>) => Promise<Response>>;
|
|
79
|
-
static nested(parentModel: string, parentParam: string, childModel: string, childParam: string): (req: EnhancedRequest, next: () => Promise<Response>) => Promise<Response>;
|
|
80
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import type { EnhancedRequest, ModelResolver, ModelTransformerFn, ModelValidatorFn, } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Global model registry instance
|
|
4
|
-
*/
|
|
5
|
-
export declare const modelRegistry: ModelRegistry;
|
|
6
|
-
/**
|
|
7
|
-
* Model binding utilities
|
|
8
|
-
*/
|
|
9
|
-
export declare const ModelUtils: {
|
|
10
|
-
/**
|
|
11
|
-
* Create a simple resolver for database models
|
|
12
|
-
*/
|
|
13
|
-
dbResolver<T>(
|
|
14
|
-
tableName: string,
|
|
15
|
-
idField: string = 'id',
|
|
16
|
-
db?: any,
|
|
17
|
-
): (ModelResolver<T> { return (params)) => unknown;
|
|
18
|
-
any>>(
|
|
19
|
-
fields: (keyof T)[],
|
|
20
|
-
): (ModelValidatorFn<T> { return (model)) => unknown;
|
|
21
|
-
K extends keyof T>(
|
|
22
|
-
fields: K[],
|
|
23
|
-
): (ModelTransformerFn<T> { return (model)) => unknown;
|
|
24
|
-
K extends keyof T>(
|
|
25
|
-
fields: K[],
|
|
26
|
-
): (ModelTransformerFn<T> { return (model)) => unknown;
|
|
27
|
-
/**
|
|
28
|
-
* Create a UUID validator
|
|
29
|
-
*/
|
|
30
|
-
uuidValidator<T extends { id: string }>(): () => unknown;
|
|
31
|
-
/**
|
|
32
|
-
* Create ownership validator (checks if user owns the model)
|
|
33
|
-
*/
|
|
34
|
-
ownershipValidator<T extends { userId?: string | number }>(
|
|
35
|
-
userIdField: string = 'userId',
|
|
36
|
-
): (ModelValidatorFn<T> { return (model, params, req)) => unknown
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Common model binding factories
|
|
40
|
-
*/
|
|
41
|
-
export declare const ModelFactory: {
|
|
42
|
-
/**
|
|
43
|
-
* Create a simple model binding for database entities
|
|
44
|
-
*/
|
|
45
|
-
entity<T>(
|
|
46
|
-
tableName: string,
|
|
47
|
-
options: {
|
|
48
|
-
idField?: string
|
|
49
|
-
cache?: boolean
|
|
50
|
-
cacheTtl?: number
|
|
51
|
-
validator?: ModelValidatorFn<T>
|
|
52
|
-
transformer?: ModelTransformerFn<T>
|
|
53
|
-
db?: any
|
|
54
|
-
} = {},
|
|
55
|
-
): unknown;
|
|
56
|
-
/**
|
|
57
|
-
* Create a user model binding with ownership validation
|
|
58
|
-
*/
|
|
59
|
-
user<T extends { id: string, userId?: string }>(
|
|
60
|
-
tableName: string = 'users',
|
|
61
|
-
options: {
|
|
62
|
-
cache?: boolean
|
|
63
|
-
cacheTtl?: number
|
|
64
|
-
db?: any
|
|
65
|
-
} = {},
|
|
66
|
-
): unknown;
|
|
67
|
-
/**
|
|
68
|
-
* Create a resource model binding with ownership check
|
|
69
|
-
*/
|
|
70
|
-
ownedResource<T extends { id: string, userId: string }>(
|
|
71
|
-
tableName: string,
|
|
72
|
-
options: {
|
|
73
|
-
idField?: string
|
|
74
|
-
userIdField?: string
|
|
75
|
-
cache?: boolean
|
|
76
|
-
cacheTtl?: number
|
|
77
|
-
db?: any
|
|
78
|
-
} = {},
|
|
79
|
-
): (ModelBindingConfig<T> { const { idField?, userIdField?, cache?, cacheTtl?, db, } = options return { resolver: ModelUtils.dbResolver<T>(tableName, idField, db), validator: (model, params, req)) => unknown
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Model resolution result
|
|
83
|
-
*/
|
|
84
|
-
export declare interface ModelResolutionResult<T = any> {
|
|
85
|
-
model: T | null
|
|
86
|
-
error?: string
|
|
87
|
-
status?: number
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Model binding configuration for a specific model
|
|
91
|
-
*/
|
|
92
|
-
export declare interface ModelBindingConfig<T = any> {
|
|
93
|
-
resolver: ModelResolver<T>
|
|
94
|
-
validator?: ModelValidatorFn<T>
|
|
95
|
-
transformer?: ModelTransformerFn<T>
|
|
96
|
-
cache?: {
|
|
97
|
-
enabled: boolean
|
|
98
|
-
ttl: number
|
|
99
|
-
key?: (params: Record<string, string>) => string
|
|
100
|
-
}
|
|
101
|
-
errorHandling?: {
|
|
102
|
-
notFound?: (params: Record<string, string>) => Response
|
|
103
|
-
validation?: (model: T, error: string) => Response
|
|
104
|
-
transform?: (error: string) => Response
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Model registry for managing model bindings
|
|
109
|
-
*/
|
|
110
|
-
export declare class ModelRegistry {
|
|
111
|
-
private models: any;
|
|
112
|
-
private cache: any;
|
|
113
|
-
register<T>(name: string, config: ModelBindingConfig<T>): void;
|
|
114
|
-
get(name: string): ModelBindingConfig | undefined;
|
|
115
|
-
has(name: string): boolean;
|
|
116
|
-
resolve<T>(modelName: string, params: Record<string, string>, req?: EnhancedRequest): Promise<ModelResolutionResult<T>>;
|
|
117
|
-
createErrorResponse(modelName: string, result: ModelResolutionResult, params: Record<string, string>): Response;
|
|
118
|
-
clearCache(modelName: string, params?: Record<string, string>): void;
|
|
119
|
-
clearAllCache(): void;
|
|
120
|
-
getCacheStats(): { totalEntries: number, validEntries: number, expiredEntries: number, models: number };
|
|
121
|
-
cleanupCache(): number;
|
|
122
|
-
private getCachedModel<T>(modelName: string, params: Record<string, string>, config: ModelBindingConfig): T | null;
|
|
123
|
-
private cacheModel<T>(modelName: string, params: Record<string, string>, model: T, config: ModelBindingConfig): void;
|
|
124
|
-
private generateCacheKey(modelName: string, params: Record<string, string>, config: ModelBindingConfig): string;
|
|
125
|
-
}
|
package/dist/model-binding.d.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import type { EnhancedRequest } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Parse route parameter to extract model name and custom key
|
|
4
|
-
* Examples: {user} -> {name: 'user', key: undefined}
|
|
5
|
-
* {post:slug} -> {name: 'post', key: 'slug'}
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Parse multiple route parameters from path
|
|
9
|
-
*/
|
|
10
|
-
export declare function parseRouteParameters(path: string): { name: string, key?: string }[];
|
|
11
|
-
export declare function parseRouteParameter(param: string): { name: string, key?: string };
|
|
12
|
-
/**
|
|
13
|
-
* Extract model parameters from route path
|
|
14
|
-
*/
|
|
15
|
-
export declare function extractModelParameters(path: string): { name: string, key?: string }[];
|
|
16
|
-
/**
|
|
17
|
-
* Resolve model from route parameter using bun-query-builder
|
|
18
|
-
*/
|
|
19
|
-
export declare function resolveModel<T extends Model>(paramName: string, value: string | number, modelWrapper: BunQueryBuilderModel<T>, customKey?: string, _context?: Record<string, Model>): Promise<T | null>;
|
|
20
|
-
/**
|
|
21
|
-
* Route model binding middleware factory for bun-query-builder models
|
|
22
|
-
*/
|
|
23
|
-
export declare function createModelBindingMiddleware(modelParameters: { name: string, key?: string }[], modelWrappers: Record<string, BunQueryBuilderModel>): (req: EnhancedRequest, next: () => Promise<Response>) => Promise<Response>;
|
|
24
|
-
/**
|
|
25
|
-
* Create a model wrapper from bun-query-builder model definition
|
|
26
|
-
*/
|
|
27
|
-
export declare function createModelWrapper<T extends Model>(modelDefinition: any, queryBuilder: any): BunQueryBuilderModel<T>;
|
|
28
|
-
/**
|
|
29
|
-
* Apply model bindings to a route
|
|
30
|
-
*/
|
|
31
|
-
export declare function applyModelBindings(path: string, modelWrappers: Record<string, BunQueryBuilderModel>, _options?: RouteBindingOptions): (req: EnhancedRequest, next: () => Promise<Response>) => Promise<Response>;
|
|
32
|
-
/**
|
|
33
|
-
* Global model binding registry instance
|
|
34
|
-
*/
|
|
35
|
-
export declare const modelRegistry: ModelBindingRegistry;
|
|
36
|
-
/**
|
|
37
|
-
* Laravel-style model binding that integrates with bun-query-builder models
|
|
38
|
-
*/
|
|
39
|
-
/**
|
|
40
|
-
* Base model interface compatible with bun-query-builder
|
|
41
|
-
*/
|
|
42
|
-
export declare interface Model {
|
|
43
|
-
id: string | number
|
|
44
|
-
getRouteKeyName?: () => string
|
|
45
|
-
resolveRouteBinding?: (value: string | number, field?: string) => Promise<this | null>
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Query builder model resolver interface for integration layer
|
|
49
|
-
*/
|
|
50
|
-
export declare interface QueryBuilderModelResolver<TModel extends Model = Model> {
|
|
51
|
-
table: string
|
|
52
|
-
queryBuilder?: any
|
|
53
|
-
find: (id: string | number, keyName?: string) => Promise<TModel | null>
|
|
54
|
-
findOrFail: (id: string | number, keyName?: string) => Promise<TModel>
|
|
55
|
-
getRouteKeyName?: () => string
|
|
56
|
-
applyConstraints?: (query: any, context: Record<string, Model>) => any
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Model binding configuration interface
|
|
60
|
-
*/
|
|
61
|
-
export declare interface ModelBindingConfig {
|
|
62
|
-
model: string
|
|
63
|
-
key?: string
|
|
64
|
-
constraints?: Record<string, any>
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Model class interface
|
|
68
|
-
*/
|
|
69
|
-
export declare interface ModelClass<T extends Model = Model> {
|
|
70
|
-
new (...args: any[]): T
|
|
71
|
-
find: (id: string | number) => Promise<T | null>
|
|
72
|
-
findOrFail: (id: string | number) => Promise<T>
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Model resolver interface
|
|
76
|
-
*/
|
|
77
|
-
export declare interface ModelResolver<T extends Model = Model> {
|
|
78
|
-
find: (id: string | number, keyName?: string) => Promise<T | null>
|
|
79
|
-
findOrFail: (id: string | number, keyName?: string) => Promise<T>
|
|
80
|
-
getRouteKeyName?: () => string
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Route binding options interface
|
|
84
|
-
*/
|
|
85
|
-
export declare interface RouteBindingOptions {
|
|
86
|
-
model?: string
|
|
87
|
-
key?: string
|
|
88
|
-
constraints?: Record<string, any>
|
|
89
|
-
middleware?: string[]
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Wrapper for bun-query-builder models to add Laravel-style route binding
|
|
93
|
-
*/
|
|
94
|
-
export declare class BunQueryBuilderModel<T extends Model = Model> {
|
|
95
|
-
public definition: any;
|
|
96
|
-
public queryBuilder: any;
|
|
97
|
-
constructor(definition: any, queryBuilder: any);
|
|
98
|
-
getTableName(): string;
|
|
99
|
-
find(id: string | number): Promise<T | null>;
|
|
100
|
-
findOrFail(id: string | number): Promise<T>;
|
|
101
|
-
where(field: string, value: any): Promise<T | null>;
|
|
102
|
-
getRouteKeyName(): string;
|
|
103
|
-
resolveRouteBinding(value: string | number, field?: string): Promise<T | null>;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Model not found error
|
|
107
|
-
*/
|
|
108
|
-
export declare class ModelNotFoundError extends Error {
|
|
109
|
-
public modelName: string;
|
|
110
|
-
public value: string | number;
|
|
111
|
-
public field?: string;
|
|
112
|
-
constructor(modelName: string, value: string | number, field?: string);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Model binding registry for explicit bindings (Laravel Route::model and Route::bind)
|
|
116
|
-
*/
|
|
117
|
-
export declare class ModelBindingRegistry {
|
|
118
|
-
private bindings: any;
|
|
119
|
-
model<T extends Model>(parameter: string, modelWrapper: BunQueryBuilderModel<T>): void;
|
|
120
|
-
bind(parameter: string, resolver: (value: string) => Promise<Model | null>): void;
|
|
121
|
-
getBinding(parameter: string): BunQueryBuilderModel | ((value: string) => Promise<Model | null>) | undefined;
|
|
122
|
-
hasBinding(parameter: string): boolean;
|
|
123
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { Model, QueryBuilderModelResolver } from './model-binding';
|
|
2
|
-
/**
|
|
3
|
-
* Factory function to create model resolvers with bun-query-builder integration
|
|
4
|
-
*/
|
|
5
|
-
export declare function createModelResolver<TModel extends Model = Model>(tableName: string, options?: {
|
|
6
|
-
keyName?: string
|
|
7
|
-
applyConstraints?: (query: any, context: Record<string, Model>) => any
|
|
8
|
-
}): QueryBuilderModelResolver<TModel>;
|
|
9
|
-
/**
|
|
10
|
-
* Create a scoped model resolver that applies constraints based on parent models
|
|
11
|
-
*/
|
|
12
|
-
export declare function createScopedModelResolver<TModel extends Model = Model>(tableName: string, constraintFn: (query: any, context: Record<string, Model>) => any, options?: {
|
|
13
|
-
keyName?: string
|
|
14
|
-
}): QueryBuilderModelResolver<TModel>;
|
|
15
|
-
/**
|
|
16
|
-
* Common constraint functions for scoped bindings
|
|
17
|
-
*/
|
|
18
|
-
export declare const constraints: {
|
|
19
|
-
/**
|
|
20
|
-
* Ensure a model belongs to a specific parent model
|
|
21
|
-
*/
|
|
22
|
-
belongsTo: (parentKey: string, foreignKey: string) => ((query: any, context: Record<string, Model>) => any;
|
|
23
|
-
/**
|
|
24
|
-
* Ensure a model belongs to the authenticated user
|
|
25
|
-
*/
|
|
26
|
-
belongsToUser: (userKey?, foreignKey?) => ((query: any, context: Record<string, Model>) => any;
|
|
27
|
-
/**
|
|
28
|
-
* Apply multiple constraints
|
|
29
|
-
*/
|
|
30
|
-
combine: (...constraintFns: Array<(query: any, context: Record<string, Model>) => any>) => ((query: any, context: Record<string, Model>) => any
|
|
31
|
-
};
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import type { EnhancedRequest } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Initialize global correlation manager
|
|
4
|
-
*/
|
|
5
|
-
export declare function initializeCorrelation(config?: CorrelationConfig): CorrelationManager;
|
|
6
|
-
/**
|
|
7
|
-
* Get global correlation manager
|
|
8
|
-
*/
|
|
9
|
-
export declare function getCorrelationManager(): CorrelationManager | null;
|
|
10
|
-
/**
|
|
11
|
-
* Correlation middleware factory
|
|
12
|
-
*/
|
|
13
|
-
export declare function createCorrelationMiddleware(config?: Partial<CorrelationConfig>): void;
|
|
14
|
-
/**
|
|
15
|
-
* Correlation helper functions
|
|
16
|
-
*/
|
|
17
|
-
export declare const CorrelationHelpers: {
|
|
18
|
-
/**
|
|
19
|
-
* Get correlation ID from request
|
|
20
|
-
*/
|
|
21
|
-
getId: (req: EnhancedRequest) => any;
|
|
22
|
-
/**
|
|
23
|
-
* Get correlation context from request
|
|
24
|
-
*/
|
|
25
|
-
getContext: (req: EnhancedRequest) => any;
|
|
26
|
-
/**
|
|
27
|
-
* Get HTTP client from request
|
|
28
|
-
*/
|
|
29
|
-
getHttpClient: (req: EnhancedRequest) => any;
|
|
30
|
-
/**
|
|
31
|
-
* Add metadata to current correlation
|
|
32
|
-
*/
|
|
33
|
-
addMetadata: (req: EnhancedRequest, metadata: Record<string, any>) => any;
|
|
34
|
-
/**
|
|
35
|
-
* Create child context for service call
|
|
36
|
-
*/
|
|
37
|
-
createChild: (req: EnhancedRequest, serviceName: string) => any;
|
|
38
|
-
/**
|
|
39
|
-
* Get trace for current request
|
|
40
|
-
*/
|
|
41
|
-
getTrace: (req: EnhancedRequest) => any
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Correlation endpoint handlers
|
|
45
|
-
*/
|
|
46
|
-
export declare const CorrelationEndpoints: {
|
|
47
|
-
/**
|
|
48
|
-
* Get correlation trace endpoint
|
|
49
|
-
*/
|
|
50
|
-
trace: (req: EnhancedRequest) => Promise<Response>;
|
|
51
|
-
/**
|
|
52
|
-
* Get correlation statistics endpoint
|
|
53
|
-
*/
|
|
54
|
-
stats: (_req: EnhancedRequest) => Promise<Response>
|
|
55
|
-
};
|
|
56
|
-
export declare interface CorrelationConfig {
|
|
57
|
-
headerName?: string
|
|
58
|
-
generateId?: () => string
|
|
59
|
-
propagateHeaders?: string[]
|
|
60
|
-
enableLogging?: boolean
|
|
61
|
-
logLevel?: 'debug' | 'info' | 'warn' | 'error'
|
|
62
|
-
maxIdLength?: number
|
|
63
|
-
validateId?: (id: string) => boolean
|
|
64
|
-
}
|
|
65
|
-
export declare interface CorrelationContext {
|
|
66
|
-
correlationId: string
|
|
67
|
-
parentId?: string
|
|
68
|
-
spanId?: string
|
|
69
|
-
traceId?: string
|
|
70
|
-
userId?: string
|
|
71
|
-
sessionId?: string
|
|
72
|
-
requestId?: string
|
|
73
|
-
metadata: Record<string, any>
|
|
74
|
-
startTime: number
|
|
75
|
-
headers: Record<string, string>
|
|
76
|
-
}
|
|
77
|
-
export declare interface ServiceCall {
|
|
78
|
-
serviceName: string
|
|
79
|
-
method: string
|
|
80
|
-
url: string
|
|
81
|
-
correlationId: string
|
|
82
|
-
parentId?: string
|
|
83
|
-
startTime: number
|
|
84
|
-
endTime?: number
|
|
85
|
-
duration?: number
|
|
86
|
-
status?: number
|
|
87
|
-
error?: string
|
|
88
|
-
metadata?: Record<string, any>
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Correlation ID manager
|
|
92
|
-
*/
|
|
93
|
-
export declare class CorrelationManager {
|
|
94
|
-
private config: CorrelationConfig;
|
|
95
|
-
private contexts: any;
|
|
96
|
-
private serviceCalls: any;
|
|
97
|
-
private activeRequests: any;
|
|
98
|
-
constructor(config?: CorrelationConfig);
|
|
99
|
-
private generateUUID(): string;
|
|
100
|
-
private isValidId(id: string): boolean;
|
|
101
|
-
extractContext(req: EnhancedRequest): CorrelationContext;
|
|
102
|
-
getContext(correlationId: string): CorrelationContext | undefined;
|
|
103
|
-
updateContext(correlationId: string, updates: Partial<CorrelationContext>): void;
|
|
104
|
-
addMetadata(correlationId: string, metadata: Record<string, any>): void;
|
|
105
|
-
createChildContext(parentId: string, serviceName: string): CorrelationContext;
|
|
106
|
-
recordServiceCall(call: Omit<ServiceCall, 'startTime'>): void;
|
|
107
|
-
completeServiceCall(correlationId: string, serviceName: string, status: number, error?: string, metadata?: Record<string, any>): void;
|
|
108
|
-
getServiceCalls(correlationId: string): ServiceCall[];
|
|
109
|
-
finishContext(correlationId: string, status?: number, error?: string): void;
|
|
110
|
-
createHttpClient(correlationId: string): {
|
|
111
|
-
fetch: (url: string, options?: RequestInit) => Promise<Response>
|
|
112
|
-
get: (url: string, options?: RequestInit) => Promise<Response>
|
|
113
|
-
post: (url: string, options?: RequestInit) => Promise<Response>
|
|
114
|
-
put: (url: string, options?: RequestInit) => Promise<Response>
|
|
115
|
-
delete: (url: string, options?: RequestInit) => Promise<Response>
|
|
116
|
-
};
|
|
117
|
-
getTrace(correlationId: string): {
|
|
118
|
-
context: CorrelationContext
|
|
119
|
-
serviceCalls: ServiceCall[]
|
|
120
|
-
children: string[]
|
|
121
|
-
} | null;
|
|
122
|
-
getFullTrace(rootCorrelationId: string): any;
|
|
123
|
-
cleanup(maxAge?: any): void;
|
|
124
|
-
getStats(): {
|
|
125
|
-
activeContexts: number
|
|
126
|
-
totalContexts: number
|
|
127
|
-
totalServiceCalls: number
|
|
128
|
-
averageCallsPerContext: number
|
|
129
|
-
};
|
|
130
|
-
private log(level: string, message: string, data: any): void;
|
|
131
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Initialize global health check manager
|
|
3
|
-
*/
|
|
4
|
-
export declare function initializeHealthChecks(config?: HealthCheckConfig): HealthCheckManager;
|
|
5
|
-
/**
|
|
6
|
-
* Get global health check manager
|
|
7
|
-
*/
|
|
8
|
-
export declare function getHealthManager(): HealthCheckManager | null;
|
|
9
|
-
/**
|
|
10
|
-
* Health check endpoint handlers
|
|
11
|
-
*/
|
|
12
|
-
export declare const HealthEndpoints: {
|
|
13
|
-
/**
|
|
14
|
-
* Basic health check endpoint
|
|
15
|
-
*/
|
|
16
|
-
health: (_req: EnhancedRequest) => Promise<Response>;
|
|
17
|
-
/**
|
|
18
|
-
* Readiness probe endpoint
|
|
19
|
-
*/
|
|
20
|
-
ready: (_req: EnhancedRequest) => Promise<Response>;
|
|
21
|
-
/**
|
|
22
|
-
* Liveness probe endpoint
|
|
23
|
-
*/
|
|
24
|
-
live: (_req: EnhancedRequest) => Promise<Response>;
|
|
25
|
-
/**
|
|
26
|
-
* Startup probe endpoint
|
|
27
|
-
*/
|
|
28
|
-
startup: (_req: EnhancedRequest) => Promise<Response>
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Built-in dependency check factories
|
|
32
|
-
*/
|
|
33
|
-
export declare const DependencyChecks: {
|
|
34
|
-
/**
|
|
35
|
-
* HTTP service dependency
|
|
36
|
-
*/
|
|
37
|
-
httpService: (name: string, url: string, options: Partial<DependencyConfig> = {}) => any;
|
|
38
|
-
/**
|
|
39
|
-
* Database dependency
|
|
40
|
-
*/
|
|
41
|
-
database: (name: string, options: Partial<DependencyConfig> = {}) => any;
|
|
42
|
-
/**
|
|
43
|
-
* Redis dependency
|
|
44
|
-
*/
|
|
45
|
-
redis: (name: string, options: Partial<DependencyConfig> = {}) => any;
|
|
46
|
-
/**
|
|
47
|
-
* File system dependency
|
|
48
|
-
*/
|
|
49
|
-
fileSystem: (name: string, path: string, options: Partial<DependencyConfig> = {}) => any;
|
|
50
|
-
/**
|
|
51
|
-
* Custom dependency with function
|
|
52
|
-
*/
|
|
53
|
-
custom: (name: string, checkFn: () => Promise<HealthCheckResult>, options: Partial<DependencyConfig> = {}) => any
|
|
54
|
-
};
|
|
55
|
-
export declare interface HealthCheckConfig {
|
|
56
|
-
timeout?: number
|
|
57
|
-
retries?: number
|
|
58
|
-
interval?: number
|
|
59
|
-
gracePeriod?: number
|
|
60
|
-
dependencies?: DependencyConfig[]
|
|
61
|
-
customChecks?: CustomHealthCheck[]
|
|
62
|
-
}
|
|
63
|
-
export declare interface DependencyConfig {
|
|
64
|
-
name: string
|
|
65
|
-
type: 'http' | 'database' | 'redis' | 'queue' | 'file' | 'custom'
|
|
66
|
-
url?: string
|
|
67
|
-
timeout?: number
|
|
68
|
-
retries?: number
|
|
69
|
-
critical?: boolean
|
|
70
|
-
metadata?: Record<string, any>
|
|
71
|
-
check?: () => Promise<HealthCheckResult>
|
|
72
|
-
}
|
|
73
|
-
export declare interface CustomHealthCheck {
|
|
74
|
-
name: string
|
|
75
|
-
check: () => Promise<HealthCheckResult>
|
|
76
|
-
critical?: boolean
|
|
77
|
-
timeout?: number
|
|
78
|
-
}
|
|
79
|
-
export declare interface HealthCheckResult {
|
|
80
|
-
status: 'healthy' | 'unhealthy' | 'degraded'
|
|
81
|
-
message?: string
|
|
82
|
-
duration?: number
|
|
83
|
-
metadata?: Record<string, any>
|
|
84
|
-
error?: string
|
|
85
|
-
timestamp: number
|
|
86
|
-
}
|
|
87
|
-
export declare interface HealthStatus {
|
|
88
|
-
status: 'healthy' | 'unhealthy' | 'degraded'
|
|
89
|
-
timestamp: number
|
|
90
|
-
uptime: number
|
|
91
|
-
version?: string
|
|
92
|
-
environment?: string
|
|
93
|
-
checks: Record<string, HealthCheckResult>
|
|
94
|
-
dependencies: Record<string, HealthCheckResult>
|
|
95
|
-
summary: {
|
|
96
|
-
total: number
|
|
97
|
-
healthy: number
|
|
98
|
-
unhealthy: number
|
|
99
|
-
degraded: number
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Health check manager
|
|
104
|
-
*/
|
|
105
|
-
export declare class HealthCheckManager {
|
|
106
|
-
private config: HealthCheckConfig;
|
|
107
|
-
private dependencies: Map<string, DependencyConfig>;
|
|
108
|
-
private customChecks: Map<string, CustomHealthCheck>;
|
|
109
|
-
private lastResults: Map<string, HealthCheckResult>;
|
|
110
|
-
private startTime: number;
|
|
111
|
-
constructor(config?: HealthCheckConfig);
|
|
112
|
-
addDependency(config: DependencyConfig): void;
|
|
113
|
-
addCustomCheck(check: CustomHealthCheck): void;
|
|
114
|
-
removeDependency(name: string): boolean;
|
|
115
|
-
removeCustomCheck(name: string): boolean;
|
|
116
|
-
checkHealth(): Promise<HealthStatus>;
|
|
117
|
-
private checkDependency(config: DependencyConfig): Promise<HealthCheckResult>;
|
|
118
|
-
private checkHttpDependency(config: DependencyConfig): Promise<HealthCheckResult>;
|
|
119
|
-
private checkDatabaseDependency(config: DependencyConfig): Promise<HealthCheckResult>;
|
|
120
|
-
private checkRedisDependency(config: DependencyConfig): Promise<HealthCheckResult>;
|
|
121
|
-
private checkQueueDependency(config: DependencyConfig): Promise<HealthCheckResult>;
|
|
122
|
-
private checkFileDependency(config: DependencyConfig): Promise<HealthCheckResult>;
|
|
123
|
-
private runCustomCheck(config: CustomHealthCheck): Promise<HealthCheckResult>;
|
|
124
|
-
private executeWithTimeout<T>(promise: Promise<T>, timeout: number): Promise<T>;
|
|
125
|
-
private isCriticalCheck(result: HealthCheckResult): boolean;
|
|
126
|
-
getLastResults(): Map<string, HealthCheckResult>;
|
|
127
|
-
getUptime(): number;
|
|
128
|
-
resetStartTime(): void;
|
|
129
|
-
}
|