theprogrammablemind 7.5.8-beta.21 → 7.5.8-beta.23
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/package.json +1 -1
- package/src/config.js +69 -89
package/package.json
CHANGED
package/src/config.js
CHANGED
@@ -30,6 +30,23 @@ const config_toServer = (config) => {
|
|
30
30
|
}
|
31
31
|
}
|
32
32
|
|
33
|
+
const setupInitializerFNArgs = (config, args) => {
|
34
|
+
const aw = (word, def) => config.addWord(word, def, args.uuid)
|
35
|
+
const ag = (generator) => config.addGenerator(generator, args.uuid, config.name)
|
36
|
+
const km = (name) => config.getConfig(name)
|
37
|
+
const apis = (name) => config.getConfig(name).api
|
38
|
+
|
39
|
+
return {
|
40
|
+
...args,
|
41
|
+
addWord: aw,
|
42
|
+
addGenerator: ag,
|
43
|
+
config: config.getPseudoConfig(args.uuid, args.currentConfig),
|
44
|
+
km,
|
45
|
+
baseConfig: config,
|
46
|
+
apis,
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
33
50
|
const contextual_priorities_toServer = (cp) => {
|
34
51
|
if (cp.context && cp.choose) {
|
35
52
|
return [cp.context, cp.choose]
|
@@ -581,19 +598,19 @@ class Config {
|
|
581
598
|
return config_toServer(config)
|
582
599
|
}
|
583
600
|
|
584
|
-
|
601
|
+
getPseudoConfig(uuid, config) {
|
585
602
|
return {
|
586
603
|
description: "this is a pseudo config that has limited functionality due to being available in the initializer function context",
|
587
604
|
addAssociation: (...args) => this.addAssociation(...args),
|
588
605
|
addAssociations: (...args) => this.addAssociations(...args),
|
589
|
-
addBridge: (...args) => this.addBridge(...args),
|
606
|
+
addBridge: (...args) => this.addBridge(...args, uuid),
|
590
607
|
addContextualPriority: (...args) => this.addContextualPriority(...args),
|
591
|
-
addGenerator: (...args) => this.addGenerator(...args),
|
608
|
+
addGenerator: (...args) => this.addGenerator(...args, uuid, config.name),
|
592
609
|
addHierarchy: (...args) => this.addHierarchy(...args),
|
593
|
-
addOperator: (...args) => this.addOperator(...args),
|
610
|
+
addOperator: (...args) => this.addOperator(...args, uuid),
|
594
611
|
addPriorities: (...args) => this.addPriorities(...args),
|
595
|
-
addSemantic: (...args) => this.addSemantic(...args),
|
596
|
-
addWord: (...args) => this.addWord(...args),
|
612
|
+
addSemantic: (...args) => this.addSemantic(...args, uuid, config.name),
|
613
|
+
addWord: (...args) => this.addWord(...args, uuid),
|
597
614
|
|
598
615
|
addArgs: (...args) => this.addArgs(...args),
|
599
616
|
getBridge: (...args) => this.getBridge(...args),
|
@@ -1024,12 +1041,12 @@ class Config {
|
|
1024
1041
|
}
|
1025
1042
|
}
|
1026
1043
|
|
1027
|
-
addBridge (bridge) {
|
1044
|
+
addBridge (bridge, uuid) {
|
1028
1045
|
if (!this.config.bridges) {
|
1029
1046
|
this.config.bridges = []
|
1030
1047
|
}
|
1031
1048
|
const bridges = this.config.bridges
|
1032
|
-
const def = Object.assign({}, bridge, { uuid: this._uuid })
|
1049
|
+
const def = Object.assign({}, bridge, { uuid: uuid || this._uuid })
|
1033
1050
|
|
1034
1051
|
if (global.entodictonDebugBridge) {
|
1035
1052
|
if (global.entodictonDebugBridge[0] == bridge.id && global.entodictonDebugBridge[1] == bridge.level) {
|
@@ -1051,12 +1068,7 @@ class Config {
|
|
1051
1068
|
this._delta.json.bridges.push({ action: 'add', bridge: def })
|
1052
1069
|
}
|
1053
1070
|
|
1054
|
-
addGenerator (
|
1055
|
-
let generator = match
|
1056
|
-
if ((typeof match === 'function') && (typeof apply === 'function')) {
|
1057
|
-
generator = { match, apply }
|
1058
|
-
}
|
1059
|
-
|
1071
|
+
addGenerator (generator, uuid, name) {
|
1060
1072
|
if (!(typeof generator.match === 'function')) {
|
1061
1073
|
throw new Error('addGenerator: Expected matcher to be a function')
|
1062
1074
|
}
|
@@ -1073,17 +1085,12 @@ class Config {
|
|
1073
1085
|
}
|
1074
1086
|
|
1075
1087
|
const generators = this.config.generators
|
1076
|
-
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 })
|
1077
1089
|
// used to be unshift
|
1078
1090
|
generators.unshift(generator)
|
1079
1091
|
}
|
1080
1092
|
|
1081
|
-
addSemantic (
|
1082
|
-
let semantic = match
|
1083
|
-
if ((typeof match === 'function') && (typeof apply === 'function')) {
|
1084
|
-
semantic = { match, apply }
|
1085
|
-
}
|
1086
|
-
|
1093
|
+
addSemantic (semantic, uuid, name) {
|
1087
1094
|
if (!(typeof semantic.match === 'function')) {
|
1088
1095
|
throw new Error('addSemantic: Expected match to be a function')
|
1089
1096
|
}
|
@@ -1100,11 +1107,11 @@ class Config {
|
|
1100
1107
|
}
|
1101
1108
|
|
1102
1109
|
const semantics = this.config.semantics
|
1103
|
-
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 })
|
1104
1111
|
semantics.unshift(semantic)
|
1105
1112
|
}
|
1106
1113
|
|
1107
|
-
addOperator (objectOrPattern) {
|
1114
|
+
addOperator (objectOrPattern, uuid) {
|
1108
1115
|
if (!this.config.operators) {
|
1109
1116
|
this.config.operators = []
|
1110
1117
|
}
|
@@ -1113,9 +1120,9 @@ class Config {
|
|
1113
1120
|
|
1114
1121
|
let operator;
|
1115
1122
|
if (typeof objectOrPattern === 'string') {
|
1116
|
-
operator = { pattern: objectOrPattern, uuid: this._uuid }
|
1123
|
+
operator = { pattern: objectOrPattern, uuid: uuid || this._uuid }
|
1117
1124
|
} else {
|
1118
|
-
operator = Object.assign({}, objectOrPattern, { uuid: this._uuid })
|
1125
|
+
operator = Object.assign({}, objectOrPattern, { uuid: uuid || this._uuid })
|
1119
1126
|
}
|
1120
1127
|
|
1121
1128
|
if (global.entodictonDebugOperator) {
|
@@ -1136,16 +1143,16 @@ class Config {
|
|
1136
1143
|
this._delta.json.operators.push({ action: 'add', operator })
|
1137
1144
|
}
|
1138
1145
|
|
1139
|
-
addWord (word, def) {
|
1140
|
-
this.addWordInternal(word, def)
|
1146
|
+
addWord (word, def, uuid) {
|
1147
|
+
this.addWordInternal(word, def, uuid)
|
1141
1148
|
}
|
1142
1149
|
|
1143
|
-
addWordInternal (word, def) {
|
1150
|
+
addWordInternal (word, def, uuid) {
|
1144
1151
|
if (!this.config.words) {
|
1145
1152
|
this.config.words = {}
|
1146
1153
|
}
|
1147
1154
|
const words = this.config.words
|
1148
|
-
def = Object.assign({}, def, { uuid: this._uuid })
|
1155
|
+
def = Object.assign({}, def, { uuid: uuid || this._uuid })
|
1149
1156
|
if (words[word]) {
|
1150
1157
|
if (!words[word].some((e) => helpers.safeEquals(e, def))) {
|
1151
1158
|
words[word].unshift(def)
|
@@ -1686,7 +1693,6 @@ class Config {
|
|
1686
1693
|
cp._uuid = cp.configs[0]._uuid
|
1687
1694
|
// update uuid here set the uuid in the objects and add error checking
|
1688
1695
|
cp.initializerFn = this.initializerFn
|
1689
|
-
cp.initAfterApi = this.initAfterApi
|
1690
1696
|
cp._api = _.cloneDeep(this._api)
|
1691
1697
|
cp._namespace = this._namespace
|
1692
1698
|
cp._eqClasses = this._eqClasses
|
@@ -1836,27 +1842,20 @@ class Config {
|
|
1836
1842
|
}
|
1837
1843
|
*/
|
1838
1844
|
const objects = {}
|
1839
|
-
const km = (name) => this.getConfig(name)
|
1840
1845
|
if (config instanceof Config) {
|
1841
|
-
// const aw = addWord(this.config, config.uuid)
|
1842
|
-
const aw = (word, def) => this.addWord(word, def)
|
1843
|
-
const ag = (matchOrGenerator, applyOrNothing) => this.addGenerator(matchOrGenerator, applyOrNothing)
|
1844
1846
|
this.get('objects').namespaced[config._uuid] = objects
|
1845
1847
|
if (config._api) {
|
1846
1848
|
config._api.objects = objects
|
1847
1849
|
config._api.config = () => this
|
1848
1850
|
}
|
1849
|
-
config.initializerFn(
|
1851
|
+
config.initializerFn(setupInitializerFNArgs(this, { testConfig: config, currentConfig: config, objects, namespace, uuid }))
|
1850
1852
|
} else {
|
1851
|
-
// const aw = addWord(this.config, this.uuid)
|
1852
|
-
const aw = (word, def) => this.addWord(word, def)
|
1853
|
-
const ag = (matchOrGenerator, applyOrNothing) => this.addGenerator(matchOrGenerator, applyOrNothing)
|
1854
1853
|
this.get('objects').namespaced[this._uuid] = objects
|
1855
1854
|
if (config._api) {
|
1856
1855
|
config._api.objects = objects
|
1857
1856
|
config._api.config = () => this
|
1858
1857
|
}
|
1859
|
-
this.initializerFn(
|
1858
|
+
this.initializerFn(setupInitializerFNArgs(this, { testConfig: this, currentConfig: this, objects, namespace, uuid }))
|
1860
1859
|
}
|
1861
1860
|
})
|
1862
1861
|
this.instances.forEach((instance) => client.processInstance(this, instance))
|
@@ -1864,13 +1863,8 @@ class Config {
|
|
1864
1863
|
|
1865
1864
|
initialize ({ force = true } = {}) {
|
1866
1865
|
if (force || !this.wasInitialized) {
|
1867
|
-
// const aw = addWord(this.config, this.uuid)
|
1868
|
-
const aw = (word, def) => this.addWord(word, def)
|
1869
|
-
const ag = (matchOrGenerator, applyOrNothing) => this.addGenerator(matchOrGenerator, applyOrNothing)
|
1870
|
-
const km = (name) => this.getConfig(name)
|
1871
|
-
// this.initializerFn({ addWord: aw, km, config: this, baseConfig: this, currentConfig: this, objects: this.get('objects'), uuid: this._uuid, namespace: '', api: this.api })
|
1872
1866
|
const objects = this.config.objects.namespaced[this._uuid]
|
1873
|
-
this.initializerFn(
|
1867
|
+
this.initializerFn(setupInitializerFNArgs(this, { testConfig: this, currentConfig: this, objects, uuid: this._uuid, namespace: '' }))
|
1874
1868
|
this.wasInitialized = true
|
1875
1869
|
}
|
1876
1870
|
}
|
@@ -1878,16 +1872,14 @@ class Config {
|
|
1878
1872
|
initializer (fn, options = {}) {
|
1879
1873
|
if (options) {
|
1880
1874
|
for (let option of Object.keys(options)) {
|
1881
|
-
const validOptions = [
|
1882
|
-
if (!
|
1875
|
+
const validOptions = []
|
1876
|
+
if (!validOptions.includes(option)) {
|
1883
1877
|
throw new Error(`For Config.initializer, unrecognized option ${option}. The valid options are ${validOptions}`)
|
1884
1878
|
}
|
1885
1879
|
}
|
1886
1880
|
}
|
1887
|
-
const { initAfterApi = false } = options;
|
1888
1881
|
this.wasInitialized = false
|
1889
|
-
this.
|
1890
|
-
this.initializerFn = (args) => {
|
1882
|
+
this.initializerFn = (args, { dontCallFn } = {}) => {
|
1891
1883
|
const transitoryMode = global.transitoryMode
|
1892
1884
|
global.transitoryMode = false
|
1893
1885
|
// const baseConfig = args.baseConfig
|
@@ -1900,7 +1892,10 @@ class Config {
|
|
1900
1892
|
currentConfig.api.uuid = currentConfig._uuid
|
1901
1893
|
}
|
1902
1894
|
// this.instances.forEach( (instance) => client.processInstance(this, instance) )
|
1903
|
-
|
1895
|
+
// greg55
|
1896
|
+
if (args.isAfterApi) {
|
1897
|
+
fn(args)
|
1898
|
+
}
|
1904
1899
|
currentConfig.wasInitialized = true
|
1905
1900
|
global.transitoryMode = transitoryMode
|
1906
1901
|
}
|
@@ -2088,15 +2083,13 @@ class Config {
|
|
2088
2083
|
const initAfterApis = []
|
2089
2084
|
const reverseIt = true
|
2090
2085
|
const interleaved = true
|
2091
|
-
let isAfterApi = false
|
2092
2086
|
this.configs.forEach((km) => {
|
2093
2087
|
const namespace = km.namespace
|
2094
2088
|
this.config.objects.namespaced[km._uuid] = {}
|
2095
2089
|
const namespacedObjects = this.config.objects.namespaced[km._uuid]
|
2096
2090
|
this.setupNamespace(km)
|
2097
|
-
// const aw =
|
2098
|
-
const
|
2099
|
-
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)
|
2100
2093
|
let config = km.config
|
2101
2094
|
|
2102
2095
|
if (config.addedArgss) {
|
@@ -2122,37 +2115,31 @@ class Config {
|
|
2122
2115
|
return config
|
2123
2116
|
}
|
2124
2117
|
// const hierarchy = new DigraphInternal((config.config || {}).hierarchy)
|
2125
|
-
const args = new Object({
|
2118
|
+
const args = new Object(setupInitializerFNArgs(this, {
|
2126
2119
|
isModule,
|
2127
|
-
addWord: aw,
|
2128
|
-
addGenerator: ag,
|
2129
|
-
km: kmFn,
|
2130
2120
|
hierarchy: this.hierarchy,
|
2131
2121
|
testConfig: config,
|
2132
|
-
config: this.getPsuedoConfig(),
|
2133
|
-
baseConfig: this,
|
2134
2122
|
currentConfig: config,
|
2135
2123
|
uuid: config._uuid,
|
2136
2124
|
objects: namespacedObjects,
|
2137
2125
|
namespace,
|
2138
2126
|
motivation: (m) => this.addMotivation(m),
|
2139
|
-
|
2140
|
-
|
2141
|
-
|
2142
|
-
|
2143
|
-
|
2144
|
-
|
2145
|
-
|
2146
|
-
|
2147
|
-
|
2148
|
-
|
2149
|
-
|
2150
|
-
} else {
|
2151
|
-
if (interleaved) {
|
2152
|
-
initAfterApis.unshift(null)
|
2153
|
-
}
|
2127
|
+
api: config.api,
|
2128
|
+
}))
|
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
|
2154
2138
|
}
|
2155
|
-
//
|
2139
|
+
// debugger
|
2140
|
+
// greg55
|
2141
|
+
config.initializerFn(args, { dontCallFn: true })
|
2142
|
+
initAfterApis.unshift({ config, args })
|
2156
2143
|
if (config._api) {
|
2157
2144
|
if (config._api.initialize) {
|
2158
2145
|
// reverse the list
|
@@ -2194,7 +2181,6 @@ class Config {
|
|
2194
2181
|
this.config.semantics = []
|
2195
2182
|
}
|
2196
2183
|
|
2197
|
-
isAfterApi = true
|
2198
2184
|
if (!interleaved) {
|
2199
2185
|
for (const config of addInternals) {
|
2200
2186
|
if (!reverseIt) {
|
@@ -2208,8 +2194,7 @@ class Config {
|
|
2208
2194
|
init()
|
2209
2195
|
}
|
2210
2196
|
for (let init of initAfterApis) {
|
2211
|
-
|
2212
|
-
init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi })
|
2197
|
+
init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true })
|
2213
2198
|
}
|
2214
2199
|
this.instances.forEach((instance) => client.processInstance(this, instance))
|
2215
2200
|
} else {
|
@@ -2242,11 +2227,12 @@ class Config {
|
|
2242
2227
|
}
|
2243
2228
|
// console.log('name -------------', name)
|
2244
2229
|
if (inits[i]) {
|
2230
|
+
// greg55
|
2245
2231
|
inits[i]()
|
2246
2232
|
}
|
2247
2233
|
if (initAfterApis[i]) {
|
2248
2234
|
const init = initAfterApis[i]
|
2249
|
-
init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi})
|
2235
|
+
init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true})
|
2250
2236
|
}
|
2251
2237
|
const instance = this.instances.find((instance) => instance.name == name)
|
2252
2238
|
if (instance) {
|
@@ -2377,15 +2363,9 @@ class Config {
|
|
2377
2363
|
}
|
2378
2364
|
const km = (name) => this.getConfig(name)
|
2379
2365
|
if (config instanceof Config) {
|
2380
|
-
|
2381
|
-
const aw = (word, def) => this.addWord(word, def)
|
2382
|
-
const ag = (matchOrGenerator, applyOrNothing) => this.addGenerator(matchOrGenerator, applyOrNothing)
|
2383
|
-
config.initializerFn({ isModule: this.isModule, addWord: aw, addGenerator: ag, baseConfig: this, km, currentConfig: config, testConfig: config, config: this.getPsuedoConfig(), objects: nsobjects, namespace, uuid, api: config.api })
|
2366
|
+
config.initializerFn(setupInitializerFNArgs(this, { isModule: this.isModule, currentConfig: config, testConfig: config, objects: nsobjects, namespace, uuid }))
|
2384
2367
|
} else {
|
2385
|
-
|
2386
|
-
const aw = (word, def) => this.addWord(word, def)
|
2387
|
-
const ag = (matchOrGenerator, applyOrNothing) => this.addGenerator(matchOrGenerator, applyOrNothing)
|
2388
|
-
this.initializerFn({ isModule: this.isModule, addWord: aw, addGenerator: ag, baseConfig: this, km, currentConfig: this, testConfig: this, config: this.getPsuedoConfig(), objects: nsobjects, namespace, uuid, api: this.api })
|
2368
|
+
this.initializerFn(setupInitializerFNArgs(this, { isModule: this.isModule, currentConfig: this, testConfig: this, objects: nsobjects, namespace, uuid }))
|
2389
2369
|
}
|
2390
2370
|
})
|
2391
2371
|
}
|