digitaltwin-core 0.1.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 +125 -0
- package/dist/components/assets_manager.d.ts +384 -0
- package/dist/components/assets_manager.d.ts.map +1 -0
- package/dist/components/assets_manager.js +637 -0
- package/dist/components/assets_manager.js.map +1 -0
- package/dist/components/collector.d.ts +62 -0
- package/dist/components/collector.d.ts.map +1 -0
- package/dist/components/collector.js +80 -0
- package/dist/components/collector.js.map +1 -0
- package/dist/components/global_assets_handler.d.ts +63 -0
- package/dist/components/global_assets_handler.d.ts.map +1 -0
- package/dist/components/global_assets_handler.js +127 -0
- package/dist/components/global_assets_handler.js.map +1 -0
- package/dist/components/handler.d.ts +33 -0
- package/dist/components/handler.d.ts.map +1 -0
- package/dist/components/handler.js +27 -0
- package/dist/components/handler.js.map +1 -0
- package/dist/components/harvester.d.ts +54 -0
- package/dist/components/harvester.d.ts.map +1 -0
- package/dist/components/harvester.js +253 -0
- package/dist/components/harvester.js.map +1 -0
- package/dist/components/index.d.ts +8 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +6 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/interfaces.d.ts +18 -0
- package/dist/components/interfaces.d.ts.map +1 -0
- package/dist/components/interfaces.js +2 -0
- package/dist/components/interfaces.js.map +1 -0
- package/dist/components/types.d.ts +47 -0
- package/dist/components/types.d.ts.map +1 -0
- package/dist/components/types.js +2 -0
- package/dist/components/types.js.map +1 -0
- package/dist/database/adapters/knex_database_adapter.d.ts +47 -0
- package/dist/database/adapters/knex_database_adapter.d.ts.map +1 -0
- package/dist/database/adapters/knex_database_adapter.js +180 -0
- package/dist/database/adapters/knex_database_adapter.js.map +1 -0
- package/dist/database/database_adapter.d.ts +92 -0
- package/dist/database/database_adapter.d.ts.map +1 -0
- package/dist/database/database_adapter.js +6 -0
- package/dist/database/database_adapter.js.map +1 -0
- package/dist/engine/digital_twin_engine.d.ts +237 -0
- package/dist/engine/digital_twin_engine.d.ts.map +1 -0
- package/dist/engine/digital_twin_engine.js +574 -0
- package/dist/engine/digital_twin_engine.js.map +1 -0
- package/dist/engine/endpoints.d.ts +7 -0
- package/dist/engine/endpoints.d.ts.map +1 -0
- package/dist/engine/endpoints.js +18 -0
- package/dist/engine/endpoints.js.map +1 -0
- package/dist/engine/events.d.ts +13 -0
- package/dist/engine/events.d.ts.map +1 -0
- package/dist/engine/events.js +11 -0
- package/dist/engine/events.js.map +1 -0
- package/dist/engine/initializer.d.ts +8 -0
- package/dist/engine/initializer.d.ts.map +1 -0
- package/dist/engine/initializer.js +23 -0
- package/dist/engine/initializer.js.map +1 -0
- package/dist/engine/queue_manager.d.ts +78 -0
- package/dist/engine/queue_manager.d.ts.map +1 -0
- package/dist/engine/queue_manager.js +167 -0
- package/dist/engine/queue_manager.js.map +1 -0
- package/dist/engine/scheduler.d.ts +30 -0
- package/dist/engine/scheduler.d.ts.map +1 -0
- package/dist/engine/scheduler.js +378 -0
- package/dist/engine/scheduler.js.map +1 -0
- package/dist/env/env.d.ts +25 -0
- package/dist/env/env.d.ts.map +1 -0
- package/dist/env/env.js +55 -0
- package/dist/env/env.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/storage/adapters/local_storage_service.d.ts +29 -0
- package/dist/storage/adapters/local_storage_service.d.ts.map +1 -0
- package/dist/storage/adapters/local_storage_service.js +50 -0
- package/dist/storage/adapters/local_storage_service.js.map +1 -0
- package/dist/storage/adapters/ovh_storage_service.d.ts +32 -0
- package/dist/storage/adapters/ovh_storage_service.d.ts.map +1 -0
- package/dist/storage/adapters/ovh_storage_service.js +70 -0
- package/dist/storage/adapters/ovh_storage_service.js.map +1 -0
- package/dist/storage/storage_factory.d.ts +14 -0
- package/dist/storage/storage_factory.d.ts.map +1 -0
- package/dist/storage/storage_factory.js +36 -0
- package/dist/storage/storage_factory.js.map +1 -0
- package/dist/storage/storage_service.d.ts +26 -0
- package/dist/storage/storage_service.d.ts.map +1 -0
- package/dist/storage/storage_service.js +7 -0
- package/dist/storage/storage_service.js.map +1 -0
- package/dist/types/data_record.d.ts +17 -0
- package/dist/types/data_record.d.ts.map +1 -0
- package/dist/types/data_record.js +2 -0
- package/dist/types/data_record.js.map +1 -0
- package/dist/utils/logger.d.ts +17 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +35 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/map_to_data_record.d.ts +10 -0
- package/dist/utils/map_to_data_record.d.ts.map +1 -0
- package/dist/utils/map_to_data_record.js +21 -0
- package/dist/utils/map_to_data_record.js.map +1 -0
- package/dist/utils/servable_endpoint.d.ts +6 -0
- package/dist/utils/servable_endpoint.d.ts.map +1 -0
- package/dist/utils/servable_endpoint.js +15 -0
- package/dist/utils/servable_endpoint.js.map +1 -0
- package/package.json +95 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Component, ScheduleRunnable, Servable } from './interfaces.js';
|
|
2
|
+
import { CollectorConfiguration } from './types.js';
|
|
3
|
+
import { DatabaseAdapter } from '../database/database_adapter.js';
|
|
4
|
+
import { StorageService } from '../storage/storage_service.js';
|
|
5
|
+
import { DataResponse } from './types.js';
|
|
6
|
+
import type { HttpMethod } from "../engine/endpoints.js";
|
|
7
|
+
/**
|
|
8
|
+
* Base abstract class for defining a Collector component.
|
|
9
|
+
* A Collector is responsible for fetching raw data from a source,
|
|
10
|
+
* storing it via a StorageService, and indexing metadata via a DatabaseAdapter.
|
|
11
|
+
* It also exposes an HTTP GET endpoint to retrieve the latest collected data.
|
|
12
|
+
*/
|
|
13
|
+
export declare abstract class Collector implements Component<CollectorConfiguration>, ScheduleRunnable, Servable {
|
|
14
|
+
/** Database adapter used to index metadata */
|
|
15
|
+
protected db: DatabaseAdapter;
|
|
16
|
+
/** Storage service used to save collected blobs */
|
|
17
|
+
protected storage: StorageService;
|
|
18
|
+
/**
|
|
19
|
+
* Injects dependencies into the collector.
|
|
20
|
+
* @param db - The database adapter
|
|
21
|
+
* @param storage - The storage service
|
|
22
|
+
*/
|
|
23
|
+
setDependencies(db: DatabaseAdapter, storage: StorageService): void;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the static configuration of the collector.
|
|
26
|
+
* Must be implemented by subclasses.
|
|
27
|
+
*/
|
|
28
|
+
abstract getConfiguration(): CollectorConfiguration;
|
|
29
|
+
/**
|
|
30
|
+
* Returns a cron-style string defining the execution schedule.
|
|
31
|
+
* Must be implemented by subclasses.
|
|
32
|
+
*/
|
|
33
|
+
abstract getSchedule(): string;
|
|
34
|
+
/**
|
|
35
|
+
* Actual logic to collect the data.
|
|
36
|
+
* Must be implemented by subclasses.
|
|
37
|
+
* @returns A Buffer containing the raw data.
|
|
38
|
+
*/
|
|
39
|
+
abstract collect(): Promise<Buffer>;
|
|
40
|
+
/**
|
|
41
|
+
* Executes the collector's data collection process.
|
|
42
|
+
* Saves the data to storage and metadata to the database if collection is successful.
|
|
43
|
+
* @returns The collected Buffer, or void if none.
|
|
44
|
+
*/
|
|
45
|
+
run(): Promise<Buffer | void>;
|
|
46
|
+
/**
|
|
47
|
+
* Defines the HTTP endpoints exposed by this component.
|
|
48
|
+
* @returns A list of route definitions.
|
|
49
|
+
*/
|
|
50
|
+
getEndpoints(): Array<{
|
|
51
|
+
method: HttpMethod;
|
|
52
|
+
path: string;
|
|
53
|
+
handler: (...args: any[]) => any;
|
|
54
|
+
responseType?: string;
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* Handler to retrieve the most recently collected data.
|
|
58
|
+
* @returns A DataResponse containing status, content, and headers.
|
|
59
|
+
*/
|
|
60
|
+
retrieve(): Promise<DataResponse>;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=collector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collector.d.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80 @@
|
|
|
1
|
+
import { engineEventBus } from "../engine/events.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base abstract class for defining a Collector component.
|
|
4
|
+
* A Collector is responsible for fetching raw data from a source,
|
|
5
|
+
* storing it via a StorageService, and indexing metadata via a DatabaseAdapter.
|
|
6
|
+
* It also exposes an HTTP GET endpoint to retrieve the latest collected data.
|
|
7
|
+
*/
|
|
8
|
+
export class Collector {
|
|
9
|
+
/**
|
|
10
|
+
* Injects dependencies into the collector.
|
|
11
|
+
* @param db - The database adapter
|
|
12
|
+
* @param storage - The storage service
|
|
13
|
+
*/
|
|
14
|
+
setDependencies(db, storage) {
|
|
15
|
+
this.db = db;
|
|
16
|
+
this.storage = storage;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Executes the collector's data collection process.
|
|
20
|
+
* Saves the data to storage and metadata to the database if collection is successful.
|
|
21
|
+
* @returns The collected Buffer, or void if none.
|
|
22
|
+
*/
|
|
23
|
+
async run() {
|
|
24
|
+
const result = await this.collect();
|
|
25
|
+
if (result) {
|
|
26
|
+
const config = this.getConfiguration();
|
|
27
|
+
const now = new Date();
|
|
28
|
+
const url = await this.storage.save(result, config.name);
|
|
29
|
+
await this.db.save({
|
|
30
|
+
name: config.name,
|
|
31
|
+
type: config.contentType,
|
|
32
|
+
url,
|
|
33
|
+
date: now,
|
|
34
|
+
});
|
|
35
|
+
// Emit event after successful collection
|
|
36
|
+
engineEventBus.emit('component:event', {
|
|
37
|
+
type: 'collector:completed',
|
|
38
|
+
componentName: config.name,
|
|
39
|
+
timestamp: now,
|
|
40
|
+
data: { bytesCollected: result.length }
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Defines the HTTP endpoints exposed by this component.
|
|
47
|
+
* @returns A list of route definitions.
|
|
48
|
+
*/
|
|
49
|
+
getEndpoints() {
|
|
50
|
+
return [
|
|
51
|
+
{
|
|
52
|
+
method: 'get', // ici, 'get' est bien assignable à HttpMethod
|
|
53
|
+
path: `/${this.getConfiguration().endpoint}`,
|
|
54
|
+
handler: this.retrieve.bind(this),
|
|
55
|
+
responseType: this.getConfiguration().contentType,
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Handler to retrieve the most recently collected data.
|
|
61
|
+
* @returns A DataResponse containing status, content, and headers.
|
|
62
|
+
*/
|
|
63
|
+
async retrieve() {
|
|
64
|
+
const config = this.getConfiguration();
|
|
65
|
+
const record = await this.db.getLatestByName(config.name);
|
|
66
|
+
if (!record) {
|
|
67
|
+
return {
|
|
68
|
+
status: 404,
|
|
69
|
+
content: 'No data available',
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const blob = await record.data();
|
|
73
|
+
return {
|
|
74
|
+
status: 200,
|
|
75
|
+
content: blob,
|
|
76
|
+
headers: { 'Content-Type': record.contentType },
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=collector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collector.js","sourceRoot":"","sources":["../../src/components/collector.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEpD;;;;;GAKG;AACH,MAAM,OAAgB,SAAS;IAO3B;;;;OAIG;IACH,eAAe,CAAC,EAAmB,EAAE,OAAuB;QACxD,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;QACZ,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IAC1B,CAAC;IAqBD;;;;OAIG;IACH,KAAK,CAAC,GAAG;QACL,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,EAAE,CAAA;QAEnC,IAAI,MAAM,EAAE,CAAC;YACT,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAA;YACtC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE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AAI,EAAE,CAAA;QAEhC,OAAO;YACH,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,EAAE,cAAc,EAAE,MAAM,CAAC,WAAW,EAAE;SAClD,CAAA;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Handler } from './handler.js';
|
|
2
|
+
import { ComponentConfiguration, DataResponse } from './types.js';
|
|
3
|
+
import { AssetsManager } from './assets_manager.js';
|
|
4
|
+
/**
|
|
5
|
+
* Global assets handler that provides access to ALL assets across ALL asset managers.
|
|
6
|
+
*
|
|
7
|
+
* This handler aggregates assets from all registered AssetsManager instances
|
|
8
|
+
* without duplicating their logic or hardcoding component names.
|
|
9
|
+
*
|
|
10
|
+
* @class GlobalAssetsHandler
|
|
11
|
+
* @extends {Handler}
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const globalHandler = new GlobalAssetsHandler()
|
|
16
|
+
* globalHandler.setAssetsManagers([gltfManager, pointcloudManager])
|
|
17
|
+
*
|
|
18
|
+
* // Usage:
|
|
19
|
+
* // GET /assets/all - Returns all assets from all managers
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class GlobalAssetsHandler extends Handler {
|
|
23
|
+
private assetsManagers;
|
|
24
|
+
/**
|
|
25
|
+
* Inject AssetsManager dependencies (called by engine)
|
|
26
|
+
*/
|
|
27
|
+
setAssetsManagers(assetsManagers: AssetsManager[]): void;
|
|
28
|
+
/**
|
|
29
|
+
* Component configuration for the global assets handler
|
|
30
|
+
*/
|
|
31
|
+
getConfiguration(): ComponentConfiguration;
|
|
32
|
+
/**
|
|
33
|
+
* Get all assets from all registered asset managers.
|
|
34
|
+
*
|
|
35
|
+
* This method delegates to each AssetsManager's getAllAssets() method
|
|
36
|
+
* and aggregates the results with proper endpoint URLs.
|
|
37
|
+
*
|
|
38
|
+
* @returns {Promise<DataResponse>} JSON response with all assets
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* // GET /assets/all
|
|
43
|
+
* // Returns: {
|
|
44
|
+
* // total: 5,
|
|
45
|
+
* // assets: [
|
|
46
|
+
* // { id: 1, component: "gltf", url: "/gltf/1", ... },
|
|
47
|
+
* // { id: 2, component: "pointcloud", url: "/pointcloud/2", ... }
|
|
48
|
+
* // ]
|
|
49
|
+
* // }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
getAllAssets(): Promise<DataResponse>;
|
|
53
|
+
/**
|
|
54
|
+
* HTTP endpoints for global assets
|
|
55
|
+
*/
|
|
56
|
+
getEndpoints(): Array<{
|
|
57
|
+
method: any;
|
|
58
|
+
path: string;
|
|
59
|
+
handler: (...args: any[]) => any;
|
|
60
|
+
responseType?: string;
|
|
61
|
+
}>;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=global_assets_handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global_assets_handler.d.ts","sourceRoot":"","sources":["../../src/components/global_assets_handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,mBAAoB,SAAQ,OAAO;IAC5C,OAAO,CAAC,cAAc,CAAsB;IAE5C;;OAEG;IACH,iBAAiB,CAAC,cAAc,EAAE,aAAa,EAAE,GAAG,IAAI;IAIxD;;OAEG;IACH,gBAAgB,IAAI,sBAAsB;IAS1C;;;;;;;;;;;;;;;;;;;OAmBG;IACG,YAAY,IAAI,OAAO,CAAC,YAAY,CAAC;IAuD3C;;OAEG;IACH,YAAY,IAAI,KAAK,CAAC;QAClB,MAAM,EAAE,GAAG,CAAA;QACX,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAA;QAChC,YAAY,CAAC,EAAE,MAAM,CAAA;KACxB,CAAC;CAUL"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Handler } from './handler.js';
|
|
2
|
+
/**
|
|
3
|
+
* Global assets handler that provides access to ALL assets across ALL asset managers.
|
|
4
|
+
*
|
|
5
|
+
* This handler aggregates assets from all registered AssetsManager instances
|
|
6
|
+
* without duplicating their logic or hardcoding component names.
|
|
7
|
+
*
|
|
8
|
+
* @class GlobalAssetsHandler
|
|
9
|
+
* @extends {Handler}
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const globalHandler = new GlobalAssetsHandler()
|
|
14
|
+
* globalHandler.setAssetsManagers([gltfManager, pointcloudManager])
|
|
15
|
+
*
|
|
16
|
+
* // Usage:
|
|
17
|
+
* // GET /assets/all - Returns all assets from all managers
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export class GlobalAssetsHandler extends Handler {
|
|
21
|
+
constructor() {
|
|
22
|
+
super(...arguments);
|
|
23
|
+
this.assetsManagers = [];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Inject AssetsManager dependencies (called by engine)
|
|
27
|
+
*/
|
|
28
|
+
setAssetsManagers(assetsManagers) {
|
|
29
|
+
this.assetsManagers = assetsManagers;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Component configuration for the global assets handler
|
|
33
|
+
*/
|
|
34
|
+
getConfiguration() {
|
|
35
|
+
return {
|
|
36
|
+
name: 'global_assets',
|
|
37
|
+
description: 'Global handler for all assets across all managers',
|
|
38
|
+
contentType: 'application/json',
|
|
39
|
+
tags: ['assets', 'global', 'all']
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get all assets from all registered asset managers.
|
|
44
|
+
*
|
|
45
|
+
* This method delegates to each AssetsManager's getAllAssets() method
|
|
46
|
+
* and aggregates the results with proper endpoint URLs.
|
|
47
|
+
*
|
|
48
|
+
* @returns {Promise<DataResponse>} JSON response with all assets
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // GET /assets/all
|
|
53
|
+
* // Returns: {
|
|
54
|
+
* // total: 5,
|
|
55
|
+
* // assets: [
|
|
56
|
+
* // { id: 1, component: "gltf", url: "/gltf/1", ... },
|
|
57
|
+
* // { id: 2, component: "pointcloud", url: "/pointcloud/2", ... }
|
|
58
|
+
* // ]
|
|
59
|
+
* // }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
async getAllAssets() {
|
|
63
|
+
try {
|
|
64
|
+
const allAssets = [];
|
|
65
|
+
// Iterate through all registered AssetsManager instances
|
|
66
|
+
for (const manager of this.assetsManagers) {
|
|
67
|
+
try {
|
|
68
|
+
const assets = await manager.getAllAssets();
|
|
69
|
+
const config = manager.getConfiguration();
|
|
70
|
+
// Transform assets to include component info and URLs
|
|
71
|
+
const transformedAssets = assets.map(asset => ({
|
|
72
|
+
id: asset.id,
|
|
73
|
+
component: config.name,
|
|
74
|
+
date: asset.date,
|
|
75
|
+
contentType: asset.contentType,
|
|
76
|
+
description: asset.description,
|
|
77
|
+
source: asset.source,
|
|
78
|
+
owner_id: asset.owner_id,
|
|
79
|
+
filename: asset.filename,
|
|
80
|
+
// Generate URLs using the manager's configuration
|
|
81
|
+
url: `/${config.name}/${asset.id}`,
|
|
82
|
+
download_url: `/${config.name}/${asset.id}/download`
|
|
83
|
+
}));
|
|
84
|
+
allAssets.push(...transformedAssets);
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
// Skip this manager if it fails, don't break the whole operation
|
|
88
|
+
console.warn(`Failed to get assets from manager ${manager.getConfiguration().name}:`, error);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Sort by date (newest first)
|
|
93
|
+
allAssets.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
|
|
94
|
+
return {
|
|
95
|
+
status: 200,
|
|
96
|
+
content: JSON.stringify({
|
|
97
|
+
total: allAssets.length,
|
|
98
|
+
assets: allAssets
|
|
99
|
+
}),
|
|
100
|
+
headers: { 'Content-Type': 'application/json' }
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
return {
|
|
105
|
+
status: 500,
|
|
106
|
+
content: JSON.stringify({
|
|
107
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
108
|
+
}),
|
|
109
|
+
headers: { 'Content-Type': 'application/json' }
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* HTTP endpoints for global assets
|
|
115
|
+
*/
|
|
116
|
+
getEndpoints() {
|
|
117
|
+
return [
|
|
118
|
+
{
|
|
119
|
+
method: 'get',
|
|
120
|
+
path: '/assets/all',
|
|
121
|
+
handler: this.getAllAssets.bind(this),
|
|
122
|
+
responseType: 'application/json',
|
|
123
|
+
}
|
|
124
|
+
];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=global_assets_handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global_assets_handler.js","sourceRoot":"","sources":["../../src/components/global_assets_handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAItC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,mBAAoB,SAAQ,OAAO;IAAhD;;QACY,mBAAc,GAAoB,EAAE,CAAA;IAkHhD,CAAC;IAhHG;;OAEG;IACH,iBAAiB,CAAC,cAA+B;QAC7C,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;IACxC,CAAC;IAED;;OAEG;IACH,gBAAgB;QACZ,OAAO;YACH,IAAI,EAAE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BAAgB,EAAE,CAAC,IAAI,GAAG,EAAE,KAAK,CAAC,CAAA;oBAC5F,SAAQ;gBACZ,CAAC;YACL,CAAC;YAED,8BAA8B;YAC9B,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC,CAAA;YAEjF,OAAO;gBACH,MAAM,EAAE,GAAG;gBACX,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC;oBACpB,KAAK,EAAE,SAAS,CAAC,MAAM;oBACvB,MAAM,EAAE,SAAS;iBACpB,CAAC;gBACF,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;aAClD,CAAA;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO;gBACH,MAAM,EAAE,GAAG;gBACX,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC;oBACpB,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;iBAClE,CAAC;gBACF,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;aAClD,CAAA;QACL,CAAC;IACL,CAAC;IAED;;OAEG;IACH,YAAY;QAMR,OAAO;YACH;gBACI,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,aAAa;gBACnB,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;gBACrC,YAAY,EAAE,kBAAkB;aACnC;SACJ,CAAA;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Component, Servable } from './interfaces.js';
|
|
2
|
+
import { ComponentConfiguration } from './types.js';
|
|
3
|
+
import { DataResponse } from './types.js';
|
|
4
|
+
import { HttpMethod } from "../engine/endpoints.js";
|
|
5
|
+
/**
|
|
6
|
+
* Description of a runtime HTTP endpoint handler.
|
|
7
|
+
*/
|
|
8
|
+
type EndpointDescriptor = {
|
|
9
|
+
method: HttpMethod;
|
|
10
|
+
path: string;
|
|
11
|
+
responseType?: string;
|
|
12
|
+
handler: (...args: any[]) => Promise<DataResponse>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Base abstract class for defining a Handler component.
|
|
16
|
+
* A Handler is a stateless, servable component that exposes HTTP endpoints,
|
|
17
|
+
* useful for on-demand computation or utility services.
|
|
18
|
+
*/
|
|
19
|
+
export declare abstract class Handler implements Component, Servable {
|
|
20
|
+
/**
|
|
21
|
+
* Returns the static configuration of the handler.
|
|
22
|
+
* Must be implemented by subclasses.
|
|
23
|
+
*/
|
|
24
|
+
abstract getConfiguration(): ComponentConfiguration;
|
|
25
|
+
/**
|
|
26
|
+
* Resolves and returns the list of servable endpoints defined on the class.
|
|
27
|
+
* Uses static metadata declared on the constructor (__endpoints).
|
|
28
|
+
* @returns A list of endpoint descriptors mapping method/path to handlers.
|
|
29
|
+
*/
|
|
30
|
+
getEndpoints(): EndpointDescriptor[];
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/components/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAYpD;;GAEG;AACH,KAAK,kBAAkB,GAAG;IACtB,MAAM,EAAE,UAAU,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,YAAY,CAAC,CAAA;CACrD,CAAA;AAED;;;;GAIG;AACH,8BAAsB,OAAQ,YAAW,SAAS,EAAE,QAAQ;IACxD;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,IAAI,sBAAsB;IAEnD;;;;OAIG;IACH,YAAY,IAAI,kBAAkB,EAAE;CAevC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base abstract class for defining a Handler component.
|
|
3
|
+
* A Handler is a stateless, servable component that exposes HTTP endpoints,
|
|
4
|
+
* useful for on-demand computation or utility services.
|
|
5
|
+
*/
|
|
6
|
+
export class Handler {
|
|
7
|
+
/**
|
|
8
|
+
* Resolves and returns the list of servable endpoints defined on the class.
|
|
9
|
+
* Uses static metadata declared on the constructor (__endpoints).
|
|
10
|
+
* @returns A list of endpoint descriptors mapping method/path to handlers.
|
|
11
|
+
*/
|
|
12
|
+
getEndpoints() {
|
|
13
|
+
const config = this.getConfiguration();
|
|
14
|
+
const ctor = this.constructor;
|
|
15
|
+
const endpoints = ctor.__endpoints || [];
|
|
16
|
+
return endpoints.map((ep) => {
|
|
17
|
+
const handlerFn = this[ep.handlerName].bind(this);
|
|
18
|
+
return {
|
|
19
|
+
method: ep.method,
|
|
20
|
+
path: ep.path,
|
|
21
|
+
responseType: ep.responseType || config.contentType,
|
|
22
|
+
handler: handlerFn,
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/components/handler.ts"],"names":[],"mappings":"AAyBA;;;;GAIG;AACH,MAAM,OAAgB,OAAO;IAOzB;;;;OAIG;IACH,YAAY;QACR,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAA;QACtC,MAAM,IAAI,GAAG,IAAI,CAAC,WAA+C,CAAA;QACjE,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,IAAI,EAAE,CAAA;QAExC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;YACxB,MAAM,SAAS,GAAI,IAA4B,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAkC,CAAA;YAC3G,OAAO;gBACH,MAAM,EAAE,EAAE,CAAC,MAAM;gBACjB,IAAI,EAAE,EAAE,CAAC,IAAI;gBACb,YAAY,EAAE,EAAE,CAAC,YAAY,IAAI,MAAM,CAAC,WAAW;gBACnD,OAAO,EAAE,SAAS;aACrB,CAAA;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Component, ScheduleRunnable, Servable } from './interfaces.js';
|
|
2
|
+
import { DataResponse, HarvesterConfiguration } from "./types.js";
|
|
3
|
+
import { DataRecord } from "../types/data_record.js";
|
|
4
|
+
import { DatabaseAdapter } from '../database/database_adapter.js';
|
|
5
|
+
import { StorageService } from '../storage/storage_service.js';
|
|
6
|
+
import type { HttpMethod } from "../engine/endpoints.js";
|
|
7
|
+
/**
|
|
8
|
+
* Abstract Harvester class for processing collected data
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class Harvester implements Component<HarvesterConfiguration>, ScheduleRunnable, Servable {
|
|
11
|
+
protected db: DatabaseAdapter;
|
|
12
|
+
protected storage: StorageService;
|
|
13
|
+
setDependencies(db: DatabaseAdapter, storage: StorageService): void;
|
|
14
|
+
abstract getConfiguration(): HarvesterConfiguration;
|
|
15
|
+
/**
|
|
16
|
+
* Override to make schedule optional based on trigger mode
|
|
17
|
+
*/
|
|
18
|
+
getSchedule(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Allow subclasses to define custom schedule
|
|
21
|
+
*/
|
|
22
|
+
getCustomSchedule?(): string;
|
|
23
|
+
abstract harvest(sourceData: DataRecord | DataRecord[], dependenciesData: Record<string, DataRecord | DataRecord[]>): Promise<Buffer | Buffer[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Main execution method - NOUVELLE VERSION SIMPLIFIÉE
|
|
26
|
+
*/
|
|
27
|
+
run(): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Get source data within the specified range
|
|
30
|
+
*/
|
|
31
|
+
private getSourceData;
|
|
32
|
+
/**
|
|
33
|
+
* Get data from dependent components
|
|
34
|
+
*/
|
|
35
|
+
private getDependenciesData;
|
|
36
|
+
/**
|
|
37
|
+
* Store harvesting results
|
|
38
|
+
*/
|
|
39
|
+
private storeResults;
|
|
40
|
+
/**
|
|
41
|
+
* HTTP endpoints
|
|
42
|
+
*/
|
|
43
|
+
getEndpoints(): Array<{
|
|
44
|
+
method: HttpMethod;
|
|
45
|
+
path: string;
|
|
46
|
+
handler: (...args: any[]) => any;
|
|
47
|
+
responseType?: string;
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* Retrieve latest harvested data
|
|
51
|
+
*/
|
|
52
|
+
retrieve(): Promise<DataResponse>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=harvester.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harvester.d.ts","sourceRoot":"","sources":["../../src/components/harvester.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AACvE,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAkFxD;;GA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