adk_session_query (erlang_adk v0.7.0)

View Source

Versioned query, pagination, and non-destructive branching for sessions.

The current session-service behaviour exposes whole snapshots. This layer adds stable ordering, HMAC-authenticated snapshot cursors, event filters, and plan/apply branching without requiring a backend rewrite. A rewind is materialized as a new session; the source is never edited or deleted.

Summary

Functions

Apply a previously generated plan to a new target session. The source snapshot and plan contents are revalidated. Scoped app/user deltas are rejected unless allow_shared_state_replay => true is explicit.

Materialize a full-head branch.

Get one session with a stable, filtered page of canonical JSON-safe events. State and event maps have all credential-bearing keys removed.

List one deterministic page. cursor_secret (at least 32 bytes) is mandatory; cursors are bound to app, user, page size, order, and the complete list snapshot.

Plan a branch at the current head without creating it.

Plan a new session retaining a chronological prefix of source events. Selectors are all, {index, Count}, {event_id, Id}, or {timestamp, Milliseconds}. Event-id and timestamp selectors are inclusive.

Materialize an historical prefix as a new session. This is always non-destructive; destructive => true is rejected.

Functions

apply_plan(Service, Plan, Opts)

-spec apply_plan(module(), map(), map()) -> {ok, map()} | {error, term()}.

Apply a previously generated plan to a new target session. The source snapshot and plan contents are revalidated. Scoped app/user deltas are rejected unless allow_shared_state_replay => true is explicit.

branch(Service, AppName, UserId, SessionId, Opts)

-spec branch(module(), binary(), binary(), binary(), map()) -> {ok, map()} | {error, term()}.

Materialize a full-head branch.

capabilities()

-spec capabilities() -> map().

get(Service, AppName, UserId, SessionId, Opts)

-spec get(module(), binary(), binary(), binary(), map()) -> {ok, map()} | {error, term()}.

Get one session with a stable, filtered page of canonical JSON-safe events. State and event maps have all credential-bearing keys removed.

list(Service, AppName, UserId, Opts)

-spec list(module(), binary(), binary(), map()) -> {ok, map()} | {error, term()}.

List one deterministic page. cursor_secret (at least 32 bytes) is mandatory; cursors are bound to app, user, page size, order, and the complete list snapshot.

new_cursor_secret()

-spec new_cursor_secret() -> binary().

plan_branch(Service, AppName, UserId, SessionId, Opts)

-spec plan_branch(module(), binary(), binary(), binary(), map()) -> {ok, map()} | {error, term()}.

Plan a branch at the current head without creating it.

plan_rewind(Service, AppName, UserId, SessionId, Selector, Opts)

-spec plan_rewind(module(), binary(), binary(), binary(), term(), map()) ->
                     {ok, map()} | {error, term()}.

Plan a new session retaining a chronological prefix of source events. Selectors are all, {index, Count}, {event_id, Id}, or {timestamp, Milliseconds}. Event-id and timestamp selectors are inclusive.

rewind(Service, AppName, UserId, SessionId, Selector, Opts)

-spec rewind(module(), binary(), binary(), binary(), term(), map()) -> {ok, map()} | {error, term()}.

Materialize an historical prefix as a new session. This is always non-destructive; destructive => true is rejected.

version()

-spec version() -> pos_integer().