@opengis/fastify-table 2.3.3 → 2.3.5

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":"checkPermissions.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/policy/funcs/checkPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,wBAAwB,CAAC;AAMhC,wBAA8B,gBAAgB,CAAC,GAAG,EAAE,eAAe;;;UA+DlE"}
1
+ {"version":3,"file":"checkPermissions.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/policy/funcs/checkPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,wBAAwB,CAAC;AAMhC,wBAA8B,gBAAgB,CAAC,GAAG,EAAE,eAAe;;;UA4DlE"}
@@ -17,10 +17,7 @@ export default async function checkPermissions(req) {
17
17
  return null;
18
18
  }
19
19
  const userPermissions = await getUserPermissions({ uid: user?.uid, userType: user?.user_type }, pg).then((arr) => arr.reduce((acc, curr) => ({ ...acc, [curr.name]: curr.actions }), {}));
20
- const havePermission = Object.keys(userPermissions).length &&
21
- permissions?.length &&
22
- permissions.length ===
23
- permissions.filter(([key, value]) => userPermissions[key]?.includes(value)).length;
20
+ const havePermission = permissions?.some(([key, value]) => userPermissions?.[key]?.includes(value)) ?? false;
24
21
  if (!user?.user_type?.includes?.("admin") && !havePermission) {
25
22
  logger.file("policy/permissions", {
26
23
  path,
@@ -1 +1 @@
1
- {"version":3,"file":"getSelect.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/table/funcs/getSelect.ts"],"names":[],"mappings":"AAYA,wBAA8B,SAAS,CACrC,IAAI,EAAE,GAAG,EACT,EAAE,MAAmB,EACrB,OAAO,UAAQ,gBAgChB"}
1
+ {"version":3,"file":"getSelect.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/table/funcs/getSelect.ts"],"names":[],"mappings":"AAYA,wBAA8B,SAAS,CACrC,IAAI,EAAE,GAAG,EACT,EAAE,MAAmB,EACrB,OAAO,UAAQ,gBAmChB"}
@@ -23,6 +23,9 @@ export default async function getSelect(name, pg = pgClients.client, nocache = f
23
23
  .then((el) => el.rows?.find((item) => item?.data)?.data)
24
24
  : undefined;
25
25
  const clsData = clsDataDB ?? clsDataGIT;
26
+ if (type === "json" && !clsData) {
27
+ return { arr: [] }; // return 200 after creation of empty user cls
28
+ }
26
29
  if (!clsData)
27
30
  return null;
28
31
  // console.log(clsData);
@@ -13,7 +13,10 @@ export declare function addCustomCls({ name, description, alias, table, uid, dat
13
13
  active?: boolean;
14
14
  }[];
15
15
  }, pg?: any): Promise<string>;
16
- export declare function deleteUserCls(name: string, pg?: any): Promise<string>;
16
+ export declare function deleteUserCls({ name, code }: {
17
+ name: string;
18
+ code?: string;
19
+ }, pg?: any): Promise<string>;
17
20
  export declare function addUserCls({ name, alias, data, description, }: {
18
21
  name: string;
19
22
  alias?: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/usercls/index.ts"],"names":[],"mappings":"AAMA,wBAAsB,YAAY,CAChC,EACE,IAAI,EACJ,WAAW,EACX,KAAK,EACL,KAAK,EACL,GAAG,EACH,IAAS,GACV,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE;QACJ,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB,EAAE,CAAC;CACL,EACD,EAAE,MAAmB,mBA8EtB;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAmB,mBAUtE;AAED,wBAAsB,UAAU,CAC9B,EACE,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,WAAW,GACZ,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;CACtC,EACD,EAAE,MAAmB,mBAkDtB;AAED,wBAAsB,WAAW,CAC/B,EACE,IAAI,EACJ,KAAK,EACL,WAAW,EACX,IAAI,GACL,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;CACtC,EACD,EAAE,MAAmB,mBAKtB;AAED,wBAAsB,cAAc,CAClC,EACE,IAAI,EACJ,MAAM,EACN,GAAG,EACH,MAAM,EACN,IAAI,GACL,EAAE;IACD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,EACD,EAAE,MAAmB,gBAgDtB;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAmB;;;;;UAsBnE;;AAED,wBAAoB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/usercls/index.ts"],"names":[],"mappings":"AAMA,wBAAsB,YAAY,CAChC,EACE,IAAI,EACJ,WAAW,E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AAC;CACtC,EACD,EAAE,MAAmB,mBAKtB;AAED,wBAAsB,cAAc,CAClC,EACE,IAAI,EACJ,MAAM,EACN,GAAG,EACH,MAAM,EACN,IAAI,GACL,EAAE;IACD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,EACD,EAAE,MAAmB,gBAgDtB;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAmB;;;;;UAsBnE;;AAED,wBAAoB"}
@@ -62,21 +62,25 @@ export async function addCustomCls({ name, description, alias, table, uid, data
62
62
  client.release();
63
63
  }
64
64
  }
65
- export async function deleteUserCls(name, pg = pgClients.client) {
65
+ export async function deleteUserCls({ name, code }, pg = pgClients.client) {
66
+ if (!name) {
67
+ throw new Error("not enough params: name");
68
+ }
66
69
  const exists = await getUserCls(name, pg);
67
70
  if (!exists) {
68
71
  throw new NotFoundError("user classifier not found");
69
72
  }
70
- await pg.query("delete from admin.user_cls where (name=$1 and parent is null) or parent=$1 ", [name]);
73
+ await pg.query(`delete from admin.user_cls where ((name=$1 and parent is null) or parent=$1) and ${code ? "code=$2" : "true"}`, [name, code].filter(Boolean));
71
74
  return "ok";
72
75
  }
73
76
  export async function addUserCls({ name, alias, data, description, }, pg = pgClients.client) {
74
77
  const type = typeof data === "string" ? "sql" : "json";
75
- if (type === "json" && !Array.isArray(data)) {
78
+ if (type === "json" && data && !Array.isArray(data)) {
76
79
  throw new Error("param data must be an array");
77
80
  }
78
81
  if (type === "json" &&
79
- typeof data === "object" &&
82
+ Array.isArray(data) &&
83
+ data.length &&
80
84
  !data.find((item) => item.id && item.text)) {
81
85
  throw new Error("param data must have items");
82
86
  }
@@ -90,19 +94,21 @@ export async function addUserCls({ name, alias, data, description, }, pg = pgCli
90
94
  data: { name, alias, description, type, data },
91
95
  });
92
96
  }
93
- else if (type === "json" && Array.isArray(data)) {
97
+ else if (type === "json") {
94
98
  await dataInsert({
95
99
  pg: client,
96
100
  table: "admin.user_cls",
97
101
  data: { name, alias, description, type },
98
102
  });
99
- await Promise.all(data.map(async (item) => {
100
- await dataInsert({
101
- pg: client,
102
- table: "admin.user_cls",
103
- data: { ...item, code: item.id, name: item.text, parent: name },
104
- });
105
- }));
103
+ if (Array.isArray(data) && data.length) {
104
+ await Promise.all(data.map(async (item) => {
105
+ await dataInsert({
106
+ pg: client,
107
+ table: "admin.user_cls",
108
+ data: { ...item, code: item.id, name: item.text, parent: name },
109
+ });
110
+ }));
111
+ }
106
112
  }
107
113
  await client.query("commit");
108
114
  return "ok";
@@ -116,7 +122,7 @@ export async function addUserCls({ name, alias, data, description, }, pg = pgCli
116
122
  }
117
123
  }
118
124
  export async function editUserCls({ name, alias, description, data, }, pg = pgClients.client) {
119
- await deleteUserCls(name, pg);
125
+ await deleteUserCls({ name }, pg);
120
126
  await addUserCls({ name, alias, description, data }, pg);
121
127
  return "ok";
122
128
  }
@@ -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;AAuBpD,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;;;;;UAwFA;AAED,wBAA8B,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,gBA0XzD"}
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;AAuBpD,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;;;;;UAwFA;AAED,wBAA8B,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,gBAuYzD"}
@@ -32,7 +32,7 @@ export async function getTableColumnMeta({ table, template, column, selectName,
32
32
  color: "#B8B8B8",
33
33
  icon: null,
34
34
  id: "null",
35
- text: "None",
35
+ text: "Показати порожні значення",
36
36
  });
37
37
  }
38
38
  // w/out select
@@ -268,13 +268,14 @@ export default async function suggest(req, reply) {
268
268
  const where = [search, val, filter, meta.pk ? `${meta.pk} is not null` : null]
269
269
  .filter(Boolean)
270
270
  .join(" and ") || "true";
271
- // const sqlSuggest = `with c(id,text) as ( ${meta.original.replace(/{{parent}}/gi, parent)} where ${where} ${meta.original.toLowerCase().includes("order by") ? "" : "order by 2"}) select * from c where ${filter} limit ${Math.min(query.limit || meta.limit || limit, limit)}`.replace(/{{uid}}/g, user?.uid || "0");
272
- const sqlSuggest = `${meta.original}
273
- WHERE EXISTS ( SELECT 1 FROM ${tableName} o WHERE o.${column} IS NOT DISTINCT FROM c.id ) and ${val || "true"} and ${search || "true"}
274
- ${meta.original.toLowerCase().includes("order by") ? "" : "order by 2"}
275
- LIMIT ${Math.min(query.limit || meta.limit || limit, limit)}`
276
- .replace(/{{parent}}/gi, parent)
277
- .replace(/{{uid}}/g, user?.uid || "0");
271
+ const sqlSuggest = tableName && column
272
+ ? `${meta.original}
273
+ WHERE EXISTS ( SELECT 1 FROM ${tableName} o WHERE o.${column} IS NOT DISTINCT FROM c.id ) and ${val || "true"} and ${search || "true"}
274
+ ${meta.original.toLowerCase().includes("order by") ? "" : "order by 2"}
275
+ LIMIT ${Math.min(query.limit || meta.limit || limit, limit)}`
276
+ .replace(/{{parent}}/gi, parent)
277
+ .replace(/{{uid}}/g, user?.uid || "0")
278
+ : `with c(id,text) as ( ${meta.original.replace(/{{parent}}/gi, parent)} where ${where} ${meta.original.toLowerCase().includes("order by") ? "" : "order by 2"}) select * from c where ${filter} limit ${Math.min(query.limit || meta.limit || limit, limit)}`.replace(/{{uid}}/g, user?.uid || "0");
278
279
  if (query.sql && debugMode) {
279
280
  return sqlSuggest;
280
281
  }
@@ -283,7 +284,7 @@ export default async function suggest(req, reply) {
283
284
  const data = dataNew.filter((el) => Object.hasOwn(el, "id") && Object.hasOwn(el, "text"));
284
285
  data
285
286
  .filter((el) => el.id === null)
286
- .forEach((el) => Object.assign(el, { id: "null", text: "None" }));
287
+ .forEach((el) => Object.assign(el, { id: "null", text: "Показати порожні значення" }));
287
288
  // table:column + select
288
289
  if (tableName && column) {
289
290
  const { name = selectName || column, type = "select" } = getColumnCLS(tableName, column) || {};
@@ -2,7 +2,7 @@ import pgClients from "../../../plugins/pg/pgClients.js";
2
2
  import getSelectMeta from "../../../plugins/table/funcs/getSelectMeta.js";
3
3
  import { deleteUserCls } from "../../../plugins/usercls/index.js";
4
4
  export default async function deleteUserClsApi({ pg = pgClients.client, params, user }, reply) {
5
- const { name } = params;
5
+ const { name, code } = params;
6
6
  const t1 = Date.now();
7
7
  if (!user?.uid) {
8
8
  return reply.status(401).send({ error: "unauthorized", code: 401 });
@@ -12,6 +12,6 @@ export default async function deleteUserClsApi({ pg = pgClients.client, params,
12
12
  name,
13
13
  nocache: 1,
14
14
  });
15
- await deleteUserCls(name, pg);
16
- return reply.status(200).send({ time: Date.now() - t1, name });
15
+ await deleteUserCls({ name, code }, pg);
16
+ return reply.status(200).send({ time: Date.now() - t1, name, code });
17
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/routes/usercls/index.ts"],"names":[],"mappings":"AAgCA,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,GAAG,EAAE,GAAG,QAqCtC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/routes/usercls/index.ts"],"names":[],"mappings":"AAiCA,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,GAAG,EAAE,GAAG,QA4CtC"}
@@ -2,6 +2,7 @@ const userClsParamsSchema = {
2
2
  type: "object",
3
3
  properties: {
4
4
  name: { type: "string" },
5
+ code: { type: "string" },
5
6
  },
6
7
  required: ["name"],
7
8
  };
@@ -12,7 +13,7 @@ const addUserClsBodySchema = {
12
13
  data: {},
13
14
  table: { type: "string" },
14
15
  },
15
- required: ["name", "data"],
16
+ required: ["name"],
16
17
  };
17
18
  const editUserClsBodySchema = {
18
19
  type: "object",
@@ -48,4 +49,7 @@ export default function plugin(app) {
48
49
  if (!app.hasRoute({ method: "DELETE", url: "/api/user-cls/:name" })) {
49
50
  app.delete("/user-cls/:name", { config: { policy: "L1" }, schema: { params: userClsParamsSchema } }, deleteUserCls);
50
51
  }
52
+ if (!app.hasRoute({ method: "DELETE", url: "/api/user-cls/:name/:code" })) {
53
+ app.delete("/user-cls/:name/:code", { config: { policy: "L1" }, schema: { params: userClsParamsSchema } }, deleteUserCls);
54
+ }
51
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.3.3",
3
+ "version": "2.3.5",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [