Commit Graph

1356 Commits

Author SHA1 Message Date
Samuel Reed 351f001652 fix(security): avoid prototype pollution on model create and update (#1805) 2019-12-16 11:01:18 -05:00
Janny bc82f2e7a8
fix: model coerce (#1806) 2019-12-13 01:33:58 -05:00
spurreiter aff2318c41
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-15 11:53:41 +02:00
Miroslav Bajtoš a647bb0736
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 introducing a new model-level setting called
`applyDefaultsOnReads`, which is enabled by default for backwards
compatibility.

When this setting is set to `false`, operations like `find` and
`findOrCreate` will NOT apply default property values on data returned
by the database (connector).

Please note that most of the other CRUD methods did not apply default
values on database data as long as the connector provided native
implementation of the operation, that aspect is not changing.

Also note that default values are applied only on properties with
`undefined` values. The value `null` does not trigger application of
default values. This is important because SQL connectors return
`null` for properties with no value set.
2019-04-09 15:46:09 +02:00
Hage Yaapa 8c99e841ff feat: Support "type" key in sub-properties 2019-03-05 23:49:25 +05:30
jannyHou 9a5bd51db5
feat: omit default fn for embeds many 2018-07-30 12:54:51 +02:00
Taranveer Virk 2167e802a9
fix unauthorized fk change (#1540) 2018-01-19 12:48:56 -05:00
Samuel Reed 40e278ab96 fix(model-builder): __data may be null. (#1415)
This error was swallowed by strong-remoting try/catch
in eachRemoteFunctionInObject()
2017-09-26 16:37:51 -04:00
Shing 88771f10fc Fix #1434 2.55.1 Throws when using where query against "JSON Object or ANY" Type (#1444)
* Test for JSON object or any type

* dao.js coercion type.definition existence check
2017-07-28 16:30:49 -04:00
Kevin Delisle f3b849bb47 castPropertyValue: throw on malformed types 2017-07-28 12:50:51 -04:00
loay 63f04a28d4 Catch errors using cb 2017-07-21 10:13:16 -04:00
nVitius 3df1826730 Recursively cast props on fromDb for memory conn.
In the fromDb step, nested properties weren't being hydrated properly.
This caused an issue with the ability to search on such properties as
Dates. The properties would be hydrated as a String type, and as such,
it was impossible to properly query on them.
2017-07-12 12:51:19 -07:00
nVitius 8ebccb65d1 Recursively coerce nested properties in dao 2017-07-11 12:55:01 -07:00
Janny 6d017c1e34 Fix #1079 - Polymorphic hasMany inverse relation (#1296)
This fixes the polymorphic hasMany inverse relation
not working as expected in include filters.
2017-07-11 15:47:32 -04:00
Janny 2190f2510f Backport - Apply hasManyThrough filter on target model (#1404)
* Apply hasManyThrough filter on target model

* Compatible with mongodb
2017-06-22 16:51:10 -04:00
somename85 cbb3f6f98a Fixed empty objList in linkOneToMany fn (#1287) 2017-04-05 10:27:34 -04:00
Ryan Graham e9baea77e0
fix missing findOrCreate error callback
Closes #1226
Resolves #1223

Signed-off-by: Ryan Graham <r.m.graham@gmail.com>
2017-03-16 18:32:47 -07:00
Miroslav Bajtoš af1d959613 Fix datasource to report connector-loading errors
Before this change, when resolving full connector path, all errors were
ignored. As a result, when the connector was installed but not
correctly built (e.g. loopback-connector-db2 which uses a native addon),
a very confusing message was reported by LoopBack.

In this commit, I am fixing the code handling `require()` errors
to ignore only MODULE_NOT_FOUND errors that contain the name
of the required module.
2017-02-06 10:58:44 +01:00
Raymond Feng 9bfab2b5a2 Replace deprecated node-uuid with uuid module 2017-01-17 09:07:21 -08:00
Heath Morrison c62ba21307 Coerce array-like objects into arrays
The query-string parser used by express
https://github.com/ljharb/qs#parsing-arrays
limits the size of arrays that are created from query strings to 20
items. Arrays larger than that are converted to objects using numeric
indices.

This commit fixes the coercion algorithm used by queries to
treat number-indexed objects as arrays. We still maintain a strict
understanding of an "array-like object" to limit the opportunity for
subtle bugs. In particular, the presence of non-index keys is an
indication that the object was not intended to be interpreted as
an array.
2017-01-10 15:11:20 +01:00
Brian Schemp d87e3bf8fb Throw error when model relation name is trigger
Defining a model relation with the name "trigger" causes the model not
able to insert records. No error is thrown when a model relation with
the name "trigger" is defined. Adding a check for the model relation
name "trigger" will now throw an error.
2017-01-03 10:41:07 +01:00
Miroslav Bajtoš 839a2c6c66 Fix HasOne.update to propagate options arg 2016-12-21 10:34:05 +01:00
Miroslav Bajtoš f8da9783bc Back-port fixes for linter errors from master 2016-12-06 10:47:27 +01:00
Heath Morrison 552dfc8f24 Continue _coerce after logical operators 2016-10-26 10:14:43 -04:00
Amir Jafarian e038b28e8c Fix manually 2016-10-19 17:35:26 -04:00
Amir Jafarian a1683fca59 Auto-update by eslint --fix 2016-10-19 17:04:05 -04:00
Rand McKinney 09fbfe9410 Update validations.js
Add doc of allowNull options property per #372.
Back-port 9a1ef08
2016-10-14 11:18:17 -04:00
Amirali Jafarian 8caf4c8327 Merge pull request #1108 from strongloop/fix_geo_2.x
Fix the bug when near filter is used
2016-10-13 10:39:15 -04:00
Simon Ho c3eca4025c Support {defaultFn: 'shortid'} (#1110)
- Backport of strongloop/loopback-datasource-juggler#1107 (takeover of
strongloop/loopback-datasource-juggler#1101)
- Squashed relevant commits
2016-10-12 20:58:07 -07:00
Simon Ho a9d381605e Add ilike and nilike operators (#1136)
Closes #633

Backport of #1091
2016-10-12 19:19:31 -07:00
Amir Jafarian fde4c0bfd6 Fix bug when near filter is used 2016-10-11 17:08:42 -04:00
Amir Jafarian 8208e8ab63 Fix JSdoc 2016-10-11 12:21:36 -04:00
Amir Jafarian e103b50b63 Add 'isNewInstance' for updateAttributes
* Add 'isNewInstance' to loaded hook for updateAttes
2016-09-23 14:09:44 -04:00
Simon Ho 8edca500c1 Add docs for KVAO
Backport of #1093
2016-09-19 13:45:16 -07:00
pponugo 64a9b8d506 Support nested queries for arrays
Enhance the built-in memory connector to correctly support nested
queries for arrays in addition to objects.

E.g. if "friends" is an array of objects containing "name", then
{ where: { "friends.name": "Jane" } } should match records containing
a friend called "Jane".
2016-09-07 13:20:56 +02:00
Simon Ho 95bc2e93cc Remove expired item before executing expire
The expire feature is falsely returning 204 instead of 404 because it is
not removing expired items before execution.
2016-09-06 16:04:33 -07:00
Sonali Samantaray 44e1d29879 upsertWithWhere feature support in juggler DAO
Backport from #1001
2016-09-06 13:41:50 -04:00
Amir Jafarian a1a9bac9ba Implement `notify` for find method 2016-08-23 19:00:50 -04:00
Simon Ho de84a8bc7d Merge pull request #1057 from strongloop/backport/globalize-kv-mem-connector
Globalize KeyValue Memory connector
2016-08-19 12:59:31 -07:00
Miroslav Bajtoš ab47ecfbab kvao: implement key filter 2016-08-18 10:30:55 +02:00
Miroslav Bajtoš 24a9a96a26 kvao: add iterateKeys() and keys()
Add a core implementation of KVAO.iterateKeys() which returns an
AsyncIterator, inspired by
 - https://github.com/tc39/proposal-async-iteration
 - https://www.npmjs.com/package/async-iterators

This way we can safely iterate even large sets of data.

Also add KVAO.keys(), a sugar API converting the result of iterateKeys()
into a single array.
2016-08-18 10:30:53 +02:00
Simon Ho 873cb4eab6 Globalize KeyValue Memory connector
[back-port of #1056]
2016-08-17 18:54:30 -07:00
Miroslav Bajtoš f7cfe25b60 Fix error message for missing global.Promise 2016-08-16 14:38:01 +02:00
Simon Ho 421597c998 Add TTL for KeyValue related features
Backport of strongloop/loopback-datasource-juggler#1030
2016-08-12 14:49:01 -07:00
Miroslav Bajtoš 1750583a15 kv-memory: fix crash in regular cleanup
Fix bug in "_setupRegularCleanup()" where the interval callback
was trying to access an object that has been garbage-collected
in the meantime.
2016-08-10 14:19:05 +02:00
Amir Jafarian 9da0e501da Backport globalization
Backport loopback-datasource-juggler#1022,
loopback-datasource-juggler#1024,
loopback-datasource-juggler#1026
2016-08-09 21:52:11 -04:00
Amir Jafarian 1b266bcf00 Return error if connector does not implement
* Return error if connector does not implement replaceById
* This patch is without globalization

Backport loopback-datasource-juggler#1034
2016-08-09 14:44:06 -04:00
Miroslav Bajtoš 8013b6acd4 kvao: return 404 when expiring unknown key 2016-08-09 10:47:12 +02:00
Amir Jafarian 9557558c8f Update doc for `validatesFormatOf` 2016-08-08 10:46:47 -04:00
Miroslav Bajtoš 837f58f82d Implement KeyValue API and memory connector
Models attached to a KeyValue connector get the following *static*
methods:

    Color.set(key, value);
    Color.set(key, value, ttl);
    Color.set(key, value, { ttl: ttl });

    Color.get(key);

    Color.expire(key, ttl);
2016-08-08 14:48:04 +02:00