View Source Polyn.Naming (Polyn v0.3.0)

Utilities for working with Polyn naming conventions

Link to this section Summary

Functions

Convert a colon separated name into a dot separated name

Create a consumer name from a source and type. Uses the configured :source_root as the prefix. Will include an additional source if passed in

Convert a dot separated name into a colon separated name

Lookup the name of a stream for a given event type

Determine if a given subject matches a subscription pattern

Remove the :domain prefix from a name

Remove the version suffix from a name

Validate the name of an event, also sometimes called an event type. Raises if invalid

Validate the name of an event, also sometimes called an event type.

Validate the source of an event

Give a version number to a name

Link to this section Functions

@spec colon_to_dot(str :: binary()) :: binary()

Convert a colon separated name into a dot separated name

examples

Examples

iex>Polyn.Naming.colon_to_dot("com:acme:user:created:v1:schema:v1")
"com.acme.user.created.v1.schema.v1"
Link to this function

consumer_name(type, source \\ nil)

View Source

Create a consumer name from a source and type. Uses the configured :source_root as the prefix. Will include an additional source if passed in

## Examples

  iex>Polyn.Naming.consumer_name("user.created.v1")
  "user_backend_user_created_v1"

  iex>Polyn.Naming.consumer_name("user.created.v1", "notifications")
  "user_backend_notifications_user_created_v1"
@spec dot_to_colon(str :: binary()) :: binary()

Convert a dot separated name into a colon separated name

examples

Examples

iex>Polyn.Naming.dot_to_colon("com.acme.user.created.v1.schema.v1")
"com:acme:user:created:v1:schema:v1"
Link to this function

lookup_stream_name!(conn, type)

View Source

Lookup the name of a stream for a given event type

examples

Examples

  iex>Polyn.Naming.lookup_stream_name!(:gnat, "user.created.v1")
  "USERS"

  iex>Polyn.Naming.lookup_stream_name!(:gnat, "foo.v1")
  Polyn.StreamException
Link to this function

subject_matches?(subject, pattern)

View Source

Determine if a given subject matches a subscription pattern

@spec trim_domain_prefix(str :: binary()) :: binary()

Remove the :domain prefix from a name

examples

Examples

iex>Polyn.Naming.trim_domain_prefix("com:acme:user:created:v1:schema:v1")
"user:created:v1:schema:v1"

iex>Polyn.Naming.trim_domain_prefix("com.acme.user.created.v1.schema.v1")
"user.created.v1.schema.v1"
Link to this function

trim_version_suffix(str)

View Source
@spec trim_version_suffix(str :: binary()) :: binary()

Remove the version suffix from a name

examples

Examples

iex>Polyn.Naming.trim_version_suffix("com.acme.user.created.v1")
"com.acme.user.created"

iex>Polyn.Naming.trim_version_suffix("com:acme:user:created:v1")
"com:acme:user:created"
Link to this function

validate_event_type!(type)

View Source
@spec validate_event_type!(name :: binary()) :: :ok

Validate the name of an event, also sometimes called an event type. Raises if invalid

examples

Examples

iex>Polyn.Naming.validate_event_type!("user.created")
:ok

iex>Polyn.Naming.validate_event_type!("user  created")
Polyn.ValidationException
Link to this function

validate_event_type(type)

View Source
@spec validate_event_type(name :: binary()) :: :ok | {:error, binary()}

Validate the name of an event, also sometimes called an event type.

examples

Examples

iex>Polyn.Naming.validate_event_type("user.created")
:ok

iex>Polyn.Naming.validate_event_type("user  created")
{:error, message}
Link to this function

validate_source_name!(name)

View Source
@spec validate_source_name!(name :: binary()) :: :ok

Validate the source of an event

examples

Examples

iex>Polyn.Naming.validate_source_name!("user.created")
:ok

iex>Polyn.Naming.validate_source_name!("user:created")
:ok

iex>Polyn.Naming.validate_source_name!("user  created")
Polyn.ValidationException
Link to this function

version_suffix(str, version \\ 1)

View Source
@spec version_suffix(str :: binary(), version :: non_neg_integer()) :: binary()

Give a version number to a name

examples

Examples

iex>Polyn.Naming.version_suffix("com:acme:user:created:")
"com:acme:user:created:v1"

iex>Polyn.Naming.version_suffix("com.acme.user.created.", 2)
"com.acme.user.created.v2"