nomad

@lacrypta/nomad v0.0.0 / VM

Interface: VM

A safe execution environment for NOMAD code execution.

Extends

Accessors

isBooting

get isBooting(): boolean

Getter used to determine if the VM is in the “booting” state.

Returns

boolean

Defined in

vm.ts:102


isCreated

get isCreated(): boolean

Getter used to determine if the VM is in the “created” state.

Returns

boolean

Defined in

vm.ts:108


isRunning

get isRunning(): boolean

Getter used to determine if the VM is in the “running” state.

Returns

boolean

Defined in

vm.ts:114


isStopped

get isStopped(): boolean

Getter used to determine if the VM is in the “stopped” state.

Returns

boolean

Defined in

vm.ts:120


isStopping

get isStopping(): boolean

Getter used to determine if the VM is in the “stopping” state.

Returns

boolean

Defined in

vm.ts:126


name

get name(): string

Getter used to retrieve the VM’s name.

Returns

string

Defined in

vm.ts:132

Methods

createEnclosure()

createEnclosure(enclosure: string): Promise<Enclosure>

Create a new enclosure with the given name.

Parameters

enclosure: string

Enclosure to create.

Returns

Promise<Enclosure>

A Promise that resolves with a Enclosure wrapper if enclosure creation completed successfully, and rejects with an Error in case errors occur.

Defined in

vm.ts:66


deleteEnclosure()

deleteEnclosure(enclosure: string): Promise<string[]>

Delete the enclosure with the given name.

This method will reject all tunnels awaiting responses on the given enclosure.

Parameters

enclosure: string

Enclosure to delete.

Returns

Promise<string[]>

A Promise that resolves with a list of deleted enclosures (the one given and any sub enclosures of it) if enclosure deletion completed successfully, and rejects with an Error in case errors occur.

Defined in

vm.ts:76


emit()

emit(
   enclosure: string, 
   event: string, ...
   args: AnyArgs): this

Emit an event towards the VMWorker.

Parameters

enclosure: string

Enclosure to use.

event: string

Event name to emit.

• …args: AnyArgs

Associated arguments to emit alongside the event.

Returns

this

this, for chaining.

Defined in

vm.ts:86


execute()

execute(
   enclosure: string, 
   dependency: Dependency, 
args?: ArgumentsMap): Promise<unknown>

Execute the given Dependency with the given arguments map in the VMWorker.

Parameters

enclosure: string

The enclosure to use.

dependency: Dependency

The Dependency to execute.

args?: ArgumentsMap

The arguments map to execute with.

Returns

Promise<unknown>

A Promise that resolves with the Dependency’s execution result, and rejects with an Error in case errors occurred.

Defined in

vm.ts:96


getSubEnclosures()

getSubEnclosures(enclosure: string, depth?: number): Promise<string[]>

List the given enclosure’s sub enclosures.

Parameters

enclosure: string

Enclosure to list the sub enclosures of.

depth?: number

Maximum enclosure depth to retrieve results for, defaults to retrieving all.

Returns

Promise<string[]>

A Promise that resolves with a list of sub enclosures enclosures if successful, and rejects with an Error in case errors occur.

Defined in

vm.ts:141


install()

install(enclosure: string, dependency: Dependency): Promise<void>

Install the given Dependency on the VMWorker.

Parameters

enclosure: string

Enclosure to use.

dependency: Dependency

The Dependency to install.

Returns

Promise<void>

A Promise that resolves with void if the Dependency was correctly installed, and rejects with an Error in case errors occurred.

Defined in

vm.ts:150


installAll()

installAll(enclosure: string, dependencies: Iterable<Dependency>): Promise<void>

Install the given Dependency iterable, by sorting them topologically and installing each one in turn.

Parameters

enclosure: string

Enclosure to use.

dependencies: Iterable<Dependency>

Dependencies to install.

Returns

Promise<void>

A Promise that resolves with void if every Dependency in the iterable was correctly installed, and rejects with an Error in case errors occurred.

Defined in

vm.ts:159


isMuted()

isMuted(enclosure: string): Promise<boolean>

Determine whether the given enclosure is muted.

Parameters

enclosure: string

Enclosure to determine mute status of.

Returns

Promise<boolean>

A Promise that resolves with a boolean value indicating whether the enclosure is muted if successful, and rejects with an Error in case errors occur.

Defined in

vm.ts:167


linkEnclosures()

linkEnclosures(enclosure: string, target: string): Promise<boolean>

Link one enclosure to another, so that events cast on the first are also handled in the second.

Parameters

enclosure: string

“Source” enclosure to use.

target: string

“Destination” enclosure to use.

Returns

Promise<boolean>

A Promise that resolves with a boolean value if enclosure linking completed successfully (the value itself determining if a new link was added), and rejects with an Error in case errors occur.

Defined in

vm.ts:176


listInstalled()

listInstalled(enclosure: string): Promise<string[]>

List the dependencies (user-level and predefined) installed on the given enclosure or its prefixes.

Parameters

enclosure: string

Enclosure to list installed dependencies of.

Returns

Promise<string[]>

A Promise that resolves with a list of installed dependency names if successful, and rejects with an Error in case errors occur.

Defined in

vm.ts:184


listLinkedFrom()

listLinkedFrom(enclosure: string): Promise<string[]>

List the enclosures that link to the given one.

Parameters

enclosure: string

Enclosure to list linked-from enclosures of.

Returns

Promise<string[]>

A Promise that resolves with a list of linked-from enclosures if successful, and rejects with an Error in case errors occur.

Defined in

vm.ts:192


listLinksTo()

listLinksTo(enclosure: string): Promise<string[]>

List the enclosures the given one is linked to.

Parameters

enclosure: string

Enclosure to list linked-to enclosures of.

Returns

Promise<string[]>

A Promise that resolves with a list of linked-to enclosures if successful, and rejects with an Error in case errors occur.

Defined in

vm.ts:200


listRootEnclosures()

listRootEnclosures(): Promise<string[]>

List the root enclosures created.

Returns

Promise<string[]>

A Promise that resolves with a list of root enclosures created if successful, and rejects with an Error in case errors occur.

Defined in

vm.ts:207


mergeEnclosure()

mergeEnclosure(enclosure: string): Promise<void>

Merge the given enclosure to its parent.

Parameters

enclosure: string

Enclosure to merge.

Returns

Promise<void>

A Promise that resolves with void if enclosure merging completed successfully, and rejects with an Error in case errors occur.

Defined in

vm.ts:215


muteEnclosure()

muteEnclosure(enclosure: string): Promise<boolean>

Mute the given enclosure, so that events cast on it are no longer propagated to this VM.

Parameters

enclosure: string

Enclosure to mute.

Returns

Promise<boolean>

A Promise that resolves with the previous muting status if enclosure muting completed successfully, and rejects with an Error in case errors occur.

Defined in

vm.ts:223


off()

off(callback: EventCallback): this

Remove the given callback from the listeners set.

Parameters

callback: EventCallback

The callback to remove.

Returns

this

this, for chaining.

Inherited from

EventCaster.off

Defined in

eventCaster.ts:120


on()

on(filter: string, callback: EventCallback): this

Attach the given callback to the EventCaster, triggered on events matching the given filter.

Parameters

filter: string

Event name filter to assign the listener to.

callback: EventCallback

Callback to call on a matching event being cast.

Returns

this

this, for chaining.

Inherited from

EventCaster.on

Defined in

eventCaster.ts:129


once()

once(filter: string, callback: EventCallback): this

Attach the given callback to the EventCaster, triggered on events matching the given filter, and removed upon being called once.

Parameters

filter: string

Event name filter to assign the listener to.

callback: EventCallback

Callback to call on a matching event being cast.

Returns

this

this, for chaining.

Inherited from

EventCaster.once

Defined in

eventCaster.ts:138


predefine()

predefine(
   enclosure: string, 
   name: string, 
callback: AnyFunction): Promise<void>

Add a predefined function to the VM’s list under the given enclosure.

Parameters

enclosure: string

Enclosure to use.

name: string

Function name to add.

callback: AnyFunction

Function callback to use.

Returns

Promise<void>

A Promise that resolves with void if the Function was correctly predefined, and rejects with an Error in case errors occurred.

Defined in

vm.ts:233


shutdown()

shutdown(timeout?: number): Promise<void>

Shut the VMWorker down.

Shutting a VM instance consists of the following:

  1. Emitting the “shutdown” event on the VMWorker.
  2. Waiting for the given timeout milliseconds.
  3. Removing all root enclosures.
  4. Calling VM.stop to finish the shutdown process.

Parameters

timeout?: number

Milliseconds to wait for the VMWorker to shut down.

Returns

Promise<void>

A Promise that resolves with void if the VMWorker was successfully shut down, and rejects with an Error in case errors are found.

Defined in

vm.ts:248


start()

start(
   workerCtor?: WorkerConstructor, 
   timeout?: number, 
rootEnclosure?: string): Promise<Enclosure>

Start the VMWorker and wait for its boot-up sequence to complete.

Starting a VM instance consists of the following:

  1. Initializing a VMWorker instance with the worker code.
  2. Setting up the boot timeout callback (in case the VMWorker takes too much time to boot).
  3. Setting up the event listeners for message, error, and messageerror.

Parameters

workerCtor?: WorkerConstructor

The Worker constructor to use in order to build the worker instance (will default to the Worker one if not given).

timeout?: number

Milliseconds to wait for the VMWorker to complete its boot-up sequence.

rootEnclosure?: string

Name of the root Enclosure to create.

Returns

Promise<Enclosure>

A Promise that resolves with a Enclosure wrapper for the default enclosure if the VMWorker was successfully booted up, and rejects with an Error in case errors occur.

Defined in

vm.ts:264


startPinger()

startPinger(pingInterval?: number, pongLimit?: number): this

Start (or re-start) the pinger interval.

Parameters

pingInterval?: number

Number of milliseconds to wait between pings to the worker.

pongLimit?: number

Maximum number of milliseconds between pong responses from the worker before declaring it unresponsive.

Returns

this

this, for chaining.

Defined in

vm.ts:273


stop()

stop(): Promise<void>

Stop the VMWorker immediately and reject all pending tunnels.

Stopping a Vm instance entails:

  1. Clearing the pinger.
  2. Calling VMWorker.kill on the VM’s VMWorker.
  3. Rejecting all existing tunnels.

Returns

Promise<void>

A Promise that resolves with void if the stopping procedure completed successfully, and rejects with an Error in case errors occur.

Defined in

vm.ts:286


stopPinger()

stopPinger(): this

Stop the pinger interval.

Returns

this

this, for chaining.

Defined in

vm.ts:293


unlinkEnclosures()

unlinkEnclosures(enclosure: string, target: string): Promise<boolean>

Unlink one enclosure from another, so that events cast on the first are no longer handled in the second.

Parameters

enclosure: string

“Source” enclosure to use.

target: string

“Destination” enclosure to use.

Returns

Promise<boolean>

A Promise that resolves with a boolean indicating whether the target enclosure was previously linked if enclosure unlinking completed successfully, and rejects with an Error in case errors occur.

Defined in

vm.ts:302


unmuteEnclosure()

unmuteEnclosure(enclosure: string): Promise<boolean>

Unmute the given enclosure, so that events cast on it are propagated to this VM.

Parameters

enclosure: string

Enclosure to unmute.

Returns

Promise<boolean>

A Promise that resolves with he previous muting status if enclosure un-muting completed successfully, and rejects with an Error in case errors occur.

Defined in

vm.ts:310