@naman_deep_singh/communication-core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +345 -0
- package/dist/cjs/abstract/BaseCircuitBreaker.js +253 -0
- package/dist/cjs/abstract/BaseClient.js +298 -0
- package/dist/cjs/abstract/BaseCompressionManager.js +377 -0
- package/dist/cjs/abstract/BaseConnectionPool.js +543 -0
- package/dist/cjs/abstract/BaseInterceptor.js +235 -0
- package/dist/cjs/abstract/BaseLoadBalancer.js +269 -0
- package/dist/cjs/abstract/BaseProtocol.js +269 -0
- package/dist/cjs/abstract/BaseRetryStrategy.js +255 -0
- package/dist/cjs/abstract/BaseSerializer.js +341 -0
- package/dist/cjs/abstract/BaseServiceDiscoverer.js +254 -0
- package/dist/cjs/abstract/BaseTimeoutManager.js +295 -0
- package/dist/cjs/abstract/index.js +25 -0
- package/dist/cjs/errors/CircuitBreakerError.js +16 -0
- package/dist/cjs/errors/CommunicationError.js +15 -0
- package/dist/cjs/errors/ConnectionError.js +15 -0
- package/dist/cjs/errors/DiscoveryError.js +15 -0
- package/dist/cjs/errors/LoadBalancerError.js +15 -0
- package/dist/cjs/errors/ProtocolError.js +15 -0
- package/dist/cjs/errors/RetryError.js +16 -0
- package/dist/cjs/errors/SerializationError.js +15 -0
- package/dist/cjs/errors/ServiceUnavailableError.js +15 -0
- package/dist/cjs/errors/TimeoutError.js +16 -0
- package/dist/cjs/errors/communicationErrorCodes.js +35 -0
- package/dist/cjs/errors/index.js +31 -0
- package/dist/cjs/index.js +38 -0
- package/dist/cjs/interfaces/CircuitBreaker.interface.js +6 -0
- package/dist/cjs/interfaces/Client.interface.js +6 -0
- package/dist/cjs/interfaces/Compression.interface.js +6 -0
- package/dist/cjs/interfaces/ConnectionPool.interface.js +6 -0
- package/dist/cjs/interfaces/Interceptor.interface.js +6 -0
- package/dist/cjs/interfaces/LoadBalancer.interface.js +2 -0
- package/dist/cjs/interfaces/Protocol.interface.js +6 -0
- package/dist/cjs/interfaces/RetryStrategy.interface.js +6 -0
- package/dist/cjs/interfaces/Serializer.interface.js +2 -0
- package/dist/cjs/interfaces/ServiceDiscovery.interface.js +6 -0
- package/dist/cjs/interfaces/Timeout.interface.js +6 -0
- package/dist/cjs/interfaces/index.js +6 -0
- package/dist/cjs/types/config.js +6 -0
- package/dist/cjs/types/events.js +6 -0
- package/dist/cjs/types/index.js +6 -0
- package/dist/cjs/types/request.js +6 -0
- package/dist/cjs/types/response.js +6 -0
- package/dist/cjs/types/service.js +6 -0
- package/dist/cjs/utils.js +200 -0
- package/dist/esm/abstract/BaseCircuitBreaker.js +249 -0
- package/dist/esm/abstract/BaseClient.js +294 -0
- package/dist/esm/abstract/BaseCompressionManager.js +373 -0
- package/dist/esm/abstract/BaseConnectionPool.js +539 -0
- package/dist/esm/abstract/BaseInterceptor.js +231 -0
- package/dist/esm/abstract/BaseLoadBalancer.js +265 -0
- package/dist/esm/abstract/BaseProtocol.js +265 -0
- package/dist/esm/abstract/BaseRetryStrategy.js +251 -0
- package/dist/esm/abstract/BaseSerializer.js +337 -0
- package/dist/esm/abstract/BaseServiceDiscoverer.js +250 -0
- package/dist/esm/abstract/BaseTimeoutManager.js +291 -0
- package/dist/esm/abstract/index.js +11 -0
- package/dist/esm/errors/CircuitBreakerError.js +12 -0
- package/dist/esm/errors/CommunicationError.js +11 -0
- package/dist/esm/errors/ConnectionError.js +11 -0
- package/dist/esm/errors/DiscoveryError.js +11 -0
- package/dist/esm/errors/LoadBalancerError.js +11 -0
- package/dist/esm/errors/ProtocolError.js +11 -0
- package/dist/esm/errors/RetryError.js +12 -0
- package/dist/esm/errors/SerializationError.js +11 -0
- package/dist/esm/errors/ServiceUnavailableError.js +11 -0
- package/dist/esm/errors/TimeoutError.js +12 -0
- package/dist/esm/errors/communicationErrorCodes.js +32 -0
- package/dist/esm/errors/index.js +17 -0
- package/dist/esm/index.js +18 -0
- package/dist/esm/interfaces/CircuitBreaker.interface.js +5 -0
- package/dist/esm/interfaces/Client.interface.js +5 -0
- package/dist/esm/interfaces/Compression.interface.js +5 -0
- package/dist/esm/interfaces/ConnectionPool.interface.js +5 -0
- package/dist/esm/interfaces/Interceptor.interface.js +5 -0
- package/dist/esm/interfaces/LoadBalancer.interface.js +1 -0
- package/dist/esm/interfaces/Protocol.interface.js +5 -0
- package/dist/esm/interfaces/RetryStrategy.interface.js +5 -0
- package/dist/esm/interfaces/Serializer.interface.js +1 -0
- package/dist/esm/interfaces/ServiceDiscovery.interface.js +5 -0
- package/dist/esm/interfaces/Timeout.interface.js +5 -0
- package/dist/esm/interfaces/index.js +5 -0
- package/dist/esm/types/config.js +5 -0
- package/dist/esm/types/events.js +5 -0
- package/dist/esm/types/index.js +5 -0
- package/dist/esm/types/request.js +5 -0
- package/dist/esm/types/response.js +5 -0
- package/dist/esm/types/service.js +5 -0
- package/dist/esm/utils.js +193 -0
- package/dist/types/abstract/BaseCircuitBreaker.d.ts +167 -0
- package/dist/types/abstract/BaseClient.d.ts +197 -0
- package/dist/types/abstract/BaseCompressionManager.d.ts +180 -0
- package/dist/types/abstract/BaseConnectionPool.d.ts +210 -0
- package/dist/types/abstract/BaseInterceptor.d.ts +150 -0
- package/dist/types/abstract/BaseLoadBalancer.d.ts +167 -0
- package/dist/types/abstract/BaseProtocol.d.ts +163 -0
- package/dist/types/abstract/BaseRetryStrategy.d.ts +130 -0
- package/dist/types/abstract/BaseSerializer.d.ts +181 -0
- package/dist/types/abstract/BaseServiceDiscoverer.d.ts +161 -0
- package/dist/types/abstract/BaseTimeoutManager.d.ts +145 -0
- package/dist/types/abstract/index.d.ts +11 -0
- package/dist/types/errors/CircuitBreakerError.d.ts +8 -0
- package/dist/types/errors/CommunicationError.d.ts +10 -0
- package/dist/types/errors/ConnectionError.d.ts +9 -0
- package/dist/types/errors/DiscoveryError.d.ts +9 -0
- package/dist/types/errors/LoadBalancerError.d.ts +9 -0
- package/dist/types/errors/ProtocolError.d.ts +9 -0
- package/dist/types/errors/RetryError.d.ts +11 -0
- package/dist/types/errors/SerializationError.d.ts +9 -0
- package/dist/types/errors/ServiceUnavailableError.d.ts +12 -0
- package/dist/types/errors/TimeoutError.d.ts +11 -0
- package/dist/types/errors/communicationErrorCodes.d.ts +27 -0
- package/dist/types/errors/index.d.ts +11 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/interfaces/CircuitBreaker.interface.d.ts +150 -0
- package/dist/types/interfaces/Client.interface.d.ts +153 -0
- package/dist/types/interfaces/Compression.interface.d.ts +190 -0
- package/dist/types/interfaces/ConnectionPool.interface.d.ts +191 -0
- package/dist/types/interfaces/Interceptor.interface.d.ts +220 -0
- package/dist/types/interfaces/LoadBalancer.interface.d.ts +153 -0
- package/dist/types/interfaces/Protocol.interface.d.ts +117 -0
- package/dist/types/interfaces/RetryStrategy.interface.d.ts +160 -0
- package/dist/types/interfaces/Serializer.interface.d.ts +176 -0
- package/dist/types/interfaces/ServiceDiscovery.interface.d.ts +189 -0
- package/dist/types/interfaces/Timeout.interface.d.ts +135 -0
- package/dist/types/interfaces/index.d.ts +15 -0
- package/dist/types/types/config.d.ts +540 -0
- package/dist/types/types/events.d.ts +204 -0
- package/dist/types/types/index.d.ts +9 -0
- package/dist/types/types/request.d.ts +143 -0
- package/dist/types/types/response.d.ts +155 -0
- package/dist/types/types/service.d.ts +279 -0
- package/dist/types/utils.d.ts +179 -0
- package/package.json +88 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serializer interface for communication layer
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
import type { SerializationConfig, SerializationFormat } from '../types/config.js';
|
|
6
|
+
/**
|
|
7
|
+
* Serialization context
|
|
8
|
+
*/
|
|
9
|
+
export interface SerializationContext {
|
|
10
|
+
/** Target format */
|
|
11
|
+
format: SerializationFormat;
|
|
12
|
+
/** Content type */
|
|
13
|
+
contentType?: string;
|
|
14
|
+
/** Character encoding */
|
|
15
|
+
encoding?: string;
|
|
16
|
+
/** Custom serialization options */
|
|
17
|
+
options?: Record<string, unknown>;
|
|
18
|
+
/** Request/response metadata */
|
|
19
|
+
metadata?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Deserialization context
|
|
23
|
+
*/
|
|
24
|
+
export interface DeserializationContext {
|
|
25
|
+
/** Source format */
|
|
26
|
+
format: SerializationFormat;
|
|
27
|
+
/** Content type */
|
|
28
|
+
contentType?: string;
|
|
29
|
+
/** Character encoding */
|
|
30
|
+
encoding?: string;
|
|
31
|
+
/** Target type (for type-safe deserialization) */
|
|
32
|
+
targetType?: unknown;
|
|
33
|
+
/** Custom deserialization options */
|
|
34
|
+
options?: Record<string, unknown>;
|
|
35
|
+
/** Request/response metadata */
|
|
36
|
+
metadata?: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Serializer interface for serializing and deserializing data
|
|
40
|
+
*/
|
|
41
|
+
export interface ISerializer {
|
|
42
|
+
/** Serializer name */
|
|
43
|
+
readonly name: string;
|
|
44
|
+
/** Supported formats */
|
|
45
|
+
readonly supportedFormats: SerializationFormat[];
|
|
46
|
+
/** Default format */
|
|
47
|
+
readonly defaultFormat: SerializationFormat;
|
|
48
|
+
/** Serializer configuration */
|
|
49
|
+
readonly config: SerializationConfig;
|
|
50
|
+
/**
|
|
51
|
+
* Serialize data to a specific format
|
|
52
|
+
* @param data Data to serialize
|
|
53
|
+
* @param context Serialization context
|
|
54
|
+
* @returns Serialized data
|
|
55
|
+
* @throws {CommunicationError} If serialization fails
|
|
56
|
+
*/
|
|
57
|
+
serialize<T = unknown>(data: T, context?: Partial<SerializationContext>): string | Buffer | Uint8Array;
|
|
58
|
+
/**
|
|
59
|
+
* Deserialize data from a specific format
|
|
60
|
+
* @param data Data to deserialize
|
|
61
|
+
* @param context Deserialization context
|
|
62
|
+
* @returns Deserialized data
|
|
63
|
+
* @throws {CommunicationError} If deserialization fails
|
|
64
|
+
*/
|
|
65
|
+
deserialize<T = unknown>(data: string | Buffer | Uint8Array, context?: Partial<DeserializationContext>): T;
|
|
66
|
+
/**
|
|
67
|
+
* Check if a format is supported
|
|
68
|
+
* @param format Format to check
|
|
69
|
+
*/
|
|
70
|
+
supportsFormat(format: SerializationFormat): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Get content type for a format
|
|
73
|
+
* @param format Format
|
|
74
|
+
* @returns Content type string
|
|
75
|
+
*/
|
|
76
|
+
getContentType(format: SerializationFormat): string;
|
|
77
|
+
/**
|
|
78
|
+
* Get format from content type
|
|
79
|
+
* @param contentType Content type
|
|
80
|
+
* @returns Format or undefined if not recognized
|
|
81
|
+
*/
|
|
82
|
+
getFormatFromContentType(contentType: string): SerializationFormat | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Validate data against a schema
|
|
85
|
+
* @param data Data to validate
|
|
86
|
+
* @param schema Validation schema
|
|
87
|
+
* @returns Validation result
|
|
88
|
+
*/
|
|
89
|
+
validate?(data: unknown, schema: unknown): {
|
|
90
|
+
valid: boolean;
|
|
91
|
+
errors?: string[];
|
|
92
|
+
details?: Record<string, unknown>;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Transform data (e.g., date parsing, bigint handling)
|
|
96
|
+
* @param data Data to transform
|
|
97
|
+
* @param direction 'serialize' or 'deserialize'
|
|
98
|
+
*/
|
|
99
|
+
transform?(data: unknown, direction: 'serialize' | 'deserialize'): unknown;
|
|
100
|
+
/**
|
|
101
|
+
* Register a custom format handler
|
|
102
|
+
* @param format Format name
|
|
103
|
+
* @param handler Serialization/deserialization functions
|
|
104
|
+
*/
|
|
105
|
+
registerFormat?(format: SerializationFormat, handler: {
|
|
106
|
+
serialize: (data: unknown) => string | Buffer | Uint8Array;
|
|
107
|
+
deserialize: (data: string | Buffer | Uint8Array) => unknown;
|
|
108
|
+
contentType?: string;
|
|
109
|
+
}): void;
|
|
110
|
+
/**
|
|
111
|
+
* Update serializer configuration
|
|
112
|
+
* @param config New configuration
|
|
113
|
+
*/
|
|
114
|
+
updateConfig(config: Partial<SerializationConfig>): void;
|
|
115
|
+
/**
|
|
116
|
+
* Get serializer statistics
|
|
117
|
+
*/
|
|
118
|
+
getStats(): {
|
|
119
|
+
totalSerializations: number;
|
|
120
|
+
totalDeserializations: number;
|
|
121
|
+
serializationErrors: number;
|
|
122
|
+
deserializationErrors: number;
|
|
123
|
+
averageSerializationTime: number;
|
|
124
|
+
averageDeserializationTime: number;
|
|
125
|
+
formatUsage: Record<string, number>;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Reset serializer statistics
|
|
129
|
+
*/
|
|
130
|
+
resetStats(): void;
|
|
131
|
+
/**
|
|
132
|
+
* Health check for the serializer
|
|
133
|
+
*/
|
|
134
|
+
healthCheck(): {
|
|
135
|
+
healthy: boolean;
|
|
136
|
+
message?: string;
|
|
137
|
+
details?: Record<string, unknown>;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Serializer factory interface
|
|
142
|
+
*/
|
|
143
|
+
export interface ISerializerFactory {
|
|
144
|
+
/**
|
|
145
|
+
* Create a new serializer instance
|
|
146
|
+
* @param name Serializer name
|
|
147
|
+
* @param config Serializer configuration
|
|
148
|
+
* @returns New serializer instance
|
|
149
|
+
*/
|
|
150
|
+
create(name: string, config?: Partial<SerializationConfig>): ISerializer;
|
|
151
|
+
/**
|
|
152
|
+
* Get an existing serializer instance
|
|
153
|
+
* @param name Serializer name
|
|
154
|
+
*/
|
|
155
|
+
get(name: string): ISerializer | undefined;
|
|
156
|
+
/**
|
|
157
|
+
* Get all serializer instances
|
|
158
|
+
*/
|
|
159
|
+
getAll(): ISerializer[];
|
|
160
|
+
/**
|
|
161
|
+
* Register a custom serializer
|
|
162
|
+
* @param name Serializer name
|
|
163
|
+
* @param serializer Serializer instance or constructor
|
|
164
|
+
*/
|
|
165
|
+
register(name: string, serializer: ISerializer | (new (config: SerializationConfig) => ISerializer)): void;
|
|
166
|
+
/**
|
|
167
|
+
* Get available serializer names
|
|
168
|
+
*/
|
|
169
|
+
getAvailableSerializers(): string[];
|
|
170
|
+
/**
|
|
171
|
+
* Get serializer for a specific format
|
|
172
|
+
* @param format Format
|
|
173
|
+
* @returns Serializer or undefined
|
|
174
|
+
*/
|
|
175
|
+
getSerializerForFormat(format: SerializationFormat): ISerializer | undefined;
|
|
176
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service discovery interface for communication layer
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
import type { ServiceDiscoveryEvent } from '../types/events.js';
|
|
6
|
+
import type { HealthCheckResult, ServiceDiscoveryResult, ServiceInstance, ServiceInstanceFilter, ServiceRegistration, ServiceRegistryConfig, UnwatchFunction, WatchCallback } from '../types/service.js';
|
|
7
|
+
/**
|
|
8
|
+
* Service discovery interface for discovering and monitoring service instances
|
|
9
|
+
*/
|
|
10
|
+
export interface IServiceDiscoverer {
|
|
11
|
+
/** Discovery type (kubernetes, consul, etc.) */
|
|
12
|
+
readonly type: string;
|
|
13
|
+
/** Discovery configuration */
|
|
14
|
+
readonly config: ServiceRegistryConfig;
|
|
15
|
+
/** Whether discovery is currently active */
|
|
16
|
+
readonly isActive: boolean;
|
|
17
|
+
/** Last discovery timestamp */
|
|
18
|
+
readonly lastDiscoveryTime?: number;
|
|
19
|
+
/** Total services discovered */
|
|
20
|
+
readonly totalServicesDiscovered: number;
|
|
21
|
+
/** Total instances discovered */
|
|
22
|
+
readonly totalInstancesDiscovered: number;
|
|
23
|
+
/**
|
|
24
|
+
* Resolve service instances for a given service name
|
|
25
|
+
* @param serviceName Service name to resolve
|
|
26
|
+
* @param filter Optional filter for instances
|
|
27
|
+
* @returns Promise resolving to service discovery result
|
|
28
|
+
* @throws {CommunicationError} If discovery fails
|
|
29
|
+
*/
|
|
30
|
+
resolve(serviceName: string, filter?: ServiceInstanceFilter): Promise<ServiceDiscoveryResult>;
|
|
31
|
+
/**
|
|
32
|
+
* Resolve all instances for multiple services
|
|
33
|
+
* @param serviceNames Array of service names
|
|
34
|
+
* @returns Promise resolving to map of service names to instances
|
|
35
|
+
*/
|
|
36
|
+
resolveAll(serviceNames: string[]): Promise<Map<string, ServiceInstance[]>>;
|
|
37
|
+
/**
|
|
38
|
+
* Watch for changes to service instances
|
|
39
|
+
* @param serviceName Service name to watch
|
|
40
|
+
* @param callback Callback function for changes
|
|
41
|
+
* @returns Unwatch function
|
|
42
|
+
*/
|
|
43
|
+
watch(serviceName: string, callback: WatchCallback): UnwatchFunction;
|
|
44
|
+
/**
|
|
45
|
+
* Stop watching a service
|
|
46
|
+
* @param serviceName Service name to stop watching
|
|
47
|
+
*/
|
|
48
|
+
unwatch(serviceName: string): void;
|
|
49
|
+
/**
|
|
50
|
+
* Stop watching all services
|
|
51
|
+
*/
|
|
52
|
+
unwatchAll(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Register a service instance
|
|
55
|
+
* @param registration Service registration information
|
|
56
|
+
* @returns Promise resolving when registration is complete
|
|
57
|
+
*/
|
|
58
|
+
register?(registration: ServiceRegistration): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Deregister a service instance
|
|
61
|
+
* @param serviceId Service instance ID
|
|
62
|
+
* @returns Promise resolving when deregistration is complete
|
|
63
|
+
*/
|
|
64
|
+
deregister?(serviceId: string): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Update service instance registration
|
|
67
|
+
* @param serviceId Service instance ID
|
|
68
|
+
* @param updates Registration updates
|
|
69
|
+
* @returns Promise resolving when update is complete
|
|
70
|
+
*/
|
|
71
|
+
updateRegistration?(serviceId: string, updates: Partial<ServiceRegistration>): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Perform health check on service instances
|
|
74
|
+
* @param serviceName Optional service name to check
|
|
75
|
+
* @returns Promise resolving to health check results
|
|
76
|
+
*/
|
|
77
|
+
healthCheck(serviceName?: string): Promise<Map<string, HealthCheckResult[]>>;
|
|
78
|
+
/**
|
|
79
|
+
* Get cached service instances
|
|
80
|
+
* @param serviceName Service name
|
|
81
|
+
* @returns Cached instances or empty array
|
|
82
|
+
*/
|
|
83
|
+
getCachedInstances(serviceName: string): ServiceInstance[];
|
|
84
|
+
/**
|
|
85
|
+
* Clear cache for a service
|
|
86
|
+
* @param serviceName Service name
|
|
87
|
+
*/
|
|
88
|
+
clearCache(serviceName?: string): void;
|
|
89
|
+
/**
|
|
90
|
+
* Refresh cache for a service
|
|
91
|
+
* @param serviceName Service name
|
|
92
|
+
* @returns Promise resolving when cache is refreshed
|
|
93
|
+
*/
|
|
94
|
+
refreshCache(serviceName?: string): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Start automatic discovery (for poll-based discoverers)
|
|
97
|
+
*/
|
|
98
|
+
start?(): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Stop automatic discovery
|
|
101
|
+
*/
|
|
102
|
+
stop?(): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Get service discovery statistics
|
|
105
|
+
*/
|
|
106
|
+
getStats(): {
|
|
107
|
+
totalResolves: number;
|
|
108
|
+
totalWatches: number;
|
|
109
|
+
cacheHits: number;
|
|
110
|
+
cacheMisses: number;
|
|
111
|
+
cacheHitRate: number;
|
|
112
|
+
averageResolveTime: number;
|
|
113
|
+
lastError?: string;
|
|
114
|
+
uptime: number;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Reset service discovery statistics
|
|
118
|
+
*/
|
|
119
|
+
resetStats(): void;
|
|
120
|
+
/**
|
|
121
|
+
* Update service discovery configuration
|
|
122
|
+
* @param config New configuration
|
|
123
|
+
*/
|
|
124
|
+
updateConfig(config: Partial<ServiceRegistryConfig>): void;
|
|
125
|
+
/**
|
|
126
|
+
* Health check for the service discoverer itself
|
|
127
|
+
*/
|
|
128
|
+
healthCheckSelf(): Promise<{
|
|
129
|
+
healthy: boolean;
|
|
130
|
+
message?: string;
|
|
131
|
+
details?: Record<string, unknown>;
|
|
132
|
+
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Close/cleanup service discovery resources
|
|
135
|
+
*/
|
|
136
|
+
close(): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Event emitter for service discovery events
|
|
139
|
+
*/
|
|
140
|
+
readonly events?: {
|
|
141
|
+
/**
|
|
142
|
+
* Subscribe to service discovery events
|
|
143
|
+
* @param event Event name or array of events
|
|
144
|
+
* @param listener Event listener
|
|
145
|
+
*/
|
|
146
|
+
on(event: string | string[], listener: (event: ServiceDiscoveryEvent) => void): void;
|
|
147
|
+
/**
|
|
148
|
+
* Unsubscribe from service discovery events
|
|
149
|
+
* @param event Event name or array of events
|
|
150
|
+
* @param listener Event listener
|
|
151
|
+
*/
|
|
152
|
+
off(event: string | string[], listener: (event: ServiceDiscoveryEvent) => void): void;
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Service discovery factory interface
|
|
157
|
+
*/
|
|
158
|
+
export interface IServiceDiscoveryFactory {
|
|
159
|
+
/**
|
|
160
|
+
* Create a new service discoverer instance
|
|
161
|
+
* @param type Discovery type
|
|
162
|
+
* @param config Discovery configuration
|
|
163
|
+
* @returns New service discoverer instance
|
|
164
|
+
*/
|
|
165
|
+
create(type: string, config: ServiceRegistryConfig): IServiceDiscoverer;
|
|
166
|
+
/**
|
|
167
|
+
* Get an existing service discoverer instance
|
|
168
|
+
* @param id Discoverer identifier
|
|
169
|
+
*/
|
|
170
|
+
get(id: string): IServiceDiscoverer | undefined;
|
|
171
|
+
/**
|
|
172
|
+
* Get all service discoverer instances
|
|
173
|
+
*/
|
|
174
|
+
getAll(): IServiceDiscoverer[];
|
|
175
|
+
/**
|
|
176
|
+
* Register a custom service discoverer type
|
|
177
|
+
* @param type Discoverer type name
|
|
178
|
+
* @param constructor Discoverer constructor
|
|
179
|
+
*/
|
|
180
|
+
register(type: string, constructor: new (config: ServiceRegistryConfig) => IServiceDiscoverer): void;
|
|
181
|
+
/**
|
|
182
|
+
* Get available service discoverer types
|
|
183
|
+
*/
|
|
184
|
+
getAvailableTypes(): string[];
|
|
185
|
+
/**
|
|
186
|
+
* Close all service discoverer instances
|
|
187
|
+
*/
|
|
188
|
+
closeAll(): Promise<void>;
|
|
189
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timeout interface for communication layer
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
import type { TimeoutConfig } from '../types/config.js';
|
|
6
|
+
/**
|
|
7
|
+
* Timeout options for individual operations
|
|
8
|
+
*/
|
|
9
|
+
export interface TimeoutOptions {
|
|
10
|
+
/** Operation timeout in milliseconds */
|
|
11
|
+
timeout?: number;
|
|
12
|
+
/** Operation name for logging */
|
|
13
|
+
name?: string;
|
|
14
|
+
/** Should throw on timeout */
|
|
15
|
+
throwOnTimeout?: boolean;
|
|
16
|
+
/** Cleanup function to call on timeout */
|
|
17
|
+
cleanup?: () => void | Promise<void>;
|
|
18
|
+
/** Custom error message */
|
|
19
|
+
errorMessage?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Timeout manager interface
|
|
23
|
+
*/
|
|
24
|
+
export interface ITimeoutManager {
|
|
25
|
+
/** Timeout configuration */
|
|
26
|
+
readonly config: TimeoutConfig;
|
|
27
|
+
/**
|
|
28
|
+
* Execute a function with timeout
|
|
29
|
+
* @param fn Function to execute
|
|
30
|
+
* @param options Timeout options
|
|
31
|
+
* @returns Promise resolving to function result
|
|
32
|
+
* @throws {CommunicationError} If timeout occurs
|
|
33
|
+
*/
|
|
34
|
+
execute<T>(fn: () => Promise<T>, options?: TimeoutOptions): Promise<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Create a timeout promise
|
|
37
|
+
* @param timeout Timeout in milliseconds
|
|
38
|
+
* @param message Error message
|
|
39
|
+
* @returns Promise that rejects after timeout
|
|
40
|
+
*/
|
|
41
|
+
createTimeout(timeout: number, message?: string): Promise<never>;
|
|
42
|
+
/**
|
|
43
|
+
* Create an abort signal for timeout
|
|
44
|
+
* @param timeout Timeout in milliseconds
|
|
45
|
+
* @returns AbortSignal
|
|
46
|
+
*/
|
|
47
|
+
createAbortSignal(timeout: number): AbortSignal;
|
|
48
|
+
/**
|
|
49
|
+
* Execute multiple promises with timeout
|
|
50
|
+
* @param promises Array of promises
|
|
51
|
+
* @param timeout Timeout in milliseconds
|
|
52
|
+
* @returns Promise that resolves when first promise resolves or times out
|
|
53
|
+
*/
|
|
54
|
+
race<T>(promises: Promise<T>[], timeout: number): Promise<T>;
|
|
55
|
+
/**
|
|
56
|
+
* Delay execution for specified time
|
|
57
|
+
* @param delay Delay in milliseconds
|
|
58
|
+
* @returns Promise that resolves after delay
|
|
59
|
+
*/
|
|
60
|
+
delay(delay: number): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Set operation timeout
|
|
63
|
+
* @param operation Operation identifier
|
|
64
|
+
* @param timeout Timeout in milliseconds
|
|
65
|
+
*/
|
|
66
|
+
setOperationTimeout(operation: string, timeout: number): void;
|
|
67
|
+
/**
|
|
68
|
+
* Get operation timeout
|
|
69
|
+
* @param operation Operation identifier
|
|
70
|
+
* @returns Timeout in milliseconds or undefined
|
|
71
|
+
*/
|
|
72
|
+
getOperationTimeout(operation: string): number | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Update timeout configuration
|
|
75
|
+
* @param config New configuration
|
|
76
|
+
*/
|
|
77
|
+
updateConfig(config: Partial<TimeoutConfig>): void;
|
|
78
|
+
/**
|
|
79
|
+
* Get timeout statistics
|
|
80
|
+
*/
|
|
81
|
+
getStats(): {
|
|
82
|
+
totalOperations: number;
|
|
83
|
+
timedOutOperations: number;
|
|
84
|
+
averageOperationTime: number;
|
|
85
|
+
timeoutRate: number;
|
|
86
|
+
perOperationStats: Record<string, {
|
|
87
|
+
calls: number;
|
|
88
|
+
timeouts: number;
|
|
89
|
+
averageTime: number;
|
|
90
|
+
}>;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Reset timeout statistics
|
|
94
|
+
*/
|
|
95
|
+
resetStats(): void;
|
|
96
|
+
/**
|
|
97
|
+
* Health check for timeout manager
|
|
98
|
+
*/
|
|
99
|
+
healthCheck(): {
|
|
100
|
+
healthy: boolean;
|
|
101
|
+
message?: string;
|
|
102
|
+
details?: Record<string, unknown>;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Timeout manager factory interface
|
|
107
|
+
*/
|
|
108
|
+
export interface ITimeoutManagerFactory {
|
|
109
|
+
/**
|
|
110
|
+
* Create a new timeout manager instance
|
|
111
|
+
* @param name Timeout manager name
|
|
112
|
+
* @param config Timeout configuration
|
|
113
|
+
* @returns New timeout manager instance
|
|
114
|
+
*/
|
|
115
|
+
create(name: string, config?: Partial<TimeoutConfig>): ITimeoutManager;
|
|
116
|
+
/**
|
|
117
|
+
* Get an existing timeout manager instance
|
|
118
|
+
* @param name Timeout manager name
|
|
119
|
+
*/
|
|
120
|
+
get(name: string): ITimeoutManager | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* Get all timeout manager instances
|
|
123
|
+
*/
|
|
124
|
+
getAll(): ITimeoutManager[];
|
|
125
|
+
/**
|
|
126
|
+
* Register a custom timeout manager
|
|
127
|
+
* @param name Timeout manager name
|
|
128
|
+
* @param manager Timeout manager instance or constructor
|
|
129
|
+
*/
|
|
130
|
+
register(name: string, manager: ITimeoutManager | (new (config: TimeoutConfig) => ITimeoutManager)): void;
|
|
131
|
+
/**
|
|
132
|
+
* Get available timeout manager names
|
|
133
|
+
*/
|
|
134
|
+
getAvailableManagers(): string[];
|
|
135
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface definitions for communication layer
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
export type { IProtocol, IProtocolFactory, } from './Protocol.interface.js';
|
|
6
|
+
export type { IClient, IClientFactory, } from './Client.interface.js';
|
|
7
|
+
export type { ICircuitBreaker, ICircuitBreakerFactory, } from './CircuitBreaker.interface.js';
|
|
8
|
+
export type { IRetryStrategy, IRetryStrategyFactory, RetryDecision, RetryContext, } from './RetryStrategy.interface.js';
|
|
9
|
+
export type { IServiceDiscoverer, IServiceDiscoveryFactory, } from './ServiceDiscovery.interface.js';
|
|
10
|
+
export type { ILoadBalanceStrategy, ILoadBalancerFactory, } from './LoadBalancer.interface.js';
|
|
11
|
+
export type { ISerializer, ISerializerFactory, SerializationContext, DeserializationContext, } from './Serializer.interface.js';
|
|
12
|
+
export type { IInterceptor, IInterceptorChain, IInterceptorFactory, InterceptorOrder, } from './Interceptor.interface.js';
|
|
13
|
+
export type { ITimeoutManager, ITimeoutManagerFactory, TimeoutOptions, } from './Timeout.interface.js';
|
|
14
|
+
export type { IConnection, IConnectionPool, IConnectionPoolFactory, ConnectionAcquisition, } from './ConnectionPool.interface.js';
|
|
15
|
+
export type { ICompressionManager, ICompressionManagerFactory, CompressionAlgorithm, CompressionOptions, CompressionResult, DecompressionResult, } from './Compression.interface.js';
|