Skip to content
This repository was archived by the owner on Oct 20, 2021. It is now read-only.

Commit 161416e

Browse files
feat(related): Added public method getReferenceValueStored
1 parent e633597 commit 161416e

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/rules/abstract-related.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { AbstractRule } from './abstract-rule';
33

44
export abstract class AbstractRelated extends AbstractRule {
55

6+
/**
7+
* Value.
8+
*/
9+
private value: any;
10+
611
/**
712
* AbstractRelated.
813
*/
@@ -22,7 +27,16 @@ export abstract class AbstractRelated extends AbstractRule {
2227
return !this.mandatory;
2328
}
2429

25-
return !this.validator || this.validator.validate(this.getReferenceValue(input));
30+
this.value = this.getReferenceValue(input);
31+
32+
return !this.validator || this.validator.validate(this.value);
33+
}
34+
35+
/**
36+
* Get reference value stored.
37+
*/
38+
public getReferenceValueStored(): any {
39+
return this.value;
2640
}
2741

2842
/**

src/rules/key-nested.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,13 @@ export class KeyNested extends AbstractRelated {
3535
* Get value.
3636
*/
3737
protected getValue(value: any, key: any): any {
38-
if (!new Key(key).validate(value)) {
39-
throw new TypeError(`Cannot select the property ${this.reference} from the given data.`);
40-
}
38+
const ruleKey: Key = new Key(key);
4139

42-
if (value instanceof Map) {
43-
return value.get(key);
40+
if (!ruleKey.validate(value)) {
41+
throw new TypeError(`Cannot select the property ${this.reference} from the given data.`);
4442
}
4543

46-
return value[key];
44+
return ruleKey.getReferenceValueStored();
4745
}
4846

4947
/**

0 commit comments

Comments
 (0)