theprogrammablemind_4wp 9.3.0 → 9.4.0

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/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) {
@@ -335,6 +335,22 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
335
335
  config.addPriority({ context: [[bridge.id, bridge.level], after], choose: [0] })
336
336
  }
337
337
  }
338
+ if (bridge.check) {
339
+ if (!config.testConfig) {
340
+ config.testConfig = {}
341
+ }
342
+ if (!config.testConfig.checks) {
343
+ config.testConfig.checks = {}
344
+ }
345
+ if (!config.testConfig?.checks?.context) {
346
+ config.testConfig.checks.context = []
347
+ }
348
+ config.testConfig.checks.context.push({
349
+ match: ({context}) => context.marker == bridge.id,
350
+ exported: true,
351
+ apply: ({context}) => bridge.check,
352
+ })
353
+ }
338
354
  if (bridge.after) {
339
355
  for (let before of bridge.after) {
340
356
  if (typeof before === 'string') {
@@ -388,7 +404,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
388
404
 
389
405
  const generator = {
390
406
  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),
407
+ match: async (args) => bridge.id === args.context.marker && args.context.level === level && args.context.paraphrase && await match(args),
392
408
  apply: (args) => apply(args),
393
409
  applyWrapped: apply,
394
410
  property: 'generatorp'
@@ -405,7 +421,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
405
421
  const level = bridge.generatorr.level >= 0 ? bridge.generatorr.level : bridge.level + 1
406
422
  const generator = {
407
423
  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),
424
+ 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
425
  apply: (args) => apply(args),
410
426
  applyWrapped: apply,
411
427
  property: 'generatorr'
@@ -420,13 +436,13 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
420
436
  const addSemantic = (semantic, evaluate) => {
421
437
  const match = semantic.match || (() => true)
422
438
  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
439
+ // 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
440
  if (semantic.apply && typeof semantic !== 'function') {
425
441
  apply = semantic.apply
426
442
  }
427
443
  const semanticDef = {
428
444
  where: semantic.where || bridge.where || helpers.where(4),
429
- match: (args) => bridge.id == args.context.marker && !!args.context.evaluate == evaluate && match(args),
445
+ match: (args) => bridge.id === args.context.marker && !!args.context.evaluate === evaluate && match(args),
430
446
  apply: (args) => apply(args),
431
447
  applyWrapped: semantic,
432
448
  property: evaluate ? 'evaluator' : 'semantic'
@@ -473,7 +489,7 @@ const handleCalculatedProps = (baseConfig, moreConfig, { addFirst, uuid } = {})
473
489
  if (moreConfig.bridges) {
474
490
  moreConfig.bridges = moreConfig.bridges.map((bridge) => {
475
491
  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',
492
+ const valid = ['after', 'conditional', 'associations', 'before', 'bridge', 'check', 'disabled', 'development', 'skipable', 'return_type_selector', 'evaluator', 'evaluators', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'operator', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
477
493
  'level', 'optional', 'selector', 'semantic', 'semantics', 'words', /Bridge$/, 'localHierarchy', 'levelSpecificHierarchy', 'where', 'uuid']
478
494
  helpers.validProps(valid, bridge, 'bridge')
479
495
  handleBridgeProps(baseConfig, bridge, { addFirst, uuid })
@@ -577,7 +593,7 @@ const addWord = (config, uuid) => ({ word, id, initial }) => {
577
593
  const normalizeConfig = (config) => {
578
594
  if (config) {
579
595
  if (!config.objects) {
580
- config.objects = { namespaced: {}, }
596
+ config.objects = { namespaced: {} }
581
597
  }
582
598
 
583
599
  for (const bag of bags) {
@@ -878,6 +894,7 @@ class Config {
878
894
  getInfo () {
879
895
  const name = this.name
880
896
  const includes = this.configs.slice(1).map((km) => km.config.name)
897
+ includes.sort()
881
898
  const visibleExamples = []
882
899
  for (const test of this.tests) {
883
900
  if (!test.developerTest) {
@@ -966,7 +983,7 @@ class Config {
966
983
  },
967
984
  objects: {
968
985
  // this is where the namespaced configs have their objects
969
- namespaced: {},
986
+ namespaced: {}
970
987
  },
971
988
  description: '',
972
989
  words: {
@@ -1026,7 +1043,7 @@ class Config {
1026
1043
 
1027
1044
  exists (marker) {
1028
1045
  for (const bridge of this.config.bridges) {
1029
- if (bridge.id == marker) {
1046
+ if (bridge.id === marker) {
1030
1047
  return true
1031
1048
  }
1032
1049
  }
@@ -1046,7 +1063,7 @@ class Config {
1046
1063
 
1047
1064
  warningNotEvaluated (log, value) {
1048
1065
  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>`
1066
+ const match = `({context}) => context.marker === '${value.marker}' && context.evaluate && <other conditions as you like>`
1050
1067
  const apply = '({context}) => <do stuff...>; context.value = <value>'
1051
1068
  const input = indent(JSON.stringify(value, null, 2), 2)
1052
1069
  const message = `${description}\nThe semantic would be\n match: ${match}\n apply: ${apply}\nThe input context would be:\n${input}\n`
@@ -1055,8 +1072,8 @@ class Config {
1055
1072
 
1056
1073
  // value is in response field
1057
1074
  // 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 })
1075
+ async getEvaluator (s, calls, log, context, args) {
1076
+ const instance = await s({ ...args, ...context, evaluate: true })
1060
1077
  calls.touch(instance)
1061
1078
  if (!instance.evalue && !instance.verbatim && !instance.value) {
1062
1079
  this.warningNotEvaluated(log, context)
@@ -1214,43 +1231,6 @@ class Config {
1214
1231
  }
1215
1232
  return bridge
1216
1233
  })
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
1234
  }
1255
1235
  return config
1256
1236
  }
@@ -1328,10 +1308,19 @@ class Config {
1328
1308
  }
1329
1309
  }
1330
1310
 
1311
+ addEnable (key) {
1312
+ this._enable.push(key)
1313
+ }
1314
+
1315
+ updateData (data) {
1316
+ data.enable = this._enable
1317
+ this._enable = []
1318
+ }
1319
+
1331
1320
  toData (data) {
1332
1321
  Object.assign(data, this.config)
1333
1322
  // greg99 delete data.objects
1334
- data.objects = {...this.config.objects}
1323
+ data.objects = { ...this.config.objects }
1335
1324
  if (!this.sendObjectsToServer) {
1336
1325
  delete data.objects.namespaced
1337
1326
  }
@@ -1490,7 +1479,7 @@ class Config {
1490
1479
  debugHierarchy([child, parent])
1491
1480
  if (this.config.hierarchy.find((element) => {
1492
1481
  const hc = hierarchyCanonical(element)
1493
- if (child == hc.child && parent == hc.parent) {
1482
+ if (child === hc.child && parent === hc.parent) {
1494
1483
  return true
1495
1484
  }
1496
1485
  })) {
@@ -1503,9 +1492,9 @@ class Config {
1503
1492
 
1504
1493
  getBridge (id, level) {
1505
1494
  if (level) {
1506
- return this.config.bridges.find((bridge) => bridge.id == id && bridge.level == level)
1495
+ return this.config.bridges.find((bridge) => bridge.id === id && bridge.level === level)
1507
1496
  } else {
1508
- return this.config.bridges.find((bridge) => bridge.id == id)
1497
+ return this.config.bridges.find((bridge) => bridge.id === id)
1509
1498
  }
1510
1499
  }
1511
1500
 
@@ -1518,8 +1507,8 @@ class Config {
1518
1507
 
1519
1508
  debugBridge(bridge)
1520
1509
  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)) {
1510
+ // if (bridges.find( (b) => b.id === bridge.id && b.level === bridge.level && b.bridge === bridge.bridge )) {
1511
+ if (bridges.find((b) => b.id === bridge.id && b.level === bridge.level)) {
1523
1512
  return
1524
1513
  }
1525
1514
  }
@@ -1577,8 +1566,14 @@ class Config {
1577
1566
  }
1578
1567
 
1579
1568
  removeSemantic (deleteSemantic) {
1580
- const id = deleteSemantic.id || deleteSemantic
1581
- const todo = [id]
1569
+ if (!Array.isArray(deleteSemantic)) {
1570
+ deleteSemantic = [deleteSemantic]
1571
+ }
1572
+ const todo = []
1573
+ for (const ds of deleteSemantic) {
1574
+ const id = ds.id || ds
1575
+ todo.push(id)
1576
+ }
1582
1577
  const seen = new Set()
1583
1578
 
1584
1579
  while (todo.length > 0) {
@@ -1588,9 +1583,10 @@ class Config {
1588
1583
  }
1589
1584
  seen.add(id)
1590
1585
  const index = this.config.semantics.findIndex((semantic) => semantic.id === id)
1591
- if (index == -1) {
1586
+ if (index === -1) {
1592
1587
  continue
1593
1588
  }
1589
+ // TODO change to tiedIs(s)
1594
1590
  for (const tied_id of this.config.semantics[index].tied_ids || []) {
1595
1591
  if (!seen.has(tied_id)) {
1596
1592
  todo.push(tied_id)
@@ -1619,7 +1615,7 @@ class Config {
1619
1615
  debugOperator(operator)
1620
1616
 
1621
1617
  if (operator.allowDups) {
1622
- if (operators.find((o) => o.pattern == operator.pattern)) {
1618
+ if (operators.find((o) => o.pattern === operator.pattern)) {
1623
1619
  return
1624
1620
  }
1625
1621
  }
@@ -1776,7 +1772,7 @@ class Config {
1776
1772
  if (!config.objects) {
1777
1773
  config.objects = {
1778
1774
  namespaced: {
1779
- },
1775
+ }
1780
1776
  }
1781
1777
  }
1782
1778
 
@@ -1885,7 +1881,7 @@ class Config {
1885
1881
  for (const word in literals) {
1886
1882
  const defs = literals[word] || []
1887
1883
  literals[word] = defs.filter((def) => !def.development)
1888
- if (literals[word].length == 0) {
1884
+ if (literals[word].length === 0) {
1889
1885
  delete literals[word]
1890
1886
  }
1891
1887
  }
@@ -1951,6 +1947,7 @@ class Config {
1951
1947
  config.priorities = config.priorities || []
1952
1948
  }
1953
1949
 
1950
+ this._enable = []
1954
1951
  this._apiKMs = apiKMs
1955
1952
 
1956
1953
  this.clientProcess = clientProcess
@@ -2033,7 +2030,7 @@ class Config {
2033
2030
  debugConfigProps(this.config)
2034
2031
  }
2035
2032
 
2036
- setSendObjectsToServer() {
2033
+ setSendObjectsToServer () {
2037
2034
  this.sendObjectsToServer = true
2038
2035
  }
2039
2036
 
@@ -2110,9 +2107,12 @@ class Config {
2110
2107
  throw new Error('This is intended to be used to instantiate a new class based on the existing API.')
2111
2108
  } else {
2112
2109
  if (name) {
2113
- if (this.name == name) {
2110
+ if (this.name === name) {
2114
2111
  return this._api.constructor
2115
2112
  } else {
2113
+ if (!this.getConfig(name)) {
2114
+ throw new Error(`Config.apiBase: The requested KM '${name}' has not been loaded`)
2115
+ }
2116
2116
  return this.getConfig(name)._api.constructor
2117
2117
  }
2118
2118
  } else {
@@ -2147,7 +2147,12 @@ class Config {
2147
2147
  }
2148
2148
  }
2149
2149
 
2150
+ setApiKMs (apiKMs) {
2151
+ this._apiKMs = [...apiKMs]
2152
+ }
2153
+
2150
2154
  // constructors is a constructor
2155
+ // TODO fix Api to be API WTF
2151
2156
  async setApi (constructor) {
2152
2157
  if (typeof constructor !== 'function') {
2153
2158
  throw new Error(`Expected the argument to be an API constructor for ${this.name}.`)
@@ -2165,7 +2170,7 @@ class Config {
2165
2170
  }
2166
2171
  } else {
2167
2172
  if (!value.initialize) {
2168
- throw new Error(`Expected the API to have an initialize function for ${this.name}.`)
2173
+ throw new Error(`Expected the API to have an initialize function for ${this.name}. If you are trying to pass in multiple API configs at once use setApiKMs to set the names of the configs that you want set.`)
2169
2174
  }
2170
2175
  }
2171
2176
 
@@ -2260,7 +2265,7 @@ class Config {
2260
2265
  if (this._apiKMs.length > 0) {
2261
2266
  const apis = cp._apiConstructor(cp)
2262
2267
  for (const name of this._apiKMs) {
2263
- if (name == this.name) {
2268
+ if (name === this.name) {
2264
2269
  cp._api = apis[name]
2265
2270
  } else {
2266
2271
  cp.km(name)._api = apis[name]
@@ -2301,8 +2306,8 @@ class Config {
2301
2306
  await cp.rebuild(options) // in copy
2302
2307
  } else {
2303
2308
  if (!cp.config.objects) {
2304
- cp.config.objects = {
2305
- namespaced: {},
2309
+ cp.config.objects = {
2310
+ namespaced: {}
2306
2311
  }
2307
2312
  } else if (!cp.config.objects.namespaced) {
2308
2313
  cp.config.objects.namespaced = {}
@@ -2608,6 +2613,24 @@ class Config {
2608
2613
  })
2609
2614
  }
2610
2615
 
2616
+ getContextChecks() {
2617
+ const allChecks = []
2618
+ for (const name of this.loadOrdering) {
2619
+ const checks = this.kms[name].testConfig?.checks?.context || []
2620
+ for (const check of checks) {
2621
+ if (check.exported) {
2622
+ allChecks.push(check)
2623
+ }
2624
+ }
2625
+ }
2626
+ for (const check of this.testConfig?.checks?.context || []) {
2627
+ if (!check.exported) {
2628
+ allChecks.push(check)
2629
+ }
2630
+ }
2631
+ return allChecks
2632
+ }
2633
+
2611
2634
  // rebuild ({ isModule: mainIsModule = false } = {}) {
2612
2635
  async rebuild ({ isModule: mainIsModule } = {}) {
2613
2636
  if (this._stop_auto_rebuild) {
@@ -2635,6 +2658,7 @@ class Config {
2635
2658
  // reorder configs base on load ordering
2636
2659
  {
2637
2660
  const ordering = this.loadOrder.order(this.configs.map((km) => km.name || km.uuid))
2661
+ this.loadOrdering = ordering
2638
2662
  const oconfigs = []
2639
2663
  for (const nameOrUUID of ordering) {
2640
2664
  for (const km of this.configs) {
@@ -2777,7 +2801,7 @@ class Config {
2777
2801
  const init = initAfterApis[i]
2778
2802
  init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true })
2779
2803
  }
2780
- const instance = this.instances.find((instance) => instance.name == name)
2804
+ const instance = this.instances.find((instance) => instance.name === name)
2781
2805
  if (instance) {
2782
2806
  await configHelpers.loadInstance(this, instance)
2783
2807
  }
@@ -2793,12 +2817,16 @@ class Config {
2793
2817
  }
2794
2818
  }
2795
2819
 
2820
+ if (this.isModule) {
2821
+ this.removeDevelopmentElements(this.config)
2822
+ }
2823
+
2796
2824
  this.valid()
2797
2825
  this.checks()
2798
2826
  }
2799
2827
 
2800
2828
  nameToUUID (name) {
2801
- return this.configs.find((km) => km._name == name)._uuid
2829
+ return this.configs.find((km) => km._name === name)._uuid
2802
2830
  }
2803
2831
 
2804
2832
  // name: namespace name
@@ -3063,7 +3091,7 @@ class Config {
3063
3091
  }
3064
3092
 
3065
3093
  // TODO trie
3066
- if (property == 'words') {
3094
+ if (property === 'words') {
3067
3095
  for (const word in value) {
3068
3096
  for (const def of value[word]) {
3069
3097
  if (!def.uuid) {
@@ -3116,7 +3144,7 @@ class Config {
3116
3144
  const mores = []
3117
3145
  for (const createConfig of createConfigs) {
3118
3146
  const more = await createConfig()
3119
- if (this.name && this.name == more.name) {
3147
+ if (this.name && this.name === more.name) {
3120
3148
  throw new Error('Cannot add an object to itself for argument number ${index+1}.')
3121
3149
  }
3122
3150
  if (this === more) {
@@ -3166,7 +3194,7 @@ class Config {
3166
3194
  })
3167
3195
  const noDups = []
3168
3196
  for (const instance of this.instances) {
3169
- if (!noDups.find((existing) => existing.name == instance.name)) {
3197
+ if (!noDups.find((existing) => existing.name === instance.name)) {
3170
3198
  noDups.push(instance)
3171
3199
  }
3172
3200
  }
@@ -3178,7 +3206,7 @@ class Config {
3178
3206
  }
3179
3207
 
3180
3208
  // TODO get rid of useOldVersion arg
3181
- addInternal (more, { uuid, addFirst = false, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps: hcps = false } = {}) {
3209
+ addInternal (more, { uuid, km, addFirst = false, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps: hcps = false } = {}) {
3182
3210
  validConfigProps(more)
3183
3211
  if (more instanceof Config) {
3184
3212
  more.initialize({ force: false })
@@ -3195,6 +3223,20 @@ class Config {
3195
3223
  handleCalculatedProps(this, more, { addFirst, uuid })
3196
3224
  applyUUID(more, uuid || this._uuid)
3197
3225
  }
3226
+ if (km) {
3227
+ if (more.semantics) {
3228
+ more.semantics.map((s) => s.km = km)
3229
+ }
3230
+ if (more.generators) {
3231
+ more.generators.map((g) => g.km = km)
3232
+ }
3233
+ }
3234
+ const normalizeIsA = (edge) => {
3235
+ if (edge.length == 3 || edge.parent || edge.child) {
3236
+ return edge
3237
+ }
3238
+ return [...edge, false]
3239
+ }
3198
3240
  for (const key of Object.keys(more)) {
3199
3241
  const value = more[key]
3200
3242
  // TODO remove name and description on the config bag
@@ -3238,9 +3280,9 @@ class Config {
3238
3280
  const hierarchy = this.config.words.hierarchy
3239
3281
  const moreHierarchy = more.words.hierarchy
3240
3282
  if (addFirst) {
3241
- this.config.words.hierarchy = moreHierarchy.concat(hierarchy)
3283
+ this.config.words.hierarchy = moreHierarchy.concat(hierarchy.map(normalizeIsA))
3242
3284
  } else {
3243
- this.config.words.hierarchy = hierarchy.concat(moreHierarchy)
3285
+ this.config.words.hierarchy = hierarchy.concat(moreHierarchy.map(normalizeIsA))
3244
3286
  }
3245
3287
  }
3246
3288
  } else if (key === 'name') {
@@ -3275,9 +3317,9 @@ class Config {
3275
3317
  }
3276
3318
  } else if (Array.isArray(value)) {
3277
3319
  // handle allowDups
3278
- if (key == 'operators') {
3320
+ if (key === 'operators') {
3279
3321
  // TODO what about other props
3280
- const isDup = (op1, op2) => op1.pattern == op2.pattern
3322
+ const isDup = (op1, op2) => op1.pattern === op2.pattern
3281
3323
  for (const newOne of more[key]) {
3282
3324
  for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
3283
3325
  const oldOne = this.config[key][iOldOne]
@@ -3291,13 +3333,13 @@ class Config {
3291
3333
  }
3292
3334
  }
3293
3335
  }
3294
- if (key == 'bridges') {
3336
+ if (key === 'bridges') {
3295
3337
  // TODO what about other props
3296
- const idDup = (b1, b2) => b1.id == b2.id && b1.level == b2.level && b1.bridge == b2.bridge
3338
+ const idDup = (b1, b2) => b1.id === b2.id && b1.level === b2.level && b1.bridge === b2.bridge
3297
3339
  for (const newOne of more[key]) {
3298
3340
  for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
3299
3341
  const oldOne = this.config[key][iOldOne]
3300
- if (newOne.id == oldOne.id) {
3342
+ if (newOne.id === oldOne.id) {
3301
3343
  if (oldOne.allowDups) {
3302
3344
  // the old one takes precedence to match what would happen during the original load
3303
3345
  this.config[key].splice(iOldOne, 1)
@@ -3311,8 +3353,10 @@ class Config {
3311
3353
  // console.log('key', key, 'XXX')
3312
3354
  // console.log('more', JSON.stringify(more, null, 2))
3313
3355
  // hierarchy must update in place and does not care about the list order
3314
- if (key == 'hierarchy') {
3315
- this.config[key].push(...more[key])
3356
+ if (key === 'hierarchy') {
3357
+ const moreEdges = more[key].map(normalizeIsA)
3358
+ this.config[key].push(...moreEdges)
3359
+ this.hierarchy.addEdges(moreEdges)
3316
3360
  } else {
3317
3361
  if (addFirst) {
3318
3362
  this.config[key] = more[key].concat(this.config[key])
@@ -3412,9 +3456,9 @@ class Config {
3412
3456
  }
3413
3457
  } else if (Array.isArray(value)) {
3414
3458
  // handle allowDups
3415
- if (key == 'operators') {
3459
+ if (key === 'operators') {
3416
3460
  // TODO what about other props
3417
- const isDup = (op1, op2) => op1.pattern == op2.pattern
3461
+ const isDup = (op1, op2) => op1.pattern === op2.pattern
3418
3462
  for (const newOne of more[key]) {
3419
3463
  for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
3420
3464
  const oldOne = this.config[key][iOldOne]
@@ -3428,13 +3472,13 @@ class Config {
3428
3472
  }
3429
3473
  }
3430
3474
  }
3431
- if (key == 'bridges') {
3475
+ if (key === 'bridges') {
3432
3476
  // TODO what about other props
3433
- const idDup = (b1, b2) => b1.id == b2.id && b1.level == b2.level && b1.bridge == b2.bridge
3477
+ const idDup = (b1, b2) => b1.id === b2.id && b1.level === b2.level && b1.bridge === b2.bridge
3434
3478
  for (const newOne of more[key]) {
3435
3479
  for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
3436
3480
  const oldOne = this.config[key][iOldOne]
3437
- if (newOne.id == oldOne.id) {
3481
+ if (newOne.id === oldOne.id) {
3438
3482
  if (oldOne.allowDups) {
3439
3483
  // the old one takes precedence to match what would happen during the original load
3440
3484
  this.config[key].splice(iOldOne, 1)
@@ -86,6 +86,9 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
86
86
  args.objects = config.get('objects')
87
87
  args.getObjects = getObjects(args.objects)
88
88
  }
89
+ args.enable = (key) => {
90
+ config.addEnable(key)
91
+ }
89
92
  if (args.uuid) {
90
93
  args.objects = args.getObjects(args.uuid)
91
94
  }
@@ -140,7 +143,7 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
140
143
  if (!c) {
141
144
  return
142
145
  }
143
- return config.getEvaluator(args.s, args.calls, logs, c)
146
+ return config.getEvaluator(args.s, args.calls, logs, c, { isModule: args.isModule, isProcess: args.isProcess })
144
147
  }
145
148
  args.gs = gs(args.g)
146
149
  args.gsp = gs(args.gp)
@@ -257,18 +260,18 @@ const setupProcessB = ({ config, initializer, allowDelta = false, rebuildingTemp
257
260
  const setupContexts = (rawContexts) => {
258
261
  let first = true
259
262
  const contexts = []
260
- contexts.push({ marker: 'controlStart', controlRemove: true })
263
+ contexts.push({ marker: 'controlStart', controlRemove: true, isControl: true })
261
264
  let previous
262
265
  for (const context of rawContexts) {
263
266
  if (first) {
264
267
  first = false
265
268
  } else {
266
- contexts.push({ marker: 'controlBetween', controlRemove: true, previous })
269
+ contexts.push({ marker: 'controlBetween', controlRemove: true, isControl: true, previous })
267
270
  }
268
271
  contexts.push(context)
269
272
  previous = context
270
273
  }
271
- contexts.push({ marker: 'controlEnd', controlRemove: true, previous })
274
+ contexts.push({ marker: 'controlEnd', controlRemove: true, isControl: true, previous })
272
275
 
273
276
  let _index = 0
274
277
  const id = (context) => {
@@ -279,7 +282,7 @@ const setupContexts = (rawContexts) => {
279
282
  return contexts
280
283
  }
281
284
 
282
- const processContextsB = async ({ config, hierarchy, semantics, generators, json, isTest, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs, forTemplate }) => {
285
+ const processContextsB = async ({ config, hierarchy, semantics, generators, json, isTest, isProcess, isModule, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs, forTemplate }) => {
283
286
  // TODO fix this name to contextsPrime
284
287
  const contextsPrime = []
285
288
  const generatedPrime = []
@@ -290,7 +293,7 @@ const processContextsB = async ({ config, hierarchy, semantics, generators, json
290
293
  const contexts = setupContexts(json.contexts)
291
294
 
292
295
  const objects = config.get('objects')
293
- const args = { objects, isResponse: true, response: json, isTest, isInstance, getObjects: getObjects(objects), instance, contexts }
296
+ const args = { objects, isResponse: true, response: json, isTest, isInstance, getObjects: getObjects(objects), instance, contexts, isProcess, isModule }
294
297
  if (!json.logs) {
295
298
  json.logs = []
296
299
  }
@@ -424,7 +427,7 @@ const loadInstance = async (config, instance) => {
424
427
  */
425
428
  const rl = instance.resultss.length
426
429
  if (rl > 0) {
427
- config.addAssociations(instance.resultss[instance.resultss.length-1].rtf_associations || [])
430
+ config.addAssociations(instance.resultss[instance.resultss.length - 1].rtf_associations || [])
428
431
  }
429
432
  /*
430
433
  TODO needs updating if still wanted
@@ -441,14 +444,14 @@ const loadInstance = async (config, instance) => {
441
444
  */
442
445
 
443
446
  // const { /* data, generators, semantics, */ hierarchy } = setupProcessB({ config })
444
- const hierarchy = config.hierarchy
445
447
  for (const i in (instance.resultss || [])) {
448
+ const hierarchy = config.hierarchy
446
449
  const results = instance.resultss[i]
447
450
  if (results.extraConfig) {
448
451
  // config.addInternal(results, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false)
449
452
  const uuid = config.nameToUUID(instance.name)
450
453
  // used to do a CLONE
451
- config.addInternal(instance.template.configs[i], { uuid, addFirst: true, handleCalculatedProps: true })
454
+ config.addInternal(instance.template.configs[i], { uuid, km: instance.name, addFirst: true, handleCalculatedProps: true })
452
455
  } else if (results.apply) {
453
456
  const objects = getObjects(config.get('objects'))(config.uuid)
454
457
  const args = { objects, getObjects: getObjects(objects) }
@@ -468,6 +471,8 @@ const loadInstance = async (config, instance) => {
468
471
  const args = { config, hierarchy, json: results, commandLineArgs: {}, forTemplate: true }
469
472
  args.isInstance = `instance${i}`
470
473
  args.instance = ''
474
+ args.isProcess = !config.isModule
475
+ args.isModule = !!config.isModule
471
476
  await processContextsB(args)
472
477
  if (results.skipSemantics) {
473
478
  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) {