Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Basha

Hierarchy

  • Listener
    • Basha

Index

Constructors

constructor

  • new Basha(servers?: Server[]): Basha
  • Parameters

    • Default value servers: Server[] = [new StdioServer({ command: 'node', args: [__filename, 'start'] }),]

    Returns Basha

Properties

Readonly id

id: string

The unique id of this executor.

Used for better tracing and to avoid duplicate entries for an executor (e.g. due to having multiple servers and therefore multiple addresses)

Private isReady

isReady: boolean = false

Is Bash ready for more input?

Private isStopping

isStopping: boolean = false

Flag to mute log errors when this interpreter is explicitly stop()ed

Protected Optional job

job: undefined | string

The id of the current job.

Used to enable cancellation of jobs by checking that the job being cancelled is the current one.

Private lock

lock: AsyncLock = new AsyncLock()

A lock to prevent async event loops from attempting to enter code into the terminal at the same time.

Private Optional output

output: undefined | string

Output from entering the last Bash input.

Used to buffer output from the pseudo-terminal.

Readonly programmingLanguages

programmingLanguages: string[] = ['bash', 'sh']

Programming language names supported by this interpreter.

Readonly prompt

prompt: "🔨 BASHA > " = "🔨 BASHA > "

The prompt used to identify when the pseudo- terminal has finished executing and is ready for more input.

Protected servers

servers: Server[]

Servers that will listen on behalf of this executor and pass on requests to it.

Protected Optional terminal

terminal: pty.IPty

The pseudo-terminal in which bash is executed.

Readonly timelimit

timelimit: number

Maximum time that the process will run.

Readonly timeout

timeout: number

Seconds of inactivity after which the listener stops.

Private Optional whenReady

whenReady: undefined | (() => void)

Function to call when Bash is ready

Methods

addresses

  • addresses(): Promise<Addresses>
  • implements

    Implements {@link Executor.addresses}.

    description

    Combines the server addresses for this executor into a single Addresses object.

    Returns Promise<Addresses>

begin

  • begin<Type>(node: Type, claims?: Claims): Promise<Type>
  • Begin running a Node.

    This method keeps a document "running", usually to allow it to react to changes within it. Compare this to execute() which will not wait and will simply execute all nodes in the document. The document will keep running until the end() method is called on it.

    Usually this method is called with a SoftwareSession as the node argument. However, it could also be called with another Node type, e.g. an Article, in which case the executor may begin it's session property, or default session if that property is missing.

    Type parameters

    • Type: schema.Node

    Parameters

    • node: Type

      The node to run, usually but not necessarily, a SoftwareSession

    • Optional claims: Claims

      The Claims made for the call

    Returns Promise<Type>

    The node, with updated properties, after it has begun running

build

  • build<Type>(node: Type): Promise<Type>
  • Build a Node.

    Type parameters

    • Type: schema.Node

    Parameters

    • node: Type

      The node to build

    Returns Promise<Type>

    The build node

call

  • call<Type>(method: Method, params: Params): Promise<Type>
  • A fallback implementation of one of the above methods.

    Since this base executor has no capabilities, this method simply throws a CapabilityError. Derived classes, may override this method, and /or one of the methods above.

    Provided so that derived classes such as Client, Delegator and Queuer can override a single method to provide their functionality instead of having to implement each of the above methods.

    Type parameters

    • Type

    Parameters

    • method: Method

      The name of the method

    • params: Params

      Values of parameters (i.e. arguments)

    Returns Promise<Type>

cancel

  • cancel(job: string): Promise<boolean>
  • override

    Override of Executor.cancel that cancels the current job only.

    Parameters

    • job: string

    Returns Promise<boolean>

capabilities

  • capabilities(): Promise<Capabilities>
  • override

    Override of Executor.capabilities to define this interpreter's capabilities.

    Returns Promise<Capabilities>

compile

  • compile<Type>(node: Type): Promise<Type>
  • Compile a Node.

    Type parameters

    • Type: schema.Node

    Parameters

    • node: Type

      The node to compile

    Returns Promise<Type>

    The compiled node

decode

  • decode(source: string, format?: undefined | string): Promise<schema.Node>
  • Decode content to a Node.

    Parameters

    • source: string

      The source of the content to decode

    • Optional format: undefined | string

      The format of the content

    Returns Promise<schema.Node>

    The decoded node

dispatch

  • dispatch(method: Method, params?: Params): Promise<any>
  • override

    Override of {@link Executor.dispatch} to update heartbeat with current time.

    Parameters

    • method: Method
    • Optional params: Params

    Returns Promise<any>

encode

  • encode(node: schema.Node, dest?: undefined | string, format?: undefined | string): Promise<string>
  • Encode a Node in a format.

    Parameters

    • node: schema.Node

      The node to encode

    • Optional dest: undefined | string

      The destination for the encoded content

    • Optional format: undefined | string

      The format to encode

    Returns Promise<string>

    The encoded content, or the destination of the content.

end

  • end<Type>(node: Type, claims?: Claims): Promise<Type>
  • End running a Node.

    Type parameters

    • Type: schema.Node

    Parameters

    • node: Type

      The running node, usually but not necessarily, a SoftwareSession

    • Optional claims: Claims

      The Claims made for the call

    Returns Promise<Type>

    The node, with updated properties, after it has ended running

enterCode

  • enterCode(code: string): Promise<string | undefined>
  • Enter Bash code into the terminal and set up handler to process output.

    Parameters

    • code: string

      Code to enter.

    Returns Promise<string | undefined>

    A promise resolving to the output.

execute

  • execute<Type>(node: Type, session?: schema.SoftwareSession, claims?: Claims, job?: undefined | string): Promise<Type>
  • override

    Override of Executor.execute that executes Bash code.

    Calculates the duration of the execution to the nearest microsecond.

    Type parameters

    • Type

    Parameters

    • node: Type
    • Optional session: schema.SoftwareSession
    • Optional claims: Claims
    • Optional job: undefined | string

    Returns Promise<Type>

executeCode

  • executeCode(code: string): Promise<unknown | undefined>
  • Execute Bash code.

    This method enters the code, parses the output and checks the exit code. If the exit code is non-zero it throws an error with the output.

    Parameters

    • code: string

      Code to execute

    Returns Promise<unknown | undefined>

    A promise resolving to the output from the command.

manifest

  • manifest(): Promise<Manifest>
  • Get the manifest of the executor.

    see

    {@link Capabilities}

    see

    {@link Addresses}

    Returns Promise<Manifest>

notified

  • notified(level: string, message: string, node?: schema.Node): void
  • override

    Override of {@link Executor.notify} to update heartbeat with current time.

    Parameters

    • level: string
    • message: string
    • Optional node: schema.Node

    Returns void

notify

  • notify(level: string, message: string, node?: schema.Node, clients?: string[]): Promise<void>
  • implements

    {Executor.notify}

    Send a notification to clients via each of this executor's servers

    Parameters

    • level: string
    • message: string
    • Optional node: schema.Node
    • Optional clients: string[]

    Returns Promise<void>

parseOutput

  • parseOutput(output: string): unknown
  • Parse output from a command.

    Attempts to parse the output as JSON. In the future, more advanced parsing such as parsing of fixed-width tables may be done.

    Parameters

    • output: string

      Output string to parse

    Returns unknown

pipe

  • pipe(node: schema.Node, calls: (Method | [Method, Params])[]): Promise<schema.Node>
  • Call a pipeline of methods passing the result of each call as the first argument of the next call.

    This method is a "meta" method that is used to chain together calls to other methods. When using a remote executor, it is more efficient than chaining those calls together "by hand" because it only involves one round trip request to the executor.

    Parameters

    • node: schema.Node

      The node to pipe through methods

    • calls: (Method | [Method, Params])[]

      A list of method, parameters tuples to pipe the node through

    Returns Promise<schema.Node>

    The node after it has been piped through the methods

query

  • query(node: schema.Node, query: string, lang: string): Promise<schema.Node>
  • Query a Node.

    Currently allows for two query languages:

    Parameters

    • node: schema.Node
    • query: string
    • lang: string

    Returns Promise<schema.Node>

register

  • register(): Promise<string>
  • Register this listener so that it can be discovered by other executors.

    Returns Promise<string>

    The path to the registration file.

run

  • run(): Promise<void>
  • Run this executor

    Starts listening with graceful shutdown on SIGINT or SIGTERM, and checking for timeout (if set).

    see

    {@link Server.run}

    Returns Promise<void>

start

  • start(servers?: Server[]): Promise<void>
  • Start listening by starting all servers.

    Parameters

    • Optional servers: Server[]

      Any additional servers to start.

    Returns Promise<void>

startBash

  • startBash(): IPty
  • Start a Bash shell process.

    Creates a pseudo-terminal and registers event handles on it to capture output and handle unexpected exit.

    Returns IPty

stop

  • stop(): Promise<void>
  • override

    Override of Listener.stop to stop the pseudo-terminal as well as servers.

    Returns Promise<void>

Generated using TypeDoc