Commit Graph

1076 Commits

Author SHA1 Message Date
crandmck d4b0a26a0e Improved and corrected API docs 2015-03-04 17:21:25 -08:00
crandmck e81415ceda Fix problems in annotations that prvented validateAsync and validate functions from appearing in API docs. 2015-03-03 16:58:19 -08:00
Raymond Feng 8042eeb3b1 Make sure inclusion filter is applied to the target model
See https://github.com/strongloop/loopback/issues/1076
2015-02-28 10:53:18 -08:00
Miroslav Bajtoš 17a999bfca Merge pull request #473 from strongloop/feature/deprecate-model-hooks-and-events
Deprecate model hooks and events
2015-02-27 19:37:39 +01:00
Miroslav Bajtoš 37d7721e0e Deprecate DAO events
List of deprecated events:

 - changed
 - deleted
 - deletedAll
2015-02-27 17:03:39 +01:00
Miroslav Bajtoš 03daaca9de Deprecate Model hooks
List of deprecated hooks:

 - beforeValidate
 - afterValidate
 - beforeCreate
 - afterCreate
 - beforeSave
 - afterSave
 - beforeUpdate
 - afterUpdate
 - beforeDestroy
 - afterDestroy

Also add a lightweight browser version of "depd", because the "depd"
does not support browser and it is not trivial to fix that.
This commits adds a lightweight implementation of depd's "deprecate"
function.
2015-02-27 16:58:24 +01:00
Partap Davis 1e6c453191 Add Promises to DAO
When a callback is omitted from a DAO method, return a Promise that
resolves to the value normally passed to the callback of that method.
If a callback is provided, behave normally.

This API will use native ES6 promises if available.  If not available,
or to force the use of another Promise library, you must assign the
global.Promise object.

e.g.:
global.Promise = require('bluebird')

Class methods affected:

- create
- updateOrCreate / upsert
- findOrCreate
- exists
- find
- findOne
- findById
- findByIds
- remove / deleteAll / destroyAll
- removeById / deleteById / destroyById
- count
- update / updateAll

Prototype methods affected:

- save
- delete / remove / destroy
- updateAttribute
- updateAttributes
- reload

Exceptions / edge cases:

- create() used to return the data object that was passed in, even if
  no callback was provided.  Now, if a callback is provided, it will
  return the data object, otherwise it will return a Promise.

- If create() is provided an array of data objects for creation, it
  will continue to always return the array. This batch creation mode
  does not support promises.

- findOrCreate() has a callback of the form: cb(err, instance, created),
  with the extra parameter indicating whether the instance was created
  or not. When called with its promise variant, the resolver will
  receive a single array parameter: [instance, created]
2015-02-26 13:45:37 -07:00
Raymond Feng 6891da4535 Merge pull request #470 from rudzon/master
Enhance updateAll to coerce the data per property definitions
2015-02-24 08:28:39 -08:00
rudzon dbe9329a37 enhance the coercion for boolean/date types 2015-02-24 13:55:57 +02:00
rudzon 35825f5e53 enhance updateAll to coerce the data per property definitions 2015-02-24 13:53:23 +02:00
Miroslav Bajtoš 52e78ff5ae relation-definition: remove trailing whitespace 2015-02-24 11:36:13 +01:00
Raymond Feng e659e2f603 Fix JS style issues 2015-02-20 14:57:48 -08:00
Miroslav Bajtoš ba0f3c1616 Add a new property option `defaultFn`
The property allows developers to specify that the default value
should be retrieved via a named function.

Only two built-in functions are supported at the moment:

  "guid", "uuid" - generate a new GUID/UUID
  "now" - use the current date and time

Support for custom (user-provided) functions is not implemented yet.
2015-02-20 20:08:25 +01:00
Miroslav Bajtoš c939efe1e7 Merge pull request #445 from PradnyaBaviskar/issue292
Add $now as shortcut default value for date property
2015-02-17 19:46:05 +01:00
Miroslav Bajtoš 76ebdcb91b ModelBaseClass: promise mode for notifyObserversOf
Support both promise and callback styles in
ModelBaseClass.notifyObserversOf.

When there is no callback supplied, the method returns a promise that
is resolved (or rejected) with the result.
2015-02-17 18:19:21 +01:00
Miroslav Bajtoš a2836fbb56 ModelBaseClass: support promise-based observers
Allow the observer functions passed to `ModelBaseClass.observe`
to return a promise instead of calling the callback.
2015-02-17 17:31:42 +01:00
Bryan Clark 98fcf6b52c use lodash to update the findBelongsTo which now returns an array of matches 2015-02-16 15:36:51 -08:00
Pradnya Baviskar aba7d0dc10 Add $now as shortcut default value for date property 2015-02-16 11:32:24 +05:30
Miroslav Bajtoš 46ff76dda0 Fix `deleteById(id)` and other test failures 2015-02-13 09:34:40 -08:00
Raymond Feng cc1791b01d Merge pull request #423 from clarkorz/hasOne-findOrCreate
use findOrCreate in hasOne#create
2015-02-11 20:51:33 -08:00
Raymond Feng bcbb9c580d Merge branch 'featrue/support-connector-findOrCreate' of https://github.com/clarkorz/loopback-datasource-juggler into clarkorz-featrue/support-connector-findOrCreate 2015-02-11 20:49:51 -08:00
Raymond Feng a8f3d21b65 Merge pull request #436 from strongloop/feature/fix-issue-293
Make sure base properties/settings are merged into the submodel
2015-02-11 16:13:00 -08:00
Raymond Feng 9bac813f59 Merge pull request #435 from strongloop/feature/add-options-to-crud-methods
Add an optional `options` argument to all CRUD methods
2015-02-11 10:31:18 -08:00
Raymond Feng 760ac97902 Add an optional `options` argument to all CRUD methods 2015-02-10 23:57:05 -08:00
Raymond Feng ecf84bf802 Enhance the coercion for boolean/date types
See https://github.com/strongloop/loopback-connector-mongodb/issues/90
2015-02-08 10:54:42 -08:00
Raymond Feng cd2bd34619 Make sure base properties/settings are merged into the submodel
See https://github.com/strongloop/loopback-datasource-juggler/issues/293
2015-02-07 11:15:28 -08:00
Clark Wang 0bef56efc0 support optimized findOrCreate
Signed-off-by: Clark Wang <clark.wangs@gmail.com>

remove undefined for creating data in findOrCreate

Signed-off-by: Clark Wang <clark.wangs@gmail.com>

getLastGeneratedUid instead of force an id

Signed-off-by: Clark Wang <clark.wangs@gmail.com>
2015-02-07 10:23:04 +08:00
Raymond Feng e9c966227d Merge pull request #420 from aol-nnov/fkCustomDbType
Create model foreign key matching type of opposite part of relation (even if it has a custom field type)
2015-02-05 10:28:04 -08:00
Miroslav Bajtoš 2e2e01cc5c Merge pull request #430 from PradnyaBaviskar/issue709
Return 400 when client provides an incorrect value
2015-02-05 12:42:54 +01:00
Pradnya Baviskar be37fb4388 Return 400 when client provides an incorrect value 2015-02-05 16:58:42 +05:30
Miroslav Bajtoš 4889443ed0 Merge pull request #422 from strongloop/feature/fix-mongodb-issue-87
Remove undefined properties for create
2015-02-04 19:11:02 +01:00
Raymond Feng 79eabf3cf9 Fix typo 2015-02-04 08:30:13 -08:00
Clark Wang 09f7c92cbe use findOrCreate in hasOne#create
So hasOne#create could take advantage from optimized findOrCreate,
which can avoid multiple creation among concurrent requests.

Signed-off-by: Clark Wang <clark.wangs@gmail.com>
2015-02-04 14:54:28 +08:00
Raymond Feng 9769df2c91 Remove undefined properties for create
See https://github.com/strongloop/loopback-connector-mongodb/issues/87
2015-02-03 08:35:18 -08:00
Andrey Loukhnov e68ecb461a Create model foreign key matching type of opposite part of relation (even if it has a custom field type) 2015-02-03 13:13:00 +03:00
Miroslav Bajtoš 9298919ec0 Merge pull request #418 from strongloop/feature/rename-query-to-access-hook
Rename hook "query" to "access"
2015-02-02 19:04:47 +01:00
Raymond Feng 4793546353 Merge pull request #400 from chrene/protected
Add support for protected properties.
2015-02-02 09:04:51 -08:00
Raymond Feng bba1ce0768 Merge pull request #405 from clarkorz/fix/id-for-compositeIds
fix id property for composite ids
2015-02-02 08:59:40 -08:00
Raymond Feng fd97b06bcc Merge pull request #416 from strongloop/feature/fix-lb-1058
Fix id type issue for update
2015-02-02 08:58:10 -08:00
Raymond Feng 4afb2385a9 Fix id type issue for update
https://github.com/strongloop/loopback/issues/1058
2015-02-02 08:44:36 -08:00
Miroslav Bajtoš fcaf19a1d2 Rename hook "query" to "access"
The name "query" creates incorrect assumption that hook handlers
may return the result of a query to bypass database access.
That is far from true, since this hook is called also by methods
like `deleteAll` or `updateAll` that don't perform any SELECT query.
2015-02-02 10:41:18 +01:00
Miroslav Bajtoš 370966df99 Implement intent hook `before delete`
Methods `DAO.deleteAll` and `DAO.prototype.delete` now invoke
`before delete` hook too. The hook receives `ctx.where` describing
models to be deleted.
2015-02-02 09:13:31 +01:00
Miroslav Bajtoš 842e543bf7 Merge pull request #415 from strongloop/fix/regression-in-dao-save
Fix regression in `.save()` from 1fd6eff
2015-01-30 18:28:10 +01:00
Raymond Feng e41b2d9393 Merge pull request #414 from strongloop/feature/fix-hasone-remoting
Fix hasOne remoting
2015-01-30 08:23:46 -08:00
Miroslav Bajtoš 31b9da7d44 Remove redundant `.toObject()` call from `upsert` 2015-01-30 11:31:30 +01:00
Miroslav Bajtoš 5cfbfe3a19 Fix regression in `.save()` from 1fd6eff1
The commit 1fd6eff1 (intent-based hooks) introduced a subtle regression
in `.save()` method where dynamic property setters were invoked twice.

This commit fixes the problem by moving pre-save data normalization
into `before save` callback.
2015-01-30 11:31:12 +01:00
Raymond Feng e46bd0cdb5 Fix hasOne remoting 2015-01-29 23:26:11 -08:00
Raymond Feng 7d42202d40 Make sure batch create calls back with correct data
See https://github.com/strongloop/loopback/issues/1031
2015-01-29 11:52:39 -08:00
Miroslav Bajtoš 1fd6eff10f Intent-based hooks for persistence
This patch introduces a new API for "intent-based" hooks. These hooks
are not tied to a particular method (e.g. "find" or "update"). Instead,
they are triggered from all methods that execute a particular "intent".

The consumer API is very simple, there is a new method
Model.observe(name, observer), where the observer is function
observer(context, callback).

Observers are inherited by child models and it is possible to register
multiple observers for the same hook.

List of hooks:

 - query
 - before save
 - after save
 - after delete
2015-01-29 08:43:52 +01:00
Miroslav Bajtoš b3d07ebbe8 ModelBaseClass: implement async observe/notify
Implement infrastructure for intent-based hooks.
2015-01-29 08:43:50 +01:00