@tsplc/config 0.2.20 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -111,43 +111,88 @@ function validateConfig(value) {
111
111
  diagnostics
112
112
  };
113
113
  }
114
+ // packages/config/src/environment.ts
115
+ import { z as z2 } from "zod";
116
+ var secretLength = 512;
117
+ var secretValue = z2.string().nonempty("is empty").max(secretLength, `is longer than ${secretLength} characters`).regex(/^[^\r\n\0]*$/, "holds a line break or NUL");
118
+ var secretPlaceholder = (name) => `${`{{tsplc-secret:${name}:`.padEnd(secretLength - 2, "-")}}}`;
119
+ var selectedTarget = (config, { target, forAgent }) => {
120
+ const names = Object.keys(config.targets);
121
+ if (target !== undefined) {
122
+ const selected = config.targets[target];
123
+ if (!selected) {
124
+ throw new Error(`The config has no target ${target}; its targets are: ${names.join(", ") || "none"}.`);
125
+ }
126
+ return selected;
127
+ }
128
+ const targets = Object.values(config.targets);
129
+ if (targets.length <= 1) {
130
+ return targets[0];
131
+ }
132
+ if (!forAgent) {
133
+ return;
134
+ }
135
+ const withAgent = targets.filter(({ agent }) => agent);
136
+ if (withAgent.length === 1) {
137
+ return withAgent[0];
138
+ }
139
+ throw new Error(`Choose the target to deploy to with --target: ${names.join(", ")}.`);
140
+ };
141
+ var projectEnvironment = (config, options) => {
142
+ const target = selectedTarget(config, options);
143
+ return {
144
+ ...options.env,
145
+ ...target?.agent && { TSPLC_AGENT_URL: target.agent.url },
146
+ ...target?.values,
147
+ ...options.forAgent && Object.fromEntries((config.secrets?.names ?? []).map((name) => [
148
+ name,
149
+ secretPlaceholder(name)
150
+ ]))
151
+ };
152
+ };
153
+ // packages/config/src/loader.ts
154
+ import { readFile } from "node:fs/promises";
155
+ import { dirname, resolve } from "node:path";
156
+ import { createJiti } from "jiti";
157
+
114
158
  // packages/config/src/schema.ts
115
- import { z as z3 } from "zod";
159
+ import { z as z4 } from "zod";
116
160
 
117
161
  // packages/config/src/build-schema.ts
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");
162
+ import { z as z3 } from "zod";
163
+ var commandArgumentSchema = z3.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");
120
164
  var codesysTimeouts = {
121
165
  build: 20 * 60 * 1000,
122
166
  hostCommand: 15000,
123
167
  runtime: 60000,
124
168
  startup: 20 * 60 * 1000,
125
169
  stop: 1e4,
126
- terminate: 5000
170
+ terminate: 5000,
171
+ transfer: 30 * 60 * 1000
127
172
  };
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({
173
+ var positiveMilliseconds = z3.number().int().positive();
174
+ var pathSchema = z3.string().trim().nonempty();
175
+ var tcpPort = z3.number().int().min(1).max(65535);
176
+ var sha256Digest = z3.string().regex(/^[a-f0-9]{64}$/);
177
+ var envName = z3.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/);
178
+ var wineSchema = z3.strictObject({
134
179
  prefix: pathSchema,
135
180
  binary: pathSchema.default("wine"),
136
181
  pathBinary: pathSchema.default("winepath"),
137
- debug: z2.string().default("-all"),
138
- nativeExit: z2.boolean().default(false)
182
+ debug: z3.string().default("-all"),
183
+ nativeExit: z3.boolean().default(false)
139
184
  });
140
- var localCodesysSchema = z2.strictObject({
185
+ var localCodesysSchema = z3.strictObject({
141
186
  executable: commandArgumentSchema,
142
187
  profile: commandArgumentSchema,
143
188
  wine: wineSchema.optional(),
144
189
  commandProcessor: pathSchema.default("cmd.exe")
145
190
  });
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({
191
+ var iecName = z3.string().regex(/^[A-Za-z][A-Za-z0-9_]*$/);
192
+ var taskPriority = z3.number().int().min(0).max(31);
193
+ var cyclicTasksSchema = z3.array(z3.strictObject({
149
194
  name: iecName,
150
- intervalNanoseconds: z2.string().regex(nanosecondsPattern).refine((value) => {
195
+ intervalNanoseconds: z3.string().regex(nanosecondsPattern).refine((value) => {
151
196
  if (!nanosecondsPattern.test(value)) {
152
197
  return false;
153
198
  }
@@ -155,7 +200,7 @@ var cyclicTasksSchema = z2.array(z2.strictObject({
155
200
  return ns % 1000000n === 0n && ns <= 4294967295000000n;
156
201
  }, "Cyclic tasks require an exact positive TIME interval in milliseconds"),
157
202
  priority: taskPriority,
158
- programs: z2.array(iecName).nonempty()
203
+ programs: z3.array(iecName).nonempty()
159
204
  })).nonempty().superRefine((tasks, context) => {
160
205
  const names = new Set;
161
206
  const programs = new Set;
@@ -181,176 +226,208 @@ var cyclicTasksSchema = z2.array(z2.strictObject({
181
226
  });
182
227
  });
183
228
  var ioBindingOptions = {
184
- inverted: z2.boolean().optional(),
185
- shared: z2.boolean().optional()
229
+ inverted: z3.boolean().optional(),
230
+ shared: z3.boolean().optional()
186
231
  };
187
- var directIoBindingSchema = z2.strictObject({
188
- address: z2.string().regex(/^%[IQ](?:X\d+\.[0-7]|[BWD]\d+)$/),
189
- type: z2.string().optional(),
232
+ var directIoBindingSchema = z3.strictObject({
233
+ address: z3.string().regex(/^%[IQ](?:X\d+\.[0-7]|[BWD]\d+)$/),
234
+ type: z3.string().optional(),
190
235
  ...ioBindingOptions
191
236
  });
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()
237
+ var ethernetSchema = z3.strictObject({
238
+ interface: z3.string().nonempty().optional(),
239
+ address: z3.ipv4().optional(),
240
+ subnet: z3.ipv4().optional(),
241
+ gateway: z3.ipv4().optional()
197
242
  });
198
- var assemblyAddress = z2.string().regex(/^%[IQ]B\d+$/);
199
- var processImageSchema = z2.strictObject({
243
+ var assemblyAddress = z3.string().regex(/^%[IQ]B\d+$/);
244
+ var processImageSchema = z3.strictObject({
200
245
  address: assemblyAddress,
201
- size: z2.number().int().positive()
246
+ size: z3.number().int().positive()
202
247
  });
203
- var channelAddress = z2.string().regex(/^%[IQ](?:X\d+\.[0-7]|B\d+)$/);
204
- var deviceTreeSchema = z2.strictObject({
248
+ var channelAddress = z3.string().regex(/^%[IQ](?:X\d+\.[0-7]|B\d+)$/);
249
+ var deviceTreeSchema = z3.strictObject({
205
250
  ethernet: ethernetSchema.default({}),
206
- devices: z2.array(z2.strictObject({
251
+ devices: z3.array(z3.strictObject({
207
252
  name: iecName,
208
- eds: z2.string().nonempty(),
209
- address: z2.ipv4().optional(),
210
- rpiMicroseconds: z2.number().int().positive().optional(),
253
+ eds: z3.string().nonempty(),
254
+ address: z3.ipv4().optional(),
255
+ rpiMicroseconds: z3.number().int().positive().optional(),
211
256
  inputs: processImageSchema.optional(),
212
257
  outputs: processImageSchema.optional(),
213
- modbus: z2.strictObject({
258
+ modbus: z3.strictObject({
214
259
  port: tcpPort,
215
- registers: z2.array(z2.strictObject({
260
+ registers: z3.array(z3.strictObject({
216
261
  name: iecName,
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+$/)
262
+ offset: z3.number().int().nonnegative(),
263
+ value: z3.string().regex(/^%QW\d+$/),
264
+ write: z3.string().regex(/^%QX\d+\.[0-7]$/),
265
+ status: z3.string().regex(/^%IB\d+$/),
266
+ requests: z3.string().regex(/^%ID\d+$/)
222
267
  }))
223
268
  }).optional(),
224
- comments: z2.array(z2.strictObject({
269
+ comments: z3.array(z3.strictObject({
225
270
  address: channelAddress,
226
- text: z2.string().nonempty()
271
+ text: z3.string().nonempty()
227
272
  })).default([])
228
273
  })).nonempty(),
229
- mappings: z2.array(z2.strictObject({
274
+ mappings: z3.array(z3.strictObject({
230
275
  address: channelAddress,
231
- variable: z2.string().nonempty()
276
+ variable: z3.string().nonempty()
232
277
  })).default([])
233
278
  });
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}$/),
279
+ var fourPartVersion = z3.string().regex(/^\d+\.\d+\.\d+\.\d+$/);
280
+ var controllerSchema = z3.strictObject({
281
+ type: z3.number().int().positive(),
282
+ id: z3.string().regex(/^[0-9A-F]{4} [0-9A-F]{4}$/),
238
283
  version: fourPartVersion
239
284
  });
240
285
  var controllerTargetSchema = controllerSchema.pick({ version: true }).extend({
241
- target: z2.enum(["linux-sl", "virtual-linux-arm64-sl"])
286
+ target: z3.enum(["linux-sl", "virtual-linux-arm64-sl"])
242
287
  });
243
288
  var controllerDevices = {
244
289
  "linux-sl": { type: 4102, id: "0000 0005" },
245
290
  "virtual-linux-arm64-sl": { type: 4096, id: "0000 1008" }
246
291
  };
247
- var configSchema = z2.strictObject({
248
- io: z2.record(z2.string(), directIoBindingSchema).optional(),
292
+ var configSchema = z3.strictObject({
293
+ io: z3.record(z3.string(), directIoBindingSchema).optional(),
249
294
  deviceTree: deviceTreeSchema.optional(),
250
295
  controller: controllerSchema.optional(),
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(),
296
+ libraryReferences: z3.array(z3.string().nonempty()).default([]),
297
+ libraries: z3.array(z3.strictObject({
298
+ title: z3.string(),
299
+ company: z3.string().optional(),
300
+ version: z3.string().optional(),
301
+ namespace: z3.string().optional(),
257
302
  path: pathSchema,
258
303
  sha256: sha256Digest,
259
- url: z2.string().optional()
304
+ url: z3.string().optional()
260
305
  })).optional(),
261
- docker: z2.strictObject({
262
- cpuSet: z2.string().regex(/^\d+(?:-\d+)?(?:,\d+(?:-\d+)?)*$/).optional()
306
+ docker: z3.strictObject({
307
+ cpuSet: z3.string().regex(/^\d+(?:-\d+)?(?:,\d+(?:-\d+)?)*$/).optional()
263
308
  }).optional(),
264
309
  template: pathSchema.optional(),
265
310
  sourceDir: pathSchema.default("src"),
266
311
  entry: pathSchema.default("src/Main.st"),
267
312
  outDir: pathSchema.default("build"),
268
- task: z2.string().nonempty().default("MainTask"),
313
+ task: z3.string().nonempty().default("MainTask"),
269
314
  tasks: cyclicTasksSchema.optional(),
270
- removeObjects: z2.array(z2.string().nonempty()).default([]),
271
- symbols: z2.boolean().default(false),
272
- online: z2.strictObject({
315
+ removeObjects: z3.array(z3.string().nonempty()).default([]),
316
+ symbols: z3.boolean().default(false),
317
+ bulkImport: z3.boolean().optional(),
318
+ online: z3.strictObject({
273
319
  network: pathSchema.default("bridge"),
274
- gateway: z2.strictObject({
320
+ gateway: z3.strictObject({
275
321
  host: pathSchema,
276
322
  port: tcpPort.default(1217)
277
323
  }),
278
- device: z2.strictObject({
324
+ device: z3.strictObject({
279
325
  host: pathSchema,
280
326
  port: tcpPort.default(11740)
281
327
  }),
282
- credentials: z2.strictObject({
328
+ credentials: z3.strictObject({
283
329
  usernameEnv: envName,
284
330
  passwordEnv: envName
285
331
  }).optional()
286
332
  }).optional(),
287
- timeouts: z2.strictObject({
333
+ timeouts: z3.strictObject({
288
334
  startup: positiveMilliseconds.default(codesysTimeouts.startup),
289
335
  build: positiveMilliseconds.default(codesysTimeouts.build),
290
336
  stop: positiveMilliseconds.default(codesysTimeouts.stop),
291
337
  terminate: positiveMilliseconds.default(codesysTimeouts.terminate),
292
338
  hostCommand: positiveMilliseconds.default(codesysTimeouts.hostCommand),
293
- runtime: positiveMilliseconds.default(codesysTimeouts.runtime)
339
+ runtime: positiveMilliseconds.default(codesysTimeouts.runtime),
340
+ prepare: positiveMilliseconds.optional(),
341
+ transfer: positiveMilliseconds.optional()
294
342
  }).prefault({})
295
343
  });
344
+ var releaseConfigSchema = configSchema.omit({
345
+ docker: true,
346
+ outDir: true,
347
+ online: true,
348
+ bulkImport: true
349
+ });
350
+ var engineeringBuildSchema = configSchema.omit({
351
+ sourceDir: true,
352
+ entry: true,
353
+ outDir: true,
354
+ task: true,
355
+ tasks: true
356
+ });
357
+ function engineeringBuildOptions(build) {
358
+ const {
359
+ sourceDir: _source,
360
+ entry: _entry,
361
+ outDir: _out,
362
+ task: _task,
363
+ tasks: _tasks,
364
+ ...settings
365
+ } = build;
366
+ return settings;
367
+ }
368
+
369
+ // packages/config/src/project-files.ts
370
+ var generatedDirectory = ".tsplc";
371
+ var emittedStDirectory = `${generatedDirectory}/artifacts/st`;
372
+ var projectSnapshotFile = `${generatedDirectory}/project.json`;
296
373
 
297
374
  // packages/config/src/schema.ts
298
- var httpOptionsSchema = z3.strictObject({
299
- timeoutMs: z3.number().int().positive().max(60000).default(2000),
300
- credentials: z3.array(z3.strictObject({
375
+ var httpOptionsSchema = z4.strictObject({
376
+ timeoutMs: z4.number().int().positive().max(60000).default(2000),
377
+ credentials: z4.array(z4.strictObject({
301
378
  originEnv: envName,
302
379
  bearerTokenEnv: envName
303
380
  })).default([])
304
381
  }).prefault({});
305
- var ioBindingSchema = z3.union([
382
+ var ioBindingSchema = z4.union([
306
383
  directIoBindingSchema,
307
- z3.strictObject({
308
- device: z3.string().min(1),
309
- channel: z3.string().min(1),
384
+ z4.strictObject({
385
+ device: z4.string().min(1),
386
+ channel: z4.string().min(1),
310
387
  ...ioBindingOptions
311
388
  })
312
389
  ]);
313
- var assemblySchema = z3.strictObject({
314
- assembly: z3.number().int().nonnegative().optional(),
315
- size: z3.number().int().positive().optional(),
390
+ var assemblySchema = z4.strictObject({
391
+ assembly: z4.number().int().nonnegative().optional(),
392
+ size: z4.number().int().positive().optional(),
316
393
  address: assemblyAddress.optional()
317
394
  });
318
- var hardwareDeviceSchema = z3.strictObject({
319
- file: z3.string().min(1),
320
- connection: z3.string().min(1).optional(),
395
+ var hardwareDeviceSchema = z4.strictObject({
396
+ file: z4.string().min(1),
397
+ connection: z4.string().min(1).optional(),
321
398
  inputs: assemblySchema.optional(),
322
399
  outputs: assemblySchema.optional(),
323
- modbus: z3.strictObject({
400
+ modbus: z4.strictObject({
324
401
  port: tcpPort.default(502),
325
- registers: z3.record(iecName, z3.number().int().min(0).max(65535))
402
+ registers: z4.record(iecName, z4.number().int().min(0).max(65535))
326
403
  }).optional(),
327
- statusSymbols: z3.record(z3.string(), z3.string()).optional(),
328
- network: z3.strictObject({
329
- address: z3.ipv4().optional(),
404
+ statusSymbols: z4.record(z4.string(), z4.string()).optional(),
405
+ network: z4.strictObject({
406
+ address: z4.ipv4().optional(),
330
407
  rpi: durationSchema.refine((rpi) => BigInt(rpi.nanoseconds) % 1000n === 0n, "An RPI must be a whole number of microseconds.").optional()
331
408
  }).optional()
332
409
  });
333
- var dependencySchema = z3.union([
410
+ var dependencySchema = z4.union([
334
411
  fourPartVersion,
335
- z3.strictObject({
412
+ z4.strictObject({
336
413
  version: fourPartVersion,
337
- company: z3.string().optional(),
338
- namespace: z3.string().optional()
414
+ company: z4.string().optional(),
415
+ namespace: z4.string().optional()
339
416
  }),
340
- z3.strictObject({ path: z3.string().min(1), namespace: z3.string().optional() })
417
+ z4.strictObject({ path: z4.string().min(1), namespace: z4.string().optional() })
341
418
  ]);
342
419
  var codesysTaskSchema = taskSchema.extend({
343
420
  name: iecName,
344
421
  priority: taskPriority
345
422
  });
346
- var monitorSchema = z3.strictObject({
347
- endpoint: z3.string().url(),
348
- namespaceUri: z3.string().optional(),
349
- symbols: z3.array(z3.string().min(1)).optional(),
350
- securityMode: z3.enum(["None", "Sign", "SignAndEncrypt"]).default("SignAndEncrypt"),
351
- securityPolicy: z3.enum(["None", "Basic256Sha256"]).optional(),
352
- certificateDirectory: z3.string().min(1).default(".tsplc/opcua-pki"),
353
- username: z3.string().min(1).optional(),
423
+ var monitorSchema = z4.strictObject({
424
+ endpoint: z4.string().url(),
425
+ namespaceUri: z4.string().optional(),
426
+ symbols: z4.array(z4.string().min(1)).optional(),
427
+ securityMode: z4.enum(["None", "Sign", "SignAndEncrypt"]).default("SignAndEncrypt"),
428
+ securityPolicy: z4.enum(["None", "Basic256Sha256"]).optional(),
429
+ certificateDirectory: z4.string().min(1).default(`${generatedDirectory}/opcua-pki`),
430
+ username: z4.string().min(1).optional(),
354
431
  passwordEnv: envName.optional()
355
432
  }).superRefine((monitor, context) => {
356
433
  if (monitor.securityPolicy && monitor.securityMode === "None" !== (monitor.securityPolicy === "None")) {
@@ -378,79 +455,80 @@ var monitorSchema = z3.strictObject({
378
455
  ...monitor,
379
456
  securityPolicy: monitor.securityPolicy ?? (monitor.securityMode === "None" ? "None" : "Basic256Sha256")
380
457
  }));
381
- var telemetrySchema = z3.strictObject({
382
- capacity: z3.number().int().min(4).max(4096).default(64),
383
- recordBytes: z3.number().int().min(128).max(1024).default(512)
458
+ var telemetrySchema = z4.strictObject({
459
+ capacity: z4.number().int().min(4).max(4096).default(64),
460
+ recordBytes: z4.number().int().min(128).max(1024).default(512)
384
461
  });
385
- var debugSchema = z3.strictObject({
386
- trace: z3.union([
387
- z3.literal(false),
388
- z3.strictObject({
389
- capacity: z3.number().int().min(16).max(4096).default(256),
390
- operands: z3.number().int().min(0).max(8).default(4)
462
+ var debugSchema = z4.strictObject({
463
+ trace: z4.union([
464
+ z4.literal(false),
465
+ z4.strictObject({
466
+ capacity: z4.number().int().min(16).max(4096).default(256),
467
+ operands: z4.number().int().min(0).max(8).default(4)
391
468
  })
392
469
  ]).default(false),
393
- writers: z3.boolean().default(true),
394
- jobs: z3.boolean().default(true),
395
- watch: z3.record(z3.string(), z3.array(z3.string().min(1))).default({}),
396
- requests: z3.strictObject({
397
- capacity: z3.number().int().min(1).max(1e5).default(1000),
398
- bodies: z3.boolean().default(false)
470
+ writers: z4.boolean().default(true),
471
+ jobs: z4.boolean().default(true),
472
+ watch: z4.record(z4.string(), z4.array(z4.string().min(1))).default({}),
473
+ requests: z4.strictObject({
474
+ capacity: z4.number().int().min(1).max(1e5).default(1000),
475
+ bodies: z4.boolean().default(false)
399
476
  }).prefault({})
400
477
  });
401
- var typegenSchema = z3.strictObject({
402
- types: z3.union([z3.string(), z3.array(z3.string())]).optional(),
403
- globals: z3.union([z3.string(), z3.array(z3.string())]).optional(),
404
- dir: z3.string().default("generated"),
405
- declarations: z3.boolean().default(true),
406
- ioTypes: z3.boolean().default(true)
478
+ var typegenSchema = z4.strictObject({
479
+ types: z4.union([z4.string(), z4.array(z4.string())]).optional(),
480
+ globals: z4.union([z4.string(), z4.array(z4.string())]).optional(),
481
+ dir: z4.string().default("generated"),
482
+ declarations: z4.boolean().default(true),
483
+ ioTypes: z4.boolean().default(true)
407
484
  });
408
- var buildTargetSchema = z3.enum(["production", "development"]);
409
- var publicationSchema = z3.strictObject({
410
- production: z3.array(z3.string().nonempty()),
411
- development: z3.array(z3.string().nonempty())
485
+ var buildTargetSchema = z4.enum(["production", "development"]);
486
+ var publicationSchema = z4.strictObject({
487
+ production: z4.array(z4.string().nonempty()),
488
+ development: z4.array(z4.string().nonempty())
412
489
  });
413
- var hmiTarget = z3.string().regex(/^\w+(\.\w+|\[\d+\])+$/);
414
- var hmiControlSchema = z3.discriminatedUnion("kind", [
415
- z3.strictObject({
416
- kind: z3.literal("button"),
417
- label: z3.string().nonempty(),
490
+ var ioSymbolsSchema = z4.record(z4.string(), z4.string());
491
+ var hmiTarget = z4.string().regex(/^\w+(\.\w+|\[\d+\])+$/);
492
+ var hmiControlSchema = z4.discriminatedUnion("kind", [
493
+ z4.strictObject({
494
+ kind: z4.literal("button"),
495
+ label: z4.string().nonempty(),
418
496
  target: hmiTarget,
419
- tone: z3.enum(["start", "stop"]).optional(),
420
- confirm: z3.boolean().optional()
497
+ tone: z4.enum(["start", "stop"]).optional(),
498
+ confirm: z4.boolean().optional()
421
499
  }),
422
- z3.strictObject({
423
- kind: z3.literal("toggle"),
424
- label: z3.string().nonempty(),
500
+ z4.strictObject({
501
+ kind: z4.literal("toggle"),
502
+ label: z4.string().nonempty(),
425
503
  target: hmiTarget
426
504
  }),
427
- z3.strictObject({
428
- kind: z3.literal("slider"),
429
- label: z3.string().nonempty(),
505
+ z4.strictObject({
506
+ kind: z4.literal("slider"),
507
+ label: z4.string().nonempty(),
430
508
  target: hmiTarget,
431
- min: z3.number().int(),
432
- max: z3.number().int()
509
+ min: z4.number().int(),
510
+ max: z4.number().int()
433
511
  })
434
512
  ]);
435
- var hmiSchema = z3.strictObject({
436
- title: z3.string().nonempty(),
437
- controls: z3.array(hmiControlSchema).default([]),
438
- conveyors: z3.array(z3.strictObject({
439
- label: z3.string().nonempty(),
440
- positions: z3.number().int().positive(),
441
- diverters: z3.array(z3.number().int().nonnegative()).default([])
513
+ var hmiSchema = z4.strictObject({
514
+ title: z4.string().nonempty(),
515
+ controls: z4.array(hmiControlSchema).default([]),
516
+ conveyors: z4.array(z4.strictObject({
517
+ label: z4.string().nonempty(),
518
+ positions: z4.number().int().positive(),
519
+ diverters: z4.array(z4.number().int().nonnegative()).default([])
442
520
  })).default([])
443
521
  });
444
- var tsplcConfigSchema = z3.strictObject({
445
- name: z3.string().default("Application"),
446
- backend: z3.literal("codesys"),
522
+ var tsplcConfigSchema = z4.strictObject({
523
+ name: z4.string().default("Application"),
524
+ backend: z4.literal("codesys"),
447
525
  publish: publicationSchema.optional(),
448
- server: z3.strictObject({
449
- baseUrlEnv: z3.string().optional(),
450
- transport: z3.enum(["http", "opcua"]).default("http"),
451
- runtime: z3.strictObject({
452
- entry: z3.string(),
453
- target: z3.enum([
526
+ server: z4.strictObject({
527
+ baseUrlEnv: z4.string().optional(),
528
+ transport: z4.enum(["http", "opcua"]).default("http"),
529
+ runtime: z4.strictObject({
530
+ entry: z4.string(),
531
+ target: z4.enum([
454
532
  "bun-linux-x64",
455
533
  "bun-linux-arm64",
456
534
  "bun-darwin-x64",
@@ -459,37 +537,37 @@ var tsplcConfigSchema = z3.strictObject({
459
537
  ]).optional()
460
538
  }).optional()
461
539
  }).optional(),
462
- compiler: z3.strictObject({
463
- tsconfig: z3.string().default("tsconfig.json"),
464
- programs: z3.record(z3.string(), z3.strictObject({ module: z3.string(), export: z3.string() }))
540
+ compiler: z4.strictObject({
541
+ tsconfig: z4.string().default("tsconfig.json"),
542
+ programs: z4.record(z4.string(), z4.strictObject({ module: z4.string(), export: z4.string() }))
465
543
  }).optional(),
466
- tasks: z3.array(codesysTaskSchema).nonempty().optional(),
544
+ tasks: z4.array(codesysTaskSchema).nonempty().optional(),
467
545
  build: configSchema.extend({ task: configSchema.shape.task.unwrap().optional() }).optional(),
468
- codesys: z3.strictObject({
546
+ codesys: z4.strictObject({
469
547
  http: httpOptionsSchema.optional(),
470
- programNames: z3.record(z3.string(), z3.string()).optional(),
471
- deviceTree: z3.strictObject({ ethernet: ethernetSchema.optional() }).optional(),
472
- controllers: z3.strictObject({
548
+ programNames: z4.record(z4.string(), z4.string()).optional(),
549
+ deviceTree: z4.strictObject({ ethernet: ethernetSchema.optional() }).optional(),
550
+ controllers: z4.strictObject({
473
551
  production: controllerTargetSchema.optional(),
474
552
  development: controllerTargetSchema.optional()
475
553
  }).optional()
476
554
  }).optional(),
477
- eds: z3.union([z3.string(), z3.array(z3.string())]).default("eds"),
478
- devices: z3.record(z3.string(), hardwareDeviceSchema).default({}),
479
- io: z3.record(z3.string(), ioBindingSchema).default({}),
480
- dependencies: z3.record(z3.string(), dependencySchema).default({}),
555
+ eds: z4.union([z4.string(), z4.array(z4.string())]).default("eds"),
556
+ devices: z4.record(z4.string(), hardwareDeviceSchema).default({}),
557
+ io: z4.record(z4.string(), ioBindingSchema).default({}),
558
+ dependencies: z4.record(z4.string(), dependencySchema).default({}),
481
559
  typegen: typegenSchema.optional(),
482
560
  monitor: monitorSchema.optional(),
483
561
  hmi: hmiSchema.optional(),
484
562
  telemetry: telemetrySchema.optional(),
485
563
  debug: debugSchema.optional(),
486
- targets: z3.record(z3.string().nonempty(), z3.strictObject({
487
- values: z3.record(envName, z3.string()).default({}),
488
- agent: z3.strictObject({ url: z3.url() }).optional()
564
+ targets: z4.record(z4.string().nonempty(), z4.strictObject({
565
+ values: z4.record(envName, z4.string()).default({}),
566
+ agent: z4.strictObject({ url: z4.url() }).optional()
489
567
  })).default({}),
490
- secrets: z3.strictObject({
491
- service: z3.string().nonempty(),
492
- names: z3.array(envName).nonempty()
568
+ secrets: z4.strictObject({
569
+ service: z4.string().nonempty(),
570
+ names: z4.array(envName).nonempty()
493
571
  }).optional()
494
572
  });
495
573
  var buildTargetFor = (command) => ["run", "download", "online-change", "inspect"].includes(command) ? "development" : "production";
@@ -569,7 +647,7 @@ function compilerConfig(config, io, buildTarget = "production") {
569
647
  ])),
570
648
  engineering: {
571
649
  kind: "v3.5",
572
- ...config.build ? { build: compilerBuildOptions(config.build) } : {}
650
+ ...config.build ? { build: engineeringBuildOptions(config.build) } : {}
573
651
  }
574
652
  }
575
653
  }
@@ -585,53 +663,8 @@ function mappedChannel(config, name, binding) {
585
663
  const source = config.io[name];
586
664
  return config.codesys?.deviceTree !== undefined && source !== undefined && "device" in source && !binding.inverted && !binding.shared && /^%[IQ][XB]/.test(binding.address) && !/^ARRAY/i.test(binding.type ?? "");
587
665
  }
588
- function compilerBuildOptions(build) {
589
- const {
590
- sourceDir: _source,
591
- entry: _entry,
592
- outDir: _out,
593
- task: _task,
594
- tasks: _tasks,
595
- ...settings
596
- } = build;
597
- return settings;
598
- }
599
- // packages/config/src/environment.ts
600
- import { z as z4 } from "zod";
601
- var secretLength = 512;
602
- var secretValue = z4.string().nonempty("is empty").max(secretLength, `is longer than ${secretLength} characters`).regex(/^[^\r\n\0]*$/, "holds a line break or NUL");
603
- var secretPlaceholder = (name) => `{{tsplc-secret:${name}:`.padEnd(secretLength - 2, "-") + "}}";
604
- var selectedTarget = (config, { target, forAgent }) => {
605
- const names = Object.keys(config.targets);
606
- if (target !== undefined) {
607
- const selected = config.targets[target];
608
- if (!selected) {
609
- throw new Error(`The config has no target ${target}; its targets are: ${names.join(", ") || "none"}.`);
610
- }
611
- return selected;
612
- }
613
- if (forAgent && names.length > 1) {
614
- throw new Error(`Choose the target to deploy to with --target: ${names.join(", ")}.`);
615
- }
616
- const [only, ...others] = Object.values(config.targets);
617
- return others.length ? undefined : only;
618
- };
619
- var projectEnvironment = (config, options) => {
620
- const target = selectedTarget(config, options);
621
- return {
622
- ...options.env,
623
- ...target?.agent && { TSPLC_AGENT_URL: target.agent.url },
624
- ...target?.values,
625
- ...options.forAgent && Object.fromEntries((config.secrets?.names ?? []).map((name) => [
626
- name,
627
- secretPlaceholder(name)
628
- ]))
629
- };
630
- };
666
+
631
667
  // packages/config/src/loader.ts
632
- import { readFile } from "node:fs/promises";
633
- import { dirname, resolve } from "node:path";
634
- import { createJiti } from "jiti";
635
668
  async function loadTsplcConfig(file = "tsplc.config.ts", environment = {
636
669
  env: process.env,
637
670
  target: undefined,
@@ -666,6 +699,7 @@ export {
666
699
  definePlcConfig,
667
700
  hmiSchema,
668
701
  httpOptionsSchema,
702
+ ioSymbolsSchema,
669
703
  loadTsplcConfig,
670
704
  ms,
671
705
  ns,
@@ -683,5 +717,5 @@ export {
683
717
  validateConfig
684
718
  };
685
719
 
686
- //# debugId=3E51E46FCC52897964756E2164756E21
720
+ //# debugId=BD83B6BA4CCE4C8A64756E2164756E21
687
721
  //# sourceMappingURL=index.js.map