@@ -5,9 +5,14 @@ import type {
55 ArraySchemaType ,
66 DocumentSchemaType ,
77 PrimitiveSchemaType ,
8+ ConstantSchemaType ,
89} from 'mongodb-schema' ;
910
1011// Type guards for mongodb-schema types
12+ function isConstantSchemaType ( type : SchemaType ) : type is ConstantSchemaType {
13+ return type . name === 'Null' || type . name === 'Undefined' ;
14+ }
15+
1116function isArraySchemaType ( type : SchemaType ) : type is ArraySchemaType {
1217 return type . name === 'Array' ;
1318}
@@ -17,7 +22,11 @@ function isDocumentSchemaType(type: SchemaType): type is DocumentSchemaType {
1722}
1823
1924function isPrimitiveSchemaType ( type : SchemaType ) : type is PrimitiveSchemaType {
20- return ! isArraySchemaType ( type ) && ! isDocumentSchemaType ( type ) ;
25+ return (
26+ ! isConstantSchemaType ( type ) &&
27+ ! isArraySchemaType ( type ) &&
28+ ! isDocumentSchemaType ( type )
29+ ) ;
2130}
2231import type { FieldInfo } from './schema-analysis-types' ;
2332
@@ -91,7 +100,7 @@ function processType(
91100 result : Record < string , FieldInfo > ,
92101 fieldProbability : number
93102) : void {
94- if ( type . name === 'Null' || type . name === 'Undefined' ) {
103+ if ( isConstantSchemaType ( type ) ) {
95104 return ;
96105 }
97106
@@ -134,16 +143,16 @@ function processType(
134143}
135144
136145/**
137- * Gets the most probable type from a list of types, excluding 'Undefined' and ' Null'
146+ * Gets the most probable type from a list of types, excluding constant types ( Null/Undefined)
138147 */
139148function getMostFrequentType ( types : SchemaType [ ] ) : SchemaType | null {
140149 if ( ! types || types . length === 0 ) {
141150 return null ;
142151 }
143152
144- // Filter out undefined types and sort by probability
153+ // Filter out constant types (Null/Undefined) and sort by probability
145154 const validTypes = types
146- . filter ( ( type ) => type . name !== 'Undefined' && type . name !== 'Null' )
155+ . filter ( ( type ) => ! isConstantSchemaType ( type ) )
147156 . sort ( ( a , b ) => ( b . probability || 0 ) - ( a . probability || 0 ) ) ;
148157
149158 return validTypes [ 0 ] || null ;
0 commit comments