theprogrammablemind_4wp 8.0.0-beta.2 → 8.0.0-beta.21
Sign up to get free protection for your applications and to get access to all the features.
- package/client.js +25 -26
- package/package.json +12 -13
- package/src/config.js +111 -208
- package/src/semantics.js +2 -2
package/client.js
CHANGED
@@ -447,7 +447,7 @@ const setupContexts = (rawContexts) => {
|
|
447
447
|
return contexts
|
448
448
|
}
|
449
449
|
|
450
|
-
const processContextsB = ({ config, hierarchy, semantics, generators, json, isTest, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs }) => {
|
450
|
+
const processContextsB = async ({ config, hierarchy, semantics, generators, json, isTest, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs }) => {
|
451
451
|
// TODO fix this name to contextsPrime
|
452
452
|
const contextsPrime = []
|
453
453
|
const generatedPrime = []
|
@@ -634,7 +634,7 @@ const setupProcessB = ({ config, initializer, allowDelta = false } = {}) => {
|
|
634
634
|
}
|
635
635
|
|
636
636
|
// instance template loadTemplate
|
637
|
-
const loadInstance = (config, instance) => {
|
637
|
+
const loadInstance = async (config, instance) => {
|
638
638
|
const transitoryMode = global.transitoryMode
|
639
639
|
global.transitoryMode = false
|
640
640
|
|
@@ -676,7 +676,7 @@ const loadInstance = (config, instance) => {
|
|
676
676
|
const args = { config, hierarchy, json: results, commandLineArgs: {} }
|
677
677
|
args.isInstance = `instance${i}`
|
678
678
|
args.instance = ''
|
679
|
-
processContextsB(args)
|
679
|
+
await processContextsB(args)
|
680
680
|
if (results.skipSemantics) {
|
681
681
|
config.config.skipSemantics = null
|
682
682
|
}
|
@@ -701,7 +701,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
701
701
|
// ensure same start state
|
702
702
|
try {
|
703
703
|
if (writeTests) {
|
704
|
-
config.rebuild()
|
704
|
+
await config.rebuild()
|
705
705
|
const objects = getObjects(config.config.objects)(config.uuid)
|
706
706
|
}
|
707
707
|
} catch (error) {
|
@@ -773,7 +773,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
773
773
|
start = runtime.performance.performance.now()
|
774
774
|
}
|
775
775
|
const { contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime } =
|
776
|
-
processContextsB({ isTest, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
776
|
+
await processContextsB({ isTest, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
777
777
|
if (isTest) {
|
778
778
|
end = runtime.performance.performance.now()
|
779
779
|
clientSideTime = end - start
|
@@ -865,8 +865,12 @@ const getConfigForTest = (config, testConfig) => {
|
|
865
865
|
|
866
866
|
const runTest = async (config, expected, { args, verbose, testConfig, debug }) => {
|
867
867
|
const test = expected.query
|
868
|
+
if (args.query && args.query != test) {
|
869
|
+
// no run this
|
870
|
+
return
|
871
|
+
}
|
868
872
|
// initialize in between test so state is not preserved since the test was adding without state
|
869
|
-
config.rebuild()
|
873
|
+
await config.rebuild()
|
870
874
|
const errorHandler = (error) => {
|
871
875
|
if (error.metadata) {
|
872
876
|
const priorities = analyzeMetaData(expected.metadata, error.metadata)
|
@@ -1012,7 +1016,7 @@ const runTests = async (config, testFile, juicyBits) => {
|
|
1012
1016
|
}
|
1013
1017
|
|
1014
1018
|
const saveTest = async (testFile, config, test, expected, testConfig, saveDeveloper) => {
|
1015
|
-
config.rebuild()
|
1019
|
+
await config.rebuild()
|
1016
1020
|
const objects = getObjects(config.config.objects)(config.uuid)
|
1017
1021
|
console.log(test)
|
1018
1022
|
const result = await _process(config, test, { isTest: true })
|
@@ -1033,11 +1037,11 @@ const saveTestsHelper = async (testFile, config, tests, todo, testConfig, saveDe
|
|
1033
1037
|
return
|
1034
1038
|
}
|
1035
1039
|
const test = todo.pop()
|
1036
|
-
config.rebuild()
|
1040
|
+
await config.rebuild()
|
1037
1041
|
const result = await saveTest(testFile, config, test, tests[test], testConfig, saveDeveloper)
|
1038
1042
|
// initialize in between test so state is not preserved since the test was adding without state
|
1039
1043
|
// config.initialize({force: true})
|
1040
|
-
config.rebuild()
|
1044
|
+
await config.rebuild()
|
1041
1045
|
return saveTestsHelper(testFile, config, tests, todo, testConfig, saveDeveloper)
|
1042
1046
|
}
|
1043
1047
|
|
@@ -1356,7 +1360,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1356
1360
|
if (previousResults && previousResults.query == query.query) {
|
1357
1361
|
results = previousResults
|
1358
1362
|
prMessage = ' Using previous results. use -rtf for a hard rebuild of everything on the server side.'
|
1359
|
-
loadInstance(config, { resultss: [results] })
|
1363
|
+
await loadInstance(config, { resultss: [results] })
|
1360
1364
|
} else {
|
1361
1365
|
results = await _process(config, query.query, { initializer, rebuildingTemplate: true })
|
1362
1366
|
}
|
@@ -1582,7 +1586,7 @@ const knowledgeModuleImpl = async ({
|
|
1582
1586
|
parser.add_argument('-t', '--test', { action: 'store_true', help: 'Run the tests. Create tests by running with the --query + --save flag' })
|
1583
1587
|
parser.add_argument('-tv', '--testVerbose', { action: 'store_true', help: 'Run the tests in verbose mode. Create tests by running with the --query or --loop with the --save flag' })
|
1584
1588
|
// parser.add_argument('-ttr', '--testToRun', { help: 'Only the specified test will be run' })
|
1585
|
-
parser.add_argument('-tva', '--testAllVerbose', { action: 'store_true', help: 'Run the tests in verbose mode. All the tests will be run instead of stopping at first failure. Create tests by running with the --query or --loop with the --save flag' })
|
1589
|
+
parser.add_argument('-tva', '--testAllVerbose', { action: 'store_true', help: 'Run the tests in verbose mode. All the tests will be run instead of stopping at first failure. Create tests by running with the --query or --loop with the --save flag. if -q is specified the tests will be run for just the specified query.' })
|
1586
1590
|
parser.add_argument('-tnp', '--testNoParenthesized', { action: 'store_true', help: 'Don\' check parenthesized differences for the tests' })
|
1587
1591
|
parser.add_argument('-n', '--count', { help: 'Number of times to run the tests. Default is one. Use this to check for flakey test. If possible the system will print out a message with the word "hint" suggesting how to fix the problem' })
|
1588
1592
|
// parser.add_argument('-b', '--build', { help: 'Specify the template file name of the form <kmName>. There should be a file called <baseKmName>.<kmName>.template.json with the queries to run. For example { queries: [...] }. The template file will be run and generate an instantiation called <baseKmName>.<kmName>.instance.json and a file called <kmName>.js that will load the template file (this is file generated only if not already existing) and a test file called <KmName>.tests.json. This can then be loaded into an instance of the current knowledge module to setup initial conditions.' })
|
@@ -1628,7 +1632,7 @@ const knowledgeModuleImpl = async ({
|
|
1628
1632
|
global.pauseDebugging = true
|
1629
1633
|
}
|
1630
1634
|
|
1631
|
-
const config = createConfig()
|
1635
|
+
const config = await createConfig()
|
1632
1636
|
setupConfig(config)
|
1633
1637
|
processResults = processResults({ config, errorHandler })
|
1634
1638
|
|
@@ -1663,7 +1667,7 @@ const knowledgeModuleImpl = async ({
|
|
1663
1667
|
throw new Error('Error for the checkForLoop argument. Expected a JSON array of operator keys of the form "[<id>, <level>]"')
|
1664
1668
|
}
|
1665
1669
|
} catch (e) {
|
1666
|
-
throw new Error(
|
1670
|
+
throw new Error('Error for the checkForLoop argument. Expected a JSON array of operator keys of the form "[<id>, <level>]"')
|
1667
1671
|
}
|
1668
1672
|
} else {
|
1669
1673
|
if (process.argv.includes('--checkForLoop') || process.argv.includes('-cl')) {
|
@@ -1860,7 +1864,7 @@ const knowledgeModuleImpl = async ({
|
|
1860
1864
|
config.config.rebuild = true
|
1861
1865
|
}
|
1862
1866
|
try {
|
1863
|
-
config.load(template.template, template.instance, { rebuild: needsRebuild.needsRebuild || options.rebuild, previousResultss: needsRebuild.previousResultss, startOfChanges: needsRebuild.startOfChanges })
|
1867
|
+
await config.load(template.template, template.instance, { rebuild: needsRebuild.needsRebuild || options.rebuild, previousResultss: needsRebuild.previousResultss, startOfChanges: needsRebuild.startOfChanges })
|
1864
1868
|
} catch (e) {
|
1865
1869
|
console.error(`Error loading template for ${config.name}. ${e.error ? e.error : e}${e.stack ? e.stack : ''}`)
|
1866
1870
|
runtime.process.exit(-1)
|
@@ -1994,7 +1998,7 @@ const knowledgeModuleImpl = async ({
|
|
1994
1998
|
lines.setElement(2, 2, JSON.stringify(result.actual.checked, null, 2))
|
1995
1999
|
lines.log()
|
1996
2000
|
if (args.vimdiff) {
|
1997
|
-
|
2001
|
+
show('checked properties for objects', result.expected.checked, result.actual.checked)
|
1998
2002
|
}
|
1999
2003
|
newError = true
|
2000
2004
|
headerShown = true
|
@@ -2012,7 +2016,7 @@ const knowledgeModuleImpl = async ({
|
|
2012
2016
|
lines.setElement(2, 2, JSON.stringify(result.actual.checkedContexts, null, 2))
|
2013
2017
|
lines.log()
|
2014
2018
|
if (args.vimdiff) {
|
2015
|
-
|
2019
|
+
show('checked properties for context', result.expected.checkedContexts, result.actual.checkedContexts)
|
2016
2020
|
}
|
2017
2021
|
newError = true
|
2018
2022
|
headerShown = true
|
@@ -2105,7 +2109,7 @@ const knowledgeModuleImpl = async ({
|
|
2105
2109
|
}
|
2106
2110
|
printConfig()
|
2107
2111
|
} else {
|
2108
|
-
const initConfig = (config) => {
|
2112
|
+
const initConfig = async (config) => {
|
2109
2113
|
if (template) {
|
2110
2114
|
if (config.needsRebuild(template.template, template.instance, { isModule: !isProcess }).needsRebuild) {
|
2111
2115
|
const error = `This module "${config.name}" cannot be used because the instance file needs rebuilding. Run on the command line with no arguments or the -rt argument to rebuild.`
|
@@ -2140,24 +2144,19 @@ const knowledgeModuleImpl = async ({
|
|
2140
2144
|
|
2141
2145
|
if (template) {
|
2142
2146
|
try {
|
2143
|
-
config.load(template.template, template.instance)
|
2147
|
+
await config.load(template.template, template.instance)
|
2144
2148
|
} catch (e) {
|
2145
2149
|
errorHandler(e)
|
2146
2150
|
}
|
2147
2151
|
}
|
2148
2152
|
}
|
2149
2153
|
|
2150
|
-
createConfigExport = (
|
2154
|
+
createConfigExport = async () => {
|
2151
2155
|
if (createConfig.cached) {
|
2152
2156
|
return createConfig.cached
|
2153
2157
|
}
|
2154
|
-
const config = createConfig(
|
2155
|
-
|
2156
|
-
config.stop_auto_rebuild()
|
2157
|
-
additionalConfig(config)
|
2158
|
-
config.restart_auto_rebuild()
|
2159
|
-
}
|
2160
|
-
initConfig(config)
|
2158
|
+
const config = await createConfig()
|
2159
|
+
await initConfig(config)
|
2161
2160
|
// config.rebuild({ isModule: true })
|
2162
2161
|
createConfig.cached = config
|
2163
2162
|
return createConfig.cached
|
package/package.json
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"devDependencies": {
|
3
|
-
"eslint-plugin-import": "^2.23.4",
|
4
|
-
"jest": "^29.7.0",
|
5
|
-
"@typescript-eslint/parser": "^4.28.4",
|
6
3
|
"@typescript-eslint/eslint-plugin": "^4.28.4",
|
7
|
-
"eslint
|
4
|
+
"@typescript-eslint/parser": "^4.28.4",
|
5
|
+
"eslint": "^7.31.0",
|
8
6
|
"eslint-config-standard": "^16.0.3",
|
7
|
+
"eslint-plugin-import": "^2.23.4",
|
8
|
+
"eslint-plugin-node": "^11.1.0",
|
9
9
|
"eslint-plugin-promise": "^5.1.0",
|
10
|
-
"
|
10
|
+
"jest": "^29.7.0"
|
11
11
|
},
|
12
12
|
"scripts": {
|
13
13
|
"to:debug": "node inspect node_modules/.bin/jest --runInBand -t NEO23",
|
@@ -52,19 +52,18 @@
|
|
52
52
|
],
|
53
53
|
"author": "dev@thinktelligence.com",
|
54
54
|
"dependencies": {
|
55
|
+
"base-64": "^1.0.0",
|
55
56
|
"deep-equal": "^2.0.4",
|
56
|
-
"
|
57
|
+
"fs": "0.0.1-security",
|
57
58
|
"json-diff": "^1.0.3",
|
59
|
+
"json-stable-stringify": "^1.0.1",
|
58
60
|
"lodash": "^4.17.20",
|
59
|
-
"
|
60
|
-
"base-64": "^1.0.0",
|
61
|
-
"sort-json": "^2.0.0",
|
61
|
+
"node-fetch": "^2.6.1",
|
62
62
|
"readline": "^1.3.0",
|
63
63
|
"scriptjs": "^2.5.9",
|
64
|
-
"
|
65
|
-
"
|
66
|
-
"node-fetch": "^2.6.1"
|
64
|
+
"sort-json": "^2.0.0",
|
65
|
+
"uuid": "^8.3.2"
|
67
66
|
},
|
68
|
-
"version": "8.0.0-beta.
|
67
|
+
"version": "8.0.0-beta.21",
|
69
68
|
"license": "UNLICENSED"
|
70
69
|
}
|
package/src/config.js
CHANGED
@@ -262,7 +262,12 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
262
262
|
}
|
263
263
|
if (bridge.children) {
|
264
264
|
for (const child of bridge.children) {
|
265
|
-
config.addHierarchy(child, bridge.id)
|
265
|
+
// config.addHierarchy(child, bridge.id)
|
266
|
+
if (child.child) {
|
267
|
+
config.addHierarchy(child.child, bridge.id, child.instance)
|
268
|
+
} else {
|
269
|
+
config.addHierarchy(child, bridge.id)
|
270
|
+
}
|
266
271
|
}
|
267
272
|
}
|
268
273
|
if (bridge.operator) {
|
@@ -270,12 +275,20 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
270
275
|
}
|
271
276
|
if (bridge.parents) {
|
272
277
|
for (const parent of bridge.parents) {
|
273
|
-
|
278
|
+
if (parent.parent) {
|
279
|
+
config.addHierarchy(bridge.id, parent.parent, parent.instance)
|
280
|
+
} else {
|
281
|
+
config.addHierarchy(bridge.id, parent)
|
282
|
+
}
|
274
283
|
}
|
275
284
|
}
|
276
285
|
if (bridge.isA) {
|
277
286
|
for (const parent of bridge.isA) {
|
278
|
-
|
287
|
+
if (parent.parent) {
|
288
|
+
config.addHierarchy(bridge.id, parent.parent, parent.instance)
|
289
|
+
} else {
|
290
|
+
config.addHierarchy(bridge.id, parent)
|
291
|
+
}
|
279
292
|
}
|
280
293
|
}
|
281
294
|
if (bridge.before) {
|
@@ -551,7 +564,7 @@ function isLetter (char) {
|
|
551
564
|
}
|
552
565
|
*/
|
553
566
|
|
554
|
-
function configDup (config, options) {
|
567
|
+
async function configDup (config, options) {
|
555
568
|
if (config instanceof Config) {
|
556
569
|
return config.copy(options)
|
557
570
|
}
|
@@ -691,9 +704,9 @@ class KM {
|
|
691
704
|
return true
|
692
705
|
}
|
693
706
|
|
694
|
-
copy2 (options) {
|
707
|
+
async copy2 (options) {
|
695
708
|
// greg -> add a flag to say don't init the api's
|
696
|
-
const config = configDup(this._config, options)
|
709
|
+
const config = await configDup(this._config, options)
|
697
710
|
const km = new KM({
|
698
711
|
config,
|
699
712
|
getCounter: options.getCounter,
|
@@ -705,10 +718,10 @@ class KM {
|
|
705
718
|
return km // copy2()
|
706
719
|
}
|
707
720
|
|
708
|
-
copy () {
|
721
|
+
async copy () {
|
709
722
|
const km = new KM({
|
710
723
|
name: this._name,
|
711
|
-
config: configDup(this._config),
|
724
|
+
config: await configDup(this._config),
|
712
725
|
// _uuid: uuidv4(),
|
713
726
|
_uuid: this._config.getCounter(this._config._name),
|
714
727
|
getCounter: (name) => this._config.getCounter(name),
|
@@ -760,7 +773,7 @@ const multiApiImpl = (initializer) => {
|
|
760
773
|
multiApi: true,
|
761
774
|
|
762
775
|
// multi functions
|
763
|
-
add: (config, multiApi, api) => {
|
776
|
+
add: async (config, multiApi, api) => {
|
764
777
|
initializer(config, api)
|
765
778
|
const name = api.getName()
|
766
779
|
multiApi.apis[name] = api
|
@@ -798,17 +811,6 @@ class Config {
|
|
798
811
|
return config_toServer(config)
|
799
812
|
}
|
800
813
|
|
801
|
-
base () {
|
802
|
-
const base = new Config()
|
803
|
-
for (const km of this.configs.reverse()) {
|
804
|
-
if (km.isSelf) {
|
805
|
-
continue
|
806
|
-
}
|
807
|
-
base.add(km.config)
|
808
|
-
}
|
809
|
-
return base
|
810
|
-
}
|
811
|
-
|
812
814
|
getInfo () {
|
813
815
|
const name = this.name
|
814
816
|
const includes = this.configs.slice(1).map((km) => km.config.name)
|
@@ -1197,7 +1199,9 @@ class Config {
|
|
1197
1199
|
// console.log("instanceFragments", instanceFragments)
|
1198
1200
|
}
|
1199
1201
|
}
|
1200
|
-
if (startOfChanges
|
1202
|
+
if (startOfChanges) {
|
1203
|
+
return { needsRebuild: true, startOfChanges, previousResultss: instance.resultss }
|
1204
|
+
} else if (startOfChanges || instance.resultss) {
|
1201
1205
|
return { needsRebuild: !(instance && sameQueries && sameFragments), startOfChanges, previousResultss: instance.resultss }
|
1202
1206
|
} else {
|
1203
1207
|
return { needsRebuild: !(instance && sameQueries && sameFragments) }
|
@@ -1222,7 +1226,7 @@ class Config {
|
|
1222
1226
|
}
|
1223
1227
|
|
1224
1228
|
// loadTemplate
|
1225
|
-
load (template, instance, options = { rebuild: false, previousResultss: undefined, startOfChanges: undefined }) {
|
1229
|
+
async load (template, instance, options = { rebuild: false, previousResultss: undefined, startOfChanges: undefined }) {
|
1226
1230
|
this.validifyTemplate(template)
|
1227
1231
|
instance.template = template
|
1228
1232
|
this.logs.push(`loading template for ${this.name}`)
|
@@ -1255,7 +1259,7 @@ class Config {
|
|
1255
1259
|
instance.name = this.name
|
1256
1260
|
this.initInstances.push(instance)
|
1257
1261
|
this.instances.push(instance)
|
1258
|
-
client.loadInstance(this, instance)
|
1262
|
+
await client.loadInstance(this, instance)
|
1259
1263
|
}
|
1260
1264
|
}
|
1261
1265
|
}
|
@@ -1309,9 +1313,9 @@ class Config {
|
|
1309
1313
|
}
|
1310
1314
|
}
|
1311
1315
|
|
1312
|
-
addHierarchy (child, parent) {
|
1316
|
+
addHierarchy (child, parent, instance) {
|
1313
1317
|
if (child && parent || !child || Array.isArray(child) || (typeof child === 'string' && !parent)) {
|
1314
|
-
this.addHierarchyChildParent(child, parent)
|
1318
|
+
this.addHierarchyChildParent(child, parent, instance)
|
1315
1319
|
// this.addHierarchyProperties ({ child, parent })
|
1316
1320
|
} else {
|
1317
1321
|
this.addHierarchyProperties(child)
|
@@ -1319,26 +1323,32 @@ class Config {
|
|
1319
1323
|
}
|
1320
1324
|
|
1321
1325
|
addHierarchyProperties (edge) {
|
1322
|
-
const { child, parent } = edge
|
1326
|
+
const { child, parent, instance } = edge
|
1323
1327
|
if (typeof child !== 'string') {
|
1324
1328
|
throw new Error(`addHierarchy expected child property to be a string. got ${JSON.stringify(child)}`)
|
1325
1329
|
}
|
1326
1330
|
if (typeof parent !== 'string') {
|
1327
1331
|
throw new Error(`addHierarchy expected parent property to be a string. got ${JSON.stringify(parent)}`)
|
1328
1332
|
}
|
1333
|
+
if (instance && typeof instance !== 'boolean') {
|
1334
|
+
throw new Error(`addHierarchy expected instance property to be a boolean or undefined. got ${JSON.stringify(instance)}`)
|
1335
|
+
}
|
1329
1336
|
debugHierarchy([child, parent])
|
1330
1337
|
this.config.hierarchy.push(edge)
|
1331
1338
|
// TODO greg11 this.hierarchy.addEdge(edge)
|
1332
|
-
this._delta.json.hierarchy.push([child, parent])
|
1339
|
+
this._delta.json.hierarchy.push([child, parent, instance || false])
|
1333
1340
|
}
|
1334
1341
|
|
1335
|
-
addHierarchyChildParent (child, parent) {
|
1342
|
+
addHierarchyChildParent (child, parent, instance) {
|
1336
1343
|
if (typeof child !== 'string') {
|
1337
1344
|
throw new Error(`addHierarchy expected child to be a string. got ${JSON.stringify(child)}`)
|
1338
1345
|
}
|
1339
1346
|
if (typeof parent !== 'string') {
|
1340
1347
|
throw new Error(`addHierarchy expected parent to be a string. got ${JSON.stringify(parent)}`)
|
1341
1348
|
}
|
1349
|
+
if (instance && typeof instance !== 'boolean') {
|
1350
|
+
throw new Error(`addHierarchy expected instance property to be a boolean or undefined. got ${JSON.stringify(instance)}`)
|
1351
|
+
}
|
1342
1352
|
debugHierarchy([child, parent])
|
1343
1353
|
if (this.config.hierarchy.find((element) => {
|
1344
1354
|
const hc = hierarchyCanonical(element)
|
@@ -1349,9 +1359,9 @@ class Config {
|
|
1349
1359
|
return
|
1350
1360
|
}
|
1351
1361
|
|
1352
|
-
this.config.hierarchy.push([child, parent])
|
1362
|
+
this.config.hierarchy.push([child, parent, instance || false])
|
1353
1363
|
// this.hierarchy.addEdge([child, parent])
|
1354
|
-
this._delta.json.hierarchy.push([child, parent])
|
1364
|
+
this._delta.json.hierarchy.push([child, parent, instance || false])
|
1355
1365
|
}
|
1356
1366
|
|
1357
1367
|
getBridge (id, level) {
|
@@ -1608,10 +1618,6 @@ class Config {
|
|
1608
1618
|
return params
|
1609
1619
|
}
|
1610
1620
|
|
1611
|
-
processContexts (contexts, params) {
|
1612
|
-
client.processContexts(contexts, this.getParams())
|
1613
|
-
}
|
1614
|
-
|
1615
1621
|
processContext (context) {
|
1616
1622
|
return client.processContext(context, this.getParams())
|
1617
1623
|
}
|
@@ -1620,6 +1626,10 @@ class Config {
|
|
1620
1626
|
return client.process(this, query, options)
|
1621
1627
|
}
|
1622
1628
|
|
1629
|
+
query (query, options) {
|
1630
|
+
return this.process(query, options)
|
1631
|
+
}
|
1632
|
+
|
1623
1633
|
processQuery (query, options) {
|
1624
1634
|
return this.process(query, options)
|
1625
1635
|
}
|
@@ -1797,24 +1807,6 @@ class Config {
|
|
1797
1807
|
// when running configs any bridges added are marked as transitory so that the associated will ignore those op's
|
1798
1808
|
this.transitoryMode = false
|
1799
1809
|
|
1800
|
-
// check for duplicate bridges
|
1801
|
-
if (config && config.bridges) {
|
1802
|
-
let duplicated = new Set()
|
1803
|
-
const seen = new Set()
|
1804
|
-
for (const bridge of config.bridges) {
|
1805
|
-
const id = `${bridge.id}/${bridge.level}`
|
1806
|
-
if (seen.has(id)) {
|
1807
|
-
duplicated.add(id)
|
1808
|
-
} else {
|
1809
|
-
seen.add(id)
|
1810
|
-
}
|
1811
|
-
}
|
1812
|
-
duplicated = Array.from(duplicated)
|
1813
|
-
if (duplicated.length > 0) {
|
1814
|
-
throw new Error(`In the KM ${config.name}, the following operators are duplicated in the bridges: ${duplicated}`)
|
1815
|
-
}
|
1816
|
-
}
|
1817
|
-
|
1818
1810
|
if (config && config.words) {
|
1819
1811
|
initWords(config.words)
|
1820
1812
|
isValidWordDef(config.words)
|
@@ -1863,6 +1855,7 @@ class Config {
|
|
1863
1855
|
}
|
1864
1856
|
this.get('objects').namespaced[this._uuid] = {}
|
1865
1857
|
this.valid()
|
1858
|
+
this.checks()
|
1866
1859
|
debugConfigProps(this.config)
|
1867
1860
|
}
|
1868
1861
|
|
@@ -1874,9 +1867,9 @@ class Config {
|
|
1874
1867
|
this._stop_auto_rebuild = true
|
1875
1868
|
}
|
1876
1869
|
|
1877
|
-
restart_auto_rebuild() {
|
1870
|
+
async restart_auto_rebuild() {
|
1878
1871
|
this._stop_auto_rebuild = false
|
1879
|
-
this.rebuild()
|
1872
|
+
await this.rebuild()
|
1880
1873
|
}
|
1881
1874
|
|
1882
1875
|
getAddedArgs (args) {
|
@@ -1895,8 +1888,8 @@ class Config {
|
|
1895
1888
|
}
|
1896
1889
|
}
|
1897
1890
|
|
1898
|
-
|
1899
|
-
this.
|
1891
|
+
async setMultiApi (initializer) {
|
1892
|
+
await this.setApi(multiApiImpl(initializer))
|
1900
1893
|
}
|
1901
1894
|
|
1902
1895
|
get multiApi () {
|
@@ -1944,31 +1937,26 @@ class Config {
|
|
1944
1937
|
}
|
1945
1938
|
}
|
1946
1939
|
|
1947
|
-
addAPI (api) {
|
1940
|
+
async addAPI (api) {
|
1941
|
+
// console.trace()
|
1942
|
+
// throw "addAPI"
|
1948
1943
|
if (this._api && this._api.multiApi) {
|
1949
|
-
this._api.add(this, this._api, api)
|
1944
|
+
await this._api.add(this, this._api, api)
|
1950
1945
|
} else {
|
1951
1946
|
throw new Error('Can only add apis to a multi-api')
|
1952
1947
|
}
|
1953
1948
|
}
|
1954
1949
|
|
1955
|
-
|
1950
|
+
async setApi (value) {
|
1956
1951
|
if (!value.initialize) {
|
1957
1952
|
throw new Error(`Expected the API to have an initialize function for ${this.name}.`)
|
1958
1953
|
}
|
1959
1954
|
|
1960
1955
|
if (this._api && this._api.multiApi) {
|
1961
|
-
this._api.add(this, this._api, value)
|
1956
|
+
await this._api.add(this, this._api, value)
|
1962
1957
|
} else {
|
1963
1958
|
this._api = _.cloneDeep(value)
|
1964
|
-
|
1965
|
-
if (this._api) {
|
1966
|
-
// this._api.objects = this.config.objects
|
1967
|
-
// this._api.config = () => this
|
1968
|
-
// this._api.uuid = this._uuid
|
1969
|
-
}
|
1970
|
-
*/
|
1971
|
-
this.rebuild()
|
1959
|
+
await this.rebuild()
|
1972
1960
|
}
|
1973
1961
|
}
|
1974
1962
|
|
@@ -1988,7 +1976,7 @@ class Config {
|
|
1988
1976
|
}
|
1989
1977
|
|
1990
1978
|
// remove all added modules and initialize with the init config
|
1991
|
-
resetToOne () {
|
1979
|
+
async resetToOne () {
|
1992
1980
|
/*
|
1993
1981
|
this.config = _.cloneDeep(this.initConfig)
|
1994
1982
|
this.configs = [this.configs[0]]
|
@@ -1997,11 +1985,8 @@ class Config {
|
|
1997
1985
|
*/
|
1998
1986
|
this.configs = [this.configs[0]]
|
1999
1987
|
this.defaultConfig()
|
2000
|
-
|
2001
|
-
|
2002
|
-
Object.assign(this.config.objects, _.cloneDeep(this.initConfig.objects || {}))
|
2003
|
-
}
|
2004
|
-
this.initializeConfigFromConfigs({ others: [], objects: this.config.objects.namespaced, moreNames: [], callInitializers: false })
|
1988
|
+
Object.assign(this.config.objects, _.cloneDeep(this.initConfig.objects || {}))
|
1989
|
+
await this.initializeConfigFromConfigs({ others: [], objects: this.config.objects.namespaced, moreNames: [], callInitializers: false })
|
2005
1990
|
const map = {}
|
2006
1991
|
for (let i = 0; i < this.configs.length; ++i) {
|
2007
1992
|
map[this.configs[i].uuid] = this.configs[i].uuid
|
@@ -2023,17 +2008,18 @@ class Config {
|
|
2023
2008
|
runtime.fs.writeFileSync(fn, JSON.stringify(this.config, 0, 2))
|
2024
2009
|
}
|
2025
2010
|
|
2026
|
-
copy (options = { callInitializers: true }) {
|
2027
|
-
}
|
2028
|
-
|
2029
|
-
copy (options = { callInitializers: true }) {
|
2011
|
+
async copy (options = { callInitializers: true }) {
|
2030
2012
|
this.valid()
|
2031
2013
|
const cp = new Config()
|
2032
2014
|
cp.logs = []
|
2033
2015
|
cp.maxDepth = this.maxDepth
|
2034
2016
|
cp.debugLoops = this.debugLoops
|
2035
2017
|
cp.transitoryMode = this.transitoryMode
|
2036
|
-
cp.configs = this.configs.map((km) => km.copy2(Object.assign({}, options, { getCounter: (name) => cp.getCounter(name), callInitializers: false })))
|
2018
|
+
// cp.configs = this.configs.map((km) => await km.copy2(Object.assign({}, options, { getCounter: (name) => cp.getCounter(name), callInitializers: false })))
|
2019
|
+
cp.configs = []
|
2020
|
+
for (const km of this.configs) {
|
2021
|
+
cp.configs.push(await km.copy2(Object.assign({}, options, { getCounter: (name) => cp.getCounter(name), callInitializers: false })))
|
2022
|
+
}
|
2037
2023
|
cp._uuid = cp.configs[0]._uuid
|
2038
2024
|
// update uuid here set the uuid in the objects and add error checking
|
2039
2025
|
cp.initializerFn = this.initializerFn
|
@@ -2054,13 +2040,8 @@ class Config {
|
|
2054
2040
|
cp.defaultConfig()
|
2055
2041
|
// cp.wasInitialized = false; // since default config GREG
|
2056
2042
|
cp.resetWasInitialized()
|
2057
|
-
|
2058
|
-
|
2059
|
-
Object.assign(cp.config.objects, _.cloneDeep(this.initConfig.objects || {}))
|
2060
|
-
}
|
2061
|
-
// cp.initializeConfigFromConfigs({ others: [], objects: cp.config.objects.namespaced, moreNames: [], ...options })
|
2062
|
-
// cp.initializeConfigFromConfigs(Object.assign({ others: [], objects: cp.config.objects.namespaced, moreNames: [] }, { callInitializers: false }))
|
2063
|
-
cp.initializeConfigFromConfigs(Object.assign({ others: [], objects: cp.config.objects.namespaced, moreNames: [] }, options))
|
2043
|
+
Object.assign(cp.config.objects, _.cloneDeep(this.initConfig.objects || {}))
|
2044
|
+
await cp.initializeConfigFromConfigs(Object.assign({ others: [], objects: cp.config.objects.namespaced, moreNames: [] }, options))
|
2064
2045
|
const map = {}
|
2065
2046
|
for (let i = 0; i < this.configs.length; ++i) {
|
2066
2047
|
map[this.configs[i].uuid] = cp.configs[i].uuid
|
@@ -2071,33 +2052,16 @@ class Config {
|
|
2071
2052
|
// debugger
|
2072
2053
|
}
|
2073
2054
|
if (options.callInitializers) {
|
2074
|
-
cp.rebuild(options)
|
2055
|
+
await cp.rebuild(options) // in copy
|
2075
2056
|
} else {
|
2076
|
-
// this mess is for duplicate into a KM after resetToOne was called
|
2077
|
-
/*
|
2078
|
-
if (cp._api) {
|
2079
|
-
// cp._api.objects = cp.config.objects
|
2080
|
-
// cp._api.config = () => (cp instanceof Config) ? cp : cp.config
|
2081
|
-
// cp._api.uuid = cp._uuid
|
2082
|
-
}
|
2083
|
-
*/
|
2084
|
-
|
2085
2057
|
if (!cp.config.objects) {
|
2086
2058
|
cp.config.objects = { namespaced: {} }
|
2087
2059
|
} else if (!cp.config.objects.namespaced) {
|
2088
2060
|
cp.config.objects.namespaced = {}
|
2089
2061
|
}
|
2090
2062
|
cp.configs.forEach((km) => {
|
2091
|
-
// const namespace = km.namespace
|
2092
2063
|
cp.config.objects.namespaced[km._uuid] = {}
|
2093
2064
|
})
|
2094
|
-
/*
|
2095
|
-
if (cp._uuid == 'concept2') {
|
2096
|
-
if (!cp.api.objects.defaultTypesForHierarchy) {
|
2097
|
-
debugger
|
2098
|
-
}
|
2099
|
-
}
|
2100
|
-
*/
|
2101
2065
|
}
|
2102
2066
|
cp.valid()
|
2103
2067
|
return cp
|
@@ -2221,41 +2185,7 @@ class Config {
|
|
2221
2185
|
}
|
2222
2186
|
}
|
2223
2187
|
|
2224
|
-
|
2225
|
-
// [...this.configs].reverse().forEach(({ config, namespace, uuid }) => {
|
2226
|
-
[...this.configs].reverse().forEach(({ config, namespace, uuid }) => {
|
2227
|
-
/*
|
2228
|
-
let objects = this.get('objects')
|
2229
|
-
if (namespace) {
|
2230
|
-
objects = {}
|
2231
|
-
this.get('objects')['namespaced'][namespace] = objects
|
2232
|
-
}
|
2233
|
-
*/
|
2234
|
-
const objects = {}
|
2235
|
-
if (config instanceof Config) {
|
2236
|
-
this.get('objects').namespaced[config._uuid] = objects
|
2237
|
-
/*
|
2238
|
-
if (config._api) {
|
2239
|
-
// config._api.objects = objects
|
2240
|
-
// config._api.config = () => this
|
2241
|
-
}
|
2242
|
-
*/
|
2243
|
-
config.initializerFn(setupInitializerFNArgs(this, { testConfig: config, currentConfig: config, objects, namespace, uuid }))
|
2244
|
-
} else {
|
2245
|
-
this.get('objects').namespaced[this._uuid] = objects
|
2246
|
-
/*
|
2247
|
-
if (config._api) {
|
2248
|
-
// config._api.objects = objects
|
2249
|
-
// config._api.config = () => this
|
2250
|
-
}
|
2251
|
-
*/
|
2252
|
-
this.initializerFn(setupInitializerFNArgs(this, { testConfig: this, currentConfig: this, objects, namespace, uuid }))
|
2253
|
-
}
|
2254
|
-
})
|
2255
|
-
this.instances.forEach((instance) => client.loadInstance(this, instance))
|
2256
|
-
}
|
2257
|
-
|
2258
|
-
initialize ({ force = true } = {}) {
|
2188
|
+
initialize23 ({ force = true } = {}) {
|
2259
2189
|
if (force || !this.wasInitialized) {
|
2260
2190
|
const objects = this.config.objects.namespaced[this._uuid]
|
2261
2191
|
this.initializerFn(setupInitializerFNArgs(this, { testConfig: this, currentConfig: this, objects, uuid: this._uuid, namespace: '' }))
|
@@ -2263,7 +2193,7 @@ class Config {
|
|
2263
2193
|
}
|
2264
2194
|
}
|
2265
2195
|
|
2266
|
-
initializer (fn, options = {}) {
|
2196
|
+
async initializer (fn, options = {}) {
|
2267
2197
|
if (options) {
|
2268
2198
|
for (const option of Object.keys(options)) {
|
2269
2199
|
const validOptions = []
|
@@ -2285,8 +2215,7 @@ class Config {
|
|
2285
2215
|
currentConfig.wasInitialized = true
|
2286
2216
|
global.transitoryMode = transitoryMode
|
2287
2217
|
}
|
2288
|
-
|
2289
|
-
this.rebuild()
|
2218
|
+
await this.rebuild()
|
2290
2219
|
}
|
2291
2220
|
|
2292
2221
|
nsToString (id) {
|
@@ -2432,7 +2361,7 @@ class Config {
|
|
2432
2361
|
}
|
2433
2362
|
|
2434
2363
|
// rebuild ({ isModule: mainIsModule = false } = {}) {
|
2435
|
-
rebuild ({ isModule: mainIsModule } = {}) {
|
2364
|
+
async rebuild ({ isModule: mainIsModule } = {}) {
|
2436
2365
|
if (this._stop_auto_rebuild) {
|
2437
2366
|
return
|
2438
2367
|
}
|
@@ -2600,7 +2529,7 @@ class Config {
|
|
2600
2529
|
}
|
2601
2530
|
const instance = this.instances.find((instance) => instance.name == name)
|
2602
2531
|
if (instance) {
|
2603
|
-
client.loadInstance(this, instance)
|
2532
|
+
await client.loadInstance(this, instance)
|
2604
2533
|
}
|
2605
2534
|
this.hierarchy.edges = this.config.hierarchy
|
2606
2535
|
}
|
@@ -2608,7 +2537,7 @@ class Config {
|
|
2608
2537
|
|
2609
2538
|
this.hierarchy.edges = this.config.hierarchy
|
2610
2539
|
this.valid()
|
2611
|
-
this.
|
2540
|
+
this.checks()
|
2612
2541
|
}
|
2613
2542
|
|
2614
2543
|
nameToUUID (name) {
|
@@ -2620,6 +2549,7 @@ class Config {
|
|
2620
2549
|
// if undefined namespace applies to first loaded config
|
2621
2550
|
// if list of name then namespace applied only to those configs
|
2622
2551
|
// if true then namespace applies to all loaded configs
|
2552
|
+
/*
|
2623
2553
|
namespace (moreNames, others) {
|
2624
2554
|
const config = this.copy()
|
2625
2555
|
if (!Array.isArray(moreNames)) {
|
@@ -2655,6 +2585,7 @@ class Config {
|
|
2655
2585
|
config.rebuild()
|
2656
2586
|
return config
|
2657
2587
|
}
|
2588
|
+
*/
|
2658
2589
|
|
2659
2590
|
setupNamespace (km) {
|
2660
2591
|
let config = km.config
|
@@ -2673,7 +2604,7 @@ class Config {
|
|
2673
2604
|
|
2674
2605
|
// config.initializerFn({ config: this, objects, namespace })
|
2675
2606
|
// this goes through all the configs and sets up this.config
|
2676
|
-
initializeConfigFromConfigs ({ others, objects, moreNames, callInitializers = true }) {
|
2607
|
+
async initializeConfigFromConfigs ({ others, objects, moreNames, callInitializers = true }) {
|
2677
2608
|
// setup the namespace in the configs
|
2678
2609
|
let first = true
|
2679
2610
|
this.configs.forEach((km) => {
|
@@ -2822,6 +2753,11 @@ class Config {
|
|
2822
2753
|
}
|
2823
2754
|
}
|
2824
2755
|
|
2756
|
+
checks () {
|
2757
|
+
this.checkOperators()
|
2758
|
+
this.checkBridges()
|
2759
|
+
}
|
2760
|
+
|
2825
2761
|
checkOperators () {
|
2826
2762
|
if (!this.config.operators) {
|
2827
2763
|
return
|
@@ -2842,53 +2778,19 @@ class Config {
|
|
2842
2778
|
return
|
2843
2779
|
}
|
2844
2780
|
|
2845
|
-
|
2846
|
-
|
2847
|
-
"634a678b-8d92-4464-bf65-943a82f404d8": {
|
2848
|
-
"ids": [ "tankConcept" ],
|
2849
|
-
"namespace": [ "ns1" ]
|
2850
|
-
},
|
2851
|
-
console.log('before check', JSON.stringify(this._eqClasses, null, 2))
|
2852
|
-
*/
|
2853
|
-
|
2854
|
-
const errors = []
|
2855
|
-
/*
|
2856
|
-
const namespaces = this.config.namespaces
|
2857
|
-
const nsToIds = {}
|
2858
|
-
for (const uuid in namespaces) {
|
2859
|
-
const namespace = namespaces[uuid].namespace
|
2860
|
-
const ns = namespace.join('#')
|
2861
|
-
if (!nsToIds[ns]) {
|
2862
|
-
nsToIds[ns] = new Set()
|
2863
|
-
}
|
2864
|
-
const ids = nsToIds[ns]
|
2865
|
-
for (const id of namespaces[uuid].ids) {
|
2866
|
-
if (ids.has(id)) {
|
2867
|
-
if (ns === '') {
|
2868
|
-
const dups = this.config.bridges.filter( (bridge) => bridge.id == id )
|
2869
|
-
errors.push(`Id '${id}' is defined more than once in the bridges of the base namespace of the KM ${this.name}, Dups are ${JSON.stringify(dups)}`)
|
2870
|
-
} else {
|
2871
|
-
errors.push(`Id '${id}' is defined more than once in the bridges of the ${ns} namespace of the KM ${this.name}`)
|
2872
|
-
}
|
2873
|
-
} else {
|
2874
|
-
ids.add(id)
|
2875
|
-
}
|
2876
|
-
}
|
2877
|
-
}
|
2878
|
-
*/
|
2879
|
-
|
2880
|
-
const keyIsPresent = {}
|
2781
|
+
let duplicated = new Set()
|
2782
|
+
const seen = new Set()
|
2881
2783
|
for (const bridge of this.config.bridges) {
|
2882
|
-
const
|
2883
|
-
if (
|
2884
|
-
|
2784
|
+
const id = `${bridge.id}/${bridge.level} (namespace: ${bridge.uuid || this.uuid})`
|
2785
|
+
if (seen.has(id)) {
|
2786
|
+
duplicated.add(id)
|
2885
2787
|
} else {
|
2886
|
-
|
2788
|
+
seen.add(id)
|
2887
2789
|
}
|
2888
2790
|
}
|
2889
|
-
|
2890
|
-
if (
|
2891
|
-
throw
|
2791
|
+
duplicated = Array.from(duplicated)
|
2792
|
+
if (duplicated.length > 0) {
|
2793
|
+
throw new Error(`In the KM ${this.name}, the following operators are duplicated in the bridges: ${duplicated}`)
|
2892
2794
|
}
|
2893
2795
|
};
|
2894
2796
|
|
@@ -2945,25 +2847,29 @@ class Config {
|
|
2945
2847
|
}
|
2946
2848
|
}
|
2947
2849
|
|
2948
|
-
add (...
|
2949
|
-
|
2950
|
-
if (
|
2951
|
-
throw new Error(
|
2850
|
+
async add (...createConfigs) {
|
2851
|
+
createConfigs.forEach((createConfig, index) => {
|
2852
|
+
if (typeof createConfig !== 'function') {
|
2853
|
+
throw new Error(`Expected add argument number ${index+1} to be a function that constructs the config.`)
|
2952
2854
|
}
|
2953
2855
|
})
|
2954
2856
|
|
2955
|
-
mores =
|
2956
|
-
|
2957
|
-
|
2857
|
+
const mores = []
|
2858
|
+
for (const createConfig of createConfigs) {
|
2859
|
+
const more = await createConfig()
|
2860
|
+
if (mores.find( (km) => km.name == more.name)) {
|
2861
|
+
throw new Error(`Expected add argument number ${index+1} to be a function that constructs the config.`)
|
2958
2862
|
}
|
2959
|
-
|
2960
|
-
|
2961
|
-
|
2962
|
-
|
2863
|
+
if (this === more) {
|
2864
|
+
throw new Error('Cannot add an object to itself.')
|
2865
|
+
}
|
2866
|
+
mores.push(more)
|
2867
|
+
}
|
2868
|
+
for (let more of mores) {
|
2963
2869
|
this.valid()
|
2964
2870
|
more.valid()
|
2965
2871
|
// copy so i don't have to copy later
|
2966
|
-
more = more.copy()
|
2872
|
+
more = await more.copy()
|
2967
2873
|
more.server(this._server, this._key, this._queryParams)
|
2968
2874
|
|
2969
2875
|
const moreConfigs = more.configs.map((km) => km.name || km.uuid)
|
@@ -2978,9 +2884,6 @@ class Config {
|
|
2978
2884
|
const moreKMs1 = [new KM({ config: more, getCounter: (name) => this.getCounter(name), uuid: more.uuid, namespace })]
|
2979
2885
|
const moreKMs2 = more.configs.slice(1).map((km) => {
|
2980
2886
|
return km
|
2981
|
-
// const cp = km.copy()
|
2982
|
-
// cp.namespace = namespace
|
2983
|
-
// return cp;
|
2984
2887
|
})
|
2985
2888
|
const moreKMs = moreKMs1.concat(moreKMs2)
|
2986
2889
|
const eqClass = moreKMs.map((km) => km.uuid)
|
@@ -2994,7 +2897,7 @@ class Config {
|
|
2994
2897
|
this.configs.push(moreKM)
|
2995
2898
|
}
|
2996
2899
|
}
|
2997
|
-
more.resetToOne()
|
2900
|
+
await more.resetToOne()
|
2998
2901
|
this.config.eqClasses = this._eqClasses
|
2999
2902
|
// greg
|
3000
2903
|
// setup instances
|
@@ -3009,8 +2912,8 @@ class Config {
|
|
3009
2912
|
}
|
3010
2913
|
}
|
3011
2914
|
this.instances = noDups
|
3012
|
-
}
|
3013
|
-
this.rebuild()
|
2915
|
+
}
|
2916
|
+
await this.rebuild() // in add(
|
3014
2917
|
this.valid()
|
3015
2918
|
return this
|
3016
2919
|
}
|
@@ -3166,7 +3069,7 @@ class Config {
|
|
3166
3069
|
// assumes this is called in reverse order
|
3167
3070
|
addInternalR (more, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false) {
|
3168
3071
|
if (more instanceof Config) {
|
3169
|
-
more.
|
3072
|
+
more.initialize23({ force: false })
|
3170
3073
|
if (useOldVersion) {
|
3171
3074
|
more = more.config
|
3172
3075
|
} else {
|
package/src/semantics.js
CHANGED
@@ -312,9 +312,9 @@ class Semantics {
|
|
312
312
|
|
313
313
|
applyToContexts (args, contexts, options) {
|
314
314
|
const contextsPrime = []
|
315
|
-
|
315
|
+
for (const context of contexts) {
|
316
316
|
contextsPrime.push(this.applyToContext(args, context, options))
|
317
|
-
}
|
317
|
+
}
|
318
318
|
return contextsPrime
|
319
319
|
}
|
320
320
|
|