digitaltwin-core 0.8.2 → 0.8.3
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/assets_manager.d.ts.map +1 -1
- package/dist/components/assets_manager.js +0 -1
- package/dist/components/assets_manager.js.map +1 -1
- package/dist/components/custom_table_manager.d.ts +1 -1
- package/dist/components/custom_table_manager.d.ts.map +1 -1
- package/dist/components/custom_table_manager.js +13 -23
- package/dist/components/custom_table_manager.js.map +1 -1
- 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/components/map_manager.d.ts.map +1 -1
- package/dist/components/tileset_manager.d.ts.map +1 -1
- package/dist/database/adapters/knex_database_adapter.d.ts +15 -2
- package/dist/database/adapters/knex_database_adapter.d.ts.map +1 -1
- package/dist/database/adapters/knex_database_adapter.js +50 -3
- package/dist/database/adapters/knex_database_adapter.js.map +1 -1
- package/dist/database/database_adapter.d.ts +22 -0
- package/dist/database/database_adapter.d.ts.map +1 -1
- package/dist/database/database_adapter.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 +18 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -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/dist/utils/zip_utils.js +1 -1
- package/dist/utils/zip_utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -5,47 +5,144 @@ import type { DatabaseAdapter } from '../database/database_adapter.js';
|
|
|
5
5
|
import type { StorageService } from '../storage/storage_service.js';
|
|
6
6
|
import type { HttpMethod } from '../engine/endpoints.js';
|
|
7
7
|
/**
|
|
8
|
-
* Abstract
|
|
8
|
+
* Abstract base class for data harvesting components.
|
|
9
|
+
*
|
|
10
|
+
* Harvesters process and analyze data that has been collected by Collectors,
|
|
11
|
+
* applying transformations, aggregations, or other data processing operations.
|
|
12
|
+
* They can be triggered by new source data or run on a schedule.
|
|
13
|
+
*
|
|
14
|
+
* Key features:
|
|
15
|
+
* - Process existing collected data with configurable ranges
|
|
16
|
+
* - Support both time-based and count-based data retrieval
|
|
17
|
+
* - Can be triggered by source data changes or scheduled execution
|
|
18
|
+
* - Provide HTTP endpoints for accessing processed results
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* class TrafficAnalysisHarvester extends Harvester {
|
|
23
|
+
* getUserConfiguration() {
|
|
24
|
+
* return {
|
|
25
|
+
* name: 'traffic-analysis',
|
|
26
|
+
* type: 'harvester',
|
|
27
|
+
* source: 'traffic-collector',
|
|
28
|
+
* source_range: '1h', // Process last hour of data
|
|
29
|
+
* schedule: '0 *\/15 * * * *' // Run every 15 minutes
|
|
30
|
+
* };
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* async harvest(data: DataRecord[]): Promise<DataRecord[]> {
|
|
34
|
+
* // Process traffic data and return analysis results
|
|
35
|
+
* return this.analyzeTrafficPatterns(data);
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
9
39
|
*/
|
|
10
40
|
export declare abstract class Harvester implements Component<HarvesterConfiguration>, ScheduleRunnable, Servable {
|
|
11
41
|
protected db: DatabaseAdapter;
|
|
12
42
|
protected storage: StorageService;
|
|
13
|
-
setDependencies(db: DatabaseAdapter, storage: StorageService): void;
|
|
14
43
|
private _configCache?;
|
|
15
44
|
/**
|
|
16
|
-
*
|
|
45
|
+
* Injects database and storage dependencies into the harvester.
|
|
46
|
+
*
|
|
47
|
+
* Called during component initialization to provide access to
|
|
48
|
+
* data storage and file operations.
|
|
49
|
+
*
|
|
50
|
+
* @param db - Database adapter for reading source data
|
|
51
|
+
* @param storage - Storage service for file operations
|
|
52
|
+
*/
|
|
53
|
+
setDependencies(db: DatabaseAdapter, storage: StorageService): void;
|
|
54
|
+
/**
|
|
55
|
+
* Provides the basic harvester configuration.
|
|
56
|
+
*
|
|
57
|
+
* Implementations must return configuration specifying the harvester's
|
|
58
|
+
* name, data source, processing range, and scheduling information.
|
|
59
|
+
*
|
|
60
|
+
* @returns Basic harvester configuration without defaults applied
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* getUserConfiguration() {
|
|
65
|
+
* return {
|
|
66
|
+
* name: 'weather-analysis',
|
|
67
|
+
* type: 'harvester',
|
|
68
|
+
* source: 'weather-collector',
|
|
69
|
+
* source_range: '24h',
|
|
70
|
+
* schedule: '0 0 * * * *' // Daily at midnight
|
|
71
|
+
* };
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
17
74
|
*/
|
|
18
75
|
abstract getUserConfiguration(): HarvesterConfiguration;
|
|
19
76
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
77
|
+
* Returns the complete harvester configuration with defaults applied.
|
|
78
|
+
*
|
|
79
|
+
* Merges user configuration with sensible defaults for optional settings.
|
|
80
|
+
* This final configuration is used by the engine and scheduler.
|
|
81
|
+
*
|
|
82
|
+
* @returns Complete configuration with all defaults applied
|
|
22
83
|
*/
|
|
23
84
|
getConfiguration(): HarvesterConfiguration;
|
|
24
85
|
/**
|
|
25
|
-
*
|
|
86
|
+
* Returns the cron schedule for this harvester.
|
|
87
|
+
*
|
|
88
|
+
* For 'on-source' trigger mode, returns empty string (no schedule).
|
|
89
|
+
* For 'scheduled' mode, uses the provided schedule or defaults to every minute.
|
|
90
|
+
*
|
|
91
|
+
* @returns Cron expression string or empty string for source-triggered mode
|
|
26
92
|
*/
|
|
27
93
|
getSchedule(): string;
|
|
28
94
|
/**
|
|
29
|
-
*
|
|
95
|
+
* Allows subclasses to define a custom schedule.
|
|
96
|
+
*
|
|
97
|
+
* Override this method to provide a custom cron expression
|
|
98
|
+
* that differs from the default every-minute schedule.
|
|
99
|
+
*
|
|
100
|
+
* @returns Custom cron expression string
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* getCustomSchedule() {
|
|
105
|
+
* return '0 0 *\/6 * * *'; // Every 6 hours
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
30
108
|
*/
|
|
31
109
|
getCustomSchedule?(): string;
|
|
32
|
-
abstract harvest(sourceData: DataRecord | DataRecord[], dependenciesData: Record<string, DataRecord | DataRecord[] | null>): Promise<Buffer | Buffer[]>;
|
|
33
110
|
/**
|
|
34
|
-
*
|
|
111
|
+
* Processes source data and returns harvested results.
|
|
112
|
+
*
|
|
113
|
+
* This is the main data processing method that implementations must provide.
|
|
114
|
+
* It receives source data (from the configured source component) and any
|
|
115
|
+
* dependency data, then performs analysis, transformation, or aggregation.
|
|
116
|
+
*
|
|
117
|
+
* @param sourceData - Data from the source component (single record or array)
|
|
118
|
+
* @param dependenciesData - Data from dependency components, keyed by component name
|
|
119
|
+
* @returns Processed data as Buffer(s) to be stored
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* async harvest(sourceData: DataRecord[], dependenciesData: Record<string, DataRecord[]>) {
|
|
124
|
+
* const trafficData = sourceData.map(r => JSON.parse(r.data.toString()));
|
|
125
|
+
* const analysis = this.performTrafficAnalysis(trafficData);
|
|
126
|
+
* return Buffer.from(JSON.stringify(analysis));
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
35
129
|
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Get source data within the specified range
|
|
39
|
-
*/
|
|
40
|
-
private getSourceData;
|
|
41
|
-
/**
|
|
42
|
-
* Get data from dependent components
|
|
43
|
-
*/
|
|
44
|
-
private getDependenciesData;
|
|
130
|
+
abstract harvest(sourceData: DataRecord | DataRecord[], dependenciesData: Record<string, DataRecord | DataRecord[] | null>): Promise<Buffer | Buffer[]>;
|
|
45
131
|
/**
|
|
46
|
-
*
|
|
132
|
+
* Main execution method for the harvester.
|
|
133
|
+
*
|
|
134
|
+
* Orchestrates the harvesting process by:
|
|
135
|
+
* 1. Determining the date range for data retrieval
|
|
136
|
+
* 2. Fetching source and dependency data
|
|
137
|
+
* 3. Calling the harvest method with the data
|
|
138
|
+
* 4. Storing the results in the database
|
|
139
|
+
*
|
|
140
|
+
* @returns True if harvesting was successful, false if no data to process
|
|
141
|
+
*
|
|
142
|
+
* @throws {Error} When source component is not specified
|
|
143
|
+
* @throws {Error} When data processing fails
|
|
47
144
|
*/
|
|
48
|
-
|
|
145
|
+
run(): Promise<boolean>;
|
|
49
146
|
/**
|
|
50
147
|
* HTTP endpoints
|
|
51
148
|
*/
|
|
@@ -59,5 +156,17 @@ export declare abstract class Harvester implements Component<HarvesterConfigurat
|
|
|
59
156
|
* Retrieve latest harvested data
|
|
60
157
|
*/
|
|
61
158
|
retrieve(): Promise<DataResponse>;
|
|
159
|
+
/**
|
|
160
|
+
* Get source data within the specified range
|
|
161
|
+
*/
|
|
162
|
+
private getSourceData;
|
|
163
|
+
/**
|
|
164
|
+
* Get data from dependent components
|
|
165
|
+
*/
|
|
166
|
+
private getDependenciesData;
|
|
167
|
+
/**
|
|
168
|
+
* Store harvesting results
|
|
169
|
+
*/
|
|
170
|
+
private storeResults;
|
|
62
171
|
}
|
|
63
172
|
//# sourceMappingURL=harvester.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"harvester.d.ts","sourceRoot":"","sources":["../../src/components/harvester.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"harvester.d.ts","sourceRoot":"","sources":["../../src/components/harvester.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AACn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AsB3B;;OAEG;YACW,mBAAmB;IAyBjC;;OAEG;YACW,YAAY;CAiC7B"}
|
|
@@ -1,8 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Utility class for
|
|
2
|
+
* Utility class for parsing harvester source range configurations.
|
|
3
|
+
*
|
|
4
|
+
* Handles conversion of various source range formats (time-based like '1h', '30m'
|
|
5
|
+
* or count-based like '100') into structured date ranges for data retrieval.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Parse time-based range: get data from last hour
|
|
10
|
+
* const result = SourceRangeParser.parseSourceRange(new Date(), '1h');
|
|
11
|
+
*
|
|
12
|
+
* // Parse count-based range: get last 50 records
|
|
13
|
+
* const result = SourceRangeParser.parseSourceRange(new Date(), 50);
|
|
14
|
+
* ```
|
|
3
15
|
*/
|
|
4
16
|
class SourceRangeParser {
|
|
5
17
|
static { this.ZERO_DATE = new Date('1970-01-01T00:00:00Z'); }
|
|
18
|
+
/**
|
|
19
|
+
* Gets the zero date used as fallback for empty datasets.
|
|
20
|
+
*
|
|
21
|
+
* @returns Unix epoch date (1970-01-01T00:00:00Z)
|
|
22
|
+
*/
|
|
23
|
+
static get zeroDate() {
|
|
24
|
+
return new Date(this.ZERO_DATE);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Parses source range configuration into a structured result.
|
|
28
|
+
*
|
|
29
|
+
* @param latestDate - The latest date in the existing data
|
|
30
|
+
* @param sourceRange - Range specification (e.g., '1h', '30m', '7d', or number for count)
|
|
31
|
+
* @returns Parsed range result with start/end dates or record limit
|
|
32
|
+
*
|
|
33
|
+
* @throws {Error} When source range format is invalid
|
|
34
|
+
*/
|
|
6
35
|
static parseSourceRange(latestDate, sourceRange) {
|
|
7
36
|
if (!sourceRange) {
|
|
8
37
|
return { startDate: latestDate, limit: 1 };
|
|
@@ -39,6 +68,14 @@ class SourceRangeParser {
|
|
|
39
68
|
const endDate = this.addTime(startDate, value, unit);
|
|
40
69
|
return { startDate, endDate };
|
|
41
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Adds time to a date based on the specified unit.
|
|
73
|
+
*
|
|
74
|
+
* @param date - Base date to add time to
|
|
75
|
+
* @param value - Amount of time to add
|
|
76
|
+
* @param unit - Time unit ('days', 'hours', 'minutes', 'seconds')
|
|
77
|
+
* @returns New date with added time
|
|
78
|
+
*/
|
|
42
79
|
static addTime(date, value, unit) {
|
|
43
80
|
const result = new Date(date);
|
|
44
81
|
switch (unit) {
|
|
@@ -57,21 +94,61 @@ class SourceRangeParser {
|
|
|
57
94
|
}
|
|
58
95
|
return result;
|
|
59
96
|
}
|
|
60
|
-
static get zeroDate() {
|
|
61
|
-
return new Date(this.ZERO_DATE);
|
|
62
|
-
}
|
|
63
97
|
}
|
|
64
98
|
/**
|
|
65
|
-
* Abstract
|
|
99
|
+
* Abstract base class for data harvesting components.
|
|
100
|
+
*
|
|
101
|
+
* Harvesters process and analyze data that has been collected by Collectors,
|
|
102
|
+
* applying transformations, aggregations, or other data processing operations.
|
|
103
|
+
* They can be triggered by new source data or run on a schedule.
|
|
104
|
+
*
|
|
105
|
+
* Key features:
|
|
106
|
+
* - Process existing collected data with configurable ranges
|
|
107
|
+
* - Support both time-based and count-based data retrieval
|
|
108
|
+
* - Can be triggered by source data changes or scheduled execution
|
|
109
|
+
* - Provide HTTP endpoints for accessing processed results
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* class TrafficAnalysisHarvester extends Harvester {
|
|
114
|
+
* getUserConfiguration() {
|
|
115
|
+
* return {
|
|
116
|
+
* name: 'traffic-analysis',
|
|
117
|
+
* type: 'harvester',
|
|
118
|
+
* source: 'traffic-collector',
|
|
119
|
+
* source_range: '1h', // Process last hour of data
|
|
120
|
+
* schedule: '0 *\/15 * * * *' // Run every 15 minutes
|
|
121
|
+
* };
|
|
122
|
+
* }
|
|
123
|
+
*
|
|
124
|
+
* async harvest(data: DataRecord[]): Promise<DataRecord[]> {
|
|
125
|
+
* // Process traffic data and return analysis results
|
|
126
|
+
* return this.analyzeTrafficPatterns(data);
|
|
127
|
+
* }
|
|
128
|
+
* }
|
|
129
|
+
* ```
|
|
66
130
|
*/
|
|
67
131
|
export class Harvester {
|
|
132
|
+
/**
|
|
133
|
+
* Injects database and storage dependencies into the harvester.
|
|
134
|
+
*
|
|
135
|
+
* Called during component initialization to provide access to
|
|
136
|
+
* data storage and file operations.
|
|
137
|
+
*
|
|
138
|
+
* @param db - Database adapter for reading source data
|
|
139
|
+
* @param storage - Storage service for file operations
|
|
140
|
+
*/
|
|
68
141
|
setDependencies(db, storage) {
|
|
69
142
|
this.db = db;
|
|
70
143
|
this.storage = storage;
|
|
71
144
|
}
|
|
72
145
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
146
|
+
* Returns the complete harvester configuration with defaults applied.
|
|
147
|
+
*
|
|
148
|
+
* Merges user configuration with sensible defaults for optional settings.
|
|
149
|
+
* This final configuration is used by the engine and scheduler.
|
|
150
|
+
*
|
|
151
|
+
* @returns Complete configuration with all defaults applied
|
|
75
152
|
*/
|
|
76
153
|
getConfiguration() {
|
|
77
154
|
if (this._configCache) {
|
|
@@ -95,7 +172,12 @@ export class Harvester {
|
|
|
95
172
|
return this._configCache;
|
|
96
173
|
}
|
|
97
174
|
/**
|
|
98
|
-
*
|
|
175
|
+
* Returns the cron schedule for this harvester.
|
|
176
|
+
*
|
|
177
|
+
* For 'on-source' trigger mode, returns empty string (no schedule).
|
|
178
|
+
* For 'scheduled' mode, uses the provided schedule or defaults to every minute.
|
|
179
|
+
*
|
|
180
|
+
* @returns Cron expression string or empty string for source-triggered mode
|
|
99
181
|
*/
|
|
100
182
|
getSchedule() {
|
|
101
183
|
const config = this.getConfiguration();
|
|
@@ -106,7 +188,18 @@ export class Harvester {
|
|
|
106
188
|
return '0 * * * * *';
|
|
107
189
|
}
|
|
108
190
|
/**
|
|
109
|
-
* Main execution method
|
|
191
|
+
* Main execution method for the harvester.
|
|
192
|
+
*
|
|
193
|
+
* Orchestrates the harvesting process by:
|
|
194
|
+
* 1. Determining the date range for data retrieval
|
|
195
|
+
* 2. Fetching source and dependency data
|
|
196
|
+
* 3. Calling the harvest method with the data
|
|
197
|
+
* 4. Storing the results in the database
|
|
198
|
+
*
|
|
199
|
+
* @returns True if harvesting was successful, false if no data to process
|
|
200
|
+
*
|
|
201
|
+
* @throws {Error} When source component is not specified
|
|
202
|
+
* @throws {Error} When data processing fails
|
|
110
203
|
*/
|
|
111
204
|
async run() {
|
|
112
205
|
const config = this.getConfiguration();
|
|
@@ -151,6 +244,38 @@ export class Harvester {
|
|
|
151
244
|
await this.storeResults(config, result, sourceData, storageDate);
|
|
152
245
|
return true;
|
|
153
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* HTTP endpoints
|
|
249
|
+
*/
|
|
250
|
+
getEndpoints() {
|
|
251
|
+
return [
|
|
252
|
+
{
|
|
253
|
+
method: 'get',
|
|
254
|
+
path: `/${this.getConfiguration().endpoint}`,
|
|
255
|
+
handler: this.retrieve.bind(this),
|
|
256
|
+
responseType: this.getConfiguration().contentType
|
|
257
|
+
}
|
|
258
|
+
];
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Retrieve latest harvested data
|
|
262
|
+
*/
|
|
263
|
+
async retrieve() {
|
|
264
|
+
const config = this.getConfiguration();
|
|
265
|
+
const record = await this.db.getLatestByName(config.name);
|
|
266
|
+
if (!record) {
|
|
267
|
+
return {
|
|
268
|
+
status: 404,
|
|
269
|
+
content: 'No data available'
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
const blob = await record.data();
|
|
273
|
+
return {
|
|
274
|
+
status: 200,
|
|
275
|
+
content: blob,
|
|
276
|
+
headers: { 'Content-Type': record.contentType }
|
|
277
|
+
};
|
|
278
|
+
}
|
|
154
279
|
/**
|
|
155
280
|
* Get source data within the specified range
|
|
156
281
|
*/
|
|
@@ -221,37 +346,5 @@ export class Harvester {
|
|
|
221
346
|
});
|
|
222
347
|
}
|
|
223
348
|
}
|
|
224
|
-
/**
|
|
225
|
-
* HTTP endpoints
|
|
226
|
-
*/
|
|
227
|
-
getEndpoints() {
|
|
228
|
-
return [
|
|
229
|
-
{
|
|
230
|
-
method: 'get',
|
|
231
|
-
path: `/${this.getConfiguration().endpoint}`,
|
|
232
|
-
handler: this.retrieve.bind(this),
|
|
233
|
-
responseType: this.getConfiguration().contentType
|
|
234
|
-
}
|
|
235
|
-
];
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Retrieve latest harvested data
|
|
239
|
-
*/
|
|
240
|
-
async retrieve() {
|
|
241
|
-
const config = this.getConfiguration();
|
|
242
|
-
const record = await this.db.getLatestByName(config.name);
|
|
243
|
-
if (!record) {
|
|
244
|
-
return {
|
|
245
|
-
status: 404,
|
|
246
|
-
content: 'No data available'
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
const blob = await record.data();
|
|
250
|
-
return {
|
|
251
|
-
status: 200,
|
|
252
|
-
content: blob,
|
|
253
|
-
headers: { 'Content-Type': record.contentType }
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
349
|
}
|
|
257
350
|
//# sourceMappingURL=harvester.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"harvester.js","sourceRoot":"","sources":["../../src/components/harvester.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"harvester.js","sourceRoot":"","sources":["../../src/components/harvester.ts"],"names":[],"mappings":"AAwBA;;;;;;;;;;;;;;GAcG;AACH,MAAM,iBAAiB;aACK,cAAS,GAAG,IAAI,IAAI,CAAC,sBAAsB,CAAC,CAAA;IAEpE;;;;OAIG;IACH,MAAM,KAAK,QAAQ;QACf,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACnC,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,gBAAgB,CAAC,UAAgB,EAAE,WAA6B;QACnE,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AAI;gBACjB,IAAI,EAAE,MAAM,CAAC,WAAW;gBACxB,GAAG;gBACH,IAAI,EAAE,WAAW;aACpB,CAAC,CAAA;QACN,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map_manager.d.ts","sourceRoot":"","sources":["../../src/components/map_manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"map_manager.d.ts","sourceRoot":"","sources":["../../src/components/map_manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAG9C;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,IAAI,CAAA;IACV,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,QAAQ,EAAE,MAAM,CAAA;IAEhB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED;;;;;;;;;;;;;;;GAeG;AACH,8BAAsB,UAAW,SAAQ,aAAa;IAClD;;;;;;;;;;OAUG;IACG,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC;IAqHnD;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IA+D3B;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,YAAY,CAAC;CAwC1C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tileset_manager.d.ts","sourceRoot":"","sources":["../../src/components/tileset_manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"tileset_manager.d.ts","sourceRoot":"","sources":["../../src/components/tileset_manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAK9C;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,IAAI,CAAA;IACV,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,QAAQ,EAAE,MAAM,CAAA;IAEhB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,UAAU,CAAC,EAAE,MAAM,CAAA;CACtB;AAED;;;;;;;;;;;;;;;GAeG;AACH,8BAAsB,cAAe,SAAQ,aAAa;IACtD;;;;;;;;;;OAUG;IACG,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC;IAsJnD;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,YAAY,CAAC;CAwC1C"}
|
|
@@ -26,11 +26,11 @@ export declare class KnexDatabaseAdapter extends DatabaseAdapter {
|
|
|
26
26
|
/**
|
|
27
27
|
* Create a KnexDatabaseAdapter for PostgreSQL with simplified configuration
|
|
28
28
|
*/
|
|
29
|
-
static forPostgreSQL(pgConfig: PostgreSQLConfig, storage: StorageService,
|
|
29
|
+
static forPostgreSQL(pgConfig: PostgreSQLConfig, storage: StorageService, _tableName?: string): KnexDatabaseAdapter;
|
|
30
30
|
/**
|
|
31
31
|
* Create a KnexDatabaseAdapter for SQLite with simplified configuration
|
|
32
32
|
*/
|
|
33
|
-
static forSQLite(sqliteConfig: SQLiteConfig, storage: StorageService,
|
|
33
|
+
static forSQLite(sqliteConfig: SQLiteConfig, storage: StorageService, _tableName?: string): KnexDatabaseAdapter;
|
|
34
34
|
save(meta: MetadataRow): Promise<DataRecord>;
|
|
35
35
|
delete(id: string, name: string): Promise<void>;
|
|
36
36
|
getById(id: string, name: string): Promise<DataRecord | undefined>;
|
|
@@ -61,6 +61,19 @@ export declare class KnexDatabaseAdapter extends DatabaseAdapter {
|
|
|
61
61
|
findByConditions(tableName: string, conditions: Record<string, any>): Promise<DataRecord[]>;
|
|
62
62
|
updateById(tableName: string, id: number, data: Record<string, any>): Promise<void>;
|
|
63
63
|
close(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Find records for custom tables (returns raw database rows, not DataRecords)
|
|
66
|
+
* This bypasses mapToDataRecord() which assumes standard table structure
|
|
67
|
+
*/
|
|
68
|
+
findCustomTableRecords(tableName: string, conditions?: Record<string, any>): Promise<any[]>;
|
|
69
|
+
/**
|
|
70
|
+
* Get a single custom table record by ID (returns raw database row, not DataRecord)
|
|
71
|
+
*/
|
|
72
|
+
getCustomTableRecordById(tableName: string, id: number): Promise<any | null>;
|
|
73
|
+
/**
|
|
74
|
+
* Insert a record into a custom table (returns the new record ID)
|
|
75
|
+
*/
|
|
76
|
+
insertCustomTableRecord(tableName: string, data: Record<string, any>): Promise<number>;
|
|
64
77
|
/**
|
|
65
78
|
* Get the underlying Knex instance for advanced operations
|
|
66
79
|
*/
|