@@ -26,19 +26,31 @@ type RecursiveQueryEntity = {
2626 } [ ] ;
2727} ;
2828
29+ type RawEntityValue = string | boolean | number | unknown [ ] | Date | { id : string } ;
30+ type RawEntity = Record < string , RawEntityValue > ;
31+ type NestedRawEntity = RawEntity & { _relation : { id : string } } ;
32+
2933export const convertRelations = < S extends Schema . Schema . AnyNoContext > (
3034 queryEntity : RecursiveQueryEntity ,
3135 ast : SchemaAST . TypeLiteral ,
3236) => {
33- const rawEntity : Record < string , string | boolean | number | unknown [ ] | Date > = { } ;
37+ const rawEntity : RawEntity = { } ;
3438
3539 for ( const prop of ast . propertySignatures ) {
3640 const result = SchemaAST . getAnnotation < string > ( Constants . PropertyIdSymbol ) ( prop . type ) ;
3741
3842 if ( Utils . isRelation ( prop . type ) && Option . isSome ( result ) ) {
3943 rawEntity [ String ( prop . name ) ] = [ ] ;
4044
41- const relationTransformation = prop . type . rest ?. [ 0 ] ?. type ;
45+ if ( ! SchemaAST . isTupleType ( prop . type ) ) {
46+ continue ;
47+ }
48+ const relationType = prop . type ;
49+ const relationTransformation = relationType . rest [ 0 ] ?. type ;
50+ if ( ! relationTransformation || ! SchemaAST . isTypeLiteral ( relationTransformation ) ) {
51+ continue ;
52+ }
53+
4254 const typeIds : string [ ] = SchemaAST . getAnnotation < string [ ] > ( Constants . TypeIdsSymbol ) ( relationTransformation ) . pipe (
4355 Option . getOrElse ( ( ) => [ ] ) ,
4456 ) ;
@@ -51,9 +63,7 @@ export const convertRelations = <S extends Schema.Schema.AnyNoContext>(
5163 ) ;
5264 if ( allRelationsWithTheCorrectPropertyTypeId ) {
5365 for ( const relationEntry of allRelationsWithTheCorrectPropertyTypeId ) {
54- let nestedRawEntity :
55- | Record < string , string | boolean | number | unknown [ ] | Date >
56- | { _relation : { id : string } } = {
66+ let nestedRawEntity : NestedRawEntity = {
5767 id : relationEntry . toEntity . id ,
5868 _relation : {
5969 id : relationEntry . id ,
0 commit comments