diff --git a/src/__tests__/utils.test.ts b/src/__tests__/utils.test.ts index ea3111c6..bcf7b97c 100644 --- a/src/__tests__/utils.test.ts +++ b/src/__tests__/utils.test.ts @@ -9,7 +9,6 @@ import { PropertyType, getDefaultValues, ObjectIdConstructorParameter, - GetIdsOptions, } from '../utils'; describe('utils', () => { @@ -385,7 +384,6 @@ describe('utils', () => { string, { input: readonly ObjectIdConstructorParameter[]; - options?: GetIdsOptions; expected: readonly ObjectId[]; }, ] @@ -440,18 +438,17 @@ describe('utils', () => { 'invalid values, when filterInvalid is true', { input: ['123', '123456789012345678900021'], - options: { filterInvalid: true }, expected: [new ObjectId('123456789012345678900021')], }, ], - ])('should return ObjectIds from %s', (_name, { input, options, expected }) => { + ])('should return ObjectIds from %s', (_name, { input, expected }) => { expect.assertions(4); // Given expect(expected.length).toBeLessThanOrEqual(input.length); // When - const actual = getIds(input, options); + const actual = getIds(input); // Then expect(actual).toEqual(expected); @@ -464,17 +461,5 @@ describe('utils', () => { ); expect(isEveryHexEquivalent).toBeTruthy(); }); - - test('should throw on invalid values, when filterInvalid is unspecified', () => { - expect.assertions(1); - - // Given - const input = ['123', '123456789012345678900021']; - - // When/Then - expect(() => getIds(input)).toThrowErrorMatchingInlineSnapshot( - '"input must be a 24 character hex string, 12 byte Uint8Array, or an integer"' - ); - }); }); }); diff --git a/src/utils.ts b/src/utils.ts index 80907abe..dcc656e2 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -195,20 +195,12 @@ export type RequireAtLeastOne = { Pick>; export type ObjectIdConstructorParameter = ConstructorParameters[0]; -export interface GetIdsOptions { - filterInvalid?: boolean; -} -export function getIds( - ids: Iterable, - options?: GetIdsOptions -): ObjectId[] { +export function getIds(ids: Iterable): ObjectId[] { return Array.from(ids).flatMap((id) => { try { return new ObjectId(id); - } catch (error) { - if (!options?.filterInvalid) { - throw error; - } + } catch { + // Intentionally empty } return [];