Immutable connection and resource context for a TerminusDB server.
A Config carries everything needed to address and authenticate a request:
the server :endpoint, credentials, and the current resource scope
(:organization, :database, :branch, :repo, :ref).
Unlike the official Python client — which holds mutable connection state on an
instance — TerminusDB.Config is immutable data. Scoping operations return
derived configs (with_database/2, with_branch/2, …) rather than mutating,
which is safe under concurrency and composes naturally with pipelines.
Options
:endpoint(String.t/0) - Required. TerminusDB server URL, e.g.http://localhost:6363.:user(String.t/0) - User name for HTTP Basic auth. Ignored when:tokenis set. The default value is"admin".:key(String.t/0) - API key / password for HTTP Basic auth. Ignored when:tokenis set. The default value is"root".:token(String.t/0) - Bearer token. When set, takes precedence over Basic auth (:user/:key).:organization(String.t/0) - Organization (team) that owns the database. The default value is"admin".:database(String.t/0) - Current database name. Set withwith_database/2.:branch(String.t/0) - Current branch. Set withwith_branch/2. The default value is"main".:repo(String.t/0) - Repository:localor a remote name. The default value is"local".:ref(String.t/0) - A commit reference for time-travel queries.:headers(map ofString.t/0keys andString.t/0values) - Extra HTTP headers merged into every request. The default value is%{}.:receive_timeout(pos_integer/0) - Socket receive timeout in milliseconds. The default value is15000.:telemetry(boolean/0) - Whether to emit:telemetryevents for operations. The default value istrue.:adapter(term/0) - A Req adapter function used in place of the network. Intended for testing:adapter: fn req -> {req, Req.Response.new(status: 200, body: %{})} end.:user_agent(String.t/0) - Value of theuser-agentrequest header. The default value is"terminusdb_ex/0.1.0".
Examples
iex> config = TerminusDB.Config.new(endpoint: "http://localhost:6363")
iex> config.endpoint
"http://localhost:6363"
iex> config.organization
"admin"
iex> config = TerminusDB.Config.new(endpoint: "http://localhost:6363", token: "tok_123")
iex> TerminusDB.Config.auth(config)
{:bearer, "tok_123"}
iex> config = TerminusDB.Config.new(endpoint: "http://localhost:6363")
iex> TerminusDB.Config.auth(config)
{:basic, "admin:root"}
Summary
Functions
Returns the Req auth tuple derived from config.
Returns a copy of config with the given fields updated.
Builds a new, validated TerminusDB.Config.
Returns config with sensitive fields redacted, suitable for telemetry metadata
and logging. Replaces :key and :token with "[redacted]".
Scopes config to the given branch.
Scopes config to the given database.
Scopes config to the given organization.
Pins config to a commit reference for time-travel queries.
Scopes config to the given repository (local or a remote name).
Types
@type t() :: %TerminusDB.Config{ adapter: (Req.Request.t() -> {Req.Request.t(), Req.Response.t()}) | nil, branch: String.t(), database: String.t() | nil, endpoint: String.t(), headers: %{required(String.t()) => String.t()}, key: String.t(), organization: String.t(), receive_timeout: pos_integer(), ref: String.t() | nil, repo: String.t(), telemetry: boolean(), token: String.t() | nil, user: String.t(), user_agent: String.t() }
Functions
Returns the Req auth tuple derived from config.
A :token takes precedence (Bearer); otherwise Basic auth is built from
:user and :key. Returns nil only if no credentials are usable.
Examples
iex> config = TerminusDB.Config.new(endpoint: "http://localhost:6363", token: "abc")
iex> TerminusDB.Config.auth(config)
{:bearer, "abc"}
iex> config = TerminusDB.Config.new(endpoint: "http://localhost:6363", user: "admin", key: "root")
iex> TerminusDB.Config.auth(config)
{:basic, "admin:root"}
Returns a copy of config with the given fields updated.
iex> config = TerminusDB.Config.new(endpoint: "http://localhost:6363")
iex> TerminusDB.Config.merge(config, database: "mydb").database
"mydb"
Builds a new, validated TerminusDB.Config.
Options
See the module documentation or schema/0 for the accepted options.
Examples
iex> %TerminusDB.Config{endpoint: "http://localhost:6363"} =
...> TerminusDB.Config.new(endpoint: "http://localhost:6363")
iex> TerminusDB.Config.new(endpoint: "http://localhost:6363", database: "foo").database
"foo"Raises NimbleOptions.ValidationError on invalid options.
iex> TerminusDB.Config.new(endpoint: 123)
** (NimbleOptions.ValidationError) invalid value for :endpoint option: expected string, got: 123
Returns config with sensitive fields redacted, suitable for telemetry metadata
and logging. Replaces :key and :token with "[redacted]".
iex> config = TerminusDB.Config.new(endpoint: "http://localhost:6363", key: "secret")
iex> redacted = TerminusDB.Config.redact(config)
iex> redacted.key
"[redacted]"
iex> redacted.endpoint
"http://localhost:6363"
@spec schema() :: keyword()
The NimbleOptions schema used to validate new/1 options.
Scopes config to the given branch.
iex> config = TerminusDB.Config.new(endpoint: "http://localhost:6363")
iex> TerminusDB.Config.with_branch(config, "feature").branch
"feature"
Scopes config to the given database.
iex> config = TerminusDB.Config.new(endpoint: "http://localhost:6363")
iex> TerminusDB.Config.with_database(config, "mydb").database
"mydb"
Scopes config to the given organization.
iex> config = TerminusDB.Config.new(endpoint: "http://localhost:6363")
iex> TerminusDB.Config.with_organization(config, "acme").organization
"acme"
Pins config to a commit reference for time-travel queries.
Scopes config to the given repository (local or a remote name).