HuwCampbell/avro/1.0.1

Avro.Name

Definitions and helpers for Avro Names.

Record, Enum and Fixed types are named types. Each has a full name that is composed of two parts; a name and a namespace. Equality of names is defined on the full name.

A namespace is list of scoping names, encoded in the interface description language and Json specification language as a dot separated string, but here as an Elm list.

The empty string may also be used as a namespace to indicate the null namespace. Equality of names (including field names and enum symbols) as well as fullnames is case-sensitive.

Record fields and enum symbols have names as well (but no namespace). Equality of fields and enum symbols is defined on the name of the field/symbol within its scope (the record/enum that defines it). Fields and enum symbols across scopes are never equal.

The name portion of the full name of named types, record field names, and enum symbols must:

  • start with [A-Za-z_][A-Za-z_]
  • subsequently contain only [A-Za-z0-9_][A-Za-z0-9_]

Definition

type alias TypeName =
{ baseName : String
, nameSpace : List String
}

An Avro Type Name

This constructor is exposed, but one should only build names which are correctly scoped and have valid names.

If unsure, one should use contextualTypeName to parse the data instead.

Functions

contextualTypeName : Maybe TypeName -> String -> Maybe String -> Result String TypeName

Build a TypeName from using the name and namespace fields within a context.

Rules for this are specified in the avro specification.

Arguments:

  • Optional context (parent name)
  • Name
  • Optional Namespace
canonicalName : TypeName -> TypeName

Normalise a TypeName.

This replaces short names with fullnames, using applicable namespaces to do so, then eliminate namespace attributes, which are now redundant.

{ reader | name : TypeName, aliases : List TypeName }
-> { writer | name : TypeName }
-> Bool

Whether two names are compatible for Schema resolution.

This means that either the unqualified names match, or an alias matches the fully qualified name.

validName : TypeName -> Result String TypeName

Test that a TypeName is valid

That is, test that

  • start with [A-Za-z_][A-Za-z_]
  • subsequently contain only [A-Za-z0-9_][A-Za-z0-9_]