@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/README.md CHANGED
@@ -1,7 +1,37 @@
1
1
  # @tsplc/config
2
2
 
3
- Part of [tsPLC](https://github.com/rip-technologies/tsplc).
3
+ The schema of `tsplc.config.ts`, the file that describes a tsPLC project, with `defineConfig`, the duration helpers and the config loader. Part of [tsPLC](https://github.com/rip-technologies/tsplc).
4
4
 
5
- The shared `tsplc.config.ts` schema: `defineConfig`, tasks, build and Docker settings, hardware devices, IO bindings, library dependencies, typegen and monitor options. Every tsPLC package and the editor read the same file.
5
+ ## Install
6
6
 
7
- See the [documentation](https://github.com/rip-technologies/tsplc/tree/master/docs). MIT licensed.
7
+ ```sh
8
+ bun add @tsplc/config
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ // tsplc.config.ts
15
+ import { defineConfig, ms } from "@tsplc/config";
16
+
17
+ export default defineConfig({
18
+ name: "PartCounter",
19
+ backend: "codesys",
20
+ compiler: {
21
+ programs: { main: { module: "src/main.ts", export: "main" } },
22
+ },
23
+ tasks: [
24
+ { name: "MainTask", priority: 1, schedule: { kind: "cyclic", interval: ms(10) }, programs: ["main"] },
25
+ ],
26
+ io: {
27
+ "io.partSensor": { address: "%IX0.0" },
28
+ "io.binFull": { address: "%QX0.0" },
29
+ },
30
+ });
31
+ ```
32
+
33
+ ## Documentation
34
+
35
+ [Configuration reference](https://github.com/rip-technologies/tsplc/blob/master/docs/04-reference/configuration.md).
36
+
37
+ MIT licensed.
package/dist/build.js CHANGED
@@ -11,15 +11,38 @@ var __esm = (fn, res, err) => () => {
11
11
  };
12
12
 
13
13
  // packages/config/src/compiler.ts
14
+ import { nanosecondsPerMillisecond } from "@tsplc/iec";
14
15
  import { z } from "zod";
15
- var nanosecondsPattern, durationSchema, sourceExportSchema, taskSchema, targetSchema, common, entryConfigSchema, programsConfigSchema;
16
+ var nanosecondsSchema, durationSchema, sourceExportSchema, taskSchema, scheduleRepeats = (tasks) => {
17
+ const names = new Set;
18
+ const programs = new Set;
19
+ const repeats = [];
20
+ tasks.forEach((task, index) => {
21
+ const name = task.name.toUpperCase();
22
+ if (names.has(name)) {
23
+ repeats.push({ task: index, position: null });
24
+ }
25
+ names.add(name);
26
+ task.programs.forEach((program, position) => {
27
+ const scheduled = program.toUpperCase();
28
+ if (programs.has(scheduled)) {
29
+ repeats.push({ task: index, position });
30
+ }
31
+ programs.add(scheduled);
32
+ });
33
+ });
34
+ return repeats;
35
+ }, targetSchema, common, entryConfigSchema, programsConfigSchema;
16
36
  var init_compiler = __esm(() => {
17
- nanosecondsPattern = /^[1-9][0-9]*$/;
18
- durationSchema = z.object({
37
+ nanosecondsSchema = z.string().regex(/^[1-9][0-9]*$/, { abort: true });
38
+ durationSchema = z.strictObject({
19
39
  kind: z.literal("duration"),
20
- nanoseconds: z.string().regex(nanosecondsPattern)
21
- }).strict();
22
- sourceExportSchema = z.object({ module: z.string().min(1), export: z.string().min(1) }).strict();
40
+ nanoseconds: nanosecondsSchema
41
+ });
42
+ sourceExportSchema = z.strictObject({
43
+ module: z.string().nonempty(),
44
+ export: z.string().nonempty()
45
+ });
23
46
  taskSchema = z.strictObject({
24
47
  name: z.string().nonempty(),
25
48
  schedule: z.strictObject({
@@ -29,31 +52,36 @@ var init_compiler = __esm(() => {
29
52
  priority: z.number().int().nonnegative(),
30
53
  programs: z.array(z.string().nonempty()).nonempty()
31
54
  });
32
- targetSchema = z.object({
33
- kind: z.string().min(1),
55
+ targetSchema = z.strictObject({
56
+ kind: z.string().nonempty(),
34
57
  options: z.unknown().refine((value) => value !== undefined, {
35
58
  message: "Target options are required."
36
59
  })
37
- }).strict();
60
+ });
38
61
  common = {
39
- name: z.string().min(1),
40
- tsconfig: z.string().min(1),
41
- tasks: z.array(taskSchema).min(1),
62
+ name: z.string().nonempty(),
63
+ tsconfig: z.string().nonempty(),
64
+ tasks: z.array(taskSchema).nonempty(),
42
65
  target: targetSchema
43
66
  };
44
- entryConfigSchema = z.object({ ...common, entry: sourceExportSchema }).strict();
45
- programsConfigSchema = z.object({
67
+ entryConfigSchema = z.strictObject({
46
68
  ...common,
47
- programs: z.record(z.string().min(1), sourceExportSchema)
48
- }).strict();
69
+ entry: sourceExportSchema
70
+ });
71
+ programsConfigSchema = z.strictObject({
72
+ ...common,
73
+ programs: z.record(z.string().nonempty(), sourceExportSchema)
74
+ });
49
75
  });
50
76
 
51
77
  // packages/config/src/build-schema.ts
78
+ import { latestTimeNanoseconds, nanosecondsPerMillisecond as nanosecondsPerMillisecond2 } from "@tsplc/iec";
79
+ import { generatedNamePattern } from "@tsplc/iec/st";
52
80
  import { z as z2 } from "zod";
53
- var commandArgumentSchema, codesysTimeouts, positiveMilliseconds, pathSchema, tcpPort, sha256Digest, envName, wineSchema, localCodesysSchema, dockerImage = "tsplc-build:latest", containerCodesys, iecName, taskPriority, cyclicTasksSchema, ioBindingOptions, directIoBindingSchema, ethernetSchema, assemblyAddress, processImageSchema, channelAddress, deviceTreeSchema, fourPartVersion, controllerSchema, controllerTargetSchema, configSchema, controllerBudgets = (timeouts) => ({
81
+ var commandArgumentSchema, codesysTimeouts, positiveMilliseconds, pathSchema, tcpPort, runtimePort = 11740, gatewayPort = 1217, opcuaPort = 4840, sha256Digest, envName, wineSchema, localCodesysSchema, dockerImage = "tsplc-build:latest", containerCodesys, iecName, taskPriority, cyclicTasksSchema, ioBindingOptions, directIoBindingSchema, ethernetSchema, assemblyAddress, processImageSchema, channelAddress, deviceTreeSchema, fourPartVersion, controllerSchema, controllerTargetSchema, configSchema, controllerBudgets = (timeouts) => ({
54
82
  prepare: timeouts.prepare ?? timeouts.build,
55
83
  transfer: timeouts.transfer ?? codesysTimeouts.transfer
56
- }), releaseConfigSchema, engineeringBuildSchema;
84
+ }), releaseConfigSchema, compilerDecided, engineeringBuildSchema;
57
85
  var init_build_schema = __esm(() => {
58
86
  init_compiler();
59
87
  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");
@@ -89,42 +117,28 @@ var init_build_schema = __esm(() => {
89
117
  profile: "CODESYS V3.5 SP22 Patch 3",
90
118
  wine: { prefix: "/tmp/codesys-wine", nativeExit: true }
91
119
  };
92
- iecName = z2.string().regex(/^[A-Za-z][A-Za-z0-9_]*$/);
120
+ iecName = z2.string().regex(generatedNamePattern);
93
121
  taskPriority = z2.number().int().min(0).max(31);
94
122
  cyclicTasksSchema = z2.array(z2.strictObject({
95
123
  name: iecName,
96
- intervalNanoseconds: z2.string().regex(nanosecondsPattern).refine((value) => {
97
- if (!nanosecondsPattern.test(value)) {
98
- return false;
99
- }
124
+ intervalNanoseconds: nanosecondsSchema.refine((value) => {
100
125
  const ns = BigInt(value);
101
- return ns % 1000000n === 0n && ns <= 4294967295000000n;
126
+ return ns % nanosecondsPerMillisecond2 === 0n && ns <= latestTimeNanoseconds;
102
127
  }, "Cyclic tasks require an exact positive TIME interval in milliseconds"),
103
128
  priority: taskPriority,
104
129
  programs: z2.array(iecName).nonempty()
105
130
  })).nonempty().superRefine((tasks, context) => {
106
- const names = new Set;
107
- const programs = new Set;
108
- tasks.forEach((task, index) => {
109
- if (names.has(task.name.toLowerCase())) {
110
- context.addIssue({
111
- code: "custom",
112
- path: [index, "name"],
113
- message: "Task names must be unique"
114
- });
115
- }
116
- names.add(task.name.toLowerCase());
117
- task.programs.forEach((program, position) => {
118
- if (programs.has(program.toLowerCase())) {
119
- context.addIssue({
120
- code: "custom",
121
- path: [index, "programs", position],
122
- message: "A program can be scheduled only once"
123
- });
124
- }
125
- programs.add(program.toLowerCase());
131
+ for (const { task, position } of scheduleRepeats(tasks)) {
132
+ context.addIssue(position === null ? {
133
+ code: "custom",
134
+ path: [task, "name"],
135
+ message: "Task names must be unique"
136
+ } : {
137
+ code: "custom",
138
+ path: [task, "programs", position],
139
+ message: "A program can be scheduled only once"
126
140
  });
127
- });
141
+ }
128
142
  });
129
143
  ioBindingOptions = {
130
144
  inverted: z2.boolean().optional(),
@@ -216,11 +230,11 @@ var init_build_schema = __esm(() => {
216
230
  network: pathSchema.default("bridge"),
217
231
  gateway: z2.strictObject({
218
232
  host: pathSchema,
219
- port: tcpPort.default(1217)
233
+ port: tcpPort.default(gatewayPort)
220
234
  }),
221
235
  device: z2.strictObject({
222
236
  host: pathSchema,
223
- port: tcpPort.default(11740)
237
+ port: tcpPort.default(runtimePort)
224
238
  }),
225
239
  credentials: z2.strictObject({
226
240
  usernameEnv: envName,
@@ -244,24 +258,27 @@ var init_build_schema = __esm(() => {
244
258
  online: true,
245
259
  bulkImport: true
246
260
  });
247
- engineeringBuildSchema = configSchema.omit({
261
+ compilerDecided = {
248
262
  sourceDir: true,
249
263
  entry: true,
250
264
  outDir: true,
251
265
  task: true,
252
266
  tasks: true
253
- });
267
+ };
268
+ engineeringBuildSchema = configSchema.omit(compilerDecided);
254
269
  });
255
270
 
256
271
  // packages/config/src/project-files.ts
257
- var generatedDirectory = ".tsplc", emittedStDirectory, projectSnapshotFile;
272
+ import { z as z4 } from "zod";
273
+ var configFileName = "tsplc.config.ts", generatedDirectory = ".tsplc", emittedStDirectory, ioSymbolsSchema, projectSnapshotFile;
258
274
  var init_project_files = __esm(() => {
259
275
  emittedStDirectory = `${generatedDirectory}/artifacts/st`;
276
+ ioSymbolsSchema = z4.record(z4.string(), z4.string());
260
277
  projectSnapshotFile = `${generatedDirectory}/project.json`;
261
278
  });
262
279
 
263
280
  // packages/config/src/schema.ts
264
- import { z as z3 } from "zod";
281
+ import { z as z5 } from "zod";
265
282
  function rawBuildConfig(config) {
266
283
  if (config.compiler) {
267
284
  throw new Error("Use the compiler build plan for TypeScript projects.");
@@ -277,75 +294,78 @@ function rawBuildConfig(config) {
277
294
  }
278
295
  return {
279
296
  ...config.build,
280
- tasks: cyclicTasksSchema.parse(config.tasks.map((task) => ({
281
- name: task.name,
282
- intervalNanoseconds: task.schedule.interval.nanoseconds,
283
- priority: task.priority,
284
- programs: task.programs
285
- })))
297
+ tasks: cyclicTasksSchema.parse(taskPlan(config.tasks))
286
298
  };
287
299
  }
288
- var httpOptionsSchema, ioBindingSchema, assemblySchema, hardwareDeviceSchema, dependencySchema, codesysTaskSchema, monitorSchema, telemetrySchema, debugSchema, typegenSchema, buildTargetSchema, publicationSchema, ioSymbolsSchema, hmiTarget, hmiControlId, hmiControlSchema, hmiSchema, tsplcConfigSchema;
300
+ var httpOptionsSchema, ioBindingSchema, assemblySchema, hardwareDeviceSchema, dependencySchema, codesysTaskSchema, monitorSchema, telemetrySchema, debugSchema, typegenSchema, buildTargetSchema, publicationSchema, hmiTarget, hmiControlId, hmiControlSchema, hmiSchema, tsplcConfigSchema, taskPlan = (tasks) => tasks.map((task) => ({
301
+ name: task.name,
302
+ intervalNanoseconds: task.schedule.interval.nanoseconds,
303
+ priority: task.priority,
304
+ programs: task.programs
305
+ }));
289
306
  var init_schema = __esm(() => {
290
307
  init_build_schema();
291
308
  init_compiler();
292
309
  init_project_files();
293
- httpOptionsSchema = z3.strictObject({
294
- timeoutMs: z3.number().int().positive().max(60000).default(2000),
295
- credentials: z3.array(z3.strictObject({
310
+ httpOptionsSchema = z5.strictObject({
311
+ timeoutMs: z5.number().int().positive().max(60000).default(2000),
312
+ credentials: z5.array(z5.strictObject({
296
313
  originEnv: envName,
297
314
  bearerTokenEnv: envName
298
315
  })).default([])
299
316
  }).prefault({});
300
- ioBindingSchema = z3.union([
317
+ ioBindingSchema = z5.union([
301
318
  directIoBindingSchema,
302
- z3.strictObject({
303
- device: z3.string().min(1),
304
- channel: z3.string().min(1),
319
+ z5.strictObject({
320
+ device: z5.string().nonempty(),
321
+ channel: z5.string().nonempty(),
305
322
  ...ioBindingOptions
306
323
  })
307
324
  ]);
308
- assemblySchema = z3.strictObject({
309
- assembly: z3.number().int().nonnegative().optional(),
310
- size: z3.number().int().positive().optional(),
325
+ assemblySchema = z5.strictObject({
326
+ assembly: z5.number().int().nonnegative().optional(),
327
+ size: z5.number().int().positive().optional(),
311
328
  address: assemblyAddress.optional()
312
329
  });
313
- hardwareDeviceSchema = z3.strictObject({
314
- file: z3.string().min(1),
315
- connection: z3.string().min(1).optional(),
330
+ hardwareDeviceSchema = z5.strictObject({
331
+ file: z5.string().nonempty(),
332
+ connection: z5.string().nonempty().optional(),
316
333
  inputs: assemblySchema.optional(),
317
334
  outputs: assemblySchema.optional(),
318
- modbus: z3.strictObject({
335
+ modbus: z5.strictObject({
319
336
  port: tcpPort.default(502),
320
- registers: z3.record(iecName, z3.number().int().min(0).max(65535))
337
+ registers: z5.record(iecName, z5.number().int().min(0).max(65535))
321
338
  }).optional(),
322
- statusSymbols: z3.record(z3.string(), z3.string()).optional(),
323
- network: z3.strictObject({
324
- address: z3.ipv4().optional(),
339
+ statusSymbols: z5.record(z5.string(), z5.string()).optional(),
340
+ network: z5.strictObject({
341
+ address: z5.ipv4().optional(),
325
342
  rpi: durationSchema.refine((rpi) => BigInt(rpi.nanoseconds) % 1000n === 0n, "An RPI must be a whole number of microseconds.").optional()
326
343
  }).optional()
327
344
  });
328
- dependencySchema = z3.union([
345
+ dependencySchema = z5.union([
329
346
  fourPartVersion,
330
- z3.strictObject({
347
+ z5.strictObject({
331
348
  version: fourPartVersion,
332
- company: z3.string().optional(),
333
- namespace: z3.string().optional()
349
+ company: z5.string().optional(),
350
+ namespace: z5.string().optional()
334
351
  }),
335
- z3.strictObject({ path: z3.string().min(1), namespace: z3.string().optional() })
352
+ z5.strictObject({
353
+ path: z5.string().nonempty(),
354
+ namespace: z5.string().optional()
355
+ })
336
356
  ]);
337
357
  codesysTaskSchema = taskSchema.extend({
338
358
  name: iecName,
339
359
  priority: taskPriority
340
360
  });
341
- monitorSchema = z3.strictObject({
342
- endpoint: z3.string().url(),
343
- namespaceUri: z3.string().optional(),
344
- symbols: z3.array(z3.string().min(1)).optional(),
345
- securityMode: z3.enum(["None", "Sign", "SignAndEncrypt"]).default("SignAndEncrypt"),
346
- securityPolicy: z3.enum(["None", "Basic256Sha256"]).optional(),
347
- certificateDirectory: z3.string().min(1).default(`${generatedDirectory}/opcua-pki`),
348
- username: z3.string().min(1).optional(),
361
+ monitorSchema = z5.strictObject({
362
+ endpoint: z5.string().url(),
363
+ namespaceUri: z5.string().optional(),
364
+ symbols: z5.array(z5.string().nonempty()).optional(),
365
+ securityMode: z5.enum(["None", "Sign", "SignAndEncrypt"]).default("SignAndEncrypt"),
366
+ securityPolicy: z5.enum(["None", "Basic256Sha256"]).optional(),
367
+ certificateDirectory: z5.string().nonempty().default(`${generatedDirectory}/opcua-pki`),
368
+ username: z5.string().nonempty().optional(),
349
369
  passwordEnv: envName.optional()
350
370
  }).superRefine((monitor, context) => {
351
371
  if (monitor.securityPolicy && monitor.securityMode === "None" !== (monitor.securityPolicy === "None")) {
@@ -373,71 +393,70 @@ var init_schema = __esm(() => {
373
393
  ...monitor,
374
394
  securityPolicy: monitor.securityPolicy ?? (monitor.securityMode === "None" ? "None" : "Basic256Sha256")
375
395
  }));
376
- telemetrySchema = z3.strictObject({
377
- capacity: z3.number().int().min(4).max(4096).default(64),
378
- recordBytes: z3.number().int().min(128).max(1024).default(512)
396
+ telemetrySchema = z5.strictObject({
397
+ capacity: z5.number().int().min(4).max(4096).default(64),
398
+ recordBytes: z5.number().int().min(128).max(1024).default(512)
379
399
  });
380
- debugSchema = z3.strictObject({
381
- trace: z3.union([
382
- z3.literal(false),
383
- z3.strictObject({
384
- capacity: z3.number().int().min(16).max(4096).default(256),
385
- operands: z3.number().int().min(0).max(8).default(4)
400
+ debugSchema = z5.strictObject({
401
+ trace: z5.union([
402
+ z5.literal(false),
403
+ z5.strictObject({
404
+ capacity: z5.number().int().min(16).max(4096).default(256),
405
+ operands: z5.number().int().min(0).max(8).default(4)
386
406
  })
387
407
  ]).default(false),
388
- writers: z3.union([
389
- z3.boolean(),
390
- z3.strictObject({ paths: z3.array(z3.string().nonempty()).nonempty() })
408
+ writers: z5.union([
409
+ z5.boolean(),
410
+ z5.strictObject({ paths: z5.array(z5.string().nonempty()).nonempty() })
391
411
  ]).default(true),
392
- jobs: z3.boolean().default(true),
393
- watch: z3.record(z3.string(), z3.array(z3.string().min(1))).default({}),
394
- requests: z3.strictObject({
395
- capacity: z3.number().int().min(1).max(1e5).default(1000),
396
- bodies: z3.boolean().default(false)
412
+ jobs: z5.boolean().default(true),
413
+ watch: z5.record(z5.string(), z5.array(z5.string().nonempty())).default({}),
414
+ requests: z5.strictObject({
415
+ capacity: z5.number().int().min(1).max(1e5).default(1000),
416
+ bodies: z5.boolean().default(false)
397
417
  }).prefault({})
398
418
  });
399
- typegenSchema = z3.strictObject({
400
- types: z3.union([z3.string(), z3.array(z3.string())]).optional(),
401
- globals: z3.union([z3.string(), z3.array(z3.string())]).optional(),
402
- dir: z3.string().default("generated"),
403
- declarations: z3.boolean().default(true),
404
- ioTypes: z3.boolean().default(true)
419
+ typegenSchema = z5.strictObject({
420
+ types: z5.union([z5.string(), z5.array(z5.string())]).optional(),
421
+ globals: z5.union([z5.string(), z5.array(z5.string())]).optional(),
422
+ dir: z5.string().default("generated"),
423
+ declarations: z5.boolean().default(true),
424
+ ioTypes: z5.boolean().default(true)
405
425
  });
406
- buildTargetSchema = z3.enum(["production", "development"]);
407
- publicationSchema = z3.strictObject({
408
- production: z3.array(z3.string().nonempty()),
409
- development: z3.array(z3.string().nonempty())
426
+ buildTargetSchema = z5.enum(["production", "development"]);
427
+ publicationSchema = z5.strictObject({
428
+ production: z5.array(z5.string().nonempty()),
429
+ development: z5.array(z5.string().nonempty())
410
430
  });
411
- ioSymbolsSchema = z3.record(z3.string(), z3.string());
412
- hmiTarget = z3.string().regex(/^\w+(\.\w+|\[\d+\])+$/);
413
- hmiControlId = z3.string().nonempty();
414
- hmiControlSchema = z3.discriminatedUnion("kind", [
415
- z3.strictObject({
416
- kind: z3.literal("button"),
431
+ hmiTarget = z5.string().regex(/^\w+(\.\w+|\[\d+\])+$/);
432
+ hmiControlId = z5.string().nonempty();
433
+ hmiControlSchema = z5.discriminatedUnion("kind", [
434
+ z5.strictObject({
435
+ kind: z5.literal("button"),
417
436
  id: hmiControlId,
418
- label: z3.string().nonempty(),
437
+ label: z5.string().nonempty(),
419
438
  target: hmiTarget,
420
- tone: z3.enum(["start", "stop"]).optional(),
421
- confirm: z3.boolean().optional()
439
+ tone: z5.enum(["start", "stop"]).optional(),
440
+ confirm: z5.boolean().optional()
422
441
  }),
423
- z3.strictObject({
424
- kind: z3.literal("toggle"),
442
+ z5.strictObject({
443
+ kind: z5.literal("toggle"),
425
444
  id: hmiControlId,
426
- label: z3.string().nonempty(),
445
+ label: z5.string().nonempty(),
427
446
  target: hmiTarget
428
447
  }),
429
- z3.strictObject({
430
- kind: z3.literal("slider"),
448
+ z5.strictObject({
449
+ kind: z5.literal("slider"),
431
450
  id: hmiControlId,
432
- label: z3.string().nonempty(),
451
+ label: z5.string().nonempty(),
433
452
  target: hmiTarget,
434
- min: z3.number().int(),
435
- max: z3.number().int()
453
+ min: z5.number().int(),
454
+ max: z5.number().int()
436
455
  })
437
456
  ]);
438
- hmiSchema = z3.strictObject({
439
- title: z3.string().nonempty(),
440
- controls: z3.array(hmiControlSchema).default([]).superRefine((controls, context) => {
457
+ hmiSchema = z5.strictObject({
458
+ title: z5.string().nonempty(),
459
+ controls: z5.array(hmiControlSchema).default([]).superRefine((controls, context) => {
441
460
  const seen = new Set;
442
461
  controls.forEach((control, index) => {
443
462
  if (seen.has(control.id)) {
@@ -450,22 +469,22 @@ var init_schema = __esm(() => {
450
469
  seen.add(control.id);
451
470
  });
452
471
  }),
453
- conveyors: z3.array(z3.strictObject({
454
- label: z3.string().nonempty(),
455
- positions: z3.number().int().positive(),
456
- diverters: z3.array(z3.number().int().nonnegative()).default([])
472
+ conveyors: z5.array(z5.strictObject({
473
+ label: z5.string().nonempty(),
474
+ positions: z5.number().int().positive(),
475
+ diverters: z5.array(z5.number().int().nonnegative()).default([])
457
476
  })).default([])
458
477
  });
459
- tsplcConfigSchema = z3.strictObject({
460
- name: z3.string().default("Application"),
461
- backend: z3.literal("codesys"),
478
+ tsplcConfigSchema = z5.strictObject({
479
+ name: z5.string().default("Application"),
480
+ backend: z5.literal("codesys"),
462
481
  publish: publicationSchema.optional(),
463
- server: z3.strictObject({
464
- baseUrlEnv: z3.string().optional(),
465
- transport: z3.enum(["http", "opcua"]).default("http"),
466
- runtime: z3.strictObject({
467
- entry: z3.string(),
468
- target: z3.enum([
482
+ server: z5.strictObject({
483
+ baseUrlEnv: envName.optional(),
484
+ transport: z5.enum(["http", "opcua"]).default("http"),
485
+ runtime: z5.strictObject({
486
+ entry: z5.string(),
487
+ target: z5.enum([
469
488
  "bun-linux-x64",
470
489
  "bun-linux-arm64",
471
490
  "bun-darwin-x64",
@@ -474,46 +493,72 @@ var init_schema = __esm(() => {
474
493
  ]).optional()
475
494
  }).optional()
476
495
  }).optional(),
477
- compiler: z3.strictObject({
478
- tsconfig: z3.string().default("tsconfig.json"),
479
- programs: z3.record(z3.string(), z3.strictObject({ module: z3.string(), export: z3.string() }))
496
+ compiler: z5.strictObject({
497
+ tsconfig: z5.string().default("tsconfig.json"),
498
+ programs: z5.record(z5.string(), sourceExportSchema)
480
499
  }).optional(),
481
- tasks: z3.array(codesysTaskSchema).nonempty().optional(),
500
+ tasks: z5.array(codesysTaskSchema).nonempty().optional(),
482
501
  build: configSchema.extend({ task: configSchema.shape.task.unwrap().optional() }).optional(),
483
- codesys: z3.strictObject({
502
+ codesys: z5.strictObject({
484
503
  http: httpOptionsSchema.optional(),
485
- programNames: z3.record(z3.string(), z3.string()).optional(),
486
- deviceTree: z3.strictObject({ ethernet: ethernetSchema.optional() }).optional(),
487
- controllers: z3.strictObject({
504
+ programNames: z5.record(z5.string(), z5.string()).optional(),
505
+ deviceTree: z5.strictObject({ ethernet: ethernetSchema.optional() }).optional(),
506
+ controllers: z5.strictObject({
488
507
  production: controllerTargetSchema.optional(),
489
508
  development: controllerTargetSchema.optional()
490
509
  }).optional()
491
510
  }).optional(),
492
- eds: z3.union([z3.string(), z3.array(z3.string())]).default("eds"),
493
- devices: z3.record(z3.string(), hardwareDeviceSchema).default({}),
494
- io: z3.record(z3.string(), ioBindingSchema).default({}),
495
- dependencies: z3.record(z3.string(), dependencySchema).default({}),
511
+ eds: z5.union([z5.string(), z5.array(z5.string())]).default("eds"),
512
+ devices: z5.record(z5.string(), hardwareDeviceSchema).default({}),
513
+ io: z5.record(z5.string(), ioBindingSchema).default({}),
514
+ dependencies: z5.record(z5.string(), dependencySchema).default({}),
496
515
  typegen: typegenSchema.optional(),
497
516
  monitor: monitorSchema.optional(),
498
517
  hmi: hmiSchema.optional(),
499
518
  telemetry: telemetrySchema.optional(),
500
519
  debug: debugSchema.optional(),
501
- targets: z3.record(z3.string().nonempty(), z3.strictObject({
502
- values: z3.record(envName, z3.string()).default({}),
503
- agent: z3.strictObject({ url: z3.url() }).optional()
520
+ targets: z5.record(z5.string().nonempty(), z5.strictObject({
521
+ values: z5.record(envName, z5.string()).default({}),
522
+ agent: z5.strictObject({ url: z5.url() }).optional()
504
523
  })).default({}),
505
- secrets: z3.strictObject({
506
- service: z3.string().nonempty(),
507
- names: z3.array(envName).nonempty()
524
+ secrets: z5.strictObject({
525
+ service: z5.string().nonempty(),
526
+ names: z5.array(envName).nonempty()
508
527
  }).optional()
528
+ }).superRefine((config, context) => {
529
+ if (config.compiler && !config.tasks) {
530
+ context.addIssue({
531
+ code: "custom",
532
+ path: ["tasks"],
533
+ message: "TypeScript programs require a tasks configuration."
534
+ });
535
+ }
509
536
  });
510
537
  });
511
538
 
512
539
  // packages/config/src/build.ts
513
540
  init_build_schema();
514
- init_build_schema();
515
541
  import { dirname, resolve } from "node:path";
516
542
  import { fileURLToPath, pathToFileURL } from "node:url";
543
+
544
+ // packages/config/src/config-module.ts
545
+ import { z as z3 } from "zod";
546
+ var configModuleSchema = z3.object({
547
+ default: z3.unknown(),
548
+ config: z3.unknown()
549
+ });
550
+ var configExport = (module, path) => {
551
+ const exports = configModuleSchema.parse(module);
552
+ if (exports.default === undefined && exports.config === undefined) {
553
+ throw new Error(`${path} must export a default config`);
554
+ }
555
+ return exports.default ?? exports.config;
556
+ };
557
+
558
+ // packages/config/src/build.ts
559
+ init_project_files();
560
+ init_build_schema();
561
+ init_compiler();
517
562
  var defineBuildConfig = (config) => config;
518
563
  var resolveConfig = (input, configFile) => {
519
564
  const parsed = configSchema.parse(input);
@@ -539,13 +584,9 @@ var resolveConfig = (input, configFile) => {
539
584
  }
540
585
  };
541
586
  };
542
- var loadConfig = async (file = "tsplc.config.ts") => {
587
+ var loadConfig = async (file = configFileName) => {
543
588
  const path = resolve(file);
544
- const module = await import(pathToFileURL(path).href);
545
- if (module.default === undefined && module.config === undefined) {
546
- throw new Error(`${path} must export a default config`);
547
- }
548
- const input = module.default ?? module.config;
589
+ const input = configExport(await import(pathToFileURL(path).href), path);
549
590
  if (input && typeof input === "object" && "build" in input) {
550
591
  await Promise.resolve().then(() => init_schema());
551
592
  return resolveConfig(rawBuildConfig(tsplcConfigSchema.parse(input)), path);
@@ -565,14 +606,20 @@ export {
565
606
  directIoBindingSchema,
566
607
  dockerImage,
567
608
  engineeringBuildSchema,
609
+ envName,
568
610
  ethernetSchema,
611
+ gatewayPort,
569
612
  iecName,
570
613
  loadConfig,
614
+ opcuaPort,
571
615
  releaseConfigSchema,
572
616
  resolveConfig,
617
+ runtimePort,
618
+ scheduleRepeats,
573
619
  sha256Digest,
620
+ taskPriority,
574
621
  tcpPort
575
622
  };
576
623
 
577
- //# debugId=22BADE23B33CC99064756E2164756E21
624
+ //# debugId=D7687E5B674F844764756E2164756E21
578
625
  //# sourceMappingURL=build.js.map