@fibery/expression-utils 1.1.10 → 1.1.12
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/lib/paramsPlaceholders.d.ts +99 -0
- package/lib/paramsPlaceholders.js +4 -0
- package/package.json +11 -9
- package/types.d.ts +70 -0
- package/lib/contextVariables.js +0 -20
- package/lib/expression-utils.js +0 -724
- package/lib/utils.js +0 -193
- package/lib/visitors.js +0 -463
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export const dateToDateTimeIntervalLookup: {
|
|
2
|
+
"$today-date": {
|
|
3
|
+
start: string;
|
|
4
|
+
end: string;
|
|
5
|
+
};
|
|
6
|
+
"$tomorrow-date": {
|
|
7
|
+
start: string;
|
|
8
|
+
end: string;
|
|
9
|
+
};
|
|
10
|
+
"$yesterday-date": {
|
|
11
|
+
start: string;
|
|
12
|
+
end: string;
|
|
13
|
+
};
|
|
14
|
+
"$week-ago-date": {
|
|
15
|
+
start: string;
|
|
16
|
+
end: string;
|
|
17
|
+
};
|
|
18
|
+
"$week-from-now-date": {
|
|
19
|
+
start: string;
|
|
20
|
+
end: string;
|
|
21
|
+
};
|
|
22
|
+
"$month-ago-date": {
|
|
23
|
+
start: string;
|
|
24
|
+
end: string;
|
|
25
|
+
};
|
|
26
|
+
"$month-from-now-date": {
|
|
27
|
+
start: string;
|
|
28
|
+
end: string;
|
|
29
|
+
};
|
|
30
|
+
"$year-ago-date": {
|
|
31
|
+
start: string;
|
|
32
|
+
end: string;
|
|
33
|
+
};
|
|
34
|
+
"$year-from-now-date": {
|
|
35
|
+
start: string;
|
|
36
|
+
end: string;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export const formulaNowDateTimeParamPlaceholder: "$formula-now-date-time-placeholder";
|
|
40
|
+
export const formulaTodayDateParamPlaceholder: "$formula-today-date-placeholder";
|
|
41
|
+
export const monthAgoDateParamPlaceholder: "$month-ago-date";
|
|
42
|
+
export const monthAgoEndDateTimeParamPlaceholder: "$month-ago-date-time-end";
|
|
43
|
+
export const monthAgoStartDateTimeParamPlaceholder: "$month-ago-date-time-start";
|
|
44
|
+
export const monthFromNowDateParamPlaceholder: "$month-from-now-date";
|
|
45
|
+
export const monthFromNowEndDateTimeParamPlaceholder: "$month-from-now-date-time-end";
|
|
46
|
+
export const monthFromNowStartDateTimeParamPlaceholder: "$month-from-now-date-time-start";
|
|
47
|
+
export const paramsPlaceholdersLookup: {
|
|
48
|
+
"$today-date": () => any;
|
|
49
|
+
"$formula-today-date-placeholder": () => any;
|
|
50
|
+
"$formula-now-date-time-placeholder": () => any;
|
|
51
|
+
"$tomorrow-date": () => any;
|
|
52
|
+
"$yesterday-date": () => any;
|
|
53
|
+
"$week-ago-date": () => any;
|
|
54
|
+
"$week-from-now-date": () => any;
|
|
55
|
+
"$month-ago-date": () => any;
|
|
56
|
+
"$month-from-now-date": () => any;
|
|
57
|
+
"$year-ago-date": () => any;
|
|
58
|
+
"$year-from-now-date": () => any;
|
|
59
|
+
"$today-date-time-start": () => any;
|
|
60
|
+
"$today-date-time-end": () => any;
|
|
61
|
+
"$tomorrow-date-time-start": () => any;
|
|
62
|
+
"$tomorrow-date-time-end": () => any;
|
|
63
|
+
"$yesterday-date-time-start": () => any;
|
|
64
|
+
"$yesterday-date-time-end": () => any;
|
|
65
|
+
"$week-ago-date-time-start": () => any;
|
|
66
|
+
"$week-ago-date-time-end": () => any;
|
|
67
|
+
"$week-from-now-date-time-start": () => any;
|
|
68
|
+
"$week-from-now-date-time-end": () => any;
|
|
69
|
+
"$month-ago-date-time-start": () => any;
|
|
70
|
+
"$month-ago-date-time-end": () => any;
|
|
71
|
+
"$month-from-now-date-time-start": () => any;
|
|
72
|
+
"$month-from-now-date-time-end": () => any;
|
|
73
|
+
"$year-ago-date-time-start": () => any;
|
|
74
|
+
"$year-ago-date-time-end": () => any;
|
|
75
|
+
"$year-from-now-date-time-start": () => any;
|
|
76
|
+
"$year-from-now-date-time-end": () => any;
|
|
77
|
+
};
|
|
78
|
+
export function replacePlaceholdersInParams(params: any): any;
|
|
79
|
+
export const todayDateParamPlaceholder: "$today-date";
|
|
80
|
+
export const todayEndDateTimeParamPlaceholder: "$today-date-time-end";
|
|
81
|
+
export const todayStartDateTimeParamPlaceholder: "$today-date-time-start";
|
|
82
|
+
export const tomorrowDateParamPlaceholder: "$tomorrow-date";
|
|
83
|
+
export const tomorrowEndDateTimeParamPlaceholder: "$tomorrow-date-time-end";
|
|
84
|
+
export const tomorrowStartDateTimeParamPlaceholder: "$tomorrow-date-time-start";
|
|
85
|
+
export const weekAgoDateParamPlaceholder: "$week-ago-date";
|
|
86
|
+
export const weekAgoEndDateTimeParamPlaceholder: "$week-ago-date-time-end";
|
|
87
|
+
export const weekAgoStartDateTimeParamPlaceholder: "$week-ago-date-time-start";
|
|
88
|
+
export const weekFromNowDateParamPlaceholder: "$week-from-now-date";
|
|
89
|
+
export const weekFromNowEndDateTimeParamPlaceholder: "$week-from-now-date-time-end";
|
|
90
|
+
export const weekFromNowStartDateTimeParamPlaceholder: "$week-from-now-date-time-start";
|
|
91
|
+
export const yearAgoDateParamPlaceholder: "$year-ago-date";
|
|
92
|
+
export const yearAgoEndDateTimeParamPlaceholder: "$year-ago-date-time-end";
|
|
93
|
+
export const yearAgoStartDateTimeParamPlaceholder: "$year-ago-date-time-start";
|
|
94
|
+
export const yearFromNowDateParamPlaceholder: "$year-from-now-date";
|
|
95
|
+
export const yearFromNowEndDateTimeParamPlaceholder: "$year-from-now-date-time-end";
|
|
96
|
+
export const yearFromNowStartDateTimeParamPlaceholder: "$year-from-now-date-time-start";
|
|
97
|
+
export const yesterdayDateParamPlaceholder: "$yesterday-date";
|
|
98
|
+
export const yesterdayEndDateTimeParamPlaceholder: "$yesterday-date-time-end";
|
|
99
|
+
export const yesterdayStartDateTimeParamPlaceholder: "$yesterday-date-time-start";
|
|
@@ -9,9 +9,11 @@ var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
|
9
9
|
const serializeDate = momentDate => {
|
|
10
10
|
return momentDate.format("YYYY-MM-DD");
|
|
11
11
|
};
|
|
12
|
+
|
|
12
13
|
const serializeDateTime = momentDate => {
|
|
13
14
|
return momentDate.toISOString();
|
|
14
15
|
};
|
|
16
|
+
|
|
15
17
|
const formulaTodayDateParamPlaceholder = "$formula-today-date-placeholder";
|
|
16
18
|
const formulaNowDateTimeParamPlaceholder = "$formula-now-date-time-placeholder";
|
|
17
19
|
const todayDateParamPlaceholder = "$today-date";
|
|
@@ -74,9 +76,11 @@ const paramsPlaceholdersLookup = {
|
|
|
74
76
|
};
|
|
75
77
|
const replacePlaceholdersInParams = params => params && ___default["default"].mapValues(params, (value, key) => {
|
|
76
78
|
const replaceFn = paramsPlaceholdersLookup[key];
|
|
79
|
+
|
|
77
80
|
if (replaceFn) {
|
|
78
81
|
return replaceFn();
|
|
79
82
|
}
|
|
83
|
+
|
|
80
84
|
return value;
|
|
81
85
|
});
|
|
82
86
|
const dateToDateTimeIntervalLookup = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/expression-utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.12",
|
|
4
4
|
"description": "utils for working with fibery api expressions",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/expression-utils.js",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"./visitors": "./lib/visitors.js",
|
|
10
10
|
"./paramsPlaceholders": "./lib/paramsPlaceholders.js"
|
|
11
11
|
},
|
|
12
|
+
"types": "./types.d.ts",
|
|
12
13
|
"fiberyDevExports": {
|
|
13
14
|
".": "./index.js",
|
|
14
15
|
"./contextVariables": "./contextVariables.js",
|
|
@@ -18,24 +19,25 @@
|
|
|
18
19
|
},
|
|
19
20
|
"main": "./lib/expression-utils.js",
|
|
20
21
|
"files": [
|
|
21
|
-
"/lib"
|
|
22
|
+
"/lib",
|
|
23
|
+
"types.d.ts"
|
|
22
24
|
],
|
|
23
25
|
"private": false,
|
|
24
26
|
"dependencies": {
|
|
25
|
-
"@fibery/helpers": "1.0.2",
|
|
26
27
|
"lodash": "4.17.21",
|
|
27
|
-
"moment": "2.29.4"
|
|
28
|
+
"moment": "2.29.4",
|
|
29
|
+
"@fibery/helpers": "1.0.3"
|
|
28
30
|
},
|
|
29
31
|
"devDependencies": {
|
|
30
32
|
"@babel/core": "7.20.5",
|
|
31
|
-
"@fibery/babel-preset": "7.2.0",
|
|
32
|
-
"@fibery/eslint-config": "8.3.0",
|
|
33
33
|
"jest": "27.5.1",
|
|
34
34
|
"jest-junit": "13.0.0",
|
|
35
|
-
"microbundle": "0.15.0"
|
|
35
|
+
"microbundle": "0.15.0",
|
|
36
|
+
"@fibery/babel-preset": "7.2.0",
|
|
37
|
+
"@fibery/eslint-config": "8.3.0"
|
|
36
38
|
},
|
|
37
39
|
"peerDependencies": {
|
|
38
|
-
"@fibery/schema": "^8.1.
|
|
40
|
+
"@fibery/schema": "^8.1.11"
|
|
39
41
|
},
|
|
40
42
|
"jest": {
|
|
41
43
|
"testEnvironment": "node",
|
|
@@ -59,7 +61,7 @@
|
|
|
59
61
|
"testURL": "http://localhost"
|
|
60
62
|
},
|
|
61
63
|
"scripts": {
|
|
62
|
-
"build": "rm -rf lib && microbundle paramsPlaceholders.js utils.js visitors.js contextVariables.js index.js -o lib -f cjs --no-compress --target node --sourcemap false",
|
|
64
|
+
"build": "rm -rf lib && microbundle paramsPlaceholders.js utils.js visitors.js contextVariables.js index.js -o lib -f cjs --no-compress --target node --sourcemap false --generateTypes false",
|
|
63
65
|
"test": "node scripts/test.js",
|
|
64
66
|
"test:ci": "yarn test --reporters=default --reporters=jest-junit",
|
|
65
67
|
"test:coverage": "yarn test --coverage --coverageDirectory=${JEST_COVERAGE_RESULT_DIR:-$(pwd)}/coverage/expression-utils --reporters=default --reporters=jest-junit",
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
+
import {TypeObject} from "@fibery/schema";
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
+
export type $TSFixMe = any;
|
|
6
|
+
|
|
7
|
+
declare module "@fibery/expression-utils" {
|
|
8
|
+
export const visitors: {
|
|
9
|
+
replaceNamesWithIdsVisitor(
|
|
10
|
+
typeObject: TypeObject,
|
|
11
|
+
onFieldNotFound?: (input: {
|
|
12
|
+
currentTypeObject: TypeObject;
|
|
13
|
+
fieldExpressionInIdsTerms: Array<string>;
|
|
14
|
+
field: string;
|
|
15
|
+
expression: Array<string>;
|
|
16
|
+
}) => $TSFixMe
|
|
17
|
+
): $TSFixMe;
|
|
18
|
+
|
|
19
|
+
replaceIdsWithNamesVisitor(
|
|
20
|
+
typeObject: TypeObject,
|
|
21
|
+
onFieldNotFound?: (input: {
|
|
22
|
+
currentTypeObject: TypeObject;
|
|
23
|
+
fieldExpressionInNamesTerms: Array<string>;
|
|
24
|
+
fieldId: string;
|
|
25
|
+
expression: Array<string>;
|
|
26
|
+
}) => $TSFixMe
|
|
27
|
+
): $TSFixMe;
|
|
28
|
+
|
|
29
|
+
deleteExpressionsWithNotFoundFieldsVisitor(typeObject): $TSFixMe;
|
|
30
|
+
};
|
|
31
|
+
export const paramsPlaceholders: {
|
|
32
|
+
dynamicFilterParamPrefix: string;
|
|
33
|
+
|
|
34
|
+
isDynamicFilterParam(paramValue: string): boolean;
|
|
35
|
+
|
|
36
|
+
getFieldIdFromDynamicParam(paramValue: string): string;
|
|
37
|
+
|
|
38
|
+
mapDynamicParams(
|
|
39
|
+
params: Record<string, $TSFixMe> | null,
|
|
40
|
+
onDynamicParam: (value: string) => string
|
|
41
|
+
): Record<string, $TSFixMe> | null;
|
|
42
|
+
|
|
43
|
+
replacePlaceholdersInParams(
|
|
44
|
+
params: Record<string, $TSFixMe> | null | undefined
|
|
45
|
+
): Record<string, $TSFixMe> | null | undefined;
|
|
46
|
+
|
|
47
|
+
paramsPlaceholdersLookup: Record<string, () => string>;
|
|
48
|
+
tomorrowStartDateTimeParamPlaceholder: string;
|
|
49
|
+
dateToDateTimeIntervalLookup: Record<string, {start: string; end: string}>;
|
|
50
|
+
|
|
51
|
+
monthAgoDateParamPlaceholder: string;
|
|
52
|
+
monthAgoStartDateTimeParamPlaceholder: string;
|
|
53
|
+
monthFromNowDateParamPlaceholder: string;
|
|
54
|
+
monthFromNowEndDateTimeParamPlaceholder: string;
|
|
55
|
+
todayDateParamPlaceholder: string;
|
|
56
|
+
todayEndDateTimeParamPlaceholder: string;
|
|
57
|
+
tomorrowDateParamPlaceholder: string;
|
|
58
|
+
weekAgoDateParamPlaceholder: string;
|
|
59
|
+
weekAgoStartDateTimeParamPlaceholder: string;
|
|
60
|
+
weekFromNowDateParamPlaceholder: string;
|
|
61
|
+
weekFromNowEndDateTimeParamPlaceholder: string;
|
|
62
|
+
yesterdayDateParamPlaceholder: string;
|
|
63
|
+
yesterdayEndDateTimeParamPlaceholder: string;
|
|
64
|
+
yesterdayStartDateTimeParamPlaceholder: string;
|
|
65
|
+
yearAgoDateParamPlaceholder: string;
|
|
66
|
+
yearAgoStartDateTimeParamPlaceholder: string;
|
|
67
|
+
yearFromNowDateParamPlaceholder: string;
|
|
68
|
+
yearFromNowEndDateTimeParamPlaceholder: string;
|
|
69
|
+
};
|
|
70
|
+
}
|
package/lib/contextVariables.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
var _ = require('lodash');
|
|
2
|
-
|
|
3
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
4
|
-
|
|
5
|
-
var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
|
|
6
|
-
|
|
7
|
-
const getEntityQueryVariables = schema => {
|
|
8
|
-
const grouped = ___default["default"].groupBy(schema.typeObjects.filter(x => x.isDomain), typeObject => typeObject.pluralTitle);
|
|
9
|
-
return ___default["default"].flatten(Object.values(grouped).map(group => {
|
|
10
|
-
return group.map(typeObject => ({
|
|
11
|
-
typeObject,
|
|
12
|
-
id: `entityQuery_${typeObject.id}`,
|
|
13
|
-
title: group.length > 1 ? `${typeObject.pluralTitle} (${typeObject.nameParts.namespace})` : typeObject.pluralTitle,
|
|
14
|
-
isCollection: true,
|
|
15
|
-
description: `All Entities from "${typeObject.title}" Database`
|
|
16
|
-
}));
|
|
17
|
-
}));
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
exports.getEntityQueryVariables = getEntityQueryVariables;
|