@opengis/fastify-table 2.0.140 → 2.0.142
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/table/funcs/getFilterSQL/util/getRangeQuery.d.ts +1 -1
- package/dist/server/plugins/table/funcs/getFilterSQL/util/getRangeQuery.d.ts.map +1 -1
- package/dist/server/plugins/table/funcs/getFilterSQL/util/getRangeQuery.js +126 -49
- package/dist/server/routes/file/controllers/export.d.ts.map +1 -1
- package/dist/server/routes/file/controllers/export.js +1 -0
- package/dist/server/routes/table/functions/getData.d.ts +2 -1
- package/dist/server/routes/table/functions/getData.d.ts.map +1 -1
- package/dist/server/routes/table/functions/getData.js +7 -4
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export default function getRangeQuery(value: any, name: string, fieldType: string | undefined, filterType: string, sql
|
|
1
|
+
export default function getRangeQuery(value: any, name: string, fieldType: string | undefined, filterType: string, sql?: string, extra?: Record<string, string>, pk?: string): string;
|
|
2
2
|
//# sourceMappingURL=getRangeQuery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRangeQuery.d.ts","sourceRoot":"","sources":["../../../../../../../server/plugins/table/funcs/getFilterSQL/util/getRangeQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getRangeQuery.d.ts","sourceRoot":"","sources":["../../../../../../../server/plugins/table/funcs/getFilterSQL/util/getRangeQuery.ts"],"names":[],"mappings":"AA4NA,MAAM,CAAC,OAAO,UAAU,aAAa,CACnC,KAAK,EAAE,GAAG,EACV,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,UAAU,EAAE,MAAM,EAClB,GAAG,CAAC,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,EAAE,CAAC,EAAE,MAAM,UA0FZ"}
|
|
@@ -15,18 +15,19 @@ const numberTypeList = [
|
|
|
15
15
|
"bigint",
|
|
16
16
|
];
|
|
17
17
|
const isValidDate = (dateStr) => {
|
|
18
|
-
if (!dateStr)
|
|
18
|
+
if (!dateStr) {
|
|
19
19
|
return false;
|
|
20
|
-
|
|
20
|
+
}
|
|
21
|
+
if (["min", "max", "cd", "cw", "cm", "cq", "cy"].includes(dateStr)) {
|
|
21
22
|
return true;
|
|
23
|
+
}
|
|
22
24
|
// iso date: 2024-01-01
|
|
23
|
-
if (dateStr
|
|
24
|
-
|
|
25
|
-
return new Date(`${mm}/${dd}/${yyyy}`).toString() !== "Invalid Date";
|
|
25
|
+
if (dateStr.includes("-")) {
|
|
26
|
+
return new Date(dateStr).toString() !== "Invalid Date";
|
|
26
27
|
}
|
|
27
28
|
// locale date: 01.01.2024
|
|
28
29
|
const [dd, mm, yyyy] = dateStr.split(".");
|
|
29
|
-
return new Date(`${mm}
|
|
30
|
+
return new Date(`${yyyy}-${mm}-${dd}`).toString() !== "Invalid Date";
|
|
30
31
|
};
|
|
31
32
|
const isValidNumber = (numStr) => ["min", "max"].includes(numStr) ? true : !isNaN(numStr);
|
|
32
33
|
function dt(y, m, d) {
|
|
@@ -45,58 +46,134 @@ function formatDateISOString(date) {
|
|
|
45
46
|
const [day, month, year] = date.split(".");
|
|
46
47
|
return `${year}-${month}-${day}`;
|
|
47
48
|
}
|
|
48
|
-
function
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return
|
|
49
|
+
function checkValid(value, fieldType, filterType, sql, extra) {
|
|
50
|
+
const sep = (value.includes(",") ? "," : null) ||
|
|
51
|
+
(value.includes("_") ? "_" : null) ||
|
|
52
|
+
(value.includes("-") ? "-" : null);
|
|
53
|
+
// number range w/o valid separator => skip invalid filter
|
|
54
|
+
if (filterType === "range" && !sep) {
|
|
55
|
+
return { isvalid: false };
|
|
55
56
|
}
|
|
56
57
|
// date range, specific options: current day, week, month, year etc.
|
|
57
|
-
if (value === "cd") {
|
|
58
|
-
return
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return {
|
|
58
|
+
if (["date", "datepicker"].includes(filterType) && value === "cd") {
|
|
59
|
+
return {
|
|
60
|
+
min: dt(dp.y, dp.m, dp.d),
|
|
61
|
+
max: dt(dp.y, dp.m, dp.d),
|
|
62
|
+
isvalid: true,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (["date", "datepicker"].includes(filterType) && value === "cw") {
|
|
66
|
+
return {
|
|
67
|
+
min: dt(dp.y, dp.m, dp.w),
|
|
68
|
+
max: dt(dp.y, dp.m, dp.w + 6),
|
|
69
|
+
isvalid: true,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (["date", "datepicker"].includes(filterType) && value === "cm") {
|
|
73
|
+
return {
|
|
74
|
+
min: dt(dp.y, dp.m, 1),
|
|
75
|
+
max: dt(dp.y, dp.m + 1, 0),
|
|
76
|
+
isvalid: true,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
if (["date", "datepicker"].includes(filterType) && value === "cq") {
|
|
80
|
+
return {
|
|
81
|
+
min: dt(dp.y, dp.q, 1),
|
|
82
|
+
max: dt(dp.y, dp.q + 3, 0),
|
|
83
|
+
isvalid: true,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (["date", "datepicker"].includes(filterType) && value === "cy") {
|
|
87
|
+
return {
|
|
88
|
+
min: dt(dp.y, 0, 1),
|
|
89
|
+
max: dt(dp.y, 11, 31),
|
|
90
|
+
isvalid: true,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
// specific period from now - days, months, years
|
|
94
|
+
if (["date", "datepicker"].includes(filterType) &&
|
|
95
|
+
value.match(/^(?<val>[1-9]\d*)(?<unit>d|m|y)$/)?.groups?.unit) {
|
|
96
|
+
const { val, unit } = value.match(/^(?<val>[1-9]\d*)(?<unit>d|m|y)$/)?.groups || {};
|
|
97
|
+
const min = (unit === "d" ? dt(dp.y, dp.m, dp.d - +val) : null) ||
|
|
98
|
+
(unit === "m" ? dt(dp.y, dp.m - +val, dp.d) : null) ||
|
|
99
|
+
(unit === "y" ? dt(dp.y - +val, dp.m, dp.d) : null);
|
|
100
|
+
return {
|
|
101
|
+
min,
|
|
102
|
+
max: dt(dp.y, dp.m, dp.d),
|
|
103
|
+
isvalid: isValidDate(min),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
// specific quarter - before skip date value validation
|
|
107
|
+
if (["date", "datepicker"].includes(filterType) &&
|
|
108
|
+
value.match(/^(?<year>\d{4})-q(?<quarter>[1-4])$/)?.groups?.quarter) {
|
|
109
|
+
const { year, quarter } = value.match(/^(?<year>\d{4})-q(?<quarter>[1-4])$/)?.groups || {};
|
|
110
|
+
const startMonth = +quarter * 3;
|
|
111
|
+
return {
|
|
112
|
+
min: dt(year, startMonth - 3, 1),
|
|
113
|
+
max: dt(year, startMonth, 0),
|
|
114
|
+
isvalid: true,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
// date value validation
|
|
118
|
+
if (["date", "datepicker"].includes(filterType) &&
|
|
119
|
+
!sep &&
|
|
120
|
+
!isValidDate(value)) {
|
|
121
|
+
return { isvalid: false };
|
|
87
122
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
123
|
+
// specific date / day
|
|
124
|
+
if (["date", "datepicker"].includes(filterType) &&
|
|
125
|
+
value.match(/^\d{4}-\d{2}-\d{2}$/)?.[0]) {
|
|
126
|
+
return {
|
|
127
|
+
min: new Date(value).toISOString().split("T")[0],
|
|
128
|
+
max: new Date(value).toISOString().split("T")[0],
|
|
129
|
+
isvalid: true,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
// specific month
|
|
133
|
+
if (["date", "datepicker"].includes(filterType) &&
|
|
134
|
+
value.match(/^\d{4}-\d{2}$/)?.[0]) {
|
|
135
|
+
return {
|
|
136
|
+
min: new Date(value).toISOString().split("T")[0],
|
|
137
|
+
max: dt(new Date(value).getFullYear(), new Date(value).getMonth() + 1, 0),
|
|
138
|
+
isvalid: true,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
// specific year
|
|
142
|
+
if (["date", "datepicker"].includes(filterType) &&
|
|
143
|
+
value.match(/^\d{4}$/)?.[0]) {
|
|
144
|
+
return {
|
|
145
|
+
min: dt(value, 0, 1),
|
|
146
|
+
max: dt(value, 11, 31),
|
|
147
|
+
isvalid: true,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (sep) {
|
|
151
|
+
const [minValue = "min", maxValue = "max"] = value.split(sep);
|
|
152
|
+
// range for numbers
|
|
153
|
+
if (filterType === "range" && fieldType) {
|
|
154
|
+
const isvalid = (numberTypeList.includes(fieldType) || sql || extra) &&
|
|
155
|
+
isValidNumber(minValue) &&
|
|
156
|
+
isValidNumber(maxValue);
|
|
157
|
+
return { min: minValue, max: maxValue, isvalid };
|
|
158
|
+
}
|
|
159
|
+
// date range, example: 01.01.2024-31.12.2024
|
|
160
|
+
if (["date", "datepicker"].includes(filterType)) {
|
|
161
|
+
const min = minValue === "min" ? minValue : formatDateISOString(minValue);
|
|
162
|
+
const max = maxValue === "max" ? maxValue : formatDateISOString(maxValue);
|
|
163
|
+
const isvalid = fieldType &&
|
|
164
|
+
(dateTypeList.includes(fieldType) || sql || extra) &&
|
|
165
|
+
isValidDate(min) &&
|
|
166
|
+
isValidDate(max);
|
|
167
|
+
return { min, max, isvalid };
|
|
168
|
+
}
|
|
93
169
|
}
|
|
94
170
|
return { isvalid: false };
|
|
95
171
|
}
|
|
96
172
|
export default function getRangeQuery(value, name, fieldType, filterType, sql, extra, pk) {
|
|
97
173
|
const { min, max, isvalid } = checkValid(value, fieldType, filterType, sql, extra);
|
|
98
|
-
if (!isvalid)
|
|
174
|
+
if (!isvalid) {
|
|
99
175
|
return "false";
|
|
176
|
+
}
|
|
100
177
|
// with sql subquery
|
|
101
178
|
if (["date", "datepicker"].includes(filterType) && sql) {
|
|
102
179
|
return sql
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/export.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAgCzD;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,wBAA8B,WAAW,CACvC,EACE,EAAqB,EACrB,OAAO,EACP,IAAI,EACJ,OAAO,EAAE,QAAQ,EACjB,GAAG,EACH,KAAU,EACV,IAAkB,EAClB,QAAQ,EACR,UAAU,GACX,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,EACD,KAAK,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/export.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAgCzD;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,wBAA8B,WAAW,CACvC,EACE,EAAqB,EACrB,OAAO,EACP,IAAI,EACJ,OAAO,EAAE,QAAQ,EACjB,GAAG,EACH,KAAU,EACV,IAAkB,EAClB,QAAQ,EACR,UAAU,GACX,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,EACD,KAAK,EAAE,YAAY,gBAkZpB"}
|
|
@@ -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, sufix, filterList, actions: actionsParam, accessQuery: accessQueryParam, columns: columnsParam, }: {
|
|
3
|
+
export default function dataAPI({ pg, params, table, id, headers, query, user, contextQuery, sufix, filterList, actions: actionsParam, accessQuery: accessQueryParam, columns: columnsParam, isExport, }: {
|
|
4
4
|
pg?: ExtendedPG;
|
|
5
5
|
params?: {
|
|
6
6
|
id?: string;
|
|
@@ -18,5 +18,6 @@ export default function dataAPI({ pg, params, table, id, headers, query, user, c
|
|
|
18
18
|
actions?: string[];
|
|
19
19
|
accessQuery?: string;
|
|
20
20
|
columns?: string[];
|
|
21
|
+
isExport?: boolean;
|
|
21
22
|
}, reply1?: FastifyReply, called?: any): Promise<any>;
|
|
22
23
|
//# 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;AA4EzD,wBAA8B,OAAO,CACnC,EACE,EAAqB,EACrB,MAAM,EACN,KAAK,EACL,EAAE,EACF,OAAY,EACZ,KAAU,EACV,IAAS,EACT,YAAY,EACZ,KAAY,EACZ,UAAU,EACV,OAAO,EAAE,YAAY,EACrB,WAAW,EAAE,gBAAgB,EAC7B,OAAO,EAAE,YAAY,
|
|
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;AA4EzD,wBAA8B,OAAO,CACnC,EACE,EAAqB,EACrB,MAAM,EACN,KAAK,EACL,EAAE,EACF,OAAY,EACZ,KAAU,EACV,IAAS,EACT,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,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,MAAM,CAAC,EAAE,YAAY,EACrB,MAAM,CAAC,EAAE,GAAG,gBAw1Bb"}
|
|
@@ -52,7 +52,7 @@ function getOrder(queryOrder, queryDesc, defaultOrder, columnList, iscalled = fa
|
|
|
52
52
|
const checkInline = {};
|
|
53
53
|
const maxLimit = 100;
|
|
54
54
|
const defaultLimit = 20;
|
|
55
|
-
export default async function dataAPI({ pg = pgClients.client, params, table, id, headers = {}, query = {}, user = {}, contextQuery, sufix = true, filterList, actions: actionsParam, accessQuery: accessQueryParam, columns: columnsParam, }, reply1, called) {
|
|
55
|
+
export default async function dataAPI({ pg = pgClients.client, params, table, id, headers = {}, query = {}, user = {}, contextQuery, sufix = true, filterList, actions: actionsParam, accessQuery: accessQueryParam, columns: columnsParam, isExport = false, }, reply1, called) {
|
|
56
56
|
const time = Date.now();
|
|
57
57
|
const timeArr = [Date.now()];
|
|
58
58
|
const { uid } = user;
|
|
@@ -193,7 +193,10 @@ export default async function dataAPI({ pg = pgClients.client, params, table, id
|
|
|
193
193
|
}
|
|
194
194
|
const columnList = dbColumns.map((el) => el.name || el).join(",");
|
|
195
195
|
const sqlTable = sql
|
|
196
|
-
?.filter?.((el) => !el?.disabled &&
|
|
196
|
+
?.filter?.((el) => !el?.disabled &&
|
|
197
|
+
!el.inline &&
|
|
198
|
+
el?.sql?.replace &&
|
|
199
|
+
!(isExport && el.export === false))
|
|
197
200
|
.map((el, i) => ` left join lateral (${el.sql.replace("{{uid}}", uid)}) ${el.name || `t${i}`} on 1=1 `)
|
|
198
201
|
?.join("") || "";
|
|
199
202
|
const cardSqlFiltered = objectId
|
|
@@ -205,7 +208,7 @@ export default async function dataAPI({ pg = pgClients.client, params, table, id
|
|
|
205
208
|
.join("\n") || ""
|
|
206
209
|
: "";
|
|
207
210
|
const sqlInline = loadTable?.sql
|
|
208
|
-
?.filter?.((el) => el.inline)
|
|
211
|
+
?.filter?.((el) => el.inline && !(isExport && el.export === false))
|
|
209
212
|
?.map((el) => `,(${el.sql})`)
|
|
210
213
|
?.join("") || "";
|
|
211
214
|
const { fields = [] } = !viewSql
|
|
@@ -326,7 +329,7 @@ export default async function dataAPI({ pg = pgClients.client, params, table, id
|
|
|
326
329
|
.join(",")}`
|
|
327
330
|
: ""}
|
|
328
331
|
from (select * ${sql
|
|
329
|
-
?.filter((el) => el.inline)
|
|
332
|
+
?.filter((el) => el.inline && !(isExport && el.export === false))
|
|
330
333
|
.map((el) => `,(${el.sql})`)
|
|
331
334
|
.join("") || ""} from ${viewSql ? `(${viewSql})` : table1} t ${sqlTable} ) t
|
|
332
335
|
|