onroute-policy-engine 2.1.0 → 2.2.0

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.
Files changed (80) hide show
  1. package/.github/workflows/pipeline.yml +25 -6
  2. package/dist/enum/custom-operator.d.ts +6 -0
  3. package/dist/enum/custom-operator.js +10 -0
  4. package/dist/enum/facts.d.ts +8 -4
  5. package/dist/enum/facts.js +8 -4
  6. package/dist/enum/index.d.ts +2 -0
  7. package/dist/enum/index.js +6 -1
  8. package/dist/enum/permit-app-info.d.ts +8 -5
  9. package/dist/enum/permit-app-info.js +8 -5
  10. package/dist/enum/policy-check.d.ts +11 -0
  11. package/dist/enum/policy-check.js +16 -0
  12. package/dist/enum/validation-result-code.d.ts +1 -0
  13. package/dist/enum/validation-result-code.js +1 -0
  14. package/dist/helper/dimensions.helper.js +7 -3
  15. package/dist/helper/display-code-helper.d.ts +42 -0
  16. package/dist/helper/display-code-helper.js +73 -1
  17. package/dist/helper/facts.helper.js +64 -0
  18. package/dist/helper/policy-check.helper.d.ts +183 -0
  19. package/dist/helper/policy-check.helper.js +337 -0
  20. package/dist/helper/vehicles.helper.d.ts +45 -1
  21. package/dist/helper/vehicles.helper.js +61 -0
  22. package/dist/policy-engine.d.ts +95 -1
  23. package/dist/policy-engine.js +103 -0
  24. package/dist/rule-operator/custom-operators.d.ts +7 -0
  25. package/dist/rule-operator/custom-operators.js +57 -3
  26. package/dist/types/axle-calculation-results.d.ts +49 -0
  27. package/dist/types/axle-calculation-results.js +8 -0
  28. package/dist/types/axle-configuration.d.ts +12 -0
  29. package/dist/types/axle-configuration.js +6 -0
  30. package/dist/types/bridge-calculation-constants.d.ts +8 -0
  31. package/dist/types/bridge-calculation-result.d.ts +11 -0
  32. package/dist/types/commodity.d.ts +10 -0
  33. package/dist/types/commodity.js +6 -0
  34. package/dist/types/cost-rule.d.ts +8 -0
  35. package/dist/types/cost-rule.js +6 -0
  36. package/dist/types/dimension-modifier.d.ts +27 -0
  37. package/dist/types/dimension-modifier.js +6 -0
  38. package/dist/types/display-code-defaults.d.ts +22 -0
  39. package/dist/types/display-code-defaults.js +6 -0
  40. package/dist/types/facts.d.ts +14 -0
  41. package/dist/types/facts.js +6 -0
  42. package/dist/types/geographic-region.d.ts +10 -0
  43. package/dist/types/geographic-region.js +6 -0
  44. package/dist/types/identified-object.d.ts +8 -0
  45. package/dist/types/identified-object.js +6 -0
  46. package/dist/types/index.d.ts +1 -0
  47. package/dist/types/permit-application.d.ts +109 -0
  48. package/dist/types/permit-application.js +6 -0
  49. package/dist/types/permit-condition.d.ts +18 -0
  50. package/dist/types/permit-condition.js +6 -0
  51. package/dist/types/permit-type.d.ts +18 -0
  52. package/dist/types/permit-type.js +6 -0
  53. package/dist/types/policy-definition.d.ts +24 -0
  54. package/dist/types/policy-definition.js +7 -0
  55. package/dist/types/range-matrix.d.ts +17 -0
  56. package/dist/types/range-matrix.js +6 -0
  57. package/dist/types/region-size-override.d.ts +10 -0
  58. package/dist/types/region-size-override.js +6 -0
  59. package/dist/types/self-issuable.d.ts +7 -0
  60. package/dist/types/self-issuable.js +6 -0
  61. package/dist/types/size-dimension.d.ts +17 -0
  62. package/dist/types/size-dimension.js +6 -0
  63. package/dist/types/special-authorizations.d.ts +9 -0
  64. package/dist/types/special-authorizations.js +6 -0
  65. package/dist/types/standard-tire-size.d.ts +8 -0
  66. package/dist/types/standard-tire-size.js +6 -0
  67. package/dist/types/vehicle-category.d.ts +27 -0
  68. package/dist/types/vehicle-category.js +6 -0
  69. package/dist/types/vehicle-type.d.ts +36 -0
  70. package/dist/types/vehicle-type.js +6 -0
  71. package/dist/types/vehicle.d.ts +27 -0
  72. package/dist/types/vehicle.js +6 -0
  73. package/dist/types/weight-dimension.d.ts +34 -0
  74. package/dist/types/weight-dimension.js +6 -0
  75. package/dist/validation-result.d.ts +1 -0
  76. package/dist/validation-results.js +2 -1
  77. package/dist/version.d.ts +1 -1
  78. package/dist/version.js +1 -1
  79. package/eslint.config.mjs +1 -1
  80. package/package.json +2 -1
@@ -0,0 +1,183 @@
1
+ import { PolicyCheckResult, AxleConfiguration } from 'onroute-policy-engine/types';
2
+ import { Policy } from 'onroute-policy-engine';
3
+ /**
4
+ * Type definition for policy check functions.
5
+ *
6
+ * Each policy check function takes a policy instance, vehicle configuration,
7
+ * and axle configuration, then returns an array of policy check results.
8
+ * These functions are used by the runAxleCalculation method to perform
9
+ * various validation checks on vehicle configurations.
10
+ *
11
+ * @param policy - The policy instance containing configuration and validation rules
12
+ * @param vehicleConfiguration - Array of vehicle type identifiers representing the vehicle configuration
13
+ * @param axleConfiguration - Array of axle configurations corresponding to each vehicle
14
+ * @returns Array of PolicyCheckResult objects representing the outcomes of the policy check
15
+ */
16
+ type PolicyCheck = (policy: Policy, vehicleConfiguration: Array<string>, axleConfiguration: Array<AxleConfiguration>) => Array<PolicyCheckResult>;
17
+ /**
18
+ * Performs bridge formula calculations on axle groups and returns policy check results.
19
+ *
20
+ * This function calculates the bridge formula for each axle group in the vehicle configuration
21
+ * and determines whether each group passes or fails the bridge formula requirements. The bridge
22
+ * formula is a provincial regulation that limits the weight that can be carried on a group of axles
23
+ * based on the distance between the first and last axles in the group.
24
+ *
25
+ * @param policy - The policy instance containing bridge calculation configuration
26
+ * @param _vehicleConfiguration - Vehicle configuration (unused in this check, but required by PolicyCheck type)
27
+ * @param axleConfiguration - Array of axle configurations containing spacing and weight information
28
+ * @returns Array of AxleGroupPolicyCheckResult objects, one for each axle group tested
29
+ *
30
+ * @example
31
+ * // For a vehicle with 3 axle groups
32
+ * const results = CheckBridgeFormula(policy, ['TRKTRAC', 'SEMITRL'], [
33
+ * { numberOfAxles: 2, axleSpread: 1.8, weight: 12000 },
34
+ * { numberOfAxles: 3, axleSpread: 4.2, weight: 34000 },
35
+ * { numberOfAxles: 3, axleSpread: 3.0, weight: 34000 }
36
+ * ]);
37
+ * // Returns results for each axle group (e.g., axles 1-2, 1-3, 2-3)
38
+ *
39
+ * @see PolicyCheck
40
+ * @see AxleGroupPolicyCheckResult
41
+ * @see BridgeCalculationResult
42
+ */
43
+ export declare function CheckBridgeFormula(policy: Policy, _vehicleConfiguration: Array<string>, axleConfiguration: Array<AxleConfiguration>): Array<PolicyCheckResult>;
44
+ /**
45
+ * Validates the number of tires per axle unit against regulatory requirements.
46
+ *
47
+ * This function checks that each axle unit has a valid number of tires based on
48
+ * the number of axles in that unit. The validation allows for 2, 4, or 8 tires
49
+ * per axle (2, 4, or 8 * number of axles). This ensures compliance with tire
50
+ * count regulations for commercial vehicles.
51
+ *
52
+ * @param _policy - The policy instance (unused in this check, but required by PolicyCheck type)
53
+ * @param _vehicleConfiguration - Vehicle configuration (unused in this check, but required by PolicyCheck type)
54
+ * @param axleConfiguration - Array of axle configurations containing tire count and axle count information
55
+ * @returns Array of AxleUnitPolicyCheckResult objects, one for each axle unit tested
56
+ *
57
+ * @example
58
+ * // For a vehicle with 2 axle units
59
+ * const results = CheckNumTiresPerAxle(policy, ['TRKTRAC'], [
60
+ * { numberOfAxles: 2, numberOfTires: 4 }, // 2 axles × 2 tires = 4 (valid)
61
+ * { numberOfAxles: 3, numberOfTires: 12 } // 3 axles × 4 tires = 12 (valid)
62
+ * ]);
63
+ * // Returns pass results for both axle units
64
+ *
65
+ * @example
66
+ * // Invalid tire count example
67
+ * const results = CheckNumTiresPerAxle(policy, ['TRKTRAC'], [
68
+ * { numberOfAxles: 2, numberOfTires: 6 } // 2 axles × 3 tires = 6 (invalid - not 2, 4, or 8 per axle)
69
+ * ]);
70
+ * // Returns fail result for the axle unit
71
+ *
72
+ * @see PolicyCheck
73
+ * @see AxleUnitPolicyCheckResult
74
+ * @see AxleConfiguration
75
+ */
76
+ export declare function CheckNumTiresPerAxle(_policy: Policy, _vehicleConfiguration: Array<string>, axleConfiguration: Array<AxleConfiguration>): Array<PolicyCheckResult>;
77
+ /**
78
+ * Validates that each axle unit's weight does not exceed the permittable weight limits.
79
+ *
80
+ * This function performs weight validation for each axle unit in a vehicle configuration.
81
+ * It retrieves the default weight dimensions for power units and trailers based on their
82
+ * vehicle types and axle counts, then compares the actual axle unit weights against the
83
+ * permittable weight limits. The function handles both power units (with steer and drive
84
+ * axles) and trailers, ensuring compliance with weight regulations.
85
+ *
86
+ * @param policy - The policy instance containing weight dimension configurations and validation rules
87
+ * @param vehicleConfiguration - Array of vehicle type identifiers representing the vehicle configuration.
88
+ * The first element should be a power unit type, followed by trailer types.
89
+ * @param axleConfiguration - Array of axle configurations containing weight and axle count information.
90
+ * For power units, this includes both steer and drive axle configurations.
91
+ * @returns Array of AxleUnitPolicyCheckResult objects, one for each axle unit tested.
92
+ * Each result indicates whether the axle unit's weight is within permittable limits.
93
+ *
94
+ * @example
95
+ * // For a truck-tractor with 2-axle steer, 3-axle drive, and a 3-axle semi-trailer
96
+ * const results = CheckPermittableWeight(policy, ['TRKTRAC', 'SEMITRL'], [
97
+ * { numberOfAxles: 2, axleUnitWeight: 12000 }, // Steer axle unit
98
+ * { numberOfAxles: 3, axleUnitWeight: 34000 }, // Drive axle unit
99
+ * { numberOfAxles: 3, axleUnitWeight: 34000 } // Trailer axle unit
100
+ * ]);
101
+ * // Returns results for each axle unit indicating pass/fail status
102
+ *
103
+ * @example
104
+ * // For a single power unit with no trailers
105
+ * const results = CheckPermittableWeight(policy, ['TRKTRAC'], [
106
+ * { numberOfAxles: 2, axleUnitWeight: 12000 }, // Steer axle unit
107
+ * { numberOfAxles: 3, axleUnitWeight: 34000 } // Drive axle unit
108
+ * ]);
109
+ * // Returns results for steer and drive axle units only
110
+ *
111
+ * @see PolicyCheck
112
+ * @see AxleUnitPolicyCheckResult
113
+ * @see WeightDimension
114
+ * @see SingleAxleDimension
115
+ */
116
+ export declare function CheckPermittableWeight(policy: Policy, vehicleConfiguration: Array<string>, axleConfiguration: Array<AxleConfiguration>): Array<PolicyCheckResult>;
117
+ /**
118
+ * Validates minimum steer axle weight requirements for single steer, tridem drive power units.
119
+ *
120
+ * This function checks that the steer axle meets minimum weight requirements when the vehicle
121
+ * configuration consists of a single steer axle followed by a tridem drive axle. The steer axle
122
+ * must carry at least 27% of the tridem drive axle weight.
123
+ *
124
+ * @param _policy - The policy instance (unused in this check, but required by PolicyCheck type)
125
+ * @param _vehicleConfiguration - Vehicle configuration (unused in this check, but required by PolicyCheck type)
126
+ * @param axleConfiguration - Array of axle configurations containing weight and axle count information
127
+ * @returns Array of AxleGroupPolicyCheckResult objects with validation results
128
+ *
129
+ * @example
130
+ * // For a single steer, tridem drive configuration
131
+ * const results = CheckMinSteerAxleWeight(policy, ['TRKTRAC'], [
132
+ * { numberOfAxles: 1, axleUnitWeight: 8000 }, // Steer axle
133
+ * { numberOfAxles: 3, axleUnitWeight: 30000 } // Tridem drive axle
134
+ * ]);
135
+ * // Returns pass if steer axle weight >= 27% of drive axle weight (8100 kgs)
136
+ *
137
+ * @see PolicyCheck
138
+ * @see AxleGroupPolicyCheckResult
139
+ */
140
+ export declare function CheckMinSteerAxleWeight(_policy: Policy, _vehicleConfiguration: Array<string>, axleConfiguration: Array<AxleConfiguration>): Array<PolicyCheckResult>;
141
+ /**
142
+ * Validates minimum drive axle weight requirements for tandem and tridem drive power units.
143
+ *
144
+ * This function checks that the drive axle meets minimum weight requirements based on the
145
+ * Gross Vehicle Combination Weight (GVCW). For tandem drive axles, the minimum is 20% of GVCW
146
+ * or 23,000 lbs (whichever is smaller). For tridem drive axles, the minimum is 20% of GVCW
147
+ * or 28,000 lbs (whichever is smaller).
148
+ *
149
+ * @param _policy - The policy instance (unused in this check, but required by PolicyCheck type)
150
+ * @param _vehicleConfiguration - Vehicle configuration (unused in this check, but required by PolicyCheck type)
151
+ * @param axleConfiguration - Array of axle configurations containing weight and axle count information
152
+ * @returns Array of AxleGroupPolicyCheckResult objects with validation results
153
+ *
154
+ * @example
155
+ * // For a tandem drive configuration with GVCW of 120,000 kgs
156
+ * const results = CheckMinDriveAxleWeight(policy, ['TRKTRAC'], [
157
+ * { numberOfAxles: 1, axleUnitWeight: 12000 }, // Steer axle
158
+ * { numberOfAxles: 2, axleUnitWeight: 24000 } // Tandem drive axle
159
+ * ]);
160
+ * // Returns pass if drive axle weight >= min(20% of GVCW, 23,000 kgs)
161
+ *
162
+ * @see PolicyCheck
163
+ * @see AxleGroupPolicyCheckResult
164
+ */
165
+ export declare function CheckMinDriveAxleWeight(_policy: Policy, _vehicleConfiguration: Array<string>, axleConfiguration: Array<AxleConfiguration>): Array<PolicyCheckResult>;
166
+ /**
167
+ * Map of policy check functions keyed by their corresponding PolicyCheckId.
168
+ *
169
+ * This map contains all the registered policy check functions that are executed
170
+ * by the runAxleCalculation method. Each entry maps a PolicyCheckId to its
171
+ * corresponding validation function. New policy checks can be added by extending
172
+ * this map with additional entries.
173
+ *
174
+ * Currently includes:
175
+ * - BridgeFormula: Validates axle groups against bridge formula requirements
176
+ * - NumberOfWheelsPerAxle: Validates tire count per axle unit
177
+ *
178
+ * @see PolicyCheck
179
+ * @see PolicyCheckId
180
+ * @see runAxleCalculation
181
+ */
182
+ export declare const policyCheckMap: Map<string, PolicyCheck>;
183
+ export {};
@@ -0,0 +1,337 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.policyCheckMap = void 0;
4
+ exports.CheckBridgeFormula = CheckBridgeFormula;
5
+ exports.CheckNumTiresPerAxle = CheckNumTiresPerAxle;
6
+ exports.CheckPermittableWeight = CheckPermittableWeight;
7
+ exports.CheckMinSteerAxleWeight = CheckMinSteerAxleWeight;
8
+ exports.CheckMinDriveAxleWeight = CheckMinDriveAxleWeight;
9
+ const enum_1 = require("../enum");
10
+ /**
11
+ * Performs bridge formula calculations on axle groups and returns policy check results.
12
+ *
13
+ * This function calculates the bridge formula for each axle group in the vehicle configuration
14
+ * and determines whether each group passes or fails the bridge formula requirements. The bridge
15
+ * formula is a provincial regulation that limits the weight that can be carried on a group of axles
16
+ * based on the distance between the first and last axles in the group.
17
+ *
18
+ * @param policy - The policy instance containing bridge calculation configuration
19
+ * @param _vehicleConfiguration - Vehicle configuration (unused in this check, but required by PolicyCheck type)
20
+ * @param axleConfiguration - Array of axle configurations containing spacing and weight information
21
+ * @returns Array of AxleGroupPolicyCheckResult objects, one for each axle group tested
22
+ *
23
+ * @example
24
+ * // For a vehicle with 3 axle groups
25
+ * const results = CheckBridgeFormula(policy, ['TRKTRAC', 'SEMITRL'], [
26
+ * { numberOfAxles: 2, axleSpread: 1.8, weight: 12000 },
27
+ * { numberOfAxles: 3, axleSpread: 4.2, weight: 34000 },
28
+ * { numberOfAxles: 3, axleSpread: 3.0, weight: 34000 }
29
+ * ]);
30
+ * // Returns results for each axle group (e.g., axles 1-2, 1-3, 2-3)
31
+ *
32
+ * @see PolicyCheck
33
+ * @see AxleGroupPolicyCheckResult
34
+ * @see BridgeCalculationResult
35
+ */
36
+ function CheckBridgeFormula(policy, _vehicleConfiguration, axleConfiguration) {
37
+ const policyCheckResults = new Array();
38
+ const policyId = enum_1.PolicyCheckId.BridgeFormula;
39
+ const bridgeCalcResults = policy.calculateBridge(axleConfiguration);
40
+ bridgeCalcResults.forEach((br) => {
41
+ const message = `Axle group ${br.startAxleUnit} to ${br.endAxleUnit} ${br.success ? 'passes' : 'does not pass'} bridge formula.`;
42
+ policyCheckResults.push({
43
+ id: policyId,
44
+ message: message,
45
+ result: br.success
46
+ ? enum_1.PolicyCheckResultType.Pass
47
+ : enum_1.PolicyCheckResultType.Fail,
48
+ startAxleUnit: br.startAxleUnit,
49
+ endAxleUnit: br.endAxleUnit,
50
+ });
51
+ });
52
+ return policyCheckResults;
53
+ }
54
+ /**
55
+ * Validates the number of tires per axle unit against regulatory requirements.
56
+ *
57
+ * This function checks that each axle unit has a valid number of tires based on
58
+ * the number of axles in that unit. The validation allows for 2, 4, or 8 tires
59
+ * per axle (2, 4, or 8 * number of axles). This ensures compliance with tire
60
+ * count regulations for commercial vehicles.
61
+ *
62
+ * @param _policy - The policy instance (unused in this check, but required by PolicyCheck type)
63
+ * @param _vehicleConfiguration - Vehicle configuration (unused in this check, but required by PolicyCheck type)
64
+ * @param axleConfiguration - Array of axle configurations containing tire count and axle count information
65
+ * @returns Array of AxleUnitPolicyCheckResult objects, one for each axle unit tested
66
+ *
67
+ * @example
68
+ * // For a vehicle with 2 axle units
69
+ * const results = CheckNumTiresPerAxle(policy, ['TRKTRAC'], [
70
+ * { numberOfAxles: 2, numberOfTires: 4 }, // 2 axles × 2 tires = 4 (valid)
71
+ * { numberOfAxles: 3, numberOfTires: 12 } // 3 axles × 4 tires = 12 (valid)
72
+ * ]);
73
+ * // Returns pass results for both axle units
74
+ *
75
+ * @example
76
+ * // Invalid tire count example
77
+ * const results = CheckNumTiresPerAxle(policy, ['TRKTRAC'], [
78
+ * { numberOfAxles: 2, numberOfTires: 6 } // 2 axles × 3 tires = 6 (invalid - not 2, 4, or 8 per axle)
79
+ * ]);
80
+ * // Returns fail result for the axle unit
81
+ *
82
+ * @see PolicyCheck
83
+ * @see AxleUnitPolicyCheckResult
84
+ * @see AxleConfiguration
85
+ */
86
+ function CheckNumTiresPerAxle(_policy, _vehicleConfiguration, axleConfiguration) {
87
+ const policyCheckResults = new Array();
88
+ const policyId = enum_1.PolicyCheckId.NumberOfWheelsPerAxle;
89
+ let axleNum = 1;
90
+ axleConfiguration.forEach((ac) => {
91
+ const numTires = ac.numberOfTires || 0;
92
+ const numAxles = ac.numberOfAxles;
93
+ // Default result to fail, set to pass explicitly if valid
94
+ let result = enum_1.PolicyCheckResultType.Fail;
95
+ let message;
96
+ if (!numAxles) {
97
+ // Invalid number of axles, cannot calculate
98
+ message = `Number of axles for axle unit ${axleNum} is not permittable.`;
99
+ }
100
+ else {
101
+ const checkResult = [numAxles * 2, numAxles * 4, numAxles * 8].includes(numTires);
102
+ message = `Number of wheels for axle unit ${axleNum} is ${checkResult ? '' : 'not '}permittable.`;
103
+ if (checkResult)
104
+ result = enum_1.PolicyCheckResultType.Pass;
105
+ }
106
+ policyCheckResults.push({
107
+ id: policyId,
108
+ message: message,
109
+ result: result,
110
+ axleUnit: axleNum,
111
+ });
112
+ axleNum++;
113
+ });
114
+ return policyCheckResults;
115
+ }
116
+ /**
117
+ * Validates that each axle unit's weight does not exceed the permittable weight limits.
118
+ *
119
+ * This function performs weight validation for each axle unit in a vehicle configuration.
120
+ * It retrieves the default weight dimensions for power units and trailers based on their
121
+ * vehicle types and axle counts, then compares the actual axle unit weights against the
122
+ * permittable weight limits. The function handles both power units (with steer and drive
123
+ * axles) and trailers, ensuring compliance with weight regulations.
124
+ *
125
+ * @param policy - The policy instance containing weight dimension configurations and validation rules
126
+ * @param vehicleConfiguration - Array of vehicle type identifiers representing the vehicle configuration.
127
+ * The first element should be a power unit type, followed by trailer types.
128
+ * @param axleConfiguration - Array of axle configurations containing weight and axle count information.
129
+ * For power units, this includes both steer and drive axle configurations.
130
+ * @returns Array of AxleUnitPolicyCheckResult objects, one for each axle unit tested.
131
+ * Each result indicates whether the axle unit's weight is within permittable limits.
132
+ *
133
+ * @example
134
+ * // For a truck-tractor with 2-axle steer, 3-axle drive, and a 3-axle semi-trailer
135
+ * const results = CheckPermittableWeight(policy, ['TRKTRAC', 'SEMITRL'], [
136
+ * { numberOfAxles: 2, axleUnitWeight: 12000 }, // Steer axle unit
137
+ * { numberOfAxles: 3, axleUnitWeight: 34000 }, // Drive axle unit
138
+ * { numberOfAxles: 3, axleUnitWeight: 34000 } // Trailer axle unit
139
+ * ]);
140
+ * // Returns results for each axle unit indicating pass/fail status
141
+ *
142
+ * @example
143
+ * // For a single power unit with no trailers
144
+ * const results = CheckPermittableWeight(policy, ['TRKTRAC'], [
145
+ * { numberOfAxles: 2, axleUnitWeight: 12000 }, // Steer axle unit
146
+ * { numberOfAxles: 3, axleUnitWeight: 34000 } // Drive axle unit
147
+ * ]);
148
+ * // Returns results for steer and drive axle units only
149
+ *
150
+ * @see PolicyCheck
151
+ * @see AxleUnitPolicyCheckResult
152
+ * @see WeightDimension
153
+ * @see SingleAxleDimension
154
+ */
155
+ function CheckPermittableWeight(policy, vehicleConfiguration, axleConfiguration) {
156
+ const policyCheckResults = new Array();
157
+ const policyId = enum_1.PolicyCheckId.CheckPermittableWeight;
158
+ const singleAxleDimensions = [];
159
+ vehicleConfiguration.forEach((vc, i) => {
160
+ let weight;
161
+ if (i === 0) {
162
+ // This is a power unit, concatenate the steer and drive axle numbers
163
+ const powerUnitAxles = axleConfiguration[0].numberOfAxles * 10 +
164
+ axleConfiguration[1].numberOfAxles;
165
+ weight = policy.getDefaultPowerUnitWeight(vc, powerUnitAxles);
166
+ const steerAxleDimension = policy.selectCorrectWeightDimension(weight, vehicleConfiguration, axleConfiguration, 0) || {};
167
+ singleAxleDimensions.push(steerAxleDimension);
168
+ const driveAxleDimension = policy.selectCorrectWeightDimension(weight, vehicleConfiguration, axleConfiguration, 1) || {};
169
+ singleAxleDimensions.push(driveAxleDimension);
170
+ }
171
+ else {
172
+ if (i + 1 < axleConfiguration.length) {
173
+ // We need this guard because the last trailer in a configuration may represent
174
+ // the pseudo-trailer 'None'; in this case the axleConfiguration length will
175
+ // be one fewer than normal because the 'None' trailer does not get an axleConfig entry
176
+ weight = policy.getDefaultTrailerWeight(vc, axleConfiguration[i + 1].numberOfAxles);
177
+ const trailerDimension = policy.selectCorrectWeightDimension(weight, vehicleConfiguration, axleConfiguration, i + 1) || {};
178
+ singleAxleDimensions.push(trailerDimension);
179
+ }
180
+ }
181
+ });
182
+ axleConfiguration.forEach((ac, i) => {
183
+ const actualWeight = ac.axleUnitWeight;
184
+ const permittableWeight = singleAxleDimensions[i].permittable || 0;
185
+ const result = actualWeight <= permittableWeight;
186
+ const axleUnit = i + 1;
187
+ const message = `Weight for axle unit ${axleUnit} ${result ? 'is permittable' : `must not exceed ${permittableWeight} kgs`}`;
188
+ policyCheckResults.push({
189
+ id: policyId,
190
+ message: message,
191
+ result: result ? enum_1.PolicyCheckResultType.Pass : enum_1.PolicyCheckResultType.Fail,
192
+ axleUnit: axleUnit,
193
+ actualWeight: actualWeight,
194
+ thresholdWeight: permittableWeight,
195
+ });
196
+ });
197
+ return policyCheckResults;
198
+ }
199
+ /**
200
+ * Validates minimum steer axle weight requirements for single steer, tridem drive power units.
201
+ *
202
+ * This function checks that the steer axle meets minimum weight requirements when the vehicle
203
+ * configuration consists of a single steer axle followed by a tridem drive axle. The steer axle
204
+ * must carry at least 27% of the tridem drive axle weight.
205
+ *
206
+ * @param _policy - The policy instance (unused in this check, but required by PolicyCheck type)
207
+ * @param _vehicleConfiguration - Vehicle configuration (unused in this check, but required by PolicyCheck type)
208
+ * @param axleConfiguration - Array of axle configurations containing weight and axle count information
209
+ * @returns Array of AxleGroupPolicyCheckResult objects with validation results
210
+ *
211
+ * @example
212
+ * // For a single steer, tridem drive configuration
213
+ * const results = CheckMinSteerAxleWeight(policy, ['TRKTRAC'], [
214
+ * { numberOfAxles: 1, axleUnitWeight: 8000 }, // Steer axle
215
+ * { numberOfAxles: 3, axleUnitWeight: 30000 } // Tridem drive axle
216
+ * ]);
217
+ * // Returns pass if steer axle weight >= 27% of drive axle weight (8100 kgs)
218
+ *
219
+ * @see PolicyCheck
220
+ * @see AxleGroupPolicyCheckResult
221
+ */
222
+ function CheckMinSteerAxleWeight(_policy, _vehicleConfiguration, axleConfiguration) {
223
+ const policyCheckResults = new Array();
224
+ const policyId = enum_1.PolicyCheckId.MinSteerAxleWeight;
225
+ let message, result;
226
+ if (axleConfiguration[0].numberOfAxles === 1 &&
227
+ axleConfiguration[1].numberOfAxles === 3) {
228
+ // Check minimum load on steer axle
229
+ if (axleConfiguration[0].axleUnitWeight >=
230
+ axleConfiguration[1].axleUnitWeight * 0.27) {
231
+ message = 'Steer axle meets minimum weight requirements';
232
+ result = enum_1.PolicyCheckResultType.Pass;
233
+ }
234
+ else {
235
+ message =
236
+ 'Steer axle must be a minimum of 27% of tridem drive axle weight';
237
+ result = enum_1.PolicyCheckResultType.Fail;
238
+ }
239
+ }
240
+ else {
241
+ // This policy check is only for single steer, tridem drive power units
242
+ message = 'Policy check does not apply to this configuration';
243
+ result = enum_1.PolicyCheckResultType.Pass;
244
+ }
245
+ policyCheckResults.push({
246
+ id: policyId,
247
+ message: message,
248
+ result: result,
249
+ startAxleUnit: 1,
250
+ endAxleUnit: 2,
251
+ });
252
+ return policyCheckResults;
253
+ }
254
+ /**
255
+ * Validates minimum drive axle weight requirements for tandem and tridem drive power units.
256
+ *
257
+ * This function checks that the drive axle meets minimum weight requirements based on the
258
+ * Gross Vehicle Combination Weight (GVCW). For tandem drive axles, the minimum is 20% of GVCW
259
+ * or 23,000 lbs (whichever is smaller). For tridem drive axles, the minimum is 20% of GVCW
260
+ * or 28,000 lbs (whichever is smaller).
261
+ *
262
+ * @param _policy - The policy instance (unused in this check, but required by PolicyCheck type)
263
+ * @param _vehicleConfiguration - Vehicle configuration (unused in this check, but required by PolicyCheck type)
264
+ * @param axleConfiguration - Array of axle configurations containing weight and axle count information
265
+ * @returns Array of AxleGroupPolicyCheckResult objects with validation results
266
+ *
267
+ * @example
268
+ * // For a tandem drive configuration with GVCW of 120,000 kgs
269
+ * const results = CheckMinDriveAxleWeight(policy, ['TRKTRAC'], [
270
+ * { numberOfAxles: 1, axleUnitWeight: 12000 }, // Steer axle
271
+ * { numberOfAxles: 2, axleUnitWeight: 24000 } // Tandem drive axle
272
+ * ]);
273
+ * // Returns pass if drive axle weight >= min(20% of GVCW, 23,000 kgs)
274
+ *
275
+ * @see PolicyCheck
276
+ * @see AxleGroupPolicyCheckResult
277
+ */
278
+ function CheckMinDriveAxleWeight(_policy, _vehicleConfiguration, axleConfiguration) {
279
+ const policyCheckResults = new Array();
280
+ const policyId = enum_1.PolicyCheckId.MinDriveAxleWeight;
281
+ const gvcw = axleConfiguration.reduce((w, curr) => w + curr.axleUnitWeight, 0);
282
+ let message, result;
283
+ if (axleConfiguration[1].numberOfAxles === 2 ||
284
+ axleConfiguration[1].numberOfAxles === 3) {
285
+ let targetMinWeight = gvcw * 0.2;
286
+ if (axleConfiguration[1].numberOfAxles === 2) {
287
+ targetMinWeight = Math.min(targetMinWeight, 23000);
288
+ }
289
+ else if (axleConfiguration[1].numberOfAxles === 3) {
290
+ targetMinWeight = Math.min(targetMinWeight, 28000);
291
+ }
292
+ if (axleConfiguration[1].axleUnitWeight >= targetMinWeight) {
293
+ message = 'Drive axle meets minimum weight requirements';
294
+ result = enum_1.PolicyCheckResultType.Pass;
295
+ }
296
+ else {
297
+ message = 'Drive axle must be a minimum 20% of the GVCW';
298
+ result = enum_1.PolicyCheckResultType.Fail;
299
+ }
300
+ }
301
+ else {
302
+ // This policy check is only for tandem or tridem drive power units
303
+ message = 'Policy check does not apply to this configuration';
304
+ result = enum_1.PolicyCheckResultType.Pass;
305
+ }
306
+ policyCheckResults.push({
307
+ id: policyId,
308
+ message: message,
309
+ result: result,
310
+ startAxleUnit: 1,
311
+ endAxleUnit: axleConfiguration.length,
312
+ });
313
+ return policyCheckResults;
314
+ }
315
+ /**
316
+ * Map of policy check functions keyed by their corresponding PolicyCheckId.
317
+ *
318
+ * This map contains all the registered policy check functions that are executed
319
+ * by the runAxleCalculation method. Each entry maps a PolicyCheckId to its
320
+ * corresponding validation function. New policy checks can be added by extending
321
+ * this map with additional entries.
322
+ *
323
+ * Currently includes:
324
+ * - BridgeFormula: Validates axle groups against bridge formula requirements
325
+ * - NumberOfWheelsPerAxle: Validates tire count per axle unit
326
+ *
327
+ * @see PolicyCheck
328
+ * @see PolicyCheckId
329
+ * @see runAxleCalculation
330
+ */
331
+ exports.policyCheckMap = new Map([
332
+ [enum_1.PolicyCheckId.BridgeFormula, CheckBridgeFormula],
333
+ [enum_1.PolicyCheckId.CheckPermittableWeight, CheckPermittableWeight],
334
+ [enum_1.PolicyCheckId.MinDriveAxleWeight, CheckMinDriveAxleWeight],
335
+ [enum_1.PolicyCheckId.MinSteerAxleWeight, CheckMinSteerAxleWeight],
336
+ [enum_1.PolicyCheckId.NumberOfWheelsPerAxle, CheckNumTiresPerAxle],
337
+ ]);
@@ -1,4 +1,4 @@
1
- import { VehicleTypes } from 'onroute-policy-engine/types';
1
+ import { PermitVehicleDetails, VehicleConfiguration, VehicleTypes } from 'onroute-policy-engine/types';
2
2
  /**
3
3
  * Filters out all LCV vehicles from a supplied list of vehicle IDs.
4
4
  * @param vehicleList List of vehicle IDs to filter
@@ -14,3 +14,47 @@ export declare function filterOutLcv(vehicleList: Array<string>, vehicleTypes: V
14
14
  * @param type Type of vehicle to filter, either powerUnit or trailer
15
15
  */
16
16
  export declare function filterVehiclesByType(vehicleList: Array<string>, vehicleTypes: VehicleTypes, type: string): Array<string>;
17
+ /**
18
+ * Converts detailed vehicle information into a simplified vehicle configuration array.
19
+ *
20
+ * This helper function takes the vehicle details (which contain the power unit information) and
21
+ * the vehicle configuration (which contains trailer information) and combines them into
22
+ * a single array of vehicle type identifiers. The resulting array represents the complete
23
+ * vehicle configuration in the order: [powerUnit, trailer1, trailer2, ...].
24
+ *
25
+ * @param vehicleDetails - The vehicle details containing power unit information including
26
+ * the vehicle subtype (e.g., 'TRKTRAC' for truck-tractor)
27
+ * @param vehicleConfiguration - The vehicle configuration containing trailer information
28
+ * and other vehicle configuration details
29
+ * @returns An array of vehicle type identifiers representing the complete vehicle configuration.
30
+ * The first element is always the power unit type, followed by any attached trailer types.
31
+ * Returns an empty array if no power unit type is found in vehicle details.
32
+ *
33
+ * @example
34
+ * // For a truck-tractor with a semi-trailer
35
+ * const config = getSimplifiedVehicleConfigurationHelper(
36
+ * { vehicleSubType: 'TRKTRAC', ... },
37
+ * { trailers: [{ vehicleSubType: 'SEMITRL' }] }
38
+ * );
39
+ * // Returns: ['TRKTRAC', 'SEMITRL']
40
+ *
41
+ * @example
42
+ * // For a single power unit with no trailers
43
+ * const config = getSimplifiedVehicleConfigurationHelper(
44
+ * { vehicleSubType: 'TRKTRAC', ... },
45
+ * { trailers: [] }
46
+ * );
47
+ * // Returns: ['TRKTRAC']
48
+ *
49
+ * @example
50
+ * // For a power unit with multiple trailers
51
+ * const config = getSimplifiedVehicleConfigurationHelper(
52
+ * { vehicleSubType: 'TRKTRAC', ... },
53
+ * { trailers: [
54
+ * { vehicleSubType: 'SEMITRL' },
55
+ * { vehicleSubType: 'BOOSTER' }
56
+ * ]}
57
+ * );
58
+ * // Returns: ['TRKTRAC', 'SEMITRL', 'BOOSTER']
59
+ */
60
+ export declare function getSimplifiedVehicleConfigurationHelper(vehicleDetails: PermitVehicleDetails, vehicleConfiguration: VehicleConfiguration): string[];
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.filterOutLcv = filterOutLcv;
4
4
  exports.filterVehiclesByType = filterVehiclesByType;
5
+ exports.getSimplifiedVehicleConfigurationHelper = getSimplifiedVehicleConfigurationHelper;
5
6
  const enum_1 = require("onroute-policy-engine/enum");
6
7
  /**
7
8
  * Filters out all LCV vehicles from a supplied list of vehicle IDs.
@@ -56,3 +57,63 @@ function filterVehiclesByType(vehicleList, vehicleTypes, type) {
56
57
  });
57
58
  return filteredVehicles;
58
59
  }
60
+ /**
61
+ * Converts detailed vehicle information into a simplified vehicle configuration array.
62
+ *
63
+ * This helper function takes the vehicle details (which contain the power unit information) and
64
+ * the vehicle configuration (which contains trailer information) and combines them into
65
+ * a single array of vehicle type identifiers. The resulting array represents the complete
66
+ * vehicle configuration in the order: [powerUnit, trailer1, trailer2, ...].
67
+ *
68
+ * @param vehicleDetails - The vehicle details containing power unit information including
69
+ * the vehicle subtype (e.g., 'TRKTRAC' for truck-tractor)
70
+ * @param vehicleConfiguration - The vehicle configuration containing trailer information
71
+ * and other vehicle configuration details
72
+ * @returns An array of vehicle type identifiers representing the complete vehicle configuration.
73
+ * The first element is always the power unit type, followed by any attached trailer types.
74
+ * Returns an empty array if no power unit type is found in vehicle details.
75
+ *
76
+ * @example
77
+ * // For a truck-tractor with a semi-trailer
78
+ * const config = getSimplifiedVehicleConfigurationHelper(
79
+ * { vehicleSubType: 'TRKTRAC', ... },
80
+ * { trailers: [{ vehicleSubType: 'SEMITRL' }] }
81
+ * );
82
+ * // Returns: ['TRKTRAC', 'SEMITRL']
83
+ *
84
+ * @example
85
+ * // For a single power unit with no trailers
86
+ * const config = getSimplifiedVehicleConfigurationHelper(
87
+ * { vehicleSubType: 'TRKTRAC', ... },
88
+ * { trailers: [] }
89
+ * );
90
+ * // Returns: ['TRKTRAC']
91
+ *
92
+ * @example
93
+ * // For a power unit with multiple trailers
94
+ * const config = getSimplifiedVehicleConfigurationHelper(
95
+ * { vehicleSubType: 'TRKTRAC', ... },
96
+ * { trailers: [
97
+ * { vehicleSubType: 'SEMITRL' },
98
+ * { vehicleSubType: 'BOOSTER' }
99
+ * ]}
100
+ * );
101
+ * // Returns: ['TRKTRAC', 'SEMITRL', 'BOOSTER']
102
+ */
103
+ function getSimplifiedVehicleConfigurationHelper(vehicleDetails, vehicleConfiguration) {
104
+ // Retrieve the power unit type from vehicle details
105
+ const powerUnitType = vehicleDetails.vehicleSubType;
106
+ // Retrieve the list of trailers from configuration
107
+ const trailerList = vehicleConfiguration.trailers || [];
108
+ // If no power unit type is found, return empty array
109
+ if (!powerUnitType) {
110
+ return [];
111
+ }
112
+ // Start with the power unit type as the base configuration
113
+ const fullVehicleConfiguration = [powerUnitType];
114
+ // Add any attached trailers to the configuration
115
+ if (trailerList) {
116
+ fullVehicleConfiguration.push(...trailerList.map((t) => t.vehicleSubType));
117
+ }
118
+ return fullVehicleConfiguration;
119
+ }