theprogrammablemind 8.0.0-beta.44 → 8.0.0-beta.46

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
@@ -1103,11 +1103,11 @@ const knowledgeModuleImpl = async ({
1103
1103
  }
1104
1104
 
1105
1105
  const createConfig = async () => {
1106
- const config = new Config(configStruct, moduleFromJSFile)
1106
+ const config = new Config(configStruct, moduleFromJSFile, _process)
1107
1107
  config.stop_auto_rebuild()
1108
1108
  await config.add(...(includes || []))
1109
1109
  if (api) {
1110
- config.setApi(api())
1110
+ config.setApi(api)
1111
1111
  }
1112
1112
  if (multiApiInitializer) {
1113
1113
  await config.setMultiApi(multiApiInitializer)
package/package.json CHANGED
@@ -65,6 +65,6 @@
65
65
  "sort-json": "^2.0.0",
66
66
  "uuid": "^8.3.2"
67
67
  },
68
- "version": "8.0.0-beta.44",
68
+ "version": "8.0.0-beta.46",
69
69
  "license": "UNLICENSED"
70
70
  }
package/src/config.js CHANGED
@@ -774,12 +774,11 @@ const multiApiImpl = (initializer) => {
774
774
  multiApi: true,
775
775
 
776
776
  // multi functions
777
- add: async (config, multiApi, api) => {
777
+ add: async (config, multiApi, api, apiConstructor) => {
778
778
  initializer(config, api)
779
779
  const name = api.getName()
780
780
  multiApi.apis[name] = api
781
- // api.objects = config.get('objects')
782
- // api.config = () => config
781
+ multiApi.apiConstructors[name] = apiConstructor
783
782
  multiApi.current = name
784
783
  },
785
784
 
@@ -802,6 +801,9 @@ const multiApiImpl = (initializer) => {
802
801
  apis: {
803
802
  },
804
803
 
804
+ apiConstructors: {
805
+ },
806
+
805
807
  // api functions
806
808
  api: (multiApi) => multiApi.apis[multiApi.current]
807
809
  })
@@ -855,6 +857,7 @@ class Config {
855
857
  addArgs: (...args) => this.addArgs(...args),
856
858
  getBridge: (...args) => this.getBridge(...args),
857
859
  fragment: (...args) => this.fragment(...args),
860
+ server: (...args) => this.server(...args),
858
861
  exists: (...args) => this.exists(...args),
859
862
  addAPI: (...args) => this.addAPI(...args)
860
863
  }
@@ -1632,6 +1635,10 @@ class Config {
1632
1635
  return await configHelpers.processContext(context, this.getParams())
1633
1636
  }
1634
1637
 
1638
+ process (query, options) {
1639
+ return this.clientProcess(this, query, options)
1640
+ }
1641
+
1635
1642
  query (query, options) {
1636
1643
  return this.process(query, options)
1637
1644
  }
@@ -1770,7 +1777,7 @@ class Config {
1770
1777
  }
1771
1778
 
1772
1779
  // configs = [ { config, namespace } ... ]
1773
- constructor (config, module) {
1780
+ constructor (config, module, clientProcess) {
1774
1781
  if (config instanceof Config) {
1775
1782
  throw new Error('Excepted the config argument to be a hash not a Config object')
1776
1783
  }
@@ -1788,6 +1795,7 @@ class Config {
1788
1795
  config.priorities = config.priorities || []
1789
1796
  }
1790
1797
 
1798
+ this.clientProcess = clientProcess
1791
1799
  this.maxDepth = 20 // for generators and semantics
1792
1800
  this.debugLoops = false // for generators and semantics
1793
1801
 
@@ -1895,7 +1903,7 @@ class Config {
1895
1903
  }
1896
1904
 
1897
1905
  async setMultiApi (initializer) {
1898
- await this.setApi(multiApiImpl(initializer))
1906
+ await this.setApi(() => multiApiImpl(initializer))
1899
1907
  }
1900
1908
 
1901
1909
  get multiApi () {
@@ -1953,15 +1961,27 @@ class Config {
1953
1961
  }
1954
1962
  }
1955
1963
 
1956
- async setApi (value) {
1964
+ async setApi (constructor) {
1965
+ if (typeof constructor !== 'function') {
1966
+ throw new Error(`Expected the argument to be an API constructor for ${this.name}.`)
1967
+ }
1968
+ const value = constructor()
1957
1969
  if (!value.initialize) {
1958
1970
  throw new Error(`Expected the API to have an initialize function for ${this.name}.`)
1959
1971
  }
1960
1972
 
1961
1973
  if (this._api && this._api.multiApi) {
1962
- await this._api.add(this, this._api, value)
1974
+ await this._api.add(this, this._api, value, constructor)
1975
+ const previousApiConstructor = this._apiConstructor
1976
+ this._apiConstructor = (config) => {
1977
+ const api = previousApiConstructor(config)
1978
+ // does this need await?
1979
+ api.add(config, api, constructor(config), constructor)
1980
+ return api
1981
+ }
1963
1982
  } else {
1964
- this._api = _.cloneDeep(value)
1983
+ this._api = value
1984
+ this._apiConstructor = constructor
1965
1985
  await this.rebuild()
1966
1986
  }
1967
1987
  }
@@ -2029,7 +2049,11 @@ class Config {
2029
2049
  cp._uuid = cp.configs[0]._uuid
2030
2050
  // update uuid here set the uuid in the objects and add error checking
2031
2051
  cp.initializerFn = this.initializerFn
2032
- cp._api = _.cloneDeep(this._api)
2052
+ // cp._api = _.cloneDeep(this._api)
2053
+ if (this._apiConstructor) {
2054
+ cp._api = this._apiConstructor(cp)
2055
+ cp._apiConstructor = this._apiConstructor
2056
+ }
2033
2057
  cp._namespace = this._namespace
2034
2058
  cp._eqClasses = this._eqClasses
2035
2059
  cp.name = this.name