@fibery/expression-utils 1.1.19 → 1.1.20

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.
@@ -90,11 +90,26 @@ const mapDynamicParams = (params, onDynamicParam) => {
90
90
  }
91
91
  }));
92
92
  };
93
+ const relativeDatePlaceholderRegex = /(\$start|\$end)-(\d+)-(second|minute|hour|day|week|month|quarter|year)-(before-now|after-now)-(date-time|date)/;
94
+ const getRelativeDateValue = relativeDatePlaceholderMatch => {
95
+ const startEnd = relativeDatePlaceholderMatch[1];
96
+ const amount = Number.parseInt(relativeDatePlaceholderMatch[2]);
97
+ const unit = relativeDatePlaceholderMatch[3];
98
+ const beforeAfter = relativeDatePlaceholderMatch[4];
99
+ const type = relativeDatePlaceholderMatch[5];
100
+ const result = beforeAfter === "before-now" ? moment__default["default"]().subtract(amount, unit) : moment__default["default"]().add(amount, unit);
101
+ const resultByStartEnd = startEnd === "$start" ? result.startOf(unit) : result.endOf(unit);
102
+ return type === "date" ? serializeDate(resultByStartEnd) : serializeDateTime(resultByStartEnd);
103
+ };
93
104
  const replacePlaceholdersInParams = params => params && ___default["default"].mapValues(params, (value, key) => {
94
105
  const replaceFn = paramsPlaceholdersLookup[key];
95
106
  if (replaceFn) {
96
107
  return replaceFn();
97
108
  }
109
+ const relativeDatePlaceholderMatch = key.match(relativeDatePlaceholderRegex);
110
+ if (relativeDatePlaceholderMatch) {
111
+ return getRelativeDateValue(relativeDatePlaceholderMatch);
112
+ }
98
113
  return value;
99
114
  });
100
115
  const dateToDateTimeIntervalLookup = {
@@ -89,11 +89,26 @@ const mapDynamicParams = (params, onDynamicParam) => {
89
89
  }
90
90
  }));
91
91
  };
92
+ const relativeDatePlaceholderRegex = /(\$start|\$end)-(\d+)-(second|minute|hour|day|week|month|quarter|year)-(before-now|after-now)-(date-time|date)/;
93
+ const getRelativeDateValue = relativeDatePlaceholderMatch => {
94
+ const startEnd = relativeDatePlaceholderMatch[1];
95
+ const amount = Number.parseInt(relativeDatePlaceholderMatch[2]);
96
+ const unit = relativeDatePlaceholderMatch[3];
97
+ const beforeAfter = relativeDatePlaceholderMatch[4];
98
+ const type = relativeDatePlaceholderMatch[5];
99
+ const result = beforeAfter === "before-now" ? moment__default["default"]().subtract(amount, unit) : moment__default["default"]().add(amount, unit);
100
+ const resultByStartEnd = startEnd === "$start" ? result.startOf(unit) : result.endOf(unit);
101
+ return type === "date" ? serializeDate(resultByStartEnd) : serializeDateTime(resultByStartEnd);
102
+ };
92
103
  const replacePlaceholdersInParams = params => params && ___default["default"].mapValues(params, (value, key) => {
93
104
  const replaceFn = paramsPlaceholdersLookup[key];
94
105
  if (replaceFn) {
95
106
  return replaceFn();
96
107
  }
108
+ const relativeDatePlaceholderMatch = key.match(relativeDatePlaceholderRegex);
109
+ if (relativeDatePlaceholderMatch) {
110
+ return getRelativeDateValue(relativeDatePlaceholderMatch);
111
+ }
97
112
  return value;
98
113
  });
99
114
  const dateToDateTimeIntervalLookup = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibery/expression-utils",
3
- "version": "1.1.19",
3
+ "version": "1.1.20",
4
4
  "description": "utils for working with fibery api expressions",
5
5
  "exports": {
6
6
  ".": "./lib/expression-utils.js",
@@ -26,18 +26,18 @@
26
26
  "dependencies": {
27
27
  "lodash": "4.17.21",
28
28
  "moment": "2.29.4",
29
- "@fibery/helpers": "1.0.4"
29
+ "@fibery/helpers": "1.1.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@babel/core": "7.20.5",
33
33
  "jest": "27.5.1",
34
34
  "jest-junit": "13.0.0",
35
35
  "microbundle": "0.15.0",
36
- "@fibery/babel-preset": "7.2.0",
37
- "@fibery/eslint-config": "8.3.0"
36
+ "@fibery/eslint-config": "8.3.0",
37
+ "@fibery/babel-preset": "7.2.0"
38
38
  },
39
39
  "peerDependencies": {
40
- "@fibery/schema": "^8.1.11"
40
+ "@fibery/schema": "^8.1.13"
41
41
  },
42
42
  "jest": {
43
43
  "testEnvironment": "node",