Mixing transform logic into another transform


I mixed a transform into another transform to avoid code duplication. The following premise works:

abstract type AbstractSourceTypeToEntityType
  mixes EntityType
  transforms AbstractSourceType {
  entityField: ~ expression "sourceField"

type SourceTypeToEntityType
  mixes EntityType, AbstractSourceToEntityType
  transforms SourceType

With the above code, loading a SourceType will use the transform logic within AbstractSourceTypeToEntityType to persist an EntityType.

But, is this recommended by C3 IoT? If I change the mix-in order, the platform throws the following error:

type SourceTypeToEntityType
  mixes AbstractSourceToEntityType, EntityType
  transforms SourceType

Invalid target type EntityType for canonical SourceType

I’m wondering if this is an unsupported hack or if I can rely on this method to avoid code duplication.


On a side note, you don’t need to explicitly mix EntityType in SourceTypeToEntityType, as the later mixes AbstractSourceTypeToEntityType which itself mixes EntityType.


Unfortunately, that doesn’t work. For this method to work, SourceTypeToEntityType must explicitly mix EntityType, or the platform throws the following error:

Error in Canonical.transform: Invalid target type EntityType for canonical SourceType

This is another detail that makes me worry whether I can rely on this method.


I’ve been looking for this type of capability for a long time on our CDC logic. I would assume that transforms should have one mixes as it’s the single target getting created, just as transforms seems to be singular. However, if it’s letting it slip in, I wonder if it’s because the order is loosely tied to the last mixin being the transform’s target while anything prior is treated as a typical mixin. If only we had a grammar…