Fix: api
This commit is contained in:
@@ -1,18 +1 @@
|
|||||||
{
|
{ writers }: writers.writePython3Bin "classgen" { flakeIgnore = [ "E501" ]; } ./main.py
|
||||||
stdenv,
|
|
||||||
python3,
|
|
||||||
lib,
|
|
||||||
}:
|
|
||||||
|
|
||||||
stdenv.mkDerivation {
|
|
||||||
name = "classgen";
|
|
||||||
src = ./.;
|
|
||||||
buildInputs = [ python3 ];
|
|
||||||
installPhase = ''
|
|
||||||
install -Dm755 ${./main.py} $out/bin/classgen
|
|
||||||
'';
|
|
||||||
meta = with lib; {
|
|
||||||
description = "A tool to generate Python dataclasses from JSON Schema definitions";
|
|
||||||
license = licenses.mit;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -129,6 +129,10 @@ def run_gen(args: argparse.Namespace) -> None:
|
|||||||
with open(args.output, "w") as f:
|
with open(args.output, "w") as f:
|
||||||
f.write(
|
f.write(
|
||||||
"""
|
"""
|
||||||
|
# DON NOT EDIT THIS FILE MANUALLY. IT IS GENERATED.
|
||||||
|
# UPDATE:
|
||||||
|
# ruff: noqa: N815
|
||||||
|
# ruff: noqa: N806
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any\n\n
|
from typing import Any\n\n
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -80,9 +80,9 @@ function createFunctions<K extends OperationNames>(
|
|||||||
registry[operationName][id] = fn;
|
registry[operationName][id] = fn;
|
||||||
|
|
||||||
window.clan[operationName] = (s: string) => {
|
window.clan[operationName] = (s: string) => {
|
||||||
const f = (response: GtkResponse<OperationResponse<K>>) => {
|
const f = (response: OperationResponse<K>) => {
|
||||||
if (response.op_key === id) {
|
if (response.op_key === id) {
|
||||||
registry[operationName][id](response.result);
|
registry[operationName][id](response);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
deserialize(f)(s);
|
deserialize(f)(s);
|
||||||
@@ -121,6 +121,7 @@ export const callApi = <K extends OperationNames>(
|
|||||||
return new Promise<OperationResponse<K>>((resolve, reject) => {
|
return new Promise<OperationResponse<K>>((resolve, reject) => {
|
||||||
const id = nanoid();
|
const id = nanoid();
|
||||||
pyApi[method].receive((response) => {
|
pyApi[method].receive((response) => {
|
||||||
|
console.log("Received response: ", { response });
|
||||||
if (response.status === "error") {
|
if (response.status === "error") {
|
||||||
reject(response);
|
reject(response);
|
||||||
}
|
}
|
||||||
@@ -132,10 +133,10 @@ export const callApi = <K extends OperationNames>(
|
|||||||
};
|
};
|
||||||
|
|
||||||
const deserialize =
|
const deserialize =
|
||||||
<T>(fn: (response: GtkResponse<T>) => void) =>
|
<T>(fn: (response: T) => void) =>
|
||||||
(str: string) => {
|
(str: string) => {
|
||||||
try {
|
try {
|
||||||
const r = JSON.parse(str) as GtkResponse<T>;
|
const r = JSON.parse(str) as T;
|
||||||
console.log("Received: ", r);
|
console.log("Received: ", r);
|
||||||
fn(r);
|
fn(r);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export const BlockDevicesView: Component = () => {
|
|||||||
if (result.status === "error") throw new Error("Failed to fetch data");
|
if (result.status === "error") throw new Error("Failed to fetch data");
|
||||||
return result.data;
|
return result.data;
|
||||||
},
|
},
|
||||||
|
staleTime: 1000 * 60 * 5,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user