@node-i3x/app 0.1.0 → 0.2.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/src/server.ts DELETED
@@ -1,82 +0,0 @@
1
- import {
2
- consoleLogger,
3
- HistoryService,
4
- ModelService,
5
- SubscriptionService,
6
- ValueService,
7
- } from '@node-i3x/core';
8
- import { OpcUaClient, OpcUaDataSourceAdapter } from '@node-i3x/opcua-connector';
9
- import { createApp } from '@node-i3x/rest-server';
10
- import type { I3xConfig } from './config.js';
11
- import { printBanner } from './banner.js';
12
-
13
- export async function startServer(
14
- config: I3xConfig,
15
- version: string,
16
- ): Promise<void> {
17
- const logger = consoleLogger;
18
-
19
- // 1. Outbound adapter (OPC UA)
20
- const opcuaClient = new OpcUaClient(
21
- {
22
- endpointUrl: config.endpoint,
23
- securityMode: config.securityMode,
24
- optimizedClient: config.optimizedClient,
25
- },
26
- logger,
27
- );
28
- const dataSource = new OpcUaDataSourceAdapter(opcuaClient, logger);
29
-
30
- // 2. Domain services (inject the port)
31
- const modelService = new ModelService(dataSource, logger);
32
- const valueService = new ValueService(dataSource, modelService, logger);
33
- const historyService = new HistoryService(dataSource, modelService, logger);
34
- const subscriptionService = new SubscriptionService(
35
- dataSource,
36
- modelService,
37
- logger,
38
- config.subscriptionInterval,
39
- );
40
-
41
- // 3. Inbound adapter (REST)
42
- const app = await createApp({
43
- dataSource,
44
- modelService,
45
- valueService,
46
- historyService,
47
- subscriptionService,
48
- logger,
49
- });
50
-
51
- // 4. Connect to OPC UA
52
- await dataSource.connect();
53
-
54
- // 5. Preload model
55
- let nodeCount: number | undefined;
56
- if (config.modelPreload) {
57
- try {
58
- const model = await modelService.preloadModel();
59
- nodeCount = model.nodesById.size;
60
- } catch (err) {
61
- logger.error('Model preload failed: ' + String(err));
62
- if (config.failOnPreloadError) process.exit(1);
63
- }
64
- }
65
-
66
- // 6. Start HTTP server
67
- await app.listen({ port: config.port, host: config.host });
68
-
69
- // 7. Banner
70
- printBanner(version, config, nodeCount);
71
-
72
- // 8. Graceful shutdown
73
- const shutdown = async () => {
74
- logger.info('Shutting down...');
75
- await app.close();
76
- await subscriptionService.close();
77
- await dataSource.disconnect();
78
- process.exit(0);
79
- };
80
- process.on('SIGINT', shutdown);
81
- process.on('SIGTERM', shutdown);
82
- }