objection 3.0.0-rc.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -56,7 +56,13 @@ function cloneWithOpt(model, shallow, stripInternal) {
56
56
  const key = keys[i];
57
57
  const value = model[key];
58
58
 
59
- if ((shallow && relationNames.includes(key)) || (stripInternal && isInternalProp(key))) {
59
+ if (shallow && relationNames.includes(key)) {
60
+ // The constructor may have given default values for relations.
61
+ delete clone[key];
62
+ continue;
63
+ }
64
+
65
+ if (stripInternal && isInternalProp(key)) {
60
66
  continue;
61
67
  }
62
68
 
@@ -3,6 +3,7 @@
3
3
  const { isString, isFunction, isRegExp, last } = require('../utils/objectUtils');
4
4
  const { QueryBuilderContextBase } = require('./QueryBuilderContextBase');
5
5
  const { QueryBuilderUserContext } = require('./QueryBuilderUserContext');
6
+ const { deprecate } = require('../utils/deprecate');
6
7
 
7
8
  const AllSelector = () => true;
8
9
  const SelectSelector =
@@ -494,6 +495,7 @@ class QueryBuilderOperationSupport {
494
495
  }
495
496
 
496
497
  skipUndefined() {
498
+ deprecate('skipUndefined() is deprecated and will be removed in objection 4.0');
497
499
  this.internalOptions().skipUndefined = true;
498
500
  return this;
499
501
  }
@@ -291,7 +291,7 @@ function modelToNode(model, node) {
291
291
  for (let r = 0, lr = relationNames.length; r < lr; ++r) {
292
292
  const relName = relationNames[r];
293
293
 
294
- if (model.hasOwnProperty(relName)) {
294
+ if (model[relName] !== undefined) {
295
295
  let childNode = node[relName];
296
296
 
297
297
  if (!childNode) {
@@ -18,7 +18,7 @@ class GraphRecursiveUpsert extends GraphOperation {
18
18
 
19
19
  function hasRelations(obj) {
20
20
  for (const relationName of obj.constructor.getRelationNames()) {
21
- if (obj.hasOwnProperty(relationName)) {
21
+ if (obj[relationName] !== undefined) {
22
22
  return true;
23
23
  }
24
24
  }
@@ -8,10 +8,13 @@ class MergeOperation extends QueryBuilderOperation {
8
8
  constructor(name, opt) {
9
9
  super(name, opt);
10
10
  this.model = null;
11
+ this.args = null;
11
12
  }
12
13
 
13
14
  onAdd(builder, args) {
14
- if (!isEmpty(args) && isObject(args[0])) {
15
+ this.args = args;
16
+
17
+ if (!isEmpty(args) && isObject(args[0]) && !Array.isArray(args[0])) {
15
18
  const json = args[0];
16
19
  const modelClass = builder.modelClass();
17
20
 
@@ -33,7 +36,7 @@ class MergeOperation extends QueryBuilderOperation {
33
36
  return knexBuilder.merge(convertedJson);
34
37
  }
35
38
 
36
- return knexBuilder.merge();
39
+ return knexBuilder.merge(...this.args);
37
40
  }
38
41
 
39
42
  toFindOperation() {
@@ -43,6 +46,7 @@ class MergeOperation extends QueryBuilderOperation {
43
46
  clone() {
44
47
  const clone = super.clone();
45
48
  clone.model = this.model;
49
+ clone.args = this.args;
46
50
  return clone;
47
51
  }
48
52
  }
@@ -71,12 +71,10 @@ class RelationOwner {
71
71
  if (values) {
72
72
  builder.whereInComposite(relatedRefs, values);
73
73
  } else {
74
- builder.where(false);
75
- builder.resolve([]);
74
+ builder.where(false).resolve([]);
76
75
  }
77
76
  } else {
78
- builder.where(false);
79
- builder.resolve([]);
77
+ builder.where(false).resolve([]);
80
78
  }
81
79
 
82
80
  return builder;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "objection",
3
- "version": "3.0.0-rc.1",
3
+ "version": "3.0.0",
4
4
  "description": "An SQL-friendly ORM for Node.js",
5
5
  "main": "lib/objection.js",
6
6
  "license": "MIT",
7
7
  "scripts": {
8
- "test": "npm run eslint && mocha --slow 10 --timeout 15000 --reporter spec --recursive tests --exclude \"tests/unit/relations/files/**\"",
9
- "test-fast": "mocha --slow 10 --timeout 15000 --reporter spec --recursive tests --bail --exclude \"tests/unit/relations/files/**\"",
10
- "test-typings": "tsc",
8
+ "test": "npm run eslint && mocha --slow 10 --timeout 15000 --reporter spec --recursive tests --exclude \"tests/unit/relations/files/**\" && npm run test:typings",
9
+ "test:fast": "mocha --slow 10 --timeout 15000 --reporter spec --recursive tests --bail --exclude \"tests/unit/relations/files/**\"",
10
+ "test:typings": "tsc",
11
11
  "prettier": "prettier --write \"{examples,lib,tests,typings,doc}/**/*.{js,ts}\"",
12
12
  "eslint": "eslint --format codeframe \"examples/**/*.js\" \"lib/**/*.js\" \"tests/**/*.js\"",
13
13
  "docs:dev": "vuepress dev doc",
@@ -960,7 +960,7 @@ declare namespace Objection {
960
960
 
961
961
  onConflict(column?: string | string[] | true): this;
962
962
  ignore(): this;
963
- merge(merge?: PartialModelObject<M>): this;
963
+ merge(merge?: PartialModelObject<M> | string[]): this;
964
964
 
965
965
  insertAndFetch(insert: PartialModelObject<M>): SingleQueryBuilder<this>;
966
966
  insertAndFetch(insert: PartialModelObject<M>[]): ArrayQueryBuilder<this>;
@@ -1,103 +0,0 @@
1
- 'use strict';
2
-
3
- const { isObject } = require('../utils/objectUtils');
4
- const { isInternalProp } = require('../utils/internalPropUtils');
5
-
6
- function omit(model, args) {
7
- if (args.length === 1 && isObject(args[0])) {
8
- const keys = args[0];
9
-
10
- if (Array.isArray(keys)) {
11
- omitArray(model, keys);
12
- } else {
13
- omitObject(model, keys);
14
- }
15
- } else {
16
- omitArray(model, args);
17
- }
18
-
19
- return model;
20
- }
21
-
22
- function pick(model, args) {
23
- if (args.length === 1 && isObject(args[0])) {
24
- const keys = args[0];
25
-
26
- if (Array.isArray(keys)) {
27
- pickArray(model, keys);
28
- } else {
29
- pickObject(model, keys);
30
- }
31
- } else {
32
- pickArray(model, args);
33
- }
34
-
35
- return model;
36
- }
37
-
38
- function omitObject(model, keyObj) {
39
- const modelClass = model.constructor;
40
- const keys = Object.keys(keyObj);
41
-
42
- for (let i = 0, l = keys.length; i < l; ++i) {
43
- const key = keys[i];
44
- const value = keyObj[key];
45
-
46
- if (value && !isInternalProp(key) && model.hasOwnProperty(key)) {
47
- modelClass.omitImpl(model, key);
48
- }
49
- }
50
- }
51
-
52
- function omitArray(model, keys) {
53
- const modelClass = model.constructor;
54
-
55
- for (let i = 0, l = keys.length; i < l; ++i) {
56
- const key = keys[i];
57
-
58
- if (!isInternalProp(key) && model.hasOwnProperty(key)) {
59
- modelClass.omitImpl(model, key);
60
- }
61
- }
62
- }
63
-
64
- function pickObject(model, keyObj) {
65
- const modelClass = model.constructor;
66
- const keys = Object.keys(model);
67
-
68
- for (let i = 0, l = keys.length; i < l; ++i) {
69
- const key = keys[i];
70
-
71
- if (!isInternalProp(key) && !keyObj[key]) {
72
- modelClass.omitImpl(model, key);
73
- }
74
- }
75
- }
76
-
77
- function pickArray(model, pick) {
78
- const modelClass = model.constructor;
79
- const keys = Object.keys(model);
80
-
81
- for (let i = 0, l = keys.length; i < l; ++i) {
82
- const key = keys[i];
83
-
84
- if (!isInternalProp(key) && !contains(pick, key)) {
85
- modelClass.omitImpl(model, key);
86
- }
87
- }
88
- }
89
-
90
- function contains(arr, value) {
91
- for (let i = 0, l = arr.length; i < l; ++i) {
92
- if (arr[i] === value) {
93
- return true;
94
- }
95
- }
96
-
97
- return false;
98
- }
99
-
100
- module.exports = {
101
- omit,
102
- pick,
103
- };