@@ -10,6 +10,7 @@ import {
10
10
isMyCustomAction ,
11
11
MultiBaseComp ,
12
12
wrapChildAction ,
13
+ evalFunc ,
13
14
} from "lowcoder-core" ;
14
15
import {
15
16
Dropdown ,
@@ -34,6 +35,9 @@ import {
34
35
ToInstanceType ,
35
36
} from "../generators/multi" ;
36
37
import { toQueryView } from "./queryCompUtils" ;
38
+ import { getGlobalSettings } from "comps/utils/globalSettings" ;
39
+ import { QUERY_EXECUTION_ERROR , QUERY_EXECUTION_OK } from "../../constants/queryConstants" ;
40
+ import type { SandBoxOption } from "lowcoder-core/src/eval/utils/evalScript" ;
37
41
38
42
const NoInputsWrapper = styled . div `
39
43
color: ${ GreyTextColor } ;
@@ -133,13 +137,60 @@ export const LibraryQuery = class extends LibraryQueryBase {
133
137
readonly isReady : boolean = false ;
134
138
135
139
private value : DataType | undefined ;
140
+ private queryInfo : any = null ;
136
141
137
142
constructor ( params : CompParams < DataType > ) {
138
143
super ( params ) ;
139
144
this . value = params . value ;
140
145
}
141
146
142
147
override getView ( ) {
148
+ // Check if this is a JS query
149
+ if ( this . queryInfo ?. query ?. compType === "js" ) {
150
+ return async ( props : any ) => {
151
+ try {
152
+ const { orgCommonSettings } = getGlobalSettings ( ) ;
153
+ const runInHost = ! ! orgCommonSettings ?. runJavaScriptInHost ;
154
+ const timer = performance . now ( ) ;
155
+ const script = this . queryInfo . query . comp . script || "" ;
156
+ const options : SandBoxOption = { disableLimit : runInHost } ;
157
+
158
+ // Get input values from the inputs component
159
+ const inputValues = Object . entries ( this . children . inputs . children ) . reduce ( ( acc , [ name , input ] ) => {
160
+ // Get the actual value from the input component's text property
161
+ const value = input . children . text . getView ( ) ;
162
+ acc [ name ] = value ;
163
+ return acc ;
164
+ } , { } as Record < string , any > ) ;
165
+
166
+ // Combine props.args with input values
167
+ const context = {
168
+ ...props . args ,
169
+ ...inputValues ,
170
+ } ;
171
+
172
+ console . log ( "script: " + script ) ;
173
+ console . log ( "context: " , context ) ;
174
+
175
+ // Pass script directly to evalFunc without wrapping
176
+ const data = await evalFunc ( script , context , undefined , options ) ;
177
+ return {
178
+ data : data ,
179
+ code : QUERY_EXECUTION_OK ,
180
+ success : true ,
181
+ runTime : Number ( ( performance . now ( ) - timer ) . toFixed ( ) ) ,
182
+ } ;
183
+ } catch ( e ) {
184
+ return {
185
+ success : false ,
186
+ data : "" ,
187
+ code : QUERY_EXECUTION_ERROR ,
188
+ message : ( e as any ) . message || "" ,
189
+ } ;
190
+ }
191
+ } ;
192
+ }
193
+
143
194
return toQueryView (
144
195
Object . entries ( this . children . inputs . children ) . map ( ( [ name , input ] ) => ( {
145
196
key : name ,
@@ -161,6 +212,7 @@ export const LibraryQuery = class extends LibraryQueryBase {
161
212
162
213
override reduce ( action : CompAction ) : this {
163
214
if ( isMyCustomAction < QueryLibraryUpdateAction > ( action , "queryLibraryUpdate" ) ) {
215
+ this . queryInfo = action . value ?. dsl ;
164
216
const inputs = this . children . inputs . setInputs ( action . value ?. dsl ?. [ "inputs" ] ?? [ ] ) ;
165
217
return setFieldsNoTypeCheck ( this , {
166
218
children : { ...this . children , inputs : inputs } ,
0 commit comments