@opengis/fastify-table 2.0.113 → 2.0.115
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/module/core/pt/schemaItem.pt.hbs +1 -1
- package/dist/script/dump.js +10 -2
- package/dist/script/dump.ts +12 -4
- package/dist/script/migrate.d.ts.map +1 -1
- package/dist/script/migrate.js +4 -0
- package/dist/script/migrate.ts +10 -0
- package/dist/server/routes/table/controllers/suggest.d.ts.map +1 -1
- package/dist/server/routes/table/controllers/suggest.js +2 -3
- package/dist/server/routes/table/functions/getData.js +1 -1
- package/package.json +5 -3
|
@@ -11,7 +11,7 @@ CREATE TABLE if not exists {{nspname}}.{{relname}}
|
|
|
11
11
|
{{column_name}} {{data_type}} {{#unless is_nullable}}NOT NULL{{/unless}}{{#if column_default}}DEFAULT {{column_default}}{{/if}}{{#ifCond @index '!=' (_math ../columns.length '-' 1)}},{{/ifCond}} -- {{{coalesce description '-'}}}
|
|
12
12
|
{{/each}}{{#if constraints.length}},{{/if}}
|
|
13
13
|
{{#each constraints}}
|
|
14
|
-
CONSTRAINT {{constraint_name}} {{#ifCond constraint_type '==' 'f'}}FOREIGN KEY ({{foreign_column}}) REFERENCES {{foreign_table}} ({{foreign_column}}) MATCH {{select confmatchtype data="constraint_matchtype"}} ON UPDATE {{select confupdtype data="constraint_action"}} ON DELETE {{select confdeltype data="constraint_action"}}{{^}}{{select constraint_type data="constraint_type_full"}} ({{column_name}}){{/ifCond}}{{#ifCond @index '!=' (_math ../constraints.length '-' 1)}},{{/ifCond}}
|
|
14
|
+
CONSTRAINT {{constraint_name}} {{#ifCond constraint_type '==' 'c'}} {{check_definition}} {{/ifCond}} {{#ifCond constraint_type '==' 'f'}}FOREIGN KEY ({{foreign_column}}) REFERENCES {{foreign_table}} ({{foreign_column}}) MATCH {{select confmatchtype data="constraint_matchtype"}} ON UPDATE {{select confupdtype data="constraint_action"}} ON DELETE {{select confdeltype data="constraint_action"}}{{^}}{{select constraint_type data="constraint_type_full"}} ({{column_name}}){{/ifCond}}{{#ifCond @index '!=' (_math ../constraints.length '-' 1)}},{{/ifCond}}
|
|
15
15
|
{{/each}}
|
|
16
16
|
);
|
|
17
17
|
|
package/dist/script/dump.js
CHANGED
|
@@ -115,7 +115,8 @@ async function schemaItem({ pg, table, schema, debug, }) {
|
|
|
115
115
|
throw new Error("invalid params");
|
|
116
116
|
const { rows: constraints } = await pg.query(`select con.conrelid::regclass as constraint_table, a.column_name,
|
|
117
117
|
con.conname as constraint_name,contype as constraint_type, con.confrelid::regclass as foreign_table,
|
|
118
|
-
con.confupdtype, con.confdeltype, con.confmatchtype, u.column_name as foreign_column
|
|
118
|
+
con.confupdtype, con.confdeltype, con.confmatchtype, u.column_name as foreign_column,
|
|
119
|
+
case when contype='c' then pg_get_constraintdef(con.oid, true) else null end AS check_definition from pg_constraint con
|
|
119
120
|
left join pg_class c ON c.oid = con.conrelid
|
|
120
121
|
left join pg_namespace n ON n.oid = c.relnamespace
|
|
121
122
|
left join lateral (
|
|
@@ -136,7 +137,14 @@ async function schemaItem({ pg, table, schema, debug, }) {
|
|
|
136
137
|
Object.assign(col, { constraint_type });
|
|
137
138
|
});
|
|
138
139
|
// table relations
|
|
139
|
-
const tableConstraints = constraints
|
|
140
|
+
const tableConstraints = constraints
|
|
141
|
+
?.filter((el) => el?.constraint_table === `${row.nspname}.${row.relname}`)
|
|
142
|
+
?.map((el) => ({
|
|
143
|
+
...el,
|
|
144
|
+
check_definition: el.check_definition
|
|
145
|
+
? new handlebars.SafeString(el.check_definition)
|
|
146
|
+
: null,
|
|
147
|
+
}));
|
|
140
148
|
Object.assign(row, { constraints: tableConstraints });
|
|
141
149
|
});
|
|
142
150
|
if (debug)
|
package/dist/script/dump.ts
CHANGED
|
@@ -156,7 +156,8 @@ async function schemaItem({
|
|
|
156
156
|
const { rows: constraints } =
|
|
157
157
|
await pg.query(`select con.conrelid::regclass as constraint_table, a.column_name,
|
|
158
158
|
con.conname as constraint_name,contype as constraint_type, con.confrelid::regclass as foreign_table,
|
|
159
|
-
con.confupdtype, con.confdeltype, con.confmatchtype, u.column_name as foreign_column
|
|
159
|
+
con.confupdtype, con.confdeltype, con.confmatchtype, u.column_name as foreign_column,
|
|
160
|
+
case when contype='c' then pg_get_constraintdef(con.oid, true) else null end AS check_definition from pg_constraint con
|
|
160
161
|
left join pg_class c ON c.oid = con.conrelid
|
|
161
162
|
left join pg_namespace n ON n.oid = c.relnamespace
|
|
162
163
|
left join lateral (
|
|
@@ -185,9 +186,16 @@ async function schemaItem({
|
|
|
185
186
|
});
|
|
186
187
|
|
|
187
188
|
// table relations
|
|
188
|
-
const tableConstraints = constraints
|
|
189
|
-
(
|
|
190
|
-
|
|
189
|
+
const tableConstraints = constraints
|
|
190
|
+
?.filter(
|
|
191
|
+
(el: any) => el?.constraint_table === `${row.nspname}.${row.relname}`
|
|
192
|
+
)
|
|
193
|
+
?.map((el: any) => ({
|
|
194
|
+
...el,
|
|
195
|
+
check_definition: el.check_definition
|
|
196
|
+
? new handlebars.SafeString(el.check_definition)
|
|
197
|
+
: null,
|
|
198
|
+
}));
|
|
191
199
|
Object.assign(row, { constraints: tableConstraints });
|
|
192
200
|
});
|
|
193
201
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../script/migrate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../script/migrate.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,OAAO,UAAU,OAAO,SAuB9B"}
|
package/dist/script/migrate.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import Fastify from "fastify";
|
|
2
3
|
import config from "../config.js";
|
|
3
4
|
import plugin from "../index.js";
|
|
5
|
+
import execMigrations from "../server/plugins/migration/exec.migrations.js";
|
|
6
|
+
import pgClients from "../server/plugins/pg/pgClients.js";
|
|
4
7
|
const timeoutMs = +(config.migrationTimeout || 5000);
|
|
5
8
|
const port = process.env.PORT || config.port || 3000;
|
|
6
9
|
if (import.meta.main) {
|
|
@@ -11,6 +14,7 @@ export default function migrate() {
|
|
|
11
14
|
app.register(plugin, config);
|
|
12
15
|
app.listen({ host: "0.0.0.0", port }, (err) => {
|
|
13
16
|
console.log(`Server started via port: ${port}`);
|
|
17
|
+
execMigrations(path.join(process.cwd(), "server/migrations"), pgClients.client).catch((err) => console.error(err.toString()));
|
|
14
18
|
setTimeout(() => {
|
|
15
19
|
console.log("Server closed after timeout", timeoutMs);
|
|
16
20
|
app.close();
|
package/dist/script/migrate.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import Fastify from "fastify";
|
|
2
3
|
|
|
3
4
|
import config from "../config.js";
|
|
4
5
|
import plugin from "../index.js";
|
|
5
6
|
|
|
7
|
+
import execMigrations from "../server/plugins/migration/exec.migrations.js";
|
|
8
|
+
import pgClients from "../server/plugins/pg/pgClients.js";
|
|
9
|
+
|
|
6
10
|
const timeoutMs = +(config.migrationTimeout || 5000);
|
|
7
11
|
|
|
8
12
|
const port = process.env.PORT || config.port || 3000;
|
|
@@ -18,6 +22,12 @@ export default function migrate() {
|
|
|
18
22
|
|
|
19
23
|
app.listen({ host: "0.0.0.0", port }, (err: any) => {
|
|
20
24
|
console.log(`Server started via port: ${port}`);
|
|
25
|
+
|
|
26
|
+
execMigrations(
|
|
27
|
+
path.join(process.cwd(), "server/migrations"),
|
|
28
|
+
pgClients.client
|
|
29
|
+
).catch((err) => console.error(err.toString()));
|
|
30
|
+
|
|
21
31
|
setTimeout(() => {
|
|
22
32
|
console.log("Server closed after timeout", timeoutMs);
|
|
23
33
|
app.close();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suggest.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/suggest.ts"],"names":[],"mappings":"AA+DA,wBAA8B,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"suggest.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/suggest.ts"],"names":[],"mappings":"AA+DA,wBAA8B,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,gBAqXzD"}
|
|
@@ -231,9 +231,8 @@ export default async function suggest(req, reply) {
|
|
|
231
231
|
}
|
|
232
232
|
// query
|
|
233
233
|
const { rows: dataNew } = await pg.query(sqlSuggest, query.key ? [query.key.toLowerCase()] : []);
|
|
234
|
-
//
|
|
235
|
-
|
|
236
|
-
const data = dataNew.filter((el) => el.id && el.text);
|
|
234
|
+
// in case id / text = Boolean
|
|
235
|
+
const data = dataNew.filter((el) => Object.hasOwn(el, "id") && Object.hasOwn(el, "text"));
|
|
237
236
|
if (tableName && column) {
|
|
238
237
|
const { name = query.sel || column, type = "select" } = getColumnCLS(tableName, column) || {};
|
|
239
238
|
await metaFormat({
|
|
@@ -231,7 +231,7 @@ export default async function dataAPI({ pg = pgClients.client, params, table, id
|
|
|
231
231
|
const fData = checkFilter
|
|
232
232
|
? await getFilterSQL({
|
|
233
233
|
pg,
|
|
234
|
-
table: loadTable ? paramsTable : table1,
|
|
234
|
+
table: loadTable ? tokenData?.table || paramsTable : table1,
|
|
235
235
|
filter: query?.filter,
|
|
236
236
|
search: query?.search,
|
|
237
237
|
state: query?.state,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengis/fastify-table",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.115",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "core-plugins",
|
|
6
6
|
"keywords": [
|
|
@@ -21,8 +21,10 @@
|
|
|
21
21
|
"dist/*"
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
|
24
|
-
"dump": "bun ./
|
|
25
|
-
"migrate": "MIGRATE=true bun ./
|
|
24
|
+
"dump": "bun ./script/dump.ts",
|
|
25
|
+
"migrate": "MIGRATE=true bun ./script/migrate.ts",
|
|
26
|
+
"dump1": "bun ./dist/script/dump.js",
|
|
27
|
+
"migrate1": "MIGRATE=true bun ./dist/script/migrate.js",
|
|
26
28
|
"prepublishOnly": "npm run build",
|
|
27
29
|
"clean": "tsc -b --clean",
|
|
28
30
|
"build": "tsc -b --clean && tsc && copyfiles server/plugins/grpc/utils/*.proto dist && copyfiles server/migrations/*.sql dist && copyfiles server/templates/**/*.html dist && copyfiles server/templates/**/*.hbs dist && copyfiles script/* dist && copyfiles -u 2 module/core/*/* dist/module/core",
|