UNPKG

serverless-spy

Version:

CDK-based library for writing elegant integration tests on AWS serverless architecture and an additional web console to monitor events in real time.

1,051 lines (915 loc) 345 kB
declare module Rx { // Type alias for observables and promises export type ObservableOrPromise<T> = IObservable<T> | Observable<T> | Promise<T>; export type ArrayLike<T> = Array<T> | { length: number;[index: number]: T; }; // Type alias for arrays and array like objects export type ArrayOrIterable<T> = ArrayLike<T>; /** * Promise A+ */ export interface Promise<T> { then<R>(onFulfilled: (value: T) => R|Promise<R>, onRejected: (error: any) => Promise<R>): Promise<R>; then<R>(onFulfilled: (value: T) => R|Promise<R>, onRejected?: (error: any) => R): Promise<R>; } /** * Promise A+ */ export interface IPromise<T> extends Promise<T> { } /** * Represents a push-style collection. */ export interface IObservable<T> { } /** * Represents a push-style collection. */ export interface Observable<T> extends IObservable<T> { } export module internals { export interface EmptyError extends Error { message: string; } export interface EmptyErrorStatic { new (): EmptyError; } export interface ObjectDisposedError extends Error { message: string; } export interface ObjectDisposedErrorStatic { new (): ObjectDisposedError; } export interface ArgumentOutOfRangeError extends Error { message: string; } export interface ArgumentOutOfRangeErrorStatic { new (): ArgumentOutOfRangeError; } export interface NotSupportedError extends Error { message: string; } export interface NotSupportedErrorStatic { new (): NotSupportedError; } export interface NotImplementedError extends Error { message: string; } export interface NotImplementedErrorStatic { new (): NotImplementedError; } } export module helpers { export var notImplemented: () => internals.NotImplementedError; export var notSupported: () => internals.NotSupportedError; } export module internals { export var bindCallback: (func: Function, thisArg: any, argCount: number) => Function; } export module internals { export var isEqual : (left: any, right: any) => boolean; } export interface IDisposable { dispose(): void; } export interface Disposable extends IDisposable { /** Is this value disposed. */ isDisposed?: boolean; } interface DisposableStatic { /** * Provides a set of static methods for creating Disposables. * @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once. */ new (action: () => void): Disposable; /** * Creates a disposable object that invokes the specified action when disposed. * @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once. * @return {Disposable} The disposable object that runs the given action upon disposal. */ create(action: () => void): Disposable; /** * Gets the disposable that does nothing when disposed. */ empty: IDisposable; /** * Validates whether the given object is a disposable * @param {Object} Object to test whether it has a dispose method * @returns {Boolean} true if a disposable object, else false. */ isDisposable(d: any): boolean; } /** * Provides a set of static methods for creating Disposables. * @param {Function} dispose Action to run during the first call to dispose. The action is guaranteed to be run at most once. */ export var Disposable: DisposableStatic; export module config { export var Promise: { new <T>(resolver: (resolvePromise: (value: T) => void, rejectPromise: (reason: any) => void) => void): IPromise<T>; }; } export module helpers { export var noop: () => void; export var notDefined: (value: any) => boolean; export var identity: <T>(value: T) => T; export var defaultNow: () => number; export var defaultComparer: (left: any, right: any) => boolean; export var defaultSubComparer: (left: any, right: any) => number; export var defaultKeySerializer: (key: any) => string; export var defaultError: (err: any) => void; export var isPromise: (p: any) => boolean; export var asArray: <T>(...args: T[]) => T[]; export var not: (value: any) => boolean; export var isFunction: (value: any) => boolean; } export type _Selector<T, TResult> = (value: T, index: number, observable: Observable<T>) => TResult; export type _ValueOrSelector<T, TResult> = TResult | _Selector<T, TResult>; export type _Predicate<T> = _Selector<T, boolean>; export type _Comparer<T, TResult> = (value1: T, value2: T) => TResult; export type _Accumulator<T, TAcc> = (acc: TAcc, value: T) => TAcc; export module special { export type _FlatMapResultSelector<T1, T2, TResult> = (value: T1, selectorValue: T2, index: number, selectorOther: number) => TResult; } export interface IObservable<T> { /** * Subscribes an o to the observable sequence. * @param {Mixed} [oOrOnNext] The object that is to receive notifications or an action to invoke for each element in the observable sequence. * @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence. * @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence. * @returns {Diposable} A disposable handling the subscriptions and unsubscriptions. */ subscribe(observer: IObserver<T>): IDisposable; /** * Subscribes an o to the observable sequence. * @param {Mixed} [oOrOnNext] The object that is to receive notifications or an action to invoke for each element in the observable sequence. * @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence. * @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence. * @returns {Diposable} A disposable handling the subscriptions and unsubscriptions. */ subscribe(onNext?: (value: T) => void, onError?: (exception: any) => void, onCompleted?: () => void): IDisposable; } export interface Observable<T> { /** * Subscribes an o to the observable sequence. * @param {Mixed} [oOrOnNext] The object that is to receive notifications or an action to invoke for each element in the observable sequence. * @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence. * @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence. * @returns {Diposable} A disposable handling the subscriptions and unsubscriptions. */ subscribe(observer: IObserver<T>): IDisposable; /** * Subscribes an o to the observable sequence. * @param {Mixed} [oOrOnNext] The object that is to receive notifications or an action to invoke for each element in the observable sequence. * @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence. * @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence. * @returns {Diposable} A disposable handling the subscriptions and unsubscriptions. */ subscribe(onNext?: (value: T) => void, onError?: (exception: any) => void, onCompleted?: () => void): IDisposable; /** * Subscribes to the next value in the sequence with an optional "this" argument. * @param {Function} onNext The function to invoke on each element in the observable sequence. * @param {Any} [thisArg] Object to use as this when executing callback. * @returns {Disposable} A disposable handling the subscriptions and unsubscriptions. */ subscribeOnNext(onNext: (value: T) => void, thisArg?: any): IDisposable; /** * Subscribes to an exceptional condition in the sequence with an optional "this" argument. * @param {Function} onError The function to invoke upon exceptional termination of the observable sequence. * @param {Any} [thisArg] Object to use as this when executing callback. * @returns {Disposable} A disposable handling the subscriptions and unsubscriptions. */ subscribeOnError(onError: (exception: any) => void, thisArg?: any): IDisposable; /** * Subscribes to the next value in the sequence with an optional "this" argument. * @param {Function} onCompleted The function to invoke upon graceful termination of the observable sequence. * @param {Any} [thisArg] Object to use as this when executing callback. * @returns {Disposable} A disposable handling the subscriptions and unsubscriptions. */ subscribeOnCompleted(onCompleted: () => void, thisArg?: any): IDisposable; /** * Subscribes an o to the observable sequence. * @param {Mixed} [oOrOnNext] The object that is to receive notifications or an action to invoke for each element in the observable sequence. * @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence. * @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence. * @returns {Diposable} A disposable handling the subscriptions and unsubscriptions. */ forEach(observer: IObserver<T>): IDisposable; /** * Subscribes an o to the observable sequence. * @param {Mixed} [oOrOnNext] The object that is to receive notifications or an action to invoke for each element in the observable sequence. * @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence. * @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence. * @returns {Diposable} A disposable handling the subscriptions and unsubscriptions. */ forEach(onNext?: (value: T) => void, onError?: (exception: any) => void, onCompleted?: () => void): IDisposable; } export interface ObservableStatic { /** * Determines whether the given object is an Observable * @param {Any} An object to determine whether it is an Observable * @returns {Boolean} true if an Observable, else false. */ isObservable(o: any): boolean; } export var Observable: ObservableStatic; export module internals { export var inherits: (child: any, parent: any) => void; export var addProperties: (obj: any, ...sources: any[]) => void; export var addRef: <T>(xs: Observable<T>, r: { getDisposable(): IDisposable; }) => Observable<T>; } export module internals { export interface ScheduledItem<TTime> { scheduler: IScheduler; state: TTime; action: (scheduler: IScheduler, state: any) => IDisposable; dueTime: TTime; comparer: (x: TTime, y: TTime) => number; disposable: SingleAssignmentDisposable; invoke(): void; compareTo(other: ScheduledItem<TTime>): number; isCancelled(): boolean; invokeCore(): IDisposable; } interface ScheduledItemStatic { new <TTime>(scheduler: IScheduler, state: any, action: (scheduler: IScheduler, state: any) => IDisposable, dueTime: TTime, comparer?: _Comparer<TTime, number>):ScheduledItem<TTime>; } export var ScheduledItem: ScheduledItemStatic } export module internals { // Priority Queue for Scheduling export interface PriorityQueue<TTime> { length: number; isHigherPriority(left: number, right: number): boolean; percolate(index: number): void; heapify(index: number): void; peek(): ScheduledItem<TTime>; removeAt(index: number): void; dequeue(): ScheduledItem<TTime>; enqueue(item: ScheduledItem<TTime>): void; remove(item: ScheduledItem<TTime>): boolean; } interface PriorityQueueStatic { new <T>(capacity: number) : PriorityQueue<T>; count: number; } export var PriorityQueue : PriorityQueueStatic; } /** * Represents a group of disposable resources that are disposed together. * @constructor */ export interface CompositeDisposable extends Disposable { /** * Adds a disposable to the CompositeDisposable or disposes the disposable if the CompositeDisposable is disposed. * @param {Mixed} item Disposable to add. */ add(item: IDisposable): void; /** * Removes and disposes the first occurrence of a disposable from the CompositeDisposable. * @param {Mixed} item Disposable to remove. * @returns {Boolean} true if found; false otherwise. */ remove(item: IDisposable): void; } interface CompositeDisposableStatic { /** * Represents a group of disposable resources that are disposed together. * @constructor */ new (...disposables: Rx.IDisposable[]): CompositeDisposable; /** * Represents a group of disposable resources that are disposed together. * @constructor */ new(disposables: Rx.IDisposable[]): CompositeDisposable; } export var CompositeDisposable: CompositeDisposableStatic; export interface SingleAssignmentDisposable { /** Performs the task of cleaning up resources. */ dispose(): void; /** Is this value disposed. */ isDisposed: boolean; getDisposable(): IDisposable; setDisposable(value: IDisposable): void; } interface SingleAssignmentDisposableStatic { new() : SingleAssignmentDisposable; } export var SingleAssignmentDisposable : SingleAssignmentDisposableStatic; export interface SerialDisposable { /** Performs the task of cleaning up resources. */ dispose(): void; /** Is this value disposed. */ isDisposed: boolean; getDisposable(): IDisposable; setDisposable(value: IDisposable): void; } interface SerialDisposableStatic { new() : SerialDisposable; } export var SerialDisposable : SerialDisposableStatic; /** * Represents a disposable resource that only disposes its underlying disposable resource when all dependent disposable objects have been disposed. */ export interface RefCountDisposable extends Disposable { /** Performs the task of cleaning up resources. */ dispose(): void; /** Is this value disposed. */ isDisposed: boolean; /** * Returns a dependent disposable that when disposed decreases the refcount on the underlying disposable. * @returns {Disposable} A dependent disposable contributing to the reference count that manages the underlying disposable's lifetime. */ getDisposable(): IDisposable; } interface RefCountDisposableStatic { /** * Initializes a new instance of the RefCountDisposable with the specified disposable. * @constructor * @param {Disposable} disposable Underlying disposable. */ new(disposable: IDisposable): RefCountDisposable; } export var RefCountDisposable : RefCountDisposableStatic; export interface IScheduler { /** Gets the current time according to the local machine's system clock. */ now(): number; /** * Schedules an action to be executed. * @param state State passed to the action to be executed. * @param {Function} action Action to be executed. * @returns {Disposable} The disposable object used to cancel the scheduled action (best effort). */ schedule<TState>(state: TState, action: (scheduler: IScheduler, state: TState) => IDisposable): IDisposable; /** * Schedules an action to be executed after dueTime. * @param state State passed to the action to be executed. * @param {Function} action Action to be executed. * @param {Number} dueTime Relative time after which to execute the action. * @returns {Disposable} The disposable object used to cancel the scheduled action (best effort). */ scheduleFuture<TState>(state: TState, dueTime: number | Date, action: (scheduler: IScheduler, state: TState) => IDisposable): IDisposable; } export interface SchedulerStatic { /** Gets the current time according to the local machine's system clock. */ now(): number; /** * Normalizes the specified TimeSpan value to a positive value. * @param {Number} timeSpan The time span value to normalize. * @returns {Number} The specified TimeSpan value if it is zero or positive; otherwise, 0 */ normalize(timeSpan: number): number; /** Determines whether the given object is a scheduler */ isScheduler(s: any): boolean; } /** Provides a set of static properties to access commonly used schedulers. */ export var Scheduler: SchedulerStatic; export interface IScheduler { /** * Schedules an action to be executed recursively. * @param {Mixed} state State passed to the action to be executed. * @param {Function} action Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in recursive invocation state. * @returns {Disposable} The disposable object used to cancel the scheduled action (best effort). */ scheduleRecursive<TState>(state: TState, action: (state: TState, action: (state: TState) => void) => void): IDisposable; /** * Schedules an action to be executed recursively after a specified relative due time. * @param {Mixed} state State passed to the action to be executed. * @param {Function} action Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in the recursive due time and invocation state. * @param {Number}dueTime Relative time after which to execute the action for the first time. * @returns {Disposable} The disposable object used to cancel the scheduled action (best effort). */ scheduleRecursiveFuture<TState, TTime extends number | Date>(state: TState, dueTime: TTime, action: (state: TState, action: (state: TState, dueTime: TTime) => void) => void): IDisposable; } export interface IScheduler { /** * Schedules a periodic piece of work by dynamically discovering the scheduler's capabilities. The periodic task will be scheduled using window.setInterval for the base implementation. * @param {Mixed} state Initial state passed to the action upon the first iteration. * @param {Number} period Period for running the work periodically. * @param {Function} action Action to be executed, potentially updating the state. * @returns {Disposable} The disposable object used to cancel the scheduled recurring action (best effort). */ schedulePeriodic<TState>(state: TState, period: number, action: (state: TState) => TState): IDisposable; } export interface IScheduler { /** * Returns a scheduler that wraps the original scheduler, adding exception handling for scheduled actions. * @param {Function} handler Handler that's run if an exception is caught. The exception will be rethrown if the handler returns false. * @returns {Scheduler} Wrapper around the original scheduler, enforcing exception handling. */ catch(handler: Function): IScheduler; } export module internals { export interface SchedulePeriodicRecursive { start(): IDisposable; } interface SchedulePeriodicRecursiveStatic { new (scheduler: any, state: any, period: any, action: any) : SchedulePeriodicRecursive; } export var SchedulePeriodicRecursive: SchedulePeriodicRecursiveStatic; } export interface SchedulerStatic { immediate: IScheduler; } export interface ICurrentThreadScheduler extends IScheduler { scheduleRequired(): boolean; } export interface SchedulerStatic { currentThread: ICurrentThreadScheduler; } export interface SchedulerStatic { default: IScheduler; async: IScheduler; } /** * Supports push-style iteration over an observable sequence. */ export interface IObserver<T> { /** * Notifies the observer of a new element in the sequence. * @param {Any} value Next element in the sequence. */ onNext(value: T): void; /** * Notifies the observer that an exception has occurred. * @param {Any} error The error that has occurred. */ onError(exception: any): void; /** * Notifies the observer of the end of the sequence. */ onCompleted(): void; } export interface Observer<T> { /** * Notifies the observer of a new element in the sequence. * @param {Any} value Next element in the sequence. */ onNext(value: T): void; /** * Notifies the observer that an exception has occurred. * @param {Any} error The error that has occurred. */ onError(exception: any): void; /** * Notifies the observer of the end of the sequence. */ onCompleted(): void; } export interface ObserverStatic { /** * Creates an observer from the specified OnNext, along with optional OnError, and OnCompleted actions. * @param {Function} [onNext] Observer's OnNext action implementation. * @param {Function} [onError] Observer's OnError action implementation. * @param {Function} [onCompleted] Observer's OnCompleted action implementation. * @returns {Observer} The observer object implemented using the given actions. */ create<T>(onNext?: (value: T) => void, onError?: (exception: any) => void, onCompleted?: () => void): Observer<T>; } /** * Supports push-style iteration over an observable sequence. */ export var Observer: ObserverStatic; /** * Represents a notification to an observer. */ export interface Notification<T> { /** * Invokes the delegate corresponding to the notification or the observer's method corresponding to the notification and returns the produced result. * * @memberOf Notification * @param {Any} observerOrOnNext Delegate to invoke for an OnNext notification or Observer to invoke the notification on.. * @param {Function} onError Delegate to invoke for an OnError notification. * @param {Function} onCompleted Delegate to invoke for an OnCompleted notification. * @returns {Any} Result produced by the observation. */ accept(observer: IObserver<T>): void; /** * Invokes the delegate corresponding to the notification or the observer's method corresponding to the notification and returns the produced result. * * @memberOf Notification * @param {Any} observerOrOnNext Delegate to invoke for an OnNext notification or Observer to invoke the notification on.. * @param {Function} onError Delegate to invoke for an OnError notification. * @param {Function} onCompleted Delegate to invoke for an OnCompleted notification. * @returns {Any} Result produced by the observation. */ accept<TResult>(onNext: (value: T) => TResult, onError: (exception: any) => TResult, onCompleted: () => TResult): TResult; /** * Returns an observable sequence with a single notification. * * @memberOf Notifications * @param {Scheduler} [scheduler] Scheduler to send out the notification calls on. * @returns {Observable} The observable sequence that surfaces the behavior of the notification upon subscription. */ toObservable(scheduler?: IScheduler): Observable<T>; hasValue: boolean; equals(other: Notification<T>): boolean; kind: string; value: T; error: any; } interface NotificationStatic { new <T>(kind: any, value: any, exception: any, accept: any, acceptObservable: any, toString: any) : Notification<T>; /** * Creates an object that represents an OnNext notification to an observer. * @param {Any} value The value contained in the notification. * @returns {Notification} The OnNext notification containing the value. */ createOnNext<T>(value: T): Notification<T>; /** * Creates an object that represents an OnError notification to an observer. * @param {Any} error The exception contained in the notification. * @returns {Notification} The OnError notification containing the exception. */ createOnError<T>(exception: any): Notification<T>; /** * Creates an object that represents an OnCompleted notification to an observer. * @returns {Notification} The OnCompleted notification. */ createOnCompleted<T>(): Notification<T>; } export var Notification : NotificationStatic; export interface Observer<T> { makeSafe(disposable: IDisposable): Observer<T>; } export module internals { /** * Abstract base class for implementations of the Observer class. * This base class enforces the grammar of observers where OnError and OnCompleted are terminal messages. */ export interface AbstractObserver<T> extends Rx.IObserver<T>, Rx.IDisposable { /** * Notifies the observer of a new element in the sequence. * @param {Any} value Next element in the sequence. */ onNext(value: T): void; /** * Notifies the observer that an exception has occurred. * @param {Any} error The error that has occurred. */ onError(exception: any): void; /** * Notifies the observer of the end of the sequence. */ onCompleted(): void; isStopped: boolean; /** * Disposes the observer, causing it to transition to the stopped state. */ dispose(): void; fail(e: any): boolean; // Must be implemented by other observers next(value: T): void; error(error: any): void; completed(): void; } interface AbstractObserverStatic { new <T>(): AbstractObserver<T>; } export var AbstractObserver: AbstractObserverStatic } /** * Class to create an Observer instance from delegate-based implementations of the on* methods. */ export interface AnonymousObserver<T> extends Observer<T> { /** * Notifies the observer of a new element in the sequence. * @param {Any} value Next element in the sequence. */ onNext(value: T): void; /** * Notifies the observer that an exception has occurred. * @param {Any} error The error that has occurred. */ onError(exception: any): void; /** * Notifies the observer of the end of the sequence. */ onCompleted(): void; } interface AnonymousObserverStatic { /** * Creates an observer from the specified OnNext, OnError, and OnCompleted actions. * @param {Any} onNext Observer's OnNext action implementation. * @param {Any} onError Observer's OnError action implementation. * @param {Any} onCompleted Observer's OnCompleted action implementation. */ new <T>(onNext?: (value: T) => void, onError?: (exception: any) => void, onCompleted?: () => void): AnonymousObserver<T>; } export var AnonymousObserver : AnonymousObserverStatic; export interface CheckedObserver<T> extends Observer<T> { checkAccess(): void; } export module internals { export interface ScheduledObserver<T> extends Observer<T> { ensureActive(): void; } } export interface Observable<T> { /** * Wraps the source sequence in order to run its observer callbacks on the specified scheduler. * * This only invokes observer callbacks on a scheduler. In case the subscription and/or unsubscription actions have side-effects * that require to be run on a scheduler, use subscribeOn. * * @param {Scheduler} scheduler Scheduler to notify observers on. * @returns {Observable} The source sequence whose observations happen on the specified scheduler. */ observeOn(scheduler: IScheduler): Observable<T>; } export interface Observable<T> { /** * Wraps the source sequence in order to run its subscription and unsubscription logic on the specified scheduler. This operation is not commonly used; * see the remarks section for more information on the distinction between subscribeOn and observeOn. * This only performs the side-effects of subscription and unsubscription on the specified scheduler. In order to invoke observer * callbacks on a scheduler, use observeOn. * @param {Scheduler} scheduler Scheduler to perform subscription and unsubscription actions on. * @returns {Observable} The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler. */ subscribeOn(scheduler: IScheduler): Observable<T>; } export interface ObservableStatic { /** * Converts a Promise to an Observable sequence * @param {Promise} An ES6 Compliant promise. * @returns {Observable} An Observable sequence which wraps the existing promise success and failure. */ fromPromise<T>(promise: Promise<T>): Observable<T>; } export interface Observable<T> { /* * Converts an existing observable sequence to an ES6 Compatible Promise * @example * var promise = Rx.Observable.return(42).toPromise(RSVP.Promise); * * // With config * Rx.config.Promise = RSVP.Promise; * var promise = Rx.Observable.return(42).toPromise(); * @param {Function} [promiseCtor] The constructor of the promise. If not provided, it looks for it in Rx.config.Promise. * @returns {Promise} An ES6 compatible promise with the last value from the observable sequence. */ toPromise(promiseCtor?: { new (resolver: (resolvePromise: (value: T) => void, rejectPromise: (reason: any) => void) => void): IPromise<T>; }): IPromise<T>; /* * Converts an existing observable sequence to an ES6 Compatible Promise * @example * var promise = Rx.Observable.return(42).toPromise(RSVP.Promise); * * // With config * Rx.config.Promise = RSVP.Promise; * var promise = Rx.Observable.return(42).toPromise(); * @param {Function} [promiseCtor] The constructor of the promise. If not provided, it looks for it in Rx.config.Promise. * @returns {Promise} An ES6 compatible promise with the last value from the observable sequence. */ toPromise<TPromise extends IPromise<T>>(promiseCtor: { new (resolver: (resolvePromise: (value: T) => void, rejectPromise: (reason: any) => void) => void): TPromise; }): TPromise; } export interface Observable<T> { /** * Creates an array from an observable sequence. * @returns {Observable} An observable sequence containing a single element with a list containing all the elements of the source sequence. */ toArray(): Observable<T[]>; } export interface ObservableStatic { /** * Creates an observable sequence from a specified subscribe method implementation. * @example * var res = Rx.Observable.create(function (observer) { return function () { } ); * var res = Rx.Observable.create(function (observer) { return Rx.Disposable.empty; } ); * var res = Rx.Observable.create(function (observer) { } ); * @param {Function} subscribe Implementation of the resulting observable sequence's subscribe method, returning a function that will be wrapped in a Disposable. * @returns {Observable} The observable sequence with the specified implementation for the Subscribe method. */ create<T>(subscribe: (observer: Observer<T>) => IDisposable | Function | void): Observable<T>; } export interface ObservableStatic { /** * Returns an observable sequence that invokes the specified factory function whenever a new observer subscribes. * * @example * var res = Rx.Observable.defer(function () { return Rx.Observable.fromArray([1,2,3]); }); * @param {Function} observableFactory Observable factory function to invoke for each observer that subscribes to the resulting sequence or Promise. * @returns {Observable} An observable sequence whose observers trigger an invocation of the given observable factory function. */ defer<T>(observableFactory: () => ObservableOrPromise<T>): Observable<T>; } export interface ObservableStatic { /** * Returns an empty observable sequence, using the specified scheduler to send out the single OnCompleted message. * * @example * var res = Rx.Observable.empty(); * var res = Rx.Observable.empty(Rx.Scheduler.timeout); * @param {Scheduler} [scheduler] Scheduler to send the termination call on. * @returns {Observable} An observable sequence with no elements. */ empty<T>(scheduler?: IScheduler): Observable<T>; } export interface ObservableStatic { /** * This method creates a new Observable sequence from an array-like or iterable object. * @param {Any} arrayLike An array-like or iterable object to convert to an Observable sequence. * @param {Function} [mapFn] Map function to call on every element of the array. * @param {Any} [thisArg] The context to use calling the mapFn if provided. * @param {Scheduler} [scheduler] Optional scheduler to use for scheduling. If not provided, defaults to Scheduler.currentThread. */ from<T>(array: ArrayOrIterable<T>): Observable<T>; /** * This method creates a new Observable sequence from an array-like or iterable object. * @param {Any} arrayLike An array-like or iterable object to convert to an Observable sequence. * @param {Function} [mapFn] Map function to call on every element of the array. * @param {Any} [thisArg] The context to use calling the mapFn if provided. * @param {Scheduler} [scheduler] Optional scheduler to use for scheduling. If not provided, defaults to Scheduler.currentThread. */ from<T, TResult>(array: ArrayOrIterable<T>, mapFn: (value: T, index: number) => TResult, thisArg?: any, scheduler?: IScheduler): Observable<TResult>; } export interface ObservableStatic { /** * Converts an array to an observable sequence, using an optional scheduler to enumerate the array. * @deprecated use Observable.from or Observable.of * @param {Scheduler} [scheduler] Scheduler to run the enumeration of the input sequence on. * @returns {Observable} The observable sequence whose elements are pulled from the given enumerable sequence. */ fromArray<T>(array: ArrayLike<T>, scheduler?: IScheduler): Observable<T>; } export interface ObservableStatic { /** * Generates an observable sequence by running a state-driven loop producing the sequence's elements, using the specified scheduler to send out observer messages. * * @example * var res = Rx.Observable.generate(0, function (x) { return x < 10; }, function (x) { return x + 1; }, function (x) { return x; }); * var res = Rx.Observable.generate(0, function (x) { return x < 10; }, function (x) { return x + 1; }, function (x) { return x; }, Rx.Scheduler.timeout); * @param {Mixed} initialState Initial state. * @param {Function} condition Condition to terminate generation (upon returning false). * @param {Function} iterate Iteration step function. * @param {Function} resultSelector Selector function for results produced in the sequence. * @param {Scheduler} [scheduler] Scheduler on which to run the generator loop. If not provided, defaults to Scheduler.currentThread. * @returns {Observable} The generated sequence. */ generate<TState, TResult>(initialState: TState, condition: (state: TState) => boolean, iterate: (state: TState) => TState, resultSelector: (state: TState) => TResult, scheduler?: IScheduler): Observable<TResult>; } export interface ObservableStatic { /** * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments. * @returns {Observable} The observable sequence whose elements are pulled from the given arguments. */ of<T>(...values: T[]): Observable<T>; /** * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments. * @param {Scheduler} scheduler A scheduler to use for scheduling the arguments. * @returns {Observable} The observable sequence whose elements are pulled from the given arguments. */ ofWithScheduler<T>(scheduler?: IScheduler, ...values: T[]): Observable<T>; } export interface ArrayObserveChange<T> { type: string; object: T[]; name?: string; oldValue?: T; index?: number; removed?: T[]; added?: number; } export interface ObservableStatic { /** * Creates an Observable sequence from changes to an array using Array.observe. * @param {Array} array An array to observe changes. * @returns {Observable} An observable sequence containing changes to an array from Array.observe. */ ofArrayChanges<T>(obj: T[]): Observable<ArrayObserveChange<T>>; } export interface ObjectObserveChange<T> { type: string; object: T; name: string; oldValue?: any; } export interface ObservableStatic { /** * Creates an Observable sequence from changes to an object using Object.observe. * @param {Object} obj An object to observe changes. * @returns {Observable} An observable sequence containing changes to an object from Object.observe. */ ofObjectChanges<T>(obj: T): Observable<ObjectObserveChange<T>>; } export interface ObservableStatic { /** * Returns a non-terminating observable sequence, which can be used to denote an infinite duration (e.g. when using reactive joins). * @returns {Observable} An observable sequence whose observers will never get called. */ never<T>(): Observable<T>; } export interface ObservableStatic { /** * Convert an object into an observable sequence of [key, value] pairs. * @param {Object} obj The object to inspect. * @param {Scheduler} [scheduler] Scheduler to run the enumeration of the input sequence on. * @returns {Observable} An observable sequence of [key, value] pairs from the object. */ pairs<T>(obj: { [key: string]: T }, scheduler?: IScheduler): Observable<[string, T]>; /** * Convert an object into an observable sequence of [key, value] pairs. * @param {Object} obj The object to inspect. * @param {Scheduler} [scheduler] Scheduler to run the enumeration of the input sequence on. * @returns {Observable} An observable sequence of [key, value] pairs from the object. */ pairs<T>(obj: { [key: number]: T }, scheduler?: IScheduler): Observable<[number, T]>; } export interface ObservableStatic { /** * Generates an observable sequence of integral numbers within a specified range, using the specified scheduler to send out observer messages. * * @example * var res = Rx.Observable.range(0, 10); * var res = Rx.Observable.range(0, 10, Rx.Scheduler.timeout); * @param {Number} start The value of the first integer in the sequence. * @param {Number} count The number of sequential integers to generate. * @param {Scheduler} [scheduler] Scheduler to run the generator loop on. If not specified, defaults to Scheduler.currentThread. * @returns {Observable} An observable sequence that contains a range of sequential integral numbers. */ range(start: number, count: number, scheduler?: IScheduler): Observable<number>; } export interface ObservableStatic { /** * Generates an observable sequence that repeats the given element the specified number of times, using the specified scheduler to send out observer messages. * * @example * var res = Rx.Observable.repeat(42); * var res = Rx.Observable.repeat(42, 4); * 3 - res = Rx.Observable.repeat(42, 4, Rx.Scheduler.timeout); * 4 - res = Rx.Observable.repeat(42, null, Rx.Scheduler.timeout); * @param {Mixed} value Element to repeat. * @param {Number} repeatCount [Optiona] Number of times to repeat the element. If not specified, repeats indefinitely. * @param {Scheduler} scheduler Scheduler to run the producer loop on. If not specified, defaults to Scheduler.immediate. * @returns {Observable} An observable sequence that repeats the given element the specified number of times. */ repeat<T>(value: T, repeatCount?: number | void, scheduler?: IScheduler): Observable<T>; } export interface ObservableStatic { /** * Returns an observable sequence that contains a single element, using the specified scheduler to send out observer messages. * There is an alias called 'just' or browsers <IE9. * @param {Mixed} value Single element in the resulting observable sequence. * @param {Scheduler} scheduler Scheduler to send the single element on. If not specified, defaults to Scheduler.immediate. * @returns {Observable} An observable sequence containing the single specified element. */ return<T>(value: T, scheduler?: IScheduler): Observable<T>; /** * Returns an observable sequence that contains a single element, using the specified scheduler to send out observer messages. * There is an alias called 'just' or browsers <IE9. * @param {Mixed} value Single element in the resulting observable sequence. * @param {Scheduler} scheduler Scheduler to send the single element on. If not specified, defaults to Scheduler.immediate. * @returns {Observable} An observable sequence containing the single specified element. */ just<T>(value: T, scheduler?: IScheduler): Observable<T>; } export interface ObservableStatic { /** * Returns an observable sequence that terminates with an exception, using the specified scheduler to send out the single onError message. * @param {Mixed} error An object used for the sequence's termination. * @param {Scheduler} scheduler Scheduler to send the exceptional termination call on. If not specified, defaults to Scheduler.immediate. * @returns {Observable} The observable sequence that terminates exceptionally with the specified exception object. */ throw<T>(exception: Error, scheduler?: IScheduler): Observable<T>; /** * Returns an observable sequence that terminates with an exception, using the specified scheduler to send out the single onError message. * @param {Mixed} error An object used for the sequence's termination. * @param {Scheduler} scheduler Scheduler to send the exceptional termination call on. If not specified, defaults to Scheduler.immediate. * @returns {Observable} The observable sequence that terminates exceptionally with the specified exception object. */ throw<T>(exception: any, scheduler?: IScheduler): Observable<T>; } export interface ObservableStatic { /** * Constructs an observable sequence that depends on a resource object, whose lifetime is tied to the resulting observable sequence's lifetime. * @param {Function} resourceFactory Factory function to obtain a resource object. * @param {Function} observableFactory Factory function to obtain an observable sequence that depends on the obtained resource. * @returns {Observable} An observable sequence whose lifetime controls the lifetime of the dependent resource object. */ using<TSource, TResource extends IDisposable>(resourceFactory: () => TResource, observableFactory: (resource: TResource) => Observable<TSource>): Observable<TSource>; } export interface Observable<T> { /** * Propagates the observable sequence or Promise that reacts first. * @param {Observable} rightSource Second observable sequence or Promise. * @returns {Observable} {Observable} An observable sequence that surfaces either of the given sequences, whichever reacted first. */ amb(observable: ObservableOrPromise<T>): Observable<T>; } export interface ObservableStatic { /** * Propagates the observable sequence or Promise that reacts first. * @returns {Observable} An observable sequence that surfaces any of the given sequences, whichever reacted first. */ amb<T>(observables: ObservableOrPromise<T>[]): Observable<T>; /** * Propagates the observable sequence or Promise that reacts first. * @returns {Observable} An observable sequence that surfaces any of the given sequences, whichever reacted first. */ amb<T>(...observables: ObservableOrPromise<T>[]): Observable<T>; } export interface Observable<T> { /** * Continues an observable sequence that is terminated by an exception with the next observable sequence. * @param {Mixed} handlerOrSecond Exception handler function that returns an observable sequence given the error that occurred in the first sequence, or a second observable sequence used to produce results when an error occurred in the first sequence. * @returns {Observable} An observable sequence containing the first sequence's elements, followed by the elements of the handler sequence in case an exception occurred. */ catch(handler: (exception: any) => ObservableOrPromise<T>): Observable<T>; /** * Continues an observable sequence that is terminated by an exception with the next observable sequence. * @param {Mixed} handlerOrSecond Exception handler function that returns an observable sequence given the error that occurred in the first sequence, or a second observable sequence used to produce results when an error occurred in the first sequence. * @returns {Observable} An observable sequence containing the first sequence's elements, followed by the elements of the handler sequence in case an exception occurred. */ catch(second: ObservableOrPromise<T>): Observable<T>; } export interface ObservableStatic { /** * Continues an observable sequence that is terminated by an exception with the next observable sequence. * @param {Array | Arguments} args Arguments or an array to use as the next sequence if an error occurs. * @returns {Observable} An observable sequence containing elements from consecutive source sequences until a source sequence terminates successfully. */ catch<T>(sources: ObservableOrPromise<T>[]): Observable<T>; /** * Continues an observable sequence that is terminated by an exception with the next observable sequence. * @param {Array | Arguments} args Arguments or an array to use as the next sequence if an error occurs. * @returns {Observable} An observable sequence containing elements from consecutive source sequences until a source sequence terminates successfully. */ catch<T>(...sources: ObservableOrPromise<T>[]): Observable<T>; } export interface Observable<T> { /** * Merges the specified observable sequences into one observable sequence by using the selector function whenever any