@@ -4,18 +4,12 @@ import { analyzeDocuments } from 'mongodb-schema';
44import type { CollectionMetadata } from 'mongodb-collection-model' ;
55import type { ThunkAction } from 'redux-thunk' ;
66import type AppRegistry from '@mongodb-js/compass-app-registry' ;
7- import type { ConnectionInfo } from '@mongodb-js/connection-info' ;
87import type { workspacesServiceLocator } from '@mongodb-js/compass-workspaces/provider' ;
9- import type { DataService } from '@mongodb-js/compass-connections/provider' ;
108import type { CollectionSubtab } from '@mongodb-js/compass-workspaces' ;
11- import type { AtlasAiService } from '@mongodb-js/compass-generative-ai /provider' ;
9+ import type { DataService } from '@mongodb-js/compass-connections /provider' ;
1210import type { experimentationServiceLocator } from '@mongodb-js/compass-telemetry/provider' ;
1311import { type Logger , mongoLogId } from '@mongodb-js/compass-logging/provider' ;
1412import { type PreferencesAccess } from 'compass-preferences-model/provider' ;
15- import {
16- MockDataSchemaRequestShape ,
17- type MockDataSchemaResponse ,
18- } from '@mongodb-js/compass-generative-ai' ;
1913import { isInternalFieldPath } from 'hadron-document' ;
2014import toNS from 'mongodb-ns' ;
2115import {
@@ -31,13 +25,6 @@ import { calculateSchemaDepth } from '../calculate-schema-depth';
3125import { processSchema } from '../transform-schema-to-field-info' ;
3226import type { Document , MongoError } from 'mongodb' ;
3327import { MockDataGeneratorStep } from '../components/mock-data-generator-modal/types' ;
34- import {
35- MOCK_DATA_GENERATOR_STATE_IDLE ,
36- MOCK_DATA_GENERATOR_STATE_GENERATING ,
37- MOCK_DATA_GENERATOR_STATE_COMPLETED ,
38- MOCK_DATA_GENERATOR_STATE_ERROR ,
39- } from '../mock-data-generator-types' ;
40- import type { MockDataGeneratorState } from '../mock-data-generator-types' ;
4128
4229const DEFAULT_SAMPLE_SIZE = 100 ;
4330
@@ -74,7 +61,6 @@ type CollectionThunkAction<R, A extends AnyAction = AnyAction> = ThunkAction<
7461 {
7562 localAppRegistry : AppRegistry ;
7663 dataService : DataService ;
77- atlasAiService : AtlasAiService ;
7864 workspaces : ReturnType < typeof workspacesServiceLocator > ;
7965 experimentationServices : ReturnType < typeof experimentationServiceLocator > ;
8066 logger : Logger ;
@@ -93,10 +79,9 @@ export type CollectionState = {
9379 isModalOpen : boolean ;
9480 currentStep : MockDataGeneratorStep ;
9581 } ;
96- fakerSchemaGeneration : MockDataGeneratorState ;
9782} ;
9883
99- export enum CollectionActions {
84+ enum CollectionActions {
10085 CollectionMetadataFetched = 'compass-collection/CollectionMetadataFetched' ,
10186 SchemaAnalysisStarted = 'compass-collection/SchemaAnalysisStarted' ,
10287 SchemaAnalysisFinished = 'compass-collection/SchemaAnalysisFinished' ,
@@ -106,9 +91,6 @@ export enum CollectionActions {
10691 MockDataGeneratorModalClosed = 'compass-collection/MockDataGeneratorModalClosed' ,
10792 MockDataGeneratorNextButtonClicked = 'compass-collection/MockDataGeneratorNextButtonClicked' ,
10893 MockDataGeneratorPreviousButtonClicked = 'compass-collection/MockDataGeneratorPreviousButtonClicked' ,
109- FakerMappingGenerationStarted = 'compass-collection/FakerMappingGenerationStarted' ,
110- FakerMappingGenerationCompleted = 'compass-collection/FakerMappingGenerationCompleted' ,
111- FakerMappingGenerationFailed = 'compass-collection/FakerMappingGenerationFailed' ,
11294}
11395
11496interface CollectionMetadataFetchedAction {
@@ -155,23 +137,6 @@ interface MockDataGeneratorPreviousButtonClickedAction {
155137 type : CollectionActions . MockDataGeneratorPreviousButtonClicked ;
156138}
157139
158- interface FakerMappingGenerationStartedAction {
159- type : CollectionActions . FakerMappingGenerationStarted ;
160- requestId : string ;
161- }
162-
163- interface FakerMappingGenerationCompletedAction {
164- type : CollectionActions . FakerMappingGenerationCompleted ;
165- fakerSchema : MockDataSchemaResponse ;
166- requestId : string ;
167- }
168-
169- interface FakerMappingGenerationFailedAction {
170- type : CollectionActions . FakerMappingGenerationFailed ;
171- error : string ;
172- requestId : string ;
173- }
174-
175140const reducer : Reducer < CollectionState , Action > = (
176141 state = {
177142 // TODO(COMPASS-7782): use hook to get the workspace tab id instead
@@ -185,9 +150,6 @@ const reducer: Reducer<CollectionState, Action> = (
185150 isModalOpen : false ,
186151 currentStep : MockDataGeneratorStep . AI_DISCLAIMER ,
187152 } ,
188- fakerSchemaGeneration : {
189- status : MOCK_DATA_GENERATOR_STATE_IDLE ,
190- } ,
191153 } ,
192154 action
193155) => {
@@ -370,53 +332,6 @@ const reducer: Reducer<CollectionState, Action> = (
370332 } ;
371333 }
372334
373- if (
374- isAction < FakerMappingGenerationStartedAction > (
375- action ,
376- CollectionActions . FakerMappingGenerationStarted
377- )
378- ) {
379- return {
380- ...state ,
381- fakerSchemaGeneration : {
382- status : MOCK_DATA_GENERATOR_STATE_GENERATING ,
383- requestId : action . requestId ,
384- } ,
385- } ;
386- }
387-
388- if (
389- isAction < FakerMappingGenerationCompletedAction > (
390- action ,
391- CollectionActions . FakerMappingGenerationCompleted
392- )
393- ) {
394- return {
395- ...state ,
396- fakerSchemaGeneration : {
397- status : MOCK_DATA_GENERATOR_STATE_COMPLETED ,
398- fakerSchema : action . fakerSchema ,
399- requestId : action . requestId ,
400- } ,
401- } ;
402- }
403-
404- if (
405- isAction < FakerMappingGenerationFailedAction > (
406- action ,
407- CollectionActions . FakerMappingGenerationFailed
408- )
409- ) {
410- return {
411- ...state ,
412- fakerSchemaGeneration : {
413- status : MOCK_DATA_GENERATOR_STATE_ERROR ,
414- error : action . error ,
415- requestId : action . requestId ,
416- } ,
417- } ;
418- }
419-
420335 return state ;
421336} ;
422337
@@ -543,77 +458,6 @@ export const analyzeCollectionSchema = (): CollectionThunkAction<
543458 } ;
544459} ;
545460
546- export const generateFakerMappings = (
547- connectionInfo : ConnectionInfo
548- ) : CollectionThunkAction < Promise < void > > => {
549- return async ( dispatch , getState , { logger, atlasAiService } ) => {
550- const { schemaAnalysis, fakerSchemaGeneration, namespace } = getState ( ) ;
551- if ( schemaAnalysis . status !== SCHEMA_ANALYSIS_STATE_COMPLETE ) {
552- logger . log . error (
553- mongoLogId ( 1_001_000_305 ) ,
554- 'Collection' ,
555- 'Cannot call `generateFakeMappings` unless schema analysis is complete'
556- ) ;
557- return ;
558- }
559-
560- if ( fakerSchemaGeneration . status === MOCK_DATA_GENERATOR_STATE_GENERATING ) {
561- logger . debug (
562- 'Faker mapping generation is already in progress, skipping new generation.'
563- ) ;
564- return ;
565- }
566-
567- // todo: dedup/abort around requestId
568- const requestId = 'some-request-id' ;
569-
570- try {
571- logger . debug ( 'Generating faker mappings' ) ;
572-
573- const { database, collection } = toNS ( namespace ) ;
574-
575- dispatch ( {
576- type : CollectionActions . FakerMappingGenerationStarted ,
577- requestId : requestId ,
578- } ) ;
579-
580- const mockDataSchemaRequest = MockDataSchemaRequestShape . parse ( {
581- databaseName : database ,
582- collectionName : collection ,
583- schema : schemaAnalysis . processedSchema ,
584- validationRules : schemaAnalysis . schemaMetadata . validationRules ,
585- } ) ;
586-
587- const response = await atlasAiService . getMockDataSchema (
588- mockDataSchemaRequest ,
589- connectionInfo
590- ) ;
591- dispatch ( {
592- type : CollectionActions . FakerMappingGenerationCompleted ,
593- fakerSchema : response ,
594- requestId : requestId ,
595- } ) ;
596- } catch ( e ) {
597- const errorMessage = e instanceof Error ? e . message : String ( e ) ;
598-
599- logger . log . error (
600- mongoLogId ( 1_001_000_312 ) ,
601- 'Collection' ,
602- 'Failed to generate faker.js mappings' ,
603- {
604- error : errorMessage ,
605- namespace,
606- }
607- ) ;
608- dispatch ( {
609- type : CollectionActions . FakerMappingGenerationFailed ,
610- error : 'Experienced an issue generating faker.js mappings' ,
611- requestId,
612- } ) ;
613- }
614- } ;
615- } ;
616-
617461export type CollectionTabPluginMetadata = CollectionMetadata & {
618462 /**
619463 * Initial query for the query bar
0 commit comments