spice-js 2.6.52 → 2.6.53
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/package.json +1 -1
- package/src/models/SpiceModel.js +18 -13
package/package.json
CHANGED
package/src/models/SpiceModel.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import { MapType, DataType } from "..";
|
|
4
4
|
let co = require("co");
|
|
5
5
|
var regeneratorRuntime = require("regenerator-runtime");
|
|
@@ -19,9 +19,11 @@ var SDate = require("sonover-date"),
|
|
|
19
19
|
_external_modifier_loaded = Symbol(),
|
|
20
20
|
_skip_cache = Symbol(),
|
|
21
21
|
_serializers = Symbol(),
|
|
22
|
-
_level = Symbol()
|
|
22
|
+
_level = Symbol(),
|
|
23
|
+
_mapping_dept = Symbol();
|
|
23
24
|
|
|
24
25
|
//const _type = Symbol("type");
|
|
26
|
+
|
|
25
27
|
let that;
|
|
26
28
|
if (!Promise.allSettled) {
|
|
27
29
|
Promise.allSettled = (promises) =>
|
|
@@ -45,6 +47,7 @@ export default class SpiceModel {
|
|
|
45
47
|
var dbtype =
|
|
46
48
|
spice.config.database.connections[args.connection].type || "couchbase";
|
|
47
49
|
let Database = require(`spice-${dbtype}`);
|
|
50
|
+
this[_mapping_dept] = args?.args?.mapping_dept || 100;
|
|
48
51
|
this.type = "";
|
|
49
52
|
this.collection = args.connection;
|
|
50
53
|
this[_args] = args.args;
|
|
@@ -476,9 +479,7 @@ export default class SpiceModel {
|
|
|
476
479
|
|
|
477
480
|
async get(args) {
|
|
478
481
|
try {
|
|
479
|
-
|
|
480
|
-
? Number(args.mapping_dept)
|
|
481
|
-
: global.mapping_dept;
|
|
482
|
+
if (args.mapping_dept) this[_mapping_dept] = args.mapping_dept;
|
|
482
483
|
|
|
483
484
|
if (!args) {
|
|
484
485
|
args = {};
|
|
@@ -876,9 +877,13 @@ export default class SpiceModel {
|
|
|
876
877
|
nesting.type === Array ||
|
|
877
878
|
nesting.type === "array"
|
|
878
879
|
) {
|
|
879
|
-
return `LEFT NEST \`${fixCollection(nesting.reference)}\` AS \`${
|
|
880
|
+
return `LEFT NEST \`${fixCollection(nesting.reference)}\` AS \`${
|
|
881
|
+
nesting.alias
|
|
882
|
+
}\` ON KEYS \`${this.type}\`.\`${nesting.alias}\``;
|
|
880
883
|
} else {
|
|
881
|
-
return `LEFT JOIN \`${fixCollection(nesting.reference)}\` AS \`${
|
|
884
|
+
return `LEFT JOIN \`${fixCollection(nesting.reference)}\` AS \`${
|
|
885
|
+
nesting.alias
|
|
886
|
+
}\` ON KEYS \`${this.type}\`.\`${nesting.alias}\``;
|
|
882
887
|
}
|
|
883
888
|
})
|
|
884
889
|
.join(" ");
|
|
@@ -897,6 +902,7 @@ export default class SpiceModel {
|
|
|
897
902
|
async list(args = {}) {
|
|
898
903
|
try {
|
|
899
904
|
args.columns = this.prepColumns(args.columns);
|
|
905
|
+
if (args.mapping_dept) this[_mapping_dept] = args.mapping_dept;
|
|
900
906
|
|
|
901
907
|
const nestings = [
|
|
902
908
|
...this.extractNestings(args?.query, this.type),
|
|
@@ -937,9 +943,6 @@ export default class SpiceModel {
|
|
|
937
943
|
|
|
938
944
|
args.limit = Number(args.limit) || undefined;
|
|
939
945
|
args.offset = Number(args.offset) || 0;
|
|
940
|
-
global.mapping_dept = args?.mapping_dept
|
|
941
|
-
? Number(args.mapping_dept)
|
|
942
|
-
: global.mapping_dept;
|
|
943
946
|
args.sort = args.sort
|
|
944
947
|
? args.sort
|
|
945
948
|
.split(",")
|
|
@@ -1080,8 +1083,9 @@ export default class SpiceModel {
|
|
|
1080
1083
|
if (!original_is_array) {
|
|
1081
1084
|
data = Array.of(data);
|
|
1082
1085
|
}
|
|
1086
|
+
this[_mapping_dept];
|
|
1083
1087
|
|
|
1084
|
-
if (this[_level]
|
|
1088
|
+
if (this[_level] + 1 < this[_mapping_dept]) {
|
|
1085
1089
|
let classes = _.isArray(Class) ? Class : [Class];
|
|
1086
1090
|
|
|
1087
1091
|
let ids = [];
|
|
@@ -1100,6 +1104,7 @@ export default class SpiceModel {
|
|
|
1100
1104
|
...this[_args],
|
|
1101
1105
|
skip_cache: this[_skip_cache],
|
|
1102
1106
|
_level: this[_level] + 1,
|
|
1107
|
+
mapping_dept: this[_mapping_dept],
|
|
1103
1108
|
}).getMulti({
|
|
1104
1109
|
skip_hooks: true,
|
|
1105
1110
|
ids: ids,
|
|
@@ -1137,8 +1142,7 @@ export default class SpiceModel {
|
|
|
1137
1142
|
if (!original_is_array) {
|
|
1138
1143
|
data = Array.of(data);
|
|
1139
1144
|
}
|
|
1140
|
-
|
|
1141
|
-
if (this[_level] < global.mapping_dept || global.mapping_dept == "*") {
|
|
1145
|
+
if (this[_level] + 1 < this[_mapping_dept]) {
|
|
1142
1146
|
let ids = [];
|
|
1143
1147
|
_.each(data, (result) => {
|
|
1144
1148
|
let value = [];
|
|
@@ -1162,6 +1166,7 @@ export default class SpiceModel {
|
|
|
1162
1166
|
...this[_args],
|
|
1163
1167
|
skip_cache: this[_skip_cache],
|
|
1164
1168
|
_level: this[_level] + 1,
|
|
1169
|
+
mapping_dept: this[_mapping_dept],
|
|
1165
1170
|
}).getMulti({
|
|
1166
1171
|
skip_hooks: true,
|
|
1167
1172
|
ids: ids,
|