From 924827c4433b2f5b61dc36c3f7ea4e9e4481a359 Mon Sep 17 00:00:00 2001 From: Simon Hofer Date: Tue, 31 Mar 2026 11:54:50 +0200 Subject: [PATCH] feat: add WServicesWithSomeQuery type map --- .../05-maps/utils/generateGroupedServices.ts | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/generator/05-maps/utils/generateGroupedServices.ts b/src/generator/05-maps/utils/generateGroupedServices.ts index 7f5d46e..09dc309 100644 --- a/src/generator/05-maps/utils/generateGroupedServices.ts +++ b/src/generator/05-maps/utils/generateGroupedServices.ts @@ -8,6 +8,7 @@ import { GeneratedService } from '../../04-services/types'; // Only functions matching this regex are included in the generation. const FILTER_REGEX = /^(some|count|create|remove|unique|update)$/; +const SOME_FILTER_REGEX = /^(some)$/; /** * Generates for each function a map with the entity-name as key and service type as value. @@ -17,6 +18,7 @@ const FILTER_REGEX = /^(some|count|create|remove|unique|update)$/; */ export const generateGroupedServices = (services: GeneratedService[]) => { const entityDescriptors: Map = new Map(); + const someQueryDescriptors: Map = new Map(); for (const service of services) { for (const fn of service.functions) { @@ -32,13 +34,25 @@ export const generateGroupedServices = (services: GeneratedService[]) => { type: `${pascalCase(service.name)}Service_${pascalCase(fn.name)}` } ]); + + if (SOME_FILTER_REGEX.test(fn.name)) { + someQueryDescriptors.set(fn.name, [ + ...(someQueryDescriptors.get(fn.name) ?? []), + { + name: service.name, + required: true, + type: `${pascalCase(service.name)}Service_${pascalCase(fn.name)}_Query` + } + ]); + } } } - const descriptors = [...entityDescriptors.entries()]; + const entityDescriptorEntries = [...entityDescriptors.entries()]; + const someQueryDescriptorEntries = [...someQueryDescriptors.entries()]; const typeGuards: string[] = []; - for (const [name] of descriptors) { + for (const [name] of entityDescriptorEntries) { const constant = camelCase(`wServiceWith_${name}_Names`); const service = pascalCase(`WServiceWith_${name}`); const guard = `(service: string | undefined): service is ${service} =>\n${indent(`${constant}.includes(service as ${service});`)}`; @@ -46,11 +60,17 @@ export const generateGroupedServices = (services: GeneratedService[]) => { } return generateStatements( - ...descriptors.map(([name, props]) => generateInterface(pascalCase(`WServicesWith_${name}`), props)), - ...descriptors.map(([name]) => + ...entityDescriptorEntries.map(([name, props]) => generateInterface(pascalCase(`WServicesWith_${name}`), props)), + ...entityDescriptorEntries.map(([name]) => generateType(pascalCase(`WServiceWith_${name}`), `keyof ${pascalCase(`WServicesWith_${name}`)}`) ), - ...descriptors.map(([name, props]) => { + ...someQueryDescriptorEntries.map(([name, props]) => + generateInterface(pascalCase(`WServicesWith_${name}_Query`), props) + ), + ...someQueryDescriptorEntries.map(([name]) => + generateType(pascalCase(`WServiceWith_${name}_Query`), `keyof ${pascalCase(`WServicesWith_${name}_Query`)}`) + ), + ...entityDescriptorEntries.map(([name, props]) => { const constant = camelCase(`wServiceWith_${name}_Names`); const type = pascalCase(`WServiceWith_${name}`); const value = generateArray(props.map((v) => v.name));