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.
- package/build/models/SpiceModel.js +28 -14
- package/package.json +1 -1
- package/src/models/SpiceModel.js +74 -55
|
@@ -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
|
|
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 =
|
|
961
|
-
return explicitAs ? aliased + " AS
|
|
971
|
+
var aliased = q(alias) + "." + (field.startsWith("`") ? field : q(field));
|
|
972
|
+
return explicitAs ? aliased + " AS " + q(explicitAs) : aliased;
|
|
962
973
|
}
|
|
963
974
|
|
|
964
|
-
var
|
|
965
|
-
return
|
|
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 ===
|
|
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.
|
|
972
|
-
|
|
982
|
+
if (!col.includes(".")) {
|
|
983
|
+
var fieldQuoted = col.startsWith("`") ? col : q(col);
|
|
984
|
+
return q(this.type) + "." + fieldQuoted;
|
|
973
985
|
}
|
|
974
986
|
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
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
|
|
997
|
+
return q(col);
|
|
984
998
|
}
|
|
985
999
|
|
|
986
1000
|
return col;
|
package/package.json
CHANGED
package/src/models/SpiceModel.js
CHANGED
|
@@ -825,66 +825,85 @@ export default class SpiceModel {
|
|
|
825
825
|
}
|
|
826
826
|
|
|
827
827
|
|
|
828
|
-
prepColumns(columns, protectedAliases = [], arrayAliases = []) {
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
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
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
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
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
if (!
|
|
872
|
-
|
|
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
|
-
|
|
875
|
-
|
|
898
|
+
|
|
899
|
+
if (!col.includes(".") && !col.startsWith("`")) {
|
|
900
|
+
return q(col);
|
|
876
901
|
}
|
|
877
902
|
return col;
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
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) {
|