theprogrammablemind_4wp 9.3.0-beta.52 → 9.3.0-beta.54
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/client.js +7 -2
- package/package.json +2 -1
- package/src/project2.js +54 -0
package/client.js
CHANGED
@@ -4,6 +4,7 @@ const { Config } = require('./src/config')
|
|
4
4
|
const { loadInstance, setupArgs, gs, processContext, getObjects, setupProcessB, processContextsB } = require('./src/configHelpers')
|
5
5
|
const Digraph = require('./src/digraph')
|
6
6
|
const { project } = require('./src/project')
|
7
|
+
const { project:project2 } = require('./src/project2')
|
7
8
|
const fetch = require('node-fetch')
|
8
9
|
const base64 = require('base-64')
|
9
10
|
const deepEqual = require('deep-equal')
|
@@ -50,7 +51,7 @@ const getConfig_getContextCheck = (testConfig) => {
|
|
50
51
|
}
|
51
52
|
|
52
53
|
const pickContext = (testConfig) => (context) => {
|
53
|
-
return
|
54
|
+
return project2(context, getConfig_getContextCheck(testConfig))
|
54
55
|
}
|
55
56
|
|
56
57
|
const pickObjects = (config, testConfig, getObjects) => {
|
@@ -68,7 +69,11 @@ const pickObjects = (config, testConfig, getObjects) => {
|
|
68
69
|
if (!objects) {
|
69
70
|
throw new Error(`In the checks for ${config.name} the KM ${km} does not exist`)
|
70
71
|
}
|
71
|
-
|
72
|
+
if (checks[km] && checks[km].find((check) => check.match && check.apply)) {
|
73
|
+
projection[km] = project2(objects, checks[km])
|
74
|
+
} else {
|
75
|
+
projection[km] = project(objects, checks[km])
|
76
|
+
}
|
72
77
|
}
|
73
78
|
return projection
|
74
79
|
}
|
package/package.json
CHANGED
@@ -53,6 +53,7 @@
|
|
53
53
|
"src/digraph_internal.js",
|
54
54
|
"src/generators.js",
|
55
55
|
"src/project.js",
|
56
|
+
"src/project2.js",
|
56
57
|
"src/semantics.js"
|
57
58
|
],
|
58
59
|
"author": "dev@thinktelligence.com",
|
@@ -69,6 +70,6 @@
|
|
69
70
|
"sort-json": "^2.0.0",
|
70
71
|
"uuid": "^8.3.2"
|
71
72
|
},
|
72
|
-
"version": "9.3.0-beta.
|
73
|
+
"version": "9.3.0-beta.54",
|
73
74
|
"license": "UNLICENSED"
|
74
75
|
}
|
package/src/project2.js
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
function project(source, filters) {
|
2
|
+
if (['string', 'number'].includes(typeof source)) {
|
3
|
+
return source
|
4
|
+
}
|
5
|
+
|
6
|
+
if (Object.keys(source).length === 0 && filters.length === 0) {
|
7
|
+
return {};
|
8
|
+
}
|
9
|
+
|
10
|
+
// Find the applicable filter for the current context
|
11
|
+
const filter = filters.find(f => f.match({ context: source }));
|
12
|
+
if (!filter) {
|
13
|
+
if (Array.isArray(source)) {
|
14
|
+
return source.map((element) => project(element, filters))
|
15
|
+
}
|
16
|
+
return {};
|
17
|
+
}
|
18
|
+
|
19
|
+
// Get the properties to include from the apply function
|
20
|
+
let properties = filter.apply();
|
21
|
+
|
22
|
+
// update
|
23
|
+
const updatedProperties = []
|
24
|
+
for (const property of properties) {
|
25
|
+
if (property.properties) {
|
26
|
+
for (const moreProperty of source[property.properties] || []) {
|
27
|
+
updatedProperties.push(moreProperty)
|
28
|
+
}
|
29
|
+
} else {
|
30
|
+
updatedProperties.push(property)
|
31
|
+
}
|
32
|
+
}
|
33
|
+
properties = updatedProperties
|
34
|
+
|
35
|
+
// Build the result object
|
36
|
+
const result = {};
|
37
|
+
properties.forEach(prop => {
|
38
|
+
if (source.hasOwnProperty(prop)) {
|
39
|
+
// If the property is an object and not null, recursively project it
|
40
|
+
if (typeof source[prop] === 'object' && source[prop] !== null) {
|
41
|
+
result[prop] = project(source[prop], filters);
|
42
|
+
} else {
|
43
|
+
// Copy primitive or null properties directly
|
44
|
+
result[prop] = source[prop];
|
45
|
+
}
|
46
|
+
}
|
47
|
+
});
|
48
|
+
|
49
|
+
return result;
|
50
|
+
}
|
51
|
+
|
52
|
+
module.exports = {
|
53
|
+
project
|
54
|
+
}
|