@nocobase/utils 2.0.0-alpha.36 → 2.0.0-alpha.38
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/assign.js +14 -1
- package/lib/common.js +6 -1
- package/lib/transformFilter.d.ts +1 -0
- package/lib/transformFilter.js +26 -2
- package/package.json +2 -2
package/lib/assign.js
CHANGED
|
@@ -45,7 +45,10 @@ var import_deepmerge = __toESM(require("deepmerge"));
|
|
|
45
45
|
var import_lodash = __toESM(require("lodash"));
|
|
46
46
|
var import_common = require("./common");
|
|
47
47
|
function getEnumerableOwnPropertySymbols(target) {
|
|
48
|
-
return Object.getOwnPropertySymbols ?
|
|
48
|
+
return Object.getOwnPropertySymbols ? (
|
|
49
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
50
|
+
Object.getOwnPropertySymbols(target).filter((symbol) => target.propertyIsEnumerable(symbol))
|
|
51
|
+
) : [];
|
|
49
52
|
}
|
|
50
53
|
__name(getEnumerableOwnPropertySymbols, "getEnumerableOwnPropertySymbols");
|
|
51
54
|
function getKeys(target) {
|
|
@@ -113,12 +116,22 @@ mergeStrategies.set("union", (x, y) => {
|
|
|
113
116
|
mergeStrategies.set(
|
|
114
117
|
"intersect",
|
|
115
118
|
(x, y) => (() => {
|
|
119
|
+
console.log("intersect inputs:", x, y);
|
|
116
120
|
if (typeof x === "string") {
|
|
117
121
|
x = x.split(",");
|
|
118
122
|
}
|
|
119
123
|
if (typeof y === "string") {
|
|
120
124
|
y = y.split(",");
|
|
121
125
|
}
|
|
126
|
+
if (typeof x === "object" && !Array.isArray(x)) {
|
|
127
|
+
x = Object.values(x || {});
|
|
128
|
+
}
|
|
129
|
+
if (typeof y === "object" && !Array.isArray(y)) {
|
|
130
|
+
y = Object.values(y || {});
|
|
131
|
+
}
|
|
132
|
+
if (!Array.isArray(x) || x.length === 0) {
|
|
133
|
+
return y || [];
|
|
134
|
+
}
|
|
122
135
|
if (!Array.isArray(x) || x.length === 0) {
|
|
123
136
|
return y || [];
|
|
124
137
|
}
|
package/lib/common.js
CHANGED
|
@@ -67,7 +67,7 @@ const isEmpty = /* @__PURE__ */ __name((value) => {
|
|
|
67
67
|
if (Array.isArray(value)) {
|
|
68
68
|
return value.length === 0;
|
|
69
69
|
}
|
|
70
|
-
return
|
|
70
|
+
return false;
|
|
71
71
|
}, "isEmpty");
|
|
72
72
|
const isPlainObject = /* @__PURE__ */ __name((value) => {
|
|
73
73
|
if (Object.prototype.toString.call(value) !== "[object Object]") {
|
|
@@ -154,6 +154,11 @@ const removeNullCondition = /* @__PURE__ */ __name((filter, customFlat = import_
|
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
const result = customFlat.unflatten(values);
|
|
157
|
+
for (const key in result) {
|
|
158
|
+
if (Array.isArray(result[key])) {
|
|
159
|
+
result[key] = result[key].filter((item) => item != null);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
157
162
|
return import_lodash.default.isEmpty(result) ? void 0 : result;
|
|
158
163
|
}, "removeNullCondition");
|
|
159
164
|
// Annotate the CommonJS export names for ESM import in node:
|
package/lib/transformFilter.d.ts
CHANGED
package/lib/transformFilter.js
CHANGED
|
@@ -28,11 +28,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
28
28
|
var transformFilter_exports = {};
|
|
29
29
|
__export(transformFilter_exports, {
|
|
30
30
|
evaluateConditions: () => evaluateConditions,
|
|
31
|
+
removeInvalidFilterItems: () => removeInvalidFilterItems,
|
|
31
32
|
transformFilter: () => transformFilter
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(transformFilter_exports);
|
|
35
|
+
var import_common = require("./common");
|
|
34
36
|
function isFilterCondition(item) {
|
|
35
|
-
return "path" in item && "operator" in item
|
|
37
|
+
return "path" in item && "operator" in item;
|
|
36
38
|
}
|
|
37
39
|
__name(isFilterCondition, "isFilterCondition");
|
|
38
40
|
function isFilterGroup(item) {
|
|
@@ -74,9 +76,30 @@ function transformFilter(filter) {
|
|
|
74
76
|
if (!Array.isArray(filter.items)) {
|
|
75
77
|
throw new Error("Invalid filter: items must be an array");
|
|
76
78
|
}
|
|
77
|
-
return transformGroup(filter);
|
|
79
|
+
return (0, import_common.removeNullCondition)(transformGroup(filter));
|
|
78
80
|
}
|
|
79
81
|
__name(transformFilter, "transformFilter");
|
|
82
|
+
function removeInvalidFilterItems(filter) {
|
|
83
|
+
if (!filter || typeof filter !== "object") {
|
|
84
|
+
throw new Error("Invalid filter: filter must be an object");
|
|
85
|
+
}
|
|
86
|
+
if (!isFilterGroup(filter)) {
|
|
87
|
+
throw new Error("Invalid filter: filter must have logic and items properties");
|
|
88
|
+
}
|
|
89
|
+
if (!Array.isArray(filter.items)) {
|
|
90
|
+
throw new Error("Invalid filter: items must be an array");
|
|
91
|
+
}
|
|
92
|
+
filter.items = filter.items.filter((item) => {
|
|
93
|
+
if (isFilterCondition(item)) {
|
|
94
|
+
return item.path && item.operator;
|
|
95
|
+
} else if (isFilterGroup(item)) {
|
|
96
|
+
return removeInvalidFilterItems(item);
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
});
|
|
100
|
+
return { ...filter };
|
|
101
|
+
}
|
|
102
|
+
__name(removeInvalidFilterItems, "removeInvalidFilterItems");
|
|
80
103
|
function evaluateCondition(condition, evaluator) {
|
|
81
104
|
const { path, operator, value } = condition;
|
|
82
105
|
return evaluator(path, operator, value);
|
|
@@ -124,5 +147,6 @@ __name(evaluateConditions, "evaluateConditions");
|
|
|
124
147
|
// Annotate the CommonJS export names for ESM import in node:
|
|
125
148
|
0 && (module.exports = {
|
|
126
149
|
evaluateConditions,
|
|
150
|
+
removeInvalidFilterItems,
|
|
127
151
|
transformFilter
|
|
128
152
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/utils",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.38",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -17,5 +17,5 @@
|
|
|
17
17
|
"multer": "^1.4.5-lts.2",
|
|
18
18
|
"object-path": "^0.11.8"
|
|
19
19
|
},
|
|
20
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "30b1723601099007f7641c6ffa4111c880cb44e4"
|
|
21
21
|
}
|