@builder-builder/builder 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/validate/brand.js +3 -12
- package/package.json +1 -1
package/dist/validate/brand.js
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
import { BuilderException } from '../exception.js';
|
|
2
2
|
import { BuilderValidateErrors } from './errors.js';
|
|
3
|
-
const
|
|
3
|
+
const VALIDATED_ENTITIES = new WeakSet();
|
|
4
4
|
export function validate(value) {
|
|
5
|
-
|
|
6
|
-
// rejects any property that isn't writable, configurable, and enumerable.
|
|
7
|
-
// Symbol keys are skipped by `JSON.stringify` regardless of enumerability,
|
|
8
|
-
// so the brand never leaks through a serialise round-trip.
|
|
9
|
-
Object.defineProperty(value, VALIDATED, {
|
|
10
|
-
value: true,
|
|
11
|
-
writable: true,
|
|
12
|
-
enumerable: true,
|
|
13
|
-
configurable: true
|
|
14
|
-
});
|
|
5
|
+
VALIDATED_ENTITIES.add(value);
|
|
15
6
|
return value;
|
|
16
7
|
}
|
|
17
8
|
export function assertValidated(value) {
|
|
18
|
-
if (typeof value !== 'object' || value === null || !(
|
|
9
|
+
if (typeof value !== 'object' || value === null || !VALIDATED_ENTITIES.has(value)) {
|
|
19
10
|
const errors = new BuilderValidateErrors();
|
|
20
11
|
errors.unvalidated(value);
|
|
21
12
|
throw new BuilderException(errors.errors);
|