Commit Graph

1554 Commits

Author SHA1 Message Date
Rifa Achrinza 837240b7f9 fix: missing serialisation for `Connector.update`
closes https://github.com/loopbackio/loopback-datasource-juggler/issues/1971

Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
2022-08-22 08:08:58 +00:00
Mario Estrada e3448fad03 chore: replace shortid with nanoid
Signed-off-by: Mario Estrada <marioestradarosa@yahoo.com>
2021-09-12 18:14:03 +08:00
Raymond Feng 454fd0f1b2 Fix value equality test to avoid toString
- The where statement can be something like {toString: 'not a function'}
- Avoid object string comparison

Signed-off-by: Raymond Feng <enjoyjava@gmail.com>
2020-10-30 09:15:39 -07:00
Miroslav Bajtoš c884c62b3b
Add more `dataSource.execute()` flavors
Implement support for the following variants:

- `execute(collection, command, ...params, options)` (MongoDB)
- `execute(...params)` (forward-compatibility & other databases)

Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
2020-08-03 15:00:30 +02:00
Miroslav Bajtoš c83f82d5a0
feat: implement DataSource.stop()
Implement `stop` as an alias for `disconnect`. This way LB4 applications
don't have to include custom `stop` implementation in every datasource
file.

Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
2020-04-23 16:20:44 +02:00
Dimitris Xalatsis 095ddd654e
Add __parent reference to embedded models
Add a new hidden property `__parent` that's automatically set on all
instances of embedded models.

For backwards compatibility, this feature is not enabled by default.
You can turn it on by adding the following line to `server/server.js`
file:

    app.registry.modelBuilder.settings.parentRef = true;
2020-04-17 13:35:42 +02:00
Agnes Lin 9fe64d412c mark idColumnName as a deprecated function 2020-03-25 15:18:34 -04:00
Dimitris Halatsis 8919115439
Move List.prototype.toItem out of inner init (#1828) 2020-03-18 12:52:35 -04:00
Agnes Lin baeb76e911 allows diff db cols naming conventions 4 discover 2020-01-29 13:26:16 -05:00
Diana Lau 251ced811b
Update copyright year and CODEOWNERS (#1818)
* chore: update CODEOWNERS

* chore: update copyright years
2020-01-21 13:12:14 -05:00
Agnes Lin ad3e1e8d8a add warning strict cannot be false with SQL dbs
this is only for LB4
2020-01-21 09:02:47 -05:00
Hage Yaapa b6f9e92ef8 feat: add persistDefaultValues (#1813)
Ignores value if it matches default value.
2019-12-17 10:52:15 -05:00
Jeremy Nagel b328934b6c [BUGFIX] Fix issue with with array constructor
- You can do new Array(4) to generate an array with 4 empty items
- Doing the same with list caused an error
- This broke lodash.deepclone
- This PR restores compatibility with the array constructor

Fixes #1798
2019-12-06 10:13:27 +11:00
Miroslav Bajtoš 1b7858a857
chore: update eslint to 6.x
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
2019-12-03 10:09:16 +01:00
Miroslav Bajtoš 770f11b3a6
Merge pull request #1790 from mitsos1os/return-promise-on-error
Convert error thrown by a property setter to a rejected promise
2019-11-29 10:15:52 +01:00
Hage Yaapa 89a964e919 feat: applyDefaultOnWrites in nested properties
Adds support for `applyDefaultOnWrites` in nested properties.
2019-11-28 13:59:47 +05:30
Dimitris Xalatsis b30fbf8c1e return failed promise on error 2019-11-22 19:38:43 +02:00
Francisco Buceta b9f0284a28
Fix generated string id's
Co-authored-by: Miroslav Bajtoš <mbajtoss@gmail.com>
2019-11-15 16:15:38 +01:00
Dimitris Halatsis ab11205fa0 fix #1781 (#1782) 2019-10-21 12:55:14 -04:00
Hage Yaapa 464610ef0a feat: add applyDefaultOnWrites property
Adds the ability to ignore writing default values to the database.
2019-08-19 17:11:27 +05:30
Ayeni Olusegun 814c55c7cd Fix polymorphic hasMany inverse relation (#1621)
* Polymorphic hasMany inverse relation

* rename test suit to eslint error
2019-08-12 15:30:28 -04:00
Dominique Emond bca631518b fix: prevent max listeners warning
If establishing a database connection is slow
and database migration runs and there are many
models, sql operations are queued up and this
leads to the node.js max emitters exceeded
warning.

A default value for max emitters has now
been introduced, and it can also be configured
in datasources.json.

Co-authored-by: Dominique Emond <dremond@ca.ibm.com>
2019-08-09 09:03:51 -04:00
Miroslav Bajtoš f1fa976f50
Fix coercion of PK value in `replaceById` method
Before this change, when both the PK value (`id`) and the `data` object
were provided as plain-data values (e.g. as received in a JSON request),
and the connector was using a complex PK type (e.g. `ObjectID`
in MongoDB), then `replaceById` operation was printing confusing
warnings:

    WARNING: id property cannot be changed from 5d39775a59f5f541513c5e05
        to 5d39775a59f5f541513c5e05 for model:Post
        in 'before save' operation hook

    WARNING: id property cannot be changed from 5d39775a59f5f541513c5e05
        to 5d39775a59f5f541513c5e05 for model:Post
        in 'loaded' operation hook

This commit fixes the problem by applying the same type coercion on the
PK value (`id`) as has been applied by the model constructor on the PK
property (`data.id`).

Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
2019-07-26 09:02:52 +02:00
darthmaim dd7167b533 Fix autoupdate queueing automigrate instead (#1762)
Fixes #1761
2019-07-25 14:17:34 -04:00
Miroslav Bajtoš 78c5b12740
feat: add DataSource.deleteAllModels() API
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>
2019-07-18 17:56:41 +02:00
Miroslav Bajtoš 40286fcd28
fix: report errors from automigrate/autoupdate
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>
2019-07-04 12:36:50 +02:00
Biniam Admikew 1ed385e393 feat: add beginTransaction API on datasource
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>
2019-06-28 12:58:50 -04:00
spurreiter 5b44c08f7a feat: after operation hook in case of errors
fix: move error into context

review: add debug statement; rename fns

fix: call next instead of ctx.end
2019-05-31 17:12:42 +02:00
Bill Matson 04523260c2 Fix for #1724 - Added options to attribute updates (#1725)
* Fix for #1724 - Added options to attribute updates

* Fix for #1724 - Added unit tests for options
2019-05-27 09:49:46 -04:00
Miroslav Bajtoš aa20180c4f
Fix "access" hook for unoptimized "near" queries
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>
2019-05-14 09:17:54 +02:00
Miroslav Bajtoš 344441d48d
Fix "loaded" hook for unoptimized "near" queries
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.
2019-05-14 09:17:54 +02:00
Miroslav Bajtoš 5369cf3d54
Fix DateString ctor to accept DateString instances
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
2019-05-13 15:21:00 +02:00
Miroslav Bajtoš ef0257e338
datasource: copy settings object in constructor
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.
2019-05-10 14:56:02 +02:00
Agnes Lin de4718d5b8 chore: update copyrights years (#1737) 2019-05-08 11:45:37 -04:00
biniam 9c94b9344b fix: allow coercion of nested properties
Handle model definitions with nested property
definitions for coercion of primitive values.
2019-05-03 18:45:39 -04:00
Miroslav Bajtoš 5c3405eceb
Add support for Node.js 12.x
- Fix code to pass all tests on Node.js 12
- Add Node.js 12 to the list of Travis CI platforms
2019-04-29 09:46:57 +02:00
biniam 48af738ec4 fix: coerce primitive properties on update 2019-04-16 10:51:44 -04:00
biniam 1534392c62 fix: coerce date array properties 2019-04-16 10:50:54 -04:00
spurreiter 55b10a43c4 fix: normalize include with boolean or number
- On include = true or include = 1 the lib crashes with
  "TypeError: includes.forEach is not a function".
- checking for boolean and number type and return empty array.
- fix: include symbol and function in normalization
- fix: review changes; adding debug stmt + early exit for tests
2019-04-05 19:02:57 +02:00
Miroslav Bajtoš e45292de08
Do not apply default values on data from database
Before this change, when a property was configured with a default value
at LoopBack side and the database was returned a record with a missing
value for such property, then we would supply use the configured
default.

This behavior is problematic for reasons explained in #1692.

In this commit, we are fixing DAO operations like `find` and
`findOrCreate` so that they do NOT apply default property values on
data returned by the database (connector).

Please note that most of the other CRUD methods were already not
applying default values on database data as long as the connector
provided native implementation of the operation.
2019-04-04 09:47:31 +02:00
Hage Yaapa 80d8fcd8b1 feat: support array within array 2019-03-07 15:58:26 +05:30
Hage Yaapa a391c83a2c feat: Support "type" key in sub-properties 2019-02-21 13:58:34 +05:30
biniam 5e0c73bec7 fix: use correct callback for geo find queries 2019-02-14 15:45:13 -05:00
Miroslav Bajtoš fd99c6dc6e
Support nested properties with class type
When converting plain-data object values into model instances,
correctly handle the case where the constructor functions is a class
constructor and must be invoked via `new`.
2019-01-25 10:05:36 +01:00
Miroslav Bajtoš 9e0f624ad5
manually fix remaining problems 2018-12-07 16:46:15 +01:00
Miroslav Bajtoš 422ec9ad4f
autofix eslint errors 2018-12-07 16:46:15 +01:00
Miroslav Bajtoš 84322d07a9
Update eslint-config-loopback to latest 2018-12-07 16:22:59 +01:00
Miroslav Bajtoš e834368502
Upgrade bson to 4.x (latest) 2018-12-07 16:22:59 +01:00
Miroslav Bajtoš fda332d60b
feat: dataSource.execute(cmd, args, opts, cb)
Implement a new helper API for calling connector's "execute" method
in a promise-friendly way.
2018-12-07 14:51:14 +01:00
Raymond Feng f9131aa18f Use options from request for settings 2018-11-13 12:32:55 -08:00