@@ -26,11 +26,18 @@ class AsyncLogicEngine {
2626 options = { yieldSupported : false , disableInline : false , permissive : false }
2727 ) {
2828 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 }
3131 this . disableInline = options . disableInline
3232 this . async = true
3333 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
3441 }
3542
3643 /**
@@ -43,39 +50,42 @@ class AsyncLogicEngine {
4350 async _parse ( logic , context , above ) {
4451 const [ func ] = Object . keys ( logic )
4552 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 }
5462 }
63+ const result = await this . methods [ func ] ( input , context , above , this )
64+ return { result : Array . isArray ( result ) ? Promise . all ( result ) : result , func }
65+ }
5566
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 =
5970 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
6374
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 }
7577 }
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 }
7686 }
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 .` )
7989 }
8090
8191 /**
0 commit comments