Reuse schema properties #1631
-
Hi, I have a very large schema that represents a cluster with many data tiers: hot Each of this properties contains a "node" type. I can't figure out how can I reuse this node type to avoid repeating. const nodesOut = z.object({
zone: z.string(),
hot: z.array(
z.object({
jvm: z.object({
mem: z.object({
heap_used_in_bytes: z.number(),
heap_used_percent: z.number(),
}),
}),
fs: z.object({
total: z.object({
total_in_bytes: z.number(),
free_in_bytes: z.number(),
available_in_bytes: z.number(),
}),
}),
indices: z.object({
mappings: z.object({
total_count: z.number(),
total_estimated_overhead_in_bytes: z.number(),
}),
}).optional(),
attributes: z.object({
data: z.string().optional(),
availability_zone: z.string(),
server_name: z.string(),
}),
})
).optional(),
warm: z.array(
z.object({
jvm: z.object({
mem: z.object({
heap_used_in_bytes: z.number(),
heap_used_percent: z.number(),
}),
}),
fs: z.object({
total: z.object({
total_in_bytes: z.number(),
free_in_bytes: z.number(),
available_in_bytes: z.number(),
}),
}),
indices: z.object({
mappings: z.object({
total_count: z.number(),
total_estimated_overhead_in_bytes: z.number(),
}),
}).optional(),
attributes: z.object({
data: z.string().optional(),
availability_zone: z.string(),
server_name: z.string(),
}),
})
).optional(),
cold: z.array(
z.object({
jvm: z.object({
mem: z.object({
heap_used_in_bytes: z.number(),
heap_used_percent: z.number(),
}),
}),
fs: z.object({
total: z.object({
total_in_bytes: z.number(),
free_in_bytes: z.number(),
available_in_bytes: z.number(),
}),
}),
indices: z.object({
mappings: z.object({
total_count: z.number(),
total_estimated_overhead_in_bytes: z.number(),
}).optional(),
}),
attributes: z.object({
data: z.string().optional(),
availability_zone: z.string(),
server_name: z.string(),
}),
})
).optional(),
frozen: z.array(
z.object({
jvm: z.object({
mem: z.object({
heap_used_in_bytes: z.number(),
heap_used_percent: z.number(),
}),
}),
fs: z.object({
total: z.object({
total_in_bytes: z.number(),
free_in_bytes: z.number(),
available_in_bytes: z.number(),
}),
}),
indices: z.object({
mappings: z.object({
total_count: z.number(),
total_estimated_overhead_in_bytes: z.number(),
}),
}).optional(),
attributes: z.object({
data: z.string().optional(),
availability_zone: z.string(),
server_name: z.string(),
}),
})
).optional(),
}); I read about recursive schemas but this is not actually recursive. What's the best way to go? Thanks |
Beta Was this translation helpful? Give feedback.
Answered by
JacobWeisenburger
Dec 5, 2022
Replies: 1 comment 2 replies
-
Does this help? const jvmSchema = z.object( {
mem: z.object( {
heap_used_in_bytes: z.number(),
heap_used_percent: z.number(),
} ),
} )
const fsSchema = z.object( {
total: z.object( {
total_in_bytes: z.number(),
free_in_bytes: z.number(),
available_in_bytes: z.number(),
} ),
} )
const indicesSchema = z.object( {
mappings: z.object( {
total_count: z.number(),
total_estimated_overhead_in_bytes: z.number(),
} ),
} )
const attributesSchema = z.object( {
data: z.string().optional(),
availability_zone: z.string(),
server_name: z.string(),
} )
const schema = z.object( {
jvm: jvmSchema,
fs: fsSchema,
indices: indicesSchema.optional(),
attributes: attributesSchema,
} )
const nodesOut = z.object( {
zone: z.string(),
hot: z.array( schema ).optional(),
warm: z.array( schema ).optional(),
cold: z.array( schema ).optional(),
frozen: z.array( schema ).optional(),
} ) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
llermaly
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this help?