onroute-policy-engine 2.28.0 → 2.29.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.
@@ -6,6 +6,7 @@ export { OverloadCalculationDetailKind } from './overload-calculation-detail-kin
6
6
  export { PolicyCheckResultType, PolicyCheckId } from './policy-check';
7
7
  export { RelativePosition } from './relative-position';
8
8
  export { ValidationResultCode } from './validation-result-code';
9
+ export { ValidationResultId } from './validation-result-id';
9
10
  export { ValidationResultType } from './validation-result-type';
10
11
  export { VehicleCategory } from './vehicle-category';
11
12
  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.VehicleCategory = exports.ValidationResultType = exports.ValidationResultCode = exports.RelativePosition = exports.PolicyCheckId = exports.PolicyCheckResultType = exports.OverloadCalculationDetailKind = exports.PermitAppInfo = exports.CostFacts = exports.PolicyFacts = exports.CustomOperator = exports.AccessoryVehicleType = void 0;
3
+ exports.VehicleTypes = exports.VehicleCategory = exports.ValidationResultType = exports.ValidationResultId = exports.ValidationResultCode = exports.RelativePosition = exports.PolicyCheckId = exports.PolicyCheckResultType = exports.OverloadCalculationDetailKind = exports.PermitAppInfo = exports.CostFacts = exports.PolicyFacts = exports.CustomOperator = 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 custom_operator_1 = require("./custom-operator");
@@ -19,6 +19,8 @@ var relative_position_1 = require("./relative-position");
19
19
  Object.defineProperty(exports, "RelativePosition", { enumerable: true, get: function () { return relative_position_1.RelativePosition; } });
20
20
  var validation_result_code_1 = require("./validation-result-code");
21
21
  Object.defineProperty(exports, "ValidationResultCode", { enumerable: true, get: function () { return validation_result_code_1.ValidationResultCode; } });
22
+ var validation_result_id_1 = require("./validation-result-id");
23
+ Object.defineProperty(exports, "ValidationResultId", { enumerable: true, get: function () { return validation_result_id_1.ValidationResultId; } });
22
24
  var validation_result_type_1 = require("./validation-result-type");
23
25
  Object.defineProperty(exports, "ValidationResultType", { enumerable: true, get: function () { return validation_result_type_1.ValidationResultType; } });
24
26
  var vehicle_category_1 = require("./vehicle-category");
@@ -0,0 +1,4 @@
1
+ /** Identifies validation results that require specific consumer processing. */
2
+ export declare enum ValidationResultId {
3
+ AxleWeightSpacing = "axle-weight-spacing"
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidationResultId = void 0;
4
+ /** Identifies validation results that require specific consumer processing. */
5
+ var ValidationResultId;
6
+ (function (ValidationResultId) {
7
+ ValidationResultId["AxleWeightSpacing"] = "axle-weight-spacing";
8
+ })(ValidationResultId || (exports.ValidationResultId = ValidationResultId = {}));
@@ -1,5 +1,17 @@
1
- import { Engine } from 'json-rules-engine';
1
+ import { Engine, EngineResult, Event } from 'json-rules-engine';
2
2
  import { Policy } from 'onroute-policy-engine';
3
+ /** This returns the "Event", eg the axleCalcViolations event, in the _current-config.json. Helps
4
+ * identify an object like this from the JSON and return it for in-memory modification
5
+ *
6
+ * This is the structure of the object we retrieve with this function
7
+ * "conditions": {
8
+ * "not": {
9
+ * "fact": "axleCalcViolations",
10
+ * "operator": "isEmptyArray",
11
+ * "value": true
12
+ * }
13
+ */
14
+ export declare function getSuccessfulEventByFact(engineResult: EngineResult, fact: string): Event | undefined;
3
15
  /**
4
16
  * Creates a json-rules-engine Engine object for each permit type specified in
5
17
  * the policy definition, added to a Map. All rules specific to each permit type
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSuccessfulEventByFact = getSuccessfulEventByFact;
3
4
  exports.getRulesEngines = getRulesEngines;
4
5
  const json_rules_engine_1 = require("json-rules-engine");
5
6
  const custom_operators_1 = require("../rule-operator/custom-operators");
@@ -19,6 +20,23 @@ function getEngine(policyDefinition) {
19
20
  policyDefinition.commonRules.forEach((r) => engine.addRule(r));
20
21
  return engine;
21
22
  }
23
+ /** This returns the "Event", eg the axleCalcViolations event, in the _current-config.json. Helps
24
+ * identify an object like this from the JSON and return it for in-memory modification
25
+ *
26
+ * This is the structure of the object we retrieve with this function
27
+ * "conditions": {
28
+ * "not": {
29
+ * "fact": "axleCalcViolations",
30
+ * "operator": "isEmptyArray",
31
+ * "value": true
32
+ * }
33
+ */
34
+ function getSuccessfulEventByFact(engineResult, fact) {
35
+ var _a;
36
+ return (_a = engineResult.results.find(({ conditions }) => 'not' in conditions &&
37
+ 'fact' in conditions.not &&
38
+ conditions.not.fact === fact)) === null || _a === void 0 ? void 0 : _a.event;
39
+ }
22
40
  /**
23
41
  * Creates a json-rules-engine Engine object for each permit type specified in
24
42
  * the policy definition, added to a Map. All rules specific to each permit type
@@ -78,6 +78,10 @@ class Policy {
78
78
  (0, facts_helper_1.addRuntimeFacts)(engine, this);
79
79
  // Run the json-rules-engine against the permit facts
80
80
  const engineResult = await engine.run(permit);
81
+ const axleCalculationEvent = (0, rules_engine_helper_1.getSuccessfulEventByFact)(engineResult, enum_1.PolicyFacts.AxleCalcViolations);
82
+ if (axleCalculationEvent === null || axleCalculationEvent === void 0 ? void 0 : axleCalculationEvent.params) {
83
+ axleCalculationEvent.params.id = enum_1.ValidationResultId.AxleWeightSpacing;
84
+ }
81
85
  // Wrap the json-rules-engine result in a ValidationResult object
82
86
  const validationResults = new validation_results_1.ValidationResults(engineResult);
83
87
  const shouldIncludeAxleCalculationResults = permit.permitType === 'STOW' &&
@@ -15,6 +15,8 @@ export declare class ValidationResult {
15
15
  type: string;
16
16
  code: string;
17
17
  message: string;
18
+ /** Stable identifier for validation classes requiring specific processing. */
19
+ id?: string;
18
20
  fieldReference?: string;
19
21
  cost?: number;
20
22
  details?: Array<string>;
@@ -36,15 +36,16 @@ class ValidationResults {
36
36
  this.cost = [];
37
37
  if (engineResult) {
38
38
  engineResult.events.forEach((e) => {
39
- var _a, _b, _c, _d, _e;
40
- var _f, _g, _h;
41
- const message = (_f = (_a = e.params) === null || _a === void 0 ? void 0 : _a.message) !== null && _f !== void 0 ? _f : `Unknown message: params=${JSON.stringify(e.params)}`;
42
- const code = (_g = (_b = e.params) === null || _b === void 0 ? void 0 : _b.code) !== null && _g !== void 0 ? _g : validation_result_code_1.ValidationResultCode.GeneralResult;
43
- const type = (_h = e.type) !== null && _h !== void 0 ? _h : validation_result_type_1.ValidationResultType.Violation.toString();
39
+ var _a, _b, _c, _d, _e, _f;
40
+ var _g, _h, _j;
41
+ const message = (_g = (_a = e.params) === null || _a === void 0 ? void 0 : _a.message) !== null && _g !== void 0 ? _g : `Unknown message: params=${JSON.stringify(e.params)}`;
42
+ const code = (_h = (_b = e.params) === null || _b === void 0 ? void 0 : _b.code) !== null && _h !== void 0 ? _h : validation_result_code_1.ValidationResultCode.GeneralResult;
43
+ const type = (_j = e.type) !== null && _j !== void 0 ? _j : validation_result_type_1.ValidationResultType.Violation.toString();
44
44
  const result = new validation_result_1.ValidationResult(type, code, message);
45
- result.fieldReference = (_c = e.params) === null || _c === void 0 ? void 0 : _c.fieldReference;
46
- result.cost = (_d = e.params) === null || _d === void 0 ? void 0 : _d.cost;
47
- result.details = (_e = e.params) === null || _e === void 0 ? void 0 : _e.details;
45
+ result.id = (_c = e.params) === null || _c === void 0 ? void 0 : _c.id;
46
+ result.fieldReference = (_d = e.params) === null || _d === void 0 ? void 0 : _d.fieldReference;
47
+ result.cost = (_e = e.params) === null || _e === void 0 ? void 0 : _e.cost;
48
+ result.details = (_f = e.params) === null || _f === void 0 ? void 0 : _f.details;
48
49
  switch (type) {
49
50
  case validation_result_type_1.ValidationResultType.Violation:
50
51
  this.violations.push(result);
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "v2.28.0";
1
+ export declare const version = "v2.29.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 = 'v2.28.0';
5
+ exports.version = 'v2.29.0';
package/package.json CHANGED
@@ -91,5 +91,5 @@
91
91
  ],
92
92
  "testEnvironment": "node"
93
93
  },
94
- "version": "v2.28.0"
94
+ "version": "v2.29.0"
95
95
  }