onroute-policy-engine 2.1.0 → 2.1.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.
|
@@ -1,4 +1,46 @@
|
|
|
1
1
|
import { Policy } from 'onroute-policy-engine';
|
|
2
2
|
import { AxleConfiguration } from 'onroute-policy-engine/types';
|
|
3
|
+
/**
|
|
4
|
+
* Helper function to generate a vehicle display code based on the vehicle configuration and axle configuration.
|
|
5
|
+
*
|
|
6
|
+
* This function determines whether to generate a standard display code (for known vehicle types with
|
|
7
|
+
* configured display codes) or a universal display code (for complex or unknown configurations).
|
|
8
|
+
*
|
|
9
|
+
* @param policy The Policy instance containing vehicle definitions and display code defaults.
|
|
10
|
+
* @param configuration Array of vehicle type identifiers representing the vehicle configuration.
|
|
11
|
+
* The first element should be a power unit type, followed by trailer types.
|
|
12
|
+
* @param axleConfiguration Array of axle configurations corresponding to each vehicle in the configuration.
|
|
13
|
+
* Each axle configuration contains details like number of axles, spacing, etc.
|
|
14
|
+
* @returns A string representing the vehicle display code, or an empty string if the configuration is empty.
|
|
15
|
+
*
|
|
16
|
+
* @throws {Error} If vehicleDisplayCodeDefaults is not configured in the policy definition.
|
|
17
|
+
*/
|
|
3
18
|
export declare function getVehicleDisplayCodeHelper(policy: Policy, configuration: Array<string>, axleConfiguration: Array<AxleConfiguration>): string;
|
|
19
|
+
/**
|
|
20
|
+
* Generates a universal display code for vehicle configurations that cannot use the standard display code format.
|
|
21
|
+
*
|
|
22
|
+
* Universal display codes are used when:
|
|
23
|
+
* - Vehicle types are unknown or don't have configured display codes
|
|
24
|
+
* - Axle configurations exceed the maximum standard axle count
|
|
25
|
+
* - Vehicle configuration doesn't match the expected pattern
|
|
26
|
+
*
|
|
27
|
+
* The universal format uses generic symbols and spacing indicators to represent the axle configuration
|
|
28
|
+
* in a standardized way that can handle complex or unusual vehicle setups.
|
|
29
|
+
*
|
|
30
|
+
* @param policy The Policy instance containing display code defaults configuration.
|
|
31
|
+
* @param axleConfiguration Array of axle configurations representing the vehicle's axle setup.
|
|
32
|
+
* Each configuration contains details like number of axles, spacing, etc.
|
|
33
|
+
* @returns A string representing the universal vehicle display code, or an empty string if the axle configuration is empty.
|
|
34
|
+
*
|
|
35
|
+
* @throws {Error} If vehicleDisplayCodeDefaults is not configured in the policy definition.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // For a complex axle configuration
|
|
39
|
+
* const code = getUniversalDisplayCode(policy, [
|
|
40
|
+
* { numberOfAxles: 2, interaxleSpacing: 1.8, ... },
|
|
41
|
+
* { numberOfAxles: 3, interaxleSpacing: 4.2, ... },
|
|
42
|
+
* { numberOfAxles: 5, interaxleSpacing: 3.0, ... } // Exceeds standard threshold
|
|
43
|
+
* ]);
|
|
44
|
+
* // Returns something like "U2U1MU3U2MU5+U3" where U represents universal axle codes
|
|
45
|
+
*/
|
|
4
46
|
export declare function getUniversalDisplayCode(policy: Policy, axleConfiguration: Array<AxleConfiguration>): string;
|
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getVehicleDisplayCodeHelper = getVehicleDisplayCodeHelper;
|
|
4
4
|
exports.getUniversalDisplayCode = getUniversalDisplayCode;
|
|
5
|
+
/**
|
|
6
|
+
* Helper function to generate a vehicle display code based on the vehicle configuration and axle configuration.
|
|
7
|
+
*
|
|
8
|
+
* This function determines whether to generate a standard display code (for known vehicle types with
|
|
9
|
+
* configured display codes) or a universal display code (for complex or unknown configurations).
|
|
10
|
+
*
|
|
11
|
+
* @param policy The Policy instance containing vehicle definitions and display code defaults.
|
|
12
|
+
* @param configuration Array of vehicle type identifiers representing the vehicle configuration.
|
|
13
|
+
* The first element should be a power unit type, followed by trailer types.
|
|
14
|
+
* @param axleConfiguration Array of axle configurations corresponding to each vehicle in the configuration.
|
|
15
|
+
* Each axle configuration contains details like number of axles, spacing, etc.
|
|
16
|
+
* @returns A string representing the vehicle display code, or an empty string if the configuration is empty.
|
|
17
|
+
*
|
|
18
|
+
* @throws {Error} If vehicleDisplayCodeDefaults is not configured in the policy definition.
|
|
19
|
+
*/
|
|
5
20
|
function getVehicleDisplayCodeHelper(policy, configuration, axleConfiguration) {
|
|
6
21
|
if (!policy.policyDefinition.vehicleDisplayCodeDefaults) {
|
|
7
22
|
throw new Error('Unable to construct vehicle display code; missing vehicleDisplayCodeDefaults in policy configuration');
|
|
@@ -65,6 +80,33 @@ function getVehicleDisplayCodeHelper(policy, configuration, axleConfiguration) {
|
|
|
65
80
|
return getUniversalDisplayCode(policy, axleConfiguration);
|
|
66
81
|
}
|
|
67
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Generates a universal display code for vehicle configurations that cannot use the standard display code format.
|
|
85
|
+
*
|
|
86
|
+
* Universal display codes are used when:
|
|
87
|
+
* - Vehicle types are unknown or don't have configured display codes
|
|
88
|
+
* - Axle configurations exceed the maximum standard axle count
|
|
89
|
+
* - Vehicle configuration doesn't match the expected pattern
|
|
90
|
+
*
|
|
91
|
+
* The universal format uses generic symbols and spacing indicators to represent the axle configuration
|
|
92
|
+
* in a standardized way that can handle complex or unusual vehicle setups.
|
|
93
|
+
*
|
|
94
|
+
* @param policy The Policy instance containing display code defaults configuration.
|
|
95
|
+
* @param axleConfiguration Array of axle configurations representing the vehicle's axle setup.
|
|
96
|
+
* Each configuration contains details like number of axles, spacing, etc.
|
|
97
|
+
* @returns A string representing the universal vehicle display code, or an empty string if the axle configuration is empty.
|
|
98
|
+
*
|
|
99
|
+
* @throws {Error} If vehicleDisplayCodeDefaults is not configured in the policy definition.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* // For a complex axle configuration
|
|
103
|
+
* const code = getUniversalDisplayCode(policy, [
|
|
104
|
+
* { numberOfAxles: 2, interaxleSpacing: 1.8, ... },
|
|
105
|
+
* { numberOfAxles: 3, interaxleSpacing: 4.2, ... },
|
|
106
|
+
* { numberOfAxles: 5, interaxleSpacing: 3.0, ... } // Exceeds standard threshold
|
|
107
|
+
* ]);
|
|
108
|
+
* // Returns something like "U2U1MU3U2MU5+U3" where U represents universal axle codes
|
|
109
|
+
*/
|
|
68
110
|
function getUniversalDisplayCode(policy, axleConfiguration) {
|
|
69
111
|
const defs = policy.policyDefinition.vehicleDisplayCodeDefaults;
|
|
70
112
|
if (!defs) {
|
|
@@ -93,7 +135,7 @@ function getUniversalDisplayCode(policy, axleConfiguration) {
|
|
|
93
135
|
displayCodeTokens.push(defs.spacingUniversalDefault);
|
|
94
136
|
}
|
|
95
137
|
}
|
|
96
|
-
if (a.numberOfAxles
|
|
138
|
+
if (a.numberOfAxles > defs.thresholdAxlesUniversal) {
|
|
97
139
|
// The number of axles in this axle unit is above the threshold
|
|
98
140
|
// for the number of axles that can be represented by the simple
|
|
99
141
|
// universal formula
|
|
@@ -140,6 +182,36 @@ function getUniversalDisplayCode(policy, axleConfiguration) {
|
|
|
140
182
|
});
|
|
141
183
|
return displayCodeTokens.join('');
|
|
142
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Determines whether a standard display code can be generated for the given vehicle configuration.
|
|
187
|
+
*
|
|
188
|
+
* A standard display code can be created when:
|
|
189
|
+
* - All vehicle types are known and have configured display codes
|
|
190
|
+
* - The power unit has all required display code properties (prefix, steer axle, drive axle)
|
|
191
|
+
* - All trailers have display codes (unless they're marked to ignore for axle calculation)
|
|
192
|
+
* - No axle configuration exceeds the maximum standard axle count
|
|
193
|
+
* - The number of axle configurations matches the number of non-ignorable vehicles plus one
|
|
194
|
+
*
|
|
195
|
+
* @param policy The Policy instance containing vehicle definitions and display code defaults.
|
|
196
|
+
* @param configuration Array of vehicle type identifiers representing the vehicle configuration.
|
|
197
|
+
* The first element should be a power unit type, followed by trailer types.
|
|
198
|
+
* @param axleConfiguration Array of axle configurations corresponding to each vehicle in the configuration.
|
|
199
|
+
* Each axle configuration contains details like number of axles, spacing, etc.
|
|
200
|
+
* @returns True if a standard display code can be generated, false if a universal display code is required.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* // Returns true for a standard truck-tractor with semi-trailer
|
|
204
|
+
* canCreateStandardCode(policy, ['TRKTRAC', 'SEMI'], [
|
|
205
|
+
* { numberOfAxles: 2, ... }, // Steer axle
|
|
206
|
+
* { numberOfAxles: 3, ... }, // Drive axle
|
|
207
|
+
* { numberOfAxles: 3, ... } // Trailer axle
|
|
208
|
+
* ]);
|
|
209
|
+
*
|
|
210
|
+
* // Returns false for unknown vehicle types or complex configurations
|
|
211
|
+
* canCreateStandardCode(policy, ['UNKNOWN'], [
|
|
212
|
+
* { numberOfAxles: 10, ... } // Exceeds standard threshold
|
|
213
|
+
* ]);
|
|
214
|
+
*/
|
|
143
215
|
function canCreateStandardCode(policy, configuration, axleConfiguration) {
|
|
144
216
|
var _a;
|
|
145
217
|
// Check that all of the vehicle types are known,
|
package/dist/policy-engine.d.ts
CHANGED
|
@@ -245,5 +245,30 @@ export declare class Policy {
|
|
|
245
245
|
* none are configured
|
|
246
246
|
*/
|
|
247
247
|
getStandardTireSizes(): Array<StandardTireSize>;
|
|
248
|
+
/**
|
|
249
|
+
* Generates a vehicle display code based on the vehicle configuration and axle configuration.
|
|
250
|
+
*
|
|
251
|
+
* The display code is a string representation that describes the vehicle configuration
|
|
252
|
+
* in a standardized format. It can generate either a standard display code (for known
|
|
253
|
+
* vehicle types with configured display codes) or a universal display code (for complex
|
|
254
|
+
* or unknown configurations).
|
|
255
|
+
*
|
|
256
|
+
* @param configuration Array of vehicle type identifiers representing the vehicle configuration.
|
|
257
|
+
* The first element should be a power unit type, followed by trailer types.
|
|
258
|
+
* @param axleConfiguration Array of axle configurations corresponding to each vehicle in the configuration.
|
|
259
|
+
* Each axle configuration contains details like number of axles, spacing, etc.
|
|
260
|
+
* @returns A string representing the vehicle display code, or an empty string if the configuration is empty.
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* // For a truck-tractor with 2-axle steer, 3-axle drive, and a 3-axle semi-trailer
|
|
264
|
+
* const code = policy.getVehicleDisplayCode(['TRKTRAC'], [
|
|
265
|
+
* { numberOfAxles: 2, axleSpread: 1.8, ... },
|
|
266
|
+
* { numberOfAxles: 3, axleSpread: 4.2, ... },
|
|
267
|
+
* { numberOfAxles: 3, axleSpread: 3.0, ... }
|
|
268
|
+
* ]);
|
|
269
|
+
* // Returns something like "TT2S13D23T3"
|
|
270
|
+
*
|
|
271
|
+
* @throws {Error} If vehicleDisplayCodeDefaults is not configured in the policy definition.
|
|
272
|
+
*/
|
|
248
273
|
getVehicleDisplayCode(configuration: Array<string>, axleConfiguration: Array<AxleConfiguration>): string;
|
|
249
274
|
}
|
package/dist/policy-engine.js
CHANGED
|
@@ -749,6 +749,31 @@ class Policy {
|
|
|
749
749
|
return new Array();
|
|
750
750
|
}
|
|
751
751
|
}
|
|
752
|
+
/**
|
|
753
|
+
* Generates a vehicle display code based on the vehicle configuration and axle configuration.
|
|
754
|
+
*
|
|
755
|
+
* The display code is a string representation that describes the vehicle configuration
|
|
756
|
+
* in a standardized format. It can generate either a standard display code (for known
|
|
757
|
+
* vehicle types with configured display codes) or a universal display code (for complex
|
|
758
|
+
* or unknown configurations).
|
|
759
|
+
*
|
|
760
|
+
* @param configuration Array of vehicle type identifiers representing the vehicle configuration.
|
|
761
|
+
* The first element should be a power unit type, followed by trailer types.
|
|
762
|
+
* @param axleConfiguration Array of axle configurations corresponding to each vehicle in the configuration.
|
|
763
|
+
* Each axle configuration contains details like number of axles, spacing, etc.
|
|
764
|
+
* @returns A string representing the vehicle display code, or an empty string if the configuration is empty.
|
|
765
|
+
*
|
|
766
|
+
* @example
|
|
767
|
+
* // For a truck-tractor with 2-axle steer, 3-axle drive, and a 3-axle semi-trailer
|
|
768
|
+
* const code = policy.getVehicleDisplayCode(['TRKTRAC'], [
|
|
769
|
+
* { numberOfAxles: 2, axleSpread: 1.8, ... },
|
|
770
|
+
* { numberOfAxles: 3, axleSpread: 4.2, ... },
|
|
771
|
+
* { numberOfAxles: 3, axleSpread: 3.0, ... }
|
|
772
|
+
* ]);
|
|
773
|
+
* // Returns something like "TT2S13D23T3"
|
|
774
|
+
*
|
|
775
|
+
* @throws {Error} If vehicleDisplayCodeDefaults is not configured in the policy definition.
|
|
776
|
+
*/
|
|
752
777
|
getVehicleDisplayCode(configuration, axleConfiguration) {
|
|
753
778
|
return (0, display_code_helper_1.getVehicleDisplayCodeHelper)(this, configuration, axleConfiguration);
|
|
754
779
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "v2.1.
|
|
1
|
+
export declare const version = "v2.1.1";
|
package/dist/version.js
CHANGED
package/eslint.config.mjs
CHANGED
|
@@ -15,7 +15,7 @@ const compat = new FlatCompat({
|
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
export default [{
|
|
18
|
-
ignores: ["**/.eslintrc.cjs", "**/node_modules/", "**/dist/", "**/.eslintrc.cjs"],
|
|
18
|
+
ignores: ["**/.eslintrc.cjs", "**/node_modules/", "**/dist/", "**/.eslintrc.cjs,", "src/_examples/usage"],
|
|
19
19
|
}, ...compat.extends("eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"), {
|
|
20
20
|
plugins: {
|
|
21
21
|
"@typescript-eslint": typescriptEslint,
|
package/package.json
CHANGED