When creating an application with a local registry, the default
behaviour is to define only two core models Model & PersistedModel.
The new flag `loadBuiltinModels` modifies this behaviour and instructs
loopback to define all builtin models in the local registry too.
Fix a regression introduced by b917075 where two loopback projects,
each one using a different instance of loopback module, were
sharing the global registry and thus not working correctly.
The issue was discovered by unit-tests in loopback-workspace.
The commit b917075 accidentally removed a couple of properties,
this commit is bringing them back:
- loopback.modelRegistry
- loopback.defaultDataSources
A unit-test was added to prevent this kind of regressions in the future.
- `loopback.registry` is now a true global registry
- `app.registry` is unique per app object
- `Model.registry` is set when a Model is created using any registry method
- `loopback.localRegistry` and `loopback({localRegistry: true})` when set to `true` this will create a `Registry` per `Application`. It defaults to `false`.
Refactor the core implementation of current context from
server/middleware/context.js into server/current-context.js.
Expose new public API:
- loopback.runInContext
- loopback.createContext
The new location allows developer to use the following identifiers
when loading the middleware using the new declarative style:
app.middlewareFromConfig(
require('loopback/server/middleware/rest'),
{ phase: 'routes' });
app.middlewareFromConfig(
require('loopback/server/middleware/url-not-found'),
{ phase: 'final' });
Modify the app and router implementation, so that the middleware is
executed in order defined by phases.
Predefined phases:
'initial', 'session', 'auth', 'parse', 'routes', 'files', 'final'
Methods defined via `app.use`, `app.route` and friends are executed
as the first thing in 'routes' phase.
API usage:
app.middleware('initial', compression());
app.middleware('initial:before', serveFavicon());
app.middleware('files:after', loopback.urlNotFound());
app.middleware('final:after', errorHandler());
Middleware flavours:
// regular handler
function handler(req, res, next) {
// do stuff
next();
}
// error handler
function errorHandler(err, req, res, next) {
// handle error and/or call next
next(err);
}
- Move configuration of Karma unit-tests from `Gruntfile.js` to a
standalone file (`test/karma.conf.js`).
- Add a new Grunt task `karma:unit-ci` to run Karma unit-tests in
PhantomJS and produce karma-xunit.xml file that can be consumed
by the CI server.
- Add grunt-mocha-test, configure it to run unit-tests.
- Add `grunt test` task that runs both karma and mocha tests,
detects Jenkins to produce XML output on CI server.
- Modify the `test` script in `package.json` to run
`grunt mocha-and-karma` (an alias for `grunt test`).
The alias is required to trick `sl-ci-run` to run `npm test`
instead of calling directly `mocha`.
- Add `es5-shim` module to karma unit-tests in order to provide
ES5-methods required by LoopBack.
- Fix `mixin(source)` in lib/loopback.js to work in PhantomJS.
`Object.getOwnPropertyDescriptor()` provided by `es5-shim` does not
work in the same way as in Node.
Move isBrowser and isServer from lib/loopback to a new file lib/runtime.
Move all Model and DataSource related methods like `createModel` and
`createDataSource` to lib/registry.
Remove the circular dependency between lib/application and lib/loopback,
by loading lib/registry and/or lib/runtime instead of lib/loopback
where appropriate
This commit is only moving the code around, the functionality should
not be changed at all.
Add new API allowing developers to split the model definition and
configuration into two steps:
1. Build models from JSON config, export them for re-use:
```js
var Customer = loopback.createModelFromConfig({
name: 'Customer',
base: 'User',
properties: {
address: 'string'
}
});
```
2. Attach existing models to a dataSource and a loopback app,
modify certain model aspects like relations:
```js
loopback.configureModel(Customer, {
dataSource: db,
relations: { /* ... */ }
});
```
Rework `app.model` to use `loopback.configureModel` under the hood.
Here is the new usage:
```js
var Customer = require('./models').Customer;
app.model(Customer, {
dataSource: 'db',
relations: { /* ... */ }
});
```
In order to preserve backwards compatibility,
`app.model(name, config)` calls both `createModelFromConfig`
and `configureModel`.
Move isBrowser and isServer from lib/loopback to a new file lib/runtime.
Move all Model and DataSource related methods like `createModel` and
`createDataSource` to lib/registry.
Remove the circular dependency between lib/application and lib/loopback,
by loading lib/registry and/or lib/runtime instead of lib/loopback
where appropriate
This commit is only moving the code around, the functionality should
not be changed at all.
Use
@property {Object} [properties]
instead of
@property {Object=} properties
for optional properties.
Use `**example**` instead of `@example`, since strong-docs don't support
the latter.
Add new API allowing developers to split the model definition and
configuration into two steps:
1. Build models from JSON config, export them for re-use:
```js
var Customer = loopback.createModelFromConfig({
name: 'Customer',
base: 'User',
properties: {
address: 'string'
}
});
```
2. Attach existing models to a dataSource and a loopback app,
modify certain model aspects like relations:
```js
loopback.configureModel(Customer, {
dataSource: db,
relations: { /* ... */ }
});
```
Rework `app.model` to use `loopback.configureModel` under the hood.
Here is the new usage:
```js
var Customer = require('./models').Customer;
app.model(Customer, {
dataSource: 'db',
relations: { /* ... */ }
});
```
In order to preserve backwards compatibility with loopback 1.x,
`app.model(name, config)` calls both `createModelFromConfig`
and `configureModel`.
Allow browserified applications to explicitly register connectors
to use in data-sources via `app.connector(name, exportsFromRequire)`.
Include built-in connectors like `Memory` and `Remote` in the registry.
Modify `dataSourcesFromConfig()` to resolve the connector via
`app.connectors` first and only then fall back to auto-require
the connector module.
creating a cache
- Use the SharedClass class to build the remote connector
- Change default base model from Model to DataModel
- Fix DataModel errors not logging correct method names
- Use the strong-remoting 1.4 resolver API to resolve dynamic remote
methods (relation api)
- Remove use of fn object for storing remoting meta data
Add a compatibility layer that allows applications based on LB pre-v1.6
to work with 1.6 versions with a minimum amount of changes required.
New flag(s):
compat.usePluralNamesForRemoting