UNPKG

@iotize/tap-scripts

Version:

IoTize Tap scripts

102 lines (101 loc) 3.18 kB
import { Tap, TapResponse } from '@iotize/tap'; import { Observable, Observer } from 'rxjs'; import { DisplayFunction, InstructionListType, LogLevel, ScriptRunnerEvent } from './definitions'; import { OutputFunction } from './instructions/output-instruction'; import { TestRunnerContextInterface } from './test-runner-context-interface'; export interface ScriptRunnerIO { output: OutputFunction; display: DisplayFunction; } export declare type ErrorHandler = (error: Error) => void; /** * */ export declare class TestRunnerContext implements TestRunnerContextInterface { device: Tap; instructions: InstructionListType; io: { display: DisplayFunction; output: OutputFunction; }; _lastLwm2mGetResponse?: TapResponse<any>; lastLwm2mResponse?: TapResponse<any>; protected _labels: { [label: string]: number; }; protected current: number; protected resultCode: number | null; protected _data: { [key: string]: any; }; protected _running: boolean; protected _observer?: Observer<ScriptRunnerEvent>; nextChanged: boolean; store(key: any, value?: any): any; get labels(): { [label: string]: number; }; set lastLwm2mGetResponse(r: TapResponse<any> | undefined); get lastLwm2mGetResponse(): TapResponse<any>; errorHandler: ErrorHandler | undefined; constructor(device: Tap, instructions: InstructionListType, io: { display: DisplayFunction; output: OutputFunction; }); /** * Resume script execution */ continue(): Promise<void>; runAll(): Observable<ScriptRunnerEvent>; isRunning(): boolean; /** * Pause script execution */ stop(): void; /** * Return true script execution is finished */ isEnded(): boolean; getCurrentIndex(): number; setNextIndex(index: number): void; runCurrent(): Promise<void>; /** * Run instruction at given index * @param index */ runOne(index: number): Promise<any>; next(): Promise<void>; /** * TODO use result code */ end(resultCode?: number): void; onError(err: Error): Promise<void>; mapLabel(name: string, value: number): void; getLabel(name: string): number | undefined; private safeRunOne; } export declare function OutputToLogFunction(response: TapResponse<any> | undefined): void; export declare function DisplayToLogFunction(logLevel: LogLevel, message: string): void; /** * Script runner * */ export declare class ScriptRunner { protected io: ScriptRunnerIO; protected _errorHandler?: ErrorHandler; context?: TestRunnerContext; constructor(io?: ScriptRunnerIO); /** * Configure error handler */ set errorHandler(handler: ErrorHandler | undefined); get errorHandler(): ErrorHandler | undefined; isRunning(): boolean; /** * Run script instructions * @param instructions * @param device */ run(instructions: InstructionListType, device: Tap): Observable<ScriptRunnerEvent>; stop(): void; }