@@ -143,54 +143,49 @@ module.exports = {
143143 modelDefinitions,
144144 } ;
145145 } )
146- )
147- . then ( schemaData => {
148- const relationships = schemaData
149- . flatMap ( ( { tables } ) => tables . map ( entityData => entityData . relationships ) )
150- . flat ( ) ;
151-
152- const packages = schemaData . flatMap (
153- ( { schemaName, tables, views, functions, procedures, modelDefinitions } ) => {
154- const bucketInfo = {
155- UDFs : functions ,
156- Procedures : procedures ,
146+ ) . then ( schemaData => {
147+ const relationships = schemaData
148+ . flatMap ( ( { tables } ) => tables . map ( entityData => entityData . relationships ) )
149+ . flat ( ) ;
150+
151+ const packages = schemaData . flatMap (
152+ ( { schemaName, tables, views, functions, procedures, modelDefinitions } ) => {
153+ const bucketInfo = {
154+ UDFs : functions ,
155+ Procedures : procedures ,
156+ } ;
157+
158+ const tablePackages = tables
159+ . map ( entityData => ( {
160+ dbName : schemaName ,
161+ collectionName : entityData . name ,
162+ documents : entityData . documents ,
163+ views : [ ] ,
164+ emptyBucket : false ,
165+ entityLevel : entityData . entityLevel ,
166+ validation : {
167+ jsonSchema : entityData . jsonSchema ,
168+ } ,
169+ bucketInfo,
170+ modelDefinitions,
171+ } ) )
172+ . sort ( data => ( app . require ( 'lodash' ) . isEmpty ( data . entityLevel . inherits ) ? - 1 : 1 ) ) ;
173+
174+ if ( views ?. length ) {
175+ const viewPackage = {
176+ dbName : schemaName ,
177+ views : views ,
178+ emptyBucket : false ,
157179 } ;
158180
159- const tablePackages = tables
160- . map ( entityData => ( {
161- dbName : schemaName ,
162- collectionName : entityData . name ,
163- documents : entityData . documents ,
164- views : [ ] ,
165- emptyBucket : false ,
166- entityLevel : entityData . entityLevel ,
167- validation : {
168- jsonSchema : entityData . jsonSchema ,
169- } ,
170- bucketInfo,
171- modelDefinitions,
172- } ) )
173- . sort ( data => ( app . require ( 'lodash' ) . isEmpty ( data . entityLevel . inherits ) ? - 1 : 1 ) ) ;
174-
175- if ( views ?. length ) {
176- const viewPackage = {
177- dbName : schemaName ,
178- views : views ,
179- emptyBucket : false ,
180- } ;
181-
182- return [ ...tablePackages , viewPackage ] ;
183- }
184-
185- return tablePackages ;
181+ return [ ...tablePackages , viewPackage ] ;
186182 }
187- ) ;
188- return { packages, relationships } ;
189- } )
190- . then ( ( { packages, relationships } ) => ( {
191- packages : facilitatePackages ( packages , logger ) ,
192- relationships,
193- } ) ) ;
183+
184+ return tablePackages ;
185+ }
186+ ) ;
187+ return { packages, relationships } ;
188+ } ) ;
194189
195190 callback ( null , packages , modelData , relationships ) ;
196191 } catch ( error ) {
@@ -213,31 +208,3 @@ const logInfo = (step, connectionInfo, logger) => {
213208 logger . log ( 'info' , getSystemInfo ( connectionInfo . appVersion ) , step ) ;
214209 logger . log ( 'info' , connectionInfo , 'connectionInfo' , connectionInfo . hiddenKeys ) ;
215210} ;
216-
217- const facilitatePackages = ( packages , logger ) => {
218- if ( checkPackagesCannotBeStringified ( packages , logger ) ) {
219- return packages . map ( pack => {
220- if ( ! Array . isArray ( pack . documents ) ) {
221- return pack ;
222- }
223-
224- const documents = pack . documents . slice ( 0 , Math . floor ( pack . documents . length / 2 ) ) ;
225-
226- return { ...pack , documents } ;
227- } ) ;
228- }
229-
230- return packages ;
231- } ;
232-
233- const checkPackagesCannotBeStringified = ( packages , logger ) => {
234- try {
235- const str = JSON . stringify ( packages ) ;
236-
237- return false ;
238- } catch ( error ) {
239- logger . log ( 'info' , prepareError ( error ) , 'Packages cannot be stringified' ) ;
240-
241- return true ;
242- }
243- } ;
0 commit comments