Skip to main content

DiffUtility

Helpers for producing Diffs between two versions of a node.

Use them when overriding diffProperties() on a model or resource - each one compares a single field of the previous node against the latest, and returns the diffs that field's change implies.

@group

Functions/Diff

Index

Constructors

constructor

Methods

staticdiffArray

  • diffArray(a: UnknownNode, b: UnknownNode, field: string): Diff<UnknownNode, unknown>[]
  • Generate a deep diff of an array of basic types from the previous node vs the latest node.


    Parameters

    • a: UnknownNode

      previous node.

    • b: UnknownNode

      latest node.

    • field: string

      string representing the field parent uses to reference the array.

    Returns Diff<UnknownNode, unknown>[]

staticdiffArrayOfObjects

  • diffArrayOfObjects(a: UnknownNode, b: UnknownNode, field: string, compare: (object1: unknown, object2: unknown) => boolean): Diff<UnknownNode, unknown>[]
  • Generate a deep diff of an array of objects from the previous node vs the latest node.


    Parameters

    • a: UnknownNode

      previous node.

    • b: UnknownNode

      latest node.

    • field: string

      string representing the field parent uses to reference the array.

    • compare: (object1: unknown, object2: unknown) => boolean

      function to check if two objects are equal.

      Returns Diff<UnknownNode, unknown>[]

    staticdiffMap

    • diffMap(a: UnknownNode, b: UnknownNode, field: string): Diff<UnknownNode, unknown>[]
    • Generate a deep diff of a map of basic types from the previous node vs the latest node.


      Parameters

      • a: UnknownNode

        previous node.

      • b: UnknownNode

        latest node.

      • field: string

        string representing the field parent uses to reference the map.

      Returns Diff<UnknownNode, unknown>[]

    staticdiffNodes

    • diffNodes(a: UnknownNode[], b: UnknownNode[], field: string): Promise<Diff<UnknownNode, unknown>[]>
    • Generate a deep diff of an array of previous node vs latest node. The diff is generated recursively, i.e. all children of the node are included in the diff.


      Parameters

      • a: UnknownNode[]

        array of previous nodes.

      • b: UnknownNode[]

        array of latest nodes.

      • field: string

        string representing the unique identifier of the node.

      Returns Promise<Diff<UnknownNode, unknown>[]>

    staticdiffObject

    • diffObject(a: UnknownNode, b: UnknownNode, field: string): Diff<UnknownNode, unknown>[]
    • Generate a deep diff of an object from the previous node vs the latest node.


      Parameters

      • a: UnknownNode

        previous node.

      • b: UnknownNode

        latest node.

      • field: string

        string representing the field parent uses to reference the object.

      Returns Diff<UnknownNode, unknown>[]

    staticisObjectDeepEquals

    • isObjectDeepEquals(x: unknown, y: unknown, excludePaths?: string[], currentPath?: string[]): boolean
    • Whether two values are deeply equal.


      Parameters

      • x: unknown

        The first value.

      • y: unknown

        The second value.

      • excludePaths: string[] = []

        Dot-separated paths to ignore, e.g. tags.

      • currentPath: string[] = []

        The path walked so far. Callers leave it empty; the recursion fills it.

      Returns boolean