Commit Graph

120 Commits

Author SHA1 Message Date
Ritchie Martori 805e0e0c1c Merge pull request #1370 from strongloop/fix/check-access-ordering
Use the new remoting.authorization hook for check access
2015-05-12 16:06:47 -07:00
Ritchie Martori 9cde2a45be Use the new remoting.authorization hook for check access 2015-05-12 15:33:05 -07:00
Miroslav Bajtoš f93b69ed0a Define remote methods via model settings/config
Process `settings.methods` and `config.methods` as a key-value map
where the key is the method name and the value is an object describing
the method in the format expected by strong-remoting.

Example: a static method `Model.create`

    "methods": {
      "create": {
        "isStatic": true,
        "accepts": {
           "arg": "data", "type": "Car",
           "http": { "source": "body" }
        },
        "returns": { "arg": "data", "type": "Car", "root": true }
      }
    }

This patch is based on the code proposed by @mrfelton in #1163.
2015-05-07 07:42:08 +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š 7528cbb712 Import subset of underscore.string scripts only
Require individual methods like `classify` instead of the whole module.
This reduces the size of the browser bundle from ~27kb down to ~2kb.
2015-03-25 14:02:16 +01:00
Miroslav Bajtoš a77b3bbac7 Remove usages of deprecated `req.param()`
Express has recently deprecated `req.param()` to force developers
to be explicit about the source of the value. To avoid deprecation
warnings, this commit replaces all calls of `req.param()` with a
simplified inline version.
2015-01-21 19:27:53 +01:00
Ron Edgecomb a028d9d198 Add error code property to known error responses.
Enhance the error objects with a `code` property containing
a machine-readable string code describing the error, for example
INVALID_TOKEN or USER_NOT_FOUND.

Also improve 404 error messages to include the model name.
2015-01-21 19:04:47 +01:00
Ryan Graham 7c0b2e83eb Remove unused underscore dependency 2014-12-02 21:53:30 -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
Rob Halff b54c70c348 Use === to compare with 0 2014-10-22 18:47:53 +02:00
Rob Halff 4ebf10ae0d add missing semicolons 2014-10-22 18:47:52 +02:00
Fabien Franzen 568c8662b4 Support per-model and per-handler remoting options
Allow the developer to pass custom `remoting` options via Model
settings, e.g.

    PersistedModel.extend(
      'MyModel',
      { name: String },
      {
        remoting: { normalizeHttpPath: true }
      });

Also add `options` arg to `app.handler`, this object is passed directly
to strong-remoting handler.
2014-10-22 09:54:15 +02:00
Miroslav Bajtoš 80020eb273 lib/application: improve URL building algo
When running on Unix and no hostname is specified, use `0.0.0.0`
as the hostname instead of `localhost`.

When running on Windows and the hostname is either not specified or
it is `0.0.0.0` or `::`, use `localhost` in the URL. The reason is
that Windows cannot open URLs using `0.0.0.0` as a hostname.
2014-10-20 13:47:24 +02: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
Ritchie Martori 7dde6466e5 Only validate dataSource when defined (Fixes #482) 2014-08-26 17:49:15 +02:00
Miroslav Bajtoš d93b6127c4 Remove `req.resume` from `app.enableAuth`
Remove `req.pause` and `req.resume` from `app.enableAuth`
 - they are no longer needed, the request starts paused and there is
   no other middleware that would resume it before us.
 - when we resume the request after authentication, we force all
   other async operations (like sharedCtor) to call pause & resume too,
   otherwise data are lost
2014-08-12 13:57:45 +02:00
Raymond Feng 9fb0977433 Pass in remotingContext for ACL
See https://github.com/strongloop/loopback/issues/451
2014-08-07 22:19:27 -07:00
Raymond Feng a9e77e0e23 Merge pull request #435 from fabien/feature/deep-remoting
Implement Model.nestRemoting
2014-08-07 10:38:09 -07:00
Fabien Franzen 539702ab3d Inherit hooks when nesting
Note that for now, the hook ctx.instance will be the root/entry object.

Added `mounted` event - should be useful in other ways too.
2014-08-05 12:14:39 +02:00
Raymond Feng 1fd562ecbd Return data source for app.dataSource() 2014-07-30 21:57:08 -07:00
Raymond Feng af26e09845 Emit a 'modelRemoted' event by app.model()
This event will be listened by loopback-explorer so that models remoted
after the explorer is initiated will be added to the api specs
2014-07-24 17:00:27 -07:00
Miroslav Bajtoš c7bca9da78 Remove `app.docs()`
The swagger integration was moved to loopback-explorer.
2014-07-22 15:08:23 +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
Raymond Feng 4e1d8c9a4e Merge branch '1.x' into 2.0 2014-07-16 11:06:24 -07:00
Raymond Feng a28e5b5897 Enhance the error message 2014-07-16 11:04:23 -07:00
Miroslav Bajtoš da9b724222 lib/application: publish Change models to REST API
When a public model is added to an application and the model has change
tracking enabled, its Change model is added to the public models.

Before this change, conflict resolution in the browser was not working,
because it was not possible to fetch the remote change.
2014-07-15 09:31:16 +02:00
Miroslav Bajtoš 8ea11ea955 Merge branch 'master' into 2.0
Land the pull request #357
> app: update `url` on `listening` event
2014-07-01 16:18:00 +02:00
Miroslav Bajtoš dfa8d7f49f app: update `url` on `listening` event
Most applications report the URL when started (at least the apps we
are scaffolding using loopback-workspace). Constructing the URL in the
loopback core allows us to simplify the templates and reduce the amount
of repeated code.
2014-07-01 14:27:02 +02:00
Miroslav Bajtoš c896c78db0 Remove `app.boot`
Modify `app.boot` to throw an exception, pointing users to the new
module `loopback-boot`.
2014-06-25 14:09:06 +02:00
Miroslav Bajtoš 70615696cd Mark `app.boot` as deprecated. 2014-06-25 13:44:07 +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š 843e09342c lib/application: Remove forgotten `loopback` ref
Use `registry.Model` instead of `loopback.Model`.
2014-06-16 09:52:11 +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
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š 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š 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š 19425b8fd9 Remove assertIsModel and isDataSource
Use `instanceof` operator instead:

  ModelCtor.prototype instanceof loopback.Model
  dataSource instanceof loopback.DataSource
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
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
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š 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š 1b11060991 Remove assertIsModel and isDataSource
Use `instanceof` operator instead:

  ModelCtor.prototype instanceof loopback.Model
  dataSource instanceof loopback.DataSource
2014-06-06 10:30: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
Ritchie Martori a2f931ed3f Refactor ACL to allow for `methodNames` / aliases 2014-06-02 14:41:08 -07:00
Miroslav Bajtoš 566757ba1d Deprecate app.boot, remove app.installMiddleware
The bootloader has its own project `loopback-boot` now.
2014-05-29 08:38:39 +02:00
Miroslav Bajtoš 18fd61a546 Merge branch 'master' into 2.0 2014-05-28 18:41:36 +02:00
Miroslav Bajtoš acf7af0c4e Merge pull request #287 from strongloop/feature/connector-registry
app: implement `connector()` and `connectors`
2014-05-28 17:01:24 +02:00