View Source DenoEx (DenoEx v0.3.0)

DenoEx is used to run javascript and typescript files in a safe environment by utilizing Deno.

basics

Basics

configuration

Configuration

Configuration of the deno installation directory can be set in a few ways. We can use an environment variable, application config, or pass it directly to the run command. The different configurations are there to facilitate different working situations. The priorities are function options > application configuration > environment.

function-option

Function Option

 iex> DenoEx.run({:file, Path.join(~w[test support hello.ts])}, [], [deno_location: "/Users/akoutmos/Documents/opensource/deno_ex/_build/dev/lib/deno_ex/priv/bin"])
 {:ok, "Hello, world.\n"}

application-configuration

Application Configuration

 import Config

 config :deno_ex,
   exectutable_location: Path.join(~w[path containing deno])

env-variable

ENV Variable

DENO_LOCATION=path

Link to this section Summary

Types

The arguments for deno

The path to the script that should be executed, or a tuple denoting what should be passed to the Deno executable over STDIN.

The list of arguements to be passed to the script

Functions

Returns the location where the deno script is expected to be located.

Link to this section Types

@type options() :: DenoEx.Pipe.options()

The arguments for deno

@type script() :: {:file, Path.t()} | {:stdin, IO.chardata()}

The path to the script that should be executed, or a tuple denoting what should be passed to the Deno executable over STDIN.

@type script_arguments() :: [String.t()]

The list of arguements to be passed to the script

Link to this section Functions

@spec executable_location() :: String.t()

Returns the location where the deno script is expected to be located.

Link to this function

run(script, script_arguments \\ [], options \\ [], timeout \\ :timer.seconds(5))

View Source
@spec run(script(), script_arguments(), options(), timeout()) ::
  {:ok | :error, String.t()}

Uses deno run to run a Deno script.

options

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

    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-1

    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

    Please refer to Deno Permissions for more details.

examples

Examples

 iex> DenoEx.run({:file, Path.join(~w[test support hello.ts])})
 {:ok, "Hello, world.\n"}

 iex> DenoEx.run({:file, Path.join(~w[test support args_echo.ts])}, ~w[foo bar])
 {:ok, "foo bar\n"}

 iex> DenoEx.run({:stdin, "console.log(\"Hello, world.\")"})
 {:ok, "Hello, world.\n"}