theprogrammablemind 8.0.0-beta.4 → 8.0.0-beta.41
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 +43 -42
- package/package.json +12 -13
- package/src/config.js +120 -217
- package/src/generators.js +8 -8
- package/src/semantics.js +15 -15
package/client.js
CHANGED
@@ -237,9 +237,8 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
|
|
237
237
|
config.setArgs(args)
|
238
238
|
}
|
239
239
|
|
240
|
-
const gs = (g) => (contexts, separator, lastSeparator) => {
|
240
|
+
const gs = (g) => async (contexts, separator, lastSeparator) => {
|
241
241
|
if (!Array.isArray(contexts)) {
|
242
|
-
debugger
|
243
242
|
throw new Error('Expected a list')
|
244
243
|
}
|
245
244
|
|
@@ -253,7 +252,7 @@ const gs = (g) => (contexts, separator, lastSeparator) => {
|
|
253
252
|
let nextSeparator = ''
|
254
253
|
for (let i = 0; i < contexts.length; ++i) {
|
255
254
|
const context = contexts[i]
|
256
|
-
const value = g(context)
|
255
|
+
const value = await g(context)
|
257
256
|
if (i > 0) {
|
258
257
|
if (i === contexts.length - 1) {
|
259
258
|
nextSeparator = lastSeparator
|
@@ -290,12 +289,12 @@ const analyzeMetaData = (right, wrong) => {
|
|
290
289
|
return []
|
291
290
|
}
|
292
291
|
|
293
|
-
const processContexts = (contexts, params) => {
|
292
|
+
const processContexts = async (contexts, params) => {
|
294
293
|
const contextsPrime = []
|
295
294
|
const generated = []
|
296
295
|
const logs = []
|
297
296
|
for (const context of contexts) {
|
298
|
-
const result = processContext(context, Object.assign({}, params, { logs }))
|
297
|
+
const result = await processContext(context, Object.assign({}, params, { logs }))
|
299
298
|
contextsPrime.push(result.context)
|
300
299
|
generated.push(result.generated)
|
301
300
|
}
|
@@ -311,7 +310,7 @@ const getObjects = (objects) => {
|
|
311
310
|
}
|
312
311
|
}
|
313
312
|
|
314
|
-
const processContext = (context, { objects = {}, config, logs = [] }) => {
|
313
|
+
const processContext = async (context, { objects = {}, config, logs = [] }) => {
|
315
314
|
const generators = config.getGenerators(logs)
|
316
315
|
const semantics = config.getSemantics(logs)
|
317
316
|
|
@@ -329,10 +328,10 @@ const processContext = (context, { objects = {}, config, logs = [] }) => {
|
|
329
328
|
const args = { objects, response, getObjects: getObjects(objects) }
|
330
329
|
setupArgs(args, config, logs, hierarchy)
|
331
330
|
|
332
|
-
context = semantics.apply(args, context)
|
333
|
-
const generated = generators.apply(args, context)
|
331
|
+
context = await semantics.apply(args, context)
|
332
|
+
const generated = await generators.apply(args, context)
|
334
333
|
const assumed = { paraphrase: true, response: false, isResponse: false }
|
335
|
-
const paraphrases = generators.apply({ ...args, assumed }, context, { paraphrase: true, response: false, isResponse: false })
|
334
|
+
const paraphrases = await generators.apply({ ...args, assumed }, context, { paraphrase: true, response: false, isResponse: false })
|
336
335
|
let responses = []
|
337
336
|
if (context.isResponse) {
|
338
337
|
responses = generated
|
@@ -447,7 +446,7 @@ const setupContexts = (rawContexts) => {
|
|
447
446
|
return contexts
|
448
447
|
}
|
449
448
|
|
450
|
-
const processContextsB = ({ config, hierarchy, semantics, generators, json, isTest, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs }) => {
|
449
|
+
const processContextsB = async ({ config, hierarchy, semantics, generators, json, isTest, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs }) => {
|
451
450
|
// TODO fix this name to contextsPrime
|
452
451
|
const contextsPrime = []
|
453
452
|
const generatedPrime = []
|
@@ -480,7 +479,7 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
480
479
|
if (!config.get('skipSemantics')) {
|
481
480
|
const semantics = config.getSemantics(json.logs)
|
482
481
|
try {
|
483
|
-
contextPrime = semantics.apply(args, context)
|
482
|
+
contextPrime = await semantics.apply(args, context)
|
484
483
|
} catch (e) {
|
485
484
|
if (e.message == 'Maximum call stack size exceeded') {
|
486
485
|
const mostCalled = semantics.getMostCalled()
|
@@ -490,7 +489,7 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
490
489
|
if (isInstance) {
|
491
490
|
console.log('error', e.error)
|
492
491
|
}
|
493
|
-
contextPrime = semantics.apply(args, {
|
492
|
+
contextPrime = await semantics.apply(args, {
|
494
493
|
marker: 'error',
|
495
494
|
context,
|
496
495
|
text: e ? e.toString() : 'not available',
|
@@ -506,11 +505,11 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
506
505
|
continue
|
507
506
|
}
|
508
507
|
let assumed = { isResponse: true }
|
509
|
-
const generated = contextPrime.isResponse ? config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed) : ''
|
508
|
+
const generated = contextPrime.isResponse ? await config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed) : ''
|
510
509
|
let generatedParenthesized = []
|
511
510
|
if (generateParenthesized) {
|
512
511
|
config.parenthesized = true
|
513
|
-
generatedParenthesized = contextPrime.isResponse ? config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed) : ''
|
512
|
+
generatedParenthesized = contextPrime.isResponse ? await config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed) : ''
|
514
513
|
config.parenthesized = false
|
515
514
|
}
|
516
515
|
// assumed = { paraphrase: true, response: false };
|
@@ -518,11 +517,11 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
518
517
|
if (generateParenthesized) {
|
519
518
|
config.parenthesized = false
|
520
519
|
}
|
521
|
-
const paraphrases = config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed)
|
520
|
+
const paraphrases = await config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed)
|
522
521
|
let paraphrasesParenthesized = []
|
523
522
|
if (generateParenthesized) {
|
524
523
|
config.parenthesized = true
|
525
|
-
paraphrasesParenthesized = config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed)
|
524
|
+
paraphrasesParenthesized = await config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed)
|
526
525
|
config.parenthesized = false
|
527
526
|
}
|
528
527
|
contextsPrime.push(contextPrime)
|
@@ -634,7 +633,7 @@ const setupProcessB = ({ config, initializer, allowDelta = false } = {}) => {
|
|
634
633
|
}
|
635
634
|
|
636
635
|
// instance template loadTemplate
|
637
|
-
const loadInstance = (config, instance) => {
|
636
|
+
const loadInstance = async (config, instance) => {
|
638
637
|
const transitoryMode = global.transitoryMode
|
639
638
|
global.transitoryMode = false
|
640
639
|
|
@@ -668,7 +667,7 @@ const loadInstance = (config, instance) => {
|
|
668
667
|
|
669
668
|
const uuid = config.nameToUUID(instance.name)
|
670
669
|
setupArgs(args, config, config.logs, hierarchy, uuid)
|
671
|
-
results.apply(args)
|
670
|
+
await results.apply(args)
|
672
671
|
} else {
|
673
672
|
if (results.skipSemantics) {
|
674
673
|
config.config.skipSemantics = results.skipSemantics
|
@@ -676,7 +675,7 @@ const loadInstance = (config, instance) => {
|
|
676
675
|
const args = { config, hierarchy, json: results, commandLineArgs: {} }
|
677
676
|
args.isInstance = `instance${i}`
|
678
677
|
args.instance = ''
|
679
|
-
processContextsB(args)
|
678
|
+
await processContextsB(args)
|
680
679
|
if (results.skipSemantics) {
|
681
680
|
config.config.skipSemantics = null
|
682
681
|
}
|
@@ -701,7 +700,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
701
700
|
// ensure same start state
|
702
701
|
try {
|
703
702
|
if (writeTests) {
|
704
|
-
config.rebuild()
|
703
|
+
await config.rebuild()
|
705
704
|
const objects = getObjects(config.config.objects)(config.uuid)
|
706
705
|
}
|
707
706
|
} catch (error) {
|
@@ -773,7 +772,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
773
772
|
start = runtime.performance.performance.now()
|
774
773
|
}
|
775
774
|
const { contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime } =
|
776
|
-
processContextsB({ isTest, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
775
|
+
await processContextsB({ isTest, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
777
776
|
if (isTest) {
|
778
777
|
end = runtime.performance.performance.now()
|
779
778
|
clientSideTime = end - start
|
@@ -865,8 +864,12 @@ const getConfigForTest = (config, testConfig) => {
|
|
865
864
|
|
866
865
|
const runTest = async (config, expected, { args, verbose, testConfig, debug }) => {
|
867
866
|
const test = expected.query
|
867
|
+
if (args.query && args.query != test) {
|
868
|
+
// no run this
|
869
|
+
return
|
870
|
+
}
|
868
871
|
// initialize in between test so state is not preserved since the test was adding without state
|
869
|
-
config.rebuild()
|
872
|
+
await config.rebuild()
|
870
873
|
const errorHandler = (error) => {
|
871
874
|
if (error.metadata) {
|
872
875
|
const priorities = analyzeMetaData(expected.metadata, error.metadata)
|
@@ -1012,7 +1015,7 @@ const runTests = async (config, testFile, juicyBits) => {
|
|
1012
1015
|
}
|
1013
1016
|
|
1014
1017
|
const saveTest = async (testFile, config, test, expected, testConfig, saveDeveloper) => {
|
1015
|
-
config.rebuild()
|
1018
|
+
await config.rebuild()
|
1016
1019
|
const objects = getObjects(config.config.objects)(config.uuid)
|
1017
1020
|
console.log(test)
|
1018
1021
|
const result = await _process(config, test, { isTest: true })
|
@@ -1033,11 +1036,11 @@ const saveTestsHelper = async (testFile, config, tests, todo, testConfig, saveDe
|
|
1033
1036
|
return
|
1034
1037
|
}
|
1035
1038
|
const test = todo.pop()
|
1036
|
-
config.rebuild()
|
1039
|
+
await config.rebuild()
|
1037
1040
|
const result = await saveTest(testFile, config, test, tests[test], testConfig, saveDeveloper)
|
1038
1041
|
// initialize in between test so state is not preserved since the test was adding without state
|
1039
1042
|
// config.initialize({force: true})
|
1040
|
-
config.rebuild()
|
1043
|
+
await config.rebuild()
|
1041
1044
|
return saveTestsHelper(testFile, config, tests, todo, testConfig, saveDeveloper)
|
1042
1045
|
}
|
1043
1046
|
|
@@ -1356,7 +1359,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1356
1359
|
if (previousResults && previousResults.query == query.query) {
|
1357
1360
|
results = previousResults
|
1358
1361
|
prMessage = ' Using previous results. use -rtf for a hard rebuild of everything on the server side.'
|
1359
|
-
loadInstance(config, { resultss: [results] })
|
1362
|
+
await loadInstance(config, { resultss: [results] })
|
1360
1363
|
} else {
|
1361
1364
|
results = await _process(config, query.query, { initializer, rebuildingTemplate: true })
|
1362
1365
|
}
|
@@ -1582,7 +1585,7 @@ const knowledgeModuleImpl = async ({
|
|
1582
1585
|
parser.add_argument('-t', '--test', { action: 'store_true', help: 'Run the tests. Create tests by running with the --query + --save flag' })
|
1583
1586
|
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
1587
|
// 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' })
|
1588
|
+
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
1589
|
parser.add_argument('-tnp', '--testNoParenthesized', { action: 'store_true', help: 'Don\' check parenthesized differences for the tests' })
|
1587
1590
|
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
1591
|
// 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 +1631,7 @@ const knowledgeModuleImpl = async ({
|
|
1628
1631
|
global.pauseDebugging = true
|
1629
1632
|
}
|
1630
1633
|
|
1631
|
-
const config = createConfig()
|
1634
|
+
const config = await createConfig()
|
1632
1635
|
setupConfig(config)
|
1633
1636
|
processResults = processResults({ config, errorHandler })
|
1634
1637
|
|
@@ -1663,7 +1666,7 @@ const knowledgeModuleImpl = async ({
|
|
1663
1666
|
throw new Error('Error for the checkForLoop argument. Expected a JSON array of operator keys of the form "[<id>, <level>]"')
|
1664
1667
|
}
|
1665
1668
|
} catch (e) {
|
1666
|
-
throw new Error(
|
1669
|
+
throw new Error('Error for the checkForLoop argument. Expected a JSON array of operator keys of the form "[<id>, <level>]"')
|
1667
1670
|
}
|
1668
1671
|
} else {
|
1669
1672
|
if (process.argv.includes('--checkForLoop') || process.argv.includes('-cl')) {
|
@@ -1860,7 +1863,7 @@ const knowledgeModuleImpl = async ({
|
|
1860
1863
|
config.config.rebuild = true
|
1861
1864
|
}
|
1862
1865
|
try {
|
1863
|
-
config.load(template.template, template.instance, { rebuild: needsRebuild.needsRebuild || options.rebuild, previousResultss: needsRebuild.previousResultss, startOfChanges: needsRebuild.startOfChanges })
|
1866
|
+
await config.load(template.template, template.instance, { rebuild: needsRebuild.needsRebuild || options.rebuild, previousResultss: needsRebuild.previousResultss, startOfChanges: needsRebuild.startOfChanges })
|
1864
1867
|
} catch (e) {
|
1865
1868
|
console.error(`Error loading template for ${config.name}. ${e.error ? e.error : e}${e.stack ? e.stack : ''}`)
|
1866
1869
|
runtime.process.exit(-1)
|
@@ -1877,6 +1880,9 @@ const knowledgeModuleImpl = async ({
|
|
1877
1880
|
config.config.retrain = true
|
1878
1881
|
}
|
1879
1882
|
|
1883
|
+
if (args.saveDeveloper) {
|
1884
|
+
args.save = true
|
1885
|
+
}
|
1880
1886
|
if (args.test || args.testVerbose || args.testAllVerbose || args.save) {
|
1881
1887
|
global.transitoryMode = true
|
1882
1888
|
}
|
@@ -1994,7 +2000,7 @@ const knowledgeModuleImpl = async ({
|
|
1994
2000
|
lines.setElement(2, 2, JSON.stringify(result.actual.checked, null, 2))
|
1995
2001
|
lines.log()
|
1996
2002
|
if (args.vimdiff) {
|
1997
|
-
|
2003
|
+
show('checked properties for objects', result.expected.checked, result.actual.checked)
|
1998
2004
|
}
|
1999
2005
|
newError = true
|
2000
2006
|
headerShown = true
|
@@ -2012,7 +2018,7 @@ const knowledgeModuleImpl = async ({
|
|
2012
2018
|
lines.setElement(2, 2, JSON.stringify(result.actual.checkedContexts, null, 2))
|
2013
2019
|
lines.log()
|
2014
2020
|
if (args.vimdiff) {
|
2015
|
-
|
2021
|
+
show('checked properties for context', result.expected.checkedContexts, result.actual.checkedContexts)
|
2016
2022
|
}
|
2017
2023
|
newError = true
|
2018
2024
|
headerShown = true
|
@@ -2105,7 +2111,7 @@ const knowledgeModuleImpl = async ({
|
|
2105
2111
|
}
|
2106
2112
|
printConfig()
|
2107
2113
|
} else {
|
2108
|
-
const initConfig = (config) => {
|
2114
|
+
const initConfig = async (config) => {
|
2109
2115
|
if (template) {
|
2110
2116
|
if (config.needsRebuild(template.template, template.instance, { isModule: !isProcess }).needsRebuild) {
|
2111
2117
|
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 +2146,19 @@ const knowledgeModuleImpl = async ({
|
|
2140
2146
|
|
2141
2147
|
if (template) {
|
2142
2148
|
try {
|
2143
|
-
config.load(template.template, template.instance)
|
2149
|
+
await config.load(template.template, template.instance)
|
2144
2150
|
} catch (e) {
|
2145
2151
|
errorHandler(e)
|
2146
2152
|
}
|
2147
2153
|
}
|
2148
2154
|
}
|
2149
2155
|
|
2150
|
-
createConfigExport = (
|
2156
|
+
createConfigExport = async () => {
|
2151
2157
|
if (createConfig.cached) {
|
2152
2158
|
return createConfig.cached
|
2153
2159
|
}
|
2154
|
-
const config = createConfig(
|
2155
|
-
|
2156
|
-
config.stop_auto_rebuild()
|
2157
|
-
additionalConfig(config)
|
2158
|
-
config.restart_auto_rebuild()
|
2159
|
-
}
|
2160
|
-
initConfig(config)
|
2160
|
+
const config = await createConfig()
|
2161
|
+
await initConfig(config)
|
2161
2162
|
// config.rebuild({ isModule: true })
|
2162
2163
|
createConfig.cached = config
|
2163
2164
|
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.41",
|
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) {
|
@@ -339,7 +352,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
339
352
|
|
340
353
|
const generator = {
|
341
354
|
where: bridge.generatorp.where || bridge.where || client.where(4),
|
342
|
-
match: (args) => bridge.id == args.context.marker && args.context.level == level && args.context.paraphrase && match(args),
|
355
|
+
match: async (args) => bridge.id == args.context.marker && args.context.level == level && args.context.paraphrase && await match(args),
|
343
356
|
apply: (args) => apply(args),
|
344
357
|
applyWrapped: apply,
|
345
358
|
property: 'generatorp'
|
@@ -356,7 +369,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
356
369
|
const level = bridge.generatorr.level >= 0 ? bridge.generatorr.level : bridge.level + 1
|
357
370
|
const generator = {
|
358
371
|
where: bridge.generatorr.where || bridge.where || client.where(4),
|
359
|
-
match: (args) => bridge.id == args.context.marker && args.context.level == level && !args.context.paraphrase && (args.context.response || args.context.isResponse) && match(args),
|
372
|
+
match: async (args) => bridge.id == args.context.marker && args.context.level == level && !args.context.paraphrase && (args.context.response || args.context.isResponse) && await match(args),
|
360
373
|
apply: (args) => apply(args),
|
361
374
|
applyWrapped: apply,
|
362
375
|
property: 'generatorr'
|
@@ -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)
|
@@ -1003,8 +1005,8 @@ class Config {
|
|
1003
1005
|
return instance
|
1004
1006
|
}
|
1005
1007
|
*/
|
1006
|
-
getEvaluator (s, calls, log, context) {
|
1007
|
-
const instance = s({ ...context, evaluate: true })
|
1008
|
+
async getEvaluator (s, calls, log, context) {
|
1009
|
+
const instance = await s({ ...context, evaluate: true })
|
1008
1010
|
calls.touch(instance)
|
1009
1011
|
if (!instance.evalue && !instance.verbatim && !instance.value) {
|
1010
1012
|
this.warningNotEvaluated(log, context)
|
@@ -1021,7 +1023,7 @@ class Config {
|
|
1021
1023
|
fragmentInstantiator (contexts) {
|
1022
1024
|
return new Object({
|
1023
1025
|
contexts: () => contexts,
|
1024
|
-
instantiate: (mappings) => {
|
1026
|
+
instantiate: async (mappings) => {
|
1025
1027
|
const instantiated = _.cloneDeep(contexts)
|
1026
1028
|
// const todo = [...instantiated]
|
1027
1029
|
// const todo = [...instantiated]
|
@@ -1029,8 +1031,8 @@ class Config {
|
|
1029
1031
|
while (todo.length > 0) {
|
1030
1032
|
const context = todo.pop()
|
1031
1033
|
for (const mapping of mappings) {
|
1032
|
-
if (mapping.match({ context })) {
|
1033
|
-
mapping.apply({ context })
|
1034
|
+
if (await mapping.match({ context })) {
|
1035
|
+
await mapping.apply({ context })
|
1034
1036
|
}
|
1035
1037
|
}
|
1036
1038
|
for (const key of Object.keys(context)) {
|
@@ -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,18 +1618,18 @@ class Config {
|
|
1608
1618
|
return params
|
1609
1619
|
}
|
1610
1620
|
|
1611
|
-
|
1612
|
-
client.
|
1613
|
-
}
|
1614
|
-
|
1615
|
-
processContext (context) {
|
1616
|
-
return client.processContext(context, this.getParams())
|
1621
|
+
async processContext (context) {
|
1622
|
+
return await client.processContext(context, this.getParams())
|
1617
1623
|
}
|
1618
1624
|
|
1619
1625
|
process (query, options) {
|
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 (this.name && this.name == more.name) {
|
2861
|
+
throw new Error('Cannot add an object to itself for argument number ${index+1}.')
|
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/generators.js
CHANGED
@@ -44,7 +44,7 @@ class Generator {
|
|
44
44
|
return `Generator(${this.match}, ${this._applyWrapped || this._apply})${this.property ? `\nsee the ${this.property} property` : ''}`
|
45
45
|
}
|
46
46
|
|
47
|
-
matches (baseArgs, objects, context, hierarchy, config, options = {}) {
|
47
|
+
async matches (baseArgs, objects, context, hierarchy, config, options = {}) {
|
48
48
|
if (objects && objects.namespaced) {
|
49
49
|
objects = objects.namespaced[this.uuid]
|
50
50
|
}
|
@@ -63,17 +63,17 @@ class Generator {
|
|
63
63
|
}
|
64
64
|
const args = Object.assign({}, baseArgs, moreArgs, (baseArgs.getUUIDScoped || (() => { return {} }))(this.uuid))
|
65
65
|
// return this.match(args)
|
66
|
-
const matches = this.match(args)
|
66
|
+
const matches = await this.match(args)
|
67
67
|
if ((matches && (options.debug || {}).match) ||
|
68
68
|
callId == this.callId) {
|
69
69
|
debugger // next line is the matcher
|
70
|
-
this.match(args)
|
70
|
+
await this.match(args)
|
71
71
|
}
|
72
72
|
return matches
|
73
73
|
}
|
74
74
|
|
75
75
|
// apply (baseArgs, objects, g, gs, context, hierarchy, config, response, log, options = {}) {
|
76
|
-
apply (baseArgs, objects, context, hierarchy, config, response, log, options = {}) {
|
76
|
+
async apply (baseArgs, objects, context, hierarchy, config, response, log, options = {}) {
|
77
77
|
if (!log) {
|
78
78
|
throw new Error('generators.apply argument log is required')
|
79
79
|
}
|
@@ -129,7 +129,7 @@ class Generator {
|
|
129
129
|
callId == this.callId) {
|
130
130
|
debugger
|
131
131
|
}
|
132
|
-
return this._apply(args)
|
132
|
+
return await this._apply(args)
|
133
133
|
}
|
134
134
|
}
|
135
135
|
|
@@ -165,7 +165,7 @@ class Generators {
|
|
165
165
|
};
|
166
166
|
|
167
167
|
// assumed - properties added to context before the generators are called. For setting paraphrase property
|
168
|
-
apply (args, context, assumed = {}, options = {}) {
|
168
|
+
async apply (args, context, assumed = {}, options = {}) {
|
169
169
|
if (Array.isArray(context)) {
|
170
170
|
throw new Error('Expected a context not an array')
|
171
171
|
}
|
@@ -186,12 +186,12 @@ class Generators {
|
|
186
186
|
const stack = args.calls.push()
|
187
187
|
for (let igenerator = 0; igenerator < this.generators.length; ++igenerator) {
|
188
188
|
const generator = this.generators[igenerator]
|
189
|
-
if (generator.matches(args, objects, context, hierarchy, config, options)) {
|
189
|
+
if (await generator.matches(args, objects, context, hierarchy, config, options)) {
|
190
190
|
const log = (message) => { this.logs.push(message) }
|
191
191
|
// this.logs.push(`Generators: applied ${generator.toString()}\n to\n ${JSON.stringify(context)}`)
|
192
192
|
let errorMessage = 'The apply function did not return a value'
|
193
193
|
try {
|
194
|
-
generated = generator.apply(args, objects, context, hierarchy, config, response, log)
|
194
|
+
generated = await generator.apply(args, objects, context, hierarchy, config, response, log)
|
195
195
|
} catch (e) {
|
196
196
|
// the next if handle this
|
197
197
|
generated = null
|
package/src/semantics.js
CHANGED
@@ -49,7 +49,7 @@ class Semantic {
|
|
49
49
|
}
|
50
50
|
}
|
51
51
|
|
52
|
-
matches (baseArgs, context, options = {}) {
|
52
|
+
async matches (baseArgs, context, options = {}) {
|
53
53
|
const hierarchy = baseArgs.hierarchy
|
54
54
|
const config = baseArgs.config
|
55
55
|
|
@@ -71,16 +71,16 @@ class Semantic {
|
|
71
71
|
}
|
72
72
|
const args = Object.assign({}, baseArgs, moreArgs, (baseArgs.getUUIDScoped || (() => { return {} }))(this.uuid))
|
73
73
|
|
74
|
-
const matches = this.matcher(args)
|
74
|
+
const matches = await this.matcher(args)
|
75
75
|
if (matches && (options.debug || {}).match ||
|
76
76
|
callId == this.callId) {
|
77
77
|
debugger // next line is the matcher
|
78
|
-
this.matcher(args)
|
78
|
+
await this.matcher(args)
|
79
79
|
}
|
80
80
|
return matches
|
81
81
|
}
|
82
82
|
|
83
|
-
apply (baseArgs, context, s, log, options = {}) {
|
83
|
+
async apply (baseArgs, context, s, log, options = {}) {
|
84
84
|
const { hierarchy, config, response } = baseArgs
|
85
85
|
const objects = baseArgs.getObjects(this.uuid)
|
86
86
|
if (config && config.debugLoops) {
|
@@ -124,7 +124,7 @@ class Semantic {
|
|
124
124
|
if (args.breakOnSemantics) {
|
125
125
|
debugger
|
126
126
|
}
|
127
|
-
this._apply(args)
|
127
|
+
await this._apply(args)
|
128
128
|
return contextPrime
|
129
129
|
}
|
130
130
|
}
|
@@ -176,7 +176,7 @@ class Semantics {
|
|
176
176
|
return this.semantics[maxOrdinal]
|
177
177
|
}
|
178
178
|
|
179
|
-
applyToContext (args, context, options) {
|
179
|
+
async applyToContext (args, context, options) {
|
180
180
|
// let context_prime = {}
|
181
181
|
if (!(context instanceof Array || context instanceof Object)) {
|
182
182
|
return context
|
@@ -197,14 +197,14 @@ class Semantics {
|
|
197
197
|
if (semantic.isQuestion && seenQuestion) {
|
198
198
|
continue
|
199
199
|
}
|
200
|
-
if (semantic.matches(args, context, options)) {
|
200
|
+
if (await semantic.matches(args, context, options)) {
|
201
201
|
if (!this.calls[counter]) {
|
202
202
|
this.calls[counter] = 0
|
203
203
|
}
|
204
204
|
this.calls[counter] += 1
|
205
205
|
const log = (message) => { this.logs.push(message) }
|
206
206
|
try {
|
207
|
-
contextPrime = semantic.apply(args, context, s, log, options)
|
207
|
+
contextPrime = await semantic.apply(args, context, s, log, options)
|
208
208
|
if (!contextPrime.controlKeepMotivation && semantic.oneShot) {
|
209
209
|
// semantic.tied_ids.forEach((tied_id) => args.config.removeSemantic(tied_id))
|
210
210
|
args.config.removeSemantic(semantic)
|
@@ -310,19 +310,19 @@ class Semantics {
|
|
310
310
|
return contextPrime
|
311
311
|
}
|
312
312
|
|
313
|
-
applyToContexts (args, contexts, options) {
|
313
|
+
async applyToContexts (args, contexts, options) {
|
314
314
|
const contextsPrime = []
|
315
|
-
|
316
|
-
contextsPrime.push(this.applyToContext(args, context, options))
|
317
|
-
}
|
315
|
+
for (const context of contexts) {
|
316
|
+
contextsPrime.push(await this.applyToContext(args, context, options))
|
317
|
+
}
|
318
318
|
return contextsPrime
|
319
319
|
}
|
320
320
|
|
321
|
-
apply (args, context, options) {
|
321
|
+
async apply (args, context, options) {
|
322
322
|
if (Array.isArray(context)) {
|
323
|
-
return this.applyToContexts(args, context, options)
|
323
|
+
return await this.applyToContexts(args, context, options)
|
324
324
|
} else if (context instanceof Object) {
|
325
|
-
return this.applyToContext(args, context, options)
|
325
|
+
return await this.applyToContext(args, context, options)
|
326
326
|
} else {
|
327
327
|
return context
|
328
328
|
}
|