theprogrammablemind_4wp 7.7.0-beta.1 → 7.7.0-beta.10

Sign up to get free protection for your applications and to get access to all the features.
package/client.js CHANGED
@@ -32,16 +32,26 @@ const pickObjects = (testConfig, objects) => {
32
32
 
33
33
  const getAsk = (config) => (uuid) => (asks) => {
34
34
  for (let ask of asks) {
35
+ let oneShot = true // default
36
+ if (ask.oneShot === false) {
37
+ oneShot = false
38
+ }
35
39
  config.addSemantic({
36
40
  uuid,
37
- oneShot: true,
41
+ oneShot,
38
42
  match: (args) => ask.matchr(args),
39
43
  apply: (args) => ask.applyr(args)
40
44
  })
41
45
  }
46
+ let oneShot = true
47
+ for (let ask of asks) {
48
+ if (ask.oneShot === false) {
49
+ oneShot = false
50
+ }
51
+ }
42
52
  config.addSemantic({
43
53
  uuid,
44
- oneShot: true,
54
+ oneShot,
45
55
  match: ({context}) => context.marker == 'controlEnd' || context.marker == 'controlBetween',
46
56
  apply: (args) => {
47
57
  for (let ask of asks) {
@@ -64,7 +74,7 @@ const getAsk = (config) => (uuid) => (asks) => {
64
74
  break
65
75
  }
66
76
  }
67
- }
77
+ }
68
78
  })
69
79
  }
70
80
 
@@ -169,6 +179,7 @@ const setupArgs = (args, config, logs, hierarchy) => {
169
179
  apis: getAPIs(uuid)
170
180
  }
171
181
  }
182
+ Object.assign(args, args.getUUIDScoped(this.uuid))
172
183
  args.breakOnSemantics = false
173
184
  args.theDebugger = {
174
185
  breakOnSemantics: (value) => args.breakOnSemantics = value
@@ -621,6 +632,15 @@ const loadInstance = (config, instance) => {
621
632
  // config.addInternal(results, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false)
622
633
  // config.addInternal(config.template.queries[i], { handleCalculatedProps: true } )
623
634
  config.addInternal(instance.template.queries[i], { addFirst: true, handleCalculatedProps: true } )
635
+ } else if (results.apply) {
636
+ const objects = config.get('objects')
637
+ const args = { objects, getObjects: getObjects(objects) }
638
+ if (instance.queries) {
639
+ args.isInstance = `instance${i}`
640
+ args.instance = instance.queries[i]
641
+ }
642
+ setupArgs(args, config, config.logs, hierarchy)
643
+ results.apply(args)
624
644
  } else {
625
645
  if (results.skipSemantics) {
626
646
  config.config.skipSemantics = results.skipSemantics
@@ -1195,9 +1215,9 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
1195
1215
  }
1196
1216
 
1197
1217
  if (responses.explain_priorities) {
1198
- console.log("Explain Priorities (listed from lower priority to higher priority)")
1199
- for ([inputss, outpus, reason] of responses.explain_priorities) {
1200
- console.log(` ${JSON.stringify(inputss)} reason: ${reason}`)
1218
+ console.log("Explain Priorities")
1219
+ for ([inputs, output, reason] of responses.explain_priorities) {
1220
+ console.log(` inputs: ${JSON.stringify(inputs)} output: ${JSON.stringify(output)} reason: ${reason}`)
1201
1221
  }
1202
1222
  }
1203
1223
  const objects = config.get('objects').namespaced[config.uuid]
@@ -1325,6 +1345,15 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
1325
1345
  config.config.skipSemantics = null
1326
1346
  errorHandler(error)
1327
1347
  }
1348
+ } else if (typeof queryOrExtraConfig == 'function') {
1349
+ console.log('calling initialize function')
1350
+ const initFunction = queryOrExtraConfig
1351
+ const objects = config.get('objects')
1352
+ const args = { objects, getObjects: getObjects(objects) }
1353
+ setupArgs(args, config, config.logs, hierarchy)
1354
+ initFunction(args)
1355
+ accumulators[property].push({ apply: queryOrExtraConfig })
1356
+ await looper(queries)
1328
1357
  } else {
1329
1358
  // extra config is def from a time like operators or bridges or words etc
1330
1359
  // it will just get added to the config
@@ -1357,8 +1386,11 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
1357
1386
  const stabilizeOutput = (template) => {
1358
1387
  stabilizeAssociations(template.associations)
1359
1388
  const stabilize = (results) => {
1360
- for (let result of results) {
1361
- if (result.extraConfig) {
1389
+ for (let i = 0; i < results.length; ++i) {
1390
+ const result = results[i]
1391
+ if (result.apply) {
1392
+ result.apply = result.apply.toString()
1393
+ } else if (result.extraConfig) {
1362
1394
  } else {
1363
1395
  delete result.load_cache_time
1364
1396
  delete result.times
@@ -1643,6 +1675,10 @@ const knowledgeModuleImpl = async ({
1643
1675
  config.config.debug = true
1644
1676
  }
1645
1677
 
1678
+ if (args.reset) {
1679
+ config.config.skip_cache = true
1680
+ }
1681
+
1646
1682
  if (args.explainPriorities) {
1647
1683
  config.config.explain_priorities = true
1648
1684
  }
@@ -1763,7 +1799,7 @@ const knowledgeModuleImpl = async ({
1763
1799
  try {
1764
1800
  config.load(template.template, template.instance, { rebuild: needsRebuild.needsRebuild || options.rebuild, previousResultss: needsRebuild.previousResultss, startOfChanges: needsRebuild.startOfChanges })
1765
1801
  } catch( e ) {
1766
- console.error(`Error loading template for ${config.name}. ${e.error ? e.error : e}`)
1802
+ console.error(`Error loading template for ${config.name}. ${e.error ? e.error : e}${e.stack ? e.stack : ''}`)
1767
1803
  runtime.process.exit(-1)
1768
1804
  }
1769
1805
  if (!args.query) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "devDependencies": {
3
3
  "eslint-plugin-import": "^2.23.4",
4
- "jest": "^26.6.3",
4
+ "jest": "^29.7.0",
5
5
  "@typescript-eslint/parser": "^4.28.4",
6
6
  "@typescript-eslint/eslint-plugin": "^4.28.4",
7
7
  "eslint-plugin-node": "^11.1.0",
@@ -65,6 +65,6 @@
65
65
  "json-stable-stringify": "^1.0.1",
66
66
  "node-fetch": "^2.6.1"
67
67
  },
68
- "version": "7.7.0-beta.1",
68
+ "version": "7.7.0-beta.10",
69
69
  "license": "ISC"
70
70
  }
package/src/config.js CHANGED
@@ -983,6 +983,8 @@ class Config {
983
983
  if (typeof queryOrConfig == 'string') {
984
984
  const query = queryOrConfig
985
985
  return query
986
+ } else if (typeof queryOrConfig == 'function') {
987
+ return { apply: queryOrConfig.toString() }
986
988
  } else {
987
989
  const config = { ...queryOrConfig }
988
990
  delete config.where
@@ -1068,6 +1070,7 @@ class Config {
1068
1070
  startOfChanges = iq
1069
1071
  }
1070
1072
  }
1073
+
1071
1074
  // things were deleted case
1072
1075
  if (templateQueries.length < instanceQueries.length) {
1073
1076
  startOfChanges = instanceQueries.length
@@ -1138,6 +1141,13 @@ class Config {
1138
1141
  return !properties.find( (property) => instance[property] && instance[property].length > 0 )
1139
1142
  }
1140
1143
  if (!isEmpty(instance)) {
1144
+ // fix up apply functions
1145
+ for (let i = 0; i < instance.resultss.length; ++i) {
1146
+ const result = instance.resultss[i]
1147
+ if (result.apply) {
1148
+ result.apply = template.queries[i]
1149
+ }
1150
+ }
1141
1151
  instance.name = this.name
1142
1152
  this.initInstances.push(instance)
1143
1153
  this.instances.push(instance)
@@ -2237,8 +2247,6 @@ class Config {
2237
2247
  const addInternals = []
2238
2248
  const inits = []
2239
2249
  const initAfterApis = []
2240
- const reverseIt = true
2241
- const interleaved = true
2242
2250
  this.configs.forEach((km) => {
2243
2251
  const namespace = km.namespace
2244
2252
  this.config.objects.namespaced[km._uuid] = {}
@@ -2304,58 +2312,30 @@ class Config {
2304
2312
  inits.unshift( () => config._api.initialize({ config: this, km: kmFn, ...args, api: config._api }) )
2305
2313
  // config._api.initialize({ config, api: config._api })
2306
2314
  } else {
2307
- if (interleaved) {
2308
- inits.unshift(null)
2309
- }
2315
+ inits.unshift(null)
2310
2316
  }
2311
2317
  // config._api.objects = namespacedObjects
2312
2318
  // config._api.config = () => this
2313
2319
  // config._api.uuid = config._uuid
2314
2320
  } else {
2315
- if (interleaved) {
2316
- inits.unshift(null)
2317
- }
2321
+ inits.unshift(null)
2318
2322
  }
2319
2323
  config.setUUIDs()
2320
2324
  config.applyNamespace(config.config, namespace, config.uuid)
2321
2325
  if (!isSelf) {
2322
- if (!reverseIt) {
2323
- addInternals.push(config)
2324
- } else {
2325
- addInternals.unshift(config)
2326
- }
2326
+ addInternals.unshift(config)
2327
2327
  } else {
2328
- if (interleaved) {
2329
- addInternals.unshift(null)
2330
- }
2328
+ addInternals.unshift(null)
2331
2329
  }
2332
2330
  km.valid()
2333
2331
  })
2334
2332
 
2335
2333
  const generators = this.config.generators
2336
2334
  const semantics = this.config.semantics
2337
- if (reverseIt) {
2338
- this.config.generators = []
2339
- this.config.semantics = []
2340
- }
2335
+ this.config.generators = []
2336
+ this.config.semantics = []
2341
2337
 
2342
- if (!interleaved) {
2343
- for (const config of addInternals) {
2344
- if (!reverseIt) {
2345
- this.addInternal(config, { includeNamespace: false, allowNameToBeNull: true })
2346
- } else {
2347
- this.addInternalR(config, true, false, false, true)
2348
- }
2349
- }
2350
- // console.log('inits from config', inits)
2351
- for (const init of inits) {
2352
- init()
2353
- }
2354
- for (let init of initAfterApis) {
2355
- init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true })
2356
- }
2357
- this.instances.forEach((instance) => client.loadInstance(this, instance))
2358
- } else {
2338
+ {
2359
2339
  const base = {
2360
2340
  operators: this.config.operators,
2361
2341
  bridges: this.config.bridges,
@@ -2371,13 +2351,16 @@ class Config {
2371
2351
  this.config.priorities = []
2372
2352
  this.config.associations = { positive: [], negative: [] }
2373
2353
  this.config.words = {}
2374
-
2354
+
2375
2355
  for (let i = 0; i < addInternals.length; ++i) {
2376
2356
  let name;
2377
2357
  if (addInternals[i]) {
2378
2358
  this.addInternalR(addInternals[i], true, false, false, true)
2379
2359
  name = addInternals[i].name
2380
2360
  } else{
2361
+ // the ones defined in config must come after the ones in the templates
2362
+ this.config.generators = generators.concat(this.config.generators)
2363
+ this.config.semantics = semantics.concat(this.config.semantics)
2381
2364
  this.addInternalR(base, true, false, false, true)
2382
2365
  name = this.name
2383
2366
  }
@@ -2398,10 +2381,6 @@ class Config {
2398
2381
  }
2399
2382
  }
2400
2383
 
2401
- if (reverseIt) {
2402
- this.config.generators = generators.concat(this.config.generators)
2403
- this.config.semantics = semantics.concat(this.config.semantics)
2404
- }
2405
2384
  this.hierarchy.edges = this.config.hierarchy
2406
2385
  this.valid()
2407
2386
  this.checkBridges()
package/src/helpers.js CHANGED
@@ -272,6 +272,8 @@ const mapInPlace = (list, fn) => {
272
272
  const updateQueries = (queryOrConfig) => {
273
273
  if (typeof queryOrConfig == 'string' || queryOrConfig.query) {
274
274
  return queryOrConfig
275
+ } else if (typeof queryOrConfig == 'function') {
276
+ return { apply: queryOrConfig.toString() }
275
277
  } else {
276
278
  const config = queryOrConfig
277
279
  return functionsToStrings(config)