@opengis/fastify-table 2.6.1 → 2.6.3
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/helper.d.ts +1 -20
- package/dist/helper.d.ts.map +1 -1
- package/dist/server/migrations/roles.sql +1 -0
- package/dist/server/plugins/auth/index.js +3 -3
- package/dist/server/routes/table/controllers/suggest.d.ts.map +1 -1
- package/dist/server/routes/table/controllers/suggest.js +23 -12
- package/dist/server/routes/table/schema.d.ts +5 -0
- package/dist/server/routes/table/schema.d.ts.map +1 -1
- package/dist/server/routes/table/schema.js +1 -0
- package/package.json +3 -3
- package/dist/module/core/select/core.user_mentioned.json +0 -3
package/dist/helper.d.ts
CHANGED
|
@@ -1,26 +1,7 @@
|
|
|
1
1
|
import config from "./config.js";
|
|
2
2
|
import { pgClients } from "./utils.js";
|
|
3
3
|
declare const prefix: any;
|
|
4
|
-
export declare function injectWithHeaders(opts: any): Promise<
|
|
5
|
-
json: () => unknown;
|
|
6
|
-
body: unknown;
|
|
7
|
-
headers: {
|
|
8
|
-
[k: string]: string;
|
|
9
|
-
};
|
|
10
|
-
statusCode: number;
|
|
11
|
-
ok: boolean;
|
|
12
|
-
status: number;
|
|
13
|
-
statusText: string;
|
|
14
|
-
type: import("undici-types").ResponseType;
|
|
15
|
-
url: string;
|
|
16
|
-
redirected: boolean;
|
|
17
|
-
bodyUsed: boolean;
|
|
18
|
-
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
19
|
-
blob: () => Promise<import("node:buffer").Blob>;
|
|
20
|
-
bytes: () => Promise<Uint8Array>;
|
|
21
|
-
formData: () => Promise<import("undici-types").FormData>;
|
|
22
|
-
text: () => Promise<string>;
|
|
23
|
-
}>;
|
|
4
|
+
export declare function injectWithHeaders(opts: any): Promise<any>;
|
|
24
5
|
export declare function setup(): Promise<void>;
|
|
25
6
|
export declare function teardown(): Promise<void>;
|
|
26
7
|
export declare function build(): Promise<any>;
|
package/dist/helper.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../helper.ts"],"names":[],"mappings":"AAEA,OAAO,MAAM,MAAM,aAAa,CAAC;AAGjC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,QAAA,MAAQ,MAAM,KAAoB,CAAC;AAInC,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,GAAG
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../helper.ts"],"names":[],"mappings":"AAEA,OAAO,MAAM,MAAM,aAAa,CAAC;AAGjC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,QAAA,MAAQ,MAAM,KAAoB,CAAC;AAInC,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAiC/D;AAED,wBAAsB,KAAK,kBAI1B;AAGD,wBAAsB,QAAQ,kBAW7B;AAED,wBAAsB,KAAK,iBA+B1B;AAED,OAAO,EAEL,MAAM,EACN,MAAM,EACN,SAAS,GACV,CAAC"}
|
|
@@ -130,6 +130,7 @@ ALTER TABLE admin.user_roles ADD COLUMN IF NOT EXISTS access_granted_time timest
|
|
|
130
130
|
ALTER TABLE admin.user_roles ADD COLUMN IF NOT EXISTS actions text [];
|
|
131
131
|
|
|
132
132
|
ALTER TABLE admin.user_roles ADD CONSTRAINT admin_user_roles_pkey PRIMARY KEY (ugr_id);
|
|
133
|
+
delete from admin.user_roles where user_uid not in (select uid from admin.users); -- prevent migration errors caused by missing users
|
|
133
134
|
ALTER TABLE admin.user_roles ADD CONSTRAINT user_roles_user_uid_fkey FOREIGN KEY (user_uid) REFERENCES admin.users (uid) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE;
|
|
134
135
|
ALTER TABLE admin.user_roles ADD CONSTRAINT admin_user_roles_role_id_fkey FOREIGN KEY (role_id) REFERENCES admin.roles (role_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE;
|
|
135
136
|
ALTER TABLE admin.user_roles ADD CONSTRAINT admin_user_roles_user_uid_role_id_key UNIQUE (user_uid, role_id);
|
|
@@ -7,8 +7,8 @@ import config from "../../../config.js";
|
|
|
7
7
|
import getRedis from "../redis/funcs/getRedis.js";
|
|
8
8
|
import { ForbiddenError } from "../../../errors.js";
|
|
9
9
|
const { prefix = "/api" } = config;
|
|
10
|
-
const {
|
|
11
|
-
if (!secret) {
|
|
10
|
+
const { auth } = config || {};
|
|
11
|
+
if (!auth?.secret && process.platform !== 'win32') {
|
|
12
12
|
throw new Error("environment variable auth.secret not set");
|
|
13
13
|
}
|
|
14
14
|
const fastifyPassport = new Authenticator();
|
|
@@ -127,7 +127,7 @@ function plugin(fastify) {
|
|
|
127
127
|
parseOptions: config?.auth?.cookieOptions || { secure: false },
|
|
128
128
|
});
|
|
129
129
|
fastify.register(session, {
|
|
130
|
-
secret: secret,
|
|
130
|
+
secret: auth?.secret || 'fastify-session-redis-store-secret',
|
|
131
131
|
cookieName: "session_auth",
|
|
132
132
|
cookie: config?.auth?.cookieOptions || { secure: false },
|
|
133
133
|
store: new RedisStore({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suggest.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/suggest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"suggest.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/suggest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AA+BpD,wBAAsB,kBAAkB,CAAC,EACvC,KAAK,EACL,QAAQ,EACR,MAAM,EACN,UAAU,EACV,QAAQ,EACR,UAAU,EACV,GAAG,EACH,EAAqB,GACtB,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,UAAU,CAAC;CACjB;;;;;;UAyGA;AAED,wBAA8B,OAAO,CAAC,GAAG,EAAE,GAAG,gBAif7C"}
|
|
@@ -13,7 +13,7 @@ export async function getTableColumnMeta({ table, template, column, selectName,
|
|
|
13
13
|
table,
|
|
14
14
|
}).then((el) => el?.columns || []);
|
|
15
15
|
const { dataTypeID } = (metaColumns || []).find((col) => col?.name === column) || {};
|
|
16
|
-
const { columns, table: tableName, sql, } = template ? await getTemplate("table", template) : { table, columns: [] };
|
|
16
|
+
const { columns, table: tableName, sql, } = template ? await getTemplate("table", template) : { sql: [], table, columns: [] };
|
|
17
17
|
const filters = template
|
|
18
18
|
? await getFilter({ pg, table: template }).then((el) => el.list)
|
|
19
19
|
: null;
|
|
@@ -83,7 +83,7 @@ export async function getTableColumnMeta({ table, template, column, selectName,
|
|
|
83
83
|
export default async function suggest(req) {
|
|
84
84
|
const time = Date.now();
|
|
85
85
|
const { params, user, query = {}, pg: pg1 = pgClients.client } = req;
|
|
86
|
-
const { lang = "ua", parent } = query;
|
|
86
|
+
const { lang = "ua", parent, page = 0 } = query;
|
|
87
87
|
const debugMode = config.local ||
|
|
88
88
|
user?.user_type?.includes?.("admin") ||
|
|
89
89
|
process.env.NODE_ENV === "test" ||
|
|
@@ -258,7 +258,9 @@ export default async function suggest(req) {
|
|
|
258
258
|
const data2 = data1.filter((el) => el.id === "null"
|
|
259
259
|
? vals.includes(null)
|
|
260
260
|
: el.id && vals.includes(el.id.toString()));
|
|
261
|
-
const
|
|
261
|
+
const limit1 = Math.min(query.limit || limit, limit);
|
|
262
|
+
const offset = page && page > 0 ? (page - 1) * limit1 : 0;
|
|
263
|
+
const data = data2.slice(offset, limit1 + offset);
|
|
262
264
|
if (data.length && query.count) {
|
|
263
265
|
const counts = qRes.rows?.reduce?.((acc, curr) => ({
|
|
264
266
|
...acc,
|
|
@@ -280,7 +282,8 @@ export default async function suggest(req) {
|
|
|
280
282
|
}
|
|
281
283
|
return {
|
|
282
284
|
time: Date.now() - time,
|
|
283
|
-
limit:
|
|
285
|
+
limit: limit1,
|
|
286
|
+
offset,
|
|
284
287
|
count: data.length,
|
|
285
288
|
total: arr.length,
|
|
286
289
|
mode: "array",
|
|
@@ -298,7 +301,9 @@ export default async function suggest(req) {
|
|
|
298
301
|
(el[lang] || el.text)?.toLowerCase()?.indexOf(lower) !== -1)
|
|
299
302
|
?.filter((el) => !query.val || query.val?.split?.(",")?.includes?.(el.id))
|
|
300
303
|
: arr;
|
|
301
|
-
const
|
|
304
|
+
const limit1 = Math.min(query.limit || limit, limit);
|
|
305
|
+
const offset = page && page > 0 ? (page - 1) * limit1 : 0;
|
|
306
|
+
const data = data1.slice(offset, limit1 + offset);
|
|
302
307
|
if (config.debug) {
|
|
303
308
|
logger.file("suggest/debug", {
|
|
304
309
|
type: 2,
|
|
@@ -309,11 +314,12 @@ export default async function suggest(req) {
|
|
|
309
314
|
}
|
|
310
315
|
return {
|
|
311
316
|
time: Date.now() - time,
|
|
312
|
-
limit:
|
|
317
|
+
limit: limit1,
|
|
318
|
+
offset,
|
|
313
319
|
count: data.length,
|
|
314
320
|
total: arr.length,
|
|
315
321
|
mode: "array",
|
|
316
|
-
data
|
|
322
|
+
data
|
|
317
323
|
};
|
|
318
324
|
}
|
|
319
325
|
const args = [];
|
|
@@ -343,15 +349,18 @@ export default async function suggest(req) {
|
|
|
343
349
|
? ""
|
|
344
350
|
: "order by 2";
|
|
345
351
|
const whereQuery = where.filter(Boolean).join(" and ") || "true";
|
|
346
|
-
|
|
352
|
+
const limit1 = Math.min(query.limit || meta.limit || limit, limit);
|
|
353
|
+
const offset = page && page > 0 ? (page - 1) * limit1 : 0;
|
|
354
|
+
args.push(limit1);
|
|
355
|
+
args.push(offset);
|
|
347
356
|
let sqlSuggest = tableName && column
|
|
348
357
|
? `${meta.original}
|
|
349
358
|
WHERE EXISTS ( SELECT 1 FROM ${tableName} o
|
|
350
359
|
WHERE ${pg.pgType[dataTypeID]?.includes("[]")
|
|
351
360
|
? `c.id = ANY(o."${column}")`
|
|
352
361
|
: `o."${column}" IS NOT DISTINCT FROM c.id`} ) and ${whereQuery || "true"}
|
|
353
|
-
${order} LIMIT $${args.length}::int`
|
|
354
|
-
: `with c(id,text) as ( ${meta.original} where ${whereQuery} ${order}) select * from c LIMIT $${args.length}::int`;
|
|
362
|
+
${order} LIMIT $${args.length - 1}::int OFFSET $${args.length}::int`
|
|
363
|
+
: `with c(id,text) as ( ${meta.original} where ${whereQuery} ${order}) select * from c LIMIT $${args.length - 1}::int OFFSET $${args.length}::int`;
|
|
355
364
|
if (sqlSuggest.includes("{{parent}}")) {
|
|
356
365
|
args.push(parent || "");
|
|
357
366
|
sqlSuggest = sqlSuggest.replace(/(['"]?){{parent}}\1/gi, `$${args.length}`);
|
|
@@ -385,7 +394,8 @@ export default async function suggest(req) {
|
|
|
385
394
|
});
|
|
386
395
|
return {
|
|
387
396
|
time: Date.now() - time,
|
|
388
|
-
limit:
|
|
397
|
+
limit: limit1,
|
|
398
|
+
offset,
|
|
389
399
|
count: data.length,
|
|
390
400
|
total: meta.count - 0,
|
|
391
401
|
mode: type === "cls" ? "array" : "sql",
|
|
@@ -418,7 +428,8 @@ export default async function suggest(req) {
|
|
|
418
428
|
}
|
|
419
429
|
const message = {
|
|
420
430
|
time: Date.now() - time,
|
|
421
|
-
limit:
|
|
431
|
+
limit: limit1,
|
|
432
|
+
offset,
|
|
422
433
|
count: data.length,
|
|
423
434
|
total: meta.count - 0,
|
|
424
435
|
mode: "sql",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../server/routes/table/schema.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyBpB,CAAC;AAEF,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BhB,CAAC;AAEF,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAajB,CAAC;AAEF,QAAA,MAAM,aAAa
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../server/routes/table/schema.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyBpB,CAAC;AAEF,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BhB,CAAC;AAEF,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAajB,CAAC;AAEF,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwBlB,CAAC;AAEF,QAAA,MAAM,UAAU;;;;;;;;;;;;;;CAQf,CAAC;AAEF,QAAA,MAAM,YAAY;;;;;;;;;;CAOjB,CAAC;AAEF,QAAA,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;CAatB,CAAC;AAEF,QAAA,MAAM,iBAAiB;;;;;;;;;;;;;;CAQtB,CAAC;AAEF,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,UAAU,EACV,YAAY,EACZ,iBAAiB,GAClB,CAAC"}
|
|
@@ -76,6 +76,7 @@ const suggestSchema = {
|
|
|
76
76
|
properties: {
|
|
77
77
|
lang: { type: "string", pattern: "^([\\w]+)$" },
|
|
78
78
|
limit: { type: "integer", minimum: 1, maximum: 200 },
|
|
79
|
+
page: { type: "integer", minimum: 1, maximum: 1000 },
|
|
79
80
|
parent: { type: "string", pattern: "^([\\d\\w_.-]+)$" },
|
|
80
81
|
sel: { type: "string", pattern: "^([\\d\\w_.-]+)$" },
|
|
81
82
|
name: { type: "string", pattern: "^([\\d\\w_.-]+)$" },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengis/fastify-table",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "core-plugins",
|
|
6
6
|
"keywords": [
|
|
@@ -51,11 +51,11 @@
|
|
|
51
51
|
"@fastify/passport": "3.0.2",
|
|
52
52
|
"@fastify/rate-limit": "11.1.0",
|
|
53
53
|
"@fastify/session": "11.1.1",
|
|
54
|
-
"@grpc/grpc-js": "1.14.
|
|
54
|
+
"@grpc/grpc-js": "1.14.5",
|
|
55
55
|
"@grpc/proto-loader": "0.8.1",
|
|
56
56
|
"apache-crypt": "1.2.6",
|
|
57
57
|
"dotenv": "17.4.2",
|
|
58
|
-
"fastify": "5.
|
|
58
|
+
"fastify": "5.12.5",
|
|
59
59
|
"fastify-plugin": "6.0.0",
|
|
60
60
|
"fastify-session-redis-store": "7.1.2",
|
|
61
61
|
"file-type": "^22.0.1",
|