ais_auth_lib 1.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/dist/conditions.d.ts +4 -0
- package/dist/conditions.js +35 -0
- package/dist/filter.d.ts +2 -0
- package/dist/filter.js +25 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19 -0
- package/dist/interfaces/condition-group.d.ts +9 -0
- package/dist/interfaces/condition-group.js +2 -0
- package/dist/interfaces/condition.d.ts +10 -0
- package/dist/interfaces/condition.js +2 -0
- package/dist/interfaces/rule.d.ts +10 -0
- package/dist/interfaces/rule.js +2 -0
- package/package.json +13 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Condition } from "./interfaces/condition";
|
|
2
|
+
import { ConditionGroup } from "./interfaces/condition-group";
|
|
3
|
+
export declare function evaluateCondition(obj: any, condition: Condition): any;
|
|
4
|
+
export declare function evaluateConditionGroup(obj: any, group: ConditionGroup): any;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evaluateConditionGroup = exports.evaluateCondition = void 0;
|
|
4
|
+
function evaluateCondition(obj, condition) {
|
|
5
|
+
const { attribute, value, operator } = condition;
|
|
6
|
+
switch (operator) {
|
|
7
|
+
case "Равно":
|
|
8
|
+
return obj[attribute] === value;
|
|
9
|
+
case "Не равно":
|
|
10
|
+
return obj[attribute] !== value;
|
|
11
|
+
case "Содержит":
|
|
12
|
+
return obj[attribute].includes(value);
|
|
13
|
+
case "Не содержит":
|
|
14
|
+
return !obj[attribute].includes(value);
|
|
15
|
+
default:
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.evaluateCondition = evaluateCondition;
|
|
20
|
+
function evaluateConditionGroup(obj, group) {
|
|
21
|
+
const { conditions } = group;
|
|
22
|
+
let result = evaluateCondition(obj, conditions[0]);
|
|
23
|
+
for (let i = 1; i < conditions.length; i++) {
|
|
24
|
+
const condition = conditions[i];
|
|
25
|
+
const currentResult = evaluateCondition(obj, condition);
|
|
26
|
+
if (condition.logicalCondition === "ИЛИ") {
|
|
27
|
+
result = result || currentResult;
|
|
28
|
+
}
|
|
29
|
+
else if (condition.logicalCondition === "И") {
|
|
30
|
+
result = result && currentResult;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
exports.evaluateConditionGroup = evaluateConditionGroup;
|
package/dist/filter.d.ts
ADDED
package/dist/filter.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.filterObjects = void 0;
|
|
4
|
+
const conditions_1 = require("./conditions");
|
|
5
|
+
function filterObjects(objects, rules) {
|
|
6
|
+
return objects.filter((obj) => {
|
|
7
|
+
let overallResult = false;
|
|
8
|
+
for (const rule of rules) {
|
|
9
|
+
let ruleResult = (0, conditions_1.evaluateConditionGroup)(obj, rule.conditionGroups[0]);
|
|
10
|
+
for (let i = 1; i < rule.conditionGroups.length; i++) {
|
|
11
|
+
const group = rule.conditionGroups[i];
|
|
12
|
+
const currentResult = (0, conditions_1.evaluateConditionGroup)(obj, group);
|
|
13
|
+
if (group.logicalCondition === "ИЛИ") {
|
|
14
|
+
ruleResult = ruleResult || currentResult;
|
|
15
|
+
}
|
|
16
|
+
else if (group.logicalCondition === "И") {
|
|
17
|
+
ruleResult = ruleResult && currentResult;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
overallResult = overallResult || ruleResult;
|
|
21
|
+
}
|
|
22
|
+
return overallResult;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
exports.filterObjects = filterObjects;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./conditions"), exports);
|
|
18
|
+
__exportStar(require("./filter"), exports);
|
|
19
|
+
__exportStar(require("./interfaces/rule"), exports);
|