theprogrammablemind 7.5.8-beta.30 → 7.5.8-beta.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/client.js +4 -3
  2. package/package.json +1 -1
  3. package/src/config.js +65 -34
package/client.js CHANGED
@@ -577,7 +577,7 @@ const setupProcessB = ({ config, initializer, allowDelta=false } = {}) => {
577
577
  }
578
578
 
579
579
  // instance template
580
- const processInstance = (config, instance) => {
580
+ const loadInstance = (config, instance) => {
581
581
  const transitoryMode = global.transitoryMode
582
582
  global.transitoryMode = false
583
583
  const { /* data, generators, semantics, */ hierarchy } = setupProcessB({ config })
@@ -587,7 +587,7 @@ const processInstance = (config, instance) => {
587
587
  if (results.extraConfig) {
588
588
  // config.addInternal(results, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false)
589
589
  // config.addInternal(config.template.queries[i], { handleCalculatedProps: true } )
590
- config.addInternal(instance.template.queries[i], { handleCalculatedProps: true } )
590
+ config.addInternal(instance.template.queries[i], { addFirst: true, handleCalculatedProps: true } )
591
591
  } else {
592
592
  processContextsB({ config, hierarchy, json: results/*, generators, semantics */, commandLineArgs: {}, isInstance: `instance${i}` })
593
593
  }
@@ -1258,6 +1258,7 @@ entodicton.knowledgeModule( {
1258
1258
  `
1259
1259
  */
1260
1260
 
1261
+ // loadTemplate BuiltTemplate
1261
1262
  const rebuildTemplate = async ({ config, target, template, errorHandler = defaultErrorHandler }) => {
1262
1263
  const accumulators = {
1263
1264
  resultss: [],
@@ -2000,7 +2001,7 @@ module.exports = {
2000
2001
  Digraph,
2001
2002
  analyzeMetaData,
2002
2003
  processContextsB,
2003
- processInstance,
2004
+ loadInstance,
2004
2005
  gs,
2005
2006
  flattens,
2006
2007
  writeTest
package/package.json CHANGED
@@ -63,6 +63,6 @@
63
63
  "json-stable-stringify": "^1.0.1",
64
64
  "node-fetch": "^2.6.1"
65
65
  },
66
- "version": "7.5.8-beta.30",
66
+ "version": "7.5.8-beta.32",
67
67
  "license": "ISC"
68
68
  }
package/src/config.js CHANGED
@@ -42,6 +42,7 @@ const validConfigProps = (config) => {
42
42
  'associations',
43
43
  'name',
44
44
  'version',
45
+ 'generatorp',
45
46
  'generators',
46
47
  'semantics',
47
48
  'where',
@@ -158,7 +159,7 @@ const contextual_priority_valid = (cp) => {
158
159
  )
159
160
  }
160
161
 
161
- const handleBridgeProps = (config, bridge) => {
162
+ const handleBridgeProps = (config, bridge, addFirst) => {
162
163
  ecatch(`While processing the bridge for ${bridge.id}#${bridge.level}`,
163
164
  () => {
164
165
  if (!bridge.bridge) {
@@ -209,14 +210,24 @@ const handleBridgeProps = (config, bridge) => {
209
210
  }
210
211
  }
211
212
  }
213
+ /*
212
214
  if (bridge.generator) {
213
- config.config.generators.unshift(bridge.generator)
215
+ if (addFirst) {
216
+ config.config.generators.unshift(bridge.generator)
217
+ } else {
218
+ config.config.generators.push(bridge.generator)
219
+ }
214
220
  }
221
+ */
215
222
  if (bridge.generators) {
216
223
  const generators = [...bridge.generators]
217
224
  generators.reverse()
218
225
  for (let generator of generators) {
219
- config.config.generators.unshift(generator)
226
+ if (addFirst) {
227
+ config.config.generators.unshift(generator)
228
+ } else {
229
+ config.config.generators.push(generator)
230
+ }
220
231
  }
221
232
  }
222
233
  if (bridge.generatorpr) {
@@ -227,66 +238,76 @@ const handleBridgeProps = (config, bridge) => {
227
238
  const match = bridge.generatorp.match || (() => true)
228
239
  const apply = typeof bridge.generatorp == 'function' ? bridge.generatorp : bridge.generatorp.apply || bridge.generatorp
229
240
  const level = bridge.generatorp.level >= 0 ? bridge.generatorp.level : bridge.level + 1
230
- config.config.generators.unshift({
241
+
242
+ const generator = {
231
243
  where: bridge.generatorp.where || bridge.where || client.where(4),
232
244
  match: (args) => bridge.id == args.context.marker && args.context.level == level && args.context.paraphrase && match(args),
233
245
  apply: (args) => apply(args),
234
246
  applyWrapped: apply,
235
247
  property: 'generatorp',
236
- })
248
+ }
249
+ if (addFirst) {
250
+ config.config.generators.unshift(generator)
251
+ } else {
252
+ config.config.generators.push(generator)
253
+ }
254
+
237
255
  }
238
256
  if (bridge.generatorr) {
239
257
  const match = bridge.generatorr.match || (() => true)
240
258
  const apply = typeof bridge.generatorr == 'function' ? bridge.generatorr : bridge.generatorr.apply || bridge.generatorr
241
259
  const level = bridge.generatorr.level >= 0 ? bridge.generatorr.level : bridge.level + 1
242
- config.config.generators.unshift({
260
+ const generator = {
243
261
  where: bridge.generatorr.where || bridge.where || client.where(4),
244
262
  match: (args) => bridge.id == args.context.marker && args.context.level == level && !args.context.paraphrase && (args.context.response || args.context.isResponse) && match(args),
245
263
  apply: (args) => apply(args),
246
264
  applyWrapped: apply,
247
265
  property: 'generatorr',
248
- })
249
- }
250
- /*
251
- if (bridge.generatorr) {
252
- config.config.generators.unshift({
253
- // TODO merge response and isResponse
254
- where: bridge.generatorr.where || bridge.where || client.where(3),
255
- match: ({context}) => bridge.id == context.marker && !context.paraphrase && (context.response || context.isResponse),
256
- apply: (args) => bridge.generatorr(args),
257
- applyWrapped: bridge.generatorr,
258
- property: 'generatorr',
259
- })
266
+ }
267
+ if (addFirst) {
268
+ config.config.generators.unshift(generator)
269
+ } else {
270
+ config.config.generators.push(generator)
271
+ }
260
272
  }
261
- */
262
273
  if (bridge.evaluator) {
263
- config.config.semantics.unshift({
274
+ const semantic = {
264
275
  where: bridge.evaluator.where || bridge.where || client.where(3),
265
276
  match: ({context}) => bridge.id == context.marker && context.evaluate,
266
277
  apply: (args) => bridge.evaluator(args),
267
278
  applyWrapped: bridge.evaluator,
268
279
  property: 'evaluator',
269
- })
280
+ }
281
+ if (addFirst) {
282
+ config.config.semantics.unshift(semantic)
283
+ } else {
284
+ config.config.semantics.push(semantic)
285
+ }
270
286
  }
271
287
  if (bridge.semantic) {
272
- config.config.semantics.unshift({
288
+ const semantic = {
273
289
  where: bridge.semantic.where || bridge.where || client.where(3),
274
290
  match: ({context}) => bridge.id == context.marker,
275
291
  apply: (args) => bridge.semantic(args),
276
292
  applyWrapped: bridge.semantic,
277
293
  property: 'semantic',
278
- })
294
+ }
295
+ if (addFirst) {
296
+ config.config.semantics.unshift(semantic)
297
+ } else {
298
+ config.config.semantics.push(semantic)
299
+ }
279
300
  }
280
301
  }
281
302
  )
282
303
  }
283
304
 
284
- const handleCalculatedProps = (baseConfig, moreConfig) => {
285
- for (let bridge of moreConfig.bridges) {
305
+ const handleCalculatedProps = (baseConfig, moreConfig, addFirst) => {
306
+ for (let bridge of (moreConfig.bridges || [])) {
286
307
  const valid = [ 'after', 'before', 'bridge', 'development', 'evaluator', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
287
308
  'level', 'optional', 'selector', 'semantic', 'words', /Bridge$/, 'localHierarchy', 'levelSpecificHierarchy', 'where', 'uuid' ]
288
309
  helpers.validProps(valid, bridge, 'bridge')
289
- handleBridgeProps(baseConfig, bridge)
310
+ handleBridgeProps(baseConfig, bridge, addFirst)
290
311
  }
291
312
  if (moreConfig.operators) {
292
313
  moreConfig.operators = moreConfig.operators.map((operator) => {
@@ -933,6 +954,7 @@ class Config {
933
954
  config_toServer(data)
934
955
  }
935
956
 
957
+ // loadTemplate
936
958
  load (template, instance, options = { rebuild: false } ) {
937
959
  this.validifyTemplate(template)
938
960
  instance.template = template
@@ -962,7 +984,7 @@ class Config {
962
984
  instance.name = this.name
963
985
  this.initInstances.push(instance)
964
986
  this.instances.push(instance)
965
- client.processInstance(this, instance)
987
+ client.loadInstance(this, instance)
966
988
  }
967
989
  }
968
990
  }
@@ -1882,7 +1904,7 @@ class Config {
1882
1904
  this.initializerFn(setupInitializerFNArgs(this, { testConfig: this, currentConfig: this, objects, namespace, uuid }))
1883
1905
  }
1884
1906
  })
1885
- this.instances.forEach((instance) => client.processInstance(this, instance))
1907
+ this.instances.forEach((instance) => client.loadInstance(this, instance))
1886
1908
  }
1887
1909
 
1888
1910
  initialize ({ force = true } = {}) {
@@ -2213,7 +2235,7 @@ class Config {
2213
2235
  for (let init of initAfterApis) {
2214
2236
  init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true })
2215
2237
  }
2216
- this.instances.forEach((instance) => client.processInstance(this, instance))
2238
+ this.instances.forEach((instance) => client.loadInstance(this, instance))
2217
2239
  } else {
2218
2240
  const base = {
2219
2241
  operators: this.config.operators,
@@ -2253,7 +2275,7 @@ class Config {
2253
2275
  }
2254
2276
  const instance = this.instances.find((instance) => instance.name == name)
2255
2277
  if (instance) {
2256
- client.processInstance(this, instance)
2278
+ client.loadInstance(this, instance)
2257
2279
  }
2258
2280
  this.hierarchy.edges = this.config.hierarchy
2259
2281
  }
@@ -2654,7 +2676,7 @@ class Config {
2654
2676
  }
2655
2677
 
2656
2678
  // TODO get rid of useOldVersion arg
2657
- addInternal (more, { useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps : hcps = false } = {}) {
2679
+ addInternal (more, { addFirst = false, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps : hcps = false } = {}) {
2658
2680
  validConfigProps(more)
2659
2681
  if (more instanceof Config) {
2660
2682
  more.initialize({ force: false })
@@ -2666,7 +2688,7 @@ class Config {
2666
2688
  }
2667
2689
  }
2668
2690
  if (hcps) {
2669
- handleCalculatedProps(this, more)
2691
+ handleCalculatedProps(this, more, addFirst)
2670
2692
  applyUUID(more, this._uuid)
2671
2693
  }
2672
2694
  for (const key of Object.keys(more)) {
@@ -2691,7 +2713,11 @@ class Config {
2691
2713
  if (!configWords[word]) {
2692
2714
  configWords[word] = []
2693
2715
  }
2694
- configWords[word] = configWords[word].concat(moreWords[word])
2716
+ if (addFirst) {
2717
+ configWords[word] = moreWords[word].concat(configWords[word])
2718
+ } else {
2719
+ configWords[word] = configWords[word].concat(moreWords[word])
2720
+ }
2695
2721
  }
2696
2722
  } else if (key === 'name') {
2697
2723
  /*
@@ -2759,7 +2785,11 @@ class Config {
2759
2785
  }
2760
2786
  // console.log('key', key, 'XXX')
2761
2787
  // console.log('more', JSON.stringify(more, null, 2))
2762
- this.config[key] = this.config[key].concat(more[key])
2788
+ if (addFirst) {
2789
+ this.config[key] = more[key].concat(this.config[key])
2790
+ } else {
2791
+ this.config[key] = this.config[key].concat(more[key])
2792
+ }
2763
2793
  } else {
2764
2794
  if (!(key in this.config)) {
2765
2795
  throw new Error(`Unexpected property in config ${key}`)
@@ -2893,4 +2923,5 @@ module.exports = {
2893
2923
  Config,
2894
2924
  config_toServer,
2895
2925
  operatorKey_valid,
2926
+ handleBridgeProps,
2896
2927
  }