@opengis/fastify-table 2.5.7 → 2.5.9
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/server/plugins/logger/index.d.ts.map +1 -1
- package/dist/server/plugins/logger/index.js +27 -7
- package/dist/server/routes/notifications/controllers/userNotifications.js +1 -1
- package/dist/server/routes/table/controllers/search.js +1 -1
- package/dist/server/routes/table/functions/getData.d.ts.map +1 -1
- package/dist/server/routes/table/functions/getData.js +1 -1
- package/package.json +1 -1
|
@@ -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;
|
|
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;AAqE7E,iBAAS,YAAY,CAAC,OAAO,EAAE,eAAe,QA+C7C;AACD,eAAe,YAAY,CAAC"}
|
|
@@ -2,6 +2,12 @@ import errorMessage from "./errorMessage.js";
|
|
|
2
2
|
import errorStatus from "./errorStatus.js";
|
|
3
3
|
import logger from "./getLogger.js";
|
|
4
4
|
import pgClients from "../pg/pgClients.js";
|
|
5
|
+
const DEFAULT_LOG_STATUS_CODES = [403, 409, 413, 415, 429];
|
|
6
|
+
const logStatusCodes = typeof process.env["LOG_STATUS_CODES"] === "string"
|
|
7
|
+
? process.env["LOG_STATUS_CODES"].split(",").map((el) => el - 0)
|
|
8
|
+
: DEFAULT_LOG_STATUS_CODES;
|
|
9
|
+
const logResponseCodes = process.env.LOG === "true" ? logStatusCodes : [];
|
|
10
|
+
const logWarningCodes = process.env.LOG === "true" ? logStatusCodes.filter((el) => el >= 400) : [];
|
|
5
11
|
// avoid process exit with exception on network changes: disconnect from db, internet altogether etc
|
|
6
12
|
process.on("uncaughtException", (err) => {
|
|
7
13
|
if (err.message === "Connection terminated unexpectedly" ||
|
|
@@ -46,18 +52,32 @@ process.on("unhandledRejection", (err) => {
|
|
|
46
52
|
throw err;
|
|
47
53
|
});
|
|
48
54
|
function loggerPlugin(fastify) {
|
|
49
|
-
fastify.addHook("onResponse", async (
|
|
55
|
+
fastify.addHook("onResponse", async (request, reply) => {
|
|
50
56
|
if (reply?.statusCode && reply.statusCode >= 400) {
|
|
51
57
|
logger.metrics(`error-count:${reply.statusCode}`);
|
|
52
58
|
}
|
|
59
|
+
if (reply?.statusCode && logResponseCodes.includes(reply.statusCode)) {
|
|
60
|
+
const { elapsedTime, statusCode } = reply;
|
|
61
|
+
const { method, url } = request;
|
|
62
|
+
if (statusCode === 200 && url.startsWith("/logger-file/"))
|
|
63
|
+
return; // skip logger self-log
|
|
64
|
+
logger.file("request", { elapsedTime, statusCode, method, url });
|
|
65
|
+
}
|
|
53
66
|
});
|
|
54
67
|
fastify.setErrorHandler(async (error, request, reply) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
68
|
+
if (!error.statusCode || error.statusCode >= 500) {
|
|
69
|
+
logger.error(error, request);
|
|
70
|
+
}
|
|
71
|
+
if (error.statusCode && logWarningCodes.includes(error.statusCode)) {
|
|
72
|
+
logger.warn(error, request);
|
|
73
|
+
}
|
|
74
|
+
if (process.env.trace === "true") {
|
|
75
|
+
console.error({
|
|
76
|
+
msg: error.message,
|
|
77
|
+
where: error.where,
|
|
78
|
+
stack: error.stack,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
61
81
|
const statusCode = errorStatus(error) || 500;
|
|
62
82
|
const message = errorMessage(error, statusCode);
|
|
63
83
|
return reply.status(statusCode).send({
|
|
@@ -5,7 +5,7 @@ const maxLimit = 100;
|
|
|
5
5
|
const q = `select notification_id as id, subject, body, created_at,
|
|
6
6
|
author_id, read, link, entity_id, (select avatar from admin.users where uid=a.author_id limit 1) as avatar
|
|
7
7
|
from crm.notifications a
|
|
8
|
-
where addressee_id=$1 order by created_at desc limit $2 offset $3`;
|
|
8
|
+
where addressee_id=$1 order by created_at desc limit $2::bigint offset $3::bigint`;
|
|
9
9
|
export default async function userNotifications(req) {
|
|
10
10
|
const { pg = pgClients.client, query, user, } = req;
|
|
11
11
|
const t1 = Date.now();
|
|
@@ -45,7 +45,7 @@ async function getData({ pg = pgClients.client, tableName, query = {}, maxLimit,
|
|
|
45
45
|
meta?.title ? `${meta.title} as title` : "",
|
|
46
46
|
]
|
|
47
47
|
.filter((el) => el)
|
|
48
|
-
.join(",")} from ${table} t ${sqlTable} where ${where.join(" and ") || "true"} ${order} limit $1 offset $2`;
|
|
48
|
+
.join(",")} from ${table} t ${sqlTable} where ${where.join(" and ") || "true"} ${order} limit $1::bigint offset $2::bigint`;
|
|
49
49
|
if (query.sql) {
|
|
50
50
|
res.sql.push(q);
|
|
51
51
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getData.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/functions/getData.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAwFzD,wBAA8B,OAAO,CACnC,EACE,EAAqB,EACrB,MAAM,EACN,KAAK,EACL,EAAE,EACF,OAAY,EACZ,KAAU,EACV,IAAS,EACT,YAAY,EACZ,YAAY,EACZ,KAAY,EACZ,UAAU,EACV,OAAO,EAAE,YAAY,EACrB,WAAW,EAAE,gBAAgB,EAC7B,OAAO,EAAE,YAAY,EACrB,QAAgB,GACjB,EAAE;IACD,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,MAAM,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,EACD,KAAK,CAAC,EAAE,YAAY,EACpB,MAAM,CAAC,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"getData.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/functions/getData.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAwFzD,wBAA8B,OAAO,CACnC,EACE,EAAqB,EACrB,MAAM,EACN,KAAK,EACL,EAAE,EACF,OAAY,EACZ,KAAU,EACV,IAAS,EACT,YAAY,EACZ,YAAY,EACZ,KAAY,EACZ,UAAU,EACV,OAAO,EAAE,YAAY,EACrB,WAAW,EAAE,gBAAgB,EAC7B,OAAO,EAAE,YAAY,EACrB,QAAgB,GACjB,EAAE;IACD,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,MAAM,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,EACD,KAAK,CAAC,EAAE,YAAY,EACpB,MAAM,CAAC,EAAE,GAAG,gBA64Bb"}
|
|
@@ -365,7 +365,7 @@ export default async function dataAPI({ pg = pgClients.client, params, table, id
|
|
|
365
365
|
|
|
366
366
|
${objectId ? cardSqlTable : ""}
|
|
367
367
|
where ${where.join(" and ") || "true"}
|
|
368
|
-
${order} limit $${idx.limit} offset $${idx.offset}`;
|
|
368
|
+
${order} limit $${idx.limit}::bigint offset $${idx.offset}::bigint`;
|
|
369
369
|
if (q1.includes("{{uid}}")) {
|
|
370
370
|
args.push(uid || "");
|
|
371
371
|
Object.assign(idx, { uid: Object.keys(idx).length + 1 });
|