@fibery/expression-utils 10.0.0 → 10.0.2
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/{src/context-variables.js → context-variables.js} +1 -1
- package/lib/{src/filter-expression → filter-expression}/index.d.ts +1 -1
- package/lib/{src/filter-expression → filter-expression}/index.js +5 -4
- package/lib/{src/filter-expression → filter-expression}/operator-utils.d.ts +3 -7
- package/lib/{src/filter-expression → filter-expression}/operator-utils.js +12 -9
- package/lib/filter-expression/operators.d.ts +354 -0
- package/lib/{src/filter-expression → filter-expression}/operators.js +30 -26
- package/lib/filter-expression/pattern-match.d.ts +23 -0
- package/lib/filter-expression/pattern-match.js +116 -0
- package/lib/filter-expression/pattern-to-expression.d.ts +6 -0
- package/lib/filter-expression/pattern-to-expression.js +42 -0
- package/lib/filter-expression/types.d.ts +56 -0
- package/lib/index.d.ts +10 -181
- package/lib/index.js +8 -8
- package/lib/{src/params-placeholders.js → params-placeholders.js} +1 -1
- package/lib/{src/utils.js → utils.js} +2 -2
- package/lib/{src/visitors.js → visitors.js} +1 -1
- package/package.json +12 -38
- package/lib/src/filter-expression/operators.d.ts +0 -113
- package/lib/src/filter-expression/pattern-match.d.ts +0 -21
- package/lib/src/filter-expression/pattern-match.js +0 -126
- package/lib/src/filter-expression/pattern-to-expression.d.ts +0 -17
- package/lib/src/filter-expression/pattern-to-expression.js +0 -44
- package/lib/src/filter-expression/types.d.ts +0 -33
- package/lib/src/tsfixme.d.ts +0 -4
- package/lib/src/tsfixme.js +0 -0
- package/lib/test-data/schema-mock.d.ts +0 -73
- package/lib/test-data/schema-mock.js +0 -175
- /package/lib/{src/context-variables.d.ts → context-variables.d.ts} +0 -0
- /package/lib/{src/errors.d.ts → errors.d.ts} +0 -0
- /package/lib/{src/errors.js → errors.js} +0 -0
- /package/lib/{src/field-expression-visitor-type-aware.d.ts → field-expression-visitor-type-aware.d.ts} +0 -0
- /package/lib/{src/field-expression-visitor-type-aware.js → field-expression-visitor-type-aware.js} +0 -0
- /package/lib/{src/filter-expression → filter-expression}/pattern-match-placeholders.d.ts +0 -0
- /package/lib/{src/filter-expression → filter-expression}/pattern-match-placeholders.js +0 -0
- /package/lib/{src/filter-expression → filter-expression}/types.js +0 -0
- /package/lib/{src/params-placeholders.d.ts → params-placeholders.d.ts} +0 -0
- /package/lib/{src/types.d.ts → types.d.ts} +0 -0
- /package/lib/{src/types.js → types.js} +0 -0
- /package/lib/{src/utils.d.ts → utils.d.ts} +0 -0
- /package/lib/{src/visitors.d.ts → visitors.d.ts} +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Expression } from "../types.js";
|
|
2
|
+
import { PatternNode } from "./types.js";
|
|
3
|
+
import { TypeObject } from "@fibery/schema";
|
|
4
|
+
//#region src/filter-expression/pattern-match.d.ts
|
|
5
|
+
type ParamPatternMatch = {
|
|
6
|
+
matchType: ":expression-match-type/param";
|
|
7
|
+
value: unknown;
|
|
8
|
+
};
|
|
9
|
+
type ExpressionPatternMatch = {
|
|
10
|
+
matchType: ":expression-match-type/expression";
|
|
11
|
+
value: Expression;
|
|
12
|
+
};
|
|
13
|
+
type PatternMatch = ParamPatternMatch | ExpressionPatternMatch;
|
|
14
|
+
declare const isParamPatternMatch: (match: PatternMatch | undefined) => match is ParamPatternMatch;
|
|
15
|
+
declare const isExpressionPatternMatch: (match: PatternMatch | undefined) => match is ExpressionPatternMatch;
|
|
16
|
+
declare const getExpressionArrayMatchValue: (match: PatternMatch | undefined) => Expression[] | null;
|
|
17
|
+
type PatternMatchResult = {
|
|
18
|
+
matchSuccess: boolean;
|
|
19
|
+
matches: PatternMatch[];
|
|
20
|
+
};
|
|
21
|
+
declare const doPatternMatch: (expression: unknown, params: Record<string, unknown>, pattern: PatternNode, typeObject: TypeObject) => PatternMatchResult;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { ExpressionPatternMatch, ParamPatternMatch, PatternMatch, PatternMatchResult, doPatternMatch, getExpressionArrayMatchValue, isExpressionPatternMatch, isParamPatternMatch };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { getFieldObjectByFieldExpression, isFieldExpressionValid, isVariableExpression } from "../utils.js";
|
|
2
|
+
import { isRecord } from "@fibery/helpers/src/_";
|
|
3
|
+
import isPlainObject from "lodash/isPlainObject.js";
|
|
4
|
+
import isString from "lodash/isString.js";
|
|
5
|
+
//#region src/filter-expression/pattern-match.ts
|
|
6
|
+
const isPlaceholderNode = (node) => {
|
|
7
|
+
if (typeof node !== "object" || node === null || Array.isArray(node)) return false;
|
|
8
|
+
const { id, matchFn } = node;
|
|
9
|
+
return typeof matchFn === "function" && (id === ":expression-pattern/expression-placeholder" || id === ":expression-pattern/param-placeholder" || id === ":expression-pattern/constant-placeholder");
|
|
10
|
+
};
|
|
11
|
+
const isQueryPatternNode = (node) => typeof node === "object" && node !== null && !Array.isArray(node) && "q/from" in node;
|
|
12
|
+
const isQueryExpression = (expression) => isRecord(expression) && "q/from" in expression && Array.isArray(expression["q/from"]);
|
|
13
|
+
const isSelectPatternRecord = (pattern) => pattern !== void 0 && isPlainObject(pattern) && !isPlaceholderNode(pattern);
|
|
14
|
+
const isParamPatternMatch = (match) => match?.matchType === ":expression-match-type/param";
|
|
15
|
+
const isExpressionPatternMatch = (match) => match?.matchType === ":expression-match-type/expression";
|
|
16
|
+
const getExpressionArrayMatchValue = (match) => isExpressionPatternMatch(match) && Array.isArray(match.value) ? match.value : null;
|
|
17
|
+
const noMatch = () => ({
|
|
18
|
+
matchSuccess: false,
|
|
19
|
+
matches: []
|
|
20
|
+
});
|
|
21
|
+
const matchSelectClause = (selectExpression, params, selectPattern, typeObject) => {
|
|
22
|
+
if (selectPattern === void 0) return {
|
|
23
|
+
matchSuccess: selectExpression === void 0,
|
|
24
|
+
matches: []
|
|
25
|
+
};
|
|
26
|
+
if (isSelectPatternRecord(selectPattern)) {
|
|
27
|
+
if (!isPlainObject(selectExpression)) return noMatch();
|
|
28
|
+
const expressionRecord = selectExpression;
|
|
29
|
+
const expressionKeys = Object.keys(expressionRecord);
|
|
30
|
+
const patternKeys = Object.keys(selectPattern);
|
|
31
|
+
if (expressionKeys.length !== patternKeys.length || patternKeys.some((key) => !Object.hasOwn(expressionRecord, key))) return noMatch();
|
|
32
|
+
const matches = [];
|
|
33
|
+
for (const key of patternKeys) {
|
|
34
|
+
const result = doPatternMatch(expressionRecord[key], params, selectPattern[key], typeObject);
|
|
35
|
+
if (!result.matchSuccess) return noMatch();
|
|
36
|
+
matches.push(...result.matches);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
matchSuccess: true,
|
|
40
|
+
matches
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return doPatternMatch(selectExpression, params, selectPattern, typeObject);
|
|
44
|
+
};
|
|
45
|
+
const matchQuery = (expression, params, pattern, typeObject) => {
|
|
46
|
+
const fromExpression = expression["q/from"];
|
|
47
|
+
if (!isFieldExpressionValid({
|
|
48
|
+
typeObject,
|
|
49
|
+
expression: fromExpression
|
|
50
|
+
})) return noMatch();
|
|
51
|
+
const fromTypeObject = getFieldObjectByFieldExpression({
|
|
52
|
+
typeObject,
|
|
53
|
+
expression: fromExpression
|
|
54
|
+
}).typeObject;
|
|
55
|
+
const fromResult = doPatternMatch(fromExpression, params, pattern["q/from"], typeObject);
|
|
56
|
+
if (!fromResult.matchSuccess) return noMatch();
|
|
57
|
+
const selectResult = matchSelectClause(expression["q/select"], params, pattern["q/select"], fromTypeObject);
|
|
58
|
+
if (!selectResult.matchSuccess || pattern["q/limit"] !== expression["q/limit"]) return noMatch();
|
|
59
|
+
const wherePattern = pattern["q/where"];
|
|
60
|
+
const whereResult = wherePattern === void 0 ? {
|
|
61
|
+
matchSuccess: expression["q/where"] === void 0,
|
|
62
|
+
matches: []
|
|
63
|
+
} : doPatternMatch(expression["q/where"], params, wherePattern, fromTypeObject);
|
|
64
|
+
if (!whereResult.matchSuccess) return noMatch();
|
|
65
|
+
return {
|
|
66
|
+
matchSuccess: true,
|
|
67
|
+
matches: [
|
|
68
|
+
...fromResult.matches,
|
|
69
|
+
...whereResult.matches,
|
|
70
|
+
...selectResult.matches
|
|
71
|
+
]
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
const matchExpression = (expressionPlaceholder, expression, typeObject) => {
|
|
75
|
+
if (!isString(expression) && !Array.isArray(expression)) return noMatch();
|
|
76
|
+
const expressionValue = expression;
|
|
77
|
+
return {
|
|
78
|
+
matchSuccess: expressionPlaceholder.matchFn(expressionValue, typeObject),
|
|
79
|
+
matches: [{
|
|
80
|
+
matchType: ":expression-match-type/expression",
|
|
81
|
+
value: isString(expressionValue) ? [expressionValue] : expressionValue
|
|
82
|
+
}]
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
const matchPlaceholder = (expression, params, placeholder) => {
|
|
86
|
+
const value = isString(expression) && isVariableExpression(expression) ? params[expression] : expression;
|
|
87
|
+
if (!placeholder.matchFn(value)) return noMatch();
|
|
88
|
+
return {
|
|
89
|
+
matchSuccess: true,
|
|
90
|
+
matches: placeholder.id === ":expression-pattern/param-placeholder" ? [{
|
|
91
|
+
matchType: ":expression-match-type/param",
|
|
92
|
+
value
|
|
93
|
+
}] : []
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
const doPatternMatch = (expression, params, pattern, typeObject) => {
|
|
97
|
+
if (expression === pattern) return {
|
|
98
|
+
matchSuccess: true,
|
|
99
|
+
matches: []
|
|
100
|
+
};
|
|
101
|
+
if (isPlaceholderNode(pattern)) return pattern.id === ":expression-pattern/expression-placeholder" ? matchExpression(pattern, expression, typeObject) : matchPlaceholder(expression, params, pattern);
|
|
102
|
+
if (isQueryPatternNode(pattern)) return isQueryExpression(expression) ? matchQuery(expression, params, pattern, typeObject) : noMatch();
|
|
103
|
+
if (!Array.isArray(expression) || !Array.isArray(pattern) || expression.length !== pattern.length) return noMatch();
|
|
104
|
+
const matches = [];
|
|
105
|
+
for (let index = 0; index < pattern.length; index += 1) {
|
|
106
|
+
const result = doPatternMatch(expression[index], params, pattern[index], typeObject);
|
|
107
|
+
if (!result.matchSuccess) return noMatch();
|
|
108
|
+
matches.push(...result.matches);
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
matchSuccess: true,
|
|
112
|
+
matches
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
//#endregion
|
|
116
|
+
export { doPatternMatch, getExpressionArrayMatchValue, isExpressionPatternMatch, isParamPatternMatch };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Expression } from "../types.js";
|
|
2
|
+
import { ConvertResult, PatternNode } from "./types.js";
|
|
3
|
+
//#region src/filter-expression/pattern-to-expression.d.ts
|
|
4
|
+
declare const convertToExpression: (pattern: PatternNode[], filterExpression: Expression, value: unknown, getNextParamName: () => string) => ConvertResult;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { convertToExpression };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { paramsPlaceholdersLookup, parseRelativeDatePlaceholder } from "../params-placeholders.js";
|
|
2
|
+
//#region src/filter-expression/pattern-to-expression.ts
|
|
3
|
+
const isPlaceholderNode = (node) => {
|
|
4
|
+
if (typeof node !== "object" || node === null || Array.isArray(node)) return false;
|
|
5
|
+
const { id, matchFn } = node;
|
|
6
|
+
return typeof matchFn === "function" && (id === ":expression-pattern/expression-placeholder" || id === ":expression-pattern/param-placeholder" || id === ":expression-pattern/constant-placeholder");
|
|
7
|
+
};
|
|
8
|
+
const isQueryPatternNode = (node) => typeof node === "object" && node !== null && !Array.isArray(node) && "q/from" in node;
|
|
9
|
+
const isSelectPatternRecord = (pattern) => pattern !== void 0 && typeof pattern === "object" && pattern !== null && !Array.isArray(pattern) && !isPlaceholderNode(pattern);
|
|
10
|
+
const convertToExpression = (pattern, filterExpression, value, getNextParamName) => {
|
|
11
|
+
const params = {};
|
|
12
|
+
const convertNode = (patternNode) => {
|
|
13
|
+
if (isPlaceholderNode(patternNode)) {
|
|
14
|
+
if (patternNode.id === ":expression-pattern/expression-placeholder") return filterExpression;
|
|
15
|
+
if (patternNode.id === ":expression-pattern/param-placeholder") {
|
|
16
|
+
const paramName = typeof value === "string" && (Object.hasOwn(paramsPlaceholdersLookup, value) || parseRelativeDatePlaceholder(value) !== null) ? value : getNextParamName();
|
|
17
|
+
params[paramName] = value;
|
|
18
|
+
return paramName;
|
|
19
|
+
}
|
|
20
|
+
const paramName = getNextParamName();
|
|
21
|
+
params[paramName] = patternNode.value;
|
|
22
|
+
return paramName;
|
|
23
|
+
}
|
|
24
|
+
if (Array.isArray(patternNode)) return patternNode.map(convertNode);
|
|
25
|
+
if (isQueryPatternNode(patternNode)) {
|
|
26
|
+
const query = { "q/from": filterExpression };
|
|
27
|
+
const selectPattern = patternNode["q/select"];
|
|
28
|
+
if (isSelectPatternRecord(selectPattern)) query["q/select"] = Object.fromEntries(Object.entries(selectPattern).map(([key, selectNode]) => [key, convertNode(selectNode)]));
|
|
29
|
+
else if (selectPattern !== void 0) query["q/select"] = convertNode(selectPattern);
|
|
30
|
+
if (patternNode["q/where"] !== void 0) query["q/where"] = convertNode(patternNode["q/where"]);
|
|
31
|
+
if (patternNode["q/limit"] !== void 0) query["q/limit"] = patternNode["q/limit"];
|
|
32
|
+
return query;
|
|
33
|
+
}
|
|
34
|
+
return patternNode;
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
expression: pattern.map(convertNode),
|
|
38
|
+
params
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
//#endregion
|
|
42
|
+
export { convertToExpression };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Expression, QueryLimit } from "../types.js";
|
|
2
|
+
import { TypeObject } from "@fibery/schema";
|
|
3
|
+
//#region src/filter-expression/types.d.ts
|
|
4
|
+
type CustomMatchResult = {
|
|
5
|
+
matchSuccess: false;
|
|
6
|
+
} | {
|
|
7
|
+
matchSuccess: true;
|
|
8
|
+
value?: unknown;
|
|
9
|
+
expression: Expression;
|
|
10
|
+
};
|
|
11
|
+
type CustomMatchFn = (where: Expression, params: Record<string, unknown>, typeObject: TypeObject) => CustomMatchResult;
|
|
12
|
+
type ExpressionPlaceholder = {
|
|
13
|
+
id: ":expression-pattern/expression-placeholder";
|
|
14
|
+
matchFn: (expression: Expression, typeObject: TypeObject) => boolean;
|
|
15
|
+
};
|
|
16
|
+
type ParamPlaceholder = {
|
|
17
|
+
id: ":expression-pattern/param-placeholder";
|
|
18
|
+
matchFn: (value: unknown) => boolean;
|
|
19
|
+
};
|
|
20
|
+
type ConstantPlaceholder = {
|
|
21
|
+
id: ":expression-pattern/constant-placeholder";
|
|
22
|
+
value: unknown;
|
|
23
|
+
matchFn: (value: unknown) => boolean;
|
|
24
|
+
};
|
|
25
|
+
type QueryPatternNode = {
|
|
26
|
+
"q/from": PatternNode;
|
|
27
|
+
"q/select"?: PatternNode | Record<string, PatternNode>;
|
|
28
|
+
"q/where"?: PatternNode;
|
|
29
|
+
"q/limit"?: QueryLimit;
|
|
30
|
+
};
|
|
31
|
+
type PatternNode = string | ExpressionPlaceholder | ParamPlaceholder | ConstantPlaceholder | QueryPatternNode | PatternNode[];
|
|
32
|
+
type ConvertResult = {
|
|
33
|
+
expression: Expression;
|
|
34
|
+
params: Record<string, unknown>;
|
|
35
|
+
};
|
|
36
|
+
type Operator = {
|
|
37
|
+
id: string;
|
|
38
|
+
type: string;
|
|
39
|
+
title: string;
|
|
40
|
+
/** Whether this is a negative operator (e.g. "is not", "does not contain"). Used for UI hints like filter color display. */
|
|
41
|
+
isNegative: boolean;
|
|
42
|
+
pattern?: PatternNode[];
|
|
43
|
+
customMatch?: CustomMatchFn;
|
|
44
|
+
customConvertToWhereExpression?: (expression: Expression, value: unknown, getNextParamName: () => string) => ConvertResult;
|
|
45
|
+
};
|
|
46
|
+
type ExpressionToFilterBy = {
|
|
47
|
+
title?: string;
|
|
48
|
+
icon?: string;
|
|
49
|
+
itemExpressions: Array<{
|
|
50
|
+
expression: Expression;
|
|
51
|
+
type: string;
|
|
52
|
+
}>;
|
|
53
|
+
calculateRelationFieldExpressions?: () => ExpressionToFilterBy[];
|
|
54
|
+
};
|
|
55
|
+
//#endregion
|
|
56
|
+
export { ConstantPlaceholder, ConvertResult, CustomMatchFn, CustomMatchResult, ExpressionPlaceholder, ExpressionToFilterBy, Operator, ParamPlaceholder, PatternNode, QueryPatternNode };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,193 +1,22 @@
|
|
|
1
|
-
import { ContextVariable, context_variables_d_exports } from "./
|
|
2
|
-
import { Expression, ExpressionVisitor, ExpressionVisitorWithDefault, FieldExpression, FromRootExpression, FunctionCallExpression, MultiFieldAccess, OrderBy, Query, Select, SubQuery } from "./
|
|
3
|
-
import { ExpressionToFilterBy, Operator } from "./
|
|
4
|
-
import { operators_d_exports } from "./
|
|
5
|
-
import { params_placeholders_d_exports } from "./
|
|
6
|
-
import { utils_d_exports } from "./
|
|
7
|
-
import { visitors_d_exports } from "./
|
|
1
|
+
import { ContextVariable, context_variables_d_exports } from "./context-variables.js";
|
|
2
|
+
import { Expression, ExpressionVisitor, ExpressionVisitorWithDefault, FieldExpression, FromRootExpression, FunctionCallExpression, MultiFieldAccess, OrderBy, Query, Select, SubQuery } from "./types.js";
|
|
3
|
+
import { ConvertResult, ExpressionToFilterBy, Operator, PatternNode } from "./filter-expression/types.js";
|
|
4
|
+
import { operators_d_exports } from "./filter-expression/operators.js";
|
|
5
|
+
import { params_placeholders_d_exports } from "./params-placeholders.js";
|
|
6
|
+
import { utils_d_exports } from "./utils.js";
|
|
7
|
+
import { visitors_d_exports } from "./visitors.js";
|
|
8
8
|
import "./index.js";
|
|
9
|
-
//#region index.d.ts
|
|
9
|
+
//#region src/index.d.ts
|
|
10
10
|
declare const filterExpression: {
|
|
11
11
|
findMatchedFilter: (filterExpression: Expression, params: Record<string, unknown>, operators: Array<Operator>, schema: import("@fibery/schema").Schema | null, type: string) => {
|
|
12
12
|
operator: Operator;
|
|
13
|
-
value:
|
|
13
|
+
value: unknown;
|
|
14
14
|
expression: Expression;
|
|
15
15
|
type: string;
|
|
16
16
|
id: string;
|
|
17
17
|
} | null;
|
|
18
18
|
operators: typeof operators_d_exports;
|
|
19
|
-
convertToExpression: (pattern: (
|
|
20
|
-
id: string;
|
|
21
|
-
value?: unknown;
|
|
22
|
-
} | {
|
|
23
|
-
"q/from"?: unknown;
|
|
24
|
-
"q/select"?: ( /*elided*/ any | {
|
|
25
|
-
id: string;
|
|
26
|
-
value?: unknown;
|
|
27
|
-
} | /*elided*/ any)[];
|
|
28
|
-
"q/where"?: ( /*elided*/ any | {
|
|
29
|
-
id: string;
|
|
30
|
-
value?: unknown;
|
|
31
|
-
} | /*elided*/ any)[];
|
|
32
|
-
"q/limit"?: unknown;
|
|
33
|
-
})[] | {
|
|
34
|
-
id: string;
|
|
35
|
-
value?: unknown;
|
|
36
|
-
} | {
|
|
37
|
-
"q/from"?: unknown;
|
|
38
|
-
"q/select"?: (any | {
|
|
39
|
-
id: string;
|
|
40
|
-
value?: unknown;
|
|
41
|
-
} | any)[];
|
|
42
|
-
"q/where"?: (any | {
|
|
43
|
-
id: string;
|
|
44
|
-
value?: unknown;
|
|
45
|
-
} | any)[];
|
|
46
|
-
"q/limit"?: unknown;
|
|
47
|
-
})[] | {
|
|
48
|
-
id: string;
|
|
49
|
-
value?: unknown;
|
|
50
|
-
} | {
|
|
51
|
-
"q/from"?: unknown;
|
|
52
|
-
"q/select"?: (any | {
|
|
53
|
-
id: string;
|
|
54
|
-
value?: unknown;
|
|
55
|
-
} | any)[];
|
|
56
|
-
"q/where"?: (any | {
|
|
57
|
-
id: string;
|
|
58
|
-
value?: unknown;
|
|
59
|
-
} | any)[];
|
|
60
|
-
"q/limit"?: unknown;
|
|
61
|
-
})[] | {
|
|
62
|
-
id: string;
|
|
63
|
-
value?: unknown;
|
|
64
|
-
} | {
|
|
65
|
-
"q/from"?: unknown;
|
|
66
|
-
"q/select"?: (any | {
|
|
67
|
-
id: string;
|
|
68
|
-
value?: unknown;
|
|
69
|
-
} | any)[];
|
|
70
|
-
"q/where"?: (any | {
|
|
71
|
-
id: string;
|
|
72
|
-
value?: unknown;
|
|
73
|
-
} | any)[];
|
|
74
|
-
"q/limit"?: unknown;
|
|
75
|
-
})[] | {
|
|
76
|
-
id: string;
|
|
77
|
-
value?: unknown;
|
|
78
|
-
} | {
|
|
79
|
-
"q/from"?: unknown;
|
|
80
|
-
"q/select"?: (any | {
|
|
81
|
-
id: string;
|
|
82
|
-
value?: unknown;
|
|
83
|
-
} | any)[];
|
|
84
|
-
"q/where"?: (any | {
|
|
85
|
-
id: string;
|
|
86
|
-
value?: unknown;
|
|
87
|
-
} | any)[];
|
|
88
|
-
"q/limit"?: unknown;
|
|
89
|
-
})[] | {
|
|
90
|
-
id: string;
|
|
91
|
-
value?: unknown;
|
|
92
|
-
} | {
|
|
93
|
-
"q/from"?: unknown;
|
|
94
|
-
"q/select"?: (any | {
|
|
95
|
-
id: string;
|
|
96
|
-
value?: unknown;
|
|
97
|
-
} | any)[];
|
|
98
|
-
"q/where"?: (any | {
|
|
99
|
-
id: string;
|
|
100
|
-
value?: unknown;
|
|
101
|
-
} | any)[];
|
|
102
|
-
"q/limit"?: unknown;
|
|
103
|
-
})[] | {
|
|
104
|
-
id: string;
|
|
105
|
-
value?: unknown;
|
|
106
|
-
} | {
|
|
107
|
-
"q/from"?: unknown;
|
|
108
|
-
"q/select"?: (any | {
|
|
109
|
-
id: string;
|
|
110
|
-
value?: unknown;
|
|
111
|
-
} | any)[];
|
|
112
|
-
"q/where"?: (any | {
|
|
113
|
-
id: string;
|
|
114
|
-
value?: unknown;
|
|
115
|
-
} | any)[];
|
|
116
|
-
"q/limit"?: unknown;
|
|
117
|
-
})[] | {
|
|
118
|
-
id: string;
|
|
119
|
-
value?: unknown;
|
|
120
|
-
} | {
|
|
121
|
-
"q/from"?: unknown;
|
|
122
|
-
"q/select"?: (any | {
|
|
123
|
-
id: string;
|
|
124
|
-
value?: unknown;
|
|
125
|
-
} | any)[];
|
|
126
|
-
"q/where"?: (any | {
|
|
127
|
-
id: string;
|
|
128
|
-
value?: unknown;
|
|
129
|
-
} | any)[];
|
|
130
|
-
"q/limit"?: unknown;
|
|
131
|
-
})[] | {
|
|
132
|
-
id: string;
|
|
133
|
-
value?: unknown;
|
|
134
|
-
} | {
|
|
135
|
-
"q/from"?: unknown;
|
|
136
|
-
"q/select"?: (any | {
|
|
137
|
-
id: string;
|
|
138
|
-
value?: unknown;
|
|
139
|
-
} | any)[];
|
|
140
|
-
"q/where"?: (any | {
|
|
141
|
-
id: string;
|
|
142
|
-
value?: unknown;
|
|
143
|
-
} | any)[];
|
|
144
|
-
"q/limit"?: unknown;
|
|
145
|
-
})[] | {
|
|
146
|
-
id: string;
|
|
147
|
-
value?: unknown;
|
|
148
|
-
} | {
|
|
149
|
-
"q/from"?: unknown;
|
|
150
|
-
"q/select"?: (any | {
|
|
151
|
-
id: string;
|
|
152
|
-
value?: unknown;
|
|
153
|
-
} | any)[];
|
|
154
|
-
"q/where"?: (any | {
|
|
155
|
-
id: string;
|
|
156
|
-
value?: unknown;
|
|
157
|
-
} | any)[];
|
|
158
|
-
"q/limit"?: unknown;
|
|
159
|
-
})[] | {
|
|
160
|
-
id: string;
|
|
161
|
-
value?: unknown;
|
|
162
|
-
} | {
|
|
163
|
-
"q/from"?: unknown;
|
|
164
|
-
"q/select"?: (any | {
|
|
165
|
-
id: string;
|
|
166
|
-
value?: unknown;
|
|
167
|
-
} | any)[];
|
|
168
|
-
"q/where"?: (any | {
|
|
169
|
-
id: string;
|
|
170
|
-
value?: unknown;
|
|
171
|
-
} | any)[];
|
|
172
|
-
"q/limit"?: unknown;
|
|
173
|
-
})[] | {
|
|
174
|
-
id: string;
|
|
175
|
-
value?: unknown;
|
|
176
|
-
} | {
|
|
177
|
-
"q/from"?: unknown;
|
|
178
|
-
"q/select"?: (any | {
|
|
179
|
-
id: string;
|
|
180
|
-
value?: unknown;
|
|
181
|
-
} | any)[];
|
|
182
|
-
"q/where"?: (any | {
|
|
183
|
-
id: string;
|
|
184
|
-
value?: unknown;
|
|
185
|
-
} | any)[];
|
|
186
|
-
"q/limit"?: unknown;
|
|
187
|
-
})[], filterExpression: Expression, value: string, getNextParamName: () => string) => {
|
|
188
|
-
expression: unknown[];
|
|
189
|
-
params: Record<string, unknown>;
|
|
190
|
-
};
|
|
19
|
+
convertToExpression: (pattern: PatternNode[], filterExpression: Expression, value: unknown, getNextParamName: () => string) => ConvertResult;
|
|
191
20
|
};
|
|
192
21
|
//#endregion
|
|
193
22
|
export { type ContextVariable, type Expression, type ExpressionToFilterBy, type ExpressionVisitor, type ExpressionVisitorWithDefault, type FieldExpression, type FromRootExpression, type FunctionCallExpression, type MultiFieldAccess, type Operator, type OrderBy, type Query, type Select, type SubQuery, context_variables_d_exports as contextVariables, filterExpression, params_placeholders_d_exports as paramsPlaceholders, utils_d_exports as utils, visitors_d_exports as visitors };
|
package/lib/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { context_variables_exports } from "./
|
|
2
|
-
import { utils_exports } from "./
|
|
3
|
-
import { findMatchedFilter } from "./
|
|
4
|
-
import { params_placeholders_exports } from "./
|
|
5
|
-
import { convertToExpression } from "./
|
|
6
|
-
import { operators_exports } from "./
|
|
7
|
-
import { visitors_exports } from "./
|
|
8
|
-
//#region index.ts
|
|
1
|
+
import { context_variables_exports } from "./context-variables.js";
|
|
2
|
+
import { utils_exports } from "./utils.js";
|
|
3
|
+
import { findMatchedFilter } from "./filter-expression/index.js";
|
|
4
|
+
import { params_placeholders_exports } from "./params-placeholders.js";
|
|
5
|
+
import { convertToExpression } from "./filter-expression/pattern-to-expression.js";
|
|
6
|
+
import { operators_exports } from "./filter-expression/operators.js";
|
|
7
|
+
import { visitors_exports } from "./visitors.js";
|
|
8
|
+
//#region src/index.ts
|
|
9
9
|
const filterExpression = {
|
|
10
10
|
findMatchedFilter,
|
|
11
11
|
operators: operators_exports,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { __exportAll } from "
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { NotImplementedError } from "./errors.js";
|
|
3
3
|
import uniqBy from "lodash/uniqBy.js";
|
|
4
4
|
import { isRecord, mapValues } from "@fibery/helpers/src/_";
|
|
5
5
|
import isPlainObject from "lodash/isPlainObject.js";
|
|
6
|
-
import isString from "lodash/isString.js";
|
|
7
6
|
import { assert } from "@fibery/helpers/utils/trace";
|
|
7
|
+
import isString from "lodash/isString.js";
|
|
8
8
|
import last from "lodash/last.js";
|
|
9
9
|
//#region src/utils.ts
|
|
10
10
|
var utils_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __exportAll } from "
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { createExpressionVisitor, firstLastFunctions, isCollectionFunctionExpression, isMultiFieldAccess, logicalOperators } from "./utils.js";
|
|
3
3
|
import { fieldAccessVisitorTypeAware } from "./field-expression-visitor-type-aware.js";
|
|
4
4
|
import { mapValues } from "@fibery/helpers/src/_";
|
package/package.json
CHANGED
|
@@ -1,62 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/expression-utils",
|
|
3
|
-
"version": "10.0.
|
|
4
|
-
"private": false,
|
|
3
|
+
"version": "10.0.2",
|
|
5
4
|
"description": "utils for working with fibery api expressions",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
6
|
"files": [
|
|
7
|
-
"
|
|
7
|
+
"lib"
|
|
8
8
|
],
|
|
9
9
|
"type": "module",
|
|
10
|
+
"sideEffects": false,
|
|
10
11
|
"main": "./lib/index.js",
|
|
12
|
+
"types": "./lib/index.d.ts",
|
|
11
13
|
"exports": {
|
|
12
14
|
".": {
|
|
13
|
-
"@fibery/source": "./index.ts",
|
|
14
15
|
"types": "./lib/index.d.ts",
|
|
15
16
|
"default": "./lib/index.js"
|
|
16
17
|
},
|
|
17
18
|
"./src/*": {
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
"default": "./src/*"
|
|
21
|
-
},
|
|
22
|
-
"types": "./lib/src/*.d.ts",
|
|
23
|
-
"default": "./lib/src/*.js"
|
|
19
|
+
"types": "./lib/*.d.ts",
|
|
20
|
+
"default": "./lib/*.js"
|
|
24
21
|
},
|
|
25
22
|
"./src/filter-expression": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"default": "./lib/src/filter-expression/index.js"
|
|
23
|
+
"types": "./lib/filter-expression/index.d.ts",
|
|
24
|
+
"default": "./lib/filter-expression/index.js"
|
|
29
25
|
}
|
|
30
26
|
},
|
|
31
27
|
"dependencies": {
|
|
32
28
|
"lodash": "4.17.21",
|
|
33
29
|
"moment": "2.29.4",
|
|
34
30
|
"uuid": "11.1.0",
|
|
35
|
-
"@fibery/helpers": "3.2.
|
|
36
|
-
},
|
|
37
|
-
"devDependencies": {
|
|
38
|
-
"@types/lodash": "4.14.172",
|
|
39
|
-
"tsdown": "0.22.7",
|
|
40
|
-
"typescript": "rc",
|
|
41
|
-
"@fibery/schema": "10.3.0"
|
|
31
|
+
"@fibery/helpers": "3.2.1"
|
|
42
32
|
},
|
|
43
33
|
"peerDependencies": {
|
|
44
|
-
"@fibery/schema": "10.3.
|
|
45
|
-
}
|
|
46
|
-
"size-limit": [
|
|
47
|
-
{
|
|
48
|
-
"path": "lib/**/*.js",
|
|
49
|
-
"limit": "22 kB"
|
|
50
|
-
}
|
|
51
|
-
],
|
|
52
|
-
"scripts": {
|
|
53
|
-
"build": "pnpm run typecheck && tsdown",
|
|
54
|
-
"test": "../../scripts/test.sh",
|
|
55
|
-
"test:ci": "../../scripts/test.sh --ci",
|
|
56
|
-
"test:coverage": "../../scripts/test.sh --ci --coverage",
|
|
57
|
-
"lint": "pnpm -w lint .",
|
|
58
|
-
"typecheck": "../../scripts/typecheck.sh",
|
|
59
|
-
"check": "../../scripts/check.sh"
|
|
60
|
-
},
|
|
61
|
-
"types": "./lib/index.d.ts"
|
|
34
|
+
"@fibery/schema": "10.3.1"
|
|
35
|
+
}
|
|
62
36
|
}
|