• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

strongloop / loopback-next / 1933
76%

Build:
DEFAULT BRANCH: master
Ran 29 Aug 2017 08:23AM UTC
Jobs 2
Files 65
Run time 3min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

pending completion
1933

push

travis-ci

web-flow
feat(repository): simplify usage of juggler bridge (#539)

**Fix `DefaultCrudRepository` methods to return expected instances**

Before, the type annotation of DefaultCrudRepository said that
CRUD methods are returning Entity instances, but in fact these
methods were returning PersistedModel instances.

Note that PersistedModel is inheriting from juggler's ModelBase class,
while Entity is inheriting from our new Model base class, and these two
inheritance chains never meet.

This commit fixes DefaultCrudRepository to convert internal
PersistedModel instances into the correct Entity instances expected
by the users of this class.

Under the hood, DefaultCrudRepository was changed to expect the Entity
model constructor function in the constructor argument, and build
the backing PersistedModel as an internal implementation detail.
This is possible thanks to static `definition` property required by
all `Model`/`Entity` classes.

**Decouple Entity/Model definition from datasources**

Before:

In order to define a model, one has to already have the datasource
the model will be eventually attached to. This makes dependency
injection impossible, because only the datasource used to create the
model could be used to build a repository instance for that model.

```ts
/* tslint:disable-next-line:variable-name */
const Note = ds.createModel<typeof juggler.PersistedModel>(
  'note',
  {title: 'string', content: 'string'},
  {},
);
```

Now:

Models are defined independently on backing datasources and
repositories, using `class` and `extends` keywords. No magic!

```ts
export class Note extends Entity {
  static definition = new ModelDefinition('note',
    {title: 'string', content: 'string'},
    {});
}
```

**Improve `@model` to build full model definition**

`DefaultCrudRepository` requires Entity-based models to provide their
model definition in the static `definition` property. This was not
supported by `@model` decorator before.

This commit improves `@model` implementation to build full model
definition including properties described via `@property` decorator,
and store this full definition in the static `definition` property.

This makes it easy to use `@model`-decorated entities together
with `DefaultCrudRepository`

**Simplify the process of defining properties**

Before, a property definition has to contain the property name,
despite the fact that the property name is also used as the key
in the property-name to property-definition map.

`PropertyDefinition` was defined as a class, which has two problems:
 - juggler supports only plain objects for property definitions
 - users cannot use plain objects to define properties

This commit changes `PropertyDefinition` to a mere interface,
removes extraneous `name` property and generally simplifies
model definition API to support the syntax we are used to in
the existing LB 3.x version.

**Add an acceptance test for Thinking in LoopBack**

This whole effort was driven by an acceptance test to verify
that the approach described in Thinking in LoopBack actually works in
practice. This test is included to make sure we don't accidentally
break in in the future.

462 of 528 branches covered (87.5%)

Branch coverage included in aggregate %.

1391 of 1460 relevant lines covered (95.27%)

134.78 hits per line

Jobs
ID Job ID Ran Files Coverage
1 1933.1 29 Aug 2017 08:27AM UTC 0
93.21
Travis Job 1933.1
2 1933.2 29 Aug 2017 08:23AM UTC 0
93.21
Travis Job 1933.2
Source Files on build 1933
Detailed source file information is not available for this build.
  • Back to Repo
  • Travis Build #1933
  • 2cf4d2b3 on github
  • Prev Build on master (#1922)
  • Next Build on master (#1935)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc