Trogon.Proto.Uuid.V1.UuidTemplate (Trogon.Proto v0.11.0)

Copy Markdown View Source

Generates deterministic UUIDv5 identities using options from proto definitions.

Uses compile-time extraction of proto options for fast runtime UUID generation. The template is parsed at compile time and generates optimized string concatenation.

Summary

Functions

Sets up deterministic UUID generation based on proto definitions.

Functions

__using__(opts)

(macro)

Sets up deterministic UUID generation based on proto definitions.

Proto Definition

Define your identity versions in a proto file with trogon options:

syntax = "proto3";

package acme.order.v1;

import "trogon/uuid/v1/options.proto";

message OrderId {
  enum IdentityVersion {
    option (trogon.uuid.v1.enum).namespace = {dns: "acme.com"};

    IDENTITY_VERSION_UNSPECIFIED = 0;
    IDENTITY_VERSION_V1 = 1 [(trogon.uuid.v1.enum_value).format = {
      template: "order/{customer_id}/{order_number}"
    }];
  }

  string value = 1;
}

Usage

defmodule MyApp.Order.IdentityVersionV1UuidTemplate do
  use Trogon.Proto.Uuid.V1.UuidTemplate,
    enum: Acme.Order.V1.OrderId.IdentityVersion,
    version: :IDENTITY_VERSION_V1
end

# Fast runtime call - namespace and template are pre-computed
MyApp.Order.IdentityVersionV1UuidTemplate.uuid5(%{customer_id: "cust-123", order_number: "ORD-456"})

Template Syntax

The template string uses {name} placeholders for value interpolation:

"order/{customer_id}/{order_number}"

Expects a map with :customer_id and :order_number keys. Placeholders are parsed at compile time and generate optimized string concatenation code.

Multiple Identity Versions

When your proto defines multiple identity versions, create separate modules:

# V1 identity
defmodule MyApp.Order.IdentityVersionV1UuidTemplate do
  use Trogon.Proto.Uuid.V1.UuidTemplate,
    enum: Acme.Order.V1.OrderId.IdentityVersion,
    version: :IDENTITY_VERSION_V1
end

# V2 identity
defmodule MyApp.Order.IdentityVersionV2UuidTemplate do
  use Trogon.Proto.Uuid.V1.UuidTemplate,
    enum: Acme.Order.V1.OrderId.IdentityVersion,
    version: :IDENTITY_VERSION_V2
end

Options

  • :enum (atom/0) - Required. The protobuf enum module containing the identity version definitions.

  • :version (atom/0) - Required. The identity version atom (e.g., :IDENTITY_VERSION_V1).