Mailglass.Identifier (Mailglass v2.0.0)

Copy Markdown View Source

Validates Postgres unquoted identifiers — the single source of truth for schema, prefix, and table-name checks across mailglass.

A valid identifier is a letter or underscore followed by any combination of letters, digits, and underscores, and is at most 63 bytes long (Postgres' NAMEDATALEN limit — longer names are silently truncated by Postgres, which can alias two distinct schemas onto one, so we reject them outright).

This grammar rejects anything that could be an injection vector — quotes, semicolons, whitespace, dashes. Callers with a legitimate need for a quoted identifier (mixed case, dashes) should pre-quote and adjust; mailglass does not surface such options.

Validation failures raise Mailglass.ConfigError with type: :invalid. The specific cause lives in context.key and context.reason — match on the struct, never on the message string.

Summary

Functions

Validates value as a Postgres unquoted identifier, returning it unchanged.

Functions

validate!(value, key)

(since 2.0.0)
@spec validate!(String.t(), atom()) :: String.t()

Validates value as a Postgres unquoted identifier, returning it unchanged.

key is the configuration key name surfaced in the raised error's context (e.g. :schema, :prefix).

Returns the validated string so it can be used pipe-first. Raises Mailglass.ConfigError with type: :invalid when value is not a binary, exceeds 63 bytes, or does not match the unquoted-identifier grammar.