@tsplc/build 0.5.8 → 0.5.10
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/cli.js +507 -450
- package/dist/cli.js.map +14 -13
- package/dist/images.js +18 -3
- package/dist/images.js.map +4 -4
- package/dist/index.js +548 -443
- package/dist/index.js.map +14 -13
- package/docker/Dockerfile +3 -0
- package/docker/runner.ts +9 -1
- package/package.json +4 -4
- package/python/codesys_online.py +50 -11
- package/python/worker.py +1 -0
- package/src/controller-online.ts +118 -28
- package/src/controller-protocol.ts +49 -7
- package/src/controller-session.ts +179 -40
- package/src/docker-context.ts +31 -4
- package/src/host/codesys-worker.ts +8 -2
- package/src/images.ts +7 -1
- package/src/index.ts +8 -0
- package/src/online-change-check.ts +208 -0
- package/src/st/declarations.ts +107 -1
package/dist/index.js
CHANGED
|
@@ -155,14 +155,14 @@ var digestFiles = async (files, texts) => {
|
|
|
155
155
|
}
|
|
156
156
|
for (const file of [...files].sort((a, b) => a.name.localeCompare(b.name))) {
|
|
157
157
|
hash.update(`${file.name}\x00`);
|
|
158
|
-
hash.update(await
|
|
158
|
+
hash.update(await file.read());
|
|
159
159
|
hash.update("\x00");
|
|
160
160
|
}
|
|
161
161
|
return hash.digest("hex");
|
|
162
162
|
};
|
|
163
163
|
var containerCodeDigest = async () => digestFiles((await Promise.all(containerCode().map(async ({ source, target }) => (await listFiles(dirname(source), source, (path) => includeSource(basename(path)))).map((name) => ({
|
|
164
164
|
name: posix.join(posix.dirname(target), name),
|
|
165
|
-
|
|
165
|
+
read: () => readFile2(resolve3(dirname(source), name))
|
|
166
166
|
}))))).flat(), {});
|
|
167
167
|
var manifestDependencies = z2.object({
|
|
168
168
|
name: z2.string(),
|
|
@@ -195,8 +195,21 @@ var containerManifest = async () => {
|
|
|
195
195
|
var recipeFile = (path) => path === "docker" || path === "docker/Dockerfile" || path === "docker/entrypoint.sh" || (path === "docker/install" || path.startsWith("docker/install/")) && includeSource(basename(path)) && basename(path) !== ".npmignore" && !path.split("/").includes("tests") && path !== "docker/install/wine-signal/check.sh";
|
|
196
196
|
var builderRecipe = async () => digestFiles((await recipeFiles()).map((name) => ({
|
|
197
197
|
name,
|
|
198
|
-
|
|
198
|
+
read: () => readFile2(resolve3(packageDirectory, name))
|
|
199
199
|
})), { manifest: JSON.stringify(await containerManifest()) });
|
|
200
|
+
var toolingLine = /\bbun\b/i;
|
|
201
|
+
var engineeringRecipe = async () => digestFiles((await recipeFiles()).map((name) => ({
|
|
202
|
+
name,
|
|
203
|
+
read: async () => {
|
|
204
|
+
const content = await readFile2(resolve3(packageDirectory, name));
|
|
205
|
+
if (name !== "docker/Dockerfile") {
|
|
206
|
+
return content;
|
|
207
|
+
}
|
|
208
|
+
return content.toString("utf8").split(`
|
|
209
|
+
`).filter((line) => !toolingLine.test(line)).join(`
|
|
210
|
+
`);
|
|
211
|
+
}
|
|
212
|
+
})), {});
|
|
200
213
|
var recipeFiles = () => listFiles(packageDirectory, resolve3(packageDirectory, "docker"), recipeFile);
|
|
201
214
|
async function prepareDockerContext() {
|
|
202
215
|
const context = await mkdtemp(resolve3(tmpdir(), "tsplc-docker-"));
|
|
@@ -392,6 +405,8 @@ async function buildBuilderImage(options) {
|
|
|
392
405
|
`SETUP_PLATFORM=${options.setupPlatform}`,
|
|
393
406
|
"--build-arg",
|
|
394
407
|
`INSTALLER_SOURCE=${options.installer ? "installer-local" : "installer-download"}`,
|
|
408
|
+
"--build-arg",
|
|
409
|
+
`TSPLC_ENGINEERING=${await engineeringRecipe()}`,
|
|
395
410
|
"--label",
|
|
396
411
|
`${recipeLabel}=${await builderRecipe()}`,
|
|
397
412
|
"--progress",
|
|
@@ -656,7 +671,7 @@ import {
|
|
|
656
671
|
} from "node:fs/promises";
|
|
657
672
|
import { resolve as resolve7 } from "node:path";
|
|
658
673
|
import { setTimeout as delay } from "node:timers/promises";
|
|
659
|
-
import { z as
|
|
674
|
+
import { z as z8 } from "zod";
|
|
660
675
|
|
|
661
676
|
// packages/build/src/controller-protocol.ts
|
|
662
677
|
import {
|
|
@@ -664,44 +679,400 @@ import {
|
|
|
664
679
|
sha256Digest,
|
|
665
680
|
tcpPort
|
|
666
681
|
} from "@tsplc/config/build";
|
|
682
|
+
import { z as z6 } from "zod";
|
|
683
|
+
|
|
684
|
+
// packages/build/src/online-change-check.ts
|
|
685
|
+
import { elementaryType } from "@tsplc/iec";
|
|
667
686
|
import { z as z5 } from "zod";
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
687
|
+
|
|
688
|
+
// packages/build/src/st/declarations.ts
|
|
689
|
+
import {
|
|
690
|
+
conditionalDirective,
|
|
691
|
+
modifiers,
|
|
692
|
+
qualifiers,
|
|
693
|
+
variableSections
|
|
694
|
+
} from "@tsplc/iec/st";
|
|
695
|
+
|
|
696
|
+
// packages/build/src/st/lexer.ts
|
|
697
|
+
import { blockCommentEnd, lineCommentEnd, stringEnd } from "@tsplc/iec/st";
|
|
698
|
+
|
|
699
|
+
class StSyntaxError extends Error {
|
|
700
|
+
constructor(source, offset, filename, message) {
|
|
701
|
+
const lines = source.slice(0, offset).split(/\r\n|\r|\n/);
|
|
702
|
+
super(`${filename}:${lines.length}:${(lines.at(-1)?.length ?? 0) + 1}: ${message}`);
|
|
703
|
+
this.name = "StSyntaxError";
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
var tokenize = (source, filename = "<source>") => {
|
|
707
|
+
const tokens = [];
|
|
708
|
+
let offset = 0;
|
|
709
|
+
const fail = (start, message) => {
|
|
710
|
+
throw new StSyntaxError(source, start, filename, message);
|
|
711
|
+
};
|
|
712
|
+
const quoted = () => {
|
|
713
|
+
offset = stringEnd(source, offset) ?? fail(offset, "Unterminated string");
|
|
714
|
+
};
|
|
715
|
+
while (offset < source.length) {
|
|
716
|
+
const start = offset;
|
|
717
|
+
const character = source[offset] ?? "";
|
|
718
|
+
if (/\s|\uFEFF/.test(character)) {
|
|
719
|
+
offset++;
|
|
720
|
+
continue;
|
|
721
|
+
}
|
|
722
|
+
if (source.startsWith("//", offset)) {
|
|
723
|
+
offset = lineCommentEnd(source, start);
|
|
724
|
+
continue;
|
|
725
|
+
}
|
|
726
|
+
if (source.startsWith("(*", offset)) {
|
|
727
|
+
offset = blockCommentEnd(source, start) ?? fail(start, "Unterminated block comment");
|
|
728
|
+
continue;
|
|
729
|
+
}
|
|
730
|
+
if (character === "'" || character === '"') {
|
|
731
|
+
quoted();
|
|
732
|
+
tokens.push({
|
|
733
|
+
kind: "string",
|
|
734
|
+
value: source.slice(start, offset),
|
|
735
|
+
start,
|
|
736
|
+
end: offset
|
|
737
|
+
});
|
|
738
|
+
continue;
|
|
739
|
+
}
|
|
740
|
+
if (character === "{") {
|
|
741
|
+
offset++;
|
|
742
|
+
while (offset < source.length && source[offset] !== "}") {
|
|
743
|
+
if (source[offset] === "'" || source[offset] === '"') {
|
|
744
|
+
quoted();
|
|
745
|
+
} else {
|
|
746
|
+
offset++;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
if (offset === source.length) {
|
|
750
|
+
fail(start, "Unterminated pragma");
|
|
751
|
+
}
|
|
752
|
+
offset++;
|
|
753
|
+
tokens.push({
|
|
754
|
+
kind: "pragma",
|
|
755
|
+
value: source.slice(start, offset),
|
|
756
|
+
start,
|
|
757
|
+
end: offset
|
|
758
|
+
});
|
|
759
|
+
continue;
|
|
760
|
+
}
|
|
761
|
+
if (/[A-Za-z_]/.test(character)) {
|
|
762
|
+
offset++;
|
|
763
|
+
while (/[A-Za-z_0-9]/.test(source[offset] ?? "")) {
|
|
764
|
+
offset++;
|
|
765
|
+
}
|
|
766
|
+
tokens.push({
|
|
767
|
+
kind: "word",
|
|
768
|
+
value: source.slice(start, offset).toUpperCase(),
|
|
769
|
+
start,
|
|
770
|
+
end: offset
|
|
771
|
+
});
|
|
772
|
+
continue;
|
|
773
|
+
}
|
|
774
|
+
offset++;
|
|
775
|
+
const pair = source.slice(start, offset + 1);
|
|
776
|
+
if ([":=", "=>", "..", "<=", ">=", "<>", "**"].includes(pair)) {
|
|
777
|
+
offset++;
|
|
778
|
+
}
|
|
779
|
+
tokens.push({
|
|
780
|
+
kind: "symbol",
|
|
781
|
+
value: source.slice(start, offset),
|
|
782
|
+
start,
|
|
783
|
+
end: offset
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
return tokens;
|
|
787
|
+
};
|
|
788
|
+
|
|
789
|
+
// packages/build/src/st/reader.ts
|
|
790
|
+
var createTokenReader = (source, filename) => {
|
|
791
|
+
const tokens = tokenize(source, filename);
|
|
792
|
+
let index = 0;
|
|
793
|
+
const peek = (ahead = 0) => tokens[index + ahead];
|
|
794
|
+
const fail = (message, token = peek()) => {
|
|
795
|
+
throw new StSyntaxError(source, token?.start ?? source.length, filename, message);
|
|
796
|
+
};
|
|
797
|
+
const take = () => {
|
|
798
|
+
const token = peek();
|
|
799
|
+
if (!token) {
|
|
800
|
+
return fail("Unexpected end of declaration");
|
|
801
|
+
}
|
|
802
|
+
index++;
|
|
803
|
+
return token;
|
|
804
|
+
};
|
|
805
|
+
const expect = (value) => {
|
|
806
|
+
if (peek()?.value !== value) {
|
|
807
|
+
fail(`Expected ${value}`);
|
|
808
|
+
}
|
|
809
|
+
return take();
|
|
810
|
+
};
|
|
811
|
+
const consume = (value) => {
|
|
812
|
+
if (peek()?.value === value) {
|
|
813
|
+
return take();
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
return {
|
|
817
|
+
source,
|
|
818
|
+
filename,
|
|
819
|
+
tokens,
|
|
820
|
+
peek,
|
|
821
|
+
take,
|
|
822
|
+
expect,
|
|
823
|
+
consume,
|
|
824
|
+
fail,
|
|
825
|
+
get index() {
|
|
826
|
+
return index;
|
|
827
|
+
},
|
|
828
|
+
get end() {
|
|
829
|
+
return tokens[index - 1]?.end ?? 0;
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
};
|
|
833
|
+
|
|
834
|
+
// packages/build/src/st/declarations.ts
|
|
835
|
+
var objectKinds = {
|
|
836
|
+
PROGRAM: "program",
|
|
837
|
+
FUNCTION_BLOCK: "function_block",
|
|
838
|
+
FUNCTIONBLOCK: "function_block",
|
|
839
|
+
FUNCTION: "function",
|
|
840
|
+
METHOD: "method",
|
|
841
|
+
INTERFACE: "interface",
|
|
842
|
+
PROPERTY: "property"
|
|
843
|
+
};
|
|
844
|
+
var closingObjects = new Set(Object.keys(objectKinds).map((kind) => `END_${kind}`));
|
|
845
|
+
var declarationKeywords = new Set([
|
|
846
|
+
...Object.keys(objectKinds),
|
|
847
|
+
...closingObjects,
|
|
848
|
+
...variableSections,
|
|
849
|
+
"END_VAR",
|
|
850
|
+
"TYPE",
|
|
851
|
+
"END_TYPE",
|
|
852
|
+
"STRUCT",
|
|
853
|
+
"END_STRUCT",
|
|
854
|
+
"UNION",
|
|
855
|
+
"END_UNION",
|
|
856
|
+
"ACTION",
|
|
857
|
+
"END_ACTION",
|
|
858
|
+
"CONFIGURATION",
|
|
859
|
+
"END_CONFIGURATION"
|
|
860
|
+
]);
|
|
861
|
+
var isDeclarationPragma = (token) => token?.kind === "pragma" && !conditionalDirective(token.value);
|
|
862
|
+
var readDeclarationPragmas = (reader) => {
|
|
863
|
+
while (isDeclarationPragma(reader.peek())) {
|
|
864
|
+
reader.take();
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
var readDeclarationSemicolon = (reader) => {
|
|
868
|
+
const token = reader.peek();
|
|
869
|
+
if (token?.value === ";" && !/[\r\n]/.test(reader.source.slice(reader.end, token.start))) {
|
|
870
|
+
reader.take();
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
var readIdentifier = (reader) => {
|
|
874
|
+
const token = reader.take();
|
|
875
|
+
if (token.kind !== "word" || declarationKeywords.has(token.value)) {
|
|
876
|
+
reader.fail("Expected an IEC identifier", token);
|
|
877
|
+
}
|
|
878
|
+
return reader.source.slice(token.start, token.end);
|
|
879
|
+
};
|
|
880
|
+
var isOverrideModifier = (reader) => {
|
|
881
|
+
const name = reader.peek(1);
|
|
882
|
+
return name?.kind === "word" && !declarationKeywords.has(name.value) && !["(", "[", ":=", ".", "^"].includes(reader.peek(2)?.value ?? "") && !/[\r\n]/.test(reader.source.slice(reader.peek()?.end, name.start));
|
|
883
|
+
};
|
|
884
|
+
var readModifiers = (reader) => {
|
|
885
|
+
while (modifiers.has(reader.peek()?.value ?? "")) {
|
|
886
|
+
if (reader.peek()?.value === "OVERRIDE" && !isOverrideModifier(reader)) {
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
reader.take();
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
var typeDelimiters = { "(": ")", "[": "]", "<": ">" };
|
|
893
|
+
var readDelimitedType = (reader, open) => {
|
|
894
|
+
reader.expect(open);
|
|
895
|
+
const closings = [typeDelimiters[open]];
|
|
896
|
+
while (closings.length) {
|
|
897
|
+
const token = reader.take();
|
|
898
|
+
if (token.kind === "string" || token.kind === "pragma") {
|
|
899
|
+
continue;
|
|
900
|
+
}
|
|
901
|
+
if (token.value === "(" || token.value === "[") {
|
|
902
|
+
closings.push(typeDelimiters[token.value]);
|
|
903
|
+
} else if (token.value === ")" || token.value === "]") {
|
|
904
|
+
if (closings.pop() !== token.value) {
|
|
905
|
+
reader.fail(`Mismatched delimiter ${token.value}`, token);
|
|
906
|
+
}
|
|
907
|
+
} else if (open === "<" && closings.at(-1) === ">") {
|
|
908
|
+
if (token.value === "<") {
|
|
909
|
+
closings.push(">");
|
|
910
|
+
}
|
|
911
|
+
if (token.value === ">") {
|
|
912
|
+
closings.pop();
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
if (declarationKeywords.has(token.value) || token.value === ";") {
|
|
916
|
+
reader.fail(`Unclosed ${open}`, token);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
var readType = (reader) => {
|
|
921
|
+
const start = reader.peek()?.start ?? reader.source.length;
|
|
922
|
+
while (true) {
|
|
923
|
+
if (["POINTER", "REFERENCE", "REF_TO"].includes(reader.peek()?.value ?? "")) {
|
|
924
|
+
if (reader.take().value !== "REF_TO") {
|
|
925
|
+
reader.expect("TO");
|
|
926
|
+
}
|
|
927
|
+
continue;
|
|
928
|
+
}
|
|
929
|
+
if (reader.consume("ARRAY")) {
|
|
930
|
+
readDelimitedType(reader, "[");
|
|
931
|
+
reader.expect("OF");
|
|
932
|
+
continue;
|
|
933
|
+
}
|
|
934
|
+
break;
|
|
935
|
+
}
|
|
936
|
+
readIdentifier(reader);
|
|
937
|
+
while (reader.consume(".")) {
|
|
938
|
+
readIdentifier(reader);
|
|
939
|
+
}
|
|
940
|
+
for (const open of ["(", "[", "<"]) {
|
|
941
|
+
if (reader.peek()?.value === open) {
|
|
942
|
+
readDelimitedType(reader, open);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
return reader.source.slice(start, reader.end);
|
|
946
|
+
};
|
|
947
|
+
var readVariableSection = (reader) => {
|
|
948
|
+
reader.take();
|
|
949
|
+
const conditionals = [];
|
|
950
|
+
while (reader.peek()?.value !== "END_VAR") {
|
|
951
|
+
const token = reader.take();
|
|
952
|
+
if (variableSections.has(token.value) || closingObjects.has(token.value)) {
|
|
953
|
+
reader.fail("Missing END_VAR", token);
|
|
954
|
+
}
|
|
955
|
+
const directive = token.kind === "pragma" && conditionalDirective(token.value);
|
|
956
|
+
if (!directive) {
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
959
|
+
if (directive === "IF") {
|
|
960
|
+
conditionals.push({ hasElse: false });
|
|
961
|
+
continue;
|
|
962
|
+
}
|
|
963
|
+
const current = conditionals.at(-1);
|
|
964
|
+
if (!current) {
|
|
965
|
+
return reader.fail("Unmatched conditional pragma", token);
|
|
966
|
+
}
|
|
967
|
+
if (directive === "END_IF") {
|
|
968
|
+
conditionals.pop();
|
|
969
|
+
continue;
|
|
970
|
+
}
|
|
971
|
+
if (current.hasElse) {
|
|
972
|
+
reader.fail("Conditional branch after ELSE", token);
|
|
973
|
+
}
|
|
974
|
+
current.hasElse = directive === "ELSE";
|
|
975
|
+
}
|
|
976
|
+
if (conditionals.length) {
|
|
977
|
+
reader.fail("Conditional pragmas must remain inside one variable section");
|
|
978
|
+
}
|
|
979
|
+
reader.take();
|
|
980
|
+
readDeclarationSemicolon(reader);
|
|
981
|
+
};
|
|
982
|
+
var readDeclarationSections = (reader) => {
|
|
983
|
+
while (reader.peek()) {
|
|
984
|
+
let ahead = 0;
|
|
985
|
+
while (isDeclarationPragma(reader.peek(ahead))) {
|
|
986
|
+
ahead++;
|
|
987
|
+
}
|
|
988
|
+
const next = reader.peek(ahead)?.value ?? "";
|
|
989
|
+
if (variableSections.has(next)) {
|
|
990
|
+
readDeclarationPragmas(reader);
|
|
991
|
+
readVariableSection(reader);
|
|
992
|
+
continue;
|
|
993
|
+
}
|
|
994
|
+
if (next !== "EXTENDS" && next !== "IMPLEMENTS") {
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
readDeclarationPragmas(reader);
|
|
998
|
+
reader.take();
|
|
999
|
+
readType(reader);
|
|
1000
|
+
while (reader.consume(",")) {
|
|
1001
|
+
readType(reader);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
};
|
|
1005
|
+
var keptSections = new Set([
|
|
1006
|
+
"VAR",
|
|
1007
|
+
"VAR_INPUT",
|
|
1008
|
+
"VAR_OUTPUT",
|
|
1009
|
+
"VAR_IN_OUT",
|
|
1010
|
+
"VAR_STAT",
|
|
1011
|
+
"VAR_INST",
|
|
1012
|
+
"VAR_GLOBAL"
|
|
1013
|
+
]);
|
|
1014
|
+
|
|
1015
|
+
// packages/build/src/online-change-check.ts
|
|
1016
|
+
var committedObjectSchema = z5.lazy(() => z5.looseObject({
|
|
1017
|
+
kind: z5.string(),
|
|
1018
|
+
name: z5.string(),
|
|
1019
|
+
declaration: z5.string(),
|
|
1020
|
+
children: z5.array(committedObjectSchema).optional()
|
|
1021
|
+
}));
|
|
1022
|
+
var onlineChangeFindingSchema = z5.strictObject({
|
|
1023
|
+
kind: z5.enum(["type", "tasks", "restart"]),
|
|
1024
|
+
refuses: z5.boolean(),
|
|
1025
|
+
object: z5.string(),
|
|
1026
|
+
variable: z5.string().nullable(),
|
|
1027
|
+
before: z5.string().nullable(),
|
|
1028
|
+
after: z5.string().nullable(),
|
|
1029
|
+
advice: z5.string()
|
|
1030
|
+
});
|
|
1031
|
+
var describeFinding = (finding) => {
|
|
1032
|
+
const where = finding.variable ? `${finding.object}.${finding.variable}` : finding.object;
|
|
1033
|
+
const change = finding.before !== null && finding.after !== null ? ` (${finding.before} → ${finding.after})` : "";
|
|
1034
|
+
return `${where}${change}: ${finding.advice}`;
|
|
1035
|
+
};
|
|
1036
|
+
|
|
1037
|
+
// packages/build/src/controller-protocol.ts
|
|
1038
|
+
var imageIdSchema = z6.string().regex(/^sha256:[a-f0-9]{64}$/);
|
|
1039
|
+
var endpointSchema = z6.strictObject({
|
|
1040
|
+
host: z6.string().nonempty(),
|
|
671
1041
|
port: tcpPort
|
|
672
1042
|
});
|
|
673
|
-
var controllerResultSchema =
|
|
674
|
-
schemaVersion:
|
|
675
|
-
operationId:
|
|
676
|
-
operation:
|
|
1043
|
+
var controllerResultSchema = z6.strictObject({
|
|
1044
|
+
schemaVersion: z6.literal(1),
|
|
1045
|
+
operationId: z6.uuid(),
|
|
1046
|
+
operation: z6.enum(["download", "online-change", "inspect"]),
|
|
677
1047
|
imageId: imageIdSchema,
|
|
1048
|
+
engineering: sha256Digest.optional(),
|
|
678
1049
|
templateHash: sha256Digest,
|
|
679
|
-
target:
|
|
680
|
-
network:
|
|
1050
|
+
target: z6.strictObject({
|
|
1051
|
+
network: z6.string().nonempty(),
|
|
681
1052
|
gateway: endpointSchema,
|
|
682
1053
|
device: endpointSchema,
|
|
683
1054
|
controller: controllerSchema.optional(),
|
|
684
1055
|
deviceTree: sha256Digest.optional()
|
|
685
1056
|
}),
|
|
686
|
-
generation:
|
|
687
|
-
application:
|
|
688
|
-
applicationGuid:
|
|
689
|
-
controllerIds:
|
|
690
|
-
codeId:
|
|
691
|
-
dataId:
|
|
1057
|
+
generation: z6.string().nonempty(),
|
|
1058
|
+
application: z6.string().nonempty(),
|
|
1059
|
+
applicationGuid: z6.string().nonempty(),
|
|
1060
|
+
controllerIds: z6.strictObject({
|
|
1061
|
+
codeId: z6.string().nonempty(),
|
|
1062
|
+
dataId: z6.string().nonempty()
|
|
692
1063
|
}),
|
|
693
|
-
state:
|
|
694
|
-
values:
|
|
1064
|
+
state: z6.string().nonempty(),
|
|
1065
|
+
values: z6.record(z6.string(), z6.string())
|
|
695
1066
|
});
|
|
696
|
-
var controllerCredentialsSchema =
|
|
697
|
-
username:
|
|
698
|
-
password:
|
|
1067
|
+
var controllerCredentialsSchema = z6.strictObject({
|
|
1068
|
+
username: z6.string().nonempty(),
|
|
1069
|
+
password: z6.string().nonempty()
|
|
699
1070
|
});
|
|
700
|
-
var warmOperationSchema =
|
|
701
|
-
operation:
|
|
702
|
-
operationId:
|
|
703
|
-
request:
|
|
704
|
-
initializeUser:
|
|
1071
|
+
var warmOperationSchema = z6.strictObject({
|
|
1072
|
+
operation: z6.enum(["download", "online-change", "review"]),
|
|
1073
|
+
operationId: z6.uuid(),
|
|
1074
|
+
request: z6.string().nonempty(),
|
|
1075
|
+
initializeUser: z6.boolean(),
|
|
705
1076
|
credentials: controllerCredentialsSchema.optional()
|
|
706
1077
|
});
|
|
707
1078
|
var tracebackFailure = (traceback) => {
|
|
@@ -726,13 +1097,24 @@ var controllerTarget = (config, online) => ({
|
|
|
726
1097
|
deviceTree: deviceTreeStructure(config.deviceTree)
|
|
727
1098
|
}
|
|
728
1099
|
});
|
|
729
|
-
var
|
|
1100
|
+
var sameBuilder = (state, expected) => state.engineering && expected.engineering ? state.engineering === expected.engineering : state.imageId === expected.imageId;
|
|
1101
|
+
var sameBaseline = (state, expected) => sameBuilder(state, expected) && state.templateHash === expected.templateHash && JSON.stringify(state.target) === JSON.stringify(expected.target);
|
|
730
1102
|
var explicitDownload = "use an explicit download";
|
|
731
1103
|
|
|
732
1104
|
class DownloadRequiredError extends Error {
|
|
733
1105
|
downloadRequired = true;
|
|
1106
|
+
findings;
|
|
1107
|
+
messages;
|
|
1108
|
+
constructor(message, options = {}) {
|
|
1109
|
+
super(message, options);
|
|
1110
|
+
this.findings = options.findings ?? [];
|
|
1111
|
+
this.messages = options.messages ?? [];
|
|
1112
|
+
}
|
|
734
1113
|
}
|
|
735
|
-
var
|
|
1114
|
+
var reviewReplySchema = z6.strictObject({
|
|
1115
|
+
findings: z6.array(onlineChangeFindingSchema)
|
|
1116
|
+
});
|
|
1117
|
+
var rollbackSchema = z6.enum([
|
|
736
1118
|
"intact",
|
|
737
1119
|
"restored",
|
|
738
1120
|
"failed",
|
|
@@ -753,30 +1135,30 @@ var transferRollback = (error) => {
|
|
|
753
1135
|
return rollbackSchema.safeParse(error.rollback).data;
|
|
754
1136
|
};
|
|
755
1137
|
var requiresDownload = (error) => error instanceof Error && ("downloadRequired" in error) && error.downloadRequired === true;
|
|
756
|
-
var loginCommandSchema =
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
command:
|
|
760
|
-
expressions:
|
|
1138
|
+
var loginCommandSchema = z6.discriminatedUnion("command", [
|
|
1139
|
+
z6.strictObject({ command: z6.literal("state") }),
|
|
1140
|
+
z6.strictObject({
|
|
1141
|
+
command: z6.literal("read"),
|
|
1142
|
+
expressions: z6.array(z6.string().nonempty()).nonempty()
|
|
761
1143
|
}),
|
|
762
|
-
|
|
763
|
-
command:
|
|
764
|
-
values:
|
|
1144
|
+
z6.strictObject({
|
|
1145
|
+
command: z6.enum(["write", "force"]),
|
|
1146
|
+
values: z6.record(z6.string().nonempty(), z6.string().nonempty())
|
|
765
1147
|
}),
|
|
766
|
-
|
|
767
|
-
command:
|
|
768
|
-
expressions:
|
|
769
|
-
restore:
|
|
1148
|
+
z6.strictObject({
|
|
1149
|
+
command: z6.literal("unforce"),
|
|
1150
|
+
expressions: z6.array(z6.string().nonempty()),
|
|
1151
|
+
restore: z6.boolean()
|
|
770
1152
|
}),
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
command:
|
|
774
|
-
kind:
|
|
1153
|
+
z6.strictObject({ command: z6.enum(["start", "stop"]) }),
|
|
1154
|
+
z6.strictObject({
|
|
1155
|
+
command: z6.literal("reset"),
|
|
1156
|
+
kind: z6.enum(["Warm", "Cold"])
|
|
775
1157
|
})
|
|
776
1158
|
]);
|
|
777
|
-
var loginResultSchema =
|
|
778
|
-
|
|
779
|
-
|
|
1159
|
+
var loginResultSchema = z6.union([
|
|
1160
|
+
z6.strictObject({ values: z6.record(z6.string(), z6.string()) }),
|
|
1161
|
+
z6.strictObject({ state: z6.string(), forced: z6.array(z6.string()) })
|
|
780
1162
|
]);
|
|
781
1163
|
|
|
782
1164
|
// packages/build/src/host/codesys-command.ts
|
|
@@ -794,7 +1176,7 @@ var codesysCommand = [
|
|
|
794
1176
|
// packages/build/src/host/codesys-host.ts
|
|
795
1177
|
import { execFile as execFile3, spawn as spawn2 } from "node:child_process";
|
|
796
1178
|
import { promisify as promisify3 } from "node:util";
|
|
797
|
-
import { z as
|
|
1179
|
+
import { z as z7 } from "zod";
|
|
798
1180
|
|
|
799
1181
|
// packages/build/src/host/windows-path.ts
|
|
800
1182
|
import { execFile as execFile2 } from "node:child_process";
|
|
@@ -807,10 +1189,10 @@ var execute2 = promisify2(execFile2);
|
|
|
807
1189
|
|
|
808
1190
|
// packages/build/src/host/codesys-host.ts
|
|
809
1191
|
var execute3 = promisify3(execFile3);
|
|
810
|
-
var exitSchema =
|
|
811
|
-
pid:
|
|
812
|
-
code:
|
|
813
|
-
signal:
|
|
1192
|
+
var exitSchema = z7.object({
|
|
1193
|
+
pid: z7.int().positive(),
|
|
1194
|
+
code: z7.int().nullable(),
|
|
1195
|
+
signal: z7.string().nullable()
|
|
814
1196
|
});
|
|
815
1197
|
|
|
816
1198
|
// packages/build/src/host/codesys-worker.ts
|
|
@@ -823,12 +1205,12 @@ var workerScripts = [
|
|
|
823
1205
|
"codesys_login.py"
|
|
824
1206
|
];
|
|
825
1207
|
var workerScriptsDigest = async () => createHash4("sha256").update(JSON.stringify(await Promise.all(workerScripts.map((script) => readFile5(resolve7(pythonDirectory, script), "utf8"))))).digest("hex");
|
|
826
|
-
var sessionSchema =
|
|
827
|
-
directory:
|
|
828
|
-
fingerprint:
|
|
829
|
-
pid:
|
|
1208
|
+
var sessionSchema = z8.object({
|
|
1209
|
+
directory: z8.string(),
|
|
1210
|
+
fingerprint: z8.string(),
|
|
1211
|
+
pid: z8.int().positive()
|
|
830
1212
|
});
|
|
831
|
-
var phaseSchema =
|
|
1213
|
+
var phaseSchema = z8.enum(["prepare", "transfer"]);
|
|
832
1214
|
var hasCode = (error, code) => error instanceof Error && ("code" in error) && error.code === code;
|
|
833
1215
|
var isProcessAlive = (pid) => {
|
|
834
1216
|
try {
|
|
@@ -868,118 +1250,23 @@ var withWorkerLock = async (config, run) => {
|
|
|
868
1250
|
throw error;
|
|
869
1251
|
}));
|
|
870
1252
|
if (owner > 0 && !isProcessAlive(owner)) {
|
|
871
|
-
throw new Error(`An interrupted command left ${path}. Remove that lock file and retry.`);
|
|
872
|
-
}
|
|
873
|
-
if (Date.now() >= deadline) {
|
|
874
|
-
throw new Error(`Timed out waiting for another CODESYS command (${path})`);
|
|
875
|
-
}
|
|
876
|
-
await delay(200);
|
|
877
|
-
}
|
|
878
|
-
};
|
|
879
|
-
|
|
880
|
-
// packages/build/src/sources.ts
|
|
881
|
-
import { readdir as readdir2, readFile as readFile6 } from "node:fs/promises";
|
|
882
|
-
import { basename as basename4, resolve as resolve8 } from "node:path";
|
|
883
|
-
import { identifierPattern as identifierPattern3 } from "@tsplc/iec/st";
|
|
884
|
-
|
|
885
|
-
// packages/build/src/io.ts
|
|
886
|
-
import { ioArray, ioScalarBits, sizePrefix } from "@tsplc/iec";
|
|
887
|
-
import { qualifiers, variableSections } from "@tsplc/iec/st";
|
|
888
|
-
|
|
889
|
-
// packages/build/src/st/lexer.ts
|
|
890
|
-
import { blockCommentEnd, lineCommentEnd, stringEnd } from "@tsplc/iec/st";
|
|
891
|
-
|
|
892
|
-
class StSyntaxError extends Error {
|
|
893
|
-
constructor(source, offset, filename, message) {
|
|
894
|
-
const lines = source.slice(0, offset).split(/\r\n|\r|\n/);
|
|
895
|
-
super(`${filename}:${lines.length}:${(lines.at(-1)?.length ?? 0) + 1}: ${message}`);
|
|
896
|
-
this.name = "StSyntaxError";
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
var tokenize = (source, filename = "<source>") => {
|
|
900
|
-
const tokens = [];
|
|
901
|
-
let offset = 0;
|
|
902
|
-
const fail = (start, message) => {
|
|
903
|
-
throw new StSyntaxError(source, start, filename, message);
|
|
904
|
-
};
|
|
905
|
-
const quoted = () => {
|
|
906
|
-
offset = stringEnd(source, offset) ?? fail(offset, "Unterminated string");
|
|
907
|
-
};
|
|
908
|
-
while (offset < source.length) {
|
|
909
|
-
const start = offset;
|
|
910
|
-
const character = source[offset] ?? "";
|
|
911
|
-
if (/\s|\uFEFF/.test(character)) {
|
|
912
|
-
offset++;
|
|
913
|
-
continue;
|
|
914
|
-
}
|
|
915
|
-
if (source.startsWith("//", offset)) {
|
|
916
|
-
offset = lineCommentEnd(source, start);
|
|
917
|
-
continue;
|
|
918
|
-
}
|
|
919
|
-
if (source.startsWith("(*", offset)) {
|
|
920
|
-
offset = blockCommentEnd(source, start) ?? fail(start, "Unterminated block comment");
|
|
921
|
-
continue;
|
|
922
|
-
}
|
|
923
|
-
if (character === "'" || character === '"') {
|
|
924
|
-
quoted();
|
|
925
|
-
tokens.push({
|
|
926
|
-
kind: "string",
|
|
927
|
-
value: source.slice(start, offset),
|
|
928
|
-
start,
|
|
929
|
-
end: offset
|
|
930
|
-
});
|
|
931
|
-
continue;
|
|
932
|
-
}
|
|
933
|
-
if (character === "{") {
|
|
934
|
-
offset++;
|
|
935
|
-
while (offset < source.length && source[offset] !== "}") {
|
|
936
|
-
if (source[offset] === "'" || source[offset] === '"') {
|
|
937
|
-
quoted();
|
|
938
|
-
} else {
|
|
939
|
-
offset++;
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
if (offset === source.length) {
|
|
943
|
-
fail(start, "Unterminated pragma");
|
|
944
|
-
}
|
|
945
|
-
offset++;
|
|
946
|
-
tokens.push({
|
|
947
|
-
kind: "pragma",
|
|
948
|
-
value: source.slice(start, offset),
|
|
949
|
-
start,
|
|
950
|
-
end: offset
|
|
951
|
-
});
|
|
952
|
-
continue;
|
|
953
|
-
}
|
|
954
|
-
if (/[A-Za-z_]/.test(character)) {
|
|
955
|
-
offset++;
|
|
956
|
-
while (/[A-Za-z_0-9]/.test(source[offset] ?? "")) {
|
|
957
|
-
offset++;
|
|
958
|
-
}
|
|
959
|
-
tokens.push({
|
|
960
|
-
kind: "word",
|
|
961
|
-
value: source.slice(start, offset).toUpperCase(),
|
|
962
|
-
start,
|
|
963
|
-
end: offset
|
|
964
|
-
});
|
|
965
|
-
continue;
|
|
966
|
-
}
|
|
967
|
-
offset++;
|
|
968
|
-
const pair = source.slice(start, offset + 1);
|
|
969
|
-
if ([":=", "=>", "..", "<=", ">=", "<>", "**"].includes(pair)) {
|
|
970
|
-
offset++;
|
|
971
|
-
}
|
|
972
|
-
tokens.push({
|
|
973
|
-
kind: "symbol",
|
|
974
|
-
value: source.slice(start, offset),
|
|
975
|
-
start,
|
|
976
|
-
end: offset
|
|
977
|
-
});
|
|
1253
|
+
throw new Error(`An interrupted command left ${path}. Remove that lock file and retry.`);
|
|
1254
|
+
}
|
|
1255
|
+
if (Date.now() >= deadline) {
|
|
1256
|
+
throw new Error(`Timed out waiting for another CODESYS command (${path})`);
|
|
1257
|
+
}
|
|
1258
|
+
await delay(200);
|
|
978
1259
|
}
|
|
979
|
-
return tokens;
|
|
980
1260
|
};
|
|
981
1261
|
|
|
1262
|
+
// packages/build/src/sources.ts
|
|
1263
|
+
import { readdir as readdir2, readFile as readFile6 } from "node:fs/promises";
|
|
1264
|
+
import { basename as basename4, resolve as resolve8 } from "node:path";
|
|
1265
|
+
import { identifierPattern as identifierPattern3 } from "@tsplc/iec/st";
|
|
1266
|
+
|
|
982
1267
|
// packages/build/src/io.ts
|
|
1268
|
+
import { ioArray, ioScalarBits, sizePrefix } from "@tsplc/iec";
|
|
1269
|
+
import { qualifiers as qualifiers2, variableSections as variableSections2 } from "@tsplc/iec/st";
|
|
983
1270
|
var span = (type) => ioArray(type) ?? { element: type, length: 1 };
|
|
984
1271
|
var addressSize = (type) => {
|
|
985
1272
|
const bits = ioScalarBits(type);
|
|
@@ -992,7 +1279,7 @@ function bindStructuredTextIo(objects, bindings) {
|
|
|
992
1279
|
let section = false;
|
|
993
1280
|
let start = 0;
|
|
994
1281
|
for (const [index, token] of tokens.entries()) {
|
|
995
|
-
if (
|
|
1282
|
+
if (variableSections2.has(token.value)) {
|
|
996
1283
|
section = true;
|
|
997
1284
|
start = index + 1;
|
|
998
1285
|
continue;
|
|
@@ -1014,7 +1301,7 @@ function bindStructuredTextIo(objects, bindings) {
|
|
|
1014
1301
|
if (colonIndex < 1) {
|
|
1015
1302
|
continue;
|
|
1016
1303
|
}
|
|
1017
|
-
const names = part.slice(0, colonIndex).filter((t) => t.kind === "word" && !
|
|
1304
|
+
const names = part.slice(0, colonIndex).filter((t) => t.kind === "word" && !qualifiers2.has(t.value) && t.value !== "AT");
|
|
1018
1305
|
const at = part.find((t) => t.value === "AT");
|
|
1019
1306
|
const variables = at ? names.filter((t) => t.start < at.start) : names;
|
|
1020
1307
|
const initializer = part.findIndex((t, index) => index > colonIndex && t.value === ":=");
|
|
@@ -1083,233 +1370,9 @@ import { basename as basename3 } from "node:path";
|
|
|
1083
1370
|
import {
|
|
1084
1371
|
globalSections,
|
|
1085
1372
|
identifierPattern as identifierPattern2,
|
|
1086
|
-
qualifiers as
|
|
1373
|
+
qualifiers as qualifiers3,
|
|
1087
1374
|
variableSections as variableSections3
|
|
1088
1375
|
} from "@tsplc/iec/st";
|
|
1089
|
-
|
|
1090
|
-
// packages/build/src/st/declarations.ts
|
|
1091
|
-
import {
|
|
1092
|
-
conditionalDirective,
|
|
1093
|
-
modifiers,
|
|
1094
|
-
variableSections as variableSections2
|
|
1095
|
-
} from "@tsplc/iec/st";
|
|
1096
|
-
var objectKinds = {
|
|
1097
|
-
PROGRAM: "program",
|
|
1098
|
-
FUNCTION_BLOCK: "function_block",
|
|
1099
|
-
FUNCTIONBLOCK: "function_block",
|
|
1100
|
-
FUNCTION: "function",
|
|
1101
|
-
METHOD: "method",
|
|
1102
|
-
INTERFACE: "interface",
|
|
1103
|
-
PROPERTY: "property"
|
|
1104
|
-
};
|
|
1105
|
-
var closingObjects = new Set(Object.keys(objectKinds).map((kind) => `END_${kind}`));
|
|
1106
|
-
var declarationKeywords = new Set([
|
|
1107
|
-
...Object.keys(objectKinds),
|
|
1108
|
-
...closingObjects,
|
|
1109
|
-
...variableSections2,
|
|
1110
|
-
"END_VAR",
|
|
1111
|
-
"TYPE",
|
|
1112
|
-
"END_TYPE",
|
|
1113
|
-
"STRUCT",
|
|
1114
|
-
"END_STRUCT",
|
|
1115
|
-
"UNION",
|
|
1116
|
-
"END_UNION",
|
|
1117
|
-
"ACTION",
|
|
1118
|
-
"END_ACTION",
|
|
1119
|
-
"CONFIGURATION",
|
|
1120
|
-
"END_CONFIGURATION"
|
|
1121
|
-
]);
|
|
1122
|
-
var isDeclarationPragma = (token) => token?.kind === "pragma" && !conditionalDirective(token.value);
|
|
1123
|
-
var readDeclarationPragmas = (reader) => {
|
|
1124
|
-
while (isDeclarationPragma(reader.peek())) {
|
|
1125
|
-
reader.take();
|
|
1126
|
-
}
|
|
1127
|
-
};
|
|
1128
|
-
var readDeclarationSemicolon = (reader) => {
|
|
1129
|
-
const token = reader.peek();
|
|
1130
|
-
if (token?.value === ";" && !/[\r\n]/.test(reader.source.slice(reader.end, token.start))) {
|
|
1131
|
-
reader.take();
|
|
1132
|
-
}
|
|
1133
|
-
};
|
|
1134
|
-
var readIdentifier = (reader) => {
|
|
1135
|
-
const token = reader.take();
|
|
1136
|
-
if (token.kind !== "word" || declarationKeywords.has(token.value)) {
|
|
1137
|
-
reader.fail("Expected an IEC identifier", token);
|
|
1138
|
-
}
|
|
1139
|
-
return reader.source.slice(token.start, token.end);
|
|
1140
|
-
};
|
|
1141
|
-
var isOverrideModifier = (reader) => {
|
|
1142
|
-
const name = reader.peek(1);
|
|
1143
|
-
return name?.kind === "word" && !declarationKeywords.has(name.value) && !["(", "[", ":=", ".", "^"].includes(reader.peek(2)?.value ?? "") && !/[\r\n]/.test(reader.source.slice(reader.peek()?.end, name.start));
|
|
1144
|
-
};
|
|
1145
|
-
var readModifiers = (reader) => {
|
|
1146
|
-
while (modifiers.has(reader.peek()?.value ?? "")) {
|
|
1147
|
-
if (reader.peek()?.value === "OVERRIDE" && !isOverrideModifier(reader)) {
|
|
1148
|
-
return;
|
|
1149
|
-
}
|
|
1150
|
-
reader.take();
|
|
1151
|
-
}
|
|
1152
|
-
};
|
|
1153
|
-
var typeDelimiters = { "(": ")", "[": "]", "<": ">" };
|
|
1154
|
-
var readDelimitedType = (reader, open) => {
|
|
1155
|
-
reader.expect(open);
|
|
1156
|
-
const closings = [typeDelimiters[open]];
|
|
1157
|
-
while (closings.length) {
|
|
1158
|
-
const token = reader.take();
|
|
1159
|
-
if (token.kind === "string" || token.kind === "pragma") {
|
|
1160
|
-
continue;
|
|
1161
|
-
}
|
|
1162
|
-
if (token.value === "(" || token.value === "[") {
|
|
1163
|
-
closings.push(typeDelimiters[token.value]);
|
|
1164
|
-
} else if (token.value === ")" || token.value === "]") {
|
|
1165
|
-
if (closings.pop() !== token.value) {
|
|
1166
|
-
reader.fail(`Mismatched delimiter ${token.value}`, token);
|
|
1167
|
-
}
|
|
1168
|
-
} else if (open === "<" && closings.at(-1) === ">") {
|
|
1169
|
-
if (token.value === "<") {
|
|
1170
|
-
closings.push(">");
|
|
1171
|
-
}
|
|
1172
|
-
if (token.value === ">") {
|
|
1173
|
-
closings.pop();
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
if (declarationKeywords.has(token.value) || token.value === ";") {
|
|
1177
|
-
reader.fail(`Unclosed ${open}`, token);
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
};
|
|
1181
|
-
var readType = (reader) => {
|
|
1182
|
-
const start = reader.peek()?.start ?? reader.source.length;
|
|
1183
|
-
while (true) {
|
|
1184
|
-
if (["POINTER", "REFERENCE", "REF_TO"].includes(reader.peek()?.value ?? "")) {
|
|
1185
|
-
if (reader.take().value !== "REF_TO") {
|
|
1186
|
-
reader.expect("TO");
|
|
1187
|
-
}
|
|
1188
|
-
continue;
|
|
1189
|
-
}
|
|
1190
|
-
if (reader.consume("ARRAY")) {
|
|
1191
|
-
readDelimitedType(reader, "[");
|
|
1192
|
-
reader.expect("OF");
|
|
1193
|
-
continue;
|
|
1194
|
-
}
|
|
1195
|
-
break;
|
|
1196
|
-
}
|
|
1197
|
-
readIdentifier(reader);
|
|
1198
|
-
while (reader.consume(".")) {
|
|
1199
|
-
readIdentifier(reader);
|
|
1200
|
-
}
|
|
1201
|
-
for (const open of ["(", "[", "<"]) {
|
|
1202
|
-
if (reader.peek()?.value === open) {
|
|
1203
|
-
readDelimitedType(reader, open);
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
return reader.source.slice(start, reader.end);
|
|
1207
|
-
};
|
|
1208
|
-
var readVariableSection = (reader) => {
|
|
1209
|
-
reader.take();
|
|
1210
|
-
const conditionals = [];
|
|
1211
|
-
while (reader.peek()?.value !== "END_VAR") {
|
|
1212
|
-
const token = reader.take();
|
|
1213
|
-
if (variableSections2.has(token.value) || closingObjects.has(token.value)) {
|
|
1214
|
-
reader.fail("Missing END_VAR", token);
|
|
1215
|
-
}
|
|
1216
|
-
const directive = token.kind === "pragma" && conditionalDirective(token.value);
|
|
1217
|
-
if (!directive) {
|
|
1218
|
-
continue;
|
|
1219
|
-
}
|
|
1220
|
-
if (directive === "IF") {
|
|
1221
|
-
conditionals.push({ hasElse: false });
|
|
1222
|
-
continue;
|
|
1223
|
-
}
|
|
1224
|
-
const current = conditionals.at(-1);
|
|
1225
|
-
if (!current) {
|
|
1226
|
-
return reader.fail("Unmatched conditional pragma", token);
|
|
1227
|
-
}
|
|
1228
|
-
if (directive === "END_IF") {
|
|
1229
|
-
conditionals.pop();
|
|
1230
|
-
continue;
|
|
1231
|
-
}
|
|
1232
|
-
if (current.hasElse) {
|
|
1233
|
-
reader.fail("Conditional branch after ELSE", token);
|
|
1234
|
-
}
|
|
1235
|
-
current.hasElse = directive === "ELSE";
|
|
1236
|
-
}
|
|
1237
|
-
if (conditionals.length) {
|
|
1238
|
-
reader.fail("Conditional pragmas must remain inside one variable section");
|
|
1239
|
-
}
|
|
1240
|
-
reader.take();
|
|
1241
|
-
readDeclarationSemicolon(reader);
|
|
1242
|
-
};
|
|
1243
|
-
var readDeclarationSections = (reader) => {
|
|
1244
|
-
while (reader.peek()) {
|
|
1245
|
-
let ahead = 0;
|
|
1246
|
-
while (isDeclarationPragma(reader.peek(ahead))) {
|
|
1247
|
-
ahead++;
|
|
1248
|
-
}
|
|
1249
|
-
const next = reader.peek(ahead)?.value ?? "";
|
|
1250
|
-
if (variableSections2.has(next)) {
|
|
1251
|
-
readDeclarationPragmas(reader);
|
|
1252
|
-
readVariableSection(reader);
|
|
1253
|
-
continue;
|
|
1254
|
-
}
|
|
1255
|
-
if (next !== "EXTENDS" && next !== "IMPLEMENTS") {
|
|
1256
|
-
return;
|
|
1257
|
-
}
|
|
1258
|
-
readDeclarationPragmas(reader);
|
|
1259
|
-
reader.take();
|
|
1260
|
-
readType(reader);
|
|
1261
|
-
while (reader.consume(",")) {
|
|
1262
|
-
readType(reader);
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
};
|
|
1266
|
-
|
|
1267
|
-
// packages/build/src/st/reader.ts
|
|
1268
|
-
var createTokenReader = (source, filename) => {
|
|
1269
|
-
const tokens = tokenize(source, filename);
|
|
1270
|
-
let index = 0;
|
|
1271
|
-
const peek = (ahead = 0) => tokens[index + ahead];
|
|
1272
|
-
const fail = (message, token = peek()) => {
|
|
1273
|
-
throw new StSyntaxError(source, token?.start ?? source.length, filename, message);
|
|
1274
|
-
};
|
|
1275
|
-
const take = () => {
|
|
1276
|
-
const token = peek();
|
|
1277
|
-
if (!token) {
|
|
1278
|
-
return fail("Unexpected end of declaration");
|
|
1279
|
-
}
|
|
1280
|
-
index++;
|
|
1281
|
-
return token;
|
|
1282
|
-
};
|
|
1283
|
-
const expect = (value) => {
|
|
1284
|
-
if (peek()?.value !== value) {
|
|
1285
|
-
fail(`Expected ${value}`);
|
|
1286
|
-
}
|
|
1287
|
-
return take();
|
|
1288
|
-
};
|
|
1289
|
-
const consume = (value) => {
|
|
1290
|
-
if (peek()?.value === value) {
|
|
1291
|
-
return take();
|
|
1292
|
-
}
|
|
1293
|
-
};
|
|
1294
|
-
return {
|
|
1295
|
-
source,
|
|
1296
|
-
filename,
|
|
1297
|
-
tokens,
|
|
1298
|
-
peek,
|
|
1299
|
-
take,
|
|
1300
|
-
expect,
|
|
1301
|
-
consume,
|
|
1302
|
-
fail,
|
|
1303
|
-
get index() {
|
|
1304
|
-
return index;
|
|
1305
|
-
},
|
|
1306
|
-
get end() {
|
|
1307
|
-
return tokens[index - 1]?.end ?? 0;
|
|
1308
|
-
}
|
|
1309
|
-
};
|
|
1310
|
-
};
|
|
1311
|
-
|
|
1312
|
-
// packages/build/src/st/parse.ts
|
|
1313
1376
|
var dutTypes = {
|
|
1314
1377
|
STRUCT: "structure",
|
|
1315
1378
|
UNION: "union",
|
|
@@ -1352,7 +1415,7 @@ var parseGlobals = (reader, options) => {
|
|
|
1352
1415
|
const start = reader.index;
|
|
1353
1416
|
readVariableSection(reader);
|
|
1354
1417
|
for (const token of reader.tokens.slice(start + 1, reader.index)) {
|
|
1355
|
-
if (token.kind !== "word" || !
|
|
1418
|
+
if (token.kind !== "word" || !qualifiers3.has(token.value)) {
|
|
1356
1419
|
break;
|
|
1357
1420
|
}
|
|
1358
1421
|
persistent ||= token.value === "PERSISTENT";
|
|
@@ -1667,24 +1730,26 @@ import { tmpdir as tmpdir4 } from "node:os";
|
|
|
1667
1730
|
import { posix as posix3, resolve as resolve10 } from "node:path";
|
|
1668
1731
|
import { setTimeout as delay2 } from "node:timers/promises";
|
|
1669
1732
|
import { controllerBudgets as controllerBudgets2 } from "@tsplc/config/build";
|
|
1670
|
-
import { z as
|
|
1733
|
+
import { z as z10 } from "zod";
|
|
1671
1734
|
|
|
1672
1735
|
// packages/build/src/controller-session.ts
|
|
1673
1736
|
import { cp as cp5, mkdir as mkdir6, readdir as readdir3, readFile as readFile7, rm as rm6, writeFile as writeFile5 } from "node:fs/promises";
|
|
1674
1737
|
import { resolve as resolve9 } from "node:path";
|
|
1675
1738
|
import {
|
|
1676
1739
|
controllerBudgets,
|
|
1740
|
+
cyclicTasksSchema as cyclicTasksSchema2,
|
|
1677
1741
|
sha256Digest as sha256Digest2
|
|
1678
1742
|
} from "@tsplc/config/build";
|
|
1679
|
-
import { z as
|
|
1680
|
-
var guid =
|
|
1681
|
-
var pointerSchema =
|
|
1682
|
-
schemaVersion:
|
|
1683
|
-
generation:
|
|
1743
|
+
import { z as z9 } from "zod";
|
|
1744
|
+
var guid = z9.string().regex(/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i);
|
|
1745
|
+
var pointerSchema = z9.strictObject({
|
|
1746
|
+
schemaVersion: z9.literal(1),
|
|
1747
|
+
generation: z9.uuid()
|
|
1684
1748
|
});
|
|
1685
1749
|
var baselineSchema = controllerResultSchema.extend({
|
|
1686
|
-
objects:
|
|
1687
|
-
|
|
1750
|
+
objects: z9.array(committedObjectSchema),
|
|
1751
|
+
tasks: cyclicTasksSchema2.optional(),
|
|
1752
|
+
files: z9.record(z9.string(), sha256Digest2),
|
|
1688
1753
|
deviceSettings: sha256Digest2.optional()
|
|
1689
1754
|
});
|
|
1690
1755
|
var controllerDirectory = (outDir) => resolve9(outDir, ".codesys/controller");
|
|
@@ -1705,10 +1770,10 @@ var controllerBaseline = async (outDir) => {
|
|
|
1705
1770
|
return "malformed";
|
|
1706
1771
|
}
|
|
1707
1772
|
};
|
|
1708
|
-
var restoreResultSchema =
|
|
1709
|
-
restored:
|
|
1710
|
-
controllerIds:
|
|
1711
|
-
state:
|
|
1773
|
+
var restoreResultSchema = z9.object({
|
|
1774
|
+
restored: z9.boolean(),
|
|
1775
|
+
controllerIds: z9.strictObject({ codeId: guid, dataId: guid }),
|
|
1776
|
+
state: z9.string()
|
|
1712
1777
|
});
|
|
1713
1778
|
|
|
1714
1779
|
// packages/build/src/controller-online.ts
|
|
@@ -1739,7 +1804,7 @@ var controllerConnection = async (config) => {
|
|
|
1739
1804
|
};
|
|
1740
1805
|
};
|
|
1741
1806
|
var checkReceipt = (result, expected, diagnostics) => {
|
|
1742
|
-
if (result.operationId !== expected.operationId || result.operation !== expected.operation || !sameBaseline(result, expected)) {
|
|
1807
|
+
if (result.operationId !== expected.operationId || result.operation !== expected.operation || result.imageId !== expected.imageId || !sameBaseline(result, expected)) {
|
|
1743
1808
|
throw new Error(`Controller receipt does not match this operation's image, template or target. Inspect ${diagnostics} for diagnostics`);
|
|
1744
1809
|
}
|
|
1745
1810
|
return result;
|
|
@@ -1791,12 +1856,14 @@ var controllerOperation = async (config, operation, options) => {
|
|
|
1791
1856
|
};
|
|
1792
1857
|
var updateController = (config, operation, options = {}) => controllerOperation(config, operation, options);
|
|
1793
1858
|
var inspectController = (config, read, options = {}) => controllerOperation(config, "inspect", { ...options, read });
|
|
1794
|
-
var loginReplySchema =
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
ok:
|
|
1798
|
-
error:
|
|
1799
|
-
downloadRequired:
|
|
1859
|
+
var loginReplySchema = z10.discriminatedUnion("ok", [
|
|
1860
|
+
z10.strictObject({ ok: z10.literal(true), result: z10.unknown() }),
|
|
1861
|
+
z10.strictObject({
|
|
1862
|
+
ok: z10.literal(false),
|
|
1863
|
+
error: z10.string(),
|
|
1864
|
+
downloadRequired: z10.literal(true).optional(),
|
|
1865
|
+
findings: z10.array(onlineChangeFindingSchema).optional(),
|
|
1866
|
+
messages: z10.array(z10.string()).optional(),
|
|
1800
1867
|
rollback: rollbackSchema.optional()
|
|
1801
1868
|
})
|
|
1802
1869
|
]);
|
|
@@ -1835,12 +1902,15 @@ var callContainer = async (name, port, method, body) => {
|
|
|
1835
1902
|
if (reply.rollback) {
|
|
1836
1903
|
throw new TransferFailedError(reply.error, reply.rollback);
|
|
1837
1904
|
}
|
|
1838
|
-
throw reply.downloadRequired || reply.error.endsWith(explicitDownload) ? new DownloadRequiredError(reply.error
|
|
1905
|
+
throw reply.downloadRequired || reply.error.endsWith(explicitDownload) ? new DownloadRequiredError(reply.error, {
|
|
1906
|
+
findings: reply.findings,
|
|
1907
|
+
messages: reply.messages
|
|
1908
|
+
}) : new Error(reply.error);
|
|
1839
1909
|
}
|
|
1840
1910
|
return reply.result;
|
|
1841
1911
|
};
|
|
1842
1912
|
var answers = (name, port) => callContainer(name, port, "GET").then(() => true, () => false);
|
|
1843
|
-
var warmStateSchema =
|
|
1913
|
+
var warmStateSchema = z10.object({ finishing: z10.boolean() });
|
|
1844
1914
|
var finishing = (name) => callContainer(name, warmPort, "GET").then((state) => warmStateSchema.safeParse(state).data?.finishing === true, () => false);
|
|
1845
1915
|
var settleWarmController = async (config, name) => {
|
|
1846
1916
|
const deadline = Date.now() + 2 * controllerBudgets2(config.timeouts).prepare;
|
|
@@ -1998,7 +2068,7 @@ var followProgress = (log, report) => {
|
|
|
1998
2068
|
var startWarmController = async (config, name) => {
|
|
1999
2069
|
await warmController(config, name, await controllerConnection(config), () => {});
|
|
2000
2070
|
};
|
|
2001
|
-
var
|
|
2071
|
+
var warmOperation = async (config, name, operation, options) => {
|
|
2002
2072
|
const report = options.onProgress ?? (() => {});
|
|
2003
2073
|
const connection = await controllerConnection(config);
|
|
2004
2074
|
const operationId = randomUUID3();
|
|
@@ -2018,7 +2088,7 @@ var updateWarmController = async (config, name, operation, options = {}) => {
|
|
|
2018
2088
|
operation,
|
|
2019
2089
|
operationId,
|
|
2020
2090
|
request,
|
|
2021
|
-
initializeUser: options.initializeUser
|
|
2091
|
+
initializeUser: options.initializeUser,
|
|
2022
2092
|
credentials: options.credentials
|
|
2023
2093
|
}).catch((error) => {
|
|
2024
2094
|
const message = `${failureReason(error)}. Inspect ${diagnostics} for diagnostics`;
|
|
@@ -2026,20 +2096,51 @@ var updateWarmController = async (config, name, operation, options = {}) => {
|
|
|
2026
2096
|
if (rollback) {
|
|
2027
2097
|
throw new TransferFailedError(message, rollback, { cause: error });
|
|
2028
2098
|
}
|
|
2029
|
-
throw
|
|
2099
|
+
throw error instanceof DownloadRequiredError ? new DownloadRequiredError(message, {
|
|
2100
|
+
cause: error,
|
|
2101
|
+
findings: error.findings,
|
|
2102
|
+
messages: error.messages
|
|
2103
|
+
}) : new Error(message, { cause: error });
|
|
2030
2104
|
});
|
|
2031
|
-
return
|
|
2032
|
-
operationId,
|
|
2033
|
-
operation,
|
|
2034
|
-
imageId: connection.imageId,
|
|
2035
|
-
templateHash: connection.templateHash,
|
|
2036
|
-
target: connection.target
|
|
2037
|
-
}, diagnostics);
|
|
2105
|
+
return { result, connection, operationId, diagnostics };
|
|
2038
2106
|
} finally {
|
|
2039
2107
|
await stopFollowing();
|
|
2040
2108
|
await rm7(directory, { recursive: true, force: true });
|
|
2041
2109
|
}
|
|
2042
2110
|
};
|
|
2111
|
+
var reviewWarmController = async (config, name, options) => {
|
|
2112
|
+
try {
|
|
2113
|
+
const { result } = await warmOperation(config, name, "review", {
|
|
2114
|
+
...options,
|
|
2115
|
+
initializeUser: false
|
|
2116
|
+
});
|
|
2117
|
+
return {
|
|
2118
|
+
possible: true,
|
|
2119
|
+
findings: reviewReplySchema.parse(result).findings,
|
|
2120
|
+
messages: []
|
|
2121
|
+
};
|
|
2122
|
+
} catch (error) {
|
|
2123
|
+
if (!(error instanceof DownloadRequiredError)) {
|
|
2124
|
+
throw error;
|
|
2125
|
+
}
|
|
2126
|
+
const explained = error.messages.length > 0 || error.findings.some((finding) => finding.refuses);
|
|
2127
|
+
return {
|
|
2128
|
+
possible: false,
|
|
2129
|
+
findings: error.findings,
|
|
2130
|
+
messages: explained ? error.messages : [failureReason(error.cause)]
|
|
2131
|
+
};
|
|
2132
|
+
}
|
|
2133
|
+
};
|
|
2134
|
+
var updateWarmController = async (config, name, operation, options = {}) => {
|
|
2135
|
+
const { result, connection, operationId, diagnostics } = await warmOperation(config, name, operation, { ...options, initializeUser: options.initializeUser ?? false });
|
|
2136
|
+
return checkReceipt(controllerResultSchema.parse(result), {
|
|
2137
|
+
operationId,
|
|
2138
|
+
operation,
|
|
2139
|
+
imageId: connection.imageId,
|
|
2140
|
+
templateHash: connection.templateHash,
|
|
2141
|
+
target: connection.target
|
|
2142
|
+
}, diagnostics);
|
|
2143
|
+
};
|
|
2043
2144
|
// packages/build/src/engineering-settings.ts
|
|
2044
2145
|
import {
|
|
2045
2146
|
controllerFor,
|
|
@@ -2056,21 +2157,21 @@ import { mkdir as mkdir8, readFile as readFile9, rename as rename3, writeFile as
|
|
|
2056
2157
|
import { basename as basename5, relative as relative3, resolve as resolve11 } from "node:path";
|
|
2057
2158
|
import { sha256Digest as sha256Digest3 } from "@tsplc/config/build";
|
|
2058
2159
|
import { generatedDirectory } from "@tsplc/config/project-files";
|
|
2059
|
-
import { z as
|
|
2160
|
+
import { z as z11 } from "zod";
|
|
2060
2161
|
var libraryRegistry = "https://store-archive.codesys.com/CODESYSLibs";
|
|
2061
2162
|
var libraryFile = /\.(?:compiled-library(?:-v\d+)?|library)$/i;
|
|
2062
|
-
var installedLibrarySchema =
|
|
2063
|
-
title:
|
|
2064
|
-
company:
|
|
2065
|
-
version:
|
|
2066
|
-
namespace:
|
|
2067
|
-
path:
|
|
2163
|
+
var installedLibrarySchema = z11.object({
|
|
2164
|
+
title: z11.string(),
|
|
2165
|
+
company: z11.string().optional(),
|
|
2166
|
+
version: z11.string().optional(),
|
|
2167
|
+
namespace: z11.string().optional(),
|
|
2168
|
+
path: z11.string(),
|
|
2068
2169
|
sha256: sha256Digest3,
|
|
2069
|
-
url:
|
|
2170
|
+
url: z11.string().optional()
|
|
2070
2171
|
});
|
|
2071
|
-
var libraryLockSchema =
|
|
2072
|
-
version:
|
|
2073
|
-
dependencies:
|
|
2172
|
+
var libraryLockSchema = z11.object({
|
|
2173
|
+
version: z11.literal(1),
|
|
2174
|
+
dependencies: z11.record(z11.string(), installedLibrarySchema)
|
|
2074
2175
|
});
|
|
2075
2176
|
var readLock = async (file) => {
|
|
2076
2177
|
const text = await readFile9(file, "utf8").catch((cause) => {
|
|
@@ -2254,7 +2355,7 @@ import { mkdtemp as mkdtemp5, readFile as readFile10, rm as rm8, writeFile as wr
|
|
|
2254
2355
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
2255
2356
|
import { basename as basename6, dirname as dirname2, join } from "node:path";
|
|
2256
2357
|
import { setTimeout as delay3 } from "node:timers/promises";
|
|
2257
|
-
import { z as
|
|
2358
|
+
import { z as z12 } from "zod";
|
|
2258
2359
|
|
|
2259
2360
|
// packages/build/src/runtime-status.ts
|
|
2260
2361
|
var getApplicationStatus = (log, application, startedAt) => {
|
|
@@ -2272,9 +2373,9 @@ var getApplicationStatus = (log, application, startedAt) => {
|
|
|
2272
2373
|
};
|
|
2273
2374
|
|
|
2274
2375
|
// packages/build/src/run.ts
|
|
2275
|
-
var stateSchema =
|
|
2276
|
-
Running:
|
|
2277
|
-
StartedAt:
|
|
2376
|
+
var stateSchema = z12.object({
|
|
2377
|
+
Running: z12.boolean(),
|
|
2378
|
+
StartedAt: z12.iso.datetime({ offset: true })
|
|
2278
2379
|
});
|
|
2279
2380
|
var service = "plc";
|
|
2280
2381
|
var runtimeProject = (name) => name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().replace(/[^a-z0-9_-]+/g, "-");
|
|
@@ -2344,6 +2445,7 @@ ${log.split(`
|
|
|
2344
2445
|
});
|
|
2345
2446
|
export {
|
|
2346
2447
|
CodesysCompilerError,
|
|
2448
|
+
DownloadRequiredError,
|
|
2347
2449
|
StSyntaxError,
|
|
2348
2450
|
TransferFailedError,
|
|
2349
2451
|
buildProject,
|
|
@@ -2356,6 +2458,7 @@ export {
|
|
|
2356
2458
|
configureRuntime,
|
|
2357
2459
|
controllerBaseline,
|
|
2358
2460
|
defineBuildConfig as defineConfig,
|
|
2461
|
+
describeFinding,
|
|
2359
2462
|
explicitDownload,
|
|
2360
2463
|
failureReason,
|
|
2361
2464
|
findControllerLogin,
|
|
@@ -2368,6 +2471,7 @@ export {
|
|
|
2368
2471
|
loadSources,
|
|
2369
2472
|
loginCommandSchema,
|
|
2370
2473
|
loginResultSchema,
|
|
2474
|
+
onlineChangeFindingSchema,
|
|
2371
2475
|
openControllerLogin,
|
|
2372
2476
|
parseSource,
|
|
2373
2477
|
progressLog,
|
|
@@ -2375,6 +2479,7 @@ export {
|
|
|
2375
2479
|
readBuild,
|
|
2376
2480
|
requiresDownload,
|
|
2377
2481
|
resolveConfig3 as resolveConfig,
|
|
2482
|
+
reviewWarmController,
|
|
2378
2483
|
rollbackSchema,
|
|
2379
2484
|
runProject,
|
|
2380
2485
|
settleWarmController,
|
|
@@ -2387,5 +2492,5 @@ export {
|
|
|
2387
2492
|
workerScriptsDigest
|
|
2388
2493
|
};
|
|
2389
2494
|
|
|
2390
|
-
//# debugId=
|
|
2495
|
+
//# debugId=A397B881BE772B7E64756E2164756E21
|
|
2391
2496
|
//# sourceMappingURL=index.js.map
|