View Source Polyn.Naming (Polyn v0.1.0)
Utilities for working with Polyn naming conventions
Link to this section Summary
Functions
Convert a colon separated name into a dot separated name
Convert a dot separated name into a colon separated name
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
.
Validate the source of an event
Give a version number to a name
Link to this section Functions
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"
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"
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"
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"
Validate the name of an event, also sometimes called an event type
.
examples
Examples
iex>Polyn.Naming.validate_event_name("user.created")
:ok
iex>Polyn.Naming.validate_event_name("user created")
{:error, ["Event names can't have spaces"]}
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")
{:error, ["Source names can't have spaces"]}
@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"