theprogrammablemind_4wp 8.0.0-beta.44 → 8.0.0-beta.45
Sign up to get free protection for your applications and to get access to all the features.
- package/client.js +1 -1
- package/package.json +1 -1
- package/src/config.js +26 -8
package/client.js
CHANGED
@@ -1107,7 +1107,7 @@ const knowledgeModuleImpl = async ({
|
|
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
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
|
-
|
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
|
})
|
@@ -1895,7 +1897,7 @@ class Config {
|
|
1895
1897
|
}
|
1896
1898
|
|
1897
1899
|
async setMultiApi (initializer) {
|
1898
|
-
await this.setApi(multiApiImpl(initializer))
|
1900
|
+
await this.setApi(() => multiApiImpl(initializer))
|
1899
1901
|
}
|
1900
1902
|
|
1901
1903
|
get multiApi () {
|
@@ -1953,15 +1955,27 @@ class Config {
|
|
1953
1955
|
}
|
1954
1956
|
}
|
1955
1957
|
|
1956
|
-
async setApi (
|
1958
|
+
async setApi (constructor) {
|
1959
|
+
if (typeof constructor !== 'function') {
|
1960
|
+
throw new Error(`Expected the argument to be an API constructor for ${this.name}.`)
|
1961
|
+
}
|
1962
|
+
const value = constructor()
|
1957
1963
|
if (!value.initialize) {
|
1958
1964
|
throw new Error(`Expected the API to have an initialize function for ${this.name}.`)
|
1959
1965
|
}
|
1960
1966
|
|
1961
1967
|
if (this._api && this._api.multiApi) {
|
1962
|
-
await this._api.add(this, this._api, value)
|
1968
|
+
await this._api.add(this, this._api, value, constructor)
|
1969
|
+
const previousApiConstructor = this._apiConstructor
|
1970
|
+
this._apiConstructor = (config) => {
|
1971
|
+
const api = previousApiConstructor(config)
|
1972
|
+
// does this need await?
|
1973
|
+
api.add(config, api, constructor(config), constructor)
|
1974
|
+
return api
|
1975
|
+
}
|
1963
1976
|
} else {
|
1964
|
-
this._api =
|
1977
|
+
this._api = value
|
1978
|
+
this._apiConstructor = constructor
|
1965
1979
|
await this.rebuild()
|
1966
1980
|
}
|
1967
1981
|
}
|
@@ -2029,7 +2043,11 @@ class Config {
|
|
2029
2043
|
cp._uuid = cp.configs[0]._uuid
|
2030
2044
|
// update uuid here set the uuid in the objects and add error checking
|
2031
2045
|
cp.initializerFn = this.initializerFn
|
2032
|
-
cp._api = _.cloneDeep(this._api)
|
2046
|
+
// cp._api = _.cloneDeep(this._api)
|
2047
|
+
if (this._apiConstructor) {
|
2048
|
+
cp._api = this._apiConstructor(cp)
|
2049
|
+
cp._apiConstructor = this._apiConstructor
|
2050
|
+
}
|
2033
2051
|
cp._namespace = this._namespace
|
2034
2052
|
cp._eqClasses = this._eqClasses
|
2035
2053
|
cp.name = this.name
|