chore(prettier): full repo linting and code reformatting once and for all (#3627)
This commit is contained in:
1 parent
01500a2d4c
commit
9045ddaedc
656 files changed
+21737
-20628
No files matched your search
@@ -126,13 +126,7 @@ describe('MeasurementService.js', () => {
|
||||
|
||||
it('throws Error if no matching criteria provided', () => {
|
||||
expect(() => {
|
||||
measurementService.addMapping(
|
||||
source,
|
||||
annotationType,
|
||||
null,
|
||||
toSourceSchema,
|
||||
toMeasurement
|
||||
);
|
||||
measurementService.addMapping(source, annotationType, null, toSourceSchema, toMeasurement);
|
||||
}).toThrow(new Error('Matching criteria not provided.'));
|
||||
});
|
||||
|
||||
@@ -194,34 +188,16 @@ describe('MeasurementService.js', () => {
|
||||
toSourceSchema,
|
||||
toMeasurement
|
||||
);
|
||||
const measurementId = source.annotationToMeasurement(
|
||||
annotationType,
|
||||
annotation
|
||||
);
|
||||
const mappedAnnotation = source.getAnnotation(
|
||||
annotationType,
|
||||
measurementId
|
||||
);
|
||||
const measurementId = source.annotationToMeasurement(annotationType, annotation);
|
||||
const mappedAnnotation = source.getAnnotation(annotationType, measurementId);
|
||||
|
||||
expect(annotation).toBe(mappedAnnotation);
|
||||
});
|
||||
|
||||
it('get annotation based on source and annotationType', () => {
|
||||
measurementService.addMapping(
|
||||
source,
|
||||
annotationType,
|
||||
{},
|
||||
toSourceSchema,
|
||||
toMeasurement
|
||||
);
|
||||
const measurementId = source.annotationToMeasurement(
|
||||
annotationType,
|
||||
annotation
|
||||
);
|
||||
const mappedAnnotation = source.getAnnotation(
|
||||
annotationType,
|
||||
measurementId
|
||||
);
|
||||
measurementService.addMapping(source, annotationType, {}, toSourceSchema, toMeasurement);
|
||||
const measurementId = source.annotationToMeasurement(annotationType, annotation);
|
||||
const mappedAnnotation = source.getAnnotation(annotationType, measurementId);
|
||||
|
||||
expect(annotation).toBe(mappedAnnotation);
|
||||
});
|
||||
@@ -323,9 +299,7 @@ describe('MeasurementService.js', () => {
|
||||
|
||||
/* Add new measurement */
|
||||
source.annotationToMeasurement(annotationType, newMeasurement);
|
||||
const savedMeasurement = measurementService.getMeasurement(
|
||||
newMeasurement.uid
|
||||
);
|
||||
const savedMeasurement = measurementService.getMeasurement(newMeasurement.uid);
|
||||
|
||||
/* Clear dynamic data */
|
||||
delete newMeasurement.modifiedTimestamp;
|
||||
@@ -384,10 +358,7 @@ describe('MeasurementService.js', () => {
|
||||
let addCallbackWasCalled = false;
|
||||
|
||||
/* Subscribe to add event */
|
||||
measurementService.subscribe(
|
||||
MEASUREMENT_ADDED,
|
||||
() => (addCallbackWasCalled = true)
|
||||
);
|
||||
measurementService.subscribe(MEASUREMENT_ADDED, () => (addCallbackWasCalled = true));
|
||||
|
||||
/* Add new measurement - two calls needed for the start and the other for the completed*/
|
||||
const uid = source.annotationToMeasurement(annotationType, measurement);
|
||||
@@ -409,20 +380,13 @@ describe('MeasurementService.js', () => {
|
||||
let updateCallbackWasCalled = false;
|
||||
|
||||
/* Subscribe to update event */
|
||||
measurementService.subscribe(
|
||||
MEASUREMENT_UPDATED,
|
||||
() => (updateCallbackWasCalled = true)
|
||||
);
|
||||
measurementService.subscribe(MEASUREMENT_UPDATED, () => (updateCallbackWasCalled = true));
|
||||
|
||||
/* Create measurement */
|
||||
const uid = source.annotationToMeasurement(annotationType, measurement);
|
||||
|
||||
/* Update measurement */
|
||||
source.annotationToMeasurement(
|
||||
annotationType,
|
||||
{ uid, ...measurement },
|
||||
true
|
||||
);
|
||||
source.annotationToMeasurement(annotationType, { uid, ...measurement }, true);
|
||||
|
||||
expect(updateCallbackWasCalled).toBe(true);
|
||||
});
|
||||
@@ -468,10 +432,7 @@ describe('MeasurementService.js', () => {
|
||||
let addCallbackWasCalled = false;
|
||||
|
||||
/* Subscribe to add event */
|
||||
measurementService.subscribe(
|
||||
MEASUREMENT_ADDED,
|
||||
() => (addCallbackWasCalled = true)
|
||||
);
|
||||
measurementService.subscribe(MEASUREMENT_ADDED, () => (addCallbackWasCalled = true));
|
||||
|
||||
/* Add new measurement - two calls needed for the start and the other for the completed*/
|
||||
// expect exceptions for unmapped measurements
|
||||
@@ -502,10 +463,7 @@ describe('MeasurementService.js', () => {
|
||||
let removeCallbackWasCalled = false;
|
||||
|
||||
/* Subscribe to add event */
|
||||
measurementService.subscribe(
|
||||
MEASUREMENT_REMOVED,
|
||||
() => (removeCallbackWasCalled = true)
|
||||
);
|
||||
measurementService.subscribe(MEASUREMENT_REMOVED, () => (removeCallbackWasCalled = true));
|
||||
|
||||
/* Add new measurement - two calls needed for the start and the other for the completed*/
|
||||
// expect exceptions for unmapped measurements
|
||||
|
||||
@@ -146,9 +146,7 @@ class MeasurementService extends PubSubService {
|
||||
|
||||
// check if valuetype is valid , and if values are strings
|
||||
if (!valueType || typeof valueType !== 'object') {
|
||||
console.warn(
|
||||
`MeasurementService: addValueType: invalid valueType: ${valueType}`
|
||||
);
|
||||
console.warn(`MeasurementService: addValueType: invalid valueType: ${valueType}`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -178,10 +176,7 @@ class MeasurementService extends PubSubService {
|
||||
return this.measurements.get(measurementUID);
|
||||
}
|
||||
|
||||
public setMeasurementSelected(
|
||||
measurementUID: string,
|
||||
selected: boolean
|
||||
): void {
|
||||
public setMeasurementSelected(measurementUID: string, selected: boolean): void {
|
||||
const measurement = this.getMeasurement(measurementUID);
|
||||
if (!measurement) {
|
||||
return;
|
||||
@@ -230,17 +225,8 @@ class MeasurementService extends PubSubService {
|
||||
version,
|
||||
};
|
||||
|
||||
source.annotationToMeasurement = (
|
||||
annotationType,
|
||||
annotation,
|
||||
isUpdate = false
|
||||
) => {
|
||||
return this.annotationToMeasurement(
|
||||
source,
|
||||
annotationType,
|
||||
annotation,
|
||||
isUpdate
|
||||
);
|
||||
source.annotationToMeasurement = (annotationType, annotation, isUpdate = false) => {
|
||||
return this.annotationToMeasurement(source, annotationType, annotation, isUpdate);
|
||||
};
|
||||
|
||||
source.remove = (measurementUID, eventDetails) => {
|
||||
@@ -281,13 +267,7 @@ class MeasurementService extends PubSubService {
|
||||
* @param {Function} toMeasurementSchema Mapping function to measurement schema
|
||||
* @return void
|
||||
*/
|
||||
addMapping(
|
||||
source,
|
||||
annotationType,
|
||||
matchingCriteria,
|
||||
toAnnotationSchema,
|
||||
toMeasurementSchema
|
||||
) {
|
||||
addMapping(source, annotationType, matchingCriteria, toAnnotationSchema, toMeasurementSchema) {
|
||||
if (!this._isValidSource(source)) {
|
||||
throw new Error('Invalid source.');
|
||||
}
|
||||
@@ -321,11 +301,7 @@ class MeasurementService extends PubSubService {
|
||||
this.mappings[source.uid] = [mapping];
|
||||
}
|
||||
|
||||
log.info(
|
||||
`New measurement mapping added to source '${this._getSourceToString(
|
||||
source
|
||||
)}'.`
|
||||
);
|
||||
log.info(`New measurement mapping added to source '${this._getSourceToString(source)}'.`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -348,20 +324,13 @@ class MeasurementService extends PubSubService {
|
||||
}
|
||||
|
||||
const measurement = this.getMeasurement(measurementUID);
|
||||
const mapping = this._getMappingByMeasurementSource(
|
||||
measurement,
|
||||
annotationType
|
||||
);
|
||||
const mapping = this._getMappingByMeasurementSource(measurement, annotationType);
|
||||
|
||||
if (mapping) {
|
||||
return mapping.toAnnotationSchema(measurement, annotationType);
|
||||
}
|
||||
|
||||
const matchingMapping = this._getMatchingMapping(
|
||||
source,
|
||||
annotationType,
|
||||
measurement
|
||||
);
|
||||
const matchingMapping = this._getMatchingMapping(source, annotationType, measurement);
|
||||
|
||||
if (matchingMapping) {
|
||||
log.info('Matching mapping found:', matchingMapping);
|
||||
@@ -380,10 +349,7 @@ class MeasurementService extends PubSubService {
|
||||
modifiedTimestamp: Math.floor(Date.now() / 1000),
|
||||
};
|
||||
|
||||
log.info(
|
||||
`Updating internal measurement representation...`,
|
||||
updatedMeasurement
|
||||
);
|
||||
log.info(`Updating internal measurement representation...`, updatedMeasurement);
|
||||
|
||||
this.measurements.set(measurementUID, updatedMeasurement);
|
||||
|
||||
@@ -405,13 +371,7 @@ class MeasurementService extends PubSubService {
|
||||
* @param {object} data The data you wish to add to the source.
|
||||
* @param {function} toMeasurementSchema A function to get the `data` into the same shape as the source annotationType.
|
||||
*/
|
||||
addRawMeasurement(
|
||||
source,
|
||||
annotationType,
|
||||
data,
|
||||
toMeasurementSchema,
|
||||
dataSource = {}
|
||||
) {
|
||||
addRawMeasurement(source, annotationType, data, toMeasurementSchema, dataSource = {}) {
|
||||
if (!this._isValidSource(source)) {
|
||||
log.warn('Invalid source. Exiting early.');
|
||||
return;
|
||||
@@ -425,9 +385,7 @@ class MeasurementService extends PubSubService {
|
||||
}
|
||||
|
||||
if (!this._sourceHasMappings(source)) {
|
||||
log.warn(
|
||||
`No measurement mappings found for '${sourceInfo}' source. Exiting early.`
|
||||
);
|
||||
log.warn(`No measurement mappings found for '${sourceInfo}' source. Exiting early.`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -496,12 +454,7 @@ class MeasurementService extends PubSubService {
|
||||
* @param {boolean} isUpdate is this an update or an add/completed instead?
|
||||
* @return {string} A measurement uid
|
||||
*/
|
||||
annotationToMeasurement(
|
||||
source,
|
||||
annotationType,
|
||||
sourceAnnotationDetail,
|
||||
isUpdate = false
|
||||
) {
|
||||
annotationToMeasurement(source, annotationType, sourceAnnotationDetail, isUpdate = false) {
|
||||
if (!this._isValidSource(source)) {
|
||||
throw new Error('Invalid source.');
|
||||
}
|
||||
@@ -512,9 +465,7 @@ class MeasurementService extends PubSubService {
|
||||
const sourceInfo = this._getSourceToString(source);
|
||||
|
||||
if (!this._sourceHasMappings(source)) {
|
||||
throw new Error(
|
||||
`No measurement mappings found for '${sourceInfo}' source. Exiting early.`
|
||||
);
|
||||
throw new Error(`No measurement mappings found for '${sourceInfo}' source. Exiting early.`);
|
||||
}
|
||||
|
||||
let measurement = {};
|
||||
@@ -599,8 +550,7 @@ class MeasurementService extends PubSubService {
|
||||
remove(measurementUID, source, eventDetails) {
|
||||
if (
|
||||
!measurementUID ||
|
||||
(!this.measurements.has(measurementUID) &&
|
||||
!this.unmappedMeasurements.has(measurementUID))
|
||||
(!this.measurements.has(measurementUID) && !this.unmappedMeasurements.has(measurementUID))
|
||||
) {
|
||||
log.warn(`No uid provided, or unable to find measurement by uid.`);
|
||||
return;
|
||||
@@ -679,9 +629,7 @@ class MeasurementService extends PubSubService {
|
||||
|
||||
_getMappingByMeasurementSource(measurement, annotationType) {
|
||||
if (this._isValidSource(measurement.source)) {
|
||||
return this.mappings[measurement.source.uid].find(
|
||||
m => m.annotationType === annotationType
|
||||
);
|
||||
return this.mappings[measurement.source.uid].find(m => m.annotationType === annotationType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -702,10 +650,7 @@ class MeasurementService extends PubSubService {
|
||||
|
||||
/* Criteria Matching */
|
||||
return sourceMappingsByDefinition.find(({ matchingCriteria }) => {
|
||||
return (
|
||||
measurement.points &&
|
||||
measurement.points.length === matchingCriteria.points
|
||||
);
|
||||
return measurement.points && measurement.points.length === matchingCriteria.points;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -736,10 +681,7 @@ class MeasurementService extends PubSubService {
|
||||
* @return {boolean} Validation if source has mappings
|
||||
*/
|
||||
_sourceHasMappings(source) {
|
||||
return (
|
||||
Array.isArray(this.mappings[source.uid]) &&
|
||||
this.mappings[source.uid].length
|
||||
);
|
||||
return Array.isArray(this.mappings[source.uid]) && this.mappings[source.uid].length;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user