Commit Graph

206 Commits

Author SHA1 Message Date
Miroslav Bajtoš 7316048afc lib/registry: `getModel` throws, add `findModel`
Rename `loopback.getModel` to `loopback.findModel`.

Implement `loopback.getModel` as a wrapper around `findModel` that
throws an error when the model as not found.
2014-06-16 16:13:24 +02:00
Miroslav Bajtoš 56c7a6b3c5 Merge branch 'master' into 2.0
Conflicts:
	test/access-token.test.js
2014-06-16 10:20:22 +02:00
Miroslav Bajtoš 8826b6396a Merge pull request #306 from karlmikko/master
Ability to return 401 and 403 response codes #301
2014-06-14 09:44:22 +02:00
Miroslav Bajtoš d2517d8236 Merge branch 'master' into 2.0 2014-06-14 09:40:57 +02:00
Karl Mikkelsen a90a5c7e58 Allow customization of ACL http status
emulate existing error on 404
new tests for model and app settings
Signed-off-by: Karl Mikkelsen <karl@karlmikko.com>
2014-06-14 11:31:15 +10: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š 362cceb70a Merge createModelFromConfig with createModel
Merge the two methods `loopback.createModel` and
`loopback.createModelFromConfig` into a single method `createModel`.
2014-06-12 10:41:45 +02:00
Miroslav Bajtoš f0ff40d3f7 test: add debug logs
Add debug logs to troubleshoot two unit tests failing
on the CI server only.
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š 3deadcd180 test: fix ACL integration tests
Change the tests creating new users so that they send valid user data,
in order to prevent 422 "validation failed" responses.

Upgrade loopback-testing to 0.2.0.
2014-06-12 10:33:40 +02:00
Raymond Feng 7769174d58 Tidy up app.model() to remove duplicate & recusrive call 2014-06-09 23:53:01 -07:00
Raymond Feng 815ad53aa4 Register existing model to app.models during app.model() 2014-06-09 16:31:33 -07:00
Raymond Feng 6b4ebdf609 Allow the creation of access token to be overriden 2014-06-09 14:53:55 -07:00
Miroslav Bajtoš 56aab8dbdd Merge createModelFromConfig with createModel
Merge the two methods `loopback.createModel` and
`loopback.createModelFromConfig` into a single method `createModel`.
2014-06-09 11:18:52 +02:00
Miroslav Bajtoš 1de6325a80 test: add debug logs
Add debug logs to troubleshoot two unit tests failing
on the CI server only.
2014-06-06 14:51:43 +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š 26874fc715 Make app.get/app.set available in browser
Implement settings object and methods in browser-express.

Add test/app.test.js to unit-tests run by karma.
2014-06-03 21:32:27 +02:00
Ritchie Martori fea1cee1c4 !fixup only set ctx.accessType when sharedMethod is available 2014-06-02 14:41:08 -07:00
Ritchie Martori a2f931ed3f Refactor ACL to allow for `methodNames` / aliases 2014-06-02 14:41:08 -07:00
Raymond Feng 663e2d1903 Merge pull request #293 from strongloop/feature/express-4.x
Upgrade to Express 4.x
2014-06-02 08:26:35 -07:00
Miroslav Bajtoš 5b53da93db test: Remove forgotten call of `console.log()`
The `console.log()` call was added by 94ec5c2.
2014-06-02 08:34:08 +02:00
Raymond Feng 3c7cfcaca8 Clean up the tests 2014-05-29 10:18:14 -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
Miroslav Bajtoš 227c2d05cd app: flatten model config
Support flat structure of model config objects, where model options
are set as top-level properties.

Before:

    Customer: {
      dataSource: 'db',
      options: {
        base: 'User'
      }
    }

Now:

    Customer: {
      dataSource: 'db',
      base: 'User'
    }
2014-05-27 08:10:20 +02:00
Raymond Feng ed0b568542 Fix the test for mocha 1.19.0
See 6c705cd4d4
2014-05-26 21:52:48 -07:00
Miroslav Bajtoš bfb154d445 Modify `loopback.rest` to include `loopback.token`
Make `loopback.rest` self-contained, so that authentication works
out of the box.

    var app = loopback();
    app.enableAuth();
    app.use(loopback.rest());

Note that cookie parsing middleware is not added, users have to
explicitly configure that if they want to store access tokens
in cookies.

Modify `loopback.token` to skip token lookup when the request already
contains `accessToken` property. This is in line with other
connect-based middleware like `cookieParser` or `json`.
2014-05-21 15:22:36 +02:00
Ritchie Martori 7eeed19bf0 Relax validation object test 2014-05-20 14:39:28 -07:00
Ritchie Martori d237ae5ddb Merge latest from master 2014-05-20 14:31:09 -07: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 4d5e7884c2 Add test for conflicts where both deleted 2014-05-16 09:58:23 -07:00
Miroslav Bajtoš 4b3d20e409 test/geo-point: relax too precise assertions
Relax the assertions to verify only the integer part of the distances.
The decimal part is subject to small variances depending on the exact
implementation of floating-point arithmetic.

For example, the distance calculated on Node v0.11.13 is different
than the distance calculated on Node v0.10.x.
2014-05-16 16:24:18 +02:00
Ritchie Martori 2f21f4ec1e Rework replication test 2014-05-15 17:30:58 -07:00
Ritchie Martori 5bf1f76762 !fixup Test cleanup 2014-05-07 07:44:00 -07:00
Ritchie Martori a3a6828709 Move replication implementation to DataModel 2014-05-06 13:31:23 -07:00
Ritchie Martori f8b5fa11ec All tests passing 2014-05-02 21:19:14 -07:00
Ritchie Martori ae2fb9dea0 !fixup use DataModel instead of Model for all data based models 2014-05-02 20:15:01 -07:00
Ritchie Martori e026a7f52c fixup! unskip failing tests 2014-05-02 20:07:59 -07:00
Ritchie Martori 012f880078 !fixup RemoteConnector tests 2014-05-02 20:04:06 -07:00
Ritchie Martori 1c7527ae3d Add missing test/model file 2014-05-02 18:12:50 -07:00
Ritchie Martori 918596f035 Refactor DataModel remoting
- Move DataModel remoting setup into setup phase
 - Add a remoting type converter for DataModels
 - Move model tests into re-usable test utilities
 - Move other test utilities into new test utilities folder
2014-05-02 18:12:24 -07:00
Ritchie Martori e35309ba27 Fixes for e2e replication / remote connector tests 2014-04-29 17:17:49 -07:00
Raymond Feng 921e35954d Rename the method so that it won't conflict with Model.checkAccess
See https://github.com/strongloop/loopback/issues/239
2014-04-21 11:13:03 -07:00
Ritchie Martori 83e74ab414 Merge 2014-04-16 07:39:13 -07:00
Ritchie Martori b660f8a59e Add replication e2e tests 2014-04-16 07:33:17 -07:00