Simplifying TypeScript Class and Struct Definitions with Effect

I wish we could do this easier:
import * as S from "effect/Schema"

export class LichtesMassConfig extends S.Class<LichtesMassConfig>()({
  width: S.Number,
  height: S.Number,
  type: S.String
}) {}

export class ZuschnittConfig extends S.Class<ZuschnittConfig>()({
  widthProfiles: S.Number,
  heightProfiles: S.Number
}) {}

export class ManufacturingConfig extends S.Class<ManufacturingConfig>()({
  cut: ZuschnittConfig,
  color: S.String,
  clearMeasurement: LichtesMassConfig,
  installationSituation: S.String
}) {}

export const LichtesMassConfigImport = S.Struct({
  width: S.Number.pipe(S.propertySignature, S.fromKey("Breite")),
  height: S.Number.pipe(S.propertySignature, S.fromKey("Höhe")),
  type: S.String.pipe(S.propertySignature, S.fromKey("Art"))
}).pipe(S.compose(LichtesMassConfig))

export const ZuschnittConfigImport = S.Struct({
  widthProfiles: S.Number.pipe(S.propertySignature, S.fromKey("Breitenprofile")),
  heightProfiles: S.Number.pipe(S.propertySignature, S.fromKey("Höhenprofile"))
}).pipe(S.compose(ZuschnittConfig))

export const ManufacturingConfigImport = S.Struct({
  cut: ZuschnittConfigImport.pipe(S.propertySignature, S.fromKey("Zuschnitt")),
  color: S.String.pipe(S.propertySignature, S.fromKey("Farbe")),
  clearMeasurement: LichtesMassConfigImport.pipe(S.propertySignature, S.fromKey("Lichtes Maß")),
  installationSituation: S.String.pipe(S.propertySignature, S.fromKey("Einbausituation II"))
}).pipe(S.compose(ManufacturingConfig))

- *Import is only there for reading from the external system, the internal system and it's data store should use the non *Import versions
- the structure is 1:1 apart from the renames
- im doing the compose because I can't just assign a *Import value to a non *Import as they're classes and got instance checks etc.

I thought maybe non Import = Import minus property signatures, but one can't easily restore the schemas contained within the property signatures of course, and we still need to do things recursively.
The inverse: Import = Non Import + S.rename, but now both encoded and decoded are renamed. also in my case, it also happens to be that Non Import code could more easily point to Import code rather than the other way around, but that's just my organizational concern I suppose.
Was this page helpful?