objection 2.2.17 → 3.0.0-alpha.5
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/lib/model/AjvValidator.js +16 -9
- package/lib/queryBuilder/QueryBuilderOperationSupport.js +2 -1
- package/lib/queryBuilder/operations/UpdateOperation.js +4 -6
- package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +2 -1
- package/lib/utils/clone.js +49 -27
- package/package.json +18 -36
- package/typings/objection/index.d.ts +36 -14
|
@@ -16,12 +16,14 @@ class AjvValidator extends Validator {
|
|
|
16
16
|
static init(self, conf) {
|
|
17
17
|
super.init(self, conf);
|
|
18
18
|
|
|
19
|
-
self.ajvOptions = Object.assign({
|
|
19
|
+
self.ajvOptions = Object.assign({}, conf.options, {
|
|
20
20
|
allErrors: true,
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
+
const Ajv = getAjv();
|
|
24
|
+
|
|
23
25
|
// Create a normal Ajv instance.
|
|
24
|
-
self.ajv = new
|
|
26
|
+
self.ajv = new Ajv(
|
|
25
27
|
Object.assign(
|
|
26
28
|
{
|
|
27
29
|
useDefaults: true,
|
|
@@ -32,7 +34,7 @@ class AjvValidator extends Validator {
|
|
|
32
34
|
|
|
33
35
|
// Create an instance that doesn't set default values. We need this one
|
|
34
36
|
// to validate `patch` objects (objects that have a subset of properties).
|
|
35
|
-
self.ajvNoDefaults = new
|
|
37
|
+
self.ajvNoDefaults = new Ajv(
|
|
36
38
|
Object.assign({}, self.ajvOptions, {
|
|
37
39
|
useDefaults: false,
|
|
38
40
|
})
|
|
@@ -151,8 +153,6 @@ function parseValidationError(errors, modelClass, options) {
|
|
|
151
153
|
let numErrors = 0;
|
|
152
154
|
|
|
153
155
|
for (const error of errors) {
|
|
154
|
-
const dataPath = `${options.dataPath || ''}${error.dataPath}`;
|
|
155
|
-
|
|
156
156
|
// If additionalProperties = false, relations can pop up as additionalProperty
|
|
157
157
|
// errors. Skip those.
|
|
158
158
|
if (
|
|
@@ -163,10 +163,17 @@ function parseValidationError(errors, modelClass, options) {
|
|
|
163
163
|
continue;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
166
|
+
let path = error.instancePath.replace(/\//g, '.');
|
|
167
|
+
|
|
168
|
+
if (error.params) {
|
|
169
|
+
if (error.params.missingProperty) {
|
|
170
|
+
path += `.${error.params.missingProperty}`;
|
|
171
|
+
} else if (error.params.additionalProperty) {
|
|
172
|
+
path += `.${error.params.additionalProperty}`;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const key = `${options.dataPath || ''}${path}`.substring(1);
|
|
170
177
|
|
|
171
178
|
// More than one error can occur for the same key in Ajv, merge them in the array:
|
|
172
179
|
const array = errorHash[key] || (errorHash[key] = []);
|
|
@@ -6,7 +6,8 @@ const { QueryBuilderContextBase } = require('./QueryBuilderContextBase');
|
|
|
6
6
|
const { QueryBuilderUserContext } = require('./QueryBuilderUserContext');
|
|
7
7
|
|
|
8
8
|
const AllSelector = () => true;
|
|
9
|
-
const SelectSelector =
|
|
9
|
+
const SelectSelector =
|
|
10
|
+
/^(select|columns|column|distinct|count|countDistinct|min|max|sum|sumDistinct|avg|avgDistinct)$/;
|
|
10
11
|
const WhereSelector = /^(where|orWhere|andWhere|find\w+)/;
|
|
11
12
|
const OnSelector = /^(on|orOn|andOn)/;
|
|
12
13
|
const OrderBySelector = /orderBy/;
|
|
@@ -113,12 +113,10 @@ function convertFieldExpressionsToRaw(builder, model, json) {
|
|
|
113
113
|
val = JSON.stringify(val);
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
convertedJson[
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
val,
|
|
121
|
-
]);
|
|
116
|
+
convertedJson[parsed.column] = knex.raw(
|
|
117
|
+
`jsonb_set(??, '${jsonRefs}', ${valuePlaceholder}, true)`,
|
|
118
|
+
[convertedJson[parsed.column] || parsed.column, val]
|
|
119
|
+
);
|
|
122
120
|
|
|
123
121
|
delete model[key];
|
|
124
122
|
} else {
|
|
@@ -157,7 +157,8 @@ function normalizeOperator(knex, operator) {
|
|
|
157
157
|
module.exports = {
|
|
158
158
|
parseFieldExpression: parseFieldExpression,
|
|
159
159
|
whereJsonbRefOnLeftJsonbValOrRefOnRight: whereJsonbRefOnLeftJsonbValOrRefOnRight,
|
|
160
|
-
whereJsonbRefOnLeftJsonbValOrRefOnRightRawQueryParams:
|
|
160
|
+
whereJsonbRefOnLeftJsonbValOrRefOnRightRawQueryParams:
|
|
161
|
+
whereJsonbRefOnLeftJsonbValOrRefOnRightRawQueryParams,
|
|
161
162
|
whereJsonFieldRightStringArrayOnLeftQuery: whereJsonFieldRightStringArrayOnLeftQuery,
|
|
162
163
|
whereJsonFieldQuery: whereJsonFieldQuery,
|
|
163
164
|
};
|
package/lib/utils/clone.js
CHANGED
|
@@ -81,36 +81,58 @@
|
|
|
81
81
|
|
|
82
82
|
/** Used to identify `toStringTag` values of typed arrays. */
|
|
83
83
|
var typedArrayTags = {};
|
|
84
|
-
typedArrayTags[float32Tag] =
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
84
|
+
typedArrayTags[float32Tag] =
|
|
85
|
+
typedArrayTags[float64Tag] =
|
|
86
|
+
typedArrayTags[int8Tag] =
|
|
87
|
+
typedArrayTags[int16Tag] =
|
|
88
|
+
typedArrayTags[int32Tag] =
|
|
89
|
+
typedArrayTags[uint8Tag] =
|
|
90
|
+
typedArrayTags[uint8ClampedTag] =
|
|
91
|
+
typedArrayTags[uint16Tag] =
|
|
92
|
+
typedArrayTags[uint32Tag] =
|
|
93
|
+
true;
|
|
94
|
+
typedArrayTags[argsTag] =
|
|
95
|
+
typedArrayTags[arrayTag] =
|
|
96
|
+
typedArrayTags[arrayBufferTag] =
|
|
97
|
+
typedArrayTags[boolTag] =
|
|
98
|
+
typedArrayTags[dataViewTag] =
|
|
99
|
+
typedArrayTags[dateTag] =
|
|
100
|
+
typedArrayTags[errorTag] =
|
|
101
|
+
typedArrayTags[funcTag] =
|
|
102
|
+
typedArrayTags[mapTag] =
|
|
103
|
+
typedArrayTags[numberTag] =
|
|
104
|
+
typedArrayTags[objectTag] =
|
|
105
|
+
typedArrayTags[regexpTag] =
|
|
106
|
+
typedArrayTags[setTag] =
|
|
107
|
+
typedArrayTags[stringTag] =
|
|
108
|
+
typedArrayTags[weakMapTag] =
|
|
109
|
+
false;
|
|
100
110
|
|
|
101
111
|
/** Used to identify `toStringTag` values supported by `_.clone`. */
|
|
102
112
|
var cloneableTags = {};
|
|
103
|
-
cloneableTags[argsTag] =
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
cloneableTags[argsTag] =
|
|
114
|
+
cloneableTags[arrayTag] =
|
|
115
|
+
cloneableTags[arrayBufferTag] =
|
|
116
|
+
cloneableTags[dataViewTag] =
|
|
117
|
+
cloneableTags[boolTag] =
|
|
118
|
+
cloneableTags[dateTag] =
|
|
119
|
+
cloneableTags[float32Tag] =
|
|
120
|
+
cloneableTags[float64Tag] =
|
|
121
|
+
cloneableTags[int8Tag] =
|
|
122
|
+
cloneableTags[int16Tag] =
|
|
123
|
+
cloneableTags[int32Tag] =
|
|
124
|
+
cloneableTags[mapTag] =
|
|
125
|
+
cloneableTags[numberTag] =
|
|
126
|
+
cloneableTags[objectTag] =
|
|
127
|
+
cloneableTags[regexpTag] =
|
|
128
|
+
cloneableTags[setTag] =
|
|
129
|
+
cloneableTags[stringTag] =
|
|
130
|
+
cloneableTags[symbolTag] =
|
|
131
|
+
cloneableTags[uint8Tag] =
|
|
132
|
+
cloneableTags[uint8ClampedTag] =
|
|
133
|
+
cloneableTags[uint16Tag] =
|
|
134
|
+
cloneableTags[uint32Tag] =
|
|
135
|
+
true;
|
|
114
136
|
cloneableTags[errorTag] = cloneableTags[funcTag] = cloneableTags[weakMapTag] = false;
|
|
115
137
|
|
|
116
138
|
/** Detect free variable `global` from Node.js. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "objection",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.5",
|
|
4
4
|
"description": "An SQL-friendly ORM for Node.js",
|
|
5
5
|
"main": "lib/objection.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"url": "git://github.com/vincit/objection.js.git"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
|
-
"node": ">=
|
|
44
|
+
"node": ">=12.0.0"
|
|
45
45
|
},
|
|
46
46
|
"keywords": [
|
|
47
47
|
"orm",
|
|
@@ -61,34 +61,32 @@
|
|
|
61
61
|
],
|
|
62
62
|
"types": "./typings/objection/index.d.ts",
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"ajv": "^6.
|
|
64
|
+
"ajv": "^8.6.2",
|
|
65
65
|
"db-errors": "^0.2.3"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
-
"knex": "
|
|
68
|
+
"knex": ">=0.95.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@types/node": "^
|
|
72
|
-
"chai": "^4.
|
|
71
|
+
"@types/node": "^16.3.2",
|
|
72
|
+
"chai": "^4.3.4",
|
|
73
73
|
"chai-subset": "^1.6.0",
|
|
74
|
-
"coveralls": "^3.1.
|
|
74
|
+
"coveralls": "^3.1.1",
|
|
75
75
|
"cross-env": "^7.0.3",
|
|
76
|
-
"eslint": "^7.
|
|
77
|
-
"eslint-plugin-prettier": "^3.
|
|
76
|
+
"eslint": "^7.30.0",
|
|
77
|
+
"eslint-plugin-prettier": "^3.4.0",
|
|
78
78
|
"expect.js": "^0.3.1",
|
|
79
|
-
"fs-extra": "^
|
|
80
|
-
"glob": "^7.1.
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"lint-staged": "^10.5.3",
|
|
84
|
-
"mocha": "^8.2.1",
|
|
79
|
+
"fs-extra": "^10.0.0",
|
|
80
|
+
"glob": "^7.1.7",
|
|
81
|
+
"knex": "0.95.7",
|
|
82
|
+
"mocha": "^9.0.2",
|
|
85
83
|
"mysql": "^2.18.1",
|
|
86
84
|
"nyc": "^15.1.0",
|
|
87
|
-
"pg": "^8.
|
|
88
|
-
"prettier": "2.2
|
|
89
|
-
"sqlite3": "^5.0.
|
|
90
|
-
"typescript": "^4.
|
|
91
|
-
"vuepress": "1.
|
|
85
|
+
"pg": "^8.6.0",
|
|
86
|
+
"prettier": "2.3.2",
|
|
87
|
+
"sqlite3": "^5.0.2",
|
|
88
|
+
"typescript": "^4.3.5",
|
|
89
|
+
"vuepress": "1.8.2"
|
|
92
90
|
},
|
|
93
91
|
"nyc": {
|
|
94
92
|
"description": "test coverage",
|
|
@@ -103,21 +101,5 @@
|
|
|
103
101
|
"text"
|
|
104
102
|
],
|
|
105
103
|
"report-dir": "./testCoverage"
|
|
106
|
-
},
|
|
107
|
-
"husky": {
|
|
108
|
-
"hooks": {
|
|
109
|
-
"pre-commit": "lint-staged"
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
"lint-staged": {
|
|
113
|
-
"*.js": [
|
|
114
|
-
"prettier --write",
|
|
115
|
-
"eslint --fix",
|
|
116
|
-
"git add"
|
|
117
|
-
],
|
|
118
|
-
"*.{yml,ts}": [
|
|
119
|
-
"prettier --write",
|
|
120
|
-
"git add"
|
|
121
|
-
]
|
|
122
104
|
}
|
|
123
105
|
}
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
// * Karl Blomster <https://github.com/kblomster>
|
|
13
13
|
// * And many others: See <https://github.com/Vincit/objection.js/blob/master/typings/objection/index.d.ts>
|
|
14
14
|
|
|
15
|
-
import
|
|
15
|
+
import Ajv, { Options as AjvOptions } from 'ajv';
|
|
16
16
|
import * as dbErrors from 'db-errors';
|
|
17
|
-
import
|
|
17
|
+
import { Knex } from 'knex';
|
|
18
18
|
|
|
19
19
|
// Export the entire Objection namespace.
|
|
20
20
|
export = Objection;
|
|
@@ -306,6 +306,11 @@ declare namespace Objection {
|
|
|
306
306
|
*/
|
|
307
307
|
type SingleQueryBuilder<T extends { SingleQueryBuilderType: any }> = T['SingleQueryBuilderType'];
|
|
308
308
|
|
|
309
|
+
/**
|
|
310
|
+
* Gets the single or undefined item query builder type for a query builder.
|
|
311
|
+
*/
|
|
312
|
+
type MaybeSingleQueryBuilder<QB extends AnyQueryBuilder> = QB['MaybeSingleQueryBuilderType'];
|
|
313
|
+
|
|
309
314
|
/**
|
|
310
315
|
* Gets the multi-item query builder type for a query builder.
|
|
311
316
|
*/
|
|
@@ -566,7 +571,7 @@ declare namespace Objection {
|
|
|
566
571
|
|
|
567
572
|
interface FirstMethod {
|
|
568
573
|
<QB extends AnyQueryBuilder>(this: QB): QB extends ArrayQueryBuilder<QB>
|
|
569
|
-
?
|
|
574
|
+
? MaybeSingleQueryBuilder<QB>
|
|
570
575
|
: QB;
|
|
571
576
|
}
|
|
572
577
|
|
|
@@ -589,10 +594,6 @@ declare namespace Objection {
|
|
|
589
594
|
(arg: T): QB;
|
|
590
595
|
}
|
|
591
596
|
|
|
592
|
-
interface OptionalOneArgMethod<T, QB extends AnyQueryBuilder> {
|
|
593
|
-
(arg?: T): QB;
|
|
594
|
-
}
|
|
595
|
-
|
|
596
597
|
interface StringReturningMethod {
|
|
597
598
|
(): string;
|
|
598
599
|
}
|
|
@@ -754,7 +755,7 @@ declare namespace Objection {
|
|
|
754
755
|
export interface GraphOptions {
|
|
755
756
|
minimize?: boolean;
|
|
756
757
|
separator?: string;
|
|
757
|
-
aliases?: {[key: string]: string};
|
|
758
|
+
aliases?: { [key: string]: string };
|
|
758
759
|
joinOperation?: string;
|
|
759
760
|
maxBatchSize?: number;
|
|
760
761
|
}
|
|
@@ -798,7 +799,13 @@ declare namespace Objection {
|
|
|
798
799
|
[key: string]: any;
|
|
799
800
|
}
|
|
800
801
|
|
|
801
|
-
export
|
|
802
|
+
export interface CatchablePromiseLike<R> extends PromiseLike<R> {
|
|
803
|
+
catch<FR = never>(
|
|
804
|
+
onrejected?: ((reason: any) => FR | PromiseLike<FR>) | undefined | null
|
|
805
|
+
): Promise<R | FR>;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
export class QueryBuilder<M extends Model, R = M[]> implements CatchablePromiseLike<R> {
|
|
802
809
|
static forClass: ForClassMethod;
|
|
803
810
|
|
|
804
811
|
select: SelectMethod<this>;
|
|
@@ -969,9 +976,9 @@ declare namespace Objection {
|
|
|
969
976
|
groupBy: GroupByMethod<this>;
|
|
970
977
|
groupByRaw: RawInterface<this>;
|
|
971
978
|
|
|
972
|
-
findById(id: MaybeCompositeId):
|
|
979
|
+
findById(id: MaybeCompositeId): MaybeSingleQueryBuilder<this>;
|
|
973
980
|
findByIds(ids: MaybeCompositeId[]): this;
|
|
974
|
-
findOne: WhereMethod<
|
|
981
|
+
findOne: WhereMethod<MaybeSingleQueryBuilder<this>>;
|
|
975
982
|
|
|
976
983
|
execute(): Promise<R>;
|
|
977
984
|
castTo<MC extends Model>(modelClass: ModelConstructor<MC>): QueryBuilderType<MC>;
|
|
@@ -1047,7 +1054,10 @@ declare namespace Objection {
|
|
|
1047
1054
|
// Deprecated
|
|
1048
1055
|
allowUpsert: AllowGraphMethod<this>;
|
|
1049
1056
|
|
|
1050
|
-
throwIfNotFound:
|
|
1057
|
+
throwIfNotFound: (
|
|
1058
|
+
arg?: any
|
|
1059
|
+
) => R extends Model | undefined ? SingleQueryBuilder<QueryBuilder<M, M>> : this;
|
|
1060
|
+
|
|
1051
1061
|
returning: ReturningMethod;
|
|
1052
1062
|
forUpdate: IdentityMethod<this>;
|
|
1053
1063
|
forShare: IdentityMethod<this>;
|
|
@@ -1156,10 +1166,22 @@ declare namespace Objection {
|
|
|
1156
1166
|
|
|
1157
1167
|
ArrayQueryBuilderType: QueryBuilder<M, M[]>;
|
|
1158
1168
|
SingleQueryBuilderType: QueryBuilder<M, M>;
|
|
1169
|
+
MaybeSingleQueryBuilderType: QueryBuilder<M, M | undefined>;
|
|
1159
1170
|
NumberQueryBuilderType: QueryBuilder<M, number>;
|
|
1160
1171
|
PageQueryBuilderType: QueryBuilder<M, Page<M>>;
|
|
1172
|
+
|
|
1173
|
+
then<R1 = R, R2 = never>(
|
|
1174
|
+
onfulfilled?: ((value: R) => R1 | PromiseLike<R1>) | undefined | null,
|
|
1175
|
+
onrejected?: ((reason: any) => R2 | PromiseLike<R2>) | undefined | null
|
|
1176
|
+
): Promise<R1 | R2>;
|
|
1177
|
+
|
|
1178
|
+
catch<FR = never>(
|
|
1179
|
+
onrejected?: ((reason: any) => FR | PromiseLike<FR>) | undefined | null
|
|
1180
|
+
): Promise<R | FR>;
|
|
1161
1181
|
}
|
|
1162
1182
|
|
|
1183
|
+
type X<T> = Promise<T>;
|
|
1184
|
+
|
|
1163
1185
|
interface FetchGraphOptions {
|
|
1164
1186
|
transaction?: TransactionOrKnex;
|
|
1165
1187
|
skipFetched?: boolean;
|
|
@@ -1287,8 +1309,8 @@ declare namespace Objection {
|
|
|
1287
1309
|
}
|
|
1288
1310
|
|
|
1289
1311
|
export interface AjvConfig {
|
|
1290
|
-
onCreateAjv(ajv:
|
|
1291
|
-
options?:
|
|
1312
|
+
onCreateAjv(ajv: Ajv): void;
|
|
1313
|
+
options?: AjvOptions;
|
|
1292
1314
|
}
|
|
1293
1315
|
|
|
1294
1316
|
export class AjvValidator extends Validator {
|