Commit Graph

1054 Commits

Author SHA1 Message Date
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
Raymond Feng f6e1df87be Allow flags to be passed via options 2018-11-09 09:33:05 -08:00
Raymond Feng eb85b3e3a6 Allow configuration of maxDepthOfQuery
https://github.com/strongloop/loopback-datasource-juggler/issues/1651
2018-10-31 08:45:16 -07:00
Raymond Feng dbe25f282d Check composite keys containing hidden props 2018-10-29 07:57:55 -07:00
Raymond Feng 8fa7c94605 Improve hidden/protected property checks
- Fixes #1645
  - do not apply hidden property check for data
- Fixes #1648
  - allow prohibitHiddenPropertiesInQuery to be set in model/ds
2018-10-28 10:03:12 -07:00
Raymond Feng 2af2599a7d Allow hidden/protected props as an object
Fixes #1646
2018-10-27 07:51:34 -07:00
Raymond Feng a391762771 Ren handleUndefined to normalizeUndefinedInQuery 2018-10-26 09:09:50 -07:00
Raymond Feng 0ce3f4ead9 Report circular or deep query objects 2018-10-25 15:14:20 -07:00
Raymond Feng 39ff54d392 Hide offending properties from the error object 2018-10-25 15:14:20 -07:00
Raymond Feng a761e0d114 Tidy up extended operator check 2018-10-25 15:14:14 -07:00
Raymond Feng f2e718639a Prevent hidden/protected props from being searched
- report errors if where contains hidden properties
- report errors if incldue scope contains hidden or protected properties
2018-10-19 09:25:47 -07:00
Raymond Feng 60e16298f2 Report errors for missing id props for include
https://github.com/strongloop/loopback/issues/4028
2018-10-19 09:20:12 -07:00
Raymond Feng f7036b2837
Merge pull request #1629 from mgabeler-lee-6rs/fix/fast-id-unique-check
fix: accelerate unique id checking
2018-10-14 07:58:35 -07:00
Miroslav Bajtoš abaf29f74d
Merge pull request #1623 from mitsos1os/issue-1622
Fix patchAttributes for embedded document properties in MongoDB
2018-10-09 14:55:56 +02:00
Miroslav Bajtoš b6a43dd65a
Switch from Bluebird to native Promise
This is a breaking change. Juggler methods are no longer returning
instances of Bluebird Promise, but return a native Promise instead.

As a result, API consumers can no longer use sugar APIs provided by
Bluebird, e.g. `spread`, `delay`, etc.

Migration guide: rewrite your code from `.then()` style into `async`
functions using `await` statements.
2018-10-05 09:30:02 +02:00
Matthew Gabeler-Lee 1ddac5bddb
fix: add test coverage, correct typo that exposed 2018-10-03 18:56:57 -04:00
Dimitris eb921ed9d5 remove null in embedded doc properties updates
calling patchAttributes without all embedded properties inits to null
2018-09-24 10:04:09 +03:00
Raymond Feng 7c7bd56b2e Add IBM copyright and MIT license headers 2018-09-17 09:00:12 -07:00
Raymond Feng 7eec7e4e34 Allow List to take items as instances of a class 2018-09-17 08:22:21 -07:00
Tom Kirkpatrick 251798c711 fix: ignore extra properties when strict=filter (#1423)
Fix for #1422
2018-08-29 22:57:37 -04:00
Miroslav Bajtoš 7d50f6130b
Upgrade eslint-config-loopback + fix formatting
The new version of our config enabled function-paren-newline rule,
this commit fixes the codebase to use more consistent handling
of newlines when calling functions.
2018-07-16 08:46:25 +02:00
Miroslav Bajtoš 38d5b5b4fa
Configure Mocha to use dot reporter
With 1965 tests, printing names of all tests is no longer useful.

This commit switches to "dot" reporter which prints a single dot per
test.
2018-07-10 12:11:46 +02:00
shenghu bc16692d9b assertation of undefined could be null 2018-07-09 11:53:27 -04:00
virkt25 9bd7f8d02f
fix: regression on Operation Hooks
Fix the regression introduced by 9af79cf51a where updateAttributes
and replaceAttributes was incorrectly handling the response returned
by the database.

This commit restores the old behaviour where `context.data` is updated
only by a connector-provided function and reverts an incorrect change
of a test file made as part of the faulty fix.

Besides the fixes, this patch also renames `data` to `dbResponse` and
add comments explaining the structure of the response object for more
clarity.
2018-07-09 16:41:56 +02:00
Miroslav Bajtoš 9af79cf51a
Fix Operation Hooks to propagate data changes
Before this change, many Operation Hooks were not correctly propagating
changes made to `ctx.data` via reassigning ctx.data to a new object.

This change modifies existing tests to account for this different
scenario, adds few more tests for scenarios that were not covered by
tests before and finally fixes the problem discovered.
2018-06-28 12:22:16 +02:00
Miroslav Bajtoš d2ee73b9d3
Update eslint + config to latest 2018-06-12 09:13:32 +02:00
Raymond Feng 2b4b44292a Fix tests to ensure compatibility w/ should@10 2018-05-24 14:21:12 -07:00
Raymond Feng 5a66f9ad72 Fix datasource state management
Use case:
1. Configure a datasource with lazyConnect = true
2. Do NOT start the DB
3. Start the app
4. Send first request and it fails to connnect to the DB
5. Start the DB
5. Requests are now served correctly
2018-05-22 10:46:45 -07:00
Raymond Feng 90163ba709 Allow toObject() to accept an 'options' argument 2018-05-10 10:18:55 -07:00
Miroslav Bajtoš 5af4c42728
feat: remove a Model from all registries
Add API allowing consumers (e.g. LoopBack) to remove a Model from all
juggler registries:
 - ModelBuilder's models
 - ModelBuilder's definitions
 - Connector registry of models
2018-04-16 14:24:53 +02:00
Janny 01427b1755 feat: omit default fn for embedsMany (#1532)
* feat: omit default fn for embeds many

* fix: apply feedback
2018-04-13 13:17:40 -04:00
bmatson c3e502032e
Pass options argument to custom validators 2018-03-22 15:51:21 +01:00
Raymond Feng 87e1e217c3 fix: allow `new DataSource(connector, settings)` 2018-02-13 09:42:41 -08:00
Raymond Feng 4be2ea8afb fix: add more tests to verify new DataSource() 2018-02-09 14:33:42 -08:00
Kevin Scroggins 25b1aa5abc Fix datasource not correctly retaining name value 2018-01-31 11:30:24 -05:00
Kevin Scroggins 07f0310d34 Added error handling for persist operation hook (#1531)
Unrelated CI failures. -.-
2018-01-24 11:37:30 -05:00
Taranveer Virk cc60ef8202 fix unauthorized fk change (#1538)
Downstream failures are unrelated.
2018-01-17 13:34:37 -05:00
Miroslav Bajtoš b0b377af0c
Set model constructor name to model name
Rework the code building model constructors to leverage `Function` class
and dynamically emit a constructor function named after the model.

Before this change, all model classes were called "ModelConstructor",
which made debugging difficult.

After this change, a model class for model "User" is called "User.

Because not all valid model names are also valid JavaScript identifiers,
we implement a simple sanitization technique (replacing characters like
"-", "." and ":" with underscore "_") and fall back to legacy
"ModelConstructor" if the model name is still not a valid JS identifier.
2018-01-08 09:37:23 +01:00
Peter Bouda 6bd9fca080 Fix bug in utils uniq function (#1526)
The uniq function does currently not work when the database is mongodb.
In the case of mongodb, the function will receive an array of bson
object of bson type ObjectID. The indexOf function will return a
different index, even if the mongodb ID is the same, as it is wrapped
in the ObjectID. This commit first transforms any ObjectID in the array
to a string representation. We can then use indexOf to check for
uniqueness.
2017-12-04 15:39:58 -05:00
Joost de Bruijn 7a4c6ca2f9 Fix query for related models (#1522) 2017-11-14 14:22:48 -05:00
zbarbuto 1d8603c491 Allow customizing embedded relation property (#1513) 2017-10-31 10:55:54 -04:00
Janny e85e0f600b Fix basic-querying (#1509)
* Fix basic-querying

* Fix duplicate MyModel
2017-10-16 16:07:01 -04:00
Zak Barbuto 99cea38fd0 Allow passing null to base model ctor 2017-09-28 09:42:30 +09:30
Jürg Lehni 0ce1fa9f87 Add a better way to handle transactions 2017-09-06 07:10:57 +02:00
Joost de Bruijn f18d3487c6 validations: use new regex per evaluation (#1479)
The RegExp is cloned before executing the test. Fixing issue #1475.
2017-09-01 12:48:29 -04:00
loay e983f0c9e1 Add test coverage for hasAndBelongsToMany 2017-08-24 11:01:54 -04:00
Rashmi Hunt 6c6df15286 Flag id as updateOnly when forceId is in effect (#1453)
* updateOnly, forceId changes

* support getUpdateOnlyProperties

* fixup! fix updateOrCreate in forceId mode

The contract of `updateOrCreate` is expecting a full object instance
to be passed to the callback.

The current implementation was creating an empty instance and
calling updateAttributes under the hood. As a result, the callback
was called with the attributes being updated only.

In order to preserve existing behaviour, we have to always build
a full initial instance by calling `findById`.

See the following discussion for more context:
https://github.com/strongloop/loopback-datasource-juggler/issues/966

* fixup! fix tests of upsert validation

* move forceId to model-builder

* remove TODO comment

* revert refactoring and test fixes

* Remove duplicate test

* change testcase names

* change to ModeClass.settingse

* forceId setup from datasource to model-builder

* fix inheritance of auto-generated forceId

* Fixed failing tests for auto change

* fixed a comment
2017-08-22 13:09:45 -07:00
loay 01b4c4a3a7 Catch err using Callback 2017-08-16 17:00:41 -04:00
Loay 80f3e93367 Merge pull request #1416 from strongloop/feature/fix-2364
Fix undefined properties in where
2017-08-09 13:54:28 -04:00
Tom Kirkpatrick 1ebad655e4 test: call true/false in isValid checks 2017-08-03 14:47:11 -04:00
Tom Kirkpatrick 138b99c703 fix: support numbers in validatesFormatOf
Fix for #1437
2017-08-03 14:47:11 -04:00
Raymond Feng 03753b6fe2 Fix undefined properties in where
https://github.com/strongloop/loopback/issues/2364
2017-08-03 14:09:21 -04:00
ssh24 80f015c2d2 Honor backwards compatability with validate update 2017-08-03 11:50:44 -04:00
ssh24 9cd0108fc6 Fix update validation callback 2017-08-02 14:55:47 -04:00
ssh24 b1a0cb8c3b Validate updateAll 2017-08-02 13:24:21 -04:00
ssh24 aec1179a30 Sort arrays before testing
Sorting the array so the ordering is the same
2017-08-02 10:45:36 -04:00
dmellonch 1b7c346bca Missing the option argument (#1426)
* Fix missing option arguments in scope.js

Added option arguments in find.relatedmodel
Added case test

* Add order filter in verify function

Fix for cloudant test
2017-08-01 14:15:21 -04:00
biniam 59b3ac22a8 use connector flag throughout tests 2017-07-26 16:18:30 -04:00
loay b1b2d5df0c Catch errors using cb 2017-07-24 14:08:58 -04:00
Diana Lau ff9b25a905 Merge pull request #1432 from simoami/master
#1386 Allow empty values when allowBlank is true
2017-07-20 11:23:54 -04:00
Jürg Lehni 4c9e91423f
Rename getAsync() methods to find() and get()
Keep getAsync() around for backward compatibility, but deprecate it
2017-07-20 14:48:29 +02:00
Simo Moujami 82a8e3d9a1 #1386 Allow empty values when allowBlank is true 2017-07-19 19:26:13 -04:00
Janny 6a1b55568c Skip imcompatible tests (#1420)
* Skip imcompatible tests
2017-07-18 15:20:21 -04:00
Janny b9129e6973 Run juggler tests for Cloudant (#1414) 2017-07-11 14:56:39 -04:00
Tetsuo Seto 4a6f0a4aa0 Fix the case where qWhere[idKey] is null 2017-06-09 09:33:22 -07:00
Kevin Delisle 828a71e576 test/helpers: annotate skipped tests
Differentiate between tests skipped by feature flags, and those
manually marked as skipped.

Tests that use the bdd.describe and bdd.it helper functions
will be marked as [UNSUPPORTED] if they are conditionally disabled.
2017-06-07 14:05:48 -04:00
ssh24 e791e9006c Apply iteration on the model object 2017-05-26 18:49:54 -04:00
ssh24 825fa3171c Fix count of properties 2017-05-23 22:17:50 -04:00
Raymond Feng 5a0b0270f3 Return promise for batch create 2017-05-19 16:16:52 -07:00
Raymond Feng c41487a1d1 Merge pull request #1371 from strongloop/exclude_prop
Handle excludeBaseProperties
2017-05-15 11:06:27 -05:00
Tetsuo Seto ef08458e8d Remove unnecessary tests for adhocSort !== false 2017-05-15 03:04:09 -07:00
Tetsuo Seto aa3f5fa4f4 Fix the test case to avoid duplicate userId 2017-05-14 19:17:32 -07:00
Tetsuo Seto c07f46000d Support include rework for C* connector
- Remove supportNonPrimaryKeyIN
- Add C* Uuid in build call
- Implement smartMerge in scope.js
2017-05-12 22:43:21 -07:00
ebarault cfd3cdf535 Overall review of polymorphic relations
In #1298, the spec/doc for polymorphic relations was reviewed

**hasX relation**
- `type`: **hasMany**
- `as`: redefines **this** relation's name (optional)
- `model`: **modelTo**
- `polymorphic`:
  - typeOf `polymorphic` === `String`
    - matching **belongsTo** relation name
      - `foreignKey` is generated as `polymorphic + 'Id'`,
      - `discriminator` is generated as `polymorphic + 'Type'`
  - typeOf `polymorphic` === `Object`
    - `as`: **DEPRECATED** should display a warning,
            replaced by `selector`
    - `selector`: should match **belongsTo** relation name if the
                  latter is defined with {polymorphic: true}
      - (required) if both foreignKey and discriminator
        are **NOT** provided
      - (extraneous) if both foreignKey and discriminator
        are provided
    - `foreignKey`:  A property of modelTo, representing the fk to
       modelFrom's id.
      - generated by default as `selector + 'Id'`
    - `discriminator`: A property of modelTo, representing the actual
                       modelFrom to be looked up and defined
                       dynamically
      - generated by default as `selector + 'Type'`

---

**belongsTo relation**
- `type`: **belongsTo**
- `as`: redefines **this** relation's name (optional)
- `model`: **NOT EXPECTED**: should throw an error at
               relation validation
- `polymorphic`:
  - typeOf `polymorphic` === `Boolean`
      - `foreignKey` is generated as `relationName + 'Id'`,
      - `discriminator` is generated as `relationName + 'Type'`
  - typeOf `polymorphic` === `Object`
    - `as`: **DEPRECATED**: should display a warning,
            replaced by `selector`
    - `selector`:
      - (required) if both foreignKey and discriminator
        are **NOT** provided
      - (extraneous) if both foreignKey and discriminator
        are provided
    - `foreignKey`: A property of modelTo, representing the fk to
                    modelFrom's id.
      - generated by default as `selector + 'Id'`
    - `discriminator`: A property of modelTo, representing the actual
                       modelFrom to be looked up and defined
                       dynamically
      - generated by default as `selector + 'Type'`
2017-05-12 21:33:39 +02:00
rashmihunt 45bf569ec4 fix assert, make the test case more clear 2017-05-12 11:47:50 -07:00
rashmihunt fed0396d9e code review, better asserts 2017-05-11 09:59:39 -07:00
rashmihunt 5aee1fe17e test case to exclude base props 2017-05-10 12:03:42 -07:00
ebarault 79068d142b configurable model merge
The PR superseeds the existing deepMerge algorithm used to merge
settings of parent and child models with a new algorithm that allows
to specify the way each setting is merged or mixed-in.

This configuration of this algorithm uses a merge policy specification.
The `getMergePolicy()` helper of BaseModelClass can be used to ease
model merge configuration.

Next is presented the expected merge behaviour for each option.
NOTE: This applies to top-level settings properties

- Any
  - `{replace: true}` (default): child replaces the value from parent
  - assignin `null` on child setting deletes the inherited setting

- Arrays
  - `{replace: false}`: unique elements of parent and child cumulate
  - `{rank: true}` adds the model inheritance rank to array
    elements of type Object {} as internal property `__rank`

- Object {}:
  - `{replace: false}`: deep merges parent and child objects
  - `{patch: true}`: child replaces inner properties from parent

The recommended merge policy is returned by getMergePolicy()
when calling the method with option `{configureModelMerge: true}`.

The legacy built-in merge policy is returned by `getMergePolicy()`
when avoiding option `configureModelMerge`.
NOTE: it also delivers ACLs ranking in addition to the legacy
behaviour as well as fixes for settings `description` and `relations`

`getMergePolicy()` can be customized using model's setting
`configureModelMerge` as follows:
```
{
  // ..
  options: {
    configureModelMerge: {
      // merge options
    }
  }
  // ..
}
```

`getMergePolicy()` method can also be extended programmatically as
follows:
```
myModel.getMergePolicy = function(options) {
  const origin = myModel.base.getMergePolicy(options);
  return Object.assign({}, origin, {
    // new/overriding options
  });
};
```
2017-05-10 02:33:45 +02:00
Loay e3ce44a286 Merge pull request #818 from fullcube/fullcube/validatesUniquenessOf-case-insensitive
Fullcube/validates uniqueness of case insensitive
2017-05-05 10:41:42 -04:00
Loay 87dd44dd59 Fix assertion errors 2017-05-04 10:38:06 -04:00
Kevin Delisle 156b638518 Merge pull request #1356 from strongloop/datetype-allow-strings
Add DateString type
2017-05-02 14:48:50 -04:00
Janny 5d10c72664 create sequence for nosql id (#1354)
* create sequence for nosql id
2017-05-02 13:35:57 -04:00
Bram Borggreve c3629633de
Add caseInsensitive opt to validatesUniquenessOf 2017-05-01 17:26:16 -05:00
Loay 6cfdcc0128 Fix order of query results 2017-05-01 16:10:55 -04:00
Kevin Delisle 5e80837424 Add DateString type
New type that preserves string input as a string, but ensures that
the string is a valid Date.

Additionally, provides a .toDate function to provide the Date
object representation of the string.
2017-05-01 12:28:59 -04:00
Kevin Delisle 8e97385a8f datatype.test: use predefined date
Some databases are storing the value in UTC (not ISO) format,
and truncating the values. Even though this is technically
unavoidable, it does fail strict string equality.
2017-04-28 15:40:19 -04:00
Andrew McDonnell 238175b4bd Added unit tests specific to DateType where null (#1349)
* Added unit test for DateType where null

* BDD for connectors w/o null support
2017-04-25 13:05:55 -04:00
paulussup e9ff88f453 Fix/geo null (#1334)
* fix check for null

* add tests

* fix for early return

* Allow check for null and non-existent value

Some connectors uses a non existent prop instead of allowing null
Modified test case to look if null exists or the prop is non existent

* Check for null value with geo near query

* Apply requested changes

* change test to two users and simplify

* check error first

* Fix simple query test case with null value

* BDD for connectors w//o null support
2017-04-24 19:28:11 -04:00
Diana Lau a488a71dbd replace exception thrown for invalid dates 2017-04-21 15:57:11 -04:00
Loay 3c19beacbb Add test case using updateAttributes 2017-04-18 13:50:57 -04:00
Loay f1d10b47ce Fix forceId bug for updateOrCreate 2017-04-18 13:14:35 -04:00
loay 1cdb431ae2 Fix relations test case 2017-04-14 03:35:46 -04:00
Eric Barault 64f64caaff handle deep geo-near queries (#1314)
* handle deep geo-near queries (#1216)

    
a dedicated mongKey is added in geo.nearFilter for mongoDB
fixes geo min distance tests as filter now expects an array

* Fix for string geoPoints

* Add geo point handle for ibmdb connectors

* Handle geo-point type for cassandra connector
2017-04-13 17:05:05 -04:00
Loay 9dc5430652 Unskip test case 2017-04-12 12:54:30 -04:00
Tetsuo Seto c1598584d8 Make tests work for other connectors as well as C*
Adjust getSchema calls
Compare ids as strings
Run tests when explicitly set to true
2017-04-12 09:11:42 -07:00
Tetsuo Seto 696e4cfa80 Remove debugger statement 2017-04-07 15:05:15 -07:00
Tetsuo Seto 0f9100f185 Fixup test support for Cassandra connector 2017-04-07 14:11:33 -07:00
Tetsuo Seto ead1fb2965 Add test support for Cassandra connector 2017-04-07 11:10:47 -07:00
Kevin Delisle 00fe8fd59e Merge pull request #1313 from strongloop/revert-1216-fix/geo.nearFilter-deep
Revert ""Near" fix for where clauses"
2017-04-06 18:29:48 -04:00