@@ -8,6 +8,7 @@ import { GeneratedService } from '../../04-services/types';
88
99// Only functions matching this regex are included in the generation.
1010const FILTER_REGEX = / ^ ( s o m e | c o u n t | c r e a t e | r e m o v e | u n i q u e | u p d a t e ) $ / ;
11+ const SOME_FILTER_REGEX = / ^ ( s o m e ) $ / ;
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 */
1819export 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