Meteor package that provides a way for you to declare your models and enums
quave:definitions
is a Meteor package that provides a way for you to declare your models and enums.
It is desired to have a centralized way to declare schemas for your MongoDB collection and also your GraphQL schema.
We believe we are not reinventing the wheel in this package but what we are doing is like putting together the wheels in the vehicle :).
meteor add quave:definitions
The idea is to be as close as possible to a SimpleSchema schema definition but also supporting additional properties when necessary for GraphQL and other necessities.
You provide a name for your model and fields, the fields is your schema definition.
See that you can use custom types from meteor/quave:custom-type-*
like DateTime
and also in combination with createEnumDefinition
(see more below).
We have also special properties:
import { createModelDefinition } from 'meteor/quave:definitions';
import { DateTimeType } from 'meteor/quave:custom-type-date-time/DateTimeType';
import { PlayerPositionDefinition } from './PlayerPositionEnum';
export const PlayerDefinition = createModelDefinition({
name: 'Player',
fields: {
name: {
type: String,
},
birthday: {
type: DateTimeType,
optional: true,
},
position: {
...PlayerPositionDefinition.toSimpleSchemaField(),
optional: true,
},
},
});
export const PlayerSchema = PlayerDefinition.toSimpleSchema();
You provide a name for your enum and options, the options are your static definitions in a limited domain.
Functions:
import { createEnumDefinition } from 'meteor/quave:definitions';
export const PlayerPositionDefinition = createEnumDefinition({
name: 'PlayerPosition',
options: {
GOLEIRO: {
name: 'Goleiro',
},
LATERAL_DIREITO: {
name: 'Lateral Direito',
},
LATERAL_ESQUERDO: {
name: 'Lateral Esquerdo',
},
ZAGUEIRO: {
name: 'Zagueiro',
},
VOLANTE: {
name: 'Volante',
},
MEIA: {
name: 'Meia',
},
ATACANTE: {
name: 'Atacante',
},
PONTA_DIREITA: {
name: 'Ponta Direita',
},
PONTA_ESQUERDA: {
name: 'Ponta Esquerda',
},
},
});
export const PlayerPosition = PlayerPositionDefinition.toEnum();
MIT