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