Skip to content

metarpheus - tagged union generation issues #107

Open
@Cardu

Description

@Cardu

trying the new version of metarpheus in gj, we found following issues:

this

@JsonCodec sealed trait AnalyticsReadError
object AnalyticsReadError {
  case object BotNotFound extends AnalyticsReadError
}

produces the following non-transipiling code:

export const AnalyticsReadError = t.union([
  t.type({
    _type: t.literal('BotNotFound')
  }, 'BotNotFound')
], 'AnalyticsReadError')
final case class RuleConfig(
  ruleId: Id[Rule],
  params: Map[NonBlankString, NonBlankString],
)

export interface RuleConfig {
  ruleId: Id<Rule>,
  params: Record<NonBlankString, NonBlankString>
}
  • sealed trait with only object implementation produces empty union type
@JsonCodec sealed trait BotDeployStatusError

object BotDeployStatusError {
  object BotNotFound extends BotDeployStatusError
}

export const BotDeployStatusError = t.union([

], 'BotDeployStatusError')
  • sealed trait that are implemented by an object containing class implementing the same trait because they are a recursive structure, generates two different models, and the second is an unknown

In GJ we have this Tree structure defined as:

sealed trait AnalyzerTree
object AnalyzerTree {
  final case class Op(
    opType: AnalyzerOpType,
    children: NonEmptyList[AnalyzerTree],
  ) extends AnalyzerTree

  final case class Atom(ruleConfig: RuleConfig) extends AnalyzerTree

...<some other methods here>

export type AnalyzerTree =
  | {
  opType: AnalyzerOpType,
  children: NonEmptyList<AnalyzerTree>,
  _type: 'Op'
}
  | {
  ruleConfig: RuleConfig,
  _type: 'Atom'
}

export const AnalyzerTree = t.union([
  t.type({
    opType: AnalyzerOpType,
    children: NonEmptyList(AnalyzerTree),
    _type: t.literal('Op')
  }, 'Op'),
  t.type({
    ruleConfig: RuleConfig,
    _type: t.literal('Atom')
  }, 'Atom')
], 'AnalyzerTree')

export type AnalyzerTree = unknown;
export const AnalyzerTree = t.unknown;

Metadata

Metadata

Assignees

No one assigned

    Labels

    BE maintbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions