@@ -26,19 +26,31 @@ type RecursiveQueryEntity = {
26
26
} [ ] ;
27
27
} ;
28
28
29
+ type RawEntityValue = string | boolean | number | unknown [ ] | Date | { id : string } ;
30
+ type RawEntity = Record < string , RawEntityValue > ;
31
+ type NestedRawEntity = RawEntity & { _relation : { id : string } } ;
32
+
29
33
export const convertRelations = < S extends Schema . Schema . AnyNoContext > (
30
34
queryEntity : RecursiveQueryEntity ,
31
35
ast : SchemaAST . TypeLiteral ,
32
36
) => {
33
- const rawEntity : Record < string , string | boolean | number | unknown [ ] | Date > = { } ;
37
+ const rawEntity : RawEntity = { } ;
34
38
35
39
for ( const prop of ast . propertySignatures ) {
36
40
const result = SchemaAST . getAnnotation < string > ( Constants . PropertyIdSymbol ) ( prop . type ) ;
37
41
38
42
if ( Utils . isRelation ( prop . type ) && Option . isSome ( result ) ) {
39
43
rawEntity [ String ( prop . name ) ] = [ ] ;
40
44
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
+
42
54
const typeIds : string [ ] = SchemaAST . getAnnotation < string [ ] > ( Constants . TypeIdsSymbol ) ( relationTransformation ) . pipe (
43
55
Option . getOrElse ( ( ) => [ ] ) ,
44
56
) ;
@@ -51,9 +63,7 @@ export const convertRelations = <S extends Schema.Schema.AnyNoContext>(
51
63
) ;
52
64
if ( allRelationsWithTheCorrectPropertyTypeId ) {
53
65
for ( const relationEntry of allRelationsWithTheCorrectPropertyTypeId ) {
54
- let nestedRawEntity :
55
- | Record < string , string | boolean | number | unknown [ ] | Date >
56
- | { _relation : { id : string } } = {
66
+ let nestedRawEntity : NestedRawEntity = {
57
67
id : relationEntry . toEntity . id ,
58
68
_relation : {
59
69
id : relationEntry . id ,
0 commit comments