@hkdigital/lib-sveltekit 0.2.13 → 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.
@@ -0,0 +1,4 @@
1
+ export { default as ServiceBase } from "./ServiceBase.js";
2
+ export { default as ServiceManager } from "./ServiceManager.js";
3
+ export * from "./service-states.js";
4
+ export * from "./typedef.js";
@@ -0,0 +1,5 @@
1
+ export { default as ServiceBase } from './ServiceBase.js';
2
+ export { default as ServiceManager } from './ServiceManager.js';
3
+
4
+ export * from './service-states.js';
5
+ export * from './typedef.js';
@@ -1,40 +1,12 @@
1
1
  /**
2
- * //
2
+ * Service configuration object passed to service initialization
3
3
  */
4
- export type ServiceConfig = import("./typedef.js").ServiceConfig;
5
- /**
6
- * class MyService extends ServiceBase {
7
- * async _init(config) {
8
- * // config is typed as ServiceConfig
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]: any;
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 {*} [*] - Service-specific configuration properties
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 {*} [*] - Additional health check properties
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-sveltekit",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"