theprogrammablemind 8.0.0-beta.2 → 8.0.0-beta.20

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.
Files changed (3) hide show
  1. package/client.js +8 -4
  2. package/package.json +12 -13
  3. package/src/config.js +52 -73
package/client.js CHANGED
@@ -865,6 +865,10 @@ const getConfigForTest = (config, testConfig) => {
865
865
 
866
866
  const runTest = async (config, expected, { args, verbose, testConfig, debug }) => {
867
867
  const test = expected.query
868
+ if (args.query && args.query != test) {
869
+ // no run this
870
+ return
871
+ }
868
872
  // initialize in between test so state is not preserved since the test was adding without state
869
873
  config.rebuild()
870
874
  const errorHandler = (error) => {
@@ -1582,7 +1586,7 @@ const knowledgeModuleImpl = async ({
1582
1586
  parser.add_argument('-t', '--test', { action: 'store_true', help: 'Run the tests. Create tests by running with the --query + --save flag' })
1583
1587
  parser.add_argument('-tv', '--testVerbose', { action: 'store_true', help: 'Run the tests in verbose mode. Create tests by running with the --query or --loop with the --save flag' })
1584
1588
  // parser.add_argument('-ttr', '--testToRun', { help: 'Only the specified test will be run' })
1585
- parser.add_argument('-tva', '--testAllVerbose', { action: 'store_true', help: 'Run the tests in verbose mode. All the tests will be run instead of stopping at first failure. Create tests by running with the --query or --loop with the --save flag' })
1589
+ parser.add_argument('-tva', '--testAllVerbose', { action: 'store_true', help: 'Run the tests in verbose mode. All the tests will be run instead of stopping at first failure. Create tests by running with the --query or --loop with the --save flag. if -q is specified the tests will be run for just the specified query.' })
1586
1590
  parser.add_argument('-tnp', '--testNoParenthesized', { action: 'store_true', help: 'Don\' check parenthesized differences for the tests' })
1587
1591
  parser.add_argument('-n', '--count', { help: 'Number of times to run the tests. Default is one. Use this to check for flakey test. If possible the system will print out a message with the word "hint" suggesting how to fix the problem' })
1588
1592
  // parser.add_argument('-b', '--build', { help: 'Specify the template file name of the form <kmName>. There should be a file called <baseKmName>.<kmName>.template.json with the queries to run. For example { queries: [...] }. The template file will be run and generate an instantiation called <baseKmName>.<kmName>.instance.json and a file called <kmName>.js that will load the template file (this is file generated only if not already existing) and a test file called <KmName>.tests.json. This can then be loaded into an instance of the current knowledge module to setup initial conditions.' })
@@ -1663,7 +1667,7 @@ const knowledgeModuleImpl = async ({
1663
1667
  throw new Error('Error for the checkForLoop argument. Expected a JSON array of operator keys of the form "[<id>, <level>]"')
1664
1668
  }
1665
1669
  } catch (e) {
1666
- throw new Error(`Error parsing JSON of the checkForLoop argument. ${e}`)
1670
+ throw new Error('Error for the checkForLoop argument. Expected a JSON array of operator keys of the form "[<id>, <level>]"')
1667
1671
  }
1668
1672
  } else {
1669
1673
  if (process.argv.includes('--checkForLoop') || process.argv.includes('-cl')) {
@@ -1994,7 +1998,7 @@ const knowledgeModuleImpl = async ({
1994
1998
  lines.setElement(2, 2, JSON.stringify(result.actual.checked, null, 2))
1995
1999
  lines.log()
1996
2000
  if (args.vimdiff) {
1997
- vimdiff(result.actual.checked, result.expected.checked)
2001
+ show('checked properties for objects', result.expected.checked, result.actual.checked)
1998
2002
  }
1999
2003
  newError = true
2000
2004
  headerShown = true
@@ -2012,7 +2016,7 @@ const knowledgeModuleImpl = async ({
2012
2016
  lines.setElement(2, 2, JSON.stringify(result.actual.checkedContexts, null, 2))
2013
2017
  lines.log()
2014
2018
  if (args.vimdiff) {
2015
- vimdiff(result.actual.checkedContexts, result.expected.checkedContexts)
2019
+ show('checked properties for context', result.expected.checkedContexts, result.actual.checkedContexts)
2016
2020
  }
2017
2021
  newError = true
2018
2022
  headerShown = true
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "devDependencies": {
3
- "eslint-plugin-import": "^2.23.4",
4
- "jest": "^29.7.0",
5
- "@typescript-eslint/parser": "^4.28.4",
6
3
  "@typescript-eslint/eslint-plugin": "^4.28.4",
7
- "eslint-plugin-node": "^11.1.0",
4
+ "@typescript-eslint/parser": "^4.28.4",
5
+ "eslint": "^7.31.0",
8
6
  "eslint-config-standard": "^16.0.3",
7
+ "eslint-plugin-import": "^2.23.4",
8
+ "eslint-plugin-node": "^11.1.0",
9
9
  "eslint-plugin-promise": "^5.1.0",
10
- "eslint": "^7.31.0"
10
+ "jest": "^29.7.0"
11
11
  },
12
12
  "scripts": {
13
13
  "to:debug": "node inspect node_modules/.bin/jest --runInBand -t NEO23",
@@ -52,19 +52,18 @@
52
52
  ],
53
53
  "author": "dev@thinktelligence.com",
54
54
  "dependencies": {
55
+ "base-64": "^1.0.0",
55
56
  "deep-equal": "^2.0.4",
56
- "uuid": "^8.3.2",
57
+ "fs": "0.0.1-security",
57
58
  "json-diff": "^1.0.3",
59
+ "json-stable-stringify": "^1.0.1",
58
60
  "lodash": "^4.17.20",
59
- "fs": "0.0.1-security",
60
- "base-64": "^1.0.0",
61
- "sort-json": "^2.0.0",
61
+ "node-fetch": "^2.6.1",
62
62
  "readline": "^1.3.0",
63
63
  "scriptjs": "^2.5.9",
64
- "underscore": "^1.13.1",
65
- "json-stable-stringify": "^1.0.1",
66
- "node-fetch": "^2.6.1"
64
+ "sort-json": "^2.0.0",
65
+ "uuid": "^8.3.2"
67
66
  },
68
- "version": "8.0.0-beta.2",
67
+ "version": "8.0.0-beta.20",
69
68
  "license": "UNLICENSED"
70
69
  }
package/src/config.js CHANGED
@@ -262,7 +262,12 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
262
262
  }
263
263
  if (bridge.children) {
264
264
  for (const child of bridge.children) {
265
- config.addHierarchy(child, bridge.id)
265
+ // config.addHierarchy(child, bridge.id)
266
+ if (child.child) {
267
+ config.addHierarchy(child.child, bridge.id, child.instance)
268
+ } else {
269
+ config.addHierarchy(child, bridge.id)
270
+ }
266
271
  }
267
272
  }
268
273
  if (bridge.operator) {
@@ -270,12 +275,20 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
270
275
  }
271
276
  if (bridge.parents) {
272
277
  for (const parent of bridge.parents) {
273
- config.addHierarchy(bridge.id, parent)
278
+ if (parent.parent) {
279
+ config.addHierarchy(bridge.id, parent.parent, parent.instance)
280
+ } else {
281
+ config.addHierarchy(bridge.id, parent)
282
+ }
274
283
  }
275
284
  }
276
285
  if (bridge.isA) {
277
286
  for (const parent of bridge.isA) {
278
- config.addHierarchy(bridge.id, parent)
287
+ if (parent.parent) {
288
+ config.addHierarchy(bridge.id, parent.parent, parent.instance)
289
+ } else {
290
+ config.addHierarchy(bridge.id, parent)
291
+ }
279
292
  }
280
293
  }
281
294
  if (bridge.before) {
@@ -1197,7 +1210,9 @@ class Config {
1197
1210
  // console.log("instanceFragments", instanceFragments)
1198
1211
  }
1199
1212
  }
1200
- if (startOfChanges || instance.resultss) {
1213
+ if (startOfChanges) {
1214
+ return { needsRebuild: true, startOfChanges, previousResultss: instance.resultss }
1215
+ } else if (startOfChanges || instance.resultss) {
1201
1216
  return { needsRebuild: !(instance && sameQueries && sameFragments), startOfChanges, previousResultss: instance.resultss }
1202
1217
  } else {
1203
1218
  return { needsRebuild: !(instance && sameQueries && sameFragments) }
@@ -1309,9 +1324,9 @@ class Config {
1309
1324
  }
1310
1325
  }
1311
1326
 
1312
- addHierarchy (child, parent) {
1327
+ addHierarchy (child, parent, instance) {
1313
1328
  if (child && parent || !child || Array.isArray(child) || (typeof child === 'string' && !parent)) {
1314
- this.addHierarchyChildParent(child, parent)
1329
+ this.addHierarchyChildParent(child, parent, instance)
1315
1330
  // this.addHierarchyProperties ({ child, parent })
1316
1331
  } else {
1317
1332
  this.addHierarchyProperties(child)
@@ -1319,26 +1334,32 @@ class Config {
1319
1334
  }
1320
1335
 
1321
1336
  addHierarchyProperties (edge) {
1322
- const { child, parent } = edge
1337
+ const { child, parent, instance } = edge
1323
1338
  if (typeof child !== 'string') {
1324
1339
  throw new Error(`addHierarchy expected child property to be a string. got ${JSON.stringify(child)}`)
1325
1340
  }
1326
1341
  if (typeof parent !== 'string') {
1327
1342
  throw new Error(`addHierarchy expected parent property to be a string. got ${JSON.stringify(parent)}`)
1328
1343
  }
1344
+ if (instance && typeof instance !== 'boolean') {
1345
+ throw new Error(`addHierarchy expected instance property to be a boolean or undefined. got ${JSON.stringify(instance)}`)
1346
+ }
1329
1347
  debugHierarchy([child, parent])
1330
1348
  this.config.hierarchy.push(edge)
1331
1349
  // TODO greg11 this.hierarchy.addEdge(edge)
1332
- this._delta.json.hierarchy.push([child, parent])
1350
+ this._delta.json.hierarchy.push([child, parent, instance || false])
1333
1351
  }
1334
1352
 
1335
- addHierarchyChildParent (child, parent) {
1353
+ addHierarchyChildParent (child, parent, instance) {
1336
1354
  if (typeof child !== 'string') {
1337
1355
  throw new Error(`addHierarchy expected child to be a string. got ${JSON.stringify(child)}`)
1338
1356
  }
1339
1357
  if (typeof parent !== 'string') {
1340
1358
  throw new Error(`addHierarchy expected parent to be a string. got ${JSON.stringify(parent)}`)
1341
1359
  }
1360
+ if (instance && typeof instance !== 'boolean') {
1361
+ throw new Error(`addHierarchy expected instance property to be a boolean or undefined. got ${JSON.stringify(instance)}`)
1362
+ }
1342
1363
  debugHierarchy([child, parent])
1343
1364
  if (this.config.hierarchy.find((element) => {
1344
1365
  const hc = hierarchyCanonical(element)
@@ -1349,9 +1370,9 @@ class Config {
1349
1370
  return
1350
1371
  }
1351
1372
 
1352
- this.config.hierarchy.push([child, parent])
1373
+ this.config.hierarchy.push([child, parent, instance || false])
1353
1374
  // this.hierarchy.addEdge([child, parent])
1354
- this._delta.json.hierarchy.push([child, parent])
1375
+ this._delta.json.hierarchy.push([child, parent, instance || false])
1355
1376
  }
1356
1377
 
1357
1378
  getBridge (id, level) {
@@ -1620,6 +1641,10 @@ class Config {
1620
1641
  return client.process(this, query, options)
1621
1642
  }
1622
1643
 
1644
+ query (query, options) {
1645
+ return this.process(query, options)
1646
+ }
1647
+
1623
1648
  processQuery (query, options) {
1624
1649
  return this.process(query, options)
1625
1650
  }
@@ -1797,24 +1822,6 @@ class Config {
1797
1822
  // when running configs any bridges added are marked as transitory so that the associated will ignore those op's
1798
1823
  this.transitoryMode = false
1799
1824
 
1800
- // check for duplicate bridges
1801
- if (config && config.bridges) {
1802
- let duplicated = new Set()
1803
- const seen = new Set()
1804
- for (const bridge of config.bridges) {
1805
- const id = `${bridge.id}/${bridge.level}`
1806
- if (seen.has(id)) {
1807
- duplicated.add(id)
1808
- } else {
1809
- seen.add(id)
1810
- }
1811
- }
1812
- duplicated = Array.from(duplicated)
1813
- if (duplicated.length > 0) {
1814
- throw new Error(`In the KM ${config.name}, the following operators are duplicated in the bridges: ${duplicated}`)
1815
- }
1816
- }
1817
-
1818
1825
  if (config && config.words) {
1819
1826
  initWords(config.words)
1820
1827
  isValidWordDef(config.words)
@@ -1863,6 +1870,7 @@ class Config {
1863
1870
  }
1864
1871
  this.get('objects').namespaced[this._uuid] = {}
1865
1872
  this.valid()
1873
+ this.checks()
1866
1874
  debugConfigProps(this.config)
1867
1875
  }
1868
1876
 
@@ -2608,7 +2616,7 @@ class Config {
2608
2616
 
2609
2617
  this.hierarchy.edges = this.config.hierarchy
2610
2618
  this.valid()
2611
- this.checkBridges()
2619
+ this.checks()
2612
2620
  }
2613
2621
 
2614
2622
  nameToUUID (name) {
@@ -2822,6 +2830,11 @@ class Config {
2822
2830
  }
2823
2831
  }
2824
2832
 
2833
+ checks () {
2834
+ this.checkOperators()
2835
+ this.checkBridges()
2836
+ }
2837
+
2825
2838
  checkOperators () {
2826
2839
  if (!this.config.operators) {
2827
2840
  return
@@ -2842,53 +2855,19 @@ class Config {
2842
2855
  return
2843
2856
  }
2844
2857
 
2845
- /*
2846
- "namespaces": {
2847
- "634a678b-8d92-4464-bf65-943a82f404d8": {
2848
- "ids": [ "tankConcept" ],
2849
- "namespace": [ "ns1" ]
2850
- },
2851
- console.log('before check', JSON.stringify(this._eqClasses, null, 2))
2852
- */
2853
-
2854
- const errors = []
2855
- /*
2856
- const namespaces = this.config.namespaces
2857
- const nsToIds = {}
2858
- for (const uuid in namespaces) {
2859
- const namespace = namespaces[uuid].namespace
2860
- const ns = namespace.join('#')
2861
- if (!nsToIds[ns]) {
2862
- nsToIds[ns] = new Set()
2863
- }
2864
- const ids = nsToIds[ns]
2865
- for (const id of namespaces[uuid].ids) {
2866
- if (ids.has(id)) {
2867
- if (ns === '') {
2868
- const dups = this.config.bridges.filter( (bridge) => bridge.id == id )
2869
- errors.push(`Id '${id}' is defined more than once in the bridges of the base namespace of the KM ${this.name}, Dups are ${JSON.stringify(dups)}`)
2870
- } else {
2871
- errors.push(`Id '${id}' is defined more than once in the bridges of the ${ns} namespace of the KM ${this.name}`)
2872
- }
2873
- } else {
2874
- ids.add(id)
2875
- }
2876
- }
2877
- }
2878
- */
2879
-
2880
- const keyIsPresent = {}
2858
+ let duplicated = new Set()
2859
+ const seen = new Set()
2881
2860
  for (const bridge of this.config.bridges) {
2882
- const key = `${bridge.id}/${bridge.level} (namespace: ${bridge.uuid})`
2883
- if (keyIsPresent[key]) {
2884
- errors.push(new Error(`Id '${key}' is defined more than once in bridges of the base namespace of the KM ${this.name}`))
2861
+ const id = `${bridge.id}/${bridge.level} (namespace: ${bridge.uuid || this.uuid})`
2862
+ if (seen.has(id)) {
2863
+ duplicated.add(id)
2885
2864
  } else {
2886
- keyIsPresent[key] = key
2865
+ seen.add(id)
2887
2866
  }
2888
2867
  }
2889
-
2890
- if (errors.length > 0) {
2891
- throw errors
2868
+ duplicated = Array.from(duplicated)
2869
+ if (duplicated.length > 0) {
2870
+ throw new Error(`In the KM ${this.name}, the following operators are duplicated in the bridges: ${duplicated}`)
2892
2871
  }
2893
2872
  };
2894
2873