Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 64x 64x 1x 1x 1x 64x 1x 64x 64x 64x 59x 64x 1x 64x 1x 64x 1x 64x 64x 1x 1x 92x 92x 92x 64x 92x 27x 92x 1x 92x 92x 1x 1x 1x 1x 1x 1x 26x 26x 26x 1x 1x 1x 1x 1x 1x 16x 16x 2x 16x 1x 16x 13x 16x 16x 1x 1x 19x 19x 3x 3x 16x 16x 16x 16x 19x 13x 13x 3x 3x 3x | import { FORMULA_KEYWORDS } from '@amalia/amalia-lang/formula/keywords/shared';
import {
DateTransform,
ValueOrAttributeType,
type AttributeValue,
type ValueOrAttribute,
type ValueOrAttributeDate,
} from '@amalia/amalia-lang/formula/types';
import { TokenType } from '@amalia/amalia-lang/tokens/types';
const getAttributeValue = (attribute: AttributeValue): string => {
switch (attribute.fieldType) {
case TokenType.LINK: {
if ('machineName' in attribute) {
return `${attribute.objectMachineName}.${attribute.machineName}`;
}
return `${attribute.objectMachineName}.${attribute.relationshipMachineName}.${attribute.propertyMachineName}`;
}
case TokenType.VARIABLE:
return `statement.${attribute.machineName}`;
case TokenType.PROPERTY:
case TokenType.VIRTUAL_PROPERTY:
case TokenType.FIELD:
return `${attribute.objectMachineName}.${attribute.propertyMachineName}`;
case TokenType.QUOTA:
return `${attribute.quotaType}.${attribute.machineName}`;
case TokenType.KEYWORD:
return FORMULA_KEYWORDS[attribute.keyword].formula;
default:
throw new Error(`Attribute type not handled`);
}
};
export const getValueOrAttribute = (valueOrAttribute: ValueOrAttribute | ValueOrAttributeDate): string => {
const { type } = valueOrAttribute;
switch (type) {
case ValueOrAttributeType.ATTRIBUTE:
return getAttributeValue(valueOrAttribute);
case ValueOrAttributeType.VALUE:
return typeof valueOrAttribute.value === 'string' ? `"${valueOrAttribute.value}"` : `${valueOrAttribute.value}`;
default:
throw new Error(`Unknown ValueOrAttribute type: ${type}`);
}
};
/**
* Pick an arg object and return the right value, transform it if necessary
* String Functions
* */
export const getStringValueOrAttribute = (valueOrAttribute: ValueOrAttribute, caseSensitive = false): string => {
const arg = getValueOrAttribute(valueOrAttribute);
return caseSensitive ? arg : `LOWER(${arg})`;
};
/**
* Pick an arg object and return the right value, transform it if necessary
* Date Functions
* */
const getDateTransformOperator = (transform: DateTransform | null): string => {
switch (transform) {
case DateTransform.DAYS_AGO:
return 'daysAgo';
case DateTransform.MONTHS_AGO:
return 'monthsAgo';
default:
return '';
}
};
export const getDateValueOrAttribute = (valueOrAttribute: ValueOrAttributeDate): string => {
const arg = getValueOrAttribute(valueOrAttribute);
if (valueOrAttribute.type === ValueOrAttributeType.VALUE) {
return arg;
}
const transformOperator = getDateTransformOperator(valueOrAttribute.options.transform);
const transformValue = valueOrAttribute.options.value;
if (!transformOperator || !transformValue) {
return arg;
}
return `${transformOperator}(${arg}, ${transformValue})`;
};
|