@opra/mongodb 1.7.4 → 1.9.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.
|
@@ -52,7 +52,9 @@ class MongoPatchGenerator {
|
|
|
52
52
|
field = dataType.findField(key, scope);
|
|
53
53
|
if (field && !field.inScope(scope))
|
|
54
54
|
continue;
|
|
55
|
+
/** Field not found */
|
|
55
56
|
if (!field) {
|
|
57
|
+
/** Additional fields will be updated */
|
|
56
58
|
if (dataType.additionalFields) {
|
|
57
59
|
if (value === null) {
|
|
58
60
|
ctx.$unset = ctx.$unset || {};
|
|
@@ -74,7 +76,7 @@ class MongoPatchGenerator {
|
|
|
74
76
|
}
|
|
75
77
|
continue;
|
|
76
78
|
}
|
|
77
|
-
|
|
79
|
+
/** Unset field value if null */
|
|
78
80
|
if (value === null) {
|
|
79
81
|
ctx.$unset = ctx.$unset || {};
|
|
80
82
|
ctx.$unset[pathDot + field.name] = 1;
|
|
@@ -85,42 +87,46 @@ class MongoPatchGenerator {
|
|
|
85
87
|
if (!value)
|
|
86
88
|
continue;
|
|
87
89
|
if (field.isArray) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
90
|
+
if (field.isNestedEntity) {
|
|
91
|
+
ctx.initArrayFields = ctx.initArrayFields || [];
|
|
92
|
+
ctx.initArrayFields.push(pathDot + field.name);
|
|
93
|
+
if (!value.length)
|
|
94
|
+
continue;
|
|
95
|
+
keyField = field.keyField || field.type.keyField;
|
|
96
|
+
if (keyField) {
|
|
97
|
+
for (let v of value) {
|
|
98
|
+
/** Increase arrayIndex and determine a new name for array filter */
|
|
99
|
+
arrayFilterName = 'f' + String(++arrayIndex);
|
|
100
|
+
/** Extract key value from object */
|
|
101
|
+
keyValue = v[keyField];
|
|
102
|
+
if (keyValue == null)
|
|
103
|
+
continue;
|
|
104
|
+
v = { ...v };
|
|
105
|
+
/** Remove key field from object */
|
|
106
|
+
delete v[keyField];
|
|
107
|
+
/** Process each object in array */
|
|
108
|
+
if (this._processComplexType(ctx, field.type, pathDot + field.name + `.$[${arrayFilterName}]`, v, scope)) {
|
|
109
|
+
result = true;
|
|
110
|
+
/** Add array filter */
|
|
111
|
+
ctx.arrayFilters = ctx.arrayFilters || [];
|
|
112
|
+
ctx.arrayFilters.unshift({
|
|
113
|
+
[`${arrayFilterName}.${keyField}`]: keyValue,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
112
116
|
}
|
|
117
|
+
continue;
|
|
113
118
|
}
|
|
114
|
-
continue;
|
|
115
119
|
}
|
|
116
120
|
}
|
|
117
|
-
|
|
121
|
+
else {
|
|
122
|
+
if (!(typeof value === 'object'))
|
|
123
|
+
continue;
|
|
124
|
+
/** Process nested object */
|
|
125
|
+
if (this._processComplexType(ctx, field.type, pathDot + field.name, value, scope)) {
|
|
126
|
+
result = true;
|
|
127
|
+
}
|
|
118
128
|
continue;
|
|
119
|
-
/** Process nested object */
|
|
120
|
-
if (this._processComplexType(ctx, field.type, pathDot + field.name, value, scope)) {
|
|
121
|
-
result = true;
|
|
122
129
|
}
|
|
123
|
-
continue;
|
|
124
130
|
}
|
|
125
131
|
ctx.$set = ctx.$set || {};
|
|
126
132
|
ctx.$set[pathDot + field.name] = value;
|
|
@@ -88,12 +88,7 @@ function prepareFilterAst(ast, negative) {
|
|
|
88
88
|
if (!ast)
|
|
89
89
|
return;
|
|
90
90
|
if (ast instanceof common_1.OpraFilter.QualifiedIdentifier ||
|
|
91
|
-
ast instanceof common_1.OpraFilter.
|
|
92
|
-
ast instanceof common_1.OpraFilter.StringLiteral ||
|
|
93
|
-
ast instanceof common_1.OpraFilter.BooleanLiteral ||
|
|
94
|
-
ast instanceof common_1.OpraFilter.NullLiteral ||
|
|
95
|
-
ast instanceof common_1.OpraFilter.DateLiteral ||
|
|
96
|
-
ast instanceof common_1.OpraFilter.TimeLiteral) {
|
|
91
|
+
ast instanceof common_1.OpraFilter.Literal) {
|
|
97
92
|
return ast.value;
|
|
98
93
|
}
|
|
99
94
|
if (ast instanceof common_1.OpraFilter.ArrayExpression) {
|
|
@@ -49,7 +49,9 @@ export class MongoPatchGenerator {
|
|
|
49
49
|
field = dataType.findField(key, scope);
|
|
50
50
|
if (field && !field.inScope(scope))
|
|
51
51
|
continue;
|
|
52
|
+
/** Field not found */
|
|
52
53
|
if (!field) {
|
|
54
|
+
/** Additional fields will be updated */
|
|
53
55
|
if (dataType.additionalFields) {
|
|
54
56
|
if (value === null) {
|
|
55
57
|
ctx.$unset = ctx.$unset || {};
|
|
@@ -71,7 +73,7 @@ export class MongoPatchGenerator {
|
|
|
71
73
|
}
|
|
72
74
|
continue;
|
|
73
75
|
}
|
|
74
|
-
|
|
76
|
+
/** Unset field value if null */
|
|
75
77
|
if (value === null) {
|
|
76
78
|
ctx.$unset = ctx.$unset || {};
|
|
77
79
|
ctx.$unset[pathDot + field.name] = 1;
|
|
@@ -82,42 +84,46 @@ export class MongoPatchGenerator {
|
|
|
82
84
|
if (!value)
|
|
83
85
|
continue;
|
|
84
86
|
if (field.isArray) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
87
|
+
if (field.isNestedEntity) {
|
|
88
|
+
ctx.initArrayFields = ctx.initArrayFields || [];
|
|
89
|
+
ctx.initArrayFields.push(pathDot + field.name);
|
|
90
|
+
if (!value.length)
|
|
91
|
+
continue;
|
|
92
|
+
keyField = field.keyField || field.type.keyField;
|
|
93
|
+
if (keyField) {
|
|
94
|
+
for (let v of value) {
|
|
95
|
+
/** Increase arrayIndex and determine a new name for array filter */
|
|
96
|
+
arrayFilterName = 'f' + String(++arrayIndex);
|
|
97
|
+
/** Extract key value from object */
|
|
98
|
+
keyValue = v[keyField];
|
|
99
|
+
if (keyValue == null)
|
|
100
|
+
continue;
|
|
101
|
+
v = { ...v };
|
|
102
|
+
/** Remove key field from object */
|
|
103
|
+
delete v[keyField];
|
|
104
|
+
/** Process each object in array */
|
|
105
|
+
if (this._processComplexType(ctx, field.type, pathDot + field.name + `.$[${arrayFilterName}]`, v, scope)) {
|
|
106
|
+
result = true;
|
|
107
|
+
/** Add array filter */
|
|
108
|
+
ctx.arrayFilters = ctx.arrayFilters || [];
|
|
109
|
+
ctx.arrayFilters.unshift({
|
|
110
|
+
[`${arrayFilterName}.${keyField}`]: keyValue,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
109
113
|
}
|
|
114
|
+
continue;
|
|
110
115
|
}
|
|
111
|
-
continue;
|
|
112
116
|
}
|
|
113
117
|
}
|
|
114
|
-
|
|
118
|
+
else {
|
|
119
|
+
if (!(typeof value === 'object'))
|
|
120
|
+
continue;
|
|
121
|
+
/** Process nested object */
|
|
122
|
+
if (this._processComplexType(ctx, field.type, pathDot + field.name, value, scope)) {
|
|
123
|
+
result = true;
|
|
124
|
+
}
|
|
115
125
|
continue;
|
|
116
|
-
/** Process nested object */
|
|
117
|
-
if (this._processComplexType(ctx, field.type, pathDot + field.name, value, scope)) {
|
|
118
|
-
result = true;
|
|
119
126
|
}
|
|
120
|
-
continue;
|
|
121
127
|
}
|
|
122
128
|
ctx.$set = ctx.$set || {};
|
|
123
129
|
ctx.$set[pathDot + field.name] = value;
|
|
@@ -85,12 +85,7 @@ function prepareFilterAst(ast, negative) {
|
|
|
85
85
|
if (!ast)
|
|
86
86
|
return;
|
|
87
87
|
if (ast instanceof OpraFilter.QualifiedIdentifier ||
|
|
88
|
-
ast instanceof OpraFilter.
|
|
89
|
-
ast instanceof OpraFilter.StringLiteral ||
|
|
90
|
-
ast instanceof OpraFilter.BooleanLiteral ||
|
|
91
|
-
ast instanceof OpraFilter.NullLiteral ||
|
|
92
|
-
ast instanceof OpraFilter.DateLiteral ||
|
|
93
|
-
ast instanceof OpraFilter.TimeLiteral) {
|
|
88
|
+
ast instanceof OpraFilter.Literal) {
|
|
94
89
|
return ast.value;
|
|
95
90
|
}
|
|
96
91
|
if (ast instanceof OpraFilter.ArrayExpression) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/mongodb",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Opra MongoDB adapter package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"valgen": "^5.12.0"
|
|
11
11
|
},
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"@opra/common": "^1.
|
|
14
|
-
"@opra/core": "^1.
|
|
15
|
-
"@opra/http": "^1.
|
|
13
|
+
"@opra/common": "^1.9.0",
|
|
14
|
+
"@opra/core": "^1.9.0",
|
|
15
|
+
"@opra/http": "^1.9.0",
|
|
16
16
|
"mongodb": "^6.0.0"
|
|
17
17
|
},
|
|
18
18
|
"type": "module",
|