Migration from version 2.x
This chapter provides a set of guidelines to help you migrate from Marble.js version 2.x to the latest 3.x version.
The newest iteration comes with some API breaking change, but don’t worry, these are not game-changers, but rather convenient improvements that open the doors to new future possibilities. During the development process, the goal was to notify and discuss incoming changes within the community as early as possible. You can check here what has changed since the latest version.
@marblejs/core
fp-ts
fp-ts@2.x
is a required peer dependency (next to rxjs
)
Context API
fp-ts@2.x
introduced changes that have a major impact to Context API (eg. Reader monad).
Version 3.0 introduces more explicit dependency binding. Previous API wasn't so precise, which could result to confusion, eg. when the dependency is lazily/eagerly evaluated.
Context❌ Old:
✅ New:
Readers
❌ Old:
✅ New:
You can create context readers via raw Reader monad composition (using available fp-ts toolset) or using createReader
utility function that saves a lot of unnecessary boilerplate.
Server creators
The release of fp-ts also had an impact to HTTP and WebSocket server creators. run()
method on Reader, etc. has been replaced with IO thunk. Additionally all server creators are promisified, which means that they will return an instance only when started listening. The change applies to all main modules: @marblejs/core
, @marblejs/websockets
, @marblejs/messaging
. More info you can find in PR #198
Bootstrapping:
❌ Old:
✅ New:
Unified config interfaces for all kind of server creators:
Effect
Marble.js v2.0 Effect
interface defines three arguments where the second one is used for accessing contextual client, eg. HttpResponse, WebSocketClient, etc. Typically the second argument was not used very often. That's why in the next major version client parameter moves to context object. It results in reduced available number of parameters from 3 to 2.
The change applies to all Effect interfaces, eg. HttpEffect
, WsEffect
, MsgEffect
❌ Old:
✅ New:
This change also implies a much cleaner base Effect
interface:
With that change the last argument of Effect interface is no more called as EffectMetadata
but rather as EffectContext
.
ErrorEffect
When dealing with error or output Effect, the developer had to use the attribute placed in the third effect argument. In Marble.js v3.0 the thrown error is passed to stream directly.
❌ Old:
✅ New:
OutputEffect
❌ Old:
✅ New:
HttpRequest
The HttpResponse object is no more carried separately but together with correlated HttpRequest.
@marblejs/middleware-logger
The newest implementation of logger middleware uses underneath the pluggable Logger dependency, so dedicated log streaming is unnecessary. The developer can simply override default Logger binding and forward the incoming logs on his own. Also, since HttpRequest
contains the response object attached to it - res
attribute is redundant.
❌ Old:
✅ New:
Last updated