ExCedar.EntityUid (ex_cedar v0.1.2)

Copy Markdown View Source

Cedar entity UID — a {type, id} pair that uniquely identifies an entity.

The type field may be namespaced (e.g. "App::User"). The id is the bare string value (unescaped). Use to_string/1 to render the Cedar syntax Type::"id" and parse/1 to parse it back.

Summary

Functions

Builds an EntityUid from type and id strings.

Parses a Cedar-syntax entity UID string into an EntityUid.

Returns the Cedar JSON entity-reference shape: %{"type" => type, "id" => id}.

Renders the EntityUid as a Cedar-syntax string (Type::"id").

Types

t()

@type t() :: %ExCedar.EntityUid{id: String.t(), type: String.t()}

Functions

new(type, id)

Builds an EntityUid from type and id strings.

parse(string)

Parses a Cedar-syntax entity UID string into an EntityUid.

iex> ExCedar.EntityUid.parse(~s|User::"alice"|)
{:ok, %ExCedar.EntityUid{type: "User", id: "alice"}}

iex> {:ok, uid} = ExCedar.EntityUid.parse(~s|App::User::"bob"|)
iex> uid.type
"App::User"

Returns {:error, %ExCedar.Error.Request{}} if the string is not a valid Cedar entity UID.

to_json(entity_uid)

Returns the Cedar JSON entity-reference shape: %{"type" => type, "id" => id}.

to_string(entity_uid)

Renders the EntityUid as a Cedar-syntax string (Type::"id").

Special characters in id (backslash and double-quote) are escaped.