Implement Integral Data Types #13
@@ -45,3 +45,16 @@ pub trait IntoCommandDefinition: Sized {
|
|||||||
|
|
||||||
fn parse(command: Command) -> Result<Self, IntoCommandDefinitionError>;
|
fn parse(command: Command) -> Result<Self, IntoCommandDefinitionError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl IntoCommandDefinition for () {
|
||||||
|
fn create(name: String) -> CommandDefinition {
|
||||||
|
CommandDefinition {
|
||||||
|
name,
|
||||||
|
parameters: vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse(_: Command) -> Result<Self, IntoCommandDefinitionError> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ const model = defineModel<{ [key: string]: CommandParameterData }>({
|
|||||||
required: true,
|
required: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data: command_info } = useCommand(props.command_name);
|
const { data: command_info, error: command_error } = useCommand(
|
||||||
|
props.command_name,
|
||||||
|
);
|
||||||
|
|
||||||
watch([command_info], ([cmd_info]) => {
|
watch([command_info], ([cmd_info]) => {
|
||||||
if (cmd_info == null) {
|
if (cmd_info == null) {
|
||||||
@@ -97,6 +99,9 @@ watch([command_info], ([cmd_info]) => {
|
|||||||
></CommandParameterDataConfigurator>
|
></CommandParameterDataConfigurator>
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
|
<template v-else-if="command_error">
|
||||||
|
<span>Error: {{ command_error }}</span>
|
||||||
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<span> Loading... </span>
|
<span> Loading... </span>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -41,8 +41,13 @@ export function useCommand(name: MaybeRefOrGetter<string>) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/cmd/${name_value}`);
|
const res = await fetch(`/api/cmd/${name_value}`);
|
||||||
data.value = await res.json();
|
if (res.ok) {
|
||||||
error.value = null;
|
data.value = await res.json();
|
||||||
|
error.value = null;
|
||||||
|
} else {
|
||||||
|
data.value = null;
|
||||||
|
error.value = await res.text();
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
data.value = null;
|
data.value = null;
|
||||||
error.value = e;
|
error.value = e;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
export function toJsonString(data: any): string {
|
export function toJsonString(data: any): string {
|
||||||
return JSON.stringify(data, (_key, value) => {
|
return JSON.stringify(data, (_key, value) => {
|
||||||
if (typeof value == 'bigint') {
|
if (typeof value == 'bigint') {
|
||||||
|
// @ts-expect-error TS2339
|
||||||
return JSON.rawJSON(value.toString());
|
return JSON.rawJSON(value.toString());
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
@@ -10,6 +11,7 @@ export function toJsonString(data: any): string {
|
|||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
export function parseJsonString(data: string): any {
|
export function parseJsonString(data: string): any {
|
||||||
|
// @ts-expect-error TS2345, TS7006
|
||||||
return JSON.parse(data, (key, value, context) => {
|
return JSON.parse(data, (key, value, context) => {
|
||||||
if (key === 'Int64' || key == 'Unsigned64') {
|
if (key === 'Int64' || key == 'Unsigned64') {
|
||||||
// Or use the constructor of your custom high-precision number library
|
// Or use the constructor of your custom high-precision number library
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ pub(super) async fn get_one(
|
|||||||
name: web::Path<String>,
|
name: web::Path<String>,
|
||||||
) -> Result<impl Responder, HttpServerResultError> {
|
) -> Result<impl Responder, HttpServerResultError> {
|
||||||
Ok(web::Json(
|
Ok(web::Json(
|
||||||
command_service.get_command_definition(&name.to_string()),
|
command_service
|
||||||
|
.get_command_definition(&name.to_string())
|
||||||
|
.ok_or_else(|| HttpServerResultError::CmdNotFound {
|
||||||
|
cmd: name.to_string(),
|
||||||
|
})?,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ pub enum HttpServerResultError {
|
|||||||
PanelUuidNotFound { uuid: Uuid },
|
PanelUuidNotFound { uuid: Uuid },
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Command(#[from] crate::command::error::Error),
|
Command(#[from] crate::command::error::Error),
|
||||||
|
#[error("Command Not Found: {cmd}")]
|
||||||
|
CmdNotFound { cmd: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResponseError for HttpServerResultError {
|
impl ResponseError for HttpServerResultError {
|
||||||
@@ -36,6 +38,7 @@ impl ResponseError for HttpServerResultError {
|
|||||||
HttpServerResultError::InternalError { .. } => StatusCode::INTERNAL_SERVER_ERROR,
|
HttpServerResultError::InternalError { .. } => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
HttpServerResultError::PanelUuidNotFound { .. } => StatusCode::NOT_FOUND,
|
HttpServerResultError::PanelUuidNotFound { .. } => StatusCode::NOT_FOUND,
|
||||||
HttpServerResultError::Command(inner) => inner.status_code(),
|
HttpServerResultError::Command(inner) => inner.status_code(),
|
||||||
|
HttpServerResultError::CmdNotFound { .. } => StatusCode::NOT_FOUND,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn error_response(&self) -> HttpResponse {
|
fn error_response(&self) -> HttpResponse {
|
||||||
|
|||||||
Reference in New Issue
Block a user