@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.
@@ -1,2 +1,2 @@
1
- export default function getRangeQuery(value: any, name: string, fieldType: string | undefined, filterType: string, sql: string, extra?: Record<string, string>, pk?: string): string;
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":"AAkHA,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,EAAE,MAAM,EACX,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,EAAE,CAAC,EAAE,MAAM,UAwFZ"}
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
- if (["min", "max"].includes(dateStr))
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?.indexOf("-") !== -1) {
24
- const [yyyy, mm, dd] = dateStr.split("-");
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}/${dd}/${yyyy}`).toString() !== "Invalid Date";
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 getRangeValues(value = "", filterType = "range") {
49
- if (["range"].includes(filterType)) {
50
- if (value?.includes(","))
51
- return value.split(",").map((el) => el || "min");
52
- if (value?.includes("_"))
53
- return value.split("_");
54
- return value.split("-");
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 [dt(dp.y, dp.m, dp.d)];
59
- }
60
- if (value === "cw") {
61
- return [dt(dp.y, dp.m, dp.w), dt(dp.y, dp.m, dp.w + 6)];
62
- }
63
- if (value === "cm") {
64
- return [dt(dp.y, dp.m, 1), dt(dp.y, dp.m + 1, 0)];
65
- }
66
- if (value === "cq") {
67
- return [dt(dp.y, dp.q, 1), dt(dp.y, dp.q + 3, 0)];
68
- }
69
- if (value === "cy") {
70
- return [dt(dp.y, 0, 1), dt(dp.y, 11, 31)];
71
- }
72
- // date range, example: 01.01.2024-31.12.2024
73
- const [startDate, endDate = "max"] = value?.includes(",")
74
- ? value.split(",").map((el) => el || "min")
75
- : value.split("-");
76
- const min = startDate === "min" ? startDate : formatDateISOString(startDate);
77
- const max = endDate === "max" ? endDate : formatDateISOString(endDate);
78
- return [min, max];
79
- }
80
- function checkValid(value, fieldType, filterType, sql, extra) {
81
- const [min, max = "max"] = getRangeValues(value, filterType);
82
- if (["date", "datepicker"].includes(filterType)) {
83
- const isvalid = (dateTypeList.includes(fieldType) || sql || extra) &&
84
- isValidDate(min) &&
85
- (isValidDate(max) || value === "cd");
86
- return { min, max, isvalid };
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
- if (["range"].includes(filterType)) {
89
- const isvalid = (numberTypeList.includes(fieldType) || sql || extra) &&
90
- isValidNumber(min) &&
91
- isValidNumber(max);
92
- return { min, max, isvalid };
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,gBAiZpB"}
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"}
@@ -111,6 +111,7 @@ export default async function exportTable({ pg = pgClients.client, headers, user
111
111
  headers,
112
112
  user,
113
113
  sufix: false,
114
+ isExport: true,
114
115
  };
115
116
  // check total count, debug sql etc.
116
117
  const result = tableSql || viewSql
@@ -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,GACtB,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;CACpB,EACD,MAAM,CAAC,EAAE,YAAY,EACrB,MAAM,CAAC,EAAE,GAAG,gBAk1Bb"}
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 && !el.inline && el?.sql?.replace)
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.0.140",
3
+ "version": "2.0.142",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [