@opengis/fastify-table 2.0.97 → 2.0.98

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.
@@ -1 +1 @@
1
- {"version":3,"file":"getMeta.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/pg/funcs/getMeta.ts"],"names":[],"mappings":"AAIA,wBAA8B,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,gBAkE5D"}
1
+ {"version":3,"file":"getMeta.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/pg/funcs/getMeta.ts"],"names":[],"mappings":"AAKA,wBAA8B,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,gBAyE5D"}
@@ -1,9 +1,16 @@
1
+ import init from "./init.js";
1
2
  import getPG from "./getPG.js";
2
3
  const data = {};
3
4
  export default async function getMeta(opt, nocache) {
4
5
  const pg = opt?.pg || getPG({ name: "client" });
5
6
  if (!pg)
6
7
  return { error: "pg connection not established", status: 400 };
8
+ // reconnect if at start of process connection was unavailable
9
+ if (!pg.pk) {
10
+ pg.connectionAttempt = 0;
11
+ pg.init = init(pg);
12
+ await init(pg);
13
+ }
7
14
  const table1 = opt?.table || opt;
8
15
  const table = pg.pk?.[table1] ? table1 : table1?.replace?.(/"/g, "");
9
16
  if (pg?.options?.database && data[pg.options.database]?.[table] && !nocache)
@@ -1 +1 @@
1
- {"version":3,"file":"getPG.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/pg/funcs/getPG.ts"],"names":[],"mappings":"AAYA,iBAAS,KAAK,CAAC,KAAK,GAAE,GAAQ,OA6C7B;AAED,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"getPG.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/pg/funcs/getPG.ts"],"names":[],"mappings":"AAYA,iBAAS,KAAK,CAAC,KAAK,GAAE,GAAQ,OAgD7B;AAED,eAAe,KAAK,CAAC"}
@@ -32,10 +32,11 @@ function getPG(param = {}) {
32
32
  return null;
33
33
  }
34
34
  pgClients[name] = new pg.Pool(dbConfig);
35
- pgClients[name].init = async () => {
36
- await init(pgClients[name]);
37
- };
38
- init(pgClients[name]);
35
+ pgClients[name].on("error", (err, client) => {
36
+ console.warn("Unexpected error on idle client", client?.options?.database);
37
+ });
38
+ pgClients[name].init = async () => init(pgClients[name]);
39
+ // pgClients[name].init();
39
40
  return pgClients[name];
40
41
  }
41
42
  export default getPG;
@@ -1 +1 @@
1
- {"version":3,"file":"getPGAsync.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/pg/funcs/getPGAsync.ts"],"names":[],"mappings":"AAYA,iBAAe,UAAU,CAAC,KAAK,EAAE,GAAG,gBAyDnC;AAED,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"getPGAsync.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/pg/funcs/getPGAsync.ts"],"names":[],"mappings":"AAYA,iBAAe,UAAU,CAAC,KAAK,EAAE,GAAG,gBA6DnC;AAED,eAAe,UAAU,CAAC"}
@@ -31,11 +31,14 @@ async function getPGAsync(param) {
31
31
  return null;
32
32
  }
33
33
  pgClients[name] = new pg.Pool(dbConfig);
34
+ pgClients[name].on("error", (err, client) => {
35
+ console.warn("Unexpected error on idle client", client?.options?.database);
36
+ });
34
37
  try {
35
38
  await init(pgClients[name]);
36
39
  }
37
40
  catch (err) {
38
- console.error("pg client init error", host, port, database);
41
+ console.warn("pg client init error", host, port, database);
39
42
  // debug only
40
43
  if (config.local && name !== "client") {
41
44
  console.warn("fall back to default pgClient", pgClients.client?.host, pgClients.client?.port, pgClients.client?.database);
@@ -1,4 +1,4 @@
1
- import pg from "pg";
2
- declare function init(client: pg.Pool): Promise<void>;
1
+ import { ExtendedPG } from "../../../types/core.js";
2
+ declare function init(client: ExtendedPG): Promise<void>;
3
3
  export default init;
4
4
  //# sourceMappingURL=init.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/pg/funcs/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AASpB,iBAAe,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,iBA2MlC;AAGD,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/pg/funcs/init.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAsBpD,iBAAe,IAAI,CAAC,MAAM,EAAE,UAAU,iBA4NrC;AAGD,eAAe,IAAI,CAAC"}
@@ -4,16 +4,40 @@ import config from "../../../../config.js";
4
4
  import getRedis from "../../redis/funcs/getRedis.js";
5
5
  import logger from "../../logger/getLogger.js";
6
6
  const rclient = getRedis({ db: 0 });
7
+ const { reconnectAttempts = 2, reconnectInterval } = config.pg || {};
8
+ function delay(ms) {
9
+ return new Promise((resolve) => setTimeout(resolve, ms));
10
+ }
11
+ // avoid process exit with exception on network changes: disconnect from db, internet altogether etc
12
+ process.on("uncaughtException", (err) => {
13
+ if (err.message === "Connection terminated unexpectedly" ||
14
+ err.code === "ECONNRESET") {
15
+ console.warn("Ignored pg connection drop:", err.toString());
16
+ return;
17
+ }
18
+ throw err; // keep normal behavior
19
+ });
7
20
  async function init(client) {
8
21
  if (!client?.options?.database) {
9
22
  return;
10
23
  }
24
+ if (!client?.init) {
25
+ return;
26
+ }
27
+ client.connectionAttempt = ++client.connectionAttempt || 1;
28
+ if (client.connectionAttempt - 1 > reconnectAttempts) {
29
+ return;
30
+ }
11
31
  try {
32
+ console.log(client.connectionAttempt, "init pg attempt");
12
33
  await client.connect();
13
34
  }
14
35
  catch (err) {
15
- console.error("Error connecting to PostgreSQL:", client?.options?.database, err.message);
16
- return;
36
+ console.warn("Error connecting to PostgreSQL:", client?.options?.database, err.message);
37
+ const wait = +(reconnectInterval || 500) * client.connectionAttempt;
38
+ // resolve fastify plugin register promise
39
+ await delay(wait);
40
+ return init(client);
17
41
  }
18
42
  const { pgType, pk } = await client
19
43
  .query(`SELECT
@@ -104,10 +128,10 @@ async function init(client) {
104
128
  }
105
129
  catch (err) {
106
130
  if (err.code === "57014") {
107
- console.error("pg.querySafe timeout", q);
131
+ console.warn("pg.querySafe timeout", q);
108
132
  return { rows: [], timeout: true };
109
133
  }
110
- console.error("pg.querySafe error", q);
134
+ console.warn("pg.querySafe error", q);
111
135
  throw err;
112
136
  }
113
137
  finally {
@@ -175,6 +199,7 @@ async function init(client) {
175
199
  queryNotice,
176
200
  querySafe,
177
201
  });
202
+ client.init = undefined;
178
203
  console.log("pg connected", client.options?.database);
179
204
  }
180
205
  // export default client;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/pg/index.ts"],"names":[],"mappings":"AA+BA,iBAAS,MAAM,CAAC,OAAO,EAAE,GAAG,QA0B3B;AAED,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/pg/index.ts"],"names":[],"mappings":"AA+BA,iBAAS,MAAM,CAAC,OAAO,EAAE,GAAG,QAwB3B;AAED,eAAe,MAAM,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"pgClients.d.ts","sourceRoot":"","sources":["../../../../server/plugins/pg/pgClients.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,CAAC;AAiB1C,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"pgClients.d.ts","sourceRoot":"","sources":["../../../../server/plugins/pg/pgClients.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,CAAC;AAkB1C,eAAe,SAAS,CAAC"}
@@ -12,10 +12,11 @@ if (config.pg) {
12
12
  statement_timeout: config.pg?.statement_timeout || 10000,
13
13
  connectionTimeoutMillis: config.pg?.connectionTimeoutMillis || 5000,
14
14
  });
15
- client.init = async () => {
16
- await init(client);
17
- };
18
- client.init();
15
+ client.on("error", (err, client1) => {
16
+ console.warn("Unexpected error on idle client", client1?.options?.database);
17
+ });
18
+ client.init = async () => init(client);
19
+ // client.init();
19
20
  pgClients.client = client;
20
21
  }
21
22
  export default pgClients;
@@ -5,6 +5,7 @@ declare let Database: any;
5
5
  export interface ExtendedPG extends Pool {
6
6
  readonly?: any;
7
7
  init?: () => void;
8
+ connectionAttempt: number;
8
9
  pk?: Record<string, string>;
9
10
  pgType?: Record<any, string>;
10
11
  tlist?: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../server/types/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAM1B,QAAA,IAAI,QAAQ,EAAE,GAAG,CAAC;AAUlB,MAAM,WAAW,UAAW,SAAQ,IAAI;IACtC,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,GAAG,CAAC;CACjE;AAYD,MAAM,WAAW,YAAY;IAC3B,GAAG,CAA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2.0.98",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [