@opengis/fastify-table 2.0.104 → 2.0.105

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":"getLogger.d.ts","sourceRoot":"","sources":["../../../../server/plugins/logger/getLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,UAAU,cAAe,SAAQ,IAAI,CAAC,MAAM;IAC1C,IAAI,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;IAClE,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5D;AAkDD,QAAA,MAAM,MAAM,EAAE,cAAgD,CAAC;AA4B/D,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"getLogger.d.ts","sourceRoot":"","sources":["../../../../server/plugins/logger/getLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,UAAU,cAAe,SAAQ,IAAI,CAAC,MAAM;IAC1C,IAAI,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;IAClE,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5D;AAgDD,QAAA,MAAM,MAAM,EAAE,cAAgD,CAAC;AA+B/D,eAAe,MAAM,CAAC"}
@@ -7,7 +7,6 @@ import getHooks from "./getHooks.js";
7
7
  import serializers from "./serializers.js";
8
8
  import timestampWithTimeZone from "./timestampWithTimeZone.js";
9
9
  const isServer = process.argv[2];
10
- const rclient2 = getRedis({ db: 2 });
11
10
  const level = process.env.LOG_LEVEL || "info";
12
11
  console.log(`log level: ${level}`);
13
12
  const targets = [
@@ -49,11 +48,14 @@ if (config.debug) {
49
48
  });
50
49
  }
51
50
  logger.metrics = function metrics(key, val, dbName) {
51
+ const rclient2 = getRedis({ db: 2 });
52
52
  const dbname = dbName || config.pg?.database;
53
53
  if (!dbname && !isServer)
54
54
  return;
55
55
  if (!config.redis)
56
56
  return;
57
- rclient2.hincrby(`${dbname}:system_metrics`, key, val || 1);
57
+ rclient2
58
+ .hincrby(`${dbname}:system_metrics`, key, val || 1)
59
+ .catch((err) => console.warn("logger metrics error", err.toString()));
58
60
  };
59
61
  export default logger;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/logger/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;AAM7E,iBAAe,MAAM,CAAC,OAAO,EAAE,eAAe,iBAwC7C;AACD,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/logger/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;AAiC7E,iBAAe,MAAM,CAAC,OAAO,EAAE,eAAe,iBAwC7C;AACD,eAAe,MAAM,CAAC"}
@@ -1,6 +1,30 @@
1
1
  import errorMessage from "./errorMessage.js";
2
2
  import logger from "./getLogger.js";
3
3
  import pgClients from "../pg/pgClients.js";
4
+ // avoid process exit with exception on network changes: disconnect from db, internet altogether etc
5
+ process.on("uncaughtException", (err) => {
6
+ if (err.message === "Connection terminated unexpectedly" ||
7
+ err.code === "ECONNRESET") {
8
+ logger.file("pg", { error: err.toString() });
9
+ console.warn("Ignored pg connection drop:", err.toString());
10
+ return;
11
+ }
12
+ throw err; // keep normal behavior
13
+ });
14
+ // avoid process exit with rejection during client connect at process start
15
+ process.on("unhandledRejection", (err) => {
16
+ if (err.message === "Connection terminated due to connection timeout") {
17
+ logger.file("pg", { error: err.message });
18
+ console.warn("Ignored pg connection timeout:", err.toString());
19
+ return;
20
+ }
21
+ if (err.message === "Connection is closed.") {
22
+ logger.file("redis", { error: err.message });
23
+ console.warn("Ignored redis connection close:", err.toString());
24
+ return;
25
+ }
26
+ throw err;
27
+ });
4
28
  async function plugin(fastify) {
5
29
  fastify.addHook("onResponse", async (req, reply) => {
6
30
  if (reply?.statusCode && reply.statusCode >= 400) {
@@ -1 +1 @@
1
- {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/pg/funcs/pool.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,CAAC;yBAqB7B,QAAO,GAAQ;AAA/B,wBAsEE"}
1
+ {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/pg/funcs/pool.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,CAAC;yBAK7B,QAAO,GAAQ;AAA/B,wBAsEE"}
@@ -9,19 +9,6 @@ import config from "../../../../config.js";
9
9
  export const Pools = {};
10
10
  const errored = {};
11
11
  const inited = {};
12
- // avoid process exit with exception on network changes: disconnect from db, internet altogether etc
13
- process.on("uncaughtException", (err) => {
14
- if (err.message === "Connection terminated unexpectedly" ||
15
- err.code === "ECONNRESET") {
16
- logger.file("pg", {
17
- message: "client connection drop",
18
- error: err.toString(),
19
- });
20
- console.warn("Ignored pg connection drop:", err.toString());
21
- return;
22
- }
23
- throw err; // keep normal behavior
24
- });
25
12
  export default (param = {}) => {
26
13
  if (!config.pg)
27
14
  return null;
@@ -1,7 +1,13 @@
1
- declare function getRedis({ db, host, port, }?: {
1
+ declare function getRedis({ db, host, port, closeClient, retryStrategy, enableOfflineQueue, lazyConnect, connectTimeout, maxRetriesPerRequest, }?: {
2
2
  db: number;
3
3
  host?: string;
4
4
  port?: number;
5
+ closeClient?: boolean;
6
+ retryStrategy?: any;
7
+ enableOfflineQueue?: boolean;
8
+ lazyConnect?: boolean;
9
+ connectTimeout?: number;
10
+ maxRetriesPerRequest?: number;
5
11
  }): any;
6
12
  export default getRedis;
7
13
  //# sourceMappingURL=getRedis.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getRedis.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/redis/funcs/getRedis.ts"],"names":[],"mappings":"AAOA,iBAAS,QAAQ,CACf,EACE,EAAE,EACF,IAAI,EACJ,IAAI,GACL,GAAE;IACD,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACH,OAsBd;AAED,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"getRedis.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/redis/funcs/getRedis.ts"],"names":[],"mappings":"AAQA,iBAAS,QAAQ,CACf,EACE,EAAE,EACF,IAAI,EACJ,IAAI,EACJ,WAAkB,EAClB,aAAwB,EACxB,kBAAyB,EACzB,WAAkB,EAClB,cAAqB,EACrB,oBAAwB,GACzB,GAAE;IACD,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;CACnB,OAwCd;AAED,eAAe,QAAQ,CAAC"}
@@ -1,9 +1,9 @@
1
- /* eslint-disable no-console */
2
1
  import { Redis } from "ioredis";
3
- // import Redis from 'ioredis';
4
2
  import config from "../../../../config.js";
3
+ import logger from "../../logger/getLogger.js";
5
4
  import redisClients from "./redisClients.js";
6
- function getRedis({ db, host, port, } = { db: 0 }) {
5
+ config.ready = config.ready || {};
6
+ function getRedis({ db, host, port, closeClient = true, retryStrategy = () => { }, enableOfflineQueue = true, lazyConnect = true, connectTimeout = 2000, maxRetriesPerRequest = 0, } = { db: 0 }) {
7
7
  if (!config.redis && !host)
8
8
  return null;
9
9
  const key = host || port ? [host, port, db].join("-") : db;
@@ -16,9 +16,24 @@ function getRedis({ db, host, port, } = { db: 0 }) {
16
16
  host: host || config.redis?.host || "127.0.0.1",
17
17
  port: port || config.redis?.port || 6379, // Redis port
18
18
  family: 4, // 4 (IPv4) or 6 (IPv6)
19
- closeClient: true,
19
+ closeClient,
20
+ retryStrategy,
21
+ enableOfflineQueue,
22
+ lazyConnect,
23
+ connectTimeout,
24
+ maxRetriesPerRequest,
20
25
  };
21
26
  redisClients[key] = new Redis(redisConfig);
27
+ redisClients[key].on("ready", () => {
28
+ config.ready[`redis:${key}`] = true;
29
+ });
30
+ redisClients[key].on("error", (err) => {
31
+ console.warn("Ignored redis error:", err.message);
32
+ logger.file("redis", { error: err.toString() });
33
+ if (err.code === "ETIMEDOUT") {
34
+ // redisClients[key].disconnect();
35
+ }
36
+ });
22
37
  console.log("redis connected", db, host, port);
23
38
  return redisClients[key];
24
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"getSelectVal.d.ts","sourceRoot":"","sources":["../../../../../../server/plugins/table/funcs/metaFormat/getSelectVal.ts"],"names":[],"mappings":"AAaA,wBAA8B,YAAY,CAAC,EACzC,EAAqB,EACrB,IAAI,EACJ,MAAM,EAAE,YAAY,EACpB,EAAU,GACX,EAAE,GAAG,gBAmGL"}
1
+ {"version":3,"file":"getSelectVal.d.ts","sourceRoot":"","sources":["../../../../../../server/plugins/table/funcs/metaFormat/getSelectVal.ts"],"names":[],"mappings":"AAaA,wBAA8B,YAAY,CAAC,EACzC,EAAqB,EACrB,IAAI,EACJ,MAAM,EAAE,YAAY,EACpB,EAAU,GACX,EAAE,GAAG,gBA6GL"}
@@ -32,7 +32,14 @@ export default async function getSelectVal({ pg = pgClients.client, name, values
32
32
  }
33
33
  const id = selectIds[name];
34
34
  // cache
35
- const key = `select:${name}`;
35
+ const table = cls.sql
36
+ ?.toLowerCase?.()
37
+ ?.replace?.(/[\n\r]+/g, " ")
38
+ ?.split?.(" from ")
39
+ ?.filter?.((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
40
+ ?.map?.((el) => el.split(/[ )]/)[0])?.[0];
41
+ const crudInc = table && config.redis ? (await rclient.get(`pg:${table}:crud`)) || 0 : 0;
42
+ const key = `select:${name}:${crudInc}`;
36
43
  const cache = values?.length && config.redis && !config.disableCache
37
44
  ? (await rclient.hmget(key, values)).reduce((p, el, i) => ({
38
45
  ...p,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.0.104",
3
+ "version": "2.0.105",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [