feat: add simple performance tracker
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 2m23s

This commit is contained in:
2024-04-25 00:02:02 +02:00
parent 2de2560a57
commit f51f61df17
12 changed files with 408 additions and 224 deletions

View File

@ -0,0 +1,57 @@
import { Graph, NodeDefinition, NodeId } from "./types";
export interface NodeRegistry {
/**
* The status of the node registry
* @remarks The status should be "loading" when the registry is loading, "ready" when the registry is ready, and "error" if an error occurred while loading the registry
*/
status: "loading" | "ready" | "error";
/**
* Load the nodes with the given ids
* @param nodeIds - The ids of the nodes to load
* @returns A promise that resolves when the nodes are loaded
* @throws An error if the nodes could not be loaded
* @remarks This method should be called before calling getNode or getAllNodes
*/
load: (nodeIds: NodeId[]) => Promise<NodeDefinition[]>;
/**
* Get a node by id
* @param id - The id of the node to get
* @returns The node with the given id, or undefined if no such node exists
*/
getNode: (id: NodeId) => NodeDefinition | undefined;
/**
* Get all nodes
* @returns An array of all nodes
*/
getAllNodes: () => NodeDefinition[];
}
export interface RuntimeExecutor {
/**
* Execute the given graph
* @param graph - The graph to execute
* @returns The result of the execution
*/
execute: (graph: Graph, settings: Record<string, unknown>) => unknown;
}
export interface RuntimeCache {
/**
* Get the value for the given key
* @param key - The key to get the value for
* @returns The value for the given key, or undefined if no such value exists
*/
get: (key: string) => unknown | undefined;
/**
* Set the value for the given key
* @param key - The key to set the value for
* @param value - The value to set
*/
set: (key: string, value: unknown) => void;
/**
* Clear the cache
*/
clear: () => void;
}

View File

@ -1,100 +1,5 @@
import { z } from "zod";
import { NodeInputSchema } from "./inputs";
export type { NodeInput } from "./inputs";
export type { NodeRegistry, RuntimeExecutor, RuntimeCache } from "./components";
export type { Node, NodeDefinition, Socket, NodeId, Edge, Graph } from "./types";
export { NodeDefinitionSchema } from "./types";
export type Node = {
id: number;
type: string;
props?: Record<string, any>,
tmp?: {
depth?: number;
mesh?: any;
random?: number;
parents?: Node[],
children?: Node[],
inputNodes?: Record<string, Node>
type?: NodeDefinition;
downX?: number;
downY?: number;
x?: number;
y?: number;
ref?: HTMLElement;
visible?: boolean;
isMoving?: boolean;
},
meta?: {
title?: string;
lastModified?: string;
},
position: [x: number, y: number]
}
export const NodeDefinitionSchema = z.object({
id: z.string(),
inputs: z.record(NodeInputSchema).optional(),
outputs: z.array(z.string()).optional(),
meta: z.object({
description: z.string().optional(),
title: z.string().optional(),
}).optional(),
});
export type NodeDefinition = z.infer<typeof NodeDefinitionSchema> & {
execute(input: Int32Array): Int32Array;
};
export type Socket = {
node: Node;
index: number | string;
position: [number, number];
};
export interface NodeRegistry {
/**
* The status of the node registry
* @remarks The status should be "loading" when the registry is loading, "ready" when the registry is ready, and "error" if an error occurred while loading the registry
*/
status: "loading" | "ready" | "error";
/**
* Load the nodes with the given ids
* @param nodeIds - The ids of the nodes to load
* @returns A promise that resolves when the nodes are loaded
* @throws An error if the nodes could not be loaded
* @remarks This method should be called before calling getNode or getAllNodes
*/
load: (nodeIds: string[]) => Promise<void>;
/**
* Get a node by id
* @param id - The id of the node to get
* @returns The node with the given id, or undefined if no such node exists
*/
getNode: (id: string) => NodeDefinition | undefined;
/**
* Get all nodes
* @returns An array of all nodes
*/
getAllNodes: () => NodeDefinition[];
}
export interface RuntimeExecutor {
/**
* Execute the given graph
* @param graph - The graph to execute
* @returns The result of the execution
*/
execute: (graph: Graph, settings: Record<string, unknown>) => unknown;
}
export type Edge = [Node, number, Node, string];
export type Graph = {
id: number;
meta?: {
title?: string;
lastModified?: string;
},
settings?: Record<string, any>,
nodes: Node[];
edges: [number, number, number, string][];
}

View File

@ -0,0 +1,64 @@
import { z } from "zod";
import { NodeInputSchema } from "./inputs";
export type NodeId = `${string}/${string}/${string}`;
export type Node = {
id: number;
type: NodeId;
props?: Record<string, number | number[]>,
tmp?: {
depth?: number;
mesh?: any;
random?: number;
parents?: Node[],
children?: Node[],
inputNodes?: Record<string, Node>
type?: NodeDefinition;
downX?: number;
downY?: number;
x?: number;
y?: number;
ref?: HTMLElement;
visible?: boolean;
isMoving?: boolean;
},
meta?: {
title?: string;
lastModified?: string;
},
position: [x: number, y: number]
}
export const NodeDefinitionSchema = z.object({
id: z.string(),
inputs: z.record(NodeInputSchema).optional(),
outputs: z.array(z.string()).optional(),
meta: z.object({
description: z.string().optional(),
title: z.string().optional(),
}).optional(),
});
export type NodeDefinition = z.infer<typeof NodeDefinitionSchema> & {
execute(input: Int32Array): Int32Array;
};
export type Socket = {
node: Node;
index: number | string;
position: [number, number];
};
export type Edge = [Node, number, Node, string];
export type Graph = {
id: number;
meta?: {
title?: string;
lastModified?: string;
},
settings?: Record<string, any>,
nodes: Node[];
edges: [number, number, number, string][];
}

View File

@ -1,27 +1,40 @@
type SparseArray<T = number> = (T | T[] | SparseArray<T>)[];
export function concatEncodedArrays(input: (number | number[])[]): number[] {
export function concatEncodedArrays(input: (number | number[] | Int32Array)[]): Int32Array {
if (input.length === 1 && Array.isArray(input[0])) {
return input[0]
let totalLength = 4;
for (let i = 0; i < input.length; i++) {
const item = input[i];
if (Array.isArray(item) || item instanceof Int32Array) {
totalLength += item.length;
} else {
totalLength++;
}
}
const result = [0, 1]; // opening bracket
const result = new Int32Array(totalLength);
result[0] = 0;
result[1] = 1;
let index = 2; // Start after the opening bracket
let last_closing_bracket = 1;
for (let i = 0; i < input.length; i++) {
const item = input[i];
if (Array.isArray(item) || item instanceof Int32Array) {
result.push(...item);
last_closing_bracket = result.length - 1;
result.set(item, index);
index += item.length;
last_closing_bracket = index - 1;
} else {
result[last_closing_bracket]++;
result.push(item);
result[index] = item;
index++;
}
}
result.push(1, 1); // closing bracket
result[totalLength - 2] = 1;
result[totalLength - 1] = 1;
return result
}

View File

@ -1,6 +1,6 @@
use utils::{
geometry::{create_multiple_paths, create_path, wrap_multiple_paths},
get_args,
split_args,
};
#[allow(dead_code)]
@ -16,7 +16,7 @@ fn test_split_args(){
];
for input in inputs {
println!("RESULT: {:?}", get_args(&input));
println!("RESULT: {:?}", split_args(&input));
}
}