spice-js 2.6.52 → 2.6.54
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/build/models/SpiceModel.js +18 -16
- package/package.json +1 -1
- package/src/models/SpiceModel.js +18 -13
|
@@ -19,8 +19,6 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
19
19
|
|
|
20
20
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
21
21
|
|
|
22
|
-
global.mapping_dept = "*";
|
|
23
|
-
|
|
24
22
|
var co = require("co");
|
|
25
23
|
|
|
26
24
|
var regeneratorRuntime = require("regenerator-runtime");
|
|
@@ -37,7 +35,8 @@ var SDate = require("sonover-date"),
|
|
|
37
35
|
_external_modifier_loaded = Symbol(),
|
|
38
36
|
_skip_cache = Symbol(),
|
|
39
37
|
_serializers = Symbol(),
|
|
40
|
-
_level = Symbol()
|
|
38
|
+
_level = Symbol(),
|
|
39
|
+
_mapping_dept = Symbol(); //const _type = Symbol("type");
|
|
41
40
|
|
|
42
41
|
|
|
43
42
|
var that;
|
|
@@ -59,20 +58,21 @@ class SpiceModel {
|
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
try {
|
|
62
|
-
var
|
|
61
|
+
var _args2, _args2$args, _args$args, _args3, _args3$args, _args4, _args4$args, _args5, _args5$args;
|
|
63
62
|
|
|
64
63
|
var dbtype = spice.config.database.connections[args.connection].type || "couchbase";
|
|
65
64
|
|
|
66
65
|
var Database = require("spice-" + dbtype);
|
|
67
66
|
|
|
67
|
+
this[_mapping_dept] = ((_args2 = args) == null ? void 0 : (_args2$args = _args2.args) == null ? void 0 : _args2$args.mapping_dept) || 100;
|
|
68
68
|
this.type = "";
|
|
69
69
|
this.collection = args.connection;
|
|
70
70
|
this[_args] = args.args;
|
|
71
71
|
this[_external_modifier_loaded] = false;
|
|
72
72
|
this[_disable_lifecycle_events] = ((_args$args = args.args) == null ? void 0 : _args$args.disable_lifecycle_events) || false;
|
|
73
|
-
this[_ctx] = (
|
|
74
|
-
this[_skip_cache] = ((
|
|
75
|
-
this[_level] = ((
|
|
73
|
+
this[_ctx] = (_args3 = args) == null ? void 0 : (_args3$args = _args3.args) == null ? void 0 : _args3$args.ctx;
|
|
74
|
+
this[_skip_cache] = ((_args4 = args) == null ? void 0 : (_args4$args = _args4.args) == null ? void 0 : _args4$args.skip_cache) || false;
|
|
75
|
+
this[_level] = ((_args5 = args) == null ? void 0 : (_args5$args = _args5.args) == null ? void 0 : _args5$args._level) || 0;
|
|
76
76
|
this[_hooks] = {
|
|
77
77
|
create: {
|
|
78
78
|
before: [],
|
|
@@ -566,9 +566,7 @@ class SpiceModel {
|
|
|
566
566
|
|
|
567
567
|
return _asyncToGenerator(function* () {
|
|
568
568
|
try {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
global.mapping_dept = ((_args5 = args) == null ? void 0 : _args5.mapping_dept) ? Number(args.mapping_dept) : global.mapping_dept;
|
|
569
|
+
if (args.mapping_dept) _this4[_mapping_dept] = args.mapping_dept;
|
|
572
570
|
|
|
573
571
|
if (!args) {
|
|
574
572
|
args = {};
|
|
@@ -993,9 +991,10 @@ class SpiceModel {
|
|
|
993
991
|
}
|
|
994
992
|
|
|
995
993
|
try {
|
|
996
|
-
var _args6, _args7, _args8
|
|
994
|
+
var _args6, _args7, _args8;
|
|
997
995
|
|
|
998
996
|
args.columns = _this12.prepColumns(args.columns);
|
|
997
|
+
if (args.mapping_dept) _this12[_mapping_dept] = args.mapping_dept;
|
|
999
998
|
var nestings = [..._this12.extractNestings((_args6 = args) == null ? void 0 : _args6.query, _this12.type), ..._this12.extractNestings((_args7 = args) == null ? void 0 : _args7.columns, _this12.type), ..._this12.extractNestings((_args8 = args) == null ? void 0 : _args8.sort, _this12.type)];
|
|
1000
999
|
|
|
1001
1000
|
var mappedNestings = _.compact(_.uniq(nestings).map(nesting => {
|
|
@@ -1028,7 +1027,6 @@ class SpiceModel {
|
|
|
1028
1027
|
|
|
1029
1028
|
args.limit = Number(args.limit) || undefined;
|
|
1030
1029
|
args.offset = Number(args.offset) || 0;
|
|
1031
|
-
global.mapping_dept = ((_args9 = args) == null ? void 0 : _args9.mapping_dept) ? Number(args.mapping_dept) : global.mapping_dept;
|
|
1032
1030
|
args.sort = args.sort ? args.sort.split(",").map(item => item.includes(".") ? item : "`" + _this12.type + "`." + _this12.formatSortComponent(item)).join(",") : "`" + _this12.type + "`.created_at DESC";
|
|
1033
1031
|
|
|
1034
1032
|
if (args.skip_hooks !== true) {
|
|
@@ -1158,7 +1156,9 @@ class SpiceModel {
|
|
|
1158
1156
|
data = Array.of(data);
|
|
1159
1157
|
}
|
|
1160
1158
|
|
|
1161
|
-
|
|
1159
|
+
_this15[_mapping_dept];
|
|
1160
|
+
|
|
1161
|
+
if (_this15[_level] + 1 < _this15[_mapping_dept]) {
|
|
1162
1162
|
var classes = _.isArray(Class) ? Class : [Class];
|
|
1163
1163
|
var ids = [];
|
|
1164
1164
|
|
|
@@ -1171,7 +1171,8 @@ class SpiceModel {
|
|
|
1171
1171
|
var returned_all = yield Promise.allSettled(_.map(classes, obj => {
|
|
1172
1172
|
return new obj(_extends({}, _this15[_args], {
|
|
1173
1173
|
skip_cache: _this15[_skip_cache],
|
|
1174
|
-
_level: _this15[_level] + 1
|
|
1174
|
+
_level: _this15[_level] + 1,
|
|
1175
|
+
mapping_dept: _this15[_mapping_dept]
|
|
1175
1176
|
})).getMulti({
|
|
1176
1177
|
skip_hooks: true,
|
|
1177
1178
|
ids: ids
|
|
@@ -1205,7 +1206,7 @@ class SpiceModel {
|
|
|
1205
1206
|
data = Array.of(data);
|
|
1206
1207
|
}
|
|
1207
1208
|
|
|
1208
|
-
if (_this16[_level]
|
|
1209
|
+
if (_this16[_level] + 1 < _this16[_mapping_dept]) {
|
|
1209
1210
|
var ids = [];
|
|
1210
1211
|
|
|
1211
1212
|
_.each(data, result => {
|
|
@@ -1228,7 +1229,8 @@ class SpiceModel {
|
|
|
1228
1229
|
var returned_all = yield Promise.allSettled(_.map(classes, obj => {
|
|
1229
1230
|
return new obj(_extends({}, _this16[_args], {
|
|
1230
1231
|
skip_cache: _this16[_skip_cache],
|
|
1231
|
-
_level: _this16[_level] + 1
|
|
1232
|
+
_level: _this16[_level] + 1,
|
|
1233
|
+
mapping_dept: _this16[_mapping_dept]
|
|
1232
1234
|
})).getMulti({
|
|
1233
1235
|
skip_hooks: true,
|
|
1234
1236
|
ids: ids
|
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,
|