Commit Graph

110 Commits

Author SHA1 Message Date
Agnes Lin de4718d5b8 chore: update copyrights years (#1737) 2019-05-08 11:45:37 -04: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
Raymond Feng dbe25f282d Check composite keys containing hidden props 2018-10-29 07:57:55 -07: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š d2ee73b9d3
Update eslint + config to latest 2018-06-12 09:13:32 +02:00
Raymond Feng 90163ba709 Allow toObject() to accept an 'options' argument 2018-05-10 10:18:55 -07: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
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
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
Thaer Abbas 57ead01624 #1261 Property name "constructor" is not allowed in 'Model' data (#1284)
* check if data has a constructor prop

* test data with no constructor

* test non function constructor

* test non function ctor message

* cleanup
2017-04-04 13:35:24 -04:00
Mikhail 68b93e1074 Disallow regexp string in arrays for coerce (#1279)
Disallow regexp arrays for coerce
2017-03-22 20:29:01 -04:00
Dimitris 6f8ecfdf5c Fixes #1230 coerceArray converts empty Objects (#1269) 2017-03-20 10:05:11 -04:00
Heath Morrison 2377792c22 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 14:46:41 +01:00
Siddhi Pai 3baa61590e Fix block padding
* Remove test/.eslintrc
* run eslint . --fix
2016-12-13 16:05:50 -08:00
Simon Ho c5e905f5c4 Fix linter errors for CI 2016-12-09 18:13:58 -08:00
Miroslav Bajtoš 0f7a567f18 Upgrade eslint & config to latest
- eslint ^3.11.1
 - eslint-config-loopback: ^6.0.0
 - fix linter errors (mostly no-undef)
2016-12-05 15:14:09 +01:00
Amir Jafarian a65311dc7c Use imperative mood for tests
* Use imperative mood for tests in test/loopback-dl.test.js
2016-10-27 16:38:40 -04:00
Heath Morrison 266e9f5a9a Continue _coerce after logical operators 2016-10-25 23:09:46 +03:00
David Cheung 805db78e19 Strict mode now always return validationError
- Deprecation of strict:validate and strict:throw
- When strict mode is enabled, it will now always
return validation error (previous strict:validate)
2016-09-19 10:27:24 -04:00
Amir Jafarian aec678d252 Fix manually 2016-08-22 19:20:12 -04:00
Amir Jafarian aa6d28268b Auto-update by eslint --fix 2016-08-22 15:12:25 -04:00
jannyHou 8935b978f3 forceId=true with auto-increment db 2016-08-08 16:26:26 -04:00
Dimitris Halatsis b7ba73f1b1 ModelBuilder: add new setting strictEmbeddedModels
The setting controls the strict mode used for embedded property types,
for example the type of "address" property in this model definition:

    modelBuilder.define('TestEmbedded', {
      name: 'string',
      address: {
        street: 'string',
      },
    });
2016-06-01 13:12:50 +02:00
Miroslav Bajtoš c7f34c3452 eslint config 2.0 + remove extra empty lines
Upgrade eslint-config-loopback to ^2.0.0.

Remove extra empty lines to make `npm run lint` pass again.
2016-04-19 16:11:43 +02:00
Miroslav Bajtoš 27c6279d6c fix remaining eslint issues 2016-04-05 15:25:34 +02:00
Miroslav Bajtoš 39e04a1756 eslint --fix 2016-04-05 15:25:34 +02:00
Ryan Graham c467b43c38 Insert copyright headers 2016-04-04 18:14:03 -07:00
Ryan Schumacher 94c3f9a432 Ability to define normalization of undefined query
Add datasource and model setting `normalizeUndefinedInQuery`
to determine how it will handle undefined values. Options:

- nullify : converts undefined to null
- throw : throw an error on undefined value
- ignore : strip the key where undefined value is found

The default operation is to strip the key.
2015-10-07 09:26:09 -07:00
Raymond Feng 6eb18cb2f6 Make sure base property definitions are cloned
Sub models sometimes need to customize the properties from the base model.
This change allows each sub model has its own copy of the base property
definition to avoid potential conflicts across multiple sub models of the
same base.
2015-07-10 10:03:51 -07:00
Raymond Feng eb6fa410fe Fix coercion from ObjectID to String 2015-07-01 14:58:14 -07:00
Raymond Feng c609b6d7ce Allow leading slash for `path` in model settings 2015-04-24 08:23:13 -07:00
Miroslav Bajtoš 99d4c6aa8d Add new strict mode "validate"
When a model is configured with `strict: 'validate'`,
any dynamic properties not included in the schema trigger
a validation error.
2015-04-14 08:16:10 +02:00
Raymond Feng 33d3239b44 Allow submodel to hide base properties 2015-03-03 10:27:22 -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
Miroslav Bajtoš 3593127ef3 Update to `should` to the latest version 4.6.3 2015-02-03 11:44:15 +01:00
Clark Wang 2e9e2dd192 fix id property for composite ids
Signed-off-by: Clark Wang <clark.wangs@gmail.com>
2015-01-22 10:39:47 +08:00
Fabien Franzen 610866bd7c Extract mergeQuery and setScopeValuesFromWhere
Related to #274 - in preparation of default scope
2014-10-09 18:13:40 +02:00
Raymond Feng fe74c8019c Tidy up model building from data sources
See https://github.com/strongloop/loopback/issues/560
2014-09-12 14:25:35 -07:00
Clark Wang 4b70f2498f Fix options for hasManyThrough doesn't apply
Signed-off-by: Clark Wang <clark.wangs@gmail.com>
2014-09-01 23:59:52 +08:00
Raymond Feng fde5b426e4 Make sure error events are emitted by data source 2014-08-27 09:14:17 -07:00
Raymond Feng fcd8ed984c Make sure falsy value is kept for properties not predefined 2014-08-21 13:47:09 -07:00
Fabien Franzen ad780604e1 Properly handle LDL for polymorphic relations 2014-08-16 11:03:16 +02:00
Fabien Franzen a67759dcbf Refactored embedsMany (relationName vs. propertyName) 2014-08-14 20:12:16 +02:00
Fabien Franzen a243d05880 Enable DL definition of embedsMany + referencesMany 2014-08-14 20:12:16 +02:00
Raymond Feng d07b716ae8 Merge pull request #200 from strongloop/feature/emit-events-during-attach
Emit dataAccessConfigured events during attach
2014-08-04 15:27:11 -07:00
Fabien Franzen 93aea7eb66 Changed options.path to option.http.path 2014-08-04 19:45:47 +02:00
Fabien Franzen 81a822524d Removed normalization (see strong-remoting) 2014-08-04 12:17:06 +02:00
Raymond Feng b9d9ab0fb3 Emit dataAccessConfigured events during attach
See discussions at https://github.com/strongloop/loopback/issues/410
2014-08-01 08:22:33 -07:00
Fabien Franzen 71bf0f8240 Customize/Normalize class-level remoting http path 2014-08-01 09:38:25 +02:00