You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
1.1 KiB
JavaScript
23 lines
1.1 KiB
JavaScript
"use strict";
|
|
|
|
const fromEntries = require("fromentries");
|
|
const syncpipe = require("syncpipe");
|
|
|
|
const wrapError = require("@validatem/wrap-error");
|
|
const forbidden = require("@validatem/forbidden");
|
|
const allowExtraProperties = require("@validatem/allow-extra-properties");
|
|
|
|
const reservedProperties = require("../../reserved-properties");
|
|
|
|
let forbidSpecialProperty = wrapError("Reserved property name cannot be used", forbidden);
|
|
|
|
module.exports = syncpipe(reservedProperties, [
|
|
(_) => _.filter((property) => property !== "constructor"),
|
|
(_) => _.map((property) => {
|
|
// NOTE: It is very important that `forbidSpecialProperty` below is wrapped in an array. Otherwise, for the `__proto__` property, it will actually treat the entire rules object as a validatem-special object due to its __proto__ being set directly to an object with the validatem-special marker... We're hacking around this by wrapping it in an array instead, which will not register as such. It's really a hack, though.
|
|
return [ property, [ forbidSpecialProperty ] ];
|
|
}),
|
|
(_) => fromEntries(_),
|
|
(_) => allowExtraProperties(_)
|
|
]);
|