bruce-models 4.2.2 → 4.2.4

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.
@@ -3514,6 +3514,7 @@
3514
3514
  Entity.Update = Update;
3515
3515
  /**
3516
3516
  * Util to remove a tag from an entity.
3517
+ * @warning This does not save the entity record.
3517
3518
  * @param params
3518
3519
  */
3519
3520
  function RemoveTag(params) {
@@ -3529,6 +3530,7 @@
3529
3530
  Entity.RemoveTag = RemoveTag;
3530
3531
  /**
3531
3532
  * Util to add a tag to an entity.
3533
+ * @warning This does not save the entity record.
3532
3534
  * @param params
3533
3535
  */
3534
3536
  function AddTag(params) {
@@ -3543,6 +3545,7 @@
3543
3545
  Entity.AddTag = AddTag;
3544
3546
  /**
3545
3547
  * Util to set a value on an entity.
3548
+ * @warning This does not save the entity record.
3546
3549
  * @param params
3547
3550
  */
3548
3551
  function SetValue(params) {
@@ -3568,28 +3571,71 @@
3568
3571
  */
3569
3572
  function GetValue(params) {
3570
3573
  var _a;
3571
- const { entity: data, path } = params;
3572
- // Backwards compatibility.
3573
- if (path.length == 1 && path[0] == "ID") {
3574
+ let { entity: data, path, handleLegacy: checkAgainstLegacy } = params;
3575
+ if (checkAgainstLegacy == null) {
3576
+ checkAgainstLegacy = true;
3577
+ }
3578
+ // Backwards compatibility for incredibly old data.
3579
+ if (checkAgainstLegacy && path.length == 1 && path[0] == "ID") {
3574
3580
  return (_a = data.Bruce) === null || _a === void 0 ? void 0 : _a.ID;
3575
3581
  }
3576
- let curData = data;
3577
- for (let i = 0; i < path.length; i++) {
3578
- const step = path[i];
3579
- if (!curData[step]) {
3580
- return null;
3582
+ const checkForValue = (path) => {
3583
+ let curData = data;
3584
+ for (let i = 0; i < path.length; i++) {
3585
+ const step = path[i];
3586
+ if (!curData[step]) {
3587
+ return null;
3588
+ }
3589
+ if (i >= path.length - 1) {
3590
+ return curData[step];
3591
+ }
3592
+ curData = curData[step];
3581
3593
  }
3582
- if (i >= path.length - 1) {
3583
- return curData[step];
3594
+ return null;
3595
+ };
3596
+ // Check using the path provided.
3597
+ let value = checkForValue(path);
3598
+ // Check for the same path but in both top-level and internal data.
3599
+ // This is done for specific paths we're migrating.
3600
+ if (value == null && checkAgainstLegacy) {
3601
+ // We're migrating 2D vector data into the internal data.
3602
+ // So we'll check against both locations until migration is complete.
3603
+ // First we'll check against properties that could be found inside the internal section.
3604
+ if (path[0] == "location") {
3605
+ value = checkForValue(["Bruce"].concat(path));
3606
+ }
3607
+ else if (path[0] == "transform") {
3608
+ value = checkForValue(["Bruce"].concat(path));
3609
+ }
3610
+ else if (path[0] == "geometry") {
3611
+ value = checkForValue(["Bruce"].concat(path));
3612
+ }
3613
+ else if (path[0] == "boundaries") {
3614
+ value = checkForValue(["Bruce"].concat(path));
3615
+ }
3616
+ // Now we'll check against properties that could still be in the top-level and haven't been migrated yet.
3617
+ if (path[0] == "Bruce" && path.length > 1) {
3618
+ if (path[1] == "location") {
3619
+ value = checkForValue(path.slice(1));
3620
+ }
3621
+ else if (path[1] == "transform") {
3622
+ value = checkForValue(path.slice(1));
3623
+ }
3624
+ else if (path[1] == "geometry") {
3625
+ value = checkForValue(path.slice(1));
3626
+ }
3627
+ else if (path[1] == "boundaries") {
3628
+ value = checkForValue(path.slice(1));
3629
+ }
3584
3630
  }
3585
- curData = curData[step];
3586
3631
  }
3587
- return null;
3632
+ return value;
3588
3633
  }
3589
3634
  Entity.GetValue = GetValue;
3590
3635
  /**
3591
3636
  * Removes a value from an entity.
3592
3637
  * This will mutate the entity record and run "delete" on the object property.
3638
+ * @warning This does not save the entity record.
3593
3639
  * @param params
3594
3640
  */
3595
3641
  function RemoveValue(params) {
@@ -4554,22 +4600,39 @@
4554
4600
  minLongitude: null
4555
4601
  };
4556
4602
  const points = [];
4557
- if (entity.location) {
4558
- points.push(entity.location);
4603
+ const location = exports.Entity.GetValue({
4604
+ entity: entity,
4605
+ path: ["location"]
4606
+ });
4607
+ if (location) {
4608
+ points.push(location);
4559
4609
  }
4560
- if (entity.geometry) {
4561
- if (entity.geometry.Point) {
4562
- points.push(...exports.Geometry.ParsePoints(entity.geometry.Point));
4610
+ const geometry = exports.Entity.GetValue({
4611
+ entity: entity,
4612
+ path: ["geometry"]
4613
+ });
4614
+ const processGeometry = (geometry, depth = 0) => {
4615
+ if (!geometry || depth > 5) {
4616
+ return;
4563
4617
  }
4564
- if (entity.geometry.LineString) {
4565
- points.push(...exports.Geometry.ParsePoints(entity.geometry.LineString));
4618
+ if (geometry.Point) {
4619
+ points.push(...exports.Geometry.ParsePoints(geometry.Point));
4566
4620
  }
4567
- if (entity.geometry.Polygon) {
4568
- for (const ring of entity.geometry.Polygon) {
4621
+ if (geometry.LineString) {
4622
+ points.push(...exports.Geometry.ParsePoints(geometry.LineString));
4623
+ }
4624
+ if (geometry.Polygon) {
4625
+ for (const ring of geometry.Polygon) {
4569
4626
  points.push(...exports.Geometry.ParsePoints(ring.LinearRing));
4570
4627
  }
4571
4628
  }
4572
- }
4629
+ if (geometry.MultiGeometry) {
4630
+ for (const multiGeometry of geometry.MultiGeometry) {
4631
+ processGeometry(multiGeometry, depth + 1);
4632
+ }
4633
+ }
4634
+ };
4635
+ processGeometry(geometry);
4573
4636
  for (const point of points) {
4574
4637
  if (bounds.maxLatitude == null || point.latitude > bounds.maxLatitude) {
4575
4638
  bounds.maxLatitude = point.latitude;
@@ -12913,7 +12976,7 @@
12913
12976
  })(exports.DataSource || (exports.DataSource = {}));
12914
12977
 
12915
12978
  // This is updated with the package.json version on build.
12916
- const VERSION = "4.2.2";
12979
+ const VERSION = "4.2.4";
12917
12980
 
12918
12981
  exports.VERSION = VERSION;
12919
12982
  exports.AbstractApi = AbstractApi;