@tsplc/config 0.2.17 → 0.2.18

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