This repository was archived by the owner on Oct 20, 2021. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,11 @@ import { AbstractRule } from './abstract-rule';
33
44export 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 /**
Original file line number Diff line number Diff 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 /**
You can’t perform that action at this time.
0 commit comments