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