objection 3.0.0 → 3.0.2
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.
- package/README.md +3 -1
- package/lib/model/Model.js +2 -2
- package/lib/objection.js +16 -2
- package/lib/utils/identifierMapping.js +1 -0
- package/lib/utils/knexUtils.js +11 -7
- package/package.json +2 -2
- package/typings/objection/index.d.ts +11 -5
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
[](https://stand-with-ukraine.pp.ua)
|
|
2
|
+
|
|
1
3
|
[](https://github.com/Vincit/objection.js)
|
|
2
4
|
[](https://gitter.im/Vincit/objection.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
3
5
|
|
|
@@ -7,7 +9,7 @@ Objection.js is an [ORM](https://en.wikipedia.org/wiki/Object-relational_mapping
|
|
|
7
9
|
|
|
8
10
|
Even though ORM is the best commonly known acronym to describe objection, a more accurate description is to call it **a relational query builder**. You get all the benefits of an SQL query builder but also a powerful set of tools for working with relations.
|
|
9
11
|
|
|
10
|
-
Objection.js is built on an SQL query builder called [knex](http://knexjs.org). All databases supported by knex are supported by objection.js. **SQLite3**, **Postgres** and **MySQL** are [thoroughly tested](https://
|
|
12
|
+
Objection.js is built on an SQL query builder called [knex](http://knexjs.org). All databases supported by knex are supported by objection.js. **SQLite3**, **Postgres** and **MySQL** are [thoroughly tested](https://github.com/Vincit/objection.js/actions).
|
|
11
13
|
|
|
12
14
|
What objection.js gives you:
|
|
13
15
|
|
package/lib/model/Model.js
CHANGED
|
@@ -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
|
|
package/lib/objection.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
DBError,
|
|
5
|
+
UniqueViolationError,
|
|
6
|
+
NotNullViolationError,
|
|
7
|
+
ForeignKeyViolationError,
|
|
8
|
+
ConstraintViolationError,
|
|
9
|
+
CheckViolationError,
|
|
10
|
+
DataError,
|
|
11
|
+
} = require('db-errors');
|
|
4
12
|
const { Model: NativeModel } = require('./model/Model');
|
|
5
13
|
const { QueryBuilder: NativeQueryBuilder } = require('./queryBuilder/QueryBuilder');
|
|
6
14
|
const { QueryBuilderBase } = require('./queryBuilder/QueryBuilderBase');
|
|
@@ -88,5 +96,11 @@ module.exports = {
|
|
|
88
96
|
knexSnakeCaseMappers,
|
|
89
97
|
knexIdentifierMapping,
|
|
90
98
|
|
|
91
|
-
|
|
99
|
+
DBError,
|
|
100
|
+
UniqueViolationError,
|
|
101
|
+
NotNullViolationError,
|
|
102
|
+
ForeignKeyViolationError,
|
|
103
|
+
ConstraintViolationError,
|
|
104
|
+
CheckViolationError,
|
|
105
|
+
DataError,
|
|
92
106
|
};
|
|
@@ -135,6 +135,7 @@ function isDigit(char) {
|
|
|
135
135
|
// If no separators are found, `mapper` is called for the entire string.
|
|
136
136
|
function mapLastPart(mapper, separator) {
|
|
137
137
|
return (str) => {
|
|
138
|
+
if (!str) return str;
|
|
138
139
|
const idx = str.lastIndexOf(separator);
|
|
139
140
|
const mapped = mapper(str.slice(idx + separator.length));
|
|
140
141
|
return str.slice(0, idx + separator.length) + mapped;
|
package/lib/utils/knexUtils.js
CHANGED
|
@@ -37,25 +37,29 @@ function isMsSql(knex) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
function isKnexQueryBuilder(value) {
|
|
40
|
-
return
|
|
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
|
|
50
|
+
return hasConstructor(value) && value.grouping === 'join' && 'joinType' in value;
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
function isKnexRaw(value) {
|
|
48
|
-
return hasConstructor(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
|
|
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.
|
|
3
|
+
"version": "3.0.2",
|
|
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.
|
|
76
|
+
"typescript": "^4.5.4",
|
|
77
77
|
"vuepress": "1.8.2"
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -132,7 +132,8 @@ declare namespace Objection {
|
|
|
132
132
|
| boolean[]
|
|
133
133
|
| Date[]
|
|
134
134
|
| null
|
|
135
|
-
| Buffer
|
|
135
|
+
| Buffer
|
|
136
|
+
| Buffer[];
|
|
136
137
|
|
|
137
138
|
type Expression<T> = T | Raw | ReferenceBuilder | ValueBuilder | AnyQueryBuilder;
|
|
138
139
|
|
|
@@ -179,6 +180,11 @@ declare namespace Objection {
|
|
|
179
180
|
*/
|
|
180
181
|
type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T];
|
|
181
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Type that attempts to only select the user-defined model properties.
|
|
185
|
+
*/
|
|
186
|
+
type DataPropertyNames<T> = Exclude<NonFunctionPropertyNames<T>, 'QueryBuilderType'>;
|
|
187
|
+
|
|
182
188
|
/**
|
|
183
189
|
* Removes `undefined` from a type.
|
|
184
190
|
*/
|
|
@@ -188,14 +194,14 @@ declare namespace Objection {
|
|
|
188
194
|
* A Pojo version of model.
|
|
189
195
|
*/
|
|
190
196
|
type ModelObject<T extends Model> = {
|
|
191
|
-
[K in
|
|
197
|
+
[K in DataPropertyNames<T>]: T[K];
|
|
192
198
|
};
|
|
193
199
|
|
|
194
200
|
/**
|
|
195
201
|
* Any object that has some of the properties of model class T match this type.
|
|
196
202
|
*/
|
|
197
203
|
type PartialModelObject<T extends Model> = {
|
|
198
|
-
[K in
|
|
204
|
+
[K in DataPropertyNames<T>]?: Defined<T[K]> extends Model
|
|
199
205
|
? T[K]
|
|
200
206
|
: Defined<T[K]> extends Array<infer I>
|
|
201
207
|
? I extends Model
|
|
@@ -217,7 +223,7 @@ declare namespace Objection {
|
|
|
217
223
|
* Just like PartialModelObject but this is applied recursively to relations.
|
|
218
224
|
*/
|
|
219
225
|
type PartialModelGraph<M, T = M & GraphParameters> = {
|
|
220
|
-
[K in
|
|
226
|
+
[K in DataPropertyNames<T>]?: Defined<T[K]> extends Model
|
|
221
227
|
? PartialModelGraph<Defined<T[K]>>
|
|
222
228
|
: Defined<T[K]> extends Array<infer I>
|
|
223
229
|
? I extends Model
|
|
@@ -1003,7 +1009,7 @@ declare namespace Objection {
|
|
|
1003
1009
|
timeout: TimeoutMethod<this>;
|
|
1004
1010
|
columnInfo: ColumnInfoMethod<this>;
|
|
1005
1011
|
|
|
1006
|
-
toKnexQuery<T = ModelObject<M>>(): Knex.QueryBuilder<T, T[]>;
|
|
1012
|
+
toKnexQuery<T extends {} = ModelObject<M>>(): Knex.QueryBuilder<T, T[]>;
|
|
1007
1013
|
clone(): this;
|
|
1008
1014
|
|
|
1009
1015
|
page(page: number, pageSize: number): PageQueryBuilder<this>;
|