theprogrammablemind_4wp 7.10.0 → 7.10.1

Sign up to get free protection for your applications and to get access to all the features.
package/src/config.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // lookup = (name) => returns <config>
2
2
  const { Semantics, normalizeGenerator } = require('./semantics')
3
3
  const { Generators } = require('./generators')
4
- const { v4 : uuidv4 } = require('uuid');
4
+ const { v4: uuidv4 } = require('uuid')
5
5
  const client = require('../client')
6
6
  const DigraphInternal = require('./digraph_internal')
7
7
  const helpers = require('./helpers')
@@ -19,16 +19,17 @@ const bags = [
19
19
  ]
20
20
 
21
21
  const indent = (string, indent) => {
22
- return string.replace(/^/gm, ' '.repeat(indent));
22
+ return string.replace(/^/gm, ' '.repeat(indent))
23
23
  }
24
24
 
25
25
  const config_toServer = (config) => {
26
+ // cant change things because copy breaks something
26
27
  }
27
28
 
28
29
  const debugPriority = (priority) => {
29
30
  if (global.entodictonDebugPriority) {
30
31
  if (helpers.subPriority(entodictonDebugPriority, priority)) {
31
- debugger; // debug hierarchy hit
32
+ debugger // debug hierarchy hit
32
33
  }
33
34
  }
34
35
  }
@@ -36,7 +37,7 @@ const debugPriority = (priority) => {
36
37
  const debugAssociation = (association) => {
37
38
  if (global.entodictonDebugAssociation) {
38
39
  if (helpers.safeEquals(global.entodictonDebugAssociation, association)) {
39
- debugger; // debug association hit
40
+ debugger // debug association hit
40
41
  }
41
42
  }
42
43
  }
@@ -44,15 +45,15 @@ const debugAssociation = (association) => {
44
45
  const debugHierarchy = (pair) => {
45
46
  if (global.entodictonDebugHierarchy) {
46
47
  if (helpers.safeEquals(global.entodictonDebugHierarchy, pair)) {
47
- debugger; // debug hierarchy hit
48
+ debugger // debug hierarchy hit
48
49
  }
49
50
  }
50
51
  }
51
52
 
52
- const debugBridge = (bridge) => {
53
+ const debugBridge = (bridge) => {
53
54
  if (global.entodictonDebugBridge) {
54
55
  if (global.entodictonDebugBridge[0] == bridge.id && global.entodictonDebugBridge[1] == bridge.level) {
55
- debugger; // debug hierarchy hit
56
+ debugger // debug hierarchy hit
56
57
  }
57
58
  }
58
59
  }
@@ -60,7 +61,7 @@ const debugBridge = (bridge) => {
60
61
  const debugOperator = (operator) => {
61
62
  if (global.entodictonDebugOperator) {
62
63
  if ((operator.pattern || operator) === global.entodictonDebugOperator) {
63
- debugger; // debug operator hit
64
+ debugger // debug operator hit
64
65
  }
65
66
  }
66
67
  }
@@ -74,7 +75,7 @@ const debugConfigProps = (config) => {
74
75
  { property: 'association', check: (v) => debugAssociation(v) },
75
76
  { property: 'hierarchy', check: (v) => debugHierarchy(v) },
76
77
  { property: 'operators', check: (v) => debugOperator(v) },
77
- { property: 'bridges', check: (v) => debugBridge(v) },
78
+ { property: 'bridges', check: (v) => debugBridge(v) }
78
79
  ]
79
80
  for (const { property, check } of checkProps) {
80
81
  if (config[property]) {
@@ -86,21 +87,21 @@ const debugConfigProps = (config) => {
86
87
  }
87
88
 
88
89
  const validConfigProps = (config) => {
89
- const valid = [
90
- 'hierarchy',
91
- 'objects',
92
- 'bridges',
93
- 'operators',
94
- 'words',
95
- 'priorities',
96
- 'associations',
97
- 'name',
98
- 'version',
99
- 'generatorp',
100
- 'generators',
101
- 'semantics',
102
- 'where',
103
- 'floaters',
90
+ const valid = [
91
+ 'hierarchy',
92
+ 'objects',
93
+ 'bridges',
94
+ 'operators',
95
+ 'words',
96
+ 'priorities',
97
+ 'associations',
98
+ 'name',
99
+ 'version',
100
+ 'generatorp',
101
+ 'generators',
102
+ 'semantics',
103
+ 'where',
104
+ 'floaters',
104
105
  'debug',
105
106
 
106
107
  // TODO Fix these from the test app
@@ -115,7 +116,7 @@ const validConfigProps = (config) => {
115
116
  'flatten',
116
117
 
117
118
  'namespaces',
118
- 'eqClasses',
119
+ 'eqClasses'
119
120
  ]
120
121
  helpers.validProps(valid, config, 'config')
121
122
  }
@@ -133,30 +134,29 @@ const setupInitializerFNArgs = (config, args) => {
133
134
  config: config.getPseudoConfig(args.uuid, args.currentConfig),
134
135
  km,
135
136
  baseConfig: config,
136
- apis,
137
+ apis
137
138
  }
138
139
  }
139
140
 
140
141
  const operatorKey_valid = (key) => {
141
142
  if (
142
- !_.isArray(key) ||
143
+ !_.isArray(key) ||
143
144
  key.length != 2 ||
144
145
  !_.isString(key[0]) ||
145
146
  !_.isInteger(key[1]) ||
146
147
  key[1] < 0
147
- ) {
148
-
148
+ ) {
149
149
  let details = ''
150
150
  if (!_.isArray(key)) {
151
- details = "Expected an array."
151
+ details = 'Expected an array.'
152
152
  } else if (key.length != 2) {
153
- details = "Expected an array of length two."
153
+ details = 'Expected an array of length two.'
154
154
  } else if (!_.isString(key[0])) {
155
- details = "Expected element zero to be a string that is an operator id."
155
+ details = 'Expected element zero to be a string that is an operator id.'
156
156
  } else if (!_.isInteger(key[1])) {
157
- details = "Expected element one to be a number that is an operator level."
157
+ details = 'Expected element one to be a number that is an operator level.'
158
158
  } else if (key[1] < 0) {
159
- details = "Expected element one to be a number that is an operator level which is greater than zero."
159
+ details = 'Expected element one to be a number that is an operator level which is greater than zero.'
160
160
  }
161
161
  throw new Error(`${JSON.stringify(key)} is not a valid operator key. Values are of the form [<operatorId>, <operatorLevel>]. ${details}`)
162
162
  }
@@ -166,13 +166,13 @@ const elist = (list, check, prefix) => {
166
166
  for ([index, element] of list.entries()) {
167
167
  try {
168
168
  check(element)
169
- } catch( e ) {
169
+ } catch (e) {
170
170
  throw new Error(prefix(index, e))
171
171
  }
172
172
  }
173
173
  }
174
174
  const priorities_valid = (cps) => {
175
- elist(cps, (cp) => priority_valid(cp), (index, e) => `priorities has an invalid priority at position ${index}. ${e}`)
175
+ elist(cps, (cp) => priority_valid(cp), (index, e) => `priorities has an invalid priority at position ${index}. ${e}`)
176
176
  }
177
177
 
178
178
  const priority_valid = (cp) => {
@@ -186,16 +186,16 @@ const priority_valid = (cp) => {
186
186
  if (!_.isArray(cp.choose)) {
187
187
  throw new Error(`The priority ${JSON.stringify(cp)} has an invalid "choose" value. The value should be a list of the operators in the context to consider for prioritization.`)
188
188
  }
189
- elist(cp.choose,
190
- (element) => {
191
- if (!element && element !== 0) {
192
- throw new Error(`The value should be an index into the "context" property of the operator that is to be considered for prioritization.`)
193
- }
194
- if (!_.isInteger(element) || element < 0 || element >= cp.context.length) {
195
- throw new Error(`The value should be an index into the "context" property of the operator that is to be considered for prioritization. Valid values are between 0 and ${cp.context.length-1}.`)
196
- }
197
- },
198
- (index, e) => `The choose property in the priority ${JSON.stringify(cp)} has an invalid index at position ${index}. ${e}`
189
+ elist(cp.choose,
190
+ (element) => {
191
+ if (!element && element !== 0) {
192
+ throw new Error('The value should be an index into the "context" property of the operator that is to be considered for prioritization.')
193
+ }
194
+ if (!_.isInteger(element) || element < 0 || element >= cp.context.length) {
195
+ throw new Error(`The value should be an index into the "context" property of the operator that is to be considered for prioritization. Valid values are between 0 and ${cp.context.length - 1}.`)
196
+ }
197
+ },
198
+ (index, e) => `The choose property in the priority ${JSON.stringify(cp)} has an invalid index at position ${index}. ${e}`
199
199
  )
200
200
  }
201
201
 
@@ -203,29 +203,29 @@ const handleBridgeProps = (config, bridge, addFirst) => {
203
203
  ecatch(`While processing the bridge for ${bridge.id}#${bridge.level}`,
204
204
  () => {
205
205
  if (!bridge.bridge) {
206
- bridge.bridge = "{ ...next(operator) }"
206
+ bridge.bridge = '{ ...next(operator) }'
207
207
  }
208
208
  if (!bridge.level) {
209
209
  bridge.level = 0
210
210
  }
211
211
  if (bridge.children) {
212
- for (let child of bridge.children) {
212
+ for (const child of bridge.children) {
213
213
  config.addHierarchy(child, bridge.id)
214
214
  }
215
215
  }
216
216
  if (bridge.parents) {
217
- for (let parent of bridge.parents) {
217
+ for (const parent of bridge.parents) {
218
218
  config.addHierarchy(bridge.id, parent)
219
219
  }
220
220
  }
221
221
  if (bridge.isA) {
222
- for (let parent of bridge.isA) {
222
+ for (const parent of bridge.isA) {
223
223
  config.addHierarchy(bridge.id, parent)
224
224
  }
225
225
  }
226
226
  if (bridge.before) {
227
227
  for (let after of bridge.before) {
228
- if (typeof after == 'string') {
228
+ if (typeof after === 'string') {
229
229
  after = [after, 0]
230
230
  }
231
231
  config.addPriority({ context: [[bridge.id, bridge.level], after], choose: [0] })
@@ -233,7 +233,7 @@ const handleBridgeProps = (config, bridge, addFirst) => {
233
233
  }
234
234
  if (bridge.after) {
235
235
  for (let before of bridge.after) {
236
- if (typeof before == 'string') {
236
+ if (typeof before === 'string') {
237
237
  before = [before, 0]
238
238
  }
239
239
  config.addPriority({ context: [before, [bridge.id, bridge.level]], choose: [0] })
@@ -241,8 +241,8 @@ const handleBridgeProps = (config, bridge, addFirst) => {
241
241
  }
242
242
  if (bridge.words) {
243
243
  for (let def of bridge.words) {
244
- if (typeof def == 'string') {
245
- config.addWordInternal(def, {"id": bridge.id, "initial": `{ value: "${def}"}` })
244
+ if (typeof def === 'string') {
245
+ config.addWordInternal(def, { id: bridge.id, initial: `{ value: "${def}"}` })
246
246
  } else {
247
247
  const word = def.word
248
248
  def = { initial: JSON.stringify(def), id: bridge.id, word }
@@ -262,7 +262,7 @@ const handleBridgeProps = (config, bridge, addFirst) => {
262
262
  if (bridge.generators) {
263
263
  const generators = [...bridge.generators]
264
264
  generators.reverse()
265
- for (let generator of generators) {
265
+ for (const generator of generators) {
266
266
  if (addFirst) {
267
267
  config.config.generators.unshift(generator)
268
268
  } else {
@@ -276,33 +276,32 @@ const handleBridgeProps = (config, bridge, addFirst) => {
276
276
  }
277
277
  if (bridge.generatorp) {
278
278
  const match = bridge.generatorp.match || (() => true)
279
- const apply = typeof bridge.generatorp == 'function' ? bridge.generatorp : bridge.generatorp.apply || bridge.generatorp
279
+ const apply = typeof bridge.generatorp === 'function' ? bridge.generatorp : bridge.generatorp.apply || bridge.generatorp
280
280
  const level = bridge.generatorp.level >= 0 ? bridge.generatorp.level : bridge.level + 1
281
-
281
+
282
282
  const generator = {
283
283
  where: bridge.generatorp.where || bridge.where || client.where(4),
284
284
  match: (args) => bridge.id == args.context.marker && args.context.level == level && args.context.paraphrase && match(args),
285
285
  apply: (args) => apply(args),
286
286
  applyWrapped: apply,
287
- property: 'generatorp',
287
+ property: 'generatorp'
288
288
  }
289
289
  if (addFirst) {
290
290
  config.config.generators.unshift(generator)
291
291
  } else {
292
292
  config.config.generators.push(generator)
293
293
  }
294
-
295
294
  }
296
295
  if (bridge.generatorr) {
297
296
  const match = bridge.generatorr.match || (() => true)
298
- const apply = typeof bridge.generatorr == 'function' ? bridge.generatorr : bridge.generatorr.apply || bridge.generatorr
297
+ const apply = typeof bridge.generatorr === 'function' ? bridge.generatorr : bridge.generatorr.apply || bridge.generatorr
299
298
  const level = bridge.generatorr.level >= 0 ? bridge.generatorr.level : bridge.level + 1
300
299
  const generator = {
301
300
  where: bridge.generatorr.where || bridge.where || client.where(4),
302
301
  match: (args) => bridge.id == args.context.marker && args.context.level == level && !args.context.paraphrase && (args.context.response || args.context.isResponse) && match(args),
303
302
  apply: (args) => apply(args),
304
303
  applyWrapped: apply,
305
- property: 'generatorr',
304
+ property: 'generatorr'
306
305
  }
307
306
  if (addFirst) {
308
307
  config.config.generators.unshift(generator)
@@ -313,10 +312,10 @@ const handleBridgeProps = (config, bridge, addFirst) => {
313
312
  if (bridge.evaluator) {
314
313
  const semantic = {
315
314
  where: bridge.evaluator.where || bridge.where || client.where(3),
316
- match: ({context}) => bridge.id == context.marker && context.evaluate,
315
+ match: ({ context }) => bridge.id == context.marker && context.evaluate,
317
316
  apply: (args) => bridge.evaluator(args),
318
317
  applyWrapped: bridge.evaluator,
319
- property: 'evaluator',
318
+ property: 'evaluator'
320
319
  }
321
320
  if (addFirst) {
322
321
  config.config.semantics.unshift(semantic)
@@ -327,10 +326,10 @@ const handleBridgeProps = (config, bridge, addFirst) => {
327
326
  if (bridge.semantic) {
328
327
  const semantic = {
329
328
  where: bridge.semantic.where || bridge.where || client.where(3),
330
- match: ({context}) => bridge.id == context.marker,
329
+ match: ({ context }) => bridge.id == context.marker,
331
330
  apply: (args) => bridge.semantic(args),
332
331
  applyWrapped: bridge.semantic,
333
- property: 'semantic',
332
+ property: 'semantic'
334
333
  }
335
334
  if (addFirst) {
336
335
  config.config.semantics.unshift(semantic)
@@ -343,11 +342,15 @@ const handleBridgeProps = (config, bridge, addFirst) => {
343
342
  }
344
343
 
345
344
  const handleCalculatedProps = (baseConfig, moreConfig, addFirst) => {
346
- for (let bridge of (moreConfig.bridges || [])) {
347
- const valid = [ 'after', 'before', 'bridge', 'development', 'evaluator', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
348
- 'level', 'optional', 'selector', 'semantic', 'words', /Bridge$/, 'localHierarchy', 'levelSpecificHierarchy', 'where', 'uuid' ]
349
- helpers.validProps(valid, bridge, 'bridge')
350
- handleBridgeProps(baseConfig, bridge, addFirst)
345
+ if (moreConfig.bridges) {
346
+ moreConfig.bridges = moreConfig.bridges.map((bridge) => {
347
+ bridge = { ...bridge }
348
+ const valid = ['after', 'before', 'bridge', 'development', 'evaluator', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
349
+ 'level', 'optional', 'selector', 'semantic', 'words', /Bridge$/, 'localHierarchy', 'levelSpecificHierarchy', 'where', 'uuid']
350
+ helpers.validProps(valid, bridge, 'bridge')
351
+ handleBridgeProps(baseConfig, bridge, addFirst)
352
+ return bridge
353
+ })
351
354
  }
352
355
  if (moreConfig.operators) {
353
356
  moreConfig.operators = moreConfig.operators.map((operator) => {
@@ -364,7 +367,6 @@ if (runtime.process.env.DEBUG_HIERARCHY) {
364
367
  global.entodictonDebugHierarchy = JSON.parse(runtime.process.env.DEBUG_HIERARCHY)
365
368
  }
366
369
 
367
-
368
370
  // i keep randomly doing one of the other so I will just make both work the same way
369
371
  if (runtime.process.env.DEBUG_PRIORITIES) {
370
372
  global.entodictonDebugPriority = JSON.parse(runtime.process.env.DEBUG_PRIORITIES)
@@ -385,7 +387,7 @@ if (runtime.process.env.DEBUG_BRIDGE) {
385
387
  // id/level
386
388
  global.entodictonDebugBridge = runtime.process.env.DEBUG_BRIDGE.split('/')
387
389
  if (global.entodictonDebugBridge.length !== 2) {
388
- console.log('Expected DEBUG_BRIDGE to be of the form "id/level"');
390
+ console.log('Expected DEBUG_BRIDGE to be of the form "id/level"')
389
391
  process.exit(-1)
390
392
  }
391
393
  global.entodictonDebugBridge[1] = parseInt(global.entodictonDebugBridge[1])
@@ -397,12 +399,12 @@ if (runtime.process.env.DEBUG_OPERATOR) {
397
399
  }
398
400
 
399
401
  const hierarchyCanonical = (element) => {
400
- if (element.child && element.parent) {
401
- return element
402
- } else {
403
- return { child: element[0], parent: element[1] }
404
- }
402
+ if (element.child && element.parent) {
403
+ return element
404
+ } else {
405
+ return { child: element[0], parent: element[1] }
405
406
  }
407
+ }
406
408
 
407
409
  const isValidDef = (word, def, config) => {
408
410
  if (!def.id) {
@@ -447,21 +449,20 @@ const normalizeConfig = (config) => {
447
449
  config[bag][i].km = config.name
448
450
  }
449
451
  }
450
-
451
452
  }
452
- if (config['bridges']) {
453
- for (let bridge of config['bridges']) {
453
+ if (config.bridges) {
454
+ for (const bridge of config.bridges) {
454
455
  if (!bridge.level) {
455
456
  bridge.level = 0
456
457
  }
457
458
  if (!bridge.bridge) {
458
- bridge.bridge = "{ ...next(operator) }"
459
+ bridge.bridge = '{ ...next(operator) }'
459
460
  }
460
461
  }
461
462
  }
462
463
 
463
464
  if (config.semantics) {
464
- for (let semantic of config.semantics) {
465
+ for (const semantic of config.semantics) {
465
466
  if (semantic.oneShot) {
466
467
  semantic.id = uuid()
467
468
  }
@@ -606,7 +607,7 @@ class KM {
606
607
  const config = configDup(this._config, options)
607
608
  const km = new KM({
608
609
  config,
609
- getCounter: options.getCounter,
610
+ getCounter: options.getCounter,
610
611
  name: this._name,
611
612
  _uuid: config._uuid,
612
613
  namespace: this._namespace,
@@ -703,16 +704,14 @@ const multiApiImpl = (initializer) => {
703
704
  })
704
705
  }
705
706
 
706
-
707
707
  class Config {
708
-
709
708
  toServer (config) {
710
709
  return config_toServer(config)
711
710
  }
712
711
 
713
712
  base () {
714
713
  const base = new Config()
715
- for (let km of this.configs.reverse()) {
714
+ for (const km of this.configs.reverse()) {
716
715
  if (km.isSelf) {
717
716
  continue
718
717
  }
@@ -721,9 +720,30 @@ class Config {
721
720
  return base
722
721
  }
723
722
 
723
+ getInfo () {
724
+ const name = this.name
725
+ const includes = this.configs.slice(1).map((km) => km.config.name)
726
+ const visibleExamples = []
727
+ for (const test of this.tests) {
728
+ if (!test.developerTest) {
729
+ visibleExamples.push(test.query)
730
+ }
731
+ }
732
+ const templateQueries = []
733
+ if (this.instances && this.instances.length > 0) {
734
+ for (const query of this.instances.slice(-1)[0].queries) {
735
+ if (typeof query === 'string') {
736
+ templateQueries.push(query)
737
+ }
738
+ }
739
+ }
740
+ const info = { name, description: this.description, examples: visibleExamples, template: templateQueries, includes }
741
+ return info
742
+ }
743
+
724
744
  getPseudoConfig (uuid, config) {
725
745
  return {
726
- description: "this is a pseudo config that has limited functionality due to being available in the initializer function context",
746
+ description: 'this is a pseudo config that has limited functionality due to being available in the initializer function context',
727
747
  addAssociation: (...args) => this.addAssociation(...args),
728
748
  addAssociations: (...args) => this.addAssociations(...args),
729
749
  addBridge: (...args) => this.addBridge(...args, uuid),
@@ -743,7 +763,7 @@ class Config {
743
763
  getBridge: (...args) => this.getBridge(...args),
744
764
  fragment: (...args) => this.fragment(...args),
745
765
  exists: (...args) => this.exists(...args),
746
- addAPI: (...args) => this.addAPI(...args),
766
+ addAPI: (...args) => this.addAPI(...args)
747
767
  }
748
768
  }
749
769
 
@@ -757,7 +777,7 @@ class Config {
757
777
  }
758
778
 
759
779
  // return the config with just the elements from the included KM's
760
- baseConfig() {
780
+ baseConfig () {
761
781
  const operators = this.config.operators.filter((operator) => {
762
782
  return operator.uuid !== this.uuid
763
783
  })
@@ -765,8 +785,8 @@ class Config {
765
785
  return bridge.uuid !== this.uuid
766
786
  })
767
787
  const words = {}
768
- for (let word in this.config.words) {
769
- const defs = this.config.words[word].filter( (def) => def.uuid !== this.uuid )
788
+ for (const word in this.config.words) {
789
+ const defs = this.config.words[word].filter((def) => def.uuid !== this.uuid)
770
790
  if (defs.length > 0) {
771
791
  words[word] = defs
772
792
  }
@@ -784,11 +804,11 @@ class Config {
784
804
  return `${maybeName}${counter}`
785
805
  }
786
806
 
787
- setTestConfig(testConfig) {
807
+ setTestConfig (testConfig) {
788
808
  this.testConfig = testConfig
789
809
  }
790
810
 
791
- getTestConfig() {
811
+ getTestConfig () {
792
812
  return this.testConfig
793
813
  }
794
814
 
@@ -833,44 +853,44 @@ class Config {
833
853
 
834
854
  // applies only to config sent to the server
835
855
 
836
- watching() {
856
+ watching () {
837
857
  const props = [
838
- 'operators',
839
- 'bridges',
840
- 'hierarchy',
841
- 'namespaces',
842
- 'eqClasses',
843
- 'priorities',
844
- 'associations',
845
- 'words',
846
- 'floaters',
847
- 'implicits',
848
- 'flatten',
849
- ];
858
+ 'operators',
859
+ 'bridges',
860
+ 'hierarchy',
861
+ 'namespaces',
862
+ 'eqClasses',
863
+ 'priorities',
864
+ 'associations',
865
+ 'words',
866
+ 'floaters',
867
+ 'implicits',
868
+ 'flatten'
869
+ ]
850
870
  const watching = {}
851
- for (let prop of props) {
871
+ for (const prop of props) {
852
872
  watching[prop] = this.config[prop]
853
873
  }
854
874
  return JSON.stringify(watching)
855
875
  }
856
876
 
857
- watch() {
858
- this.watchStart = this.watching();
877
+ watch () {
878
+ this.watchStart = this.watching()
859
879
  }
860
880
 
861
- wasChanged() {
881
+ wasChanged () {
862
882
  if (!this.watchStart) {
863
- return false;
883
+ return false
864
884
  }
865
885
  return this.watchStart !== this.watching()
866
886
  }
867
887
 
868
- exists(marker) {
869
- for (let bridge of this.config.bridges) {
888
+ exists (marker) {
889
+ for (const bridge of this.config.bridges) {
870
890
  if (bridge.id == marker) {
871
- return true;
891
+ return true
872
892
  }
873
- }
893
+ }
874
894
  }
875
895
 
876
896
  getSemantics (logs = []) {
@@ -884,7 +904,7 @@ class Config {
884
904
  warningNotEvaluated (log, value) {
885
905
  const description = 'WARNING: for semantics, implement an evaluations handler, set "value" property of the operator to the value.'
886
906
  const match = `({context}) => context.marker == '${value.marker}' && context.evaluate && <other conditions as you like>`
887
- const apply = `({context}) => <do stuff...>; context.value = <value>`
907
+ const apply = '({context}) => <do stuff...>; context.value = <value>'
888
908
  const input = indent(JSON.stringify(value, null, 2), 2)
889
909
  const message = `${description}\nThe semantic would be\n match: ${match}\n apply: ${apply}\nThe input context would be:\n${input}\n`
890
910
  log.push(indent(message, 4))
@@ -911,18 +931,17 @@ class Config {
911
931
  const instance = s({ ...context, evaluate: true })
912
932
  calls.touch(instance)
913
933
  if (!instance.evalue && !instance.verbatim && !instance.value) {
914
- this.warningNotEvaluated(log, context);
934
+ this.warningNotEvaluated(log, context)
915
935
  }
916
936
  if (!instance.evalue) {
917
937
  instance.evalue = instance.value
918
938
  instance.edefault = true
919
939
  }
920
940
  delete instance.evaluate
921
- instance.instance = true;
941
+ instance.instance = true
922
942
  return instance
923
943
  }
924
944
 
925
-
926
945
  fragmentInstantiator (contexts) {
927
946
  return new Object({
928
947
  contexts: () => contexts,
@@ -944,7 +963,7 @@ class Config {
944
963
  continue
945
964
  }
946
965
  if (context[key].instantiated) {
947
- continue;
966
+ continue
948
967
  }
949
968
  todo.push(context[key])
950
969
  }
@@ -970,20 +989,20 @@ class Config {
970
989
  return true
971
990
  }
972
991
  const toCanonical = (f) => {
973
- if (typeof f == 'string') {
992
+ if (typeof f === 'string') {
974
993
  return { query: f }
975
994
  } else {
976
995
  return f
977
996
  }
978
997
  }
979
- const instanceFragments = (instance.fragments || []).map((fragment) => fragment.key || fragment.query).map( toCanonical )
980
- const templateFragments = (template.fragments || []).concat(this.dynamicFragments).map( toCanonical )
998
+ const instanceFragments = (instance.fragments || []).map((fragment) => fragment.key || fragment.query).map(toCanonical)
999
+ const templateFragments = (template.fragments || []).concat(this.dynamicFragments).map(toCanonical)
981
1000
  const sameFragments = helpers.safeEquals(templateFragments, instanceFragments)
982
1001
  const toCanonicalQuery = (queryOrConfig) => {
983
- if (typeof queryOrConfig == 'string') {
1002
+ if (typeof queryOrConfig === 'string') {
984
1003
  const query = queryOrConfig
985
1004
  return query
986
- } else if (typeof queryOrConfig == 'function') {
1005
+ } else if (typeof queryOrConfig === 'function') {
987
1006
  if (options.isModule) {
988
1007
  return { apply: 'function in the browser has webpack rewrites so can not be compared' }
989
1008
  } else {
@@ -998,8 +1017,8 @@ class Config {
998
1017
  } else {
999
1018
  const config = { ...queryOrConfig }
1000
1019
  delete config.where
1001
- config.operators = (config.operators || []).map( (operator) => {
1002
- if (typeof operator == 'string') {
1020
+ config.operators = (config.operators || []).map((operator) => {
1021
+ if (typeof operator === 'string') {
1003
1022
  return { pattern: operator }
1004
1023
  } else {
1005
1024
  operator = { ...operator }
@@ -1007,7 +1026,7 @@ class Config {
1007
1026
  return operator
1008
1027
  }
1009
1028
  })
1010
- config.bridges = (config.bridges || []).map( (bridge) => {
1029
+ config.bridges = (config.bridges || []).map((bridge) => {
1011
1030
  bridge = { ...bridge },
1012
1031
  bridge.level = bridge.level || 0
1013
1032
  delete bridge.uuid
@@ -1015,10 +1034,10 @@ class Config {
1015
1034
  })
1016
1035
  if (options.isModule) {
1017
1036
  // things like webpack rewrite the functions if there are constants so this compare does not work
1018
- delete config.generators;
1019
- delete config.semantics;
1037
+ delete config.generators
1038
+ delete config.semantics
1020
1039
  config.bridges = (config.bridges || []).map((bridge) => {
1021
- bridge = {...bridge}
1040
+ bridge = { ...bridge }
1022
1041
  delete bridge.where
1023
1042
  delete bridge.generatorp
1024
1043
  delete bridge.generatorr
@@ -1026,24 +1045,24 @@ class Config {
1026
1045
  delete bridge.evaluator
1027
1046
  delete bridge.semantic
1028
1047
  return bridge
1029
- });
1048
+ })
1030
1049
  } else {
1031
1050
  config.generators = (config.generators || []).map((generator) => {
1032
- generator = {...generator}
1051
+ generator = { ...generator }
1033
1052
  delete generator.where
1034
1053
  generator.match = generator.match.toString()
1035
1054
  generator.apply = generator.apply.toString()
1036
1055
  return generator
1037
1056
  })
1038
1057
  config.semantics = (config.semantics || []).map((semantic) => {
1039
- semantic = {...semantic}
1058
+ semantic = { ...semantic }
1040
1059
  delete semantic.where
1041
1060
  semantic.match = semantic.match.toString()
1042
1061
  semantic.apply = semantic.apply.toString()
1043
1062
  return semantic
1044
1063
  })
1045
1064
  config.bridges = (config.bridges || []).map((bridge) => {
1046
- bridge = {...bridge}
1065
+ bridge = { ...bridge }
1047
1066
  delete bridge.where
1048
1067
  if (bridge.generatorp) {
1049
1068
  bridge.generatorp = bridge.generatorp.toString()
@@ -1067,13 +1086,13 @@ class Config {
1067
1086
  }
1068
1087
  }
1069
1088
  const toCanonicalQueries = (elements) => {
1070
- return elements.map( toCanonicalQuery )
1089
+ return elements.map(toCanonicalQuery)
1071
1090
  }
1072
1091
 
1073
1092
  const templateQueries = toCanonicalQueries(template.queries || []).map(helpers.updateQueries)
1074
1093
  const instanceQueries = toCanonicalQueries(instance.queries || [])
1075
1094
  let sameQueries = true
1076
- let startOfChanges;
1095
+ let startOfChanges
1077
1096
  for (let iq = 0; iq < templateQueries.length; ++iq) {
1078
1097
  if (!helpers.safeEquals(templateQueries[iq], instanceQueries[iq])) {
1079
1098
  sameQueries = false
@@ -1081,9 +1100,10 @@ class Config {
1081
1100
  }
1082
1101
  }
1083
1102
 
1084
- if (startOfChanges) {
1085
- console.log('templateQueries[startOfChanges]', templateQueries[startOfChanges]);
1086
- console.log('instanceQueries[startOfChanges]', instanceQueries[startOfChanges]);
1103
+ const debug = true
1104
+ if (debug && startOfChanges) {
1105
+ console.log('templateQueries[startOfChanges]', templateQueries[startOfChanges])
1106
+ console.log('instanceQueries[startOfChanges]', instanceQueries[startOfChanges])
1087
1107
  }
1088
1108
 
1089
1109
  // things were deleted case
@@ -1092,7 +1112,6 @@ class Config {
1092
1112
  }
1093
1113
  // const sameQueries = helpers.safeEquals(toCanonicalQueries(template.queries || []).map(helpers.updateQueries), toCanonicalQueries(instance.queries || []))
1094
1114
 
1095
- const debug = false
1096
1115
  if (debug) {
1097
1116
  if (!(instance && sameQueries && sameFragments)) {
1098
1117
  if (!sameQueries) {
@@ -1100,8 +1119,8 @@ class Config {
1100
1119
  debugger
1101
1120
  }
1102
1121
  // console.log("instance", instance)
1103
- console.log("sameQueries", sameQueries)
1104
- console.log("sameFragments", sameFragments)
1122
+ console.log('sameQueries', sameQueries)
1123
+ console.log('sameFragments', sameFragments)
1105
1124
  // console.log("templateFragments", templateFragments)
1106
1125
  // console.log("instanceFragments", instanceFragments)
1107
1126
  // console.log('template.queries', JSON.stringify(toCanonicalQueries(template.queries || []).map(helpers.updateQueries), null, 2))
@@ -1119,8 +1138,8 @@ class Config {
1119
1138
  if (!template.queries && !template.fragments) {
1120
1139
  throw new Error(`Expected the template for ${this.name} to be an object that can have the properties: queries and fragments`)
1121
1140
  }
1122
- for (let query of template.queries || []) {
1123
- if (typeof query == 'string') {
1141
+ for (const query of template.queries || []) {
1142
+ if (typeof query === 'string') {
1124
1143
  } else if (query instanceof Config) {
1125
1144
  throw new Error(`For the template for ${this.name}, each element in queries should be either a string or a structure with a config (not a Config object).`)
1126
1145
  }
@@ -1133,7 +1152,7 @@ class Config {
1133
1152
  }
1134
1153
 
1135
1154
  // loadTemplate
1136
- load (template, instance, options = { rebuild: false, previousResultss: undefined, startOfChanges: undefined } ) {
1155
+ load (template, instance, options = { rebuild: false, previousResultss: undefined, startOfChanges: undefined }) {
1137
1156
  this.validifyTemplate(template)
1138
1157
  instance.template = template
1139
1158
  this.logs.push(`loading template for ${this.name}`)
@@ -1145,15 +1164,15 @@ class Config {
1145
1164
  } else {
1146
1165
  // no change
1147
1166
  // this.initInstances.push({ ...instance, name: config.name })
1148
- const isEmpty = ( instance ) => {
1167
+ const isEmpty = (instance) => {
1149
1168
  const properties = [
1150
- "queries",
1151
- "resultss",
1152
- "fragments",
1153
- "semantics",
1154
- "associations",
1169
+ 'queries',
1170
+ 'resultss',
1171
+ 'fragments',
1172
+ 'semantics',
1173
+ 'associations'
1155
1174
  ]
1156
- return !properties.find( (property) => instance[property] && instance[property].length > 0 )
1175
+ return !properties.find((property) => instance[property] && instance[property].length > 0)
1157
1176
  }
1158
1177
  if (!isEmpty(instance)) {
1159
1178
  // fix up apply functions
@@ -1171,7 +1190,7 @@ class Config {
1171
1190
  }
1172
1191
  }
1173
1192
 
1174
- addFragments(fragments) {
1193
+ addFragments (fragments) {
1175
1194
  // only run this if not loading as module write error if loading as module and different
1176
1195
  this.dynamicFragments = this.dynamicFragments.concat(fragments)
1177
1196
  }
@@ -1181,12 +1200,12 @@ class Config {
1181
1200
  }
1182
1201
 
1183
1202
  addAssociations (associations) {
1184
- for (let association of associations) {
1203
+ for (const association of associations) {
1185
1204
  this.addAssociation(association)
1186
1205
  }
1187
1206
  }
1188
1207
 
1189
- debugConfig() {
1208
+ debugConfig () {
1190
1209
  }
1191
1210
 
1192
1211
  addAssociation (association) {
@@ -1215,17 +1234,17 @@ class Config {
1215
1234
  }
1216
1235
 
1217
1236
  addPriorities (priorities) {
1218
- for (let priority of priorities) {
1237
+ for (const priority of priorities) {
1219
1238
  this.addPriority(priority)
1220
1239
  }
1221
1240
  }
1222
1241
 
1223
1242
  addHierarchy (child, parent) {
1224
- if (child && parent || !child || Array.isArray(child) || (typeof child == 'string' && !parent)) {
1243
+ if (child && parent || !child || Array.isArray(child) || (typeof child === 'string' && !parent)) {
1225
1244
  this.addHierarchyChildParent(child, parent)
1226
1245
  // this.addHierarchyProperties ({ child, parent })
1227
1246
  } else {
1228
- this.addHierarchyProperties (child)
1247
+ this.addHierarchyProperties(child)
1229
1248
  }
1230
1249
  }
1231
1250
 
@@ -1251,8 +1270,8 @@ class Config {
1251
1270
  throw new Error(`addHierarchy expected parent to be a string. got ${JSON.stringify(parent)}`)
1252
1271
  }
1253
1272
  debugHierarchy([child, parent])
1254
- if (this.config.hierarchy.find( (element) => {
1255
- const hc = hierarchyCanonical(element)
1273
+ if (this.config.hierarchy.find((element) => {
1274
+ const hc = hierarchyCanonical(element)
1256
1275
  if (child == hc.child && parent == hc.parent) {
1257
1276
  return true
1258
1277
  }
@@ -1267,9 +1286,9 @@ class Config {
1267
1286
 
1268
1287
  getBridge (id, level) {
1269
1288
  if (level) {
1270
- return this.config.bridges.find( (bridge) => bridge.id == id && bridge.level == level )
1289
+ return this.config.bridges.find((bridge) => bridge.id == id && bridge.level == level)
1271
1290
  } else {
1272
- return this.config.bridges.find( (bridge) => bridge.id == id)
1291
+ return this.config.bridges.find((bridge) => bridge.id == id)
1273
1292
  }
1274
1293
  }
1275
1294
 
@@ -1279,12 +1298,12 @@ class Config {
1279
1298
  }
1280
1299
  const bridges = this.config.bridges
1281
1300
  const def = Object.assign({}, bridge, { uuid: uuid || this._uuid })
1282
-
1301
+
1283
1302
  debugBridge(bridge)
1284
1303
  if (bridge.allowDups) {
1285
1304
  // if (bridges.find( (b) => b.id == bridge.id && b.level == bridge.level && b.bridge == bridge.bridge )) {
1286
- if (bridges.find( (b) => b.id == bridge.id && b.level == bridge.level)) {
1287
- return;
1305
+ if (bridges.find((b) => b.id == bridge.id && b.level == bridge.level)) {
1306
+ return
1288
1307
  }
1289
1308
  }
1290
1309
  if (global.transitoryMode) {
@@ -1292,7 +1311,7 @@ class Config {
1292
1311
  }
1293
1312
  handleBridgeProps(this, def)
1294
1313
  bridges.push(def)
1295
- this.checkBridges();
1314
+ this.checkBridges()
1296
1315
  this._delta.json.bridges.push({ action: 'add', bridge: def })
1297
1316
  }
1298
1317
 
@@ -1340,8 +1359,8 @@ class Config {
1340
1359
  semantics.unshift(semantic)
1341
1360
  }
1342
1361
 
1343
- removeSemantic(deleteSemantic) {
1344
- const index = this.config.semantics.findIndex( (semantic) => semantic.id === deleteSemantic.id )
1362
+ removeSemantic (deleteSemantic) {
1363
+ const index = this.config.semantics.findIndex((semantic) => semantic.id === deleteSemantic.id)
1345
1364
  if (index >= 0) {
1346
1365
  this.config.semantics.splice(index, 1)
1347
1366
  }
@@ -1354,7 +1373,7 @@ class Config {
1354
1373
 
1355
1374
  const operators = this.config.operators
1356
1375
 
1357
- let operator;
1376
+ let operator
1358
1377
  if (typeof objectOrPattern === 'string') {
1359
1378
  operator = { pattern: objectOrPattern, uuid: uuid || this._uuid }
1360
1379
  } else {
@@ -1364,8 +1383,8 @@ class Config {
1364
1383
  debugOperator(operator)
1365
1384
 
1366
1385
  if (operator.allowDups) {
1367
- if (operators.find( (o) => o.pattern == operator.pattern )) {
1368
- return;
1386
+ if (operators.find((o) => o.pattern == operator.pattern)) {
1387
+ return
1369
1388
  }
1370
1389
  }
1371
1390
 
@@ -1424,19 +1443,19 @@ class Config {
1424
1443
  }
1425
1444
  }
1426
1445
 
1427
- getServer() {
1446
+ getServer () {
1428
1447
  return this._server
1429
1448
  }
1430
1449
 
1431
- getAPIKey() {
1450
+ getAPIKey () {
1432
1451
  return this._key
1433
1452
  }
1434
1453
 
1435
- getQueryParams() {
1454
+ getQueryParams () {
1436
1455
  return this._queryParams
1437
1456
  }
1438
1457
 
1439
- setQueryParams(queryParams) {
1458
+ setQueryParams (queryParams) {
1440
1459
  this._queryParams = queryParams
1441
1460
  }
1442
1461
 
@@ -1544,14 +1563,14 @@ class Config {
1544
1563
  }
1545
1564
 
1546
1565
  getConfigs () {
1547
- const configs = {};
1566
+ const configs = {}
1548
1567
  configs[this.name] = this
1549
1568
  for (const config of this.configs) {
1550
1569
  if (config.config instanceof Config) {
1551
1570
  configs[config.config.name] = config.config
1552
1571
  }
1553
1572
  }
1554
- return configs;
1573
+ return configs
1555
1574
  }
1556
1575
 
1557
1576
  getConfigByUUID (uuid) {
@@ -1580,18 +1599,18 @@ class Config {
1580
1599
  }
1581
1600
  }
1582
1601
 
1583
- removeDevelopmentElements(config) {
1602
+ removeDevelopmentElements (config) {
1584
1603
  if (!config) {
1585
1604
  return
1586
1605
  }
1587
- config.operators = config.operators.filter( (element) => !element.development )
1588
- config.bridges = config.bridges.filter( (element) => !element.development )
1589
- config.generators = config.generators.filter( (element) => !element.development )
1590
- config.semantics = config.semantics.filter( (element) => !element.development )
1591
- config.hierarchy = (config.hierarchy).filter( (element) => !element.development )
1606
+ config.operators = config.operators.filter((element) => !element.development)
1607
+ config.bridges = config.bridges.filter((element) => !element.development)
1608
+ config.generators = config.generators.filter((element) => !element.development)
1609
+ config.semantics = config.semantics.filter((element) => !element.development)
1610
+ config.hierarchy = (config.hierarchy).filter((element) => !element.development)
1592
1611
  for (const word in config.words) {
1593
1612
  const defs = config.words[word] || []
1594
- config.words[word] = defs.filter( (def) => !def.development )
1613
+ config.words[word] = defs.filter((def) => !def.development)
1595
1614
  if (config.words[word].length == 0) {
1596
1615
  delete config.words[word]
1597
1616
  }
@@ -1714,11 +1733,11 @@ class Config {
1714
1733
  debugConfigProps(this.config)
1715
1734
  }
1716
1735
 
1717
- addArgs(moreArgs) {
1736
+ addArgs (moreArgs) {
1718
1737
  this.addedArgss.push(moreArgs)
1719
1738
  }
1720
1739
 
1721
- getAddedArgs(args) {
1740
+ getAddedArgs (args) {
1722
1741
  for (let addedArgs of this.addedArgss) {
1723
1742
  addedArgs = addedArgs(args)
1724
1743
  Object.assign(args, addedArgs)
@@ -1742,9 +1761,9 @@ class Config {
1742
1761
  }
1743
1762
 
1744
1763
  delta () {
1745
- return {
1746
- cacheKey: this._delta.cacheKey,
1747
- json: this._delta.json
1764
+ return {
1765
+ cacheKey: this._delta.cacheKey,
1766
+ json: this._delta.json
1748
1767
  }
1749
1768
  }
1750
1769
 
@@ -1757,7 +1776,7 @@ class Config {
1757
1776
  bridges: [],
1758
1777
  associations: [],
1759
1778
  priorities: [],
1760
- hierarchy: [],
1779
+ hierarchy: []
1761
1780
  }
1762
1781
  }
1763
1782
  }
@@ -1774,11 +1793,11 @@ class Config {
1774
1793
  }
1775
1794
  }
1776
1795
 
1777
- addAPI(api) {
1796
+ addAPI (api) {
1778
1797
  if (this._api && this._api.multiApi) {
1779
1798
  this._api.add(this, this._api, api)
1780
1799
  } else {
1781
- throw new Error("Can only add apis to a multi-api")
1800
+ throw new Error('Can only add apis to a multi-api')
1782
1801
  }
1783
1802
  }
1784
1803
 
@@ -1841,15 +1860,15 @@ class Config {
1841
1860
  }
1842
1861
 
1843
1862
  // TODO add more details
1844
- equal(config) {
1863
+ equal (config) {
1845
1864
  if (JSON.stringify(this.config) != JSON.stringify(config.config)) {
1846
- debugger;
1847
- return false;
1865
+ debugger
1866
+ return false
1848
1867
  }
1849
1868
  return true
1850
1869
  }
1851
1870
 
1852
- dump(fn) {
1871
+ dump (fn) {
1853
1872
  runtime.fs.writeFileSync(fn, JSON.stringify(this.config, 0, 2))
1854
1873
  }
1855
1874
 
@@ -1861,7 +1880,7 @@ class Config {
1861
1880
  const cp = new Config()
1862
1881
  cp.logs = []
1863
1882
  cp.maxDepth = this.maxDepth
1864
- cp.debugLoops = this.debugLoops
1883
+ cp.debugLoops = this.debugLoops
1865
1884
  cp.transitoryMode = this.transitoryMode
1866
1885
  cp.configs = this.configs.map((km) => km.copy2(Object.assign({}, options, { getCounter: (name) => cp.getCounter(name), callInitializers: false })))
1867
1886
  cp._uuid = cp.configs[0]._uuid
@@ -1898,7 +1917,7 @@ class Config {
1898
1917
  cp.mapUUIDs(map)
1899
1918
 
1900
1919
  if (cp._uuid == 'concept2') {
1901
- // debugger
1920
+ // debugger
1902
1921
  }
1903
1922
  if (options.callInitializers) {
1904
1923
  cp.rebuild(options)
@@ -1921,7 +1940,7 @@ class Config {
1921
1940
  // const namespace = km.namespace
1922
1941
  cp.config.objects.namespaced[km._uuid] = {}
1923
1942
  })
1924
- /*
1943
+ /*
1925
1944
  if (cp._uuid == 'concept2') {
1926
1945
  if (!cp.api.objects.defaultTypesForHierarchy) {
1927
1946
  debugger
@@ -2061,7 +2080,7 @@ class Config {
2061
2080
 
2062
2081
  initializer (fn, options = {}) {
2063
2082
  if (options) {
2064
- for (let option of Object.keys(options)) {
2083
+ for (const option of Object.keys(options)) {
2065
2084
  const validOptions = []
2066
2085
  if (!validOptions.includes(option)) {
2067
2086
  throw new Error(`For Config.initializer, unrecognized option ${option}. The valid options are ${validOptions}`)
@@ -2227,7 +2246,7 @@ class Config {
2227
2246
  // rebuild ({ isModule: mainIsModule = false } = {}) {
2228
2247
  rebuild ({ isModule: mainIsModule } = {}) {
2229
2248
  this.resetDelta()
2230
- const debug = this.config.debug;
2249
+ const debug = this.config.debug
2231
2250
  this.config = _.cloneDeep(this.initConfig)
2232
2251
  this.hierarchy = new DigraphInternal(this.config.hierarchy)
2233
2252
  if (debug) {
@@ -2270,8 +2289,8 @@ class Config {
2270
2289
  // const aw = (word, def) => this.addWord(word, def)
2271
2290
  // const ag = (matchOrGenerator, applyOrNothing) => this.addGenerator(matchOrGenerator, applyOrNothing)
2272
2291
  let config = km.config
2273
-
2274
- if (config.addedArgss) {
2292
+
2293
+ if (config.addedArgss) {
2275
2294
  this.addedArgss = this.addedArgss.concat(config.addedArgss)
2276
2295
  }
2277
2296
 
@@ -2294,15 +2313,15 @@ class Config {
2294
2313
  return config
2295
2314
  }
2296
2315
  // const hierarchy = new DigraphInternal((config.config || {}).hierarchy)
2297
- const args = new Object(setupInitializerFNArgs(this, {
2298
- isModule,
2299
- hierarchy: this.hierarchy,
2316
+ const args = new Object(setupInitializerFNArgs(this, {
2317
+ isModule,
2318
+ hierarchy: this.hierarchy,
2300
2319
  testConfig: config,
2301
- currentConfig: config,
2302
- uuid: config._uuid,
2303
- objects: namespacedObjects,
2304
- namespace,
2305
- api: config.api,
2320
+ currentConfig: config,
2321
+ uuid: config._uuid,
2322
+ objects: namespacedObjects,
2323
+ namespace,
2324
+ api: config.api
2306
2325
  }))
2307
2326
 
2308
2327
  const currentConfig = args.currentConfig
@@ -2319,12 +2338,12 @@ class Config {
2319
2338
  // debugger
2320
2339
  // greg55
2321
2340
  config.initializerFn(args, { dontCallFn: true })
2322
- initAfterApis.unshift({ config, args })
2341
+ initAfterApis.unshift({ config, args })
2323
2342
  if (config._api) {
2324
2343
  if (config._api.initialize) {
2325
2344
  // reverse the list
2326
2345
  // TODO sync up the args with initialize of config
2327
- inits.unshift( () => config._api.initialize({ config: this, km: kmFn, ...args, api: config._api }) )
2346
+ inits.unshift(() => config._api.initialize({ config: this, km: kmFn, ...args, api: config._api }))
2328
2347
  // config._api.initialize({ config, api: config._api })
2329
2348
  } else {
2330
2349
  inits.unshift(null)
@@ -2366,13 +2385,13 @@ class Config {
2366
2385
  this.config.priorities = []
2367
2386
  this.config.associations = { positive: [], negative: [] }
2368
2387
  this.config.words = {}
2369
-
2388
+
2370
2389
  for (let i = 0; i < addInternals.length; ++i) {
2371
- let name;
2390
+ let name
2372
2391
  if (addInternals[i]) {
2373
2392
  this.addInternalR(addInternals[i], true, false, false, true)
2374
2393
  name = addInternals[i].name
2375
- } else{
2394
+ } else {
2376
2395
  // the ones defined in config must come after the ones in the templates
2377
2396
  this.config.generators = generators.concat(this.config.generators)
2378
2397
  this.config.semantics = semantics.concat(this.config.semantics)
@@ -2386,7 +2405,7 @@ class Config {
2386
2405
  }
2387
2406
  if (initAfterApis[i]) {
2388
2407
  const init = initAfterApis[i]
2389
- init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true})
2408
+ init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true })
2390
2409
  }
2391
2410
  const instance = this.instances.find((instance) => instance.name == name)
2392
2411
  if (instance) {
@@ -2401,9 +2420,10 @@ class Config {
2401
2420
  this.checkBridges()
2402
2421
  }
2403
2422
 
2404
- nameToUUID(name) {
2423
+ nameToUUID (name) {
2405
2424
  return this.configs.find((km) => km._name == name)._uuid
2406
2425
  }
2426
+
2407
2427
  // name: namespace name
2408
2428
  // others
2409
2429
  // if undefined namespace applies to first loaded config
@@ -2580,7 +2600,7 @@ class Config {
2580
2600
  context: context.map((id) => {
2581
2601
  return [toNS(id[0]), id[1]]
2582
2602
  }),
2583
- choose,
2603
+ choose
2584
2604
  }
2585
2605
  if (ordered) {
2586
2606
  priority.ordered = ordered
@@ -2605,7 +2625,7 @@ class Config {
2605
2625
  }
2606
2626
 
2607
2627
  const seen = {}
2608
- for (let operator of this.config.operators) {
2628
+ for (const operator of this.config.operators) {
2609
2629
  if (seen[operator.pattern]) {
2610
2630
  const key = `${operator.pattern} (namespace: ${operator.uuid})`
2611
2631
  throw new Error(`Operator '${key}' is defined more than once in the operators`)
@@ -2678,10 +2698,10 @@ class Config {
2678
2698
  throw new Error(`Setting invalid property ${property}`)
2679
2699
  }
2680
2700
 
2681
- if ('words' == property) {
2682
- for (let word in value) {
2683
- for (let def of value[word]) {
2684
- if (!def['uuid']) {
2701
+ if (property == 'words') {
2702
+ for (const word in value) {
2703
+ for (const def of value[word]) {
2704
+ if (!def.uuid) {
2685
2705
  throw new Error(`All definitions for '${property}' must have the uuid property set (config.uuid). uuid is missing from ${JSON.stringify(def)} for the word '${word}'`)
2686
2706
  }
2687
2707
  }
@@ -2689,8 +2709,8 @@ class Config {
2689
2709
  }
2690
2710
 
2691
2711
  if (['operators', 'bridges'].includes(property)) {
2692
- for (let def of value) {
2693
- if (!def['uuid']) {
2712
+ for (const def of value) {
2713
+ if (!def.uuid) {
2694
2714
  throw new Error(`All definitions for '${property}' must have the uuid property set (config.uuid). uuid is missing from ${JSON.stringify(def)}`)
2695
2715
  }
2696
2716
  }
@@ -2770,9 +2790,9 @@ class Config {
2770
2790
  this.configs.forEach((km) => {
2771
2791
  this.instances = (km._config.instances || this.initInstances.slice()).concat(this.instances)
2772
2792
  })
2773
- let noDups = []
2774
- for (let instance of this.instances) {
2775
- if (!noDups.find( (existing) => existing.name == instance.name )) {
2793
+ const noDups = []
2794
+ for (const instance of this.instances) {
2795
+ if (!noDups.find((existing) => existing.name == instance.name)) {
2776
2796
  noDups.push(instance)
2777
2797
  }
2778
2798
  }
@@ -2784,7 +2804,7 @@ class Config {
2784
2804
  }
2785
2805
 
2786
2806
  // TODO get rid of useOldVersion arg
2787
- addInternal (more, { uuid, addFirst = false, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps : hcps = false } = {}) {
2807
+ addInternal (more, { uuid, addFirst = false, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps: hcps = false } = {}) {
2788
2808
  validConfigProps(more)
2789
2809
  if (more instanceof Config) {
2790
2810
  more.initialize({ force: false })
@@ -2866,12 +2886,12 @@ class Config {
2866
2886
  const isDup = (op1, op2) => op1.pattern == op2.pattern
2867
2887
  for (const newOne of more[key]) {
2868
2888
  for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
2869
- const oldOne = this.config[key][iOldOne];
2889
+ const oldOne = this.config[key][iOldOne]
2870
2890
  if (isDup(newOne, oldOne)) {
2871
2891
  if (oldOne.allowDups) {
2872
2892
  // the old one takes precedence to match what would happen during the original load
2873
2893
  this.config[key].splice(iOldOne, 1)
2874
- break;
2894
+ break
2875
2895
  }
2876
2896
  }
2877
2897
  }
@@ -2882,14 +2902,14 @@ class Config {
2882
2902
  const idDup = (b1, b2) => b1.id == b2.id && b1.level == b2.level && b1.bridge == b2.bridge
2883
2903
  for (const newOne of more[key]) {
2884
2904
  for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
2885
- const oldOne = this.config[key][iOldOne];
2905
+ const oldOne = this.config[key][iOldOne]
2886
2906
  if (newOne.id == oldOne.id) {
2887
2907
  if (oldOne.allowDups) {
2888
2908
  // the old one takes precedence to match what would happen during the original load
2889
2909
  this.config[key].splice(iOldOne, 1)
2890
- break;
2910
+ break
2891
2911
  }
2892
- }
2912
+ }
2893
2913
  }
2894
2914
  }
2895
2915
  }
@@ -2987,12 +3007,12 @@ class Config {
2987
3007
  const isDup = (op1, op2) => op1.pattern == op2.pattern
2988
3008
  for (const newOne of more[key]) {
2989
3009
  for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
2990
- const oldOne = this.config[key][iOldOne];
3010
+ const oldOne = this.config[key][iOldOne]
2991
3011
  if (isDup(newOne, oldOne)) {
2992
3012
  if (oldOne.allowDups) {
2993
3013
  // the old one takes precedence to match what would happen during the original load
2994
3014
  this.config[key].splice(iOldOne, 1)
2995
- break;
3015
+ break
2996
3016
  }
2997
3017
  }
2998
3018
  }
@@ -3003,12 +3023,12 @@ class Config {
3003
3023
  const idDup = (b1, b2) => b1.id == b2.id && b1.level == b2.level && b1.bridge == b2.bridge
3004
3024
  for (const newOne of more[key]) {
3005
3025
  for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
3006
- const oldOne = this.config[key][iOldOne];
3026
+ const oldOne = this.config[key][iOldOne]
3007
3027
  if (newOne.id == oldOne.id) {
3008
3028
  if (oldOne.allowDups) {
3009
3029
  // the old one takes precedence to match what would happen during the original load
3010
3030
  this.config[key].splice(iOldOne, 1)
3011
- break;
3031
+ break
3012
3032
  }
3013
3033
  }
3014
3034
  }
@@ -3034,5 +3054,5 @@ module.exports = {
3034
3054
  Config,
3035
3055
  config_toServer,
3036
3056
  operatorKey_valid,
3037
- handleBridgeProps,
3057
+ handleBridgeProps
3038
3058
  }