feat: some shit
This commit is contained in:
parent
05e8970475
commit
fca59e87e5
@ -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
|
||||||
|
.select({
|
||||||
definition: nodeTable.definition,
|
definition: nodeTable.definition,
|
||||||
hash: nodeTable.hash,
|
hash: nodeTable.hash,
|
||||||
}).from(
|
})
|
||||||
nodeTable,
|
.from(nodeTable)
|
||||||
)
|
.where(and(eq(nodeTable.userId, userName)));
|
||||||
.where(
|
|
||||||
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,12 +126,13 @@ export async function getNodeDefinitionById(
|
|||||||
systemId: string,
|
systemId: string,
|
||||||
nodeId: string,
|
nodeId: string,
|
||||||
) {
|
) {
|
||||||
const node = await db.select({
|
const node = await db
|
||||||
|
.select({
|
||||||
definition: nodeTable.definition,
|
definition: nodeTable.definition,
|
||||||
hash: nodeTable.hash,
|
hash: nodeTable.hash,
|
||||||
}).from(
|
})
|
||||||
nodeTable,
|
.from(nodeTable)
|
||||||
).where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(nodeTable.userId, userName),
|
eq(nodeTable.userId, userName),
|
||||||
eq(nodeTable.systemId, systemId),
|
eq(nodeTable.systemId, systemId),
|
||||||
@ -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,12 +163,13 @@ export async function getNodeVersions(
|
|||||||
system: string,
|
system: string,
|
||||||
nodeId: string,
|
nodeId: string,
|
||||||
) {
|
) {
|
||||||
const nodes = await db.select({
|
const nodes = await db
|
||||||
|
.select({
|
||||||
definition: nodeTable.definition,
|
definition: nodeTable.definition,
|
||||||
hash: nodeTable.hash,
|
hash: nodeTable.hash,
|
||||||
}).from(
|
})
|
||||||
nodeTable,
|
.from(nodeTable)
|
||||||
).where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(nodeTable.userId, user),
|
eq(nodeTable.userId, user),
|
||||||
eq(nodeTable.systemId, system),
|
eq(nodeTable.systemId, system),
|
||||||
@ -175,7 +180,7 @@ export async function getNodeVersions(
|
|||||||
|
|
||||||
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
|
||||||
|
.select({
|
||||||
definition: nodeTable.definition,
|
definition: nodeTable.definition,
|
||||||
}).from(
|
})
|
||||||
nodeTable,
|
.from(nodeTable)
|
||||||
).where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(nodeTable.userId, user),
|
eq(nodeTable.userId, user),
|
||||||
eq(nodeTable.systemId, system),
|
eq(nodeTable.systemId, system),
|
||||||
eq(nodeTable.nodeId, nodeId),
|
eq(nodeTable.nodeId, nodeId),
|
||||||
eq(nodeTable.hash, hash),
|
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
|
||||||
|
.select({
|
||||||
content: nodeTable.content,
|
content: nodeTable.content,
|
||||||
}).from(
|
})
|
||||||
nodeTable,
|
.from(nodeTable)
|
||||||
).where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(nodeTable.userId, user),
|
eq(nodeTable.userId, user),
|
||||||
eq(nodeTable.systemId, system),
|
eq(nodeTable.systemId, system),
|
||||||
eq(nodeTable.nodeId, nodeId),
|
eq(nodeTable.nodeId, nodeId),
|
||||||
eq(nodeTable.hash, hash),
|
eq(nodeTable.hash, hash),
|
||||||
),
|
),
|
||||||
).limit(1);
|
)
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
if (node.length === 0) {
|
if (node.length === 0) {
|
||||||
throw new NodeNotFoundError();
|
throw new NodeNotFoundError();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user