11import type { Reducer , AnyAction , Action } from 'redux' ;
2- import { analyzeDocuments , type Schema } from 'mongodb-schema' ;
2+ import { analyzeDocuments } from 'mongodb-schema' ;
33
44import type { CollectionMetadata } from 'mongodb-collection-model' ;
55import type { ThunkAction } from 'redux-thunk' ;
@@ -19,8 +19,10 @@ import {
1919 SCHEMA_ANALYSIS_STATE_INITIAL ,
2020 type SchemaAnalysisError ,
2121 type SchemaAnalysisState ,
22+ type FieldInfo ,
2223} from '../schema-analysis-types' ;
2324import { calculateSchemaDepth } from '../calculate-schema-depth' ;
25+ import { processSchema } from '../transform-schema-to-field-info' ;
2426import type { Document , MongoError } from 'mongodb' ;
2527
2628const DEFAULT_SAMPLE_SIZE = 100 ;
@@ -106,7 +108,7 @@ interface SchemaAnalysisStartedAction {
106108
107109interface SchemaAnalysisFinishedAction {
108110 type : CollectionActions . SchemaAnalysisFinished ;
109- schema : Schema ;
111+ processedSchema : Record < string , FieldInfo > ;
110112 sampleDocument : Document ;
111113 schemaMetadata : {
112114 maxNestingDepth : number ;
@@ -201,7 +203,7 @@ const reducer: Reducer<CollectionState, Action> = (
201203 ...state ,
202204 schemaAnalysis : {
203205 status : SCHEMA_ANALYSIS_STATE_COMPLETE ,
204- schema : action . schema ,
206+ processedSchema : action . processedSchema ,
205207 sampleDocument : action . sampleDocument ,
206208 schemaMetadata : action . schemaMetadata ,
207209 } ,
@@ -420,7 +422,9 @@ export const analyzeCollectionSchema = (): CollectionThunkAction<
420422 schema . fields = schema . fields . filter (
421423 ( { path } ) => ! isInternalFieldPath ( path [ 0 ] )
422424 ) ;
423- // TODO: Transform schema to structure that will be used by the LLM.
425+
426+ // Transform schema to structure that will be used by the LLM
427+ const processedSchema = processSchema ( schema ) ;
424428
425429 const maxNestingDepth = await calculateSchemaDepth ( schema ) ;
426430 const { database, collection } = toNS ( namespace ) ;
@@ -432,7 +436,7 @@ export const analyzeCollectionSchema = (): CollectionThunkAction<
432436 } ;
433437 dispatch ( {
434438 type : CollectionActions . SchemaAnalysisFinished ,
435- schema ,
439+ processedSchema ,
436440 sampleDocument : sampleDocuments [ 0 ] ,
437441 schemaMetadata,
438442 } ) ;
0 commit comments