@@ -121,40 +121,55 @@ async function updateJsonObject(
121121 obj : any ,
122122 tablesServerContext : TablesServerContext ,
123123) : Promise < any > {
124- if ( ! obj || typeof obj !== 'object' ) return obj ;
124+ if ( ! obj || typeof obj !== 'object' ) {
125+ return obj ;
126+ }
125127
126- if ( obj . input ?. tableName ) {
127- const fields = await getFieldsFromCache (
128- obj . input . tableName ,
129- tablesServerContext ,
130- ) ;
128+ await updateInputFields ( obj , tablesServerContext ) ;
129+ await processObjectKeys ( obj , tablesServerContext ) ;
131130
132- if ( ! fields ) {
133- return obj ;
134- }
131+ return obj ;
132+ }
133+
134+ async function updateInputFields (
135+ obj : any ,
136+ tablesServerContext : TablesServerContext ,
137+ ) : Promise < void > {
138+ if ( ! obj . input ?. tableName ) {
139+ return ;
140+ }
135141
136- if ( obj . input . fieldsProperties ?. fieldsProperties ) {
137- for ( const field of obj . input . fieldsProperties . fieldsProperties ) {
138- if ( ! field . fieldName ) {
139- continue ;
140- }
142+ const fields = await getFieldsFromCache (
143+ obj . input . tableName ,
144+ tablesServerContext ,
145+ ) ;
141146
142- updateFieldValue ( field , fields . get ( field . fieldName ) ) ;
143- }
147+ if ( ! fields || ! obj . input . fieldsProperties ?. fieldsProperties ) {
148+ return ;
149+ }
150+
151+ for ( const field of obj . input . fieldsProperties . fieldsProperties ) {
152+ if ( field . fieldName ) {
153+ updateFieldValue ( field , fields . get ( field . fieldName ) ) ;
144154 }
145155 }
156+ }
146157
158+ async function processObjectKeys (
159+ obj : any ,
160+ tablesServerContext : TablesServerContext ,
161+ ) : Promise < void > {
147162 for ( const key of Object . keys ( obj ) ) {
148163 if ( Array . isArray ( obj [ key ] ) ) {
149- for ( const item of obj [ key ] ) {
150- obj [ key ] = await updateJsonObject ( item , tablesServerContext ) ;
151- }
152- } else if ( typeof obj [ key ] === 'object' ) {
164+ obj [ key ] = await Promise . all (
165+ obj [ key ] . map ( ( item : any ) =>
166+ updateJsonObject ( item , tablesServerContext ) ,
167+ ) ,
168+ ) ;
169+ } else if ( typeof obj [ key ] === 'object' && obj [ key ] !== null ) {
153170 obj [ key ] = await updateJsonObject ( obj [ key ] , tablesServerContext ) ;
154171 }
155172 }
156-
157- return obj ;
158173}
159174
160175function updateFieldValue ( field : any , fieldMap ?: Map < number , string > ) {
0 commit comments