@tsplc/config 0.2.17 → 0.2.19
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 +2 -2
- package/dist/build.js +164 -133
- package/dist/build.js.map +7 -7
- package/dist/index.js +291 -208
- package/dist/index.js.map +8 -7
- package/dist/schema.js +249 -204
- package/dist/schema.js.map +5 -5
- package/package.json +50 -51
- package/src/build-schema.ts +220 -197
- package/src/build.ts +73 -63
- package/src/compiler.ts +140 -122
- package/src/environment.ts +72 -0
- package/src/index.ts +52 -1
- package/src/loader.ts +33 -15
- package/src/schema.ts +429 -356
- package/templates/provenance.json +6 -6
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
|
|
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 =
|
|
16
|
-
var pathSchema =
|
|
17
|
-
var
|
|
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:
|
|
22
|
-
nativeExit:
|
|
140
|
+
debug: z2.string().default("-all"),
|
|
141
|
+
nativeExit: z2.boolean().default(false)
|
|
23
142
|
});
|
|
24
|
-
var localCodesysSchema =
|
|
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 =
|
|
31
|
-
var
|
|
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:
|
|
34
|
-
if (
|
|
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:
|
|
41
|
-
programs:
|
|
160
|
+
priority: taskPriority,
|
|
161
|
+
programs: z2.array(iecName).nonempty()
|
|
42
162
|
})).nonempty().superRefine((tasks, context) => {
|
|
43
|
-
const names = 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:
|
|
67
|
-
shared:
|
|
187
|
+
inverted: z2.boolean().optional(),
|
|
188
|
+
shared: z2.boolean().optional()
|
|
68
189
|
};
|
|
69
|
-
var directIoBindingSchema =
|
|
70
|
-
address:
|
|
71
|
-
type:
|
|
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 =
|
|
75
|
-
interface:
|
|
76
|
-
address:
|
|
77
|
-
subnet:
|
|
78
|
-
gateway:
|
|
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
|
|
81
|
-
|
|
82
|
-
|
|
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
|
|
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:
|
|
209
|
+
devices: z2.array(z2.strictObject({
|
|
87
210
|
name: iecName,
|
|
88
|
-
eds:
|
|
89
|
-
address:
|
|
90
|
-
rpiMicroseconds:
|
|
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:
|
|
94
|
-
port:
|
|
95
|
-
registers:
|
|
216
|
+
modbus: z2.strictObject({
|
|
217
|
+
port: tcpPort,
|
|
218
|
+
registers: z2.array(z2.strictObject({
|
|
96
219
|
name: iecName,
|
|
97
|
-
offset:
|
|
98
|
-
value:
|
|
99
|
-
write:
|
|
100
|
-
status:
|
|
101
|
-
requests:
|
|
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:
|
|
105
|
-
address:
|
|
106
|
-
text:
|
|
227
|
+
comments: z2.array(z2.strictObject({
|
|
228
|
+
address: channelAddress,
|
|
229
|
+
text: z2.string().nonempty()
|
|
107
230
|
})).default([])
|
|
108
231
|
})).nonempty(),
|
|
109
|
-
mappings:
|
|
110
|
-
address:
|
|
111
|
-
variable:
|
|
232
|
+
mappings: z2.array(z2.strictObject({
|
|
233
|
+
address: channelAddress,
|
|
234
|
+
variable: z2.string().nonempty()
|
|
112
235
|
})).default([])
|
|
113
236
|
});
|
|
114
|
-
var
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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:
|
|
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 =
|
|
127
|
-
io:
|
|
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:
|
|
131
|
-
libraries:
|
|
132
|
-
title:
|
|
133
|
-
company:
|
|
134
|
-
version:
|
|
135
|
-
namespace:
|
|
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:
|
|
138
|
-
url:
|
|
261
|
+
sha256: sha256Digest,
|
|
262
|
+
url: z2.string().optional()
|
|
139
263
|
})).optional(),
|
|
140
|
-
docker:
|
|
141
|
-
cpuSet:
|
|
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:
|
|
271
|
+
task: z2.string().nonempty().default("MainTask"),
|
|
148
272
|
tasks: cyclicTasksSchema.optional(),
|
|
149
|
-
removeObjects:
|
|
150
|
-
symbols:
|
|
151
|
-
online:
|
|
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:
|
|
277
|
+
gateway: z2.strictObject({
|
|
154
278
|
host: pathSchema,
|
|
155
|
-
port:
|
|
279
|
+
port: tcpPort.default(1217)
|
|
156
280
|
}),
|
|
157
|
-
device:
|
|
281
|
+
device: z2.strictObject({
|
|
158
282
|
host: pathSchema,
|
|
159
|
-
port:
|
|
283
|
+
port: tcpPort.default(11740)
|
|
160
284
|
}),
|
|
161
|
-
credentials:
|
|
162
|
-
usernameEnv:
|
|
163
|
-
passwordEnv:
|
|
285
|
+
credentials: z2.strictObject({
|
|
286
|
+
usernameEnv: envName,
|
|
287
|
+
passwordEnv: envName
|
|
164
288
|
}).optional()
|
|
165
289
|
}).optional(),
|
|
166
|
-
timeouts:
|
|
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:
|
|
281
|
-
bearerTokenEnv:
|
|
304
|
+
originEnv: envName,
|
|
305
|
+
bearerTokenEnv: envName
|
|
282
306
|
})).default([])
|
|
283
|
-
}).
|
|
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:
|
|
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:
|
|
304
|
-
registers: z3.record(
|
|
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
|
-
|
|
337
|
+
fourPartVersion,
|
|
314
338
|
z3.strictObject({
|
|
315
|
-
version:
|
|
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
|
|
322
|
-
name:
|
|
323
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
}).
|
|
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(
|
|
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 && {
|
|
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
|
-
|
|
522
|
+
}
|
|
523
|
+
if (!config.build) {
|
|
489
524
|
throw new Error("Configure build settings.");
|
|
490
|
-
|
|
525
|
+
}
|
|
526
|
+
if (!config.tasks) {
|
|
491
527
|
return config.build;
|
|
492
|
-
|
|
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
|
-
|
|
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=
|
|
621
|
+
//# debugId=942E279F71FB2D2164756E2164756E21
|
|
577
622
|
//# sourceMappingURL=schema.js.map
|