{-# LANGUAGE OverloadedStrings #-}

module Hydra.Impl.Haskell.Sources.Ext.Avro.Schema where

import Hydra.All
import Hydra.Impl.Haskell.Dsl.Types as Types
import Hydra.Impl.Haskell.Dsl.Standard
import Hydra.Impl.Haskell.Sources.Core
import Hydra.Impl.Haskell.Sources.Ext.Json.Model
import Hydra.Impl.Haskell.Sources.Ext.Rdf.Syntax


avroSchemaModule :: Module Meta
avroSchemaModule :: Module Meta
avroSchemaModule = forall m.
Namespace -> [Element m] -> [Module m] -> Maybe [Char] -> Module m
Module Namespace
ns [Element Meta]
elements [Module Meta
jsonModelModule] forall a b. (a -> b) -> a -> b
$
    forall a. a -> Maybe a
Just ([Char]
"A model for Avro schemas. Based on the Avro 1.11.1 specification:\n" forall a. [a] -> [a] -> [a]
++
      [Char]
"  https://avro.apache.org/docs/1.11.1/specification)")
  where
    ns :: Namespace
ns = [Char] -> Namespace
Namespace [Char]
"hydra/ext/avro/schema"
    def :: [Char] -> Type m -> Element m
def = forall m. Namespace -> [Char] -> Type m -> Element m
datatype Namespace
ns
    avro :: [Char] -> Type m
avro = forall m. Namespace -> [Char] -> Type m
nsref Namespace
ns
    json :: [Char] -> Type m
json = forall m. Namespace -> [Char] -> Type m
nsref forall a b. (a -> b) -> a -> b
$ forall m. Module m -> Namespace
moduleNamespace Module Meta
jsonModelModule

    elements :: [Element Meta]
elements = [
      forall {m}. [Char] -> Type m -> Element m
def [Char]
"Array" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
record [
          [Char]
"items"forall m. [Char] -> Type m -> FieldType m
>: forall {m}. [Char] -> Type m
avro [Char]
"Schema"],

      forall {m}. [Char] -> Type m -> Element m
def [Char]
"Enum" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
record [
          [Char]
"symbols"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc ([Char]
"a JSON array, listing symbols, as JSON strings. All symbols in an enum must be unique; " forall a. [a] -> [a] -> [a]
++
              [Char]
"duplicates are prohibited. Every symbol must match the regular expression [A-Za-z_][A-Za-z0-9_]* " forall a. [a] -> [a] -> [a]
++
              [Char]
"(the same requirement as for names)") forall a b. (a -> b) -> a -> b
$
            forall m. Type m -> Type m
list forall m. Type m
string,
          [Char]
"default"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc ([Char]
"A default value for this enumeration, used during resolution when the reader encounters " forall a. [a] -> [a] -> [a]
++
              [Char]
"a symbol from the writer that isn’t defined in the reader’s schema. " forall a. [a] -> [a] -> [a]
++
              [Char]
"The value provided here must be a JSON string that’s a member of the symbols array") forall a b. (a -> b) -> a -> b
$
            forall m. Type m -> Type m
optional forall m. Type m
string],

      forall {m}. [Char] -> Type m -> Element m
def [Char]
"Field" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
record [
          [Char]
"name"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"a JSON string providing the name of the field"
            forall m. Type m
string,
          [Char]
"doc"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"a JSON string describing this field for users" forall a b. (a -> b) -> a -> b
$
            forall m. Type m -> Type m
optional forall m. Type m
string,
          [Char]
"type"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"a schema" forall a b. (a -> b) -> a -> b
$
            forall {m}. [Char] -> Type m
avro [Char]
"Schema",
          [Char]
"default"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"default value for this field, only used when reading instances that lack the field for schema evolution purposes" forall a b. (a -> b) -> a -> b
$
            forall m. Type m -> Type m
optional forall a b. (a -> b) -> a -> b
$ forall {m}. [Char] -> Type m
json [Char]
"Value",
          [Char]
"order"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"specifies how this field impacts sort ordering of this record" forall a b. (a -> b) -> a -> b
$
            forall m. Type m -> Type m
optional forall a b. (a -> b) -> a -> b
$ forall {m}. [Char] -> Type m
avro [Char]
"Order",
          [Char]
"aliases"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"a JSON array of strings, providing alternate names for this field" forall a b. (a -> b) -> a -> b
$
            forall m. Type m -> Type m
optional forall a b. (a -> b) -> a -> b
$ forall m. Type m -> Type m
list forall m. Type m
string,
          [Char]
"annotations"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"Any additional key/value pairs attached to the field" forall a b. (a -> b) -> a -> b
$
            forall m. Type m -> Type m -> Type m
Types.map forall m. Type m
string forall a b. (a -> b) -> a -> b
$ forall {m}. [Char] -> Type m
json [Char]
"Value"],

      forall {m}. [Char] -> Type m -> Element m
def [Char]
"Fixed" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
record [
          [Char]
"size"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"an integer, specifying the number of bytes per value"
            forall m. Type m
int32],

      forall {m}. [Char] -> Type m -> Element m
def [Char]
"Map" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
record [
          [Char]
"values"forall m. [Char] -> Type m -> FieldType m
>: forall {m}. [Char] -> Type m
avro [Char]
"Schema"],

      forall {m}. [Char] -> Type m -> Element m
def [Char]
"Named" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
record [
          [Char]
"name"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"a string naming this schema"
            forall m. Type m
string,
          [Char]
"namespace"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"a string that qualifies the name" forall a b. (a -> b) -> a -> b
$
            forall m. Type m -> Type m
optional forall m. Type m
string,
          [Char]
"aliases"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"a JSON array of strings, providing alternate names for this schema" forall a b. (a -> b) -> a -> b
$
            forall m. Type m -> Type m
optional forall a b. (a -> b) -> a -> b
$ forall m. Type m -> Type m
list forall m. Type m
string,
          [Char]
"doc"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"a JSON string providing documentation to the user of this schema" forall a b. (a -> b) -> a -> b
$
            forall m. Type m -> Type m
optional forall m. Type m
string,
          [Char]
"type"forall m. [Char] -> Type m -> FieldType m
>: forall {m}. [Char] -> Type m
avro [Char]
"NamedType",
          [Char]
"annotations"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"Any additional key/value pairs attached to the type" forall a b. (a -> b) -> a -> b
$
            forall m. Type m -> Type m -> Type m
Types.map forall m. Type m
string forall a b. (a -> b) -> a -> b
$ forall {m}. [Char] -> Type m
json [Char]
"Value"],

      forall {m}. [Char] -> Type m -> Element m
def [Char]
"NamedType" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
union [
          [Char]
"enum"forall m. [Char] -> Type m -> FieldType m
>: forall {m}. [Char] -> Type m
avro [Char]
"Enum",
          [Char]
"fixed"forall m. [Char] -> Type m -> FieldType m
>: forall {m}. [Char] -> Type m
avro [Char]
"Fixed",
          [Char]
"record"forall m. [Char] -> Type m -> FieldType m
>: forall {m}. [Char] -> Type m
avro [Char]
"Record"],

      forall {m}. [Char] -> Type m -> Element m
def [Char]
"Order" forall a b. (a -> b) -> a -> b
$
        forall m. [[Char]] -> Type m
enum [[Char]
"ascending", [Char]
"descending", [Char]
"ignore"],

      forall {m}. [Char] -> Type m -> Element m
def [Char]
"Primitive" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
union [
          [Char]
"null"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"no value" forall m. Type m
unit,
          [Char]
"boolean"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"A binary value" forall m. Type m
unit,
          [Char]
"int"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"32-bit signed integer" forall m. Type m
unit,
          [Char]
"long"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"64-bit signed integer" forall m. Type m
unit,
          [Char]
"float"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"single precision (32-bit) IEEE 754 floating-point number" forall m. Type m
unit,
          [Char]
"double"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"double precision (64-bit) IEEE 754 floating-point number" forall m. Type m
unit,
          [Char]
"bytes"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"sequence of 8-bit unsigned bytes" forall m. Type m
unit,
          [Char]
"string"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"unicode character sequence" forall m. Type m
unit],

      forall {m}. [Char] -> Type m -> Element m
def [Char]
"Record" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
record [
          [Char]
"fields"forall m. [Char] -> Type m -> FieldType m
>:
            [Char] -> Type Meta -> Type Meta
doc [Char]
"a JSON array, listing fields" forall a b. (a -> b) -> a -> b
$
            forall m. Type m -> Type m
list forall a b. (a -> b) -> a -> b
$ forall {m}. [Char] -> Type m
avro [Char]
"Field"],

      forall {m}. [Char] -> Type m -> Element m
def [Char]
"Schema" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
union [
          [Char]
"array"forall m. [Char] -> Type m -> FieldType m
>: forall {m}. [Char] -> Type m
avro [Char]
"Array",
          [Char]
"map"forall m. [Char] -> Type m -> FieldType m
>: forall {m}. [Char] -> Type m
avro [Char]
"Map",
          [Char]
"named"forall m. [Char] -> Type m -> FieldType m
>: forall {m}. [Char] -> Type m
avro [Char]
"Named",
          [Char]
"primitive"forall m. [Char] -> Type m -> FieldType m
>: forall {m}. [Char] -> Type m
avro [Char]
"Primitive",
          [Char]
"reference"forall m. [Char] -> Type m -> FieldType m
>: -- Note: "reference" is not described in the Avro specification; this has been added
            [Char] -> Type Meta -> Type Meta
doc [Char]
"A reference by name to a previously defined type" forall m. Type m
string,
          [Char]
"union"forall m. [Char] -> Type m -> FieldType m
>: forall {m}. [Char] -> Type m
avro [Char]
"Union"
        ],

      forall {m}. [Char] -> Type m -> Element m
def [Char]
"Union" forall a b. (a -> b) -> a -> b
$
        forall m. Type m -> Type m
list forall a b. (a -> b) -> a -> b
$ forall {m}. [Char] -> Type m
avro [Char]
"Schema"]