objection 3.0.0 → 3.0.1

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.
@@ -858,8 +858,8 @@ function getReadOnlyAttributes(modelClass) {
858
858
  }
859
859
 
860
860
  function getReadOnlyAttributesRecursively(modelClass) {
861
- if (modelClass === Model) {
862
- // Stop recursion to the model class.
861
+ if (modelClass === Model || modelClass.prototype == undefined) {
862
+ // Stop recursion to the model class or its prototype is null or undefined.
863
863
  return [];
864
864
  }
865
865
 
@@ -37,25 +37,29 @@ function isMsSql(knex) {
37
37
  }
38
38
 
39
39
  function isKnexQueryBuilder(value) {
40
- return hasConstructor(value, 'Builder') && 'client' in value;
40
+ return (
41
+ hasConstructor(value) &&
42
+ isFunction(value.select) &&
43
+ isFunction(value.column) &&
44
+ value.select === value.column &&
45
+ 'client' in value
46
+ );
41
47
  }
42
48
 
43
49
  function isKnexJoinBuilder(value) {
44
- return hasConstructor(value, 'JoinClause') && 'joinType' in value;
50
+ return hasConstructor(value) && value.grouping === 'join' && 'joinType' in value;
45
51
  }
46
52
 
47
53
  function isKnexRaw(value) {
48
- return hasConstructor(value, 'Raw') && 'client' in value;
54
+ return hasConstructor(value) && value.isRawInstance && 'client' in value;
49
55
  }
50
56
 
51
57
  function isKnexTransaction(knex) {
52
58
  return !!getDialect(knex) && isFunction(knex.commit) && isFunction(knex.rollback);
53
59
  }
54
60
 
55
- function hasConstructor(value, constructorName) {
56
- return (
57
- isObject(value) && isFunction(value.constructor) && value.constructor.name === constructorName
58
- );
61
+ function hasConstructor(value) {
62
+ return isObject(value) && isFunction(value.constructor);
59
63
  }
60
64
 
61
65
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "objection",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "An SQL-friendly ORM for Node.js",
5
5
  "main": "lib/objection.js",
6
6
  "license": "MIT",
@@ -73,7 +73,7 @@
73
73
  "pg": "^8.7.1",
74
74
  "prettier": "2.4.1",
75
75
  "sqlite3": "^5.0.2",
76
- "typescript": "^4.4.4",
76
+ "typescript": "^4.5.4",
77
77
  "vuepress": "1.8.2"
78
78
  }
79
79
  }
@@ -179,6 +179,11 @@ declare namespace Objection {
179
179
  */
180
180
  type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T];
181
181
 
182
+ /**
183
+ * Type that attempts to only select the user-defined model properties.
184
+ */
185
+ type DataPropertyNames<T> = Exclude<NonFunctionPropertyNames<T>, 'QueryBuilderType'>;
186
+
182
187
  /**
183
188
  * Removes `undefined` from a type.
184
189
  */
@@ -188,14 +193,14 @@ declare namespace Objection {
188
193
  * A Pojo version of model.
189
194
  */
190
195
  type ModelObject<T extends Model> = {
191
- [K in Exclude<NonFunctionPropertyNames<T>, 'QueryBuilderType'>]: T[K];
196
+ [K in DataPropertyNames<T>]: T[K];
192
197
  };
193
198
 
194
199
  /**
195
200
  * Any object that has some of the properties of model class T match this type.
196
201
  */
197
202
  type PartialModelObject<T extends Model> = {
198
- [K in NonFunctionPropertyNames<T>]?: Defined<T[K]> extends Model
203
+ [K in DataPropertyNames<T>]?: Defined<T[K]> extends Model
199
204
  ? T[K]
200
205
  : Defined<T[K]> extends Array<infer I>
201
206
  ? I extends Model
@@ -217,7 +222,7 @@ declare namespace Objection {
217
222
  * Just like PartialModelObject but this is applied recursively to relations.
218
223
  */
219
224
  type PartialModelGraph<M, T = M & GraphParameters> = {
220
- [K in NonFunctionPropertyNames<T>]?: Defined<T[K]> extends Model
225
+ [K in DataPropertyNames<T>]?: Defined<T[K]> extends Model
221
226
  ? PartialModelGraph<Defined<T[K]>>
222
227
  : Defined<T[K]> extends Array<infer I>
223
228
  ? I extends Model