@openfn/language-varo 1.0.2 → 1.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/dist/index.js CHANGED
@@ -9,6 +9,8 @@ var Adaptor_exports = {};
9
9
  __export(Adaptor_exports, {
10
10
  alterState: () => alterState,
11
11
  combine: () => combine,
12
+ convertItemsToReports: () => convertItemsToReports,
13
+ convertReportsToMessageContents: () => convertReportsToMessageContents,
12
14
  convertToEms: () => convertToEms,
13
15
  cursor: () => cursor,
14
16
  dataPath: () => dataPath,
@@ -29,21 +31,258 @@ import { expandReferences } from "@openfn/language-common/util";
29
31
  // src/Utils.js
30
32
  function parseMetadata(message) {
31
33
  var _a;
32
- if (!((_a = message.metadata) == null ? void 0 : _a.content)) {
34
+ const content = (_a = message.metadata) == null ? void 0 : _a.content;
35
+ if (!content) {
33
36
  console.error("No metadata supplied.");
34
37
  return null;
35
38
  }
36
39
  try {
37
- return JSON.parse(message.metadata.content);
40
+ return JSON.parse(content);
38
41
  } catch (error) {
39
42
  console.error("Invalid metadata JSON.", error);
40
43
  return null;
41
44
  }
42
45
  }
46
+ function removeNullProps(obj) {
47
+ for (const key in obj) {
48
+ if (obj[key] == null) {
49
+ delete obj[key];
50
+ }
51
+ }
52
+ return obj;
53
+ }
54
+ function deepEqual(a, b) {
55
+ if (a === b)
56
+ return true;
57
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null)
58
+ return false;
59
+ const aKeys = Object.keys(a);
60
+ const bKeys = Object.keys(b);
61
+ if (aKeys.length !== bKeys.length)
62
+ return false;
63
+ for (const key of aKeys) {
64
+ if (!bKeys.includes(key) || !deepEqual(a[key], b[key]))
65
+ return false;
66
+ }
67
+ return true;
68
+ }
69
+ function formatDeviceInfo(data) {
70
+ function formatType(label, mfr, mod, ser) {
71
+ let output2 = "";
72
+ if (mfr || mod || ser) {
73
+ output2 += `${label}
74
+ `;
75
+ if (mfr) {
76
+ output2 += ` Manufacturer: ${mfr}
77
+ `;
78
+ }
79
+ if (mod) {
80
+ output2 += ` Model: ${mod}
81
+ `;
82
+ }
83
+ if (ser) {
84
+ output2 += ` Serial Number: ${ser}
85
+ `;
86
+ }
87
+ output2 += "\n";
88
+ }
89
+ return output2;
90
+ }
91
+ let output = "";
92
+ output += formatType("Appliance", data.AMFR, data.AMOD, data.ASER);
93
+ output += formatType("Logger", data.LMFR, data.LMOD, data.LSER);
94
+ output += formatType("EMD", data.EMFR, data.EMOD, data.ESER);
95
+ return output || "No valid data found";
96
+ }
97
+
98
+ // src/StreamingUtils.js
99
+ function parseRtmdCollectionToReports(collection) {
100
+ if (!Array.isArray(collection) || collection.length === 0) {
101
+ console.error("No records to process for report.");
102
+ return null;
103
+ }
104
+ return groupDifferencesAndMergeRecords(collection, "ESER", "ABST");
105
+ }
106
+ function parseFlatRecordsToReports(collection, reqReport, reqRecord) {
107
+ if (!Array.isArray(collection) || collection.length === 0) {
108
+ console.error("No records to process for report.");
109
+ return null;
110
+ }
111
+ const reports = [];
112
+ const groups = groupByProperty(collection, "LSER");
113
+ for (const key in groups) {
114
+ const records = groups[key];
115
+ const reportRecord = records[0];
116
+ const report = mapProperties(reportRecord, records, reqReport, reqRecord);
117
+ promoteDeviceProperties(report, "E");
118
+ reports.push(report);
119
+ }
120
+ return reports;
121
+ }
122
+ function groupDifferencesAndMergeRecords(collection, reportsGroupKey, recordsGroupKey) {
123
+ const groups = groupByProperty(collection, reportsGroupKey);
124
+ const reports = [];
125
+ for (const key in groups) {
126
+ const rawReports = groups[key];
127
+ const report = { ...rawReports[0] };
128
+ removeNullProps(report);
129
+ const allRecords = rawReports.flatMap((r) => r.records || []);
130
+ const mergedRecords = mergeRecords(allRecords, recordsGroupKey);
131
+ const allProps = getAllProps(rawReports, [reportsGroupKey, "records"]);
132
+ const differingProps = getDifferingProps(rawReports, allProps);
133
+ const differences = buildDifferences(rawReports, report, differingProps);
134
+ report["records"] = mergedRecords;
135
+ report["zDifferences"] = differences;
136
+ promoteDeviceProperties(report, "L");
137
+ reports.push(report);
138
+ }
139
+ return reports;
140
+ }
141
+ function groupByProperty(collection, property) {
142
+ return collection.reduce((acc, item) => {
143
+ const key = item[property];
144
+ if (!acc[key]) {
145
+ acc[key] = [];
146
+ }
147
+ acc[key].push(item);
148
+ return acc;
149
+ }, {});
150
+ }
151
+ function mergeRecords(records, groupKey) {
152
+ const grouped = groupByProperty(records, groupKey);
153
+ const merged = [];
154
+ for (const key in grouped) {
155
+ const group = grouped[key];
156
+ const mergedRecord = {};
157
+ let tvcAlrm = null;
158
+ let tambAlrm = null;
159
+ for (const record of group) {
160
+ Object.assign(mergedRecord, record);
161
+ const alrm = record["ALRM"];
162
+ if (alrm != null) {
163
+ if ("TVC" in record)
164
+ tvcAlrm = alrm;
165
+ if ("TAMB" in record)
166
+ tambAlrm = alrm;
167
+ }
168
+ }
169
+ if (tambAlrm != null) {
170
+ mergedRecord["zTambAlrm"] = tambAlrm;
171
+ mergedRecord["ALRM"] = tambAlrm;
172
+ }
173
+ if (tvcAlrm != null) {
174
+ mergedRecord["zTvcAlrm"] = tvcAlrm;
175
+ mergedRecord["ALRM"] = tvcAlrm;
176
+ }
177
+ removeNullProps(mergedRecord);
178
+ merged.push(mergedRecord);
179
+ }
180
+ return merged;
181
+ }
182
+ function getAllProps(collection, excludedProps = []) {
183
+ const props = /* @__PURE__ */ new Set();
184
+ for (const item of collection) {
185
+ for (const prop in item) {
186
+ if (excludedProps.includes(prop))
187
+ continue;
188
+ if (item[prop] === null)
189
+ continue;
190
+ props.add(prop);
191
+ }
192
+ }
193
+ return Array.from(props);
194
+ }
195
+ function getDifferingProps(records, props) {
196
+ const differing = [];
197
+ for (const prop of props) {
198
+ const firstValue = records[0][prop];
199
+ const isDifferent = records.some((r) => !deepEqual(r[prop], firstValue));
200
+ if (isDifferent) {
201
+ differing.push(prop);
202
+ }
203
+ }
204
+ return differing;
205
+ }
206
+ function buildDifferences(records, base, differingProps) {
207
+ const uniqueSet = /* @__PURE__ */ new Set();
208
+ return records.map((record) => {
209
+ const diff = {};
210
+ for (const prop of differingProps) {
211
+ if (!deepEqual(record[prop], base[prop])) {
212
+ diff[prop] = record[prop];
213
+ }
214
+ }
215
+ const sortedDiff = Object.keys(diff).sort().reduce((acc, key2) => {
216
+ acc[key2] = diff[key2];
217
+ return acc;
218
+ }, {});
219
+ const key = JSON.stringify(sortedDiff);
220
+ if (Object.keys(diff).length > 0 && !uniqueSet.has(key)) {
221
+ uniqueSet.add(key);
222
+ return sortedDiff;
223
+ }
224
+ return null;
225
+ }).filter(Boolean);
226
+ }
227
+ var defs = {
228
+ report: "ACAT,ADOP,AID,AMFR,AMID,AMOD,APQS,ASER,CDAT,CDAT2,CID,CNAM,CNAM2,CSER,CSER2,CSOF,CSOF2,DLST,DNAM,EDOP,EID,EMFR,EMOD,EMSV,EPQS,ESER,FID,FNAM,LACC,LAT,LDOP,LID,LMFR,LMOD,LNG,LPQS,LSER,LSV,RNAM,SIGN".split(","),
229
+ record: "ABST,ACCD,ACSV,ALRM,BEMD,BLOG,CMPR,CMPR2,CMPS,CMPS2,CSOF,CSOF2,DCCD,DCSV,DORF,DORV,DRCF,DRCV,EERR,FANS,HAMB,HCOM,HOLD,IDRF,IDRV,LERR,MSW,SVA,TAMB,TCON,TCON2,TFRZ,TPCB,TPCB2,TVC".split(",")
230
+ };
231
+ function mapProperties(report, records, reqReport, reqRecord) {
232
+ function resolveReqKeys(option, defaults) {
233
+ if (option === true)
234
+ return defaults;
235
+ if (typeof option === "string" && option.trim()) {
236
+ return option.split(",").map((k) => k.trim());
237
+ }
238
+ return [];
239
+ }
240
+ function extract(source, keys, reqKeys) {
241
+ const result = {};
242
+ for (const key of keys) {
243
+ if (key in source && source[key] !== null) {
244
+ result[key] = source[key];
245
+ } else if (reqKeys.includes(key)) {
246
+ result[key] = null;
247
+ }
248
+ }
249
+ return result;
250
+ }
251
+ if (!report)
252
+ return null;
253
+ const reqReportKeys = resolveReqKeys(reqReport, defs.report);
254
+ const reqRecordKeys = resolveReqKeys(reqRecord, defs.record);
255
+ const reportKeys = [.../* @__PURE__ */ new Set([...defs.report, ...reqReportKeys])];
256
+ const recordKeys = [.../* @__PURE__ */ new Set([...defs.record, ...reqRecordKeys])];
257
+ const reportResult = extract(report, reportKeys, reqReportKeys);
258
+ const recordResults = (records == null ? void 0 : records.map((record) => extract(record, recordKeys, reqRecordKeys)).filter((record) => Object.keys(record).length > 0)) ?? [];
259
+ return {
260
+ ...reportResult,
261
+ records: recordResults
262
+ };
263
+ }
264
+ function promoteDeviceProperties(source, destination) {
265
+ const keyPairs = [
266
+ ["LID", "EID"],
267
+ ["LMFR", "EMFR"],
268
+ ["LMOD", "EMOD"],
269
+ ["LSER", "ESER"],
270
+ ["LDOP", "EDOP"],
271
+ ["LSV", "EMSV"],
272
+ ["LPQS", "EPQS"]
273
+ ];
274
+ for (const [lKey, eKey] of keyPairs) {
275
+ const [fromKey, toKey] = destination === "E" ? [lKey, eKey] : [eKey, lKey];
276
+ if (source[toKey] != null)
277
+ continue;
278
+ if (source[fromKey] != null)
279
+ source[toKey] = source[fromKey];
280
+ }
281
+ }
43
282
 
44
283
  // src/VaroEmsUtils.js
45
- function parseVaroEmsToEms(metadata, data, dataPath2) {
46
- const result = {
284
+ function parseVaroEmsToReport(metadata, data, dataPath2) {
285
+ const report = {
47
286
  CID: null,
48
287
  LAT: metadata.location.used.latitude,
49
288
  LNG: metadata.location.used.longitude,
@@ -86,9 +325,9 @@ function parseVaroEmsToEms(metadata, data, dataPath2) {
86
325
  TAMB: item.TAMB,
87
326
  TVC: item.TVC
88
327
  };
89
- result.records.push(record);
328
+ report.records.push(record);
90
329
  }
91
- return result;
330
+ return report;
92
331
  }
93
332
  function parseRelativeDateFromUsbPluggedInfo(path) {
94
333
  const regex = /_CURRENT_DATA_(?<duration>\w+?)_(?<date>\w+?)\.json$/;
@@ -150,42 +389,44 @@ function parseIsoToAbbreviatedIso(iso) {
150
389
  }
151
390
 
152
391
  // src/FridgeTagUtils.js
153
- function parseFridgeTagToEms(metadata, nodes) {
154
- const result = {
155
- records: [],
156
- reports: []
157
- };
158
- applyMetadataToResult();
159
- applyNodesToResult();
160
- function applyMetadataToResult() {
392
+ function parseFridgeTagToReport(metadata, nodes) {
393
+ const report = {};
394
+ const records = [];
395
+ const zReports = [];
396
+ applyMetadataToReport();
397
+ applyNodesToReport();
398
+ report.records = records;
399
+ report.zReports = zReports;
400
+ return report;
401
+ function applyMetadataToReport() {
161
402
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
162
- applyPropertyToResult("AMFR", (_a = metadata == null ? void 0 : metadata.refrigerator) == null ? void 0 : _a.manufacturer);
163
- applyPropertyToResult("AMOD", (_b = metadata == null ? void 0 : metadata.refrigerator) == null ? void 0 : _b.model);
164
- applyPropertyToResult("LMFR", (_c = metadata == null ? void 0 : metadata.refrigerator) == null ? void 0 : _c.deviceManufacturer);
165
- applyPropertyToResult("CID", (_d = metadata == null ? void 0 : metadata.facility) == null ? void 0 : _d.country);
166
- applyPropertyToResult("LAT", (_f = (_e = metadata == null ? void 0 : metadata.location) == null ? void 0 : _e.used) == null ? void 0 : _f.latitude);
167
- applyPropertyToResult("LNG", (_h = (_g = metadata == null ? void 0 : metadata.location) == null ? void 0 : _g.used) == null ? void 0 : _h.longitude);
168
- applyPropertyToResult("LACC", (_j = (_i = metadata == null ? void 0 : metadata.location) == null ? void 0 : _i.used) == null ? void 0 : _j.accuracy);
403
+ applyPropertyToReport("AMFR", (_a = metadata == null ? void 0 : metadata.refrigerator) == null ? void 0 : _a.manufacturer);
404
+ applyPropertyToReport("AMOD", (_b = metadata == null ? void 0 : metadata.refrigerator) == null ? void 0 : _b.model);
405
+ applyPropertyToReport("LMFR", (_c = metadata == null ? void 0 : metadata.refrigerator) == null ? void 0 : _c.deviceManufacturer);
406
+ applyPropertyToReport("CID", (_d = metadata == null ? void 0 : metadata.facility) == null ? void 0 : _d.country);
407
+ applyPropertyToReport("LAT", (_f = (_e = metadata == null ? void 0 : metadata.location) == null ? void 0 : _e.used) == null ? void 0 : _f.latitude);
408
+ applyPropertyToReport("LNG", (_h = (_g = metadata == null ? void 0 : metadata.location) == null ? void 0 : _g.used) == null ? void 0 : _h.longitude);
409
+ applyPropertyToReport("LACC", (_j = (_i = metadata == null ? void 0 : metadata.location) == null ? void 0 : _i.used) == null ? void 0 : _j.accuracy);
169
410
  }
170
- function applyNodesToResult() {
411
+ function applyNodesToReport() {
171
412
  var _a, _b, _c;
172
- applyPropertyToResult("LMOD", nodes["Device"]);
173
- applyPropertyToResult("LSER", (_a = nodes["Conf"]) == null ? void 0 : _a["Serial"]);
174
- applyPropertyToResult("LSV", nodes["Fw Vers"]);
413
+ applyPropertyToReport("LMOD", nodes["Device"]);
414
+ applyPropertyToReport("LSER", (_a = nodes["Conf"]) == null ? void 0 : _a["Serial"]);
415
+ applyPropertyToReport("LSV", nodes["Fw Vers"]);
175
416
  let productionDate = (_b = nodes["Conf"]) == null ? void 0 : _b["Test TS"];
176
417
  productionDate = productionDate ? new Date(productionDate) : null;
177
- applyPropertyToResult("LDOP", productionDate);
418
+ applyPropertyToReport("LDOP", productionDate);
178
419
  let dayIndex = 1;
179
420
  let dayNode;
180
421
  while ((dayNode = (_c = nodes["Hist"]) == null ? void 0 : _c[dayIndex++]) !== void 0) {
181
422
  applyDayToRecords(dayNode);
182
- applyDayToReports(dayNode);
423
+ applyDayToZReports(dayNode);
183
424
  }
184
425
  }
185
- function applyPropertyToResult(property, text) {
426
+ function applyPropertyToReport(property, text) {
186
427
  if (!text)
187
428
  return;
188
- result[property] = text;
429
+ report[property] = text;
189
430
  }
190
431
  function applyDayToRecords(dayNode) {
191
432
  applyNodeToRecords(dayNode, "TS Min T", "Min T", "0", "FRZE");
@@ -200,11 +441,11 @@ function parseFridgeTagToEms(metadata, nodes) {
200
441
  (_a = dayNode2["Alarm"]) == null ? void 0 : _a[alarmField],
201
442
  alarmDescription
202
443
  );
203
- result.records.push({
444
+ records.push({
204
445
  ABST: dateTime,
205
446
  TVC: temp,
206
447
  ALRM: alarm,
207
- description: date + " " + tempField
448
+ zdescription: date + " " + tempField
208
449
  });
209
450
  function parseAlarm(alarmNode, description) {
210
451
  if (alarmNode["t Acc"] === "0")
@@ -213,17 +454,17 @@ function parseFridgeTagToEms(metadata, nodes) {
213
454
  }
214
455
  }
215
456
  }
216
- function applyDayToReports(dayNode) {
217
- const report = {
457
+ function applyDayToZReports(dayNode) {
458
+ const report2 = {
218
459
  date: new Date(dayNode["Date"]),
219
460
  duration: "1D",
220
461
  alarms: [],
221
462
  aggregates: []
222
463
  };
223
- applyAlarmsToReport(dayNode);
224
- applyAggregatesToReport(dayNode);
225
- result.reports.push(report);
226
- function applyAlarmsToReport(dayNode2) {
464
+ applyAlarmsToZReport(dayNode);
465
+ applyAggregatesToZReport(dayNode);
466
+ zReports.push(report2);
467
+ function applyAlarmsToZReport(dayNode2) {
227
468
  var _a, _b;
228
469
  const date = dayNode2["Date"];
229
470
  applyAlarmToAlarms((_a = dayNode2["Alarm"]) == null ? void 0 : _a["0"], "FRZE");
@@ -246,13 +487,13 @@ function parseFridgeTagToEms(metadata, nodes) {
246
487
  if (count) {
247
488
  alarm.count = count;
248
489
  }
249
- report.alarms.push(alarm);
490
+ report2.alarms.push(alarm);
250
491
  }
251
492
  }
252
- function applyAggregatesToReport(dayNode2) {
493
+ function applyAggregatesToZReport(dayNode2) {
253
494
  applyTvcToAggregates(dayNode2);
254
495
  function applyTvcToAggregates(dayNode3) {
255
- report.aggregates.push({
496
+ report2.aggregates.push({
256
497
  id: "TVC",
257
498
  min: parseFloat(dayNode3["Min T"]),
258
499
  max: parseFloat(dayNode3["Max T"]),
@@ -261,7 +502,6 @@ function parseFridgeTagToEms(metadata, nodes) {
261
502
  }
262
503
  }
263
504
  }
264
- return result;
265
505
  }
266
506
  function parseFridgeTag(text) {
267
507
  const result = {};
@@ -320,7 +560,7 @@ function convertToEms(messageContents) {
320
560
  return async (state) => {
321
561
  var _a, _b;
322
562
  const [resolvedMessageContents] = expandReferences(state, messageContents);
323
- const results = [];
563
+ const reports = [];
324
564
  console.log("Incoming message contents", resolvedMessageContents.length);
325
565
  for (const content of resolvedMessageContents) {
326
566
  if ((_a = content.fridgeTag) == null ? void 0 : _a.content) {
@@ -328,8 +568,8 @@ function convertToEms(messageContents) {
328
568
  if (!metadata)
329
569
  continue;
330
570
  const fridgeTagNodes = parseFridgeTag(content.fridgeTag.content);
331
- const result = parseFridgeTagToEms(metadata, fridgeTagNodes);
332
- results.push(result);
571
+ const result = parseFridgeTagToReport(metadata, fridgeTagNodes);
572
+ reports.push(result);
333
573
  continue;
334
574
  }
335
575
  if ((_b = content.data) == null ? void 0 : _b.content) {
@@ -338,16 +578,60 @@ function convertToEms(messageContents) {
338
578
  continue;
339
579
  const data = JSON.parse(content.data.content);
340
580
  const dataPath2 = content.data.filename;
341
- const result = parseVaroEmsToEms(metadata, data, dataPath2);
342
- results.push(result);
581
+ const result = parseVaroEmsToReport(metadata, data, dataPath2);
582
+ reports.push(result);
343
583
  continue;
344
584
  }
345
585
  console.error(
346
586
  `Insufficient content found for MessageID: ${content.messageId}`
347
587
  );
348
588
  }
349
- console.log("Converted message contents", results.length);
350
- return { ...composeNextState(state, results) };
589
+ console.log("Converted message contents", reports.length);
590
+ return { ...composeNextState(state, reports) };
591
+ };
592
+ }
593
+ function convertItemsToReports(items, reportType = "unknown") {
594
+ return async (state) => {
595
+ const [resolvedRecords, resolvedReportType] = expandReferences(
596
+ state,
597
+ items,
598
+ reportType
599
+ );
600
+ const reportParsers = {
601
+ ems: parseFlatRecordsToReports,
602
+ rtmd: parseRtmdCollectionToReports
603
+ };
604
+ const parser = reportParsers[resolvedReportType];
605
+ if (!parser) {
606
+ throw new Error(`Report type not supported: ${resolvedReportType}`);
607
+ }
608
+ const reports = parser(resolvedRecords);
609
+ return { ...composeNextState(state, reports) };
610
+ };
611
+ }
612
+ function convertReportsToMessageContents(reports, reportType = "unknown") {
613
+ return async (state) => {
614
+ const [resolvedReports, resolvedReportType] = expandReferences(
615
+ state,
616
+ reports,
617
+ reportType
618
+ );
619
+ const messageContents = [];
620
+ for (const report of resolvedReports) {
621
+ report["zReportType"] = resolvedReportType;
622
+ report["zGeneratedTimestamp"] = new Date().toISOString();
623
+ const serialNumber = report["ESER"] || report["LSER"] || report["ASER"];
624
+ const messageContent = {
625
+ subject: `OpenFn | ${resolvedReportType.toUpperCase()} | ${serialNumber}`,
626
+ body: formatDeviceInfo(report),
627
+ data: {
628
+ filename: "data.json",
629
+ content: JSON.stringify(report, null, 4)
630
+ }
631
+ };
632
+ messageContents.push(messageContent);
633
+ }
634
+ return { ...composeNextState(state, messageContents) };
351
635
  };
352
636
  }
353
637
 
@@ -356,6 +640,8 @@ var src_default = Adaptor_exports;
356
640
  export {
357
641
  alterState,
358
642
  combine,
643
+ convertItemsToReports,
644
+ convertReportsToMessageContents,
359
645
  convertToEms,
360
646
  cursor,
361
647
  dataPath,
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@openfn/language-varo",
3
- "version": "1.0.2",
3
+ "label": "Varo",
4
+ "version": "1.1.0",
4
5
  "description": "OpenFn varo adaptor",
5
6
  "type": "module",
6
7
  "exports": {
@@ -20,13 +21,12 @@
20
21
  "configuration-schema.json"
21
22
  ],
22
23
  "dependencies": {
23
- "@openfn/language-common": "2.3.3"
24
+ "@openfn/language-common": "2.4.0"
24
25
  },
25
26
  "devDependencies": {
26
27
  "assertion-error": "2.0.0",
27
28
  "chai": "4.3.6",
28
29
  "deep-eql": "4.1.1",
29
- "esno": "^0.16.3",
30
30
  "rimraf": "3.0.2",
31
31
  "undici": "^5.22.1"
32
32
  },
@@ -16,4 +16,45 @@
16
16
  * );
17
17
  */
18
18
  export function convertToEms(messageContents: any[]): Operation;
19
+ /**
20
+ * Read a collection of EMS-like data records and convert them to a standard EMS report/record format.
21
+ * Systematically separates report properties from record properties.
22
+ * @public
23
+ * @function
24
+ * @param {Array} items - Array of EMS-like JSON objects.
25
+ * @param {string} [reportType='unknown'] - Optional. Source of the report, e.g., "ems" or "rtmd".
26
+ * @state {Array} data - The converted, EMS-compliant report with records.
27
+ * @returns {Operation}
28
+ * @example <caption>Convert data to EMS-compliant data.</caption>
29
+ * convertItemsToReport(
30
+ * [
31
+ * { "ASER": "BJBC 08 30", "ABST": "20241205T004440Z", "TVC": 5.0 },
32
+ * { "ASER": "BJBC 08 30", "ABST": "20241205T005440Z", "TVC": 5.2 },
33
+ * ]
34
+ * );
35
+ *
36
+ * state.data becomes:
37
+ * {
38
+ * "ASER": "BJBC 08 30",
39
+ * records: [
40
+ * { "ABST": "20241205T004440Z", "TVC": 5.0 },
41
+ * { "ABST": "20241205T005440Z", "TVC": 5.2 },
42
+ * ],
43
+ * }
44
+ */
45
+ export function convertItemsToReports(items: any[], reportType?: string): Operation;
46
+ /**
47
+ * Converts an EMS-compliant report into Varo-compatible message components.
48
+ *
49
+ * @public
50
+ * @function
51
+ * @param {Object} reports - EMS-compliant report objects.
52
+ * @param {string} [reportType='unknown'] - Optional. Source of the report, e.g., "ems" or "rtmd".
53
+ * @returns {Function} An operation function that receives `state` and returns updated message content.
54
+ *
55
+ * @example
56
+ * // Convert EMS-compliant reports to Varo message components.
57
+ * convertReportsToMessageContents(emsReports, "ems");
58
+ */
59
+ export function convertReportsToMessageContents(reports: any, reportType?: string): Function;
19
60
  export { alterState, combine, cursor, dataPath, dataValue, each, field, fields, fn, fnIf, http, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
@@ -1,5 +1,5 @@
1
- export function parseFridgeTagToEms(metadata: any, nodes: any): {
1
+ export function parseFridgeTagToReport(metadata: any, nodes: any): {
2
2
  records: any[];
3
- reports: any[];
3
+ zReports: any[];
4
4
  };
5
5
  export function parseFridgeTag(text: any): {};
@@ -0,0 +1,4 @@
1
+ export function parseRtmdCollectionToReports(collection: any): any[];
2
+ export function parseFlatRecordsToReports(collection: any, reqReport: any, reqRecord: any): {
3
+ records: any;
4
+ }[];
package/types/Utils.d.ts CHANGED
@@ -1 +1,4 @@
1
1
  export function parseMetadata(message: any): any;
2
+ export function removeNullProps(obj: any): any;
3
+ export function deepEqual(a: any, b: any): boolean;
4
+ export function formatDeviceInfo(data: any): string;
@@ -1,4 +1,4 @@
1
- export function parseVaroEmsToEms(metadata: any, data: any, dataPath: any): {
1
+ export function parseVaroEmsToReport(metadata: any, data: any, dataPath: any): {
2
2
  CID: any;
3
3
  LAT: any;
4
4
  LNG: any;