@holo-js/db-postgres 0.3.28 → 0.4.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Holo-JS contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ e09e537da3940c05be778a8af0fd489257533a2c58b7ce585c5acd9a6210e642
package/dist/index.d.ts CHANGED
@@ -6,8 +6,16 @@ type PostgresQueryResult = {
6
6
  rows: Record<string, unknown>[];
7
7
  rowCount?: number | null;
8
8
  };
9
+ type TypeParserSource = {
10
+ getTypeParser(oid: number, format?: 'text' | 'binary'): (value: string) => unknown;
11
+ };
12
+ type PostgresQueryConfig = {
13
+ text: string;
14
+ values: unknown[];
15
+ types: TypeParserSource;
16
+ };
9
17
  interface PostgresQueryableLike {
10
- query(sql: string, bindings?: readonly unknown[]): Promise<PostgresQueryResult | PostgresQueryResult[]>;
18
+ query(sql: string | PostgresQueryConfig, bindings?: readonly unknown[]): Promise<PostgresQueryResult | PostgresQueryResult[]>;
11
19
  }
12
20
  interface PostgresClientLike extends PostgresQueryableLike {
13
21
  release?(): void;
@@ -56,4 +64,5 @@ declare class PostgresAdapter<TConfig extends PoolConfig = PoolConfig> implement
56
64
  declare function createPostgresAdapter<TConfig extends PoolConfig = PoolConfig>(options?: PostgresAdapterOptions<TConfig>): PostgresAdapter<TConfig>;
57
65
  declare const postgresDatabaseDriverFactory: DatabaseDriverFactory;
58
66
 
59
- export { PostgresAdapter, type PostgresAdapterOptions, type PostgresClientLike, type PostgresPoolLike, type PostgresQueryableLike, createPostgresAdapter, postgresDatabaseDriverFactory };
67
+ export { PostgresAdapter, createPostgresAdapter, postgresDatabaseDriverFactory };
68
+ export type { PostgresAdapterOptions, PostgresClientLike, PostgresPoolLike, PostgresQueryableLike };
package/dist/index.mjs CHANGED
@@ -1,11 +1,32 @@
1
1
  // src/index.ts
2
2
  import { holoRuntimeInternals } from "@holo-js/db";
3
3
  import { Pool, types } from "pg";
4
+ var { formatWithOffset, parseCalendarDate, parseWallClockTimestamp } = holoRuntimeInternals;
4
5
  var TransactionError = class extends Error {
5
6
  };
6
7
  function finalQueryResult(result) {
7
8
  return Array.isArray(result) ? result.at(-1) ?? { rows: [], rowCount: 0 } : result;
8
9
  }
10
+ function toDriverBinding(value, timeZone) {
11
+ return value instanceof Date ? formatWithOffset(value, timeZone) : value;
12
+ }
13
+ function baseTypesOf(queryable) {
14
+ const source = queryable;
15
+ return source._types ?? source.options?.types ?? types;
16
+ }
17
+ function applicationTypes(base, timeZone) {
18
+ return {
19
+ getTypeParser(oid, format = "text") {
20
+ if (format === "text" && oid === 1082) {
21
+ return (value) => parseCalendarDate(value, timeZone) ?? base.getTypeParser(oid, format)(value);
22
+ }
23
+ if (format === "text" && oid === 1114) {
24
+ return (value) => parseWallClockTimestamp(value, timeZone, "later") ?? base.getTypeParser(oid, format)(value);
25
+ }
26
+ return base.getTypeParser(oid, format);
27
+ }
28
+ };
29
+ }
9
30
  function quoteDatabaseIdentifier(database) {
10
31
  return `"${database.replaceAll('"', '""')}"`;
11
32
  }
@@ -18,6 +39,28 @@ function stripDatabaseFromConnectionString(connectionString) {
18
39
  connectionString: parsed.toString()
19
40
  };
20
41
  }
42
+ var openPoolSessions = /* @__PURE__ */ new WeakMap();
43
+ function createHoloPool(config) {
44
+ const pool = new Pool({ ...config });
45
+ const sessions = /* @__PURE__ */ new Set();
46
+ openPoolSessions.set(pool, sessions);
47
+ pool.on("connect", (client) => {
48
+ sessions.add(client);
49
+ client.once("end", () => sessions.delete(client));
50
+ });
51
+ pool.on("error", (error) => holoRuntimeInternals.reportError(error, { capability: "db", operation: "postgres.idleClient" }));
52
+ return pool;
53
+ }
54
+ async function endPoolAndAwaitSessions(pool) {
55
+ if (!(pool instanceof Pool)) {
56
+ return pool.end();
57
+ }
58
+ const sessions = openPoolSessions.get(pool);
59
+ await pool.end();
60
+ await Promise.all([...sessions ?? []].map((client) => new Promise((resolve) => {
61
+ client.once("end", () => resolve());
62
+ })));
63
+ }
21
64
  function resolveBootstrapTarget(config) {
22
65
  if (!config) {
23
66
  return void 0;
@@ -62,15 +105,7 @@ var PostgresAdapter = class {
62
105
  this.supportsConcurrentTransactionScopes = !options.client;
63
106
  this.directClient = options.client;
64
107
  this.pool = options.pool;
65
- this.createPoolInstance = options.createPool ?? (options.client || options.pool ? void 0 : (config) => new Pool({
66
- ...config,
67
- types: config?.types ?? {
68
- getTypeParser(oid, format = "text") {
69
- if (oid === 1114 && format === "text") return (value) => /* @__PURE__ */ new Date(`${value}Z`);
70
- return types.getTypeParser(oid, format);
71
- }
72
- }
73
- }));
108
+ this.createPoolInstance = options.createPool ?? (options.client || options.pool ? void 0 : (config) => createHoloPool(config));
74
109
  this.config = options.config ?? (options.connectionString ? { connectionString: options.connectionString } : void 0);
75
110
  this.connected = !!(options.client || options.pool);
76
111
  this.transactionClients = new holoRuntimeInternals.PooledTransactionClients(
@@ -106,7 +141,7 @@ var PostgresAdapter = class {
106
141
  }
107
142
  this.transactionClients.disconnect();
108
143
  if (this.pool) {
109
- await this.pool.end();
144
+ await endPoolAndAwaitSessions(this.pool);
110
145
  this.pool = void 0;
111
146
  } else if (this.directClient?.end) {
112
147
  await this.directClient.end();
@@ -184,7 +219,12 @@ var PostgresAdapter = class {
184
219
  }
185
220
  async queryResult(sql, bindings) {
186
221
  const client = await this.getQueryable();
187
- const result = await client.query(sql, bindings);
222
+ const timeZone = holoRuntimeInternals.getApplicationTimezone();
223
+ const result = await client.query({
224
+ text: sql,
225
+ values: bindings.map((value) => toDriverBinding(value, timeZone)),
226
+ types: applicationTypes(baseTypesOf(client), timeZone)
227
+ });
188
228
  return finalQueryResult(result);
189
229
  }
190
230
  async ensureDatabaseExists() {
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "name": "@holo-js/db-postgres",
3
- "version": "0.3.28",
3
+ "version": "0.4.0",
4
4
  "description": "Holo-JS Framework - Postgres database adapter",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/cobraprojects/holo-js.git",
10
+ "directory": "packages/db-postgres"
11
+ },
7
12
  "exports": {
8
13
  ".": {
9
14
  "types": "./dist/index.d.ts",
@@ -14,7 +19,8 @@
14
19
  "main": "./dist/index.mjs",
15
20
  "types": "./dist/index.d.ts",
16
21
  "files": [
17
- "dist"
22
+ "dist",
23
+ "LICENSE"
18
24
  ],
19
25
  "scripts": {
20
26
  "build": "tsup",
@@ -24,19 +30,19 @@
24
30
  "test:integration": "HOLO_POSTGRES_INTEGRATION=1 vitest --run tests/postgres.test.ts"
25
31
  },
26
32
  "peerDependencies": {
27
- "@holo-js/db": "^0.3.28"
33
+ "@holo-js/db": "^0.4.0"
28
34
  },
29
35
  "dependencies": {
30
36
  "pg": "^8.13.0"
31
37
  },
32
38
  "devDependencies": {
33
- "@holo-js/db": "^0.3.28",
39
+ "@holo-js/db": "^0.4.0",
34
40
  "@types/pg": "^8.11.0",
35
- "tsup": "^8.3.5",
36
- "typescript": "^5.7.2",
37
- "vitest": "^4.1.5"
41
+ "tsup": "^9.0.0",
42
+ "typescript": "^6.0.3",
43
+ "vitest": "^5.0.5"
38
44
  },
39
45
  "engines": {
40
- "node": "^22.12.0 || ^24.0.0 || ^26.0.0"
46
+ "node": "^22.18.0 || ^24.0.0 || ^26.0.0"
41
47
  }
42
48
  }