spice-js 2.6.14 → 2.6.16

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.
@@ -833,12 +833,37 @@ class SpiceModel {
833
833
 
834
834
  return _asyncToGenerator(function* () {
835
835
  try {
836
- var _args4;
836
+ var _args4, _args5, _args6;
837
837
 
838
838
  if (!args) {
839
839
  args = {};
840
840
  }
841
841
 
842
+ function prepColumns(columns) {
843
+ if (columns && columns != "") {
844
+ var columnList = columns.split(","); // Convert comma-separated string to array
845
+
846
+ return _.join(_.compact(_.map(columnList, column => {
847
+ if (column == "meta().id") {
848
+ column = undefined;
849
+ } else if (!column.startsWith("`") && !column.endsWith("`")) {
850
+ if (!column.includes(".") && !column.startsWith(that.type)) {
851
+ column = "`" + that.type + "`.`" + column + "`";
852
+ }
853
+
854
+ return column;
855
+ }
856
+
857
+ return column;
858
+ })), ",");
859
+ }
860
+
861
+ return columns;
862
+ }
863
+
864
+ var query = "";
865
+ args.columns = prepColumns(args.columns);
866
+
842
867
  function filterResultsByColumns(data, columns) {
843
868
  if (columns && columns != "") {
844
869
  columns = columns.replace(/`/g, "");
@@ -867,7 +892,7 @@ class SpiceModel {
867
892
  return returnVal;
868
893
  }
869
894
 
870
- var nestings = extractNestings((_args4 = args) == null ? void 0 : _args4.query, _this11.type);
895
+ 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)];
871
896
 
872
897
  var mappedNestings = _.compact(_.map(nestings, nesting => {
873
898
  var prop = _this11.props[nesting];
@@ -900,27 +925,6 @@ class SpiceModel {
900
925
 
901
926
  args._join = _join;
902
927
 
903
- function prepColumns(columns) {
904
- if (columns && columns != "") {
905
- var columnList = columns.split(","); // Convert comma-separated string to array
906
-
907
- return _.join(_.compact(_.map(columnList, column => {
908
- if (column == "meta().id") {
909
- column = undefined;
910
- } else if (!column.startsWith("`") && !column.endsWith("`")) {
911
- return "`" + column + "`";
912
- }
913
-
914
- return column;
915
- })), ",");
916
- }
917
-
918
- return columns;
919
- }
920
-
921
- var query = "";
922
- args.columns = prepColumns(args.columns);
923
-
924
928
  if (args.is_full_text && args.is_full_text === "true" || args.is_custom_query && args.is_custom_query === "true") {
925
929
  query = args.query;
926
930
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-js",
3
- "version": "2.6.14",
3
+ "version": "2.6.16",
4
4
  "description": "spice",
5
5
  "main": "build/index.js",
6
6
  "repository": {
@@ -743,11 +743,41 @@ export default class SpiceModel {
743
743
  args = {};
744
744
  }
745
745
 
746
+ function prepColumns(columns) {
747
+ if (columns && columns != "") {
748
+ let columnList = columns.split(","); // Convert comma-separated string to array
749
+ return _.join(
750
+ _.compact(
751
+ _.map(columnList, (column) => {
752
+ if (column == "meta().id") {
753
+ column = undefined;
754
+ } else if (!column.startsWith("`") && !column.endsWith("`")) {
755
+ `\`${column}\``;
756
+ }
757
+ if (column) {
758
+ if (!column.includes(".") && !column.startsWith(that.type)) {
759
+ column = `\`${that.type}\`.${column}`;
760
+ }
761
+ }
762
+ return column;
763
+ })
764
+ ),
765
+ ","
766
+ );
767
+ }
768
+ return columns;
769
+ }
770
+
771
+ let query = "";
772
+ args.columns = prepColumns(args.columns);
746
773
  function filterResultsByColumns(data, columns) {
747
774
  if (columns && columns != "") {
748
775
  columns = columns.replace(/`/g, "");
749
776
  columns = columns.replace(/meta\(\)\.id/g, "id");
750
- let columnList = columns.split(","); // Convert comma-separated string to array
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
751
781
  columnList.push("_permissions"); // Always include _permissions
752
782
  columnList.push("id"); // Always include _permissions
753
783
  return _.map(data, (entry) => _.pick(entry, columnList));
@@ -764,9 +794,13 @@ export default class SpiceModel {
764
794
  return returnVal;
765
795
  }
766
796
 
767
- let nestings = extractNestings(args?.query, this.type);
797
+ let nestings = [
798
+ ...extractNestings(args?.query, this.type),
799
+ ...extractNestings(args?.columns, this.type),
800
+ ...extractNestings(args?.sort, this.type),
801
+ ];
768
802
  let mappedNestings = _.compact(
769
- _.map(nestings, (nesting) => {
803
+ _.map(_.uniq(nestings), (nesting) => {
770
804
  let prop = this.props[nesting];
771
805
  if (prop) {
772
806
  if (prop.map) {
@@ -793,28 +827,6 @@ export default class SpiceModel {
793
827
  let _join = createJoinSection(mappedNestings);
794
828
  args._join = _join;
795
829
 
796
- function prepColumns(columns) {
797
- if (columns && columns != "") {
798
- let columnList = columns.split(","); // Convert comma-separated string to array
799
- return _.join(
800
- _.compact(
801
- _.map(columnList, (column) => {
802
- if (column == "meta().id") {
803
- column = undefined;
804
- } else if (!column.startsWith("`") && !column.endsWith("`")) {
805
- return `\`${column}\``;
806
- }
807
- return column;
808
- })
809
- ),
810
- ","
811
- );
812
- }
813
- return columns;
814
- }
815
-
816
- let query = "";
817
- args.columns = prepColumns(args.columns);
818
830
  if (
819
831
  (args.is_full_text && args.is_full_text === "true") ||
820
832
  (args.is_custom_query && args.is_custom_query === "true")
@@ -846,6 +858,18 @@ export default class SpiceModel {
846
858
 
847
859
  if (!args.sort) {
848
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, ",");
849
873
  }
850
874
  if (args.skip_hooks != true) {
851
875
  await this.run_hook(this, "list", "before");
@@ -952,9 +976,6 @@ export default class SpiceModel {
952
976
  args.statement_consistent,
953
977
  args._join
954
978
  );
955
- if (this.type == "user") {
956
- console.log("results from DB No Chache available", results);
957
- }
958
979
  }
959
980
  }
960
981
  }