@opengis/fastify-table 2.0.97 → 2.0.99
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/pg/funcs/getMeta.d.ts.map +1 -1
- package/dist/server/plugins/pg/funcs/getMeta.js +7 -0
- package/dist/server/plugins/pg/funcs/getPG.d.ts.map +1 -1
- package/dist/server/plugins/pg/funcs/getPG.js +5 -4
- package/dist/server/plugins/pg/funcs/getPGAsync.d.ts.map +1 -1
- package/dist/server/plugins/pg/funcs/getPGAsync.js +4 -1
- package/dist/server/plugins/pg/funcs/init.d.ts +2 -2
- package/dist/server/plugins/pg/funcs/init.d.ts.map +1 -1
- package/dist/server/plugins/pg/funcs/init.js +29 -4
- package/dist/server/plugins/pg/index.d.ts.map +1 -1
- package/dist/server/plugins/pg/pgClients.d.ts.map +1 -1
- package/dist/server/plugins/pg/pgClients.js +5 -4
- package/dist/server/plugins/table/funcs/getTemplate.d.ts.map +1 -1
- package/dist/server/plugins/table/funcs/getTemplate.js +8 -1
- package/dist/server/types/core.d.ts +1 -0
- package/dist/server/types/core.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMeta.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/pg/funcs/getMeta.ts"],"names":[],"mappings":"
|
|
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,
|
|
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].
|
|
36
|
-
|
|
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,
|
|
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.
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/pg/funcs/init.ts"],"names":[],"mappings":"
|
|
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.
|
|
16
|
-
|
|
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.
|
|
131
|
+
console.warn("pg.querySafe timeout", q);
|
|
108
132
|
return { rows: [], timeout: true };
|
|
109
133
|
}
|
|
110
|
-
console.
|
|
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,
|
|
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;
|
|
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.
|
|
16
|
-
|
|
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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTemplate.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/table/funcs/getTemplate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getTemplate.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/table/funcs/getTemplate.ts"],"names":[],"mappings":"AA+FA,wBAA8B,WAAW,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,gBAyB7D"}
|
|
@@ -10,7 +10,7 @@ async function readFileData(file) {
|
|
|
10
10
|
if (ext === "yml") {
|
|
11
11
|
return yaml.load(data);
|
|
12
12
|
}
|
|
13
|
-
if (ext === "json") {
|
|
13
|
+
if (ext === "json" && data) {
|
|
14
14
|
return JSON.parse(data);
|
|
15
15
|
}
|
|
16
16
|
if (ext === "md") {
|
|
@@ -44,6 +44,13 @@ async function getTemplateData(template) {
|
|
|
44
44
|
// one file template: table, form
|
|
45
45
|
if (template.length === 1) {
|
|
46
46
|
const data = await readFileData(template[0][1]);
|
|
47
|
+
if (template[0][2] === "json" &&
|
|
48
|
+
path.basename(path.dirname(template[0][1])) === "table" &&
|
|
49
|
+
data?.parent) {
|
|
50
|
+
const parentTemplate = getTemplatePath("table").find((el) => el[0] === data.parent);
|
|
51
|
+
const parentData = await readFileData(parentTemplate[1]);
|
|
52
|
+
return { ...(parentData || {}), ...data };
|
|
53
|
+
}
|
|
47
54
|
return data;
|
|
48
55
|
}
|
|
49
56
|
// multi file template: select, etc
|
|
@@ -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,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