@fibery/expression-utils 9.7.3 → 10.0.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.
- package/lib/_virtual/_rolldown/runtime.js +13 -0
- package/lib/index.d.ts +191 -585
- package/lib/index.js +15 -50
- package/lib/src/context-variables.d.ts +27 -22
- package/lib/src/context-variables.js +106 -138
- package/lib/src/errors.d.ts +5 -2
- package/lib/src/errors.js +14 -14
- package/lib/src/field-expression-visitor-type-aware.d.ts +18 -16
- package/lib/src/field-expression-visitor-type-aware.js +116 -131
- package/lib/src/filter-expression/index.d.ts +12 -9
- package/lib/src/filter-expression/index.js +34 -47
- package/lib/src/filter-expression/operator-utils.d.ts +14 -11
- package/lib/src/filter-expression/operator-utils.js +191 -185
- package/lib/src/filter-expression/operators.d.ts +111 -106
- package/lib/src/filter-expression/operators.js +1130 -846
- package/lib/src/filter-expression/pattern-match-placeholders.d.ts +63 -61
- package/lib/src/filter-expression/pattern-match-placeholders.js +107 -138
- package/lib/src/filter-expression/pattern-match.d.ts +17 -15
- package/lib/src/filter-expression/pattern-match.js +118 -130
- package/lib/src/filter-expression/pattern-to-expression.d.ts +13 -11
- package/lib/src/filter-expression/pattern-to-expression.js +42 -45
- package/lib/src/filter-expression/types.d.ts +29 -26
- package/lib/src/filter-expression/types.js +0 -3
- package/lib/src/params-placeholders.d.ts +55 -51
- package/lib/src/params-placeholders.js +199 -192
- package/lib/src/tsfixme.d.ts +4 -1
- package/lib/src/tsfixme.js +0 -3
- package/lib/src/types.d.ts +47 -45
- package/lib/src/types.js +0 -3
- package/lib/src/utils.d.ts +53 -48
- package/lib/src/utils.js +276 -337
- package/lib/src/visitors.d.ts +43 -37
- package/lib/src/visitors.js +306 -365
- package/lib/test-data/schema-mock.d.ts +68 -751
- package/lib/test-data/schema-mock.js +175 -139
- package/package.json +17 -10
- package/lib/index.js.map +0 -1
- package/lib/src/context-variables.js.map +0 -1
- package/lib/src/errors.js.map +0 -1
- package/lib/src/field-expression-visitor-type-aware.js.map +0 -1
- package/lib/src/filter-expression/index.js.map +0 -1
- package/lib/src/filter-expression/operator-utils.js.map +0 -1
- package/lib/src/filter-expression/operators.js.map +0 -1
- package/lib/src/filter-expression/pattern-match-placeholders.js.map +0 -1
- package/lib/src/filter-expression/pattern-match.js.map +0 -1
- package/lib/src/filter-expression/pattern-to-expression.js.map +0 -1
- package/lib/src/filter-expression/types.js.map +0 -1
- package/lib/src/params-placeholders.js.map +0 -1
- package/lib/src/tsfixme.js.map +0 -1
- package/lib/src/types.js.map +0 -1
- package/lib/src/utils.js.map +0 -1
- package/lib/src/visitors.js.map +0 -1
- package/lib/test-data/schema-mock.js.map +0 -1
|
@@ -1,135 +1,120 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
fieldAccess,
|
|
65
|
-
});
|
|
66
|
-
return notFoundResult
|
|
67
|
-
? { typeObject: notFoundResult.typeObject, expression: [...expression, notFoundResult.fieldAccess] }
|
|
68
|
-
: {
|
|
69
|
-
typeObject,
|
|
70
|
-
expression,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
1
|
+
import { createExpressionVisitor, isMultiFieldAccess } from "./utils.js";
|
|
2
|
+
import { mapValues } from "@fibery/helpers/src/_";
|
|
3
|
+
import isPlainObject from "lodash/isPlainObject.js";
|
|
4
|
+
//#region src/field-expression-visitor-type-aware.ts
|
|
5
|
+
const visitFieldExpression = ({ expression: fieldExpression, typeObject: initialTypeObject, onField, onFieldNotFound }) => fieldExpression.reduce(({ typeObject, expression }, fieldAccess) => {
|
|
6
|
+
if (typeObject && isMultiFieldAccess(fieldAccess) && Object.hasOwn(typeObject.fieldObjectsById, fieldAccess[0])) {
|
|
7
|
+
const typeId = fieldAccess[1];
|
|
8
|
+
const fieldObject = typeObject.fieldObjectsById[fieldAccess[0]];
|
|
9
|
+
const nextTypeObject = fieldObject.multiRelatedFieldObjects.find((f) => f.holderTypeObject.id === typeId)?.holderTypeObject;
|
|
10
|
+
if (!nextTypeObject) {
|
|
11
|
+
const notFoundResult = onFieldNotFound({
|
|
12
|
+
currentTypeObject: typeObject,
|
|
13
|
+
expression: fieldExpression,
|
|
14
|
+
fieldAccess
|
|
15
|
+
});
|
|
16
|
+
return notFoundResult ? {
|
|
17
|
+
typeObject: notFoundResult.typeObject,
|
|
18
|
+
expression: [...expression, notFoundResult.fieldAccess]
|
|
19
|
+
} : {
|
|
20
|
+
typeObject,
|
|
21
|
+
expression
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const onFieldResult = onField({
|
|
25
|
+
fieldAccess,
|
|
26
|
+
fieldObject,
|
|
27
|
+
typeObject: nextTypeObject
|
|
28
|
+
});
|
|
29
|
+
return onFieldResult ? {
|
|
30
|
+
typeObject: onFieldResult.typeObject,
|
|
31
|
+
expression: [...expression, onFieldResult.fieldAccess]
|
|
32
|
+
} : {
|
|
33
|
+
typeObject,
|
|
34
|
+
expression
|
|
35
|
+
};
|
|
36
|
+
} else if (typeObject && Object.hasOwn(typeObject.fieldObjectsById, fieldAccess)) {
|
|
37
|
+
const fieldObject = typeObject.fieldObjectsById[fieldAccess];
|
|
38
|
+
const onFieldResult = onField({
|
|
39
|
+
fieldAccess,
|
|
40
|
+
fieldObject,
|
|
41
|
+
typeObject: fieldObject.typeObject
|
|
42
|
+
});
|
|
43
|
+
return onFieldResult ? {
|
|
44
|
+
typeObject: onFieldResult.typeObject,
|
|
45
|
+
expression: [...expression, onFieldResult.fieldAccess]
|
|
46
|
+
} : {
|
|
47
|
+
typeObject,
|
|
48
|
+
expression
|
|
49
|
+
};
|
|
50
|
+
} else {
|
|
51
|
+
const notFoundResult = onFieldNotFound({
|
|
52
|
+
currentTypeObject: typeObject,
|
|
53
|
+
expression: fieldExpression,
|
|
54
|
+
fieldAccess
|
|
55
|
+
});
|
|
56
|
+
return notFoundResult ? {
|
|
57
|
+
typeObject: notFoundResult.typeObject,
|
|
58
|
+
expression: [...expression, notFoundResult.fieldAccess]
|
|
59
|
+
} : {
|
|
60
|
+
typeObject,
|
|
61
|
+
expression
|
|
62
|
+
};
|
|
63
|
+
}
|
|
73
64
|
}, {
|
|
74
|
-
|
|
75
|
-
|
|
65
|
+
typeObject: initialTypeObject,
|
|
66
|
+
expression: []
|
|
76
67
|
});
|
|
77
|
-
const defaultOnFieldNotFound = () =>
|
|
78
|
-
const defaultOnField = () =>
|
|
79
|
-
const fieldAccessVisitorTypeAwareInternal = ({ typeObject, rootTypeObject, onField = defaultOnField, onFieldNotFound = defaultOnFieldNotFound
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
...(whereExpression ? { "q/where": subQueryVisitor.visitExpression(whereExpression) } : null),
|
|
120
|
-
...(orderByExpression
|
|
121
|
-
? {
|
|
122
|
-
"q/order-by": subQueryVisitor.visitOrderByExpression(orderByExpression),
|
|
123
|
-
}
|
|
124
|
-
: null),
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
return subQueryExpression;
|
|
128
|
-
},
|
|
129
|
-
});
|
|
68
|
+
const defaultOnFieldNotFound = () => void 0;
|
|
69
|
+
const defaultOnField = () => void 0;
|
|
70
|
+
const fieldAccessVisitorTypeAwareInternal = ({ typeObject, rootTypeObject, onField = defaultOnField, onFieldNotFound = defaultOnFieldNotFound }) => {
|
|
71
|
+
return createExpressionVisitor({
|
|
72
|
+
visitFieldExpression: (expression) => visitFieldExpression({
|
|
73
|
+
typeObject,
|
|
74
|
+
expression,
|
|
75
|
+
onField,
|
|
76
|
+
onFieldNotFound
|
|
77
|
+
}).expression,
|
|
78
|
+
visitFromRootFieldExpression: ([fromRootKeyword, ...rest]) => [fromRootKeyword, ...rest.map((x) => fieldAccessVisitorTypeAwareInternal({
|
|
79
|
+
typeObject: rootTypeObject,
|
|
80
|
+
rootTypeObject,
|
|
81
|
+
onField,
|
|
82
|
+
onFieldNotFound
|
|
83
|
+
}).visitExpression(x))],
|
|
84
|
+
visitQueryExpression: (subQueryExpression) => {
|
|
85
|
+
const { "q/from": fromExpression, "q/select": selectExpression, "q/where": whereExpression, "q/order-by": orderByExpression } = subQueryExpression;
|
|
86
|
+
const fromVisitResult = visitFieldExpression({
|
|
87
|
+
typeObject,
|
|
88
|
+
expression: fromExpression,
|
|
89
|
+
onField,
|
|
90
|
+
onFieldNotFound
|
|
91
|
+
});
|
|
92
|
+
if (fromVisitResult?.typeObject) {
|
|
93
|
+
const subQueryVisitor = fieldAccessVisitorTypeAwareInternal({
|
|
94
|
+
typeObject: fromVisitResult?.typeObject,
|
|
95
|
+
rootTypeObject,
|
|
96
|
+
onField,
|
|
97
|
+
onFieldNotFound
|
|
98
|
+
});
|
|
99
|
+
return {
|
|
100
|
+
...subQueryExpression,
|
|
101
|
+
"q/from": fromVisitResult.expression,
|
|
102
|
+
"q/select": isPlainObject(selectExpression) ? mapValues(selectExpression, (val) => subQueryVisitor.visitExpression(val)) : subQueryVisitor.visitExpression(selectExpression),
|
|
103
|
+
...whereExpression ? { "q/where": subQueryVisitor.visitExpression(whereExpression) } : null,
|
|
104
|
+
...orderByExpression ? { "q/order-by": subQueryVisitor.visitOrderByExpression(orderByExpression) } : null
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return subQueryExpression;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
130
110
|
};
|
|
131
|
-
const fieldAccessVisitorTypeAware = ({ typeObject, onField = defaultOnField, onFieldNotFound = defaultOnFieldNotFound
|
|
132
|
-
|
|
111
|
+
const fieldAccessVisitorTypeAware = ({ typeObject, onField = defaultOnField, onFieldNotFound = defaultOnFieldNotFound }) => {
|
|
112
|
+
return fieldAccessVisitorTypeAwareInternal({
|
|
113
|
+
typeObject,
|
|
114
|
+
rootTypeObject: typeObject,
|
|
115
|
+
onField,
|
|
116
|
+
onFieldNotFound
|
|
117
|
+
});
|
|
133
118
|
};
|
|
134
|
-
|
|
135
|
-
|
|
119
|
+
//#endregion
|
|
120
|
+
export { fieldAccessVisitorTypeAware };
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { Expression } from "../types.js";
|
|
2
|
+
import { Operator } from "./types.js";
|
|
3
|
+
import { Schema } from "@fibery/schema";
|
|
4
|
+
//#region src/filter-expression/index.d.ts
|
|
5
|
+
declare const findMatchedFilter: (filterExpression: Expression, params: Record<string, unknown>, operators: Array<Operator>, schema: Schema | null, type: string) => {
|
|
6
|
+
operator: Operator;
|
|
7
|
+
value: any;
|
|
8
|
+
expression: Expression;
|
|
9
|
+
type: string;
|
|
10
|
+
id: string;
|
|
10
11
|
} | null;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { findMatchedFilter };
|
|
@@ -1,49 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const errors_1 = require("../errors");
|
|
6
|
-
const pattern_match_1 = require("./pattern-match");
|
|
1
|
+
import { NotImplementedError } from "../errors.js";
|
|
2
|
+
import { doPatternMatch } from "./pattern-match.js";
|
|
3
|
+
import { v4 } from "uuid";
|
|
4
|
+
//#region src/filter-expression/index.ts
|
|
7
5
|
const findMatchedFilter = (filterExpression, params, operators, schema, type) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
operator,
|
|
38
|
-
value: paramMatches[0] && paramMatches[0].value,
|
|
39
|
-
expression: expressionMatches[0].value,
|
|
40
|
-
type,
|
|
41
|
-
id: (0, uuid_1.v4)(),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return null;
|
|
6
|
+
if (!schema || !Object.hasOwn(schema.typeObjectsByName, type)) return null;
|
|
7
|
+
const typeObject = schema.typeObjectsByName[type];
|
|
8
|
+
for (const operator of operators) if (operator.customMatch) {
|
|
9
|
+
const matchResult = operator.customMatch(filterExpression, params, typeObject);
|
|
10
|
+
if (matchResult.matchSuccess) return {
|
|
11
|
+
operator,
|
|
12
|
+
value: matchResult.value,
|
|
13
|
+
expression: matchResult.expression,
|
|
14
|
+
type,
|
|
15
|
+
id: v4()
|
|
16
|
+
};
|
|
17
|
+
} else {
|
|
18
|
+
const { matchSuccess, matches } = doPatternMatch(filterExpression, params, operator.pattern, typeObject);
|
|
19
|
+
if (matchSuccess) {
|
|
20
|
+
const paramMatches = matches.filter((x) => x.matchType === ":expression-match-type/param");
|
|
21
|
+
const expressionMatches = matches.filter((x) => x.matchType === ":expression-match-type/expression");
|
|
22
|
+
if (paramMatches.length > 1) throw new NotImplementedError(`Operator pattern with several param placeholders`);
|
|
23
|
+
if (expressionMatches.length > 1) throw new NotImplementedError(`Operator pattern with several expression placeholders`);
|
|
24
|
+
return {
|
|
25
|
+
operator,
|
|
26
|
+
value: paramMatches[0] && paramMatches[0].value,
|
|
27
|
+
expression: expressionMatches[0].value,
|
|
28
|
+
type,
|
|
29
|
+
id: v4()
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
47
34
|
};
|
|
48
|
-
|
|
49
|
-
|
|
35
|
+
//#endregion
|
|
36
|
+
export { findMatchedFilter };
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { Expression } from "../types.js";
|
|
2
|
+
import { $TSFixMe } from "../tsfixme.js";
|
|
3
|
+
import { CustomMatchFn, Operator } from "./types.js";
|
|
4
|
+
//#region src/filter-expression/operator-utils.d.ts
|
|
5
|
+
declare const isDateTime: (dateString: string) => boolean;
|
|
6
|
+
declare const NO_VALUE: undefined;
|
|
7
|
+
declare const isNoValue: (value: unknown) => boolean;
|
|
8
|
+
declare const getCompareOperatorForDateTime: (id: string, title: string, operator: string, compareByStartInterval: boolean, isNegative: boolean) => Operator;
|
|
9
|
+
declare const getWithinOperatorCustomConvertFn: (leftPartExcluded: boolean) => (expression: Expression, value: {
|
|
10
|
+
withinRangeStart: unknown;
|
|
11
|
+
withinRangeEnd: unknown;
|
|
11
12
|
} | null, getNextParamName: () => string) => $TSFixMe;
|
|
12
|
-
|
|
13
|
+
declare const getWithinOperatorCustomMatchFn: (fieldPlaceholder: $TSFixMe, leftPartExcluded: boolean) => CustomMatchFn;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { NO_VALUE, getCompareOperatorForDateTime, getWithinOperatorCustomConvertFn, getWithinOperatorCustomMatchFn, isDateTime, isNoValue };
|