@saber-usa/node-common 1.7.29 → 1.7.32

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saber-usa/node-common",
3
- "version": "1.7.29",
3
+ "version": "1.7.32",
4
4
  "description": "Common node functions for Saber",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -23,7 +23,7 @@
23
23
  "author": "Saber USA",
24
24
  "license": "ISC",
25
25
  "dependencies": {
26
- "@aws-sdk/client-s3": "^3.1085.0",
26
+ "@aws-sdk/client-s3": "^3.1086.0",
27
27
  "date-fns": "^4.4.0",
28
28
  "lodash": "4.18.1",
29
29
  "mathjs": "^15.2.0",
package/src/astro.js CHANGED
@@ -145,24 +145,24 @@ const validateTle = (line1, line2) => {
145
145
  * @return {boolean} true if the propagation output is valid, false otherwise
146
146
  */
147
147
  const isPropagateValid = (out) => {
148
- if (out === null || out === undefined) {
148
+ if (!isDefined(out)) {
149
149
  return false;
150
150
  }
151
151
 
152
152
  if (out.position) {
153
153
  const pos = out.position;
154
- if (pos.x === null || pos.x === undefined || Number.isNaN(pos.x)
155
- || pos.y === null || pos.y === undefined || Number.isNaN(pos.y)
156
- || pos.z === null || pos.z === undefined || Number.isNaN(pos.z)) {
154
+ if (!isDefined(pos.x) || Number.isNaN(pos.x)
155
+ || !isDefined(pos.y) || Number.isNaN(pos.y)
156
+ || !isDefined(pos.z) || Number.isNaN(pos.z)) {
157
157
  return false;
158
158
  }
159
159
  }
160
160
 
161
161
  if (out.velocity) {
162
162
  const vel = out.velocity;
163
- if (vel.x === null || vel.x === undefined || Number.isNaN(vel.x)
164
- || vel.y === null || vel.y === undefined || Number.isNaN(vel.y)
165
- || vel.z === null || vel.z === undefined || Number.isNaN(vel.z)) {
163
+ if (!isDefined(vel.x) || Number.isNaN(vel.x)
164
+ || !isDefined(vel.y) || Number.isNaN(vel.y)
165
+ || !isDefined(vel.z) || Number.isNaN(vel.z)) {
166
166
  return false;
167
167
  }
168
168
  }
@@ -1391,7 +1391,7 @@ const GetElsetUdlFromTle = (
1391
1391
  // and we may be unsure of entering true or false for any reason.
1392
1392
  if (isBoolean(isUct)) {
1393
1393
  elset.uct = isUct;
1394
- } else if (isUct === null || isUct === undefined) {
1394
+ } else if (!isDefined(isUct)) {
1395
1395
  // Do nothing, do not populate nor put null.
1396
1396
  } else {
1397
1397
  throw new Error("Input uct flag is not of type boolean.");
package/src/transform.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import _ from "lodash";
2
+ import {isDefined} from "./utils.js";
2
3
 
3
4
  const transformObjectKeys = (transform, object, deep = true) => _.cond([
4
5
  [
@@ -32,4 +33,15 @@ const pascalCaseObjectKeys = (transformItem, deep) => transformObjectKeys(
32
33
  deep,
33
34
  );
34
35
 
35
- export {transformObjectKeys, lowerCaseObjectKeys, pascalCaseObjectKeys, pascalCase};
36
+ // Write a true SQL NULL instead of the *string* "null" (JSON.stringify(null) === "null")
37
+ // when a value is absent, so nullable JSON/TEXT columns stay unambiguously empty.
38
+ const jsonOrNull = (value) => (isDefined(value) ? JSON.stringify(value) : null);
39
+
40
+ // As jsonOrNull, but additionally rejects non-array values (e.g. a provider returning the
41
+ // string "OTHER" in place of a real array), coercing them to null rather than serializing them.
42
+ const jsonArrayOrNull = (value) => (Array.isArray(value) ? JSON.stringify(value) : null);
43
+
44
+ export {
45
+ transformObjectKeys, lowerCaseObjectKeys, pascalCaseObjectKeys, pascalCase,
46
+ jsonOrNull, jsonArrayOrNull,
47
+ };
package/src/udl.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  raDecToGeodetic,
11
11
  estimateSlantRange,
12
12
  } from "./astro.js";
13
- import {lowerCaseObjectKeys} from "./transform.js";
13
+ import {lowerCaseObjectKeys, jsonArrayOrNull} from "./transform.js";
14
14
  import {isDefined} from "./utils.js";
15
15
  import _ from "lodash";
16
16
 
@@ -336,10 +336,6 @@ const udlToNpsState = (udlRow) => {
336
336
  const Yvel = _.get(udlRow, "yvel", null);
337
337
  const Zvel = _.get(udlRow, "zvel", null);
338
338
  const rawCov = _.get(udlRow, "cov", null );
339
- // Guard against providers returning a non-array `cov` (e.g. the string "null" or "OTHER"
340
- // in place of a real covariance matrix). Only ever serialize a real array or null, so the
341
- // Covariance column always holds valid JSON that downstream JSON-array parsers can read.
342
- const cov = Array.isArray(rawCov) ? rawCov : null;
343
339
  const covRefFrame = _.get(udlRow, "covReferenceFrame", null );
344
340
  let keplerians = {a: null, e: null, i: null, raan: null, w: null, f: null};
345
341
 
@@ -372,7 +368,10 @@ const udlToNpsState = (udlRow) => {
372
368
  Xvel: Xvel,
373
369
  Yvel: Yvel,
374
370
  Zvel: Zvel,
375
- Covariance: JSON.stringify(cov),
371
+ // Guard against providers returning a non-array `cov` (e.g. the string "null" or
372
+ // "OTHER" in place of a real covariance matrix), and write a true SQL NULL rather
373
+ // than the string "null" when there is no covariance at all.
374
+ Covariance: jsonArrayOrNull(rawCov),
376
375
  CovarianceRefFrame: covRefFrame,
377
376
  SemiMajorAxis: keplerians.a,
378
377
  Eccentricity: keplerians.e,