Added denormalized computation fields
This commit is contained in:
@@ -4,7 +4,7 @@ import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.js';
|
||||
|
||||
// Get schemas that apply fields directly so they can be gracefully extended
|
||||
// because {type: Schema} fields can't be extended
|
||||
function fieldToCompute(field){
|
||||
function fieldToCompute(field) {
|
||||
const schemaObj = {
|
||||
[`${field}.calculation`]: {
|
||||
type: String,
|
||||
@@ -17,22 +17,52 @@ function fieldToCompute(field){
|
||||
return new SimpleSchema(schemaObj);
|
||||
}
|
||||
|
||||
function computedOnlyField(field){
|
||||
function computedOnlyField(field) {
|
||||
const schemaObj = {
|
||||
[`${field}.value`]: {
|
||||
// The parseNode of the compiled value before any effects are applied or rolls made
|
||||
[`${field}.unaffected`]: {
|
||||
type: Object,
|
||||
optional: true,
|
||||
blackbox: true,
|
||||
},
|
||||
/*
|
||||
// toString(.baseValue)
|
||||
[`${field}.baseValueString`]: {
|
||||
type: SimpleSchema.oneOf(String, Number),
|
||||
optional: true,
|
||||
removeBeforeCompute: true,
|
||||
},
|
||||
// A list of effects targeting this calculation
|
||||
[`${field}.effects`]: {
|
||||
*/
|
||||
// The compiled parseNode after applying all effects
|
||||
[`${field}.value`]: {
|
||||
type: Object,
|
||||
optional: true,
|
||||
blackbox: true,
|
||||
},
|
||||
/*
|
||||
// toString(.value)
|
||||
[`${field}.valueString`]: {
|
||||
type: SimpleSchema.oneOf(String, Number),
|
||||
optional: true,
|
||||
removeBeforeCompute: true,
|
||||
},
|
||||
*/
|
||||
// A list of effect Ids targeting this calculation
|
||||
[`${field}.effectIds`]: {
|
||||
type: Array,
|
||||
optional: true,
|
||||
removeBeforeCompute: true,
|
||||
},
|
||||
[`${field}.effects.$`]: {
|
||||
type: Object,
|
||||
blackbox: true,
|
||||
[`${field}.effectIds.$`]: {
|
||||
type: String,
|
||||
},
|
||||
[`${field}.proficiencyIds`]: {
|
||||
type: Array,
|
||||
optional: true,
|
||||
removeBeforeCompute: true,
|
||||
},
|
||||
[`${field}.proficiencyIds.$`]: {
|
||||
type: String,
|
||||
},
|
||||
// A cache of the parse result of the calculation
|
||||
[`${field}.parseNode`]: {
|
||||
@@ -56,7 +86,7 @@ function computedOnlyField(field){
|
||||
maxCount: STORAGE_LIMITS.errorCount,
|
||||
removeBeforeCompute: true,
|
||||
},
|
||||
[`${field}.errors.$`]:{
|
||||
[`${field}.errors.$`]: {
|
||||
type: ErrorSchema,
|
||||
},
|
||||
}
|
||||
@@ -65,9 +95,9 @@ function computedOnlyField(field){
|
||||
}
|
||||
|
||||
// We must include parent array and object fields for the schema to be valid
|
||||
function includeParentFields(field, schemaObj){
|
||||
function includeParentFields(field, schemaObj) {
|
||||
const splitField = field.split('.');
|
||||
if (splitField.length === 1){
|
||||
if (splitField.length === 1) {
|
||||
schemaObj[field] = {
|
||||
type: Object,
|
||||
optional: true,
|
||||
@@ -78,8 +108,8 @@ function includeParentFields(field, schemaObj){
|
||||
let key = '';
|
||||
splitField.push('');
|
||||
splitField.forEach((value, index) => {
|
||||
if (key){
|
||||
if (value === '$'){
|
||||
if (key) {
|
||||
if (value === '$') {
|
||||
schemaObj[key] = {
|
||||
type: Array,
|
||||
optional: true
|
||||
@@ -90,7 +120,7 @@ function includeParentFields(field, schemaObj){
|
||||
optional: true,
|
||||
};
|
||||
// the last object is the computed field
|
||||
if (index === splitField.length - 1){
|
||||
if (index === splitField.length - 1) {
|
||||
schemaObj[key].computedField = true;
|
||||
}
|
||||
}
|
||||
@@ -102,7 +132,7 @@ function includeParentFields(field, schemaObj){
|
||||
|
||||
// This should rarely be used, since the other two will merge correctly when
|
||||
// uncomputed and computedOnly schemas are merged
|
||||
function computedField(field){
|
||||
function computedField(field) {
|
||||
return computedField(field).extend(computedOnlyField(field));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user