Skip to content

Commit 924827c

Browse files
committed
feat: add WServicesWithSomeQuery type map
1 parent 65ad1ef commit 924827c

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

src/generator/05-maps/utils/generateGroupedServices.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { GeneratedService } from '../../04-services/types';
88

99
// Only functions matching this regex are included in the generation.
1010
const FILTER_REGEX = /^(some|count|create|remove|unique|update)$/;
11+
const SOME_FILTER_REGEX = /^(some)$/;
1112

1213
/**
1314
* 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)$/;
1718
*/
1819
export const generateGroupedServices = (services: GeneratedService[]) => {
1920
const entityDescriptors: Map<string, InterfaceProperty[]> = new Map();
21+
const someQueryDescriptors: Map<string, InterfaceProperty[]> = new Map();
2022

2123
for (const service of services) {
2224
for (const fn of service.functions) {
@@ -32,25 +34,43 @@ export const generateGroupedServices = (services: GeneratedService[]) => {
3234
type: `${pascalCase(service.name)}Service_${pascalCase(fn.name)}`
3335
}
3436
]);
37+
38+
if (SOME_FILTER_REGEX.test(fn.name)) {
39+
someQueryDescriptors.set(fn.name, [
40+
...(someQueryDescriptors.get(fn.name) ?? []),
41+
{
42+
name: service.name,
43+
required: true,
44+
type: `${pascalCase(service.name)}Service_${pascalCase(fn.name)}_Query`
45+
}
46+
]);
47+
}
3548
}
3649
}
3750

38-
const descriptors = [...entityDescriptors.entries()];
51+
const entityDescriptorEntries = [...entityDescriptors.entries()];
52+
const someQueryDescriptorEntries = [...someQueryDescriptors.entries()];
3953
const typeGuards: string[] = [];
4054

41-
for (const [name] of descriptors) {
55+
for (const [name] of entityDescriptorEntries) {
4256
const constant = camelCase(`wServiceWith_${name}_Names`);
4357
const service = pascalCase(`WServiceWith_${name}`);
4458
const guard = `(service: string | undefined): service is ${service} =>\n${indent(`${constant}.includes(service as ${service});`)}`;
4559
typeGuards.push(`export const is${service} = ${guard}`);
4660
}
4761

4862
return generateStatements(
49-
...descriptors.map(([name, props]) => generateInterface(pascalCase(`WServicesWith_${name}`), props)),
50-
...descriptors.map(([name]) =>
63+
...entityDescriptorEntries.map(([name, props]) => generateInterface(pascalCase(`WServicesWith_${name}`), props)),
64+
...entityDescriptorEntries.map(([name]) =>
5165
generateType(pascalCase(`WServiceWith_${name}`), `keyof ${pascalCase(`WServicesWith_${name}`)}`)
5266
),
53-
...descriptors.map(([name, props]) => {
67+
...someQueryDescriptorEntries.map(([name, props]) =>
68+
generateInterface(pascalCase(`WServicesWith_${name}_Query`), props)
69+
),
70+
...someQueryDescriptorEntries.map(([name]) =>
71+
generateType(pascalCase(`WServiceWith_${name}_Query`), `keyof ${pascalCase(`WServicesWith_${name}_Query`)}`)
72+
),
73+
...entityDescriptorEntries.map(([name, props]) => {
5474
const constant = camelCase(`wServiceWith_${name}_Names`);
5575
const type = pascalCase(`WServiceWith_${name}`);
5676
const value = generateArray(props.map((v) => v.name));

0 commit comments

Comments
 (0)