server

Documentation for using streamListDiff in a NodeJS environment.

IMPORT

import { streamListDiff } from "@donedeal0/superdiff/server";

FORMAT

Input

In a server environment, Readable refers to NodeJS streams, and FilePath refers to the path of a file (e.g., ./list.json). Examples are provided in the #usage section below.

 prevList: Readable | FilePath | Record<string, unknown>[],
 nextList: Readable | FilePath | Record<string, unknown>[],
 referenceProperty: keyof Record<string, unknown>,
 options: {
  showOnly?: ("added" | "deleted" | "moved" | "updated" | "equal")[], // [] by default
  chunksSize?: number, // 0 by default
  considerMoveAsUpdate?: boolean; // false by default
  useWorker?: boolean; // true by default
  showWarnings?: boolean; // true by default
}
  • prevList: the original object list.

  • nextList: the new object list.

  • referenceProperty: a property common to all objects in your lists (e.g. id).

  • options

    • chunksSize the number of object diffs returned by each streamed chunk. (e.g. 0 = 1 object diff per chunk, 10 = 10 object diffs per chunk).

    • showOnly gives you the option to return only the values whose status you are interested in (e.g. ["added", "equal"]).

    • considerMoveAsUpdate: if set to true a moved value will be considered as updated.

    • useWorker: if set to true, the diff will be run in a worker for maximum performance. Only recommended for large lists (e.g. +100,000 items).

    • showWarnings: if set to true, potential warnings will be displayed in the console.

Output

The objects diff are grouped into arrays - called chunks - and are consumed thanks to an event listener. You have access to 3 events:

  • data: to be notified when a new chunk of object diffs is available.

  • finish: to be notified when the stream is finished.

  • error: to be notified if an error occurs during the stream.


USAGE

Input

Array

Stream

File

Example

Output

Last updated