Compare commits
7 Commits
15ff1cc52d
...
main
Author | SHA1 | Date | |
---|---|---|---|
05b192e7ab | |||
edcaab4bd4
|
|||
a99040f42e
|
|||
fca59e87e5
|
|||
05e8970475
|
|||
385d1dd831
|
|||
dc46c4b64c
|
@ -32,7 +32,10 @@
|
|||||||
let performanceStore = createPerformanceStore();
|
let performanceStore = createPerformanceStore();
|
||||||
|
|
||||||
const registryCache = new IndexDBCache("node-registry");
|
const registryCache = new IndexDBCache("node-registry");
|
||||||
const nodeRegistry = new RemoteNodeRegistry("", registryCache);
|
const nodeRegistry = new RemoteNodeRegistry(
|
||||||
|
"https://node-store.app.max-richter.dev",
|
||||||
|
registryCache,
|
||||||
|
);
|
||||||
const workerRuntime = new WorkerRuntimeExecutor();
|
const workerRuntime = new WorkerRuntimeExecutor();
|
||||||
const runtimeCache = new MemoryRuntimeCache();
|
const runtimeCache = new MemoryRuntimeCache();
|
||||||
const memoryRuntime = new MemoryRuntimeExecutor(nodeRegistry, runtimeCache);
|
const memoryRuntime = new MemoryRuntimeExecutor(nodeRegistry, runtimeCache);
|
||||||
|
@ -45,6 +45,7 @@ async function postNode(node: Node) {
|
|||||||
const wasmContent = await Deno.readFile(node.path);
|
const wasmContent = await Deno.readFile(node.path);
|
||||||
|
|
||||||
const url = `http://localhost:8000/nodes`;
|
const url = `http://localhost:8000/nodes`;
|
||||||
|
// const url = "https://node-store.app.max-richter.dev/nodes";
|
||||||
|
|
||||||
const res = await fetch(url, {
|
const res = await fetch(url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -58,34 +58,16 @@ async function getNodeByVersion(
|
|||||||
const [id, version] = nodeId.replace(/\.wasm$/, "").split("@");
|
const [id, version] = nodeId.replace(/\.wasm$/, "").split("@");
|
||||||
console.log({ user, system, id, version });
|
console.log({ user, system, id, version });
|
||||||
if (version) {
|
if (version) {
|
||||||
return service.getNodeVersionWasm(
|
return service.getNodeVersionWasm(user, system, id, version);
|
||||||
user,
|
|
||||||
system,
|
|
||||||
id,
|
|
||||||
version,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return service.getNodeWasmById(
|
return service.getNodeWasmById(user, system, id);
|
||||||
user,
|
|
||||||
system,
|
|
||||||
id,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const [id, version] = nodeId.replace(/\.json$/, "").split("@");
|
const [id, version] = nodeId.replace(/\.json$/, "").split("@");
|
||||||
if (!version) {
|
if (!version) {
|
||||||
return service.getNodeDefinitionById(
|
return service.getNodeDefinitionById(user, system, id);
|
||||||
user,
|
|
||||||
system,
|
|
||||||
id,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return await service.getNodeVersion(
|
return await service.getNodeVersion(user, system, id, version);
|
||||||
user,
|
|
||||||
system,
|
|
||||||
id,
|
|
||||||
version,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,7 +152,10 @@ nodeRouter.openapi(
|
|||||||
console.log("Get Nodes by System", { user, system });
|
console.log("Get Nodes by System", { user, system });
|
||||||
try {
|
try {
|
||||||
const nodes = await service.getNodesBySystem(user, system);
|
const nodes = await service.getNodesBySystem(user, system);
|
||||||
return c.json(nodes);
|
return c.json({
|
||||||
|
id: `${user}/${system}`,
|
||||||
|
nodes: nodes.map((n) => ({ id: n.id.split("@")[0] })),
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof CustomError) {
|
if (error instanceof CustomError) {
|
||||||
throw new HTTPException(error.status, { message: error.message });
|
throw new HTTPException(error.status, { message: error.message });
|
||||||
@ -201,8 +186,13 @@ nodeRouter.openapi(
|
|||||||
const nodeId = c.req.param("nodeId.json").replace(/\.json$/, "");
|
const nodeId = c.req.param("nodeId.json").replace(/\.json$/, "");
|
||||||
console.log("Get Node by Id", { user, system, nodeId });
|
console.log("Get Node by Id", { user, system, nodeId });
|
||||||
try {
|
try {
|
||||||
const node = await service.getNodeDefinitionById(user, system, nodeId);
|
const res = await getNodeByVersion(user, system, nodeId);
|
||||||
return c.json(node);
|
if (res instanceof ArrayBuffer) {
|
||||||
|
c.header("Content-Type", "application/wasm");
|
||||||
|
return c.body(res);
|
||||||
|
} else {
|
||||||
|
return c.json(res);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof CustomError) {
|
if (error instanceof CustomError) {
|
||||||
throw new HTTPException(error.status, { message: error.message });
|
throw new HTTPException(error.status, { message: error.message });
|
||||||
|
@ -53,21 +53,17 @@ export async function createNode(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getNodeDefinitionsByUser(userName: string) {
|
export async function getNodeDefinitionsByUser(userName: string) {
|
||||||
const nodes = await db.select({
|
const nodes = await db
|
||||||
definition: nodeTable.definition,
|
.select({
|
||||||
hash: nodeTable.hash,
|
definition: nodeTable.definition,
|
||||||
}).from(
|
hash: nodeTable.hash,
|
||||||
nodeTable,
|
})
|
||||||
)
|
.from(nodeTable)
|
||||||
.where(
|
.where(and(eq(nodeTable.userId, userName)));
|
||||||
and(
|
|
||||||
eq(nodeTable.userId, userName),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
return nodes.map((n) => ({
|
return nodes.map((n) => ({
|
||||||
...n.definition,
|
...n.definition,
|
||||||
id: n.definition.id + "@" + n.hash,
|
// id: n.definition.id + "@" + n.hash,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,16 +79,18 @@ export async function getNodesBySystem(
|
|||||||
.from(nodeTable)
|
.from(nodeTable)
|
||||||
.where(
|
.where(
|
||||||
and(eq(nodeTable.systemId, systemId), eq(nodeTable.userId, username)),
|
and(eq(nodeTable.systemId, systemId), eq(nodeTable.userId, username)),
|
||||||
).orderBy(nodeTable.userId, nodeTable.systemId, nodeTable.nodeId);
|
)
|
||||||
|
.orderBy(nodeTable.userId, nodeTable.systemId, nodeTable.nodeId);
|
||||||
|
|
||||||
const definitions = nodes
|
const definitions = nodes
|
||||||
.map((node) =>
|
.map(
|
||||||
[NodeDefinitionSchema.safeParse(node.definition), node.hash] as const
|
(node) =>
|
||||||
|
[NodeDefinitionSchema.safeParse(node.definition), node.hash] as const,
|
||||||
)
|
)
|
||||||
.filter(([v]) => v.success)
|
.filter(([v]) => v.success)
|
||||||
.map(([v, hash]) => ({
|
.map(([v, hash]) => ({
|
||||||
...v.data,
|
...v.data,
|
||||||
id: v?.data?.id + "@" + hash,
|
// id: v?.data?.id + "@" + hash,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return definitions;
|
return definitions;
|
||||||
@ -103,7 +101,9 @@ export async function getNodeWasmById(
|
|||||||
systemId: string,
|
systemId: string,
|
||||||
nodeId: string,
|
nodeId: string,
|
||||||
) {
|
) {
|
||||||
const node = await db.select({ content: nodeTable.content }).from(nodeTable)
|
const node = await db
|
||||||
|
.select({ content: nodeTable.content })
|
||||||
|
.from(nodeTable)
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(nodeTable.userId, userName),
|
eq(nodeTable.userId, userName),
|
||||||
@ -126,18 +126,19 @@ export async function getNodeDefinitionById(
|
|||||||
systemId: string,
|
systemId: string,
|
||||||
nodeId: string,
|
nodeId: string,
|
||||||
) {
|
) {
|
||||||
const node = await db.select({
|
const node = await db
|
||||||
definition: nodeTable.definition,
|
.select({
|
||||||
hash: nodeTable.hash,
|
definition: nodeTable.definition,
|
||||||
}).from(
|
hash: nodeTable.hash,
|
||||||
nodeTable,
|
})
|
||||||
).where(
|
.from(nodeTable)
|
||||||
and(
|
.where(
|
||||||
eq(nodeTable.userId, userName),
|
and(
|
||||||
eq(nodeTable.systemId, systemId),
|
eq(nodeTable.userId, userName),
|
||||||
eq(nodeTable.nodeId, nodeId),
|
eq(nodeTable.systemId, systemId),
|
||||||
),
|
eq(nodeTable.nodeId, nodeId),
|
||||||
)
|
),
|
||||||
|
)
|
||||||
.orderBy(asc(nodeTable.createdAt))
|
.orderBy(asc(nodeTable.createdAt))
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
@ -151,7 +152,10 @@ export async function getNodeDefinitionById(
|
|||||||
throw new InvalidNodeDefinitionError();
|
throw new InvalidNodeDefinitionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
return { ...definition.data, id: definition.data.id + "@" + node[0].hash };
|
return {
|
||||||
|
...definition.data,
|
||||||
|
// id: definition.data.id + "@" + node[0].hash
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getNodeVersions(
|
export async function getNodeVersions(
|
||||||
@ -159,23 +163,24 @@ export async function getNodeVersions(
|
|||||||
system: string,
|
system: string,
|
||||||
nodeId: string,
|
nodeId: string,
|
||||||
) {
|
) {
|
||||||
const nodes = await db.select({
|
const nodes = await db
|
||||||
definition: nodeTable.definition,
|
.select({
|
||||||
hash: nodeTable.hash,
|
definition: nodeTable.definition,
|
||||||
}).from(
|
hash: nodeTable.hash,
|
||||||
nodeTable,
|
})
|
||||||
).where(
|
.from(nodeTable)
|
||||||
and(
|
.where(
|
||||||
eq(nodeTable.userId, user),
|
and(
|
||||||
eq(nodeTable.systemId, system),
|
eq(nodeTable.userId, user),
|
||||||
eq(nodeTable.nodeId, nodeId),
|
eq(nodeTable.systemId, system),
|
||||||
),
|
eq(nodeTable.nodeId, nodeId),
|
||||||
)
|
),
|
||||||
|
)
|
||||||
.orderBy(asc(nodeTable.createdAt));
|
.orderBy(asc(nodeTable.createdAt));
|
||||||
|
|
||||||
return nodes.map((node) => ({
|
return nodes.map((node) => ({
|
||||||
...node.definition,
|
...node.definition,
|
||||||
id: node.definition.id + "@" + node.hash,
|
// id: node.definition.id + "@" + node.hash,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,18 +190,20 @@ export async function getNodeVersion(
|
|||||||
nodeId: string,
|
nodeId: string,
|
||||||
hash: string,
|
hash: string,
|
||||||
) {
|
) {
|
||||||
const nodes = await db.select({
|
const nodes = await db
|
||||||
definition: nodeTable.definition,
|
.select({
|
||||||
}).from(
|
definition: nodeTable.definition,
|
||||||
nodeTable,
|
})
|
||||||
).where(
|
.from(nodeTable)
|
||||||
and(
|
.where(
|
||||||
eq(nodeTable.userId, user),
|
and(
|
||||||
eq(nodeTable.systemId, system),
|
eq(nodeTable.userId, user),
|
||||||
eq(nodeTable.nodeId, nodeId),
|
eq(nodeTable.systemId, system),
|
||||||
eq(nodeTable.hash, hash),
|
eq(nodeTable.nodeId, nodeId),
|
||||||
),
|
eq(nodeTable.hash, hash),
|
||||||
).limit(1);
|
),
|
||||||
|
)
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
if (nodes.length === 0) {
|
if (nodes.length === 0) {
|
||||||
throw new NodeNotFoundError();
|
throw new NodeNotFoundError();
|
||||||
@ -211,18 +218,20 @@ export async function getNodeVersionWasm(
|
|||||||
nodeId: string,
|
nodeId: string,
|
||||||
hash: string,
|
hash: string,
|
||||||
) {
|
) {
|
||||||
const node = await db.select({
|
const node = await db
|
||||||
content: nodeTable.content,
|
.select({
|
||||||
}).from(
|
content: nodeTable.content,
|
||||||
nodeTable,
|
})
|
||||||
).where(
|
.from(nodeTable)
|
||||||
and(
|
.where(
|
||||||
eq(nodeTable.userId, user),
|
and(
|
||||||
eq(nodeTable.systemId, system),
|
eq(nodeTable.userId, user),
|
||||||
eq(nodeTable.nodeId, nodeId),
|
eq(nodeTable.systemId, system),
|
||||||
eq(nodeTable.hash, hash),
|
eq(nodeTable.nodeId, nodeId),
|
||||||
),
|
eq(nodeTable.hash, hash),
|
||||||
).limit(1);
|
),
|
||||||
|
)
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
if (node.length === 0) {
|
if (node.length === 0) {
|
||||||
throw new NodeNotFoundError();
|
throw new NodeNotFoundError();
|
||||||
|
Reference in New Issue
Block a user