Node SDK

Module lib/streams

Legend

  • Namespace
  • Variable
  • Function
  • Function with type parameter
  • Type alias
  • Type alias with type parameter
  • Interface
  • Interface with type parameter
  • Enumeration
  • Class

Index

Type aliases

CommandWrapFunction<T, U>: (obj: T, done: (err?: any, result?: U) => void, push: (data: U) => void) => void

Type parameters

  • T

    The type of the data to be processed

  • U = any

    The type of the data that results from being processed

Type declaration

    • (obj: T, done: (err?: any, result?: U) => void, push: (data: U) => void): void
    • A function that takes the data to be processed, the callback done function and a push function that can be used to wrap a command to do work.

      If the processing succeeded and you don't need to checkpoint and you don't want to pass anything on to flow to the next processing step, you can just call this function with no arguments.

      Parameters

      • obj: T
      • done: (err?: any, result?: U) => void
          • (err?: any, result?: U): void
          • The callback function to send back an error or the successful processed result.

            Parameters

            • Optional err: any

              If processing failed, set this to an Error object representing the failure.

            • Optional result: U

              If processing succeed and you don't need to pass anything to another processing step, you can pass true here which will checkpoint for you for the event being processed. If processing succeeded and you need to send a result of processing to another processing step, set this to be the data to send.

            Returns void

      • push: (data: U) => void
          • (data: U): void
          • A convenience method to push the resulting processed data to a queue.

            Parameters

            • data: U

              The data to push to a queue.

            Returns void

      Returns void

ProcessCallback<T>: (err?: any, result?: boolean | T, opts?: ProcessCallbackOptions) => void

Type parameters

  • T

    The data to give to the next processing step, in a pipeline that would be putting the data into the pipeline to flow to the next pipeline step.

Type declaration

    • This is a standard callback used to tell the SDK that you are done processing something, either successfully or not successfully. If the processing succeeded and you don't need to checkpoint and you don't want to pass anything on to flow to the next processing step, you can just call this function with no arguments.

      Parameters

      • Optional err: any

        If processing failed, set this to an Error object representing the failure.

      • Optional result: boolean | T

        If processing succeed and you don't need to pass anything to another processing step, you can pass true here which will checkpoint for you for the event being processed. If processing succeeded and you need to send a result of processing to another processing step, set this to be the data to send.

      • Optional opts: ProcessCallbackOptions

        This allows you to override the normal options used by the SDK for this one event that you are saying is now "done".

      Returns void

ProcessFunction<T, U>: (this: ProcessFunctionContext<U>, payload: T, wrapper: ReadEvent<T>, callback: ProcessCallback<U>) => void

Type parameters

  • T

    The type of the data that is to be processed

  • U

    The type of the data that will be the result of processing

Type declaration

ProcessFunctionAsync<T, U>: (this: ProcessFunctionContext<U>, payload: T, wrapper: ReadEvent<T>) => Promise<ProcessFunctionAsyncReturn<U> | ProcessFunctionAsyncReturnOptions<U>>

Type parameters

  • T

  • U

Type declaration

ProcessFunctionAsyncReturn<T>: T | T[] | boolean

Type parameters

  • T

Variables

eventstream: typeof es

For convenience, a re-export of the popular event-stream library.

Functions

  • This creates a pipeline step to tell the SDK to micro-batch events received in one pipeline step before sending them to the next pipeline step. It's useful to control how many events arrive all at once, roughly, to the next pipeline step. It can be helpful for a pipeline step to receive a micro-batch of events, say 100 at a time, instead of 1 at a time to leverage economies of scale when writing to a database, e.g. doing one query to the database to get 100 records back all at once instead of having to do a query to the database for each event as it comes in.

    Type parameters

    • T

      The type of the data being batched from the previous pipeline step before sending to the next pipeline step

    Parameters

    • opts: number | BatchOptions

      If a number, then this is how many events to batch up before sending along. If BatchOptions then this is fine-grained control to ensure events keep flowing smoothly whether there are a few or many at a given moment.

    Returns TransformStream<T, ReadEvent<T[]>>

    The pipeline step that is ready to be used in a pipeline

  • buffer(opts: any, each: any, emit: any, flush: any): stream.Transform
  • Parameters

    • opts: any
    • each: any
    • emit: any
    • flush: any

    Returns stream.Transform

  • bufferBackoff<T>(each: any, emit: any, retryOpts: any, opts: any, flush: any): WritableStream<T>
  • This creates a pipeline step that takes an event, logs it and then passes the event on to the next pipeline step. The log will include the event ID of the event, if it's present. This is helpful to get visibility into the pipeline.

    Type parameters

    • T

      The type of the event that flows in, gets logged and then flows unchanged to the next pipeline step

    Parameters

    • label: string

      If present, log statements are prefixed with this string

    • Optional records: number

      If present, only log every Nth event that flows through where N is records

    Returns TransformStream<T, T>

    The pipeline step that is ready to be used in a pipeline

  • This creates a pipeline step that takes an event, logs it and then passes the event on to the next pipeline step. The log will include the event ID of the event, if it's present. This is helpful to get visibility into the pipeline.

    Type parameters

    • T

      The type of the event that flows in, gets logged and then flows unchanged to the next pipeline step

    Parameters

    • Optional records: number

      If present, only log every Nth event that flows through where N is records

    Returns TransformStream<T, T>

    The pipeline step that is ready to be used in a pipeline

  • Creates a pipeline step that can act as a noop sink.

    Sometimes you don't care to push data anywhere when you have a pipeline, but you need the fine-grained control of making your own pipeline. When that's the case, use this to create a final pipeline step, a sink, to end your pipeline.

    Pipelines must have a sink or data won't flow through the pipeline since Node streams pull data starting with the sink who asks the previous pipeline step for data and then that previous step asks the one before it for data and so on. So, no sink means no data flows. This gives you a noop sink.

    Type parameters

    • T

      The type of the data sent into this final pipeline step

    Parameters

    • Optional shouldLog: string | boolean

      If a string, logs events that come in, prefixing the log statement with the stream. If this is true, logs the event. Otherwise, does nothing.

    Returns WritableStream<T>

    The pipeline step that is ready to be used in a pipeline

  • eventIdFromTimestamp(timestamp: MomentInput, granularity?: string, record?: number): string
  • Helper function to turn a timestamp into an RStreams event ID.

    Parameters

    • timestamp: MomentInput

      The timestamp you want to turn into an RStreams event ID which can be anything used to construct a Moment object

    • Optional granularity: string

      Specify the granularity of the event ID, maybe just year/month or year/month/hour, etc.

    • Optional record: number

    Returns string

    The generated event ID

  • eventIdToTimestamp(eid: string): number
  • Helper function to turn a an RStreams event ID into a timestamp.

    Parameters

    • eid: string

      The event ID to turn into an epoch timestamp

    Returns number

    The timestamp as a time since the epoch

  • fromS3(file: { bucket: string; key: string; range?: string }): WritableStream<any>
  • This creates a pipeline step that can act as the first step in a pipeline, the source, which reads data from an S3 file.

    Parameters

    • file: { bucket: string; key: string; range?: string }

      What to read from.

      • bucket: string

        The name of the S3 bucket to read from

      • key: string

        The name of the file in the bucket to read from

      • Optional range?: string

        Read from a specific range in the file. This is a string that must look like this: bytes=<startingByteoffset>-<endingByteOffset> where is the start position to read from and is the ending position to read from, exclusive.

    Returns WritableStream<any>

    The pipeline step that is ready to be used in a pipeline

  • Creates a pipeline step that will log events as they pass through which can be helpful for debugging in between streaming operations.

    Type parameters

    • T

      The type of the data that flows through the step to be logged

    Parameters

    • Optional prefix: string

      If provided, this prefix is included with each log

    Returns TransformStream<T, T>

    The pipeline step that is ready to be used in a pipeline

  • parse(skipErrors?: boolean): stream.Transform
  • A pipeline step that will split and parse JSON lines, turning them into events.

    Parameters

    • Optional skipErrors: boolean

      If true and there's a parse error, the error and the JSON line that couldn't be parsed is skipped. Defaults to false.

    Returns stream.Transform

    The pipeline step that is ready to be used in a pipeline

  • A callback-based version of pipeAsync. Creates a pipeline of steps where the first step produces the data and then it flows to the next step and so on. The first step is the source, producing the content, the final step is the sink.

    Type parameters

    • T1

      The type of data that is produced by the source

    Parameters

    • read: Stream | ReadableStream<T1>

      Pipeline step 1: The source that produces the data, the first step of the pipe

    • write: Stream | WritableStream<T1>

      Pipeline step 2: The sink that is the last step of the pipe

    • Optional errorCallback: ErrorCallback

      Called if something goes wrong

    Returns WritableStream<T1> | stream.Stream

    The pipeline itself

  • A callback-based version of pipeAsync. Creates a pipeline of steps where the first step produces the data and then it flows to the next step and so on. The first step is the source, producing the content, the final step is the sink.

    Type parameters

    • T1

      The type of data that is produced by the source

    • T2

      The type of data generated and that moves to the final step of the pipe

    Parameters

    • read: Stream | ReadableStream<T1>

      Pipeline step 1: The source that produces the data, the first step of the pipe

    • t1: TransformStream<T1, T2>

      Pipeline step 2: A transformation step that takes data from the previous step and pushes the result to the next step

    • write: Stream | WritableStream<T2>

      Pipeline step 3: The sink that is the last step of the pipe

    • Optional errorCallback: ErrorCallback

      Called if something goes wrong

    Returns WritableStream<T2> | stream.Stream

    The pipeline itself

  • A callback-based version of pipeAsync. Creates a pipeline of steps where the first step produces the data and then it flows to the next step and so on. The first step is the source, producing the content, the final step is the sink.

    Type parameters

    • T1

      The type of data that is produced by the source

    • T2

      The type of data generated and that moves to the next step of the pipe

    • T3

      The type of data generated and that moves to the final step of the pipe

    Parameters

    • read: Stream | ReadableStream<T1>

      Pipeline step 1: The source that produces the data, the first step of the pipe

    • t1: TransformStream<T1, T2>

      Pipeline step 2: A transformation step that takes data from the previous step and pushes the result to the next step

    • t2: TransformStream<T2, T3>

      Pipeline step 3: A transformation step that takes data from the previous step and pushes the result to the next step

    • write: Stream | WritableStream<T3>

      Pipeline step 4: The sink that is the last step of the pipe

    • Optional errorCallback: ErrorCallback

      Called if something goes wrong

    Returns WritableStream<T3> | stream.Stream

    The pipeline itself

  • A callback-based version of pipeAsync. Creates a pipeline of steps where the first step produces the data and then it flows to the next step and so on. The first step is the source, producing the content, the final step is the sink.

    Type parameters

    • T1

      The type of data that is produced by the source

    • T2

      The type of data generated and that moves to the next step of the pipe

    • T3

      The type of data generated and that moves to the next step of the pipe

    • T4

      The type of data generated and that moves to the final step of the pipe

    Parameters

    • read: Stream | ReadableStream<T1>

      Pipeline step 1: The source that produces the data, the first step of the pipe

    • t1: TransformStream<T1, T2>

      Pipeline step 2: A transformation step that takes data from the previous step and pushes the result to the next step

    • t2: TransformStream<T2, T3>

      Pipeline step 3: A transformation step that takes data from the previous step and pushes the result to the next step

    • t3: TransformStream<T3, T4>

      Pipeline step 4: A transformation step that takes data from the previous step and pushes the result to the next step

    • write: Stream | WritableStream<T4>

      Pipeline step 5: The sink that is the last step of the pipe

    • Optional errorCallback: ErrorCallback

      Called if something goes wrong

    Returns WritableStream<T4> | stream.Stream

    The pipeline itself

  • A callback-based version of pipeAsync. Creates a pipeline of steps where the first step produces the data and then it flows to the next step and so on. The first step is the source, producing the content, the final step is the sink.

    Type parameters

    • T1

      The type of data that is produced by the source

    • T2

      The type of data generated and that moves to the next step of the pipe

    • T3

      The type of data generated and that moves to the next step of the pipe

    • T4

      The type of data generated and that moves to the next step of the pipe

    • T5

      The type of data generated and that moves to the final step of the pipe

    Parameters

    • read: Stream | ReadableStream<T1>

      Pipeline step 1: The source that produces the data, the first step of the pipe

    • t1: TransformStream<T1, T2>

      Pipeline step 2: A transformation step that takes data from the previous step and pushes the result to the next step

    • t2: TransformStream<T2, T3>

      Pipeline step 3: A transformation step that takes data from the previous step and pushes the result to the next step

    • t3: TransformStream<T3, T4>

      Pipeline step 4: A transformation step that takes data from the previous step and pushes the result to the next step

    • t4: TransformStream<T4, T5>

      Pipeline step 5: A transformation step that takes data from the previous step and pushes the result to the next step

    • write: Stream | WritableStream<T5>

      Pipeline step 6: The sink that is the last step of the pipe

    • Optional errorCallback: ErrorCallback

      Called if something goes wrong

    Returns WritableStream<T5> | stream.Stream

    The pipeline itself

  • A callback-based version of pipeAsync. Creates a pipeline of steps where the first step produces the data and then it flows to the next step and so on. The first step is the source, producing the content, the final step is the sink.

    Type parameters

    • T1

      The type of data that is produced by the source

    • T2

      The type of data generated and that moves to the next step of the pipe

    • T3

      The type of data generated and that moves to the next step of the pipe

    • T4

      The type of data generated and that moves to the next step of the pipe

    • T5

      The type of data generated and that moves to the next step of the pipe

    • T6

      The type of data generated and that moves to the final step of the pipe

    Parameters

    • read: Stream | ReadableStream<T1>

      Pipeline step 1: The source that produces the data, the first step of the pipe

    • t1: TransformStream<T1, T2>

      Pipeline step 2: A transformation step that takes data from the previous step and pushes the result to the next step

    • t2: TransformStream<T2, T3>

      Pipeline step 3: A transformation step that takes data from the previous step and pushes the result to the next step

    • t3: TransformStream<T3, T4>

      Pipeline step 4: A transformation step that takes data from the previous step and pushes the result to the next step

    • t4: TransformStream<T4, T5>

      Pipeline step 5: A transformation step that takes data from the previous step and pushes the result to the next step

    • t5: TransformStream<T5, T6>

      Pipeline step 6: A transformation step that takes data from the previous step and pushes the result to the next step

    • write: Stream | WritableStream<T6>

      Pipeline step 7: The sink that is the last step of the pipe

    • Optional errorCallback: ErrorCallback

      Called if something goes wrong

    Returns WritableStream<T6> | stream.Stream

    The pipeline itself

  • An async/await-friendly version of pipe. Creates a pipeline of steps where the first step produces the data and then it flows to the next step and so on. The first step is the source, producing the content, the final step is the sink.

    Type parameters

    • T1

      The type of data that is produced by the source

    Parameters

    • read: Stream | ReadableStream<T1>

      Pipeline step 1: The source that produces the data, the first step of the pipe

    • write: WritableStream<T1>

      Pipeline step 2: The sink that is the last step of the pipe

    Returns Promise<void>

    A promise so it can play nice with async/await

  • An async/await-friendly version of pipe. Creates a pipeline of steps where the first step produces the data and then it flows to the next step and so on. The first step is the source, producing the content, the final step is the sink.

    Type parameters

    • T1

      The type of data that is produced by the source

    • T2

      The type of data generated and that moves to the final step of the pipe

    Parameters

    • read: Stream | ReadableStream<T1>

      Pipeline step 1: The source that produces the data, the first step of the pipe

    • t1: TransformStream<T1, T2>

      Pipeline step 2: A transformation step that takes data from the previous step and pushes the result to the next step

    • write: WritableStream<T2>

      Pipeline step 3: The sink that is the last step of the pipe

    Returns Promise<void>

    A promise so it can play nice with async/await

  • An async/await-friendly version of pipe. Creates a pipeline of steps where the first step produces the data and then it flows to the next step and so on. The first step is the source, producing the content, the final step is the sink.

    Type parameters

    • T1

      The type of data that is produced by the source

    • T2

      The type of data generated and that moves to the next step of the pipe

    • T3

      The type of data generated and that moves to the final step of the pipe

    Parameters

    • read: Stream | ReadableStream<T1>

      Pipeline step 1: The source that produces the data, the first step of the pipe

    • t1: TransformStream<T1, T2>

      Pipeline step 2: A transformation step that takes data from the previous step and pushes the result to the next step

    • t2: TransformStream<T2, T3>

      Pipeline step 3: A transformation step that takes data from the previous step and pushes the result to the next step

    • write: WritableStream<T3>

      Pipeline step 4: The sink that is the last step of the pipe

    Returns Promise<void>

    A promise so it can play nice with async/await

  • An async/await-friendly version of pipe. Creates a pipeline of steps where the first step produces the data and then it flows to the next step and so on. The first step is the source, producing the content, the final step is the sink.

    Type parameters

    • T1

      The type of data that is produced by the source

    • T2

      The type of data generated and that moves to the next step of the pipe

    • T3

      The type of data generated and that moves to the next step of the pipe

    • T4

      The type of data generated and that moves to the final step of the pipe

    Parameters

    • read: Stream | ReadableStream<T1>

      Pipeline step 1: The source that produces the data, the first step of the pipe

    • t1: TransformStream<T1, T2>

      Pipeline step 2: A transformation step that takes data from the previous step and pushes the result to the next step

    • t2: TransformStream<T2, T3>

      Pipeline step 3: A transformation step that takes data from the previous step and pushes the result to the next step

    • t3: TransformStream<T3, T4>

      Pipeline step 4: A transformation step that takes data from the previous step and pushes the result to the next step

    • write: WritableStream<T4>

      Pipeline step 5: The sink that is the last step of the pipe

    Returns Promise<void>

    A promise so it can play nice with async/await

  • An async/await-friendly version of pipe. Creates a pipeline of steps where the first step produces the data and then it flows to the next step and so on. The first step is the source, producing the content, the final step is the sink.

    Type parameters

    • T1

      The type of data that is produced by the source

    • T2

      The type of data generated and that moves to the next step of the pipe

    • T3

      The type of data generated and that moves to the next step of the pipe

    • T4

      The type of data generated and that moves to the next step of the pipe

    • T5

      The type of data generated and that moves to the final step of the pipe

    Parameters

    • read: Stream | ReadableStream<T1>

      Pipeline step 1: The source that produces the data, the first step of the pipe

    • t1: TransformStream<T1, T2>

      Pipeline step 2: A transformation step that takes data from the previous step and pushes the result to the next step

    • t2: TransformStream<T2, T3>

      Pipeline step 3: A transformation step that takes data from the previous step and pushes the result to the next step

    • t3: TransformStream<T3, T4>

      Pipeline step 4: A transformation step that takes data from the previous step and pushes the result to the next step

    • t4: TransformStream<T4, T5>

      Pipeline step 5: A transformation step that takes data from the previous step and pushes the result to the next step

    • write: WritableStream<T5>

      Pipeline step 6: The sink that is the last step of the pipe

    Returns Promise<void>

    A promise so it can play nice with async/await

  • An async/await-friendly version of pipe. Creates a pipeline of steps where the first step produces the data and then it flows to the next step and so on. The first step is the source, producing the content, the final step is the sink.

    Type parameters

    • T1

      The type of data that is produced by the source

    • T2

      The type of data generated and that moves to the next step of the pipe

    • T3

      The type of data generated and that moves to the next step of the pipe

    • T4

      The type of data generated and that moves to the next step of the pipe

    • T5

      The type of data generated and that moves to the next step of the pipe

    • T6

      The type of data generated and that moves to the final step of the pipe

    Parameters

    • read: Stream | ReadableStream<T1>

      Pipeline step 1: The source that produces the data, the first step of the pipe

    • t1: TransformStream<T1, T2>

      Pipeline step 2: A transformation step that takes data from the previous step and pushes the result to the next step

    • t2: TransformStream<T2, T3>

      Pipeline step 3: A transformation step that takes data from the previous step and pushes the result to the next step

    • t3: TransformStream<T3, T4>

      Pipeline step 4: A transformation step that takes data from the previous step and pushes the result to the next step

    • t4: TransformStream<T4, T5>

      Pipeline step 5: A transformation step that takes data from the previous step and pushes the result to the next step

    • t5: TransformStream<T5, T6>

      Pipeline step 6: A transformation step that takes data from the previous step and pushes the result to the next step

    • write: WritableStream<T6>

      Pipeline step 7: The sink that is the last step of the pipe

    Returns Promise<void>

    A promise so it can play nice with async/await

  • This creates a pipeline step that takes events in of type T, allows your code to process it and then you send an event of type U to the the next pipeline step.

    internal

    Type parameters

    • T

      The type of the data sent into the function to be processed

    • U

      The type of the data you send on after being processed

    Parameters

    • id: string

      The name of the bot act as

    • func: ProcessFunction<T, U>

      The function to process data, getting data of type T and returning data of type U

    • outQueue: string

      The queue to send the resulting data to

    Returns TransformStream<T, U>

    The pipeline step that is ready to be used in a pipeline

  • This creates a pipeline step that turns a Javascript object into a JSON line (newline at the end of the stringified JS object). This is used to make it easy to create JSON lines files.

    Returns TransformStream<any, string>

    The pipeline step that is ready to be used in a pipeline

  • This creates a callback based pipeline step that will take data in, possibly transform the data or do computation, and then sends the result on to the next step in the pipeline.

    see

    throughAsync

    Type parameters

    • T

      The type of the data sent in to be passed through this step.

    • U

      The type of data to be sent on to the next step in the pipeline.

    Parameters

    • Optional transform: (this: TransformStream<T, U>, obj: T, done: DataCallback<U, Error>) => void

      A function that does the work of taking the data in, doing something with it and then calling the done function when done. The first arg is stripped off by Javascript since it recognizes that the this arg is just to set the this context so that the this keyword will work inside the function and itself be the instance of the transform stream which can be useful. For example, say you want to push to an event in here to a queue. You could do that by calling this.push to push the event to a queue while still sending the queue on the next step in the pipeline afterwards.

      So, the first real argument your function will receive is obj which is the data event being sent in to be processed/transformed and sent on to the next pipeline step. The second arg is done. You call this when you're done. Call done() if there's no error but you want to filter out this event and not pass it on to the next pipeline step. Call done(err) if an error ocurreed where err is a string or Error object. Call done(null, U) when no error and you want to pass on an event to the next step in the pipeline where U is the type of object being sent on.

    • Optional flush: FlushCallback<U, Error>

      A function to be called when the entire pipeline has been flushed to allow for cleanup, perhaps closing a DB connection.

    Returns TransformStream<T, U>

    The pipeline step that is ready to be used in a pipeline

  • This creates an async/await-friendly pipeline step that will take data in, possibly transform the data or do computation, and then sends the result on to the next step in the pipeline.

    see

    through

    Type parameters

    • T

      The type of the data sent in to be passed through this step.

    • U

      The type of data to be sent on to the next step in the pipeline.

    Parameters

    • Optional transform: (this: TransformStream<T, U>, obj: T) => U | Promise<U>

      A function that does the work of taking the data in, doing something with it and then rejecting or resolving the promise with the result object type U. If you resolve with no result data, the event is skipped and not sent to the next pipeline step. The first arg is stripped off by Javascript since it recognizes that the this arg is just to set the this context so that the this keyword will work inside the function and itself be the instance of the transform stream which can be useful. For example, say you want to push to an event in here to a queue. You could do that by calling this.push to push the event to a queue while still sending the queue on the next step in the pipeline afterwards.

      So, the first real argument your function will receive is obj which is the data event being sent in to be processed/transformed and sent on to the next pipeline step.

    • Optional flush: (this: TransformStream<T, U>) => U | Promise<U>

      A function to be called when the entire pipeline has been flushed to allow for cleanup, perhaps closing a DB connection.

    Returns TransformStream<T, U>

    The pipeline step that is ready to be used in a pipeline

  • This creates a pipeline step meant to be the last step in a pipeline, the sink, that writes events that flow into it into S3. You should micro-batch events before getting to this step to control how many events to write to the file.

    Parameters

    • Bucket: string

      The name of the AWS S3 bucket to write the file to

    • File: string

      The name of the file to write.

    Returns WritableStream<any>

    The pipeline step that is ready to be used in a pipeline

Generated using TypeDoc