onroute-policy-engine 2.1.1 → 2.2.1

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/dist/enum/custom-operator.d.ts +6 -0
  2. package/dist/enum/custom-operator.js +10 -0
  3. package/dist/enum/facts.d.ts +8 -4
  4. package/dist/enum/facts.js +8 -4
  5. package/dist/enum/index.d.ts +2 -0
  6. package/dist/enum/index.js +6 -1
  7. package/dist/enum/permit-app-info.d.ts +8 -5
  8. package/dist/enum/permit-app-info.js +8 -5
  9. package/dist/enum/policy-check.d.ts +11 -0
  10. package/dist/enum/policy-check.js +16 -0
  11. package/dist/enum/validation-result-code.d.ts +1 -0
  12. package/dist/enum/validation-result-code.js +1 -0
  13. package/dist/helper/dimensions.helper.js +7 -3
  14. package/dist/helper/facts.helper.js +64 -0
  15. package/dist/helper/policy-check.helper.d.ts +183 -0
  16. package/dist/helper/policy-check.helper.js +337 -0
  17. package/dist/helper/vehicles.helper.d.ts +45 -1
  18. package/dist/helper/vehicles.helper.js +61 -0
  19. package/dist/policy-engine.d.ts +70 -1
  20. package/dist/policy-engine.js +78 -0
  21. package/dist/rule-operator/custom-operators.d.ts +7 -0
  22. package/dist/rule-operator/custom-operators.js +57 -3
  23. package/dist/types/axle-calculation-results.d.ts +49 -0
  24. package/dist/types/axle-calculation-results.js +8 -0
  25. package/dist/types/axle-configuration.d.ts +12 -0
  26. package/dist/types/axle-configuration.js +6 -0
  27. package/dist/types/bridge-calculation-constants.d.ts +8 -0
  28. package/dist/types/bridge-calculation-result.d.ts +11 -0
  29. package/dist/types/commodity.d.ts +10 -0
  30. package/dist/types/commodity.js +6 -0
  31. package/dist/types/cost-rule.d.ts +8 -0
  32. package/dist/types/cost-rule.js +6 -0
  33. package/dist/types/dimension-modifier.d.ts +27 -0
  34. package/dist/types/dimension-modifier.js +6 -0
  35. package/dist/types/display-code-defaults.d.ts +22 -0
  36. package/dist/types/display-code-defaults.js +6 -0
  37. package/dist/types/facts.d.ts +14 -0
  38. package/dist/types/facts.js +6 -0
  39. package/dist/types/geographic-region.d.ts +10 -0
  40. package/dist/types/geographic-region.js +6 -0
  41. package/dist/types/identified-object.d.ts +8 -0
  42. package/dist/types/identified-object.js +6 -0
  43. package/dist/types/index.d.ts +1 -0
  44. package/dist/types/permit-application.d.ts +109 -0
  45. package/dist/types/permit-application.js +6 -0
  46. package/dist/types/permit-condition.d.ts +18 -0
  47. package/dist/types/permit-condition.js +6 -0
  48. package/dist/types/permit-type.d.ts +18 -0
  49. package/dist/types/permit-type.js +6 -0
  50. package/dist/types/policy-definition.d.ts +24 -0
  51. package/dist/types/policy-definition.js +7 -0
  52. package/dist/types/range-matrix.d.ts +17 -0
  53. package/dist/types/range-matrix.js +6 -0
  54. package/dist/types/region-size-override.d.ts +10 -0
  55. package/dist/types/region-size-override.js +6 -0
  56. package/dist/types/self-issuable.d.ts +7 -0
  57. package/dist/types/self-issuable.js +6 -0
  58. package/dist/types/size-dimension.d.ts +17 -0
  59. package/dist/types/size-dimension.js +6 -0
  60. package/dist/types/special-authorizations.d.ts +9 -0
  61. package/dist/types/special-authorizations.js +6 -0
  62. package/dist/types/standard-tire-size.d.ts +8 -0
  63. package/dist/types/standard-tire-size.js +6 -0
  64. package/dist/types/vehicle-category.d.ts +27 -0
  65. package/dist/types/vehicle-category.js +6 -0
  66. package/dist/types/vehicle-type.d.ts +36 -0
  67. package/dist/types/vehicle-type.js +6 -0
  68. package/dist/types/vehicle.d.ts +27 -0
  69. package/dist/types/vehicle.js +6 -0
  70. package/dist/types/weight-dimension.d.ts +34 -0
  71. package/dist/types/weight-dimension.js +6 -0
  72. package/dist/validation-result.d.ts +1 -0
  73. package/dist/validation-results.js +2 -1
  74. package/dist/version.d.ts +1 -1
  75. package/dist/version.js +1 -1
  76. package/package.json +2 -1
  77. package/.github/workflows/analysis.yml +0 -68
  78. package/.github/workflows/pipeline.yml +0 -60
  79. package/.vscode/launch.json +0 -21
  80. package/eslint.config.mjs +0 -46
@@ -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
+ }
@@ -1,4 +1,4 @@
1
- import { PolicyDefinition, PermitType, Commodity, VehicleType, SizeDimension, AxleConfiguration, BridgeCalculationResult, ConditionForPermit, TrailerType, PowerUnitType, TrailerWeightDimension, PowerUnitWeightDimension, WeightDimension, SingleAxleDimension, StandardTireSize, TrailerDimensions } from 'onroute-policy-engine/types';
1
+ import { PolicyDefinition, PermitType, Commodity, VehicleType, SizeDimension, AxleConfiguration, BridgeCalculationResult, ConditionForPermit, TrailerType, PowerUnitType, TrailerWeightDimension, PowerUnitWeightDimension, WeightDimension, SingleAxleDimension, StandardTireSize, TrailerDimensions, AxleCalcResults, PermitVehicleDetails, VehicleConfiguration } from 'onroute-policy-engine/types';
2
2
  import { Engine } from 'json-rules-engine';
3
3
  import { ValidationResults } from './validation-results';
4
4
  import { SpecialAuthorizations } from './types/special-authorizations';
@@ -186,6 +186,42 @@ export declare class Policy {
186
186
  * axle group in the vehicle configuration
187
187
  */
188
188
  calculateBridge(axleConfig: Array<AxleConfiguration>): Array<BridgeCalculationResult>;
189
+ /**
190
+ * Runs all configured axle calculation policy checks against a vehicle configuration.
191
+ *
192
+ * This method iterates through all registered policy check functions (such as bridge formula
193
+ * calculations and tire count validations) and applies them to the provided vehicle and axle
194
+ * configurations. The results are aggregated into a single AxleCalcResults object containing
195
+ * all policy check outcomes and a total overload calculation.
196
+ *
197
+ * @param vehicleConfiguration Array of vehicle type identifiers representing the vehicle configuration.
198
+ * The first element should be a power unit type, followed by trailer types.
199
+ * Example: ['TRKTRAC', 'SEMITRL'] for a truck tractor with semi-trailer.
200
+ * @param axleConfiguration Array of axle configurations corresponding to each vehicle in the configuration.
201
+ * Each axle configuration contains details like number of axles, spacing, tire count, etc.
202
+ * The length should match the vehicleConfiguration array plus one (since the first
203
+ * vehicle in the configuration is a power unit with two axle units).
204
+ * @returns AxleCalcResults object containing:
205
+ * - results: Array of PolicyCheckResult objects, each representing the outcome of a specific policy check
206
+ * - totalOverload: Numeric value representing the total overload across all axle calculations
207
+ *
208
+ * @example
209
+ * // For a truck-tractor with 2-axle steer, 3-axle drive, and a 3-axle semi-trailer
210
+ * const results = policy.runAxleCalculation(
211
+ * ['TRKTRAC', 'SEMITRL'],
212
+ * [
213
+ * { numberOfAxles: 2, axleSpread: 1.8, numberOfTires: 4 },
214
+ * { numberOfAxles: 3, axleSpread: 4.2, numberOfTires: 12 },
215
+ * { numberOfAxles: 3, axleSpread: 3.0, numberOfTires: 12 }
216
+ * ]
217
+ * );
218
+ * // Returns results with bridge formula checks, tire count validations, etc.
219
+ *
220
+ * @see AxleCalcResults
221
+ * @see PolicyCheckResult
222
+ * @see AxleConfiguration
223
+ */
224
+ runAxleCalculation(vehicleConfiguration: Array<string>, axleConfiguration: Array<AxleConfiguration>): AxleCalcResults;
189
225
  /**
190
226
  * Gets the list of allowed vehicles separated into two maps, one
191
227
  * for trailers and one for power units. This will filter out LCV
@@ -271,4 +307,37 @@ export declare class Policy {
271
307
  * @throws {Error} If vehicleDisplayCodeDefaults is not configured in the policy definition.
272
308
  */
273
309
  getVehicleDisplayCode(configuration: Array<string>, axleConfiguration: Array<AxleConfiguration>): string;
310
+ /**
311
+ * Converts detailed vehicle information into a simplified vehicle configuration array.
312
+ *
313
+ * This method takes the vehicle details (which contain the power unit information) and
314
+ * the vehicle configuration (which contains trailer information) and combines them into
315
+ * a single array of vehicle type identifiers. The resulting array represents the complete
316
+ * vehicle configuration in the order: [powerUnit, trailer1, trailer2, ...].
317
+ *
318
+ * @param vehicleDetails - The vehicle details containing power unit information including
319
+ * the vehicle subtype (e.g., 'TRKTRAC' for truck-tractor)
320
+ * @param vehicleConfiguration - The vehicle configuration containing trailer information
321
+ * and other vehicle configuration details
322
+ * @returns An array of vehicle type identifiers representing the complete vehicle configuration.
323
+ * The first element is always the power unit type, followed by any attached trailer types.
324
+ * Returns an empty array if no power unit type is found in vehicle details.
325
+ *
326
+ * @example
327
+ * // For a truck-tractor with a semi-trailer
328
+ * const config = policy.getSimplifiedVehicleConfiguration(
329
+ * { vehicleSubType: 'TRKTRAC', ... },
330
+ * { trailers: [{ vehicleSubType: 'SEMITRL' }] }
331
+ * );
332
+ * // Returns: ['TRKTRAC', 'SEMITRL']
333
+ *
334
+ * @example
335
+ * // For a single power unit with no trailers
336
+ * const config = policy.getSimplifiedVehicleConfiguration(
337
+ * { vehicleSubType: 'TRKTRAC', ... },
338
+ * { trailers: [] }
339
+ * );
340
+ * // Returns: ['TRKTRAC']
341
+ */
342
+ getSimplifiedVehicleConfiguration(vehicleDetails: PermitVehicleDetails, vehicleConfiguration: VehicleConfiguration): string[];
274
343
  }
@@ -20,6 +20,7 @@ const conditions_helper_1 = require("./helper/conditions.helper");
20
20
  const dimensions_helper_1 = require("./helper/dimensions.helper");
21
21
  const dimensions_helper_2 = require("./helper/dimensions.helper");
22
22
  const display_code_helper_1 = require("./helper/display-code-helper");
23
+ const policy_check_helper_1 = require("./helper/policy-check.helper");
23
24
  /** Class representing commercial vehicle policy. */
24
25
  class Policy {
25
26
  /**
@@ -657,6 +658,48 @@ class Policy {
657
658
  }
658
659
  return bridgeResults;
659
660
  }
661
+ /**
662
+ * Runs all configured axle calculation policy checks against a vehicle configuration.
663
+ *
664
+ * This method iterates through all registered policy check functions (such as bridge formula
665
+ * calculations and tire count validations) and applies them to the provided vehicle and axle
666
+ * configurations. The results are aggregated into a single AxleCalcResults object containing
667
+ * all policy check outcomes and a total overload calculation.
668
+ *
669
+ * @param vehicleConfiguration Array of vehicle type identifiers representing the vehicle configuration.
670
+ * The first element should be a power unit type, followed by trailer types.
671
+ * Example: ['TRKTRAC', 'SEMITRL'] for a truck tractor with semi-trailer.
672
+ * @param axleConfiguration Array of axle configurations corresponding to each vehicle in the configuration.
673
+ * Each axle configuration contains details like number of axles, spacing, tire count, etc.
674
+ * The length should match the vehicleConfiguration array plus one (since the first
675
+ * vehicle in the configuration is a power unit with two axle units).
676
+ * @returns AxleCalcResults object containing:
677
+ * - results: Array of PolicyCheckResult objects, each representing the outcome of a specific policy check
678
+ * - totalOverload: Numeric value representing the total overload across all axle calculations
679
+ *
680
+ * @example
681
+ * // For a truck-tractor with 2-axle steer, 3-axle drive, and a 3-axle semi-trailer
682
+ * const results = policy.runAxleCalculation(
683
+ * ['TRKTRAC', 'SEMITRL'],
684
+ * [
685
+ * { numberOfAxles: 2, axleSpread: 1.8, numberOfTires: 4 },
686
+ * { numberOfAxles: 3, axleSpread: 4.2, numberOfTires: 12 },
687
+ * { numberOfAxles: 3, axleSpread: 3.0, numberOfTires: 12 }
688
+ * ]
689
+ * );
690
+ * // Returns results with bridge formula checks, tire count validations, etc.
691
+ *
692
+ * @see AxleCalcResults
693
+ * @see PolicyCheckResult
694
+ * @see AxleConfiguration
695
+ */
696
+ runAxleCalculation(vehicleConfiguration, axleConfiguration) {
697
+ const axleCalcResults = { results: [], totalOverload: 0 };
698
+ for (const [, func] of policy_check_helper_1.policyCheckMap) {
699
+ axleCalcResults.results.push(...func(this, vehicleConfiguration, axleConfiguration));
700
+ }
701
+ return axleCalcResults;
702
+ }
660
703
  /**
661
704
  * Gets the list of allowed vehicles separated into two maps, one
662
705
  * for trailers and one for power units. This will filter out LCV
@@ -777,5 +820,40 @@ class Policy {
777
820
  getVehicleDisplayCode(configuration, axleConfiguration) {
778
821
  return (0, display_code_helper_1.getVehicleDisplayCodeHelper)(this, configuration, axleConfiguration);
779
822
  }
823
+ /**
824
+ * Converts detailed vehicle information into a simplified vehicle configuration array.
825
+ *
826
+ * This method takes the vehicle details (which contain the power unit information) and
827
+ * the vehicle configuration (which contains trailer information) and combines them into
828
+ * a single array of vehicle type identifiers. The resulting array represents the complete
829
+ * vehicle configuration in the order: [powerUnit, trailer1, trailer2, ...].
830
+ *
831
+ * @param vehicleDetails - The vehicle details containing power unit information including
832
+ * the vehicle subtype (e.g., 'TRKTRAC' for truck-tractor)
833
+ * @param vehicleConfiguration - The vehicle configuration containing trailer information
834
+ * and other vehicle configuration details
835
+ * @returns An array of vehicle type identifiers representing the complete vehicle configuration.
836
+ * The first element is always the power unit type, followed by any attached trailer types.
837
+ * Returns an empty array if no power unit type is found in vehicle details.
838
+ *
839
+ * @example
840
+ * // For a truck-tractor with a semi-trailer
841
+ * const config = policy.getSimplifiedVehicleConfiguration(
842
+ * { vehicleSubType: 'TRKTRAC', ... },
843
+ * { trailers: [{ vehicleSubType: 'SEMITRL' }] }
844
+ * );
845
+ * // Returns: ['TRKTRAC', 'SEMITRL']
846
+ *
847
+ * @example
848
+ * // For a single power unit with no trailers
849
+ * const config = policy.getSimplifiedVehicleConfiguration(
850
+ * { vehicleSubType: 'TRKTRAC', ... },
851
+ * { trailers: [] }
852
+ * );
853
+ * // Returns: ['TRKTRAC']
854
+ */
855
+ getSimplifiedVehicleConfiguration(vehicleDetails, vehicleConfiguration) {
856
+ return (0, vehicles_helper_1.getSimplifiedVehicleConfigurationHelper)(vehicleDetails, vehicleConfiguration);
857
+ }
780
858
  }
781
859
  exports.Policy = Policy;
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Custom Operators for JSON Rules Engine
3
+ *
4
+ * This module defines custom operators that extend the functionality of the json-rules-engine
5
+ * library. These operators provide specialized validation and comparison logic for the
6
+ * onRouteBC policy engine.
7
+ */
1
8
  import { Operator } from 'json-rules-engine';
2
9
  declare const CustomOperators: Array<Operator>;
3
10
  export { CustomOperators };