@tsplc/config 0.5.13 → 0.5.15

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/schema.js CHANGED
@@ -1,16 +1,19 @@
1
1
  // packages/config/src/schema.ts
2
- import { z as z3 } from "zod";
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 nanosecondsPattern = /^[1-9][0-9]*$/;
10
- var durationSchema = z.object({
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: z.string().regex(nanosecondsPattern)
13
- }).strict();
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, 1e6);
26
- var seconds = (value) => duration(value, 1e9);
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.object({ module: z.string().min(1), export: z.string().min(1) }).strict();
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 targetSchema = z.object({
39
- kind: z.string().min(1),
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
- }).strict();
69
+ });
44
70
  var common = {
45
- name: z.string().min(1),
46
- tsconfig: z.string().min(1),
47
- tasks: z.array(taskSchema).min(1),
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.object({ ...common, entry: sourceExportSchema }).strict();
51
- var programsConfigSchema = z.object({
76
+ var entryConfigSchema = z.strictObject({
52
77
  ...common,
53
- programs: z.record(z.string().min(1), sourceExportSchema)
54
- }).strict();
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 taskNames = new Set;
86
- const assigned = new Set;
87
- for (const task of data.tasks) {
88
- if (taskNames.has(task.name)) {
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
- taskNames.add(task.name);
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 (assigned.has(program)) {
124
+ if (repeated(index, position)) {
97
125
  report(`Program ${program} must belong to exactly one task.`);
98
126
  }
99
- assigned.add(program);
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 (!assigned.has(program)) {
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(/^[A-Za-z][A-Za-z0-9_]*$/);
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: z2.string().regex(nanosecondsPattern).refine((value) => {
156
- if (!nanosecondsPattern.test(value)) {
157
- return false;
158
- }
185
+ intervalNanoseconds: nanosecondsSchema.refine((value) => {
159
186
  const ns = BigInt(value);
160
- return ns % 1000000n === 0n && ns <= 4294967295000000n;
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 names = new Set;
166
- const programs = new Set;
167
- tasks.forEach((task, index) => {
168
- if (names.has(task.name.toLowerCase())) {
169
- context.addIssue({
170
- code: "custom",
171
- path: [index, "name"],
172
- message: "Task names must be unique"
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 controllerDevices = {
249
- "linux-sl": { type: 4102, id: "0000 0005" },
250
- "virtual-linux-arm64-sl": { type: 4096, id: "0000 1008" }
251
- };
252
- var controllerDeviceNames = {
253
- "linux-sl": "CODESYS Control for Linux SL",
254
- "virtual-linux-arm64-sl": "CODESYS Virtual Control for Linux ARM64 SL"
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(1217)
304
+ port: tcpPort.default(gatewayPort)
287
305
  }),
288
306
  device: z2.strictObject({
289
307
  host: pathSchema,
290
- port: tcpPort.default(11740)
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 engineeringBuildSchema = configSchema.omit({
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
- function engineeringBuildOptions(build) {
322
- const {
323
- sourceDir: _source,
324
- entry: _entry,
325
- outDir: _out,
326
- task: _task,
327
- tasks: _tasks,
328
- ...settings
329
- } = build;
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 = z3.strictObject({
340
- timeoutMs: z3.number().int().positive().max(60000).default(2000),
341
- credentials: z3.array(z3.strictObject({
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 = z3.union([
366
+ var ioBindingSchema = z4.union([
347
367
  directIoBindingSchema,
348
- z3.strictObject({
349
- device: z3.string().min(1),
350
- channel: z3.string().min(1),
368
+ z4.strictObject({
369
+ device: z4.string().nonempty(),
370
+ channel: z4.string().nonempty(),
351
371
  ...ioBindingOptions
352
372
  })
353
373
  ]);
354
- var assemblySchema = z3.strictObject({
355
- assembly: z3.number().int().nonnegative().optional(),
356
- size: z3.number().int().positive().optional(),
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 = z3.strictObject({
360
- file: z3.string().min(1),
361
- connection: z3.string().min(1).optional(),
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: z3.strictObject({
384
+ modbus: z4.strictObject({
365
385
  port: tcpPort.default(502),
366
- registers: z3.record(iecName, z3.number().int().min(0).max(65535))
386
+ registers: z4.record(iecName, z4.number().int().min(0).max(65535))
367
387
  }).optional(),
368
- statusSymbols: z3.record(z3.string(), z3.string()).optional(),
369
- network: z3.strictObject({
370
- address: z3.ipv4().optional(),
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 = z3.union([
394
+ var dependencySchema = z4.union([
375
395
  fourPartVersion,
376
- z3.strictObject({
396
+ z4.strictObject({
377
397
  version: fourPartVersion,
378
- company: z3.string().optional(),
379
- namespace: z3.string().optional()
398
+ company: z4.string().optional(),
399
+ namespace: z4.string().optional()
380
400
  }),
381
- z3.strictObject({ path: z3.string().min(1), namespace: z3.string().optional() })
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 = z3.strictObject({
388
- endpoint: z3.string().url(),
389
- namespaceUri: z3.string().optional(),
390
- symbols: z3.array(z3.string().min(1)).optional(),
391
- securityMode: z3.enum(["None", "Sign", "SignAndEncrypt"]).default("SignAndEncrypt"),
392
- securityPolicy: z3.enum(["None", "Basic256Sha256"]).optional(),
393
- certificateDirectory: z3.string().min(1).default(`${generatedDirectory}/opcua-pki`),
394
- username: z3.string().min(1).optional(),
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 = z3.strictObject({
423
- capacity: z3.number().int().min(4).max(4096).default(64),
424
- recordBytes: z3.number().int().min(128).max(1024).default(512)
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 = z3.strictObject({
427
- trace: z3.union([
428
- z3.literal(false),
429
- z3.strictObject({
430
- capacity: z3.number().int().min(16).max(4096).default(256),
431
- operands: z3.number().int().min(0).max(8).default(4)
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: z3.union([
435
- z3.boolean(),
436
- z3.strictObject({ paths: z3.array(z3.string().nonempty()).nonempty() })
457
+ writers: z4.union([
458
+ z4.boolean(),
459
+ z4.strictObject({ paths: z4.array(z4.string().nonempty()).nonempty() })
437
460
  ]).default(true),
438
- jobs: z3.boolean().default(true),
439
- watch: z3.record(z3.string(), z3.array(z3.string().min(1))).default({}),
440
- requests: z3.strictObject({
441
- capacity: z3.number().int().min(1).max(1e5).default(1000),
442
- bodies: z3.boolean().default(false)
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 = z3.strictObject({
446
- types: z3.union([z3.string(), z3.array(z3.string())]).optional(),
447
- globals: z3.union([z3.string(), z3.array(z3.string())]).optional(),
448
- dir: z3.string().default("generated"),
449
- declarations: z3.boolean().default(true),
450
- ioTypes: z3.boolean().default(true)
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 = z3.enum(["production", "development"]);
453
- var publicationSchema = z3.strictObject({
454
- production: z3.array(z3.string().nonempty()),
455
- development: z3.array(z3.string().nonempty())
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 ioSymbolsSchema = z3.record(z3.string(), z3.string());
458
- var hmiTarget = z3.string().regex(/^\w+(\.\w+|\[\d+\])+$/);
459
- var hmiControlId = z3.string().nonempty();
460
- var hmiControlSchema = z3.discriminatedUnion("kind", [
461
- z3.strictObject({
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: z3.string().nonempty(),
486
+ label: z4.string().nonempty(),
465
487
  target: hmiTarget,
466
- tone: z3.enum(["start", "stop"]).optional(),
467
- confirm: z3.boolean().optional()
488
+ tone: z4.enum(["start", "stop"]).optional(),
489
+ confirm: z4.boolean().optional()
468
490
  }),
469
- z3.strictObject({
470
- kind: z3.literal("toggle"),
491
+ z4.strictObject({
492
+ kind: z4.literal("toggle"),
471
493
  id: hmiControlId,
472
- label: z3.string().nonempty(),
494
+ label: z4.string().nonempty(),
473
495
  target: hmiTarget
474
496
  }),
475
- z3.strictObject({
476
- kind: z3.literal("slider"),
497
+ z4.strictObject({
498
+ kind: z4.literal("slider"),
477
499
  id: hmiControlId,
478
- label: z3.string().nonempty(),
500
+ label: z4.string().nonempty(),
479
501
  target: hmiTarget,
480
- min: z3.number().int(),
481
- max: z3.number().int()
502
+ min: z4.number().int(),
503
+ max: z4.number().int()
482
504
  })
483
505
  ]);
484
- var hmiSchema = z3.strictObject({
485
- title: z3.string().nonempty(),
486
- controls: z3.array(hmiControlSchema).default([]).superRefine((controls, context) => {
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: z3.array(z3.strictObject({
500
- label: z3.string().nonempty(),
501
- positions: z3.number().int().positive(),
502
- diverters: z3.array(z3.number().int().nonnegative()).default([])
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 = z3.strictObject({
506
- name: z3.string().default("Application"),
507
- backend: z3.literal("codesys"),
527
+ var tsplcConfigSchema = z4.strictObject({
528
+ name: z4.string().default("Application"),
529
+ backend: z4.literal("codesys"),
508
530
  publish: publicationSchema.optional(),
509
- server: z3.strictObject({
510
- baseUrlEnv: z3.string().optional(),
511
- transport: z3.enum(["http", "opcua"]).default("http"),
512
- runtime: z3.strictObject({
513
- entry: z3.string(),
514
- target: z3.enum([
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: z3.strictObject({
524
- tsconfig: z3.string().default("tsconfig.json"),
525
- programs: z3.record(z3.string(), z3.strictObject({ module: z3.string(), export: z3.string() }))
545
+ compiler: z4.strictObject({
546
+ tsconfig: z4.string().default("tsconfig.json"),
547
+ programs: z4.record(z4.string(), sourceExportSchema)
526
548
  }).optional(),
527
- tasks: z3.array(codesysTaskSchema).nonempty().optional(),
549
+ tasks: z4.array(codesysTaskSchema).nonempty().optional(),
528
550
  build: configSchema.extend({ task: configSchema.shape.task.unwrap().optional() }).optional(),
529
- codesys: z3.strictObject({
551
+ codesys: z4.strictObject({
530
552
  http: httpOptionsSchema.optional(),
531
- programNames: z3.record(z3.string(), z3.string()).optional(),
532
- deviceTree: z3.strictObject({ ethernet: ethernetSchema.optional() }).optional(),
533
- controllers: z3.strictObject({
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: z3.union([z3.string(), z3.array(z3.string())]).default("eds"),
539
- devices: z3.record(z3.string(), hardwareDeviceSchema).default({}),
540
- io: z3.record(z3.string(), ioBindingSchema).default({}),
541
- dependencies: z3.record(z3.string(), dependencySchema).default({}),
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: z3.record(z3.string().nonempty(), z3.strictObject({
548
- values: z3.record(envName, z3.string()).default({}),
549
- agent: z3.strictObject({ url: z3.url() }).optional()
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: z3.strictObject({
552
- service: z3.string().nonempty(),
553
- names: z3.array(envName).nonempty()
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
- ...controllerDevices[controller.target],
590
+ ...controllerTargets[controller.target].device,
561
591
  version: controller.version
562
592
  };
563
593
  };
564
- var controllerDeviceName = (config, command) => controllerDeviceNames[config.codesys?.controllers?.[buildTargetFor(command)]?.target ?? "linux-sl"];
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.map((task) => ({
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 && /^%[IQ][XB]/.test(binding.address) && !/^ARRAY/i.test(binding.type ?? "");
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=A2939D575559A6DD64756E2164756E21
716
+ //# debugId=5A66D913A18FF94D64756E2164756E21
676
717
  //# sourceMappingURL=schema.js.map