Verify numeric schema boundaries instead of assuming integer coercion
In total5@0.0.19, the compact numeric types all enter the native number validator. Int does not guarantee an integer: 7.9 is preserved. Number2 also preserves this fraction; do not interpret its name as rounding to two decimal places. Required numeric zero is accepted.
TinyInt accepts values from 0 through 255. SmallInt accepts -32767 through 32767; notably, -32768 is rejected in this version. These subtype checks enforce bounds but do not require integral values: TinyInt accepts 1.5. Apply an explicit Number.isInteger() check for identifiers, counters or quantities that must be integers. These observations describe this version and the tested values, not SQL column semantics.
var schema = NEWSCHEMA('NumericBoundaries', '*integer:Int,*small:SmallInt,*tiny:TinyInt,*decimal:Number2');
exports.install = function() {
ROUTE('POST /numbers/ @json', numbers);
};
function numbers($) {
var result = schema.transform($.body);
if (result.error) {
$.response.status = 400;
$.json({ error: 'invalid numeric input' });
return;
}
$.json(result.response);
}