@saber-usa/node-common 1.7.10 → 1.7.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/astro.js +13 -3
- package/src/checkNetwork.cjs +20 -20
- package/src/index.js +1 -1
- package/src/loggerFactory.cjs +98 -98
- package/src/udl.js +121 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saber-usa/node-common",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.11",
|
|
4
4
|
"description": "Common node functions for Saber",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"winston": "3.3.3"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@babel/core": "7.
|
|
33
|
-
"@babel/eslint-parser": "7.
|
|
34
|
-
"@babel/plugin-transform-modules-commonjs": "7.
|
|
32
|
+
"@babel/core": "7.23.0",
|
|
33
|
+
"@babel/eslint-parser": "^7.23.0",
|
|
34
|
+
"@babel/plugin-transform-modules-commonjs": "7.23.0",
|
|
35
35
|
"@jest/globals": "27.4.4",
|
|
36
36
|
"eslint-config-google": "0.14.0",
|
|
37
37
|
"eslint-plugin-jest": "25.3.0",
|
package/src/astro.js
CHANGED
|
@@ -1057,6 +1057,16 @@ const RaDecToGeodetic = (
|
|
|
1057
1057
|
* @return {Number} range The range from the sensor to the satellite
|
|
1058
1058
|
*/
|
|
1059
1059
|
const estimateSlantRange = (obTime, ra, dec, senLat, senLon, senAltKm) => {
|
|
1060
|
+
// check for nulls
|
|
1061
|
+
if (!isDefined(obTime)
|
|
1062
|
+
|| !isDefined(ra)
|
|
1063
|
+
|| !isDefined(dec)
|
|
1064
|
+
|| !isDefined(senLat)
|
|
1065
|
+
|| !isDefined(senLon)
|
|
1066
|
+
|| !isDefined(senAltKm)) {
|
|
1067
|
+
return null;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1060
1070
|
// A very rough initial guess, akso initialization
|
|
1061
1071
|
let range = 35786;
|
|
1062
1072
|
|
|
@@ -1703,7 +1713,7 @@ const getLeoRpoData = (line1, line2, sats, startTime, endTime) => {
|
|
|
1703
1713
|
Line2: line2,
|
|
1704
1714
|
};
|
|
1705
1715
|
const pEphem = prop(pElset, start, end, 10000);
|
|
1706
|
-
if(pEphem.length === 0) return results; // Primary may have re-entered the atmosphere
|
|
1716
|
+
if (pEphem.length === 0) return results; // Primary may have re-entered the atmosphere
|
|
1707
1717
|
|
|
1708
1718
|
sats.forEach( (s) => {
|
|
1709
1719
|
const sEphem = prop(s, start, end, 10000);
|
|
@@ -1788,8 +1798,8 @@ const getGeoRpoData = (line1, line2, sats, startTime, endTime, lonTime) => {
|
|
|
1788
1798
|
Line1: line1,
|
|
1789
1799
|
Line2: line2,
|
|
1790
1800
|
}, start, end, 60000);
|
|
1791
|
-
if(pEphem.length === 0) return results; // Primary may have re-entered the atmosphere
|
|
1792
|
-
|
|
1801
|
+
if (pEphem.length === 0) return results; // Primary may have re-entered the atmosphere
|
|
1802
|
+
|
|
1793
1803
|
const lonEvalTime = lonTime ? new Date(lonTime) : new Date(end);
|
|
1794
1804
|
|
|
1795
1805
|
const pLonAndDrift = getLonAndDrift(line1, line2, lonEvalTime);
|
package/src/checkNetwork.cjs
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
const _ = require("lodash");
|
|
2
|
-
const {resolve4} = require("dns").promises;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const checkRecord = (hostName) => resolve4(hostName).
|
|
6
|
-
then((addresss) => !_.isEmpty(addresss)).
|
|
7
|
-
catch(_.stubFalse);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
module.exports.checkRecord = checkRecord;
|
|
11
|
-
module.exports.checkNetwork = (domains) => Promise.all(
|
|
12
|
-
_.map(
|
|
13
|
-
domains,
|
|
14
|
-
(hostName) => checkRecord(hostName).
|
|
15
|
-
then((found) => found
|
|
16
|
-
? hostName
|
|
17
|
-
: null,
|
|
18
|
-
),
|
|
19
|
-
),
|
|
20
|
-
).then((resolved) => _.flow(_.compact, _.first)(resolved) || null);
|
|
1
|
+
const _ = require("lodash");
|
|
2
|
+
const {resolve4} = require("dns").promises;
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const checkRecord = (hostName) => resolve4(hostName).
|
|
6
|
+
then((addresss) => !_.isEmpty(addresss)).
|
|
7
|
+
catch(_.stubFalse);
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
module.exports.checkRecord = checkRecord;
|
|
11
|
+
module.exports.checkNetwork = (domains) => Promise.all(
|
|
12
|
+
_.map(
|
|
13
|
+
domains,
|
|
14
|
+
(hostName) => checkRecord(hostName).
|
|
15
|
+
then((found) => found
|
|
16
|
+
? hostName
|
|
17
|
+
: null,
|
|
18
|
+
),
|
|
19
|
+
),
|
|
20
|
+
).then((resolved) => _.flow(_.compact, _.first)(resolved) || null);
|
package/src/index.js
CHANGED
package/src/loggerFactory.cjs
CHANGED
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
const winston = require("winston");
|
|
2
|
-
const {
|
|
3
|
-
createLogger,
|
|
4
|
-
format,
|
|
5
|
-
transports,
|
|
6
|
-
} = winston;
|
|
7
|
-
const cj = (data) => Object.keys(data).length > 0
|
|
8
|
-
? JSON.stringify(data, null, 2)
|
|
9
|
-
: null;
|
|
10
|
-
|
|
11
|
-
const isTest = process.env.NODE_ENV === "test";
|
|
12
|
-
|
|
13
|
-
const defaultLogger = new transports.Console({
|
|
14
|
-
silent: isTest,
|
|
15
|
-
level: "warn",
|
|
16
|
-
format: format.errors({stack: true}),
|
|
17
|
-
timestamp: true,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const errorLogger = new transports.Console({
|
|
21
|
-
silent: isTest,
|
|
22
|
-
format: format.errors({stack: true}),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Creates a logger
|
|
27
|
-
*
|
|
28
|
-
* @param {String} nameSpace Namespace for the logger
|
|
29
|
-
* @param {Object} additionalData additional data to include with logging
|
|
30
|
-
* @param {string} level Default logging level to set (overwrites environment setting)
|
|
31
|
-
* @return {winston.Logger}
|
|
32
|
-
*/
|
|
33
|
-
module.exports.loggerFactory = ({
|
|
34
|
-
nameSpace = "saber",
|
|
35
|
-
additionalData = {},
|
|
36
|
-
level,
|
|
37
|
-
} = {}) => {
|
|
38
|
-
const logLevel = process.env.LOG_LEVEL || "warn";
|
|
39
|
-
const isConsole = !!(process.env.CONSOLE_LOG);
|
|
40
|
-
|
|
41
|
-
const loggerTransport = isConsole
|
|
42
|
-
? new transports.Console({
|
|
43
|
-
defaultMeta: additionalData,
|
|
44
|
-
level: level || logLevel,
|
|
45
|
-
format: format.combine(
|
|
46
|
-
format.errors({stack: true}),
|
|
47
|
-
format.cli(),
|
|
48
|
-
// eslint-disable-next-line max-len
|
|
49
|
-
format.printf(({
|
|
50
|
-
level,
|
|
51
|
-
message,
|
|
52
|
-
nameSpace,
|
|
53
|
-
stack,
|
|
54
|
-
...rest
|
|
55
|
-
}) =>
|
|
56
|
-
[
|
|
57
|
-
level,
|
|
58
|
-
`[${nameSpace}]`,
|
|
59
|
-
":",
|
|
60
|
-
message,
|
|
61
|
-
stack,
|
|
62
|
-
cj(rest),
|
|
63
|
-
].filter((value) => !!value)
|
|
64
|
-
.join(" "),
|
|
65
|
-
),
|
|
66
|
-
),
|
|
67
|
-
})
|
|
68
|
-
: defaultLogger;
|
|
69
|
-
|
|
70
|
-
const config = {
|
|
71
|
-
levels: {
|
|
72
|
-
// RFC5424
|
|
73
|
-
emerg: 0,
|
|
74
|
-
alert: 1,
|
|
75
|
-
crit: 2,
|
|
76
|
-
error: 3,
|
|
77
|
-
warning: 4,
|
|
78
|
-
notice: 5,
|
|
79
|
-
info: 6,
|
|
80
|
-
debug: 7,
|
|
81
|
-
// npm levels
|
|
82
|
-
warn: 4,
|
|
83
|
-
verbose: 6,
|
|
84
|
-
silly: 8,
|
|
85
|
-
},
|
|
86
|
-
exitOnError: false,
|
|
87
|
-
transports: [loggerTransport],
|
|
88
|
-
// Console logger from above will log errors
|
|
89
|
-
exceptionHandlers: !isConsole ? [errorLogger] : [],
|
|
90
|
-
rejectionHandlers: !isConsole ? [errorLogger] : [],
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
return createLogger(config)
|
|
94
|
-
.child({
|
|
95
|
-
...additionalData,
|
|
96
|
-
nameSpace: nameSpace,
|
|
97
|
-
});
|
|
98
|
-
}
|
|
1
|
+
const winston = require("winston");
|
|
2
|
+
const {
|
|
3
|
+
createLogger,
|
|
4
|
+
format,
|
|
5
|
+
transports,
|
|
6
|
+
} = winston;
|
|
7
|
+
const cj = (data) => Object.keys(data).length > 0
|
|
8
|
+
? JSON.stringify(data, null, 2)
|
|
9
|
+
: null;
|
|
10
|
+
|
|
11
|
+
const isTest = process.env.NODE_ENV === "test";
|
|
12
|
+
|
|
13
|
+
const defaultLogger = new transports.Console({
|
|
14
|
+
silent: isTest,
|
|
15
|
+
level: "warn",
|
|
16
|
+
format: format.errors({stack: true}),
|
|
17
|
+
timestamp: true,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const errorLogger = new transports.Console({
|
|
21
|
+
silent: isTest,
|
|
22
|
+
format: format.errors({stack: true}),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Creates a logger
|
|
27
|
+
*
|
|
28
|
+
* @param {String} nameSpace Namespace for the logger
|
|
29
|
+
* @param {Object} additionalData additional data to include with logging
|
|
30
|
+
* @param {string} level Default logging level to set (overwrites environment setting)
|
|
31
|
+
* @return {winston.Logger}
|
|
32
|
+
*/
|
|
33
|
+
module.exports.loggerFactory = ({
|
|
34
|
+
nameSpace = "saber",
|
|
35
|
+
additionalData = {},
|
|
36
|
+
level,
|
|
37
|
+
} = {}) => {
|
|
38
|
+
const logLevel = process.env.LOG_LEVEL || "warn";
|
|
39
|
+
const isConsole = !!(process.env.CONSOLE_LOG);
|
|
40
|
+
|
|
41
|
+
const loggerTransport = isConsole
|
|
42
|
+
? new transports.Console({
|
|
43
|
+
defaultMeta: additionalData,
|
|
44
|
+
level: level || logLevel,
|
|
45
|
+
format: format.combine(
|
|
46
|
+
format.errors({stack: true}),
|
|
47
|
+
format.cli(),
|
|
48
|
+
// eslint-disable-next-line max-len
|
|
49
|
+
format.printf(({
|
|
50
|
+
level,
|
|
51
|
+
message,
|
|
52
|
+
nameSpace,
|
|
53
|
+
stack,
|
|
54
|
+
...rest
|
|
55
|
+
}) =>
|
|
56
|
+
[
|
|
57
|
+
level,
|
|
58
|
+
`[${nameSpace}]`,
|
|
59
|
+
":",
|
|
60
|
+
message,
|
|
61
|
+
stack,
|
|
62
|
+
cj(rest),
|
|
63
|
+
].filter((value) => !!value)
|
|
64
|
+
.join(" "),
|
|
65
|
+
),
|
|
66
|
+
),
|
|
67
|
+
})
|
|
68
|
+
: defaultLogger;
|
|
69
|
+
|
|
70
|
+
const config = {
|
|
71
|
+
levels: {
|
|
72
|
+
// RFC5424
|
|
73
|
+
emerg: 0,
|
|
74
|
+
alert: 1,
|
|
75
|
+
crit: 2,
|
|
76
|
+
error: 3,
|
|
77
|
+
warning: 4,
|
|
78
|
+
notice: 5,
|
|
79
|
+
info: 6,
|
|
80
|
+
debug: 7,
|
|
81
|
+
// npm levels
|
|
82
|
+
warn: 4,
|
|
83
|
+
verbose: 6,
|
|
84
|
+
silly: 8,
|
|
85
|
+
},
|
|
86
|
+
exitOnError: false,
|
|
87
|
+
transports: [loggerTransport],
|
|
88
|
+
// Console logger from above will log errors
|
|
89
|
+
exceptionHandlers: !isConsole ? [errorLogger] : [],
|
|
90
|
+
rejectionHandlers: !isConsole ? [errorLogger] : [],
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return createLogger(config)
|
|
94
|
+
.child({
|
|
95
|
+
...additionalData,
|
|
96
|
+
nameSpace: nameSpace,
|
|
97
|
+
});
|
|
98
|
+
}
|
package/src/udl.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import {fixDate} from "./fixDate.js";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
calcRegime,
|
|
4
|
+
getElsetUdlFromTle,
|
|
5
|
+
getLonAndDrift,
|
|
6
|
+
getRaanPrecession,
|
|
7
|
+
raDecToAzEl,
|
|
8
|
+
azElToRaDec,
|
|
9
|
+
raDecToGeodetic,
|
|
10
|
+
estimateSlantRange,
|
|
11
|
+
} from "./astro.js";
|
|
3
12
|
import {lowerCaseObjectKeys} from "./transform.js";
|
|
4
13
|
import {isDefined} from "./utils.js";
|
|
5
14
|
import _ from "lodash";
|
|
@@ -113,4 +122,114 @@ export function formatUdlData(topic, udlData) {
|
|
|
113
122
|
}
|
|
114
123
|
}
|
|
115
124
|
|
|
116
|
-
|
|
125
|
+
/**
|
|
126
|
+
* Enriches the Azimuth and Elevation fields of the given object, if needed.
|
|
127
|
+
*
|
|
128
|
+
* @param {object} npsOb - The object to be enriched.
|
|
129
|
+
* @param {array} enrichedFields - The array of already enriched fields.
|
|
130
|
+
* @return {array} The updated array of enriched fields.
|
|
131
|
+
*/
|
|
132
|
+
const enrichAzimuthAndElevation = (npsOb, enrichedFields) => {
|
|
133
|
+
const azel = raDecToAzEl(npsOb.ObTime, npsOb.Ra, npsOb.Dec, npsOb.SenLat, npsOb.SenLon);
|
|
134
|
+
const {Az, El} = azel;
|
|
135
|
+
if (Az && !npsOb.Azimuth) {
|
|
136
|
+
npsOb.Azimuth = Az;
|
|
137
|
+
enrichedFields.push("Azimuth");
|
|
138
|
+
}
|
|
139
|
+
if (El && !npsOb.Elevation) {
|
|
140
|
+
npsOb.Elevation = El;
|
|
141
|
+
enrichedFields.push("Elevation");
|
|
142
|
+
}
|
|
143
|
+
return enrichedFields;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Enriches the Ra and Dec fields of the given object, if needed.
|
|
148
|
+
*
|
|
149
|
+
* @param {object} npsOb - The object to be enriched.
|
|
150
|
+
* @param {array} enrichedFields - The array of already enriched fields.
|
|
151
|
+
* @return {array} The updated array of enriched fields.
|
|
152
|
+
*/
|
|
153
|
+
const enrichRaAndDec = (npsOb, enrichedFields) => {
|
|
154
|
+
const radec = azElToRaDec(
|
|
155
|
+
npsOb.ObTime,
|
|
156
|
+
npsOb.Azimuth,
|
|
157
|
+
npsOb.Elevation,
|
|
158
|
+
npsOb.SenLat,
|
|
159
|
+
npsOb.SenLon,
|
|
160
|
+
);
|
|
161
|
+
const {ra, dec} = radec;
|
|
162
|
+
if (ra && !npsOb.Ra) {
|
|
163
|
+
npsOb.Ra = ra;
|
|
164
|
+
enrichedFields.push("Ra");
|
|
165
|
+
}
|
|
166
|
+
if (dec && !npsOb.Dec) {
|
|
167
|
+
npsOb.Dec = dec;
|
|
168
|
+
enrichedFields.push("Dec");
|
|
169
|
+
}
|
|
170
|
+
return enrichedFields;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Enriches the GeoLon field of the given object, if needed.
|
|
175
|
+
*
|
|
176
|
+
* @param {object} npsOb - The object to be enriched.
|
|
177
|
+
* @param {array} enrichedFields - The array of already enriched fields.
|
|
178
|
+
* @return {array} The updated array of enriched fields.
|
|
179
|
+
*/
|
|
180
|
+
const enrichGeoLon = (npsOb, enrichedFields) => {
|
|
181
|
+
// In the absence of range, we estimate the slant range from the sensor to the sat
|
|
182
|
+
const slantRange = npsOb.Range ?? npsOb.GeoRange ?? estimateSlantRange(
|
|
183
|
+
npsOb.ObTime,
|
|
184
|
+
npsOb.Ra, npsOb.Dec,
|
|
185
|
+
npsOb.SenLat, npsOb.SenLon, npsOb.SenAlt,
|
|
186
|
+
);
|
|
187
|
+
const geodetic= raDecToGeodetic(
|
|
188
|
+
npsOb.ObTime,
|
|
189
|
+
npsOb.Ra,
|
|
190
|
+
npsOb.Dec,
|
|
191
|
+
npsOb.SenLat,
|
|
192
|
+
npsOb.SenLon,
|
|
193
|
+
npsOb.SenAlt,
|
|
194
|
+
slantRange,
|
|
195
|
+
);
|
|
196
|
+
npsOb.GeoLon = geodetic.Longitude;
|
|
197
|
+
npsOb.GeoLat = geodetic.Latitude;
|
|
198
|
+
|
|
199
|
+
if (typeof slantRange === "number" && !isNaN(slantRange)) {
|
|
200
|
+
if (!npsOb.Range && !npsOb.GeoRange) enrichedFields.push("GeoRange");
|
|
201
|
+
npsOb.GeoRange = slantRange;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (npsOb.GeoLon) enrichedFields.push("GeoLon");
|
|
205
|
+
if (npsOb.GeoLat) enrichedFields.push("GeoLat");
|
|
206
|
+
return enrichedFields;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Enriches the given object by adding missing fields.
|
|
211
|
+
* This is the main function that uses helper functions to enrich different fields of the object.
|
|
212
|
+
*
|
|
213
|
+
* @param {object} npsOb - The object to be enriched.
|
|
214
|
+
* @return {object} The enriched object.
|
|
215
|
+
*/
|
|
216
|
+
const enrichUdlFields = (npsOb) => {
|
|
217
|
+
let enrichedFields = [];
|
|
218
|
+
|
|
219
|
+
if (!npsOb.Azimuth || !npsOb.Elevation) {
|
|
220
|
+
enrichedFields = enrichAzimuthAndElevation(npsOb, enrichedFields);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (!npsOb.Ra || !npsOb.Dec) {
|
|
224
|
+
enrichedFields = enrichRaAndDec(npsOb, enrichedFields);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (!npsOb.GeoLon) {
|
|
228
|
+
enrichedFields = enrichGeoLon(npsOb, enrichedFields);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
npsOb.EnrichedFields = enrichedFields.join(",");
|
|
232
|
+
return npsOb;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
export {udlToNpsElset, udlToNpsGroundSite, enrichUdlFields};
|