theprogrammablemind 9.3.0-beta.2 → 9.3.0-beta.21
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 +64 -60
- package/demo.js +2 -2
- package/package.json +1 -1
- package/src/config.js +68 -85
- package/src/configHelpers.js +7 -5
- package/src/digraph.js +2 -2
- package/src/digraph_internal.js +2 -2
- package/src/flatten.js +1 -1
- package/src/generators.js +6 -6
- package/src/helpers.js +16 -15
- package/src/project.js +3 -0
- package/src/semantics.js +4 -4
- package/src/unflatten.js +1 -1
package/client.js
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
const { Semantics, Semantic } = require('./src/semantics')
|
2
2
|
const { Generators, Generator } = require('./src/generators')
|
3
3
|
const { Config } = require('./src/config')
|
4
|
-
const { loadInstance,
|
5
|
-
const DigraphInternal = require('./src/digraph_internal')
|
4
|
+
const { loadInstance, setupArgs, gs, processContext, getObjects, setupProcessB, processContextsB } = require('./src/configHelpers')
|
6
5
|
const Digraph = require('./src/digraph')
|
7
6
|
const { project } = require('./src/project')
|
8
7
|
const fetch = require('node-fetch')
|
@@ -12,7 +11,7 @@ const _ = require('lodash')
|
|
12
11
|
const stringify = require('json-stable-stringify')
|
13
12
|
const Lines = require('./lines')
|
14
13
|
const flattens = require('./src/flatten')
|
15
|
-
const { appendNoDups,
|
14
|
+
const { appendNoDups, updateQueries, safeNoDups, stableId, where, suggestAssociationsFix, suggestAssociationsFixFromSummaries, validProps } = require('./src/helpers')
|
16
15
|
const runtime = require('./runtime')
|
17
16
|
const sortJson = runtime.sortJson
|
18
17
|
const debug = require('./src/debug')
|
@@ -77,7 +76,7 @@ const pickObjects = (config, testConfig, getObjects) => {
|
|
77
76
|
const sameJSON = (json1, json2) => {
|
78
77
|
const sjson1 = sortJson(json1, { depth: 25 })
|
79
78
|
const sjson2 = sortJson(json2, { depth: 25 })
|
80
|
-
return JSON.stringify(sjson1)
|
79
|
+
return JSON.stringify(sjson1) === JSON.stringify(sjson2)
|
81
80
|
}
|
82
81
|
|
83
82
|
const vimdiff = (actualJSON, expectedJSON, title) => {
|
@@ -149,7 +148,7 @@ const convertToStable = (objects) => {
|
|
149
148
|
const writeTestFile = (fn, tests) => {
|
150
149
|
const stabilize = (tests) => {
|
151
150
|
for (const test of tests) {
|
152
|
-
for (opChoice of test.metadata.opChoices) {
|
151
|
+
for (const opChoice of test.metadata.opChoices) {
|
153
152
|
opChoice.ops.sort()
|
154
153
|
}
|
155
154
|
test.metadata.opChoices.sort()
|
@@ -185,7 +184,7 @@ const writeTest = (fn, query, objects, generated, paraphrases, responses, contex
|
|
185
184
|
}, { depth: 25 })
|
186
185
|
let wasSet = false
|
187
186
|
tests.forEach((test, index) => {
|
188
|
-
if (test.query
|
187
|
+
if (test.query === query) {
|
189
188
|
tests[index] = results
|
190
189
|
wasSet = true
|
191
190
|
}
|
@@ -261,7 +260,7 @@ const throwErrorHandler = (error) => {
|
|
261
260
|
throw error
|
262
261
|
}
|
263
262
|
|
264
|
-
const _process = async (config, query, { initializer, commandLineArgs, credentials, writeTests, isTest, saveDeveloper, rebuildingTemplate, testConfig, testsFN, errorHandler = throwErrorHandler } = {}) => {
|
263
|
+
const _process = async (config, query, { initializer, commandLineArgs, credentials, writeTests, isProcess, isModule, isTest, saveDeveloper, rebuildingTemplate, testConfig, testsFN, errorHandler = throwErrorHandler } = {}) => {
|
265
264
|
if (credentials) {
|
266
265
|
config.server(credentials.server, credentials.key)
|
267
266
|
}
|
@@ -321,7 +320,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
321
320
|
data.start_counter = startCounter
|
322
321
|
let json = await doWithRetries(retries, url, queryParams, data)
|
323
322
|
let resetData = false
|
324
|
-
if (json.code
|
323
|
+
if (json.code === 'NOT_IN_CACHE') {
|
325
324
|
resetData = true
|
326
325
|
const setupB = setupProcessB({ config, allowDelta: false })
|
327
326
|
data = setupB.data
|
@@ -346,15 +345,16 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
346
345
|
throw json
|
347
346
|
} else {
|
348
347
|
let clientSideTime
|
348
|
+
let start
|
349
349
|
if (isTest) {
|
350
350
|
start = runtime.performance.performance.now()
|
351
351
|
}
|
352
352
|
const summary = { summaries: json.summaries, length: json.contexts.length }
|
353
353
|
summaries.push(summary)
|
354
354
|
const { contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime } =
|
355
|
-
await processContextsB({ isTest, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
355
|
+
await processContextsB({ isTest, isProcess, isModule, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
356
356
|
if (isTest) {
|
357
|
-
end = runtime.performance.performance.now()
|
357
|
+
const end = runtime.performance.performance.now()
|
358
358
|
clientSideTime = end - start
|
359
359
|
}
|
360
360
|
response.associations = json.associations
|
@@ -386,13 +386,13 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
386
386
|
}
|
387
387
|
|
388
388
|
if (writeTests) {
|
389
|
-
const
|
389
|
+
const actualConfig = getConfigForTest(config, testConfig)
|
390
390
|
const saveObjects = { ...config.config.objects }
|
391
391
|
saveObjects.nameToUUID = {}
|
392
392
|
for (const km of config.configs) {
|
393
393
|
saveObjects.nameToUUID[km.name] = km.uuid
|
394
394
|
}
|
395
|
-
writeTest(testsFN, query, saveObjects, response.generated, response.paraphrases, response.responses, response.contexts, response.associations, response.metadata,
|
395
|
+
writeTest(testsFN, query, saveObjects, response.generated, response.paraphrases, response.responses, response.contexts, response.associations, response.metadata, actualConfig, saveDeveloper, response.paraphrasesParenthesized, response.generatedParenthesized, response.summaries)
|
396
396
|
}
|
397
397
|
|
398
398
|
return response
|
@@ -485,7 +485,7 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug, tim
|
|
485
485
|
setupArgs(args, config)
|
486
486
|
await testConfig.initializer(args)
|
487
487
|
}
|
488
|
-
const result = await _process(config, test, { errorHandler, isTest: true })
|
488
|
+
const result = await _process(config, test, { errorHandler, isTest: true, isProcess: true, isModule: false })
|
489
489
|
result.query = test
|
490
490
|
if (debug) {
|
491
491
|
defaultInnerProcess(config, errorHandler, result)
|
@@ -499,19 +499,19 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug, tim
|
|
499
499
|
timings.client += result.clientSideTimes / 1000
|
500
500
|
lines.log()
|
501
501
|
}
|
502
|
-
const
|
503
|
-
delete
|
504
|
-
const
|
505
|
-
const
|
506
|
-
let
|
502
|
+
const expectedObjects = sortJson(convertToStable(expected.objects), { depth: 25 })
|
503
|
+
delete expectedObjects.nameToUUID
|
504
|
+
const actualObjects = sortJson(convertToStable(config.config.objects), { depth: 25 })
|
505
|
+
const failedParaphrases = !matching(result.paraphrases, expected.paraphrases)
|
506
|
+
let failedParaphrasesParenthesized = !matching(result.paraphrasesParenthesized, expected.paraphrasesParenthesized)
|
507
507
|
let failed_generatedParenthesized = !matching(result.generatedParenthesized, expected.generatedParenthesized)
|
508
508
|
// TODO fix the naming conventions: camelcase + use actual instead of result
|
509
|
-
const
|
510
|
-
const
|
511
|
-
const
|
509
|
+
const failedResponses = !matching(result.responses, expected.responses)
|
510
|
+
const failedContexts = !matching(result.contexts, expected.contexts)
|
511
|
+
const failedObjects = !matching(actualObjects, expectedObjects)
|
512
512
|
|
513
513
|
if (args.testNoParenthesized) {
|
514
|
-
|
514
|
+
failedParaphrasesParenthesized = false
|
515
515
|
failed_generatedParenthesized = false
|
516
516
|
}
|
517
517
|
|
@@ -525,23 +525,23 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug, tim
|
|
525
525
|
}
|
526
526
|
return expected.objects.namespaced[expected.objects.nameToUUID[name]] || {}
|
527
527
|
}
|
528
|
-
const
|
528
|
+
const expectedChecked = sortJson(pickObjects(config, testConfig, expectedGetObjects), { depth: 25 })
|
529
529
|
const actualGetObjects = (name) => {
|
530
530
|
if (!name) {
|
531
531
|
name = config.name
|
532
532
|
}
|
533
|
-
const km = config.configs.find((km) => km.name
|
533
|
+
const km = config.configs.find((km) => km.name === name)
|
534
534
|
return config.config.objects.namespaced[km.uuid] || {}
|
535
535
|
}
|
536
|
-
const
|
537
|
-
const
|
536
|
+
const actualChecked = sortJson(pickObjects(config, testConfig, actualGetObjects), { depth: 25 })
|
537
|
+
const failedChecked = !matching(actualObjects, expectedObjects)
|
538
538
|
|
539
|
-
const
|
540
|
-
const
|
541
|
-
const
|
542
|
-
const
|
543
|
-
const
|
544
|
-
const failed =
|
539
|
+
const failedChecks = !matching(actualObjects, expectedObjects)
|
540
|
+
const failedChecked_objects = !matching(actualChecked, expectedChecked)
|
541
|
+
const actualConfig = sortJson(convertToStable(getConfigForTest(config, testConfig)), { depth: 25 })
|
542
|
+
const expectedConfig = sortJson(convertToStable(expected.config), { depth: 25 })
|
543
|
+
const failedConfig = !matching(actualConfig, expectedConfig)
|
544
|
+
const failed = failedChecked_objects || failedParaphrases || failedParaphrasesParenthesized || failed_generatedParenthesized || failedResponses || failedContexts || failedObjects || failedConfig || failedChecked || failedCheckedContexts
|
545
545
|
|
546
546
|
if (expected.metadata && result.metadata && failed) {
|
547
547
|
const priorities = analyzeMetaData(expected.metadata, result.metadata)
|
@@ -559,9 +559,9 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug, tim
|
|
559
559
|
paraphrasesParenthesized: expected.paraphrasesParenthesized,
|
560
560
|
generatedParenthesized: expected.generatedParenthesized,
|
561
561
|
results: expected.contexts,
|
562
|
-
checked:
|
562
|
+
checked: expectedChecked,
|
563
563
|
checkedContexts: pickedExpectedContexts,
|
564
|
-
objects:
|
564
|
+
objects: expectedObjects,
|
565
565
|
config: expected.config,
|
566
566
|
summaries: expected.summaries
|
567
567
|
},
|
@@ -571,10 +571,10 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug, tim
|
|
571
571
|
paraphrasesParenthesized: result.paraphrasesParenthesized,
|
572
572
|
generatedParenthesized: result.generatedParenthesized,
|
573
573
|
results: result.contexts,
|
574
|
-
checked:
|
574
|
+
checked: actualChecked,
|
575
575
|
checkedContexts: pickedResultContexts,
|
576
|
-
objects:
|
577
|
-
config:
|
576
|
+
objects: actualObjects,
|
577
|
+
config: actualConfig,
|
578
578
|
summaries: result.summaries
|
579
579
|
}
|
580
580
|
}
|
@@ -624,7 +624,7 @@ const saveTest = async (testFile, config, test, expected, testConfig, saveDevelo
|
|
624
624
|
await config.rebuild()
|
625
625
|
const objects = getObjects(config.config.objects)(config.uuid)
|
626
626
|
console.log(test)
|
627
|
-
const result = await _process(config, test, { isTest: true })
|
627
|
+
const result = await _process(config, test, { isTest: true, isProcess: true, isModule: true })
|
628
628
|
// const actualObjects = config.config.objects
|
629
629
|
const actualConfig = getConfigForTest(config, testConfig)
|
630
630
|
const args = {
|
@@ -667,6 +667,7 @@ const showInfo = (description, section, config) => {
|
|
667
667
|
console.log(JSON.stringify(config.getInfo(), null, 2))
|
668
668
|
}
|
669
669
|
|
670
|
+
/*
|
670
671
|
const submitBugToAPI = async (subscription_id, subscription_password, config) => {
|
671
672
|
console.log('********* Submitting bug *********')
|
672
673
|
const body = { description: config.config.description, config: config.config }
|
@@ -689,7 +690,6 @@ const submitBugToAPI = async (subscription_id, subscription_password, config) =>
|
|
689
690
|
})
|
690
691
|
}
|
691
692
|
|
692
|
-
/*
|
693
693
|
const submitBug = async (subscription_id, subscription_password, config, utterance, retries = 2) => {
|
694
694
|
// TODO remove these from the config
|
695
695
|
const properties = ['expected_contexts', 'expected_generated']
|
@@ -862,7 +862,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
|
|
862
862
|
|
863
863
|
if (responses.explain_priorities) {
|
864
864
|
console.log('Explain Priorities')
|
865
|
-
for ([inputs, output, reason] of responses.explain_priorities) {
|
865
|
+
for (const [inputs, output, reason] of responses.explain_priorities) {
|
866
866
|
console.log(` inputs: ${JSON.stringify(inputs)} output: ${JSON.stringify(output)} reason: ${reason}`)
|
867
867
|
}
|
868
868
|
}
|
@@ -871,7 +871,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
|
|
871
871
|
if (!name) {
|
872
872
|
name = config.name
|
873
873
|
}
|
874
|
-
const km = config.configs.find((km) => km.name
|
874
|
+
const km = config.configs.find((km) => km.name === name)
|
875
875
|
return config.config.objects.namespaced[km.uuid] || {}
|
876
876
|
}
|
877
877
|
const picked = sortJson(pickObjects(config, config.testConfig, actualGetObjects), { depth: 25 })
|
@@ -967,7 +967,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
967
967
|
}
|
968
968
|
config.config.skipSemantics = skipSemantics && !isFragment
|
969
969
|
const transitoryMode = global.transitoryMode
|
970
|
-
if (isFragment || property
|
970
|
+
if (isFragment || property === 'fragments') {
|
971
971
|
global.transitoryMode = true
|
972
972
|
}
|
973
973
|
if (hierarchy) {
|
@@ -991,7 +991,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
991
991
|
console.log(getSuggestionMessage(suggestion))
|
992
992
|
}
|
993
993
|
}
|
994
|
-
if (!rebuild && previousResults && previousResults.query
|
994
|
+
if (!rebuild && previousResults && previousResults.query === query.query) {
|
995
995
|
results = previousResults
|
996
996
|
prMessage = ' Using previous results. use -rtf for a hard rebuild of everything on the server side.'
|
997
997
|
await loadInstance(config, { resultss: [results] })
|
@@ -1139,7 +1139,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
1139
1139
|
for (let configsIndex = 0; configsIndex < template.configs.length; ++configsIndex) {
|
1140
1140
|
const query = template.configs[configsIndex]
|
1141
1141
|
// account for things for example associations being added to the config while debugginer
|
1142
|
-
const pr = previousResultss && previousResultss.find((pr) => pr.query
|
1142
|
+
const pr = previousResultss && previousResultss.find((pr) => pr.query === query)
|
1143
1143
|
todo.push({ property: 'resultss', query, previousResults: pr, skipSemantics: false || query.skipSemantics })
|
1144
1144
|
}
|
1145
1145
|
}
|
@@ -1309,7 +1309,7 @@ const knowledgeModuleImpl = async ({
|
|
1309
1309
|
parser.add_argument('--parenthesized', { action: 'store_true', help: 'Show the generated phrases with parenthesis.' })
|
1310
1310
|
parser.add_argument('-c', '--clean', { help: 'Remove data from the test files. a === association' })
|
1311
1311
|
parser.add_argument('-od', '--objectDiff', { action: 'store_true', help: 'When showing the objects use a colour diff' })
|
1312
|
-
parser.add_argument('-p', '--print', { help: 'Print the specified elements c === config, w === words, b === bridges, o === operators d === objects (d for data), h === hierarchy, g === generators, s === semantics, l === load t=tests ordering p === priorities a
|
1312
|
+
parser.add_argument('-p', '--print', { help: 'Print the specified elements c === config, w === words, b === bridges, o === operators d === objects (d for data), h === hierarchy, g === generators, s === semantics, l === load t=tests ordering p === priorities a === associations j === JSON sent to server. for example --print wb' })
|
1313
1313
|
parser.add_argument('-s', '--save', { action: 'store_true', help: 'When running with the --query flag this will save the current run to the test file. When running without the --query flag all tests will be run and resaved.' })
|
1314
1314
|
parser.add_argument('-fr', '--failRebuild', { action: 'store_true', help: 'If a rebuild is required fail out.' })
|
1315
1315
|
parser.add_argument('-sd', '--saveDeveloper', { action: 'store_true', help: 'Same as -s but the query will not show up in the info command.' })
|
@@ -1361,10 +1361,10 @@ const knowledgeModuleImpl = async ({
|
|
1361
1361
|
if (what.length !== 2) {
|
1362
1362
|
return false
|
1363
1363
|
}
|
1364
|
-
if (!typeof what[0]
|
1364
|
+
if (!typeof what[0] === 'string') {
|
1365
1365
|
return false
|
1366
1366
|
}
|
1367
|
-
if (!typeof what[1]
|
1367
|
+
if (!typeof what[1] === 'number') {
|
1368
1368
|
return false
|
1369
1369
|
}
|
1370
1370
|
return true
|
@@ -1682,9 +1682,9 @@ const knowledgeModuleImpl = async ({
|
|
1682
1682
|
const tidy_summaries = (summaries) => {
|
1683
1683
|
const summaries_prime = []
|
1684
1684
|
for (const chunk of summaries) {
|
1685
|
-
chunk_prime = { length: chunk.length, summaries: [] }
|
1685
|
+
const chunk_prime = { length: chunk.length, summaries: [] }
|
1686
1686
|
for (const summary of chunk.summaries) {
|
1687
|
-
const summary_prime = { counter: summary.counter, operators: [] }
|
1687
|
+
const summary_prime = { counter: summary.counter, operators: [] }
|
1688
1688
|
for (const operator of summary.operators) {
|
1689
1689
|
summary_prime.operators.push(`{ marker: [${operator.marker[0]}, ${operator.marker[1]}] range: { start: ${operator.range.start}, end: ${operator.range.end} } }`)
|
1690
1690
|
}
|
@@ -1716,7 +1716,7 @@ const knowledgeModuleImpl = async ({
|
|
1716
1716
|
if (lengths > iDiff) {
|
1717
1717
|
const suggestion = suggestAssociationsFix(result.expected.summaries[iSummaries].summaries, result.actual.summaries[iSummaries].summaries)
|
1718
1718
|
if (suggestion) {
|
1719
|
-
suggestedFix = suggestion
|
1719
|
+
const suggestedFix = suggestion
|
1720
1720
|
// console.log(`Try adding this to the associations: { context: ${JSON.stringify(getSuggestion(suggestedFix))}, choose: <indexOfMainElement> },`)
|
1721
1721
|
console.log(getSuggestionMessage(suggestedFix))
|
1722
1722
|
return
|
@@ -1856,7 +1856,7 @@ const knowledgeModuleImpl = async ({
|
|
1856
1856
|
f()
|
1857
1857
|
})
|
1858
1858
|
.catch((e) => {
|
1859
|
-
if (e.errno
|
1859
|
+
if (e.errno === 'ECONNREFUSED') {
|
1860
1860
|
console.log(e)
|
1861
1861
|
readline.close()
|
1862
1862
|
} else {
|
@@ -1880,7 +1880,7 @@ const knowledgeModuleImpl = async ({
|
|
1880
1880
|
global.beforeObjects = _.cloneDeep(objects)
|
1881
1881
|
}
|
1882
1882
|
try {
|
1883
|
-
await processResults(_process(config, args.query, { commandLineArgs: args, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
|
1883
|
+
await processResults(_process(config, args.query, { commandLineArgs: args, isProcess, isModule: !isProcess, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
|
1884
1884
|
} catch (error) {
|
1885
1885
|
console.log('Error', error)
|
1886
1886
|
}
|
@@ -1909,8 +1909,18 @@ const knowledgeModuleImpl = async ({
|
|
1909
1909
|
loadForTesting = true
|
1910
1910
|
}
|
1911
1911
|
}
|
1912
|
+
if (template) {
|
1913
|
+
try {
|
1914
|
+
await config.load(rebuildTemplate, template.template, template.instance)
|
1915
|
+
} catch (e) {
|
1916
|
+
errorHandler(e)
|
1917
|
+
}
|
1918
|
+
}
|
1919
|
+
|
1912
1920
|
// remove test only stuff
|
1913
1921
|
if (!isProcess && !loadForTesting) {
|
1922
|
+
config.removeDevelopmentElements(config.config)
|
1923
|
+
/*
|
1914
1924
|
config.config.operators = config.config.operators.filter((operator) => {
|
1915
1925
|
if (operator.development) {
|
1916
1926
|
return false
|
@@ -1925,20 +1935,14 @@ const knowledgeModuleImpl = async ({
|
|
1925
1935
|
return true
|
1926
1936
|
}
|
1927
1937
|
})
|
1938
|
+
*/
|
1928
1939
|
}
|
1929
1940
|
|
1930
|
-
if (template) {
|
1931
|
-
try {
|
1932
|
-
await config.load(rebuildTemplate, template.template, template.instance)
|
1933
|
-
} catch (e) {
|
1934
|
-
errorHandler(e)
|
1935
|
-
}
|
1936
|
-
}
|
1937
1941
|
}
|
1938
1942
|
|
1939
1943
|
// no cache 21 minutes + rebuild fails "node tester_rebuild -m colors"
|
1940
1944
|
// cache okay
|
1941
|
-
createConfigExport = async () => {
|
1945
|
+
const createConfigExport = async () => {
|
1942
1946
|
if (createConfig.cached) {
|
1943
1947
|
return createConfig.cached
|
1944
1948
|
}
|
package/demo.js
CHANGED
@@ -34,13 +34,13 @@ let config = {
|
|
34
34
|
apply: ({ context }) => context.evalue
|
35
35
|
},
|
36
36
|
{
|
37
|
-
match: ({ context }) => context.marker
|
37
|
+
match: ({ context }) => context.marker === 'unknown',
|
38
38
|
apply: ({ context }) => context.text
|
39
39
|
}
|
40
40
|
],
|
41
41
|
semantics: [
|
42
42
|
{
|
43
|
-
match: ({ context }) => context.marker
|
43
|
+
match: ({ context }) => context.marker === 'went',
|
44
44
|
apply: ({ context }) => {
|
45
45
|
// same way as kms that I wrote. you dont have to do this though
|
46
46
|
context.isResponse = true
|
package/package.json
CHANGED
package/src/config.js
CHANGED
@@ -98,7 +98,7 @@ const debugBridge = (bridge) => {
|
|
98
98
|
return
|
99
99
|
}
|
100
100
|
if (global.entodictonDebugBridge) {
|
101
|
-
if (global.entodictonDebugBridge
|
101
|
+
if (global.entodictonDebugBridge === bridge.id) {
|
102
102
|
// debug hierarchy hit
|
103
103
|
debugger // eslint-disable-line no-debugger
|
104
104
|
}
|
@@ -128,13 +128,13 @@ const debugConfigProps = (config) => {
|
|
128
128
|
{ property: 'priorities', check: (v) => debugPriority(v) },
|
129
129
|
{ property: 'associations', check: (v) => debugAssociation(v) },
|
130
130
|
// TODO implement debugWords
|
131
|
-
{ property: 'words', check: (v) => debugWords(v) },
|
131
|
+
// { property: 'words', check: (v) => debugWords(v) },
|
132
132
|
{ property: 'hierarchy', check: (v) => debugHierarchy(v) },
|
133
133
|
{ property: 'operators', check: (v) => debugOperator(v) },
|
134
134
|
{ property: 'bridges', check: (v) => debugBridge(v) }
|
135
135
|
]
|
136
136
|
for (const { property, check } of checkProps) {
|
137
|
-
if (property
|
137
|
+
if (property === 'associations') {
|
138
138
|
if (config[property]) {
|
139
139
|
if (config[property].negative) {
|
140
140
|
for (const value of config[property].negative) {
|
@@ -147,7 +147,7 @@ const debugConfigProps = (config) => {
|
|
147
147
|
}
|
148
148
|
}
|
149
149
|
}
|
150
|
-
} else if (property
|
150
|
+
} else if (property === 'words') {
|
151
151
|
/*
|
152
152
|
if (config[property]) {
|
153
153
|
for (const value of config[property].literals) {
|
@@ -249,7 +249,7 @@ const operatorKey_valid = (key) => {
|
|
249
249
|
}
|
250
250
|
|
251
251
|
const elist = (list, check, prefix) => {
|
252
|
-
for ([index, element] of list.entries()) {
|
252
|
+
for (const [index, element] of list.entries()) {
|
253
253
|
try {
|
254
254
|
check(element)
|
255
255
|
} catch (e) {
|
@@ -388,7 +388,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
388
388
|
|
389
389
|
const generator = {
|
390
390
|
where: bridge.generatorp.where || bridge.where || helpers.where(4),
|
391
|
-
match: async (args) => bridge.id
|
391
|
+
match: async (args) => bridge.id === args.context.marker && args.context.level === level && args.context.paraphrase && await match(args),
|
392
392
|
apply: (args) => apply(args),
|
393
393
|
applyWrapped: apply,
|
394
394
|
property: 'generatorp'
|
@@ -405,7 +405,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
405
405
|
const level = bridge.generatorr.level >= 0 ? bridge.generatorr.level : bridge.level + 1
|
406
406
|
const generator = {
|
407
407
|
where: bridge.generatorr.where || bridge.where || helpers.where(4),
|
408
|
-
match: async (args) => bridge.id
|
408
|
+
match: async (args) => bridge.id === args.context.marker && args.context.level === level && !args.context.paraphrase && (args.context.response || args.context.isResponse) && await match(args),
|
409
409
|
apply: (args) => apply(args),
|
410
410
|
applyWrapped: apply,
|
411
411
|
property: 'generatorr'
|
@@ -420,13 +420,13 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
420
420
|
const addSemantic = (semantic, evaluate) => {
|
421
421
|
const match = semantic.match || (() => true)
|
422
422
|
let apply = semantic
|
423
|
-
// if I do apply
|
423
|
+
// if I do apply === semantic.apply or semantic there is one function that has apply defined for some reason even though not explicitly set
|
424
424
|
if (semantic.apply && typeof semantic !== 'function') {
|
425
425
|
apply = semantic.apply
|
426
426
|
}
|
427
427
|
const semanticDef = {
|
428
428
|
where: semantic.where || bridge.where || helpers.where(4),
|
429
|
-
match: (args) => bridge.id
|
429
|
+
match: (args) => bridge.id === args.context.marker && !!args.context.evaluate === evaluate && match(args),
|
430
430
|
apply: (args) => apply(args),
|
431
431
|
applyWrapped: semantic,
|
432
432
|
property: evaluate ? 'evaluator' : 'semantic'
|
@@ -577,7 +577,7 @@ const addWord = (config, uuid) => ({ word, id, initial }) => {
|
|
577
577
|
const normalizeConfig = (config) => {
|
578
578
|
if (config) {
|
579
579
|
if (!config.objects) {
|
580
|
-
config.objects = { namespaced: {}
|
580
|
+
config.objects = { namespaced: {} }
|
581
581
|
}
|
582
582
|
|
583
583
|
for (const bag of bags) {
|
@@ -966,7 +966,7 @@ class Config {
|
|
966
966
|
},
|
967
967
|
objects: {
|
968
968
|
// this is where the namespaced configs have their objects
|
969
|
-
namespaced: {}
|
969
|
+
namespaced: {}
|
970
970
|
},
|
971
971
|
description: '',
|
972
972
|
words: {
|
@@ -1026,7 +1026,7 @@ class Config {
|
|
1026
1026
|
|
1027
1027
|
exists (marker) {
|
1028
1028
|
for (const bridge of this.config.bridges) {
|
1029
|
-
if (bridge.id
|
1029
|
+
if (bridge.id === marker) {
|
1030
1030
|
return true
|
1031
1031
|
}
|
1032
1032
|
}
|
@@ -1046,7 +1046,7 @@ class Config {
|
|
1046
1046
|
|
1047
1047
|
warningNotEvaluated (log, value) {
|
1048
1048
|
const description = 'WARNING: for semantics, implement an evaluations handler, set "value" property of the operator to the value.'
|
1049
|
-
const match = `({context}) => context.marker
|
1049
|
+
const match = `({context}) => context.marker === '${value.marker}' && context.evaluate && <other conditions as you like>`
|
1050
1050
|
const apply = '({context}) => <do stuff...>; context.value = <value>'
|
1051
1051
|
const input = indent(JSON.stringify(value, null, 2), 2)
|
1052
1052
|
const message = `${description}\nThe semantic would be\n match: ${match}\n apply: ${apply}\nThe input context would be:\n${input}\n`
|
@@ -1055,8 +1055,8 @@ class Config {
|
|
1055
1055
|
|
1056
1056
|
// value is in response field
|
1057
1057
|
// TODO maybe generalize out query+evaluate along the lines of set value and set reference
|
1058
|
-
async getEvaluator (s, calls, log, context) {
|
1059
|
-
const instance = await s({ ...context, evaluate: true })
|
1058
|
+
async getEvaluator (s, calls, log, context, args) {
|
1059
|
+
const instance = await s({ ...args, ...context, evaluate: true })
|
1060
1060
|
calls.touch(instance)
|
1061
1061
|
if (!instance.evalue && !instance.verbatim && !instance.value) {
|
1062
1062
|
this.warningNotEvaluated(log, context)
|
@@ -1214,43 +1214,6 @@ class Config {
|
|
1214
1214
|
}
|
1215
1215
|
return bridge
|
1216
1216
|
})
|
1217
|
-
} else {
|
1218
|
-
/* done in updateQueries now
|
1219
|
-
config.generators = (config.generators || []).map((generator) => {
|
1220
|
-
generator = { ...generator }
|
1221
|
-
delete generator.where
|
1222
|
-
generator.match = generator.match.toString()
|
1223
|
-
generator.apply = generator.apply.toString()
|
1224
|
-
return generator
|
1225
|
-
})
|
1226
|
-
config.semantics = (config.semantics || []).map((semantic) => {
|
1227
|
-
semantic = { ...semantic }
|
1228
|
-
delete semantic.where
|
1229
|
-
semantic.match = semantic.match.toString()
|
1230
|
-
semantic.apply = semantic.apply.toString()
|
1231
|
-
return semantic
|
1232
|
-
})
|
1233
|
-
config.bridges = (config.bridges || []).map((bridge) => {
|
1234
|
-
bridge = { ...bridge }
|
1235
|
-
delete bridge.where
|
1236
|
-
if (bridge.generatorp) {
|
1237
|
-
bridge.generatorp = bridge.generatorp.toString()
|
1238
|
-
}
|
1239
|
-
if (bridge.generatorr) {
|
1240
|
-
bridge.generatorr = bridge.generatorr.toString()
|
1241
|
-
}
|
1242
|
-
if (bridge.generatorpr) {
|
1243
|
-
bridge.generatorpr = bridge.generatorpr.toString()
|
1244
|
-
}
|
1245
|
-
if (bridge.evaluator) {
|
1246
|
-
bridge.evaluator = bridge.evaluator.toString()
|
1247
|
-
}
|
1248
|
-
if (bridge.semantic) {
|
1249
|
-
bridge.semantic = bridge.semantic.toString()
|
1250
|
-
}
|
1251
|
-
return bridge
|
1252
|
-
})
|
1253
|
-
*/
|
1254
1217
|
}
|
1255
1218
|
return config
|
1256
1219
|
}
|
@@ -1331,7 +1294,7 @@ class Config {
|
|
1331
1294
|
toData (data) {
|
1332
1295
|
Object.assign(data, this.config)
|
1333
1296
|
// greg99 delete data.objects
|
1334
|
-
data.objects = {...this.config.objects}
|
1297
|
+
data.objects = { ...this.config.objects }
|
1335
1298
|
if (!this.sendObjectsToServer) {
|
1336
1299
|
delete data.objects.namespaced
|
1337
1300
|
}
|
@@ -1490,7 +1453,7 @@ class Config {
|
|
1490
1453
|
debugHierarchy([child, parent])
|
1491
1454
|
if (this.config.hierarchy.find((element) => {
|
1492
1455
|
const hc = hierarchyCanonical(element)
|
1493
|
-
if (child
|
1456
|
+
if (child === hc.child && parent === hc.parent) {
|
1494
1457
|
return true
|
1495
1458
|
}
|
1496
1459
|
})) {
|
@@ -1503,9 +1466,9 @@ class Config {
|
|
1503
1466
|
|
1504
1467
|
getBridge (id, level) {
|
1505
1468
|
if (level) {
|
1506
|
-
return this.config.bridges.find((bridge) => bridge.id
|
1469
|
+
return this.config.bridges.find((bridge) => bridge.id === id && bridge.level === level)
|
1507
1470
|
} else {
|
1508
|
-
return this.config.bridges.find((bridge) => bridge.id
|
1471
|
+
return this.config.bridges.find((bridge) => bridge.id === id)
|
1509
1472
|
}
|
1510
1473
|
}
|
1511
1474
|
|
@@ -1518,8 +1481,8 @@ class Config {
|
|
1518
1481
|
|
1519
1482
|
debugBridge(bridge)
|
1520
1483
|
if (bridge.allowDups) {
|
1521
|
-
// if (bridges.find( (b) => b.id
|
1522
|
-
if (bridges.find((b) => b.id
|
1484
|
+
// if (bridges.find( (b) => b.id === bridge.id && b.level === bridge.level && b.bridge === bridge.bridge )) {
|
1485
|
+
if (bridges.find((b) => b.id === bridge.id && b.level === bridge.level)) {
|
1523
1486
|
return
|
1524
1487
|
}
|
1525
1488
|
}
|
@@ -1588,7 +1551,7 @@ class Config {
|
|
1588
1551
|
}
|
1589
1552
|
seen.add(id)
|
1590
1553
|
const index = this.config.semantics.findIndex((semantic) => semantic.id === id)
|
1591
|
-
if (index
|
1554
|
+
if (index === -1) {
|
1592
1555
|
continue
|
1593
1556
|
}
|
1594
1557
|
for (const tied_id of this.config.semantics[index].tied_ids || []) {
|
@@ -1619,7 +1582,7 @@ class Config {
|
|
1619
1582
|
debugOperator(operator)
|
1620
1583
|
|
1621
1584
|
if (operator.allowDups) {
|
1622
|
-
if (operators.find((o) => o.pattern
|
1585
|
+
if (operators.find((o) => o.pattern === operator.pattern)) {
|
1623
1586
|
return
|
1624
1587
|
}
|
1625
1588
|
}
|
@@ -1776,7 +1739,7 @@ class Config {
|
|
1776
1739
|
if (!config.objects) {
|
1777
1740
|
config.objects = {
|
1778
1741
|
namespaced: {
|
1779
|
-
}
|
1742
|
+
}
|
1780
1743
|
}
|
1781
1744
|
}
|
1782
1745
|
|
@@ -1885,7 +1848,7 @@ class Config {
|
|
1885
1848
|
for (const word in literals) {
|
1886
1849
|
const defs = literals[word] || []
|
1887
1850
|
literals[word] = defs.filter((def) => !def.development)
|
1888
|
-
if (literals[word].length
|
1851
|
+
if (literals[word].length === 0) {
|
1889
1852
|
delete literals[word]
|
1890
1853
|
}
|
1891
1854
|
}
|
@@ -2033,7 +1996,7 @@ class Config {
|
|
2033
1996
|
debugConfigProps(this.config)
|
2034
1997
|
}
|
2035
1998
|
|
2036
|
-
setSendObjectsToServer() {
|
1999
|
+
setSendObjectsToServer () {
|
2037
2000
|
this.sendObjectsToServer = true
|
2038
2001
|
}
|
2039
2002
|
|
@@ -2110,9 +2073,12 @@ class Config {
|
|
2110
2073
|
throw new Error('This is intended to be used to instantiate a new class based on the existing API.')
|
2111
2074
|
} else {
|
2112
2075
|
if (name) {
|
2113
|
-
if (this.name
|
2076
|
+
if (this.name === name) {
|
2114
2077
|
return this._api.constructor
|
2115
2078
|
} else {
|
2079
|
+
if (!this.getConfig(name)) {
|
2080
|
+
throw new Error(`Config.apiBase: The requested KM '${name}' has not been loaded`)
|
2081
|
+
}
|
2116
2082
|
return this.getConfig(name)._api.constructor
|
2117
2083
|
}
|
2118
2084
|
} else {
|
@@ -2147,7 +2113,12 @@ class Config {
|
|
2147
2113
|
}
|
2148
2114
|
}
|
2149
2115
|
|
2116
|
+
setApiKMs (apiKMs) {
|
2117
|
+
this._apiKMs = [...apiKMs]
|
2118
|
+
}
|
2119
|
+
|
2150
2120
|
// constructors is a constructor
|
2121
|
+
// TODO fix Api to be API WTF
|
2151
2122
|
async setApi (constructor) {
|
2152
2123
|
if (typeof constructor !== 'function') {
|
2153
2124
|
throw new Error(`Expected the argument to be an API constructor for ${this.name}.`)
|
@@ -2165,7 +2136,7 @@ class Config {
|
|
2165
2136
|
}
|
2166
2137
|
} else {
|
2167
2138
|
if (!value.initialize) {
|
2168
|
-
throw new Error(`Expected the API to have an initialize function for ${this.name}.`)
|
2139
|
+
throw new Error(`Expected the API to have an initialize function for ${this.name}. If you are trying to pass in multiple API configs at once use setApiKMs to set the names of the configs that you want set.`)
|
2169
2140
|
}
|
2170
2141
|
}
|
2171
2142
|
|
@@ -2260,7 +2231,7 @@ class Config {
|
|
2260
2231
|
if (this._apiKMs.length > 0) {
|
2261
2232
|
const apis = cp._apiConstructor(cp)
|
2262
2233
|
for (const name of this._apiKMs) {
|
2263
|
-
if (name
|
2234
|
+
if (name === this.name) {
|
2264
2235
|
cp._api = apis[name]
|
2265
2236
|
} else {
|
2266
2237
|
cp.km(name)._api = apis[name]
|
@@ -2301,8 +2272,8 @@ class Config {
|
|
2301
2272
|
await cp.rebuild(options) // in copy
|
2302
2273
|
} else {
|
2303
2274
|
if (!cp.config.objects) {
|
2304
|
-
cp.config.objects = {
|
2305
|
-
namespaced: {}
|
2275
|
+
cp.config.objects = {
|
2276
|
+
namespaced: {}
|
2306
2277
|
}
|
2307
2278
|
} else if (!cp.config.objects.namespaced) {
|
2308
2279
|
cp.config.objects.namespaced = {}
|
@@ -2777,7 +2748,7 @@ class Config {
|
|
2777
2748
|
const init = initAfterApis[i]
|
2778
2749
|
init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true })
|
2779
2750
|
}
|
2780
|
-
const instance = this.instances.find((instance) => instance.name
|
2751
|
+
const instance = this.instances.find((instance) => instance.name === name)
|
2781
2752
|
if (instance) {
|
2782
2753
|
await configHelpers.loadInstance(this, instance)
|
2783
2754
|
}
|
@@ -2793,12 +2764,16 @@ class Config {
|
|
2793
2764
|
}
|
2794
2765
|
}
|
2795
2766
|
|
2767
|
+
if (this.isModule) {
|
2768
|
+
this.removeDevelopmentElements(this.config)
|
2769
|
+
}
|
2770
|
+
|
2796
2771
|
this.valid()
|
2797
2772
|
this.checks()
|
2798
2773
|
}
|
2799
2774
|
|
2800
2775
|
nameToUUID (name) {
|
2801
|
-
return this.configs.find((km) => km._name
|
2776
|
+
return this.configs.find((km) => km._name === name)._uuid
|
2802
2777
|
}
|
2803
2778
|
|
2804
2779
|
// name: namespace name
|
@@ -3063,7 +3038,7 @@ class Config {
|
|
3063
3038
|
}
|
3064
3039
|
|
3065
3040
|
// TODO trie
|
3066
|
-
if (property
|
3041
|
+
if (property === 'words') {
|
3067
3042
|
for (const word in value) {
|
3068
3043
|
for (const def of value[word]) {
|
3069
3044
|
if (!def.uuid) {
|
@@ -3116,7 +3091,7 @@ class Config {
|
|
3116
3091
|
const mores = []
|
3117
3092
|
for (const createConfig of createConfigs) {
|
3118
3093
|
const more = await createConfig()
|
3119
|
-
if (this.name && this.name
|
3094
|
+
if (this.name && this.name === more.name) {
|
3120
3095
|
throw new Error('Cannot add an object to itself for argument number ${index+1}.')
|
3121
3096
|
}
|
3122
3097
|
if (this === more) {
|
@@ -3166,7 +3141,7 @@ class Config {
|
|
3166
3141
|
})
|
3167
3142
|
const noDups = []
|
3168
3143
|
for (const instance of this.instances) {
|
3169
|
-
if (!noDups.find((existing) => existing.name
|
3144
|
+
if (!noDups.find((existing) => existing.name === instance.name)) {
|
3170
3145
|
noDups.push(instance)
|
3171
3146
|
}
|
3172
3147
|
}
|
@@ -3178,7 +3153,7 @@ class Config {
|
|
3178
3153
|
}
|
3179
3154
|
|
3180
3155
|
// TODO get rid of useOldVersion arg
|
3181
|
-
addInternal (more, { uuid, addFirst = false, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps: hcps = false } = {}) {
|
3156
|
+
addInternal (more, { uuid, km, addFirst = false, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps: hcps = false } = {}) {
|
3182
3157
|
validConfigProps(more)
|
3183
3158
|
if (more instanceof Config) {
|
3184
3159
|
more.initialize({ force: false })
|
@@ -3195,6 +3170,14 @@ class Config {
|
|
3195
3170
|
handleCalculatedProps(this, more, { addFirst, uuid })
|
3196
3171
|
applyUUID(more, uuid || this._uuid)
|
3197
3172
|
}
|
3173
|
+
if (km) {
|
3174
|
+
if (more.semantics) {
|
3175
|
+
more.semantics.map( (s) => s.km = km )
|
3176
|
+
}
|
3177
|
+
if (more.generators) {
|
3178
|
+
more.generators.map( (g) => g.km = km )
|
3179
|
+
}
|
3180
|
+
}
|
3198
3181
|
for (const key of Object.keys(more)) {
|
3199
3182
|
const value = more[key]
|
3200
3183
|
// TODO remove name and description on the config bag
|
@@ -3275,9 +3258,9 @@ class Config {
|
|
3275
3258
|
}
|
3276
3259
|
} else if (Array.isArray(value)) {
|
3277
3260
|
// handle allowDups
|
3278
|
-
if (key
|
3261
|
+
if (key === 'operators') {
|
3279
3262
|
// TODO what about other props
|
3280
|
-
const isDup = (op1, op2) => op1.pattern
|
3263
|
+
const isDup = (op1, op2) => op1.pattern === op2.pattern
|
3281
3264
|
for (const newOne of more[key]) {
|
3282
3265
|
for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
|
3283
3266
|
const oldOne = this.config[key][iOldOne]
|
@@ -3291,13 +3274,13 @@ class Config {
|
|
3291
3274
|
}
|
3292
3275
|
}
|
3293
3276
|
}
|
3294
|
-
if (key
|
3277
|
+
if (key === 'bridges') {
|
3295
3278
|
// TODO what about other props
|
3296
|
-
const idDup = (b1, b2) => b1.id
|
3279
|
+
const idDup = (b1, b2) => b1.id === b2.id && b1.level === b2.level && b1.bridge === b2.bridge
|
3297
3280
|
for (const newOne of more[key]) {
|
3298
3281
|
for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
|
3299
3282
|
const oldOne = this.config[key][iOldOne]
|
3300
|
-
if (newOne.id
|
3283
|
+
if (newOne.id === oldOne.id) {
|
3301
3284
|
if (oldOne.allowDups) {
|
3302
3285
|
// the old one takes precedence to match what would happen during the original load
|
3303
3286
|
this.config[key].splice(iOldOne, 1)
|
@@ -3311,7 +3294,7 @@ class Config {
|
|
3311
3294
|
// console.log('key', key, 'XXX')
|
3312
3295
|
// console.log('more', JSON.stringify(more, null, 2))
|
3313
3296
|
// hierarchy must update in place and does not care about the list order
|
3314
|
-
if (key
|
3297
|
+
if (key === 'hierarchy') {
|
3315
3298
|
this.config[key].push(...more[key])
|
3316
3299
|
} else {
|
3317
3300
|
if (addFirst) {
|
@@ -3412,9 +3395,9 @@ class Config {
|
|
3412
3395
|
}
|
3413
3396
|
} else if (Array.isArray(value)) {
|
3414
3397
|
// handle allowDups
|
3415
|
-
if (key
|
3398
|
+
if (key === 'operators') {
|
3416
3399
|
// TODO what about other props
|
3417
|
-
const isDup = (op1, op2) => op1.pattern
|
3400
|
+
const isDup = (op1, op2) => op1.pattern === op2.pattern
|
3418
3401
|
for (const newOne of more[key]) {
|
3419
3402
|
for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
|
3420
3403
|
const oldOne = this.config[key][iOldOne]
|
@@ -3428,13 +3411,13 @@ class Config {
|
|
3428
3411
|
}
|
3429
3412
|
}
|
3430
3413
|
}
|
3431
|
-
if (key
|
3414
|
+
if (key === 'bridges') {
|
3432
3415
|
// TODO what about other props
|
3433
|
-
const idDup = (b1, b2) => b1.id
|
3416
|
+
const idDup = (b1, b2) => b1.id === b2.id && b1.level === b2.level && b1.bridge === b2.bridge
|
3434
3417
|
for (const newOne of more[key]) {
|
3435
3418
|
for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
|
3436
3419
|
const oldOne = this.config[key][iOldOne]
|
3437
|
-
if (newOne.id
|
3420
|
+
if (newOne.id === oldOne.id) {
|
3438
3421
|
if (oldOne.allowDups) {
|
3439
3422
|
// the old one takes precedence to match what would happen during the original load
|
3440
3423
|
this.config[key].splice(iOldOne, 1)
|
package/src/configHelpers.js
CHANGED
@@ -140,7 +140,7 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
|
|
140
140
|
if (!c) {
|
141
141
|
return
|
142
142
|
}
|
143
|
-
return config.getEvaluator(args.s, args.calls, logs, c)
|
143
|
+
return config.getEvaluator(args.s, args.calls, logs, c, { isModule: args.isModule, isProcess: args.isProcess })
|
144
144
|
}
|
145
145
|
args.gs = gs(args.g)
|
146
146
|
args.gsp = gs(args.gp)
|
@@ -279,7 +279,7 @@ const setupContexts = (rawContexts) => {
|
|
279
279
|
return contexts
|
280
280
|
}
|
281
281
|
|
282
|
-
const processContextsB = async ({ config, hierarchy, semantics, generators, json, isTest, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs, forTemplate }) => {
|
282
|
+
const processContextsB = async ({ config, hierarchy, semantics, generators, json, isTest, isProcess, isModule, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs, forTemplate }) => {
|
283
283
|
// TODO fix this name to contextsPrime
|
284
284
|
const contextsPrime = []
|
285
285
|
const generatedPrime = []
|
@@ -290,7 +290,7 @@ const processContextsB = async ({ config, hierarchy, semantics, generators, json
|
|
290
290
|
const contexts = setupContexts(json.contexts)
|
291
291
|
|
292
292
|
const objects = config.get('objects')
|
293
|
-
const args = { objects, isResponse: true, response: json, isTest, isInstance, getObjects: getObjects(objects), instance, contexts }
|
293
|
+
const args = { objects, isResponse: true, response: json, isTest, isInstance, getObjects: getObjects(objects), instance, contexts, isProcess, isModule }
|
294
294
|
if (!json.logs) {
|
295
295
|
json.logs = []
|
296
296
|
}
|
@@ -424,7 +424,7 @@ const loadInstance = async (config, instance) => {
|
|
424
424
|
*/
|
425
425
|
const rl = instance.resultss.length
|
426
426
|
if (rl > 0) {
|
427
|
-
config.addAssociations(instance.resultss[instance.resultss.length-1].rtf_associations || [])
|
427
|
+
config.addAssociations(instance.resultss[instance.resultss.length - 1].rtf_associations || [])
|
428
428
|
}
|
429
429
|
/*
|
430
430
|
TODO needs updating if still wanted
|
@@ -448,7 +448,7 @@ const loadInstance = async (config, instance) => {
|
|
448
448
|
// config.addInternal(results, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false)
|
449
449
|
const uuid = config.nameToUUID(instance.name)
|
450
450
|
// used to do a CLONE
|
451
|
-
config.addInternal(instance.template.configs[i], { uuid, addFirst: true, handleCalculatedProps: true })
|
451
|
+
config.addInternal(instance.template.configs[i], { uuid, km: instance.name, addFirst: true, handleCalculatedProps: true })
|
452
452
|
} else if (results.apply) {
|
453
453
|
const objects = getObjects(config.get('objects'))(config.uuid)
|
454
454
|
const args = { objects, getObjects: getObjects(objects) }
|
@@ -468,6 +468,8 @@ const loadInstance = async (config, instance) => {
|
|
468
468
|
const args = { config, hierarchy, json: results, commandLineArgs: {}, forTemplate: true }
|
469
469
|
args.isInstance = `instance${i}`
|
470
470
|
args.instance = ''
|
471
|
+
args.isProcess = !config.isModule
|
472
|
+
args.isModule = !!config.isModule
|
471
473
|
await processContextsB(args)
|
472
474
|
if (results.skipSemantics) {
|
473
475
|
config.config.skipSemantics = null
|
package/src/digraph.js
CHANGED
@@ -22,7 +22,7 @@ class Digraph {
|
|
22
22
|
while (Object.keys(frontier).length > 0) {
|
23
23
|
const n = Object.keys(frontier)[0]
|
24
24
|
const ps = frontier[n]
|
25
|
-
if (to
|
25
|
+
if (to === n) {
|
26
26
|
return ps[0]
|
27
27
|
}
|
28
28
|
if (done.has(n)) {
|
@@ -184,7 +184,7 @@ class Digraph {
|
|
184
184
|
}
|
185
185
|
|
186
186
|
exists (child, parent) {
|
187
|
-
return this._edges.find((edge) => edge[0]
|
187
|
+
return this._edges.find((edge) => edge[0] === child && edge[1] === parent)
|
188
188
|
}
|
189
189
|
|
190
190
|
addList (l) {
|
package/src/digraph_internal.js
CHANGED
@@ -24,7 +24,7 @@ class DigraphInternal {
|
|
24
24
|
addEdge (edge) {
|
25
25
|
edge = toA(edge)
|
26
26
|
// if (this._edges.find((existing) => _.isEqual(edge, existing))) {
|
27
|
-
if (this._edges.find((existing) => edge[0]
|
27
|
+
if (this._edges.find((existing) => edge[0] === existing[0] && edge[1] === existing[1])) {
|
28
28
|
return false
|
29
29
|
}
|
30
30
|
this._edges.push(edge)
|
@@ -154,7 +154,7 @@ class DigraphInternal {
|
|
154
154
|
}
|
155
155
|
|
156
156
|
exists (child, parent) {
|
157
|
-
return this._edges.findIndex((edge) => edge[0]
|
157
|
+
return this._edges.findIndex((edge) => edge[0] === child && edge[1] === parent) != -1
|
158
158
|
}
|
159
159
|
|
160
160
|
addList (l) {
|
package/src/flatten.js
CHANGED
@@ -92,7 +92,7 @@ const flatten = (markers, value) => {
|
|
92
92
|
const split = markers.includes(marker)
|
93
93
|
if (split) {
|
94
94
|
if ('value' in properties) {
|
95
|
-
flattenedValues = []
|
95
|
+
let flattenedValues = []
|
96
96
|
for (const v of properties.value) {
|
97
97
|
if (v.flatten) {
|
98
98
|
flattenedValues = flattenedValues.concat(flatten(markers, v)[0])
|
package/src/generators.js
CHANGED
@@ -65,7 +65,7 @@ class Generator {
|
|
65
65
|
// return this.match(args)
|
66
66
|
const matches = await this.match(args)
|
67
67
|
if ((matches && (options.debug || {}).match) ||
|
68
|
-
callId
|
68
|
+
callId === this.callId) {
|
69
69
|
// next line is the matcher
|
70
70
|
debugger // eslint-disable-line no-debugger
|
71
71
|
await this.match(args)
|
@@ -78,7 +78,7 @@ class Generator {
|
|
78
78
|
if (!log) {
|
79
79
|
throw new Error('generators.apply argument log is required')
|
80
80
|
}
|
81
|
-
if (baseArgs.call && config &&
|
81
|
+
if (baseArgs.call && config && baseArgs.calls.stack.length > config.maxDepth) {
|
82
82
|
throw new Error(`Max depth of ${config.maxDepth} for calls has been exceeded. maxDepth can be set on the config object. To see the calls run with the --dl or set the debugLoops property on the config`)
|
83
83
|
}
|
84
84
|
|
@@ -116,11 +116,11 @@ class Generator {
|
|
116
116
|
apis: this.getAPIs(config)
|
117
117
|
}
|
118
118
|
const args = Object.assign({}, baseArgs, moreArgs, (baseArgs.getUUIDScoped || (() => { return {} }))(this.uuid))
|
119
|
-
if (this.property
|
119
|
+
if (this.property === 'generatorp') {
|
120
120
|
args.g = args.gp
|
121
121
|
}
|
122
122
|
if ((options.debug || {}).apply ||
|
123
|
-
callId
|
123
|
+
callId === this.callId) {
|
124
124
|
debugger // eslint-disable-line no-debugger
|
125
125
|
}
|
126
126
|
return await this._apply(args)
|
@@ -218,7 +218,7 @@ class Generators {
|
|
218
218
|
lines.setElement(0, 2, stack)
|
219
219
|
lines.newRow()
|
220
220
|
lines.setElement(0, 1, 'DEBUG')
|
221
|
-
lines.setElement(0, 2, `To debug this use args.callId
|
221
|
+
lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
|
222
222
|
lines.newRow()
|
223
223
|
lines.setElement(0, 1, 'ERROR')
|
224
224
|
lines.setElement(0, 2, errorMessage)
|
@@ -250,7 +250,7 @@ class Generators {
|
|
250
250
|
lines.setElement(0, 2, stack)
|
251
251
|
lines.newRow()
|
252
252
|
lines.setElement(0, 1, 'DEBUG')
|
253
|
-
lines.setElement(0, 2, `To debug this use args.callId
|
253
|
+
lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
|
254
254
|
lines.newRow()
|
255
255
|
lines.setElement(0, 1, 'TO')
|
256
256
|
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
package/src/helpers.js
CHANGED
@@ -97,7 +97,7 @@ const appendNoDups = (l1, l2) => {
|
|
97
97
|
}
|
98
98
|
|
99
99
|
const safeNoDups = (list) => {
|
100
|
-
noDups = []
|
100
|
+
const noDups = []
|
101
101
|
for (const element of list) {
|
102
102
|
if (!noDups.find((e) => safeEquals(e, element))) {
|
103
103
|
noDups.push(element)
|
@@ -112,14 +112,14 @@ const safeEquals = (v1, v2) => {
|
|
112
112
|
}
|
113
113
|
|
114
114
|
const type = typeof v1
|
115
|
-
if (type
|
116
|
-
return v1
|
117
|
-
} else if (type
|
118
|
-
return v1.toString()
|
115
|
+
if (type === 'number' || type === 'string') {
|
116
|
+
return v1 === v2
|
117
|
+
} else if (type === 'function') {
|
118
|
+
return v1.toString() === v2.toString()
|
119
119
|
} else if (v1 == undefined || v2 == undefined) {
|
120
|
-
return v1
|
120
|
+
return v1 === v2
|
121
121
|
} else {
|
122
|
-
if (v1.length
|
122
|
+
if (v1.length !== v2.length) {
|
123
123
|
return false
|
124
124
|
}
|
125
125
|
for (const key in v1) {
|
@@ -148,7 +148,7 @@ const semanticsGenerate = (from, known) => {
|
|
148
148
|
}
|
149
149
|
|
150
150
|
return {
|
151
|
-
match: ({context}) => marker
|
151
|
+
match: ({context}) => marker === marker,
|
152
152
|
apply: ({context}) => {
|
153
153
|
},
|
154
154
|
}
|
@@ -299,9 +299,9 @@ const sortJson = (json) => {
|
|
299
299
|
const validProps = (valids, object, type) => {
|
300
300
|
for (const prop of Object.keys(object)) {
|
301
301
|
let okay = false
|
302
|
-
for (valid of valids) {
|
302
|
+
for (const valid of valids) {
|
303
303
|
if (typeof valid === 'string') {
|
304
|
-
okay = prop
|
304
|
+
okay = prop === valid
|
305
305
|
} else {
|
306
306
|
okay = prop.match(valid)
|
307
307
|
}
|
@@ -310,6 +310,7 @@ const validProps = (valids, object, type) => {
|
|
310
310
|
}
|
311
311
|
}
|
312
312
|
if (!okay) {
|
313
|
+
valids.sort()
|
313
314
|
throw new Error(`Unknown property "${prop}" in the ${type}. Valid properties are ${valids.join(', ')}. The ${type} is ${JSON.stringify(object)}`)
|
314
315
|
}
|
315
316
|
}
|
@@ -334,7 +335,7 @@ const updateQueries = (queryOrConfig) => {
|
|
334
335
|
|
335
336
|
const functionsToStrings = (config) => {
|
336
337
|
config = { ...config }
|
337
|
-
defToStrings = (def) => {
|
338
|
+
const defToStrings = (def) => {
|
338
339
|
if (def.apply) {
|
339
340
|
// return { ...def, match: def.match.toString(), apply: def.apply.toString() }
|
340
341
|
return { match: def.match.toString(), apply: def.apply.toString() }
|
@@ -390,7 +391,7 @@ const ecatch = (where, call) => {
|
|
390
391
|
}
|
391
392
|
|
392
393
|
const equalKey = (key1, key2) => {
|
393
|
-
return key1[0]
|
394
|
+
return key1[0] === key2[0] && key1[1] === key2[1]
|
394
395
|
}
|
395
396
|
|
396
397
|
// matches for { context: ..., [ordered], choose: ... } exactely OR
|
@@ -399,8 +400,8 @@ const subPriority = (sub, sup) => {
|
|
399
400
|
if (Array.isArray(sub)) {
|
400
401
|
const subChoosen = sub[0]
|
401
402
|
const subOther = sub[1]
|
402
|
-
const hasChoosen = sup.choose.find((index) => equalKey(sup.context[index], subChoosen))
|
403
|
-
const hasOtherChosen = sup.choose.find((index) => equalKey(sup.context[index], subOther))
|
403
|
+
const hasChoosen = sup.choose.find((index) => equalKey(sup.context[index], subChoosen)) !== undefined
|
404
|
+
const hasOtherChosen = sup.choose.find((index) => equalKey(sup.context[index], subOther)) !== undefined
|
404
405
|
const hasOther = sup.context.find((other) => equalKey(other, subOther)) !== undefined
|
405
406
|
return !!(hasChoosen && hasOther) && !hasOtherChosen
|
406
407
|
}
|
@@ -418,7 +419,7 @@ const subPriority = (sub, sup) => {
|
|
418
419
|
}
|
419
420
|
const chosen1 = choose(sub)
|
420
421
|
const chosen2 = choose(sup)
|
421
|
-
const sameId = (id1, id2) => id1[0]
|
422
|
+
const sameId = (id1, id2) => id1[0] === id2[0] && id1[1] === id2[1]
|
422
423
|
// same length so only need one way
|
423
424
|
const missing1 = chosen1.find((id1) => !chosen2.find((id2) => sameId(id1, id2)))
|
424
425
|
if (missing1) {
|
package/src/project.js
CHANGED
package/src/semantics.js
CHANGED
@@ -72,7 +72,7 @@ class Semantic {
|
|
72
72
|
async matches (args, context, options = {}) {
|
73
73
|
this.fixUpArgs(args, context)
|
74
74
|
const matches = await this.matcher(args)
|
75
|
-
if (matches && (options.debug || {}).match || args.callId
|
75
|
+
if (matches && (options.debug || {}).match || args.callId === this.callId) {
|
76
76
|
// next line is the matcher
|
77
77
|
debugger // eslint-disable-line no-debugger
|
78
78
|
await this.matcher(args)
|
@@ -92,7 +92,7 @@ class Semantic {
|
|
92
92
|
const contextPrime = Object.assign({}, context)
|
93
93
|
this.fixUpArgs(args, contextPrime)
|
94
94
|
|
95
|
-
if ((options.debug || {}).apply || args.callId
|
95
|
+
if ((options.debug || {}).apply || args.callId === this.callId) {
|
96
96
|
debugger // eslint-disable-line no-debugger
|
97
97
|
}
|
98
98
|
if (args.breakOnSemantics) {
|
@@ -234,7 +234,7 @@ class Semantics {
|
|
234
234
|
lines.setElement(0, 2, stack)
|
235
235
|
lines.newRow()
|
236
236
|
lines.setElement(0, 1, 'DEBUG')
|
237
|
-
lines.setElement(0, 2, `To debug this use args.callId
|
237
|
+
lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
|
238
238
|
lines.newRow()
|
239
239
|
lines.setElement(0, 1, 'ERROR')
|
240
240
|
lines.setElement(0, 2, errorMessage)
|
@@ -269,7 +269,7 @@ class Semantics {
|
|
269
269
|
lines.setElement(0, 2, stack)
|
270
270
|
lines.newRow()
|
271
271
|
lines.setElement(0, 1, 'DEBUG')
|
272
|
-
lines.setElement(0, 2, `To debug this use args.callId
|
272
|
+
lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
|
273
273
|
lines.newRow()
|
274
274
|
lines.setElement(0, 1, 'RESULT')
|
275
275
|
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
package/src/unflatten.js
CHANGED
@@ -36,7 +36,7 @@ const concatLists = (l1, l2) => {
|
|
36
36
|
|
37
37
|
const findPropertyWithManyValues = (contexts, properties) => {
|
38
38
|
for (const property of properties) {
|
39
|
-
if (new Set(contexts.map((context) => context[property])).size
|
39
|
+
if (new Set(contexts.map((context) => context[property])).size === 1) {
|
40
40
|
return property
|
41
41
|
}
|
42
42
|
}
|