@tsplc/build 0.5.9 → 0.5.12

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/index.js CHANGED
@@ -671,7 +671,7 @@ import {
671
671
  } from "node:fs/promises";
672
672
  import { resolve as resolve7 } from "node:path";
673
673
  import { setTimeout as delay } from "node:timers/promises";
674
- import { z as z7 } from "zod";
674
+ import { z as z8 } from "zod";
675
675
 
676
676
  // packages/build/src/controller-protocol.ts
677
677
  import {
@@ -679,47 +679,413 @@ import {
679
679
  sha256Digest,
680
680
  tcpPort
681
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";
682
686
  import { z as z5 } from "zod";
683
- var imageIdSchema = z5.string().regex(/^sha256:[a-f0-9]{64}$/);
684
- var endpointSchema = z5.strictObject({
685
- host: z5.string().nonempty(),
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(),
686
1041
  port: tcpPort
687
1042
  });
688
- var controllerResultSchema = z5.strictObject({
689
- schemaVersion: z5.literal(1),
690
- operationId: z5.uuid(),
691
- operation: z5.enum(["download", "online-change", "inspect"]),
1043
+ var controllerResultSchema = z6.strictObject({
1044
+ schemaVersion: z6.literal(1),
1045
+ operationId: z6.uuid(),
1046
+ operation: z6.enum(["download", "online-change", "inspect"]),
692
1047
  imageId: imageIdSchema,
693
1048
  engineering: sha256Digest.optional(),
694
1049
  templateHash: sha256Digest,
695
- target: z5.strictObject({
696
- network: z5.string().nonempty(),
1050
+ target: z6.strictObject({
1051
+ network: z6.string().nonempty(),
697
1052
  gateway: endpointSchema,
698
1053
  device: endpointSchema,
699
1054
  controller: controllerSchema.optional(),
700
1055
  deviceTree: sha256Digest.optional()
701
1056
  }),
702
- generation: z5.string().nonempty(),
703
- application: z5.string().nonempty(),
704
- applicationGuid: z5.string().nonempty(),
705
- controllerIds: z5.strictObject({
706
- codeId: z5.string().nonempty(),
707
- dataId: z5.string().nonempty()
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()
708
1063
  }),
709
- state: z5.string().nonempty(),
710
- values: z5.record(z5.string(), z5.string())
1064
+ state: z6.string().nonempty(),
1065
+ values: z6.record(z6.string(), z6.string())
711
1066
  });
712
- var controllerCredentialsSchema = z5.strictObject({
713
- username: z5.string().nonempty(),
714
- password: z5.string().nonempty()
1067
+ var controllerCredentialsSchema = z6.strictObject({
1068
+ username: z6.string().nonempty(),
1069
+ password: z6.string().nonempty()
715
1070
  });
716
- var warmOperationSchema = z5.strictObject({
717
- operation: z5.enum(["download", "online-change"]),
718
- operationId: z5.uuid(),
719
- request: z5.string().nonempty(),
720
- initializeUser: z5.boolean(),
1071
+ var resetKindSchema = z6.enum(["Warm", "Cold"]);
1072
+ var warmRequest = {
1073
+ operationId: z6.uuid(),
1074
+ request: z6.string().nonempty(),
721
1075
  credentials: controllerCredentialsSchema.optional()
722
- });
1076
+ };
1077
+ var warmOperationSchema = z6.discriminatedUnion("operation", [
1078
+ z6.strictObject({
1079
+ operation: z6.enum(["download", "online-change", "review"]),
1080
+ ...warmRequest,
1081
+ initializeUser: z6.boolean()
1082
+ }),
1083
+ z6.strictObject({
1084
+ operation: z6.literal("restart"),
1085
+ ...warmRequest,
1086
+ reset: resetKindSchema
1087
+ })
1088
+ ]);
723
1089
  var tracebackFailure = (traceback) => {
724
1090
  const text = traceback.trim();
725
1091
  const lastFrame = text.lastIndexOf(`
@@ -748,8 +1114,19 @@ var explicitDownload = "use an explicit download";
748
1114
 
749
1115
  class DownloadRequiredError extends Error {
750
1116
  downloadRequired = true;
1117
+ findings;
1118
+ messages;
1119
+ constructor(message, options = {}) {
1120
+ super(message, options);
1121
+ this.findings = options.findings ?? [];
1122
+ this.messages = options.messages ?? [];
1123
+ }
751
1124
  }
752
- var rollbackSchema = z5.enum([
1125
+ var restartReplySchema = z6.strictObject({ state: z6.string() });
1126
+ var reviewReplySchema = z6.strictObject({
1127
+ findings: z6.array(onlineChangeFindingSchema)
1128
+ });
1129
+ var rollbackSchema = z6.enum([
753
1130
  "intact",
754
1131
  "restored",
755
1132
  "failed",
@@ -770,30 +1147,27 @@ var transferRollback = (error) => {
770
1147
  return rollbackSchema.safeParse(error.rollback).data;
771
1148
  };
772
1149
  var requiresDownload = (error) => error instanceof Error && ("downloadRequired" in error) && error.downloadRequired === true;
773
- var loginCommandSchema = z5.discriminatedUnion("command", [
774
- z5.strictObject({ command: z5.literal("state") }),
775
- z5.strictObject({
776
- command: z5.literal("read"),
777
- expressions: z5.array(z5.string().nonempty()).nonempty()
1150
+ var loginCommandSchema = z6.discriminatedUnion("command", [
1151
+ z6.strictObject({ command: z6.literal("state") }),
1152
+ z6.strictObject({
1153
+ command: z6.literal("read"),
1154
+ expressions: z6.array(z6.string().nonempty()).nonempty()
778
1155
  }),
779
- z5.strictObject({
780
- command: z5.enum(["write", "force"]),
781
- values: z5.record(z5.string().nonempty(), z5.string().nonempty())
1156
+ z6.strictObject({
1157
+ command: z6.enum(["write", "force"]),
1158
+ values: z6.record(z6.string().nonempty(), z6.string().nonempty())
782
1159
  }),
783
- z5.strictObject({
784
- command: z5.literal("unforce"),
785
- expressions: z5.array(z5.string().nonempty()),
786
- restore: z5.boolean()
1160
+ z6.strictObject({
1161
+ command: z6.literal("unforce"),
1162
+ expressions: z6.array(z6.string().nonempty()),
1163
+ restore: z6.boolean()
787
1164
  }),
788
- z5.strictObject({ command: z5.enum(["start", "stop"]) }),
789
- z5.strictObject({
790
- command: z5.literal("reset"),
791
- kind: z5.enum(["Warm", "Cold"])
792
- })
1165
+ z6.strictObject({ command: z6.enum(["start", "stop"]) }),
1166
+ z6.strictObject({ command: z6.literal("reset"), kind: resetKindSchema })
793
1167
  ]);
794
- var loginResultSchema = z5.union([
795
- z5.strictObject({ values: z5.record(z5.string(), z5.string()) }),
796
- z5.strictObject({ state: z5.string(), forced: z5.array(z5.string()) })
1168
+ var loginResultSchema = z6.union([
1169
+ z6.strictObject({ values: z6.record(z6.string(), z6.string()) }),
1170
+ z6.strictObject({ state: z6.string(), forced: z6.array(z6.string()) })
797
1171
  ]);
798
1172
 
799
1173
  // packages/build/src/host/codesys-command.ts
@@ -811,7 +1185,7 @@ var codesysCommand = [
811
1185
  // packages/build/src/host/codesys-host.ts
812
1186
  import { execFile as execFile3, spawn as spawn2 } from "node:child_process";
813
1187
  import { promisify as promisify3 } from "node:util";
814
- import { z as z6 } from "zod";
1188
+ import { z as z7 } from "zod";
815
1189
 
816
1190
  // packages/build/src/host/windows-path.ts
817
1191
  import { execFile as execFile2 } from "node:child_process";
@@ -824,10 +1198,10 @@ var execute2 = promisify2(execFile2);
824
1198
 
825
1199
  // packages/build/src/host/codesys-host.ts
826
1200
  var execute3 = promisify3(execFile3);
827
- var exitSchema = z6.object({
828
- pid: z6.int().positive(),
829
- code: z6.int().nullable(),
830
- signal: z6.string().nullable()
1201
+ var exitSchema = z7.object({
1202
+ pid: z7.int().positive(),
1203
+ code: z7.int().nullable(),
1204
+ signal: z7.string().nullable()
831
1205
  });
832
1206
 
833
1207
  // packages/build/src/host/codesys-worker.ts
@@ -840,12 +1214,12 @@ var workerScripts = [
840
1214
  "codesys_login.py"
841
1215
  ];
842
1216
  var workerScriptsDigest = async () => createHash4("sha256").update(JSON.stringify(await Promise.all(workerScripts.map((script) => readFile5(resolve7(pythonDirectory, script), "utf8"))))).digest("hex");
843
- var sessionSchema = z7.object({
844
- directory: z7.string(),
845
- fingerprint: z7.string(),
846
- pid: z7.int().positive()
1217
+ var sessionSchema = z8.object({
1218
+ directory: z8.string(),
1219
+ fingerprint: z8.string(),
1220
+ pid: z8.int().positive()
847
1221
  });
848
- var phaseSchema = z7.enum(["prepare", "transfer"]);
1222
+ var phaseSchema = z8.enum(["prepare", "transfer"]);
849
1223
  var hasCode = (error, code) => error instanceof Error && ("code" in error) && error.code === code;
850
1224
  var isProcessAlive = (pid) => {
851
1225
  try {
@@ -900,103 +1274,8 @@ import { basename as basename4, resolve as resolve8 } from "node:path";
900
1274
  import { identifierPattern as identifierPattern3 } from "@tsplc/iec/st";
901
1275
 
902
1276
  // packages/build/src/io.ts
903
- import { ioArray, ioScalarBits, sizePrefix } from "@tsplc/iec";
904
- import { qualifiers, variableSections } from "@tsplc/iec/st";
905
-
906
- // packages/build/src/st/lexer.ts
907
- import { blockCommentEnd, lineCommentEnd, stringEnd } from "@tsplc/iec/st";
908
-
909
- class StSyntaxError extends Error {
910
- constructor(source, offset, filename, message) {
911
- const lines = source.slice(0, offset).split(/\r\n|\r|\n/);
912
- super(`${filename}:${lines.length}:${(lines.at(-1)?.length ?? 0) + 1}: ${message}`);
913
- this.name = "StSyntaxError";
914
- }
915
- }
916
- var tokenize = (source, filename = "<source>") => {
917
- const tokens = [];
918
- let offset = 0;
919
- const fail = (start, message) => {
920
- throw new StSyntaxError(source, start, filename, message);
921
- };
922
- const quoted = () => {
923
- offset = stringEnd(source, offset) ?? fail(offset, "Unterminated string");
924
- };
925
- while (offset < source.length) {
926
- const start = offset;
927
- const character = source[offset] ?? "";
928
- if (/\s|\uFEFF/.test(character)) {
929
- offset++;
930
- continue;
931
- }
932
- if (source.startsWith("//", offset)) {
933
- offset = lineCommentEnd(source, start);
934
- continue;
935
- }
936
- if (source.startsWith("(*", offset)) {
937
- offset = blockCommentEnd(source, start) ?? fail(start, "Unterminated block comment");
938
- continue;
939
- }
940
- if (character === "'" || character === '"') {
941
- quoted();
942
- tokens.push({
943
- kind: "string",
944
- value: source.slice(start, offset),
945
- start,
946
- end: offset
947
- });
948
- continue;
949
- }
950
- if (character === "{") {
951
- offset++;
952
- while (offset < source.length && source[offset] !== "}") {
953
- if (source[offset] === "'" || source[offset] === '"') {
954
- quoted();
955
- } else {
956
- offset++;
957
- }
958
- }
959
- if (offset === source.length) {
960
- fail(start, "Unterminated pragma");
961
- }
962
- offset++;
963
- tokens.push({
964
- kind: "pragma",
965
- value: source.slice(start, offset),
966
- start,
967
- end: offset
968
- });
969
- continue;
970
- }
971
- if (/[A-Za-z_]/.test(character)) {
972
- offset++;
973
- while (/[A-Za-z_0-9]/.test(source[offset] ?? "")) {
974
- offset++;
975
- }
976
- tokens.push({
977
- kind: "word",
978
- value: source.slice(start, offset).toUpperCase(),
979
- start,
980
- end: offset
981
- });
982
- continue;
983
- }
984
- offset++;
985
- const pair = source.slice(start, offset + 1);
986
- if ([":=", "=>", "..", "<=", ">=", "<>", "**"].includes(pair)) {
987
- offset++;
988
- }
989
- tokens.push({
990
- kind: "symbol",
991
- value: source.slice(start, offset),
992
- start,
993
- end: offset
994
- });
995
- }
996
- return tokens;
997
- };
998
-
999
- // packages/build/src/io.ts
1277
+ import { ioArray, ioScalarBits, sizePrefix } from "@tsplc/iec";
1278
+ import { qualifiers as qualifiers2, variableSections as variableSections2 } from "@tsplc/iec/st";
1000
1279
  var span = (type) => ioArray(type) ?? { element: type, length: 1 };
1001
1280
  var addressSize = (type) => {
1002
1281
  const bits = ioScalarBits(type);
@@ -1009,7 +1288,7 @@ function bindStructuredTextIo(objects, bindings) {
1009
1288
  let section = false;
1010
1289
  let start = 0;
1011
1290
  for (const [index, token] of tokens.entries()) {
1012
- if (variableSections.has(token.value)) {
1291
+ if (variableSections2.has(token.value)) {
1013
1292
  section = true;
1014
1293
  start = index + 1;
1015
1294
  continue;
@@ -1031,7 +1310,7 @@ function bindStructuredTextIo(objects, bindings) {
1031
1310
  if (colonIndex < 1) {
1032
1311
  continue;
1033
1312
  }
1034
- const names = part.slice(0, colonIndex).filter((t) => t.kind === "word" && !qualifiers.has(t.value) && t.value !== "AT");
1313
+ const names = part.slice(0, colonIndex).filter((t) => t.kind === "word" && !qualifiers2.has(t.value) && t.value !== "AT");
1035
1314
  const at = part.find((t) => t.value === "AT");
1036
1315
  const variables = at ? names.filter((t) => t.start < at.start) : names;
1037
1316
  const initializer = part.findIndex((t, index) => index > colonIndex && t.value === ":=");
@@ -1103,242 +1382,6 @@ import {
1103
1382
  qualifiers as qualifiers3,
1104
1383
  variableSections as variableSections3
1105
1384
  } from "@tsplc/iec/st";
1106
-
1107
- // packages/build/src/st/declarations.ts
1108
- import {
1109
- conditionalDirective,
1110
- modifiers,
1111
- qualifiers as qualifiers2,
1112
- variableSections as variableSections2
1113
- } from "@tsplc/iec/st";
1114
-
1115
- // packages/build/src/st/reader.ts
1116
- var createTokenReader = (source, filename) => {
1117
- const tokens = tokenize(source, filename);
1118
- let index = 0;
1119
- const peek = (ahead = 0) => tokens[index + ahead];
1120
- const fail = (message, token = peek()) => {
1121
- throw new StSyntaxError(source, token?.start ?? source.length, filename, message);
1122
- };
1123
- const take = () => {
1124
- const token = peek();
1125
- if (!token) {
1126
- return fail("Unexpected end of declaration");
1127
- }
1128
- index++;
1129
- return token;
1130
- };
1131
- const expect = (value) => {
1132
- if (peek()?.value !== value) {
1133
- fail(`Expected ${value}`);
1134
- }
1135
- return take();
1136
- };
1137
- const consume = (value) => {
1138
- if (peek()?.value === value) {
1139
- return take();
1140
- }
1141
- };
1142
- return {
1143
- source,
1144
- filename,
1145
- tokens,
1146
- peek,
1147
- take,
1148
- expect,
1149
- consume,
1150
- fail,
1151
- get index() {
1152
- return index;
1153
- },
1154
- get end() {
1155
- return tokens[index - 1]?.end ?? 0;
1156
- }
1157
- };
1158
- };
1159
-
1160
- // packages/build/src/st/declarations.ts
1161
- var objectKinds = {
1162
- PROGRAM: "program",
1163
- FUNCTION_BLOCK: "function_block",
1164
- FUNCTIONBLOCK: "function_block",
1165
- FUNCTION: "function",
1166
- METHOD: "method",
1167
- INTERFACE: "interface",
1168
- PROPERTY: "property"
1169
- };
1170
- var closingObjects = new Set(Object.keys(objectKinds).map((kind) => `END_${kind}`));
1171
- var declarationKeywords = new Set([
1172
- ...Object.keys(objectKinds),
1173
- ...closingObjects,
1174
- ...variableSections2,
1175
- "END_VAR",
1176
- "TYPE",
1177
- "END_TYPE",
1178
- "STRUCT",
1179
- "END_STRUCT",
1180
- "UNION",
1181
- "END_UNION",
1182
- "ACTION",
1183
- "END_ACTION",
1184
- "CONFIGURATION",
1185
- "END_CONFIGURATION"
1186
- ]);
1187
- var isDeclarationPragma = (token) => token?.kind === "pragma" && !conditionalDirective(token.value);
1188
- var readDeclarationPragmas = (reader) => {
1189
- while (isDeclarationPragma(reader.peek())) {
1190
- reader.take();
1191
- }
1192
- };
1193
- var readDeclarationSemicolon = (reader) => {
1194
- const token = reader.peek();
1195
- if (token?.value === ";" && !/[\r\n]/.test(reader.source.slice(reader.end, token.start))) {
1196
- reader.take();
1197
- }
1198
- };
1199
- var readIdentifier = (reader) => {
1200
- const token = reader.take();
1201
- if (token.kind !== "word" || declarationKeywords.has(token.value)) {
1202
- reader.fail("Expected an IEC identifier", token);
1203
- }
1204
- return reader.source.slice(token.start, token.end);
1205
- };
1206
- var isOverrideModifier = (reader) => {
1207
- const name = reader.peek(1);
1208
- return name?.kind === "word" && !declarationKeywords.has(name.value) && !["(", "[", ":=", ".", "^"].includes(reader.peek(2)?.value ?? "") && !/[\r\n]/.test(reader.source.slice(reader.peek()?.end, name.start));
1209
- };
1210
- var readModifiers = (reader) => {
1211
- while (modifiers.has(reader.peek()?.value ?? "")) {
1212
- if (reader.peek()?.value === "OVERRIDE" && !isOverrideModifier(reader)) {
1213
- return;
1214
- }
1215
- reader.take();
1216
- }
1217
- };
1218
- var typeDelimiters = { "(": ")", "[": "]", "<": ">" };
1219
- var readDelimitedType = (reader, open) => {
1220
- reader.expect(open);
1221
- const closings = [typeDelimiters[open]];
1222
- while (closings.length) {
1223
- const token = reader.take();
1224
- if (token.kind === "string" || token.kind === "pragma") {
1225
- continue;
1226
- }
1227
- if (token.value === "(" || token.value === "[") {
1228
- closings.push(typeDelimiters[token.value]);
1229
- } else if (token.value === ")" || token.value === "]") {
1230
- if (closings.pop() !== token.value) {
1231
- reader.fail(`Mismatched delimiter ${token.value}`, token);
1232
- }
1233
- } else if (open === "<" && closings.at(-1) === ">") {
1234
- if (token.value === "<") {
1235
- closings.push(">");
1236
- }
1237
- if (token.value === ">") {
1238
- closings.pop();
1239
- }
1240
- }
1241
- if (declarationKeywords.has(token.value) || token.value === ";") {
1242
- reader.fail(`Unclosed ${open}`, token);
1243
- }
1244
- }
1245
- };
1246
- var readType = (reader) => {
1247
- const start = reader.peek()?.start ?? reader.source.length;
1248
- while (true) {
1249
- if (["POINTER", "REFERENCE", "REF_TO"].includes(reader.peek()?.value ?? "")) {
1250
- if (reader.take().value !== "REF_TO") {
1251
- reader.expect("TO");
1252
- }
1253
- continue;
1254
- }
1255
- if (reader.consume("ARRAY")) {
1256
- readDelimitedType(reader, "[");
1257
- reader.expect("OF");
1258
- continue;
1259
- }
1260
- break;
1261
- }
1262
- readIdentifier(reader);
1263
- while (reader.consume(".")) {
1264
- readIdentifier(reader);
1265
- }
1266
- for (const open of ["(", "[", "<"]) {
1267
- if (reader.peek()?.value === open) {
1268
- readDelimitedType(reader, open);
1269
- }
1270
- }
1271
- return reader.source.slice(start, reader.end);
1272
- };
1273
- var readVariableSection = (reader) => {
1274
- reader.take();
1275
- const conditionals = [];
1276
- while (reader.peek()?.value !== "END_VAR") {
1277
- const token = reader.take();
1278
- if (variableSections2.has(token.value) || closingObjects.has(token.value)) {
1279
- reader.fail("Missing END_VAR", token);
1280
- }
1281
- const directive = token.kind === "pragma" && conditionalDirective(token.value);
1282
- if (!directive) {
1283
- continue;
1284
- }
1285
- if (directive === "IF") {
1286
- conditionals.push({ hasElse: false });
1287
- continue;
1288
- }
1289
- const current = conditionals.at(-1);
1290
- if (!current) {
1291
- return reader.fail("Unmatched conditional pragma", token);
1292
- }
1293
- if (directive === "END_IF") {
1294
- conditionals.pop();
1295
- continue;
1296
- }
1297
- if (current.hasElse) {
1298
- reader.fail("Conditional branch after ELSE", token);
1299
- }
1300
- current.hasElse = directive === "ELSE";
1301
- }
1302
- if (conditionals.length) {
1303
- reader.fail("Conditional pragmas must remain inside one variable section");
1304
- }
1305
- reader.take();
1306
- readDeclarationSemicolon(reader);
1307
- };
1308
- var readDeclarationSections = (reader) => {
1309
- while (reader.peek()) {
1310
- let ahead = 0;
1311
- while (isDeclarationPragma(reader.peek(ahead))) {
1312
- ahead++;
1313
- }
1314
- const next = reader.peek(ahead)?.value ?? "";
1315
- if (variableSections2.has(next)) {
1316
- readDeclarationPragmas(reader);
1317
- readVariableSection(reader);
1318
- continue;
1319
- }
1320
- if (next !== "EXTENDS" && next !== "IMPLEMENTS") {
1321
- return;
1322
- }
1323
- readDeclarationPragmas(reader);
1324
- reader.take();
1325
- readType(reader);
1326
- while (reader.consume(",")) {
1327
- readType(reader);
1328
- }
1329
- }
1330
- };
1331
- var keptSections = new Set([
1332
- "VAR",
1333
- "VAR_INPUT",
1334
- "VAR_OUTPUT",
1335
- "VAR_IN_OUT",
1336
- "VAR_STAT",
1337
- "VAR_INST",
1338
- "VAR_GLOBAL"
1339
- ]);
1340
-
1341
- // packages/build/src/st/parse.ts
1342
1385
  var dutTypes = {
1343
1386
  STRUCT: "structure",
1344
1387
  UNION: "union",
@@ -1707,18 +1750,6 @@ import {
1707
1750
  sha256Digest as sha256Digest2
1708
1751
  } from "@tsplc/config/build";
1709
1752
  import { z as z9 } from "zod";
1710
-
1711
- // packages/build/src/online-change-check.ts
1712
- import { elementaryType } from "@tsplc/iec";
1713
- import { z as z8 } from "zod";
1714
- var committedObjectSchema = z8.lazy(() => z8.looseObject({
1715
- kind: z8.string(),
1716
- name: z8.string(),
1717
- declaration: z8.string(),
1718
- children: z8.array(committedObjectSchema).optional()
1719
- }));
1720
-
1721
- // packages/build/src/controller-session.ts
1722
1753
  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);
1723
1754
  var pointerSchema = z9.strictObject({
1724
1755
  schemaVersion: z9.literal(1),
@@ -1840,6 +1871,8 @@ var loginReplySchema = z10.discriminatedUnion("ok", [
1840
1871
  ok: z10.literal(false),
1841
1872
  error: z10.string(),
1842
1873
  downloadRequired: z10.literal(true).optional(),
1874
+ findings: z10.array(onlineChangeFindingSchema).optional(),
1875
+ messages: z10.array(z10.string()).optional(),
1843
1876
  rollback: rollbackSchema.optional()
1844
1877
  })
1845
1878
  ]);
@@ -1878,7 +1911,10 @@ var callContainer = async (name, port, method, body) => {
1878
1911
  if (reply.rollback) {
1879
1912
  throw new TransferFailedError(reply.error, reply.rollback);
1880
1913
  }
1881
- throw reply.downloadRequired || reply.error.endsWith(explicitDownload) ? new DownloadRequiredError(reply.error) : new Error(reply.error);
1914
+ throw reply.downloadRequired || reply.error.endsWith(explicitDownload) ? new DownloadRequiredError(reply.error, {
1915
+ findings: reply.findings,
1916
+ messages: reply.messages
1917
+ }) : new Error(reply.error);
1882
1918
  }
1883
1919
  return reply.result;
1884
1920
  };
@@ -2041,7 +2077,7 @@ var followProgress = (log, report) => {
2041
2077
  var startWarmController = async (config, name) => {
2042
2078
  await warmController(config, name, await controllerConnection(config), () => {});
2043
2079
  };
2044
- var updateWarmController = async (config, name, operation, options = {}) => {
2080
+ var warmOperation = async (config, name, operation, options) => {
2045
2081
  const report = options.onProgress ?? (() => {});
2046
2082
  const connection = await controllerConnection(config);
2047
2083
  const operationId = randomUUID3();
@@ -2058,10 +2094,9 @@ var updateWarmController = async (config, name, operation, options = {}) => {
2058
2094
  const stopFollowing = options.onProgress ? followProgress(jobProgressLog(config.outDir, operationId), options.onProgress) : async () => {};
2059
2095
  try {
2060
2096
  const result = await callContainer(name, warmPort, "POST", {
2061
- operation,
2097
+ ...operation,
2062
2098
  operationId,
2063
2099
  request,
2064
- initializeUser: options.initializeUser ?? false,
2065
2100
  credentials: options.credentials
2066
2101
  }).catch((error) => {
2067
2102
  const message = `${failureReason(error)}. Inspect ${diagnostics} for diagnostics`;
@@ -2069,20 +2104,52 @@ var updateWarmController = async (config, name, operation, options = {}) => {
2069
2104
  if (rollback) {
2070
2105
  throw new TransferFailedError(message, rollback, { cause: error });
2071
2106
  }
2072
- throw requiresDownload(error) ? new DownloadRequiredError(message, { cause: error }) : new Error(message, { cause: error });
2107
+ throw error instanceof DownloadRequiredError ? new DownloadRequiredError(message, {
2108
+ cause: error,
2109
+ findings: error.findings,
2110
+ messages: error.messages
2111
+ }) : new Error(message, { cause: error });
2073
2112
  });
2074
- return checkReceipt(controllerResultSchema.parse(result), {
2075
- operationId,
2076
- operation,
2077
- imageId: connection.imageId,
2078
- templateHash: connection.templateHash,
2079
- target: connection.target
2080
- }, diagnostics);
2113
+ return { result, connection, operationId, diagnostics };
2081
2114
  } finally {
2082
2115
  await stopFollowing();
2083
2116
  await rm7(directory, { recursive: true, force: true });
2084
2117
  }
2085
2118
  };
2119
+ var reviewWarmController = async (config, name, options) => {
2120
+ try {
2121
+ const { result } = await warmOperation(config, name, { operation: "review", initializeUser: false }, options);
2122
+ return {
2123
+ possible: true,
2124
+ findings: reviewReplySchema.parse(result).findings,
2125
+ messages: []
2126
+ };
2127
+ } catch (error) {
2128
+ if (!(error instanceof DownloadRequiredError)) {
2129
+ throw error;
2130
+ }
2131
+ const explained = error.messages.length > 0 || error.findings.some((finding) => finding.refuses);
2132
+ return {
2133
+ possible: false,
2134
+ findings: error.findings,
2135
+ messages: explained ? error.messages : [failureReason(error.cause)]
2136
+ };
2137
+ }
2138
+ };
2139
+ var restartWarmController = async (config, name, reset, options) => {
2140
+ const { result } = await warmOperation(config, name, { operation: "restart", reset }, options);
2141
+ return restartReplySchema.parse(result);
2142
+ };
2143
+ var updateWarmController = async (config, name, operation, options = {}) => {
2144
+ const { result, connection, operationId, diagnostics } = await warmOperation(config, name, { operation, initializeUser: options.initializeUser ?? false }, options);
2145
+ return checkReceipt(controllerResultSchema.parse(result), {
2146
+ operationId,
2147
+ operation,
2148
+ imageId: connection.imageId,
2149
+ templateHash: connection.templateHash,
2150
+ target: connection.target
2151
+ }, diagnostics);
2152
+ };
2086
2153
  // packages/build/src/engineering-settings.ts
2087
2154
  import {
2088
2155
  controllerFor,
@@ -2387,6 +2454,7 @@ ${log.split(`
2387
2454
  });
2388
2455
  export {
2389
2456
  CodesysCompilerError,
2457
+ DownloadRequiredError,
2390
2458
  StSyntaxError,
2391
2459
  TransferFailedError,
2392
2460
  buildProject,
@@ -2399,6 +2467,7 @@ export {
2399
2467
  configureRuntime,
2400
2468
  controllerBaseline,
2401
2469
  defineBuildConfig as defineConfig,
2470
+ describeFinding,
2402
2471
  explicitDownload,
2403
2472
  failureReason,
2404
2473
  findControllerLogin,
@@ -2411,6 +2480,7 @@ export {
2411
2480
  loadSources,
2412
2481
  loginCommandSchema,
2413
2482
  loginResultSchema,
2483
+ onlineChangeFindingSchema,
2414
2484
  openControllerLogin,
2415
2485
  parseSource,
2416
2486
  progressLog,
@@ -2418,6 +2488,8 @@ export {
2418
2488
  readBuild,
2419
2489
  requiresDownload,
2420
2490
  resolveConfig3 as resolveConfig,
2491
+ restartWarmController,
2492
+ reviewWarmController,
2421
2493
  rollbackSchema,
2422
2494
  runProject,
2423
2495
  settleWarmController,
@@ -2430,5 +2502,5 @@ export {
2430
2502
  workerScriptsDigest
2431
2503
  };
2432
2504
 
2433
- //# debugId=EB6D02505BF86AFD64756E2164756E21
2505
+ //# debugId=A33BB6F2C62569F164756E2164756E21
2434
2506
  //# sourceMappingURL=index.js.map