@yarkivaev/scada 2.6.22 → 2.6.23
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/package.json
CHANGED
|
@@ -13,6 +13,10 @@ export const historyProtocol = 'stateful-correction-v1';
|
|
|
13
13
|
function machineName(machine) {
|
|
14
14
|
if (typeof machine !== 'string' || !machine || machine.length > 200) { throw new TypeError('machine required'); }
|
|
15
15
|
}
|
|
16
|
+
async function ready(connection, machine, hold) {
|
|
17
|
+
try { await assertHistoryReady(connection, machine); return null; }
|
|
18
|
+
catch (error) { if (error.statusCode===409 && hold) { return hold; } throw error; }
|
|
19
|
+
}
|
|
16
20
|
async function transaction(pool, machine, action, topology=false) {
|
|
17
21
|
machineName(machine);
|
|
18
22
|
const client = await pool.connect();
|
|
@@ -59,6 +63,13 @@ function context(pool,machine,from,until,options) {
|
|
|
59
63
|
machineName(machine);
|
|
60
64
|
return historyContext(pool,machine,from,until,options);
|
|
61
65
|
}
|
|
66
|
+
async function snapshot(connection, machine, range, page, observationSource) {
|
|
67
|
+
if (observationSource) {
|
|
68
|
+
const held=await ready(connection,machine,page.classifierKey&&page.workId&&{available:false,items:[],segments:[],annotations:[],context:{from:range.from,until:range.until,paddingMs:page.padding,...page}});
|
|
69
|
+
if (held) { return held; }
|
|
70
|
+
}
|
|
71
|
+
return context(connection,machine,range.from,range.until,{...page,observations:observationSource?.(connection)});
|
|
72
|
+
}
|
|
62
73
|
async function unchanged(client, machine, base, {observationSource,timeScale}) {
|
|
63
74
|
await client.query('LOCK TABLE segments IN SHARE ROW EXCLUSIVE MODE');
|
|
64
75
|
const latest = await context(client, machine, base.from, base.until, { padding: base.paddingMs, cutoff: -Infinity,cursor:base.cursor ?? null,end:base.end ?? null,classifierKey:base.classifierKey,workId:base.workId,workToken:base.workToken,timeScale,observations:observationSource?.(client) });
|
|
@@ -89,7 +100,7 @@ function commit(pool, machine, workId, segments, {base, observationSource,timeSc
|
|
|
89
100
|
if (!work.rowCount) { return { applied: false }; }
|
|
90
101
|
checkClaim(work.rows[0],base);
|
|
91
102
|
if (segments.length && !base?.revision) { throw new TypeError('History context revision required'); }
|
|
92
|
-
if (observationSource) { await
|
|
103
|
+
if (observationSource) { const held=await ready(client,machine,{applied:false}); if (held) { return held; } }
|
|
93
104
|
const latest = base?.revision ? await unchanged(client, machine, base, {observationSource,timeScale}) : null;
|
|
94
105
|
const exteriors = nativeHistoryBounds(segments, latest, base, timeScale);
|
|
95
106
|
for (const item of exteriors) {
|
|
@@ -160,10 +171,8 @@ export default function historyPg(pool, { retentionDays = 30, now = Date.now, ob
|
|
|
160
171
|
if (observationSource) { throw new TypeError('External observations require durable telemetry admission'); }
|
|
161
172
|
return accept(pool, machine, items, cutoff()); },
|
|
162
173
|
context(machine, from, until, padding = 60000*timeScale, page = {}) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return context(connection,machine,from,until,{padding,cutoff:cutoff(),...page,timeScale,observations:observationSource?.(connection)});
|
|
166
|
-
}
|
|
174
|
+
const options={padding,cutoff:cutoff(),...page,timeScale};
|
|
175
|
+
function read(connection) { return snapshot(connection,machine,{from,until},options,observationSource); }
|
|
167
176
|
return page.classifierKey && page.workId ? transaction(pool,machine,read) : read(pool);
|
|
168
177
|
},
|
|
169
178
|
async work(machine) {
|