macula_mri (macula v0.20.5)
View SourceMacula Resource Identifier (MRI) - Core Module
Provides parsing, validation, formatting, and manipulation of MRIs. MRI format: mri:{type}:{realm}/{path}
Example: {ok, Parsed} = macula_mri:parse(MRI), app = macula_mri:type(Parsed), Realm = macula_mri:realm(Parsed), Path = macula_mri:path(Parsed).
Summary
Functions
Get all ancestors of an MRI, from immediate parent to root.
Append a segment to an MRI's path.
Get the depth of an MRI (0 for realm, 1 for org, etc).
Derive a DHT procedure from an instance MRI and a declared procedure name.
Derive a DHT topic from an instance MRI and a declared topic name.
Format an MRI map back to binary.
Check if PotentialAncestor is an ancestor of MRI.
Check if an MRI is valid.
Join path segments with slashes.
Create a new MRI from a map.
Create a new MRI from type, realm, and path.
Create an app MRI.
Create an instance MRI (running installation of an artifact). Instance path: {org}/{device}/{instance_name} Example: mri:instance:io.macula/acme/edge-01/counter
Create an instance MRI with qualifier (environment or replica index). Example: mri:instance:io.macula/acme/edge-01/counter.prod
Create an org MRI.
Create a realm MRI.
Create a service MRI.
Create a user MRI.
Get the parent MRI, or undefined for realm-level MRIs.
Get the parent type for a given type.
Parse an MRI binary into a map.
Get the path segments from an MRI.
Get the path as a single joined string.
Get the realm from an MRI.
Split a path string into segments.
Convert an MRI to a topic/procedure prefix (realm/path segments).
Get the type from an MRI (binary or parsed).
Validate an MRI, returning ok or error with reason.
Types
Functions
Get all ancestors of an MRI, from immediate parent to root.
-spec append_segment(mri() | mri_map(), path_segment()) -> mri().
Append a segment to an MRI's path.
-spec depth(mri() | mri_map()) -> non_neg_integer().
Get the depth of an MRI (0 for realm, 1 for org, etc).
Derive a DHT procedure from an instance MRI and a declared procedure name.
Takes an instance MRI and a declared procedure name, returns the full DHT procedure. The instance path becomes a prefix: realm/org/device/instance.declared_procedure
Example: InstanceMRI = "mri:instance:io.macula/acme/edge-01/counter.prod" DeclaredProcedure = "place_order" Result = "io.macula/acme/edge-01/counter.prod.place_order"
Derive a DHT topic from an instance MRI and a declared topic name.
Takes an instance MRI and a declared topic name, returns the full DHT topic. The instance path becomes a prefix: realm/org/device/instance.declared_topic
Example: InstanceMRI = "mri:instance:io.macula/acme/edge-01/counter.prod" DeclaredTopic = "orders.created" Result = "io.macula/acme/edge-01/counter.prod.orders.created"
Format an MRI map back to binary.
Check if PotentialAncestor is an ancestor of MRI.
Check if an MRI is valid.
-spec join_path([path_segment()]) -> binary().
Join path segments with slashes.
Create a new MRI from a map.
-spec new(mri_type(), realm(), [path_segment()]) -> {ok, mri()} | {error, term()}.
Create a new MRI from type, realm, and path.
Create an app MRI.
Create an instance MRI (running installation of an artifact). Instance path: {org}/{device}/{instance_name} Example: mri:instance:io.macula/acme/edge-01/counter
Create an instance MRI with qualifier (environment or replica index). Example: mri:instance:io.macula/acme/edge-01/counter.prod
Create an org MRI.
Create a realm MRI.
Create a service MRI.
Create a user MRI.
Get the parent MRI, or undefined for realm-level MRIs.
Get the parent type for a given type.
Parse an MRI binary into a map.
-spec path(mri() | mri_map()) -> [path_segment()].
Get the path segments from an MRI.
Get the path as a single joined string.
Get the realm from an MRI.
-spec split_path(binary()) -> [path_segment()].
Split a path string into segments.
Convert an MRI to a topic/procedure prefix (realm/path segments).
Takes any MRI and extracts the realm and path as a topic-compatible prefix. Format: realm/path_segment1/path_segment2/...
Example: MRI = "mri:instance:io.macula/acme/edge-01/counter.prod" Result = "io.macula/acme/edge-01/counter.prod"
Get the type from an MRI (binary or parsed).
Validate an MRI, returning ok or error with reason.