spice-js 2.6.67 → 2.6.68

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.
@@ -932,6 +932,17 @@ class SpiceModel {
932
932
  }
933
933
 
934
934
  if (!columns || columns === "") return columns;
935
+
936
+ var q = function q(s) {
937
+ if (s === void 0) {
938
+ s = "";
939
+ }
940
+
941
+ var t = (s || "").trim();
942
+ if (t.startsWith("`") && t.endsWith("`")) return t;
943
+ return "`" + t.replace(/`/g, "``") + "`";
944
+ };
945
+
935
946
  var protectedSet = new Set(protectedAliases);
936
947
  var arraySet = new Set(arrayAliases);
937
948
  var tokens = columns.split(",");
@@ -950,37 +961,40 @@ class SpiceModel {
950
961
  var proj = this.buildArrayProjection(alias, field);
951
962
 
952
963
  if (explicitAs && explicitAs !== alias + "_" + field) {
953
- proj = proj.replace(/AS\s+`[^`]+`$/i, "AS `" + explicitAs + "`");
964
+ proj = proj.replace(/AS\s+`[^`]+`$/i, "AS " + q(explicitAs));
954
965
  }
955
966
 
956
967
  return proj;
957
968
  }
958
969
 
959
970
  if (protectedSet.has(alias)) {
960
- var aliased = "`" + alias + "`." + (field.startsWith("`") ? field : "`" + field + "`");
961
- return explicitAs ? aliased + " AS `" + explicitAs + "`" : aliased;
971
+ var aliased = q(alias) + "." + (field.startsWith("`") ? field : q(field));
972
+ return explicitAs ? aliased + " AS " + q(explicitAs) : aliased;
962
973
  }
963
974
 
964
- var bare = col.replace(/`/g, "");
965
- return "`" + this.type + "`." + bare;
975
+ var qualified = q(this.type) + "." + q(alias) + "." + q(field);
976
+ return explicitAs ? qualified + " AS " + q(explicitAs) : qualified;
966
977
  }
967
978
 
968
- var looksProtected = [...protectedSet].some(a => col === a || col === "`" + a + "`" || col.startsWith(a + ".") || col.startsWith("`" + a + "`."));
979
+ var looksProtected = [...protectedSet].some(a => col === a || col === q(a) || col.startsWith(a + ".") || col.startsWith(q(a) + "."));
969
980
 
970
981
  if (!looksProtected) {
971
- if (!col.startsWith("`") && !col.endsWith("`") && !col.includes("(")) {
972
- col = "`" + col + "`";
982
+ if (!col.includes(".")) {
983
+ var fieldQuoted = col.startsWith("`") ? col : q(col);
984
+ return q(this.type) + "." + fieldQuoted;
973
985
  }
974
986
 
975
- if (col && !col.includes(".") && !col.startsWith(this.type)) {
976
- col = "`" + this.type + "`." + col.replace(/`/g, "");
977
- }
978
-
979
- return col;
987
+ var parts = col.split(".");
988
+ var safeParts = parts.map(p => {
989
+ var t = p.trim();
990
+ if (t === "" || /\w+\s*\(/.test(t)) return t;
991
+ return t.startsWith("`") ? t : q(t);
992
+ });
993
+ return q(this.type) + "." + safeParts.join(".");
980
994
  }
981
995
 
982
996
  if (!col.includes(".") && !col.startsWith("`")) {
983
- return "`" + col + "`";
997
+ return q(col);
984
998
  }
985
999
 
986
1000
  return col;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-js",
3
- "version": "2.6.67",
3
+ "version": "2.6.68",
4
4
  "description": "spice",
5
5
  "main": "build/index.js",
6
6
  "repository": {
@@ -825,66 +825,85 @@ export default class SpiceModel {
825
825
  }
826
826
 
827
827
 
828
- prepColumns(columns, protectedAliases = [], arrayAliases = []) {
829
- if (!columns || columns === "") return columns;
830
-
831
- const protectedSet = new Set(protectedAliases);
832
- const arraySet = new Set(arrayAliases);
833
-
834
- const tokens = columns.split(",");
835
-
836
- const out = tokens.map((raw) => {
837
- let col = (raw || "").trim();
838
- if (col === "" || col === "meta().id") return undefined;
839
-
840
-
841
- if (/^\s*ARRAY\s+/i.test(col) || /\w+\s*\(/.test(col)) return col;
842
-
843
- const m = col.match(/^\s*`?(\w+)`?\.`?(\w+)`?(?:\s+AS\s+`?([\w]+)`?)?\s*$/i);
844
- if (m) {
845
- const alias = m[1];
846
- const field = m[2];
847
- const explicitAs = m[3];
848
-
849
- if (arraySet.has(alias)) {
850
- let proj = this.buildArrayProjection(alias, field);
851
- if (explicitAs && explicitAs !== `${alias}_${field}`) {
852
- proj = proj.replace(/AS\s+`[^`]+`$/i, `AS \`${explicitAs}\``);
828
+ prepColumns(columns, protectedAliases = [], arrayAliases = []) {
829
+ if (!columns || columns === "") return columns;
830
+
831
+ const q = (s = "") => {
832
+ const t = (s || "").trim();
833
+ if (t.startsWith("`") && t.endsWith("`")) return t;
834
+ return "`" + t.replace(/`/g, "``") + "`";
835
+ };
836
+
837
+ const protectedSet = new Set(protectedAliases);
838
+ const arraySet = new Set(arrayAliases);
839
+
840
+ const tokens = columns.split(",");
841
+
842
+ const out = tokens.map((raw) => {
843
+ let col = (raw || "").trim();
844
+ if (col === "" || col === "meta().id") return undefined;
845
+
846
+
847
+ if (/^\s*ARRAY\s+/i.test(col) || /\w+\s*\(/.test(col)) return col;
848
+
849
+
850
+ const m = col.match(/^\s*`?(\w+)`?\.`?(\w+)`?(?:\s+AS\s+`?([\w]+)`?)?\s*$/i);
851
+ if (m) {
852
+ const alias = m[1];
853
+ const field = m[2];
854
+ const explicitAs = m[3];
855
+
856
+ if (arraySet.has(alias)) {
857
+ let proj = this.buildArrayProjection(alias, field);
858
+ if (explicitAs && explicitAs !== `${alias}_${field}`) {
859
+ proj = proj.replace(/AS\s+`[^`]+`$/i, `AS ${q(explicitAs)}`);
860
+ }
861
+ return proj;
853
862
  }
854
- return proj;
855
- }
856
-
857
- if (protectedSet.has(alias)) {
858
- const aliased = `\`${alias}\`.${field.startsWith("`") ? field : `\`${field}\``}`;
859
- return explicitAs ? `${aliased} AS \`${explicitAs}\`` : aliased;
863
+
864
+ if (protectedSet.has(alias)) {
865
+ const aliased = `${q(alias)}.${field.startsWith("`") ? field : q(field)}`;
866
+ return explicitAs ? `${aliased} AS ${q(explicitAs)}` : aliased;
867
+ }
868
+
869
+
870
+ const qualified = `${q(this.type)}.${q(alias)}.${q(field)}`;
871
+ return explicitAs ? `${qualified} AS ${q(explicitAs)}` : qualified;
860
872
  }
861
-
862
- const bare = col.replace(/`/g, "");
863
- return `\`${this.type}\`.${bare}`;
864
- }
865
-
866
- const looksProtected = [...protectedSet].some(
867
- (a) => col === a || col === `\`${a}\`` || col.startsWith(`${a}.`) || col.startsWith(`\`${a}\`.`)
868
- );
869
-
870
- if (!looksProtected) {
871
- if (!col.startsWith("`") && !col.endsWith("`") && !col.includes("(")) {
872
- col = `\`${col}\``;
873
+
874
+
875
+ const looksProtected = [...protectedSet].some(
876
+ (a) =>
877
+ col === a ||
878
+ col === q(a) ||
879
+ col.startsWith(`${a}.`) ||
880
+ col.startsWith(`${q(a)}.`)
881
+ );
882
+
883
+ if (!looksProtected) {
884
+
885
+ if (!col.includes(".")) {
886
+ const fieldQuoted = col.startsWith("`") ? col : q(col);
887
+ return `${q(this.type)}.${fieldQuoted}`;
888
+ }
889
+
890
+ const parts = col.split(".");
891
+ const safeParts = parts.map((p) => {
892
+ const t = p.trim();
893
+ if (t === "" || /\w+\s*\(/.test(t)) return t;
894
+ return t.startsWith("`") ? t : q(t);
895
+ });
896
+ return `${q(this.type)}.${safeParts.join(".")}`;
873
897
  }
874
- if (col && !col.includes(".") && !col.startsWith(this.type)) {
875
- col = `\`${this.type}\`.${col.replace(/`/g, "")}`;
898
+
899
+ if (!col.includes(".") && !col.startsWith("`")) {
900
+ return q(col);
876
901
  }
877
902
  return col;
878
- }
879
-
880
- if (!col.includes(".") && !col.startsWith("`")) {
881
- return `\`${col}\``;
882
- }
883
- return col;
884
- });
885
-
886
- return _.join(_.compact(out), ",");
887
- }
903
+ });
904
+
905
+ return _.join(_.compact(out), ",");
906
+ }
888
907
 
889
908
 
890
909
  filterResultsByColumns(data, columns) {