Skip to content

Commit f594b7b

Browse files
committed
Make ClientStatefulQueryReply more DRY
1 parent 1f51ae2 commit f594b7b

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

packages/cmake-file-api/src/schemas/ReplyIndexV1.ts

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,28 @@ const ReplyErrorObject = z.object({
1919
error: z.string(),
2020
});
2121

22+
const VersionNumber = z.number();
23+
24+
const VersionObject = z.object({
25+
major: z.number(),
26+
minor: z.number().optional(),
27+
});
28+
29+
const VersionSpec = z.union([
30+
VersionNumber,
31+
VersionObject,
32+
z.array(z.union([VersionNumber, VersionObject])),
33+
]);
34+
35+
const QueryRequest = z.object({
36+
kind: z.string(),
37+
version: VersionSpec.optional(),
38+
client: z.unknown().optional(),
39+
});
40+
2241
const ClientStatefulQueryReply = z.object({
2342
client: z.unknown().optional(),
24-
requests: z
25-
.array(
26-
z.object({
27-
kind: z.string(),
28-
version: z
29-
.union([
30-
z.number(),
31-
z.object({
32-
major: z.number(),
33-
minor: z.number().optional(),
34-
}),
35-
z.array(
36-
z.union([
37-
z.number(),
38-
z.object({
39-
major: z.number(),
40-
minor: z.number().optional(),
41-
}),
42-
]),
43-
),
44-
])
45-
.optional(),
46-
client: z.unknown().optional(),
47-
}),
48-
)
49-
.optional(),
43+
requests: z.array(QueryRequest).optional(),
5044
responses: z.array(ReplyFileReferenceV1).optional(),
5145
});
5246

0 commit comments

Comments
 (0)