Guidance on Using Codecs in Effect Schema and Serialization
Hey related to my previous message but more general, I'm looking for some guidance and opinioins on how to think about codecs in effect schema, e.g. when should a string be considered the encoded form versus it just being a 'representation' of the struct, perhaps one of many -- and then codecs are instead about making things serializable and once a sschema has achieved being json serializable then it shouldn't use codecs anymore.
A few things that are rubbing me the wrong way:
- if using classes and wanting a codec for that class you have to have a module that first defines the class, then another def of the S.transform... part, and you still have to export the defined class in order to satisfty TS type referrability (inference breaks if the class is not exported because callers can't see the underlyting type, compiler stuff)
- choosing string as a cannonical encoded form seems arbitrary, at least in cases where the other option is just send the struct as is -- codecs do not play well with the concept of a data type and multiple 'exporters' and this leads me to begin seeing codecs as not being in charge of data type transformations but again really that serialization layer
A few things that are rubbing me the wrong way:
- if using classes and wanting a codec for that class you have to have a module that first defines the class, then another def of the S.transform... part, and you still have to export the defined class in order to satisfty TS type referrability (inference breaks if the class is not exported because callers can't see the underlyting type, compiler stuff)
- choosing string as a cannonical encoded form seems arbitrary, at least in cases where the other option is just send the struct as is -- codecs do not play well with the concept of a data type and multiple 'exporters' and this leads me to begin seeing codecs as not being in charge of data type transformations but again really that serialization layer
