@neetru/sdk 3.4.1 → 3.4.2

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.cjs CHANGED
@@ -684,13 +684,17 @@ var init_lease = __esm({
684
684
  // src/db/sql/sql-client.ts
685
685
  var sql_client_exports = {};
686
686
  __export(sql_client_exports, {
687
+ DEFAULT_POOL_CONNECT_TIMEOUT_MS: () => DEFAULT_POOL_CONNECT_TIMEOUT_MS,
688
+ DEFAULT_POOL_IDLE_MS: () => DEFAULT_POOL_IDLE_MS,
689
+ DEFAULT_POOL_MAX: () => DEFAULT_POOL_MAX,
687
690
  LEASE_ENDPOINT: () => LEASE_ENDPOINT,
688
691
  LEASE_RENEW_ENDPOINT: () => LEASE_RENEW_ENDPOINT,
689
692
  createDrizzleHandle: () => createDrizzleHandle,
690
693
  createHttpLeaseFetcher: () => createHttpLeaseFetcher,
691
694
  createPgPool: () => createPgPool,
692
695
  createSqlClientFromConfig: () => createSqlClientFromConfig,
693
- createSqlClientWithDeps: () => createSqlClientWithDeps
696
+ createSqlClientWithDeps: () => createSqlClientWithDeps,
697
+ resolvePoolTuning: () => resolvePoolTuning
694
698
  });
695
699
  function mapEnvToCore(sdkEnv) {
696
700
  if (sdkEnv === "workspace") return "staging";
@@ -779,6 +783,30 @@ function parseLease(raw) {
779
783
  expiresAt: req("expiresAt", "string")
780
784
  };
781
785
  }
786
+ function readEnvInt(name, def, min, max) {
787
+ const raw = typeof process !== "undefined" ? process.env?.[name] : void 0;
788
+ if (raw === void 0 || raw.trim() === "") return def;
789
+ const n = Number.parseInt(raw.trim(), 10);
790
+ if (!Number.isFinite(n) || n < min || n > max) return def;
791
+ return n;
792
+ }
793
+ function resolvePoolTuning() {
794
+ return {
795
+ // Teto 100: bem abaixo do `max_client_conn = 500` do PgBouncer, com folga
796
+ // para múltiplas instâncias do app dividirem o mesmo front-door.
797
+ max: readEnvInt("NEETRU_DB_POOL_MAX", DEFAULT_POOL_MAX, 1, 100),
798
+ // Teto 15min = janela do cert; piso 1s.
799
+ idleTimeoutMillis: readEnvInt("NEETRU_DB_POOL_IDLE_MS", DEFAULT_POOL_IDLE_MS, 1e3, 9e5),
800
+ connectionTimeoutMillis: readEnvInt(
801
+ "NEETRU_DB_POOL_CONNECT_TIMEOUT_MS",
802
+ DEFAULT_POOL_CONNECT_TIMEOUT_MS,
803
+ 1e3,
804
+ 12e4
805
+ ),
806
+ keepAlive: true,
807
+ keepAliveInitialDelayMillis: 1e4
808
+ };
809
+ }
782
810
  async function createPgPool(lease) {
783
811
  const { Pool } = await import(
784
812
  /* webpackIgnore: true */
@@ -797,9 +825,7 @@ async function createPgPool(lease) {
797
825
  user: lease.user,
798
826
  password: lease.password,
799
827
  ssl,
800
- max: 3,
801
- idleTimeoutMillis: 3e4,
802
- connectionTimeoutMillis: 1e4
828
+ ...resolvePoolTuning()
803
829
  });
804
830
  }
805
831
  async function createDrizzleHandle(pool, schema) {
@@ -934,9 +960,9 @@ async function createSqlClientFromConfig(config, schema, options) {
934
960
  user: lease.user,
935
961
  password: lease.password,
936
962
  ssl,
937
- max: 3,
938
- idleTimeoutMillis: 3e4,
939
- connectionTimeoutMillis: 1e4
963
+ // Tuning centralizado (env-tunável) — ver resolvePoolTuning + auditoria
964
+ // docs/_review/AUDITORIA_DB_CONN_PERF_2026-09-06.md no Core.
965
+ ...resolvePoolTuning()
940
966
  });
941
967
  };
942
968
  const createDrizzle = (pool, s) => {
@@ -959,7 +985,7 @@ async function createSqlClientFromConfig(config, schema, options) {
959
985
  options
960
986
  );
961
987
  }
962
- var LEASE_ENDPOINT, LEASE_RENEW_ENDPOINT;
988
+ var LEASE_ENDPOINT, LEASE_RENEW_ENDPOINT, DEFAULT_POOL_MAX, DEFAULT_POOL_IDLE_MS, DEFAULT_POOL_CONNECT_TIMEOUT_MS;
963
989
  var init_sql_client = __esm({
964
990
  "src/db/sql/sql-client.ts"() {
965
991
  init_db_errors();
@@ -968,6 +994,9 @@ var init_sql_client = __esm({
968
994
  init_resilient_pool();
969
995
  LEASE_ENDPOINT = "/api/sdk/v1/db/lease";
970
996
  LEASE_RENEW_ENDPOINT = "/api/sdk/v1/db/lease/renew";
997
+ DEFAULT_POOL_MAX = 10;
998
+ DEFAULT_POOL_IDLE_MS = 6e4;
999
+ DEFAULT_POOL_CONNECT_TIMEOUT_MS = 1e4;
971
1000
  }
972
1001
  });
973
1002