UNPKG

@ha4us/script.adapter

Version:

Scripting Adapter for the ha4us

65 lines (64 loc) 2.07 kB
/// <reference types="node" /> import * as vm from 'vm'; import * as domain from 'domain'; import { Subject } from 'rxjs'; import { Ha4usObject, Ha4usLogger } from '@ha4us/core'; import { StateService, ObjectService, YamlService, Ha4usArguments, MediaService } from '@ha4us/adapter'; import { Sandbox } from './sandbox.class'; export declare enum ScriptEventType { Error = "error", Log = "log", State = "state" } export declare class ScriptEvent { readonly name: string; readonly type: ScriptEventType; data?: any; constructor(name: string, type: ScriptEventType, data?: any); } export declare type Severity = 'debug' | 'info' | 'warn' | 'error'; export declare class LogEvent { readonly severity: Severity; readonly message: string; readonly attachments?: any[]; constructor(severity: Severity, message: string, attachments?: any[]); } export declare type Status = 'stopped' | 'running' | 'error'; export interface ScriptOptions { $args: Ha4usArguments; $log: Ha4usLogger; $yaml: YamlService; $states: StateService; $objects: ObjectService; $media: MediaService; } export declare class Ha4usScript { opts: ScriptOptions; readonly name: string; readonly topic: string; readonly path: string; autostart: boolean; _source: string; source: string; sandbox: Sandbox; domain: domain.Domain; script: vm.Script; result: any; _status: Status; status: Status; status$: Subject<Status>; log$: Subject<LogEvent>; $log: Ha4usLogger; constructor(scriptObject: Ha4usObject, opts: ScriptOptions); log(severity: Severity, msg: string, attachments?: any[]): void; prepareStack(e: Error, match: RegExp): string; init(): Promise<Ha4usScript>; protected transpile(source: string): Promise<string>; compile(): Promise<Ha4usScript>; enterDomain(): void; start(): Promise<Ha4usScript>; stop(): Promise<Ha4usScript>; restart(): Promise<this>; destroy(): Promise<Ha4usScript>; toHa4usObject(): Partial<Ha4usObject>; }