refactor(scada): use canonical device identifiers
This commit is contained in:
@@ -2,7 +2,7 @@ import { z } from "zod";
|
||||
import type { FrontendActionManifest } from "./types.js";
|
||||
|
||||
type Definition = { manifest: FrontendActionManifest; inputSchema: z.ZodTypeAny; outputSchema: z.ZodTypeAny };
|
||||
const sensorId = z.string().trim().min(1).max(128);
|
||||
const deviceId = z.string().trim().min(1).max(128);
|
||||
const scadaLevel = z.enum(["high", "medium", "low", "unrated"]);
|
||||
const levelCounts = z.object({
|
||||
high: z.number().int().nonnegative(),
|
||||
@@ -11,18 +11,18 @@ const levelCounts = z.object({
|
||||
unrated: z.number().int().nonnegative(),
|
||||
}).strict();
|
||||
const renderScadaAnalysisInput = z.object({
|
||||
items: z.array(z.object({ sensor_id: sensorId, level: scadaLevel }).strict()).min(1).max(100),
|
||||
items: z.array(z.object({ device_id: deviceId, level: scadaLevel }).strict()).min(1).max(100),
|
||||
}).strict().superRefine((value, context) => {
|
||||
const seen = new Set<string>();
|
||||
value.items.forEach((item, index) => {
|
||||
if (seen.has(item.sensor_id)) {
|
||||
if (seen.has(item.device_id)) {
|
||||
context.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "sensor_id values must be unique",
|
||||
path: ["items", index, "sensor_id"],
|
||||
message: "device_id values must be unique",
|
||||
path: ["items", index, "device_id"],
|
||||
});
|
||||
}
|
||||
seen.add(item.sensor_id);
|
||||
seen.add(item.device_id);
|
||||
});
|
||||
});
|
||||
const definitions: Definition[] = [
|
||||
@@ -36,8 +36,8 @@ const definitions: Definition[] = [
|
||||
},
|
||||
inputSchema: renderScadaAnalysisInput,
|
||||
outputSchema: z.object({
|
||||
rendered_ids: z.array(sensorId),
|
||||
missing_ids: z.array(sensorId),
|
||||
rendered_ids: z.array(deviceId),
|
||||
missing_ids: z.array(deviceId),
|
||||
level_counts: levelCounts,
|
||||
fitted: z.literal(true),
|
||||
}).strict(),
|
||||
|
||||
Reference in New Issue
Block a user