@tsplc/build 0.5.9 → 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/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,45 +679,400 @@ 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 warmOperationSchema = z6.strictObject({
1072
+ operation: z6.enum(["download", "online-change", "review"]),
1073
+ operationId: z6.uuid(),
1074
+ request: z6.string().nonempty(),
1075
+ initializeUser: z6.boolean(),
721
1076
  credentials: controllerCredentialsSchema.optional()
722
1077
  });
723
1078
  var tracebackFailure = (traceback) => {
@@ -748,8 +1103,18 @@ var explicitDownload = "use an explicit download";
748
1103
 
749
1104
  class DownloadRequiredError extends Error {
750
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
+ }
751
1113
  }
752
- var rollbackSchema = z5.enum([
1114
+ var reviewReplySchema = z6.strictObject({
1115
+ findings: z6.array(onlineChangeFindingSchema)
1116
+ });
1117
+ var rollbackSchema = z6.enum([
753
1118
  "intact",
754
1119
  "restored",
755
1120
  "failed",
@@ -770,30 +1135,30 @@ var transferRollback = (error) => {
770
1135
  return rollbackSchema.safeParse(error.rollback).data;
771
1136
  };
772
1137
  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()
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()
778
1143
  }),
779
- z5.strictObject({
780
- command: z5.enum(["write", "force"]),
781
- values: z5.record(z5.string().nonempty(), z5.string().nonempty())
1144
+ z6.strictObject({
1145
+ command: z6.enum(["write", "force"]),
1146
+ values: z6.record(z6.string().nonempty(), z6.string().nonempty())
782
1147
  }),
783
- z5.strictObject({
784
- command: z5.literal("unforce"),
785
- expressions: z5.array(z5.string().nonempty()),
786
- restore: z5.boolean()
1148
+ z6.strictObject({
1149
+ command: z6.literal("unforce"),
1150
+ expressions: z6.array(z6.string().nonempty()),
1151
+ restore: z6.boolean()
787
1152
  }),
788
- z5.strictObject({ command: z5.enum(["start", "stop"]) }),
789
- z5.strictObject({
790
- command: z5.literal("reset"),
791
- kind: z5.enum(["Warm", "Cold"])
1153
+ z6.strictObject({ command: z6.enum(["start", "stop"]) }),
1154
+ z6.strictObject({
1155
+ command: z6.literal("reset"),
1156
+ kind: z6.enum(["Warm", "Cold"])
792
1157
  })
793
1158
  ]);
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()) })
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()) })
797
1162
  ]);
798
1163
 
799
1164
  // packages/build/src/host/codesys-command.ts
@@ -811,7 +1176,7 @@ var codesysCommand = [
811
1176
  // packages/build/src/host/codesys-host.ts
812
1177
  import { execFile as execFile3, spawn as spawn2 } from "node:child_process";
813
1178
  import { promisify as promisify3 } from "node:util";
814
- import { z as z6 } from "zod";
1179
+ import { z as z7 } from "zod";
815
1180
 
816
1181
  // packages/build/src/host/windows-path.ts
817
1182
  import { execFile as execFile2 } from "node:child_process";
@@ -824,10 +1189,10 @@ var execute2 = promisify2(execFile2);
824
1189
 
825
1190
  // packages/build/src/host/codesys-host.ts
826
1191
  var execute3 = promisify3(execFile3);
827
- var exitSchema = z6.object({
828
- pid: z6.int().positive(),
829
- code: z6.int().nullable(),
830
- signal: z6.string().nullable()
1192
+ var exitSchema = z7.object({
1193
+ pid: z7.int().positive(),
1194
+ code: z7.int().nullable(),
1195
+ signal: z7.string().nullable()
831
1196
  });
832
1197
 
833
1198
  // packages/build/src/host/codesys-worker.ts
@@ -840,12 +1205,12 @@ var workerScripts = [
840
1205
  "codesys_login.py"
841
1206
  ];
842
1207
  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()
1208
+ var sessionSchema = z8.object({
1209
+ directory: z8.string(),
1210
+ fingerprint: z8.string(),
1211
+ pid: z8.int().positive()
847
1212
  });
848
- var phaseSchema = z7.enum(["prepare", "transfer"]);
1213
+ var phaseSchema = z8.enum(["prepare", "transfer"]);
849
1214
  var hasCode = (error, code) => error instanceof Error && ("code" in error) && error.code === code;
850
1215
  var isProcessAlive = (pid) => {
851
1216
  try {
@@ -897,106 +1262,11 @@ var withWorkerLock = async (config, run) => {
897
1262
  // packages/build/src/sources.ts
898
1263
  import { readdir as readdir2, readFile as readFile6 } from "node:fs/promises";
899
1264
  import { basename as basename4, resolve as resolve8 } from "node:path";
900
- import { identifierPattern as identifierPattern3 } from "@tsplc/iec/st";
901
-
902
- // 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
- };
1265
+ import { identifierPattern as identifierPattern3 } from "@tsplc/iec/st";
998
1266
 
999
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";
1000
1270
  var span = (type) => ioArray(type) ?? { element: type, length: 1 };
1001
1271
  var addressSize = (type) => {
1002
1272
  const bits = ioScalarBits(type);
@@ -1009,7 +1279,7 @@ function bindStructuredTextIo(objects, bindings) {
1009
1279
  let section = false;
1010
1280
  let start = 0;
1011
1281
  for (const [index, token] of tokens.entries()) {
1012
- if (variableSections.has(token.value)) {
1282
+ if (variableSections2.has(token.value)) {
1013
1283
  section = true;
1014
1284
  start = index + 1;
1015
1285
  continue;
@@ -1031,7 +1301,7 @@ function bindStructuredTextIo(objects, bindings) {
1031
1301
  if (colonIndex < 1) {
1032
1302
  continue;
1033
1303
  }
1034
- const names = part.slice(0, colonIndex).filter((t) => t.kind === "word" && !qualifiers.has(t.value) && t.value !== "AT");
1304
+ const names = part.slice(0, colonIndex).filter((t) => t.kind === "word" && !qualifiers2.has(t.value) && t.value !== "AT");
1035
1305
  const at = part.find((t) => t.value === "AT");
1036
1306
  const variables = at ? names.filter((t) => t.start < at.start) : names;
1037
1307
  const initializer = part.findIndex((t, index) => index > colonIndex && t.value === ":=");
@@ -1103,242 +1373,6 @@ import {
1103
1373
  qualifiers as qualifiers3,
1104
1374
  variableSections as variableSections3
1105
1375
  } 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
1376
  var dutTypes = {
1343
1377
  STRUCT: "structure",
1344
1378
  UNION: "union",
@@ -1707,18 +1741,6 @@ import {
1707
1741
  sha256Digest as sha256Digest2
1708
1742
  } from "@tsplc/config/build";
1709
1743
  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
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);
1723
1745
  var pointerSchema = z9.strictObject({
1724
1746
  schemaVersion: z9.literal(1),
@@ -1840,6 +1862,8 @@ var loginReplySchema = z10.discriminatedUnion("ok", [
1840
1862
  ok: z10.literal(false),
1841
1863
  error: z10.string(),
1842
1864
  downloadRequired: z10.literal(true).optional(),
1865
+ findings: z10.array(onlineChangeFindingSchema).optional(),
1866
+ messages: z10.array(z10.string()).optional(),
1843
1867
  rollback: rollbackSchema.optional()
1844
1868
  })
1845
1869
  ]);
@@ -1878,7 +1902,10 @@ var callContainer = async (name, port, method, body) => {
1878
1902
  if (reply.rollback) {
1879
1903
  throw new TransferFailedError(reply.error, reply.rollback);
1880
1904
  }
1881
- throw reply.downloadRequired || reply.error.endsWith(explicitDownload) ? new DownloadRequiredError(reply.error) : new Error(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);
1882
1909
  }
1883
1910
  return reply.result;
1884
1911
  };
@@ -2041,7 +2068,7 @@ var followProgress = (log, report) => {
2041
2068
  var startWarmController = async (config, name) => {
2042
2069
  await warmController(config, name, await controllerConnection(config), () => {});
2043
2070
  };
2044
- var updateWarmController = async (config, name, operation, options = {}) => {
2071
+ var warmOperation = async (config, name, operation, options) => {
2045
2072
  const report = options.onProgress ?? (() => {});
2046
2073
  const connection = await controllerConnection(config);
2047
2074
  const operationId = randomUUID3();
@@ -2061,7 +2088,7 @@ var updateWarmController = async (config, name, operation, options = {}) => {
2061
2088
  operation,
2062
2089
  operationId,
2063
2090
  request,
2064
- initializeUser: options.initializeUser ?? false,
2091
+ initializeUser: options.initializeUser,
2065
2092
  credentials: options.credentials
2066
2093
  }).catch((error) => {
2067
2094
  const message = `${failureReason(error)}. Inspect ${diagnostics} for diagnostics`;
@@ -2069,20 +2096,51 @@ var updateWarmController = async (config, name, operation, options = {}) => {
2069
2096
  if (rollback) {
2070
2097
  throw new TransferFailedError(message, rollback, { cause: error });
2071
2098
  }
2072
- throw requiresDownload(error) ? new DownloadRequiredError(message, { cause: error }) : new Error(message, { cause: error });
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 });
2073
2104
  });
2074
- return checkReceipt(controllerResultSchema.parse(result), {
2075
- operationId,
2076
- operation,
2077
- imageId: connection.imageId,
2078
- templateHash: connection.templateHash,
2079
- target: connection.target
2080
- }, diagnostics);
2105
+ return { result, connection, operationId, diagnostics };
2081
2106
  } finally {
2082
2107
  await stopFollowing();
2083
2108
  await rm7(directory, { recursive: true, force: true });
2084
2109
  }
2085
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
+ };
2086
2144
  // packages/build/src/engineering-settings.ts
2087
2145
  import {
2088
2146
  controllerFor,
@@ -2387,6 +2445,7 @@ ${log.split(`
2387
2445
  });
2388
2446
  export {
2389
2447
  CodesysCompilerError,
2448
+ DownloadRequiredError,
2390
2449
  StSyntaxError,
2391
2450
  TransferFailedError,
2392
2451
  buildProject,
@@ -2399,6 +2458,7 @@ export {
2399
2458
  configureRuntime,
2400
2459
  controllerBaseline,
2401
2460
  defineBuildConfig as defineConfig,
2461
+ describeFinding,
2402
2462
  explicitDownload,
2403
2463
  failureReason,
2404
2464
  findControllerLogin,
@@ -2411,6 +2471,7 @@ export {
2411
2471
  loadSources,
2412
2472
  loginCommandSchema,
2413
2473
  loginResultSchema,
2474
+ onlineChangeFindingSchema,
2414
2475
  openControllerLogin,
2415
2476
  parseSource,
2416
2477
  progressLog,
@@ -2418,6 +2479,7 @@ export {
2418
2479
  readBuild,
2419
2480
  requiresDownload,
2420
2481
  resolveConfig3 as resolveConfig,
2482
+ reviewWarmController,
2421
2483
  rollbackSchema,
2422
2484
  runProject,
2423
2485
  settleWarmController,
@@ -2430,5 +2492,5 @@ export {
2430
2492
  workerScriptsDigest
2431
2493
  };
2432
2494
 
2433
- //# debugId=EB6D02505BF86AFD64756E2164756E21
2495
+ //# debugId=A397B881BE772B7E64756E2164756E21
2434
2496
  //# sourceMappingURL=index.js.map