TypeSafeSDK.Prepared (TypeSafeSDK v0.4.0)

Copy Markdown View Source

A validated, immutable semantic question contract.

Preparation caches the exact wire fragment, retains finite caller-key metadata, and computes a versioned semantic fingerprint. Composition functions rebuild the value through the normal validation path, so ordering and request-relative invariants are never bypassed.

Summary

Functions

Delete one key and revalidate the resulting Prepared value.

Return the versioned deterministic semantic-contract fingerprint.

Return caller keys in execution/wire order.

Right-biased merge preserving duplicate positions from the left.

Replace a question without moving it, or append a new key.

Take selected keys while preserving their source execution order.

Types

caller_key()

@type caller_key() :: atom() | String.t()

t()

@type t() :: %TypeSafeSDK.Prepared{
  count: pos_integer(),
  definitions: map(),
  encoded: struct(),
  fingerprint: String.t(),
  json: binary(),
  keys: %{required(String.t()) => caller_key()},
  ordered_keys: [caller_key()],
  questions: [{caller_key(), term()}]
}

Functions

delete(prepared, key)

@spec delete(t(), caller_key()) :: {:ok, t()} | {:error, TypeSafeSDK.Error.t()}

Delete one key and revalidate the resulting Prepared value.

fingerprint(prepared)

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

Return the versioned deterministic semantic-contract fingerprint.

keys(prepared)

@spec keys(t()) :: [caller_key()]

Return caller keys in execution/wire order.

merge(left, right)

@spec merge(t(), t()) :: {:ok, t()} | {:error, TypeSafeSDK.Error.t()}

Right-biased merge preserving duplicate positions from the left.

new(prepared)

@spec new(t() | map() | list()) :: {:ok, t()} | {:error, TypeSafeSDK.Error.t()}

new!(questions)

@spec new!(t() | map() | list()) :: t()

put(prepared, key, question)

@spec put(t(), caller_key(), term()) :: {:ok, t()} | {:error, TypeSafeSDK.Error.t()}

Replace a question without moving it, or append a new key.

take(prepared, requested)

@spec take(t(), Enumerable.t()) :: {:ok, t()} | {:error, TypeSafeSDK.Error.t()}

Take selected keys while preserving their source execution order.