跳过导航
Your domain model is not JSON. It does not have to be.
0:00 / 1:11

Your domain model is not JSON. It does not have to be.

Giulio Canti

@GiulioCanti3525 位关注者

在 X 上查看
200 个赞下载原帖

19,126 次观看

Your domain model is not JSON. It does not have to be. In Effect v4, `Schema.toCodecJson` handles the bridge automatically, even for custom types. ↓

10 条评论

评论来自 X (Twitter) 上的原帖

  • Sebastian Lorenz 的头像

    @thefubhy

    It's weird that there is a Schema.Graph but not Schema.Cron

    11 个赞

  • teej dv 🔭 的头像

    @teej_dv

    is there a way to avoid calling json.parse in the examples? i can't remember what the "right" way is to do that there

    5 个赞

  • Giulio Canti 的头像

    @GiulioCanti

    Yes, you can compose it with Schema.fromJsonString const jsonStringCodec = Schema.fromJsonString( Schema.toCodecJson(WalletSnapshot) ) The same codec also encodes directly to a JSON string. I kept JSON.parse explicit only to distinguish JSON text from JSON safe data

    10 个赞

  • teej dv 🔭 的头像

    @teej_dv

    got it, that was the one i think i was missing. ty ty

    2 个赞

  • Théo Pomies 的头像

    @theopomies

    One day we'll have fullstack Effect and this will be one of the pillars

    3 个赞

  • Stress and pressure 的头像

    @iSnifer

    There are plenty methods that use it under the hood, so you don't need to call it manually: HttpBody.jsonSchema, HttpClientRequest.schemaBodyJson, HttpClientResponse.schemaJson, HttpClientResponse.schemaBodyJson, HttpServerRequest.schemaBodyJson, HttpServerResponse.schemaJson, HttpIncomingMessage.schemaBodyJson, etc

    2 个赞

  • Andrea 的头像

    @andreafspeziale

    Somehow recalls me the old good days of io-ts

    1 个赞

  • Buswe 的头像

    @buswe_com

    Keeping the codec at the edge lets your domain model hold rich types like Date, bigint or branded ids and only flatten to JSON on the wire.

  • Patrick Roza 的头像

    @patroza

    The one time it’s kind of a downside is when you have a document database query engine where you’re expected to pass in json values; as json codecs are untyped. Encoded in v3 worked well there. Then again, we can of course build the query api as Type or Encoded, and then use the json codec internally to translate

  • Anders Lie 的头像

    @anderslie

    literal godsend. how does it handle optional / make sure no undefined is in the serialized form? current pain is defining Schema.optionalWith(..., { exact: true, as: "Option" }) everywhere to make sure undefined is omitted from keys entirely