@yarkivaev/scada 2.3.58 → 2.3.59

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yarkivaev/scada",
3
- "version": "2.3.58",
3
+ "version": "2.3.59",
4
4
  "description": "SCADA domain objects, state persistence, and plant monitoring",
5
5
  "repository": {
6
6
  "type": "git",
@@ -99,7 +99,7 @@ function filterLatest(store, machineId, kind, bound) {
99
99
  * In-memory operations state port for tests and local runs.
100
100
  *
101
101
  * @param {object} store - shared mutable store with operations array
102
- * @returns {object} operations port matching operationStatePg shape
102
+ * @returns {object} operations port matching operationStatePg shape including drop
103
103
  */
104
104
  export default function operationStateMemory(store) {
105
105
  if (!store.operations) {
@@ -126,6 +126,15 @@ export default function operationStateMemory(store) {
126
126
  const [row] = store.operations.splice(index, 1);
127
127
  return Promise.resolve(row);
128
128
  },
129
+ drop(machineId, key) {
130
+ const index = store.operations.findIndex((row) => {
131
+ return row.machine === machineId && row.key === key;
132
+ });
133
+ if (index >= 0) {
134
+ store.operations.splice(index, 1);
135
+ }
136
+ return Promise.resolve();
137
+ },
129
138
  listForMachine(machineId, kind, range) {
130
139
  return Promise.resolve(filterList(store, machineId, kind, range));
131
140
  },
@@ -120,17 +120,33 @@ async function removeOperation(pool, machineId, key) {
120
120
  return result.rows[0];
121
121
  }
122
122
 
123
+ /**
124
+ * Deletes an operation when present. Absence is success.
125
+ *
126
+ * @param {object} pool - pg pool
127
+ * @param {string} machineId - machine identifier
128
+ * @param {string} key - operation storage key
129
+ * @returns {Promise<void>}
130
+ */
131
+ function dropOperation(pool, machineId, key) {
132
+ return pool.query(
133
+ 'DELETE FROM operations WHERE machine = $1 AND key = $2',
134
+ [machineId, key]
135
+ );
136
+ }
137
+
123
138
  /**
124
139
  * PostgreSQL operations persistence port for generic machine operations.
125
140
  *
126
141
  * @param {object} pool - pg pool
127
- * @returns {object} operations port with upsert, get, remove, listForMachine, latestForMachine
142
+ * @returns {object} operations port with upsert, get, remove, drop, listForMachine, latestForMachine
128
143
  *
129
144
  * @example
130
145
  * const store = operationStatePg(pool);
131
146
  * await store.upsert({ machine: 'm1', key: 'nb-1', kind: 'sample', ... });
132
147
  * await store.latestForMachine('m1', 'sample', { to: new Date() });
133
148
  * await store.remove('m1', 'nb-1');
149
+ * await store.drop('m1', 'nb-1');
134
150
  */
135
151
  export default function operationStatePg(pool) {
136
152
  return {
@@ -143,6 +159,9 @@ export default function operationStatePg(pool) {
143
159
  remove(machineId, key) {
144
160
  return removeOperation(pool, machineId, key);
145
161
  },
162
+ drop(machineId, key) {
163
+ return dropOperation(pool, machineId, key);
164
+ },
146
165
  listForMachine(machineId, kind, range) {
147
166
  return listForMachine(pool, machineId, kind, range);
148
167
  },
@@ -3,7 +3,9 @@ import processingErrorLog from '../ingest/processingErrorLog.js';
3
3
  /**
4
4
  * PostgreSQL sink for generic operation sync records.
5
5
  *
6
- * @param {object} operations - Operations port with upsert(item) and remove(machineId, key)
6
+ * Federated deletes call operations.drop, which is idempotent when the row is absent.
7
+ *
8
+ * @param {object} operations - Operations port with upsert(item) and drop(machineId, key)
7
9
  * @returns {object} Sink with accept() and remove() methods
8
10
  *
9
11
  * @example
@@ -26,7 +28,7 @@ export default function operationSyncSink(operations) {
26
28
  },
27
29
  async remove(record) {
28
30
  try {
29
- await operations.remove(record.machine, record.key);
31
+ await operations.drop(record.machine, record.key);
30
32
  } catch (error) {
31
33
  processingErrorLog('operation_sync_sink', error, {
32
34
  machine: record.machine,