supabase-test 0.4.9 → 0.4.10

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/connect.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { getConnections as getPgConnections, type GetConnectionOpts, type GetConnectionResult } from 'pgsql-test';
2
2
  /**
3
3
  * Get connections with Supabase defaults applied.
4
- * Environment variables take precedence over Supabase defaults.
5
- * User-provided options take precedence over both.
4
+ * Uses deepmerge for proper nested config merging.
6
5
  *
7
- * Note: Uses PGUSER/PGPASSWORD for both pg config and db.connection
8
- * (DB_CONNECTION_ROLE can still be used to override the default role)
6
+ * Precedence (later wins):
7
+ * 1. Supabase defaults
8
+ * 2. Environment variables (PGUSER/PGPASSWORD)
9
+ * 3. User-provided options
9
10
  */
10
11
  export declare const getConnections: (cn?: GetConnectionOpts, seedAdapters?: Parameters<typeof getPgConnections>[1]) => Promise<GetConnectionResult>;
11
12
  export type { GetConnectionOpts, GetConnectionResult };
package/connect.js CHANGED
@@ -1,6 +1,10 @@
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.getConnections = void 0;
7
+ const deepmerge_1 = __importDefault(require("deepmerge"));
4
8
  const pg_env_1 = require("pg-env");
5
9
  const pgsql_test_1 = require("pgsql-test");
6
10
  /**
@@ -12,6 +16,12 @@ const SUPABASE_DEFAULTS = {
12
16
  authenticated: 'authenticated',
13
17
  administrator: 'service_role',
14
18
  default: 'anon',
19
+ },
20
+ connections: {
21
+ app: {
22
+ user: 'supabase_admin',
23
+ password: 'postgres',
24
+ }
15
25
  }
16
26
  };
17
27
  /**
@@ -24,47 +34,35 @@ const SUPABASE_PG_DEFAULTS = {
24
34
  };
25
35
  /**
26
36
  * Get connections with Supabase defaults applied.
27
- * Environment variables take precedence over Supabase defaults.
28
- * User-provided options take precedence over both.
37
+ * Uses deepmerge for proper nested config merging.
29
38
  *
30
- * Note: Uses PGUSER/PGPASSWORD for both pg config and db.connection
31
- * (DB_CONNECTION_ROLE can still be used to override the default role)
39
+ * Precedence (later wins):
40
+ * 1. Supabase defaults
41
+ * 2. Environment variables (PGUSER/PGPASSWORD)
42
+ * 3. User-provided options
32
43
  */
33
44
  const getConnections = async (cn = {}, seedAdapters) => {
34
- // Get environment variables - these should take precedence over our defaults
45
+ // Get environment variables (only includes defined keys)
35
46
  const pgEnvVars = (0, pg_env_1.getPgEnvVars)();
36
- // Build pg config: env vars > Supabase defaults, then user overrides will override both
37
- const pgConfig = {};
38
- pgConfig.port = pgEnvVars.port ?? SUPABASE_PG_DEFAULTS.port;
39
- pgConfig.user = pgEnvVars.user ?? SUPABASE_PG_DEFAULTS.user;
40
- pgConfig.password = pgEnvVars.password ?? SUPABASE_PG_DEFAULTS.password;
41
- // Build connection config: use same user/password as pg config (from env vars or Supabase defaults)
42
- // Default role is 'anon' (Supabase default), but DB_CONNECTION_ROLE can override it
43
- const connectionConfig = {
44
- role: process.env.DB_CONNECTION_ROLE ?? SUPABASE_DEFAULTS.roles.default,
45
- };
46
- // Build roles config: Supabase defaults, then user overrides will override
47
- const rolesConfig = {
48
- ...SUPABASE_DEFAULTS.roles,
49
- };
50
- // Build the merged options, respecting precedence: env vars > Supabase defaults > user overrides
51
- const mergedOpts = {
52
- pg: {
53
- ...pgConfig,
54
- ...cn.pg, // User overrides take precedence
55
- },
47
+ // Build env overrides - pgEnvVars already only has defined keys
48
+ // Mirror user/password to connections.app for the app connection
49
+ const envOverrides = {
50
+ pg: pgEnvVars,
56
51
  db: {
57
- connection: {
58
- ...connectionConfig,
59
- ...cn.db?.connection, // User overrides take precedence
60
- },
61
- roles: {
62
- ...rolesConfig,
63
- ...cn.db?.roles, // User overrides take precedence
64
- },
65
- ...cn.db, // Other user overrides
52
+ connections: {
53
+ app: {
54
+ ...(pgEnvVars.user && { user: pgEnvVars.user }),
55
+ ...(pgEnvVars.password && { password: pgEnvVars.password }),
56
+ }
57
+ }
66
58
  }
67
59
  };
60
+ // Merge: Supabase defaults -> env vars -> user overrides
61
+ const mergedOpts = deepmerge_1.default.all([
62
+ { pg: SUPABASE_PG_DEFAULTS, db: SUPABASE_DEFAULTS },
63
+ envOverrides,
64
+ cn,
65
+ ]);
68
66
  return (0, pgsql_test_1.getConnections)(mergedOpts, seedAdapters);
69
67
  };
70
68
  exports.getConnections = getConnections;
package/esm/connect.js CHANGED
@@ -1,3 +1,4 @@
1
+ import deepmerge from 'deepmerge';
1
2
  import { getPgEnvVars } from 'pg-env';
2
3
  import { getConnections as getPgConnections } from 'pgsql-test';
3
4
  /**
@@ -9,6 +10,12 @@ const SUPABASE_DEFAULTS = {
9
10
  authenticated: 'authenticated',
10
11
  administrator: 'service_role',
11
12
  default: 'anon',
13
+ },
14
+ connections: {
15
+ app: {
16
+ user: 'supabase_admin',
17
+ password: 'postgres',
18
+ }
12
19
  }
13
20
  };
14
21
  /**
@@ -21,46 +28,34 @@ const SUPABASE_PG_DEFAULTS = {
21
28
  };
22
29
  /**
23
30
  * Get connections with Supabase defaults applied.
24
- * Environment variables take precedence over Supabase defaults.
25
- * User-provided options take precedence over both.
31
+ * Uses deepmerge for proper nested config merging.
26
32
  *
27
- * Note: Uses PGUSER/PGPASSWORD for both pg config and db.connection
28
- * (DB_CONNECTION_ROLE can still be used to override the default role)
33
+ * Precedence (later wins):
34
+ * 1. Supabase defaults
35
+ * 2. Environment variables (PGUSER/PGPASSWORD)
36
+ * 3. User-provided options
29
37
  */
30
38
  export const getConnections = async (cn = {}, seedAdapters) => {
31
- // Get environment variables - these should take precedence over our defaults
39
+ // Get environment variables (only includes defined keys)
32
40
  const pgEnvVars = getPgEnvVars();
33
- // Build pg config: env vars > Supabase defaults, then user overrides will override both
34
- const pgConfig = {};
35
- pgConfig.port = pgEnvVars.port ?? SUPABASE_PG_DEFAULTS.port;
36
- pgConfig.user = pgEnvVars.user ?? SUPABASE_PG_DEFAULTS.user;
37
- pgConfig.password = pgEnvVars.password ?? SUPABASE_PG_DEFAULTS.password;
38
- // Build connection config: use same user/password as pg config (from env vars or Supabase defaults)
39
- // Default role is 'anon' (Supabase default), but DB_CONNECTION_ROLE can override it
40
- const connectionConfig = {
41
- role: process.env.DB_CONNECTION_ROLE ?? SUPABASE_DEFAULTS.roles.default,
42
- };
43
- // Build roles config: Supabase defaults, then user overrides will override
44
- const rolesConfig = {
45
- ...SUPABASE_DEFAULTS.roles,
46
- };
47
- // Build the merged options, respecting precedence: env vars > Supabase defaults > user overrides
48
- const mergedOpts = {
49
- pg: {
50
- ...pgConfig,
51
- ...cn.pg, // User overrides take precedence
52
- },
41
+ // Build env overrides - pgEnvVars already only has defined keys
42
+ // Mirror user/password to connections.app for the app connection
43
+ const envOverrides = {
44
+ pg: pgEnvVars,
53
45
  db: {
54
- connection: {
55
- ...connectionConfig,
56
- ...cn.db?.connection, // User overrides take precedence
57
- },
58
- roles: {
59
- ...rolesConfig,
60
- ...cn.db?.roles, // User overrides take precedence
61
- },
62
- ...cn.db, // Other user overrides
46
+ connections: {
47
+ app: {
48
+ ...(pgEnvVars.user && { user: pgEnvVars.user }),
49
+ ...(pgEnvVars.password && { password: pgEnvVars.password }),
50
+ }
51
+ }
63
52
  }
64
53
  };
54
+ // Merge: Supabase defaults -> env vars -> user overrides
55
+ const mergedOpts = deepmerge.all([
56
+ { pg: SUPABASE_PG_DEFAULTS, db: SUPABASE_DEFAULTS },
57
+ envOverrides,
58
+ cn,
59
+ ]);
65
60
  return getPgConnections(mergedOpts, seedAdapters);
66
61
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supabase-test",
3
- "version": "0.4.9",
3
+ "version": "0.4.10",
4
4
  "author": "Interweb <developers@interweb.io>",
5
5
  "description": "supabase-test offers isolated, role-aware, and rollback-friendly PostgreSQL environments for integration tests with Supabase defaults baked in",
6
6
  "main": "index.js",
@@ -52,12 +52,13 @@
52
52
  "test:watch": "jest --watch"
53
53
  },
54
54
  "dependencies": {
55
- "@pgpmjs/types": "^2.12.5",
55
+ "@pgpmjs/types": "^2.12.6",
56
+ "deepmerge": "^4.3.1",
56
57
  "pg-env": "^1.2.4",
57
- "pgsql-test": "^2.17.5"
58
+ "pgsql-test": "^2.18.0"
58
59
  },
59
60
  "devDependencies": {
60
61
  "makage": "^0.1.9"
61
62
  },
62
- "gitHead": "63d51202de99ec03c329e00e5cd1dff4bc60b367"
63
+ "gitHead": "ac6c6b866ea6a578baf61208b22fcb12fdd46e5d"
63
64
  }