@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
package/dist/utils/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './query-preservation';
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate the client-side script for query preservation
|
|
3
|
-
* This script intercepts link clicks and preserves specified query params
|
|
4
|
-
*/
|
|
5
|
-
export declare function generateQueryPreservationScript(config: QueryPreservationConfig): string;
|
|
6
|
-
/**
|
|
7
|
-
* Inject the query preservation script into HTML content
|
|
8
|
-
* Inserts before </head> or </body> if </head> not found
|
|
9
|
-
*/
|
|
10
|
-
export declare function injectQueryPreservationScript(html: string, config: QueryPreservationConfig): string;
|
|
11
|
-
/**
|
|
12
|
-
* Build a URL with preserved query parameters
|
|
13
|
-
* Server-side utility for generating links
|
|
14
|
-
*/
|
|
15
|
-
export declare function buildUrlWithPreservedParams(path: string, currentUrl: string | URL, config: QueryPreservationConfig, additionalParams?: Record<string, string>): string;
|
|
16
|
-
/**
|
|
17
|
-
* Default configuration
|
|
18
|
-
*/
|
|
19
|
-
export declare const defaultQueryPreservationConfig: QueryPreservationConfig;
|
|
20
|
-
/**
|
|
21
|
-
* Query Parameter Preservation
|
|
22
|
-
*
|
|
23
|
-
* Automatically preserves specified query parameters across navigation.
|
|
24
|
-
* This is useful for maintaining state like siteId, theme, locale, etc.
|
|
25
|
-
*/
|
|
26
|
-
export declare interface QueryPreservationConfig {
|
|
27
|
-
enabled?: boolean
|
|
28
|
-
preserve?: string[]
|
|
29
|
-
exclude?: string[]
|
|
30
|
-
routes?: string[]
|
|
31
|
-
}
|
package/dist/utils.d.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type { ActionHandler, ActionHandlerClass, RouteHandler } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Normalizes a path by ensuring it starts with a forward slash and has no trailing slash
|
|
4
|
-
* @param path The path to normalize
|
|
5
|
-
*/
|
|
6
|
-
export declare function normalizePath(path: string): string;
|
|
7
|
-
/**
|
|
8
|
-
* Converts a string path to an action path for dynamic imports
|
|
9
|
-
* @param path The path to convert (e.g., 'Actions/Home/IndexAction')
|
|
10
|
-
*/
|
|
11
|
-
export declare function toActionPath(path: string): string;
|
|
12
|
-
/**
|
|
13
|
-
* Checks if a handler is a class constructor implementing ActionHandlerClass
|
|
14
|
-
* @param handler The handler to check
|
|
15
|
-
*/
|
|
16
|
-
export declare function isActionClass(handler: ActionHandler): handler is new () => ActionHandlerClass;
|
|
17
|
-
/**
|
|
18
|
-
* Checks if a handler is a route handler function
|
|
19
|
-
* @param handler The handler to check
|
|
20
|
-
*/
|
|
21
|
-
export declare function isRouteHandler(handler: ActionHandler): handler is RouteHandler;
|
|
22
|
-
/**
|
|
23
|
-
* Extracts named parameters from a path pattern
|
|
24
|
-
* @param pattern The path pattern (e.g., '/users/{id}/posts/{postId}')
|
|
25
|
-
*/
|
|
26
|
-
export declare function extractParamNames(pattern: string): string[];
|
|
27
|
-
/**
|
|
28
|
-
* Creates a regex pattern from a path pattern
|
|
29
|
-
* @param pattern The path pattern
|
|
30
|
-
*/
|
|
31
|
-
export declare function createPathRegex(pattern: string): RegExp;
|
|
32
|
-
/**
|
|
33
|
-
* Matches a path against a pattern and extracts parameters
|
|
34
|
-
* @param pattern The path pattern (e.g., '/users/{id}')
|
|
35
|
-
* @param path The actual path (e.g., '/users/123')
|
|
36
|
-
* @param params Output parameter object that will contain extracted parameters
|
|
37
|
-
* @param constraints Optional constraints for route parameters
|
|
38
|
-
* @returns Boolean indicating whether the path matches the pattern
|
|
39
|
-
*/
|
|
40
|
-
export declare function matchPath(pattern: string, path: string, params: Record<string, string>, constraints?: Record<string, string>): boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Joins path segments ensuring proper formatting
|
|
43
|
-
* @param segments Path segments to join
|
|
44
|
-
*/
|
|
45
|
-
export declare function joinPaths(...segments: string[]): string;
|
|
46
|
-
/**
|
|
47
|
-
* Validates a route path format
|
|
48
|
-
* @param path The path to validate
|
|
49
|
-
*/
|
|
50
|
-
export declare function validatePath(path: string): boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Check if a file exists at the given path
|
|
53
|
-
* @param path The file path to check
|
|
54
|
-
*/
|
|
55
|
-
export declare function fileExists(path: string): Promise<boolean>;
|
|
56
|
-
/**
|
|
57
|
-
* Resolve a view name to an actual file path
|
|
58
|
-
* @param viewName The view name (without extension)
|
|
59
|
-
* @param viewsPath The base path for views
|
|
60
|
-
* @param extensions File extensions to try
|
|
61
|
-
*/
|
|
62
|
-
export declare function resolveViewPath(viewName: string, viewsPath: string, extensions: string[]): Promise<string | null>;
|
|
63
|
-
/**
|
|
64
|
-
* Basic HTML template processing - replaces {{ varName }} with the corresponding value
|
|
65
|
-
* @param template The HTML template string
|
|
66
|
-
* @param data The data to inject into the template
|
|
67
|
-
*/
|
|
68
|
-
export declare function processHtmlTemplate(template: string, data: Record<string, any>): string;
|
|
69
|
-
export * from './utils/query-preservation';
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validation middleware factory
|
|
3
|
-
*/
|
|
4
|
-
export declare function createValidationMiddleware(rules: ValidationRules, config?: ValidatorConfig): void;
|
|
5
|
-
/**
|
|
6
|
-
* Factory function to create validation rule builder
|
|
7
|
-
*/
|
|
8
|
-
export declare function rule(): ValidationRuleBuilder;
|
|
9
|
-
/**
|
|
10
|
-
* Built-in validation rules
|
|
11
|
-
*/
|
|
12
|
-
export declare const BuiltInRules: {
|
|
13
|
-
required: { name: 'required'; validate: (value) => unknown; message: 'The :field field is required.' };
|
|
14
|
-
string: {
|
|
15
|
-
name: 'string';
|
|
16
|
-
validate: unknown;
|
|
17
|
-
message: 'The :field field must be a string.'
|
|
18
|
-
};
|
|
19
|
-
number: {
|
|
20
|
-
name: 'number';
|
|
21
|
-
validate: unknown
|
|
22
|
-
};
|
|
23
|
-
integer: {
|
|
24
|
-
name: 'integer';
|
|
25
|
-
validate: unknown
|
|
26
|
-
};
|
|
27
|
-
boolean: {
|
|
28
|
-
name: 'boolean';
|
|
29
|
-
validate: unknown;
|
|
30
|
-
message: 'The :field field must be true or false.'
|
|
31
|
-
};
|
|
32
|
-
email: { name: 'email'; validate: (value) => unknown };
|
|
33
|
-
url: { name: 'url'; validate: (value) => unknown };
|
|
34
|
-
min: { name: 'min'; validate: (value, parameters) => unknown };
|
|
35
|
-
max: { name: 'max'; validate: (value, parameters) => unknown };
|
|
36
|
-
between: { name: 'between'; validate: (value, parameters) => unknown };
|
|
37
|
-
in: { name: 'in'; validate: (value, parameters) => unknown; message: (field, parameters) => unknown };
|
|
38
|
-
notIn: { name: 'not_in'; validate: (value, parameters) => unknown; message: (field, parameters) => unknown };
|
|
39
|
-
regex: { name: 'regex'; validate: (value, parameters) => unknown };
|
|
40
|
-
alpha: {
|
|
41
|
-
name: 'alpha';
|
|
42
|
-
validate: unknown
|
|
43
|
-
};
|
|
44
|
-
alphaNum: {
|
|
45
|
-
name: 'alpha_num';
|
|
46
|
-
validate: unknown
|
|
47
|
-
};
|
|
48
|
-
alphaDash: {
|
|
49
|
-
name: 'alpha_dash';
|
|
50
|
-
validate: unknown
|
|
51
|
-
};
|
|
52
|
-
date: { name: 'date'; validate: (value) => unknown };
|
|
53
|
-
dateAfter: { name: 'after'; validate: (value, parameters) => unknown };
|
|
54
|
-
dateBefore: { name: 'before'; validate: (value, parameters) => unknown };
|
|
55
|
-
confirmed: { name: 'confirmed'; validate: (value, parameters, field, data) => unknown };
|
|
56
|
-
same: { name: 'same'; validate: (value, parameters, field, data) => unknown };
|
|
57
|
-
different: { name: 'different'; validate: (value, parameters, field, data) => unknown; message: (field, parameters) => unknown };
|
|
58
|
-
json: { name: 'json'; validate: (value) => unknown; message: 'The :field field must be valid JSON.' };
|
|
59
|
-
uuid: { name: 'uuid'; validate: (value) => unknown };
|
|
60
|
-
array: {
|
|
61
|
-
name: 'array';
|
|
62
|
-
validate: unknown
|
|
63
|
-
};
|
|
64
|
-
object: {
|
|
65
|
-
name: 'object';
|
|
66
|
-
validate: unknown
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Database validation rules (require external implementation)
|
|
71
|
-
*/
|
|
72
|
-
export declare const DatabaseRules: {
|
|
73
|
-
unique: { name: 'unique'; validate: (_value, _parameters) => unknown; message: 'The :field field must be unique.' };
|
|
74
|
-
exists: { name: 'exists'; validate: (_value, _parameters) => unknown; message: 'The selected :field is invalid.' }
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Global validator instance
|
|
78
|
-
*/
|
|
79
|
-
export declare const globalValidator: Validator;
|
|
80
|
-
/**
|
|
81
|
-
* Validation helper functions
|
|
82
|
-
*/
|
|
83
|
-
export declare const ValidationHelpers: {
|
|
84
|
-
/**
|
|
85
|
-
* Create validation rules object
|
|
86
|
-
*/
|
|
87
|
-
rules(rules: Record<string, string | ValidationRuleBuilder>): unknown;
|
|
88
|
-
/**
|
|
89
|
-
* Validate single value
|
|
90
|
-
*/
|
|
91
|
-
async validateValue(value: any, rules: string, field = 'value'): unknown;
|
|
92
|
-
/**
|
|
93
|
-
* Check if value passes validation
|
|
94
|
-
*/
|
|
95
|
-
async passes(value: any, rules: string): unknown;
|
|
96
|
-
/**
|
|
97
|
-
* Check if value fails validation
|
|
98
|
-
*/
|
|
99
|
-
async fails(value: any, rules: string): unknown
|
|
100
|
-
};
|
|
101
|
-
export declare interface ValidationRule {
|
|
102
|
-
name: string
|
|
103
|
-
validate: (value: any, parameters: string[], field: string, data: Record<string, any>) => Promise<boolean> | boolean
|
|
104
|
-
message: string | ((field: string, parameters: string[]) => string)
|
|
105
|
-
}
|
|
106
|
-
export declare interface ValidationRules {
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
export declare interface ValidationErrors {
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
export declare interface ValidatorConfig {
|
|
113
|
-
stopOnFirstFailure?: boolean
|
|
114
|
-
customMessages?: Record<string, string>
|
|
115
|
-
customAttributes?: Record<string, string>
|
|
116
|
-
bail?: boolean
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Main validator class
|
|
120
|
-
*/
|
|
121
|
-
export declare class Validator {
|
|
122
|
-
private rules: Record<string, ValidationRule>;
|
|
123
|
-
private config: ValidatorConfig;
|
|
124
|
-
constructor(config?: ValidatorConfig);
|
|
125
|
-
registerRule(rule: ValidationRule): void;
|
|
126
|
-
registerRules(rules: Record<string, ValidationRule>): void;
|
|
127
|
-
private parseRuleString(ruleString: string): Array<{ name: string, parameters: string[] }>;
|
|
128
|
-
validate(data: Record<string, any>, rules: ValidationRules): Promise<ValidationErrors>;
|
|
129
|
-
validateOrFail(data: Record<string, any>, rules: ValidationRules): Promise<void>;
|
|
130
|
-
private getNestedValue(obj: Record<string, any>, path: string): any;
|
|
131
|
-
private formatErrorMessage(rule: ValidationRule, field: string, parameters: string[]): string;
|
|
132
|
-
private replacePlaceholders(message: string, field: string, parameters: string[]): string;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Validation rule builder for fluent API
|
|
136
|
-
*/
|
|
137
|
-
export declare class ValidationRuleBuilder {
|
|
138
|
-
private rules: string[];
|
|
139
|
-
required(): this;
|
|
140
|
-
string(): this;
|
|
141
|
-
number(): this;
|
|
142
|
-
integer(): this;
|
|
143
|
-
boolean(): this;
|
|
144
|
-
email(): this;
|
|
145
|
-
url(): this;
|
|
146
|
-
min(value: number): this;
|
|
147
|
-
max(value: number): this;
|
|
148
|
-
between(min: number, max: number): this;
|
|
149
|
-
in(values: string[]): this;
|
|
150
|
-
notIn(values: string[]): this;
|
|
151
|
-
regex(pattern: string): this;
|
|
152
|
-
alpha(): this;
|
|
153
|
-
alphaNum(): this;
|
|
154
|
-
alphaDash(): this;
|
|
155
|
-
date(): this;
|
|
156
|
-
after(date: string): this;
|
|
157
|
-
before(date: string): this;
|
|
158
|
-
confirmed(field?: string): this;
|
|
159
|
-
same(field: string): this;
|
|
160
|
-
different(field: string): this;
|
|
161
|
-
json(): this;
|
|
162
|
-
uuid(): this;
|
|
163
|
-
array(): this;
|
|
164
|
-
object(): this;
|
|
165
|
-
unique(table: string, column?: string): this;
|
|
166
|
-
exists(table: string, column?: string): this;
|
|
167
|
-
custom(ruleName: string, parameters: string[]): this;
|
|
168
|
-
build(): string;
|
|
169
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import type { ServerWebSocket } from 'bun';
|
|
2
|
-
import type { Buffer } from 'node:buffer';
|
|
3
|
-
/**
|
|
4
|
-
* WebSocket cluster helpers
|
|
5
|
-
*/
|
|
6
|
-
export declare const WebSocketClusterHelpers: {
|
|
7
|
-
/**
|
|
8
|
-
* Create room-based chat system
|
|
9
|
-
*/
|
|
10
|
-
createChatSystem: (cluster: WebSocketCluster) => any;
|
|
11
|
-
/**
|
|
12
|
-
* Create real-time notifications system
|
|
13
|
-
*/
|
|
14
|
-
createNotificationSystem: (cluster: WebSocketCluster) => any;
|
|
15
|
-
/**
|
|
16
|
-
* Create presence system
|
|
17
|
-
*/
|
|
18
|
-
createPresenceSystem: (cluster: WebSocketCluster) => any
|
|
19
|
-
};
|
|
20
|
-
export declare interface WebSocketClusterConfig {
|
|
21
|
-
workers?: number
|
|
22
|
-
maxConnections?: number
|
|
23
|
-
heartbeatInterval?: number
|
|
24
|
-
compression?: boolean
|
|
25
|
-
backpressureLimit?: number
|
|
26
|
-
closeOnBackpressureLimit?: boolean
|
|
27
|
-
idleTimeout?: number
|
|
28
|
-
maxPayloadLength?: number
|
|
29
|
-
}
|
|
30
|
-
export declare interface ClusterMessage {
|
|
31
|
-
type: 'broadcast' | 'direct' | 'join' | 'leave' | 'heartbeat' | 'stats'
|
|
32
|
-
workerId?: string
|
|
33
|
-
targetId?: string
|
|
34
|
-
roomId?: string
|
|
35
|
-
data?: any
|
|
36
|
-
timestamp: number
|
|
37
|
-
}
|
|
38
|
-
export declare interface WebSocketConnection {
|
|
39
|
-
id: string
|
|
40
|
-
workerId: string
|
|
41
|
-
socket: ServerWebSocket<any>
|
|
42
|
-
rooms: Set<string>
|
|
43
|
-
metadata: Record<string, any>
|
|
44
|
-
lastHeartbeat: number
|
|
45
|
-
connected: boolean
|
|
46
|
-
}
|
|
47
|
-
export declare interface WebSocketRoom {
|
|
48
|
-
id: string
|
|
49
|
-
connections: Set<string>
|
|
50
|
-
metadata: Record<string, any>
|
|
51
|
-
created: number
|
|
52
|
-
}
|
|
53
|
-
export declare interface ClusterStats {
|
|
54
|
-
totalConnections: number
|
|
55
|
-
totalRooms: number
|
|
56
|
-
workerStats: Record<string, {
|
|
57
|
-
connections: number
|
|
58
|
-
rooms: number
|
|
59
|
-
memoryUsage: number
|
|
60
|
-
uptime: number
|
|
61
|
-
}>
|
|
62
|
-
messagesSent: number
|
|
63
|
-
messagesReceived: number
|
|
64
|
-
bytesTransferred: number
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* WebSocket cluster manager for distributing connections across workers
|
|
68
|
-
*/
|
|
69
|
-
export declare class WebSocketCluster {
|
|
70
|
-
private config: Required<WebSocketClusterConfig>;
|
|
71
|
-
private workers: any;
|
|
72
|
-
private connections: any;
|
|
73
|
-
private rooms: any;
|
|
74
|
-
private messageHandlers: any;
|
|
75
|
-
private stats: ClusterStats;
|
|
76
|
-
private heartbeatTimer?: Timer;
|
|
77
|
-
private isMainWorker: boolean;
|
|
78
|
-
private workerId: string;
|
|
79
|
-
constructor(config?: WebSocketClusterConfig);
|
|
80
|
-
createServer(options?: {
|
|
81
|
-
port?: number
|
|
82
|
-
hostname?: string
|
|
83
|
-
onConnection?: (ws: ServerWebSocket<any>, request: Request) => void
|
|
84
|
-
onMessage?: (ws: ServerWebSocket<any>, message: string | Buffer) => void
|
|
85
|
-
onClose?: (ws: ServerWebSocket<any>, code?: number, reason?: string) => void
|
|
86
|
-
onError?: (ws: ServerWebSocket<any>, error: Error) => void
|
|
87
|
-
}): any;
|
|
88
|
-
joinRoom(connectionId: string, roomId: string, metadata?: Record<string, any>): boolean;
|
|
89
|
-
leaveRoom(connectionId: string, roomId: string): boolean;
|
|
90
|
-
broadcastToRoom(roomId: string, message: string | Buffer, excludeConnectionId?: string): number;
|
|
91
|
-
sendToConnection(connectionId: string, message: string | Buffer): boolean;
|
|
92
|
-
getStats(): ClusterStats;
|
|
93
|
-
getRoomConnections(roomId: string): string[];
|
|
94
|
-
getConnectionRooms(connectionId: string): string[];
|
|
95
|
-
closeConnection(connectionId: string, code?: number, reason?: string): boolean;
|
|
96
|
-
shutdown(): void;
|
|
97
|
-
private generateConnectionId(): string;
|
|
98
|
-
private generateWorkerId(): string;
|
|
99
|
-
private initializeStats(): ClusterStats;
|
|
100
|
-
private setupWorkerCommunication(): void;
|
|
101
|
-
private handleWorkerMessage(message: ClusterMessage): void;
|
|
102
|
-
private handleClusterMessage(connection: WebSocketConnection, message: ClusterMessage): void;
|
|
103
|
-
private broadcastToWorkers(message: ClusterMessage): void;
|
|
104
|
-
private startHeartbeat(): void;
|
|
105
|
-
private updateWorkerStats(): void;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* WebSocket cluster factory
|
|
109
|
-
*/
|
|
110
|
-
export declare class WebSocketClusterFactory {
|
|
111
|
-
static create(config?: WebSocketClusterConfig): WebSocketCluster;
|
|
112
|
-
static createHighPerformance(): WebSocketCluster;
|
|
113
|
-
static createDevelopment(): WebSocketCluster;
|
|
114
|
-
}
|