objection 3.0.4 → 3.0.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.
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const Ajv = require('ajv');
|
|
4
|
+
const addFormats = require('ajv-formats');
|
|
3
5
|
const { Validator } = require('./Validator');
|
|
4
6
|
const { ValidationErrorType } = require('../model/ValidationError');
|
|
5
7
|
const { isObject, once, cloneDeep: lodashCloneDeep, omit } = require('../utils/objectUtils');
|
|
6
8
|
|
|
7
|
-
const getAjv = once(() => {
|
|
8
|
-
try {
|
|
9
|
-
return require('ajv');
|
|
10
|
-
} catch (err) {
|
|
11
|
-
throw new Error('Optional ajv dependency not installed. Please run `npm install ajv --save`');
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
|
|
15
9
|
class AjvValidator extends Validator {
|
|
16
10
|
static init(self, conf) {
|
|
17
11
|
super.init(self, conf);
|
|
@@ -20,8 +14,6 @@ class AjvValidator extends Validator {
|
|
|
20
14
|
allErrors: true,
|
|
21
15
|
});
|
|
22
16
|
|
|
23
|
-
const Ajv = getAjv();
|
|
24
|
-
|
|
25
17
|
// Create a normal Ajv instance.
|
|
26
18
|
self.ajv = new Ajv(
|
|
27
19
|
Object.assign(
|
|
@@ -43,8 +35,13 @@ class AjvValidator extends Validator {
|
|
|
43
35
|
// A cache for the compiled validator functions.
|
|
44
36
|
self.cache = new Map();
|
|
45
37
|
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
const setupAjv = (ajv) => {
|
|
39
|
+
addFormats(ajv);
|
|
40
|
+
conf.onCreateAjv(ajv);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
setupAjv(self.ajv);
|
|
44
|
+
setupAjv(self.ajvNoDefaults);
|
|
48
45
|
}
|
|
49
46
|
|
|
50
47
|
beforeValidate({ json, model, options, ctx }) {
|
|
@@ -256,7 +253,7 @@ function jsonSchemaWithoutRequired(jsonSchema) {
|
|
|
256
253
|
return Object.assign(
|
|
257
254
|
omit(jsonSchema, ['required', ...subSchemaProps]),
|
|
258
255
|
...subSchemaProps.map((prop) => subSchemaWithoutRequired(jsonSchema, prop)),
|
|
259
|
-
jsonSchema && jsonSchema.definitions
|
|
256
|
+
jsonSchema && jsonSchema.definitions && Object.keys(jsonSchema.definitions).length > 0
|
|
260
257
|
? {
|
|
261
258
|
definitions: Object.assign(
|
|
262
259
|
...Object.keys(jsonSchema.definitions).map((prop) => ({
|
|
@@ -264,6 +261,9 @@ function jsonSchemaWithoutRequired(jsonSchema) {
|
|
|
264
261
|
}))
|
|
265
262
|
),
|
|
266
263
|
}
|
|
264
|
+
: {},
|
|
265
|
+
jsonSchema.discriminator && jsonSchema.discriminator.propertyName
|
|
266
|
+
? { required: [jsonSchema.discriminator.propertyName] }
|
|
267
267
|
: {}
|
|
268
268
|
);
|
|
269
269
|
}
|
|
@@ -345,6 +345,10 @@ class QueryBuilderBase extends QueryBuilderOperationSupport {
|
|
|
345
345
|
return this.addOperation(new KnexOperation('intersect'), args);
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
+
except(...args) {
|
|
349
|
+
return this.addOperation(new KnexOperation('except'), args);
|
|
350
|
+
}
|
|
351
|
+
|
|
348
352
|
having(...args) {
|
|
349
353
|
return this.addOperation(new KnexOperation('having'), args);
|
|
350
354
|
}
|
|
@@ -4,7 +4,7 @@ const promiseUtils = require('../../../utils/promiseUtils');
|
|
|
4
4
|
|
|
5
5
|
const { EagerOperation } = require('./EagerOperation');
|
|
6
6
|
const { isMsSql, isOracle, isSqlite } = require('../../../utils/knexUtils');
|
|
7
|
-
const { asArray, flatten, chunk } = require('../../../utils/objectUtils');
|
|
7
|
+
const { isObject, asArray, flatten, chunk } = require('../../../utils/objectUtils');
|
|
8
8
|
const { ValidationErrorType } = require('../../../model/ValidationError');
|
|
9
9
|
const { createModifier } = require('../../../utils/createModifier');
|
|
10
10
|
const { RelationDoesNotExistError } = require('../../../model/RelationDoesNotExistError');
|
|
@@ -63,7 +63,8 @@ class WhereInEagerOperation extends EagerOperation {
|
|
|
63
63
|
|
|
64
64
|
const models = asArray(result);
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
// Check models to be actual objects, to filter out `count` results (#2397).
|
|
67
|
+
if (!models.length || !isObject(models[0])) {
|
|
67
68
|
return result;
|
|
68
69
|
}
|
|
69
70
|
|
|
@@ -187,7 +187,10 @@ function isQueryBuilder(item) {
|
|
|
187
187
|
|
|
188
188
|
function findFirstNonPartialAncestorQuery(builder) {
|
|
189
189
|
builder = builder.parentQuery();
|
|
190
|
-
|
|
190
|
+
if (!builder)
|
|
191
|
+
throw Error(
|
|
192
|
+
'query method `for` ommitted outside a subquery, can not figure out relation target'
|
|
193
|
+
);
|
|
191
194
|
while (builder.isPartial()) {
|
|
192
195
|
if (!builder.parentQuery()) {
|
|
193
196
|
break;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "objection",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5",
|
|
4
4
|
"description": "An SQL-friendly ORM for Node.js",
|
|
5
5
|
"main": "lib/objection.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"types": "./typings/objection/index.d.ts",
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"ajv": "^8.6.2",
|
|
57
|
+
"ajv-formats": "^2.1.1",
|
|
57
58
|
"db-errors": "^0.2.3"
|
|
58
59
|
},
|
|
59
60
|
"peerDependencies": {
|
|
@@ -194,9 +194,7 @@ declare namespace Objection {
|
|
|
194
194
|
/**
|
|
195
195
|
* A Pojo version of model.
|
|
196
196
|
*/
|
|
197
|
-
type ModelObject<T extends Model> =
|
|
198
|
-
[K in DataPropertyNames<T>]: T[K];
|
|
199
|
-
};
|
|
197
|
+
type ModelObject<T extends Model> = Pick<T, DataPropertyNames<T>>;
|
|
200
198
|
|
|
201
199
|
/**
|
|
202
200
|
* Any object that has some of the properties of model class T match this type.
|
|
@@ -234,10 +232,10 @@ declare namespace Objection {
|
|
|
234
232
|
type PartialModelGraphField<F> = Defined<F> extends Model
|
|
235
233
|
? PartialModelGraph<Defined<F>>
|
|
236
234
|
: Defined<F> extends Array<infer I>
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
235
|
+
? I extends Model
|
|
236
|
+
? PartialModelGraph<I>[]
|
|
237
|
+
: Expression<F>
|
|
238
|
+
: Expression<F>;
|
|
241
239
|
|
|
242
240
|
/**
|
|
243
241
|
* Extracts the property names (excluding relations) of a model class.
|
|
@@ -709,9 +707,7 @@ declare namespace Objection {
|
|
|
709
707
|
<QB extends AnyQueryBuilder>(
|
|
710
708
|
this: QB,
|
|
711
709
|
column: string | Raw | (string | Raw)[]
|
|
712
|
-
): QB extends NumberQueryBuilder<QB>
|
|
713
|
-
? ArrayQueryBuilder<QB>
|
|
714
|
-
: QB;
|
|
710
|
+
): QB extends NumberQueryBuilder<QB> ? ArrayQueryBuilder<QB> : QB;
|
|
715
711
|
}
|
|
716
712
|
|
|
717
713
|
interface TimeoutOptions {
|
|
@@ -995,6 +991,7 @@ declare namespace Objection {
|
|
|
995
991
|
union: UnionMethod<this>;
|
|
996
992
|
unionAll: UnionMethod<this>;
|
|
997
993
|
intersect: SetOperationsMethod<this>;
|
|
994
|
+
except: SetOperationsMethod<this>;
|
|
998
995
|
|
|
999
996
|
with: WithMethod<this>;
|
|
1000
997
|
withRecursive: WithMethod<this>;
|