Created
February 18, 2023 22:59
-
-
Save eser/e14ad84a50a03db19ccd2d7942e3315d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validateModel(): void { | |
this.logger.debug(`validating model for ${this.name}`); | |
asserts.assertExists(this.name, "name is required"); | |
asserts.assert(this.name.length > 0, "name is required"); | |
asserts.assertExists(this.version, "version is required"); | |
asserts.assert(this.version.length > 0, "version is required"); | |
const integrationFeatures = [ | |
"predefinedMetrics", | |
"queryable", | |
"multipleAccounts", | |
"clientRn", | |
"clientWeb", | |
]; | |
integrationFeatures.forEach((feature) => { | |
asserts.assertExists( | |
this.features[feature], | |
`features.${feature} is required`, | |
); | |
asserts.assert( | |
Object.values(FeatureType).includes(this.features[feature]), | |
`features.${feature} is required`, | |
); | |
}); | |
asserts.assertExists( | |
this.parameters, | |
"parameters is required", | |
); | |
if ( | |
[FeatureType.Available, FeatureType.Premium].includes( | |
this.features.predefinedMetrics, | |
) | |
) { | |
asserts.assertExists( | |
this.predefinedMetrics, | |
"predefinedMetrics is required", | |
); | |
asserts.assert( | |
this.predefinedMetrics.length > 0, | |
"predefinedMetrics is required", | |
); | |
} | |
for ( | |
const [predefinedMetricIdx, predefinedMetric] of Object.entries( | |
this.predefinedMetrics, | |
) | |
) { | |
asserts.assertExists( | |
predefinedMetric.id, | |
`predefinedMetric[${predefinedMetricIdx}].id is required`, | |
); | |
asserts.assert( | |
predefinedMetric.id.length > 0, | |
`predefinedMetric[${predefinedMetricIdx}].id is required`, | |
); | |
asserts.assertExists( | |
predefinedMetric.title, | |
`predefinedMetric[${predefinedMetricIdx}].title is required`, | |
); | |
asserts.assert( | |
predefinedMetric.title.length > 0, | |
`predefinedMetric[${predefinedMetricIdx}].title is required`, | |
); | |
asserts.assertExists( | |
predefinedMetric.features, | |
`predefinedMetric[${predefinedMetricIdx}].features is required`, | |
); | |
asserts.assert( | |
predefinedMetric.features instanceof Object, | |
`predefinedMetric[${predefinedMetricIdx}].features should be an object`, | |
); | |
asserts.assertExists( | |
predefinedMetric.features.add, | |
`predefinedMetric[${predefinedMetricIdx}].features.add is required`, | |
); | |
asserts.assert( | |
Object.values(FeatureType).includes(predefinedMetric.features.add), | |
`predefinedMetric[${predefinedMetricIdx}].features.add is required`, | |
); | |
asserts.assertExists( | |
predefinedMetric.features.history, | |
`predefinedMetric[${predefinedMetricIdx}].features.history is required`, | |
); | |
asserts.assert( | |
Object.values(FeatureType).includes(predefinedMetric.features.history), | |
`predefinedMetric[${predefinedMetricIdx}].features.history is required`, | |
); | |
asserts.assertExists( | |
predefinedMetric.features.aggregate, | |
`predefinedMetric[${predefinedMetricIdx}].features.aggregate is required`, | |
); | |
asserts.assert( | |
Object.values(FeatureType).includes( | |
predefinedMetric.features.aggregate, | |
), | |
`predefinedMetric[${predefinedMetricIdx}].features.aggregate is required`, | |
); | |
asserts.assertExists( | |
predefinedMetric.fields, | |
`predefinedMetric[${predefinedMetricIdx}].fields is required`, | |
); | |
asserts.assert( | |
predefinedMetric.fields.length > 0, | |
`predefinedMetric[${predefinedMetricIdx}].fields is required`, | |
); | |
asserts.assert( | |
predefinedMetric.fields.some((field) => field.id === "value"), | |
`predefinedMetric[${predefinedMetricIdx}].fields must contain a field named as value`, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment