Skip to content

Commit 61c82bd

Browse files
committed
cleanup
1 parent d8a1b5e commit 61c82bd

File tree

2 files changed

+26
-42
lines changed

2 files changed

+26
-42
lines changed

packages/compass-data-modeling/src/utils/schema-traversal.spec.tsx

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -210,39 +210,37 @@ describe('traverseSchema', function () {
210210
describe('getFieldFromSchema', function () {
211211
describe('field not found', function () {
212212
it('empty schema', function () {
213-
expect(() =>
214-
getFieldFromSchema({
215-
fieldPath: ['name'],
216-
jsonSchema: {},
217-
})
218-
).to.throw('Field not found in schema');
213+
const result = getFieldFromSchema({
214+
fieldPath: ['name'],
215+
jsonSchema: {},
216+
});
217+
expect(result).to.be.undefined;
219218
});
220219

221220
it('wrong path', function () {
222-
expect(() =>
223-
getFieldFromSchema({
224-
fieldPath: ['address', 'age'],
225-
jsonSchema: {
226-
bsonType: 'object',
227-
properties: {
228-
person: {
229-
bsonType: 'object',
230-
properties: {
231-
age: { bsonType: 'int' },
232-
name: { bsonType: 'string' },
233-
},
221+
const result = getFieldFromSchema({
222+
fieldPath: ['address', 'age'],
223+
jsonSchema: {
224+
bsonType: 'object',
225+
properties: {
226+
person: {
227+
bsonType: 'object',
228+
properties: {
229+
age: { bsonType: 'int' },
230+
name: { bsonType: 'string' },
234231
},
235-
address: {
236-
bsonType: 'object',
237-
properties: {
238-
street: { bsonType: 'string' },
239-
city: { bsonType: 'string' },
240-
},
232+
},
233+
address: {
234+
bsonType: 'object',
235+
properties: {
236+
street: { bsonType: 'string' },
237+
city: { bsonType: 'string' },
241238
},
242239
},
243240
},
244-
})
245-
).to.throw('Field not found in schema');
241+
},
242+
});
243+
expect(result).to.be.undefined;
246244
});
247245
});
248246

packages/compass-data-modeling/src/utils/schema-traversal.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@ import type { FieldPath } from '../services/data-model-storage';
33

44
/**
55
* Traverses a MongoDB JSON schema and calls the visitor for each field.
6-
*
7-
* @param {Object} params - The parameters object.
8-
* @param {MongoDBJSONSchema} params.jsonSchema - The JSON schema to traverse.
9-
* @param {function} params.visitor - Function called for each field.
10-
* @returns {void}
116
*/
127
export const traverseSchema = ({
138
jsonSchema,
14-
parentFieldPath = [],
159
visitor,
10+
parentFieldPath = [],
1611
}: {
1712
jsonSchema: MongoDBJSONSchema;
1813
visitor: ({
@@ -103,15 +98,6 @@ function searchItemsForChild(
10398

10499
/**
105100
* Finds a single field in a MongoDB JSON schema.
106-
*
107-
* @param {Object} params - The parameters object.
108-
* @param {MongoDBJSONSchema} params.jsonSchema - The JSON schema to traverse.
109-
* @param {FieldPath} params.fieldPath - The field path to find.
110-
* @returns {Object} result - The field information.
111-
* @returns {FieldPath[]} result.fieldPath - The full path to the found field.
112-
* @returns {string[]} result.fieldTypes - Flat list of BSON types for the found field.
113-
* @returns {MongoDBJSONSchema} result.jsonSchema - The JSON schema node for the found field.
114-
115101
*/
116102
export const getFieldFromSchema = ({
117103
jsonSchema,
@@ -149,7 +135,7 @@ export const getFieldFromSchema = ({
149135
}
150136
}
151137
if (!nextStep) {
152-
throw new Error('Field not found in schema');
138+
return;
153139
}
154140

155141
// Reached the end of path, return the field information

0 commit comments

Comments
 (0)