theprogrammablemind 7.5.4-beta.3 → 7.5.4-beta.5

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
@@ -8,7 +8,7 @@ const _ = require('lodash')
8
8
  const stringify = require('json-stable-stringify')
9
9
  const Lines = require('./lines')
10
10
  const flattens = require('./src/flatten')
11
- const { appendNoDups, InitCalls } = require('./src/helpers')
11
+ const { appendNoDups, InitCalls, updateQueries } = require('./src/helpers')
12
12
  const runtime = require('./runtime')
13
13
  const sortJson = runtime.sortJson
14
14
 
@@ -478,7 +478,7 @@ const doWithRetries = async (n, url, queryParams, data) => {
478
478
  }
479
479
  }
480
480
 
481
- const setupProcessB = ({ config, allowDelta=false } = {}) => {
481
+ const setupProcessB = ({ config, initializer, allowDelta=false } = {}) => {
482
482
  const key = config._key
483
483
 
484
484
  const data = Object.assign({ key, version: '3' }, { uuid: config._uuid })
@@ -526,7 +526,7 @@ const processInstance = (config, instance) => {
526
526
  global.transitoryMode = transitoryMode
527
527
  }
528
528
 
529
- const _process = async (config, query, { commandLineArgs, credentials, writeTests, isTest, saveDeveloper, testConfig, testsFN, errorHandler = defaultErrorHandler } = {}) => {
529
+ const _process = async (config, query, { initializer, commandLineArgs, credentials, writeTests, isTest, saveDeveloper, testConfig, testsFN, errorHandler = defaultErrorHandler } = {}) => {
530
530
  if (credentials) {
531
531
  config.server(credentials.server, credentials.key)
532
532
  }
@@ -546,7 +546,7 @@ const _process = async (config, query, { commandLineArgs, credentials, writeTest
546
546
  throw error
547
547
  }
548
548
 
549
- let { data, /* generators, semantics, */ hierarchy } = setupProcessB({ config, allowDelta: true })
549
+ let { data, /* generators, semantics, */ hierarchy } = setupProcessB({ config, initializer, allowDelta: true })
550
550
  if (commandLineArgs && commandLineArgs.checkForLoop) {
551
551
  data.checkForLoop = true
552
552
  }
@@ -1057,7 +1057,7 @@ const build = async ({ config, target, template, errorHandler = defaultErrorHand
1057
1057
  finish()
1058
1058
  return
1059
1059
  }
1060
- const { property, hierarchy, query: queryOrExtraConfig, skipSemantics } = queries.shift()
1060
+ const { property, hierarchy, query: queryOrExtraConfig, initializer, skipSemantics } = queries.shift()
1061
1061
  // queries are strings or { query: "blah", development: true/false }
1062
1062
  if (typeof queryOrExtraConfig === 'string' || queryOrExtraConfig.query) {
1063
1063
  let query = queryOrExtraConfig;
@@ -1082,7 +1082,7 @@ const build = async ({ config, target, template, errorHandler = defaultErrorHand
1082
1082
  }
1083
1083
 
1084
1084
  try {
1085
- const results = await _process(config, query.query, {})
1085
+ const results = await _process(config, query.query, {initializer})
1086
1086
  if (config.config.debug) {
1087
1087
  // TODO pass in the error handler like the other ones
1088
1088
  defaultInnerProcess(config, defaultErrorHandler, results)
@@ -1143,7 +1143,7 @@ const build = async ({ config, target, template, errorHandler = defaultErrorHand
1143
1143
  return template
1144
1144
  };
1145
1145
  stabilizeOutput(accumulators)
1146
- runtime.fs.writeFileSync(instanceName, JSON.stringify(Object.assign({ queries: template.queries }, accumulators), 0, 2))
1146
+ runtime.fs.writeFileSync(instanceName, JSON.stringify(Object.assign({ queries: template.queries.map(updateQueries) }, accumulators), 0, 2))
1147
1147
 
1148
1148
  // km tests file
1149
1149
  const testsName = `./${target}.test.json`
@@ -1160,7 +1160,9 @@ const build = async ({ config, target, template, errorHandler = defaultErrorHand
1160
1160
  return queryStringOrProperties
1161
1161
  }
1162
1162
  }
1163
- let todo = (template.queries || []).map((query) => { return { property: 'resultss', query, skipSemantics: false } })
1163
+ let todo = []
1164
+ todo = todo.concat((template.initializers || []).map((query) => { return { initializer: true, property: 'resultss', query, skipSemantics: false } }))
1165
+ todo = todo.concat((template.queries || []).map((query) => { return { property: 'resultss', query, skipSemantics: false } }))
1164
1166
  todo = todo.concat((template.fragments || []).map((query) => { return Object.assign({}, toProperties(query), { property: 'fragments', skipSemantics: false }) }))
1165
1167
  todo = todo.concat((template.semantics || []).map((definition) => { return { property: 'semantics', query: `${definition.from}\n${definition.to}`, skipSemantics: true } }))
1166
1168
  await looper(Object.assign([], todo))
@@ -1265,7 +1267,6 @@ const knowledgeModule = async ({
1265
1267
  config.load(template.template, template.instance)
1266
1268
  }
1267
1269
  }
1268
-
1269
1270
  if (isProcess) {
1270
1271
  // setup();
1271
1272
  const parser = new runtime.ArgumentParser({
@@ -1299,6 +1300,7 @@ const knowledgeModule = async ({
1299
1300
  parser.add_argument('-da', '--debugAssociation', { help: 'When running with the --debugAssociation flag the debugging will break when the specified association is added to the config' })
1300
1301
  parser.add_argument('-dh', '--debugHierarchy', { help: 'When running with the --debugHierarchy flag the debugging will break when the specified child-parent pair is added to the config for the main config. Set DEBUG_HIERARCHY to debug any config loaded. For example DEBUG_HIERARCHY=\'["cat", "mammel"]\'' })
1301
1302
  parser.add_argument('-db', '--debugBridge', { help: 'When running with the --debugBridge flag the debugging will break when the specified bridge is added to the config for the main config. Set DEBUG_BRIDGE to debug any config loaded. For example DEBUG_BRIDGE=\'id/level\'' })
1303
+ parser.add_argument('-do', '--debugOperator', { help: 'When running with the --debugOperator flag the debugging will break when the specified operator is added to the config for the main config. Set DEBUG_OPERATOR to debug any config loaded. For example DEBUG_OPERATOR=\'([operator] ([arg]))\'' })
1302
1304
 
1303
1305
  const args = parser.parse_args()
1304
1306
  args.count = args.count || 1
@@ -1316,6 +1318,10 @@ const knowledgeModule = async ({
1316
1318
  console.log('Expected DEBUG_BRIDGE to be of the form "id/level"');
1317
1319
  }
1318
1320
  }
1321
+ if (args.debugOperator) {
1322
+ // id/level
1323
+ global.entodictonDebugOperator = args.debugOperator
1324
+ }
1319
1325
 
1320
1326
  if (args.clean) {
1321
1327
  const tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
package/package.json CHANGED
@@ -16,6 +16,7 @@
16
16
  "lint:fix": "eslint \"**/*.js\" --fix",
17
17
  "lint": "eslint \"**/*.js\"",
18
18
  "to": "node node_modules/.bin/jest --runInBand -t NEO23",
19
+ "tos": "node node_modules/.bin/jest --runInBand -t NEOS23",
19
20
  "test": "jest --config ./jest.config.json",
20
21
  "test:watch": "npm run test -- --watch"
21
22
  },
@@ -61,6 +62,6 @@
61
62
  "json-stable-stringify": "^1.0.1",
62
63
  "node-fetch": "^2.6.1"
63
64
  },
64
- "version": "7.5.4-beta.3",
65
+ "version": "7.5.4-beta.5",
65
66
  "license": "ISC"
66
67
  }
package/src/config.js CHANGED
@@ -5,7 +5,6 @@ const { Generators } = require('./generators')
5
5
  const client = require('../client')
6
6
  const Digraph = require('./digraph')
7
7
  const helpers = require('./helpers')
8
- const deepEqual = require('deep-equal')
9
8
  const runtime = require('../runtime')
10
9
  const _ = require('lodash')
11
10
 
@@ -117,6 +116,11 @@ if (runtime.process.env.DEBUG_BRIDGE) {
117
116
  global.entodictonDebugBridge[1] = int(global.entodictonDebugBridge[1])
118
117
  }
119
118
 
119
+ if (runtime.process.env.DEBUG_OPERATOR) {
120
+ // id/level
121
+ global.entodictonDebugOperator = runtime.process.env.DEBUG_OPERATOR
122
+ }
123
+
120
124
  const hierarchyCanonical = (element) => {
121
125
  if (element.child && element.parent) {
122
126
  return element
@@ -417,6 +421,29 @@ const multiApiImpl = (initializer) => {
417
421
 
418
422
  class Config {
419
423
 
424
+ // return the config with just the elements from the included KM's
425
+ baseConfig() {
426
+ const operators = this.config.operators.filter((operator) => {
427
+ return operator.uuid !== this.uuid
428
+ })
429
+ const bridges = this.config.bridges.filter((bridge) => {
430
+ return bridge.uuid !== this.uuid
431
+ })
432
+ const words = {}
433
+ for (let word in this.config.words) {
434
+ const defs = this.config.words[word].filter( (def) => def.uuid !== this.uuid )
435
+ if (defs.length > 0) {
436
+ words[word] = defs
437
+ }
438
+ }
439
+ debugger
440
+ return {
441
+ operators,
442
+ bridges,
443
+ words
444
+ }
445
+ }
446
+
420
447
  getCounter (maybeName = '') {
421
448
  const counter = this.configCounter
422
449
  this.configCounter += 1
@@ -618,12 +645,13 @@ class Config {
618
645
  }
619
646
  const instanceFragments = (instance.fragments || []).map((fragment) => fragment.key || fragment.query).map( toCanonical )
620
647
  const templateFragments = (template.fragments || []).concat(this.dynamicFragments).map( toCanonical )
621
- const sameFragments = deepEqual(templateFragments, instanceFragments)
622
- const sameQueries = deepEqual((template.queries || []), (instance.queries || []))
648
+ const sameFragments = helpers.safeEquals(templateFragments, instanceFragments)
649
+ const sameQueries = helpers.safeEquals((template.queries || []).map(helpers.updateQueries), (instance.queries || []))
623
650
  return !(instance && sameQueries && sameFragments)
624
651
  }
625
652
 
626
653
  load (template, instance, options = { rebuild: false } ) {
654
+ this.template = template
627
655
  this.logs.push(`loading template for ${this.name}`)
628
656
  if (instance && instance.associations && !options.rebuild) {
629
657
  this.addAssociations(instance.associations)
@@ -685,7 +713,7 @@ class Config {
685
713
  }
686
714
  }
687
715
  if (global.entodictonDebugAssociation) {
688
- if (deepEqual(global.entodictonDebugAssociation, association)) {
716
+ if (helpers.safeEquals(global.entodictonDebugAssociation, association)) {
689
717
  debugger; // debug association hit
690
718
  }
691
719
  }
@@ -720,7 +748,7 @@ class Config {
720
748
  throw `addHierarchy expected parent property to be a string. got ${JSON.stringify(parent)}`
721
749
  }
722
750
  if (global.entodictonDebugHierarchy) {
723
- if (deepEqual(global.entodictonDebugHierarchy, [child, parent])) {
751
+ if ((helpers.safeEquals.entodictonDebugHierarchy, [child, parent])) {
724
752
  debugger; // debug hierarchy hit
725
753
  }
726
754
  }
@@ -738,7 +766,7 @@ class Config {
738
766
  }
739
767
 
740
768
  if (global.entodictonDebugHierarchy) {
741
- if (deepEqual(global.entodictonDebugHierarchy, [child, parent])) {
769
+ if (helpers.safeEquals(global.entodictonDebugHierarchy, [child, parent])) {
742
770
  debugger; // debug hierarchy hit
743
771
  }
744
772
  }
@@ -845,6 +873,7 @@ class Config {
845
873
  if (!this.config.operators) {
846
874
  this.config.operators = []
847
875
  }
876
+
848
877
  const operators = this.config.operators
849
878
 
850
879
  let operator;
@@ -854,6 +883,12 @@ class Config {
854
883
  operator = Object.assign({}, objectOrPattern, { uuid: this._uuid })
855
884
  }
856
885
 
886
+ if (global.entodictonDebugOperator) {
887
+ if (operator.pattern === global.entodictonDebugOperator) {
888
+ debugger; // debug operator hit
889
+ }
890
+ }
891
+
857
892
  if (operator.allowDups) {
858
893
  if (operators.find( (o) => o.pattern == operator.pattern )) {
859
894
  return;
@@ -1726,7 +1761,8 @@ class Config {
1726
1761
 
1727
1762
  if (currentConfig.api) {
1728
1763
  currentConfig.api.objects = args.objects
1729
- currentConfig.api.config = () => this
1764
+ // GREG42 currentConfig.api.config = () => this
1765
+ currentConfig.api.config = () => args.baseConfig
1730
1766
  currentConfig.api.uuid = currentConfig._uuid
1731
1767
  }
1732
1768
  // this.instances.forEach( (instance) => client.processInstance(this, instance) )
package/src/helpers.js CHANGED
@@ -44,10 +44,23 @@ const appendNoDups = (l1, l2) => {
44
44
  }
45
45
 
46
46
  const safeEquals = (v1, v2) => {
47
- if (!deepEqual(stringify(v1), stringify(v2))) {
47
+ if (typeof v1 !== typeof v2) {
48
48
  return false
49
49
  }
50
- return true
50
+
51
+ const type = typeof v1
52
+ if (type == 'number' || type == 'string') {
53
+ return v1 == v2
54
+ } else if (type == 'function') {
55
+ return v1.toString() == v2.toString()
56
+ } else {
57
+ for (let key in v1) {
58
+ if (!safeEquals(v1[key], v2[key])) {
59
+ return false
60
+ }
61
+ }
62
+ return true
63
+ }
51
64
  }
52
65
 
53
66
  /*
@@ -238,7 +251,66 @@ const mapInPlace = (list, fn) => {
238
251
  }
239
252
  }
240
253
 
254
+ const updateQueries = (queryOrConfig) => {
255
+ if (typeof queryOrConfig == 'string' || queryOrConfig.query) {
256
+ return queryOrConfig
257
+ } else {
258
+ const config = queryOrConfig
259
+ return functionsToStrings(config)
260
+ }
261
+ }
262
+
263
+ const functionsToStrings = (config) => {
264
+ config = {...config}
265
+ const mapGenerator = (generator) => {
266
+ if (generator.apply) {
267
+ return { ...generator, match: generator.match.toString(), apply: generator.apply.toString() }
268
+ } else {
269
+ return [ generator[0].toString(), generator[1].toString() ]
270
+ }
271
+ }
272
+ if (config.generators) {
273
+ config.generators = config.generators.map( mapGenerator )
274
+ }
275
+ if (config.semantics) {
276
+ config.semantics = config.semantics.map( (semantic) => {
277
+ if (semantic.apply) {
278
+ return { ...semantic, match: semantic.match.toString(), apply: semantic.apply.toString() }
279
+ } else {
280
+ return [ semantic[0].toString(), semantic[1].toString() ]
281
+ }
282
+ })
283
+ }
284
+ if (config.bridges) {
285
+ config.bridges = config.bridges.map( (bridge) => {
286
+ bridge = {...bridge}
287
+ if (bridge.generator) {
288
+ bridge.generator = bridge.generator.toString()
289
+ }
290
+ if (bridge.generators) {
291
+ bridge.generators = bridge.generators.map( mapGenerator )
292
+ }
293
+ if (bridge.generatorp) {
294
+ bridge.generatorp = bridge.generatorp.toString()
295
+ }
296
+ if (bridge.generatorr) {
297
+ bridge.generatorr = bridge.generatorr.toString()
298
+ }
299
+ if (bridge.semantic) {
300
+ bridge.semantic = bridge.semantic.toString()
301
+ }
302
+ if (bridge.evaluator) {
303
+ bridge.evaluator = bridge.evaluator.toString()
304
+ }
305
+ return bridge
306
+ })
307
+ }
308
+ return config
309
+ }
310
+
241
311
  module.exports = {
312
+ functionsToStrings,
313
+ updateQueries,
242
314
  mapInPlace,
243
315
  validProps,
244
316
  args,