eslint-plugin-slonik 1.5.1 → 1.6.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.
@@ -1,6 +1,6 @@
1
1
  import * as fp_ts_lib_Either from 'fp-ts/lib/Either';
2
2
  import postgres from 'postgres';
3
- import { R as RuleOptionConnection, a as ConnectionTarget } from '../shared/eslint-plugin-slonik.1m1xlVmw.cjs';
3
+ import { R as RuleOptionConnection, a as ConnectionTarget } from '../shared/eslint-plugin-slonik.uSZXmGoY.cjs';
4
4
  import 'zod';
5
5
 
6
6
  declare class DatabaseInitializationError extends Error {
@@ -1,6 +1,6 @@
1
1
  import * as fp_ts_lib_Either from 'fp-ts/lib/Either';
2
2
  import postgres from 'postgres';
3
- import { R as RuleOptionConnection, a as ConnectionTarget } from '../shared/eslint-plugin-slonik.1m1xlVmw.mjs';
3
+ import { R as RuleOptionConnection, a as ConnectionTarget } from '../shared/eslint-plugin-slonik.uSZXmGoY.mjs';
4
4
  import 'zod';
5
5
 
6
6
  declare class DatabaseInitializationError extends Error {
@@ -1,6 +1,6 @@
1
1
  import * as fp_ts_lib_Either from 'fp-ts/lib/Either';
2
2
  import postgres from 'postgres';
3
- import { R as RuleOptionConnection, a as ConnectionTarget } from '../shared/eslint-plugin-slonik.1m1xlVmw.js';
3
+ import { R as RuleOptionConnection, a as ConnectionTarget } from '../shared/eslint-plugin-slonik.uSZXmGoY.js';
4
4
  import 'zod';
5
5
 
6
6
  declare class DatabaseInitializationError extends Error {
@@ -2263,6 +2263,7 @@ async function getPgTypeExprMap(sql) {
2263
2263
  return map;
2264
2264
  }
2265
2265
 
2266
+ const DEFAULT_CONNECTION_TIMEOUT_MS = 5e3;
2266
2267
  function createConnectionManager() {
2267
2268
  const connectionMap = /* @__PURE__ */ new Map();
2268
2269
  return {
@@ -2276,13 +2277,15 @@ function getOrCreateConnection(databaseUrl, connectionMap, options) {
2276
2277
  O.foldW(
2277
2278
  () => {
2278
2279
  const config = parseConnection(databaseUrl);
2280
+ const timeoutMs = options?.connectionTimeout ?? DEFAULT_CONNECTION_TIMEOUT_MS;
2279
2281
  const sql = postgres({
2280
2282
  host: config.host,
2281
2283
  port: config.port,
2282
2284
  user: config.user,
2283
2285
  password: config.password,
2284
2286
  database: config.database,
2285
- ...options
2287
+ connect_timeout: Math.ceil(timeoutMs / 1e3),
2288
+ ...options?.postgresOptions
2286
2289
  });
2287
2290
  connectionMap.set(databaseUrl, sql);
2288
2291
  return { sql, databaseUrl, isFirst: true };
@@ -2375,17 +2378,21 @@ async function handler(params) {
2375
2378
  runAsWorker(handler);
2376
2379
  function workerHandler(params) {
2377
2380
  const strategy = getConnectionStrategyByRuleOptionConnection(params);
2381
+ const connectionTimeout = params.connection.connectionTimeout;
2378
2382
  const connectionPayload = match(strategy).with(
2379
2383
  { type: "databaseUrl" },
2380
- ({ databaseUrl }) => TE.right(connections.getOrCreate(databaseUrl))
2384
+ ({ databaseUrl }) => TE.right(connections.getOrCreate(databaseUrl, { connectionTimeout }))
2381
2385
  ).with({ type: "migrations" }, ({ migrationsDir, databaseName, connectionUrl }) => {
2382
2386
  const { connectionOptions, databaseUrl } = getMigrationDatabaseMetadata({
2383
2387
  connectionUrl,
2384
2388
  databaseName
2385
2389
  });
2386
- const { sql, isFirst } = connections.getOrCreate(databaseUrl);
2390
+ const { sql, isFirst } = connections.getOrCreate(databaseUrl, { connectionTimeout });
2387
2391
  const { sql: migrationSql } = connections.getOrCreate(connectionUrl, {
2388
- onnotice: () => {
2392
+ connectionTimeout,
2393
+ postgresOptions: {
2394
+ onnotice: () => {
2395
+ }
2389
2396
  }
2390
2397
  });
2391
2398
  const connectionPayload2 = { sql, isFirst, databaseUrl };