prisma-sql 1.7.0 → 1.8.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/index.js CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";
1
+ import { convertDMMFToModels, isDynamicParameter, extractDynamicName } from '@dee-wan/schema-parser';
2
+ export { convertDMMFToModels } from '@dee-wan/schema-parser';
3
+
2
4
  var __defProp = Object.defineProperty;
3
5
  var __defProps = Object.defineProperties;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -20,19 +20,6 @@ var __spreadValues = (a, b) => {
20
20
  return a;
21
21
  };
22
22
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
- var __export = (target, all) => {
24
- for (var name in all)
25
- __defProp(target, name, { get: all[name], enumerable: true });
26
- };
27
- var __copyProps = (to, from, except, desc) => {
28
- if (from && typeof from === "object" || typeof from === "function") {
29
- for (let key of __getOwnPropNames(from))
30
- if (!__hasOwnProp.call(to, key) && key !== except)
31
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
32
- }
33
- return to;
34
- };
35
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
23
  var __async = (__this, __arguments, generator) => {
37
24
  return new Promise((resolve, reject) => {
38
25
  var fulfilled = (value) => {
@@ -54,21 +41,6 @@ var __async = (__this, __arguments, generator) => {
54
41
  });
55
42
  };
56
43
 
57
- // src/index.ts
58
- var src_exports = {};
59
- __export(src_exports, {
60
- convertDMMFToModels: () => import_schema_parser10.convertDMMFToModels,
61
- createPrismaSQL: () => createPrismaSQL,
62
- createToSQL: () => createToSQL,
63
- generateAllSQL: () => generateAllSQL,
64
- generateSQL: () => generateSQL2,
65
- generateSQLByModel: () => generateSQLByModel,
66
- getGlobalDialect: () => getGlobalDialect,
67
- setGlobalDialect: () => setGlobalDialect,
68
- speedExtension: () => speedExtension
69
- });
70
- module.exports = __toCommonJS(src_exports);
71
-
72
44
  // src/sql-builder-dialect.ts
73
45
  var globalDialect = "postgres";
74
46
  function setGlobalDialect(dialect) {
@@ -384,7 +356,6 @@ var Wildcards = Object.freeze({
384
356
  [Ops.ENDS_WITH]: (v) => `%${v}`
385
357
  });
386
358
  var REGEX_CACHE = {
387
- PARAM_PLACEHOLDER: /\$(\d+)/g,
388
359
  VALID_IDENTIFIER: /^[a-z_][a-z0-9_]*$/
389
360
  };
390
361
  var LIMITS = Object.freeze({
@@ -689,7 +660,7 @@ function validateMappingsAgainstPlaceholders(mappings, placeholders, max, dialec
689
660
  const mappingIndices = /* @__PURE__ */ new Set();
690
661
  for (const mapping of mappings) {
691
662
  validateMappingIndex(mapping, max);
692
- ensureUniqueMappingIndex(mappingIndices, mapping.index, dialect);
663
+ ensureUniqueMappingIndex(mappingIndices, mapping.index);
693
664
  ensureMappingIndexExistsInSql(placeholders, mapping.index);
694
665
  validateMappingValueShape(mapping);
695
666
  }
@@ -879,9 +850,6 @@ function joinCondition(field, parentAlias, childAlias) {
879
850
  function getModelByName(schemas, name) {
880
851
  return schemas.find((m) => m.name === name);
881
852
  }
882
-
883
- // src/builder/where/operators-scalar.ts
884
- var import_schema_parser = require("@dee-wan/schema-parser");
885
853
  function buildNotComposite(expr, val, params, dialect, buildOp, separator) {
886
854
  const entries = Object.entries(val).filter(
887
855
  ([k, v]) => k !== "mode" && v !== void 0
@@ -910,7 +878,7 @@ function buildScalarOperator(expr, op, val, params, mode, fieldType, dialect) {
910
878
  }
911
879
  if (op === Ops.EQUALS && mode === Modes.INSENSITIVE && isNotNullish(dialect)) {
912
880
  const placeholder = params.addAuto(val);
913
- return caseInsensitiveEquals(expr, placeholder, dialect);
881
+ return caseInsensitiveEquals(expr, placeholder);
914
882
  }
915
883
  const STRING_LIKE_OPS = /* @__PURE__ */ new Set([
916
884
  Ops.CONTAINS,
@@ -981,7 +949,7 @@ function buildDynamicLikePattern(op, placeholder, dialect) {
981
949
  }
982
950
  function handleLikeOperator(expr, op, val, params, mode, dialect) {
983
951
  if (val === void 0) return "";
984
- if ((0, import_schema_parser.isDynamicParameter)(val)) {
952
+ if (isDynamicParameter(val)) {
985
953
  const placeholder2 = params.addAuto(val);
986
954
  const patternExpr = buildDynamicLikePattern(op, placeholder2, dialect);
987
955
  if (mode === Modes.INSENSITIVE) {
@@ -997,7 +965,7 @@ function handleLikeOperator(expr, op, val, params, mode, dialect) {
997
965
  }
998
966
  function handleInOperator(expr, op, val, params, dialect) {
999
967
  if (val === void 0) return "";
1000
- if ((0, import_schema_parser.isDynamicParameter)(val)) {
968
+ if (isDynamicParameter(val)) {
1001
969
  const placeholder2 = params.addAuto(val);
1002
970
  return op === Ops.IN ? inArray(expr, placeholder2, dialect) : notInArray(expr, placeholder2, dialect);
1003
971
  }
@@ -1030,11 +998,8 @@ function handleComparisonOperator(expr, op, val, params) {
1030
998
  const placeholder = params.addAuto(val);
1031
999
  return `${expr} ${sqlOp} ${placeholder}`;
1032
1000
  }
1033
-
1034
- // src/builder/where/operators-array.ts
1035
- var import_schema_parser2 = require("@dee-wan/schema-parser");
1036
1001
  function buildArrayParam(val, params, dialect) {
1037
- if ((0, import_schema_parser2.isDynamicParameter)(val)) {
1002
+ if (isDynamicParameter(val)) {
1038
1003
  return params.addAuto(val);
1039
1004
  }
1040
1005
  if (!Array.isArray(val)) {
@@ -1108,7 +1073,7 @@ function handleArrayHas(expr, val, params, cast, dialect) {
1108
1073
  value: val
1109
1074
  });
1110
1075
  }
1111
- if (!(0, import_schema_parser2.isDynamicParameter)(val) && Array.isArray(val)) {
1076
+ if (!isDynamicParameter(val) && Array.isArray(val)) {
1112
1077
  throw createError(`has requires scalar value (single element), not array`, {
1113
1078
  operator: Ops.HAS,
1114
1079
  value: val
@@ -1125,7 +1090,7 @@ function handleArrayHas(expr, val, params, cast, dialect) {
1125
1090
  }
1126
1091
  function handleArrayHasSome(expr, val, params, cast, dialect) {
1127
1092
  if (val === void 0) return "";
1128
- if ((0, import_schema_parser2.isDynamicParameter)(val)) {
1093
+ if (isDynamicParameter(val)) {
1129
1094
  const placeholder2 = params.addAuto(val);
1130
1095
  return arrayOverlaps(expr, placeholder2, cast, dialect);
1131
1096
  }
@@ -1797,9 +1762,6 @@ function createAliasGenerator(maxAliases = 1e4) {
1797
1762
  }
1798
1763
  };
1799
1764
  }
1800
-
1801
- // src/builder/shared/param-store.ts
1802
- var import_schema_parser3 = require("@dee-wan/schema-parser");
1803
1765
  var MAX_PARAM_INDEX = Number.MAX_SAFE_INTEGER - 1e3;
1804
1766
  function assertSameLength(params, mappings) {
1805
1767
  if (params.length !== mappings.length) {
@@ -1930,8 +1892,8 @@ function createStoreInternal(startIndex, initialParams = [], initialMappings = [
1930
1892
  return dynamicName === void 0 ? addStatic(value) : addDynamic(dynamicName);
1931
1893
  }
1932
1894
  function addAuto(value) {
1933
- if ((0, import_schema_parser3.isDynamicParameter)(value)) {
1934
- const dynamicName = (0, import_schema_parser3.extractDynamicName)(value);
1895
+ if (isDynamicParameter(value)) {
1896
+ const dynamicName = extractDynamicName(value);
1935
1897
  return add(void 0, dynamicName);
1936
1898
  }
1937
1899
  return add(value);
@@ -2020,13 +1982,10 @@ function buildWhereClause(where, options) {
2020
1982
  }
2021
1983
  return publicResult;
2022
1984
  }
2023
-
2024
- // src/builder/shared/int-like.ts
2025
- var import_schema_parser4 = require("@dee-wan/schema-parser");
2026
1985
  function normalizeIntLike(name, v, opts = {}) {
2027
1986
  var _a, _b;
2028
1987
  if (!isNotNullish(v)) return void 0;
2029
- if ((0, import_schema_parser4.isDynamicParameter)(v)) return v;
1988
+ if (isDynamicParameter(v)) return v;
2030
1989
  if (typeof v !== "number" || !Number.isFinite(v) || !Number.isInteger(v)) {
2031
1990
  throw new Error(`${name} must be an integer`);
2032
1991
  }
@@ -2043,9 +2002,6 @@ function normalizeIntLike(name, v, opts = {}) {
2043
2002
  }
2044
2003
  return v;
2045
2004
  }
2046
-
2047
- // src/builder/shared/dynamic-params.ts
2048
- var import_schema_parser5 = require("@dee-wan/schema-parser");
2049
2005
  function scopeName(scope, dynamicName) {
2050
2006
  const s = String(scope).trim();
2051
2007
  const dn = String(dynamicName).trim();
@@ -2053,16 +2009,13 @@ function scopeName(scope, dynamicName) {
2053
2009
  return `${s}:${dn}`;
2054
2010
  }
2055
2011
  function addAutoScoped(params, value, scope) {
2056
- if ((0, import_schema_parser5.isDynamicParameter)(value)) {
2057
- const dn = (0, import_schema_parser5.extractDynamicName)(value);
2012
+ if (isDynamicParameter(value)) {
2013
+ const dn = extractDynamicName(value);
2058
2014
  return params.add(void 0, scopeName(scope, dn));
2059
2015
  }
2060
2016
  return params.add(value);
2061
2017
  }
2062
2018
 
2063
- // src/builder/pagination.ts
2064
- var import_schema_parser6 = require("@dee-wan/schema-parser");
2065
-
2066
2019
  // src/builder/shared/order-by-utils.ts
2067
2020
  var flipNulls = (v) => {
2068
2021
  const s = String(v).toLowerCase();
@@ -2198,7 +2151,7 @@ function normalizeFiniteInteger(name, v) {
2198
2151
  return v;
2199
2152
  }
2200
2153
  function normalizeNonNegativeInt(name, v) {
2201
- if ((0, import_schema_parser6.isDynamicParameter)(v)) return v;
2154
+ if (isDynamicParameter(v)) return v;
2202
2155
  const n = normalizeFiniteInteger(name, v);
2203
2156
  if (n < 0) {
2204
2157
  throw new Error(`${name} must be >= 0`);
@@ -2212,7 +2165,7 @@ function hasNonNullishProp(v, key) {
2212
2165
  return isPlainObject(v) && key in v && isNotNullish(v[key]);
2213
2166
  }
2214
2167
  function normalizeIntegerOrDynamic(name, v) {
2215
- if ((0, import_schema_parser6.isDynamicParameter)(v)) return v;
2168
+ if (isDynamicParameter(v)) return v;
2216
2169
  return normalizeFiniteInteger(name, v);
2217
2170
  }
2218
2171
  function readSkipTake(relArgs) {
@@ -2445,9 +2398,6 @@ function getPaginationParams(method, args) {
2445
2398
  return {};
2446
2399
  }
2447
2400
 
2448
- // src/builder/select/assembly.ts
2449
- var import_schema_parser7 = require("@dee-wan/schema-parser");
2450
-
2451
2401
  // src/builder/select/fields.ts
2452
2402
  function toSelectEntries(select) {
2453
2403
  const out = [];
@@ -3283,7 +3233,7 @@ function appendPagination(sql, spec) {
3283
3233
  const isFindUniqueOrFirst = method === "findUnique" || method === "findFirst";
3284
3234
  if (isFindUniqueOrFirst) {
3285
3235
  const parts2 = [sql, SQL_TEMPLATES.LIMIT, "1"];
3286
- const hasSkip = isNotNullish(pagination.skip) && ((0, import_schema_parser7.isDynamicParameter)(pagination.skip) || typeof pagination.skip === "number" && pagination.skip > 0) && method === "findFirst";
3236
+ const hasSkip = isNotNullish(pagination.skip) && (isDynamicParameter(pagination.skip) || typeof pagination.skip === "number" && pagination.skip > 0) && method === "findFirst";
3287
3237
  if (hasSkip) {
3288
3238
  const placeholder = addAutoScoped(
3289
3239
  params,
@@ -3516,7 +3466,7 @@ function normalizeArgsForNegativeTake(method, args) {
3516
3466
  }
3517
3467
  function normalizeArgsForDialect(dialect, args, model) {
3518
3468
  if (dialect !== "postgres") return args;
3519
- return applyPostgresDistinctOrderBy(args, model);
3469
+ return applyPostgresDistinctOrderBy(args);
3520
3470
  }
3521
3471
  function buildCursorClauseIfAny(input) {
3522
3472
  const { cursor, orderBy, tableName, alias, params, dialect } = input;
@@ -3595,9 +3545,7 @@ function buildSelectSql(input) {
3595
3545
  const argsForSql = normalizeArgsForNegativeTake(method, args);
3596
3546
  const normalizedArgs = normalizeArgsForDialect(
3597
3547
  dialectToUse,
3598
- argsForSql,
3599
- model
3600
- );
3548
+ argsForSql);
3601
3549
  validateDistinct(model, normalizedArgs.distinct);
3602
3550
  validateOrderBy(model, normalizedArgs.orderBy);
3603
3551
  validateCursor(model, normalizedArgs.cursor);
@@ -3613,9 +3561,6 @@ function buildSelectSql(input) {
3613
3561
  });
3614
3562
  return constructFinalSql(spec);
3615
3563
  }
3616
-
3617
- // src/builder/aggregates.ts
3618
- var import_schema_parser8 = require("@dee-wan/schema-parser");
3619
3564
  var MODEL_FIELD_CACHE = /* @__PURE__ */ new WeakMap();
3620
3565
  var NUMERIC_TYPES = /* @__PURE__ */ new Set(["Int", "Float", "Decimal", "BigInt"]);
3621
3566
  var AGGREGATES = [
@@ -3710,7 +3655,7 @@ function buildNullComparison(expr, op) {
3710
3655
  throw new Error(`Operator '${op}' doesn't support null in HAVING`);
3711
3656
  }
3712
3657
  function buildInComparison(expr, op, val, params, dialect) {
3713
- if ((0, import_schema_parser8.isDynamicParameter)(val)) {
3658
+ if (isDynamicParameter(val)) {
3714
3659
  const placeholder2 = addHavingParam(params, op, val);
3715
3660
  return op === Ops.IN ? inArray(expr, placeholder2, dialect) : notInArray(expr, placeholder2, dialect);
3716
3661
  }
@@ -4108,7 +4053,7 @@ function buildCountSql(whereResult, tableName, alias, skip, dialect) {
4108
4053
  });
4109
4054
  }
4110
4055
  function applyCountSkip(subSelect, normalizedSkip, params, dialect) {
4111
- const shouldApply = (0, import_schema_parser8.isDynamicParameter)(normalizedSkip) || typeof normalizedSkip === "number" && normalizedSkip > 0;
4056
+ const shouldApply = isDynamicParameter(normalizedSkip) || typeof normalizedSkip === "number" && normalizedSkip > 0;
4112
4057
  if (!shouldApply) return subSelect;
4113
4058
  const placeholder = addAutoScoped(params, normalizedSkip, "count.skip");
4114
4059
  if (dialect === "sqlite") {
@@ -4116,9 +4061,6 @@ function applyCountSkip(subSelect, normalizedSkip, params, dialect) {
4116
4061
  }
4117
4062
  return `${subSelect} ${SQL_TEMPLATES.OFFSET} ${placeholder}`;
4118
4063
  }
4119
-
4120
- // src/sql-generator.ts
4121
- var import_schema_parser9 = require("@dee-wan/schema-parser");
4122
4064
  function safeAlias(input) {
4123
4065
  const raw = String(input).toLowerCase();
4124
4066
  const cleaned = raw.replace(/[^a-z0-9_]/g, "_");
@@ -4220,7 +4162,7 @@ function buildParamsFromMappings(mappings) {
4220
4162
  }
4221
4163
  function resolveModelContext(directive) {
4222
4164
  const { model, datamodel } = directive.context;
4223
- const schemaModels = (0, import_schema_parser9.convertDMMFToModels)(datamodel);
4165
+ const schemaModels = convertDMMFToModels(datamodel);
4224
4166
  const modelDef = getModelByName(schemaModels, model.name);
4225
4167
  if (!modelDef) throw new Error(`Model ${model.name} not found in schema`);
4226
4168
  return { schemaModels, modelDef };
@@ -4353,9 +4295,6 @@ function transformQueryResults(method, results) {
4353
4295
  const transformer = RESULT_TRANSFORMERS[method];
4354
4296
  return transformer ? transformer(results) : results;
4355
4297
  }
4356
-
4357
- // src/index.ts
4358
- var import_schema_parser10 = require("@dee-wan/schema-parser");
4359
4298
  var ACCELERATED_METHODS = /* @__PURE__ */ new Set([
4360
4299
  "findMany",
4361
4300
  "findFirst",
@@ -4682,16 +4621,7 @@ function generateSQLByModel(directives) {
4682
4621
  }
4683
4622
  return byModel;
4684
4623
  }
4685
- // Annotate the CommonJS export names for ESM import in node:
4686
- 0 && (module.exports = {
4687
- convertDMMFToModels,
4688
- createPrismaSQL,
4689
- createToSQL,
4690
- generateAllSQL,
4691
- generateSQL,
4692
- generateSQLByModel,
4693
- getGlobalDialect,
4694
- setGlobalDialect,
4695
- speedExtension
4696
- });
4624
+
4625
+ export { createPrismaSQL, createToSQL, generateAllSQL, generateSQL2 as generateSQL, generateSQLByModel, getGlobalDialect, setGlobalDialect, speedExtension };
4626
+ //# sourceMappingURL=index.js.map
4697
4627
  //# sourceMappingURL=index.js.map