dbgate-filterparser 7.0.6 → 7.1.0

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 (2) hide show
  1. package/lib/filterTool.js +35 -1
  2. package/package.json +3 -3
package/lib/filterTool.js CHANGED
@@ -19,8 +19,42 @@ function getFilterValueExpression(value, dataType) {
19
19
  var _a;
20
20
  if (value == null)
21
21
  return 'NULL';
22
- if ((0, dbgate_tools_1.isTypeDateTime)(dataType))
22
+ if ((0, dbgate_tools_1.isTypeDateTime)(dataType)) {
23
+ // Check for year as number (GROUP:YEAR)
24
+ if (typeof value === 'number' && Number.isInteger(value) && value >= 1000 && value <= 9999) {
25
+ return value.toString();
26
+ }
27
+ if ((0, isString_1.default)(value)) {
28
+ // Year only
29
+ if (/^\d{4}$/.test(value)) {
30
+ return value;
31
+ }
32
+ // Year-month: validate month is in range 01-12
33
+ const yearMonthMatch = value.match(/^(\d{4})-(\d{1,2})$/);
34
+ if (yearMonthMatch) {
35
+ const month = parseInt(yearMonthMatch[2], 10);
36
+ if (month >= 1 && month <= 12) {
37
+ return value;
38
+ }
39
+ }
40
+ // Year-month-day: validate month and day
41
+ const yearMonthDayMatch = value.match(/^(\d{4})-(\d{1,2})-(\d{1,2})$/);
42
+ if (yearMonthDayMatch) {
43
+ const month = parseInt(yearMonthDayMatch[2], 10);
44
+ const day = parseInt(yearMonthDayMatch[3], 10);
45
+ // Quick validation: month 1-12, day 1-31
46
+ if (month >= 1 && month <= 12 && day >= 1 && day <= 31) {
47
+ // Construct a date to verify it's actually valid (e.g., reject 2024-02-30)
48
+ const dateStr = `${yearMonthDayMatch[1]}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
49
+ const date = (0, date_fns_1.toDate)(dateStr);
50
+ if (!isNaN(date.getTime())) {
51
+ return value;
52
+ }
53
+ }
54
+ }
55
+ }
23
56
  return (0, date_fns_1.format)((0, date_fns_1.toDate)(getDateStringWithoutTimeZone(value)), 'yyyy-MM-dd HH:mm:ss');
57
+ }
24
58
  if (value === true)
25
59
  return 'TRUE';
26
60
  if (value === false)
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "7.0.6",
2
+ "version": "7.1.0",
3
3
  "name": "dbgate-filterparser",
4
4
  "main": "lib/index.js",
5
5
  "typings": "lib/index.d.ts",
@@ -17,7 +17,7 @@
17
17
  "lib"
18
18
  ],
19
19
  "devDependencies": {
20
- "dbgate-types": "^7.0.6",
20
+ "dbgate-types": "^7.1.0",
21
21
  "@types/jest": "^25.1.4",
22
22
  "@types/node": "^13.7.0",
23
23
  "jest": "^28.1.3",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@types/parsimmon": "^1.10.1",
29
- "dbgate-tools": "^7.0.6",
29
+ "dbgate-tools": "^7.1.0",
30
30
  "lodash": "^4.17.21",
31
31
  "date-fns": "^4.1.0",
32
32
  "moment": "^2.24.0",