@tsplc/config 0.5.14 → 0.5.16
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 +33 -3
- package/dist/build.js +222 -175
- package/dist/build.js.map +9 -8
- package/dist/index.js +401 -341
- package/dist/index.js.map +10 -9
- package/dist/project-files.js +9 -2
- package/dist/project-files.js.map +3 -3
- package/dist/schema.js +237 -196
- package/dist/schema.js.map +6 -6
- package/package.json +2 -1
- package/src/build-schema.ts +64 -61
- package/src/build.ts +11 -10
- package/src/compiler.ts +80 -58
- package/src/config-module.ts +15 -0
- package/src/environment.ts +45 -34
- package/src/index.ts +10 -1
- package/src/loader.ts +10 -23
- package/src/project-files.ts +14 -0
- package/src/schema.ts +162 -118
package/dist/schema.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
// packages/config/src/schema.ts
|
|
2
|
-
import { z as
|
|
2
|
+
import { z as z4 } from "zod";
|
|
3
3
|
|
|
4
4
|
// packages/config/src/build-schema.ts
|
|
5
|
+
import { latestTimeNanoseconds, nanosecondsPerMillisecond as nanosecondsPerMillisecond2 } from "@tsplc/iec";
|
|
6
|
+
import { generatedNamePattern } from "@tsplc/iec/st";
|
|
5
7
|
import { z as z2 } from "zod";
|
|
6
8
|
|
|
7
9
|
// packages/config/src/compiler.ts
|
|
10
|
+
import { nanosecondsPerMillisecond } from "@tsplc/iec";
|
|
8
11
|
import { z } from "zod";
|
|
9
|
-
var
|
|
10
|
-
var durationSchema = z.
|
|
12
|
+
var nanosecondsSchema = z.string().regex(/^[1-9][0-9]*$/, { abort: true });
|
|
13
|
+
var durationSchema = z.strictObject({
|
|
11
14
|
kind: z.literal("duration"),
|
|
12
|
-
nanoseconds:
|
|
13
|
-
})
|
|
15
|
+
nanoseconds: nanosecondsSchema
|
|
16
|
+
});
|
|
14
17
|
function duration(value, scale) {
|
|
15
18
|
if (!Number.isFinite(value) || value <= 0) {
|
|
16
19
|
throw new Error("Task duration must be finite and positive.");
|
|
@@ -22,10 +25,13 @@ function duration(value, scale) {
|
|
|
22
25
|
return { kind: "duration", nanoseconds: String(nanoseconds) };
|
|
23
26
|
}
|
|
24
27
|
var ns = (value) => duration(value, 1);
|
|
25
|
-
var ms = (value) => duration(value,
|
|
26
|
-
var seconds = (value) => duration(value,
|
|
28
|
+
var ms = (value) => duration(value, Number(nanosecondsPerMillisecond));
|
|
29
|
+
var seconds = (value) => duration(value, Number(nanosecondsPerMillisecond) * 1000);
|
|
27
30
|
var durationHelpers = { ns, ms, seconds };
|
|
28
|
-
var sourceExportSchema = z.
|
|
31
|
+
var sourceExportSchema = z.strictObject({
|
|
32
|
+
module: z.string().nonempty(),
|
|
33
|
+
export: z.string().nonempty()
|
|
34
|
+
});
|
|
29
35
|
var taskSchema = z.strictObject({
|
|
30
36
|
name: z.string().nonempty(),
|
|
31
37
|
schedule: z.strictObject({
|
|
@@ -35,23 +41,46 @@ var taskSchema = z.strictObject({
|
|
|
35
41
|
priority: z.number().int().nonnegative(),
|
|
36
42
|
programs: z.array(z.string().nonempty()).nonempty()
|
|
37
43
|
});
|
|
38
|
-
var
|
|
39
|
-
|
|
44
|
+
var scheduleRepeats = (tasks) => {
|
|
45
|
+
const names = new Set;
|
|
46
|
+
const programs = new Set;
|
|
47
|
+
const repeats = [];
|
|
48
|
+
tasks.forEach((task, index) => {
|
|
49
|
+
const name = task.name.toUpperCase();
|
|
50
|
+
if (names.has(name)) {
|
|
51
|
+
repeats.push({ task: index, position: null });
|
|
52
|
+
}
|
|
53
|
+
names.add(name);
|
|
54
|
+
task.programs.forEach((program, position) => {
|
|
55
|
+
const scheduled = program.toUpperCase();
|
|
56
|
+
if (programs.has(scheduled)) {
|
|
57
|
+
repeats.push({ task: index, position });
|
|
58
|
+
}
|
|
59
|
+
programs.add(scheduled);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
return repeats;
|
|
63
|
+
};
|
|
64
|
+
var targetSchema = z.strictObject({
|
|
65
|
+
kind: z.string().nonempty(),
|
|
40
66
|
options: z.unknown().refine((value) => value !== undefined, {
|
|
41
67
|
message: "Target options are required."
|
|
42
68
|
})
|
|
43
|
-
})
|
|
69
|
+
});
|
|
44
70
|
var common = {
|
|
45
|
-
name: z.string().
|
|
46
|
-
tsconfig: z.string().
|
|
47
|
-
tasks: z.array(taskSchema).
|
|
71
|
+
name: z.string().nonempty(),
|
|
72
|
+
tsconfig: z.string().nonempty(),
|
|
73
|
+
tasks: z.array(taskSchema).nonempty(),
|
|
48
74
|
target: targetSchema
|
|
49
75
|
};
|
|
50
|
-
var entryConfigSchema = z.
|
|
51
|
-
var programsConfigSchema = z.object({
|
|
76
|
+
var entryConfigSchema = z.strictObject({
|
|
52
77
|
...common,
|
|
53
|
-
|
|
54
|
-
})
|
|
78
|
+
entry: sourceExportSchema
|
|
79
|
+
});
|
|
80
|
+
var programsConfigSchema = z.strictObject({
|
|
81
|
+
...common,
|
|
82
|
+
programs: z.record(z.string().nonempty(), sourceExportSchema)
|
|
83
|
+
});
|
|
55
84
|
function definePlcConfig(config) {
|
|
56
85
|
return config;
|
|
57
86
|
}
|
|
@@ -82,25 +111,24 @@ function validateConfig(value) {
|
|
|
82
111
|
if (Object.keys(programs).length === 0) {
|
|
83
112
|
report("At least one program is required.");
|
|
84
113
|
}
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
if (
|
|
114
|
+
const repeats = scheduleRepeats(data.tasks);
|
|
115
|
+
const repeated = (task, position) => repeats.some((repeat) => repeat.task === task && repeat.position === position);
|
|
116
|
+
data.tasks.forEach((task, index) => {
|
|
117
|
+
if (repeated(index, null)) {
|
|
89
118
|
report(`Duplicate task name: ${task.name}.`);
|
|
90
119
|
}
|
|
91
|
-
|
|
92
|
-
for (const program of task.programs) {
|
|
120
|
+
task.programs.forEach((program, position) => {
|
|
93
121
|
if (!Object.hasOwn(programs, program)) {
|
|
94
122
|
report(`Task ${task.name} references unknown program ${program}.`);
|
|
95
123
|
}
|
|
96
|
-
if (
|
|
124
|
+
if (repeated(index, position)) {
|
|
97
125
|
report(`Program ${program} must belong to exactly one task.`);
|
|
98
126
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
const scheduled = new Set(data.tasks.flatMap((task) => task.programs));
|
|
102
130
|
for (const program of Object.keys(programs)) {
|
|
103
|
-
if (!
|
|
131
|
+
if (!scheduled.has(program)) {
|
|
104
132
|
report(`Program ${program} is not assigned to a task.`);
|
|
105
133
|
}
|
|
106
134
|
}
|
|
@@ -133,6 +161,8 @@ var codesysTimeouts = {
|
|
|
133
161
|
var positiveMilliseconds = z2.number().int().positive();
|
|
134
162
|
var pathSchema = z2.string().trim().nonempty();
|
|
135
163
|
var tcpPort = z2.number().int().min(1).max(65535);
|
|
164
|
+
var runtimePort = 11740;
|
|
165
|
+
var gatewayPort = 1217;
|
|
136
166
|
var sha256Digest = z2.string().regex(/^[a-f0-9]{64}$/);
|
|
137
167
|
var envName = z2.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/);
|
|
138
168
|
var wineSchema = z2.strictObject({
|
|
@@ -148,42 +178,28 @@ var localCodesysSchema = z2.strictObject({
|
|
|
148
178
|
wine: wineSchema.optional(),
|
|
149
179
|
commandProcessor: pathSchema.default("cmd.exe")
|
|
150
180
|
});
|
|
151
|
-
var iecName = z2.string().regex(
|
|
181
|
+
var iecName = z2.string().regex(generatedNamePattern);
|
|
152
182
|
var taskPriority = z2.number().int().min(0).max(31);
|
|
153
183
|
var cyclicTasksSchema = z2.array(z2.strictObject({
|
|
154
184
|
name: iecName,
|
|
155
|
-
intervalNanoseconds:
|
|
156
|
-
if (!nanosecondsPattern.test(value)) {
|
|
157
|
-
return false;
|
|
158
|
-
}
|
|
185
|
+
intervalNanoseconds: nanosecondsSchema.refine((value) => {
|
|
159
186
|
const ns = BigInt(value);
|
|
160
|
-
return ns %
|
|
187
|
+
return ns % nanosecondsPerMillisecond2 === 0n && ns <= latestTimeNanoseconds;
|
|
161
188
|
}, "Cyclic tasks require an exact positive TIME interval in milliseconds"),
|
|
162
189
|
priority: taskPriority,
|
|
163
190
|
programs: z2.array(iecName).nonempty()
|
|
164
191
|
})).nonempty().superRefine((tasks, context) => {
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
names.add(task.name.toLowerCase());
|
|
176
|
-
task.programs.forEach((program, position) => {
|
|
177
|
-
if (programs.has(program.toLowerCase())) {
|
|
178
|
-
context.addIssue({
|
|
179
|
-
code: "custom",
|
|
180
|
-
path: [index, "programs", position],
|
|
181
|
-
message: "A program can be scheduled only once"
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
programs.add(program.toLowerCase());
|
|
192
|
+
for (const { task, position } of scheduleRepeats(tasks)) {
|
|
193
|
+
context.addIssue(position === null ? {
|
|
194
|
+
code: "custom",
|
|
195
|
+
path: [task, "name"],
|
|
196
|
+
message: "Task names must be unique"
|
|
197
|
+
} : {
|
|
198
|
+
code: "custom",
|
|
199
|
+
path: [task, "programs", position],
|
|
200
|
+
message: "A program can be scheduled only once"
|
|
185
201
|
});
|
|
186
|
-
}
|
|
202
|
+
}
|
|
187
203
|
});
|
|
188
204
|
var ioBindingOptions = {
|
|
189
205
|
inverted: z2.boolean().optional(),
|
|
@@ -245,13 +261,15 @@ var controllerSchema = z2.strictObject({
|
|
|
245
261
|
var controllerTargetSchema = controllerSchema.pick({ version: true }).extend({
|
|
246
262
|
target: z2.enum(["linux-sl", "virtual-linux-arm64-sl"])
|
|
247
263
|
});
|
|
248
|
-
var
|
|
249
|
-
"linux-sl": {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
"linux-sl":
|
|
254
|
-
|
|
264
|
+
var controllerTargets = {
|
|
265
|
+
"linux-sl": {
|
|
266
|
+
device: { type: 4102, id: "0000 0005" },
|
|
267
|
+
deviceName: "CODESYS Control for Linux SL"
|
|
268
|
+
},
|
|
269
|
+
"virtual-linux-arm64-sl": {
|
|
270
|
+
device: { type: 4096, id: "0000 1008" },
|
|
271
|
+
deviceName: "CODESYS Virtual Control for Linux ARM64 SL"
|
|
272
|
+
}
|
|
255
273
|
};
|
|
256
274
|
var configSchema = z2.strictObject({
|
|
257
275
|
io: z2.record(z2.string(), directIoBindingSchema).optional(),
|
|
@@ -283,11 +301,11 @@ var configSchema = z2.strictObject({
|
|
|
283
301
|
network: pathSchema.default("bridge"),
|
|
284
302
|
gateway: z2.strictObject({
|
|
285
303
|
host: pathSchema,
|
|
286
|
-
port: tcpPort.default(
|
|
304
|
+
port: tcpPort.default(gatewayPort)
|
|
287
305
|
}),
|
|
288
306
|
device: z2.strictObject({
|
|
289
307
|
host: pathSchema,
|
|
290
|
-
port: tcpPort.default(
|
|
308
|
+
port: tcpPort.default(runtimePort)
|
|
291
309
|
}),
|
|
292
310
|
credentials: z2.strictObject({
|
|
293
311
|
usernameEnv: envName,
|
|
@@ -311,87 +329,92 @@ var releaseConfigSchema = configSchema.omit({
|
|
|
311
329
|
online: true,
|
|
312
330
|
bulkImport: true
|
|
313
331
|
});
|
|
314
|
-
var
|
|
332
|
+
var compilerDecided = {
|
|
315
333
|
sourceDir: true,
|
|
316
334
|
entry: true,
|
|
317
335
|
outDir: true,
|
|
318
336
|
task: true,
|
|
319
337
|
tasks: true
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}
|
|
338
|
+
};
|
|
339
|
+
var isCompilerDecided = (key) => Object.hasOwn(compilerDecided, key);
|
|
340
|
+
var engineeringBuildSchema = configSchema.omit(compilerDecided);
|
|
341
|
+
var engineeringBuildOptions = (build) => {
|
|
342
|
+
const settings = { ...build };
|
|
343
|
+
for (const key of Object.keys(settings)) {
|
|
344
|
+
if (isCompilerDecided(key)) {
|
|
345
|
+
delete settings[key];
|
|
346
|
+
}
|
|
347
|
+
}
|
|
330
348
|
return settings;
|
|
331
|
-
}
|
|
349
|
+
};
|
|
332
350
|
|
|
333
351
|
// packages/config/src/project-files.ts
|
|
352
|
+
import { z as z3 } from "zod";
|
|
334
353
|
var generatedDirectory = ".tsplc";
|
|
335
354
|
var emittedStDirectory = `${generatedDirectory}/artifacts/st`;
|
|
355
|
+
var ioSymbolsSchema = z3.record(z3.string(), z3.string());
|
|
336
356
|
var projectSnapshotFile = `${generatedDirectory}/project.json`;
|
|
337
357
|
|
|
338
358
|
// packages/config/src/schema.ts
|
|
339
|
-
var httpOptionsSchema =
|
|
340
|
-
timeoutMs:
|
|
341
|
-
credentials:
|
|
359
|
+
var httpOptionsSchema = z4.strictObject({
|
|
360
|
+
timeoutMs: z4.number().int().positive().max(60000).default(2000),
|
|
361
|
+
credentials: z4.array(z4.strictObject({
|
|
342
362
|
originEnv: envName,
|
|
343
363
|
bearerTokenEnv: envName
|
|
344
364
|
})).default([])
|
|
345
365
|
}).prefault({});
|
|
346
|
-
var ioBindingSchema =
|
|
366
|
+
var ioBindingSchema = z4.union([
|
|
347
367
|
directIoBindingSchema,
|
|
348
|
-
|
|
349
|
-
device:
|
|
350
|
-
channel:
|
|
368
|
+
z4.strictObject({
|
|
369
|
+
device: z4.string().nonempty(),
|
|
370
|
+
channel: z4.string().nonempty(),
|
|
351
371
|
...ioBindingOptions
|
|
352
372
|
})
|
|
353
373
|
]);
|
|
354
|
-
var assemblySchema =
|
|
355
|
-
assembly:
|
|
356
|
-
size:
|
|
374
|
+
var assemblySchema = z4.strictObject({
|
|
375
|
+
assembly: z4.number().int().nonnegative().optional(),
|
|
376
|
+
size: z4.number().int().positive().optional(),
|
|
357
377
|
address: assemblyAddress.optional()
|
|
358
378
|
});
|
|
359
|
-
var hardwareDeviceSchema =
|
|
360
|
-
file:
|
|
361
|
-
connection:
|
|
379
|
+
var hardwareDeviceSchema = z4.strictObject({
|
|
380
|
+
file: z4.string().nonempty(),
|
|
381
|
+
connection: z4.string().nonempty().optional(),
|
|
362
382
|
inputs: assemblySchema.optional(),
|
|
363
383
|
outputs: assemblySchema.optional(),
|
|
364
|
-
modbus:
|
|
384
|
+
modbus: z4.strictObject({
|
|
365
385
|
port: tcpPort.default(502),
|
|
366
|
-
registers:
|
|
386
|
+
registers: z4.record(iecName, z4.number().int().min(0).max(65535))
|
|
367
387
|
}).optional(),
|
|
368
|
-
statusSymbols:
|
|
369
|
-
network:
|
|
370
|
-
address:
|
|
388
|
+
statusSymbols: z4.record(z4.string(), z4.string()).optional(),
|
|
389
|
+
network: z4.strictObject({
|
|
390
|
+
address: z4.ipv4().optional(),
|
|
371
391
|
rpi: durationSchema.refine((rpi) => BigInt(rpi.nanoseconds) % 1000n === 0n, "An RPI must be a whole number of microseconds.").optional()
|
|
372
392
|
}).optional()
|
|
373
393
|
});
|
|
374
|
-
var dependencySchema =
|
|
394
|
+
var dependencySchema = z4.union([
|
|
375
395
|
fourPartVersion,
|
|
376
|
-
|
|
396
|
+
z4.strictObject({
|
|
377
397
|
version: fourPartVersion,
|
|
378
|
-
company:
|
|
379
|
-
namespace:
|
|
398
|
+
company: z4.string().optional(),
|
|
399
|
+
namespace: z4.string().optional()
|
|
380
400
|
}),
|
|
381
|
-
|
|
401
|
+
z4.strictObject({
|
|
402
|
+
path: z4.string().nonempty(),
|
|
403
|
+
namespace: z4.string().optional()
|
|
404
|
+
})
|
|
382
405
|
]);
|
|
383
406
|
var codesysTaskSchema = taskSchema.extend({
|
|
384
407
|
name: iecName,
|
|
385
408
|
priority: taskPriority
|
|
386
409
|
});
|
|
387
|
-
var monitorSchema =
|
|
388
|
-
endpoint:
|
|
389
|
-
namespaceUri:
|
|
390
|
-
symbols:
|
|
391
|
-
securityMode:
|
|
392
|
-
securityPolicy:
|
|
393
|
-
certificateDirectory:
|
|
394
|
-
username:
|
|
410
|
+
var monitorSchema = z4.strictObject({
|
|
411
|
+
endpoint: z4.string().url(),
|
|
412
|
+
namespaceUri: z4.string().optional(),
|
|
413
|
+
symbols: z4.array(z4.string().nonempty()).optional(),
|
|
414
|
+
securityMode: z4.enum(["None", "Sign", "SignAndEncrypt"]).default("SignAndEncrypt"),
|
|
415
|
+
securityPolicy: z4.enum(["None", "Basic256Sha256"]).optional(),
|
|
416
|
+
certificateDirectory: z4.string().nonempty().default(`${generatedDirectory}/opcua-pki`),
|
|
417
|
+
username: z4.string().nonempty().optional(),
|
|
395
418
|
passwordEnv: envName.optional()
|
|
396
419
|
}).superRefine((monitor, context) => {
|
|
397
420
|
if (monitor.securityPolicy && monitor.securityMode === "None" !== (monitor.securityPolicy === "None")) {
|
|
@@ -419,71 +442,70 @@ var monitorSchema = z3.strictObject({
|
|
|
419
442
|
...monitor,
|
|
420
443
|
securityPolicy: monitor.securityPolicy ?? (monitor.securityMode === "None" ? "None" : "Basic256Sha256")
|
|
421
444
|
}));
|
|
422
|
-
var telemetrySchema =
|
|
423
|
-
capacity:
|
|
424
|
-
recordBytes:
|
|
445
|
+
var telemetrySchema = z4.strictObject({
|
|
446
|
+
capacity: z4.number().int().min(4).max(4096).default(64),
|
|
447
|
+
recordBytes: z4.number().int().min(128).max(1024).default(512)
|
|
425
448
|
});
|
|
426
|
-
var debugSchema =
|
|
427
|
-
trace:
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
capacity:
|
|
431
|
-
operands:
|
|
449
|
+
var debugSchema = z4.strictObject({
|
|
450
|
+
trace: z4.union([
|
|
451
|
+
z4.literal(false),
|
|
452
|
+
z4.strictObject({
|
|
453
|
+
capacity: z4.number().int().min(16).max(4096).default(256),
|
|
454
|
+
operands: z4.number().int().min(0).max(8).default(4)
|
|
432
455
|
})
|
|
433
456
|
]).default(false),
|
|
434
|
-
writers:
|
|
435
|
-
|
|
436
|
-
|
|
457
|
+
writers: z4.union([
|
|
458
|
+
z4.boolean(),
|
|
459
|
+
z4.strictObject({ paths: z4.array(z4.string().nonempty()).nonempty() })
|
|
437
460
|
]).default(true),
|
|
438
|
-
jobs:
|
|
439
|
-
watch:
|
|
440
|
-
requests:
|
|
441
|
-
capacity:
|
|
442
|
-
bodies:
|
|
461
|
+
jobs: z4.boolean().default(true),
|
|
462
|
+
watch: z4.record(z4.string(), z4.array(z4.string().nonempty())).default({}),
|
|
463
|
+
requests: z4.strictObject({
|
|
464
|
+
capacity: z4.number().int().min(1).max(1e5).default(1000),
|
|
465
|
+
bodies: z4.boolean().default(false)
|
|
443
466
|
}).prefault({})
|
|
444
467
|
});
|
|
445
|
-
var typegenSchema =
|
|
446
|
-
types:
|
|
447
|
-
globals:
|
|
448
|
-
dir:
|
|
449
|
-
declarations:
|
|
450
|
-
ioTypes:
|
|
468
|
+
var typegenSchema = z4.strictObject({
|
|
469
|
+
types: z4.union([z4.string(), z4.array(z4.string())]).optional(),
|
|
470
|
+
globals: z4.union([z4.string(), z4.array(z4.string())]).optional(),
|
|
471
|
+
dir: z4.string().default("generated"),
|
|
472
|
+
declarations: z4.boolean().default(true),
|
|
473
|
+
ioTypes: z4.boolean().default(true)
|
|
451
474
|
});
|
|
452
|
-
var buildTargetSchema =
|
|
453
|
-
var publicationSchema =
|
|
454
|
-
production:
|
|
455
|
-
development:
|
|
475
|
+
var buildTargetSchema = z4.enum(["production", "development"]);
|
|
476
|
+
var publicationSchema = z4.strictObject({
|
|
477
|
+
production: z4.array(z4.string().nonempty()),
|
|
478
|
+
development: z4.array(z4.string().nonempty())
|
|
456
479
|
});
|
|
457
|
-
var
|
|
458
|
-
var
|
|
459
|
-
var
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
kind: z3.literal("button"),
|
|
480
|
+
var hmiTarget = z4.string().regex(/^\w+(\.\w+|\[\d+\])+$/);
|
|
481
|
+
var hmiControlId = z4.string().nonempty();
|
|
482
|
+
var hmiControlSchema = z4.discriminatedUnion("kind", [
|
|
483
|
+
z4.strictObject({
|
|
484
|
+
kind: z4.literal("button"),
|
|
463
485
|
id: hmiControlId,
|
|
464
|
-
label:
|
|
486
|
+
label: z4.string().nonempty(),
|
|
465
487
|
target: hmiTarget,
|
|
466
|
-
tone:
|
|
467
|
-
confirm:
|
|
488
|
+
tone: z4.enum(["start", "stop"]).optional(),
|
|
489
|
+
confirm: z4.boolean().optional()
|
|
468
490
|
}),
|
|
469
|
-
|
|
470
|
-
kind:
|
|
491
|
+
z4.strictObject({
|
|
492
|
+
kind: z4.literal("toggle"),
|
|
471
493
|
id: hmiControlId,
|
|
472
|
-
label:
|
|
494
|
+
label: z4.string().nonempty(),
|
|
473
495
|
target: hmiTarget
|
|
474
496
|
}),
|
|
475
|
-
|
|
476
|
-
kind:
|
|
497
|
+
z4.strictObject({
|
|
498
|
+
kind: z4.literal("slider"),
|
|
477
499
|
id: hmiControlId,
|
|
478
|
-
label:
|
|
500
|
+
label: z4.string().nonempty(),
|
|
479
501
|
target: hmiTarget,
|
|
480
|
-
min:
|
|
481
|
-
max:
|
|
502
|
+
min: z4.number().int(),
|
|
503
|
+
max: z4.number().int()
|
|
482
504
|
})
|
|
483
505
|
]);
|
|
484
|
-
var hmiSchema =
|
|
485
|
-
title:
|
|
486
|
-
controls:
|
|
506
|
+
var hmiSchema = z4.strictObject({
|
|
507
|
+
title: z4.string().nonempty(),
|
|
508
|
+
controls: z4.array(hmiControlSchema).default([]).superRefine((controls, context) => {
|
|
487
509
|
const seen = new Set;
|
|
488
510
|
controls.forEach((control, index) => {
|
|
489
511
|
if (seen.has(control.id)) {
|
|
@@ -496,22 +518,22 @@ var hmiSchema = z3.strictObject({
|
|
|
496
518
|
seen.add(control.id);
|
|
497
519
|
});
|
|
498
520
|
}),
|
|
499
|
-
conveyors:
|
|
500
|
-
label:
|
|
501
|
-
positions:
|
|
502
|
-
diverters:
|
|
521
|
+
conveyors: z4.array(z4.strictObject({
|
|
522
|
+
label: z4.string().nonempty(),
|
|
523
|
+
positions: z4.number().int().positive(),
|
|
524
|
+
diverters: z4.array(z4.number().int().nonnegative()).default([])
|
|
503
525
|
})).default([])
|
|
504
526
|
});
|
|
505
|
-
var tsplcConfigSchema =
|
|
506
|
-
name:
|
|
507
|
-
backend:
|
|
527
|
+
var tsplcConfigSchema = z4.strictObject({
|
|
528
|
+
name: z4.string().default("Application"),
|
|
529
|
+
backend: z4.literal("codesys"),
|
|
508
530
|
publish: publicationSchema.optional(),
|
|
509
|
-
server:
|
|
510
|
-
baseUrlEnv:
|
|
511
|
-
transport:
|
|
512
|
-
runtime:
|
|
513
|
-
entry:
|
|
514
|
-
target:
|
|
531
|
+
server: z4.strictObject({
|
|
532
|
+
baseUrlEnv: envName.optional(),
|
|
533
|
+
transport: z4.enum(["http", "opcua"]).default("http"),
|
|
534
|
+
runtime: z4.strictObject({
|
|
535
|
+
entry: z4.string(),
|
|
536
|
+
target: z4.enum([
|
|
515
537
|
"bun-linux-x64",
|
|
516
538
|
"bun-linux-arm64",
|
|
517
539
|
"bun-darwin-x64",
|
|
@@ -520,49 +542,63 @@ var tsplcConfigSchema = z3.strictObject({
|
|
|
520
542
|
]).optional()
|
|
521
543
|
}).optional()
|
|
522
544
|
}).optional(),
|
|
523
|
-
compiler:
|
|
524
|
-
tsconfig:
|
|
525
|
-
programs:
|
|
545
|
+
compiler: z4.strictObject({
|
|
546
|
+
tsconfig: z4.string().default("tsconfig.json"),
|
|
547
|
+
programs: z4.record(z4.string(), sourceExportSchema)
|
|
526
548
|
}).optional(),
|
|
527
|
-
tasks:
|
|
549
|
+
tasks: z4.array(codesysTaskSchema).nonempty().optional(),
|
|
528
550
|
build: configSchema.extend({ task: configSchema.shape.task.unwrap().optional() }).optional(),
|
|
529
|
-
codesys:
|
|
551
|
+
codesys: z4.strictObject({
|
|
530
552
|
http: httpOptionsSchema.optional(),
|
|
531
|
-
programNames:
|
|
532
|
-
deviceTree:
|
|
533
|
-
controllers:
|
|
553
|
+
programNames: z4.record(z4.string(), z4.string()).optional(),
|
|
554
|
+
deviceTree: z4.strictObject({ ethernet: ethernetSchema.optional() }).optional(),
|
|
555
|
+
controllers: z4.strictObject({
|
|
534
556
|
production: controllerTargetSchema.optional(),
|
|
535
557
|
development: controllerTargetSchema.optional()
|
|
536
558
|
}).optional()
|
|
537
559
|
}).optional(),
|
|
538
|
-
eds:
|
|
539
|
-
devices:
|
|
540
|
-
io:
|
|
541
|
-
dependencies:
|
|
560
|
+
eds: z4.union([z4.string(), z4.array(z4.string())]).default("eds"),
|
|
561
|
+
devices: z4.record(z4.string(), hardwareDeviceSchema).default({}),
|
|
562
|
+
io: z4.record(z4.string(), ioBindingSchema).default({}),
|
|
563
|
+
dependencies: z4.record(z4.string(), dependencySchema).default({}),
|
|
542
564
|
typegen: typegenSchema.optional(),
|
|
543
565
|
monitor: monitorSchema.optional(),
|
|
544
566
|
hmi: hmiSchema.optional(),
|
|
545
567
|
telemetry: telemetrySchema.optional(),
|
|
546
568
|
debug: debugSchema.optional(),
|
|
547
|
-
targets:
|
|
548
|
-
values:
|
|
549
|
-
agent:
|
|
569
|
+
targets: z4.record(z4.string().nonempty(), z4.strictObject({
|
|
570
|
+
values: z4.record(envName, z4.string()).default({}),
|
|
571
|
+
agent: z4.strictObject({ url: z4.url() }).optional()
|
|
550
572
|
})).default({}),
|
|
551
|
-
secrets:
|
|
552
|
-
service:
|
|
553
|
-
names:
|
|
573
|
+
secrets: z4.strictObject({
|
|
574
|
+
service: z4.string().nonempty(),
|
|
575
|
+
names: z4.array(envName).nonempty()
|
|
554
576
|
}).optional()
|
|
577
|
+
}).superRefine((config, context) => {
|
|
578
|
+
if (config.compiler && !config.tasks) {
|
|
579
|
+
context.addIssue({
|
|
580
|
+
code: "custom",
|
|
581
|
+
path: ["tasks"],
|
|
582
|
+
message: "TypeScript programs require a tasks configuration."
|
|
583
|
+
});
|
|
584
|
+
}
|
|
555
585
|
});
|
|
556
586
|
var buildTargetFor = (command) => ["run", "download", "online-change", "inspect"].includes(command) ? "development" : "production";
|
|
557
587
|
var controllerFor = (config, command) => {
|
|
558
588
|
const controller = config.codesys?.controllers?.[buildTargetFor(command)];
|
|
559
589
|
return controller && {
|
|
560
|
-
...
|
|
590
|
+
...controllerTargets[controller.target].device,
|
|
561
591
|
version: controller.version
|
|
562
592
|
};
|
|
563
593
|
};
|
|
564
|
-
var controllerDeviceName = (config, command) =>
|
|
594
|
+
var controllerDeviceName = (config, command) => controllerTargets[config.codesys?.controllers?.[buildTargetFor(command)]?.target ?? "linux-sl"].deviceName;
|
|
565
595
|
var serverTokenEnv = (config) => config.codesys?.http?.credentials.find(({ originEnv }) => originEnv === config.server?.baseUrlEnv)?.bearerTokenEnv;
|
|
596
|
+
var serverBaseUrl = (config, env) => config.server?.baseUrlEnv === undefined ? undefined : env[config.server.baseUrlEnv];
|
|
597
|
+
var typegenSettings = (config) => config.typegen ?? typegenSchema.parse({});
|
|
598
|
+
var projectSlugs = {
|
|
599
|
+
kebab: (name) => name.replace(/([a-z0-9])([A-Z])|([A-Z])([A-Z][a-z])/g, "$1$3-$2$4").replace(/[^A-Za-z0-9]+/g, "-").replace(/^-|-$/g, "").toLowerCase(),
|
|
600
|
+
runtime: (name) => name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().replace(/[^a-z0-9_-]+/g, "-")
|
|
601
|
+
};
|
|
566
602
|
var simulationConfig = (config) => ({
|
|
567
603
|
...config,
|
|
568
604
|
eds: [],
|
|
@@ -593,14 +629,15 @@ function rawBuildConfig(config) {
|
|
|
593
629
|
}
|
|
594
630
|
return {
|
|
595
631
|
...config.build,
|
|
596
|
-
tasks: cyclicTasksSchema.parse(config.tasks
|
|
597
|
-
name: task.name,
|
|
598
|
-
intervalNanoseconds: task.schedule.interval.nanoseconds,
|
|
599
|
-
priority: task.priority,
|
|
600
|
-
programs: task.programs
|
|
601
|
-
})))
|
|
632
|
+
tasks: cyclicTasksSchema.parse(taskPlan(config.tasks))
|
|
602
633
|
};
|
|
603
634
|
}
|
|
635
|
+
var taskPlan = (tasks) => tasks.map((task) => ({
|
|
636
|
+
name: task.name,
|
|
637
|
+
intervalNanoseconds: task.schedule.interval.nanoseconds,
|
|
638
|
+
priority: task.priority,
|
|
639
|
+
programs: task.programs
|
|
640
|
+
}));
|
|
604
641
|
function compilerConfig(config, io, buildTarget = "production") {
|
|
605
642
|
if (!config.compiler || !config.tasks) {
|
|
606
643
|
throw new Error("This project uses raw Structured Text; no TypeScript compiler is configured.");
|
|
@@ -645,7 +682,7 @@ function compilerConfig(config, io, buildTarget = "production") {
|
|
|
645
682
|
}
|
|
646
683
|
function mappedChannel(config, name, binding) {
|
|
647
684
|
const source = config.io[name];
|
|
648
|
-
return config.codesys?.deviceTree !== undefined && source !== undefined && "device" in source && !binding.inverted && !binding.shared &&
|
|
685
|
+
return config.codesys?.deviceTree !== undefined && source !== undefined && "device" in source && !binding.inverted && !binding.shared && channelAddress.safeParse(binding.address).success && !/^ARRAY/i.test(binding.type ?? "");
|
|
649
686
|
}
|
|
650
687
|
export {
|
|
651
688
|
buildTargetFor,
|
|
@@ -661,16 +698,20 @@ export {
|
|
|
661
698
|
ioSymbolsSchema,
|
|
662
699
|
ms,
|
|
663
700
|
ns,
|
|
701
|
+
projectSlugs,
|
|
664
702
|
publicationSchema,
|
|
665
703
|
rawBuildConfig,
|
|
666
704
|
seconds,
|
|
705
|
+
serverBaseUrl,
|
|
667
706
|
serverTokenEnv,
|
|
668
707
|
simulationConfig,
|
|
708
|
+
taskPlan,
|
|
669
709
|
telemetrySchema,
|
|
670
710
|
tsplcConfigSchema,
|
|
671
711
|
typegenSchema,
|
|
712
|
+
typegenSettings,
|
|
672
713
|
validateConfig
|
|
673
714
|
};
|
|
674
715
|
|
|
675
|
-
//# debugId=
|
|
716
|
+
//# debugId=5A66D913A18FF94D64756E2164756E21
|
|
676
717
|
//# sourceMappingURL=schema.js.map
|