@hkdigital/lib-sveltekit 0.2.12 → 0.2.14
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/ServiceManager.d.ts +1 -1
- package/dist/classes/services/ServiceManager.js +7 -6
- package/dist/classes/services/index.d.ts +4 -0
- package/dist/classes/services/index.js +5 -0
- package/dist/classes/services/typedef.d.ts +80 -37
- package/dist/classes/services/typedef.js +7 -7
- package/package.json +1 -1
@@ -13,7 +13,7 @@
|
|
13
13
|
* import AuthService from './services/AuthService.js';
|
14
14
|
*
|
15
15
|
* const manager = new ServiceManager({
|
16
|
-
*
|
16
|
+
* debug: true,
|
17
17
|
* stopTimeout: 10000
|
18
18
|
* });
|
19
19
|
*
|
@@ -103,7 +103,7 @@ export class ServiceManager extends EventEmitter {
|
|
103
103
|
|
104
104
|
/** @type {ServiceManagerConfig} */
|
105
105
|
this.config = {
|
106
|
-
|
106
|
+
debug: config.debug ?? false,
|
107
107
|
autoStart: config.autoStart ?? false,
|
108
108
|
stopTimeout: config.stopTimeout || 10000,
|
109
109
|
logConfig: config.logConfig || {}
|
@@ -449,7 +449,8 @@ export class ServiceManager extends EventEmitter {
|
|
449
449
|
this.config.logConfig.globalLevel = level;
|
450
450
|
|
451
451
|
// Apply to all existing services
|
452
|
-
|
452
|
+
// eslint-disable-next-line no-unused-vars
|
453
|
+
for (const [_, entry] of this.services) {
|
453
454
|
if (entry.instance) {
|
454
455
|
entry.instance.setLogLevel(level);
|
455
456
|
}
|
@@ -489,13 +490,13 @@ export class ServiceManager extends EventEmitter {
|
|
489
490
|
// Private methods
|
490
491
|
|
491
492
|
/**
|
492
|
-
* Setup logging configuration based on
|
493
|
+
* Setup logging configuration based on config.dev
|
493
494
|
*
|
494
495
|
* @private
|
495
496
|
*/
|
496
497
|
_setupLogging() {
|
497
|
-
// Set default log levels based on
|
498
|
-
if (this.config.
|
498
|
+
// Set default log levels based on config.debug flag
|
499
|
+
if (this.config.debug) {
|
499
500
|
this.config.logConfig.defaultLevel = DEBUG;
|
500
501
|
} else {
|
501
502
|
this.config.logConfig.defaultLevel = WARN;
|
@@ -1,40 +1,12 @@
|
|
1
1
|
/**
|
2
|
-
*
|
2
|
+
* Service configuration object passed to service initialization
|
3
3
|
*/
|
4
|
-
export type ServiceConfig =
|
5
|
-
/**
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
*
|
11
|
-
* async _healthCheck() {
|
12
|
-
* // Return type is HealthStatus
|
13
|
-
* return { latency: 10 };
|
14
|
-
* }
|
15
|
-
* }
|
16
|
-
*/
|
17
|
-
export type HealthStatus = import("./typedef.js").HealthStatus;
|
18
|
-
/**
|
19
|
-
* //
|
20
|
-
*/
|
21
|
-
export type ServiceManagerConfig = import("./typedef.js").ServiceManagerConfig;
|
22
|
-
/**
|
23
|
-
* const config = {
|
24
|
-
* environment: 'development',
|
25
|
-
* stopTimeout: 5000
|
26
|
-
* };
|
27
|
-
*
|
28
|
-
* const manager = new ServiceManager(config);
|
29
|
-
*
|
30
|
-
* const options = {
|
31
|
-
* dependencies: ['database'],
|
32
|
-
* tags: ['critical']
|
33
|
-
* };
|
34
|
-
*
|
35
|
-
* manager.register('auth', AuthService, {}, options);
|
36
|
-
*/
|
37
|
-
export type ServiceRegistrationOptions = import("./typedef.js").ServiceRegistrationOptions;
|
4
|
+
export type ServiceConfig = {
|
5
|
+
/**
|
6
|
+
* - Service-specific configuration properties
|
7
|
+
*/
|
8
|
+
key?: any;
|
9
|
+
};
|
38
10
|
/**
|
39
11
|
* Options for creating a service instance
|
40
12
|
*/
|
@@ -61,6 +33,35 @@ export type StopOptions = {
|
|
61
33
|
*/
|
62
34
|
force?: boolean;
|
63
35
|
};
|
36
|
+
/**
|
37
|
+
* Health status returned by service health checks
|
38
|
+
*/
|
39
|
+
export type HealthStatus = {
|
40
|
+
/**
|
41
|
+
* - Service name
|
42
|
+
*/
|
43
|
+
name: string;
|
44
|
+
/**
|
45
|
+
* - Current service state
|
46
|
+
*/
|
47
|
+
state: string;
|
48
|
+
/**
|
49
|
+
* - Whether the service is healthy
|
50
|
+
*/
|
51
|
+
healthy: boolean;
|
52
|
+
/**
|
53
|
+
* - Error message if unhealthy
|
54
|
+
*/
|
55
|
+
error?: string;
|
56
|
+
/**
|
57
|
+
* - Error from health check itself
|
58
|
+
*/
|
59
|
+
checkError?: string;
|
60
|
+
/**
|
61
|
+
* - Additional health check properties
|
62
|
+
*/
|
63
|
+
key?: any;
|
64
|
+
};
|
64
65
|
/**
|
65
66
|
* Event emitted when service state changes
|
66
67
|
*/
|
@@ -112,6 +113,48 @@ export type ServiceErrorEvent = {
|
|
112
113
|
* Service class constructor type
|
113
114
|
*/
|
114
115
|
export type ServiceConstructor = new (name: string, options?: ServiceOptions) => ServiceBase;
|
116
|
+
/**
|
117
|
+
* Options for registering a service
|
118
|
+
*/
|
119
|
+
export type ServiceRegistrationOptions = {
|
120
|
+
/**
|
121
|
+
* - Services this service depends on
|
122
|
+
*/
|
123
|
+
dependencies?: string[];
|
124
|
+
/**
|
125
|
+
* - Tags for grouping services
|
126
|
+
*/
|
127
|
+
tags?: string[];
|
128
|
+
/**
|
129
|
+
* - Startup priority (higher starts first)
|
130
|
+
*/
|
131
|
+
priority?: number;
|
132
|
+
};
|
133
|
+
/**
|
134
|
+
* Configuration for ServiceManager
|
135
|
+
*/
|
136
|
+
export type ServiceManagerConfig = {
|
137
|
+
/**
|
138
|
+
* - Runtime environment
|
139
|
+
*/
|
140
|
+
environment?: string;
|
141
|
+
/**
|
142
|
+
* - Auto-start services on registration
|
143
|
+
*/
|
144
|
+
autoStart?: boolean;
|
145
|
+
/**
|
146
|
+
* - Default timeout for stopping services
|
147
|
+
*/
|
148
|
+
stopTimeout?: number;
|
149
|
+
/**
|
150
|
+
* - Initial log level for ServiceManager
|
151
|
+
*/
|
152
|
+
logLevel?: string;
|
153
|
+
/**
|
154
|
+
* - Logging configuration
|
155
|
+
*/
|
156
|
+
logConfig?: LogConfig;
|
157
|
+
};
|
115
158
|
/**
|
116
159
|
* Logging configuration
|
117
160
|
*/
|
@@ -168,7 +211,7 @@ export type ServiceEntry = {
|
|
168
211
|
* Result of health check for all services
|
169
212
|
*/
|
170
213
|
export type HealthCheckResult = {
|
171
|
-
[x: string]:
|
214
|
+
[x: string]: HealthStatus;
|
172
215
|
};
|
173
216
|
/**
|
174
217
|
* Base class interface that services must implement
|
@@ -193,7 +236,7 @@ export type ServiceBase = {
|
|
193
236
|
/**
|
194
237
|
* - Service logger
|
195
238
|
*/
|
196
|
-
logger: Logger;
|
239
|
+
logger: import("../logging").Logger;
|
197
240
|
initialize: (config?: ServiceConfig) => Promise<boolean>;
|
198
241
|
start: () => Promise<boolean>;
|
199
242
|
stop: (options?: StopOptions) => Promise<boolean>;
|
@@ -9,8 +9,8 @@
|
|
9
9
|
* // In your service implementation
|
10
10
|
* import { ServiceBase } from './ServiceBase.js';
|
11
11
|
*
|
12
|
-
* // @typedef {import('./typedef.js').ServiceConfig} ServiceConfig
|
13
|
-
* // @typedef {import('./typedef.js').HealthStatus} HealthStatus
|
12
|
+
* // @ typedef {import('./typedef.js').ServiceConfig} ServiceConfig
|
13
|
+
* // @ typedef {import('./typedef.js').HealthStatus} HealthStatus
|
14
14
|
*
|
15
15
|
* class MyService extends ServiceBase {
|
16
16
|
* async _init(config) {
|
@@ -27,8 +27,8 @@
|
|
27
27
|
* // When using ServiceManager
|
28
28
|
* import { ServiceManager } from './ServiceManager.js';
|
29
29
|
*
|
30
|
-
* // @typedef {import('./typedef.js').ServiceManagerConfig} ServiceManagerConfig
|
31
|
-
* // @typedef {import('./typedef.js').ServiceRegistrationOptions} ServiceRegistrationOptions
|
30
|
+
* // @ typedef {import('./typedef.js').ServiceManagerConfig} ServiceManagerConfig
|
31
|
+
* // @ typedef {import('./typedef.js').ServiceRegistrationOptions} ServiceRegistrationOptions
|
32
32
|
*
|
33
33
|
* const config = {
|
34
34
|
* environment: 'development',
|
@@ -48,7 +48,7 @@
|
|
48
48
|
/**
|
49
49
|
* Service configuration object passed to service initialization
|
50
50
|
* @typedef {Object} ServiceConfig
|
51
|
-
* @property {*} [
|
51
|
+
* @property {*} [key] - Service-specific configuration properties
|
52
52
|
*/
|
53
53
|
|
54
54
|
/**
|
@@ -73,7 +73,7 @@
|
|
73
73
|
* @property {boolean} healthy - Whether the service is healthy
|
74
74
|
* @property {string} [error] - Error message if unhealthy
|
75
75
|
* @property {string} [checkError] - Error from health check itself
|
76
|
-
* @property {*} [
|
76
|
+
* @property {*} [key] - Additional health check properties
|
77
77
|
*/
|
78
78
|
|
79
79
|
/**
|
@@ -154,7 +154,7 @@
|
|
154
154
|
* @property {string} state - Current state
|
155
155
|
* @property {boolean} healthy - Health status
|
156
156
|
* @property {Error|null} error - Last error
|
157
|
-
* @property {Logger} logger - Service logger
|
157
|
+
* @property {import('../logging').Logger} logger - Service logger
|
158
158
|
* @property {(config?: ServiceConfig) => Promise<boolean>} initialize
|
159
159
|
* @property {() => Promise<boolean>} start
|
160
160
|
* @property {(options?: StopOptions) => Promise<boolean>} stop
|