-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathtask.ts
More file actions
68 lines (60 loc) · 1.89 KB
/
task.ts
File metadata and controls
68 lines (60 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { z } from "zod";
import type { DataType, Network } from "../index.js";
import { DisplayInformation } from "./display_information.js";
import { TrainingInformation } from "./training_information.js";
export namespace Task {
export type ID = string;
export const baseSchema = z.object({
id: z.string(),
displayInformation: DisplayInformation.baseSchema,
trainingInformation: TrainingInformation.baseSchema,
});
export const dataTypeToSchema = {
image: z.object({
dataType: z.literal("image"),
displayInformation: DisplayInformation.dataTypeToSchema.image,
trainingInformation: TrainingInformation.dataTypeToSchema.image,
}),
tabular: z.object({
dataType: z.literal("tabular"),
displayInformation: DisplayInformation.dataTypeToSchema.tabular,
trainingInformation: TrainingInformation.dataTypeToSchema.tabular,
}),
text: z.object({
dataType: z.literal("text"),
displayInformation: DisplayInformation.dataTypeToSchema.text,
trainingInformation: TrainingInformation.dataTypeToSchema.text,
}),
} satisfies Record<DataType, unknown>;
export const networkToSchema = {
decentralized: z.object({
trainingInformation: TrainingInformation.networkToSchema.decentralized,
}),
federated: z.object({
trainingInformation: TrainingInformation.networkToSchema.federated,
}),
local: z.object({
trainingInformation: TrainingInformation.networkToSchema.local,
}),
} satisfies Record<Network, unknown>;
export const schema = baseSchema
.and(
z.union([
dataTypeToSchema.image,
dataTypeToSchema.tabular,
dataTypeToSchema.text,
]),
)
.and(
z.union([
networkToSchema.decentralized,
networkToSchema.federated,
networkToSchema.local,
]),
);
}
export type Task<D extends DataType, N extends Network> = z.infer<
typeof Task.baseSchema
> &
z.infer<(typeof Task.dataTypeToSchema)[D]> &
z.infer<(typeof Task.networkToSchema)[N]>;