onroute-policy-engine 2.5.0 → 2.5.2

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.
@@ -1,4 +1,4 @@
1
- import { PolicyCheckResult, AxleConfiguration } from 'onroute-policy-engine/types';
1
+ import { PolicyCheckResult, AxleConfiguration, AxleGroupPolicyCheckResult } from 'onroute-policy-engine/types';
2
2
  import { Policy } from 'onroute-policy-engine';
3
3
  /**
4
4
  * Type definition for policy check functions.
@@ -24,9 +24,9 @@ type PolicyCheck = (policy: Policy, vehicleConfiguration: Array<string>, axleCon
24
24
  * @param _policy - The policy instance (unused in this check, but required by PolicyCheck type)
25
25
  * @param _vehicleConfiguration - Vehicle configuration (unused in this check, but required by PolicyCheck type)
26
26
  * @param axleConfiguration - Array of axle configurations containing axle count information
27
- * @returns Array of AxleUnitPolicyCheckResult objects, one for each axle unit tested
27
+ * @returns Array of AxleGroupPolicyCheckResult objects, one for each axle unit tested
28
28
  */
29
- export declare function CheckNumberOfAxles(_policy: Policy, _vehicleConfiguration: Array<string>, axleConfiguration: Array<AxleConfiguration>): Array<PolicyCheckResult>;
29
+ export declare function CheckNumberOfAxles(_policy: Policy, _vehicleConfiguration: Array<string>, axleConfiguration: Array<AxleConfiguration>): Array<AxleGroupPolicyCheckResult>;
30
30
  /**
31
31
  * Performs bridge formula calculations on axle groups and returns policy check results.
32
32
  *
@@ -19,7 +19,7 @@ const enum_1 = require("../enum");
19
19
  * @param _policy - The policy instance (unused in this check, but required by PolicyCheck type)
20
20
  * @param _vehicleConfiguration - Vehicle configuration (unused in this check, but required by PolicyCheck type)
21
21
  * @param axleConfiguration - Array of axle configurations containing axle count information
22
- * @returns Array of AxleUnitPolicyCheckResult objects, one for each axle unit tested
22
+ * @returns Array of AxleGroupPolicyCheckResult objects, one for each axle unit tested
23
23
  */
24
24
  function CheckNumberOfAxles(_policy, _vehicleConfiguration, axleConfiguration) {
25
25
  const policyCheckResults = new Array();
@@ -42,7 +42,8 @@ function CheckNumberOfAxles(_policy, _vehicleConfiguration, axleConfiguration) {
42
42
  id: policyId,
43
43
  message,
44
44
  result,
45
- axleUnit,
45
+ startAxleUnit: axleUnit,
46
+ endAxleUnit: axleUnit,
46
47
  });
47
48
  });
48
49
  return policyCheckResults;
@@ -696,10 +696,21 @@ class Policy {
696
696
  */
697
697
  runAxleCalculation(vehicleConfiguration, axleConfiguration, licensedGVW) {
698
698
  const axleCalcResults = { results: [], totalOverload: 0 };
699
+ // This is a little helper closure that just converts any PolicyCheckResult into an AxleGroupPolicyCheckResult,
700
+ // basically giving us startAxleUnit and endAxleUnit, which can help with frontend form highlighting.
701
+ const toAxleGroupPolicyCheckResult = (result) => {
702
+ if ('startAxleUnit' in result && 'endAxleUnit' in result) {
703
+ return result;
704
+ }
705
+ if ('axleUnit' in result && typeof result.axleUnit === 'number') {
706
+ return Object.assign(Object.assign({}, result), { startAxleUnit: result.axleUnit, endAxleUnit: result.axleUnit });
707
+ }
708
+ return Object.assign(Object.assign({}, result), { startAxleUnit: 1, endAxleUnit: axleConfiguration.length });
709
+ };
699
710
  const gvcw = axleConfiguration.reduce((w, curr) => w + curr.axleUnitWeight, 0);
700
711
  axleCalcResults.totalOverload = Math.max(axleCalcResults.totalOverload, gvcw - licensedGVW);
701
712
  const axleCountResults = (0, policy_check_helper_1.CheckNumberOfAxles)(this, vehicleConfiguration, axleConfiguration);
702
- axleCalcResults.results.push(...axleCountResults);
713
+ axleCalcResults.results.push(...axleCountResults.map(toAxleGroupPolicyCheckResult));
703
714
  if (axleCountResults.some((r) => r.result === enum_1.PolicyCheckResultType.Fail)) {
704
715
  return axleCalcResults;
705
716
  }
@@ -707,7 +718,7 @@ class Policy {
707
718
  if (policyCheckId === enum_1.PolicyCheckId.NumberOfAxles) {
708
719
  continue;
709
720
  }
710
- axleCalcResults.results.push(...policyCheck(this, vehicleConfiguration, axleConfiguration));
721
+ axleCalcResults.results.push(...policyCheck(this, vehicleConfiguration, axleConfiguration).map(toAxleGroupPolicyCheckResult));
711
722
  }
712
723
  return axleCalcResults;
713
724
  }
@@ -927,6 +938,10 @@ class Policy {
927
938
  if (!powerUnit) {
928
939
  throw new Error(`Invalid power unit: '${powerUnitSubtype}'`);
929
940
  }
941
+ if (trailerSubtype === enum_1.AccessoryVehicleType.Jeep ||
942
+ trailerSubtype === enum_1.AccessoryVehicleType.Booster) {
943
+ return false;
944
+ }
930
945
  const trailer = powerUnit.trailers.find(trailer => trailer.type === trailerSubtype);
931
946
  if (!trailer) {
932
947
  throw new Error(`Invalid trailer: '${trailerSubtype}'`);
@@ -9,8 +9,8 @@ import { PolicyCheckResultType } from 'onroute-policy-engine/enum';
9
9
  * Complete results from axle calculations including all policy checks and total overload
10
10
  */
11
11
  export type AxleCalcResults = {
12
- /** Array of individual policy check results */
13
- results: Array<PolicyCheckResult>;
12
+ /** Array of individual axle group policy check results */
13
+ results: Array<AxleGroupPolicyCheckResult>;
14
14
  /** Total weight overload across all axles in kilograms */
15
15
  totalOverload: number;
16
16
  };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "v2.5.0";
1
+ export declare const version = "v2.5.2";
package/dist/version.js CHANGED
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
4
  // Generated by genversion.
5
- exports.version = 'v2.5.0';
5
+ exports.version = 'v2.5.2';
package/package.json CHANGED
@@ -91,5 +91,5 @@
91
91
  ],
92
92
  "testEnvironment": "node"
93
93
  },
94
- "version": "v2.5.0"
94
+ "version": "v2.5.2"
95
95
  }