refactor: 按职责拆分工作流共享模型
This commit is contained in:
1 parent
22bd7a9995
commit
8a34ea8c85
14 files changed
+782
-751
No files matched your search
@@ -0,0 +1,176 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { WorkflowTaskSchema } from "./nodes.js";
|
||||
|
||||
// ── 工作流(EASO Pipeline)───────────────────────────────────
|
||||
|
||||
export const WorkflowSchema = z.object({
|
||||
id: z.string(),
|
||||
pipelineName: z.string().default(""),
|
||||
state: z.number().default(0),
|
||||
runningCount: z.number().default(0),
|
||||
errorCount: z.number().default(0),
|
||||
updateTime: z.string().default(""),
|
||||
updateUser: z.string().nullable().optional(),
|
||||
tasks: z.array(WorkflowTaskSchema).default([]),
|
||||
desc: z.string().nullable().optional(),
|
||||
customDesc: z.string().nullable().optional(),
|
||||
});
|
||||
|
||||
export const WorkflowPageSchema = z.object({
|
||||
pipelineNum: z.number().default(0),
|
||||
runningNum: z.number().default(0),
|
||||
allRunCount: z.number().default(0),
|
||||
errorCount: z.number().default(0),
|
||||
number: z.number().default(1),
|
||||
size: z.number().default(20),
|
||||
totalPages: z.number().default(0),
|
||||
totalItems: z.number().default(0),
|
||||
pipelineList: z.array(WorkflowSchema).default([]),
|
||||
});
|
||||
|
||||
export const WorkflowStatsSchema = z.object({
|
||||
total: z.number().default(0),
|
||||
completed: z.number().default(0),
|
||||
failed: z.number().default(0),
|
||||
started: z.number().default(0),
|
||||
pipelineOpenCount: z.number().default(0),
|
||||
pipelineCloseCount: z.number().default(0),
|
||||
pipelineAllCount: z.number().default(0),
|
||||
});
|
||||
|
||||
export const WorkflowAlarmSchema = z.object({
|
||||
alarmUser: z.array(z.any()).default([]),
|
||||
alarmType: z.array(z.string()).default([]),
|
||||
active: z.boolean().default(true),
|
||||
alarmScope: z.string().default(""),
|
||||
});
|
||||
|
||||
export const WorkflowDetailSchema = z.object({
|
||||
id: z.string(),
|
||||
label: z.string().default(""),
|
||||
desc: z.string().nullable().optional(),
|
||||
customDesc: z.string().nullable().optional(),
|
||||
state: z.coerce.number().default(0),
|
||||
debugState: z.coerce.number().default(0),
|
||||
runTimes: z.coerce.number().default(0),
|
||||
errorTimes: z.coerce.number().default(0),
|
||||
updateTime: z.string().default(""),
|
||||
updateUser: z.string().nullable().optional(),
|
||||
staffName: z.string().nullable().optional(),
|
||||
version: z.string().default(""),
|
||||
dataLimit: z.coerce.number().default(20),
|
||||
source: z.coerce.number().default(0),
|
||||
queueJobs: z.boolean().default(false),
|
||||
tasksVersion: z.coerce.number().default(0),
|
||||
tasks: z.array(WorkflowTaskSchema).default([]),
|
||||
alarm: z.union([
|
||||
WorkflowAlarmSchema,
|
||||
z.string().transform((val) => {
|
||||
try {
|
||||
const parsed = JSON.parse(val);
|
||||
return WorkflowAlarmSchema.safeParse(parsed).data ?? undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}),
|
||||
z.null(),
|
||||
]).optional(),
|
||||
inputs: z.array(z.object({ key: z.string(), value: z.any() })).optional(),
|
||||
"$snapshot": z.array(z.object({ key: z.string(), value: z.string() })).optional(),
|
||||
}).passthrough();
|
||||
|
||||
export const WorkflowSnapshotSchema = z.object({
|
||||
id: z.string(),
|
||||
pipelineId: z.string(),
|
||||
corporationId: z.string().default(""),
|
||||
platformId: z.string().default(""),
|
||||
triggerKey: z.string().default(""),
|
||||
label: z.string().default(""),
|
||||
tasks: z.array(WorkflowTaskSchema).nullable().optional(),
|
||||
inputs: z.union([z.string(), z.array(z.any())]).default("[]"),
|
||||
outputs: z.union([z.string(), z.array(z.any())]).default("[]"),
|
||||
retry: z.number().default(0),
|
||||
state: z.number().default(0),
|
||||
debugState: z.number().default(0),
|
||||
staffId: z.string().nullable().optional(),
|
||||
staffName: z.string().nullable().optional(),
|
||||
createTime: z.string().default(""),
|
||||
updateTime: z.string().default(""),
|
||||
version: z.string().default(""),
|
||||
}).passthrough();
|
||||
|
||||
export const WorkflowSnapshotPageSchema = z.object({
|
||||
number: z.number().default(1),
|
||||
size: z.number().default(10),
|
||||
totalPages: z.number().default(0),
|
||||
totalItems: z.number().default(0),
|
||||
items: z.array(WorkflowSnapshotSchema).default([]),
|
||||
});
|
||||
|
||||
export const WorkflowLogItemSchema = z.record(z.string(), z.any());
|
||||
|
||||
export const WorkflowLogPageSchema = z.object({
|
||||
number: z.number().default(1),
|
||||
size: z.number().default(10),
|
||||
totalPages: z.number().default(0),
|
||||
totalItems: z.number().default(0),
|
||||
items: z.array(WorkflowLogItemSchema).default([]),
|
||||
executeCount: z.number().default(0),
|
||||
successCount: z.number().default(0),
|
||||
errorCount: z.number().default(0),
|
||||
jobList: z.array(WorkflowLogItemSchema).default([]),
|
||||
}).passthrough();
|
||||
|
||||
export const WorkflowChargeSchema = z.object({
|
||||
corporationId: z.string().default(""),
|
||||
status: z.string().default(""),
|
||||
orderType: z.string().default(""),
|
||||
total: z.number().default(0),
|
||||
used: z.number().default(0),
|
||||
remaining: z.number().default(0),
|
||||
});
|
||||
|
||||
// ── 工作流状态 ────────────────────────────────────────────────────────────────
|
||||
|
||||
export const WorkflowStateSchema = z.union([z.literal(0), z.literal(1)]);
|
||||
|
||||
// ── 跨应用聚合结果类型 ───────────────────────────────────────────────────────
|
||||
|
||||
export const WorkflowSummarySchema = WorkflowSchema.extend({
|
||||
platformId: z.string(),
|
||||
platformName: z.string(),
|
||||
});
|
||||
|
||||
export const WorkflowListAllErrorSchema = z.object({
|
||||
platformId: z.string(),
|
||||
platformName: z.string(),
|
||||
error: z.string(),
|
||||
});
|
||||
|
||||
export const TaskMatchSchema = z.object({
|
||||
taskName: z.string(),
|
||||
taskType: z.string(),
|
||||
levelIndex: z.array(z.number()),
|
||||
});
|
||||
|
||||
export const WorkflowWithMatchesSchema = WorkflowSummarySchema.extend({
|
||||
matchedTasks: z.array(TaskMatchSchema),
|
||||
});
|
||||
|
||||
|
||||
export type WorkflowState = z.infer<typeof WorkflowStateSchema>;
|
||||
export type Workflow = z.infer<typeof WorkflowSchema>;
|
||||
export type WorkflowPage = z.infer<typeof WorkflowPageSchema>;
|
||||
export type WorkflowStats = z.infer<typeof WorkflowStatsSchema>;
|
||||
export type WorkflowAlarm = z.infer<typeof WorkflowAlarmSchema>;
|
||||
export type WorkflowDetail = z.infer<typeof WorkflowDetailSchema>;
|
||||
export type WorkflowSnapshot = z.infer<typeof WorkflowSnapshotSchema>;
|
||||
export type WorkflowSnapshotPage = z.infer<typeof WorkflowSnapshotPageSchema>;
|
||||
export type WorkflowLogItem = z.infer<typeof WorkflowLogItemSchema>;
|
||||
export type WorkflowLogPage = z.infer<typeof WorkflowLogPageSchema>;
|
||||
export type WorkflowCharge = z.infer<typeof WorkflowChargeSchema>;
|
||||
export type WorkflowSummary = z.infer<typeof WorkflowSummarySchema>;
|
||||
export type WorkflowListAllError = z.infer<typeof WorkflowListAllErrorSchema>;
|
||||
export type TaskMatch = z.infer<typeof TaskMatchSchema>;
|
||||
export type WorkflowWithMatches = z.infer<typeof WorkflowWithMatchesSchema>;
|
||||
Reference in new issue
Block a user