theprogrammablemind 9.8.0 → 9.9.0-beta.0
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 +65 -50
- package/index.js +2 -1
- package/lines.js +1 -1
- package/package.json +4 -2
- package/src/config.js +70 -52
- package/src/configHelpers.js +56 -26
- package/src/digraph.js +99 -11
- package/src/digraph_internal.js +135 -20
- package/src/fragments.js +17 -2
- package/src/generators.js +22 -13
- package/src/helpers.js +82 -9
- package/src/project2.js +24 -18
- package/src/semantics.js +25 -15
package/client.js
CHANGED
|
@@ -12,10 +12,22 @@ const _ = require('lodash')
|
|
|
12
12
|
const stringify = require('json-stable-stringify')
|
|
13
13
|
const Lines = require('./lines')
|
|
14
14
|
const flattens = require('./src/flatten')
|
|
15
|
-
const { helpDebugHierarchy, sortJson, appendNoDups, InitCalls, updateQueries, safeNoDups, stableId, where, suggestAssociationsFix, suggestAssociationsFixFromSummaries, validProps, OverrideCheck, } = require('./src/helpers')
|
|
15
|
+
const { helpDebugHierarchy, sortJson, appendNoDups, InitCalls, updateQueries, safeNoDups, stableId, where, suggestAssociationsFix, suggestAssociationsFixFromSummaries, validProps, OverrideCheck, removeProp, } = require('./src/helpers')
|
|
16
16
|
const runtime = require('./runtime')
|
|
17
17
|
const db = require('./src/debug')
|
|
18
18
|
|
|
19
|
+
class ErrorJSON extends Error {
|
|
20
|
+
constructor (json) {
|
|
21
|
+
super()
|
|
22
|
+
this.json = json
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
toString() {
|
|
26
|
+
return JSON.stringify(json.error)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
19
31
|
const getConfig_getObjectsCheck = (config, testConfig) => {
|
|
20
32
|
let testConfigName = config.name
|
|
21
33
|
if (testConfig.testModuleName) {
|
|
@@ -59,20 +71,11 @@ const pickObjects = (config, testConfig, getObjects) => {
|
|
|
59
71
|
throw new Error(`In the checks for ${config.name} the KM ${km} does not exist`)
|
|
60
72
|
}
|
|
61
73
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
} else {
|
|
66
|
-
projection[km] = project(objects, checks[km])
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
const lastIndex = contextChecks.length - 1
|
|
70
|
-
const last = contextChecks[lastIndex]
|
|
71
|
-
contextChecks[lastIndex] = { match: last.match, apply: () => [...new Set([...(checks[km] || []), ...last.apply()])] }
|
|
74
|
+
const lastIndex = contextChecks.length - 1
|
|
75
|
+
const last = contextChecks[lastIndex]
|
|
76
|
+
contextChecks[lastIndex] = { match: last.match, apply: () => [...new Set([...(checks[km] || []), ...last.apply()])] }
|
|
72
77
|
|
|
73
|
-
|
|
74
|
-
projection[km] = project2(objects, contextChecks)
|
|
75
|
-
}
|
|
78
|
+
projection[km] = project2(objects, contextChecks)
|
|
76
79
|
}
|
|
77
80
|
return projection
|
|
78
81
|
}
|
|
@@ -167,13 +170,6 @@ const writeTest = (fn, query, objects, generated, paraphrases, responses, contex
|
|
|
167
170
|
if (runtime.fs.existsSync(fn)) {
|
|
168
171
|
tests = JSON.parse(runtime.fs.readFileSync(fn))
|
|
169
172
|
}
|
|
170
|
-
/*
|
|
171
|
-
for (const association of associations) {
|
|
172
|
-
association.sort()
|
|
173
|
-
}
|
|
174
|
-
associations.sort()
|
|
175
|
-
*/
|
|
176
|
-
// tests[query] = sortJson({ paraphrases, responses, contexts, objects: convertToStable(objects), associations, metadata, config, developerTest: saveDeveloper }, { depth: 25 })
|
|
177
173
|
const results = sortJson({
|
|
178
174
|
query,
|
|
179
175
|
summaries,
|
|
@@ -198,7 +194,6 @@ const writeTest = (fn, query, objects, generated, paraphrases, responses, contex
|
|
|
198
194
|
if (!wasSet) {
|
|
199
195
|
tests.push(results)
|
|
200
196
|
}
|
|
201
|
-
// fs.writeFileSync(fn, stringify(tests, { space: 2 }), { encoding: 'utf8', flag: 'w+' })
|
|
202
197
|
writeTestFile(fn, tests)
|
|
203
198
|
}
|
|
204
199
|
|
|
@@ -267,7 +262,7 @@ const throwErrorHandler = (error) => {
|
|
|
267
262
|
throw error
|
|
268
263
|
}
|
|
269
264
|
|
|
270
|
-
const _process = async (config, query, { queryNumber, initializer, commandLineArgs, credentials, writeTests, logs, isProcess, isModule, isTest, saveDeveloper, rebuildingTemplate, testConfig, testsFN, errorHandler = throwErrorHandler } = {}) => {
|
|
265
|
+
const _process = async (config, query, { isFragment, queryNumber, initializer, commandLineArgs, credentials, writeTests, logs, isProcess, isModule, isTest, saveDeveloper, rebuildingTemplate, testConfig, testsFN, errorHandler = throwErrorHandler } = {}) => {
|
|
271
266
|
if (credentials) {
|
|
272
267
|
config.server(credentials.server, credentials.key)
|
|
273
268
|
}
|
|
@@ -363,7 +358,7 @@ const _process = async (config, query, { queryNumber, initializer, commandLineAr
|
|
|
363
358
|
startCounter = json.end_counter + 1
|
|
364
359
|
delete json.results
|
|
365
360
|
if (json.status !== 200) {
|
|
366
|
-
throw json
|
|
361
|
+
throw new ErrorJSON(json)
|
|
367
362
|
} else {
|
|
368
363
|
let clientSideTime
|
|
369
364
|
let start
|
|
@@ -373,7 +368,7 @@ const _process = async (config, query, { queryNumber, initializer, commandLineAr
|
|
|
373
368
|
const summary = { summaries: json.summaries, length: json.contexts.length }
|
|
374
369
|
summaries.push(summary)
|
|
375
370
|
const { updatedContextIdCounter, contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime } =
|
|
376
|
-
await processContextsB({ contextIdCounter, logs, calls, isTest, isProcess, isModule, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
|
371
|
+
await processContextsB({ skipSemantics: isFragment, isFragment, contextIdCounter, logs, calls, isTest, isProcess, isModule, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
|
377
372
|
contextIdCounter = updatedContextIdCounter
|
|
378
373
|
if (isTest) {
|
|
379
374
|
const end = runtime.performance.performance.now()
|
|
@@ -390,9 +385,9 @@ const _process = async (config, query, { queryNumber, initializer, commandLineAr
|
|
|
390
385
|
response.trace = response.trace.concat(json.trace)
|
|
391
386
|
response.version = json.version
|
|
392
387
|
response.explain_priorities = json.explain_priorities
|
|
393
|
-
response.
|
|
388
|
+
response.explain_associations_details = (response.explain_associations_details || []).concat(json.explain_associations_details)
|
|
389
|
+
response.explain_associations_trie = json.explain_associations_trie
|
|
394
390
|
response.contextual_priorities_ambiguities = json.contextual_priorities_ambiguities
|
|
395
|
-
// response.rtf_associations = json.rtf_associations
|
|
396
391
|
|
|
397
392
|
response.contexts = response.contexts.concat(contextsPrime)
|
|
398
393
|
response.generated = response.generated.concat(generatedPrime)
|
|
@@ -417,9 +412,11 @@ const _process = async (config, query, { queryNumber, initializer, commandLineAr
|
|
|
417
412
|
|
|
418
413
|
return response
|
|
419
414
|
} catch (error) {
|
|
420
|
-
error.
|
|
421
|
-
|
|
422
|
-
|
|
415
|
+
if (error.json) {
|
|
416
|
+
error.json.summaries = summaries
|
|
417
|
+
error.json.queryNumber = queryNumber
|
|
418
|
+
error.json.query = query
|
|
419
|
+
}
|
|
423
420
|
errorHandler(error)
|
|
424
421
|
}
|
|
425
422
|
}
|
|
@@ -755,30 +752,43 @@ const submitBug = async (subscription_id, subscription_password, config, utteran
|
|
|
755
752
|
*/
|
|
756
753
|
|
|
757
754
|
const defaultErrorHandler = async (error) => {
|
|
758
|
-
|
|
755
|
+
const json = error.json || error
|
|
756
|
+
|
|
757
|
+
if (json.explain_associations_details) {
|
|
758
|
+
console.log("EXPLAIN ASSOCIATIONS START")
|
|
759
|
+
console.log("EXPLAIN ASSOCIATIONS TRIE START")
|
|
760
|
+
console.log(json.explain_associations_trie)
|
|
761
|
+
console.log("EXPLAIN ASSOCIATIONS TRIE END")
|
|
762
|
+
console.log("EXPLAIN ASSOCIATIONS DETAILS START")
|
|
763
|
+
debugger
|
|
764
|
+
console.log(json.explain_associations_details)
|
|
765
|
+
console.log("EXPLAIN ASSOCIATIONS DETAILS END")
|
|
766
|
+
console.log("EXPLAIN ASSOCIATIONS END")
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
if (json.logs) {
|
|
759
770
|
console.log('\nlogs: ')
|
|
760
|
-
for (const log of
|
|
771
|
+
for (const log of json.logs) {
|
|
761
772
|
console.log('\n ', log)
|
|
762
773
|
}
|
|
763
774
|
}
|
|
764
775
|
|
|
765
|
-
if (
|
|
766
|
-
console.log('trace: ',
|
|
776
|
+
if (json.trace) {
|
|
777
|
+
console.log('trace: ', json.trace)
|
|
767
778
|
}
|
|
768
779
|
|
|
769
|
-
if (
|
|
770
|
-
console.log('
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
if (error.stack) {
|
|
780
|
+
if (json.stack) {
|
|
781
|
+
console.log('error: ')
|
|
782
|
+
console.log(json.stack)
|
|
783
|
+
} else if (error.stack) {
|
|
774
784
|
console.log('error: ')
|
|
775
785
|
console.log(error.stack)
|
|
776
786
|
}
|
|
777
787
|
|
|
778
788
|
let doErrorExit = false
|
|
779
|
-
if (
|
|
789
|
+
if (json.errors) {
|
|
780
790
|
console.log('error: ')
|
|
781
|
-
for (const e of
|
|
791
|
+
for (const e of json.errors) {
|
|
782
792
|
if (e.logs) {
|
|
783
793
|
console.log('\nlogs: ')
|
|
784
794
|
for (const log of e.logs) {
|
|
@@ -793,16 +803,16 @@ const defaultErrorHandler = async (error) => {
|
|
|
793
803
|
doErrorExit = true
|
|
794
804
|
}
|
|
795
805
|
}
|
|
796
|
-
if (
|
|
806
|
+
if (json.error) {
|
|
797
807
|
console.log('error: ')
|
|
798
|
-
for (const e of
|
|
808
|
+
for (const e of json.error) {
|
|
799
809
|
console.log('\n ', e)
|
|
800
810
|
doErrorExit = true
|
|
801
811
|
}
|
|
802
812
|
}
|
|
803
813
|
|
|
804
|
-
if (
|
|
805
|
-
console.log(`query: #${
|
|
814
|
+
if (json.query) {
|
|
815
|
+
console.log(`query: #${json.queryNumber} ${json.query}`)
|
|
806
816
|
doErrorExit = true
|
|
807
817
|
}
|
|
808
818
|
|
|
@@ -810,7 +820,7 @@ const defaultErrorHandler = async (error) => {
|
|
|
810
820
|
runtime.process.exit(-1)
|
|
811
821
|
}
|
|
812
822
|
|
|
813
|
-
|
|
823
|
+
json.config = null // otherwise it dumps too much on the console
|
|
814
824
|
|
|
815
825
|
throw error
|
|
816
826
|
}
|
|
@@ -895,8 +905,11 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
|
|
|
895
905
|
}
|
|
896
906
|
}
|
|
897
907
|
|
|
898
|
-
if (responses.
|
|
899
|
-
console.log(responses.
|
|
908
|
+
if (responses.explain_associations_details) {
|
|
909
|
+
console.log(responses.explain_associations_trie)
|
|
910
|
+
for (const l of responses.explain_associations_details) {
|
|
911
|
+
console.log(l)
|
|
912
|
+
}
|
|
900
913
|
}
|
|
901
914
|
|
|
902
915
|
// const objects = config.get('objects').namespaced[config.uuid]
|
|
@@ -907,6 +920,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
|
|
|
907
920
|
const km = config.configs.find((km) => km.name === name)
|
|
908
921
|
return config.config.objects.namespaced[km.uuid] || {}
|
|
909
922
|
}
|
|
923
|
+
|
|
910
924
|
const picked = sortJson(pickObjects(config, config.testConfig, actualGetObjects), { depth: 25 })
|
|
911
925
|
if (!_.isEmpty(picked)) {
|
|
912
926
|
console.log('--- Object showing only the checked values ---')
|
|
@@ -1041,7 +1055,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
|
1041
1055
|
await loadInstance(config, { resultss: [results] })
|
|
1042
1056
|
} else {
|
|
1043
1057
|
try {
|
|
1044
|
-
results = await _process(config, query.query, { initializer, rebuildingTemplate: true })
|
|
1058
|
+
results = await _process(config, query.query, { initializer, rebuildingTemplate: true, isFragment })
|
|
1045
1059
|
} catch (e) {
|
|
1046
1060
|
if (e.summaries && e.summaries.length > 0) {
|
|
1047
1061
|
suggestFix(e.summaries)
|
|
@@ -1069,7 +1083,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
|
1069
1083
|
results.isFragment = isFragment
|
|
1070
1084
|
results.skipSemantics = skipSemantics
|
|
1071
1085
|
results.development = query.development
|
|
1072
|
-
results.key = { query: query.query, hierarchy }
|
|
1086
|
+
results.key = { query: query.query, hierarchy, preserve: query.preserve }
|
|
1073
1087
|
accumulators[property].push(results)
|
|
1074
1088
|
if (isFragment) {
|
|
1075
1089
|
config.fragmentsBeingBuilt.push({ query: query.query, contexts: results.contexts })
|
|
@@ -1135,6 +1149,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
|
1135
1149
|
const stabilizeOutput = (template) => {
|
|
1136
1150
|
// stabilizeAssociations(template.associations)
|
|
1137
1151
|
const stabilize = (results) => {
|
|
1152
|
+
removeProp(results, (_, k) => k === "context_id")
|
|
1138
1153
|
for (let i = 0; i < results.length; ++i) {
|
|
1139
1154
|
const result = results[i]
|
|
1140
1155
|
if (result.apply) {
|
package/index.js
CHANGED
|
@@ -1,7 +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 { w, where, OverrideCheck, setByPath, getByPath } = require('./src/helpers')
|
|
4
|
+
const { w, where, OverrideCheck, setByPath, getByPath, removeProp } = require('./src/helpers')
|
|
5
5
|
const Digraph = require('./src/digraph')
|
|
6
6
|
const client = require('./client')
|
|
7
7
|
const flattens = require('./src/flatten')
|
|
@@ -32,4 +32,5 @@ module.exports = {
|
|
|
32
32
|
unflatten: unflatten.unflatten,
|
|
33
33
|
debug,
|
|
34
34
|
OverrideCheck,
|
|
35
|
+
removeProp,
|
|
35
36
|
}
|
package/lines.js
CHANGED
package/package.json
CHANGED
|
@@ -15,12 +15,14 @@
|
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"to:debug": "node inspect node_modules/.bin/jest --runInBand -t NEO23",
|
|
18
|
-
"
|
|
18
|
+
"testd": "node inspect node_modules/.bin/jest --runInBand --config ./jest.config.json",
|
|
19
19
|
"td": "node inspect node_modules/.bin/jest --runInBand --config ./jest.config.json",
|
|
20
20
|
"tod": "node inspect node_modules/.bin/jest --runInBand -t NEO23",
|
|
21
|
+
"toda": "node inspect node_modules/.bin/jest --runInBand -t NEO23A",
|
|
21
22
|
"lint:fix": "eslint \"**/*.js\" --fix",
|
|
22
23
|
"lint": "eslint \"**/*.js\"",
|
|
23
24
|
"to": "node node_modules/.bin/jest --runInBand -t NEO23",
|
|
25
|
+
"toa": "node node_modules/.bin/jest --runInBand -t NEO23A",
|
|
24
26
|
"tos": "node node_modules/.bin/jest --runInBand -t NEOS23",
|
|
25
27
|
"test": "jest --config ./jest.config.json",
|
|
26
28
|
"test:python": "node node_modules/.bin/jest --runInBand -t PYTHON",
|
|
@@ -73,6 +75,6 @@
|
|
|
73
75
|
"scriptjs": "^2.5.9",
|
|
74
76
|
"uuid": "^8.3.2"
|
|
75
77
|
},
|
|
76
|
-
"version": "9.
|
|
78
|
+
"version": "9.9.0-beta.0",
|
|
77
79
|
"license": "UNLICENSED"
|
|
78
80
|
}
|
package/src/config.js
CHANGED
|
@@ -3,7 +3,7 @@ const { Semantics, normalizeGenerator } = require('./semantics')
|
|
|
3
3
|
const { Generators } = require('./generators')
|
|
4
4
|
const { v4: uuidv4 } = require('uuid')
|
|
5
5
|
const configHelpers = require('./configHelpers')
|
|
6
|
-
const
|
|
6
|
+
const Digraph = require('./digraph')
|
|
7
7
|
const helpers = require('./helpers')
|
|
8
8
|
const { InitCalls } = require('./helpers')
|
|
9
9
|
const { ecatch } = require('./helpers')
|
|
@@ -30,7 +30,7 @@ const config_toServer = (config) => {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
const updateHierarchy = (config) => {
|
|
33
|
-
config.hierarchy = new
|
|
33
|
+
config.hierarchy = new Digraph(config.config.hierarchy)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
const initWords = (words) => {
|
|
@@ -295,9 +295,6 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
|
295
295
|
if (bridge.scope && config.isModule) {
|
|
296
296
|
return
|
|
297
297
|
}
|
|
298
|
-
if (false && !bridge.bridge) {
|
|
299
|
-
bridge.bridge = '{ ...next(operator) }'
|
|
300
|
-
}
|
|
301
298
|
if (!bridge.level) {
|
|
302
299
|
bridge.level = 0
|
|
303
300
|
}
|
|
@@ -391,6 +388,13 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
|
391
388
|
}
|
|
392
389
|
*/
|
|
393
390
|
|
|
391
|
+
if (!bridge.where) {
|
|
392
|
+
if (bridge.generator || bridge.generatorp || bridge.generatorr || bridge.generator ||
|
|
393
|
+
bridge.semantic || bridge.semantics) {
|
|
394
|
+
throw new Error(`In the KM "${config.name}", for the bridge ${bridge.id} the where property is missing. Use where: where().`)
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
394
398
|
const addUUID = (obj) => { return { ...obj, uuid: uuid || config.uuid } }
|
|
395
399
|
|
|
396
400
|
if (bridge.generators) {
|
|
@@ -469,7 +473,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
|
469
473
|
}
|
|
470
474
|
}
|
|
471
475
|
|
|
472
|
-
const addSemantic = (semantic, evaluate) => {
|
|
476
|
+
const addSemantic = (semantic, evaluate, property) => {
|
|
473
477
|
const match = semantic.match || (() => true)
|
|
474
478
|
let apply = semantic
|
|
475
479
|
// if I do apply === semantic.apply or semantic there is one function that has apply defined for some reason even though not explicitly set
|
|
@@ -491,13 +495,13 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
|
491
495
|
}
|
|
492
496
|
} else {
|
|
493
497
|
semanticDef = {
|
|
494
|
-
match: (args) => bridge.id === args.context.marker &&
|
|
498
|
+
match: (args) => bridge.id === args.context.marker && match(args),
|
|
495
499
|
apply: (args) => apply(args),
|
|
496
500
|
applyWrapped: semantic,
|
|
497
501
|
}
|
|
498
502
|
}
|
|
499
503
|
semanticDef.where = semantic.where || bridge.where || helpers.where(4)
|
|
500
|
-
semanticDef.property =
|
|
504
|
+
semanticDef.property = property
|
|
501
505
|
if (semantic.priority) {
|
|
502
506
|
semanticDef.priority = semantic.priority
|
|
503
507
|
}
|
|
@@ -509,22 +513,8 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
|
509
513
|
}
|
|
510
514
|
}
|
|
511
515
|
|
|
512
|
-
if (bridge.evaluator) {
|
|
513
|
-
addSemantic(bridge.evaluator, true)
|
|
514
|
-
}
|
|
515
|
-
|
|
516
516
|
if (bridge.semantic) {
|
|
517
|
-
addSemantic(bridge.semantic, false)
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
if (bridge.evaluators) {
|
|
521
|
-
const evaluators = [...bridge.evaluators]
|
|
522
|
-
evaluators.reverse()
|
|
523
|
-
if (evaluators) {
|
|
524
|
-
for (const evaluator of evaluators) {
|
|
525
|
-
addSemantic(evaluator, true)
|
|
526
|
-
}
|
|
527
|
-
}
|
|
517
|
+
addSemantic(bridge.semantic, false, 'semantic')
|
|
528
518
|
}
|
|
529
519
|
|
|
530
520
|
if (bridge.semantics) {
|
|
@@ -556,8 +546,6 @@ const handleCalculatedProps = (baseConfig, moreConfig, { addFirst, uuid } = {})
|
|
|
556
546
|
'convolution',
|
|
557
547
|
'disabled',
|
|
558
548
|
'enhanced_associations',
|
|
559
|
-
'evaluator',
|
|
560
|
-
'evaluators',
|
|
561
549
|
'generatorp',
|
|
562
550
|
'generatorpr',
|
|
563
551
|
'generatorr',
|
|
@@ -569,6 +557,7 @@ const handleCalculatedProps = (baseConfig, moreConfig, { addFirst, uuid } = {})
|
|
|
569
557
|
'level',
|
|
570
558
|
'levelSpecificHierarchy',
|
|
571
559
|
'localHierarchy',
|
|
560
|
+
'match',
|
|
572
561
|
'operator',
|
|
573
562
|
'optional',
|
|
574
563
|
'parents',
|
|
@@ -996,9 +985,10 @@ class Config {
|
|
|
996
985
|
|
|
997
986
|
async fixtures () {
|
|
998
987
|
if (this.testConfig?.fixtures) {
|
|
999
|
-
const args = {
|
|
988
|
+
const args = {
|
|
989
|
+
}
|
|
1000
990
|
args.uuid = this._uuid
|
|
1001
|
-
configHelpers.setupArgs(args, this)
|
|
991
|
+
configHelpers.setupArgs(args, this, this.logs)
|
|
1002
992
|
return this.testConfig.fixtures(args)
|
|
1003
993
|
}
|
|
1004
994
|
}
|
|
@@ -1029,6 +1019,7 @@ class Config {
|
|
|
1029
1019
|
return {
|
|
1030
1020
|
pseudo: true,
|
|
1031
1021
|
description: 'this is a pseudo config that has limited functionality due to being available in the initializer and fixtures function context',
|
|
1022
|
+
nextFragmentContextId: () => this.nextFragmentContextId(),
|
|
1032
1023
|
addAssociation: (...args) => this.addAssociation(...args),
|
|
1033
1024
|
addAssociations: (...args) => this.addAssociations(...args),
|
|
1034
1025
|
addBridge: (...args) => this.addBridge(...args, uuid),
|
|
@@ -1043,6 +1034,7 @@ class Config {
|
|
|
1043
1034
|
addPattern: (...args) => this.addPattern(...args, uuid),
|
|
1044
1035
|
updateBridge: (...args) => this.updateBridge(...args),
|
|
1045
1036
|
processContext: (...args) => this.processContext(...args),
|
|
1037
|
+
logs: this.logs,
|
|
1046
1038
|
|
|
1047
1039
|
semantics: () => this.config.semantics,
|
|
1048
1040
|
getConfigs: () => this.configs,
|
|
@@ -1242,7 +1234,7 @@ class Config {
|
|
|
1242
1234
|
|
|
1243
1235
|
warningNotEvaluated (log, value) {
|
|
1244
1236
|
const description = 'WARNING: for semantics, implement an evaluations handler, set "value" property of the operator to the value.'
|
|
1245
|
-
const match = `({context}) => context.marker === '${value.marker}' &&
|
|
1237
|
+
const match = `({context}) => context.marker === '${value.marker}' && <other conditions as you like>`
|
|
1246
1238
|
const apply = '({context}) => <do stuff...>; context.value = <value>'
|
|
1247
1239
|
const input = indent(JSON.stringify(value, null, 2), 2)
|
|
1248
1240
|
const message = `${description}\nThe semantic would be\n match: ${match}\n apply: ${apply}\nThe input context would be:\n${input}\n`
|
|
@@ -1251,18 +1243,15 @@ class Config {
|
|
|
1251
1243
|
|
|
1252
1244
|
// value is in response field
|
|
1253
1245
|
// TODO maybe generalize out query+evaluate along the lines of set value and set reference
|
|
1254
|
-
async
|
|
1255
|
-
const
|
|
1256
|
-
|
|
1257
|
-
if (
|
|
1258
|
-
|
|
1246
|
+
async evaluate (args, logs, context) {
|
|
1247
|
+
const apply = (c) => this.getSemantics(logs).apply(args, c)
|
|
1248
|
+
const instance = await apply(context)
|
|
1249
|
+
if (typeof instance !== 'string') {
|
|
1250
|
+
args.calls.touch(instance)
|
|
1259
1251
|
}
|
|
1260
|
-
if (instance.evalue == null) {
|
|
1261
|
-
|
|
1262
|
-
instance.edefault = true
|
|
1252
|
+
if (instance.evalue == null && !instance.verbatim && !instance.value) {
|
|
1253
|
+
this.warningNotEvaluated(logs, context)
|
|
1263
1254
|
}
|
|
1264
|
-
delete instance.evaluate
|
|
1265
|
-
instance.instance = true
|
|
1266
1255
|
return instance
|
|
1267
1256
|
}
|
|
1268
1257
|
|
|
@@ -1293,10 +1282,14 @@ class Config {
|
|
|
1293
1282
|
let fi = fragmentInstantiator(args, fragment.contexts)
|
|
1294
1283
|
if (mappings) {
|
|
1295
1284
|
fi = await fi
|
|
1296
|
-
|
|
1285
|
+
const instantiated = await fi.instantiate([{
|
|
1297
1286
|
match: ({context}) => !!mappings[context.value], // is the value in the mappings
|
|
1298
1287
|
apply: ({context}) => Object.assign(context, mappings[context.value]),
|
|
1299
|
-
}])
|
|
1288
|
+
}], fragment.key?.preserve)
|
|
1289
|
+
if (process.env.DEBUG_CONTEXT_ID && process.env.DEBUG_CONTEXT_ID == instantiated.context_id) {
|
|
1290
|
+
debugger
|
|
1291
|
+
}
|
|
1292
|
+
return instantiated
|
|
1300
1293
|
} else {
|
|
1301
1294
|
return fi
|
|
1302
1295
|
}
|
|
@@ -1305,6 +1298,7 @@ class Config {
|
|
|
1305
1298
|
}
|
|
1306
1299
|
}
|
|
1307
1300
|
|
|
1301
|
+
/*
|
|
1308
1302
|
fragmentMapper (args, values, fromModelQuery, toModelQuery) {
|
|
1309
1303
|
const fromModelFragment = this.getFragment(fromModelQuery)
|
|
1310
1304
|
console.dir(fromModelFragment)
|
|
@@ -1313,6 +1307,7 @@ class Config {
|
|
|
1313
1307
|
const mapper = fragmentMapperInstantiator(values, fromModelFragment.contexts, toModelFragment.contexts)
|
|
1314
1308
|
return mapper
|
|
1315
1309
|
}
|
|
1310
|
+
*/
|
|
1316
1311
|
|
|
1317
1312
|
// { rebuild: false, isModule: false }
|
|
1318
1313
|
needsRebuild (template, instance, options) {
|
|
@@ -1384,6 +1379,7 @@ class Config {
|
|
|
1384
1379
|
bridge = { ...bridge },
|
|
1385
1380
|
bridge.level = bridge.level || 0
|
|
1386
1381
|
delete bridge.uuid
|
|
1382
|
+
delete bridge.where
|
|
1387
1383
|
return bridge
|
|
1388
1384
|
})
|
|
1389
1385
|
if (options.isModule) {
|
|
@@ -1396,8 +1392,6 @@ class Config {
|
|
|
1396
1392
|
delete bridge.generatorp
|
|
1397
1393
|
delete bridge.generatorr
|
|
1398
1394
|
delete bridge.generatorpr
|
|
1399
|
-
delete bridge.evaluator
|
|
1400
|
-
delete bridge.evaluators
|
|
1401
1395
|
delete bridge.semantic
|
|
1402
1396
|
delete bridge.semantics
|
|
1403
1397
|
if (false && !bridge.bridge) {
|
|
@@ -2179,6 +2173,12 @@ class Config {
|
|
|
2179
2173
|
// await this.demoInitializer(this)
|
|
2180
2174
|
}
|
|
2181
2175
|
|
|
2176
|
+
nextFragmentContextId() {
|
|
2177
|
+
const id = this.fragmentNextContextId
|
|
2178
|
+
this.fragmentNextContextId = this.fragmentNextContextId + 1
|
|
2179
|
+
return id
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2182
2182
|
// configs = [ { config, namespace } ... ]
|
|
2183
2183
|
constructor (config, module, clientProcess, apiKMs, rootIsProcess, testingModuleName) {
|
|
2184
2184
|
if (config instanceof Config) {
|
|
@@ -2189,6 +2189,8 @@ class Config {
|
|
|
2189
2189
|
apiKMs = []
|
|
2190
2190
|
}
|
|
2191
2191
|
|
|
2192
|
+
this.fragmentNextContextId = 1000
|
|
2193
|
+
|
|
2192
2194
|
if (config) {
|
|
2193
2195
|
validConfigProps(config)
|
|
2194
2196
|
|
|
@@ -2273,7 +2275,7 @@ class Config {
|
|
|
2273
2275
|
}
|
|
2274
2276
|
}
|
|
2275
2277
|
this.terminatorFn = () => {}
|
|
2276
|
-
this.loadOrder = new
|
|
2278
|
+
this.loadOrder = new Digraph()
|
|
2277
2279
|
this.wasInitialized = false
|
|
2278
2280
|
this.configs = []
|
|
2279
2281
|
this._api = undefined
|
|
@@ -2281,13 +2283,13 @@ class Config {
|
|
|
2281
2283
|
this._namespace = []
|
|
2282
2284
|
this._eqClasses = []
|
|
2283
2285
|
// this._uuid = uuidv4()
|
|
2284
|
-
this._uuid = this.getCounter(this.name)
|
|
2286
|
+
this._uuid = (this.name || '') + this.getCounter(this.name)
|
|
2285
2287
|
if (config) {
|
|
2286
2288
|
config = _.cloneDeep(config)
|
|
2287
2289
|
this.config = config
|
|
2288
2290
|
handleCalculatedProps(this, config)
|
|
2289
2291
|
}
|
|
2290
|
-
this.hierarchy = new
|
|
2292
|
+
this.hierarchy = new Digraph(this.config.hierarchy)
|
|
2291
2293
|
this.initConfig = _.cloneDeep(this.config)
|
|
2292
2294
|
this.configs.push(new KM({ config: this.config, getCounter: (name) => this.config.getCounter(name), uuid: this._uuid }))
|
|
2293
2295
|
|
|
@@ -2528,6 +2530,7 @@ class Config {
|
|
|
2528
2530
|
cp.logs = []
|
|
2529
2531
|
cp.demoInitializer = this.demoInitializer
|
|
2530
2532
|
cp.maxDepth = this.maxDepth
|
|
2533
|
+
cp.loadOrder = this.loadOrder
|
|
2531
2534
|
cp.debugLoops = this.debugLoops
|
|
2532
2535
|
cp.transitoryMode = this.transitoryMode
|
|
2533
2536
|
// cp.configs = this.configs.map((km) => await km.copy2(Object.assign({}, options, { getCounter: (name) => cp.getCounter(name), callInitializers: false })))
|
|
@@ -2568,7 +2571,7 @@ class Config {
|
|
|
2568
2571
|
cp.configCounter = this.configCounter
|
|
2569
2572
|
cp.testConfig = this.testConfig
|
|
2570
2573
|
cp._server = this._server
|
|
2571
|
-
cp.hierarchy = new
|
|
2574
|
+
cp.hierarchy = new Digraph(this.config.hierarchy)
|
|
2572
2575
|
cp.sendObjectsToServer = this.sendObjectsToServer
|
|
2573
2576
|
|
|
2574
2577
|
cp.scope = this.scope
|
|
@@ -2956,7 +2959,7 @@ class Config {
|
|
|
2956
2959
|
this.resetDelta()
|
|
2957
2960
|
const debug = this.config.debug
|
|
2958
2961
|
this.config = _.cloneDeep(this.initConfig)
|
|
2959
|
-
this.hierarchy = new
|
|
2962
|
+
this.hierarchy = new Digraph(this.config.hierarchy)
|
|
2960
2963
|
if (debug) {
|
|
2961
2964
|
this.config.debug = debug
|
|
2962
2965
|
}
|
|
@@ -2974,7 +2977,7 @@ class Config {
|
|
|
2974
2977
|
|
|
2975
2978
|
// reorder configs base on load ordering
|
|
2976
2979
|
{
|
|
2977
|
-
const ordering = this.
|
|
2980
|
+
const ordering = this.getLoadOrder().order(this.configs.map((km) => km.name || km.uuid))
|
|
2978
2981
|
this.loadOrdering = ordering
|
|
2979
2982
|
const oconfigs = []
|
|
2980
2983
|
for (const nameOrUUID of ordering) {
|
|
@@ -3016,7 +3019,7 @@ class Config {
|
|
|
3016
3019
|
}
|
|
3017
3020
|
if (!isSelf) {
|
|
3018
3021
|
config.config = _.cloneDeep(config.initConfig)
|
|
3019
|
-
config.hierarchy = new
|
|
3022
|
+
config.hierarchy = new Digraph(config.config.hierarchy)
|
|
3020
3023
|
}
|
|
3021
3024
|
config.wasInitialized = false
|
|
3022
3025
|
// TODO change name of config: to baseConfig:
|
|
@@ -3024,7 +3027,7 @@ class Config {
|
|
|
3024
3027
|
const config = this.getConfig(name)
|
|
3025
3028
|
return config
|
|
3026
3029
|
}
|
|
3027
|
-
// const hierarchy = new
|
|
3030
|
+
// const hierarchy = new Digraph((config.config || {}).hierarchy)
|
|
3028
3031
|
const args = new Object(setupInitializerFNArgs(this, {
|
|
3029
3032
|
isModule,
|
|
3030
3033
|
hierarchy: this.hierarchy,
|
|
@@ -3489,8 +3492,6 @@ class Config {
|
|
|
3489
3492
|
more = await more.copy()
|
|
3490
3493
|
more.server(this._server, this._key, this._queryParams)
|
|
3491
3494
|
|
|
3492
|
-
const moreConfigs = more.configs.map((km) => km.name || km.uuid)
|
|
3493
|
-
this.loadOrder.addList(moreConfigs)
|
|
3494
3495
|
|
|
3495
3496
|
// get the new ones
|
|
3496
3497
|
// remove the dups
|
|
@@ -3530,11 +3531,28 @@ class Config {
|
|
|
3530
3531
|
}
|
|
3531
3532
|
this.instances = noDups
|
|
3532
3533
|
}
|
|
3534
|
+
|
|
3535
|
+
this.loadOrder = this.getLoadOrder()
|
|
3536
|
+
|
|
3533
3537
|
await this.rebuild() // in add(
|
|
3534
3538
|
this.valid()
|
|
3535
3539
|
return this
|
|
3536
3540
|
}
|
|
3537
3541
|
|
|
3542
|
+
getLoadOrder() {
|
|
3543
|
+
const loadOrder = new Digraph()
|
|
3544
|
+
for (const [i, config] of this.configs.entries()) {
|
|
3545
|
+
if (i == 0) {
|
|
3546
|
+
} else {
|
|
3547
|
+
loadOrder.add( this.name, config.name )
|
|
3548
|
+
for (const edge of config.config?.loadOrder.edges || []) {
|
|
3549
|
+
loadOrder.addEdge(edge)
|
|
3550
|
+
}
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3553
|
+
return loadOrder
|
|
3554
|
+
}
|
|
3555
|
+
|
|
3538
3556
|
// TODO get rid of useOldVersion arg
|
|
3539
3557
|
addInternal (more,
|
|
3540
3558
|
{ uuid, km, addFirst = false, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps: hcps = false } = {}) {
|