prisma-sql 1.75.7 → 1.75.9

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.
@@ -70,7 +70,7 @@ var require_package = __commonJS({
70
70
  "package.json"(exports$1, module) {
71
71
  module.exports = {
72
72
  name: "prisma-sql",
73
- version: "1.75.7",
73
+ version: "1.75.9",
74
74
  description: "Convert Prisma queries to optimized SQL with type safety. 2-7x faster than Prisma Client.",
75
75
  main: "dist/index.cjs",
76
76
  module: "dist/index.js",
@@ -7289,25 +7289,6 @@ function stableJson(value) {
7289
7289
  2
7290
7290
  );
7291
7291
  }
7292
- function cleanDatabaseUrl(url) {
7293
- try {
7294
- const parsed = new URL(url);
7295
- parsed.search = "";
7296
- if (parsed.password) {
7297
- parsed.password = "***";
7298
- }
7299
- if (parsed.username && parsed.username.length > 0) {
7300
- if (parsed.username.length <= 3) {
7301
- parsed.username = "***";
7302
- } else {
7303
- parsed.username = parsed.username.slice(0, 3) + "***";
7304
- }
7305
- }
7306
- return parsed.toString();
7307
- } catch (error) {
7308
- return "[invalid-url]";
7309
- }
7310
- }
7311
7292
  function createQueryKey(processedQuery) {
7312
7293
  return JSON.stringify(processedQuery, (key, value) => {
7313
7294
  if (value && typeof value === "object" && !Array.isArray(value)) {
@@ -7334,17 +7315,19 @@ function countTotalQueries(queries) {
7334
7315
  function quoteIdent(dialect, ident) {
7335
7316
  return `"${ident.replace(/"/g, '""')}"`;
7336
7317
  }
7337
- function createDatabaseExecutor(params) {
7318
+ function createDatabaseExecutor(options) {
7338
7319
  return __async(this, null, function* () {
7339
- const { databaseUrl, dialect } = params;
7320
+ const { databaseUrl, dialect, connectTimeoutMs = 3e4 } = options;
7340
7321
  if (dialect === "postgres") {
7341
7322
  const postgres = yield import('postgres');
7342
- cleanDatabaseUrl(databaseUrl);
7343
- const sql = postgres.default(databaseUrl, { max: 1 });
7323
+ const sql = postgres.default(databaseUrl, {
7324
+ connect_timeout: Math.ceil(connectTimeoutMs / 1e3),
7325
+ max: 1
7326
+ });
7344
7327
  return {
7345
7328
  executor: {
7346
- query: (sqlStr, params2) => __async(null, null, function* () {
7347
- return yield sql.unsafe(sqlStr, params2 || []);
7329
+ query: (q, params) => __async(null, null, function* () {
7330
+ return yield sql.unsafe(q, params != null ? params : []);
7348
7331
  })
7349
7332
  },
7350
7333
  cleanup: () => __async(null, null, function* () {
@@ -7352,7 +7335,7 @@ function createDatabaseExecutor(params) {
7352
7335
  })
7353
7336
  };
7354
7337
  }
7355
- throw new Error(`Dialect ${dialect} not supported for stats collection`);
7338
+ throw new Error(`createDatabaseExecutor does not support dialect: ${dialect}`);
7356
7339
  });
7357
7340
  }
7358
7341
  function extractMeasurableOneToManyEdges(datamodel) {
@@ -7823,6 +7806,7 @@ function emitPlannerGeneratedModule(artifacts) {
7823
7806
  }
7824
7807
 
7825
7808
  // src/code-emitter.ts
7809
+ var DB_CONNECT_TIMEOUT_MS = 5e3;
7826
7810
  function extractEnumMappings(datamodel) {
7827
7811
  const mappings = {};
7828
7812
  const fieldTypes = {};
@@ -7893,7 +7877,6 @@ function processAllModelDirectives(directiveResults, config) {
7893
7877
  }
7894
7878
  return { queries, skippedCount };
7895
7879
  }
7896
- var DB_CONNECT_TIMEOUT_MS = 5e3;
7897
7880
  function generateClient(options) {
7898
7881
  return __async(this, null, function* () {
7899
7882
  var _a3;
@@ -7914,61 +7897,17 @@ function generateClient(options) {
7914
7897
  yield promises.mkdir(absoluteOutputDir, { recursive: true });
7915
7898
  let plannerArtifacts = options.plannerArtifacts;
7916
7899
  if (!plannerArtifacts) {
7917
- let executor = options.executor;
7918
- let cleanup;
7919
- if (!executor && datasourceUrl) {
7920
- let timedOut = false;
7921
- const timeoutHandle = new Promise((_, reject) => {
7922
- var _a4;
7923
- const id = setTimeout(() => {
7924
- timedOut = true;
7925
- reject(
7926
- new Error(
7927
- `DB connection timed out after ${DB_CONNECT_TIMEOUT_MS}ms`
7928
- )
7929
- );
7930
- }, DB_CONNECT_TIMEOUT_MS);
7931
- (_a4 = id.unref) == null ? void 0 : _a4.call(id);
7932
- });
7933
- try {
7934
- const dbConn = yield Promise.race([
7935
- createDatabaseExecutor({
7936
- databaseUrl: datasourceUrl,
7937
- dialect: config.dialect
7938
- }),
7939
- timeoutHandle
7940
- ]);
7941
- if (!timedOut) {
7942
- executor = dbConn.executor;
7943
- cleanup = dbConn.cleanup;
7944
- }
7945
- } catch (error) {
7946
- console.warn(
7947
- "\u26A0 Failed to connect:",
7948
- error instanceof Error ? error.message : error
7949
- );
7950
- }
7951
- }
7952
- if (executor) {
7953
- try {
7954
- console.log(
7955
- "\u{1F4CA} Collecting relation cardinalities and roundtrip cost..."
7956
- );
7957
- plannerArtifacts = yield collectPlannerArtifacts({
7958
- executor,
7959
- datamodel,
7960
- dialect: config.dialect
7961
- });
7962
- } catch (error) {
7963
- console.warn(
7964
- "\u26A0 Failed to collect stats:",
7965
- error instanceof Error ? error.message : error
7966
- );
7967
- } finally {
7968
- if (cleanup) {
7969
- yield cleanup();
7970
- }
7971
- }
7900
+ const skipPlanner = process.env.PRISMA_SQL_SKIP_PLANNER === "1" || process.env.PRISMA_SQL_SKIP_PLANNER === "true";
7901
+ if (skipPlanner) {
7902
+ console.log(
7903
+ "\u23ED Skipping planner stats collection (PRISMA_SQL_SKIP_PLANNER)"
7904
+ );
7905
+ } else {
7906
+ plannerArtifacts = yield collectPlannerWithTimeout(
7907
+ options,
7908
+ config,
7909
+ datasourceUrl
7910
+ );
7972
7911
  }
7973
7912
  }
7974
7913
  if (!plannerArtifacts) {
@@ -8000,6 +7939,61 @@ function generateClient(options) {
8000
7939
  console.log(`\u2713 Output: ${outputPath}`);
8001
7940
  });
8002
7941
  }
7942
+ var PLANNER_TOTAL_TIMEOUT_MS = 15e3;
7943
+ function collectPlannerWithTimeout(options, config, datasourceUrl) {
7944
+ return __async(this, null, function* () {
7945
+ const timeoutMs = Number(process.env.PRISMA_SQL_PLANNER_TIMEOUT_MS) || PLANNER_TOTAL_TIMEOUT_MS;
7946
+ let cleanup;
7947
+ let settled = false;
7948
+ const work = () => __async(null, null, function* () {
7949
+ let executor = options.executor;
7950
+ if (!executor && datasourceUrl) {
7951
+ const dbConn = yield createDatabaseExecutor({
7952
+ databaseUrl: datasourceUrl,
7953
+ dialect: config.dialect,
7954
+ connectTimeoutMs: DB_CONNECT_TIMEOUT_MS
7955
+ });
7956
+ executor = dbConn.executor;
7957
+ cleanup = dbConn.cleanup;
7958
+ }
7959
+ if (!executor) return void 0;
7960
+ console.log("\u{1F4CA} Collecting relation cardinalities and roundtrip cost...");
7961
+ return yield collectPlannerArtifacts({
7962
+ executor,
7963
+ datamodel: options.datamodel,
7964
+ dialect: config.dialect
7965
+ });
7966
+ });
7967
+ const timeout = new Promise((resolve3) => {
7968
+ const id = setTimeout(() => {
7969
+ settled = true;
7970
+ console.warn(
7971
+ `\u26A0 Planner stats collection timed out after ${timeoutMs}ms, using defaults`
7972
+ );
7973
+ resolve3(void 0);
7974
+ }, timeoutMs);
7975
+ if (typeof id === "object" && "unref" in id) id.unref();
7976
+ });
7977
+ try {
7978
+ const result = yield Promise.race([work(), timeout]);
7979
+ if (settled) return void 0;
7980
+ return result;
7981
+ } catch (error) {
7982
+ if (!settled) {
7983
+ console.warn(
7984
+ "\u26A0 Failed to collect planner stats:",
7985
+ error instanceof Error ? error.message : error
7986
+ );
7987
+ }
7988
+ return void 0;
7989
+ } finally {
7990
+ if (cleanup) {
7991
+ yield cleanup().catch(() => {
7992
+ });
7993
+ }
7994
+ }
7995
+ });
7996
+ }
8003
7997
  function generateImports(runtimeImportPath) {
8004
7998
  return `import {
8005
7999
  buildSQL,