Skip to content

Commit 77af388

Browse files
committed
pass collection name, db name, and validation rules
1 parent f7d352d commit 77af388

File tree

3 files changed

+36
-28
lines changed

3 files changed

+36
-28
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ export const generateFakerMappings = (
547547
connectionInfo: ConnectionInfo
548548
): CollectionThunkAction<Promise<void>> => {
549549
return async (dispatch, getState, { logger, atlasAiService }) => {
550-
const { schemaAnalysis, fakerSchemaGeneration } = getState();
550+
const { schemaAnalysis, fakerSchemaGeneration, namespace } = getState();
551551
if (schemaAnalysis.status !== SCHEMA_ANALYSIS_STATE_COMPLETE) {
552552
logger.log.error(
553553
mongoLogId(1_001_000_305),
@@ -566,17 +566,23 @@ export const generateFakerMappings = (
566566

567567
// todo: dedup/abort around requestId
568568
const requestId = 'some-request-id';
569+
var what = 'what';
569570
try {
570571
logger.debug('Generating faker mappings');
571572

573+
const { database, collection } = toNS(namespace);
574+
572575
dispatch({
573576
type: CollectionActions.FakerMappingGenerationStarted,
574577
requestId: requestId,
575578
});
576579

577-
const mockDataSchemaRequest = MockDataSchemaRequestShape.parse(
578-
schemaAnalysis.processedSchema
579-
);
580+
const mockDataSchemaRequest = MockDataSchemaRequestShape.parse({
581+
databaseName: database,
582+
collectionName: collection,
583+
schema: schemaAnalysis.processedSchema,
584+
validationRules: schemaAnalysis.schemaMetadata.validationRules,
585+
});
580586

581587
const response = await atlasAiService.getMockDataSchema(
582588
mockDataSchemaRequest,
@@ -595,7 +601,9 @@ export const generateFakerMappings = (
595601
);
596602
dispatch({
597603
type: CollectionActions.FakerMappingGenerationFailed,
598-
error: 'Failed to generate faker mappings',
604+
error:
605+
'Failed to generate faker mappings' +
606+
String(e instanceof Error ? e.message : e),
599607
requestId: requestId,
600608
});
601609
}

packages/compass-collection/src/stores/collection-tab.spec.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -291,29 +291,30 @@ describe('Collection Tab Content store', function () {
291291
it('can complete successfully', async function () {
292292
const dispatch = sandbox.spy();
293293
const getState = sandbox.stub().returns({
294+
namespace: 'some_db.some_collection',
294295
schemaAnalysis: {
295296
status: SCHEMA_ANALYSIS_STATE_COMPLETE,
296297
processedSchema: {
297-
collectionName: 'foo',
298-
databaseName: 'test',
299-
schema: {
300-
name: {
301-
type: 'String',
302-
sampleValues: ['John', 'Jane', 'Bob'],
303-
probability: 1.0,
304-
},
305-
age: {
306-
type: 'Number',
307-
sampleValues: [25, 30, 35],
308-
probability: 0.9,
309-
},
310-
isActive: {
311-
type: 'Boolean',
312-
sampleValues: [true, false],
313-
probability: 0.8,
314-
},
298+
name: {
299+
type: 'String',
300+
probability: 1.0,
301+
sampleValues: ['John', 'Jane', 'Bob'],
302+
},
303+
age: {
304+
type: 'Number',
305+
probability: 0.9,
306+
sampleValues: [25, 30],
307+
},
308+
isActive: {
309+
type: 'Boolean',
310+
probability: 0.8,
311+
sampleValues: [true, false],
315312
},
316313
},
314+
schemaMetadata: {
315+
maxNestingDepth: 1,
316+
validationRules: null,
317+
},
317318
},
318319
fakerSchemaGeneration: { status: MOCK_DATA_GENERATOR_STATE_IDLE },
319320
});
@@ -353,9 +354,7 @@ describe('Collection Tab Content store', function () {
353354
},
354355
};
355356
const atlasAiService = {
356-
getMockDataSchema: sandbox
357-
.stub()
358-
.returns(Promise.resolve(mockDataSchemaResponse)),
357+
getMockDataSchema: sandbox.stub().resolves(mockDataSchemaResponse),
359358
};
360359

361360
// Act
@@ -386,6 +385,7 @@ describe('Collection Tab Content store', function () {
386385
it('can dispatch a failure', async function () {
387386
const dispatch = sandbox.spy();
388387
const getState = sandbox.stub().returns({
388+
namespace: 'some_db.some_collection',
389389
schemaAnalysis: {
390390
status: SCHEMA_ANALYSIS_STATE_COMPLETE,
391391
processedSchema: undefined,
@@ -398,7 +398,7 @@ describe('Collection Tab Content store', function () {
398398
};
399399

400400
const atlasAiService = {
401-
getMockDataSchema: sandbox.stub().returns(Promise.resolve({})),
401+
getMockDataSchema: sandbox.stub().resolves({}),
402402
};
403403

404404
// Act

packages/compass-generative-ai/src/atlas-ai-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export const MockDataSchemaRequestShape = z.object({
228228
collectionName: z.string(),
229229
databaseName: z.string(),
230230
schema: MockDataSchemaRawFieldMappingShape,
231-
validationRules: z.record(z.string(), z.unknown()).optional(),
231+
validationRules: z.record(z.string(), z.unknown()).nullable().optional(),
232232
includeSampleValues: z.boolean().default(false),
233233
});
234234

0 commit comments

Comments
 (0)