-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
featureNew functionality or improvementNew functionality or improvement
Milestone
Description
This is conceptually similar to any.tags(), any.notes(), and any.description(), but allows the storage of an object rather than a string. This is valuable because, besides annotating the schemas, it allows us to build modules on Joi that provide additional functionality. Example use case:
var schema = {
_id: Joi.number().integer().meta({index: {unique: true, sparse: true}}),
name: 'Margaret'
};
// Registers schema as the validator for person models, and
// extracts indexing information for each field from the metadata on each field.
myDBAdapter.model('Person', schema);This can currently be accomplished using tags(), but it requires string parsing and complicates the logic of actually retrieving the metadata. E.g.
var schema = {
_id: Joi.number().integer().tags(['index:unique', 'index:sparse']),
name: 'Margaret'
};The benefit of an any.meta() is similar to that of the existing description functions -- the metadata is stored consistently and doesn't need to worry about clobbering / being clobbered by Joi's moving parts.
Cheers,
Josh
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
featureNew functionality or improvementNew functionality or improvement