All files types.ts

100% Statements 4/4
100% Branches 2/2
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99                                                    4x 4x 4x 4x                                                                                                                                          
import { StreamSubscriptionActions } from "./stream_subscription";
 
export interface StreamInterface<T> {
  listen(
    onData: StreamListener<T>,
    callbacks?: StreamListenOptions
  ): StreamSubscriptionActions;
  asBroadcastStream(): StreamInterface<T>;
  every(condition: (data: T) => boolean): Promise<boolean>;
  first(): Promise<T>;
  firstWhere(condition: (data: T) => boolean): Promise<T>;
  forEach(fn: (data: T) => void): Promise<void>;
  reduce(reducer: (prev: any, next: T) => any): Promise<any>;
  map(transform: (data: T) => any): StreamInterface<T>;
  take(n: number): StreamInterface<T>;
  takeWhile(condition: (data: T) => boolean): StreamInterface<T>;
  skip(n: number): StreamInterface<T>;
  skipWhile(condition: (data: T) => boolean): StreamInterface<T>;
  where(condition: (data: T) => boolean): StreamInterface<T>;
  toArray(): Promise<Array<T>>;
  toSet(): Promise<Set<T>>;
  isBroadcast: boolean;
}
/**
 * streamMessageType - the types a message can be
 */
export enum StreamMessageType {
  Data,
  Error,
  Done,
}
 
/**
 * StreamMessageData - represents data in a stream
 * @template T - The type of data i nthe stream
 */
export interface StreamMessageData<T> {
  type: StreamMessageType.Data;
  data: T;
}
 
/**
 * StreamMessageError - represents errors in the stream
 */
export interface StreamMessageError {
  type: StreamMessageType.Error;
  data: Error;
}
 
/**
 * StreamMessageDone - represents the done message in the stream
 */
export interface StreamMessageDone {
  type: StreamMessageType.Done;
}
 
/**
 * StreamMessage - the messages in the stream
 */
export type StreamMessage<T> =
  | StreamMessageData<T>
  | StreamMessageError
  | StreamMessageDone;
 
/**
 * streamListener - listeners of the stream
 * @param data - the data passed to the listener
 * @template T - the type of the data
 */
export interface StreamListener<T> {
  (data: T): void;
}
 
/**
 * streamErrorListener - error listeners on the stream
 * @param error - the error
 */
export interface StreamErrorListener {
  (e: Error): void;
}
 
/**
 * StreamCallback - callbacks for the stream (eg: onDone, onPause, onResume...)
 */
export interface StreamCallback {
  (): void;
}
 
/**
 * StreamListenOptions - the optional callbacks when listening to a stream
 */
export interface StreamListenOptions {
  onError?: StreamErrorListener;
  onDone?: StreamCallback;
  onPause?: StreamCallback;
  onResume?: StreamCallback;
  cancelOnError?: boolean;
}