ocpp-messages 0.2.0 → 0.2.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/compile.js +87 -4
- package/package.json +1 -1
- package/v1.6/MeterValues.d.ts +76 -51
- package/v1.6/StopTransaction.d.ts +90 -63
package/compile.js
CHANGED
|
@@ -2,6 +2,85 @@
|
|
|
2
2
|
const { compileFromFile } = require("json-schema-to-typescript");
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Extract inline enum types with more than 3 values into named type aliases
|
|
7
|
+
* @param {string} ts - The generated TypeScript code
|
|
8
|
+
* @param {string} propertyName - The property name for generating type name
|
|
9
|
+
* @returns {string} - The transformed TypeScript code
|
|
10
|
+
*/
|
|
11
|
+
function extractLargeEnums(ts, propertyName) {
|
|
12
|
+
const extractedTypes = [];
|
|
13
|
+
const typeMap = new Map();
|
|
14
|
+
|
|
15
|
+
// Match inline union types - handles both single-line and multi-line formats
|
|
16
|
+
// Pattern matches:
|
|
17
|
+
// propertyName?: "value1" | "value2" ...;
|
|
18
|
+
// OR
|
|
19
|
+
// propertyName?:
|
|
20
|
+
// | "value1"
|
|
21
|
+
// | "value2" ...;
|
|
22
|
+
const enumPattern = /(\w+)\?:\s*\n?\s*((?:\|\s*)?(?:"[^"]+"\s*(?:\||;)\s*\n?\s*)*(?:"[^"]+"))\s*;/gs;
|
|
23
|
+
|
|
24
|
+
let transformed = ts;
|
|
25
|
+
let match;
|
|
26
|
+
const matches = [];
|
|
27
|
+
|
|
28
|
+
// Collect all matches first (to avoid issues with string replacement during iteration)
|
|
29
|
+
while ((match = enumPattern.exec(ts)) !== null) {
|
|
30
|
+
matches.push({
|
|
31
|
+
fullMatch: match[0],
|
|
32
|
+
propName: match[1],
|
|
33
|
+
enumValues: match[2]
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Process each match
|
|
38
|
+
for (const matchData of matches) {
|
|
39
|
+
const { fullMatch, propName, enumValues } = matchData;
|
|
40
|
+
|
|
41
|
+
// Extract all quoted values
|
|
42
|
+
const values = enumValues.match(/"[^"]+"/g);
|
|
43
|
+
if (values && values.length > 3) {
|
|
44
|
+
// Generate type name: capitalize first letter and add "EnumType" suffix
|
|
45
|
+
const typeName = propName.charAt(0).toUpperCase() + propName.slice(1) + "EnumType";
|
|
46
|
+
|
|
47
|
+
// Format the enum type nicely
|
|
48
|
+
const formattedEnum = values.map((v, i) =>
|
|
49
|
+
i === 0 ? `\n | ${v}` : ` | ${v}`
|
|
50
|
+
).join('\n');
|
|
51
|
+
|
|
52
|
+
// Store extracted type if not already added
|
|
53
|
+
if (!typeMap.has(typeName)) {
|
|
54
|
+
extractedTypes.push(`export type ${typeName} =${formattedEnum};`);
|
|
55
|
+
typeMap.set(typeName, true);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Replace inline enum with type reference
|
|
59
|
+
const replacement = `${propName}?: ${typeName};`;
|
|
60
|
+
transformed = transformed.replace(fullMatch, replacement);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// If we extracted any types, prepend them to the output
|
|
65
|
+
if (extractedTypes.length > 0) {
|
|
66
|
+
const lines = transformed.split('\n');
|
|
67
|
+
const headerEndIndex = lines.findIndex((line, i) => i > 0 && line.trim() === '' && lines[i-1].includes('*/'));
|
|
68
|
+
|
|
69
|
+
if (headerEndIndex !== -1) {
|
|
70
|
+
const header = lines.slice(0, headerEndIndex + 1).join('\n');
|
|
71
|
+
const rest = lines.slice(headerEndIndex + 1).join('\n');
|
|
72
|
+
transformed = header + '\n' + extractedTypes.join('\n\n') + '\n\n' + rest;
|
|
73
|
+
} else {
|
|
74
|
+
// Fallback: just prepend after first 6 lines
|
|
75
|
+
const header = lines.slice(0, 6).join('\n');
|
|
76
|
+
const rest = lines.slice(6).join('\n');
|
|
77
|
+
transformed = header + '\n\n' + extractedTypes.join('\n\n') + '\n\n' + rest;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return transformed;
|
|
82
|
+
}
|
|
83
|
+
|
|
5
84
|
// Compile v1.6 schemas
|
|
6
85
|
fs.readdir(__dirname + "/schema/v1.6", function (err, files) {
|
|
7
86
|
//handling error
|
|
@@ -11,9 +90,11 @@ fs.readdir(__dirname + "/schema/v1.6", function (err, files) {
|
|
|
11
90
|
//listing all files using forEach
|
|
12
91
|
files.forEach(function (file) {
|
|
13
92
|
// compile from file
|
|
14
|
-
compileFromFile(`${__dirname}/schema/v1.6/${file}`).then((ts) =>
|
|
15
|
-
|
|
16
|
-
|
|
93
|
+
compileFromFile(`${__dirname}/schema/v1.6/${file}`).then((ts) => {
|
|
94
|
+
// Extract large enums into named types
|
|
95
|
+
const transformedTs = extractLargeEnums(ts, file.replace(".json", ""));
|
|
96
|
+
fs.writeFileSync(`${__dirname}/v1.6/${file.replace(".json", ".d.ts")}`, transformedTs);
|
|
97
|
+
});
|
|
17
98
|
console.log(file);
|
|
18
99
|
});
|
|
19
100
|
});
|
|
@@ -47,7 +128,9 @@ fs.readdir(__dirname + "/schema/v2.0", function (err, files) {
|
|
|
47
128
|
compile(schema, baseName)
|
|
48
129
|
.then((ts) => {
|
|
49
130
|
// Replace any remaining URN-based interface names with clean names
|
|
50
|
-
|
|
131
|
+
let cleanedTs = ts.replace(/export interface Urn\w+/g, `export interface ${baseName}`);
|
|
132
|
+
// Extract large enums into named types
|
|
133
|
+
cleanedTs = extractLargeEnums(cleanedTs, baseName);
|
|
51
134
|
fs.writeFileSync(`${__dirname}/v2.0/${baseName}.d.ts`, cleanedTs);
|
|
52
135
|
})
|
|
53
136
|
.catch((err) => {
|
package/package.json
CHANGED
package/v1.6/MeterValues.d.ts
CHANGED
|
@@ -5,6 +5,77 @@
|
|
|
5
5
|
* and run json-schema-to-typescript to regenerate this file.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
export type ContextEnumType =
|
|
9
|
+
| "Interruption.Begin"
|
|
10
|
+
| "Interruption.End"
|
|
11
|
+
| "Sample.Clock"
|
|
12
|
+
| "Sample.Periodic"
|
|
13
|
+
| "Transaction.Begin"
|
|
14
|
+
| "Transaction.End"
|
|
15
|
+
| "Trigger"
|
|
16
|
+
| "Other";
|
|
17
|
+
|
|
18
|
+
export type MeasurandEnumType =
|
|
19
|
+
| "Energy.Active.Export.Register"
|
|
20
|
+
| "Energy.Active.Import.Register"
|
|
21
|
+
| "Energy.Reactive.Export.Register"
|
|
22
|
+
| "Energy.Reactive.Import.Register"
|
|
23
|
+
| "Energy.Active.Export.Interval"
|
|
24
|
+
| "Energy.Active.Import.Interval"
|
|
25
|
+
| "Energy.Reactive.Export.Interval"
|
|
26
|
+
| "Energy.Reactive.Import.Interval"
|
|
27
|
+
| "Power.Active.Export"
|
|
28
|
+
| "Power.Active.Import"
|
|
29
|
+
| "Power.Offered"
|
|
30
|
+
| "Power.Reactive.Export"
|
|
31
|
+
| "Power.Reactive.Import"
|
|
32
|
+
| "Power.Factor"
|
|
33
|
+
| "Current.Import"
|
|
34
|
+
| "Current.Export"
|
|
35
|
+
| "Current.Offered"
|
|
36
|
+
| "Voltage"
|
|
37
|
+
| "Frequency"
|
|
38
|
+
| "Temperature"
|
|
39
|
+
| "SoC"
|
|
40
|
+
| "RPM";
|
|
41
|
+
|
|
42
|
+
export type PhaseEnumType =
|
|
43
|
+
| "L1"
|
|
44
|
+
| "L2"
|
|
45
|
+
| "L3"
|
|
46
|
+
| "N"
|
|
47
|
+
| "L1-N"
|
|
48
|
+
| "L2-N"
|
|
49
|
+
| "L3-N"
|
|
50
|
+
| "L1-L2"
|
|
51
|
+
| "L2-L3"
|
|
52
|
+
| "L3-L1";
|
|
53
|
+
|
|
54
|
+
export type LocationEnumType =
|
|
55
|
+
| "Cable"
|
|
56
|
+
| "EV"
|
|
57
|
+
| "Inlet"
|
|
58
|
+
| "Outlet"
|
|
59
|
+
| "Body";
|
|
60
|
+
|
|
61
|
+
export type UnitEnumType =
|
|
62
|
+
| "Wh"
|
|
63
|
+
| "kWh"
|
|
64
|
+
| "varh"
|
|
65
|
+
| "kvarh"
|
|
66
|
+
| "W"
|
|
67
|
+
| "kW"
|
|
68
|
+
| "VA"
|
|
69
|
+
| "kVA"
|
|
70
|
+
| "var"
|
|
71
|
+
| "kvar"
|
|
72
|
+
| "A"
|
|
73
|
+
| "V"
|
|
74
|
+
| "K"
|
|
75
|
+
| "Celcius"
|
|
76
|
+
| "Fahrenheit"
|
|
77
|
+
| "Percent";
|
|
78
|
+
|
|
8
79
|
export interface MeterValuesRequest {
|
|
9
80
|
connectorId: number;
|
|
10
81
|
transactionId?: number;
|
|
@@ -12,58 +83,12 @@ export interface MeterValuesRequest {
|
|
|
12
83
|
timestamp: string;
|
|
13
84
|
sampledValue: {
|
|
14
85
|
value: string;
|
|
15
|
-
context?:
|
|
16
|
-
| "Interruption.Begin"
|
|
17
|
-
| "Interruption.End"
|
|
18
|
-
| "Sample.Clock"
|
|
19
|
-
| "Sample.Periodic"
|
|
20
|
-
| "Transaction.Begin"
|
|
21
|
-
| "Transaction.End"
|
|
22
|
-
| "Trigger"
|
|
23
|
-
| "Other";
|
|
86
|
+
context?: ContextEnumType;
|
|
24
87
|
format?: "Raw" | "SignedData";
|
|
25
|
-
measurand?:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
| "Energy.Reactive.Import.Register"
|
|
30
|
-
| "Energy.Active.Export.Interval"
|
|
31
|
-
| "Energy.Active.Import.Interval"
|
|
32
|
-
| "Energy.Reactive.Export.Interval"
|
|
33
|
-
| "Energy.Reactive.Import.Interval"
|
|
34
|
-
| "Power.Active.Export"
|
|
35
|
-
| "Power.Active.Import"
|
|
36
|
-
| "Power.Offered"
|
|
37
|
-
| "Power.Reactive.Export"
|
|
38
|
-
| "Power.Reactive.Import"
|
|
39
|
-
| "Power.Factor"
|
|
40
|
-
| "Current.Import"
|
|
41
|
-
| "Current.Export"
|
|
42
|
-
| "Current.Offered"
|
|
43
|
-
| "Voltage"
|
|
44
|
-
| "Frequency"
|
|
45
|
-
| "Temperature"
|
|
46
|
-
| "SoC"
|
|
47
|
-
| "RPM";
|
|
48
|
-
phase?: "L1" | "L2" | "L3" | "N" | "L1-N" | "L2-N" | "L3-N" | "L1-L2" | "L2-L3" | "L3-L1";
|
|
49
|
-
location?: "Cable" | "EV" | "Inlet" | "Outlet" | "Body";
|
|
50
|
-
unit?:
|
|
51
|
-
| "Wh"
|
|
52
|
-
| "kWh"
|
|
53
|
-
| "varh"
|
|
54
|
-
| "kvarh"
|
|
55
|
-
| "W"
|
|
56
|
-
| "kW"
|
|
57
|
-
| "VA"
|
|
58
|
-
| "kVA"
|
|
59
|
-
| "var"
|
|
60
|
-
| "kvar"
|
|
61
|
-
| "A"
|
|
62
|
-
| "V"
|
|
63
|
-
| "K"
|
|
64
|
-
| "Celcius"
|
|
65
|
-
| "Fahrenheit"
|
|
66
|
-
| "Percent";
|
|
88
|
+
measurand?: MeasurandEnumType;
|
|
89
|
+
phase?: PhaseEnumType;
|
|
90
|
+
location?: LocationEnumType;
|
|
91
|
+
unit?: UnitEnumType;
|
|
67
92
|
[k: string]: unknown;
|
|
68
93
|
}[];
|
|
69
94
|
[k: string]: unknown;
|
|
@@ -5,79 +5,106 @@
|
|
|
5
5
|
* and run json-schema-to-typescript to regenerate this file.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
export type ReasonEnumType =
|
|
9
|
+
| "EmergencyStop"
|
|
10
|
+
| "EVDisconnected"
|
|
11
|
+
| "HardReset"
|
|
12
|
+
| "Local"
|
|
13
|
+
| "Other"
|
|
14
|
+
| "PowerLoss"
|
|
15
|
+
| "Reboot"
|
|
16
|
+
| "Remote"
|
|
17
|
+
| "SoftReset"
|
|
18
|
+
| "UnlockCommand"
|
|
19
|
+
| "DeAuthorized";
|
|
20
|
+
|
|
21
|
+
export type ContextEnumType =
|
|
22
|
+
| "Interruption.Begin"
|
|
23
|
+
| "Interruption.End"
|
|
24
|
+
| "Sample.Clock"
|
|
25
|
+
| "Sample.Periodic"
|
|
26
|
+
| "Transaction.Begin"
|
|
27
|
+
| "Transaction.End"
|
|
28
|
+
| "Trigger"
|
|
29
|
+
| "Other";
|
|
30
|
+
|
|
31
|
+
export type MeasurandEnumType =
|
|
32
|
+
| "Energy.Active.Export.Register"
|
|
33
|
+
| "Energy.Active.Import.Register"
|
|
34
|
+
| "Energy.Reactive.Export.Register"
|
|
35
|
+
| "Energy.Reactive.Import.Register"
|
|
36
|
+
| "Energy.Active.Export.Interval"
|
|
37
|
+
| "Energy.Active.Import.Interval"
|
|
38
|
+
| "Energy.Reactive.Export.Interval"
|
|
39
|
+
| "Energy.Reactive.Import.Interval"
|
|
40
|
+
| "Power.Active.Export"
|
|
41
|
+
| "Power.Active.Import"
|
|
42
|
+
| "Power.Offered"
|
|
43
|
+
| "Power.Reactive.Export"
|
|
44
|
+
| "Power.Reactive.Import"
|
|
45
|
+
| "Power.Factor"
|
|
46
|
+
| "Current.Import"
|
|
47
|
+
| "Current.Export"
|
|
48
|
+
| "Current.Offered"
|
|
49
|
+
| "Voltage"
|
|
50
|
+
| "Frequency"
|
|
51
|
+
| "Temperature"
|
|
52
|
+
| "SoC"
|
|
53
|
+
| "RPM";
|
|
54
|
+
|
|
55
|
+
export type PhaseEnumType =
|
|
56
|
+
| "L1"
|
|
57
|
+
| "L2"
|
|
58
|
+
| "L3"
|
|
59
|
+
| "N"
|
|
60
|
+
| "L1-N"
|
|
61
|
+
| "L2-N"
|
|
62
|
+
| "L3-N"
|
|
63
|
+
| "L1-L2"
|
|
64
|
+
| "L2-L3"
|
|
65
|
+
| "L3-L1";
|
|
66
|
+
|
|
67
|
+
export type LocationEnumType =
|
|
68
|
+
| "Cable"
|
|
69
|
+
| "EV"
|
|
70
|
+
| "Inlet"
|
|
71
|
+
| "Outlet"
|
|
72
|
+
| "Body";
|
|
73
|
+
|
|
74
|
+
export type UnitEnumType =
|
|
75
|
+
| "Wh"
|
|
76
|
+
| "kWh"
|
|
77
|
+
| "varh"
|
|
78
|
+
| "kvarh"
|
|
79
|
+
| "W"
|
|
80
|
+
| "kW"
|
|
81
|
+
| "VA"
|
|
82
|
+
| "kVA"
|
|
83
|
+
| "var"
|
|
84
|
+
| "kvar"
|
|
85
|
+
| "A"
|
|
86
|
+
| "V"
|
|
87
|
+
| "K"
|
|
88
|
+
| "Celcius"
|
|
89
|
+
| "Fahrenheit"
|
|
90
|
+
| "Percent";
|
|
91
|
+
|
|
8
92
|
export interface StopTransactionRequest {
|
|
9
93
|
idTag?: string;
|
|
10
94
|
meterStop: number;
|
|
11
95
|
timestamp: string;
|
|
12
96
|
transactionId: number;
|
|
13
|
-
reason?:
|
|
14
|
-
| "EmergencyStop"
|
|
15
|
-
| "EVDisconnected"
|
|
16
|
-
| "HardReset"
|
|
17
|
-
| "Local"
|
|
18
|
-
| "Other"
|
|
19
|
-
| "PowerLoss"
|
|
20
|
-
| "Reboot"
|
|
21
|
-
| "Remote"
|
|
22
|
-
| "SoftReset"
|
|
23
|
-
| "UnlockCommand"
|
|
24
|
-
| "DeAuthorized";
|
|
97
|
+
reason?: ReasonEnumType;
|
|
25
98
|
transactionData?: {
|
|
26
99
|
timestamp: string;
|
|
27
100
|
sampledValue: {
|
|
28
101
|
value: string;
|
|
29
|
-
context?:
|
|
30
|
-
| "Interruption.Begin"
|
|
31
|
-
| "Interruption.End"
|
|
32
|
-
| "Sample.Clock"
|
|
33
|
-
| "Sample.Periodic"
|
|
34
|
-
| "Transaction.Begin"
|
|
35
|
-
| "Transaction.End"
|
|
36
|
-
| "Trigger"
|
|
37
|
-
| "Other";
|
|
102
|
+
context?: ContextEnumType;
|
|
38
103
|
format?: "Raw" | "SignedData";
|
|
39
|
-
measurand?:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
| "Energy.Reactive.Import.Register"
|
|
44
|
-
| "Energy.Active.Export.Interval"
|
|
45
|
-
| "Energy.Active.Import.Interval"
|
|
46
|
-
| "Energy.Reactive.Export.Interval"
|
|
47
|
-
| "Energy.Reactive.Import.Interval"
|
|
48
|
-
| "Power.Active.Export"
|
|
49
|
-
| "Power.Active.Import"
|
|
50
|
-
| "Power.Offered"
|
|
51
|
-
| "Power.Reactive.Export"
|
|
52
|
-
| "Power.Reactive.Import"
|
|
53
|
-
| "Power.Factor"
|
|
54
|
-
| "Current.Import"
|
|
55
|
-
| "Current.Export"
|
|
56
|
-
| "Current.Offered"
|
|
57
|
-
| "Voltage"
|
|
58
|
-
| "Frequency"
|
|
59
|
-
| "Temperature"
|
|
60
|
-
| "SoC"
|
|
61
|
-
| "RPM";
|
|
62
|
-
phase?: "L1" | "L2" | "L3" | "N" | "L1-N" | "L2-N" | "L3-N" | "L1-L2" | "L2-L3" | "L3-L1";
|
|
63
|
-
location?: "Cable" | "EV" | "Inlet" | "Outlet" | "Body";
|
|
64
|
-
unit?:
|
|
65
|
-
| "Wh"
|
|
66
|
-
| "kWh"
|
|
67
|
-
| "varh"
|
|
68
|
-
| "kvarh"
|
|
69
|
-
| "W"
|
|
70
|
-
| "kW"
|
|
71
|
-
| "VA"
|
|
72
|
-
| "kVA"
|
|
73
|
-
| "var"
|
|
74
|
-
| "kvar"
|
|
75
|
-
| "A"
|
|
76
|
-
| "V"
|
|
77
|
-
| "K"
|
|
78
|
-
| "Celcius"
|
|
79
|
-
| "Fahrenheit"
|
|
80
|
-
| "Percent";
|
|
104
|
+
measurand?: MeasurandEnumType;
|
|
105
|
+
phase?: PhaseEnumType;
|
|
106
|
+
location?: LocationEnumType;
|
|
107
|
+
unit?: UnitEnumType;
|
|
81
108
|
[k: string]: unknown;
|
|
82
109
|
}[];
|
|
83
110
|
[k: string]: unknown;
|