theprogrammablemind 9.5.1-beta.30 → 9.5.1-beta.31
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 +55 -19
- package/package.json +1 -1
- package/src/config.js +25 -5
- package/src/project2.js +48 -5
package/client.js
CHANGED
|
@@ -45,23 +45,13 @@ const getSuggestionMessage = (suggestion) => {
|
|
|
45
45
|
return `Try adding this to the associations: { context: ${JSON.stringify(getSuggestion(suggestion))}, choose: <indexOfMainElement> },\n If that does not work look at the logs and check when the operators become wrong during an interation. Deduce the change based on the previous iteration and what operator was applied.`
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
const getConfig_getContextCheck = (testConfig) => {
|
|
49
|
-
return (testConfig.checks && testConfig.checks.context) || []
|
|
50
|
-
}
|
|
51
|
-
|
|
52
48
|
const pickContext = (contextChecks) => (context) => {
|
|
53
49
|
return project2(context, contextChecks)
|
|
54
50
|
}
|
|
55
51
|
|
|
56
52
|
const pickObjects = (config, testConfig, getObjects) => {
|
|
57
|
-
/*
|
|
58
|
-
let testConfigName = config.name
|
|
59
|
-
if (testConfig.testModuleName) {
|
|
60
|
-
objects = getObjects(config.config.objects)(config.getConfigs()[testConfig.testModuleName].uuid)
|
|
61
|
-
testConfigName = testConfig.testModuleName
|
|
62
|
-
}
|
|
63
|
-
*/
|
|
64
53
|
const checks = getConfig_getObjectsCheck(config, testConfig)
|
|
54
|
+
const contextChecks = config.getContextChecks()
|
|
65
55
|
const projection = {}
|
|
66
56
|
for (const km in checks) {
|
|
67
57
|
const objects = getObjects(km)
|
|
@@ -69,10 +59,19 @@ const pickObjects = (config, testConfig, getObjects) => {
|
|
|
69
59
|
throw new Error(`In the checks for ${config.name} the KM ${km} does not exist`)
|
|
70
60
|
}
|
|
71
61
|
|
|
72
|
-
if (
|
|
73
|
-
|
|
62
|
+
if (false) {
|
|
63
|
+
if (checks[km] && checks[km].find((check) => check.match && check.apply)) {
|
|
64
|
+
projection[km] = project2(objects, checks[km])
|
|
65
|
+
} else {
|
|
66
|
+
projection[km] = project(objects, checks[km])
|
|
67
|
+
}
|
|
74
68
|
} else {
|
|
75
|
-
|
|
69
|
+
const lastIndex = contextChecks.length - 1
|
|
70
|
+
const last = contextChecks[lastIndex]
|
|
71
|
+
contextChecks[lastIndex] = { match: last.match, apply: () => [...new Set([...(checks[km] || []), ...last.apply()])] }
|
|
72
|
+
|
|
73
|
+
// projection[km] = project2(objects, [...checks[km], ...contextChecks])
|
|
74
|
+
projection[km] = project2(objects, contextChecks)
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
77
|
return projection
|
|
@@ -841,7 +840,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
|
|
|
841
840
|
}
|
|
842
841
|
console.log(responses.trace)
|
|
843
842
|
|
|
844
|
-
if (
|
|
843
|
+
if (false) {
|
|
845
844
|
if (global.beforeObjects) {
|
|
846
845
|
console.log('objects', runtime.jsonDiff.diffString(global.beforeObjects, config.get('objects')))
|
|
847
846
|
} else {
|
|
@@ -1327,13 +1326,32 @@ const knowledgeModuleImpl = async ({
|
|
|
1327
1326
|
parser.add_argument('-cl', '--checkForLoop', { nargs: '?', help: 'Check for loops in the priorities, Optional argument is list of operator keys to consider. For example [["banana", 0], ["food", 1]]' })
|
|
1328
1327
|
parser.add_argument('-r', '--reset', { action: 'store_true', help: 'Get the server to bypass the cache and rebuild everything' })
|
|
1329
1328
|
parser.add_argument('-q', '--query', { help: 'Run the specified query' })
|
|
1329
|
+
parser.add_argument('-f', '--filter', { help: 'for -pd only the data for the knowledge modules that start with this string will be shown' })
|
|
1330
1330
|
parser.add_argument('-ip ', '--server', { help: 'Server to run against' })
|
|
1331
1331
|
parser.add_argument('-qp ', '--queryParams', { help: 'Query params for the server call' })
|
|
1332
1332
|
parser.add_argument('-dt', '--deleteTest', { help: 'Delete the specified query from the tests file.' })
|
|
1333
1333
|
parser.add_argument('--parenthesized', { action: 'store_true', help: 'Show the generated phrases with parenthesis.' })
|
|
1334
1334
|
parser.add_argument('-c', '--clean', { help: 'Remove data from the test files. a === association' })
|
|
1335
1335
|
parser.add_argument('-od', '--objectDiff', { action: 'store_true', help: 'When showing the objects use a colour diff' })
|
|
1336
|
-
parser.add_argument('-p', '--print', { help:
|
|
1336
|
+
parser.add_argument('-p', '--print', { help:
|
|
1337
|
+
`Print the specified elements
|
|
1338
|
+
a === associations
|
|
1339
|
+
b === bridges,
|
|
1340
|
+
c === config,
|
|
1341
|
+
cc === test checks,
|
|
1342
|
+
d === objects (d for data),
|
|
1343
|
+
g === generators,
|
|
1344
|
+
h === hierarchy,
|
|
1345
|
+
ha === hierarchy ancestors,
|
|
1346
|
+
j === JSON sent to server,
|
|
1347
|
+
l === load ordering,
|
|
1348
|
+
o === operators,
|
|
1349
|
+
p === priorities,
|
|
1350
|
+
s === semantics,
|
|
1351
|
+
t === tests ordering,
|
|
1352
|
+
w === words,
|
|
1353
|
+
for example --print wb' })
|
|
1354
|
+
` })
|
|
1337
1355
|
parser.add_argument('-s', '--save', { action: 'store_true', help: 'When running with the --query flag this will save the current run to the test file. When running without the --query flag all tests will be run and resaved.' })
|
|
1338
1356
|
parser.add_argument('-fr', '--failRebuild', { action: 'store_true', help: 'If a rebuild is required fail out.' })
|
|
1339
1357
|
parser.add_argument('-sd', '--saveDeveloper', { action: 'store_true', help: 'Same as -s but the query will not show up in the info command.' })
|
|
@@ -1494,6 +1512,12 @@ const knowledgeModuleImpl = async ({
|
|
|
1494
1512
|
counter += 1
|
|
1495
1513
|
}
|
|
1496
1514
|
}
|
|
1515
|
+
if (hasArg('cc')) {
|
|
1516
|
+
for (const cc of config.getContextChecks()) {
|
|
1517
|
+
const printable = { ...cc, match: cc.match.toString(), apply: cc.apply.toString() }
|
|
1518
|
+
console.log(JSON.stringify(printable, null, 2))
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1497
1521
|
if (hasArg('c')) {
|
|
1498
1522
|
const { data } = setupProcessB({ config })
|
|
1499
1523
|
console.log('Config as sent to server')
|
|
@@ -1557,8 +1581,19 @@ const knowledgeModuleImpl = async ({
|
|
|
1557
1581
|
}
|
|
1558
1582
|
|
|
1559
1583
|
if (hasArg('d')) {
|
|
1560
|
-
|
|
1561
|
-
|
|
1584
|
+
if (args.filter) {
|
|
1585
|
+
console.log(`objects (data) filtered by ${args.filter} ================`)
|
|
1586
|
+
const projection = { namespaced: {} }
|
|
1587
|
+
for (const key of Object.keys(config.config.objects.namespaced)) {
|
|
1588
|
+
if (key.startsWith(args.filter)) {
|
|
1589
|
+
projection.namespaced[key] = config.config.objects.namespaced[key]
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
console.log(JSON.stringify(projection, null, 2))
|
|
1593
|
+
} else {
|
|
1594
|
+
console.log('objects (data) ================')
|
|
1595
|
+
console.log(JSON.stringify(config.config.objects, null, 2))
|
|
1596
|
+
}
|
|
1562
1597
|
}
|
|
1563
1598
|
|
|
1564
1599
|
if (hasArg('p')) {
|
|
@@ -2044,5 +2079,6 @@ module.exports = {
|
|
|
2044
2079
|
gs,
|
|
2045
2080
|
flattens,
|
|
2046
2081
|
writeTest,
|
|
2047
|
-
getConfigForTest
|
|
2082
|
+
getConfigForTest,
|
|
2083
|
+
debug,
|
|
2048
2084
|
}
|
package/package.json
CHANGED
package/src/config.js
CHANGED
|
@@ -346,6 +346,8 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
|
346
346
|
config.testConfig.checks.context = []
|
|
347
347
|
}
|
|
348
348
|
config.testConfig.checks.context.push({
|
|
349
|
+
'bridge.id': bridge.id,
|
|
350
|
+
'bridge.check': bridge.check,
|
|
349
351
|
match: ({context}) => context.marker == bridge.id,
|
|
350
352
|
exported: true,
|
|
351
353
|
apply: ({context}) => bridge.check,
|
|
@@ -2785,19 +2787,37 @@ class Config {
|
|
|
2785
2787
|
|
|
2786
2788
|
getContextChecks() {
|
|
2787
2789
|
const allChecks = []
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
for (const
|
|
2791
|
-
|
|
2792
|
-
|
|
2790
|
+
let defaults = () => []
|
|
2791
|
+
if (this.loadOrdering) {
|
|
2792
|
+
for (const name of this.loadOrdering) {
|
|
2793
|
+
const checks = this.kms[name].testConfig?.checks?.context || []
|
|
2794
|
+
const oldDefaults = defaults
|
|
2795
|
+
for (const check of checks) {
|
|
2796
|
+
if (!check.match) {
|
|
2797
|
+
const oldDefaults = defaults
|
|
2798
|
+
defaults = () => [...new Set([...check.apply(), ...oldDefaults()])]
|
|
2799
|
+
continue
|
|
2800
|
+
}
|
|
2801
|
+
if (check.exported) {
|
|
2802
|
+
allChecks.push(check)
|
|
2803
|
+
}
|
|
2793
2804
|
}
|
|
2794
2805
|
}
|
|
2795
2806
|
}
|
|
2796
2807
|
for (const check of this.testConfig?.checks?.context || []) {
|
|
2808
|
+
if (!check.match) {
|
|
2809
|
+
const oldDefaults = defaults
|
|
2810
|
+
defaults = () => [...new Set([...check.apply(), ...oldDefaults()])]
|
|
2811
|
+
continue
|
|
2812
|
+
}
|
|
2797
2813
|
if (!check.exported) {
|
|
2798
2814
|
allChecks.push(check)
|
|
2799
2815
|
}
|
|
2800
2816
|
}
|
|
2817
|
+
allChecks.push({
|
|
2818
|
+
match: () => true,
|
|
2819
|
+
apply: defaults
|
|
2820
|
+
})
|
|
2801
2821
|
return allChecks
|
|
2802
2822
|
}
|
|
2803
2823
|
|
package/src/project2.js
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
|
-
function
|
|
1
|
+
function areFirstNEqual(arr1, arr2, n) {
|
|
2
|
+
if (n <= 0) return true;
|
|
3
|
+
if (arr1.length < n || arr2.length < n) return false;
|
|
4
|
+
|
|
5
|
+
for (let i = 0; i < n; i++) {
|
|
6
|
+
if (arr1[i] !== arr2[i]) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function project(source, filters, path=[]) {
|
|
2
14
|
if (['string', 'number'].includes(typeof source)) {
|
|
3
15
|
return source
|
|
4
16
|
}
|
|
5
|
-
|
|
17
|
+
if (Array.isArray(source)) {
|
|
18
|
+
const result = []
|
|
19
|
+
for (const value of source) {
|
|
20
|
+
result.push(project(value, filters, [...path, '*']))
|
|
21
|
+
}
|
|
22
|
+
return result
|
|
23
|
+
}
|
|
6
24
|
function isPlainObject(obj) {
|
|
7
25
|
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
8
26
|
}
|
|
@@ -18,7 +36,7 @@ function project(source, filters) {
|
|
|
18
36
|
const filter = filters.find(f => f.match({ context: source }));
|
|
19
37
|
if (!filter) {
|
|
20
38
|
if (Array.isArray(source)) {
|
|
21
|
-
return source.map((element) => project(element, filters))
|
|
39
|
+
return source.map((element) => project(element, filters, [...path, '*']))
|
|
22
40
|
}
|
|
23
41
|
return {};
|
|
24
42
|
}
|
|
@@ -29,6 +47,7 @@ function project(source, filters) {
|
|
|
29
47
|
// update
|
|
30
48
|
const updatedProperties = []
|
|
31
49
|
for (const property of properties) {
|
|
50
|
+
// property that contains a list of properties to be checked
|
|
32
51
|
if (property.properties) {
|
|
33
52
|
for (const moreProperty of source[property.properties] || []) {
|
|
34
53
|
updatedProperties.push(moreProperty)
|
|
@@ -42,10 +61,34 @@ function project(source, filters) {
|
|
|
42
61
|
// Build the result object
|
|
43
62
|
const result = {};
|
|
44
63
|
properties.forEach(prop => {
|
|
45
|
-
if (source.hasOwnProperty(prop)) {
|
|
64
|
+
if (prop.path && (prop.path.length === path.length + 1) && areFirstNEqual(path, prop.path, path.length) && source.hasOwnProperty(prop.path[path.length])) {
|
|
65
|
+
const endProp = prop.path[path.length]
|
|
66
|
+
if (Array.isArray(source[endProp])) {
|
|
67
|
+
result[endProp] = []
|
|
68
|
+
for (const key in source[endProp]) {
|
|
69
|
+
result[endProp].push(project(source[endProp][key], filters, [...path, endProp, key]))
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
result[endProp] = {}
|
|
73
|
+
for (const key in source[endProp]) {
|
|
74
|
+
result[endProp][key] = project(source[endProp][key], filters, [...path, endProp, key])
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
} else if (source.hasOwnProperty(prop)) {
|
|
46
78
|
// If the property is an object and not null, recursively project it
|
|
47
79
|
if (typeof source[prop] === 'object' && source[prop] !== null) {
|
|
48
|
-
result[prop] = project(source[prop], filters);
|
|
80
|
+
result[prop] = project(source[prop], filters, [...path, prop]);
|
|
81
|
+
} else {
|
|
82
|
+
// Copy primitive or null properties directly
|
|
83
|
+
result[prop] = source[prop];
|
|
84
|
+
}
|
|
85
|
+
} else if (prop.property && source.hasOwnProperty(prop.property)) {
|
|
86
|
+
// If the property is an object and not null, recursively project it
|
|
87
|
+
if (typeof source[prop.property] === 'object' && source[prop.property] !== null) {
|
|
88
|
+
result[prop.property] = {}
|
|
89
|
+
for (const key of prop.check) {
|
|
90
|
+
result[prop.property][key] = project(source[prop.property][key], filters, [...path, prop.property, key]);
|
|
91
|
+
}
|
|
49
92
|
} else {
|
|
50
93
|
// Copy primitive or null properties directly
|
|
51
94
|
result[prop] = source[prop];
|