onroute-policy-engine 1.7.0 → 1.8.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.
@@ -40,8 +40,10 @@ function runBridgeFormula(axleConfig, policy) {
40
40
  }
41
41
  let totalWeight = axle.axleUnitWeight;
42
42
  // Spread may be zero or undefined if the axle unit
43
- // is a single axle. Spacing to next will be zero or
44
- // undefined for the final axle unit in the configuration.
43
+ // is a single axle. Interaxle spacing will be zero or
44
+ // undefined for the first axle unit in the configuration
45
+ // since it describes the spacing from the previous axle
46
+ // unit in the configuration.
45
47
  if (axle.numberOfAxles > 1 && (!axle.axleSpread || axle.axleSpread < 0)) {
46
48
  throw new Error(`Invalid or missing axle spread for axle unit number ${firstAxle}`);
47
49
  }
@@ -0,0 +1,89 @@
1
+ import { Policy } from '../policy-engine';
2
+ import { AxleConfiguration, PowerUnitWeightDimension, SizeDimension, TrailerWeightDimension, VehicleRelatives, WeightDimension } from '../types';
3
+ import { SingleAxleDimension } from '../types/weight-dimension';
4
+ /**
5
+ * Gets the maximum size dimensions for a given permit type, commodity,
6
+ * and vehicle configuration. A vehicle configuration's size dimension is
7
+ * dictated by the configuration on the trailer. For configurations that
8
+ * are just a power unit, a pseudo trailer type 'NONE' is used and the
9
+ * size dimension is configured on that. Accessory category trailers
10
+ * (e.g. jeeps and boosters) are not used for configuration since they
11
+ * do not impact the size dimension in policy.
12
+ * @param permitTypeId ID of the permit type to get size dimension for
13
+ * @param commodityId ID of the commodity to get size dimension for
14
+ * @param currentConfiguration Current vehicle configuration to get size dimension for
15
+ * @param regions List of regions the vehicle will be traveling in. If not
16
+ * supplied this defaults to the most restrictive size dimension (if multiple
17
+ * are configured).
18
+ * @returns SizeDimension for the given permit type, commodity, and configuration
19
+ */
20
+ export declare function getSizeDimensionHelper(policy: Policy, permitTypeId: string, commodityId: string, configuration: Array<string>, regions?: Array<string>): SizeDimension | null;
21
+ /**
22
+ * Selects the correct size dimension from a list of potential candidates, based
23
+ * on the modifier of each dimension. If none of the modifiers match, returns
24
+ * null.
25
+ * @param sizeDimensions Size dimension options to choose from
26
+ * @param configuration The full vehicle configuration
27
+ * @param sizeTrailer The last trailer in the configuration that can be used
28
+ * for size calculations (e.g. not a booster).
29
+ */
30
+ export declare function selectCorrectSizeDimension(sizeDimensions: Array<SizeDimension>, configuration: Array<string>, sizeTrailer: string): SizeDimension | null;
31
+ /**
32
+ * Gets the default legal and permittable weights for a
33
+ * given power unit type and number of axles. The number of
34
+ * axles is supplied as a 2-digit number, with the most
35
+ * significant digit representing the steer axle unit and the
36
+ * least significant digit representing the drive axle unit.
37
+ * @param policy The instantiated policy object with weight config
38
+ * @param subType Power unit subtype
39
+ * @param axles Number of axles in the power unit axle units
40
+ * @returns Array of power unit weights. Multiple power unit
41
+ * weights may be returned if there are different weights
42
+ * depending on prior / subsequent vehicles in the
43
+ * configuration (weight modifiers). Will return an empty array
44
+ * if the number of axles is not configured in policy.
45
+ */
46
+ export declare function getDefaultPowerUnitWeightHelper(policy: Policy, subType: string, axles: number): Array<PowerUnitWeightDimension>;
47
+ /**
48
+ * Gets the default legal and permittable weights for a
49
+ * given trailer type and number of axles in the trailer axle
50
+ * unit.
51
+ * @param policy The instantiated policy object with weight config
52
+ * @param subType Trailer subtype
53
+ * @param axles Number of axles in the trailer axle unit
54
+ * @returns Array of trailer weights. Multiple trailer
55
+ * weights may be returned if there are different weights
56
+ * depending on prior / subsequent vehicles in the
57
+ * configuration (weight modifiers). Will return an empty array
58
+ * if the number of axles is not configured in policy.
59
+ */
60
+ export declare function getDefaultTrailerWeightHelper(policy: Policy, subType: string, axles: number): Array<TrailerWeightDimension>;
61
+ /**
62
+ * Given a list of default weight dimensions and a vehicle
63
+ * configuration, select the correct weight dimensions for
64
+ * the axle unit at the supplied axleIndex. The weight dimensions
65
+ * may have modifiers (e.g. if a tandem booster follows a tridem
66
+ * semi trailer) - this method will select the correct weights
67
+ * to be used for policy checks.
68
+ * @param policy The instantiated policy object with weight config
69
+ * @param weightDimensions Default weight dimensions for the vehicle
70
+ * at the index indicated by axleIndex
71
+ * @param configuration Full vehicle configuration
72
+ * @param axleConfiguration Full axle weights of the vehicle configuration
73
+ * @param axleIndex Index of the axle unit for which weights are
74
+ * to be returned.
75
+ * @returns Single axle dimension representing the legal and permittable
76
+ * weights for the axle unit at the supplied axleIndex.
77
+ */
78
+ export declare function selectCorrectWeightDimensionHelper(policy: Policy, weightDimensions: Array<WeightDimension>, configuration: Array<string>, axleConfiguration: Array<AxleConfiguration>, axleIndex: number): SingleAxleDimension | null;
79
+ /**
80
+ * Convenience method to get the vehicles in the configuration relative
81
+ * to the axle unit at the indicated axleIndex, to be used when
82
+ * evaluating weight modifiers.
83
+ * @param policy The instantiated policy object with weight config
84
+ * @param configuration Full vehicle configuration
85
+ * @param axleIndex Index of the axle unit for which relatives are
86
+ * to be returned.
87
+ * @returns VehicleRelatives for the axle at the indicated axleIndex
88
+ */
89
+ export declare function getVehicleRelatives(policy: Policy, configuration: Array<string>, axleIndex: number): VehicleRelatives;
@@ -0,0 +1,473 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSizeDimensionHelper = getSizeDimensionHelper;
4
+ exports.selectCorrectSizeDimension = selectCorrectSizeDimension;
5
+ exports.getDefaultPowerUnitWeightHelper = getDefaultPowerUnitWeightHelper;
6
+ exports.getDefaultTrailerWeightHelper = getDefaultTrailerWeightHelper;
7
+ exports.selectCorrectWeightDimensionHelper = selectCorrectWeightDimensionHelper;
8
+ exports.getVehicleRelatives = getVehicleRelatives;
9
+ const enum_1 = require("../enum");
10
+ /**
11
+ * Gets the maximum size dimensions for a given permit type, commodity,
12
+ * and vehicle configuration. A vehicle configuration's size dimension is
13
+ * dictated by the configuration on the trailer. For configurations that
14
+ * are just a power unit, a pseudo trailer type 'NONE' is used and the
15
+ * size dimension is configured on that. Accessory category trailers
16
+ * (e.g. jeeps and boosters) are not used for configuration since they
17
+ * do not impact the size dimension in policy.
18
+ * @param permitTypeId ID of the permit type to get size dimension for
19
+ * @param commodityId ID of the commodity to get size dimension for
20
+ * @param currentConfiguration Current vehicle configuration to get size dimension for
21
+ * @param regions List of regions the vehicle will be traveling in. If not
22
+ * supplied this defaults to the most restrictive size dimension (if multiple
23
+ * are configured).
24
+ * @returns SizeDimension for the given permit type, commodity, and configuration
25
+ */
26
+ function getSizeDimensionHelper(policy, permitTypeId, commodityId, configuration, regions) {
27
+ var _a, _b, _c;
28
+ // Initialize the sizeDimension with global defaults
29
+ let sizeDimension = null;
30
+ // Validate that the configuration is permittable
31
+ if (policy.isConfigurationValid(permitTypeId, commodityId, configuration)) {
32
+ // Get the power unit that has the size configuration
33
+ const commodity = policy.getCommodityDefinition(commodityId);
34
+ const powerUnit = (_b = (_a = commodity === null || commodity === void 0 ? void 0 : commodity.size) === null || _a === void 0 ? void 0 : _a.powerUnits) === null || _b === void 0 ? void 0 : _b.find((pu) => pu.type == configuration[0]);
35
+ if (!powerUnit) {
36
+ throw new Error(`Configuration error: could not find power unit '${configuration[0]}'`);
37
+ }
38
+ // Get the last trailer in the configuration that can be used for size calculations
39
+ const sizeTrailer = Array.from(configuration)
40
+ .reverse()
41
+ .find((vehicleId) => {
42
+ var _a;
43
+ const trailerType = (_a = policy.policyDefinition.vehicleTypes.trailerTypes) === null || _a === void 0 ? void 0 : _a.find((v) => v.id == vehicleId);
44
+ return !(trailerType === null || trailerType === void 0 ? void 0 : trailerType.ignoreForSizeDimensions);
45
+ });
46
+ if (sizeTrailer) {
47
+ // Get the trailer size dimension array for the commodity
48
+ const trailer = (_c = powerUnit.trailers) === null || _c === void 0 ? void 0 : _c.find((t) => t.type == sizeTrailer);
49
+ let sizeDimensions;
50
+ if (trailer &&
51
+ trailer.sizeDimensions &&
52
+ trailer.sizeDimensions.length > 0) {
53
+ sizeDimensions = trailer.sizeDimensions;
54
+ }
55
+ else {
56
+ sizeDimensions = new Array();
57
+ }
58
+ const sizeDimensionConfigured = selectCorrectSizeDimension(sizeDimensions, configuration, sizeTrailer);
59
+ if (sizeDimensionConfigured) {
60
+ // Adjust the size dimensions for the regions travelled, if needed
61
+ if (!regions) {
62
+ // If we are not provided a list of regions, assume we are
63
+ // traveling through all regions (will take the most restrictive
64
+ // of all dimensions in all cases).
65
+ console.log('Assuming all regions for size dimension lookup');
66
+ regions = policy.policyDefinition.geographicRegions.map((g) => g.id);
67
+ }
68
+ else {
69
+ console.log(`Using '${regions}' as regions for size lookup`);
70
+ }
71
+ const valueOverrides = [];
72
+ regions === null || regions === void 0 ? void 0 : regions.forEach((r) => {
73
+ var _a, _b, _c, _d;
74
+ let valueOverride;
75
+ // Check to see if this region has specific size dimensions
76
+ const regionOverride = (_a = sizeDimensionConfigured.regions) === null || _a === void 0 ? void 0 : _a.find((cr) => cr.region == r);
77
+ if (!regionOverride) {
78
+ // The region travelled does not have an override, so it assumes
79
+ // the dimensions of the bc default.
80
+ valueOverride = {
81
+ region: r,
82
+ h: sizeDimensionConfigured.h,
83
+ w: sizeDimensionConfigured.w,
84
+ l: sizeDimensionConfigured.l,
85
+ };
86
+ }
87
+ else {
88
+ // There is a region override with one or more dimensions. Use this
89
+ // value preferentially, using default dimension if not supplied
90
+ valueOverride = {
91
+ region: r,
92
+ h: (_b = regionOverride.h) !== null && _b !== void 0 ? _b : sizeDimensionConfigured.h,
93
+ w: (_c = regionOverride.w) !== null && _c !== void 0 ? _c : sizeDimensionConfigured.w,
94
+ l: (_d = regionOverride.l) !== null && _d !== void 0 ? _d : sizeDimensionConfigured.l,
95
+ };
96
+ }
97
+ valueOverrides.push(valueOverride);
98
+ });
99
+ // At this point we have a complete set of size dimensions for each of
100
+ // the regions that will be traversed. Take the minimum value of each
101
+ // dimension for the final value.
102
+ const minimumOverrides = valueOverrides.reduce((accumulator, currentValue) => {
103
+ if (typeof currentValue.h !== 'undefined') {
104
+ if (typeof accumulator.h === 'undefined') {
105
+ accumulator.h = currentValue.h;
106
+ }
107
+ else {
108
+ accumulator.h = Math.min(accumulator.h, currentValue.h);
109
+ }
110
+ }
111
+ if (typeof currentValue.w !== 'undefined') {
112
+ if (typeof accumulator.w === 'undefined') {
113
+ accumulator.w = currentValue.w;
114
+ }
115
+ else {
116
+ accumulator.w = Math.min(accumulator.w, currentValue.w);
117
+ }
118
+ }
119
+ if (typeof currentValue.l !== 'undefined') {
120
+ if (typeof accumulator.l === 'undefined') {
121
+ accumulator.l = currentValue.l;
122
+ }
123
+ else {
124
+ accumulator.l = Math.min(accumulator.l, currentValue.l);
125
+ }
126
+ }
127
+ return accumulator;
128
+ }, { region: '' });
129
+ sizeDimension = {
130
+ rp: sizeDimensionConfigured.rp,
131
+ fp: sizeDimensionConfigured.fp,
132
+ h: minimumOverrides.h,
133
+ w: minimumOverrides.w,
134
+ l: minimumOverrides.l,
135
+ };
136
+ }
137
+ else {
138
+ console.log('Size dimension not configured for trailer');
139
+ }
140
+ }
141
+ else {
142
+ console.log('Could not locate trailer to use for size dimension');
143
+ }
144
+ }
145
+ else {
146
+ console.log('Configuration is invalid, returning null size dimension');
147
+ }
148
+ return sizeDimension;
149
+ }
150
+ /**
151
+ * Selects the correct size dimension from a list of potential candidates, based
152
+ * on the modifier of each dimension. If none of the modifiers match, returns
153
+ * null.
154
+ * @param sizeDimensions Size dimension options to choose from
155
+ * @param configuration The full vehicle configuration
156
+ * @param sizeTrailer The last trailer in the configuration that can be used
157
+ * for size calculations (e.g. not a booster).
158
+ */
159
+ function selectCorrectSizeDimension(sizeDimensions, configuration, sizeTrailer) {
160
+ var _a;
161
+ let matchingDimension = null;
162
+ if ((sizeDimensions === null || sizeDimensions === void 0 ? void 0 : sizeDimensions.length) > 0 && (configuration === null || configuration === void 0 ? void 0 : configuration.length) > 0) {
163
+ for (const sizeDimension of sizeDimensions) {
164
+ if (!sizeDimension.modifiers) {
165
+ // This dimension has no modifiers, so it is the default if none of
166
+ // the other specific modifiers match.
167
+ matchingDimension = sizeDimension;
168
+ console.log('Using default size dimension, no modifiers specified');
169
+ }
170
+ else {
171
+ const sizeTrailerIndex = configuration.findIndex((c) => sizeTrailer == c);
172
+ const isMatch = (_a = sizeDimension.modifiers) === null || _a === void 0 ? void 0 : _a.every((m) => {
173
+ if (!m.type) {
174
+ return false;
175
+ }
176
+ switch (m.position) {
177
+ case enum_1.RelativePosition.First.toString():
178
+ return configuration[0] == m.type;
179
+ case enum_1.RelativePosition.Last.toString():
180
+ return configuration[configuration.length - 1] == m.type;
181
+ case enum_1.RelativePosition.Before.toString():
182
+ return configuration[sizeTrailerIndex - 1] == m.type;
183
+ case enum_1.RelativePosition.After.toString():
184
+ return configuration[sizeTrailerIndex + 1] == m.type;
185
+ default:
186
+ return false;
187
+ }
188
+ });
189
+ // As soon as we find a dimension with matching modifiers,
190
+ // set it and return it.
191
+ if (isMatch) {
192
+ matchingDimension = sizeDimension;
193
+ break;
194
+ }
195
+ }
196
+ }
197
+ }
198
+ else {
199
+ console.log('Either size dimensions or configuration array is null, no matching dimension returned');
200
+ }
201
+ return matchingDimension;
202
+ }
203
+ /**
204
+ * Gets the default legal and permittable weights for a
205
+ * given power unit type and number of axles. The number of
206
+ * axles is supplied as a 2-digit number, with the most
207
+ * significant digit representing the steer axle unit and the
208
+ * least significant digit representing the drive axle unit.
209
+ * @param policy The instantiated policy object with weight config
210
+ * @param subType Power unit subtype
211
+ * @param axles Number of axles in the power unit axle units
212
+ * @returns Array of power unit weights. Multiple power unit
213
+ * weights may be returned if there are different weights
214
+ * depending on prior / subsequent vehicles in the
215
+ * configuration (weight modifiers). Will return an empty array
216
+ * if the number of axles is not configured in policy.
217
+ */
218
+ function getDefaultPowerUnitWeightHelper(policy, subType, axles) {
219
+ return getDefaultVehicleWeightHelper(policy, subType, axles, true);
220
+ }
221
+ /**
222
+ * Gets the default legal and permittable weights for a
223
+ * given trailer type and number of axles in the trailer axle
224
+ * unit.
225
+ * @param policy The instantiated policy object with weight config
226
+ * @param subType Trailer subtype
227
+ * @param axles Number of axles in the trailer axle unit
228
+ * @returns Array of trailer weights. Multiple trailer
229
+ * weights may be returned if there are different weights
230
+ * depending on prior / subsequent vehicles in the
231
+ * configuration (weight modifiers). Will return an empty array
232
+ * if the number of axles is not configured in policy.
233
+ */
234
+ function getDefaultTrailerWeightHelper(policy, subType, axles) {
235
+ return getDefaultVehicleWeightHelper(policy, subType, axles, false);
236
+ }
237
+ /**
238
+ * Helper function for getting the default vehicle weight,
239
+ * works for both power units and trailers based on the
240
+ * value of the isPowerUnit flag. Not exported so not intended
241
+ * to be used outside of this helper class.
242
+ * @param policy The instantiated policy object with weight config
243
+ * @param subType Trailer subtype
244
+ * @param axles Number of axles in the vehicle
245
+ * @param isPowerUnit Whether this vehicle is a power unit
246
+ * @returns Array of weight dimensions, either TrailerWeightDimension
247
+ * or PowerUnitWeightDimension based on the value of isPowerUnit
248
+ */
249
+ function getDefaultVehicleWeightHelper(policy, subType, axles, isPowerUnit) {
250
+ var _a, _b, _c, _d, _e, _f;
251
+ const vehicleDefinition = isPowerUnit
252
+ ? policy.getPowerUnitDefinition(subType)
253
+ : policy.getTrailerDefinition(subType);
254
+ if (!vehicleDefinition) {
255
+ throw new Error(`No definition found for vehicle type '${subType}'`);
256
+ }
257
+ // Prefer specific subtype weight definition
258
+ const weights = (_a = vehicleDefinition.defaultWeightDimensions) === null || _a === void 0 ? void 0 : _a.filter((w) => w.axles === axles);
259
+ if (weights && weights.length > 0) {
260
+ return JSON.parse(JSON.stringify(weights));
261
+ }
262
+ // Second preference is category weight definition
263
+ const vehicleCategories = isPowerUnit
264
+ ? (_b = policy.policyDefinition.vehicleCategories) === null || _b === void 0 ? void 0 : _b.powerUnitCategories
265
+ : (_c = policy.policyDefinition.vehicleCategories) === null || _c === void 0 ? void 0 : _c.trailerCategories;
266
+ const vehicleCategory = vehicleCategories === null || vehicleCategories === void 0 ? void 0 : vehicleCategories.find((c) => c.id === vehicleDefinition.category);
267
+ if (vehicleCategory) {
268
+ const overridesForAxle = (_d = vehicleCategory.defaultWeightDimensions) === null || _d === void 0 ? void 0 : _d.filter((w) => w.axles === axles);
269
+ if (overridesForAxle) {
270
+ return JSON.parse(JSON.stringify(overridesForAxle));
271
+ }
272
+ }
273
+ // Final preference is global weight default
274
+ const globalDefaults = isPowerUnit
275
+ ? (_e = policy.policyDefinition.globalWeightDefaults) === null || _e === void 0 ? void 0 : _e.powerUnits
276
+ : (_f = policy.policyDefinition.globalWeightDefaults) === null || _f === void 0 ? void 0 : _f.trailers;
277
+ const vehicleDefaults = globalDefaults === null || globalDefaults === void 0 ? void 0 : globalDefaults.filter((w) => w.axles === axles);
278
+ if (vehicleDefaults) {
279
+ // Return a copy of the vehicle weights
280
+ return JSON.parse(JSON.stringify(vehicleDefaults));
281
+ }
282
+ else {
283
+ return new Array();
284
+ }
285
+ }
286
+ /**
287
+ * Given a list of default weight dimensions and a vehicle
288
+ * configuration, select the correct weight dimensions for
289
+ * the axle unit at the supplied axleIndex. The weight dimensions
290
+ * may have modifiers (e.g. if a tandem booster follows a tridem
291
+ * semi trailer) - this method will select the correct weights
292
+ * to be used for policy checks.
293
+ * @param policy The instantiated policy object with weight config
294
+ * @param weightDimensions Default weight dimensions for the vehicle
295
+ * at the index indicated by axleIndex
296
+ * @param configuration Full vehicle configuration
297
+ * @param axleConfiguration Full axle weights of the vehicle configuration
298
+ * @param axleIndex Index of the axle unit for which weights are
299
+ * to be returned.
300
+ * @returns Single axle dimension representing the legal and permittable
301
+ * weights for the axle unit at the supplied axleIndex.
302
+ */
303
+ function selectCorrectWeightDimensionHelper(policy, weightDimensions, configuration, axleConfiguration, axleIndex) {
304
+ let matchingDimension = null;
305
+ if (!weightDimensions || weightDimensions.length === 0) {
306
+ throw new Error('Missing weight dimensions');
307
+ }
308
+ if (!configuration || configuration.length === 0) {
309
+ throw new Error('Missing configuration');
310
+ }
311
+ if (!axleConfiguration || axleConfiguration.length === 0) {
312
+ throw new Error('Missing axle configuration');
313
+ }
314
+ if (axleIndex > configuration.length) {
315
+ throw new Error('Invalid axle index value');
316
+ }
317
+ if (configuration.length !== axleConfiguration.length - 1) {
318
+ // We expect the axle configuration array length to be one more
319
+ // than the configuration length because the power unit has two
320
+ // axle units.
321
+ throw new Error('Wrong number of axles configured for vehicle configuration');
322
+ }
323
+ const relatives = getVehicleRelatives(policy, configuration, axleIndex);
324
+ for (const weightDimension of weightDimensions) {
325
+ // Just renaming this for conciseness
326
+ const m = weightDimension.modifier;
327
+ if (!m) {
328
+ // This dimension has no modifiers, so it is the default
329
+ if (axleIndex <= 1) {
330
+ const pwd = weightDimension;
331
+ matchingDimension = {
332
+ legal: axleIndex === 0 ? pwd.saLegal : pwd.daLegal,
333
+ permittable: axleIndex === 0 ? pwd.saPermittable : pwd.daPermittable,
334
+ };
335
+ }
336
+ else {
337
+ const twd = weightDimension;
338
+ const { legal, permittable } = twd;
339
+ matchingDimension = { legal, permittable };
340
+ }
341
+ console.log('Using default weight dimension, no modifiers specified');
342
+ }
343
+ else {
344
+ let isMatch = false;
345
+ // We can match by vehicle type or vehicle category
346
+ let matcher = m.type;
347
+ let isTypeMatch = true;
348
+ if (!matcher) {
349
+ matcher = m.category;
350
+ isTypeMatch = false;
351
+ }
352
+ if (matcher) {
353
+ switch (m.position) {
354
+ case enum_1.RelativePosition.First.toString():
355
+ isMatch =
356
+ matcher ==
357
+ (isTypeMatch ? relatives.firstType : relatives.firstCategory);
358
+ break;
359
+ case enum_1.RelativePosition.Last.toString():
360
+ isMatch =
361
+ matcher ==
362
+ (isTypeMatch ? relatives.lastType : relatives.lastCategory);
363
+ break;
364
+ case enum_1.RelativePosition.Before.toString(): {
365
+ isMatch =
366
+ matcher ==
367
+ (isTypeMatch ? relatives.prevType : relatives.prevCategory);
368
+ if (isMatch && m.axles) {
369
+ isMatch =
370
+ m.axles == axleConfiguration[axleIndex - 1].numberOfAxles;
371
+ }
372
+ const spacingFromPrev = axleConfiguration[axleIndex].interaxleSpacing;
373
+ if (!spacingFromPrev) {
374
+ console.log(`Axle configuration incorrect, missing interaxle spacing`);
375
+ isMatch = false;
376
+ break;
377
+ }
378
+ else if (isMatch && m.minInterAxleSpacing) {
379
+ isMatch = m.minInterAxleSpacing <= spacingFromPrev;
380
+ }
381
+ if (isMatch && m.maxInterAxleSpacing) {
382
+ isMatch = m.maxInterAxleSpacing >= spacingFromPrev;
383
+ }
384
+ break;
385
+ }
386
+ case enum_1.RelativePosition.After.toString(): {
387
+ isMatch =
388
+ matcher ==
389
+ (isTypeMatch ? relatives.nextType : relatives.nextCategory);
390
+ if (isMatch && m.axles) {
391
+ isMatch =
392
+ m.axles == axleConfiguration[axleIndex + 1].numberOfAxles;
393
+ }
394
+ const spacingToNext = axleConfiguration[axleIndex + 1].interaxleSpacing;
395
+ if (!spacingToNext) {
396
+ console.log(`Axle configuration incorrect, missing interaxle spacing`);
397
+ isMatch = false;
398
+ break;
399
+ }
400
+ else if (isMatch && m.minInterAxleSpacing) {
401
+ isMatch = m.minInterAxleSpacing <= spacingToNext;
402
+ }
403
+ if (isMatch && m.maxInterAxleSpacing) {
404
+ isMatch = m.maxInterAxleSpacing >= spacingToNext;
405
+ }
406
+ break;
407
+ }
408
+ default:
409
+ isMatch = false;
410
+ break;
411
+ }
412
+ }
413
+ // As soon as we find a dimension with matching modifiers,
414
+ // set it and return it. The implication is that if there are
415
+ // multiple modifiers that match, the first one will be
416
+ // returned (so modifiers should be configured to be exclusive).
417
+ if (isMatch) {
418
+ const twd = weightDimension;
419
+ const { legal, permittable } = twd;
420
+ matchingDimension = { legal, permittable };
421
+ break;
422
+ }
423
+ }
424
+ }
425
+ return matchingDimension;
426
+ }
427
+ /**
428
+ * Convenience method to get the vehicles in the configuration relative
429
+ * to the axle unit at the indicated axleIndex, to be used when
430
+ * evaluating weight modifiers.
431
+ * @param policy The instantiated policy object with weight config
432
+ * @param configuration Full vehicle configuration
433
+ * @param axleIndex Index of the axle unit for which relatives are
434
+ * to be returned.
435
+ * @returns VehicleRelatives for the axle at the indicated axleIndex
436
+ */
437
+ function getVehicleRelatives(policy, configuration, axleIndex) {
438
+ var _a, _b;
439
+ const firstType = configuration[0];
440
+ const lastType = configuration[configuration.length - 1];
441
+ const firstVehicle = policy.getVehicleDefinition(firstType);
442
+ const lastVehicle = policy.getVehicleDefinition(lastType);
443
+ // Get relevant nearby vehicle types for the target axle
444
+ const vehicleRelatives = {
445
+ firstType: firstType,
446
+ lastType: lastType,
447
+ firstCategory: firstVehicle === null || firstVehicle === void 0 ? void 0 : firstVehicle.category,
448
+ lastCategory: lastVehicle === null || lastVehicle === void 0 ? void 0 : lastVehicle.category,
449
+ };
450
+ if (axleIndex <= 1) {
451
+ // First two axles are for the power unit which has no
452
+ // previous type (it is first in the configuration always)
453
+ vehicleRelatives.prevType = null;
454
+ vehicleRelatives.prevCategory = null;
455
+ }
456
+ else {
457
+ // Subtract 2 from the configuration index to account for
458
+ // the fact that the power unit has two axles.
459
+ vehicleRelatives.prevType = configuration[axleIndex - 2];
460
+ vehicleRelatives.prevCategory = (_a = policy.getVehicleDefinition(vehicleRelatives.prevType)) === null || _a === void 0 ? void 0 : _a.category;
461
+ }
462
+ if (configuration.length === 1 || axleIndex === configuration.length) {
463
+ // The axleIndex is for the last vehicle in the configuration,
464
+ // so it has no next type.
465
+ vehicleRelatives.nextType = null;
466
+ vehicleRelatives.nextCategory = null;
467
+ }
468
+ else {
469
+ vehicleRelatives.nextType = configuration[axleIndex];
470
+ vehicleRelatives.nextCategory = (_b = policy.getVehicleDefinition(vehicleRelatives.nextType)) === null || _b === void 0 ? void 0 : _b.category;
471
+ }
472
+ return vehicleRelatives;
473
+ }
@@ -1,4 +1,4 @@
1
- import { PolicyDefinition, PermitType, Commodity, VehicleType, SizeDimension, AxleConfiguration, BridgeCalculationResult, ConditionForPermit } from 'onroute-policy-engine/types';
1
+ import { PolicyDefinition, PermitType, Commodity, VehicleType, SizeDimension, AxleConfiguration, BridgeCalculationResult, ConditionForPermit, TrailerType, PowerUnitType, TrailerWeightDimension, PowerUnitWeightDimension, WeightDimension, SingleAxleDimension, StandardTireSize } 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';
@@ -101,46 +101,31 @@ export declare class Policy {
101
101
  getNextPermittableVehicles(permitTypeId: string, commodityId: string, currentConfiguration: Array<string>): Map<string, string>;
102
102
  /**
103
103
  * Returns whether the supplied configuration is valid for the given permit type
104
- * and commodity. If the permit type does not require a commodity, this method
105
- * will return false. This will not validate incomplete configurations - if the
106
- * current configuration has only a power unit this will return false even if the
107
- * power unit is acceptable because there is no trailer which is mandatory.
108
- * If this is called for a permit type that does not require commodity, or with
109
- * a commodity not permitted for the permit type, it will return false.
104
+ * and commodity. If the permit type does not require a commodity, or if this
105
+ * method is called with a commodity not permitted for the permit type, this method
106
+ * will return false.
110
107
  * @param permitTypeId ID of the permit type to validate the configuration against
111
108
  * @param commodityId ID of the commodity used for the configuration
112
109
  * @param currentConfiguration Current vehicle configuration to validate
113
110
  * @param validatePartial Whether to validate a partial configuration (e.g. one
114
111
  * that does not include a trailer). This will just return whether or not there
115
112
  * are any invalid vehicles in the configuration. If true, an empty current
116
- * configuration will return true from this method.
113
+ * configuration will return true from this method provided the commodity is
114
+ * allowable for the permit type.
117
115
  */
118
116
  isConfigurationValid(permitTypeId: string, commodityId: string, currentConfiguration: Array<string>, validatePartial?: boolean): boolean;
119
117
  /**
120
118
  * Gets the maximum size dimensions for a given permit type, commodity,
121
- * and vehicle configuration. A vehicle configuration's size dimension is
122
- * dictated by the configuration on the trailer. For configurations that
123
- * are just a power unit, a pseudo trailer type 'NONE' is used and the
124
- * size dimension is configured on that. Accessory category trailers
125
- * (e.g. jeeps and boosters) are not used for configuration since they
126
- * do not impact the size dimension in policy.
119
+ * and vehicle configuration. Delegates to helper method.
127
120
  * @param permitTypeId ID of the permit type to get size dimension for
128
121
  * @param commodityId ID of the commodity to get size dimension for
129
- * @param currentConfiguration Current vehicle configuration to get size dimension for
122
+ * @param configuration Current vehicle configuration to get size dimension for
130
123
  * @param regions List of regions the vehicle will be traveling in. If not
131
124
  * supplied this defaults to the most restrictive size dimension (if multiple
132
125
  * are configured).
133
126
  * @returns SizeDimension for the given permit type, commodity, and configuration
134
127
  */
135
128
  getSizeDimension(permitTypeId: string, commodityId: string, configuration: Array<string>, regions?: Array<string>): SizeDimension | null;
136
- /**
137
- * Selects the correct size dimension from a list of potential candidates, based
138
- * on the modifier of each dimension. If none of the modifiers match, returns
139
- * null.
140
- * @param sizeDimensions Size dimension options to choose from
141
- * @param currentConfiguration The full vehicle configuration
142
- */
143
- selectCorrectSizeDimension(sizeDimensions: Array<SizeDimension>, configuration: Array<string>, sizeTrailer: string): SizeDimension | null;
144
129
  /**
145
130
  * Gets a list of all configured power unit types in the policy definition.
146
131
  * @returns Map of power unit type IDs to power unit type names.
@@ -164,6 +149,18 @@ export declare class Policy {
164
149
  * @returns Vehicle Type (trailer or power unit), or null if none found
165
150
  */
166
151
  getVehicleDefinition(subType?: string): VehicleType | null;
152
+ /**
153
+ * Gets a full PowerUnitType definition by subtype
154
+ * @param subType string subtype of the power unit to return
155
+ * @returns PowerUnitType for the supplied subtype
156
+ */
157
+ getPowerUnitDefinition(subType?: string): PowerUnitType | null;
158
+ /**
159
+ * Gets a full TrailerType definition by subtype
160
+ * @param subType string subtype of the trailer to return
161
+ * @returns TrailerType for the supplied subtype
162
+ */
163
+ getTrailerDefinition(subType?: string): TrailerType | null;
167
164
  /**
168
165
  * Gets a full Commodity definition by ID
169
166
  * @param type Type ID of the commodity to return.
@@ -185,4 +182,56 @@ export declare class Policy {
185
182
  * @param permitType Permit type definition
186
183
  */
187
184
  getAllowedVehicles(permitType: PermitType): Map<string, Map<string, string>>;
185
+ /**
186
+ * Gets the default legal and permittable weights for a
187
+ * given trailer type and number of axles in the trailer axle
188
+ * unit.
189
+ * @param subType Trailer subtype
190
+ * @param axles Number of axles in the trailer axle unit
191
+ * @returns Array of trailer weights. Multiple trailer
192
+ * weights may be returned if there are different weights
193
+ * depending on prior / subsequent vehicles in the
194
+ * configuration (weight modifiers). Will return an empty array
195
+ * if the number of axles is not configured in policy.
196
+ */
197
+ getDefaultTrailerWeight(subType: string, axles: number): Array<TrailerWeightDimension>;
198
+ /**
199
+ * Gets the default legal and permittable weights for a
200
+ * given power unit type and number of axles. The number of
201
+ * axles is supplied as a 2-digit number, with the most
202
+ * significant digit representing the steer axle unit and the
203
+ * least significant digit representing the drive axle unit.
204
+ * @param subType Power unit subtype
205
+ * @param axles Number of axles in the power unit axle units
206
+ * @returns Array of power unit weights. Multiple power unit
207
+ * weights may be returned if there are different weights
208
+ * depending on prior / subsequent vehicles in the
209
+ * configuration (weight modifiers). Will return an empty array
210
+ * if the number of axles is not configured in policy.
211
+ */
212
+ getDefaultPowerUnitWeight(subType: string, axles: number): Array<PowerUnitWeightDimension>;
213
+ /**
214
+ * Given a list of default weight dimensions and a vehicle
215
+ * configuration, select the correct weight dimensions for
216
+ * the axle unit at the supplied axleIndex. The weight dimensions
217
+ * may have modifiers (e.g. if a tandem booster follows a tridem
218
+ * semi trailer) - this method will select the correct weights
219
+ * to be used for policy checks.
220
+ * @param weightDimensions Default weight dimensions for the vehicle
221
+ * at the index indicated by axleIndex
222
+ * @param configuration Full vehicle configuration
223
+ * @param axleConfiguration Full axle weights of the vehicle configuration
224
+ * @param axleIndex Index of the axle unit for which weights are
225
+ * to be returned.
226
+ * @returns Single axle dimension representing the legal and permittable
227
+ * weights for the axle unit at the supplied axleIndex.
228
+ */
229
+ selectCorrectWeightDimension(weightDimensions: Array<WeightDimension>, configuration: Array<string>, axleConfiguration: Array<AxleConfiguration>, axleIndex: number): SingleAxleDimension | null;
230
+ /**
231
+ * Get the list of known standard tire sizes, used to populate
232
+ * dropdown lists in front-end interfaces.
233
+ * @returns List of known standard tire sizes, or empty array if
234
+ * none are configured
235
+ */
236
+ getStandardTireSizes(): Array<StandardTireSize>;
188
237
  }
@@ -17,6 +17,8 @@ const lt_1 = __importDefault(require("semver/functions/lt"));
17
17
  const major_1 = __importDefault(require("semver/functions/major"));
18
18
  const vehicles_helper_1 = require("./helper/vehicles.helper");
19
19
  const conditions_helper_1 = require("./helper/conditions.helper");
20
+ const dimensions_helper_1 = require("./helper/dimensions.helper");
21
+ const dimensions_helper_2 = require("./helper/dimensions.helper");
20
22
  /** Class representing commercial vehicle policy. */
21
23
  class Policy {
22
24
  /**
@@ -392,19 +394,17 @@ class Policy {
392
394
  }
393
395
  /**
394
396
  * Returns whether the supplied configuration is valid for the given permit type
395
- * and commodity. If the permit type does not require a commodity, this method
396
- * will return false. This will not validate incomplete configurations - if the
397
- * current configuration has only a power unit this will return false even if the
398
- * power unit is acceptable because there is no trailer which is mandatory.
399
- * If this is called for a permit type that does not require commodity, or with
400
- * a commodity not permitted for the permit type, it will return false.
397
+ * and commodity. If the permit type does not require a commodity, or if this
398
+ * method is called with a commodity not permitted for the permit type, this method
399
+ * will return false.
401
400
  * @param permitTypeId ID of the permit type to validate the configuration against
402
401
  * @param commodityId ID of the commodity used for the configuration
403
402
  * @param currentConfiguration Current vehicle configuration to validate
404
403
  * @param validatePartial Whether to validate a partial configuration (e.g. one
405
404
  * that does not include a trailer). This will just return whether or not there
406
405
  * are any invalid vehicles in the configuration. If true, an empty current
407
- * configuration will return true from this method.
406
+ * configuration will return true from this method provided the commodity is
407
+ * allowable for the permit type.
408
408
  */
409
409
  isConfigurationValid(permitTypeId, commodityId, currentConfiguration, validatePartial = false) {
410
410
  var _a, _b;
@@ -488,194 +488,17 @@ class Policy {
488
488
  }
489
489
  /**
490
490
  * Gets the maximum size dimensions for a given permit type, commodity,
491
- * and vehicle configuration. A vehicle configuration's size dimension is
492
- * dictated by the configuration on the trailer. For configurations that
493
- * are just a power unit, a pseudo trailer type 'NONE' is used and the
494
- * size dimension is configured on that. Accessory category trailers
495
- * (e.g. jeeps and boosters) are not used for configuration since they
496
- * do not impact the size dimension in policy.
491
+ * and vehicle configuration. Delegates to helper method.
497
492
  * @param permitTypeId ID of the permit type to get size dimension for
498
493
  * @param commodityId ID of the commodity to get size dimension for
499
- * @param currentConfiguration Current vehicle configuration to get size dimension for
494
+ * @param configuration Current vehicle configuration to get size dimension for
500
495
  * @param regions List of regions the vehicle will be traveling in. If not
501
496
  * supplied this defaults to the most restrictive size dimension (if multiple
502
497
  * are configured).
503
498
  * @returns SizeDimension for the given permit type, commodity, and configuration
504
499
  */
505
500
  getSizeDimension(permitTypeId, commodityId, configuration, regions) {
506
- var _a, _b, _c;
507
- // Initialize the sizeDimension with global defaults
508
- let sizeDimension = null;
509
- // Validate that the configuration is permittable
510
- if (this.isConfigurationValid(permitTypeId, commodityId, configuration)) {
511
- // Get the power unit that has the size configuration
512
- const commodity = this.getCommodityDefinition(commodityId);
513
- const powerUnit = (_b = (_a = commodity === null || commodity === void 0 ? void 0 : commodity.size) === null || _a === void 0 ? void 0 : _a.powerUnits) === null || _b === void 0 ? void 0 : _b.find((pu) => pu.type == configuration[0]);
514
- if (!powerUnit) {
515
- throw new Error(`Configuration error: could not find power unit '${configuration[0]}'`);
516
- }
517
- // Get the last trailer in the configuration that can be used for size calculations
518
- const sizeTrailer = Array.from(configuration)
519
- .reverse()
520
- .find((vehicleId) => {
521
- var _a;
522
- const trailerType = (_a = this.policyDefinition.vehicleTypes.trailerTypes) === null || _a === void 0 ? void 0 : _a.find((v) => v.id == vehicleId);
523
- return !(trailerType === null || trailerType === void 0 ? void 0 : trailerType.ignoreForSizeDimensions);
524
- });
525
- if (sizeTrailer) {
526
- // Get the trailer size dimension array for the commodity
527
- const trailer = (_c = powerUnit.trailers) === null || _c === void 0 ? void 0 : _c.find((t) => t.type == sizeTrailer);
528
- let sizeDimensions;
529
- if (trailer &&
530
- trailer.sizeDimensions &&
531
- trailer.sizeDimensions.length > 0) {
532
- sizeDimensions = trailer.sizeDimensions;
533
- }
534
- else {
535
- sizeDimensions = new Array();
536
- }
537
- const sizeDimensionConfigured = this.selectCorrectSizeDimension(sizeDimensions, configuration, sizeTrailer);
538
- if (sizeDimensionConfigured) {
539
- // Adjust the size dimensions for the regions travelled, if needed
540
- if (!regions) {
541
- // If we are not provided a list of regions, assume we are
542
- // traveling through all regions (will take the most restrictive
543
- // of all dimensions in all cases).
544
- console.log('Assuming all regions for size dimension lookup');
545
- regions = this.policyDefinition.geographicRegions.map((g) => g.id);
546
- }
547
- else {
548
- console.log(`Using '${regions}' as regions for size lookup`);
549
- }
550
- const valueOverrides = [];
551
- regions === null || regions === void 0 ? void 0 : regions.forEach((r) => {
552
- var _a, _b, _c, _d;
553
- let valueOverride;
554
- // Check to see if this region has specific size dimensions
555
- const regionOverride = (_a = sizeDimensionConfigured.regions) === null || _a === void 0 ? void 0 : _a.find((cr) => cr.region == r);
556
- if (!regionOverride) {
557
- // The region travelled does not have an override, so it assumes
558
- // the dimensions of the bc default.
559
- valueOverride = {
560
- region: r,
561
- h: sizeDimensionConfigured.h,
562
- w: sizeDimensionConfigured.w,
563
- l: sizeDimensionConfigured.l,
564
- };
565
- }
566
- else {
567
- // There is a region override with one or more dimensions. Use this
568
- // value preferentially, using default dimension if not supplied
569
- valueOverride = {
570
- region: r,
571
- h: (_b = regionOverride.h) !== null && _b !== void 0 ? _b : sizeDimensionConfigured.h,
572
- w: (_c = regionOverride.w) !== null && _c !== void 0 ? _c : sizeDimensionConfigured.w,
573
- l: (_d = regionOverride.l) !== null && _d !== void 0 ? _d : sizeDimensionConfigured.l,
574
- };
575
- }
576
- valueOverrides.push(valueOverride);
577
- });
578
- // At this point we have a complete set of size dimensions for each of
579
- // the regions that will be traversed. Take the minimum value of each
580
- // dimension for the final value.
581
- const minimumOverrides = valueOverrides.reduce((accumulator, currentValue) => {
582
- if (typeof currentValue.h !== 'undefined') {
583
- if (typeof accumulator.h === 'undefined') {
584
- accumulator.h = currentValue.h;
585
- }
586
- else {
587
- accumulator.h = Math.min(accumulator.h, currentValue.h);
588
- }
589
- }
590
- if (typeof currentValue.w !== 'undefined') {
591
- if (typeof accumulator.w === 'undefined') {
592
- accumulator.w = currentValue.w;
593
- }
594
- else {
595
- accumulator.w = Math.min(accumulator.w, currentValue.w);
596
- }
597
- }
598
- if (typeof currentValue.l !== 'undefined') {
599
- if (typeof accumulator.l === 'undefined') {
600
- accumulator.l = currentValue.l;
601
- }
602
- else {
603
- accumulator.l = Math.min(accumulator.l, currentValue.l);
604
- }
605
- }
606
- return accumulator;
607
- }, { region: '' });
608
- sizeDimension = {
609
- rp: sizeDimensionConfigured.rp,
610
- fp: sizeDimensionConfigured.fp,
611
- h: minimumOverrides.h,
612
- w: minimumOverrides.w,
613
- l: minimumOverrides.l,
614
- };
615
- }
616
- else {
617
- console.log('Size dimension not configured for trailer');
618
- }
619
- }
620
- else {
621
- console.log('Could not locate trailer to use for size dimension');
622
- }
623
- }
624
- else {
625
- console.log('Configuration is invalid, returning null size dimension');
626
- }
627
- return sizeDimension;
628
- }
629
- /**
630
- * Selects the correct size dimension from a list of potential candidates, based
631
- * on the modifier of each dimension. If none of the modifiers match, returns
632
- * null.
633
- * @param sizeDimensions Size dimension options to choose from
634
- * @param currentConfiguration The full vehicle configuration
635
- */
636
- selectCorrectSizeDimension(sizeDimensions, configuration, sizeTrailer) {
637
- var _a;
638
- let matchingDimension = null;
639
- if ((sizeDimensions === null || sizeDimensions === void 0 ? void 0 : sizeDimensions.length) > 0 && (configuration === null || configuration === void 0 ? void 0 : configuration.length) > 0) {
640
- for (const sizeDimension of sizeDimensions) {
641
- if (!sizeDimension.modifiers) {
642
- // This dimension has no modifiers, so it is the default if none of
643
- // the other specific modifiers match.
644
- matchingDimension = sizeDimension;
645
- console.log('Using default size dimension, no modifiers specified');
646
- }
647
- else {
648
- const sizeTrailerIndex = configuration.findIndex((c) => sizeTrailer == c);
649
- const isMatch = (_a = sizeDimension.modifiers) === null || _a === void 0 ? void 0 : _a.every((m) => {
650
- if (!m.type) {
651
- return false;
652
- }
653
- switch (m.position) {
654
- case enum_1.RelativePosition.First.toString():
655
- return configuration[0] == m.type;
656
- case enum_1.RelativePosition.Last.toString():
657
- return configuration[configuration.length - 1] == m.type;
658
- case enum_1.RelativePosition.Before.toString():
659
- return configuration[sizeTrailerIndex - 1] == m.type;
660
- case enum_1.RelativePosition.After.toString():
661
- return configuration[sizeTrailerIndex + 1] == m.type;
662
- default:
663
- return false;
664
- }
665
- });
666
- // As soon as we find a dimension with matching modifiers,
667
- // set it and return it.
668
- if (isMatch) {
669
- matchingDimension = sizeDimension;
670
- break;
671
- }
672
- }
673
- }
674
- }
675
- else {
676
- console.log('Either size dimensions or configuration array is null, no matching dimension returned');
677
- }
678
- return matchingDimension;
501
+ return (0, dimensions_helper_1.getSizeDimensionHelper)(this, permitTypeId, commodityId, configuration, regions);
679
502
  }
680
503
  /**
681
504
  * Gets a list of all configured power unit types in the policy definition.
@@ -718,15 +541,31 @@ class Policy {
718
541
  */
719
542
  getVehicleDefinition(subType) {
720
543
  var _a, _b;
721
- if (this.policyDefinition.vehicleTypes) {
722
- const puType = (_a = this.policyDefinition.vehicleTypes.powerUnitTypes) === null || _a === void 0 ? void 0 : _a.find((pu) => pu.id == subType);
723
- if (puType) {
724
- return puType;
725
- }
726
- const trType = (_b = this.policyDefinition.vehicleTypes.trailerTypes) === null || _b === void 0 ? void 0 : _b.find((tr) => tr.id == subType);
727
- if (trType) {
728
- return trType;
729
- }
544
+ return ((_b = (_a = this.getPowerUnitDefinition(subType)) !== null && _a !== void 0 ? _a : this.getTrailerDefinition(subType)) !== null && _b !== void 0 ? _b : null);
545
+ }
546
+ /**
547
+ * Gets a full PowerUnitType definition by subtype
548
+ * @param subType string subtype of the power unit to return
549
+ * @returns PowerUnitType for the supplied subtype
550
+ */
551
+ getPowerUnitDefinition(subType) {
552
+ var _a, _b;
553
+ const puType = (_b = (_a = this.policyDefinition.vehicleTypes) === null || _a === void 0 ? void 0 : _a.powerUnitTypes) === null || _b === void 0 ? void 0 : _b.find((pu) => pu.id == subType);
554
+ if (puType) {
555
+ return puType;
556
+ }
557
+ return null;
558
+ }
559
+ /**
560
+ * Gets a full TrailerType definition by subtype
561
+ * @param subType string subtype of the trailer to return
562
+ * @returns TrailerType for the supplied subtype
563
+ */
564
+ getTrailerDefinition(subType) {
565
+ var _a, _b;
566
+ const trType = (_b = (_a = this.policyDefinition.vehicleTypes) === null || _a === void 0 ? void 0 : _a.trailerTypes) === null || _b === void 0 ? void 0 : _b.find((tr) => tr.id == subType);
567
+ if (trType) {
568
+ return trType;
730
569
  }
731
570
  return null;
732
571
  }
@@ -792,5 +631,70 @@ class Policy {
792
631
  allowedVehicleMap.set(enum_1.VehicleTypes.Trailers, (0, lists_helper_1.extractIdentifiedObjects)(this.policyDefinition.vehicleTypes.trailerTypes, trailerIds));
793
632
  return allowedVehicleMap;
794
633
  }
634
+ /**
635
+ * Gets the default legal and permittable weights for a
636
+ * given trailer type and number of axles in the trailer axle
637
+ * unit.
638
+ * @param subType Trailer subtype
639
+ * @param axles Number of axles in the trailer axle unit
640
+ * @returns Array of trailer weights. Multiple trailer
641
+ * weights may be returned if there are different weights
642
+ * depending on prior / subsequent vehicles in the
643
+ * configuration (weight modifiers). Will return an empty array
644
+ * if the number of axles is not configured in policy.
645
+ */
646
+ getDefaultTrailerWeight(subType, axles) {
647
+ return (0, dimensions_helper_2.getDefaultTrailerWeightHelper)(this, subType, axles);
648
+ }
649
+ /**
650
+ * Gets the default legal and permittable weights for a
651
+ * given power unit type and number of axles. The number of
652
+ * axles is supplied as a 2-digit number, with the most
653
+ * significant digit representing the steer axle unit and the
654
+ * least significant digit representing the drive axle unit.
655
+ * @param subType Power unit subtype
656
+ * @param axles Number of axles in the power unit axle units
657
+ * @returns Array of power unit weights. Multiple power unit
658
+ * weights may be returned if there are different weights
659
+ * depending on prior / subsequent vehicles in the
660
+ * configuration (weight modifiers). Will return an empty array
661
+ * if the number of axles is not configured in policy.
662
+ */
663
+ getDefaultPowerUnitWeight(subType, axles) {
664
+ return (0, dimensions_helper_2.getDefaultPowerUnitWeightHelper)(this, subType, axles);
665
+ }
666
+ /**
667
+ * Given a list of default weight dimensions and a vehicle
668
+ * configuration, select the correct weight dimensions for
669
+ * the axle unit at the supplied axleIndex. The weight dimensions
670
+ * may have modifiers (e.g. if a tandem booster follows a tridem
671
+ * semi trailer) - this method will select the correct weights
672
+ * to be used for policy checks.
673
+ * @param weightDimensions Default weight dimensions for the vehicle
674
+ * at the index indicated by axleIndex
675
+ * @param configuration Full vehicle configuration
676
+ * @param axleConfiguration Full axle weights of the vehicle configuration
677
+ * @param axleIndex Index of the axle unit for which weights are
678
+ * to be returned.
679
+ * @returns Single axle dimension representing the legal and permittable
680
+ * weights for the axle unit at the supplied axleIndex.
681
+ */
682
+ selectCorrectWeightDimension(weightDimensions, configuration, axleConfiguration, axleIndex) {
683
+ return (0, dimensions_helper_1.selectCorrectWeightDimensionHelper)(this, weightDimensions, configuration, axleConfiguration, axleIndex);
684
+ }
685
+ /**
686
+ * Get the list of known standard tire sizes, used to populate
687
+ * dropdown lists in front-end interfaces.
688
+ * @returns List of known standard tire sizes, or empty array if
689
+ * none are configured
690
+ */
691
+ getStandardTireSizes() {
692
+ if (this.policyDefinition.standardTireSizes) {
693
+ return this.policyDefinition.standardTireSizes;
694
+ }
695
+ else {
696
+ return new Array();
697
+ }
698
+ }
795
699
  }
796
700
  exports.Policy = Policy;
@@ -7,3 +7,13 @@ export type DimensionModifier = SelfIssuable & {
7
7
  minInterAxleSpacing?: number;
8
8
  maxInterAxleSpacing?: number;
9
9
  };
10
+ export type VehicleRelatives = {
11
+ firstType: string;
12
+ lastType: string;
13
+ nextType?: string | null;
14
+ prevType?: string | null;
15
+ firstCategory?: string | null;
16
+ lastCategory?: string | null;
17
+ nextCategory?: string | null;
18
+ prevCategory?: string | null;
19
+ };
@@ -3,10 +3,11 @@ export { BridgeCalculationConstants } from './bridge-calculation-constants';
3
3
  export { BridgeCalculationResult } from './bridge-calculation-result';
4
4
  export { Commodity, CommoditySize, CommodityWeight } from './commodity';
5
5
  export { CostRule } from './cost-rule';
6
- export { DimensionModifier } from './dimension-modifier';
6
+ export { DimensionModifier, VehicleRelatives } from './dimension-modifier';
7
7
  export { PermitFacts } from './facts';
8
8
  export { GeographicRegion } from './geographic-region';
9
9
  export { IdentifiedObject } from './identified-object';
10
+ export { PermitMailingAddress, PermitContactDetails, PermitVehicleDetails, PermitCommodity, PermitData, PermittedCommodity, VehicleInConfiguration, VehicleConfiguration, PermittedRoute, ManualRoute, PermitApplication, } from './permit-application';
10
11
  export { PermitConditionDefinition, ConditionRequirement, ConditionForPermit, } from './permit-condition';
11
12
  export { PermitType } from './permit-type';
12
13
  export { PolicyDefinition } from './policy-definition';
@@ -15,7 +16,8 @@ export { RegionSizeOverride } from './region-size-override';
15
16
  export { SelfIssuable } from './self-issuable';
16
17
  export { SizeDimension } from './size-dimension';
17
18
  export { SpecialAuthorizations } from './special-authorizations';
19
+ export { StandardTireSize } from './standard-tire-size';
18
20
  export { VehicleCategory, PowerUnitCategory, TrailerCategory, VehicleCategories, } from './vehicle-category';
19
21
  export { VehicleType, PowerUnitType, TrailerType, VehicleTypes, } from './vehicle-type';
20
22
  export { Vehicle, VehicleSizeConfiguration, TrailerSize, PowerUnitWeight, TrailerWeight, } from './vehicle';
21
- export { WeightDimension, PowerUnitWeightDimension, TrailerWeightDimension, DefaultWeightDimensions, } from './weight-dimension';
23
+ export { WeightDimension, PowerUnitWeightDimension, TrailerWeightDimension, DefaultWeightDimensions, SingleAxleDimension, } from './weight-dimension';
@@ -0,0 +1,93 @@
1
+ import { AxleConfiguration } from 'onroute-policy-engine/types';
2
+ export type PermitMailingAddress = {
3
+ addressLine1: string;
4
+ addressLine2?: string | null;
5
+ city: string;
6
+ provinceCode: string;
7
+ countryCode: string;
8
+ postalCode: string;
9
+ };
10
+ export type PermitContactDetails = {
11
+ firstName: string;
12
+ lastName: string;
13
+ phone1: string;
14
+ phone1Extension?: string | null;
15
+ phone2?: string | null;
16
+ phone2Extension?: string | null;
17
+ email: string;
18
+ additionalEmail?: string | null;
19
+ fax?: string | null;
20
+ };
21
+ export type PermitVehicleDetails = {
22
+ vehicleId?: string | null;
23
+ unitNumber?: string | null;
24
+ vin: string;
25
+ plate: string;
26
+ make?: string | null;
27
+ year?: number | null;
28
+ countryCode: string;
29
+ provinceCode: string;
30
+ vehicleType: string;
31
+ vehicleSubType: string;
32
+ licensedGVW?: number | null;
33
+ saveVehicle?: boolean | null;
34
+ };
35
+ export type PermitCommodity = {
36
+ description: string;
37
+ condition: string;
38
+ conditionLink: string;
39
+ checked: boolean;
40
+ disabled: boolean;
41
+ };
42
+ export type PermitData = {
43
+ companyName: string;
44
+ doingBusinessAs?: string;
45
+ clientNumber: string;
46
+ permitDuration: number;
47
+ commodities: Array<PermitCommodity>;
48
+ contactDetails: PermitContactDetails;
49
+ mailingAddress: PermitMailingAddress;
50
+ vehicleDetails: PermitVehicleDetails;
51
+ feeSummary?: string | null;
52
+ startDate: string;
53
+ expiryDate?: string | null;
54
+ permittedCommodity?: PermittedCommodity | null;
55
+ vehicleConfiguration?: VehicleConfiguration | null;
56
+ permittedRoute?: PermittedRoute | null;
57
+ applicationNotes?: string | null;
58
+ thirdPartyLiability?: string | null;
59
+ conditionalLicensingFee?: string | null;
60
+ };
61
+ export type PermittedCommodity = {
62
+ commodityType: string;
63
+ loadDescription: string;
64
+ };
65
+ export type VehicleInConfiguration = {
66
+ vehicleSubType: string;
67
+ };
68
+ export type VehicleConfiguration = {
69
+ overallLength?: number;
70
+ overallWidth?: number;
71
+ overallHeight?: number;
72
+ frontProjection?: number;
73
+ rearProjection?: number;
74
+ trailers?: Array<VehicleInConfiguration> | null;
75
+ loadedGVW?: number;
76
+ netWeight?: number;
77
+ axleConfiguration?: Array<AxleConfiguration>;
78
+ };
79
+ export type PermittedRoute = {
80
+ manualRoute?: ManualRoute | null;
81
+ routeDetails?: string | null;
82
+ };
83
+ export type ManualRoute = {
84
+ highwaySequence: Array<string>;
85
+ origin: string;
86
+ destination: string;
87
+ exitPoint?: string;
88
+ totalDistance?: number;
89
+ };
90
+ export type PermitApplication = {
91
+ permitData: PermitData;
92
+ permitType: string;
93
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,4 @@
1
- import { GeographicRegion, PermitType, DefaultWeightDimensions, VehicleTypes, Commodity, SizeDimension, VehicleCategories, RangeMatrix, BridgeCalculationConstants, PermitConditionDefinition } from 'onroute-policy-engine/types';
1
+ import { GeographicRegion, PermitType, DefaultWeightDimensions, VehicleTypes, Commodity, SizeDimension, VehicleCategories, RangeMatrix, BridgeCalculationConstants, PermitConditionDefinition, StandardTireSize } from 'onroute-policy-engine/types';
2
2
  import { RuleProperties } from 'json-rules-engine';
3
3
  export type PolicyDefinition = {
4
4
  minPEVersion: string;
@@ -13,4 +13,5 @@ export type PolicyDefinition = {
13
13
  rangeMatrices?: Array<RangeMatrix>;
14
14
  bridgeCalculationConstants: BridgeCalculationConstants;
15
15
  conditions?: Array<PermitConditionDefinition>;
16
+ standardTireSizes?: Array<StandardTireSize>;
16
17
  };
@@ -0,0 +1,4 @@
1
+ export type StandardTireSize = {
2
+ name: string;
3
+ size: number;
4
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,7 @@
1
- import { IdentifiedObject, SizeDimension, PowerUnitWeightDimension, TrailerWeightDimension } from 'onroute-policy-engine/types';
1
+ import { IdentifiedObject, SizeDimension, PowerUnitWeightDimension, TrailerWeightDimension, WeightDimension } from 'onroute-policy-engine/types';
2
2
  export type VehicleCategory = IdentifiedObject & {
3
3
  defaultSizeDimensions?: SizeDimension;
4
+ defaultWeightDimensions?: Array<WeightDimension>;
4
5
  };
5
6
  export type PowerUnitCategory = VehicleCategory & {
6
7
  defaultWeightDimensions?: Array<PowerUnitWeightDimension>;
@@ -1,7 +1,11 @@
1
1
  import { DimensionModifier, SelfIssuable } from 'onroute-policy-engine/types';
2
+ export type SingleAxleDimension = {
3
+ legal?: number;
4
+ permittable?: number;
5
+ };
2
6
  export type WeightDimension = SelfIssuable & {
3
7
  axles: number;
4
- modifiers?: Array<DimensionModifier>;
8
+ modifier?: DimensionModifier;
5
9
  };
6
10
  export type PowerUnitWeightDimension = WeightDimension & {
7
11
  saLegal?: number;
@@ -9,10 +13,7 @@ export type PowerUnitWeightDimension = WeightDimension & {
9
13
  daLegal?: number;
10
14
  daPermittable?: number;
11
15
  };
12
- export type TrailerWeightDimension = WeightDimension & {
13
- legal?: number;
14
- permittable?: number;
15
- };
16
+ export type TrailerWeightDimension = WeightDimension & SingleAxleDimension;
16
17
  export type DefaultWeightDimensions = {
17
18
  powerUnits: Array<PowerUnitWeightDimension>;
18
19
  trailers: Array<TrailerWeightDimension>;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "v1.7.0";
1
+ export declare const version = "v1.8.1";
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 = 'v1.7.0';
5
+ exports.version = 'v1.8.1';
package/package.json CHANGED
@@ -89,5 +89,5 @@
89
89
  ],
90
90
  "testEnvironment": "node"
91
91
  },
92
- "version": "v1.7.0"
92
+ "version": "v1.8.1"
93
93
  }