prisma-sql 1.23.0 → 1.24.0
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/dist/generator.cjs +137 -13
- package/dist/generator.cjs.map +1 -1
- package/dist/generator.js +137 -13
- package/dist/generator.js.map +1 -1
- package/dist/index.cjs +136 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +136 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/generator.js
CHANGED
|
@@ -54,7 +54,7 @@ var require_package = __commonJS({
|
|
|
54
54
|
"package.json"(exports$1, module) {
|
|
55
55
|
module.exports = {
|
|
56
56
|
name: "prisma-sql",
|
|
57
|
-
version: "1.
|
|
57
|
+
version: "1.24.0",
|
|
58
58
|
description: "Convert Prisma queries to optimized SQL with type safety. 2-7x faster than Prisma Client.",
|
|
59
59
|
main: "dist/index.cjs",
|
|
60
60
|
module: "dist/index.js",
|
|
@@ -790,8 +790,140 @@ var NUL = String.fromCharCode(0);
|
|
|
790
790
|
function containsControlChars(s) {
|
|
791
791
|
return s.includes(NUL) || s.includes("\n") || s.includes("\r");
|
|
792
792
|
}
|
|
793
|
-
function
|
|
794
|
-
|
|
793
|
+
function assertNoControlChars(label, s) {
|
|
794
|
+
if (containsControlChars(s)) {
|
|
795
|
+
throw new Error(
|
|
796
|
+
`${label} contains invalid characters: ${JSON.stringify(s)}`
|
|
797
|
+
);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
function isIdentCharCode(c) {
|
|
801
|
+
return c >= 48 && c <= 57 || c >= 65 && c <= 90 || c >= 97 && c <= 122 || c === 95;
|
|
802
|
+
}
|
|
803
|
+
function isIdentStartCharCode(c) {
|
|
804
|
+
return c >= 65 && c <= 90 || c >= 97 && c <= 122 || c === 95;
|
|
805
|
+
}
|
|
806
|
+
function parseQuotedPart(input, start) {
|
|
807
|
+
const n = input.length;
|
|
808
|
+
let i = start + 1;
|
|
809
|
+
let sawAny = false;
|
|
810
|
+
while (i < n) {
|
|
811
|
+
const c = input.charCodeAt(i);
|
|
812
|
+
if (c === 34) {
|
|
813
|
+
const next = i + 1;
|
|
814
|
+
if (next < n && input.charCodeAt(next) === 34) {
|
|
815
|
+
sawAny = true;
|
|
816
|
+
i += 2;
|
|
817
|
+
continue;
|
|
818
|
+
}
|
|
819
|
+
if (!sawAny) {
|
|
820
|
+
throw new Error(
|
|
821
|
+
`tableName/tableRef has empty quoted identifier part: ${JSON.stringify(input)}`
|
|
822
|
+
);
|
|
823
|
+
}
|
|
824
|
+
return i + 1;
|
|
825
|
+
}
|
|
826
|
+
if (c === 10 || c === 13 || c === 0) {
|
|
827
|
+
throw new Error(
|
|
828
|
+
`tableName/tableRef contains invalid characters: ${JSON.stringify(input)}`
|
|
829
|
+
);
|
|
830
|
+
}
|
|
831
|
+
sawAny = true;
|
|
832
|
+
i++;
|
|
833
|
+
}
|
|
834
|
+
throw new Error(
|
|
835
|
+
`tableName/tableRef has unterminated quoted identifier: ${JSON.stringify(input)}`
|
|
836
|
+
);
|
|
837
|
+
}
|
|
838
|
+
function parseUnquotedPart(input, start) {
|
|
839
|
+
const n = input.length;
|
|
840
|
+
let i = start;
|
|
841
|
+
if (i >= n) {
|
|
842
|
+
throw new Error(`tableName/tableRef is invalid: ${JSON.stringify(input)}`);
|
|
843
|
+
}
|
|
844
|
+
const c0 = input.charCodeAt(i);
|
|
845
|
+
if (!isIdentStartCharCode(c0)) {
|
|
846
|
+
throw new Error(
|
|
847
|
+
`tableName/tableRef must use identifiers (or quoted identifiers). Got: ${JSON.stringify(input)}`
|
|
848
|
+
);
|
|
849
|
+
}
|
|
850
|
+
i++;
|
|
851
|
+
while (i < n) {
|
|
852
|
+
const c = input.charCodeAt(i);
|
|
853
|
+
if (c === 46) break;
|
|
854
|
+
if (!isIdentCharCode(c)) {
|
|
855
|
+
throw new Error(
|
|
856
|
+
`tableName/tableRef contains invalid identifier characters: ${JSON.stringify(input)}`
|
|
857
|
+
);
|
|
858
|
+
}
|
|
859
|
+
i++;
|
|
860
|
+
}
|
|
861
|
+
return i;
|
|
862
|
+
}
|
|
863
|
+
function assertSafeQualifiedName(tableRef) {
|
|
864
|
+
const raw = String(tableRef);
|
|
865
|
+
const trimmed = raw.trim();
|
|
866
|
+
if (trimmed.length === 0) {
|
|
867
|
+
throw new Error("tableName/tableRef is required and cannot be empty");
|
|
868
|
+
}
|
|
869
|
+
if (raw !== trimmed) {
|
|
870
|
+
throw new Error(
|
|
871
|
+
`tableName/tableRef must not contain leading/trailing whitespace: ${JSON.stringify(raw)}`
|
|
872
|
+
);
|
|
873
|
+
}
|
|
874
|
+
assertNoControlChars("tableName/tableRef", trimmed);
|
|
875
|
+
for (let i2 = 0; i2 < trimmed.length; i2++) {
|
|
876
|
+
const c = trimmed.charCodeAt(i2);
|
|
877
|
+
if (c === 9 || c === 11 || c === 12 || c === 32) {
|
|
878
|
+
throw new Error(
|
|
879
|
+
`tableName/tableRef must not contain whitespace: ${JSON.stringify(trimmed)}`
|
|
880
|
+
);
|
|
881
|
+
}
|
|
882
|
+
if (c === 59) {
|
|
883
|
+
throw new Error(
|
|
884
|
+
`tableName/tableRef must not contain ';': ${JSON.stringify(trimmed)}`
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
if (c === 40 || c === 41) {
|
|
888
|
+
throw new Error(
|
|
889
|
+
`tableName/tableRef must not contain parentheses: ${JSON.stringify(trimmed)}`
|
|
890
|
+
);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
let i = 0;
|
|
894
|
+
const n = trimmed.length;
|
|
895
|
+
let parts = 0;
|
|
896
|
+
while (i < n) {
|
|
897
|
+
const c = trimmed.charCodeAt(i);
|
|
898
|
+
if (c === 46) {
|
|
899
|
+
throw new Error(
|
|
900
|
+
`tableName/tableRef has empty identifier part: ${JSON.stringify(trimmed)}`
|
|
901
|
+
);
|
|
902
|
+
}
|
|
903
|
+
if (c === 34) {
|
|
904
|
+
i = parseQuotedPart(trimmed, i);
|
|
905
|
+
} else {
|
|
906
|
+
i = parseUnquotedPart(trimmed, i);
|
|
907
|
+
}
|
|
908
|
+
parts++;
|
|
909
|
+
if (parts > 2) {
|
|
910
|
+
throw new Error(
|
|
911
|
+
`tableName/tableRef must be 'table' or 'schema.table' (max 2 parts). Got: ${JSON.stringify(trimmed)}`
|
|
912
|
+
);
|
|
913
|
+
}
|
|
914
|
+
if (i === n) break;
|
|
915
|
+
if (trimmed.charCodeAt(i) !== 46) {
|
|
916
|
+
throw new Error(
|
|
917
|
+
`tableName/tableRef is invalid: ${JSON.stringify(trimmed)}`
|
|
918
|
+
);
|
|
919
|
+
}
|
|
920
|
+
i++;
|
|
921
|
+
if (i === n) {
|
|
922
|
+
throw new Error(
|
|
923
|
+
`tableName/tableRef cannot end with '.': ${JSON.stringify(trimmed)}`
|
|
924
|
+
);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
795
927
|
}
|
|
796
928
|
function quote(id) {
|
|
797
929
|
if (isEmptyString(id)) {
|
|
@@ -856,7 +988,7 @@ function assertSafeAlias(alias) {
|
|
|
856
988
|
if (a.trim().length === 0) {
|
|
857
989
|
throw new Error("alias is required and cannot be empty");
|
|
858
990
|
}
|
|
859
|
-
if (
|
|
991
|
+
if (containsControlChars(a) || a.includes(";")) {
|
|
860
992
|
throw new Error(`alias contains unsafe characters: ${JSON.stringify(a)}`);
|
|
861
993
|
}
|
|
862
994
|
if (!/^[A-Za-z_]\w*$/.test(a)) {
|
|
@@ -866,15 +998,7 @@ function assertSafeAlias(alias) {
|
|
|
866
998
|
}
|
|
867
999
|
}
|
|
868
1000
|
function assertSafeTableRef(tableRef) {
|
|
869
|
-
|
|
870
|
-
if (t.trim().length === 0) {
|
|
871
|
-
throw new Error("tableName/tableRef is required and cannot be empty");
|
|
872
|
-
}
|
|
873
|
-
if (containsUnsafeSqlFragmentChars(t)) {
|
|
874
|
-
throw new Error(
|
|
875
|
-
`tableName/tableRef contains unsafe characters: ${JSON.stringify(t)}`
|
|
876
|
-
);
|
|
877
|
-
}
|
|
1001
|
+
assertSafeQualifiedName(tableRef);
|
|
878
1002
|
}
|
|
879
1003
|
function normalizeKeyList(input) {
|
|
880
1004
|
if (!isNotNullish(input)) return [];
|