theprogrammablemind_4wp 9.3.0-beta.4 → 9.3.0-beta.40

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
@@ -1,8 +1,7 @@
1
1
  const { Semantics, Semantic } = require('./src/semantics')
2
2
  const { Generators, Generator } = require('./src/generators')
3
3
  const { Config } = require('./src/config')
4
- const { loadInstance, ErrorReason, listable, setupArgs, gs, processContext, getObjects, setupProcessB, processContextsB } = require('./src/configHelpers')
5
- const DigraphInternal = require('./src/digraph_internal')
4
+ const { loadInstance, setupArgs, gs, processContext, getObjects, setupProcessB, processContextsB } = require('./src/configHelpers')
6
5
  const Digraph = require('./src/digraph')
7
6
  const { project } = require('./src/project')
8
7
  const fetch = require('node-fetch')
@@ -12,7 +11,7 @@ const _ = require('lodash')
12
11
  const stringify = require('json-stable-stringify')
13
12
  const Lines = require('./lines')
14
13
  const flattens = require('./src/flatten')
15
- const { appendNoDups, InitCalls, updateQueries, safeNoDups, stableId, where, suggestAssociationsFix, suggestAssociationsFixFromSummaries, validProps } = require('./src/helpers')
14
+ const { appendNoDups, updateQueries, safeNoDups, stableId, where, suggestAssociationsFix, suggestAssociationsFixFromSummaries, validProps } = require('./src/helpers')
16
15
  const runtime = require('./runtime')
17
16
  const sortJson = runtime.sortJson
18
17
  const debug = require('./src/debug')
@@ -77,7 +76,7 @@ const pickObjects = (config, testConfig, getObjects) => {
77
76
  const sameJSON = (json1, json2) => {
78
77
  const sjson1 = sortJson(json1, { depth: 25 })
79
78
  const sjson2 = sortJson(json2, { depth: 25 })
80
- return JSON.stringify(sjson1) == JSON.stringify(sjson2)
79
+ return JSON.stringify(sjson1) === JSON.stringify(sjson2)
81
80
  }
82
81
 
83
82
  const vimdiff = (actualJSON, expectedJSON, title) => {
@@ -149,7 +148,7 @@ const convertToStable = (objects) => {
149
148
  const writeTestFile = (fn, tests) => {
150
149
  const stabilize = (tests) => {
151
150
  for (const test of tests) {
152
- for (opChoice of test.metadata.opChoices) {
151
+ for (const opChoice of test.metadata.opChoices) {
153
152
  opChoice.ops.sort()
154
153
  }
155
154
  test.metadata.opChoices.sort()
@@ -185,7 +184,7 @@ const writeTest = (fn, query, objects, generated, paraphrases, responses, contex
185
184
  }, { depth: 25 })
186
185
  let wasSet = false
187
186
  tests.forEach((test, index) => {
188
- if (test.query == query) {
187
+ if (test.query === query) {
189
188
  tests[index] = results
190
189
  wasSet = true
191
190
  }
@@ -261,7 +260,7 @@ const throwErrorHandler = (error) => {
261
260
  throw error
262
261
  }
263
262
 
264
- const _process = async (config, query, { initializer, commandLineArgs, credentials, writeTests, isTest, saveDeveloper, rebuildingTemplate, testConfig, testsFN, errorHandler = throwErrorHandler } = {}) => {
263
+ const _process = async (config, query, { initializer, commandLineArgs, credentials, writeTests, isProcess, isModule, isTest, saveDeveloper, rebuildingTemplate, testConfig, testsFN, errorHandler = throwErrorHandler } = {}) => {
265
264
  if (credentials) {
266
265
  config.server(credentials.server, credentials.key)
267
266
  }
@@ -321,7 +320,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
321
320
  data.start_counter = startCounter
322
321
  let json = await doWithRetries(retries, url, queryParams, data)
323
322
  let resetData = false
324
- if (json.code == 'NOT_IN_CACHE') {
323
+ if (json.code === 'NOT_IN_CACHE') {
325
324
  resetData = true
326
325
  const setupB = setupProcessB({ config, allowDelta: false })
327
326
  data = setupB.data
@@ -346,15 +345,16 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
346
345
  throw json
347
346
  } else {
348
347
  let clientSideTime
348
+ let start
349
349
  if (isTest) {
350
350
  start = runtime.performance.performance.now()
351
351
  }
352
352
  const summary = { summaries: json.summaries, length: json.contexts.length }
353
353
  summaries.push(summary)
354
354
  const { contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime } =
355
- await processContextsB({ isTest, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
355
+ await processContextsB({ isTest, isProcess, isModule, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
356
356
  if (isTest) {
357
- end = runtime.performance.performance.now()
357
+ const end = runtime.performance.performance.now()
358
358
  clientSideTime = end - start
359
359
  }
360
360
  response.associations = json.associations
@@ -386,13 +386,13 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
386
386
  }
387
387
 
388
388
  if (writeTests) {
389
- const actual_config = getConfigForTest(config, testConfig)
389
+ const actualConfig = getConfigForTest(config, testConfig)
390
390
  const saveObjects = { ...config.config.objects }
391
391
  saveObjects.nameToUUID = {}
392
392
  for (const km of config.configs) {
393
393
  saveObjects.nameToUUID[km.name] = km.uuid
394
394
  }
395
- writeTest(testsFN, query, saveObjects, response.generated, response.paraphrases, response.responses, response.contexts, response.associations, response.metadata, actual_config, saveDeveloper, response.paraphrasesParenthesized, response.generatedParenthesized, response.summaries)
395
+ writeTest(testsFN, query, saveObjects, response.generated, response.paraphrases, response.responses, response.contexts, response.associations, response.metadata, actualConfig, saveDeveloper, response.paraphrasesParenthesized, response.generatedParenthesized, response.summaries)
396
396
  }
397
397
 
398
398
  return response
@@ -485,7 +485,7 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug, tim
485
485
  setupArgs(args, config)
486
486
  await testConfig.initializer(args)
487
487
  }
488
- const result = await _process(config, test, { errorHandler, isTest: true })
488
+ const result = await _process(config, test, { errorHandler, isTest: true, isProcess: true, isModule: false })
489
489
  result.query = test
490
490
  if (debug) {
491
491
  defaultInnerProcess(config, errorHandler, result)
@@ -499,19 +499,19 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug, tim
499
499
  timings.client += result.clientSideTimes / 1000
500
500
  lines.log()
501
501
  }
502
- const expected_objects = sortJson(convertToStable(expected.objects), { depth: 25 })
503
- delete expected_objects.nameToUUID
504
- const actual_objects = sortJson(convertToStable(config.config.objects), { depth: 25 })
505
- const failed_paraphrases = !matching(result.paraphrases, expected.paraphrases)
506
- let failed_paraphrasesParenthesized = !matching(result.paraphrasesParenthesized, expected.paraphrasesParenthesized)
502
+ const expectedObjects = sortJson(convertToStable(expected.objects), { depth: 25 })
503
+ delete expectedObjects.nameToUUID
504
+ const actualObjects = sortJson(convertToStable(config.config.objects), { depth: 25 })
505
+ const failedParaphrases = !matching(result.paraphrases, expected.paraphrases)
506
+ let failedParaphrasesParenthesized = !matching(result.paraphrasesParenthesized, expected.paraphrasesParenthesized)
507
507
  let failed_generatedParenthesized = !matching(result.generatedParenthesized, expected.generatedParenthesized)
508
508
  // TODO fix the naming conventions: camelcase + use actual instead of result
509
- const failed_responses = !matching(result.responses, expected.responses)
510
- const failed_contexts = !matching(result.contexts, expected.contexts)
511
- const failed_objects = !matching(actual_objects, expected_objects)
509
+ const failedResponses = !matching(result.responses, expected.responses)
510
+ const failedContexts = !matching(result.contexts, expected.contexts)
511
+ const failedObjects = !matching(actualObjects, expectedObjects)
512
512
 
513
513
  if (args.testNoParenthesized) {
514
- failed_paraphrasesParenthesized = false
514
+ failedParaphrasesParenthesized = false
515
515
  failed_generatedParenthesized = false
516
516
  }
517
517
 
@@ -525,23 +525,23 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug, tim
525
525
  }
526
526
  return expected.objects.namespaced[expected.objects.nameToUUID[name]] || {}
527
527
  }
528
- const expected_checked = sortJson(pickObjects(config, testConfig, expectedGetObjects), { depth: 25 })
528
+ const expectedChecked = sortJson(pickObjects(config, testConfig, expectedGetObjects), { depth: 25 })
529
529
  const actualGetObjects = (name) => {
530
530
  if (!name) {
531
531
  name = config.name
532
532
  }
533
- const km = config.configs.find((km) => km.name == name)
533
+ const km = config.configs.find((km) => km.name === name)
534
534
  return config.config.objects.namespaced[km.uuid] || {}
535
535
  }
536
- const actual_checked = sortJson(pickObjects(config, testConfig, actualGetObjects), { depth: 25 })
537
- const failed_checked = !matching(actual_objects, expected_objects)
536
+ const actualChecked = sortJson(pickObjects(config, testConfig, actualGetObjects), { depth: 25 })
537
+ const failedChecked = !matching(actualObjects, expectedObjects)
538
538
 
539
- const failed_checks = !matching(actual_objects, expected_objects)
540
- const failed_checked_objects = !matching(actual_checked, expected_checked)
541
- const actual_config = sortJson(convertToStable(getConfigForTest(config, testConfig)), { depth: 25 })
542
- const expected_config = sortJson(convertToStable(expected.config), { depth: 25 })
543
- const failed_config = !matching(actual_config, expected_config)
544
- const failed = failed_checked_objects || failed_paraphrases || failed_paraphrasesParenthesized || failed_generatedParenthesized || failed_responses || failed_contexts || failed_objects || failed_config || failed_checked || failedCheckedContexts
539
+ const failedChecks = !matching(actualObjects, expectedObjects)
540
+ const failedChecked_objects = !matching(actualChecked, expectedChecked)
541
+ const actualConfig = sortJson(convertToStable(getConfigForTest(config, testConfig)), { depth: 25 })
542
+ const expectedConfig = sortJson(convertToStable(expected.config), { depth: 25 })
543
+ const failedConfig = !matching(actualConfig, expectedConfig)
544
+ const failed = failedChecked_objects || failedParaphrases || failedParaphrasesParenthesized || failed_generatedParenthesized || failedResponses || failedContexts || failedObjects || failedConfig || failedChecked || failedCheckedContexts
545
545
 
546
546
  if (expected.metadata && result.metadata && failed) {
547
547
  const priorities = analyzeMetaData(expected.metadata, result.metadata)
@@ -559,9 +559,9 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug, tim
559
559
  paraphrasesParenthesized: expected.paraphrasesParenthesized,
560
560
  generatedParenthesized: expected.generatedParenthesized,
561
561
  results: expected.contexts,
562
- checked: expected_checked,
562
+ checked: expectedChecked,
563
563
  checkedContexts: pickedExpectedContexts,
564
- objects: expected_objects,
564
+ objects: expectedObjects,
565
565
  config: expected.config,
566
566
  summaries: expected.summaries
567
567
  },
@@ -571,10 +571,10 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug, tim
571
571
  paraphrasesParenthesized: result.paraphrasesParenthesized,
572
572
  generatedParenthesized: result.generatedParenthesized,
573
573
  results: result.contexts,
574
- checked: actual_checked,
574
+ checked: actualChecked,
575
575
  checkedContexts: pickedResultContexts,
576
- objects: actual_objects,
577
- config: actual_config,
576
+ objects: actualObjects,
577
+ config: actualConfig,
578
578
  summaries: result.summaries
579
579
  }
580
580
  }
@@ -624,7 +624,7 @@ const saveTest = async (testFile, config, test, expected, testConfig, saveDevelo
624
624
  await config.rebuild()
625
625
  const objects = getObjects(config.config.objects)(config.uuid)
626
626
  console.log(test)
627
- const result = await _process(config, test, { isTest: true })
627
+ const result = await _process(config, test, { isTest: true, isProcess: true, isModule: true })
628
628
  // const actualObjects = config.config.objects
629
629
  const actualConfig = getConfigForTest(config, testConfig)
630
630
  const args = {
@@ -667,6 +667,7 @@ const showInfo = (description, section, config) => {
667
667
  console.log(JSON.stringify(config.getInfo(), null, 2))
668
668
  }
669
669
 
670
+ /*
670
671
  const submitBugToAPI = async (subscription_id, subscription_password, config) => {
671
672
  console.log('********* Submitting bug *********')
672
673
  const body = { description: config.config.description, config: config.config }
@@ -689,7 +690,6 @@ const submitBugToAPI = async (subscription_id, subscription_password, config) =>
689
690
  })
690
691
  }
691
692
 
692
- /*
693
693
  const submitBug = async (subscription_id, subscription_password, config, utterance, retries = 2) => {
694
694
  // TODO remove these from the config
695
695
  const properties = ['expected_contexts', 'expected_generated']
@@ -862,7 +862,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
862
862
 
863
863
  if (responses.explain_priorities) {
864
864
  console.log('Explain Priorities')
865
- for ([inputs, output, reason] of responses.explain_priorities) {
865
+ for (const [inputs, output, reason] of responses.explain_priorities) {
866
866
  console.log(` inputs: ${JSON.stringify(inputs)} output: ${JSON.stringify(output)} reason: ${reason}`)
867
867
  }
868
868
  }
@@ -871,7 +871,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
871
871
  if (!name) {
872
872
  name = config.name
873
873
  }
874
- const km = config.configs.find((km) => km.name == name)
874
+ const km = config.configs.find((km) => km.name === name)
875
875
  return config.config.objects.namespaced[km.uuid] || {}
876
876
  }
877
877
  const picked = sortJson(pickObjects(config, config.testConfig, actualGetObjects), { depth: 25 })
@@ -967,7 +967,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
967
967
  }
968
968
  config.config.skipSemantics = skipSemantics && !isFragment
969
969
  const transitoryMode = global.transitoryMode
970
- if (isFragment || property == 'fragments') {
970
+ if (isFragment || property === 'fragments') {
971
971
  global.transitoryMode = true
972
972
  }
973
973
  if (hierarchy) {
@@ -991,7 +991,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
991
991
  console.log(getSuggestionMessage(suggestion))
992
992
  }
993
993
  }
994
- if (!rebuild && previousResults && previousResults.query == query.query) {
994
+ if (!rebuild && previousResults && previousResults.query === query.query) {
995
995
  results = previousResults
996
996
  prMessage = ' Using previous results. use -rtf for a hard rebuild of everything on the server side.'
997
997
  await loadInstance(config, { resultss: [results] })
@@ -1139,7 +1139,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
1139
1139
  for (let configsIndex = 0; configsIndex < template.configs.length; ++configsIndex) {
1140
1140
  const query = template.configs[configsIndex]
1141
1141
  // account for things for example associations being added to the config while debugginer
1142
- const pr = previousResultss && previousResultss.find((pr) => pr.query == query)
1142
+ const pr = previousResultss && previousResultss.find((pr) => pr.query === query)
1143
1143
  todo.push({ property: 'resultss', query, previousResults: pr, skipSemantics: false || query.skipSemantics })
1144
1144
  }
1145
1145
  }
@@ -1309,7 +1309,7 @@ const knowledgeModuleImpl = async ({
1309
1309
  parser.add_argument('--parenthesized', { action: 'store_true', help: 'Show the generated phrases with parenthesis.' })
1310
1310
  parser.add_argument('-c', '--clean', { help: 'Remove data from the test files. a === association' })
1311
1311
  parser.add_argument('-od', '--objectDiff', { action: 'store_true', help: 'When showing the objects use a colour diff' })
1312
- 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, g === generators, s === semantics, l === load t=tests ordering p === priorities a == associations j == JSON sent to server. for example --print wb' })
1312
+ 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, g === generators, s === semantics, l === load t=tests ordering p === priorities a === associations j === JSON sent to server. for example --print wb' })
1313
1313
  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.' })
1314
1314
  parser.add_argument('-fr', '--failRebuild', { action: 'store_true', help: 'If a rebuild is required fail out.' })
1315
1315
  parser.add_argument('-sd', '--saveDeveloper', { action: 'store_true', help: 'Same as -s but the query will not show up in the info command.' })
@@ -1361,10 +1361,10 @@ const knowledgeModuleImpl = async ({
1361
1361
  if (what.length !== 2) {
1362
1362
  return false
1363
1363
  }
1364
- if (!typeof what[0] == 'string') {
1364
+ if (!typeof what[0] === 'string') {
1365
1365
  return false
1366
1366
  }
1367
- if (!typeof what[1] == 'number') {
1367
+ if (!typeof what[1] === 'number') {
1368
1368
  return false
1369
1369
  }
1370
1370
  return true
@@ -1682,9 +1682,9 @@ const knowledgeModuleImpl = async ({
1682
1682
  const tidy_summaries = (summaries) => {
1683
1683
  const summaries_prime = []
1684
1684
  for (const chunk of summaries) {
1685
- chunk_prime = { length: chunk.length, summaries: [] }
1685
+ const chunk_prime = { length: chunk.length, summaries: [] }
1686
1686
  for (const summary of chunk.summaries) {
1687
- const summary_prime = { counter: summary.counter, operators: [] }
1687
+ const summary_prime = { counter: summary.counter, operators: [] }
1688
1688
  for (const operator of summary.operators) {
1689
1689
  summary_prime.operators.push(`{ marker: [${operator.marker[0]}, ${operator.marker[1]}] range: { start: ${operator.range.start}, end: ${operator.range.end} } }`)
1690
1690
  }
@@ -1716,7 +1716,7 @@ const knowledgeModuleImpl = async ({
1716
1716
  if (lengths > iDiff) {
1717
1717
  const suggestion = suggestAssociationsFix(result.expected.summaries[iSummaries].summaries, result.actual.summaries[iSummaries].summaries)
1718
1718
  if (suggestion) {
1719
- suggestedFix = suggestion
1719
+ const suggestedFix = suggestion
1720
1720
  // console.log(`Try adding this to the associations: { context: ${JSON.stringify(getSuggestion(suggestedFix))}, choose: <indexOfMainElement> },`)
1721
1721
  console.log(getSuggestionMessage(suggestedFix))
1722
1722
  return
@@ -1856,7 +1856,7 @@ const knowledgeModuleImpl = async ({
1856
1856
  f()
1857
1857
  })
1858
1858
  .catch((e) => {
1859
- if (e.errno == 'ECONNREFUSED') {
1859
+ if (e.errno === 'ECONNREFUSED') {
1860
1860
  console.log(e)
1861
1861
  readline.close()
1862
1862
  } else {
@@ -1880,7 +1880,7 @@ const knowledgeModuleImpl = async ({
1880
1880
  global.beforeObjects = _.cloneDeep(objects)
1881
1881
  }
1882
1882
  try {
1883
- await processResults(_process(config, args.query, { commandLineArgs: args, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
1883
+ await processResults(_process(config, args.query, { commandLineArgs: args, isProcess, isModule: !isProcess, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
1884
1884
  } catch (error) {
1885
1885
  console.log('Error', error)
1886
1886
  }
@@ -1909,8 +1909,18 @@ const knowledgeModuleImpl = async ({
1909
1909
  loadForTesting = true
1910
1910
  }
1911
1911
  }
1912
+ if (template) {
1913
+ try {
1914
+ await config.load(rebuildTemplate, template.template, template.instance)
1915
+ } catch (e) {
1916
+ errorHandler(e)
1917
+ }
1918
+ }
1919
+
1912
1920
  // remove test only stuff
1913
1921
  if (!isProcess && !loadForTesting) {
1922
+ config.removeDevelopmentElements(config.config)
1923
+ /*
1914
1924
  config.config.operators = config.config.operators.filter((operator) => {
1915
1925
  if (operator.development) {
1916
1926
  return false
@@ -1925,21 +1935,15 @@ const knowledgeModuleImpl = async ({
1925
1935
  return true
1926
1936
  }
1927
1937
  })
1938
+ */
1928
1939
  }
1929
1940
 
1930
- if (template) {
1931
- try {
1932
- await config.load(rebuildTemplate, template.template, template.instance)
1933
- } catch (e) {
1934
- errorHandler(e)
1935
- }
1936
- }
1937
1941
  }
1938
1942
 
1939
1943
  // no cache 21 minutes + rebuild fails "node tester_rebuild -m colors"
1940
1944
  // cache okay
1941
- createConfigExport = async () => {
1942
- if (createConfig.cached) {
1945
+ const createConfigExport = async (useCache = true) => {
1946
+ if (useCache && createConfig.cached) {
1943
1947
  return createConfig.cached
1944
1948
  }
1945
1949
  const config = await createConfig()
package/demo.js CHANGED
@@ -34,13 +34,13 @@ let config = {
34
34
  apply: ({ context }) => context.evalue
35
35
  },
36
36
  {
37
- match: ({ context }) => context.marker == 'unknown',
37
+ match: ({ context }) => context.marker === 'unknown',
38
38
  apply: ({ context }) => context.text
39
39
  }
40
40
  ],
41
41
  semantics: [
42
42
  {
43
- match: ({ context }) => context.marker == 'went',
43
+ match: ({ context }) => context.marker === 'went',
44
44
  apply: ({ context }) => {
45
45
  // same way as kms that I wrote. you dont have to do this though
46
46
  context.isResponse = true
package/package.json CHANGED
@@ -69,6 +69,6 @@
69
69
  "sort-json": "^2.0.0",
70
70
  "uuid": "^8.3.2"
71
71
  },
72
- "version": "9.3.0-beta.4",
72
+ "version": "9.3.0-beta.40",
73
73
  "license": "UNLICENSED"
74
74
  }
package/src/config.js CHANGED
@@ -98,7 +98,7 @@ const debugBridge = (bridge) => {
98
98
  return
99
99
  }
100
100
  if (global.entodictonDebugBridge) {
101
- if (global.entodictonDebugBridge == bridge.id) {
101
+ if (global.entodictonDebugBridge === bridge.id) {
102
102
  // debug hierarchy hit
103
103
  debugger // eslint-disable-line no-debugger
104
104
  }
@@ -128,13 +128,13 @@ const debugConfigProps = (config) => {
128
128
  { property: 'priorities', check: (v) => debugPriority(v) },
129
129
  { property: 'associations', check: (v) => debugAssociation(v) },
130
130
  // TODO implement debugWords
131
- { property: 'words', check: (v) => debugWords(v) },
131
+ // { property: 'words', check: (v) => debugWords(v) },
132
132
  { property: 'hierarchy', check: (v) => debugHierarchy(v) },
133
133
  { property: 'operators', check: (v) => debugOperator(v) },
134
134
  { property: 'bridges', check: (v) => debugBridge(v) }
135
135
  ]
136
136
  for (const { property, check } of checkProps) {
137
- if (property == 'associations') {
137
+ if (property === 'associations') {
138
138
  if (config[property]) {
139
139
  if (config[property].negative) {
140
140
  for (const value of config[property].negative) {
@@ -147,7 +147,7 @@ const debugConfigProps = (config) => {
147
147
  }
148
148
  }
149
149
  }
150
- } else if (property == 'words') {
150
+ } else if (property === 'words') {
151
151
  /*
152
152
  if (config[property]) {
153
153
  for (const value of config[property].literals) {
@@ -249,7 +249,7 @@ const operatorKey_valid = (key) => {
249
249
  }
250
250
 
251
251
  const elist = (list, check, prefix) => {
252
- for ([index, element] of list.entries()) {
252
+ for (const [index, element] of list.entries()) {
253
253
  try {
254
254
  check(element)
255
255
  } catch (e) {
@@ -388,7 +388,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
388
388
 
389
389
  const generator = {
390
390
  where: bridge.generatorp.where || bridge.where || helpers.where(4),
391
- match: async (args) => bridge.id == args.context.marker && args.context.level == level && args.context.paraphrase && await match(args),
391
+ match: async (args) => bridge.id === args.context.marker && args.context.level === level && args.context.paraphrase && await match(args),
392
392
  apply: (args) => apply(args),
393
393
  applyWrapped: apply,
394
394
  property: 'generatorp'
@@ -405,7 +405,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
405
405
  const level = bridge.generatorr.level >= 0 ? bridge.generatorr.level : bridge.level + 1
406
406
  const generator = {
407
407
  where: bridge.generatorr.where || bridge.where || helpers.where(4),
408
- match: async (args) => bridge.id == args.context.marker && args.context.level == level && !args.context.paraphrase && (args.context.response || args.context.isResponse) && await match(args),
408
+ match: async (args) => bridge.id === args.context.marker && args.context.level === level && !args.context.paraphrase && (args.context.response || args.context.isResponse) && await match(args),
409
409
  apply: (args) => apply(args),
410
410
  applyWrapped: apply,
411
411
  property: 'generatorr'
@@ -420,13 +420,13 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
420
420
  const addSemantic = (semantic, evaluate) => {
421
421
  const match = semantic.match || (() => true)
422
422
  let apply = semantic
423
- // if I do apply == semantic.apply or semantic there is one function that has apply defined for some reason even though not explicitly set
423
+ // if I do apply === semantic.apply or semantic there is one function that has apply defined for some reason even though not explicitly set
424
424
  if (semantic.apply && typeof semantic !== 'function') {
425
425
  apply = semantic.apply
426
426
  }
427
427
  const semanticDef = {
428
428
  where: semantic.where || bridge.where || helpers.where(4),
429
- match: (args) => bridge.id == args.context.marker && !!args.context.evaluate == evaluate && match(args),
429
+ match: (args) => bridge.id === args.context.marker && !!args.context.evaluate === evaluate && match(args),
430
430
  apply: (args) => apply(args),
431
431
  applyWrapped: semantic,
432
432
  property: evaluate ? 'evaluator' : 'semantic'
@@ -473,7 +473,7 @@ const handleCalculatedProps = (baseConfig, moreConfig, { addFirst, uuid } = {})
473
473
  if (moreConfig.bridges) {
474
474
  moreConfig.bridges = moreConfig.bridges.map((bridge) => {
475
475
  bridge = { ...bridge }
476
- const valid = ['after', 'conditional', 'associations', 'before', 'bridge', 'development', 'skipable', 'return_type_selector', 'evaluator', 'evaluators', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'operator', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
476
+ const valid = ['after', 'conditional', 'associations', 'before', 'bridge', 'disabled', 'development', 'skipable', 'return_type_selector', 'evaluator', 'evaluators', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'operator', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
477
477
  'level', 'optional', 'selector', 'semantic', 'semantics', 'words', /Bridge$/, 'localHierarchy', 'levelSpecificHierarchy', 'where', 'uuid']
478
478
  helpers.validProps(valid, bridge, 'bridge')
479
479
  handleBridgeProps(baseConfig, bridge, { addFirst, uuid })
@@ -577,7 +577,7 @@ const addWord = (config, uuid) => ({ word, id, initial }) => {
577
577
  const normalizeConfig = (config) => {
578
578
  if (config) {
579
579
  if (!config.objects) {
580
- config.objects = { namespaced: {}, }
580
+ config.objects = { namespaced: {} }
581
581
  }
582
582
 
583
583
  for (const bag of bags) {
@@ -966,7 +966,7 @@ class Config {
966
966
  },
967
967
  objects: {
968
968
  // this is where the namespaced configs have their objects
969
- namespaced: {},
969
+ namespaced: {}
970
970
  },
971
971
  description: '',
972
972
  words: {
@@ -1026,7 +1026,7 @@ class Config {
1026
1026
 
1027
1027
  exists (marker) {
1028
1028
  for (const bridge of this.config.bridges) {
1029
- if (bridge.id == marker) {
1029
+ if (bridge.id === marker) {
1030
1030
  return true
1031
1031
  }
1032
1032
  }
@@ -1046,7 +1046,7 @@ class Config {
1046
1046
 
1047
1047
  warningNotEvaluated (log, value) {
1048
1048
  const description = 'WARNING: for semantics, implement an evaluations handler, set "value" property of the operator to the value.'
1049
- const match = `({context}) => context.marker == '${value.marker}' && context.evaluate && <other conditions as you like>`
1049
+ const match = `({context}) => context.marker === '${value.marker}' && context.evaluate && <other conditions as you like>`
1050
1050
  const apply = '({context}) => <do stuff...>; context.value = <value>'
1051
1051
  const input = indent(JSON.stringify(value, null, 2), 2)
1052
1052
  const message = `${description}\nThe semantic would be\n match: ${match}\n apply: ${apply}\nThe input context would be:\n${input}\n`
@@ -1055,8 +1055,8 @@ class Config {
1055
1055
 
1056
1056
  // value is in response field
1057
1057
  // TODO maybe generalize out query+evaluate along the lines of set value and set reference
1058
- async getEvaluator (s, calls, log, context) {
1059
- const instance = await s({ ...context, evaluate: true })
1058
+ async getEvaluator (s, calls, log, context, args) {
1059
+ const instance = await s({ ...args, ...context, evaluate: true })
1060
1060
  calls.touch(instance)
1061
1061
  if (!instance.evalue && !instance.verbatim && !instance.value) {
1062
1062
  this.warningNotEvaluated(log, context)
@@ -1214,43 +1214,6 @@ class Config {
1214
1214
  }
1215
1215
  return bridge
1216
1216
  })
1217
- } else {
1218
- /* done in updateQueries now
1219
- config.generators = (config.generators || []).map((generator) => {
1220
- generator = { ...generator }
1221
- delete generator.where
1222
- generator.match = generator.match.toString()
1223
- generator.apply = generator.apply.toString()
1224
- return generator
1225
- })
1226
- config.semantics = (config.semantics || []).map((semantic) => {
1227
- semantic = { ...semantic }
1228
- delete semantic.where
1229
- semantic.match = semantic.match.toString()
1230
- semantic.apply = semantic.apply.toString()
1231
- return semantic
1232
- })
1233
- config.bridges = (config.bridges || []).map((bridge) => {
1234
- bridge = { ...bridge }
1235
- delete bridge.where
1236
- if (bridge.generatorp) {
1237
- bridge.generatorp = bridge.generatorp.toString()
1238
- }
1239
- if (bridge.generatorr) {
1240
- bridge.generatorr = bridge.generatorr.toString()
1241
- }
1242
- if (bridge.generatorpr) {
1243
- bridge.generatorpr = bridge.generatorpr.toString()
1244
- }
1245
- if (bridge.evaluator) {
1246
- bridge.evaluator = bridge.evaluator.toString()
1247
- }
1248
- if (bridge.semantic) {
1249
- bridge.semantic = bridge.semantic.toString()
1250
- }
1251
- return bridge
1252
- })
1253
- */
1254
1217
  }
1255
1218
  return config
1256
1219
  }
@@ -1331,7 +1294,7 @@ class Config {
1331
1294
  toData (data) {
1332
1295
  Object.assign(data, this.config)
1333
1296
  // greg99 delete data.objects
1334
- data.objects = {...this.config.objects}
1297
+ data.objects = { ...this.config.objects }
1335
1298
  if (!this.sendObjectsToServer) {
1336
1299
  delete data.objects.namespaced
1337
1300
  }
@@ -1490,7 +1453,7 @@ class Config {
1490
1453
  debugHierarchy([child, parent])
1491
1454
  if (this.config.hierarchy.find((element) => {
1492
1455
  const hc = hierarchyCanonical(element)
1493
- if (child == hc.child && parent == hc.parent) {
1456
+ if (child === hc.child && parent === hc.parent) {
1494
1457
  return true
1495
1458
  }
1496
1459
  })) {
@@ -1503,9 +1466,9 @@ class Config {
1503
1466
 
1504
1467
  getBridge (id, level) {
1505
1468
  if (level) {
1506
- return this.config.bridges.find((bridge) => bridge.id == id && bridge.level == level)
1469
+ return this.config.bridges.find((bridge) => bridge.id === id && bridge.level === level)
1507
1470
  } else {
1508
- return this.config.bridges.find((bridge) => bridge.id == id)
1471
+ return this.config.bridges.find((bridge) => bridge.id === id)
1509
1472
  }
1510
1473
  }
1511
1474
 
@@ -1518,8 +1481,8 @@ class Config {
1518
1481
 
1519
1482
  debugBridge(bridge)
1520
1483
  if (bridge.allowDups) {
1521
- // if (bridges.find( (b) => b.id == bridge.id && b.level == bridge.level && b.bridge == bridge.bridge )) {
1522
- if (bridges.find((b) => b.id == bridge.id && b.level == bridge.level)) {
1484
+ // if (bridges.find( (b) => b.id === bridge.id && b.level === bridge.level && b.bridge === bridge.bridge )) {
1485
+ if (bridges.find((b) => b.id === bridge.id && b.level === bridge.level)) {
1523
1486
  return
1524
1487
  }
1525
1488
  }
@@ -1577,8 +1540,14 @@ class Config {
1577
1540
  }
1578
1541
 
1579
1542
  removeSemantic (deleteSemantic) {
1580
- const id = deleteSemantic.id || deleteSemantic
1581
- const todo = [id]
1543
+ if (!Array.isArray(deleteSemantic)) {
1544
+ deleteSemantic = [deleteSemantic]
1545
+ }
1546
+ const todo = []
1547
+ for (const ds of deleteSemantic) {
1548
+ const id = ds.id || ds
1549
+ todo.push(id)
1550
+ }
1582
1551
  const seen = new Set()
1583
1552
 
1584
1553
  while (todo.length > 0) {
@@ -1588,9 +1557,10 @@ class Config {
1588
1557
  }
1589
1558
  seen.add(id)
1590
1559
  const index = this.config.semantics.findIndex((semantic) => semantic.id === id)
1591
- if (index == -1) {
1560
+ if (index === -1) {
1592
1561
  continue
1593
1562
  }
1563
+ // TODO change to tiedIs(s)
1594
1564
  for (const tied_id of this.config.semantics[index].tied_ids || []) {
1595
1565
  if (!seen.has(tied_id)) {
1596
1566
  todo.push(tied_id)
@@ -1619,7 +1589,7 @@ class Config {
1619
1589
  debugOperator(operator)
1620
1590
 
1621
1591
  if (operator.allowDups) {
1622
- if (operators.find((o) => o.pattern == operator.pattern)) {
1592
+ if (operators.find((o) => o.pattern === operator.pattern)) {
1623
1593
  return
1624
1594
  }
1625
1595
  }
@@ -1776,7 +1746,7 @@ class Config {
1776
1746
  if (!config.objects) {
1777
1747
  config.objects = {
1778
1748
  namespaced: {
1779
- },
1749
+ }
1780
1750
  }
1781
1751
  }
1782
1752
 
@@ -1885,7 +1855,7 @@ class Config {
1885
1855
  for (const word in literals) {
1886
1856
  const defs = literals[word] || []
1887
1857
  literals[word] = defs.filter((def) => !def.development)
1888
- if (literals[word].length == 0) {
1858
+ if (literals[word].length === 0) {
1889
1859
  delete literals[word]
1890
1860
  }
1891
1861
  }
@@ -2033,7 +2003,7 @@ class Config {
2033
2003
  debugConfigProps(this.config)
2034
2004
  }
2035
2005
 
2036
- setSendObjectsToServer() {
2006
+ setSendObjectsToServer () {
2037
2007
  this.sendObjectsToServer = true
2038
2008
  }
2039
2009
 
@@ -2110,7 +2080,7 @@ class Config {
2110
2080
  throw new Error('This is intended to be used to instantiate a new class based on the existing API.')
2111
2081
  } else {
2112
2082
  if (name) {
2113
- if (this.name == name) {
2083
+ if (this.name === name) {
2114
2084
  return this._api.constructor
2115
2085
  } else {
2116
2086
  if (!this.getConfig(name)) {
@@ -2150,7 +2120,7 @@ class Config {
2150
2120
  }
2151
2121
  }
2152
2122
 
2153
- setApiKMs(apiKMs) {
2123
+ setApiKMs (apiKMs) {
2154
2124
  this._apiKMs = [...apiKMs]
2155
2125
  }
2156
2126
 
@@ -2190,7 +2160,6 @@ class Config {
2190
2160
  this._apiConstructor = constructor
2191
2161
  if (this._apiKMs.length > 0) {
2192
2162
  for (const name of this._apiKMs) {
2193
- debugger
2194
2163
  this.km(name)._api = value[name]
2195
2164
  }
2196
2165
  } else {
@@ -2269,7 +2238,7 @@ class Config {
2269
2238
  if (this._apiKMs.length > 0) {
2270
2239
  const apis = cp._apiConstructor(cp)
2271
2240
  for (const name of this._apiKMs) {
2272
- if (name == this.name) {
2241
+ if (name === this.name) {
2273
2242
  cp._api = apis[name]
2274
2243
  } else {
2275
2244
  cp.km(name)._api = apis[name]
@@ -2310,8 +2279,8 @@ class Config {
2310
2279
  await cp.rebuild(options) // in copy
2311
2280
  } else {
2312
2281
  if (!cp.config.objects) {
2313
- cp.config.objects = {
2314
- namespaced: {},
2282
+ cp.config.objects = {
2283
+ namespaced: {}
2315
2284
  }
2316
2285
  } else if (!cp.config.objects.namespaced) {
2317
2286
  cp.config.objects.namespaced = {}
@@ -2786,7 +2755,7 @@ class Config {
2786
2755
  const init = initAfterApis[i]
2787
2756
  init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true })
2788
2757
  }
2789
- const instance = this.instances.find((instance) => instance.name == name)
2758
+ const instance = this.instances.find((instance) => instance.name === name)
2790
2759
  if (instance) {
2791
2760
  await configHelpers.loadInstance(this, instance)
2792
2761
  }
@@ -2802,12 +2771,16 @@ class Config {
2802
2771
  }
2803
2772
  }
2804
2773
 
2774
+ if (this.isModule) {
2775
+ this.removeDevelopmentElements(this.config)
2776
+ }
2777
+
2805
2778
  this.valid()
2806
2779
  this.checks()
2807
2780
  }
2808
2781
 
2809
2782
  nameToUUID (name) {
2810
- return this.configs.find((km) => km._name == name)._uuid
2783
+ return this.configs.find((km) => km._name === name)._uuid
2811
2784
  }
2812
2785
 
2813
2786
  // name: namespace name
@@ -3072,7 +3045,7 @@ class Config {
3072
3045
  }
3073
3046
 
3074
3047
  // TODO trie
3075
- if (property == 'words') {
3048
+ if (property === 'words') {
3076
3049
  for (const word in value) {
3077
3050
  for (const def of value[word]) {
3078
3051
  if (!def.uuid) {
@@ -3125,7 +3098,7 @@ class Config {
3125
3098
  const mores = []
3126
3099
  for (const createConfig of createConfigs) {
3127
3100
  const more = await createConfig()
3128
- if (this.name && this.name == more.name) {
3101
+ if (this.name && this.name === more.name) {
3129
3102
  throw new Error('Cannot add an object to itself for argument number ${index+1}.')
3130
3103
  }
3131
3104
  if (this === more) {
@@ -3175,7 +3148,7 @@ class Config {
3175
3148
  })
3176
3149
  const noDups = []
3177
3150
  for (const instance of this.instances) {
3178
- if (!noDups.find((existing) => existing.name == instance.name)) {
3151
+ if (!noDups.find((existing) => existing.name === instance.name)) {
3179
3152
  noDups.push(instance)
3180
3153
  }
3181
3154
  }
@@ -3187,7 +3160,7 @@ class Config {
3187
3160
  }
3188
3161
 
3189
3162
  // TODO get rid of useOldVersion arg
3190
- addInternal (more, { uuid, addFirst = false, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps: hcps = false } = {}) {
3163
+ addInternal (more, { uuid, km, addFirst = false, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps: hcps = false } = {}) {
3191
3164
  validConfigProps(more)
3192
3165
  if (more instanceof Config) {
3193
3166
  more.initialize({ force: false })
@@ -3204,6 +3177,20 @@ class Config {
3204
3177
  handleCalculatedProps(this, more, { addFirst, uuid })
3205
3178
  applyUUID(more, uuid || this._uuid)
3206
3179
  }
3180
+ if (km) {
3181
+ if (more.semantics) {
3182
+ more.semantics.map( (s) => s.km = km )
3183
+ }
3184
+ if (more.generators) {
3185
+ more.generators.map( (g) => g.km = km )
3186
+ }
3187
+ }
3188
+ const normalizeIsA = (edge) => {
3189
+ if (edge.length == 3 || edge.parent || edge.child) {
3190
+ return edge
3191
+ }
3192
+ return [...edge, false]
3193
+ }
3207
3194
  for (const key of Object.keys(more)) {
3208
3195
  const value = more[key]
3209
3196
  // TODO remove name and description on the config bag
@@ -3247,9 +3234,9 @@ class Config {
3247
3234
  const hierarchy = this.config.words.hierarchy
3248
3235
  const moreHierarchy = more.words.hierarchy
3249
3236
  if (addFirst) {
3250
- this.config.words.hierarchy = moreHierarchy.concat(hierarchy)
3237
+ this.config.words.hierarchy = moreHierarchy.concat(hierarchy.map(normalizeIsA))
3251
3238
  } else {
3252
- this.config.words.hierarchy = hierarchy.concat(moreHierarchy)
3239
+ this.config.words.hierarchy = hierarchy.concat(moreHierarchy.map(normalizeIsA))
3253
3240
  }
3254
3241
  }
3255
3242
  } else if (key === 'name') {
@@ -3284,9 +3271,9 @@ class Config {
3284
3271
  }
3285
3272
  } else if (Array.isArray(value)) {
3286
3273
  // handle allowDups
3287
- if (key == 'operators') {
3274
+ if (key === 'operators') {
3288
3275
  // TODO what about other props
3289
- const isDup = (op1, op2) => op1.pattern == op2.pattern
3276
+ const isDup = (op1, op2) => op1.pattern === op2.pattern
3290
3277
  for (const newOne of more[key]) {
3291
3278
  for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
3292
3279
  const oldOne = this.config[key][iOldOne]
@@ -3300,13 +3287,13 @@ class Config {
3300
3287
  }
3301
3288
  }
3302
3289
  }
3303
- if (key == 'bridges') {
3290
+ if (key === 'bridges') {
3304
3291
  // TODO what about other props
3305
- const idDup = (b1, b2) => b1.id == b2.id && b1.level == b2.level && b1.bridge == b2.bridge
3292
+ const idDup = (b1, b2) => b1.id === b2.id && b1.level === b2.level && b1.bridge === b2.bridge
3306
3293
  for (const newOne of more[key]) {
3307
3294
  for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
3308
3295
  const oldOne = this.config[key][iOldOne]
3309
- if (newOne.id == oldOne.id) {
3296
+ if (newOne.id === oldOne.id) {
3310
3297
  if (oldOne.allowDups) {
3311
3298
  // the old one takes precedence to match what would happen during the original load
3312
3299
  this.config[key].splice(iOldOne, 1)
@@ -3320,8 +3307,10 @@ class Config {
3320
3307
  // console.log('key', key, 'XXX')
3321
3308
  // console.log('more', JSON.stringify(more, null, 2))
3322
3309
  // hierarchy must update in place and does not care about the list order
3323
- if (key == 'hierarchy') {
3324
- this.config[key].push(...more[key])
3310
+ if (key === 'hierarchy') {
3311
+ const moreEdges = more[key].map(normalizeIsA)
3312
+ this.config[key].push(...moreEdges)
3313
+ this.hierarchy.addEdges(moreEdges)
3325
3314
  } else {
3326
3315
  if (addFirst) {
3327
3316
  this.config[key] = more[key].concat(this.config[key])
@@ -3421,9 +3410,9 @@ class Config {
3421
3410
  }
3422
3411
  } else if (Array.isArray(value)) {
3423
3412
  // handle allowDups
3424
- if (key == 'operators') {
3413
+ if (key === 'operators') {
3425
3414
  // TODO what about other props
3426
- const isDup = (op1, op2) => op1.pattern == op2.pattern
3415
+ const isDup = (op1, op2) => op1.pattern === op2.pattern
3427
3416
  for (const newOne of more[key]) {
3428
3417
  for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
3429
3418
  const oldOne = this.config[key][iOldOne]
@@ -3437,13 +3426,13 @@ class Config {
3437
3426
  }
3438
3427
  }
3439
3428
  }
3440
- if (key == 'bridges') {
3429
+ if (key === 'bridges') {
3441
3430
  // TODO what about other props
3442
- const idDup = (b1, b2) => b1.id == b2.id && b1.level == b2.level && b1.bridge == b2.bridge
3431
+ const idDup = (b1, b2) => b1.id === b2.id && b1.level === b2.level && b1.bridge === b2.bridge
3443
3432
  for (const newOne of more[key]) {
3444
3433
  for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
3445
3434
  const oldOne = this.config[key][iOldOne]
3446
- if (newOne.id == oldOne.id) {
3435
+ if (newOne.id === oldOne.id) {
3447
3436
  if (oldOne.allowDups) {
3448
3437
  // the old one takes precedence to match what would happen during the original load
3449
3438
  this.config[key].splice(iOldOne, 1)
@@ -140,7 +140,7 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
140
140
  if (!c) {
141
141
  return
142
142
  }
143
- return config.getEvaluator(args.s, args.calls, logs, c)
143
+ return config.getEvaluator(args.s, args.calls, logs, c, { isModule: args.isModule, isProcess: args.isProcess })
144
144
  }
145
145
  args.gs = gs(args.g)
146
146
  args.gsp = gs(args.gp)
@@ -257,18 +257,18 @@ const setupProcessB = ({ config, initializer, allowDelta = false, rebuildingTemp
257
257
  const setupContexts = (rawContexts) => {
258
258
  let first = true
259
259
  const contexts = []
260
- contexts.push({ marker: 'controlStart', controlRemove: true })
260
+ contexts.push({ marker: 'controlStart', controlRemove: true, isControl: true })
261
261
  let previous
262
262
  for (const context of rawContexts) {
263
263
  if (first) {
264
264
  first = false
265
265
  } else {
266
- contexts.push({ marker: 'controlBetween', controlRemove: true, previous })
266
+ contexts.push({ marker: 'controlBetween', controlRemove: true, isControl: true, previous })
267
267
  }
268
268
  contexts.push(context)
269
269
  previous = context
270
270
  }
271
- contexts.push({ marker: 'controlEnd', controlRemove: true, previous })
271
+ contexts.push({ marker: 'controlEnd', controlRemove: true, isControl: true, previous })
272
272
 
273
273
  let _index = 0
274
274
  const id = (context) => {
@@ -279,7 +279,7 @@ const setupContexts = (rawContexts) => {
279
279
  return contexts
280
280
  }
281
281
 
282
- const processContextsB = async ({ config, hierarchy, semantics, generators, json, isTest, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs, forTemplate }) => {
282
+ const processContextsB = async ({ config, hierarchy, semantics, generators, json, isTest, isProcess, isModule, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs, forTemplate }) => {
283
283
  // TODO fix this name to contextsPrime
284
284
  const contextsPrime = []
285
285
  const generatedPrime = []
@@ -290,7 +290,7 @@ const processContextsB = async ({ config, hierarchy, semantics, generators, json
290
290
  const contexts = setupContexts(json.contexts)
291
291
 
292
292
  const objects = config.get('objects')
293
- const args = { objects, isResponse: true, response: json, isTest, isInstance, getObjects: getObjects(objects), instance, contexts }
293
+ const args = { objects, isResponse: true, response: json, isTest, isInstance, getObjects: getObjects(objects), instance, contexts, isProcess, isModule }
294
294
  if (!json.logs) {
295
295
  json.logs = []
296
296
  }
@@ -424,7 +424,7 @@ const loadInstance = async (config, instance) => {
424
424
  */
425
425
  const rl = instance.resultss.length
426
426
  if (rl > 0) {
427
- config.addAssociations(instance.resultss[instance.resultss.length-1].rtf_associations || [])
427
+ config.addAssociations(instance.resultss[instance.resultss.length - 1].rtf_associations || [])
428
428
  }
429
429
  /*
430
430
  TODO needs updating if still wanted
@@ -441,14 +441,14 @@ const loadInstance = async (config, instance) => {
441
441
  */
442
442
 
443
443
  // const { /* data, generators, semantics, */ hierarchy } = setupProcessB({ config })
444
- const hierarchy = config.hierarchy
445
444
  for (const i in (instance.resultss || [])) {
445
+ const hierarchy = config.hierarchy
446
446
  const results = instance.resultss[i]
447
447
  if (results.extraConfig) {
448
448
  // config.addInternal(results, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false)
449
449
  const uuid = config.nameToUUID(instance.name)
450
450
  // used to do a CLONE
451
- config.addInternal(instance.template.configs[i], { uuid, addFirst: true, handleCalculatedProps: true })
451
+ config.addInternal(instance.template.configs[i], { uuid, km: instance.name, addFirst: true, handleCalculatedProps: true })
452
452
  } else if (results.apply) {
453
453
  const objects = getObjects(config.get('objects'))(config.uuid)
454
454
  const args = { objects, getObjects: getObjects(objects) }
@@ -468,6 +468,8 @@ const loadInstance = async (config, instance) => {
468
468
  const args = { config, hierarchy, json: results, commandLineArgs: {}, forTemplate: true }
469
469
  args.isInstance = `instance${i}`
470
470
  args.instance = ''
471
+ args.isProcess = !config.isModule
472
+ args.isModule = !!config.isModule
471
473
  await processContextsB(args)
472
474
  if (results.skipSemantics) {
473
475
  config.config.skipSemantics = null
package/src/debug.js CHANGED
@@ -31,12 +31,12 @@ const wasHit = (name) => {
31
31
  return hits[name]
32
32
  }
33
33
 
34
- const counter = (name, breakAt = [], debugBreak = true) => {
34
+ const counter = (name, { breakAt=[], debugBreak=true, tag='' } = {}) => {
35
35
  if (!counters[name]) {
36
36
  counters[name] = 0
37
37
  }
38
38
  counters[name] += 1
39
- console.log(`counters[${name}] = ${counters[name]}`)
39
+ console.log(`counters[${name}] = ${counters[name]} ${tag}`)
40
40
  unhit(name)
41
41
  if (Array.isArray(breakAt) && breakAt.includes(counters[name])) {
42
42
  if (debugBreak) {
package/src/digraph.js CHANGED
@@ -22,7 +22,7 @@ class Digraph {
22
22
  while (Object.keys(frontier).length > 0) {
23
23
  const n = Object.keys(frontier)[0]
24
24
  const ps = frontier[n]
25
- if (to == n) {
25
+ if (to === n) {
26
26
  return ps[0]
27
27
  }
28
28
  if (done.has(n)) {
@@ -184,7 +184,7 @@ class Digraph {
184
184
  }
185
185
 
186
186
  exists (child, parent) {
187
- return this._edges.find((edge) => edge[0] == child && edge[1] == parent)
187
+ return this._edges.find((edge) => edge[0] === child && edge[1] === parent)
188
188
  }
189
189
 
190
190
  addList (l) {
@@ -24,7 +24,7 @@ class DigraphInternal {
24
24
  addEdge (edge) {
25
25
  edge = toA(edge)
26
26
  // if (this._edges.find((existing) => _.isEqual(edge, existing))) {
27
- if (this._edges.find((existing) => edge[0] == existing[0] && edge[1] == existing[1])) {
27
+ if (this._edges.find((existing) => edge[0] === existing[0] && edge[1] === existing[1])) {
28
28
  return false
29
29
  }
30
30
  this._edges.push(edge)
@@ -154,7 +154,7 @@ class DigraphInternal {
154
154
  }
155
155
 
156
156
  exists (child, parent) {
157
- return this._edges.findIndex((edge) => edge[0] == child && edge[1] == parent) != -1
157
+ return this._edges.findIndex((edge) => edge[0] === child && edge[1] === parent) != -1
158
158
  }
159
159
 
160
160
  addList (l) {
package/src/flatten.js CHANGED
@@ -92,7 +92,7 @@ const flatten = (markers, value) => {
92
92
  const split = markers.includes(marker)
93
93
  if (split) {
94
94
  if ('value' in properties) {
95
- flattenedValues = []
95
+ let flattenedValues = []
96
96
  for (const v of properties.value) {
97
97
  if (v.flatten) {
98
98
  flattenedValues = flattenedValues.concat(flatten(markers, v)[0])
package/src/generators.js CHANGED
@@ -65,7 +65,7 @@ class Generator {
65
65
  // return this.match(args)
66
66
  const matches = await this.match(args)
67
67
  if ((matches && (options.debug || {}).match) ||
68
- callId == this.callId) {
68
+ callId === this.callId) {
69
69
  // next line is the matcher
70
70
  debugger // eslint-disable-line no-debugger
71
71
  await this.match(args)
@@ -78,7 +78,7 @@ class Generator {
78
78
  if (!log) {
79
79
  throw new Error('generators.apply argument log is required')
80
80
  }
81
- if (baseArgs.call && config && sbaseArgs.calls.stack.length > config.maxDepth) {
81
+ if (baseArgs.call && config && baseArgs.calls.stack.length > config.maxDepth) {
82
82
  throw new Error(`Max depth of ${config.maxDepth} for calls has been exceeded. maxDepth can be set on the config object. To see the calls run with the --dl or set the debugLoops property on the config`)
83
83
  }
84
84
 
@@ -116,11 +116,11 @@ class Generator {
116
116
  apis: this.getAPIs(config)
117
117
  }
118
118
  const args = Object.assign({}, baseArgs, moreArgs, (baseArgs.getUUIDScoped || (() => { return {} }))(this.uuid))
119
- if (this.property == 'generatorp') {
119
+ if (this.property === 'generatorp') {
120
120
  args.g = args.gp
121
121
  }
122
122
  if ((options.debug || {}).apply ||
123
- callId == this.callId) {
123
+ callId === this.callId) {
124
124
  debugger // eslint-disable-line no-debugger
125
125
  }
126
126
  return await this._apply(args)
@@ -218,7 +218,7 @@ class Generators {
218
218
  lines.setElement(0, 2, stack)
219
219
  lines.newRow()
220
220
  lines.setElement(0, 1, 'DEBUG')
221
- lines.setElement(0, 2, `To debug this use args.callId == '${args.calls.current()}'`)
221
+ lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
222
222
  lines.newRow()
223
223
  lines.setElement(0, 1, 'ERROR')
224
224
  lines.setElement(0, 2, errorMessage)
@@ -250,7 +250,7 @@ class Generators {
250
250
  lines.setElement(0, 2, stack)
251
251
  lines.newRow()
252
252
  lines.setElement(0, 1, 'DEBUG')
253
- lines.setElement(0, 2, `To debug this use args.callId == '${args.calls.current()}'`)
253
+ lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
254
254
  lines.newRow()
255
255
  lines.setElement(0, 1, 'TO')
256
256
  lines.setElement(0, 2, `context_id: ${context.context_id}`)
package/src/helpers.js CHANGED
@@ -97,7 +97,7 @@ const appendNoDups = (l1, l2) => {
97
97
  }
98
98
 
99
99
  const safeNoDups = (list) => {
100
- noDups = []
100
+ const noDups = []
101
101
  for (const element of list) {
102
102
  if (!noDups.find((e) => safeEquals(e, element))) {
103
103
  noDups.push(element)
@@ -112,14 +112,14 @@ const safeEquals = (v1, v2) => {
112
112
  }
113
113
 
114
114
  const type = typeof v1
115
- if (type == 'number' || type == 'string') {
116
- return v1 == v2
117
- } else if (type == 'function') {
118
- return v1.toString() == v2.toString()
115
+ if (type === 'number' || type === 'string') {
116
+ return v1 === v2
117
+ } else if (type === 'function') {
118
+ return v1.toString() === v2.toString()
119
119
  } else if (v1 == undefined || v2 == undefined) {
120
- return v1 == v2
120
+ return v1 === v2
121
121
  } else {
122
- if (v1.length != v2.length) {
122
+ if (v1.length !== v2.length) {
123
123
  return false
124
124
  }
125
125
  for (const key in v1) {
@@ -148,7 +148,7 @@ const semanticsGenerate = (from, known) => {
148
148
  }
149
149
 
150
150
  return {
151
- match: ({context}) => marker == marker,
151
+ match: ({context}) => marker === marker,
152
152
  apply: ({context}) => {
153
153
  },
154
154
  }
@@ -299,9 +299,9 @@ const sortJson = (json) => {
299
299
  const validProps = (valids, object, type) => {
300
300
  for (const prop of Object.keys(object)) {
301
301
  let okay = false
302
- for (valid of valids) {
302
+ for (const valid of valids) {
303
303
  if (typeof valid === 'string') {
304
- okay = prop == valid
304
+ okay = prop === valid
305
305
  } else {
306
306
  okay = prop.match(valid)
307
307
  }
@@ -310,6 +310,7 @@ const validProps = (valids, object, type) => {
310
310
  }
311
311
  }
312
312
  if (!okay) {
313
+ valids.sort()
313
314
  throw new Error(`Unknown property "${prop}" in the ${type}. Valid properties are ${valids.join(', ')}. The ${type} is ${JSON.stringify(object)}`)
314
315
  }
315
316
  }
@@ -334,7 +335,7 @@ const updateQueries = (queryOrConfig) => {
334
335
 
335
336
  const functionsToStrings = (config) => {
336
337
  config = { ...config }
337
- defToStrings = (def) => {
338
+ const defToStrings = (def) => {
338
339
  if (def.apply) {
339
340
  // return { ...def, match: def.match.toString(), apply: def.apply.toString() }
340
341
  return { match: def.match.toString(), apply: def.apply.toString() }
@@ -390,7 +391,7 @@ const ecatch = (where, call) => {
390
391
  }
391
392
 
392
393
  const equalKey = (key1, key2) => {
393
- return key1[0] == key2[0] && key1[1] == key2[1]
394
+ return key1[0] === key2[0] && key1[1] === key2[1]
394
395
  }
395
396
 
396
397
  // matches for { context: ..., [ordered], choose: ... } exactely OR
@@ -399,8 +400,8 @@ const subPriority = (sub, sup) => {
399
400
  if (Array.isArray(sub)) {
400
401
  const subChoosen = sub[0]
401
402
  const subOther = sub[1]
402
- const hasChoosen = sup.choose.find((index) => equalKey(sup.context[index], subChoosen)) != undefined
403
- const hasOtherChosen = sup.choose.find((index) => equalKey(sup.context[index], subOther)) != undefined
403
+ const hasChoosen = sup.choose.find((index) => equalKey(sup.context[index], subChoosen)) !== undefined
404
+ const hasOtherChosen = sup.choose.find((index) => equalKey(sup.context[index], subOther)) !== undefined
404
405
  const hasOther = sup.context.find((other) => equalKey(other, subOther)) !== undefined
405
406
  return !!(hasChoosen && hasOther) && !hasOtherChosen
406
407
  }
@@ -418,7 +419,7 @@ const subPriority = (sub, sup) => {
418
419
  }
419
420
  const chosen1 = choose(sub)
420
421
  const chosen2 = choose(sup)
421
- const sameId = (id1, id2) => id1[0] == id2[0] && id1[1] == id2[1]
422
+ const sameId = (id1, id2) => id1[0] === id2[0] && id1[1] === id2[1]
422
423
  // same length so only need one way
423
424
  const missing1 = chosen1.find((id1) => !chosen2.find((id2) => sameId(id1, id2)))
424
425
  if (missing1) {
package/src/project.js CHANGED
@@ -3,6 +3,9 @@ const project = (object, filter) => {
3
3
  if (!object) {
4
4
  return
5
5
  }
6
+ if (typeof object == 'string' || typeof object == 'number') {
7
+ return object
8
+ }
6
9
 
7
10
  const projection = {}
8
11
  const set = (property, value) => {
package/src/semantics.js CHANGED
@@ -72,7 +72,7 @@ class Semantic {
72
72
  async matches (args, context, options = {}) {
73
73
  this.fixUpArgs(args, context)
74
74
  const matches = await this.matcher(args)
75
- if (matches && (options.debug || {}).match || args.callId == this.callId) {
75
+ if (matches && (options.debug || {}).match || args.callId === this.callId) {
76
76
  // next line is the matcher
77
77
  debugger // eslint-disable-line no-debugger
78
78
  await this.matcher(args)
@@ -92,7 +92,7 @@ class Semantic {
92
92
  const contextPrime = Object.assign({}, context)
93
93
  this.fixUpArgs(args, contextPrime)
94
94
 
95
- if ((options.debug || {}).apply || args.callId == this.callId) {
95
+ if ((options.debug || {}).apply || args.callId === this.callId) {
96
96
  debugger // eslint-disable-line no-debugger
97
97
  }
98
98
  if (args.breakOnSemantics) {
@@ -234,7 +234,7 @@ class Semantics {
234
234
  lines.setElement(0, 2, stack)
235
235
  lines.newRow()
236
236
  lines.setElement(0, 1, 'DEBUG')
237
- lines.setElement(0, 2, `To debug this use args.callId == '${args.calls.current()}'`)
237
+ lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
238
238
  lines.newRow()
239
239
  lines.setElement(0, 1, 'ERROR')
240
240
  lines.setElement(0, 2, errorMessage)
@@ -269,7 +269,7 @@ class Semantics {
269
269
  lines.setElement(0, 2, stack)
270
270
  lines.newRow()
271
271
  lines.setElement(0, 1, 'DEBUG')
272
- lines.setElement(0, 2, `To debug this use args.callId == '${args.calls.current()}'`)
272
+ lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
273
273
  lines.newRow()
274
274
  lines.setElement(0, 1, 'RESULT')
275
275
  lines.setElement(0, 2, `context_id: ${context.context_id}`)
package/src/unflatten.js CHANGED
@@ -36,7 +36,7 @@ const concatLists = (l1, l2) => {
36
36
 
37
37
  const findPropertyWithManyValues = (contexts, properties) => {
38
38
  for (const property of properties) {
39
- if (new Set(contexts.map((context) => context[property])).size == 1) {
39
+ if (new Set(contexts.map((context) => context[property])).size === 1) {
40
40
  return property
41
41
  }
42
42
  }