solnic / drops

🛠️ Tools for working with data effectively - data contracts using types, schemas, domain validation rules, type-safe casting, and more.
Other
257 stars 6 forks source link

Add first class types #25

Closed solnic closed 1 year ago

solnic commented 1 year ago

Introduce Drops.Type with:

Now a schema looks like this:

contract.schema() #=> %Drops.Type.Schema{
  primitive: :map,
  constraints: [predicate: {:type?, :map}],
  keys: [
    %Drops.Type.Schema.Key{
      path: [:age],
      presence: :required,
      type: %Drops.Type{
        primitive: :integer,
        constraints: [predicate: {:type?, :integer}]
      }
    },
    %Drops.Type.Schema.Key{
      path: [:name],
      presence: :required,
      type: %Drops.Type{
        primitive: :string,
        constraints: [predicate: {:type?, :string}]
      }
    }
  ],
  atomize: false
}