Type references in `make` call in jasmine tests

#1

Assume these 3 types are correct, the important part is the weight field and that the transform does a straight mapping.

type Airport {
  name : string
}
entity type Airplane schema name 'air' {
  name : string
  home : Airport
  weight: ExactDimension 
}

type CanonicalAirplane ...{
  name : string
  home : Airport
  weight : ExactDimension
}

type TransformCanonicalAirplaneToAirplane mixes Airplane transforms CanonicalAirplane{}

Jasime Test snippet

var canair = CanonicalAirplane.make({
	name : "plane1",
	home : "home1ID",
	weight : {value: 12345, unit: {id: "'kilogram'"}},
});

var planes = CanonicalAirplane.transformCanonical(
  [canair], {targetType: "Airplane"}
);

Before adding the weight field, the home field was populating just fine which seemed odd, since I didn’t call it out as a json object like {id:“home1ID”}. Trying to use the json object notation actually failed. So that’s my first confusion is how to properly structure reference types in the above test - just ID in a string or does it depend on how the reference field is linking to the reference type?

Second, the above Jasmine test will produce an error and I’m not sure how to properly create the weight reference field as it seems inconsistent with the others.

Error: Error in Canonical.transform: Index 0: { "message" : "Error while transforming: {Transformation Type:TransformCanonicalAirplaneToAirplane, Target Airplane, ErrorMsg:Transformation failed: Airplane.weight.weight Error Msg: No implementation found for c3.love.expr.ast.NameNode }", "codes" : [ "TransformationError" ]
0 Likes

#2

Can you elaborate further the question? Here is an example of using nested types in canonicals

0 Likes

#3

yeah - typing stuff in this little window and formatting just wasn’t cooperating today.

0 Likes

#4

I think your json passed to the make is not correct, there is a missing , try with:

var canair = CanonicalAirplane.make({
	name : "plane1",
	home : "home1ID",
	weight : {value: 12345, unit: {id: "kilogram"}}
})
0 Likes

#5

/handwave - this is an example derived from actual work that I doubt I can post on a public forum. Please assume syntax is correct

0 Likes

#6

the error you are experiencing happens when you try to transform a non-primitive type without reconstructing the object during the transformation.

You will need to redefine the appropriate properties for a Type in your transformation.

0 Likes

#7

It’s not about nested types, but rather non primitive types in a canonical. our architecture moves data from raw -> Source Type -> Canonical -> Entity. So that two set of transforms leads us to having a non primitive in the canonical that’s getting transformed again from canon to entity. Per jbraun - I’m breaking it down in the second transform and recreating the non primitive again. will post results when validated.

0 Likes

#8

Jbraun’s suggestion worked. Essentially recoding the non-primitive field in the transform instead of doing a straight field mapping.
My canonical has an ExactDimension field latestWeightQuantity. When I transform the canonical to my entity I had to change the transform from
latestWeightQuantity : ~ expression "latestWeightQuantity" to
latestWeightQuantity : ~ expression {value: "latestWeightQuantity.value", unit: {id:"latestWeightQuantity.unit.id" }}

0 Likes