atmosx-nwws-parser 1.0.2023 → 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} +41 -26
  2. package/dist/esm/{helper.mjs → index.mjs} +37 -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 +6 -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 -2867
  23. package/dist/cjs/parsers/events.cjs +0 -2867
  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 -2867
  27. package/dist/cjs/parsers/types/cap.cjs +0 -2867
  28. package/dist/cjs/parsers/types/text.cjs +0 -2867
  29. package/dist/cjs/parsers/types/ugc.cjs +0 -2867
  30. package/dist/cjs/parsers/types/vtec.cjs +0 -2867
  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 -2867
  35. package/dist/cjs/xmpp.cjs +0 -2867
  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 -2834
  44. package/dist/esm/parsers/events.mjs +0 -2834
  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 -2834
  48. package/dist/esm/parsers/types/cap.mjs +0 -2834
  49. package/dist/esm/parsers/types/text.mjs +0 -2834
  50. package/dist/esm/parsers/types/ugc.mjs +0 -2834
  51. package/dist/esm/parsers/types/vtec.mjs +0 -2834
  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 -2834
  56. package/dist/esm/xmpp.mjs +0 -2834
@@ -75,9 +75,9 @@ var __async = (__this, __arguments, generator) => {
75
75
  });
76
76
  };
77
77
 
78
- // src/helper.ts
79
- var helper_exports = {};
80
- __export(helper_exports, {
78
+ // src/index.ts
79
+ var index_exports = {};
80
+ __export(index_exports, {
81
81
  AlertManager: () => AlertManager,
82
82
  Database: () => database_default,
83
83
  EAS: () => eas_default,
@@ -86,10 +86,10 @@ __export(helper_exports, {
86
86
  TextParser: () => text_default,
87
87
  UGCParser: () => ugc_default,
88
88
  VtecParser: () => vtec_default,
89
- default: () => helper_default,
89
+ default: () => index_default,
90
90
  types: () => types_exports
91
91
  });
92
- module.exports = __toCommonJS(helper_exports);
92
+ module.exports = __toCommonJS(index_exports);
93
93
 
94
94
  // src/bootstrap.ts
95
95
  var fs = __toESM(require("fs"));
@@ -941,6 +941,7 @@ var cache = {
941
941
  var settings = {
942
942
  database: path.join(process.cwd(), "shapefiles.db"),
943
943
  isNWWS: true,
944
+ catchUnhandledExceptions: false,
944
945
  NoaaWeatherWireService: {
945
946
  clientReconnections: {
946
947
  canReconnect: true,
@@ -1516,7 +1517,7 @@ var VTECAlerts = class {
1516
1517
  const getBaseProperties = yield events_default.getBaseProperties(message, validated, getUGC, vtec);
1517
1518
  const getHeader = events_default.getHeader(__spreadValues(__spreadValues({}, validated.attributes), getBaseProperties.attributes), getBaseProperties, vtec);
1518
1519
  processed.push({
1519
- preformance: performance.now() - tick,
1520
+ performance: performance.now() - tick,
1520
1521
  tracking: vtec.tracking,
1521
1522
  header: getHeader,
1522
1523
  vtec: vtec.raw,
@@ -1584,7 +1585,7 @@ var UGCAlerts = class {
1584
1585
  const getHeader = events_default.getHeader(__spreadValues(__spreadValues({}, validated.attributes), getBaseProperties.attributes), getBaseProperties);
1585
1586
  const getEvent = this.getEvent(message, getBaseProperties.attributes.getAwip);
1586
1587
  processed.push({
1587
- preformance: performance.now() - tick,
1588
+ performance: performance.now() - tick,
1588
1589
  tracking: this.getTracking(getBaseProperties, getUGC.zones),
1589
1590
  header: getHeader,
1590
1591
  vtec: `N/A`,
@@ -1622,7 +1623,7 @@ var UGCAlerts2 = class {
1622
1623
  const getHeader = events_default.getHeader(__spreadValues(__spreadValues({}, validated.attributes), getBaseProperties.attributes), getBaseProperties);
1623
1624
  const getEvent = this.getEvent(message, getBaseProperties.attributes.getAwip);
1624
1625
  processed.push({
1625
- preformance: performance.now() - tick,
1626
+ performance: performance.now() - tick,
1626
1627
  tracking: this.getTracking(getBaseProperties),
1627
1628
  header: getHeader,
1628
1629
  vtec: `N/A`,
@@ -1680,7 +1681,7 @@ var CapAlerts = class {
1680
1681
  const getHeader = events_default.getHeader(__spreadValues({}, validated.attributes));
1681
1682
  const getSource = text_default.textProductToString(extracted.description, `SOURCE...`, [`.`]) || `N/A`;
1682
1683
  processed.push({
1683
- preformance: performance.now() - tick,
1684
+ performance: performance.now() - tick,
1684
1685
  tracking: this.getTracking(extracted),
1685
1686
  header: getHeader,
1686
1687
  vtec: extracted.vtec || `N/A`,
@@ -1711,7 +1712,13 @@ var CapAlerts = class {
1711
1712
  discussion_wind_intensity: `N/A`,
1712
1713
  discussion_hail_intensity: `N/A`
1713
1714
  },
1714
- 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
1715
1722
  }
1716
1723
  });
1717
1724
  }
@@ -1738,7 +1745,7 @@ var APIAlerts = class {
1738
1745
  }
1739
1746
  static event(validated) {
1740
1747
  return __async(this, null, function* () {
1741
- 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;
1742
1749
  let processed = [];
1743
1750
  const messages = Object.values(JSON.parse(validated.message).features);
1744
1751
  for (let feature of messages) {
@@ -1753,7 +1760,7 @@ var APIAlerts = class {
1753
1760
  const getSource = text_default.textProductToString(getDescription, `SOURCE...`, [`.`]) || `N/A`;
1754
1761
  const getOffice = this.getICAO(getVTEC || ``);
1755
1762
  processed.push({
1756
- preformance: performance.now() - tick,
1763
+ performance: performance.now() - tick,
1757
1764
  tracking: this.getTracking({ vtec: getVTEC, wmoidentifier: getWmo, ugc: getUgc ? getUgc.join(`,`) : null }),
1758
1765
  header: getHeader,
1759
1766
  vtec: getVTEC || `N/A`,
@@ -1788,7 +1795,13 @@ var APIAlerts = class {
1788
1795
  peakWindGust: `N/A`,
1789
1796
  peakHailSize: `N/A`
1790
1797
  },
1791
- 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
1792
1805
  }
1793
1806
  });
1794
1807
  }
@@ -2342,16 +2355,17 @@ var EventParser = class {
2342
2355
  }
2343
2356
  }
2344
2357
  const filtered = events2.filter((alert) => {
2345
- var _a2, _b2, _c2, _d2;
2358
+ var _a2, _b2, _d2, _e2;
2346
2359
  const originalEvent = alert;
2347
2360
  const props = originalEvent == null ? void 0 : originalEvent.properties;
2348
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"]);
2349
2363
  if (bools == null ? void 0 : bools.betterEventParsing) {
2350
2364
  const { eventName, tags } = this.enhanceEvent(originalEvent);
2351
2365
  originalEvent.properties.event = eventName;
2352
2366
  originalEvent.properties.tags = tags;
2353
2367
  }
2354
- 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();
2355
2369
  const statusCorrelation = definitions.correlations.find((c) => c.type === originalEvent.properties.action_type);
2356
2370
  for (const key in sets) {
2357
2371
  const setting = sets[key];
@@ -2370,17 +2384,15 @@ var EventParser = class {
2370
2384
  if (key === "checkExpired" && setting && new Date(props == null ? void 0 : props.expires).getTime() < (/* @__PURE__ */ new Date()).getTime()) return false;
2371
2385
  }
2372
2386
  originalEvent.properties.action_type = statusCorrelation ? statusCorrelation.forward : originalEvent.properties.action_type;
2373
- originalEvent.properties.is_updated = statusCorrelation ? statusCorrelation.update == true && bools.checkExpired : false;
2374
- originalEvent.properties.is_issued = statusCorrelation ? statusCorrelation.new == true && bools.checkExpired : false;
2375
- originalEvent.properties.is_cancelled = statusCorrelation ? statusCorrelation.cancel == true && bools.checkExpired : false;
2376
- const _e2 = originalEvent, { performance: performance2 } = _e2, eventWithoutPerformance = __objRest(_e2, ["performance"]);
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;
2377
2390
  originalEvent.hash = packages.crypto.createHash("md5").update(JSON.stringify(eventWithoutPerformance)).digest("hex");
2378
2391
  if (props.description) {
2379
2392
  const detectedPhrase = definitions.cancelSignatures.find((sig) => props.description.toLowerCase().includes(sig.toLowerCase()));
2380
- if (detectedPhrase && bools.checkExpired) {
2393
+ if (detectedPhrase) {
2381
2394
  originalEvent.properties.action_type = "Cancel";
2382
2395
  originalEvent.properties.is_cancelled = true;
2383
- return false;
2384
2396
  }
2385
2397
  }
2386
2398
  if (originalEvent.vtec) {
@@ -2390,6 +2402,7 @@ var EventParser = class {
2390
2402
  return false;
2391
2403
  }
2392
2404
  }
2405
+ if (bools.checkExpired && originalEvent.properties.is_cancelled == true) return false;
2393
2406
  cache.events.emit(`on${originalEvent.properties.parent.replace(/\s+/g, "")}`);
2394
2407
  return true;
2395
2408
  });
@@ -2754,8 +2767,8 @@ var Utils = class {
2754
2767
  * @static
2755
2768
  */
2756
2769
  static detectUncaughtExceptions() {
2757
- if (process.listeners("uncaughtException").some((l) => l.name === "uncaughtExceptionHandler")) return;
2758
- process.on(`uncaughtException`, (error) => {
2770
+ if (cache.events.listenerCount("uncaughtException") > 0) return;
2771
+ cache.events.on("uncaughtException", (error) => {
2759
2772
  cache.events.emit(`onError`, { message: `Uncaught Exception: ${error.message}`, code: `error-uncaught-exception`, stack: error.stack });
2760
2773
  });
2761
2774
  }
@@ -2873,7 +2886,7 @@ var Utils = class {
2873
2886
  };
2874
2887
  var utils_default = Utils;
2875
2888
 
2876
- // src/helper.ts
2889
+ // src/index.ts
2877
2890
  var AlertManager = class {
2878
2891
  constructor(metadata) {
2879
2892
  this.start(metadata);
@@ -2978,7 +2991,9 @@ var AlertManager = class {
2978
2991
  return Promise.resolve();
2979
2992
  }
2980
2993
  this.setSettings(metadata);
2981
- utils_default.detectUncaughtExceptions();
2994
+ if (settings.catchUnhandledExceptions) {
2995
+ utils_default.detectUncaughtExceptions();
2996
+ }
2982
2997
  const settings2 = settings;
2983
2998
  this.isNoaaWeatherWireService = settings.isNWWS;
2984
2999
  cache.isReady = false;
@@ -3014,7 +3029,7 @@ var AlertManager = class {
3014
3029
  });
3015
3030
  }
3016
3031
  };
3017
- var helper_default = AlertManager;
3032
+ var index_default = AlertManager;
3018
3033
  // Annotate the CommonJS export names for ESM import in node:
3019
3034
  0 && (module.exports = {
3020
3035
  AlertManager,
@@ -900,6 +900,7 @@ var cache = {
900
900
  var settings = {
901
901
  database: path.join(process.cwd(), "shapefiles.db"),
902
902
  isNWWS: true,
903
+ catchUnhandledExceptions: false,
903
904
  NoaaWeatherWireService: {
904
905
  clientReconnections: {
905
906
  canReconnect: true,
@@ -1475,7 +1476,7 @@ var VTECAlerts = class {
1475
1476
  const getBaseProperties = yield events_default.getBaseProperties(message, validated, getUGC, vtec);
1476
1477
  const getHeader = events_default.getHeader(__spreadValues(__spreadValues({}, validated.attributes), getBaseProperties.attributes), getBaseProperties, vtec);
1477
1478
  processed.push({
1478
- preformance: performance.now() - tick,
1479
+ performance: performance.now() - tick,
1479
1480
  tracking: vtec.tracking,
1480
1481
  header: getHeader,
1481
1482
  vtec: vtec.raw,
@@ -1543,7 +1544,7 @@ var UGCAlerts = class {
1543
1544
  const getHeader = events_default.getHeader(__spreadValues(__spreadValues({}, validated.attributes), getBaseProperties.attributes), getBaseProperties);
1544
1545
  const getEvent = this.getEvent(message, getBaseProperties.attributes.getAwip);
1545
1546
  processed.push({
1546
- preformance: performance.now() - tick,
1547
+ performance: performance.now() - tick,
1547
1548
  tracking: this.getTracking(getBaseProperties, getUGC.zones),
1548
1549
  header: getHeader,
1549
1550
  vtec: `N/A`,
@@ -1581,7 +1582,7 @@ var UGCAlerts2 = class {
1581
1582
  const getHeader = events_default.getHeader(__spreadValues(__spreadValues({}, validated.attributes), getBaseProperties.attributes), getBaseProperties);
1582
1583
  const getEvent = this.getEvent(message, getBaseProperties.attributes.getAwip);
1583
1584
  processed.push({
1584
- preformance: performance.now() - tick,
1585
+ performance: performance.now() - tick,
1585
1586
  tracking: this.getTracking(getBaseProperties),
1586
1587
  header: getHeader,
1587
1588
  vtec: `N/A`,
@@ -1639,7 +1640,7 @@ var CapAlerts = class {
1639
1640
  const getHeader = events_default.getHeader(__spreadValues({}, validated.attributes));
1640
1641
  const getSource = text_default.textProductToString(extracted.description, `SOURCE...`, [`.`]) || `N/A`;
1641
1642
  processed.push({
1642
- preformance: performance.now() - tick,
1643
+ performance: performance.now() - tick,
1643
1644
  tracking: this.getTracking(extracted),
1644
1645
  header: getHeader,
1645
1646
  vtec: extracted.vtec || `N/A`,
@@ -1670,7 +1671,13 @@ var CapAlerts = class {
1670
1671
  discussion_wind_intensity: `N/A`,
1671
1672
  discussion_hail_intensity: `N/A`
1672
1673
  },
1673
- 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
1674
1681
  }
1675
1682
  });
1676
1683
  }
@@ -1697,7 +1704,7 @@ var APIAlerts = class {
1697
1704
  }
1698
1705
  static event(validated) {
1699
1706
  return __async(this, null, function* () {
1700
- 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;
1701
1708
  let processed = [];
1702
1709
  const messages = Object.values(JSON.parse(validated.message).features);
1703
1710
  for (let feature of messages) {
@@ -1712,7 +1719,7 @@ var APIAlerts = class {
1712
1719
  const getSource = text_default.textProductToString(getDescription, `SOURCE...`, [`.`]) || `N/A`;
1713
1720
  const getOffice = this.getICAO(getVTEC || ``);
1714
1721
  processed.push({
1715
- preformance: performance.now() - tick,
1722
+ performance: performance.now() - tick,
1716
1723
  tracking: this.getTracking({ vtec: getVTEC, wmoidentifier: getWmo, ugc: getUgc ? getUgc.join(`,`) : null }),
1717
1724
  header: getHeader,
1718
1725
  vtec: getVTEC || `N/A`,
@@ -1747,7 +1754,13 @@ var APIAlerts = class {
1747
1754
  peakWindGust: `N/A`,
1748
1755
  peakHailSize: `N/A`
1749
1756
  },
1750
- 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
1751
1764
  }
1752
1765
  });
1753
1766
  }
@@ -2301,16 +2314,17 @@ var EventParser = class {
2301
2314
  }
2302
2315
  }
2303
2316
  const filtered = events2.filter((alert) => {
2304
- var _a2, _b2, _c2, _d2;
2317
+ var _a2, _b2, _d2, _e2;
2305
2318
  const originalEvent = alert;
2306
2319
  const props = originalEvent == null ? void 0 : originalEvent.properties;
2307
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"]);
2308
2322
  if (bools == null ? void 0 : bools.betterEventParsing) {
2309
2323
  const { eventName, tags } = this.enhanceEvent(originalEvent);
2310
2324
  originalEvent.properties.event = eventName;
2311
2325
  originalEvent.properties.tags = tags;
2312
2326
  }
2313
- 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();
2314
2328
  const statusCorrelation = definitions.correlations.find((c) => c.type === originalEvent.properties.action_type);
2315
2329
  for (const key in sets) {
2316
2330
  const setting = sets[key];
@@ -2329,17 +2343,15 @@ var EventParser = class {
2329
2343
  if (key === "checkExpired" && setting && new Date(props == null ? void 0 : props.expires).getTime() < (/* @__PURE__ */ new Date()).getTime()) return false;
2330
2344
  }
2331
2345
  originalEvent.properties.action_type = statusCorrelation ? statusCorrelation.forward : originalEvent.properties.action_type;
2332
- originalEvent.properties.is_updated = statusCorrelation ? statusCorrelation.update == true && bools.checkExpired : false;
2333
- originalEvent.properties.is_issued = statusCorrelation ? statusCorrelation.new == true && bools.checkExpired : false;
2334
- originalEvent.properties.is_cancelled = statusCorrelation ? statusCorrelation.cancel == true && bools.checkExpired : false;
2335
- const _e2 = originalEvent, { performance: performance2 } = _e2, eventWithoutPerformance = __objRest(_e2, ["performance"]);
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;
2336
2349
  originalEvent.hash = packages.crypto.createHash("md5").update(JSON.stringify(eventWithoutPerformance)).digest("hex");
2337
2350
  if (props.description) {
2338
2351
  const detectedPhrase = definitions.cancelSignatures.find((sig) => props.description.toLowerCase().includes(sig.toLowerCase()));
2339
- if (detectedPhrase && bools.checkExpired) {
2352
+ if (detectedPhrase) {
2340
2353
  originalEvent.properties.action_type = "Cancel";
2341
2354
  originalEvent.properties.is_cancelled = true;
2342
- return false;
2343
2355
  }
2344
2356
  }
2345
2357
  if (originalEvent.vtec) {
@@ -2349,6 +2361,7 @@ var EventParser = class {
2349
2361
  return false;
2350
2362
  }
2351
2363
  }
2364
+ if (bools.checkExpired && originalEvent.properties.is_cancelled == true) return false;
2352
2365
  cache.events.emit(`on${originalEvent.properties.parent.replace(/\s+/g, "")}`);
2353
2366
  return true;
2354
2367
  });
@@ -2713,8 +2726,8 @@ var Utils = class {
2713
2726
  * @static
2714
2727
  */
2715
2728
  static detectUncaughtExceptions() {
2716
- if (process.listeners("uncaughtException").some((l) => l.name === "uncaughtExceptionHandler")) return;
2717
- process.on(`uncaughtException`, (error) => {
2729
+ if (cache.events.listenerCount("uncaughtException") > 0) return;
2730
+ cache.events.on("uncaughtException", (error) => {
2718
2731
  cache.events.emit(`onError`, { message: `Uncaught Exception: ${error.message}`, code: `error-uncaught-exception`, stack: error.stack });
2719
2732
  });
2720
2733
  }
@@ -2832,7 +2845,7 @@ var Utils = class {
2832
2845
  };
2833
2846
  var utils_default = Utils;
2834
2847
 
2835
- // src/helper.ts
2848
+ // src/index.ts
2836
2849
  var AlertManager = class {
2837
2850
  constructor(metadata) {
2838
2851
  this.start(metadata);
@@ -2937,7 +2950,9 @@ var AlertManager = class {
2937
2950
  return Promise.resolve();
2938
2951
  }
2939
2952
  this.setSettings(metadata);
2940
- utils_default.detectUncaughtExceptions();
2953
+ if (settings.catchUnhandledExceptions) {
2954
+ utils_default.detectUncaughtExceptions();
2955
+ }
2941
2956
  const settings2 = settings;
2942
2957
  this.isNoaaWeatherWireService = settings.isNWWS;
2943
2958
  cache.isReady = false;
@@ -2973,7 +2988,7 @@ var AlertManager = class {
2973
2988
  });
2974
2989
  }
2975
2990
  };
2976
- var helper_default = AlertManager;
2991
+ var index_default = AlertManager;
2977
2992
  export {
2978
2993
  AlertManager,
2979
2994
  database_default as Database,
@@ -2983,6 +2998,6 @@ export {
2983
2998
  text_default as TextParser,
2984
2999
  ugc_default as UGCParser,
2985
3000
  vtec_default as VtecParser,
2986
- helper_default as default,
3001
+ index_default as default,
2987
3002
  types_exports as types
2988
3003
  };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "atmosx-nwws-parser",
3
- "version": "1.0.2023",
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,20 +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
- const { performance, ...eventWithoutPerformance } = originalEvent;
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
187
  originalEvent.hash = loader.packages.crypto.createHash('md5').update(JSON.stringify(eventWithoutPerformance)).digest('hex');
188
188
  if (props.description) {
189
189
  const detectedPhrase = loader.definitions.cancelSignatures.find(sig => props.description.toLowerCase().includes(sig.toLowerCase()));
190
- 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; }
191
191
  }
192
192
  if (originalEvent.vtec) {
193
193
  const getType = originalEvent.vtec.split(`.`)[0];
194
194
  const isTestProduct = loader.definitions.productTypes[getType] == `Test Product`
195
195
  if (isTestProduct) { return false; }
196
196
  }
197
+ if (bools.checkExpired && originalEvent.properties.is_cancelled == true) return false;
197
198
  loader.cache.events.emit(`on${originalEvent.properties.parent.replace(/\s+/g, '')}`)
198
199
  return true;
199
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
+ })