File tree Expand file tree Collapse file tree 5 files changed +17
-18
lines changed
packages/compass-collection/src
components/mock-data-generator-modal Expand file tree Collapse file tree 5 files changed +17
-18
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import React from 'react';
1313import FieldSelector from './schema-field-selector' ;
1414import FakerMappingSelector from './faker-mapping-selector' ;
1515import type { FakerSchema , MockDataGeneratorState } from './types' ;
16+ import type { MongoDBFieldType } from '../../schema-analysis-types' ;
1617
1718const containerStyles = css ( {
1819 display : 'flex' ,
@@ -75,7 +76,7 @@ const FakerSchemaEditorContent = ({
7576 ...fakerSchemaFormValues ,
7677 [ activeField ] : {
7778 ...currentMapping ,
78- mongoType : newJsonType ,
79+ mongoType : newJsonType as MongoDBFieldType ,
7980 } ,
8081 } ) ;
8182 resetIsSchemaConfirmed ( ) ;
Original file line number Diff line number Diff line change 11import { expect } from 'chai' ;
22import { faker } from '@faker-js/faker/locale/en' ;
3- import {
4- generateScript ,
5- type FakerFieldMapping ,
6- } from './script-generation-utils' ;
3+ import { generateScript } from './script-generation-utils' ;
4+ import type { FakerFieldMapping } from './types' ;
75
86/**
97 * Helper function to test that generated document code is executable
Original file line number Diff line number Diff line change 11import type { MongoDBFieldType } from '../../schema-analysis-types' ;
2+ import type { FakerFieldMapping } from './types' ;
23
34export type FakerArg = string | number | boolean | { json : string } ;
45
56const DEFAULT_ARRAY_LENGTH = 3 ;
67const INDENT_SIZE = 2 ;
78
8- export interface FakerFieldMapping {
9- mongoType : MongoDBFieldType ;
10- fakerMethod : string ;
11- fakerArgs : FakerArg [ ] ;
12- probability ?: number ; // 0.0 - 1.0 frequency of field (defaults to 1.0)
13- }
14-
159// Array length configuration for different array types
1610export type ArrayLengthMap = {
1711 [ fieldName : string ] :
Original file line number Diff line number Diff line change 11import type { MockDataSchemaResponse } from '@mongodb-js/compass-generative-ai' ;
2+ import type { MongoDBFieldType } from '../../schema-analysis-types' ;
3+ import type { FakerArg } from './script-generation-utils' ;
24
35export enum MockDataGeneratorStep {
46 SCHEMA_CONFIRMATION = 'SCHEMA_CONFIRMATION' ,
@@ -37,11 +39,11 @@ export type MockDataGeneratorState =
3739
3840export type FakerSchemaMapping = MockDataSchemaResponse [ 'fields' ] [ number ] ;
3941
40- export type FakerFieldMapping = {
41- mongoType : string ;
42+ export interface FakerFieldMapping {
43+ mongoType : MongoDBFieldType ;
4244 fakerMethod : string ;
43- fakerArgs : any [ ] ;
44- probability : number ;
45- } ;
45+ fakerArgs : FakerArg [ ] ;
46+ probability ? : number ; // 0.0 - 1.0 frequency of field (defaults to 1.0)
47+ }
4648
4749export type FakerSchema = Record < string , FakerFieldMapping > ;
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ import {
2727 type SchemaAnalysisError ,
2828 type SchemaAnalysisState ,
2929 type FieldInfo ,
30+ MongoDBFieldType ,
3031} from '../schema-analysis-types' ;
3132import { calculateSchemaDepth } from '../calculate-schema-depth' ;
3233import {
@@ -708,7 +709,10 @@ function transformFakerSchemaToObject(
708709
709710 for ( const field of fakerSchema ) {
710711 const { fieldPath, ...fieldMapping } = field ;
711- result [ fieldPath ] = fieldMapping ;
712+ result [ fieldPath ] = {
713+ ...fieldMapping ,
714+ mongoType : fieldMapping . mongoType as MongoDBFieldType ,
715+ } ;
712716 }
713717
714718 return result ;
You can’t perform that action at this time.
0 commit comments