@cepseudo/engine 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/LICENSE +21 -0
- package/README.md +209 -0
- package/dist/component_types.d.ts +92 -0
- package/dist/component_types.d.ts.map +1 -0
- package/dist/component_types.js +93 -0
- package/dist/component_types.js.map +1 -0
- package/dist/digital_twin_engine.d.ts +390 -0
- package/dist/digital_twin_engine.d.ts.map +1 -0
- package/dist/digital_twin_engine.js +1200 -0
- package/dist/digital_twin_engine.js.map +1 -0
- package/dist/endpoints.d.ts +45 -0
- package/dist/endpoints.d.ts.map +1 -0
- package/dist/endpoints.js +87 -0
- package/dist/endpoints.js.map +1 -0
- package/dist/error_handler.d.ts +20 -0
- package/dist/error_handler.d.ts.map +1 -0
- package/dist/error_handler.js +68 -0
- package/dist/error_handler.js.map +1 -0
- package/dist/global_assets_handler.d.ts +63 -0
- package/dist/global_assets_handler.d.ts.map +1 -0
- package/dist/global_assets_handler.js +127 -0
- package/dist/global_assets_handler.js.map +1 -0
- package/dist/graceful_shutdown.d.ts +44 -0
- package/dist/graceful_shutdown.d.ts.map +1 -0
- package/dist/graceful_shutdown.js +79 -0
- package/dist/graceful_shutdown.js.map +1 -0
- package/dist/health.d.ts +112 -0
- package/dist/health.d.ts.map +1 -0
- package/dist/health.js +190 -0
- package/dist/health.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/initializer.d.ts +62 -0
- package/dist/initializer.d.ts.map +1 -0
- package/dist/initializer.js +110 -0
- package/dist/initializer.js.map +1 -0
- package/dist/loader/component_loader.d.ts +133 -0
- package/dist/loader/component_loader.d.ts.map +1 -0
- package/dist/loader/component_loader.js +340 -0
- package/dist/loader/component_loader.js.map +1 -0
- package/dist/openapi/generator.d.ts +93 -0
- package/dist/openapi/generator.d.ts.map +1 -0
- package/dist/openapi/generator.js +293 -0
- package/dist/openapi/generator.js.map +1 -0
- package/dist/queue_manager.d.ts +87 -0
- package/dist/queue_manager.d.ts.map +1 -0
- package/dist/queue_manager.js +196 -0
- package/dist/queue_manager.js.map +1 -0
- package/dist/scheduler.d.ts +29 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +375 -0
- package/dist/scheduler.js.map +1 -0
- package/package.json +78 -0
package/dist/health.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { DatabaseAdapter } from '@cepseudo/database';
|
|
2
|
+
import type { QueueManager } from './queue_manager.js';
|
|
3
|
+
import type { StorageService } from '@cepseudo/storage';
|
|
4
|
+
/**
|
|
5
|
+
* Individual health check result
|
|
6
|
+
*/
|
|
7
|
+
export interface HealthCheck {
|
|
8
|
+
/** Status of the check */
|
|
9
|
+
status: 'up' | 'down';
|
|
10
|
+
/** Response latency in milliseconds */
|
|
11
|
+
latency?: number;
|
|
12
|
+
/** Error message if status is down */
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Component counts for health status
|
|
17
|
+
*/
|
|
18
|
+
export interface ComponentCounts {
|
|
19
|
+
collectors: number;
|
|
20
|
+
harvesters: number;
|
|
21
|
+
handlers: number;
|
|
22
|
+
assetsManagers: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Full health status response
|
|
26
|
+
*/
|
|
27
|
+
export interface HealthStatus {
|
|
28
|
+
/** Overall status */
|
|
29
|
+
status: 'healthy' | 'degraded' | 'unhealthy';
|
|
30
|
+
/** ISO timestamp of the check */
|
|
31
|
+
timestamp: string;
|
|
32
|
+
/** Process uptime in seconds */
|
|
33
|
+
uptime: number;
|
|
34
|
+
/** Package version if available */
|
|
35
|
+
version?: string;
|
|
36
|
+
/** Individual service checks */
|
|
37
|
+
checks: Record<string, HealthCheck>;
|
|
38
|
+
/** Component counts */
|
|
39
|
+
components?: ComponentCounts;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Custom health check function type
|
|
43
|
+
*/
|
|
44
|
+
export type HealthCheckFn = () => Promise<HealthCheck>;
|
|
45
|
+
/**
|
|
46
|
+
* Health checker with support for custom checks
|
|
47
|
+
*/
|
|
48
|
+
export declare class HealthChecker {
|
|
49
|
+
#private;
|
|
50
|
+
/**
|
|
51
|
+
* Register a custom health check
|
|
52
|
+
* @param name Unique name for the check
|
|
53
|
+
* @param checkFn Function that performs the check
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* healthChecker.registerCheck('external-api', async () => {
|
|
58
|
+
* try {
|
|
59
|
+
* await fetch('https://api.example.com/health')
|
|
60
|
+
* return { status: 'up' }
|
|
61
|
+
* } catch (error) {
|
|
62
|
+
* return { status: 'down', error: error.message }
|
|
63
|
+
* }
|
|
64
|
+
* })
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
registerCheck(name: string, checkFn: HealthCheckFn): void;
|
|
68
|
+
/**
|
|
69
|
+
* Remove a health check
|
|
70
|
+
* @param name Name of the check to remove
|
|
71
|
+
*/
|
|
72
|
+
removeCheck(name: string): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Get list of registered check names
|
|
75
|
+
*/
|
|
76
|
+
getCheckNames(): string[];
|
|
77
|
+
/**
|
|
78
|
+
* Set component counts for health status
|
|
79
|
+
*/
|
|
80
|
+
setComponentCounts(counts: ComponentCounts): void;
|
|
81
|
+
/**
|
|
82
|
+
* Set version for health status
|
|
83
|
+
*/
|
|
84
|
+
setVersion(version: string): void;
|
|
85
|
+
/**
|
|
86
|
+
* Perform all registered health checks
|
|
87
|
+
*/
|
|
88
|
+
performCheck(): Promise<HealthStatus>;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Create a database health check function
|
|
92
|
+
*/
|
|
93
|
+
export declare function createDatabaseCheck(db: DatabaseAdapter): HealthCheckFn;
|
|
94
|
+
/**
|
|
95
|
+
* Create a Redis health check function via QueueManager
|
|
96
|
+
*/
|
|
97
|
+
export declare function createRedisCheck(qm: QueueManager): HealthCheckFn;
|
|
98
|
+
/**
|
|
99
|
+
* Create a storage health check function
|
|
100
|
+
*/
|
|
101
|
+
export declare function createStorageCheck(storage: StorageService): HealthCheckFn;
|
|
102
|
+
/**
|
|
103
|
+
* Perform deep health check on all services (convenience function)
|
|
104
|
+
*/
|
|
105
|
+
export declare function performHealthCheck(database: DatabaseAdapter, queueManager?: QueueManager | null, storage?: StorageService, componentCounts?: ComponentCounts, version?: string): Promise<HealthStatus>;
|
|
106
|
+
/**
|
|
107
|
+
* Simple liveness check - always returns ok if process is running
|
|
108
|
+
*/
|
|
109
|
+
export declare function livenessCheck(): {
|
|
110
|
+
status: 'ok';
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=health.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../src/health.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAEvD;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,0BAA0B;IAC1B,MAAM,EAAE,IAAI,GAAG,MAAM,CAAA;IACrB,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,cAAc,EAAE,MAAM,CAAA;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,qBAAqB;IACrB,MAAM,EAAE,SAAS,GAAG,UAA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O,CAAC,YAAY,CAAC,CAsBvB;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI;IAAE,MAAM,EAAE,IAAI,CAAA;CAAE,CAEhD"}
|
package/dist/health.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Health checker with support for custom checks
|
|
3
|
+
*/
|
|
4
|
+
export class HealthChecker {
|
|
5
|
+
#checks = new Map();
|
|
6
|
+
#componentCounts;
|
|
7
|
+
#version;
|
|
8
|
+
/**
|
|
9
|
+
* Register a custom health check
|
|
10
|
+
* @param name Unique name for the check
|
|
11
|
+
* @param checkFn Function that performs the check
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* healthChecker.registerCheck('external-api', async () => {
|
|
16
|
+
* try {
|
|
17
|
+
* await fetch('https://api.example.com/health')
|
|
18
|
+
* return { status: 'up' }
|
|
19
|
+
* } catch (error) {
|
|
20
|
+
* return { status: 'down', error: error.message }
|
|
21
|
+
* }
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
registerCheck(name, checkFn) {
|
|
26
|
+
this.#checks.set(name, checkFn);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Remove a health check
|
|
30
|
+
* @param name Name of the check to remove
|
|
31
|
+
*/
|
|
32
|
+
removeCheck(name) {
|
|
33
|
+
return this.#checks.delete(name);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get list of registered check names
|
|
37
|
+
*/
|
|
38
|
+
getCheckNames() {
|
|
39
|
+
return Array.from(this.#checks.keys());
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Set component counts for health status
|
|
43
|
+
*/
|
|
44
|
+
setComponentCounts(counts) {
|
|
45
|
+
this.#componentCounts = counts;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Set version for health status
|
|
49
|
+
*/
|
|
50
|
+
setVersion(version) {
|
|
51
|
+
this.#version = version;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Perform all registered health checks
|
|
55
|
+
*/
|
|
56
|
+
async performCheck() {
|
|
57
|
+
const checks = {};
|
|
58
|
+
// Run all checks in parallel
|
|
59
|
+
const entries = Array.from(this.#checks.entries());
|
|
60
|
+
const results = await Promise.all(entries.map(async ([name, checkFn]) => {
|
|
61
|
+
const start = Date.now();
|
|
62
|
+
try {
|
|
63
|
+
const result = await checkFn();
|
|
64
|
+
return [name, { ...result, latency: result.latency ?? Date.now() - start }];
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
return [
|
|
68
|
+
name,
|
|
69
|
+
{
|
|
70
|
+
status: 'down',
|
|
71
|
+
latency: Date.now() - start,
|
|
72
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
73
|
+
}
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
}));
|
|
77
|
+
results.forEach(([name, result]) => {
|
|
78
|
+
checks[name] = result;
|
|
79
|
+
});
|
|
80
|
+
// Determine overall status
|
|
81
|
+
const allChecks = Object.values(checks);
|
|
82
|
+
const anyDown = allChecks.some(c => c.status === 'down');
|
|
83
|
+
const databaseDown = checks['database']?.status === 'down';
|
|
84
|
+
let status;
|
|
85
|
+
if (databaseDown) {
|
|
86
|
+
status = 'unhealthy';
|
|
87
|
+
}
|
|
88
|
+
else if (anyDown) {
|
|
89
|
+
status = 'degraded';
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
status = 'healthy';
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
status,
|
|
96
|
+
timestamp: new Date().toISOString(),
|
|
97
|
+
uptime: process.uptime(),
|
|
98
|
+
...(this.#version && { version: this.#version }),
|
|
99
|
+
checks,
|
|
100
|
+
...(this.#componentCounts && { components: this.#componentCounts })
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Create a database health check function
|
|
106
|
+
*/
|
|
107
|
+
export function createDatabaseCheck(db) {
|
|
108
|
+
return async () => {
|
|
109
|
+
const start = Date.now();
|
|
110
|
+
try {
|
|
111
|
+
// Use doesTableExists as a ping - it will fail if DB is unreachable
|
|
112
|
+
await db.doesTableExists('_health_check_ping');
|
|
113
|
+
return { status: 'up', latency: Date.now() - start };
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
return {
|
|
117
|
+
status: 'down',
|
|
118
|
+
latency: Date.now() - start,
|
|
119
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Create a Redis health check function via QueueManager
|
|
126
|
+
*/
|
|
127
|
+
export function createRedisCheck(qm) {
|
|
128
|
+
return async () => {
|
|
129
|
+
const start = Date.now();
|
|
130
|
+
try {
|
|
131
|
+
await qm.getQueueStats();
|
|
132
|
+
return { status: 'up', latency: Date.now() - start };
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
return {
|
|
136
|
+
status: 'down',
|
|
137
|
+
latency: Date.now() - start,
|
|
138
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Create a storage health check function
|
|
145
|
+
*/
|
|
146
|
+
export function createStorageCheck(storage) {
|
|
147
|
+
return async () => {
|
|
148
|
+
const start = Date.now();
|
|
149
|
+
try {
|
|
150
|
+
if ('checkConnection' in storage && typeof storage.checkConnection === 'function') {
|
|
151
|
+
await storage.checkConnection();
|
|
152
|
+
}
|
|
153
|
+
return { status: 'up', latency: Date.now() - start };
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
return {
|
|
157
|
+
status: 'down',
|
|
158
|
+
latency: Date.now() - start,
|
|
159
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Perform deep health check on all services (convenience function)
|
|
166
|
+
*/
|
|
167
|
+
export async function performHealthCheck(database, queueManager, storage, componentCounts, version) {
|
|
168
|
+
const checker = new HealthChecker();
|
|
169
|
+
checker.registerCheck('database', createDatabaseCheck(database));
|
|
170
|
+
if (queueManager) {
|
|
171
|
+
checker.registerCheck('redis', createRedisCheck(queueManager));
|
|
172
|
+
}
|
|
173
|
+
if (storage) {
|
|
174
|
+
checker.registerCheck('storage', createStorageCheck(storage));
|
|
175
|
+
}
|
|
176
|
+
if (componentCounts) {
|
|
177
|
+
checker.setComponentCounts(componentCounts);
|
|
178
|
+
}
|
|
179
|
+
if (version) {
|
|
180
|
+
checker.setVersion(version);
|
|
181
|
+
}
|
|
182
|
+
return checker.performCheck();
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Simple liveness check - always returns ok if process is running
|
|
186
|
+
*/
|
|
187
|
+
export function livenessCheck() {
|
|
188
|
+
return { status: 'ok' };
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=health.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.js","sourceRoot":"","sources":["../src/health.ts"],"names":[],"mappings":"AAiDA;;GAEG;AACH,MAAM,OAAO,aAAa;IACb,OAAO,GAAG,IAAI,GAAG,EAAyB,CAAA;IACnD,gBAAgB,CAAkB;IAClC,QAAQ,CAAS;IAEjB;;;;;;;;;;;;;;;;OAgBG;IACH,aAAa,CAAC,IAAY,EAAE,OAAsB;QAC9C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IACnC,CAAC;IAED;;;OAGG;IACH,WAAW,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACpC,CAAC;IAED;;OAEG;IACH,aAAa;QACT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twin_engine.js';
|
|
2
|
+
export type { EngineOptions, ComponentValidationResult } from './digital_twin_engine.js';
|
|
3
|
+
export { scheduleComponents } from './scheduler.js';
|
|
4
|
+
export { QueueManager } from './queue_manager.js';
|
|
5
|
+
export type { QueueConfig } from './queue_manager.js';
|
|
6
|
+
export { detectComponentType, isCollector, isHarvester, isHandler, isAssetsManager, isCustomTableManager, isActiveComponent } from './component_types.js';
|
|
7
|
+
export type { AnyComponent, ComponentTypeName, SchedulableComponent, ActiveComponent, ComponentTypeMap, LoadedComponents } from './component_types.js';
|
|
8
|
+
export { initializeComponents, initializeAssetsManagers } from './initializer.js';
|
|
9
|
+
export { exposeEndpoints } from './endpoints.js';
|
|
10
|
+
export { HealthChecker, createDatabaseCheck, createRedisCheck, createStorageCheck, performHealthCheck, livenessCheck } from './health.js';
|
|
11
|
+
export type { HealthCheckFn, HealthCheck, HealthStatus, ComponentCounts } from './health.js';
|
|
12
|
+
export { errorHandler, asyncHandler, notFoundHandler } from './error_handler.js';
|
|
13
|
+
export { setupGracefulShutdown } from './graceful_shutdown.js';
|
|
14
|
+
export type { ShutdownOptions } from './graceful_shutdown.js';
|
|
15
|
+
export { GlobalAssetsHandler } from './global_assets_handler.js';
|
|
16
|
+
export { loadComponents } from './loader/component_loader.js';
|
|
17
|
+
export type { LoadComponentsOptions, LoadComponentsResult } from './loader/component_loader.js';
|
|
18
|
+
export { OpenAPIGenerator } from './openapi/generator.js';
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,YAAY,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAA;AAGxF,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAGnD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAGrD,OAAO,EACH,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,SAAS,EACT,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACpB,MAAM,sBAAsB,CAAA;AAC7B,YAAY,EACR,YAAY,EACZ,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EACnB,MAAM,sBAAsB,CAAA;AAG7B,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAA;AAGjF,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAGhD,OAAO,EACH,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EAChB,MAAM,aAAa,CAAA;AACpB,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAG5F,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAGhF,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AAC9D,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAG7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAGhE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAA;AAG/F,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Engine
|
|
2
|
+
export { DigitalTwinEngine } from './digital_twin_engine.js';
|
|
3
|
+
// Scheduler
|
|
4
|
+
export { scheduleComponents } from './scheduler.js';
|
|
5
|
+
// Queue Manager
|
|
6
|
+
export { QueueManager } from './queue_manager.js';
|
|
7
|
+
// Component Types & Guards
|
|
8
|
+
export { detectComponentType, isCollector, isHarvester, isHandler, isAssetsManager, isCustomTableManager, isActiveComponent } from './component_types.js';
|
|
9
|
+
// Initializer
|
|
10
|
+
export { initializeComponents, initializeAssetsManagers } from './initializer.js';
|
|
11
|
+
// Endpoints
|
|
12
|
+
export { exposeEndpoints } from './endpoints.js';
|
|
13
|
+
// Health
|
|
14
|
+
export { HealthChecker, createDatabaseCheck, createRedisCheck, createStorageCheck, performHealthCheck, livenessCheck } from './health.js';
|
|
15
|
+
// Error Handler
|
|
16
|
+
export { errorHandler, asyncHandler, notFoundHandler } from './error_handler.js';
|
|
17
|
+
// Graceful Shutdown
|
|
18
|
+
export { setupGracefulShutdown } from './graceful_shutdown.js';
|
|
19
|
+
// Global Assets Handler
|
|
20
|
+
export { GlobalAssetsHandler } from './global_assets_handler.js';
|
|
21
|
+
// Component Loader
|
|
22
|
+
export { loadComponents } from './loader/component_loader.js';
|
|
23
|
+
// OpenAPI Generator
|
|
24
|
+
export { OpenAPIGenerator } from './openapi/generator.js';
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,SAAS;AACT,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAG5D,YAAY;AACZ,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAEnD,gBAAgB;AAChB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAGjD,2BAA2B;AAC3B,OAAO,EACH,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,SAAS,EACT,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACpB,MAAM,sBAAsB,CAAA;AAU7B,cAAc;AACd,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAA;AAEjF,YAAY;AACZ,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEhD,SAAS;AACT,OAAO,EACH,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EAChB,MAAM,aAAa,CAAA;AAGpB,gBAAgB;AAChB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEhF,oBAAoB;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AAG9D,wBAAwB;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAEhE,mBAAmB;AACnB,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAG7D,oBAAoB;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Component initialization utilities for the digital twin engine
|
|
3
|
+
*
|
|
4
|
+
* This module handles the setup and initialization of digital twin components,
|
|
5
|
+
* including database table creation and dependency injection.
|
|
6
|
+
*/
|
|
7
|
+
import type { Collector, Harvester } from '@cepseudo/components';
|
|
8
|
+
import type { AssetsManager } from '@cepseudo/assets';
|
|
9
|
+
import type { DatabaseAdapter } from '@cepseudo/database';
|
|
10
|
+
import type { StorageService } from '@cepseudo/storage';
|
|
11
|
+
import type { AuthMiddleware } from '@cepseudo/auth';
|
|
12
|
+
/**
|
|
13
|
+
* Initializes data collection and processing components with required dependencies.
|
|
14
|
+
*
|
|
15
|
+
* This function sets up collectors and harvesters by:
|
|
16
|
+
* 1. Creating necessary database tables for each component
|
|
17
|
+
* 2. Running automatic schema migrations if enabled
|
|
18
|
+
* 3. Injecting database and storage service dependencies
|
|
19
|
+
*
|
|
20
|
+
* @param components - Array of collectors and harvesters to initialize
|
|
21
|
+
* @param database - Database adapter instance for data storage
|
|
22
|
+
* @param storage - Storage service instance for file operations
|
|
23
|
+
* @param autoMigration - Enable automatic schema migration (default: true)
|
|
24
|
+
*
|
|
25
|
+
* @throws {Error} When database table creation fails
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const components = [weatherCollector, trafficHarvester];
|
|
30
|
+
* const database = new KnexDatabaseAdapter(config);
|
|
31
|
+
* const storage = new LocalStorageService();
|
|
32
|
+
*
|
|
33
|
+
* await initializeComponents(components, database, storage, true);
|
|
34
|
+
* // Components are now ready to process data
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function initializeComponents(components: Array<Collector | Harvester>, database: DatabaseAdapter, storage: StorageService, autoMigration?: boolean): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Initializes asset management components with required dependencies.
|
|
40
|
+
*
|
|
41
|
+
* Asset managers handle file-based resources (like 3D models, tilesets, maps)
|
|
42
|
+
* and require both database access for metadata and storage for file operations.
|
|
43
|
+
*
|
|
44
|
+
* @param assetsManagers - Array of asset managers to initialize
|
|
45
|
+
* @param database - Database adapter instance for metadata storage
|
|
46
|
+
* @param storage - Storage service instance for asset file operations
|
|
47
|
+
* @param autoMigration - Enable automatic schema migration (default: true)
|
|
48
|
+
*
|
|
49
|
+
* @throws {Error} When database table creation fails
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const managers = [tilesetManager, pointCloudManager];
|
|
54
|
+
* const database = new KnexDatabaseAdapter(config);
|
|
55
|
+
* const storage = new OvhS3StorageService(credentials);
|
|
56
|
+
*
|
|
57
|
+
* await initializeAssetsManagers(managers, database, storage, true);
|
|
58
|
+
* // Asset managers are now ready to handle file operations
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function initializeAssetsManagers(assetsManagers: AssetsManager[], database: DatabaseAdapter, storage: StorageService, autoMigration?: boolean, authMiddleware?: AuthMiddleware): Promise<void>;
|
|
62
|
+
//# sourceMappingURL=initializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initializer.d.ts","sourceRoot":"","sources":["../src/initializer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,oBAAoB,CACtC,UAAU,EAAE,KAAK,CAAC,SAAS,GAAG,SAAS,CAAC,EACxC,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,cAAc,EACvB,aAAa,GAAE,OAAc,GAC9B,OAAO,CAAC,IAAI,CAAC,CAQf;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,wBAAwB,CAC1C,cAAc,EAAE,aAAa,EAAE,EAC/B,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,cAAc,EACvB,aAAa,GAAE,OAAc,EAC7B,cAAc,CAAC,EAAE,cAAc,GAChC,OAAO,CAAC,IAAI,CAAC,CAUf"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Component initialization utilities for the digital twin engine
|
|
3
|
+
*
|
|
4
|
+
* This module handles the setup and initialization of digital twin components,
|
|
5
|
+
* including database table creation and dependency injection.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Initializes data collection and processing components with required dependencies.
|
|
9
|
+
*
|
|
10
|
+
* This function sets up collectors and harvesters by:
|
|
11
|
+
* 1. Creating necessary database tables for each component
|
|
12
|
+
* 2. Running automatic schema migrations if enabled
|
|
13
|
+
* 3. Injecting database and storage service dependencies
|
|
14
|
+
*
|
|
15
|
+
* @param components - Array of collectors and harvesters to initialize
|
|
16
|
+
* @param database - Database adapter instance for data storage
|
|
17
|
+
* @param storage - Storage service instance for file operations
|
|
18
|
+
* @param autoMigration - Enable automatic schema migration (default: true)
|
|
19
|
+
*
|
|
20
|
+
* @throws {Error} When database table creation fails
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const components = [weatherCollector, trafficHarvester];
|
|
25
|
+
* const database = new KnexDatabaseAdapter(config);
|
|
26
|
+
* const storage = new LocalStorageService();
|
|
27
|
+
*
|
|
28
|
+
* await initializeComponents(components, database, storage, true);
|
|
29
|
+
* // Components are now ready to process data
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export async function initializeComponents(components, database, storage, autoMigration = true) {
|
|
33
|
+
// Create all tables in parallel for faster startup
|
|
34
|
+
await Promise.all(components.map(comp => ensureTableExists(database, comp.getConfiguration().name, autoMigration)));
|
|
35
|
+
// Inject dependencies (synchronous, fast)
|
|
36
|
+
for (const comp of components) {
|
|
37
|
+
comp.setDependencies(database, storage);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Initializes asset management components with required dependencies.
|
|
42
|
+
*
|
|
43
|
+
* Asset managers handle file-based resources (like 3D models, tilesets, maps)
|
|
44
|
+
* and require both database access for metadata and storage for file operations.
|
|
45
|
+
*
|
|
46
|
+
* @param assetsManagers - Array of asset managers to initialize
|
|
47
|
+
* @param database - Database adapter instance for metadata storage
|
|
48
|
+
* @param storage - Storage service instance for asset file operations
|
|
49
|
+
* @param autoMigration - Enable automatic schema migration (default: true)
|
|
50
|
+
*
|
|
51
|
+
* @throws {Error} When database table creation fails
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const managers = [tilesetManager, pointCloudManager];
|
|
56
|
+
* const database = new KnexDatabaseAdapter(config);
|
|
57
|
+
* const storage = new OvhS3StorageService(credentials);
|
|
58
|
+
*
|
|
59
|
+
* await initializeAssetsManagers(managers, database, storage, true);
|
|
60
|
+
* // Asset managers are now ready to handle file operations
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export async function initializeAssetsManagers(assetsManagers, database, storage, autoMigration = true, authMiddleware) {
|
|
64
|
+
// Create all tables in parallel for faster startup
|
|
65
|
+
await Promise.all(assetsManagers.map(manager => ensureTableExists(database, manager.getConfiguration().name, autoMigration)));
|
|
66
|
+
// Inject dependencies (synchronous, fast)
|
|
67
|
+
for (const manager of assetsManagers) {
|
|
68
|
+
manager.setDependencies(database, storage, authMiddleware);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Ensures a database table exists for the specified component.
|
|
73
|
+
*
|
|
74
|
+
* Checks if a table exists in the database and creates it if missing.
|
|
75
|
+
* If autoMigration is enabled and table exists, runs schema migration.
|
|
76
|
+
* This function is called during component initialization to ensure
|
|
77
|
+
* each component has its required storage table available.
|
|
78
|
+
*
|
|
79
|
+
* @param database - Database adapter to check/create table with
|
|
80
|
+
* @param tableName - Name of the table to ensure exists
|
|
81
|
+
* @param autoMigration - Enable automatic schema migration for existing tables
|
|
82
|
+
*
|
|
83
|
+
* @throws {Error} When table creation or migration fails
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* // Internal usage during component initialization
|
|
88
|
+
* await ensureTableExists(database, 'weather_data_collector', true);
|
|
89
|
+
* // Table now exists and schema is up-to-date
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @internal This function is used internally by initialization functions
|
|
93
|
+
*/
|
|
94
|
+
async function ensureTableExists(database, tableName, autoMigration = true) {
|
|
95
|
+
const exists = await database.doesTableExists(tableName);
|
|
96
|
+
if (!exists) {
|
|
97
|
+
await database.createTable(tableName);
|
|
98
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
99
|
+
console.log(`[DigitalTwin] Created table "${tableName}"`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else if (autoMigration) {
|
|
103
|
+
// Table exists, run migration to add missing columns/indexes
|
|
104
|
+
const migrations = await database.migrateTableSchema(tableName);
|
|
105
|
+
if (migrations.length > 0 && process.env.NODE_ENV !== 'test') {
|
|
106
|
+
console.log(`[DigitalTwin] Migrated "${tableName}": ${migrations.join(', ')}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=initializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initializer.js","sourceRoot":"","sources":["../src/initializer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACtC,UAAwC,EACxC,QAAyB,EACzB,OAAuB,EACvB,gBAAyB,IAAI;IAE7B,mDAAmD;IACnD,MAAM,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,iBAAiB,CAAC,QAAQ,EAAE,IAAI,CAAC,gBAAgB,EAAE,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;IAEnH,0CAA0C;IAC1C,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC5B,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAC3C,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC1C,cAA+B,EAC/B,QAAyB,EACzB,OAAuB,EACvB,gBAAyB,IAAI,EAC7B,cAA+B;IAE/B,mDAAmD;IACnD,MAAM,OAAO,CAAC,GAAG,CACb,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CA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