Commit Graph

71 Commits

Author SHA1 Message Date
Ryan Graham 4d6f2e7ab7
update/insert copyright notices 2016-05-03 17:10:46 -07:00
Richard Walker 65ca318392 Create stack-removing errorhandler middleware
Create a wrapper around express' errorhandler that removes the stack
trace from error responses when "options.includeStack" is false.
2015-09-03 08:38:24 +02:00
Samuel Gaus ecc98fd29c Allow EJS templates to use includes
Simple change that allows templates to use includes.
2015-08-27 16:37:04 +01:00
Miroslav Bajtoš 0ccc1e2b73 Add loadBuiltinModels flag to loopback(options)
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.
2015-06-01 12:19:28 +02:00
Miroslav Bajtoš f130b7aa01 Rework global registry to be per-module-instance
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.
2015-04-17 19:26:05 +02:00
Miroslav Bajtoš 4d0a824757 Add back loopback properties like modelBuilder
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.
2015-04-17 18:05:25 +02:00
Ritchie Martori b9170751bc Add support for app level Model isolation
- `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`.
2015-04-03 11:48:45 -07:00
Miroslav Bajtoš 2aa09ba574 Add `loopback.runInContext`
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
2015-03-27 19:12:17 +01:00
Miroslav Bajtoš 7fc66a182e Move middleware sources to `server/middleware`
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' });
2014-11-12 12:44:34 +01:00
Raymond Feng f803ecec55 Make sure loopback has all properties from express 2014-11-11 11:27:39 -08:00
Miroslav Bajtoš 8f5aea3e3b Fix `loopback.getCurrentContext`
- ensure the method is always defined

 - return `null` when the context is not active
   (we are not inside a request-handling chain)
2014-11-11 11:04:41 +01:00
Miroslav Bajtoš 4e1433b519 Middleware phases - initial implementation
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);
    }
2014-11-10 19:50:58 +01:00
Rand McKinney 0e35c1877c Changes to JSdoc comments
Moved faviconFile to class properties.
2014-11-04 10:59:38 -08:00
Miroslav Bajtoš 48d4ed28d3 Coding style cleanup (Gruntfile, lib)
- Gruntfile: add `jshint` and `jscs` as deps of `grunt test`
 - Gruntfile: temporarily disable checks of `test` scripts
 - .jscsrc: relax jsdoc validation
 - .jshintrc: relax the rule for property access via dot notation
 - lib: fix remaining style issues
2014-11-04 08:25:35 +01:00
Rob Halff 33096dafa7 Enable jscs for `lib`, fix style violations 2014-11-04 08:25:33 +01:00
Miroslav Bajtoš edd464aca5 Expose path to the built-in favicon file
The path is available via `loopback.faviconFile`.
2014-11-03 10:00:24 +01:00
crandmck 2f4a54d93c Clean up jsdoc comments
Add class properties, expose some methods that should have
been documented, etc.
2014-10-15 09:42:24 +02:00
Miroslav Bajtoš 3a0f793c9b Register built-in models in a standalone file
Move the code registering built-in models to a new file
`lib/builtin-models.js`.
2014-10-13 12:09:19 +02:00
Miroslav Bajtoš eb5ef04b6a Remove `loopback.compat.usePluralNamesForRemoting`
The `usePluralNamesForRemoting` was added in January 2014 for users
upgrading from LoopBack 1.5 or older.
2014-07-21 16:56:46 +02:00
Miroslav Bajtoš 50816ebbe3 Fix loopback in PhantomJS, fix karma tests
- 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.
2014-06-26 13:30:09 +02:00
Miroslav Bajtoš d2517d8236 Merge branch 'master' into 2.0 2014-06-14 09:40:57 +02:00
Miroslav Bajtoš c4db83ad43 Expose loopback as `app.loopback`
The primary intention is to allow loopback plugins to determine
the version of the loopback framework from the `app` object.
2014-06-13 10:34:51 +02:00
Miroslav Bajtoš d21669b844 Merge branch 'master' into 2.0
Conflicts:
	docs.json
	lib/application.js
	lib/loopback.js
	lib/models/data-model.js
	lib/models/model.js
	lib/models/user.js
	lib/registry.js
	package.json
	test/app.test.js
2014-06-13 10:09:25 +02:00
Miroslav Bajtoš 7d674779e1 refactor: extract runtime and registry
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.
2014-06-12 10:41:44 +02:00
Miroslav Bajtoš fc0fad4a9f Add createModelFromConfig and configureModel()
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`.
2014-06-12 10:41:44 +02:00
Miroslav Bajtoš b576639d90 Add loopback.version back
Add `loopback.version` that was accidentaly removed by #308.
2014-06-10 11:19:36 +02:00
Miroslav Bajtoš eac231df99 refactor: extract runtime and registry
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.
2014-06-06 11:53:23 +02:00
Miroslav Bajtoš 51e977de9b lib/loopback: fix jsdoc comments
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.
2014-06-06 10:28:21 +02:00
Miroslav Bajtoš 5f1c3a86eb Merge pull request #304 from strongloop/feature/createModelFromConfig
[2.0] Add createModelFromConfig and configureModel()
2014-06-06 10:27:03 +02:00
Miroslav Bajtoš f844459311 Add createModelFromConfig and configureModel()
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`.
2014-06-05 17:47:28 +02:00
Miroslav Bajtoš ea5b9d16fc Rename DataModel to PersistedModel 2014-06-05 09:56:00 +02:00
Miroslav Bajtoš 88a4bb462e Exclude express-middleware from browser bundle
Fix lib/loopback to include express-middleware only on the server.

Bump up strong-remoting dependency to use the version working in
browsers.
2014-06-03 21:32:27 +02:00
Raymond Feng bb0ddb26ec Rename express-wrapper to express-middleware 2014-05-29 10:18:58 -07:00
Raymond Feng 49380e490f Upgrade to Express 4.x 2014-05-29 08:44:05 -07:00
Miroslav Bajtoš 18fd61a546 Merge branch 'master' into 2.0 2014-05-28 18:41:36 +02:00
Miroslav Bajtoš 94ec5c294a app: implement `connector()` and `connectors`
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.
2014-05-28 15:11:43 +02:00
Miroslav Bajtoš 7cfe450161 Make app.datasources unique per app instance
This removes a source of confusion in unit-tests.
2014-05-27 14:33:42 +02:00
Ritchie Martori eec7bdd5f4 - Use the RemoteObjects class to find remote objects instead of
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
2014-05-19 15:56:26 -07:00
Ritchie Martori e86a00de69 Merge branch master 2014-04-15 12:53:00 -07:00
Ritchie Martori 5298834c68 Merge branch 'master' into feature/remoting-connector 2014-04-14 11:01:20 -07:00
crandmck 006aca6b9c Update and cleanup JSDoc 2014-04-02 15:46:39 -07:00
Ritchie Martori dcdbef861e Add Remote connector 2014-03-27 14:47:29 -07:00
Ritchie Martori 57ff242308 Minor doc fix 2014-03-10 18:05:44 -07:00
Ryan Graham 088c2e2296 Merge fixup 2014-02-19 14:11:16 -08:00
Ritchie Martori 138821cf8b Merge package.json and lib/loopback.js 2014-02-19 11:44:44 -08:00
Raymond Feng 46b579dc4a Make sure User/AccessToken relations are set up by default
User.login assumes the relation User.accessTokens exists
2014-02-14 10:31:30 -08:00
Ritchie Martori e7f64a3abf Add karma for running browser tests 2014-02-12 10:17:02 -08:00
Miroslav Bajtoš b13ff35697 Make app.models unique per app instance
Remove a source of confusion in unit-tests.
2014-02-04 20:28:19 +01:00
Miroslav Bajtoš 20766e251a Add loopback.compat to simplify upgrade to 1.6
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
2014-01-27 10:29:57 +01:00
Ritchie Martori 4be3395298 Add Change model 2014-01-26 13:20:19 -08:00