View Source DenoEx.Pipe (DenoEx v0.5.0)

The DenoEx pipe.

This module defines a struct and the main functions for working with deno pipes and their responses.

Summary

Types

arguments for deno

status of the pipe

t()

Elixir.DenoEx.Pipe

Functions

returns if the pipe is finished running or not

Initializes a deno pipe with everything needed to run a deno script.

get the buffer from the desired datastream

Executes the deno pipe in another process and sets up to monitor the results.

Sends data to a running process

returns the exit code of a finished pipe

Waits for a pipe to finish and collects the results.

Types

@type options() ::
  keyword(
    {:deno_location, binary()}
    | {:allow_env, boolean() | [binary()]}
    | {:allow_sys, boolean() | [binary()]}
    | {:allow_net, boolean() | [binary()]}
    | {:allow_hrtime, boolean()}
    | {:allow_ffi, boolean() | [binary()]}
    | {:allow_run, boolean() | [binary()]}
    | {:allow_write, boolean() | [binary()]}
    | {:allow_read, boolean() | [binary()]}
    | {:allow_all, boolean()}
    | {:no_remote, boolean()}
    | {:import_map, binary()}
    | {:lock, binary()}
    | {:cached_only, boolean()}
  )

arguments for deno

@type status() ::
  :initialized | :running | {:exited, :normal | pos_integer()} | :timeout

status of the pipe

@opaque t()

Elixir.DenoEx.Pipe

@opaque t(status)

Functions

@spec finished?(t(status())) :: boolean()

returns if the pipe is finished running or not

Link to this function

new(script, script_args \\ [], options \\ [])

View Source
@spec new(DenoEx.script(), DenoEx.script_arguments(), options()) ::
  t(:initialized) | {:error, String.t()}

Initializes a deno pipe with everything needed to run a deno script.

## Options

  • :deno_location (String.t/0) - Sets the path where the deno executable is located.

Note: It does not include the deno executable. If the executable is located at /usr/bin/deno then the deno_location should be /usr/bin.

  • :allow_env - Allows read and write access to environment variables.

    true: allows full access to the environment variables

    [String.t()]: allows access to only the subset of variables in the list.

  • :allow_sys - Allows access to APIs that provide system information. i.e. hostname, memory usage

    true: allows full access

    [String.t()]: allows access to only the subset calls. hostname, osRelease, osUptime, loadavg, networkInterfaces, systemMemoryInfo, uid, and gid

  • :allow_net - Allows network access.

    true: allows full access to the network

    [String.t()]: allows access to only the network connections specified ie. 127.0.0.1:4000, 127.0.0.1, :4001

  • :allow_hrtime (boolean/0) - Allows high-resolution time measurement. High-resolution time can be used in timing attacks and fingerprinting.

  • :allow_ffi - Allow loading of dynamic libraries.

    WARNING:

    Be aware that dynamic libraries are not run in a sandbox and therefore do not have the same security restrictions as the Deno process. Therefore, use it with caution.

    true: allows all dlls to be accessed

    [Path.t()]: A list of paths to dlls that will be accessible

  • :allow_run - Allow running subprocesses.

    WARNING

    Be aware that subprocesses are not run in a sandbox and therefore do not have the same security restrictions as the Deno process. Therefore, use it with caution.

    true: allows all subprocesses to be run

    [Path.t()]: A list of subprocesses to run

  • :allow_write - Allow the ability to write files.

    true: allows all files to be written

    [Path.t()]: A list of files that can be written

  • :allow_read - Allow the ability to read files.

    true: allows all files to be read

    [Path.t()]: A list of files that can be read

  • :allow_all (boolean/0) - Turns on all options and bypasses all security measures

  • :no_remote (boolean/0) - Disallows installing of imports from remote locations

  • :import_map (String.t/0) - The location of the import map json file for finding vendored dependencies

  • :lock (String.t/0) - The location of the lock file for running scripts

  • :cached_only (boolean/0) - Only allows chaced dependencies to be used

    Please refer to Deno Permissions for more details.

Examples

 iex> DenoEx.Pipe.new({:file, Path.join(~w[test support hello.ts])})
 #DenoEx.Pipe<status: :initialized, ...>

 iex> DenoEx.Pipe.new({:file, Path.join(~w[test support args_echo.ts])}, ~w[foo bar])
 #DenoEx.Pipe<status: :initialized, ...>
@spec output(t(status())) :: [String.t()]

get the buffer from the desired datastream

@spec run(t(:initialized)) :: t(:running)

Executes the deno pipe in another process and sets up to monitor the results.

While running a Deno.Pipe sends messages back to the calling process.

Examples

 iex> DenoEx.Pipe.new({:file, Path.join(~w[test support hello.ts])}) |> DenoEx.Pipe.run()
 #DenoEx.Pipe<status: :running, ...>
@spec send(t(:running), binary()) :: :ok

Sends data to a running process

@spec status(t(status())) :: status()

returns the exit code of a finished pipe

Link to this function

yield(pipe, timeout \\ :timer.seconds(5))

View Source
@spec yield(t(:running), timeout()) ::
  {:ok, t({:exit, :normal})}
  | {:error, t({:exit, pos_integer()})}
  | {:timeout, t(:timeout)}

Waits for a pipe to finish and collects the results.

Examples

 iex> {:ok, pipe} = DenoEx.Pipe.new({:file, Path.join(~w[test support hello.ts])}) |> DenoEx.Pipe.run() |> DenoEx.Pipe.yield()
 iex> pipe
 #DenoEx.Pipe<status: {:exit, :normal}, ...>

 iex> {:timeout, pipe} = DenoEx.Pipe.new({:file, Path.join(~w[test support hello.ts])}) |> DenoEx.Pipe.run() |> DenoEx.Pipe.yield(1)
 iex> pipe
 #DenoEx.Pipe<status: :timeout, ...>