Hi there, so I need a bit of guidance on the next part of my project. What I’m trying to do replicate a “field type” that multiple entities within my data model have in common. I have kept the base type pretty simple and I’m trying to create a Schema class for each entity.
The code I’m referring to is here : https://github.com/dragginzgame/dragginz/tree/master/src/dragginz
For instance
public type PetStageID = Types.ID; // the key of the map
public type PetStage = {
created: Types.Time; // type aliases to avoid confusion
lastModified: Types.Time;
name: Text;
description: Text;
baseLevel: Types.Level;
rank: Types.Rank;
progressLevels: Nat;
}
then because fields like name, level and rank are always validated in the same way, I define the Schema as
public class PetStageSchema(e : PetStage) = {
var name = Schema.Name();
var description = Schema.Description();
var baseLevel = Schema.Level(); // always a value 1-20
var rank = Schema.Rank(); // always a value 1-8
var progressLevels = Schema.NatRange(1, 20); // not used anywhere else
};
The Schema class does nothing right now, I just wanted to get the definitions in there and for the code to compile. The Schema classes Name(), Description() etc. should contain all the rules needed to validate and sanitise the values.
ie. a name with certain unicode characters in could be rejected, and " the book of magic " would be sanitised to “The Book of Magic”
So what I’m looking for is to do something like
e := PetStage{ values... };
e := MySanitiser(e);
err := MyValidator(e);
Just not sure of the best way to set it up. I don’t want to have to repeat the same name validation code 100 times. Need a push in the right direction and I should be good.