@saber-usa/node-common 1.7.16 → 1.7.17
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/README.md +22 -1
- package/package.json +9 -9
- package/src/FrameConverter.js +116 -139
- package/src/LLA.js +1 -1
- package/src/LaunchNominalClass.js +10 -24
- package/src/NodeVector3D.js +2 -2
- package/src/OrbitUtils.js +23 -42
- package/src/ShadowGEOCalculator.js +2 -2
- package/src/TimeConverter.js +11 -9
- package/src/astro.js +170 -164
- package/src/ballisticPropagator.js +34 -40
- package/src/checkNetwork.cjs +21 -21
- package/src/constants.js +2 -2
- package/src/fixDate.js +1 -1
- package/src/index.js +1 -1
- package/src/launchNominal.js +13 -13
- package/src/loggerFactory.cjs +122 -99
- package/src/s3.js +3 -3
- package/src/udl.js +1 -1
- package/src/utils.js +2 -2
|
@@ -103,7 +103,7 @@ class BallisticPropagatorUtils {
|
|
|
103
103
|
*/
|
|
104
104
|
static kepler1(planet, t0, x0, t1) {
|
|
105
105
|
const muqr = 1;
|
|
106
|
-
const tlimit =
|
|
106
|
+
const tlimit = 1e-10;
|
|
107
107
|
const kn = 10;
|
|
108
108
|
|
|
109
109
|
const rex = planet[0];
|
|
@@ -134,7 +134,7 @@ class BallisticPropagatorUtils {
|
|
|
134
134
|
|
|
135
135
|
const d0 = r0.dot(v0);
|
|
136
136
|
const sigma0 = d0 / muqr;
|
|
137
|
-
const alp0 = 2
|
|
137
|
+
const alp0 = 2 / r0Mag - v0Mag * v0Mag;
|
|
138
138
|
|
|
139
139
|
// Initial guess
|
|
140
140
|
let x = alp0 * dt;
|
|
@@ -156,7 +156,7 @@ class BallisticPropagatorUtils {
|
|
|
156
156
|
} else if (alp0 === 0) {
|
|
157
157
|
y = 0;
|
|
158
158
|
cy = 0.5;
|
|
159
|
-
sy = 1
|
|
159
|
+
sy = 1 / 6;
|
|
160
160
|
} else if (alp0 > 0) {
|
|
161
161
|
y = alp0 * x * x;
|
|
162
162
|
yqr = Math.sqrt(y);
|
|
@@ -182,7 +182,7 @@ class BallisticPropagatorUtils {
|
|
|
182
182
|
dx = 0.5 * x;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
if (Math.abs(dx) <
|
|
185
|
+
if (Math.abs(dx) < 1e-10) {break;}
|
|
186
186
|
|
|
187
187
|
x -= dx;
|
|
188
188
|
}
|
|
@@ -217,7 +217,6 @@ class BallisticPropagatorUtils {
|
|
|
217
217
|
*/
|
|
218
218
|
static ballisticProp(x0, span, eqrad, mu, j2, j3) {
|
|
219
219
|
// Setup
|
|
220
|
-
// const pi = 3.141592653589793238;
|
|
221
220
|
const pi = Math.PI;
|
|
222
221
|
const twopi = 2 * pi;
|
|
223
222
|
// const degs = 180 / pi; Astrolibrary's use of degs is unusual in that it calculates a value but immediately discards it.
|
|
@@ -253,13 +252,13 @@ class BallisticPropagatorUtils {
|
|
|
253
252
|
const r0mag = x0.Position.magnitude();
|
|
254
253
|
const v0mag = x0.Velocity.magnitude();
|
|
255
254
|
|
|
256
|
-
const alp0 = 2
|
|
255
|
+
const alp0 = 2 / r0mag - v0mag * v0mag / gm;
|
|
257
256
|
|
|
258
257
|
let periapsisRadius; let e0;
|
|
259
|
-
if (Math.abs(alp0) <
|
|
260
|
-
periapsisRadius = h02 / (2
|
|
258
|
+
if (Math.abs(alp0) < 1e-15) {
|
|
259
|
+
periapsisRadius = h02 / (2 * gm); // Parabolic
|
|
261
260
|
} else {
|
|
262
|
-
const a0 = 1
|
|
261
|
+
const a0 = 1 / alp0;
|
|
263
262
|
const e02 = 1 - alp0 * h02 / gm;
|
|
264
263
|
|
|
265
264
|
if (e02 <= 0) {
|
|
@@ -268,7 +267,7 @@ class BallisticPropagatorUtils {
|
|
|
268
267
|
e0 = Math.sqrt(e02);
|
|
269
268
|
}
|
|
270
269
|
|
|
271
|
-
periapsisRadius = a0 * (1
|
|
270
|
+
periapsisRadius = a0 * (1 - e0);
|
|
272
271
|
}
|
|
273
272
|
|
|
274
273
|
if (periapsisRadius < 210) {
|
|
@@ -289,7 +288,7 @@ class BallisticPropagatorUtils {
|
|
|
289
288
|
// ========== STEP 1: Initial coordinate transformation ==========
|
|
290
289
|
const delta = -xj3 / (2 * xj2);
|
|
291
290
|
const csq = xj2 * (1 - delta * delta / xj2);
|
|
292
|
-
const d0 = Math.
|
|
291
|
+
const d0 = Math.hypot(pin.x, pin.y);
|
|
293
292
|
let alph0 = Math.atan2(pin.y, pin.x);
|
|
294
293
|
|
|
295
294
|
if (alph0 < 0) {alph0 = twopi + alph0;}
|
|
@@ -299,7 +298,7 @@ class BallisticPropagatorUtils {
|
|
|
299
298
|
const rhotemp = r02 - csq + delta * (zpdelta + pin.z);
|
|
300
299
|
const rho0 = Math.sqrt(
|
|
301
300
|
rhotemp + Math.sqrt(rhotemp * rhotemp + 4 * csq * (zpdelta * zpdelta)))
|
|
302
|
-
/ Math.sqrt(2
|
|
301
|
+
/ Math.sqrt(2);
|
|
303
302
|
const rho02 = rho0 * rho0;
|
|
304
303
|
const sigma0 = zpdelta / rho0;
|
|
305
304
|
const rrd = pin.dot(vin); // Using pious-squid dot product
|
|
@@ -343,7 +342,7 @@ class BallisticPropagatorUtils {
|
|
|
343
342
|
a1 = (csq - gam1 * b1) / pgam1;
|
|
344
343
|
const dela1 = a1 - a1p;
|
|
345
344
|
|
|
346
|
-
if (Math.abs(dela1) <
|
|
345
|
+
if (Math.abs(dela1) < 1e-15) {break;}
|
|
347
346
|
a1p = a1;
|
|
348
347
|
}
|
|
349
348
|
|
|
@@ -370,7 +369,7 @@ class BallisticPropagatorUtils {
|
|
|
370
369
|
s1 = (pcsgam0 - s0 * p0 * q1) / ((1 - 2 * px * p1) * p0);
|
|
371
370
|
const dels1 = s1 - s1p;
|
|
372
371
|
|
|
373
|
-
if (Math.abs(dels1) <
|
|
372
|
+
if (Math.abs(dels1) < 1e-15) {break;}
|
|
374
373
|
s1p = s1;
|
|
375
374
|
}
|
|
376
375
|
|
|
@@ -387,12 +386,6 @@ class BallisticPropagatorUtils {
|
|
|
387
386
|
q = Math.sqrt(pxs);
|
|
388
387
|
}
|
|
389
388
|
|
|
390
|
-
let xinc = Math.asin(q);
|
|
391
|
-
|
|
392
|
-
// Check inclination quadrant - CRITICAL FIX from C#
|
|
393
|
-
// eslint-disable-next-line no-useless-assignment -- xinc appears unused downstream; needs manual review
|
|
394
|
-
if (alph3 * Math.cos(xinc) < 0) {xinc = pi - xinc;}
|
|
395
|
-
|
|
396
389
|
const q2 = q * q;
|
|
397
390
|
const q4 = q2 * q2;
|
|
398
391
|
const betad = 1 + p1 * px - q1 * px * px - q1 * q2;
|
|
@@ -421,7 +414,7 @@ class BallisticPropagatorUtils {
|
|
|
421
414
|
const b1sq = b1 * b1;
|
|
422
415
|
|
|
423
416
|
const a2 = (3 * a1sq - b1) / 2;
|
|
424
|
-
const a3 = 2.5 * a1sq * a1 - 1.
|
|
417
|
+
const a3 = 2.5 * a1sq * a1 - 1.5 * a1 * b1;
|
|
425
418
|
const a4 = 0.375 * (b1sq - 10 * a1sq * b1);
|
|
426
419
|
const a5 = 1.875 * a1 * b1sq;
|
|
427
420
|
const a6 = -0.3125 * b1sq * b1;
|
|
@@ -472,7 +465,7 @@ class BallisticPropagatorUtils {
|
|
|
472
465
|
const x72 = 6 * ecc / p6 + 2 * x74;
|
|
473
466
|
const x71 = 1 / p6 + x73;
|
|
474
467
|
|
|
475
|
-
const gg1si = 1
|
|
468
|
+
const gg1si = 1 / Math.sqrt(gam1);
|
|
476
469
|
const gg1psi = gg1si / Math.sqrt(p);
|
|
477
470
|
|
|
478
471
|
// R1 coefficients
|
|
@@ -569,7 +562,7 @@ class BallisticPropagatorUtils {
|
|
|
569
562
|
|
|
570
563
|
const ucf1 = 2 * sq / (1 + sq2);
|
|
571
564
|
const ucf2 = sq2 / (1 + sq2 * sq2);
|
|
572
|
-
const ucf3 = 2
|
|
565
|
+
const ucf3 = 2 * sq3 / (3 * (1 + sq3 * sq3));
|
|
573
566
|
|
|
574
567
|
const denystt = 1 + sq + sq;
|
|
575
568
|
const denyst = denystt * denystt * d1;
|
|
@@ -602,7 +595,7 @@ class BallisticPropagatorUtils {
|
|
|
602
595
|
|
|
603
596
|
// Avoid singularity at zero inclination
|
|
604
597
|
let u;
|
|
605
|
-
if (q === 0
|
|
598
|
+
if (q === 0) {
|
|
606
599
|
u = 0;
|
|
607
600
|
} else {
|
|
608
601
|
const d5sq = Math.sqrt(s1 * p0 * (1 + p1 * sigma0 - q1 * sigma0 * sigma0));
|
|
@@ -627,9 +620,9 @@ class BallisticPropagatorUtils {
|
|
|
627
620
|
|
|
628
621
|
// Compute xhat at initial time
|
|
629
622
|
let xhat;
|
|
630
|
-
if (gamma < -
|
|
631
|
-
if (Math.abs(ecc) <
|
|
632
|
-
|| Math.abs(sqrf) <
|
|
623
|
+
if (gamma < -1e-14) { // Ellipse
|
|
624
|
+
if (Math.abs(ecc) < 1e-10
|
|
625
|
+
|| Math.abs(sqrf) < 1e-10
|
|
633
626
|
|| Math.abs(rho0 - rho1) < 1e-5) {
|
|
634
627
|
xhat = 0;
|
|
635
628
|
} else {
|
|
@@ -641,9 +634,9 @@ class BallisticPropagatorUtils {
|
|
|
641
634
|
|
|
642
635
|
xhat = acs / smgam;
|
|
643
636
|
}
|
|
644
|
-
} else if (gamma >
|
|
645
|
-
if (Math.abs(ecc) <
|
|
646
|
-
xhat = 0
|
|
637
|
+
} else if (gamma > 1e-14) { // Hyperbola
|
|
638
|
+
if (Math.abs(ecc) < 1e-10 || Math.abs(sqrf) < 1e-10) {
|
|
639
|
+
xhat = 0;
|
|
647
640
|
} else {
|
|
648
641
|
const chat = (rho0 - rho1) / ecc;
|
|
649
642
|
const zz = gamma * chat + 1;
|
|
@@ -660,13 +653,13 @@ class BallisticPropagatorUtils {
|
|
|
660
653
|
let eca = smgam * xhat;
|
|
661
654
|
let tra; let chat; let shat;
|
|
662
655
|
|
|
663
|
-
if (gamma < -
|
|
656
|
+
if (gamma < -1e-14) { // Ellipse
|
|
664
657
|
sneca = Math.sin(eca);
|
|
665
658
|
cneca = Math.cos(eca);
|
|
666
659
|
const s1mes = Math.sqrt(1 - ecc2);
|
|
667
660
|
const temp3 = 2 * Math.atan(ecc * sneca / (1 + s1mes - ecc * cneca));
|
|
668
661
|
tra = eca + temp3;
|
|
669
|
-
} else if (gamma >
|
|
662
|
+
} else if (gamma > 1e-14) { // Hyperbola
|
|
670
663
|
sneca = Math.sinh(eca);
|
|
671
664
|
cneca = Math.cosh(eca);
|
|
672
665
|
|
|
@@ -698,7 +691,7 @@ class BallisticPropagatorUtils {
|
|
|
698
691
|
let w6 = x71 * tra + x72 * snw + x73 * v3 + x74 * v4 + x75 * v5 + x76 * v6 + x77 * v7;
|
|
699
692
|
|
|
700
693
|
let uhat;
|
|
701
|
-
if (Math.abs(gamma) >=
|
|
694
|
+
if (Math.abs(gamma) >= 1e-14) { // Circle, ellipse, hyperbola
|
|
702
695
|
chat = (cneca - 1) / gamma;
|
|
703
696
|
uhat = (sneca - eca) / gams3;
|
|
704
697
|
} else { // Parabola
|
|
@@ -716,12 +709,12 @@ class BallisticPropagatorUtils {
|
|
|
716
709
|
let cb1qs = cstar - b1q * sstar;
|
|
717
710
|
let psi1 = Math.atan(xmm1 * sstar / cb1qs);
|
|
718
711
|
|
|
719
|
-
if (cb1qs * Math.cos(psi1) < 0
|
|
712
|
+
if (cb1qs * Math.cos(psi1) < 0) {psi1 = pi + psi1;}
|
|
720
713
|
|
|
721
714
|
let cb2qs = cstar - b2q * sstar;
|
|
722
715
|
let psi2 = Math.atan(xmm2 * sstar / cb2qs);
|
|
723
716
|
|
|
724
|
-
if (cb2qs * Math.cos(psi2) < 0
|
|
717
|
+
if (cb2qs * Math.cos(psi2) < 0) {psi2 = pi + psi2;}
|
|
725
718
|
|
|
726
719
|
let r3 = cr31 * w2 + cr32 * w3 + cr33 * w4 + cr34 * w5 + cr35 * w6;
|
|
727
720
|
|
|
@@ -749,13 +742,13 @@ class BallisticPropagatorUtils {
|
|
|
749
742
|
for (let ick = 1; ick <= 10; ick++) {
|
|
750
743
|
eca = smgam * xhat;
|
|
751
744
|
|
|
752
|
-
if (gamma < -
|
|
745
|
+
if (gamma < -1e-14) { // Ellipse
|
|
753
746
|
sneca = Math.sin(eca);
|
|
754
747
|
cneca = Math.cos(eca);
|
|
755
748
|
const s1mes = Math.sqrt(1 - ecc2);
|
|
756
749
|
const temp3 = 2 * Math.atan(ecc * sneca / (1 + s1mes - ecc * cneca));
|
|
757
750
|
tra = eca + temp3;
|
|
758
|
-
} else if (gamma >
|
|
751
|
+
} else if (gamma > 1e-14) { // Hyperbola
|
|
759
752
|
sneca = Math.sinh(eca);
|
|
760
753
|
cneca = Math.cosh(eca);
|
|
761
754
|
chat = (cneca - 1) / gamma;
|
|
@@ -788,7 +781,7 @@ class BallisticPropagatorUtils {
|
|
|
788
781
|
w5 = x61 * tra + x62 * snw + x63 * v3 + x64 * v4 + x65 * v5 + x66 * v6;
|
|
789
782
|
w6 = x71 * tra + x72 * snw + x73 * v3 + x74 * v4 + x75 * v5 + x76 * v6 + x77 * v7;
|
|
790
783
|
|
|
791
|
-
if (Math.abs(gamma) >=
|
|
784
|
+
if (Math.abs(gamma) >= 1e-14) {
|
|
792
785
|
chat = (cneca - 1) / gamma;
|
|
793
786
|
uhat = (sneca - eca) / gams3;
|
|
794
787
|
} else { // Parabola
|
|
@@ -847,7 +840,7 @@ class BallisticPropagatorUtils {
|
|
|
847
840
|
|
|
848
841
|
xhat -= delx;
|
|
849
842
|
|
|
850
|
-
if (Math.abs(delx) <
|
|
843
|
+
if (Math.abs(delx) < 1e-14) {break;}
|
|
851
844
|
}
|
|
852
845
|
|
|
853
846
|
// ========== STEP 7: Final coordinate transformation ==========
|
|
@@ -949,7 +942,7 @@ class BallisticPropagator {
|
|
|
949
942
|
// Create PosVelVec using pious-squid Vector3D
|
|
950
943
|
// Handle both lowercase and uppercase property names, but check for undefined specifically
|
|
951
944
|
const getComponent = (vector, lowerProp, upperProp) => {
|
|
952
|
-
return vector[lowerProp]
|
|
945
|
+
return vector[lowerProp] === undefined ? vector[upperProp] : vector[lowerProp];
|
|
953
946
|
};
|
|
954
947
|
|
|
955
948
|
const x0 = new PosVelVec(
|
|
@@ -1036,3 +1029,4 @@ export {BallisticPropagator, BallisticPropagatorUtils, PosVelVec, EarthConstants
|
|
|
1036
1029
|
* console.log('Position after 300s:', result.position);
|
|
1037
1030
|
* console.log('Velocity after 300s:', result.velocity);
|
|
1038
1031
|
*/
|
|
1032
|
+
|
package/src/checkNetwork.cjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const _ = require("lodash");
|
|
3
|
-
const {resolve4} = require("dns").promises;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const checkRecord = (hostName) => resolve4(hostName).
|
|
7
|
-
then((addresss) => !_.isEmpty(addresss)).
|
|
8
|
-
catch(_.stubFalse);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
module.exports.checkRecord = checkRecord;
|
|
12
|
-
module.exports.checkNetwork = (domains) => Promise.all(
|
|
13
|
-
_.map(
|
|
14
|
-
domains,
|
|
15
|
-
(hostName) => checkRecord(hostName).
|
|
16
|
-
then((found) => found
|
|
17
|
-
? hostName
|
|
18
|
-
: null,
|
|
19
|
-
),
|
|
20
|
-
),
|
|
21
|
-
).then((resolved) => _.flow(_.compact, _.first)(resolved) || null);
|
|
1
|
+
"use strict";
|
|
2
|
+
const _ = require("lodash");
|
|
3
|
+
const {resolve4} = require("node:dns").promises;
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const checkRecord = (hostName) => resolve4(hostName).
|
|
7
|
+
then((addresss) => !_.isEmpty(addresss)).
|
|
8
|
+
catch(_.stubFalse);
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
module.exports.checkRecord = checkRecord;
|
|
12
|
+
module.exports.checkNetwork = (domains) => Promise.all(
|
|
13
|
+
_.map(
|
|
14
|
+
domains,
|
|
15
|
+
(hostName) => checkRecord(hostName).
|
|
16
|
+
then((found) => found
|
|
17
|
+
? hostName
|
|
18
|
+
: null,
|
|
19
|
+
),
|
|
20
|
+
),
|
|
21
|
+
).then((resolved) => _.flow(_.compact, _.first)(resolved) || null);
|
package/src/constants.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export const DEG2RAD = Math.PI / 180;
|
|
2
2
|
export const RAD2DEG = 180 / Math.PI;
|
|
3
|
-
export const SEC2RAD = Math.PI / (180
|
|
3
|
+
export const SEC2RAD = Math.PI / (180 * 3600); // seconds to radians conversion
|
|
4
4
|
export const ARCSEC2RAD = 1 / (3600 * 180 / Math.PI); // arcseconds to radians conversion (1 arcsec = 1/3600 deg = 1/3600 * π/180 rad)
|
|
5
5
|
export const MILLIS_PER_DAY = 24 * 60 * 60 * 1000; // Number of milliseconds in a day
|
|
6
6
|
|
|
7
|
-
export const SUN_RADIUS_KM = 695701
|
|
7
|
+
export const SUN_RADIUS_KM = 695701; // Sun radius in kilometers
|
|
8
8
|
export const AU_KM = 149597870.7; // Astronomical Unit in kilometers
|
|
9
9
|
|
|
10
10
|
export const MU = 3.986004418e14; // (m^3)/(s^2) WGS-84 Earth Mu
|
package/src/fixDate.js
CHANGED
|
@@ -59,4 +59,4 @@ export const mySqlDateToJs = (dt) => {
|
|
|
59
59
|
* @param {String} dt The date string to test
|
|
60
60
|
* @return {Boolean} True if is SQL date, false otherwise
|
|
61
61
|
*/
|
|
62
|
-
export const isSqlDate = (dt) =>
|
|
62
|
+
export const isSqlDate = (dt) => /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d{1,6})?$/.exec(dt);
|
package/src/index.js
CHANGED
|
@@ -14,7 +14,7 @@ export * from "./NodeVector3D.js";
|
|
|
14
14
|
// UDL exports are grouped; re-export individually and as namespace if needed
|
|
15
15
|
import * as udl from "./udl.js";
|
|
16
16
|
export * from "./udl.js";
|
|
17
|
-
export
|
|
17
|
+
export * as udl from "./udl.js";
|
|
18
18
|
|
|
19
19
|
// Optional default aggregate similar to old CommonJS shape
|
|
20
20
|
import * as loggerFactoryNS from "./loggerFactory.cjs";
|
package/src/launchNominal.js
CHANGED
|
@@ -18,9 +18,9 @@ const notamToCoordArray = (notam) => {
|
|
|
18
18
|
|
|
19
19
|
// clean up the NOTAM. Remove all spaces and unwanted characters and convert to upper case
|
|
20
20
|
notam = notam
|
|
21
|
-
.
|
|
22
|
-
.
|
|
23
|
-
.
|
|
21
|
+
.replaceAll(/\s/g, "")
|
|
22
|
+
.replaceAll("-", "")
|
|
23
|
+
.replaceAll(".", "")
|
|
24
24
|
.toUpperCase();
|
|
25
25
|
|
|
26
26
|
const coordArray = [];
|
|
@@ -58,19 +58,19 @@ const convertToDecimal = (coord) => {
|
|
|
58
58
|
|
|
59
59
|
// Now, coord contains only the numeric part
|
|
60
60
|
if (coord.length === 4) { // Format DDMM
|
|
61
|
-
degrees = parseInt(coord.substr(0, 2), 10);
|
|
62
|
-
minutes = parseInt(coord.substr(2, 2), 10);
|
|
61
|
+
degrees = Number.parseInt(coord.substr(0, 2), 10);
|
|
62
|
+
minutes = Number.parseInt(coord.substr(2, 2), 10);
|
|
63
63
|
} else if (coord.length === 5) { // Format DDDMM
|
|
64
|
-
degrees = parseInt(coord.substr(0, 3), 10);
|
|
65
|
-
minutes = parseInt(coord.substr(3, 2), 10);
|
|
64
|
+
degrees = Number.parseInt(coord.substr(0, 3), 10);
|
|
65
|
+
minutes = Number.parseInt(coord.substr(3, 2), 10);
|
|
66
66
|
} else if (coord.length === 6) { // Format DDMMSS
|
|
67
|
-
degrees = parseInt(coord.substr(0, 2), 10);
|
|
68
|
-
minutes = parseInt(coord.substr(2, 2), 10);
|
|
69
|
-
seconds = parseInt(coord.substr(4, 2), 10);
|
|
67
|
+
degrees = Number.parseInt(coord.substr(0, 2), 10);
|
|
68
|
+
minutes = Number.parseInt(coord.substr(2, 2), 10);
|
|
69
|
+
seconds = Number.parseInt(coord.substr(4, 2), 10);
|
|
70
70
|
} else if (coord.length === 7) { // Format DDDMMSS
|
|
71
|
-
degrees = parseInt(coord.substr(0, 3), 10);
|
|
72
|
-
minutes = parseInt(coord.substr(3, 2), 10);
|
|
73
|
-
seconds = parseInt(coord.substr(5, 2), 10);
|
|
71
|
+
degrees = Number.parseInt(coord.substr(0, 3), 10);
|
|
72
|
+
minutes = Number.parseInt(coord.substr(3, 2), 10);
|
|
73
|
+
seconds = Number.parseInt(coord.substr(5, 2), 10);
|
|
74
74
|
} else {
|
|
75
75
|
return 0; // Invalid format
|
|
76
76
|
}
|
package/src/loggerFactory.cjs
CHANGED
|
@@ -1,99 +1,122 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const winston = require("winston");
|
|
3
|
-
const {
|
|
4
|
-
createLogger,
|
|
5
|
-
format,
|
|
6
|
-
transports,
|
|
7
|
-
} = winston;
|
|
8
|
-
const cj = (data) => Object.keys(data).length > 0
|
|
9
|
-
? JSON.stringify(data, null, 2)
|
|
10
|
-
: null;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
const winston = require("winston");
|
|
3
|
+
const {
|
|
4
|
+
createLogger,
|
|
5
|
+
format,
|
|
6
|
+
transports,
|
|
7
|
+
} = winston;
|
|
8
|
+
const cj = (data) => Object.keys(data).length > 0
|
|
9
|
+
? JSON.stringify(data, null, 2)
|
|
10
|
+
: null;
|
|
11
|
+
|
|
12
|
+
/** Avoid `[object Object]` when interpolating arbitrary meta (Sonar S6551). */
|
|
13
|
+
const safeLogString = (value) => {
|
|
14
|
+
if (value === null || value === undefined) {
|
|
15
|
+
return "";
|
|
16
|
+
}
|
|
17
|
+
const type = typeof value;
|
|
18
|
+
if (type === "string") {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
if (type === "number" || type === "boolean" || type === "bigint") {
|
|
22
|
+
return String(value);
|
|
23
|
+
}
|
|
24
|
+
if (value instanceof Error) {
|
|
25
|
+
return value.stack || value.message || String(value);
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
return JSON.stringify(value);
|
|
29
|
+
} catch {
|
|
30
|
+
return "[Unserializable]";
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const isTest = process.env.NODE_ENV === "test";
|
|
35
|
+
|
|
36
|
+
const defaultLogger = new transports.Console({
|
|
37
|
+
silent: isTest,
|
|
38
|
+
level: "warn",
|
|
39
|
+
format: format.errors({stack: true}),
|
|
40
|
+
timestamp: true,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const errorLogger = new transports.Console({
|
|
44
|
+
silent: isTest,
|
|
45
|
+
format: format.errors({stack: true}),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Creates a logger
|
|
50
|
+
*
|
|
51
|
+
* @param {String} nameSpace Namespace for the logger
|
|
52
|
+
* @param {Object} additionalData additional data to include with logging
|
|
53
|
+
* @param {string} level Default logging level to set (overwrites environment setting)
|
|
54
|
+
* @return {winston.Logger}
|
|
55
|
+
*/
|
|
56
|
+
module.exports.loggerFactory = ({
|
|
57
|
+
nameSpace = "saber",
|
|
58
|
+
additionalData = {},
|
|
59
|
+
level,
|
|
60
|
+
} = {}) => {
|
|
61
|
+
const logLevel = process.env.LOG_LEVEL || "warn";
|
|
62
|
+
const isConsole = !!(process.env.CONSOLE_LOG);
|
|
63
|
+
|
|
64
|
+
const loggerTransport = isConsole
|
|
65
|
+
? new transports.Console({
|
|
66
|
+
defaultMeta: additionalData,
|
|
67
|
+
level: level || logLevel,
|
|
68
|
+
format: format.combine(
|
|
69
|
+
format.errors({stack: true}),
|
|
70
|
+
format.cli(),
|
|
71
|
+
|
|
72
|
+
format.printf(({
|
|
73
|
+
level,
|
|
74
|
+
message,
|
|
75
|
+
nameSpace,
|
|
76
|
+
stack,
|
|
77
|
+
...rest
|
|
78
|
+
}) =>
|
|
79
|
+
[
|
|
80
|
+
safeLogString(level),
|
|
81
|
+
`[${safeLogString(nameSpace)}]`,
|
|
82
|
+
":",
|
|
83
|
+
safeLogString(message),
|
|
84
|
+
safeLogString(stack),
|
|
85
|
+
cj(rest),
|
|
86
|
+
].filter((value) => value !== "" && value !== null && value !== undefined)
|
|
87
|
+
.join(" "),
|
|
88
|
+
),
|
|
89
|
+
),
|
|
90
|
+
})
|
|
91
|
+
: defaultLogger;
|
|
92
|
+
|
|
93
|
+
const config = {
|
|
94
|
+
levels: {
|
|
95
|
+
// RFC5424
|
|
96
|
+
emerg: 0,
|
|
97
|
+
alert: 1,
|
|
98
|
+
crit: 2,
|
|
99
|
+
error: 3,
|
|
100
|
+
warning: 4,
|
|
101
|
+
notice: 5,
|
|
102
|
+
info: 6,
|
|
103
|
+
debug: 7,
|
|
104
|
+
// npm levels
|
|
105
|
+
warn: 4,
|
|
106
|
+
verbose: 6,
|
|
107
|
+
silly: 8,
|
|
108
|
+
},
|
|
109
|
+
exitOnError: false,
|
|
110
|
+
transports: [loggerTransport],
|
|
111
|
+
// Console logger from above will log errors
|
|
112
|
+
exceptionHandlers: isConsole ? [] : [errorLogger],
|
|
113
|
+
rejectionHandlers: isConsole ? [] : [errorLogger],
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
return createLogger(config)
|
|
117
|
+
.child({
|
|
118
|
+
...additionalData,
|
|
119
|
+
nameSpace: nameSpace,
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
|
package/src/s3.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {S3Client, PutObjectCommand, HeadObjectCommand} from "@aws-sdk/client-s3";
|
|
2
|
-
import {readFileSync} from "fs";
|
|
3
|
-
import {basename} from "path";
|
|
2
|
+
import {readFileSync} from "node:fs";
|
|
3
|
+
import {basename} from "node:path";
|
|
4
4
|
import {config} from "dotenv";
|
|
5
5
|
config();
|
|
6
6
|
|
|
@@ -26,7 +26,7 @@ const s3Client = new S3Client({
|
|
|
26
26
|
*/
|
|
27
27
|
export async function s3Upload(fileName, type = "image/png", buffer = null) {
|
|
28
28
|
try {
|
|
29
|
-
const fileContent = buffer
|
|
29
|
+
const fileContent = buffer ?? readFileSync(fileName);
|
|
30
30
|
return await s3Client.send(new PutObjectCommand({
|
|
31
31
|
Bucket: "saber-probe-images", // S3 Bucket name
|
|
32
32
|
Key: buffer ? fileName : basename(fileName), // File name to save as in S3
|
package/src/udl.js
CHANGED
|
@@ -197,7 +197,7 @@ const enrichGeoLon = (npsOb, enrichedFields) => {
|
|
|
197
197
|
npsOb.GeoLon = geodetic.Longitude;
|
|
198
198
|
npsOb.GeoLat = geodetic.Latitude;
|
|
199
199
|
|
|
200
|
-
if (typeof slantRange === "number" && !isNaN(slantRange)) {
|
|
200
|
+
if (typeof slantRange === "number" && !Number.isNaN(slantRange)) {
|
|
201
201
|
if (!npsOb.Range && !npsOb.GeoRange) {enrichedFields.push("GeoRange");}
|
|
202
202
|
npsOb.GeoRange = slantRange;
|
|
203
203
|
}
|
package/src/utils.js
CHANGED
|
@@ -135,7 +135,7 @@ function epochToDate(days, year) {
|
|
|
135
135
|
* @return {Object} Returns magnitude object
|
|
136
136
|
*/
|
|
137
137
|
const getMagnitude = function(v) {
|
|
138
|
-
return Math.
|
|
138
|
+
return Math.hypot(v.x, v.y, v.z);
|
|
139
139
|
};
|
|
140
140
|
|
|
141
141
|
/**
|
|
@@ -214,7 +214,7 @@ const dist = (p1, p2) => {
|
|
|
214
214
|
const a = p2.x - p1.x;
|
|
215
215
|
const b = p2.y - p1.y;
|
|
216
216
|
const c = p2.z - p1.z;
|
|
217
|
-
return Math.
|
|
217
|
+
return Math.hypot(a, b, c);
|
|
218
218
|
};
|
|
219
219
|
|
|
220
220
|
/** Checks if the variable is a valid dataMode string.
|