Skip to content

Get rid of peer dependency on loopback-datasource-juggler #275

Closed
@bajtos

Description

@bajtos

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 type Point. The call is made from initialize.
  • All SQL connectors are extending juggler.BaseSQL

I am proposing to make the following changes:

  • Move BaseSQL and Connector (which is super class of BaseSQL) to a new module (e.g. loopback-connector-base or loopback-connector). Modify connectors to use this new module instead of juggler.
  • To preserve backwards compatibility, juggler should probably require loopback-connector-base and expose BaseSQL and Connector classes. This can be removed in the next major version.
  • Modify the signature of initialize function from initializeDataSource(dataSource, callback) to initializeDataSource(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:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions