diff --git a/application/OrganizationInteractor.ts b/application/OrganizationInteractor.ts index d2bd9ec..1a9a016 100644 --- a/application/OrganizationInteractor.ts +++ b/application/OrganizationInteractor.ts @@ -516,7 +516,7 @@ export class OrganizationInteractor extends Interactor { }) // Group the results by the requirement type - return groupBy(requirements, ({ req_type }) => req_type) + return Object.groupBy(requirements, ({ req_type }) => req_type) } */ diff --git a/server/data/services/NaturalLanguageToRequirementService.ts b/server/data/services/NaturalLanguageToRequirementService.ts index af0c709..1ce981a 100644 --- a/server/data/services/NaturalLanguageToRequirementService.ts +++ b/server/data/services/NaturalLanguageToRequirementService.ts @@ -3,7 +3,7 @@ import { v7 as uuidv7 } from 'uuid'; import zodToJsonSchema from "zod-to-json-schema"; import zodSchema from '../llm-zod-schemas/index.js' import { zodResponseFormat } from "openai/helpers/zod"; -import { dedent, groupBy } from "#shared/utils"; +import { dedent } from "#shared/utils"; type LLMResponseType = typeof zodSchema['_type']['requirements'] type ArrayToUnion = T extends (infer U)[] ? U : never @@ -53,6 +53,6 @@ export default class NaturalLanguageToRequirementService { const result = (completion.choices[0].message.parsed?.requirements ?? []) .map((req) => ({ ...req, id: uuidv7() })); - return groupBy(result, ({ type }) => type) as ParsedRequirementGroup + return Object.groupBy(result, ({ type }) => type) as ParsedRequirementGroup } } \ No newline at end of file diff --git a/shared/utils/groupBy.test.ts b/shared/utils/groupBy.test.ts deleted file mode 100644 index d12d4a1..0000000 --- a/shared/utils/groupBy.test.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { describe, it, expect } from 'vitest'; -import { groupBy } from './groupBy'; - -describe('groupBy', () => { - it('should group items by a string key', () => { - const items = [ - { category: 'fruit', name: 'apple' }, - { category: 'fruit', name: 'banana' }, - { category: 'vegetable', name: 'carrot' } - ]; - const result = groupBy(items, item => item.category); - expect(result).toEqual({ - fruit: [ - { category: 'fruit', name: 'apple' }, - { category: 'fruit', name: 'banana' } - ], - vegetable: [ - { category: 'vegetable', name: 'carrot' } - ] - }); - }); - - it('should group items by a numeric key', () => { - const items = [1.1, 2.2, 1.3, 2.4]; - const result = groupBy(items, item => Math.floor(item)); - expect(result).toEqual({ - 1: [1.1, 1.3], - 2: [2.2, 2.4] - }); - }); - - it('should handle an empty array', () => { - const items: any[] = []; - const result = groupBy(items, item => item); - expect(result).toEqual({}); - }); - - it('should handle grouping by index', () => { - const items = ['a', 'b', 'c', 'd']; - const result = groupBy(items, (item, index) => index % 2); - expect(result).toEqual({ - 0: ['a', 'c'], - 1: ['b', 'd'] - }); - }); -}); \ No newline at end of file diff --git a/shared/utils/groupBy.ts b/shared/utils/groupBy.ts deleted file mode 100644 index 9386038..0000000 --- a/shared/utils/groupBy.ts +++ /dev/null @@ -1,12 +0,0 @@ -// The server is currently Node 20 which does not support Object.groupBy. -// See: https://github.com/final-hill/cathedral/issues/371 -function groupBy(items: Iterable, keySelector: (item: T, index: number) => K): Partial> { - return [...items].reduce((acc, item, index) => { - const key = keySelector(item, index), - group = (acc as any)[key as any] ?? ((acc as any)[key as any] = []) - group.push(item) - return acc - }, {} as Partial>) -} - -export { groupBy } \ No newline at end of file diff --git a/shared/utils/index.ts b/shared/utils/index.ts index 4f654c2..8f03fda 100644 --- a/shared/utils/index.ts +++ b/shared/utils/index.ts @@ -4,7 +4,6 @@ export * from './camelCaseToTitleCase'; export * from './debounce'; export * from './dedent'; export * from './deSlugify'; -export * from './groupBy'; export * from './pascalCaseToSnakeCase' export * from './slugify'; export * from './snakeCaseToCamelCase';