@@ -4,7 +4,7 @@ import { Config, Model, ModelSchema, PrimitiveType, Property, PropertyType, Rela
44import { namePattern } from "./utils.js"
55
66export function parseConfig ( init : ModelSchema ) : Config {
7- const relations : Omit < Relation , "sourceType " | "targetType " > [ ] = [ ]
7+ const relations : Omit < Relation , "sourcePrimaryKey " | "targetPrimaryKey " > [ ] = [ ]
88 const models : Model [ ] = [ ]
99
1010 for ( const [ modelName , { $indexes, $primary, ...rest } ] of Object . entries ( init ) ) {
@@ -71,20 +71,20 @@ export function parseConfig(init: ModelSchema): Config {
7171 throw new Error ( `invalid model schema: invalid relation source "${ relation . source } " (no such model)` )
7272 }
7373
74- const sourcePrimaryProperty = sourceModel . properties . find ( ( property ) => property . name === sourceModel . primaryKey )
75- assert ( sourcePrimaryProperty !== undefined )
76- assert ( sourcePrimaryProperty . kind === "primitive" )
74+ const sourcePrimaryKey = sourceModel . properties . find ( ( property ) => property . name === sourceModel . primaryKey )
75+ assert ( sourcePrimaryKey !== undefined )
76+ assert ( sourcePrimaryKey . kind === "primitive" )
7777
7878 const targetModel = models . find ( ( model ) => model . name === relation . target )
7979 if ( targetModel === undefined ) {
8080 throw new Error ( `invalid model schema: invalid relation target "${ relation . target } " (no such model)` )
8181 }
8282
83- const targetPrimaryProperty = targetModel . properties . find ( ( property ) => property . name === targetModel . primaryKey )
84- assert ( targetPrimaryProperty !== undefined )
85- assert ( targetPrimaryProperty . kind === "primitive" )
83+ const targetPrimaryKey = targetModel . properties . find ( ( property ) => property . name === targetModel . primaryKey )
84+ assert ( targetPrimaryKey !== undefined )
85+ assert ( targetPrimaryKey . kind === "primitive" )
8686
87- return { ...relation , sourceType : sourcePrimaryProperty . type , targetType : targetPrimaryProperty . type }
87+ return { ...relation , sourcePrimaryKey , targetPrimaryKey }
8888 } ) ,
8989 models,
9090 }
0 commit comments