Adam S
07/11/2022, 4:22 PMBig Chungus
07/11/2022, 5:41 PMBig Chungus
07/11/2022, 5:41 PMAdam S
07/11/2022, 6:02 PM@JsExport
are more focused on re-using code. kxs-ts-gen is focused on serialization.
It's also a lot more flexible. In Kotlinx Serialization you can define custom serializers, like serializing a colour class Colour(0, 255, 255, 100)
as a hex string. kxs-ts-gen will automatically take that into account, and generate compatible TypeScript interfaces.Adam S
07/11/2022, 6:05 PM[0, 2, 10]
is more compact than { "x": 0, "y": 2, "z": 10 }
I don't think the above is possible with @JsExport
Joffrey
07/12/2022, 12:25 PMBig Chungus
07/12/2022, 12:30 PMBig Chungus
07/12/2022, 12:30 PMBig Chungus
07/12/2022, 12:31 PMJoffrey
07/12/2022, 12:33 PMBig Chungus
07/12/2022, 12:37 PMAdam S
07/12/2022, 5:09 PMAre you saying that the generated TS interfaces reflect the format on the wire instead of using a code-friendly structure similar to what is in the Kotlin classes?yes, it generates TS interfaces. I don't know what you mean by 'code friendly structure'? I'm actually using this for a TypeScriptToLua project, so Kotlin/JS isn't an option at all. If I didn't have this tool then I'd have to manually create TypeScript interfaces to match the JSON that the
@Serializable
Kotlin classes produce - which I find error prone and laborious. I looked into generating both TS and Kt from a schema (like OpenAPI) - but nothing was satisfying. It's nice having a Kotlin-first approach.
kxs-ts-gen is re-treading ground - ProtoBufSchemaGenerator does the same thingJoffrey
07/13/2022, 10:01 AMx, y, z
properties for a 3D point, or an enum type to repesent a set of possible values. When the wire format is different (e.g. an array for the 3D point, or integers for the enum), it's usually because it's more optimal for transport, but it's never because it's easier to work with from the code (otherwise the Kotlin declaration would be just changed to that other format).
So my point is, the initial declarations in Kotlin code are either equal or better-suited for usage from code than the wire format, so if you could better match the initial Kotlin declarations in your TS definitions, it would usually be better from the consumer's perspective. This, of course, means that you do need deserialization facilities to convert from the wire format to those "better" TS interfaces.
Representing the wire format is easier of course, and might be "good enough" for some use cases. This is probably what justifies the simplification of just representing a suboptimal wire format in code without deserialization code. However, in the extreme case where a lot of custom serialization is used to reduce the payload, the wire format will be really uncomfortable to use from TS. That said, maybe this extreme case is just theoretical, and people interested in optimizing that much would just use a more efficient binary format like protonschulzke
07/13/2022, 1:48 PM