@hkdigital/lib-sveltekit 0.2.11 → 0.2.13
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/classes/services/ServiceBase.d.ts +83 -73
- package/dist/classes/services/ServiceBase.js +237 -181
- package/dist/classes/services/ServiceManager.d.ts +96 -267
- package/dist/classes/services/ServiceManager.js +368 -874
- package/dist/classes/services/_old/ServiceBase.d.ts +153 -0
- package/dist/classes/services/_old/ServiceBase.js +409 -0
- package/dist/classes/services/_old/ServiceManager.d.ts +350 -0
- package/dist/classes/services/_old/ServiceManager.js +1114 -0
- package/dist/classes/services/service-states.d.ts +154 -0
- package/dist/classes/services/service-states.js +199 -0
- package/dist/classes/services/typedef.d.ts +206 -0
- package/dist/classes/services/typedef.js +169 -0
- package/package.json +1 -1
- /package/dist/classes/services/{constants.d.ts → _old/constants.d.ts} +0 -0
- /package/dist/classes/services/{constants.js → _old/constants.js} +0 -0
- /package/dist/classes/services/{index.d.ts → _old/index.d.ts} +0 -0
- /package/dist/classes/services/{index.js → _old/index.js} +0 -0
@@ -0,0 +1,169 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview Type definitions for the service management system.
|
3
|
+
*
|
4
|
+
* This file contains all TypeScript/JSDoc type definitions used throughout
|
5
|
+
* the service management system. Import these types in your service
|
6
|
+
* implementations and when using the ServiceManager.
|
7
|
+
*
|
8
|
+
* @example
|
9
|
+
* // In your service implementation
|
10
|
+
* import { ServiceBase } from './ServiceBase.js';
|
11
|
+
*
|
12
|
+
* // @typedef {import('./typedef.js').ServiceConfig} ServiceConfig
|
13
|
+
* // @typedef {import('./typedef.js').HealthStatus} HealthStatus
|
14
|
+
*
|
15
|
+
* class MyService extends ServiceBase {
|
16
|
+
* async _init(config) {
|
17
|
+
* // config is typed as ServiceConfig
|
18
|
+
* }
|
19
|
+
*
|
20
|
+
* async _healthCheck() {
|
21
|
+
* // Return type is HealthStatus
|
22
|
+
* return { latency: 10 };
|
23
|
+
* }
|
24
|
+
* }
|
25
|
+
*
|
26
|
+
* @example
|
27
|
+
* // When using ServiceManager
|
28
|
+
* import { ServiceManager } from './ServiceManager.js';
|
29
|
+
*
|
30
|
+
* // @typedef {import('./typedef.js').ServiceManagerConfig} ServiceManagerConfig
|
31
|
+
* // @typedef {import('./typedef.js').ServiceRegistrationOptions} ServiceRegistrationOptions
|
32
|
+
*
|
33
|
+
* const config = {
|
34
|
+
* environment: 'development',
|
35
|
+
* stopTimeout: 5000
|
36
|
+
* };
|
37
|
+
*
|
38
|
+
* const manager = new ServiceManager(config);
|
39
|
+
*
|
40
|
+
* const options = {
|
41
|
+
* dependencies: ['database'],
|
42
|
+
* tags: ['critical']
|
43
|
+
* };
|
44
|
+
*
|
45
|
+
* manager.register('auth', AuthService, {}, options);
|
46
|
+
*/
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Service configuration object passed to service initialization
|
50
|
+
* @typedef {Object} ServiceConfig
|
51
|
+
* @property {*} [*] - Service-specific configuration properties
|
52
|
+
*/
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Options for creating a service instance
|
56
|
+
* @typedef {Object} ServiceOptions
|
57
|
+
* @property {string} [logLevel] - Initial log level for the service
|
58
|
+
* @property {number} [shutdownTimeout=5000] - Timeout for graceful shutdown
|
59
|
+
*/
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Options for stopping a service
|
63
|
+
* @typedef {Object} StopOptions
|
64
|
+
* @property {number} [timeout] - Override shutdown timeout
|
65
|
+
* @property {boolean} [force=false] - Force stop even if timeout exceeded
|
66
|
+
*/
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Health status returned by service health checks
|
70
|
+
* @typedef {Object} HealthStatus
|
71
|
+
* @property {string} name - Service name
|
72
|
+
* @property {string} state - Current service state
|
73
|
+
* @property {boolean} healthy - Whether the service is healthy
|
74
|
+
* @property {string} [error] - Error message if unhealthy
|
75
|
+
* @property {string} [checkError] - Error from health check itself
|
76
|
+
* @property {*} [*] - Additional health check properties
|
77
|
+
*/
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Event emitted when service state changes
|
81
|
+
* @typedef {Object} StateChangeEvent
|
82
|
+
* @property {string} service - Service name
|
83
|
+
* @property {string} oldState - Previous state
|
84
|
+
* @property {string} newState - New state
|
85
|
+
*/
|
86
|
+
|
87
|
+
/**
|
88
|
+
* Event emitted when service health changes
|
89
|
+
* @typedef {Object} HealthChangeEvent
|
90
|
+
* @property {string} service - Service name
|
91
|
+
* @property {boolean} healthy - New health status
|
92
|
+
*/
|
93
|
+
|
94
|
+
/**
|
95
|
+
* Event emitted when service encounters an error
|
96
|
+
* @typedef {Object} ServiceErrorEvent
|
97
|
+
* @property {string} service - Service name
|
98
|
+
* @property {string} operation - Operation that failed
|
99
|
+
* @property {Error} error - Error that occurred
|
100
|
+
*/
|
101
|
+
|
102
|
+
/**
|
103
|
+
* Service class constructor type
|
104
|
+
* @typedef {new (name: string, options?: ServiceOptions) => ServiceBase} ServiceConstructor
|
105
|
+
*/
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Options for registering a service
|
109
|
+
* @typedef {Object} ServiceRegistrationOptions
|
110
|
+
* @property {string[]} [dependencies=[]] - Services this service depends on
|
111
|
+
* @property {string[]} [tags=[]] - Tags for grouping services
|
112
|
+
* @property {number} [priority=0] - Startup priority (higher starts first)
|
113
|
+
*/
|
114
|
+
|
115
|
+
/**
|
116
|
+
* Configuration for ServiceManager
|
117
|
+
* @typedef {Object} ServiceManagerConfig
|
118
|
+
* @property {string} [environment='production'] - Runtime environment
|
119
|
+
* @property {boolean} [autoStart=false] - Auto-start services on registration
|
120
|
+
* @property {number} [stopTimeout=10000] - Default timeout for stopping services
|
121
|
+
* @property {string} [logLevel] - Initial log level for ServiceManager
|
122
|
+
* @property {LogConfig} [logConfig={}] - Logging configuration
|
123
|
+
*/
|
124
|
+
|
125
|
+
/**
|
126
|
+
* Logging configuration
|
127
|
+
* @typedef {Object} LogConfig
|
128
|
+
* @property {string} [defaultLevel] - Default log level for services
|
129
|
+
* @property {string} [globalLevel] - Override level for all services
|
130
|
+
* @property {Object<string, string>} [serviceLevels] - Per-service log levels
|
131
|
+
*/
|
132
|
+
|
133
|
+
/**
|
134
|
+
* Internal service registry entry
|
135
|
+
* @typedef {Object} ServiceEntry
|
136
|
+
* @property {ServiceConstructor} ServiceClass - Service class constructor
|
137
|
+
* @property {ServiceBase|null} instance - Service instance (lazy-created)
|
138
|
+
* @property {ServiceConfig} config - Service configuration
|
139
|
+
* @property {string[]} dependencies - Service dependencies
|
140
|
+
* @property {Set<string>} dependents - Services that depend on this one
|
141
|
+
* @property {string[]} tags - Service tags
|
142
|
+
* @property {number} priority - Startup priority
|
143
|
+
*/
|
144
|
+
|
145
|
+
/**
|
146
|
+
* Result of health check for all services
|
147
|
+
* @typedef {Object<string, HealthStatus>} HealthCheckResult
|
148
|
+
*/
|
149
|
+
|
150
|
+
/**
|
151
|
+
* Base class interface that services must implement
|
152
|
+
* @typedef {Object} ServiceBase
|
153
|
+
* @property {string} name - Service name
|
154
|
+
* @property {string} state - Current state
|
155
|
+
* @property {boolean} healthy - Health status
|
156
|
+
* @property {Error|null} error - Last error
|
157
|
+
* @property {Logger} logger - Service logger
|
158
|
+
* @property {(config?: ServiceConfig) => Promise<boolean>} initialize
|
159
|
+
* @property {() => Promise<boolean>} start
|
160
|
+
* @property {(options?: StopOptions) => Promise<boolean>} stop
|
161
|
+
* @property {() => Promise<boolean>} recover
|
162
|
+
* @property {() => Promise<boolean>} destroy
|
163
|
+
* @property {() => Promise<HealthStatus>} getHealth
|
164
|
+
* @property {(level: string) => boolean} setLogLevel
|
165
|
+
* @property {(event: string, handler: Function) => Function} on
|
166
|
+
* @property {(event: string, data: any) => boolean} emit
|
167
|
+
*/
|
168
|
+
|
169
|
+
export {};
|
package/package.json
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|