// Immutable values which can be JSON.stringified into a structurally unique string. export type Simplify = T extends Object ? { [K in keyof T]: T[K] } : T; export type StringKeyOf = keyof T extends string ? keyof T : never; export type FunctionType

= (...p: P) => R; export type GraphFunctionID = string; export type GraphFunction< Input extends any[] = any[], Output = any > = FunctionType>; export type GraphFunctions = { [name: GraphFunctionID]: GraphFunction }; export type GraphNodeInput = T extends GraphFunction ? Input : never; export type GraphNodeOutput = T extends GraphFunction ? Output : never; export type GraphNodeID = string; export type GraphReference = { ref: ID }; export type GraphInput = any; export function isGraphReference(value: unknown) : value is GraphReference { const maybe = value as GraphReference | undefined; return typeof maybe?.ref === "string"; } export type GraphNode = StringKeyOf> = GraphNodeByTypeAndFunction; export type GraphNodeByTypeAndFunction = { type: Type; input: GraphInput[] & { [Index in keyof GraphNodeInput]: GraphNodeInput[Index] | GraphReference }; } export type Graph = { [id: GraphNodeID]: GraphNode> }; export type StringKeysOfType = ({ [Key in keyof A]: A[Key] extends T ? (Key extends string ? Key : never) : never })[keyof A]; export type ValuesOrReference = unknown[] & { [Key in keyof A]: A[Key] | GraphReference> } export function defineGraphFunctions(gf: GF): GF { return gf; } type Foo = { a: number, b: string, c: number } type Bar = StringKeysOfType