digitaltwin-core 0.8.0 → 0.8.1
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/components/handler.d.ts +70 -9
- package/dist/components/handler.d.ts.map +1 -1
- package/dist/components/handler.js +45 -6
- package/dist/components/handler.js.map +1 -1
- package/dist/components/harvester.d.ts +129 -20
- package/dist/components/harvester.d.ts.map +1 -1
- package/dist/components/harvester.js +134 -41
- package/dist/components/harvester.js.map +1 -1
- package/dist/components/interfaces.d.ts +108 -0
- package/dist/components/interfaces.d.ts.map +1 -1
- package/dist/components/interfaces.js +6 -0
- package/dist/components/interfaces.js.map +1 -1
- package/dist/engine/endpoints.d.ts +39 -0
- package/dist/engine/endpoints.d.ts.map +1 -1
- package/dist/engine/endpoints.js +31 -0
- package/dist/engine/endpoints.js.map +1 -1
- package/dist/engine/events.d.ts +80 -0
- package/dist/engine/events.d.ts.map +1 -1
- package/dist/engine/events.js +60 -0
- package/dist/engine/events.js.map +1 -1
- package/dist/engine/initializer.d.ts +51 -0
- package/dist/engine/initializer.d.ts.map +1 -1
- package/dist/engine/initializer.js +72 -0
- package/dist/engine/initializer.js.map +1 -1
- package/dist/env/env.d.ts +101 -0
- package/dist/env/env.d.ts.map +1 -1
- package/dist/env/env.js +101 -0
- package/dist/env/env.js.map +1 -1
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -1
- package/dist/types/data_record.d.ts +65 -4
- package/dist/types/data_record.d.ts.map +1 -1
- package/dist/types/data_record.js +6 -0
- package/dist/types/data_record.js.map +1 -1
- package/dist/utils/servable_endpoint.d.ts +59 -2
- package/dist/utils/servable_endpoint.d.ts.map +1 -1
- package/dist/utils/servable_endpoint.js +51 -0
- package/dist/utils/servable_endpoint.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,17 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Core interfaces defining the contract for digital twin components
|
|
3
|
+
*
|
|
4
|
+
* These interfaces establish the foundation for component architecture, scheduling,
|
|
5
|
+
* and HTTP endpoint serving capabilities within the digital twin ecosystem.
|
|
6
|
+
*/
|
|
1
7
|
import type { ComponentConfiguration } from './types.js';
|
|
2
8
|
import type { HttpMethod } from '../engine/endpoints.js';
|
|
9
|
+
/**
|
|
10
|
+
* Base interface for all digital twin components.
|
|
11
|
+
*
|
|
12
|
+
* Components are the fundamental building blocks of a digital twin system,
|
|
13
|
+
* each responsible for a specific aspect of data management or processing.
|
|
14
|
+
*
|
|
15
|
+
* @template T - The type of configuration object this component uses
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* class MyCollector implements Component<MyCollectorConfig> {
|
|
20
|
+
* getConfiguration(): MyCollectorConfig {
|
|
21
|
+
* return { name: 'my-collector', interval: 5000 };
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
3
26
|
export interface Component<T extends ComponentConfiguration = ComponentConfiguration> {
|
|
27
|
+
/**
|
|
28
|
+
* Returns the configuration object for this component.
|
|
29
|
+
*
|
|
30
|
+
* The configuration contains metadata about the component such as its name,
|
|
31
|
+
* type, scheduling information, and component-specific settings.
|
|
32
|
+
*
|
|
33
|
+
* @returns The component's configuration object
|
|
34
|
+
*/
|
|
4
35
|
getConfiguration(): T;
|
|
5
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Interface for components that can be scheduled to run periodically.
|
|
39
|
+
*
|
|
40
|
+
* Components implementing this interface can be automatically executed
|
|
41
|
+
* by the digital twin engine's scheduler based on a cron expression.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* class DataCollector implements ScheduleRunnable {
|
|
46
|
+
* async run(): Promise<void> {
|
|
47
|
+
* // Collect and process data
|
|
48
|
+
* console.log('Collecting data...');
|
|
49
|
+
* }
|
|
50
|
+
*
|
|
51
|
+
* getSchedule(): string {
|
|
52
|
+
* return '0 *.5 * * * *'; // Every 5 minutes
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
6
57
|
export interface ScheduleRunnable {
|
|
58
|
+
/**
|
|
59
|
+
* Executes the component's main functionality.
|
|
60
|
+
*
|
|
61
|
+
* This method is called automatically by the scheduler according to
|
|
62
|
+
* the schedule returned by getSchedule(). Implementations should handle
|
|
63
|
+
* errors appropriately and return a promise that resolves when the
|
|
64
|
+
* operation is complete.
|
|
65
|
+
*
|
|
66
|
+
* @returns A promise that resolves when the run operation completes
|
|
67
|
+
*/
|
|
7
68
|
run(): Promise<unknown>;
|
|
69
|
+
/**
|
|
70
|
+
* Returns the cron expression defining when this component should run.
|
|
71
|
+
*
|
|
72
|
+
* The schedule follows standard cron syntax (second minute hour day month dayOfWeek).
|
|
73
|
+
*
|
|
74
|
+
* @returns A cron expression string (e.g., '0 *.5 * * * *' for every 5 minutes)
|
|
75
|
+
*/
|
|
8
76
|
getSchedule(): string;
|
|
9
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Interface for components that can expose HTTP endpoints.
|
|
80
|
+
*
|
|
81
|
+
* Components implementing this interface can serve HTTP requests,
|
|
82
|
+
* allowing external systems to interact with the digital twin's data
|
|
83
|
+
* and functionality through REST APIs.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* class DataProvider implements Servable {
|
|
88
|
+
* getEndpoints() {
|
|
89
|
+
* return [
|
|
90
|
+
* {
|
|
91
|
+
* method: 'GET',
|
|
92
|
+
* path: '/api/data',
|
|
93
|
+
* handler: this.getData.bind(this),
|
|
94
|
+
* responseType: 'application/json'
|
|
95
|
+
* }
|
|
96
|
+
* ];
|
|
97
|
+
* }
|
|
98
|
+
*
|
|
99
|
+
* private async getData() {
|
|
100
|
+
* return { data: 'example' };
|
|
101
|
+
* }
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
10
105
|
export interface Servable {
|
|
106
|
+
/**
|
|
107
|
+
* Returns an array of HTTP endpoints this component exposes.
|
|
108
|
+
*
|
|
109
|
+
* Each endpoint defines the HTTP method, URL path, handler function,
|
|
110
|
+
* and optional response content type. The digital twin engine will
|
|
111
|
+
* automatically register these endpoints with the HTTP server.
|
|
112
|
+
*
|
|
113
|
+
* @returns Array of endpoint definitions
|
|
114
|
+
*/
|
|
11
115
|
getEndpoints(): Array<{
|
|
116
|
+
/** HTTP method for this endpoint (GET, POST, PUT, DELETE, etc.) */
|
|
12
117
|
method: HttpMethod;
|
|
118
|
+
/** URL path for this endpoint (e.g., '/api/data') */
|
|
13
119
|
path: string;
|
|
120
|
+
/** Function to handle requests to this endpoint */
|
|
14
121
|
handler: (...args: any[]) => any;
|
|
122
|
+
/** Optional response content type (defaults to 'application/json') */
|
|
15
123
|
responseType?: string;
|
|
16
124
|
}>;
|
|
17
125
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/components/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAExD,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,sBAAsB,GAAG,sBAAsB;IAChF,gBAAgB,IAAI,CAAC,CAAA;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC7B,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/components/interfaces.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAExD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,sBAAsB,GAAG,sBAAsB;IAChF;;;;;;;OAOG;IACH,gBAAgB,IAAI,CAAC,CAAA;CACxB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,gBAAgB;IAC7B;;;;;;;;;OASG;IACH,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;IAEvB;;;;;;OAMG;IACH,WAAW,IAAI,MAAM,CAAA;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,WAAW,QAAQ;IACrB;;;;;;;;OAQG;IACH,YAAY,IAAI,KAAK,CAAC;QAClB,mEAAmE;QACnE,MAAM,EAAE,UAAU,CAAA;QAClB,qDAAqD;QACrD,IAAI,EAAE,MAAM,CAAA;QACZ,mDAAmD;QACnD,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAA;QAChC,sEAAsE;QACtE,YAAY,CAAC,EAAE,MAAM,CAAA;KACxB,CAAC,CAAA;CACL"}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Core interfaces defining the contract for digital twin components
|
|
3
|
+
*
|
|
4
|
+
* These interfaces establish the foundation for component architecture, scheduling,
|
|
5
|
+
* and HTTP endpoint serving capabilities within the digital twin ecosystem.
|
|
6
|
+
*/
|
|
1
7
|
export {};
|
|
2
8
|
//# sourceMappingURL=interfaces.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/components/interfaces.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/components/interfaces.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -1,8 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview HTTP endpoint exposure utilities for digital twin components
|
|
3
|
+
*
|
|
4
|
+
* This module handles the automatic registration of HTTP endpoints from servable
|
|
5
|
+
* components to the Express router, enabling RESTful API access to digital twin data.
|
|
6
|
+
*/
|
|
1
7
|
import type { Router } from 'ultimate-express';
|
|
2
8
|
import type { Collector } from '../components/collector.js';
|
|
3
9
|
import type { Harvester } from '../components/harvester.js';
|
|
4
10
|
import type { Handler } from '../components/handler.js';
|
|
5
11
|
import type { AssetsManager, CustomTableManager } from '../components/index.js';
|
|
12
|
+
/**
|
|
13
|
+
* Supported HTTP methods for component endpoints.
|
|
14
|
+
*
|
|
15
|
+
* These methods correspond to standard REST operations:
|
|
16
|
+
* - get: Retrieve data
|
|
17
|
+
* - post: Create new resources
|
|
18
|
+
* - put: Update existing resources (full update)
|
|
19
|
+
* - patch: Update existing resources (partial update)
|
|
20
|
+
* - delete: Remove resources
|
|
21
|
+
*/
|
|
6
22
|
export type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch';
|
|
23
|
+
/**
|
|
24
|
+
* Automatically registers HTTP endpoints from servable components to an Express router.
|
|
25
|
+
*
|
|
26
|
+
* This function iterates through all provided components, extracts their endpoints,
|
|
27
|
+
* and registers them with the Express router. Each endpoint is wrapped with error
|
|
28
|
+
* handling to ensure robust API behavior.
|
|
29
|
+
*
|
|
30
|
+
* @param router - Express router instance to register endpoints with
|
|
31
|
+
* @param servables - Array of components that expose HTTP endpoints
|
|
32
|
+
*
|
|
33
|
+
* @throws {Error} When an unsupported HTTP method is encountered
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const router = express.Router();
|
|
38
|
+
* const components = [collector1, harvester1, assetsManager1];
|
|
39
|
+
*
|
|
40
|
+
* await exposeEndpoints(router, components);
|
|
41
|
+
*
|
|
42
|
+
* // Now the router has all endpoints from the components registered
|
|
43
|
+
* app.use('/api', router);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
7
46
|
export declare function exposeEndpoints(router: Router, servables: Array<Collector | Harvester | Handler | AssetsManager | CustomTableManager>): Promise<void>;
|
|
8
47
|
//# sourceMappingURL=endpoints.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoints.d.ts","sourceRoot":"","sources":["../../src/engine/endpoints.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAEvD,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAE/E,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"endpoints.d.ts","sourceRoot":"","sources":["../../src/engine/endpoints.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAEvD,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAE/E;;;;;;;;;GASG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAA;AAsBpE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,eAAe,CACjC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,KAAK,CAAC,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,aAAa,GAAG,kBAAkB,CAAC,GACvF,OAAO,CAAC,IAAI,CAAC,CAyBf"}
|
package/dist/engine/endpoints.js
CHANGED
|
@@ -1,9 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview HTTP endpoint exposure utilities for digital twin components
|
|
3
|
+
*
|
|
4
|
+
* This module handles the automatic registration of HTTP endpoints from servable
|
|
5
|
+
* components to the Express router, enabling RESTful API access to digital twin data.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Automatically registers HTTP endpoints from servable components to an Express router.
|
|
9
|
+
*
|
|
10
|
+
* This function iterates through all provided components, extracts their endpoints,
|
|
11
|
+
* and registers them with the Express router. Each endpoint is wrapped with error
|
|
12
|
+
* handling to ensure robust API behavior.
|
|
13
|
+
*
|
|
14
|
+
* @param router - Express router instance to register endpoints with
|
|
15
|
+
* @param servables - Array of components that expose HTTP endpoints
|
|
16
|
+
*
|
|
17
|
+
* @throws {Error} When an unsupported HTTP method is encountered
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const router = express.Router();
|
|
22
|
+
* const components = [collector1, harvester1, assetsManager1];
|
|
23
|
+
*
|
|
24
|
+
* await exposeEndpoints(router, components);
|
|
25
|
+
*
|
|
26
|
+
* // Now the router has all endpoints from the components registered
|
|
27
|
+
* app.use('/api', router);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
1
30
|
export async function exposeEndpoints(router, servables) {
|
|
2
31
|
for (const servable of servables) {
|
|
3
32
|
const endpoints = servable.getEndpoints();
|
|
4
33
|
for (const ep of endpoints) {
|
|
5
34
|
const method = ep.method.toLowerCase();
|
|
6
35
|
if (typeof router[method] === 'function') {
|
|
36
|
+
// Register endpoint with error handling wrapper
|
|
7
37
|
router[method](ep.path, async (req, res) => {
|
|
8
38
|
try {
|
|
9
39
|
const result = await ep.handler(req);
|
|
@@ -12,6 +42,7 @@ export async function exposeEndpoints(router, servables) {
|
|
|
12
42
|
.send(result.content);
|
|
13
43
|
}
|
|
14
44
|
catch {
|
|
45
|
+
// Generic error response to avoid exposing internal details
|
|
15
46
|
res.status(500).send({ error: 'Internal server error' });
|
|
16
47
|
}
|
|
17
48
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoints.js","sourceRoot":"","sources":["../../src/engine/endpoints.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"endpoints.js","sourceRoot":"","sources":["../../src/engine/endpoints.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAyCH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACjC,MAAc,EACd,SAAsF;IAEtF,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QAC/B,MAAM,SAAS,GAAe,QAAQ,CAAC,YAAY,EAAE,CAAA;QAErD,KAAK,MAAM,EAAE,IAAI,SAAS,EAAE,CAAC;YACzB,MAAM,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,EAAgB,CAAA;YAEpD,IAAI,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,UAAU,EAAE,CAAC;gBACvC,gDAAgD;gBAChD,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,EAAE;oBAC1D,IAAI,CAAC;wBACD,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;wBACpC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;6BACpB,MAAM,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC;6BAC5B,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;oBAC7B,CAAC;oBAAC,MAAM,CAAC;wBACL,4DAA4D;wBAC5D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,uBAAuB,EAAE,CAAC,CAAA;oBAC5D,CAAC;gBACL,CAAC,CAAC,CAAA;YACN,CAAC;iBAAM,CAAC;gBACJ,MAAM,IAAI,KAAK,CAAC,4BAA4B,EAAE,CAAC,MAAM,EAAE,CAAC,CAAA;YAC5D,CAAC;QACL,CAAC;IACL,CAAC;AACL,CAAC"}
|
package/dist/engine/events.d.ts
CHANGED
|
@@ -1,13 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Event system for digital twin engine component communication
|
|
3
|
+
*
|
|
4
|
+
* This module provides a centralized event bus for components to communicate
|
|
5
|
+
* asynchronously about their execution status and data processing events.
|
|
6
|
+
*/
|
|
1
7
|
import { EventEmitter } from 'events';
|
|
8
|
+
/**
|
|
9
|
+
* Interface representing an event emitted by digital twin components.
|
|
10
|
+
*
|
|
11
|
+
* Component events provide information about component execution lifecycle,
|
|
12
|
+
* allowing other parts of the system to react to component state changes.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const event: ComponentEvent = {
|
|
17
|
+
* type: 'collector:completed',
|
|
18
|
+
* componentName: 'weather-data-collector',
|
|
19
|
+
* timestamp: new Date(),
|
|
20
|
+
* data: { recordsProcessed: 150 }
|
|
21
|
+
* };
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
2
24
|
export interface ComponentEvent {
|
|
25
|
+
/** The type of event that occurred */
|
|
3
26
|
type: 'collector:completed' | 'harvester:completed';
|
|
27
|
+
/** Name of the component that emitted this event */
|
|
4
28
|
componentName: string;
|
|
29
|
+
/** Timestamp when the event occurred */
|
|
5
30
|
timestamp: Date;
|
|
31
|
+
/** Optional additional data related to the event */
|
|
6
32
|
data?: any;
|
|
7
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Enhanced event bus for digital twin engine component communication.
|
|
36
|
+
*
|
|
37
|
+
* Extends Node.js EventEmitter to provide type-safe event handling
|
|
38
|
+
* for component lifecycle events. All components can emit events
|
|
39
|
+
* to notify other parts of the system about their execution status.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* // Listen for collector completion events
|
|
44
|
+
* engineEventBus.on('collector:completed', (event) => {
|
|
45
|
+
* console.log(`Collector ${event.componentName} completed at ${event.timestamp}`);
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // Emit an event from a component
|
|
49
|
+
* engineEventBus.emit('collector:completed', {
|
|
50
|
+
* type: 'collector:completed',
|
|
51
|
+
* componentName: 'my-collector',
|
|
52
|
+
* timestamp: new Date(),
|
|
53
|
+
* data: { success: true }
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
8
57
|
export declare class EngineEventBus extends EventEmitter {
|
|
58
|
+
/**
|
|
59
|
+
* Emits a component event to all registered listeners.
|
|
60
|
+
*
|
|
61
|
+
* @param event - The event name/type to emit
|
|
62
|
+
* @param data - The component event data
|
|
63
|
+
* @returns True if the event had listeners, false otherwise
|
|
64
|
+
*/
|
|
9
65
|
emit(event: string, data: ComponentEvent): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Registers a listener for component events.
|
|
68
|
+
*
|
|
69
|
+
* @param event - The event name/type to listen for
|
|
70
|
+
* @param listener - Function to call when the event is emitted
|
|
71
|
+
* @returns This event bus instance for method chaining
|
|
72
|
+
*/
|
|
10
73
|
on(event: string, listener: (data: ComponentEvent) => void): this;
|
|
11
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Global event bus instance for the digital twin engine.
|
|
77
|
+
*
|
|
78
|
+
* This singleton provides a centralized communication channel
|
|
79
|
+
* for all components within the digital twin system.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* // Listen for all collector events
|
|
84
|
+
* engineEventBus.on('collector:completed', (event) => {
|
|
85
|
+
* console.log(`Collector completed: ${event.componentName}`);
|
|
86
|
+
* });
|
|
87
|
+
*
|
|
88
|
+
* // Components emit events through this bus
|
|
89
|
+
* engineEventBus.emit('collector:completed', eventData);
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
12
92
|
export declare const engineEventBus: EngineEventBus;
|
|
13
93
|
//# sourceMappingURL=events.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/engine/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAErC,MAAM,WAAW,cAAc;IAC3B,IAAI,EAAE,qBAAqB,GAAG,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/engine/events.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAErC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,cAAc;IAC3B,sCAAsC;IACtC,IAAI,EAAE,qBAAqB,GAAG,qBAAqB,CAAA;IAEnD,oDAAoD;IACpD,aAAa,EAAE,MAAM,CAAA;IAErB,wCAAwC;IACxC,SAAS,EAAE,IAAI,CAAA;IAEf,oDAAoD;IACpD,IAAI,CAAC,EAAE,GAAG,CAAA;CACb;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,cAAe,SAAQ,YAAY;IAC5C;;;;;;OAMG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO;IAIlD;;;;;;OAMG;IACH,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,IAAI,GAAG,IAAI;CAGpE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,cAAc,gBAAuB,CAAA"}
|
package/dist/engine/events.js
CHANGED
|
@@ -1,11 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Event system for digital twin engine component communication
|
|
3
|
+
*
|
|
4
|
+
* This module provides a centralized event bus for components to communicate
|
|
5
|
+
* asynchronously about their execution status and data processing events.
|
|
6
|
+
*/
|
|
1
7
|
import { EventEmitter } from 'events';
|
|
8
|
+
/**
|
|
9
|
+
* Enhanced event bus for digital twin engine component communication.
|
|
10
|
+
*
|
|
11
|
+
* Extends Node.js EventEmitter to provide type-safe event handling
|
|
12
|
+
* for component lifecycle events. All components can emit events
|
|
13
|
+
* to notify other parts of the system about their execution status.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Listen for collector completion events
|
|
18
|
+
* engineEventBus.on('collector:completed', (event) => {
|
|
19
|
+
* console.log(`Collector ${event.componentName} completed at ${event.timestamp}`);
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Emit an event from a component
|
|
23
|
+
* engineEventBus.emit('collector:completed', {
|
|
24
|
+
* type: 'collector:completed',
|
|
25
|
+
* componentName: 'my-collector',
|
|
26
|
+
* timestamp: new Date(),
|
|
27
|
+
* data: { success: true }
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
2
31
|
export class EngineEventBus extends EventEmitter {
|
|
32
|
+
/**
|
|
33
|
+
* Emits a component event to all registered listeners.
|
|
34
|
+
*
|
|
35
|
+
* @param event - The event name/type to emit
|
|
36
|
+
* @param data - The component event data
|
|
37
|
+
* @returns True if the event had listeners, false otherwise
|
|
38
|
+
*/
|
|
3
39
|
emit(event, data) {
|
|
4
40
|
return super.emit(event, data);
|
|
5
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Registers a listener for component events.
|
|
44
|
+
*
|
|
45
|
+
* @param event - The event name/type to listen for
|
|
46
|
+
* @param listener - Function to call when the event is emitted
|
|
47
|
+
* @returns This event bus instance for method chaining
|
|
48
|
+
*/
|
|
6
49
|
on(event, listener) {
|
|
7
50
|
return super.on(event, listener);
|
|
8
51
|
}
|
|
9
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Global event bus instance for the digital twin engine.
|
|
55
|
+
*
|
|
56
|
+
* This singleton provides a centralized communication channel
|
|
57
|
+
* for all components within the digital twin system.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* // Listen for all collector events
|
|
62
|
+
* engineEventBus.on('collector:completed', (event) => {
|
|
63
|
+
* console.log(`Collector completed: ${event.componentName}`);
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* // Components emit events through this bus
|
|
67
|
+
* engineEventBus.emit('collector:completed', eventData);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
10
70
|
export const engineEventBus = new EngineEventBus();
|
|
11
71
|
//# sourceMappingURL=events.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/engine/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/engine/events.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAgCrC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAO,cAAe,SAAQ,YAAY;IAC5C;;;;;;OAMG;IACH,IAAI,CAAC,KAAa,EAAE,IAAoB;QACpC,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;IAClC,CAAC;IAED;;;;;;OAMG;IACH,EAAE,CAAC,KAAa,EAAE,QAAwC;QACtD,OAAO,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IACpC,CAAC;CACJ;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,cAAc,EAAE,CAAA"}
|
|
@@ -1,8 +1,59 @@
|
|
|
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
|
+
*/
|
|
1
7
|
import type { Collector } from '../components/collector.js';
|
|
2
8
|
import type { Harvester } from '../components/harvester.js';
|
|
3
9
|
import type { AssetsManager } from '../components/assets_manager.js';
|
|
4
10
|
import type { DatabaseAdapter } from '../database/database_adapter.js';
|
|
5
11
|
import type { StorageService } from '../storage/storage_service.js';
|
|
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. Injecting database and storage service dependencies
|
|
18
|
+
*
|
|
19
|
+
* @param components - Array of collectors and harvesters to initialize
|
|
20
|
+
* @param database - Database adapter instance for data storage
|
|
21
|
+
* @param storage - Storage service instance for file operations
|
|
22
|
+
*
|
|
23
|
+
* @throws {Error} When database table creation fails
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const components = [weatherCollector, trafficHarvester];
|
|
28
|
+
* const database = new KnexDatabaseAdapter(config);
|
|
29
|
+
* const storage = new LocalStorageService();
|
|
30
|
+
*
|
|
31
|
+
* await initializeComponents(components, database, storage);
|
|
32
|
+
* // Components are now ready to process data
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
6
35
|
export declare function initializeComponents(components: Array<Collector | Harvester>, database: DatabaseAdapter, storage: StorageService): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Initializes asset management components with required dependencies.
|
|
38
|
+
*
|
|
39
|
+
* Asset managers handle file-based resources (like 3D models, tilesets, maps)
|
|
40
|
+
* and require both database access for metadata and storage for file operations.
|
|
41
|
+
*
|
|
42
|
+
* @param assetsManagers - Array of asset managers to initialize
|
|
43
|
+
* @param database - Database adapter instance for metadata storage
|
|
44
|
+
* @param storage - Storage service instance for asset file operations
|
|
45
|
+
*
|
|
46
|
+
* @throws {Error} When database table creation fails
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const managers = [tilesetManager, pointCloudManager];
|
|
51
|
+
* const database = new KnexDatabaseAdapter(config);
|
|
52
|
+
* const storage = new OvhS3StorageService(credentials);
|
|
53
|
+
*
|
|
54
|
+
* await initializeAssetsManagers(managers, database, storage);
|
|
55
|
+
* // Asset managers are now ready to handle file operations
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
7
58
|
export declare function initializeAssetsManagers(assetsManagers: AssetsManager[], database: DatabaseAdapter, storage: StorageService): Promise<void>;
|
|
8
59
|
//# sourceMappingURL=initializer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initializer.d.ts","sourceRoot":"","sources":["../../src/engine/initializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAA;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAEnE,wBAAsB,oBAAoB,CACtC,UAAU,EAAE,KAAK,CAAC,SAAS,GAAG,SAAS,CAAC,EACxC,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,cAAc,GACxB,OAAO,CAAC,IAAI,CAAC,CAMf;AAED,wBAAsB,wBAAwB,CAC1C,cAAc,EAAE,aAAa,EAAE,EAC/B,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,cAAc,GACxB,OAAO,CAAC,IAAI,CAAC,CAMf"}
|
|
1
|
+
{"version":3,"file":"initializer.d.ts","sourceRoot":"","sources":["../../src/engine/initializer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAA;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAEnE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,oBAAoB,CACtC,UAAU,EAAE,KAAK,CAAC,SAAS,GAAG,SAAS,CAAC,EACxC,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,cAAc,GACxB,OAAO,CAAC,IAAI,CAAC,CAMf;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,wBAAwB,CAC1C,cAAc,EAAE,aAAa,EAAE,EAC/B,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,cAAc,GACxB,OAAO,CAAC,IAAI,CAAC,CAMf"}
|
|
@@ -1,3 +1,32 @@
|
|
|
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. Injecting database and storage service dependencies
|
|
13
|
+
*
|
|
14
|
+
* @param components - Array of collectors and harvesters to initialize
|
|
15
|
+
* @param database - Database adapter instance for data storage
|
|
16
|
+
* @param storage - Storage service instance for file operations
|
|
17
|
+
*
|
|
18
|
+
* @throws {Error} When database table creation fails
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const components = [weatherCollector, trafficHarvester];
|
|
23
|
+
* const database = new KnexDatabaseAdapter(config);
|
|
24
|
+
* const storage = new LocalStorageService();
|
|
25
|
+
*
|
|
26
|
+
* await initializeComponents(components, database, storage);
|
|
27
|
+
* // Components are now ready to process data
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
1
30
|
export async function initializeComponents(components, database, storage) {
|
|
2
31
|
for (const comp of components) {
|
|
3
32
|
const config = comp.getConfiguration();
|
|
@@ -5,6 +34,28 @@ export async function initializeComponents(components, database, storage) {
|
|
|
5
34
|
comp.setDependencies(database, storage);
|
|
6
35
|
}
|
|
7
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Initializes asset management components with required dependencies.
|
|
39
|
+
*
|
|
40
|
+
* Asset managers handle file-based resources (like 3D models, tilesets, maps)
|
|
41
|
+
* and require both database access for metadata and storage for file operations.
|
|
42
|
+
*
|
|
43
|
+
* @param assetsManagers - Array of asset managers to initialize
|
|
44
|
+
* @param database - Database adapter instance for metadata storage
|
|
45
|
+
* @param storage - Storage service instance for asset file operations
|
|
46
|
+
*
|
|
47
|
+
* @throws {Error} When database table creation fails
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const managers = [tilesetManager, pointCloudManager];
|
|
52
|
+
* const database = new KnexDatabaseAdapter(config);
|
|
53
|
+
* const storage = new OvhS3StorageService(credentials);
|
|
54
|
+
*
|
|
55
|
+
* await initializeAssetsManagers(managers, database, storage);
|
|
56
|
+
* // Asset managers are now ready to handle file operations
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
8
59
|
export async function initializeAssetsManagers(assetsManagers, database, storage) {
|
|
9
60
|
for (const manager of assetsManagers) {
|
|
10
61
|
const config = manager.getConfiguration();
|
|
@@ -12,6 +63,27 @@ export async function initializeAssetsManagers(assetsManagers, database, storage
|
|
|
12
63
|
manager.setDependencies(database, storage);
|
|
13
64
|
}
|
|
14
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Ensures a database table exists for the specified component.
|
|
68
|
+
*
|
|
69
|
+
* Checks if a table exists in the database and creates it if missing.
|
|
70
|
+
* This function is called during component initialization to ensure
|
|
71
|
+
* each component has its required storage table available.
|
|
72
|
+
*
|
|
73
|
+
* @param database - Database adapter to check/create table with
|
|
74
|
+
* @param tableName - Name of the table to ensure exists
|
|
75
|
+
*
|
|
76
|
+
* @throws {Error} When table creation fails
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* // Internal usage during component initialization
|
|
81
|
+
* await ensureTableExists(database, 'weather_data_collector');
|
|
82
|
+
* // Table now exists and is ready for use
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @internal This function is used internally by initialization functions
|
|
86
|
+
*/
|
|
15
87
|
async function ensureTableExists(database, tableName) {
|
|
16
88
|
const exists = await database.doesTableExists(tableName);
|
|
17
89
|
if (!exists) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initializer.js","sourceRoot":"","sources":["../../src/engine/initializer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"initializer.js","sourceRoot":"","sources":["../../src/engine/initializer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACtC,UAAwC,EACxC,QAAyB,EACzB,OAAuB;IAEvB,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAA;QACtC,MAAM,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC9C,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAC3C,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC1C,cAA+B,EAC/B,QAAyB,EACzB,OAAuB;IAEvB,KAAK,MAAM,OAAO,IAAI,cAAc,EAAE,CAAC;QACnC,MAAM,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAA;QACzC,MAAM,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC9C,OAAO,CAAC,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAC9C,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,KAAK,UAAU,iBAAiB,CAAC,QAAyB,EAAE,SAAiB;IACzE,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,eAAe,CAAC,SAAS,CAAC,CAAA;IACxD,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,OAAO,CAAC,GAAG,CAAC,iCAAiC,SAAS,MAAM,CAAC,CAAA;QAC7D,MAAM,QAAQ,CAAC,WAAW,CAAC,SAAS,CAAC,CAAA;QACrC,OAAO,CAAC,GAAG,CAAC,YAAY,SAAS,wBAAwB,CAAC,CAAA;IAC9D,CAAC;AACL,CAAC"}
|