kgrapgh-logic-engine 1.0.1
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/AssemblyLaw.js +5 -0
- package/DistributionLaw.js +12 -0
- package/Map.js +9 -0
- package/experince.js +30 -0
- package/fotmater.js +10 -0
- package/kgraph.js +27 -0
- package/kmap.js +22 -0
- package/package.json +10 -0
- package/pathGenerator.js +8 -0
- package/success.js +6 -0
- package/totalpath.js +5 -0
package/AssemblyLaw.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { assemblyLaw } from "./AssemblyLaw.js";
|
|
2
|
+
import { pathGenerator } from "./pathGenerator.js";
|
|
3
|
+
|
|
4
|
+
export const distributionLaw = (nodes) => {
|
|
5
|
+
const values = assemblyLaw(nodes);
|
|
6
|
+
const pathSize = Math.floor(values.length / 3);
|
|
7
|
+
const pathA = pathGenerator(values, pathSize, 0);
|
|
8
|
+
const pathB = pathGenerator(values, pathSize, 1);
|
|
9
|
+
const pathC = pathGenerator(values, pathSize, 2);
|
|
10
|
+
return [pathA, pathB, pathC];
|
|
11
|
+
}
|
|
12
|
+
|
package/Map.js
ADDED
package/experince.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { K_Graph } from "./kgraph.js";
|
|
2
|
+
|
|
3
|
+
const userData = {
|
|
4
|
+
name: "Mido",
|
|
5
|
+
age: 20,
|
|
6
|
+
experience: 4,
|
|
7
|
+
isProfessional: true,
|
|
8
|
+
projectsCount: 5,
|
|
9
|
+
city: "Cairo",
|
|
10
|
+
hasLaptop: true,
|
|
11
|
+
englishLevel: "B2",
|
|
12
|
+
remoteOk: true,
|
|
13
|
+
availability: "Full-time"
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const userSchema = [
|
|
17
|
+
{ id: "R1", key: "age", test: (v) => v >= 18, message: "السن صغير" },
|
|
18
|
+
{ id: "R2", key: "experience", test: (v) => v >= 3, message: "الخبرة قليلة" },
|
|
19
|
+
{ id: "R3", key: "isProfessional", test: (v) => v === true, message: "غير محترف" },
|
|
20
|
+
{ id: "R4", key: "projectsCount", test: (v) => v > 2, message: "مشاريعك قليلة" },
|
|
21
|
+
{ id: "R5", key: "city", test: (v) => v === "Cairo", message: "خارج القاهرة" },
|
|
22
|
+
{ id: "R6", key: "hasLaptop", test: (v) => v === true, message: "محتاج لاب توب" },
|
|
23
|
+
{ id: "R7", key: "englishLevel", test: (v) => v !== "A1", message: "مستوى الإنجليزي ضعيف" },
|
|
24
|
+
{ id: "R8", key: "remoteOk", test: (v) => v === true, message: "لازم توافق على الـ Remote" },
|
|
25
|
+
{ id: "R9", key: "availability", test: (v) => v === "Full-time", message: "محتاجين تفرغ كامل" },
|
|
26
|
+
{ id: "R10", key: "name", test: (v) => v.length > 2, message: "الاسم قصير جداً" }
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const result = K_Graph(userData, userSchema);
|
|
30
|
+
console.log((result));
|
package/fotmater.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { logicRegisterd } from "./kmap.js";
|
|
2
|
+
|
|
3
|
+
export const createJsonReport = (nodes) => {
|
|
4
|
+
const isPassed = logicRegisterd(nodes);
|
|
5
|
+
const report = {
|
|
6
|
+
logic_summary: isPassed ? 'OK' : 'FAIL',
|
|
7
|
+
timestamp: new Date().toISOString()
|
|
8
|
+
};
|
|
9
|
+
return JSON.parse(JSON.stringify(report));
|
|
10
|
+
}
|
package/kgraph.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// K-Graph Library
|
|
2
|
+
|
|
3
|
+
import { MapGraph } from "./Map.js";
|
|
4
|
+
import { createJsonReport } from "./fotmater.js";
|
|
5
|
+
import { KMap } from "./kmap.js";
|
|
6
|
+
import { successMathimaticsLaw } from "./success.js";
|
|
7
|
+
export const K_Graph = (data, schema) => {
|
|
8
|
+
|
|
9
|
+
const nodes = MapGraph(rules => ({
|
|
10
|
+
id: rules?.id,
|
|
11
|
+
active: rules?.test(data[rules?.key]),
|
|
12
|
+
message: rules?.message,
|
|
13
|
+
}), schema);
|
|
14
|
+
|
|
15
|
+
const isPassed = KMap(nodes);
|
|
16
|
+
return {
|
|
17
|
+
success: successMathimaticsLaw(isPassed, !isPassed),
|
|
18
|
+
status: isPassed ? "accepted" : "rejected",
|
|
19
|
+
trace: MapGraph(n => `${n.id}: ${n.active ? 'OK' : 'FAIL'}`, nodes),
|
|
20
|
+
data: createJsonReport(nodes),
|
|
21
|
+
errors: MapGraph(n => n.active ? null : n.message, nodes).filter(m => m !== null)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
package/kmap.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
import { totalPath } from "./totalpath.js";
|
|
3
|
+
const validation = (value) => {
|
|
4
|
+
if (value.length === 0) return true;
|
|
5
|
+
const [head, ...tail] = value;
|
|
6
|
+
return head && validation(tail);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const RegisteredOfficer = (nodes) => {
|
|
10
|
+
return totalPath(nodes).flat();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const logicRegisterd = (nodes) => {
|
|
14
|
+
const values = RegisteredOfficer(nodes);
|
|
15
|
+
return validation(values);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const KMap = (nodes) => {
|
|
19
|
+
return logicRegisterd(nodes);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { KMap, logicRegisterd, };
|
package/package.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kgrapgh-logic-engine",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A smart logic engine for data validation using Graph concepts",
|
|
5
|
+
"keywords": ["kgraph", "graph", "validation", "logic", "data"],
|
|
6
|
+
"author": "Mohamed Medhat",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "kgraph.js",
|
|
9
|
+
"license": "ISC"
|
|
10
|
+
}
|
package/pathGenerator.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
|
|
2
|
+
const mathCeli = (a, b) => {
|
|
3
|
+
return Math.floor((a + b - 1) / b);
|
|
4
|
+
}
|
|
5
|
+
export const pathGenerator = (values, pathSize, modValue) => {
|
|
6
|
+
const numberOfPath = mathCeli(values.length, pathSize);
|
|
7
|
+
return values.filter((_, i) => i % numberOfPath === modValue).slice(0, pathSize);
|
|
8
|
+
}
|
package/success.js
ADDED