spice-js 2.6.15 → 2.6.17
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 +24 -9
- package/package.json +1 -1
- package/src/models/SpiceModel.js +21 -7
|
@@ -847,11 +847,13 @@ class SpiceModel {
|
|
|
847
847
|
if (column == "meta().id") {
|
|
848
848
|
column = undefined;
|
|
849
849
|
} else if (!column.startsWith("`") && !column.endsWith("`")) {
|
|
850
|
+
"`" + column + "`";
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
if (column) {
|
|
850
854
|
if (!column.includes(".") && !column.startsWith(that.type)) {
|
|
851
|
-
column = "`" + that.type + "
|
|
855
|
+
column = "`" + that.type + "`." + column;
|
|
852
856
|
}
|
|
853
|
-
|
|
854
|
-
return column;
|
|
855
857
|
}
|
|
856
858
|
|
|
857
859
|
return column;
|
|
@@ -868,7 +870,10 @@ class SpiceModel {
|
|
|
868
870
|
if (columns && columns != "") {
|
|
869
871
|
columns = columns.replace(/`/g, "");
|
|
870
872
|
columns = columns.replace(/meta\(\)\.id/g, "id");
|
|
871
|
-
var columnList = columns.split(",")
|
|
873
|
+
var columnList = columns.split(",").map(column => {
|
|
874
|
+
//if colums has a . then remove the first part of the string
|
|
875
|
+
return column.includes(".") ? _.last(column.split(".")) : column;
|
|
876
|
+
}); // Convert comma-separated string to array
|
|
872
877
|
|
|
873
878
|
columnList.push("_permissions"); // Always include _permissions
|
|
874
879
|
|
|
@@ -894,7 +899,7 @@ class SpiceModel {
|
|
|
894
899
|
|
|
895
900
|
var nestings = [...extractNestings((_args4 = args) == null ? void 0 : _args4.query, _this11.type), ...extractNestings((_args5 = args) == null ? void 0 : _args5.columns, _this11.type), ...extractNestings((_args6 = args) == null ? void 0 : _args6.sort, _this11.type)];
|
|
896
901
|
|
|
897
|
-
var mappedNestings = _.compact(_.map(nestings, nesting => {
|
|
902
|
+
var mappedNestings = _.compact(_.map(_.uniq(nestings), nesting => {
|
|
898
903
|
var prop = _this11.props[nesting];
|
|
899
904
|
|
|
900
905
|
if (prop) {
|
|
@@ -953,6 +958,20 @@ class SpiceModel {
|
|
|
953
958
|
|
|
954
959
|
if (!args.sort) {
|
|
955
960
|
args.sort = "`" + _this11.type + "`.created_at DESC";
|
|
961
|
+
} else {
|
|
962
|
+
var sort_array = args.sort.split(","); // check the first string in each item in the array to see if it contains a . if not then add the type
|
|
963
|
+
|
|
964
|
+
var new_sort_array = [];
|
|
965
|
+
|
|
966
|
+
for (var i = 0; i < sort_array.length; i++) {
|
|
967
|
+
if (!sort_array[i].includes(".")) {
|
|
968
|
+
new_sort_array.push("`" + _this11.type + "`.`" + sort_array[i] + "`");
|
|
969
|
+
} else {
|
|
970
|
+
new_sort_array.push(sort_array[i]);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
args.sort = _.join(new_sort_array, ",");
|
|
956
975
|
}
|
|
957
976
|
|
|
958
977
|
if (args.skip_hooks != true) {
|
|
@@ -1019,10 +1038,6 @@ class SpiceModel {
|
|
|
1019
1038
|
}
|
|
1020
1039
|
} else {
|
|
1021
1040
|
results = yield _this11.database.search(_this11.type, args.columns || "", query || "", args.limit, args.offset, args.sort, args.do_count, args.statement_consistent, args._join);
|
|
1022
|
-
|
|
1023
|
-
if (_this11.type == "user") {
|
|
1024
|
-
console.log("results from DB No Chache available", results);
|
|
1025
|
-
}
|
|
1026
1041
|
}
|
|
1027
1042
|
}
|
|
1028
1043
|
}
|
package/package.json
CHANGED
package/src/models/SpiceModel.js
CHANGED
|
@@ -752,10 +752,12 @@ export default class SpiceModel {
|
|
|
752
752
|
if (column == "meta().id") {
|
|
753
753
|
column = undefined;
|
|
754
754
|
} else if (!column.startsWith("`") && !column.endsWith("`")) {
|
|
755
|
+
`\`${column}\``;
|
|
756
|
+
}
|
|
757
|
+
if (column) {
|
|
755
758
|
if (!column.includes(".") && !column.startsWith(that.type)) {
|
|
756
|
-
column = `\`${that.type}
|
|
759
|
+
column = `\`${that.type}\`.${column}`;
|
|
757
760
|
}
|
|
758
|
-
return column;
|
|
759
761
|
}
|
|
760
762
|
return column;
|
|
761
763
|
})
|
|
@@ -772,7 +774,10 @@ export default class SpiceModel {
|
|
|
772
774
|
if (columns && columns != "") {
|
|
773
775
|
columns = columns.replace(/`/g, "");
|
|
774
776
|
columns = columns.replace(/meta\(\)\.id/g, "id");
|
|
775
|
-
let columnList = columns.split(",")
|
|
777
|
+
let columnList = columns.split(",").map((column) => {
|
|
778
|
+
//if colums has a . then remove the first part of the string
|
|
779
|
+
return column.includes(".") ? _.last(column.split(".")) : column;
|
|
780
|
+
}); // Convert comma-separated string to array
|
|
776
781
|
columnList.push("_permissions"); // Always include _permissions
|
|
777
782
|
columnList.push("id"); // Always include _permissions
|
|
778
783
|
return _.map(data, (entry) => _.pick(entry, columnList));
|
|
@@ -795,7 +800,7 @@ export default class SpiceModel {
|
|
|
795
800
|
...extractNestings(args?.sort, this.type),
|
|
796
801
|
];
|
|
797
802
|
let mappedNestings = _.compact(
|
|
798
|
-
_.map(nestings, (nesting) => {
|
|
803
|
+
_.map(_.uniq(nestings), (nesting) => {
|
|
799
804
|
let prop = this.props[nesting];
|
|
800
805
|
if (prop) {
|
|
801
806
|
if (prop.map) {
|
|
@@ -853,6 +858,18 @@ export default class SpiceModel {
|
|
|
853
858
|
|
|
854
859
|
if (!args.sort) {
|
|
855
860
|
args.sort = `\`${this.type}\`.created_at DESC`;
|
|
861
|
+
} else {
|
|
862
|
+
let sort_array = args.sort.split(",");
|
|
863
|
+
// check the first string in each item in the array to see if it contains a . if not then add the type
|
|
864
|
+
let new_sort_array = [];
|
|
865
|
+
for (let i = 0; i < sort_array.length; i++) {
|
|
866
|
+
if (!sort_array[i].includes(".")) {
|
|
867
|
+
new_sort_array.push(`\`${this.type}\`.\`${sort_array[i]}\``);
|
|
868
|
+
} else {
|
|
869
|
+
new_sort_array.push(sort_array[i]);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
args.sort = _.join(new_sort_array, ",");
|
|
856
873
|
}
|
|
857
874
|
if (args.skip_hooks != true) {
|
|
858
875
|
await this.run_hook(this, "list", "before");
|
|
@@ -959,9 +976,6 @@ export default class SpiceModel {
|
|
|
959
976
|
args.statement_consistent,
|
|
960
977
|
args._join
|
|
961
978
|
);
|
|
962
|
-
if (this.type == "user") {
|
|
963
|
-
console.log("results from DB No Chache available", results);
|
|
964
|
-
}
|
|
965
979
|
}
|
|
966
980
|
}
|
|
967
981
|
}
|