@strapi/database 4.11.0-exp.push-transfer-push-stuck → 4.11.1-beta.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.
- package/lib/index.d.ts +4 -2
- package/lib/query/helpers/where.js +18 -59
- package/package.json +5 -4
package/lib/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { LifecycleProvider } from './lifecycles';
|
|
|
3
3
|
import { MigrationProvider } from './migrations';
|
|
4
4
|
import { SchemaProvider } from './schema';
|
|
5
5
|
|
|
6
|
+
type ID = number | string;
|
|
7
|
+
|
|
6
8
|
type LogicalOperators<T> = {
|
|
7
9
|
$and?: WhereParams<T>[];
|
|
8
10
|
$or?: WhereParams<T>[];
|
|
@@ -84,7 +86,7 @@ interface EntityManager {
|
|
|
84
86
|
createMany<K extends keyof AllTypes>(
|
|
85
87
|
uid: K,
|
|
86
88
|
params: CreateManyParams<AllTypes[K]>
|
|
87
|
-
): Promise<{ count: number }>;
|
|
89
|
+
): Promise<{ count: number; ids: ID[] }>;
|
|
88
90
|
|
|
89
91
|
update<K extends keyof AllTypes>(uid: K, params: any): Promise<any>;
|
|
90
92
|
updateMany<K extends keyof AllTypes>(uid: K, params: any): Promise<{ count: number }>;
|
|
@@ -119,7 +121,7 @@ interface QueryFromContentType<T extends keyof AllTypes> {
|
|
|
119
121
|
findPage(params: FindParams<AllTypes[T]>): Promise<{ results: any[]; pagination: Pagination }>;
|
|
120
122
|
|
|
121
123
|
create(params: CreateParams<AllTypes[T]>): Promise<any>;
|
|
122
|
-
createMany(params: CreateManyParams<AllTypes[T]>): Promise<{ count: number }>;
|
|
124
|
+
createMany(params: CreateManyParams<AllTypes[T]>): Promise<{ count: number; ids: ID[] }>;
|
|
123
125
|
|
|
124
126
|
update(params: any): Promise<any>;
|
|
125
127
|
updateMany(params: any): Promise<{ count: number }>;
|
|
@@ -1,55 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const { isArray, castArray, keys, isPlainObject } = require('lodash/fp');
|
|
4
4
|
|
|
5
|
+
const { isOperatorOfType } = require('@strapi/utils');
|
|
5
6
|
const types = require('../../types');
|
|
6
7
|
const { createField } = require('../../fields');
|
|
7
8
|
const { createJoin } = require('./join');
|
|
8
9
|
const { toColumnName } = require('./transform');
|
|
9
10
|
const { isKnexQuery } = require('../../utils/knex');
|
|
10
11
|
|
|
11
|
-
const GROUP_OPERATORS = ['$and', '$or'];
|
|
12
|
-
const OPERATORS = [
|
|
13
|
-
'$not',
|
|
14
|
-
'$in',
|
|
15
|
-
'$notIn',
|
|
16
|
-
'$eq',
|
|
17
|
-
'$eqi',
|
|
18
|
-
'$ne',
|
|
19
|
-
'$gt',
|
|
20
|
-
'$gte',
|
|
21
|
-
'$lt',
|
|
22
|
-
'$lte',
|
|
23
|
-
'$null',
|
|
24
|
-
'$notNull',
|
|
25
|
-
'$between',
|
|
26
|
-
'$startsWith',
|
|
27
|
-
'$endsWith',
|
|
28
|
-
'$startsWithi',
|
|
29
|
-
'$endsWithi',
|
|
30
|
-
'$contains',
|
|
31
|
-
'$notContains',
|
|
32
|
-
'$containsi',
|
|
33
|
-
'$notContainsi',
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
const CAST_OPERATORS = [
|
|
37
|
-
'$not',
|
|
38
|
-
'$in',
|
|
39
|
-
'$notIn',
|
|
40
|
-
'$eq',
|
|
41
|
-
'$ne',
|
|
42
|
-
'$gt',
|
|
43
|
-
'$gte',
|
|
44
|
-
'$lt',
|
|
45
|
-
'$lte',
|
|
46
|
-
'$between',
|
|
47
|
-
];
|
|
48
|
-
|
|
49
|
-
const ARRAY_OPERATORS = ['$in', '$notIn', '$between'];
|
|
50
|
-
|
|
51
|
-
const isOperator = (key) => OPERATORS.includes(key);
|
|
52
|
-
|
|
53
12
|
const castValue = (value, attribute) => {
|
|
54
13
|
if (!attribute) {
|
|
55
14
|
return value;
|
|
@@ -65,12 +24,12 @@ const castValue = (value, attribute) => {
|
|
|
65
24
|
};
|
|
66
25
|
|
|
67
26
|
const processAttributeWhere = (attribute, where, operator = '$eq') => {
|
|
68
|
-
if (
|
|
27
|
+
if (isArray(where)) {
|
|
69
28
|
return where.map((sub) => processAttributeWhere(attribute, sub, operator));
|
|
70
29
|
}
|
|
71
30
|
|
|
72
|
-
if (!
|
|
73
|
-
if (
|
|
31
|
+
if (!isPlainObject(where)) {
|
|
32
|
+
if (isOperatorOfType('cast', operator)) {
|
|
74
33
|
return castValue(where, attribute);
|
|
75
34
|
}
|
|
76
35
|
|
|
@@ -82,7 +41,7 @@ const processAttributeWhere = (attribute, where, operator = '$eq') => {
|
|
|
82
41
|
for (const key of Object.keys(where)) {
|
|
83
42
|
const value = where[key];
|
|
84
43
|
|
|
85
|
-
if (!
|
|
44
|
+
if (!isOperatorOfType('where', key)) {
|
|
86
45
|
throw new Error(`Undefined attribute level operator ${key}`);
|
|
87
46
|
}
|
|
88
47
|
|
|
@@ -100,16 +59,16 @@ const processAttributeWhere = (attribute, where, operator = '$eq') => {
|
|
|
100
59
|
* @returns {Object}
|
|
101
60
|
*/
|
|
102
61
|
const processWhere = (where, ctx) => {
|
|
103
|
-
if (!
|
|
62
|
+
if (!isArray(where) && !isPlainObject(where)) {
|
|
104
63
|
throw new Error('Where must be an array or an object');
|
|
105
64
|
}
|
|
106
65
|
|
|
107
|
-
if (
|
|
66
|
+
if (isArray(where)) {
|
|
108
67
|
return where.map((sub) => processWhere(sub, ctx));
|
|
109
68
|
}
|
|
110
69
|
|
|
111
70
|
const processNested = (where, ctx) => {
|
|
112
|
-
if (!
|
|
71
|
+
if (!isPlainObject(where)) {
|
|
113
72
|
return where;
|
|
114
73
|
}
|
|
115
74
|
|
|
@@ -126,7 +85,7 @@ const processWhere = (where, ctx) => {
|
|
|
126
85
|
const value = where[key];
|
|
127
86
|
|
|
128
87
|
// if operator $and $or then loop over them
|
|
129
|
-
if (
|
|
88
|
+
if (isOperatorOfType('group', key)) {
|
|
130
89
|
filters[key] = value.map((sub) => processNested(sub, ctx));
|
|
131
90
|
continue;
|
|
132
91
|
}
|
|
@@ -136,7 +95,7 @@ const processWhere = (where, ctx) => {
|
|
|
136
95
|
continue;
|
|
137
96
|
}
|
|
138
97
|
|
|
139
|
-
if (
|
|
98
|
+
if (isOperatorOfType('where', key)) {
|
|
140
99
|
throw new Error(
|
|
141
100
|
`Only $and, $or and $not can only be used as root level operators. Found ${key}.`
|
|
142
101
|
);
|
|
@@ -165,7 +124,7 @@ const processWhere = (where, ctx) => {
|
|
|
165
124
|
uid: attribute.target,
|
|
166
125
|
});
|
|
167
126
|
|
|
168
|
-
if (!
|
|
127
|
+
if (!isPlainObject(nestedWhere) || isOperatorOfType('where', keys(nestedWhere)[0])) {
|
|
169
128
|
nestedWhere = { [qb.aliasColumn('id', subAlias)]: nestedWhere };
|
|
170
129
|
}
|
|
171
130
|
|
|
@@ -192,7 +151,7 @@ const processWhere = (where, ctx) => {
|
|
|
192
151
|
|
|
193
152
|
// TODO: add type casting per operator at some point
|
|
194
153
|
const applyOperator = (qb, column, operator, value) => {
|
|
195
|
-
if (Array.isArray(value) && !
|
|
154
|
+
if (Array.isArray(value) && !isOperatorOfType('array', operator)) {
|
|
196
155
|
return qb.where((subQB) => {
|
|
197
156
|
value.forEach((subValue) =>
|
|
198
157
|
subQB.orWhere((innerQB) => {
|
|
@@ -209,12 +168,12 @@ const applyOperator = (qb, column, operator, value) => {
|
|
|
209
168
|
}
|
|
210
169
|
|
|
211
170
|
case '$in': {
|
|
212
|
-
qb.whereIn(column, isKnexQuery(value) ? value :
|
|
171
|
+
qb.whereIn(column, isKnexQuery(value) ? value : castArray(value));
|
|
213
172
|
break;
|
|
214
173
|
}
|
|
215
174
|
|
|
216
175
|
case '$notIn': {
|
|
217
|
-
qb.whereNotIn(column, isKnexQuery(value) ? value :
|
|
176
|
+
qb.whereNotIn(column, isKnexQuery(value) ? value : castArray(value));
|
|
218
177
|
break;
|
|
219
178
|
}
|
|
220
179
|
|
|
@@ -328,7 +287,7 @@ const applyOperator = (qb, column, operator, value) => {
|
|
|
328
287
|
};
|
|
329
288
|
|
|
330
289
|
const applyWhereToColumn = (qb, column, columnWhere) => {
|
|
331
|
-
if (!
|
|
290
|
+
if (!isPlainObject(columnWhere)) {
|
|
332
291
|
if (Array.isArray(columnWhere)) {
|
|
333
292
|
return qb.whereIn(column, columnWhere);
|
|
334
293
|
}
|
|
@@ -344,11 +303,11 @@ const applyWhereToColumn = (qb, column, columnWhere) => {
|
|
|
344
303
|
};
|
|
345
304
|
|
|
346
305
|
const applyWhere = (qb, where) => {
|
|
347
|
-
if (!
|
|
306
|
+
if (!isArray(where) && !isPlainObject(where)) {
|
|
348
307
|
throw new Error('Where must be an array or an object');
|
|
349
308
|
}
|
|
350
309
|
|
|
351
|
-
if (
|
|
310
|
+
if (isArray(where)) {
|
|
352
311
|
return qb.where((subQB) => where.forEach((subWhere) => applyWhere(subQB, subWhere)));
|
|
353
312
|
}
|
|
354
313
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/database",
|
|
3
|
-
"version": "4.11.
|
|
3
|
+
"version": "4.11.1-beta.0",
|
|
4
4
|
"description": "Strapi's database layer",
|
|
5
5
|
"homepage": "https://strapi.io",
|
|
6
6
|
"bugs": {
|
|
@@ -33,17 +33,18 @@
|
|
|
33
33
|
"lint": "run -T eslint ."
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"@strapi/utils": "4.11.1-beta.0",
|
|
36
37
|
"date-fns": "2.30.0",
|
|
37
38
|
"debug": "4.3.4",
|
|
38
39
|
"fs-extra": "10.0.0",
|
|
39
40
|
"knex": "2.4.0",
|
|
40
41
|
"lodash": "4.17.21",
|
|
41
|
-
"semver": "7.
|
|
42
|
-
"umzug": "3.
|
|
42
|
+
"semver": "7.5.1",
|
|
43
|
+
"umzug": "3.2.1"
|
|
43
44
|
},
|
|
44
45
|
"engines": {
|
|
45
46
|
"node": ">=14.19.1 <=18.x.x",
|
|
46
47
|
"npm": ">=6.0.0"
|
|
47
48
|
},
|
|
48
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "30e56b8376b9cb52c39ecd1c3b7d8706688a1685"
|
|
49
50
|
}
|