Jido.Signal.Bus.RecordedSignal (Jido Signal v1.0.0)

View Source

Represents a signal that has been recorded in the bus log.

This struct wraps a signal with additional metadata about when it was recorded.

Summary

Types

t()

A recorded signal with metadata

Functions

Deserializes a JSON string back into a RecordedSignal struct or list of RecordedSignal structs.

Serializes a RecordedSignal or a list of RecordedSignals to JSON string.

Types

t()

@type t() :: %Jido.Signal.Bus.RecordedSignal{
  created_at: DateTime.t(),
  id: String.t(),
  signal: Jido.Signal.t(),
  type: String.t()
}

A recorded signal with metadata

Functions

deserialize(json)

@spec deserialize(binary()) :: {:ok, t() | [t()]} | {:error, term()}

Deserializes a JSON string back into a RecordedSignal struct or list of RecordedSignal structs.

Parameters

  • json: The JSON string to deserialize

Returns

{:ok, RecordedSignal.t() | list(RecordedSignal.t())} if successful, {:error, reason} otherwise

Examples

iex> json = ~s({"id":"rec123","type":"example.event","created_at":"2023-01-01T00:00:00Z","signal":{"type":"example.event","source":"/example"}})
iex> {:ok, recorded} = Jido.Signal.Bus.RecordedSignal.deserialize(json)
iex> recorded.id
"rec123"

iex> # Deserializing multiple RecordedSignals
iex> json = ~s([{"id":"rec1","type":"event1","created_at":"2023-01-01T00:00:00Z","signal":{"type":"event1","source":"/ex"}}])
iex> {:ok, records} = Jido.Signal.Bus.RecordedSignal.deserialize(json)
iex> length(records)
1

serialize(recorded_signal)

@spec serialize(t() | [t()]) :: binary()

Serializes a RecordedSignal or a list of RecordedSignals to JSON string.

Parameters

  • recorded_signal_or_list: A RecordedSignal struct or list of RecordedSignal structs

Returns

A JSON string representing the RecordedSignal(s)

Examples

iex> signal = %Jido.Signal{type: "example.event", source: "/example"}
iex> recorded = %Jido.Signal.Bus.RecordedSignal{id: "rec123", type: "example.event", created_at: DateTime.utc_now(), signal: signal}
iex> json = Jido.Signal.Bus.RecordedSignal.serialize(recorded)
iex> is_binary(json)
true

iex> # Serializing multiple RecordedSignals
iex> signal = %Jido.Signal{type: "example.event", source: "/example"}
iex> records = [
...>   %Jido.Signal.Bus.RecordedSignal{id: "rec1", type: "event1", created_at: DateTime.utc_now(), signal: signal},
...>   %Jido.Signal.Bus.RecordedSignal{id: "rec2", type: "event2", created_at: DateTime.utc_now(), signal: signal}
...> ]
iex> json = Jido.Signal.Bus.RecordedSignal.serialize(records)
iex> is_binary(json)
true