ExDav.Storage behaviour (ExDav v0.1.0)

Copy Markdown View Source

Behaviour for CalDAV storage adapters.

Adapters return plain maps so the protocol layer is agnostic of any particular ORM. A reference Postgres adapter ships in ExDav.Storage.Postgres.

Adapters are paired with the plug via the :storage opt:

plug ExDav.CalDav.Plug,
  storage: ExDav.Storage.Postgres,
  authenticator: {ExDav.Authenticator.Basic,
                  verify: {ExDav.Storage.Postgres, :authenticate}}

Summary

Types

calendar()

@type calendar() :: %{
  name: String.t(),
  displayname: String.t(),
  description: String.t() | nil,
  components: [String.t()],
  ctag: non_neg_integer(),
  objects: %{optional(String.t()) => object()}
}

calendar_name()

@type calendar_name() :: String.t()

create_calendar_opts()

@type create_calendar_opts() :: [
  displayname: String.t() | nil,
  description: String.t() | nil,
  components: [String.t()]
]

object()

@type object() :: %{
  name: String.t(),
  ical: String.t(),
  etag: String.t(),
  uid: String.t() | nil,
  component: String.t() | nil
}

object_name()

@type object_name() :: String.t()

update_props()

@type update_props() :: [displayname: String.t(), description: String.t() | nil]

username()

@type username() :: String.t()

Callbacks

create_calendar(username, calendar_name, create_calendar_opts)

@callback create_calendar(username(), calendar_name(), create_calendar_opts()) ::
  {:ok, calendar()} | {:error, :no_user | :already_exists | :invalid}

delete_calendar(username, calendar_name)

@callback delete_calendar(username(), calendar_name()) :: :ok | {:error, :not_found}

delete_object(username, calendar_name, object_name)

@callback delete_object(username(), calendar_name(), object_name()) ::
  :ok | {:error, :not_found | :precondition_failed}

get_calendar(username, calendar_name)

@callback get_calendar(username(), calendar_name()) :: calendar() | nil

get_calendar_with_objects(username, calendar_name)

@callback get_calendar_with_objects(username(), calendar_name()) :: calendar() | nil

get_object(username, calendar_name, object_name)

@callback get_object(username(), calendar_name(), object_name()) :: object() | nil

list_calendars(username)

@callback list_calendars(username()) :: [calendar()]

put_object(username, calendar_name, object_name, ical)

@callback put_object(username(), calendar_name(), object_name(), ical :: String.t()) ::
  {:ok, object()} | {:error, :not_found | :invalid}

sync_changes(username, calendar_name, since)

@callback sync_changes(username(), calendar_name(), since :: non_neg_integer() | nil) ::
  {[object()], [object_name()], non_neg_integer()} | {:error, :not_found}

update_calendar(username, calendar_name, update_props)

@callback update_calendar(username(), calendar_name(), update_props()) ::
  {:ok, calendar()} | {:error, :not_found | :invalid}

user_exists?(username)

@callback user_exists?(username()) :: boolean()