onroute-policy-engine 2.0.1 → 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.
- package/dist/helper/display-code-helper.d.ts +46 -0
- package/dist/helper/display-code-helper.js +255 -0
- package/dist/helper/facts.helper.js +0 -1
- package/dist/policy-engine.d.ts +26 -0
- package/dist/policy-engine.js +29 -0
- package/dist/types/display-code-defaults.d.ts +18 -0
- package/dist/types/display-code-defaults.js +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/policy-definition.d.ts +2 -1
- package/dist/types/vehicle-type.d.ts +5 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/eslint.config.mjs +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Policy } from 'onroute-policy-engine';
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
46
|
+
export declare function getUniversalDisplayCode(policy: Policy, axleConfiguration: Array<AxleConfiguration>): string;
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVehicleDisplayCodeHelper = getVehicleDisplayCodeHelper;
|
|
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
|
+
*/
|
|
20
|
+
function getVehicleDisplayCodeHelper(policy, configuration, axleConfiguration) {
|
|
21
|
+
if (!policy.policyDefinition.vehicleDisplayCodeDefaults) {
|
|
22
|
+
throw new Error('Unable to construct vehicle display code; missing vehicleDisplayCodeDefaults in policy configuration');
|
|
23
|
+
}
|
|
24
|
+
// Empty configuration, empty display code
|
|
25
|
+
if (configuration.length === 0) {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
if (canCreateStandardCode(policy, configuration, axleConfiguration)) {
|
|
29
|
+
const defs = policy.policyDefinition.vehicleDisplayCodeDefaults;
|
|
30
|
+
const displayCodeTokens = [];
|
|
31
|
+
displayCodeTokens.push(defs.prefixStandard || '');
|
|
32
|
+
const powerUnit = policy.getPowerUnitDefinition(configuration[0]);
|
|
33
|
+
// Add the power unit display code, e.g. TT
|
|
34
|
+
displayCodeTokens.push((powerUnit === null || powerUnit === void 0 ? void 0 : powerUnit.displayCodePrefix) || '');
|
|
35
|
+
// Add the number of axles in the steer axle unit
|
|
36
|
+
displayCodeTokens.push(axleConfiguration[0].numberOfAxles.toString());
|
|
37
|
+
// Add the power unit steer axle display code, e.g. S
|
|
38
|
+
displayCodeTokens.push((powerUnit === null || powerUnit === void 0 ? void 0 : powerUnit.displayCodeSteerAxle) || '');
|
|
39
|
+
// Add the steer axle unit index label (first axle unit)
|
|
40
|
+
displayCodeTokens.push('1');
|
|
41
|
+
// Add the padding if necessary. Padding is added once for
|
|
42
|
+
// every axle above 1 in the steer axle unit.
|
|
43
|
+
displayCodeTokens.push(defs.paddingStandard.repeat(axleConfiguration[0].numberOfAxles - 1));
|
|
44
|
+
// Add the number of axles in the drive axle unit
|
|
45
|
+
displayCodeTokens.push(axleConfiguration[1].numberOfAxles.toString());
|
|
46
|
+
// Add the power unit drive axle display code, e.g. D
|
|
47
|
+
displayCodeTokens.push((powerUnit === null || powerUnit === void 0 ? void 0 : powerUnit.displayCodeDriveAxle) || '');
|
|
48
|
+
// Add the drive axle unit index label (second axle unit)
|
|
49
|
+
displayCodeTokens.push('2');
|
|
50
|
+
// Add the padding if necessary. Padding is added once for
|
|
51
|
+
// every axle above 1 in the drive axle unit.
|
|
52
|
+
if (axleConfiguration.length > 2) {
|
|
53
|
+
displayCodeTokens.push(defs.paddingStandard.repeat(axleConfiguration[1].numberOfAxles - 1));
|
|
54
|
+
}
|
|
55
|
+
let currentAxleIndex = 2;
|
|
56
|
+
configuration.slice(1).forEach((v) => {
|
|
57
|
+
const trailer = policy.getTrailerDefinition(v);
|
|
58
|
+
if (!(trailer === null || trailer === void 0 ? void 0 : trailer.ignoreForAxleCalculation)) {
|
|
59
|
+
// Add the number of axles of the trailer
|
|
60
|
+
displayCodeTokens.push(axleConfiguration[currentAxleIndex].numberOfAxles.toString());
|
|
61
|
+
// Add the trailer display code, e.g. T
|
|
62
|
+
displayCodeTokens.push((trailer === null || trailer === void 0 ? void 0 : trailer.displayCode) || '');
|
|
63
|
+
// Add the axle unit index label, with prefix if axle unit
|
|
64
|
+
// number is more than a single digit, e.g. '.10'
|
|
65
|
+
if (currentAxleIndex >= 9) {
|
|
66
|
+
displayCodeTokens.push(defs.multiDigitPrefix);
|
|
67
|
+
}
|
|
68
|
+
displayCodeTokens.push((currentAxleIndex + 1).toString());
|
|
69
|
+
// Add the padding if necessary. Padding is added once for
|
|
70
|
+
// every axle above 1 in the drive axle unit.
|
|
71
|
+
if (axleConfiguration.length > currentAxleIndex + 1) {
|
|
72
|
+
displayCodeTokens.push(defs.paddingStandard.repeat(axleConfiguration[currentAxleIndex].numberOfAxles - 1));
|
|
73
|
+
}
|
|
74
|
+
currentAxleIndex++;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return displayCodeTokens.join('');
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
return getUniversalDisplayCode(policy, axleConfiguration);
|
|
81
|
+
}
|
|
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
|
+
*/
|
|
110
|
+
function getUniversalDisplayCode(policy, axleConfiguration) {
|
|
111
|
+
const defs = policy.policyDefinition.vehicleDisplayCodeDefaults;
|
|
112
|
+
if (!defs) {
|
|
113
|
+
throw new Error('Unable to construct vehicle display code; missing vehicleDisplayCodeDefaults in policy configuration');
|
|
114
|
+
}
|
|
115
|
+
// Empty axle configuration, empty display code
|
|
116
|
+
if (axleConfiguration.length === 0) {
|
|
117
|
+
return '';
|
|
118
|
+
}
|
|
119
|
+
const displayCodeTokens = [];
|
|
120
|
+
displayCodeTokens.push(defs.prefixUniversal || '');
|
|
121
|
+
let currentAxleIndex = 0;
|
|
122
|
+
axleConfiguration.forEach((a) => {
|
|
123
|
+
if (currentAxleIndex > 0) {
|
|
124
|
+
// Add the universal spacing glyph, e.g. 'MU' , if this is
|
|
125
|
+
// not the first axle unit
|
|
126
|
+
if (a.interaxleSpacing &&
|
|
127
|
+
a.interaxleSpacing <= defs.spacingUniversalSmallMax) {
|
|
128
|
+
displayCodeTokens.push(defs.spacingUniversalSmall);
|
|
129
|
+
}
|
|
130
|
+
else if (a.interaxleSpacing &&
|
|
131
|
+
a.interaxleSpacing >= defs.spacingUniversalLargeMin) {
|
|
132
|
+
displayCodeTokens.push(defs.spacingUniversalLarge);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
displayCodeTokens.push(defs.spacingUniversalDefault);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (a.numberOfAxles > defs.thresholdAxlesUniversal) {
|
|
139
|
+
// The number of axles in this axle unit is above the threshold
|
|
140
|
+
// for the number of axles that can be represented by the simple
|
|
141
|
+
// universal formula
|
|
142
|
+
displayCodeTokens.push(defs.thresholdAxlesUniversal.toString());
|
|
143
|
+
// Add the over axles code, e.g. '+'
|
|
144
|
+
displayCodeTokens.push(defs.overAxlesCodeUniversal);
|
|
145
|
+
// Add the universal axle code, e.g. 'U'
|
|
146
|
+
displayCodeTokens.push(defs.universalAxleCode);
|
|
147
|
+
// Add the axle unit index label, with prefix if axle unit
|
|
148
|
+
// number is more than a single digit, e.g. '.10'
|
|
149
|
+
if (currentAxleIndex >= 9) {
|
|
150
|
+
displayCodeTokens.push(defs.multiDigitPrefix);
|
|
151
|
+
}
|
|
152
|
+
displayCodeTokens.push((currentAxleIndex + 1).toString());
|
|
153
|
+
// Add the padding. Padding is added once for every axle
|
|
154
|
+
// above 1, up to the universal threshold.
|
|
155
|
+
displayCodeTokens.push(defs.paddingUniversal.repeat(defs.thresholdAxlesUniversal - 1));
|
|
156
|
+
// Add the extra axle unit glyps, e.g. 'XU', for
|
|
157
|
+
// each axle unit above the universal threshold
|
|
158
|
+
for (let i = defs.thresholdAxlesUniversal + 1; i < a.numberOfAxles; i++) {
|
|
159
|
+
displayCodeTokens.push(defs.extraAxleUniversal);
|
|
160
|
+
}
|
|
161
|
+
// Add the end axle unit glyph, e.g. 'EU'
|
|
162
|
+
displayCodeTokens.push(defs.endAxleUniversal);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
// Add the number of axles in the axle unit, e.g. '2'
|
|
166
|
+
displayCodeTokens.push(a.numberOfAxles.toString());
|
|
167
|
+
// Add the universal axle code, e.g. 'U'
|
|
168
|
+
displayCodeTokens.push(defs.universalAxleCode);
|
|
169
|
+
// Add the axle unit index label, with prefix if axle unit
|
|
170
|
+
// number is more than a single digit, e.g. '.10'
|
|
171
|
+
if (currentAxleIndex >= 9) {
|
|
172
|
+
displayCodeTokens.push(defs.multiDigitPrefix);
|
|
173
|
+
}
|
|
174
|
+
displayCodeTokens.push((currentAxleIndex + 1).toString());
|
|
175
|
+
// Add the padding if necessary. Padding is added once for
|
|
176
|
+
// every axle above 1 in the axle unit.
|
|
177
|
+
if (axleConfiguration.length > currentAxleIndex + 1) {
|
|
178
|
+
displayCodeTokens.push(defs.paddingUniversal.repeat(axleConfiguration[currentAxleIndex].numberOfAxles - 1));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
currentAxleIndex++;
|
|
182
|
+
});
|
|
183
|
+
return displayCodeTokens.join('');
|
|
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
|
+
*/
|
|
215
|
+
function canCreateStandardCode(policy, configuration, axleConfiguration) {
|
|
216
|
+
var _a;
|
|
217
|
+
// Check that all of the vehicle types are known,
|
|
218
|
+
// and that all have display codes configured
|
|
219
|
+
const powerUnit = policy.getPowerUnitDefinition(configuration[0]);
|
|
220
|
+
if (!powerUnit ||
|
|
221
|
+
!powerUnit.displayCodePrefix ||
|
|
222
|
+
!powerUnit.displayCodeSteerAxle ||
|
|
223
|
+
!powerUnit.displayCodeDriveAxle) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
// Check all the trailers (if there are any)
|
|
227
|
+
for (let i = 1; i < configuration.length; i++) {
|
|
228
|
+
const trailer = policy.getTrailerDefinition(configuration[i]);
|
|
229
|
+
if (!trailer ||
|
|
230
|
+
(!trailer.displayCode && !trailer.ignoreForAxleCalculation)) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// Check that none of the axles exceed the max standard
|
|
235
|
+
const maxAxles = ((_a = policy.policyDefinition.vehicleDisplayCodeDefaults) === null || _a === void 0 ? void 0 : _a.maxAxlesStandard) || 0;
|
|
236
|
+
for (let j = 0; j < axleConfiguration.length; j++) {
|
|
237
|
+
if (axleConfiguration[j].numberOfAxles > maxAxles) {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// Count all non-ignorable vehicles
|
|
242
|
+
const vehicleCount = configuration.filter((v) => {
|
|
243
|
+
const vehicle = policy.getVehicleDefinition(v);
|
|
244
|
+
if (vehicle && !vehicle.ignoreForAxleCalculation) {
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
return false;
|
|
248
|
+
}).length;
|
|
249
|
+
// The vehicle list does not correspond with the number of non-
|
|
250
|
+
// ignorable axles, so the universal diagram is the only option
|
|
251
|
+
if (axleConfiguration.length !== vehicleCount + 1) {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
@@ -94,7 +94,6 @@ function addRuntimeFacts(engine, policy) {
|
|
|
94
94
|
const dateFrom = (0, dayjs_1.default)(dateFromStr, enum_1.PermitAppInfo.PermitDateFormat);
|
|
95
95
|
const dateTo = (0, dayjs_1.default)(dateToStr, enum_1.PermitAppInfo.PermitDateFormat);
|
|
96
96
|
const daysBetween = dateTo.diff(dateFrom, 'day');
|
|
97
|
-
console.log(`Calculated daysBetween '${dateFromStr}' and '${dateToStr}' as '${daysBetween}'`);
|
|
98
97
|
return daysBetween;
|
|
99
98
|
});
|
|
100
99
|
/**
|
package/dist/policy-engine.d.ts
CHANGED
|
@@ -245,4 +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
|
+
*/
|
|
273
|
+
getVehicleDisplayCode(configuration: Array<string>, axleConfiguration: Array<AxleConfiguration>): string;
|
|
248
274
|
}
|
package/dist/policy-engine.js
CHANGED
|
@@ -19,6 +19,7 @@ const vehicles_helper_1 = require("./helper/vehicles.helper");
|
|
|
19
19
|
const conditions_helper_1 = require("./helper/conditions.helper");
|
|
20
20
|
const dimensions_helper_1 = require("./helper/dimensions.helper");
|
|
21
21
|
const dimensions_helper_2 = require("./helper/dimensions.helper");
|
|
22
|
+
const display_code_helper_1 = require("./helper/display-code-helper");
|
|
22
23
|
/** Class representing commercial vehicle policy. */
|
|
23
24
|
class Policy {
|
|
24
25
|
/**
|
|
@@ -748,5 +749,33 @@ class Policy {
|
|
|
748
749
|
return new Array();
|
|
749
750
|
}
|
|
750
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
|
+
*/
|
|
777
|
+
getVehicleDisplayCode(configuration, axleConfiguration) {
|
|
778
|
+
return (0, display_code_helper_1.getVehicleDisplayCodeHelper)(this, configuration, axleConfiguration);
|
|
779
|
+
}
|
|
751
780
|
}
|
|
752
781
|
exports.Policy = Policy;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type VehicleDisplayCodeDefaults = {
|
|
2
|
+
prefixStandard: string;
|
|
3
|
+
prefixUniversal: string;
|
|
4
|
+
paddingStandard: string;
|
|
5
|
+
paddingUniversal: string;
|
|
6
|
+
spacingUniversalDefault: string;
|
|
7
|
+
spacingUniversalSmall: string;
|
|
8
|
+
spacingUniversalLarge: string;
|
|
9
|
+
spacingUniversalSmallMax: number;
|
|
10
|
+
spacingUniversalLargeMin: number;
|
|
11
|
+
extraAxleUniversal: string;
|
|
12
|
+
endAxleUniversal: string;
|
|
13
|
+
maxAxlesStandard: number;
|
|
14
|
+
thresholdAxlesUniversal: number;
|
|
15
|
+
overAxlesCodeUniversal: string;
|
|
16
|
+
universalAxleCode: string;
|
|
17
|
+
multiDigitPrefix: string;
|
|
18
|
+
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { BridgeCalculationResult } from './bridge-calculation-result';
|
|
|
4
4
|
export { Commodity } from './commodity';
|
|
5
5
|
export { CostRule } from './cost-rule';
|
|
6
6
|
export { DimensionModifier, VehicleRelatives } from './dimension-modifier';
|
|
7
|
+
export { VehicleDisplayCodeDefaults } from './display-code-defaults';
|
|
7
8
|
export { PermitFacts } from './facts';
|
|
8
9
|
export { GeographicRegion } from './geographic-region';
|
|
9
10
|
export { IdentifiedObject } from './identified-object';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GeographicRegion, PermitType, DefaultWeightDimensions, VehicleTypes, Commodity, SizeDimension, VehicleCategories, RangeMatrix, BridgeCalculationConstants, PermitConditionDefinition, StandardTireSize } from 'onroute-policy-engine/types';
|
|
1
|
+
import { GeographicRegion, PermitType, DefaultWeightDimensions, VehicleTypes, Commodity, SizeDimension, VehicleCategories, RangeMatrix, BridgeCalculationConstants, PermitConditionDefinition, StandardTireSize, VehicleDisplayCodeDefaults } from 'onroute-policy-engine/types';
|
|
2
2
|
import { RuleProperties } from 'json-rules-engine';
|
|
3
3
|
export type PolicyDefinition = {
|
|
4
4
|
minPEVersion: string;
|
|
@@ -14,4 +14,5 @@ export type PolicyDefinition = {
|
|
|
14
14
|
bridgeCalculationConstants: BridgeCalculationConstants;
|
|
15
15
|
conditions?: Array<PermitConditionDefinition>;
|
|
16
16
|
standardTireSizes?: Array<StandardTireSize>;
|
|
17
|
+
vehicleDisplayCodeDefaults?: VehicleDisplayCodeDefaults;
|
|
17
18
|
};
|
|
@@ -3,15 +3,20 @@ export type VehicleType = IdentifiedObject & {
|
|
|
3
3
|
category: string;
|
|
4
4
|
defaultSizeDimensions?: SizeDimension;
|
|
5
5
|
ignoreForSizeDimensions?: boolean;
|
|
6
|
+
ignoreForAxleCalculation?: boolean;
|
|
6
7
|
isLcv?: boolean;
|
|
7
8
|
conditions?: Array<ConditionRequirement>;
|
|
8
9
|
additionalAxleSubType?: string;
|
|
9
10
|
};
|
|
10
11
|
export type PowerUnitType = VehicleType & {
|
|
11
12
|
defaultWeightDimensions?: Array<PowerUnitWeightDimension>;
|
|
13
|
+
displayCodePrefix?: string;
|
|
14
|
+
displayCodeSteerAxle?: string;
|
|
15
|
+
displayCodeDriveAxle?: string;
|
|
12
16
|
};
|
|
13
17
|
export type TrailerType = VehicleType & {
|
|
14
18
|
defaultWeightDimensions?: Array<TrailerWeightDimension>;
|
|
19
|
+
displayCode?: string;
|
|
15
20
|
};
|
|
16
21
|
export type VehicleTypes = {
|
|
17
22
|
powerUnitTypes: Array<PowerUnitType>;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "v2.
|
|
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