Skip to content

Commit a43ebf2

Browse files
committed
use shorthand array syntax and enhance validation logic in validateFakerSchema function
1 parent c9f3a29 commit a43ebf2

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

packages/compass-collection/src/components/mock-data-generator-modal/faker-schema-editor-screen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const FakerSchemaEditorContent = ({
5252
fakerSchemaMappings,
5353
onSchemaConfirmed,
5454
}: {
55-
fakerSchemaMappings: Array<FakerSchemaMapping>;
55+
fakerSchemaMappings: FakerSchemaMapping[];
5656
onSchemaConfirmed: (isConfirmed: boolean) => void;
5757
}) => {
5858
const [fakerSchemaFormValues, setFakerSchemaFormValues] =

packages/compass-collection/src/components/mock-data-generator-modal/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type MockDataGeneratorInProgressState = {
1919

2020
type MockDataGeneratorCompletedState = {
2121
status: 'completed';
22-
fakerSchema: Array<FakerSchemaMapping>;
22+
fakerSchema: FakerSchemaMapping[];
2323
requestId: string;
2424
};
2525

packages/compass-collection/src/modules/collection-tab.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export interface FakerMappingGenerationStartedAction {
185185

186186
export interface FakerMappingGenerationCompletedAction {
187187
type: CollectionActions.FakerMappingGenerationCompleted;
188-
fakerSchema: Array<FakerSchemaMapping>;
188+
fakerSchema: FakerSchemaMapping[];
189189
requestId: string;
190190
}
191191

@@ -706,8 +706,11 @@ const validateFakerSchema = (
706706
return fakerSchema.content.fields.map((field) => {
707707
const { fakerMethod } = field;
708708

709-
const [moduleName, methodName] = fakerMethod.split('.');
710-
if (typeof (faker as any)[moduleName]?.[methodName] !== 'function') {
709+
const [moduleName, methodName, ...rest] = fakerMethod.split('.');
710+
if (
711+
rest.length > 0 ||
712+
typeof (faker as any)[moduleName]?.[methodName] !== 'function'
713+
) {
711714
logger.log.warn(
712715
mongoLogId(1_001_000_372),
713716
'Collection',

0 commit comments

Comments
 (0)