Add control RPC method registry
This commit is contained in:
@@ -30,9 +30,33 @@ export const CONTROL_PLANE_ROUTES = {
|
|||||||
surfaceSession: "/surface-session",
|
surfaceSession: "/surface-session",
|
||||||
replEval: "/repl/eval",
|
replEval: "/repl/eval",
|
||||||
replClose: "/repl/close",
|
replClose: "/repl/close",
|
||||||
|
rpcSocket: "/rpc",
|
||||||
browserSocket: "/ws",
|
browserSocket: "/ws",
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
export const CONTROL_PLANE_RPC_METHODS = {
|
||||||
|
run: "control.run",
|
||||||
|
status: "control.status",
|
||||||
|
check: "control.check",
|
||||||
|
cutover: "control.cutover",
|
||||||
|
clearState: "control.clearState",
|
||||||
|
describe: "control.describe",
|
||||||
|
logs: "control.logs",
|
||||||
|
errors: "control.errors",
|
||||||
|
devices: "control.devices",
|
||||||
|
deviceAssign: "control.device.assign",
|
||||||
|
deviceAssignLive: "control.device.assignLive",
|
||||||
|
deviceRename: "control.device.rename",
|
||||||
|
deviceIdentify: "control.device.identify",
|
||||||
|
deviceStopIdentify: "control.device.stopIdentify",
|
||||||
|
deviceRemove: "control.device.remove",
|
||||||
|
publicAuthGrant: "control.publicAuthGrant.create",
|
||||||
|
publicAuthGrantRevoke: "control.publicAuthGrant.revoke",
|
||||||
|
surfaceSession: "control.surfaceSession.create",
|
||||||
|
replEval: "control.repl.eval",
|
||||||
|
replClose: "control.repl.close",
|
||||||
|
} as const;
|
||||||
|
|
||||||
const nonEmptyString = z.string().min(1);
|
const nonEmptyString = z.string().min(1);
|
||||||
const nullableString = z.string().nullable();
|
const nullableString = z.string().nullable();
|
||||||
const optionalNullableStringAsNull = z
|
const optionalNullableStringAsNull = z
|
||||||
@@ -656,6 +680,55 @@ export const ControlPlaneCutoverResponseSchema = z.object({
|
|||||||
packages: z.array(ControlPlaneRunningPackageSchema),
|
packages: z.array(ControlPlaneRunningPackageSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const ControlPlaneRpcMethodParamsSchemas = {
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.run]: ControlPlaneRunRequestSchema,
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.status]: z.object({}).optional(),
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.check]: ControlPlaneCheckRequestSchema,
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.cutover]: ControlPlaneCutoverRequestSchema,
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.clearState]: ControlPlaneClearStateRequestSchema,
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.describe]: ControlPlaneDescribeRequestSchema,
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.logs]: ControlPlaneLogsRequestSchema,
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.errors]: ControlPlaneErrorsRequestSchema,
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.devices]: z.object({}).optional(),
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.deviceAssign]:
|
||||||
|
ControlPlaneDeviceAssignRequestSchema,
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.deviceAssignLive]:
|
||||||
|
ControlPlaneDeviceAssignRequestSchema,
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.deviceRename]:
|
||||||
|
ControlPlaneDeviceRenameRequestSchema,
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.deviceIdentify]:
|
||||||
|
ControlPlaneDeviceIdentifyRequestSchema,
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.deviceStopIdentify]:
|
||||||
|
ControlPlaneDeviceRemoveRequestSchema,
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.deviceRemove]:
|
||||||
|
ControlPlaneDeviceRemoveRequestSchema,
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.publicAuthGrant]:
|
||||||
|
ControlPlanePublicAuthGrantRequestSchema,
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.publicAuthGrantRevoke]:
|
||||||
|
ControlPlanePublicAuthGrantRevokeRequestSchema,
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.surfaceSession]:
|
||||||
|
ControlPlaneSurfaceSessionRequestSchema,
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.replEval]: ControlPlaneReplEvalRequestSchema,
|
||||||
|
[CONTROL_PLANE_RPC_METHODS.replClose]: ControlPlaneReplCloseRequestSchema,
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type ControlPlaneRpcMethod =
|
||||||
|
(typeof CONTROL_PLANE_RPC_METHODS)[keyof typeof CONTROL_PLANE_RPC_METHODS];
|
||||||
|
|
||||||
|
export const parseControlPlaneRpcParams = (
|
||||||
|
method: string,
|
||||||
|
params: unknown,
|
||||||
|
) => {
|
||||||
|
const schema =
|
||||||
|
ControlPlaneRpcMethodParamsSchemas[
|
||||||
|
method as keyof typeof ControlPlaneRpcMethodParamsSchemas
|
||||||
|
];
|
||||||
|
if (!schema) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return parseWith(schema, params ?? {});
|
||||||
|
};
|
||||||
|
|
||||||
export type ControlPlaneRunRequest = {
|
export type ControlPlaneRunRequest = {
|
||||||
target: string;
|
target: string;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user