11
2- /* eslint-disable camelcase */
32import Reservoir from 'reservoir' ;
43import type {
54 Document ,
@@ -52,8 +51,8 @@ export type BaseSchemaType = {
5251 bsonType : string ;
5352
5453 // As `values` is from a sample reservoir this isn't a true check for duplicates/uniqueness.
55- // We cannot compute `unique` and `has_duplicates ` when `storeValues` is false.
56- has_duplicates ?: boolean ;
54+ // We cannot compute `unique` and `hasDuplicates ` when `storeValues` is false.
55+ hasDuplicates ?: boolean ;
5756 unique ?: number ;
5857}
5958
@@ -69,8 +68,8 @@ export type PrimitiveSchemaType = BaseSchemaType & {
6968export type ArraySchemaType = BaseSchemaType & {
7069 name : 'Array' ;
7170 lengths : number [ ] ;
72- average_length : number ;
73- total_count : number ;
71+ averageLength : number ;
72+ totalCount : number ;
7473 // eslint-disable-next-line no-use-before-define
7574 types : SchemaType [ ] ;
7675}
@@ -91,7 +90,7 @@ export type SchemaField = {
9190 path : string [ ] ;
9291 type : string | string [ ] ;
9392 probability : number ;
94- has_duplicates : boolean ;
93+ hasDuplicates : boolean ;
9594 types : SchemaType [ ] ;
9695} ;
9796
@@ -259,26 +258,26 @@ function computeUniqueForType(type: SchemaAnalysisType) {
259258
260259/**
261260 * Final pass through the result to add missing information:
262- * - Compute `probability`, `unique`, `has_duplicates ` and
263- * `average_length ` fields.
261+ * - Compute `probability`, `unique`, `hasDuplicates ` and
262+ * `averageLength ` fields.
264263 * - Add `Undefined` pseudo-types.
265264 * - Collapse `type` arrays to single string if length 1.
266265 * - Turn fields and types objects into arrays to conform with original
267266 * schema parser.
268267 */
269268function finalizeSchema ( schemaAnalysis : SchemaAnalysisRoot ) : SchemaField [ ] {
270269 function finalizeArrayFieldProperties ( type : SchemaAnalysisArrayType ) {
271- const total_count = Object . values ( type . types )
270+ const totalCount = Object . values ( type . types )
272271 . map ( ( v : any ) => v . count )
273272 . reduce ( ( p , c ) => p + c , 0 ) ;
274273
275- const types = finalizeSchemaFieldTypes ( type . types , total_count ) ;
274+ const types = finalizeSchemaFieldTypes ( type . types , totalCount ) ;
276275
277276 return {
278277 types,
279- total_count ,
278+ totalCount ,
280279 lengths : type . lengths ,
281- average_length : total_count / type . lengths . length
280+ averageLength : totalCount / type . lengths . length
282281 } ;
283282 }
284283
@@ -292,7 +291,7 @@ function finalizeSchema(schemaAnalysis: SchemaAnalysisRoot): SchemaField[] {
292291 count : type . count ,
293292 probability : type . count / parentCount ,
294293 unique,
295- has_duplicates : computeHasDuplicatesForType ( type , unique ) ,
294+ hasDuplicates : computeHasDuplicatesForType ( type , unique ) ,
296295 values : isNullType ( type ) ? undefined : type . values ,
297296 bsonType : type . bsonType , // Note: `Object` is replaced with `Document`.
298297 ...( isArrayType ( type ) ? finalizeArrayFieldProperties ( type ) : { } ) ,
@@ -312,7 +311,7 @@ function finalizeSchema(schemaAnalysis: SchemaAnalysisRoot): SchemaField[] {
312311 name : 'Undefined' ,
313312 bsonType : 'Undefined' ,
314313 unique : undefinedCount > 1 ? 0 : 1 ,
315- has_duplicates : undefinedCount > 1 ,
314+ hasDuplicates : undefinedCount > 1 ,
316315 path : field . path ,
317316 count : undefinedCount ,
318317 probability : undefinedCount / parentCount
@@ -325,7 +324,7 @@ function finalizeSchema(schemaAnalysis: SchemaAnalysisRoot): SchemaField[] {
325324 count : field . count ,
326325 type : fieldTypes . length === 1 ? fieldTypes [ 0 ] . name : fieldTypes . map ( ( v : SchemaType ) => v . name ) , // Or one value or array.
327326 probability : field . count / parentCount ,
328- has_duplicates : ! ! fieldTypes . find ( ( v : SchemaType ) => v . has_duplicates ) ,
327+ hasDuplicates : ! ! fieldTypes . find ( ( v : SchemaType ) => v . hasDuplicates ) ,
329328 types : fieldTypes
330329 } ;
331330 } ) . sort ( fieldComparator ) ;
0 commit comments