Description
LoopBack has a peer dependency on loopback-datasource-juggler. As explained in an older comment:
Before peerDependency is adopted, we end up with the following tree:
myapp
--> loopback --> loopback-datasource-juggler
--> loopback-connector-mongodb --> loopback-datasource-juggler
Having multiple instances of juggler is a problem because then there are multiple instances of the global Model registry.
I have looked at several connectors (mysql, postgresql, oracle, rest, soap) and found the following usages of loopback-datasource-juggler:
- Mysql connector calls
juggler.ModelBuilder.registerType
to register a custom typePoint
. The call is made frominitialize
. - All SQL connectors are extending
juggler.BaseSQL
I am proposing to make the following changes:
- Move
BaseSQL
andConnector
(which is super class of BaseSQL) to a new module (e.g.loopback-connector-base
orloopback-connector
). Modify connectors to use this new module instead of juggler. - To preserve backwards compatibility, juggler should probably require
loopback-connector-base
and exposeBaseSQL
andConnector
classes. This can be removed in the next major version. - Modify the signature of
initialize
function frominitializeDataSource(dataSource, callback)
toinitializeDataSource(dataSource, ModelBuilder, callback)
.
The new dependency graph would look like this:
myapp
--> loopback --> loopback-datasource-juggler -> loopback-connector-base
--> loopback-connector-mongodb --> loopback-connector-base
/to @ritch @Raymond what's your opinion on this? I am happy to implement these changes once I get green light from you.
Note: if we are going to release juggler 2.x then it should wait until this change is made, as it allows us to drop juggler dependency on connector base.
Connector check list:
- mysql (v1.3.0)
- mongodb (v1.3.0)
- rest (v1.2.1)
- soap (v1.1.0)
- postgresql (v1.1.0)
- oracle (v1.4.0)
- mssql (v1.1.0)
- kafka - see Remove peer dep on loopback haio/loopback-connector-kafka#1
- neo4j
- Incorrect dependency on juggler and strong-remoting loopback-connector-remote#5