theprogrammablemind_4wp 7.5.8-beta.22 → 7.5.8-beta.24
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/config.js +49 -79
package/package.json
CHANGED
package/src/config.js
CHANGED
@@ -31,24 +31,16 @@ const config_toServer = (config) => {
|
|
31
31
|
}
|
32
32
|
|
33
33
|
const setupInitializerFNArgs = (config, args) => {
|
34
|
-
const aw = (word, def) => config.addWord(word, def)
|
35
|
-
const ag = (
|
34
|
+
const aw = (word, def) => config.addWord(word, def, args.uuid)
|
35
|
+
const ag = (generator) => config.addGenerator(generator, args.uuid, config.name)
|
36
36
|
const km = (name) => config.getConfig(name)
|
37
|
-
const apis = (name) =>
|
38
|
-
return config.getConfig(name).api
|
39
|
-
/*
|
40
|
-
if (args.isAfterApi) {
|
41
|
-
return config.getConfig(name).api
|
42
|
-
}
|
43
|
-
throw new Error("APIs should not be accessed in the initializer until after they are all initialized. Call initializer like config.initializer(fn, { initAfterApi: true }). Then the args to the initalizer will include isAfterApi which can be used to determine if the initialize is being run before or after the API's are initialized. The default is before.")
|
44
|
-
*/
|
45
|
-
}
|
37
|
+
const apis = (name) => config.getConfig(name).api
|
46
38
|
|
47
39
|
return {
|
48
40
|
...args,
|
49
41
|
addWord: aw,
|
50
42
|
addGenerator: ag,
|
51
|
-
config: config.
|
43
|
+
config: config.getPseudoConfig(args.uuid, args.currentConfig),
|
52
44
|
km,
|
53
45
|
baseConfig: config,
|
54
46
|
apis,
|
@@ -606,19 +598,19 @@ class Config {
|
|
606
598
|
return config_toServer(config)
|
607
599
|
}
|
608
600
|
|
609
|
-
|
601
|
+
getPseudoConfig(uuid, config) {
|
610
602
|
return {
|
611
603
|
description: "this is a pseudo config that has limited functionality due to being available in the initializer function context",
|
612
604
|
addAssociation: (...args) => this.addAssociation(...args),
|
613
605
|
addAssociations: (...args) => this.addAssociations(...args),
|
614
|
-
addBridge: (...args) => this.addBridge(...args),
|
606
|
+
addBridge: (...args) => this.addBridge(...args, uuid),
|
615
607
|
addContextualPriority: (...args) => this.addContextualPriority(...args),
|
616
|
-
addGenerator: (...args) => this.addGenerator(...args),
|
608
|
+
addGenerator: (...args) => this.addGenerator(...args, uuid, config.name),
|
617
609
|
addHierarchy: (...args) => this.addHierarchy(...args),
|
618
|
-
addOperator: (...args) => this.addOperator(...args),
|
610
|
+
addOperator: (...args) => this.addOperator(...args, uuid),
|
619
611
|
addPriorities: (...args) => this.addPriorities(...args),
|
620
|
-
addSemantic: (...args) => this.addSemantic(...args),
|
621
|
-
addWord: (...args) => this.addWord(...args),
|
612
|
+
addSemantic: (...args) => this.addSemantic(...args, uuid, config.name),
|
613
|
+
addWord: (...args) => this.addWord(...args, uuid),
|
622
614
|
|
623
615
|
addArgs: (...args) => this.addArgs(...args),
|
624
616
|
getBridge: (...args) => this.getBridge(...args),
|
@@ -1049,12 +1041,12 @@ class Config {
|
|
1049
1041
|
}
|
1050
1042
|
}
|
1051
1043
|
|
1052
|
-
addBridge (bridge) {
|
1044
|
+
addBridge (bridge, uuid) {
|
1053
1045
|
if (!this.config.bridges) {
|
1054
1046
|
this.config.bridges = []
|
1055
1047
|
}
|
1056
1048
|
const bridges = this.config.bridges
|
1057
|
-
const def = Object.assign({}, bridge, { uuid: this._uuid })
|
1049
|
+
const def = Object.assign({}, bridge, { uuid: uuid || this._uuid })
|
1058
1050
|
|
1059
1051
|
if (global.entodictonDebugBridge) {
|
1060
1052
|
if (global.entodictonDebugBridge[0] == bridge.id && global.entodictonDebugBridge[1] == bridge.level) {
|
@@ -1076,12 +1068,7 @@ class Config {
|
|
1076
1068
|
this._delta.json.bridges.push({ action: 'add', bridge: def })
|
1077
1069
|
}
|
1078
1070
|
|
1079
|
-
addGenerator (
|
1080
|
-
let generator = match
|
1081
|
-
if ((typeof match === 'function') && (typeof apply === 'function')) {
|
1082
|
-
generator = { match, apply }
|
1083
|
-
}
|
1084
|
-
|
1071
|
+
addGenerator (generator, uuid, name) {
|
1085
1072
|
if (!(typeof generator.match === 'function')) {
|
1086
1073
|
throw new Error('addGenerator: Expected matcher to be a function')
|
1087
1074
|
}
|
@@ -1098,17 +1085,12 @@ class Config {
|
|
1098
1085
|
}
|
1099
1086
|
|
1100
1087
|
const generators = this.config.generators
|
1101
|
-
Object.assign(generator, { uuid: this._uuid, km: this.name, index: generators.length })
|
1088
|
+
Object.assign(generator, { uuid: uuid || this._uuid, km: name || this.name, index: generators.length })
|
1102
1089
|
// used to be unshift
|
1103
1090
|
generators.unshift(generator)
|
1104
1091
|
}
|
1105
1092
|
|
1106
|
-
addSemantic (
|
1107
|
-
let semantic = match
|
1108
|
-
if ((typeof match === 'function') && (typeof apply === 'function')) {
|
1109
|
-
semantic = { match, apply }
|
1110
|
-
}
|
1111
|
-
|
1093
|
+
addSemantic (semantic, uuid, name) {
|
1112
1094
|
if (!(typeof semantic.match === 'function')) {
|
1113
1095
|
throw new Error('addSemantic: Expected match to be a function')
|
1114
1096
|
}
|
@@ -1125,11 +1107,11 @@ class Config {
|
|
1125
1107
|
}
|
1126
1108
|
|
1127
1109
|
const semantics = this.config.semantics
|
1128
|
-
Object.assign(semantic, { uuid: this._uuid, km: this.name, index: semantics.length })
|
1110
|
+
Object.assign(semantic, { uuid: uuid || this._uuid, km: name || this.name, index: semantics.length })
|
1129
1111
|
semantics.unshift(semantic)
|
1130
1112
|
}
|
1131
1113
|
|
1132
|
-
addOperator (objectOrPattern) {
|
1114
|
+
addOperator (objectOrPattern, uuid) {
|
1133
1115
|
if (!this.config.operators) {
|
1134
1116
|
this.config.operators = []
|
1135
1117
|
}
|
@@ -1138,9 +1120,9 @@ class Config {
|
|
1138
1120
|
|
1139
1121
|
let operator;
|
1140
1122
|
if (typeof objectOrPattern === 'string') {
|
1141
|
-
operator = { pattern: objectOrPattern, uuid: this._uuid }
|
1123
|
+
operator = { pattern: objectOrPattern, uuid: uuid || this._uuid }
|
1142
1124
|
} else {
|
1143
|
-
operator = Object.assign({}, objectOrPattern, { uuid: this._uuid })
|
1125
|
+
operator = Object.assign({}, objectOrPattern, { uuid: uuid || this._uuid })
|
1144
1126
|
}
|
1145
1127
|
|
1146
1128
|
if (global.entodictonDebugOperator) {
|
@@ -1161,16 +1143,16 @@ class Config {
|
|
1161
1143
|
this._delta.json.operators.push({ action: 'add', operator })
|
1162
1144
|
}
|
1163
1145
|
|
1164
|
-
addWord (word, def) {
|
1165
|
-
this.addWordInternal(word, def)
|
1146
|
+
addWord (word, def, uuid) {
|
1147
|
+
this.addWordInternal(word, def, uuid)
|
1166
1148
|
}
|
1167
1149
|
|
1168
|
-
addWordInternal (word, def) {
|
1150
|
+
addWordInternal (word, def, uuid) {
|
1169
1151
|
if (!this.config.words) {
|
1170
1152
|
this.config.words = {}
|
1171
1153
|
}
|
1172
1154
|
const words = this.config.words
|
1173
|
-
def = Object.assign({}, def, { uuid: this._uuid })
|
1155
|
+
def = Object.assign({}, def, { uuid: uuid || this._uuid })
|
1174
1156
|
if (words[word]) {
|
1175
1157
|
if (!words[word].some((e) => helpers.safeEquals(e, def))) {
|
1176
1158
|
words[word].unshift(def)
|
@@ -1711,7 +1693,6 @@ class Config {
|
|
1711
1693
|
cp._uuid = cp.configs[0]._uuid
|
1712
1694
|
// update uuid here set the uuid in the objects and add error checking
|
1713
1695
|
cp.initializerFn = this.initializerFn
|
1714
|
-
cp.initAfterApi = this.initAfterApi
|
1715
1696
|
cp._api = _.cloneDeep(this._api)
|
1716
1697
|
cp._namespace = this._namespace
|
1717
1698
|
cp._eqClasses = this._eqClasses
|
@@ -1862,7 +1843,6 @@ class Config {
|
|
1862
1843
|
*/
|
1863
1844
|
const objects = {}
|
1864
1845
|
if (config instanceof Config) {
|
1865
|
-
// const aw = addWord(this.config, config.uuid)
|
1866
1846
|
this.get('objects').namespaced[config._uuid] = objects
|
1867
1847
|
if (config._api) {
|
1868
1848
|
config._api.objects = objects
|
@@ -1870,7 +1850,6 @@ class Config {
|
|
1870
1850
|
}
|
1871
1851
|
config.initializerFn(setupInitializerFNArgs(this, { testConfig: config, currentConfig: config, objects, namespace, uuid }))
|
1872
1852
|
} else {
|
1873
|
-
// const aw = addWord(this.config, this.uuid)
|
1874
1853
|
this.get('objects').namespaced[this._uuid] = objects
|
1875
1854
|
if (config._api) {
|
1876
1855
|
config._api.objects = objects
|
@@ -1884,8 +1863,6 @@ class Config {
|
|
1884
1863
|
|
1885
1864
|
initialize ({ force = true } = {}) {
|
1886
1865
|
if (force || !this.wasInitialized) {
|
1887
|
-
// const aw = addWord(this.config, this.uuid)
|
1888
|
-
// this.initializerFn({ addWord: aw, km, config: this, baseConfig: this, currentConfig: this, objects: this.get('objects'), uuid: this._uuid, namespace: '', api: this.api })
|
1889
1866
|
const objects = this.config.objects.namespaced[this._uuid]
|
1890
1867
|
this.initializerFn(setupInitializerFNArgs(this, { testConfig: this, currentConfig: this, objects, uuid: this._uuid, namespace: '' }))
|
1891
1868
|
this.wasInitialized = true
|
@@ -1895,16 +1872,14 @@ class Config {
|
|
1895
1872
|
initializer (fn, options = {}) {
|
1896
1873
|
if (options) {
|
1897
1874
|
for (let option of Object.keys(options)) {
|
1898
|
-
const validOptions = [
|
1899
|
-
if (!
|
1875
|
+
const validOptions = []
|
1876
|
+
if (!validOptions.includes(option)) {
|
1900
1877
|
throw new Error(`For Config.initializer, unrecognized option ${option}. The valid options are ${validOptions}`)
|
1901
1878
|
}
|
1902
1879
|
}
|
1903
1880
|
}
|
1904
|
-
const { initAfterApi = false } = options;
|
1905
1881
|
this.wasInitialized = false
|
1906
|
-
this.
|
1907
|
-
this.initializerFn = (args) => {
|
1882
|
+
this.initializerFn = (args, { dontCallFn } = {}) => {
|
1908
1883
|
const transitoryMode = global.transitoryMode
|
1909
1884
|
global.transitoryMode = false
|
1910
1885
|
// const baseConfig = args.baseConfig
|
@@ -1917,7 +1892,10 @@ class Config {
|
|
1917
1892
|
currentConfig.api.uuid = currentConfig._uuid
|
1918
1893
|
}
|
1919
1894
|
// this.instances.forEach( (instance) => client.processInstance(this, instance) )
|
1920
|
-
|
1895
|
+
// greg55
|
1896
|
+
if (args.isAfterApi) {
|
1897
|
+
fn(args)
|
1898
|
+
}
|
1921
1899
|
currentConfig.wasInitialized = true
|
1922
1900
|
global.transitoryMode = transitoryMode
|
1923
1901
|
}
|
@@ -2105,15 +2083,13 @@ class Config {
|
|
2105
2083
|
const initAfterApis = []
|
2106
2084
|
const reverseIt = true
|
2107
2085
|
const interleaved = true
|
2108
|
-
let isAfterApi = false
|
2109
2086
|
this.configs.forEach((km) => {
|
2110
2087
|
const namespace = km.namespace
|
2111
2088
|
this.config.objects.namespaced[km._uuid] = {}
|
2112
2089
|
const namespacedObjects = this.config.objects.namespaced[km._uuid]
|
2113
2090
|
this.setupNamespace(km)
|
2114
|
-
// const aw =
|
2115
|
-
const
|
2116
|
-
const ag = (matchOrGenerator, applyOrNothing) => this.addGenerator(matchOrGenerator, applyOrNothing)
|
2091
|
+
// const aw = (word, def) => this.addWord(word, def)
|
2092
|
+
// const ag = (matchOrGenerator, applyOrNothing) => this.addGenerator(matchOrGenerator, applyOrNothing)
|
2117
2093
|
let config = km.config
|
2118
2094
|
|
2119
2095
|
if (config.addedArgss) {
|
@@ -2148,25 +2124,22 @@ class Config {
|
|
2148
2124
|
objects: namespacedObjects,
|
2149
2125
|
namespace,
|
2150
2126
|
motivation: (m) => this.addMotivation(m),
|
2151
|
-
|
2152
|
-
/*
|
2153
|
-
if (!isAfterApi) {
|
2154
|
-
throw new Error("APIs should not be accessed in the initializer until after they are all initialized. Call initializer like config.initializer(fn, { initAfterApi: true }). Then the args to the initalizer will include isAfterApi which can be used to determine if the initialize is being run before or after the API's are initialized. The default is before.")
|
2155
|
-
}
|
2156
|
-
*/
|
2157
|
-
return config.api
|
2158
|
-
}
|
2127
|
+
api: config.api,
|
2159
2128
|
}))
|
2160
|
-
|
2161
|
-
|
2162
|
-
|
2163
|
-
|
2164
|
-
|
2165
|
-
|
2166
|
-
|
2167
|
-
|
2129
|
+
|
2130
|
+
const currentConfig = args.currentConfig
|
2131
|
+
|
2132
|
+
if (args.currentConfig.api) {
|
2133
|
+
args.currentConfig.api.objects = args.objects
|
2134
|
+
// TODO assign pseudo config?
|
2135
|
+
args.currentConfig.api.config = () => args.baseConfig
|
2136
|
+
args.currentConfig.api.uuid = args.currentConfig._uuid
|
2137
|
+
args.currentConfig.wasInitialized = true
|
2168
2138
|
}
|
2169
|
-
//
|
2139
|
+
// debugger
|
2140
|
+
// greg55
|
2141
|
+
config.initializerFn(args, { dontCallFn: true })
|
2142
|
+
initAfterApis.unshift({ config, args })
|
2170
2143
|
if (config._api) {
|
2171
2144
|
if (config._api.initialize) {
|
2172
2145
|
// reverse the list
|
@@ -2208,7 +2181,6 @@ class Config {
|
|
2208
2181
|
this.config.semantics = []
|
2209
2182
|
}
|
2210
2183
|
|
2211
|
-
isAfterApi = true
|
2212
2184
|
if (!interleaved) {
|
2213
2185
|
for (const config of addInternals) {
|
2214
2186
|
if (!reverseIt) {
|
@@ -2222,8 +2194,7 @@ class Config {
|
|
2222
2194
|
init()
|
2223
2195
|
}
|
2224
2196
|
for (let init of initAfterApis) {
|
2225
|
-
|
2226
|
-
init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi })
|
2197
|
+
init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true })
|
2227
2198
|
}
|
2228
2199
|
this.instances.forEach((instance) => client.processInstance(this, instance))
|
2229
2200
|
} else {
|
@@ -2256,11 +2227,12 @@ class Config {
|
|
2256
2227
|
}
|
2257
2228
|
// console.log('name -------------', name)
|
2258
2229
|
if (inits[i]) {
|
2230
|
+
// greg55
|
2259
2231
|
inits[i]()
|
2260
2232
|
}
|
2261
2233
|
if (initAfterApis[i]) {
|
2262
2234
|
const init = initAfterApis[i]
|
2263
|
-
init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi})
|
2235
|
+
init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true})
|
2264
2236
|
}
|
2265
2237
|
const instance = this.instances.find((instance) => instance.name == name)
|
2266
2238
|
if (instance) {
|
@@ -2391,10 +2363,8 @@ class Config {
|
|
2391
2363
|
}
|
2392
2364
|
const km = (name) => this.getConfig(name)
|
2393
2365
|
if (config instanceof Config) {
|
2394
|
-
// const aw = addWord(this.config, config.uuid)
|
2395
2366
|
config.initializerFn(setupInitializerFNArgs(this, { isModule: this.isModule, currentConfig: config, testConfig: config, objects: nsobjects, namespace, uuid }))
|
2396
2367
|
} else {
|
2397
|
-
// const aw = addWord(this.config, this.uuid)
|
2398
2368
|
this.initializerFn(setupInitializerFNArgs(this, { isModule: this.isModule, currentConfig: this, testConfig: this, objects: nsobjects, namespace, uuid }))
|
2399
2369
|
}
|
2400
2370
|
})
|