Files
radicle-explorer/httpd-client/lib/shared.ts
T
Sebastian Martinez f0758de9f3 Add reactions to patch revisions
- Also adapts to the new reactions API schema everywhere.
2024-02-02 13:33:07 +01:00

66 lines
1.6 KiB
TypeScript

import type { ZodSchema, z } from "zod";
import { array, boolean, literal, number, object, string, union } from "zod";
export interface SuccessResponse {
success: true;
}
export const successResponseSchema = object({
success: literal(true),
}) satisfies ZodSchema<SuccessResponse>;
export const nodeConfigSchema = object({
alias: string(),
peers: union([
object({ type: literal("static") }),
object({ type: literal("dynamic"), target: number() }),
]),
listen: array(string()),
connect: array(string()),
externalAddresses: array(string()),
network: union([literal("main"), literal("test")]),
relay: boolean(),
limits: object({
routingMaxSize: number(),
routingMaxAge: number(),
fetchConcurrency: number(),
gossipMaxAge: number(),
maxOpenFiles: number(),
rate: object({
inbound: object({
fillRate: number(),
capacity: number(),
}),
outbound: object({
fillRate: number(),
capacity: number(),
}),
}),
}),
policy: union([literal("allow"), literal("block")]),
scope: union([literal("followed"), literal("all")]),
});
export const rangeSchema = union([
object({
type: literal("lines"),
range: object({ start: number(), end: number() }),
}),
object({
type: literal("chars"),
line: number(),
range: object({ start: number(), end: number() }),
}),
]);
export type Range = z.infer<typeof rangeSchema>;
export const codeLocationSchema = object({
path: string(),
old: rangeSchema.optional(),
new: rangeSchema.optional(),
});
export type CodeLocation = z.infer<typeof codeLocationSchema>;