@fairfox/polly 0.6.0 → 0.6.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.
|
@@ -1075,6 +1075,7 @@ class HandlerExtractor {
|
|
|
1075
1075
|
extractHandlers() {
|
|
1076
1076
|
const handlers = [];
|
|
1077
1077
|
const messageTypes = new Set;
|
|
1078
|
+
const invalidMessageTypes = new Set;
|
|
1078
1079
|
const sourceFiles = this.project.getSourceFiles();
|
|
1079
1080
|
if (process.env["POLLY_DEBUG"]) {
|
|
1080
1081
|
console.log(`[DEBUG] Loaded ${sourceFiles.length} source files`);
|
|
@@ -1088,17 +1089,30 @@ class HandlerExtractor {
|
|
|
1088
1089
|
const fileHandlers = this.extractFromFile(sourceFile);
|
|
1089
1090
|
handlers.push(...fileHandlers);
|
|
1090
1091
|
for (const handler of fileHandlers) {
|
|
1091
|
-
|
|
1092
|
+
if (this.isValidTLAIdentifier(handler.messageType)) {
|
|
1093
|
+
messageTypes.add(handler.messageType);
|
|
1094
|
+
} else {
|
|
1095
|
+
invalidMessageTypes.add(handler.messageType);
|
|
1096
|
+
}
|
|
1092
1097
|
}
|
|
1093
1098
|
}
|
|
1094
1099
|
if (process.env["POLLY_DEBUG"]) {
|
|
1095
1100
|
console.log(`[DEBUG] Total handlers extracted: ${handlers.length}`);
|
|
1101
|
+
if (invalidMessageTypes.size > 0) {
|
|
1102
|
+
console.log(`[DEBUG] Filtered ${invalidMessageTypes.size} invalid message type(s) from handlers`);
|
|
1103
|
+
}
|
|
1096
1104
|
}
|
|
1097
1105
|
return {
|
|
1098
1106
|
handlers,
|
|
1099
1107
|
messageTypes
|
|
1100
1108
|
};
|
|
1101
1109
|
}
|
|
1110
|
+
isValidTLAIdentifier(s) {
|
|
1111
|
+
if (!s || s.length === 0) {
|
|
1112
|
+
return false;
|
|
1113
|
+
}
|
|
1114
|
+
return /^[a-zA-Z][a-zA-Z0-9_]*$/.test(s);
|
|
1115
|
+
}
|
|
1102
1116
|
extractFromFile(sourceFile) {
|
|
1103
1117
|
const handlers = [];
|
|
1104
1118
|
const filePath = sourceFile.getFilePath();
|
|
@@ -1602,13 +1616,35 @@ class TypeExtractor {
|
|
|
1602
1616
|
const tsConfigPath = typeof configFilePath === "string" ? configFilePath : "tsconfig.json";
|
|
1603
1617
|
const handlerExtractor = new HandlerExtractor(tsConfigPath);
|
|
1604
1618
|
const handlerAnalysis = handlerExtractor.extractHandlers();
|
|
1619
|
+
const allMessageTypes = Array.from(new Set([...messageTypes, ...handlerAnalysis.messageTypes]));
|
|
1620
|
+
const validMessageTypes = [];
|
|
1621
|
+
const invalidMessageTypes = [];
|
|
1622
|
+
for (const msgType of allMessageTypes) {
|
|
1623
|
+
if (this.isValidTLAIdentifier(msgType)) {
|
|
1624
|
+
validMessageTypes.push(msgType);
|
|
1625
|
+
} else {
|
|
1626
|
+
invalidMessageTypes.push(msgType);
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
if (invalidMessageTypes.length > 0 && process.env["POLLY_DEBUG"]) {
|
|
1630
|
+
console.log(`[WARN] Filtered out ${invalidMessageTypes.length} invalid message type(s):`);
|
|
1631
|
+
for (const invalid of invalidMessageTypes) {
|
|
1632
|
+
console.log(`[WARN] - "${invalid}" (not a valid TLA+ identifier)`);
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1605
1635
|
return {
|
|
1606
1636
|
stateType,
|
|
1607
|
-
messageTypes:
|
|
1637
|
+
messageTypes: validMessageTypes,
|
|
1608
1638
|
fields,
|
|
1609
1639
|
handlers: handlerAnalysis.handlers
|
|
1610
1640
|
};
|
|
1611
1641
|
}
|
|
1642
|
+
isValidTLAIdentifier(s) {
|
|
1643
|
+
if (!s || s.length === 0) {
|
|
1644
|
+
return false;
|
|
1645
|
+
}
|
|
1646
|
+
return /^[a-zA-Z][a-zA-Z0-9_]*$/.test(s);
|
|
1647
|
+
}
|
|
1612
1648
|
extractStateType(filePath) {
|
|
1613
1649
|
const sourceFile = this.project.getSourceFile(filePath);
|
|
1614
1650
|
if (!sourceFile) {
|
|
@@ -2750,4 +2786,4 @@ Stack trace:`, COLORS.gray));
|
|
|
2750
2786
|
process.exit(1);
|
|
2751
2787
|
});
|
|
2752
2788
|
|
|
2753
|
-
//# debugId=
|
|
2789
|
+
//# debugId=865A93F68683B62A64756E2164756E21
|