relq 1.0.85 → 1.0.87

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.
Files changed (72) hide show
  1. package/dist/cjs/cli/commands/export.cjs +2 -2
  2. package/dist/cjs/cli/commands/generate.cjs +2 -2
  3. package/dist/cjs/cli/commands/import.cjs +2 -2
  4. package/dist/cjs/cli/commands/init.cjs +2 -2
  5. package/dist/cjs/cli/commands/introspect.cjs +2 -2
  6. package/dist/cjs/cli/commands/migrate.cjs +2 -2
  7. package/dist/cjs/cli/commands/pull.cjs +2 -2
  8. package/dist/cjs/cli/commands/push.cjs +2 -2
  9. package/dist/cjs/cli/commands/rollback.cjs +2 -2
  10. package/dist/cjs/cli/commands/seed.cjs +2 -2
  11. package/dist/cjs/cli/commands/status.cjs +2 -2
  12. package/dist/cjs/cli/commands/validate.cjs +1 -1
  13. package/dist/cjs/cli/utils/change-tracker.cjs +1 -1
  14. package/dist/cjs/cli/utils/commit-manager.cjs +3 -3
  15. package/dist/cjs/cli/utils/config-loader.cjs +2 -2
  16. package/dist/cjs/cli/utils/context.cjs +2 -2
  17. package/dist/cjs/cli/utils/project-root.cjs +3 -3
  18. package/dist/cjs/cli/utils/relqignore.cjs +2 -2
  19. package/dist/cjs/cli/utils/repo-manager.cjs +3 -3
  20. package/dist/cjs/cli/utils/schema-hash.cjs +1 -1
  21. package/dist/cjs/cli/utils/schema-loader.cjs +2 -2
  22. package/dist/cjs/cli/utils/schema-validator.cjs +2 -2
  23. package/dist/cjs/cli/utils/snapshot-manager.cjs +2 -2
  24. package/dist/cjs/cli/utils/types-manager.cjs +2 -2
  25. package/dist/cjs/config/config.cjs +5 -1
  26. package/dist/cjs/config/env.cjs +7 -3
  27. package/dist/cjs/core/helpers/select-joins.cjs +8 -3
  28. package/dist/cjs/core/pg-family/shared/pg-base.cjs +5 -18
  29. package/dist/cjs/core/shared/cleanup.cjs +6 -2
  30. package/dist/cjs/errors/relq-errors.cjs +9 -5
  31. package/dist/cjs/pubsub/listener-connection.cjs +3 -3
  32. package/dist/cjs/utils/aws-dsql.cjs +8 -4
  33. package/dist/cjs/utils/env-resolver.cjs +19 -15
  34. package/dist/cjs/utils/environment-detection.cjs +27 -23
  35. package/dist/cjs/utils/pool-defaults.cjs +8 -23
  36. package/dist/esm/cli/commands/export.js +2 -2
  37. package/dist/esm/cli/commands/generate.js +2 -2
  38. package/dist/esm/cli/commands/import.js +2 -2
  39. package/dist/esm/cli/commands/init.js +2 -2
  40. package/dist/esm/cli/commands/introspect.js +2 -2
  41. package/dist/esm/cli/commands/migrate.js +2 -2
  42. package/dist/esm/cli/commands/pull.js +2 -2
  43. package/dist/esm/cli/commands/push.js +2 -2
  44. package/dist/esm/cli/commands/rollback.js +2 -2
  45. package/dist/esm/cli/commands/seed.js +2 -2
  46. package/dist/esm/cli/commands/status.js +2 -2
  47. package/dist/esm/cli/commands/validate.js +1 -1
  48. package/dist/esm/cli/utils/change-tracker.js +1 -1
  49. package/dist/esm/cli/utils/commit-manager.js +3 -3
  50. package/dist/esm/cli/utils/config-loader.js +2 -2
  51. package/dist/esm/cli/utils/context.js +2 -2
  52. package/dist/esm/cli/utils/project-root.js +3 -3
  53. package/dist/esm/cli/utils/relqignore.js +2 -2
  54. package/dist/esm/cli/utils/repo-manager.js +3 -3
  55. package/dist/esm/cli/utils/schema-hash.js +1 -1
  56. package/dist/esm/cli/utils/schema-loader.js +2 -2
  57. package/dist/esm/cli/utils/schema-validator.js +2 -2
  58. package/dist/esm/cli/utils/snapshot-manager.js +2 -2
  59. package/dist/esm/cli/utils/types-manager.js +2 -2
  60. package/dist/esm/config/config.js +1 -0
  61. package/dist/esm/config/env.js +1 -0
  62. package/dist/esm/core/helpers/select-joins.js +8 -3
  63. package/dist/esm/core/pg-family/shared/pg-base.js +6 -19
  64. package/dist/esm/core/shared/cleanup.js +1 -0
  65. package/dist/esm/errors/relq-errors.js +1 -0
  66. package/dist/esm/pubsub/listener-connection.js +1 -1
  67. package/dist/esm/utils/aws-dsql.js +1 -0
  68. package/dist/esm/utils/env-resolver.js +3 -2
  69. package/dist/esm/utils/environment-detection.js +1 -0
  70. package/dist/esm/utils/pool-defaults.js +8 -23
  71. package/dist/index.d.ts +71 -52
  72. package/package.json +1 -1
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.loadEnvFile = loadEnvFile;
4
7
  exports.resolvePgEnv = resolvePgEnv;
@@ -8,9 +11,10 @@ exports.hasAwsEnvConfig = hasAwsEnvConfig;
8
11
  exports.validateEnvConfig = validateEnvConfig;
9
12
  exports.mergeWithPgEnv = mergeWithPgEnv;
10
13
  exports.mergeWithAwsEnv = mergeWithAwsEnv;
14
+ const node_process_1 = __importDefault(require("node:process"));
11
15
  const relq_errors_1 = require("../errors/relq-errors.cjs");
12
- const fs_1 = require("fs");
13
- const path_1 = require("path");
16
+ const node_fs_1 = require("node:fs");
17
+ const node_path_1 = require("node:path");
14
18
  let envLoaded = false;
15
19
  function parseEnvFile(content) {
16
20
  const result = {};
@@ -33,35 +37,35 @@ function parseEnvFile(content) {
33
37
  return result;
34
38
  }
35
39
  function findEnvFile(startDir) {
36
- let currentDir = (0, path_1.resolve)(startDir);
40
+ let currentDir = (0, node_path_1.resolve)(startDir);
37
41
  let prevDir = '';
38
42
  while (currentDir !== prevDir) {
39
- const envPath = (0, path_1.join)(currentDir, '.env');
40
- if ((0, fs_1.existsSync)(envPath)) {
43
+ const envPath = (0, node_path_1.join)(currentDir, '.env');
44
+ if ((0, node_fs_1.existsSync)(envPath)) {
41
45
  return envPath;
42
46
  }
43
- const pkgPath = (0, path_1.join)(currentDir, 'package.json');
44
- if ((0, fs_1.existsSync)(pkgPath)) {
47
+ const pkgPath = (0, node_path_1.join)(currentDir, 'package.json');
48
+ if ((0, node_fs_1.existsSync)(pkgPath)) {
45
49
  return null;
46
50
  }
47
51
  prevDir = currentDir;
48
- currentDir = (0, path_1.dirname)(currentDir);
52
+ currentDir = (0, node_path_1.dirname)(currentDir);
49
53
  }
50
54
  return null;
51
55
  }
52
56
  function loadEnvFile(path) {
53
- if (typeof process === 'undefined' || !process.env) {
57
+ if (typeof node_process_1.default === 'undefined' || !node_process_1.default.env) {
54
58
  return {};
55
59
  }
56
60
  try {
57
- const envPath = path ?? findEnvFile(process.cwd());
61
+ const envPath = path ?? findEnvFile(node_process_1.default.cwd());
58
62
  if (!envPath)
59
63
  return {};
60
- const content = (0, fs_1.readFileSync)(envPath, 'utf-8');
64
+ const content = (0, node_fs_1.readFileSync)(envPath, 'utf-8');
61
65
  const vars = parseEnvFile(content);
62
66
  for (const [key, value] of Object.entries(vars)) {
63
- if (process.env[key] === undefined) {
64
- process.env[key] = value;
67
+ if (node_process_1.default.env[key] === undefined) {
68
+ node_process_1.default.env[key] = value;
65
69
  }
66
70
  }
67
71
  return vars;
@@ -78,11 +82,11 @@ function ensureEnvLoaded() {
78
82
  }
79
83
  ensureEnvLoaded();
80
84
  function getEnv(key) {
81
- if (typeof process === 'undefined' || !process.env) {
85
+ if (typeof node_process_1.default === 'undefined' || !node_process_1.default.env) {
82
86
  return undefined;
83
87
  }
84
88
  ensureEnvLoaded();
85
- return process.env[key];
89
+ return node_process_1.default.env[key];
86
90
  }
87
91
  function getEnvNumber(key) {
88
92
  const val = getEnv(key);
@@ -1,13 +1,17 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.detectEnvironment = detectEnvironment;
4
7
  exports.isServerless = isServerless;
5
8
  exports.isTraditional = isTraditional;
6
9
  exports.isEdge = isEdge;
7
10
  exports.getEnvironmentDescription = getEnvironmentDescription;
11
+ const node_process_1 = __importDefault(require("node:process"));
8
12
  function detectEnvironment() {
9
13
  const detected = [];
10
- const hasProcess = typeof process !== 'undefined' && process.env !== undefined;
14
+ const hasProcess = typeof node_process_1.default !== 'undefined' && node_process_1.default.env !== undefined;
11
15
  if (!hasProcess) {
12
16
  return {
13
17
  type: 'edge',
@@ -16,10 +20,10 @@ function detectEnvironment() {
16
20
  hasProcess: false
17
21
  };
18
22
  }
19
- if (process.env.VERCEL || process.env.VERCEL_ENV) {
20
- if (process.env.VERCEL)
23
+ if (node_process_1.default.env.VERCEL || node_process_1.default.env.VERCEL_ENV) {
24
+ if (node_process_1.default.env.VERCEL)
21
25
  detected.push('VERCEL');
22
- if (process.env.VERCEL_ENV)
26
+ if (node_process_1.default.env.VERCEL_ENV)
23
27
  detected.push('VERCEL_ENV');
24
28
  return {
25
29
  type: 'serverless',
@@ -28,14 +32,14 @@ function detectEnvironment() {
28
32
  hasProcess: true
29
33
  };
30
34
  }
31
- if (process.env.AWS_LAMBDA_FUNCTION_NAME ||
32
- process.env.AWS_EXECUTION_ENV ||
33
- process.env.LAMBDA_TASK_ROOT) {
34
- if (process.env.AWS_LAMBDA_FUNCTION_NAME)
35
+ if (node_process_1.default.env.AWS_LAMBDA_FUNCTION_NAME ||
36
+ node_process_1.default.env.AWS_EXECUTION_ENV ||
37
+ node_process_1.default.env.LAMBDA_TASK_ROOT) {
38
+ if (node_process_1.default.env.AWS_LAMBDA_FUNCTION_NAME)
35
39
  detected.push('AWS_LAMBDA_FUNCTION_NAME');
36
- if (process.env.AWS_EXECUTION_ENV)
40
+ if (node_process_1.default.env.AWS_EXECUTION_ENV)
37
41
  detected.push('AWS_EXECUTION_ENV');
38
- if (process.env.LAMBDA_TASK_ROOT)
42
+ if (node_process_1.default.env.LAMBDA_TASK_ROOT)
39
43
  detected.push('LAMBDA_TASK_ROOT');
40
44
  return {
41
45
  type: 'serverless',
@@ -44,10 +48,10 @@ function detectEnvironment() {
44
48
  hasProcess: true
45
49
  };
46
50
  }
47
- if (process.env.NETLIFY || process.env.NETLIFY_DEV) {
48
- if (process.env.NETLIFY)
51
+ if (node_process_1.default.env.NETLIFY || node_process_1.default.env.NETLIFY_DEV) {
52
+ if (node_process_1.default.env.NETLIFY)
49
53
  detected.push('NETLIFY');
50
- if (process.env.NETLIFY_DEV)
54
+ if (node_process_1.default.env.NETLIFY_DEV)
51
55
  detected.push('NETLIFY_DEV');
52
56
  return {
53
57
  type: 'serverless',
@@ -56,12 +60,12 @@ function detectEnvironment() {
56
60
  hasProcess: true
57
61
  };
58
62
  }
59
- if (process.env.FUNCTION_NAME || process.env.FUNCTION_TARGET || process.env.GCP_PROJECT) {
60
- if (process.env.FUNCTION_NAME)
63
+ if (node_process_1.default.env.FUNCTION_NAME || node_process_1.default.env.FUNCTION_TARGET || node_process_1.default.env.GCP_PROJECT) {
64
+ if (node_process_1.default.env.FUNCTION_NAME)
61
65
  detected.push('FUNCTION_NAME');
62
- if (process.env.FUNCTION_TARGET)
66
+ if (node_process_1.default.env.FUNCTION_TARGET)
63
67
  detected.push('FUNCTION_TARGET');
64
- if (process.env.GCP_PROJECT)
68
+ if (node_process_1.default.env.GCP_PROJECT)
65
69
  detected.push('GCP_PROJECT');
66
70
  return {
67
71
  type: 'serverless',
@@ -70,10 +74,10 @@ function detectEnvironment() {
70
74
  hasProcess: true
71
75
  };
72
76
  }
73
- if (process.env.AZURE_FUNCTIONS_ENVIRONMENT || process.env.WEBSITE_INSTANCE_ID) {
74
- if (process.env.AZURE_FUNCTIONS_ENVIRONMENT)
77
+ if (node_process_1.default.env.AZURE_FUNCTIONS_ENVIRONMENT || node_process_1.default.env.WEBSITE_INSTANCE_ID) {
78
+ if (node_process_1.default.env.AZURE_FUNCTIONS_ENVIRONMENT)
75
79
  detected.push('AZURE_FUNCTIONS_ENVIRONMENT');
76
- if (process.env.WEBSITE_INSTANCE_ID)
80
+ if (node_process_1.default.env.WEBSITE_INSTANCE_ID)
77
81
  detected.push('WEBSITE_INSTANCE_ID');
78
82
  return {
79
83
  type: 'serverless',
@@ -82,10 +86,10 @@ function detectEnvironment() {
82
86
  hasProcess: true
83
87
  };
84
88
  }
85
- if (process.env.CLOUDFLARE_WORKERS || process.env.CF_PAGES) {
86
- if (process.env.CLOUDFLARE_WORKERS)
89
+ if (node_process_1.default.env.CLOUDFLARE_WORKERS || node_process_1.default.env.CF_PAGES) {
90
+ if (node_process_1.default.env.CLOUDFLARE_WORKERS)
87
91
  detected.push('CLOUDFLARE_WORKERS');
88
- if (process.env.CF_PAGES)
92
+ if (node_process_1.default.env.CF_PAGES)
89
93
  detected.push('CF_PAGES');
90
94
  return {
91
95
  type: 'edge',
@@ -11,24 +11,14 @@ function getSmartPoolDefaults() {
11
11
  min: 0,
12
12
  idleTimeoutMillis: 10000,
13
13
  connectionTimeoutMillis: 10000,
14
- pool: false
15
14
  };
16
- if (env.type === 'serverless') {
15
+ if (env.type === 'serverless' || env.type === 'edge') {
17
16
  return {
18
17
  ...baseConfig,
19
18
  max: 1,
20
19
  idleTimeoutMillis: 1000,
21
- recommendation: `Serverless environment detected (${env.provider}).\n` +
22
- ' Using single connection mode (recommended).\n' +
23
- ' If pooling enabled: min: 0, max: 1'
24
- };
25
- }
26
- if (env.type === 'edge') {
27
- return {
28
- ...baseConfig,
29
- max: 0,
30
- recommendation: 'Edge runtime detected. PostgreSQL connections not supported.\n' +
31
- ' Use query builder only: relq("table").select().toString()'
20
+ recommendation: `${env.type === 'serverless' ? 'Serverless' : 'Edge'} environment detected (${env.provider}).\n` +
21
+ ' Pool: min: 0, max: 1 (single lazy connection per invocation)'
32
22
  };
33
23
  }
34
24
  return {
@@ -36,8 +26,7 @@ function getSmartPoolDefaults() {
36
26
  max: 10,
37
27
  idleTimeoutMillis: 30000,
38
28
  recommendation: 'Traditional server environment.\n' +
39
- ' Pooling disabled by default (single client).\n' +
40
- ' To enable pooling: new Relq(schema, { pool: true, ... })'
29
+ ' Pool: min: 0, max: 10 (connections created on demand, scale under load)'
41
30
  };
42
31
  }
43
32
  function validatePoolConfig(config, env) {
@@ -45,15 +34,11 @@ function validatePoolConfig(config, env) {
45
34
  const errors = [];
46
35
  const min = config.min ?? 0;
47
36
  const max = config.max ?? 10;
48
- if (env.type === 'edge') {
49
- errors.push('āŒ Edge runtime detected (Cloudflare Workers/Deno Deploy).\n' +
50
- ' PostgreSQL connections are not supported in edge runtimes.\n' +
37
+ if (env.type === 'edge' && max > 1) {
38
+ warnings.push(`āš ļø Running in ${env.provider} (edge) with pool max: ${max}.\n` +
39
+ ' Edge runtimes have short-lived connections.\n' +
51
40
  ' \n' +
52
- ' Options:\n' +
53
- ' 1. Use query builder only: relq("table").select().toString()\n' +
54
- ' 2. Use HTTP-based database (Supabase, Neon, Xata)\n' +
55
- ' 3. Deploy to traditional Node.js runtime');
56
- return { valid: false, warnings, errors };
41
+ ' Recommended: pool: { min: 0, max: 1 }');
57
42
  }
58
43
  if (min > max) {
59
44
  warnings.push(`āš ļø Pool min (${min}) is greater than max (${max}).\n` +
@@ -1,6 +1,6 @@
1
1
  import { defineCommand } from 'citty';
2
- import * as fs from 'fs';
3
- import * as path from 'path';
2
+ import * as fs from 'node:fs';
3
+ import * as path from 'node:path';
4
4
  import * as p from '@clack/prompts';
5
5
  import { buildContext } from "../utils/context.js";
6
6
  import { colors } from "../utils/colors.js";
@@ -1,6 +1,6 @@
1
1
  import { defineCommand } from 'citty';
2
- import * as fs from 'fs';
3
- import * as path from 'path';
2
+ import * as fs from 'node:fs';
3
+ import * as path from 'node:path';
4
4
  import * as p from '@clack/prompts';
5
5
  import { buildContext } from "../utils/context.js";
6
6
  import { colors } from "../utils/colors.js";
@@ -1,5 +1,5 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
3
  import * as p from '@clack/prompts';
4
4
  import { defineCommand } from 'citty';
5
5
  import { parseFunctions, parseTriggers, parseComments } from "../utils/sql-parser.js";
@@ -1,5 +1,5 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
3
  import * as p from '@clack/prompts';
4
4
  import { defineCommand } from 'citty';
5
5
  import { loadEnvConfig } from "../utils/env-loader.js";
@@ -1,6 +1,6 @@
1
1
  import { defineCommand } from 'citty';
2
- import * as fs from 'fs';
3
- import * as readline from 'readline';
2
+ import * as fs from 'node:fs';
3
+ import * as readline from 'node:readline';
4
4
  import { buildContext } from "../utils/context.js";
5
5
  import { fatal, formatError } from "../utils/ui.js";
6
6
  import { parseSqlToDefineTable } from "../../introspect/index.js";
@@ -1,6 +1,6 @@
1
1
  import { defineCommand } from 'citty';
2
- import * as fs from 'fs';
3
- import * as path from 'path';
2
+ import * as fs from 'node:fs';
3
+ import * as path from 'node:path';
4
4
  import * as p from '@clack/prompts';
5
5
  import { buildContext } from "../utils/context.js";
6
6
  import { colors } from "../utils/colors.js";
@@ -1,5 +1,5 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
3
  import { defineCommand } from 'citty';
4
4
  import * as p from '@clack/prompts';
5
5
  import { buildContext } from "../utils/context.js";
@@ -1,6 +1,6 @@
1
1
  import { defineCommand } from 'citty';
2
- import * as fs from 'fs';
3
- import * as path from 'path';
2
+ import * as fs from 'node:fs';
3
+ import * as path from 'node:path';
4
4
  import * as p from '@clack/prompts';
5
5
  import { buildContext } from "../utils/context.js";
6
6
  import { colors } from "../utils/colors.js";
@@ -1,6 +1,6 @@
1
1
  import { defineCommand } from 'citty';
2
- import * as fs from 'fs';
3
- import * as path from 'path';
2
+ import * as fs from 'node:fs';
3
+ import * as path from 'node:path';
4
4
  import * as p from '@clack/prompts';
5
5
  import { buildContext } from "../utils/context.js";
6
6
  import { colors } from "../utils/colors.js";
@@ -1,6 +1,6 @@
1
1
  import { defineCommand } from 'citty';
2
- import * as fs from 'fs';
3
- import * as path from 'path';
2
+ import * as fs from 'node:fs';
3
+ import * as path from 'node:path';
4
4
  import * as p from '@clack/prompts';
5
5
  import { buildContext } from "../utils/context.js";
6
6
  import { colors } from "../utils/colors.js";
@@ -1,6 +1,6 @@
1
1
  import { defineCommand } from 'citty';
2
- import * as fs from 'fs';
3
- import * as path from 'path';
2
+ import * as fs from 'node:fs';
3
+ import * as path from 'node:path';
4
4
  import { buildContext } from "../utils/context.js";
5
5
  import { colors } from "../utils/colors.js";
6
6
  import { fatal } from "../utils/ui.js";
@@ -1,5 +1,5 @@
1
1
  import { defineCommand } from 'citty';
2
- import * as path from 'path';
2
+ import * as path from 'node:path';
3
3
  import { buildContext } from "../utils/context.js";
4
4
  import { colors } from "../utils/colors.js";
5
5
  import { getSchemaPath } from "../utils/config-loader.js";
@@ -1,4 +1,4 @@
1
- import * as crypto from 'crypto';
1
+ import * as crypto from 'node:crypto';
2
2
  export function generateChangeId(type, objectType, objectName, parentName) {
3
3
  const input = `${type}:${objectType}:${parentName || ''}:${objectName}:${Date.now()}`;
4
4
  return crypto.createHash('sha1').update(input).digest('hex').substring(0, 12);
@@ -1,6 +1,6 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import * as crypto from 'crypto';
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import * as crypto from 'node:crypto';
4
4
  import { buildPoolConfig } from "../../config/index.js";
5
5
  import { detectDialect } from "./dialect-router.js";
6
6
  import { normalizeSchema, generateSchemaHash } from "./schema-hash.js";
@@ -1,8 +1,8 @@
1
1
  import { loadConfig as baseLoadConfig } from "../../config/config.js";
2
2
  import { fatal } from "./ui.js";
3
3
  import { loadEnvConfig } from "./env-loader.js";
4
- import * as fs from 'fs';
5
- import * as path from 'path';
4
+ import * as fs from 'node:fs';
5
+ import * as path from 'node:path';
6
6
  const CONFIG_FILENAMES = [
7
7
  'relq.config.ts',
8
8
  'relq.config.mjs',
@@ -1,5 +1,5 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
3
  import { findProjectRoot } from "./project-root.js";
4
4
  import { findConfigFileRecursive, loadConfigWithEnv } from "./config-loader.js";
5
5
  import { fatal } from "./ui.js";
@@ -1,6 +1,6 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import * as os from 'os';
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import * as os from 'node:os';
4
4
  const CONFIG_FILENAMES = [
5
5
  'relq.config.ts',
6
6
  'relq.config.mjs',
@@ -1,5 +1,5 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
3
  const REQUIRES_PARENT = [
4
4
  'COLUMN', 'INDEX', 'CONSTRAINT', 'CHECK', 'PRIMARY_KEY',
5
5
  'FOREIGN_KEY', 'EXCLUSION', 'PARTITION', 'TRIGGER'
@@ -1,6 +1,6 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import * as crypto from 'crypto';
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import * as crypto from 'node:crypto';
4
4
  import { buildPoolConfig } from "../../config/config.js";
5
5
  import { detectDialect } from "./dialect-router.js";
6
6
  const RELQ_DIR = '.relq';
@@ -1,4 +1,4 @@
1
- import * as crypto from 'crypto';
1
+ import * as crypto from 'node:crypto';
2
2
  export function normalizeSchema(schema) {
3
3
  const userTables = schema.tables.filter(t => !t.name.startsWith('_relq') &&
4
4
  !t.name.startsWith('relq_'));
@@ -1,5 +1,5 @@
1
- import * as path from 'path';
2
- import * as fs from 'fs';
1
+ import * as path from 'node:path';
2
+ import * as fs from 'node:fs';
3
3
  import { createJiti } from 'jiti';
4
4
  import { schemaToAST, parsedTableToTableInfo } from "./schema-to-ast.js";
5
5
  function hasMissingTrackingIds(ast) {
@@ -1,6 +1,6 @@
1
1
  import * as ts from 'typescript';
2
- import * as fs from 'fs';
3
- import * as path from 'path';
2
+ import * as fs from 'node:fs';
3
+ import * as path from 'node:path';
4
4
  export function validateSchemaFile(schemaPath) {
5
5
  const absolutePath = path.resolve(schemaPath);
6
6
  if (!fs.existsSync(absolutePath)) {
@@ -1,5 +1,5 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
3
  const SNAPSHOT_VERSION = 1;
4
4
  const DEFAULT_SNAPSHOT_PATH = '.relq/snapshot.json';
5
5
  export function loadSnapshot(snapshotPath) {
@@ -1,5 +1,5 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
3
  import { buildPoolConfig } from "../../config/config.js";
4
4
  import { detectDialect } from "./dialect-router.js";
5
5
  function getCreateTableSql(isDsql) {
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import { join, dirname, parse, basename } from 'node:path';
2
3
  import { existsSync, statSync } from 'node:fs';
3
4
  import { createJiti } from 'jiti';
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import { DEFAULT_DIALECT } from "./types.js";
2
3
  import { parseConnectionUrl } from "./url-parser.js";
3
4
  export const ENV_VARS = {
@@ -21,7 +21,12 @@ export function executeTypeSafeJoin(ctx, joinType, tableOrAlias, callback) {
21
21
  const rightProxy = createTableProxy(rightTableName, rightAlias, rightTableDef);
22
22
  const conditionBuilder = new JoinConditionBuilder();
23
23
  if (callback) {
24
- callback(conditionBuilder, leftProxy, rightProxy);
24
+ if (joinType === 'RIGHT JOIN') {
25
+ callback(conditionBuilder, leftProxy, rightProxy);
26
+ }
27
+ else {
28
+ callback(conditionBuilder, rightProxy, leftProxy);
29
+ }
25
30
  }
26
31
  const conditionInternals = conditionBuilder[JOIN_INTERNAL];
27
32
  if (!conditionInternals.hasConditions() && schema && relations) {
@@ -33,7 +38,7 @@ export function executeTypeSafeJoin(ctx, joinType, tableOrAlias, callback) {
33
38
  }
34
39
  else {
35
40
  throw new RelqQueryError(`Cannot auto-resolve FK relationship between "${ctx.schemaKey || ctx.tableName}" and "${rightTableKey}". ` +
36
- `Either provide a callback with explicit join conditions, or define the relationship in your relations config.`, { hint: `Use .join('${rightTableKey}', (on, left, right) => on.equal(left.columnName, right.id))` });
41
+ `Either provide a callback with explicit join conditions, or define the relationship in your relations config.`, { hint: `Use .join('${rightTableKey}', (on, ${rightTableKey}, source) => on.equal(${rightTableKey}.id, source.columnName))` });
37
42
  }
38
43
  }
39
44
  const selectedProps = conditionInternals.getSelectedColumns();
@@ -89,7 +94,7 @@ export function executeTypeSafeJoinMany(ctx, joinType, tableOrAlias, callback) {
89
94
  };
90
95
  };
91
96
  conditionBuilder[JOIN_SETUP](proxyCreator, rightProxy);
92
- callback(conditionBuilder, leftProxy, rightProxy);
97
+ callback(conditionBuilder, rightProxy, leftProxy);
93
98
  const lateralSQL = buildLateralSubquery(rightTableName, rightAlias, conditionBuilder, rightTableDef);
94
99
  const lateralJoinType = joinType === 'LEFT JOIN' ? 'LEFT JOIN LATERAL' : 'JOIN LATERAL';
95
100
  const joinClause = {
@@ -1,9 +1,8 @@
1
1
  import { toPoolConfig, isAwsDsqlConfig } from "../../../types/config-types.js";
2
2
  import { getAwsDsqlToken } from "../../../utils/aws-dsql.js";
3
3
  import { RelqConfigError, RelqConnectionError, parsePostgresError } from "../../../errors/relq-errors.js";
4
- import { detectEnvironment, getEnvironmentDescription } from "../../../utils/environment-detection.js";
4
+ import { detectEnvironment } from "../../../utils/environment-detection.js";
5
5
  import { validatePoolConfig, formatPoolConfig, getSmartPoolDefaults } from "../../../utils/pool-defaults.js";
6
- import { RelqEnvironmentError } from "../../../errors/relq-errors.js";
7
6
  import { debugLog } from "../../helpers/methods.js";
8
7
  import { RelqBase } from "../../relq-base.js";
9
8
  import { pgDialect } from "./pg-dialect.js";
@@ -168,19 +167,11 @@ export class PgBase extends RelqBase {
168
167
  return config.pooling;
169
168
  if (config.disableSmartDefaults)
170
169
  return true;
171
- return this.environment.type === 'traditional';
170
+ return true;
172
171
  }
173
172
  validateConfiguration() {
174
173
  if (this.config.disableSmartDefaults)
175
174
  return;
176
- if (this.environment.type === 'edge') {
177
- throw new RelqEnvironmentError('Cannot use Relq with database connections in edge runtime.\n' +
178
- 'Edge runtimes (Cloudflare Workers, Deno Deploy) do not support TCP connections.\n\n' +
179
- 'Options:\n' +
180
- '1. Use query builder only: relq("table").select().toString()\n' +
181
- '2. Use HTTP-based database (Supabase, Neon, Xata)\n' +
182
- '3. Deploy to Node.js runtime', getEnvironmentDescription(this.environment), 'No TCP/PostgreSQL support');
183
- }
184
175
  const poolConfig = {
185
176
  min: this.config.pool?.min,
186
177
  max: this.config.pool?.max
@@ -211,20 +202,16 @@ export class PgBase extends RelqBase {
211
202
  idleTimeoutMillis: this.config.pool?.idleTimeoutMillis ?? smartDefaults.idleTimeoutMillis,
212
203
  connectionTimeoutMillis: this.config.pool?.connectionTimeoutMillis ?? smartDefaults.connectionTimeoutMillis
213
204
  });
214
- if (this.environment.type === 'serverless') {
205
+ if (this.environment.type === 'serverless' || this.environment.type === 'edge') {
215
206
  if (logLevel === 'info' || logLevel === 'debug') {
216
- console.log(`\nšŸ”µ Relq: ${this.environment.provider} detected (serverless)\n` +
217
- ` Pooling: ${this.usePooling ? 'enabled' : 'disabled'}\n` +
218
- ` Pool config: ${poolConfig}\n` +
219
- ` Recommendation: Use min: 0, max: 1 for serverless`);
207
+ console.log(`\nšŸ”µ Relq: ${this.environment.provider} detected (${this.environment.type})\n` +
208
+ ` Pool config: ${poolConfig}`);
220
209
  }
221
210
  }
222
211
  else if (this.environment.type === 'traditional') {
223
212
  if (logLevel === 'debug') {
224
213
  console.log(`\n🟢 Relq: Traditional server environment\n` +
225
- ` Pooling: ${this.usePooling ? 'enabled' : 'disabled'}\n` +
226
- ` Pool config: ${poolConfig}\n` +
227
- ` Connections created on demand, scale up under load`);
214
+ ` Pool config: ${poolConfig}`);
228
215
  }
229
216
  }
230
217
  }
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  export const activeInstances = new Set();
2
3
  let cleanupHandlersRegistered = false;
3
4
  export function registerGlobalCleanupHandlers() {
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  export function setupErrorHandler() {
2
3
  if (typeof process === 'undefined' || !process.on)
3
4
  return;
@@ -1,4 +1,4 @@
1
- import { EventEmitter } from 'events';
1
+ import { EventEmitter } from 'node:events';
2
2
  import { Client } from 'pg';
3
3
  import format from "../utils/pg-format.js";
4
4
  export class ListenerConnection extends EventEmitter {
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import { existsSync, mkdirSync, readFileSync, writeFileSync, accessSync } from 'node:fs';
2
3
  import { join } from 'node:path';
3
4
  import { tmpdir } from 'node:os';
@@ -1,6 +1,7 @@
1
+ import process from 'node:process';
1
2
  import { RelqConfigError } from "../errors/relq-errors.js";
2
- import { existsSync, readFileSync } from 'fs';
3
- import { join, dirname, resolve } from 'path';
3
+ import { existsSync, readFileSync } from 'node:fs';
4
+ import { join, dirname, resolve } from 'node:path';
4
5
  let envLoaded = false;
5
6
  function parseEnvFile(content) {
6
7
  const result = {};
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  export function detectEnvironment() {
2
3
  const detected = [];
3
4
  const hasProcess = typeof process !== 'undefined' && process.env !== undefined;