theprogrammablemind 9.5.1-beta.30 → 9.5.1-beta.32

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 CHANGED
@@ -14,7 +14,7 @@ const Lines = require('./lines')
14
14
  const flattens = require('./src/flatten')
15
15
  const { sortJson, appendNoDups, updateQueries, safeNoDups, stableId, where, suggestAssociationsFix, suggestAssociationsFixFromSummaries, validProps } = require('./src/helpers')
16
16
  const runtime = require('./runtime')
17
- const debug = require('./src/debug')
17
+ const db = require('./src/debug')
18
18
 
19
19
  const getConfig_getObjectsCheck = (config, testConfig) => {
20
20
  let testConfigName = config.name
@@ -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 (checks[km] && checks[km].find((check) => check.match && check.apply)) {
73
- projection[km] = project2(objects, checks[km])
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
- projection[km] = project(objects, checks[km])
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
@@ -237,9 +236,10 @@ const doWithRetries = async (n, url, queryParams, data) => {
237
236
  body: JSON.stringify(data),
238
237
  timeout: 1000 * 60 * 5, // it does not respect this timeout so that's why I have the retries
239
238
  headers: {
240
- mode: 'no-cors',
239
+ // mode: 'no-cors',
241
240
  'Content-Type': 'application/json'
242
- }
241
+ },
242
+ credentials: 'same-origin',
243
243
  })
244
244
  if (result.ok) {
245
245
  return JSON.parse(JSON.stringify(await result.json()))
@@ -841,7 +841,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
841
841
  }
842
842
  console.log(responses.trace)
843
843
 
844
- if (true) {
844
+ if (false) {
845
845
  if (global.beforeObjects) {
846
846
  console.log('objects', runtime.jsonDiff.diffString(global.beforeObjects, config.get('objects')))
847
847
  } else {
@@ -1327,13 +1327,32 @@ const knowledgeModuleImpl = async ({
1327
1327
  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
1328
  parser.add_argument('-r', '--reset', { action: 'store_true', help: 'Get the server to bypass the cache and rebuild everything' })
1329
1329
  parser.add_argument('-q', '--query', { help: 'Run the specified query' })
1330
+ parser.add_argument('-f', '--filter', { help: 'for -pd only the data for the knowledge modules that start with this string will be shown' })
1330
1331
  parser.add_argument('-ip ', '--server', { help: 'Server to run against' })
1331
1332
  parser.add_argument('-qp ', '--queryParams', { help: 'Query params for the server call' })
1332
1333
  parser.add_argument('-dt', '--deleteTest', { help: 'Delete the specified query from the tests file.' })
1333
1334
  parser.add_argument('--parenthesized', { action: 'store_true', help: 'Show the generated phrases with parenthesis.' })
1334
1335
  parser.add_argument('-c', '--clean', { help: 'Remove data from the test files. a === association' })
1335
1336
  parser.add_argument('-od', '--objectDiff', { action: 'store_true', help: 'When showing the objects use a colour diff' })
1336
- parser.add_argument('-p', '--print', { help: 'Print the specified elements c === config, w === words, b === bridges, o === operators d === objects (d for data), h === hierarchy, ha === hierarchy ancestors g === generators, s === semantics, l === load t=tests ordering p === priorities a === associations j === JSON sent to server. for example --print wb' })
1337
+ parser.add_argument('-p', '--print', { help:
1338
+ `Print the specified elements
1339
+ a === associations
1340
+ b === bridges,
1341
+ c === config,
1342
+ cc === test checks,
1343
+ d === objects (d for data),
1344
+ g === generators,
1345
+ h === hierarchy,
1346
+ ha === hierarchy ancestors,
1347
+ j === JSON sent to server,
1348
+ l === load ordering,
1349
+ o === operators,
1350
+ p === priorities,
1351
+ s === semantics,
1352
+ t === tests ordering,
1353
+ w === words,
1354
+ for example --print wb' })
1355
+ ` })
1337
1356
  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
1357
  parser.add_argument('-fr', '--failRebuild', { action: 'store_true', help: 'If a rebuild is required fail out.' })
1339
1358
  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 +1513,12 @@ const knowledgeModuleImpl = async ({
1494
1513
  counter += 1
1495
1514
  }
1496
1515
  }
1516
+ if (hasArg('cc')) {
1517
+ for (const cc of config.getContextChecks()) {
1518
+ const printable = { ...cc, match: cc.match.toString(), apply: cc.apply.toString() }
1519
+ console.log(JSON.stringify(printable, null, 2))
1520
+ }
1521
+ }
1497
1522
  if (hasArg('c')) {
1498
1523
  const { data } = setupProcessB({ config })
1499
1524
  console.log('Config as sent to server')
@@ -1557,8 +1582,19 @@ const knowledgeModuleImpl = async ({
1557
1582
  }
1558
1583
 
1559
1584
  if (hasArg('d')) {
1560
- console.log('objects (data) ================')
1561
- console.log(JSON.stringify(config.config.objects, null, 2))
1585
+ if (args.filter) {
1586
+ console.log(`objects (data) filtered by ${args.filter} ================`)
1587
+ const projection = { namespaced: {} }
1588
+ for (const key of Object.keys(config.config.objects.namespaced)) {
1589
+ if (key.startsWith(args.filter)) {
1590
+ projection.namespaced[key] = config.config.objects.namespaced[key]
1591
+ }
1592
+ }
1593
+ console.log(JSON.stringify(projection, null, 2))
1594
+ } else {
1595
+ console.log('objects (data) ================')
1596
+ console.log(JSON.stringify(config.config.objects, null, 2))
1597
+ }
1562
1598
  }
1563
1599
 
1564
1600
  if (hasArg('p')) {
@@ -2044,5 +2080,6 @@ module.exports = {
2044
2080
  gs,
2045
2081
  flattens,
2046
2082
  writeTest,
2047
- getConfigForTest
2083
+ getConfigForTest,
2084
+ debug: db,
2048
2085
  }
package/package.json CHANGED
@@ -72,6 +72,6 @@
72
72
  "scriptjs": "^2.5.9",
73
73
  "uuid": "^8.3.2"
74
74
  },
75
- "version": "9.5.1-beta.30",
75
+ "version": "9.5.1-beta.32",
76
76
  "license": "UNLICENSED"
77
77
  }
package/src/config.js CHANGED
@@ -335,6 +335,8 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
335
335
  config.addPriority({ context: [[bridge.id, bridge.level], after], choose: [0] })
336
336
  }
337
337
  }
338
+
339
+ // done in setTestConfig
338
340
  if (bridge.check) {
339
341
  if (!config.testConfig) {
340
342
  config.testConfig = {}
@@ -345,12 +347,15 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
345
347
  if (!config.testConfig?.checks?.context) {
346
348
  config.testConfig.checks.context = []
347
349
  }
348
- config.testConfig.checks.context.push({
350
+ config.contextChecksFromBridges.push({
351
+ 'bridge.id': bridge.id,
352
+ 'bridge.check': bridge.check,
349
353
  match: ({context}) => context.marker == bridge.id,
350
354
  exported: true,
351
355
  apply: ({context}) => bridge.check,
352
356
  })
353
357
  }
358
+
354
359
  if (bridge.after) {
355
360
  for (let before of bridge.after) {
356
361
  if (typeof before === 'string') {
@@ -1052,7 +1057,27 @@ class Config {
1052
1057
  }
1053
1058
 
1054
1059
  setTestConfig (testConfig) {
1055
- this.testConfig = testConfig
1060
+ this.testConfig = { ...testConfig }
1061
+ if (!this.testConfig.checks) {
1062
+ this.testConfig.checks = {}
1063
+ }
1064
+ if (!this.testConfig?.checks?.context) {
1065
+ this.testConfig.checks.context = []
1066
+ }
1067
+ this.testConfig.checks.context = this.contextChecksFromBridges.concat(this.testConfig.checks.context)
1068
+ /*
1069
+ const currentTestConfig = testConfig // add bridge has added check.context's
1070
+
1071
+ if (!this.testConfig.checks) {
1072
+ debugger
1073
+ // this.testConfig.checks =
1074
+ }
1075
+
1076
+ // set during bridge setup
1077
+ if (currentTestConfig.checks?.context) {
1078
+ this.testConfig.checks.context = currentTestConfig.checks.context.concat(this.testConfig.checks.context)
1079
+ }
1080
+ */
1056
1081
  }
1057
1082
 
1058
1083
  getTestConfig () {
@@ -2099,6 +2124,8 @@ class Config {
2099
2124
  config.priorities = config.priorities || []
2100
2125
  }
2101
2126
 
2127
+ this.contextChecksFromBridges = []
2128
+
2102
2129
  this._enable = []
2103
2130
  this._apiKMs = apiKMs
2104
2131
 
@@ -2158,7 +2185,7 @@ class Config {
2158
2185
 
2159
2186
  // set the default server so stuff just works
2160
2187
  // this.server('https://184.67.27.82:3000', '6804954f-e56d-471f-bbb8-08e3c54d9321')
2161
- this.server('https://thinktelligence.com:3000', '6804954f-e56d-471f-bbb8-08e3c54d9321')
2188
+ this.server('https://thinktelligence.com/entodicton', '6804954f-e56d-471f-bbb8-08e3c54d9321')
2162
2189
 
2163
2190
  this.defaultConfig()
2164
2191
  this.initializerFn = ({ currentConfig }) => {
@@ -2425,6 +2452,7 @@ class Config {
2425
2452
  // update uuid here set the uuid in the objects and add error checking
2426
2453
  cp.initializerFn = this.initializerFn
2427
2454
  cp.terminatorFn = this.terminatorFn
2455
+ cp.contextChecksFromBridges = this.contextChecksFromBridges
2428
2456
  cp._apiKMs = this._apiKMs
2429
2457
  cp._apiConstructor = this._apiConstructor
2430
2458
  if (cp._apiConstructor) {
@@ -2785,19 +2813,37 @@ class Config {
2785
2813
 
2786
2814
  getContextChecks() {
2787
2815
  const allChecks = []
2788
- for (const name of this.loadOrdering) {
2789
- const checks = this.kms[name].testConfig?.checks?.context || []
2790
- for (const check of checks) {
2791
- if (check.exported) {
2792
- allChecks.push(check)
2816
+ let defaults = () => []
2817
+ if (this.loadOrdering) {
2818
+ for (const name of this.loadOrdering) {
2819
+ const checks = this.kms[name].testConfig?.checks?.context || []
2820
+ const oldDefaults = defaults
2821
+ for (const check of checks) {
2822
+ if (!check.match) {
2823
+ const oldDefaults = defaults
2824
+ defaults = () => helpers.safeNoDups([...check.apply(), ...oldDefaults()])
2825
+ continue
2826
+ }
2827
+ if (check.exported) {
2828
+ allChecks.push(check)
2829
+ }
2793
2830
  }
2794
2831
  }
2795
2832
  }
2796
2833
  for (const check of this.testConfig?.checks?.context || []) {
2834
+ if (!check.match) {
2835
+ const oldDefaults = defaults
2836
+ defaults = () => [...new Set([...check.apply(), ...oldDefaults()])]
2837
+ continue
2838
+ }
2797
2839
  if (!check.exported) {
2798
2840
  allChecks.push(check)
2799
2841
  }
2800
2842
  }
2843
+ allChecks.push({
2844
+ match: () => true,
2845
+ apply: defaults
2846
+ })
2801
2847
  return allChecks
2802
2848
  }
2803
2849
 
package/src/project2.js CHANGED
@@ -1,8 +1,26 @@
1
- function project(source, filters) {
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];