in src/parsers/clause-parsers.ts [220:266]
private odataExpressionFromValue(field: WorkItemFieldReference, value: string): string {
// first, clean up any special values.
const macrosInValue = value.match(/^@([A-Za-z]+)/g) || [];
macrosInValue.forEach((macro) => {
switch (macro.toLocaleLowerCase()) {
case '@me':
value = value.replace(macro, this.webContext.user.email);
NotesService.instance.newNote('warning', `There is no OData equivalent for @me. Replacing with the static value of '${value}'.`);
break;
case '@project':
value = value.replace(macro, this.webContext.project.name);
NotesService.instance.newNote('warning', `There is no OData equivalent for @project. Replacing with the static value of '${value}'.`);
break;
case '@today':
const dateText = value.trim().toLocaleLowerCase();
if (dateText.length === '@today'.length) {
// If there are no arithmetic operations, we can use now().
value = 'date(now())';
} else {
// Arithmetic operations are currently not supported by VSTS OData. Replace with static value.
const matches = dateText.match(/@today ?([-+]) ?([0-9]+)/);
const theDate = new Date(Date.now());
theDate.setDate(theDate.getDate() + parseInt(`${matches[1]}${matches[2]}`, 10));
value = theDate.toISOString();
NotesService.instance.newNote('warning', `Arithmetic operations on @today are not supported by OData at this time. Replacing with the static value of '${value}'.`);
}
break;
default:
NotesService.instance.newNote('warning', `There is no OData equivalent for ${macro}. Please manually replace the value in your OData query.`);
break;
}
});
const oDataType = this.metadata[field.referenceName].type;
// Replace math operations for certain data types where math is allowed.
if (this.mathAllowedTypes.includes(oDataType)) {
value = value.replace(/ ?- ?/, ' sub ');
value = value.replace(/ ?\+ ?/, ' add ');
value = value.replace(/ ?\* ?/, ' mul ');
value = value.replace(/ ?\/ ?/, ' div ');
}
// Send to handler for type.
const handler = this.supportedTypesHandlingMap[oDataType];
return handler.handler(value);
}