@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/README.md +1 -1
- package/dist/build.js +38 -7
- package/dist/build.js.map +8 -7
- package/dist/index.js +260 -226
- package/dist/index.js.map +9 -8
- package/dist/project-files.js +18 -0
- package/dist/project-files.js.map +10 -0
- package/dist/schema.js +42 -16
- package/dist/schema.js.map +7 -6
- package/package.json +13 -2
- package/src/build-schema.ts +61 -0
- package/src/build.ts +15 -10
- package/src/compiler.ts +3 -0
- package/src/environment.ts +15 -7
- package/src/index.ts +37 -36
- package/src/loader.ts +3 -0
- package/src/project-files.ts +15 -0
- package/src/schema.ts +23 -27
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
|
|
159
|
+
import { z as z4 } from "zod";
|
|
116
160
|
|
|
117
161
|
// packages/config/src/build-schema.ts
|
|
118
|
-
import { z as
|
|
119
|
-
var commandArgumentSchema =
|
|
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 =
|
|
129
|
-
var pathSchema =
|
|
130
|
-
var tcpPort =
|
|
131
|
-
var sha256Digest =
|
|
132
|
-
var envName =
|
|
133
|
-
var wineSchema =
|
|
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:
|
|
138
|
-
nativeExit:
|
|
182
|
+
debug: z3.string().default("-all"),
|
|
183
|
+
nativeExit: z3.boolean().default(false)
|
|
139
184
|
});
|
|
140
|
-
var localCodesysSchema =
|
|
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 =
|
|
147
|
-
var taskPriority =
|
|
148
|
-
var cyclicTasksSchema =
|
|
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:
|
|
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:
|
|
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:
|
|
185
|
-
shared:
|
|
229
|
+
inverted: z3.boolean().optional(),
|
|
230
|
+
shared: z3.boolean().optional()
|
|
186
231
|
};
|
|
187
|
-
var directIoBindingSchema =
|
|
188
|
-
address:
|
|
189
|
-
type:
|
|
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 =
|
|
193
|
-
interface:
|
|
194
|
-
address:
|
|
195
|
-
subnet:
|
|
196
|
-
gateway:
|
|
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 =
|
|
199
|
-
var processImageSchema =
|
|
243
|
+
var assemblyAddress = z3.string().regex(/^%[IQ]B\d+$/);
|
|
244
|
+
var processImageSchema = z3.strictObject({
|
|
200
245
|
address: assemblyAddress,
|
|
201
|
-
size:
|
|
246
|
+
size: z3.number().int().positive()
|
|
202
247
|
});
|
|
203
|
-
var channelAddress =
|
|
204
|
-
var deviceTreeSchema =
|
|
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:
|
|
251
|
+
devices: z3.array(z3.strictObject({
|
|
207
252
|
name: iecName,
|
|
208
|
-
eds:
|
|
209
|
-
address:
|
|
210
|
-
rpiMicroseconds:
|
|
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:
|
|
258
|
+
modbus: z3.strictObject({
|
|
214
259
|
port: tcpPort,
|
|
215
|
-
registers:
|
|
260
|
+
registers: z3.array(z3.strictObject({
|
|
216
261
|
name: iecName,
|
|
217
|
-
offset:
|
|
218
|
-
value:
|
|
219
|
-
write:
|
|
220
|
-
status:
|
|
221
|
-
requests:
|
|
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:
|
|
269
|
+
comments: z3.array(z3.strictObject({
|
|
225
270
|
address: channelAddress,
|
|
226
|
-
text:
|
|
271
|
+
text: z3.string().nonempty()
|
|
227
272
|
})).default([])
|
|
228
273
|
})).nonempty(),
|
|
229
|
-
mappings:
|
|
274
|
+
mappings: z3.array(z3.strictObject({
|
|
230
275
|
address: channelAddress,
|
|
231
|
-
variable:
|
|
276
|
+
variable: z3.string().nonempty()
|
|
232
277
|
})).default([])
|
|
233
278
|
});
|
|
234
|
-
var fourPartVersion =
|
|
235
|
-
var controllerSchema =
|
|
236
|
-
type:
|
|
237
|
-
id:
|
|
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:
|
|
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 =
|
|
248
|
-
io:
|
|
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:
|
|
252
|
-
libraries:
|
|
253
|
-
title:
|
|
254
|
-
company:
|
|
255
|
-
version:
|
|
256
|
-
namespace:
|
|
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:
|
|
304
|
+
url: z3.string().optional()
|
|
260
305
|
})).optional(),
|
|
261
|
-
docker:
|
|
262
|
-
cpuSet:
|
|
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:
|
|
313
|
+
task: z3.string().nonempty().default("MainTask"),
|
|
269
314
|
tasks: cyclicTasksSchema.optional(),
|
|
270
|
-
removeObjects:
|
|
271
|
-
symbols:
|
|
272
|
-
|
|
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:
|
|
320
|
+
gateway: z3.strictObject({
|
|
275
321
|
host: pathSchema,
|
|
276
322
|
port: tcpPort.default(1217)
|
|
277
323
|
}),
|
|
278
|
-
device:
|
|
324
|
+
device: z3.strictObject({
|
|
279
325
|
host: pathSchema,
|
|
280
326
|
port: tcpPort.default(11740)
|
|
281
327
|
}),
|
|
282
|
-
credentials:
|
|
328
|
+
credentials: z3.strictObject({
|
|
283
329
|
usernameEnv: envName,
|
|
284
330
|
passwordEnv: envName
|
|
285
331
|
}).optional()
|
|
286
332
|
}).optional(),
|
|
287
|
-
timeouts:
|
|
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 =
|
|
299
|
-
timeoutMs:
|
|
300
|
-
credentials:
|
|
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 =
|
|
382
|
+
var ioBindingSchema = z4.union([
|
|
306
383
|
directIoBindingSchema,
|
|
307
|
-
|
|
308
|
-
device:
|
|
309
|
-
channel:
|
|
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 =
|
|
314
|
-
assembly:
|
|
315
|
-
size:
|
|
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 =
|
|
319
|
-
file:
|
|
320
|
-
connection:
|
|
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:
|
|
400
|
+
modbus: z4.strictObject({
|
|
324
401
|
port: tcpPort.default(502),
|
|
325
|
-
registers:
|
|
402
|
+
registers: z4.record(iecName, z4.number().int().min(0).max(65535))
|
|
326
403
|
}).optional(),
|
|
327
|
-
statusSymbols:
|
|
328
|
-
network:
|
|
329
|
-
address:
|
|
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 =
|
|
410
|
+
var dependencySchema = z4.union([
|
|
334
411
|
fourPartVersion,
|
|
335
|
-
|
|
412
|
+
z4.strictObject({
|
|
336
413
|
version: fourPartVersion,
|
|
337
|
-
company:
|
|
338
|
-
namespace:
|
|
414
|
+
company: z4.string().optional(),
|
|
415
|
+
namespace: z4.string().optional()
|
|
339
416
|
}),
|
|
340
|
-
|
|
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 =
|
|
347
|
-
endpoint:
|
|
348
|
-
namespaceUri:
|
|
349
|
-
symbols:
|
|
350
|
-
securityMode:
|
|
351
|
-
securityPolicy:
|
|
352
|
-
certificateDirectory:
|
|
353
|
-
username:
|
|
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 =
|
|
382
|
-
capacity:
|
|
383
|
-
recordBytes:
|
|
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 =
|
|
386
|
-
trace:
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
capacity:
|
|
390
|
-
operands:
|
|
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:
|
|
394
|
-
jobs:
|
|
395
|
-
watch:
|
|
396
|
-
requests:
|
|
397
|
-
capacity:
|
|
398
|
-
bodies:
|
|
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 =
|
|
402
|
-
types:
|
|
403
|
-
globals:
|
|
404
|
-
dir:
|
|
405
|
-
declarations:
|
|
406
|
-
ioTypes:
|
|
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 =
|
|
409
|
-
var publicationSchema =
|
|
410
|
-
production:
|
|
411
|
-
development:
|
|
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
|
|
414
|
-
var
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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:
|
|
420
|
-
confirm:
|
|
497
|
+
tone: z4.enum(["start", "stop"]).optional(),
|
|
498
|
+
confirm: z4.boolean().optional()
|
|
421
499
|
}),
|
|
422
|
-
|
|
423
|
-
kind:
|
|
424
|
-
label:
|
|
500
|
+
z4.strictObject({
|
|
501
|
+
kind: z4.literal("toggle"),
|
|
502
|
+
label: z4.string().nonempty(),
|
|
425
503
|
target: hmiTarget
|
|
426
504
|
}),
|
|
427
|
-
|
|
428
|
-
kind:
|
|
429
|
-
label:
|
|
505
|
+
z4.strictObject({
|
|
506
|
+
kind: z4.literal("slider"),
|
|
507
|
+
label: z4.string().nonempty(),
|
|
430
508
|
target: hmiTarget,
|
|
431
|
-
min:
|
|
432
|
-
max:
|
|
509
|
+
min: z4.number().int(),
|
|
510
|
+
max: z4.number().int()
|
|
433
511
|
})
|
|
434
512
|
]);
|
|
435
|
-
var hmiSchema =
|
|
436
|
-
title:
|
|
437
|
-
controls:
|
|
438
|
-
conveyors:
|
|
439
|
-
label:
|
|
440
|
-
positions:
|
|
441
|
-
diverters:
|
|
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 =
|
|
445
|
-
name:
|
|
446
|
-
backend:
|
|
522
|
+
var tsplcConfigSchema = z4.strictObject({
|
|
523
|
+
name: z4.string().default("Application"),
|
|
524
|
+
backend: z4.literal("codesys"),
|
|
447
525
|
publish: publicationSchema.optional(),
|
|
448
|
-
server:
|
|
449
|
-
baseUrlEnv:
|
|
450
|
-
transport:
|
|
451
|
-
runtime:
|
|
452
|
-
entry:
|
|
453
|
-
target:
|
|
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:
|
|
463
|
-
tsconfig:
|
|
464
|
-
programs:
|
|
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:
|
|
544
|
+
tasks: z4.array(codesysTaskSchema).nonempty().optional(),
|
|
467
545
|
build: configSchema.extend({ task: configSchema.shape.task.unwrap().optional() }).optional(),
|
|
468
|
-
codesys:
|
|
546
|
+
codesys: z4.strictObject({
|
|
469
547
|
http: httpOptionsSchema.optional(),
|
|
470
|
-
programNames:
|
|
471
|
-
deviceTree:
|
|
472
|
-
controllers:
|
|
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:
|
|
478
|
-
devices:
|
|
479
|
-
io:
|
|
480
|
-
dependencies:
|
|
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:
|
|
487
|
-
values:
|
|
488
|
-
agent:
|
|
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:
|
|
491
|
-
service:
|
|
492
|
-
names:
|
|
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:
|
|
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
|
-
|
|
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=
|
|
720
|
+
//# debugId=BD83B6BA4CCE4C8A64756E2164756E21
|
|
687
721
|
//# sourceMappingURL=index.js.map
|