Packages

A Gleam library for building and orchestrating agents on the BEAM.

Current section

Files

Jump to
pig src pig@session_store.erl
Raw

src/pig@session_store.erl

-module(pig@session_store).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/pig/session_store.gleam").
-export([new_commit/2]).
-export_type([session_error/0, session/0, session_commit/0, session_store/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(" Durable session storage types for atomic agent-state transitions.\n").
-type session_error() :: {unavailable, binary()} |
{corrupt, binary()} |
{parent_conflict,
gleam@option:option(binary()),
gleam@option:option(binary())} |
{invalid_commit, binary()}.
-type session() :: {session,
gleam@option:option(binary()),
list(pig_protocol@message:message())}.
-type session_commit() :: {session_commit,
binary(),
gleam@option:option(binary()),
list(pig_protocol@message:message())}.
-type session_store() :: {session_store,
fun(() -> {ok, session()} | {error, session_error()}),
fun((session_commit()) -> {ok, session()} | {error, session_error()})}.
-file("src/pig/session_store.gleam", 34).
?DOC(
" Create a commit with a fresh opaque ID, its expected parent, and its delta.\n"
"\n"
" The ID is generated independently of the messages, so commits with identical\n"
" contents still have distinct identities.\n"
).
-spec new_commit(
gleam@option:option(binary()),
list(pig_protocol@message:message())
) -> session_commit().
new_commit(Parent, Messages) ->
{session_commit,
<<"commit-"/utf8,
(gleam@bit_array:base64_url_encode(
crypto:strong_rand_bytes(16),
false
))/binary>>,
Parent,
Messages}.