@lobb-js/core 0.26.1 → 0.27.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lobb-js/core",
3
3
  "license": "UNLICENSED",
4
- "version": "0.26.1",
4
+ "version": "0.27.0",
5
5
  "type": "module",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -38,13 +38,43 @@ export class PGDriver extends DatabaseDriver {
38
38
 
39
39
  public async createConnection() {
40
40
  const default_pool_connections = (cpus().length * 2) + 4;
41
+ const { host, port } = this.databaseConfig;
41
42
 
42
- // Ensure the database exists before connecting
43
- await this.ensureDatabaseExists();
43
+ try {
44
+ // Ensure the database exists before connecting
45
+ await this.ensureDatabaseExists();
46
+ } catch (err: any) {
47
+ const addr = `${host}:${port}`;
48
+ if (err.code === "ESERVFAIL" || err.code === "ENOTFOUND" || err.code === "EAI_AGAIN") {
49
+ throw new LobbError({
50
+ code: "INTERNAL_SERVER_ERROR",
51
+ message: `Cannot connect to database: failed to resolve host "${host}". Make sure the database server is running and reachable at ${addr}.`,
52
+ });
53
+ }
54
+ if (err.code === "ECONNREFUSED") {
55
+ throw new LobbError({
56
+ code: "INTERNAL_SERVER_ERROR",
57
+ message: `Cannot connect to database: connection refused at ${addr}. Make sure the database server is running.`,
58
+ });
59
+ }
60
+ if (err.code === "ETIMEDOUT") {
61
+ throw new LobbError({
62
+ code: "INTERNAL_SERVER_ERROR",
63
+ message: `Cannot connect to database: connection timed out at ${addr}. Make sure the database server is reachable.`,
64
+ });
65
+ }
66
+ if ((err as any).code === "28P01") {
67
+ throw new LobbError({
68
+ code: "INTERNAL_SERVER_ERROR",
69
+ message: `Cannot connect to database: authentication failed for user "${this.databaseConfig.username}" at ${addr}. Check your database credentials.`,
70
+ });
71
+ }
72
+ throw err;
73
+ }
44
74
 
45
75
  // Now connect to the actual target database
46
76
  this.pool = new Pool({
47
- host: this.databaseConfig.host,
77
+ host,
48
78
  port: this.databaseConfig.port,
49
79
  user: this.databaseConfig.username,
50
80
  password: this.databaseConfig.password,
package/src/index.ts CHANGED
@@ -20,6 +20,7 @@ export type { Config, WebConfig } from "./types/config/config.ts";
20
20
  export type { RelationsConfig } from "./types/config/relations.ts";
21
21
  export type {
22
22
  CollectionConfig,
23
+ NormalCollectionConfig,
23
24
  CollectionIndex,
24
25
  CollectionIndexes,
25
26
  CollectionsConfig,