Refactored schemas to make properties all implicitely children

This commit is contained in:
Stefan Zermatten
2019-04-03 12:38:01 +02:00
parent 28ffcc87b4
commit 681e669e76
19 changed files with 37 additions and 62 deletions

View File

@@ -3,7 +3,6 @@ import schema from '/imports/api/schema.js';
import AdjustmentSchema from '/imports/api/creature/subSchemas/AdjustmentSchema.js';
import StoredBuffSchema from '/imports/api/creature/properties/Buffs.js';
import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js';
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
import ColorSchema from '/imports/api/creature/subSchemas/ColorSchema.js';
// Mixins
@@ -92,7 +91,6 @@ ActionSchema.extend(ColorSchema);
Actions.attachSchema(ActionSchema);
Actions.attachSchema(PropertySchema);
Actions.attachSchema(ChildSchema);
const insertAction = new ValidatedMethod({
name: 'Actions.methods.insert',

View File

@@ -1,5 +1,4 @@
import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js';
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
import ColorSchema from '/imports/api/creature/subSchemas/ColorSchema.js';
import SimpleSchema from 'simpl-schema';
import schema from '/imports/api/schema.js';
@@ -93,9 +92,8 @@ const ComputedAttributeSchema = schema({
},
}).extend(AttributeSchema);
Attributes.attachSchema(PropertySchema);
Attributes.attachSchema(ComputedAttributeSchema);
Attributes.attachSchema(ChildSchema);
Attributes.attachSchema(PropertySchema);
const insertAttribute = new ValidatedMethod({
name: 'Attributes.methods.insert',

View File

@@ -1,7 +1,6 @@
import SimpleSchema from 'simpl-schema';
import schema from '/imports/api/schema.js';
import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js';
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
import { EffectSchema } from '/imports/api/creature/properties/Effects.js';
// Mixins
@@ -79,7 +78,6 @@ let AppliedBuffSchema = schema({
Buffs.attachSchema(AppliedBuffSchema);
Buffs.attachSchema(PropertySchema);
Buffs.attachSchema(ChildSchema);
const insertBuff = new ValidatedMethod({
name: 'Buffs.methods.insert',

View File

@@ -1,7 +1,6 @@
import SimpleSchema from 'simpl-schema';
import schema from '/imports/api/schema.js';
import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js';
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX.js';
// Mixins
@@ -48,7 +47,6 @@ let ClassLevelSchema = schema({
ClassLevels.attachSchema(ClassLevelSchema);
ClassLevels.attachSchema(PropertySchema);
ClassLevels.attachSchema(ChildSchema);
// Todo ensure the class level is being parented to a compatible class, and that
// previous level requirements are met

View File

@@ -1,7 +1,6 @@
import SimpleSchema from 'simpl-schema';
import schema from '/imports/api/schema.js';
import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js';
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
import ColorSchema from "/imports/api/creature/subSchemas/ColorSchema.js";
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX.js';
@@ -31,7 +30,6 @@ ClassSchema.extend(ColorSchema);
Classes.attachSchema(ClassSchema);
Classes.attachSchema(PropertySchema);
Classes.attachSchema(ChildSchema);
const insertClass = new ValidatedMethod({
name: 'Classes.methods.insert',

View File

@@ -1,7 +1,6 @@
import SimpleSchema from 'simpl-schema';
import schema from '/imports/api/schema.js';
import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js';
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
import DAMAGE_TYPES from '/imports/constants/DAMAGE_TYPES.js';
// Mixins
@@ -39,7 +38,6 @@ let DamageMultiplierSchema = schema({
DamageMultipliers.attachSchema(DamageMultiplierSchema);
DamageMultipliers.attachSchema(PropertySchema);
DamageMultipliers.attachSchema(ChildSchema);
const insertDamageMultiplier = new ValidatedMethod({
name: 'DamageMultipliers.methods.insert',

View File

@@ -1,7 +1,6 @@
import SimpleSchema from 'simpl-schema';
import schema from '/imports/api/schema.js';
import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js';
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
// Mixins
import recomputeCreatureMixin from '/imports/api/mixins/recomputeCreatureMixin.js';
@@ -58,9 +57,8 @@ const EffectComputedSchema = new SimpleSchema({
},
}).extend(EffectSchema);
Effects.attachSchema(PropertySchema);
Effects.attachSchema(ChildSchema);
Effects.attachSchema(EffectComputedSchema);
Effects.attachSchema(PropertySchema);
const insertEffect = new ValidatedMethod({
name: 'Effects.methods.insert',

View File

@@ -48,8 +48,8 @@ let ExperienceSchema = schema({
},
});
Experiences.attachSchema(PropertySchema);
Experiences.attachSchema(ExperienceSchema);
Experiences.attachSchema(PropertySchema);
const insertExperience = new ValidatedMethod({
name: 'Experiences.methods.insert',

View File

@@ -1,10 +1,6 @@
import SimpleSchema from 'simpl-schema';
import schema from '/imports/api/schema.js';
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
import { recomputeCreatureById } from '/imports/api/creature/creatureComputation.js'
import { getHighestOrder } from '/imports/api/order/order.js';
import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js';
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
import ColorSchema from '/imports/api/creature/subSchemas/ColorSchema.js';
// Mixins
@@ -38,12 +34,8 @@ let FeatureSchema = new SimpleSchema({
FeatureSchema.extend(ColorSchema);
Features.attachSchema(
schema(FeatureSchema)
.extend(PropertySchema)
.extend(ChildSchema)
);
Features.attachSchema(FeatureSchema);
Features.attachSchema(PropertySchema);
const insertFeature = new ValidatedMethod({
name: 'Features.methods.insert',
@@ -65,8 +57,8 @@ const insertFeature = new ValidatedMethod({
const updateFeature = new ValidatedMethod({
name: 'Features.methods.update',
mixins: [
updateSchemaMixin,
propagateInheritanceUpdateMixin,
updateSchemaMixin,
creaturePermissionMixin,
],
collection: Features,

View File

@@ -1,7 +1,6 @@
import SimpleSchema from 'simpl-schema';
import schema from '/imports/api/schema.js';
import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js';
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
// Mixins
import creaturePermissionMixin from '/imports/api/mixins/creaturePermissionMixin.js';
@@ -24,10 +23,10 @@ let FolderSchema = schema({
type: Boolean,
defaultValue: true,
},
}).extend(PropertySchema);
});
Folders.attachSchema(FolderSchema);
Folders.attachSchema(ChildSchema);
Folders.attachSchema(PropertySchema);
const insertFolder = new ValidatedMethod({
name: 'Folders.methods.insert',

View File

@@ -1,7 +1,6 @@
import SimpleSchema from 'simpl-schema';
import schema from '/imports/api/schema.js';
import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js';
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
// Mixins
import recomputeCreatureMixin from '/imports/api/mixins/recomputeCreatureMixin.js';
@@ -34,7 +33,6 @@ let ProficiencySchema = schema({
Proficiencies.attachSchema(ProficiencySchema);
Proficiencies.attachSchema(PropertySchema);
Proficiencies.attachSchema(ChildSchema);
const insertProficiency = new ValidatedMethod({
name: 'Proficiencies.methods.insert',

View File

@@ -1,6 +1,5 @@
import SimpleSchema from 'simpl-schema';
import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js';
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
import AdjustmentSchema from '/imports/api/creature/subSchemas/AdjustmentSchema.js';
import StoredBuffSchema from '/imports/api/creature/properties/Buffs.js';
@@ -95,7 +94,6 @@ let RollSchema = new SimpleSchema({
Rolls.attachSchema(RollSchema);
Rolls.attachSchema(PropertySchema);
Rolls.attachSchema(ChildSchema);
const insertRoll = new ValidatedMethod({
name: 'Rolls.methods.insert',

View File

@@ -1,7 +1,6 @@
import SimpleSchema from 'simpl-schema';
import schema from '/imports/api/schema.js';
import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js';
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
import ColorSchema from '/imports/api/creature/subSchemas/ColorSchema.js';
// Mixins
@@ -103,7 +102,6 @@ let ComputedSkillSchema = schema({
Skills.attachSchema(ComputedSkillSchema);
Skills.attachSchema(PropertySchema);
Skills.attachSchema(ChildSchema);
const insertSkill = new ValidatedMethod({
name: 'Skills.methods.insert',

View File

@@ -2,7 +2,6 @@ import SimpleSchema from 'simpl-schema';
import schema from '/imports/api/schema.js';
import ColorSchema from "/imports/api/creature/subSchemas/ColorSchema.js";
import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js';
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
// Mixins
import creaturePermissionMixin from '/imports/api/mixins/creaturePermissionMixin.js';
@@ -44,7 +43,6 @@ SpellListSchema.extend(ColorSchema);
SpellLists.attachSchema(SpellListSchema);
SpellLists.attachSchema(PropertySchema);
SpellLists.attachSchema(ChildSchema);
const insertSpellList = new ValidatedMethod({
name: 'SpellLists.methods.insert',

View File

@@ -2,7 +2,6 @@ import ColorSchema from '/imports/api/creature/subSchemas/ColorSchema.js';
import SimpleSchema from 'simpl-schema';
import schema from '/imports/api/schema.js';
import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js';
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
// Mixins
import creaturePermissionMixin from '/imports/api/mixins/creaturePermissionMixin.js';
@@ -95,7 +94,6 @@ SpellSchema.extend(ColorSchema);
Spells.attachSchema(SpellSchema);
Spells.attachSchema(PropertySchema);
Spells.attachSchema(ChildSchema);
const insertSpell = new ValidatedMethod({
name: 'Spells.methods.insert',

View File

@@ -1,9 +1,9 @@
import updateAction from '/imports/api/creature/properties/Actions.js';
import updateAttribute from '/imports/api/creature/properties/Attributes.js';
import updateBuff from '/imports/api/creature/properties/Buff.js';
import updateBuff from '/imports/api/creature/properties/Buffs.js';
import updateClass from '/imports/api/creature/properties/Classes.js';
import updateClassLevel from '/imports/api/creature/properties/ClassLevels.js';
import updateDamageMiliplier from '/imports/api/creature/properties/DamageMilipliers.js';
import updateDamageMultiplier from '/imports/api/creature/properties/DamageMultipliers.js';
import updateEffect from '/imports/api/creature/properties/Effects.js';
import updateExperience from '/imports/api/creature/properties/Experiences.js';
import updateFeature from '/imports/api/creature/properties/Features.js';
@@ -21,7 +21,7 @@ export default Object.freeze({
buffs: updateBuff,
classs: updateClass,
classLevels: updateClassLevel,
damageMilipliers: updateDamageMiliplier,
damageMultipliers: updateDamageMultiplier,
effects: updateEffect,
experiences: updateExperience,
features: updateFeature,

View File

@@ -1,5 +1,6 @@
import SimpleSchema from 'simpl-schema';
import SoftRemovableSchema from '/imports/api/parenting/SoftRemovableSchema.js';
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
const PropertySchema = new SimpleSchema({
charId: {
@@ -8,14 +9,14 @@ const PropertySchema = new SimpleSchema({
index: 1,
optional: true,
},
name: {
type: String,
optional: true,
},
enabled: {
type: Boolean,
defaultValue: true,
},
name: {
type: String,
optional: true,
},
order: {
type: SimpleSchema.Integer,
index: true,
@@ -23,5 +24,6 @@ const PropertySchema = new SimpleSchema({
});
PropertySchema.extend(SoftRemovableSchema);
PropertySchema.extend(ChildSchema);
export default PropertySchema;

View File

@@ -51,13 +51,16 @@ export default function updateSchemaMixin(methodOptions) {
// Set up the new validation
methodOptions.validate = function(args){
argumentSchema.validate(args);
updateSchema.validate(args.update, methodOptions.schemaValidatorOptions);
updateSchema.validate(
{$set: args.update},
methodOptions.schemaValidatorOptions
);
};
// Give a default run function if one isn't supplied
if (!methodOptions.run){
methodOptions.run = function({_id, update}){
return MethodOptions.collection.update(_id, {$set: update});
return methodOptions.collection.update(_id, {$set: update});
};
}
return methodOptions;

View File

@@ -1,15 +1,7 @@
import SimpleSchema from 'simpl-schema';
import schema from '/imports/api/schema.js';
const RefSchema = new SimpleSchema({
id: {
type: String,
regEx: SimpleSchema.RegEx.Id,
index: 1
},
collection: {
type: String
},
const inhertitedFieldsSchema = new SimpleSchema({
name: {
type: String,
optional: true,
@@ -21,6 +13,19 @@ const RefSchema = new SimpleSchema({
},
});
const RefSchema = new SimpleSchema({
id: {
type: String,
regEx: SimpleSchema.RegEx.Id,
index: 1
},
collection: {
type: String
},
});
RefSchema.extend(inhertitedFieldsSchema);
let ChildSchema = schema({
parent: {
type: RefSchema,
@@ -35,9 +40,7 @@ let ChildSchema = schema({
},
});
const inheritedFields = new Set(RefSchema.objectKeys());
inheritedFields.delete('id');
inheritedFields.delete('collection');
const inheritedFields = new Set(inhertitedFieldsSchema.objectKeys());
export default ChildSchema;
export { inheritedFields };