@hot-updater/postgres 1.2.0-rc.4 → 1.2.0-rc.5

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
@@ -36,6 +36,7 @@ const { Pool } = pg.default;
36
36
  const DATABASE_TARGET = Symbol.for("@hot-updater/database-target");
37
37
  /** The server and database a pool reaches: `postgres/<host>:<port>/<database>`. */
38
38
  const targetOf = ({ connectionString, host, port, database }) => {
39
+ if (typeof connectionString === "function") return void 0;
39
40
  if (connectionString !== void 0) try {
40
41
  const url = new URL(connectionString);
41
42
  return `postgres/${url.hostname}:${url.port || "5432"}/${decodeURIComponent(url.pathname.slice(1))}`;
@@ -53,7 +54,14 @@ const targetOf = ({ connectionString, host, port, database }) => {
53
54
  const postgres = (config) => {
54
55
  const { dialect, ...poolConfig } = config;
55
56
  const target = targetOf(poolConfig);
56
- const db = new kysely.Kysely({ dialect: dialect ?? new kysely.PostgresDialect({ pool: new Pool(poolConfig) }) });
57
+ const { connectionString } = poolConfig;
58
+ const db = new kysely.Kysely({ dialect: dialect ?? new kysely.PostgresDialect({ pool: typeof connectionString === "function" ? async () => new Pool({
59
+ ...poolConfig,
60
+ connectionString: await connectionString()
61
+ }) : new Pool({
62
+ ...poolConfig,
63
+ connectionString
64
+ }) }) });
57
65
  return {
58
66
  ...(0, _hot_updater_plugin_core.createEngineDatabase)({
59
67
  name: "postgres",
package/dist/index.d.cts CHANGED
@@ -2,7 +2,15 @@ import { EngineDatabase } from "@hot-updater/plugin-core";
2
2
  import { Dialect } from "kysely";
3
3
  import { PoolConfig } from "pg";
4
4
  //#region src/postgres.d.ts
5
- type PostgresConfig = PoolConfig & {
5
+ type PostgresPoolConfig = Omit<PoolConfig, "connectionString"> & {
6
+ /**
7
+ * The database's URL, or a function that returns it, such as one that
8
+ * reads it with `secretEnv`: called when the pool first connects, so a
9
+ * config loads without it.
10
+ */
11
+ readonly connectionString?: string | (() => string | Promise<string>);
12
+ };
13
+ type PostgresConfig = PostgresPoolConfig & {
6
14
  readonly dialect?: Dialect;
7
15
  };
8
16
  /**
package/dist/index.d.mts CHANGED
@@ -2,7 +2,15 @@ import { EngineDatabase } from "@hot-updater/plugin-core";
2
2
  import { Dialect } from "kysely";
3
3
  import { PoolConfig } from "pg";
4
4
  //#region src/postgres.d.ts
5
- type PostgresConfig = PoolConfig & {
5
+ type PostgresPoolConfig = Omit<PoolConfig, "connectionString"> & {
6
+ /**
7
+ * The database's URL, or a function that returns it, such as one that
8
+ * reads it with `secretEnv`: called when the pool first connects, so a
9
+ * config loads without it.
10
+ */
11
+ readonly connectionString?: string | (() => string | Promise<string>);
12
+ };
13
+ type PostgresConfig = PostgresPoolConfig & {
6
14
  readonly dialect?: Dialect;
7
15
  };
8
16
  /**
package/dist/index.mjs CHANGED
@@ -12,6 +12,7 @@ const { Pool } = pg;
12
12
  const DATABASE_TARGET = Symbol.for("@hot-updater/database-target");
13
13
  /** The server and database a pool reaches: `postgres/<host>:<port>/<database>`. */
14
14
  const targetOf = ({ connectionString, host, port, database }) => {
15
+ if (typeof connectionString === "function") return void 0;
15
16
  if (connectionString !== void 0) try {
16
17
  const url = new URL(connectionString);
17
18
  return `postgres/${url.hostname}:${url.port || "5432"}/${decodeURIComponent(url.pathname.slice(1))}`;
@@ -29,7 +30,14 @@ const targetOf = ({ connectionString, host, port, database }) => {
29
30
  const postgres = (config) => {
30
31
  const { dialect, ...poolConfig } = config;
31
32
  const target = targetOf(poolConfig);
32
- const db = new Kysely({ dialect: dialect ?? new PostgresDialect({ pool: new Pool(poolConfig) }) });
33
+ const { connectionString } = poolConfig;
34
+ const db = new Kysely({ dialect: dialect ?? new PostgresDialect({ pool: typeof connectionString === "function" ? async () => new Pool({
35
+ ...poolConfig,
36
+ connectionString: await connectionString()
37
+ }) : new Pool({
38
+ ...poolConfig,
39
+ connectionString
40
+ }) }) });
33
41
  return {
34
42
  ...createEngineDatabase({
35
43
  name: "postgres",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/postgres",
3
3
  "type": "module",
4
- "version": "1.2.0-rc.4",
4
+ "version": "1.2.0-rc.5",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.mjs",
@@ -34,9 +34,9 @@
34
34
  "dependencies": {
35
35
  "kysely": "0.28.17",
36
36
  "pg": "8.13.1",
37
- "@hot-updater/protocol": "1.2.0-rc.4",
38
- "@hot-updater/server": "1.2.0-rc.4",
39
- "@hot-updater/plugin-core": "1.2.0-rc.4"
37
+ "@hot-updater/protocol": "1.2.0-rc.5",
38
+ "@hot-updater/server": "1.2.0-rc.5",
39
+ "@hot-updater/plugin-core": "1.2.0-rc.5"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@electric-sql/pglite": "0.4.1",
@@ -45,7 +45,7 @@
45
45
  "camelcase-keys": "^9.1.3",
46
46
  "kysely-pglite-dialect": "1.2.0",
47
47
  "pg-minify": "^1.6.5",
48
- "@hot-updater/test-utils": "1.2.0-rc.4"
48
+ "@hot-updater/test-utils": "1.2.0-rc.5"
49
49
  },
50
50
  "scripts": {
51
51
  "build": "tsdown",