Options
All
  • Public
  • Public/Protected
  • All
Menu

ugraph

Index

Type aliases

Variables

Functions

Type aliases

Node<PROPS>: { $id: string } & PROPS

Type parameters

Obj: Record<string, unknown>

Variables

Node: ZodObject<extendShape<{}, { $id: ZodString }>, "passthrough", ZodTypeAny, { $id: string }, { $id: string }>
Obj: ZodObject<{}, "passthrough", ZodTypeAny, {}, {}>

Functions

  • isNode(source: unknown): source is Node<Obj>
  • Parameters

    • source: unknown

    Returns source is Node<Obj>

  • isObj(source: unknown): source is Obj
  • Parameters

    • source: unknown

    Returns source is Obj

  • isReference(source: unknown): source is { $node: string | {} }
  • Parameters

    • source: unknown

    Returns source is { $node: string | {} }

  • parse(data: unknown, options?: { onConflict?: "abort" | "merge" | "ignore"; onNode?: any }): Result<{ data: unknown; nodes: Map<string, Node> }, ["DataInvalid", { errors: DataError[] }]>
  • Given data, will return a runtime Graph with all Nodes recursively resolved and mapped in .nodes for access via. that Node's $id. Accepts any data structure, although Objects and/or Arrays are most useful.

    If given types, will also validate all Objects with a $type property defined. Accepts a Map of Nodes and/or Validators OR a data-like definition which will be automatically parsed for it's Nodes. Type-definition Nodes use it's $id property to determine which $type name to validate on a Object.

    Parameters

    • data: unknown
    • options: { onConflict?: "abort" | "merge" | "ignore"; onNode?: any } = {}
      • Optional onConflict?: "abort" | "merge" | "ignore"

        Default: "abort"

        • "abort", return error on conflicting node definition.
        • "merge", merge props of all conflicting node definitions (slower).
        • "ignore", skips conflicts (only first instance is used).
      • onNode?:function
        • onNode(id: string, node: Node<Obj>): void
        • Optional callback fired once per-every complete Node object, with $id.

          Parameters

          Returns void

    Returns Result<{ data: unknown; nodes: Map<string, Node> }, ["DataInvalid", { errors: DataError[] }]>

Generated using TypeDoc