theprogrammablemind 9.5.1-beta.10 → 9.5.1-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client.js CHANGED
@@ -2011,9 +2011,15 @@ const ensureTestFile = (module, name, type) => {
2011
2011
  }
2012
2012
 
2013
2013
  const knowledgeModule = async (...args) => {
2014
- await knowledgeModuleImpl(...args).catch((e) => {
2014
+ await knowledgeModuleImpl(...args).catch(async (e) => {
2015
2015
  console.error(e)
2016
- process.exit(-1)
2016
+ function sleep(ms) {
2017
+ return new Promise((resolve) => {
2018
+ setTimeout(resolve, ms);
2019
+ });
2020
+ }
2021
+ await sleep(1) // get the stderr to flush
2022
+ await process.exit(-1); // tiny trick: empty write forces flush of console.error buffer
2017
2023
  })
2018
2024
  }
2019
2025
 
package/package.json CHANGED
@@ -73,6 +73,6 @@
73
73
  "sort-json": "^2.0.0",
74
74
  "uuid": "^8.3.2"
75
75
  },
76
- "version": "9.5.1-beta.10",
76
+ "version": "9.5.1-beta.11",
77
77
  "license": "UNLICENSED"
78
78
  }
package/src/config.js CHANGED
@@ -10,7 +10,7 @@ const { ecatch } = require('./helpers')
10
10
  const runtime = require('../runtime')
11
11
  const _ = require('lodash')
12
12
  const db = require('./debug')
13
- const { fragmentInstantiator } = require('./fragments')
13
+ const { fragmentInstantiator, fragmentMapperInstantiator } = require('./fragments')
14
14
 
15
15
  const debugBreak = () => {
16
16
  // debugger
@@ -903,6 +903,10 @@ class Config {
903
903
  return config_toServer(config)
904
904
  }
905
905
 
906
+ async run(handler) {
907
+ return configHelpers.run(this, handler)
908
+ }
909
+
906
910
  async fixtures () {
907
911
  if (this.testConfig?.fixtures) {
908
912
  const args = {}
@@ -1108,26 +1112,42 @@ class Config {
1108
1112
  return instance
1109
1113
  }
1110
1114
 
1111
- fragment (args, query) {
1115
+ getFragment(query) {
1112
1116
  for (const instance of (this.instances || [])) {
1113
1117
  for (const fragment of (instance.fragments || [])) {
1114
1118
  if (fragment.query === query) {
1115
- return fragmentInstantiator(args, fragment.contexts)
1119
+ return fragment
1116
1120
  }
1117
1121
  }
1118
1122
  for (const fragment of (instance.resultss || [])) {
1119
1123
  if (fragment.isFragment && fragment.query === query) {
1120
- return fragmentInstantiator(args, fragment.contexts)
1124
+ return fragment
1121
1125
  }
1122
1126
  }
1123
1127
  for (const fragment of (this.fragmentsBeingBuilt || [])) {
1124
1128
  if (fragment.query === query) {
1125
- return fragmentInstantiator(args, fragment.contexts)
1129
+ return fragment
1126
1130
  }
1127
1131
  }
1128
1132
  }
1129
1133
  }
1130
1134
 
1135
+ fragment (args, query) {
1136
+ const fragment = this.getFragment(query)
1137
+ if (fragment) {
1138
+ return fragmentInstantiator(args, fragment.contexts)
1139
+ }
1140
+ }
1141
+
1142
+ fragmentMapper (args, values, fromModelQuery, toModelQuery) {
1143
+ const fromModelFragment = this.getFragment(fromModelQuery)
1144
+ console.dir(fromModelFragment)
1145
+ const toModelFragment = this.getFragment(toModelQuery)
1146
+ console.dir(toModelFragment)
1147
+ const mapper = fragmentMapperInstantiator(values, fromModelFragment.contexts, toModelFragment.contexts)
1148
+ return mapper
1149
+ }
1150
+
1131
1151
  // { rebuild: false, isModule: false }
1132
1152
  needsRebuild (template, instance, options) {
1133
1153
  if (options.rebuild) {
@@ -1832,6 +1852,16 @@ class Config {
1832
1852
  }
1833
1853
  }
1834
1854
 
1855
+ getObjects () {
1856
+ const configs = {}
1857
+ const ns = this.config.objects.namespaced
1858
+ configs[this.name] = this
1859
+ for (const config of this.configs) {
1860
+ configs[config._name] = ns[config._uuid]
1861
+ }
1862
+ return configs
1863
+ }
1864
+
1835
1865
  getConfig (name) {
1836
1866
  if (this.name === name) {
1837
1867
  return this
@@ -121,6 +121,9 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
121
121
  args.fragments = (query) => {
122
122
  return config.fragment(args, query)
123
123
  }
124
+ args.fragmentMapper = (values, fromModelQuery, toModelQuery) => {
125
+ return config.fragmentMapper(args, values, fromModelQuery, toModelQuery)
126
+ }
124
127
  args.breakOnSemantics = false
125
128
  args.theDebugger = {
126
129
  breakOnSemantics: (value) => args.breakOnSemantics = value
@@ -202,6 +205,23 @@ const getObjects = (objects) => {
202
205
  }
203
206
  }
204
207
 
208
+ const run = async (config, handler) => {
209
+ // map to hash
210
+ config = config || {}
211
+ if (config.config) {
212
+ config = config
213
+ }
214
+
215
+ const hierarchy = new DigraphInternal((config.config || {}).hierarchy || [])
216
+
217
+ debugger
218
+ const objects = config.config.objects.namespaced[config.uuid]
219
+ const logs = []
220
+ const args = {}
221
+ setupArgs(args, config, logs, hierarchy)
222
+ return handler(args)
223
+ }
224
+
205
225
  const processContext = async (context, { objects = {}, config, logs = [] }) => {
206
226
  const generators = config.getGenerators(logs)
207
227
  const semantics = config.getSemantics(logs)
@@ -516,6 +536,7 @@ module.exports = {
516
536
  // listable,
517
537
  setupArgs,
518
538
  processContext,
539
+ run,
519
540
  getObjects,
520
541
  gs,
521
542
  processContextsB,