onroute-policy-engine 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,4 +4,5 @@ export { PermitAppInfo } from './permit-app-info';
4
4
  export { RelativePosition } from './relative-position';
5
5
  export { ValidationResultCode } from './validation-result-code';
6
6
  export { ValidationResultType } from './validation-result-type';
7
+ export { VehicleCategory } from './vehicle-category';
7
8
  export { VehicleTypes } from './vehicle-types';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VehicleTypes = exports.ValidationResultType = exports.ValidationResultCode = exports.RelativePosition = exports.PermitAppInfo = exports.CostFacts = exports.PolicyFacts = exports.AccessoryVehicleType = void 0;
3
+ exports.VehicleTypes = exports.VehicleCategory = exports.ValidationResultType = exports.ValidationResultCode = exports.RelativePosition = exports.PermitAppInfo = exports.CostFacts = exports.PolicyFacts = exports.AccessoryVehicleType = void 0;
4
4
  var accessory_vehicle_type_1 = require("./accessory-vehicle-type");
5
5
  Object.defineProperty(exports, "AccessoryVehicleType", { enumerable: true, get: function () { return accessory_vehicle_type_1.AccessoryVehicleType; } });
6
6
  var facts_1 = require("./facts");
@@ -14,5 +14,7 @@ var validation_result_code_1 = require("./validation-result-code");
14
14
  Object.defineProperty(exports, "ValidationResultCode", { enumerable: true, get: function () { return validation_result_code_1.ValidationResultCode; } });
15
15
  var validation_result_type_1 = require("./validation-result-type");
16
16
  Object.defineProperty(exports, "ValidationResultType", { enumerable: true, get: function () { return validation_result_type_1.ValidationResultType; } });
17
+ var vehicle_category_1 = require("./vehicle-category");
18
+ Object.defineProperty(exports, "VehicleCategory", { enumerable: true, get: function () { return vehicle_category_1.VehicleCategory; } });
17
19
  var vehicle_types_1 = require("./vehicle-types");
18
20
  Object.defineProperty(exports, "VehicleTypes", { enumerable: true, get: function () { return vehicle_types_1.VehicleTypes; } });
@@ -0,0 +1,4 @@
1
+ export declare enum VehicleCategory {
2
+ PowerUnit = "powerUnit",
3
+ Trailer = "trailer"
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VehicleCategory = void 0;
4
+ var VehicleCategory;
5
+ (function (VehicleCategory) {
6
+ VehicleCategory["PowerUnit"] = "powerUnit";
7
+ VehicleCategory["Trailer"] = "trailer";
8
+ })(VehicleCategory || (exports.VehicleCategory = VehicleCategory = {}));
@@ -6,3 +6,11 @@ import { VehicleTypes } from '../types';
6
6
  * @returns
7
7
  */
8
8
  export declare function filterOutLcv(vehicleList: Array<string>, vehicleTypes: VehicleTypes): Array<string>;
9
+ /**
10
+ * Filters a list of vehicles to include only those matching the supplied
11
+ * vehicle type - either powerUnit or trailer.
12
+ * @param vehicleList List of vehicle IDs to filter
13
+ * @param vehicleTypes Configured vehicle types from policy configuration
14
+ * @param type Type of vehicle to filter, either powerUnit or trailer
15
+ */
16
+ export declare function filterVehiclesByType(vehicleList: Array<string>, vehicleTypes: VehicleTypes, type: string): Array<string>;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.filterOutLcv = filterOutLcv;
4
+ exports.filterVehiclesByType = filterVehiclesByType;
5
+ const enum_1 = require("../enum");
4
6
  /**
5
7
  * Filters out all LCV vehicles from a supplied list of vehicle IDs.
6
8
  * @param vehicleList List of vehicle IDs to filter
@@ -26,3 +28,31 @@ function filterOutLcv(vehicleList, vehicleTypes) {
26
28
  });
27
29
  return filteredList;
28
30
  }
31
+ /**
32
+ * Filters a list of vehicles to include only those matching the supplied
33
+ * vehicle type - either powerUnit or trailer.
34
+ * @param vehicleList List of vehicle IDs to filter
35
+ * @param vehicleTypes Configured vehicle types from policy configuration
36
+ * @param type Type of vehicle to filter, either powerUnit or trailer
37
+ */
38
+ function filterVehiclesByType(vehicleList, vehicleTypes, type) {
39
+ if (type !== enum_1.VehicleCategory.PowerUnit.toString() &&
40
+ type !== enum_1.VehicleCategory.Trailer.toString()) {
41
+ throw new Error(`Cannot filter based on invalid type '${type}'`);
42
+ }
43
+ let targetVehicleTypes;
44
+ if (type === enum_1.VehicleCategory.PowerUnit) {
45
+ targetVehicleTypes = vehicleTypes.powerUnitTypes;
46
+ }
47
+ else {
48
+ targetVehicleTypes = vehicleTypes.trailerTypes;
49
+ }
50
+ if (!targetVehicleTypes) {
51
+ return new Array();
52
+ }
53
+ const filteredVehicles = vehicleList.filter((vid) => {
54
+ const vehicleDef = targetVehicleTypes.find((vt) => vt.id === vid);
55
+ return vehicleDef;
56
+ });
57
+ return filteredVehicles;
58
+ }
@@ -68,7 +68,7 @@ export declare class Policy {
68
68
  * other keyed on 'trailers'. Each map consists of a string id for the
69
69
  * vehicle, and a string common name for the vehicle.
70
70
  */
71
- getPermittableVehicleTypes(permitTypeId: string, commodityId: string): Map<string, Map<string, string>>;
71
+ getPermittableVehicleTypes(permitTypeId: string, commodityId?: string): Map<string, Map<string, string>>;
72
72
  /**
73
73
  * Gets a list of all allowable power unit types for the given permit type
74
74
  * and commodity.
@@ -163,4 +163,11 @@ export declare class Policy {
163
163
  * axle group in the vehicle configuration
164
164
  */
165
165
  calculateBridge(axleConfig: Array<AxleConfiguration>): Array<BridgeCalculationResult>;
166
+ /**
167
+ * Gets the list of allowed vehicles separated into two maps, one
168
+ * for trailers and one for power units. This will filter out LCV
169
+ * vehicles unless authorized in special authorizations.
170
+ * @param permitType Permit type definition
171
+ */
172
+ getAllowedVehicles(permitType: PermitType): Map<string, Map<string, string>>;
166
173
  }
@@ -169,21 +169,24 @@ class Policy {
169
169
  */
170
170
  getPermittableVehicleTypes(permitTypeId, commodityId) {
171
171
  var _a, _b, _c, _d, _e;
172
- if (!permitTypeId || !commodityId) {
173
- throw new Error('Missing permitTypeId and/or commodityId');
172
+ if (!permitTypeId) {
173
+ throw new Error('Missing permitTypeId');
174
174
  }
175
175
  const permitType = this.getPermitTypeDefinition(permitTypeId);
176
176
  if (!permitType) {
177
177
  throw new Error(`Invalid permit type: '${permitTypeId}'`);
178
178
  }
179
179
  if (!permitType.commodityRequired) {
180
- // If commodity is not required, this method cannot calculate the
181
- // permittable vehicle types since they will not be configured.
182
- throw new Error(`Permit type '${permitTypeId}' does not require a commodity`);
180
+ // If commodity is not required, get the permittable vehicle types
181
+ // from the permit allowedVehicles list.
182
+ return this.getAllowedVehicles(permitType);
183
183
  }
184
184
  let puTypes;
185
185
  let trTypes;
186
186
  const allowableCommodities = this.getCommodities(permitTypeId);
187
+ if (!commodityId) {
188
+ throw new Error('Missing commodityId, permit type requires it');
189
+ }
187
190
  if (!allowableCommodities.has(commodityId)) {
188
191
  // If the commodity is not allowed for the permit type, no power
189
192
  // units or trailers are allowed.
@@ -709,5 +712,32 @@ class Policy {
709
712
  }
710
713
  return bridgeResults;
711
714
  }
715
+ /**
716
+ * Gets the list of allowed vehicles separated into two maps, one
717
+ * for trailers and one for power units. This will filter out LCV
718
+ * vehicles unless authorized in special authorizations.
719
+ * @param permitType Permit type definition
720
+ */
721
+ getAllowedVehicles(permitType) {
722
+ if (permitType.commodityRequired) {
723
+ // If commodity is required, this method cannot be used since it
724
+ // requires a fixed set of allowed vehicle types, not commodity-based
725
+ throw new Error(`Allowed vehicles not configured for permit type requiring commodity: '${permitType.id}'`);
726
+ }
727
+ let allowedVehicles = permitType.allowedVehicles;
728
+ if (!allowedVehicles) {
729
+ return new Map();
730
+ }
731
+ if (!this.specialAuthorizations ||
732
+ !this.specialAuthorizations.isLcvAllowed) {
733
+ allowedVehicles = this.filterOutLongCombinationVehicles(allowedVehicles);
734
+ }
735
+ const allowedVehicleMap = new Map();
736
+ const powerUnitIds = (0, vehicles_helper_1.filterVehiclesByType)(allowedVehicles, this.policyDefinition.vehicleTypes, enum_1.VehicleCategory.PowerUnit);
737
+ const trailerIds = (0, vehicles_helper_1.filterVehiclesByType)(allowedVehicles, this.policyDefinition.vehicleTypes, enum_1.VehicleCategory.Trailer);
738
+ allowedVehicleMap.set(enum_1.VehicleTypes.PowerUnits, (0, lists_helper_1.extractIdentifiedObjects)(this.policyDefinition.vehicleTypes.powerUnitTypes, powerUnitIds));
739
+ allowedVehicleMap.set(enum_1.VehicleTypes.Trailers, (0, lists_helper_1.extractIdentifiedObjects)(this.policyDefinition.vehicleTypes.trailerTypes, trailerIds));
740
+ return allowedVehicleMap;
741
+ }
712
742
  }
713
743
  exports.Policy = Policy;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "v1.2.0";
1
+ export declare const version = "v1.3.0";
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.2.0';
5
+ exports.version = 'v1.3.0';
package/package.json CHANGED
@@ -89,5 +89,5 @@
89
89
  ],
90
90
  "testEnvironment": "node"
91
91
  },
92
- "version": "v1.2.0"
92
+ "version": "v1.3.0"
93
93
  }