Fix types
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Michael Zhang 2023-04-18 20:07:51 -05:00
parent 97774d5852
commit b69b497cdd
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
3 changed files with 24 additions and 25 deletions

View file

@ -1,4 +1,4 @@
import { Node, App, PrismaClient } from "@prisma/client";
import { Node, App, PrismaClient, Prisma } from "@prisma/client";
import {
FetchedNode,
ICreateNodeRequest,
@ -8,8 +8,11 @@ import {
IRemoveNodeRequest,
IUpdateNodeRequest,
} from "./types";
import { inspect } from "util";
/**
* Server-side wrapper class for interfacing with the underlying data storage
* tool.
*/
export class Database {
private prisma: PrismaClient;
@ -23,24 +26,21 @@ export class Database {
public async findManyNodes(
request: IFindManyNodesRequest
): Promise<FetchedNode[] | null> {
const query = {
take: request.take,
select: { id: true, label: true, metadata: true },
where: { metadata: { some: { OR: [] } } },
};
const select_keys = [];
if (request.select_keys) {
for (const key of request.select_keys) {
query.where.metadata.some.OR.push({
select_keys.push({
appKey: key.appKey,
appId: key.appId,
});
}
}
console.log("query", inspect(query, false, 10));
const nodes = await this.prisma.node.findMany(query);
const nodes = await this.prisma.node.findMany({
take: request.take,
select: { id: true, label: true, metadata: true },
where: { metadata: { some: { OR: [...select_keys] } } },
});
return nodes;
}
@ -94,7 +94,6 @@ export class Database {
value: Buffer.from(value),
},
});
console.log("Creating metadata keys", key, value, meta);
}
}
@ -102,7 +101,9 @@ export class Database {
});
}
public async updateNode(request: IUpdateNodeRequest): Promise<Node | null> {
public async updateNode(
request: IUpdateNodeRequest
): Promise<FetchedNode | null> {
const node = await this.prisma.$transaction(async (client) => {
await client.node.update({ where: { id: request.id }, data: {} });
@ -138,7 +139,6 @@ export class Database {
await this.prisma.$transaction(async (client) => {
await this.prisma.node.delete({ where: { id: request.id } });
});
console.log("Removed", request);
}
}

View file

@ -2,20 +2,20 @@ import { For, batch, createEffect, createSignal, JSX } from "solid-js";
import { SetStoreFunction, Store, createStore } from "solid-js/store";
import { useRouteData } from "solid-start";
import { createServerAction$, createServerData$ } from "solid-start/server";
import { FetchedNode } from "~/core/types";
import { db, todosApp } from "~/db";
const retrieveMeta = (node, key) => {
const retrieveMeta = (node: FetchedNode, key: string) => {
const meta = node.metadata.find(
(meta) => meta.appId == todosApp.id && meta.appKey == key
);
if (!meta) return null;
const metaValue = meta.value.toString();
console.log("s", key, metaValue);
return JSON.parse(metaValue);
};
const nodeToTodoItem = (node) => ({
const nodeToTodoItem = (node: FetchedNode) => ({
id: node.id,
title: retrieveMeta(node, "title"),
completed: retrieveMeta(node, "completed"),
@ -47,9 +47,10 @@ export function routeData() {
}
export default function Todos() {
const ouais = useRouteData<typeof routeData>();
if (!ouais()) return <>Loading...</>;
const { initTodos } = ouais();
const getRouteData = useRouteData<typeof routeData>();
const data = getRouteData();
if (!data) return <>Loading...</>;
const { initTodos } = data;
const [newTitle, setTitle] = createSignal("");
const [todos, setTodos] = createTodoStore<TodoItem[]>("todos", initTodos);
@ -69,7 +70,6 @@ export default function Todos() {
label: `todo-${title}`,
metadata_keys,
});
console.log("Created node", node);
return node;
},
@ -121,7 +121,7 @@ export default function Todos() {
setMeta("completed", completed);
const node = await db.updateNode({ id, metadata_keys });
console.log("Updated node", node);
if (!node) return;
return nodeToTodoItem(node);
}
@ -166,7 +166,6 @@ export default function Todos() {
});
await removeTodoAction({ id: todo.id });
console.log("Removed", todo);
// TODO: Is there a race condition here with the index?
setTodos((t) => removeIndex(t, idx));
};
@ -233,7 +232,6 @@ function createTodoStore<T extends object>(
);
createEffect(() => {
console.log("Calling local storage");
// localStorage.setItem(name, JSON.stringify(state));
});

View file

@ -7,6 +7,7 @@
"moduleResolution": "node",
"jsxImportSource": "solid-js",
"jsx": "preserve",
"noEmit": true,
"strict": true,
"types": ["solid-start/env"],
"baseUrl": "./",