@yarkivaev/scada 2.18.0 → 2.20.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/index.js +17 -0
- package/package.json +4 -2
- package/src/application/cycleTimelineFetch.js +56 -0
- package/src/application/deploy/collectorProcesses.js +1 -0
- package/src/application/deploy/collectorSourcePlan.js +41 -0
- package/src/application/deploy/compileCollectorTasks.js +2 -2
- package/src/application/deploy/edgeDescriptors.js +31 -0
- package/src/application/deploy/fieldbusSourcePlan.js +93 -0
- package/src/application/deploy/plantBindingProfile.js +24 -0
- package/src/application/deploy/topologyGraph.js +81 -0
- package/src/application/edgeOperatorCatalog.js +9 -7
- package/src/application/mcp/analyticsMcpPort.js +20 -0
- package/src/application/mcp/analyticsNamespaceNodes.js +29 -0
- package/src/application/mcp/analyticsTextContent.js +13 -0
- package/src/application/mcp/plantReadPorts.js +168 -0
- package/src/application/mcp/textContentCatalog.js +7 -0
- package/src/application/operationPrefixes.js +67 -0
- package/src/application/operatorCatalogView.js +8 -0
- package/src/application/projectPlantShops.js +17 -0
- package/src/application/runtime/collectorDslManifest.js +44 -0
- package/src/application/runtime/collectorLaunch.js +34 -0
- package/src/application/runtime/collectorOptions.js +21 -0
- package/src/application/runtime/controlDeliveryEnvironment.js +19 -0
- package/src/application/runtime/embeddedCollectors.js +6 -0
- package/src/application/runtime/index.js +7 -1
- package/src/application/runtime/pagedDelivery.js +87 -0
- package/src/application/runtime/resolveSecrets.js +9 -0
- package/src/application/siteOperatorCatalog.js +8 -7
- package/src/application/siteRuntime/checkpointedOperationPoll.js +77 -0
- package/src/application/siteRuntime/cutoverOperations.js +25 -0
- package/src/application/siteRuntime/databaseMigrations.js +27 -0
- package/src/application/siteRuntime/edgeMetricsStore.js +35 -0
- package/src/application/siteRuntime/history.js +29 -0
- package/src/application/siteRuntime/index.js +16 -0
- package/src/application/siteRuntime/measurementTopic.js +9 -0
- package/src/application/siteRuntime/operationFederation.js +15 -0
- package/src/application/siteRuntime/operationSnapshot.js +18 -0
- package/src/application/siteRuntime/operatorField.js +49 -0
- package/src/application/siteRuntime/operatorUpdates.js +37 -0
- package/src/application/siteRuntime/telemetry.js +31 -0
- package/src/application/siteRuntime/telemetryBackfillCommand.js +64 -0
- package/src/application/timelineMetrics.js +36 -0
- package/src/domain/timeline/cyclePhases.js +191 -0
- package/src/domain/timeline/taggedCycleWindows.js +17 -0
- package/src/domain/timeline/taggedSegment.js +47 -0
- package/src/domain/timeline/taggedTimeline.js +98 -0
- package/src/domain/timeline/timelineSegment.js +25 -0
- package/src/infrastructure/deploy/brokerFleetPolicy.js +91 -0
- package/src/infrastructure/deploy/configuredArchivePlan.js +25 -0
- package/src/infrastructure/deploy/configuredBrokerRoutes.js +34 -0
- package/src/infrastructure/deploy/configuredClassification.js +74 -0
- package/src/infrastructure/deploy/configuredCollectorChartDeployment.js +22 -0
- package/src/infrastructure/deploy/configuredControlPlane.js +116 -0
- package/src/infrastructure/deploy/configuredDeploymentCredentials.js +45 -0
- package/src/infrastructure/deploy/configuredEtcdInventory.js +30 -0
- package/src/infrastructure/deploy/configuredRuntimeCapabilities.js +14 -0
- package/src/infrastructure/deploy/configuredSiteAssets.js +50 -0
- package/src/infrastructure/deploy/configuredStagedDeployment.js +48 -0
- package/src/infrastructure/deploy/controlPlaneCli.js +17 -0
- package/src/infrastructure/deploy/highAvailability/configuredBrokerReconciliation.js +21 -0
- package/src/infrastructure/deploy/highAvailability/historyWatermark.js +2 -2
- package/src/infrastructure/deploy/highAvailability/index.js +3 -1
- package/src/infrastructure/deploy/highAvailability/replicaHistoryStore.js +7 -0
- package/src/infrastructure/deploy/index.js +22 -1
- package/src/infrastructure/deploy/mixedStoreHistory.js +27 -0
- package/src/infrastructure/deploy/publicBrokerPlan.js +15 -0
- package/src/infrastructure/deploy/siteBrokerDefinitions.js +97 -0
- package/src/infrastructure/deploy/stagedSitePlan.js +132 -0
- package/src/infrastructure/deploy/supervisedServicePlan.js +82 -0
- package/src/infrastructure/http/edge/attachClassify.js +30 -0
- package/src/infrastructure/http/edge/classifyProxy.js +72 -0
- package/src/infrastructure/http/edge/classifyRecord.js +32 -0
- package/src/infrastructure/http/edge/classifyRouting.js +14 -0
- package/src/infrastructure/http/edge/siteAccess.js +7 -0
- package/src/infrastructure/http/edge/writeGuard.js +84 -0
- package/src/infrastructure/http/plant/routes/machineOperationList.js +18 -0
- package/src/infrastructure/http/plant/routes/operationRoute.js +2 -11
- package/src/infrastructure/http/plant/routes/operatorRoute.js +25 -0
- package/src/infrastructure/http/plant/streams/operationStream.js +25 -37
- package/src/infrastructure/ingest/mqtt/modbusDeviceSpec.js +5 -28
- package/src/infrastructure/ingest/mqtt/registerPoint.js +2 -2
- package/src/infrastructure/mdmesh/adminReconciliation.js +19 -0
- package/src/infrastructure/mdmesh/bootstrapMdmeshCredentials.js +4 -4
- package/src/infrastructure/mdmesh/controllerOperation.js +17 -0
- package/src/infrastructure/mdmesh/index.js +3 -0
- package/src/infrastructure/mdmesh/publishApk.js +30 -0
- package/src/infrastructure/persistence/clickhouse/metricBursts.js +73 -0
- package/src/infrastructure/persistence/pg/cyclePhaseQuery.js +168 -0
- package/src/infrastructure/persistence/pg/cyclePrior.js +96 -0
- package/src/infrastructure/persistence/pg/operatorFieldStore.js +50 -0
- package/src/infrastructure/streams/boundedTextFrames.js +27 -0
- package/src/infrastructure/streams/framedSerialSource.js +25 -0
- package/src/infrastructure/streams/index.js +6 -0
- package/src/infrastructure/streams/namedSerialDevices.js +26 -0
- package/src/infrastructure/streams/pollSnapshot.js +11 -0
- package/src/infrastructure/streams/serialLine.js +26 -0
- package/src/infrastructure/streams/watchCurrentReading.js +31 -0
- package/src/infrastructure/streams/windowPublication.js +73 -0
package/index.js
CHANGED
|
@@ -158,3 +158,20 @@ export { default as executeKubeSeed } from './src/infrastructure/deploy/executeK
|
|
|
158
158
|
export { default as edgeTelemetryRuntime } from './src/infrastructure/ingest/telemetry/edgeTelemetryRuntime.js';
|
|
159
159
|
export { default as kubeServiceAccount } from './src/infrastructure/management/kubeServiceAccount.js';
|
|
160
160
|
export * from './src/infrastructure/deploy/index.js';
|
|
161
|
+
export { default as plantReadPorts } from './src/application/mcp/plantReadPorts.js';
|
|
162
|
+
export { default as analyticsMcpPort } from './src/application/mcp/analyticsMcpPort.js';
|
|
163
|
+
export { default as analyticsNamespaceNodes } from './src/application/mcp/analyticsNamespaceNodes.js';
|
|
164
|
+
export { default as analyticsTextContent } from './src/application/mcp/analyticsTextContent.js';
|
|
165
|
+
export { modbusFloat } from './src/infrastructure/ingest/mqtt/registerPoint.js';
|
|
166
|
+
export { default as cyclePrior } from './src/infrastructure/persistence/pg/cyclePrior.js';
|
|
167
|
+
export { default as cyclePhaseQuery } from './src/infrastructure/persistence/pg/cyclePhaseQuery.js';
|
|
168
|
+
export { default as operationPrefixes } from './src/application/operationPrefixes.js';
|
|
169
|
+
export { default as cyclePhases } from './src/domain/timeline/cyclePhases.js';
|
|
170
|
+
export { default as cycleTimelineFetch } from './src/application/cycleTimelineFetch.js';
|
|
171
|
+
export { default as textContentCatalog } from './src/application/mcp/textContentCatalog.js';
|
|
172
|
+
export { timelineSegments, measurementBounds, measurementPeaks } from './src/application/timelineMetrics.js';
|
|
173
|
+
export { default as projectPlantShops } from './src/application/projectPlantShops.js';
|
|
174
|
+
export { default as taggedTimeline } from './src/domain/timeline/taggedTimeline.js';
|
|
175
|
+
export { default as taggedSegment } from './src/domain/timeline/taggedSegment.js';
|
|
176
|
+
export { default as timelineSegment } from './src/domain/timeline/timelineSegment.js';
|
|
177
|
+
export { default as taggedCycleWindows } from './src/domain/timeline/taggedCycleWindows.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yarkivaev/scada",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.0",
|
|
4
4
|
"description": "SCADA domain objects, state persistence, and plant monitoring",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
"./control": "./src/application/control/index.js",
|
|
24
24
|
"./mdmesh": "./src/infrastructure/mdmesh/index.js",
|
|
25
25
|
"./deployment": "./src/infrastructure/deploy/index.js",
|
|
26
|
-
"./deployment/high-availability": "./src/infrastructure/deploy/highAvailability/index.js"
|
|
26
|
+
"./deployment/high-availability": "./src/infrastructure/deploy/highAvailability/index.js",
|
|
27
|
+
"./site/runtime": "./src/application/siteRuntime/index.js",
|
|
28
|
+
"./http/site-access": "./src/infrastructure/http/edge/siteAccess.js"
|
|
27
29
|
},
|
|
28
30
|
"bin": {
|
|
29
31
|
"modbus-to-mqtt": "./src/bin/modbus-to-mqtt.js",
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sorts timeline rows by start time ascending.
|
|
3
|
+
*
|
|
4
|
+
* @param {object} leftRow - left timeline row
|
|
5
|
+
* @param {object} rightRow - right timeline row
|
|
6
|
+
* @returns {number} sort order
|
|
7
|
+
*/
|
|
8
|
+
function sortByStartTime(leftRow, rightRow) {
|
|
9
|
+
return leftRow.start_time.getTime() - rightRow.start_time.getTime();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Merges timeline rows by start time without duplicates.
|
|
14
|
+
*
|
|
15
|
+
* @param {Array<object>} left - first timeline row batch
|
|
16
|
+
* @param {Array<object>} right - second timeline row batch
|
|
17
|
+
* @returns {Array<object>} sorted unique rows
|
|
18
|
+
*/
|
|
19
|
+
function mergeSegmentRows(left, right) {
|
|
20
|
+
const seen = new Set();
|
|
21
|
+
const merged = [];
|
|
22
|
+
const all = left.concat(right);
|
|
23
|
+
all.sort(sortByStartTime);
|
|
24
|
+
for (let index = 0; index < all.length; index += 1) {
|
|
25
|
+
const row = all[index];
|
|
26
|
+
const key = row.start_time.toISOString();
|
|
27
|
+
if (!seen.has(key)) {
|
|
28
|
+
seen.add(key);
|
|
29
|
+
merged.push(row);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return merged;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Loads timeline rows needed to derive cycles intersecting a query window.
|
|
37
|
+
*
|
|
38
|
+
* @param {object} timeline - machine timeline with list method
|
|
39
|
+
* @param {object} range - query window with from and to Date values
|
|
40
|
+
* @returns {Promise<Array<object>>} rows spanning cycle anchors before from
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* const rows = await cycleTimelineFetch(machine.timeline, { from, to });
|
|
44
|
+
*/
|
|
45
|
+
export default async function cycleTimelineFetch(timeline, range, lookbackMs) {
|
|
46
|
+
const lookbackFrom = new Date(range.from.getTime() - lookbackMs);
|
|
47
|
+
const beforeRows = await timeline.list({
|
|
48
|
+
from: lookbackFrom.toISOString(),
|
|
49
|
+
to: range.from.toISOString()
|
|
50
|
+
});
|
|
51
|
+
const windowRows = await timeline.list({
|
|
52
|
+
from: range.from.toISOString(),
|
|
53
|
+
to: range.to.toISOString()
|
|
54
|
+
});
|
|
55
|
+
return mergeSegmentRows(beforeRows, windowRows);
|
|
56
|
+
}
|
|
@@ -38,6 +38,7 @@ export default function collectorProcesses(machines, describe, project) {
|
|
|
38
38
|
});
|
|
39
39
|
return { name: descriptor.name, command: descriptor.command, env: { ...descriptor.env, ...settings.env },
|
|
40
40
|
hostDevices, resources: descriptor.resources,
|
|
41
|
+
...(settings.spec === undefined ? {} : { spec: settings.spec, identity: settings.identity }),
|
|
41
42
|
...(descriptor.image === undefined ? {} : { image: descriptor.image }) };
|
|
42
43
|
});
|
|
43
44
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import deploymentTemplate, { deploymentCondition } from '../../infrastructure/deploy/deploymentTemplate.js';
|
|
2
2
|
import expand from './expand.js';
|
|
3
|
+
import compileCollectorTasks from './compileCollectorTasks.js';
|
|
4
|
+
import { deploymentContext } from './deploymentPlan.js';
|
|
3
5
|
import releases from './releases.js';
|
|
4
6
|
import collectorProcesses from './collectorProcesses.js';
|
|
5
7
|
|
|
@@ -86,6 +88,45 @@ export function collectorConsumerTasks(declarations, cluster, bindings, generati
|
|
|
86
88
|
});
|
|
87
89
|
}
|
|
88
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Use the same assignment compiler from rollout, control catalog and collector CLI.
|
|
93
|
+
* Device projections provide typed specs and stable logical identities.
|
|
94
|
+
*/
|
|
95
|
+
export function configuredCollectorAssignments(policy, collect, validateBindings) {
|
|
96
|
+
const settings = {
|
|
97
|
+
rules: policy.adapters, sourceTypes: policy.sourceTypes ?? [], collect,
|
|
98
|
+
compile(processes, generation) { return compileCollectorTasks(processes, {}, generation); }
|
|
99
|
+
};
|
|
100
|
+
const pattern = new RegExp(policy.site.pattern, 'u');
|
|
101
|
+
|
|
102
|
+
function devices(document, selection = {}) {
|
|
103
|
+
return collectorDeviceAssignments(document, selection, settings);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function site(document, server, app, generation = 1) {
|
|
107
|
+
const cluster = server.id;
|
|
108
|
+
const match = pattern.exec(cluster);
|
|
109
|
+
if (!match) { throw new TypeError(`Unknown collector site ${cluster}`); }
|
|
110
|
+
const bindings = deploymentTemplate(policy.site.bindings, { cluster, app, ...match.groups });
|
|
111
|
+
validateBindings?.(bindings);
|
|
112
|
+
const consumers = collectorConsumerTasks(policy.consumers, cluster, bindings, generation);
|
|
113
|
+
const readers = settings.sourceTypes.length ? devices(document, { cluster, generation }) : [];
|
|
114
|
+
return [...readers, ...consumers];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function manifest(document, selection) {
|
|
118
|
+
const { cluster, stream, adapter, generation } = selection;
|
|
119
|
+
if (!pattern.test(cluster ?? '') || stream || adapter) { return devices(document, selection); }
|
|
120
|
+
if (document.edgeControlPlane?.enabled) {
|
|
121
|
+
throw new TypeError('Control-mode assignments are managed through the declarative control catalog');
|
|
122
|
+
}
|
|
123
|
+
const { server, profile } = deploymentContext(document, cluster);
|
|
124
|
+
return site(document, server, profile.apps.scada, generation);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return { devices, site, manifest };
|
|
128
|
+
}
|
|
129
|
+
|
|
89
130
|
/** Project release mappings with an injected fieldbus point decoder. */
|
|
90
131
|
export function mapCollectorRelease(values, decode) {
|
|
91
132
|
const machines = (values.machines || []).map((machine) => {
|
|
@@ -22,10 +22,10 @@ function declaredTasks(input, generation) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/** Compile source-derived descriptors to stable assignments or use explicitly declared identities. */
|
|
25
|
-
export default function compileCollectorTasks(input, { describe, identity }, generation = 1) {
|
|
25
|
+
export default function compileCollectorTasks(input, { describe, identity } = {}, generation = 1) {
|
|
26
26
|
if (!Array.isArray(input)) { return declaredTasks(input, generation); }
|
|
27
27
|
return input.map((process) => {
|
|
28
28
|
const spec = process.spec ? structuredClone(process.spec) : describe(process);
|
|
29
|
-
return { taskId: `${spec.adapter}:${digest(identity(spec)).slice(0, 20)}`, generation, specVersion: 1, spec };
|
|
29
|
+
return { taskId: `${spec.adapter}:${digest(process.identity ?? identity(spec)).slice(0, 20)}`, generation, specVersion: 1, spec };
|
|
30
30
|
});
|
|
31
31
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Edge machine list from EDGE_MACHINES or the plant profile.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* const rows = edgeDescriptors(process.env, profile);
|
|
6
|
+
*
|
|
7
|
+
* @param {object} env - process environment
|
|
8
|
+
* @param {{ machines: function(): Array }} profile - plant profile
|
|
9
|
+
* @returns {Array<{device: string, id: string, shop?: string, kind?: string}>}
|
|
10
|
+
*/
|
|
11
|
+
export default function edgeDescriptors(env, profile) {
|
|
12
|
+
const raw = env.EDGE_MACHINES;
|
|
13
|
+
if (typeof raw === 'string' && raw.length > 0) {
|
|
14
|
+
return JSON.parse(raw).map((entry) => {
|
|
15
|
+
return {
|
|
16
|
+
device: entry.device,
|
|
17
|
+
id: entry.id,
|
|
18
|
+
shop: entry.shop,
|
|
19
|
+
kind: entry.kind
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return profile.machines().map((entry) => {
|
|
24
|
+
return {
|
|
25
|
+
device: entry.device,
|
|
26
|
+
id: entry.machine,
|
|
27
|
+
shop: entry.shop,
|
|
28
|
+
kind: entry.kind
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { parseSerialSource } from './collectorSourcePlan.js';
|
|
2
|
+
import serialLine from '../../infrastructure/streams/serialLine.js';
|
|
3
|
+
|
|
4
|
+
function registerOrigin(address) {
|
|
5
|
+
const text = new URL(address).searchParams.get('at');
|
|
6
|
+
if (text === null) { return undefined; }
|
|
7
|
+
const origin = parseInt(text, 10);
|
|
8
|
+
if (Number.isNaN(origin)) { throw new Error(`Address at must be a number, got: ${text}`); }
|
|
9
|
+
return origin;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function holdingPoint(value, address, profiles) {
|
|
13
|
+
const channel = String(value);
|
|
14
|
+
if (channel.startsWith('holding:')) { return channel; }
|
|
15
|
+
const origin = registerOrigin(address);
|
|
16
|
+
for (const profile of profiles) {
|
|
17
|
+
const entry = profile.layout.find((row) => { return row.channel === channel; });
|
|
18
|
+
if (entry) { return `holding:${(origin ?? profile.origin) + entry.offset}:${profile.order}`; }
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function registerMap(mapping, address, profiles) {
|
|
24
|
+
const next = {};
|
|
25
|
+
for (const [key, value] of Object.entries(mapping || {})) {
|
|
26
|
+
const point = holdingPoint(value, address, profiles);
|
|
27
|
+
if (point === null) { return null; }
|
|
28
|
+
next[key] = point;
|
|
29
|
+
}
|
|
30
|
+
return next;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Convert named device channels into portable holding points using declared register profiles. */
|
|
34
|
+
export function projectRegisterMaps(maps, addresses, profiles) {
|
|
35
|
+
if (!Array.isArray(maps) || !Array.isArray(addresses) || maps.length !== addresses.length) { return null; }
|
|
36
|
+
const rows = maps.map((mapping, index) => { return registerMap(mapping, addresses[index], profiles); });
|
|
37
|
+
return rows.includes(null) ? null : rows;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Validate the ordered RTU sources sharing one serial port and register window. */
|
|
41
|
+
export function sharedRegisterBus(rows, { label, count }) {
|
|
42
|
+
const ports = rows.map(({ from }) => { return parseSerialSource(from); });
|
|
43
|
+
const [first] = ports;
|
|
44
|
+
if (!first) { throw new TypeError(`${label} requires at least one serial source`); }
|
|
45
|
+
if (new Set(ports.map(({ slave }) => { return slave; })).size !== ports.length) {
|
|
46
|
+
throw new Error('duplicate Modbus slave address');
|
|
47
|
+
}
|
|
48
|
+
const at = first.query.get('at');
|
|
49
|
+
const size = first.query.get('count');
|
|
50
|
+
if (!/^\d+$/u.test(at || '') || size !== String(count)) {
|
|
51
|
+
throw new Error(`${label} requires a numeric address and ${count} registers`);
|
|
52
|
+
}
|
|
53
|
+
if (ports.some(({ path, baud, line, query, slave }) => {
|
|
54
|
+
return path !== first.path || baud !== first.baud || line !== first.line || query.toString() !== first.query.toString() || !slave;
|
|
55
|
+
})) { throw new Error(`${label} sources must share one serial bus and register range`); }
|
|
56
|
+
return { at, count: size, ports };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function rawSerialPorts(rows, label) {
|
|
60
|
+
const ports = rows.map(({ from }) => { return parseSerialSource(from); });
|
|
61
|
+
if (new Set(ports.map(({ path }) => { return path; })).size !== ports.length) {
|
|
62
|
+
throw new Error(`duplicate ${label} port`);
|
|
63
|
+
}
|
|
64
|
+
if (ports.some(({ slave, query }) => { return slave || query.toString(); })) {
|
|
65
|
+
throw new Error(`${label} serial sources cannot specify a Modbus slave or register range`);
|
|
66
|
+
}
|
|
67
|
+
return ports;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Validate independent inputs and produce typed serial settings. */
|
|
71
|
+
export function rawSerialDevices(rows, { label, name }) {
|
|
72
|
+
return rawSerialPorts(rows, label).map(({ path, baud, line }, index) => {
|
|
73
|
+
const baudRate = Number(baud);
|
|
74
|
+
if (!Number.isFinite(baudRate) || baudRate <= 0) { throw new Error(`Invalid ${label} baud rate`); }
|
|
75
|
+
return { name: name(rows[index]), path, baudRate, ...serialLine(line) };
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Validate independent raw serial inputs and produce the runtime's device-list ABI. */
|
|
80
|
+
export function rawSerialDeviceList(rows, { label, name }) {
|
|
81
|
+
return rawSerialPorts(rows, label).map(({ path, baud, line }, index) => { return `${name(rows[index])}:${path}:${baud}:${line}`; }).join(',');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Group stream URLs by database endpoint in source order, ignoring URL query selectors. */
|
|
85
|
+
export function databaseSourceGroups(rows, { port, identity }) {
|
|
86
|
+
const sources = new Map();
|
|
87
|
+
rows.forEach(({ from }) => {
|
|
88
|
+
const address = new URL(from);
|
|
89
|
+
const source = { host: address.hostname, port: Number(address.port || port), database: address.pathname.slice(1), ...identity };
|
|
90
|
+
sources.set(JSON.stringify(source), source);
|
|
91
|
+
});
|
|
92
|
+
return [...sources.values()];
|
|
93
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function taxonomy(declarations) {
|
|
2
|
+
return Object.freeze(Object.fromEntries(Object.entries(declarations).map(([section, value]) => {
|
|
3
|
+
const declared = Array.isArray(value) ? Object.freeze([...value]) : value;
|
|
4
|
+
return [section, () => { return declared; }];
|
|
5
|
+
})));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Combine an installation's topology, taxonomy and application-supplied integrations. */
|
|
9
|
+
export default function plantBindingProfile({ topology, taxonomy: declarations, integrations }) {
|
|
10
|
+
return function profile() {
|
|
11
|
+
const layout = topology();
|
|
12
|
+
const tags = taxonomy(declarations);
|
|
13
|
+
const links = integrations();
|
|
14
|
+
return Object.freeze({
|
|
15
|
+
name() { return layout.plant; },
|
|
16
|
+
topology() { return layout; },
|
|
17
|
+
taxonomy() { return tags; },
|
|
18
|
+
integrations() { return links; },
|
|
19
|
+
machines() {
|
|
20
|
+
return layout.machines.map(({ device, id: machine, shop, kind }) => { return Object.freeze({ device, machine, shop, kind }); });
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project the configured topology onto the SCADA graph contract.
|
|
3
|
+
*
|
|
4
|
+
* @param {object} layout - layout
|
|
5
|
+
* @param {string} [version] - optional package or env version
|
|
6
|
+
* @returns {object} { plant, nodes, links }
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* topologyGraph(layout);
|
|
10
|
+
*/
|
|
11
|
+
function shopNodes(layout) {
|
|
12
|
+
return layout.shops.map((area) => {
|
|
13
|
+
return { id: area.id, kind: 'shop', title: area.label, status: 'unknown' };
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function machineNode(entry) {
|
|
18
|
+
const node = {
|
|
19
|
+
id: entry.id,
|
|
20
|
+
kind: 'machine',
|
|
21
|
+
title: entry.label,
|
|
22
|
+
parent: entry.shop,
|
|
23
|
+
status: 'unknown'
|
|
24
|
+
};
|
|
25
|
+
if (entry.inspect) {
|
|
26
|
+
node.inspect = entry.inspect;
|
|
27
|
+
}
|
|
28
|
+
return node;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function sensorNodes(entry) {
|
|
32
|
+
if (!entry.sensors) {
|
|
33
|
+
return { nodes: [], links: [] };
|
|
34
|
+
}
|
|
35
|
+
const nodes = [];
|
|
36
|
+
const links = [];
|
|
37
|
+
Object.keys(entry.sensors).forEach((key) => {
|
|
38
|
+
const id = `${entry.id}-${key}`;
|
|
39
|
+
nodes.push({ id, kind: 'collector', title: key, parent: entry.id, status: 'unknown' });
|
|
40
|
+
links.push({ from: entry.id, to: id, kind: 'contains' });
|
|
41
|
+
});
|
|
42
|
+
return { nodes, links };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function collectorNodes(layout) {
|
|
46
|
+
const nodes = [];
|
|
47
|
+
const links = [];
|
|
48
|
+
(layout.collectors || []).forEach((item) => {
|
|
49
|
+
nodes.push({
|
|
50
|
+
id: item.id,
|
|
51
|
+
kind: 'collector',
|
|
52
|
+
title: item.title,
|
|
53
|
+
parent: item.shop,
|
|
54
|
+
status: 'unknown'
|
|
55
|
+
});
|
|
56
|
+
item.feeds.forEach((machineId) => {
|
|
57
|
+
links.push({ from: item.id, to: machineId, kind: 'feeds' });
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
return { nodes, links };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export default function topologyGraph(layout, version) {
|
|
64
|
+
const plant = { id: layout.plant, title: layout.title };
|
|
65
|
+
if (version) {
|
|
66
|
+
plant.version = version;
|
|
67
|
+
}
|
|
68
|
+
const nodes = [...shopNodes(layout)];
|
|
69
|
+
const links = [];
|
|
70
|
+
layout.machines.forEach((entry) => {
|
|
71
|
+
nodes.push(machineNode(entry));
|
|
72
|
+
links.push({ from: entry.shop, to: entry.id, kind: 'contains' });
|
|
73
|
+
const nested = sensorNodes(entry);
|
|
74
|
+
nodes.push(...nested.nodes);
|
|
75
|
+
links.push(...nested.links);
|
|
76
|
+
});
|
|
77
|
+
const extra = collectorNodes(layout);
|
|
78
|
+
nodes.push(...extra.nodes);
|
|
79
|
+
links.push(...extra.links);
|
|
80
|
+
return { plant, nodes, links };
|
|
81
|
+
}
|
|
@@ -3,7 +3,8 @@ import centralOperators from '../infrastructure/operators/centralOperators.js';
|
|
|
3
3
|
import operatorsSync from '../infrastructure/operators/operatorsSync.js';
|
|
4
4
|
import edgeOperators from '../infrastructure/operators/edgeOperators.js';
|
|
5
5
|
import stateHttpClient from '../infrastructure/http/edge/stateHttpClient.js';
|
|
6
|
-
import
|
|
6
|
+
import operatorCatalogView from './operatorCatalogView.js';
|
|
7
|
+
import { centralOperatorsUpdate, edgeOperatorsUpdate } from './siteRuntime/operatorUpdates.js';
|
|
7
8
|
|
|
8
9
|
const DEFAULT_SYNC_INTERVAL_SEC = 30;
|
|
9
10
|
|
|
@@ -27,19 +28,20 @@ function syncIntervalMs(env) {
|
|
|
27
28
|
* @example
|
|
28
29
|
* edgeOperatorCatalog('/api/v1', process.env);
|
|
29
30
|
*/
|
|
30
|
-
export default function edgeOperatorCatalog(basePath, env) {
|
|
31
|
+
export default function edgeOperatorCatalog(basePath, env, { update = false, ...extensions } = {}) {
|
|
31
32
|
const cache = operators();
|
|
33
|
+
const createProvider = update ? edgeOperatorsUpdate : edgeOperators;
|
|
34
|
+
const createSource = update ? centralOperatorsUpdate : centralOperators;
|
|
32
35
|
const centralUrl = env.CENTRAL_PLANT_URL;
|
|
33
36
|
if (!centralUrl) {
|
|
34
|
-
|
|
35
|
-
return { routes: operatorRoute(basePath, provider), sync: undefined, provider };
|
|
37
|
+
return { ...operatorCatalogView(basePath, createProvider(cache), extensions), sync: undefined };
|
|
36
38
|
}
|
|
37
39
|
const client = stateHttpClient({
|
|
38
40
|
baseUrl: centralUrl,
|
|
39
41
|
token: env.CENTRAL_PLANT_TOKEN
|
|
40
42
|
});
|
|
41
|
-
const source =
|
|
42
|
-
const provider =
|
|
43
|
+
const source = createSource(client, basePath);
|
|
44
|
+
const provider = createProvider(cache, source);
|
|
43
45
|
const sync = operatorsSync(source, cache, { intervalMs: syncIntervalMs(env) });
|
|
44
|
-
return {
|
|
46
|
+
return { ...operatorCatalogView(basePath, provider, extensions), sync };
|
|
45
47
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Picks the HTTP port for the analytics MCP process.
|
|
3
|
+
*
|
|
4
|
+
* ANALYTICS_MCP_PORT wins. PORT is the infra fallback. Default is 3100.
|
|
5
|
+
*
|
|
6
|
+
* @param {NodeJS.ProcessEnv} env - process environment
|
|
7
|
+
* @returns {number} listen port
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* analyticsMcpPort({ ANALYTICS_MCP_PORT: '3100' });
|
|
11
|
+
*/
|
|
12
|
+
export default function analyticsMcpPort(env) {
|
|
13
|
+
if (env.ANALYTICS_MCP_PORT) {
|
|
14
|
+
return Number(env.ANALYTICS_MCP_PORT);
|
|
15
|
+
}
|
|
16
|
+
if (env.PORT) {
|
|
17
|
+
return Number(env.PORT);
|
|
18
|
+
}
|
|
19
|
+
return 3100;
|
|
20
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps a deployment namespace projection to the analytics namespace tree.
|
|
3
|
+
*
|
|
4
|
+
* Plant data uses `silence` and `binding.topic`. The library wants
|
|
5
|
+
* `silenceSeconds` and `source`.
|
|
6
|
+
*
|
|
7
|
+
* @param {ReadonlyArray<object>} nodes - namespace() result
|
|
8
|
+
* @returns {Array<object>} nodes for namespaceTree
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* analyticsNamespaceNodes(namespace())[0].silenceSeconds;
|
|
12
|
+
*/
|
|
13
|
+
export default function analyticsNamespaceNodes(nodes) {
|
|
14
|
+
return nodes.map((node) => {
|
|
15
|
+
const mapped = {
|
|
16
|
+
kind: node.kind,
|
|
17
|
+
path: node.path,
|
|
18
|
+
silenceSeconds: node.silence,
|
|
19
|
+
title: node.title
|
|
20
|
+
};
|
|
21
|
+
if (node.binding && typeof node.binding.topic === 'string') {
|
|
22
|
+
mapped.source = node.binding.topic;
|
|
23
|
+
}
|
|
24
|
+
if (node.binding && typeof node.binding.unit === 'string') {
|
|
25
|
+
mapped.unit = node.binding.unit;
|
|
26
|
+
}
|
|
27
|
+
return mapped;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Register configured text resources and prompts with the analytics server. */
|
|
2
|
+
export default function analyticsTextContent(server, { resources = [], prompts = [] }) {
|
|
3
|
+
resources.forEach(({ name, uri, description, text }) => {
|
|
4
|
+
server.registerResource(name, uri, { description, mimeType: 'text/plain' }, () => {
|
|
5
|
+
return { contents: [{ mimeType: 'text/plain', text, uri }] };
|
|
6
|
+
});
|
|
7
|
+
});
|
|
8
|
+
prompts.forEach(({ name, text }) => {
|
|
9
|
+
server.registerPrompt(name, { description: text }, () => {
|
|
10
|
+
return { messages: [{ content: { text, type: 'text' }, role: 'user' }] };
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
}
|