@fairfox/polly 0.7.1 → 0.7.2
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.
|
@@ -687,6 +687,17 @@ class TLAGenerator {
|
|
|
687
687
|
return isFirst;
|
|
688
688
|
}
|
|
689
689
|
addStateType(config, _analysis) {
|
|
690
|
+
this.defineValueTypes();
|
|
691
|
+
this.line("\\* Application state type definition");
|
|
692
|
+
this.line("State == [");
|
|
693
|
+
this.indent++;
|
|
694
|
+
const stateFields = this.collectStateFields(config, _analysis);
|
|
695
|
+
this.writeStateFields(stateFields);
|
|
696
|
+
this.indent--;
|
|
697
|
+
this.line("]");
|
|
698
|
+
this.line("");
|
|
699
|
+
}
|
|
700
|
+
defineValueTypes() {
|
|
690
701
|
this.line("\\* Generic value type for sequences and maps");
|
|
691
702
|
this.line("\\* Bounded to allow model checking");
|
|
692
703
|
this.line('Value == {"v1", "v2", "v3"}');
|
|
@@ -695,9 +706,8 @@ class TLAGenerator {
|
|
|
695
706
|
this.line("\\* Bounded to allow model checking");
|
|
696
707
|
this.line('Keys == {"k1", "k2", "k3"}');
|
|
697
708
|
this.line("");
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
this.indent++;
|
|
709
|
+
}
|
|
710
|
+
collectStateFields(config, _analysis) {
|
|
701
711
|
const stateFields = [];
|
|
702
712
|
for (const [fieldPath, fieldConfig] of Object.entries(config.state)) {
|
|
703
713
|
if (typeof fieldConfig !== "object" || fieldConfig === null)
|
|
@@ -707,24 +717,26 @@ class TLAGenerator {
|
|
|
707
717
|
stateFields.push(`${fieldName}: ${tlaType}`);
|
|
708
718
|
}
|
|
709
719
|
for (const fieldAnalysis of _analysis.fields) {
|
|
710
|
-
if (!fieldAnalysis.path || typeof fieldAnalysis.path !== "string")
|
|
720
|
+
if (!fieldAnalysis.path || typeof fieldAnalysis.path !== "string")
|
|
711
721
|
continue;
|
|
712
|
-
}
|
|
713
722
|
const fieldName = this.sanitizeFieldName(fieldAnalysis.path);
|
|
714
|
-
if (stateFields.some((f) => f.startsWith(`${fieldName}:`)))
|
|
723
|
+
if (stateFields.some((f) => f.startsWith(`${fieldName}:`)))
|
|
715
724
|
continue;
|
|
716
|
-
}
|
|
717
725
|
const tlaType = this.inferTLATypeFromAnalysis(fieldAnalysis);
|
|
718
726
|
stateFields.push(`${fieldName}: ${tlaType}`);
|
|
719
727
|
}
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
728
|
+
return stateFields;
|
|
729
|
+
}
|
|
730
|
+
writeStateFields(fields) {
|
|
731
|
+
if (fields.length === 0) {
|
|
732
|
+
this.line("dummy: BOOLEAN \\* Placeholder for empty state");
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
for (let i = 0;i < fields.length; i++) {
|
|
736
|
+
const field = fields[i];
|
|
737
|
+
const suffix = i < fields.length - 1 ? "," : "";
|
|
723
738
|
this.line(`${field}${suffix}`);
|
|
724
739
|
}
|
|
725
|
-
this.indent--;
|
|
726
|
-
this.line("]");
|
|
727
|
-
this.line("");
|
|
728
740
|
}
|
|
729
741
|
addMessageTypes(_config, analysis) {
|
|
730
742
|
if (analysis.messageTypes.length === 0) {
|
|
@@ -765,6 +777,20 @@ class TLAGenerator {
|
|
|
765
777
|
this.line("\\* Initial application state");
|
|
766
778
|
this.line("InitialState == [");
|
|
767
779
|
this.indent++;
|
|
780
|
+
const fields = this.collectInitialStateFields(config, _analysis);
|
|
781
|
+
this.writeInitialStateFields(fields);
|
|
782
|
+
this.indent--;
|
|
783
|
+
this.line("]");
|
|
784
|
+
this.line("");
|
|
785
|
+
this.line("\\* Initial state (extends MessageRouter)");
|
|
786
|
+
this.line("UserInit ==");
|
|
787
|
+
this.indent++;
|
|
788
|
+
this.line("/\\ Init \\* MessageRouter's init");
|
|
789
|
+
this.line("/\\ contextStates = [c \\in Contexts |-> InitialState]");
|
|
790
|
+
this.indent--;
|
|
791
|
+
this.line("");
|
|
792
|
+
}
|
|
793
|
+
collectInitialStateFields(config, _analysis) {
|
|
768
794
|
const fields = [];
|
|
769
795
|
for (const [fieldPath, fieldConfig] of Object.entries(config.state)) {
|
|
770
796
|
if (typeof fieldConfig !== "object" || fieldConfig === null)
|
|
@@ -774,31 +800,26 @@ class TLAGenerator {
|
|
|
774
800
|
fields.push(`${fieldName} |-> ${initialValue}`);
|
|
775
801
|
}
|
|
776
802
|
for (const fieldAnalysis of _analysis.fields) {
|
|
777
|
-
if (!fieldAnalysis.path || typeof fieldAnalysis.path !== "string")
|
|
803
|
+
if (!fieldAnalysis.path || typeof fieldAnalysis.path !== "string")
|
|
778
804
|
continue;
|
|
779
|
-
}
|
|
780
805
|
const fieldName = this.sanitizeFieldName(fieldAnalysis.path);
|
|
781
|
-
if (fields.some((f) => f.startsWith(`${fieldName} |->`)))
|
|
806
|
+
if (fields.some((f) => f.startsWith(`${fieldName} |->`)))
|
|
782
807
|
continue;
|
|
783
|
-
}
|
|
784
808
|
const initialValue = this.getInitialValueFromAnalysis(fieldAnalysis);
|
|
785
809
|
fields.push(`${fieldName} |-> ${initialValue}`);
|
|
786
810
|
}
|
|
811
|
+
return fields;
|
|
812
|
+
}
|
|
813
|
+
writeInitialStateFields(fields) {
|
|
814
|
+
if (fields.length === 0) {
|
|
815
|
+
this.line("dummy |-> FALSE \\* Placeholder for empty state");
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
787
818
|
for (let i = 0;i < fields.length; i++) {
|
|
788
819
|
const field = fields[i];
|
|
789
820
|
const suffix = i < fields.length - 1 ? "," : "";
|
|
790
821
|
this.line(`${field}${suffix}`);
|
|
791
822
|
}
|
|
792
|
-
this.indent--;
|
|
793
|
-
this.line("]");
|
|
794
|
-
this.line("");
|
|
795
|
-
this.line("\\* Initial state (extends MessageRouter)");
|
|
796
|
-
this.line("UserInit ==");
|
|
797
|
-
this.indent++;
|
|
798
|
-
this.line("/\\ Init \\* MessageRouter's init");
|
|
799
|
-
this.line("/\\ contextStates = [c \\in Contexts |-> InitialState]");
|
|
800
|
-
this.indent--;
|
|
801
|
-
this.line("");
|
|
802
823
|
}
|
|
803
824
|
addActions(config, analysis) {
|
|
804
825
|
this.line("\\* =============================================================================");
|
|
@@ -4526,4 +4547,4 @@ main().catch((error) => {
|
|
|
4526
4547
|
process.exit(1);
|
|
4527
4548
|
});
|
|
4528
4549
|
|
|
4529
|
-
//# debugId=
|
|
4550
|
+
//# debugId=6EFAE591D90C88BD64756E2164756E21
|