@@ -26,11 +26,18 @@ class AsyncLogicEngine {
26
26
options = { yieldSupported : false , disableInline : false , permissive : false }
27
27
) {
28
28
this . methods = { ...methods }
29
- /** @type {{yieldSupported?: Boolean, disableInline?: Boolean, permissive?: boolean } } */
30
- this . options = { ... options }
29
+ /** @type {{yieldSupported?: Boolean, disableInline?: Boolean } } */
30
+ this . options = { yieldSupported : options . yieldSupported , disableInline : options . disableInline }
31
31
this . disableInline = options . disableInline
32
32
this . async = true
33
33
this . fallback = new LogicEngine ( methods , options )
34
+
35
+ if ( ! this . isData ) {
36
+ if ( ! options . permissive ) this . isData = ( ) => false
37
+ else this . isData = ( data , key ) => ! ( key in this . methods )
38
+ }
39
+
40
+ this . fallback . isData = this . isData
34
41
}
35
42
36
43
/**
@@ -43,39 +50,42 @@ class AsyncLogicEngine {
43
50
async _parse ( logic , context , above ) {
44
51
const [ func ] = Object . keys ( logic )
45
52
const data = logic [ func ]
46
- if ( this . methods [ func ] ) {
47
- if ( typeof this . methods [ func ] === 'function' ) {
48
- const input = await this . run ( data , context , { above } )
49
- if ( this . options . yieldSupported && ( await checkYield ( input ) ) ) {
50
- return { result : input , func }
51
- }
52
- const result = await this . methods [ func ] ( input , context , above , this )
53
- return { result : Array . isArray ( result ) ? Promise . all ( result ) : result , func }
53
+
54
+ if ( this . isData ( logic , func ) ) return { result : logic , func }
55
+
56
+ if ( ! this . methods [ func ] ) throw new Error ( `Method '${ func } ' was not found in the Logic Engine.` )
57
+
58
+ if ( typeof this . methods [ func ] === 'function' ) {
59
+ const input = await this . run ( data , context , { above } )
60
+ if ( this . options . yieldSupported && ( await checkYield ( input ) ) ) {
61
+ return { result : input , func }
54
62
}
63
+ const result = await this . methods [ func ] ( input , context , above , this )
64
+ return { result : Array . isArray ( result ) ? Promise . all ( result ) : result , func }
65
+ }
55
66
56
- if ( typeof this . methods [ func ] === 'object' ) {
57
- const { asyncMethod, method, traverse } = this . methods [ func ]
58
- const shouldTraverse =
67
+ if ( typeof this . methods [ func ] === 'object' ) {
68
+ const { asyncMethod, method, traverse } = this . methods [ func ]
69
+ const shouldTraverse =
59
70
typeof traverse === 'undefined' ? true : traverse
60
- const parsedData = shouldTraverse
61
- ? await this . run ( data , context , { above } )
62
- : data
71
+ const parsedData = shouldTraverse
72
+ ? await this . run ( data , context , { above } )
73
+ : data
63
74
64
- if ( this . options . yieldSupported && ( await checkYield ( parsedData ) ) ) {
65
- return { result : parsedData , func }
66
- }
67
-
68
- const result = await ( asyncMethod || method ) (
69
- parsedData ,
70
- context ,
71
- above ,
72
- this
73
- )
74
- return { result : Array . isArray ( result ) ? Promise . all ( result ) : result , func }
75
+ if ( this . options . yieldSupported && ( await checkYield ( parsedData ) ) ) {
76
+ return { result : parsedData , func }
75
77
}
78
+
79
+ const result = await ( asyncMethod || method ) (
80
+ parsedData ,
81
+ context ,
82
+ above ,
83
+ this
84
+ )
85
+ return { result : Array . isArray ( result ) ? Promise . all ( result ) : result , func }
76
86
}
77
- if ( this . options . permissive ) return { result : logic , func }
78
- throw new Error ( `Method '${ func } ' was not found in the Logic Engine .` )
87
+
88
+ throw new Error ( `Method '${ func } ' is not set up properly .` )
79
89
}
80
90
81
91
/**
0 commit comments