@tsplc/config 0.2.16 → 0.2.18
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/README.md +2 -2
- package/dist/build.js +164 -133
- package/dist/build.js.map +7 -7
- package/dist/index.js +291 -208
- package/dist/index.js.map +8 -7
- package/dist/schema.js +249 -204
- package/dist/schema.js.map +5 -5
- package/package.json +50 -51
- package/src/build-schema.ts +220 -197
- package/src/build.ts +73 -63
- package/src/compiler.ts +140 -122
- package/src/environment.ts +72 -0
- package/src/index.ts +52 -1
- package/src/loader.ts +33 -15
- package/src/schema.ts +429 -356
- package/templates/provenance.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,9 +1,122 @@
|
|
|
1
|
+
// packages/config/src/compiler.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var nanosecondsPattern = /^[1-9][0-9]*$/;
|
|
4
|
+
var durationSchema = z.object({
|
|
5
|
+
kind: z.literal("duration"),
|
|
6
|
+
nanoseconds: z.string().regex(nanosecondsPattern)
|
|
7
|
+
}).strict();
|
|
8
|
+
function duration(value, scale) {
|
|
9
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
10
|
+
throw new Error("Task duration must be finite and positive.");
|
|
11
|
+
}
|
|
12
|
+
const nanoseconds = value * scale;
|
|
13
|
+
if (!Number.isSafeInteger(nanoseconds)) {
|
|
14
|
+
throw new Error("Task duration must be an exact, safe number of nanoseconds.");
|
|
15
|
+
}
|
|
16
|
+
return { kind: "duration", nanoseconds: String(nanoseconds) };
|
|
17
|
+
}
|
|
18
|
+
var ns = (value) => duration(value, 1);
|
|
19
|
+
var ms = (value) => duration(value, 1e6);
|
|
20
|
+
var seconds = (value) => duration(value, 1e9);
|
|
21
|
+
var sourceExportSchema = z.object({ module: z.string().min(1), export: z.string().min(1) }).strict();
|
|
22
|
+
var taskSchema = z.strictObject({
|
|
23
|
+
name: z.string().nonempty(),
|
|
24
|
+
schedule: z.strictObject({
|
|
25
|
+
kind: z.literal("cyclic"),
|
|
26
|
+
interval: durationSchema
|
|
27
|
+
}),
|
|
28
|
+
priority: z.number().int().nonnegative(),
|
|
29
|
+
programs: z.array(z.string().nonempty()).nonempty()
|
|
30
|
+
});
|
|
31
|
+
var targetSchema = z.object({
|
|
32
|
+
kind: z.string().min(1),
|
|
33
|
+
options: z.unknown().refine((value) => value !== undefined, {
|
|
34
|
+
message: "Target options are required."
|
|
35
|
+
})
|
|
36
|
+
}).strict();
|
|
37
|
+
var common = {
|
|
38
|
+
name: z.string().min(1),
|
|
39
|
+
tsconfig: z.string().min(1),
|
|
40
|
+
tasks: z.array(taskSchema).min(1),
|
|
41
|
+
target: targetSchema
|
|
42
|
+
};
|
|
43
|
+
var entryConfigSchema = z.object({ ...common, entry: sourceExportSchema }).strict();
|
|
44
|
+
var programsConfigSchema = z.object({
|
|
45
|
+
...common,
|
|
46
|
+
programs: z.record(z.string().min(1), sourceExportSchema)
|
|
47
|
+
}).strict();
|
|
48
|
+
function definePlcConfig(config) {
|
|
49
|
+
return config;
|
|
50
|
+
}
|
|
51
|
+
function validateConfig(value) {
|
|
52
|
+
const multiplePrograms = typeof value === "object" && value !== null && Object.hasOwn(value, "programs") && !Object.hasOwn(value, "entry");
|
|
53
|
+
const parsed = (multiplePrograms ? programsConfigSchema : entryConfigSchema).safeParse(value);
|
|
54
|
+
if (!parsed.success) {
|
|
55
|
+
return {
|
|
56
|
+
diagnostics: parsed.error.issues.map((issue) => ({
|
|
57
|
+
origin: "config",
|
|
58
|
+
code: "PLC5001",
|
|
59
|
+
severity: "error",
|
|
60
|
+
message: `${issue.path.join(".") || "config"}: ${issue.message}`
|
|
61
|
+
}))
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const { data } = parsed;
|
|
65
|
+
const programs = "entry" in data ? { main: data.entry } : data.programs;
|
|
66
|
+
const diagnostics = [];
|
|
67
|
+
const report = (message) => {
|
|
68
|
+
diagnostics.push({
|
|
69
|
+
origin: "config",
|
|
70
|
+
code: "PLC5002",
|
|
71
|
+
severity: "error",
|
|
72
|
+
message
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
if (Object.keys(programs).length === 0) {
|
|
76
|
+
report("At least one program is required.");
|
|
77
|
+
}
|
|
78
|
+
const taskNames = new Set;
|
|
79
|
+
const assigned = new Set;
|
|
80
|
+
for (const task of data.tasks) {
|
|
81
|
+
if (taskNames.has(task.name)) {
|
|
82
|
+
report(`Duplicate task name: ${task.name}.`);
|
|
83
|
+
}
|
|
84
|
+
taskNames.add(task.name);
|
|
85
|
+
for (const program of task.programs) {
|
|
86
|
+
if (!Object.hasOwn(programs, program)) {
|
|
87
|
+
report(`Task ${task.name} references unknown program ${program}.`);
|
|
88
|
+
}
|
|
89
|
+
if (assigned.has(program)) {
|
|
90
|
+
report(`Program ${program} must belong to exactly one task.`);
|
|
91
|
+
}
|
|
92
|
+
assigned.add(program);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
for (const program of Object.keys(programs)) {
|
|
96
|
+
if (!assigned.has(program)) {
|
|
97
|
+
report(`Program ${program} is not assigned to a task.`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (diagnostics.length) {
|
|
101
|
+
return { diagnostics };
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
config: {
|
|
105
|
+
name: data.name,
|
|
106
|
+
tsconfig: data.tsconfig,
|
|
107
|
+
programs,
|
|
108
|
+
tasks: data.tasks,
|
|
109
|
+
target: data.target
|
|
110
|
+
},
|
|
111
|
+
diagnostics
|
|
112
|
+
};
|
|
113
|
+
}
|
|
1
114
|
// packages/config/src/schema.ts
|
|
2
115
|
import { z as z3 } from "zod";
|
|
3
116
|
|
|
4
117
|
// packages/config/src/build-schema.ts
|
|
5
|
-
import { z } from "zod";
|
|
6
|
-
var commandArgumentSchema =
|
|
118
|
+
import { z as z2 } from "zod";
|
|
119
|
+
var commandArgumentSchema = z2.string().refine((value) => value.trim().length > 0, "Command arguments must not be empty").refine((value) => !/["\r\n\0]/.test(value), "Command arguments must not contain quotes, line breaks, or null bytes");
|
|
7
120
|
var codesysTimeouts = {
|
|
8
121
|
build: 20 * 60 * 1000,
|
|
9
122
|
hostCommand: 15000,
|
|
@@ -12,35 +125,40 @@ var codesysTimeouts = {
|
|
|
12
125
|
stop: 1e4,
|
|
13
126
|
terminate: 5000
|
|
14
127
|
};
|
|
15
|
-
var positiveMilliseconds =
|
|
16
|
-
var pathSchema =
|
|
17
|
-
var
|
|
128
|
+
var positiveMilliseconds = z2.number().int().positive();
|
|
129
|
+
var pathSchema = z2.string().trim().nonempty();
|
|
130
|
+
var tcpPort = z2.number().int().min(1).max(65535);
|
|
131
|
+
var sha256Digest = z2.string().regex(/^[a-f0-9]{64}$/);
|
|
132
|
+
var envName = z2.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/);
|
|
133
|
+
var wineSchema = z2.strictObject({
|
|
18
134
|
prefix: pathSchema,
|
|
19
135
|
binary: pathSchema.default("wine"),
|
|
20
136
|
pathBinary: pathSchema.default("winepath"),
|
|
21
|
-
debug:
|
|
22
|
-
nativeExit:
|
|
137
|
+
debug: z2.string().default("-all"),
|
|
138
|
+
nativeExit: z2.boolean().default(false)
|
|
23
139
|
});
|
|
24
|
-
var localCodesysSchema =
|
|
140
|
+
var localCodesysSchema = z2.strictObject({
|
|
25
141
|
executable: commandArgumentSchema,
|
|
26
142
|
profile: commandArgumentSchema,
|
|
27
143
|
wine: wineSchema.optional(),
|
|
28
144
|
commandProcessor: pathSchema.default("cmd.exe")
|
|
29
145
|
});
|
|
30
|
-
var iecName =
|
|
31
|
-
var
|
|
146
|
+
var iecName = z2.string().regex(/^[A-Za-z][A-Za-z0-9_]*$/);
|
|
147
|
+
var taskPriority = z2.number().int().min(0).max(31);
|
|
148
|
+
var cyclicTasksSchema = z2.array(z2.strictObject({
|
|
32
149
|
name: iecName,
|
|
33
|
-
intervalNanoseconds:
|
|
34
|
-
if (
|
|
150
|
+
intervalNanoseconds: z2.string().regex(nanosecondsPattern).refine((value) => {
|
|
151
|
+
if (!nanosecondsPattern.test(value)) {
|
|
35
152
|
return false;
|
|
36
153
|
}
|
|
37
154
|
const ns = BigInt(value);
|
|
38
155
|
return ns % 1000000n === 0n && ns <= 4294967295000000n;
|
|
39
156
|
}, "Cyclic tasks require an exact positive TIME interval in milliseconds"),
|
|
40
|
-
priority:
|
|
41
|
-
programs:
|
|
157
|
+
priority: taskPriority,
|
|
158
|
+
programs: z2.array(iecName).nonempty()
|
|
42
159
|
})).nonempty().superRefine((tasks, context) => {
|
|
43
|
-
const names = new Set
|
|
160
|
+
const names = new Set;
|
|
161
|
+
const programs = new Set;
|
|
44
162
|
tasks.forEach((task, index) => {
|
|
45
163
|
if (names.has(task.name.toLowerCase())) {
|
|
46
164
|
context.addIssue({
|
|
@@ -63,107 +181,110 @@ var cyclicTasksSchema = z.array(z.strictObject({
|
|
|
63
181
|
});
|
|
64
182
|
});
|
|
65
183
|
var ioBindingOptions = {
|
|
66
|
-
inverted:
|
|
67
|
-
shared:
|
|
184
|
+
inverted: z2.boolean().optional(),
|
|
185
|
+
shared: z2.boolean().optional()
|
|
68
186
|
};
|
|
69
|
-
var directIoBindingSchema =
|
|
70
|
-
address:
|
|
71
|
-
type:
|
|
187
|
+
var directIoBindingSchema = z2.strictObject({
|
|
188
|
+
address: z2.string().regex(/^%[IQ](?:X\d+\.[0-7]|[BWD]\d+)$/),
|
|
189
|
+
type: z2.string().optional(),
|
|
72
190
|
...ioBindingOptions
|
|
73
191
|
});
|
|
74
|
-
var ethernetSchema =
|
|
75
|
-
interface:
|
|
76
|
-
address:
|
|
77
|
-
subnet:
|
|
78
|
-
gateway:
|
|
192
|
+
var ethernetSchema = z2.strictObject({
|
|
193
|
+
interface: z2.string().nonempty().optional(),
|
|
194
|
+
address: z2.ipv4().optional(),
|
|
195
|
+
subnet: z2.ipv4().optional(),
|
|
196
|
+
gateway: z2.ipv4().optional()
|
|
79
197
|
});
|
|
80
|
-
var
|
|
81
|
-
|
|
82
|
-
|
|
198
|
+
var assemblyAddress = z2.string().regex(/^%[IQ]B\d+$/);
|
|
199
|
+
var processImageSchema = z2.strictObject({
|
|
200
|
+
address: assemblyAddress,
|
|
201
|
+
size: z2.number().int().positive()
|
|
83
202
|
});
|
|
84
|
-
var
|
|
203
|
+
var channelAddress = z2.string().regex(/^%[IQ](?:X\d+\.[0-7]|B\d+)$/);
|
|
204
|
+
var deviceTreeSchema = z2.strictObject({
|
|
85
205
|
ethernet: ethernetSchema.default({}),
|
|
86
|
-
devices:
|
|
206
|
+
devices: z2.array(z2.strictObject({
|
|
87
207
|
name: iecName,
|
|
88
|
-
eds:
|
|
89
|
-
address:
|
|
90
|
-
rpiMicroseconds:
|
|
208
|
+
eds: z2.string().nonempty(),
|
|
209
|
+
address: z2.ipv4().optional(),
|
|
210
|
+
rpiMicroseconds: z2.number().int().positive().optional(),
|
|
91
211
|
inputs: processImageSchema.optional(),
|
|
92
212
|
outputs: processImageSchema.optional(),
|
|
93
|
-
modbus:
|
|
94
|
-
port:
|
|
95
|
-
registers:
|
|
213
|
+
modbus: z2.strictObject({
|
|
214
|
+
port: tcpPort,
|
|
215
|
+
registers: z2.array(z2.strictObject({
|
|
96
216
|
name: iecName,
|
|
97
|
-
offset:
|
|
98
|
-
value:
|
|
99
|
-
write:
|
|
100
|
-
status:
|
|
101
|
-
requests:
|
|
217
|
+
offset: z2.number().int().nonnegative(),
|
|
218
|
+
value: z2.string().regex(/^%QW\d+$/),
|
|
219
|
+
write: z2.string().regex(/^%QX\d+\.[0-7]$/),
|
|
220
|
+
status: z2.string().regex(/^%IB\d+$/),
|
|
221
|
+
requests: z2.string().regex(/^%ID\d+$/)
|
|
102
222
|
}))
|
|
103
223
|
}).optional(),
|
|
104
|
-
comments:
|
|
105
|
-
address:
|
|
106
|
-
text:
|
|
224
|
+
comments: z2.array(z2.strictObject({
|
|
225
|
+
address: channelAddress,
|
|
226
|
+
text: z2.string().nonempty()
|
|
107
227
|
})).default([])
|
|
108
228
|
})).nonempty(),
|
|
109
|
-
mappings:
|
|
110
|
-
address:
|
|
111
|
-
variable:
|
|
229
|
+
mappings: z2.array(z2.strictObject({
|
|
230
|
+
address: channelAddress,
|
|
231
|
+
variable: z2.string().nonempty()
|
|
112
232
|
})).default([])
|
|
113
233
|
});
|
|
114
|
-
var
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
234
|
+
var fourPartVersion = z2.string().regex(/^\d+\.\d+\.\d+\.\d+$/);
|
|
235
|
+
var controllerSchema = z2.strictObject({
|
|
236
|
+
type: z2.number().int().positive(),
|
|
237
|
+
id: z2.string().regex(/^[0-9A-F]{4} [0-9A-F]{4}$/),
|
|
238
|
+
version: fourPartVersion
|
|
118
239
|
});
|
|
119
240
|
var controllerTargetSchema = controllerSchema.pick({ version: true }).extend({
|
|
120
|
-
target:
|
|
241
|
+
target: z2.enum(["linux-sl", "virtual-linux-arm64-sl"])
|
|
121
242
|
});
|
|
122
243
|
var controllerDevices = {
|
|
123
244
|
"linux-sl": { type: 4102, id: "0000 0005" },
|
|
124
245
|
"virtual-linux-arm64-sl": { type: 4096, id: "0000 1008" }
|
|
125
246
|
};
|
|
126
|
-
var configSchema =
|
|
127
|
-
io:
|
|
247
|
+
var configSchema = z2.strictObject({
|
|
248
|
+
io: z2.record(z2.string(), directIoBindingSchema).optional(),
|
|
128
249
|
deviceTree: deviceTreeSchema.optional(),
|
|
129
250
|
controller: controllerSchema.optional(),
|
|
130
|
-
libraryReferences:
|
|
131
|
-
libraries:
|
|
132
|
-
title:
|
|
133
|
-
company:
|
|
134
|
-
version:
|
|
135
|
-
namespace:
|
|
251
|
+
libraryReferences: z2.array(z2.string().nonempty()).default([]),
|
|
252
|
+
libraries: z2.array(z2.strictObject({
|
|
253
|
+
title: z2.string(),
|
|
254
|
+
company: z2.string().optional(),
|
|
255
|
+
version: z2.string().optional(),
|
|
256
|
+
namespace: z2.string().optional(),
|
|
136
257
|
path: pathSchema,
|
|
137
|
-
sha256:
|
|
138
|
-
url:
|
|
258
|
+
sha256: sha256Digest,
|
|
259
|
+
url: z2.string().optional()
|
|
139
260
|
})).optional(),
|
|
140
|
-
docker:
|
|
141
|
-
cpuSet:
|
|
261
|
+
docker: z2.strictObject({
|
|
262
|
+
cpuSet: z2.string().regex(/^\d+(?:-\d+)?(?:,\d+(?:-\d+)?)*$/).optional()
|
|
142
263
|
}).optional(),
|
|
143
264
|
template: pathSchema.optional(),
|
|
144
265
|
sourceDir: pathSchema.default("src"),
|
|
145
266
|
entry: pathSchema.default("src/Main.st"),
|
|
146
267
|
outDir: pathSchema.default("build"),
|
|
147
|
-
task:
|
|
268
|
+
task: z2.string().nonempty().default("MainTask"),
|
|
148
269
|
tasks: cyclicTasksSchema.optional(),
|
|
149
|
-
removeObjects:
|
|
150
|
-
symbols:
|
|
151
|
-
online:
|
|
270
|
+
removeObjects: z2.array(z2.string().nonempty()).default([]),
|
|
271
|
+
symbols: z2.boolean().default(false),
|
|
272
|
+
online: z2.strictObject({
|
|
152
273
|
network: pathSchema.default("bridge"),
|
|
153
|
-
gateway:
|
|
274
|
+
gateway: z2.strictObject({
|
|
154
275
|
host: pathSchema,
|
|
155
|
-
port:
|
|
276
|
+
port: tcpPort.default(1217)
|
|
156
277
|
}),
|
|
157
|
-
device:
|
|
278
|
+
device: z2.strictObject({
|
|
158
279
|
host: pathSchema,
|
|
159
|
-
port:
|
|
280
|
+
port: tcpPort.default(11740)
|
|
160
281
|
}),
|
|
161
|
-
credentials:
|
|
162
|
-
usernameEnv:
|
|
163
|
-
passwordEnv:
|
|
282
|
+
credentials: z2.strictObject({
|
|
283
|
+
usernameEnv: envName,
|
|
284
|
+
passwordEnv: envName
|
|
164
285
|
}).optional()
|
|
165
286
|
}).optional(),
|
|
166
|
-
timeouts:
|
|
287
|
+
timeouts: z2.strictObject({
|
|
167
288
|
startup: positiveMilliseconds.default(codesysTimeouts.startup),
|
|
168
289
|
build: positiveMilliseconds.default(codesysTimeouts.build),
|
|
169
290
|
stop: positiveMilliseconds.default(codesysTimeouts.stop),
|
|
@@ -173,114 +294,14 @@ var configSchema = z.strictObject({
|
|
|
173
294
|
}).prefault({})
|
|
174
295
|
});
|
|
175
296
|
|
|
176
|
-
// packages/config/src/compiler.ts
|
|
177
|
-
import { z as z2 } from "zod";
|
|
178
|
-
var durationSchema = z2.object({
|
|
179
|
-
kind: z2.literal("duration"),
|
|
180
|
-
nanoseconds: z2.string().regex(/^[1-9][0-9]*$/)
|
|
181
|
-
}).strict();
|
|
182
|
-
function duration(value, scale) {
|
|
183
|
-
if (!Number.isFinite(value) || value <= 0) {
|
|
184
|
-
throw new Error("Task duration must be finite and positive.");
|
|
185
|
-
}
|
|
186
|
-
const nanoseconds = value * scale;
|
|
187
|
-
if (!Number.isSafeInteger(nanoseconds)) {
|
|
188
|
-
throw new Error("Task duration must be an exact, safe number of nanoseconds.");
|
|
189
|
-
}
|
|
190
|
-
return { kind: "duration", nanoseconds: String(nanoseconds) };
|
|
191
|
-
}
|
|
192
|
-
var ns = (value) => duration(value, 1);
|
|
193
|
-
var ms = (value) => duration(value, 1e6);
|
|
194
|
-
var seconds = (value) => duration(value, 1e9);
|
|
195
|
-
var sourceExportSchema = z2.object({ module: z2.string().min(1), export: z2.string().min(1) }).strict();
|
|
196
|
-
var taskSchema = z2.object({
|
|
197
|
-
name: z2.string().min(1),
|
|
198
|
-
schedule: z2.object({ kind: z2.literal("cyclic"), interval: durationSchema }).strict(),
|
|
199
|
-
priority: z2.number().int().nonnegative(),
|
|
200
|
-
programs: z2.array(z2.string().min(1)).min(1)
|
|
201
|
-
}).strict();
|
|
202
|
-
var targetSchema = z2.object({
|
|
203
|
-
kind: z2.string().min(1),
|
|
204
|
-
options: z2.unknown().refine((value) => value !== undefined, { message: "Target options are required." })
|
|
205
|
-
}).strict();
|
|
206
|
-
var common = {
|
|
207
|
-
name: z2.string().min(1),
|
|
208
|
-
tsconfig: z2.string().min(1),
|
|
209
|
-
tasks: z2.array(taskSchema).min(1),
|
|
210
|
-
target: targetSchema
|
|
211
|
-
};
|
|
212
|
-
var entryConfigSchema = z2.object({ ...common, entry: sourceExportSchema }).strict();
|
|
213
|
-
var programsConfigSchema = z2.object({ ...common, programs: z2.record(z2.string().min(1), sourceExportSchema) }).strict();
|
|
214
|
-
function definePlcConfig(config) {
|
|
215
|
-
return config;
|
|
216
|
-
}
|
|
217
|
-
function validateConfig(value) {
|
|
218
|
-
const multiplePrograms = typeof value === "object" && value !== null && Object.hasOwn(value, "programs") && !Object.hasOwn(value, "entry");
|
|
219
|
-
const parsed = (multiplePrograms ? programsConfigSchema : entryConfigSchema).safeParse(value);
|
|
220
|
-
if (!parsed.success) {
|
|
221
|
-
return {
|
|
222
|
-
diagnostics: parsed.error.issues.map((issue) => ({
|
|
223
|
-
origin: "config",
|
|
224
|
-
code: "PLC5001",
|
|
225
|
-
severity: "error",
|
|
226
|
-
message: `${issue.path.join(".") || "config"}: ${issue.message}`
|
|
227
|
-
}))
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
const { data } = parsed;
|
|
231
|
-
const programs = "entry" in data ? { main: data.entry } : data.programs;
|
|
232
|
-
const diagnostics = [];
|
|
233
|
-
const report = (message) => {
|
|
234
|
-
diagnostics.push({ origin: "config", code: "PLC5002", severity: "error", message });
|
|
235
|
-
};
|
|
236
|
-
if (Object.keys(programs).length === 0) {
|
|
237
|
-
report("At least one program is required.");
|
|
238
|
-
}
|
|
239
|
-
const taskNames = new Set;
|
|
240
|
-
const assigned = new Set;
|
|
241
|
-
for (const task of data.tasks) {
|
|
242
|
-
if (taskNames.has(task.name)) {
|
|
243
|
-
report(`Duplicate task name: ${task.name}.`);
|
|
244
|
-
}
|
|
245
|
-
taskNames.add(task.name);
|
|
246
|
-
for (const program of task.programs) {
|
|
247
|
-
if (!Object.hasOwn(programs, program)) {
|
|
248
|
-
report(`Task ${task.name} references unknown program ${program}.`);
|
|
249
|
-
}
|
|
250
|
-
if (assigned.has(program)) {
|
|
251
|
-
report(`Program ${program} must belong to exactly one task.`);
|
|
252
|
-
}
|
|
253
|
-
assigned.add(program);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
for (const program of Object.keys(programs)) {
|
|
257
|
-
if (!assigned.has(program)) {
|
|
258
|
-
report(`Program ${program} is not assigned to a task.`);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
if (diagnostics.length) {
|
|
262
|
-
return { diagnostics };
|
|
263
|
-
}
|
|
264
|
-
return {
|
|
265
|
-
config: {
|
|
266
|
-
name: data.name,
|
|
267
|
-
tsconfig: data.tsconfig,
|
|
268
|
-
programs,
|
|
269
|
-
tasks: data.tasks,
|
|
270
|
-
target: data.target
|
|
271
|
-
},
|
|
272
|
-
diagnostics
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
|
|
276
297
|
// packages/config/src/schema.ts
|
|
277
298
|
var httpOptionsSchema = z3.strictObject({
|
|
278
299
|
timeoutMs: z3.number().int().positive().max(60000).default(2000),
|
|
279
300
|
credentials: z3.array(z3.strictObject({
|
|
280
|
-
originEnv:
|
|
281
|
-
bearerTokenEnv:
|
|
301
|
+
originEnv: envName,
|
|
302
|
+
bearerTokenEnv: envName
|
|
282
303
|
})).default([])
|
|
283
|
-
}).
|
|
304
|
+
}).prefault({});
|
|
284
305
|
var ioBindingSchema = z3.union([
|
|
285
306
|
directIoBindingSchema,
|
|
286
307
|
z3.strictObject({
|
|
@@ -292,7 +313,7 @@ var ioBindingSchema = z3.union([
|
|
|
292
313
|
var assemblySchema = z3.strictObject({
|
|
293
314
|
assembly: z3.number().int().nonnegative().optional(),
|
|
294
315
|
size: z3.number().int().positive().optional(),
|
|
295
|
-
address:
|
|
316
|
+
address: assemblyAddress.optional()
|
|
296
317
|
});
|
|
297
318
|
var hardwareDeviceSchema = z3.strictObject({
|
|
298
319
|
file: z3.string().min(1),
|
|
@@ -300,8 +321,8 @@ var hardwareDeviceSchema = z3.strictObject({
|
|
|
300
321
|
inputs: assemblySchema.optional(),
|
|
301
322
|
outputs: assemblySchema.optional(),
|
|
302
323
|
modbus: z3.strictObject({
|
|
303
|
-
port:
|
|
304
|
-
registers: z3.record(
|
|
324
|
+
port: tcpPort.default(502),
|
|
325
|
+
registers: z3.record(iecName, z3.number().int().min(0).max(65535))
|
|
305
326
|
}).optional(),
|
|
306
327
|
statusSymbols: z3.record(z3.string(), z3.string()).optional(),
|
|
307
328
|
network: z3.strictObject({
|
|
@@ -310,19 +331,17 @@ var hardwareDeviceSchema = z3.strictObject({
|
|
|
310
331
|
}).optional()
|
|
311
332
|
});
|
|
312
333
|
var dependencySchema = z3.union([
|
|
313
|
-
|
|
334
|
+
fourPartVersion,
|
|
314
335
|
z3.strictObject({
|
|
315
|
-
version:
|
|
336
|
+
version: fourPartVersion,
|
|
316
337
|
company: z3.string().optional(),
|
|
317
338
|
namespace: z3.string().optional()
|
|
318
339
|
}),
|
|
319
340
|
z3.strictObject({ path: z3.string().min(1), namespace: z3.string().optional() })
|
|
320
341
|
]);
|
|
321
|
-
var
|
|
322
|
-
name:
|
|
323
|
-
|
|
324
|
-
priority: z3.number().int().min(0).max(31),
|
|
325
|
-
programs: z3.array(z3.string().min(1)).nonempty()
|
|
342
|
+
var codesysTaskSchema = taskSchema.extend({
|
|
343
|
+
name: iecName,
|
|
344
|
+
priority: taskPriority
|
|
326
345
|
});
|
|
327
346
|
var monitorSchema = z3.strictObject({
|
|
328
347
|
endpoint: z3.string().url(),
|
|
@@ -332,26 +351,29 @@ var monitorSchema = z3.strictObject({
|
|
|
332
351
|
securityPolicy: z3.enum(["None", "Basic256Sha256"]).optional(),
|
|
333
352
|
certificateDirectory: z3.string().min(1).default(".tsplc/opcua-pki"),
|
|
334
353
|
username: z3.string().min(1).optional(),
|
|
335
|
-
passwordEnv:
|
|
354
|
+
passwordEnv: envName.optional()
|
|
336
355
|
}).superRefine((monitor, context) => {
|
|
337
|
-
if (monitor.securityPolicy && monitor.securityMode === "None" !== (monitor.securityPolicy === "None"))
|
|
356
|
+
if (monitor.securityPolicy && monitor.securityMode === "None" !== (monitor.securityPolicy === "None")) {
|
|
338
357
|
context.addIssue({
|
|
339
358
|
code: "custom",
|
|
340
359
|
path: ["securityPolicy"],
|
|
341
360
|
message: "None mode requires None policy; secure modes require Basic256Sha256."
|
|
342
361
|
});
|
|
343
|
-
|
|
362
|
+
}
|
|
363
|
+
if (monitor.passwordEnv && !monitor.username) {
|
|
344
364
|
context.addIssue({
|
|
345
365
|
code: "custom",
|
|
346
366
|
path: ["username"],
|
|
347
367
|
message: "Configure username when passwordEnv is used."
|
|
348
368
|
});
|
|
349
|
-
|
|
369
|
+
}
|
|
370
|
+
if (monitor.username && monitor.securityMode === "None") {
|
|
350
371
|
context.addIssue({
|
|
351
372
|
code: "custom",
|
|
352
373
|
path: ["securityMode"],
|
|
353
374
|
message: "Username authentication requires a secure OPC-UA connection."
|
|
354
375
|
});
|
|
376
|
+
}
|
|
355
377
|
}).transform((monitor) => ({
|
|
356
378
|
...monitor,
|
|
357
379
|
securityPolicy: monitor.securityPolicy ?? (monitor.securityMode === "None" ? "None" : "Basic256Sha256")
|
|
@@ -374,7 +396,7 @@ var debugSchema = z3.strictObject({
|
|
|
374
396
|
requests: z3.strictObject({
|
|
375
397
|
capacity: z3.number().int().min(1).max(1e5).default(1000),
|
|
376
398
|
bodies: z3.boolean().default(false)
|
|
377
|
-
}).
|
|
399
|
+
}).prefault({})
|
|
378
400
|
});
|
|
379
401
|
var typegenSchema = z3.strictObject({
|
|
380
402
|
types: z3.union([z3.string(), z3.array(z3.string())]).optional(),
|
|
@@ -441,7 +463,7 @@ var tsplcConfigSchema = z3.strictObject({
|
|
|
441
463
|
tsconfig: z3.string().default("tsconfig.json"),
|
|
442
464
|
programs: z3.record(z3.string(), z3.strictObject({ module: z3.string(), export: z3.string() }))
|
|
443
465
|
}).optional(),
|
|
444
|
-
tasks: z3.array(
|
|
466
|
+
tasks: z3.array(codesysTaskSchema).nonempty().optional(),
|
|
445
467
|
build: configSchema.extend({ task: configSchema.shape.task.unwrap().optional() }).optional(),
|
|
446
468
|
codesys: z3.strictObject({
|
|
447
469
|
http: httpOptionsSchema.optional(),
|
|
@@ -460,13 +482,22 @@ var tsplcConfigSchema = z3.strictObject({
|
|
|
460
482
|
monitor: monitorSchema.optional(),
|
|
461
483
|
hmi: hmiSchema.optional(),
|
|
462
484
|
telemetry: telemetrySchema.optional(),
|
|
463
|
-
debug: debugSchema.optional()
|
|
485
|
+
debug: debugSchema.optional(),
|
|
486
|
+
targets: z3.record(z3.string().nonempty(), z3.strictObject({ values: z3.record(envName, z3.string()) })).default({}),
|
|
487
|
+
secrets: z3.strictObject({
|
|
488
|
+
service: z3.string().nonempty(),
|
|
489
|
+
names: z3.array(envName).nonempty()
|
|
490
|
+
}).optional()
|
|
464
491
|
});
|
|
465
492
|
var buildTargetFor = (command) => ["run", "download", "online-change", "inspect"].includes(command) ? "development" : "production";
|
|
466
493
|
var controllerFor = (config, command) => {
|
|
467
494
|
const controller = config.codesys?.controllers?.[buildTargetFor(command)];
|
|
468
|
-
return controller && {
|
|
495
|
+
return controller && {
|
|
496
|
+
...controllerDevices[controller.target],
|
|
497
|
+
version: controller.version
|
|
498
|
+
};
|
|
469
499
|
};
|
|
500
|
+
var serverTokenEnv = (config) => config.codesys?.http?.credentials.find(({ originEnv }) => originEnv === config.server?.baseUrlEnv)?.bearerTokenEnv;
|
|
470
501
|
var simulationConfig = (config) => ({
|
|
471
502
|
...config,
|
|
472
503
|
eds: [],
|
|
@@ -483,14 +514,18 @@ function defineConfig(config) {
|
|
|
483
514
|
return config;
|
|
484
515
|
}
|
|
485
516
|
function rawBuildConfig(config) {
|
|
486
|
-
if (config.compiler)
|
|
517
|
+
if (config.compiler) {
|
|
487
518
|
throw new Error("Use the compiler build plan for TypeScript projects.");
|
|
488
|
-
|
|
519
|
+
}
|
|
520
|
+
if (!config.build) {
|
|
489
521
|
throw new Error("Configure build settings.");
|
|
490
|
-
|
|
522
|
+
}
|
|
523
|
+
if (!config.tasks) {
|
|
491
524
|
return config.build;
|
|
492
|
-
|
|
525
|
+
}
|
|
526
|
+
if (config.build.tasks || config.build.task !== undefined) {
|
|
493
527
|
throw new Error("Configure the raw ST schedule in tasks or build.tasks/build.task, not both.");
|
|
528
|
+
}
|
|
494
529
|
return {
|
|
495
530
|
...config.build,
|
|
496
531
|
tasks: cyclicTasksSchema.parse(config.tasks.map((task) => ({
|
|
@@ -502,9 +537,14 @@ function rawBuildConfig(config) {
|
|
|
502
537
|
};
|
|
503
538
|
}
|
|
504
539
|
function compilerConfig(config, io, buildTarget = "production") {
|
|
505
|
-
if (!config.compiler || !config.tasks)
|
|
540
|
+
if (!config.compiler || !config.tasks) {
|
|
506
541
|
throw new Error("This project uses raw Structured Text; no TypeScript compiler is configured.");
|
|
507
|
-
|
|
542
|
+
}
|
|
543
|
+
const {
|
|
544
|
+
deviceTree: _deviceTree,
|
|
545
|
+
controllers: _controllers,
|
|
546
|
+
...codesys
|
|
547
|
+
} = config.codesys ?? {};
|
|
508
548
|
const value = {
|
|
509
549
|
name: config.name,
|
|
510
550
|
tsconfig: config.compiler.tsconfig,
|
|
@@ -532,9 +572,10 @@ function compilerConfig(config, io, buildTarget = "production") {
|
|
|
532
572
|
}
|
|
533
573
|
};
|
|
534
574
|
const validated = validateConfig(value);
|
|
535
|
-
if (!validated.config)
|
|
575
|
+
if (!validated.config) {
|
|
536
576
|
throw new Error(validated.diagnostics.map((item) => item.message).join(`
|
|
537
577
|
`));
|
|
578
|
+
}
|
|
538
579
|
return validated.config;
|
|
539
580
|
}
|
|
540
581
|
function mappedChannel(config, name, binding) {
|
|
@@ -552,11 +593,43 @@ function compilerBuildOptions(build) {
|
|
|
552
593
|
} = build;
|
|
553
594
|
return settings;
|
|
554
595
|
}
|
|
596
|
+
// packages/config/src/environment.ts
|
|
597
|
+
import { z as z4 } from "zod";
|
|
598
|
+
var secretLength = 512;
|
|
599
|
+
var secretValue = z4.string().nonempty("is empty").max(secretLength, `is longer than ${secretLength} characters`).regex(/^[^\r\n\0]*$/, "holds a line break or NUL");
|
|
600
|
+
var secretPlaceholder = (name) => `{{tsplc-secret:${name}:`.padEnd(secretLength - 2, "-") + "}}";
|
|
601
|
+
var targetValues = (config, { target, forAgent }) => {
|
|
602
|
+
const names = Object.keys(config.targets);
|
|
603
|
+
if (target !== undefined) {
|
|
604
|
+
const selected = config.targets[target];
|
|
605
|
+
if (!selected) {
|
|
606
|
+
throw new Error(`The config has no target ${target}; its targets are: ${names.join(", ") || "none"}.`);
|
|
607
|
+
}
|
|
608
|
+
return selected.values;
|
|
609
|
+
}
|
|
610
|
+
if (forAgent && names.length > 1) {
|
|
611
|
+
throw new Error(`Choose the target to deploy to with --target: ${names.join(", ")}.`);
|
|
612
|
+
}
|
|
613
|
+
const [only, ...others] = Object.values(config.targets);
|
|
614
|
+
return only && !others.length ? only.values : {};
|
|
615
|
+
};
|
|
616
|
+
var projectEnvironment = (config, options) => ({
|
|
617
|
+
...options.env,
|
|
618
|
+
...targetValues(config, options),
|
|
619
|
+
...options.forAgent && Object.fromEntries((config.secrets?.names ?? []).map((name) => [
|
|
620
|
+
name,
|
|
621
|
+
secretPlaceholder(name)
|
|
622
|
+
]))
|
|
623
|
+
});
|
|
555
624
|
// packages/config/src/loader.ts
|
|
556
625
|
import { readFile } from "node:fs/promises";
|
|
557
626
|
import { dirname, resolve } from "node:path";
|
|
558
627
|
import { createJiti } from "jiti";
|
|
559
|
-
async function loadTsplcConfig(file = "tsplc.config.ts"
|
|
628
|
+
async function loadTsplcConfig(file = "tsplc.config.ts", environment = {
|
|
629
|
+
env: process.env,
|
|
630
|
+
target: undefined,
|
|
631
|
+
forAgent: false
|
|
632
|
+
}) {
|
|
560
633
|
const configFile = resolve(file);
|
|
561
634
|
await readFile(configFile);
|
|
562
635
|
const jiti = createJiti(import.meta.url, {
|
|
@@ -567,9 +640,15 @@ async function loadTsplcConfig(file = "tsplc.config.ts") {
|
|
|
567
640
|
});
|
|
568
641
|
const module = await jiti.import(configFile);
|
|
569
642
|
const config = tsplcConfigSchema.parse(module.default ?? module.config);
|
|
570
|
-
if (config.compiler && !config.tasks)
|
|
643
|
+
if (config.compiler && !config.tasks) {
|
|
571
644
|
throw new Error("TypeScript programs require a tasks configuration.");
|
|
572
|
-
|
|
645
|
+
}
|
|
646
|
+
return {
|
|
647
|
+
configFile,
|
|
648
|
+
root: dirname(configFile),
|
|
649
|
+
config,
|
|
650
|
+
env: projectEnvironment(config, environment)
|
|
651
|
+
};
|
|
573
652
|
}
|
|
574
653
|
export {
|
|
575
654
|
buildTargetFor,
|
|
@@ -583,9 +662,13 @@ export {
|
|
|
583
662
|
loadTsplcConfig,
|
|
584
663
|
ms,
|
|
585
664
|
ns,
|
|
665
|
+
projectEnvironment,
|
|
586
666
|
publicationSchema,
|
|
587
667
|
rawBuildConfig,
|
|
588
668
|
seconds,
|
|
669
|
+
secretPlaceholder,
|
|
670
|
+
secretValue,
|
|
671
|
+
serverTokenEnv,
|
|
589
672
|
simulationConfig,
|
|
590
673
|
telemetrySchema,
|
|
591
674
|
tsplcConfigSchema,
|
|
@@ -593,5 +676,5 @@ export {
|
|
|
593
676
|
validateConfig
|
|
594
677
|
};
|
|
595
678
|
|
|
596
|
-
//# debugId=
|
|
679
|
+
//# debugId=499750059EF1D2C964756E2164756E21
|
|
597
680
|
//# sourceMappingURL=index.js.map
|