atmosx-nwws-parser 1.0.2022 → 1.0.2031

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.
Files changed (56) hide show
  1. package/dist/cjs/{helper.cjs → index.cjs} +54 -26
  2. package/dist/esm/{helper.mjs → index.mjs} +50 -22
  3. package/package.json +2 -2
  4. package/src/bootstrap.ts +1 -0
  5. package/src/{helper.ts → index.ts} +1 -1
  6. package/src/parsers/events.ts +7 -5
  7. package/src/parsers/types/api.ts +8 -2
  8. package/src/parsers/types/cap.ts +8 -2
  9. package/src/parsers/types/text.ts +1 -1
  10. package/src/parsers/types/ugc.ts +1 -1
  11. package/src/parsers/types/vtec.ts +1 -1
  12. package/src/types.ts +1 -0
  13. package/src/utils.ts +3 -3
  14. package/tsup.config.ts +10 -7
  15. package/dist/cjs/bootstrap.cjs +0 -1000
  16. package/dist/cjs/database.cjs +0 -1105
  17. package/dist/cjs/dictionaries/awips.cjs +0 -370
  18. package/dist/cjs/dictionaries/events.cjs +0 -139
  19. package/dist/cjs/dictionaries/icao.cjs +0 -265
  20. package/dist/cjs/dictionaries/offshore.cjs +0 -40
  21. package/dist/cjs/dictionaries/signatures.cjs +0 -132
  22. package/dist/cjs/eas.cjs +0 -2854
  23. package/dist/cjs/parsers/events.cjs +0 -2854
  24. package/dist/cjs/parsers/stanza.cjs +0 -1099
  25. package/dist/cjs/parsers/text.cjs +0 -1133
  26. package/dist/cjs/parsers/types/api.cjs +0 -2854
  27. package/dist/cjs/parsers/types/cap.cjs +0 -2854
  28. package/dist/cjs/parsers/types/text.cjs +0 -2854
  29. package/dist/cjs/parsers/types/ugc.cjs +0 -2854
  30. package/dist/cjs/parsers/types/vtec.cjs +0 -2854
  31. package/dist/cjs/parsers/ugc.cjs +0 -1130
  32. package/dist/cjs/parsers/vtec.cjs +0 -1051
  33. package/dist/cjs/types.cjs +0 -17
  34. package/dist/cjs/utils.cjs +0 -2854
  35. package/dist/cjs/xmpp.cjs +0 -2854
  36. package/dist/esm/bootstrap.mjs +0 -963
  37. package/dist/esm/database.mjs +0 -1070
  38. package/dist/esm/dictionaries/awips.mjs +0 -346
  39. package/dist/esm/dictionaries/events.mjs +0 -111
  40. package/dist/esm/dictionaries/icao.mjs +0 -241
  41. package/dist/esm/dictionaries/offshore.mjs +0 -16
  42. package/dist/esm/dictionaries/signatures.mjs +0 -106
  43. package/dist/esm/eas.mjs +0 -2821
  44. package/dist/esm/parsers/events.mjs +0 -2821
  45. package/dist/esm/parsers/stanza.mjs +0 -1063
  46. package/dist/esm/parsers/text.mjs +0 -1097
  47. package/dist/esm/parsers/types/api.mjs +0 -2821
  48. package/dist/esm/parsers/types/cap.mjs +0 -2821
  49. package/dist/esm/parsers/types/text.mjs +0 -2821
  50. package/dist/esm/parsers/types/ugc.mjs +0 -2821
  51. package/dist/esm/parsers/types/vtec.mjs +0 -2821
  52. package/dist/esm/parsers/ugc.mjs +0 -1095
  53. package/dist/esm/parsers/vtec.mjs +0 -1016
  54. package/dist/esm/types.mjs +0 -0
  55. package/dist/esm/utils.mjs +0 -2821
  56. package/dist/esm/xmpp.mjs +0 -2821
@@ -21,6 +21,18 @@ var __spreadValues = (a, b) => {
21
21
  return a;
22
22
  };
23
23
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __objRest = (source, exclude) => {
25
+ var target = {};
26
+ for (var prop in source)
27
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
28
+ target[prop] = source[prop];
29
+ if (source != null && __getOwnPropSymbols)
30
+ for (var prop of __getOwnPropSymbols(source)) {
31
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
32
+ target[prop] = source[prop];
33
+ }
34
+ return target;
35
+ };
24
36
  var __export = (target, all) => {
25
37
  for (var name in all)
26
38
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -63,9 +75,9 @@ var __async = (__this, __arguments, generator) => {
63
75
  });
64
76
  };
65
77
 
66
- // src/helper.ts
67
- var helper_exports = {};
68
- __export(helper_exports, {
78
+ // src/index.ts
79
+ var index_exports = {};
80
+ __export(index_exports, {
69
81
  AlertManager: () => AlertManager,
70
82
  Database: () => database_default,
71
83
  EAS: () => eas_default,
@@ -74,10 +86,10 @@ __export(helper_exports, {
74
86
  TextParser: () => text_default,
75
87
  UGCParser: () => ugc_default,
76
88
  VtecParser: () => vtec_default,
77
- default: () => helper_default,
89
+ default: () => index_default,
78
90
  types: () => types_exports
79
91
  });
80
- module.exports = __toCommonJS(helper_exports);
92
+ module.exports = __toCommonJS(index_exports);
81
93
 
82
94
  // src/bootstrap.ts
83
95
  var fs = __toESM(require("fs"));
@@ -929,6 +941,7 @@ var cache = {
929
941
  var settings = {
930
942
  database: path.join(process.cwd(), "shapefiles.db"),
931
943
  isNWWS: true,
944
+ catchUnhandledExceptions: false,
932
945
  NoaaWeatherWireService: {
933
946
  clientReconnections: {
934
947
  canReconnect: true,
@@ -1504,7 +1517,7 @@ var VTECAlerts = class {
1504
1517
  const getBaseProperties = yield events_default.getBaseProperties(message, validated, getUGC, vtec);
1505
1518
  const getHeader = events_default.getHeader(__spreadValues(__spreadValues({}, validated.attributes), getBaseProperties.attributes), getBaseProperties, vtec);
1506
1519
  processed.push({
1507
- preformance: performance.now() - tick,
1520
+ performance: performance.now() - tick,
1508
1521
  tracking: vtec.tracking,
1509
1522
  header: getHeader,
1510
1523
  vtec: vtec.raw,
@@ -1572,7 +1585,7 @@ var UGCAlerts = class {
1572
1585
  const getHeader = events_default.getHeader(__spreadValues(__spreadValues({}, validated.attributes), getBaseProperties.attributes), getBaseProperties);
1573
1586
  const getEvent = this.getEvent(message, getBaseProperties.attributes.getAwip);
1574
1587
  processed.push({
1575
- preformance: performance.now() - tick,
1588
+ performance: performance.now() - tick,
1576
1589
  tracking: this.getTracking(getBaseProperties, getUGC.zones),
1577
1590
  header: getHeader,
1578
1591
  vtec: `N/A`,
@@ -1610,7 +1623,7 @@ var UGCAlerts2 = class {
1610
1623
  const getHeader = events_default.getHeader(__spreadValues(__spreadValues({}, validated.attributes), getBaseProperties.attributes), getBaseProperties);
1611
1624
  const getEvent = this.getEvent(message, getBaseProperties.attributes.getAwip);
1612
1625
  processed.push({
1613
- preformance: performance.now() - tick,
1626
+ performance: performance.now() - tick,
1614
1627
  tracking: this.getTracking(getBaseProperties),
1615
1628
  header: getHeader,
1616
1629
  vtec: `N/A`,
@@ -1668,7 +1681,7 @@ var CapAlerts = class {
1668
1681
  const getHeader = events_default.getHeader(__spreadValues({}, validated.attributes));
1669
1682
  const getSource = text_default.textProductToString(extracted.description, `SOURCE...`, [`.`]) || `N/A`;
1670
1683
  processed.push({
1671
- preformance: performance.now() - tick,
1684
+ performance: performance.now() - tick,
1672
1685
  tracking: this.getTracking(extracted),
1673
1686
  header: getHeader,
1674
1687
  vtec: extracted.vtec || `N/A`,
@@ -1699,7 +1712,13 @@ var CapAlerts = class {
1699
1712
  discussion_wind_intensity: `N/A`,
1700
1713
  discussion_hail_intensity: `N/A`
1701
1714
  },
1702
- geometry: extracted.polygon ? { type: `Polygon`, coordinates: extracted.polygon.split(` `).map((coord) => coord.split(`,`).map((num) => parseFloat(num))) } : null
1715
+ geometry: extracted.polygon ? {
1716
+ type: `Polygon`,
1717
+ coordinates: extracted.polygon.split(` `).map((coord) => {
1718
+ const [lon, lat] = coord.split(`,`).map((num) => parseFloat(num));
1719
+ return [lat, lon];
1720
+ })
1721
+ } : null
1703
1722
  }
1704
1723
  });
1705
1724
  }
@@ -1726,7 +1745,7 @@ var APIAlerts = class {
1726
1745
  }
1727
1746
  static event(validated) {
1728
1747
  return __async(this, null, function* () {
1729
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca;
1748
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia;
1730
1749
  let processed = [];
1731
1750
  const messages = Object.values(JSON.parse(validated.message).features);
1732
1751
  for (let feature of messages) {
@@ -1741,7 +1760,7 @@ var APIAlerts = class {
1741
1760
  const getSource = text_default.textProductToString(getDescription, `SOURCE...`, [`.`]) || `N/A`;
1742
1761
  const getOffice = this.getICAO(getVTEC || ``);
1743
1762
  processed.push({
1744
- preformance: performance.now() - tick,
1763
+ performance: performance.now() - tick,
1745
1764
  tracking: this.getTracking({ vtec: getVTEC, wmoidentifier: getWmo, ugc: getUgc ? getUgc.join(`,`) : null }),
1746
1765
  header: getHeader,
1747
1766
  vtec: getVTEC || `N/A`,
@@ -1776,7 +1795,13 @@ var APIAlerts = class {
1776
1795
  peakWindGust: `N/A`,
1777
1796
  peakHailSize: `N/A`
1778
1797
  },
1779
- geometry: (_ca = feature == null ? void 0 : feature.geometry) != null ? _ca : null
1798
+ geometry: ((_ea = (_da = (_ca = feature == null ? void 0 : feature.geometry) == null ? void 0 : _ca.coordinates) == null ? void 0 : _da[0]) == null ? void 0 : _ea.length) ? {
1799
+ type: ((_fa = feature == null ? void 0 : feature.geometry) == null ? void 0 : _fa.type) || "Polygon",
1800
+ coordinates: (_ia = (_ha = (_ga = feature == null ? void 0 : feature.geometry) == null ? void 0 : _ga.coordinates) == null ? void 0 : _ha[0]) == null ? void 0 : _ia.map((coord) => {
1801
+ const [lon, lat] = Array.isArray(coord) ? coord : [0, 0];
1802
+ return [lon, lat];
1803
+ })
1804
+ } : null
1780
1805
  }
1781
1806
  });
1782
1807
  }
@@ -2330,16 +2355,17 @@ var EventParser = class {
2330
2355
  }
2331
2356
  }
2332
2357
  const filtered = events2.filter((alert) => {
2333
- var _a2, _b2, _c2, _d2;
2358
+ var _a2, _b2, _d2, _e2;
2334
2359
  const originalEvent = alert;
2335
2360
  const props = originalEvent == null ? void 0 : originalEvent.properties;
2336
2361
  const ugcs = (_b2 = (_a2 = props == null ? void 0 : props.geocode) == null ? void 0 : _a2.UGC) != null ? _b2 : [];
2362
+ const _c2 = originalEvent, { performance: performance2, header } = _c2, eventWithoutPerformance = __objRest(_c2, ["performance", "header"]);
2337
2363
  if (bools == null ? void 0 : bools.betterEventParsing) {
2338
2364
  const { eventName, tags } = this.enhanceEvent(originalEvent);
2339
2365
  originalEvent.properties.event = eventName;
2340
2366
  originalEvent.properties.tags = tags;
2341
2367
  }
2342
- const eventCheck = (bools == null ? void 0 : bools.useParentEvents) ? (_c2 = props.parent) == null ? void 0 : _c2.toLowerCase() : (_d2 = props.event) == null ? void 0 : _d2.toLowerCase();
2368
+ const eventCheck = (bools == null ? void 0 : bools.useParentEvents) ? (_d2 = props.parent) == null ? void 0 : _d2.toLowerCase() : (_e2 = props.event) == null ? void 0 : _e2.toLowerCase();
2343
2369
  const statusCorrelation = definitions.correlations.find((c) => c.type === originalEvent.properties.action_type);
2344
2370
  for (const key in sets) {
2345
2371
  const setting = sets[key];
@@ -2358,16 +2384,15 @@ var EventParser = class {
2358
2384
  if (key === "checkExpired" && setting && new Date(props == null ? void 0 : props.expires).getTime() < (/* @__PURE__ */ new Date()).getTime()) return false;
2359
2385
  }
2360
2386
  originalEvent.properties.action_type = statusCorrelation ? statusCorrelation.forward : originalEvent.properties.action_type;
2361
- originalEvent.properties.is_updated = statusCorrelation ? statusCorrelation.update == true && bools.checkExpired : false;
2362
- originalEvent.properties.is_issued = statusCorrelation ? statusCorrelation.new == true && bools.checkExpired : false;
2363
- originalEvent.properties.is_cancelled = statusCorrelation ? statusCorrelation.cancel == true && bools.checkExpired : false;
2364
- originalEvent.hash = packages.crypto.createHash("md5").update(JSON.stringify(originalEvent)).digest("hex");
2387
+ originalEvent.properties.is_updated = statusCorrelation ? statusCorrelation.update == true : false;
2388
+ originalEvent.properties.is_issued = statusCorrelation ? statusCorrelation.new == true : false;
2389
+ originalEvent.properties.is_cancelled = statusCorrelation ? statusCorrelation.cancel == true : false;
2390
+ originalEvent.hash = packages.crypto.createHash("md5").update(JSON.stringify(eventWithoutPerformance)).digest("hex");
2365
2391
  if (props.description) {
2366
2392
  const detectedPhrase = definitions.cancelSignatures.find((sig) => props.description.toLowerCase().includes(sig.toLowerCase()));
2367
- if (detectedPhrase && bools.checkExpired) {
2393
+ if (detectedPhrase) {
2368
2394
  originalEvent.properties.action_type = "Cancel";
2369
2395
  originalEvent.properties.is_cancelled = true;
2370
- return false;
2371
2396
  }
2372
2397
  }
2373
2398
  if (originalEvent.vtec) {
@@ -2377,6 +2402,7 @@ var EventParser = class {
2377
2402
  return false;
2378
2403
  }
2379
2404
  }
2405
+ if (bools.checkExpired && originalEvent.properties.is_cancelled == true) return false;
2380
2406
  cache.events.emit(`on${originalEvent.properties.parent.replace(/\s+/g, "")}`);
2381
2407
  return true;
2382
2408
  });
@@ -2741,8 +2767,8 @@ var Utils = class {
2741
2767
  * @static
2742
2768
  */
2743
2769
  static detectUncaughtExceptions() {
2744
- if (process.listeners("uncaughtException").some((l) => l.name === "uncaughtExceptionHandler")) return;
2745
- process.on(`uncaughtException`, (error) => {
2770
+ if (cache.events.listenerCount("uncaughtException") > 0) return;
2771
+ cache.events.on("uncaughtException", (error) => {
2746
2772
  cache.events.emit(`onError`, { message: `Uncaught Exception: ${error.message}`, code: `error-uncaught-exception`, stack: error.stack });
2747
2773
  });
2748
2774
  }
@@ -2860,7 +2886,7 @@ var Utils = class {
2860
2886
  };
2861
2887
  var utils_default = Utils;
2862
2888
 
2863
- // src/helper.ts
2889
+ // src/index.ts
2864
2890
  var AlertManager = class {
2865
2891
  constructor(metadata) {
2866
2892
  this.start(metadata);
@@ -2965,7 +2991,9 @@ var AlertManager = class {
2965
2991
  return Promise.resolve();
2966
2992
  }
2967
2993
  this.setSettings(metadata);
2968
- utils_default.detectUncaughtExceptions();
2994
+ if (settings.catchUnhandledExceptions) {
2995
+ utils_default.detectUncaughtExceptions();
2996
+ }
2969
2997
  const settings2 = settings;
2970
2998
  this.isNoaaWeatherWireService = settings.isNWWS;
2971
2999
  cache.isReady = false;
@@ -3001,7 +3029,7 @@ var AlertManager = class {
3001
3029
  });
3002
3030
  }
3003
3031
  };
3004
- var helper_default = AlertManager;
3032
+ var index_default = AlertManager;
3005
3033
  // Annotate the CommonJS export names for ESM import in node:
3006
3034
  0 && (module.exports = {
3007
3035
  AlertManager,
@@ -17,6 +17,18 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
20
32
  var __async = (__this, __arguments, generator) => {
21
33
  return new Promise((resolve, reject) => {
22
34
  var fulfilled = (value) => {
@@ -888,6 +900,7 @@ var cache = {
888
900
  var settings = {
889
901
  database: path.join(process.cwd(), "shapefiles.db"),
890
902
  isNWWS: true,
903
+ catchUnhandledExceptions: false,
891
904
  NoaaWeatherWireService: {
892
905
  clientReconnections: {
893
906
  canReconnect: true,
@@ -1463,7 +1476,7 @@ var VTECAlerts = class {
1463
1476
  const getBaseProperties = yield events_default.getBaseProperties(message, validated, getUGC, vtec);
1464
1477
  const getHeader = events_default.getHeader(__spreadValues(__spreadValues({}, validated.attributes), getBaseProperties.attributes), getBaseProperties, vtec);
1465
1478
  processed.push({
1466
- preformance: performance.now() - tick,
1479
+ performance: performance.now() - tick,
1467
1480
  tracking: vtec.tracking,
1468
1481
  header: getHeader,
1469
1482
  vtec: vtec.raw,
@@ -1531,7 +1544,7 @@ var UGCAlerts = class {
1531
1544
  const getHeader = events_default.getHeader(__spreadValues(__spreadValues({}, validated.attributes), getBaseProperties.attributes), getBaseProperties);
1532
1545
  const getEvent = this.getEvent(message, getBaseProperties.attributes.getAwip);
1533
1546
  processed.push({
1534
- preformance: performance.now() - tick,
1547
+ performance: performance.now() - tick,
1535
1548
  tracking: this.getTracking(getBaseProperties, getUGC.zones),
1536
1549
  header: getHeader,
1537
1550
  vtec: `N/A`,
@@ -1569,7 +1582,7 @@ var UGCAlerts2 = class {
1569
1582
  const getHeader = events_default.getHeader(__spreadValues(__spreadValues({}, validated.attributes), getBaseProperties.attributes), getBaseProperties);
1570
1583
  const getEvent = this.getEvent(message, getBaseProperties.attributes.getAwip);
1571
1584
  processed.push({
1572
- preformance: performance.now() - tick,
1585
+ performance: performance.now() - tick,
1573
1586
  tracking: this.getTracking(getBaseProperties),
1574
1587
  header: getHeader,
1575
1588
  vtec: `N/A`,
@@ -1627,7 +1640,7 @@ var CapAlerts = class {
1627
1640
  const getHeader = events_default.getHeader(__spreadValues({}, validated.attributes));
1628
1641
  const getSource = text_default.textProductToString(extracted.description, `SOURCE...`, [`.`]) || `N/A`;
1629
1642
  processed.push({
1630
- preformance: performance.now() - tick,
1643
+ performance: performance.now() - tick,
1631
1644
  tracking: this.getTracking(extracted),
1632
1645
  header: getHeader,
1633
1646
  vtec: extracted.vtec || `N/A`,
@@ -1658,7 +1671,13 @@ var CapAlerts = class {
1658
1671
  discussion_wind_intensity: `N/A`,
1659
1672
  discussion_hail_intensity: `N/A`
1660
1673
  },
1661
- geometry: extracted.polygon ? { type: `Polygon`, coordinates: extracted.polygon.split(` `).map((coord) => coord.split(`,`).map((num) => parseFloat(num))) } : null
1674
+ geometry: extracted.polygon ? {
1675
+ type: `Polygon`,
1676
+ coordinates: extracted.polygon.split(` `).map((coord) => {
1677
+ const [lon, lat] = coord.split(`,`).map((num) => parseFloat(num));
1678
+ return [lat, lon];
1679
+ })
1680
+ } : null
1662
1681
  }
1663
1682
  });
1664
1683
  }
@@ -1685,7 +1704,7 @@ var APIAlerts = class {
1685
1704
  }
1686
1705
  static event(validated) {
1687
1706
  return __async(this, null, function* () {
1688
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca;
1707
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia;
1689
1708
  let processed = [];
1690
1709
  const messages = Object.values(JSON.parse(validated.message).features);
1691
1710
  for (let feature of messages) {
@@ -1700,7 +1719,7 @@ var APIAlerts = class {
1700
1719
  const getSource = text_default.textProductToString(getDescription, `SOURCE...`, [`.`]) || `N/A`;
1701
1720
  const getOffice = this.getICAO(getVTEC || ``);
1702
1721
  processed.push({
1703
- preformance: performance.now() - tick,
1722
+ performance: performance.now() - tick,
1704
1723
  tracking: this.getTracking({ vtec: getVTEC, wmoidentifier: getWmo, ugc: getUgc ? getUgc.join(`,`) : null }),
1705
1724
  header: getHeader,
1706
1725
  vtec: getVTEC || `N/A`,
@@ -1735,7 +1754,13 @@ var APIAlerts = class {
1735
1754
  peakWindGust: `N/A`,
1736
1755
  peakHailSize: `N/A`
1737
1756
  },
1738
- geometry: (_ca = feature == null ? void 0 : feature.geometry) != null ? _ca : null
1757
+ geometry: ((_ea = (_da = (_ca = feature == null ? void 0 : feature.geometry) == null ? void 0 : _ca.coordinates) == null ? void 0 : _da[0]) == null ? void 0 : _ea.length) ? {
1758
+ type: ((_fa = feature == null ? void 0 : feature.geometry) == null ? void 0 : _fa.type) || "Polygon",
1759
+ coordinates: (_ia = (_ha = (_ga = feature == null ? void 0 : feature.geometry) == null ? void 0 : _ga.coordinates) == null ? void 0 : _ha[0]) == null ? void 0 : _ia.map((coord) => {
1760
+ const [lon, lat] = Array.isArray(coord) ? coord : [0, 0];
1761
+ return [lon, lat];
1762
+ })
1763
+ } : null
1739
1764
  }
1740
1765
  });
1741
1766
  }
@@ -2289,16 +2314,17 @@ var EventParser = class {
2289
2314
  }
2290
2315
  }
2291
2316
  const filtered = events2.filter((alert) => {
2292
- var _a2, _b2, _c2, _d2;
2317
+ var _a2, _b2, _d2, _e2;
2293
2318
  const originalEvent = alert;
2294
2319
  const props = originalEvent == null ? void 0 : originalEvent.properties;
2295
2320
  const ugcs = (_b2 = (_a2 = props == null ? void 0 : props.geocode) == null ? void 0 : _a2.UGC) != null ? _b2 : [];
2321
+ const _c2 = originalEvent, { performance: performance2, header } = _c2, eventWithoutPerformance = __objRest(_c2, ["performance", "header"]);
2296
2322
  if (bools == null ? void 0 : bools.betterEventParsing) {
2297
2323
  const { eventName, tags } = this.enhanceEvent(originalEvent);
2298
2324
  originalEvent.properties.event = eventName;
2299
2325
  originalEvent.properties.tags = tags;
2300
2326
  }
2301
- const eventCheck = (bools == null ? void 0 : bools.useParentEvents) ? (_c2 = props.parent) == null ? void 0 : _c2.toLowerCase() : (_d2 = props.event) == null ? void 0 : _d2.toLowerCase();
2327
+ const eventCheck = (bools == null ? void 0 : bools.useParentEvents) ? (_d2 = props.parent) == null ? void 0 : _d2.toLowerCase() : (_e2 = props.event) == null ? void 0 : _e2.toLowerCase();
2302
2328
  const statusCorrelation = definitions.correlations.find((c) => c.type === originalEvent.properties.action_type);
2303
2329
  for (const key in sets) {
2304
2330
  const setting = sets[key];
@@ -2317,16 +2343,15 @@ var EventParser = class {
2317
2343
  if (key === "checkExpired" && setting && new Date(props == null ? void 0 : props.expires).getTime() < (/* @__PURE__ */ new Date()).getTime()) return false;
2318
2344
  }
2319
2345
  originalEvent.properties.action_type = statusCorrelation ? statusCorrelation.forward : originalEvent.properties.action_type;
2320
- originalEvent.properties.is_updated = statusCorrelation ? statusCorrelation.update == true && bools.checkExpired : false;
2321
- originalEvent.properties.is_issued = statusCorrelation ? statusCorrelation.new == true && bools.checkExpired : false;
2322
- originalEvent.properties.is_cancelled = statusCorrelation ? statusCorrelation.cancel == true && bools.checkExpired : false;
2323
- originalEvent.hash = packages.crypto.createHash("md5").update(JSON.stringify(originalEvent)).digest("hex");
2346
+ originalEvent.properties.is_updated = statusCorrelation ? statusCorrelation.update == true : false;
2347
+ originalEvent.properties.is_issued = statusCorrelation ? statusCorrelation.new == true : false;
2348
+ originalEvent.properties.is_cancelled = statusCorrelation ? statusCorrelation.cancel == true : false;
2349
+ originalEvent.hash = packages.crypto.createHash("md5").update(JSON.stringify(eventWithoutPerformance)).digest("hex");
2324
2350
  if (props.description) {
2325
2351
  const detectedPhrase = definitions.cancelSignatures.find((sig) => props.description.toLowerCase().includes(sig.toLowerCase()));
2326
- if (detectedPhrase && bools.checkExpired) {
2352
+ if (detectedPhrase) {
2327
2353
  originalEvent.properties.action_type = "Cancel";
2328
2354
  originalEvent.properties.is_cancelled = true;
2329
- return false;
2330
2355
  }
2331
2356
  }
2332
2357
  if (originalEvent.vtec) {
@@ -2336,6 +2361,7 @@ var EventParser = class {
2336
2361
  return false;
2337
2362
  }
2338
2363
  }
2364
+ if (bools.checkExpired && originalEvent.properties.is_cancelled == true) return false;
2339
2365
  cache.events.emit(`on${originalEvent.properties.parent.replace(/\s+/g, "")}`);
2340
2366
  return true;
2341
2367
  });
@@ -2700,8 +2726,8 @@ var Utils = class {
2700
2726
  * @static
2701
2727
  */
2702
2728
  static detectUncaughtExceptions() {
2703
- if (process.listeners("uncaughtException").some((l) => l.name === "uncaughtExceptionHandler")) return;
2704
- process.on(`uncaughtException`, (error) => {
2729
+ if (cache.events.listenerCount("uncaughtException") > 0) return;
2730
+ cache.events.on("uncaughtException", (error) => {
2705
2731
  cache.events.emit(`onError`, { message: `Uncaught Exception: ${error.message}`, code: `error-uncaught-exception`, stack: error.stack });
2706
2732
  });
2707
2733
  }
@@ -2819,7 +2845,7 @@ var Utils = class {
2819
2845
  };
2820
2846
  var utils_default = Utils;
2821
2847
 
2822
- // src/helper.ts
2848
+ // src/index.ts
2823
2849
  var AlertManager = class {
2824
2850
  constructor(metadata) {
2825
2851
  this.start(metadata);
@@ -2924,7 +2950,9 @@ var AlertManager = class {
2924
2950
  return Promise.resolve();
2925
2951
  }
2926
2952
  this.setSettings(metadata);
2927
- utils_default.detectUncaughtExceptions();
2953
+ if (settings.catchUnhandledExceptions) {
2954
+ utils_default.detectUncaughtExceptions();
2955
+ }
2928
2956
  const settings2 = settings;
2929
2957
  this.isNoaaWeatherWireService = settings.isNWWS;
2930
2958
  cache.isReady = false;
@@ -2960,7 +2988,7 @@ var AlertManager = class {
2960
2988
  });
2961
2989
  }
2962
2990
  };
2963
- var helper_default = AlertManager;
2991
+ var index_default = AlertManager;
2964
2992
  export {
2965
2993
  AlertManager,
2966
2994
  database_default as Database,
@@ -2970,6 +2998,6 @@ export {
2970
2998
  text_default as TextParser,
2971
2999
  ugc_default as UGCParser,
2972
3000
  vtec_default as VtecParser,
2973
- helper_default as default,
3001
+ index_default as default,
2974
3002
  types_exports as types
2975
3003
  };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "atmosx-nwws-parser",
3
- "version": "1.0.2022",
3
+ "version": "1.0.2031",
4
4
  "description": "NOAA Weather Wire Parser - Built for standalone and Project AtmosphericX Integration.",
5
- "main": "dist/cjs/helper.cjs",
5
+ "main": "dist/cjs/index.cjs",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/K3YOMI/atmosx-nwws-parser.git",
package/src/bootstrap.ts CHANGED
@@ -66,6 +66,7 @@ export const cache = {
66
66
  export const settings = {
67
67
  database: path.join(process.cwd(), 'shapefiles.db'),
68
68
  isNWWS: true,
69
+ catchUnhandledExceptions: false,
69
70
  NoaaWeatherWireService: {
70
71
  clientReconnections: {
71
72
  canReconnect: true,
@@ -128,7 +128,7 @@ export class AlertManager {
128
128
  return Promise.resolve();
129
129
  }
130
130
  this.setSettings(metadata);
131
- Utils.detectUncaughtExceptions();
131
+ if (loader.settings.catchUnhandledExceptions) { Utils.detectUncaughtExceptions(); }
132
132
  const settings = loader.settings as types.ClientSettings;
133
133
  this.isNoaaWeatherWireService = loader.settings.isNWWS
134
134
  loader.cache.isReady = false;
@@ -158,6 +158,7 @@ export class EventParser {
158
158
  const originalEvent = alert
159
159
  const props = originalEvent?.properties;
160
160
  const ugcs = props?.geocode?.UGC ?? [];
161
+ const { performance, header, ...eventWithoutPerformance } = originalEvent;
161
162
  if (bools?.betterEventParsing) {
162
163
  const { eventName, tags } = this.enhanceEvent(originalEvent);
163
164
  originalEvent.properties.event = eventName;
@@ -180,19 +181,20 @@ export class EventParser {
180
181
  if (key === 'checkExpired' && setting && new Date(props?.expires).getTime() < new Date().getTime()) return false;
181
182
  }
182
183
  originalEvent.properties.action_type = statusCorrelation ? statusCorrelation.forward : originalEvent.properties.action_type;
183
- originalEvent.properties.is_updated = statusCorrelation ? (statusCorrelation.update == true && bools.checkExpired) : false;
184
- originalEvent.properties.is_issued = statusCorrelation ? (statusCorrelation.new == true && bools.checkExpired) : false;
185
- originalEvent.properties.is_cancelled = statusCorrelation ? (statusCorrelation.cancel == true && bools.checkExpired) : false;
186
- originalEvent.hash = loader.packages.crypto.createHash('md5').update(JSON.stringify(originalEvent)).digest('hex');
184
+ originalEvent.properties.is_updated = statusCorrelation ? (statusCorrelation.update == true) : false;
185
+ originalEvent.properties.is_issued = statusCorrelation ? (statusCorrelation.new == true) : false;
186
+ originalEvent.properties.is_cancelled = statusCorrelation ? (statusCorrelation.cancel == true) : false;
187
+ originalEvent.hash = loader.packages.crypto.createHash('md5').update(JSON.stringify(eventWithoutPerformance)).digest('hex');
187
188
  if (props.description) {
188
189
  const detectedPhrase = loader.definitions.cancelSignatures.find(sig => props.description.toLowerCase().includes(sig.toLowerCase()));
189
- if (detectedPhrase && bools.checkExpired) { originalEvent.properties.action_type = 'Cancel'; originalEvent.properties.is_cancelled = true; return false; }
190
+ if (detectedPhrase) { originalEvent.properties.action_type = 'Cancel'; originalEvent.properties.is_cancelled = true; }
190
191
  }
191
192
  if (originalEvent.vtec) {
192
193
  const getType = originalEvent.vtec.split(`.`)[0];
193
194
  const isTestProduct = loader.definitions.productTypes[getType] == `Test Product`
194
195
  if (isTestProduct) { return false; }
195
196
  }
197
+ if (bools.checkExpired && originalEvent.properties.is_cancelled == true) return false;
196
198
  loader.cache.events.emit(`on${originalEvent.properties.parent.replace(/\s+/g, '')}`)
197
199
  return true;
198
200
  })
@@ -48,7 +48,7 @@ export class APIAlerts {
48
48
  const getSource = TextParser.textProductToString(getDescription, `SOURCE...`, [`.`]) || `N/A`;
49
49
  const getOffice = this.getICAO(getVTEC || ``);
50
50
  processed.push({
51
- preformance: performance.now() - tick,
51
+ performance: performance.now() - tick,
52
52
  tracking: this.getTracking({ vtec: getVTEC, wmoidentifier: getWmo, ugc: getUgc ? getUgc.join(`,`) : null }),
53
53
  header: getHeader,
54
54
  vtec: getVTEC || `N/A`,
@@ -83,7 +83,13 @@ export class APIAlerts {
83
83
  peakWindGust: `N/A`,
84
84
  peakHailSize: `N/A`,
85
85
  },
86
- geometry: feature?.geometry ?? null,
86
+ geometry: feature?.geometry?.coordinates?.[0]?.length ? {
87
+ type: feature?.geometry?.type || 'Polygon',
88
+ coordinates: feature?.geometry?.coordinates?.[0]?.map((coord: number) => {
89
+ const [lon, lat] = Array.isArray(coord) ? coord : [0, 0];
90
+ return [lon, lat];
91
+ })
92
+ } : null
87
93
  }
88
94
  })
89
95
  }
@@ -47,7 +47,7 @@ export class CapAlerts {
47
47
  const getHeader = EventParser.getHeader({ ...validated.attributes,} as types.TypeAttributes);
48
48
  const getSource = TextParser.textProductToString(extracted.description, `SOURCE...`, [`.`]) || `N/A`;
49
49
  processed.push({
50
- preformance: performance.now() - tick,
50
+ performance: performance.now() - tick,
51
51
  tracking: this.getTracking(extracted),
52
52
  header: getHeader,
53
53
  vtec: extracted.vtec || `N/A`,
@@ -78,7 +78,13 @@ export class CapAlerts {
78
78
  discussion_wind_intensity: `N/A`,
79
79
  discussion_hail_intensity: `N/A`,
80
80
  },
81
- geometry: extracted.polygon ? { type: `Polygon`, coordinates: extracted.polygon.split(` `).map((coord: string) => coord.split(`,`).map((num: string) => parseFloat(num))) } : null,
81
+ geometry: extracted.polygon ? {
82
+ type: `Polygon`,
83
+ coordinates: extracted.polygon.split(` `).map((coord: string) => {
84
+ const [lon, lat] = coord.split(`,`).map((num: string) => parseFloat(num));
85
+ return [lat, lon];
86
+ })
87
+ } : null,
82
88
  }
83
89
  })
84
90
  }
@@ -39,7 +39,7 @@ export class UGCAlerts {
39
39
  const getHeader = EventParser.getHeader({ ...validated.attributes, ...getBaseProperties.attributes } as types.TypeAttributes, getBaseProperties);
40
40
  const getEvent = this.getEvent(message, getBaseProperties.attributes.getAwip);
41
41
  processed.push({
42
- preformance: performance.now() - tick,
42
+ performance: performance.now() - tick,
43
43
  tracking: this.getTracking(getBaseProperties),
44
44
  header: getHeader,
45
45
  vtec: `N/A`,
@@ -69,7 +69,7 @@ export class UGCAlerts {
69
69
  const getHeader = EventParser.getHeader({ ...validated.attributes, ...getBaseProperties.attributes } as types.TypeAttributes, getBaseProperties);
70
70
  const getEvent = this.getEvent(message, getBaseProperties.attributes.getAwip);
71
71
  processed.push({
72
- preformance: performance.now() - tick,
72
+ performance: performance.now() - tick,
73
73
  tracking: this.getTracking(getBaseProperties, getUGC.zones),
74
74
  header: getHeader,
75
75
  vtec: `N/A`,
@@ -43,7 +43,7 @@ export class VTECAlerts {
43
43
  const getBaseProperties = await EventParser.getBaseProperties(message, validated, getUGC, vtec) as types.BaseProperties;
44
44
  const getHeader = EventParser.getHeader({ ...validated.attributes, ...getBaseProperties.attributes } as types.TypeAttributes, getBaseProperties, vtec);
45
45
  processed.push({
46
- preformance: performance.now() - tick,
46
+ performance: performance.now() - tick,
47
47
  tracking: vtec.tracking,
48
48
  header: getHeader,
49
49
  vtec: vtec.raw,
package/src/types.ts CHANGED
@@ -164,6 +164,7 @@ export interface TypeAlert {
164
164
  export interface ClientSettings {
165
165
  database?: string,
166
166
  isNWWS: boolean,
167
+ catchUnhandledExceptions: boolean,
167
168
  NoaaWeatherWireService: NoaaWeatherWireServiceSettings,
168
169
  NationalWeatherService: NationalWeatherServiceSettings,
169
170
  global: GlobalSettings,
package/src/utils.ts CHANGED
@@ -92,10 +92,10 @@ export class Utils {
92
92
  * @static
93
93
  */
94
94
  public static detectUncaughtExceptions(): void {
95
- if (process.listeners('uncaughtException').some(l => l.name === 'uncaughtExceptionHandler')) return;
96
- process.on(`uncaughtException`, (error: Error) => {
95
+ if (loader.cache.events.listenerCount('uncaughtException') > 0) return;
96
+ loader.cache.events.on('uncaughtException', (error: Error) => {
97
97
  loader.cache.events.emit(`onError`, {message: `Uncaught Exception: ${error.message}`, code: `error-uncaught-exception`, stack: error.stack});
98
- })
98
+ });
99
99
  }
100
100
 
101
101
  /**
package/tsup.config.ts CHANGED
@@ -1,11 +1,14 @@
1
- import { defineConfig } from 'tsup';
1
+ import { defineConfig } from 'tsup'
2
2
 
3
3
  export default defineConfig({
4
- entry: ['src/**/*.ts'],
5
- format: ['esm', 'cjs'],
4
+ entry: ['src/index.ts'],
6
5
  outDir: 'dist',
7
- splitting: false,
6
+ format: ['esm', 'cjs'],
8
7
  clean: true,
9
- outExtension({ format }) {return {js: format === 'esm' ? '.mjs' : '.cjs',};},
10
- esbuildOptions(options, context) { options.outdir = `dist/${context.format}`; },
11
- });
8
+ outExtension({ format }) {
9
+ return { js: format === 'esm' ? '.mjs' : '.cjs' }
10
+ },
11
+ esbuildOptions(options, context) {
12
+ options.outdir = `dist/${context.format}`
13
+ },
14
+ })