@@ -13,6 +13,7 @@ import type {
1313 IPortConfig ,
1414 NodeEvent ,
1515 NodeExecutionResult ,
16+ ObjectPortValue ,
1617 PortConnectedEvent ,
1718 PortDisconnectedEvent ,
1819} from '@badaitech/chaingraph-types'
@@ -215,114 +216,81 @@ class ArrayNode extends BaseNode {
215216 switch ( portConfig . type ) {
216217 case 'string' : {
217218 specificSchema = {
218- type : portConfig . type ,
219+ ... portConfig ,
219220 defaultValue : portConfig . defaultValue || '' ,
220- minLength : portConfig . minLength ,
221- maxLength : portConfig . maxLength ,
222- pattern : portConfig . pattern ,
223- ui : {
224- isTextArea : portConfig . ui ?. isTextArea ,
225- isPassword : portConfig . ui ?. isPassword ,
226- textareaDimensions : portConfig . ui ?. textareaDimensions ,
227- hideEditor : false ,
228- } ,
229221 }
230222 break
231223 }
232224 case 'number' : {
233225 specificSchema = {
234- type : portConfig . type ,
226+ ... portConfig ,
235227 defaultValue : portConfig . defaultValue ?? 0 ,
236- min : portConfig . min ,
237- max : portConfig . max ,
238- step : portConfig . step ,
239- integer : portConfig . integer ,
240- ui : {
241- isSlider : portConfig . ui ?. isSlider ,
242- leftSliderLabel : portConfig . ui ?. leftSliderLabel ,
243- rightSliderLabel : portConfig . ui ?. rightSliderLabel ,
244- hideEditor : false ,
245- } ,
246228 }
247229 break
248230 }
249231 case 'boolean' : {
250232 specificSchema = {
251- type : portConfig . type ,
233+ ... portConfig ,
252234 defaultValue : portConfig . defaultValue ?? false ,
253- ui : {
254- hideEditor : false ,
255- } ,
256235 }
257236 break
258237 }
259238 case 'array' : {
260239 specificSchema = {
261- type : portConfig . type ,
240+ ... portConfig ,
262241 itemConfig : this . createPortConfig ( portConfig . itemConfig , true ) ,
263242 defaultValue : portConfig . defaultValue || [ ] ,
264- minLength : portConfig . minLength ,
265- maxLength : portConfig . maxLength ,
266243 isMutable : true ,
267- ui : {
268- hideEditor : false ,
269- } ,
270244 }
271245 break
272246 }
273247 case 'object' : {
248+ const objectSchema = this . createObjectSchema ( portConfig . schema )
249+ const defaultValue = this . createObjectDefaultValues ( objectSchema )
274250 specificSchema = {
275- type : portConfig . type ,
276- schema : this . createObjectSchema ( portConfig . schema ) ,
277- defaultValue : portConfig . defaultValue || { } ,
251+ ... portConfig ,
252+ schema : objectSchema ,
253+ defaultValue,
278254 isSchemaMutable : false ,
279255 ui : {
280- hideEditor : false ,
281256 keyDeletable : false ,
282257 } ,
283258 }
284259 break
285260 }
286261 case 'enum' : {
287262 specificSchema = {
288- type : portConfig . type ,
289- options : portConfig . options || [ ] ,
263+ ...portConfig ,
290264 defaultValue : portConfig . defaultValue || '' ,
291- ui : {
292- hideEditor : false ,
293- } ,
294265 }
295266 break
296267 }
297268 case 'stream' : {
298269 specificSchema = {
299- type : portConfig . type ,
270+ ... portConfig ,
300271 itemConfig : this . createPortConfig ( portConfig . itemConfig , true ) ,
301- ui : {
302- hideEditor : false ,
303- } ,
304272 }
305273 break
306274 }
307275 case 'any' : {
308276 specificSchema = {
309- type : portConfig . type ,
277+ ... portConfig ,
310278 defaultValue : portConfig . defaultValue ,
311- ui : {
312- hideEditor : false ,
313- } ,
314279 }
315280 break
316281 }
317282 }
318283
319- if ( isChildConfig ) {
320- specificSchema = {
321- ...specificSchema ,
322- title : portConfig . title ,
323- description : portConfig . description ,
324- order : portConfig . order ,
325- }
284+ specificSchema = {
285+ ...specificSchema ,
286+ id : undefined ,
287+ title : isChildConfig ? specificSchema . title : undefined ,
288+ description : isChildConfig ? specificSchema . description : undefined ,
289+ direction : 'output' ,
290+ ui : {
291+ ...specificSchema . ui ,
292+ hideEditor : false ,
293+ } ,
326294 }
327295
328296 return specificSchema
@@ -342,13 +310,25 @@ class ArrayNode extends BaseNode {
342310 }
343311
344312 return {
345- id : schema . id || undefined ,
346- type : schema . type || 'object' ,
347- description : schema . description || undefined ,
348- category : schema . category || undefined ,
349313 properties,
350314 }
351315 }
316+
317+ /**
318+ * Create default values for object ports based on the schema
319+ */
320+ private createObjectDefaultValues ( schema ?: IObjectSchema ) : ObjectPortValue < any > {
321+ if ( ! schema || ! schema . properties ) {
322+ return { }
323+ }
324+
325+ const defaultValue : ObjectPortValue < any > = { }
326+ for ( const key in schema . properties ) {
327+ defaultValue [ key ] = schema . properties [ key ] . defaultValue
328+ }
329+
330+ return defaultValue
331+ }
352332}
353333
354334export default ArrayNode
0 commit comments