@fibery/expression-utils 14.0.0 → 15.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/types.d.ts +3 -2
- package/lib/visitors.d.ts +3 -3
- package/lib/visitors.js +13 -13
- package/package.json +3 -3
package/lib/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EntityId, PublicId } from "@fibery/schema";
|
|
1
2
|
//#region src/types.d.ts
|
|
2
3
|
type MultiFieldAccess = [string, string];
|
|
3
4
|
type FieldExpression = Array<string | MultiFieldAccess>;
|
|
@@ -48,10 +49,10 @@ type ExpressionVisitor = {
|
|
|
48
49
|
};
|
|
49
50
|
type ExpressionVisitorWithDefault = Required<ExpressionVisitor>;
|
|
50
51
|
type FiberyIdentity = {
|
|
51
|
-
"fibery/id":
|
|
52
|
+
"fibery/id": EntityId;
|
|
52
53
|
};
|
|
53
54
|
type FiberyAutocompletes = {
|
|
54
|
-
"fibery/public-id"?:
|
|
55
|
+
"fibery/public-id"?: PublicId;
|
|
55
56
|
"fibery/rank"?: number;
|
|
56
57
|
__NOTHING_INTERESTING__TitleField__?: string;
|
|
57
58
|
};
|
package/lib/visitors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Expression, ExpressionVisitor, FieldExpression } from "./types.js";
|
|
1
|
+
import { Expression, ExpressionVisitor, FieldExpression, MultiFieldAccess } from "./types.js";
|
|
2
2
|
import { fieldAccessVisitorTypeAware } from "./field-expression-visitor-type-aware.js";
|
|
3
3
|
import { FieldId, TypeObject } from "@fibery/schema";
|
|
4
4
|
declare namespace visitors_d_exports {
|
|
@@ -6,7 +6,7 @@ declare namespace visitors_d_exports {
|
|
|
6
6
|
}
|
|
7
7
|
type OnFieldNotFoundInNamesTerms = (params: {
|
|
8
8
|
fieldExpressionInNamesTerms: FieldExpression;
|
|
9
|
-
fieldId: FieldId;
|
|
9
|
+
fieldId: FieldId | MultiFieldAccess;
|
|
10
10
|
currentTypeObject: TypeObject | null;
|
|
11
11
|
expression: FieldExpression;
|
|
12
12
|
}) => {
|
|
@@ -40,7 +40,7 @@ declare const getExpressionType: ({ expression, typeObject, functionsMeta, onFie
|
|
|
40
40
|
}>;
|
|
41
41
|
onFieldNotFound?: ({ currentTypeObject, fieldId }: {
|
|
42
42
|
currentTypeObject: TypeObject | null;
|
|
43
|
-
fieldId: FieldId;
|
|
43
|
+
fieldId: FieldId | MultiFieldAccess;
|
|
44
44
|
}) => {
|
|
45
45
|
currentTypeObject: TypeObject | null;
|
|
46
46
|
};
|
package/lib/visitors.js
CHANGED
|
@@ -121,6 +121,15 @@ const replaceNamesWithIdsVisitor = (typeObject, onFieldNotFound = defaultNamesWi
|
|
|
121
121
|
onFieldNotFound
|
|
122
122
|
}), "fieldExpressionInIdsTerms");
|
|
123
123
|
};
|
|
124
|
+
const resolveFieldExpressionTypeObject = (typeObject, expression) => expression.reduce((holderTypeObject, field) => {
|
|
125
|
+
const fieldObject = holderTypeObject ? holderTypeObject.getFieldObjectByName(isMultiFieldAccess(field) ? field[0] : field) : void 0;
|
|
126
|
+
if (!fieldObject) return null;
|
|
127
|
+
if (isMultiFieldAccess(field)) {
|
|
128
|
+
const type = field[1];
|
|
129
|
+
return fieldObject.multiRelatedFieldObjects.find((f) => f.holderType === type)?.holderTypeObject ?? null;
|
|
130
|
+
}
|
|
131
|
+
return fieldObject.typeObject;
|
|
132
|
+
}, typeObject);
|
|
124
133
|
const deleteExpressionsWithNotFoundFieldsVisitor = (typeObject) => {
|
|
125
134
|
const visitor = createExpressionVisitor({
|
|
126
135
|
visitFunctionCallExpression: ([fnName, ...args]) => {
|
|
@@ -131,16 +140,7 @@ const deleteExpressionsWithNotFoundFieldsVisitor = (typeObject) => {
|
|
|
131
140
|
} else return argsNew.length === args.length ? [fnName, ...argsNew] : null;
|
|
132
141
|
},
|
|
133
142
|
visitFieldExpression: (expression) => {
|
|
134
|
-
return
|
|
135
|
-
const fieldObject = holderTypeObject ? holderTypeObject.getFieldObjectByName(isMultiFieldAccess(field) ? field[0] : field) : void 0;
|
|
136
|
-
if (fieldObject && isMultiFieldAccess(field)) {
|
|
137
|
-
const type = field[1];
|
|
138
|
-
const nextTypeObject = fieldObject.multiRelatedFieldObjects.find((f) => f.holderType === type)?.holderTypeObject;
|
|
139
|
-
if (!nextTypeObject) return null;
|
|
140
|
-
return nextTypeObject;
|
|
141
|
-
} else if (fieldObject) return fieldObject.typeObject;
|
|
142
|
-
else return null;
|
|
143
|
-
}, typeObject) && expression;
|
|
143
|
+
return resolveFieldExpressionTypeObject(typeObject, expression) && expression;
|
|
144
144
|
},
|
|
145
145
|
visitOrderByExpression: (orderByExpression) => {
|
|
146
146
|
return orderByExpression.map((x) => {
|
|
@@ -155,7 +155,7 @@ const deleteExpressionsWithNotFoundFieldsVisitor = (typeObject) => {
|
|
|
155
155
|
},
|
|
156
156
|
visitQueryExpression: (subQueryExpression) => {
|
|
157
157
|
const { "q/from": fromExpression, "q/select": selectExpression, "q/where": whereExpression, "q/order-by": orderByExpression } = subQueryExpression;
|
|
158
|
-
const subQueryTypeObject =
|
|
158
|
+
const subQueryTypeObject = resolveFieldExpressionTypeObject(typeObject, fromExpression);
|
|
159
159
|
if (subQueryTypeObject) {
|
|
160
160
|
const subQueryVisitor = deleteExpressionsWithNotFoundFieldsVisitor(subQueryTypeObject);
|
|
161
161
|
const subQueryExpressionNew = pickBy({
|
|
@@ -165,8 +165,8 @@ const deleteExpressionsWithNotFoundFieldsVisitor = (typeObject) => {
|
|
|
165
165
|
...whereExpression ? { "q/where": subQueryVisitor.visitExpression(whereExpression) } : null,
|
|
166
166
|
...orderByExpression ? { "q/order-by": subQueryVisitor.visitOrderByExpression(orderByExpression) } : null
|
|
167
167
|
});
|
|
168
|
-
const { "q/select": selectExpressionNew } = subQueryExpressionNew;
|
|
169
|
-
return selectExpressionNew ? subQueryExpressionNew : null;
|
|
168
|
+
const { "q/from": fromExpressionNew, "q/select": selectExpressionNew } = subQueryExpressionNew;
|
|
169
|
+
return fromExpressionNew && selectExpressionNew ? subQueryExpressionNew : null;
|
|
170
170
|
} else return null;
|
|
171
171
|
}
|
|
172
172
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/expression-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "15.0.0",
|
|
4
4
|
"description": "utils for working with fibery api expressions",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"files": [
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"lodash": "4.17.21",
|
|
29
29
|
"moment": "2.29.4",
|
|
30
30
|
"uuid": "11.1.0",
|
|
31
|
-
"@fibery/helpers": "
|
|
31
|
+
"@fibery/helpers": "4.0.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@fibery/schema": "
|
|
34
|
+
"@fibery/schema": "12.0.0"
|
|
35
35
|
}
|
|
36
36
|
}
|