When writing tests, for performance reasons we often want to reuse
the same data-source instance for many tests suites. At the same time,
we want to keep such test suites independent and allow them to reuse
the same model name for different model classes.
Juggler does support redefinition of a model with the same name.
This change is adding a new API called that allows tests to remove all
old models before creating new ones. This API would be typically
called from a `before` hook.
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
Defer automigrate/autoupdate until we are connected, so that connection
errors can be reported back to callers.
Fix postInit handler to not report connection error to console.log
and via dataSource "error" event in case there is already an operation
queued. When this happens, we want the error to be handled by the
queued operation and reported to its caller.
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
add `beginTransaction` method to DataSource class
which calls `begin` method from the Transaction class
which in turn invokes the connector's `beginTransaction`
method if it supports transactions.
add beginTransaction method which calls begin
method from the Transaction class which in turn
calls the connector's beginTransaction method if
it supports transactions.
Co-Authored-By: Miroslav Bajtoš <mbajtoss@gmail.com>
* Fix types to describe native Promise (Miroslav Bajtoš)
* feat: after operation hook in case of errors (spurreiter)
* Fix for #1724 - Added options to attribute updates (#1725) (Bill Matson)
Before this change, when an "access" hook modified the "query" object,
the "near" condition from the original "query" object were still
applied. As a result, the query can end up being more restrictive and
return only a subset of models that should have matched the conditions.
With this change in place, after "access" hook observers are invoked,
we update the "near" condition using the "query" object provided by
hook observers.
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
Before this change, two "loaded" events were emitted for every model
instance found. This commit fixes the problem and restores the intended
behavior.
The bug was probably introduced by 5e0c73bec7.
Rework setup of the Operation Hooks test suite for memory connector
so that the "unoptimized" variant disables not only atomic CRUD
operations, but also geo queries.
This way we can test both "near" querying implementations:
- When the connectors supports "near" queries natively.
- When "near" queries are executed at LoopBack side in-memory.
Fix DataSource constructor to create a shallow copy of the settings
object provided by the caller. This prevents surprising behavior
where changes made to `ds.settings` were picked up by the provided
config object, as observed e.g. in tests of our MongoDB connector.
* Add support for Node.js 12.x (Miroslav Bajtoš)
* fix: coerce primitive properties on update (biniam)
* fix: coerce date array properties (biniam)
* fix: normalize include with boolean or number (spurreiter)