@opengis/fastify-table 2.5.43 → 2.5.46

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.
Files changed (89) hide show
  1. package/dist/functions.d.ts +1 -0
  2. package/dist/functions.d.ts.map +1 -1
  3. package/dist/functions.js +122 -1
  4. package/dist/helper.d.ts +20 -0
  5. package/dist/helper.d.ts.map +1 -1
  6. package/dist/helper.js +26 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +5 -2
  9. package/dist/server/migrations/dictionaries.sql +79 -0
  10. package/dist/server/plugins/access/funcs/getResources.d.ts +2 -1
  11. package/dist/server/plugins/access/funcs/getResources.d.ts.map +1 -1
  12. package/dist/server/plugins/access/funcs/getResources.js +5 -1
  13. package/dist/server/plugins/crud/funcs/dataDelete.d.ts +2 -1
  14. package/dist/server/plugins/crud/funcs/dataDelete.d.ts.map +1 -1
  15. package/dist/server/plugins/crud/funcs/dataDelete.js +2 -2
  16. package/dist/server/plugins/crud/funcs/getOpt.d.ts +1 -1
  17. package/dist/server/plugins/crud/funcs/getOpt.d.ts.map +1 -1
  18. package/dist/server/plugins/crud/funcs/getOpt.js +1 -1
  19. package/dist/server/plugins/crud/funcs/setOpt.d.ts +1 -1
  20. package/dist/server/plugins/crud/funcs/setOpt.d.ts.map +1 -1
  21. package/dist/server/plugins/crud/funcs/setOpt.js +1 -1
  22. package/dist/server/plugins/crud/funcs/setToken.d.ts +1 -1
  23. package/dist/server/plugins/crud/funcs/setToken.d.ts.map +1 -1
  24. package/dist/server/plugins/table/funcs/getData.d.ts +32 -0
  25. package/dist/server/plugins/table/funcs/getData.d.ts.map +1 -0
  26. package/dist/server/plugins/table/funcs/getData.js +703 -0
  27. package/dist/server/plugins/table/funcs/getFilterSQLParametrized/index.d.ts +2 -1
  28. package/dist/server/plugins/table/funcs/getFilterSQLParametrized/index.d.ts.map +1 -1
  29. package/dist/server/plugins/table/funcs/getFilterSQLParametrized/index.js +2 -2
  30. package/dist/server/routes/crud/controllers/insert.d.ts +1 -2
  31. package/dist/server/routes/crud/controllers/insert.d.ts.map +1 -1
  32. package/dist/server/routes/crud/controllers/insert.js +1 -1
  33. package/dist/server/routes/crud/controllers/table.d.ts +1 -2
  34. package/dist/server/routes/crud/controllers/table.d.ts.map +1 -1
  35. package/dist/server/routes/crud/controllers/table.js +1 -1
  36. package/dist/server/routes/crud/controllers/update.js +1 -1
  37. package/dist/server/routes/crud/crud.route.d.ts +3 -0
  38. package/dist/server/routes/crud/crud.route.d.ts.map +1 -0
  39. package/dist/server/routes/crud/crud.route.js +161 -0
  40. package/dist/server/routes/crud/crud.schema.d.ts +114 -0
  41. package/dist/server/routes/crud/crud.schema.d.ts.map +1 -0
  42. package/dist/server/routes/crud/crud.schema.js +64 -0
  43. package/dist/server/routes/crud/functions/createTableRelation.d.ts +13 -0
  44. package/dist/server/routes/crud/functions/createTableRelation.d.ts.map +1 -0
  45. package/dist/server/routes/crud/functions/createTableRelation.js +93 -0
  46. package/dist/server/routes/crud/functions/deleteTableRelation.d.ts +11 -0
  47. package/dist/server/routes/crud/functions/deleteTableRelation.d.ts.map +1 -0
  48. package/dist/server/routes/crud/functions/deleteTableRelation.js +74 -0
  49. package/dist/server/routes/crud/functions/readTableRelations.d.ts +25 -0
  50. package/dist/server/routes/crud/functions/readTableRelations.d.ts.map +1 -0
  51. package/dist/server/routes/crud/functions/readTableRelations.js +76 -0
  52. package/dist/server/routes/crud/functions/updateTableRelation.d.ts +14 -0
  53. package/dist/server/routes/crud/functions/updateTableRelation.d.ts.map +1 -0
  54. package/dist/server/routes/crud/functions/updateTableRelation.js +117 -0
  55. package/dist/server/routes/dictionaries/dictionaries.route.d.ts +2 -0
  56. package/dist/server/routes/dictionaries/dictionaries.route.d.ts.map +1 -0
  57. package/dist/server/routes/dictionaries/dictionaries.route.js +134 -0
  58. package/dist/server/routes/dictionaries/dictionaries.schema.d.ts +190 -0
  59. package/dist/server/routes/dictionaries/dictionaries.schema.d.ts.map +1 -0
  60. package/dist/server/routes/dictionaries/dictionaries.schema.js +86 -0
  61. package/dist/server/routes/dictionaries/functions/create.dictionary.d.ts +10 -0
  62. package/dist/server/routes/dictionaries/functions/create.dictionary.d.ts.map +1 -0
  63. package/dist/server/routes/dictionaries/functions/create.dictionary.item.d.ts +13 -0
  64. package/dist/server/routes/dictionaries/functions/create.dictionary.item.d.ts.map +1 -0
  65. package/dist/server/routes/dictionaries/functions/create.dictionary.item.js +57 -0
  66. package/dist/server/routes/dictionaries/functions/create.dictionary.js +76 -0
  67. package/dist/server/routes/dictionaries/functions/delete.dictionary.d.ts +9 -0
  68. package/dist/server/routes/dictionaries/functions/delete.dictionary.d.ts.map +1 -0
  69. package/dist/server/routes/dictionaries/functions/delete.dictionary.item.d.ts +11 -0
  70. package/dist/server/routes/dictionaries/functions/delete.dictionary.item.d.ts.map +1 -0
  71. package/dist/server/routes/dictionaries/functions/delete.dictionary.item.js +32 -0
  72. package/dist/server/routes/dictionaries/functions/delete.dictionary.js +28 -0
  73. package/dist/server/routes/dictionaries/functions/read.dictionaries.d.ts +5 -0
  74. package/dist/server/routes/dictionaries/functions/read.dictionaries.d.ts.map +1 -0
  75. package/dist/server/routes/dictionaries/functions/read.dictionaries.js +27 -0
  76. package/dist/server/routes/dictionaries/functions/update.dictionary.d.ts +10 -0
  77. package/dist/server/routes/dictionaries/functions/update.dictionary.d.ts.map +1 -0
  78. package/dist/server/routes/dictionaries/functions/update.dictionary.item.d.ts +13 -0
  79. package/dist/server/routes/dictionaries/functions/update.dictionary.item.d.ts.map +1 -0
  80. package/dist/server/routes/dictionaries/functions/update.dictionary.item.js +48 -0
  81. package/dist/server/routes/dictionaries/functions/update.dictionary.js +51 -0
  82. package/dist/server/routes/file/schema.js +6 -6
  83. package/dist/server/routes/table/functions/getData.d.ts +3 -2
  84. package/dist/server/routes/table/functions/getData.d.ts.map +1 -1
  85. package/dist/server/routes/table/functions/getData.js +2 -14
  86. package/dist/server/routes/table/schema.d.ts +5 -4
  87. package/dist/server/routes/table/schema.d.ts.map +1 -1
  88. package/dist/server/routes/table/schema.js +13 -13
  89. package/package.json +1 -1
@@ -0,0 +1,13 @@
1
+ /**
2
+ *
3
+ * @param {String} id Item ID, optional
4
+ * @param {String} code Dictionary code (filename)
5
+ * @param {String} body.code Item code
6
+ */
7
+ export default function createDictionaryItem({ id, code, body, uid, }: {
8
+ id: string;
9
+ code: string;
10
+ body: Record<string, any>;
11
+ uid: string;
12
+ }, pg?: any): Promise<any>;
13
+ //# sourceMappingURL=create.dictionary.item.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.dictionary.item.d.ts","sourceRoot":"","sources":["../../../../../server/routes/dictionaries/functions/create.dictionary.item.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AAEH,wBAA8B,oBAAoB,CAChD,EACE,EAAE,EACF,IAAI,EACJ,IAAI,EACJ,GAAG,GACJ,EAAE;IACD,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;CACb,EACD,EAAE,MAAmB,gBA2DtB"}
@@ -0,0 +1,57 @@
1
+ import pgClients from "../../../plugins/pg/pgClients.js";
2
+ import dataInsert from "../../../plugins/crud/funcs/dataInsert.js";
3
+ import { BadRequestError, NotFoundError } from "../../../../errors.js";
4
+ import updateDictionary from "./update.dictionary.js";
5
+ /**
6
+ *
7
+ * @param {String} id Item ID, optional
8
+ * @param {String} code Dictionary code (filename)
9
+ * @param {String} body.code Item code
10
+ */
11
+ export default async function createDictionaryItem({ id, code, body, uid, }, pg = pgClients.client) {
12
+ if (!pg) {
13
+ throw new Error("empty pg");
14
+ }
15
+ if (!code) {
16
+ throw BadRequestError("not enough params: code");
17
+ }
18
+ if (!body) {
19
+ throw BadRequestError("not enough params: body");
20
+ }
21
+ if (!body.code) {
22
+ throw BadRequestError("not enough body params: code");
23
+ }
24
+ if (!body.name) {
25
+ throw BadRequestError("not enough body params: name");
26
+ }
27
+ const { system, id: dictionaryId } = await pg
28
+ .query("select id from admin.dictionaries where code=$1", [code])
29
+ .then((r) => ({ system: r.rows?.[0]?.system, id: r.rows?.[0]?.id }));
30
+ if (!dictionaryId) {
31
+ throw NotFoundError("dictionary not found");
32
+ }
33
+ // make custom
34
+ if (system) {
35
+ await updateDictionary({ id: dictionaryId, body: { system: false }, uid }, pg);
36
+ }
37
+ const { data } = await dataInsert({
38
+ id,
39
+ table: "admin.dictionary_items",
40
+ data: {
41
+ code: body.code,
42
+ dictionary_id: dictionaryId,
43
+ name: body.name,
44
+ description: body.description,
45
+ color: body.color,
46
+ icon: body.icon,
47
+ parent_id: body.parent_id,
48
+ sort_order: body.sort,
49
+ metadata: body.metadata,
50
+ system: false,
51
+ active: body.active === false ? false : true,
52
+ },
53
+ pg,
54
+ uid,
55
+ });
56
+ return data;
57
+ }
@@ -0,0 +1,76 @@
1
+ import pgClients from "../../../plugins/pg/pgClients.js";
2
+ import dataInsert from "../../../plugins/crud/funcs/dataInsert.js";
3
+ import deleteDictionary from "./delete.dictionary.js";
4
+ import { BadRequestError } from "../../../../errors.js";
5
+ /**
6
+ *
7
+ * @param {String} id Dictionary ID, optional
8
+ */
9
+ export default async function createDictionary({ id, body, uid, }, pg = pgClients.client) {
10
+ if (!pg) {
11
+ throw new Error("empty pg");
12
+ }
13
+ if (!body) {
14
+ throw BadRequestError("not enough params: body");
15
+ }
16
+ if (!body?.values?.length) {
17
+ // throw BadRequestError("not enough body params: values");
18
+ }
19
+ const client = await pg.connect();
20
+ try {
21
+ const systemDictionaryId = await pg
22
+ .query("select id from admin.dictionaries where system and id = $1", [id])
23
+ .then((r) => r.rows?.[0]?.id);
24
+ await client.query("begin");
25
+ if (systemDictionaryId) {
26
+ await deleteDictionary({ id: systemDictionaryId, uid }, client);
27
+ }
28
+ const { data } = (await dataInsert({
29
+ id,
30
+ table: "admin.dictionaries",
31
+ data: {
32
+ code: body.code,
33
+ name: body.name,
34
+ module: body.module,
35
+ description: body.description,
36
+ source: "custom",
37
+ system: false,
38
+ editable: body.editable === false ? false : true,
39
+ },
40
+ pg: client,
41
+ uid,
42
+ })) || {};
43
+ if (!data) {
44
+ throw new Error("dictionary insert error");
45
+ }
46
+ const values = await Promise.all((body.values || []).map(async (el) => {
47
+ return dataInsert({
48
+ table: "admin.dictionary_items",
49
+ data: {
50
+ dictionary_id: id,
51
+ code: el.code,
52
+ name: el.name,
53
+ description: el.description,
54
+ color: el.color,
55
+ icon: el.icon,
56
+ parent_id: el.parent_id,
57
+ sort_order: el.sort_order,
58
+ metadata: el.metadata,
59
+ system: false,
60
+ active: el.active === false ? false : true,
61
+ },
62
+ pg: client,
63
+ uid,
64
+ }).then((r) => r.data);
65
+ }));
66
+ await client.query("commit");
67
+ return { ...data, values };
68
+ }
69
+ catch (err) {
70
+ await client.query("rollback");
71
+ throw err;
72
+ }
73
+ finally {
74
+ client.release();
75
+ }
76
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ *
3
+ * @param {String} id Dictionary ID
4
+ */
5
+ export default function deleteDictionary({ id, uid, }: {
6
+ id: string;
7
+ uid: string;
8
+ }, pg?: any): Promise<any>;
9
+ //# sourceMappingURL=delete.dictionary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delete.dictionary.d.ts","sourceRoot":"","sources":["../../../../../server/routes/dictionaries/functions/delete.dictionary.ts"],"names":[],"mappings":"AAKA;;;GAGG;AAEH,wBAA8B,gBAAgB,CAC5C,EACE,EAAE,EACF,GAAG,GACJ,EAAE;IACD,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;CACb,EACD,EAAE,MAAmB,gBA6BtB"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ *
3
+ * @param {String} id Item ID
4
+ * @param {String} code Dictionary code (filename)
5
+ */
6
+ export default function deleteDictionaryItem({ id, code, uid, }: {
7
+ id: string;
8
+ code: string;
9
+ uid: string;
10
+ }, pg?: any): Promise<any>;
11
+ //# sourceMappingURL=delete.dictionary.item.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delete.dictionary.item.d.ts","sourceRoot":"","sources":["../../../../../server/routes/dictionaries/functions/delete.dictionary.item.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AAEH,wBAA8B,oBAAoB,CAChD,EACE,EAAE,EACF,IAAI,EACJ,GAAG,GACJ,EAAE;IACD,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb,EACD,EAAE,MAAmB,gBAiCtB"}
@@ -0,0 +1,32 @@
1
+ import pgClients from "../../../plugins/pg/pgClients.js";
2
+ import dataDelete from "../../../plugins/crud/funcs/dataDelete.js";
3
+ import { BadRequestError, NotFoundError } from "../../../../errors.js";
4
+ /**
5
+ *
6
+ * @param {String} id Item ID
7
+ * @param {String} code Dictionary code (filename)
8
+ */
9
+ export default async function deleteDictionaryItem({ id, code, uid, }, pg = pgClients.client) {
10
+ if (!pg) {
11
+ throw new Error("empty pg");
12
+ }
13
+ if (!id) {
14
+ throw BadRequestError("not enough params: id");
15
+ }
16
+ if (!code) {
17
+ throw BadRequestError("not enough params: code");
18
+ }
19
+ const itemId = await pg
20
+ .query("select id from admin.dictionary_items where dictionary_id in (select id from admin.dictionaries where $1 in (id,code) ) and $2 in (id,code)", [code, id])
21
+ .then((r) => r.rows?.[0]?.id);
22
+ if (!itemId) {
23
+ throw NotFoundError("dictionary item not found");
24
+ }
25
+ const item = await dataDelete({
26
+ id: itemId,
27
+ table: "admin.dictionary_items",
28
+ pg,
29
+ uid,
30
+ });
31
+ return item;
32
+ }
@@ -0,0 +1,28 @@
1
+ import pgClients from "../../../plugins/pg/pgClients.js";
2
+ import dataDelete from "../../../plugins/crud/funcs/dataDelete.js";
3
+ import { BadRequestError, NotFoundError } from "../../../../errors.js";
4
+ /**
5
+ *
6
+ * @param {String} id Dictionary ID
7
+ */
8
+ export default async function deleteDictionary({ id, uid, }, pg = pgClients.client) {
9
+ if (!pg) {
10
+ throw new Error("empty pg");
11
+ }
12
+ if (!id) {
13
+ throw BadRequestError("not enough params: id");
14
+ }
15
+ const values = await pg
16
+ .query("delete from admin.dictionary_items where dictionary_id=$1 returning id,code,name,color,icon", [id])
17
+ .then((r) => r.rowCount || 0);
18
+ const row = await dataDelete({
19
+ table: "admin.dictionaries",
20
+ id,
21
+ uid,
22
+ pg,
23
+ });
24
+ if (!row) {
25
+ throw NotFoundError("dictionary not found");
26
+ }
27
+ return { ...row, values };
28
+ }
@@ -0,0 +1,5 @@
1
+ export default function readDictionaries({ code, values, }: {
2
+ code: string;
3
+ values?: boolean;
4
+ }, pg?: any): Promise<any>;
5
+ //# sourceMappingURL=read.dictionaries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read.dictionaries.d.ts","sourceRoot":"","sources":["../../../../../server/routes/dictionaries/functions/read.dictionaries.ts"],"names":[],"mappings":"AAIA,wBAA8B,gBAAgB,CAC5C,EACE,IAAI,EACJ,MAAc,GACf,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,EACD,EAAE,MAAmB,gBAqCtB"}
@@ -0,0 +1,27 @@
1
+ import pgClients from "../../../plugins/pg/pgClients.js";
2
+ import { NotFoundError } from "../../../../errors.js";
3
+ export default async function readDictionaries({ code, values = false, }, pg = pgClients.client) {
4
+ if (!pg) {
5
+ throw new Error("empty pg");
6
+ }
7
+ if (!code) {
8
+ const rows = await pg
9
+ .query("select code,name,module,source from admin.dictionaries")
10
+ .then((r) => r.rows || []);
11
+ return { total: rows.length, rows };
12
+ }
13
+ // code is unique
14
+ const rows = await pg
15
+ .query("select id, code, name, module, description, source, editable, system from admin.dictionaries where $1 in (code, id) limit 1", [code])
16
+ .then((r) => r.rows || []);
17
+ if (!rows.length) {
18
+ throw NotFoundError("dictionary not found");
19
+ }
20
+ const items = await pg
21
+ .query("select code, name, description, color, icon, sort_order as sort, parent_id, active, system, metadata from admin.dictionary_items where dictionary_id=$1", [rows[0].id])
22
+ .then((r) => r.rows || []);
23
+ if (values) {
24
+ return items;
25
+ }
26
+ return { ...rows[0], values: items };
27
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ *
3
+ * @param {String} id Dictionary ID
4
+ */
5
+ export default function updateDictionary({ id, body, uid, }: {
6
+ id: string;
7
+ body: Record<string, any>;
8
+ uid: string;
9
+ }, pg?: any): Promise<any>;
10
+ //# sourceMappingURL=update.dictionary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.dictionary.d.ts","sourceRoot":"","sources":["../../../../../server/routes/dictionaries/functions/update.dictionary.ts"],"names":[],"mappings":"AAIA;;;GAGG;AAEH,wBAA8B,gBAAgB,CAC5C,EACE,EAAE,EACF,IAAI,EACJ,GAAG,GACJ,EAAE;IACD,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;CACb,EACD,EAAE,MAAmB,gBAyDtB"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ *
3
+ * @param {String} id Item ID
4
+ * @param {String} code Dictionary code (filename)
5
+ * @param {String} body.code Item code
6
+ */
7
+ export default function updateDictionaryItem({ id, code, body, uid, }: {
8
+ id: string;
9
+ code: string;
10
+ body: Record<string, any>;
11
+ uid: string;
12
+ }, pg?: any): Promise<any>;
13
+ //# sourceMappingURL=update.dictionary.item.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.dictionary.item.d.ts","sourceRoot":"","sources":["../../../../../server/routes/dictionaries/functions/update.dictionary.item.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AAEH,wBAA8B,oBAAoB,CAChD,EACE,EAAE,EACF,IAAI,EACJ,IAAI,EACJ,GAAG,GACJ,EAAE;IACD,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;CACb,EACD,EAAE,MAAmB,gBAiDtB"}
@@ -0,0 +1,48 @@
1
+ import pgClients from "../../../plugins/pg/pgClients.js";
2
+ import dataUpdate from "../../../plugins/crud/funcs/dataUpdate.js";
3
+ import updateDictionary from "./update.dictionary.js";
4
+ import { BadRequestError, NotFoundError } from "../../../../errors.js";
5
+ /**
6
+ *
7
+ * @param {String} id Item ID
8
+ * @param {String} code Dictionary code (filename)
9
+ * @param {String} body.code Item code
10
+ */
11
+ export default async function updateDictionaryItem({ id, code, body, uid, }, pg = pgClients.client) {
12
+ if (!pg) {
13
+ throw new Error("empty pg");
14
+ }
15
+ if (!code) {
16
+ throw BadRequestError("not enough params: code");
17
+ }
18
+ if (!body) {
19
+ throw BadRequestError("not enough params: body");
20
+ }
21
+ const { system, id: dictionaryId } = await pg
22
+ .query("select id from admin.dictionaries where $1 in (id,code)", [code])
23
+ .then((r) => ({ system: r.rows?.[0]?.system, id: r.rows?.[0]?.id }));
24
+ if (!dictionaryId) {
25
+ throw NotFoundError("dictionary not found");
26
+ }
27
+ const itemId = await pg
28
+ .query("select id from admin.dictionary_items where $1 in (id,code)", [id])
29
+ .then((r) => r.rows?.[0]?.id);
30
+ if (!itemId) {
31
+ throw NotFoundError("dictionary item not found");
32
+ }
33
+ // make custom
34
+ if (system) {
35
+ await updateDictionary({ id: dictionaryId, body: { system: false }, uid }, pg);
36
+ }
37
+ const row = await dataUpdate({
38
+ id: itemId,
39
+ table: "admin.dictionary_items",
40
+ data: {
41
+ ...body,
42
+ sort_order: body.sort,
43
+ },
44
+ pg,
45
+ uid,
46
+ });
47
+ return row;
48
+ }
@@ -0,0 +1,51 @@
1
+ import pgClients from "../../../plugins/pg/pgClients.js";
2
+ import dataInsert from "../../../plugins/crud/funcs/dataInsert.js";
3
+ import dataUpdate from "../../../plugins/crud/funcs/dataUpdate.js";
4
+ /**
5
+ *
6
+ * @param {String} id Dictionary ID
7
+ */
8
+ export default async function updateDictionary({ id, body, uid, }, pg = pgClients.client) {
9
+ if (!pg) {
10
+ throw new Error("empty pg");
11
+ }
12
+ if (!id) {
13
+ throw new Error("not enough params: id");
14
+ }
15
+ if (!body) {
16
+ throw new Error("not enough params: body");
17
+ }
18
+ const row = await dataUpdate({
19
+ id,
20
+ table: "admin.dictionaries",
21
+ data: body,
22
+ pg,
23
+ uid,
24
+ });
25
+ if (body.values?.length) {
26
+ const client = await pg.connect();
27
+ try {
28
+ await client.query("begin");
29
+ await client.query("delete from admin.dictionary_items where dictionary_id = $1", [id]);
30
+ const values = await Promise.all(body.values.map(async (item) => dataInsert({
31
+ table: "admin.dictionary_items",
32
+ data: {
33
+ ...item,
34
+ dictionary_id: id,
35
+ },
36
+ pg: client,
37
+ uid,
38
+ }).then((r) => r.data)));
39
+ await client.query("commit");
40
+ return { ...row, values };
41
+ }
42
+ catch (err) {
43
+ await client.query("rollback");
44
+ throw err;
45
+ }
46
+ finally {
47
+ client.release();
48
+ }
49
+ }
50
+ return row;
51
+ }
@@ -3,13 +3,13 @@ const resizeSchema = {
3
3
  type: "object",
4
4
  properties: {
5
5
  filepath: { type: "string" },
6
- quality: { type: "number", exclusiveMinimum: 0, maximum: 100 },
6
+ quality: { type: "integer", exclusiveMinimum: 0, maximum: 100 },
7
7
  size: {
8
8
  type: "string",
9
9
  pattern: "^((\\d{1,4})x(\\d{1,4})|(\\d{1,4})x|x(\\d{1,4}))$",
10
10
  },
11
- w: { type: "number", minimum: 1, maximum: 2048 },
12
- h: { type: "number", minimum: 1, maximum: 2048 },
11
+ w: { type: "integer", minimum: 1, maximum: 2048 },
12
+ h: { type: "integer", minimum: 1, maximum: 2048 },
13
13
  },
14
14
  },
15
15
  };
@@ -17,9 +17,9 @@ const exportSchema = {
17
17
  querystring: {
18
18
  type: "object",
19
19
  properties: {
20
- limit: { type: "number", minimum: 1 },
21
- batchLimit: { type: "number", minimum: 1 },
22
- page: { type: "number", minimum: 1 },
20
+ limit: { type: "integer", minimum: 1 },
21
+ batchLimit: { type: "integer", minimum: 1 },
22
+ page: { type: "integer", minimum: 1 },
23
23
  key: { type: "string", pattern: "^([\\d\\w_.-]+)$" },
24
24
  },
25
25
  },
@@ -1,6 +1,6 @@
1
1
  import type { FastifyReply } from "fastify";
2
2
  import type { ExtendedPG } from "../../../types/core.js";
3
- export default function dataAPI({ pg, params, table, id, headers, query, user, contextQuery, searchColumn, sufix, filterList, actions: actionsParam, accessQuery: accessQueryParam, columns: columnsParam, isExport, }: {
3
+ export default function dataAPI({ pg, params, table, id, headers, query, user, contextQuery, searchColumn, sufix, filterList, actions: actionsParam, accessQuery: accessQueryParam, columns: columnsParam, isExport, called: isCalled, }: {
4
4
  pg?: ExtendedPG;
5
5
  params?: {
6
6
  id?: string;
@@ -20,5 +20,6 @@ export default function dataAPI({ pg, params, table, id, headers, query, user, c
20
20
  accessQuery?: string;
21
21
  columns?: string[];
22
22
  isExport?: boolean;
23
- }, reply?: FastifyReply, called?: any): Promise<any>;
23
+ called?: boolean;
24
+ }, _?: FastifyReply, called1?: any): Promise<any>;
24
25
  //# sourceMappingURL=getData.d.ts.map
@@ -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;AAuGzD,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,gBAk5Bb"}
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;AAuFzD,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,EAChB,MAAM,EAAE,QAAQ,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;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,EACD,CAAC,CAAC,EAAE,YAAY,EAChB,OAAO,CAAC,EAAE,GAAG,gBAo5Bd"}
@@ -25,19 +25,6 @@ const components = {
25
25
  "vs-widget-file": "select 'vs-widget-file' as component, count(*) from crm.files where entity_id=$1 and file_status<>3",
26
26
  "vs-widget-comments": "select 'vs-widget-comments' as component, count(*) from crm.communications where entity_id=$1",
27
27
  };
28
- const mockReply = {
29
- response: {},
30
- // redirect: (txt) => txt,
31
- redirect: (txt) => Object.assign(mockReply.response, {
32
- body: txt,
33
- statusCode: mockReply.response.statusCode || 200,
34
- }),
35
- status: (statusCode) => {
36
- Object.assign(mockReply.response, { status: statusCode });
37
- return mockReply;
38
- },
39
- send: (txt) => Object.assign(mockReply.response, txt),
40
- };
41
28
  function getOrder({ queryOrder, queryDesc, defaultOrder, columnList, cols, sqlColumns, iscalled = false, }) {
42
29
  if (iscalled && queryOrder) {
43
30
  return `order by ${queryOrder}`;
@@ -59,7 +46,8 @@ function getOrder({ queryOrder, queryDesc, defaultOrder, columnList, cols, sqlCo
59
46
  const checkInline = {};
60
47
  const maxLimit = 100;
61
48
  const defaultLimit = 20;
62
- export default async function dataAPI({ pg = pgClients.client, params, table, id, headers = {}, query = {}, user = {}, contextQuery, searchColumn, sufix = true, filterList, actions: actionsParam, accessQuery: accessQueryParam, columns: columnsParam, isExport = false, }, reply, called) {
49
+ export default async function dataAPI({ pg = pgClients.client, params, table, id, headers = {}, query = {}, user = {}, contextQuery, searchColumn, sufix = true, filterList, actions: actionsParam, accessQuery: accessQueryParam, columns: columnsParam, isExport = false, called: isCalled, }, _, called1) {
50
+ const called = called1 || isCalled;
63
51
  const time = Date.now();
64
52
  const timeArr = [Date.now()];
65
53
  const { uid } = user;
@@ -134,7 +134,7 @@ declare const searchSchema: {
134
134
  };
135
135
  sql: {
136
136
  type: string;
137
- pattern: string;
137
+ enum: number[];
138
138
  };
139
139
  };
140
140
  };
@@ -170,14 +170,15 @@ declare const suggestSchema: {
170
170
  };
171
171
  sql: {
172
172
  type: string;
173
+ enum: number[];
173
174
  };
174
175
  count: {
175
176
  type: string;
177
+ enum: number[];
176
178
  };
177
179
  json: {
178
180
  type: string;
179
- minimum: number;
180
- maximum: number;
181
+ enum: number[];
181
182
  };
182
183
  };
183
184
  };
@@ -223,7 +224,7 @@ declare const cardTabDataSchema: {
223
224
  properties: {
224
225
  sql: {
225
226
  type: string;
226
- pattern: string;
227
+ enum: number[];
227
228
  };
228
229
  };
229
230
  };
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../server/routes/table/schema.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyBpB,CAAC;AAEF,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BhB,CAAC;AAEF,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAajB,CAAC;AAEF,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsBlB,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"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../server/routes/table/schema.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyBpB,CAAC;AAEF,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BhB,CAAC;AAEF,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAajB,CAAC;AAEF,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsBlB,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"}
@@ -2,8 +2,8 @@ const tableDataSchema = {
2
2
  type: "object",
3
3
  properties: {
4
4
  querystring: {
5
- limit: { type: "number", minimum: 1 },
6
- page: { type: "number", minimum: 1 },
5
+ limit: { type: "integer", minimum: 1 },
6
+ page: { type: "integer", minimum: 1 },
7
7
  // filter: { type: 'string', pattern: '^([\\w\\d_-]+)=([А-Яа-яҐґЄєІіЇї\\d\\w\\s\\/\\[\\]\\(\\)\\{\\}\\|,.!?;:—_=-@%#$&^*+=`~]+)$' },
8
8
  // search: { type: 'string', pattern: '^([А-Яа-яҐґЄєІіЇї\\d\\w\\s\\/\\[\\]\\(\\)\\{\\}\\|,.!?;:—_=-@%#$&^*+=`~]+)$' },
9
9
  order: { type: "string", pattern: "^([\\d\\w_.-]+)$" },
@@ -13,7 +13,7 @@ const tableDataSchema = {
13
13
  bbox: { type: "string", pattern: "^([\\d\\s,.-]+)$" },
14
14
  polyline: { type: "string", pattern: "^([\\d\\w|@{}~_`]+)$" },
15
15
  // key: { type: 'string', pattern: '^([\\d\\w_]+)$' },
16
- sql: { type: "number" },
16
+ sql: { type: "integer" },
17
17
  },
18
18
  },
19
19
  params: {
@@ -28,8 +28,8 @@ const tableSchema = {
28
28
  querystring: {
29
29
  type: "object",
30
30
  properties: {
31
- limit: { type: "number", minimum: 1 },
32
- page: { type: "number", minimum: 1 },
31
+ limit: { type: "integer", minimum: 1 },
32
+ page: { type: "integer", minimum: 1 },
33
33
  // filter: { type: 'string', pattern: '^([\\w\\d_-]+)=([А-Яа-яҐґЄєІіЇї\\d\\w\\s\\/\\[\\]\\(\\)\\{\\}\\|,.!?;:—_=-@%#$&^*+=`~]+)$' },
34
34
  // search: { type: 'string', pattern: '^([А-Яа-яҐґЄєІіЇї\\d\\w\\s\\/\\[\\]\\(\\)\\{\\}\\|,.!?;:—_=-@%#$&^*+=`~]+)$' },
35
35
  order: { type: "string", pattern: "^$|^[\\d\\w_.-]+$" },
@@ -40,7 +40,7 @@ const tableSchema = {
40
40
  // polyline: { type: 'string', pattern: '^([\\d\\w\\|@\\/\\{\\}~_`]+)$' },
41
41
  key: { type: "string", pattern: "^([А-Яа-яҐґЄєІіЇї\\d\\w\\s_.-]+)$" },
42
42
  uid: { type: "string", pattern: "^([\\d\\w_.-]+)$" },
43
- sql: { type: "number" },
43
+ sql: { type: "integer" },
44
44
  },
45
45
  },
46
46
  params: {
@@ -55,13 +55,13 @@ const searchSchema = {
55
55
  querystring: {
56
56
  type: "object",
57
57
  properties: {
58
- page: { type: "number", minimum: 1 },
59
- limit: { type: "number", minimum: 1 },
58
+ page: { type: "integer", minimum: 1 },
59
+ limit: { type: "integer", minimum: 1 },
60
60
  order: { type: "string", pattern: "^([\\d\\w_.-]+)$" },
61
61
  desc: { type: "string", pattern: "^(\\d+)$" },
62
62
  key: { type: "string", pattern: "^([А-Яа-яҐґЄєІіЇї\\d\\w\\s_.-]+)$" },
63
63
  table: { type: "string", pattern: "^([\\d\\w_.-]+)$" },
64
- sql: { type: "string", pattern: "^(\\d)$" },
64
+ sql: { type: "integer", enum: [1] },
65
65
  },
66
66
  },
67
67
  };
@@ -76,9 +76,9 @@ const suggestSchema = {
76
76
  name: { type: "string", pattern: "^([\\d\\w_.-]+)$" },
77
77
  key: { type: "string", pattern: "^([А-Яа-яҐґЄєІіЇї\\d\\w\\s_.-]+)$" },
78
78
  val: { type: "string", pattern: "([\\d\\w]+)$" },
79
- sql: { type: "number" },
80
- count: { type: "number" },
81
- json: { type: "number", minimum: 1, maximum: 1 }, // dummy schema param to avoid crash caused by frontend calls w/ useless json param
79
+ sql: { type: "integer", enum: [1] },
80
+ count: { type: "integer", enum: [1] },
81
+ json: { type: "integer", enum: [1] }, // dummy schema param to avoid crash caused by frontend calls w/ useless json param
82
82
  },
83
83
  },
84
84
  params: {
@@ -109,7 +109,7 @@ const cardTabDataSchema = {
109
109
  querystring: {
110
110
  type: "object",
111
111
  properties: {
112
- sql: { type: "string", pattern: "^(\\d)$" },
112
+ sql: { type: "integer", enum: [1] },
113
113
  },
114
114
  },
115
115
  params: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.5.43",
3
+ "version": "2.5.46",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [